<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 - functions with empty body are wrongly optimized"
   href="https://bugs.llvm.org/show_bug.cgi?id=33299">33299</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>functions with empty body are wrongly optimized
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>4.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>yangyibiao@nju.edu.cn
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18571" name="attach_18571" title="the test file for reproduce this bug">attachment 18571</a> <a href="attachment.cgi?id=18571&action=edit" title="the test file for reproduce this bug">[details]</a></span>
the test file for reproduce this bug

/* test.c */
#include "stdio.h"

static int g;
static int arr[2] = {0, 1};

static int f1() 
{
    // function with empty body
}

static void f()
{
    g = f1();
}

void main(int argc, char **argv)
{
    f();
    printf("%d\n", arr[g]);
}
/* end of test.c */


With/without optimization when compiling the attached file "test.c", the
outputs are different.

the command for compile the attached file is as follows:

$ clang -O0 test.c -o test0
$ clang -O1 test.c -o test1
$ clang -O2 test.c -o test2
$ clang -O3 test.c -o test3
$ clang -Ofast test.c -o test4</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>