[cfe-dev] [RFC][PATCH] Static analyser warning about identical inner condition
Daniel Marjamäki
Daniel.Marjamaki at evidente.se
Fri May 8 01:46:31 PDT 2015
Hello!
This is just a request for comments.
The patch I attach improves the identicalexpr checker in the static analyser. It adds a warning when there is an identical inner condition inside a if.
Example code taken from a debian project:
if(revint)
{
if(revint)
Testing:
I scanned 477 debian projects with this checker and got 2 warnings. Both are bugs as far as I see. Also, in both these cases the inner conditions does not have an 'else' so there is no unreachable code.
I think it would be a good idea to add a heuristic to avoid warnings when there is hidden code. For example:
if (x)
{
#if SOME_FALSE_CONDITION
x = dostuff();
#endif
if (x)
But other than that... this checker seems to be reliable imho.
A possible further improvement would be to warn also warn if the inner condition "overlaps". For instance:
if (x == 15)
{
if (x > 0)
...
Any opinions / ideas?
Best regards,
Daniel Marjamäki
..................................................................................................................
Daniel Marjamäki Senior Engineer
Evidente ES East AB Warfvinges väg 34 SE-112 51 Stockholm Sweden
Mobile: +46 (0)709 12 42 62
E-mail: Daniel.Marjamaki at evidente.se
www.evidente.se
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 150505-IdenticalInnerCondition.diff
Type: text/x-patch
Size: 1047 bytes
Desc: 150505-IdenticalInnerCondition.diff
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150508/e51b890e/attachment.bin>
More information about the cfe-dev
mailing list