- Regression with npot vector in struct triggering an assert #2219.

This commit is contained in:
Christoffer Lerno
2025-12-05 17:26:22 +01:00
parent 608fc4df9f
commit 034a048c8a
4 changed files with 71 additions and 2 deletions

View File

@@ -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

View File

@@ -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)
{

View File

@@ -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
}

View File

@@ -9,4 +9,4 @@ extern fn void foo(Vec4f) @cname("foo");
/* #expect: test.ll
declare void @foo(double, double) #0
declare void @foo(<2 x float>, <2 x float>) #0