From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2049) id D90223856262; Thu, 5 May 2022 12:09:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D90223856262 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Matthew Malcomson To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] Fix &MEM_REF fold in expand_simple_operations X-Act-Checkin: gcc X-Git-Author: Richard Sandiford X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: a4a587c96ec5b85fbd90793d7a2d8b4e65d9745d X-Git-Newrev: 978d3670e25b488ac577ee439a8aba783cee3f41 Message-Id: <20220505120928.D90223856262@sourceware.org> Date: Thu, 5 May 2022 12:09:28 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 May 2022 12:09:29 -0000 https://gcc.gnu.org/g:978d3670e25b488ac577ee439a8aba783cee3f41 commit 978d3670e25b488ac577ee439a8aba783cee3f41 Author: Richard Sandiford 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 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 &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);