public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Matthew Malcomson <matmal01@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] Fix &MEM_REF fold in expand_simple_operations Date: Thu, 5 May 2022 12:09:28 +0000 (GMT) [thread overview] Message-ID: <20220505120928.D90223856262@sourceware.org> (raw) 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);
reply other threads:[~2022-05-05 12:09 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220505120928.D90223856262@sourceware.org \ --to=matmal01@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).