Hello.
The comment for the preprocessor callback MacroUndefined says:
/// \brief Hook called whenever a macro \#undef is seen.
However, in function
void Preprocessor::HandleUndefDirective(Token &UndefTok) {
the callback is only called after the following check:
// If the macro is not defined, this is a noop undef, just return.
if (MI == 0) return;
As a result, the client is not notified for some of the #undef's.
Afawct, the client should always be notified, no matter if the macro was
actually defined or not (if it was not previously defined, the callback
should be passed in the null MacroInfo pointer).
Please, find attached a corresponding patch for review.
NOTE: searching the mailing list, it seems the same issue was reported
by Jason Haslam in the following post, apparently with no follow up:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120220/053916.html
Enea.
Index: lib/Lex/PreprocessingRecord.cpp
===================================================================
--- lib/Lex/PreprocessingRecord.cpp (revision 172392)
+++ lib/Lex/PreprocessingRecord.cpp (working copy)
@@ -416,7 +416,9 @@
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(
Index: lib/Lex/PPDirectives.cpp
===================================================================
--- lib/Lex/PPDirectives.cpp (revision 172392)
+++ lib/Lex/PPDirectives.cpp (working copy)
@@ -1967,16 +1967,17 @@
// 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());
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits