[llvm-bugs] [Bug 38523] New: clang-analyzer-security.FloatLoopCounter is too aggressive

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 10 11:50:55 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38523

            Bug ID: 38523
           Summary: clang-analyzer-security.FloatLoopCounter is too
                    aggressive
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: ldalessandro at gmail.com
                CC: llvm-bugs at lists.llvm.org

The documentation references CERT: FLP30-C, FLP30-CPP as the basis for this
check.

From
https://wiki.sei.cmu.edu/confluence/display/c/FLP30-C.+Do+not+use+floating-point+variables+as+loop+counters,

> For the purpose of this rule, a loop counter is an induction variable
> that is used as an operand of a comparison expression that is used as 
> the controlling expression of a do, while, or for loop. An induction 
> variable is a variable that gets increased or decreased by a fixed 
> amount on every iteration of a loop [Aho 1986]. Furthermore, the change 
> to the variable must occur directly in the loop body (rather than
> inside a function executed within the loop).

The implementation of this check incorrectly flags the following for loop as
failing.

> for (double t = 0.0, dt = 0.0; t < 1.0; t += dt) {
>   dt = f();
> }

In this case, t is not an induction variable and should not be flagged, as dt
is not fixed. This is a common looping structure in numerical methods.

See the last comment (David Svoboda at the time of writing) at
https://wiki.sei.cmu.edu/confluence/display/java/NUM09-J.+Do+not+use+floating-point+variables+as+loop+counters
for reference.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180810/caec1105/attachment.html>


More information about the llvm-bugs mailing list