aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-08-17 16:49:23 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-08-17 16:49:23 -0400
commit66a490c27c01c958d8d20dbc289c6b2b934a724e (patch)
treeedd444dfae7eb106453f9aa0aa9ec3908c97e2f1 /src/ir.cpp
parent0ff396c34f93b60a000e1ee50e881a8c25122b79 (diff)
downloadzig-66a490c27c01c958d8d20dbc289c6b2b934a724e.tar.gz
zig-66a490c27c01c958d8d20dbc289c6b2b934a724e.zip
detect non-async function pointer of inferred async function
closes #3075
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 51f849ce19..c37fac2f52 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -15160,6 +15160,20 @@ no_mem_slot:
return var_ptr_instruction;
}
+// This function is called when a comptime value becomes accessible at runtime.
+static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *val) {
+ ir_assert(value_is_comptime(val), source_instr);
+ if (val->special == ConstValSpecialUndef)
+ return;
+
+ if (val->type->id == ZigTypeIdFn && val->type->data.fn.fn_type_id.cc == CallingConventionUnspecified) {
+ ir_assert(val->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);
+ if (val->data.x_ptr.data.fn.fn_entry->non_async_node == nullptr) {
+ val->data.x_ptr.data.fn.fn_entry->non_async_node = source_instr->source_node;
+ }
+ }
+}
+
static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr,
IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const)
{
@@ -15256,6 +15270,10 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
break;
}
+ if (instr_is_comptime(value)) {
+ mark_comptime_value_escape(ira, source_instr, &value->value);
+ }
+
IrInstructionStorePtr *store_ptr = ir_build_store_ptr(&ira->new_irb, source_instr->scope,
source_instr->source_node, ptr, value);
return &store_ptr->base;