aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2020-10-25 11:25:02 +0100
committerVeikka Tuominen <git@vexu.eu>2020-10-28 21:13:32 +0200
commit6d2f103bfb8931e2e65ca7f79d62389b69781492 (patch)
treef7f6d1fbbaffea1f1cfe9d743008c0e6e977424a /src
parent1a171a143aaa1be843b6f028cbb8e82aaec79e2c (diff)
downloadzig-6d2f103bfb8931e2e65ca7f79d62389b69781492.tar.gz
zig-6d2f103bfb8931e2e65ca7f79d62389b69781492.zip
stage1: Fix crash in comptime struct value copy
Comptime fields are never materialized in the ZigValue so pay attention when iterating over the fields array. Fixes #6800
Diffstat (limited to 'src')
-rw-r--r--src/stage1/analyze.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp
index fd0de8e907..0da3ec58dc 100644
--- a/src/stage1/analyze.cpp
+++ b/src/stage1/analyze.cpp
@@ -5686,7 +5686,13 @@ static bool can_mutate_comptime_var_state(ZigValue *value) {
zig_unreachable();
case ZigTypeIdStruct:
for (uint32_t i = 0; i < value->type->data.structure.src_field_count; i += 1) {
- if (can_mutate_comptime_var_state(value->data.x_struct.fields[i]))
+ TypeStructField *type_struct_field = value->type->data.structure.fields[i];
+
+ ZigValue *field_value = type_struct_field->is_comptime ?
+ type_struct_field->init_val :
+ value->data.x_struct.fields[i];
+
+ if (can_mutate_comptime_var_state(field_value))
return true;
}
return false;
@@ -9690,6 +9696,11 @@ void copy_const_val(CodeGen *g, ZigValue *dest, ZigValue *src) {
if (dest->type->id == ZigTypeIdStruct) {
dest->data.x_struct.fields = alloc_const_vals_ptrs(g, dest->type->data.structure.src_field_count);
for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) {
+ TypeStructField *type_struct_field = dest->type->data.structure.fields[i];
+ // comptime-known values are stored in the field init_val inside
+ // the struct type.
+ if (type_struct_field->is_comptime)
+ continue;
copy_const_val(g, dest->data.x_struct.fields[i], src->data.x_struct.fields[i]);
dest->data.x_struct.fields[i]->parent.id = ConstParentIdStruct;
dest->data.x_struct.fields[i]->parent.data.p_struct.struct_val = dest;