From 1a132c4d7cdb22cbab85b8596418daa2c3157812 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 19 Feb 2021 13:05:47 +0100 Subject: [PATCH] arm: Fix ICE with -fstack-protector -mpure-code [PR98998] The vla15.C testcase ICEs with -mcpu=cortex-m1 -mpure-code -fstack-protector -mthumb as what force_const_mem returns (a SYMBOL_REF) is not a valid memory address. Previously the code was moving the address of the force_const_mem into a register rather than the content of that MEM, so that instruction must have been supported and loading from a MEM with a single REG base ought to be valid too. 2021-02-19 Jakub Jelinek PR target/98998 * config/arm/arm.md (*stack_protect_combined_set_insn, *stack_protect_combined_test_insn): If force_const_mem result is not valid general operand, force its address into the destination register first. * gcc.target/arm/pure-code/pr98998.c: New test. --- gcc/config/arm/arm.md | 10 ++++++++++ .../gcc.target/arm/pure-code/pr98998.c | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/gcc.target/arm/pure-code/pr98998.c diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md index 3e441f9dd21..45a471a887a 100644 --- a/gcc/config/arm/arm.md +++ b/gcc/config/arm/arm.md @@ -9216,6 +9216,11 @@ else { rtx mem = force_const_mem (SImode, operands[1]); + if (!general_operand (mem, SImode)) + { + emit_move_insn (operands[2], XEXP (mem, 0)); + mem = replace_equiv_address (mem, operands[2], false); + } emit_move_insn (operands[2], mem); } } @@ -9299,6 +9304,11 @@ else { rtx mem = force_const_mem (SImode, operands[1]); + if (!general_operand (mem, SImode)) + { + emit_move_insn (operands[3], XEXP (mem, 0)); + mem = replace_equiv_address (mem, operands[3], false); + } emit_move_insn (operands[3], mem); } } diff --git a/gcc/testsuite/gcc.target/arm/pure-code/pr98998.c b/gcc/testsuite/gcc.target/arm/pure-code/pr98998.c new file mode 100644 index 00000000000..9d7b0b24f0e --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/pure-code/pr98998.c @@ -0,0 +1,20 @@ +/* PR target/98998 */ +/* { dg-do compile { target fstack_protector } } */ +/* { dg-options "-mpure-code -fstack-protector" } */ + +void *volatile p; + +int +main () +{ + int n = 0; + lab:; + int x[n % 1000 + 1]; + x[0] = 1; + x[n % 1000] = 2; + p = x; + n++; + if (n < 1000000) + goto lab; + return 0; +} -- 2.30.2