| ... | ... | @@ -927,6 +927,20 @@ static const char *calling_convention_fn_type_str(CallingConvention cc) { |
| 927 | 927 | zig_unreachable(); |
| 928 | 928 | } |
| 929 | 929 | |
| 930 | static bool calling_convention_allows_zig_types(CallingConvention cc) { |
| 931 | switch (cc) { |
| 932 | case CallingConventionUnspecified: |
| 933 | case CallingConventionAsync: |
| 934 | return true; |
| 935 | case CallingConventionC: |
| 936 | case CallingConventionCold: |
| 937 | case CallingConventionNaked: |
| 938 | case CallingConventionStdcall: |
| 939 | return false; |
| 940 | } |
| 941 | zig_unreachable(); |
| 942 | } |
| 943 | |
| 930 | 944 | TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g) { |
| 931 | 945 | if (g->stack_trace_type == nullptr) { |
| 932 | 946 | ConstExprValue *stack_trace_type_val = get_builtin_value(g, "StackTrace"); |
| ... | ... | @@ -1380,7 +1394,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1380 | 1394 | bool param_is_var_args = param_node->data.param_decl.is_var_args; |
| 1381 | 1395 | |
| 1382 | 1396 | if (param_is_comptime) { |
| 1383 | | if (fn_type_id.cc != CallingConventionUnspecified) { |
| 1397 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1384 | 1398 | add_node_error(g, param_node, |
| 1385 | 1399 | buf_sprintf("comptime parameter not allowed in function with calling convention '%s'", |
| 1386 | 1400 | calling_convention_name(fn_type_id.cc))); |
| ... | ... | @@ -1391,7 +1405,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1391 | 1405 | if (fn_type_id.cc == CallingConventionC) { |
| 1392 | 1406 | fn_type_id.param_count = fn_type_id.next_param_index; |
| 1393 | 1407 | continue; |
| 1394 | | } else if (fn_type_id.cc == CallingConventionUnspecified) { |
| 1408 | } else if (calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1395 | 1409 | return get_generic_fn_type(g, &fn_type_id); |
| 1396 | 1410 | } else { |
| 1397 | 1411 | add_node_error(g, param_node, |
| ... | ... | @@ -1405,7 +1419,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1405 | 1419 | if (type_is_invalid(type_entry)) { |
| 1406 | 1420 | return g->builtin_types.entry_invalid; |
| 1407 | 1421 | } |
| 1408 | | if (fn_type_id.cc != CallingConventionUnspecified) { |
| 1422 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1409 | 1423 | type_ensure_zero_bits_known(g, type_entry); |
| 1410 | 1424 | if (!type_has_bits(type_entry)) { |
| 1411 | 1425 | add_node_error(g, param_node->data.param_decl.type, |
| ... | ... | @@ -1415,7 +1429,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1415 | 1429 | } |
| 1416 | 1430 | } |
| 1417 | 1431 | |
| 1418 | | if (fn_type_id.cc != CallingConventionUnspecified && !type_allowed_in_extern(g, type_entry)) { |
| 1432 | if (!calling_convention_allows_zig_types(fn_type_id.cc) && !type_allowed_in_extern(g, type_entry)) { |
| 1419 | 1433 | add_node_error(g, param_node->data.param_decl.type, |
| 1420 | 1434 | buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'", |
| 1421 | 1435 | buf_ptr(&type_entry->name), |
| ... | ... | @@ -1435,7 +1449,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1435 | 1449 | buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name))); |
| 1436 | 1450 | return g->builtin_types.entry_invalid; |
| 1437 | 1451 | case TypeTableEntryIdVar: |
| 1438 | | if (fn_type_id.cc != CallingConventionUnspecified) { |
| 1452 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1439 | 1453 | add_node_error(g, param_node->data.param_decl.type, |
| 1440 | 1454 | buf_sprintf("parameter of type 'var' not allowed in function with calling convention '%s'", |
| 1441 | 1455 | calling_convention_name(fn_type_id.cc))); |
| ... | ... | @@ -1467,7 +1481,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1467 | 1481 | case TypeTableEntryIdFn: |
| 1468 | 1482 | case TypeTableEntryIdPromise: |
| 1469 | 1483 | ensure_complete_type(g, type_entry); |
| 1470 | | if (fn_type_id.cc == CallingConventionUnspecified && !type_is_copyable(g, type_entry)) { |
| 1484 | if (calling_convention_allows_zig_types(fn_type_id.cc) && !type_is_copyable(g, type_entry)) { |
| 1471 | 1485 | add_node_error(g, param_node->data.param_decl.type, |
| 1472 | 1486 | buf_sprintf("type '%s' is not copyable; cannot pass by value", buf_ptr(&type_entry->name))); |
| 1473 | 1487 | return g->builtin_types.entry_invalid; |
| ... | ... | @@ -1498,7 +1512,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1498 | 1512 | fn_type_id.return_type = specified_return_type; |
| 1499 | 1513 | } |
| 1500 | 1514 | |
| 1501 | | if (fn_type_id.cc != CallingConventionUnspecified && !type_allowed_in_extern(g, fn_type_id.return_type)) { |
| 1515 | if (!calling_convention_allows_zig_types(fn_type_id.cc) && !type_allowed_in_extern(g, fn_type_id.return_type)) { |
| 1502 | 1516 | add_node_error(g, fn_proto->return_type, |
| 1503 | 1517 | buf_sprintf("return type '%s' not allowed in function with calling convention '%s'", |
| 1504 | 1518 | buf_ptr(&fn_type_id.return_type->name), |
| ... | ... | @@ -1525,7 +1539,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1525 | 1539 | case TypeTableEntryIdBoundFn: |
| 1526 | 1540 | case TypeTableEntryIdVar: |
| 1527 | 1541 | case TypeTableEntryIdMetaType: |
| 1528 | | if (fn_type_id.cc != CallingConventionUnspecified) { |
| 1542 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1529 | 1543 | add_node_error(g, fn_proto->return_type, |
| 1530 | 1544 | buf_sprintf("return type '%s' not allowed in function with calling convention '%s'", |
| 1531 | 1545 | buf_ptr(&fn_type_id.return_type->name), |