[clang-tools-extra] r187898 - Fixed incorrect header guard/nested header mechanism.

John Thompson John.Thompson.JTSoftware at gmail.com
Wed Aug 7 11:49:47 PDT 2013


Author: jtsoftware
Date: Wed Aug  7 13:49:47 2013
New Revision: 187898

URL: http://llvm.org/viewvc/llvm-project?rev=187898&view=rev
Log:
Fixed incorrect header guard/nested header mechanism.

Modified:
    clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
    clang-tools-extra/trunk/test/modularize/Inputs/HeaderGuard.h
    clang-tools-extra/trunk/test/modularize/NoProblemsGuard.modularize

Modified: clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp?rev=187898&r1=187897&r2=187898&view=diff
==============================================================================
--- clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp (original)
+++ clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp Wed Aug  7 13:49:47 2013
@@ -223,6 +223,7 @@
 #include "clang/Lex/PPCallbacks.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/StringPool.h"
+#include "llvm/ADT/SmallSet.h"
 #include "PreprocessorTracker.h"
 
 namespace Modularize {
@@ -806,6 +807,7 @@ public:
   // Handle entering a preprocessing session.
   void handlePreprocessorEntry(clang::Preprocessor &PP,
                                llvm::StringRef rootHeaderFile) {
+    HeadersInThisCompile.clear();
     assert((HeaderStack.size() == 0) && "Header stack should be empty.");
     pushHeaderHandle(addHeader(rootHeaderFile));
     PP.addPPCallbacks(new PreprocessorCallbacks(*this, PP, rootHeaderFile));
@@ -819,12 +821,11 @@ public:
     if (HeaderPath.startswith("<"))
       return;
     HeaderHandle H = addHeader(HeaderPath);
-    if (H != getCurrentHeaderHandle()) {
-      // Check for nested header.
-      if (!InNestedHeader)
-        InNestedHeader = isHeaderHandleInStack(H);
+    if (H != getCurrentHeaderHandle())
       pushHeaderHandle(H);
-    }
+    // Check for nested header.
+    if (!InNestedHeader)
+      InNestedHeader = !HeadersInThisCompile.insert(H);
   }
   // Handle exiting a header source file.
   void handleHeaderExit(llvm::StringRef HeaderPath) {
@@ -1167,6 +1168,7 @@ private:
   std::vector<HeaderHandle> HeaderStack;
   std::vector<HeaderInclusionPath> InclusionPaths;
   InclusionPathHandle CurrentInclusionPathHandle;
+  llvm::SmallSet<HeaderHandle, 128> HeadersInThisCompile;
   MacroExpansionMap MacroExpansions;
   ConditionalExpansionMap ConditionalExpansions;
   bool InNestedHeader;

Modified: clang-tools-extra/trunk/test/modularize/Inputs/HeaderGuard.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/modularize/Inputs/HeaderGuard.h?rev=187898&r1=187897&r2=187898&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/modularize/Inputs/HeaderGuard.h (original)
+++ clang-tools-extra/trunk/test/modularize/Inputs/HeaderGuard.h Wed Aug  7 13:49:47 2013
@@ -2,4 +2,5 @@
 #define _HEADERGUARD_H_
 #include "HeaderGuardSub1.h"
 #include "HeaderGuardSub2.h"
+#include "HeaderGuardSubSub.h"
 #endif // _HEADERGUARD_H_

Modified: clang-tools-extra/trunk/test/modularize/NoProblemsGuard.modularize
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/modularize/NoProblemsGuard.modularize?rev=187898&r1=187897&r2=187898&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/modularize/NoProblemsGuard.modularize (original)
+++ clang-tools-extra/trunk/test/modularize/NoProblemsGuard.modularize Wed Aug  7 13:49:47 2013
@@ -2,3 +2,4 @@
 
 Inputs/HeaderGuardSub1.h
 Inputs/HeaderGuardSub2.h
+Inputs/HeaderGuard.h





More information about the cfe-commits mailing list