llvm / llvm/llvm-project

[opt] -passes="instrprof" causes Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"'

Open
#191,976 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

crash generated by fuzzer llvm:transforms
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer: https://godbolt.org/z/KqYqhGr7f

opt: /root/llvm-project/llvm/include/llvm/Support/Casting.h:572: decltype(auto) llvm::cast(From*) [with To = llvm::GlobalVariable; From = llvm::Value]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=instrprof <source>
1.	Running pass "instrprof" on module "<source>"
 #0 0x0000000005c4f168 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5c4f168)
 #1 0x0000000005c4bf94 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5c4bf94)
 #2 0x0000000005c4c10a SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007444b5e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007444b5e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007444b5e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007444b5e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007444b5e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007444b5e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000003766f9e (anonymous namespace)::InstrLowerer::getOrCreateRegionCounters(llvm::InstrProfCntrInstBase*) InstrProfiling.cpp:0:0
#10 0x000000000376aab0 (anonymous namespace)::InstrLowerer::lower() InstrProfiling.cpp:0:0
#11 0x000000000376c5da llvm::InstrProfilingLoweringPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x376c5da)
#12 0x00000000031c64be llvm::detail::PassModel<llvm::Module, llvm::InstrProfilingLoweringPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x31c64be)
#13 0x00000000059b2266 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x59b2266)
#14 0x000000000096f03a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x96f03a)
#15 0x00000000009630df optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9630df)
#16 0x00007444b5e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#17 0x00007444b5e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#18 0x00000000009585c5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9585c5)
Program terminated with signal: SIGSEGV
Compiler returned: 139

Generated by fuzzer.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Godbolt reproducer and the opt -passes=instrprof command, then inspect InstrProfiling.cpp around InstrLowerer::getOrCreateRegionCounters(), where the assertion occurs. Compare the Value being cast with the expected GlobalVariable and confirm the reproducer no longer aborts while running the instrprof pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.