xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjC/objc-fixed-enum.m (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -g -emit-llvm -o - %s | FileCheck %s
2f4a2713aSLionel Sambuc// The DWARF standard says the underlying data type of an enum may be
3f4a2713aSLionel Sambuc// stored in an DW_AT_type entry in the enum DIE. This is useful to have
4f4a2713aSLionel Sambuc// so the debugger knows about the signedness of the underlying type.
5f4a2713aSLionel Sambuc
6f4a2713aSLionel Sambuctypedef long NSInteger;
7f4a2713aSLionel Sambuc#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
8f4a2713aSLionel Sambuc
9f4a2713aSLionel Sambuc// Enum with no specified underlying type
10f4a2713aSLionel Sambuctypedef enum {
11f4a2713aSLionel Sambuc  Enum0One,
12f4a2713aSLionel Sambuc  Enum0Two
13f4a2713aSLionel Sambuc} Enum0;
14f4a2713aSLionel Sambuc
15f4a2713aSLionel Sambuc// Enum declared with the NS_ENUM macro
16f4a2713aSLionel Sambuctypedef NS_ENUM(NSInteger, Enum1) {
17f4a2713aSLionel Sambuc  Enum1One = -1,
18f4a2713aSLionel Sambuc  Enum1Two
19f4a2713aSLionel Sambuc};
20f4a2713aSLionel Sambuc
21f4a2713aSLionel Sambuc// Enum declared with a fixed underlying type
22f4a2713aSLionel Sambuctypedef enum : NSInteger {
23f4a2713aSLionel Sambuc  Enum2One = -1,
24f4a2713aSLionel Sambuc  Enum2Two
25f4a2713aSLionel Sambuc} Enum2;
26f4a2713aSLionel Sambuc
27f4a2713aSLionel Sambuc// Typedef and declaration separately
28f4a2713aSLionel Sambucenum : NSInteger
29f4a2713aSLionel Sambuc{
30f4a2713aSLionel Sambuc  Enum3One = -1,
31f4a2713aSLionel Sambuc  Enum3Two
32f4a2713aSLionel Sambuc};
33f4a2713aSLionel Sambuctypedef NSInteger Enum3;
34f4a2713aSLionel Sambuc
35f4a2713aSLionel Sambucint main() {
36f4a2713aSLionel Sambuc  Enum0 e0 = Enum0One;
37*0a6a1f1dSLionel Sambuc  // CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM0:[0-9]+]], metadata !{{.*}})
38f4a2713aSLionel Sambuc  Enum1 e1 = Enum1One;
39*0a6a1f1dSLionel Sambuc  // CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM1:[0-9]+]], metadata !{{.*}})
40f4a2713aSLionel Sambuc  Enum2 e2 = Enum2One;
41*0a6a1f1dSLionel Sambuc  // CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM2:[0-9]+]], metadata !{{.*}})
42f4a2713aSLionel Sambuc  Enum3 e3 = Enum3One;
43*0a6a1f1dSLionel Sambuc  // CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM3:[0-9]+]], metadata !{{.*}})
44f4a2713aSLionel Sambuc
45f4a2713aSLionel Sambuc  // -Werror and the following line ensures that these enums are not
46f4a2713aSLionel Sambuc  // -treated as C++11 strongly typed enums.
47f4a2713aSLionel Sambuc  return e0 != e1 && e1 == e2 && e2 == e3;
48f4a2713aSLionel Sambuc}
49f4a2713aSLionel Sambuc// CHECK: ![[ENUMERATOR0:[0-9]+]] = {{.*}}; [ DW_TAG_enumeration_type ] [line 10
50f4a2713aSLionel Sambuc// CHECK: ![[ENUMERATOR1:[0-9]+]] = {{.*}}; [ DW_TAG_enumeration_type ] [Enum1] [line 16{{.*}}] [from NSInteger]
51f4a2713aSLionel Sambuc// CHECK: ![[ENUMERATOR3:[0-9]+]] = {{.*}}; [ DW_TAG_typedef ] [NSInteger] [line 6{{.*}}] [from long int]
52f4a2713aSLionel Sambuc// CHECK: ![[ENUMERATOR2:[0-9]+]] = {{.*}}; [ DW_TAG_enumeration_type ] [line 22{{.*}}] [from NSInteger]
53f4a2713aSLionel Sambuc
54*0a6a1f1dSLionel Sambuc// CHECK: ![[ENUM0]] = !{!"0x100\00e0\00{{[^,]*}}"{{, [^,]+, [^,]+}}, ![[TYPE0:[0-9]+]]} ; [ DW_TAG_auto_variable ]
55*0a6a1f1dSLionel Sambuc// CHECK: ![[TYPE0]] = !{!"0x16\00Enum0\00{{.*}}", {{.*}}, ![[ENUMERATOR0]]} ; [ DW_TAG_typedef ] [Enum0]
56f4a2713aSLionel Sambuc
57*0a6a1f1dSLionel Sambuc// CHECK: ![[ENUM1]] = !{!"0x100\00e1\00{{[^,]*}}"{{, [^,]+, [^,]+}}, ![[TYPE1:[0-9]+]]} ; [ DW_TAG_auto_variable ]
58*0a6a1f1dSLionel Sambuc// CHECK: ![[TYPE1]] = !{!"0x16\00Enum1\00{{.*}}", {{.*}}, ![[ENUMERATOR1]]} ; [ DW_TAG_typedef ] [Enum1]
59f4a2713aSLionel Sambuc
60*0a6a1f1dSLionel Sambuc// CHECK: ![[ENUM2]] = !{!"0x100\00e2\00{{[^,]*}}"{{, [^,]+, [^,]+}}, ![[TYPE2:[0-9]+]]} ; [ DW_TAG_auto_variable ]
61*0a6a1f1dSLionel Sambuc// CHECK: ![[TYPE2]] = !{!"0x16\00Enum2\00{{.*}}", {{.*}}, ![[ENUMERATOR2]]} ; [ DW_TAG_typedef ] [Enum2]
62f4a2713aSLionel Sambuc
63*0a6a1f1dSLionel Sambuc// CHECK: ![[ENUM3]] = !{!"0x100\00e3\00{{[^,]*}}"{{, [^,]+, [^,]+}}, ![[TYPE3:[0-9]+]]} ; [ DW_TAG_auto_variable ]
64*0a6a1f1dSLionel Sambuc// CHECK: ![[TYPE3]] = !{!"0x16\00Enum3\00{{.*}}", {{.*}}, ![[ENUMERATOR3]]} ; [ DW_TAG_typedef ] [Enum3]
65