[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGenObjC / objc-fixed-enum.m
blob6ac2ae6debee6154189682449a16a8635fc437db
1 // RUN: %clang_cc1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
2 // The DWARF standard says the underlying data type of an enum may be
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.
6 typedef long NSInteger;
7 #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
9 // Enum with no specified underlying type
10 typedef enum {
11   Enum0One,
12   Enum0Two
13 } Enum0;
15 // Enum declared with the NS_ENUM macro
16 typedef NS_ENUM(NSInteger, Enum1) {
17   Enum1One = -1,
18   Enum1Two
21 // Enum declared with a fixed underlying type
22 typedef enum : NSInteger {
23   Enum2One = -1,
24   Enum2Two
25 } Enum2;
27 // Typedef and declaration separately
28 enum : NSInteger
30   Enum3One = -1,
31   Enum3Two
33 typedef NSInteger Enum3;
35 int main(void) {
36   Enum0 e0 = Enum0One;
37   // CHECK: #dbg_declare({{.*}}, ![[ENUM0:[0-9]+]], !{{.*}})
38   Enum1 e1 = Enum1One;
39   // CHECK: #dbg_declare({{.*}}, ![[ENUM1:[0-9]+]], !{{.*}})
40   Enum2 e2 = Enum2One;
41   // CHECK: #dbg_declare({{.*}}, ![[ENUM2:[0-9]+]], !{{.*}})
42   Enum3 e3 = Enum3One;
43   // CHECK: #dbg_declare({{.*}}, ![[ENUM3:[0-9]+]], !{{.*}})
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;
49 // CHECK: ![[ENUMERATOR0:[0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type
50 // CHECK-SAME:                                       line: 10,
51 // CHECK: ![[ENUMERATOR1:[0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum1"
52 // CHECK-SAME:                                       line: 16
53 // CHECK-SAME:                                       baseType: ![[ENUMERATOR3:[0-9]+]]
54 // CHECK: ![[ENUMERATOR3]] = !DIDerivedType(tag: DW_TAG_typedef, name: "NSInteger"
55 // CHECK-SAME:                              line: 6
56 // CHECK-SAME:                              baseType: ![[LONGINT:[0-9]+]]
57 // CHECK: ![[LONGINT]] = !DIBasicType(name: "long"
58 // CHECK: ![[ENUMERATOR2:[0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type,
59 // CHECK-SAME:                                       line: 22
60 // CHECK-SAME:                                       baseType: ![[ENUMERATOR3]]
62 // CHECK: ![[ENUM0]] = !DILocalVariable(name: "e0"
63 // CHECK-SAME:                          type: ![[TYPE0:[0-9]+]]
64 // CHECK: ![[TYPE0]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum0",
65 // CHECK-SAME:                        baseType: ![[ENUMERATOR0]]
67 // CHECK: ![[ENUM1]] = !DILocalVariable(name: "e1"
68 // CHECK-SAME:                          type: ![[TYPE1:[0-9]+]]
69 // CHECK: ![[TYPE1]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum1"
70 // CHECK-SAME:                        baseType: ![[ENUMERATOR1]]
72 // CHECK: ![[ENUM2]] = !DILocalVariable(name: "e2"
73 // CHECK-SAME:                          type: ![[TYPE2:[0-9]+]]
74 // CHECK: ![[TYPE2]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum2"
75 // CHECK-SAME:                        baseType: ![[ENUMERATOR2]]
77 // CHECK: ![[ENUM3]] = !DILocalVariable(name: "e3"
78 // CHECK-SAME:                          type: ![[TYPE3:[0-9]+]]
79 // CHECK: ![[TYPE3]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum3"
80 // CHECK-SAME:                        baseType: ![[ENUMERATOR3]]