diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-03-13 19:13:10 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-03-13 19:15:20 -0400 |
| commit | 7f7823e23cfd82739401f43a329106bee0748b10 (patch) | |
| tree | eb8382e8e704f72f33494a20879d303b53d5db04 /src/codegen.cpp | |
| parent | d6e84e325bab360c6b6980dc2d57df872b9affdc (diff) | |
| download | zig-7f7823e23cfd82739401f43a329106bee0748b10.tar.gz zig-7f7823e23cfd82739401f43a329106bee0748b10.zip | |
fix casting a function to a pointer causing compiler crash
closes #777
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index 384322dac1..a44091bdbf 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -4840,7 +4840,9 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c case TypeTableEntryIdEnum: return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_enum_tag); case TypeTableEntryIdFn: - return fn_llvm_value(g, const_val->data.x_fn.fn_entry); + assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction); + assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst); + return fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry); case TypeTableEntryIdPointer: { render_const_val_global(g, const_val, name); @@ -4909,6 +4911,8 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c render_const_val_global(g, const_val, ""); return const_val->global_refs->llvm_value; } + case ConstPtrSpecialFunction: + return LLVMConstBitCast(fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry), const_val->type->type_ref); } } zig_unreachable(); @@ -6313,7 +6317,9 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) { ConstExprValue *fn_field = &this_val->data.x_struct.fields[1]; fn_field->type = fn_type; fn_field->special = ConstValSpecialStatic; - fn_field->data.x_fn.fn_entry = test_fn_entry; + fn_field->data.x_ptr.special = ConstPtrSpecialFunction; + fn_field->data.x_ptr.mut = ConstPtrMutComptimeConst; + fn_field->data.x_ptr.data.fn.fn_entry = test_fn_entry; } ConstExprValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true); |
