[clang] [llvm] [SystemZ] Global Stackprotector and associated location section (PR #169317)
Dominik Steenken via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 2 02:17:00 PST 2026
================
@@ -3187,6 +3194,45 @@ static void adjustICmpTruncate(SelectionDAG &DAG, const SDLoc &DL,
}
}
+// Adjust if a given Compare is a check of the stack guard against a stack
+// guard instance on the stack. Specifically, this checks if:
+// - The operands are a load of the stack guard, and a load from a stack slot
+// - Those operand values are not used elsewhere <-- asserts if this is not
+// true!
+static void adjustForStackGuardCompare(SelectionDAG &DAG, const SDLoc &DL,
+ Comparison &C) {
+ SDValue StackGuardLoad;
+ LoadSDNode *FILoad;
+
+ if (C.Op0.isMachineOpcode() &&
+ C.Op0.getMachineOpcode() == SystemZ::LOAD_STACK_GUARD &&
+ ISD::isNormalLoad(C.Op1.getNode()) &&
+ dyn_cast<FrameIndexSDNode>(C.Op1.getOperand(1))) {
+ StackGuardLoad = C.Op0;
+ FILoad = cast<LoadSDNode>(C.Op1);
+ } else if ((C.Op1.isMachineOpcode() &&
+ C.Op1.getMachineOpcode() == SystemZ::LOAD_STACK_GUARD &&
+ ISD::isNormalLoad(C.Op0.getNode()) &&
+ dyn_cast<FrameIndexSDNode>(C.Op0.getOperand(1)))) {
+ StackGuardLoad = C.Op1;
+ FILoad = cast<LoadSDNode>(C.Op0);
+ } else {
+ return;
+ }
+ // Assert that the values of the loads are not used elsewhere.
+ // Bail for now. TODO: What is the proper response here?
+ assert(
+ SDValue(FILoad, 0).hasOneUse() &&
+ "Value of stackguard loaded from stack must be used for compare only!");
+ assert(StackGuardLoad.hasOneUse() &&
+ "Value of reference stackguard must be used for compare only!");
+
+ // At this point we are sure that this is a proper compare_stack_guard
+ // case, update the opcode to reflect this.
+ C.Opcode = SystemZISD::COMPARE_STACKGUARD;
+ C.CCValid = SystemZ::CCMASK_ICMP;
----------------
dominik-steenken wrote:
done
https://github.com/llvm/llvm-project/pull/169317
More information about the cfe-commits
mailing list