[llvm-commits] CAST patch (For Review Only) Part #1: include + vmcore part

Chris Lattner clattner at apple.com
Mon Nov 20 17:18:41 PST 2006


>> +  case Instruction::IntToPtr: //always treated as unsigned
>> +  case Instruction::UIToFP:
>> +  case Instruction::ZExt:
>> +    // A ZExt always produces an unsigned value so we need to cast
>> the value
>> +    // now before we try to cast it to the destination type
>> +    if (isa<ConstantIntegral>(V))
>> +      V = ConstantInt::get(SrcTy->getUnsignedVersion(),
>> +
>> cast<ConstantIntegral>(V)->getZExtValue());
>> +    break;
>
> what can abort here? The only possible thing is
> cast<ConstantIntegral>(V) and that is checked with the
> isa<ConstantIntegral>(V).

You're right, for some reason I didn't see the isa check. :)

>> ConstantFoldCastInstruction will miscompile a fptoui cast if the
>> destination is signed and fptosi if dest is unsigned.  For example,
>> "sbyte fptouint float 255.0" should be defined and return -1 always.
>
> Right we discussed this on IRC and I made a change that passes the  
> test
> case we developed. It uses the Rules to cast to unsigned and then  
> again
> to cast to signed.

Ok

>>
>> +Constant *ConstantExpr::getCast(unsigned oc, Constant *C, const Type
>> *Ty) {
>> +  Instruction::CastOps opc = Instruction::CastOps(oc);
>> +  assert(Instruction::isCast(opc) && "opcode out of range");
>> +  assert(C && Ty && "Null arguments to getCast");
>> +  assert(Ty->isFirstClassType() && "Cannot cast to an aggregate
>> type!");
>> +
>> +  switch (opc) {
>> +    default:
>> +      break;
>>
>>
>> This should abort on an invalid cast opcode, not return null (the
>> default should not be 'break' then ret null).
>
> What should it return in a release-asserts build? Returning 0 will  
> make
> it fail (segv) very close to the actual problem.

It doesn't matter what happens.  In these cases chose what is fastest  
in the non-failure case and smallest in generated code.  We don't  
care how nicely it fails.

>
> I replaced it with:
>
>   assert(isa<PointerType>(SrcTy) == isa<PointerType>(DstTy) &&
>         "Bitcast cannot cast pointer to non-pointer and vice versa");
>
> because they must either both be a pointer or neither be a pointer.

Sounds good.

-Chris





More information about the llvm-commits mailing list