------- Comment #9 from rguenther at suse dot de  2008-11-02 12:20 -------
Subject: Re:  [4.2/4.3/4.4 Regression] offset warning should
 be given in the front-end

On Sat, 1 Nov 2008, manu at gcc dot gnu dot org wrote:

> ------- Comment #8 from manu at gcc dot gnu dot org  2008-11-01 17:44 -------
> This is my current patch and it works in this testcase. However, it also
> triggers on cases like: const char *p = str + sizeof(str)
> 
> Perhaps I am doing this at the wrong place. Any suggestions?

Keep in mind that one-after the string is ok, so ...

> 
> @@ -3322,10 +3323,36 @@ pointer_int_sum (enum tree_code resultco
> 
>    /* Create the sum or difference.  */
>    if (resultcode == MINUS_EXPR)
>      intop = fold_build1 (NEGATE_EXPR, sizetype, intop);
> 
> +
> +  if (TREE_CODE (intop) == INTEGER_CST)
> +    {
> +      tree offset_node;
> +      tree string_cst = string_constant (ptrop, &offset_node);
> +
> +      if (string_cst != 0
> +         && !(offset_node && TREE_CODE (offset_node) != INTEGER_CST))
> +       {
> +         HOST_WIDE_INT max = TREE_STRING_LENGTH (string_cst) - 1;

... the -1 is wrong here.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35652

Reply via email to