aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/sanitizers.h
blob: b7ae9386275e8aa57e2ec7e5690b4011e7e15425 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

/**
 * Convenience macros for determining if the build is instrumented using sanitizers.
 *
 * If any sanitizer is detected, VESPA_USE_SANITIZER will be defined as 1, otherwise not defined.
 * Additionally, the macro VESPA_USE_<SANITIZER_NAME>_SANITIZER will be defined in case code needs to
 * know exactly which sanitizer is being instrumented with.
 */

// Normalize compiler-specific sanitizer definitions
#ifndef __SANITIZE_ADDRESS__
#  if defined(__has_feature)
#    if __has_feature(address_sanitizer)
#      define __SANITIZE_ADDRESS__
#    endif
#  endif
#endif

#ifndef __SANITIZE_THREAD__
#  if defined(__has_feature)
#    if __has_feature(thread_sanitizer)
#      define __SANITIZE_THREAD__
#    endif
#  endif
#endif

#ifndef __SANITIZE_UNDEFINED__
#  if defined(__has_feature)
#    if __has_feature(undefined_sanitizer)
#      define __SANITIZE_UNDEFINED__
#    endif
#  endif
#endif

#ifdef __SANITIZE_ADDRESS__
#  define VESPA_USE_SANITIZER 1
#  define VESPA_USE_ADDRESS_SANITIZER 1
#  define VESPA_SANITIZER_NAME "address"
#endif

#ifdef __SANITIZE_THREAD__
#  define VESPA_USE_SANITIZER 1
#  define VESPA_USE_THREAD_SANITIZER 1
#  define VESPA_SANITIZER_NAME "thread"
#endif

#ifdef __SANITIZE_UNDEFINED__
#  define VESPA_USE_SANITIZER 1
#  define VESPA_USE_UNDEFINED_SANITIZER 1
#  define VESPA_SANITIZER_NAME "undefined"
#endif