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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to