llvm / llvm/llvm-project

[SROA][DebugInfo] Crash when `asm goto` with SEH: `MCExpr.cpp:223: llvm::MCSymbolRefExpr::MCSymbolRefExpr(const MCSymbol *, Spec, SMLoc): Assertion 'Symbol' failed.`

Open
#221,544 1 comment 0 reactions 0 assignees View on GitHub
confirmed crash-on-valid llvm:mc
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

https://godbolt.org/z/favoG15ja

`-g`, `-O`, and the `sroa` pass are required to reproduce.

reproducer:
```
$ ~/llvm/build/work-stage2-shared/bin/clang --target=x86_64-mingw -S dir.cpp -g -fno-exceptions -fno-rtti -O -o - -emit-llvm -Xclang -disable-llvm-passes | \
~/llvm/build/work-stage2-shared/bin/opt -passes=sroa - -o - | \
~/llvm/build/work-stage2-shared/bin/llc - > /dev/null

llc: /home/kikairoya/llvm/work/llvm/lib/MC/MCExpr.cpp:223: llvm::MCSymbolRefExpr::MCSymbolRefExpr(const MCSymbol *, Spec, SMLoc): Assertion `Symbol' 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: /home/kikairoya/llvm/build/work-stage2-shared/bin/llc -
#0 0x00007e793f07e2bb llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/kikairoya/llvm/work/llvm/lib/Support/Unix/Signals.inc:931:13
#1 0x00007e793f07ba44 llvm::sys::RunSignalHandlers() /home/kikairoya/llvm/work/llvm/lib/Support/Signals.cpp:109:18
#2 0x00007e793f07eccb SignalHandler(int, siginfo_t*, void*) /home/kikairoya/llvm/work/llvm/lib/Support/Unix/Signals.inc:474:38
#3 0x00007e793e63e6f0 (/usr/lib/libc.so.6+0x3e6f0)
#4 0x00007e793e69a17c (/usr/lib/libc.so.6+0x9a17c)
#5 0x00007e793e63e5d0 raise (/usr/lib/libc.so.6+0x3e5d0)
#6 0x00007e793e625685 abort (/usr/lib/libc.so.6+0x25685)
#7 0x00007e793e626704 (/usr/lib/libc.so.6+0x26704)
#8 0x00007e793e6361f2 __assert_fail (/usr/lib/libc.so.6+0x361f2)
#9 0x00007e794178039d (/home/kikairoya/llvm/build/work-stage2-shared/bin/../lib/libLLVMMC.so.24.0git+0xd539d)
#10 0x00007e79417803de llvm::MCSymbolRefExpr::create(llvm::MCSymbol const*, unsigned short, llvm::MCContext&, llvm::SMLoc) /home/kikairoya/llvm/work/llvm/lib/MC/MCExpr.cpp:0:20
#11 0x00007e79417a2790 llvm::MCStreamer::emitSymbolValue(llvm::MCSymbol const*, unsigned int, bool) /home/kikairoya/llvm/work/llvm/lib/MC/MCStreamer.cpp:186:5
#12 0x00007e79423e4563 void emitRangeList, emitLocList(llvm::DwarfDebug&, llvm::AsmPrinter*, llvm::DebugLocStream::List const&)::$_0>(llvm::DwarfDebug&, llvm::AsmPrinter*, llvm::MCSymbol*, llvm::ArrayRef const&, llvm::DwarfCompileUnit const&, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, llvm::StringRef (*)(unsigned int), bool, emitLocList(llvm::DwarfDebug&, llvm::AsmPrinter*, llvm::DebugLocStream::List const&)::$_0) /home/kikairoya/llvm/work/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:0:29
#13 0x00007e79423e4563 emitLocList(llvm::DwarfDebug&, llvm::AsmPrinter*, llvm::DebugLocStream::List const&) /home/kikairoya/llvm/work/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:3596:3
#14 0x00007e79423e4563 llvm::DwarfDebug::emitDebugLocImpl(llvm::MCSection*) /home/kikairoya/llvm/work/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:3617:5
#15 0x00007e79423d83b1 llvm::DwarfDebug::emitAbbreviations() /home/kikairoya/llvm/work/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:3007:23
#16 0x00007e79423d83b1 llvm::DwarfDebug::endModule() /home/kikairoya/llvm/work/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1603:3
#17 0x00007e794239686a llvm::AsmPrinter::doFinalization(llvm::Module&) /home/kikairoya/llvm/work/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:3092:22
#18 0x00007e793f6cde9a llvm::FPPassManager::doFinalization(llvm::Module&) /home/kikairoya/llvm/work/llvm/lib/IR/LegacyPassManager.cpp:1489:13
#19 0x00007e793f6c829d (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/kikairoya/llvm/work/llvm/lib/IR/LegacyPassManager.cpp:1623:13
#20 0x00007e793f6c829d llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/kikairoya/llvm/work/llvm/lib/IR/LegacyPassManager.cpp:533:44
#21 0x000062f62b41d44e compileModule(char**, llvm::SmallVectorImpl&, llvm::LLVMContext&, std::__cxx11::basic_string, std::allocator>&) /home/kikairoya/llvm/work/llvm/tools/llc/llc.cpp:885:17
#22 0x000062f62b41a553 main /home/kikairoya/llvm/work/llvm/tools/llc/llc.cpp:459:13
#23 0x00007e793e627781 (/usr/lib/libc.so.6+0x27781)
#24 0x00007e793e6278b9 __libc_start_main (/usr/lib/libc.so.6+0x278b9)
#25 0x000062f62b4197c5 _start (/home/kikairoya/llvm/build/work-stage2-shared/bin/llc+0x127c5)
```
`dir.cpp` (manually reduced from `newlib-cygwin/winsup/cygwin/dir.cc`):

```c++
void set_errno(int);

