diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1660,6 +1660,14 @@ let Documentation = [NoDebugDocs]; } +def StandaloneDebug : InheritableAttr { + let Spellings = [Clang<"standalone_debug">]; + let Subjects = SubjectList<[CXXRecord]>; + let Documentation = [Undocumented]; + let SimpleHandler = 1; + let LangOpts = [CPlusPlus]; +} + def NoDuplicate : InheritableAttr { let Spellings = [Clang<"noduplicate">]; let Subjects = SubjectList<[Function]>; diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -2385,7 +2385,8 @@ if (DebugKind == codegenoptions::DebugLineTablesOnly) return true; - if (DebugKind > codegenoptions::LimitedDebugInfo) + if (DebugKind > codegenoptions::LimitedDebugInfo || + RD->hasAttr()) return false; if (!LangOpts.CPlusPlus) diff --git a/clang/test/CodeGenCXX/force-debug-attribute.cpp b/clang/test/CodeGenCXX/force-debug-attribute.cpp new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenCXX/force-debug-attribute.cpp @@ -0,0 +1,28 @@ +// 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__((standalone_debug)) +#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) {} +// DEBUG: !DICompositeType({{.*}}name: "some_struct" +// DEBUG-SAME: flags: {{.*}}DIFlagFwdDecl +// WITHATTR: !DICompositeType({{.*}}name: "some_struct" +// WITHATTR-NOT: DIFlagFwdDecl + +template struct Foo { Foo() {} T x; }; +extern template struct DEBUGASNEEDED Foo; +void func2(Foo f) {} +// DEBUG: !DICompositeType({{.*}}name: "Foo" +// DEBUG-SAME: flags: {{.*}}DIFlagFwdDecl +// WITHATTR: !DICompositeType({{.*}}name: "Foo" +// WITHATTR-NOT: DIFlagFwdDecl