Skip to content
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

[lldb] Fix crash when adding members to an "incomplete" type #102116

Merged
merged 2 commits into from
Aug 8, 2024
Merged
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
11 changes: 9 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,15 @@ static void PrepareContextToReceiveMembers(TypeSystemClang &ast,
}

// We don't have a type definition and/or the import failed, but we need to
// add members to it. Start the definition to make that possible.
tag_decl_ctx->startDefinition();
// add members to it. Start the definition to make that possible. If the type
// has no external storage we also have to complete the definition. Otherwise,
// that will happen when we are asked to complete the type
// (CompleteTypeFromDWARF).
ast.StartTagDeclarationDefinition(type);
if (!tag_decl_ctx->hasExternalLexicalStorage()) {
ast.SetDeclIsForcefullyCompleted(tag_decl_ctx);
ast.CompleteTagDeclarationDefinition(type);
}
}

ParsedDWARFTypeAttributes::ParsedDWARFTypeAttributes(const DWARFDIE &die) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %clangxx --target=x86_64-pc-linux -flimit-debug-info -o %t -c %s -g
// RUN: %lldb %t -o "target var a" -o "expr -- var" -o exit | FileCheck %s

// This forces lldb to attempt to complete the type A. Since it has no
// definition it will fail.
// CHECK: target var a
// CHECK: (A) a = <incomplete type "A">

// Now attempt to display the second variable, which will try to add a typedef
// to the incomplete type. Make sure that succeeds. Use the expression command
// to make sure the resulting AST can be imported correctly.
// CHECK: expr -- var
// CHECK: (A::X) $0 = 0

struct A {
// Declare the constructor, but don't define it to avoid emitting the
// definition in the debug info.
A();
using X = int;
};

A a;
A::X var;
Loading