<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - clang-analyzer-security.FloatLoopCounter is too aggressive"
   href="https://bugs.llvm.org/show_bug.cgi?id=38523">38523</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang-analyzer-security.FloatLoopCounter is too aggressive
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>dcoughlin@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>ldalessandro@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The documentation references CERT: FLP30-C, FLP30-CPP as the basis for this
check.

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

<span class="quote">> 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).</span >

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

<span class="quote">> for (double t = 0.0, dt = 0.0; t < 1.0; t += dt) {
>   dt = f();
> }</span >

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
<a href="https://wiki.sei.cmu.edu/confluence/display/java/NUM09-J.+Do+not+use+floating-point+variables+as+loop+counters">https://wiki.sei.cmu.edu/confluence/display/java/NUM09-J.+Do+not+use+floating-point+variables+as+loop+counters</a>
for reference.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>