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, align: 32
17 // CHECK-NOT: offset:
18 // CHECK-NOT: flags:
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, align: 64
25 // CHECK-NOT: offset:
26 // CHECK-NOT: flags:
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-NOT: baseType:
32 // CHECK-SAME: size: 32, align: 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-SAME: elements: [[TEST_ENUMS:![0-9]+]]
56 // CHECK-SAME: identifier: "_ZTSN5test21EE"
57 // CHECK: [[TEST2]] = !DINamespace(name: "test2"
58 // CHECK: [[TEST_ENUMS]] = !{[[TEST_E:![0-9]*]]}
59 // CHECK: [[TEST_E]] = !DIEnumerator(name: "e", value: 0)
60 enum E : int;
func(E *)61 void func(E *) {
62 }
63 enum E : int { e };
64 }
65
66 namespace test3 {
67 // FIXME: this should just be a declaration under -fno-standalone-debug
68 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E"
69 // CHECK-SAME: scope: [[TEST3:![0-9]+]]
70 // CHECK-SAME: elements: [[TEST_ENUMS]]
71 // CHECK-SAME: identifier: "_ZTSN5test31EE"
72 // CHECK: [[TEST3]] = !DINamespace(name: "test3"
73 enum E : int { e };
func(E *)74 void func(E *) {
75 }
76 }
77
78 namespace test4 {
79 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E"
80 // CHECK-SAME: scope: [[TEST4:![0-9]+]]
81 // CHECK-SAME: elements: [[TEST_ENUMS]]
82 // CHECK-SAME: identifier: "_ZTSN5test41EE"
83 // CHECK: [[TEST4]] = !DINamespace(name: "test4"
84 enum E : int;
f1(E *)85 void f1(E *) {
86 }
87 enum E : int { e };
f2(E)88 void f2(E) {
89 }
90 }
91
92 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "D"
93 // CHECK-SAME: line: 6
94 // CHECK-SAME: size: 16, align: 16
95 // CHECK-NOT: offset:
96 // CHECK-SAME: flags: DIFlagFwdDecl
97
98 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Z"
99 // CHECK-NOT: scope:
100 // CHECK-SAME: flags: DIFlagFwdDecl
fz()101 void fz() { Z z; }
102
103 namespace test5 {
104 // CHECK: [[TEST5:![0-9]+]] = !DINamespace(name: "test5"
105 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E"
106 // CHECK-SAME: scope: [[TEST5]]
107 // CHECK-SAME: flags: DIFlagFwdDecl
108 // CHECK-SAME: identifier: "_ZTSN5test51EE"
109 enum E : int;
f1(E *)110 void f1(E *) {
111 }
112 }
113
114 namespace test6 {
115 // Ensure typedef'd enums aren't manifest by debug info generation.
116 // This could cause "typedef changes linkage of anonymous type, but linkage was
117 // already computed" errors.
118 // CHECK-NOT: test6
119 typedef enum {
120 } E;
121 }
122