1 // RUN: %clang_cl_asan -O0 %s -Fe%t 2 // RUN: not %run %t 2>&1 | FileCheck %s 3 4 class Parent { 5 public: 6 int field; 7 }; 8 9 class Child : public Parent { 10 public: 11 int extra_field; 12 }; 13 14 int main(void) { 15 Parent *p = new Parent; 16 Child *c = (Child*)p; // Intentional error here! 17 c->extra_field = 42; 18 // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 19 // CHECK: WRITE of size 4 at [[ADDR]] thread T0 20 // CHECK: {{#0 0x[0-9a-f]* in main .*wrong_downcast_on_heap.cc}}:[[@LINE-3]] 21 // CHECK: [[ADDR]] is located 0 bytes to the right of 4-byte region 22 // CHECK: allocated by thread T0 here: 23 // CHECK: #0 {{.*}} operator new 24 return 0; 25 } 26 27