diff options
author | Jakub Jelinek <jakub@redhat.com> | 2001-04-25 23:18:20 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2001-04-25 23:18:20 +0200 |
commit | b5cd6849d1c40c64411e1afc2bad31c865ba315a (patch) | |
tree | 6d4ac07ada29786989dcc8c8201e0d13bd597d95 /gcc/c-format.c | |
parent | ad5042df72d0eaed0b7c76c0424b95c5fdbf71f3 (diff) | |
download | gcc-b5cd6849d1c40c64411e1afc2bad31c865ba315a.zip gcc-b5cd6849d1c40c64411e1afc2bad31c865ba315a.tar.gz gcc-b5cd6849d1c40c64411e1afc2bad31c865ba315a.tar.bz2 |
c-format.c (check_format_info_recurse): Handle PLUS_EXPR for format string.
* c-format.c (check_format_info_recurse): Handle
PLUS_EXPR for format string.
* gcc.dg/format/plus-1.c: New test.
From-SVN: r41550
Diffstat (limited to 'gcc/c-format.c')
-rw-r--r-- | gcc/c-format.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/gcc/c-format.c b/gcc/c-format.c index b6270e2..f0b4caf 100644 --- a/gcc/c-format.c +++ b/gcc/c-format.c @@ -1500,6 +1500,7 @@ check_format_info_recurse (status, res, info, format_tree, params, arg_num) int arg_num; { int format_length; + HOST_WIDE_INT offset; const char *format_chars; tree array_size = 0; tree array_init; @@ -1589,6 +1590,35 @@ check_format_info_recurse (status, res, info, format_tree, params, arg_num) return; } + offset = 0; + if (TREE_CODE (format_tree) == PLUS_EXPR) + { + tree arg0, arg1; + + arg0 = TREE_OPERAND (format_tree, 0); + arg1 = TREE_OPERAND (format_tree, 1); + STRIP_NOPS (arg0); + STRIP_NOPS (arg1); + if (TREE_CODE (arg1) == INTEGER_CST) + format_tree = arg0; + else if (TREE_CODE (arg0) == INTEGER_CST) + { + format_tree = arg1; + arg1 = arg0; + } + else + { + res->number_non_literal++; + return; + } + if (!host_integerp (arg1, 1)) + { + res->number_non_literal++; + return; + } + + offset = TREE_INT_CST_LOW (arg1); + } if (TREE_CODE (format_tree) != ADDR_EXPR) { res->number_non_literal++; @@ -1632,6 +1662,16 @@ check_format_info_recurse (status, res, info, format_tree, params, arg_num) format_length = array_size_value; } } + if (offset) + { + if (offset >= format_length) + { + res->number_non_literal++; + return; + } + format_chars += offset; + format_length -= offset; + } if (format_length < 1) { res->number_unterminated++; |