https://llvm.org/bugs/show_bug.cgi?id=28416

            Bug ID: 28416
           Summary: malloc is optimized out for release build
           Product: clang
           Version: 3.8
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangb...@nondot.org
          Reporter: dmark...@mac.com
                CC: dgre...@apple.com, llvm-bugs@lists.llvm.org
    Classification: Unclassified

the following code behaves incorrectly

int main(int argc, const char * argv[]) {
    size_t need_size = 0x1000000000000;
    void *data = malloc(need_size);
    if(data == NULL) {
        printf("data == NULL\n");
        return 1;
    } else {
        printf("data != NULL\n");
    }
    free(data);
    return 0;
}

it returns 

data != NULL
Program ended with exit code: 0


but it should return

data == NULL
Program ended with exit code: 1


gcc handles that situation correctly


clang shouldn't optimize it out, because result of the malloc is used and 

caller of my program relies on the exit code

Note, clang flag -fno-builtin prevents clang from malloc optimize out

and solve the problem.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to