| ... | @@ -1015,6 +1015,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionHasDecl *) { | ... | @@ -1015,6 +1015,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionHasDecl *) { |
| 1015 | return IrInstructionIdHasDecl; | 1015 | return IrInstructionIdHasDecl; |
| 1016 | } | 1016 | } |
| 1017 | | 1017 | |
| | 1018 | static constexpr IrInstructionId ir_instruction_id(IrInstructionUndeclaredIdent *) { |
| | 1019 | return IrInstructionIdUndeclaredIdent; |
| | 1020 | } |
| | 1021 | |
| 1018 | template<typename T> | 1022 | template<typename T> |
| 1019 | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { | 1023 | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1020 | T *special_instruction = allocate<T>(1); | 1024 | T *special_instruction = allocate<T>(1); |
| ... | @@ -3031,6 +3035,15 @@ static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *s | ... | @@ -3031,6 +3035,15 @@ static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *s |
| 3031 | return &instruction->base; | 3035 | return &instruction->base; |
| 3032 | } | 3036 | } |
| 3033 | | 3037 | |
| | 3038 | static IrInstruction *ir_build_undeclared_identifier(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| | 3039 | Buf *name) |
| | 3040 | { |
| | 3041 | IrInstructionUndeclaredIdent *instruction = ir_build_instruction<IrInstructionUndeclaredIdent>(irb, scope, source_node); |
| | 3042 | instruction->name = name; |
| | 3043 | |
| | 3044 | return &instruction->base; |
| | 3045 | } |
| | 3046 | |
| 3034 | static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *scope_is_comptime, IrInstruction *is_comptime) { | 3047 | static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *scope_is_comptime, IrInstruction *is_comptime) { |
| 3035 | IrInstructionCheckRuntimeScope *instruction = ir_build_instruction<IrInstructionCheckRuntimeScope>(irb, scope, source_node); | 3048 | IrInstructionCheckRuntimeScope *instruction = ir_build_instruction<IrInstructionCheckRuntimeScope>(irb, scope, source_node); |
| 3036 | instruction->scope_is_comptime = scope_is_comptime; | 3049 | instruction->scope_is_comptime = scope_is_comptime; |
| ... | @@ -3896,13 +3909,18 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, | ... | @@ -3896,13 +3909,18 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3896 | | 3909 | |
| 3897 | Buf *variable_name = node->data.symbol_expr.symbol; | 3910 | Buf *variable_name = node->data.symbol_expr.symbol; |
| 3898 | | 3911 | |
| 3899 | if (buf_eql_str(variable_name, "_") && lval == LValPtr) { | 3912 | if (buf_eql_str(variable_name, "_")) { |
| 3900 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node); | 3913 | if (lval == LValPtr) { |
| 3901 | const_instruction->base.value.type = get_pointer_to_type(irb->codegen, | 3914 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node); |
| 3902 | irb->codegen->builtin_types.entry_void, false); | 3915 | const_instruction->base.value.type = get_pointer_to_type(irb->codegen, |
| 3903 | const_instruction->base.value.special = ConstValSpecialStatic; | 3916 | irb->codegen->builtin_types.entry_void, false); |
| 3904 | const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialDiscard; | 3917 | const_instruction->base.value.special = ConstValSpecialStatic; |
| 3905 | return &const_instruction->base; | 3918 | const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialDiscard; |
| | 3919 | return &const_instruction->base; |
| | 3920 | } else { |
| | 3921 | add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to")); |
| | 3922 | return irb->codegen->invalid_instruction; |
| | 3923 | } |
| 3906 | } | 3924 | } |
| 3907 | | 3925 | |
| 3908 | ZigType *primitive_type; | 3926 | ZigType *primitive_type; |
| ... | @@ -3943,11 +3961,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, | ... | @@ -3943,11 +3961,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3943 | return irb->codegen->invalid_instruction; | 3961 | return irb->codegen->invalid_instruction; |
| 3944 | } | 3962 | } |
| 3945 | | 3963 | |
| 3946 | // put a variable of same name with invalid type in global scope | 3964 | return ir_build_undeclared_identifier(irb, scope, node, variable_name); |
| 3947 | // so that future references to this same name will find a variable with an invalid type | | |
| 3948 | populate_invalid_variable_in_scope(irb->codegen, scope, node, variable_name); | | |
| 3949 | add_node_error(irb->codegen, node, buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name))); | | |
| 3950 | return irb->codegen->invalid_instruction; | | |
| 3951 | } | 3965 | } |
| 3952 | | 3966 | |
| 3953 | static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { | 3967 | static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { |
| ... | @@ -23237,6 +23251,16 @@ static IrInstruction *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstruct | ... | @@ -23237,6 +23251,16 @@ static IrInstruction *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstruct |
| 23237 | return ir_const_bool(ira, &instruction->base, true); | 23251 | return ir_const_bool(ira, &instruction->base, true); |
| 23238 | } | 23252 | } |
| 23239 | | 23253 | |
| | 23254 | static IrInstruction *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstructionUndeclaredIdent *instruction) { |
| | 23255 | // put a variable of same name with invalid type in global scope |
| | 23256 | // so that future references to this same name will find a variable with an invalid type |
| | 23257 | populate_invalid_variable_in_scope(ira->codegen, instruction->base.scope, instruction->base.source_node, |
| | 23258 | instruction->name); |
| | 23259 | ir_add_error(ira, &instruction->base, |
| | 23260 | buf_sprintf("use of undeclared identifier '%s'", buf_ptr(instruction->name))); |
| | 23261 | return ira->codegen->invalid_instruction; |
| | 23262 | } |
| | 23263 | |
| 23240 | static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { | 23264 | static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { |
| 23241 | switch (instruction->id) { | 23265 | switch (instruction->id) { |
| 23242 | case IrInstructionIdInvalid: | 23266 | case IrInstructionIdInvalid: |
| ... | @@ -23533,6 +23557,8 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio | ... | @@ -23533,6 +23557,8 @@ static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructio |
| 23533 | return ir_analyze_instruction_check_runtime_scope(ira, (IrInstructionCheckRuntimeScope *)instruction); | 23557 | return ir_analyze_instruction_check_runtime_scope(ira, (IrInstructionCheckRuntimeScope *)instruction); |
| 23534 | case IrInstructionIdHasDecl: | 23558 | case IrInstructionIdHasDecl: |
| 23535 | return ir_analyze_instruction_has_decl(ira, (IrInstructionHasDecl *)instruction); | 23559 | return ir_analyze_instruction_has_decl(ira, (IrInstructionHasDecl *)instruction); |
| | 23560 | case IrInstructionIdUndeclaredIdent: |
| | 23561 | return ir_analyze_instruction_undeclared_ident(ira, (IrInstructionUndeclaredIdent *)instruction); |
| 23536 | } | 23562 | } |
| 23537 | zig_unreachable(); | 23563 | zig_unreachable(); |
| 23538 | } | 23564 | } |
| ... | @@ -23667,6 +23693,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -23667,6 +23693,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 23667 | case IrInstructionIdAssertNonNull: | 23693 | case IrInstructionIdAssertNonNull: |
| 23668 | case IrInstructionIdResizeSlice: | 23694 | case IrInstructionIdResizeSlice: |
| 23669 | case IrInstructionIdGlobalAsm: | 23695 | case IrInstructionIdGlobalAsm: |
| | 23696 | case IrInstructionIdUndeclaredIdent: |
| 23670 | return true; | 23697 | return true; |
| 23671 | | 23698 | |
| 23672 | case IrInstructionIdPhi: | 23699 | case IrInstructionIdPhi: |