summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2020-12-03 08:24:52 +0100
committerCristian Adam <cristian.adam@qt.io>2023-04-19 14:59:37 +0200
commitb10142749bc818cd1454d121b67254532af8ad5c (patch)
tree240e7d364488d93dd90bf11a7f3c1b28dcee1ad0
parent18ddebe1a1a9bde349441631365f0472e9693520 (diff)
Handle user files as volatile in tooling on windows
Prevent locking user files when running clang tools by marking them as volatile. Non volatile files will be mapped into memory and a handle is kept to track file changes. This handle can prevent other processes to access or remove the file. Fixes: QTCREATORBUG-24911 Change-Id: I517e9982972a9e5e20df60c603675a9d370004c6 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
-rw-r--r--clang/include/clang/Frontend/CompilerInstance.h2
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp4
-rw-r--r--clang/lib/Tooling/Tooling.cpp8
3 files changed, 10 insertions, 4 deletions
diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h
index f132c961c8a2..f9a5d6ce02f3 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -640,7 +640,7 @@ public:
createFileManager(IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr);
/// Create the source manager and replace any existing one with it.
- void createSourceManager(FileManager &FileMgr);
+ void createSourceManager(FileManager &FileMgr, bool UserFilesAreVolatile = false);
/// Create the preprocessor, using the invocation, file, and source managers,
/// and replace any existing one with it.
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index ac9f8f8ed51c..0cf4de8f23f8 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -389,8 +389,8 @@ FileManager *CompilerInstance::createFileManager(
// Source Manager
-void CompilerInstance::createSourceManager(FileManager &FileMgr) {
- SourceMgr = new SourceManager(getDiagnostics(), FileMgr);
+void CompilerInstance::createSourceManager(FileManager &FileMgr, bool UserFilesAreVolatile) {
+ SourceMgr = new SourceManager(getDiagnostics(), FileMgr, UserFilesAreVolatile);
}
// Initialize the remapping of files to alternative contents, e.g.,
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 8966c12ef7c1..4a65a6f410a2 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -429,7 +429,13 @@ bool FrontendActionFactory::runInvocation(
if (!Compiler.hasDiagnostics())
return false;
- Compiler.createSourceManager(*Files);
+#ifdef _WIN32
+ constexpr static bool UserFilesAreVolatile = true;
+#else
+ constexpr static bool UserFilesAreVolatile = false;
+#endif
+
+ Compiler.createSourceManager(*Files, UserFilesAreVolatile);
const bool Success = Compiler.ExecuteAction(*ScopedToolAction);