[llvm-bugs] [Bug 46677] New: Unexpected behavior for static declaration of memset
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Jul 10 14:50:50 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=46677
Bug ID: 46677
Summary: Unexpected behavior for static declaration of memset
Product: clang
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: efriedma at quicinc.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
neeilans at live.com, richard-llvm at metafoo.co.uk
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.
--
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/20200710/657c7b15/attachment.html>
More information about the llvm-bugs
mailing list