[llvm] [CodeGen] Inline stack guard check on Windows (PR #136290)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 18 04:58:15 PDT 2025
================
@@ -3126,14 +3099,66 @@ void SelectionDAGBuilder::visitSPDescriptorParent(StackProtectorDescriptor &SPD,
/// For a high level explanation of how this fits into the stack protector
/// generation see the comment on the declaration of class
/// StackProtectorDescriptor.
-void
-SelectionDAGBuilder::visitSPDescriptorFailure(StackProtectorDescriptor &SPD) {
+void SelectionDAGBuilder::visitSPDescriptorFailure(
+ StackProtectorDescriptor &SPD) {
+
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
- TargetLowering::MakeLibCallOptions CallOptions;
- CallOptions.setDiscardResult(true);
- SDValue Chain = TLI.makeLibCall(DAG, RTLIB::STACKPROTECTOR_CHECK_FAIL,
- MVT::isVoid, {}, CallOptions, getCurSDLoc())
- .second;
+ MachineBasicBlock *ParentBB = SPD.getParentMBB();
+ const Module &M = *ParentBB->getParent()->getFunction().getParent();
+ SDValue Chain;
+
+ // Retrieve guard check function, nullptr if instrumentation is inlined.
+ if (const Function *GuardCheckFn = TLI.getSSPStackGuardCheck(M)) {
+
+ // First create the loads to the guard/stack slot for the comparison.
+ EVT PtrTy = TLI.getPointerTy(DAG.getDataLayout());
+ EVT PtrMemTy = TLI.getPointerMemTy(DAG.getDataLayout());
+
+ MachineFrameInfo &MFI = ParentBB->getParent()->getFrameInfo();
+ int FI = MFI.getStackProtectorIndex();
+
+ SDLoc dl = getCurSDLoc();
+ SDValue StackSlotPtr = DAG.getFrameIndex(FI, PtrTy);
+ Align Align = DAG.getDataLayout().getPrefTypeAlign(
+ PointerType::get(M.getContext(), 0));
----------------
arsenm wrote:
Should use the correct address space pointer, implied from the value
https://github.com/llvm/llvm-project/pull/136290
More information about the llvm-commits
mailing list