[clang] [llvm] [clang] Use the VFS in `CrossTranslationUnitContext` (PR #175097)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 9 10:17:25 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Jan Svoboda (jansvoboda11)
<details>
<summary>Changes</summary>
This PR propagates the VFS where necessary from `CrossTranslationUnitContext::ASTLoader` to avoid sandbox violations.
---
Full diff: https://github.com/llvm/llvm-project/pull/175097.diff
1 Files Affected:
- (modified) clang/lib/CrossTU/CrossTranslationUnit.cpp (+4-1)
``````````diff
diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp
index a3fc2cf6bfb3c..7496deb74cb67 100644
--- a/clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -24,6 +24,7 @@
#include "llvm/ADT/Statistic.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/IOSandbox.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/YAMLParser.h"
@@ -620,6 +621,8 @@ CrossTranslationUnitContext::ASTLoader::loadFromSource(
auto Diags = llvm::makeIntrusiveRefCnt<DiagnosticsEngine>(DiagID, *DiagOpts,
DiagClient);
+ // This runs the driver which isn't expected to be free of sandbox violations.
+ auto BypassSandbox = llvm::sys::sandbox::scopedDisable();
return CreateASTUnitFromCommandLine(
CommandLineArgs.begin(), (CommandLineArgs.end()),
CI.getPCHContainerOperations(), DiagOpts, Diags,
@@ -710,7 +713,7 @@ llvm::Error CrossTranslationUnitContext::ASTLoader::lazyInitInvocationList() {
return llvm::make_error<IndexError>(PreviousParsingResult);
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileContent =
- llvm::MemoryBuffer::getFile(InvocationListFilePath);
+ CI.getVirtualFileSystem().getBufferForFile(InvocationListFilePath);
if (!FileContent) {
PreviousParsingResult = index_error_code::invocation_list_file_not_found;
return llvm::make_error<IndexError>(PreviousParsingResult);
``````````
</details>
https://github.com/llvm/llvm-project/pull/175097
More information about the cfe-commits
mailing list