diff options
| author | gingerBill <bill@gingerbill.org> | 2019-09-02 18:59:07 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-09-02 18:59:07 +0100 |
| commit | 1370c10d1b9012bd914cf35347f8f6d9ac1a0da0 (patch) | |
| tree | 97a69682bd1840ac6af58860877677b65a1a5986 /src/ir.cpp | |
| parent | 1348d8a8cdefcb02be6ad9346ecbf24a4635fe0c (diff) | |
Fix Converting addresses to function pointers produces llvm-opt error #431
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 26f787976..4d5a55814 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -6967,7 +6967,34 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) { } // NOTE(bill): Regular call - irValue *value = ir_build_expr(proc, ce->proc); + irValue *value = nullptr; + Ast *proc_expr = unparen_expr(ce->proc); + if (proc_expr->tav.mode == Addressing_Constant) { + ExactValue v = proc_expr->tav.value; + switch (v.kind) { + case ExactValue_Integer: + { + u64 u = big_int_to_u64(&v.value_integer); + irValue *x = ir_const_uintptr(u); + x = ir_emit_conv(proc, x, t_rawptr); + value = ir_emit_conv(proc, x, proc_expr->tav.type); + break; + } + case ExactValue_Pointer: + { + u64 u = cast(u64)v.value_pointer; + irValue *x = ir_const_uintptr(u); + x = ir_emit_conv(proc, x, t_rawptr); + value = ir_emit_conv(proc, x, proc_expr->tav.type); + break; + } + } + } + + if (value == nullptr) { + value = ir_build_expr(proc, proc_expr); + } + GB_ASSERT(value != nullptr); Type *proc_type_ = base_type(ir_type(value)); GB_ASSERT(proc_type_->kind == Type_Proc); |