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/SemaStmt.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/Sema/SemaStmt.cpp')
-rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 16 |
1 files changed, 11 insertions, 5 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 |