public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-10305] middle-end/106331 - fix mem attributes for string op arguments
Date: Tue, 11 Oct 2022 13:04:34 +0000 (GMT)	[thread overview]
Message-ID: <20221011130434.11925384D197@sourceware.org> (raw)

https://gcc.gnu.org/g:90d3b4dd84c08cc134578397d9c6b30b7dc4b440

commit r11-10305-g90d3b4dd84c08cc134578397d9c6b30b7dc4b440
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Jul 19 09:57:22 2022 +0200

    middle-end/106331 - fix mem attributes for string op arguments
    
    get_memory_rtx tries hard to come up with a MEM_EXPR to record
    in the memory attributes but in the last fallback fails to properly
    account for an unknown offset and thus, as visible in this testcase,
    incorrect alignment computed from set_mem_attributes.  The following
    rectifies both parts.
    
            PR middle-end/106331
            * builtins.c (get_memory_rtx): Compute alignment from
            the original address and set MEM_OFFSET to unknown when
            we create a MEM_EXPR from the base object of the address.
    
            * gfortran.dg/pr106331.f90: New testcase.
    
    (cherry picked from commit e4ff11a8f2e80adb8ada69bf35ee6a1ab18a9c85)

Diff:
---
 gcc/builtins.c                         | 13 +++++++++----
 gcc/testsuite/gfortran.dg/pr106331.f90 |  7 +++++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 64f4999ab07..627a89b3c45 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -2110,7 +2110,7 @@ expand_builtin_prefetch (tree exp)
 static rtx
 get_memory_rtx (tree exp, tree len)
 {
-  tree orig_exp = exp;
+  tree orig_exp = exp, base;
   rtx addr, mem;
 
   /* When EXP is not resolved SAVE_EXPR, MEM_ATTRS can be still derived
@@ -2141,10 +2141,11 @@ get_memory_rtx (tree exp, tree len)
   if (is_gimple_mem_ref_addr (TREE_OPERAND (exp, 0)))
     set_mem_attributes (mem, exp, 0);
   else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
-	   && (exp = get_base_address (TREE_OPERAND (TREE_OPERAND (exp, 0),
-						     0))))
+	   && (base = get_base_address (TREE_OPERAND (TREE_OPERAND (exp, 0),
+						      0))))
     {
-      exp = build_fold_addr_expr (exp);
+      unsigned int align = get_pointer_alignment (TREE_OPERAND (exp, 0));
+      exp = build_fold_addr_expr (base);
       exp = fold_build2 (MEM_REF,
 			 build_array_type (char_type_node,
 					   build_range_type (sizetype,
@@ -2152,6 +2153,10 @@ get_memory_rtx (tree exp, tree len)
 							     NULL)),
 			 exp, build_int_cst (ptr_type_node, 0));
       set_mem_attributes (mem, exp, 0);
+      /* Since we stripped parts make sure the offset is unknown and the
+	 alignment is computed from the original address.  */
+      clear_mem_offset (mem);
+      set_mem_align (mem, align);
     }
   set_mem_alias_set (mem, 0);
   return mem;
diff --git a/gcc/testsuite/gfortran.dg/pr106331.f90 b/gcc/testsuite/gfortran.dg/pr106331.f90
new file mode 100644
index 00000000000..3873863be48
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr106331.f90
@@ -0,0 +1,7 @@
+! { dg-do run }
+! { dg-options "-Og" }
+
+PROGRAM main
+  CHARACTER(LEN=24) :: a(2)
+  a = ''
+END PROGRAM

                 reply	other threads:[~2022-10-11 13:04 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=20221011130434.11925384D197@sourceware.org \
    --to=rguenth@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: link
Be 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).