[LLVMdev] Semi-random crashes seemingly related to Arguments

Chris Lattner sabre at nondot.org
Tue Jan 23 11:33:30 PST 2007


On Mon, 22 Jan 2007, Marcel Weiher wrote:
> I've been having somewhat semi-random crashes that seem to be related
> to my use of Argument objects, usually when I then try to use them for
> processing, for examples in a CallInst.

Your code looks pretty reasonable to me.  The only thing to be aware of is 
that varargs functions will have fewer Argument nodes than calls to the 
functions have (e.g. the values passed through the "..." won't have a 
corresponding Argument).  Other than that, I can't think of anything 
off-hand.

-Chris

> Do I need to copy or wrap the Argument if I want to use it as a
> Value?  Or can I just use the reference that I am getting (multiple
> times)?  I think there is probably something very fundamental about
> the ownership model / memory management or how Argument objects work
> that I am missing (or (e) all of the above).
>
> The code below is what I use to fetch arguments from the Function
> object in order to use them.  I wrap them up in an Objective-C object
> that just holds on to the pointer.  The really weird part is the line
> above the (non-exception) return statement.  It is obviously totally
> useless and should have no effect whatsoever.  However, without it I
> will crash sometime later, either when creating a CallInst that uses
> the Argument in question or when actually generating code for the
> CallInst slightly later.   (I used to have an NSLog() there that had
> the same effect, but my hunch was that it was just malloc() activity,
> not anything to do with the I/O taking place.
>
> The code is mostly ripped from the examples, but I couldn't find any
> uses where the Argument obtained survives beyond the scope of the
> local function.
>
> There have been other bits of weirdness about Arguments, for example
> crashes or non-crashes depending on wether they had a name set or not
> (all combinations of these two parameters), but those seem to be
> quiescent at the time.  Any ideas?
>
> Thanks,
>
> Marcel
>
>
> ------- my weird code.m ------------
> -argumentAtIndex:(int)argIndex
> {
>         Argument *ArgX;
>         if ( argIndex < numArgs ) {
>                 int i;
>                 ArgX = ((Function*)function)->arg_begin();
>                 for (i=0 ;i<argIndex;i++) {
>                         ++ArgX;
>                 }
>
>                 [NSString stringWithFormat:@"get argument[%d/%d]=
> %x",argIndex,numArgs,ArgX];     //   with this in place, it doesn't
> crash
>                 return [MPWLLVMValue
> llvmValueWithLLVMValue:ArgX];  // wrap the arg
>         } else {
> 		//--- error handling, irrelevant here...
>                 [NSException raise:@"IndexOutOfBounds"
> format:@"requesting argument %d when only %d
> available",argIndex,numArgs];
>                 return nil;
>         }
> }
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list