[llvm-commits] [PATCH] C Bindings: Allow reading MDNode operands

Duncan Sands baldrick at free.fr
Wed Sep 19 13:31:31 PDT 2012


Hi Anthony,

On 19/09/12 18:29, Anthony Bryant wrote:
> On 19 September 2012 16:28, Villmow, Micah <Micah.Villmow at amd.com> wrote:
>> + * The passed LLVMValueRef pointer should refer to an array of LLVMValueRef at
>> + * least LLVMGetMDNodeNumOperands long.
>>
>> I think a better wording here would be something like:
>> " The passed LLVMValueRef pointer should point to memory that contains enough space
>> to hold the number of LLVMValueRef's returned by LLVMGetMDNodeNumOperands."
>
> I basically copied that comment from the one that retrieves operands
> from named metadata.
> Is this version better (attached)?
>
>> +void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest)
>> +{
>> +  const MDNode *N = cast<MDNode>(unwrap(V));
>> +  const unsigned numOperands = N->getNumOperands();
>> +  for (unsigned i = 0; i < numOperands; i++) {
>> +    Dest[i] = wrap(N->getOperand(i));
>> +  }
>> +}
>>
>> What happens in the case where the LLVMValueRef is not an MDNode?
>
> As Duncan said, if you provide invalid input, it should crash rather
> than fail silently (as my first version did). This way it's easier to
> debug if you give it the wrong arguments.

sorry for the delay, I just wanted to check that
LLVMGetNamedMetadataNumOperands were already present in the last release (if not
it would have been OK to change them).  They were present, so I think your patch
is OK as is and I've applied it in commit 164247.

Ciao, Duncan.



More information about the llvm-commits mailing list