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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to