-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.

llvm-svn: 232295
This commit is contained in:
Dmitri Gribenko 2015-03-15 01:08:23 +00:00
parent 86ecb1bdaf
commit ad80af8f19
2 changed files with 8 additions and 1 deletions

View File

@ -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;

View File

@ -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}}