Clang -fcatch- undefined -behavior does not work as advertised

I built release 3.1 llvm / compiler-rt / clang release 3.1 and I'm trying to check if -fcatch- undefined -behavior really does nothing. So far no luck. For instance. I compile and run

#include <stdio.h>
#include <stdlib.h>

int main() {
    int* x = malloc(sizeof(int) * 10);
    printf("%d\n", x[20]);
    return 0;
}

with

$ /usr/local/bin/clang -fcatch-undefined-behavior undef_test.c && ./a.out
0

Am I missing something really simple?

+5
source share
2 answers

Yes: xnot an array.

From the documentation :

-fcatch- undefined -behavior. , undefined. , , , Clang undefined. , __builtin_trap() . :

  • Subscript, - , , .
  • , .
  • __builtin_unreachable.
  • llvm __builtin_object_size, , __builtin_object_size , . .

, , , : ( malloc), ; (, malloc void*).

,

int main() {
    int x[10] = {};
    printf("%d\n", x[20]);
}

Address Sanitizer.

+4

-fcatch-undefined-behavior . . ABI , .

, malloc - , , .

, malloc NULL. , NULL, NULL ( ). , NULL , ( free realloc). , , malloc -tated NULL, undefined.

, , , malloc .

+1

All Articles