On Tue, 17 Jul 2018, Martin Sebor wrote: > The attached update takes care of a couple of problems pointed > out by Bernd Edlinger in his comments on the bug. The ICE he > mentioned in comment #20 was due mixing sizetype, ssizetype, > and size_type_node in c_strlen(). AFAICS, some of it predates > the patch but my changes made it worse and also managed trigger > it.
+ has no internal zero bytes. If the offset falls within the bounds + of the string subtract the offset from the length of the string, + and return that. Otherwise the length is zero. Take care to + use SAVE_EXPR in case the OFFSET has side-effects. */ + tree offsave = TREE_SIDE_EFFECTS (byteoff) ? save_expr (byteoff) : byteoff; + offsave = fold_convert (ssizetype, offsave); + tree condexp = fold_build2_loc (loc, LE_EXPR, boolean_type_node, offsave, + build_int_cst (ssizetype, len * eltsize)); + tree lenexp = size_diffop_loc (loc, ssize_int (strelts * eltsize), offsave); + return fold_build3_loc (loc, COND_EXPR, ssizetype, condexp, lenexp, + build_zero_cst (ssizetype)); in what case are you expecting to return an actual COND_EXRP and why is that useful? You return a signed value but bother to guard it so it is never less than zero. Why? Why not simply return the difference as you did before but with the side-effects properly handled? > On 07/17/2018 09:19 AM, Martin Sebor wrote: > > My enhancement to extract constant strings out of complex > > aggregates committed last week introduced a couple of bugs in > > dealing with non-constant indices and offsets. One of the bugs > > was fixed earlier today (PR 86528) but another one remains. It > > causes strlen (among other functions) to incorrectly fold > > expressions involving a non-constant index into an array of > > strings by treating the index the same as a non-consatnt > > offset into it. > > > > The non-constant index should either prevent the folding, or it > > needs to handle it differently from an offset. > > > > The attached patch takes the conservative approach of avoiding > > the folding in this case. The remaining changes deal with > > the fallout from the fix. > > > > Tested on x86_64-linux. > > > > Martin > > > > -- Richard Biener <rguent...@suse.de> SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)