HomePhabricator

[analyzer] Check for code testing a variable for 0 after using it as a…

Description

[analyzer] Check for code testing a variable for 0 after using it as a denominator.

This new checker, alpha.core.TestAfterDivZero, catches issues like this:

int sum = ...
int avg = sum / count; // potential division by zero...
if (count == 0) { ... } // ...caught here

Because the analyzer does not necessarily explore /all/ paths through a program,
this check is restricted to only work on zero checks that immediately follow a
division operation (/ % /= %=). This could later be expanded to handle checks
dominated by a division operation but not necessarily in the same CFG block.

Patch by Anders Rönnholm! (with very minor modifications by me)

Details

Committed
jroseJul 10 2014, 9:10 AM
Parents
rL212730: Feeding isSafeToSpeculativelyExecute its DataLayout pointer (in Sink)
Branches
Unknown
Tags
Unknown

Event Timeline