Here's an example of how this would be used: In the constructor for ConstantVector, there's an assert:<div><br><div><div><div><font class="Apple-style-span" face="'courier new', monospace">  assert(C->getType() == T->getElementType() &&</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">         "Initializer for vector element doesn't match vector element type!");</font></div></div><div><br></div><div>I would change this to:</div>

<br><meta charset="utf-8"><div><div><font class="Apple-style-span" face="'courier new', monospace">  ASSERT_STRM(C->getType() == T->getElementType(),</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    "Initializer for vector element " << I - V.begin() << " with type " <<</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">    C->getType() << " doesn't match vector element type " <<</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    T->getElementType());</font></div>

<meta charset="utf-8"><div><br></div></div><div>With more detailed assertions like this, a much larger class of programmer errors can be diagnosed without having to go into the debugger.</div><div><br></div><div>Because the stream is a raw_ostream, LLVM types and values can easily be printed to the stream without having to convert them to string form.</div>

<div><br></div><div>Based on the suggestions so far, I'm guessing that the macro would look like this:</div><div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace">#include "llvm/Support/raw_ostream.h"</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">namespace llvm {</font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace"><br>

</font></span></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">// This just writes out "Assertion Failed" and the file/line number in</font></span></div>

<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">// a form that IDEs can parse.       </font></span></div><div><font class="Apple-style-span" face="'courier new', monospace">void assertion_prologue(const char * file, unsigned line);</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">// This does the trap or abort or whatever.</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">void assertion_trap();</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">#if NDEBUG</font></div>

<meta charset="utf-8"><div><font class="Apple-style-span" face="'courier new', monospace">  #define LLVM_ASSERT_STRM(expr, args) do {} while false</font></div><div><font class="Apple-style-span" face="'courier new', monospace">  // Alternatively</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">  // #define LLVM_ASSERT_STRM(expr, args) (void)0</font></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace; ">#else</span></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">  /// Assertion macro that acts as an error output stream. Typical usage:</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">  ///</font></div><div><font class="Apple-style-span" face="'courier new', monospace">  ///   LLVM_ASSERT_STRM(a != b, "Expected " << a << " == " << " b")</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">  #define LLVM_ASSERT_STRM(expr, args) \</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre">        </span>  do { if (!(expr)) { \</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">      assertion_prologue(__FILE__, __LINE__); \</font></div><div><font class="Apple-style-span" face="'courier new', monospace">      errs() << args << "\n"; \</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">      assertion_trap(); \</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    } while (false)</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace; ">#endif</span></div></div><div><br></div>

<div><meta charset="utf-8"><div><font class="Apple-style-span" face="'courier new', monospace">/// Assertion macro that behaves like standard C assert().</font></div><div><font class="Apple-style-span" face="'courier new', monospace">#define LLVM_ASSERT(expr) LLVM_LLASSEERT_STRM(expr, #expr)</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">/// Assertion macro that expects two values to be equal, as defined</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">/// by the equality operator.</font></div><div><font class="Apple-style-span" face="'courier new', monospace">#define LLVM_LLASSERT_EQ(expected, actual) \</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace">  LLVM_LLASSEERT_STRM(expected == actual, "Expected: " << expected << \</font></div><div><font class="Apple-style-span" face="'courier new', monospace">                 " but actually was " << actual)</font></div>

<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div>I'm open to suggestions on naming - LLVM_ASSERT_STRM may be a little too verbose, but you have to be careful about name collisions since macros aren't namespaced. In particular I want to avoid any overlap with Google Test, which has a bunch of ASSERT_XXX macros.</div>

<div><br><div class="gmail_quote">On Tue, Jul 26, 2011 at 8:01 PM, Nathan Jeffords <span dir="ltr"><<a href="mailto:blunted2night@gmail.com">blunted2night@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

sorry, my previous message got sent too early<div><br></div><div>I think the macro should look something like this:<br><div><br></div><div>#define ASSERT_STRM(cond,expr) \</div><div> do {</div><div>  if (cond) {</div><div>


    std::cerr << expr << std::end;</div><div>    assertion_trap ();</div><div>  }</div><div> } while (false)<div><div></div><div class="h5"><br><br><div class="gmail_quote">On Tue, Jul 26, 2011 at 7:57 PM, Nathan Jeffords <span dir="ltr"><<a href="mailto:blunted2night@gmail.com" target="_blank">blunted2night@gmail.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">wrapping the macro's body in:<div><br></div><div>do { ... } while (false)</div><div><br></div><div>would make the the macro a proper statement so that:</div>


<div><br></div><div>if (cond)</div><div>  ASSERT(some_other_cond);</div>
<div>else</div><div>  do_something_cool ();</div><div><br></div><div>compiles as expected.</div><div><br></div><div>IMO, it would work as such</div><div><br></div><div>#define ASSERT_STM(cond,expr)</div><div><div></div><div>


<div><br></div><div>
<br><div class="gmail_quote">On Tue, Jul 26, 2011 at 6:36 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:reid.kleckner@gmail.com" target="_blank">reid.kleckner@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



He wants to be able to resume execution from the debugger after<br>
assertion failure.<br>
<font color="#888888"><br>
Reid<br>
</font><div><div></div><div><br>
On Tue, Jul 26, 2011 at 8:07 PM, Alistair Lynn <<a href="mailto:arplynn@gmail.com" target="_blank">arplynn@gmail.com</a>> wrote:<br>
> Hi-<br>
><br>
>> Yep, but tripping the debugger is highly non-portable.<br>
><br>
> You're suggesting that inline asm is more portable than calling abort?<br>
><br>
> Alistair<br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
><br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>-- Talin<br>
</div></div>