From 366ebc4831e5c4a8b3251d296f05228b623bc3aa Mon Sep 17 00:00:00 2001 From: Alexey Starovoytov Date: Tue, 18 Oct 2005 03:16:21 +0000 Subject: PR middle-end/23522 * fold-const.c (fold_widened_comparison): Do not allow range based constant folding when right operand cannot be unwidened. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@105536 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 7 +++++++ gcc/fold-const.c | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 91973cd7465..439ea318c23 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2005-10-17 Alexey Starovoytov + Ian Lance Taylor + + PR middle-end/23522 + * fold-const.c (fold_widened_comparison): Do not allow range based + constant folding when right operand cannot be unwidened. + 2005-10-17 Richard Henderson * builtins.c (expand_builtin_synchronize): Build a new-style asm diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 015930e5ca6..a6aa1df818c 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6250,8 +6250,6 @@ fold_widened_comparison (enum tree_code code, tree type, tree arg0, tree arg1) return NULL_TREE; arg1_unw = get_unwidened (arg1, shorter_type); - if (!arg1_unw) - return NULL_TREE; /* If possible, express the comparison in the shorter mode. */ if ((code == EQ_EXPR || code == NE_EXPR @@ -6264,7 +6262,9 @@ fold_widened_comparison (enum tree_code code, tree type, tree arg0, tree arg1) return fold_build2 (code, type, arg0_unw, fold_convert (shorter_type, arg1_unw)); - if (TREE_CODE (arg1_unw) != INTEGER_CST) + if (TREE_CODE (arg1_unw) != INTEGER_CST + || TREE_CODE (shorter_type) != INTEGER_TYPE + || !int_fits_type_p (arg1_unw, shorter_type)) return NULL_TREE; /* If we are comparing with the integer that does not fit into the range -- cgit v1.2.3