diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-09-24 19:56:18 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-09-24 19:56:18 +0000 |
commit | c12906ee78e006df6a71acf52ca9dd3171ddbf07 (patch) | |
tree | 9f5b63b76d2234499eec9263896b573ef0f554dd | |
parent | 5e02f6525d109c42650575c352bd2fdb14ed4193 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164549 91177308-0d34-0410-b5e6-96231b3b80d8
-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); + } } } } |