Let FOLLY_SAFE_DCHECK be erased by the optimizer in release builds
Summary: [Folly] Let `FOLLY_SAFE_DCHECK` be erased by the optimizer in release builds. Just like `DCHECK` is erased by the optimizer, not by the preprocessor, in release builds. `assert`, by contrast, is erased by the preprocessor. But the intention here is to mimic `DCHECK`. This makes a difference if the expression uses a parameter or local variable. This way, the AST still sees a use of that parameter or local variable in release builds (the optimizer later removes that use). Rather than the AST not seeing any uses of that parameter or local variable, and consequently the compiler emitting a warning or error that the parameter or local variable is unused. Even so, the expression is never evaluated in release builds. We ensure that by actually using `true || (expr)` as the conditional of our expanded expression in release builds. The `true` comes from `!folly::kIsDebug`, which is a `constexpr bool` expression and is `true` in release builds. The `||` short-circuits; the optimizer sees that the whole expanded expression statically evaluates to `static_cast<void>(0)` and removes it the expanded expression entirely. Reviewed By: simpkins Differential Revision: D3701227 fbshipit-source-id: e4fa48ee5a88e45dc08757c14d1944de734796ff
Showing
Please register or sign in to comment