diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp index b23fcb041aa08..e022771ebe203 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp @@ -1230,6 +1230,30 @@ 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(decl)) { + llvm::raw_string_ostream name_stream(name_string); + from_named_decl->printName(name_stream); + name_stream.flush(); + } + + return name_string; + }; + + 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 // definition when it needs it. In this case the ASTImporter isn't aware @@ -1239,8 +1263,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}"); @@ -1252,19 +1274,13 @@ 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(from)) { - llvm::raw_string_ostream name_stream(name_string); - from_named_decl->printName(name_stream); - name_stream.flush(); - } LLDB_LOG(log_ast, "==== [ClangASTImporter][TUDecl: {0:x}] Imported " "({1}Decl*){2:x}, named {3} (from " "(Decl*){4:x})", static_cast(to->getTranslationUnitDecl()), - from->getDeclKindName(), static_cast(to), name_string, - static_cast(from)); + from->getDeclKindName(), static_cast(to), + getDeclName(from), static_cast(from)); // Log the AST of the TU. std::string ast_string;