[LLVMdev] Suggestion: include object data in assertion messages

Chris Lattner clattner at apple.com
Thu Mar 12 09:15:33 PDT 2009


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



More information about the llvm-dev mailing list