[llvm-dev] [RFC] Usage of NDEBUG as a guard for non-assert debug code
Reid Kleckner via llvm-dev
llvm-dev at lists.llvm.org
Thu Apr 9 09:57:04 PDT 2020
It's true, there are many development-only features guarded by ifndef
NDEBUG in LLVM and Clang. Generally, I think LLVM prefers to have as few
configure-time compilation modes as possible. The existing alternative
build modes of "expensive checks" and "ABI breaking checks" are already
expensive enough to maintain.
I would caution you that, in our experience in Chromium, we found that
assertions add ~25% to compile time, so shipping with assertions enabled is
not a small performance hit. Hans Wennborg did some experiments, and he
found that the highest overhead asserts also have the highest value (mostly
type casting asserts). See the details in https://crbug.com/896306#c27.
Given how expensive the assertions are by themselves, I suggest that you
either accept the cost of the additional features enabled with assertions
(dbgs etc), or ship without assertions.
On Thu, Apr 9, 2020 at 7:26 AM David Truby via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> Hi all,
> During discussions about assertions in the Flang project, we noticed that
> there are a lot of cases in LLVM that #ifndef NDEBUG is used as a guard for
> non-assert code that we want enabled in debug builds.
> This works fine on its own, however it affects the behaviour of
> LLVM_ENABLE_ASSERTIONS; since NDEBUG controls whether assertions are
> enabled or not, a lot of debug code gets enabled in addition to asserts if
> you specify this flag. This goes contrary to the name of the flag I believe
> also its intention. Specifically in Flang we have a case where someone
> wants to ship a build with assertions enabled, but doesn't want to drag in
> all the extra things that are controlled by NDEBUG in LLVM.
> In my opinion we ideally want LLVM_ENABLE_ASSERTIONS to _only_ enable
> assertions and do nothing else. I don't think this is possible without
> changing the use of NDEBUG elsewhere as NDEBUG controls whether assert is
> I propose we should be using another macro (something like
> LLVM_DEBUG_CHECKS ?) that is enabled in Debug builds, and possibly
> controlled by another cmake flag (LLVM_ENABLE_DEBUG_CHECKS ?) for code that
> we want enabled for debugging but not in releases. This would allow
> LLVM_ENABLE_ASSERTIONS to do what it says on the tin and actually enable
> assertions only.
> Does anyone else have any thoughts on this?
> David Truby
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev