Skip to content

Commit

Permalink
[lldb] Fix crash when adding members to an "incomplete" type
Browse files Browse the repository at this point in the history
This fixes a regression caused by delayed type definition searching
(llvm#96755 and friends): If we end up adding a member (e.g. a typedef) to a
type that we've already attempted to complete (and failed), the
resulting AST would end up inconsistent (we would start to "forcibly"
complete it, but never finish it), and importing it into an expression
AST would crash.

This patch fixes this by detecting the situation and finishing the
definition as well.
  • Loading branch information
labath committed Aug 6, 2024
1 parent bb59f04 commit 14eb16d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
9 changes: 7 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,13 @@ 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.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 -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;

0 comments on commit 14eb16d

Please sign in to comment.