xref: /llvm-project/llvm/test/tools/dsymutil/X86/inlined-static-variable.cpp (revision f1fdfe6888f93b9f6dfb4689e1f3206de584ff5b)
1 // RUN: dsymutil -f -y %p/dummy-debug-map.map -oso-prepend-path \
2 // RUN:   %p/../Inputs/inlined-static-variable -o - -keep-function-for-static \
3 // RUN:   | llvm-dwarfdump - | FileCheck %s --implicit-check-not \
4 // RUN:   "{{DW_AT_low_pc|DW_AT_high_pc|DW_AT_location|DW_TAG|NULL}}" \
5 // RUN:   --check-prefixes=CHECK
6 //
7 // RUN: dsymutil --linker parallel --no-odr -f -y %p/dummy-debug-map.map \
8 // RUN:   -oso-prepend-path %p/../Inputs/inlined-static-variable -o - \
9 // RUN:   -keep-function-for-static | llvm-dwarfdump - | FileCheck %s \
10 // RUN:   --implicit-check-not \
11 // RUN:   "{{DW_AT_low_pc|DW_AT_high_pc|DW_AT_location|DW_TAG|NULL}}" \
12 // RUN:   --check-prefixes=CHECK
13 
14 // clang -g -c inlined-static-variable.cpp -o 4.o
15 
16 // The functions removed and not_removed are not in the debug map and are
17 // considered dead, but they are also inlined into the function foo which is
18 // in the debug map. Those function-local globals are alive and thus should
19 // have locations in the debug info even if their functions do not.
20 
removed()21 inline __attribute__((always_inline)) int removed() {
22   static int a = 0;
23   return ++a;
24 }
25 
not_removed()26 __attribute__((always_inline)) int not_removed() {
27   static int b = 0;
28   return ++b;
29 }
30 
unused()31 int unused() {
32   static int c = 0;
33   return ++c;
34 }
35 
foo()36 int foo() {
37   return removed() + not_removed();
38 }
39 
40 // CHECK: DW_TAG_compile_unit
41 // CHECK:   DW_AT_low_pc
42 // CHECK:   DW_AT_high_pc
43 
44 // CHECK:   DW_TAG_subprogram
45 // CHECK:     DW_AT_name	("removed")
46 // CHECK:     DW_TAG_variable
47 // CHECK:       DW_AT_name	("a")
48 // CHECK:       DW_AT_location
49 // CHECK:     NULL
50 
51 // CHECK:   DW_TAG_base_type
52 // CHECK:   DW_TAG_subprogram
53 // CHECK:     DW_AT_name	("not_removed")
54 // CHECK:     DW_TAG_variable
55 // CHECK:       DW_AT_name	("b")
56 // CHECK:       DW_AT_location
57 // CHECK:     NULL
58 
59 // CHECK:   DW_TAG_subprogram
60 // CHECK:     DW_AT_low_pc
61 // CHECK:     DW_AT_high_pc
62 // CHECK:     DW_AT_name	("foo")
63 // CHECK:     DW_TAG_inlined_subroutine
64 // CHECK:       DW_AT_low_pc
65 // CHECK:       DW_AT_high_pc
66 // CHECK:     DW_TAG_inlined_subroutine
67 // CHECK:       DW_AT_low_pc
68 // CHECK:       DW_AT_high_pc
69 // CHECK:     NULL
70 // CHECK:   NULL
71