Paul Robinson | b17327d | 2016-04-27 17:37:12 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -DSETNODEBUG=0 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=YESINFO |
| 2 | // RUN: %clang_cc1 -DSETNODEBUG=1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=NOINFO |
| 3 | |
| 4 | #if SETNODEBUG |
| 5 | #define NODEBUG __attribute__((nodebug)) |
| 6 | #else |
| 7 | #define NODEBUG |
| 8 | #endif |
| 9 | |
Paul Robinson | b17327d | 2016-04-27 17:37:12 +0000 | [diff] [blame] | 10 | // Const global variable. Use it so it gets emitted. |
| 11 | NODEBUG static const int const_global_int_def = 1; |
| 12 | void func1(int); |
| 13 | void func2() { func1(const_global_int_def); } |
| 14 | // YESINFO-DAG: !DIGlobalVariable(name: "const_global_int_def" |
| 15 | // NOINFO-NOT: !DIGlobalVariable(name: "const_global_int_def" |
| 16 | |
| 17 | // Global variable with a more involved type. |
| 18 | // If the variable has no debug info, the type should not appear either. |
| 19 | struct S1 { |
| 20 | int a; |
| 21 | int b; |
| 22 | }; |
| 23 | NODEBUG S1 global_struct = { 2, 3 }; |
| 24 | // YESINFO-DAG: !DICompositeType({{.*}} name: "S1" |
| 25 | // NOINFO-NOT: !DICompositeType({{.*}} name: "S1" |
| 26 | // YESINFO-DAG: !DIGlobalVariable(name: "global_struct" |
| 27 | // NOINFO-NOT: !DIGlobalVariable(name: "global_struct" |
| 28 | |
| 29 | // Static data members. Const member needs a use. |
Paul Robinson | 9253135 | 2016-04-28 17:52:28 +0000 | [diff] [blame] | 30 | // Also the class as a whole needs a use, so that we produce debug info for |
| 31 | // the entire class (iterating over the members, demonstrably skipping those |
| 32 | // with 'nodebug'). |
Paul Robinson | b17327d | 2016-04-27 17:37:12 +0000 | [diff] [blame] | 33 | struct S2 { |
| 34 | NODEBUG static int static_member; |
| 35 | NODEBUG static const int static_const_member = 4; |
| 36 | }; |
| 37 | int S2::static_member = 5; |
Paul Robinson | 9253135 | 2016-04-28 17:52:28 +0000 | [diff] [blame] | 38 | void func3() { |
| 39 | S2 junk; |
| 40 | func1(S2::static_const_member); |
| 41 | } |
Paul Robinson | b17327d | 2016-04-27 17:37:12 +0000 | [diff] [blame] | 42 | // YESINFO-DAG: !DIGlobalVariable(name: "static_member" |
| 43 | // NOINFO-NOT: !DIGlobalVariable(name: "static_member" |
| 44 | // YESINFO-DAG: !DIDerivedType({{.*}} name: "static_const_member" |
| 45 | // NOINFO-NOT: !DIDerivedType({{.*}} name: "static_const_member" |
| 46 | |
Paul Robinson | afd2dde | 2016-06-16 00:42:36 +0000 | [diff] [blame] | 47 | // Function-local static and auto variables. |
Paul Robinson | 1c6fc20 | 2016-04-27 22:18:46 +0000 | [diff] [blame] | 48 | void func4() { |
| 49 | NODEBUG static int static_local = 6; |
Paul Robinson | afd2dde | 2016-06-16 00:42:36 +0000 | [diff] [blame] | 50 | NODEBUG int normal_local = 7; |
Paul Robinson | b17327d | 2016-04-27 17:37:12 +0000 | [diff] [blame] | 51 | } |
Paul Robinson | 1c6fc20 | 2016-04-27 22:18:46 +0000 | [diff] [blame] | 52 | // YESINFO-DAG: !DIGlobalVariable(name: "static_local" |
| 53 | // NOINFO-NOT: !DIGlobalVariable(name: "static_local" |
Paul Robinson | afd2dde | 2016-06-16 00:42:36 +0000 | [diff] [blame] | 54 | // YESINFO-DAG: !DILocalVariable(name: "normal_local" |
| 55 | // NOINFO-NOT: !DILocalVariable(name: "normal_local" |