authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-29 14:01:12-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-29 14:01:12-05:00
log1c60f3145098cda92a7bd90ed0fce4bd75a03d1c
tree11e9bf1b797e217169f2d2d4d3e3fa8bfa151571
parent2b5e0b66a27d2a83cb596a28c9792a86523401b3

add compile error for calling naked function


2 files changed, 19 insertions(+), 0 deletions(-)

src/ir.cpp+9
...@@ -9837,6 +9837,15 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -9837,6 +9837,15 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
98379837
9838 AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;;9838 AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;;
98399839
9840 if (fn_type_id->cc == CallingConventionNaked) {
9841 ErrorMsg *msg = ir_add_error(ira, fn_ref, buf_sprintf("unable to call function with naked calling convention"));
9842 if (fn_proto_node) {
9843 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here"));
9844 }
9845 return ira->codegen->builtin_types.entry_invalid;
9846 }
9847
9848
9840 if (fn_type_id->is_var_args) {9849 if (fn_type_id->is_var_args) {
9841 if (call_param_count < src_param_count) {9850 if (call_param_count < src_param_count) {
9842 ErrorMsg *msg = ir_add_error_node(ira, source_node,9851 ErrorMsg *msg = ir_add_error_node(ira, source_node,
test/compile_errors.zig+10
...@@ -1,6 +1,16 @@...@@ -1,6 +1,16 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.CompileErrorContext) void {3pub fn addCases(cases: &tests.CompileErrorContext) void {
4 cases.add("calling function with naked calling convention",
5 \\export fn entry() void {
6 \\ foo();
7 \\}
8 \\nakedcc fn foo() void { }
9 ,
10 ".tmp_source.zig:2:5: error: unable to call function with naked calling convention",
11 ".tmp_source.zig:4:9: note: declared here");
12
13
4 cases.add("function with invalid return type",14 cases.add("function with invalid return type",
5 \\export fn foo() boid {}15 \\export fn foo() boid {}
6 , ".tmp_source.zig:1:17: error: use of undeclared identifier 'boid'");16 , ".tmp_source.zig:1:17: error: use of undeclared identifier 'boid'");