Skip to content

Commit d7c0ba3

Browse files
authored
Add test profiles that disable all EMBOSS_CHECKs. (#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.
1 parent 73cbd98 commit d7c0ba3

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

compiler/back_end/cpp/build_defs.bzl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,26 @@ def emboss_cc_test(name, copts = None, no_w_sign_compare = False, **kwargs):
2020
"""Generates cc_test rules with and without -DEMBOSS_NO_OPTIMIZATIONS."""
2121
native.cc_test(
2222
name = name,
23-
copts = ["-DEMBOSS_FORCE_ALL_CHECKS"] + (copts or []),
23+
copts = copts or [],
2424
**kwargs
2525
)
2626
native.cc_test(
2727
name = name + "_no_opts",
2828
copts = [
2929
"-DEMBOSS_NO_OPTIMIZATIONS",
30-
"-DEMBOSS_FORCE_ALL_CHECKS",
30+
] + ([] if no_w_sign_compare else ["-Wsign-compare"]) + (copts or []),
31+
**kwargs
32+
)
33+
native.cc_test(
34+
name = name + "_no_checks",
35+
copts = ["-DEMBOSS_SKIP_CHECKS"] + (copts or []),
36+
**kwargs
37+
)
38+
native.cc_test(
39+
name = name + "_no_checks_no_opts",
40+
copts = [
41+
"-DEMBOSS_NO_OPTIMIZATIONS",
42+
"-DEMBOSS_SKIP_CHECKS",
3143
] + ([] if no_w_sign_compare else ["-Wsign-compare"]) + (copts or []),
3244
**kwargs
3345
)

runtime/cpp/emboss_defines.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,17 @@
6666
//
6767
// By default, checks are only enabled on non-NDEBUG builds. (Note that all
6868
// translation units MUST be built with the same value of NDEBUG!)
69+
//
70+
// The EMBOSS_SKIP_CHECKS parameter allows all CHECKs to be compiled out
71+
// without -DNDEBUG; this is useful for testing.
6972
#if !defined(EMBOSS_CHECK)
73+
#if defined(EMBOSS_SKIP_CHECKS)
74+
#define EMBOSS_CHECK(x) ((void)0)
75+
#define EMBOSS_CHECK_ABORTS false
76+
#else // !defined(EMBOSS_SKIP_CHECKS)
7077
#define EMBOSS_CHECK(x) assert((x))
7178
#define EMBOSS_CHECK_ABORTS (!(NDEBUG))
79+
#endif // defined(EMBOSS_SKIP_CHECKS)
7280
#endif // !defined(EMBOSS_CHECK)
7381

7482
#if !defined(EMBOSS_CHECK_ABORTS)

0 commit comments

Comments
 (0)