1*8472fa6cSDavid Blaikie // RUN: %clang_cc1 -DSETNODEBUG=0 -emit-llvm -std=c++14 -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=YESINFO
2*8472fa6cSDavid Blaikie // RUN: %clang_cc1 -DSETNODEBUG=1 -emit-llvm -std=c++14 -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=NOINFO
3b17327d7SPaul Robinson 
4b17327d7SPaul Robinson #if SETNODEBUG
5b17327d7SPaul Robinson #define NODEBUG __attribute__((nodebug))
6b17327d7SPaul Robinson #else
7b17327d7SPaul Robinson #define NODEBUG
8b17327d7SPaul Robinson #endif
9b17327d7SPaul Robinson 
10b17327d7SPaul Robinson // Const global variable. Use it so it gets emitted.
11b17327d7SPaul Robinson NODEBUG static const int const_global_int_def = 1;
12b17327d7SPaul Robinson void func1(int);
func2()13b17327d7SPaul Robinson void func2() { func1(const_global_int_def); }
14b17327d7SPaul Robinson // YESINFO-DAG: !DIGlobalVariable(name: "const_global_int_def"
15b17327d7SPaul Robinson // NOINFO-NOT:  !DIGlobalVariable(name: "const_global_int_def"
16b17327d7SPaul Robinson 
17b17327d7SPaul Robinson // Global variable with a more involved type.
18b17327d7SPaul Robinson // If the variable has no debug info, the type should not appear either.
19b17327d7SPaul Robinson struct S1 {
20b17327d7SPaul Robinson   int a;
21b17327d7SPaul Robinson   int b;
22b17327d7SPaul Robinson };
23b17327d7SPaul Robinson NODEBUG S1 global_struct = { 2, 3 };
24b17327d7SPaul Robinson // YESINFO-DAG: !DICompositeType({{.*}} name: "S1"
25b17327d7SPaul Robinson // NOINFO-NOT:  !DICompositeType({{.*}} name: "S1"
26b17327d7SPaul Robinson // YESINFO-DAG: !DIGlobalVariable(name: "global_struct"
27b17327d7SPaul Robinson // NOINFO-NOT:  !DIGlobalVariable(name: "global_struct"
28b17327d7SPaul Robinson 
29b17327d7SPaul Robinson // Static data members. Const member needs a use.
309253135cSPaul Robinson // Also the class as a whole needs a use, so that we produce debug info for
319253135cSPaul Robinson // the entire class (iterating over the members, demonstrably skipping those
329253135cSPaul Robinson // with 'nodebug').
33b17327d7SPaul Robinson struct S2 {
34b17327d7SPaul Robinson   NODEBUG static int static_member;
35b17327d7SPaul Robinson   NODEBUG static const int static_const_member = 4;
36b17327d7SPaul Robinson };
37b17327d7SPaul Robinson int S2::static_member = 5;
func3()389253135cSPaul Robinson void func3() {
399253135cSPaul Robinson   S2 junk;
409253135cSPaul Robinson   func1(S2::static_const_member);
419253135cSPaul Robinson }
42b17327d7SPaul Robinson // YESINFO-DAG: !DIGlobalVariable(name: "static_member"
43b17327d7SPaul Robinson // NOINFO-NOT:  !DIGlobalVariable(name: "static_member"
44b17327d7SPaul Robinson // YESINFO-DAG: !DIDerivedType({{.*}} name: "static_const_member"
45b17327d7SPaul Robinson // NOINFO-NOT:  !DIDerivedType({{.*}} name: "static_const_member"
46b17327d7SPaul Robinson 
47afd2dde2SPaul Robinson // Function-local static and auto variables.
func4()481c6fc206SPaul Robinson void func4() {
491c6fc206SPaul Robinson   NODEBUG static int static_local = 6;
50afd2dde2SPaul Robinson   NODEBUG        int normal_local = 7;
51b17327d7SPaul Robinson }
521c6fc206SPaul Robinson // YESINFO-DAG: !DIGlobalVariable(name: "static_local"
531c6fc206SPaul Robinson // NOINFO-NOT:  !DIGlobalVariable(name: "static_local"
54afd2dde2SPaul Robinson // YESINFO-DAG: !DILocalVariable(name: "normal_local"
55afd2dde2SPaul Robinson // NOINFO-NOT:  !DILocalVariable(name: "normal_local"
56*8472fa6cSDavid Blaikie 
57*8472fa6cSDavid Blaikie template <typename T>
58*8472fa6cSDavid Blaikie using y NODEBUG = int;
func5()59*8472fa6cSDavid Blaikie void func5() {
60*8472fa6cSDavid Blaikie   NODEBUG typedef int x;
61*8472fa6cSDavid Blaikie   x a;
62*8472fa6cSDavid Blaikie   y<int> b;
63*8472fa6cSDavid Blaikie }
64*8472fa6cSDavid Blaikie // YESINFO-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "x"
65*8472fa6cSDavid Blaikie // NOINFO-NOT:  !DIDerivedType(tag: DW_TAG_typedef, name: "x"
66*8472fa6cSDavid Blaikie // YESINFO-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "y<int>"
67*8472fa6cSDavid Blaikie // NOINFO-NOT:  !DIDerivedType(tag: DW_TAG_typedef, name: "y<int>"
68