]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
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>
Tue, 16 Mar 2021 13:11:03 +0000 (14:11 +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.

(cherry picked from commit 084963dcaca2f0836366fdb001561e29ecbfb483)

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

index 610273d91e93b1bb17ed7086e096a9a90d4a07d7..10b6fd3bb4d721a47c40d77cf4c4e53528cdb956 100644 (file)
@@ -10843,7 +10843,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" } */
+}