llvm: handle vectors in packed structs

Closes #13201
This commit is contained in:
Veikka Tuominen 2022-12-19 12:18:55 +02:00
parent 0eddf0cbc0
commit 2926d95e6a
2 changed files with 3 additions and 6 deletions

View File

@ -5966,7 +5966,7 @@ pub const FuncGen = struct {
const shift_amt = containing_int.typeOf().constInt(bit_offset, .False);
const shifted_value = self.builder.buildLShr(containing_int, shift_amt, "");
const elem_llvm_ty = try self.dg.lowerType(field_ty);
if (field_ty.zigTypeTag() == .Float) {
if (field_ty.zigTypeTag() == .Float or field_ty.zigTypeTag() == .Vector) {
const elem_bits = @intCast(c_uint, field_ty.bitSize(target));
const same_size_int = self.context.intType(elem_bits);
const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");
@ -5989,7 +5989,7 @@ pub const FuncGen = struct {
assert(struct_ty.containerLayout() == .Packed);
const containing_int = struct_llvm_val;
const elem_llvm_ty = try self.dg.lowerType(field_ty);
if (field_ty.zigTypeTag() == .Float) {
if (field_ty.zigTypeTag() == .Float or field_ty.zigTypeTag() == .Vector) {
const elem_bits = @intCast(c_uint, field_ty.bitSize(target));
const same_size_int = self.context.intType(elem_bits);
const truncated_int = self.builder.buildTrunc(containing_int, same_size_int, "");
@ -9889,7 +9889,7 @@ pub const FuncGen = struct {
return result_ptr;
}
if (info.pointee_type.zigTypeTag() == .Float) {
if (info.pointee_type.zigTypeTag() == .Float or info.pointee_type.zigTypeTag() == .Vector) {
const same_size_int = self.context.intType(elem_bits);
const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");
return self.builder.buildBitCast(truncated_int, elem_llvm_ty, "");

View File

@ -358,9 +358,6 @@ test "comptime @bitCast packed struct to int and back" {
const rt_cast = @bitCast(S, i);
const ct_cast = comptime @bitCast(S, @as(Int, 0));
inline for (@typeInfo(S).Struct.fields) |field| {
if (@typeInfo(field.type) == .Vector)
continue; //TODO: https://github.com/ziglang/zig/issues/13201
try expectEqual(@field(rt_cast, field.name), @field(ct_cast, field.name));
}
}