Skip to content

Commit 3ec9ee6

Browse files
authored
Merge pull request #11633 from swiftlang/jan_svoboda/stable-21-sandbox-cherry-pick
[clang] Cherry-pick FS sandboxing (pt. 1)
2 parents 0d4ffb3 + 6980f6e commit 3ec9ee6

File tree

182 files changed

+1240
-865
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+1240
-865
lines changed

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-include-fixer/IncludeFixer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@ bool IncludeFixerActionFactory::runInvocation(
9494

9595
// Create the compiler's actual diagnostics engine. We want to drop all
9696
// diagnostics here.
97-
Compiler.createDiagnostics(Files->getVirtualFileSystem(),
98-
new clang::IgnoringDiagConsumer,
97+
Compiler.createDiagnostics(new clang::IgnoringDiagConsumer,
9998
/*ShouldOwnClient=*/true);
100-
Compiler.createSourceManager(*Files);
99+
Compiler.createSourceManager();
101100

102101
// We abort on fatal errors so don't let a large number of errors become
103102
// fatal. A missing #include can cause thousands of errors.

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/Compiler.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,9 @@ prepareCompilerInstance(std::unique_ptr<clang::CompilerInvocation> CI,
147147
}
148148

149149
auto Clang = std::make_unique<CompilerInstance>(std::move(CI));
150-
Clang->createDiagnostics(*VFS, &DiagsClient, false);
151-
152-
if (auto VFSWithRemapping = createVFSFromCompilerInvocation(
153-
Clang->getInvocation(), Clang->getDiagnostics(), VFS))
154-
VFS = VFSWithRemapping;
155-
Clang->createFileManager(VFS);
156-
150+
Clang->createVirtualFileSystem(VFS, &DiagsClient);
151+
Clang->createDiagnostics(&DiagsClient, false);
152+
Clang->createFileManager();
157153
if (!Clang->createTarget())
158154
return nullptr;
159155

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ class TestScheme : public URIScheme {
577577
Body = Body.ltrim('/');
578578
llvm::SmallString<16> Path(Body);
579579
path::native(Path);
580-
fs::make_absolute(TestScheme::TestDir, Path);
580+
path::make_absolute(TestScheme::TestDir, Path);
581581
return std::string(Path);
582582
}
583583

@@ -775,8 +775,8 @@ It should be used via an editor plugin rather than invoked directly. For more in
775775
clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment variable.
776776
)";
777777
llvm::cl::HideUnrelatedOptions(ClangdCategories);
778-
llvm::cl::ParseCommandLineOptions(argc, argv, Overview,
779-
/*Errs=*/nullptr, FlagsEnvVar);
778+
llvm::cl::ParseCommandLineOptions(argc, argv, Overview, /*Errs=*/nullptr,
779+
/*VFS=*/nullptr, FlagsEnvVar);
780780
if (Test) {
781781
if (!Sync.getNumOccurrences())
782782
Sync = true;

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-tools-extra/include-cleaner/unittests/RecordTest.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,15 @@ TEST_F(PragmaIncludeTest, ExportInUnnamedBuffer) {
625625
*Diags, "clang"));
626626

627627
auto Clang = std::make_unique<CompilerInstance>(std::move(Invocation));
628-
Clang->createDiagnostics(*VFS);
628+
Clang->createVirtualFileSystem(VFS);
629+
Clang->createDiagnostics();
629630

630-
auto *FM = Clang->createFileManager(VFS);
631+
Clang->createFileManager();
632+
FileManager &FM = Clang->getFileManager();
631633
ASSERT_TRUE(Clang->ExecuteAction(*Inputs.MakeAction()));
632634
EXPECT_THAT(
633-
PI.getExporters(llvm::cantFail(FM->getFileRef("foo.h")), *FM),
634-
testing::ElementsAre(llvm::cantFail(FM->getFileRef("exporter.h"))));
635+
PI.getExporters(llvm::cantFail(FM.getFileRef("foo.h")), FM),
636+
testing::ElementsAre(llvm::cantFail(FM.getFileRef("exporter.h"))));
635637
}
636638

637639
TEST_F(PragmaIncludeTest, OutlivesFMAndSM) {

0 commit comments

Comments
 (0)