Closed
Description
This code crashed at O2:
static char c = -2, l;
char d;
int e, f, b, k;
static char *g = &d;
long h;
static int *i = &f;
char a;
int m(int n) {
if (n < 0)
return n;
return 0;
}
void o(long n) { *i = m(c + 6) + c + n; }
void main() {
a = c;
char *j[2] = {&g};
for (; b;)
;
*g = 0;
e |= 0 != h;
l = *g;
o(l != 0);
c = 7;
for (;; c = 0)
k = *i + *i;
}
Compiler Explorer: https://godbolt.org/z/r96WqYacv
Bisected to 3e1b55c which was committed by @nikic
The crash is:
clang: /root/llvm-project/llvm/include/llvm/ADT/APInt.h:127: llvm::APInt::APInt(unsigned int, uint64_t, bool, bool): Assertion `llvm::isUIntN(BitWidth, val) && "Value is not an N-bit unsigned value"' failed.
Backtrace:
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O2 -Wall -Wextra -fno-strict-aliasing <source>
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module '<source>'.
4. Running pass 'X86 DAG->DAG Instruction Selection' on function '@main'
#0 0x0000000003c01b78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c01b78)
#1 0x0000000003bff87c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3bff87c)
#2 0x0000000003b4cd78 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007dabed242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007dabed2969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007dabed242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007dabed2287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007dabed22871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007dabed239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x0000000004ed6c79 llvm::SelectionDAG::getConstant(unsigned long, llvm::SDLoc const&, llvm::EVT, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ed6c79)
#10 0x00000000026d7805 (anonymous namespace)::X86DAGToDAGISel::matchIndexRecursively(llvm::SDValue, (anonymous namespace)::X86ISelAddressMode&, unsigned int) X86ISelDAGToDAG.cpp:0:0
#11 0x00000000026d7c89 (anonymous namespace)::X86DAGToDAGISel::matchIndexRecursively(llvm::SDValue, (anonymous namespace)::X86ISelAddressMode&, unsigned int) X86ISelDAGToDAG.cpp:0:0
#12 0x00000000026d952a (anonymous namespace)::X86DAGToDAGISel::matchAddressRecursively(llvm::SDValue, (anonymous namespace)::X86ISelAddressMode&, unsigned int) X86ISelDAGToDAG.cpp:0:0
#13 0x00000000026dab90 (anonymous namespace)::X86DAGToDAGISel::selectLEAAddr(llvm::SDValue, llvm::SDValue&, llvm::SDValue&, llvm::SDValue&, llvm::SDValue&, llvm::SDValue&) X86ISelDAGToDAG.cpp:0:0
#14 0x00000000026eb1c7 (anonymous namespace)::X86DAGToDAGISel::CheckComplexPattern(llvm::SDNode*, llvm::SDNode*, llvm::SDValue, unsigned int, llvm::SmallVectorImpl<std::pair<llvm::SDValue, llvm::SDNode*>>&) X86ISelDAGToDAG.cpp:0:0
#15 0x0000000004f0ba37 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f0ba37)
#16 0x00000000026e0cf1 (anonymous namespace)::X86DAGToDAGISel::Select(llvm::SDNode*) X86ISelDAGToDAG.cpp:0:0
#17 0x0000000004f0106b llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f0106b)
#18 0x0000000004f1026a llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f1026a)
#19 0x0000000004f137e9 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f137e9)
#20 0x0000000004f14aa0 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f14aa0)
#21 0x0000000004f0544f llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f0544f)
#22 0x0000000002f54029 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#23 0x000000000355b57f llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x355b57f)
#24 0x000000000355b931 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x355b931)
#25 0x000000000355c1d1 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x355c1d1)
#26 0x0000000003eb4a33 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3eb4a33)
#27 0x000000000458355e clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x458355e)
#28 0x000000000653a51c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x653a51c)
#29 0x0000000004583938 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4583938)
#30 0x000000000483e9b9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x483e9b9)
#31 0x00000000047be64e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47be64e)
#32 0x0000000004929a1e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4929a1e)
#33 0x0000000000cb12df cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcb12df)
#34 0x0000000000ca8e7a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#35 0x00000000045c6b89 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#36 0x0000000003b4d224 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b4d224)
#37 0x00000000045c717f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#38 0x000000000458d41d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x458d41d)
#39 0x000000000458e50d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x458e50d)
#40 0x00000000045958c5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45958c5)
#41 0x0000000000cae123 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcae123)
#42 0x0000000000b82494 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xb82494)
#43 0x00007dabed229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#44 0x00007dabed229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#45 0x0000000000ca892e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xca892e)