void fn1(int x) {
__label__ __l_try, __l_except, __l_endtry;
__asm__ goto (
".seh_handler handler_fn, @except\n\t"
".seh_handlerdata\n\t"
".long 1\n\t"
".rva %l[__l_try],%l[__l_endtry],%l[__l_except],%l[__l_except]\n\t"
".seh_endprologue\n\t"
: : : : __l_try, __l_endtry, __l_except);
{
__l_try:
__asm__ __volatile__ ("" ::: "memory");
goto __l_endtry;
}
{
__l_except:
set_errno(x);
}
__l_endtry:
__asm__ __volatile__ ("" ::: "memory");
}

struct base {
virtual ~base();
};

struct context_impl: base {
~context_impl() {}
};

void fn2() {
context_impl ctx;
}

```

more reduced IR which requires SROA to crash:

```
target datalayout = "e-m:w-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-windows-gnu"

$_ZN12context_implC2Ev = comdat any

define void @_Z3fn1i(i32 %x) !dbg !4 {
entry:
%x.addr = alloca i32, align 4
store i32 %x, ptr %x.addr, align 4
#dbg_declare(ptr %x.addr, !7, !DIExpression(), !9)
callbr void asm sideeffect ".seh_handler handler_fn, @except\0A\09.seh_handlerdata\0A\09.long 1\0A\09.rva ${0:l},${1:l},${2:l},${2:l}\0A\09.seh_endprologue\0A\09", "!i,!i,!i,~{dirflag},~{fpsr},~{flags}"()
to label %asm.fallthrough [label %__l_try, label %__l_endtry, label %__l_except], !dbg !10

asm.fallthrough: ; preds = %entry
ret void

__l_try: ; preds = %entry
ret void

__l_except: ; preds = %entry
call void null(i32 0)
ret void

__l_endtry: ; preds = %entry
ret void
}

define void @_ZN12context_implC2Ev(ptr %this) comdat !dbg !11 {
entry:
ret void
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 24.0.0git (llvm-project cygwinmod)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !2, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "dir.cpp", directory: "/tmp")
!2 = !{}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = distinct !DISubprogram(name: "fn1", linkageName: "_Z3fn1i", scope: !1, file: !1, line: 3, type: !5, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2, keyInstructions: true)
!5 = distinct !DISubroutineType(types: !6)
!6 = !{null}
!7 = !DILocalVariable(name: "x", arg: 1, scope: !4, file: !1, line: 3, type: !8)
!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!9 = !DILocation(line: 3, column: 14, scope: !4)
!10 = !DILocation(line: 5, column: 3, scope: !4, atomGroup: 759, atomRank: 1)
!11 = distinct !DISubprogram(name: "context_impl", linkageName: "_ZN12context_implC2Ev", scope: !12, file: !1, line: 29, type: !14, scopeLine: 29, flags: DIFlagArtificial | DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !15, retainedNodes: !2, keyInstructions: true)
!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "context_impl", file: !1, line: 29, size: 64, flags: DIFlagTypePassByReference | DIFlagNonTrivial, elements: !2, vtableHolder: !13, identifier: "_ZTS12context_impl")
!13 = !DICompositeType(tag: DW_TAG_structure_type, name: "base", file: !1, line: 25, size: 64, flags: DIFlagFwdDecl | DIFlagNonTrivial, identifier: "_ZTS4base")
!14 = distinct !DISubroutineType(types: !6)
!15 = !DISubprogram(name: "context_impl", linkageName: "_ZN12context_implC4Ev", scope: !12, type: !14, flags: DIFlagArtificial | DIFlagPrototyped, spFlags: DISPFlagOptimized)
```

Contributor guide

Open the contributing guide

Research direction

Start by running the provided clang, opt, and llc pipeline with the reduced dir.cpp or IR reproducer. Trace the crash from lib/CodeGen/AsmPrinter/DwarfDebug.cpp through MCStreamer::emitSymbolValue and inspect the SROA-produced IR and debug locations. Done means the reproducer no longer asserts, with a regression test covering the asm goto and SEH case.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.