Fix of int.min incorrect behaviour #1154.

This commit is contained in:
Christoffer Lerno
2024-02-26 18:13:40 +01:00
parent f0dd0e8f92
commit 4ba033fc84
3 changed files with 14 additions and 4 deletions

View File

@@ -12,6 +12,7 @@
- Fixed array calculation for npot2 vectors.
- $$memcpy_inline and $$memset_inline fixed.
- `.$Type = ...` and `.$foo = ...` now works #1156.
- `int.min` incorrect behaviour #1154.
### Stdlib changes
- Added `new_aligned` and `alloc_aligned` functions to prevent accidental under-alignment when allocating simd.

View File

@@ -3403,16 +3403,16 @@ static inline bool sema_create_const_min(SemaContext *context, Expr *expr, Type
switch (flat->type_kind)
{
case TYPE_I8:
expr->const_expr.ixx.i = (Int128){ 0, 0x80 };
expr->const_expr.ixx.i = (Int128){ 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFF80 };
break;
case TYPE_I16:
expr->const_expr.ixx.i = (Int128){ 0, 0x8000 };
expr->const_expr.ixx.i = (Int128){ 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFF8000 };
break;
case TYPE_I32:
expr->const_expr.ixx.i = (Int128){ 0, 1ULL << 31 };
expr->const_expr.ixx.i = (Int128){ 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFF80000000 };
break;
case TYPE_I64:
expr->const_expr.ixx.i = (Int128){ 0, 1ULL << 63 };
expr->const_expr.ixx.i = (Int128){ 0xFFFFFFFFFFFFFFFF, 1ULL << 63 };
break;
case TYPE_I128:
expr->const_expr.ixx.i = (Int128){ 1ULL << 63, 0 };

View File

@@ -0,0 +1,9 @@
fn void! int_min() @test
{
assert(int.min == -2147483648);
assert((float)int.min == -2147483648.0f);
assert(short.min == -32768);
assert((float)short.min == -32768.0f);
assert(ichar.min == -128);
assert((float)ichar.min == -128.0f);
}