This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] alpha.different.MissingBreak checker
Needs ReviewPublic

Authored by e.pavlov on May 26 2014, 6:27 AM.

Details

Reviewers
jordan_rose
Summary

Please review new checker for Clang static analyzer, which checks for missing 'break' statement in 'switch' statement

Diff Detail

Event Timeline

e.pavlov updated this revision to Diff 9806.May 26 2014, 6:27 AM
e.pavlov retitled this revision from to [analyzer] alpha.different.MissingBreak checker.
e.pavlov updated this object.
e.pavlov edited the test plan for this revision. (Show Details)
e.pavlov added a reviewer: jordan_rose.
e.pavlov added a subscriber: Unknown Object (MLST).
jordan_rose edited edge metadata.May 28 2014, 8:26 AM

We already have this as a warning in Clang: -Wimplicit-fallthrough. The problem is that we have no way to silence it in any mode except C++11 (where we have a [[clang::fallthrough]] attribute), so it currently doesn't do anything in other language modes. There have been some past discussions on cfe-dev about turning it on anyway, possibly with idioms to silence the warning (like a comment containing the word "fallthrough").

e.pavlov added a comment.EditedMay 28 2014, 10:48 PM

Hello Jordan, thanks for reply. I read the discussion on cfe-dev and I agree that this checker could be as special case for DeadStores checker.
My checker also checks dead stores, but this is just one condition to suppress false positives. My checker can find missing break when dead store didn't exist,
we just need to comment out lines 188-189 in the code of the checker. Of course, without dead store checking it produces a little bit more false positives, but it is not too noisy and can find more true positives.
Please note, that this checker can processing 'fallthrough' comments (it might be improved, but it works) and works with another versions of C/C++.

Anyway, I hope that this checker can be useful for further work on implicit-fallthrough warning.