From 4e5b0884d2f8e2b5ab68e43f1b5dfea07c78d695 Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Sun, 15 Mar 2015 01:08:23 +0000 Subject: [PATCH] -Wempty-body: fix false negative triggered by macros When if statement condition ended in a macro: if (ptr == NULL); the check used to consider the definition location of NULL, instead of the current line. Patch by Manasij Mukherjee. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@232295 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaChecking.cpp | 2 +- test/SemaCXX/warn-empty-body.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index c4ff8b4ef3..5eafa50348 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -8625,7 +8625,7 @@ 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; diff --git a/test/SemaCXX/warn-empty-body.cpp b/test/SemaCXX/warn-empty-body.cpp index d3aaac1d8c..a248c4251d 100644 --- a/test/SemaCXX/warn-empty-body.cpp +++ b/test/SemaCXX/warn-empty-body.cpp @@ -4,10 +4,17 @@ void a(int i); int b(); int c(); +#define MACRO_A 0 + void test1(int x, int y) { while(true) { if (x); // expected-warning {{if statement has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}} + // Check that we handle conditions that start or end with a macro + // correctly. + if (x == MACRO_A); // expected-warning {{if statement has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}} + if (MACRO_A == x); // expected-warning {{if statement has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}} + int i; // PR11329 for (i = 0; i < x; i++); { // expected-warning{{for loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}} -- 2.50.1