Add test profiles that disable all `EMBOSS_CHECK`s. (#211)
This catches cases where C++ code inadvertently includes side effects
inside of an `EMBOSS_CHECK`; the default `EMBOSS_CHECK` uses `assert`,
which will be omitted when `NDEBUG` is defined.
diff --git a/compiler/back_end/cpp/build_defs.bzl b/compiler/back_end/cpp/build_defs.bzl
index a1df7aa..16e0532 100644
--- a/compiler/back_end/cpp/build_defs.bzl
+++ b/compiler/back_end/cpp/build_defs.bzl
@@ -20,14 +20,26 @@
"""Generates cc_test rules with and without -DEMBOSS_NO_OPTIMIZATIONS."""
native.cc_test(
name = name,
- copts = ["-DEMBOSS_FORCE_ALL_CHECKS"] + (copts or []),
+ copts = copts or [],
**kwargs
)
native.cc_test(
name = name + "_no_opts",
copts = [
"-DEMBOSS_NO_OPTIMIZATIONS",
- "-DEMBOSS_FORCE_ALL_CHECKS",
+ ] + ([] if no_w_sign_compare else ["-Wsign-compare"]) + (copts or []),
+ **kwargs
+ )
+ native.cc_test(
+ name = name + "_no_checks",
+ copts = ["-DEMBOSS_SKIP_CHECKS"] + (copts or []),
+ **kwargs
+ )
+ native.cc_test(
+ name = name + "_no_checks_no_opts",
+ copts = [
+ "-DEMBOSS_NO_OPTIMIZATIONS",
+ "-DEMBOSS_SKIP_CHECKS",
] + ([] if no_w_sign_compare else ["-Wsign-compare"]) + (copts or []),
**kwargs
)
diff --git a/runtime/cpp/emboss_defines.h b/runtime/cpp/emboss_defines.h
index 5677874..e247d00 100644
--- a/runtime/cpp/emboss_defines.h
+++ b/runtime/cpp/emboss_defines.h
@@ -66,9 +66,17 @@
//
// By default, checks are only enabled on non-NDEBUG builds. (Note that all
// translation units MUST be built with the same value of NDEBUG!)
+//
+// The EMBOSS_SKIP_CHECKS parameter allows all CHECKs to be compiled out
+// without -DNDEBUG; this is useful for testing.
#if !defined(EMBOSS_CHECK)
+#if defined(EMBOSS_SKIP_CHECKS)
+#define EMBOSS_CHECK(x) ((void)0)
+#define EMBOSS_CHECK_ABORTS false
+#else // !defined(EMBOSS_SKIP_CHECKS)
#define EMBOSS_CHECK(x) assert((x))
#define EMBOSS_CHECK_ABORTS (!(NDEBUG))
+#endif // defined(EMBOSS_SKIP_CHECKS)
#endif // !defined(EMBOSS_CHECK)
#if !defined(EMBOSS_CHECK_ABORTS)