[llvm-bugs] [Bug 26997] New: memset() is optimised out even if followed by asm("":::"memory")

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Mar 19 04:43:42 PDT 2016


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

            Bug ID: 26997
           Summary: memset() is optimised out even if followed by
                    asm("":::"memory")
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: socketpair at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

suppose program:

=============================
#include <string.h>

int main() {
    char buf[256];

    memset(buf,0, sizeof(buf));
    asm volatile("": : :"memory");

    return buf[0];
}
=============================

clang-3.7 -O3 throw out memset() call. (gcc 5.2.1 does not).

if I change assembler directive to

asm volatile("": : "g" (buf) :"memory");

everything works right. AFAIK, clobbering memory mean clobbering ALL memory, so
this may mean that any memory (including buf array) has been potentialy
changed. Since I return first byte of that array, clang (llvm?) should not
think that this byte is always zero.

Interestingly, but

asm volatile("nop": : :"memory");

will elimiate memset() anyway.

-- 
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/20160319/099051e2/attachment.html>


More information about the llvm-bugs mailing list