[llvm] [RISC-V] Adjust trampoline code for branch control flow protection (PR #141949)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 3 09:55:06 PDT 2025


================
@@ -8295,9 +8296,22 @@ SDValue RISCVTargetLowering::lowerINIT_TRAMPOLINE(SDValue Op,
   //     16: <StaticChainOffset>
   //     24: <FunctionAddressOffset>
   //     32:
-
-  constexpr unsigned StaticChainOffset = 16;
-  constexpr unsigned FunctionAddressOffset = 24;
+  // Offset with branch control flow protection enabled:
+  //      0: lpad    <imm20>
+  //      4: auipc   t3, 0
+  //      8: ld      t2, 28(t3)
+  //     12: ld      t3, 20(t3)
+  //     16: jalr    t2
+  //     20: <StaticChainOffset>
+  //     28: <FunctionAddressOffset>
+  //     36:
+
+  const bool HasCFBranch =
+      Subtarget.hasStdExtZicfilp() &&
+      DAG.getMMI()->getModule()->getModuleFlag("cf-protection-branch");
----------------
topperc wrote:

Weren't you using `MF.getFunction()->getParent()->getModuleFlag` before?

https://github.com/llvm/llvm-project/pull/141949


More information about the llvm-commits mailing list