1 // Copyright 2019 The Marl Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef marl_sanitizers_h 16 #define marl_sanitizers_h 17 18 // Define MARL_ADDRESS_SANITIZER_ENABLED to 1 if the project was built with the 19 // address sanitizer enabled (-fsanitize=address). 20 #if defined(__SANITIZE_ADDRESS__) 21 #define MARL_ADDRESS_SANITIZER_ENABLED 1 22 #else // defined(__SANITIZE_ADDRESS__) 23 #if defined(__clang__) 24 #if __has_feature(address_sanitizer) 25 #define MARL_ADDRESS_SANITIZER_ENABLED 1 26 #endif // __has_feature(address_sanitizer) 27 #endif // defined(__clang__) 28 #endif // defined(__SANITIZE_ADDRESS__) 29 30 // MARL_ADDRESS_SANITIZER_ONLY(X) resolves to X if 31 // MARL_ADDRESS_SANITIZER_ENABLED is defined to a non-zero value, otherwise 32 // MARL_ADDRESS_SANITIZER_ONLY() is stripped by the preprocessor. 33 #if MARL_ADDRESS_SANITIZER_ENABLED 34 #define MARL_ADDRESS_SANITIZER_ONLY(x) x 35 #else 36 #define MARL_ADDRESS_SANITIZER_ONLY(x) 37 #endif // MARL_ADDRESS_SANITIZER_ENABLED 38 39 // Define MARL_MEMORY_SANITIZER_ENABLED to 1 if the project was built with the 40 // memory sanitizer enabled (-fsanitize=memory). 41 #if defined(__SANITIZE_MEMORY__) 42 #define MARL_MEMORY_SANITIZER_ENABLED 1 43 #else // defined(__SANITIZE_MEMORY__) 44 #if defined(__clang__) 45 #if __has_feature(memory_sanitizer) 46 #define MARL_MEMORY_SANITIZER_ENABLED 1 47 #endif // __has_feature(memory_sanitizer) 48 #endif // defined(__clang__) 49 #endif // defined(__SANITIZE_MEMORY__) 50 51 // MARL_MEMORY_SANITIZER_ONLY(X) resolves to X if MARL_MEMORY_SANITIZER_ENABLED 52 // is defined to a non-zero value, otherwise MARL_MEMORY_SANITIZER_ONLY() is 53 // stripped by the preprocessor. 54 #if MARL_MEMORY_SANITIZER_ENABLED 55 #define MARL_MEMORY_SANITIZER_ONLY(x) x 56 #else 57 #define MARL_MEMORY_SANITIZER_ONLY(x) 58 #endif // MARL_MEMORY_SANITIZER_ENABLED 59 60 // Define MARL_THREAD_SANITIZER_ENABLED to 1 if the project was built with the 61 // thread sanitizer enabled (-fsanitize=thread). 62 #if defined(__SANITIZE_THREAD__) 63 #define MARL_THREAD_SANITIZER_ENABLED 1 64 #else // defined(__SANITIZE_THREAD__) 65 #if defined(__clang__) 66 #if __has_feature(thread_sanitizer) 67 #define MARL_THREAD_SANITIZER_ENABLED 1 68 #endif // __has_feature(thread_sanitizer) 69 #endif // defined(__clang__) 70 #endif // defined(__SANITIZE_THREAD__) 71 72 // MARL_THREAD_SANITIZER_ONLY(X) resolves to X if MARL_THREAD_SANITIZER_ENABLED 73 // is defined to a non-zero value, otherwise MARL_THREAD_SANITIZER_ONLY() is 74 // stripped by the preprocessor. 75 #if MARL_THREAD_SANITIZER_ENABLED 76 #define MARL_THREAD_SANITIZER_ONLY(x) x 77 #else 78 #define MARL_THREAD_SANITIZER_ONLY(x) 79 #endif // MARL_THREAD_SANITIZER_ENABLED 80 81 // Define MARL_UNDEFINED_SANITIZER_ENABLED to 1 if the project was built with 82 // the undefined sanitizer enabled (-fsanitize=undefined). 83 #if defined(__clang__) 84 #if __has_feature(undefined_behavior_sanitizer) 85 #define MARL_UNDEFINED_SANITIZER_ENABLED 1 86 #endif // __has_feature(undefined_behavior_sanitizer) 87 #endif // defined(__clang__) 88 89 // MARL_UNDEFINED_SANITIZER_ONLY(X) resolves to X if 90 // MARL_UNDEFINED_SANITIZER_ENABLED is defined to a non-zero value, otherwise 91 // MARL_UNDEFINED_SANITIZER_ONLY() is stripped by the preprocessor. 92 #if MARL_UNDEFINED_SANITIZER_ENABLED 93 #define MARL_UNDEFINED_SANITIZER_ONLY(x) x 94 #else 95 #define MARL_UNDEFINED_SANITIZER_ONLY(x) 96 #endif // MARL_UNDEFINED_SANITIZER_ENABLED 97 98 #endif // marl_sanitizers_h 99