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/Sema | |
| 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/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 16 | ||||
| -rw-r--r-- | clang/lib/Sema/TreeTransform.h | 8 |
2 files changed, 16 insertions, 8 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index a4f1d34aec3..c6194edac3a 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -282,8 +282,8 @@ Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, StmtResult Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Decl *CondVar, - Stmt *thenStmt, SourceLocation ElseLoc, - Stmt *elseStmt) { + Stmt *thenStmt, bool MacroExpandedInThenStmt, + SourceLocation ElseLoc, Stmt *elseStmt) { ExprResult CondResult(CondVal.release()); VarDecl *ConditionVar = 0; @@ -304,17 +304,23 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Decl *CondVar, // if (condition); // do_stuff(); // - // NOTE: Do not emit this warning if the body is expanded from a macro. if (!elseStmt) { if (NullStmt* stmt = dyn_cast<NullStmt>(thenStmt)) - if (!stmt->getLocStart().isMacroID()) + // But do not warn if the body is a macro that expands to nothing, e.g: + // + // #define CALL(x) + // if (condition) + // CALL(0); + // + if (!MacroExpandedInThenStmt) Diag(stmt->getSemiLoc(), diag::warn_empty_if_body); } DiagnoseUnusedExprResult(elseStmt); return Owned(new (Context) IfStmt(Context, IfLoc, ConditionVar, ConditionExpr, - thenStmt, ElseLoc, elseStmt)); + thenStmt, ElseLoc, elseStmt, + MacroExpandedInThenStmt)); } /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 807346c4c57..3ae4e5c5f49 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -772,9 +772,11 @@ public: /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, - VarDecl *CondVar, Stmt *Then, + VarDecl *CondVar, Stmt *Then, + bool MacroExpandedInThenStmt, SourceLocation ElseLoc, Stmt *Else) { - return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); + return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, + MacroExpandedInThenStmt, ElseLoc, Else); } /// \brief Start building a new switch statement. @@ -3692,7 +3694,7 @@ TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { return SemaRef.Owned(S); return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, - Then.get(), + Then.get(), S->hasMacroExpandedInThenStmt(), S->getElseLoc(), Else.get()); } |

