From: Aldy Hernandez Date: Fri, 13 Apr 2018 09:24:58 +0000 (+0000) Subject: Rewrite size_must_be_zero_p with irange infrastructure. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0bcfd10047731bea91d5a7709d10d8e9177c3826;p=thirdparty%2Fgcc.git Rewrite size_must_be_zero_p with irange infrastructure. Rewrite size_must_be_zero_p with irange infrastructure. Previous implementation did not get the bits in [7fff,ffff]. This fixes a handful of regressions. From-SVN: r259370 --- diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 521bd75fcd8a..af957ce05a2f 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -642,9 +642,25 @@ var_decl_component_p (tree var) static bool size_must_be_zero_p (tree size) { - return (integer_zerop (size) - || (TREE_CODE (size) == SSA_NAME - && irange (size).zero_p ())); + if (integer_zerop (size)) + return true; + + if (TREE_CODE (size) != SSA_NAME) + return false; + + tree type = TREE_TYPE (size); + int prec = TYPE_PRECISION (type); + + wide_int wone = wi::one (prec); + + /* Compute the value of SSIZE_MAX, the largest positive value that + can be stored in ssize_t, the signed counterpart of size_t. */ + wide_int ssize_max = wi::lshift (wi::one (prec), prec - 1) - 1; + + irange not_zero (type, wone, ssize_max); + irange size_range (size); + return (size_range.contains_p (0) + && size_range.intersect (not_zero).empty_p ()); } /* Fold function call to builtin mem{{,p}cpy,move}. Try to detect and