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
main(void)14 int 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 T0
20 // CHECK-NEXT: {{#0 0x[0-9a-f]* in main .*wrong_downcast_on_stack.cc}}:[[@LINE-3]]
21 // CHECK: [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:[0-9]+]] in frame
22 // CHECK-NEXT: {{#0 0x[0-9a-f]* in main }}
23 // CHECK: 'p' <== Memory access at offset [[OFFSET]] overflows this variable
24 return 0;
25 }
26
27