This is an archive of the discontinued LLVM Phabricator instance.

warning when inner condition is identical
ClosedPublic

Authored by danielmarjamaki on Jul 2 2015, 3:01 AM.

Details

Summary

The core.alpha.IdenticalExpr checker warns when some expressions are identical. For example when a if condition and else if condition are identical there is a warning.

This patch makes Clang warn also when an inner if condition is identical to the outer if condition.

Diff Detail

Event Timeline

danielmarjamaki retitled this revision from to warning when inner condition is identical.
danielmarjamaki updated this object.
danielmarjamaki edited the test plan for this revision. (Show Details)
danielmarjamaki added a subscriber: Unknown Object (MLST).
kimgr added a subscriber: kimgr.Jul 2 2015, 1:38 PM

Added some ideas for tests that might break.

test/Analysis/identical-expressions.cpp
1543

How about a negative test here, eg

if (++x > 10) {
  if (++x > 10) {
  ...

Or one with a mod of x between the ifs, and one with an unrelated change between the ifs, eg ++y.

Added some ideas for tests that might break.

good ideas.. I will add these tests.

added a few test cases as suggested by Kim.

danielmarjamaki marked an inline comment as done.Jul 6 2015, 3:41 AM

I have tested it. report: https://drive.google.com/file/d/0BykPmWrCOxt2X3NYSWF4X21tR1k/view?usp=sharing

Statistics:
projects: 1398
files: 66578
warnings: 16

I have investigated all warnings and they are correct.

kimgr added a comment.Jul 9 2015, 11:40 AM

Some style nits and a question around the purpose of Sr. It doesn't appear to do what I thought it would.

I'll leave further review in the hands of owners, I'm just passing through.

lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
119

Could you say /*IgnoreSideEffects=*/ false for the last param, so it's more obvious that conditions with side effects are not considered?

120

Can you name this after its purpose? Something like OriginalCondRange...?

125

Is the Sr used for the note, and intended to point to the first if-statement? In your posted output the warning and the note both have the same location, and it would be neat if they pointed to the respective stmts.

test/Analysis/identical-expressions.cpp
1544

s/todo/FIXME/

Use proper sentence casing in comments.

s/written/emitted/ ?

1554

s/dont/Don't/

End sentence with a full stop.

1560

s/dont/Don't/ and end with a full stop.

Some style nits and a question around the purpose of Sr. It doesn't appear to do what I thought it would.

I'll leave further review in the hands of owners, I'm just passing through.

Thanks!

I'll take care of these comments when I get back from my vacation.

Minor cleanup

zaks.anna edited edge metadata.Aug 5 2015, 5:19 PM

Otherwise, LGTM.

Thanks!
Anna.

lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
123

"conditions of the inner and outer statements are identical" ?

Ideally, we'd want to highlight both conditions but i am not sure if that is possible.

test/Analysis/identical-expressions.cpp
1535

What is the purpose of this '//' line?

danielmarjamaki accepted this revision.Aug 10 2015, 12:56 AM
danielmarjamaki added a reviewer: danielmarjamaki.
danielmarjamaki marked 6 inline comments as done.
danielmarjamaki added inline comments.
lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
120

Removed

125

I removed Sr

This revision is now accepted and ready to land.Aug 10 2015, 12:56 AM