| author | |
| committer | |
| log | 596ca6cf70cf43c27e31bbcfc36bcdc70b13897a |
| tree | 1f6915d289cf77ac70d7a7f23ca7f2b6f73e4aa6 |
| parent | 78962eeeda07d613ebdfd239082268a6702c19db |
4 files changed, 16 insertions(+), 6 deletions(-)
src/analyze.cpp+7-4| ... | @@ -3823,15 +3823,18 @@ static Error resolve_decl_container(CodeGen *g, TldContainer *tld_container) { | ... | @@ -3823,15 +3823,18 @@ static Error resolve_decl_container(CodeGen *g, TldContainer *tld_container) { |
| 3823 | } | 3823 | } |
| 3824 | } | 3824 | } |
| 3825 | 3825 | ||
| 3826 | ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry) { | 3826 | ZigType *validate_var_type(CodeGen *g, AstNodeVariableDeclaration *source_node, ZigType *type_entry) { |
| 3827 | switch (type_entry->id) { | 3827 | switch (type_entry->id) { |
| 3828 | case ZigTypeIdInvalid: | 3828 | case ZigTypeIdInvalid: |
| 3829 | return g->builtin_types.entry_invalid; | 3829 | return g->builtin_types.entry_invalid; |
| 3830 | case ZigTypeIdOpaque: | ||
| 3831 | if (source_node->is_extern) | ||
| 3832 | return type_entry; | ||
| 3833 | ZIG_FALLTHROUGH; | ||
| 3830 | case ZigTypeIdUnreachable: | 3834 | case ZigTypeIdUnreachable: |
| 3831 | case ZigTypeIdUndefined: | 3835 | case ZigTypeIdUndefined: |
| 3832 | case ZigTypeIdNull: | 3836 | case ZigTypeIdNull: |
| 3833 | case ZigTypeIdOpaque: | 3837 | add_node_error(g, source_node->type, buf_sprintf("variable of type '%s' not allowed", |
| 3834 | add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed", | ||
| 3835 | buf_ptr(&type_entry->name))); | 3838 | buf_ptr(&type_entry->name))); |
| 3836 | return g->builtin_types.entry_invalid; | 3839 | return g->builtin_types.entry_invalid; |
| 3837 | case ZigTypeIdComptimeFloat: | 3840 | case ZigTypeIdComptimeFloat: |
| ... | @@ -3973,7 +3976,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) { | ... | @@ -3973,7 +3976,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) { |
| 3973 | } else { | 3976 | } else { |
| 3974 | tld_var->analyzing_type = true; | 3977 | tld_var->analyzing_type = true; |
| 3975 | ZigType *proposed_type = analyze_type_expr(g, tld_var->base.parent_scope, var_decl->type); | 3978 | ZigType *proposed_type = analyze_type_expr(g, tld_var->base.parent_scope, var_decl->type); |
| 3976 | explicit_type = validate_var_type(g, var_decl->type, proposed_type); | 3979 | explicit_type = validate_var_type(g, var_decl, proposed_type); |
| 3977 | } | 3980 | } |
| 3978 | } | 3981 | } |
| 3979 | 3982 |
src/analyze.hpp+1-1| ... | @@ -77,7 +77,7 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node, bool all | ... | @@ -77,7 +77,7 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node, bool all |
| 77 | ZigType *get_src_ptr_type(ZigType *type); | 77 | ZigType *get_src_ptr_type(ZigType *type); |
| 78 | uint32_t get_ptr_align(CodeGen *g, ZigType *type); | 78 | uint32_t get_ptr_align(CodeGen *g, ZigType *type); |
| 79 | bool get_ptr_const(CodeGen *g, ZigType *type); | 79 | bool get_ptr_const(CodeGen *g, ZigType *type); |
| 80 | ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry); | 80 | ZigType *validate_var_type(CodeGen *g, AstNodeVariableDeclaration *source_node, ZigType *type_entry); |
| 81 | ZigType *container_ref_type(ZigType *type_entry); | 81 | ZigType *container_ref_type(ZigType *type_entry); |
| 82 | bool type_is_complete(ZigType *type_entry); | 82 | bool type_is_complete(ZigType *type_entry); |
| 83 | bool type_is_resolved(ZigType *type_entry, ResolveStatus status); | 83 | bool type_is_resolved(ZigType *type_entry, ResolveStatus status); |
src/ir.cpp+1-1| ... | @@ -18505,7 +18505,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV | ... | @@ -18505,7 +18505,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV |
| 18505 | if (decl_var_instruction->var_type != nullptr) { | 18505 | if (decl_var_instruction->var_type != nullptr) { |
| 18506 | var_type = decl_var_instruction->var_type->child; | 18506 | var_type = decl_var_instruction->var_type->child; |
| 18507 | ZigType *proposed_type = ir_resolve_type(ira, var_type); | 18507 | ZigType *proposed_type = ir_resolve_type(ira, var_type); |
| 18508 | explicit_type = validate_var_type(ira->codegen, var_type->base.source_node, proposed_type); | 18508 | explicit_type = validate_var_type(ira->codegen, &var->decl_node->data.variable_declaration, proposed_type); |
| 18509 | if (type_is_invalid(explicit_type)) { | 18509 | if (type_is_invalid(explicit_type)) { |
| 18510 | var->var_type = ira->codegen->builtin_types.entry_invalid; | 18510 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 18511 | return ira->codegen->invalid_inst_gen; | 18511 | return ira->codegen->invalid_inst_gen; |
test/stage1/behavior/misc.zig+7| ... | @@ -713,3 +713,10 @@ test "auto created variables have correct alignment" { | ... | @@ -713,3 +713,10 @@ test "auto created variables have correct alignment" { |
| 713 | expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a); | 713 | expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a); |
| 714 | comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a); | 714 | comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a); |
| 715 | } | 715 | } |
| 716 | |||
| 717 | extern var opaque_extern_var: @Type(.Opaque); | ||
| 718 | var var_to_export: u32 = 42; | ||
| 719 | test "extern variable with non-pointer opaque type" { | ||
| 720 | @export(var_to_export, .{ .name = "opaque_extern_var" }); | ||
| 721 | expect(@ptrCast(*align(1) u32, &opaque_extern_var).* == 42); | ||
| 722 | } |