]> granicus.if.org Git - clang/commitdiff
Make sure that we don't end up making an #undef'd macro visible after
authorDouglas Gregor <dgregor@apple.com>
Mon, 24 Sep 2012 19:56:18 +0000 (19:56 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 24 Sep 2012 19:56:18 +0000 (19:56 +0000)
the fact. Test cases will come when we're actually (de-)serializing
macro history.

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

include/clang/Lex/Preprocessor.h
lib/Serialization/ASTReader.cpp

index edd9a9e56c85060a2398b4054deadc2104f8c601..19f7916a5992e4a53f52b240c77bdbc46b2d0bcc 100644 (file)
@@ -278,7 +278,8 @@ class Preprocessor : public RefCountedBase<Preprocessor> {
   /// 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
index 9fe6ef317e13f18829a5c10bfed3e851cea14911..6de0c65ba30a5e62ec80fd5b5340c7a9cd766b6f 100644 (file)
@@ -2552,9 +2552,15 @@ void ASTReader::makeNamesVisible(const HiddenNames &Names) {
     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);
+        }
       }
     }
   }