[LLVMdev] Semi-random crashes seemingly related to Arguments

Marcel Weiher mweiher at apple.com
Mon Jan 22 17:37:15 PST 2007


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.

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;
         }
}






More information about the llvm-dev mailing list