1 ; REQUIRES: object-emission 2 3 ; RUN: %llc_dwarf -O0 -filetype=obj < %s | llvm-dwarfdump -v -debug-info - | FileCheck %s 4 5 ; Testing that two distinct (distinct by writing them in separate files, while 6 ; still fulfilling C++'s ODR by having identical token sequences) functions, 7 ; linked under LTO, get plausible debug info (and don't crash). 8 9 ; Built from source: 10 ; $ clang++ a.cpp b.cpp -g -c -emit-llvm 11 ; $ llvm-link a.bc b.bc -o ab.bc 12 13 ; This change is intended to tickle a case where the subprogram MDNode 14 ; associated with the llvm::Function will differ from the subprogram 15 ; referenced by the DbgLocs in the function. 16 17 ; $ sed -ie "s/!12, !0/!0, !12/" ab.ll 18 ; $ cat a.cpp 19 ; inline int func(int i) { 20 ; return i * 2; 21 ; } 22 ; int (*x)(int) = &func; 23 ; $ cat b.cpp 24 ; inline int func(int i) { 25 ; return i * 2; 26 ; } 27 ; int (*y)(int) = &func; 28 29 ; The DISubprogram should show up in compile unit a. 30 ; CHECK: DW_TAG_compile_unit 31 ; CHECK-NOT: DW_TAG 32 ; CHECK: DW_AT_name {{.*}}"b.cpp" 33 ; CHECK-NOT: DW_TAG_subprogram 34 35 ; CHECK: DW_TAG_compile_unit 36 ; CHECK-NOT: DW_TAG 37 ; CHECK: DW_AT_name {{.*}}"a.cpp" 38 ; CHECK: DW_AT_name {{.*}} "func" 39 40 source_filename = "test/DebugInfo/Generic/cross-cu-linkonce-distinct.ll" 41 42 @x = global i32 (i32)* @_Z4funci, align 8, !dbg !0 43 @y = global i32 (i32)* @_Z4funci, align 8, !dbg !7 44 45 ; Function Attrs: inlinehint nounwind uwtable 46 define linkonce_odr i32 @_Z4funci(i32 %i) #0 !dbg !18 { 47 %1 = alloca i32, align 4 48 store i32 %i, i32* %1, align 4 49 call void @llvm.dbg.declare(metadata i32* %1, metadata !19, metadata !20), !dbg !21 50 %2 = load i32, i32* %1, align 4, !dbg !22 51 %3 = mul nsw i32 %2, 2, !dbg !22 52 ret i32 %3, !dbg !22 53 } 54 55 ; Function Attrs: nounwind readnone 56 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 57 58 attributes #0 = { inlinehint nounwind uwtable } 59 attributes #1 = { nounwind readnone } 60 61 !llvm.dbg.cu = !{!10, !13} 62 !llvm.module.flags = !{!15, !16} 63 !llvm.ident = !{!17, !17} 64 65 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 66 !1 = !DIGlobalVariable(name: "x", scope: null, file: !2, line: 4, type: !3, isLocal: false, isDefinition: true) 67 !2 = !DIFile(filename: "a.cpp", directory: "/tmp/dbginfo") 68 !3 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !4, size: 64, align: 64) 69 !4 = !DISubroutineType(types: !5) 70 !5 = !{!6, !6} 71 !6 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 72 !7 = !DIGlobalVariableExpression(var: !8, expr: !DIExpression()) 73 !8 = !DIGlobalVariable(name: "y", scope: null, file: !9, line: 4, type: !3, isLocal: false, isDefinition: true) 74 !9 = !DIFile(filename: "b.cpp", directory: "/tmp/dbginfo") 75 !10 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !9, producer: "clang version 3.5.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !11, retainedTypes: !11, globals: !12, imports: !11) 76 !11 = !{} 77 !12 = !{!7} 78 !13 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 3.5.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !11, retainedTypes: !11, globals: !14, imports: !11) 79 !14 = !{!0} 80 !15 = !{i32 2, !"Dwarf Version", i32 4} 81 !16 = !{i32 1, !"Debug Info Version", i32 3} 82 !17 = !{!"clang version 3.5.0 "} 83 !18 = distinct !DISubprogram(name: "func", linkageName: "_Z4funci", scope: !2, file: !2, line: 1, type: !4, isLocal: false, isDefinition: true, scopeLine: 1, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !13, retainedNodes: !11) 84 !19 = !DILocalVariable(name: "i", arg: 1, scope: !18, file: !2, line: 1, type: !6) 85 !20 = !DIExpression() 86 !21 = !DILocation(line: 1, scope: !18) 87 !22 = !DILocation(line: 2, scope: !18) 88 89