Revert r119838 "Don't warn for empty 'if' body if there is a macro that expands to nothing"
and use a better and more general approach, where NullStmt has a flag to indicate whether it was preceded by an empty macro.
Thanks to Abramo Bagnara for the hint!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119887 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index e3c1568..26d2279 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -147,8 +147,10 @@
case tok::l_brace: // C99 6.8.2: compound-statement
return ParseCompoundStatement(AttrList);
- case tok::semi: // C99 6.8.3p3: expression[opt] ';'
- return Actions.ActOnNullStmt(ConsumeToken());
+ case tok::semi: { // C99 6.8.3p3: expression[opt] ';'
+ bool LeadingEmptyMacro = Tok.hasLeadingEmptyMacro();
+ return Actions.ActOnNullStmt(ConsumeToken(), LeadingEmptyMacro);
+ }
case tok::kw_if: // C99 6.8.4.1: if-statement
return ParseIfStatement(AttrList);
@@ -538,8 +540,7 @@
bool Parser::ParseParenExprOrCondition(ExprResult &ExprResult,
Decl *&DeclResult,
SourceLocation Loc,
- bool ConvertToBoolean,
- bool *MacroExpandedAfterRParen) {
+ bool ConvertToBoolean) {
bool ParseError = false;
SourceLocation LParenLoc = ConsumeParen();
@@ -568,14 +569,7 @@
}
// Otherwise the condition is valid or the rparen is present.
-
- // Catch a macro expansion after ')'. This is used to know that there is a
- // macro for 'if' body and not warn for empty body if the macro is empty.
- PPMacroExpansionTrap MacroExpansionTrap(PP);
MatchRHSPunctuation(tok::r_paren, LParenLoc);
- if (MacroExpandedAfterRParen)
- *MacroExpandedAfterRParen = MacroExpansionTrap.hasMacroExpansionOccured();
-
return false;
}
@@ -618,9 +612,7 @@
// Parse the condition.
ExprResult CondExp;
Decl *CondVar = 0;
- bool MacroExpandedInThenStmt;
- if (ParseParenExprOrCondition(CondExp, CondVar, IfLoc, true,
- &MacroExpandedInThenStmt))
+ if (ParseParenExprOrCondition(CondExp, CondVar, IfLoc, true))
return StmtError();
FullExprArg FullCondExp(Actions.MakeFullExpr(CondExp.get()));
@@ -704,7 +696,7 @@
ElseStmt = Actions.ActOnNullStmt(ElseStmtLoc);
return Actions.ActOnIfStmt(IfLoc, FullCondExp, CondVar, ThenStmt.get(),
- MacroExpandedInThenStmt, ElseLoc, ElseStmt.get());
+ ElseLoc, ElseStmt.get());
}
/// ParseSwitchStatement