summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-01-16 16:52:44 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-01-16 16:52:44 +0000
commit99b0a6a03a3ad7285478242b6522683112888a63 (patch)
tree5e74f40b4694bfc9f7b56d2d4270bce62e1dccbf /clang/lib
parent395a7e5d35154c8d8e573fa1e3898dc3f8ce7ef9 (diff)
downloadbcm5719-llvm-99b0a6a03a3ad7285478242b6522683112888a63.tar.gz
bcm5719-llvm-99b0a6a03a3ad7285478242b6522683112888a63.zip
[preprocessor] Call the MacroUndefined callback even when the macro was not defined.
Patch by Enea Zaffanella! llvm-svn: 172623
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Lex/PPDirectives.cpp9
-rw-r--r--clang/lib/Lex/PreprocessingRecord.cpp4
2 files changed, 8 insertions, 5 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 6796f1c21bb..bdca03637db 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1967,16 +1967,17 @@ void Preprocessor::HandleUndefDirective(Token &UndefTok) {
// Okay, we finally have a valid identifier to undef.
MacroInfo *MI = getMacroInfo(MacroNameTok.getIdentifierInfo());
+ // 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, MI);
+
// If the macro is not defined, this is a noop undef, just return.
if (MI == 0) return;
if (!MI->isUsed() && MI->isWarnIfUnused())
Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used);
- // If the callbacks want to know, tell them about the macro #undef.
- if (Callbacks)
- Callbacks->MacroUndefined(MacroNameTok, MI);
-
if (MI->isWarnIfUnused())
WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());
diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp
index 8e8afeb4b76..d7ebeafdf95 100644
--- a/clang/lib/Lex/PreprocessingRecord.cpp
+++ b/clang/lib/Lex/PreprocessingRecord.cpp
@@ -416,7 +416,9 @@ void PreprocessingRecord::MacroDefined(const Token &Id,
void PreprocessingRecord::MacroUndefined(const Token &Id,
const MacroInfo *MI) {
- MacroDefinitions.erase(MI);
+ // Note: MI may be null (when #undef'ining an undefined macro).
+ if (MI)
+ MacroDefinitions.erase(MI);
}
void PreprocessingRecord::InclusionDirective(
OpenPOWER on IntegriCloud