Add VERIFY_ONLY_CHECK that only evaluates in VERIFY mode#902
Add VERIFY_ONLY_CHECK that only evaluates in VERIFY mode#902sipa wants to merge 1 commit intobitcoin-core:masterfrom
Conversation
|
What do you think about this? This a rather hacky but working way to let the compiler error out if it fails to prove that This compiles fine with on current master on clang and gcc with |
|
@real-or-random Ha, nice! But I think we'll still want a macro like this for cases where it can't be optimized out? Or do you think all cases now are actually removed? We'd also need some define to explicitly disable VERIFY_CHECK for -O0 builds. |
I think the fact that master compiles fine with this implies all cases are optimized everywhere.
Indeed. edit: We also may want to make this conditional on clang/gcc to make sure we don't break compilation for people using obscure compilers. |
|
@real-or-random See #904. |
|
Closing in favor of #904. |
The
VERIFY_CHECKmacro still evaluates its argument in non-VERIFY mode, to make sure that in case it has any side effects (intentionally or unintentionally) that are relevant to the code, these also apply in production builds.This isn't always desirable. If nontrivial functions are invoked inside of them the compiler may be unable to optimize the call out, resulting in performance degradation or even the introduction of non-constant-time behavior where that is unexpected.
This adds a new
VERIFY_ONLY_CHECKmacro that does not evaluate its argument (it is still compiled inside anif (0)though to guarantee syntactic correctness), for this purpose, and changes some nontrivial calls to use it.