diff options
author | Richard Sandiford <richard.sandiford@arm.com> | 2021-01-05 11:29:10 +0000 |
---|---|---|
committer | Richard Sandiford <richard.sandiford@arm.com> | 2021-01-05 11:29:10 +0000 |
commit | e8beba1cfc761cc35762283b3b44a355ef05e25b (patch) | |
tree | 1b0898b7078689eaba6d6ec3b72e778f40f09c89 /gcc/explow.c | |
parent | eac8675225c4cdae347a11089f2b0a22ce920965 (diff) | |
download | gcc-e8beba1cfc761cc35762283b3b44a355ef05e25b.zip gcc-e8beba1cfc761cc35762283b3b44a355ef05e25b.tar.gz gcc-e8beba1cfc761cc35762283b3b44a355ef05e25b.tar.bz2 |
explow, aarch64: Fix force-Pmode-to-mem for ILP32 [PR97269]
This patch fixes a mode/rtx mismatch for ILP32 targets in:
mem = force_const_mem (ptr_mode, imm);
where imm can be Pmode rather than ptr_mode.
The patch uses convert_memory_address to convert the Pmode address
to ptr_mode before the call. However, immediate addresses can in
general contain unspecs, and convert_memory_address wasn't set up
to handle those.
The patch therefore adds some generic unspec handling to
convert_memory_address_addr_space_1. As the comment says, we can add
a target hook if this behaviour turns out to be wrong for some targets.
But I think what the patch does is a strict improvement over the status
quo: without it, we would try to force the unspec into a register,
but nevertheless wrap the result in a (const ...). That in turn
would be invalid rtl and seems bound to generate an ICE later.
I tested the explow.c part using -fstack-protector with local hacks
to force SYMBOL_FORCE_TO_MEM for UNSPEC_SALT_ADDR.
Fixes c-c++-common/torture/pr57945.c and various other tests.
gcc/
PR target/97269
* explow.c (convert_memory_address_addr_space_1): Handle UNSPECs
nested in CONSTs.
* config/aarch64/aarch64.c (aarch64_expand_mov_immediate): Use
convert_memory_address to convert symbolic immediates to ptr_mode
before forcing them to memory.
Diffstat (limited to 'gcc/explow.c')
-rw-r--r-- | gcc/explow.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/gcc/explow.c b/gcc/explow.c index c474869..b6da277 100644 --- a/gcc/explow.c +++ b/gcc/explow.c @@ -378,6 +378,26 @@ convert_memory_address_addr_space_1 (scalar_int_mode to_mode ATTRIBUTE_UNUSED, } break; + case UNSPEC: + /* Assume that all UNSPECs in a constant address can be converted + operand-by-operand. We could add a target hook if some targets + require different behavior. */ + if (in_const && GET_MODE (x) == from_mode) + { + unsigned int n = XVECLEN (x, 0); + rtvec v = gen_rtvec (n); + for (unsigned int i = 0; i < n; ++i) + { + rtx op = XVECEXP (x, 0, i); + if (GET_MODE (op) == from_mode) + op = convert_memory_address_addr_space_1 (to_mode, op, as, + in_const, no_emit); + RTVEC_ELT (v, i) = op; + } + return gen_rtx_UNSPEC (to_mode, v, XINT (x, 1)); + } + break; + default: break; } |