diff --git a/releasenotes.md b/releasenotes.md index 09c46ce3a..636b6f25c 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -33,6 +33,7 @@ - Using `defer catch` with a (void), would cause an assertion. #2580 - Fix decl attribute in the wrong place causing an assertion. #2581 - Passing a single value to `@wasm` would ignore the renaming. +- `*(int*)1` incorrectly yielded an assert in LLVM IR lowering #2584. ### Stdlib changes diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index fe6721704..01a45747f 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -2371,7 +2371,7 @@ static inline void llvm_emit_deref(GenContext *c, BEValue *value, Expr *inner, T llvm_emit_expr(c, value, inner); llvm_value_rvalue(c, value); AlignSize alignment = type_abi_alignment(type); - if (safe_mode_enabled()) + if (safe_mode_enabled() && !expr_is_const(inner)) { LLVMValueRef check = LLVMBuildICmp(c->builder, LLVMIntEQ, value->value, llvm_get_zero(c, inner->type), "checknull"); scratch_buffer_clear(); diff --git a/test/test_suite/safe/deref_absolute.c3t b/test/test_suite/safe/deref_absolute.c3t new file mode 100644 index 000000000..7fb637894 --- /dev/null +++ b/test/test_suite/safe/deref_absolute.c3t @@ -0,0 +1,6 @@ +module main; + +fn void main() +{ + int x = *(int*)1; +} \ No newline at end of file