[cfe-commits] r161047 - in /cfe/trunk: include/clang/Basic/FileManager.h lib/Basic/FileManager.cpp lib/Tooling/Tooling.cpp test/Tooling/Inputs/ test/Tooling/Inputs/lit.local.cfg test/Tooling/Inputs/pch-fail.h test/Tooling/Inputs/pch.cpp test/Tooling/Inputs/pch.h test/Tooling/pch.cpp

Manuel Klimek klimek at google.com
Tue Jul 31 06:56:55 PDT 2012


Author: klimek
Date: Tue Jul 31 08:56:54 2012
New Revision: 161047

URL: http://llvm.org/viewvc/llvm-project?rev=161047&view=rev
Log:
Fixes a segfault in Tooling when using pch's:
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.


Added:
    cfe/trunk/test/Tooling/Inputs/
    cfe/trunk/test/Tooling/Inputs/lit.local.cfg
    cfe/trunk/test/Tooling/Inputs/pch-fail.h
    cfe/trunk/test/Tooling/Inputs/pch.cpp
    cfe/trunk/test/Tooling/Inputs/pch.h
    cfe/trunk/test/Tooling/pch.cpp
Modified:
    cfe/trunk/include/clang/Basic/FileManager.h
    cfe/trunk/lib/Basic/FileManager.cpp
    cfe/trunk/lib/Tooling/Tooling.cpp

Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=161047&r1=161046&r2=161047&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Tue Jul 31 08:56:54 2012
@@ -186,6 +186,9 @@
   /// \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).
   ///

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=161047&r1=161046&r2=161047&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Tue Jul 31 08:56:54 2012
@@ -223,6 +223,10 @@
   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,

Modified: cfe/trunk/lib/Tooling/Tooling.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=161047&r1=161046&r2=161047&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/Tooling.cpp (original)
+++ cfe/trunk/lib/Tooling/Tooling.cpp Tue Jul 31 08:56:54 2012
@@ -212,6 +212,7 @@
   const bool Success = Compiler.ExecuteAction(*ScopedToolAction);
 
   Compiler.resetAndLeakFileManager();
+  Files->clearStatCaches();
   return Success;
 }
 

Added: cfe/trunk/test/Tooling/Inputs/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/Inputs/lit.local.cfg?rev=161047&view=auto
==============================================================================
--- cfe/trunk/test/Tooling/Inputs/lit.local.cfg (added)
+++ cfe/trunk/test/Tooling/Inputs/lit.local.cfg Tue Jul 31 08:56:54 2012
@@ -0,0 +1 @@
+config.suffixes = []

Added: cfe/trunk/test/Tooling/Inputs/pch-fail.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/Inputs/pch-fail.h?rev=161047&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Tooling/Inputs/pch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/Inputs/pch.cpp?rev=161047&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Tooling/Inputs/pch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/Inputs/pch.h?rev=161047&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Tooling/pch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/pch.cpp?rev=161047&view=auto
==============================================================================
--- cfe/trunk/test/Tooling/pch.cpp (added)
+++ cfe/trunk/test/Tooling/pch.cpp Tue Jul 31 08:56:54 2012
@@ -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
+





More information about the cfe-commits mailing list