1 //===-- asan_benchmarks_test.cpp ---------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file is a part of AddressSanitizer, an address sanity checker.
11 // Some benchmarks for the instrumented code.
12 //===----------------------------------------------------------------------===//
14 #include "asan_test_utils.h"
17 __attribute__((noinline
))
18 static void ManyAccessFunc(T
*x
, size_t n_elements
, size_t n_iter
) {
19 for (size_t iter
= 0; iter
< n_iter
; iter
++) {
20 break_optimization(0);
21 // hand unroll the loop to stress the reg alloc.
22 for (size_t i
= 0; i
<= n_elements
- 16; i
+= 16) {
43 TEST(AddressSanitizer
, ManyAccessBenchmark
) {
45 int *int_array
= new int[kLen
];
46 ManyAccessFunc(int_array
, kLen
, 1 << 24);
50 // access 7 char elements in a 7 byte array (i.e. on the border).
51 __attribute__((noinline
))
52 static void BorderAccessFunc(char *x
, size_t n_iter
) {
53 for (size_t iter
= 0; iter
< n_iter
; iter
++) {
54 break_optimization(x
);
65 TEST(AddressSanitizer
, BorderAccessBenchmark
) {
66 char *char_7_array
= new char[7];
67 BorderAccessFunc(char_7_array
, 1 << 30);
68 delete [] char_7_array
;
71 static void FunctionWithLargeStack() {
76 TEST(AddressSanitizer
, FakeStackBenchmark
) {
77 for (int i
= 0; i
< 10000000; i
++)
78 Ident(&FunctionWithLargeStack
)();
81 int main(int argc
, char **argv
) {
82 testing::InitGoogleTest(&argc
, argv
);
83 return RUN_ALL_TESTS();