debug-info-same-line.cpp revision ef8225444452a1486bd721f3285301fe84643b00
1651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -g -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
25ca58a0aca0320b8980921e8ee55112668817939Adrian Prantl
35ca58a0aca0320b8980921e8ee55112668817939Adrian Prantl// Make sure that clang outputs distinct debug info for a function
45ca58a0aca0320b8980921e8ee55112668817939Adrian Prantl// that is inlined twice on the same line. Otherwise it would appear
55ca58a0aca0320b8980921e8ee55112668817939Adrian Prantl// as if the function was only inlined once.
600df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl
700df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl#define INLINE inline __attribute__((always_inline))
800df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl
96bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesint i;
1000df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl
116bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen HinesINLINE void sum(int a, int b) {
126bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  i = a + b;
1300df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl}
1400df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl
156bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid noinline(int x, int y) {
166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  i = x + y;
1700df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl}
1800df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl
196bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#define CALLS sum(9, 10), sum(11, 12)
2000df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl
216bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesinline void inlsum(int t, int u) {
226bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  i = t + u;
2300df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl}
2400df5eaa9f4f7cc0809fd47c95311b532fbe63c6Adrian Prantl
256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesint main() {
266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  sum(1, 2), sum(3, 4);
276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  noinline(5, 6), noinline(7, 8);
286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  CALLS;
296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  inlsum(13, 14), inlsum(15, 16);
306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines}
31b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl
326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-LABEL: @main
336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: = add {{.*}} !dbg [[FIRST_INLINE:![0-9]*]]
346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: = add {{.*}} !dbg [[SECOND_INLINE:![0-9]*]]
356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
366bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Check that we don't give column information (and thus end up with distinct
376bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// line entries) for two non-inlined calls on the same line.
38ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// CHECK: call {{.*}}noinline{{.*}}({{i32[ ]?[a-z]*}} 5, {{i32[ ]?[a-z]*}} 6), !dbg [[NOINLINE:![0-9]*]]
39ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// CHECK: call {{.*}}noinline{{.*}}({{i32[ ]?[a-z]*}} 7, {{i32[ ]?[a-z]*}} 8), !dbg [[NOINLINE]]
406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
416bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// FIXME: These should be separate locations but because the two calls have the
426bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// same line /and/ column, they get coalesced into a single inlined call by
436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// accident. We need discriminators or some other changes to LLVM to cope with
446bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// this. (this is, unfortunately, an LLVM test disguised as a Clang test - since
456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// inlining is forced to happen here). It's possible this could be fixed in
466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Clang, but I doubt it'll be the right place for the fix.
476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: = add {{.*}} !dbg [[FIRST_MACRO_INLINE:![0-9]*]]
486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: = add {{.*}} !dbg [[FIRST_MACRO_INLINE]]
496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
506bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// Even if the functions are marked inline but do not get inlined, they
516bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// shouldn't use column information, and thus should be at the same debug
526bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// location.
53ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// CHECK: call {{.*}}inlsum{{.*}}({{i32[ ]?[a-z]*}} 13, {{i32[ ]?[a-z]*}} 14), !dbg [[INL_FIRST:![0-9]*]]
54ef8225444452a1486bd721f3285301fe84643b00Stephen Hines// CHECK: call {{.*}}inlsum{{.*}}({{i32[ ]?[a-z]*}} 15, {{i32[ ]?[a-z]*}} 16), !dbg [[INL_SECOND:![0-9]*]]
556bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
566bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// [[FIRST_INLINE]] =
576bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// [[SECOND_INLINE]] =
586bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
596bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// FIXME: These should be the same location since the functions appear on the
606bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// same line and were not inlined - they needlessly have column information
616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// intended to disambiguate inlined calls, which is going to confuse GDB as it
626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// doesn't cope well with column information.
636bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// [[INL_FIRST]] =
646bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// [[INL_SECOND]] =
65