| 1 | // RUN: %clangxx_asan -O0 -std=c++11 %s -o %t && %run %t 2>&1 | FileCheck %s |
| 2 | // RUN: %clangxx_asan -O1 -std=c++11 %s -o %t && %run %t 2>&1 | FileCheck %s |
| 3 | // RUN: %clangxx_asan -O2 -std=c++11 %s -o %t && %run %t 2>&1 | FileCheck %s |
| 4 | |
| 5 | // Test that we do not detect false buffer overflows cased by optimization when |
| 6 | // when local variable replaced by a smaller global constant. |
| 7 | // https://bugs.llvm.org/show_bug.cgi?id=33372 |
| 8 | |
| 9 | #include <stdio.h> |
| 10 | #include <string.h> |
| 11 | |
| 12 | struct A { int x, y, z; }; |
| 13 | struct B { A a; /*gap*/ long b; }; |
| 14 | B *bb; |
| 15 | |
| 16 | void test1() { |
| 17 | A a1 = {.x: 1, .y: 1, .z: 2}; |
| 18 | B b1 = {.a: a1, .b: 6}; |
| 19 | bb = new B(b1); |
| 20 | } |
| 21 | |
| 22 | const char KKK[] = {1, 1, 2}; |
| 23 | char bbb[100000]; |
| 24 | |
| 25 | void test2() { |
| 26 | char cc[sizeof(bbb)]; |
| 27 | memcpy(dest: cc, src: KKK , n: sizeof(KKK)); |
| 28 | memcpy(dest: bbb, src: cc, n: sizeof(bbb)); |
| 29 | } |
| 30 | |
| 31 | int main(int argc, char *argv[]) { |
| 32 | test1(); |
| 33 | test2(); |
| 34 | printf(format: "PASSED" ); |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | // CHECK-NOT: ERROR: AddressSanitizer |
| 39 | // CHECK: PASSED |
| 40 | |