authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-26 20:00:28-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-26 20:01:42-04:00
log7ce7e2c9d1d43886c93f34b67d32ef77cc0d8a6e
treeb983cf44e18da510aa9b9bb02953f02af076c410
parent7f4d4bdb3f8c4ac0c368074c111d5455ea6c8ade

emit error for extern function

with byvalue return value or parameter. currently we don't codegen byvalue parameters or return values correctly for C compatibilty functions so instead of generating incorrect code, we emit a compile error. eventually we'll support this feature and remove the compile error. See #180

3 files changed, 17 insertions(+), 16 deletions(-)

src/analyze.cpp+8-2
......@@ -6903,9 +6903,9 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
69036903 add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));
69046904 }
69056905
6906 if (fn_type->data.fn.fn_type_id.is_extern && type->id == TypeTableEntryIdStruct) {
6906 if (fn_type->data.fn.fn_type_id.is_extern && handle_is_ptr(type)) {
69076907 add_node_error(g, param_decl_node,
6908 buf_sprintf("byvalue struct parameters not yet supported on extern functions"));
6908 buf_sprintf("byvalue types not yet supported on extern function parameters"));
69096909 }
69106910
69116911 if (buf_len(param_decl->name) == 0) {
......@@ -6927,6 +6927,12 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
69276927 }
69286928
69296929 TypeTableEntry *expected_type = fn_type->data.fn.fn_type_id.return_type;
6930
6931 if (fn_type->data.fn.fn_type_id.is_extern && handle_is_ptr(expected_type)) {
6932 add_node_error(g, fn_proto_node->data.fn_proto.return_type,
6933 buf_sprintf("byvalue types not yet supported on extern function return values"));
6934 }
6935
69306936 TypeTableEntry *block_return_type = analyze_expression(g, import, context, expected_type, node->data.fn_def.body);
69316937
69326938 node->data.fn_def.implicit_return_type = block_return_type;
std/compiler_rt.zig-12
......@@ -210,18 +210,6 @@ export fn __umoddi3(a: du_int, b: du_int) -> du_int {
210210 return r;
211211}
212212
213struct AeabiUlDivModResult {
214 quot: u64,
215 rem: u64,
216}
217#debug_safety(false)
218export fn __aeabi_uldivmod(numerator: u64, denominator: u64) -> AeabiUlDivModResult{
219 var result: AeabiUlDivModResult = undefined;
220 result.quot = __udivmoddi4(numerator, denominator, &result.rem);
221 return result;
222}
223
224
225213#attribute("test")
226214fn test_umoddi3() {
227215 test_one_umoddi3(0, 1, 0);
test/run_tests.cpp+9-2
......@@ -884,10 +884,17 @@ var a : i32 = 1;
884884var a : i32 = 2;
885885 )SOURCE", 1, ".tmp_source.zig:3:1: error: redeclaration of variable 'a'");
886886
887 add_compile_fail_case("byvalue struct on exported functions", R"SOURCE(
887 add_compile_fail_case("byvalue struct parameter in exported function", R"SOURCE(
888888struct A { x : i32, }
889889export fn f(a : A) {}
890 )SOURCE", 1, ".tmp_source.zig:3:13: error: byvalue struct parameters not yet supported on extern functions");
890 )SOURCE", 1, ".tmp_source.zig:3:13: error: byvalue types not yet supported on extern function parameters");
891
892 add_compile_fail_case("byvalue struct return value in exported function", R"SOURCE(
893struct A { x: i32, }
894export fn f() -> A {
895 A {.x = 1234 }
896}
897 )SOURCE", 1, ".tmp_source.zig:3:18: error: byvalue types not yet supported on extern function return values");
891898
892899 add_compile_fail_case("duplicate field in struct value expression", R"SOURCE(
893900struct A {