2013-09-04 12:12:25 +08:00
|
|
|
// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | FileCheck %s
|
2016-04-14 04:00:45 +08:00
|
|
|
// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S -o - | FileCheck %s
|
|
|
|
// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S -o - | FileCheck %s
|
2013-01-17 03:54:35 +08:00
|
|
|
// PR14471
|
|
|
|
|
2013-08-18 04:01:53 +08:00
|
|
|
enum X {
|
|
|
|
Y
|
|
|
|
};
|
2013-01-17 03:54:35 +08:00
|
|
|
class C
|
|
|
|
{
|
|
|
|
static int a;
|
2013-01-20 09:19:17 +08:00
|
|
|
const static bool const_a = true;
|
2013-01-17 03:54:35 +08:00
|
|
|
protected:
|
|
|
|
static int b;
|
2016-04-14 04:00:45 +08:00
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
constexpr static float const_b = 3.14;
|
|
|
|
#else
|
2013-01-20 09:19:17 +08:00
|
|
|
const static float const_b = 3.14;
|
2016-04-14 04:00:45 +08:00
|
|
|
#endif
|
2013-01-17 03:54:35 +08:00
|
|
|
public:
|
|
|
|
static int c;
|
|
|
|
const static int const_c = 18;
|
|
|
|
int d;
|
2013-08-18 04:01:53 +08:00
|
|
|
static X x_a;
|
2013-01-17 03:54:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// The definition of C::a drives the emission of class C, which is
|
|
|
|
// why the definition of "a" comes before the declarations while
|
|
|
|
// "b" and "c" come after.
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}}, identifier: "_ZTS1X")
|
2016-04-24 05:08:27 +08:00
|
|
|
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "anon_static_decl_struct"
|
|
|
|
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var"
|
|
|
|
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "static_decl_templ<int>"
|
|
|
|
// CHECK-NOT: DIFlagFwdDecl
|
|
|
|
// CHECK-SAME: ){{$}}
|
|
|
|
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "static_decl_templ_var"
|
|
|
|
|
|
|
|
// CHECK: !DIGlobalVariable(name: "a", {{.*}}variable: i32* @_ZN1C1aE, declaration: ![[DECL_A:[0-9]+]])
|
|
|
|
int C::a = 4;
|
|
|
|
// CHECK: ![[DECL_A]] = !DIDerivedType(tag: DW_TAG_member, name: "a"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-NOT: size:
|
|
|
|
// CHECK-NOT: align:
|
|
|
|
// CHECK-NOT: offset:
|
|
|
|
// CHECK-SAME: flags: DIFlagStaticMember)
|
|
|
|
//
|
2016-04-24 05:08:27 +08:00
|
|
|
// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "C"{{.*}}, identifier: "_ZTS1C")
|
|
|
|
//
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_a"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-NOT: size:
|
|
|
|
// CHECK-NOT: align:
|
|
|
|
// CHECK-NOT: offset:
|
|
|
|
// CHECK-SAME: flags: DIFlagStaticMember,
|
|
|
|
// CHECK-SAME: extraData: i1 true)
|
2016-04-24 05:08:27 +08:00
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: ![[DECL_B:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "b"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-NOT: size:
|
|
|
|
// CHECK-NOT: align:
|
|
|
|
// CHECK-NOT: offset:
|
|
|
|
// CHECK-SAME: flags: DIFlagProtected | DIFlagStaticMember)
|
|
|
|
//
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_b"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-NOT: size:
|
|
|
|
// CHECK-NOT: align:
|
|
|
|
// CHECK-NOT: offset:
|
|
|
|
// CHECK-SAME: flags: DIFlagProtected | DIFlagStaticMember,
|
|
|
|
// CHECK-SAME: extraData: float 0x{{.*}})
|
2016-04-24 05:08:27 +08:00
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: ![[DECL_C:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "c"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-NOT: size:
|
|
|
|
// CHECK-NOT: align:
|
|
|
|
// CHECK-NOT: offset:
|
|
|
|
// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember)
|
|
|
|
//
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_c"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-NOT: size:
|
|
|
|
// CHECK-NOT: align:
|
|
|
|
// CHECK-NOT: offset:
|
|
|
|
// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember,
|
|
|
|
// CHECK-SAME: extraData: i32 18)
|
|
|
|
//
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "x_a"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember)
|
|
|
|
|
2016-04-24 05:08:27 +08:00
|
|
|
// CHECK: !DIGlobalVariable(name: "b", {{.*}}variable: i32* @_ZN1C1bE, declaration: ![[DECL_B]])
|
|
|
|
int C::b = 2;
|
|
|
|
// CHECK: !DIGlobalVariable(name: "c", {{.*}}variable: i32* @_ZN1C1cE, declaration: ![[DECL_C]])
|
|
|
|
int C::c = 1;
|
2015-03-04 01:25:55 +08:00
|
|
|
|
2016-04-24 05:08:27 +08:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
C instance_C;
|
|
|
|
instance_C.d = 8;
|
|
|
|
return C::c;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-NOT: !DIGlobalVariable(name: "anon_static_decl_var"
|
2014-11-20 03:42:40 +08:00
|
|
|
|
|
|
|
// Test this in an anonymous namespace to ensure the type is retained even when
|
|
|
|
// it doesn't get automatically retained by the string type reference machinery.
|
|
|
|
namespace {
|
|
|
|
struct anon_static_decl_struct {
|
|
|
|
static const int anon_static_decl_var = 117;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-11-21 08:20:58 +08:00
|
|
|
|
2014-11-20 03:42:40 +08:00
|
|
|
int ref() {
|
|
|
|
return anon_static_decl_struct::anon_static_decl_var;
|
|
|
|
}
|
|
|
|
|
2014-11-21 08:20:58 +08:00
|
|
|
template<typename T>
|
|
|
|
struct static_decl_templ {
|
|
|
|
static const int static_decl_templ_var = 7;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
const int static_decl_templ<T>::static_decl_templ_var;
|
|
|
|
|
|
|
|
int static_decl_templ_ref() {
|
|
|
|
return static_decl_templ<int>::static_decl_templ_var;
|
|
|
|
}
|
|
|
|
|
2014-10-15 06:22:17 +08:00
|
|
|
// Verify that even when a static member declaration is created lazily when
|
|
|
|
// creating the definition, the declaration line is that of the canonical
|
2014-10-17 02:38:36 +08:00
|
|
|
// declaration, not the definition. Also, since we look at the canonical
|
|
|
|
// definition, we should also correctly emit the constant value (42) into the
|
|
|
|
// debug info.
|
2014-10-15 06:22:17 +08:00
|
|
|
struct V {
|
|
|
|
virtual ~V(); // cause the definition of 'V' to be omitted by no-standalone-debug optimization
|
|
|
|
static const int const_va = 42;
|
|
|
|
};
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_va",
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: line: [[@LINE-3]]
|
|
|
|
// CHECK-SAME: extraData: i32 42
|
2014-10-15 06:22:17 +08:00
|
|
|
const int V::const_va;
|
2014-10-24 00:39:49 +08:00
|
|
|
|
|
|
|
namespace x {
|
|
|
|
struct y {
|
2016-04-24 05:08:27 +08:00
|
|
|
// CHECK: !DIGlobalVariable(name: "z",
|
|
|
|
// CHECK-SAME: scope: [[NS_X:![0-9]+]]
|
|
|
|
// CHECK: [[NS_X]] = !DINamespace(name: "x"
|
2014-10-24 00:39:49 +08:00
|
|
|
static int z;
|
|
|
|
};
|
|
|
|
int y::z;
|
|
|
|
}
|