<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Missing warning about uninitialized var when going through a pointer"
   href="https://llvm.org/bugs/show_bug.cgi?id=28249">28249</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missing warning about uninitialized var when going through a pointer
          </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>-New Bugs
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Source code:

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

int main()
{
  int i;
  printf("%d\n", *(int *)&i);
}
----------------------------------------------------------------------

Results:

----------------------------------------------------------------------
$ clang -std=c11 -Weverything -O3 test.c && ./a.out
-1069783944
----------------------------------------------------------------------

clang version: clang version 3.9.0 (trunk 271312)

For comparison:

----------------------------------------------------------------------
$ gcc -std=c11 -pedantic -Wall -Wextra -O3 test.c && ./a.out
test.c: In function ‘main’:
test.c:6:3: warning: ‘i’ is used uninitialized in this function
[-Wuninitialized]
   printf("%d\n", *(int *)&i);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~
0
----------------------------------------------------------------------

gcc version: gcc (GCC) 7.0.0 20160616 (experimental)

The optimizer sees that an undef value is used:

----------------------------------------------------------------------
*** IR Dump After SROA ***
; Function Attrs: nounwind uwtable
define i32 @main() #0 {
entry:
  %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4
x i8]* @.str, i32 0, i32 0), i32 undef)
  ret i32 0
}
----------------------------------------------------------------------

but nevertheless a warning is not emitted.

The code in the testcase is useless but the same happens when a representation
of an uninitialized variable is accessed, i.e. there is no warning for `*(char
*)&i`.</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>