| ... | ... | @@ -1754,7 +1754,7 @@ static Error emit_error_unless_type_allowed_in_packed_union(CodeGen *g, ZigType |
| 1754 | 1754 | return emit_error_unless_type_allowed_in_packed_container(g, type_entry, source_node, "union"); |
| 1755 | 1755 | } |
| 1756 | 1756 | |
| 1757 | | Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { |
| 1757 | Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, ExternPosition position, bool *result) { |
| 1758 | 1758 | Error err; |
| 1759 | 1759 | switch (type_entry->id) { |
| 1760 | 1760 | case ZigTypeIdInvalid: |
| ... | ... | @@ -1773,8 +1773,10 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { |
| 1773 | 1773 | case ZigTypeIdAnyFrame: |
| 1774 | 1774 | *result = false; |
| 1775 | 1775 | return ErrorNone; |
| 1776 | | case ZigTypeIdOpaque: |
| 1777 | 1776 | case ZigTypeIdUnreachable: |
| 1777 | *result = position == ExternPositionFunctionReturn; |
| 1778 | return ErrorNone; |
| 1779 | case ZigTypeIdOpaque: |
| 1778 | 1780 | case ZigTypeIdBool: |
| 1779 | 1781 | *result = true; |
| 1780 | 1782 | return ErrorNone; |
| ... | ... | @@ -1792,23 +1794,27 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { |
| 1792 | 1794 | return ErrorNone; |
| 1793 | 1795 | } |
| 1794 | 1796 | case ZigTypeIdVector: |
| 1795 | | return type_allowed_in_extern(g, type_entry->data.vector.elem_type, result); |
| 1797 | return type_allowed_in_extern(g, type_entry->data.vector.elem_type, ExternPositionOther, result); |
| 1796 | 1798 | case ZigTypeIdFloat: |
| 1797 | 1799 | *result = true; |
| 1798 | 1800 | return ErrorNone; |
| 1799 | 1801 | case ZigTypeIdArray: |
| 1800 | | return type_allowed_in_extern(g, type_entry->data.array.child_type, result); |
| 1802 | if ((err = type_allowed_in_extern(g, type_entry->data.array.child_type, ExternPositionOther, result))) |
| 1803 | return err; |
| 1804 | *result = *result && |
| 1805 | position != ExternPositionFunctionParameter && |
| 1806 | position != ExternPositionFunctionReturn; |
| 1807 | return ErrorNone; |
| 1801 | 1808 | case ZigTypeIdFn: |
| 1802 | 1809 | *result = !calling_convention_allows_zig_types(type_entry->data.fn.fn_type_id.cc); |
| 1803 | 1810 | return ErrorNone; |
| 1804 | 1811 | case ZigTypeIdPointer: |
| 1805 | 1812 | if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown))) |
| 1806 | 1813 | return err; |
| 1807 | | if (!type_has_bits(g, type_entry)) { |
| 1808 | | *result = false; |
| 1809 | | return ErrorNone; |
| 1810 | | } |
| 1811 | | *result = true; |
| 1814 | bool has_bits; |
| 1815 | if ((err = type_has_bits2(g, type_entry, &has_bits))) |
| 1816 | return err; |
| 1817 | *result = has_bits; |
| 1812 | 1818 | return ErrorNone; |
| 1813 | 1819 | case ZigTypeIdStruct: |
| 1814 | 1820 | *result = type_entry->data.structure.layout == ContainerLayoutExtern || |
| ... | ... | @@ -1820,23 +1826,24 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { |
| 1820 | 1826 | *result = false; |
| 1821 | 1827 | return ErrorNone; |
| 1822 | 1828 | } |
| 1823 | | if (!type_is_nonnull_ptr(g, child_type)) { |
| 1829 | bool is_nonnull_ptr; |
| 1830 | if ((err = type_is_nonnull_ptr2(g, child_type, &is_nonnull_ptr))) |
| 1831 | return err; |
| 1832 | if (!is_nonnull_ptr) { |
| 1824 | 1833 | *result = false; |
| 1825 | 1834 | return ErrorNone; |
| 1826 | 1835 | } |
| 1827 | | return type_allowed_in_extern(g, child_type, result); |
| 1836 | return type_allowed_in_extern(g, child_type, ExternPositionOther, result); |
| 1828 | 1837 | } |
| 1829 | 1838 | case ZigTypeIdEnum: { |
| 1830 | 1839 | if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown))) |
| 1831 | 1840 | return err; |
| 1832 | 1841 | ZigType *tag_int_type = type_entry->data.enumeration.tag_int_type; |
| 1833 | | if (type_entry->data.enumeration.has_explicit_tag_type) { |
| 1834 | | return type_allowed_in_extern(g, tag_int_type, result); |
| 1835 | | } else { |
| 1836 | | *result = type_entry->data.enumeration.layout == ContainerLayoutExtern || |
| 1837 | | type_entry->data.enumeration.layout == ContainerLayoutPacked; |
| 1838 | | return ErrorNone; |
| 1839 | | } |
| 1842 | if (type_entry->data.enumeration.has_explicit_tag_type) |
| 1843 | return type_allowed_in_extern(g, tag_int_type, position, result); |
| 1844 | *result = type_entry->data.enumeration.layout == ContainerLayoutExtern || |
| 1845 | type_entry->data.enumeration.layout == ContainerLayoutPacked; |
| 1846 | return ErrorNone; |
| 1840 | 1847 | } |
| 1841 | 1848 | case ZigTypeIdUnion: |
| 1842 | 1849 | *result = type_entry->data.unionation.layout == ContainerLayoutExtern || |
| ... | ... | @@ -1933,7 +1940,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 1933 | 1940 | |
| 1934 | 1941 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1935 | 1942 | bool ok_type; |
| 1936 | | if ((err = type_allowed_in_extern(g, type_entry, &ok_type))) |
| 1943 | if ((err = type_allowed_in_extern(g, type_entry, ExternPositionFunctionParameter, &ok_type))) |
| 1937 | 1944 | return g->builtin_types.entry_invalid; |
| 1938 | 1945 | if (!ok_type) { |
| 1939 | 1946 | add_node_error(g, param_node->data.param_decl.type, |
| ... | ... | @@ -2038,7 +2045,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 2038 | 2045 | if ((err = type_resolve(g, fn_type_id.return_type, ResolveStatusSizeKnown))) |
| 2039 | 2046 | return g->builtin_types.entry_invalid; |
| 2040 | 2047 | bool ok_type; |
| 2041 | | if ((err = type_allowed_in_extern(g, fn_type_id.return_type, &ok_type))) |
| 2048 | if ((err = type_allowed_in_extern(g, fn_type_id.return_type, ExternPositionFunctionReturn, &ok_type))) |
| 2042 | 2049 | return g->builtin_types.entry_invalid; |
| 2043 | 2050 | if (!ok_type) { |
| 2044 | 2051 | add_node_error(g, fn_proto->return_type, |
| ... | ... | @@ -2357,7 +2364,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { |
| 2357 | 2364 | |
| 2358 | 2365 | if (struct_type->data.structure.layout == ContainerLayoutExtern) { |
| 2359 | 2366 | bool ok_type; |
| 2360 | | if ((err = type_allowed_in_extern(g, field_type, &ok_type))) { |
| 2367 | if ((err = type_allowed_in_extern(g, field_type, ExternPositionOther, &ok_type))) { |
| 2361 | 2368 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; |
| 2362 | 2369 | return ErrorSemanticAnalyzeFail; |
| 2363 | 2370 | } |
| ... | ... | @@ -2612,7 +2619,7 @@ static Error type_is_valid_extern_enum_tag(CodeGen *g, ZigType *ty, bool *result |
| 2612 | 2619 | // signed char, a signed integer or an unsigned one. But GCC/Clang allow |
| 2613 | 2620 | // other integral types as a compiler extension so let's accomodate them |
| 2614 | 2621 | // aswell. |
| 2615 | | return type_allowed_in_extern(g, ty, result); |
| 2622 | return type_allowed_in_extern(g, ty, ExternPositionOther, result); |
| 2616 | 2623 | } |
| 2617 | 2624 | |
| 2618 | 2625 | static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { |