xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/debug-info-same-line.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -g -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc // Make sure that clang outputs distinct debug info for a function
4f4a2713aSLionel Sambuc // that is inlined twice on the same line. Otherwise it would appear
5f4a2713aSLionel Sambuc // as if the function was only inlined once.
6f4a2713aSLionel Sambuc 
7f4a2713aSLionel Sambuc #define INLINE inline __attribute__((always_inline))
8f4a2713aSLionel Sambuc 
9*0a6a1f1dSLionel Sambuc int i;
10*0a6a1f1dSLionel Sambuc 
sum(int a,int b)11*0a6a1f1dSLionel Sambuc INLINE void sum(int a, int b) {
12*0a6a1f1dSLionel Sambuc   i = a + b;
13f4a2713aSLionel Sambuc }
14f4a2713aSLionel Sambuc 
noinline(int x,int y)15*0a6a1f1dSLionel Sambuc void noinline(int x, int y) {
16*0a6a1f1dSLionel Sambuc   i = x + y;
17f4a2713aSLionel Sambuc }
18f4a2713aSLionel Sambuc 
19*0a6a1f1dSLionel Sambuc #define CALLS sum(9, 10), sum(11, 12)
20*0a6a1f1dSLionel Sambuc 
inlsum(int t,int u)21*0a6a1f1dSLionel Sambuc inline void inlsum(int t, int u) {
22*0a6a1f1dSLionel Sambuc   i = t + u;
23f4a2713aSLionel Sambuc }
24f4a2713aSLionel Sambuc 
main()25*0a6a1f1dSLionel Sambuc int main() {
26*0a6a1f1dSLionel Sambuc   sum(1, 2), sum(3, 4);
27*0a6a1f1dSLionel Sambuc   noinline(5, 6), noinline(7, 8);
28*0a6a1f1dSLionel Sambuc   CALLS;
29*0a6a1f1dSLionel Sambuc   inlsum(13, 14), inlsum(15, 16);
30f4a2713aSLionel Sambuc }
31f4a2713aSLionel Sambuc 
32*0a6a1f1dSLionel Sambuc // CHECK-LABEL: @main
33*0a6a1f1dSLionel Sambuc // CHECK: = add {{.*}} !dbg [[FIRST_INLINE:![0-9]*]]
34*0a6a1f1dSLionel Sambuc // CHECK: = add {{.*}} !dbg [[SECOND_INLINE:![0-9]*]]
35f4a2713aSLionel Sambuc 
36*0a6a1f1dSLionel Sambuc // Check that we don't give column information (and thus end up with distinct
37*0a6a1f1dSLionel Sambuc // line entries) for two non-inlined calls on the same line.
38*0a6a1f1dSLionel Sambuc // CHECK: call {{.*}}noinline{{.*}}({{i32[ ]?[a-z]*}} 5, {{i32[ ]?[a-z]*}} 6), !dbg [[NOINLINE:![0-9]*]]
39*0a6a1f1dSLionel Sambuc // CHECK: call {{.*}}noinline{{.*}}({{i32[ ]?[a-z]*}} 7, {{i32[ ]?[a-z]*}} 8), !dbg [[NOINLINE]]
40f4a2713aSLionel Sambuc 
41*0a6a1f1dSLionel Sambuc // FIXME: These should be separate locations but because the two calls have the
42*0a6a1f1dSLionel Sambuc // same line /and/ column, they get coalesced into a single inlined call by
43*0a6a1f1dSLionel Sambuc // accident. We need discriminators or some other changes to LLVM to cope with
44*0a6a1f1dSLionel Sambuc // this. (this is, unfortunately, an LLVM test disguised as a Clang test - since
45*0a6a1f1dSLionel Sambuc // inlining is forced to happen here). It's possible this could be fixed in
46*0a6a1f1dSLionel Sambuc // Clang, but I doubt it'll be the right place for the fix.
47*0a6a1f1dSLionel Sambuc // CHECK: = add {{.*}} !dbg [[FIRST_MACRO_INLINE:![0-9]*]]
48*0a6a1f1dSLionel Sambuc // CHECK: = add {{.*}} !dbg [[FIRST_MACRO_INLINE]]
49f4a2713aSLionel Sambuc 
50*0a6a1f1dSLionel Sambuc // Even if the functions are marked inline but do not get inlined, they
51*0a6a1f1dSLionel Sambuc // shouldn't use column information, and thus should be at the same debug
52*0a6a1f1dSLionel Sambuc // location.
53*0a6a1f1dSLionel Sambuc // CHECK: call {{.*}}inlsum{{.*}}({{i32[ ]?[a-z]*}} 13, {{i32[ ]?[a-z]*}} 14), !dbg [[INL_FIRST:![0-9]*]]
54*0a6a1f1dSLionel Sambuc // CHECK: call {{.*}}inlsum{{.*}}({{i32[ ]?[a-z]*}} 15, {{i32[ ]?[a-z]*}} 16), !dbg [[INL_SECOND:![0-9]*]]
55f4a2713aSLionel Sambuc 
56*0a6a1f1dSLionel Sambuc // [[FIRST_INLINE]] =
57*0a6a1f1dSLionel Sambuc // [[SECOND_INLINE]] =
58f4a2713aSLionel Sambuc 
59*0a6a1f1dSLionel Sambuc // FIXME: These should be the same location since the functions appear on the
60*0a6a1f1dSLionel Sambuc // same line and were not inlined - they needlessly have column information
61*0a6a1f1dSLionel Sambuc // intended to disambiguate inlined calls, which is going to confuse GDB as it
62*0a6a1f1dSLionel Sambuc // doesn't cope well with column information.
63*0a6a1f1dSLionel Sambuc // [[INL_FIRST]] =
64*0a6a1f1dSLionel Sambuc // [[INL_SECOND]] =
65