<html>
    <head>
      <base href="http://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 --- - No warning and incorrect optimization"
   href="http://llvm.org/bugs/show_bug.cgi?id=16940">16940</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>No warning and incorrect optimization
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.2
          </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>rjenks@ti.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following (bad) code compiles and links with no warnings or errors.  With
any level of optimization enabled it returns the wrong result.

////////// main.c
#include <stdio.h>
#define bool int
bool isBroken();

int main(int argc, const char * argv[]) {
    bool broken = isBroken();
    printf("broken? %s", broken ? "true" : "false");
}

///////// broken.c
#include <stdbool.h>

bool isBroken() {
    return false;
}



Without optimization this prints: "broken? false"
With any level of optimization this prints: "broken? true"

In essence, one file is compiled with bool as a 1 byte datatype and the other
as a 4 byte datatype.  I realize that the fundamental issue is that the
function prototype lied about the function definition.  I'm just surprised that
it didn't generate warnings or errors and that it fooled the optimizer.

This is on a Mac using xCode 4.6.3
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.4.0
Thread model: posix</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>