r279024 - PR28438: Update the information on an identifier with local definitions before

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 17 18:16:55 PDT 2016


Author: rsmith
Date: Wed Aug 17 20:16:55 2016
New Revision: 279024

URL: http://llvm.org/viewvc/llvm-project?rev=279024&view=rev
Log:
PR28438: Update the information on an identifier with local definitions before
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.

Added:
    cfe/trunk/test/Modules/Inputs/PR28438/
    cfe/trunk/test/Modules/Inputs/PR28438/a.h
    cfe/trunk/test/Modules/Inputs/PR28438/b1.h
    cfe/trunk/test/Modules/Inputs/PR28438/b2.h
    cfe/trunk/test/Modules/Inputs/PR28438/module.modulemap
    cfe/trunk/test/Modules/pr28438.cpp
Modified:
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Lex/Preprocessor.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=279024&r1=279023&r2=279024&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Aug 17 20:16:55 2016
@@ -398,6 +398,8 @@ class Preprocessor : public RefCountedBa
 
     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 RefCountedBa
   };
   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;

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=279024&r1=279023&r2=279024&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Wed Aug 17 20:16:55 2016
@@ -618,6 +618,11 @@ static diag::kind getFutureCompatDiagKin
       "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(Toke
     if (&II == Ident__VA_ARGS__)
       CurrentIsPoisoned = Ident__VA_ARGS__->isPoisoned();
 
-    ExternalSource->updateOutOfDateIdentifier(II);
+    updateOutOfDateIdentifier(II);
     Identifier.setKind(II.getTokenID());
 
     if (&II == Ident__VA_ARGS__)

Added: cfe/trunk/test/Modules/Inputs/PR28438/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28438/a.h?rev=279024&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR28438/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR28438/a.h Wed Aug 17 20:16:55 2016
@@ -0,0 +1 @@
+#define FOO

Added: cfe/trunk/test/Modules/Inputs/PR28438/b1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28438/b1.h?rev=279024&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR28438/b1.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR28438/b1.h Wed Aug 17 20:16:55 2016
@@ -0,0 +1,2 @@
+#define FOO
+#include "a.h"

Added: cfe/trunk/test/Modules/Inputs/PR28438/b2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28438/b2.h?rev=279024&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Modules/Inputs/PR28438/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28438/module.modulemap?rev=279024&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/PR28438/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/PR28438/module.modulemap Wed Aug 17 20:16:55 2016
@@ -0,0 +1,2 @@
+module A { header "a.h" export * }
+module B { module B1 { header "b1.h" export * } module B2 { header "b2.h" export * } }

Added: cfe/trunk/test/Modules/pr28438.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/pr28438.cpp?rev=279024&view=auto
==============================================================================
--- cfe/trunk/test/Modules/pr28438.cpp (added)
+++ cfe/trunk/test/Modules/pr28438.cpp Wed Aug 17 20:16:55 2016
@@ -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




More information about the cfe-commits mailing list