File: objc-fixed-enum.m

package info (click to toggle)
llvm-toolchain-18 1%3A18.1.8-18
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,908,340 kB
  • sloc: cpp: 6,667,937; ansic: 1,440,452; asm: 883,619; python: 230,549; objc: 76,880; f90: 74,238; lisp: 35,989; pascal: 16,571; sh: 10,229; perl: 7,459; ml: 5,047; awk: 3,523; makefile: 2,987; javascript: 2,149; xml: 892; fortran: 649; cs: 573
file content (80 lines) | stat: -rw-r--r-- 3,389 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// RUN: %clang_cc1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
// The DWARF standard says the underlying data type of an enum may be
// stored in an DW_AT_type entry in the enum DIE. This is useful to have
// so the debugger knows about the signedness of the underlying type.

typedef long NSInteger;
#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type

// Enum with no specified underlying type
typedef enum {
  Enum0One,
  Enum0Two
} Enum0;

// Enum declared with the NS_ENUM macro
typedef NS_ENUM(NSInteger, Enum1) {
  Enum1One = -1,
  Enum1Two
};

// Enum declared with a fixed underlying type
typedef enum : NSInteger {
  Enum2One = -1,
  Enum2Two
} Enum2;

// Typedef and declaration separately
enum : NSInteger
{
  Enum3One = -1,
  Enum3Two
};
typedef NSInteger Enum3;

int main(void) {
  Enum0 e0 = Enum0One;
  // CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM0:[0-9]+]], metadata !{{.*}})
  Enum1 e1 = Enum1One;
  // CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM1:[0-9]+]], metadata !{{.*}})
  Enum2 e2 = Enum2One;
  // CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM2:[0-9]+]], metadata !{{.*}})
  Enum3 e3 = Enum3One;
  // CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM3:[0-9]+]], metadata !{{.*}})

  // -Werror and the following line ensures that these enums are not
  // -treated as C++11 strongly typed enums.
  return e0 != e1 && e1 == e2 && e2 == e3;
}
// CHECK: ![[ENUMERATOR0:[0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type
// CHECK-SAME:                                       line: 10,
// CHECK: ![[ENUMERATOR1:[0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum1"
// CHECK-SAME:                                       line: 16
// CHECK-SAME:                                       baseType: ![[ENUMERATOR3:[0-9]+]]
// CHECK: ![[ENUMERATOR3]] = !DIDerivedType(tag: DW_TAG_typedef, name: "NSInteger"
// CHECK-SAME:                              line: 6
// CHECK-SAME:                              baseType: ![[LONGINT:[0-9]+]]
// CHECK: ![[LONGINT]] = !DIBasicType(name: "long"
// CHECK: ![[ENUMERATOR2:[0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type,
// CHECK-SAME:                                       line: 22
// CHECK-SAME:                                       baseType: ![[ENUMERATOR3]]

// CHECK: ![[ENUM0]] = !DILocalVariable(name: "e0"
// CHECK-SAME:                          type: ![[TYPE0:[0-9]+]]
// CHECK: ![[TYPE0]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum0",
// CHECK-SAME:                        baseType: ![[ENUMERATOR0]]

// CHECK: ![[ENUM1]] = !DILocalVariable(name: "e1"
// CHECK-SAME:                          type: ![[TYPE1:[0-9]+]]
// CHECK: ![[TYPE1]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum1"
// CHECK-SAME:                        baseType: ![[ENUMERATOR1]]

// CHECK: ![[ENUM2]] = !DILocalVariable(name: "e2"
// CHECK-SAME:                          type: ![[TYPE2:[0-9]+]]
// CHECK: ![[TYPE2]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum2"
// CHECK-SAME:                        baseType: ![[ENUMERATOR2]]

// CHECK: ![[ENUM3]] = !DILocalVariable(name: "e3"
// CHECK-SAME:                          type: ![[TYPE3:[0-9]+]]
// CHECK: ![[TYPE3]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum3"
// CHECK-SAME:                        baseType: ![[ENUMERATOR3]]