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