diff --git a/tccgen.c b/tccgen.c index aedbc0c8b..315a3a2d2 100644 --- a/tccgen.c +++ b/tccgen.c @@ -3252,10 +3252,7 @@ static void gen_cast(CType *type) vtop->c.i = (vtop->c.ld != 0); } else { if(sf) - /* the range of [int64_t] is enough to hold the integer part of any float value. - Meanwhile, converting negative double to unsigned integer is UB. - So first convert to [int64_t] here. */ - vtop->c.i = (int64_t)vtop->c.ld; + vtop->c.i = vtop->c.ld; else if (sbt_bt == VT_LLONG || (PTR_SIZE == 8 && sbt == VT_PTR)) ; else if (sbt & VT_UNSIGNED) diff --git a/tests/tests2/134_double_to_signed.c b/tests/tests2/134_double_to_signed.c index a9f5e0eda..a8abbb1f2 100644 --- a/tests/tests2/134_double_to_signed.c +++ b/tests/tests2/134_double_to_signed.c @@ -7,4 +7,6 @@ int main() { printf("%d\n", (int)-2147483648.0); d = -2147483648.0; printf("%d\n", (int)d); + + printf("%llu\n", (unsigned long long)1e19); } diff --git a/tests/tests2/134_double_to_signed.expect b/tests/tests2/134_double_to_signed.expect index 468a382d8..950c416a7 100644 --- a/tests/tests2/134_double_to_signed.expect +++ b/tests/tests2/134_double_to_signed.expect @@ -2,3 +2,4 @@ -1 -2147483648 -2147483648 +10000000000000000000