Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CodeGen / debug-info-enum.cpp
blob4d83fdc32903cec597300bbbb0fe3749c08e245b
1 // Test enumeration representation in debuig info metadata:
2 // * test value representation for each possible underlying integer type
3 // * test the integer type is as expected
4 // * test the DW_AT_enum_class attribute is present (resp. absent) as expected.
6 // RUN: %clang -target x86_64-linux -g -S -emit-llvm -o - %s | FileCheck %s
9 enum class E0 : signed char {
10 A0 = -128,
11 B0 = 127,
12 } x0;
13 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E0"
14 // CHECK-SAME: baseType: ![[SCHAR:[0-9]+]]
15 // CHECK-SAME: DIFlagEnumClass
16 // CHECK-SAME: elements: ![[ELTS0:[0-9]+]]
17 // CHECK: ![[SCHAR]] = !DIBasicType(name: "signed char", size: 8, encoding: DW_ATE_signed_char)
18 // CHECK: ![[ELTS0]] = !{![[A0:[0-9]+]], ![[B0:[0-9]+]]}
19 // CHECK: ![[A0]] = !DIEnumerator(name: "A0", value: -128)
20 // CHECK: ![[B0]] = !DIEnumerator(name: "B0", value: 127)
22 enum class E1 : unsigned char { A1 = 255 } x1;
23 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E1"
24 // CHECK-SAME: baseType: ![[UCHAR:[0-9]+]]
25 // CHECK-SAME: DIFlagEnumClass
26 // CHECK-SAME: elements: ![[ELTS1:[0-9]+]]
27 // CHECK: ![[UCHAR]] = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char)
28 // CHECK: ![[ELTS1]] = !{![[A1:[0-9]+]]}
29 // CHECK: ![[A1]] = !DIEnumerator(name: "A1", value: 255, isUnsigned: true)
31 enum class E2 : signed short {
32 A2 = -32768,
33 B2 = 32767,
34 } x2;
35 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E2"
36 // CHECK-SAME: baseType: ![[SHORT:[0-9]+]]
37 // CHECK-SAME: DIFlagEnumClass
38 // CHECK-SAME: elements: ![[ELTS2:[0-9]+]]
39 // CHECK: ![[SHORT]] = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed)
40 // CHECK: ![[ELTS2]] = !{![[A2:[0-9]+]], ![[B2:[0-9]+]]}
41 // CHECK: ![[A2]] = !DIEnumerator(name: "A2", value: -32768)
42 // CHECK: ![[B2]] = !DIEnumerator(name: "B2", value: 32767)
44 enum class E3 : unsigned short { A3 = 65535 } x3;
45 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E3"
46 // CHECK-SAME: baseType: ![[USHORT:[0-9]+]]
47 // CHECK-SAME: DIFlagEnumClass
48 // CHECK-SAME: elements: ![[ELTS3:[0-9]+]]
49 // CHECK: ![[USHORT]] = !DIBasicType(name: "unsigned short", size: 16, encoding: DW_ATE_unsigned)
50 // CHECK: ![[ELTS3]] = !{![[A3:[0-9]+]]}
51 // CHECK: ![[A3]] = !DIEnumerator(name: "A3", value: 65535, isUnsigned: true)
53 enum class E4 : signed int { A4 = -2147483648, B4 = 2147483647 } x4;
54 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E4"
55 // CHECK-SAME: baseType: ![[INT:[0-9]+]]
56 // CHECK-SAME: DIFlagEnumClass
57 // CHECK-SAME: elements: ![[ELTS4:[0-9]+]]
58 // CHECK: ![[INT]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
59 // CHECK: ![[ELTS4]] = !{![[A4:[0-9]+]], ![[B4:[0-9]+]]}
60 // CHECK: ![[A4]] = !DIEnumerator(name: "A4", value: -2147483648)
61 // CHECK: ![[B4]] = !DIEnumerator(name: "B4", value: 2147483647)
63 enum class E5 : unsigned int { A5 = 4294967295 } x5;
64 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E5"
65 // CHECK-SAME: baseType: ![[UINT:[0-9]+]]
66 // CHECK-SAME: DIFlagEnumClass
67 // CHECK-SAME: elements: ![[ELTS5:[0-9]+]]
68 // CHECK: ![[UINT]] = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
69 // CHECK: ![[ELTS5]] = !{![[A5:[0-9]+]]}
70 // CHECK: ![[A5]] = !DIEnumerator(name: "A5", value: 4294967295, isUnsigned: true)
72 enum class E6 : signed long long {
73 A6 = -9223372036854775807LL - 1,
74 B6 = 9223372036854775807LL
75 } x6;
76 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E6"
77 // CHECK-SAME: baseType: ![[LONG:[0-9]+]]
78 // CHECK-SAME: DIFlagEnumClass
79 // CHECK-SAME: elements: ![[ELTS6:[0-9]+]]
80 // CHECK: ![[LONG]] = !DIBasicType(name: "long long", size: 64, encoding: DW_ATE_signed)
81 // CHECK: ![[ELTS6]] = !{![[A6:[0-9]+]], ![[B6:[0-9]+]]}
82 // CHECK: ![[A6]] = !DIEnumerator(name: "A6", value: -9223372036854775808)
83 // CHECK: ![[B6]] = !DIEnumerator(name: "B6", value: 9223372036854775807)
85 enum class E7 : unsigned long long { A7 = 18446744073709551615ULL } x7;
86 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E7"
87 // CHECK-SAME: baseType: ![[ULONG:[0-9]+]]
88 // CHECK-SAME: DIFlagEnumClass
89 // CHECK-SAME: elements: ![[ELTS7:[0-9]+]]
90 // CHECK: ![[ULONG]] = !DIBasicType(name: "unsigned long long", size: 64, encoding: DW_ATE_unsigned)
91 // CHECK: ![[ELTS7]] = !{![[A7:[0-9]+]]}
92 // CHECK: ![[A7]] = !DIEnumerator(name: "A7", value: 18446744073709551615, isUnsigned: true)
94 // Also test the FixedEnum flag is not present for old-style enumerations.
95 enum E8 { A8 = -128, B8 = 127 } x8;
96 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "E8"
97 // CHECK-SAME: baseType: ![[INT]]
98 // CHECK-NOT: DIFlagEnumClass
99 // CHECK: !DIEnumerator(name: "A8", value: -128)