xref: /llvm-project/compiler-rt/test/gwp_asan/heap_buffer_underflow.cpp (revision dcf23e13615f88bdd4975058595ee60cf1d5811c)
121184ec5SMitch Phillips // REQUIRES: gwp_asan
221184ec5SMitch Phillips // RUN: %clangxx_gwp_asan %s -o %t
321184ec5SMitch Phillips // RUN: %expect_crash %run %t 2>&1 | FileCheck %s
421184ec5SMitch Phillips 
521184ec5SMitch Phillips // CHECK: GWP-ASan detected a memory error
6a6258684SMitch Phillips // CHECK: Buffer Underflow at 0x{{[a-f0-9]+}} (1 byte to the left
77339ca27SMitch Phillips // CHECK-SAME: of a {{[1-9][0-9]*}}-byte allocation
821184ec5SMitch Phillips 
921184ec5SMitch Phillips #include <cstdlib>
1021184ec5SMitch Phillips 
1121184ec5SMitch Phillips #include "page_size.h"
1221184ec5SMitch Phillips 
main()1321184ec5SMitch Phillips int main() {
14*dcf23e13SMitch Phillips   char *Ptr = reinterpret_cast<char *>(malloc(pageSize()));
1521184ec5SMitch Phillips   volatile char x = *(Ptr - 1);
1621184ec5SMitch Phillips   return 0;
1721184ec5SMitch Phillips }
18