Douglas Katzman | 3459ce2 | 2015-10-08 04:24:12 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s |
Adrian Prantl | c60dc71 | 2013-04-19 19:56:39 +0000 | [diff] [blame] | 2 | // The DWARF standard says the underlying data type of an enum may be |
Adrian Prantl | b37427f | 2013-04-19 21:48:07 +0000 | [diff] [blame] | 3 | // stored in an DW_AT_type entry in the enum DIE. This is useful to have |
| 4 | // so the debugger knows about the signedness of the underlying type. |
Adrian Prantl | c60dc71 | 2013-04-19 19:56:39 +0000 | [diff] [blame] | 5 | |
| 6 | typedef long NSInteger; |
| 7 | #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type |
| 8 | |
| 9 | // Enum with no specified underlying type |
| 10 | typedef enum { |
| 11 | Enum0One, |
| 12 | Enum0Two |
| 13 | } Enum0; |
| 14 | |
| 15 | // Enum declared with the NS_ENUM macro |
| 16 | typedef NS_ENUM(NSInteger, Enum1) { |
| 17 | Enum1One = -1, |
| 18 | Enum1Two |
| 19 | }; |
| 20 | |
| 21 | // Enum declared with a fixed underlying type |
| 22 | typedef enum : NSInteger { |
| 23 | Enum2One = -1, |
| 24 | Enum2Two |
| 25 | } Enum2; |
| 26 | |
| 27 | // Typedef and declaration separately |
| 28 | enum : NSInteger |
| 29 | { |
| 30 | Enum3One = -1, |
| 31 | Enum3Two |
| 32 | }; |
| 33 | typedef NSInteger Enum3; |
| 34 | |
| 35 | int main() { |
| 36 | Enum0 e0 = Enum0One; |
Duncan P. N. Exon Smith | b3a6669 | 2014-12-15 19:10:08 +0000 | [diff] [blame] | 37 | // CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM0:[0-9]+]], metadata !{{.*}}) |
Adrian Prantl | c60dc71 | 2013-04-19 19:56:39 +0000 | [diff] [blame] | 38 | Enum1 e1 = Enum1One; |
Duncan P. N. Exon Smith | b3a6669 | 2014-12-15 19:10:08 +0000 | [diff] [blame] | 39 | // CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM1:[0-9]+]], metadata !{{.*}}) |
Adrian Prantl | c60dc71 | 2013-04-19 19:56:39 +0000 | [diff] [blame] | 40 | Enum2 e2 = Enum2One; |
Duncan P. N. Exon Smith | b3a6669 | 2014-12-15 19:10:08 +0000 | [diff] [blame] | 41 | // CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM2:[0-9]+]], metadata !{{.*}}) |
Adrian Prantl | c60dc71 | 2013-04-19 19:56:39 +0000 | [diff] [blame] | 42 | Enum3 e3 = Enum3One; |
Duncan P. N. Exon Smith | b3a6669 | 2014-12-15 19:10:08 +0000 | [diff] [blame] | 43 | // CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM3:[0-9]+]], metadata !{{.*}}) |
Adrian Prantl | c60dc71 | 2013-04-19 19:56:39 +0000 | [diff] [blame] | 44 | |
| 45 | // -Werror and the following line ensures that these enums are not |
| 46 | // -treated as C++11 strongly typed enums. |
| 47 | return e0 != e1 && e1 == e2 && e2 == e3; |
| 48 | } |
Duncan P. N. Exon Smith | 9dd4e4e | 2015-04-29 16:40:08 +0000 | [diff] [blame] | 49 | // CHECK: ![[ENUMERATOR0:[0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame] | 50 | // CHECK-SAME: line: 10, |
Duncan P. N. Exon Smith | 9dd4e4e | 2015-04-29 16:40:08 +0000 | [diff] [blame] | 51 | // CHECK: ![[ENUMERATOR1:[0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum1" |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame] | 52 | // CHECK-SAME: line: 16 |
| 53 | // CHECK-SAME: baseType: ![[ENUMERATOR3:[0-9]+]] |
Duncan P. N. Exon Smith | 9dd4e4e | 2015-04-29 16:40:08 +0000 | [diff] [blame] | 54 | // CHECK: ![[ENUMERATOR3]] = !DIDerivedType(tag: DW_TAG_typedef, name: "NSInteger" |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame] | 55 | // CHECK-SAME: line: 6 |
| 56 | // CHECK-SAME: baseType: ![[LONGINT:[0-9]+]] |
Duncan P. N. Exon Smith | 9dd4e4e | 2015-04-29 16:40:08 +0000 | [diff] [blame] | 57 | // CHECK: ![[LONGINT]] = !DIBasicType(name: "long int" |
| 58 | // CHECK: ![[ENUMERATOR2:[0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame] | 59 | // CHECK-SAME: line: 22 |
| 60 | // CHECK-SAME: baseType: ![[ENUMERATOR3]] |
Adrian Prantl | c60dc71 | 2013-04-19 19:56:39 +0000 | [diff] [blame] | 61 | |
Duncan P. N. Exon Smith | 38a7f11 | 2015-07-31 18:59:37 +0000 | [diff] [blame] | 62 | // CHECK: ![[ENUM0]] = !DILocalVariable(name: "e0" |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame] | 63 | // CHECK-SAME: type: ![[TYPE0:[0-9]+]] |
Duncan P. N. Exon Smith | 9dd4e4e | 2015-04-29 16:40:08 +0000 | [diff] [blame] | 64 | // CHECK: ![[TYPE0]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum0", |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame] | 65 | // CHECK-SAME: baseType: ![[ENUMERATOR0]] |
Adrian Prantl | c60dc71 | 2013-04-19 19:56:39 +0000 | [diff] [blame] | 66 | |
Duncan P. N. Exon Smith | 38a7f11 | 2015-07-31 18:59:37 +0000 | [diff] [blame] | 67 | // CHECK: ![[ENUM1]] = !DILocalVariable(name: "e1" |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame] | 68 | // CHECK-SAME: type: ![[TYPE1:[0-9]+]] |
Duncan P. N. Exon Smith | 9dd4e4e | 2015-04-29 16:40:08 +0000 | [diff] [blame] | 69 | // CHECK: ![[TYPE1]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum1" |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame] | 70 | // CHECK-SAME: baseType: ![[ENUMERATOR1]] |
Adrian Prantl | c60dc71 | 2013-04-19 19:56:39 +0000 | [diff] [blame] | 71 | |
Duncan P. N. Exon Smith | 38a7f11 | 2015-07-31 18:59:37 +0000 | [diff] [blame] | 72 | // CHECK: ![[ENUM2]] = !DILocalVariable(name: "e2" |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame] | 73 | // CHECK-SAME: type: ![[TYPE2:[0-9]+]] |
Duncan P. N. Exon Smith | 9dd4e4e | 2015-04-29 16:40:08 +0000 | [diff] [blame] | 74 | // CHECK: ![[TYPE2]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum2" |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame] | 75 | // CHECK-SAME: baseType: ![[ENUMERATOR2]] |
Adrian Prantl | c60dc71 | 2013-04-19 19:56:39 +0000 | [diff] [blame] | 76 | |
Duncan P. N. Exon Smith | 38a7f11 | 2015-07-31 18:59:37 +0000 | [diff] [blame] | 77 | // CHECK: ![[ENUM3]] = !DILocalVariable(name: "e3" |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame] | 78 | // CHECK-SAME: type: ![[TYPE3:[0-9]+]] |
Duncan P. N. Exon Smith | 9dd4e4e | 2015-04-29 16:40:08 +0000 | [diff] [blame] | 79 | // CHECK: ![[TYPE3]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum3" |
Duncan P. N. Exon Smith | f04be1f | 2015-03-03 17:25:55 +0000 | [diff] [blame] | 80 | // CHECK-SAME: baseType: ![[ENUMERATOR3]] |