Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is expensive (I honestly don't know), you may want to put this in a if(log) block.

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
Expand All @@ -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}");
Expand All @@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might as well put this call directly into the log message (line 1184)

LLDB_LOG(log_ast,
"==== [ClangASTImporter][TUDecl: {0:x}] Imported "
"({1}Decl*){2:x}, named {3} (from "
Expand Down
Loading