public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r8-10893] c-family: Avoid ICE on va_arg [PR99324]
@ 2021-04-22 16:51 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-04-22 16:51 UTC (permalink / raw)
  To: gcc-cvs

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

commit r8-10893-gcd7c8ae0178c5dad7e8cec6c001e9e334d8c31bc
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Mar 3 09:55:19 2021 +0100

    c-family: Avoid ICE on va_arg [PR99324]
    
    build_va_arg calls the middle-end mark_addressable, which e.g. requires that
    cfun is non-NULL.  The following patch calls instead c_common_mark_addressable_vec
    which is the c-family variant similarly to the FE c_mark_addressable and
    cxx_mark_addressable, except that it doesn't error on addresses of register
    variables.  As the taking of the address is artificial for the .VA_ARG
    ifn and when that is lowered goes away, it is similar case to the vector
    subscripting for which c_common_mark_addressable_vec has been added.
    
    2021-03-03  Jakub Jelinek  <jakub@redhat.com>
    
            PR c/99324
            * c-common.c (build_va_arg): Call c_common_mark_addressable_vec
            instead of mark_addressable.  Fix a comment typo -
            neutrallly -> neutrally.
    
            * gcc.c-torture/compile/pr99324.c: New test.
    
    (cherry picked from commit 0e87dc86eb56f732a41af2590f0b807031003fbe)

Diff:
---
 gcc/c-family/c-common.c                       |  6 +++---
 gcc/testsuite/gcc.c-torture/compile/pr99324.c | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 6ce5744a373..d68987c4810 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -4453,7 +4453,7 @@ build_va_arg (location_t loc, tree expr, tree type)
       if (canon_va_type == NULL_TREE)
 	error_at (loc, "first argument to %<va_arg%> not of type %<va_list%>");
 
-      /* Let's handle things neutrallly, if expr:
+      /* Let's handle things neutrally, if expr:
 	 - has undeclared type, or
 	 - is not an va_list type.  */
       return build_va_arg_1 (loc, type, error_mark_node);
@@ -4465,7 +4465,7 @@ build_va_arg (location_t loc, tree expr, tree type)
 
       /* Take the address, to get '&ap'.  Note that &ap is not a va_list
 	 type.  */
-      mark_addressable (expr);
+      c_common_mark_addressable_vec (expr);
       expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (expr)), expr);
 
       return build_va_arg_1 (loc, type, expr);
@@ -4527,7 +4527,7 @@ build_va_arg (location_t loc, tree expr, tree type)
 
       /* Take the address, to get '&ap'.  Make sure it's a pointer to array
 	 elem type.  */
-      mark_addressable (expr);
+      c_common_mark_addressable_vec (expr);
       expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (canon_va_type)),
 		     expr);
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr99324.c b/gcc/testsuite/gcc.c-torture/compile/pr99324.c
new file mode 100644
index 00000000000..7a41e5c64b1
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr99324.c
@@ -0,0 +1,19 @@
+/* PR c/99324 */
+
+#include <stdarg.h>
+
+int
+foo (int x, ...)
+{
+  va_list a;
+  va_start (a, x);
+  int b[6] = {};
+  int bar (c)
+    int c[1][va_arg (a, int)];
+  {
+    return sizeof c[0];
+  }
+  int r = bar (b);
+  va_end (a);
+  return r;
+}


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

only message in thread, other threads:[~2021-04-22 16:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22 16:51 [gcc r8-10893] c-family: Avoid ICE on va_arg [PR99324] Jakub Jelinek

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).