1// REQUIRES: gwp_asan
2// RUN: %clangxx_gwp_asan %s -o %t
3// RUN: %expect_crash %run %t 2>&1 | FileCheck %s
4
5// CHECK: GWP-ASan detected a memory error
6// CHECK: Buffer Underflow at 0x{{[a-f0-9]+}} (1 byte to the left
7// CHECK-SAME: of a {{[1-9][0-9]*}}-byte allocation
8
9#include <cstdlib>
10
11#include "page_size.h"
12
13int main() {
14 char *Ptr = reinterpret_cast<char *>(malloc(pageSize()));
15 volatile char x = *(Ptr - 1);
16 return 0;
17}
18

source code of compiler-rt/test/gwp_asan/heap_buffer_underflow.cpp