Index: lib/Target/RISCV/RISCVISelLowering.h =================================================================== --- lib/Target/RISCV/RISCVISelLowering.h +++ lib/Target/RISCV/RISCVISelLowering.h @@ -128,6 +128,16 @@ bool isDesirableToCommuteWithShift(const SDNode *N, CombineLevel Level) const override; + /// If a physical register, this returns the register that receives the + /// exception address on entry to an EH pad. + unsigned + getExceptionPointerRegister(const Constant *PersonalityFn) const override; + + /// If a physical register, this returns the register that receives the + /// exception typeid on entry to a landing pad. + unsigned + getExceptionSelectorRegister(const Constant *PersonalityFn) const override; + private: void analyzeInputArgs(MachineFunction &MF, CCState &CCInfo, const SmallVectorImpl &Ins, Index: lib/Target/RISCV/RISCVISelLowering.cpp =================================================================== --- lib/Target/RISCV/RISCVISelLowering.cpp +++ lib/Target/RISCV/RISCVISelLowering.cpp @@ -2522,3 +2522,13 @@ Result = Builder.CreateTrunc(Result, Builder.getInt32Ty()); return Result; } + +unsigned RISCVTargetLowering::getExceptionPointerRegister( + const Constant *PersonalityFn) const { + return RISCV::X10; +} + +unsigned RISCVTargetLowering::getExceptionSelectorRegister( + const Constant *PersonalityFn) const { + return RISCV::X11; +} Index: test/CodeGen/RISCV/exception-pointer-register.ll =================================================================== --- /dev/null +++ test/CodeGen/RISCV/exception-pointer-register.ll @@ -0,0 +1,37 @@ +; RUN: llc -mtriple=riscv32 < %s +; RUN: llc -mtriple=riscv64 < %s +; +; Before getExceptionPointerRegister() and getExceptionSelectorRegister() +; lowering hooks were defined this would trigger an assertion during live +; variable analysis + +declare void @foo(i1* %p); +declare void @bar(i1* %p); +declare dso_local i32 @__gxx_personality_v0(...) + +define void @caller(i1* %p) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: + %0 = icmp eq i1* %p, null + br i1 %0, label %bb1, label %bb2 + +bb1: + invoke void @foo(i1* %p) to label %end1 unwind label %lpad + +bb2: + invoke void @bar(i1* %p) to label %end2 unwind label %lpad + +lpad: + %1 = landingpad { i8*, i32 } cleanup + call void @callee(i1* %p) + resume { i8*, i32 } %1 + +end1: + ret void + +end2: + ret void +} + +define internal void @callee(i1* %p) { + ret void +}