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 r14-4678] middle-end/111818 - failed DECL_NOT_GIMPLE_REG_P setting of volatile
Date: Tue, 17 Oct 2023 06:26:38 +0000 (GMT)	[thread overview]
Message-ID: <20231017062638.4A8383857354@sourceware.org> (raw)

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

commit r14-4678-gce55521bcd149fdc431f1d78e706b66d470210ae
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Oct 16 12:50:46 2023 +0200

    middle-end/111818 - failed DECL_NOT_GIMPLE_REG_P setting of volatile
    
    The following addresses a missed DECL_NOT_GIMPLE_REG_P setting of
    a volatile declared parameter which causes inlining to substitute
    a constant parameter into a context where its address is required.
    
    The main issue is in update_address_taken which clears
    DECL_NOT_GIMPLE_REG_P from the parameter but fails to rewrite it
    because is_gimple_reg returns false for volatiles.  The following
    changes maybe_optimize_var to make the 1:1 correspondence between
    clearing DECL_NOT_GIMPLE_REG_P of a register typed decl and
    actually rewriting it to SSA.
    
            PR middle-end/111818
            * tree-ssa.cc (maybe_optimize_var): When clearing
            DECL_NOT_GIMPLE_REG_P always rewrite into SSA.
    
            * gcc.dg/torture/pr111818.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr111818.c | 11 +++++++++++
 gcc/tree-ssa.cc                         | 17 +++++++++++------
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr111818.c b/gcc/testsuite/gcc.dg/torture/pr111818.c
new file mode 100644
index 000000000000..a7a91111d717
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr111818.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+
+static void foo(const volatile unsigned int x, void *p)
+{
+  __builtin_memcpy(p, (void *)&x, sizeof x);
+}
+
+void bar(void *number)
+{
+  foo(0, number);
+}
diff --git a/gcc/tree-ssa.cc b/gcc/tree-ssa.cc
index ebba02b84496..2f3210fcf616 100644
--- a/gcc/tree-ssa.cc
+++ b/gcc/tree-ssa.cc
@@ -1788,15 +1788,20 @@ maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs,
 	  maybe_reg = true;
 	  DECL_NOT_GIMPLE_REG_P (var) = 0;
 	}
-      if (maybe_reg && is_gimple_reg (var))
+      if (maybe_reg)
 	{
-	  if (dump_file)
+	  if (is_gimple_reg (var))
 	    {
-	      fprintf (dump_file, "Now a gimple register: ");
-	      print_generic_expr (dump_file, var);
-	      fprintf (dump_file, "\n");
+	      if (dump_file)
+		{
+		  fprintf (dump_file, "Now a gimple register: ");
+		  print_generic_expr (dump_file, var);
+		  fprintf (dump_file, "\n");
+		}
+	      bitmap_set_bit (suitable_for_renaming, DECL_UID (var));
 	    }
-	  bitmap_set_bit (suitable_for_renaming, DECL_UID (var));
+	  else
+	    DECL_NOT_GIMPLE_REG_P (var) = 1;
 	}
     }
 }

                 reply	other threads:[~2023-10-17  6:26 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=20231017062638.4A8383857354@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).