I’ve been having some trouble implementing a new intrinsic for LLVM and I was wondering if someone might know the answer.
LLVM has an llvm.returnaddress intrinsic, but for a specific project, I need to be able to modify the return address of a function as well, so I’m implementing a new intrinsic:
def int_setreturnaddress : Intrinsic<, [llvm_i32_ty, llvm_ptr_ty], >;
And I’m using it as follows:
B.CreateIntToPtr(ConstantInt::get(IntPtrTy, 0 /* testing */)), RA->getReturnType()));
The problem I’m facing is that for some reason, my following line inside X86TargetLowering::LowerOperation is never getting called:
case ISD::SETRETURNADDR: return LowerSETRETURNADDR(Op, DAG);
This is despite the fact that I can confirm the following line inside SelectionDAGBuilder::visitIntrinsicCall is getting called:
setValue(&I, DAG.getNode(ISD::SETRETURNADDR, sdl, TLI->getPointerTy(),
My best guess is that my code is being optimized out – but I’m not sure where or why.
Does anyone know why this might be happening?