workaround for debug info bug?

I just reported this bug:
https://bugs.llvm.org/show_bug.cgi?id=35314

This very simple IR is causing infinite recursion in llvm::DwarfUnit::getOrCreateTypeDIE in llvm 5.0.0.

Is there a workaround? Is anyone willing to save me a recompile and check if this is fixed in 5.0.1 or trunk?

clang -c test.ll repros the issue.

; ModuleID = ‘test’
source_filename = “test”
target datalayout = “e-m:e-i64:64-f80:128-n8:16:32:64-S128”
target triple = “x86_64-unknown-linux-gnu”

%Foo = type { float }
%“u8” = type { i8*, i64 }

@0 = internal unnamed_addr constant %Foo zeroinitializer, align 4

; Function Attrs: nobuiltin noreturn nounwind
define internal fastcc void @panic(%“u8”* byval nonnull readonly) unnamed_addr #0 !dbg !4 {
Entry:
call void @llvm.dbg.declare(metadata %“u8”* %0, metadata !18, metadata !19), !dbg !20
br label %WhileCond, !dbg !21

WhileCond: ; preds = %WhileCond, %Entry
br label %WhileCond, !dbg !21
}

; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1

; Function Attrs: nobuiltin nounwind
define void @entry() #2 !dbg !24 {
Entry:
%f = alloca %Foo, align 4
%0 = bitcast %Foo* %f to i8*, !dbg !36
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* bitcast (%Foo* @0 to i8*), i64 4, i32 4, i1 false), !dbg !36
call void @llvm.dbg.declare(metadata %Foo* %f, metadata !28, metadata !19), !dbg !36
ret void, !dbg !37
}

; Function Attrs: argmemonly nounwind
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1) #3

attributes #0 = { nobuiltin noreturn nounwind “no-frame-pointer-elim”=“true” “no-frame-pointer-elim-non-leaf” }
attributes #1 = { nounwind readnone speculatable }
attributes #2 = { nobuiltin nounwind “no-frame-pointer-elim”=“true” “no-frame-pointer-elim-non-leaf” }
attributes #3 = { argmemonly nounwind }

!llvm.module.flags = !{!0}
= !{!1}

!0 = !{i32 2, !“Debug Info Version”, i32 3}
!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: “zig 0.1.1.1f0d561”, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3)
!2 = !DIFile(filename: “test”, directory: “.”)
!3 = !{}
!4 = distinct !DISubprogram(name: “panic”, scope: !5, file: !5, line: 10, type: !6, isLocal: true, isDefinition: true, scopeLine: 10, isOptimized: false, unit: !1, variables: !17)
!5 = !DIFile(filename: “test.zig”, directory: “/home/andy/dev/zig/build”)
!6 = !DISubroutineType(types: !7)
!7 = !{!8, !9}
!8 = !DIBasicType(name: “void”, encoding: DW_ATE_unsigned)
!9 = !DIDerivedType(tag: DW_TAG_pointer_type, name: “&const u8”, baseType: !10, size: 64, align: 64)
!10 = !DICompositeType(tag: DW_TAG_structure_type, name: “u8”, size: 128, align: 64, elements: !11)
!11 = !{!12, !15}
!12 = !DIDerivedType(tag: DW_TAG_member, name: “ptr”, scope: !10, baseType: !13, size: 64, align: 64)
!13 = !DIDerivedType(tag: DW_TAG_pointer_type, name: “&u8”, baseType: !14, size: 64, align: 64)
!14 = !DIBasicType(name: “u8”, size: 8, encoding: DW_ATE_unsigned_char)
!15 = !DIDerivedType(tag: DW_TAG_member, name: “len”, scope: !10, baseType: !16, size: 64, align: 64, offset: 64)
!16 = !DIBasicType(name: “usize”, size: 64, encoding: DW_ATE_unsigned)
!17 = !{!18}
!18 = !DILocalVariable(name: “msg”, arg: 1, scope: !4, file: !5, line: 10, type: !10)
!19 = !DIExpression()
!20 = !DILocation(line: 10, column: 14, scope: !4)
!21 = !DILocation(line: 10, column: 45, scope: !22)
!22 = distinct !DILexicalBlock(scope: !23, file: !5, line: 10, column: 43)
!23 = distinct !DILexicalBlock(scope: !4, file: !5, line: 10, column: 14)
!24 = distinct !DISubprogram(name: “entry”, scope: !5, file: !5, line: 6, type: !25, isLocal: false, isDefinition: true, scopeLine: 6, isOptimized: false, unit: !1, variables: !27)
!25 = !DISubroutineType(types: !26)
!26 = !{!8}
!27 = !{!28}
!28 = !DILocalVariable(name: “f”, scope: !29, file: !5, line: 7, type: !30)
!29 = distinct !DILexicalBlock(scope: !24, file: !5, line: 6, column: 19)
!30 = distinct !DICompositeType(tag: DW_TAG_union_type, name: “Foo”, scope: !30, file: !5, line: 1, size: 32, align: 32, elements: !31)
!31 = !{!32, !34}
!32 = !DIDerivedType(tag: DW_TAG_member, name: “float”, scope: !30, file: !5, line: 2, baseType: !33, size: 32, align: 32)
!33 = !DIBasicType(name: “f32”, size: 32, encoding: DW_ATE_float)
!34 = !DIDerivedType(tag: DW_TAG_member, name: “int”, scope: !30, file: !5, line: 3, baseType: !35, size: 32, align: 32)
!35 = !DIBasicType(name: “u32”, size: 32, encoding: DW_ATE_unsigned)
!36 = !DILocation(line: 7, column: 5, scope: !29)
!37 = !DILocation(line: 6, column: 19, scope: !24)

