[PATCH] middle-end/99122 - more VLA inlining fixes
Richard Biener
rguenther@suse.de
Fri Feb 19 13:20:18 GMT 2021
This avoids declaring a function with VLA arguments or return values
as inlineable. IPA CP still ICEs, so the testcase has that disabled.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
2021-02-19 Richard Biener <rguenther@suse.de>
PR middle-end/99122
* tree-inline.c (inline_forbidden_p): Do not inline functions
with VLA arguments or return value.
* gcc.dg/pr99122-3.c: New testcase.
---
gcc/testsuite/gcc.dg/pr99122-3.c | 19 +++++++++++++++++++
gcc/tree-inline.c | 10 ++++++++++
2 files changed, 29 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/pr99122-3.c
diff --git a/gcc/testsuite/gcc.dg/pr99122-3.c b/gcc/testsuite/gcc.dg/pr99122-3.c
new file mode 100644
index 00000000000..6aa5b2912ca
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr99122-3.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -g -fno-ipa-cp -w" } */
+
+static int foo ();
+
+int
+bar (int n)
+{
+ return foo (n, 2.0);
+}
+
+static inline int
+foo (int n, struct T { char a[n]; } b)
+{
+ int r = 0, i;
+ for (i = 0; i < n; i++)
+ r += b.a[i];
+ return r;
+}
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index 01a08cf27be..c993b1fee8a 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -4022,6 +4022,16 @@ inline_forbidden_p (tree fndecl)
wi.info = (void *) fndecl;
wi.pset = &visited_nodes;
+ /* We cannot inline a function with a VLA typed argument or result since
+ we have no implementation materializing a variable of such type in
+ the caller. */
+ if (COMPLETE_TYPE_P (TREE_TYPE (TREE_TYPE (fndecl)))
+ && !poly_int_tree_p (TYPE_SIZE (TREE_TYPE (TREE_TYPE (fndecl)))))
+ return true;
+ for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
+ if (!poly_int_tree_p (DECL_SIZE (parm)))
+ return true;
+
FOR_EACH_BB_FN (bb, fun)
{
gimple *ret;
--
2.26.2
More information about the Gcc-patches
mailing list