<div dir="ltr">I thought NDEBUG was what the assert macro also used to decide whether to be an assert or not.</div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div>
<br><div class="gmail_quote">On Wed, Oct 4, 2017 at 2:41 PM, Quentin Colombet via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">Hi,<div><br></div><div>While audit our code, we found out a strange pattern in one of the LLVM headers and we were wondering if that was expected or if it should be fixed.</div><div><br></div><div>Namely the problem looks like this:</div><div><font face="Menlo" style="font-size:11px">#ifndef NDEBUG</font></div><div><font face="Menlo" style="font-size:11px">  // Define some variable.</font></div><div><font face="Menlo" style="font-size:11px">#endif</font></div><div><font face="Menlo" style="font-size:11px"><br></font></div><div><font face="Menlo" style="font-size:11px">assert(/*use this variable, i.e., outside of the ifndef NDEBUG scope*/);</font></div><div><br></div><div>This happens in <span style="font-family:Menlo;font-size:11px;background-color:rgb(255,255,255)">include/llvm/IR/<wbr>ValueHandle.h </span>for the variable <span style="font-family:Menlo;font-size:11px;background-color:rgb(255,255,255)">Poisoned </span>line 494</div><div><br></div><div>This works because when we build LLVM with assert we explicitly disable NDEBUG:</div><div><div><font face="Menlo" style="font-size:11px">if( LLVM_ENABLE_ASSERTIONS )</font></div><div><font face="Menlo" style="font-size:11px">  […]</font></div><div><font face="Menlo" style="font-size:11px">  # On non-Debug builds cmake automatically defines NDEBUG, so we</font></div><div><font face="Menlo" style="font-size:11px">  # explicitly undefine it:</font></div><div><font face="Menlo" style="font-size:11px">  if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )</font></div><div><font face="Menlo" style="font-size:11px">    add_definitions( -UNDEBUG )</font></div></div><div><br></div><div>If we use this header in a different project and thus, with potentially different rules for macro definitions, the compiler complains with</div><div><div><font face="Menlo"><span style="font-size:11px">error:   use of undeclared identifier ‘Poisoned'</span></font></div></div><div><font face="Menlo" style="font-size:11px"><br></font></div><div>I think the right thing to do is to fix the code to work without the special way of setting the macros, but I’d like people opinions first.</div><div><br></div><div>Thanks,</div><div>-Quentin</div></div><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>