@@ -2067,8 +2067,11 @@ create_stack_guard (void)
20672067{
20682068 tree guard = build_decl (DECL_SOURCE_LOCATION (current_function_decl),
20692069 VAR_DECL, NULL , ptr_type_node);
2070+ machine_mode mode = TYPE_MODE (TREE_TYPE (guard));
20702071 TREE_THIS_VOLATILE (guard) = 1 ;
20712072 TREE_USED (guard) = 1 ;
2073+ // record the alignment requirements for this stack slot
2074+ record_alignment_for_reg_var (GET_MODE_ALIGNMENT (mode));
20722075 expand_one_stack_var (guard);
20732076 crtl->stack_protect_guard = guard;
20742077}
@@ -6544,11 +6547,13 @@ stack_protect_prologue (void)
65446547 rtx x, y;
65456548
65466549 crtl->stack_protect_guard_decl = guard_decl;
6547- x = expand_normal (crtl-> stack_protect_guard ) ;
6550+ x = NULL_RTX ;
65486551
65496552 if (targetm.have_stack_protect_combined_set () && guard_decl)
65506553 {
65516554 gcc_assert (DECL_P (guard_decl));
6555+ if (x == NULL_RTX)
6556+ x = expand_normal (crtl->stack_protect_guard );
65526557 y = DECL_RTL (guard_decl);
65536558
65546559 /* Allow the target to compute address of Y and copy it to X without
@@ -6562,22 +6567,29 @@ stack_protect_prologue (void)
65626567 }
65636568 }
65646569
6565- if (guard_decl)
6566- y = expand_normal (guard_decl);
6567- else
6568- y = const0_rtx;
6569-
65706570 /* Allow the target to copy from Y to X without leaking Y into a
65716571 register. */
65726572 if (targetm.have_stack_protect_set ())
6573- if (rtx_insn *insn = targetm.gen_stack_protect_set (x, y))
6574- {
6575- emit_insn (insn);
6576- return ;
6577- }
6573+ {
6574+ if (x == NULL_RTX)
6575+ x = expand_normal (crtl->stack_protect_guard );
6576+ if (guard_decl)
6577+ y = expand_normal (guard_decl);
6578+ else
6579+ y = const0_rtx;
6580+
6581+ if (rtx_insn *insn = targetm.gen_stack_protect_set (x, y))
6582+ {
6583+ emit_insn (insn);
6584+ return ;
6585+ }
6586+ }
65786587
6579- /* Otherwise do a straight move. */
6580- emit_move_insn (x, y);
6588+ /* Otherwise generate and expand an assignment expression. This
6589+ generates code that works in the case where the stack is aligned
6590+ differently to the guard variable (e.g. on m68k). */
6591+ expand_assignment (crtl->stack_protect_guard ,
6592+ crtl->stack_protect_guard_decl , false );
65816593}
65826594
65836595/* Translate the intermediate representation contained in the CFG
0 commit comments