[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:14 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());
----------------
arsenm wrote:

You should essentially never use getPointerTy. The correct pointer type should be implied by some value in context 

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


More information about the llvm-commits mailing list