]> granicus.if.org Git - clang/commitdiff
PR28438: Update the information on an identifier with local definitions before
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 18 Aug 2016 01:16:55 +0000 (01:16 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 18 Aug 2016 01:16:55 +0000 (01:16 +0000)
trying to write out its macro graph, in case we imported a module that added
another module macro between the most recent local definition and the end of
the module.

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

include/clang/Lex/Preprocessor.h
lib/Lex/Preprocessor.cpp
test/Modules/Inputs/PR28438/a.h [new file with mode: 0644]
test/Modules/Inputs/PR28438/b1.h [new file with mode: 0644]
test/Modules/Inputs/PR28438/b2.h [new file with mode: 0644]
test/Modules/Inputs/PR28438/module.modulemap [new file with mode: 0644]
test/Modules/pr28438.cpp [new file with mode: 0644]

index 000df6647fe6c4d9324ca2c2fda26116af59aaa8..66ff490de14eb78ec3a1048e428b6065acd62932 100644 (file)
@@ -398,6 +398,8 @@ class Preprocessor : public RefCountedBase<Preprocessor> {
 
     ModuleMacroInfo *getModuleInfo(Preprocessor &PP,
                                    const IdentifierInfo *II) const {
+      if (II->isOutOfDate())
+        PP.updateOutOfDateIdentifier(const_cast<IdentifierInfo&>(*II));
       // FIXME: Find a spare bit on IdentifierInfo and store a
       //        HasModuleMacros flag.
       if (!II->hasMacroDefinition() ||
@@ -653,6 +655,8 @@ class Preprocessor : public RefCountedBase<Preprocessor> {
   };
   DeserializedMacroInfoChain *DeserialMIChainHead;
 
+  void updateOutOfDateIdentifier(IdentifierInfo &II) const;
+
 public:
   Preprocessor(IntrusiveRefCntPtr<PreprocessorOptions> PPOpts,
                DiagnosticsEngine &diags, LangOptions &opts,
@@ -900,6 +904,8 @@ public:
 
   /// \brief Get the list of leaf (non-overridden) module macros for a name.
   ArrayRef<ModuleMacro*> getLeafModuleMacros(const IdentifierInfo *II) const {
+    if (II->isOutOfDate())
+      updateOutOfDateIdentifier(const_cast<IdentifierInfo&>(*II));
     auto I = LeafModuleMacros.find(II);
     if (I != LeafModuleMacros.end())
       return I->second;
index f0d68725462086dc413609e59fd887c2296b68db..73039373824cacde07ab2d3f4795cd2ef513f753 100644 (file)
@@ -618,6 +618,11 @@ static diag::kind getFutureCompatDiagKind(const IdentifierInfo &II,
       "Keyword not known to come from a newer Standard or proposed Standard");
 }
 
+void Preprocessor::updateOutOfDateIdentifier(IdentifierInfo &II) const {
+  assert(II.isOutOfDate() && "not out of date");
+  getExternalSource()->updateOutOfDateIdentifier(II);
+}
+
 /// HandleIdentifier - This callback is invoked when the lexer reads an
 /// identifier.  This callback looks up the identifier in the map and/or
 /// potentially macro expands it or turns it into a named token (like 'for').
@@ -642,7 +647,7 @@ bool Preprocessor::HandleIdentifier(Token &Identifier) {
     if (&II == Ident__VA_ARGS__)
       CurrentIsPoisoned = Ident__VA_ARGS__->isPoisoned();
 
-    ExternalSource->updateOutOfDateIdentifier(II);
+    updateOutOfDateIdentifier(II);
     Identifier.setKind(II.getTokenID());
 
     if (&II == Ident__VA_ARGS__)
diff --git a/test/Modules/Inputs/PR28438/a.h b/test/Modules/Inputs/PR28438/a.h
new file mode 100644 (file)
index 0000000..a7e26ac
--- /dev/null
@@ -0,0 +1 @@
+#define FOO
diff --git a/test/Modules/Inputs/PR28438/b1.h b/test/Modules/Inputs/PR28438/b1.h
new file mode 100644 (file)
index 0000000..262976e
--- /dev/null
@@ -0,0 +1,2 @@
+#define FOO
+#include "a.h"
diff --git a/test/Modules/Inputs/PR28438/b2.h b/test/Modules/Inputs/PR28438/b2.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Modules/Inputs/PR28438/module.modulemap b/test/Modules/Inputs/PR28438/module.modulemap
new file mode 100644 (file)
index 0000000..cb77d47
--- /dev/null
@@ -0,0 +1,2 @@
+module A { header "a.h" export * }
+module B { module B1 { header "b1.h" export * } module B2 { header "b2.h" export * } }
diff --git a/test/Modules/pr28438.cpp b/test/Modules/pr28438.cpp
new file mode 100644 (file)
index 0000000..b8b9077
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fsyntax-only -verify %s -fmodules -fmodules-cache-path=%t -I%S/Inputs/PR28438 -fimplicit-module-maps
+
+#include "a.h"
+#include "b2.h"
+
+#pragma clang __debug macro FOO
+
+FOO // xpected-no-diagnostics