From 28f9230b40ee7aa179705c39616aaf2a5f303b73 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 10 Jul 2018 10:12:08 -0400 Subject: [PATCH] fix crash when calling comptime-known undefined function ptr closes #880 closes #1212 --- src/ir.cpp | 2 ++ test/compile_errors.zig | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/ir.cpp b/src/ir.cpp index 2dc6ddad2c69fb0600458db77dec3946ede92f74..10ce3254fd8d65b3593875549b4b0ae1b3f0741d 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -13271,6 +13271,8 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction return ir_finish_anal(ira, cast_instruction->value.type); } else if (fn_ref->value.type->id == TypeTableEntryIdFn) { FnTableEntry *fn_table_entry = ir_resolve_fn(ira, fn_ref); + if (fn_table_entry == nullptr) + return ira->codegen->builtin_types.entry_invalid; return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, fn_ref, nullptr, is_comptime, call_instruction->fn_inline); } else if (fn_ref->value.type->id == TypeTableEntryIdBoundFn) { diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 1b76c01564866b9c0af6a4cb0da4dcc08e2b2ba7..a6db8d50b4bfd4db933bb193addb18535d59ba80 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -1,6 +1,19 @@ const tests = @import("tests.zig"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.add( + "use of comptime-known undefined function value", + \\const Cmd = struct { + \\ exec: fn () void, + \\}; + \\export fn entry() void { + \\ const command = Cmd{ .exec = undefined }; + \\ command.exec(); + \\} + , + ".tmp_source.zig:6:12: error: use of undefined value", + ); + cases.add( "bad @alignCast at comptime", \\comptime { -- 2.54.0