From 0cdfd5c1411a3e6af1ba7d579ef8bb5e752cbc2d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 18 Dec 2016 02:13:07 -0500 Subject: IR: fix container field access via container pointer --- src/ir.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 705a6d0c2f..d5dfbea86e 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -5066,6 +5066,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc return result; } } + // TODO if the instruction is a get pointer instruction we can skip it IrInstruction *load_ptr_instruction = ir_build_load_ptr(&ira->new_irb, source_instruction->scope, source_instruction->source_node, ptr); load_ptr_instruction->type_entry = child_type; return load_ptr_instruction; @@ -6853,7 +6854,13 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru return container_type; } else if (is_container_ref(container_type)) { assert(container_ptr->type_entry->id == TypeTableEntryIdPointer); - return ir_analyze_container_field_ptr(ira, field_name, field_ptr_instruction, container_ptr, container_type); + if (container_type->id == TypeTableEntryIdPointer) { + TypeTableEntry *bare_type = container_ref_type(container_type); + IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr); + return ir_analyze_container_field_ptr(ira, field_name, field_ptr_instruction, container_child, bare_type); + } else { + return ir_analyze_container_field_ptr(ira, field_name, field_ptr_instruction, container_ptr, container_type); + } } else if (container_type->id == TypeTableEntryIdArray) { if (buf_eql_str(field_name, "len")) { ConstExprValue *len_val = allocate(1); -- cgit v1.2.3