On 08/22/2018 08:41 AM, Bernd Edlinger wrote:
Hi!


This patch adds some more checks to c_getstr to fix PR middle-end/87053
wrong code bug.

Unfortunately this patch alone is not sufficient to fix the problem,
but also the patch for PR 86714 that hardens c_getstr is necessary
to prevent the wrong folding.


Bootstrapped and reg-tested on top of my PR 86711/86714 patch.
Is it OK for trunk?

This case is also the subject of the patch I submitted back in
July for 86711/86714 and 86552.  With it, GCC avoid folding
the strlen call early and warns for the missing nul:

warning: ‘__builtin_strlen’ argument missing terminating nul [-Wstringop-overflow=]
   if (__builtin_strlen (u.z) != 7)
       ^~~~~~~~~~~~~~~~

The patch doesn't doesn't prevent all such strings from being
folded and it eventually lets fold_builtin_strlen() do its thing:

          /* To avoid warning multiple times about unterminated
             arrays only warn if its length has been determined
             and is being folded to a constant.  */
          if (nonstr)
            warn_string_no_nul (loc, NULL_TREE, fndecl, nonstr);

          return fold_convert_loc (loc, type, len);

Handling this case is a matter of avoiding the folding here as
well and moving the warning later.

Since my patch is still in the review queue and does much more
than just prevent folding of non-nul terminated arrays it should
be reviewed first.

Martin

Reply via email to