diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-19 20:54:25 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-19 20:54:25 +0000 |
commit | 90ee2a4ecf8ef519ebce5e8fc388d6f818ab1019 (patch) | |
tree | 52d750b9607a311ae1a14cea8d1a4b7bdfb60985 /clang/lib/Parse/ParseStmt.cpp | |
parent | efed613172d902cf2ce49f68dd36f15a29a34dab (diff) | |
download | bcm5719-llvm-90ee2a4ecf8ef519ebce5e8fc388d6f818ab1019.tar.gz bcm5719-llvm-90ee2a4ecf8ef519ebce5e8fc388d6f818ab1019.zip |
Don't warn for empty 'if' body if there is a macro that expands to nothing, e.g:
if (condition)
CALL(0); // empty macro but don't warn for empty body.
Fixes rdar://8436021.
llvm-svn: 119838
Diffstat (limited to 'clang/lib/Parse/ParseStmt.cpp')
-rw-r--r-- | clang/lib/Parse/ParseStmt.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 12444e87bbd..e3c15680c23 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -538,7 +538,8 @@ StmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) { bool Parser::ParseParenExprOrCondition(ExprResult &ExprResult, Decl *&DeclResult, SourceLocation Loc, - bool ConvertToBoolean) { + bool ConvertToBoolean, + bool *MacroExpandedAfterRParen) { bool ParseError = false; SourceLocation LParenLoc = ConsumeParen(); @@ -567,7 +568,14 @@ bool Parser::ParseParenExprOrCondition(ExprResult &ExprResult, } // 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; } @@ -610,7 +618,9 @@ StmtResult Parser::ParseIfStatement(AttributeList *Attr) { // Parse the condition. ExprResult CondExp; Decl *CondVar = 0; - if (ParseParenExprOrCondition(CondExp, CondVar, IfLoc, true)) + bool MacroExpandedInThenStmt; + if (ParseParenExprOrCondition(CondExp, CondVar, IfLoc, true, + &MacroExpandedInThenStmt)) return StmtError(); FullExprArg FullCondExp(Actions.MakeFullExpr(CondExp.get())); @@ -694,7 +704,7 @@ StmtResult Parser::ParseIfStatement(AttributeList *Attr) { ElseStmt = Actions.ActOnNullStmt(ElseStmtLoc); return Actions.ActOnIfStmt(IfLoc, FullCondExp, CondVar, ThenStmt.get(), - ElseLoc, ElseStmt.get()); + MacroExpandedInThenStmt, ElseLoc, ElseStmt.get()); } /// ParseSwitchStatement |