Skip to content

[DebugInfo] Produce debuginfo for nested types when the outer type is [[clang::standalone_debug]] #146175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2075,12 +2075,13 @@ void CGDebugInfo::CollectRecordFields(

// Bump field number for next field.
++fieldNo;
} else if (CGM.getCodeGenOpts().EmitCodeView) {
} else if (CGM.getCodeGenOpts().EmitCodeView ||
record->hasAttr<StandaloneDebugAttr>()) {
// Debug info for nested types is included in the member list only for
// CodeView.
// CodeView and types with the standalone_debug attribute.
if (const auto *nestedType = dyn_cast<TypeDecl>(I)) {
// MSVC doesn't generate nested type for anonymous struct/union.
if (isa<RecordDecl>(I) &&
if (CGM.getCodeGenOpts().EmitCodeView && isa<RecordDecl>(I) &&
cast<RecordDecl>(I)->isAnonymousStructOrUnion())
continue;
if (!nestedType->isImplicit() &&
Expand Down
29 changes: 29 additions & 0 deletions clang/test/CodeGenCXX/standalone-debug-attribute-limited.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %clang_cc1 -DSETATTR=0 -triple x86_64-unknown-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=DEBUG
// RUN: %clang_cc1 -DSETATTR=1 -triple x86_64-unknown-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=WITHATTR
// Use -debug-info-kind=limited because an unused type will never have a used ctor.

#if SETATTR
#define STANDALONEDEBUGATTR __attribute__((standalone_debug))
#else
#define STANDALONEDEBUGATTR
#endif

struct STANDALONEDEBUGATTR TypeWithNested {
struct Unused1 {
};
struct STANDALONEDEBUGATTR Unused2 {
};

int value = 0;
};
void f(TypeWithNested s) {}
// DEBUG: !DICompositeType(tag: DW_TAG_structure_type, name: "TypeWithNested"
// DEBUG-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "Unused1"
// DEBUG-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "Unused2"
// WITHATTR: !DICompositeType(tag: DW_TAG_structure_type, name: "TypeWithNested"
// WITHATTR: !DICompositeType(tag: DW_TAG_structure_type, name: "Unused1"
// The STANDALONEDEBUGATTR isn't propagated to the nested type by default, so
// it should still be a forward declaration.
// WITHATTR-SAME: DIFlagFwdDecl
// WITHATTR: !DICompositeType(tag: DW_TAG_structure_type, name: "Unused2"
// WITHATTR-NOT: DIFlagFwdDecl
Loading