<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - Unexpected behavior for static declaration of memset"
href="https://bugs.llvm.org/show_bug.cgi?id=46677">46677</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Unexpected behavior for static declaration of memset
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</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>efriedma@quicinc.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Take the following at -O0:
static int memset(int z){ return 3; }
int g(int*a) { if (a[0] > 1) return *(volatile char*)0; return 0; }
int f() { int z[1000] = {0}; z[0]++; g(z); return memset(1); }
int main() { f(); f(); }
The program crashes; according to the C standard, it shouldn't. (Strictly
speaking, the name memset can be used for internal symbols if C library headers
aren't included.)
Another testcase; suppose we have something like the following at -O2:
__attribute((noinline)) void *fast_memset(void *s, int c, unsigned long n) {
for (int i = 0; i < n; ++i)
((char*)s)[i] = c;
return s;
}
__attribute((noinline)) static void *memset(void *s, int c, unsigned long n) {
return fast_memset(s, c, n);
}
void f2(char* x) { memset(x, 3, 100); }
int g(volatile int *a) { if (a[0] > 1) return *(volatile char*)0; return 0; }
void f() { volatile int z[1000] = {0}; z[0]++; g(z); }
int main() { f(); f(); }
This crashes; according to the C standard, it also shouldn't crash. (The
"memset" looks like it should work on the surface, but it doesn't due to
constant propagation.)
-----
It's possible there isn't any reasonable way to fix this due to various
compatibility constraints. But we should at least emit a warning in that case.</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>