This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix -Wunused-but-set* with VLAs (PR c/43981)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 4 May 2010 20:52:52 +0200
- Subject: [PATCH] Fix -Wunused-but-set* with VLAs (PR c/43981)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
If VLA length is a variable rather than say expression involving variables,
we forgot to mark that variable DECL_READ_P.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux. Ok for
trunk?
2010-05-04 Jakub Jelinek <jakub@redhat.com>
PR c/43981
* c-parser.c (c_parser_direct_declarator_inner): Call mark_exp_read
on dimen.
* gcc.dg/Wunused-var-8.c: New test.
--- gcc/c-parser.c.jj 2010-04-27 08:47:19.000000000 +0200
+++ gcc/c-parser.c 2010-05-04 13:21:03.000000000 +0200
@@ -2474,6 +2474,8 @@ c_parser_direct_declarator_inner (c_pars
"expected %<]%>");
return NULL;
}
+ if (dimen)
+ mark_exp_read (dimen);
declarator = build_array_declarator (brace_loc, dimen, quals_attrs,
static_seen, star_seen);
if (declarator == NULL)
--- gcc/testsuite/gcc.dg/Wunused-var-8.c.jj 2010-05-04 13:22:19.000000000 +0200
+++ gcc/testsuite/gcc.dg/Wunused-var-8.c 2010-05-04 13:23:40.000000000 +0200
@@ -0,0 +1,15 @@
+/* PR c/43981 */
+/* { dg-do compile } */
+/* { dg-options "-Wunused" } */
+
+void g (char *);
+
+char
+f (int a)
+{
+ int len = a * 3;
+ char t[len];
+
+ g (t);
+ return t[0];
+}
Jakub