[llvm-commits] [llvm-gcc-4.2] r85466 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Duncan Sands baldrick at free.fr
Thu Oct 29 01:19:35 PDT 2009


Hi Eric,

> +    tree Object = TREE_VALUE(arglist);
> +    tree ObjTy = TREE_VALUE(TREE_CHAIN(arglist));
> +
> +    Value* Args[] = {
> +      Emit(Object, 0),
> +      Emit(ObjTy, 0)
> +    };
> +
> +    // Grab the current types.
> +    const Type* Ty[3];
> +    Ty[0] = ConvertType(TREE_TYPE(exp));
> +    Ty[1] = Type::getInt8PtrTy(Context);
> +    Ty[2] = ConvertType(TREE_TYPE(ObjTy));
> +
> +    // Manually coerce the args to the current types.
> +    Args[0] = Builder.CreateBitCast(Args[0], Ty[1]);

bitcast is ok for pointers, but

> +    Args[1] = Builder.CreateIntCast(Args[1], Ty[2], "");

it never has any effect on integers, because it can only be used to cast to
an integer type of the same size, and that means to the original type.
Probably you want CastToAnyType, CastToUIntType or one of the other helper
methods here.  Also, why not set up the Ty array before the Args array, and
do the type conversions in the declaration of Args?

Ciao,

Duncan.



More information about the llvm-commits mailing list