diff --git a/releasenotes.md b/releasenotes.md index aebfa9cea..b3888b902 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -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. diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 15d7c385b..93c32a414 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -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 }; diff --git a/test/unit/regression/int_min.c3 b/test/unit/regression/int_min.c3 new file mode 100644 index 000000000..4c6286aeb --- /dev/null +++ b/test/unit/regression/int_min.c3 @@ -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); +}