<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 - icmp gives inconsistent result for unnamed functions"
   href="https://bugs.llvm.org/show_bug.cgi?id=47090">47090</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>icmp gives inconsistent result for unnamed functions
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>post+llvm@ralfj.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>A Rust user found a case where comparison with icmp is non-deterministic:
<a href="https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=8affd2a65b02a35e16dbab4682cb8886">https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=8affd2a65b02a35e16dbab4682cb8886</a>.

What this does is it take pointers to two functions that are marked as
"unnamed", casts those pointers to integers, and then compares them twice --
once after passing them through a "black box" noinline function, and once
immediately. The compiler seemingly optimized the latter comparison to "false",
but later makes the two function's addresses identical.

If we describe the semantics of this program at the LLVM IR level, then I think
we have to either accept that "icmp" can produce different results for the same
input (it is non-deterministic), or the program has to have UB.  But it's not
UB to compare "unnamed function" pointers, right?  My expectation was that
unnamed function can end up having the same or different addresses depending on
optimizer decisions etc, but whether it is one or the other has to be
consistent throughout a single execution of the program.</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>