aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-11-24 16:25:26 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-11-24 16:25:26 -0500
commit09ec720dab6331c8be0300f2943f7d757ad0d7c3 (patch)
treec9b2fc59b1efb6148dbf39f1c4b9c476b2a9a512 /src/ir.cpp
parentf7574f44c120dc834ebaf2773dc1ab098a20c232 (diff)
downloadzig-09ec720dab6331c8be0300f2943f7d757ad0d7c3.tar.gz
zig-09ec720dab6331c8be0300f2943f7d757ad0d7c3.zip
fix comptime `@ptrCast` of pointers to arrays
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index d88137d949..4b39f736ad 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -18585,12 +18585,27 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
case ConstPtrSpecialDiscard:
zig_unreachable();
case ConstPtrSpecialRef:
- mem_size = 1;
- old_size = 1;
- new_index = index;
+ if (array_ptr_val->data.x_ptr.data.ref.pointee->type->id == ZigTypeIdArray) {
+ ConstExprValue *array_val = array_ptr_val->data.x_ptr.data.ref.pointee;
+ new_index = index;
+ ZigType *array_type = array_val->type;
+ mem_size = array_type->data.array.len;
+ if (array_type->data.array.sentinel != nullptr) {
+ mem_size += 1;
+ }
+ old_size = mem_size;
- out_val->data.x_ptr.special = ConstPtrSpecialRef;
- out_val->data.x_ptr.data.ref.pointee = array_ptr_val->data.x_ptr.data.ref.pointee;
+ out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
+ out_val->data.x_ptr.data.base_array.array_val = array_val;
+ out_val->data.x_ptr.data.base_array.elem_index = new_index;
+ } else {
+ mem_size = 1;
+ old_size = 1;
+ new_index = index;
+
+ out_val->data.x_ptr.special = ConstPtrSpecialRef;
+ out_val->data.x_ptr.data.ref.pointee = array_ptr_val->data.x_ptr.data.ref.pointee;
+ }
break;
case ConstPtrSpecialBaseArray:
{