Unified · Split
| @@ -3249,7 +3249,10 @@ error: · 3248 unmodified lines | |||
| 3249 | vtop->c.i = (vtop->c.ld != 0); | 3249 | vtop->c.i = (vtop->c.ld != 0); |
| 3250 | } else { | 3250 | } else { |
| 3251 | if(sf) | 3251 | if(sf) |
| 3252 | vtop->c.i = vtop->c.ld; | 3252 | /* the range of [int64_t] is enough to hold the integer part of any float value. |
| 3253 | Meanwhile, converting negative double to unsigned integer is UB. | ||
| 3254 | So first convert to [int64_t] here. */ | ||
| 3255 | vtop->c.i = (int64_t)vtop->c.ld; | ||
| 3253 | else if (sbt_bt == VT_LLONG || (PTR_SIZE == 8 && sbt == VT_PTR)) | 3256 | else if (sbt_bt == VT_LLONG || (PTR_SIZE == 8 && sbt == VT_PTR)) |
| 3254 | ; | 3257 | ; |
| 3255 | else if (sbt & VT_UNSIGNED) | 3258 | else if (sbt & VT_UNSIGNED) |
| @@ -0,0 +1,10 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | int main() { | ||
| 3 | printf("%d\n", (int)-1.0); | ||
| 4 | double d = -1.0; | ||
| 5 | printf("%d\n", (int)d); | ||
| 6 | |||
| 7 | printf("%d\n", (int)-2147483648.0); | ||
| 8 | d = -2147483648.0; | ||
| 9 | printf("%d\n", (int)d); | ||
| 10 | } | ||
| @@ -0,0 +1,4 @@ | |||
| 1 | -1 | ||
| 2 | -1 | ||
| 3 | -2147483648 | ||
| 4 | -2147483648 | ||