[LLVMbugs] [Bug 16940] New: No warning and incorrect optimization

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Aug 20 08:19:50 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=16940

            Bug ID: 16940
           Summary: No warning and incorrect optimization
           Product: clang
           Version: 3.2
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rjenks at ti.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130820/cddba950/attachment.html>


More information about the llvm-bugs mailing list