This is an archive of the discontinued LLVM Phabricator instance.

alpha.core.UnreachableCode - don't warn about unreachable code inside macro
ClosedPublic

Authored by danielmarjamaki on Oct 14 2016, 3:18 AM.

Details

Summary

This patch fixes false positives for such code:

#define RETURN(X)  do { return; } while (0)

void dostuff(void) {
  RETURN(1); // no-warning
}

The condition "0" in the macro is unreachable but that condition is there for a good reason.

Diff Detail

Repository
rL LLVM

Event Timeline

danielmarjamaki retitled this revision from to alpha.core.UnreachableCode - don't warn about unreachable code inside macro.
danielmarjamaki updated this object.
danielmarjamaki added reviewers: NoQ, dcoughlin.
danielmarjamaki set the repository for this revision to rL LLVM.

We should pattern match for this specific macro pattern (ex: do{...}while(0) ) instead of suppressing all warnings coming from macros. Maybe we could use the same heuristic as -Wunreachable-code-return compiler warning?

make pattern to avoid warnings more specific

zaks.anna accepted this revision.Oct 17 2016, 11:57 AM
zaks.anna added a reviewer: zaks.anna.
zaks.anna edited edge metadata.

LGTM. Thank you!

This revision is now accepted and ready to land.Oct 17 2016, 11:58 AM
This revision was automatically updated to reflect the committed changes.