public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] Fix &MEM_REF fold in expand_simple_operations
@ 2022-05-05 12:09 Matthew Malcomson
0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2022-05-05 12:09 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:978d3670e25b488ac577ee439a8aba783cee3f41
commit 978d3670e25b488ac577ee439a8aba783cee3f41
Author: Richard Sandiford <richard.sandiford@arm.com>
Date: Wed Apr 20 16:42:22 2022 +0100
Fix &MEM_REF fold in expand_simple_operations
expand_simple_operations looks for expressions of the form
&MEM_REF(ptr)compoment-refs
where component-refs include things like field names and array
indices. It then folds that to:
POINTER_PLUS_EXPR<ptr, offset>
where offset is the byte offset associated with component-refs.
In the testcase, the function was doing that even when ptr was a
capability and the result of the & wasn't, meaning that the type
on the POINTER_PLUS_EXPR dropped the capability from the result.
Fortunately this was caught by verify_gimple, as intended,
so it wasn't a silent error.
Diff:
---
gcc/testsuite/gcc.target/aarch64/morello/pointer-arith-4.c | 11 +++++++++++
gcc/tree-ssa-loop-niter.c | 4 +++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/pointer-arith-4.c b/gcc/testsuite/gcc.target/aarch64/morello/pointer-arith-4.c
new file mode 100644
index 00000000000..494f8e75b1a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/pointer-arith-4.c
@@ -0,0 +1,11 @@
+struct S { char s[0]; } *__capability a;
+
+void
+foo (void)
+{
+ char *b = (char *) a->s;
+ int c = 0;
+ b[0] = 0;
+ while (++c < 9)
+ b[c] = 255;
+}
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 48e1a1ed9c2..bdc565aceef 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -2089,7 +2089,9 @@ expand_simple_operations (tree expr, tree stop, hash_map<tree, tree> &cache)
tree base = get_addr_base_and_unit_offset (TREE_OPERAND (e, 0),
&offset);
if (base
- && TREE_CODE (base) == MEM_REF)
+ && TREE_CODE (base) == MEM_REF
+ && useless_type_conversion_p (TREE_TYPE (TREE_OPERAND (base, 0)),
+ TREE_TYPE (expr)))
{
ee = expand_simple_operations (TREE_OPERAND (base, 0), stop,
cache);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-05 12:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-05 12:09 [gcc(refs/vendors/ARM/heads/morello)] Fix &MEM_REF fold in expand_simple_operations Matthew Malcomson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).