[clang] 1b913cd - [clang][CodeGen] Strip unneeded calls to raw_string_ostream::str() (NFC)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 13 17:36:46 PDT 2024


Author: JOE1994
Date: 2024-09-13T20:33:58-04:00
New Revision: 1b913cde2a4e3cf3b180edd0477a8e85f61886ce

URL: https://github.com/llvm/llvm-project/commit/1b913cde2a4e3cf3b180edd0477a8e85f61886ce
DIFF: https://github.com/llvm/llvm-project/commit/1b913cde2a4e3cf3b180edd0477a8e85f61886ce.diff

LOG: [clang][CodeGen] Strip unneeded calls to raw_string_ostream::str() (NFC)

Try to avoid excess layer of indirection when possible.

p.s. Remove a call to raw_string_ostream::flush() which is a no-op.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGDebugInfo.cpp
    clang/lib/CodeGen/CGOpenMPRuntime.cpp
    clang/lib/CodeGen/CodeGenAction.cpp
    clang/lib/CodeGen/MacroPPCallbacks.cpp
    clang/lib/CodeGen/SanitizerMetadata.cpp
    clang/lib/CodeGen/Targets/X86.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 1cd80a4bf5e3fa..6c433cf6a85d5e 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2384,7 +2384,7 @@ CGDebugInfo::CollectTemplateParams(std::optional<TemplateArgs> OArgs,
       TA.getAsTemplate().getAsTemplateDecl()->printQualifiedName(
           OS, getPrintingPolicy());
       TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
-          TheCU, Name, nullptr, OS.str(), defaultParameter));
+          TheCU, Name, nullptr, QualName, defaultParameter));
       break;
     }
     case TemplateArgument::Pack:
@@ -5653,7 +5653,7 @@ std::string CGDebugInfo::GetName(const Decl *D, bool Qualified) const {
       std::string CanonicalOriginalName;
       llvm::raw_string_ostream OriginalOS(CanonicalOriginalName);
       ND->getNameForDiagnostic(OriginalOS, PP, Qualified);
-      assert(EncodedOriginalNameOS.str() == OriginalOS.str());
+      assert(EncodedOriginalName == CanonicalOriginalName);
 #endif
     }
   }

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 9cf597a65be043..807f9881f53f40 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -8864,7 +8864,6 @@ emitMappingInformation(CodeGenFunction &CGF, llvm::OpenMPIRBuilder &OMPBuilder,
     PrintingPolicy P(CGF.getContext().getLangOpts());
     llvm::raw_string_ostream OS(ExprName);
     MapExprs.getMapExpr()->printPretty(OS, nullptr, P);
-    OS.flush();
   } else {
     ExprName = MapExprs.getMapDecl()->getNameAsString();
   }

diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index e87226e60297c0..883333f0924ddb 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -654,7 +654,7 @@ void BackendConsumer::UnsupportedDiagHandler(
   auto DiagType = D.getSeverity() == llvm::DS_Error
                       ? diag::err_fe_backend_unsupported
                       : diag::warn_fe_backend_unsupported;
-  Diags.Report(Loc, DiagType) << MsgStream.str();
+  Diags.Report(Loc, DiagType) << Msg;
 
   if (BadDebugInfo)
     // If we were not able to translate the file:line:col information
@@ -691,9 +691,7 @@ void BackendConsumer::EmitOptimizationMessage(
   if (D.getHotness())
     MsgStream << " (hotness: " << *D.getHotness() << ")";
 
-  Diags.Report(Loc, DiagID)
-      << AddFlagValue(D.getPassName())
-      << MsgStream.str();
+  Diags.Report(Loc, DiagID) << AddFlagValue(D.getPassName()) << Msg;
 
   if (BadDebugInfo)
     // If we were not able to translate the file:line:col information

diff  --git a/clang/lib/CodeGen/MacroPPCallbacks.cpp b/clang/lib/CodeGen/MacroPPCallbacks.cpp
index c5d1e3ad5a2054..7313a938869a81 100644
--- a/clang/lib/CodeGen/MacroPPCallbacks.cpp
+++ b/clang/lib/CodeGen/MacroPPCallbacks.cpp
@@ -185,7 +185,7 @@ void MacroPPCallbacks::MacroDefined(const Token &MacroNameTok,
   writeMacroDefinition(*Id, *MD->getMacroInfo(), PP, Name, Value);
   Gen->getCGDebugInfo()->CreateMacro(getCurrentScope(),
                                      llvm::dwarf::DW_MACINFO_define, location,
-                                     Name.str(), Value.str());
+                                     NameBuffer, ValueBuffer);
 }
 
 void MacroPPCallbacks::MacroUndefined(const Token &MacroNameTok,

diff  --git a/clang/lib/CodeGen/SanitizerMetadata.cpp b/clang/lib/CodeGen/SanitizerMetadata.cpp
index 53161c316c58a4..afa104a654dab4 100644
--- a/clang/lib/CodeGen/SanitizerMetadata.cpp
+++ b/clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -94,7 +94,7 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, const VarDecl &D,
     return NoSanitizeMask;
   };
 
-  reportGlobal(GV, D.getLocation(), OS.str(), D.getType(), getNoSanitizeMask(D),
+  reportGlobal(GV, D.getLocation(), QualName, D.getType(), getNoSanitizeMask(D),
                IsDynInit);
 }
 

diff  --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp
index 7e051e475f9d08..7f73bf2a65266e 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -284,7 +284,7 @@ static void rewriteInputConstraintReferences(unsigned FirstIn,
       Pos = DigitEnd;
     }
   }
-  AsmString = std::move(OS.str());
+  AsmString = std::move(Buf);
 }
 
 /// Add output constraints for EAX:EDX because they are return registers.


        


More information about the cfe-commits mailing list