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

Duncan Sands baldrick at free.fr
Thu Sep 13 04:09:46 PDT 2012


Hi Anthony,

>>> (Sorry for sending this to the wrong list earlier.)
>>>
>>> This patch just adds two functions: LLVMGetMDNodeNumOperands and
>>> LLVMGetMDNodeOperands, which allow access to MDNode operands from the
>>> C API, similarly to how named metadata can be accessed there.
>>>
>>> Could this be reviewed and possibly committed please?
>>
>> if the node isn't an MDNode shouldn't it barf (eg abort)?
>
> I thought I checked for that - both of them do dyn_cast<MDNode> and
> check whether the result is null before continuing.
>
> Do you mean they should return some sort of error? Because the
> functions that read the same things from NamedMDNodes don't.

yes, that they should cause some sort of error.  I think routines like
LLVMGetNamedMetadataNumOperands are wrong to work the way they do.  There
should be a routine to get the named metadata pointer given the name (or
null if there is no name).  There should be a routine to get or create
named metadata given the name (and it should return a metadata pointer).
Routines like LLVMGetNamedMetadataNumOperands should take the metadata
pointer and ensure a crash if it isn't the right kind of pointer (eg by
using cast rather than dyn_cast).

Ciao, Duncan.



More information about the llvm-commits mailing list