[LLVMdev] Proposal for better assertions in LLVM
Talin
viridia at gmail.com
Wed Jul 27 00:34:59 PDT 2011
On Tue, Jul 26, 2011 at 10:59 PM, Chris Lattner <clattner at apple.com> wrote:
>
> On Jul 26, 2011, at 9:17 PM, Talin wrote:
>
> Here's an example of how this would be used: In the constructor for
> ConstantVector, there's an assert:
>
> assert(C->getType() == T->getElementType() &&
> "Initializer for vector element doesn't match vector element
> type!");
>
> I would change this to:
>
> ASSERT_STRM(C->getType() == T->getElementType(),
> "Initializer for vector element " << I - V.begin() << " with type " <<
> C->getType() << " doesn't match vector element type " <<
> T->getElementType());
>
> With more detailed assertions like this, a much larger class of programmer
> errors can be diagnosed without having to go into the debugger.
>
> 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.
>
>
> I'm unconvinced that this is worth it at all. This is only going to allow
> you to "avoid going into the debugger" in the most trivial cases.
>
> From an API user's perspective, those trivial cases happen quite
frequently, at least in my experience. Often times I only need to know what
type is involved to figure out what went wrong.
-Chris
>
--
-- Talin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110727/3cc5cf1e/attachment.html>
More information about the llvm-dev
mailing list