diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-02-26 23:50:04 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-02-26 23:50:04 -0500 |
| commit | 25761570f1bb4413020ebbfc959caa3429453517 (patch) | |
| tree | ac228c95e0393a8b36202864c60a4fd712a0e8d3 /src/ir.cpp | |
| parent | 8dd0b4e1f12bc9f70ff6c312b35563595fdb4476 (diff) | |
| download | zig-25761570f1bb4413020ebbfc959caa3429453517.tar.gz zig-25761570f1bb4413020ebbfc959caa3429453517.zip | |
more robust const struct values
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index fcaab07e6b..8e614298ea 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -10567,7 +10567,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru if (existing_assign_node) { ErrorMsg *msg = ir_add_error_node(ira, field->source_node, buf_sprintf("duplicate field")); add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here")); - continue; + return ira->codegen->builtin_types.entry_invalid; } field_assign_nodes[field_index] = field->source_node; @@ -10602,6 +10602,17 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru if (const_val.special == ConstValSpecialStatic) { ConstExprValue *out_val = ir_build_const_from(ira, instruction); *out_val = const_val; + + for (size_t i = 0; i < instr_field_count; i += 1) { + ConstExprValue *field_val = &out_val->data.x_struct.fields[i]; + ConstParent *parent = get_const_val_parent(field_val); + if (parent != nullptr) { + parent->id = ConstParentIdStruct; + parent->data.p_struct.field_index = i; + parent->data.p_struct.struct_val = out_val; + } + } + return container_type; } @@ -10681,10 +10692,11 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira *out_val = const_val; for (size_t i = 0; i < elem_count; i += 1) { ConstExprValue *elem_val = &out_val->data.x_array.elements[i]; - if (elem_val->type->id == TypeTableEntryIdArray) { - elem_val->data.x_array.parent.id = ConstParentIdArray; - elem_val->data.x_array.parent.data.p_array.array_val = out_val; - elem_val->data.x_array.parent.data.p_array.elem_index = i; + ConstParent *parent = get_const_val_parent(elem_val); + if (parent != nullptr) { + parent->id = ConstParentIdArray; + parent->data.p_array.array_val = out_val; + parent->data.p_array.elem_index = i; } } return fixed_size_array_type; |
