35 lines · cpp
1// RUN: %clangxx -fsanitize=local-bounds %s -O3 -o %t && %run %t 12// RUN: %clangxx -fsanitize=local-bounds %s -O3 -o %t && not --crash %run %t 33// RUN: %clangxx -fsanitize=local-bounds -fno-sanitize-trap=local-bounds %s -O3 -o %t && not %run %t 3 2>&1 | FileCheck %s4// RUN: %clangxx -fsanitize=local-bounds -fno-sanitize-trap=local-bounds -fsanitize-recover=local-bounds %s -O3 -o %t && %run %t 3 2>&1 | FileCheck %s5// RUN: %clangxx -fsanitize=local-bounds -fno-sanitize-trap=local-bounds -fsanitize-recover=local-bounds -g %s -O3 -o %t && %run %t 3 2>&1 | FileCheck %s --check-prefixes=LINE6 7#include <cstdlib>8 9struct S {10 int k;11 int l;12};13 14__attribute__((noinline)) void init(S *s) {15 __asm__ __volatile__("" : : "r"(s) : "memory");16}17 18__attribute__((noinline, no_sanitize("memory", "address", "hwaddress"))) int19test(char i) {20 S a;21 init(&a);22 S b;23 init(&b);24 return ((int *)(&a))[i];25 // CHECK: error: access out of bounds26 // CHECK: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior27 // LINE: local_bounds.cpp:[[#@LINE-3]]:{{.*}}runtime error: access out of bounds28 // LINE: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior {{.*}}local_bounds.cpp:[[#@LINE-4]]29}30 31int main(int argc, char **argv) {32 test(argv[1][0] - '0');33 return 0;34}35