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

Anthony Bryant antjbryant at gmail.com
Wed Sep 19 09:29:06 PDT 2012


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.

Thanks,
Anthony Bryant.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mdnode_operands_v3.patch
Type: application/octet-stream
Size: 1714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120919/3f1429cd/attachment.obj>


More information about the llvm-commits mailing list