public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-6221] gimple-fold: Remove incorrect folding of debug stmts [PR103691]
Date: Wed,  5 Jan 2022 09:46:02 +0000 (GMT)	[thread overview]
Message-ID: <20220105094602.82F93385840A@sourceware.org> (raw)

https://gcc.gnu.org/g:a4c2e62d60f47d47cdd94951e16b0de50495cdab

commit r12-6221-ga4c2e62d60f47d47cdd94951e16b0de50495cdab
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Jan 5 10:45:26 2022 +0100

    gimple-fold: Remove incorrect folding of debug stmts [PR103691]
    
    For ADDR_EXPR gimple_debug_bind_get_value fold_stmt_1 uses
    maybe_canonicalize_mem_ref_addr earlier and I think that should
    resolve the concerns raised in PR52329.  But folding ADDR_EXPR
    operand using maybe_fold_reference and then taking address of that
    looks like an invalid transformation, it can transform
      # DEBUG D.4293 => &a[0]
    into
      # DEBUG D.4293 => &2.0e+0
    etc., all we want to allow are the lhs folding of the operand which
    maybe_fold_reference no longer does since r12-21-g0bf8cd9d5e8ac.
    
    2022-01-05  Jakub Jelinek  <jakub@redhat.com>
    
            PR fortran/103691
            * gimple-fold.c (fold_stmt_1): Don't call maybe_fold_reference
            for DEBUG stmts with ADDR_EXPR gimple_debug_bind_get_value,
            it can do unwanted rhs folding like &a[0] into &2.0 etc.
    
            * gfortran.dg/pr103691.f90: New test.

Diff:
---
 gcc/gimple-fold.c                      | 15 +--------------
 gcc/testsuite/gfortran.dg/pr103691.f90 |  9 +++++++++
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 80e7d89c1da..77c551af942 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -6283,8 +6283,7 @@ fold_stmt_1 (gimple_stmt_iterator *gsi, bool inplace, tree (*valueize) (tree))
       if (gimple_debug_bind_p (stmt))
 	{
 	  tree val = gimple_debug_bind_get_value (stmt);
-	  if (val
-	      && REFERENCE_CLASS_P (val))
+	  if (val && REFERENCE_CLASS_P (val))
 	    {
 	      tree tem = maybe_fold_reference (val);
 	      if (tem)
@@ -6293,18 +6292,6 @@ fold_stmt_1 (gimple_stmt_iterator *gsi, bool inplace, tree (*valueize) (tree))
 		  changed = true;
 		}
 	    }
-	  else if (val
-		   && TREE_CODE (val) == ADDR_EXPR)
-	    {
-	      tree ref = TREE_OPERAND (val, 0);
-	      tree tem = maybe_fold_reference (ref);
-	      if (tem)
-		{
-		  tem = build_fold_addr_expr_with_type (tem, TREE_TYPE (val));
-		  gimple_debug_bind_set_value (stmt, tem);
-		  changed = true;
-		}
-	    }
 	}
       break;
 
diff --git a/gcc/testsuite/gfortran.dg/pr103691.f90 b/gcc/testsuite/gfortran.dg/pr103691.f90
new file mode 100644
index 00000000000..f1f551e20fa
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103691.f90
@@ -0,0 +1,9 @@
+! PR fortran/103691
+! { dg-do compile }
+! { dg-options "-O2 -g" }
+
+program pr103691
+  real, parameter :: a(0) = 2.0
+  real, allocatable :: b(:)
+  allocate (b, mold=a)
+end


                 reply	other threads:[~2022-01-05  9:46 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=20220105094602.82F93385840A@sourceware.org \
    --to=jakub@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).