Obtaining return address during lowerCall()

I’m implementing a more secure calling convention (on the CHERI fork of llvm, but my question is applicable to vanilla llvm as well).

A part of this calling convention is returning using what is called an “activation record”, a small bundle of code and data placed on the stack which when executed restores the environment of the caller.

To construct this activation record I need to obtain a return address, ie the address of the first instruction after RISCVISD::CALL.

As stated in the title, I am working in the lowerCall() function (in RISCVISelLowering.cpp), so the return address will have to be some variable which is filled in during machine code emission. My question is: where can I obtain that variable during call lowering?

If I can provide more information to illustrate the problem further, I am more than happy to do so.

Not sure if I really understood your problem, but can’t you just create a MCSymbol representing a label after RISCVISD::CALL, and making sure that you emit that label in the AsmPrinter? Depending on place you need to access that label, you can either store in in the RISCVMachineFunctionInfo, or refer to it with a MCSymbolSDNode in the DAG.