This is an archive of the discontinued LLVM Phabricator instance.

[Analysis] -Wunreachable-code shouldn't fire on the increment of a foreach loop
ClosedPublic

Authored by sammccall on Feb 12 2019, 9:01 AM.

Details

Summary

The idea is that the code here isn't written, so doesn't indicate a bug.
Similar to code expanded from macros.

This means the warning no longer fires on this code:

for (auto C : collection) {
  process(C);
  return;
}
handleEmptyCollection();

Unclear whether this is more often a bug or not in practice, I think it's a
reasonable idiom in some cases.
Either way, if we want to warn on "loop that doesn't loop", I think it should be
a separate warning, and catch while(1) break;

Diff Detail

Repository
rL LLVM

Event Timeline

sammccall created this revision.Feb 12 2019, 9:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 12 2019, 9:01 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
This revision is now accepted and ready to land.Feb 13 2019, 10:13 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 14 2019, 11:16 PM