diff --git a/releasenotes.md b/releasenotes.md index 0ee3052a3..b049ca9a1 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -19,6 +19,7 @@ - Compiler assert when using generic parameters list without any parameters. #2369 - Parsing difference between "0x00." and "0X00." literals #2371 - Fixed bug generating `$c += 1` when `$c` was derived from a pointer but behind a cast. +- Compiler segfault when using bitwise not on number literal cast to bitstruct #2373. ### Stdlib changes - Add `==` to `Pair`, `Triple` and TzDateTime. Add print to `Pair` and `Triple`. diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 74955fa85..fb9aedde0 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -8575,7 +8575,7 @@ static inline bool sema_expr_analyse_bit_not(SemaContext *context, Expr *expr, b } VALID_VEC: - if (is_bitstruct && sema_cast_const(inner)) + if (is_bitstruct && sema_cast_const(inner) && expr_is_const_initializer(inner)) { expr_replace(expr, inner); sema_invert_bitstruct_const_initializer(expr->const_expr.initializer); diff --git a/test/test_suite/bitstruct/bitstruct_negate_cast.c3t b/test/test_suite/bitstruct/bitstruct_negate_cast.c3t new file mode 100644 index 000000000..830545a87 --- /dev/null +++ b/test/test_suite/bitstruct/bitstruct_negate_cast.c3t @@ -0,0 +1,12 @@ +// #target: macos-x64 +module test; +bitstruct Foo : uint +{ + bool test : 2; +} + +fn int main() +{ + ~(Foo)2; + return 0; +}