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

            Bug ID: 44931
           Summary: Invalid optimization involving malloc and pointer
                    aliasing
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangb...@nondot.org
          Reporter: psko...@gmail.com
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@metafoo.co.uk

Sort of contrived, but this code:

int use_malloc(int * X, void ** R, size_t Sz)
{
    *X = 42;
    *R = malloc(Sz);
    return *X;
}

is getting unconditionally optimized to return 42 on clang (not on gcc).

This is an invalid optimization considering that the function can be called
with use_malloc(&errno, ...) and malloc will set errno on failure.

Failing test case:

https://gcc.godbolt.org/z/sEEBpJ

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

Reply via email to