Skip to content

Commit eef2db7

Browse files
committed
revert commit b8b6a5f
As it will cause printf("%llu\n", (unsigned long long)1e19); output 9223372036854775808 instead of 10000000000000000000
1 parent c6afdff commit eef2db7

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

tccgen.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -3252,10 +3252,7 @@ static void gen_cast(CType *type)
32523252
vtop->c.i = (vtop->c.ld != 0);
32533253
} else {
32543254
if(sf)
3255-
/* the range of [int64_t] is enough to hold the integer part of any float value.
3256-
Meanwhile, converting negative double to unsigned integer is UB.
3257-
So first convert to [int64_t] here. */
3258-
vtop->c.i = (int64_t)vtop->c.ld;
3255+
vtop->c.i = vtop->c.ld;
32593256
else if (sbt_bt == VT_LLONG || (PTR_SIZE == 8 && sbt == VT_PTR))
32603257
;
32613258
else if (sbt & VT_UNSIGNED)

tests/tests2/134_double_to_signed.c

+2
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ int main() {
77
printf("%d\n", (int)-2147483648.0);
88
d = -2147483648.0;
99
printf("%d\n", (int)d);
10+
11+
printf("%llu\n", (unsigned long long)1e19);
1012
}

tests/tests2/134_double_to_signed.expect

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
-1
33
-2147483648
44
-2147483648
5+
10000000000000000000

0 commit comments

Comments
 (0)