authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-11-18 22:44:59-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-11-18 22:44:59-05:00
log31565efe9d6cde2e4909f986d50f8c46166d3311
tree024fbac9aa2153c884e6de86673578c12ef46517
parentd94cb0566be6463594f0904aa759de9e52585842

IR: fix decl references pointerness


1 files changed, 26 insertions(+), 13 deletions(-)

src/ir.cpp+26-13
......@@ -1152,25 +1152,43 @@ static IrInstruction *ir_gen_decl_ref(IrBuilder *irb, AstNode *source_node, AstN
11521152 if (decl_node->type == NodeTypeVariableDeclaration) {
11531153 VariableTableEntry *var = decl_node->data.variable_declaration.variable;
11541154 IrInstruction *var_ptr = ir_build_var_ptr(irb, source_node, var);
1155 return ir_build_load_ptr(irb, source_node, var_ptr);
1155 if (lval != LValPurposeNone)
1156 return var_ptr;
1157 else
1158 return ir_build_load_ptr(irb, source_node, var_ptr);
11561159 } else if (decl_node->type == NodeTypeFnProto) {
11571160 FnTableEntry *fn_entry = decl_node->data.fn_proto.fn_table_entry;
11581161 assert(fn_entry->type_entry);
1162 IrInstruction *ref_instruction;
11591163 if (fn_entry->type_entry->id == TypeTableEntryIdGenericFn) {
1160 return ir_build_const_generic_fn(irb, source_node, fn_entry->type_entry);
1164 ref_instruction = ir_build_const_generic_fn(irb, source_node, fn_entry->type_entry);
11611165 } else {
1162 return ir_build_const_fn(irb, source_node, fn_entry);
1166 ref_instruction = ir_build_const_fn(irb, source_node, fn_entry);
11631167 }
1168 if (lval != LValPurposeNone)
1169 return ir_build_un_op(irb, source_node, IrUnOpAddressOf, ref_instruction);
1170 else
1171 return ref_instruction;
11641172 } else if (decl_node->type == NodeTypeContainerDecl) {
1173 IrInstruction *ref_instruction;
11651174 if (decl_node->data.struct_decl.generic_params.length > 0) {
11661175 TypeTableEntry *type_entry = decl_node->data.struct_decl.generic_fn_type;
11671176 assert(type_entry);
1168 return ir_build_const_generic_fn(irb, source_node, type_entry);
1177 ref_instruction = ir_build_const_generic_fn(irb, source_node, type_entry);
11691178 } else {
1170 return ir_build_const_type(irb, source_node, decl_node->data.struct_decl.type_entry);
1179 ref_instruction = ir_build_const_type(irb, source_node, decl_node->data.struct_decl.type_entry);
11711180 }
1181 if (lval != LValPurposeNone)
1182 return ir_build_un_op(irb, source_node, IrUnOpAddressOf, ref_instruction);
1183 else
1184 return ref_instruction;
11721185 } else if (decl_node->type == NodeTypeTypeDecl) {
1173 return ir_build_const_type(irb, source_node, decl_node->data.type_decl.child_type_entry);
1186 TypeTableEntry *child_type = decl_node->data.type_decl.child_type_entry;
1187 IrInstruction *ref_instruction = ir_build_const_type(irb, source_node, child_type);
1188 if (lval != LValPurposeNone)
1189 return ir_build_un_op(irb, source_node, IrUnOpAddressOf, ref_instruction);
1190 else
1191 return ref_instruction;
11741192 } else {
11751193 zig_unreachable();
11761194 }
......@@ -1201,13 +1219,8 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, AstNode *node, LValPurpose l
12011219 }
12021220
12031221 AstNode *decl_node = find_decl(node->block_context, variable_name);
1204 if (decl_node) {
1205 IrInstruction *value = ir_gen_decl_ref(irb, node, decl_node, lval, node->block_context);
1206 if (lval == LValPurposeAddressOf)
1207 return ir_build_un_op(irb, node, IrUnOpAddressOf, value);
1208 else
1209 return value;
1210 }
1222 if (decl_node)
1223 return ir_gen_decl_ref(irb, node, decl_node, lval, node->block_context);
12111224
12121225 if (node->owner->any_imports_failed) {
12131226 // skip the error message since we had a failing import in this file