diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-04-10 12:04:25 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-04-10 12:04:25 -0700 |
| commit | 0683bd8bf66c00d38f79d49319b5d80ac1f9a470 (patch) | |
| tree | 14a189d75708cbca15b770fdb8b947fd0f0a62c5 /src/codegen.cpp | |
| parent | fddfc314d647b06fb65e8a94f670a537a1d4bbb4 (diff) | |
| download | zig-0683bd8bf66c00d38f79d49319b5d80ac1f9a470.tar.gz zig-0683bd8bf66c00d38f79d49319b5d80ac1f9a470.zip | |
fix crash when casting undefined to slice
also fix crash having to do with runtime allocated stack memory
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index e2c3b6667b..a0fdc7b749 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2479,37 +2479,40 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa value, variable->type, expr_type); } else { bool ignore_uninit = false; - TypeTableEntry *var_type = get_type_for_type_node(var_decl->type); - if (var_type->id == TypeTableEntryIdStruct && - var_type->data.structure.is_unknown_size_array) - { - assert(var_decl->type->type == NodeTypeArrayType); - AstNode *size_node = var_decl->type->data.array_type.size; - if (size_node) { - ConstExprValue *const_val = &get_resolved_expr(size_node)->const_val; - if (!const_val->ok) { - TypeTableEntry *ptr_type = var_type->data.structure.fields[0].type_entry; - assert(ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *child_type = ptr_type->data.pointer.child_type; - - LLVMValueRef size_val = gen_expr(g, size_node); - - add_debug_source_node(g, source_node); - LLVMValueRef ptr_val = LLVMBuildArrayAlloca(g->builder, child_type->type_ref, - size_val, ""); - - // store the freshly allocated pointer in the unknown size array struct - LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, - variable->value_ref, 0, ""); - LLVMBuildStore(g->builder, ptr_val, ptr_field_ptr); - - // store the size in the len field - LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, - variable->value_ref, 1, ""); - LLVMBuildStore(g->builder, size_val, len_field_ptr); - - // don't clobber what we just did with debug initialization - ignore_uninit = true; + // handle runtime stack allocation + if (var_decl->type) { + TypeTableEntry *var_type = get_type_for_type_node(var_decl->type); + if (var_type->id == TypeTableEntryIdStruct && + var_type->data.structure.is_unknown_size_array) + { + assert(var_decl->type->type == NodeTypeArrayType); + AstNode *size_node = var_decl->type->data.array_type.size; + if (size_node) { + ConstExprValue *const_val = &get_resolved_expr(size_node)->const_val; + if (!const_val->ok) { + TypeTableEntry *ptr_type = var_type->data.structure.fields[0].type_entry; + assert(ptr_type->id == TypeTableEntryIdPointer); + TypeTableEntry *child_type = ptr_type->data.pointer.child_type; + + LLVMValueRef size_val = gen_expr(g, size_node); + + add_debug_source_node(g, source_node); + LLVMValueRef ptr_val = LLVMBuildArrayAlloca(g->builder, child_type->type_ref, + size_val, ""); + + // store the freshly allocated pointer in the unknown size array struct + LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, + variable->value_ref, 0, ""); + LLVMBuildStore(g->builder, ptr_val, ptr_field_ptr); + + // store the size in the len field + LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, + variable->value_ref, 1, ""); + LLVMBuildStore(g->builder, size_val, len_field_ptr); + + // don't clobber what we just did with debug initialization + ignore_uninit = true; + } } } } |
