c/99224 - avoid ICEing on invalid __builtin_next_arg
authorRichard Biener <rguenther@suse.de>
Wed, 24 Feb 2021 08:18:05 +0000 (09:18 +0100)
committerRichard Biener <rguenther@suse.de>
Wed, 24 Feb 2021 09:24:14 +0000 (10:24 +0100)
This avoids crashes with __builtin_next_arg on non-parameters.  For
the specific testcase we arrive with an anonymous SSA_NAME so that
SSA_NAME_VAR becomes NULL and we crash.

2021-02-24  Richard Biener  <rguenther@suse.de>

PR c/99224
* builtins.c (fold_builtin_next_arg): Avoid NULL arg.

* gcc.dg/pr99224.c: New testcase.

gcc/builtins.c
gcc/testsuite/gcc.dg/pr99224.c [new file with mode: 0644]

index 0aed008..42150ce 100644 (file)
@@ -12597,7 +12597,8 @@ fold_builtin_next_arg (tree exp, bool va_start_p)
       arg = CALL_EXPR_ARG (exp, 0);
     }
 
-  if (TREE_CODE (arg) == SSA_NAME)
+  if (TREE_CODE (arg) == SSA_NAME
+      && SSA_NAME_VAR (arg))
     arg = SSA_NAME_VAR (arg);
 
   /* We destructively modify the call to be __builtin_va_start (ap, 0)
diff --git a/gcc/testsuite/gcc.dg/pr99224.c b/gcc/testsuite/gcc.dg/pr99224.c
new file mode 100644 (file)
index 0000000..f6e9ac8
--- /dev/null
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+
+void f (char *c, ...)
+{
+  __builtin_next_arg (*c); /* { dg-warning "not last named argument" } */
+}