[DebugInfo] Add an attribute to force type info to be emitted for

class types.

The goal is to provide a way to bypass constructor homing when emitting
class definitions and force class definitions in the debug info.

Not sure about the wording of the attribute, or whether it should be
specific to classes with constructors
This commit is contained in:
Amy Huang 2021-02-05 15:43:45 -08:00
parent 3f22547fd1
commit 1b5c2915a2
3 changed files with 33 additions and 0 deletions

View File

@ -1660,6 +1660,13 @@ def NoDebug : InheritableAttr {
let Documentation = [NoDebugDocs];
}
def DebugTypeInfoAsNeeded : InheritableAttr {
let Spellings = [Clang<"debug_type_info_as_needed">];
let Subjects = SubjectList<[CXXRecord]>;
let Documentation = [Undocumented];
let SimpleHandler = 1;
}
def NoDuplicate : InheritableAttr {
let Spellings = [Clang<"noduplicate">];
let Subjects = SubjectList<[Function]>;

View File

@ -2344,6 +2344,10 @@ static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
if (!CXXDecl)
return false;
// Don't omit definition if marked with attribute.
if (RD->hasAttr<DebugTypeInfoAsNeededAttr>())
return false;
// Only emit complete debug info for a dynamic class when its vtable is
// emitted. However, Microsoft debuggers don't resolve type information
// across DLL boundaries, so skip this optimization if the class or any of its

View File

@ -0,0 +1,22 @@
// RUN: %clang_cc1 -DSETATTR=0 -emit-llvm -std=c++14 -debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=DEBUG
// RUN: %clang_cc1 -DSETATTR=1 -emit-llvm -std=c++14 -debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=WITHATTR
#if SETATTR
#define DEBUGASNEEDED __attribute__((debug_type_info_as_needed))
#else
#define DEBUGASNEEDED
#endif
// Struct that isn't constructed, so its full type info should be omitted with
// -debug-info-kind=constructor.
struct DEBUGASNEEDED some_struct {
some_struct() {}
};
void func1(some_struct s) {}
// void func2() { func1(); }
// DEBUG: !DICompositeType({{.*}}name: "some_struct"
// DEBUG-SAME: flags: {{.*}}DIFlagFwdDecl
// WITHATTR: !DICompositeType({{.*}}name: "some_struct"
// WITHATTR-NOT: DIFlagFwdDecl