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: unassignedclangb...@nondot.org
          Reporter: socketp...@gmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to