Skip to content

Commit 28f9230

Browse files
committedJul 10, 2018
fix crash when calling comptime-known undefined function ptr
closes #880 closes #1212
1 parent b5cfbfd commit 28f9230

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
 

‎src/ir.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13271,6 +13271,8 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
1327113271
return ir_finish_anal(ira, cast_instruction->value.type);
1327213272
} else if (fn_ref->value.type->id == TypeTableEntryIdFn) {
1327313273
FnTableEntry *fn_table_entry = ir_resolve_fn(ira, fn_ref);
13274+
if (fn_table_entry == nullptr)
13275+
return ira->codegen->builtin_types.entry_invalid;
1327413276
return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
1327513277
fn_ref, nullptr, is_comptime, call_instruction->fn_inline);
1327613278
} else if (fn_ref->value.type->id == TypeTableEntryIdBoundFn) {

‎test/compile_errors.zig‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
const tests = @import("tests.zig");
22

33
pub fn addCases(cases: *tests.CompileErrorContext) void {
4+
cases.add(
5+
"use of comptime-known undefined function value",
6+
\\const Cmd = struct {
7+
\\ exec: fn () void,
8+
\\};
9+
\\export fn entry() void {
10+
\\ const command = Cmd{ .exec = undefined };
11+
\\ command.exec();
12+
\\}
13+
,
14+
".tmp_source.zig:6:12: error: use of undefined value",
15+
);
16+
417
cases.add(
518
"bad @alignCast at comptime",
619
\\comptime {

0 commit comments

Comments
 (0)
Please sign in to comment.