Skip to content

llvm/include/llvm/Support/Casting.h:109: Assertion failed #93029

Closed
@dcb314

Description

@dcb314

Clang can be made to say:

clang: /home/dcb38/llvm/trunk/llvm/include/llvm/Support/Casting.h:109: static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = llvm::UndefValue; From = llvm::Constant]: Assertion `Val && "isa<> used on a null pointer"' failed.

codegen_timing_486-53904b.sh.gz
codegen_timing_486-53904b.c.gz

Activity

llvmbot

llvmbot commented on May 22, 2024

@llvmbot
Member

@llvm/issue-subscribers-c

Author: None (dcb314)

Clang can be made to say:

clang: /home/dcb38/llvm/trunk/llvm/include/llvm/Support/Casting.h:109: static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = llvm::UndefValue; From = llvm::Constant]: Assertion `Val && "isa<> used on a null pointer"' failed.

codegen_timing_486-53904b.sh.gz
codegen_timing_486-53904b.c.gz

Endilll

Endilll commented on May 22, 2024

@Endilll
Contributor

Can't reproduce on trunk and 18.1.0 with assertions: https://godbolt.org/z/8Wxvqcz4o
Can you provide full compiler output, not just the assertion? We need stack trace to identify where and at which stage the crash occurred.

dcb314

dcb314 commented on May 22, 2024

@dcb314
Author

The version of the compiler I used was from this morning.
Git hash 1cf75cc.

Stack backtrace is

 #7 0x00007f701984887f abort (/lib64/libc.so.6+0x2687f)
 #8 0x00007f701984879b _nl_load_domain.cold (/lib64/libc.so.6+0x2679b)
 #9 0x00007f7019858187 (/lib64/libc.so.6+0x36187)
#10 0x0000000001b7cfe4 llvm::InstCombinerImpl::foldCmpLoadFromIndexedGlobal(llvm::LoadInst*, llvm::GetElementPtrInst*, llvm::GlobalVariable*, llvm::CmpInst&, llvm::ConstantInt*) /home/dcb38/llvm/trunk/llvm/include/llvm/Support/Casting.h:109:5
#11 0x0000000001ba58c2 llvm::InstCombinerImpl::visitICmpInst(llvm::ICmpInst&) /home/dcb38/llvm/trunk/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:7300:3
#12 0x0000000001b0538b llvm::InstCombinerImpl::run() /home/dcb38/llvm/trunk/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5089:36
#13 0x0000000001b06ae8 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::LoopInfo*, llvm::InstCombineOptions const&) /home/dcb38/llvm/trunk/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5389:5
#14 0x0000000001b07d13 llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/dcb38/llvm/trunk/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:5448:3
#15 0x000000000221ab9d llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/dcb38/llvm/trunk/llvm/include/llvm/IR/PassManagerInternal.h:91:3
#16 0x0000000001a5885e llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/dcb38/llvm/trunk/llvm/include/llvm/IR/PassManager.h:228:20
#17 0x0000000000b45efd llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/dcb38/llvm/trunk/llvm/include/llvm/IR/PassManagerInternal.h:91:3

Machine type is x86_64. AMD Zen 3 I think.

When the reduction is finished, I will post it here.

Endilll

Endilll commented on May 22, 2024

@Endilll
Contributor

Thank you for reducing it yourself! Please make sure you follow this guidance, in order for your reduction to be as useful as possible: #89807 (comment)

dcb314

dcb314 commented on May 22, 2024

@dcb314
Author

It works fine with yesterday's clang:

llvm $ ~/llvm/results.20240521/bin/clang -c -w -O1 codegen_timing_486-53904b.c
llvm $ 

But not todays ;-|

