Skip to content

Commit

Permalink
Add test profiles that disable all EMBOSS_CHECKs. (#211)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
reventlov authored Nov 20, 2024
1 parent 73cbd98 commit d7c0ba3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
16 changes: 14 additions & 2 deletions compiler/back_end/cpp/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,26 @@ def emboss_cc_test(name, copts = None, no_w_sign_compare = False, **kwargs):
"""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
)
8 changes: 8 additions & 0 deletions runtime/cpp/emboss_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d7c0ba3

Please sign in to comment.