27 lines · cpp
1// RUN: %clang_cl_asan %Od %s %Fe%t2// RUN: not %run %t 2>&1 | FileCheck %s3 4class Parent {5 public:6 int field;7};8 9class Child : public Parent {10 public:11 int extra_field;12};13 14int main(void) {15 Parent p;16 Child *c = (Child*)&p; // Intentional error here!17 c->extra_field = 42;18// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]19// CHECK: WRITE of size 4 at [[ADDR]] thread T020// CHECK-NEXT: {{#0 0x[0-9a-f]* in main .*wrong_downcast_on_stack.cpp}}:[[@LINE-3]]21// CHECK: [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:[0-9]+]] in frame22// CHECK-NEXT: {{#0 0x[0-9a-f]* in main }}23// CHECK: 'p'{{.*}} <== Memory access at offset [[OFFSET]] overflows this variable24 return 0;25}26 27