Assertion `castIsValid(getOpcode(), S, Ty) && "Illegal BitCast"' failed.

ok.. So I am trying out what you have suggested. I have written the below code which basically tries to write the constant 10 to a file. myprint is a function pointer to a function which takes char * parameter and writes it to file.

Value *Ten = ConstantInt::get(Type::Int32Ty, 10);
const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
AllocaInst *AI = new AllocaInst(Type::Int32Ty);
Value *ST = new StoreInst(Ten,AI,false,4,j);
Value *BT = new BitCastInst(ST,VoidPtrTy,"",j);
CallInst *CallPrint = CallInst::Create(myprint, BT, "", j);
CallPrint->setTailCall(true);

I am getting the following error while executing.
Assertion `castIsValid(getOpcode(), S, Ty) && "Illegal BitCast"' failed.

What am I doing wrong :(? I always get stuck badly when these assertions fail :(. Please help me out here.
Thanks,
Bhavani

Value *Ten = ConstantInt::get(Type::Int32Ty, 10);
const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
AllocaInst *AI = new AllocaInst(Type::Int32Ty);
Value *ST = new StoreInst(Ten,AI,false,4,j);
Value *BT = new BitCastInst(ST,VoidPtrTy,"",j);

Should be "new BitCastInst(AI,VoidPtrTy,"",j);"

CallInst *CallPrint = CallInst::Create(myprint, BT, "", j);
CallPrint->setTailCall(true);

-Eli

bhavani krishnan wrote:

ok.. So I am trying out what you have suggested. I have written the below code which basically tries to write the constant 10 to a file. myprint is a function pointer to a function which takes char * parameter and writes it to file.

Value *Ten = ConstantInt::get(Type::Int32Ty, 10);
const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
AllocaInst *AI = new AllocaInst(Type::Int32Ty);
Value *ST = new StoreInst(Ten,AI,false,4,j);

Realize that StoreInst's don't have a result. A 'store' does not evaluate to a particular value at run time. Its type is Void.

Value *BT = new BitCastInst(ST,VoidPtrTy,"",j);

Trying to cast (void) to (void*) is invalid. Instead, you should cast the AllocaInst, ala:

   Value *BT = new BitCastInst(AI,VoidPtrTy,"",j);

Nick