Home | History | Annotate | Download | only in CodeGenCXX
      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 // CHECK: define {{.*}} @main
     87 // CHECK: call {{.*}} @_Z3fooii
     88 // CHECK: call {{.*}} @_Z3fooii
     89 // CHECK: call {{.*}} @_Z3fooii
     90 // CHECK: store
     91 // CHECK: getelementptr
     92 // We want to see the same !dbg node for non-inlined functions.
     93 // Needed for GDB compatibility.
     94 // CHECK: load {{.*}} !dbg ![[DBG:.*]]
     95 // CHECK: load {{.*}} !dbg ![[DBG]]
     96 // CHECK: load {{.*}} !dbg ![[DBG]]
     97 // CHECK: call {{.*}} @_Z11strange_maxii(i32 %{{.*}}, i32 %{{.*}}), !dbg ![[DBG]]
     98 // CHECK: call {{.*}} @_Z11strange_maxii(i32 %{{.*}}, i32 %{{.*}}), !dbg ![[DBG]]
     99