[patch] mergefunc struct result

Duncan P. N. Exon Smith dexonsmith at apple.com
Sat Apr 19 16:50:49 PDT 2014


On 2014 Apr 19, at 01:30, Carlo Kok <ck at remobjects.com> wrote:

> On Sat, 19 Apr 2014 00:03:24 +0200, Duncan P. N. Exon Smith <dexonsmith at apple.com> wrote:
> 
>>> +  if (SrcTy->isStructTy() && DestTy->isStructTy()) {
>> 
>> Should this be asserting:
>> 
>>    assert(DestTy->isStructTy())
>> 
>> rather than checking it?
>> 
>>> +    assert(SrcTy->getStructNumElements() == DestTy->getStructNumElements());
>>> +    Value* res = UndefValue::get(DestTy);
>> 
> 
> In this case no, the function works on ints and pointers now:

For clarity, I mean: 

    if (SrcTy->isStructTy()) {
      assert(DestTy->isStructTy() && "Can only cast SrcTy to StructTy");
      // ...
    }
    assert(!DestTy->isStructTy() && "Cannot cast SrcTy to StructTy");

> static Value* createCast(IRBuilder<false> &Builder, Value *V, Type *DestTy) {
>  Type *SrcTy = V->getType();
>  if (SrcTy->isIntegerTy() && DestTy->isPointerTy())
>    return Builder.CreateIntToPtr(V, DestTy);
>  else if (SrcTy->isPointerTy() && DestTy->isIntegerTy())
>    return Builder.CreatePtrToInt(V, DestTy);
>  else
>    return Builder.CreateBitCast(V, DestTy);
> }
> 
> I'm just adding a new option (struct) above it so it doesn't get into
> the bit cast.
> 
> -- 
> Calo Kok




More information about the llvm-commits mailing list