| ... | @@ -927,6 +927,20 @@ static const char *calling_convention_fn_type_str(CallingConvention cc) { | ... | @@ -927,6 +927,20 @@ static const char *calling_convention_fn_type_str(CallingConvention cc) { |
| 927 | zig_unreachable(); | 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 | TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g) { | 944 | TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g) { |
| 931 | if (g->stack_trace_type == nullptr) { | 945 | if (g->stack_trace_type == nullptr) { |
| 932 | ConstExprValue *stack_trace_type_val = get_builtin_value(g, "StackTrace"); | 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,7 +1394,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1380 | bool param_is_var_args = param_node->data.param_decl.is_var_args; | 1394 | bool param_is_var_args = param_node->data.param_decl.is_var_args; |
| 1381 | | 1395 | |
| 1382 | if (param_is_comptime) { | 1396 | if (param_is_comptime) { |
| 1383 | if (fn_type_id.cc != CallingConventionUnspecified) { | 1397 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1384 | add_node_error(g, param_node, | 1398 | add_node_error(g, param_node, |
| 1385 | buf_sprintf("comptime parameter not allowed in function with calling convention '%s'", | 1399 | buf_sprintf("comptime parameter not allowed in function with calling convention '%s'", |
| 1386 | calling_convention_name(fn_type_id.cc))); | 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,7 +1405,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1391 | if (fn_type_id.cc == CallingConventionC) { | 1405 | if (fn_type_id.cc == CallingConventionC) { |
| 1392 | fn_type_id.param_count = fn_type_id.next_param_index; | 1406 | fn_type_id.param_count = fn_type_id.next_param_index; |
| 1393 | continue; | 1407 | continue; |
| 1394 | } else if (fn_type_id.cc == CallingConventionUnspecified) { | 1408 | } else if (calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1395 | return get_generic_fn_type(g, &fn_type_id); | 1409 | return get_generic_fn_type(g, &fn_type_id); |
| 1396 | } else { | 1410 | } else { |
| 1397 | add_node_error(g, param_node, | 1411 | add_node_error(g, param_node, |
| ... | @@ -1405,7 +1419,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c | ... | @@ -1405,7 +1419,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1405 | if (type_is_invalid(type_entry)) { | 1419 | if (type_is_invalid(type_entry)) { |
| 1406 | return g->builtin_types.entry_invalid; | 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 | type_ensure_zero_bits_known(g, type_entry); | 1423 | type_ensure_zero_bits_known(g, type_entry); |
| 1410 | if (!type_has_bits(type_entry)) { | 1424 | if (!type_has_bits(type_entry)) { |
| 1411 | add_node_error(g, param_node->data.param_decl.type, | 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,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 | add_node_error(g, param_node->data.param_decl.type, | 1433 | add_node_error(g, param_node->data.param_decl.type, |
| 1420 | buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'", | 1434 | buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'", |
| 1421 | buf_ptr(&type_entry->name), | 1435 | buf_ptr(&type_entry->name), |
| ... | @@ -1435,7 +1449,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c | ... | @@ -1435,7 +1449,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1435 | buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name))); | 1449 | buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name))); |
| 1436 | return g->builtin_types.entry_invalid; | 1450 | return g->builtin_types.entry_invalid; |
| 1437 | case TypeTableEntryIdVar: | 1451 | case TypeTableEntryIdVar: |
| 1438 | if (fn_type_id.cc != CallingConventionUnspecified) { | 1452 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1439 | add_node_error(g, param_node->data.param_decl.type, | 1453 | add_node_error(g, param_node->data.param_decl.type, |
| 1440 | buf_sprintf("parameter of type 'var' not allowed in function with calling convention '%s'", | 1454 | buf_sprintf("parameter of type 'var' not allowed in function with calling convention '%s'", |
| 1441 | calling_convention_name(fn_type_id.cc))); | 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,7 +1481,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1467 | case TypeTableEntryIdFn: | 1481 | case TypeTableEntryIdFn: |
| 1468 | case TypeTableEntryIdPromise: | 1482 | case TypeTableEntryIdPromise: |
| 1469 | ensure_complete_type(g, type_entry); | 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 | add_node_error(g, param_node->data.param_decl.type, | 1485 | add_node_error(g, param_node->data.param_decl.type, |
| 1472 | buf_sprintf("type '%s' is not copyable; cannot pass by value", buf_ptr(&type_entry->name))); | 1486 | buf_sprintf("type '%s' is not copyable; cannot pass by value", buf_ptr(&type_entry->name))); |
| 1473 | return g->builtin_types.entry_invalid; | 1487 | return g->builtin_types.entry_invalid; |
| ... | @@ -1498,7 +1512,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c | ... | @@ -1498,7 +1512,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1498 | fn_type_id.return_type = specified_return_type; | 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 | add_node_error(g, fn_proto->return_type, | 1516 | add_node_error(g, fn_proto->return_type, |
| 1503 | buf_sprintf("return type '%s' not allowed in function with calling convention '%s'", | 1517 | buf_sprintf("return type '%s' not allowed in function with calling convention '%s'", |
| 1504 | buf_ptr(&fn_type_id.return_type->name), | 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,7 +1539,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c |
| 1525 | case TypeTableEntryIdBoundFn: | 1539 | case TypeTableEntryIdBoundFn: |
| 1526 | case TypeTableEntryIdVar: | 1540 | case TypeTableEntryIdVar: |
| 1527 | case TypeTableEntryIdMetaType: | 1541 | case TypeTableEntryIdMetaType: |
| 1528 | if (fn_type_id.cc != CallingConventionUnspecified) { | 1542 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1529 | add_node_error(g, fn_proto->return_type, | 1543 | add_node_error(g, fn_proto->return_type, |
| 1530 | buf_sprintf("return type '%s' not allowed in function with calling convention '%s'", | 1544 | buf_sprintf("return type '%s' not allowed in function with calling convention '%s'", |
| 1531 | buf_ptr(&fn_type_id.return_type->name), | 1545 | buf_ptr(&fn_type_id.return_type->name), |