authorgravatar for wrongnull@gmail.comBogdan Romanyuk <wrongnull@gmail.com> 2023-11-23 05:08:15+03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-11-23 02:08:15+00:00
logaa31096cbd0d66d7c31e12eebe91f36293346dba
tree7908a5ffa180b1539c3d77dfd6336f90904e06be
parente4977f3e89fcc164a4d02cd38eb066cfe1a1124f
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Sema: disallow call to undefined function


3 files changed, 13 insertions(+), 1 deletions(-)

src/Sema.zig+3
...@@ -7132,6 +7132,9 @@ fn analyzeCall(...@@ -7132,6 +7132,9 @@ fn analyzeCall(
7132 const callee_ty = sema.typeOf(func);7132 const callee_ty = sema.typeOf(func);
7133 const func_ty_info = mod.typeToFunc(func_ty).?;7133 const func_ty_info = mod.typeToFunc(func_ty).?;
7134 const cc = func_ty_info.cc;7134 const cc = func_ty_info.cc;
7135 if (try sema.resolveValue(func)) |func_val|
7136 if (func_val.isUndef(mod))
7137 return sema.failWithUseOfUndef(block, call_src);
7135 if (cc == .Naked) {7138 if (cc == .Naked) {
7136 const maybe_decl = try sema.funcDeclSrc(func);7139 const maybe_decl = try sema.funcDeclSrc(func);
7137 const msg = msg: {7140 const msg = msg: {
test/cases/compile_errors/refer_to_the_type_of_a_generic_function.zig+1-1
...@@ -8,4 +8,4 @@ export fn entry() void {...@@ -8,4 +8,4 @@ export fn entry() void {
8// backend=stage28// backend=stage2
9// target=native9// target=native
10//10//
11// :4:5: error: use of undefined value here causes undefined behavior11// :4:6: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/undefined_value_call.zig created+9
...@@ -0,0 +1,9 @@
1pub export fn entry() void {
2 @as(fn () void, undefined)();
3}
4
5// error
6// backend=stage2
7// target=native
8//
9// :2:31: error: use of undefined value here causes undefined behavior