[cfe-commits] r164549 - in /cfe/trunk: include/clang/Lex/Preprocessor.h lib/Serialization/ASTReader.cpp

Douglas Gregor dgregor at apple.com
Mon Sep 24 12:56:18 PDT 2012


Author: dgregor
Date: Mon Sep 24 14:56:18 2012
New Revision: 164549

URL: http://llvm.org/viewvc/llvm-project?rev=164549&view=rev
Log:
Make sure that we don't end up making an #undef'd macro visible after
the fact. Test cases will come when we're actually (de-)serializing
macro history.

Modified:
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=164549&r1=164548&r2=164549&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Mon Sep 24 14:56:18 2012
@@ -278,7 +278,8 @@
   /// keep a mapping to the history of all macro definitions and #undefs in
   /// the reverse order (the latest one is in the head of the list).
   llvm::DenseMap<IdentifierInfo*, MacroInfo*> Macros;
-
+  friend class ASTReader;
+  
   /// \brief Macros that we want to warn because they are not used at the end
   /// of the translation unit; we store just their SourceLocations instead
   /// something like MacroInfo*. The benefit of this is that when we are

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=164549&r1=164548&r2=164549&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Mon Sep 24 14:56:18 2012
@@ -2552,9 +2552,15 @@
     else {
       IdentifierInfo *II = Names[I].get<IdentifierInfo *>();
       if (!II->hasMacroDefinition()) {
-        II->setHasMacroDefinition(true);
-        if (DeserializationListener)
-          DeserializationListener->MacroVisible(II);
+        // Make sure that this macro hasn't been #undef'd in the mean-time.
+        llvm::DenseMap<IdentifierInfo*, MacroInfo*>::iterator Known
+          = PP.Macros.find(II);
+        if (Known == PP.Macros.end() ||
+            Known->second->getUndefLoc().isInvalid()) {
+          II->setHasMacroDefinition(true);
+          if (DeserializationListener)
+            DeserializationListener->MacroVisible(II);
+        }
       }
     }
   }





More information about the cfe-commits mailing list