harness.cpp revision 1.1.1.3
1//===-- harness.cpp ---------------------------------------------*- C++ -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8 9#include "gwp_asan/tests/harness.h" 10 11namespace gwp_asan { 12namespace test { 13bool OnlyOnce() { 14 static int x = 0; 15 return !x++; 16} 17} // namespace test 18} // namespace gwp_asan 19 20// Optnone to ensure that the calls to these functions are not optimized away, 21// as we're looking for them in the backtraces. 22__attribute__((optnone)) char * 23AllocateMemory(gwp_asan::GuardedPoolAllocator &GPA) { 24 return static_cast<char *>(GPA.allocate(1)); 25} 26__attribute__((optnone)) void 27DeallocateMemory(gwp_asan::GuardedPoolAllocator &GPA, void *Ptr) { 28 GPA.deallocate(Ptr); 29} 30__attribute__((optnone)) void 31DeallocateMemory2(gwp_asan::GuardedPoolAllocator &GPA, void *Ptr) { 32 GPA.deallocate(Ptr); 33} 34__attribute__((optnone)) void TouchMemory(void *Ptr) { 35 *(reinterpret_cast<volatile char *>(Ptr)) = 7; 36} 37