1 // RUN: %clang_cc1 -g -emit-llvm -o - %s | FileCheck %s 2 3 // Make sure that clang outputs distinct debug info for a function 4 // that is inlined twice on the same line. Otherwise it would appear 5 // as if the function was only inlined once. 6 7 #define INLINE inline __attribute__((always_inline)) 8 9 INLINE int 10 product (int x, int y) 11 { 12 int result = x * y; 13 return result; 14 } 15 16 INLINE int 17 sum (int a, int b) 18 { 19 int result = a + b; 20 return result; 21 } 22 23 int 24 strange_max (int m, int n) 25 { 26 if (m > n) 27 return m; 28 else if (n > m) 29 return n; 30 else 31 return 0; 32 } 33 34 int 35 foo (int i, int j) 36 { 37 if (strange_max (i, j) == i) 38 return product (i, j); 39 else if (strange_max (i, j) == j) 40 return sum (i, j); 41 else 42 return product (sum (i, i), sum (j, j)); 43 } 44 45 int 46 main(int argc, char const *argv[]) 47 { 48 49 int array[3]; 50 int n; 51 52 array[0] = foo (1238, 78392); 53 array[1] = foo (379265, 23674); 54 array[2] = foo (872934, 234); 55 56 n = strange_max(array[0], strange_max(array[1], array[2])); 57 58 return n & 0xf; 59 } 60 61 // CHECK: define {{.*}} @_Z3fooii 62 // i 63 // CHECK: call void @llvm.dbg.declare 64 // j 65 // CHECK: call void @llvm.dbg.declare 66 // x 67 // CHECK: call void @llvm.dbg.declare 68 // y 69 // CHECK: call void @llvm.dbg.declare 70 // result 71 // CHECK: call void @llvm.dbg.declare 72 73 // CHECK: call void @llvm.dbg.declare(metadata !{i32* %{{.*}}}, metadata ![[A_MD:[0-9]+]]), !dbg ![[A_DI:[0-9]+]] 74 // CHECK: call void @llvm.dbg.declare(metadata !{i32* %{{.*}}}, metadata ![[B_MD:[0-9]+]]), !dbg ![[B_DI:[0-9]+]] 75 // result 76 // CHECK: call void @llvm.dbg.declare 77 78 // We want to see a distinct !dbg node. 79 // CHECK-NOT: call void @llvm.dbg.declare(metadata !{i32* %{{.*}}}, metadata ![[A_MD]]), !dbg ![[A_DI]] 80 // CHECK: call void @llvm.dbg.declare(metadata !{i32* %{{.*}}}, metadata ![[A_MD]]), !dbg !{{.*}} 81 // CHECK-NOT: call void @llvm.dbg.declare(metadata !{i32* %{{.*}}}, metadata ![[B_MD]]), !dbg ![[B_DI]] 82 // CHECK: call void @llvm.dbg.declare(metadata !{i32* %{{.*}}}, metadata ![[B_MD]]), !dbg !{{.*}} 83 // result 84 // CHECK: call void @llvm.dbg.declare 85 86 // We want to see a distinct !dbg node. 87 // CHECK-NOT: call void @llvm.dbg.declare(metadata !{i32* %{{.*}}}, metadata ![[A_MD]]), !dbg ![[A_DI]] 88 // CHECK: call void @llvm.dbg.declare(metadata !{i32* %{{.*}}}, metadata ![[A_MD]]), !dbg !{{.*}} 89 // CHECK-NOT: call void @llvm.dbg.declare(metadata !{i32* %{{.*}}}, metadata ![[B_MD]]), !dbg ![[B_DI]] 90 // CHECK: call void @llvm.dbg.declare(metadata !{i32* %{{.*}}}, metadata ![[B_MD]]), !dbg !{{.*}} 91 // result 92 // CHECK: call void @llvm.dbg.declare 93 94 // Again: we want to see a distinct !dbg node. 95 // CHECK: call void @llvm.dbg.declare(metadata !{i32* %{{.*}}}, metadata ![[X_MD:[0-9]+]]), !dbg ![[X_DI:[0-9]+]] 96 // CHECK: call void @llvm.dbg.declare(metadata !{i32* %{{.*}}}, metadata ![[Y_MD:[0-9]+]]), !dbg ![[Y_DI:[0-9]+]] 97 // result 98 // CHECK: call void @llvm.dbg.declare 99 100 101 // CHECK: define {{.*}} @main 102 // CHECK: call {{.*}} @_Z3fooii 103 // CHECK: call {{.*}} @_Z3fooii 104 // CHECK: call {{.*}} @_Z3fooii 105 // CHECK: store 106 // CHECK: getelementptr 107 // We want to see the same !dbg node for non-inlined functions. 108 // Needed for GDB compatibility. 109 // CHECK: load {{.*}} !dbg ![[DBG:.*]] 110 // CHECK: load {{.*}} !dbg ![[DBG]] 111 // CHECK: load {{.*}} !dbg ![[DBG]] 112 // CHECK: call {{.*}} @_Z11strange_maxii(i32 {{.*}}, i32 {{.*}}), !dbg ![[DBG]] 113 // CHECK: call {{.*}} @_Z11strange_maxii(i32 {{.*}}, i32 {{.*}}), !dbg ![[DBG]] 114 115 116 // Verify that product() has its own inlined_at location at column 15. 117 // CHECK-DAG: ![[A_MD]] = metadata{{.*}}[ DW_TAG_arg_variable ] [a] 118 // CHECK-DAG: ![[B_MD]] = metadata{{.*}}[ DW_TAG_arg_variable ] [b] 119 // CHECK-DAG: ![[X_MD]] = metadata{{.*}}[ DW_TAG_arg_variable ] [x] 120 // CHECK-DAG: ![[Y_MD]] = metadata{{.*}}[ DW_TAG_arg_variable ] [y] 121 // CHECK-DAG: ![[X_DI]] = metadata !{i32 {{[0-9]+}}, i32 {{[0-9]+}}, metadata !{{[0-9]+}}, metadata ![[PRODUCT:[0-9]+]]} 122 // CHECK-DAG: [[PRODUCT]] = metadata !{i32 {{.*}}, i32 16, metadata !{{.*}}, null} 123 // CHECK-DAG: ![[Y_DI]] = metadata !{i32 {{[0-9]+}}, i32 {{[0-9]+}}, metadata !{{[0-9]+}}, metadata ![[PRODUCT]]} 124