diff options
author | Vedant Kumar <vsk@apple.com> | 2017-04-26 21:05:44 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2017-04-26 21:05:44 +0000 |
commit | 349a624ab98ea25abc46f2587b28787a570a6552 (patch) | |
tree | 0b3cded11786b4b886cf287a6d22756f0ada48e1 /clang/lib/Lex | |
parent | 6abada8ab8bbc3ca89338f4ee5dbd86516656d5b (diff) | |
download | bcm5719-llvm-349a624ab98ea25abc46f2587b28787a570a6552.tar.gz bcm5719-llvm-349a624ab98ea25abc46f2587b28787a570a6552.zip |
Revert "Revert "PPCallbacks::MacroUndefined, change signature and add test.""
This reverts commit r301469. It isn't needed with r301470, which fixes
the API break introduced in the original commit.
llvm-svn: 301472
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 29 | ||||
-rw-r--r-- | clang/lib/Lex/PreprocessingRecord.cpp | 3 |
2 files changed, 17 insertions, 15 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 8a56ddf2369..fd4e6d30def 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -2592,25 +2592,26 @@ void Preprocessor::HandleUndefDirective() { // Okay, we have a valid identifier to undef. auto *II = MacroNameTok.getIdentifierInfo(); auto MD = getMacroDefinition(II); + UndefMacroDirective *Undef = nullptr; + + // If the macro is not defined, this is a noop undef. + if (const MacroInfo *MI = MD.getMacroInfo()) { + if (!MI->isUsed() && MI->isWarnIfUnused()) + Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used); + + if (MI->isWarnIfUnused()) + WarnUnusedMacroLocs.erase(MI->getDefinitionLoc()); + + Undef = AllocateUndefMacroDirective(MacroNameTok.getLocation()); + } // If the callbacks want to know, tell them about the macro #undef. // Note: no matter if the macro was defined or not. if (Callbacks) - Callbacks->MacroUndefined(MacroNameTok, MD); - - // If the macro is not defined, this is a noop undef, just return. - const MacroInfo *MI = MD.getMacroInfo(); - if (!MI) - return; - - if (!MI->isUsed() && MI->isWarnIfUnused()) - Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used); - - if (MI->isWarnIfUnused()) - WarnUnusedMacroLocs.erase(MI->getDefinitionLoc()); + Callbacks->MacroUndefined(MacroNameTok, MD, Undef); - appendMacroDirective(MacroNameTok.getIdentifierInfo(), - AllocateUndefMacroDirective(MacroNameTok.getLocation())); + if (Undef) + appendMacroDirective(II, Undef); } //===----------------------------------------------------------------------===// diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp index 13e15f3c943..03c4cbe589d 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -422,7 +422,8 @@ void PreprocessingRecord::MacroDefined(const Token &Id, } void PreprocessingRecord::MacroUndefined(const Token &Id, - const MacroDefinition &MD) { + const MacroDefinition &MD, + const MacroDirective *Undef) { MD.forAllDefinitions([&](MacroInfo *MI) { MacroDefinitions.erase(MI); }); } |