Author: David Blaikie Date: 2021-07-08T13:37:57-07:00 New Revision: 1def2579e10dd84405465f403e8c31acebff0c97
URL: https://github.com/llvm/llvm-project/commit/1def2579e10dd84405465f403e8c31acebff0c97 DIFF: https://github.com/llvm/llvm-project/commit/1def2579e10dd84405465f403e8c31acebff0c97.diff LOG: PR51018: Remove explicit conversions from SmallString to StringRef to future-proof against C++23 C++23 will make these conversions ambiguous - so fix them to make the codebase forward-compatible with C++23 (& a follow-up change I've made will make this ambiguous/invalid even in <C++23 so we don't regress this & it generally improves the code anyway) Added: Modified: clang-tools-extra/clang-doc/HTMLGenerator.cpp clang-tools-extra/clangd/JSONTransport.cpp clang-tools-extra/clangd/QueryDriverDatabase.cpp clang-tools-extra/clangd/Selection.cpp clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h clang/lib/AST/MicrosoftMangle.cpp clang/lib/Analysis/MacroExpansionContext.cpp clang/lib/Basic/FileManager.cpp clang/lib/CodeGen/MicrosoftCXXABI.cpp clang/lib/CrossTU/CrossTranslationUnit.cpp clang/lib/Driver/ToolChains/AMDGPU.cpp clang/lib/Lex/HeaderSearch.cpp clang/lib/Lex/PPDirectives.cpp clang/lib/Sema/SemaStmt.cpp clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp clang/tools/clang-scan-deps/ClangScanDeps.cpp clang/unittests/Frontend/FrontendActionTest.cpp lld/COFF/PDB.cpp lldb/source/Commands/CommandCompletions.cpp llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp llvm/lib/IR/ValueSymbolTable.cpp llvm/lib/LTO/LTOModule.cpp llvm/lib/MC/MCContext.cpp llvm/lib/Object/IRSymtab.cpp llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp llvm/lib/Support/CommandLine.cpp llvm/lib/Support/Signals.cpp llvm/lib/Support/VirtualFileSystem.cpp llvm/lib/Transforms/Scalar/MergeICmps.cpp llvm/lib/Transforms/Utils/MemoryOpRemark.cpp llvm/tools/llvm-exegesis/lib/Analysis.cpp llvm/tools/llvm-readobj/COFFDumper.cpp llvm/unittests/Bitstream/BitstreamWriterTest.cpp llvm/unittests/DebugInfo/DWARF/DWARFDieManualExtractTest.cpp llvm/unittests/Support/CommandLineTest.cpp llvm/unittests/Support/LockFileManagerTest.cpp mlir/lib/IR/AsmPrinter.cpp mlir/lib/Tools/mlir-lsp-server/lsp/Transport.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index 49ff36a02be7..e110f312d10c 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -579,8 +579,8 @@ genHTML(const Index &Index, StringRef InfoPath, bool IsOutermostList) { if (!Index.JumpToSection) SpanBody->Children.emplace_back(genReference(Index, InfoPath)); else - SpanBody->Children.emplace_back(genReference( - Index, InfoPath, StringRef{Index.JumpToSection.getValue()})); + SpanBody->Children.emplace_back( + genReference(Index, InfoPath, Index.JumpToSection.getValue().str())); } if (Index.Children.empty()) return Out; diff --git a/clang-tools-extra/clangd/JSONTransport.cpp b/clang-tools-extra/clangd/JSONTransport.cpp index 3e8caceda21c..49cd4e0903e3 100644 --- a/clang-tools-extra/clangd/JSONTransport.cpp +++ b/clang-tools-extra/clangd/JSONTransport.cpp @@ -230,7 +230,7 @@ bool JSONTransport::readStandardMessage(std::string &JSON) { return false; InMirror << Line; - llvm::StringRef LineRef(Line); + llvm::StringRef LineRef = Line; // We allow comments in headers. Technically this isn't part @@ -298,7 +298,7 @@ bool JSONTransport::readDelimitedMessage(std::string &JSON) { llvm::SmallString<128> Line; while (readLine(In, Line)) { InMirror << Line; - auto LineRef = llvm::StringRef(Line).trim(); + auto LineRef = Line.str().trim(); if (LineRef.startswith("#")) // comment continue; diff --git a/clang-tools-extra/clangd/QueryDriverDatabase.cpp b/clang-tools-extra/clangd/QueryDriverDatabase.cpp index 9704cb8e480f..5e51837b4820 100644 --- a/clang-tools-extra/clangd/QueryDriverDatabase.cpp +++ b/clang-tools-extra/clangd/QueryDriverDatabase.cpp @@ -175,8 +175,7 @@ extractSystemIncludesAndTarget(llvm::SmallString<128> Driver, auto CleanUp = llvm::make_scope_exit( [&StdErrPath]() { llvm::sys::fs::remove(StdErrPath); }); - llvm::Optional<llvm::StringRef> Redirects[] = { - {""}, {""}, llvm::StringRef(StdErrPath)}; + llvm::Optional<llvm::StringRef> Redirects[] = {{""}, {""}, StdErrPath.str()}; llvm::SmallVector<llvm::StringRef> Args = {Driver, "-E", "-x", Lang, "-", "-v"}; diff --git a/clang-tools-extra/clangd/Selection.cpp b/clang-tools-extra/clangd/Selection.cpp index ad41dec9f20f..b4f767fde095 100644 --- a/clang-tools-extra/clangd/Selection.cpp +++ b/clang-tools-extra/clangd/Selection.cpp @@ -771,8 +771,7 @@ llvm::SmallString<256> abbreviatedString(DynTypedNode N, } auto Pos = Result.find('\n'); if (Pos != llvm::StringRef::npos) { - bool MoreText = - !llvm::all_of(llvm::StringRef(Result).drop_front(Pos), llvm::isSpace); + bool MoreText = !llvm::all_of(Result.str().drop_front(Pos), llvm::isSpace); Result.resize(Pos); if (MoreText) Result.append(" …"); diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h index 7d0881343478..82dc0b8fdb57 100644 --- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h +++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h @@ -65,7 +65,7 @@ class CachedFileSystemEntry { return MaybeStat.getError(); assert(!MaybeStat->isDirectory() && "not a file"); assert(isValid() && "not initialized"); - return StringRef(Contents); + return Contents.str(); } /// \returns The error or the status of the entry. diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp index d3ce9aaced7c..3176077804fc 100644 --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -3676,7 +3676,7 @@ void MicrosoftMangleContextImpl::mangleCXXRTTICompleteObjectLocator( assert(VFTableMangling.startswith("??_7") || VFTableMangling.startswith("??_S")); - Out << "??_R4" << StringRef(VFTableMangling).drop_front(4); + Out << "??_R4" << VFTableMangling.str().drop_front(4); } void MicrosoftMangleContextImpl::mangleSEHFilterExpression( diff --git a/clang/lib/Analysis/MacroExpansionContext.cpp b/clang/lib/Analysis/MacroExpansionContext.cpp index f261ba8d5389..290510691891 100644 --- a/clang/lib/Analysis/MacroExpansionContext.cpp +++ b/clang/lib/Analysis/MacroExpansionContext.cpp @@ -111,7 +111,7 @@ MacroExpansionContext::getExpandedText(SourceLocation MacroExpansionLoc) const { return StringRef{""}; // Otherwise we have the actual token sequence as string. - return StringRef{It->getSecond()}; + return It->getSecond().str(); } Optional<StringRef> diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index df306bd83136..74cd2f295be6 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -611,7 +611,7 @@ StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) { SmallString<4096> CanonicalNameBuf; if (!FS->getRealPath(Dir->getName(), CanonicalNameBuf)) - CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage); + CanonicalName = CanonicalNameBuf.str().copy(CanonicalNameStorage); CanonicalNames.insert({Dir, CanonicalName}); return CanonicalName; @@ -627,7 +627,7 @@ StringRef FileManager::getCanonicalName(const FileEntry *File) { SmallString<4096> CanonicalNameBuf; if (!FS->getRealPath(File->getName(), CanonicalNameBuf)) - CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage); + CanonicalName = CanonicalNameBuf.str().copy(CanonicalNameStorage); CanonicalNames.insert({File, CanonicalName}); return CanonicalName; diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp index 6bbf07786742..68f2828febe2 100644 --- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -4338,7 +4338,7 @@ llvm::GlobalVariable *MicrosoftCXXABI::getThrowInfo(QualType T) { }; auto *GV = new llvm::GlobalVariable( CGM.getModule(), TIType, /*isConstant=*/true, getLinkageForRTTI(T), - llvm::ConstantStruct::get(TIType, Fields), StringRef(MangledName)); + llvm::ConstantStruct::get(TIType, Fields), MangledName.str()); GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); GV->setSection(".xdata"); if (GV->isWeakForLinker()) diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp index adee55304c87..0aecad491ecc 100644 --- a/clang/lib/CrossTU/CrossTranslationUnit.cpp +++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp @@ -634,7 +634,7 @@ parseInvocationList(StringRef FileContent, llvm::sys::path::Style PathStyle) { SmallString<32> NativeSourcePath(SourcePath); llvm::sys::path::native(NativeSourcePath, PathStyle); - StringRef InvocationKey(NativeSourcePath); + StringRef InvocationKey = NativeSourcePath; if (InvocationList.find(InvocationKey) != InvocationList.end()) return llvm::make_error<IndexError>( diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp index 2e92be51f69e..0a1da2879ee1 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -748,7 +748,7 @@ AMDGPUToolChain::detectSystemGPUs(const ArgList &Args, llvm::FileRemover OutputRemover(OutputFile.c_str()); llvm::Optional<llvm::StringRef> Redirects[] = { {""}, - StringRef(OutputFile), + OutputFile.str(), {""}, }; diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 9970c3c99a27..d5adbcf62cbc 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -727,7 +727,7 @@ diagnoseFrameworkInclude(DiagnosticsEngine &Diags, SourceLocation IncludeLoc, if (!isAngled && !FoundByHeaderMap) { SmallString<128> NewInclude("<"); if (IsIncludeeInFramework) { - NewInclude += StringRef(ToFramework).drop_back(10); // drop .framework + NewInclude += ToFramework.str().drop_back(10); // drop .framework NewInclude += "/"; } NewInclude += IncludeFilename; diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index d0e4962a3747..556dd8daf652 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -1480,7 +1480,7 @@ void Preprocessor::HandleUserDiagnosticDirective(Token &Tok, // Find the first non-whitespace character, so that we can make the // diagnostic more succinct. - StringRef Msg = StringRef(Message).ltrim(' '); + StringRef Msg = Message.str().ltrim(' '); if (isWarning) Diag(Tok, diag::pp_hash_warning) << Msg; diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 59e64c4b1c5b..fa798c2d557c 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -1332,12 +1332,12 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, if (PrevString == CurrString) Diag(CaseVals[i].second->getLHS()->getBeginLoc(), diag::err_duplicate_case) - << (PrevString.empty() ? StringRef(CaseValStr) : PrevString); + << (PrevString.empty() ? CaseValStr.str() : PrevString); else Diag(CaseVals[i].second->getLHS()->getBeginLoc(), diag::err_duplicate_case_ diff ering_expr) - << (PrevString.empty() ? StringRef(CaseValStr) : PrevString) - << (CurrString.empty() ? StringRef(CaseValStr) : CurrString) + << (PrevString.empty() ? CaseValStr.str() : PrevString) + << (CurrString.empty() ? CaseValStr.str() : CurrString) << CaseValStr; Diag(CaseVals[i - 1].second->getLHS()->getBeginLoc(), diff --git a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp index adfc2f8cb8fe..4a9c7ce3c66d 100644 --- a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp @@ -193,7 +193,7 @@ void DereferenceChecker::reportBug(DerefKind K, ProgramStateRef State, } auto report = std::make_unique<PathSensitiveBugReport>( - *BT, buf.empty() ? BT->getDescription() : StringRef(buf), N); + *BT, buf.empty() ? BT->getDescription() : buf.str(), N); bugreporter::trackExpressionValue(N, bugreporter::getDerefExpr(S), *report); diff --git a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp index a0e52b193152..43f7091c97f3 100644 --- a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp +++ b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp @@ -499,7 +499,7 @@ class TempFileHandlerRAII { return createFileError(File, EC); OS.write(Contents->data(), Contents->size()); } - return Files.front(); + return Files.front().str(); } private: diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp index b6533361c529..74784ebd3b9c 100644 --- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp @@ -83,8 +83,8 @@ class ResourceDirectoryCache { llvm::FileRemover ErrorRemover(ErrorFile.c_str()); llvm::Optional<StringRef> Redirects[] = { {""}, // Stdin - StringRef(OutputFile), - StringRef(ErrorFile), + OutputFile.str(), + ErrorFile.str(), }; if (const int RC = llvm::sys::ExecuteAndWait( ClangBinaryPath, PrintResourceDirArgs, {}, Redirects)) { diff --git a/clang/unittests/Frontend/FrontendActionTest.cpp b/clang/unittests/Frontend/FrontendActionTest.cpp index bdc0af40adc2..8de687d28e72 100644 --- a/clang/unittests/Frontend/FrontendActionTest.cpp +++ b/clang/unittests/Frontend/FrontendActionTest.cpp @@ -272,8 +272,7 @@ TEST(GeneratePCHFrontendAction, CacheGeneratedPCH) { MemoryBuffer::getMemBuffer("int foo(void) { return 1; }\n").release()); Invocation->getFrontendOpts().Inputs.push_back( FrontendInputFile("test.h", Language::C)); - Invocation->getFrontendOpts().OutputFile = - std::string(StringRef(PCHFilename)); + Invocation->getFrontendOpts().OutputFile = PCHFilename.str().str(); Invocation->getFrontendOpts().ProgramAction = frontend::GeneratePCH; Invocation->getTargetOpts().Triple = "x86_64-apple-darwin19.0.0"; CompilerInstance Compiler; diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp index cb8b27b6f485..e355857dd93d 100644 --- a/lld/COFF/PDB.cpp +++ b/lld/COFF/PDB.cpp @@ -1068,7 +1068,7 @@ void PDBLinker::createModuleDBI(ObjFile *file) { bool inArchive = !file->parentName.empty(); objName = inArchive ? file->parentName : file->getName(); pdbMakeAbsolute(objName); - StringRef modName = inArchive ? file->getName() : StringRef(objName); + StringRef modName = inArchive ? file->getName() : objName.str(); file->moduleDBI = &exitOnErr(dbiBuilder.addModuleInfo(modName)); file->moduleDBI->setObjFileName(objName); diff --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp index 0ea6d4288169..857b2a05b91c 100644 --- a/lldb/source/Commands/CommandCompletions.cpp +++ b/lldb/source/Commands/CommandCompletions.cpp @@ -331,7 +331,7 @@ static void DiskFilesOrDirectories(const llvm::Twine &partial_name, llvm::StringRef PartialItem; if (CompletionBuffer.startswith("~")) { - llvm::StringRef Buffer(CompletionBuffer); + llvm::StringRef Buffer = CompletionBuffer; size_t FirstSep = Buffer.find_if([](char c) { return path::is_separator(c); }); diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index f04cbb07403b..a1507a349d43 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1684,7 +1684,7 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) { std::string Buf; raw_string_ostream OS(Buf); std::unique_ptr<remarks::MetaSerializer> MetaSerializer = - Filename ? RemarkSerializer.metaSerializer(OS, StringRef(*Filename)) + Filename ? RemarkSerializer.metaSerializer(OS, Filename->str()) : RemarkSerializer.metaSerializer(OS); MetaSerializer->emit(); diff --git a/llvm/lib/IR/ValueSymbolTable.cpp b/llvm/lib/IR/ValueSymbolTable.cpp index 6e5330ecc5f8..cf85a571f9a0 100644 --- a/llvm/lib/IR/ValueSymbolTable.cpp +++ b/llvm/lib/IR/ValueSymbolTable.cpp @@ -61,7 +61,7 @@ ValueName *ValueSymbolTable::makeUniqueName(Value *V, S << ++LastUnique; // Try insert the vmap entry with this suffix. - auto IterBool = vmap.insert(std::make_pair(UniqueName, V)); + auto IterBool = vmap.insert(std::make_pair(UniqueName.str(), V)); if (IterBool.second) return &*IterBool.first; } diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp index 1119622578df..155790041a75 100644 --- a/llvm/lib/LTO/LTOModule.cpp +++ b/llvm/lib/LTO/LTOModule.cpp @@ -545,7 +545,8 @@ void LTOModule::addPotentialUndefinedSymbol(ModuleSymbolTable::Symbol Sym, name.c_str(); } - auto IterBool = _undefines.insert(std::make_pair(name, NameAndAttributes())); + auto IterBool = + _undefines.insert(std::make_pair(name.str(), NameAndAttributes())); // we already have the symbol if (!IterBool.second) @@ -582,7 +583,7 @@ void LTOModule::parseSymbols() { SymTab.printSymbolName(OS, Sym); Buffer.c_str(); } - StringRef Name(Buffer); + StringRef Name = Buffer; if (IsUndefined) addAsmGlobalSymbolUndef(Name); diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index 906588a1a169..af2546cb0a8b 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -261,7 +261,7 @@ MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix, NewName.resize(Name.size()); raw_svector_ostream(NewName) << NextUniqueID++; } - auto NameEntry = UsedNames.insert(std::make_pair(NewName, true)); + auto NameEntry = UsedNames.insert(std::make_pair(NewName.str(), true)); if (NameEntry.second || !NameEntry.first->second) { // Ok, we found a name. // Mark it as used for a non-section symbol. @@ -394,7 +394,7 @@ MCContext::createXCOFFSymbolImpl(const StringMapEntry<bool> *Name, else ValidName.append(InvalidName); - auto NameEntry = UsedNames.insert(std::make_pair(ValidName, true)); + auto NameEntry = UsedNames.insert(std::make_pair(ValidName.str(), true)); assert((NameEntry.second || !NameEntry.first->second) && "This name is used somewhere else."); // Mark the name as used for a non-section symbol. diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp index 4ff73f9356cb..70655d1a26be 100644 --- a/llvm/lib/Object/IRSymtab.cpp +++ b/llvm/lib/Object/IRSymtab.cpp @@ -230,7 +230,7 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab, raw_svector_ostream OS(Name); Msymtab.printSymbolName(OS, Msym); } - setStr(Sym.Name, Saver.save(StringRef(Name))); + setStr(Sym.Name, Saver.save(Name.str())); auto Flags = Msymtab.getSymbolFlags(Msym); if (Flags & object::BasicSymbolRef::SF_Undefined) diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp index 6a9258fee5ee..ceb2d7dcb5b9 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp @@ -63,7 +63,7 @@ void CoverageFilenamesSectionWriter::write(raw_ostream &OS, bool Compress) { encodeULEB128(Filenames.size(), OS); encodeULEB128(FilenamesStr.size(), OS); encodeULEB128(doCompression ? CompressedStr.size() : 0U, OS); - OS << (doCompression ? StringRef(CompressedStr) : StringRef(FilenamesStr)); + OS << (doCompression ? CompressedStr.str() : StringRef(FilenamesStr)); } namespace { diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index 0cc82739798d..8cf7d5b1e57e 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -864,7 +864,7 @@ void cl::TokenizeGNUCommandLine(StringRef Src, StringSaver &Saver, // End the token if this is whitespace. if (isWhitespace(C)) { if (!Token.empty()) - NewArgv.push_back(Saver.save(StringRef(Token)).data()); + NewArgv.push_back(Saver.save(Token.str()).data()); // Mark the end of lines in response files. if (MarkEOLs && C == '\n') NewArgv.push_back(nullptr); @@ -878,7 +878,7 @@ void cl::TokenizeGNUCommandLine(StringRef Src, StringSaver &Saver, // Append the last token after hitting EOF with no whitespace. if (!Token.empty()) - NewArgv.push_back(Saver.save(StringRef(Token)).data()); + NewArgv.push_back(Saver.save(Token.str()).data()); } /// Backslashes are interpreted in a rather complicated way in the Windows-style diff --git a/llvm/lib/Support/Signals.cpp b/llvm/lib/Support/Signals.cpp index 5aa1a9efcf59..4e70eed28b86 100644 --- a/llvm/lib/Support/Signals.cpp +++ b/llvm/lib/Support/Signals.cpp @@ -165,8 +165,8 @@ static bool printSymbolizedStackTrace(StringRef Argv0, void **StackTrace, } } - Optional<StringRef> Redirects[] = {StringRef(InputFile), - StringRef(OutputFile), StringRef("")}; + Optional<StringRef> Redirects[] = {InputFile.str(), OutputFile.str(), + StringRef("")}; StringRef Args[] = {"llvm-symbolizer", "--functions=linkage", "--inlining", #ifdef _WIN32 // Pass --relative-address on Windows so that we don't diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index 3f6c434f7720..15bb54e61817 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -1604,7 +1604,7 @@ class llvm::vfs::RedirectingFileSystemParser { } // Remove trailing slash(es), being careful not to remove the root path - StringRef Trimmed(Name); + StringRef Trimmed = Name; size_t RootPathLen = sys::path::root_path(Trimmed, path_style).size(); while (Trimmed.size() > RootPathLen && sys::path::is_separator(Trimmed.back(), path_style)) diff --git a/llvm/lib/Transforms/Scalar/MergeICmps.cpp b/llvm/lib/Transforms/Scalar/MergeICmps.cpp index 0327652ab921..283e9029571a 100644 --- a/llvm/lib/Transforms/Scalar/MergeICmps.cpp +++ b/llvm/lib/Transforms/Scalar/MergeICmps.cpp @@ -596,7 +596,7 @@ class MergedBlockName { append(BB->getName()); } } - return StringRef(Scratch); + return Scratch.str(); } }; } // namespace diff --git a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp index 8836fe220ad8..0f0b551f754a 100644 --- a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp +++ b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp @@ -217,7 +217,7 @@ void MemoryOpRemark::visitIntrinsicCall(const IntrinsicInst &II) { } auto R = makeRemark(RemarkPass.data(), remarkName(RK_IntrinsicCall), &II); - visitCallee(StringRef(CallTo), /*KnownLibCall=*/true, *R); + visitCallee(CallTo.str(), /*KnownLibCall=*/true, *R); visitSizeOperand(II.getOperand(2), *R); auto *CIVolatile = dyn_cast<ConstantInt>(II.getOperand(3)); diff --git a/llvm/tools/llvm-exegesis/lib/Analysis.cpp b/llvm/tools/llvm-exegesis/lib/Analysis.cpp index 519b54512da4..be360b9f6d71 100644 --- a/llvm/tools/llvm-exegesis/lib/Analysis.cpp +++ b/llvm/tools/llvm-exegesis/lib/Analysis.cpp @@ -116,7 +116,7 @@ void Analysis::writeSnippet(raw_ostream &OS, ArrayRef<uint8_t> Bytes, raw_svector_ostream OSS(InstPrinterStr); InstPrinter_->printInst(&MI, 0, "", *SubtargetInfo_, OSS); Bytes = Bytes.drop_front(MISize); - Lines.emplace_back(StringRef(InstPrinterStr).trim()); + Lines.emplace_back(InstPrinterStr.str().trim()); } writeEscaped<Tag>(OS, join(Lines, Separator)); } diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp index 4647b24f8ba4..96124cc03484 100644 --- a/llvm/tools/llvm-readobj/COFFDumper.cpp +++ b/llvm/tools/llvm-readobj/COFFDumper.cpp @@ -1874,7 +1874,7 @@ void COFFDumper::printResourceDirectoryTable( OS << ": (ID " << Entry.Identifier.ID << ")"; } } - Name = StringRef(IDStr); + Name = IDStr; ListScope ResourceType(W, Level.str() + Name.str()); if (Entry.Offset.isSubDir()) { W.printHex("Table Offset", Entry.Offset.value()); diff --git a/llvm/unittests/Bitstream/BitstreamWriterTest.cpp b/llvm/unittests/Bitstream/BitstreamWriterTest.cpp index 993c5aadee2d..054948e7e8b6 100644 --- a/llvm/unittests/Bitstream/BitstreamWriterTest.cpp +++ b/llvm/unittests/Bitstream/BitstreamWriterTest.cpp @@ -38,7 +38,7 @@ TEST(BitstreamWriterTest, emitBlobWithSize) { W.Emit('r', 8); W.Emit(0, 8); } - EXPECT_EQ(StringRef(Expected), Buffer); + EXPECT_EQ(Expected.str(), Buffer); } TEST(BitstreamWriterTest, emitBlobEmpty) { diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDieManualExtractTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDieManualExtractTest.cpp index 458f1db63c5c..d41e0ffa5015 100644 --- a/llvm/unittests/DebugInfo/DWARF/DWARFDieManualExtractTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFDieManualExtractTest.cpp @@ -72,7 +72,7 @@ TEST(DWARFDie, manualExtractDump) { "0x0000000b: DW_TAG_compile_unit", " DW_AT_name (\"/tmp/main.c\")", " DW_AT_language (DW_LANG_C)"}; - StringRef(Output).split(Strings, '\n', -1, false); + Output.str().split(Strings, '\n', -1, false); ASSERT_EQ(Strings.size(), NumOfLines); for (size_t I = 0; I < NumOfLines; ++I) EXPECT_EQ(ValidStrings[I], Strings[I]); diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp index 57fae856acb4..7d880464e266 100644 --- a/llvm/unittests/Support/CommandLineTest.cpp +++ b/llvm/unittests/Support/CommandLineTest.cpp @@ -1064,7 +1064,7 @@ TEST(CommandLineTest, ReadConfigFile) { llvm::SmallString<128> CurrDir; std::error_code EC = llvm::sys::fs::current_path(CurrDir); EXPECT_TRUE(!EC); - EXPECT_TRUE(StringRef(CurrDir) != TestDir.path()); + EXPECT_NE(CurrDir.str(), TestDir.path()); llvm::BumpPtrAllocator A; llvm::StringSaver Saver(A); diff --git a/llvm/unittests/Support/LockFileManagerTest.cpp b/llvm/unittests/Support/LockFileManagerTest.cpp index 0b5a0d982a8f..552053d46e84 100644 --- a/llvm/unittests/Support/LockFileManagerTest.cpp +++ b/llvm/unittests/Support/LockFileManagerTest.cpp @@ -36,7 +36,7 @@ TEST(LockFileManagerTest, Basic) { } // Now that the lock is out of scope, the file should be gone. - EXPECT_FALSE(sys::fs::exists(StringRef(LockedFile))); + EXPECT_FALSE(sys::fs::exists(LockedFile.str())); } TEST(LockFileManagerTest, LinkLockExists) { @@ -52,7 +52,7 @@ TEST(LockFileManagerTest, LinkLockExists) { sys::path::append(TmpFileLock, "file.lock-000"); int FD; - std::error_code EC = sys::fs::openFileForWrite(StringRef(TmpFileLock), FD); + std::error_code EC = sys::fs::openFileForWrite(TmpFileLock.str(), FD); ASSERT_FALSE(EC); int Ret = close(FD); @@ -61,7 +61,7 @@ TEST(LockFileManagerTest, LinkLockExists) { EC = sys::fs::create_link(TmpFileLock.str(), FileLocK.str()); ASSERT_FALSE(EC); - EC = sys::fs::remove(StringRef(TmpFileLock)); + EC = sys::fs::remove(TmpFileLock.str()); ASSERT_FALSE(EC); { @@ -72,7 +72,7 @@ TEST(LockFileManagerTest, LinkLockExists) { } // Now that the lock is out of scope, the file should be gone. - EXPECT_FALSE(sys::fs::exists(StringRef(LockedFile))); + EXPECT_FALSE(sys::fs::exists(LockedFile.str())); } diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index 401ee1af1113..259182dabf11 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -1124,7 +1124,7 @@ StringRef SSANameState::uniqueValueName(StringRef name) { while (true) { probeName += llvm::utostr(nextConflictID++); if (!usedNames.count(probeName)) { - name = StringRef(probeName).copy(usedNameAllocator); + name = probeName.str().copy(usedNameAllocator); break; } probeName.resize(name.size() + 1); @@ -1405,7 +1405,7 @@ static void printFloatValue(const APFloat &apValue, raw_ostream &os) { apValue.toString(strValue); // Make sure that we can parse the default form as a float. - if (StringRef(strValue).contains('.')) { + if (strValue.str().contains('.')) { os << strValue; return; } diff --git a/mlir/lib/Tools/mlir-lsp-server/lsp/Transport.cpp b/mlir/lib/Tools/mlir-lsp-server/lsp/Transport.cpp index 768fd2e09653..35d6734b1935 100644 --- a/mlir/lib/Tools/mlir-lsp-server/lsp/Transport.cpp +++ b/mlir/lib/Tools/mlir-lsp-server/lsp/Transport.cpp @@ -298,7 +298,7 @@ LogicalResult JSONTransport::readStandardMessage(std::string &json) { return failure(); // Content-Length is a mandatory header, and the only one we handle. - StringRef lineRef(line); + StringRef lineRef = line; if (lineRef.consume_front("Content-Length: ")) { llvm::getAsUnsignedInteger(lineRef.trim(), 0, contentLength); } else if (!lineRef.trim().empty()) { @@ -338,7 +338,7 @@ LogicalResult JSONTransport::readDelimitedMessage(std::string &json) { json.clear(); llvm::SmallString<128> line; while (succeeded(readLine(in, line))) { - StringRef lineRef = StringRef(line).trim(); + StringRef lineRef = line.str().trim(); if (lineRef.startswith("//")) { // Found a delimiter for the message. if (lineRef == "// -----") _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits