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.

llvm-svn: 164549
This commit is contained in:
Douglas Gregor 2012-09-24 19:56:18 +00:00
parent 3cb355d11f
commit e769d862ee
2 changed files with 11 additions and 4 deletions

View 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

View 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);
}
}
}
}