public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r9-9342] c/99224 - avoid ICEing on invalid __builtin_next_arg
@ 2021-04-12 11:23 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-04-12 11:23 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:c7712377876cb7e6c3ca3ce479245c6386dfc9a6

commit r9-9342-gc7712377876cb7e6c3ca3ce479245c6386dfc9a6
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Feb 24 09:18:05 2021 +0100

    c/99224 - avoid ICEing on invalid __builtin_next_arg
    
    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)

Diff:
---
 gcc/builtins.c                 | 3 ++-
 gcc/testsuite/gcc.dg/pr99224.c | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/builtins.c b/gcc/builtins.c
index e8e43f53ec6..39ba87a6759 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -10267,7 +10267,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
index 00000000000..f6e9ac8eba3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr99224.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+
+void f (char *c, ...)
+{
+  __builtin_next_arg (*c); /* { dg-warning "not last named argument" } */
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-12 11:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12 11:23 [gcc r9-9342] c/99224 - avoid ICEing on invalid __builtin_next_arg Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).