<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 4/9/20 9:59 AM, Chris Tetreault via
llvm-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:BYAPR02MB45511A506EBFC283CA35003FDAC10@BYAPR02MB4551.namprd02.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal">David,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> In my opinion, NDEBUG is one of those
gross old C things that everybody complains about. It’s called
“Not Debug”, but really it means “Assert Disabled”. I think
one could be forgiven for actually using it as a heuristic of
whether or not a build is a debug build, especially since no
other options are provided. I appreciate your desire, but I
think it’d be unfortunate if the build system grew yet another
flag to control debugness.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> As far as I can tell, as it currently
works, LLVM_ENABLE_ASSERTIONS just makes sure that NDEBUG is
not defined, even in release builds. So if I do
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=TRUE, I’ll
get an optimized build with no debug symbols but with asserts
enabled, which in my mind isn’t a terribly useful thing to
have. </p>
</div>
</blockquote>
<p>(Completely ignoring rest of thread context. Replying to
previous sentence in isolation.)</p>
<p>A Release+Asserts build is an *incredibly* useful thing to have.
It's generally the only configuration I build. It's fast enough
to not be obviously painfully slow, several times faster to build
than a debug build, takes *much* less space on disk, and yet
reports assertion failures.<br>
</p>
<blockquote type="cite"
cite="mid:BYAPR02MB45511A506EBFC283CA35003FDAC10@BYAPR02MB4551.namprd02.prod.outlook.com">
<div class="WordSection1">
<p class="MsoNormal">Furthermore, none of this works on Visual
Studio because it has a UI menu to control the build type. I
personally would be very disappointed to see Visual Studio’s
build type dropdown break.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> Since we C’s assert, it is intrinsically
tied to NDEBUG. What we need is proper custom asserts. In
codebases I’ve seen in my travels that have this it usually
looks like:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Courier New"">//
If asserts are enabled, evaluate and assert that expr is
truthy. If it is not, complain with msg.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Courier New"">LLVM_ASSERT(expr,
msg)<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Courier New"">//
If asserts are enabled, evaluate and assert that expr is
truthy. If it is not, complain with msg.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Courier New"">//
If asserts are disabled, evaluate expr, do not assert.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Courier New"">//
either way, return expr<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Courier New"">LLVM_VERIFY(expr,
msg)<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> The first one is useful as a traditional
assert. The second one is useful if you are calling a
function, and want to assert that it succeeds, but still need
it to be evaluated in release builds:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Courier New"">auto
*Foo =
LLVM_VERIFY(ReturnsAPointerThatShouldNeverActuallyBeNull(),
“this should never return null”);<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> If we have custom asserts, then we can
have custom assert guard macros:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Courier New"">//
true if this is any sort of debug build<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Courier New"">LLVM_DEBUG_BUILD<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Courier New"">//
true if asserts are turned on (Debug build on Windows,<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Courier New"">//
Debug build or -DLLVM_ASSERTIONS_ENABLED=TRUE on other
platforms)<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.0pt;font-family:"Courier New"">LLVM_ASSERTS_ENABLED<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> These flags could be derived from just
CMAKE_BUILD_TYPE, and LLVM_ENABLE_ASSERTIONS can go away
(assuming we agree that an asserting build with optimizations
and no debug info is worse than useless). Custom asserts also
have the advantage of having a proper message parameter and
not needing to rely on the truthiness of string literals.
Obviously this is a much more invasive change than what you
are proposing, but in my opinion it’s the correct thing to do.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal"> Christopher Tetreault<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> llvm-dev
<a class="moz-txt-link-rfc2396E" href="mailto:llvm-dev-bounces@lists.llvm.org"><llvm-dev-bounces@lists.llvm.org></a> <b>On Behalf Of
</b>David Truby via llvm-dev<br>
<b>Sent:</b> Thursday, April 9, 2020 7:26 AM<br>
<b>To:</b> <a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> [EXT] [llvm-dev] [RFC] Usage of NDEBUG as
a guard for non-assert debug code<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><span
style="font-size:12.0pt;color:black">Hi all,<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-size:12.0pt;color:black">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. <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-size:12.0pt;color:black">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.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-size:12.0pt;color:black">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. <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-size:12.0pt;color:black">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.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-size:12.0pt;color:black">Does anyone else have
any thoughts on this?<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-size:12.0pt;color:black">Thanks<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-size:12.0pt;color:black">David Truby<o:p></o:p></span></p>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
</body>
</html>