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-9228] middle-end/102518 - avoid invalid GIMPLE during inlining
Date: Mon,  8 Nov 2021 13:32:16 +0000 (GMT)	[thread overview]
Message-ID: <20211108133216.792723858401@sourceware.org> (raw)

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

commit r11-9228-gae3227710c71ca693ee43c825f5d0d0fbd3c3773
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Sep 30 15:05:53 2021 +0200

    middle-end/102518 - avoid invalid GIMPLE during inlining
    
    When inlining we have to avoid mapping a non-lvalue parameter
    value into a context that prevents the parameter to be a register.
    Formerly the register were TREE_ADDRESSABLE but now it can be
    just DECL_NOT_GIMPLE_REG_P.
    
    2021-09-30  Richard Biener  <rguenther@suse.de>
    
            PR middle-end/102518
            * tree-inline.c (setup_one_parameter): Avoid substituting
            an invariant into contexts where a GIMPLE register is not valid.
    
            * gcc.dg/torture/pr102518.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr102518.c | 12 ++++++++++++
 gcc/tree-inline.c                       |  6 +++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr102518.c b/gcc/testsuite/gcc.dg/torture/pr102518.c
new file mode 100644
index 00000000000..bd181ec9d99
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr102518.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+struct A {
+  int *x;
+};
+int i;
+int f(int *const c) {
+  struct A * b = (struct A *)(&c);
+  return b->x != 0;
+}
+void g() { f(&i); }
+
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index 6e0c16bc355..48588c41b35 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -3476,7 +3476,11 @@ setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn,
 	 invalid sharing when operand is not really constant.
 	 It is not big deal to prohibit constant propagation here as
 	 we will constant propagate in DOM1 pass anyway.  */
-      if (is_gimple_min_invariant (value)
+      if ((is_gimple_min_invariant (value)
+	   /* When the parameter is used in a context that forces it to
+	      not be a GIMPLE register avoid substituting something that
+	      is not a decl there.  */
+	   && ! DECL_NOT_GIMPLE_REG_P (p))
 	  && useless_type_conversion_p (TREE_TYPE (p),
 						 TREE_TYPE (value))
 	  /* We have to be very careful about ADDR_EXPR.  Make sure


                 reply	other threads:[~2021-11-08 13:32 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=20211108133216.792723858401@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).