diff --git a/releasenotes.md b/releasenotes.md index ac30832ab..855308a35 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -2,8 +2,12 @@ ## 0.7.9 Change list + ### Changes / improvements + ### Fixes +- Regression with npot vector in struct triggering an assert #2219. + ### Stdlib changes ## 0.7.8 Change list diff --git a/src/compiler/abi/c_abi_x64.c b/src/compiler/abi/c_abi_x64.c index 99b7dc25f..0442045ad 100644 --- a/src/compiler/abi/c_abi_x64.c +++ b/src/compiler/abi/c_abi_x64.c @@ -489,7 +489,7 @@ static Type *x64_get_fp_type_at_offset(Type *type, unsigned ir_offset) if (type->type_kind == TYPE_STRUCT || type->type_kind == TYPE_UNION) { Decl *element = x64_get_member_at_offset(type->decl, ir_offset); - return x64_get_fp_type_at_offset(element->type, ir_offset - element->offset); + return x64_get_fp_type_at_offset(lowered_member_type(element), ir_offset - element->offset); } if (type->type_kind == TYPE_ARRAY) { diff --git a/test/test_suite/abi/sysv_wrapped_vec.c3t b/test/test_suite/abi/sysv_wrapped_vec.c3t new file mode 100644 index 000000000..d1344df87 --- /dev/null +++ b/test/test_suite/abi/sysv_wrapped_vec.c3t @@ -0,0 +1,65 @@ +// #target: linux-x64 +module test; +import std; + +fn int main() +{ + Vec3f eye = {{2.0f, 2.0f, 2.0f}}; + Vec3fs eye2 = {{2.0f, 2.0f, 2.0f}}; + look_at(eye); + look_at2(eye2); + return 0; +} +fn void look_at(Vec3f eye) {} +fn void look_at2(Vec3fs eye) {} + +struct Vec3f +{ + float[<3>] inner; +} + +struct Vec3fs +{ + float[3] inner; +} + +/* #expect: test.ll + +define i32 @main() #0 { +entry: + %eye = alloca %Vec3f, align 4 + %eye2 = alloca %Vec3fs, align 4 + %coerce = alloca %Vec3f, align 8 + %coerce1 = alloca %Vec3fs, align 8 + call void @llvm.memcpy.p0.p0.i32(ptr align 4 %eye, ptr align 4 @.__const, i32 12, i1 false) + call void @llvm.memcpy.p0.p0.i32(ptr align 4 %eye2, ptr align 4 @.__const.1, i32 12, i1 false) + call void @llvm.memcpy.p0.p0.i32(ptr align 8 %coerce, ptr align 4 %eye, i32 12, i1 false) + %lo = load <2 x float>, ptr %coerce, align 8 + %ptradd = getelementptr inbounds i8, ptr %coerce, i64 8 + %hi = load float, ptr %ptradd, align 8 + call void @test.look_at(<2 x float> %lo, float %hi) + call void @llvm.memcpy.p0.p0.i32(ptr align 8 %coerce1, ptr align 4 %eye2, i32 12, i1 false) + %lo2 = load <2 x float>, ptr %coerce1, align 8 + %ptradd3 = getelementptr inbounds i8, ptr %coerce1, i64 8 + %hi4 = load float, ptr %ptradd3, align 8 + call void @test.look_at2(<2 x float> %lo2, float %hi4) + ret i32 0 +} + +define void @test.look_at(<2 x float> %0, float %1) #0 { +entry: + %eye = alloca %Vec3f, align 8 + store <2 x float> %0, ptr %eye, align 8 + %ptradd = getelementptr inbounds i8, ptr %eye, i64 8 + store float %1, ptr %ptradd, align 8 + ret void +} + +define void @test.look_at2(<2 x float> %0, float %1) #0 { +entry: + %eye = alloca %Vec3fs, align 8 + store <2 x float> %0, ptr %eye, align 8 + %ptradd = getelementptr inbounds i8, ptr %eye, i64 8 + store float %1, ptr %ptradd, align 8 + ret void +} \ No newline at end of file diff --git a/test/test_suite/vector/vector_lowering_regression1.c3t b/test/test_suite/vector/vector_lowering_regression1.c3t index c1062c4f2..919fdfa9b 100644 --- a/test/test_suite/vector/vector_lowering_regression1.c3t +++ b/test/test_suite/vector/vector_lowering_regression1.c3t @@ -9,4 +9,4 @@ extern fn void foo(Vec4f) @cname("foo"); /* #expect: test.ll -declare void @foo(double, double) #0 \ No newline at end of file +declare void @foo(<2 x float>, <2 x float>) #0 \ No newline at end of file