<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 - Wrong optimization: instability of uninitialized variables leads to nonsense"
   href="https://bugs.llvm.org/show_bug.cgi?id=44512">44512</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrong optimization: instability of uninitialized variables leads to nonsense
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>ch3root@openwall.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Epigraph: "To put it another way, if I have a comparison that gives one answer
to some observers and other answers to other observers, there may be nothing
that prevents that logical contradiction from infecting the remainder of the
execution." Hal Finkel, <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - InstCombine cannot blindly assume that inttoptr(ptrtoint x) -> x"
   href="show_bug.cgi?id=34548#c77">bug 34548, comment 77</a>.

Uninitialized variables have unstable values which leads to nonsense:

----------------------------------------------------------------------
#include <stdio.h>

void f(unsigned char x, unsigned char y)
{
    if (y == x)
        printf("x = %u\n", x);
}

int main()
{
    unsigned char x = 1;
    unsigned char y; // no trap representation possible
    (void)&y; // disarm C11, 6.3.2.1p2

    f(x, y);
}
----------------------------------------------------------------------
$ clang -std=c11 -Wall -O3 test.c && ./a.out
x = 0
----------------------------------------------------------------------
clang x86-64 version: clang version 10.0.0
(<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
cdd05f2aea3b950a4e2c496175117e6b47b2a050)
----------------------------------------------------------------------

This example uses conditional equivalence propagation to demonstrate the effect
but the problem is not limited to it in any way.

There two aspects here:

1) according to my reading of C11 this program doesn't invoke UB and should
either print the right value or not print anything at all (and AFAIR various
changes proposed for handling uninitialized variables don't change this given
that no trap representation is possible here);
2) IIUC the definition of undef in LLVM is supposed to guarantee the same
result as C11 here.</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>