<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 - UndrefReturn false positive"
   href="https://bugs.llvm.org/show_bug.cgi?id=46215">46215</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>UndrefReturn false positive
          </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>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </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>kim.grasman@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following minimal program triggers a false positive in Clang SA's
UndefReturn checker:

  // t.c
  char T(char **d) {
        char *entries[2];
        entries[0] = d[0];
        char *buf1 = (char *)entries;
        return buf1[1];
  }

  $ clang-11 -cc1 -analyze -analyzer-checker=core.uninitialized.UndefReturn t.c 
  t.c:9:2: warning: Undefined or garbage value returned to caller
[core.uninitialized.UndefReturn]
          return buf1[1];
          ^~~~~~~~~~~~~~
  1 warning generated.

I've tried to debug this, and it looks like the region store gets confused
about the type and size of the region. I believe I narrowed it down to this old
FIXME:
<a href="https://github.com/llvm/llvm-project/blob/e93f7e6d1ab973be717e00966f66739930361a80/clang/lib/StaticAnalyzer/Core/RegionStore.cpp#L1455">https://github.com/llvm/llvm-project/blob/e93f7e6d1ab973be717e00966f66739930361a80/clang/lib/StaticAnalyzer/Core/RegionStore.cpp#L1455</a>.

We hit a similar issue for production code when hashing an array of pointer
values, but

a) it triggers in UndefResultChecker, not ReturnUndefChecker
b) I haven't been able to reduce it as effectively

They both seem to be based on the region store's isUndef logic, so I suspect
they're related.</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>