diff options
| author | sayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-01-01 20:33:28 +0000 |
|---|---|---|
| committer | sayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-01-01 20:33:28 +0000 |
| commit | bfc80611c8d699d0d574b8ce90a56a509702828f (patch) | |
| tree | dabb115839d326d5afb180d661686ff9d70acb98 | |
| parent | cd2b30fea976020afc609c8a013363617a147d62 (diff) | |
| download | ppe42-gcc-bfc80611c8d699d0d574b8ce90a56a509702828f.tar.gz ppe42-gcc-bfc80611c8d699d0d574b8ce90a56a509702828f.zip | |
* tree.c (int_fits_type_p): A narrower type always fits in a
wider one, except for negative values into unsigned types.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@92788 138bc75d-0d04-0410-961f-82ee72b054a4
| -rw-r--r-- | gcc/ChangeLog | 6 | ||||
| -rw-r--r-- | gcc/tree.c | 15 |
2 files changed, 17 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 159941cec25..503f1534134 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,4 +1,10 @@ 2005-01-01 Roger Sayle <roger@eyesopen.com> + Olivier Hainque <hainque@act-europe.fr> + + * tree.c (int_fits_type_p): A narrower type always fits in a + wider one, except for negative values into unsigned types. + +2005-01-01 Roger Sayle <roger@eyesopen.com> * tree.c (int_fits_type_p): Compare the result of force_fit_type with the original constant rather than require TREE_OVERFLOW. diff --git a/gcc/tree.c b/gcc/tree.c index ca97e30351e..e648aaa6b45 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -4879,10 +4879,17 @@ int_fits_type_p (tree c, tree type) /* Perform some generic filtering first, which may allow making a decision even if the bounds are not constant. First, negative integers never fit in unsigned types, */ - if ((TYPE_UNSIGNED (type) && tree_int_cst_sgn (c) < 0) - /* Also, unsigned integers with top bit set never fit signed types. */ - || (! TYPE_UNSIGNED (type) - && TYPE_UNSIGNED (TREE_TYPE (c)) && tree_int_cst_msb (c))) + if (TYPE_UNSIGNED (type) && tree_int_cst_sgn (c) < 0) + return 0; + + /* Second, narrower types always fit in wider ones. */ + if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c))) + return 1; + + /* Third, unsigned integers with top bit set never fit signed types. */ + if (! TYPE_UNSIGNED (type) + && TYPE_UNSIGNED (TREE_TYPE (c)) + && tree_int_cst_msb (c)) return 0; /* If at least one bound of the type is a constant integer, we can check |

