<div dir="ltr">Hi David,<br><br><div>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.</div><div><br></div><div>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 <a href="https://crbug.com/896306#c27">https://crbug.com/896306#c27</a>.</div><div><br></div><div>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. </div><div><br></div><div>Reid</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 9, 2020 at 7:26 AM David Truby via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">




<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Hi all,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
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.
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
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.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
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 enabled.
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
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.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Does anyone else have any thoughts on this?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Thanks</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
David Truby</div>
</div>

_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>