[Lldb-commits] [lldb] [lldb][ClangASTImporter][NFC] Emit a log message when we break MapImported invariant (PR #112748)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 18 01:48:58 PDT 2024
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/112748
>From 247f2638be2decf0f806050e90c25c4b664b2f97 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Thu, 17 Oct 2024 17:40:35 +0100
Subject: [PATCH 1/6] [lldb][ClangASTImporter][NFC] Emit a log message when we
break MapImported invariant
---
.../Clang/ClangASTImporter.cpp | 27 ++++++++++++++-----
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
index 630ad7e20ab7e0..9a0e354daff712 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -1136,6 +1136,25 @@ ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) {
void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
clang::Decl *to, clang::Decl *from) {
+ Log *log = GetLog(LLDBLog::Expressions);
+
+ auto getDeclName = [](Decl const *decl) {
+ std::string name_string;
+ if (auto const *from_named_decl = dyn_cast<clang::NamedDecl>(decl)) {
+ llvm::raw_string_ostream name_stream(name_string);
+ from_named_decl->printName(name_stream);
+ }
+
+ return name_string;
+ };
+
+ if (auto *D = GetAlreadyImportedOrNull(from); D && D != to)
+ LLDB_LOG(log,
+ "[ClangASTImporter] WARNING: overwriting an already imported decl "
+ "'{0:x}' ('{1}') from '{2:x}' with {3:x}. Likely due to a name "
+ "conflict when importing {1}.",
+ D, getDeclName(from), from, to);
+
// We might have a forward declaration from a shared library that we
// gave external lexical storage so that Clang asks us about the full
// definition when it needs it. In this case the ASTImporter isn't aware
@@ -1145,8 +1164,6 @@ void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
// tell the ASTImporter that 'to' was imported from 'from'.
MapImported(from, to);
- Log *log = GetLog(LLDBLog::Expressions);
-
if (llvm::Error err = ImportDefinition(from)) {
LLDB_LOG_ERROR(log, std::move(err),
"[ClangASTImporter] Error during importing definition: {0}");
@@ -1158,11 +1175,7 @@ void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
to_tag->setCompleteDefinition(from_tag->isCompleteDefinition());
if (Log *log_ast = GetLog(LLDBLog::AST)) {
- std::string name_string;
- if (NamedDecl *from_named_decl = dyn_cast<clang::NamedDecl>(from)) {
- llvm::raw_string_ostream name_stream(name_string);
- from_named_decl->printName(name_stream);
- }
+ std::string name_string = getDeclName(from);
LLDB_LOG(log_ast,
"==== [ClangASTImporter][TUDecl: {0:x}] Imported "
"({1}Decl*){2:x}, named {3} (from "
>From c1e78158074549d83448733a6560fa53fa843041 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Thu, 17 Oct 2024 17:52:07 +0100
Subject: [PATCH 2/6] fixup! add quotes
---
.../Plugins/ExpressionParser/Clang/ClangASTImporter.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
index 9a0e354daff712..2fbd8e6ca688fc 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -1151,8 +1151,8 @@ void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
if (auto *D = GetAlreadyImportedOrNull(from); D && D != to)
LLDB_LOG(log,
"[ClangASTImporter] WARNING: overwriting an already imported decl "
- "'{0:x}' ('{1}') from '{2:x}' with {3:x}. Likely due to a name "
- "conflict when importing {1}.",
+ "'{0:x}' ('{1}') from '{2:x}' with '{3:x}'. Likely due to a name "
+ "conflict when importing '{1}'.",
D, getDeclName(from), from, to);
// We might have a forward declaration from a shared library that we
>From b239e11588829a5086ec4ca134cfcfecd02cf686 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 18 Oct 2024 09:43:21 +0100
Subject: [PATCH 3/6] fixup! only do lookup when logging; add braces;
WARNING->ERROR
---
.../ExpressionParser/Clang/ClangASTImporter.cpp | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
index 2fbd8e6ca688fc..be2e5e63e5730c 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -1148,12 +1148,15 @@ void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
return name_string;
};
- if (auto *D = GetAlreadyImportedOrNull(from); D && D != to)
- LLDB_LOG(log,
- "[ClangASTImporter] WARNING: overwriting an already imported decl "
- "'{0:x}' ('{1}') from '{2:x}' with '{3:x}'. Likely due to a name "
- "conflict when importing '{1}'.",
- D, getDeclName(from), from, to);
+ if (log) {
+ if (auto *D = GetAlreadyImportedOrNull(from); D && D != to) {
+ LLDB_LOG(log,
+ "[ClangASTImporter] ERROR: overwriting an already imported decl "
+ "'{0:x}' ('{1}') from '{2:x}' with '{3:x}'. Likely due to a name "
+ "conflict when importing '{1}'.",
+ D, getDeclName(from), from, to);
+ }
+ }
// We might have a forward declaration from a shared library that we
// gave external lexical storage so that Clang asks us about the full
>From 4069dbfaccacfa58241f3dc96e50d299d3c509f5 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 18 Oct 2024 09:43:59 +0100
Subject: [PATCH 4/6] fixup! clang-format
---
.../ExpressionParser/Clang/ClangASTImporter.cpp | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
index be2e5e63e5730c..52ac3c45a23624 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -1150,11 +1150,12 @@ void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
if (log) {
if (auto *D = GetAlreadyImportedOrNull(from); D && D != to) {
- LLDB_LOG(log,
- "[ClangASTImporter] ERROR: overwriting an already imported decl "
- "'{0:x}' ('{1}') from '{2:x}' with '{3:x}'. Likely due to a name "
- "conflict when importing '{1}'.",
- D, getDeclName(from), from, to);
+ LLDB_LOG(
+ log,
+ "[ClangASTImporter] ERROR: overwriting an already imported decl "
+ "'{0:x}' ('{1}') from '{2:x}' with '{3:x}'. Likely due to a name "
+ "conflict when importing '{1}'.",
+ D, getDeclName(from), from, to);
}
}
>From 7262cbe92347a8a3b229d8ce0b907521a00ca0c2 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 18 Oct 2024 09:48:29 +0100
Subject: [PATCH 5/6] fixup! remove redundant local
---
.../source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
index 52ac3c45a23624..476f2106406f4e 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -1179,13 +1179,12 @@ void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
to_tag->setCompleteDefinition(from_tag->isCompleteDefinition());
if (Log *log_ast = GetLog(LLDBLog::AST)) {
- std::string name_string = getDeclName(from);
LLDB_LOG(log_ast,
"==== [ClangASTImporter][TUDecl: {0:x}] Imported "
"({1}Decl*){2:x}, named {3} (from "
"(Decl*){4:x})",
static_cast<void *>(to->getTranslationUnitDecl()),
- from->getDeclKindName(), static_cast<void *>(to), name_string,
+ from->getDeclKindName(), static_cast<void *>(to), getDeclName(from),
static_cast<void *>(from));
// Log the AST of the TU.
>From 3bd2f8cc2c932c821de72c6a4c10ee6afb32c2e1 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 18 Oct 2024 09:48:43 +0100
Subject: [PATCH 6/6] fixup! clang-format
---
.../Plugins/ExpressionParser/Clang/ClangASTImporter.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
index 476f2106406f4e..db9a6dd197b3a6 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -1184,8 +1184,8 @@ void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
"({1}Decl*){2:x}, named {3} (from "
"(Decl*){4:x})",
static_cast<void *>(to->getTranslationUnitDecl()),
- from->getDeclKindName(), static_cast<void *>(to), getDeclName(from),
- static_cast<void *>(from));
+ from->getDeclKindName(), static_cast<void *>(to),
+ getDeclName(from), static_cast<void *>(from));
// Log the AST of the TU.
std::string ast_string;
More information about the lldb-commits
mailing list