Revert r318556 "Loosen -Wempty-body warning"

It seems this somehow made -Wempty-body fire in some macro cases where
it didn't before, e.g.

  ../../third_party/ffmpeg/libavcodec/bitstream.c(169,5):  error: if statement has empty body [-Werror,-Wempty-body]
      ff_dlog(NULL, "new table index=%d size=%d\n", table_index, table_size);
      ^
  ../../third_party/ffmpeg\libavutil/internal.h(276,80):  note: expanded from macro 'ff_dlog'
  #   define ff_dlog(ctx, ...) do { if (0) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0)
                                                                                 ^
  ../../third_party/ffmpeg/libavcodec/bitstream.c(169,5):  note: put the
  semicolon on a separate line to silence this warning

Reverting until this can be figured out.

> Do not show it when `if` or `else` come from macros.
> E.g.,
>
>     #define USED(A) if (A); else
>     #define SOME_IF(A) if (A)
>
>     void test() {
>       // No warnings are shown in those cases now.
>       USED(0);
>       SOME_IF(0);
>     }
>
> Patch by Ilya Biryukov!
>
> Differential Revision: https://reviews.llvm.org/D40185

llvm-svn: 318665
This commit is contained in:
Hans Wennborg 2017-11-20 17:38:16 +00:00
parent dc5050c4f5
commit 9541975071
5 changed files with 3 additions and 18 deletions

View File

@ -9698,7 +9698,6 @@ public:
class ConditionResult {
Decl *ConditionVar;
FullExprArg Condition;
SourceLocation RParenLoc;
bool Invalid;
bool HasKnownValue;
bool KnownValue;
@ -9722,9 +9721,6 @@ public:
return std::make_pair(cast_or_null<VarDecl>(ConditionVar),
Condition.get());
}
void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
llvm::Optional<bool> getKnownValue() const {
if (!HasKnownValue)
return None;

View File

@ -1101,7 +1101,6 @@ bool Parser::ParseParenExprOrCondition(StmtResult *InitStmt,
// Otherwise the condition is valid or the rparen is present.
T.consumeClose();
Cond.setRParenLoc(T.getCloseLocation());
// Check for extraneous ')'s to catch things like "if (foo())) {". We know
// that all callers are looking for a statement after the condition, so ")"

View File

@ -11821,7 +11821,7 @@ static bool ShouldDiagnoseEmptyStmtBody(const SourceManager &SourceMgr,
// Get line numbers of statement and body.
bool StmtLineInvalid;
unsigned StmtLine = SourceMgr.getSpellingLineNumber(StmtLoc,
unsigned StmtLine = SourceMgr.getPresumedLineNumber(StmtLoc,
&StmtLineInvalid);
if (StmtLineInvalid)
return false;

View File

@ -530,7 +530,8 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, bool IsConstexpr, Stmt *InitStmt,
if (elseStmt)
DiagnoseEmptyStmtBody(ElseLoc, elseStmt, diag::warn_empty_else_body);
else
DiagnoseEmptyStmtBody(Cond.RParenLoc, thenStmt, diag::warn_empty_if_body);
DiagnoseEmptyStmtBody(CondExpr->getLocEnd(), thenStmt,
diag::warn_empty_if_body);
return BuildIfStmt(IfLoc, IsConstexpr, InitStmt, Cond, thenStmt, ElseLoc,
elseStmt);

View File

@ -301,14 +301,3 @@ void test7(int x, int y) {
if (x) IDENTITY(); // no-warning
}
#define SOME_IF(A) if (A)
#define IF_ELSE(A) if (A); else
void test_macros() {
SOME_IF(0);
IF_ELSE(0);
IDENTITY(if (0);) // expected-warning{{if statement has empty body}} expected-note{{separate line}}
IDENTITY(if (0); else;) // expected-warning{{else clause has empty body}} expected-note{{separate line}}}
}