Skip to content

Commit

Permalink
revert commit b8b6a5f
Browse files Browse the repository at this point in the history
As it will cause printf("%llu\n", (unsigned long long)1e19); output
9223372036854775808
instead of
10000000000000000000
  • Loading branch information
kbkpbot committed Dec 30, 2024
1 parent c6afdff commit eef2db7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
5 changes: 1 addition & 4 deletions tccgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions tests/tests2/134_double_to_signed.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions tests/tests2/134_double_to_signed.expect
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
-1
-2147483648
-2147483648
10000000000000000000

0 comments on commit eef2db7

Please sign in to comment.