]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end/102518 - avoid invalid GIMPLE during inlining
authorRichard Biener <rguenther@suse.de>
Thu, 30 Sep 2021 13:05:53 +0000 (15:05 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 8 Nov 2021 12:40:21 +0000 (13:40 +0100)
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.

gcc/testsuite/gcc.dg/torture/pr102518.c [new file with mode: 0644]
gcc/tree-inline.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr102518.c b/gcc/testsuite/gcc.dg/torture/pr102518.c
new file mode 100644 (file)
index 0000000..bd181ec
--- /dev/null
@@ -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); }
+
index 6e0c16bc355efa9a8c4460267ec6d9b41144f669..48588c41b35bf026df7b730f01c07d1ce168ca53 100644 (file)
@@ -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