[llvm-bugs] [Bug 28416] New: malloc is optimized out for release build

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jul 4 10:16:39 PDT 2016


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: unassignedclangbugs at nondot.org
          Reporter: dmarkman at mac.com
                CC: dgregor at apple.com, llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160704/a734c937/attachment.html>


More information about the llvm-bugs mailing list