diff options
author | sayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-07-25 23:21:56 +0000 |
---|---|---|
committer | sayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-07-25 23:21:56 +0000 |
commit | a2d0445dacbd93ce0b21d8641c5315c72727fee1 (patch) | |
tree | fe2cca2c97ebff50cdce92939507476d43dba1e2 /gcc/convert.c | |
parent | 01b1b46d0819b9d111fb9144d1163a9dc86d921f (diff) | |
download | gcc-a2d0445dacbd93ce0b21d8641c5315c72727fee1.tar.gz |
PR middle-end/28473
* convert.c (convert_to_integer): When transforming (T)foo(x) into
bar(x) check that bar's result type can represent all the values of T.
* gcc.dg/fold-convround-1.c: New test case.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@115742 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/convert.c')
-rw-r--r-- | gcc/convert.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/gcc/convert.c b/gcc/convert.c index ab780d8ebd3..27571956a1e 100644 --- a/gcc/convert.c +++ b/gcc/convert.c @@ -388,27 +388,36 @@ convert_to_integer (tree type, tree expr) /* Only convert in ISO C99 mode. */ if (!TARGET_C99_FUNCTIONS) break; - if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_integer_type_node)) - fn = mathfn_built_in (s_intype, BUILT_IN_LLCEIL); - else + if (outprec < TYPE_PRECISION (long_integer_type_node) + || (outprec == TYPE_PRECISION (long_integer_type_node) + && !TYPE_UNSIGNED (type))) fn = mathfn_built_in (s_intype, BUILT_IN_LCEIL); + else if (outprec == TYPE_PRECISION (long_long_integer_type_node) + && !TYPE_UNSIGNED (type)) + fn = mathfn_built_in (s_intype, BUILT_IN_LLCEIL); break; CASE_FLT_FN (BUILT_IN_FLOOR): /* Only convert in ISO C99 mode. */ if (!TARGET_C99_FUNCTIONS) break; - if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_integer_type_node)) - fn = mathfn_built_in (s_intype, BUILT_IN_LLFLOOR); - else + if (outprec < TYPE_PRECISION (long_integer_type_node) + || (outprec == TYPE_PRECISION (long_integer_type_node) + && !TYPE_UNSIGNED (type))) fn = mathfn_built_in (s_intype, BUILT_IN_LFLOOR); + else if (outprec == TYPE_PRECISION (long_long_integer_type_node) + && !TYPE_UNSIGNED (type)) + fn = mathfn_built_in (s_intype, BUILT_IN_LLFLOOR); break; CASE_FLT_FN (BUILT_IN_ROUND): - if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_integer_type_node)) - fn = mathfn_built_in (s_intype, BUILT_IN_LLROUND); - else + if (outprec < TYPE_PRECISION (long_integer_type_node) + || (outprec == TYPE_PRECISION (long_integer_type_node) + && !TYPE_UNSIGNED (type))) fn = mathfn_built_in (s_intype, BUILT_IN_LROUND); + else if (outprec == TYPE_PRECISION (long_long_integer_type_node) + && !TYPE_UNSIGNED (type)) + fn = mathfn_built_in (s_intype, BUILT_IN_LLROUND); break; CASE_FLT_FN (BUILT_IN_RINT): @@ -417,10 +426,13 @@ convert_to_integer (tree type, tree expr) break; /* ... Fall through ... */ CASE_FLT_FN (BUILT_IN_NEARBYINT): - if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (long_long_integer_type_node)) - fn = mathfn_built_in (s_intype, BUILT_IN_LLRINT); - else - fn = mathfn_built_in (s_intype, BUILT_IN_LRINT); + if (outprec < TYPE_PRECISION (long_integer_type_node) + || (outprec == TYPE_PRECISION (long_integer_type_node) + && !TYPE_UNSIGNED (type))) + fn = mathfn_built_in (s_intype, BUILT_IN_LRINT); + else if (outprec == TYPE_PRECISION (long_long_integer_type_node) + && !TYPE_UNSIGNED (type)) + fn = mathfn_built_in (s_intype, BUILT_IN_LLRINT); break; CASE_FLT_FN (BUILT_IN_TRUNC): |