From b147ff5b60ebb32ec5a3c1f6da82601201d5ad9a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 10 Jan 2016 18:56:50 -0700 Subject: fix codegen for void struct fields --- src/codegen.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index e89b19e79f..79cefd311e 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -412,12 +412,13 @@ static LLVMValueRef gen_field_ptr(CodeGen *g, AstNode *node, TypeTableEntry **ou assert(LLVMGetTypeKind(LLVMTypeOf(struct_ptr)) == LLVMPointerTypeKind); assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(struct_ptr))) == LLVMStructTypeKind); - assert(node->data.field_access_expr.field_index >= 0); + int gen_field_index = node->data.field_access_expr.type_struct_field->gen_index; + assert(gen_field_index >= 0); *out_type_entry = node->data.field_access_expr.type_struct_field->type_entry; add_debug_source_node(g, node); - return LLVMBuildStructGEP(g->builder, struct_ptr, node->data.field_access_expr.field_index, ""); + return LLVMBuildStructGEP(g->builder, struct_ptr, gen_field_index, ""); } static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) { @@ -1419,12 +1420,14 @@ static LLVMValueRef gen_struct_val_expr(CodeGen *g, AstNode *node) { for (int i = 0; i < field_count; i += 1) { AstNode *field_node = node->data.struct_val_expr.fields.at(i); assert(field_node->type == NodeTypeStructValueField); - int index = field_node->data.struct_val_field.index; - TypeStructField *type_struct_field = &type_entry->data.structure.fields[index]; + TypeStructField *type_struct_field = field_node->data.struct_val_field.type_struct_field; + if (type_struct_field->type_entry->id == TypeTableEntryIdVoid) { + continue; + } assert(buf_eql_buf(type_struct_field->name, &field_node->data.struct_val_field.name)); add_debug_source_node(g, field_node); - LLVMValueRef field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, index, ""); + LLVMValueRef field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, type_struct_field->gen_index, ""); LLVMValueRef value = gen_expr(g, field_node->data.struct_val_field.expr); LLVMBuildStore(g->builder, value, field_ptr); } -- cgit v1.2.3