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