tint: Add Checked[Add|Mul|Madd]()

Test-for-overflow utilities for AInt.

Bug: tint:1504
Change-Id: I974ef829c72aaa4c2012550855227f71d4a370a0
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91700
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
Ben Clayton
2022-05-31 13:14:29 +00:00
committed by Dawn LUCI CQ
parent fa5cd029d1
commit 61537d3f57
3 changed files with 322 additions and 37 deletions

View File

@@ -20,23 +20,63 @@
#define TINT_REQUIRE_SEMICOLON static_assert(true)
#if defined(_MSC_VER)
#define TINT_WARNING_UNREACHABLE_CODE 4702
#define TINT_WARNING_CONSTANT_OVERFLOW 4756
////////////////////////////////////////////////////////////////////////////////
// MSVC
////////////////////////////////////////////////////////////////////////////////
#define TINT_DISABLE_WARNING_CONSTANT_OVERFLOW __pragma(warning(disable : 4756))
#define TINT_DISABLE_WARNING_MAYBE_UNINITIALIZED /* currently no-op */
#define TINT_DISABLE_WARNING_UNREACHABLE_CODE __pragma(warning(disable : 4702))
// clang-format off
#define TINT_BEGIN_DISABLE_WARNING(name) \
__pragma(warning(push)) \
__pragma(warning(disable:TINT_CONCAT(TINT_WARNING_, name))) \
#define TINT_BEGIN_DISABLE_WARNING(name) \
__pragma(warning(push)) \
TINT_CONCAT(TINT_DISABLE_WARNING_, name) \
TINT_REQUIRE_SEMICOLON
#define TINT_END_DISABLE_WARNING(name) \
__pragma(warning(pop)) \
#define TINT_END_DISABLE_WARNING(name) \
__pragma(warning(pop)) \
TINT_REQUIRE_SEMICOLON
// clang-format on
#elif defined(__clang__)
////////////////////////////////////////////////////////////////////////////////
// Clang
////////////////////////////////////////////////////////////////////////////////
#define TINT_DISABLE_WARNING_CONSTANT_OVERFLOW /* currently no-op */
#define TINT_DISABLE_WARNING_MAYBE_UNINITIALIZED /* currently no-op */
#define TINT_DISABLE_WARNING_UNREACHABLE_CODE /* currently no-op */
// clang-format off
#define TINT_BEGIN_DISABLE_WARNING(name) \
_Pragma("clang diagnostic push") \
TINT_CONCAT(TINT_DISABLE_WARNING_, name) \
TINT_REQUIRE_SEMICOLON
#define TINT_END_DISABLE_WARNING(name) \
_Pragma("clang diagnostic pop") \
TINT_REQUIRE_SEMICOLON
// clang-format on
#elif defined(__GNUC__)
////////////////////////////////////////////////////////////////////////////////
// GCC
////////////////////////////////////////////////////////////////////////////////
#define TINT_DISABLE_WARNING_CONSTANT_OVERFLOW /* currently no-op */
#define TINT_DISABLE_WARNING_MAYBE_UNINITIALIZED \
_Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
#define TINT_DISABLE_WARNING_UNREACHABLE_CODE /* currently no-op */
// clang-format off
#define TINT_BEGIN_DISABLE_WARNING(name) \
_Pragma("GCC diagnostic push") \
TINT_CONCAT(TINT_DISABLE_WARNING_, name) \
TINT_REQUIRE_SEMICOLON
#define TINT_END_DISABLE_WARNING(name) \
_Pragma("GCC diagnostic pop") \
TINT_REQUIRE_SEMICOLON
// clang-format on
#else
// clang-format off
////////////////////////////////////////////////////////////////////////////////
// Other
////////////////////////////////////////////////////////////////////////////////
#define TINT_BEGIN_DISABLE_WARNING(name) TINT_REQUIRE_SEMICOLON
#define TINT_END_DISABLE_WARNING(name) TINT_REQUIRE_SEMICOLON
// clang-format on
#endif // defined(_MSC_VER)
#endif
#endif // SRC_TINT_UTILS_COMPILER_MACROS_H_