- Bug with slice acces as inline struct member #2088.

This commit is contained in:
Christoffer Lerno
2025-04-16 17:02:22 +02:00
parent a44e932806
commit 37ffd92f7b
3 changed files with 29 additions and 6 deletions

View File

@@ -20,6 +20,7 @@
- Regression with invalid setup of the WASM temp allocator. - Regression with invalid setup of the WASM temp allocator.
- Correctly detect multiple overloads of the same type. - Correctly detect multiple overloads of the same type.
- ABI bug on x64 Linux / MacOS when passing a union containing a struct of 3 floats. #2087 - ABI bug on x64 Linux / MacOS when passing a union containing a struct of 3 floats. #2087
- Bug with slice acces as inline struct member #2088.
### Stdlib changes ### Stdlib changes
- Hash functions for integer vectors and arrays. - Hash functions for integer vectors and arrays.

View File

@@ -5362,13 +5362,13 @@ CHECK_DEEPER:
if (flat_type->type_kind == TYPE_SLICE) if (flat_type->type_kind == TYPE_SLICE)
{ {
// Handle literal "foo".len which is now a slice. // Handle literal "foo".len which is now a slice.
sema_expr_flatten_const_ident(parent); sema_expr_flatten_const_ident(current_parent);
if (expr_is_const_string(parent)) if (expr_is_const_string(current_parent))
{ {
expr_rewrite_const_int(expr, type_isz, parent->const_expr.bytes.len); expr_rewrite_const_int(expr, type_isz, current_parent->const_expr.bytes.len);
return true; return true;
} }
expr_rewrite_slice_len(expr, parent, type_usz); expr_rewrite_slice_len(expr, current_parent, type_usz);
return true; return true;
} }
if (flat_type->type_kind == TYPE_ARRAY || flat_type->type_kind == TYPE_VECTOR) if (flat_type->type_kind == TYPE_ARRAY || flat_type->type_kind == TYPE_VECTOR)
@@ -5385,7 +5385,7 @@ CHECK_DEEPER:
if (flat_type->type_kind == TYPE_TYPEID) if (flat_type->type_kind == TYPE_TYPEID)
{ {
bool was_error = false; bool was_error = false;
if (sema_expr_rewrite_to_typeid_property(context, expr, parent, kw, &was_error)) return !was_error; if (sema_expr_rewrite_to_typeid_property(context, expr, current_parent, kw, &was_error)) return !was_error;
} }
if (flat_type->type_kind == TYPE_VECTOR) if (flat_type->type_kind == TYPE_VECTOR)
{ {
@@ -5486,7 +5486,7 @@ CHECK_DEEPER:
if (!sema_analyse_decl(context, decl)) return false; if (!sema_analyse_decl(context, decl)) return false;
Decl *ref = current_parent->const_expr.enum_val; Decl *ref = current_parent->const_expr.enum_val;
if (!sema_analyse_decl(context, ref)) return false; if (!sema_analyse_decl(context, ref)) return false;
ASSERT_SPAN(expr, parent->const_expr.const_kind == CONST_ENUM); ASSERT_SPAN(expr, current_parent->const_expr.const_kind == CONST_ENUM);
Expr *copy_init = copy_expr_single(ref->enum_constant.args[member->var.index]); Expr *copy_init = copy_expr_single(ref->enum_constant.args[member->var.index]);
expr_replace(expr, copy_init); expr_replace(expr, copy_init);
ASSERT_SPAN(expr, copy_init->resolve_status == RESOLVE_DONE); ASSERT_SPAN(expr, copy_init->resolve_status == RESOLVE_DONE);

View File

@@ -0,0 +1,22 @@
// #target: macos-x64
module test;
struct Foo
{
inline String str;
}
fn int main()
{
(Foo){}.len;
return 0;
}
/* #expect: test.ll
entry:
%literal = alloca %Foo, align 8
call void @llvm.memset.p0.i64(ptr align 8 %literal, i8 0, i64 16, i1 false)
%ptradd = getelementptr inbounds i8, ptr %literal, i64 8
ret i32 0
}