Test on Mac, with not latest but trunk code. I get error below:

$ clang -c test.ll
warning: overriding the module target triple with x86_64-apple-macosx10.13.0 [-Woverride-module]
clang-6.0: error: unable to execute command: Illegal instruction: 4

​I see no infinite recursion here.​

Seems like something infinite-recursion like to me:
$ clang --version
clang version 6.0.0 (trunk 317833)
Target: powerpc64le-unknown-linux-gnu
$ clang -c test.ll
warning: overriding the module target triple with powerpc64le-unknown-linux-gnu [-Woverride-module]

#255 0x0000000012b07a78 llvm::DwarfUnit::getOrCreateTypeDIE(llvm::MDNode const*)

So I’d say it reproduces.

It reproduces with trunk on linux here as well.


#231 0x0000000004c5f822 llvm::DwarfUnit::getOrCreateContextDIE(llvm::DIScope const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:671:0
#232 0x0000000004c5faf2 llvm::DwarfUnit::getOrCreateTypeDIE(llvm::MDNode const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:714:0
#233 0x0000000004c5f822 llvm::DwarfUnit::getOrCreateContextDIE(llvm::DIScope const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:671:0
#234 0x0000000004c5faf2 llvm::DwarfUnit::getOrCreateTypeDIE(llvm::MDNode const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:714:0
#235 0x0000000004c5f822 llvm::DwarfUnit::getOrCreateContextDIE(llvm::DIScope const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:671:0
#236 0x0000000004c5faf2 llvm::DwarfUnit::getOrCreateTypeDIE(llvm::MDNode const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:714:0
#237 0x0000000004c5f822 llvm::DwarfUnit::getOrCreateContextDIE(llvm::DIScope const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:671:0
#238 0x0000000004c5faf2 llvm::DwarfUnit::getOrCreateTypeDIE(llvm::MDNode const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:714:0
#239 0x0000000004c5f822 llvm::DwarfUnit::getOrCreateContextDIE(llvm::DIScope const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:671:0
#240 0x0000000004c5faf2 llvm::DwarfUnit::getOrCreateTypeDIE(llvm::MDNode const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:714:0
#241 0x0000000004c5f822 llvm::DwarfUnit::getOrCreateContextDIE(llvm::DIScope const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:671:0
#242 0x0000000004c5faf2 llvm::DwarfUnit::getOrCreateTypeDIE(llvm::MDNode const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:714:0
#243 0x0000000004c5f822 llvm::DwarfUnit::getOrCreateContextDIE(llvm::DIScope const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:671:0
#244 0x0000000004c5faf2 llvm::DwarfUnit::getOrCreateTypeDIE(llvm::MDNode const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:714:0
#245 0x0000000004c5f822 llvm::DwarfUnit::getOrCreateContextDIE(llvm::DIScope const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:671:0
#246 0x0000000004c5faf2 llvm::DwarfUnit::getOrCreateTypeDIE(llvm::MDNode const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:714:0
#247 0x0000000004c5f822 llvm::DwarfUnit::getOrCreateContextDIE(llvm::DIScope const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:671:0
#248 0x0000000004c5faf2 llvm::DwarfUnit::getOrCreateTypeDIE(llvm::MDNode const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:714:0
#249 0x0000000004c5f822 llvm::DwarfUnit::getOrCreateContextDIE(llvm::DIScope const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:671:0
#250 0x0000000004c5faf2 llvm::DwarfUnit::getOrCreateTypeDIE(llvm::MDNode const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:714:0
#251 0x0000000004c5f822 llvm::DwarfUnit::getOrCreateContextDIE(llvm::DIScope const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:671:0
#252 0x0000000004c5faf2 llvm::DwarfUnit::getOrCreateTypeDIE(llvm::MDNode const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:714:0
#253 0x0000000004c5f822 llvm::DwarfUnit::getOrCreateContextDIE(llvm::DIScope const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:671:0
#254 0x0000000004c5faf2 llvm::DwarfUnit::getOrCreateTypeDIE(llvm::MDNode const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:714:0
#255 0x0000000004c5f822 llvm::DwarfUnit::getOrCreateContextDIE(llvm::DIScope const*) /home/jimshinns/llvm-6.0-src/lib/CodeGen/AsmPrinter/DwarfUnit.cpp:671:0
Stack dump:
0. Program arguments: /usr/local/bin/clang-6.0 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name test.ll -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /home/jimshinns/test.gcno -resource-dir /usr/local/lib/clang/6.0.0 -fdebug-compilation-dir /home/jimshinns -ferror-limit 19 -fmessage-length 80 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o test.o -x ir test.ll

  1. Code generation
    clang-6.0: error: unable to execute command: Segmentation fault (core dumped)
    clang-6.0: error: clang frontend command failed due to signal (use -v to see invocation)
    clang version 6.0.0 (trunk 318165)
    Target: x86_64-unknown-linux-gnu
    Thread model: posix
    InstalledDir: /usr/local/bin

Thanks for the repros.

I think this line may be the problem:

!30 = distinct !DICompositeType(tag: DW_TAG_union_type, name: “Foo”, scope: !30, file: !5, line: 1, size: 32, align: 32, elements: !31)

The scope is itself. I’ll investigate this in the frontend.

Please file a bug with this example. I think the verifier ought to catch this kind of thing.

–paulr