[Lldb-commits] [lldb] [lldb] Fix crash when adding members to an "incomplete" type (PR #102116)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Aug 6 06:11:38 PDT 2024
https://github.com/labath updated https://github.com/llvm/llvm-project/pull/102116
>From c5373215793f744ab80b80e394354e455b415fcb Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Tue, 6 Aug 2024 11:36:31 +0200
Subject: [PATCH 1/2] [lldb] Fix crash when adding members to an "incomplete"
type
This fixes a regression caused by delayed type definition searching
(#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.
---
.../SymbolFile/DWARF/DWARFASTParserClang.cpp | 11 +++++++--
.../DWARF/x86/typedef-in-incomplete-type.cpp | 23 +++++++++++++++++++
2 files changed, 32 insertions(+), 2 deletions(-)
create mode 100644 lldb/test/Shell/SymbolFile/DWARF/x86/typedef-in-incomplete-type.cpp
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index a4dcde1629fc2..3968d5bf71e1c 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -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) {
diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/typedef-in-incomplete-type.cpp b/lldb/test/Shell/SymbolFile/DWARF/x86/typedef-in-incomplete-type.cpp
new file mode 100644
index 0000000000000..47ea1e2639c6e
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/typedef-in-incomplete-type.cpp
@@ -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;
>From 1a0a69810c2329fcb558592637bd39ee82262942 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Tue, 6 Aug 2024 15:11:14 +0200
Subject: [PATCH 2/2] add -flimit-debug-info
---
.../Shell/SymbolFile/DWARF/x86/typedef-in-incomplete-type.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/typedef-in-incomplete-type.cpp b/lldb/test/Shell/SymbolFile/DWARF/x86/typedef-in-incomplete-type.cpp
index 47ea1e2639c6e..591607784b0a9 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/typedef-in-incomplete-type.cpp
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/typedef-in-incomplete-type.cpp
@@ -1,4 +1,4 @@
-// RUN: %clangxx --target=x86_64-pc-linux -o %t -c %s -g
+// 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
More information about the lldb-commits
mailing list