1
0

simde-diagnostic.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* SPDX-License-Identifier: MIT
  2. *
  3. * Permission is hereby granted, free of charge, to any person
  4. * obtaining a copy of this software and associated documentation
  5. * files (the "Software"), to deal in the Software without
  6. * restriction, including without limitation the rights to use, copy,
  7. * modify, merge, publish, distribute, sublicense, and/or sell copies
  8. * of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be
  12. * included in all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  18. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  19. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. *
  23. * Copyright:
  24. * 2017-2020 Evan Nemerson <[email protected]>
  25. */
  26. /* SIMDe targets a very wide range of standards and compilers, and our
  27. * goal is to compile cleanly even with extremely aggressive warnings
  28. * (i.e., -Weverything in clang, -Wextra in GCC, /W4 for MSVC, etc.)
  29. * treated as errors.
  30. *
  31. * While our preference is to resolve the underlying issue a given
  32. * diagnostic is warning us about, sometimes that's not possible.
  33. * Fixing a warning in one compiler may cause problems in another.
  34. * Sometimes a warning doesn't really apply to us (false positives),
  35. * and sometimes adhering to a warning would mean dropping a feature
  36. * we *know* the compiler supports since we have tested specifically
  37. * for the compiler or feature.
  38. *
  39. * When practical, warnings are only disabled for specific code. For
  40. * a list of warnings which are enabled by default in all SIMDe code,
  41. * see SIMDE_DISABLE_UNWANTED_DIAGNOSTICS. Note that we restore the
  42. * warning stack when SIMDe is done parsing, so code which includes
  43. * SIMDe is not deprived of these warnings.
  44. */
  45. #if !defined(SIMDE_DIAGNOSTIC_H)
  46. #include "hedley.h"
  47. /* This is only to help us implement functions like _mm_undefined_ps. */
  48. #if defined(SIMDE_DIAGNOSTIC_DISABLE_UNINITIALIZED_)
  49. #undef SIMDE_DIAGNOSTIC_DISABLE_UNINITIALIZED_
  50. #endif
  51. #if HEDLEY_HAS_WARNING("-Wuninitialized")
  52. #define SIMDE_DIAGNOSTIC_DISABLE_UNINITIALIZED_ \
  53. _Pragma("clang diagnostic ignored \"-Wuninitialized\"")
  54. #elif HEDLEY_GCC_VERSION_CHECK(4, 2, 0)
  55. #define SIMDE_DIAGNOSTIC_DISABLE_UNINITIALIZED_ \
  56. _Pragma("GCC diagnostic ignored \"-Wuninitialized\"")
  57. #elif HEDLEY_PGI_VERSION_CHECK(19, 10, 0)
  58. #define SIMDE_DIAGNOSTIC_DISABLE_UNINITIALIZED_ _Pragma("diag_suppress 549")
  59. #elif HEDLEY_SUNPRO_VERSION_CHECK(5, 14, 0) && defined(__cplusplus)
  60. #define SIMDE_DIAGNOSTIC_DISABLE_UNINITIALIZED_ \
  61. _Pragma("error_messages(off,SEC_UNINITIALIZED_MEM_READ,SEC_UNDEFINED_RETURN_VALUE,unassigned)")
  62. #elif HEDLEY_SUNPRO_VERSION_CHECK(5, 14, 0)
  63. #define SIMDE_DIAGNOSTIC_DISABLE_UNINITIALIZED_ \
  64. _Pragma("error_messages(off,SEC_UNINITIALIZED_MEM_READ,SEC_UNDEFINED_RETURN_VALUE)")
  65. #elif HEDLEY_SUNPRO_VERSION_CHECK(5, 12, 0) && defined(__cplusplus)
  66. #define SIMDE_DIAGNOSTIC_DISABLE_UNINITIALIZED_ \
  67. _Pragma("error_messages(off,unassigned)")
  68. #elif HEDLEY_TI_VERSION_CHECK(16, 9, 9) || \
  69. HEDLEY_TI_CL6X_VERSION_CHECK(8, 0, 0) || \
  70. HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
  71. HEDLEY_TI_CLPRU_VERSION_CHECK(2, 3, 2)
  72. #define SIMDE_DIAGNOSTIC_DISABLE_UNINITIALIZED_ _Pragma("diag_suppress 551")
  73. #elif HEDLEY_INTEL_VERSION_CHECK(13, 0, 0)
  74. #define SIMDE_DIAGNOSTIC_DISABLE_UNINITIALIZED_ _Pragma("warning(disable:592)")
  75. #elif HEDLEY_MSVC_VERSION_CHECK(19, 0, 0) && !defined(__MSVC_RUNTIME_CHECKS)
  76. #define SIMDE_DIAGNOSTIC_DISABLE_UNINITIALIZED_ \
  77. __pragma(warning(disable : 4700))
  78. #endif
  79. /* GCC emits a lot of "notes" about the ABI being different for things
  80. * in newer versions of GCC. We don't really care because all our
  81. * functions are inlined and don't generate ABI. */
  82. #if HEDLEY_GCC_VERSION_CHECK(7, 0, 0)
  83. #define SIMDE_DIAGNOSTIC_DISABLE_PSABI_ \
  84. _Pragma("GCC diagnostic ignored \"-Wpsabi\"")
  85. #else
  86. #define SIMDE_DIAGNOSTIC_DISABLE_PSABI_
  87. #endif
  88. /* Since MMX uses x87 FP registers, you're supposed to call _mm_empty()
  89. * after each MMX function before any floating point instructions.
  90. * Some compilers warn about functions which use MMX functions but
  91. * don't call _mm_empty(). However, since SIMDe is implementyng the
  92. * MMX API we shouldn't be calling _mm_empty(); we leave it to the
  93. * caller to invoke simde_mm_empty(). */
  94. #if HEDLEY_INTEL_VERSION_CHECK(19, 0, 0)
  95. #define SIMDE_DIAGNOSTIC_DISABLE_NO_EMMS_INSTRUCTION_ \
  96. _Pragma("warning(disable:13200 13203)")
  97. #elif defined(HEDLEY_MSVC_VERSION)
  98. #define SIMDE_DIAGNOSTIC_DISABLE_NO_EMMS_INSTRUCTION_ \
  99. __pragma(warning(disable : 4799))
  100. #else
  101. #define SIMDE_DIAGNOSTIC_DISABLE_NO_EMMS_INSTRUCTION_
  102. #endif
  103. /* Intel is pushing people to use OpenMP SIMD instead of Cilk+, so they
  104. * emit a diagnostic if you use #pragma simd instead of
  105. * #pragma omp simd. SIMDe supports OpenMP SIMD, you just need to
  106. * compile with -qopenmp or -qopenmp-simd and define
  107. * SIMDE_ENABLE_OPENMP. Cilk+ is just a fallback. */
  108. #if HEDLEY_INTEL_VERSION_CHECK(18, 0, 0)
  109. #define SIMDE_DIAGNOSTIC_DISABLE_SIMD_PRAGMA_DEPRECATED_ \
  110. _Pragma("warning(disable:3948)")
  111. #else
  112. #define SIMDE_DIAGNOSTIC_DISABLE_SIMD_PRAGMA_DEPRECATED_
  113. #endif
  114. #if defined(HEDLEY_MSVC_VERSION)
  115. #define SIMDE_DIAGNOSTIC_DISABLE_NON_CONSTANT_AGGREGATE_INITIALIZER_ \
  116. __pragma(warning(disable : 4204))
  117. #else
  118. #define SIMDE_DIAGNOSTIC_DISABLE_NON_CONSTANT_AGGREGATE_INITIALIZER_
  119. #endif
  120. /* This warning needs a lot of work. It is triggered if all you do is
  121. * pass the value to memcpy/__builtin_memcpy, or if you initialize a
  122. * member of the union, even if that member takes up the entire union.
  123. * Last tested with clang-10, hopefully things will improve in the
  124. * future; if clang fixes this I'd love to enable it. */
  125. #if HEDLEY_HAS_WARNING("-Wconditional-uninitialized")
  126. #define SIMDE_DIAGNOSTIC_DISABLE_CONDITIONAL_UNINITIALIZED_ \
  127. _Pragma("clang diagnostic ignored \"-Wconditional-uninitialized\"")
  128. #else
  129. #define SIMDE_DIAGNOSTIC_DISABLE_CONDITIONAL_UNINITIALIZED_
  130. #endif
  131. /* This warning is meant to catch things like `0.3 + 0.4 == 0.7`, which
  132. * will is false. However, SIMDe uses these operations exclusively
  133. * for things like _mm_cmpeq_ps, for which we really do want to check
  134. * for equality (or inequality).
  135. *
  136. * If someone wants to put together a SIMDE_FLOAT_EQUAL(a, op, b) macro
  137. * which just wraps a check in some code do disable this diagnostic I'd
  138. * be happy to accept it. */
  139. #if HEDLEY_HAS_WARNING("-Wfloat-equal") || HEDLEY_GCC_VERSION_CHECK(3, 0, 0)
  140. #define SIMDE_DIAGNOSTIC_DISABLE_FLOAT_EQUAL_ \
  141. _Pragma("GCC diagnostic ignored \"-Wfloat-equal\"")
  142. #else
  143. #define SIMDE_DIAGNOSTIC_DISABLE_FLOAT_EQUAL_
  144. #endif
  145. /* This is because we use HEDLEY_STATIC_ASSERT for static assertions.
  146. * If Hedley can't find an implementation it will preprocess to
  147. * nothing, which means there will be a trailing semi-colon. */
  148. #if HEDLEY_HAS_WARNING("-Wextra-semi")
  149. #define SIMDE_DIAGNOSTIC_DISABLE_EXTRA_SEMI_ \
  150. _Pragma("clang diagnostic ignored \"-Wextra-semi\"")
  151. #elif HEDLEY_GCC_VERSION_CHECK(8, 1, 0) && defined(__cplusplus)
  152. #define SIMDE_DIAGNOSTIC_DISABLE_EXTRA_SEMI_ \
  153. _Pragma("GCC diagnostic ignored \"-Wextra-semi\"")
  154. #else
  155. #define SIMDE_DIAGNOSTIC_DISABLE_EXTRA_SEMI_
  156. #endif
  157. /* We do use a few variadic macros, which technically aren't available
  158. * until C99 and C++11, but every compiler I'm aware of has supported
  159. * them for much longer. That said, usage is isolated to the test
  160. * suite and compilers known to support them. */
  161. #if HEDLEY_HAS_WARNING("-Wvariadic-macros") || HEDLEY_GCC_VERSION_CHECK(4, 0, 0)
  162. #if HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic")
  163. #define SIMDE_DIAGNOSTIC_DISABLE_VARIADIC_MACROS_ \
  164. _Pragma("clang diagnostic ignored \"-Wvariadic-macros\"") _Pragma( \
  165. "clang diagnostic ignored \"-Wc++98-compat-pedantic\"")
  166. #else
  167. #define SIMDE_DIAGNOSTIC_DISABLE_VARIADIC_MACROS_ \
  168. _Pragma("GCC diagnostic ignored \"-Wvariadic-macros\"")
  169. #endif
  170. #else
  171. #define SIMDE_DIAGNOSTIC_DISABLE_VARIADIC_MACROS_
  172. #endif
  173. /* Triggered when assigning a float to a double implicitly. We use
  174. * explicit casts in SIMDe, this is only used in the test suite. */
  175. #if HEDLEY_HAS_WARNING("-Wdouble-promotion")
  176. #define SIMDE_DIAGNOSTIC_DISABLE_DOUBLE_PROMOTION_ \
  177. _Pragma("clang diagnostic ignored \"-Wdouble-promotion\"")
  178. #else
  179. #define SIMDE_DIAGNOSTIC_DISABLE_DOUBLE_PROMOTION_
  180. #endif
  181. /* Several compilers treat conformant array parameters as VLAs. We
  182. * test to make sure we're in C mode (C++ doesn't support CAPs), and
  183. * that the version of the standard supports CAPs. We also blacklist
  184. * some buggy compilers like MSVC (the logic is in Hedley if you want
  185. * to take a look), but with certain warnings enabled some compilers
  186. * still like to emit a diagnostic. */
  187. #if HEDLEY_HAS_WARNING("-Wvla")
  188. #define SIMDE_DIAGNOSTIC_DISABLE_VLA_ \
  189. _Pragma("clang diagnostic ignored \"-Wvla\"")
  190. #elif HEDLEY_GCC_VERSION_CHECK(4, 3, 0)
  191. #define SIMDE_DIAGNOSTIC_DISABLE_VLA_ \
  192. _Pragma("GCC diagnostic ignored \"-Wvla\"")
  193. #else
  194. #define SIMDE_DIAGNOSTIC_DISABLE_VLA_
  195. #endif
  196. #if HEDLEY_HAS_WARNING("-Wused-but-marked-unused")
  197. #define SIMDE_DIAGNOSTIC_DISABLE_USED_BUT_MARKED_UNUSED_ \
  198. _Pragma("clang diagnostic ignored \"-Wused-but-marked-unused\"")
  199. #else
  200. #define SIMDE_DIAGNOSTIC_DISABLE_USED_BUT_MARKED_UNUSED_
  201. #endif
  202. #if HEDLEY_HAS_WARNING("-Wunused-function")
  203. #define SIMDE_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION_ \
  204. _Pragma("clang diagnostic ignored \"-Wunused-function\"")
  205. #elif HEDLEY_GCC_VERSION_CHECK(3, 4, 0)
  206. #define SIMDE_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION_ \
  207. _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
  208. #else
  209. #define SIMDE_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION_
  210. #endif
  211. #if HEDLEY_HAS_WARNING("-Wpass-failed")
  212. #define SIMDE_DIAGNOSTIC_DISABLE_PASS_FAILED_ \
  213. _Pragma("clang diagnostic ignored \"-Wpass-failed\"")
  214. #else
  215. #define SIMDE_DIAGNOSTIC_DISABLE_PASS_FAILED_
  216. #endif
  217. /* https://github.com/nemequ/simde/issues/277 */
  218. #if defined(HEDLEY_GCC_VERSION) && HEDLEY_GCC_VERSION_CHECK(4, 6, 0) && \
  219. !HEDLEY_GCC_VERSION_CHECK(6, 0, 0) && defined(__cplusplus)
  220. #define SIMDE_DIAGNOSTIC_DISABLE_BUGGY_UNUSED_BUT_SET_VARIBALE \
  221. _Pragma("GCC diagnostic ignored \"-Wunused-but-set-variable\"")
  222. #else
  223. #define SIMDE_DIAGNOSTIC_DISABLE_BUGGY_UNUSED_BUT_SET_VARIBALE
  224. #endif
  225. /* Some compilers, such as clang, may use `long long` for 64-bit
  226. * integers, but `long long` triggers a diagnostic with
  227. * -Wc++98-compat-pedantic which says 'long long' is incompatible with
  228. * C++98. */
  229. #if HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic")
  230. #define SIMDE_DIAGNOSTIC_DISABLE_CPP98_COMPAT_PEDANTIC \
  231. _Pragma("clang diagnostic ignored \"-Wc++98-compat-pedantic\"")
  232. #else
  233. #define SIMDE_DIAGNOSTIC_DISABLE_CPP98_COMPAT_PEDANTIC
  234. #endif
  235. #define SIMDE_DISABLE_UNWANTED_DIAGNOSTICS \
  236. SIMDE_DIAGNOSTIC_DISABLE_PSABI_ \
  237. SIMDE_DIAGNOSTIC_DISABLE_NO_EMMS_INSTRUCTION_ \
  238. SIMDE_DIAGNOSTIC_DISABLE_SIMD_PRAGMA_DEPRECATED_ \
  239. SIMDE_DIAGNOSTIC_DISABLE_CONDITIONAL_UNINITIALIZED_ \
  240. SIMDE_DIAGNOSTIC_DISABLE_FLOAT_EQUAL_ \
  241. SIMDE_DIAGNOSTIC_DISABLE_NON_CONSTANT_AGGREGATE_INITIALIZER_ \
  242. SIMDE_DIAGNOSTIC_DISABLE_EXTRA_SEMI_ \
  243. SIMDE_DIAGNOSTIC_DISABLE_VLA_ \
  244. SIMDE_DIAGNOSTIC_DISABLE_USED_BUT_MARKED_UNUSED_ \
  245. SIMDE_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION_ \
  246. SIMDE_DIAGNOSTIC_DISABLE_PASS_FAILED_ \
  247. SIMDE_DIAGNOSTIC_DISABLE_CPP98_COMPAT_PEDANTIC \
  248. SIMDE_DIAGNOSTIC_DISABLE_BUGGY_UNUSED_BUT_SET_VARIBALE
  249. #endif