From 17404f8e6edea28fc70e074fd75101e1ed48b620 Mon Sep 17 00:00:00 2001 From: r00ster91 Date: Sun, 29 Jan 2023 23:25:31 +0100 Subject: [PATCH] Sema: emit compile error for comptime or inline call of function pointer --- src/Sema.zig | 7 ++++++- .../comptime_call_of_function_pointer.zig | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/cases/compile_errors/comptime_call_of_function_pointer.zig diff --git a/src/Sema.zig b/src/Sema.zig index 9c553a0092..7448fd149c 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -6446,7 +6446,12 @@ fn analyzeCall( .extern_fn => return sema.fail(block, call_src, "{s} call of extern function", .{ @as([]const u8, if (is_comptime_call) "comptime" else "inline"), }), - else => unreachable, + else => { + assert(callee_ty.isPtrAtRuntime()); + return sema.fail(block, call_src, "{s} call of function pointer", .{ + @as([]const u8, if (is_comptime_call) "comptime" else "inline"), + }); + }, }; if (func_ty_info.is_var_args) { return sema.fail(block, call_src, "{s} call of variadic function", .{ diff --git a/test/cases/compile_errors/comptime_call_of_function_pointer.zig b/test/cases/compile_errors/comptime_call_of_function_pointer.zig new file mode 100644 index 0000000000..cf01f5ea2c --- /dev/null +++ b/test/cases/compile_errors/comptime_call_of_function_pointer.zig @@ -0,0 +1,10 @@ +export fn entry() void { + const fn_ptr = @intToPtr(*align(1) fn () void, 0xffd2); + comptime fn_ptr(); +} + +// error +// backend=stage2 +// target=native +// +// :3:20: error: comptime call of function pointer