This is an archive of the discontinued LLVM Phabricator instance.

Loosen -Wempty-body warning.
ClosedPublic

Authored by rnk on Nov 17 2017, 10:19 AM.

Details

Summary

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);
}

Diff Detail

Repository
rL LLVM

Event Timeline

ilya-biryukov created this revision.Nov 17 2017, 10:19 AM
rnk requested changes to this revision.Nov 17 2017, 10:41 AM

Why does passing the rparen location for the if condition fix the warning for IF_ELSE? I assumed that would refer to the else clause semicolon.

This revision now requires changes to proceed.Nov 17 2017, 10:41 AM
rnk accepted this revision.Nov 17 2017, 12:53 PM

I'll go ahead and land this as requested to unblock things. Thanks for the patch, sorry for the trouble!

lib/Sema/SemaChecking.cpp
11818 ↗(On Diff #123377)

I see, this fixes the else macro case.

This revision is now accepted and ready to land.Nov 17 2017, 12:53 PM
rnk commandeered this revision.Nov 17 2017, 12:55 PM
rnk edited reviewers, added: ilya-biryukov; removed: rnk.
This revision now requires review to proceed.Nov 17 2017, 12:55 PM
rnk updated this revision to Diff 123406.Nov 17 2017, 12:56 PM
  • minor tweak
This revision was automatically updated to reflect the committed changes.
ilya-biryukov edited edge metadata.Nov 20 2017, 2:10 AM
In D40185#928845, @rnk wrote:

Why does passing the rparen location for the if condition fix the warning for IF_ELSE? I assumed that would refer to the else clause semicolon.

Using spelling locations fixes the else case, but breaks some of the if cases involving macros (catched by warn-empty-body.cpp test).