On Mon, 14 Jul 2014, Richard Biener wrote: > On Fri, 11 Jul 2014, Jakub Jelinek wrote: > > > On Fri, Jul 11, 2014 at 03:36:15PM +0200, Richard Biener wrote: > > > *************** c_strlen (tree src, int only_value) > > > *** 606,612 **** > > > > > > /* If the offset is known to be out of bounds, warn, and call strlen > > > at > > > runtime. */ > > > ! if (offset < 0 || offset > max) > > > { > > > /* Suppress multiple warnings for propagated constant strings. */ > > > if (! TREE_NO_WARNING (src)) > > > --- 610,617 ---- > > > > > > /* If the offset is known to be out of bounds, warn, and call strlen > > > at > > > runtime. */ > > > ! if (only_value != 2 > > > ! && (offset < 0 || offset > max)) > > > { > > > /* Suppress multiple warnings for propagated constant strings. */ > > > if (! TREE_NO_WARNING (src)) > > > > This looks wrong. I'd say you only want to disable the warning for > > only_value != 2, but still return NULL_TREE, otherwise the strlen call will > > be out of bounds in the compiler. So move only_value != 2 down to the > > second if ? > > Hmm, yeah. Probably doesn't matter for this use but I'm testing the > obvious fix.
Fixed like so, bootstrapped and tested on x86_64-unknown-linux-gnu. Richard. 2014-07-14 Richard Biener <rguent...@suse.de> * builtins.c (c_strlen): Make only_value == 2 really only affect warning generation. Index: gcc/builtins.c =================================================================== --- gcc/builtins.c (revision 212513) +++ gcc/builtins.c (working copy) @@ -610,11 +610,11 @@ c_strlen (tree src, int only_value) /* If the offset is known to be out of bounds, warn, and call strlen at runtime. */ - if (only_value != 2 - && (offset < 0 || offset > max)) + if (offset < 0 || offset > max) { /* Suppress multiple warnings for propagated constant strings. */ - if (! TREE_NO_WARNING (src)) + if (only_value != 2 + && !TREE_NO_WARNING (src)) { warning_at (loc, 0, "offset outside bounds of constant string"); TREE_NO_WARNING (src) = 1;