@@ -1230,6 +1230,30 @@ ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) {
12301230
12311231void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo (
12321232 clang::Decl *to, clang::Decl *from) {
1233+ Log *log = GetLog (LLDBLog::Expressions);
1234+
1235+ auto getDeclName = [](Decl const *decl) {
1236+ std::string name_string;
1237+ if (auto const *from_named_decl = dyn_cast<clang::NamedDecl>(decl)) {
1238+ llvm::raw_string_ostream name_stream (name_string);
1239+ from_named_decl->printName (name_stream);
1240+ name_stream.flush ();
1241+ }
1242+
1243+ return name_string;
1244+ };
1245+
1246+ if (log) {
1247+ if (auto *D = GetAlreadyImportedOrNull (from); D && D != to) {
1248+ LLDB_LOG (
1249+ log,
1250+ " [ClangASTImporter] ERROR: overwriting an already imported decl "
1251+ " '{0:x}' ('{1}') from '{2:x}' with '{3:x}'. Likely due to a name "
1252+ " conflict when importing '{1}'." ,
1253+ D, getDeclName (from), from, to);
1254+ }
1255+ }
1256+
12331257 // We might have a forward declaration from a shared library that we
12341258 // gave external lexical storage so that Clang asks us about the full
12351259 // definition when it needs it. In this case the ASTImporter isn't aware
@@ -1239,8 +1263,6 @@ void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
12391263 // tell the ASTImporter that 'to' was imported from 'from'.
12401264 MapImported (from, to);
12411265
1242- Log *log = GetLog (LLDBLog::Expressions);
1243-
12441266 if (llvm::Error err = ImportDefinition (from)) {
12451267 LLDB_LOG_ERROR (log, std::move (err),
12461268 " [ClangASTImporter] Error during importing definition: {0}" );
@@ -1252,19 +1274,13 @@ void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
12521274 to_tag->setCompleteDefinition (from_tag->isCompleteDefinition ());
12531275
12541276 if (Log *log_ast = GetLog (LLDBLog::AST)) {
1255- std::string name_string;
1256- if (NamedDecl *from_named_decl = dyn_cast<clang::NamedDecl>(from)) {
1257- llvm::raw_string_ostream name_stream (name_string);
1258- from_named_decl->printName (name_stream);
1259- name_stream.flush ();
1260- }
12611277 LLDB_LOG (log_ast,
12621278 " ==== [ClangASTImporter][TUDecl: {0:x}] Imported "
12631279 " ({1}Decl*){2:x}, named {3} (from "
12641280 " (Decl*){4:x})" ,
12651281 static_cast <void *>(to->getTranslationUnitDecl ()),
1266- from->getDeclKindName (), static_cast <void *>(to), name_string,
1267- static_cast <void *>(from));
1282+ from->getDeclKindName (), static_cast <void *>(to),
1283+ getDeclName (from), static_cast <void *>(from));
12681284
12691285 // Log the AST of the TU.
12701286 std::string ast_string;
0 commit comments