<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - memset() is optimised out even if followed by asm("":::"memory")"
href="https://llvm.org/bugs/show_bug.cgi?id=26997">26997</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>memset() is optimised out even if followed by asm("":::"memory")
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.7
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>socketpair@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>