xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
nix
docker
test_files
cpp
sources
asan.cpp
1
#include <
atomic
>
2
#include <
cstddef
>
3
#include <
iostream
>
4
5
// Regression test: the compiler-rt sanitizer interface headers must be on the
6
// include path. A bare on-PATH clang in the Nix CI env doesn't get them
7
// propagated automatically, so this include would fail to compile with clang++
8
// if the env isn't wired up correctly. abseil hits the same include during
9
// sanitizer builds. LeakSanitizer ships with AddressSanitizer.
10
#include <sanitizer/lsan_interface.h>
11
12
#if defined(__clang__) || defined(__GNUC__)
13
__attribute__((noinline))
14
#elif defined(_MSC_VER)
15
__declspec(noinline)
16
#endif
17
int
18
read_after_free(
volatile
int
* array,
std::size_t
index)
19
{
20
std::atomic_signal_fence
(std::memory_order_seq_cst);
21
int
value = array[index];
22
std::atomic_signal_fence
(std::memory_order_seq_cst);
23
return
value;
24
}
25
26
int
27
main()
28
{
29
int
* array =
new
int
[5]{10, 20, 30, 40, 50};
30
delete
[] array;
31
32
std::cout
<<
"Value at index 2: "
<< read_after_free(array, 2) <<
std::endl
;
33
34
return
0;
35
}
atomic
std::atomic_signal_fence
T atomic_signal_fence(T... args)
std::cout
cstddef
std::endl
T endl(T... args)
iostream
std::size_t
Generated by
1.17.0