@@ -1230,6 +1230,30 @@ ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) {
1230
1230
1231
1231
void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo (
1232
1232
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
+
1233
1257
// We might have a forward declaration from a shared library that we
1234
1258
// gave external lexical storage so that Clang asks us about the full
1235
1259
// definition when it needs it. In this case the ASTImporter isn't aware
@@ -1239,8 +1263,6 @@ void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
1239
1263
// tell the ASTImporter that 'to' was imported from 'from'.
1240
1264
MapImported (from, to);
1241
1265
1242
- Log *log = GetLog (LLDBLog::Expressions);
1243
-
1244
1266
if (llvm::Error err = ImportDefinition (from)) {
1245
1267
LLDB_LOG_ERROR (log, std::move (err),
1246
1268
" [ClangASTImporter] Error during importing definition: {0}" );
@@ -1252,19 +1274,13 @@ void ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(
1252
1274
to_tag->setCompleteDefinition (from_tag->isCompleteDefinition ());
1253
1275
1254
1276
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
- }
1261
1277
LLDB_LOG (log_ast,
1262
1278
" ==== [ClangASTImporter][TUDecl: {0:x}] Imported "
1263
1279
" ({1}Decl*){2:x}, named {3} (from "
1264
1280
" (Decl*){4:x})" ,
1265
1281
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));
1268
1284
1269
1285
// Log the AST of the TU.
1270
1286
std::string ast_string;
0 commit comments