]> 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>
Fri, 1 Oct 2021 06:26:26 +0000 (08:26 +0200)
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 5e50e8013e2af3b1ab6f9b45f6421a8933f23dc2..e292a144967c0f74768a5716c509defceb8d5fd5 100644 (file)
@@ -3490,7 +3490,11 @@ setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn,
       /* We may produce non-gimple trees by adding NOPs or introduce invalid
         sharing when the value is not constant or DECL.  And we need to make
         sure that it cannot be modified from another path in the callee.  */
-      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))
           || (DECL_P (value) && TREE_READONLY (value))
           || (auto_var_in_fn_p (value, id->dst_fn)
               && !TREE_ADDRESSABLE (value)))