Skip to content

Commit 3cd3202

Browse files
authoredSep 24, 2024··
[Frontend] Teach LoadFromASTFile to take FileName by StringRef (NFC) (#109583)
Without this patch, several callers of LoadFromASTFile construct an instance of std::string to be passed as FileName, only to be converted back to StringRef when LoadFromASTFile calls ReadAST. This patch changes the type of FileName to StringRef and updates the callers.
1 parent 2028687 commit 3cd3202

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed
 

‎clang/include/clang/Frontend/ASTUnit.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,8 @@ class ASTUnit {
692692
///
693693
/// \returns - The initialized ASTUnit or null if the AST failed to load.
694694
static std::unique_ptr<ASTUnit>
695-
LoadFromASTFile(const std::string &Filename,
696-
const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad,
695+
LoadFromASTFile(StringRef Filename, const PCHContainerReader &PCHContainerRdr,
696+
WhatToLoad ToLoad,
697697
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
698698
const FileSystemOptions &FileSystemOpts,
699699
std::shared_ptr<HeaderSearchOptions> HSOpts,

‎clang/lib/CrossTU/CrossTranslationUnit.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,9 @@ CrossTranslationUnitContext::ASTLoader::loadFromDump(StringRef ASTDumpPath) {
566566
IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
567567
new DiagnosticsEngine(DiagID, &*DiagOpts, DiagClient));
568568
return ASTUnit::LoadFromASTFile(
569-
std::string(ASTDumpPath.str()),
570-
CI.getPCHContainerOperations()->getRawReader(), ASTUnit::LoadEverything,
571-
Diags, CI.getFileSystemOpts(), CI.getHeaderSearchOptsPtr());
569+
ASTDumpPath, CI.getPCHContainerOperations()->getRawReader(),
570+
ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts(),
571+
CI.getHeaderSearchOptsPtr());
572572
}
573573

574574
/// Load the AST from a source-file, which is supposed to be located inside the

‎clang/lib/Frontend/ASTUnit.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ void ASTUnit::ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
802802
}
803803

804804
std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
805-
const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
805+
StringRef Filename, const PCHContainerReader &PCHContainerRdr,
806806
WhatToLoad ToLoad, IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
807807
const FileSystemOptions &FileSystemOpts,
808808
std::shared_ptr<HeaderSearchOptions> HSOpts,

‎clang/lib/Frontend/FrontendAction.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,8 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
625625
StringRef InputFile = Input.getFile();
626626

627627
std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(
628-
std::string(InputFile), CI.getPCHContainerReader(),
629-
ASTUnit::LoadPreprocessorOnly, ASTDiags, CI.getFileSystemOpts(),
628+
InputFile, CI.getPCHContainerReader(), ASTUnit::LoadPreprocessorOnly,
629+
ASTDiags, CI.getFileSystemOpts(),
630630
/*HeaderSearchOptions=*/nullptr);
631631
if (!AST)
632632
return false;
@@ -693,9 +693,9 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
693693
StringRef InputFile = Input.getFile();
694694

695695
std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(
696-
std::string(InputFile), CI.getPCHContainerReader(),
697-
ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts(),
698-
CI.getHeaderSearchOptsPtr(), CI.getLangOptsPtr());
696+
InputFile, CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags,
697+
CI.getFileSystemOpts(), CI.getHeaderSearchOptsPtr(),
698+
CI.getLangOptsPtr());
699699

700700
if (!AST)
701701
return false;

‎clang/tools/c-index-test/core_main.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,12 @@ static bool printSourceSymbolsFromModule(StringRef modulePath,
274274

275275
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
276276
CompilerInstance::createDiagnostics(new DiagnosticOptions());
277-
std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
278-
std::string(modulePath), *pchRdr, ASTUnit::LoadASTOnly, Diags,
279-
FileSystemOpts, HSOpts, /*LangOpts=*/nullptr,
280-
/*OnlyLocalDecls=*/true, CaptureDiagsKind::None,
281-
/*AllowASTWithCompilerErrors=*/true,
282-
/*UserFilesAreVolatile=*/false);
277+
std::unique_ptr<ASTUnit> AU =
278+
ASTUnit::LoadFromASTFile(modulePath, *pchRdr, ASTUnit::LoadASTOnly, Diags,
279+
FileSystemOpts, HSOpts, /*LangOpts=*/nullptr,
280+
/*OnlyLocalDecls=*/true, CaptureDiagsKind::None,
281+
/*AllowASTWithCompilerErrors=*/true,
282+
/*UserFilesAreVolatile=*/false);
283283
if (!AU) {
284284
errs() << "failed to create TU for: " << modulePath << '\n';
285285
return true;

‎clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static bool HandleAST(StringRef AstPath) {
155155
IntrusiveRefCntPtr<DiagnosticsEngine> DiagEngine = GetDiagnosticsEngine();
156156

157157
std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile(
158-
AstPath.str(), CI->getPCHContainerOperations()->getRawReader(),
158+
AstPath, CI->getPCHContainerOperations()->getRawReader(),
159159
ASTUnit::LoadASTOnly, DiagEngine, CI->getFileSystemOpts(),
160160
CI->getHeaderSearchOptsPtr());
161161

‎clang/unittests/Frontend/ASTUnitTest.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ TEST_F(ASTUnitTest, SaveLoadPreservesLangOptionsInPrintingPolicy) {
9292
auto HSOpts = std::make_shared<HeaderSearchOptions>();
9393

9494
std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
95-
std::string(ASTFileName.str()), PCHContainerOps->getRawReader(),
96-
ASTUnit::LoadEverything, Diags, FileSystemOptions(), HSOpts);
95+
ASTFileName, PCHContainerOps->getRawReader(), ASTUnit::LoadEverything,
96+
Diags, FileSystemOptions(), HSOpts);
9797

9898
if (!AU)
9999
FAIL() << "failed to load ASTUnit";

0 commit comments

Comments
 (0)
Please sign in to comment.