On Tue, Feb 20, 2018 at 12:03:26PM -0700, Martin Sebor wrote: > PR tree-optimization/84478 - [8 Regression] pdftex miscompilation on i386 > > gcc/ChangeLog: > > PR tree-optimization/84478 > * gimple-fold.c (get_range_strlen): Set *MINLEN to zero. > (get_range_strlen): Reset range on failure. > > gcc/testsuite/ChangeLog: > > PR tree-optimization/84478 > * gcc.c-torture/execute/pr84478.c: New test. > > Index: gcc/gimple-fold.c > =================================================================== > --- gcc/gimple-fold.c (revision 257796) > +++ gcc/gimple-fold.c (working copy) > @@ -1369,7 +1369,10 @@ get_range_strlen (tree arg, tree length[2], bitmap > tree eltype = TREE_TYPE (type); > if (TREE_CODE (type) != ARRAY_TYPE > || !INTEGRAL_TYPE_P (eltype)) > - return false; > + { > + *minlen = ssize_int (0); > + return false; > + }
This is just one of the 13 spots where we return false, so this doesn't look safe or sufficient to me, even when you actually honor the return value in 2 argument get_range_strlen. You'd really need to do { if (fuzzy) - *maxlen = build_all_ones_cst (size_type_node); + { + *minlen = size_int (0); + *maxlen = build_all_ones_cst (size_type_node); + } else return false; } or just drop that if (fuzzy) stuff from there, but that breaks the warning tests. It would help if you explained why you think it is a good idea ignoring the other phi arguments if you have one (or more) where you can determine length. One variation of my patch could be instead of adding type 3 change fuzzy from bool to int, and use fuzzy == 1 for the strlen value ranges and fuzzy == 2 for the warning code (i.e. 2 operand get_range_strlen). Note, my patch passed regtest on both x86_64-linux and i686-linux. Jakub