Sema: disallow call to undefined function

This commit is contained in:
Bogdan Romanyuk
2023-11-23 05:08:15 +03:00
committed by GitHub
parent e4977f3e89
commit aa31096cbd
3 changed files with 13 additions and 1 deletions

View File

@@ -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: {

View File

@@ -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

View File

@@ -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