This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR21509
- From: Richard Guenther <rguenth at tat dot physik dot uni-tuebingen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 11 May 2005 13:01:12 +0200 (CEST)
- Subject: [PATCH] Fix PR21509
This is the patch I happened to find lying around for PR21509 which
I just filed. Added a testcase and went through a make and make
check for the c and c++ format tests.
Ok for mainline and 4.0? Ok for 3.4 as it looks it applies
cleanly there, too?
Thanks,
Richard.
2005-05-11 Richard Guenther <rguenth@gcc.gnu.org>
* c-format.c (check_format_arg): Handle string literals of
the form &"string"[offset].
* g++.dg/warn/format4.C: New testcase.
Index: gcc/c-format.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-format.c,v
retrieving revision 1.74
diff -c -3 -p -r1.74 c-format.c
*** gcc/c-format.c 26 Apr 2005 23:57:55 -0000 1.74
--- gcc/c-format.c 28 Apr 2005 13:24:22 -0000
*************** check_format_arg (void *ctx, tree format
*** 1260,1265 ****
--- 1260,1269 ----
return;
}
format_tree = TREE_OPERAND (format_tree, 0);
+ if (TREE_CODE (format_tree) == ARRAY_REF
+ && host_integerp (TREE_OPERAND (format_tree, 1), 0)
+ && (offset += tree_low_cst (TREE_OPERAND (format_tree, 1), 0)) >= 0)
+ format_tree = TREE_OPERAND (format_tree, 0);
if (TREE_CODE (format_tree) == VAR_DECL
&& TREE_CODE (TREE_TYPE (format_tree)) == ARRAY_TYPE
&& (array_init = decl_constant_value (format_tree)) != format_tree
// { dg-do compile }
// { dg-options "-Wformat=2" }
extern "C" int printf (const char*, ...);
void foo(int i)
{
printf("Hello World %d!\n", i);
printf(&"Hello World %d!\n"[0], i);
printf(&"Hello World %d!\n"[6], i);
printf(&"Hello World %d!\n"[8]-2, i);
printf(&"Hello World %d!\n"[4]+2, i);
}