1 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-apple-darwin -std=c++11 %s -o - | FileCheck %s
2
3 enum class A { A1=1 }; // underlying type is int by default
4 enum class B: unsigned long { B1=1 }; // underlying type is unsigned long
5 enum C { C1 = 1 };
6 enum D : short; // enum forward declaration
7 enum Z : int;
8 A a;
9 B b;
10 C c;
11 D d;
12
13 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "A"
14 // CHECK-SAME: line: 3
15 // CHECK-SAME: baseType: ![[INT:[0-9]+]]
16 // CHECK-SAME: size: 32
17 // CHECK-NOT: offset:
18 // CHECK-SAME: flags: DIFlagEnumClass
19 // CHECK-SAME: ){{$}}
20 // CHECK: ![[INT]] = !DIBasicType(name: "int"
21 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "B"
22 // CHECK-SAME: line: 4
23 // CHECK-SAME: baseType: ![[ULONG:[0-9]+]]
24 // CHECK-SAME: size: 64
25 // CHECK-NOT: offset:
26 // CHECK-SAME: flags: DIFlagEnumClass
27 // CHECK-SAME: ){{$}}
28 // CHECK: ![[ULONG]] = !DIBasicType(name: "long unsigned int"
29 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "C"
30 // CHECK-SAME: line: 5
31 // CHECK-SAME: baseType: ![[ULONG:[0-9]+]]
32 // CHECK-SAME: size: 32
33 // CHECK-NOT: offset:
34 // CHECK-NOT: flags:
35 // CHECK-SAME: ){{$}}
36
37 namespace PR14029 {
38 // Make sure this doesn't crash/assert.
39 template <typename T> struct Test {
40 enum class Tag {
41 test = 0
42 };
TestPR14029::Test43 Test() {
44 auto t = Tag::test;
45 }
tagPR14029::Test46 Tag tag() const { return static_cast<Tag>(1); }
47 };
48 Test<int> t;
49 }
50
51 namespace test2 {
52 // FIXME: this should just be a declaration under -fno-standalone-debug
53 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E"
54 // CHECK-SAME: scope: [[TEST2:![0-9]+]]
55 // CHECK-NOT: DIFlagEnumClass
56 // CHECK-SAME: elements: [[TEST_ENUMS:![0-9]+]]
57 // CHECK-SAME: identifier: "_ZTSN5test21EE"
58 // CHECK: [[TEST2]] = !DINamespace(name: "test2"
59 // CHECK: [[TEST_ENUMS]] = !{[[TEST_E:![0-9]*]]}
60 // CHECK: [[TEST_E]] = !DIEnumerator(name: "e", value: 0)
61 enum E : int;
func(E *)62 void func(E *) {
63 }
64 enum E : int { e };
65 }
66
67 namespace test3 {
68 // FIXME: this should just be a declaration under -fno-standalone-debug
69 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E"
70 // CHECK-SAME: scope: [[TEST3:![0-9]+]]
71 // CHECK-NOT: DIFlagEnumClass
72 // CHECK-SAME: elements: [[TEST_ENUMS]]
73 // CHECK-SAME: identifier: "_ZTSN5test31EE"
74 // CHECK: [[TEST3]] = !DINamespace(name: "test3"
75 enum E : int { e };
func(E *)76 void func(E *) {
77 }
78 }
79
80 namespace test4 {
81 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E"
82 // CHECK-SAME: scope: [[TEST4:![0-9]+]]
83 // CHECK-NOT: DIFlagEnumClass
84 // CHECK-SAME: elements: [[TEST_ENUMS]]
85 // CHECK-SAME: identifier: "_ZTSN5test41EE"
86 // CHECK: [[TEST4]] = !DINamespace(name: "test4"
87 enum E : int;
f1(E *)88 void f1(E *) {
89 }
90 enum E : int { e };
f2(E)91 void f2(E) {
92 }
93 }
94
95 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "D"
96 // CHECK-SAME: line: 6
97 // CHECK-SAME: size: 16
98 // CHECK-NOT: offset:
99 // CHECK-SAME: flags: DIFlagFwdDecl
100
101 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Z"
102 // CHECK-NOT: scope:
103 // CHECK-SAME: flags: DIFlagFwdDecl
fz()104 void fz() { Z z; }
105
106 namespace test5 {
107 // CHECK: [[TEST5:![0-9]+]] = !DINamespace(name: "test5"
108 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E"
109 // CHECK-SAME: scope: [[TEST5]]
110 // CHECK-SAME: flags: DIFlagFwdDecl
111 // CHECK-SAME: identifier: "_ZTSN5test51EE"
112 enum E : int;
f1(E *)113 void f1(E *) {
114 }
115 }
116
117 namespace test6 {
118 // Ensure typedef'd enums aren't manifest by debug info generation.
119 // This could cause "typedef changes linkage of anonymous type, but linkage was
120 // already computed" errors.
121 // CHECK-NOT: test6
122 typedef enum {
123 } E;
124 }
125