llvm $ ~/llvm/results.20240522/bin/clang -c -w -O1 codegen_timing_486-53904b.c
lang: /home/dcb38/llvm/trunk/llvm/include/llvm/Support/Casting.h:109: static bo
ol llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = llvm::UndefV
alue; From = llvm::Constant]: Assertion `Val && "isa<> used on a null pointer"' 
failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and i
nclude the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /home/dcb38/llvm/results.20240522/bin/clang -c -w -O1
 codegen_timing_486-53904b.c
1.	<eof> parser at end of file
2.	Optimizer
 #0 0x0000000001fa377e llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home
/dcb38/llvm/trunk/llvm/lib/Support/Unix/Signals.inc:723:22
 #1 0x0000000001fa08eb llvm::sys::RunSignalHandlers() /home/dcb38/llvm/trunk/llv
m/lib/Support/Signals.cpp:105:20
 #2 0x0000000001eed398 HandleCrash /home/dcb38/llvm/trunk/llvm/lib/Support/Crash
RecoveryContext.cpp:73:5
 #3 0x0000000001eed398 CrashRecoverySignalHandler(int) /home/dcb38/llvm/trunk/ll
vm/lib/Support/CrashRecoveryContext.cpp:390:62
 #4 0x00007fbec565fbb0 __restore_rt (/lib64/libc.so.6+0x3dbb0)
 #5 0x00007fbec56b0884 __pthread_kill_implementation (/lib64/libc.so.6+0x8e884)
 #6 0x00007fbec565fafe gsignal (/lib64/libc.so.6+0x3dafe)
 #7 0x00007fbec564887f abort (/lib64/libc.so.6+0x2687f)
 #8 0x00007fbec564879b _nl_load_domain.cold (/lib64/libc.so.6+0x2679b)
 #9 0x00007fbec5658187 (/lib64/libc.so.6+0x36187)
#10 0x0000000001b7cfe4 llvm::InstCombinerImpl::foldCmpLoadFromIndexedGlobal(llvm
::LoadInst*, llvm::GetElementPtrInst*, llvm::GlobalVariable*, llvm::CmpInst&, ll

Yesterday's compiler has git hash 6246b49
and today's has 1cf75cc.

That looks like 142 commits, so that should be easy (for someone who knows
what they are doing), to bisect.

self-assigned this
on May 22, 2024
removed
needs-reductionLarge reproducer that should be reduced into a simpler form
on May 22, 2024
dtcxzyw

dtcxzyw commented on May 22, 2024

@dtcxzyw
Member

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

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@opcode_timings = constant [2 x ptr] [ptr @timing_mr, ptr @timing_mr]
@timing_mr = external global i32

define i1 @codegen_timing_486_prefix(i64 %idxprom) {
entry:
  %arrayidx = getelementptr [2 x ptr], ptr @opcode_timings, i64 0, i64 %idxprom
  %0 = load ptr, ptr %arrayidx, align 8
  %cmp.i = icmp ult ptr %0, inttoptr (i64 10001 to ptr)
  ret i1 %cmp.i
}
opt: /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/include/llvm/Support/Casting.h:109: static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = llvm::UndefValue; From = llvm::Constant]: Assertion `Val && "isa<> used on a null pointer"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: bin/opt -passes=instcombine reduced.ll -S
 #0 0x0000732e2ac08db0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.19.0git+0x208db0)
 #1 0x0000732e2ac05dbf llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.19.0git+0x205dbf)
 #2 0x0000732e2ac05f15 SignalHandler(int) Signals.cpp:0:0
 #3 0x0000732e2a642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000732e2a6969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x0000732e2a6969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x0000732e2a6969fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x0000732e2a642476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x0000732e2a6287f3 abort ./stdlib/abort.c:81:7
 #9 0x0000732e2a62871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x0000732e2a639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x0000732e264f7f99 llvm::InstCombinerImpl::foldCmpLoadFromIndexedGlobal(llvm::LoadInst*, llvm::GetElementPtrInst*, llvm::GlobalVariable*, llvm::CmpInst&, llvm::ConstantInt*) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMInstCombine.so.19.0git+0xd7f99)
#12 0x0000732e2652b2a3 llvm::InstCombinerImpl::visitICmpInst(llvm::ICmpInst&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMInstCombine.so.19.0git+0x10b2a3)
#13 0x0000732e2647f6e4 llvm::InstCombinerImpl::run() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMInstCombine.so.19.0git+0x5f6e4)
#14 0x0000732e264806a4 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::LoopInfo*, llvm::InstCombineOptions const&) InstructionCombining.cpp:0:0
#15 0x0000732e264815cc llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMInstCombine.so.19.0git+0x615cc)
#16 0x0000732e27ec3516 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMPasses.so.19.0git+0xc3516)
#17 0x0000732e24d51300 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.19.0git+0x351300)
#18 0x0000732e29ed3cf6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.19.0git+0xd3cf6)
#19 0x0000732e24d4ff97 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.19.0git+0x34ff97)
#20 0x0000732e29ed5426 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.19.0git+0xd5426)
#21 0x0000732e24d4e1b1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.19.0git+0x34e1b1)
#22 0x0000732e2b0996c4 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) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.19.0git+0x2d6c4)
#23 0x0000732e2b0a6b3a optMain (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.19.0git+0x3ab3a)
#24 0x0000732e2a629d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#25 0x0000732e2a629e40 call_init ./csu/../csu/libc-start.c:128:20
#26 0x0000732e2a629e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#27 0x0000610f2523b095 _start (bin/opt+0x1095)
Aborted (core dumped)

LLVM version: cf12830

dcb314

dcb314 commented on May 22, 2024

@dcb314
Author

Final reduced C code seems to be:

int timing_int;
static int *opcode_timings[] = {&timing_int, 0};
char codegen_timing_486_prefix_prefix;
void codegen_timing_486_prefix() {
  if ((long)opcode_timings[codegen_timing_486_prefix_prefix] & ~0xffff)
    *(int *)0;
}
dtcxzyw

dtcxzyw commented on May 22, 2024

@dtcxzyw
Member

Fixed by 0748a98

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @dcb314@EugeneZelenko@Endilll@dtcxzyw@llvmbot

    Issue actions

      llvm/include/llvm/Support/Casting.h:109: Assertion failed · Issue #93029 · llvm/llvm-project