Skip to content

Commit c498ced

Browse files
jansvoboda11mahesh-attarde
authored andcommitted
[llvm][support] Move make_absolute from sys::fs to sys::path (llvm#161459)
The `llvm::sys::fs::make_absolute(const Twine &, SmallVectorImpl<char> &)` functions doesn't perform any FS access - it only modifies the second parameter via path/string operations. This function should live in the `llvm::sys::path` namespace for consistency and for making it easier to spot function calls that perform IO.
1 parent 4c63064 commit c498ced

File tree

20 files changed

+84
-84
lines changed

20 files changed

+84
-84
lines changed

bolt/lib/Core/BinaryContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ void BinaryContext::preprocessDWODebugInfo() {
16621662
"files.\n";
16631663
}
16641664
// Prevent failures when DWOName is already an absolute path.
1665-
sys::fs::make_absolute(DWOCompDir, AbsolutePath);
1665+
sys::path::make_absolute(DWOCompDir, AbsolutePath);
16661666
DWARFUnit *DWOCU =
16671667
DwarfUnit->getNonSkeletonUnitDIE(false, AbsolutePath).getDwarfUnit();
16681668
if (!DWOCU->isDWOUnit()) {

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,7 @@ void DWARFRewriter::writeDWOFiles(
18531853
else if (!sys::fs::exists(CompDir))
18541854
CompDir = ".";
18551855
// Prevent failures when DWOName is already an absolute path.
1856-
sys::fs::make_absolute(CompDir, AbsolutePath);
1856+
sys::path::make_absolute(CompDir, AbsolutePath);
18571857

18581858
std::error_code EC;
18591859
std::unique_ptr<ToolOutputFile> TempOut =

clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ groupReplacements(const TUReplacements &TUs, const TUDiagnostics &TUDs,
142142
// build directories, make them absolute immediately.
143143
SmallString<128> Path = R.getFilePath();
144144
if (BuildDir)
145-
llvm::sys::fs::make_absolute(*BuildDir, Path);
145+
llvm::sys::path::make_absolute(*BuildDir, Path);
146146
else
147147
SM.getFileManager().makeAbsolutePath(Path);
148148

clang-tools-extra/clang-move/Move.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ std::string MakeAbsolutePath(StringRef CurrentDir, StringRef Path) {
7575
return "";
7676
llvm::SmallString<128> InitialDirectory(CurrentDir);
7777
llvm::SmallString<128> AbsolutePath(Path);
78-
llvm::sys::fs::make_absolute(InitialDirectory, AbsolutePath);
78+
llvm::sys::path::make_absolute(InitialDirectory, AbsolutePath);
7979
return CleanPath(std::move(AbsolutePath));
8080
}
8181

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ struct FragmentCompiler {
131131
return std::nullopt;
132132
}
133133
llvm::SmallString<256> AbsPath = llvm::StringRef(*Path);
134-
llvm::sys::fs::make_absolute(FragmentDirectory, AbsPath);
134+
llvm::sys::path::make_absolute(FragmentDirectory, AbsPath);
135135
llvm::sys::path::native(AbsPath, Style);
136136
return AbsPath.str().str();
137137
}

clang-tools-extra/clangd/SystemIncludeExtractor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct DriverArgs {
106106
// relative or absolute).
107107
if (llvm::any_of(Driver,
108108
[](char C) { return llvm::sys::path::is_separator(C); })) {
109-
llvm::sys::fs::make_absolute(Cmd.Directory, Driver);
109+
llvm::sys::path::make_absolute(Cmd.Directory, Driver);
110110
}
111111
this->Driver = Driver.str().str();
112112
for (size_t I = 0, E = Cmd.CommandLine.size(); I < E; ++I) {

clang-tools-extra/clangd/index/SymbolCollector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class SymbolCollector::HeaderFileURICache {
325325
if (R.second) {
326326
llvm::SmallString<256> AbsPath = Path;
327327
if (!llvm::sys::path::is_absolute(AbsPath) && !FallbackDir.empty())
328-
llvm::sys::fs::make_absolute(FallbackDir, AbsPath);
328+
llvm::sys::path::make_absolute(FallbackDir, AbsPath);
329329
assert(llvm::sys::path::is_absolute(AbsPath) &&
330330
"If the VFS can't make paths absolute, a FallbackDir must be "
331331
"provided");

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class TestScheme : public URIScheme {
578578
Body = Body.ltrim('/');
579579
llvm::SmallString<16> Path(Body);
580580
path::native(Path);
581-
fs::make_absolute(TestScheme::TestDir, Path);
581+
path::make_absolute(TestScheme::TestDir, Path);
582582
return std::string(Path);
583583
}
584584

clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ mapInputsToAbsPaths(clang::tooling::CompilationDatabase &CDB,
344344
}
345345
for (const auto &Cmd : Cmds) {
346346
llvm::SmallString<256> CDBPath(Cmd.Filename);
347-
llvm::sys::fs::make_absolute(Cmd.Directory, CDBPath);
347+
llvm::sys::path::make_absolute(Cmd.Directory, CDBPath);
348348
CDBToAbsPaths[std::string(CDBPath)] = std::string(AbsPath);
349349
}
350350
}

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,7 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
20772077

20782078
llvm::SmallString<32> FilePath = File;
20792079
if (!WorkingDir.empty() && !path::is_absolute(FilePath))
2080-
fs::make_absolute(WorkingDir, FilePath);
2080+
path::make_absolute(WorkingDir, FilePath);
20812081
// remove_dots switches to backslashes on windows as a side-effect!
20822082
// We always want to suggest forward slashes for includes.
20832083
// (not remove_dots(..., posix) as that misparses windows paths).
@@ -2091,7 +2091,7 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
20912091
// `BestPrefixLength` accordingly.
20922092
auto CheckDir = [&](llvm::SmallString<32> Dir) -> bool {
20932093
if (!WorkingDir.empty() && !path::is_absolute(Dir))
2094-
fs::make_absolute(WorkingDir, Dir);
2094+
path::make_absolute(WorkingDir, Dir);
20952095
path::remove_dots(Dir, /*remove_dot_dot=*/true);
20962096
for (auto NI = path::begin(File), NE = path::end(File),
20972097
DI = path::begin(Dir), DE = path::end(Dir);

0 commit comments

Comments
 (0)