if so, how do I turn on? I can't find this in the documentation myself and google didn't provide useful results
e.g,
int arr[2];
arr[5] = n; // runtime error
Yes. The command-line to enable this is -fsanitize=address
.
For more information on this, including expected slowdown and why you might be getting link errors, see Clang's AddressSanitizer Documentation.
Keep in mind the address sanitizer does more than bounds check on stack objects; if that's the only capability you want, I think you can limit it to doing only that by additionally passing -mllvm -asan-stack
. See this page on address sanitizer flags for details.