diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-05-11 22:41:44 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-05-11 22:41:44 -0400 |
| commit | 277b9cf8788f340f387e63029ad9fc12664cafff (patch) | |
| tree | 4eed4bea02c91dd6e98786be22613b06aa1ddf6f /src | |
| parent | 6e821078f625a03eb8b7794c983da0f7793366ab (diff) | |
| download | zig-277b9cf8788f340f387e63029ad9fc12664cafff.tar.gz zig-277b9cf8788f340f387e63029ad9fc12664cafff.zip | |
fix comptime code modification of global const
closes #1008
Diffstat (limited to 'src')
| -rw-r--r-- | src/ir.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 1e6a7d7b8b..c251f30320 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -8686,6 +8686,10 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_ *dest = *src; if (!same_global_refs) { dest->global_refs = global_refs; + if (dest->type->id == TypeTableEntryIdStruct) { + dest->data.x_struct.fields = allocate_nonzero<ConstExprValue>(dest->type->data.structure.src_field_count); + memcpy(dest->data.x_struct.fields, src->data.x_struct.fields, sizeof(ConstExprValue) * dest->type->data.structure.src_field_count); + } } } @@ -11670,7 +11674,8 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc if (var->mem_slot_index != SIZE_MAX) { assert(var->mem_slot_index < ira->exec_context.mem_slot_count); ConstExprValue *mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index]; - *mem_slot = casted_init_value->value; + copy_const_val(mem_slot, &casted_init_value->value, + !is_comptime_var || var->gen_is_const); if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) { ir_build_const_from(ira, &decl_var_instruction->base); |
