macros.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. /*
  5. OPENTELEMETRY_HAVE_BUILTIN&OPENTELEMETRY_HAVE_FEATURE
  6. Checks whether the compiler supports a Clang Feature Checking Macro, and if
  7. so, checks whether it supports the provided builtin function "x" where x
  8. is one of the functions noted in
  9. https://clang.llvm.org/docs/LanguageExtensions.html
  10. Note: Use this macro to avoid an extra level of #ifdef __has_builtin check.
  11. http://releases.llvm.org/3.3/tools/clang/docs/LanguageExtensions.html
  12. */
  13. #if !defined(OPENTELEMETRY_HAVE_BUILTIN)
  14. # ifdef __has_builtin
  15. # define OPENTELEMETRY_HAVE_BUILTIN(x) __has_builtin(x)
  16. # else
  17. # define OPENTELEMETRY_HAVE_BUILTIN(x) 0
  18. # endif
  19. #endif
  20. #if !defined(OPENTELEMETRY_HAVE_FEATURE)
  21. # ifdef __has_feature
  22. # define OPENTELEMETRY_HAVE_FEATURE(f) __has_feature(f)
  23. # else
  24. # define OPENTELEMETRY_HAVE_FEATURE(f) 0
  25. # endif
  26. #endif
  27. /*
  28. has feature
  29. OPENTELEMETRY_HAVE_ATTRIBUTE
  30. A function-like feature checking macro that is a wrapper around
  31. `__has_attribute`, which is defined by GCC 5+ and Clang and evaluates to a
  32. nonzero constant integer if the attribute is supported or 0 if not.
  33. It evaluates to zero if `__has_attribute` is not defined by the compiler.
  34. GCC: https://gcc.gnu.org/gcc-5/changes.html
  35. Clang: https://clang.llvm.org/docs/LanguageExtensions.html
  36. */
  37. #if !defined(OPENTELEMETRY_HAVE_ATTRIBUTE)
  38. # ifdef __has_attribute
  39. # define OPENTELEMETRY_HAVE_ATTRIBUTE(x) __has_attribute(x)
  40. # else
  41. # define OPENTELEMETRY_HAVE_ATTRIBUTE(x) 0
  42. # endif
  43. #endif
  44. /*
  45. OPENTELEMETRY_HAVE_CPP_ATTRIBUTE
  46. A function-like feature checking macro that accepts C++11 style attributes.
  47. It's a wrapper around `__has_cpp_attribute`, defined by ISO C++ SD-6
  48. (https://en.cppreference.com/w/cpp/experimental/feature_test). If we don't
  49. find `__has_cpp_attribute`, will evaluate to 0.
  50. */
  51. #if !defined(OPENTELEMETRY_HAVE_CPP_ATTRIBUTE)
  52. # if defined(__cplusplus) && defined(__has_cpp_attribute)
  53. // NOTE: requiring __cplusplus above should not be necessary, but
  54. // works around https://bugs.llvm.org/show_bug.cgi?id=23435.
  55. # define OPENTELEMETRY_HAVE_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
  56. # else
  57. # define OPENTELEMETRY_HAVE_CPP_ATTRIBUTE(x) 0
  58. # endif
  59. #endif
  60. /*
  61. Expected usage pattern:
  62. if OPENTELEMETRY_LIKELY_CONDITION (ptr != nullptr)
  63. {
  64. do_something_likely();
  65. } else {
  66. do_something_unlikely();
  67. }
  68. This pattern works with gcc/clang and __builtin_expect(),
  69. as well as with C++20.
  70. It is unclear if __builtin_expect() will be deprecated
  71. in favor of C++20 [[likely]] or not.
  72. OPENTELEMETRY_LIKELY_CONDITION is preferred over OPENTELEMETRY_LIKELY,
  73. to be revisited when C++20 is required.
  74. */
  75. #if !defined(OPENTELEMETRY_LIKELY_CONDITION) && defined(__cplusplus)
  76. // Only use likely with C++20
  77. # if __cplusplus >= 202002L
  78. // GCC 9 has likely attribute but do not support declare it at the beginning of statement
  79. # if defined(__has_cpp_attribute) && (defined(__clang__) || !defined(__GNUC__) || __GNUC__ > 9)
  80. # if __has_cpp_attribute(likely)
  81. # define OPENTELEMETRY_LIKELY_CONDITION(C) (C) [[likely]]
  82. # endif
  83. # endif
  84. # endif
  85. #endif
  86. #if !defined(OPENTELEMETRY_LIKELY_CONDITION) && (defined(__clang__) || defined(__GNUC__))
  87. // Only use if supported by the compiler
  88. # define OPENTELEMETRY_LIKELY_CONDITION(C) (__builtin_expect(!!(C), true))
  89. #endif
  90. #ifndef OPENTELEMETRY_LIKELY_CONDITION
  91. // Do not use likely annotations
  92. # define OPENTELEMETRY_LIKELY_CONDITION(C) (C)
  93. #endif
  94. #if !defined(OPENTELEMETRY_UNLIKELY_CONDITION) && defined(__cplusplus)
  95. // Only use unlikely with C++20
  96. # if __cplusplus >= 202002L
  97. // GCC 9 has unlikely attribute but do not support declare it at the beginning of statement
  98. # if defined(__has_cpp_attribute) && (defined(__clang__) || !defined(__GNUC__) || __GNUC__ > 9)
  99. # if __has_cpp_attribute(unlikely)
  100. # define OPENTELEMETRY_UNLIKELY_CONDITION(C) (C) [[unlikely]]
  101. # endif
  102. # endif
  103. # endif
  104. #endif
  105. #if !defined(OPENTELEMETRY_UNLIKELY_CONDITION) && (defined(__clang__) || defined(__GNUC__))
  106. // Only use if supported by the compiler
  107. # define OPENTELEMETRY_UNLIKELY_CONDITION(C) (__builtin_expect(!!(C), false))
  108. #endif
  109. #ifndef OPENTELEMETRY_UNLIKELY_CONDITION
  110. // Do not use unlikely annotations
  111. # define OPENTELEMETRY_UNLIKELY_CONDITION(C) (C)
  112. #endif
  113. /*
  114. Expected usage pattern:
  115. if (ptr != nullptr)
  116. OPENTELEMETRY_LIKELY
  117. {
  118. do_something_likely();
  119. } else {
  120. do_something_unlikely();
  121. }
  122. This pattern works starting with C++20.
  123. See https://en.cppreference.com/w/cpp/language/attributes/likely
  124. Please use OPENTELEMETRY_LIKELY_CONDITION instead for now.
  125. */
  126. #if !defined(OPENTELEMETRY_LIKELY) && defined(__cplusplus)
  127. // Only use likely with C++20
  128. # if __cplusplus >= 202002L
  129. // GCC 9 has likely attribute but do not support declare it at the beginning of statement
  130. # if defined(__has_cpp_attribute) && (defined(__clang__) || !defined(__GNUC__) || __GNUC__ > 9)
  131. # if __has_cpp_attribute(likely)
  132. # define OPENTELEMETRY_LIKELY [[likely]]
  133. # endif
  134. # endif
  135. # endif
  136. #endif
  137. #ifndef OPENTELEMETRY_LIKELY
  138. # define OPENTELEMETRY_LIKELY
  139. #endif
  140. #if !defined(OPENTELEMETRY_UNLIKELY) && defined(__cplusplus)
  141. // Only use unlikely with C++20
  142. # if __cplusplus >= 202002L
  143. // GCC 9 has unlikely attribute but do not support declare it at the beginning of statement
  144. # if defined(__has_cpp_attribute) && (defined(__clang__) || !defined(__GNUC__) || __GNUC__ > 9)
  145. # if __has_cpp_attribute(unlikely)
  146. # define OPENTELEMETRY_UNLIKELY [[unlikely]]
  147. # endif
  148. # endif
  149. # endif
  150. #endif
  151. #ifndef OPENTELEMETRY_UNLIKELY
  152. # define OPENTELEMETRY_UNLIKELY
  153. #endif
  154. /// \brief Declare variable as maybe unused
  155. /// usage:
  156. /// OPENTELEMETRY_MAYBE_UNUSED int a;
  157. /// class OPENTELEMETRY_MAYBE_UNUSED a;
  158. /// OPENTELEMETRY_MAYBE_UNUSED int a();
  159. ///
  160. #if defined(__cplusplus) && __cplusplus >= 201703L
  161. # define OPENTELEMETRY_MAYBE_UNUSED [[maybe_unused]]
  162. #elif defined(__clang__)
  163. # define OPENTELEMETRY_MAYBE_UNUSED __attribute__((unused))
  164. #elif defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
  165. # define OPENTELEMETRY_MAYBE_UNUSED __attribute__((unused))
  166. #elif (defined(_MSC_VER) && _MSC_VER >= 1910) && (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
  167. # define OPENTELEMETRY_MAYBE_UNUSED [[maybe_unused]]
  168. #else
  169. # define OPENTELEMETRY_MAYBE_UNUSED
  170. #endif
  171. #ifndef OPENTELEMETRY_RTTI_ENABLED
  172. # if defined(__clang__)
  173. # if __has_feature(cxx_rtti)
  174. # define OPENTELEMETRY_RTTI_ENABLED
  175. # endif
  176. # elif defined(__GNUG__)
  177. # if defined(__GXX_RTTI)
  178. # define OPENTELEMETRY_RTTI_ENABLED
  179. # endif
  180. # elif defined(_MSC_VER)
  181. # if defined(_CPPRTTI)
  182. # define OPENTELEMETRY_RTTI_ENABLED
  183. # endif
  184. # endif
  185. #endif
  186. #if defined(__cplusplus) && __cplusplus >= 201402L
  187. # define OPENTELEMETRY_DEPRECATED [[deprecated]]
  188. #elif defined(__clang__)
  189. # define OPENTELEMETRY_DEPRECATED __attribute__((deprecated))
  190. #elif defined(__GNUC__)
  191. # define OPENTELEMETRY_DEPRECATED __attribute__((deprecated))
  192. #elif defined(_MSC_VER)
  193. # if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
  194. # define OPENTELEMETRY_DEPRECATED [[deprecated]]
  195. # else
  196. # define OPENTELEMETRY_DEPRECATED __declspec(deprecated)
  197. # endif
  198. #else
  199. # define OPENTELEMETRY_DEPRECATED
  200. #endif
  201. #if defined(__cplusplus) && __cplusplus >= 201402L
  202. # define OPENTELEMETRY_DEPRECATED_MESSAGE(msg) [[deprecated(msg)]]
  203. #elif defined(__clang__)
  204. # define OPENTELEMETRY_DEPRECATED_MESSAGE(msg) __attribute__((deprecated(msg)))
  205. #elif defined(__GNUC__)
  206. # define OPENTELEMETRY_DEPRECATED_MESSAGE(msg) __attribute__((deprecated(msg)))
  207. #elif defined(_MSC_VER)
  208. # if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
  209. # define OPENTELEMETRY_DEPRECATED_MESSAGE(msg) [[deprecated(msg)]]
  210. # else
  211. # define OPENTELEMETRY_DEPRECATED_MESSAGE(msg) __declspec(deprecated(msg))
  212. # endif
  213. #else
  214. # define OPENTELEMETRY_DEPRECATED_MESSAGE(msg)
  215. #endif
  216. // Regex support
  217. #if (__GNUC__ == 4 && (__GNUC_MINOR__ == 8 || __GNUC_MINOR__ == 9))
  218. # define OPENTELEMETRY_HAVE_WORKING_REGEX 0
  219. #else
  220. # define OPENTELEMETRY_HAVE_WORKING_REGEX 1
  221. #endif
  222. /* clang-format off */
  223. /**
  224. @page HEADER_ONLY_SINGLETON Header only singleton.
  225. @section ELF_SINGLETON
  226. For clang and gcc, the desired coding pattern is as follows.
  227. @verbatim
  228. class Foo
  229. {
  230. // (a)
  231. __attribute__((visibility("default")))
  232. // (b)
  233. T& get_singleton()
  234. {
  235. // (c)
  236. static T singleton;
  237. return singleton;
  238. }
  239. };
  240. @endverbatim
  241. (a) is needed when the code is build with
  242. @code -fvisibility="hidden" @endcode
  243. to ensure that all instances of (b) are visible to the linker.
  244. What is duplicated in the binary is @em code, in (b).
  245. The linker will make sure only one instance
  246. of all the (b) methods is used.
  247. (c) is a singleton implemented inside a method.
  248. This is very desirable, because:
  249. - the C++ compiler guarantees that construction
  250. of the variable (c) is thread safe.
  251. - constructors for (c) singletons are executed in code path order,
  252. or not at all if the singleton is never used.
  253. @section OTHER_SINGLETON
  254. For other platforms, header only singletons are not supported at this
  255. point.
  256. @section CODING_PATTERN
  257. The coding pattern to use in the source code is as follows
  258. @verbatim
  259. class Foo
  260. {
  261. OPENTELEMETRY_API_SINGLETON
  262. T& get_singleton()
  263. {
  264. static T singleton;
  265. return singleton;
  266. }
  267. };
  268. @endverbatim
  269. */
  270. /* clang-format on */
  271. #if defined(__clang__)
  272. # define OPENTELEMETRY_API_SINGLETON __attribute__((visibility("default")))
  273. # define OPENTELEMETRY_LOCAL_SYMBOL __attribute__((visibility("hidden")))
  274. #elif defined(__GNUC__)
  275. # define OPENTELEMETRY_API_SINGLETON __attribute__((visibility("default")))
  276. # define OPENTELEMETRY_LOCAL_SYMBOL __attribute__((visibility("hidden")))
  277. #else
  278. /* Add support for other compilers here. */
  279. # define OPENTELEMETRY_API_SINGLETON
  280. # define OPENTELEMETRY_LOCAL_SYMBOL
  281. #endif
  282. //
  283. // Atomic wrappers based on compiler intrinsics for memory read/write.
  284. // The tailing number is read/write length in bits.
  285. //
  286. // N.B. Compiler intrinsic is used because the usage of C++ standard library is restricted in the
  287. // OpenTelemetry C++ API.
  288. //
  289. #if defined(__GNUC__)
  290. # define OPENTELEMETRY_ATOMIC_READ_8(ptr) __atomic_load_n(ptr, __ATOMIC_SEQ_CST)
  291. # define OPENTELEMETRY_ATOMIC_WRITE_8(ptr, value) __atomic_store_n(ptr, value, __ATOMIC_SEQ_CST)
  292. #elif defined(_MSC_VER)
  293. # include <intrin.h>
  294. # define OPENTELEMETRY_ATOMIC_READ_8(ptr) \
  295. static_cast<uint8_t>(_InterlockedCompareExchange8(reinterpret_cast<char *>(ptr), 0, 0))
  296. # define OPENTELEMETRY_ATOMIC_WRITE_8(ptr, value) \
  297. _InterlockedExchange8(reinterpret_cast<char *>(ptr), static_cast<char>(value))
  298. #else
  299. # error port atomics read/write for the current platform
  300. #endif
  301. /* clang-format on */
  302. //
  303. // The if/elif order matters here. If both OPENTELEMETRY_BUILD_IMPORT_DLL and
  304. // OPENTELEMETRY_BUILD_EXPORT_DLL are defined, the former takes precedence.
  305. //
  306. // TODO: consider define OPENTELEMETRY_EXPORT for cygwin/gcc, see below link.
  307. // https://gcc.gnu.org/wiki/Visibility#How_to_use_the_new_C.2B-.2B-_visibility_support
  308. //
  309. #if defined(_MSC_VER) && defined(OPENTELEMETRY_BUILD_IMPORT_DLL)
  310. # define OPENTELEMETRY_EXPORT __declspec(dllimport)
  311. #elif defined(_MSC_VER) && defined(OPENTELEMETRY_BUILD_EXPORT_DLL)
  312. # define OPENTELEMETRY_EXPORT __declspec(dllexport)
  313. #else
  314. //
  315. // build OpenTelemetry as static library or not on Windows.
  316. //
  317. # define OPENTELEMETRY_EXPORT
  318. #endif
  319. // OPENTELEMETRY_HAVE_EXCEPTIONS
  320. //
  321. // Checks whether the compiler both supports and enables exceptions. Many
  322. // compilers support a "no exceptions" mode that disables exceptions.
  323. //
  324. // Generally, when OPENTELEMETRY_HAVE_EXCEPTIONS is not defined:
  325. //
  326. // * Code using `throw` and `try` may not compile.
  327. // * The `noexcept` specifier will still compile and behave as normal.
  328. // * The `noexcept` operator may still return `false`.
  329. //
  330. // For further details, consult the compiler's documentation.
  331. #ifndef OPENTELEMETRY_HAVE_EXCEPTIONS
  332. # if defined(__clang__) && ((__clang_major__ * 100) + __clang_minor__) < 306
  333. // Clang < 3.6
  334. // http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro
  335. # if defined(__EXCEPTIONS) && OPENTELEMETRY_HAVE_FEATURE(cxx_exceptions)
  336. # define OPENTELEMETRY_HAVE_EXCEPTIONS 1
  337. # endif // defined(__EXCEPTIONS) && OPENTELEMETRY_HAVE_FEATURE(cxx_exceptions)
  338. # elif OPENTELEMETRY_HAVE_FEATURE(cxx_exceptions)
  339. # define OPENTELEMETRY_HAVE_EXCEPTIONS 1
  340. // Handle remaining special cases and default to exceptions being supported.
  341. # elif !(defined(__GNUC__) && !defined(__EXCEPTIONS) && !defined(__cpp_exceptions)) && \
  342. !(defined(_MSC_VER) && !defined(_CPPUNWIND))
  343. # define OPENTELEMETRY_HAVE_EXCEPTIONS 1
  344. # endif
  345. #endif
  346. #ifndef OPENTELEMETRY_HAVE_EXCEPTIONS
  347. # define OPENTELEMETRY_HAVE_EXCEPTIONS 0
  348. #endif
  349. /*
  350. OPENTELEMETRY_ATTRIBUTE_LIFETIME_BOUND indicates that a resource owned by a function
  351. parameter or implicit object parameter is retained by the return value of the
  352. annotated function (or, for a parameter of a constructor, in the value of the
  353. constructed object). This attribute causes warnings to be produced if a
  354. temporary object does not live long enough.
  355. When applied to a reference parameter, the referenced object is assumed to be
  356. retained by the return value of the function. When applied to a non-reference
  357. parameter (for example, a pointer or a class type), all temporaries
  358. referenced by the parameter are assumed to be retained by the return value of
  359. the function.
  360. See also the upstream documentation:
  361. https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
  362. */
  363. #ifndef OPENTELEMETRY_ATTRIBUTE_LIFETIME_BOUND
  364. # if OPENTELEMETRY_HAVE_CPP_ATTRIBUTE(clang::lifetimebound)
  365. # define OPENTELEMETRY_ATTRIBUTE_LIFETIME_BOUND [[clang::lifetimebound]]
  366. # elif OPENTELEMETRY_HAVE_ATTRIBUTE(lifetimebound)
  367. # define OPENTELEMETRY_ATTRIBUTE_LIFETIME_BOUND __attribute__((lifetimebound))
  368. # else
  369. # define OPENTELEMETRY_ATTRIBUTE_LIFETIME_BOUND
  370. # endif
  371. #endif
  372. // OPENTELEMETRY_HAVE_MEMORY_SANITIZER
  373. //
  374. // MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of
  375. // a compiler instrumentation module and a run-time library.
  376. #ifndef OPENTELEMETRY_HAVE_MEMORY_SANITIZER
  377. # if !defined(__native_client__) && OPENTELEMETRY_HAVE_FEATURE(memory_sanitizer)
  378. # define OPENTELEMETRY_HAVE_MEMORY_SANITIZER 1
  379. # else
  380. # define OPENTELEMETRY_HAVE_MEMORY_SANITIZER 0
  381. # endif
  382. #endif
  383. #if OPENTELEMETRY_HAVE_MEMORY_SANITIZER && OPENTELEMETRY_HAVE_ATTRIBUTE(no_sanitize_memory)
  384. # define OPENTELEMETRY_SANITIZER_NO_MEMORY \
  385. __attribute__((no_sanitize_memory)) // __attribute__((no_sanitize("memory")))
  386. #else
  387. # define OPENTELEMETRY_SANITIZER_NO_MEMORY
  388. #endif
  389. // OPENTELEMETRY_HAVE_THREAD_SANITIZER
  390. //
  391. // ThreadSanitizer (TSan) is a fast data race detector.
  392. #ifndef OPENTELEMETRY_HAVE_THREAD_SANITIZER
  393. # if defined(__SANITIZE_THREAD__)
  394. # define OPENTELEMETRY_HAVE_THREAD_SANITIZER 1
  395. # elif OPENTELEMETRY_HAVE_FEATURE(thread_sanitizer)
  396. # define OPENTELEMETRY_HAVE_THREAD_SANITIZER 1
  397. # else
  398. # define OPENTELEMETRY_HAVE_THREAD_SANITIZER 0
  399. # endif
  400. #endif
  401. #if OPENTELEMETRY_HAVE_THREAD_SANITIZER && OPENTELEMETRY_HAVE_ATTRIBUTE(no_sanitize_thread)
  402. # define OPENTELEMETRY_SANITIZER_NO_THREAD \
  403. __attribute__((no_sanitize_thread)) // __attribute__((no_sanitize("thread")))
  404. #else
  405. # define OPENTELEMETRY_SANITIZER_NO_THREAD
  406. #endif
  407. // OPENTELEMETRY_HAVE_ADDRESS_SANITIZER
  408. //
  409. // AddressSanitizer (ASan) is a fast memory error detector.
  410. #ifndef OPENTELEMETRY_HAVE_ADDRESS_SANITIZER
  411. # if defined(__SANITIZE_ADDRESS__)
  412. # define OPENTELEMETRY_HAVE_ADDRESS_SANITIZER 1
  413. # elif OPENTELEMETRY_HAVE_FEATURE(address_sanitizer)
  414. # define OPENTELEMETRY_HAVE_ADDRESS_SANITIZER 1
  415. # else
  416. # define OPENTELEMETRY_HAVE_ADDRESS_SANITIZER 0
  417. # endif
  418. #endif
  419. // OPENTELEMETRY_HAVE_HWADDRESS_SANITIZER
  420. //
  421. // Hardware-Assisted AddressSanitizer (or HWASAN) is even faster than asan
  422. // memory error detector which can use CPU features like ARM TBI, Intel LAM or
  423. // AMD UAI.
  424. #ifndef OPENTELEMETRY_HAVE_HWADDRESS_SANITIZER
  425. # if defined(__SANITIZE_HWADDRESS__)
  426. # define OPENTELEMETRY_HAVE_HWADDRESS_SANITIZER 1
  427. # elif OPENTELEMETRY_HAVE_FEATURE(hwaddress_sanitizer)
  428. # define OPENTELEMETRY_HAVE_HWADDRESS_SANITIZER 1
  429. # else
  430. # define OPENTELEMETRY_HAVE_HWADDRESS_SANITIZER 0
  431. # endif
  432. #endif
  433. #if OPENTELEMETRY_HAVE_ADDRESS_SANITIZER && OPENTELEMETRY_HAVE_ATTRIBUTE(no_sanitize_address)
  434. # define OPENTELEMETRY_SANITIZER_NO_ADDRESS \
  435. __attribute__((no_sanitize_address)) // __attribute__((no_sanitize("address")))
  436. #elif OPENTELEMETRY_HAVE_ADDRESS_SANITIZER && defined(_MSC_VER) && _MSC_VER >= 1928
  437. # define OPENTELEMETRY_SANITIZER_NO_ADDRESS __declspec(no_sanitize_address)
  438. #elif OPENTELEMETRY_HAVE_HWADDRESS_SANITIZER && OPENTELEMETRY_HAVE_ATTRIBUTE(no_sanitize)
  439. # define OPENTELEMETRY_SANITIZER_NO_ADDRESS __attribute__((no_sanitize("hwaddress")))
  440. #else
  441. # define OPENTELEMETRY_SANITIZER_NO_ADDRESS
  442. #endif