2015-10-08 12:24:12 +08:00
|
|
|
// RUN: %clang_cc1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
|
2013-04-20 03:56:39 +08:00
|
|
|
// The DWARF standard says the underlying data type of an enum may be
|
2013-04-20 05:48:07 +08:00
|
|
|
// 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.
|
2013-04-20 03:56:39 +08:00
|
|
|
|
|
|
|
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() {
|
|
|
|
Enum0 e0 = Enum0One;
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM0:[0-9]+]], metadata !{{.*}})
|
2013-04-20 03:56:39 +08:00
|
|
|
Enum1 e1 = Enum1One;
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM1:[0-9]+]], metadata !{{.*}})
|
2013-04-20 03:56:39 +08:00
|
|
|
Enum2 e2 = Enum2One;
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM2:[0-9]+]], metadata !{{.*}})
|
2013-04-20 03:56:39 +08:00
|
|
|
Enum3 e3 = Enum3One;
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: call void @llvm.dbg.declare(metadata {{.*}}, metadata ![[ENUM3:[0-9]+]], metadata !{{.*}})
|
2013-04-20 03:56:39 +08:00
|
|
|
|
|
|
|
// -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;
|
|
|
|
}
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: ![[ENUMERATOR0:[0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: line: 10,
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: ![[ENUMERATOR1:[0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum1"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: line: 16
|
|
|
|
// CHECK-SAME: baseType: ![[ENUMERATOR3:[0-9]+]]
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: ![[ENUMERATOR3]] = !DIDerivedType(tag: DW_TAG_typedef, name: "NSInteger"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: line: 6
|
|
|
|
// CHECK-SAME: baseType: ![[LONGINT:[0-9]+]]
|
DebugInfo: Use clang's preferred names for integer types
This reverts c7f16ab3e3f27d944db72908c9c1b1b7366f5515 / r109694 - which
suggested this was done to improve consistency with the gdb test suite.
Possible that at the time GCC did not canonicalize integer types, and so
matching types was important for cross-compiler validity, or that it was
only a case of over-constrained test cases that printed out/tested the
exact names of integer types.
In any case neither issue seems to exist today based on my limited
testing - both gdb and lldb canonicalize integer types (in a way that
happens to match Clang's preferred naming, incidentally) and so never
print the original text name produced in the DWARF by GCC or Clang.
This canonicalization appears to be in `integer_types_same_name_p` for
GDB and in `TypeSystemClang::GetBasicTypeEnumeration` for lldb.
(I tested this with one translation unit defining 3 variables - `long`,
`long (*)()`, and `int (*)()`, and another translation unit that had
main, and a function that took `long (*)()` as a parameter - then
compiled them with mismatched compilers (either GCC+Clang, or
Clang+(Clang with this patch applied)) and no matter the combination,
despite the debug info for one CU naming the type "long int" and the
other naming it "long", both debuggers printed out the name as "long"
and were able to correctly perform overload resolution and pass the
`long int (*)()` variable to the `long (*)()` function parameter)
Did find one hiccup, identified by the lldb test suite - that CodeView
was relying on these names to map them to builtin types in that format.
So added some handling for that in LLVM. (these could be split out into
separate patches, but seems small enough to not warrant it - will do
that if there ends up needing any reverti/revisiting)
Differential Revision: https://reviews.llvm.org/D110455
2021-09-25 07:13:07 +08:00
|
|
|
// CHECK: ![[LONGINT]] = !DIBasicType(name: "long"
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: ![[ENUMERATOR2:[0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type,
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: line: 22
|
|
|
|
// CHECK-SAME: baseType: ![[ENUMERATOR3]]
|
2013-04-20 03:56:39 +08:00
|
|
|
|
2015-08-01 02:59:37 +08:00
|
|
|
// CHECK: ![[ENUM0]] = !DILocalVariable(name: "e0"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: type: ![[TYPE0:[0-9]+]]
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: ![[TYPE0]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum0",
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: baseType: ![[ENUMERATOR0]]
|
2013-04-20 03:56:39 +08:00
|
|
|
|
2015-08-01 02:59:37 +08:00
|
|
|
// CHECK: ![[ENUM1]] = !DILocalVariable(name: "e1"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: type: ![[TYPE1:[0-9]+]]
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: ![[TYPE1]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum1"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: baseType: ![[ENUMERATOR1]]
|
2013-04-20 03:56:39 +08:00
|
|
|
|
2015-08-01 02:59:37 +08:00
|
|
|
// CHECK: ![[ENUM2]] = !DILocalVariable(name: "e2"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: type: ![[TYPE2:[0-9]+]]
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: ![[TYPE2]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum2"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: baseType: ![[ENUMERATOR2]]
|
2013-04-20 03:56:39 +08:00
|
|
|
|
2015-08-01 02:59:37 +08:00
|
|
|
// CHECK: ![[ENUM3]] = !DILocalVariable(name: "e3"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: type: ![[TYPE3:[0-9]+]]
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: ![[TYPE3]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Enum3"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: baseType: ![[ENUMERATOR3]]
|