llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.8k stars 11.91k forks source link

LiveDebugVariables crash with -opt-bisect-limit #57997

Closed aeubanks closed 1 year ago

aeubanks commented 2 years ago
$ cat /tmp/a.ll
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define void @f(i64 %0) !dbg !5 {
  call void @llvm.dbg.value(metadata i64 %0, metadata !7, metadata !DIExpression()), !dbg !11
  %switch = icmp eq i64 %0, 0
  tail call void @h(i1 %switch)
  %2 = tail call ptr @g()
  ret void, !dbg !12
}

declare ptr @g() local_unnamed_addr

declare void @llvm.dbg.value(metadata, metadata, metadata)

declare void @h(i1)

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

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, globals: !2, nameTableKind: None)
!1 = !DIFile(filename: "a.cc", directory: "/tmp", checksumkind: CSK_MD5, checksum: "d23f5e660fbe3ad0736b70a51025225d")
!2 = !{}
!3 = !{i32 7, !"Dwarf Version", i32 5}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 221, type: !6, scopeLine: 221, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
!6 = !DISubroutineType(types: !2)
!7 = !DILocalVariable(name: "count", arg: 3, scope: !5, file: !1, line: 221, type: !8)
!8 = !DIDerivedType(tag: DW_TAG_typedef, name: "size_t", file: !9, line: 46, baseType: !10)
!9 = !DIFile(filename: "stddef.h", directory: "/tmp/", checksumkind: CSK_MD5, checksum: "89af46ad12914219411a5eaafda2889f")
!10 = !DIBasicType(name: "unsigned long", size: 64, encoding: DW_ATE_unsigned)
!11 = !DILocation(line: 0, scope: !5)
!12 = !DILocation(line: 250, column: 1, scope: !5)
$ ./build/rel/bin/llc -O3 -o /dev/null -opt-bisect-limit=6 /tmp/a.ll
...
llc: ../../llvm/lib/CodeGen/LiveDebugVariables.cpp:881: MachineBasicBlock::iterator (anonymous namespace)::LDVImpl::handleDebugInstr(MachineInstr &, SlotIndex): Assertion `!MI.getOperand(0).isReg() || !MI.getOperand(0).getReg().isVirtual()' failed.

looks similar to https://github.com/llvm/llvm-project/issues/53937 @OCHyams @jmorse

jmorse commented 2 years ago

I looked at this for a bit then got side-tracked; it is indeed similar to #53937, with the same root cause, the optimisation level turns out to be a poor indicator for which flavour of variable locations we generated the function with. A quick attempt to hack around it didn't work; I suspect the correct way forwards is to add a MachineFunction flag recording what flavour of debug-info we have. This is slightly unfortunate, but robust.

jmorse commented 1 year ago

(Now getting time address this)

jmorse commented 1 year ago

https://reviews.llvm.org/D141387

jmorse commented 1 year ago

Landed in 9f8544713ad8e57fb74cbfce3fbc7fff523e549f