1*9880d681SAndroid Build Coastguard Worker; RUN: llvm-link %s %S/Inputs/replaced-function-matches-first-subprogram.ll -S | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker 3*9880d681SAndroid Build Coastguard Worker; Generated from C++ source: 4*9880d681SAndroid Build Coastguard Worker; 5*9880d681SAndroid Build Coastguard Worker; // repro/t.h 6*9880d681SAndroid Build Coastguard Worker; template <class T> struct Class { 7*9880d681SAndroid Build Coastguard Worker; int foo() { return 0; } 8*9880d681SAndroid Build Coastguard Worker; }; 9*9880d681SAndroid Build Coastguard Worker; // repro/d1/t1.cpp 10*9880d681SAndroid Build Coastguard Worker; #include "t.h" 11*9880d681SAndroid Build Coastguard Worker; int foo() { return Class<int>().foo(); } 12*9880d681SAndroid Build Coastguard Worker; // repro/d2/t2.cpp 13*9880d681SAndroid Build Coastguard Worker; #include "t.h" 14*9880d681SAndroid Build Coastguard Worker; template struct Class<int>; 15*9880d681SAndroid Build Coastguard Worker 16*9880d681SAndroid Build Coastguard Worker%struct.Class = type { i8 } 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Worker; CHECK: define i32 @_Z3foov(){{.*}} !dbg ![[SP1:[0-9]+]] 19*9880d681SAndroid Build Coastguard Workerdefine i32 @_Z3foov() !dbg !4 { 20*9880d681SAndroid Build Coastguard Workerentry: 21*9880d681SAndroid Build Coastguard Worker %tmp = alloca %struct.Class, align 1 22*9880d681SAndroid Build Coastguard Worker %call = call i32 @_ZN5ClassIiE3fooEv(%struct.Class* %tmp), !dbg !14 23*9880d681SAndroid Build Coastguard Worker ret i32 %call, !dbg !14 24*9880d681SAndroid Build Coastguard Worker} 25*9880d681SAndroid Build Coastguard Worker 26*9880d681SAndroid Build Coastguard Worker; CHECK: define weak_odr i32 @_ZN5ClassIiE3fooEv(%struct.Class* %this){{.*}} !dbg ![[SP2:[0-9]+]] { 27*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: } 28*9880d681SAndroid Build Coastguard Worker; CHECK: !dbg ![[LOC:[0-9]+]] 29*9880d681SAndroid Build Coastguard Workerdefine linkonce_odr i32 @_ZN5ClassIiE3fooEv(%struct.Class* %this) align 2 !dbg !7 { 30*9880d681SAndroid Build Coastguard Workerentry: 31*9880d681SAndroid Build Coastguard Worker %this.addr = alloca %struct.Class*, align 8 32*9880d681SAndroid Build Coastguard Worker store %struct.Class* %this, %struct.Class** %this.addr, align 8 33*9880d681SAndroid Build Coastguard Worker %this1 = load %struct.Class*, %struct.Class** %this.addr 34*9880d681SAndroid Build Coastguard Worker ret i32 0, !dbg !15 35*9880d681SAndroid Build Coastguard Worker} 36*9880d681SAndroid Build Coastguard Worker 37*9880d681SAndroid Build Coastguard Worker; CHECK: !llvm.dbg.cu = !{![[CU1:[0-9]+]], ![[CU2:[0-9]+]]} 38*9880d681SAndroid Build Coastguard Worker!llvm.dbg.cu = !{!0} 39*9880d681SAndroid Build Coastguard Worker!llvm.module.flags = !{!10, !11, !12} 40*9880d681SAndroid Build Coastguard Worker!llvm.ident = !{!13} 41*9880d681SAndroid Build Coastguard Worker 42*9880d681SAndroid Build Coastguard Worker; Extract out the list of subprograms from each compile unit. 43*9880d681SAndroid Build Coastguard Worker; CHECK: ![[CU1:[0-9]+]] = distinct !DICompileUnit( 44*9880d681SAndroid Build Coastguard Worker; CHECK: ![[CU2:[0-9]+]] = distinct !DICompileUnit( 45*9880d681SAndroid Build Coastguard Worker!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.6.0 (trunk 224193) (llvm/trunk 224197)", isOptimized: false, emissionKind: LineTablesOnly, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2) 46*9880d681SAndroid Build Coastguard Worker!1 = !DIFile(filename: "t1.cpp", directory: "/Users/dexonsmith/data/llvm/staging/test/Linker/repro/d1") 47*9880d681SAndroid Build Coastguard Worker!2 = !{} 48*9880d681SAndroid Build Coastguard Worker!4 = distinct !DISubprogram(name: "foo", line: 2, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 2, file: !1, scope: !5, type: !6, variables: !2) 49*9880d681SAndroid Build Coastguard Worker!5 = !DIFile(filename: "t1.cpp", directory: "/Users/dexonsmith/data/llvm/staging/test/Linker/repro/d1") 50*9880d681SAndroid Build Coastguard Worker!6 = !DISubroutineType(types: !2) 51*9880d681SAndroid Build Coastguard Worker 52*9880d681SAndroid Build Coastguard Worker; Extract out the file from the replaced subprogram. 53*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: ![[SP2:.*]] = distinct !DISubprogram({{.*}} file: ![[FILE:[0-9]+]],{{.*}}, unit: ![[CU2]] 54*9880d681SAndroid Build Coastguard Worker 55*9880d681SAndroid Build Coastguard Worker; We can't use CHECK-NOT/CHECK-SAME with a CHECK-DAG, so rely on field order to 56*9880d681SAndroid Build Coastguard Worker; prove that there's no function: here. 57*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: ![[SP2r:.*]] = {{.*}}!DISubprogram({{.*}} isOptimized: false, unit: ![[CU1]], variables: 58*9880d681SAndroid Build Coastguard Worker!7 = distinct !DISubprogram(name: "foo", line: 2, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 2, file: !8, scope: !9, type: !6, variables: !2) 59*9880d681SAndroid Build Coastguard Worker 60*9880d681SAndroid Build Coastguard Worker; The new subprogram should be pointing at the new directory. 61*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: ![[FILE]] = !DIFile(filename: "../t.h", directory: "/Users/dexonsmith/data/llvm/staging/test/Linker/repro/d2") 62*9880d681SAndroid Build Coastguard Worker!8 = !DIFile(filename: "../t.h", directory: "/Users/dexonsmith/data/llvm/staging/test/Linker/repro/d1") 63*9880d681SAndroid Build Coastguard Worker!9 = !DIFile(filename: "../t.h", directory: "/Users/dexonsmith/data/llvm/staging/test/Linker/repro/d1") 64*9880d681SAndroid Build Coastguard Worker!10 = !{i32 2, !"Dwarf Version", i32 2} 65*9880d681SAndroid Build Coastguard Worker!11 = !{i32 2, !"Debug Info Version", i32 3} 66*9880d681SAndroid Build Coastguard Worker!12 = !{i32 1, !"PIC Level", i32 2} 67*9880d681SAndroid Build Coastguard Worker!13 = !{!"clang version 3.6.0 (trunk 224193) (llvm/trunk 224197)"} 68*9880d681SAndroid Build Coastguard Worker!14 = !DILocation(line: 2, column: 20, scope: !4) 69*9880d681SAndroid Build Coastguard Worker 70*9880d681SAndroid Build Coastguard Worker; The same subprogram should be pointed to by inside the !dbg reference. 71*9880d681SAndroid Build Coastguard Worker; CHECK: ![[LOC]] = !DILocation(line: 2, column: 15, scope: ![[SP2]]) 72*9880d681SAndroid Build Coastguard Worker!15 = !DILocation(line: 2, column: 15, scope: !7) 73