Constant deref of subscript had inserted checks #2818

This commit is contained in:
Christoffer Lerno
2026-01-24 23:24:36 +01:00
parent 9b2fc04959
commit b5e25e3857
3 changed files with 16 additions and 1 deletions

View File

@@ -121,6 +121,7 @@
- Recursive definitions not discovered when initializer is access on other const #2817
- Slice overrun detected late hit codegen assert #2822
- Compile time dereference of a constant slice was too generous #2821
- Constant deref of subscript had inserted checks #2818
### Stdlib changes
- Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads.

View File

@@ -780,7 +780,7 @@ static inline void llvm_emit_subscript(GenContext *c, BEValue *value, Expr *expr
}
llvm_emit_subscript_addr(c, value, expr);
if (safe_mode_enabled() && value->alignment > 1 && !c->emitting_load_store_check && parent_type->type_kind != TYPE_ARRAY)
if (!llvm_is_global_eval(c) && safe_mode_enabled() && value->alignment > 1 && !c->emitting_load_store_check && parent_type->type_kind != TYPE_ARRAY)
{
LLVMValueRef as_int = LLVMBuildPtrToInt(c->builder, value->value, llvm_get_type(c, type_usz), "");
LLVMValueRef align = llvm_const_int(c, type_usz, value->alignment);

View File

@@ -0,0 +1,14 @@
// #target: macos-x64
module test;
int a;
fn int main()
{
static any[] x = { &&((&a + 1)[2]), };
return 0;
}
/* #expect: test.ll
@test.a = global i32 0, align 4
@.__const_slice = private unnamed_addr global [1 x %any] [%any { ptr getelementptr inbounds (i8, ptr getelementptr (i8, ptr @test.a, i64 4), i64 8), i64 ptrtoint (ptr @"$ct.int" to i64) }], align 16
@main.x = internal unnamed_addr global %"any[]" { ptr @.__const_slice, i64 1 }, align 8