[llvm-bugs] [Bug 44931] New: Invalid optimization involving malloc and pointer aliasing

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Feb 16 08:46:50 PST 2020


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: unassignedclangbugs at nondot.org
          Reporter: pskocik at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200216/74c7a3cb/attachment.html>


More information about the llvm-bugs mailing list