| 1 | // RUN: %clangxx_asan -O0 -fsanitize-address-field-padding=1 %s -o %t |
| 2 | // RUN: not %run %t 11 2>&1 | FileCheck %s |
| 3 | // RUN: %run %t 10 |
| 4 | // |
| 5 | // FIXME: fix 32-bits. |
| 6 | // REQUIRES: asan-64-bits, shadow-scale-3 |
| 7 | // FIXME: Implement ASan intra-object padding in Clang's MS record layout |
| 8 | // UNSUPPORTED: target={{.*windows-msvc.*}} |
| 9 | #include <stdio.h> |
| 10 | #include <stdlib.h> |
| 11 | class Foo { |
| 12 | public: |
| 13 | Foo() : pre1(1), pre2(2), post1(3), post2(4) { |
| 14 | } |
| 15 | virtual ~Foo() { |
| 16 | } |
| 17 | void set(int i, int val) { a[i] = val; } |
| 18 | // CHECK: ERROR: AddressSanitizer: intra-object-overflow |
| 19 | // CHECK: #0 {{.*}}Foo::set{{.*}}intra-object-overflow.cpp:[[@LINE-2]] |
| 20 | private: |
| 21 | int pre1, pre2; |
| 22 | int a[11]; |
| 23 | int post1, post2; |
| 24 | }; |
| 25 | |
| 26 | int main(int argc, char **argv) { |
| 27 | int idx = argc == 2 ? atoi(nptr: argv[1]) : 0; |
| 28 | Foo *foo = new Foo; |
| 29 | foo->set(i: idx, val: 42); |
| 30 | // CHECK: #1 {{.*}}main{{.*}}intra-object-overflow.cpp:[[@LINE-1]] |
| 31 | // CHECK: is located 84 bytes inside of 128-byte region |
| 32 | delete foo; |
| 33 | } |
| 34 | |