The -Walloca pass can receive a malformed alloca, courtesy of someone providing a faulty prototype.  This was causing an ICE because we assumed alloca calls had at least one argument, which the testcase does not:

+void *alloca ();
+__typeof__(alloca ()) a () { return alloca (); }

I don't believe it should be the responsibility of the -Walloca-larger-than=* pass to warn against such things, so I propose we just ignore this.

I also think we should handle this testcase, regardless of the target having an alloca builtin, since the testcase includes its own prototype.  Thus, the missing "{dg-require-effect-target alloca}".

OK?

gcc/

	PR tree-optimization/84224
	* gimple-ssa-warn-alloca.c (execute): Do not ICE on malformed
	allocas.

diff --git a/gcc/gimple-ssa-warn-alloca.c b/gcc/gimple-ssa-warn-alloca.c
index 941810a997e..7457a16d21f 100644
--- a/gcc/gimple-ssa-warn-alloca.c
+++ b/gcc/gimple-ssa-warn-alloca.c
@@ -443,9 +443,10 @@ pass_walloca::execute (function *fun)
 	  gimple *stmt = gsi_stmt (si);
 	  location_t loc = gimple_location (stmt);
 
-	  if (!gimple_alloca_call_p (stmt))
+	  if (!gimple_alloca_call_p (stmt)
+	      /* A faulty prototype can yield a malformed alloca() call.  */
+	      || gimple_call_num_args (stmt) < 1)
 	    continue;
-	  gcc_assert (gimple_call_num_args (stmt) >= 1);
 
 	  const bool is_vla
 	    = gimple_call_alloca_for_var_p (as_a <gcall *> (stmt));
diff --git a/gcc/testsuite/gcc.dg/Walloca-16.c b/gcc/testsuite/gcc.dg/Walloca-16.c
new file mode 100644
index 00000000000..3ee96a9570a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Walloca-16.c
@@ -0,0 +1,6 @@
+/* PR tree-optimization/84224 */
+/* { dg-do compile } */
+/* { dg-options "-O0 -Walloca" } */
+
+void *alloca ();
+__typeof__(alloca ()) a () { return alloca (); }

Reply via email to