[PATCH, C] Fix format warnings
Richard Guenther
rguenth@tat.physik.uni-tuebingen.de
Tue Apr 26 14:48:00 GMT 2005
This patch makes the C frontend not warn that a format string
is not literal for things like
char *a = "Foo";
printf(&a[0]);
This will trigger everywhere in the format testsuite if the
C frontend starts emitting array-to-pointer decay as &a[0].
Compiled and tested on i686-unknown-linux for C.
Ok for mainline?
Thanks,
Richard.
2005-04-26 Richard Guenther <rguenth@gcc.gnu.org>
* c-format.c (check_format_arg): Handle &a[0] the same
as &a.
Index: c-format.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-format.c,v
retrieving revision 1.73
diff -c -3 -p -r1.73 c-format.c
*** c-format.c 23 Apr 2005 21:27:31 -0000 1.73
--- c-format.c 26 Apr 2005 14:33:35 -0000
*************** check_format_arg (void *ctx, tree format
*** 1260,1265 ****
--- 1260,1268 ----
return;
}
format_tree = TREE_OPERAND (format_tree, 0);
+ if (TREE_CODE (format_tree) == ARRAY_REF
+ && integer_zerop (TREE_OPERAND (format_tree, 1)))
+ 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
More information about the Gcc-patches
mailing list