Commit aa31096cbd

Bogdan Romanyuk <65823030+wrongnull@users.noreply.github.com>
2023-11-23 03:08:15
Sema: disallow call to undefined function
1 parent e4977f3
src/Sema.zig
@@ -7132,6 +7132,9 @@ fn analyzeCall(
     const callee_ty = sema.typeOf(func);
     const func_ty_info = mod.typeToFunc(func_ty).?;
     const cc = func_ty_info.cc;
+    if (try sema.resolveValue(func)) |func_val|
+        if (func_val.isUndef(mod))
+            return sema.failWithUseOfUndef(block, call_src);
     if (cc == .Naked) {
         const maybe_decl = try sema.funcDeclSrc(func);
         const msg = msg: {
test/cases/compile_errors/refer_to_the_type_of_a_generic_function.zig
@@ -8,4 +8,4 @@ export fn entry() void {
 // backend=stage2
 // target=native
 //
-// :4:5: error: use of undefined value here causes undefined behavior
+// :4:6: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/undefined_value_call.zig
@@ -0,0 +1,9 @@
+pub export fn entry() void {
+    @as(fn () void, undefined)();
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :2:31: error: use of undefined value here causes undefined behavior