mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
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
This commit is contained in:
parent
7f4d4bdb3f
commit
7ce7e2c9d1
@ -6903,9 +6903,9 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
|
||||
add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter"));
|
||||
}
|
||||
|
||||
if (fn_type->data.fn.fn_type_id.is_extern && type->id == TypeTableEntryIdStruct) {
|
||||
if (fn_type->data.fn.fn_type_id.is_extern && handle_is_ptr(type)) {
|
||||
add_node_error(g, param_decl_node,
|
||||
buf_sprintf("byvalue struct parameters not yet supported on extern functions"));
|
||||
buf_sprintf("byvalue types not yet supported on extern function parameters"));
|
||||
}
|
||||
|
||||
if (buf_len(param_decl->name) == 0) {
|
||||
@ -6927,6 +6927,12 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
|
||||
}
|
||||
|
||||
TypeTableEntry *expected_type = fn_type->data.fn.fn_type_id.return_type;
|
||||
|
||||
if (fn_type->data.fn.fn_type_id.is_extern && handle_is_ptr(expected_type)) {
|
||||
add_node_error(g, fn_proto_node->data.fn_proto.return_type,
|
||||
buf_sprintf("byvalue types not yet supported on extern function return values"));
|
||||
}
|
||||
|
||||
TypeTableEntry *block_return_type = analyze_expression(g, import, context, expected_type, node->data.fn_def.body);
|
||||
|
||||
node->data.fn_def.implicit_return_type = block_return_type;
|
||||
|
||||
@ -210,18 +210,6 @@ export fn __umoddi3(a: du_int, b: du_int) -> du_int {
|
||||
return r;
|
||||
}
|
||||
|
||||
struct AeabiUlDivModResult {
|
||||
quot: u64,
|
||||
rem: u64,
|
||||
}
|
||||
#debug_safety(false)
|
||||
export fn __aeabi_uldivmod(numerator: u64, denominator: u64) -> AeabiUlDivModResult{
|
||||
var result: AeabiUlDivModResult = undefined;
|
||||
result.quot = __udivmoddi4(numerator, denominator, &result.rem);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#attribute("test")
|
||||
fn test_umoddi3() {
|
||||
test_one_umoddi3(0, 1, 0);
|
||||
|
||||
@ -884,10 +884,17 @@ var a : i32 = 1;
|
||||
var a : i32 = 2;
|
||||
)SOURCE", 1, ".tmp_source.zig:3:1: error: redeclaration of variable 'a'");
|
||||
|
||||
add_compile_fail_case("byvalue struct on exported functions", R"SOURCE(
|
||||
add_compile_fail_case("byvalue struct parameter in exported function", R"SOURCE(
|
||||
struct A { x : i32, }
|
||||
export fn f(a : A) {}
|
||||
)SOURCE", 1, ".tmp_source.zig:3:13: error: byvalue struct parameters not yet supported on extern functions");
|
||||
)SOURCE", 1, ".tmp_source.zig:3:13: error: byvalue types not yet supported on extern function parameters");
|
||||
|
||||
add_compile_fail_case("byvalue struct return value in exported function", R"SOURCE(
|
||||
struct A { x: i32, }
|
||||
export fn f() -> A {
|
||||
A {.x = 1234 }
|
||||
}
|
||||
)SOURCE", 1, ".tmp_source.zig:3:18: error: byvalue types not yet supported on extern function return values");
|
||||
|
||||
add_compile_fail_case("duplicate field in struct value expression", R"SOURCE(
|
||||
struct A {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user