aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorJohn Schmidt <john.schmidt.h@gmail.com>2023-03-08 23:13:37 +0100
committerJohn Schmidt <john.schmidt.h@gmail.com>2023-03-09 00:55:33 +0100
commit0606f0aa5576122204886f1a3c9530c0ce75c044 (patch)
tree8e1c9cf9b000a60d4f98aafeb318f6814bea52a7 /src/Sema.zig
parent505e720421ce4f7ed11730fe68d32e3bba711f3c (diff)
downloadzig-0606f0aa5576122204886f1a3c9530c0ce75c044.tar.gz
zig-0606f0aa5576122204886f1a3c9530c0ce75c044.zip
sema: fix result ptr coercion array -> vector
Previously this worked for array to vector where the element type matched exactly (e.g `[4]u8` to `@Vector(4, u8)`) since that is performed with a simple `.bitcast` operation, but now it also works for types where the array is coercible to the vector type (e.g `[4]u8` to `@Vector(4, u16)`).
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index a33c9bee6d..61b6209a3e 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -2538,6 +2538,20 @@ fn coerceResultPtr(
const trash_inst = trash_block.instructions.pop();
switch (air_tags[trash_inst]) {
+ // Array coerced to Vector where element size is not equal but coercible.
+ .aggregate_init => {
+ const ty_pl = air_datas[trash_inst].ty_pl;
+ const ptr_operand_ty = try Type.ptr(sema.arena, sema.mod, .{
+ .pointee_type = try sema.analyzeAsType(block, src, ty_pl.ty),
+ .@"addrspace" = addr_space,
+ });
+
+ if (try sema.resolveDefinedValue(block, src, new_ptr)) |ptr_val| {
+ return sema.addConstant(ptr_operand_ty, ptr_val);
+ } else {
+ return sema.bitCast(block, ptr_operand_ty, new_ptr, src, null);
+ }
+ },
.bitcast => {
const ty_op = air_datas[trash_inst].ty_op;
const operand_ty = sema.typeOf(ty_op.operand);