From: Yaron Keren Date: Thu, 13 Aug 2015 18:12:56 +0000 (+0000) Subject: Remove and forbid raw_svector_ostream::flush() calls. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f49d6b849111267a2f0559b098f49061018ec6c4;p=clang Remove and forbid raw_svector_ostream::flush() calls. After r244870 flush() will only compare two null pointers and return, doing nothing but wasting run time. The call is not required any more as the stream and its SmallString are always in sync. Thanks to David Blaikie for reviewing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244928 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ARCMigrate/ARCMT.cpp b/lib/ARCMigrate/ARCMT.cpp index e328842185..7eb01fb93d 100644 --- a/lib/ARCMigrate/ARCMT.cpp +++ b/lib/ARCMigrate/ARCMT.cpp @@ -600,7 +600,6 @@ bool MigrationProcess::applyTransform(TransformFn trans, SmallString<512> newText; llvm::raw_svector_ostream vecOS(newText); buf.write(vecOS); - vecOS.flush(); std::unique_ptr memBuf( llvm::MemoryBuffer::getMemBufferCopy( StringRef(newText.data(), newText.size()), newFname)); diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index b61a421ce4..8271023eed 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -1982,7 +1982,6 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { SmallString<512> newText; llvm::raw_svector_ostream vecOS(newText); buf.write(vecOS); - vecOS.flush(); std::unique_ptr memBuf( llvm::MemoryBuffer::getMemBufferCopy( StringRef(newText.data(), newText.size()), file->getName())); @@ -2215,7 +2214,6 @@ static std::string applyEditsToTemp(const FileEntry *FE, SmallString<512> NewText; llvm::raw_svector_ostream OS(NewText); Buf->write(OS); - OS.flush(); SmallString<64> TempPath; int FD; diff --git a/lib/AST/ASTDiagnostic.cpp b/lib/AST/ASTDiagnostic.cpp index 5b66f58344..0544ccbef7 100644 --- a/lib/AST/ASTDiagnostic.cpp +++ b/lib/AST/ASTDiagnostic.cpp @@ -445,8 +445,6 @@ void clang::FormatASTNodeDiagnosticArgument( } - OS.flush(); - if (NeedQuotes) { Output.insert(Output.begin()+OldEnd, '\''); Output.push_back('\''); diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 89f47f980c..3327fb3ef1 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -498,7 +498,6 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { else MC->mangleName(ND, Out); - Out.flush(); if (!Buffer.empty() && Buffer.front() == '\01') return Buffer.substr(1); return Buffer.str(); @@ -660,7 +659,6 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { Out << Proto; - Out.flush(); return Name.str().str(); } if (const CapturedDecl *CD = dyn_cast(CurrentDecl)) { @@ -692,7 +690,6 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { MD->getSelector().print(Out); Out << ']'; - Out.flush(); return Name.str().str(); } if (isa(CurrentDecl) && IT == PrettyFunction) { diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp index 1fcf466a1f..1e777a51d9 100644 --- a/lib/AST/ItaniumMangle.cpp +++ b/lib/AST/ItaniumMangle.cpp @@ -2405,7 +2405,6 @@ void CXXNameMangler::mangleType(const ObjCObjectType *T) { StringRef name = I->getName(); QualOS << name.size() << name; } - QualOS.flush(); Out << 'U' << QualStr.size() << QualStr; } diff --git a/lib/AST/Mangle.cpp b/lib/AST/Mangle.cpp index 1a061c4f66..014338f049 100644 --- a/lib/AST/Mangle.cpp +++ b/lib/AST/Mangle.cpp @@ -206,7 +206,6 @@ void MangleContext::mangleCtorBlock(const CXXConstructorDecl *CD, SmallString<64> Buffer; llvm::raw_svector_ostream Out(Buffer); mangleCXXCtor(CD, CT, Out); - Out.flush(); mangleFunctionBlock(*this, Buffer, BD, ResStream); } @@ -216,7 +215,6 @@ void MangleContext::mangleDtorBlock(const CXXDestructorDecl *DD, SmallString<64> Buffer; llvm::raw_svector_ostream Out(Buffer); mangleCXXDtor(DD, DT, Out); - Out.flush(); mangleFunctionBlock(*this, Buffer, BD, ResStream); } @@ -253,7 +251,6 @@ void MangleContext::mangleBlock(const DeclContext *DC, const BlockDecl *BD, } } } - Stream.flush(); mangleFunctionBlock(*this, Buffer, BD, Out); } diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index a5f75ec0b1..1be02f5e23 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -721,7 +721,6 @@ void MicrosoftCXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, llvm::raw_svector_ostream Stream(TemplateMangling); MicrosoftCXXNameMangler Extra(Context, Stream); Extra.mangleTemplateInstantiationName(TD, *TemplateArgs); - Stream.flush(); mangleSourceName(TemplateMangling); return; diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index ac31722899..eaa1e250eb 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -613,7 +613,6 @@ static SmallString<256> getUniqueTagTypeName(const TagType *Ty, // a unique string for a type? llvm::raw_svector_ostream Out(FullName); CGM.getCXXABI().getMangleContext().mangleCXXRTTIName(QualType(Ty, 0), Out); - Out.flush(); return FullName; } diff --git a/lib/CodeGen/CGVTT.cpp b/lib/CodeGen/CGVTT.cpp index e3df5a4c05..4fb76710d2 100644 --- a/lib/CodeGen/CGVTT.cpp +++ b/lib/CodeGen/CGVTT.cpp @@ -108,7 +108,6 @@ llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTT(const CXXRecordDecl *RD) { llvm::raw_svector_ostream Out(OutName); cast(CGM.getCXXABI().getMangleContext()) .mangleCXXVTT(RD, Out); - Out.flush(); StringRef Name = OutName.str(); // This will also defer the definition of the VTT. diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index 83f45b5da2..fcb5c36649 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -44,7 +44,6 @@ llvm::Constant *CodeGenModule::GetAddrOfThunk(GlobalDecl GD, Thunk.This, Out); else getCXXABI().getMangleContext().mangleThunk(MD, Thunk, Out); - Out.flush(); llvm::Type *Ty = getTypes().GetFunctionTypeForVTable(GD); return GetOrCreateLLVMFunction(Name, Ty, GD, /*ForVTable=*/true, @@ -644,7 +643,6 @@ CodeGenVTables::GenerateConstructionVTable(const CXXRecordDecl *RD, cast(CGM.getCXXABI().getMangleContext()) .mangleCXXCtorVTable(RD, Base.getBaseOffset().getQuantity(), Base.getBase(), Out); - Out.flush(); StringRef Name = OutName.str(); llvm::ArrayType *ArrayType = diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index fe1f9bae78..5ce25a29d4 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -2953,7 +2953,6 @@ CodeGenModule::GetAddrOfConstantStringFromLiteral(const StringLiteral *S, getCXXABI().getMangleContext().shouldMangleStringLiteral(S)) { llvm::raw_svector_ostream Out(MangledNameBuffer); getCXXABI().getMangleContext().mangleStringLiteral(S, Out); - Out.flush(); LT = llvm::GlobalValue::LinkOnceODRLinkage; GlobalVariableName = MangledNameBuffer; @@ -3041,7 +3040,6 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalTemporary( llvm::raw_svector_ostream Out(Name); getCXXABI().getMangleContext().mangleReferenceTemporary( VD, E->getManglingNumber(), Out); - Out.flush(); APValue *Value = nullptr; if (E->getStorageDuration() == SD_Static) { diff --git a/lib/CodeGen/CodeGenTBAA.cpp b/lib/CodeGen/CodeGenTBAA.cpp index 53ba02a813..c3c925cde2 100644 --- a/lib/CodeGen/CodeGenTBAA.cpp +++ b/lib/CodeGen/CodeGenTBAA.cpp @@ -155,7 +155,6 @@ CodeGenTBAA::getTBAAInfo(QualType QTy) { SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); MContext.mangleTypeName(QualType(ETy, 0), Out); - Out.flush(); return MetadataCache[Ty] = createTBAAScalarType(OutName, getChar()); } @@ -271,7 +270,6 @@ CodeGenTBAA::getTBAAStructTypeInfo(QualType QTy) { // Don't use the mangler for C code. llvm::raw_svector_ostream Out(OutName); MContext.mangleTypeName(QualType(Ty, 0), Out); - Out.flush(); } else { OutName = RD->getName(); } diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp index 115bf19d97..3948b2447e 100644 --- a/lib/CodeGen/ItaniumCXXABI.cpp +++ b/lib/CodeGen/ItaniumCXXABI.cpp @@ -1439,7 +1439,6 @@ llvm::GlobalVariable *ItaniumCXXABI::getAddrOfVTable(const CXXRecordDecl *RD, SmallString<256> Name; llvm::raw_svector_ostream Out(Name); getMangleContext().mangleCXXVTable(RD, Out); - Out.flush(); ItaniumVTableContext &VTContext = CGM.getItaniumVTableContext(); llvm::ArrayType *ArrayType = llvm::ArrayType::get( @@ -1814,7 +1813,6 @@ void ItaniumCXXABI::EmitGuardedInit(CodeGenFunction &CGF, { llvm::raw_svector_ostream out(guardName); getMangleContext().mangleStaticGuardVariable(&D, out); - out.flush(); } // Create the guard variable with a zero-initializer. @@ -2038,7 +2036,6 @@ ItaniumCXXABI::getOrCreateThreadLocalWrapper(const VarDecl *VD, { llvm::raw_svector_ostream Out(WrapperName); getMangleContext().mangleItaniumThreadLocalWrapper(VD, Out); - Out.flush(); } if (llvm::Value *V = CGM.getModule().getNamedValue(WrapperName)) @@ -2094,7 +2091,6 @@ void ItaniumCXXABI::EmitThreadLocalInitFuncs( { llvm::raw_svector_ostream Out(InitFnName); getMangleContext().mangleItaniumThreadLocalInit(VD, Out); - Out.flush(); } // If we have a definition for the variable, emit the initialization @@ -2290,7 +2286,6 @@ llvm::GlobalVariable *ItaniumRTTIBuilder::GetAddrOfTypeName( SmallString<256> Name; llvm::raw_svector_ostream Out(Name); CGM.getCXXABI().getMangleContext().mangleCXXRTTIName(Ty, Out); - Out.flush(); // We know that the mangled name of the type starts at index 4 of the // mangled name of the typename, so we can just index into it in order to @@ -2312,7 +2307,6 @@ ItaniumRTTIBuilder::GetAddrOfExternalRTTIDescriptor(QualType Ty) { SmallString<256> Name; llvm::raw_svector_ostream Out(Name); CGM.getCXXABI().getMangleContext().mangleCXXRTTI(Ty, Out); - Out.flush(); // Look for an existing global. llvm::GlobalVariable *GV = CGM.getModule().getNamedGlobal(Name); @@ -2711,7 +2705,6 @@ llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(QualType Ty, bool Force) { SmallString<256> Name; llvm::raw_svector_ostream Out(Name); CGM.getCXXABI().getMangleContext().mangleCXXRTTI(Ty, Out); - Out.flush(); llvm::GlobalVariable *OldGV = CGM.getModule().getNamedGlobal(Name); if (OldGV && !OldGV->isDeclaration()) { diff --git a/lib/CodeGen/MicrosoftCXXABI.cpp b/lib/CodeGen/MicrosoftCXXABI.cpp index 3084446795..e62bbae466 100644 --- a/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/lib/CodeGen/MicrosoftCXXABI.cpp @@ -257,7 +257,6 @@ public: SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); getMangleContext().mangleCXXVirtualDisplacementMap(SrcRD, DstRD, Out); - Out.flush(); StringRef MangledName = OutName.str(); if (auto *VDispMap = CGM.getModule().getNamedGlobal(MangledName)) @@ -1854,7 +1853,6 @@ llvm::Function *MicrosoftCXXABI::EmitVirtualMemPtrThunk( SmallString<256> ThunkName; llvm::raw_svector_ostream Out(ThunkName); getMangleContext().mangleVirtualMemPtrThunk(MD, Out); - Out.flush(); // If the thunk has been generated previously, just return it. if (llvm::GlobalValue *GV = CGM.getModule().getNamedValue(ThunkName)) @@ -1930,7 +1928,6 @@ MicrosoftCXXABI::getAddrOfVBTable(const VPtrInfo &VBT, const CXXRecordDecl *RD, SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); getMangleContext().mangleCXXVBTable(RD, VBT.MangledPath, Out); - Out.flush(); StringRef Name = OutName.str(); llvm::ArrayType *VBTableType = @@ -2342,7 +2339,6 @@ void MicrosoftCXXABI::EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D, Out); else getMangleContext().mangleStaticGuardVariable(&D, Out); - Out.flush(); } // Create the guard variable with a zero-initializer. Just absorb linkage, @@ -3747,7 +3743,6 @@ MicrosoftCXXABI::getAddrOfCXXCtorClosure(const CXXConstructorDecl *CD, SmallString<256> ThunkName; llvm::raw_svector_ostream Out(ThunkName); getMangleContext().mangleCXXCtor(CD, CT, Out); - Out.flush(); // If the thunk has been generated previously, just return it. if (llvm::GlobalValue *GV = CGM.getModule().getNamedValue(ThunkName)) diff --git a/lib/CodeGen/ObjectFilePCHContainerOperations.cpp b/lib/CodeGen/ObjectFilePCHContainerOperations.cpp index d0e857be3c..526c0c71de 100644 --- a/lib/CodeGen/ObjectFilePCHContainerOperations.cpp +++ b/lib/CodeGen/ObjectFilePCHContainerOperations.cpp @@ -139,7 +139,6 @@ public: clang::EmitBackendOutput(Diags, CodeGenOpts, TargetOpts, LangOpts, Ctx.getTargetInfo().getDataLayoutString(), M.get(), BackendAction::Backend_EmitLL, &OS); - OS.flush(); llvm::dbgs() << Buffer; }); diff --git a/lib/Index/CommentToXML.cpp b/lib/Index/CommentToXML.cpp index ef6aeefa65..d5c225ecad 100644 --- a/lib/Index/CommentToXML.cpp +++ b/lib/Index/CommentToXML.cpp @@ -481,7 +481,6 @@ void CommentASTToHTMLConverter::visitFullComment(const FullComment *C) { Result << ""; } - Result.flush(); } void CommentASTToHTMLConverter::visitNonStandaloneParagraphComment( @@ -1078,8 +1077,6 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) { } Result << RootEndTag; - - Result.flush(); } void CommentASTToXMLConverter::appendToResultWithXMLEscaping(StringRef S) { diff --git a/lib/Index/USRGeneration.cpp b/lib/Index/USRGeneration.cpp index 8cdd283ba5..cc98a719a6 100644 --- a/lib/Index/USRGeneration.cpp +++ b/lib/Index/USRGeneration.cpp @@ -156,10 +156,8 @@ public: //===----------------------------------------------------------------------===// bool USRGenerator::EmitDeclName(const NamedDecl *D) { - Out.flush(); const unsigned startSize = Buf.size(); D->printName(Out); - Out.flush(); const unsigned endSize = Buf.size(); return startSize == endSize; } @@ -462,7 +460,6 @@ void USRGenerator::VisitTagDecl(const TagDecl *D) { } Out << '@'; - Out.flush(); assert(Buf.size() > 0); const unsigned off = Buf.size() - 1; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index e25b160806..7c54986f56 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -11461,7 +11461,6 @@ static FixItHint createFriendTagNNSFixIt(Sema &SemaRef, NamedDecl *ND, Scope *S, std::reverse(Namespaces.begin(), Namespaces.end()); for (auto *II : Namespaces) OS << II->getName() << "::"; - OS.flush(); return FixItHint::CreateInsertion(NameLoc, Insertion); } diff --git a/lib/Sema/SemaExceptionSpec.cpp b/lib/Sema/SemaExceptionSpec.cpp index ec3d9fd82f..7d03ac4b24 100644 --- a/lib/Sema/SemaExceptionSpec.cpp +++ b/lib/Sema/SemaExceptionSpec.cpp @@ -318,7 +318,6 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) { default: llvm_unreachable("This spec type is compatible with none."); } - OS.flush(); SourceLocation FixItLoc; if (TypeSourceInfo *TSInfo = New->getTypeSourceInfo()) { diff --git a/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp b/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp index 2ba7ea4a4e..3f27c3954f 100644 --- a/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp @@ -159,7 +159,6 @@ void DereferenceChecker::reportBug(ProgramStateRef State, const Stmt *S, break; } - os.flush(); auto report = llvm::make_unique( *BT_null, buf.empty() ? BT_null->getDescription() : StringRef(buf), N); diff --git a/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp b/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp index 4e3f9b73ac..db4fbca36d 100644 --- a/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp @@ -276,7 +276,6 @@ void ASTFieldVisitor::ReportError(QualType T) { } } os << " (type " << FieldChain.back()->getType().getAsString() << ")"; - os.flush(); // Note that this will fire for every translation unit that uses this // class. This is suboptimal, but at least scan-build will merge diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 1fb62d259c..46125e3a52 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -7364,8 +7364,6 @@ Logger &cxindex::Logger::operator<<(const llvm::format_object_base &Fmt) { static llvm::ManagedStatic LoggingMutex; cxindex::Logger::~Logger() { - LogOS.flush(); - llvm::sys::ScopedLock L(*LoggingMutex); static llvm::TimeRecord sBeginTR = llvm::TimeRecord::getCurrentTime();