]> granicus.if.org Git - clang/commitdiff
Fixes a segfault in Tooling when using pch's:
authorManuel Klimek <klimek@google.com>
Tue, 31 Jul 2012 13:56:54 +0000 (13:56 +0000)
committerManuel Klimek <klimek@google.com>
Tue, 31 Jul 2012 13:56:54 +0000 (13:56 +0000)
Clear the FileManager's stat cache in between running
translation units, as the stat cache loaded from a pch
is only valid for one compiler invocation.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161047 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/FileManager.h
lib/Basic/FileManager.cpp
lib/Tooling/Tooling.cpp
test/Tooling/Inputs/lit.local.cfg [new file with mode: 0644]
test/Tooling/Inputs/pch-fail.h [new file with mode: 0644]
test/Tooling/Inputs/pch.cpp [new file with mode: 0644]
test/Tooling/Inputs/pch.h [new file with mode: 0644]
test/Tooling/pch.cpp [new file with mode: 0644]

index 930523f4a729c2560e4c875d1c168b712febe1d1..b00f2b78270944a53ffad7a2f060f5a18adc927b 100644 (file)
@@ -186,6 +186,9 @@ public:
   /// \brief Removes the specified FileSystemStatCache object from the manager.
   void removeStatCache(FileSystemStatCache *statCache);
 
+  /// \brief Removes all FileSystemStatCache objects from the manager.
+  void clearStatCaches();
+
   /// \brief Lookup, cache, and verify the specified directory (real or
   /// virtual).
   ///
index b921f3e0d9d85b61b06fdd32288b61e9689b3aa8..c6b894c7e2fe66830fca5c83408f62a17d562de7 100644 (file)
@@ -223,6 +223,10 @@ void FileManager::removeStatCache(FileSystemStatCache *statCache) {
   PrevCache->setNextStatCache(statCache->getNextStatCache());
 }
 
+void FileManager::clearStatCaches() {
+  StatCache.reset(0);
+}
+
 /// \brief Retrieve the directory that the given file name resides in.
 /// Filename can point to either a real file or a virtual file.
 static const DirectoryEntry *getDirectoryFromFile(FileManager &FileMgr,
index 5d41172a919275a6731f40ef86c8ab8adff9c76c..e93e0c97f710c37a000013921f767812f71f64e1 100644 (file)
@@ -212,6 +212,7 @@ bool ToolInvocation::runInvocation(
   const bool Success = Compiler.ExecuteAction(*ScopedToolAction);
 
   Compiler.resetAndLeakFileManager();
+  Files->clearStatCaches();
   return Success;
 }
 
diff --git a/test/Tooling/Inputs/lit.local.cfg b/test/Tooling/Inputs/lit.local.cfg
new file mode 100644 (file)
index 0000000..e6f55ee
--- /dev/null
@@ -0,0 +1 @@
+config.suffixes = []
diff --git a/test/Tooling/Inputs/pch-fail.h b/test/Tooling/Inputs/pch-fail.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Tooling/Inputs/pch.cpp b/test/Tooling/Inputs/pch.cpp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Tooling/Inputs/pch.h b/test/Tooling/Inputs/pch.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Tooling/pch.cpp b/test/Tooling/pch.cpp
new file mode 100644 (file)
index 0000000..bfa20d8
--- /dev/null
@@ -0,0 +1,21 @@
+// This is a regression test for handling of stat caches within the tooling
+// infrastructure. This test reproduces the problem under valgrind:
+
+// First, create a pch that we can later load. Loading the pch will insert
+// a stat cache into the FileManager:
+// RUN: %clang -x c++-header %S/Inputs/pch.h -o %t1
+
+// Use the generated pch and enforce a subsequent stat miss by by using
+// the test file with an unrelated include as second translation unit:
+// Do not directly pipe into FileCheck, as that would hide errors from
+// valgrind due to pipefail not being set in lit.
+// RUN: clang-check "%S/Inputs/pch.cpp" "%s" -- -include-pch %t1 -I "%S" -c >%t2 2>&1
+// RUN: FileCheck %s < %t2
+
+#include "Inputs/pch-fail.h"
+
+// CHECK: Processing
+
+// FIXME: This is incompatible to -fms-compatibility.
+// XFAIL: win32
+