Sema: disallow call to undefined function
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -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
|
||||
|
||||
9
test/cases/compile_errors/undefined_value_call.zig
Normal file
9
test/cases/compile_errors/undefined_value_call.zig
Normal 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
|
||||
Reference in New Issue
Block a user