diff options
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 3 | ||||
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 12 |
2 files changed, 11 insertions, 4 deletions
diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index edd9a9e56c..19f7916a59 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -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 diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 9fe6ef317e..6de0c65ba3 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -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); + } } } } |