[llvm-commits] [llvm-gcc-4.2] r79605 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
Bill Wendling
isanbard at gmail.com
Fri Aug 21 10:35:13 PDT 2009
Hi Duncan,
> Hi Bill,
>
>> - if (isa<PointerType>(In->getType()))
>> - In = Builder.CreatePtrToInt(In, Amt->getType(),
>> + if (isa<PointerType>(In->getType())) {
>> + const Type *Ty = 0;
>> +
>> + switch (getInt64(TYPE_SIZE (TREE_TYPE (TREE_OPERAND (exp,
>> 0))), true)) {
>> + default: assert(0 && "Pointer size in bits not a power of 2!");
>> + case 1: Ty = Type::getInt1Ty(Context); break;
>> + case 8: Ty = Type::getInt8Ty(Context); break;
>> + case 16: Ty = Type::getInt16Ty(Context); break;
>> + case 32: Ty = Type::getInt32Ty(Context); break;
>> + case 64: Ty = Type::getInt64Ty(Context); break;
>> + }
>> +
>> + In = Builder.CreatePtrToInt(In, Ty,
>> (In->getNameStr()+".cast").c_str());
>
> why don't you use the result type of the expression (isn't it
> an integer?). If it's a pointer too, then you can replace the
> above with:
>
The result type isn't necessarily the size of the pointer, and isn't
always a pointer either. I just feel a bit more comfortable with using
the equivalent pointer's integer size I guess? I don't know. It
probably doesn't really make a different since it'll be truncated
nonetheless...
-bw
> Ty = IntegerType::get(Context, TYPE_PRECISION(TREE_TYPE
> (TREE_OPERAND (exp, 0))));
>
> Ciao,
>
> Duncan.
More information about the llvm-commits
mailing list