[llvm-commits] [llvm] r92761 - in /llvm/trunk: docs/LangRef.html include/llvm/Metadata.h lib/AsmParser/LLParser.cpp lib/Bitcode/Reader/BitcodeReader.cpp lib/VMCore/Metadata.cpp unittests/VMCore/MetadataTest.cpp

Devang Patel dpatel at apple.com
Fri Jan 8 17:43:03 PST 2010


On Jan 8, 2010, at 11:45 AM, Chris Lattner wrote:

>> +++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Tue Jan  5  
>> 14:41:31 2010
>> @@ -787,11 +787,11 @@
>>
>>      // Read named metadata elements.
>>      unsigned Size = Record.size();
>> -      SmallVector<MetadataBase*, 8> Elts;
>> +      SmallVector<MDNode *, 8> Elts;
>>      for (unsigned i = 0; i != Size; ++i) {
>>        Value *MD = MDValueList.getValueFwdRef(Record[i]);
>> -        if (MetadataBase *B = dyn_cast<MetadataBase>(MD))
>> -        Elts.push_back(B);
>> +        if (MDNode *B = dyn_cast_or_null<MDNode>(MD))
>> +          Elts.push_back(B);
>
> This isn't great.  Three cases here: null is always fine.  MDNode is  
> also fine, non-MDNode is not fine.
>
> You should either use cast_or_null or you should check for non-null  
> and non-MDNodes and reject them with an error.

Done.

>
>> +++ llvm/trunk/lib/VMCore/Metadata.cpp Tue Jan  5 14:41:31 2010
>> @@ -252,14 +252,14 @@
>> }
>>
>> /// getOperand - Return specified operand.
>> -MetadataBase *NamedMDNode::getOperand(unsigned i) const {
>> +MDNode *NamedMDNode::getOperand(unsigned i) const {
>>  assert(i < getNumOperands() && "Invalid Operand number!");
>> -  return getNMDOps(Operands)[i];
>> +  return dyn_cast_or_null<MDNode>(getNMDOps(Operands)[i]);
>
> This should be cast_or_null.

This is does not work. I am not sure, why. Any clue?
   Metadata.cpp:258: error: no matching function for call to  
‘cast_or_null(llvm::WeakVH&)’
Thanks,
-
Devang



More information about the llvm-commits mailing list