[LLVMdev] Suggestion: include object data in assertion messages

someguy just.s0m3.guy at gmail.com
Fri Mar 13 04:17:37 PDT 2009


Thats good... but the NDEBUG region gets printed even if the assertion passes.

Ideally, a printf-style format string would be better. That way you
get info relevant to your assertion, with your assertion.

On Thu, Mar 12, 2009 at 6:15 PM, Chris Lattner <clattner at apple.com> wrote:
>
> On Mar 12, 2009, at 1:47 AM, someguy wrote:
>> However, assertion messages are static strings, and don't include any
>> information about the particular object/value which caused the
>> assertion. In a 'data oriented' system like llvm, this makes it really
>> difficult to pinpoint which node is actually triggering the assertion.
>>
>> For example, in ScheduleDAGSDNodesEmit.cpp
>> (lib/CodeGen/SelectionDAG/), in the ScheduleDAGSDNodes::AddOperand
>> method, there is the following assert:
>
> The typical idiom we use for this are things like:
>
> Value::~Value() {
> #ifndef NDEBUG      // Only in -g mode...
>   // Check to make sure that there are no uses of this value that are
> still
>   // around when the value is destroyed.  If there are, then we have
> a dangling
>   // reference and something is wrong.  This code is here to print
> out what is
>   // still being referenced.  The value in question should be printed
> as
>   // a <badref>
>   //
>   if (!use_empty()) {
>     cerr << "While deleting: " << *VTy << " %" << getNameStr() << "\n";
>     for (use_iterator I = use_begin(), E = use_end(); I != E; ++I)
>       cerr << "Use still stuck around after Def is destroyed:"
>            << **I << "\n";
>   }
> #endif
>   assert(use_empty() && "Uses remain when a value is destroyed!");
>
>
> This lets you do anything you want before crashing.
>
> -Chris
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>




More information about the llvm-dev mailing list