diff options
| author | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-05-13 09:48:12 +0000 |
|---|---|---|
| committer | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-05-13 09:48:12 +0000 |
| commit | b02995ae42a294cc4bd6e33801ed95472ec2d86f (patch) | |
| tree | b9d23e0b16c4bdc7b552843f6fdf8735223307d0 /gcc | |
| parent | 729b154cdbf9ea09624bb4bdf23204dda20a4a18 (diff) | |
| download | ppe42-gcc-b02995ae42a294cc4bd6e33801ed95472ec2d86f.tar.gz ppe42-gcc-b02995ae42a294cc4bd6e33801ed95472ec2d86f.zip | |
2005-05-14 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@99652 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
| -rw-r--r-- | gcc/ChangeLog | 7 | ||||
| -rw-r--r-- | gcc/c-format.c | 4 | ||||
| -rw-r--r-- | gcc/testsuite/g++.dg/warn/format4.C | 13 |
3 files changed, 24 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3203e67ddfd..286c65cd482 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2005-05-13 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. + 2005-05-13 Kazu Hirata <kazu@cs.umass.edu> * config/mips/3000.md, config/mips/4000.md, diff --git a/gcc/c-format.c b/gcc/c-format.c index dd570ab23dc..daa071e61ab 100644 --- a/gcc/c-format.c +++ b/gcc/c-format.c @@ -1260,6 +1260,10 @@ check_format_arg (void *ctx, tree format_tree, 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 diff --git a/gcc/testsuite/g++.dg/warn/format4.C b/gcc/testsuite/g++.dg/warn/format4.C new file mode 100644 index 00000000000..fa622fceb4f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/format4.C @@ -0,0 +1,13 @@ +// { 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); +} |

