llvm / llvm/llvm-project

opt crashes in llvm/lib/IR/DebugInfo.cpp:544

Open
#173,128 4 comments 0 reactions 0 assignees View on GitHub
crash debuginfo generated by fuzzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

When running opt on the following IR, opt crashes.
I am not sure whether this is a valid case. If using opt in this way is not appropriate, I am open to closing this issue.
godbolt: https://godbolt.org/z/oMjoTPEMz

llvm version 50ae726bb3498

test.ll

```
define i32 @negativity_1() {
br label %loop

loop: ; preds = %loop, %0
%phi = phi i32 [ 0, %0 ], [ %and2, %loop ]
%and2 = and i32 %phi, -1
%and3 = and i32 %and2, -32768
%cond = icmp eq i32 %and3, 0
br i1 %cond, label %exit, label %loop,!llvm.loop!1

exit: ; preds = %loop
ret i32 %and3
}

!0 =!{}
!1 = distinct!{}

```

commads
./bin/opt test.ll -S

stacktrace

```
opt: /root/llvm-project/llvm/lib/IR/DebugInfo.cpp:544: llvm::MDNode* stripDebugLocFromLoopID(llvm::MDNode*): Assertion `!N->operands().empty() && "Missing self reference?"' 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 -S
#0 0x00000000059afac8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x59afac8)
#1 0x00000000059ac974 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x59ac974)
#2 0x00000000059acaea SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007cd9aa842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007cd9aa8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007cd9aa842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007cd9aa8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007cd9aa82871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007cd9aa839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x00000000056523c9 llvm::stripDebugInfo(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x56523c9)
#10 0x0000000005652662 llvm::StripDebugInfo(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5652662)
#11 0x000000000559f284 llvm::UpgradeDebugInfo(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x559f284)
#12 0x000000000537ef68 llvm::LLParser::validateEndOfModule(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x537ef68)
#13 0x00000000053b739b llvm::LLParser::Run(bool, llvm::function_ref, std::allocator>> (llvm::StringRef, llvm::StringRef)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x53b739b)
#14 0x00000000053601b7 parseAssemblyInto(llvm::MemoryBufferRef, llvm::Module*, llvm::ModuleSummaryIndex*, llvm::SMDiagnostic&, llvm::SlotMapping*, bool, llvm::function_ref, std::allocator>> (llvm::StringRef, llvm::StringRef)>, llvm::AsmParserContext*) Parser.cpp:0:0
#15 0x0000000005360361 llvm::parseAssembly(llvm::MemoryBufferRef, llvm::SMDiagnostic&, llvm::LLVMContext&, llvm::SlotMapping*, llvm::function_ref, std::allocator>> (llvm::StringRef, llvm::StringRef)>, llvm::AsmParserContext*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5360361)
#16 0x000000000535b1f1 llvm::parseIR(llvm::MemoryBufferRef, llvm::SMDiagnostic&, llvm::LLVMContext&, llvm::ParserCallbacks, llvm::AsmParserContext*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x535b1f1)
#17 0x000000000535d414 llvm::parseIRFile(llvm::StringRef, llvm::SMDiagnostic&, llvm::LLVMContext&, llvm::ParserCallbacks, llvm::AsmParserContext*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x535d414)
#18 0x000000000096ea63 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x96ea63)
#19 0x00007cd9aa829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#20 0x00007cd9aa829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#21 0x0000000000967a85 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x967a85)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```

Contributor guide

Open the contributing guide

Research direction

Start with llvm/lib/IR/DebugInfo.cpp:544 and trace the stripDebugInfo, StripDebugInfo, and UpgradeDebugInfo calls shown in the stack trace. Reproduce the assertion with the supplied test.ll using opt, then determine the expected handling for this loop metadata and add regression coverage showing that the input no longer crashes.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.