authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-18 02:13:07-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-18 02:13:07-05:00
log0cdfd5c1411a3e6af1ba7d579ef8bb5e752cbc2d
treed7d108f035f253a031d235fb90a04a757b3c9420
parent0d2f2b79eaf844e6bcdb41fe61c7e1655df9b1a0

IR: fix container field access via container pointer


1 files changed, 8 insertions(+), 1 deletions(-)

src/ir.cpp+8-1
...@@ -5066,6 +5066,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -5066,6 +5066,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
5066 return result;5066 return result;
5067 }5067 }
5068 }5068 }
5069 // TODO if the instruction is a get pointer instruction we can skip it
5069 IrInstruction *load_ptr_instruction = ir_build_load_ptr(&ira->new_irb, source_instruction->scope, source_instruction->source_node, ptr);5070 IrInstruction *load_ptr_instruction = ir_build_load_ptr(&ira->new_irb, source_instruction->scope, source_instruction->source_node, ptr);
5070 load_ptr_instruction->type_entry = child_type;5071 load_ptr_instruction->type_entry = child_type;
5071 return load_ptr_instruction;5072 return load_ptr_instruction;
...@@ -6853,7 +6854,13 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -6853,7 +6854,13 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
6853 return container_type;6854 return container_type;
6854 } else if (is_container_ref(container_type)) {6855 } else if (is_container_ref(container_type)) {
6855 assert(container_ptr->type_entry->id == TypeTableEntryIdPointer);6856 assert(container_ptr->type_entry->id == TypeTableEntryIdPointer);
6856 return ir_analyze_container_field_ptr(ira, field_name, field_ptr_instruction, container_ptr, container_type);6857 if (container_type->id == TypeTableEntryIdPointer) {
6858 TypeTableEntry *bare_type = container_ref_type(container_type);
6859 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr);
6860 return ir_analyze_container_field_ptr(ira, field_name, field_ptr_instruction, container_child, bare_type);
6861 } else {
6862 return ir_analyze_container_field_ptr(ira, field_name, field_ptr_instruction, container_ptr, container_type);
6863 }
6857 } else if (container_type->id == TypeTableEntryIdArray) {6864 } else if (container_type->id == TypeTableEntryIdArray) {
6858 if (buf_eql_str(field_name, "len")) {6865 if (buf_eql_str(field_name, "len")) {
6859 ConstExprValue *len_val = allocate<ConstExprValue>(1);6866 ConstExprValue *len_val = allocate<ConstExprValue>(1);