From dd21dbfae1f4208225b424693a64b7c26a938ca7 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Thu, 19 Nov 2026 17:31:34 +0000 Subject: [PATCH] Skip AST dumps when verbose logging is disabled Signed-off-by: Perfloop Agent --- cpp2rust/converter/converter.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index b45d5a46ff..ecc8dc0a27 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -412,6 +412,12 @@ bool Converter::VisitTranslationUnitDecl(clang::TranslationUnitDecl *decl) { return false; } +static void DumpVerbose(const clang::Decl *decl) { + if (auto &out = log(); &out != &llvm::nulls()) { + decl->dump(out); + } +} + bool Converter::VisitFunctionDecl(clang::FunctionDecl *decl) { if (auto method = clang::dyn_cast(decl)) { return VisitCXXMethodDecl(method); @@ -422,7 +428,7 @@ bool Converter::VisitFunctionDecl(clang::FunctionDecl *decl) { if (!IsInMainFile(decl) && !decl_ids_.insert(GetID(decl)).second) { return false; } - decl->dump(log()); + DumpVerbose(decl); ScopedValue push_fn(curr_function_, decl); std::string function_name; if (decl->isMain()) { @@ -872,7 +878,7 @@ bool Converter::RecordHasCopyableFields(const clang::RecordDecl *decl) { } bool Converter::VisitRecordDecl(clang::RecordDecl *decl) { - decl->dump(log()); + DumpVerbose(decl); // VisitCXXRecordDecl already visited the record if (clang::isa(decl)) { @@ -1105,7 +1111,7 @@ void Converter::EmitRustUnion(clang::RecordDecl *decl) { } bool Converter::VisitCXXRecordDecl(clang::CXXRecordDecl *decl) { - decl->dump(log()); + DumpVerbose(decl); if (!IsConvertibleCXXRecordDecl(decl)) { return false; @@ -1148,7 +1154,7 @@ bool Converter::VisitCXXRecordDecl(clang::CXXRecordDecl *decl) { } bool Converter::VisitCXXMethodDecl(clang::CXXMethodDecl *decl) { - decl->dump(log()); + DumpVerbose(decl); if (!ShouldConvertMethod(decl)) { return false; }