
Having AllEnumtypes to be a vector of TrackingMDNodeRef makes it possible to reflect changes in metadata in the vector if they took place before DIBuilder being finalized. Otherwise, we end up with heap-use-after-free because AllEnumTypes contains metadata that no longer valid. Consider a case where we have a class containing a definition of a enum, so this enum has the class as a scope. For some reason (doesn't matter for the current issue), we create a temporary debug metadata for this class, and then resolve it while finalizing CGDebugInfo. In the case of collision during uniqifying the temporary, we then need to replace its uses with a new pointer. If a temporary's user is unique (this is the enum mentioned above), we may need re-uniquefying it, which may return a new pointer in the case of another collision. If so, the pointer we stored in AllEnumTypes vector become dangling. Making AllEnumTypes hodling TrackingMDNodeRef should solve this problem (see debug-info-enum-metadata-collision.cpp test for details). Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D137067
26 lines
923 B
C++
26 lines
923 B
C++
// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -debug-info-kind=constructor %s -o - | FileCheck %s
|
|
|
|
// Test that clang doesn't crash while resolving temporary debug metadata of
|
|
// a record with collisions in the record's enum users.
|
|
|
|
// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
|
|
// CHECK-SAME: scope: [[SCOPE:![0-9]+]]
|
|
// CHECK-SAME: elements: [[ELEMENTS:![0-9]+]]
|
|
// CHECK: [[SCOPE]] = !DICompositeType(tag: DW_TAG_structure_type
|
|
// CHECK-SAME: name: "Struct1<Struct3>"
|
|
// CHECK: [[ELEMENTS]] = !{[[ELEMENT:![0-9]+]]}
|
|
// CHECK: [[ELEMENT]] = !DIEnumerator(name: "enumValue1"
|
|
|
|
template <typename> struct Struct1 {
|
|
enum { enumValue1 };
|
|
Struct1();
|
|
};
|
|
void function2() {
|
|
struct Struct3 {};
|
|
int i = Struct1<Struct3>::enumValue1;
|
|
}
|
|
void function3() {
|
|
struct Struct3 {};
|
|
int i = Struct1<Struct3>::enumValue1;
|
|
}
|