Package: clang Version: 3.0-6 Severity: minor Hi,
when compiling C code using memset in a bad way with clang, enabling optimizations (-O1 / -O2 / -Os) creates binaries with an illegal instruction on x86 and x86_64 systems: zsh: illegal hardware instruction ./ill valgrind: vex x86->IR: unhandled instruction bytes: 0xF 0xB 0x90 0x90 When using gcc (or clang without optimizations), the code terminates with a segmentation fault, I believe this should happen for clang -O1 / -O2 as well. This only happens when compiling _wrong_ code, so I'm not sure how much of a bug this actually is. A file to reproduce this (ill.c) is attached. If I can provide any additional information, please let me know. -- System Information: Debian Release: wheezy/sid APT prefers unstable APT policy: (500, 'unstable') Architecture: i386 (i686) Kernel: Linux 3.2.0-2-686-pae (SMP w/2 CPU cores) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Versions of packages clang depends on: ii libc6 2.13-27 ii libclang-common-dev 3.0-6 ii libffi5 3.0.10-3 ii libgcc1 1:4.7.0-1 ii libllvm3.0 3.0-9 ii libstdc++6 4.7.0-1 ii libstdc++6-4.6-dev 4.6.3-1 Versions of packages clang recommends: ii llvm-3.0-dev <none> ii python 2.7.2-10 clang suggests no packages. -- no debconf information
/* * compiled with: clang -O2 -Wall -Wextra -o ill ill.c * * expected: segmentation fault * actual result: illegal instruction (tested on x86 and x86_64) * happens with -O1, -O2 and -Os, it's fine without optimization */ #include <stdlib.h> #include <string.h> struct __somestruct { int a; int b; int c; int d; int e; int f; }; typedef struct __somestruct _somestruct; typedef _somestruct *somestruct; int main (void) { somestruct foo = NULL; foo = malloc(sizeof(_somestruct)); memset(&foo, 0, sizeof(foo)); /* correct usage: */ /* memset(foo, 0, sizeof(_somestruct)); */ /* note: gcc -O2 optimizes this all away, so to compare it to gcc, the * code may need to be more complex */ foo->a = 25; return 0; }