| ... | ... | @@ -50,6 +50,7 @@ struct IrAnalyze { |
| 50 | 50 | size_t *backward_branch_count; |
| 51 | 51 | size_t *backward_branch_quota; |
| 52 | 52 | ZigFn *fn; |
| 53 | IrInstSrc *suspend_source_instr; |
| 53 | 54 | |
| 54 | 55 | // For the purpose of using in a debugger |
| 55 | 56 | void dump(); |
| ... | ... | @@ -216,15 +217,14 @@ struct DbgIrBreakPoint { |
| 216 | 217 | }; |
| 217 | 218 | |
| 218 | 219 | static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type); |
| 219 | | static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr, |
| 220 | static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 220 | 221 | IrInstGen *value, ZigType *expected_type); |
| 221 | | static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr, |
| 222 | static IrInstGen *ir_get_deref(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *ptr, |
| 222 | 223 | ResultLoc *result_loc); |
| 223 | 224 | static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 224 | | IrInst* source_instr, IrInstGen *container_ptr, IrInst *container_ptr_src, |
| 225 | Scope *scope, AstNode *source_node, IrInstGen *container_ptr, AstNode *container_ptr_src, |
| 225 | 226 | ZigType *container_type, bool initializing); |
| 226 | | static void ir_assert_gen_impl(bool ok, IrInstGen *source_instruction, const char *file, unsigned int line); |
| 227 | | static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var); |
| 227 | static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigVar *var); |
| 228 | 228 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op); |
| 229 | 229 | static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align); |
| 230 | 230 | static ZigType *adjust_ptr_const(CodeGen *g, ZigType *ptr_type, bool is_const); |
| ... | ... | @@ -233,53 +233,51 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou |
| 233 | 233 | static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val); |
| 234 | 234 | static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, |
| 235 | 235 | ZigValue *out_val, ZigValue *ptr_val); |
| 236 | | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr, |
| 237 | | IrInst *ptr_src, ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on, |
| 238 | | bool keep_bigger_alignment); |
| 236 | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 237 | IrInstGen *ptr, AstNode *ptr_src, ZigType *dest_type, AstNode *dest_type_src, |
| 238 | bool safety_check_on, bool keep_bigger_alignment); |
| 239 | 239 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed); |
| 240 | 240 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align); |
| 241 | | static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 241 | static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target, |
| 242 | 242 | ZigType *ptr_type); |
| 243 | | static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 243 | static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value, |
| 244 | 244 | ZigType *dest_type); |
| 245 | | static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 245 | static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInstSrc *suspend_source_instr, |
| 246 | 246 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, bool allow_discard); |
| 247 | | static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 247 | static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInstSrc *suspend_source_instr, |
| 248 | 248 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, bool allow_discard); |
| 249 | | static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr, |
| 249 | static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 250 | 250 | IrInstGen *base_ptr, bool safety_check_on, bool initializing); |
| 251 | | static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr, |
| 251 | static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 252 | 252 | IrInstGen *base_ptr, bool safety_check_on, bool initializing); |
| 253 | | static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr, |
| 253 | static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 254 | 254 | IrInstGen *base_ptr, bool initializing); |
| 255 | | static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 255 | static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 256 | 256 | IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const); |
| 257 | 257 | static void ir_reset_result(ResultLoc *result_loc); |
| 258 | | static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 258 | static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 259 | 259 | TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing); |
| 260 | 260 | static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 261 | | IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type); |
| 262 | | static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value); |
| 263 | | static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst *source_instr); |
| 264 | | static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty); |
| 265 | | static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instruction, |
| 261 | Scope *scope, AstNode *source_node, IrInstGen *container_ptr, ZigType *container_type); |
| 262 | static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value); |
| 263 | static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, AstNode *source_node); |
| 264 | static IrInstGen *ir_const_undef(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty); |
| 265 | static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 266 | 266 | AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstGen *field_result_loc, |
| 267 | 267 | IrInstGen *result_loc); |
| 268 | | static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst* source_instr, |
| 268 | static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 269 | 269 | IrInstGen *struct_operand, TypeStructField *field); |
| 270 | 270 | static bool value_cmp_numeric_val_any(ZigValue *left, Cmp predicate, ZigValue *right); |
| 271 | 271 | static bool value_cmp_numeric_val_all(ZigValue *left, Cmp predicate, ZigValue *right); |
| 272 | 272 | static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, TypeStructField *field); |
| 273 | 273 | static void value_to_bigfloat(BigFloat *out, ZigValue *val); |
| 274 | 274 | |
| 275 | | static void ir_assert_impl(bool ok, IrInst *source_instruction, char const *file, unsigned int line) { |
| 275 | static void ir_assert_impl(bool ok, IrInstGen *source_instruction, char const *file, unsigned int line) { |
| 276 | 276 | if (ok) return; |
| 277 | 277 | src_assert_impl(ok, source_instruction->source_node, file, line); |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | | |
| 281 | 280 | #define ir_assert(OK, SOURCE_INSTRUCTION) ir_assert_impl((OK), (SOURCE_INSTRUCTION), __FILE__, __LINE__) |
| 282 | | #define ir_assert_gen(OK, SOURCE_INSTRUCTION) ir_assert_gen_impl((OK), (SOURCE_INSTRUCTION), __FILE__, __LINE__) |
| 283 | 281 | |
| 284 | 282 | void destroy_instruction_gen(IrInstGen *inst) { |
| 285 | 283 | switch (inst->id) { |
| ... | ... | @@ -498,7 +496,7 @@ static void ira_deref(IrAnalyze *ira) { |
| 498 | 496 | // destroy dangling IrInstGenConst |
| 499 | 497 | for (size_t i = 0; i < ira->new_irb.constants.length; i += 1) { |
| 500 | 498 | auto constant = ira->new_irb.constants.items[i]; |
| 501 | | if (constant->base.base.ref_count == 0 && !ir_inst_gen_has_side_effects(&constant->base)) |
| 499 | if (constant->base.ref_count == 0 && !ir_inst_gen_has_side_effects(&constant->base)) |
| 502 | 500 | destroy_instruction_gen(&constant->base); |
| 503 | 501 | } |
| 504 | 502 | ira->new_irb.constants.deinit(&heap::c_allocator); |
| ... | ... | @@ -692,7 +690,7 @@ static bool instr_is_comptime(IrInstGen *instruction) { |
| 692 | 690 | |
| 693 | 691 | static void ir_ref_inst_gen(IrInstGen *instruction) { |
| 694 | 692 | assert(instruction->id != IrInstGenIdInvalid); |
| 695 | | instruction->base.ref_count += 1; |
| 693 | instruction->ref_count += 1; |
| 696 | 694 | } |
| 697 | 695 | |
| 698 | 696 | static void create_result_ptr(CodeGen *codegen, ZigType *expected_type, |
| ... | ... | @@ -1108,9 +1106,9 @@ template<typename T> |
| 1108 | 1106 | static T *ir_create_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) { |
| 1109 | 1107 | T *special_instruction = heap::c_allocator.create<T>(); |
| 1110 | 1108 | special_instruction->base.id = ir_inst_id(special_instruction); |
| 1111 | | special_instruction->base.base.scope = scope; |
| 1112 | | special_instruction->base.base.source_node = source_node; |
| 1113 | | special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec); |
| 1109 | special_instruction->base.scope = scope; |
| 1110 | special_instruction->base.source_node = source_node; |
| 1111 | special_instruction->base.debug_id = exec_next_debug_id_gen(irb->exec); |
| 1114 | 1112 | special_instruction->base.owner_bb = irb->current_basic_block; |
| 1115 | 1113 | special_instruction->base.value = irb->codegen->pass1_arena->create<ZigValue>(); |
| 1116 | 1114 | return special_instruction; |
| ... | ... | @@ -1120,9 +1118,9 @@ template<typename T> |
| 1120 | 1118 | static T *ir_create_inst_noval(IrBuilderGen *irb, Scope *scope, AstNode *source_node) { |
| 1121 | 1119 | T *special_instruction = heap::c_allocator.create<T>(); |
| 1122 | 1120 | special_instruction->base.id = ir_inst_id(special_instruction); |
| 1123 | | special_instruction->base.base.scope = scope; |
| 1124 | | special_instruction->base.base.source_node = source_node; |
| 1125 | | special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec); |
| 1121 | special_instruction->base.scope = scope; |
| 1122 | special_instruction->base.source_node = source_node; |
| 1123 | special_instruction->base.debug_id = exec_next_debug_id_gen(irb->exec); |
| 1126 | 1124 | special_instruction->base.owner_bb = irb->current_basic_block; |
| 1127 | 1125 | return special_instruction; |
| 1128 | 1126 | } |
| ... | ... | @@ -1155,20 +1153,20 @@ IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigF |
| 1155 | 1153 | { |
| 1156 | 1154 | IrInstGenAlloca *alloca_gen = heap::c_allocator.create<IrInstGenAlloca>(); |
| 1157 | 1155 | alloca_gen->base.id = IrInstGenIdAlloca; |
| 1158 | | alloca_gen->base.base.source_node = source_node; |
| 1159 | | alloca_gen->base.base.scope = scope; |
| 1156 | alloca_gen->base.source_node = source_node; |
| 1157 | alloca_gen->base.scope = scope; |
| 1160 | 1158 | alloca_gen->base.value = g->pass1_arena->create<ZigValue>(); |
| 1161 | 1159 | alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false); |
| 1162 | | alloca_gen->base.base.ref_count = 1; |
| 1160 | alloca_gen->base.ref_count = 1; |
| 1163 | 1161 | alloca_gen->name_hint = name_hint; |
| 1164 | 1162 | fn->alloca_gen_list.append(alloca_gen); |
| 1165 | 1163 | return &alloca_gen->base; |
| 1166 | 1164 | } |
| 1167 | 1165 | |
| 1168 | | static IrInstGen *ir_build_cast(IrAnalyze *ira, IrInst *source_instr,ZigType *dest_type, |
| 1169 | | IrInstGen *value, CastOp cast_op) |
| 1166 | static IrInstGen *ir_build_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1167 | ZigType *dest_type, IrInstGen *value, CastOp cast_op) |
| 1170 | 1168 | { |
| 1171 | | IrInstGenCast *inst = ir_build_inst_gen<IrInstGenCast>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 1169 | IrInstGenCast *inst = ir_build_inst_gen<IrInstGenCast>(&ira->new_irb, scope, source_node); |
| 1172 | 1170 | inst->base.value->type = dest_type; |
| 1173 | 1171 | inst->value = value; |
| 1174 | 1172 | inst->cast_op = cast_op; |
| ... | ... | @@ -1178,10 +1176,10 @@ static IrInstGen *ir_build_cast(IrAnalyze *ira, IrInst *source_instr,ZigType *de |
| 1178 | 1176 | return &inst->base; |
| 1179 | 1177 | } |
| 1180 | 1178 | |
| 1181 | | static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *condition, |
| 1179 | static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *condition, |
| 1182 | 1180 | IrBasicBlockGen *then_block, IrBasicBlockGen *else_block) |
| 1183 | 1181 | { |
| 1184 | | IrInstGenCondBr *inst = ir_build_inst_noreturn<IrInstGenCondBr>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 1182 | IrInstGenCondBr *inst = ir_build_inst_noreturn<IrInstGenCondBr>(&ira->new_irb, scope, source_node); |
| 1185 | 1183 | inst->condition = condition; |
| 1186 | 1184 | inst->then_block = then_block; |
| 1187 | 1185 | inst->else_block = else_block; |
| ... | ... | @@ -1191,9 +1189,8 @@ static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, IrInst *source_instr, IrI |
| 1191 | 1189 | return &inst->base; |
| 1192 | 1190 | } |
| 1193 | 1191 | |
| 1194 | | static IrInstGen *ir_build_return_gen(IrAnalyze *ira, IrInst *source_inst, IrInstGen *operand) { |
| 1195 | | IrInstGenReturn *inst = ir_build_inst_noreturn<IrInstGenReturn>(&ira->new_irb, |
| 1196 | | source_inst->scope, source_inst->source_node); |
| 1192 | static IrInstGen *ir_build_return_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand) { |
| 1193 | IrInstGenReturn *inst = ir_build_inst_noreturn<IrInstGenReturn>(&ira->new_irb, scope, source_node); |
| 1197 | 1194 | inst->operand = operand; |
| 1198 | 1195 | |
| 1199 | 1196 | if (operand != nullptr) ir_ref_inst_gen(operand); |
| ... | ... | @@ -1201,11 +1198,11 @@ static IrInstGen *ir_build_return_gen(IrAnalyze *ira, IrInst *source_inst, IrIns |
| 1201 | 1198 | return &inst->base; |
| 1202 | 1199 | } |
| 1203 | 1200 | |
| 1204 | | static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *res_type, |
| 1201 | static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *res_type, |
| 1205 | 1202 | IrBinOp op_id, IrInstGen *op1, IrInstGen *op2, bool safety_check_on) |
| 1206 | 1203 | { |
| 1207 | 1204 | IrInstGenBinOp *inst = ir_build_inst_gen<IrInstGenBinOp>(&ira->new_irb, |
| 1208 | | source_instr->scope, source_instr->source_node); |
| 1205 | scope, source_node); |
| 1209 | 1206 | inst->base.value->type = res_type; |
| 1210 | 1207 | inst->op_id = op_id; |
| 1211 | 1208 | inst->op1 = op1; |
| ... | ... | @@ -1219,8 +1216,8 @@ static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, IrInst *source_instr, ZigT |
| 1219 | 1216 | } |
| 1220 | 1217 | |
| 1221 | 1218 | |
| 1222 | | static IrInstGen *ir_build_var_ptr_gen(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) { |
| 1223 | | IrInstGenVarPtr *instruction = ir_build_inst_gen<IrInstGenVarPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 1219 | static IrInstGen *ir_build_var_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigVar *var) { |
| 1220 | IrInstGenVarPtr *instruction = ir_build_inst_gen<IrInstGenVarPtr>(&ira->new_irb, scope, source_node); |
| 1224 | 1221 | instruction->var = var; |
| 1225 | 1222 | |
| 1226 | 1223 | var->ref_count += 1; |
| ... | ... | @@ -1249,10 +1246,10 @@ static IrInstGen *ir_build_elem_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *s |
| 1249 | 1246 | return &instruction->base; |
| 1250 | 1247 | } |
| 1251 | 1248 | |
| 1252 | | static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, IrInst *source_instr, |
| 1249 | static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1253 | 1250 | IrInstGen *struct_ptr, TypeStructField *field, ZigType *ptr_type) |
| 1254 | 1251 | { |
| 1255 | | IrInstGenStructFieldPtr *inst = ir_build_inst_gen<IrInstGenStructFieldPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 1252 | IrInstGenStructFieldPtr *inst = ir_build_inst_gen<IrInstGenStructFieldPtr>(&ira->new_irb, scope, source_node); |
| 1256 | 1253 | inst->base.value->type = ptr_type; |
| 1257 | 1254 | inst->struct_ptr = struct_ptr; |
| 1258 | 1255 | inst->field = field; |
| ... | ... | @@ -1262,11 +1259,11 @@ static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, IrInst *source_instr |
| 1262 | 1259 | return &inst->base; |
| 1263 | 1260 | } |
| 1264 | 1261 | |
| 1265 | | static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, IrInst *source_instr, |
| 1262 | static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1266 | 1263 | IrInstGen *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing, ZigType *ptr_type) |
| 1267 | 1264 | { |
| 1268 | 1265 | IrInstGenUnionFieldPtr *inst = ir_build_inst_gen<IrInstGenUnionFieldPtr>(&ira->new_irb, |
| 1269 | | source_instr->scope, source_instr->source_node); |
| 1266 | scope, source_node); |
| 1270 | 1267 | inst->base.value->type = ptr_type; |
| 1271 | 1268 | inst->initializing = initializing; |
| 1272 | 1269 | inst->safety_check_on = safety_check_on; |
| ... | ... | @@ -1278,13 +1275,13 @@ static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, IrInst *source_instr, |
| 1278 | 1275 | return &inst->base; |
| 1279 | 1276 | } |
| 1280 | 1277 | |
| 1281 | | static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 1278 | static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1282 | 1279 | ZigFn *fn_entry, IrInstGen *fn_ref, size_t arg_count, IrInstGen **args, |
| 1283 | 1280 | CallModifier modifier, IrInstGen *new_stack, bool is_async_call_builtin, |
| 1284 | 1281 | IrInstGen *result_loc, ZigType *return_type) |
| 1285 | 1282 | { |
| 1286 | 1283 | IrInstGenCall *call_instruction = ir_build_inst_gen<IrInstGenCall>(&ira->new_irb, |
| 1287 | | source_instruction->scope, source_instruction->source_node); |
| 1284 | scope, source_node); |
| 1288 | 1285 | call_instruction->base.value->type = return_type; |
| 1289 | 1286 | call_instruction->fn_entry = fn_entry; |
| 1290 | 1287 | call_instruction->fn_ref = fn_ref; |
| ... | ... | @@ -1304,14 +1301,14 @@ static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, IrInst *source_instructi |
| 1304 | 1301 | return call_instruction; |
| 1305 | 1302 | } |
| 1306 | 1303 | |
| 1307 | | static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, IrInst *source_instr, size_t incoming_count, |
| 1304 | static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, size_t incoming_count, |
| 1308 | 1305 | IrBasicBlockGen **incoming_blocks, IrInstGen **incoming_values, ZigType *result_type) |
| 1309 | 1306 | { |
| 1310 | 1307 | assert(incoming_count != 0); |
| 1311 | 1308 | assert(incoming_count != SIZE_MAX); |
| 1312 | 1309 | |
| 1313 | 1310 | IrInstGenPhi *phi_instruction = ir_build_inst_gen<IrInstGenPhi>(&ira->new_irb, |
| 1314 | | source_instr->scope, source_instr->source_node); |
| 1311 | scope, source_node); |
| 1315 | 1312 | phi_instruction->base.value->type = result_type; |
| 1316 | 1313 | phi_instruction->incoming_count = incoming_count; |
| 1317 | 1314 | phi_instruction->incoming_blocks = incoming_blocks; |
| ... | ... | @@ -1324,16 +1321,16 @@ static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, IrInst *source_instr, size_t |
| 1324 | 1321 | return &phi_instruction->base; |
| 1325 | 1322 | } |
| 1326 | 1323 | |
| 1327 | | static IrInstGen *ir_build_br_gen(IrAnalyze *ira, IrInst *source_instr, IrBasicBlockGen *dest_block) { |
| 1328 | | IrInstGenBr *inst = ir_build_inst_noreturn<IrInstGenBr>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 1324 | static IrInstGen *ir_build_br_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrBasicBlockGen *dest_block) { |
| 1325 | IrInstGenBr *inst = ir_build_inst_noreturn<IrInstGenBr>(&ira->new_irb, scope, source_node); |
| 1329 | 1326 | inst->dest_block = dest_block; |
| 1330 | 1327 | |
| 1331 | 1328 | return &inst->base; |
| 1332 | 1329 | } |
| 1333 | 1330 | |
| 1334 | | static IrInstGen *ir_build_negation(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, ZigType *expr_type, bool wrapping) { |
| 1331 | static IrInstGen *ir_build_negation(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand, ZigType *expr_type, bool wrapping) { |
| 1335 | 1332 | IrInstGenNegation *instruction = ir_build_inst_gen<IrInstGenNegation>(&ira->new_irb, |
| 1336 | | source_instr->scope, source_instr->source_node); |
| 1333 | scope, source_node); |
| 1337 | 1334 | instruction->base.value->type = expr_type; |
| 1338 | 1335 | instruction->operand = operand; |
| 1339 | 1336 | instruction->wrapping = wrapping; |
| ... | ... | @@ -1343,11 +1340,11 @@ static IrInstGen *ir_build_negation(IrAnalyze *ira, IrInst *source_instr, IrInst |
| 1343 | 1340 | return &instruction->base; |
| 1344 | 1341 | } |
| 1345 | 1342 | |
| 1346 | | static IrInstGen *ir_build_binary_not(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, |
| 1343 | static IrInstGen *ir_build_binary_not(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand, |
| 1347 | 1344 | ZigType *expr_type) |
| 1348 | 1345 | { |
| 1349 | 1346 | IrInstGenBinaryNot *instruction = ir_build_inst_gen<IrInstGenBinaryNot>(&ira->new_irb, |
| 1350 | | source_instr->scope, source_instr->source_node); |
| 1347 | scope, source_node); |
| 1351 | 1348 | instruction->base.value->type = expr_type; |
| 1352 | 1349 | instruction->operand = operand; |
| 1353 | 1350 | |
| ... | ... | @@ -1356,14 +1353,14 @@ static IrInstGen *ir_build_binary_not(IrAnalyze *ira, IrInst *source_instr, IrIn |
| 1356 | 1353 | return &instruction->base; |
| 1357 | 1354 | } |
| 1358 | 1355 | |
| 1359 | | static IrInstGen *ir_build_unreachable_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 1360 | | IrInstGenUnreachable *inst = ir_build_inst_noreturn<IrInstGenUnreachable>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 1356 | static IrInstGen *ir_build_unreachable_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) { |
| 1357 | IrInstGenUnreachable *inst = ir_build_inst_noreturn<IrInstGenUnreachable>(&ira->new_irb, scope, source_node); |
| 1361 | 1358 | return &inst->base; |
| 1362 | 1359 | } |
| 1363 | 1360 | |
| 1364 | | static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr, IrInstGen *value) { |
| 1361 | static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *ptr, IrInstGen *value) { |
| 1365 | 1362 | IrInstGenStorePtr *instruction = ir_build_inst_void<IrInstGenStorePtr>(&ira->new_irb, |
| 1366 | | source_instr->scope, source_instr->source_node); |
| 1363 | scope, source_node); |
| 1367 | 1364 | instruction->ptr = ptr; |
| 1368 | 1365 | instruction->value = value; |
| 1369 | 1366 | |
| ... | ... | @@ -1373,11 +1370,11 @@ static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, IrInst *source_instr, I |
| 1373 | 1370 | return &instruction->base; |
| 1374 | 1371 | } |
| 1375 | 1372 | |
| 1376 | | static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, IrInst *src_inst, |
| 1373 | static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1377 | 1374 | IrInstGen *vector_ptr, IrInstGen *index, IrInstGen *value) |
| 1378 | 1375 | { |
| 1379 | 1376 | IrInstGenVectorStoreElem *inst = ir_build_inst_void<IrInstGenVectorStoreElem>( |
| 1380 | | &ira->new_irb, src_inst->scope, src_inst->source_node); |
| 1377 | &ira->new_irb, scope, source_node); |
| 1381 | 1378 | inst->vector_ptr = vector_ptr; |
| 1382 | 1379 | inst->index = index; |
| 1383 | 1380 | inst->value = value; |
| ... | ... | @@ -1389,11 +1386,11 @@ static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, IrInst *src_inst, |
| 1389 | 1386 | return &inst->base; |
| 1390 | 1387 | } |
| 1391 | 1388 | |
| 1392 | | static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 1389 | static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1393 | 1390 | ZigVar *var, IrInstGen *var_ptr) |
| 1394 | 1391 | { |
| 1395 | 1392 | IrInstGenDeclVar *inst = ir_build_inst_gen<IrInstGenDeclVar>(&ira->new_irb, |
| 1396 | | source_instruction->scope, source_instruction->source_node); |
| 1393 | scope, source_node); |
| 1397 | 1394 | inst->base.value->special = ConstValSpecialStatic; |
| 1398 | 1395 | inst->base.value->type = ira->codegen->builtin_types.entry_void; |
| 1399 | 1396 | inst->var = var; |
| ... | ... | @@ -1404,11 +1401,11 @@ static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instructi |
| 1404 | 1401 | return &inst->base; |
| 1405 | 1402 | } |
| 1406 | 1403 | |
| 1407 | | static IrInstGen *ir_build_extern_gen(IrAnalyze *ira, IrInst *source_instr, Buf *name, |
| 1404 | static IrInstGen *ir_build_extern_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, Buf *name, |
| 1408 | 1405 | GlobalLinkageId linkage, bool is_thread_local, ZigType *expr_type) |
| 1409 | 1406 | { |
| 1410 | 1407 | IrInstGenExtern *instruction = ir_build_inst_gen<IrInstGenExtern>(&ira->new_irb, |
| 1411 | | source_instr->scope, source_instr->source_node); |
| 1408 | scope, source_node); |
| 1412 | 1409 | instruction->base.value->type = expr_type; |
| 1413 | 1410 | instruction->name = name; |
| 1414 | 1411 | instruction->linkage = linkage; |
| ... | ... | @@ -1417,11 +1414,11 @@ static IrInstGen *ir_build_extern_gen(IrAnalyze *ira, IrInst *source_instr, Buf |
| 1417 | 1414 | return &instruction->base; |
| 1418 | 1415 | } |
| 1419 | 1416 | |
| 1420 | | static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 1417 | static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1421 | 1418 | IrInstGen *ptr, ZigType *ty, IrInstGen *result_loc) |
| 1422 | 1419 | { |
| 1423 | 1420 | IrInstGenLoadPtr *instruction = ir_build_inst_gen<IrInstGenLoadPtr>( |
| 1424 | | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1421 | &ira->new_irb, scope, source_node); |
| 1425 | 1422 | instruction->base.value->type = ty; |
| 1426 | 1423 | instruction->ptr = ptr; |
| 1427 | 1424 | instruction->result_loc = result_loc; |
| ... | ... | @@ -1432,12 +1429,12 @@ static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, IrInst *source_instructi |
| 1432 | 1429 | return &instruction->base; |
| 1433 | 1430 | } |
| 1434 | 1431 | |
| 1435 | | static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr, |
| 1432 | static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1436 | 1433 | Buf *asm_template, AsmToken *token_list, size_t token_list_len, |
| 1437 | 1434 | IrInstGen **input_list, IrInstGen **output_types, ZigVar **output_vars, size_t return_count, |
| 1438 | 1435 | bool has_side_effects, ZigType *return_type) |
| 1439 | 1436 | { |
| 1440 | | IrInstGenAsm *instruction = ir_build_inst_gen<IrInstGenAsm>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 1437 | IrInstGenAsm *instruction = ir_build_inst_gen<IrInstGenAsm>(&ira->new_irb, scope, source_node); |
| 1441 | 1438 | instruction->base.value->type = return_type; |
| 1442 | 1439 | instruction->asm_template = asm_template; |
| 1443 | 1440 | instruction->token_list = token_list; |
| ... | ... | @@ -1448,13 +1445,13 @@ static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr, |
| 1448 | 1445 | instruction->return_count = return_count; |
| 1449 | 1446 | instruction->has_side_effects = has_side_effects; |
| 1450 | 1447 | |
| 1451 | | assert(source_instr->source_node->type == NodeTypeAsmExpr); |
| 1452 | | for (size_t i = 0; i < source_instr->source_node->data.asm_expr.output_list.length; i += 1) { |
| 1448 | assert(source_node->type == NodeTypeAsmExpr); |
| 1449 | for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) { |
| 1453 | 1450 | IrInstGen *output_type = output_types[i]; |
| 1454 | 1451 | if (output_type) ir_ref_inst_gen(output_type); |
| 1455 | 1452 | } |
| 1456 | 1453 | |
| 1457 | | for (size_t i = 0; i < source_instr->source_node->data.asm_expr.input_list.length; i += 1) { |
| 1454 | for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) { |
| 1458 | 1455 | IrInstGen *input_value = input_list[i]; |
| 1459 | 1456 | ir_ref_inst_gen(input_value); |
| 1460 | 1457 | } |
| ... | ... | @@ -1462,9 +1459,9 @@ static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr, |
| 1462 | 1459 | return &instruction->base; |
| 1463 | 1460 | } |
| 1464 | 1461 | |
| 1465 | | static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) { |
| 1462 | static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value) { |
| 1466 | 1463 | IrInstGenTestNonNull *inst = ir_build_inst_gen<IrInstGenTestNonNull>(&ira->new_irb, |
| 1467 | | source_instr->scope, source_instr->source_node); |
| 1464 | scope, source_node); |
| 1468 | 1465 | inst->base.value->type = ira->codegen->builtin_types.entry_bool; |
| 1469 | 1466 | inst->value = value; |
| 1470 | 1467 | |
| ... | ... | @@ -1473,11 +1470,11 @@ static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, IrInst *source_inst |
| 1473 | 1470 | return &inst->base; |
| 1474 | 1471 | } |
| 1475 | 1472 | |
| 1476 | | static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, IrInst *source_instr, |
| 1473 | static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1477 | 1474 | IrInstGen *base_ptr, bool safety_check_on, bool initializing, ZigType *result_type) |
| 1478 | 1475 | { |
| 1479 | 1476 | IrInstGenOptionalUnwrapPtr *inst = ir_build_inst_gen<IrInstGenOptionalUnwrapPtr>(&ira->new_irb, |
| 1480 | | source_instr->scope, source_instr->source_node); |
| 1477 | scope, source_node); |
| 1481 | 1478 | inst->base.value->type = result_type; |
| 1482 | 1479 | inst->base_ptr = base_ptr; |
| 1483 | 1480 | inst->safety_check_on = safety_check_on; |
| ... | ... | @@ -1488,11 +1485,11 @@ static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, IrInst *sourc |
| 1488 | 1485 | return &inst->base; |
| 1489 | 1486 | } |
| 1490 | 1487 | |
| 1491 | | static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_ty, |
| 1488 | static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_ty, |
| 1492 | 1489 | IrInstGen *operand, IrInstGen *result_loc) |
| 1493 | 1490 | { |
| 1494 | 1491 | IrInstGenOptionalWrap *instruction = ir_build_inst_gen<IrInstGenOptionalWrap>( |
| 1495 | | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1492 | &ira->new_irb, scope, source_node); |
| 1496 | 1493 | instruction->base.value->type = result_ty; |
| 1497 | 1494 | instruction->operand = operand; |
| 1498 | 1495 | instruction->result_loc = result_loc; |
| ... | ... | @@ -1503,11 +1500,11 @@ static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, IrInst *source_instruct |
| 1503 | 1500 | return &instruction->base; |
| 1504 | 1501 | } |
| 1505 | 1502 | |
| 1506 | | static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, IrInst *source_instruction, |
| 1503 | static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1507 | 1504 | ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc) |
| 1508 | 1505 | { |
| 1509 | 1506 | IrInstGenErrWrapPayload *instruction = ir_build_inst_gen<IrInstGenErrWrapPayload>( |
| 1510 | | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1507 | &ira->new_irb, scope, source_node); |
| 1511 | 1508 | instruction->base.value->type = result_type; |
| 1512 | 1509 | instruction->operand = operand; |
| 1513 | 1510 | instruction->result_loc = result_loc; |
| ... | ... | @@ -1518,11 +1515,11 @@ static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, IrInst *source_instr |
| 1518 | 1515 | return &instruction->base; |
| 1519 | 1516 | } |
| 1520 | 1517 | |
| 1521 | | static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, IrInst *source_instruction, |
| 1518 | static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1522 | 1519 | ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc) |
| 1523 | 1520 | { |
| 1524 | 1521 | IrInstGenErrWrapCode *instruction = ir_build_inst_gen<IrInstGenErrWrapCode>( |
| 1525 | | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1522 | &ira->new_irb, scope, source_node); |
| 1526 | 1523 | instruction->base.value->type = result_type; |
| 1527 | 1524 | instruction->operand = operand; |
| 1528 | 1525 | instruction->result_loc = result_loc; |
| ... | ... | @@ -1533,9 +1530,9 @@ static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, IrInst *source_instruct |
| 1533 | 1530 | return &instruction->base; |
| 1534 | 1531 | } |
| 1535 | 1532 | |
| 1536 | | static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) { |
| 1533 | static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type, IrInstGen *op) { |
| 1537 | 1534 | IrInstGenClz *instruction = ir_build_inst_gen<IrInstGenClz>(&ira->new_irb, |
| 1538 | | source_instr->scope, source_instr->source_node); |
| 1535 | scope, source_node); |
| 1539 | 1536 | instruction->base.value->type = result_type; |
| 1540 | 1537 | instruction->op = op; |
| 1541 | 1538 | |
| ... | ... | @@ -1544,9 +1541,9 @@ static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType |
| 1544 | 1541 | return &instruction->base; |
| 1545 | 1542 | } |
| 1546 | 1543 | |
| 1547 | | static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) { |
| 1544 | static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type, IrInstGen *op) { |
| 1548 | 1545 | IrInstGenCtz *instruction = ir_build_inst_gen<IrInstGenCtz>(&ira->new_irb, |
| 1549 | | source_instr->scope, source_instr->source_node); |
| 1546 | scope, source_node); |
| 1550 | 1547 | instruction->base.value->type = result_type; |
| 1551 | 1548 | instruction->op = op; |
| 1552 | 1549 | |
| ... | ... | @@ -1555,11 +1552,11 @@ static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType |
| 1555 | 1552 | return &instruction->base; |
| 1556 | 1553 | } |
| 1557 | 1554 | |
| 1558 | | static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, |
| 1555 | static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type, |
| 1559 | 1556 | IrInstGen *op) |
| 1560 | 1557 | { |
| 1561 | 1558 | IrInstGenPopCount *instruction = ir_build_inst_gen<IrInstGenPopCount>(&ira->new_irb, |
| 1562 | | source_instr->scope, source_instr->source_node); |
| 1559 | scope, source_node); |
| 1563 | 1560 | instruction->base.value->type = result_type; |
| 1564 | 1561 | instruction->op = op; |
| 1565 | 1562 | |
| ... | ... | @@ -1568,11 +1565,11 @@ static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, IrInst *source_instr, Z |
| 1568 | 1565 | return &instruction->base; |
| 1569 | 1566 | } |
| 1570 | 1567 | |
| 1571 | | static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *op_type, |
| 1568 | static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *op_type, |
| 1572 | 1569 | IrInstGen *op) |
| 1573 | 1570 | { |
| 1574 | 1571 | IrInstGenBswap *instruction = ir_build_inst_gen<IrInstGenBswap>(&ira->new_irb, |
| 1575 | | source_instr->scope, source_instr->source_node); |
| 1572 | scope, source_node); |
| 1576 | 1573 | instruction->base.value->type = op_type; |
| 1577 | 1574 | instruction->op = op; |
| 1578 | 1575 | |
| ... | ... | @@ -1581,11 +1578,11 @@ static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, IrInst *source_instr, ZigTy |
| 1581 | 1578 | return &instruction->base; |
| 1582 | 1579 | } |
| 1583 | 1580 | |
| 1584 | | static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *int_type, |
| 1581 | static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *int_type, |
| 1585 | 1582 | IrInstGen *op) |
| 1586 | 1583 | { |
| 1587 | 1584 | IrInstGenBitReverse *instruction = ir_build_inst_gen<IrInstGenBitReverse>(&ira->new_irb, |
| 1588 | | source_instr->scope, source_instr->source_node); |
| 1585 | scope, source_node); |
| 1589 | 1586 | instruction->base.value->type = int_type; |
| 1590 | 1587 | instruction->op = op; |
| 1591 | 1588 | |
| ... | ... | @@ -1594,11 +1591,11 @@ static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, IrInst *source_instr, |
| 1594 | 1591 | return &instruction->base; |
| 1595 | 1592 | } |
| 1596 | 1593 | |
| 1597 | | static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, IrInst *source_instr, |
| 1594 | static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1598 | 1595 | IrInstGen *target_value, IrBasicBlockGen *else_block, size_t case_count, IrInstGenSwitchBrCase *cases) |
| 1599 | 1596 | { |
| 1600 | 1597 | IrInstGenSwitchBr *instruction = ir_build_inst_noreturn<IrInstGenSwitchBr>(&ira->new_irb, |
| 1601 | | source_instr->scope, source_instr->source_node); |
| 1598 | scope, source_node); |
| 1602 | 1599 | instruction->target_value = target_value; |
| 1603 | 1600 | instruction->else_block = else_block; |
| 1604 | 1601 | instruction->case_count = case_count; |
| ... | ... | @@ -1613,11 +1610,11 @@ static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, IrInst *source_ |
| 1613 | 1610 | return instruction; |
| 1614 | 1611 | } |
| 1615 | 1612 | |
| 1616 | | static IrInstGen *ir_build_union_tag(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, |
| 1613 | static IrInstGen *ir_build_union_tag(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value, |
| 1617 | 1614 | ZigType *tag_type) |
| 1618 | 1615 | { |
| 1619 | 1616 | IrInstGenUnionTag *instruction = ir_build_inst_gen<IrInstGenUnionTag>(&ira->new_irb, |
| 1620 | | source_instr->scope, source_instr->source_node); |
| 1617 | scope, source_node); |
| 1621 | 1618 | instruction->value = value; |
| 1622 | 1619 | instruction->base.value->type = tag_type; |
| 1623 | 1620 | |
| ... | ... | @@ -1626,11 +1623,11 @@ static IrInstGen *ir_build_union_tag(IrAnalyze *ira, IrInst *source_instr, IrIns |
| 1626 | 1623 | return &instruction->base; |
| 1627 | 1624 | } |
| 1628 | 1625 | |
| 1629 | | static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type, |
| 1626 | static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type, |
| 1630 | 1627 | IrInstGen *operand, IrInstGen *result_loc) |
| 1631 | 1628 | { |
| 1632 | 1629 | IrInstGenRef *instruction = ir_build_inst_gen<IrInstGenRef>(&ira->new_irb, |
| 1633 | | source_instruction->scope, source_instruction->source_node); |
| 1630 | scope, source_node); |
| 1634 | 1631 | instruction->base.value->type = result_type; |
| 1635 | 1632 | instruction->operand = operand; |
| 1636 | 1633 | instruction->result_loc = result_loc; |
| ... | ... | @@ -1641,11 +1638,11 @@ static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, IrInst *source_instruction, Z |
| 1641 | 1638 | return &instruction->base; |
| 1642 | 1639 | } |
| 1643 | 1640 | |
| 1644 | | static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, |
| 1641 | static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value, |
| 1645 | 1642 | ZigType *str_type) |
| 1646 | 1643 | { |
| 1647 | 1644 | IrInstGenErrName *instruction = ir_build_inst_gen<IrInstGenErrName>(&ira->new_irb, |
| 1648 | | source_instr->scope, source_instr->source_node); |
| 1645 | scope, source_node); |
| 1649 | 1646 | instruction->base.value->type = str_type; |
| 1650 | 1647 | instruction->value = value; |
| 1651 | 1648 | |
| ... | ... | @@ -1654,12 +1651,12 @@ static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, IrInst *source_instr, Ir |
| 1654 | 1651 | return &instruction->base; |
| 1655 | 1652 | } |
| 1656 | 1653 | |
| 1657 | | static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type, |
| 1654 | static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type, |
| 1658 | 1655 | IrInstGen *ptr, IrInstGen *cmp_value, IrInstGen *new_value, |
| 1659 | 1656 | AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstGen *result_loc) |
| 1660 | 1657 | { |
| 1661 | 1658 | IrInstGenCmpxchg *instruction = ir_build_inst_gen<IrInstGenCmpxchg>(&ira->new_irb, |
| 1662 | | source_instruction->scope, source_instruction->source_node); |
| 1659 | scope, source_node); |
| 1663 | 1660 | instruction->base.value->type = result_type; |
| 1664 | 1661 | instruction->ptr = ptr; |
| 1665 | 1662 | instruction->cmp_value = cmp_value; |
| ... | ... | @@ -1677,17 +1674,17 @@ static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instructio |
| 1677 | 1674 | return &instruction->base; |
| 1678 | 1675 | } |
| 1679 | 1676 | |
| 1680 | | static IrInstGen *ir_build_fence_gen(IrAnalyze *ira, IrInst *source_instr, AtomicOrder order) { |
| 1677 | static IrInstGen *ir_build_fence_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, AtomicOrder order) { |
| 1681 | 1678 | IrInstGenFence *instruction = ir_build_inst_void<IrInstGenFence>(&ira->new_irb, |
| 1682 | | source_instr->scope, source_instr->source_node); |
| 1679 | scope, source_node); |
| 1683 | 1680 | instruction->order = order; |
| 1684 | 1681 | |
| 1685 | 1682 | return &instruction->base; |
| 1686 | 1683 | } |
| 1687 | 1684 | |
| 1688 | | static IrInstGen *ir_build_reduce_gen(IrAnalyze *ira, IrInst *source_instruction, ReduceOp op, IrInstGen *value, ZigType *result_type) { |
| 1685 | static IrInstGen *ir_build_reduce_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ReduceOp op, IrInstGen *value, ZigType *result_type) { |
| 1689 | 1686 | IrInstGenReduce *instruction = ir_build_inst_gen<IrInstGenReduce>(&ira->new_irb, |
| 1690 | | source_instruction->scope, source_instruction->source_node); |
| 1687 | scope, source_node); |
| 1691 | 1688 | instruction->base.value->type = result_type; |
| 1692 | 1689 | instruction->op = op; |
| 1693 | 1690 | instruction->value = value; |
| ... | ... | @@ -1713,23 +1710,23 @@ static void ir_set_cursor_at_end_and_append_block_gen(IrBuilderGen *irb, IrBasic |
| 1713 | 1710 | ir_set_cursor_at_end_gen(irb, basic_block); |
| 1714 | 1711 | } |
| 1715 | 1712 | |
| 1716 | | static IrInstGen *ir_build_suspend_begin_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 1713 | static IrInstGen *ir_build_suspend_begin_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) { |
| 1717 | 1714 | IrInstGenSuspendBegin *inst = ir_build_inst_void<IrInstGenSuspendBegin>(&ira->new_irb, |
| 1718 | | source_instr->scope, source_instr->source_node); |
| 1715 | scope, source_node); |
| 1719 | 1716 | return &inst->base; |
| 1720 | 1717 | } |
| 1721 | 1718 | |
| 1722 | | static IrInstGen *ir_build_save_err_ret_addr_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 1719 | static IrInstGen *ir_build_save_err_ret_addr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) { |
| 1723 | 1720 | IrInstGenSaveErrRetAddr *inst = ir_build_inst_void<IrInstGenSaveErrRetAddr>(&ira->new_irb, |
| 1724 | | source_instr->scope, source_instr->source_node); |
| 1721 | scope, source_node); |
| 1725 | 1722 | return &inst->base; |
| 1726 | 1723 | } |
| 1727 | 1724 | |
| 1728 | | static IrInstGen *ir_build_truncate_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *dest_type, |
| 1725 | static IrInstGen *ir_build_truncate_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *dest_type, |
| 1729 | 1726 | IrInstGen *target) |
| 1730 | 1727 | { |
| 1731 | 1728 | IrInstGenTruncate *instruction = ir_build_inst_gen<IrInstGenTruncate>(&ira->new_irb, |
| 1732 | | source_instr->scope, source_instr->source_node); |
| 1729 | scope, source_node); |
| 1733 | 1730 | instruction->base.value->type = dest_type; |
| 1734 | 1731 | instruction->target = target; |
| 1735 | 1732 | |
| ... | ... | @@ -1754,11 +1751,11 @@ static IrInstGen *ir_build_shuffle_vector_gen(IrAnalyze *ira, Scope *scope, AstN |
| 1754 | 1751 | return &inst->base; |
| 1755 | 1752 | } |
| 1756 | 1753 | |
| 1757 | | static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type, |
| 1754 | static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *result_type, |
| 1758 | 1755 | IrInstGen *scalar) |
| 1759 | 1756 | { |
| 1760 | 1757 | IrInstGenSplat *instruction = ir_build_inst_gen<IrInstGenSplat>( |
| 1761 | | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1758 | &ira->new_irb, scope, source_node); |
| 1762 | 1759 | instruction->base.value->type = result_type; |
| 1763 | 1760 | instruction->scalar = scalar; |
| 1764 | 1761 | |
| ... | ... | @@ -1767,9 +1764,9 @@ static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 1767 | 1764 | return &instruction->base; |
| 1768 | 1765 | } |
| 1769 | 1766 | |
| 1770 | | static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) { |
| 1767 | static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value) { |
| 1771 | 1768 | IrInstGenBoolNot *instruction = ir_build_inst_gen<IrInstGenBoolNot>(&ira->new_irb, |
| 1772 | | source_instr->scope, source_instr->source_node); |
| 1769 | scope, source_node); |
| 1773 | 1770 | instruction->base.value->type = ira->codegen->builtin_types.entry_bool; |
| 1774 | 1771 | instruction->value = value; |
| 1775 | 1772 | |
| ... | ... | @@ -1778,11 +1775,11 @@ static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, IrInst *source_instr, Ir |
| 1778 | 1775 | return &instruction->base; |
| 1779 | 1776 | } |
| 1780 | 1777 | |
| 1781 | | static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, IrInst *source_instr, |
| 1778 | static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1782 | 1779 | IrInstGen *dest_ptr, IrInstGen *byte, IrInstGen *count) |
| 1783 | 1780 | { |
| 1784 | 1781 | IrInstGenMemset *instruction = ir_build_inst_void<IrInstGenMemset>(&ira->new_irb, |
| 1785 | | source_instr->scope, source_instr->source_node); |
| 1782 | scope, source_node); |
| 1786 | 1783 | instruction->dest_ptr = dest_ptr; |
| 1787 | 1784 | instruction->byte = byte; |
| 1788 | 1785 | instruction->count = count; |
| ... | ... | @@ -1794,11 +1791,11 @@ static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, IrInst *source_instr, |
| 1794 | 1791 | return &instruction->base; |
| 1795 | 1792 | } |
| 1796 | 1793 | |
| 1797 | | static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, IrInst *source_instr, |
| 1794 | static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1798 | 1795 | IrInstGen *dest_ptr, IrInstGen *src_ptr, IrInstGen *count) |
| 1799 | 1796 | { |
| 1800 | 1797 | IrInstGenMemcpy *instruction = ir_build_inst_void<IrInstGenMemcpy>(&ira->new_irb, |
| 1801 | | source_instr->scope, source_instr->source_node); |
| 1798 | scope, source_node); |
| 1802 | 1799 | instruction->dest_ptr = dest_ptr; |
| 1803 | 1800 | instruction->src_ptr = src_ptr; |
| 1804 | 1801 | instruction->count = count; |
| ... | ... | @@ -1810,12 +1807,12 @@ static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, IrInst *source_instr, |
| 1810 | 1807 | return &instruction->base; |
| 1811 | 1808 | } |
| 1812 | 1809 | |
| 1813 | | static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *slice_type, |
| 1810 | static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *slice_type, |
| 1814 | 1811 | IrInstGen *ptr, IrInstGen *start, IrInstGen *end, bool safety_check_on, IrInstGen *result_loc, |
| 1815 | 1812 | ZigValue *sentinel) |
| 1816 | 1813 | { |
| 1817 | 1814 | IrInstGenSlice *instruction = ir_build_inst_gen<IrInstGenSlice>( |
| 1818 | | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1815 | &ira->new_irb, scope, source_node); |
| 1819 | 1816 | instruction->base.value->type = slice_type; |
| 1820 | 1817 | instruction->ptr = ptr; |
| 1821 | 1818 | instruction->start = start; |
| ... | ... | @@ -1832,33 +1829,33 @@ static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 1832 | 1829 | return &instruction->base; |
| 1833 | 1830 | } |
| 1834 | 1831 | |
| 1835 | | static IrInstGen *ir_build_breakpoint_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 1832 | static IrInstGen *ir_build_breakpoint_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) { |
| 1836 | 1833 | IrInstGenBreakpoint *instruction = ir_build_inst_void<IrInstGenBreakpoint>(&ira->new_irb, |
| 1837 | | source_instr->scope, source_instr->source_node); |
| 1834 | scope, source_node); |
| 1838 | 1835 | return &instruction->base; |
| 1839 | 1836 | } |
| 1840 | 1837 | |
| 1841 | | static IrInstGen *ir_build_return_address_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 1842 | | IrInstGenReturnAddress *inst = ir_build_inst_gen<IrInstGenReturnAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 1838 | static IrInstGen *ir_build_return_address_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) { |
| 1839 | IrInstGenReturnAddress *inst = ir_build_inst_gen<IrInstGenReturnAddress>(&ira->new_irb, scope, source_node); |
| 1843 | 1840 | inst->base.value->type = ira->codegen->builtin_types.entry_usize; |
| 1844 | 1841 | return &inst->base; |
| 1845 | 1842 | } |
| 1846 | 1843 | |
| 1847 | | static IrInstGen *ir_build_frame_address_gen(IrAnalyze *ira, IrInst *source_instr) { |
| 1848 | | IrInstGenFrameAddress *inst = ir_build_inst_gen<IrInstGenFrameAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 1844 | static IrInstGen *ir_build_frame_address_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node) { |
| 1845 | IrInstGenFrameAddress *inst = ir_build_inst_gen<IrInstGenFrameAddress>(&ira->new_irb, scope, source_node); |
| 1849 | 1846 | inst->base.value->type = ira->codegen->builtin_types.entry_usize; |
| 1850 | 1847 | return &inst->base; |
| 1851 | 1848 | } |
| 1852 | 1849 | |
| 1853 | | static IrInstGen *ir_build_handle_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *ty) { |
| 1854 | | IrInstGenFrameHandle *inst = ir_build_inst_gen<IrInstGenFrameHandle>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 1850 | static IrInstGen *ir_build_handle_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) { |
| 1851 | IrInstGenFrameHandle *inst = ir_build_inst_gen<IrInstGenFrameHandle>(&ira->new_irb, scope, source_node); |
| 1855 | 1852 | inst->base.value->type = ty; |
| 1856 | 1853 | return &inst->base; |
| 1857 | 1854 | } |
| 1858 | 1855 | |
| 1859 | | static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *fn) |
| 1856 | static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *fn) |
| 1860 | 1857 | { |
| 1861 | | IrInstGenFrameSize *inst = ir_build_inst_gen<IrInstGenFrameSize>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 1858 | IrInstGenFrameSize *inst = ir_build_inst_gen<IrInstGenFrameSize>(&ira->new_irb, scope, source_node); |
| 1862 | 1859 | inst->base.value->type = ira->codegen->builtin_types.entry_usize; |
| 1863 | 1860 | inst->fn = fn; |
| 1864 | 1861 | |
| ... | ... | @@ -1867,12 +1864,12 @@ static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, IrInst *source_instr, |
| 1867 | 1864 | return &inst->base; |
| 1868 | 1865 | } |
| 1869 | 1866 | |
| 1870 | | static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, IrInst *source_instr, |
| 1867 | static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1871 | 1868 | IrOverflowOp op, IrInstGen *op1, IrInstGen *op2, IrInstGen *result_ptr, |
| 1872 | 1869 | ZigType *result_ptr_type) |
| 1873 | 1870 | { |
| 1874 | 1871 | IrInstGenOverflowOp *instruction = ir_build_inst_gen<IrInstGenOverflowOp>(&ira->new_irb, |
| 1875 | | source_instr->scope, source_instr->source_node); |
| 1872 | scope, source_node); |
| 1876 | 1873 | instruction->base.value->type = ira->codegen->builtin_types.entry_bool; |
| 1877 | 1874 | instruction->op = op; |
| 1878 | 1875 | instruction->op1 = op1; |
| ... | ... | @@ -1887,11 +1884,11 @@ static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, IrInst *source_instr, |
| 1887 | 1884 | return &instruction->base; |
| 1888 | 1885 | } |
| 1889 | 1886 | |
| 1890 | | static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, |
| 1887 | static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand, |
| 1891 | 1888 | BuiltinFnId fn_id, ZigType *operand_type) |
| 1892 | 1889 | { |
| 1893 | 1890 | IrInstGenFloatOp *instruction = ir_build_inst_gen<IrInstGenFloatOp>(&ira->new_irb, |
| 1894 | | source_instr->scope, source_instr->source_node); |
| 1891 | scope, source_node); |
| 1895 | 1892 | instruction->base.value->type = operand_type; |
| 1896 | 1893 | instruction->operand = operand; |
| 1897 | 1894 | instruction->fn_id = fn_id; |
| ... | ... | @@ -1901,11 +1898,11 @@ static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, IrInst *source_instr, Ir |
| 1901 | 1898 | return &instruction->base; |
| 1902 | 1899 | } |
| 1903 | 1900 | |
| 1904 | | static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *op1, IrInstGen *op2, |
| 1901 | static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *op1, IrInstGen *op2, |
| 1905 | 1902 | IrInstGen *op3, ZigType *expr_type) |
| 1906 | 1903 | { |
| 1907 | 1904 | IrInstGenMulAdd *instruction = ir_build_inst_gen<IrInstGenMulAdd>(&ira->new_irb, |
| 1908 | | source_instr->scope, source_instr->source_node); |
| 1905 | scope, source_node); |
| 1909 | 1906 | instruction->base.value->type = expr_type; |
| 1910 | 1907 | instruction->op1 = op1; |
| 1911 | 1908 | instruction->op2 = op2; |
| ... | ... | @@ -1918,9 +1915,9 @@ static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, IrInst *source_instr, IrI |
| 1918 | 1915 | return &instruction->base; |
| 1919 | 1916 | } |
| 1920 | 1917 | |
| 1921 | | static IrInstGen *ir_build_test_err_gen(IrAnalyze *ira, IrInst *source_instruction, IrInstGen *err_union) { |
| 1918 | static IrInstGen *ir_build_test_err_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *err_union) { |
| 1922 | 1919 | IrInstGenTestErr *instruction = ir_build_inst_gen<IrInstGenTestErr>( |
| 1923 | | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1920 | &ira->new_irb, scope, source_node); |
| 1924 | 1921 | instruction->base.value->type = ira->codegen->builtin_types.entry_bool; |
| 1925 | 1922 | instruction->err_union = err_union; |
| 1926 | 1923 | |
| ... | ... | @@ -1955,11 +1952,11 @@ static IrInstGen *ir_build_unwrap_err_payload_gen(IrAnalyze *ira, Scope *scope, |
| 1955 | 1952 | return &inst->base; |
| 1956 | 1953 | } |
| 1957 | 1954 | |
| 1958 | | static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 1955 | static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1959 | 1956 | ZigType *ptr_type, IrInstGen *ptr, bool safety_check_on) |
| 1960 | 1957 | { |
| 1961 | 1958 | IrInstGenPtrCast *instruction = ir_build_inst_gen<IrInstGenPtrCast>( |
| 1962 | | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1959 | &ira->new_irb, scope, source_node); |
| 1963 | 1960 | instruction->base.value->type = ptr_type; |
| 1964 | 1961 | instruction->ptr = ptr; |
| 1965 | 1962 | instruction->safety_check_on = safety_check_on; |
| ... | ... | @@ -1969,11 +1966,11 @@ static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInst *source_instructi |
| 1969 | 1966 | return &instruction->base; |
| 1970 | 1967 | } |
| 1971 | 1968 | |
| 1972 | | static IrInstGen *ir_build_bit_cast_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 1969 | static IrInstGen *ir_build_bit_cast_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 1973 | 1970 | IrInstGen *operand, ZigType *ty) |
| 1974 | 1971 | { |
| 1975 | 1972 | IrInstGenBitCast *instruction = ir_build_inst_gen<IrInstGenBitCast>( |
| 1976 | | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1973 | &ira->new_irb, scope, source_node); |
| 1977 | 1974 | instruction->base.value->type = ty; |
| 1978 | 1975 | instruction->operand = operand; |
| 1979 | 1976 | |
| ... | ... | @@ -2006,8 +2003,8 @@ static IrInstGen *ir_build_int_to_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode |
| 2006 | 2003 | return &instruction->base; |
| 2007 | 2004 | } |
| 2008 | 2005 | |
| 2009 | | static IrInstGen *ir_build_ptr_to_int_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) { |
| 2010 | | IrInstGenPtrToInt *inst = ir_build_inst_gen<IrInstGenPtrToInt>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2006 | static IrInstGen *ir_build_ptr_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target) { |
| 2007 | IrInstGenPtrToInt *inst = ir_build_inst_gen<IrInstGenPtrToInt>(&ira->new_irb, scope, source_node); |
| 2011 | 2008 | inst->base.value->type = ira->codegen->builtin_types.entry_usize; |
| 2012 | 2009 | inst->target = target; |
| 2013 | 2010 | |
| ... | ... | @@ -2052,9 +2049,9 @@ static IrInstGen *ir_build_err_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode |
| 2052 | 2049 | return &instruction->base; |
| 2053 | 2050 | } |
| 2054 | 2051 | |
| 2055 | | static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *msg) { |
| 2052 | static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *msg) { |
| 2056 | 2053 | IrInstGenPanic *instruction = ir_build_inst_noreturn<IrInstGenPanic>(&ira->new_irb, |
| 2057 | | source_instr->scope, source_instr->source_node); |
| 2054 | scope, source_node); |
| 2058 | 2055 | instruction->msg = msg; |
| 2059 | 2056 | |
| 2060 | 2057 | ir_ref_inst_gen(msg); |
| ... | ... | @@ -2062,11 +2059,11 @@ static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, IrInst *source_instr, IrIns |
| 2062 | 2059 | return &instruction->base; |
| 2063 | 2060 | } |
| 2064 | 2061 | |
| 2065 | | static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target, |
| 2062 | static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target, |
| 2066 | 2063 | ZigType *result_type) |
| 2067 | 2064 | { |
| 2068 | 2065 | IrInstGenTagName *instruction = ir_build_inst_gen<IrInstGenTagName>(&ira->new_irb, |
| 2069 | | source_instr->scope, source_instr->source_node); |
| 2066 | scope, source_node); |
| 2070 | 2067 | instruction->base.value->type = result_type; |
| 2071 | 2068 | instruction->target = target; |
| 2072 | 2069 | |
| ... | ... | @@ -2075,11 +2072,11 @@ static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, Ir |
| 2075 | 2072 | return &instruction->base; |
| 2076 | 2073 | } |
| 2077 | 2074 | |
| 2078 | | static IrInstGen *ir_build_field_parent_ptr_gen(IrAnalyze *ira, IrInst *source_instr, |
| 2075 | static IrInstGen *ir_build_field_parent_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2079 | 2076 | IrInstGen *field_ptr, TypeStructField *field, ZigType *result_type) |
| 2080 | 2077 | { |
| 2081 | 2078 | IrInstGenFieldParentPtr *inst = ir_build_inst_gen<IrInstGenFieldParentPtr>(&ira->new_irb, |
| 2082 | | source_instr->scope, source_instr->source_node); |
| 2079 | scope, source_node); |
| 2083 | 2080 | inst->base.value->type = result_type; |
| 2084 | 2081 | inst->field_ptr = field_ptr; |
| 2085 | 2082 | inst->field = field; |
| ... | ... | @@ -2111,10 +2108,10 @@ static IrInstGen *ir_build_error_return_trace_gen(IrAnalyze *ira, Scope *scope, |
| 2111 | 2108 | return &inst->base; |
| 2112 | 2109 | } |
| 2113 | 2110 | |
| 2114 | | static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr, |
| 2111 | static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2115 | 2112 | IrInstGen *ptr, IrInstGen *operand, AtomicRmwOp op, AtomicOrder ordering, ZigType *operand_type) |
| 2116 | 2113 | { |
| 2117 | | IrInstGenAtomicRmw *instruction = ir_build_inst_gen<IrInstGenAtomicRmw>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 2114 | IrInstGenAtomicRmw *instruction = ir_build_inst_gen<IrInstGenAtomicRmw>(&ira->new_irb, scope, source_node); |
| 2118 | 2115 | instruction->base.value->type = operand_type; |
| 2119 | 2116 | instruction->ptr = ptr; |
| 2120 | 2117 | instruction->op = op; |
| ... | ... | @@ -2127,11 +2124,11 @@ static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr, |
| 2127 | 2124 | return &instruction->base; |
| 2128 | 2125 | } |
| 2129 | 2126 | |
| 2130 | | static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, IrInst *source_instr, |
| 2127 | static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2131 | 2128 | IrInstGen *ptr, AtomicOrder ordering, ZigType *operand_type) |
| 2132 | 2129 | { |
| 2133 | 2130 | IrInstGenAtomicLoad *instruction = ir_build_inst_gen<IrInstGenAtomicLoad>(&ira->new_irb, |
| 2134 | | source_instr->scope, source_instr->source_node); |
| 2131 | scope, source_node); |
| 2135 | 2132 | instruction->base.value->type = operand_type; |
| 2136 | 2133 | instruction->ptr = ptr; |
| 2137 | 2134 | instruction->ordering = ordering; |
| ... | ... | @@ -2141,11 +2138,11 @@ static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, IrInst *source_instr, |
| 2141 | 2138 | return &instruction->base; |
| 2142 | 2139 | } |
| 2143 | 2140 | |
| 2144 | | static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr, |
| 2141 | static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2145 | 2142 | IrInstGen *ptr, IrInstGen *value, AtomicOrder ordering) |
| 2146 | 2143 | { |
| 2147 | 2144 | IrInstGenAtomicStore *instruction = ir_build_inst_void<IrInstGenAtomicStore>(&ira->new_irb, |
| 2148 | | source_instr->scope, source_instr->source_node); |
| 2145 | scope, source_node); |
| 2149 | 2146 | instruction->ptr = ptr; |
| 2150 | 2147 | instruction->value = value; |
| 2151 | 2148 | instruction->ordering = ordering; |
| ... | ... | @@ -2157,11 +2154,11 @@ static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr |
| 2157 | 2154 | } |
| 2158 | 2155 | |
| 2159 | 2156 | |
| 2160 | | static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, IrInst *source_instruction, |
| 2157 | static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2161 | 2158 | ZigType *result_type, IrInstGen *vector, IrInstGen *result_loc) |
| 2162 | 2159 | { |
| 2163 | 2160 | IrInstGenVectorToArray *instruction = ir_build_inst_gen<IrInstGenVectorToArray>(&ira->new_irb, |
| 2164 | | source_instruction->scope, source_instruction->source_node); |
| 2161 | scope, source_node); |
| 2165 | 2162 | instruction->base.value->type = result_type; |
| 2166 | 2163 | instruction->vector = vector; |
| 2167 | 2164 | instruction->result_loc = result_loc; |
| ... | ... | @@ -2172,11 +2169,11 @@ static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, IrInst *source_instru |
| 2172 | 2169 | return &instruction->base; |
| 2173 | 2170 | } |
| 2174 | 2171 | |
| 2175 | | static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInst *source_instruction, |
| 2172 | static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2176 | 2173 | ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc) |
| 2177 | 2174 | { |
| 2178 | 2175 | IrInstGenPtrOfArrayToSlice *instruction = ir_build_inst_gen<IrInstGenPtrOfArrayToSlice>(&ira->new_irb, |
| 2179 | | source_instruction->scope, source_instruction->source_node); |
| 2176 | scope, source_node); |
| 2180 | 2177 | instruction->base.value->type = result_type; |
| 2181 | 2178 | instruction->operand = operand; |
| 2182 | 2179 | instruction->result_loc = result_loc; |
| ... | ... | @@ -2187,11 +2184,11 @@ static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInst *source_ |
| 2187 | 2184 | return &instruction->base; |
| 2188 | 2185 | } |
| 2189 | 2186 | |
| 2190 | | static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, IrInst *source_instruction, |
| 2187 | static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2191 | 2188 | IrInstGen *array, ZigType *result_type) |
| 2192 | 2189 | { |
| 2193 | 2190 | IrInstGenArrayToVector *instruction = ir_build_inst_gen<IrInstGenArrayToVector>(&ira->new_irb, |
| 2194 | | source_instruction->scope, source_instruction->source_node); |
| 2191 | scope, source_node); |
| 2195 | 2192 | instruction->base.value->type = result_type; |
| 2196 | 2193 | instruction->array = array; |
| 2197 | 2194 | |
| ... | ... | @@ -2200,11 +2197,11 @@ static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, IrInst *source_instru |
| 2200 | 2197 | return &instruction->base; |
| 2201 | 2198 | } |
| 2202 | 2199 | |
| 2203 | | static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, IrInst *source_instruction, |
| 2200 | static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2204 | 2201 | IrInstGen *target) |
| 2205 | 2202 | { |
| 2206 | 2203 | IrInstGenAssertZero *instruction = ir_build_inst_gen<IrInstGenAssertZero>(&ira->new_irb, |
| 2207 | | source_instruction->scope, source_instruction->source_node); |
| 2204 | scope, source_node); |
| 2208 | 2205 | instruction->base.value->type = ira->codegen->builtin_types.entry_void; |
| 2209 | 2206 | instruction->target = target; |
| 2210 | 2207 | |
| ... | ... | @@ -2213,11 +2210,11 @@ static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, IrInst *source_instructio |
| 2213 | 2210 | return &instruction->base; |
| 2214 | 2211 | } |
| 2215 | 2212 | |
| 2216 | | static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, IrInst *source_instruction, |
| 2213 | static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2217 | 2214 | IrInstGen *target) |
| 2218 | 2215 | { |
| 2219 | 2216 | IrInstGenAssertNonNull *instruction = ir_build_inst_gen<IrInstGenAssertNonNull>(&ira->new_irb, |
| 2220 | | source_instruction->scope, source_instruction->source_node); |
| 2217 | scope, source_node); |
| 2221 | 2218 | instruction->base.value->type = ira->codegen->builtin_types.entry_void; |
| 2222 | 2219 | instruction->target = target; |
| 2223 | 2220 | |
| ... | ... | @@ -2226,20 +2223,20 @@ static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, IrInst *source_instru |
| 2226 | 2223 | return &instruction->base; |
| 2227 | 2224 | } |
| 2228 | 2225 | |
| 2229 | | static IrInstGenAlloca *ir_build_alloca_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 2226 | static IrInstGenAlloca *ir_build_alloca_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2230 | 2227 | uint32_t align, const char *name_hint) |
| 2231 | 2228 | { |
| 2232 | 2229 | IrInstGenAlloca *instruction = ir_create_inst_gen<IrInstGenAlloca>(&ira->new_irb, |
| 2233 | | source_instruction->scope, source_instruction->source_node); |
| 2230 | scope, source_node); |
| 2234 | 2231 | instruction->align = align; |
| 2235 | 2232 | instruction->name_hint = name_hint; |
| 2236 | 2233 | |
| 2237 | 2234 | return instruction; |
| 2238 | 2235 | } |
| 2239 | 2236 | |
| 2240 | | static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSuspendBegin *begin) { |
| 2237 | static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGenSuspendBegin *begin) { |
| 2241 | 2238 | IrInstGenSuspendFinish *inst = ir_build_inst_void<IrInstGenSuspendFinish>(&ira->new_irb, |
| 2242 | | source_instr->scope, source_instr->source_node); |
| 2239 | scope, source_node); |
| 2243 | 2240 | inst->begin = begin; |
| 2244 | 2241 | |
| 2245 | 2242 | ir_ref_inst_gen(&begin->base); |
| ... | ... | @@ -2247,11 +2244,11 @@ static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, IrInst *source_ins |
| 2247 | 2244 | return &inst->base; |
| 2248 | 2245 | } |
| 2249 | 2246 | |
| 2250 | | static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, IrInst *source_instruction, |
| 2247 | static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2251 | 2248 | IrInstGen *frame, ZigType *result_type, IrInstGen *result_loc, bool is_nosuspend) |
| 2252 | 2249 | { |
| 2253 | 2250 | IrInstGenAwait *instruction = ir_build_inst_gen<IrInstGenAwait>(&ira->new_irb, |
| 2254 | | source_instruction->scope, source_instruction->source_node); |
| 2251 | scope, source_node); |
| 2255 | 2252 | instruction->base.value->type = result_type; |
| 2256 | 2253 | instruction->frame = frame; |
| 2257 | 2254 | instruction->result_loc = result_loc; |
| ... | ... | @@ -2263,9 +2260,9 @@ static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, IrInst *source_instruc |
| 2263 | 2260 | return instruction; |
| 2264 | 2261 | } |
| 2265 | 2262 | |
| 2266 | | static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *frame) { |
| 2263 | static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *frame) { |
| 2267 | 2264 | IrInstGenResume *instruction = ir_build_inst_void<IrInstGenResume>(&ira->new_irb, |
| 2268 | | source_instr->scope, source_instr->source_node); |
| 2265 | scope, source_node); |
| 2269 | 2266 | instruction->frame = frame; |
| 2270 | 2267 | |
| 2271 | 2268 | ir_ref_inst_gen(frame); |
| ... | ... | @@ -2273,11 +2270,11 @@ static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, IrInst *source_instr, IrIn |
| 2273 | 2270 | return &instruction->base; |
| 2274 | 2271 | } |
| 2275 | 2272 | |
| 2276 | | static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, |
| 2273 | static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *operand, |
| 2277 | 2274 | SpillId spill_id) |
| 2278 | 2275 | { |
| 2279 | 2276 | IrInstGenSpillBegin *instruction = ir_build_inst_void<IrInstGenSpillBegin>(&ira->new_irb, |
| 2280 | | source_instr->scope, source_instr->source_node); |
| 2277 | scope, source_node); |
| 2281 | 2278 | instruction->operand = operand; |
| 2282 | 2279 | instruction->spill_id = spill_id; |
| 2283 | 2280 | |
| ... | ... | @@ -2286,11 +2283,11 @@ static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, IrInst *source_instr, |
| 2286 | 2283 | return &instruction->base; |
| 2287 | 2284 | } |
| 2288 | 2285 | |
| 2289 | | static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSpillBegin *begin, |
| 2286 | static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGenSpillBegin *begin, |
| 2290 | 2287 | ZigType *result_type) |
| 2291 | 2288 | { |
| 2292 | 2289 | IrInstGenSpillEnd *instruction = ir_build_inst_gen<IrInstGenSpillEnd>(&ira->new_irb, |
| 2293 | | source_instr->scope, source_instr->source_node); |
| 2290 | scope, source_node); |
| 2294 | 2291 | instruction->base.value->type = result_type; |
| 2295 | 2292 | instruction->begin = begin; |
| 2296 | 2293 | |
| ... | ... | @@ -2299,11 +2296,11 @@ static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, IrInst *source_instr, I |
| 2299 | 2296 | return &instruction->base; |
| 2300 | 2297 | } |
| 2301 | 2298 | |
| 2302 | | static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, IrInst *source_instruction, |
| 2299 | static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 2303 | 2300 | IrInstGen *vector, IrInstGen *index) |
| 2304 | 2301 | { |
| 2305 | 2302 | IrInstGenVectorExtractElem *instruction = ir_build_inst_gen<IrInstGenVectorExtractElem>( |
| 2306 | | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2303 | &ira->new_irb, scope, source_node); |
| 2307 | 2304 | instruction->base.value->type = vector->value->type->data.vector.elem_type; |
| 2308 | 2305 | instruction->vector = vector; |
| 2309 | 2306 | instruction->index = index; |
| ... | ... | @@ -2314,9 +2311,9 @@ static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, IrInst *source_in |
| 2314 | 2311 | return &instruction->base; |
| 2315 | 2312 | } |
| 2316 | 2313 | |
| 2317 | | static IrInstGen *ir_build_wasm_memory_size_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *index) { |
| 2314 | static IrInstGen *ir_build_wasm_memory_size_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *index) { |
| 2318 | 2315 | IrInstGenWasmMemorySize *instruction = ir_build_inst_gen<IrInstGenWasmMemorySize>(&ira->new_irb, |
| 2319 | | source_instr->scope, source_instr->source_node); |
| 2316 | scope, source_node); |
| 2320 | 2317 | instruction->base.value->type = ira->codegen->builtin_types.entry_u32; |
| 2321 | 2318 | instruction->index = index; |
| 2322 | 2319 | |
| ... | ... | @@ -2325,9 +2322,9 @@ static IrInstGen *ir_build_wasm_memory_size_gen(IrAnalyze *ira, IrInst *source_i |
| 2325 | 2322 | return &instruction->base; |
| 2326 | 2323 | } |
| 2327 | 2324 | |
| 2328 | | static IrInstGen *ir_build_wasm_memory_grow_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *index, IrInstGen *delta) { |
| 2325 | static IrInstGen *ir_build_wasm_memory_grow_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *index, IrInstGen *delta) { |
| 2329 | 2326 | IrInstGenWasmMemoryGrow *instruction = ir_build_inst_gen<IrInstGenWasmMemoryGrow>(&ira->new_irb, |
| 2330 | | source_instr->scope, source_instr->source_node); |
| 2327 | scope, source_node); |
| 2331 | 2328 | instruction->base.value->type = ira->codegen->builtin_types.entry_i32; |
| 2332 | 2329 | instruction->index = index; |
| 2333 | 2330 | instruction->delta = delta; |
| ... | ... | @@ -2551,15 +2548,10 @@ static ErrorMsg *opt_ir_add_error_node(IrAnalyze *ira, CodeGen *codegen, AstNode |
| 2551 | 2548 | return add_node_error(codegen, source_node, msg); |
| 2552 | 2549 | } |
| 2553 | 2550 | |
| 2554 | | static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInst *source_instruction, Buf *msg) { |
| 2551 | static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstGen *source_instruction, Buf *msg) { |
| 2555 | 2552 | return ir_add_error_node(ira, source_instruction->source_node, msg); |
| 2556 | 2553 | } |
| 2557 | 2554 | |
| 2558 | | static void ir_assert_gen_impl(bool ok, IrInstGen *source_instruction, char const *file, unsigned int line) { |
| 2559 | | if (ok) return; |
| 2560 | | src_assert_impl(ok, source_instruction->base.source_node, file, line); |
| 2561 | | } |
| 2562 | | |
| 2563 | 2555 | // This function takes a comptime ptr and makes the child const value conform to the type |
| 2564 | 2556 | // described by the pointer. |
| 2565 | 2557 | static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, |
| ... | ... | @@ -2622,11 +2614,11 @@ static Error ir_exec_scan_for_side_effects(CodeGen *codegen, Stage1Air *exec) { |
| 2622 | 2614 | break; |
| 2623 | 2615 | } |
| 2624 | 2616 | } |
| 2625 | | if (get_scope_typeof(instruction->base.scope) != nullptr) { |
| 2617 | if (get_scope_typeof(instruction->scope) != nullptr) { |
| 2626 | 2618 | // doesn't count, it's inside a @TypeOf() |
| 2627 | 2619 | continue; |
| 2628 | 2620 | } |
| 2629 | | exec_add_error_node_gen(codegen, exec, instruction->base.source_node, |
| 2621 | exec_add_error_node_gen(codegen, exec, instruction->source_node, |
| 2630 | 2622 | buf_sprintf("unable to evaluate constant expression")); |
| 2631 | 2623 | return ErrorSemanticAnalyzeFail; |
| 2632 | 2624 | } |
| ... | ... | @@ -2634,9 +2626,9 @@ static Error ir_exec_scan_for_side_effects(CodeGen *codegen, Stage1Air *exec) { |
| 2634 | 2626 | zig_unreachable(); |
| 2635 | 2627 | } |
| 2636 | 2628 | |
| 2637 | | static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInst* source_instruction) { |
| 2629 | static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstSrc* source_instruction) { |
| 2638 | 2630 | if (ir_should_inline(ira->zir, source_instruction->scope)) { |
| 2639 | | ir_add_error(ira, source_instruction, buf_sprintf("unable to evaluate constant expression")); |
| 2631 | ir_add_error_node(ira, source_instruction->source_node, buf_sprintf("unable to evaluate constant expression")); |
| 2640 | 2632 | return false; |
| 2641 | 2633 | } |
| 2642 | 2634 | return true; |
| ... | ... | @@ -3518,7 +3510,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction |
| 3518 | 3510 | } |
| 3519 | 3511 | Buf *val_buf = buf_alloc(); |
| 3520 | 3512 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); |
| 3521 | | ir_add_error_node(ira, instruction->base.source_node, |
| 3513 | ir_add_error_node(ira, instruction->source_node, |
| 3522 | 3514 | buf_sprintf("type %s cannot represent integer value %s", |
| 3523 | 3515 | buf_ptr(&other_type->name), |
| 3524 | 3516 | buf_ptr(val_buf))); |
| ... | ... | @@ -3613,7 +3605,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction |
| 3613 | 3605 | } |
| 3614 | 3606 | Buf *val_buf = buf_alloc(); |
| 3615 | 3607 | float_append_buf(val_buf, const_val); |
| 3616 | | ir_add_error_node(ira, instruction->base.source_node, |
| 3608 | ir_add_error_node(ira, instruction->source_node, |
| 3617 | 3609 | buf_sprintf("cast of value %s to type '%s' loses information", |
| 3618 | 3610 | buf_ptr(val_buf), |
| 3619 | 3611 | buf_ptr(&other_type->name))); |
| ... | ... | @@ -3622,7 +3614,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction |
| 3622 | 3614 | if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { |
| 3623 | 3615 | Buf *val_buf = buf_alloc(); |
| 3624 | 3616 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); |
| 3625 | | ir_add_error_node(ira, instruction->base.source_node, |
| 3617 | ir_add_error_node(ira, instruction->source_node, |
| 3626 | 3618 | buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'", |
| 3627 | 3619 | buf_ptr(val_buf), |
| 3628 | 3620 | buf_ptr(&other_type->name))); |
| ... | ... | @@ -3643,7 +3635,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction |
| 3643 | 3635 | if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { |
| 3644 | 3636 | Buf *val_buf = buf_alloc(); |
| 3645 | 3637 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); |
| 3646 | | ir_add_error_node(ira, instruction->base.source_node, |
| 3638 | ir_add_error_node(ira, instruction->source_node, |
| 3647 | 3639 | buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'", |
| 3648 | 3640 | buf_ptr(val_buf), |
| 3649 | 3641 | buf_ptr(&child_type->name))); |
| ... | ... | @@ -3666,7 +3658,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction |
| 3666 | 3658 | Buf *val_buf = buf_alloc(); |
| 3667 | 3659 | float_append_buf(val_buf, const_val); |
| 3668 | 3660 | |
| 3669 | | ir_add_error_node(ira, instruction->base.source_node, |
| 3661 | ir_add_error_node(ira, instruction->source_node, |
| 3670 | 3662 | buf_sprintf("fractional component prevents float value %s from being casted to type '%s'", |
| 3671 | 3663 | buf_ptr(val_buf), |
| 3672 | 3664 | buf_ptr(&other_type->name))); |
| ... | ... | @@ -3696,7 +3688,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction |
| 3696 | 3688 | bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); |
| 3697 | 3689 | } |
| 3698 | 3690 | |
| 3699 | | ir_add_error_node(ira, instruction->base.source_node, |
| 3691 | ir_add_error_node(ira, instruction->source_node, |
| 3700 | 3692 | buf_sprintf("%s value %s cannot be coerced to type '%s'", |
| 3701 | 3693 | num_lit_str, |
| 3702 | 3694 | buf_ptr(val_buf), |
| ... | ... | @@ -4210,7 +4202,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4210 | 4202 | size_t errors_count = 0; |
| 4211 | 4203 | ZigType *err_set_type = nullptr; |
| 4212 | 4204 | if (prev_inst->value->type->id == ZigTypeIdErrorSet) { |
| 4213 | | if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->base.source_node)) { |
| 4205 | if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->source_node)) { |
| 4214 | 4206 | return ira->codegen->builtin_types.entry_invalid; |
| 4215 | 4207 | } |
| 4216 | 4208 | if (type_is_global_error_set(prev_inst->value->type)) { |
| ... | ... | @@ -4254,14 +4246,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4254 | 4246 | } |
| 4255 | 4247 | |
| 4256 | 4248 | if (prev_type->id == ZigTypeIdErrorSet) { |
| 4257 | | ir_assert_gen(err_set_type != nullptr, prev_inst); |
| 4249 | ir_assert(err_set_type != nullptr, prev_inst); |
| 4258 | 4250 | if (cur_type->id == ZigTypeIdErrorSet) { |
| 4259 | 4251 | if (type_is_global_error_set(err_set_type)) { |
| 4260 | 4252 | continue; |
| 4261 | 4253 | } |
| 4262 | 4254 | bool allow_infer = cur_type->data.error_set.infer_fn != nullptr && |
| 4263 | 4255 | cur_type->data.error_set.infer_fn == ira->fn; |
| 4264 | | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) { |
| 4256 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) { |
| 4265 | 4257 | return ira->codegen->builtin_types.entry_invalid; |
| 4266 | 4258 | } |
| 4267 | 4259 | if (!allow_infer && type_is_global_error_set(cur_type)) { |
| ... | ... | @@ -4329,7 +4321,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4329 | 4321 | ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 4330 | 4322 | bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr && |
| 4331 | 4323 | cur_err_set_type->data.error_set.infer_fn == ira->fn; |
| 4332 | | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) { |
| 4324 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { |
| 4333 | 4325 | return ira->codegen->builtin_types.entry_invalid; |
| 4334 | 4326 | } |
| 4335 | 4327 | if (!allow_infer && type_is_global_error_set(cur_err_set_type)) { |
| ... | ... | @@ -4384,7 +4376,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4384 | 4376 | if (cur_type->id == ZigTypeIdErrorSet) { |
| 4385 | 4377 | bool allow_infer = cur_type->data.error_set.infer_fn != nullptr && |
| 4386 | 4378 | cur_type->data.error_set.infer_fn == ira->fn; |
| 4387 | | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) { |
| 4379 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) { |
| 4388 | 4380 | return ira->codegen->builtin_types.entry_invalid; |
| 4389 | 4381 | } |
| 4390 | 4382 | if (!allow_infer && type_is_global_error_set(cur_type)) { |
| ... | ... | @@ -4407,7 +4399,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4407 | 4399 | err_set_type = cur_type; |
| 4408 | 4400 | } |
| 4409 | 4401 | |
| 4410 | | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->base.source_node)) { |
| 4402 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->source_node)) { |
| 4411 | 4403 | return ira->codegen->builtin_types.entry_invalid; |
| 4412 | 4404 | } |
| 4413 | 4405 | |
| ... | ... | @@ -4470,11 +4462,11 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4470 | 4462 | bool allow_infer_cur = cur_err_set_type->data.error_set.infer_fn != nullptr && |
| 4471 | 4463 | cur_err_set_type->data.error_set.infer_fn == ira->fn; |
| 4472 | 4464 | |
| 4473 | | if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->base.source_node)) { |
| 4465 | if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) { |
| 4474 | 4466 | return ira->codegen->builtin_types.entry_invalid; |
| 4475 | 4467 | } |
| 4476 | 4468 | |
| 4477 | | if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) { |
| 4469 | if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { |
| 4478 | 4470 | return ira->codegen->builtin_types.entry_invalid; |
| 4479 | 4471 | } |
| 4480 | 4472 | |
| ... | ... | @@ -4653,7 +4645,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4653 | 4645 | ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; |
| 4654 | 4646 | bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr && |
| 4655 | 4647 | cur_err_set_type->data.error_set.infer_fn == ira->fn; |
| 4656 | | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) { |
| 4648 | if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { |
| 4657 | 4649 | return ira->codegen->builtin_types.entry_invalid; |
| 4658 | 4650 | } |
| 4659 | 4651 | if ((!allow_infer && type_is_global_error_set(cur_err_set_type)) || |
| ... | ... | @@ -4890,9 +4882,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4890 | 4882 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 4891 | 4883 | buf_sprintf("incompatible types: '%s' and '%s'", |
| 4892 | 4884 | buf_ptr(&prev_type->name), buf_ptr(&cur_type->name))); |
| 4893 | | add_error_note(ira->codegen, msg, prev_inst->base.source_node, |
| 4885 | add_error_note(ira->codegen, msg, prev_inst->source_node, |
| 4894 | 4886 | buf_sprintf("type '%s' here", buf_ptr(&prev_type->name))); |
| 4895 | | add_error_note(ira->codegen, msg, cur_inst->base.source_node, |
| 4887 | add_error_note(ira->codegen, msg, cur_inst->source_node, |
| 4896 | 4888 | buf_sprintf("type '%s' here", buf_ptr(&cur_type->name))); |
| 4897 | 4889 | |
| 4898 | 4890 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -4984,7 +4976,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 4984 | 4976 | } |
| 4985 | 4977 | } |
| 4986 | 4978 | |
| 4987 | | static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr, |
| 4979 | static bool eval_const_expr_implicit_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 4988 | 4980 | CastOp cast_op, |
| 4989 | 4981 | ZigValue *other_val, ZigType *other_type, |
| 4990 | 4982 | ZigValue *const_val, ZigType *new_type) |
| ... | ... | @@ -5069,7 +5061,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr, |
| 5069 | 5061 | Buf *int_buf = buf_alloc(); |
| 5070 | 5062 | bigint_append_buf(int_buf, &const_val->data.x_bigint, 10); |
| 5071 | 5063 | |
| 5072 | | ir_add_error(ira, source_instr, |
| 5064 | ir_add_error_node(ira, source_node, |
| 5073 | 5065 | buf_sprintf("integer value '%s' cannot be stored in type '%s'", |
| 5074 | 5066 | buf_ptr(int_buf), buf_ptr(&new_type->name))); |
| 5075 | 5067 | return false; |
| ... | ... | @@ -5086,9 +5078,9 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr, |
| 5086 | 5078 | return true; |
| 5087 | 5079 | } |
| 5088 | 5080 | |
| 5089 | | static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) { |
| 5081 | static IrInstGen *ir_const(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) { |
| 5090 | 5082 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 5091 | | inst->scope, inst->source_node); |
| 5083 | scope, source_node); |
| 5092 | 5084 | IrInstGen *new_instruction = &const_instruction->base; |
| 5093 | 5085 | new_instruction->value->type = ty; |
| 5094 | 5086 | new_instruction->value->special = ConstValSpecialStatic; |
| ... | ... | @@ -5096,45 +5088,46 @@ static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) { |
| 5096 | 5088 | return new_instruction; |
| 5097 | 5089 | } |
| 5098 | 5090 | |
| 5099 | | static IrInstGen *ir_const_noval(IrAnalyze *ira, IrInst *old_instruction) { |
| 5091 | static IrInstGen *ir_const_noval(IrAnalyze *ira, Scope *scope, AstNode *source_node) { |
| 5100 | 5092 | IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb, |
| 5101 | | old_instruction->scope, old_instruction->source_node); |
| 5093 | scope, source_node); |
| 5102 | 5094 | ira->new_irb.constants.append(&heap::c_allocator, const_instruction); |
| 5103 | 5095 | return &const_instruction->base; |
| 5104 | 5096 | } |
| 5105 | 5097 | |
| 5106 | 5098 | // This function initializes the new IrInstGen with the provided ZigValue, |
| 5107 | 5099 | // rather than creating a new one. |
| 5108 | | static IrInstGen *ir_const_move(IrAnalyze *ira, IrInst *old_instruction, ZigValue *val) { |
| 5109 | | IrInstGen *result = ir_const_noval(ira, old_instruction); |
| 5100 | static IrInstGen *ir_const_move(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigValue *val) { |
| 5101 | IrInstGen *result = ir_const_noval(ira, scope, source_node); |
| 5110 | 5102 | result->value = val; |
| 5111 | 5103 | return result; |
| 5112 | 5104 | } |
| 5113 | 5105 | |
| 5114 | | static IrInstGen *ir_resolve_cast(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, |
| 5106 | static IrInstGen *ir_resolve_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value, |
| 5115 | 5107 | ZigType *wanted_type, CastOp cast_op) |
| 5116 | 5108 | { |
| 5117 | 5109 | if (instr_is_comptime(value) || !type_has_bits(ira->codegen, wanted_type)) { |
| 5118 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 5110 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 5119 | 5111 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 5120 | 5112 | if (val == nullptr) |
| 5121 | 5113 | return ira->codegen->invalid_inst_gen; |
| 5122 | 5114 | |
| 5123 | | if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, val, val->type, |
| 5115 | if (!eval_const_expr_implicit_cast(ira, scope, source_node, cast_op, val, val->type, |
| 5124 | 5116 | result->value, wanted_type)) |
| 5125 | 5117 | { |
| 5126 | 5118 | return ira->codegen->invalid_inst_gen; |
| 5127 | 5119 | } |
| 5128 | 5120 | return result; |
| 5129 | 5121 | } else { |
| 5130 | | return ir_build_cast(ira, source_instr, wanted_type, value, cast_op); |
| 5122 | return ir_build_cast(ira, scope, source_node, |
| 5123 | wanted_type, value, cast_op); |
| 5131 | 5124 | } |
| 5132 | 5125 | } |
| 5133 | 5126 | |
| 5134 | | static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 5135 | | IrInstGen *value, ZigType *wanted_type) |
| 5127 | static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, |
| 5128 | Scope *scope, AstNode *source_node, IrInstGen *value, ZigType *wanted_type) |
| 5136 | 5129 | { |
| 5137 | | ir_assert(value->value->type->id == ZigTypeIdPointer, source_instr); |
| 5130 | src_assert(value->value->type->id == ZigTypeIdPointer, source_node); |
| 5138 | 5131 | |
| 5139 | 5132 | Error err; |
| 5140 | 5133 | |
| ... | ... | @@ -5151,13 +5144,13 @@ static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrI |
| 5151 | 5144 | if (val == nullptr) |
| 5152 | 5145 | return ira->codegen->invalid_inst_gen; |
| 5153 | 5146 | if (val->special == ConstValSpecialUndef) |
| 5154 | | return ir_const_undef(ira, source_instr, wanted_type); |
| 5147 | return ir_const_undef(ira, scope, source_node, wanted_type); |
| 5155 | 5148 | |
| 5156 | | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); |
| 5149 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_node); |
| 5157 | 5150 | if (pointee == nullptr) |
| 5158 | 5151 | return ira->codegen->invalid_inst_gen; |
| 5159 | 5152 | if (pointee->special != ConstValSpecialRuntime) { |
| 5160 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 5153 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 5161 | 5154 | result->value->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 5162 | 5155 | result->value->data.x_ptr.mut = val->data.x_ptr.mut; |
| 5163 | 5156 | result->value->data.x_ptr.data.base_array.array_val = pointee; |
| ... | ... | @@ -5166,10 +5159,11 @@ static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrI |
| 5166 | 5159 | } |
| 5167 | 5160 | } |
| 5168 | 5161 | |
| 5169 | | return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast); |
| 5162 | return ir_build_cast(ira, scope, source_node, |
| 5163 | wanted_type, value, CastOpBitCast); |
| 5170 | 5164 | } |
| 5171 | 5165 | |
| 5172 | | static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* source_instr, |
| 5166 | static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 5173 | 5167 | IrInstGen *array_ptr, ZigType *wanted_type, ResultLoc *result_loc) |
| 5174 | 5168 | { |
| 5175 | 5169 | Error err; |
| ... | ... | @@ -5189,7 +5183,7 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc |
| 5189 | 5183 | // undef_array->special = ConstValSpecialUndef; |
| 5190 | 5184 | // undef_array->type = array_type; |
| 5191 | 5185 | |
| 5192 | | // IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 5186 | // IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 5193 | 5187 | // init_const_slice(ira->codegen, result->value, undef_array, 0, 0, false, nullptr); |
| 5194 | 5188 | // result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 5195 | 5189 | // result->value->type = wanted_type; |
| ... | ... | @@ -5210,13 +5204,13 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc |
| 5210 | 5204 | ZigValue *array_ptr_val = ir_resolve_const(ira, array_ptr, undef_allowed); |
| 5211 | 5205 | if (array_ptr_val == nullptr) |
| 5212 | 5206 | return ira->codegen->invalid_inst_gen; |
| 5213 | | ir_assert(is_slice(wanted_type), source_instr); |
| 5207 | src_assert(is_slice(wanted_type), source_node); |
| 5214 | 5208 | if (array_ptr_val->special == ConstValSpecialUndef) { |
| 5215 | 5209 | ZigValue *undef_array = ira->codegen->pass1_arena->create<ZigValue>(); |
| 5216 | 5210 | undef_array->special = ConstValSpecialUndef; |
| 5217 | 5211 | undef_array->type = array_type; |
| 5218 | 5212 | |
| 5219 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 5213 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 5220 | 5214 | init_const_slice(ira->codegen, result->value, undef_array, 0, 0, false, nullptr); |
| 5221 | 5215 | result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 5222 | 5216 | result->value->type = wanted_type; |
| ... | ... | @@ -5227,7 +5221,7 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc |
| 5227 | 5221 | if (array_ptr_val->data.x_ptr.special == ConstPtrSpecialSubArray) { |
| 5228 | 5222 | ZigValue *array_val = array_ptr_val->data.x_ptr.data.base_array.array_val; |
| 5229 | 5223 | if (array_val->special != ConstValSpecialRuntime) { |
| 5230 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 5224 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 5231 | 5225 | init_const_slice(ira->codegen, result->value, array_val, |
| 5232 | 5226 | array_ptr_val->data.x_ptr.data.base_array.elem_index, |
| 5233 | 5227 | array_type->data.array.len, wanted_const, nullptr); |
| ... | ... | @@ -5236,13 +5230,13 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc |
| 5236 | 5230 | return result; |
| 5237 | 5231 | } |
| 5238 | 5232 | } else if (array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 5239 | | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr_val, source_instr->source_node); |
| 5233 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr_val, source_node); |
| 5240 | 5234 | if (pointee == nullptr) |
| 5241 | 5235 | return ira->codegen->invalid_inst_gen; |
| 5242 | 5236 | if (pointee->special != ConstValSpecialRuntime) { |
| 5243 | 5237 | assert(array_ptr_val->type->id == ZigTypeIdPointer); |
| 5244 | 5238 | |
| 5245 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 5239 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 5246 | 5240 | init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, wanted_const, nullptr); |
| 5247 | 5241 | result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; |
| 5248 | 5242 | result->value->type = wanted_type; |
| ... | ... | @@ -5252,16 +5246,17 @@ static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* sourc |
| 5252 | 5246 | } |
| 5253 | 5247 | |
| 5254 | 5248 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 5255 | | IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 5249 | IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, |
| 5250 | result_loc, wanted_type, nullptr, true, true); |
| 5256 | 5251 | if (type_is_invalid(result_loc_inst->value->type) || |
| 5257 | 5252 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) |
| 5258 | 5253 | { |
| 5259 | 5254 | return result_loc_inst; |
| 5260 | 5255 | } |
| 5261 | | return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst); |
| 5256 | return ir_build_ptr_of_array_to_slice(ira, scope, source_node, wanted_type, array_ptr, result_loc_inst); |
| 5262 | 5257 | } |
| 5263 | 5258 | |
| 5264 | | static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, IrInst *ref_old_instruction) { |
| 5259 | static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, IrInstSrc *ref_old_instruction) { |
| 5265 | 5260 | assert(old_bb); |
| 5266 | 5261 | |
| 5267 | 5262 | if (old_bb->child) { |
| ... | ... | @@ -5276,13 +5271,13 @@ static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, Stage1ZirBasicBlock *old_b |
| 5276 | 5271 | return new_bb; |
| 5277 | 5272 | } |
| 5278 | 5273 | |
| 5279 | | static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, IrInst *ref_old_instruction) { |
| 5274 | static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, IrInstSrc *ref_old_instruction) { |
| 5280 | 5275 | assert(ref_old_instruction != nullptr); |
| 5281 | 5276 | IrBasicBlockGen *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction); |
| 5282 | | if (new_bb->must_be_comptime_source_instr) { |
| 5283 | | ErrorMsg *msg = ir_add_error(ira, ref_old_instruction, |
| 5277 | if (new_bb->must_be_comptime_source_node != nullptr) { |
| 5278 | ErrorMsg *msg = ir_add_error_node(ira, ref_old_instruction->source_node, |
| 5284 | 5279 | buf_sprintf("control flow attempts to use compile-time variable at runtime")); |
| 5285 | | add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_instr->source_node, |
| 5280 | add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_node, |
| 5286 | 5281 | buf_sprintf("compile-time variable assigned here")); |
| 5287 | 5282 | return nullptr; |
| 5288 | 5283 | } |
| ... | ... | @@ -5290,14 +5285,16 @@ static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, Stage1ZirBasicBloc |
| 5290 | 5285 | } |
| 5291 | 5286 | |
| 5292 | 5287 | static void ir_start_bb(IrAnalyze *ira, Stage1ZirBasicBlock *old_bb, Stage1ZirBasicBlock *const_predecessor_bb) { |
| 5293 | | ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? &old_bb->instruction_list.at(0)->base : nullptr); |
| 5288 | src_assert(!old_bb->suspended, |
| 5289 | (old_bb->instruction_list.length != 0) ? |
| 5290 | old_bb->instruction_list.at(0)->source_node : nullptr); |
| 5294 | 5291 | ira->instruction_index = 0; |
| 5295 | 5292 | ira->zir_current_basic_block = old_bb; |
| 5296 | 5293 | ira->const_predecessor_bb = const_predecessor_bb; |
| 5297 | 5294 | ira->old_bb_index = old_bb->index; |
| 5298 | 5295 | } |
| 5299 | 5296 | |
| 5300 | | static IrInstGen *ira_suspend(IrAnalyze *ira, IrInst *old_instruction, Stage1ZirBasicBlock *next_bb, |
| 5297 | static IrInstGen *ira_suspend(IrAnalyze *ira, IrInstSrc *old_instruction, Stage1ZirBasicBlock *next_bb, |
| 5301 | 5298 | IrSuspendPosition *suspend_pos) |
| 5302 | 5299 | { |
| 5303 | 5300 | if (ira->codegen->verbose_ir) { |
| ... | ... | @@ -5306,7 +5303,7 @@ static IrInstGen *ira_suspend(IrAnalyze *ira, IrInst *old_instruction, Stage1Zir |
| 5306 | 5303 | ira->zir_current_basic_block->debug_id, |
| 5307 | 5304 | ira->zir->basic_block_list.at(ira->old_bb_index)->name_hint, |
| 5308 | 5305 | ira->zir->basic_block_list.at(ira->old_bb_index)->debug_id, |
| 5309 | | ira->zir_current_basic_block->instruction_list.at(ira->instruction_index)->base.debug_id, |
| 5306 | ira->zir_current_basic_block->instruction_list.at(ira->instruction_index)->debug_id, |
| 5310 | 5307 | ira->old_bb_index, ira->instruction_index); |
| 5311 | 5308 | } |
| 5312 | 5309 | suspend_pos->basic_block_index = ira->old_bb_index; |
| ... | ... | @@ -5342,7 +5339,7 @@ static IrInstGen *ira_resume(IrAnalyze *ira) { |
| 5342 | 5339 | if (ira->codegen->verbose_ir) { |
| 5343 | 5340 | fprintf(stderr, "%s_%" PRIu32 " #%" PRIu32 "\n", ira->zir_current_basic_block->name_hint, |
| 5344 | 5341 | ira->zir_current_basic_block->debug_id, |
| 5345 | | ira->zir_current_basic_block->instruction_list.at(pos.instruction_index)->base.debug_id); |
| 5342 | ira->zir_current_basic_block->instruction_list.at(pos.instruction_index)->debug_id); |
| 5346 | 5343 | } |
| 5347 | 5344 | ira->const_predecessor_bb = nullptr; |
| 5348 | 5345 | ira->new_irb.current_basic_block = ira->zir_current_basic_block->child; |
| ... | ... | @@ -5418,7 +5415,7 @@ static IrInstGen *ir_unreach_error(IrAnalyze *ira) { |
| 5418 | 5415 | return ira->codegen->unreach_instruction; |
| 5419 | 5416 | } |
| 5420 | 5417 | |
| 5421 | | static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction) { |
| 5418 | static bool ir_emit_backward_branch(IrAnalyze *ira, AstNode* source_node) { |
| 5422 | 5419 | size_t *bbc = ira->backward_branch_count; |
| 5423 | 5420 | size_t *quota = ira->backward_branch_quota; |
| 5424 | 5421 | |
| ... | ... | @@ -5430,16 +5427,16 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction) |
| 5430 | 5427 | |
| 5431 | 5428 | *bbc += 1; |
| 5432 | 5429 | if (*bbc > *quota) { |
| 5433 | | ir_add_error(ira, source_instruction, |
| 5430 | ir_add_error_node(ira, source_node, |
| 5434 | 5431 | buf_sprintf("evaluation exceeded %" ZIG_PRI_usize " backwards branches", *quota)); |
| 5435 | 5432 | return false; |
| 5436 | 5433 | } |
| 5437 | 5434 | return true; |
| 5438 | 5435 | } |
| 5439 | 5436 | |
| 5440 | | static IrInstGen *ir_inline_bb(IrAnalyze *ira, IrInst* source_instruction, Stage1ZirBasicBlock *old_bb) { |
| 5437 | static IrInstGen *ir_inline_bb(IrAnalyze *ira, AstNode* source_node, Stage1ZirBasicBlock *old_bb) { |
| 5441 | 5438 | if (old_bb->debug_id <= ira->zir_current_basic_block->debug_id) { |
| 5442 | | if (!ir_emit_backward_branch(ira, source_instruction)) |
| 5439 | if (!ir_emit_backward_branch(ira, source_node)) |
| 5443 | 5440 | return ir_unreach_error(ira); |
| 5444 | 5441 | } |
| 5445 | 5442 | |
| ... | ... | @@ -5454,8 +5451,8 @@ static IrInstGen *ir_finish_anal(IrAnalyze *ira, IrInstGen *instruction) { |
| 5454 | 5451 | return instruction; |
| 5455 | 5452 | } |
| 5456 | 5453 | |
| 5457 | | static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_entry) { |
| 5458 | | IrInstGen *result = ir_const(ira, source_instr, fn_entry->type_entry); |
| 5454 | static IrInstGen *ir_const_fn(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigFn *fn_entry) { |
| 5455 | IrInstGen *result = ir_const(ira, scope, source_node, fn_entry->type_entry); |
| 5459 | 5456 | result->value->special = ConstValSpecialStatic; |
| 5460 | 5457 | result->value->data.x_ptr.data.fn.fn_entry = fn_entry; |
| 5461 | 5458 | result->value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| ... | ... | @@ -5463,62 +5460,62 @@ static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_en |
| 5463 | 5460 | return result; |
| 5464 | 5461 | } |
| 5465 | 5462 | |
| 5466 | | static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, IrInst *src_inst, ZigFn *fn_entry, IrInstGen *first_arg, |
| 5467 | | IrInst *first_arg_src) |
| 5463 | static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 5464 | ZigFn *fn_entry, IrInstGen *first_arg, AstNode *first_arg_src) |
| 5468 | 5465 | { |
| 5469 | 5466 | // This is unfortunately required to avoid improperly freeing first_arg_src |
| 5470 | 5467 | ira_ref(ira); |
| 5471 | 5468 | |
| 5472 | | IrInstGen *result = ir_const(ira, src_inst, get_bound_fn_type(ira->codegen, fn_entry)); |
| 5469 | IrInstGen *result = ir_const(ira, scope, source_node, get_bound_fn_type(ira->codegen, fn_entry)); |
| 5473 | 5470 | result->value->data.x_bound_fn.fn = fn_entry; |
| 5474 | 5471 | result->value->data.x_bound_fn.first_arg = first_arg; |
| 5475 | 5472 | result->value->data.x_bound_fn.first_arg_src = first_arg_src; |
| 5476 | 5473 | return result; |
| 5477 | 5474 | } |
| 5478 | 5475 | |
| 5479 | | static IrInstGen *ir_const_type(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) { |
| 5480 | | IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type); |
| 5476 | static IrInstGen *ir_const_type(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) { |
| 5477 | IrInstGen *result = ir_const(ira, scope, source_node, ira->codegen->builtin_types.entry_type); |
| 5481 | 5478 | result->value->data.x_type = ty; |
| 5482 | 5479 | return result; |
| 5483 | 5480 | } |
| 5484 | 5481 | |
| 5485 | | static IrInstGen *ir_const_bool(IrAnalyze *ira, IrInst *source_instruction, bool value) { |
| 5486 | | IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool); |
| 5482 | static IrInstGen *ir_const_bool(IrAnalyze *ira, Scope *scope, AstNode *source_node, bool value) { |
| 5483 | IrInstGen *result = ir_const(ira, scope, source_node, ira->codegen->builtin_types.entry_bool); |
| 5487 | 5484 | result->value->data.x_bool = value; |
| 5488 | 5485 | return result; |
| 5489 | 5486 | } |
| 5490 | 5487 | |
| 5491 | | static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) { |
| 5492 | | IrInstGen *result = ir_const(ira, source_instruction, ty); |
| 5488 | static IrInstGen *ir_const_undef(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) { |
| 5489 | IrInstGen *result = ir_const(ira, scope, source_node, ty); |
| 5493 | 5490 | result->value->special = ConstValSpecialUndef; |
| 5494 | 5491 | return result; |
| 5495 | 5492 | } |
| 5496 | 5493 | |
| 5497 | | static IrInstGen *ir_const_unreachable(IrAnalyze *ira, IrInst *source_instruction) { |
| 5498 | | IrInstGen *result = ir_const_noval(ira, source_instruction); |
| 5494 | static IrInstGen *ir_const_unreachable(IrAnalyze *ira, Scope *scope, AstNode *source_node) { |
| 5495 | IrInstGen *result = ir_const_noval(ira, scope, source_node); |
| 5499 | 5496 | result->value = ira->codegen->intern.for_unreachable(); |
| 5500 | 5497 | return result; |
| 5501 | 5498 | } |
| 5502 | 5499 | |
| 5503 | | static IrInstGen *ir_const_void(IrAnalyze *ira, IrInst *source_instruction) { |
| 5504 | | IrInstGen *result = ir_const_noval(ira, source_instruction); |
| 5500 | static IrInstGen *ir_const_void(IrAnalyze *ira, Scope *scope, AstNode *source_node) { |
| 5501 | IrInstGen *result = ir_const_noval(ira, scope, source_node); |
| 5505 | 5502 | result->value = ira->codegen->intern.for_void(); |
| 5506 | 5503 | return result; |
| 5507 | 5504 | } |
| 5508 | 5505 | |
| 5509 | | static IrInstGen *ir_const_unsigned(IrAnalyze *ira, IrInst *source_instruction, uint64_t value) { |
| 5510 | | IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int); |
| 5506 | static IrInstGen *ir_const_unsigned(IrAnalyze *ira, Scope *scope, AstNode *source_node, uint64_t value) { |
| 5507 | IrInstGen *result = ir_const(ira, scope, source_node, ira->codegen->builtin_types.entry_num_lit_int); |
| 5511 | 5508 | bigint_init_unsigned(&result->value->data.x_bigint, value); |
| 5512 | 5509 | return result; |
| 5513 | 5510 | } |
| 5514 | 5511 | |
| 5515 | | static IrInstGen *ir_get_const_ptr(IrAnalyze *ira, IrInst *instruction, |
| 5512 | static IrInstGen *ir_get_const_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 5516 | 5513 | ZigValue *pointee, ZigType *pointee_type, |
| 5517 | 5514 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align) |
| 5518 | 5515 | { |
| 5519 | 5516 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, |
| 5520 | 5517 | ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false); |
| 5521 | | IrInstGen *const_instr = ir_const(ira, instruction, ptr_type); |
| 5518 | IrInstGen *const_instr = ir_const(ira, scope, source_node, ptr_type); |
| 5522 | 5519 | ZigValue *const_val = const_instr->value; |
| 5523 | 5520 | const_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 5524 | 5521 | const_val->data.x_ptr.mut = ptr_mut; |
| ... | ... | @@ -5562,7 +5559,7 @@ static Error ir_resolve_const_val(CodeGen *codegen, Stage1Air *exec, AstNode *so |
| 5562 | 5559 | |
| 5563 | 5560 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed) { |
| 5564 | 5561 | Error err; |
| 5565 | | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->base.source_node, |
| 5562 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node, |
| 5566 | 5563 | value->value, undef_allowed))) |
| 5567 | 5564 | { |
| 5568 | 5565 | return nullptr; |
| ... | ... | @@ -5641,7 +5638,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstGen *err_value) { |
| 5641 | 5638 | return nullptr; |
| 5642 | 5639 | |
| 5643 | 5640 | if (err_value->value->type->id != ZigTypeIdErrorSet) { |
| 5644 | | ir_add_error_node(ira, err_value->base.source_node, |
| 5641 | ir_add_error_node(ira, err_value->source_node, |
| 5645 | 5642 | buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name))); |
| 5646 | 5643 | return nullptr; |
| 5647 | 5644 | } |
| ... | ... | @@ -5670,13 +5667,13 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstGen *type_value) { |
| 5670 | 5667 | return nullptr; |
| 5671 | 5668 | |
| 5672 | 5669 | if (type_value->value->type->id != ZigTypeIdMetaType) { |
| 5673 | | ir_add_error_node(ira, type_value->base.source_node, |
| 5670 | ir_add_error_node(ira, type_value->source_node, |
| 5674 | 5671 | buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name))); |
| 5675 | 5672 | return nullptr; |
| 5676 | 5673 | } |
| 5677 | 5674 | |
| 5678 | 5675 | Error err; |
| 5679 | | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->base.source_node, |
| 5676 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->source_node, |
| 5680 | 5677 | type_value->value, LazyOkNoUndef))) |
| 5681 | 5678 | { |
| 5682 | 5679 | return nullptr; |
| ... | ... | @@ -5690,7 +5687,7 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstGen *type_value) { |
| 5690 | 5687 | if (val == nullptr) |
| 5691 | 5688 | return ira->codegen->builtin_types.entry_invalid; |
| 5692 | 5689 | |
| 5693 | | return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->base.source_node, val); |
| 5690 | return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->source_node, val); |
| 5694 | 5691 | } |
| 5695 | 5692 | |
| 5696 | 5693 | static Error ir_validate_vector_elem_type(IrAnalyze *ira, AstNode *source_node, ZigType *elem_type) { |
| ... | ... | @@ -5712,7 +5709,7 @@ static ZigType *ir_resolve_vector_elem_type(IrAnalyze *ira, IrInstGen *elem_type |
| 5712 | 5709 | ZigType *elem_type = ir_resolve_type(ira, elem_type_value); |
| 5713 | 5710 | if (type_is_invalid(elem_type)) |
| 5714 | 5711 | return ira->codegen->builtin_types.entry_invalid; |
| 5715 | | if ((err = ir_validate_vector_elem_type(ira, elem_type_value->base.source_node, elem_type))) |
| 5712 | if ((err = ir_validate_vector_elem_type(ira, elem_type_value->source_node, elem_type))) |
| 5716 | 5713 | return ira->codegen->builtin_types.entry_invalid; |
| 5717 | 5714 | return elem_type; |
| 5718 | 5715 | } |
| ... | ... | @@ -5723,12 +5720,12 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstGen *type_value) { |
| 5723 | 5720 | return ira->codegen->builtin_types.entry_invalid; |
| 5724 | 5721 | |
| 5725 | 5722 | if (ty->id != ZigTypeIdInt) { |
| 5726 | | ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node, |
| 5723 | ErrorMsg *msg = ir_add_error_node(ira, type_value->source_node, |
| 5727 | 5724 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&ty->name))); |
| 5728 | 5725 | if (ty->id == ZigTypeIdVector && |
| 5729 | 5726 | ty->data.vector.elem_type->id == ZigTypeIdInt) |
| 5730 | 5727 | { |
| 5731 | | add_error_note(ira->codegen, msg, type_value->base.source_node, |
| 5728 | add_error_note(ira->codegen, msg, type_value->source_node, |
| 5732 | 5729 | buf_sprintf("represent vectors with their element types, i.e. '%s'", |
| 5733 | 5730 | buf_ptr(&ty->data.vector.elem_type->name))); |
| 5734 | 5731 | } |
| ... | ... | @@ -5738,14 +5735,14 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstGen *type_value) { |
| 5738 | 5735 | return ty; |
| 5739 | 5736 | } |
| 5740 | 5737 | |
| 5741 | | static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInst *op_source, IrInstGen *type_value) { |
| 5738 | static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, AstNode *op_source, IrInstGen *type_value) { |
| 5742 | 5739 | if (type_is_invalid(type_value->value->type)) |
| 5743 | 5740 | return ira->codegen->builtin_types.entry_invalid; |
| 5744 | 5741 | |
| 5745 | 5742 | if (type_value->value->type->id != ZigTypeIdMetaType) { |
| 5746 | | ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node, |
| 5743 | ErrorMsg *msg = ir_add_error_node(ira, type_value->source_node, |
| 5747 | 5744 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name))); |
| 5748 | | add_error_note(ira->codegen, msg, op_source->source_node, |
| 5745 | add_error_note(ira->codegen, msg, op_source, |
| 5749 | 5746 | buf_sprintf("`||` merges error sets; `or` performs boolean OR")); |
| 5750 | 5747 | return ira->codegen->builtin_types.entry_invalid; |
| 5751 | 5748 | } |
| ... | ... | @@ -5757,9 +5754,9 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInst *op_source, IrI |
| 5757 | 5754 | assert(const_val->data.x_type != nullptr); |
| 5758 | 5755 | ZigType *result_type = const_val->data.x_type; |
| 5759 | 5756 | if (result_type->id != ZigTypeIdErrorSet) { |
| 5760 | | ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node, |
| 5757 | ErrorMsg *msg = ir_add_error_node(ira, type_value->source_node, |
| 5761 | 5758 | buf_sprintf("expected error set type, found type '%s'", buf_ptr(&result_type->name))); |
| 5762 | | add_error_note(ira->codegen, msg, op_source->source_node, |
| 5759 | add_error_note(ira->codegen, msg, op_source, |
| 5763 | 5760 | buf_sprintf("`||` merges error sets; `or` performs boolean OR")); |
| 5764 | 5761 | return ira->codegen->builtin_types.entry_invalid; |
| 5765 | 5762 | } |
| ... | ... | @@ -5771,7 +5768,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstGen *fn_value) { |
| 5771 | 5768 | return nullptr; |
| 5772 | 5769 | |
| 5773 | 5770 | if (fn_value->value->type->id != ZigTypeIdFn) { |
| 5774 | | ir_add_error_node(ira, fn_value->base.source_node, |
| 5771 | ir_add_error_node(ira, fn_value->source_node, |
| 5775 | 5772 | buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name))); |
| 5776 | 5773 | return nullptr; |
| 5777 | 5774 | } |
| ... | ... | @@ -5787,7 +5784,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstGen *fn_value) { |
| 5787 | 5784 | return const_val->data.x_ptr.data.fn.fn_entry; |
| 5788 | 5785 | } |
| 5789 | 5786 | |
| 5790 | | static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr, |
| 5787 | static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 5791 | 5788 | IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc) |
| 5792 | 5789 | { |
| 5793 | 5790 | assert(wanted_type->id == ZigTypeIdOptional); |
| ... | ... | @@ -5803,7 +5800,7 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr, |
| 5803 | 5800 | return ira->codegen->invalid_inst_gen; |
| 5804 | 5801 | |
| 5805 | 5802 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 5806 | | source_instr->scope, source_instr->source_node); |
| 5803 | scope, source_node); |
| 5807 | 5804 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 5808 | 5805 | if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) { |
| 5809 | 5806 | copy_const_val(ira->codegen, const_instruction->base.value, val); |
| ... | ... | @@ -5819,19 +5816,19 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr, |
| 5819 | 5816 | } |
| 5820 | 5817 | IrInstGen *result_loc_inst = nullptr; |
| 5821 | 5818 | if (result_loc != nullptr) { |
| 5822 | | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 5819 | result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, wanted_type, nullptr, true, true); |
| 5823 | 5820 | if (type_is_invalid(result_loc_inst->value->type) || |
| 5824 | 5821 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) |
| 5825 | 5822 | { |
| 5826 | 5823 | return result_loc_inst; |
| 5827 | 5824 | } |
| 5828 | 5825 | } |
| 5829 | | IrInstGen *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst); |
| 5826 | IrInstGen *result = ir_build_optional_wrap(ira, scope, source_node, wanted_type, value, result_loc_inst); |
| 5830 | 5827 | result->value->data.rh_maybe = RuntimeHintOptionalNonNull; |
| 5831 | 5828 | return result; |
| 5832 | 5829 | } |
| 5833 | 5830 | |
| 5834 | | static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_instr, |
| 5831 | static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 5835 | 5832 | IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc) |
| 5836 | 5833 | { |
| 5837 | 5834 | assert(wanted_type->id == ZigTypeIdErrorUnion); |
| ... | ... | @@ -5853,7 +5850,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins |
| 5853 | 5850 | err_set_val->data.x_err_set = nullptr; |
| 5854 | 5851 | |
| 5855 | 5852 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 5856 | | source_instr->scope, source_instr->source_node); |
| 5853 | scope, source_node); |
| 5857 | 5854 | const_instruction->base.value->type = wanted_type; |
| 5858 | 5855 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 5859 | 5856 | const_instruction->base.value->data.x_err_union.error_set = err_set_val; |
| ... | ... | @@ -5864,7 +5861,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins |
| 5864 | 5861 | IrInstGen *result_loc_inst; |
| 5865 | 5862 | if (handle_is_ptr(ira->codegen, wanted_type)) { |
| 5866 | 5863 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 5867 | | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 5864 | result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, wanted_type, nullptr, true, true); |
| 5868 | 5865 | if (type_is_invalid(result_loc_inst->value->type) || |
| 5869 | 5866 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 5870 | 5867 | return result_loc_inst; |
| ... | ... | @@ -5873,12 +5870,12 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins |
| 5873 | 5870 | result_loc_inst = nullptr; |
| 5874 | 5871 | } |
| 5875 | 5872 | |
| 5876 | | IrInstGen *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst); |
| 5873 | IrInstGen *result = ir_build_err_wrap_payload(ira, scope, source_node, wanted_type, value, result_loc_inst); |
| 5877 | 5874 | result->value->data.rh_error_union = RuntimeHintErrorUnionNonError; |
| 5878 | 5875 | return result; |
| 5879 | 5876 | } |
| 5880 | 5877 | |
| 5881 | | static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 5878 | static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value, |
| 5882 | 5879 | ZigType *wanted_type) |
| 5883 | 5880 | { |
| 5884 | 5881 | assert(value->value->type->id == ZigTypeIdErrorSet); |
| ... | ... | @@ -5889,7 +5886,7 @@ static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr, |
| 5889 | 5886 | if (!val) |
| 5890 | 5887 | return ira->codegen->invalid_inst_gen; |
| 5891 | 5888 | |
| 5892 | | if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) { |
| 5889 | if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_node)) { |
| 5893 | 5890 | return ira->codegen->invalid_inst_gen; |
| 5894 | 5891 | } |
| 5895 | 5892 | if (!type_is_global_error_set(wanted_type)) { |
| ... | ... | @@ -5901,7 +5898,7 @@ static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr, |
| 5901 | 5898 | } |
| 5902 | 5899 | } |
| 5903 | 5900 | if (!subset) { |
| 5904 | | ir_add_error(ira, source_instr, |
| 5901 | ir_add_error_node(ira, source_node, |
| 5905 | 5902 | buf_sprintf("error.%s not a member of error set '%s'", |
| 5906 | 5903 | buf_ptr(&val->data.x_err_set->name), buf_ptr(&wanted_type->name))); |
| 5907 | 5904 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -5909,17 +5906,17 @@ static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr, |
| 5909 | 5906 | } |
| 5910 | 5907 | |
| 5911 | 5908 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 5912 | | source_instr->scope, source_instr->source_node); |
| 5909 | scope, source_node); |
| 5913 | 5910 | const_instruction->base.value->type = wanted_type; |
| 5914 | 5911 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 5915 | 5912 | const_instruction->base.value->data.x_err_set = val->data.x_err_set; |
| 5916 | 5913 | return &const_instruction->base; |
| 5917 | 5914 | } |
| 5918 | 5915 | |
| 5919 | | return ir_build_cast(ira, source_instr, wanted_type, value, CastOpErrSet); |
| 5916 | return ir_build_cast(ira, scope, source_node, wanted_type, value, CastOpErrSet); |
| 5920 | 5917 | } |
| 5921 | 5918 | |
| 5922 | | static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInst* source_instr, |
| 5919 | static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 5923 | 5920 | IrInstGen *frame_ptr, ZigType *wanted_type) |
| 5924 | 5921 | { |
| 5925 | 5922 | if (instr_is_comptime(frame_ptr)) { |
| ... | ... | @@ -5927,27 +5924,27 @@ static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInst* sourc |
| 5927 | 5924 | if (ptr_val == nullptr) |
| 5928 | 5925 | return ira->codegen->invalid_inst_gen; |
| 5929 | 5926 | |
| 5930 | | ir_assert(ptr_val->type->id == ZigTypeIdPointer, source_instr); |
| 5927 | src_assert(ptr_val->type->id == ZigTypeIdPointer, source_node ); |
| 5931 | 5928 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 5932 | 5929 | zig_panic("TODO comptime frame pointer"); |
| 5933 | 5930 | } |
| 5934 | 5931 | } |
| 5935 | 5932 | |
| 5936 | | return ir_build_cast(ira, source_instr, wanted_type, frame_ptr, CastOpBitCast); |
| 5933 | return ir_build_cast(ira, scope, source_node, wanted_type, frame_ptr, CastOpBitCast); |
| 5937 | 5934 | } |
| 5938 | 5935 | |
| 5939 | | static IrInstGen *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInst* source_instr, |
| 5936 | static IrInstGen *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 5940 | 5937 | IrInstGen *value, ZigType *wanted_type) |
| 5941 | 5938 | { |
| 5942 | 5939 | if (instr_is_comptime(value)) { |
| 5943 | 5940 | zig_panic("TODO comptime anyframe->T to anyframe"); |
| 5944 | 5941 | } |
| 5945 | 5942 | |
| 5946 | | return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast); |
| 5943 | return ir_build_cast(ira, scope, source_node, wanted_type, value, CastOpBitCast); |
| 5947 | 5944 | } |
| 5948 | 5945 | |
| 5949 | 5946 | |
| 5950 | | static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 5947 | static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value, |
| 5951 | 5948 | ZigType *wanted_type, ResultLoc *result_loc) |
| 5952 | 5949 | { |
| 5953 | 5950 | assert(wanted_type->id == ZigTypeIdErrorUnion); |
| ... | ... | @@ -5965,7 +5962,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr, |
| 5965 | 5962 | err_set_val->data.x_err_set = val->data.x_err_set; |
| 5966 | 5963 | |
| 5967 | 5964 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 5968 | | source_instr->scope, source_instr->source_node); |
| 5965 | scope, source_node); |
| 5969 | 5966 | const_instruction->base.value->type = wanted_type; |
| 5970 | 5967 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 5971 | 5968 | const_instruction->base.value->data.x_err_union.error_set = err_set_val; |
| ... | ... | @@ -5976,7 +5973,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr, |
| 5976 | 5973 | IrInstGen *result_loc_inst; |
| 5977 | 5974 | if (handle_is_ptr(ira->codegen, wanted_type)) { |
| 5978 | 5975 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 5979 | | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true); |
| 5976 | result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, wanted_type, nullptr, true, true); |
| 5980 | 5977 | if (type_is_invalid(result_loc_inst->value->type) || |
| 5981 | 5978 | result_loc_inst->value->type->id == ZigTypeIdUnreachable) |
| 5982 | 5979 | { |
| ... | ... | @@ -5987,19 +5984,19 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr, |
| 5987 | 5984 | } |
| 5988 | 5985 | |
| 5989 | 5986 | |
| 5990 | | IrInstGen *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst); |
| 5987 | IrInstGen *result = ir_build_err_wrap_code(ira, scope, source_node, wanted_type, value, result_loc_inst); |
| 5991 | 5988 | result->value->data.rh_error_union = RuntimeHintErrorUnionError; |
| 5992 | 5989 | return result; |
| 5993 | 5990 | } |
| 5994 | 5991 | |
| 5995 | | static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, ZigType *wanted_type) { |
| 5992 | static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value, ZigType *wanted_type) { |
| 5996 | 5993 | assert(wanted_type->id == ZigTypeIdOptional); |
| 5997 | 5994 | assert(instr_is_comptime(value)); |
| 5998 | 5995 | |
| 5999 | 5996 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 6000 | 5997 | assert(val != nullptr); |
| 6001 | 5998 | |
| 6002 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 5999 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 6003 | 6000 | result->value->special = ConstValSpecialStatic; |
| 6004 | 6001 | |
| 6005 | 6002 | if (get_src_ptr_type(wanted_type) != nullptr) { |
| ... | ... | @@ -6012,7 +6009,7 @@ static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInst *source_instr, |
| 6012 | 6009 | return result; |
| 6013 | 6010 | } |
| 6014 | 6011 | |
| 6015 | | static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_instr, |
| 6012 | static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 6016 | 6013 | IrInstGen *value, ZigType *wanted_type) |
| 6017 | 6014 | { |
| 6018 | 6015 | assert(wanted_type->id == ZigTypeIdPointer); |
| ... | ... | @@ -6022,13 +6019,13 @@ static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_in |
| 6022 | 6019 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 6023 | 6020 | assert(val != nullptr); |
| 6024 | 6021 | |
| 6025 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 6022 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 6026 | 6023 | result->value->data.x_ptr.special = ConstPtrSpecialNull; |
| 6027 | 6024 | result->value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 6028 | 6025 | return result; |
| 6029 | 6026 | } |
| 6030 | 6027 | |
| 6031 | | static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value, |
| 6028 | static IrInstGen *ir_get_ref2(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value, |
| 6032 | 6029 | ZigType *elem_type, bool is_const, bool is_volatile) |
| 6033 | 6030 | { |
| 6034 | 6031 | Error err; |
| ... | ... | @@ -6040,7 +6037,7 @@ static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInst |
| 6040 | 6037 | ZigValue *val = ir_resolve_const(ira, value, LazyOk); |
| 6041 | 6038 | if (!val) |
| 6042 | 6039 | return ira->codegen->invalid_inst_gen; |
| 6043 | | return ir_get_const_ptr(ira, source_instruction, val, elem_type, |
| 6040 | return ir_get_const_ptr(ira, scope, source_node, val, elem_type, |
| 6044 | 6041 | ConstPtrMutComptimeConst, is_const, is_volatile, 0); |
| 6045 | 6042 | } |
| 6046 | 6043 | |
| ... | ... | @@ -6052,20 +6049,20 @@ static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInst |
| 6052 | 6049 | |
| 6053 | 6050 | IrInstGen *result_loc; |
| 6054 | 6051 | if (type_has_bits(ira->codegen, ptr_type) && !handle_is_ptr(ira->codegen, elem_type)) { |
| 6055 | | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), elem_type, nullptr, true, true); |
| 6052 | result_loc = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(), elem_type, nullptr, true, true); |
| 6056 | 6053 | } else { |
| 6057 | 6054 | result_loc = nullptr; |
| 6058 | 6055 | } |
| 6059 | 6056 | |
| 6060 | | IrInstGen *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc); |
| 6057 | IrInstGen *new_instruction = ir_build_ref_gen(ira, scope, source_node, ptr_type, value, result_loc); |
| 6061 | 6058 | new_instruction->value->data.rh_ptr = RuntimeHintPtrStack; |
| 6062 | 6059 | return new_instruction; |
| 6063 | 6060 | } |
| 6064 | 6061 | |
| 6065 | | static IrInstGen *ir_get_ref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value, |
| 6062 | static IrInstGen *ir_get_ref(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value, |
| 6066 | 6063 | bool is_const, bool is_volatile) |
| 6067 | 6064 | { |
| 6068 | | return ir_get_ref2(ira, source_instruction, value, value->value->type, is_const, is_volatile); |
| 6065 | return ir_get_ref2(ira, scope, source_node, value, value->value->type, is_const, is_volatile); |
| 6069 | 6066 | } |
| 6070 | 6067 | |
| 6071 | 6068 | static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, AstNode *source_node, ZigType *union_type) { |
| ... | ... | @@ -6099,13 +6096,13 @@ static bool can_fold_enum_type(ZigType *ty) { |
| 6099 | 6096 | (tag_int_type->id == ZigTypeIdInt && tag_int_type->data.integral.bit_count == 0); |
| 6100 | 6097 | } |
| 6101 | 6098 | |
| 6102 | | static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) { |
| 6099 | static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target) { |
| 6103 | 6100 | Error err; |
| 6104 | 6101 | |
| 6105 | 6102 | IrInstGen *enum_target; |
| 6106 | 6103 | ZigType *enum_type; |
| 6107 | 6104 | if (target->value->type->id == ZigTypeIdUnion) { |
| 6108 | | enum_type = ir_resolve_union_tag_type(ira, target->base.source_node, target->value->type); |
| 6105 | enum_type = ir_resolve_union_tag_type(ira, target->source_node, target->value->type); |
| 6109 | 6106 | if (type_is_invalid(enum_type)) |
| 6110 | 6107 | return ira->codegen->invalid_inst_gen; |
| 6111 | 6108 | enum_target = ir_implicit_cast(ira, target, enum_type); |
| ... | ... | @@ -6115,7 +6112,7 @@ static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, I |
| 6115 | 6112 | enum_target = target; |
| 6116 | 6113 | enum_type = target->value->type; |
| 6117 | 6114 | } else { |
| 6118 | | ir_add_error_node(ira, target->base.source_node, |
| 6115 | ir_add_error_node(ira, target->source_node, |
| 6119 | 6116 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name))); |
| 6120 | 6117 | return ira->codegen->invalid_inst_gen; |
| 6121 | 6118 | } |
| ... | ... | @@ -6128,7 +6125,7 @@ static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, I |
| 6128 | 6125 | |
| 6129 | 6126 | // If there is only one possible tag, then we know at comptime what it is. |
| 6130 | 6127 | if (can_fold_enum_type(enum_type)) { |
| 6131 | | IrInstGen *result = ir_const(ira, source_instr, tag_type); |
| 6128 | IrInstGen *result = ir_const(ira, scope, source_node, tag_type); |
| 6132 | 6129 | init_const_bigint(result->value, tag_type, |
| 6133 | 6130 | &enum_type->data.enumeration.fields[0].value); |
| 6134 | 6131 | return result; |
| ... | ... | @@ -6138,15 +6135,15 @@ static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, I |
| 6138 | 6135 | ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad); |
| 6139 | 6136 | if (!val) |
| 6140 | 6137 | return ira->codegen->invalid_inst_gen; |
| 6141 | | IrInstGen *result = ir_const(ira, source_instr, tag_type); |
| 6138 | IrInstGen *result = ir_const(ira, scope, source_node, tag_type); |
| 6142 | 6139 | init_const_bigint(result->value, tag_type, &val->data.x_enum_tag); |
| 6143 | 6140 | return result; |
| 6144 | 6141 | } |
| 6145 | 6142 | |
| 6146 | | return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, enum_target, tag_type); |
| 6143 | return ir_build_widen_or_shorten(ira, scope, source_node, enum_target, tag_type); |
| 6147 | 6144 | } |
| 6148 | 6145 | |
| 6149 | | static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr, |
| 6146 | static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 6150 | 6147 | IrInstGen *target, ZigType *wanted_type) |
| 6151 | 6148 | { |
| 6152 | 6149 | assert(target->value->type->id == ZigTypeIdUnion); |
| ... | ... | @@ -6157,7 +6154,7 @@ static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr, |
| 6157 | 6154 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 6158 | 6155 | if (!val) |
| 6159 | 6156 | return ira->codegen->invalid_inst_gen; |
| 6160 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 6157 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 6161 | 6158 | result->value->special = ConstValSpecialStatic; |
| 6162 | 6159 | result->value->type = wanted_type; |
| 6163 | 6160 | bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag); |
| ... | ... | @@ -6166,7 +6163,7 @@ static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr, |
| 6166 | 6163 | |
| 6167 | 6164 | // If there is only 1 possible tag, then we know at comptime what it is. |
| 6168 | 6165 | if (can_fold_enum_type(wanted_type)) { |
| 6169 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 6166 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 6170 | 6167 | result->value->special = ConstValSpecialStatic; |
| 6171 | 6168 | result->value->type = wanted_type; |
| 6172 | 6169 | TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field; |
| ... | ... | @@ -6174,18 +6171,18 @@ static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr, |
| 6174 | 6171 | return result; |
| 6175 | 6172 | } |
| 6176 | 6173 | |
| 6177 | | return ir_build_union_tag(ira, source_instr, target, wanted_type); |
| 6174 | return ir_build_union_tag(ira, scope, source_node, target, wanted_type); |
| 6178 | 6175 | } |
| 6179 | 6176 | |
| 6180 | | static IrInstGen *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInst* source_instr, |
| 6177 | static IrInstGen *ir_analyze_undefined_to_anything(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 6181 | 6178 | IrInstGen *target, ZigType *wanted_type) |
| 6182 | 6179 | { |
| 6183 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 6180 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 6184 | 6181 | result->value->special = ConstValSpecialUndef; |
| 6185 | 6182 | return result; |
| 6186 | 6183 | } |
| 6187 | 6184 | |
| 6188 | | static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr, |
| 6185 | static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 6189 | 6186 | IrInstGen *uncasted_target, ZigType *wanted_type) |
| 6190 | 6187 | { |
| 6191 | 6188 | Error err; |
| ... | ... | @@ -6207,7 +6204,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr, |
| 6207 | 6204 | Buf *int_buf = buf_alloc(); |
| 6208 | 6205 | bigint_append_buf(int_buf, &target->value->data.x_enum_tag, 10); |
| 6209 | 6206 | |
| 6210 | | ir_add_error(ira, &target->base, |
| 6207 | ir_add_error(ira, target, |
| 6211 | 6208 | buf_sprintf("no tag by value %s", buf_ptr(int_buf))); |
| 6212 | 6209 | return ira->codegen->invalid_inst_gen; |
| 6213 | 6210 | } |
| ... | ... | @@ -6223,7 +6220,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr, |
| 6223 | 6220 | case OnePossibleValueNo: { |
| 6224 | 6221 | AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at( |
| 6225 | 6222 | union_field->enum_field->decl_index); |
| 6226 | | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 6223 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 6227 | 6224 | buf_sprintf("cast to union '%s' must initialize '%s' field '%s'", |
| 6228 | 6225 | buf_ptr(&wanted_type->name), |
| 6229 | 6226 | buf_ptr(&field_type->name), |
| ... | ... | @@ -6236,7 +6233,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr, |
| 6236 | 6233 | break; |
| 6237 | 6234 | } |
| 6238 | 6235 | |
| 6239 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 6236 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 6240 | 6237 | result->value->special = ConstValSpecialStatic; |
| 6241 | 6238 | result->value->type = wanted_type; |
| 6242 | 6239 | bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag); |
| ... | ... | @@ -6247,7 +6244,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr, |
| 6247 | 6244 | } |
| 6248 | 6245 | |
| 6249 | 6246 | if (target->value->type->data.enumeration.non_exhaustive) { |
| 6250 | | ir_add_error(ira, source_instr, |
| 6247 | ir_add_error_node(ira, source_node, |
| 6251 | 6248 | buf_sprintf("runtime cast to union '%s' from non-exhustive enum", |
| 6252 | 6249 | buf_ptr(&wanted_type->name))); |
| 6253 | 6250 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -6256,10 +6253,10 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr, |
| 6256 | 6253 | // if the union has all fields 0 bits, we can do it |
| 6257 | 6254 | // and in fact it's a noop cast because the union value is just the enum value |
| 6258 | 6255 | if (wanted_type->data.unionation.gen_field_count == 0) { |
| 6259 | | return ir_build_cast(ira, &target->base, wanted_type, target, CastOpNoop); |
| 6256 | return ir_build_cast(ira, target->scope, target->source_node, wanted_type, target, CastOpNoop); |
| 6260 | 6257 | } |
| 6261 | 6258 | |
| 6262 | | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 6259 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 6263 | 6260 | buf_sprintf("runtime cast to union '%s' which has non-void fields", |
| 6264 | 6261 | buf_ptr(&wanted_type->name))); |
| 6265 | 6262 | for (uint32_t i = 0; i < wanted_type->data.unionation.src_field_count; i += 1) { |
| ... | ... | @@ -6283,7 +6280,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr, |
| 6283 | 6280 | |
| 6284 | 6281 | static bool value_numeric_fits_in_type(ZigValue *value, ZigType *type_entry); |
| 6285 | 6282 | |
| 6286 | | static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_instr, |
| 6283 | static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 6287 | 6284 | IrInstGen *target, ZigType *wanted_type) |
| 6288 | 6285 | { |
| 6289 | 6286 | ZigType *wanted_scalar_type = (target->value->type->id == ZigTypeIdVector) ? |
| ... | ... | @@ -6298,19 +6295,19 @@ static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_ins |
| 6298 | 6295 | |
| 6299 | 6296 | if (wanted_scalar_type->id == ZigTypeIdInt) { |
| 6300 | 6297 | if (!wanted_scalar_type->data.integral.is_signed && value_cmp_numeric_val_any(val, CmpLT, nullptr)) { |
| 6301 | | ir_add_error(ira, source_instr, |
| 6298 | ir_add_error_node(ira, source_node, |
| 6302 | 6299 | buf_sprintf("attempt to cast negative value to unsigned integer")); |
| 6303 | 6300 | return ira->codegen->invalid_inst_gen; |
| 6304 | 6301 | } |
| 6305 | 6302 | if (!value_numeric_fits_in_type(val, wanted_scalar_type)) { |
| 6306 | | ir_add_error(ira, source_instr, |
| 6303 | ir_add_error_node(ira, source_node, |
| 6307 | 6304 | buf_sprintf("cast from '%s' to '%s' truncates bits", |
| 6308 | 6305 | buf_ptr(&target->value->type->name), buf_ptr(&wanted_scalar_type->name))); |
| 6309 | 6306 | return ira->codegen->invalid_inst_gen; |
| 6310 | 6307 | } |
| 6311 | 6308 | } |
| 6312 | 6309 | |
| 6313 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 6310 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 6314 | 6311 | result->value->type = wanted_type; |
| 6315 | 6312 | |
| 6316 | 6313 | if (wanted_type->id == ZigTypeIdVector) { |
| ... | ... | @@ -6346,16 +6343,16 @@ static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_ins |
| 6346 | 6343 | if (!type_has_bits(ira->codegen, wanted_type)) { |
| 6347 | 6344 | assert(wanted_type->id == ZigTypeIdInt); |
| 6348 | 6345 | assert(type_has_bits(ira->codegen, target->value->type)); |
| 6349 | | ir_build_assert_zero(ira, source_instr, target); |
| 6350 | | IrInstGen *result = ir_const_unsigned(ira, source_instr, 0); |
| 6346 | ir_build_assert_zero(ira, scope, source_node, target); |
| 6347 | IrInstGen *result = ir_const_unsigned(ira, scope, source_node, 0); |
| 6351 | 6348 | result->value->type = wanted_type; |
| 6352 | 6349 | return result; |
| 6353 | 6350 | } |
| 6354 | 6351 | |
| 6355 | | return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, target, wanted_type); |
| 6352 | return ir_build_widen_or_shorten(ira, scope, source_node, target, wanted_type); |
| 6356 | 6353 | } |
| 6357 | 6354 | |
| 6358 | | static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr, |
| 6355 | static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 6359 | 6356 | IrInstGen *target, ZigType *wanted_type) |
| 6360 | 6357 | { |
| 6361 | 6358 | Error err; |
| ... | ... | @@ -6367,7 +6364,7 @@ static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr, |
| 6367 | 6364 | return ira->codegen->invalid_inst_gen; |
| 6368 | 6365 | |
| 6369 | 6366 | if (actual_type != wanted_type->data.enumeration.tag_int_type) { |
| 6370 | | ir_add_error(ira, source_instr, |
| 6367 | ir_add_error_node(ira, source_node, |
| 6371 | 6368 | buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'", |
| 6372 | 6369 | buf_ptr(&actual_type->name), |
| 6373 | 6370 | buf_ptr(&wanted_type->data.enumeration.tag_int_type->name))); |
| ... | ... | @@ -6385,7 +6382,7 @@ static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr, |
| 6385 | 6382 | if (field == nullptr && !wanted_type->data.enumeration.non_exhaustive) { |
| 6386 | 6383 | Buf *val_buf = buf_alloc(); |
| 6387 | 6384 | bigint_append_buf(val_buf, &val->data.x_bigint, 10); |
| 6388 | | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 6385 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 6389 | 6386 | buf_sprintf("enum '%s' has no tag matching integer value %s", |
| 6390 | 6387 | buf_ptr(&wanted_type->name), buf_ptr(val_buf))); |
| 6391 | 6388 | add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node, |
| ... | ... | @@ -6393,22 +6390,22 @@ static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr, |
| 6393 | 6390 | return ira->codegen->invalid_inst_gen; |
| 6394 | 6391 | } |
| 6395 | 6392 | |
| 6396 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 6393 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 6397 | 6394 | bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint); |
| 6398 | 6395 | return result; |
| 6399 | 6396 | } |
| 6400 | 6397 | |
| 6401 | | return ir_build_int_to_enum_gen(ira, source_instr->scope, source_instr->source_node, wanted_type, target); |
| 6398 | return ir_build_int_to_enum_gen(ira, scope, source_node, wanted_type, target); |
| 6402 | 6399 | } |
| 6403 | 6400 | |
| 6404 | | static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, IrInst* source_instr, |
| 6401 | static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 6405 | 6402 | IrInstGen *target, ZigType *wanted_type) |
| 6406 | 6403 | { |
| 6407 | 6404 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 6408 | 6405 | if (!val) |
| 6409 | 6406 | return ira->codegen->invalid_inst_gen; |
| 6410 | 6407 | |
| 6411 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 6408 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 6412 | 6409 | if (wanted_type->id == ZigTypeIdComptimeFloat) { |
| 6413 | 6410 | float_init_float(result->value, val); |
| 6414 | 6411 | } else if (wanted_type->id == ZigTypeIdComptimeInt) { |
| ... | ... | @@ -6419,7 +6416,7 @@ static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, IrInst* source_in |
| 6419 | 6416 | return result; |
| 6420 | 6417 | } |
| 6421 | 6418 | |
| 6422 | | static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 6419 | static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target, |
| 6423 | 6420 | ZigType *wanted_type) |
| 6424 | 6421 | { |
| 6425 | 6422 | assert(target->value->type->id == ZigTypeIdInt); |
| ... | ... | @@ -6431,9 +6428,9 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir |
| 6431 | 6428 | if (!val) |
| 6432 | 6429 | return ira->codegen->invalid_inst_gen; |
| 6433 | 6430 | |
| 6434 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 6431 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 6435 | 6432 | |
| 6436 | | if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) { |
| 6433 | if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_node)) { |
| 6437 | 6434 | return ira->codegen->invalid_inst_gen; |
| 6438 | 6435 | } |
| 6439 | 6436 | |
| ... | ... | @@ -6444,7 +6441,7 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir |
| 6444 | 6441 | if (bigint_cmp_zero(&val->data.x_bigint) == CmpEQ || bigint_cmp(&val->data.x_bigint, &err_count) != CmpLT) { |
| 6445 | 6442 | Buf *val_buf = buf_alloc(); |
| 6446 | 6443 | bigint_append_buf(val_buf, &val->data.x_bigint, 10); |
| 6447 | | ir_add_error(ira, source_instr, |
| 6444 | ir_add_error_node(ira, source_node, |
| 6448 | 6445 | buf_sprintf("integer value %s represents no error", buf_ptr(val_buf))); |
| 6449 | 6446 | return ira->codegen->invalid_inst_gen; |
| 6450 | 6447 | } |
| ... | ... | @@ -6468,7 +6465,7 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir |
| 6468 | 6465 | if (err == nullptr) { |
| 6469 | 6466 | Buf *val_buf = buf_alloc(); |
| 6470 | 6467 | bigint_append_buf(val_buf, &val->data.x_bigint, 10); |
| 6471 | | ir_add_error(ira, source_instr, |
| 6468 | ir_add_error_node(ira, source_node, |
| 6472 | 6469 | buf_sprintf("integer value %s represents no error in '%s'", buf_ptr(val_buf), buf_ptr(&wanted_type->name))); |
| 6473 | 6470 | return ira->codegen->invalid_inst_gen; |
| 6474 | 6471 | } |
| ... | ... | @@ -6478,10 +6475,10 @@ static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, Ir |
| 6478 | 6475 | } |
| 6479 | 6476 | } |
| 6480 | 6477 | |
| 6481 | | return ir_build_int_to_err_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type); |
| 6478 | return ir_build_int_to_err_gen(ira, scope, source_node, target, wanted_type); |
| 6482 | 6479 | } |
| 6483 | 6480 | |
| 6484 | | static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 6481 | static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target, |
| 6485 | 6482 | ZigType *wanted_type) |
| 6486 | 6483 | { |
| 6487 | 6484 | assert(wanted_type->id == ZigTypeIdInt); |
| ... | ... | @@ -6493,7 +6490,7 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir |
| 6493 | 6490 | if (!val) |
| 6494 | 6491 | return ira->codegen->invalid_inst_gen; |
| 6495 | 6492 | |
| 6496 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 6493 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 6497 | 6494 | |
| 6498 | 6495 | ErrorTableEntry *err; |
| 6499 | 6496 | if (err_type->id == ZigTypeIdErrorUnion) { |
| ... | ... | @@ -6510,7 +6507,7 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir |
| 6510 | 6507 | if (!bigint_fits_in_bits(&result->value->data.x_bigint, |
| 6511 | 6508 | wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) |
| 6512 | 6509 | { |
| 6513 | | ir_add_error_node(ira, source_instr->source_node, |
| 6510 | ir_add_error_node(ira, source_node, |
| 6514 | 6511 | buf_sprintf("error code '%s' does not fit in '%s'", |
| 6515 | 6512 | buf_ptr(&err->name), buf_ptr(&wanted_type->name))); |
| 6516 | 6513 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -6528,15 +6525,15 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir |
| 6528 | 6525 | zig_unreachable(); |
| 6529 | 6526 | } |
| 6530 | 6527 | if (!type_is_global_error_set(err_set_type)) { |
| 6531 | | if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_instr->source_node)) { |
| 6528 | if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_node)) { |
| 6532 | 6529 | return ira->codegen->invalid_inst_gen; |
| 6533 | 6530 | } |
| 6534 | 6531 | if (err_set_type->data.error_set.err_count == 0) { |
| 6535 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 6532 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 6536 | 6533 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 6537 | 6534 | return result; |
| 6538 | 6535 | } else if (err_set_type->data.error_set.err_count == 1) { |
| 6539 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 6536 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 6540 | 6537 | ErrorTableEntry *err = err_set_type->data.error_set.errors[0]; |
| 6541 | 6538 | bigint_init_unsigned(&result->value->data.x_bigint, err->value); |
| 6542 | 6539 | return result; |
| ... | ... | @@ -6546,15 +6543,15 @@ static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, Ir |
| 6546 | 6543 | BigInt bn; |
| 6547 | 6544 | bigint_init_unsigned(&bn, ira->codegen->errors_by_index.length); |
| 6548 | 6545 | if (!bigint_fits_in_bits(&bn, wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) { |
| 6549 | | ir_add_error_node(ira, source_instr->source_node, |
| 6546 | ir_add_error_node(ira, source_node, |
| 6550 | 6547 | buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name))); |
| 6551 | 6548 | return ira->codegen->invalid_inst_gen; |
| 6552 | 6549 | } |
| 6553 | 6550 | |
| 6554 | | return ir_build_err_to_int_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type); |
| 6551 | return ir_build_err_to_int_gen(ira, scope, source_node, target, wanted_type); |
| 6555 | 6552 | } |
| 6556 | 6553 | |
| 6557 | | static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 6554 | static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target, |
| 6558 | 6555 | ZigType *wanted_type) |
| 6559 | 6556 | { |
| 6560 | 6557 | assert(wanted_type->id == ZigTypeIdPointer); |
| ... | ... | @@ -6573,7 +6570,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr, |
| 6573 | 6570 | return ira->codegen->invalid_inst_gen; |
| 6574 | 6571 | |
| 6575 | 6572 | assert(val->type->id == ZigTypeIdPointer); |
| 6576 | | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); |
| 6573 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_node); |
| 6577 | 6574 | if (pointee == nullptr) |
| 6578 | 6575 | return ira->codegen->invalid_inst_gen; |
| 6579 | 6576 | if (pointee->special != ConstValSpecialRuntime) { |
| ... | ... | @@ -6586,7 +6583,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr, |
| 6586 | 6583 | array_val->parent.data.p_scalar.scalar_val = pointee; |
| 6587 | 6584 | |
| 6588 | 6585 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 6589 | | source_instr->scope, source_instr->source_node); |
| 6586 | scope, source_node); |
| 6590 | 6587 | const_instruction->base.value->type = wanted_type; |
| 6591 | 6588 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 6592 | 6589 | const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialRef; |
| ... | ... | @@ -6597,7 +6594,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr, |
| 6597 | 6594 | } |
| 6598 | 6595 | |
| 6599 | 6596 | // pointer to array and pointer to single item are represented the same way at runtime |
| 6600 | | return ir_build_cast(ira, &target->base, wanted_type, target, CastOpBitCast); |
| 6597 | return ir_build_cast(ira, target->scope, target->source_node, wanted_type, target, CastOpBitCast); |
| 6601 | 6598 | } |
| 6602 | 6599 | |
| 6603 | 6600 | static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCastOnly *cast_result, |
| ... | ... | @@ -6794,25 +6791,25 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 6794 | 6791 | } |
| 6795 | 6792 | } |
| 6796 | 6793 | |
| 6797 | | static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, IrInst* source_instr, |
| 6794 | static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 6798 | 6795 | IrInstGen *array, ZigType *vector_type) |
| 6799 | 6796 | { |
| 6800 | 6797 | if (instr_is_comptime(array)) { |
| 6801 | 6798 | // arrays and vectors have the same ZigValue representation |
| 6802 | | IrInstGen *result = ir_const(ira, source_instr, vector_type); |
| 6799 | IrInstGen *result = ir_const(ira, scope, source_node, vector_type); |
| 6803 | 6800 | copy_const_val(ira->codegen, result->value, array->value); |
| 6804 | 6801 | result->value->type = vector_type; |
| 6805 | 6802 | return result; |
| 6806 | 6803 | } |
| 6807 | | return ir_build_array_to_vector(ira, source_instr, array, vector_type); |
| 6804 | return ir_build_array_to_vector(ira, scope, source_node, array, vector_type); |
| 6808 | 6805 | } |
| 6809 | 6806 | |
| 6810 | | static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_instr, |
| 6807 | static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 6811 | 6808 | IrInstGen *vector, ZigType *array_type, ResultLoc *result_loc) |
| 6812 | 6809 | { |
| 6813 | 6810 | if (instr_is_comptime(vector)) { |
| 6814 | 6811 | // arrays and vectors have the same ZigValue representation |
| 6815 | | IrInstGen *result = ir_const(ira, source_instr, array_type); |
| 6812 | IrInstGen *result = ir_const(ira, scope, source_node, array_type); |
| 6816 | 6813 | copy_const_val(ira->codegen, result->value, vector->value); |
| 6817 | 6814 | result->value->type = array_type; |
| 6818 | 6815 | return result; |
| ... | ... | @@ -6820,14 +6817,14 @@ static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_inst |
| 6820 | 6817 | if (result_loc == nullptr) { |
| 6821 | 6818 | result_loc = no_result_loc(); |
| 6822 | 6819 | } |
| 6823 | | IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, true, true); |
| 6820 | IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, array_type, nullptr, true, true); |
| 6824 | 6821 | if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 6825 | 6822 | return result_loc_inst; |
| 6826 | 6823 | } |
| 6827 | | return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst); |
| 6824 | return ir_build_vector_to_array(ira, scope, source_node, array_type, vector, result_loc_inst); |
| 6828 | 6825 | } |
| 6829 | 6826 | |
| 6830 | | static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 6827 | static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 6831 | 6828 | IrInstGen *integer, ZigType *dest_type) |
| 6832 | 6829 | { |
| 6833 | 6830 | IrInstGen *unsigned_integer; |
| ... | ... | @@ -6839,7 +6836,7 @@ static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 6839 | 6836 | if (integer->value->type->data.integral.bit_count > |
| 6840 | 6837 | ira->codegen->builtin_types.entry_usize->data.integral.bit_count) |
| 6841 | 6838 | { |
| 6842 | | ir_add_error(ira, source_instr, |
| 6839 | ir_add_error_node(ira, source_node, |
| 6843 | 6840 | buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'", |
| 6844 | 6841 | buf_ptr(&integer->value->type->name), |
| 6845 | 6842 | buf_ptr(&dest_type->name))); |
| ... | ... | @@ -6849,7 +6846,7 @@ static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 6849 | 6846 | if (integer->value->type->data.integral.is_signed) { |
| 6850 | 6847 | ZigType *unsigned_int_type = get_int_type(ira->codegen, false, |
| 6851 | 6848 | integer->value->type->data.integral.bit_count); |
| 6852 | | unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type); |
| 6849 | unsigned_integer = ir_analyze_bit_cast(ira, scope, source_node, integer, unsigned_int_type); |
| 6853 | 6850 | if (type_is_invalid(unsigned_integer->value->type)) |
| 6854 | 6851 | return ira->codegen->invalid_inst_gen; |
| 6855 | 6852 | } else { |
| ... | ... | @@ -6857,7 +6854,7 @@ static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 6857 | 6854 | } |
| 6858 | 6855 | } |
| 6859 | 6856 | |
| 6860 | | return ir_analyze_int_to_ptr(ira, source_instr, unsigned_integer, dest_type); |
| 6857 | return ir_analyze_int_to_ptr(ira, scope, source_node, unsigned_integer, dest_type); |
| 6861 | 6858 | } |
| 6862 | 6859 | |
| 6863 | 6860 | static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) { |
| ... | ... | @@ -6871,7 +6868,7 @@ static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) { |
| 6871 | 6868 | return false; |
| 6872 | 6869 | } |
| 6873 | 6870 | |
| 6874 | | static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 6871 | static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value, |
| 6875 | 6872 | ZigType *enum_type) |
| 6876 | 6873 | { |
| 6877 | 6874 | assert(enum_type->id == ZigTypeIdEnum); |
| ... | ... | @@ -6882,19 +6879,19 @@ static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, IrInst* source_instr, |
| 6882 | 6879 | |
| 6883 | 6880 | TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal); |
| 6884 | 6881 | if (field == nullptr) { |
| 6885 | | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("enum '%s' has no field named '%s'", |
| 6882 | ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("enum '%s' has no field named '%s'", |
| 6886 | 6883 | buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal))); |
| 6887 | 6884 | add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node, |
| 6888 | 6885 | buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name))); |
| 6889 | 6886 | return ira->codegen->invalid_inst_gen; |
| 6890 | 6887 | } |
| 6891 | | IrInstGen *result = ir_const(ira, source_instr, enum_type); |
| 6888 | IrInstGen *result = ir_const(ira, scope, source_node, enum_type); |
| 6892 | 6889 | bigint_init_bigint(&result->value->data.x_enum_tag, &field->value); |
| 6893 | 6890 | |
| 6894 | 6891 | return result; |
| 6895 | 6892 | } |
| 6896 | 6893 | |
| 6897 | | static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* source_instr, |
| 6894 | static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 6898 | 6895 | IrInstGen *struct_ptr, ZigType *actual_type, ZigType *wanted_type) |
| 6899 | 6896 | { |
| 6900 | 6897 | Error err; |
| ... | ... | @@ -6906,7 +6903,7 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou |
| 6906 | 6903 | size_t instr_field_count = actual_type->data.structure.src_field_count; |
| 6907 | 6904 | assert(array_len == instr_field_count); |
| 6908 | 6905 | |
| 6909 | | bool need_comptime = ir_should_inline(ira->zir, source_instr->scope) |
| 6906 | bool need_comptime = ir_should_inline(ira->zir, scope) |
| 6910 | 6907 | || type_requires_comptime(ira->codegen, wanted_type) == ReqCompTimeYes; |
| 6911 | 6908 | bool is_comptime = true; |
| 6912 | 6909 | |
| ... | ... | @@ -6915,16 +6912,16 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou |
| 6915 | 6912 | // Determine if the struct_operand will be comptime. |
| 6916 | 6913 | ZigValue *elem_values = heap::c_allocator.allocate<ZigValue>(array_len); |
| 6917 | 6914 | IrInstGen **casted_fields = heap::c_allocator.allocate<IrInstGen *>(array_len); |
| 6918 | | IrInstGen *const_result = ir_const(ira, source_instr, wanted_type); |
| 6915 | IrInstGen *const_result = ir_const(ira, scope, source_node, wanted_type); |
| 6919 | 6916 | |
| 6920 | 6917 | for (size_t i = 0; i < array_len; i += 1) { |
| 6921 | 6918 | TypeStructField *src_field = actual_type->data.structure.fields[i]; |
| 6922 | 6919 | |
| 6923 | | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, src_field, struct_ptr, |
| 6920 | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, src_field, struct_ptr, |
| 6924 | 6921 | actual_type, false); |
| 6925 | 6922 | if (type_is_invalid(field_ptr->value->type)) |
| 6926 | 6923 | return ira->codegen->invalid_inst_gen; |
| 6927 | | IrInstGen *field_value = ir_get_deref(ira, source_instr, field_ptr, nullptr); |
| 6924 | IrInstGen *field_value = ir_get_deref(ira, scope, source_node, field_ptr, nullptr); |
| 6928 | 6925 | if (type_is_invalid(field_value->value->type)) |
| 6929 | 6926 | return ira->codegen->invalid_inst_gen; |
| 6930 | 6927 | IrInstGen *casted_value = ir_implicit_cast(ira, field_value, elem_type); |
| ... | ... | @@ -6950,13 +6947,13 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou |
| 6950 | 6947 | } |
| 6951 | 6948 | |
| 6952 | 6949 | if (is_comptime) { |
| 6953 | | IrInstGen *const_result = ir_const(ira, source_instr, wanted_type); |
| 6950 | IrInstGen *const_result = ir_const(ira, scope, source_node, wanted_type); |
| 6954 | 6951 | const_result->value->data.x_array.special = ConstArraySpecialNone; |
| 6955 | 6952 | const_result->value->data.x_array.data.s_none.elements = elem_values; |
| 6956 | 6953 | return const_result; |
| 6957 | 6954 | } |
| 6958 | 6955 | |
| 6959 | | IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, no_result_loc(), |
| 6956 | IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(), |
| 6960 | 6957 | wanted_type, nullptr, true, true); |
| 6961 | 6958 | if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 6962 | 6959 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -6964,12 +6961,12 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou |
| 6964 | 6961 | |
| 6965 | 6962 | ZigType *elem_type_ptr = get_pointer_to_type(ira->codegen, elem_type, false); |
| 6966 | 6963 | for (size_t i = 0; i < array_len; i += 1) { |
| 6967 | | IrInstGen *index_val = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize); |
| 6964 | IrInstGen *index_val = ir_const(ira, scope, source_node, ira->codegen->builtin_types.entry_usize); |
| 6968 | 6965 | bigint_init_unsigned(&index_val->value->data.x_bigint, i); |
| 6969 | 6966 | |
| 6970 | | IrInstGen *elem_ptr = ir_build_elem_ptr_gen(ira, source_instr->scope, source_instr->source_node, |
| 6967 | IrInstGen *elem_ptr = ir_build_elem_ptr_gen(ira, scope, source_node, |
| 6971 | 6968 | result_loc_inst, index_val, false, elem_type_ptr); |
| 6972 | | IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, elem_ptr, casted_fields[i], true); |
| 6969 | IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, scope, source_node, elem_ptr, casted_fields[i], true); |
| 6973 | 6970 | if (type_is_invalid(store_ptr_inst->value->type)) |
| 6974 | 6971 | return ira->codegen->invalid_inst_gen; |
| 6975 | 6972 | } |
| ... | ... | @@ -6980,13 +6977,13 @@ static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* sou |
| 6980 | 6977 | return result_loc_inst; |
| 6981 | 6978 | } |
| 6982 | 6979 | |
| 6983 | | static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* source_instr, |
| 6980 | static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 6984 | 6981 | IrInstGen *struct_ptr, ZigType *actual_type, ZigType *wanted_type) |
| 6985 | 6982 | { |
| 6986 | 6983 | Error err; |
| 6987 | 6984 | |
| 6988 | 6985 | if (wanted_type->data.structure.resolve_status == ResolveStatusBeingInferred) { |
| 6989 | | ir_add_error(ira, source_instr, buf_sprintf("type coercion of anon struct literal to inferred struct")); |
| 6986 | ir_add_error_node(ira, source_node, buf_sprintf("type coercion of anon struct literal to inferred struct")); |
| 6990 | 6987 | return ira->codegen->invalid_inst_gen; |
| 6991 | 6988 | } |
| 6992 | 6989 | |
| ... | ... | @@ -6996,7 +6993,7 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so |
| 6996 | 6993 | size_t actual_field_count = wanted_type->data.structure.src_field_count; |
| 6997 | 6994 | size_t instr_field_count = actual_type->data.structure.src_field_count; |
| 6998 | 6995 | |
| 6999 | | bool need_comptime = ir_should_inline(ira->zir, source_instr->scope) |
| 6996 | bool need_comptime = ir_should_inline(ira->zir, scope) |
| 7000 | 6997 | || type_requires_comptime(ira->codegen, wanted_type) == ReqCompTimeYes; |
| 7001 | 6998 | bool is_comptime = true; |
| 7002 | 6999 | |
| ... | ... | @@ -7005,13 +7002,13 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so |
| 7005 | 7002 | AstNode **field_assign_nodes = heap::c_allocator.allocate<AstNode *>(actual_field_count); |
| 7006 | 7003 | ZigValue **field_values = heap::c_allocator.allocate<ZigValue *>(actual_field_count); |
| 7007 | 7004 | IrInstGen **casted_fields = heap::c_allocator.allocate<IrInstGen *>(actual_field_count); |
| 7008 | | IrInstGen *const_result = ir_const(ira, source_instr, wanted_type); |
| 7005 | IrInstGen *const_result = ir_const(ira, scope, source_node, wanted_type); |
| 7009 | 7006 | |
| 7010 | 7007 | for (size_t i = 0; i < instr_field_count; i += 1) { |
| 7011 | 7008 | TypeStructField *src_field = actual_type->data.structure.fields[i]; |
| 7012 | 7009 | TypeStructField *dst_field = find_struct_type_field(wanted_type, src_field->name); |
| 7013 | 7010 | if (dst_field == nullptr) { |
| 7014 | | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("no field named '%s' in struct '%s'", |
| 7011 | ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("no field named '%s' in struct '%s'", |
| 7015 | 7012 | buf_ptr(src_field->name), buf_ptr(&wanted_type->name))); |
| 7016 | 7013 | if (wanted_type->data.structure.decl_node) { |
| 7017 | 7014 | add_error_note(ira->codegen, msg, wanted_type->data.structure.decl_node, |
| ... | ... | @@ -7022,20 +7019,20 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so |
| 7022 | 7019 | return ira->codegen->invalid_inst_gen; |
| 7023 | 7020 | } |
| 7024 | 7021 | |
| 7025 | | ir_assert(src_field->decl_node != nullptr, source_instr); |
| 7022 | src_assert(src_field->decl_node != nullptr, source_node); |
| 7026 | 7023 | AstNode *existing_assign_node = field_assign_nodes[dst_field->src_index]; |
| 7027 | 7024 | if (existing_assign_node != nullptr) { |
| 7028 | | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("duplicate field")); |
| 7025 | ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("duplicate field")); |
| 7029 | 7026 | add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here")); |
| 7030 | 7027 | return ira->codegen->invalid_inst_gen; |
| 7031 | 7028 | } |
| 7032 | 7029 | field_assign_nodes[dst_field->src_index] = src_field->decl_node; |
| 7033 | 7030 | |
| 7034 | | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, src_field, struct_ptr, |
| 7031 | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, src_field, struct_ptr, |
| 7035 | 7032 | actual_type, false); |
| 7036 | 7033 | if (type_is_invalid(field_ptr->value->type)) |
| 7037 | 7034 | return ira->codegen->invalid_inst_gen; |
| 7038 | | IrInstGen *field_value = ir_get_deref(ira, source_instr, field_ptr, nullptr); |
| 7035 | IrInstGen *field_value = ir_get_deref(ira, scope, source_node, field_ptr, nullptr); |
| 7039 | 7036 | if (type_is_invalid(field_value->value->type)) |
| 7040 | 7037 | return ira->codegen->invalid_inst_gen; |
| 7041 | 7038 | IrInstGen *casted_value = ir_implicit_cast(ira, field_value, dst_field->type_entry); |
| ... | ... | @@ -7067,7 +7064,7 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so |
| 7067 | 7064 | TypeStructField *field = wanted_type->data.structure.fields[i]; |
| 7068 | 7065 | memoize_field_init_val(ira->codegen, wanted_type, field); |
| 7069 | 7066 | if (field->init_val == nullptr) { |
| 7070 | | ir_add_error(ira, source_instr, |
| 7067 | ir_add_error_node(ira, source_node, |
| 7071 | 7068 | buf_sprintf("missing field: '%s'", buf_ptr(field->name))); |
| 7072 | 7069 | any_missing = true; |
| 7073 | 7070 | continue; |
| ... | ... | @@ -7080,19 +7077,19 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so |
| 7080 | 7077 | init_val_copy->parent.data.p_struct.struct_val = const_result->value; |
| 7081 | 7078 | init_val_copy->parent.data.p_struct.field_index = i; |
| 7082 | 7079 | field_values[i] = init_val_copy; |
| 7083 | | casted_fields[i] = ir_const_move(ira, source_instr, init_val_copy); |
| 7080 | casted_fields[i] = ir_const_move(ira, scope, source_node, init_val_copy); |
| 7084 | 7081 | } |
| 7085 | 7082 | if (any_missing) |
| 7086 | 7083 | return ira->codegen->invalid_inst_gen; |
| 7087 | 7084 | |
| 7088 | 7085 | if (is_comptime) { |
| 7089 | 7086 | heap::c_allocator.deallocate(field_assign_nodes, actual_field_count); |
| 7090 | | IrInstGen *const_result = ir_const(ira, source_instr, wanted_type); |
| 7087 | IrInstGen *const_result = ir_const(ira, scope, source_node, wanted_type); |
| 7091 | 7088 | const_result->value->data.x_struct.fields = field_values; |
| 7092 | 7089 | return const_result; |
| 7093 | 7090 | } |
| 7094 | 7091 | |
| 7095 | | IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, no_result_loc(), |
| 7092 | IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(), |
| 7096 | 7093 | wanted_type, nullptr, true, true); |
| 7097 | 7094 | if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 7098 | 7095 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -7100,10 +7097,10 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so |
| 7100 | 7097 | |
| 7101 | 7098 | for (size_t i = 0; i < actual_field_count; i += 1) { |
| 7102 | 7099 | TypeStructField *field = wanted_type->data.structure.fields[i]; |
| 7103 | | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc_inst, wanted_type, true); |
| 7100 | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, field, result_loc_inst, wanted_type, true); |
| 7104 | 7101 | if (type_is_invalid(field_ptr->value->type)) |
| 7105 | 7102 | return ira->codegen->invalid_inst_gen; |
| 7106 | | IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, field_ptr, casted_fields[i], true); |
| 7103 | IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, scope, source_node, field_ptr, casted_fields[i], true); |
| 7107 | 7104 | if (type_is_invalid(store_ptr_inst->value->type)) |
| 7108 | 7105 | return ira->codegen->invalid_inst_gen; |
| 7109 | 7106 | } |
| ... | ... | @@ -7115,7 +7112,7 @@ static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* so |
| 7115 | 7112 | return result_loc_inst; |
| 7116 | 7113 | } |
| 7117 | 7114 | |
| 7118 | | static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* source_instr, |
| 7115 | static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 7119 | 7116 | IrInstGen *struct_ptr, ZigType *struct_type, ZigType *union_type) |
| 7120 | 7117 | { |
| 7121 | 7118 | Error err; |
| ... | ... | @@ -7141,11 +7138,11 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou |
| 7141 | 7138 | if (payload_type == nullptr) |
| 7142 | 7139 | return ira->codegen->invalid_inst_gen; |
| 7143 | 7140 | |
| 7144 | | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, only_field, struct_ptr, |
| 7141 | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, only_field, struct_ptr, |
| 7145 | 7142 | struct_type, false); |
| 7146 | 7143 | if (type_is_invalid(field_ptr->value->type)) |
| 7147 | 7144 | return ira->codegen->invalid_inst_gen; |
| 7148 | | IrInstGen *field_value = ir_get_deref(ira, source_instr, field_ptr, nullptr); |
| 7145 | IrInstGen *field_value = ir_get_deref(ira, scope, source_node, field_ptr, nullptr); |
| 7149 | 7146 | if (type_is_invalid(field_value->value->type)) |
| 7150 | 7147 | return ira->codegen->invalid_inst_gen; |
| 7151 | 7148 | |
| ... | ... | @@ -7158,7 +7155,7 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou |
| 7158 | 7155 | if (val == nullptr) |
| 7159 | 7156 | return ira->codegen->invalid_inst_gen; |
| 7160 | 7157 | |
| 7161 | | IrInstGen *result = ir_const(ira, source_instr, union_type); |
| 7158 | IrInstGen *result = ir_const(ira, scope, source_node, union_type); |
| 7162 | 7159 | bigint_init_bigint(&result->value->data.x_union.tag, &union_field->enum_field->value); |
| 7163 | 7160 | result->value->data.x_union.payload = val; |
| 7164 | 7161 | |
| ... | ... | @@ -7168,18 +7165,18 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou |
| 7168 | 7165 | return result; |
| 7169 | 7166 | } |
| 7170 | 7167 | |
| 7171 | | IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, no_result_loc(), |
| 7168 | IrInstGen *result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(), |
| 7172 | 7169 | union_type, nullptr, true, true); |
| 7173 | 7170 | if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 7174 | 7171 | return ira->codegen->invalid_inst_gen; |
| 7175 | 7172 | } |
| 7176 | 7173 | |
| 7177 | | IrInstGen *payload_ptr = ir_analyze_container_field_ptr(ira, only_field->name, source_instr, |
| 7178 | | result_loc_inst, source_instr, union_type, true); |
| 7174 | IrInstGen *payload_ptr = ir_analyze_container_field_ptr(ira, only_field->name, |
| 7175 | scope, source_node, result_loc_inst, source_node, union_type, true); |
| 7179 | 7176 | if (type_is_invalid(payload_ptr->value->type)) |
| 7180 | 7177 | return ira->codegen->invalid_inst_gen; |
| 7181 | 7178 | |
| 7182 | | IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, payload_ptr, casted_value, false); |
| 7179 | IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, scope, source_node, payload_ptr, casted_value, false); |
| 7183 | 7180 | if (type_is_invalid(store_ptr_inst->value->type)) |
| 7184 | 7181 | return ira->codegen->invalid_inst_gen; |
| 7185 | 7182 | |
| ... | ... | @@ -7190,13 +7187,13 @@ static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* sou |
| 7190 | 7187 | // otherwise return ErrorNone. Does not emit any instructions. |
| 7191 | 7188 | // Assumes that the pointer types have element types with the same ABI alignment. Avoids resolving the |
| 7192 | 7189 | // pointer types' alignments if both of the pointer types are ABI aligned. |
| 7193 | | static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *dest_ptr_type, |
| 7190 | static Error ir_cast_ptr_align(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *dest_ptr_type, |
| 7194 | 7191 | ZigType *src_ptr_type, AstNode *src_source_node) |
| 7195 | 7192 | { |
| 7196 | 7193 | Error err; |
| 7197 | 7194 | |
| 7198 | | ir_assert(dest_ptr_type->id == ZigTypeIdPointer, source_instr); |
| 7199 | | ir_assert(src_ptr_type->id == ZigTypeIdPointer, source_instr); |
| 7195 | src_assert(dest_ptr_type->id == ZigTypeIdPointer, source_node); |
| 7196 | src_assert(src_ptr_type->id == ZigTypeIdPointer, source_node); |
| 7200 | 7197 | |
| 7201 | 7198 | if (dest_ptr_type->data.pointer.explicit_alignment == 0 && |
| 7202 | 7199 | src_ptr_type->data.pointer.explicit_alignment == 0) |
| ... | ... | @@ -7213,10 +7210,10 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *de |
| 7213 | 7210 | uint32_t wanted_align = get_ptr_align(ira->codegen, dest_ptr_type); |
| 7214 | 7211 | uint32_t actual_align = get_ptr_align(ira->codegen, src_ptr_type); |
| 7215 | 7212 | if (wanted_align > actual_align) { |
| 7216 | | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment")); |
| 7213 | ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("cast increases pointer alignment")); |
| 7217 | 7214 | add_error_note(ira->codegen, msg, src_source_node, |
| 7218 | 7215 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_ptr_type->name), actual_align)); |
| 7219 | | add_error_note(ira->codegen, msg, source_instr->source_node, |
| 7216 | add_error_note(ira->codegen, msg, source_node, |
| 7220 | 7217 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_ptr_type->name), wanted_align)); |
| 7221 | 7218 | return ErrorSemanticAnalyzeFail; |
| 7222 | 7219 | } |
| ... | ... | @@ -7224,34 +7221,33 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *de |
| 7224 | 7221 | return ErrorNone; |
| 7225 | 7222 | } |
| 7226 | 7223 | |
| 7227 | | static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst* source_instr, |
| 7224 | static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 7228 | 7225 | IrInstGen *struct_operand, TypeStructField *field) |
| 7229 | 7226 | { |
| 7230 | | IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false); |
| 7227 | IrInstGen *struct_ptr = ir_get_ref(ira, scope, source_node, struct_operand, true, false); |
| 7231 | 7228 | if (type_is_invalid(struct_ptr->value->type)) |
| 7232 | 7229 | return ira->codegen->invalid_inst_gen; |
| 7233 | | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr, |
| 7230 | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, field, struct_ptr, |
| 7234 | 7231 | struct_operand->value->type, false); |
| 7235 | 7232 | if (type_is_invalid(field_ptr->value->type)) |
| 7236 | 7233 | return ira->codegen->invalid_inst_gen; |
| 7237 | | return ir_get_deref(ira, source_instr, field_ptr, nullptr); |
| 7234 | return ir_get_deref(ira, scope, source_node, field_ptr, nullptr); |
| 7238 | 7235 | } |
| 7239 | 7236 | |
| 7240 | | static IrInstGen *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInst* source_instr, |
| 7237 | static IrInstGen *ir_analyze_optional_value_payload_value(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 7241 | 7238 | IrInstGen *optional_operand, bool safety_check_on) |
| 7242 | 7239 | { |
| 7243 | | IrInstGen *opt_ptr = ir_get_ref(ira, source_instr, optional_operand, true, false); |
| 7244 | | IrInstGen *payload_ptr = ir_analyze_unwrap_optional_payload(ira, source_instr, opt_ptr, |
| 7240 | IrInstGen *opt_ptr = ir_get_ref(ira, scope, source_node, optional_operand, true, false); |
| 7241 | IrInstGen *payload_ptr = ir_analyze_unwrap_optional_payload(ira, scope, source_node, opt_ptr, |
| 7245 | 7242 | safety_check_on, false); |
| 7246 | | return ir_get_deref(ira, source_instr, payload_ptr, nullptr); |
| 7243 | return ir_get_deref(ira, scope, source_node, payload_ptr, nullptr); |
| 7247 | 7244 | } |
| 7248 | 7245 | |
| 7249 | | static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7246 | static IrInstGen *ir_analyze_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 7250 | 7247 | ZigType *wanted_type, IrInstGen *value) |
| 7251 | 7248 | { |
| 7252 | 7249 | Error err; |
| 7253 | 7250 | ZigType *actual_type = value->value->type; |
| 7254 | | AstNode *source_node = source_instr->source_node; |
| 7255 | 7251 | |
| 7256 | 7252 | if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) { |
| 7257 | 7253 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -7268,21 +7264,21 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7268 | 7264 | if (const_cast_result.id == ConstCastResultIdInvalid) |
| 7269 | 7265 | return ira->codegen->invalid_inst_gen; |
| 7270 | 7266 | if (const_cast_result.id == ConstCastResultIdOk) { |
| 7271 | | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop); |
| 7267 | return ir_resolve_cast(ira, scope, source_node, value, wanted_type, CastOpNoop); |
| 7272 | 7268 | } |
| 7273 | 7269 | |
| 7274 | 7270 | if (const_cast_result.id == ConstCastResultIdFnCC) { |
| 7275 | | ir_assert(value->value->type->id == ZigTypeIdFn, source_instr); |
| 7271 | src_assert(value->value->type->id == ZigTypeIdFn, source_node); |
| 7276 | 7272 | // ConstCastResultIdFnCC is guaranteed to be the last one reported, meaning everything else is ok. |
| 7277 | 7273 | if (wanted_type->data.fn.fn_type_id.cc == CallingConventionAsync && |
| 7278 | 7274 | actual_type->data.fn.fn_type_id.cc == CallingConventionUnspecified) |
| 7279 | 7275 | { |
| 7280 | | ir_assert(value->value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr); |
| 7276 | src_assert(value->value->data.x_ptr.special == ConstPtrSpecialFunction, source_node); |
| 7281 | 7277 | ZigFn *fn = value->value->data.x_ptr.data.fn.fn_entry; |
| 7282 | 7278 | if (fn->inferred_async_node == nullptr) { |
| 7283 | | fn->inferred_async_node = source_instr->source_node; |
| 7279 | fn->inferred_async_node = source_node; |
| 7284 | 7280 | } |
| 7285 | | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop); |
| 7281 | return ir_resolve_cast(ira, scope, source_node, value, wanted_type, CastOpNoop); |
| 7286 | 7282 | } |
| 7287 | 7283 | } |
| 7288 | 7284 | |
| ... | ... | @@ -7293,12 +7289,12 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7293 | 7289 | if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, |
| 7294 | 7290 | false).id == ConstCastResultIdOk) |
| 7295 | 7291 | { |
| 7296 | | return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr); |
| 7292 | return ir_analyze_optional_wrap(ira, scope, source_node, value, wanted_type, nullptr); |
| 7297 | 7293 | } else if (actual_type->id == ZigTypeIdComptimeInt || |
| 7298 | 7294 | actual_type->id == ZigTypeIdComptimeFloat) |
| 7299 | 7295 | { |
| 7300 | 7296 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) { |
| 7301 | | return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr); |
| 7297 | return ir_analyze_optional_wrap(ira, scope, source_node, value, wanted_type, nullptr); |
| 7302 | 7298 | } else { |
| 7303 | 7299 | return ira->codegen->invalid_inst_gen; |
| 7304 | 7300 | } |
| ... | ... | @@ -7318,11 +7314,11 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7318 | 7314 | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| 7319 | 7315 | !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 7320 | 7316 | { |
| 7321 | | IrInstGen *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, |
| 7317 | IrInstGen *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, scope, source_node, value, |
| 7322 | 7318 | wanted_child_type); |
| 7323 | 7319 | if (type_is_invalid(cast1->value->type)) |
| 7324 | 7320 | return ira->codegen->invalid_inst_gen; |
| 7325 | | return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr); |
| 7321 | return ir_analyze_optional_wrap(ira, scope, source_node, cast1, wanted_type, nullptr); |
| 7326 | 7322 | } |
| 7327 | 7323 | } |
| 7328 | 7324 | } |
| ... | ... | @@ -7332,12 +7328,12 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7332 | 7328 | if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type, |
| 7333 | 7329 | source_node, false).id == ConstCastResultIdOk) |
| 7334 | 7330 | { |
| 7335 | | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr); |
| 7331 | return ir_analyze_err_wrap_payload(ira, scope, source_node, value, wanted_type, nullptr); |
| 7336 | 7332 | } else if (actual_type->id == ZigTypeIdComptimeInt || |
| 7337 | 7333 | actual_type->id == ZigTypeIdComptimeFloat) |
| 7338 | 7334 | { |
| 7339 | 7335 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) { |
| 7340 | | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr); |
| 7336 | return ir_analyze_err_wrap_payload(ira, scope, source_node, value, wanted_type, nullptr); |
| 7341 | 7337 | } else { |
| 7342 | 7338 | return ira->codegen->invalid_inst_gen; |
| 7343 | 7339 | } |
| ... | ... | @@ -7355,11 +7351,11 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7355 | 7351 | actual_type->id == ZigTypeIdComptimeInt || |
| 7356 | 7352 | actual_type->id == ZigTypeIdComptimeFloat) |
| 7357 | 7353 | { |
| 7358 | | IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 7354 | IrInstGen *cast1 = ir_analyze_cast(ira, scope, source_node, wanted_type->data.error_union.payload_type, value); |
| 7359 | 7355 | if (type_is_invalid(cast1->value->type)) |
| 7360 | 7356 | return ira->codegen->invalid_inst_gen; |
| 7361 | 7357 | |
| 7362 | | IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 7358 | IrInstGen *cast2 = ir_analyze_cast(ira, scope, source_node, wanted_type, cast1); |
| 7363 | 7359 | if (type_is_invalid(cast2->value->type)) |
| 7364 | 7360 | return ira->codegen->invalid_inst_gen; |
| 7365 | 7361 | |
| ... | ... | @@ -7376,13 +7372,13 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7376 | 7372 | wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat)) |
| 7377 | 7373 | { |
| 7378 | 7374 | if (value->value->special == ConstValSpecialUndef) { |
| 7379 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 7375 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 7380 | 7376 | result->value->special = ConstValSpecialUndef; |
| 7381 | 7377 | return result; |
| 7382 | 7378 | } |
| 7383 | 7379 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) { |
| 7384 | 7380 | if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) { |
| 7385 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 7381 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 7386 | 7382 | if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) { |
| 7387 | 7383 | copy_const_val(ira->codegen, result->value, value->value); |
| 7388 | 7384 | result->value->type = wanted_type; |
| ... | ... | @@ -7391,7 +7387,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7391 | 7387 | } |
| 7392 | 7388 | return result; |
| 7393 | 7389 | } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) { |
| 7394 | | IrInstGen *result = ir_const(ira, source_instr, wanted_type); |
| 7390 | IrInstGen *result = ir_const(ira, scope, source_node, wanted_type); |
| 7395 | 7391 | if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) { |
| 7396 | 7392 | BigFloat bf; |
| 7397 | 7393 | bigfloat_init_bigint(&bf, &value->value->data.x_bigint); |
| ... | ... | @@ -7413,7 +7409,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7413 | 7409 | wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed && |
| 7414 | 7410 | wanted_type->data.integral.bit_count >= actual_type->data.integral.bit_count) |
| 7415 | 7411 | { |
| 7416 | | return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); |
| 7412 | return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type); |
| 7417 | 7413 | } |
| 7418 | 7414 | |
| 7419 | 7415 | // small enough unsigned ints can get casted to large enough signed ints |
| ... | ... | @@ -7421,7 +7417,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7421 | 7417 | actual_type->id == ZigTypeIdInt && !actual_type->data.integral.is_signed && |
| 7422 | 7418 | wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count) |
| 7423 | 7419 | { |
| 7424 | | return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); |
| 7420 | return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type); |
| 7425 | 7421 | } |
| 7426 | 7422 | |
| 7427 | 7423 | // float widening conversion |
| ... | ... | @@ -7429,7 +7425,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7429 | 7425 | actual_type->id == ZigTypeIdFloat && |
| 7430 | 7426 | wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count) |
| 7431 | 7427 | { |
| 7432 | | return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); |
| 7428 | return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type); |
| 7433 | 7429 | } |
| 7434 | 7430 | |
| 7435 | 7431 | // *[N]T to ?[]T |
| ... | ... | @@ -7439,11 +7435,11 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7439 | 7435 | actual_type->data.pointer.ptr_len == PtrLenSingle && |
| 7440 | 7436 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) |
| 7441 | 7437 | { |
| 7442 | | IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); |
| 7438 | IrInstGen *cast1 = ir_analyze_cast(ira, scope, source_node, wanted_type->data.maybe.child_type, value); |
| 7443 | 7439 | if (type_is_invalid(cast1->value->type)) |
| 7444 | 7440 | return ira->codegen->invalid_inst_gen; |
| 7445 | 7441 | |
| 7446 | | IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 7442 | IrInstGen *cast2 = ir_analyze_cast(ira, scope, source_node, wanted_type, cast1); |
| 7447 | 7443 | if (type_is_invalid(cast2->value->type)) |
| 7448 | 7444 | return ira->codegen->invalid_inst_gen; |
| 7449 | 7445 | |
| ... | ... | @@ -7474,7 +7470,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7474 | 7470 | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| 7475 | 7471 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 7476 | 7472 | { |
| 7477 | | return ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_type); |
| 7473 | return ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, scope, source_node, value, wanted_type); |
| 7478 | 7474 | } |
| 7479 | 7475 | } |
| 7480 | 7476 | } |
| ... | ... | @@ -7525,17 +7521,17 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7525 | 7521 | } |
| 7526 | 7522 | if (ok_align) { |
| 7527 | 7523 | if (wanted_type->id == ZigTypeIdErrorUnion) { |
| 7528 | | IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value); |
| 7524 | IrInstGen *cast1 = ir_analyze_cast(ira, scope, source_node, slice_type, value); |
| 7529 | 7525 | if (type_is_invalid(cast1->value->type)) |
| 7530 | 7526 | return ira->codegen->invalid_inst_gen; |
| 7531 | 7527 | |
| 7532 | | IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 7528 | IrInstGen *cast2 = ir_analyze_cast(ira, scope, source_node, wanted_type, cast1); |
| 7533 | 7529 | if (type_is_invalid(cast2->value->type)) |
| 7534 | 7530 | return ira->codegen->invalid_inst_gen; |
| 7535 | 7531 | |
| 7536 | 7532 | return cast2; |
| 7537 | 7533 | } else { |
| 7538 | | return ir_resolve_ptr_of_array_to_slice(ira, source_instr, value, slice_type, nullptr); |
| 7534 | return ir_resolve_ptr_of_array_to_slice(ira, scope, source_node, value, slice_type, nullptr); |
| 7539 | 7535 | } |
| 7540 | 7536 | } |
| 7541 | 7537 | } |
| ... | ... | @@ -7554,7 +7550,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7554 | 7550 | scalar_wanted_type->data.integral.is_signed == scalar_actual_type->data.integral.is_signed && |
| 7555 | 7551 | scalar_wanted_type->data.integral.bit_count >= scalar_actual_type->data.integral.bit_count) |
| 7556 | 7552 | { |
| 7557 | | return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); |
| 7553 | return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type); |
| 7558 | 7554 | } |
| 7559 | 7555 | |
| 7560 | 7556 | // small enough unsigned ints can get casted to large enough signed ints |
| ... | ... | @@ -7562,7 +7558,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7562 | 7558 | scalar_actual_type->id == ZigTypeIdInt && !scalar_actual_type->data.integral.is_signed && |
| 7563 | 7559 | scalar_wanted_type->data.integral.bit_count > scalar_actual_type->data.integral.bit_count) |
| 7564 | 7560 | { |
| 7565 | | return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); |
| 7561 | return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type); |
| 7566 | 7562 | } |
| 7567 | 7563 | |
| 7568 | 7564 | // float widening conversion |
| ... | ... | @@ -7570,7 +7566,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7570 | 7566 | scalar_actual_type->id == ZigTypeIdFloat && |
| 7571 | 7567 | scalar_wanted_type->data.floating.bit_count >= scalar_actual_type->data.floating.bit_count) |
| 7572 | 7568 | { |
| 7573 | | return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); |
| 7569 | return ir_analyze_widen_or_shorten(ira, scope, source_node, value, wanted_type); |
| 7574 | 7570 | } |
| 7575 | 7571 | } |
| 7576 | 7572 | |
| ... | ... | @@ -7605,10 +7601,10 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7605 | 7601 | } |
| 7606 | 7602 | } |
| 7607 | 7603 | if (ok) { |
| 7608 | | IrInstGen *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type); |
| 7604 | IrInstGen *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, scope, source_node, value, anyframe_type); |
| 7609 | 7605 | if (anyframe_type == wanted_type) |
| 7610 | 7606 | return cast1; |
| 7611 | | return ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 7607 | return ir_analyze_cast(ira, scope, source_node, wanted_type, cast1); |
| 7612 | 7608 | } |
| 7613 | 7609 | } |
| 7614 | 7610 | } |
| ... | ... | @@ -7617,28 +7613,28 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7617 | 7613 | if (actual_type->id == ZigTypeIdAnyFrame && actual_type->data.any_frame.result_type != nullptr && |
| 7618 | 7614 | wanted_type->id == ZigTypeIdAnyFrame && wanted_type->data.any_frame.result_type == nullptr) |
| 7619 | 7615 | { |
| 7620 | | return ir_analyze_anyframe_to_anyframe(ira, source_instr, value, wanted_type); |
| 7616 | return ir_analyze_anyframe_to_anyframe(ira, scope, source_node, value, wanted_type); |
| 7621 | 7617 | } |
| 7622 | 7618 | |
| 7623 | 7619 | // cast from null literal to maybe type |
| 7624 | 7620 | if (wanted_type->id == ZigTypeIdOptional && |
| 7625 | 7621 | actual_type->id == ZigTypeIdNull) |
| 7626 | 7622 | { |
| 7627 | | return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type); |
| 7623 | return ir_analyze_null_to_maybe(ira, scope, source_node, value, wanted_type); |
| 7628 | 7624 | } |
| 7629 | 7625 | |
| 7630 | 7626 | // cast from null literal to C pointer |
| 7631 | 7627 | if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenC && |
| 7632 | 7628 | actual_type->id == ZigTypeIdNull) |
| 7633 | 7629 | { |
| 7634 | | return ir_analyze_null_to_c_pointer(ira, source_instr, value, wanted_type); |
| 7630 | return ir_analyze_null_to_c_pointer(ira, scope, source_node, value, wanted_type); |
| 7635 | 7631 | } |
| 7636 | 7632 | |
| 7637 | 7633 | // cast from E to E!T |
| 7638 | 7634 | if (wanted_type->id == ZigTypeIdErrorUnion && |
| 7639 | 7635 | actual_type->id == ZigTypeIdErrorSet) |
| 7640 | 7636 | { |
| 7641 | | return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type, nullptr); |
| 7637 | return ir_analyze_err_wrap_code(ira, scope, source_node, value, wanted_type, nullptr); |
| 7642 | 7638 | } |
| 7643 | 7639 | |
| 7644 | 7640 | // cast from typed number to integer or float literal. |
| ... | ... | @@ -7647,35 +7643,35 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7647 | 7643 | ((actual_type->id == ZigTypeIdInt && wanted_type->id == ZigTypeIdComptimeInt) || |
| 7648 | 7644 | (actual_type->id == ZigTypeIdFloat && wanted_type->id == ZigTypeIdComptimeFloat))) |
| 7649 | 7645 | { |
| 7650 | | return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type); |
| 7646 | return ir_analyze_number_to_literal(ira, scope, source_node, value, wanted_type); |
| 7651 | 7647 | } |
| 7652 | 7648 | |
| 7653 | 7649 | // cast from enum literal to enum with matching field name |
| 7654 | 7650 | if (actual_type->id == ZigTypeIdEnumLiteral && wanted_type->id == ZigTypeIdEnum) |
| 7655 | 7651 | { |
| 7656 | | return ir_analyze_enum_literal(ira, source_instr, value, wanted_type); |
| 7652 | return ir_analyze_enum_literal(ira, scope, source_node, value, wanted_type); |
| 7657 | 7653 | } |
| 7658 | 7654 | |
| 7659 | 7655 | // cast from enum literal to optional enum |
| 7660 | 7656 | if (actual_type->id == ZigTypeIdEnumLiteral && |
| 7661 | 7657 | (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum)) |
| 7662 | 7658 | { |
| 7663 | | IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type); |
| 7659 | IrInstGen *result = ir_analyze_enum_literal(ira, scope, source_node, value, wanted_type->data.maybe.child_type); |
| 7664 | 7660 | if (type_is_invalid(result->value->type)) |
| 7665 | 7661 | return result; |
| 7666 | 7662 | |
| 7667 | | return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr); |
| 7663 | return ir_analyze_optional_wrap(ira, scope, source_node, value, wanted_type, nullptr); |
| 7668 | 7664 | } |
| 7669 | 7665 | |
| 7670 | 7666 | // cast from enum literal to error union when payload is an enum |
| 7671 | 7667 | if (actual_type->id == ZigTypeIdEnumLiteral && |
| 7672 | 7668 | (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum)) |
| 7673 | 7669 | { |
| 7674 | | IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type); |
| 7670 | IrInstGen *result = ir_analyze_enum_literal(ira, scope, source_node, value, wanted_type->data.error_union.payload_type); |
| 7675 | 7671 | if (type_is_invalid(result->value->type)) |
| 7676 | 7672 | return result; |
| 7677 | 7673 | |
| 7678 | | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr); |
| 7674 | return ir_analyze_err_wrap_payload(ira, scope, source_node, value, wanted_type, nullptr); |
| 7679 | 7675 | } |
| 7680 | 7676 | |
| 7681 | 7677 | // cast from union to the enum type of the union |
| ... | ... | @@ -7684,7 +7680,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7684 | 7680 | return ira->codegen->invalid_inst_gen; |
| 7685 | 7681 | |
| 7686 | 7682 | if (actual_type->data.unionation.tag_type == wanted_type) { |
| 7687 | | return ir_analyze_union_to_tag(ira, source_instr, value, wanted_type); |
| 7683 | return ir_analyze_union_to_tag(ira, scope, source_node, value, wanted_type); |
| 7688 | 7684 | } |
| 7689 | 7685 | } |
| 7690 | 7686 | |
| ... | ... | @@ -7693,7 +7689,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7693 | 7689 | if (is_tagged_union(wanted_type) && (actual_type->id == ZigTypeIdEnum || |
| 7694 | 7690 | actual_type->id == ZigTypeIdEnumLiteral)) |
| 7695 | 7691 | { |
| 7696 | | return ir_analyze_enum_to_union(ira, source_instr, value, wanted_type); |
| 7692 | return ir_analyze_enum_to_union(ira, scope, source_node, value, wanted_type); |
| 7697 | 7693 | } |
| 7698 | 7694 | |
| 7699 | 7695 | // cast from *T to *[1]T |
| ... | ... | @@ -7709,10 +7705,10 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7709 | 7705 | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && |
| 7710 | 7706 | (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile)) |
| 7711 | 7707 | { |
| 7712 | | if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->base.source_node))) |
| 7708 | if ((err = ir_cast_ptr_align(ira, scope, source_node, wanted_type, actual_type, value->source_node))) |
| 7713 | 7709 | return ira->codegen->invalid_inst_gen; |
| 7714 | 7710 | |
| 7715 | | return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type); |
| 7711 | return ir_analyze_ptr_to_array(ira, scope, source_node, value, wanted_type); |
| 7716 | 7712 | } |
| 7717 | 7713 | } |
| 7718 | 7714 | |
| ... | ... | @@ -7733,8 +7729,8 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7733 | 7729 | slice_ptr_type->data.pointer.sentinel)))) |
| 7734 | 7730 | { |
| 7735 | 7731 | TypeStructField *ptr_field = actual_type->data.structure.fields[slice_ptr_index]; |
| 7736 | | IrInstGen *slice_ptr = ir_analyze_struct_value_field_value(ira, source_instr, value, ptr_field); |
| 7737 | | return ir_implicit_cast2(ira, source_instr, slice_ptr, wanted_type); |
| 7732 | IrInstGen *slice_ptr = ir_analyze_struct_value_field_value(ira, scope, source_node, value, ptr_field); |
| 7733 | return ir_implicit_cast2(ira, scope, source_node, slice_ptr, wanted_type); |
| 7738 | 7734 | } |
| 7739 | 7735 | } |
| 7740 | 7736 | |
| ... | ... | @@ -7754,8 +7750,8 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7754 | 7750 | dest_ptr_type = wanted_type->data.maybe.child_type; |
| 7755 | 7751 | } |
| 7756 | 7752 | if (dest_ptr_type != nullptr) { |
| 7757 | | return ir_analyze_ptr_cast(ira, source_instr, value, source_instr, wanted_type, source_instr, true, |
| 7758 | | false); |
| 7753 | return ir_analyze_ptr_cast(ira, scope, source_node, value, source_node, |
| 7754 | wanted_type, source_node, true, false); |
| 7759 | 7755 | } |
| 7760 | 7756 | } |
| 7761 | 7757 | |
| ... | ... | @@ -7768,7 +7764,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7768 | 7764 | if ((err = type_has_bits2(ira->codegen, actual_type, &has_bits))) |
| 7769 | 7765 | return ira->codegen->invalid_inst_gen; |
| 7770 | 7766 | if (!has_bits) { |
| 7771 | | return ir_get_ref(ira, source_instr, value, false, false); |
| 7767 | return ir_get_ref(ira, scope, source_node, value, false, false); |
| 7772 | 7768 | } |
| 7773 | 7769 | } |
| 7774 | 7770 | |
| ... | ... | @@ -7778,7 +7774,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7778 | 7774 | types_match_const_cast_only(ira, wanted_type->data.array.child_type, |
| 7779 | 7775 | actual_type->data.vector.elem_type, source_node, false).id == ConstCastResultIdOk) |
| 7780 | 7776 | { |
| 7781 | | return ir_analyze_vector_to_array(ira, source_instr, value, wanted_type, nullptr); |
| 7777 | return ir_analyze_vector_to_array(ira, scope, source_node, value, wanted_type, nullptr); |
| 7782 | 7778 | } |
| 7783 | 7779 | |
| 7784 | 7780 | // cast from [N]T to @Vector(N, T) |
| ... | ... | @@ -7787,7 +7783,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7787 | 7783 | types_match_const_cast_only(ira, actual_type->data.array.child_type, |
| 7788 | 7784 | wanted_type->data.vector.elem_type, source_node, false).id == ConstCastResultIdOk) |
| 7789 | 7785 | { |
| 7790 | | return ir_analyze_array_to_vector(ira, source_instr, value, wanted_type); |
| 7786 | return ir_analyze_array_to_vector(ira, scope, source_node, value, wanted_type); |
| 7791 | 7787 | } |
| 7792 | 7788 | |
| 7793 | 7789 | // casting between C pointers and normal pointers |
| ... | ... | @@ -7797,14 +7793,15 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7797 | 7793 | actual_type->data.pointer.child_type, source_node, |
| 7798 | 7794 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 7799 | 7795 | { |
| 7800 | | return ir_analyze_ptr_cast(ira, source_instr, value, source_instr, wanted_type, source_instr, true, false); |
| 7796 | return ir_analyze_ptr_cast(ira, scope, source_node, value, source_node, |
| 7797 | wanted_type, source_node, true, false); |
| 7801 | 7798 | } |
| 7802 | 7799 | |
| 7803 | 7800 | // cast from integer to C pointer |
| 7804 | 7801 | if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenC && |
| 7805 | 7802 | (actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt)) |
| 7806 | 7803 | { |
| 7807 | | return ir_analyze_int_to_c_ptr(ira, source_instr, value, wanted_type); |
| 7804 | return ir_analyze_int_to_c_ptr(ira, scope, source_node, value, wanted_type); |
| 7808 | 7805 | } |
| 7809 | 7806 | |
| 7810 | 7807 | // cast from inferred struct type to array, union, or struct |
| ... | ... | @@ -7816,34 +7813,34 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7816 | 7813 | if (wanted_type->id == ZigTypeIdArray && (is_array_init || field_count == 0) && |
| 7817 | 7814 | wanted_type->data.array.len == field_count) |
| 7818 | 7815 | { |
| 7819 | | IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, value, true, false); |
| 7816 | IrInstGen *struct_ptr = ir_get_ref(ira, scope, source_node, value, true, false); |
| 7820 | 7817 | if (type_is_invalid(struct_ptr->value->type)) |
| 7821 | 7818 | return ira->codegen->invalid_inst_gen; |
| 7822 | 7819 | |
| 7823 | | IrInstGen *ptr = ir_analyze_struct_literal_to_array(ira, source_instr, struct_ptr, actual_type, wanted_type); |
| 7820 | IrInstGen *ptr = ir_analyze_struct_literal_to_array(ira, scope, source_node, struct_ptr, actual_type, wanted_type); |
| 7824 | 7821 | if (ptr->value->type->id != ZigTypeIdPointer) |
| 7825 | 7822 | return ptr; |
| 7826 | | return ir_get_deref(ira, source_instr, ptr, nullptr); |
| 7823 | return ir_get_deref(ira, scope, source_node, ptr, nullptr); |
| 7827 | 7824 | } else if (wanted_type->id == ZigTypeIdStruct && !is_slice(wanted_type) && |
| 7828 | 7825 | (!is_array_init || field_count == 0)) |
| 7829 | 7826 | { |
| 7830 | | IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, value, true, false); |
| 7827 | IrInstGen *struct_ptr = ir_get_ref(ira, scope, source_node, value, true, false); |
| 7831 | 7828 | if (type_is_invalid(struct_ptr->value->type)) |
| 7832 | 7829 | return ira->codegen->invalid_inst_gen; |
| 7833 | 7830 | |
| 7834 | | IrInstGen *ptr = ir_analyze_struct_literal_to_struct(ira, source_instr, struct_ptr, actual_type, wanted_type); |
| 7831 | IrInstGen *ptr = ir_analyze_struct_literal_to_struct(ira, scope, source_node, struct_ptr, actual_type, wanted_type); |
| 7835 | 7832 | if (ptr->value->type->id != ZigTypeIdPointer) |
| 7836 | 7833 | return ptr; |
| 7837 | | return ir_get_deref(ira, source_instr, ptr, nullptr); |
| 7834 | return ir_get_deref(ira, scope, source_node, ptr, nullptr); |
| 7838 | 7835 | } else if (wanted_type->id == ZigTypeIdUnion && !is_array_init && field_count == 1) { |
| 7839 | | IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, value, true, false); |
| 7836 | IrInstGen *struct_ptr = ir_get_ref(ira, scope, source_node, value, true, false); |
| 7840 | 7837 | if (type_is_invalid(struct_ptr->value->type)) |
| 7841 | 7838 | return ira->codegen->invalid_inst_gen; |
| 7842 | 7839 | |
| 7843 | | IrInstGen *ptr = ir_analyze_struct_literal_to_union(ira, source_instr, struct_ptr, actual_type, wanted_type); |
| 7840 | IrInstGen *ptr = ir_analyze_struct_literal_to_union(ira, scope, source_node, struct_ptr, actual_type, wanted_type); |
| 7844 | 7841 | if (ptr->value->type->id != ZigTypeIdPointer) |
| 7845 | 7842 | return ptr; |
| 7846 | | return ir_get_deref(ira, source_instr, ptr, nullptr); |
| 7843 | return ir_get_deref(ira, scope, source_node, ptr, nullptr); |
| 7847 | 7844 | } |
| 7848 | 7845 | } |
| 7849 | 7846 | |
| ... | ... | @@ -7862,22 +7859,22 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7862 | 7859 | if (wanted_child->id == ZigTypeIdArray && (is_array_init || field_count == 0) && |
| 7863 | 7860 | wanted_child->data.array.len == field_count && (const_ok || field_count == 0)) |
| 7864 | 7861 | { |
| 7865 | | IrInstGen *res = ir_analyze_struct_literal_to_array(ira, source_instr, value, anon_type, wanted_child); |
| 7862 | IrInstGen *res = ir_analyze_struct_literal_to_array(ira, scope, source_node, value, anon_type, wanted_child); |
| 7866 | 7863 | if (res->value->type->id == ZigTypeIdPointer) |
| 7867 | 7864 | return res; |
| 7868 | | return ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile); |
| 7865 | return ir_get_ref(ira, scope, source_node, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile); |
| 7869 | 7866 | } else if (wanted_child->id == ZigTypeIdStruct && !is_slice(wanted_type) && |
| 7870 | 7867 | (!is_array_init || field_count == 0) && const_ok) |
| 7871 | 7868 | { |
| 7872 | | IrInstGen *res = ir_analyze_struct_literal_to_struct(ira, source_instr, value, anon_type, wanted_child); |
| 7869 | IrInstGen *res = ir_analyze_struct_literal_to_struct(ira, scope, source_node, value, anon_type, wanted_child); |
| 7873 | 7870 | if (res->value->type->id == ZigTypeIdPointer) |
| 7874 | 7871 | return res; |
| 7875 | | return ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile); |
| 7872 | return ir_get_ref(ira, scope, source_node, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile); |
| 7876 | 7873 | } else if (wanted_child->id == ZigTypeIdUnion && !is_array_init && field_count == 1 && const_ok) { |
| 7877 | | IrInstGen *res = ir_analyze_struct_literal_to_union(ira, source_instr, value, anon_type, wanted_child); |
| 7874 | IrInstGen *res = ir_analyze_struct_literal_to_union(ira, scope, source_node, value, anon_type, wanted_child); |
| 7878 | 7875 | if (res->value->type->id == ZigTypeIdPointer) |
| 7879 | 7876 | return res; |
| 7880 | | return ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile); |
| 7877 | return ir_get_ref(ira, scope, source_node, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile); |
| 7881 | 7878 | } |
| 7882 | 7879 | } else if (is_slice(wanted_type) && (is_array_init || field_count == 0)) { |
| 7883 | 7880 | ZigType *slice_type = wanted_type->data.structure.fields[slice_ptr_index]->type_entry; |
| ... | ... | @@ -7886,49 +7883,49 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 7886 | 7883 | { |
| 7887 | 7884 | ZigType *slice_child_type = slice_type->data.pointer.child_type; |
| 7888 | 7885 | ZigType *slice_array_type = get_array_type(ira->codegen, slice_child_type, field_count, nullptr); |
| 7889 | | IrInstGen *res = ir_analyze_struct_literal_to_array(ira, source_instr, value, anon_type, slice_array_type); |
| 7886 | IrInstGen *res = ir_analyze_struct_literal_to_array(ira, scope, source_node, value, anon_type, slice_array_type); |
| 7890 | 7887 | if (type_is_invalid(res->value->type)) |
| 7891 | 7888 | return ira->codegen->invalid_inst_gen; |
| 7892 | 7889 | if (res->value->type->id != ZigTypeIdPointer) |
| 7893 | | res = ir_get_ref(ira, source_instr, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile); |
| 7890 | res = ir_get_ref(ira, scope, source_node, res, actual_type->data.pointer.is_const, actual_type->data.pointer.is_volatile); |
| 7894 | 7891 | |
| 7895 | | return ir_resolve_ptr_of_array_to_slice(ira, source_instr, res, wanted_type, nullptr); |
| 7892 | return ir_resolve_ptr_of_array_to_slice(ira, scope, source_node, res, wanted_type, nullptr); |
| 7896 | 7893 | } |
| 7897 | 7894 | } |
| 7898 | 7895 | } |
| 7899 | 7896 | |
| 7900 | 7897 | // cast from undefined to anything |
| 7901 | 7898 | if (actual_type->id == ZigTypeIdUndefined) { |
| 7902 | | return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type); |
| 7899 | return ir_analyze_undefined_to_anything(ira, scope, source_node, value, wanted_type); |
| 7903 | 7900 | } |
| 7904 | 7901 | |
| 7905 | 7902 | // T to ?U, where T implicitly casts to U |
| 7906 | 7903 | if (wanted_type->id == ZigTypeIdOptional && actual_type->id != ZigTypeIdOptional) { |
| 7907 | | IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type); |
| 7904 | IrInstGen *cast1 = ir_implicit_cast2(ira, scope, source_node, value, wanted_type->data.maybe.child_type); |
| 7908 | 7905 | if (type_is_invalid(cast1->value->type)) |
| 7909 | 7906 | return ira->codegen->invalid_inst_gen; |
| 7910 | | return ir_implicit_cast2(ira, source_instr, cast1, wanted_type); |
| 7907 | return ir_implicit_cast2(ira, scope, source_node, cast1, wanted_type); |
| 7911 | 7908 | } |
| 7912 | 7909 | |
| 7913 | 7910 | // T to E!U, where T implicitly casts to U |
| 7914 | 7911 | if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id != ZigTypeIdErrorUnion && |
| 7915 | 7912 | actual_type->id != ZigTypeIdErrorSet) |
| 7916 | 7913 | { |
| 7917 | | IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.error_union.payload_type); |
| 7914 | IrInstGen *cast1 = ir_implicit_cast2(ira, scope, source_node, value, wanted_type->data.error_union.payload_type); |
| 7918 | 7915 | if (type_is_invalid(cast1->value->type)) |
| 7919 | 7916 | return ira->codegen->invalid_inst_gen; |
| 7920 | | return ir_implicit_cast2(ira, source_instr, cast1, wanted_type); |
| 7917 | return ir_implicit_cast2(ira, scope, source_node, cast1, wanted_type); |
| 7921 | 7918 | } |
| 7922 | 7919 | |
| 7923 | | ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node, |
| 7920 | ErrorMsg *parent_msg = ir_add_error_node(ira, source_node, |
| 7924 | 7921 | buf_sprintf("expected type '%s', found '%s'", |
| 7925 | 7922 | buf_ptr(&wanted_type->name), |
| 7926 | 7923 | buf_ptr(&actual_type->name))); |
| 7927 | | report_recursive_error(ira, source_instr->source_node, &const_cast_result, parent_msg); |
| 7924 | report_recursive_error(ira, source_node, &const_cast_result, parent_msg); |
| 7928 | 7925 | return ira->codegen->invalid_inst_gen; |
| 7929 | 7926 | } |
| 7930 | 7927 | |
| 7931 | | static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr, |
| 7928 | static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 7932 | 7929 | IrInstGen *value, ZigType *expected_type) |
| 7933 | 7930 | { |
| 7934 | 7931 | assert(value); |
| ... | ... | @@ -7942,20 +7939,20 @@ static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr, |
| 7942 | 7939 | if (value->value->type->id == ZigTypeIdUnreachable) |
| 7943 | 7940 | return value; |
| 7944 | 7941 | |
| 7945 | | return ir_analyze_cast(ira, value_source_instr, expected_type, value); |
| 7942 | return ir_analyze_cast(ira, scope, source_node, expected_type, value); |
| 7946 | 7943 | } |
| 7947 | 7944 | |
| 7948 | 7945 | static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type) { |
| 7949 | | return ir_implicit_cast2(ira, &value->base, value, expected_type); |
| 7946 | return ir_implicit_cast2(ira, value->scope, value->source_node, value, expected_type); |
| 7950 | 7947 | } |
| 7951 | 7948 | |
| 7952 | 7949 | static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) { |
| 7953 | | ir_assert_gen(ptr->value->type->id == ZigTypeIdPointer, ptr); |
| 7950 | ir_assert(ptr->value->type->id == ZigTypeIdPointer, ptr); |
| 7954 | 7951 | ZigType *elem_type = ptr->value->type->data.pointer.child_type; |
| 7955 | 7952 | if (elem_type != g->builtin_types.entry_anytype) |
| 7956 | 7953 | return elem_type; |
| 7957 | 7954 | |
| 7958 | | if (ir_resolve_lazy(g, ptr->base.source_node, ptr->value)) |
| 7955 | if (ir_resolve_lazy(g, ptr->source_node, ptr->value)) |
| 7959 | 7956 | return g->builtin_types.entry_invalid; |
| 7960 | 7957 | |
| 7961 | 7958 | assert(value_is_comptime(ptr->value)); |
| ... | ... | @@ -7963,7 +7960,7 @@ static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) { |
| 7963 | 7960 | return pointee->type; |
| 7964 | 7961 | } |
| 7965 | 7962 | |
| 7966 | | static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *ptr, |
| 7963 | static IrInstGen *ir_get_deref(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *ptr, |
| 7967 | 7964 | ResultLoc *result_loc) |
| 7968 | 7965 | { |
| 7969 | 7966 | Error err; |
| ... | ... | @@ -7972,7 +7969,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns |
| 7972 | 7969 | return ira->codegen->invalid_inst_gen; |
| 7973 | 7970 | |
| 7974 | 7971 | if (ptr_type->id != ZigTypeIdPointer) { |
| 7975 | | ir_add_error_node(ira, source_instruction->source_node, |
| 7972 | ir_add_error_node(ira, source_node, |
| 7976 | 7973 | buf_sprintf("attempt to dereference non-pointer type '%s'", |
| 7977 | 7974 | buf_ptr(&ptr_type->name))); |
| 7978 | 7975 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -7986,7 +7983,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns |
| 7986 | 7983 | case OnePossibleValueInvalid: |
| 7987 | 7984 | return ira->codegen->invalid_inst_gen; |
| 7988 | 7985 | case OnePossibleValueYes: |
| 7989 | | return ir_const_move(ira, source_instruction, |
| 7986 | return ir_const_move(ira, scope, source_node, |
| 7990 | 7987 | get_the_one_possible_value(ira->codegen, child_type)); |
| 7991 | 7988 | case OnePossibleValueNo: |
| 7992 | 7989 | break; |
| ... | ... | @@ -7995,11 +7992,11 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns |
| 7995 | 7992 | if (ptr->value->special == ConstValSpecialUndef) { |
| 7996 | 7993 | // If we are in a TypeOf call, we return an undefined value instead of erroring |
| 7997 | 7994 | // since we know the type. |
| 7998 | | if (get_scope_typeof(source_instruction->scope)) { |
| 7999 | | return ir_const_undef(ira, source_instruction, child_type); |
| 7995 | if (get_scope_typeof(scope)) { |
| 7996 | return ir_const_undef(ira, scope, source_node, child_type); |
| 8000 | 7997 | } |
| 8001 | 7998 | |
| 8002 | | ir_add_error(ira, &ptr->base, buf_sprintf("attempt to dereference undefined value")); |
| 7999 | ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value")); |
| 8003 | 8000 | return ira->codegen->invalid_inst_gen; |
| 8004 | 8001 | } |
| 8005 | 8002 | if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| ... | ... | @@ -8008,9 +8005,9 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns |
| 8008 | 8005 | child_type = pointee->type; |
| 8009 | 8006 | } |
| 8010 | 8007 | if (pointee->special != ConstValSpecialRuntime) { |
| 8011 | | IrInstGen *result = ir_const(ira, source_instruction, child_type); |
| 8008 | IrInstGen *result = ir_const(ira, scope, source_node, child_type); |
| 8012 | 8009 | |
| 8013 | | if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value, |
| 8010 | if ((err = ir_read_const_ptr(ira, ira->codegen, source_node, result->value, |
| 8014 | 8011 | ptr->value))) |
| 8015 | 8012 | { |
| 8016 | 8013 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -8038,12 +8035,12 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns |
| 8038 | 8035 | if (ptr_type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) { |
| 8039 | 8036 | if (ptr->id == IrInstGenIdElemPtr) { |
| 8040 | 8037 | IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr; |
| 8041 | | IrInstGen *vector_loaded = ir_get_deref(ira, &elem_ptr->array_ptr->base, |
| 8042 | | elem_ptr->array_ptr, nullptr); |
| 8038 | IrInstGen *vector_loaded = ir_get_deref(ira, elem_ptr->array_ptr->scope, |
| 8039 | elem_ptr->array_ptr->source_node, elem_ptr->array_ptr, nullptr); |
| 8043 | 8040 | IrInstGen *elem_index = elem_ptr->elem_index; |
| 8044 | | return ir_build_vector_extract_elem(ira, source_instruction, vector_loaded, elem_index); |
| 8041 | return ir_build_vector_extract_elem(ira, scope, source_node, vector_loaded, elem_index); |
| 8045 | 8042 | } |
| 8046 | | ir_add_error(ira, &ptr->base, |
| 8043 | ir_add_error(ira, ptr, |
| 8047 | 8044 | buf_sprintf("unable to determine vector element index of type '%s'", buf_ptr(&ptr_type->name))); |
| 8048 | 8045 | return ira->codegen->invalid_inst_gen; |
| 8049 | 8046 | } |
| ... | ... | @@ -8051,7 +8048,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns |
| 8051 | 8048 | IrInstGen *result_loc_inst; |
| 8052 | 8049 | if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(ira->codegen, child_type)) { |
| 8053 | 8050 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 8054 | | result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true, true); |
| 8051 | result_loc_inst = ir_resolve_result(ira, ira->suspend_source_instr, result_loc, child_type, nullptr, true, true); |
| 8055 | 8052 | if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) { |
| 8056 | 8053 | return result_loc_inst; |
| 8057 | 8054 | } |
| ... | ... | @@ -8059,7 +8056,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns |
| 8059 | 8056 | result_loc_inst = nullptr; |
| 8060 | 8057 | } |
| 8061 | 8058 | |
| 8062 | | return ir_build_load_ptr_gen(ira, source_instruction, ptr, child_type, result_loc_inst); |
| 8059 | return ir_build_load_ptr_gen(ira, scope, source_node, ptr, child_type, result_loc_inst); |
| 8063 | 8060 | } |
| 8064 | 8061 | |
| 8065 | 8062 | static bool ir_resolve_const_align(CodeGen *codegen, Stage1Air *exec, AstNode *source_node, |
| ... | ... | @@ -8110,7 +8107,7 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstGen *value, ZigType *elem_typ |
| 8110 | 8107 | if (type_is_invalid(casted_value->value->type)) |
| 8111 | 8108 | return false; |
| 8112 | 8109 | |
| 8113 | | return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->base.source_node, |
| 8110 | return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->source_node, |
| 8114 | 8111 | casted_value->value, out); |
| 8115 | 8112 | } |
| 8116 | 8113 | |
| ... | ... | @@ -8279,7 +8276,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstGen *value) { |
| 8279 | 8276 | size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i; |
| 8280 | 8277 | ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index]; |
| 8281 | 8278 | if (char_val->special == ConstValSpecialUndef) { |
| 8282 | | ir_add_error(ira, &casted_value->base, buf_sprintf("use of undefined value")); |
| 8279 | ir_add_error(ira, casted_value, buf_sprintf("use of undefined value")); |
| 8283 | 8280 | return nullptr; |
| 8284 | 8281 | } |
| 8285 | 8282 | uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint); |
| ... | ... | @@ -8301,13 +8298,13 @@ static IrInstGen *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira |
| 8301 | 8298 | ira->src_implicit_return_type_list.append(value); |
| 8302 | 8299 | } |
| 8303 | 8300 | |
| 8304 | | return ir_const_void(ira, &instruction->base.base); |
| 8301 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 8305 | 8302 | } |
| 8306 | 8303 | |
| 8307 | 8304 | static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn *instruction) { |
| 8308 | 8305 | if (instruction->operand == nullptr) { |
| 8309 | 8306 | // result location mechanism took care of it. |
| 8310 | | IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, nullptr); |
| 8307 | IrInstGen *result = ir_build_return_gen(ira, instruction->base.scope, instruction->base.source_node, nullptr); |
| 8311 | 8308 | return ir_finish_anal(ira, result); |
| 8312 | 8309 | } |
| 8313 | 8310 | |
| ... | ... | @@ -8330,7 +8327,7 @@ static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn |
| 8330 | 8327 | handle_is_ptr(ira->codegen, ira->explicit_return_type)) |
| 8331 | 8328 | { |
| 8332 | 8329 | // result location mechanism took care of it. |
| 8333 | | IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, nullptr); |
| 8330 | IrInstGen *result = ir_build_return_gen(ira, instruction->base.scope, instruction->base.source_node, nullptr); |
| 8334 | 8331 | return ir_finish_anal(ira, result); |
| 8335 | 8332 | } |
| 8336 | 8333 | |
| ... | ... | @@ -8338,16 +8335,17 @@ static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn |
| 8338 | 8335 | casted_operand->value->type->id == ZigTypeIdPointer && |
| 8339 | 8336 | casted_operand->value->data.rh_ptr == RuntimeHintPtrStack) |
| 8340 | 8337 | { |
| 8341 | | ir_add_error(ira, &instruction->operand->base, buf_sprintf("function returns address of local variable")); |
| 8338 | ir_add_error_node(ira, instruction->operand->source_node, |
| 8339 | buf_sprintf("function returns address of local variable")); |
| 8342 | 8340 | return ir_unreach_error(ira); |
| 8343 | 8341 | } |
| 8344 | 8342 | |
| 8345 | | IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, casted_operand); |
| 8343 | IrInstGen *result = ir_build_return_gen(ira, instruction->base.scope, instruction->base.source_node, casted_operand); |
| 8346 | 8344 | return ir_finish_anal(ira, result); |
| 8347 | 8345 | } |
| 8348 | 8346 | |
| 8349 | 8347 | static IrInstGen *ir_analyze_instruction_const(IrAnalyze *ira, IrInstSrcConst *instruction) { |
| 8350 | | return ir_const_move(ira, &instruction->base.base, instruction->value); |
| 8348 | return ir_const_move(ira, instruction->base.scope, instruction->base.source_node, instruction->value); |
| 8351 | 8349 | } |
| 8352 | 8350 | |
| 8353 | 8351 | static IrInstGen *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) { |
| ... | ... | @@ -8388,11 +8386,13 @@ static IrInstGen *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstSrcBinOp *bin_op_ |
| 8388 | 8386 | } else { |
| 8389 | 8387 | zig_unreachable(); |
| 8390 | 8388 | } |
| 8391 | | return ir_const_bool(ira, &bin_op_instruction->base.base, result_bool); |
| 8389 | return ir_const_bool(ira, bin_op_instruction->base.scope, |
| 8390 | bin_op_instruction->base.source_node, result_bool); |
| 8392 | 8391 | } |
| 8393 | 8392 | |
| 8394 | | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, bool_type, |
| 8395 | | bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 8393 | return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope, |
| 8394 | bin_op_instruction->base.source_node, bool_type, bin_op_instruction->op_id, |
| 8395 | casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 8396 | 8396 | } |
| 8397 | 8397 | |
| 8398 | 8398 | static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) { |
| ... | ... | @@ -8444,12 +8444,12 @@ static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) { |
| 8444 | 8444 | } |
| 8445 | 8445 | |
| 8446 | 8446 | static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type, |
| 8447 | | ZigValue *op1_val, ZigValue *op2_val, IrInst *source_instr, IrBinOp op_id, |
| 8447 | ZigValue *op1_val, ZigValue *op2_val, Scope *scope, AstNode *source_node, IrBinOp op_id, |
| 8448 | 8448 | bool one_possible_value) |
| 8449 | 8449 | { |
| 8450 | 8450 | if (op1_val->special == ConstValSpecialUndef || |
| 8451 | 8451 | op2_val->special == ConstValSpecialUndef) |
| 8452 | | return ir_const_undef(ira, source_instr, resolved_type); |
| 8452 | return ir_const_undef(ira, scope, source_node, resolved_type); |
| 8453 | 8453 | if (resolved_type->id == ZigTypeIdPointer && op_id != IrBinOpCmpEq && op_id != IrBinOpCmpNotEq) { |
| 8454 | 8454 | if ((op1_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr || |
| 8455 | 8455 | op1_val->data.x_ptr.special == ConstPtrSpecialNull) && |
| ... | ... | @@ -8469,7 +8469,7 @@ static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type, |
| 8469 | 8469 | cmp_result = CmpEQ; |
| 8470 | 8470 | } |
| 8471 | 8471 | bool answer = resolve_cmp_op_id(op_id, cmp_result); |
| 8472 | | return ir_const_bool(ira, source_instr, answer); |
| 8472 | return ir_const_bool(ira, scope, source_node, answer); |
| 8473 | 8473 | } |
| 8474 | 8474 | } else { |
| 8475 | 8475 | bool are_equal = one_possible_value || const_values_equal(ira->codegen, op1_val, op2_val); |
| ... | ... | @@ -8481,12 +8481,12 @@ static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type, |
| 8481 | 8481 | } else { |
| 8482 | 8482 | zig_unreachable(); |
| 8483 | 8483 | } |
| 8484 | | return ir_const_bool(ira, source_instr, answer); |
| 8484 | return ir_const_bool(ira, scope, source_node, answer); |
| 8485 | 8485 | } |
| 8486 | 8486 | zig_unreachable(); |
| 8487 | 8487 | } |
| 8488 | 8488 | |
| 8489 | | static IrInstGen *ir_try_evaluate_bin_op_cmp_const(IrAnalyze *ira, IrInst *source_instr, IrInstGen *op1, IrInstGen *op2, |
| 8489 | static IrInstGen *ir_try_evaluate_bin_op_cmp_const(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *op1, IrInstGen *op2, |
| 8490 | 8490 | ZigType *resolved_type, IrBinOp op_id) |
| 8491 | 8491 | { |
| 8492 | 8492 | assert(op1->value->type == resolved_type && op2->value->type == resolved_type); |
| ... | ... | @@ -8510,8 +8510,8 @@ static IrInstGen *ir_try_evaluate_bin_op_cmp_const(IrAnalyze *ira, IrInst *sourc |
| 8510 | 8510 | if (op2_val == nullptr) |
| 8511 | 8511 | return ira->codegen->invalid_inst_gen; |
| 8512 | 8512 | if (resolved_type->id != ZigTypeIdVector) |
| 8513 | | return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, source_instr, op_id, one_possible_value); |
| 8514 | | IrInstGen *result = ir_const(ira, source_instr, |
| 8513 | return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, scope, source_node, op_id, one_possible_value); |
| 8514 | IrInstGen *result = ir_const(ira, scope, source_node, |
| 8515 | 8515 | get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool)); |
| 8516 | 8516 | result->value->data.x_array.data.s_none.elements = |
| 8517 | 8517 | ira->codegen->pass1_arena->allocate<ZigValue>(resolved_type->data.vector.len); |
| ... | ... | @@ -8521,7 +8521,7 @@ static IrInstGen *ir_try_evaluate_bin_op_cmp_const(IrAnalyze *ira, IrInst *sourc |
| 8521 | 8521 | IrInstGen *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type, |
| 8522 | 8522 | &op1_val->data.x_array.data.s_none.elements[i], |
| 8523 | 8523 | &op2_val->data.x_array.data.s_none.elements[i], |
| 8524 | | source_instr, op_id, one_possible_value); |
| 8524 | scope, source_node, op_id, one_possible_value); |
| 8525 | 8525 | copy_const_val(ira->codegen, &result->value->data.x_array.data.s_none.elements[i], cur_res->value); |
| 8526 | 8526 | } |
| 8527 | 8527 | return result; |
| ... | ... | @@ -8608,7 +8608,7 @@ static Error lazy_cmp_zero(CodeGen *codegen, AstNode *source_node, ZigValue *val |
| 8608 | 8608 | zig_unreachable(); |
| 8609 | 8609 | } |
| 8610 | 8610 | |
| 8611 | | static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr, |
| 8611 | static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 8612 | 8612 | ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val) |
| 8613 | 8613 | { |
| 8614 | 8614 | Error err; |
| ... | ... | @@ -8616,12 +8616,12 @@ static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr, |
| 8616 | 8616 | // Before resolving the values, we special case comparisons against zero. These can often |
| 8617 | 8617 | // be done without resolving lazy values, preventing potential dependency loops. |
| 8618 | 8618 | Cmp op1_cmp_zero; |
| 8619 | | if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op1_val, &op1_cmp_zero))) { |
| 8619 | if ((err = lazy_cmp_zero(ira->codegen, source_node, op1_val, &op1_cmp_zero))) { |
| 8620 | 8620 | if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally; |
| 8621 | 8621 | return ira->codegen->trace_err; |
| 8622 | 8622 | } |
| 8623 | 8623 | Cmp op2_cmp_zero; |
| 8624 | | if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op2_val, &op2_cmp_zero))) { |
| 8624 | if ((err = lazy_cmp_zero(ira->codegen, source_node, op2_val, &op2_cmp_zero))) { |
| 8625 | 8625 | if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally; |
| 8626 | 8626 | return ira->codegen->trace_err; |
| 8627 | 8627 | } |
| ... | ... | @@ -8658,12 +8658,12 @@ static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr, |
| 8658 | 8658 | } |
| 8659 | 8659 | never_mind_just_calculate_it_normally: |
| 8660 | 8660 | |
| 8661 | | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_instr->source_node, |
| 8661 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_node, |
| 8662 | 8662 | op1_val, UndefOk))) |
| 8663 | 8663 | { |
| 8664 | 8664 | return ira->codegen->trace_err; |
| 8665 | 8665 | } |
| 8666 | | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_instr->source_node, |
| 8666 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_node, |
| 8667 | 8667 | op2_val, UndefOk))) |
| 8668 | 8668 | { |
| 8669 | 8669 | return ira->codegen->trace_err; |
| ... | ... | @@ -8686,12 +8686,12 @@ never_mind_just_calculate_it_normally: |
| 8686 | 8686 | return nullptr; |
| 8687 | 8687 | } |
| 8688 | 8688 | if (op1_val->type->id == ZigTypeIdComptimeFloat) { |
| 8689 | | IrInstGen *tmp = ir_const_noval(ira, source_instr); |
| 8689 | IrInstGen *tmp = ir_const_noval(ira, scope, source_node); |
| 8690 | 8690 | tmp->value = op1_val; |
| 8691 | 8691 | IrInstGen *casted = ir_implicit_cast(ira, tmp, op2_val->type); |
| 8692 | 8692 | op1_val = casted->value; |
| 8693 | 8693 | } else if (op2_val->type->id == ZigTypeIdComptimeFloat) { |
| 8694 | | IrInstGen *tmp = ir_const_noval(ira, source_instr); |
| 8694 | IrInstGen *tmp = ir_const_noval(ira, scope, source_node); |
| 8695 | 8695 | tmp->value = op2_val; |
| 8696 | 8696 | IrInstGen *casted = ir_implicit_cast(ira, tmp, op1_val->type); |
| 8697 | 8697 | op2_val = casted->value; |
| ... | ... | @@ -8746,7 +8746,7 @@ never_mind_just_calculate_it_normally: |
| 8746 | 8746 | return nullptr; |
| 8747 | 8747 | } |
| 8748 | 8748 | |
| 8749 | | static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_instr, |
| 8749 | static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 8750 | 8750 | IrInstGen *op1, IrInstGen *op2, IrBinOp op_id) |
| 8751 | 8751 | { |
| 8752 | 8752 | Error err; |
| ... | ... | @@ -8757,7 +8757,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 8757 | 8757 | ZigType *op2_scalar_type = op2->value->type; |
| 8758 | 8758 | if (op1->value->type->id == ZigTypeIdVector && op2->value->type->id == ZigTypeIdVector) { |
| 8759 | 8759 | if (op1->value->type->data.vector.len != op2->value->type->data.vector.len) { |
| 8760 | | ir_add_error(ira, source_instr, |
| 8760 | ir_add_error_node(ira, source_node, |
| 8761 | 8761 | buf_sprintf("vector length mismatch: %" PRIu64 " and %" PRIu64, |
| 8762 | 8762 | op1->value->type->data.vector.len, op2->value->type->data.vector.len)); |
| 8763 | 8763 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -8766,7 +8766,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 8766 | 8766 | op1_scalar_type = op1->value->type->data.vector.elem_type; |
| 8767 | 8767 | op2_scalar_type = op2->value->type->data.vector.elem_type; |
| 8768 | 8768 | } else if (op1->value->type->id == ZigTypeIdVector || op2->value->type->id == ZigTypeIdVector) { |
| 8769 | | ir_add_error(ira, source_instr, |
| 8769 | ir_add_error_node(ira, source_node, |
| 8770 | 8770 | buf_sprintf("mixed scalar and vector operands to comparison operator: '%s' and '%s'", |
| 8771 | 8771 | buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name))); |
| 8772 | 8772 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -8796,14 +8796,14 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 8796 | 8796 | } |
| 8797 | 8797 | Cmp op1_cmp_zero; |
| 8798 | 8798 | bool have_op1_cmp_zero = false; |
| 8799 | | if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op1->value, &op1_cmp_zero))) { |
| 8799 | if ((err = lazy_cmp_zero(ira->codegen, source_node, op1->value, &op1_cmp_zero))) { |
| 8800 | 8800 | if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen; |
| 8801 | 8801 | } else { |
| 8802 | 8802 | have_op1_cmp_zero = true; |
| 8803 | 8803 | } |
| 8804 | 8804 | Cmp op2_cmp_zero; |
| 8805 | 8805 | bool have_op2_cmp_zero = false; |
| 8806 | | if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op2->value, &op2_cmp_zero))) { |
| 8806 | if ((err = lazy_cmp_zero(ira->codegen, source_node, op2->value, &op2_cmp_zero))) { |
| 8807 | 8807 | if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen; |
| 8808 | 8808 | } else { |
| 8809 | 8809 | have_op2_cmp_zero = true; |
| ... | ... | @@ -8811,7 +8811,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 8811 | 8811 | if (((opv_op1 || instr_is_comptime(op1)) && (opv_op2 || instr_is_comptime(op2))) || |
| 8812 | 8812 | (have_op1_cmp_zero && have_op2_cmp_zero)) |
| 8813 | 8813 | { |
| 8814 | | IrInstGen *result_instruction = ir_const(ira, source_instr, result_type); |
| 8814 | IrInstGen *result_instruction = ir_const(ira, scope, source_node, result_type); |
| 8815 | 8815 | ZigValue *out_val = result_instruction->value; |
| 8816 | 8816 | if (result_type->id == ZigTypeIdVector) { |
| 8817 | 8817 | size_t len = result_type->data.vector.len; |
| ... | ... | @@ -8824,10 +8824,10 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 8824 | 8824 | ZigValue *scalar_op2_val = &op2->value->data.x_array.data.s_none.elements[i]; |
| 8825 | 8825 | ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 8826 | 8826 | assert(scalar_out_val->type == scalar_result_type); |
| 8827 | | ErrorMsg *msg = ir_eval_bin_op_cmp_scalar(ira, source_instr, |
| 8827 | ErrorMsg *msg = ir_eval_bin_op_cmp_scalar(ira, scope, source_node, |
| 8828 | 8828 | scalar_op1_val, op_id, scalar_op2_val, scalar_out_val); |
| 8829 | 8829 | if (msg != nullptr) { |
| 8830 | | add_error_note(ira->codegen, msg, source_instr->source_node, |
| 8830 | add_error_note(ira->codegen, msg, source_node, |
| 8831 | 8831 | buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i)); |
| 8832 | 8832 | return ira->codegen->invalid_inst_gen; |
| 8833 | 8833 | } |
| ... | ... | @@ -8835,7 +8835,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 8835 | 8835 | out_val->type = result_type; |
| 8836 | 8836 | out_val->special = ConstValSpecialStatic; |
| 8837 | 8837 | } else { |
| 8838 | | if (ir_eval_bin_op_cmp_scalar(ira, source_instr, op1->value, op_id, |
| 8838 | if (ir_eval_bin_op_cmp_scalar(ira, scope, source_node, op1->value, op_id, |
| 8839 | 8839 | op2->value, out_val) != nullptr) |
| 8840 | 8840 | { |
| 8841 | 8841 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -8853,9 +8853,9 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 8853 | 8853 | // 0 > unsigned_x // false |
| 8854 | 8854 | switch (op_id) { |
| 8855 | 8855 | case IrBinOpCmpLessOrEq: |
| 8856 | | return ir_const_bool(ira, source_instr, true); |
| 8856 | return ir_const_bool(ira, scope, source_node, true); |
| 8857 | 8857 | case IrBinOpCmpGreaterThan: |
| 8858 | | return ir_const_bool(ira, source_instr, false); |
| 8858 | return ir_const_bool(ira, scope, source_node, false); |
| 8859 | 8859 | default: |
| 8860 | 8860 | break; |
| 8861 | 8861 | } |
| ... | ... | @@ -8870,11 +8870,11 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 8870 | 8870 | case IrBinOpCmpNotEq: |
| 8871 | 8871 | case IrBinOpCmpLessOrEq: |
| 8872 | 8872 | case IrBinOpCmpLessThan: |
| 8873 | | return ir_const_bool(ira, source_instr, true); |
| 8873 | return ir_const_bool(ira, scope, source_node, true); |
| 8874 | 8874 | case IrBinOpCmpEq: |
| 8875 | 8875 | case IrBinOpCmpGreaterOrEq: |
| 8876 | 8876 | case IrBinOpCmpGreaterThan: |
| 8877 | | return ir_const_bool(ira, source_instr, false); |
| 8877 | return ir_const_bool(ira, scope, source_node, false); |
| 8878 | 8878 | default: |
| 8879 | 8879 | break; |
| 8880 | 8880 | } |
| ... | ... | @@ -8886,9 +8886,9 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 8886 | 8886 | // unsigned_x >= 0 // true |
| 8887 | 8887 | switch (op_id) { |
| 8888 | 8888 | case IrBinOpCmpLessThan: |
| 8889 | | return ir_const_bool(ira, source_instr, false); |
| 8889 | return ir_const_bool(ira, scope, source_node, false); |
| 8890 | 8890 | case IrBinOpCmpGreaterOrEq: |
| 8891 | | return ir_const_bool(ira, source_instr, true); |
| 8891 | return ir_const_bool(ira, scope, source_node, true); |
| 8892 | 8892 | default: |
| 8893 | 8893 | break; |
| 8894 | 8894 | } |
| ... | ... | @@ -8903,11 +8903,11 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 8903 | 8903 | case IrBinOpCmpNotEq: |
| 8904 | 8904 | case IrBinOpCmpGreaterOrEq: |
| 8905 | 8905 | case IrBinOpCmpGreaterThan: |
| 8906 | | return ir_const_bool(ira, source_instr, true); |
| 8906 | return ir_const_bool(ira, scope, source_node, true); |
| 8907 | 8907 | case IrBinOpCmpEq: |
| 8908 | 8908 | case IrBinOpCmpLessThan: |
| 8909 | 8909 | case IrBinOpCmpLessOrEq: |
| 8910 | | return ir_const_bool(ira, source_instr, false); |
| 8910 | return ir_const_bool(ira, scope, source_node, false); |
| 8911 | 8911 | default: |
| 8912 | 8912 | break; |
| 8913 | 8913 | } |
| ... | ... | @@ -8936,7 +8936,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 8936 | 8936 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type); |
| 8937 | 8937 | if (type_is_invalid(casted_op1->value->type) || type_is_invalid(casted_op2->value->type)) |
| 8938 | 8938 | return ira->codegen->invalid_inst_gen; |
| 8939 | | return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true); |
| 8939 | return ir_build_bin_op_gen(ira, scope, source_node, result_type, op_id, casted_op1, casted_op2, true); |
| 8940 | 8940 | } |
| 8941 | 8941 | |
| 8942 | 8942 | // For mixed unsigned integer sizes, implicit cast both operands to the larger integer. |
| ... | ... | @@ -8967,7 +8967,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 8967 | 8967 | if (op1_val == nullptr) |
| 8968 | 8968 | return ira->codegen->invalid_inst_gen; |
| 8969 | 8969 | if (op1_val->special == ConstValSpecialUndef) |
| 8970 | | return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool); |
| 8970 | return ir_const_undef(ira, scope, source_node, ira->codegen->builtin_types.entry_bool); |
| 8971 | 8971 | bool is_unsigned; |
| 8972 | 8972 | if (op1_is_float) { |
| 8973 | 8973 | BigInt bigint = {}; |
| ... | ... | @@ -8975,7 +8975,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 8975 | 8975 | Cmp zcmp = float_cmp_zero(op1_val); |
| 8976 | 8976 | if (float_has_fraction(op1_val)) { |
| 8977 | 8977 | if (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq) { |
| 8978 | | return ir_const_bool(ira, source_instr, op_id == IrBinOpCmpNotEq); |
| 8978 | return ir_const_bool(ira, scope, source_node, op_id == IrBinOpCmpNotEq); |
| 8979 | 8979 | } |
| 8980 | 8980 | if (zcmp == CmpLT) { |
| 8981 | 8981 | bigint_decr(&bigint); |
| ... | ... | @@ -8993,10 +8993,10 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 8993 | 8993 | op1_bits += 1; |
| 8994 | 8994 | } |
| 8995 | 8995 | } else if (op1_is_float) { |
| 8996 | | ir_assert(op1_scalar_type->id == ZigTypeIdFloat, source_instr); |
| 8996 | src_assert(op1_scalar_type->id == ZigTypeIdFloat, source_node); |
| 8997 | 8997 | dest_float_type = op1_scalar_type; |
| 8998 | 8998 | } else { |
| 8999 | | ir_assert(op1_scalar_type->id == ZigTypeIdInt, source_instr); |
| 8999 | src_assert(op1_scalar_type->id == ZigTypeIdInt, source_node); |
| 9000 | 9000 | op1_bits = op1_scalar_type->data.integral.bit_count; |
| 9001 | 9001 | if (!op1_scalar_type->data.integral.is_signed && dest_int_is_signed) { |
| 9002 | 9002 | op1_bits += 1; |
| ... | ... | @@ -9008,7 +9008,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 9008 | 9008 | if (op2_val == nullptr) |
| 9009 | 9009 | return ira->codegen->invalid_inst_gen; |
| 9010 | 9010 | if (op2_val->special == ConstValSpecialUndef) |
| 9011 | | return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool); |
| 9011 | return ir_const_undef(ira, scope, source_node, ira->codegen->builtin_types.entry_bool); |
| 9012 | 9012 | bool is_unsigned; |
| 9013 | 9013 | if (op2_is_float) { |
| 9014 | 9014 | BigInt bigint = {}; |
| ... | ... | @@ -9016,7 +9016,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 9016 | 9016 | Cmp zcmp = float_cmp_zero(op2_val); |
| 9017 | 9017 | if (float_has_fraction(op2_val)) { |
| 9018 | 9018 | if (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq) { |
| 9019 | | return ir_const_bool(ira, source_instr, op_id == IrBinOpCmpNotEq); |
| 9019 | return ir_const_bool(ira, scope, source_node, op_id == IrBinOpCmpNotEq); |
| 9020 | 9020 | } |
| 9021 | 9021 | if (zcmp == CmpLT) { |
| 9022 | 9022 | bigint_decr(&bigint); |
| ... | ... | @@ -9034,10 +9034,10 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 9034 | 9034 | op2_bits += 1; |
| 9035 | 9035 | } |
| 9036 | 9036 | } else if (op2_is_float) { |
| 9037 | | ir_assert(op2_scalar_type->id == ZigTypeIdFloat, source_instr); |
| 9037 | src_assert(op2_scalar_type->id == ZigTypeIdFloat, source_node); |
| 9038 | 9038 | dest_float_type = op2_scalar_type; |
| 9039 | 9039 | } else { |
| 9040 | | ir_assert(op2_scalar_type->id == ZigTypeIdInt, source_instr); |
| 9040 | src_assert(op2_scalar_type->id == ZigTypeIdInt, source_node); |
| 9041 | 9041 | op2_bits = op2_scalar_type->data.integral.bit_count; |
| 9042 | 9042 | if (!op2_scalar_type->data.integral.is_signed && dest_int_is_signed) { |
| 9043 | 9043 | op2_bits += 1; |
| ... | ... | @@ -9055,7 +9055,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 9055 | 9055 | IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type); |
| 9056 | 9056 | if (type_is_invalid(casted_op2->value->type)) |
| 9057 | 9057 | return ira->codegen->invalid_inst_gen; |
| 9058 | | return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true); |
| 9058 | return ir_build_bin_op_gen(ira, scope, source_node, result_type, op_id, casted_op1, casted_op2, true); |
| 9059 | 9059 | } |
| 9060 | 9060 | |
| 9061 | 9061 | static bool type_is_self_comparable(ZigType *ty, bool is_equality_cmp) { |
| ... | ... | @@ -9106,7 +9106,7 @@ static bool type_is_self_comparable(ZigType *ty, bool is_equality_cmp) { |
| 9106 | 9106 | zig_unreachable(); |
| 9107 | 9107 | } |
| 9108 | 9108 | |
| 9109 | | static IrInstGen *ir_try_evaluate_cmp_optional_non_optional_const(IrAnalyze *ira, IrInst *source_instr, ZigType *child_type, |
| 9109 | static IrInstGen *ir_try_evaluate_cmp_optional_non_optional_const(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *child_type, |
| 9110 | 9110 | IrInstGen *optional, IrInstGen *non_optional, IrBinOp op_id) |
| 9111 | 9111 | { |
| 9112 | 9112 | assert(optional->value->type->id == ZigTypeIdOptional); |
| ... | ... | @@ -9126,22 +9126,22 @@ static IrInstGen *ir_try_evaluate_cmp_optional_non_optional_const(IrAnalyze *ira |
| 9126 | 9126 | } |
| 9127 | 9127 | |
| 9128 | 9128 | if (!optional_value_is_null(optional_val)) { |
| 9129 | | IrInstGen *optional_unwrapped = ir_analyze_optional_value_payload_value(ira, source_instr, optional, false); |
| 9129 | IrInstGen *optional_unwrapped = ir_analyze_optional_value_payload_value(ira, scope, source_node, optional, false); |
| 9130 | 9130 | if (type_is_invalid(optional_unwrapped->value->type)) { |
| 9131 | 9131 | return ira->codegen->invalid_inst_gen; |
| 9132 | 9132 | } |
| 9133 | 9133 | |
| 9134 | | IrInstGen *ret = ir_try_evaluate_bin_op_cmp_const(ira, source_instr, optional_unwrapped, non_optional, child_type, op_id); |
| 9134 | IrInstGen *ret = ir_try_evaluate_bin_op_cmp_const(ira, scope, source_node, optional_unwrapped, non_optional, child_type, op_id); |
| 9135 | 9135 | assert(ret != nullptr); |
| 9136 | 9136 | return ret; |
| 9137 | 9137 | } |
| 9138 | | return ir_const_bool(ira, source_instr, (op_id != IrBinOpCmpEq)); |
| 9138 | return ir_const_bool(ira, scope, source_node, (op_id != IrBinOpCmpEq)); |
| 9139 | 9139 | } else { |
| 9140 | 9140 | return nullptr; |
| 9141 | 9141 | } |
| 9142 | 9142 | } |
| 9143 | 9143 | |
| 9144 | | static IrInstGen *ir_evaluate_cmp_optional_non_optional(IrAnalyze *ira, IrInst *source_instr, ZigType *child_type, |
| 9144 | static IrInstGen *ir_evaluate_cmp_optional_non_optional(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *child_type, |
| 9145 | 9145 | IrInstGen *optional, IrInstGen *non_optional, IrBinOp op_id) |
| 9146 | 9146 | { |
| 9147 | 9147 | assert(optional->value->type->id == ZigTypeIdOptional); |
| ... | ... | @@ -9152,26 +9152,26 @@ static IrInstGen *ir_evaluate_cmp_optional_non_optional(IrAnalyze *ira, IrInst * |
| 9152 | 9152 | ZigType *result_type = ira->codegen->builtin_types.entry_bool; |
| 9153 | 9153 | ir_append_basic_block_gen(&ira->new_irb, ira->new_irb.current_basic_block); |
| 9154 | 9154 | |
| 9155 | | IrBasicBlockGen *null_block = ir_create_basic_block_gen(ira, source_instr->scope, "CmpOptionalNonOptionalOptionalNull"); |
| 9156 | | IrBasicBlockGen *non_null_block = ir_create_basic_block_gen(ira, source_instr->scope, "CmpOptionalNonOptionalOptionalNotNull"); |
| 9157 | | IrBasicBlockGen *end_block = ir_create_basic_block_gen(ira, source_instr->scope, "CmpOptionalNonOptionalEnd"); |
| 9155 | IrBasicBlockGen *null_block = ir_create_basic_block_gen(ira, scope, "CmpOptionalNonOptionalOptionalNull"); |
| 9156 | IrBasicBlockGen *non_null_block = ir_create_basic_block_gen(ira, scope, "CmpOptionalNonOptionalOptionalNotNull"); |
| 9157 | IrBasicBlockGen *end_block = ir_create_basic_block_gen(ira, scope, "CmpOptionalNonOptionalEnd"); |
| 9158 | 9158 | |
| 9159 | | IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, source_instr, optional); |
| 9160 | | ir_build_cond_br_gen(ira, source_instr, is_non_null, non_null_block, null_block); |
| 9159 | IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, scope, source_node, optional); |
| 9160 | ir_build_cond_br_gen(ira, scope, source_node, is_non_null, non_null_block, null_block); |
| 9161 | 9161 | |
| 9162 | 9162 | ir_set_cursor_at_end_and_append_block_gen(&ira->new_irb, non_null_block); |
| 9163 | | IrInstGen *optional_unwrapped = ir_analyze_optional_value_payload_value(ira, source_instr, optional, false); |
| 9163 | IrInstGen *optional_unwrapped = ir_analyze_optional_value_payload_value(ira, scope, source_node, optional, false); |
| 9164 | 9164 | if (type_is_invalid(optional_unwrapped->value->type)) { |
| 9165 | 9165 | return ira->codegen->invalid_inst_gen; |
| 9166 | 9166 | } |
| 9167 | | IrInstGen *non_null_cmp_result = ir_build_bin_op_gen(ira, source_instr, result_type, op_id, |
| 9167 | IrInstGen *non_null_cmp_result = ir_build_bin_op_gen(ira, scope, source_node, result_type, op_id, |
| 9168 | 9168 | optional_unwrapped, non_optional, false); // safety check unnecessary for comparison operators |
| 9169 | | ir_build_br_gen(ira, source_instr, end_block); |
| 9169 | ir_build_br_gen(ira, scope, source_node, end_block); |
| 9170 | 9170 | |
| 9171 | 9171 | |
| 9172 | 9172 | ir_set_cursor_at_end_and_append_block_gen(&ira->new_irb, null_block); |
| 9173 | | IrInstGen *null_result = ir_const_bool(ira, source_instr, (op_id != IrBinOpCmpEq)); |
| 9174 | | ir_build_br_gen(ira, source_instr, end_block); |
| 9173 | IrInstGen *null_result = ir_const_bool(ira, scope, source_node, (op_id != IrBinOpCmpEq)); |
| 9174 | ir_build_br_gen(ira, scope, source_node, end_block); |
| 9175 | 9175 | |
| 9176 | 9176 | ir_set_cursor_at_end_gen(&ira->new_irb, end_block); |
| 9177 | 9177 | int incoming_count = 2; |
| ... | ... | @@ -9182,10 +9182,10 @@ static IrInstGen *ir_evaluate_cmp_optional_non_optional(IrAnalyze *ira, IrInst * |
| 9182 | 9182 | incoming_values[0] = null_result; |
| 9183 | 9183 | incoming_values[1] = non_null_cmp_result; |
| 9184 | 9184 | |
| 9185 | | return ir_build_phi_gen(ira, source_instr, incoming_count, incoming_blocks, incoming_values, result_type); |
| 9185 | return ir_build_phi_gen(ira, scope, source_node, incoming_count, incoming_blocks, incoming_values, result_type); |
| 9186 | 9186 | } |
| 9187 | 9187 | |
| 9188 | | static IrInstGen *ir_analyze_cmp_optional_non_optional(IrAnalyze *ira, IrInst *source_instr, |
| 9188 | static IrInstGen *ir_analyze_cmp_optional_non_optional(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 9189 | 9189 | IrInstGen *op1, IrInstGen *op2, IrInstGen *optional, IrBinOp op_id) |
| 9190 | 9190 | { |
| 9191 | 9191 | assert(op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq); |
| ... | ... | @@ -9204,22 +9204,22 @@ static IrInstGen *ir_analyze_cmp_optional_non_optional(IrAnalyze *ira, IrInst *s |
| 9204 | 9204 | ZigType *child_type = optional->value->type->data.maybe.child_type; |
| 9205 | 9205 | bool child_type_matches = (child_type == non_optional->value->type); |
| 9206 | 9206 | if (!child_type_matches || !type_is_self_comparable(child_type, true)) { |
| 9207 | | ErrorMsg *msg = ir_add_error_node(ira, source_instr->source_node, buf_sprintf("cannot compare types '%s' and '%s'", |
| 9207 | ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("cannot compare types '%s' and '%s'", |
| 9208 | 9208 | buf_ptr(&op1->value->type->name), |
| 9209 | 9209 | buf_ptr(&op2->value->type->name))); |
| 9210 | 9210 | |
| 9211 | 9211 | if (!child_type_matches) { |
| 9212 | 9212 | if (non_optional->value->type->id == ZigTypeIdOptional) { |
| 9213 | | add_error_note(ira->codegen, msg, source_instr->source_node, buf_sprintf( |
| 9213 | add_error_note(ira->codegen, msg, source_node, buf_sprintf( |
| 9214 | 9214 | "optional to optional comparison is only supported for optional pointer types")); |
| 9215 | 9215 | } else { |
| 9216 | | add_error_note(ira->codegen, msg, source_instr->source_node, |
| 9216 | add_error_note(ira->codegen, msg, source_node, |
| 9217 | 9217 | buf_sprintf("optional child type '%s' must be the same as non-optional type '%s'", |
| 9218 | 9218 | buf_ptr(&child_type->name), |
| 9219 | 9219 | buf_ptr(&non_optional->value->type->name))); |
| 9220 | 9220 | } |
| 9221 | 9221 | } else { |
| 9222 | | add_error_note(ira->codegen, msg, source_instr->source_node, |
| 9222 | add_error_note(ira->codegen, msg, source_node, |
| 9223 | 9223 | buf_sprintf("operator not supported for type '%s'", |
| 9224 | 9224 | buf_ptr(&child_type->name))); |
| 9225 | 9225 | } |
| ... | ... | @@ -9227,17 +9227,17 @@ static IrInstGen *ir_analyze_cmp_optional_non_optional(IrAnalyze *ira, IrInst *s |
| 9227 | 9227 | } |
| 9228 | 9228 | |
| 9229 | 9229 | if (child_type->id == ZigTypeIdVector) { |
| 9230 | | ir_add_error_node(ira, source_instr->source_node, buf_sprintf("TODO add comparison of optional vector")); |
| 9230 | ir_add_error_node(ira, source_node, buf_sprintf("TODO add comparison of optional vector")); |
| 9231 | 9231 | return ira->codegen->invalid_inst_gen; |
| 9232 | 9232 | } |
| 9233 | 9233 | |
| 9234 | | if (IrInstGen *const_result = ir_try_evaluate_cmp_optional_non_optional_const(ira, source_instr, child_type, |
| 9234 | if (IrInstGen *const_result = ir_try_evaluate_cmp_optional_non_optional_const(ira, scope, source_node, child_type, |
| 9235 | 9235 | optional, non_optional, op_id)) |
| 9236 | 9236 | { |
| 9237 | 9237 | return const_result; |
| 9238 | 9238 | } |
| 9239 | 9239 | |
| 9240 | | return ir_evaluate_cmp_optional_non_optional(ira, source_instr, child_type, optional, non_optional, op_id); |
| 9240 | return ir_evaluate_cmp_optional_non_optional(ira, scope, source_node, child_type, optional, non_optional, op_id); |
| 9241 | 9241 | } |
| 9242 | 9242 | |
| 9243 | 9243 | static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) { |
| ... | ... | @@ -9249,12 +9249,13 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i |
| 9249 | 9249 | if (type_is_invalid(op2->value->type)) |
| 9250 | 9250 | return ira->codegen->invalid_inst_gen; |
| 9251 | 9251 | |
| 9252 | | AstNode *source_node = bin_op_instruction->base.base.source_node; |
| 9252 | AstNode *source_node = bin_op_instruction->base.source_node; |
| 9253 | 9253 | |
| 9254 | 9254 | IrBinOp op_id = bin_op_instruction->op_id; |
| 9255 | 9255 | bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq); |
| 9256 | 9256 | if (is_equality_cmp && op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdNull) { |
| 9257 | | return ir_const_bool(ira, &bin_op_instruction->base.base, (op_id == IrBinOpCmpEq)); |
| 9257 | return ir_const_bool(ira, bin_op_instruction->base.scope, |
| 9258 | bin_op_instruction->base.source_node, (op_id == IrBinOpCmpEq)); |
| 9258 | 9259 | } else if (is_equality_cmp && |
| 9259 | 9260 | ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) || |
| 9260 | 9261 | (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional))) |
| ... | ... | @@ -9273,13 +9274,16 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i |
| 9273 | 9274 | return ira->codegen->invalid_inst_gen; |
| 9274 | 9275 | bool is_null = optional_value_is_null(maybe_val); |
| 9275 | 9276 | bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null; |
| 9276 | | return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result); |
| 9277 | return ir_const_bool(ira, bin_op_instruction->base.scope, |
| 9278 | bin_op_instruction->base.source_node, bool_result); |
| 9277 | 9279 | } |
| 9278 | 9280 | |
| 9279 | | IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, maybe_op); |
| 9281 | IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, bin_op_instruction->base.scope, |
| 9282 | bin_op_instruction->base.source_node, maybe_op); |
| 9280 | 9283 | |
| 9281 | 9284 | if (op_id == IrBinOpCmpEq) { |
| 9282 | | return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null); |
| 9285 | return ir_build_bool_not_gen(ira, bin_op_instruction->base.scope, |
| 9286 | bin_op_instruction->base.source_node, is_non_null); |
| 9283 | 9287 | } else { |
| 9284 | 9288 | return is_non_null; |
| 9285 | 9289 | } |
| ... | ... | @@ -9302,28 +9306,28 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i |
| 9302 | 9306 | if (!c_ptr_val) |
| 9303 | 9307 | return ira->codegen->invalid_inst_gen; |
| 9304 | 9308 | if (c_ptr_val->special == ConstValSpecialUndef) |
| 9305 | | return ir_const_undef(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool); |
| 9309 | return ir_const_undef(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, ira->codegen->builtin_types.entry_bool); |
| 9306 | 9310 | bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull || |
| 9307 | 9311 | (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr && |
| 9308 | 9312 | c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0); |
| 9309 | 9313 | bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null; |
| 9310 | | return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result); |
| 9314 | return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, bool_result); |
| 9311 | 9315 | } |
| 9312 | | IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, c_ptr_op); |
| 9316 | IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, c_ptr_op); |
| 9313 | 9317 | |
| 9314 | 9318 | if (op_id == IrBinOpCmpEq) { |
| 9315 | | return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null); |
| 9319 | return ir_build_bool_not_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, is_non_null); |
| 9316 | 9320 | } else { |
| 9317 | 9321 | return is_non_null; |
| 9318 | 9322 | } |
| 9319 | 9323 | } else if (is_equality_cmp && |
| 9320 | 9324 | (op1->value->type->id == ZigTypeIdOptional && get_src_ptr_type(op1->value->type) == nullptr)) |
| 9321 | 9325 | { |
| 9322 | | return ir_analyze_cmp_optional_non_optional(ira, &bin_op_instruction->base.base, op1, op2, op1, op_id); |
| 9326 | return ir_analyze_cmp_optional_non_optional(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1, op2, op1, op_id); |
| 9323 | 9327 | } else if(is_equality_cmp && |
| 9324 | 9328 | (op2->value->type->id == ZigTypeIdOptional && get_src_ptr_type(op2->value->type) == nullptr)) |
| 9325 | 9329 | { |
| 9326 | | return ir_analyze_cmp_optional_non_optional(ira, &bin_op_instruction->base.base, op1, op2, op2, op_id); |
| 9330 | return ir_analyze_cmp_optional_non_optional(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1, op2, op2, op_id); |
| 9327 | 9331 | } else if (op1->value->type->id == ZigTypeIdNull || op2->value->type->id == ZigTypeIdNull) { |
| 9328 | 9332 | ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type; |
| 9329 | 9333 | ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null", |
| ... | ... | @@ -9369,10 +9373,10 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i |
| 9369 | 9373 | Cmp cmp_result = bigint_cmp(&const_union_val->data.x_union.tag, &const_enum_val->data.x_enum_tag); |
| 9370 | 9374 | bool bool_result = (op_id == IrBinOpCmpEq) ? cmp_result == CmpEQ : cmp_result != CmpEQ; |
| 9371 | 9375 | |
| 9372 | | return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result); |
| 9376 | return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, bool_result); |
| 9373 | 9377 | } |
| 9374 | 9378 | |
| 9375 | | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool, |
| 9379 | return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, ira->codegen->builtin_types.entry_bool, |
| 9376 | 9380 | op_id, casted_union, casted_val, bin_op_instruction->safety_check_on); |
| 9377 | 9381 | } |
| 9378 | 9382 | |
| ... | ... | @@ -9404,7 +9408,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i |
| 9404 | 9408 | } else { |
| 9405 | 9409 | zig_unreachable(); |
| 9406 | 9410 | } |
| 9407 | | return ir_const_bool(ira, &bin_op_instruction->base.base, answer); |
| 9411 | return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, answer); |
| 9408 | 9412 | } |
| 9409 | 9413 | |
| 9410 | 9414 | if (!type_is_global_error_set(intersect_type)) { |
| ... | ... | @@ -9424,7 +9428,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i |
| 9424 | 9428 | } else { |
| 9425 | 9429 | zig_unreachable(); |
| 9426 | 9430 | } |
| 9427 | | return ir_const_bool(ira, &bin_op_instruction->base.base, answer); |
| 9431 | return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, answer); |
| 9428 | 9432 | } |
| 9429 | 9433 | } |
| 9430 | 9434 | |
| ... | ... | @@ -9446,10 +9450,10 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i |
| 9446 | 9450 | zig_unreachable(); |
| 9447 | 9451 | } |
| 9448 | 9452 | |
| 9449 | | return ir_const_bool(ira, &bin_op_instruction->base.base, answer); |
| 9453 | return ir_const_bool(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, answer); |
| 9450 | 9454 | } |
| 9451 | 9455 | |
| 9452 | | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool, |
| 9456 | return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, ira->codegen->builtin_types.entry_bool, |
| 9453 | 9457 | op_id, op1, op2, bin_op_instruction->safety_check_on); |
| 9454 | 9458 | } |
| 9455 | 9459 | |
| ... | ... | @@ -9457,7 +9461,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i |
| 9457 | 9461 | // This operation allows any combination of integer and float types, regardless of the |
| 9458 | 9462 | // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for |
| 9459 | 9463 | // numeric types. |
| 9460 | | return ir_analyze_bin_op_cmp_numeric(ira, &bin_op_instruction->base.base, op1, op2, op_id); |
| 9464 | return ir_analyze_bin_op_cmp_numeric(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1, op2, op_id); |
| 9461 | 9465 | } |
| 9462 | 9466 | |
| 9463 | 9467 | IrInstGen *instructions[] = {op1, op2}; |
| ... | ... | @@ -9481,7 +9485,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i |
| 9481 | 9485 | if (type_is_invalid(casted_op2->value->type)) |
| 9482 | 9486 | return ira->codegen->invalid_inst_gen; |
| 9483 | 9487 | |
| 9484 | | IrInstGen *resolve_const_result = ir_try_evaluate_bin_op_cmp_const(ira, &bin_op_instruction->base.base, casted_op1, |
| 9488 | IrInstGen *resolve_const_result = ir_try_evaluate_bin_op_cmp_const(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, casted_op1, |
| 9485 | 9489 | casted_op2, resolved_type, op_id); |
| 9486 | 9490 | if (resolve_const_result != nullptr) { |
| 9487 | 9491 | return resolve_const_result; |
| ... | ... | @@ -9490,11 +9494,11 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i |
| 9490 | 9494 | ZigType *res_type = (resolved_type->id == ZigTypeIdVector) ? |
| 9491 | 9495 | get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool) : |
| 9492 | 9496 | ira->codegen->builtin_types.entry_bool; |
| 9493 | | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, res_type, |
| 9497 | return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, res_type, |
| 9494 | 9498 | op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 9495 | 9499 | } |
| 9496 | 9500 | |
| 9497 | | static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry, |
| 9501 | static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *type_entry, |
| 9498 | 9502 | ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val) |
| 9499 | 9503 | { |
| 9500 | 9504 | bool is_int; |
| ... | ... | @@ -9517,10 +9521,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi |
| 9517 | 9521 | if ((op_id == IrBinOpDivUnspecified || op_id == IrBinOpRemRem || op_id == IrBinOpRemMod || |
| 9518 | 9522 | op_id == IrBinOpDivTrunc || op_id == IrBinOpDivFloor) && op2_zcmp == CmpEQ) |
| 9519 | 9523 | { |
| 9520 | | return ir_add_error(ira, source_instr, buf_sprintf("division by zero")); |
| 9524 | return ir_add_error_node(ira, source_node, buf_sprintf("division by zero")); |
| 9521 | 9525 | } |
| 9522 | 9526 | if ((op_id == IrBinOpRemRem || op_id == IrBinOpRemMod) && op2_zcmp == CmpLT) { |
| 9523 | | return ir_add_error(ira, source_instr, buf_sprintf("negative denominator")); |
| 9527 | return ir_add_error_node(ira, source_node, buf_sprintf("negative denominator")); |
| 9524 | 9528 | } |
| 9525 | 9529 | |
| 9526 | 9530 | switch (op_id) { |
| ... | ... | @@ -9565,7 +9569,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi |
| 9565 | 9569 | BigInt orig_bigint; |
| 9566 | 9570 | bigint_shl(&orig_bigint, &out_val->data.x_bigint, &op2_val->data.x_bigint); |
| 9567 | 9571 | if (bigint_cmp(&op1_val->data.x_bigint, &orig_bigint) != CmpEQ) { |
| 9568 | | return ir_add_error(ira, source_instr, buf_sprintf("exact shift shifted out 1 bits")); |
| 9572 | return ir_add_error_node(ira, source_node, buf_sprintf("exact shift shifted out 1 bits")); |
| 9569 | 9573 | } |
| 9570 | 9574 | break; |
| 9571 | 9575 | } |
| ... | ... | @@ -9633,14 +9637,14 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi |
| 9633 | 9637 | BigInt remainder; |
| 9634 | 9638 | bigint_rem(&remainder, &op1_val->data.x_bigint, &op2_val->data.x_bigint); |
| 9635 | 9639 | if (bigint_cmp_zero(&remainder) != CmpEQ) { |
| 9636 | | return ir_add_error(ira, source_instr, buf_sprintf("exact division had a remainder")); |
| 9640 | return ir_add_error_node(ira, source_node, buf_sprintf("exact division had a remainder")); |
| 9637 | 9641 | } |
| 9638 | 9642 | } else { |
| 9639 | 9643 | float_div_trunc(out_val, op1_val, op2_val); |
| 9640 | 9644 | ZigValue remainder = {}; |
| 9641 | 9645 | float_rem(&remainder, op1_val, op2_val); |
| 9642 | 9646 | if (float_cmp_zero(&remainder) != CmpEQ) { |
| 9643 | | return ir_add_error(ira, source_instr, buf_sprintf("exact division had a remainder")); |
| 9647 | return ir_add_error_node(ira, source_node, buf_sprintf("exact division had a remainder")); |
| 9644 | 9648 | } |
| 9645 | 9649 | } |
| 9646 | 9650 | break; |
| ... | ... | @@ -9664,7 +9668,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi |
| 9664 | 9668 | if (!bigint_fits_in_bits(&out_val->data.x_bigint, type_entry->data.integral.bit_count, |
| 9665 | 9669 | type_entry->data.integral.is_signed)) |
| 9666 | 9670 | { |
| 9667 | | return ir_add_error(ira, source_instr, buf_sprintf("operation caused overflow")); |
| 9671 | return ir_add_error_node(ira, source_node, buf_sprintf("operation caused overflow")); |
| 9668 | 9672 | } |
| 9669 | 9673 | } |
| 9670 | 9674 | |
| ... | ... | @@ -9674,10 +9678,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, Zi |
| 9674 | 9678 | } |
| 9675 | 9679 | |
| 9676 | 9680 | // This works on operands that have already been checked to be comptime known. |
| 9677 | | static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr, |
| 9681 | static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 9678 | 9682 | ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val) |
| 9679 | 9683 | { |
| 9680 | | IrInstGen *result_instruction = ir_const(ira, source_instr, type_entry); |
| 9684 | IrInstGen *result_instruction = ir_const(ira, scope, source_node, type_entry); |
| 9681 | 9685 | ZigValue *out_val = result_instruction->value; |
| 9682 | 9686 | if (type_entry->id == ZigTypeIdVector) { |
| 9683 | 9687 | expand_undef_array(ira->codegen, op1_val); |
| ... | ... | @@ -9692,10 +9696,10 @@ static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr, |
| 9692 | 9696 | ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 9693 | 9697 | assert(scalar_op1_val->type == scalar_type); |
| 9694 | 9698 | assert(scalar_out_val->type == scalar_type); |
| 9695 | | ErrorMsg *msg = ir_eval_math_op_scalar(ira, source_instr, scalar_type, |
| 9699 | ErrorMsg *msg = ir_eval_math_op_scalar(ira, scope, source_node, scalar_type, |
| 9696 | 9700 | scalar_op1_val, op_id, scalar_op2_val, scalar_out_val); |
| 9697 | 9701 | if (msg != nullptr) { |
| 9698 | | add_error_note(ira->codegen, msg, source_instr->source_node, |
| 9702 | add_error_note(ira->codegen, msg, source_node, |
| 9699 | 9703 | buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i)); |
| 9700 | 9704 | return ira->codegen->invalid_inst_gen; |
| 9701 | 9705 | } |
| ... | ... | @@ -9703,7 +9707,7 @@ static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr, |
| 9703 | 9707 | out_val->type = type_entry; |
| 9704 | 9708 | out_val->special = ConstValSpecialStatic; |
| 9705 | 9709 | } else { |
| 9706 | | if (ir_eval_math_op_scalar(ira, source_instr, type_entry, op1_val, op_id, op2_val, out_val) != nullptr) { |
| 9710 | if (ir_eval_math_op_scalar(ira, scope, source_node, type_entry, op1_val, op_id, op2_val, out_val) != nullptr) { |
| 9707 | 9711 | return ira->codegen->invalid_inst_gen; |
| 9708 | 9712 | } |
| 9709 | 9713 | } |
| ... | ... | @@ -9723,14 +9727,14 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in |
| 9723 | 9727 | ZigType *op2_type = op2->value->type; |
| 9724 | 9728 | |
| 9725 | 9729 | if (op1_type->id == ZigTypeIdVector && op2_type->id != ZigTypeIdVector) { |
| 9726 | | ir_add_error(ira, &bin_op_instruction->op1->base, |
| 9730 | ir_add_error_node(ira, bin_op_instruction->op1->source_node, |
| 9727 | 9731 | buf_sprintf("bit shifting operation expected vector type, found '%s'", |
| 9728 | 9732 | buf_ptr(&op2_type->name))); |
| 9729 | 9733 | return ira->codegen->invalid_inst_gen; |
| 9730 | 9734 | } |
| 9731 | 9735 | |
| 9732 | 9736 | if (op1_type->id != ZigTypeIdVector && op2_type->id == ZigTypeIdVector) { |
| 9733 | | ir_add_error(ira, &bin_op_instruction->op1->base, |
| 9737 | ir_add_error_node(ira, bin_op_instruction->op1->source_node, |
| 9734 | 9738 | buf_sprintf("bit shifting operation expected vector type, found '%s'", |
| 9735 | 9739 | buf_ptr(&op1_type->name))); |
| 9736 | 9740 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -9742,14 +9746,14 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in |
| 9742 | 9746 | op2_type->data.vector.elem_type : op2_type; |
| 9743 | 9747 | |
| 9744 | 9748 | if (op1_scalar_type->id != ZigTypeIdInt && op1_scalar_type->id != ZigTypeIdComptimeInt) { |
| 9745 | | ir_add_error(ira, &bin_op_instruction->op1->base, |
| 9749 | ir_add_error_node(ira, bin_op_instruction->op1->source_node, |
| 9746 | 9750 | buf_sprintf("bit shifting operation expected integer type, found '%s'", |
| 9747 | 9751 | buf_ptr(&op1_scalar_type->name))); |
| 9748 | 9752 | return ira->codegen->invalid_inst_gen; |
| 9749 | 9753 | } |
| 9750 | 9754 | |
| 9751 | 9755 | if (op2_scalar_type->id != ZigTypeIdInt && op2_scalar_type->id != ZigTypeIdComptimeInt) { |
| 9752 | | ir_add_error(ira, &bin_op_instruction->op2->base, |
| 9756 | ir_add_error_node(ira, bin_op_instruction->op2->source_node, |
| 9753 | 9757 | buf_sprintf("shift amount has to be an integer type, but found '%s'", |
| 9754 | 9758 | buf_ptr(&op2_scalar_type->name))); |
| 9755 | 9759 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -9766,7 +9770,7 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in |
| 9766 | 9770 | } |
| 9767 | 9771 | |
| 9768 | 9772 | if (!instr_is_comptime(op2)) { |
| 9769 | | ir_add_error(ira, &bin_op_instruction->base.base, |
| 9773 | ir_add_error_node(ira, bin_op_instruction->base.source_node, |
| 9770 | 9774 | buf_sprintf("LHS of shift must be a fixed-width integer type, or RHS must be compile-time known")); |
| 9771 | 9775 | return ira->codegen->invalid_inst_gen; |
| 9772 | 9776 | } |
| ... | ... | @@ -9778,7 +9782,7 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in |
| 9778 | 9782 | if (op2_val->data.x_bigint.is_negative) { |
| 9779 | 9783 | Buf *val_buf = buf_alloc(); |
| 9780 | 9784 | bigint_append_buf(val_buf, &op2_val->data.x_bigint, 10); |
| 9781 | | ir_add_error(ira, &casted_op2->base, |
| 9785 | ir_add_error(ira, casted_op2, |
| 9782 | 9786 | buf_sprintf("shift by negative value %s", buf_ptr(val_buf))); |
| 9783 | 9787 | return ira->codegen->invalid_inst_gen; |
| 9784 | 9788 | } |
| ... | ... | @@ -9806,10 +9810,10 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in |
| 9806 | 9810 | init_const_usize(ira->codegen, &bit_count_value, bit_count); |
| 9807 | 9811 | |
| 9808 | 9812 | if (!value_cmp_numeric_val_all(op2_val, CmpLT, &bit_count_value)) { |
| 9809 | | ErrorMsg* msg = ir_add_error(ira, |
| 9810 | | &bin_op_instruction->base.base, |
| 9813 | ErrorMsg* msg = ir_add_error_node(ira, |
| 9814 | bin_op_instruction->base.source_node, |
| 9811 | 9815 | buf_sprintf("RHS of shift is too large for LHS type")); |
| 9812 | | add_error_note(ira->codegen, msg, op1->base.source_node, |
| 9816 | add_error_note(ira->codegen, msg, op1->source_node, |
| 9813 | 9817 | buf_sprintf("type %s has only %u bits", |
| 9814 | 9818 | buf_ptr(&op1->value->type->name), bit_count)); |
| 9815 | 9819 | |
| ... | ... | @@ -9825,7 +9829,7 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in |
| 9825 | 9829 | return ira->codegen->invalid_inst_gen; |
| 9826 | 9830 | |
| 9827 | 9831 | if (value_cmp_numeric_val_all(op2_val, CmpEQ, nullptr)) |
| 9828 | | return ir_analyze_cast(ira, &bin_op_instruction->base.base, op1->value->type, op1); |
| 9832 | return ir_analyze_cast(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1->value->type, op1); |
| 9829 | 9833 | } |
| 9830 | 9834 | |
| 9831 | 9835 | if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) { |
| ... | ... | @@ -9837,10 +9841,10 @@ static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_in |
| 9837 | 9841 | if (op2_val == nullptr) |
| 9838 | 9842 | return ira->codegen->invalid_inst_gen; |
| 9839 | 9843 | |
| 9840 | | return ir_analyze_math_op(ira, &bin_op_instruction->base.base, op1_type, op1_val, op_id, op2_val); |
| 9844 | return ir_analyze_math_op(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1_type, op1_val, op_id, op2_val); |
| 9841 | 9845 | } |
| 9842 | 9846 | |
| 9843 | | return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, op1->value->type, |
| 9847 | return ir_build_bin_op_gen(ira, bin_op_instruction->base.scope, bin_op_instruction->base.source_node, op1->value->type, |
| 9844 | 9848 | op_id, op1, casted_op2, bin_op_instruction->safety_check_on); |
| 9845 | 9849 | } |
| 9846 | 9850 | |
| ... | ... | @@ -10006,14 +10010,14 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc |
| 10006 | 10010 | if (op1_val == nullptr) |
| 10007 | 10011 | return ira->codegen->invalid_inst_gen; |
| 10008 | 10012 | if (op1_val->special == ConstValSpecialUndef) |
| 10009 | | return ir_const_undef(ira, &instruction->base.base, op1->value->type); |
| 10013 | return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, op1->value->type); |
| 10010 | 10014 | } |
| 10011 | 10015 | if (instr_is_comptime(casted_op2)) { |
| 10012 | 10016 | op2_val = ir_resolve_const(ira, casted_op2, UndefOk); |
| 10013 | 10017 | if (op2_val == nullptr) |
| 10014 | 10018 | return ira->codegen->invalid_inst_gen; |
| 10015 | 10019 | if (op2_val->special == ConstValSpecialUndef) |
| 10016 | | return ir_const_undef(ira, &instruction->base.base, op1->value->type); |
| 10020 | return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, op1->value->type); |
| 10017 | 10021 | } |
| 10018 | 10022 | |
| 10019 | 10023 | ZigType *elem_type = op1->value->type->data.pointer.child_type; |
| ... | ... | @@ -10069,18 +10073,18 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc |
| 10069 | 10073 | } else { |
| 10070 | 10074 | zig_unreachable(); |
| 10071 | 10075 | } |
| 10072 | | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 10076 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type); |
| 10073 | 10077 | result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 10074 | 10078 | result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 10075 | 10079 | result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr; |
| 10076 | 10080 | return result; |
| 10077 | 10081 | } |
| 10078 | 10082 | |
| 10079 | | return ir_build_bin_op_gen(ira, &instruction->base.base, result_type, op_id, op1, casted_op2, true); |
| 10083 | return ir_build_bin_op_gen(ira, instruction->base.scope, instruction->base.source_node, result_type, op_id, op1, casted_op2, true); |
| 10080 | 10084 | } |
| 10081 | 10085 | |
| 10082 | 10086 | IrInstGen *instructions[] = {op1, op2}; |
| 10083 | | ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.base.source_node, nullptr, instructions, 2); |
| 10087 | ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.source_node, nullptr, instructions, 2); |
| 10084 | 10088 | if (type_is_invalid(resolved_type)) |
| 10085 | 10089 | return ira->codegen->invalid_inst_gen; |
| 10086 | 10090 | |
| ... | ... | @@ -10091,7 +10095,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc |
| 10091 | 10095 | bool is_float = scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat; |
| 10092 | 10096 | |
| 10093 | 10097 | if (!is_int && !(is_float && ok_float_op(op_id))) { |
| 10094 | | AstNode *source_node = instruction->base.base.source_node; |
| 10098 | AstNode *source_node = instruction->base.source_node; |
| 10095 | 10099 | ir_add_error_node(ira, source_node, |
| 10096 | 10100 | buf_sprintf("invalid operands to binary expression: '%s' and '%s'", |
| 10097 | 10101 | buf_ptr(&op1->value->type->name), |
| ... | ... | @@ -10144,17 +10148,17 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc |
| 10144 | 10148 | // division function ambiguity problem. |
| 10145 | 10149 | ok = true; |
| 10146 | 10150 | } else { |
| 10147 | | IrInstGen *trunc_val = ir_analyze_math_op(ira, &instruction->base.base, resolved_type, |
| 10151 | IrInstGen *trunc_val = ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type, |
| 10148 | 10152 | op1_val, IrBinOpDivTrunc, op2_val); |
| 10149 | 10153 | if (type_is_invalid(trunc_val->value->type)) |
| 10150 | 10154 | return ira->codegen->invalid_inst_gen; |
| 10151 | 10155 | |
| 10152 | | IrInstGen *floor_val = ir_analyze_math_op(ira, &instruction->base.base, resolved_type, |
| 10156 | IrInstGen *floor_val = ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type, |
| 10153 | 10157 | op1_val, IrBinOpDivFloor, op2_val); |
| 10154 | 10158 | if (type_is_invalid(floor_val->value->type)) |
| 10155 | 10159 | return ira->codegen->invalid_inst_gen; |
| 10156 | 10160 | |
| 10157 | | IrInstGen *cmp_val = ir_analyze_bin_op_cmp_numeric(ira, &instruction->base.base, |
| 10161 | IrInstGen *cmp_val = ir_analyze_bin_op_cmp_numeric(ira, instruction->base.scope, instruction->base.source_node, |
| 10158 | 10162 | trunc_val, floor_val, IrBinOpCmpEq); |
| 10159 | 10163 | if (type_is_invalid(cmp_val->value->type)) |
| 10160 | 10164 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -10165,7 +10169,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc |
| 10165 | 10169 | } |
| 10166 | 10170 | |
| 10167 | 10171 | if (!ok) { |
| 10168 | | ir_add_error(ira, &instruction->base.base, |
| 10172 | ir_add_error_node(ira, instruction->base.source_node, |
| 10169 | 10173 | buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact", |
| 10170 | 10174 | buf_ptr(&op1->value->type->name), |
| 10171 | 10175 | buf_ptr(&op2->value->type->name))); |
| ... | ... | @@ -10183,17 +10187,17 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc |
| 10183 | 10187 | // division function ambiguity problem. |
| 10184 | 10188 | ok = true; |
| 10185 | 10189 | } else { |
| 10186 | | IrInstGen *rem_val = ir_analyze_math_op(ira, &instruction->base.base, resolved_type, |
| 10190 | IrInstGen *rem_val = ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type, |
| 10187 | 10191 | op1_val, IrBinOpRemRem, op2_val); |
| 10188 | 10192 | if (type_is_invalid(rem_val->value->type)) |
| 10189 | 10193 | return ira->codegen->invalid_inst_gen; |
| 10190 | 10194 | |
| 10191 | | IrInstGen *mod_val = ir_analyze_math_op(ira, &instruction->base.base, resolved_type, |
| 10195 | IrInstGen *mod_val = ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type, |
| 10192 | 10196 | op1_val, IrBinOpRemMod, op2_val); |
| 10193 | 10197 | if (type_is_invalid(mod_val->value->type)) |
| 10194 | 10198 | return ira->codegen->invalid_inst_gen; |
| 10195 | 10199 | |
| 10196 | | IrInstGen *cmp_val = ir_analyze_bin_op_cmp_numeric(ira, &instruction->base.base, |
| 10200 | IrInstGen *cmp_val = ir_analyze_bin_op_cmp_numeric(ira, instruction->base.scope, instruction->base.source_node, |
| 10197 | 10201 | rem_val, mod_val, IrBinOpCmpEq); |
| 10198 | 10202 | if (type_is_invalid(cmp_val->value->type)) |
| 10199 | 10203 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -10204,7 +10208,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc |
| 10204 | 10208 | } |
| 10205 | 10209 | |
| 10206 | 10210 | if (!ok) { |
| 10207 | | ir_add_error(ira, &instruction->base.base, |
| 10211 | ir_add_error_node(ira, instruction->base.source_node, |
| 10208 | 10212 | buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod", |
| 10209 | 10213 | buf_ptr(&op1->value->type->name), |
| 10210 | 10214 | buf_ptr(&op2->value->type->name))); |
| ... | ... | @@ -10213,7 +10217,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc |
| 10213 | 10217 | } |
| 10214 | 10218 | } |
| 10215 | 10219 | |
| 10216 | | return ir_analyze_math_op(ira, &instruction->base.base, resolved_type, op1_val, op_id, op2_val); |
| 10220 | return ir_analyze_math_op(ira, instruction->base.scope, instruction->base.source_node, resolved_type, op1_val, op_id, op2_val); |
| 10217 | 10221 | } |
| 10218 | 10222 | |
| 10219 | 10223 | const bool is_signed_div = |
| ... | ... | @@ -10225,7 +10229,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc |
| 10225 | 10229 | op_id = IrBinOpDivTrunc; |
| 10226 | 10230 | |
| 10227 | 10231 | if (is_signed_div) { |
| 10228 | | ir_add_error(ira, &instruction->base.base, |
| 10232 | ir_add_error_node(ira, instruction->base.source_node, |
| 10229 | 10233 | buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact", |
| 10230 | 10234 | buf_ptr(&op1->value->type->name), |
| 10231 | 10235 | buf_ptr(&op2->value->type->name))); |
| ... | ... | @@ -10235,7 +10239,7 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc |
| 10235 | 10239 | op_id = IrBinOpRemRem; |
| 10236 | 10240 | |
| 10237 | 10241 | if (is_signed_div) { |
| 10238 | | ir_add_error(ira, &instruction->base.base, |
| 10242 | ir_add_error_node(ira, instruction->base.source_node, |
| 10239 | 10243 | buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod", |
| 10240 | 10244 | buf_ptr(&op1->value->type->name), |
| 10241 | 10245 | buf_ptr(&op2->value->type->name))); |
| ... | ... | @@ -10243,11 +10247,11 @@ static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruc |
| 10243 | 10247 | } |
| 10244 | 10248 | } |
| 10245 | 10249 | |
| 10246 | | return ir_build_bin_op_gen(ira, &instruction->base.base, resolved_type, |
| 10250 | return ir_build_bin_op_gen(ira, instruction->base.scope, instruction->base.source_node, resolved_type, |
| 10247 | 10251 | op_id, casted_op1, casted_op2, instruction->safety_check_on); |
| 10248 | 10252 | } |
| 10249 | 10253 | |
| 10250 | | static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr, |
| 10254 | static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 10251 | 10255 | IrInstGen *op1, IrInstGen *op2) |
| 10252 | 10256 | { |
| 10253 | 10257 | Error err; |
| ... | ... | @@ -10259,9 +10263,9 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr, |
| 10259 | 10263 | |
| 10260 | 10264 | Buf *bare_name = buf_alloc(); |
| 10261 | 10265 | Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct), |
| 10262 | | source_instr->scope, source_instr->source_node, bare_name); |
| 10263 | | ZigType *new_type = get_partial_container_type(ira->codegen, source_instr->scope, |
| 10264 | | ContainerKindStruct, source_instr->source_node, buf_ptr(name), bare_name, ContainerLayoutAuto); |
| 10266 | scope, source_node, bare_name); |
| 10267 | ZigType *new_type = get_partial_container_type(ira->codegen, scope, |
| 10268 | ContainerKindStruct, source_node, buf_ptr(name), bare_name, ContainerLayoutAuto); |
| 10265 | 10269 | new_type->data.structure.special = StructSpecialInferredTuple; |
| 10266 | 10270 | new_type->data.structure.resolve_status = ResolveStatusBeingInferred; |
| 10267 | 10271 | uint32_t new_field_count = op1_field_count + op2_field_count; |
| ... | ... | @@ -10270,7 +10274,7 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr, |
| 10270 | 10274 | new_type->data.structure.fields = realloc_type_struct_fields(new_type->data.structure.fields, |
| 10271 | 10275 | 0, new_field_count); |
| 10272 | 10276 | |
| 10273 | | IrInstGen *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(), |
| 10277 | IrInstGen *new_struct_ptr = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(), |
| 10274 | 10278 | new_type, nullptr, false, true); |
| 10275 | 10279 | |
| 10276 | 10280 | for (uint32_t i = 0; i < new_field_count; i += 1) { |
| ... | ... | @@ -10304,18 +10308,18 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr, |
| 10304 | 10308 | src_field = op2_type->data.structure.fields[i - op1_field_count]; |
| 10305 | 10309 | src_struct_op = op2; |
| 10306 | 10310 | } |
| 10307 | | IrInstGen *field_value = ir_analyze_struct_value_field_value(ira, source_instr, |
| 10311 | IrInstGen *field_value = ir_analyze_struct_value_field_value(ira, scope, source_node, |
| 10308 | 10312 | src_struct_op, src_field); |
| 10309 | 10313 | if (type_is_invalid(field_value->value->type)) |
| 10310 | 10314 | return ira->codegen->invalid_inst_gen; |
| 10311 | | IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(ira, source_instr, dst_field, |
| 10315 | IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, dst_field, |
| 10312 | 10316 | new_struct_ptr, new_type, true); |
| 10313 | 10317 | if (type_is_invalid(dest_ptr->value->type)) |
| 10314 | 10318 | return ira->codegen->invalid_inst_gen; |
| 10315 | 10319 | if (instr_is_comptime(field_value)) { |
| 10316 | 10320 | const_ptrs.append(dest_ptr); |
| 10317 | 10321 | } |
| 10318 | | IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, dest_ptr, field_value, |
| 10322 | IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, scope, source_node, dest_ptr, field_value, |
| 10319 | 10323 | true); |
| 10320 | 10324 | if (type_is_invalid(store_ptr_inst->value->type)) |
| 10321 | 10325 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -10329,17 +10333,18 @@ static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr, |
| 10329 | 10333 | // This field will be generated comptime; no need to do this. |
| 10330 | 10334 | continue; |
| 10331 | 10335 | } |
| 10332 | | IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr); |
| 10336 | IrInstGen *deref = ir_get_deref(ira, elem_result_loc->scope, |
| 10337 | elem_result_loc->source_node, elem_result_loc, nullptr); |
| 10333 | 10338 | if (!type_requires_comptime(ira->codegen, elem_result_loc->value->type->data.pointer.child_type)) { |
| 10334 | 10339 | elem_result_loc->value->special = ConstValSpecialRuntime; |
| 10335 | 10340 | } |
| 10336 | | ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, true); |
| 10341 | ir_analyze_store_ptr(ira, elem_result_loc->scope, elem_result_loc->source_node, elem_result_loc, deref, true); |
| 10337 | 10342 | } |
| 10338 | 10343 | } |
| 10339 | 10344 | |
| 10340 | 10345 | const_ptrs.deinit(); |
| 10341 | 10346 | |
| 10342 | | return ir_get_deref(ira, source_instr, new_struct_ptr, nullptr); |
| 10347 | return ir_get_deref(ira, scope, source_node, new_struct_ptr, nullptr); |
| 10343 | 10348 | } |
| 10344 | 10349 | |
| 10345 | 10350 | static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instruction) { |
| ... | ... | @@ -10354,7 +10359,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi |
| 10354 | 10359 | return ira->codegen->invalid_inst_gen; |
| 10355 | 10360 | |
| 10356 | 10361 | if (is_tuple(op1_type) && is_tuple(op2_type)) { |
| 10357 | | return ir_analyze_tuple_cat(ira, &instruction->base.base, op1, op2); |
| 10362 | return ir_analyze_tuple_cat(ira, instruction->base.scope, instruction->base.source_node, op1, op2); |
| 10358 | 10363 | } |
| 10359 | 10364 | |
| 10360 | 10365 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| ... | ... | @@ -10402,14 +10407,14 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi |
| 10402 | 10407 | { |
| 10403 | 10408 | ZigType *array_type = op1_type->data.pointer.child_type; |
| 10404 | 10409 | child_type = array_type->data.array.child_type; |
| 10405 | | op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->base.source_node); |
| 10410 | op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->source_node); |
| 10406 | 10411 | if (op1_array_val == nullptr) |
| 10407 | 10412 | return ira->codegen->invalid_inst_gen; |
| 10408 | 10413 | op1_array_index = 0; |
| 10409 | 10414 | op1_array_end = array_type->data.array.len; |
| 10410 | 10415 | sentinel1 = array_type->data.array.sentinel; |
| 10411 | 10416 | } else { |
| 10412 | | ir_add_error(ira, &op1->base, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name))); |
| 10417 | ir_add_error(ira, op1, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name))); |
| 10413 | 10418 | return ira->codegen->invalid_inst_gen; |
| 10414 | 10419 | } |
| 10415 | 10420 | |
| ... | ... | @@ -10450,7 +10455,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi |
| 10450 | 10455 | { |
| 10451 | 10456 | ZigType *array_type = op2_type->data.pointer.child_type; |
| 10452 | 10457 | op2_type_valid = array_type->data.array.child_type == child_type; |
| 10453 | | op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->base.source_node); |
| 10458 | op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->source_node); |
| 10454 | 10459 | if (op2_array_val == nullptr) |
| 10455 | 10460 | return ira->codegen->invalid_inst_gen; |
| 10456 | 10461 | op2_array_index = 0; |
| ... | ... | @@ -10458,12 +10463,12 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi |
| 10458 | 10463 | |
| 10459 | 10464 | sentinel2 = array_type->data.array.sentinel; |
| 10460 | 10465 | } else { |
| 10461 | | ir_add_error(ira, &op2->base, |
| 10466 | ir_add_error(ira, op2, |
| 10462 | 10467 | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name))); |
| 10463 | 10468 | return ira->codegen->invalid_inst_gen; |
| 10464 | 10469 | } |
| 10465 | 10470 | if (!op2_type_valid) { |
| 10466 | | ir_add_error(ira, &op2->base, buf_sprintf("expected array of type '%s', found '%s'", |
| 10471 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 10467 | 10472 | buf_ptr(&child_type->name), |
| 10468 | 10473 | buf_ptr(&op2->value->type->name))); |
| 10469 | 10474 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -10483,7 +10488,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi |
| 10483 | 10488 | } |
| 10484 | 10489 | |
| 10485 | 10490 | // The type of result is populated in the following if blocks |
| 10486 | | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 10491 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr); |
| 10487 | 10492 | ZigValue *out_val = result->value; |
| 10488 | 10493 | |
| 10489 | 10494 | ZigValue *out_array_val; |
| ... | ... | @@ -10571,7 +10576,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi |
| 10571 | 10576 | return result; |
| 10572 | 10577 | } |
| 10573 | 10578 | |
| 10574 | | static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr, |
| 10579 | static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 10575 | 10580 | IrInstGen *op1, IrInstGen *op2) |
| 10576 | 10581 | { |
| 10577 | 10582 | Error err; |
| ... | ... | @@ -10584,22 +10589,22 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr, |
| 10584 | 10589 | |
| 10585 | 10590 | uint64_t new_field_count; |
| 10586 | 10591 | if (mul_u64_overflow(op1_field_count, mult_amt, &new_field_count)) { |
| 10587 | | ir_add_error(ira, source_instr, buf_sprintf("operation results in overflow")); |
| 10592 | ir_add_error_node(ira, source_node, buf_sprintf("operation results in overflow")); |
| 10588 | 10593 | return ira->codegen->invalid_inst_gen; |
| 10589 | 10594 | } |
| 10590 | 10595 | |
| 10591 | 10596 | Buf *bare_name = buf_alloc(); |
| 10592 | 10597 | Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct), |
| 10593 | | source_instr->scope, source_instr->source_node, bare_name); |
| 10594 | | ZigType *new_type = get_partial_container_type(ira->codegen, source_instr->scope, |
| 10595 | | ContainerKindStruct, source_instr->source_node, buf_ptr(name), bare_name, ContainerLayoutAuto); |
| 10598 | scope, source_node, bare_name); |
| 10599 | ZigType *new_type = get_partial_container_type(ira->codegen, scope, |
| 10600 | ContainerKindStruct, source_node, buf_ptr(name), bare_name, ContainerLayoutAuto); |
| 10596 | 10601 | new_type->data.structure.special = StructSpecialInferredTuple; |
| 10597 | 10602 | new_type->data.structure.resolve_status = ResolveStatusBeingInferred; |
| 10598 | 10603 | new_type->data.structure.src_field_count = new_field_count; |
| 10599 | 10604 | new_type->data.structure.fields = realloc_type_struct_fields( |
| 10600 | 10605 | new_type->data.structure.fields, 0, new_field_count); |
| 10601 | 10606 | |
| 10602 | | IrInstGen *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(), |
| 10607 | IrInstGen *new_struct_ptr = ir_resolve_result(ira, ira->suspend_source_instr, no_result_loc(), |
| 10603 | 10608 | new_type, nullptr, false, true); |
| 10604 | 10609 | |
| 10605 | 10610 | for (uint64_t i = 0; i < new_field_count; i += 1) { |
| ... | ... | @@ -10624,12 +10629,12 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr, |
| 10624 | 10629 | TypeStructField *dst_field = new_type->data.structure.fields[i]; |
| 10625 | 10630 | |
| 10626 | 10631 | IrInstGen *field_value = ir_analyze_struct_value_field_value( |
| 10627 | | ira, source_instr, op1, src_field); |
| 10632 | ira, scope, source_node, op1, src_field); |
| 10628 | 10633 | if (type_is_invalid(field_value->value->type)) |
| 10629 | 10634 | return ira->codegen->invalid_inst_gen; |
| 10630 | 10635 | |
| 10631 | 10636 | IrInstGen *dest_ptr = ir_analyze_struct_field_ptr( |
| 10632 | | ira, source_instr, dst_field, new_struct_ptr, new_type, true); |
| 10637 | ira, scope, source_node, dst_field, new_struct_ptr, new_type, true); |
| 10633 | 10638 | if (type_is_invalid(dest_ptr->value->type)) |
| 10634 | 10639 | return ira->codegen->invalid_inst_gen; |
| 10635 | 10640 | |
| ... | ... | @@ -10638,7 +10643,7 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr, |
| 10638 | 10643 | } |
| 10639 | 10644 | |
| 10640 | 10645 | IrInstGen *store_ptr_inst = ir_analyze_store_ptr( |
| 10641 | | ira, source_instr, dest_ptr, field_value, true); |
| 10646 | ira, scope, source_node, dest_ptr, field_value, true); |
| 10642 | 10647 | if (type_is_invalid(store_ptr_inst->value->type)) |
| 10643 | 10648 | return ira->codegen->invalid_inst_gen; |
| 10644 | 10649 | } |
| ... | ... | @@ -10652,12 +10657,13 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr, |
| 10652 | 10657 | // This field will be generated comptime; no need to do this. |
| 10653 | 10658 | continue; |
| 10654 | 10659 | } |
| 10655 | | IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr); |
| 10660 | IrInstGen *deref = ir_get_deref(ira, elem_result_loc->scope, |
| 10661 | elem_result_loc->source_node, elem_result_loc, nullptr); |
| 10656 | 10662 | if (!type_requires_comptime(ira->codegen, elem_result_loc->value->type->data.pointer.child_type)) { |
| 10657 | 10663 | elem_result_loc->value->special = ConstValSpecialRuntime; |
| 10658 | 10664 | } |
| 10659 | | IrInstGen *store_ptr_inst = ir_analyze_store_ptr( |
| 10660 | | ira, &elem_result_loc->base, elem_result_loc, deref, true); |
| 10665 | IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, elem_result_loc->scope, |
| 10666 | elem_result_loc->source_node, elem_result_loc, deref, true); |
| 10661 | 10667 | if (type_is_invalid(store_ptr_inst->value->type)) |
| 10662 | 10668 | return ira->codegen->invalid_inst_gen; |
| 10663 | 10669 | } |
| ... | ... | @@ -10665,7 +10671,7 @@ static IrInstGen *ir_analyze_tuple_mult(IrAnalyze *ira, IrInst* source_instr, |
| 10665 | 10671 | |
| 10666 | 10672 | const_ptrs.deinit(); |
| 10667 | 10673 | |
| 10668 | | return ir_get_deref(ira, source_instr, new_struct_ptr, nullptr); |
| 10674 | return ir_get_deref(ira, scope, source_node, new_struct_ptr, nullptr); |
| 10669 | 10675 | } |
| 10670 | 10676 | |
| 10671 | 10677 | static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruction) { |
| ... | ... | @@ -10690,7 +10696,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct |
| 10690 | 10696 | op1->value->type->data.pointer.child_type->id == ZigTypeIdArray) |
| 10691 | 10697 | { |
| 10692 | 10698 | array_type = op1->value->type->data.pointer.child_type; |
| 10693 | | IrInstGen *array_inst = ir_get_deref(ira, &op1->base, op1, nullptr); |
| 10699 | IrInstGen *array_inst = ir_get_deref(ira, op1->scope, op1->source_node, op1, nullptr); |
| 10694 | 10700 | if (type_is_invalid(array_inst->value->type)) |
| 10695 | 10701 | return ira->codegen->invalid_inst_gen; |
| 10696 | 10702 | array_val = ir_resolve_const(ira, array_inst, UndefOk); |
| ... | ... | @@ -10698,9 +10704,9 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct |
| 10698 | 10704 | return ira->codegen->invalid_inst_gen; |
| 10699 | 10705 | want_ptr_to_array = true; |
| 10700 | 10706 | } else if (is_tuple(op1->value->type)) { |
| 10701 | | return ir_analyze_tuple_mult(ira, &instruction->base.base, op1, op2); |
| 10707 | return ir_analyze_tuple_mult(ira, instruction->base.scope, instruction->base.source_node, op1, op2); |
| 10702 | 10708 | } else { |
| 10703 | | ir_add_error(ira, &op1->base, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name))); |
| 10709 | ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name))); |
| 10704 | 10710 | return ira->codegen->invalid_inst_gen; |
| 10705 | 10711 | } |
| 10706 | 10712 | |
| ... | ... | @@ -10712,7 +10718,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct |
| 10712 | 10718 | uint64_t new_array_len; |
| 10713 | 10719 | |
| 10714 | 10720 | if (mul_u64_overflow(old_array_len, mult_amt, &new_array_len)) { |
| 10715 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("operation results in overflow")); |
| 10721 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("operation results in overflow")); |
| 10716 | 10722 | return ira->codegen->invalid_inst_gen; |
| 10717 | 10723 | } |
| 10718 | 10724 | |
| ... | ... | @@ -10722,9 +10728,9 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct |
| 10722 | 10728 | |
| 10723 | 10729 | IrInstGen *array_result; |
| 10724 | 10730 | if (array_val->special == ConstValSpecialUndef || array_val->data.x_array.special == ConstArraySpecialUndef) { |
| 10725 | | array_result = ir_const_undef(ira, &instruction->base.base, result_array_type); |
| 10731 | array_result = ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, result_array_type); |
| 10726 | 10732 | } else { |
| 10727 | | array_result = ir_const(ira, &instruction->base.base, result_array_type); |
| 10733 | array_result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_array_type); |
| 10728 | 10734 | ZigValue *out_val = array_result->value; |
| 10729 | 10735 | |
| 10730 | 10736 | switch (type_has_one_possible_value(ira->codegen, result_array_type)) { |
| ... | ... | @@ -10765,7 +10771,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct |
| 10765 | 10771 | } |
| 10766 | 10772 | skip_computation: |
| 10767 | 10773 | if (want_ptr_to_array) { |
| 10768 | | return ir_get_ref(ira, &instruction->base.base, array_result, true, false); |
| 10774 | return ir_get_ref(ira, instruction->base.scope, instruction->base.source_node, array_result, true, false); |
| 10769 | 10775 | } else { |
| 10770 | 10776 | return array_result; |
| 10771 | 10777 | } |
| ... | ... | @@ -10774,26 +10780,26 @@ skip_computation: |
| 10774 | 10780 | static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira, |
| 10775 | 10781 | IrInstSrcMergeErrSets *instruction) |
| 10776 | 10782 | { |
| 10777 | | ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op1->child); |
| 10783 | ZigType *op1_type = ir_resolve_error_set_type(ira, instruction->base.source_node, instruction->op1->child); |
| 10778 | 10784 | if (type_is_invalid(op1_type)) |
| 10779 | 10785 | return ira->codegen->invalid_inst_gen; |
| 10780 | 10786 | |
| 10781 | | ZigType *op2_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op2->child); |
| 10787 | ZigType *op2_type = ir_resolve_error_set_type(ira, instruction->base.source_node, instruction->op2->child); |
| 10782 | 10788 | if (type_is_invalid(op2_type)) |
| 10783 | 10789 | return ira->codegen->invalid_inst_gen; |
| 10784 | 10790 | |
| 10785 | | if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->base.source_node)) { |
| 10791 | if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->source_node)) { |
| 10786 | 10792 | return ira->codegen->invalid_inst_gen; |
| 10787 | 10793 | } |
| 10788 | 10794 | |
| 10789 | | if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->base.source_node)) { |
| 10795 | if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->source_node)) { |
| 10790 | 10796 | return ira->codegen->invalid_inst_gen; |
| 10791 | 10797 | } |
| 10792 | 10798 | |
| 10793 | 10799 | if (type_is_global_error_set(op1_type) || |
| 10794 | 10800 | type_is_global_error_set(op2_type)) |
| 10795 | 10801 | { |
| 10796 | | return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_global_error_set); |
| 10802 | return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_global_error_set); |
| 10797 | 10803 | } |
| 10798 | 10804 | |
| 10799 | 10805 | size_t errors_count = ira->codegen->errors_by_index.length; |
| ... | ... | @@ -10806,7 +10812,7 @@ static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira, |
| 10806 | 10812 | ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name); |
| 10807 | 10813 | heap::c_allocator.deallocate(errors, errors_count); |
| 10808 | 10814 | |
| 10809 | | return ir_const_type(ira, &instruction->base.base, result_type); |
| 10815 | return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, result_type); |
| 10810 | 10816 | } |
| 10811 | 10817 | |
| 10812 | 10818 | |
| ... | ... | @@ -10871,7 +10877,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV |
| 10871 | 10877 | } |
| 10872 | 10878 | } |
| 10873 | 10879 | |
| 10874 | | AstNode *source_node = decl_var_instruction->base.base.source_node; |
| 10880 | AstNode *source_node = decl_var_instruction->base.source_node; |
| 10875 | 10881 | |
| 10876 | 10882 | bool is_comptime_var = ir_get_var_is_comptime(var); |
| 10877 | 10883 | |
| ... | ... | @@ -10881,13 +10887,14 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV |
| 10881 | 10887 | // if this is null, a compiler error happened and did not initialize the variable. |
| 10882 | 10888 | // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation. |
| 10883 | 10889 | if (var_ptr == nullptr || type_is_invalid(var_ptr->value->type)) { |
| 10884 | | ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base.base); |
| 10890 | src_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, |
| 10891 | decl_var_instruction->base.source_node); |
| 10885 | 10892 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 10886 | 10893 | return ira->codegen->invalid_inst_gen; |
| 10887 | 10894 | } |
| 10888 | 10895 | |
| 10889 | 10896 | // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value. |
| 10890 | | ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base.base); |
| 10897 | src_assert(var_ptr->value->type->id == ZigTypeIdPointer, decl_var_instruction->base.source_node); |
| 10891 | 10898 | |
| 10892 | 10899 | ZigType *result_type = var_ptr->value->type->data.pointer.child_type; |
| 10893 | 10900 | if (type_is_invalid(result_type)) { |
| ... | ... | @@ -10902,7 +10909,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV |
| 10902 | 10909 | if (ptr_val == nullptr) |
| 10903 | 10910 | return ira->codegen->invalid_inst_gen; |
| 10904 | 10911 | |
| 10905 | | init_val = const_ptr_pointee(ira, ira->codegen, ptr_val, decl_var_instruction->base.base.source_node); |
| 10912 | init_val = const_ptr_pointee(ira, ira->codegen, ptr_val, decl_var_instruction->base.source_node); |
| 10906 | 10913 | if (init_val == nullptr) |
| 10907 | 10914 | return ira->codegen->invalid_inst_gen; |
| 10908 | 10915 | |
| ... | ... | @@ -10935,7 +10942,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV |
| 10935 | 10942 | case ReqCompTimeNo: |
| 10936 | 10943 | if (init_val != nullptr && value_is_comptime(init_val)) { |
| 10937 | 10944 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 10938 | | decl_var_instruction->base.base.source_node, init_val, UndefOk))) |
| 10945 | decl_var_instruction->base.source_node, init_val, UndefOk))) |
| 10939 | 10946 | { |
| 10940 | 10947 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 10941 | 10948 | } else if (init_val->type->id == ZigTypeIdFn && |
| ... | ... | @@ -10968,13 +10975,13 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV |
| 10968 | 10975 | assert(var->var_type); |
| 10969 | 10976 | |
| 10970 | 10977 | if (type_is_invalid(result_type)) { |
| 10971 | | return ir_const_void(ira, &decl_var_instruction->base.base); |
| 10978 | return ir_const_void(ira, decl_var_instruction->base.scope, decl_var_instruction->base.source_node); |
| 10972 | 10979 | } |
| 10973 | 10980 | |
| 10974 | 10981 | if (decl_var_instruction->align_value == nullptr) { |
| 10975 | 10982 | if ((err = type_resolve(ira->codegen, result_type, ResolveStatusAlignmentKnown))) { |
| 10976 | 10983 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 10977 | | return ir_const_void(ira, &decl_var_instruction->base.base); |
| 10984 | return ir_const_void(ira, decl_var_instruction->base.scope, decl_var_instruction->base.source_node); |
| 10978 | 10985 | } |
| 10979 | 10986 | var->align_bytes = get_ptr_align(ira->codegen, var_ptr->value->type); |
| 10980 | 10987 | } else { |
| ... | ... | @@ -10993,7 +11000,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV |
| 10993 | 11000 | // we need a runtime ptr but we have a comptime val. |
| 10994 | 11001 | // since it's a comptime val there are no instructions for it. |
| 10995 | 11002 | // we memcpy the init value here |
| 10996 | | IrInstGen *deref = ir_get_deref(ira, &var_ptr->base, var_ptr, nullptr); |
| 11003 | IrInstGen *deref = ir_get_deref(ira, var_ptr->scope, var_ptr->source_node, var_ptr, nullptr); |
| 10997 | 11004 | if (type_is_invalid(deref->value->type)) { |
| 10998 | 11005 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 10999 | 11006 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -11003,13 +11010,13 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV |
| 11003 | 11010 | // instruction. |
| 11004 | 11011 | assert(deref->value->special != ConstValSpecialRuntime); |
| 11005 | 11012 | var_ptr->value->special = ConstValSpecialRuntime; |
| 11006 | | ir_analyze_store_ptr(ira, &var_ptr->base, var_ptr, deref, false); |
| 11013 | ir_analyze_store_ptr(ira, var_ptr->scope, var_ptr->source_node, var_ptr, deref, false); |
| 11007 | 11014 | } |
| 11008 | 11015 | if (instr_is_comptime(var_ptr) && (is_comptime_var || (var_class_requires_const && var->gen_is_const))) { |
| 11009 | | return ir_const_void(ira, &decl_var_instruction->base.base); |
| 11016 | return ir_const_void(ira, decl_var_instruction->base.scope, decl_var_instruction->base.source_node); |
| 11010 | 11017 | } |
| 11011 | 11018 | } else if (is_comptime_var) { |
| 11012 | | ir_add_error(ira, &decl_var_instruction->base.base, |
| 11019 | ir_add_error_node(ira, decl_var_instruction->base.source_node, |
| 11013 | 11020 | buf_sprintf("cannot store runtime value in compile time variable")); |
| 11014 | 11021 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 11015 | 11022 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -11019,7 +11026,7 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV |
| 11019 | 11026 | if (fn_entry) |
| 11020 | 11027 | fn_entry->variable_list.append(var); |
| 11021 | 11028 | |
| 11022 | | return ir_build_var_decl_gen(ira, &decl_var_instruction->base.base, var, var_ptr); |
| 11029 | return ir_build_var_decl_gen(ira, decl_var_instruction->base.scope, decl_var_instruction->base.source_node, var, var_ptr); |
| 11023 | 11030 | } |
| 11024 | 11031 | |
| 11025 | 11032 | static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport *instruction) { |
| ... | ... | @@ -11035,32 +11042,32 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport |
| 11035 | 11042 | assert(options_type->id == ZigTypeIdStruct); |
| 11036 | 11043 | |
| 11037 | 11044 | TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name")); |
| 11038 | | ir_assert(name_field != nullptr, &instruction->base.base); |
| 11039 | | IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, name_field); |
| 11045 | src_assert(name_field != nullptr, instruction->base.source_node); |
| 11046 | IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, name_field); |
| 11040 | 11047 | if (type_is_invalid(name_inst->value->type)) |
| 11041 | 11048 | return ira->codegen->invalid_inst_gen; |
| 11042 | 11049 | |
| 11043 | 11050 | TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage")); |
| 11044 | | ir_assert(linkage_field != nullptr, &instruction->base.base); |
| 11045 | | IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, linkage_field); |
| 11051 | src_assert(linkage_field != nullptr, instruction->base.source_node); |
| 11052 | IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, linkage_field); |
| 11046 | 11053 | if (type_is_invalid(linkage_inst->value->type)) |
| 11047 | 11054 | return ira->codegen->invalid_inst_gen; |
| 11048 | 11055 | |
| 11049 | 11056 | TypeStructField *section_field = find_struct_type_field(options_type, buf_create_from_str("section")); |
| 11050 | | ir_assert(section_field != nullptr, &instruction->base.base); |
| 11051 | | IrInstGen *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, section_field); |
| 11057 | src_assert(section_field != nullptr, instruction->base.source_node); |
| 11058 | IrInstGen *section_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, section_field); |
| 11052 | 11059 | if (type_is_invalid(section_inst->value->type)) |
| 11053 | 11060 | return ira->codegen->invalid_inst_gen; |
| 11054 | 11061 | |
| 11055 | 11062 | // The `section` field is optional, we have to unwrap it first |
| 11056 | | IrInstGen *non_null_check = ir_analyze_test_non_null(ira, &instruction->base.base, section_inst); |
| 11063 | IrInstGen *non_null_check = ir_analyze_test_non_null(ira, instruction->base.scope, instruction->base.source_node, section_inst); |
| 11057 | 11064 | bool is_non_null; |
| 11058 | 11065 | if (!ir_resolve_bool(ira, non_null_check, &is_non_null)) |
| 11059 | 11066 | return ira->codegen->invalid_inst_gen; |
| 11060 | 11067 | |
| 11061 | 11068 | IrInstGen *section_str_inst = nullptr; |
| 11062 | 11069 | if (is_non_null) { |
| 11063 | | section_str_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base.base, section_inst, false); |
| 11070 | section_str_inst = ir_analyze_optional_value_payload_value(ira, instruction->base.scope, instruction->base.source_node, section_inst, false); |
| 11064 | 11071 | if (type_is_invalid(section_str_inst->value->type)) |
| 11065 | 11072 | return ira->codegen->invalid_inst_gen; |
| 11066 | 11073 | } |
| ... | ... | @@ -11071,7 +11078,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport |
| 11071 | 11078 | return ira->codegen->invalid_inst_gen; |
| 11072 | 11079 | |
| 11073 | 11080 | if (buf_len(symbol_name) < 1) { |
| 11074 | | ir_add_error(ira, &name_inst->base, |
| 11081 | ir_add_error(ira, name_inst, |
| 11075 | 11082 | buf_sprintf("exported symbol name cannot be empty")); |
| 11076 | 11083 | return ira->codegen->invalid_inst_gen; |
| 11077 | 11084 | } |
| ... | ... | @@ -11090,12 +11097,12 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport |
| 11090 | 11097 | // in another file. |
| 11091 | 11098 | TldFn *tld_fn = heap::c_allocator.create<TldFn>(); |
| 11092 | 11099 | tld_fn->base.id = TldIdFn; |
| 11093 | | tld_fn->base.source_node = instruction->base.base.source_node; |
| 11100 | tld_fn->base.source_node = instruction->base.source_node; |
| 11094 | 11101 | |
| 11095 | 11102 | auto entry = ira->codegen->exported_symbol_names.put_unique(symbol_name, &tld_fn->base); |
| 11096 | 11103 | if (entry) { |
| 11097 | 11104 | AstNode *other_export_node = entry->value->source_node; |
| 11098 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 11105 | ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node, |
| 11099 | 11106 | buf_sprintf("exported symbol collision: '%s'", buf_ptr(symbol_name))); |
| 11100 | 11107 | add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol here")); |
| 11101 | 11108 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -11114,17 +11121,17 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport |
| 11114 | 11121 | CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc; |
| 11115 | 11122 | switch (cc) { |
| 11116 | 11123 | case CallingConventionUnspecified: { |
| 11117 | | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 11124 | ErrorMsg *msg = ir_add_error(ira, target, |
| 11118 | 11125 | buf_sprintf("exported function must specify calling convention")); |
| 11119 | 11126 | add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here")); |
| 11120 | 11127 | } break; |
| 11121 | 11128 | case CallingConventionAsync: { |
| 11122 | | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 11129 | ErrorMsg *msg = ir_add_error(ira, target, |
| 11123 | 11130 | buf_sprintf("exported function cannot be async")); |
| 11124 | 11131 | add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here")); |
| 11125 | 11132 | } break; |
| 11126 | 11133 | case CallingConventionInline: { |
| 11127 | | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 11134 | ErrorMsg *msg = ir_add_error(ira, target, |
| 11128 | 11135 | buf_sprintf("exported function cannot be inline")); |
| 11129 | 11136 | add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here")); |
| 11130 | 11137 | } break; |
| ... | ... | @@ -11147,10 +11154,10 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport |
| 11147 | 11154 | } break; |
| 11148 | 11155 | case ZigTypeIdStruct: |
| 11149 | 11156 | if (is_slice(target->value->type)) { |
| 11150 | | ir_add_error(ira, &target->base, |
| 11157 | ir_add_error(ira, target, |
| 11151 | 11158 | buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name))); |
| 11152 | 11159 | } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) { |
| 11153 | | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 11160 | ErrorMsg *msg = ir_add_error(ira, target, |
| 11154 | 11161 | buf_sprintf("exported struct value must be declared extern")); |
| 11155 | 11162 | add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here")); |
| 11156 | 11163 | } else { |
| ... | ... | @@ -11159,7 +11166,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport |
| 11159 | 11166 | break; |
| 11160 | 11167 | case ZigTypeIdUnion: |
| 11161 | 11168 | if (target->value->type->data.unionation.layout != ContainerLayoutExtern) { |
| 11162 | | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 11169 | ErrorMsg *msg = ir_add_error(ira, target, |
| 11163 | 11170 | buf_sprintf("exported union value must be declared extern")); |
| 11164 | 11171 | add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here")); |
| 11165 | 11172 | } else { |
| ... | ... | @@ -11168,7 +11175,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport |
| 11168 | 11175 | break; |
| 11169 | 11176 | case ZigTypeIdEnum: |
| 11170 | 11177 | if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) { |
| 11171 | | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 11178 | ErrorMsg *msg = ir_add_error(ira, target, |
| 11172 | 11179 | buf_sprintf("exported enum value must be declared extern")); |
| 11173 | 11180 | add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here")); |
| 11174 | 11181 | } else { |
| ... | ... | @@ -11181,7 +11188,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport |
| 11181 | 11188 | return ira->codegen->invalid_inst_gen; |
| 11182 | 11189 | |
| 11183 | 11190 | if (!ok_type) { |
| 11184 | | ir_add_error(ira, &target->base, |
| 11191 | ir_add_error(ira, target, |
| 11185 | 11192 | buf_sprintf("array element type '%s' not extern-compatible", |
| 11186 | 11193 | buf_ptr(&target->value->type->data.array.child_type->name))); |
| 11187 | 11194 | } else { |
| ... | ... | @@ -11196,31 +11203,31 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport |
| 11196 | 11203 | zig_unreachable(); |
| 11197 | 11204 | case ZigTypeIdStruct: |
| 11198 | 11205 | if (is_slice(type_value)) { |
| 11199 | | ir_add_error(ira, &target->base, |
| 11206 | ir_add_error(ira, target, |
| 11200 | 11207 | buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name))); |
| 11201 | 11208 | } else if (type_value->data.structure.layout != ContainerLayoutExtern) { |
| 11202 | | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 11209 | ErrorMsg *msg = ir_add_error(ira, target, |
| 11203 | 11210 | buf_sprintf("exported struct must be declared extern")); |
| 11204 | 11211 | add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here")); |
| 11205 | 11212 | } |
| 11206 | 11213 | break; |
| 11207 | 11214 | case ZigTypeIdUnion: |
| 11208 | 11215 | if (type_value->data.unionation.layout != ContainerLayoutExtern) { |
| 11209 | | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 11216 | ErrorMsg *msg = ir_add_error(ira, target, |
| 11210 | 11217 | buf_sprintf("exported union must be declared extern")); |
| 11211 | 11218 | add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here")); |
| 11212 | 11219 | } |
| 11213 | 11220 | break; |
| 11214 | 11221 | case ZigTypeIdEnum: |
| 11215 | 11222 | if (type_value->data.enumeration.layout != ContainerLayoutExtern) { |
| 11216 | | ErrorMsg *msg = ir_add_error(ira, &target->base, |
| 11223 | ErrorMsg *msg = ir_add_error(ira, target, |
| 11217 | 11224 | buf_sprintf("exported enum must be declared extern")); |
| 11218 | 11225 | add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here")); |
| 11219 | 11226 | } |
| 11220 | 11227 | break; |
| 11221 | 11228 | case ZigTypeIdFn: { |
| 11222 | 11229 | if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) { |
| 11223 | | ir_add_error(ira, &target->base, |
| 11230 | ir_add_error(ira, target, |
| 11224 | 11231 | buf_sprintf("exported function type must specify calling convention")); |
| 11225 | 11232 | } |
| 11226 | 11233 | } break; |
| ... | ... | @@ -11246,7 +11253,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport |
| 11246 | 11253 | case ZigTypeIdOpaque: |
| 11247 | 11254 | case ZigTypeIdFnFrame: |
| 11248 | 11255 | case ZigTypeIdAnyFrame: |
| 11249 | | ir_add_error(ira, &target->base, |
| 11256 | ir_add_error(ira, target, |
| 11250 | 11257 | buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name))); |
| 11251 | 11258 | break; |
| 11252 | 11259 | } |
| ... | ... | @@ -11272,7 +11279,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport |
| 11272 | 11279 | case ZigTypeIdEnumLiteral: |
| 11273 | 11280 | case ZigTypeIdFnFrame: |
| 11274 | 11281 | case ZigTypeIdAnyFrame: |
| 11275 | | ir_add_error(ira, &target->base, |
| 11282 | ir_add_error(ira, target, |
| 11276 | 11283 | buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name))); |
| 11277 | 11284 | break; |
| 11278 | 11285 | } |
| ... | ... | @@ -11288,7 +11295,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport |
| 11288 | 11295 | } |
| 11289 | 11296 | } |
| 11290 | 11297 | |
| 11291 | | return ir_const_void(ira, &instruction->base.base); |
| 11298 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 11292 | 11299 | } |
| 11293 | 11300 | |
| 11294 | 11301 | static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, AstNode *source_node); |
| ... | ... | @@ -11306,38 +11313,38 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern |
| 11306 | 11313 | assert(options_type->id == ZigTypeIdStruct); |
| 11307 | 11314 | |
| 11308 | 11315 | TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name")); |
| 11309 | | ir_assert(name_field != nullptr, &instruction->base.base); |
| 11310 | | IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, name_field); |
| 11316 | src_assert(name_field != nullptr, instruction->base.source_node); |
| 11317 | IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, name_field); |
| 11311 | 11318 | if (type_is_invalid(name_inst->value->type)) |
| 11312 | 11319 | return ira->codegen->invalid_inst_gen; |
| 11313 | 11320 | |
| 11314 | 11321 | TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage")); |
| 11315 | | ir_assert(linkage_field != nullptr, &instruction->base.base); |
| 11316 | | IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, linkage_field); |
| 11322 | src_assert(linkage_field != nullptr, instruction->base.source_node); |
| 11323 | IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, linkage_field); |
| 11317 | 11324 | if (type_is_invalid(linkage_inst->value->type)) |
| 11318 | 11325 | return ira->codegen->invalid_inst_gen; |
| 11319 | 11326 | |
| 11320 | 11327 | TypeStructField *is_thread_local_field = find_struct_type_field(options_type, buf_create_from_str("is_thread_local")); |
| 11321 | | ir_assert(is_thread_local_field != nullptr, &instruction->base.base); |
| 11322 | | IrInstGen *is_thread_local_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, is_thread_local_field); |
| 11328 | src_assert(is_thread_local_field != nullptr, instruction->base.source_node); |
| 11329 | IrInstGen *is_thread_local_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, is_thread_local_field); |
| 11323 | 11330 | if (type_is_invalid(is_thread_local_inst->value->type)) |
| 11324 | 11331 | return ira->codegen->invalid_inst_gen; |
| 11325 | 11332 | |
| 11326 | 11333 | TypeStructField *library_name_field = find_struct_type_field(options_type, buf_create_from_str("library_name")); |
| 11327 | | ir_assert(library_name_field != nullptr, &instruction->base.base); |
| 11328 | | IrInstGen *library_name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, library_name_field); |
| 11334 | src_assert(library_name_field != nullptr, instruction->base.source_node); |
| 11335 | IrInstGen *library_name_inst = ir_analyze_struct_value_field_value(ira, instruction->base.scope, instruction->base.source_node, options, library_name_field); |
| 11329 | 11336 | if (type_is_invalid(library_name_inst->value->type)) |
| 11330 | 11337 | return ira->codegen->invalid_inst_gen; |
| 11331 | 11338 | |
| 11332 | 11339 | // The `library_name` field is optional, we have to unwrap it first |
| 11333 | | IrInstGen *non_null_check = ir_analyze_test_non_null(ira, &instruction->base.base, library_name_inst); |
| 11340 | IrInstGen *non_null_check = ir_analyze_test_non_null(ira, instruction->base.scope, instruction->base.source_node, library_name_inst); |
| 11334 | 11341 | bool is_non_null; |
| 11335 | 11342 | if (!ir_resolve_bool(ira, non_null_check, &is_non_null)) |
| 11336 | 11343 | return ira->codegen->invalid_inst_gen; |
| 11337 | 11344 | |
| 11338 | 11345 | IrInstGen *library_name_val_inst = nullptr; |
| 11339 | 11346 | if (is_non_null) { |
| 11340 | | library_name_val_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base.base, library_name_inst, false); |
| 11347 | library_name_val_inst = ir_analyze_optional_value_payload_value(ira, instruction->base.scope, instruction->base.source_node, library_name_inst, false); |
| 11341 | 11348 | if (type_is_invalid(library_name_val_inst->value->type)) |
| 11342 | 11349 | return ira->codegen->invalid_inst_gen; |
| 11343 | 11350 | } |
| ... | ... | @@ -11348,7 +11355,7 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern |
| 11348 | 11355 | return ira->codegen->invalid_inst_gen; |
| 11349 | 11356 | |
| 11350 | 11357 | if (get_src_ptr_type(value_type) == nullptr) { |
| 11351 | | ir_add_error(ira, &name_inst->base, |
| 11358 | ir_add_error(ira, name_inst, |
| 11352 | 11359 | buf_sprintf("expected (optional) pointer type or function")); |
| 11353 | 11360 | return ira->codegen->invalid_inst_gen; |
| 11354 | 11361 | } |
| ... | ... | @@ -11358,7 +11365,7 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern |
| 11358 | 11365 | return ira->codegen->invalid_inst_gen; |
| 11359 | 11366 | |
| 11360 | 11367 | if (buf_len(symbol_name) == 0) { |
| 11361 | | ir_add_error(ira, &name_inst->base, |
| 11368 | ir_add_error(ira, name_inst, |
| 11362 | 11369 | buf_sprintf("extern symbol name cannot be empty")); |
| 11363 | 11370 | return ira->codegen->invalid_inst_gen; |
| 11364 | 11371 | } |
| ... | ... | @@ -11370,12 +11377,12 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern |
| 11370 | 11377 | return ira->codegen->invalid_inst_gen; |
| 11371 | 11378 | |
| 11372 | 11379 | if (buf_len(library_name) == 0) { |
| 11373 | | ir_add_error(ira, &library_name_inst->base, |
| 11380 | ir_add_error(ira, library_name_inst, |
| 11374 | 11381 | buf_sprintf("library name name cannot be empty")); |
| 11375 | 11382 | return ira->codegen->invalid_inst_gen; |
| 11376 | 11383 | } |
| 11377 | 11384 | |
| 11378 | | add_link_lib_symbol(ira, library_name, symbol_name, instruction->base.base.source_node); |
| 11385 | add_link_lib_symbol(ira, library_name, symbol_name, instruction->base.source_node); |
| 11379 | 11386 | |
| 11380 | 11387 | buf_destroy(library_name); |
| 11381 | 11388 | } |
| ... | ... | @@ -11396,18 +11403,18 @@ static IrInstGen *ir_analyze_instruction_extern(IrAnalyze *ira, IrInstSrcExtern |
| 11396 | 11403 | // XXX: Find a better way to do this (in stage2). |
| 11397 | 11404 | TldFn *tld_fn = heap::c_allocator.create<TldFn>(); |
| 11398 | 11405 | tld_fn->base.id = TldIdFn; |
| 11399 | | tld_fn->base.source_node = instruction->base.base.source_node; |
| 11406 | tld_fn->base.source_node = instruction->base.source_node; |
| 11400 | 11407 | |
| 11401 | 11408 | auto entry = ira->codegen->external_symbol_names.put_unique(symbol_name, &tld_fn->base); |
| 11402 | 11409 | if (entry) { |
| 11403 | 11410 | AstNode *other_extern_node = entry->value->source_node; |
| 11404 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 11411 | ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node, |
| 11405 | 11412 | buf_sprintf("extern symbol collision: '%s'", buf_ptr(symbol_name))); |
| 11406 | 11413 | add_error_note(ira->codegen, msg, other_extern_node, buf_sprintf("other symbol here")); |
| 11407 | 11414 | return ira->codegen->invalid_inst_gen; |
| 11408 | 11415 | } |
| 11409 | 11416 | |
| 11410 | | return ir_build_extern_gen(ira, &instruction->base.base, symbol_name, global_linkage_id, |
| 11417 | return ir_build_extern_gen(ira, instruction->base.scope, instruction->base.source_node, symbol_name, global_linkage_id, |
| 11411 | 11418 | is_thread_local, expr_type); |
| 11412 | 11419 | } |
| 11413 | 11420 | |
| ... | ... | @@ -11423,24 +11430,24 @@ static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 11423 | 11430 | if (instruction->optional == IrInstErrorReturnTraceNull) { |
| 11424 | 11431 | ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type); |
| 11425 | 11432 | if (!ira_has_err_ret_trace(ira)) { |
| 11426 | | IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type); |
| 11433 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, optional_type); |
| 11427 | 11434 | ZigValue *out_val = result->value; |
| 11428 | 11435 | assert(get_src_ptr_type(optional_type) != nullptr); |
| 11429 | 11436 | out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 11430 | 11437 | out_val->data.x_ptr.data.hard_coded_addr.addr = 0; |
| 11431 | 11438 | return result; |
| 11432 | 11439 | } |
| 11433 | | return ir_build_error_return_trace_gen(ira, instruction->base.base.scope, |
| 11434 | | instruction->base.base.source_node, instruction->optional, optional_type); |
| 11440 | return ir_build_error_return_trace_gen(ira, instruction->base.scope, |
| 11441 | instruction->base.source_node, instruction->optional, optional_type); |
| 11435 | 11442 | } else { |
| 11436 | 11443 | assert(ira->codegen->have_err_ret_tracing); |
| 11437 | | return ir_build_error_return_trace_gen(ira, instruction->base.base.scope, |
| 11438 | | instruction->base.base.source_node, instruction->optional, ptr_to_stack_trace_type); |
| 11444 | return ir_build_error_return_trace_gen(ira, instruction->base.scope, |
| 11445 | instruction->base.source_node, instruction->optional, ptr_to_stack_trace_type); |
| 11439 | 11446 | } |
| 11440 | 11447 | } |
| 11441 | 11448 | |
| 11442 | 11449 | static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcErrorUnion *instruction) { |
| 11443 | | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 11450 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type); |
| 11444 | 11451 | result->value->special = ConstValSpecialLazy; |
| 11445 | 11452 | |
| 11446 | 11453 | LazyValueErrUnionType *lazy_err_union_type = heap::c_allocator.create<LazyValueErrUnionType>(); |
| ... | ... | @@ -11459,7 +11466,7 @@ static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcEr |
| 11459 | 11466 | return result; |
| 11460 | 11467 | } |
| 11461 | 11468 | |
| 11462 | | static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType *var_type, |
| 11469 | static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *var_type, |
| 11463 | 11470 | uint32_t align, const char *name_hint, bool force_comptime) |
| 11464 | 11471 | { |
| 11465 | 11472 | Error err; |
| ... | ... | @@ -11468,7 +11475,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType |
| 11468 | 11475 | pointee->special = ConstValSpecialUndef; |
| 11469 | 11476 | pointee->llvm_align = align; |
| 11470 | 11477 | |
| 11471 | | IrInstGenAlloca *result = ir_build_alloca_gen(ira, source_inst, align, name_hint); |
| 11478 | IrInstGenAlloca *result = ir_build_alloca_gen(ira, scope, source_node, align, name_hint); |
| 11472 | 11479 | result->base.value->special = ConstValSpecialStatic; |
| 11473 | 11480 | result->base.value->data.x_ptr.special = ConstPtrSpecialRef; |
| 11474 | 11481 | result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer; |
| ... | ... | @@ -11481,7 +11488,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType |
| 11481 | 11488 | if ((err = type_resolve(ira->codegen, var_type, ResolveStatusAlignmentKnown))) |
| 11482 | 11489 | return ira->codegen->invalid_inst_gen; |
| 11483 | 11490 | if (!var_type_has_bits) { |
| 11484 | | ir_add_error(ira, source_inst, |
| 11491 | ir_add_error_node(ira, source_node, |
| 11485 | 11492 | buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned", |
| 11486 | 11493 | name_hint, buf_ptr(&var_type->name))); |
| 11487 | 11494 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -11502,9 +11509,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType |
| 11502 | 11509 | return &result->base; |
| 11503 | 11510 | } |
| 11504 | 11511 | |
| 11505 | | static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 11506 | | ResultLoc *result_loc) |
| 11507 | | { |
| 11512 | static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, ResultLoc *result_loc) { |
| 11508 | 11513 | switch (result_loc->id) { |
| 11509 | 11514 | case ResultLocIdInvalid: |
| 11510 | 11515 | case ResultLocIdPeerParent: |
| ... | ... | @@ -11584,12 +11589,13 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out |
| 11584 | 11589 | zig_unreachable(); |
| 11585 | 11590 | } |
| 11586 | 11591 | |
| 11587 | | static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 11592 | static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstSrc *suspend_source_instr, |
| 11588 | 11593 | ResultLoc *result_loc, ZigType *value_type) |
| 11589 | 11594 | { |
| 11590 | 11595 | if (type_is_invalid(value_type)) |
| 11591 | 11596 | return ira->codegen->invalid_inst_gen; |
| 11592 | | IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, ""); |
| 11597 | IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr->scope, |
| 11598 | suspend_source_instr->source_node, 0, ""); |
| 11593 | 11599 | alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false, |
| 11594 | 11600 | PtrLenSingle, 0, 0, 0, false); |
| 11595 | 11601 | set_up_result_loc_for_inferred_comptime(ira, &alloca_gen->base); |
| ... | ... | @@ -11618,7 +11624,7 @@ static bool result_loc_is_discard(ResultLoc *result_loc_pass1) { |
| 11618 | 11624 | } |
| 11619 | 11625 | |
| 11620 | 11626 | // when calling this function, at the callsite must check for result type noreturn and propagate it up |
| 11621 | | static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 11627 | static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInstSrc *suspend_source_instr, |
| 11622 | 11628 | ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, |
| 11623 | 11629 | bool allow_discard) |
| 11624 | 11630 | { |
| ... | ... | @@ -11662,7 +11668,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 11662 | 11668 | var = new_var; |
| 11663 | 11669 | } |
| 11664 | 11670 | if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) { |
| 11665 | | ir_add_error(ira, &result_loc->source_instruction->base, |
| 11671 | ir_add_error_node(ira, result_loc->source_instruction->source_node, |
| 11666 | 11672 | buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name))); |
| 11667 | 11673 | return ira->codegen->invalid_inst_gen; |
| 11668 | 11674 | } |
| ... | ... | @@ -11674,14 +11680,16 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 11674 | 11680 | if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) { |
| 11675 | 11681 | return ira->codegen->invalid_inst_gen; |
| 11676 | 11682 | } |
| 11677 | | IrInstGen *alloca_gen = ir_analyze_alloca(ira, &result_loc->source_instruction->base, value_type, |
| 11683 | IrInstGen *alloca_gen = ir_analyze_alloca(ira, |
| 11684 | result_loc->source_instruction->scope, |
| 11685 | result_loc->source_instruction->source_node, value_type, |
| 11678 | 11686 | align, alloca_src->name_hint, force_comptime); |
| 11679 | 11687 | if (force_runtime) { |
| 11680 | 11688 | alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 11681 | 11689 | alloca_gen->value->special = ConstValSpecialRuntime; |
| 11682 | 11690 | } |
| 11683 | 11691 | if (alloca_src->base.child != nullptr && !result_loc->written) { |
| 11684 | | alloca_src->base.child->base.ref_count = 0; |
| 11692 | alloca_src->base.child->ref_count = 0; |
| 11685 | 11693 | } |
| 11686 | 11694 | alloca_src->base.child = alloca_gen; |
| 11687 | 11695 | var->ptr_instruction = alloca_gen; |
| ... | ... | @@ -11786,7 +11794,8 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 11786 | 11794 | |
| 11787 | 11795 | IrInstGen *casted_value; |
| 11788 | 11796 | if (value != nullptr) { |
| 11789 | | casted_value = ir_implicit_cast2(ira, suspend_source_instr, value, dest_type); |
| 11797 | casted_value = ir_implicit_cast2(ira, suspend_source_instr->scope, |
| 11798 | suspend_source_instr->source_node, value, dest_type); |
| 11790 | 11799 | if (type_is_invalid(casted_value->value->type)) |
| 11791 | 11800 | return ira->codegen->invalid_inst_gen; |
| 11792 | 11801 | dest_type = casted_value->value->type; |
| ... | ... | @@ -11835,7 +11844,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 11835 | 11844 | |
| 11836 | 11845 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira, |
| 11837 | 11846 | parent_result_loc->value->type, ptr_type, |
| 11838 | | result_cast->base.source_instruction->base.source_node, false); |
| 11847 | result_cast->base.source_instruction->source_node, false); |
| 11839 | 11848 | if (const_cast_result.id == ConstCastResultIdInvalid) |
| 11840 | 11849 | return ira->codegen->invalid_inst_gen; |
| 11841 | 11850 | if (const_cast_result.id != ConstCastResultIdOk) { |
| ... | ... | @@ -11849,8 +11858,10 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 11849 | 11858 | } |
| 11850 | 11859 | |
| 11851 | 11860 | result_loc->written = true; |
| 11852 | | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, |
| 11853 | | &parent_result_loc->base, ptr_type, &result_cast->base.source_instruction->base, false, false); |
| 11861 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr->scope, |
| 11862 | suspend_source_instr->source_node, parent_result_loc, |
| 11863 | parent_result_loc->source_node, ptr_type, |
| 11864 | result_cast->base.source_instruction->source_node, false, false); |
| 11854 | 11865 | return result_loc->resolved_loc; |
| 11855 | 11866 | } |
| 11856 | 11867 | case ResultLocIdBitCast: { |
| ... | ... | @@ -11863,13 +11874,13 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 11863 | 11874 | if ((err = get_codegen_ptr_type(ira->codegen, dest_type, &dest_cg_ptr_type))) |
| 11864 | 11875 | return ira->codegen->invalid_inst_gen; |
| 11865 | 11876 | if (dest_cg_ptr_type != nullptr) { |
| 11866 | | ir_add_error(ira, &result_loc->source_instruction->base, |
| 11877 | ir_add_error_node(ira, result_loc->source_instruction->source_node, |
| 11867 | 11878 | buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name))); |
| 11868 | 11879 | return ira->codegen->invalid_inst_gen; |
| 11869 | 11880 | } |
| 11870 | 11881 | |
| 11871 | 11882 | if (!type_can_bit_cast(dest_type)) { |
| 11872 | | ir_add_error(ira, &result_loc->source_instruction->base, |
| 11883 | ir_add_error_node(ira, result_loc->source_instruction->source_node, |
| 11873 | 11884 | buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name))); |
| 11874 | 11885 | return ira->codegen->invalid_inst_gen; |
| 11875 | 11886 | } |
| ... | ... | @@ -11878,20 +11889,21 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 11878 | 11889 | if ((err = get_codegen_ptr_type(ira->codegen, value_type, &value_cg_ptr_type))) |
| 11879 | 11890 | return ira->codegen->invalid_inst_gen; |
| 11880 | 11891 | if (value_cg_ptr_type != nullptr) { |
| 11881 | | ir_add_error(ira, suspend_source_instr, |
| 11892 | ir_add_error_node(ira, suspend_source_instr->source_node, |
| 11882 | 11893 | buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name))); |
| 11883 | 11894 | return ira->codegen->invalid_inst_gen; |
| 11884 | 11895 | } |
| 11885 | 11896 | |
| 11886 | 11897 | if (!type_can_bit_cast(value_type)) { |
| 11887 | | ir_add_error(ira, suspend_source_instr, |
| 11898 | ir_add_error_node(ira, suspend_source_instr->source_node, |
| 11888 | 11899 | buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&value_type->name))); |
| 11889 | 11900 | return ira->codegen->invalid_inst_gen; |
| 11890 | 11901 | } |
| 11891 | 11902 | |
| 11892 | 11903 | IrInstGen *bitcasted_value; |
| 11893 | 11904 | if (value != nullptr) { |
| 11894 | | bitcasted_value = ir_analyze_bit_cast(ira, &result_loc->source_instruction->base, value, dest_type); |
| 11905 | bitcasted_value = ir_analyze_bit_cast(ira, result_loc->source_instruction->scope, |
| 11906 | result_loc->source_instruction->source_node, value, dest_type); |
| 11895 | 11907 | dest_type = bitcasted_value->value->type; |
| 11896 | 11908 | } else { |
| 11897 | 11909 | bitcasted_value = nullptr; |
| ... | ... | @@ -11943,15 +11955,17 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 11943 | 11955 | parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero); |
| 11944 | 11956 | |
| 11945 | 11957 | result_loc->written = true; |
| 11946 | | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc, |
| 11947 | | &parent_result_loc->base, ptr_type, &result_bit_cast->base.source_instruction->base, false, false); |
| 11958 | result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr->scope, |
| 11959 | suspend_source_instr->source_node, parent_result_loc, |
| 11960 | parent_result_loc->source_node, ptr_type, |
| 11961 | result_bit_cast->base.source_instruction->source_node, false, false); |
| 11948 | 11962 | return result_loc->resolved_loc; |
| 11949 | 11963 | } |
| 11950 | 11964 | } |
| 11951 | 11965 | zig_unreachable(); |
| 11952 | 11966 | } |
| 11953 | 11967 | |
| 11954 | | static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr, |
| 11968 | static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInstSrc *suspend_source_instr, |
| 11955 | 11969 | ResultLoc *result_loc_pass1, ZigType *value_type, IrInstGen *value, bool force_runtime, |
| 11956 | 11970 | bool allow_discard) |
| 11957 | 11971 | { |
| ... | ... | @@ -11994,7 +12008,7 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr |
| 11994 | 12008 | field->type_entry = value_type; |
| 11995 | 12009 | field->type_val = create_const_type(ira->codegen, field->type_entry); |
| 11996 | 12010 | field->src_index = old_field_count; |
| 11997 | | field->decl_node = value ? value->base.source_node : suspend_source_instr->source_node; |
| 12011 | field->decl_node = value ? value->source_node : suspend_source_instr->source_node; |
| 11998 | 12012 | if (value && instr_is_comptime(value)) { |
| 11999 | 12013 | ZigValue *val = ir_resolve_const(ira, value, UndefOk); |
| 12000 | 12014 | if (!val) |
| ... | ... | @@ -12007,7 +12021,8 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr |
| 12007 | 12021 | |
| 12008 | 12022 | ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false); |
| 12009 | 12023 | if (instr_is_comptime(result_loc)) { |
| 12010 | | casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type); |
| 12024 | casted_ptr = ir_const(ira, suspend_source_instr->scope, |
| 12025 | suspend_source_instr->source_node, struct_ptr_type); |
| 12011 | 12026 | copy_const_val(ira->codegen, casted_ptr->value, result_loc->value); |
| 12012 | 12027 | casted_ptr->value->type = struct_ptr_type; |
| 12013 | 12028 | } else { |
| ... | ... | @@ -12034,7 +12049,8 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr |
| 12034 | 12049 | } |
| 12035 | 12050 | } |
| 12036 | 12051 | |
| 12037 | | result_loc = ir_analyze_struct_field_ptr(ira, suspend_source_instr, field, casted_ptr, |
| 12052 | result_loc = ir_analyze_struct_field_ptr(ira, suspend_source_instr->scope, |
| 12053 | suspend_source_instr->source_node, field, casted_ptr, |
| 12038 | 12054 | isf->inferred_struct_type, true); |
| 12039 | 12055 | if (type_is_invalid(result_loc->value->type)) { |
| 12040 | 12056 | return result_loc; |
| ... | ... | @@ -12046,7 +12062,7 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr |
| 12046 | 12062 | return result_loc; |
| 12047 | 12063 | } |
| 12048 | 12064 | |
| 12049 | | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr); |
| 12065 | src_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr->source_node); |
| 12050 | 12066 | ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type; |
| 12051 | 12067 | if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && |
| 12052 | 12068 | value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined) |
| ... | ... | @@ -12054,21 +12070,25 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr |
| 12054 | 12070 | bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, actual_elem_type, value_type); |
| 12055 | 12071 | if (!same_comptime_repr) { |
| 12056 | 12072 | result_loc_pass1->written = was_written; |
| 12057 | | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true); |
| 12073 | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr->scope, |
| 12074 | suspend_source_instr->source_node, result_loc, false, true); |
| 12058 | 12075 | } |
| 12059 | 12076 | } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion && |
| 12060 | 12077 | value_type->id != ZigTypeIdUndefined) |
| 12061 | 12078 | { |
| 12062 | 12079 | if (value_type->id == ZigTypeIdErrorSet) { |
| 12063 | | return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true); |
| 12080 | return ir_analyze_unwrap_err_code(ira, suspend_source_instr->scope, |
| 12081 | suspend_source_instr->source_node, result_loc, true); |
| 12064 | 12082 | } else { |
| 12065 | | IrInstGen *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr, |
| 12083 | IrInstGen *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, |
| 12084 | suspend_source_instr->scope, suspend_source_instr->source_node, |
| 12066 | 12085 | result_loc, false, true); |
| 12067 | 12086 | ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type; |
| 12068 | 12087 | if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && |
| 12069 | 12088 | value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined) |
| 12070 | 12089 | { |
| 12071 | | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, unwrapped_err_ptr, false, true); |
| 12090 | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr->scope, |
| 12091 | suspend_source_instr->source_node, unwrapped_err_ptr, false, true); |
| 12072 | 12092 | } else { |
| 12073 | 12093 | return unwrapped_err_ptr; |
| 12074 | 12094 | } |
| ... | ... | @@ -12095,17 +12115,17 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr |
| 12095 | 12115 | if (implicit_elem_type == ira->codegen->builtin_types.entry_anytype) { |
| 12096 | 12116 | Buf *bare_name = buf_alloc(); |
| 12097 | 12117 | Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct), |
| 12098 | | instruction->base.base.scope, instruction->base.base.source_node, bare_name); |
| 12118 | instruction->base.scope, instruction->base.source_node, bare_name); |
| 12099 | 12119 | |
| 12100 | 12120 | StructSpecial struct_special = StructSpecialInferredStruct; |
| 12101 | | if (instruction->base.base.source_node->type == NodeTypeContainerInitExpr && |
| 12102 | | instruction->base.base.source_node->data.container_init_expr.kind == ContainerInitKindArray) |
| 12121 | if (instruction->base.source_node->type == NodeTypeContainerInitExpr && |
| 12122 | instruction->base.source_node->data.container_init_expr.kind == ContainerInitKindArray) |
| 12103 | 12123 | { |
| 12104 | 12124 | struct_special = StructSpecialInferredTuple; |
| 12105 | 12125 | } |
| 12106 | 12126 | |
| 12107 | 12127 | ZigType *inferred_struct_type = get_partial_container_type(ira->codegen, |
| 12108 | | instruction->base.base.scope, ContainerKindStruct, instruction->base.base.source_node, |
| 12128 | instruction->base.scope, ContainerKindStruct, instruction->base.source_node, |
| 12109 | 12129 | buf_ptr(name), bare_name, ContainerLayoutAuto); |
| 12110 | 12130 | inferred_struct_type->data.structure.special = struct_special; |
| 12111 | 12131 | inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred; |
| ... | ... | @@ -12116,7 +12136,7 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr |
| 12116 | 12136 | if (type_is_invalid(implicit_elem_type)) |
| 12117 | 12137 | return ira->codegen->invalid_inst_gen; |
| 12118 | 12138 | } |
| 12119 | | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 12139 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 12120 | 12140 | implicit_elem_type, nullptr, false, true); |
| 12121 | 12141 | if (result_loc != nullptr) |
| 12122 | 12142 | return result_loc; |
| ... | ... | @@ -12125,7 +12145,7 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr |
| 12125 | 12145 | if (fn != nullptr && fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync && |
| 12126 | 12146 | instruction->result_loc->id == ResultLocIdReturn) |
| 12127 | 12147 | { |
| 12128 | | result_loc = ir_resolve_result(ira, &instruction->base.base, no_result_loc(), |
| 12148 | result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(), |
| 12129 | 12149 | implicit_elem_type, nullptr, false, true); |
| 12130 | 12150 | if (result_loc != nullptr && |
| 12131 | 12151 | (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) |
| ... | ... | @@ -12136,9 +12156,9 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr |
| 12136 | 12156 | return result_loc; |
| 12137 | 12157 | } |
| 12138 | 12158 | |
| 12139 | | IrInstGen *result = ir_const(ira, &instruction->base.base, implicit_elem_type); |
| 12159 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, implicit_elem_type); |
| 12140 | 12160 | result->value->special = ConstValSpecialUndef; |
| 12141 | | IrInstGen *ptr = ir_get_ref(ira, &instruction->base.base, result, false, false); |
| 12161 | IrInstGen *ptr = ir_get_ref(ira, instruction->base.scope, instruction->base.source_node, result, false, false); |
| 12142 | 12162 | ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar; |
| 12143 | 12163 | return ptr; |
| 12144 | 12164 | } |
| ... | ... | @@ -12180,14 +12200,14 @@ static void ir_reset_result(ResultLoc *result_loc) { |
| 12180 | 12200 | |
| 12181 | 12201 | static IrInstGen *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstSrcResetResult *instruction) { |
| 12182 | 12202 | ir_reset_result(instruction->result_loc); |
| 12183 | | return ir_const_void(ira, &instruction->base.base); |
| 12203 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 12184 | 12204 | } |
| 12185 | 12205 | |
| 12186 | | static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, IrInst* source_instr, |
| 12206 | static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 12187 | 12207 | ZigType *fn_ret_type, bool is_async_call_builtin, IrInstGen **args_ptr, size_t args_len, |
| 12188 | 12208 | IrInstGen *ret_ptr_uncasted) |
| 12189 | 12209 | { |
| 12190 | | ir_assert(is_async_call_builtin, source_instr); |
| 12210 | src_assert(is_async_call_builtin, source_node); |
| 12191 | 12211 | if (type_is_invalid(ret_ptr_uncasted->value->type)) |
| 12192 | 12212 | return ira->codegen->invalid_inst_gen; |
| 12193 | 12213 | if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) { |
| ... | ... | @@ -12197,47 +12217,47 @@ static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, IrInst* source_instr |
| 12197 | 12217 | return ir_implicit_cast(ira, ret_ptr_uncasted, get_pointer_to_type(ira->codegen, fn_ret_type, false)); |
| 12198 | 12218 | } |
| 12199 | 12219 | |
| 12200 | | static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, ZigFn *fn_entry, |
| 12220 | static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigFn *fn_entry, |
| 12201 | 12221 | ZigType *fn_type, IrInstGen *fn_ref, IrInstGen **casted_args, size_t arg_count, |
| 12202 | 12222 | IrInstGen *casted_new_stack, bool is_async_call_builtin, IrInstGen *ret_ptr_uncasted, |
| 12203 | 12223 | ResultLoc *call_result_loc) |
| 12204 | 12224 | { |
| 12205 | 12225 | if (fn_entry == nullptr) { |
| 12206 | 12226 | if (fn_type->data.fn.fn_type_id.cc != CallingConventionAsync) { |
| 12207 | | ir_add_error(ira, &fn_ref->base, |
| 12227 | ir_add_error(ira, fn_ref, |
| 12208 | 12228 | buf_sprintf("expected async function, found '%s'", buf_ptr(&fn_type->name))); |
| 12209 | 12229 | return ira->codegen->invalid_inst_gen; |
| 12210 | 12230 | } |
| 12211 | 12231 | if (casted_new_stack == nullptr) { |
| 12212 | | ir_add_error(ira, &fn_ref->base, buf_sprintf("function is not comptime-known; @asyncCall required")); |
| 12232 | ir_add_error(ira, fn_ref, buf_sprintf("function is not comptime-known; @asyncCall required")); |
| 12213 | 12233 | return ira->codegen->invalid_inst_gen; |
| 12214 | 12234 | } |
| 12215 | 12235 | } |
| 12216 | 12236 | if (casted_new_stack != nullptr) { |
| 12217 | 12237 | ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type; |
| 12218 | | IrInstGen *ret_ptr = get_async_call_result_loc(ira, source_instr, fn_ret_type, is_async_call_builtin, |
| 12238 | IrInstGen *ret_ptr = get_async_call_result_loc(ira, scope, source_node, fn_ret_type, is_async_call_builtin, |
| 12219 | 12239 | casted_args, arg_count, ret_ptr_uncasted); |
| 12220 | 12240 | if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type)) |
| 12221 | 12241 | return ira->codegen->invalid_inst_gen; |
| 12222 | 12242 | |
| 12223 | 12243 | ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type); |
| 12224 | 12244 | |
| 12225 | | IrInstGenCall *call_gen = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, |
| 12245 | IrInstGenCall *call_gen = ir_build_call_gen(ira, scope, source_node, fn_entry, fn_ref, |
| 12226 | 12246 | arg_count, casted_args, CallModifierAsync, casted_new_stack, |
| 12227 | 12247 | is_async_call_builtin, ret_ptr, anyframe_type); |
| 12228 | 12248 | return &call_gen->base; |
| 12229 | 12249 | } else { |
| 12230 | 12250 | ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry); |
| 12231 | | IrInstGen *result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 12251 | IrInstGen *result_loc = ir_resolve_result(ira, ira->suspend_source_instr, call_result_loc, |
| 12232 | 12252 | frame_type, nullptr, true, false); |
| 12233 | 12253 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 12234 | 12254 | return result_loc; |
| 12235 | 12255 | } |
| 12236 | | result_loc = ir_implicit_cast2(ira, source_instr, result_loc, |
| 12256 | result_loc = ir_implicit_cast2(ira, scope, source_node, result_loc, |
| 12237 | 12257 | get_pointer_to_type(ira->codegen, frame_type, false)); |
| 12238 | 12258 | if (type_is_invalid(result_loc->value->type)) |
| 12239 | 12259 | return ira->codegen->invalid_inst_gen; |
| 12240 | | return &ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, arg_count, |
| 12260 | return &ir_build_call_gen(ira, scope, source_node, fn_entry, fn_ref, arg_count, |
| 12241 | 12261 | casted_args, CallModifierAsync, casted_new_stack, |
| 12242 | 12262 | is_async_call_builtin, result_loc, frame_type)->base; |
| 12243 | 12263 | } |
| ... | ... | @@ -12276,7 +12296,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 12276 | 12296 | } |
| 12277 | 12297 | |
| 12278 | 12298 | static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node, |
| 12279 | | IrInstGen *arg, IrInst *arg_src, Scope **child_scope, size_t *next_proto_i, |
| 12299 | IrInstGen *arg, AstNode *arg_src, Scope **child_scope, size_t *next_proto_i, |
| 12280 | 12300 | GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstGen **casted_args, |
| 12281 | 12301 | ZigFn *impl_fn) |
| 12282 | 12302 | { |
| ... | ... | @@ -12298,7 +12318,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 12298 | 12318 | if (type_is_invalid(param_type)) |
| 12299 | 12319 | return false; |
| 12300 | 12320 | |
| 12301 | | casted_arg = ir_implicit_cast2(ira, arg_src, arg, param_type); |
| 12321 | casted_arg = ir_implicit_cast2(ira, arg->scope, arg_src, arg, param_type); |
| 12302 | 12322 | if (type_is_invalid(casted_arg->value->type)) |
| 12303 | 12323 | return false; |
| 12304 | 12324 | |
| ... | ... | @@ -12326,7 +12346,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 12326 | 12346 | ZigValue *arg_val; |
| 12327 | 12347 | |
| 12328 | 12348 | if (comptime_arg && !instr_is_comptime(casted_arg)) { |
| 12329 | | ir_add_error(ira, &casted_arg->base, |
| 12349 | ir_add_error(ira, casted_arg, |
| 12330 | 12350 | buf_sprintf("runtime value cannot be passed to comptime arg")); |
| 12331 | 12351 | return false; |
| 12332 | 12352 | } |
| ... | ... | @@ -12355,7 +12375,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 12355 | 12375 | } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt || |
| 12356 | 12376 | casted_arg->value->type->id == ZigTypeIdComptimeFloat) |
| 12357 | 12377 | { |
| 12358 | | ir_add_error(ira, &casted_arg->base, |
| 12378 | ir_add_error(ira, casted_arg, |
| 12359 | 12379 | buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557")); |
| 12360 | 12380 | return false; |
| 12361 | 12381 | } |
| ... | ... | @@ -12372,7 +12392,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 12372 | 12392 | return true; |
| 12373 | 12393 | } |
| 12374 | 12394 | |
| 12375 | | static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) { |
| 12395 | static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigVar *var) { |
| 12376 | 12396 | while (var->next_var != nullptr) { |
| 12377 | 12397 | var = var->next_var; |
| 12378 | 12398 | } |
| ... | ... | @@ -12391,7 +12411,7 @@ static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *v |
| 12391 | 12411 | bool comptime_var_mem = ir_get_var_is_comptime(var); |
| 12392 | 12412 | bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern; |
| 12393 | 12413 | |
| 12394 | | IrInstGen *result = ir_build_var_ptr_gen(ira, source_instr, var); |
| 12414 | IrInstGen *result = ir_build_var_ptr_gen(ira, scope, source_node, var); |
| 12395 | 12415 | result->value->type = var_ptr_type; |
| 12396 | 12416 | |
| 12397 | 12417 | if (!linkage_makes_it_runtime && !var->is_thread_local && value_is_comptime(var->const_value)) { |
| ... | ... | @@ -12427,20 +12447,20 @@ static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *v |
| 12427 | 12447 | } |
| 12428 | 12448 | |
| 12429 | 12449 | // This function is called when a comptime value becomes accessible at runtime. |
| 12430 | | static void mark_comptime_value_escape(IrAnalyze *ira, IrInst* source_instr, ZigValue *val) { |
| 12431 | | ir_assert(value_is_comptime(val), source_instr); |
| 12450 | static void mark_comptime_value_escape(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigValue *val) { |
| 12451 | src_assert(value_is_comptime(val), source_node); |
| 12432 | 12452 | if (val->special == ConstValSpecialUndef) |
| 12433 | 12453 | return; |
| 12434 | 12454 | |
| 12435 | 12455 | if (val->type->id == ZigTypeIdFn && val->type->data.fn.fn_type_id.cc == CallingConventionUnspecified) { |
| 12436 | | ir_assert(val->data.x_ptr.special == ConstPtrSpecialFunction, source_instr); |
| 12456 | src_assert(val->data.x_ptr.special == ConstPtrSpecialFunction, source_node); |
| 12437 | 12457 | if (val->data.x_ptr.data.fn.fn_entry->non_async_node == nullptr) { |
| 12438 | | val->data.x_ptr.data.fn.fn_entry->non_async_node = source_instr->source_node; |
| 12458 | val->data.x_ptr.data.fn.fn_entry->non_async_node = source_node; |
| 12439 | 12459 | } |
| 12440 | 12460 | } |
| 12441 | 12461 | } |
| 12442 | 12462 | |
| 12443 | | static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 12463 | static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 12444 | 12464 | IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const) |
| 12445 | 12465 | { |
| 12446 | 12466 | assert(ptr->value->type->id == ZigTypeIdPointer); |
| ... | ... | @@ -12449,14 +12469,14 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 12449 | 12469 | if (uncasted_value->value->type->id == ZigTypeIdErrorUnion || |
| 12450 | 12470 | uncasted_value->value->type->id == ZigTypeIdErrorSet) |
| 12451 | 12471 | { |
| 12452 | | ir_add_error(ira, source_instr, buf_sprintf("error is discarded. consider using `try`, `catch`, or `if`")); |
| 12472 | ir_add_error_node(ira, source_node, buf_sprintf("error is discarded. consider using `try`, `catch`, or `if`")); |
| 12453 | 12473 | return ira->codegen->invalid_inst_gen; |
| 12454 | 12474 | } |
| 12455 | | return ir_const_void(ira, source_instr); |
| 12475 | return ir_const_void(ira, scope, source_node); |
| 12456 | 12476 | } |
| 12457 | 12477 | |
| 12458 | 12478 | if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) { |
| 12459 | | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); |
| 12479 | ir_add_error_node(ira, source_node, buf_sprintf("cannot assign to constant")); |
| 12460 | 12480 | return ira->codegen->invalid_inst_gen; |
| 12461 | 12481 | } |
| 12462 | 12482 | |
| ... | ... | @@ -12469,14 +12489,14 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 12469 | 12489 | case OnePossibleValueInvalid: |
| 12470 | 12490 | return ira->codegen->invalid_inst_gen; |
| 12471 | 12491 | case OnePossibleValueYes: |
| 12472 | | return ir_const_void(ira, source_instr); |
| 12492 | return ir_const_void(ira, scope, source_node); |
| 12473 | 12493 | case OnePossibleValueNo: |
| 12474 | 12494 | break; |
| 12475 | 12495 | } |
| 12476 | 12496 | |
| 12477 | 12497 | if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 12478 | 12498 | if (!allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) { |
| 12479 | | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); |
| 12499 | ir_add_error_node(ira, source_node, buf_sprintf("cannot assign to constant")); |
| 12480 | 12500 | return ira->codegen->invalid_inst_gen; |
| 12481 | 12501 | } |
| 12482 | 12502 | if ((allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) || |
| ... | ... | @@ -12484,24 +12504,24 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 12484 | 12504 | ptr->value->data.x_ptr.mut == ConstPtrMutInfer) |
| 12485 | 12505 | { |
| 12486 | 12506 | if (instr_is_comptime(value)) { |
| 12487 | | ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node); |
| 12507 | ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_node); |
| 12488 | 12508 | if (dest_val == nullptr) |
| 12489 | 12509 | return ira->codegen->invalid_inst_gen; |
| 12490 | 12510 | if (dest_val->special != ConstValSpecialRuntime) { |
| 12491 | 12511 | copy_const_val(ira->codegen, dest_val, value->value); |
| 12492 | 12512 | |
| 12493 | 12513 | if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar && |
| 12494 | | !ira->new_irb.current_basic_block->must_be_comptime_source_instr) |
| 12514 | ira->new_irb.current_basic_block->must_be_comptime_source_node == nullptr) |
| 12495 | 12515 | { |
| 12496 | | ira->new_irb.current_basic_block->must_be_comptime_source_instr = source_instr; |
| 12516 | ira->new_irb.current_basic_block->must_be_comptime_source_node = source_node; |
| 12497 | 12517 | } |
| 12498 | | return ir_const_void(ira, source_instr); |
| 12518 | return ir_const_void(ira, scope, source_node); |
| 12499 | 12519 | } |
| 12500 | 12520 | } |
| 12501 | 12521 | if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 12502 | 12522 | ptr->value->special = ConstValSpecialRuntime; |
| 12503 | 12523 | } else { |
| 12504 | | ir_add_error(ira, source_instr, |
| 12524 | ir_add_error_node(ira, source_node, |
| 12505 | 12525 | buf_sprintf("cannot store runtime value in compile time variable")); |
| 12506 | 12526 | ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value); |
| 12507 | 12527 | dest_val->type = ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -12525,11 +12545,11 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 12525 | 12545 | case OnePossibleValueInvalid: |
| 12526 | 12546 | return ira->codegen->invalid_inst_gen; |
| 12527 | 12547 | case OnePossibleValueNo: |
| 12528 | | ir_add_error(ira, source_instr, |
| 12548 | ir_add_error_node(ira, source_node, |
| 12529 | 12549 | buf_sprintf("cannot store runtime value in type '%s'", buf_ptr(&child_type->name))); |
| 12530 | 12550 | return ira->codegen->invalid_inst_gen; |
| 12531 | 12551 | case OnePossibleValueYes: |
| 12532 | | return ir_const_void(ira, source_instr); |
| 12552 | return ir_const_void(ira, scope, source_node); |
| 12533 | 12553 | } |
| 12534 | 12554 | zig_unreachable(); |
| 12535 | 12555 | case ReqCompTimeNo: |
| ... | ... | @@ -12537,7 +12557,7 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 12537 | 12557 | } |
| 12538 | 12558 | |
| 12539 | 12559 | if (instr_is_comptime(value)) { |
| 12540 | | mark_comptime_value_escape(ira, source_instr, value->value); |
| 12560 | mark_comptime_value_escape(ira, scope, source_node, value->value); |
| 12541 | 12561 | } |
| 12542 | 12562 | |
| 12543 | 12563 | // If this is a store to a pointer with a runtime-known vector index, |
| ... | ... | @@ -12549,20 +12569,20 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 12549 | 12569 | if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) { |
| 12550 | 12570 | if (ptr->id == IrInstGenIdElemPtr) { |
| 12551 | 12571 | IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr; |
| 12552 | | return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr, |
| 12572 | return ir_build_vector_store_elem(ira, scope, source_node, elem_ptr->array_ptr, |
| 12553 | 12573 | elem_ptr->elem_index, value); |
| 12554 | 12574 | } |
| 12555 | | ir_add_error(ira, &ptr->base, |
| 12575 | ir_add_error(ira, ptr, |
| 12556 | 12576 | buf_sprintf("unable to determine vector element index of type '%s'", |
| 12557 | 12577 | buf_ptr(&ptr->value->type->name))); |
| 12558 | 12578 | return ira->codegen->invalid_inst_gen; |
| 12559 | 12579 | } |
| 12560 | 12580 | |
| 12561 | | return ir_build_store_ptr_gen(ira, source_instr, ptr, value); |
| 12581 | return ir_build_store_ptr_gen(ira, scope, source_node, ptr, value); |
| 12562 | 12582 | } |
| 12563 | 12583 | |
| 12564 | | static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr, |
| 12565 | | IrInstGen *new_stack, IrInst *new_stack_src, bool is_async_call_builtin, ZigFn *fn_entry) |
| 12584 | static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 12585 | IrInstGen *new_stack, AstNode *new_stack_src, bool is_async_call_builtin, ZigFn *fn_entry) |
| 12566 | 12586 | { |
| 12567 | 12587 | if (new_stack == nullptr) |
| 12568 | 12588 | return nullptr; |
| ... | ... | @@ -12570,7 +12590,7 @@ static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr, |
| 12570 | 12590 | if (!is_async_call_builtin && |
| 12571 | 12591 | arch_stack_pointer_register_name(ira->codegen->zig_target->arch) == nullptr) |
| 12572 | 12592 | { |
| 12573 | | ir_add_error(ira, source_instr, |
| 12593 | ir_add_error_node(ira, source_node, |
| 12574 | 12594 | buf_sprintf("target arch '%s' does not support calling with a new stack", |
| 12575 | 12595 | target_arch_name(ira->codegen->zig_target->arch))); |
| 12576 | 12596 | } |
| ... | ... | @@ -12591,14 +12611,14 @@ static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr, |
| 12591 | 12611 | false, false, PtrLenUnknown, required_align, 0, 0, false); |
| 12592 | 12612 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 12593 | 12613 | ira->codegen->need_frame_size_prefix_data = true; |
| 12594 | | return ir_implicit_cast2(ira, new_stack_src, new_stack, u8_slice); |
| 12614 | return ir_implicit_cast2(ira, new_stack->scope, new_stack_src, new_stack, u8_slice); |
| 12595 | 12615 | } |
| 12596 | 12616 | } |
| 12597 | 12617 | |
| 12598 | | static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12618 | static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 12599 | 12619 | ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref, |
| 12600 | | IrInstGen *first_arg_ptr, IrInst *first_arg_ptr_src, CallModifier modifier, |
| 12601 | | IrInstGen *new_stack, IrInst *new_stack_src, bool is_async_call_builtin, |
| 12620 | IrInstGen *first_arg_ptr, AstNode *first_arg_ptr_src, CallModifier modifier, |
| 12621 | IrInstGen *new_stack, AstNode *new_stack_src, bool is_async_call_builtin, |
| 12602 | 12622 | IrInstGen **args_ptr, size_t args_len, IrInstGen *ret_ptr, ResultLoc *call_result_loc) |
| 12603 | 12623 | { |
| 12604 | 12624 | Error err; |
| ... | ... | @@ -12615,12 +12635,11 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12615 | 12635 | } |
| 12616 | 12636 | size_t src_param_count = fn_type_id->param_count - var_args_1_or_0; |
| 12617 | 12637 | size_t call_param_count = args_len + first_arg_1_or_0; |
| 12618 | | AstNode *source_node = source_instr->source_node; |
| 12619 | 12638 | |
| 12620 | 12639 | AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;; |
| 12621 | 12640 | |
| 12622 | 12641 | if (fn_type_id->cc == CallingConventionNaked) { |
| 12623 | | ErrorMsg *msg = ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to call function with naked calling convention")); |
| 12642 | ErrorMsg *msg = ir_add_error(ira, fn_ref, buf_sprintf("unable to call function with naked calling convention")); |
| 12624 | 12643 | if (fn_proto_node) { |
| 12625 | 12644 | add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here")); |
| 12626 | 12645 | } |
| ... | ... | @@ -12652,25 +12671,25 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12652 | 12671 | if (modifier == CallModifierCompileTime) { |
| 12653 | 12672 | // If we are evaluating an extern function in a TypeOf call, we can return an undefined value |
| 12654 | 12673 | // of its return type. |
| 12655 | | if (fn_entry != nullptr && get_scope_typeof(source_instr->scope) != nullptr && |
| 12674 | if (fn_entry != nullptr && get_scope_typeof(scope) != nullptr && |
| 12656 | 12675 | fn_proto_node->data.fn_proto.is_extern) { |
| 12657 | 12676 | |
| 12658 | 12677 | assert(fn_entry->body_node == nullptr); |
| 12659 | 12678 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; |
| 12660 | | ZigType *return_type = ir_analyze_type_expr(ira, source_instr->scope, return_type_node); |
| 12679 | ZigType *return_type = ir_analyze_type_expr(ira, scope, return_type_node); |
| 12661 | 12680 | if (type_is_invalid(return_type)) |
| 12662 | 12681 | return ira->codegen->invalid_inst_gen; |
| 12663 | 12682 | |
| 12664 | | return ir_const_undef(ira, source_instr, return_type); |
| 12683 | return ir_const_undef(ira, scope, source_node, return_type); |
| 12665 | 12684 | } |
| 12666 | 12685 | |
| 12667 | 12686 | // No special handling is needed for compile time evaluation of generic functions. |
| 12668 | 12687 | if (!fn_entry || fn_entry->body_node == nullptr) { |
| 12669 | | ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to evaluate constant expression")); |
| 12688 | ir_add_error(ira, fn_ref, buf_sprintf("unable to evaluate constant expression")); |
| 12670 | 12689 | return ira->codegen->invalid_inst_gen; |
| 12671 | 12690 | } |
| 12672 | 12691 | |
| 12673 | | if (!ir_emit_backward_branch(ira, source_instr)) |
| 12692 | if (!ir_emit_backward_branch(ira, source_node)) |
| 12674 | 12693 | return ira->codegen->invalid_inst_gen; |
| 12675 | 12694 | |
| 12676 | 12695 | // Fork a scope of the function with known values for the parameters. |
| ... | ... | @@ -12692,7 +12711,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12692 | 12711 | if (!first_arg_known_bare) { |
| 12693 | 12712 | first_arg = first_arg_ptr; |
| 12694 | 12713 | } else { |
| 12695 | | first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr); |
| 12714 | first_arg = ir_get_deref(ira, first_arg_ptr->scope, first_arg_ptr->source_node, first_arg_ptr, nullptr); |
| 12696 | 12715 | if (type_is_invalid(first_arg->value->type)) |
| 12697 | 12716 | return ira->codegen->invalid_inst_gen; |
| 12698 | 12717 | } |
| ... | ... | @@ -12710,7 +12729,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12710 | 12729 | |
| 12711 | 12730 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; |
| 12712 | 12731 | if (return_type_node == nullptr) { |
| 12713 | | ir_add_error(ira, &fn_ref->base, |
| 12732 | ir_add_error(ira, fn_ref, |
| 12714 | 12733 | buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447")); |
| 12715 | 12734 | return ira->codegen->invalid_inst_gen; |
| 12716 | 12735 | } |
| ... | ... | @@ -12744,7 +12763,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12744 | 12763 | |
| 12745 | 12764 | if ((err = ir_eval_const_value(ira->codegen, exec_scope, body_node, result_ptr, |
| 12746 | 12765 | ira->backward_branch_count, ira->backward_branch_quota, |
| 12747 | | fn_entry, nullptr, source_instr->source_node, nullptr, ira->new_irb.exec, return_type_node, |
| 12766 | fn_entry, nullptr, source_node, nullptr, ira->new_irb.exec, return_type_node, |
| 12748 | 12767 | UndefOk))) |
| 12749 | 12768 | { |
| 12750 | 12769 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -12777,13 +12796,13 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12777 | 12796 | } |
| 12778 | 12797 | } |
| 12779 | 12798 | |
| 12780 | | IrInstGen *new_instruction = ir_const_move(ira, source_instr, result); |
| 12799 | IrInstGen *new_instruction = ir_const_move(ira, scope, source_node, result); |
| 12781 | 12800 | return ir_finish_anal(ira, new_instruction); |
| 12782 | 12801 | } |
| 12783 | 12802 | |
| 12784 | 12803 | if (fn_type->data.fn.is_generic) { |
| 12785 | 12804 | if (!fn_entry) { |
| 12786 | | ir_add_error(ira, &fn_ref->base, |
| 12805 | ir_add_error(ira, fn_ref, |
| 12787 | 12806 | buf_sprintf("calling a generic function requires compile-time known function value")); |
| 12788 | 12807 | return ira->codegen->invalid_inst_gen; |
| 12789 | 12808 | } |
| ... | ... | @@ -12827,7 +12846,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12827 | 12846 | if (!first_arg_known_bare) { |
| 12828 | 12847 | first_arg = first_arg_ptr; |
| 12829 | 12848 | } else { |
| 12830 | | first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr); |
| 12849 | first_arg = ir_get_deref(ira, first_arg_ptr->scope, first_arg_ptr->source_node, |
| 12850 | first_arg_ptr, nullptr); |
| 12831 | 12851 | if (type_is_invalid(first_arg->value->type)) |
| 12832 | 12852 | return ira->codegen->invalid_inst_gen; |
| 12833 | 12853 | } |
| ... | ... | @@ -12847,7 +12867,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12847 | 12867 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i); |
| 12848 | 12868 | assert(param_decl_node->type == NodeTypeParamDecl); |
| 12849 | 12869 | |
| 12850 | | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &arg->base, &impl_fn->child_scope, |
| 12870 | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, arg->source_node, |
| 12871 | &impl_fn->child_scope, |
| 12851 | 12872 | &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn)) |
| 12852 | 12873 | { |
| 12853 | 12874 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -12882,7 +12903,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12882 | 12903 | return ira->codegen->invalid_inst_gen; |
| 12883 | 12904 | |
| 12884 | 12905 | if(!is_valid_return_type(specified_return_type)){ |
| 12885 | | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 12906 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 12886 | 12907 | buf_sprintf("call to generic function with %s return type '%s' not allowed", type_id_name(specified_return_type->id), buf_ptr(&specified_return_type->name))); |
| 12887 | 12908 | add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("function declared here")); |
| 12888 | 12909 | |
| ... | ... | @@ -12905,7 +12926,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12905 | 12926 | switch (type_requires_comptime(ira->codegen, specified_return_type)) { |
| 12906 | 12927 | case ReqCompTimeYes: |
| 12907 | 12928 | // Throw out our work and call the function as if it were comptime. |
| 12908 | | return ir_analyze_fn_call(ira, source_instr, fn_entry, fn_type, fn_ref, first_arg_ptr, |
| 12929 | return ir_analyze_fn_call(ira, scope, source_node, fn_entry, fn_type, fn_ref, first_arg_ptr, |
| 12909 | 12930 | first_arg_ptr_src, CallModifierCompileTime, new_stack, new_stack_src, is_async_call_builtin, |
| 12910 | 12931 | args_ptr, args_len, ret_ptr, call_result_loc); |
| 12911 | 12932 | case ReqCompTimeInvalid: |
| ... | ... | @@ -12924,7 +12945,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12924 | 12945 | if (type_is_invalid(impl_fn->type_entry)) |
| 12925 | 12946 | return ira->codegen->invalid_inst_gen; |
| 12926 | 12947 | |
| 12927 | | impl_fn->analyzed_executable.source_node = source_instr->source_node; |
| 12948 | impl_fn->analyzed_executable.source_node = source_node; |
| 12928 | 12949 | impl_fn->analyzed_executable.parent_exec = ira->new_irb.exec; |
| 12929 | 12950 | impl_fn->branch_quota = *ira->backward_branch_quota; |
| 12930 | 12951 | |
| ... | ... | @@ -12937,14 +12958,14 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12937 | 12958 | parent_fn_entry->calls_or_awaits_errorable_fn = true; |
| 12938 | 12959 | } |
| 12939 | 12960 | |
| 12940 | | IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, |
| 12961 | IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, scope, source_node, new_stack, |
| 12941 | 12962 | new_stack_src, is_async_call_builtin, impl_fn); |
| 12942 | 12963 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) |
| 12943 | 12964 | return ira->codegen->invalid_inst_gen; |
| 12944 | 12965 | |
| 12945 | 12966 | size_t impl_param_count = impl_fn_type_id->param_count; |
| 12946 | 12967 | if (modifier == CallModifierAsync) { |
| 12947 | | IrInstGen *result = ir_analyze_async_call(ira, source_instr, impl_fn, impl_fn->type_entry, |
| 12968 | IrInstGen *result = ir_analyze_async_call(ira, scope, source_node, impl_fn, impl_fn->type_entry, |
| 12948 | 12969 | nullptr, casted_args, impl_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, |
| 12949 | 12970 | call_result_loc); |
| 12950 | 12971 | return ir_finish_anal(ira, result); |
| ... | ... | @@ -12952,20 +12973,20 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12952 | 12973 | |
| 12953 | 12974 | IrInstGen *result_loc; |
| 12954 | 12975 | if (handle_is_ptr(ira->codegen, impl_fn_type_id->return_type)) { |
| 12955 | | result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 12976 | result_loc = ir_resolve_result(ira, ira->suspend_source_instr, call_result_loc, |
| 12956 | 12977 | impl_fn_type_id->return_type, nullptr, true, false); |
| 12957 | 12978 | if (result_loc != nullptr) { |
| 12958 | 12979 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 12959 | 12980 | return result_loc; |
| 12960 | 12981 | } |
| 12961 | 12982 | if (result_loc->value->type->data.pointer.is_const) { |
| 12962 | | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); |
| 12983 | ir_add_error_node(ira, source_node, buf_sprintf("cannot assign to constant")); |
| 12963 | 12984 | return ira->codegen->invalid_inst_gen; |
| 12964 | 12985 | } |
| 12965 | 12986 | |
| 12966 | | IrInstGen *dummy_value = ir_const(ira, source_instr, impl_fn_type_id->return_type); |
| 12987 | IrInstGen *dummy_value = ir_const(ira, scope, source_node, impl_fn_type_id->return_type); |
| 12967 | 12988 | dummy_value->value->special = ConstValSpecialRuntime; |
| 12968 | | IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr, |
| 12989 | IrInstGen *dummy_result = ir_implicit_cast2(ira, scope, source_node, |
| 12969 | 12990 | dummy_value, result_loc->value->type->data.pointer.child_type); |
| 12970 | 12991 | if (type_is_invalid(dummy_result->value->type)) |
| 12971 | 12992 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -12979,7 +13000,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12979 | 13000 | } |
| 12980 | 13001 | } |
| 12981 | 13002 | } else if (is_async_call_builtin) { |
| 12982 | | result_loc = get_async_call_result_loc(ira, source_instr, impl_fn_type_id->return_type, |
| 13003 | result_loc = get_async_call_result_loc(ira, scope, source_node, impl_fn_type_id->return_type, |
| 12983 | 13004 | is_async_call_builtin, args_ptr, args_len, ret_ptr); |
| 12984 | 13005 | if (result_loc != nullptr && type_is_invalid(result_loc->value->type)) |
| 12985 | 13006 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -12991,15 +13012,15 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 12991 | 13012 | parent_fn_entry->inferred_async_node == nullptr && |
| 12992 | 13013 | modifier != CallModifierNoSuspend) |
| 12993 | 13014 | { |
| 12994 | | parent_fn_entry->inferred_async_node = fn_ref->base.source_node; |
| 13015 | parent_fn_entry->inferred_async_node = fn_ref->source_node; |
| 12995 | 13016 | parent_fn_entry->inferred_async_fn = impl_fn; |
| 12996 | 13017 | } |
| 12997 | 13018 | |
| 12998 | | IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr, |
| 13019 | IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, scope, source_node, |
| 12999 | 13020 | impl_fn, nullptr, impl_param_count, casted_args, modifier, casted_new_stack, |
| 13000 | 13021 | is_async_call_builtin, result_loc, impl_fn_type_id->return_type); |
| 13001 | 13022 | |
| 13002 | | if (get_scope_typeof(source_instr->scope) == nullptr) { |
| 13023 | if (get_scope_typeof(scope) == nullptr) { |
| 13003 | 13024 | parent_fn_entry->call_list.append(new_call_instruction); |
| 13004 | 13025 | } |
| 13005 | 13026 | |
| ... | ... | @@ -13027,12 +13048,13 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 13027 | 13048 | if (param_type->id == ZigTypeIdPointer) { |
| 13028 | 13049 | first_arg = first_arg_ptr; |
| 13029 | 13050 | } else { |
| 13030 | | first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr); |
| 13051 | first_arg = ir_get_deref(ira, first_arg_ptr->scope, first_arg_ptr->source_node, |
| 13052 | first_arg_ptr, nullptr); |
| 13031 | 13053 | if (type_is_invalid(first_arg->value->type)) |
| 13032 | 13054 | return ira->codegen->invalid_inst_gen; |
| 13033 | 13055 | } |
| 13034 | 13056 | |
| 13035 | | IrInstGen *casted_arg = ir_implicit_cast2(ira, first_arg_ptr_src, first_arg, param_type); |
| 13057 | IrInstGen *casted_arg = ir_implicit_cast2(ira, first_arg->scope, first_arg_ptr_src, first_arg, param_type); |
| 13036 | 13058 | if (type_is_invalid(casted_arg->value->type)) |
| 13037 | 13059 | return ira->codegen->invalid_inst_gen; |
| 13038 | 13060 | |
| ... | ... | @@ -13067,18 +13089,18 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 13067 | 13089 | return ira->codegen->invalid_inst_gen; |
| 13068 | 13090 | |
| 13069 | 13091 | if (fn_entry != nullptr && fn_type_id->cc == CallingConventionInline && modifier == CallModifierNeverInline) { |
| 13070 | | ir_add_error(ira, source_instr, |
| 13092 | ir_add_error_node(ira, source_node, |
| 13071 | 13093 | buf_sprintf("no-inline call of inline function")); |
| 13072 | 13094 | return ira->codegen->invalid_inst_gen; |
| 13073 | 13095 | } |
| 13074 | 13096 | |
| 13075 | | IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, new_stack_src, |
| 13097 | IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, scope, source_node, new_stack, new_stack_src, |
| 13076 | 13098 | is_async_call_builtin, fn_entry); |
| 13077 | 13099 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) |
| 13078 | 13100 | return ira->codegen->invalid_inst_gen; |
| 13079 | 13101 | |
| 13080 | 13102 | if (modifier == CallModifierAsync) { |
| 13081 | | IrInstGen *result = ir_analyze_async_call(ira, source_instr, fn_entry, fn_type, fn_ref, |
| 13103 | IrInstGen *result = ir_analyze_async_call(ira, scope, source_node, fn_entry, fn_type, fn_ref, |
| 13082 | 13104 | casted_args, call_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, call_result_loc); |
| 13083 | 13105 | return ir_finish_anal(ira, result); |
| 13084 | 13106 | } |
| ... | ... | @@ -13087,28 +13109,28 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 13087 | 13109 | parent_fn_entry->inferred_async_node == nullptr && |
| 13088 | 13110 | modifier != CallModifierNoSuspend) |
| 13089 | 13111 | { |
| 13090 | | parent_fn_entry->inferred_async_node = fn_ref->base.source_node; |
| 13112 | parent_fn_entry->inferred_async_node = fn_ref->source_node; |
| 13091 | 13113 | parent_fn_entry->inferred_async_fn = fn_entry; |
| 13092 | 13114 | } |
| 13093 | 13115 | |
| 13094 | 13116 | IrInstGen *result_loc; |
| 13095 | 13117 | if (handle_is_ptr(ira->codegen, return_type)) { |
| 13096 | | result_loc = ir_resolve_result(ira, source_instr, call_result_loc, |
| 13118 | result_loc = ir_resolve_result(ira, ira->suspend_source_instr, call_result_loc, |
| 13097 | 13119 | return_type, nullptr, true, false); |
| 13098 | 13120 | if (result_loc != nullptr) { |
| 13099 | 13121 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 13100 | 13122 | return result_loc; |
| 13101 | 13123 | } |
| 13102 | 13124 | if (result_loc->value->type->data.pointer.is_const) { |
| 13103 | | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); |
| 13125 | ir_add_error_node(ira, source_node, buf_sprintf("cannot assign to constant")); |
| 13104 | 13126 | return ira->codegen->invalid_inst_gen; |
| 13105 | 13127 | } |
| 13106 | 13128 | |
| 13107 | 13129 | ZigType *expected_return_type = result_loc->value->type->data.pointer.child_type; |
| 13108 | 13130 | |
| 13109 | | IrInstGen *dummy_value = ir_const(ira, source_instr, return_type); |
| 13131 | IrInstGen *dummy_value = ir_const(ira, scope, source_node, return_type); |
| 13110 | 13132 | dummy_value->value->special = ConstValSpecialRuntime; |
| 13111 | | IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr, |
| 13133 | IrInstGen *dummy_result = ir_implicit_cast2(ira, scope, source_node, |
| 13112 | 13134 | dummy_value, expected_return_type); |
| 13113 | 13135 | if (type_is_invalid(dummy_result->value->type)) { |
| 13114 | 13136 | if ((return_type->id == ZigTypeIdErrorUnion || return_type->id == ZigTypeIdErrorSet) && |
| ... | ... | @@ -13118,7 +13140,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 13118 | 13140 | add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg, |
| 13119 | 13141 | ira->explicit_return_type_source_node, buf_sprintf("function cannot return an error")); |
| 13120 | 13142 | } else { |
| 13121 | | add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg, result_loc->base.source_node, |
| 13143 | add_error_note(ira->codegen, ira->new_irb.exec->first_err_trace_msg, result_loc->source_node, |
| 13122 | 13144 | buf_sprintf("cannot store an error in type '%s'", buf_ptr(&expected_return_type->name))); |
| 13123 | 13145 | } |
| 13124 | 13146 | } |
| ... | ... | @@ -13133,7 +13155,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 13133 | 13155 | } |
| 13134 | 13156 | } |
| 13135 | 13157 | } else if (is_async_call_builtin) { |
| 13136 | | result_loc = get_async_call_result_loc(ira, source_instr, return_type, is_async_call_builtin, |
| 13158 | result_loc = get_async_call_result_loc(ira, scope, source_node, return_type, is_async_call_builtin, |
| 13137 | 13159 | args_ptr, args_len, ret_ptr); |
| 13138 | 13160 | if (result_loc != nullptr && type_is_invalid(result_loc->value->type)) |
| 13139 | 13161 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -13141,10 +13163,10 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 13141 | 13163 | result_loc = nullptr; |
| 13142 | 13164 | } |
| 13143 | 13165 | |
| 13144 | | IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, |
| 13166 | IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, scope, source_node, fn_entry, fn_ref, |
| 13145 | 13167 | call_param_count, casted_args, modifier, casted_new_stack, |
| 13146 | 13168 | is_async_call_builtin, result_loc, return_type); |
| 13147 | | if (get_scope_typeof(source_instr->scope) == nullptr) { |
| 13169 | if (get_scope_typeof(scope) == nullptr) { |
| 13148 | 13170 | parent_fn_entry->call_list.append(new_call_instruction); |
| 13149 | 13171 | } |
| 13150 | 13172 | return ir_finish_anal(ira, &new_call_instruction->base); |
| ... | ... | @@ -13152,15 +13174,15 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 13152 | 13174 | |
| 13153 | 13175 | static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_instruction, |
| 13154 | 13176 | ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref, |
| 13155 | | IrInstGen *first_arg_ptr, IrInst *first_arg_ptr_src, CallModifier modifier) |
| 13177 | IrInstGen *first_arg_ptr, AstNode *first_arg_ptr_src, CallModifier modifier) |
| 13156 | 13178 | { |
| 13157 | 13179 | IrInstGen *new_stack = nullptr; |
| 13158 | | IrInst *new_stack_src = nullptr; |
| 13180 | AstNode *new_stack_src = nullptr; |
| 13159 | 13181 | if (call_instruction->new_stack) { |
| 13160 | 13182 | new_stack = call_instruction->new_stack->child; |
| 13161 | 13183 | if (type_is_invalid(new_stack->value->type)) |
| 13162 | 13184 | return ira->codegen->invalid_inst_gen; |
| 13163 | | new_stack_src = &call_instruction->new_stack->base; |
| 13185 | new_stack_src = call_instruction->new_stack->source_node; |
| 13164 | 13186 | } |
| 13165 | 13187 | IrInstGen **args_ptr = heap::c_allocator.allocate<IrInstGen *>(call_instruction->arg_count); |
| 13166 | 13188 | for (size_t i = 0; i < call_instruction->arg_count; i += 1) { |
| ... | ... | @@ -13174,7 +13196,8 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins |
| 13174 | 13196 | if (type_is_invalid(ret_ptr->value->type)) |
| 13175 | 13197 | return ira->codegen->invalid_inst_gen; |
| 13176 | 13198 | } |
| 13177 | | IrInstGen *result = ir_analyze_fn_call(ira, &call_instruction->base.base, fn_entry, fn_type, fn_ref, |
| 13199 | IrInstGen *result = ir_analyze_fn_call(ira, call_instruction->base.scope, |
| 13200 | call_instruction->base.source_node, fn_entry, fn_type, fn_ref, |
| 13178 | 13201 | first_arg_ptr, first_arg_ptr_src, modifier, new_stack, new_stack_src, |
| 13179 | 13202 | call_instruction->is_async_call_builtin, args_ptr, call_instruction->arg_count, ret_ptr, |
| 13180 | 13203 | call_instruction->result_loc); |
| ... | ... | @@ -13182,7 +13205,7 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins |
| 13182 | 13205 | return result; |
| 13183 | 13206 | } |
| 13184 | 13207 | |
| 13185 | | static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, |
| 13208 | static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 13186 | 13209 | IrInstSrc *pass1_options, IrInstSrc *pass1_fn_ref, IrInstGen **args_ptr, size_t args_len, |
| 13187 | 13210 | ResultLoc *result_loc) |
| 13188 | 13211 | { |
| ... | ... | @@ -13195,19 +13218,19 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, |
| 13195 | 13218 | return ira->codegen->invalid_inst_gen; |
| 13196 | 13219 | |
| 13197 | 13220 | TypeStructField *modifier_field = find_struct_type_field(options->value->type, buf_create_from_str("modifier")); |
| 13198 | | ir_assert(modifier_field != nullptr, source_instr); |
| 13199 | | IrInstGen *modifier_inst = ir_analyze_struct_value_field_value(ira, source_instr, options, modifier_field); |
| 13221 | src_assert(modifier_field != nullptr, source_node); |
| 13222 | IrInstGen *modifier_inst = ir_analyze_struct_value_field_value(ira, scope, source_node, options, modifier_field); |
| 13200 | 13223 | ZigValue *modifier_val = ir_resolve_const(ira, modifier_inst, UndefBad); |
| 13201 | 13224 | if (modifier_val == nullptr) |
| 13202 | 13225 | return ira->codegen->invalid_inst_gen; |
| 13203 | 13226 | CallModifier modifier = (CallModifier)bigint_as_u32(&modifier_val->data.x_enum_tag); |
| 13204 | 13227 | |
| 13205 | | if (ir_should_inline(ira->zir, source_instr->scope)) { |
| 13228 | if (ir_should_inline(ira->zir, scope)) { |
| 13206 | 13229 | switch (modifier) { |
| 13207 | 13230 | case CallModifierBuiltin: |
| 13208 | 13231 | zig_unreachable(); |
| 13209 | 13232 | case CallModifierAsync: |
| 13210 | | ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @call with async modifier")); |
| 13233 | ir_add_error_node(ira, source_node, buf_sprintf("TODO: comptime @call with async modifier")); |
| 13211 | 13234 | return ira->codegen->invalid_inst_gen; |
| 13212 | 13235 | case CallModifierCompileTime: |
| 13213 | 13236 | case CallModifierNone: |
| ... | ... | @@ -13217,18 +13240,18 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, |
| 13217 | 13240 | modifier = CallModifierCompileTime; |
| 13218 | 13241 | break; |
| 13219 | 13242 | case CallModifierNeverInline: |
| 13220 | | ir_add_error(ira, source_instr, |
| 13243 | ir_add_error_node(ira, source_node, |
| 13221 | 13244 | buf_sprintf("unable to perform 'never_inline' call at compile-time")); |
| 13222 | 13245 | return ira->codegen->invalid_inst_gen; |
| 13223 | 13246 | case CallModifierNeverTail: |
| 13224 | | ir_add_error(ira, source_instr, |
| 13247 | ir_add_error_node(ira, source_node, |
| 13225 | 13248 | buf_sprintf("unable to perform 'never_tail' call at compile-time")); |
| 13226 | 13249 | return ira->codegen->invalid_inst_gen; |
| 13227 | 13250 | } |
| 13228 | 13251 | } |
| 13229 | 13252 | |
| 13230 | 13253 | IrInstGen *first_arg_ptr = nullptr; |
| 13231 | | IrInst *first_arg_ptr_src = nullptr; |
| 13254 | AstNode *first_arg_ptr_src = nullptr; |
| 13232 | 13255 | ZigFn *fn = nullptr; |
| 13233 | 13256 | if (instr_is_comptime(fn_ref)) { |
| 13234 | 13257 | if (fn_ref->value->type->id == ZigTypeIdBoundFn) { |
| ... | ... | @@ -13249,7 +13272,7 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, |
| 13249 | 13272 | case CallModifierAlwaysInline: |
| 13250 | 13273 | case CallModifierAsync: |
| 13251 | 13274 | if (fn == nullptr) { |
| 13252 | | ir_add_error(ira, &modifier_inst->base, |
| 13275 | ir_add_error(ira, modifier_inst, |
| 13253 | 13276 | buf_sprintf("the specified modifier requires a comptime-known function")); |
| 13254 | 13277 | return ira->codegen->invalid_inst_gen; |
| 13255 | 13278 | } |
| ... | ... | @@ -13261,43 +13284,43 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, |
| 13261 | 13284 | ZigType *fn_type = (fn != nullptr) ? fn->type_entry : fn_ref->value->type; |
| 13262 | 13285 | |
| 13263 | 13286 | TypeStructField *stack_field = find_struct_type_field(options->value->type, buf_create_from_str("stack")); |
| 13264 | | ir_assert(stack_field != nullptr, source_instr); |
| 13265 | | IrInstGen *opt_stack = ir_analyze_struct_value_field_value(ira, source_instr, options, stack_field); |
| 13287 | src_assert(stack_field != nullptr, source_node); |
| 13288 | IrInstGen *opt_stack = ir_analyze_struct_value_field_value(ira, scope, source_node, options, stack_field); |
| 13266 | 13289 | if (type_is_invalid(opt_stack->value->type)) |
| 13267 | 13290 | return ira->codegen->invalid_inst_gen; |
| 13268 | 13291 | |
| 13269 | | IrInstGen *stack_is_non_null_inst = ir_analyze_test_non_null(ira, source_instr, opt_stack); |
| 13292 | IrInstGen *stack_is_non_null_inst = ir_analyze_test_non_null(ira, scope, source_node, opt_stack); |
| 13270 | 13293 | bool stack_is_non_null; |
| 13271 | 13294 | if (!ir_resolve_bool(ira, stack_is_non_null_inst, &stack_is_non_null)) |
| 13272 | 13295 | return ira->codegen->invalid_inst_gen; |
| 13273 | 13296 | |
| 13274 | 13297 | IrInstGen *stack = nullptr; |
| 13275 | | IrInst *stack_src = nullptr; |
| 13298 | AstNode *stack_src = nullptr; |
| 13276 | 13299 | if (stack_is_non_null) { |
| 13277 | | stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false); |
| 13300 | stack = ir_analyze_optional_value_payload_value(ira, scope, source_node, opt_stack, false); |
| 13278 | 13301 | if (type_is_invalid(stack->value->type)) |
| 13279 | 13302 | return ira->codegen->invalid_inst_gen; |
| 13280 | | stack_src = &stack->base; |
| 13303 | stack_src = stack->source_node; |
| 13281 | 13304 | } |
| 13282 | 13305 | |
| 13283 | | return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src, |
| 13306 | return ir_analyze_fn_call(ira, scope, source_node, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src, |
| 13284 | 13307 | modifier, stack, stack_src, false, args_ptr, args_len, nullptr, result_loc); |
| 13285 | 13308 | } |
| 13286 | 13309 | |
| 13287 | | static IrInstGen *ir_analyze_async_call_extra(IrAnalyze *ira, IrInst* source_instr, CallModifier modifier, |
| 13310 | static IrInstGen *ir_analyze_async_call_extra(IrAnalyze *ira, Scope *scope, AstNode *source_node, CallModifier modifier, |
| 13288 | 13311 | IrInstSrc *pass1_fn_ref, IrInstSrc *ret_ptr, IrInstSrc *new_stack, IrInstGen **args_ptr, size_t args_len, ResultLoc *result_loc) |
| 13289 | 13312 | { |
| 13290 | 13313 | IrInstGen *fn_ref = pass1_fn_ref->child; |
| 13291 | 13314 | if (type_is_invalid(fn_ref->value->type)) |
| 13292 | 13315 | return ira->codegen->invalid_inst_gen; |
| 13293 | 13316 | |
| 13294 | | if (ir_should_inline(ira->zir, source_instr->scope)) { |
| 13295 | | ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @asyncCall")); |
| 13317 | if (ir_should_inline(ira->zir, scope)) { |
| 13318 | ir_add_error_node(ira, source_node, buf_sprintf("TODO: comptime @asyncCall")); |
| 13296 | 13319 | return ira->codegen->invalid_inst_gen; |
| 13297 | 13320 | } |
| 13298 | 13321 | |
| 13299 | 13322 | IrInstGen *first_arg_ptr = nullptr; |
| 13300 | | IrInst *first_arg_ptr_src = nullptr; |
| 13323 | AstNode *first_arg_ptr_src = nullptr; |
| 13301 | 13324 | ZigFn *fn = nullptr; |
| 13302 | 13325 | if (instr_is_comptime(fn_ref)) { |
| 13303 | 13326 | if (fn_ref->value->type->id == ZigTypeIdBoundFn) { |
| ... | ... | @@ -13320,22 +13343,23 @@ static IrInstGen *ir_analyze_async_call_extra(IrAnalyze *ira, IrInst* source_ins |
| 13320 | 13343 | } |
| 13321 | 13344 | |
| 13322 | 13345 | ZigType *fn_type = (fn != nullptr) ? fn->type_entry : fn_ref->value->type; |
| 13323 | | IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack->child, |
| 13324 | | &new_stack->base, true, fn); |
| 13346 | IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, scope, source_node, |
| 13347 | new_stack->child, new_stack->source_node, true, fn); |
| 13325 | 13348 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) |
| 13326 | 13349 | return ira->codegen->invalid_inst_gen; |
| 13327 | 13350 | |
| 13328 | | return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src, |
| 13329 | | modifier, casted_new_stack, &new_stack->base, true, args_ptr, args_len, ret_ptr_uncasted, result_loc); |
| 13351 | return ir_analyze_fn_call(ira, scope, source_node, fn, fn_type, fn_ref, first_arg_ptr, |
| 13352 | first_arg_ptr_src, modifier, casted_new_stack, new_stack->source_node, true, args_ptr, |
| 13353 | args_len, ret_ptr_uncasted, result_loc); |
| 13330 | 13354 | } |
| 13331 | 13355 | |
| 13332 | | static bool ir_extract_tuple_call_args(IrAnalyze *ira, IrInst *source_instr, IrInstGen *args, IrInstGen ***args_ptr, size_t *args_len) { |
| 13356 | static bool ir_extract_tuple_call_args(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *args, IrInstGen ***args_ptr, size_t *args_len) { |
| 13333 | 13357 | ZigType *args_type = args->value->type; |
| 13334 | 13358 | if (type_is_invalid(args_type)) |
| 13335 | 13359 | return false; |
| 13336 | 13360 | |
| 13337 | 13361 | if (args_type->id != ZigTypeIdStruct) { |
| 13338 | | ir_add_error(ira, &args->base, |
| 13362 | ir_add_error(ira, args, |
| 13339 | 13363 | buf_sprintf("expected tuple or struct, found '%s'", buf_ptr(&args_type->name))); |
| 13340 | 13364 | return false; |
| 13341 | 13365 | } |
| ... | ... | @@ -13345,12 +13369,12 @@ static bool ir_extract_tuple_call_args(IrAnalyze *ira, IrInst *source_instr, IrI |
| 13345 | 13369 | *args_ptr = heap::c_allocator.allocate<IrInstGen *>(*args_len); |
| 13346 | 13370 | for (size_t i = 0; i < *args_len; i += 1) { |
| 13347 | 13371 | TypeStructField *arg_field = args_type->data.structure.fields[i]; |
| 13348 | | (*args_ptr)[i] = ir_analyze_struct_value_field_value(ira, source_instr, args, arg_field); |
| 13372 | (*args_ptr)[i] = ir_analyze_struct_value_field_value(ira, scope, source_node, args, arg_field); |
| 13349 | 13373 | if (type_is_invalid((*args_ptr)[i]->value->type)) |
| 13350 | 13374 | return false; |
| 13351 | 13375 | } |
| 13352 | 13376 | } else { |
| 13353 | | ir_add_error(ira, &args->base, buf_sprintf("TODO: struct args")); |
| 13377 | ir_add_error(ira, args, buf_sprintf("TODO: struct args")); |
| 13354 | 13378 | return false; |
| 13355 | 13379 | } |
| 13356 | 13380 | return true; |
| ... | ... | @@ -13360,11 +13384,11 @@ static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCal |
| 13360 | 13384 | IrInstGen *args = instruction->args->child; |
| 13361 | 13385 | IrInstGen **args_ptr = nullptr; |
| 13362 | 13386 | size_t args_len = 0; |
| 13363 | | if (!ir_extract_tuple_call_args(ira, &instruction->base.base, args, &args_ptr, &args_len)) { |
| 13387 | if (!ir_extract_tuple_call_args(ira, instruction->base.scope, instruction->base.source_node, args, &args_ptr, &args_len)) { |
| 13364 | 13388 | return ira->codegen->invalid_inst_gen; |
| 13365 | 13389 | } |
| 13366 | 13390 | |
| 13367 | | IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options, |
| 13391 | IrInstGen *result = ir_analyze_call_extra(ira, instruction->base.scope, instruction->base.source_node, instruction->options, |
| 13368 | 13392 | instruction->fn_ref, args_ptr, args_len, instruction->result_loc); |
| 13369 | 13393 | heap::c_allocator.deallocate(args_ptr, args_len); |
| 13370 | 13394 | return result; |
| ... | ... | @@ -13374,11 +13398,11 @@ static IrInstGen *ir_analyze_instruction_async_call_extra(IrAnalyze *ira, IrInst |
| 13374 | 13398 | IrInstGen *args = instruction->args->child; |
| 13375 | 13399 | IrInstGen **args_ptr = nullptr; |
| 13376 | 13400 | size_t args_len = 0; |
| 13377 | | if (!ir_extract_tuple_call_args(ira, &instruction->base.base, args, &args_ptr, &args_len)) { |
| 13401 | if (!ir_extract_tuple_call_args(ira, instruction->base.scope, instruction->base.source_node, args, &args_ptr, &args_len)) { |
| 13378 | 13402 | return ira->codegen->invalid_inst_gen; |
| 13379 | 13403 | } |
| 13380 | 13404 | |
| 13381 | | IrInstGen *result = ir_analyze_async_call_extra(ira, &instruction->base.base, instruction->modifier, |
| 13405 | IrInstGen *result = ir_analyze_async_call_extra(ira, instruction->base.scope, instruction->base.source_node, instruction->modifier, |
| 13382 | 13406 | instruction->fn_ref, instruction->ret_ptr, instruction->new_stack, args_ptr, args_len, instruction->result_loc); |
| 13383 | 13407 | heap::c_allocator.deallocate(args_ptr, args_len); |
| 13384 | 13408 | return result; |
| ... | ... | @@ -13392,7 +13416,7 @@ static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCall |
| 13392 | 13416 | return ira->codegen->invalid_inst_gen; |
| 13393 | 13417 | } |
| 13394 | 13418 | |
| 13395 | | IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options, |
| 13419 | IrInstGen *result = ir_analyze_call_extra(ira, instruction->base.scope, instruction->base.source_node, instruction->options, |
| 13396 | 13420 | instruction->fn_ref, args_ptr, instruction->args_len, instruction->result_loc); |
| 13397 | 13421 | heap::c_allocator.deallocate(args_ptr, instruction->args_len); |
| 13398 | 13422 | return result; |
| ... | ... | @@ -13404,7 +13428,7 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal |
| 13404 | 13428 | return ira->codegen->invalid_inst_gen; |
| 13405 | 13429 | |
| 13406 | 13430 | bool is_comptime = (call_instruction->modifier == CallModifierCompileTime) || |
| 13407 | | ir_should_inline(ira->zir, call_instruction->base.base.scope); |
| 13431 | ir_should_inline(ira->zir, call_instruction->base.scope); |
| 13408 | 13432 | CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier; |
| 13409 | 13433 | |
| 13410 | 13434 | if (is_comptime || instr_is_comptime(fn_ref)) { |
| ... | ... | @@ -13412,9 +13436,9 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal |
| 13412 | 13436 | ZigType *ty = ir_resolve_type(ira, fn_ref); |
| 13413 | 13437 | if (ty == nullptr) |
| 13414 | 13438 | return ira->codegen->invalid_inst_gen; |
| 13415 | | ErrorMsg *msg = ir_add_error(ira, &fn_ref->base, |
| 13439 | ErrorMsg *msg = ir_add_error(ira, fn_ref, |
| 13416 | 13440 | buf_sprintf("type '%s' not a function", buf_ptr(&ty->name))); |
| 13417 | | add_error_note(ira->codegen, msg, call_instruction->base.base.source_node, |
| 13441 | add_error_note(ira->codegen, msg, call_instruction->base.source_node, |
| 13418 | 13442 | buf_sprintf("use @as builtin for type coercion")); |
| 13419 | 13443 | return ira->codegen->invalid_inst_gen; |
| 13420 | 13444 | } else if (fn_ref->value->type->id == ZigTypeIdFn) { |
| ... | ... | @@ -13427,12 +13451,12 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal |
| 13427 | 13451 | assert(fn_ref->value->special == ConstValSpecialStatic); |
| 13428 | 13452 | ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn; |
| 13429 | 13453 | IrInstGen *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg; |
| 13430 | | IrInst *first_arg_ptr_src = fn_ref->value->data.x_bound_fn.first_arg_src; |
| 13454 | AstNode *first_arg_ptr_src = fn_ref->value->data.x_bound_fn.first_arg_src; |
| 13431 | 13455 | CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier; |
| 13432 | 13456 | return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, |
| 13433 | 13457 | fn_ref, first_arg_ptr, first_arg_ptr_src, modifier); |
| 13434 | 13458 | } else { |
| 13435 | | ir_add_error(ira, &fn_ref->base, |
| 13459 | ir_add_error(ira, fn_ref, |
| 13436 | 13460 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name))); |
| 13437 | 13461 | return ira->codegen->invalid_inst_gen; |
| 13438 | 13462 | } |
| ... | ... | @@ -13442,7 +13466,7 @@ static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *cal |
| 13442 | 13466 | return ir_analyze_fn_call_src(ira, call_instruction, nullptr, fn_ref->value->type, |
| 13443 | 13467 | fn_ref, nullptr, nullptr, modifier); |
| 13444 | 13468 | } else { |
| 13445 | | ir_add_error(ira, &fn_ref->base, |
| 13469 | ir_add_error(ira, fn_ref, |
| 13446 | 13470 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name))); |
| 13447 | 13471 | return ira->codegen->invalid_inst_gen; |
| 13448 | 13472 | } |
| ... | ... | @@ -13561,7 +13585,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source |
| 13561 | 13585 | } |
| 13562 | 13586 | |
| 13563 | 13587 | static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instruction) { |
| 13564 | | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 13588 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type); |
| 13565 | 13589 | result->value->special = ConstValSpecialLazy; |
| 13566 | 13590 | |
| 13567 | 13591 | LazyValueOptType *lazy_opt_type = heap::c_allocator.create<LazyValueOptType>(); |
| ... | ... | @@ -13576,7 +13600,7 @@ static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instru |
| 13576 | 13600 | return result; |
| 13577 | 13601 | } |
| 13578 | 13602 | |
| 13579 | | static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *scalar_type, |
| 13603 | static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *scalar_type, |
| 13580 | 13604 | ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op) |
| 13581 | 13605 | { |
| 13582 | 13606 | bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat); |
| ... | ... | @@ -13586,7 +13610,7 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, Z |
| 13586 | 13610 | |
| 13587 | 13611 | if (!ok_type) { |
| 13588 | 13612 | const char *fmt = is_wrap_op ? "invalid wrapping negation type: '%s'" : "invalid negation type: '%s'"; |
| 13589 | | return ir_add_error(ira, source_instr, buf_sprintf(fmt, buf_ptr(&scalar_type->name))); |
| 13613 | return ir_add_error_node(ira, source_node, buf_sprintf(fmt, buf_ptr(&scalar_type->name))); |
| 13590 | 13614 | } |
| 13591 | 13615 | |
| 13592 | 13616 | if (is_float) { |
| ... | ... | @@ -13606,7 +13630,7 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, Z |
| 13606 | 13630 | } |
| 13607 | 13631 | |
| 13608 | 13632 | if (!bigint_fits_in_bits(&scalar_out_val->data.x_bigint, scalar_type->data.integral.bit_count, true)) { |
| 13609 | | return ir_add_error(ira, source_instr, buf_sprintf("negation caused overflow")); |
| 13633 | return ir_add_error_node(ira, source_node, buf_sprintf("negation caused overflow")); |
| 13610 | 13634 | } |
| 13611 | 13635 | return nullptr; |
| 13612 | 13636 | } |
| ... | ... | @@ -13632,7 +13656,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction |
| 13632 | 13656 | break; |
| 13633 | 13657 | ZIG_FALLTHROUGH; |
| 13634 | 13658 | default: |
| 13635 | | ir_add_error(ira, &instruction->base.base, |
| 13659 | ir_add_error_node(ira, instruction->base.source_node, |
| 13636 | 13660 | buf_sprintf("negation of type '%s'", buf_ptr(&scalar_type->name))); |
| 13637 | 13661 | return ira->codegen->invalid_inst_gen; |
| 13638 | 13662 | } |
| ... | ... | @@ -13642,7 +13666,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction |
| 13642 | 13666 | if (!operand_val) |
| 13643 | 13667 | return ira->codegen->invalid_inst_gen; |
| 13644 | 13668 | |
| 13645 | | IrInstGen *result_instruction = ir_const(ira, &instruction->base.base, expr_type); |
| 13669 | IrInstGen *result_instruction = ir_const(ira, instruction->base.scope, instruction->base.source_node, expr_type); |
| 13646 | 13670 | ZigValue *out_val = result_instruction->value; |
| 13647 | 13671 | if (expr_type->id == ZigTypeIdVector) { |
| 13648 | 13672 | expand_undef_array(ira->codegen, operand_val); |
| ... | ... | @@ -13654,10 +13678,10 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction |
| 13654 | 13678 | ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 13655 | 13679 | assert(scalar_operand_val->type == scalar_type); |
| 13656 | 13680 | assert(scalar_out_val->type == scalar_type); |
| 13657 | | ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type, |
| 13681 | ErrorMsg *msg = ir_eval_negation_scalar(ira, instruction->base.scope, instruction->base.source_node, scalar_type, |
| 13658 | 13682 | scalar_operand_val, scalar_out_val, is_wrap_op); |
| 13659 | 13683 | if (msg != nullptr) { |
| 13660 | | add_error_note(ira->codegen, msg, instruction->base.base.source_node, |
| 13684 | add_error_note(ira->codegen, msg, instruction->base.source_node, |
| 13661 | 13685 | buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i)); |
| 13662 | 13686 | return ira->codegen->invalid_inst_gen; |
| 13663 | 13687 | } |
| ... | ... | @@ -13665,7 +13689,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction |
| 13665 | 13689 | out_val->type = expr_type; |
| 13666 | 13690 | out_val->special = ConstValSpecialStatic; |
| 13667 | 13691 | } else { |
| 13668 | | if (ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type, operand_val, out_val, |
| 13692 | if (ir_eval_negation_scalar(ira, instruction->base.scope, instruction->base.source_node, scalar_type, operand_val, out_val, |
| 13669 | 13693 | is_wrap_op) != nullptr) |
| 13670 | 13694 | { |
| 13671 | 13695 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -13674,7 +13698,7 @@ static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction |
| 13674 | 13698 | return result_instruction; |
| 13675 | 13699 | } |
| 13676 | 13700 | |
| 13677 | | return ir_build_negation(ira, &instruction->base.base, value, expr_type, is_wrap_op); |
| 13701 | return ir_build_negation(ira, instruction->base.scope, instruction->base.source_node, value, expr_type, is_wrap_op); |
| 13678 | 13702 | } |
| 13679 | 13703 | |
| 13680 | 13704 | static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction) { |
| ... | ... | @@ -13687,7 +13711,7 @@ static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction) |
| 13687 | 13711 | expr_type->data.vector.elem_type : expr_type; |
| 13688 | 13712 | |
| 13689 | 13713 | if (scalar_type->id != ZigTypeIdInt) { |
| 13690 | | ir_add_error(ira, &instruction->base.base, |
| 13714 | ir_add_error_node(ira, instruction->base.source_node, |
| 13691 | 13715 | buf_sprintf("unable to perform binary not operation on type '%s'", buf_ptr(&expr_type->name))); |
| 13692 | 13716 | return ira->codegen->invalid_inst_gen; |
| 13693 | 13717 | } |
| ... | ... | @@ -13697,7 +13721,7 @@ static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction) |
| 13697 | 13721 | if (expr_val == nullptr) |
| 13698 | 13722 | return ira->codegen->invalid_inst_gen; |
| 13699 | 13723 | |
| 13700 | | IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type); |
| 13724 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, expr_type); |
| 13701 | 13725 | |
| 13702 | 13726 | if (expr_type->id == ZigTypeIdVector) { |
| 13703 | 13727 | expand_undef_array(ira->codegen, expr_val); |
| ... | ... | @@ -13721,7 +13745,7 @@ static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction) |
| 13721 | 13745 | return result; |
| 13722 | 13746 | } |
| 13723 | 13747 | |
| 13724 | | return ir_build_binary_not(ira, &instruction->base.base, value, expr_type); |
| 13748 | return ir_build_binary_not(ira, instruction->base.scope, instruction->base.source_node, value, expr_type); |
| 13725 | 13749 | } |
| 13726 | 13750 | |
| 13727 | 13751 | static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *instruction) { |
| ... | ... | @@ -13740,19 +13764,20 @@ static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *in |
| 13740 | 13764 | return ira->codegen->invalid_inst_gen; |
| 13741 | 13765 | ZigType *ptr_type = ptr->value->type; |
| 13742 | 13766 | if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) { |
| 13743 | | ir_add_error_node(ira, instruction->base.base.source_node, |
| 13767 | ir_add_error_node(ira, instruction->base.source_node, |
| 13744 | 13768 | buf_sprintf("index syntax required for unknown-length pointer type '%s'", |
| 13745 | 13769 | buf_ptr(&ptr_type->name))); |
| 13746 | 13770 | return ira->codegen->invalid_inst_gen; |
| 13747 | 13771 | } |
| 13748 | 13772 | |
| 13749 | | IrInstGen *result = ir_get_deref(ira, &instruction->base.base, ptr, instruction->result_loc); |
| 13773 | IrInstGen *result = ir_get_deref(ira, instruction->base.scope, |
| 13774 | instruction->base.source_node, ptr, instruction->result_loc); |
| 13750 | 13775 | if (type_is_invalid(result->value->type)) |
| 13751 | 13776 | return ira->codegen->invalid_inst_gen; |
| 13752 | 13777 | |
| 13753 | 13778 | // If the result needs to be an lvalue, type check it |
| 13754 | 13779 | if (instruction->lval != LValNone && result->value->type->id != ZigTypeIdPointer) { |
| 13755 | | ir_add_error(ira, &instruction->base.base, |
| 13780 | ir_add_error_node(ira, instruction->base.source_node, |
| 13756 | 13781 | buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name))); |
| 13757 | 13782 | return ira->codegen->invalid_inst_gen; |
| 13758 | 13783 | } |
| ... | ... | @@ -13786,15 +13811,15 @@ static IrInstGen *ir_analyze_instruction_br(IrAnalyze *ira, IrInstSrcBr *br_inst |
| 13786 | 13811 | return ir_unreach_error(ira); |
| 13787 | 13812 | |
| 13788 | 13813 | if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr)) |
| 13789 | | return ir_inline_bb(ira, &br_instruction->base.base, old_dest_block); |
| 13814 | return ir_inline_bb(ira, br_instruction->base.source_node, old_dest_block); |
| 13790 | 13815 | |
| 13791 | | IrBasicBlockGen *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base.base); |
| 13816 | IrBasicBlockGen *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base); |
| 13792 | 13817 | if (new_bb == nullptr) |
| 13793 | 13818 | return ir_unreach_error(ira); |
| 13794 | 13819 | |
| 13795 | 13820 | ir_push_resume_block(ira, old_dest_block); |
| 13796 | 13821 | |
| 13797 | | IrInstGen *result = ir_build_br_gen(ira, &br_instruction->base.base, new_bb); |
| 13822 | IrInstGen *result = ir_build_br_gen(ira, br_instruction->base.scope, br_instruction->base.source_node, new_bb); |
| 13798 | 13823 | return ir_finish_anal(ira, result); |
| 13799 | 13824 | } |
| 13800 | 13825 | |
| ... | ... | @@ -13821,44 +13846,48 @@ static IrInstGen *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstSrcCondBr |
| 13821 | 13846 | cond_br_instruction->then_block : cond_br_instruction->else_block; |
| 13822 | 13847 | |
| 13823 | 13848 | if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr)) |
| 13824 | | return ir_inline_bb(ira, &cond_br_instruction->base.base, old_dest_block); |
| 13849 | return ir_inline_bb(ira, cond_br_instruction->base.source_node, old_dest_block); |
| 13825 | 13850 | |
| 13826 | | IrBasicBlockGen *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base.base); |
| 13851 | IrBasicBlockGen *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base); |
| 13827 | 13852 | if (new_dest_block == nullptr) |
| 13828 | 13853 | return ir_unreach_error(ira); |
| 13829 | 13854 | |
| 13830 | 13855 | ir_push_resume_block(ira, old_dest_block); |
| 13831 | 13856 | |
| 13832 | | IrInstGen *result = ir_build_br_gen(ira, &cond_br_instruction->base.base, new_dest_block); |
| 13857 | IrInstGen *result = ir_build_br_gen(ira, cond_br_instruction->base.scope, |
| 13858 | cond_br_instruction->base.source_node, new_dest_block); |
| 13833 | 13859 | return ir_finish_anal(ira, result); |
| 13834 | 13860 | } |
| 13835 | 13861 | |
| 13836 | 13862 | assert(cond_br_instruction->then_block != cond_br_instruction->else_block); |
| 13837 | | IrBasicBlockGen *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base.base); |
| 13863 | IrBasicBlockGen *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base); |
| 13838 | 13864 | if (new_then_block == nullptr) |
| 13839 | 13865 | return ir_unreach_error(ira); |
| 13840 | 13866 | |
| 13841 | | IrBasicBlockGen *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base.base); |
| 13867 | IrBasicBlockGen *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base); |
| 13842 | 13868 | if (new_else_block == nullptr) |
| 13843 | 13869 | return ir_unreach_error(ira); |
| 13844 | 13870 | |
| 13845 | 13871 | ir_push_resume_block(ira, cond_br_instruction->else_block); |
| 13846 | 13872 | ir_push_resume_block(ira, cond_br_instruction->then_block); |
| 13847 | 13873 | |
| 13848 | | IrInstGen *result = ir_build_cond_br_gen(ira, &cond_br_instruction->base.base, |
| 13849 | | casted_condition, new_then_block, new_else_block); |
| 13874 | IrInstGen *result = ir_build_cond_br_gen(ira, cond_br_instruction->base.scope, |
| 13875 | cond_br_instruction->base.source_node, casted_condition, new_then_block, |
| 13876 | new_else_block); |
| 13850 | 13877 | return ir_finish_anal(ira, result); |
| 13851 | 13878 | } |
| 13852 | 13879 | |
| 13853 | 13880 | static IrInstGen *ir_analyze_instruction_unreachable(IrAnalyze *ira, |
| 13854 | 13881 | IrInstSrcUnreachable *unreachable_instruction) |
| 13855 | 13882 | { |
| 13856 | | if (ir_should_inline(ira->zir, unreachable_instruction->base.base.scope)) { |
| 13857 | | ir_add_error(ira, &unreachable_instruction->base.base, buf_sprintf("reached unreachable code")); |
| 13883 | if (ir_should_inline(ira->zir, unreachable_instruction->base.scope)) { |
| 13884 | ir_add_error_node(ira, unreachable_instruction->base.source_node, |
| 13885 | buf_sprintf("reached unreachable code")); |
| 13858 | 13886 | return ir_unreach_error(ira); |
| 13859 | 13887 | } |
| 13860 | 13888 | |
| 13861 | | IrInstGen *result = ir_build_unreachable_gen(ira, &unreachable_instruction->base.base); |
| 13889 | IrInstGen *result = ir_build_unreachable_gen(ira, unreachable_instruction->base.scope, |
| 13890 | unreachable_instruction->base.source_node); |
| 13862 | 13891 | return ir_finish_anal(ira, result); |
| 13863 | 13892 | } |
| 13864 | 13893 | |
| ... | ... | @@ -13876,7 +13905,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i |
| 13876 | 13905 | return ira->codegen->invalid_inst_gen; |
| 13877 | 13906 | |
| 13878 | 13907 | if (value->value->special != ConstValSpecialRuntime) { |
| 13879 | | IrInstGen *result = ir_const(ira, &phi_instruction->base.base, nullptr); |
| 13908 | IrInstGen *result = ir_const(ira, phi_instruction->base.scope, |
| 13909 | phi_instruction->base.source_node, nullptr); |
| 13880 | 13910 | copy_const_val(ira->codegen, result->value, value->value); |
| 13881 | 13911 | return result; |
| 13882 | 13912 | } else { |
| ... | ... | @@ -13899,9 +13929,10 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i |
| 13899 | 13929 | if (gen_instruction == nullptr) { |
| 13900 | 13930 | // unreachable instructions will cause implicit_elem_type to be null |
| 13901 | 13931 | if (this_peer->base.implicit_elem_type == nullptr) { |
| 13902 | | instructions[i] = ir_const_unreachable(ira, &this_peer->base.source_instruction->base); |
| 13932 | instructions[i] = ir_const_unreachable(ira, this_peer->base.source_instruction->scope, this_peer->base.source_instruction->source_node); |
| 13903 | 13933 | } else { |
| 13904 | | instructions[i] = ir_const(ira, &this_peer->base.source_instruction->base, |
| 13934 | instructions[i] = ir_const(ira, this_peer->base.source_instruction->scope, |
| 13935 | this_peer->base.source_instruction->source_node, |
| 13905 | 13936 | this_peer->base.implicit_elem_type); |
| 13906 | 13937 | instructions[i]->value->special = ConstValSpecialRuntime; |
| 13907 | 13938 | } |
| ... | ... | @@ -13910,18 +13941,19 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i |
| 13910 | 13941 | } |
| 13911 | 13942 | |
| 13912 | 13943 | } |
| 13913 | | ZigType *expected_type = ir_result_loc_expected_type(ira, &phi_instruction->base.base, peer_parent->parent); |
| 13944 | ZigType *expected_type = ir_result_loc_expected_type(ira, peer_parent->parent); |
| 13914 | 13945 | peer_parent->resolved_type = ir_resolve_peer_types(ira, |
| 13915 | | peer_parent->base.source_instruction->base.source_node, expected_type, instructions, |
| 13946 | peer_parent->base.source_instruction->source_node, expected_type, instructions, |
| 13916 | 13947 | peer_parent->peers.length); |
| 13917 | 13948 | if (type_is_invalid(peer_parent->resolved_type)) |
| 13918 | 13949 | return ira->codegen->invalid_inst_gen; |
| 13919 | 13950 | |
| 13920 | 13951 | // the logic below assumes there are no instructions in the new current basic block yet |
| 13921 | | ir_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, &phi_instruction->base.base); |
| 13952 | src_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, |
| 13953 | phi_instruction->base.source_node); |
| 13922 | 13954 | |
| 13923 | 13955 | // In case resolving the parent activates a suspend, do it now |
| 13924 | | IrInstGen *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base.base, peer_parent->parent, |
| 13956 | IrInstGen *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent, |
| 13925 | 13957 | peer_parent->resolved_type, nullptr, false, true); |
| 13926 | 13958 | if (parent_result_loc != nullptr && |
| 13927 | 13959 | (type_is_invalid(parent_result_loc->value->type) || parent_result_loc->value->type->id == ZigTypeIdUnreachable)) |
| ... | ... | @@ -13937,7 +13969,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i |
| 13937 | 13969 | if (instrs_to_move.length != 0) { |
| 13938 | 13970 | IrBasicBlockGen *predecessor = peer_parent->base.source_instruction->child->owner_bb; |
| 13939 | 13971 | IrInstGen *branch_instruction = predecessor->instruction_list.pop(); |
| 13940 | | ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base.base); |
| 13972 | src_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, |
| 13973 | phi_instruction->base.source_node); |
| 13941 | 13974 | while (instrs_to_move.length != 0) { |
| 13942 | 13975 | predecessor->instruction_list.append(instrs_to_move.pop()); |
| 13943 | 13976 | } |
| ... | ... | @@ -13947,7 +13980,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i |
| 13947 | 13980 | } |
| 13948 | 13981 | |
| 13949 | 13982 | IrSuspendPosition suspend_pos; |
| 13950 | | ira_suspend(ira, &phi_instruction->base.base, nullptr, &suspend_pos); |
| 13983 | ira_suspend(ira, &phi_instruction->base, nullptr, &suspend_pos); |
| 13951 | 13984 | ir_push_resume(ira, suspend_pos); |
| 13952 | 13985 | |
| 13953 | 13986 | for (size_t i = 0; i < peer_parent->peers.length; i += 1) { |
| ... | ... | @@ -13988,7 +14021,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i |
| 13988 | 14021 | } |
| 13989 | 14022 | |
| 13990 | 14023 | if (new_incoming_blocks.length == 0) { |
| 13991 | | IrInstGen *result = ir_build_unreachable_gen(ira, &phi_instruction->base.base); |
| 14024 | IrInstGen *result = ir_build_unreachable_gen(ira, phi_instruction->base.scope, |
| 14025 | phi_instruction->base.source_node); |
| 13992 | 14026 | return ir_finish_anal(ira, result); |
| 13993 | 14027 | } |
| 13994 | 14028 | |
| ... | ... | @@ -14011,7 +14045,8 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i |
| 14011 | 14045 | resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child); |
| 14012 | 14046 | } else if (peer_parent->parent->resolved_loc) { |
| 14013 | 14047 | ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type; |
| 14014 | | ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base.base); |
| 14048 | src_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, |
| 14049 | phi_instruction->base.source_node); |
| 14015 | 14050 | resolved_type = resolved_loc_ptr_type->data.pointer.child_type; |
| 14016 | 14051 | } |
| 14017 | 14052 | |
| ... | ... | @@ -14021,7 +14056,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i |
| 14021 | 14056 | } |
| 14022 | 14057 | |
| 14023 | 14058 | if (resolved_type == nullptr) { |
| 14024 | | resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.base.source_node, nullptr, |
| 14059 | resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr, |
| 14025 | 14060 | new_incoming_values.items, new_incoming_values.length); |
| 14026 | 14061 | if (type_is_invalid(resolved_type)) |
| 14027 | 14062 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -14031,7 +14066,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i |
| 14031 | 14066 | case OnePossibleValueInvalid: |
| 14032 | 14067 | return ira->codegen->invalid_inst_gen; |
| 14033 | 14068 | case OnePossibleValueYes: |
| 14034 | | return ir_const_move(ira, &phi_instruction->base.base, |
| 14069 | return ir_const_move(ira, phi_instruction->base.scope, phi_instruction->base.source_node, |
| 14035 | 14070 | get_the_one_possible_value(ira->codegen, resolved_type)); |
| 14036 | 14071 | case OnePossibleValueNo: |
| 14037 | 14072 | break; |
| ... | ... | @@ -14041,7 +14076,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i |
| 14041 | 14076 | case ReqCompTimeInvalid: |
| 14042 | 14077 | return ira->codegen->invalid_inst_gen; |
| 14043 | 14078 | case ReqCompTimeYes: |
| 14044 | | ir_add_error(ira, &phi_instruction->base.base, |
| 14079 | ir_add_error_node(ira, phi_instruction->base.source_node, |
| 14045 | 14080 | buf_sprintf("values of type '%s' must be comptime known", buf_ptr(&resolved_type->name))); |
| 14046 | 14081 | return ira->codegen->invalid_inst_gen; |
| 14047 | 14082 | case ReqCompTimeNo: |
| ... | ... | @@ -14057,7 +14092,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i |
| 14057 | 14092 | for (size_t i = 0; i < new_incoming_values.length; i += 1) { |
| 14058 | 14093 | IrInstGen *new_value = new_incoming_values.at(i); |
| 14059 | 14094 | IrBasicBlockGen *predecessor = new_incoming_blocks.at(i); |
| 14060 | | ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base.base); |
| 14095 | src_assert(predecessor->instruction_list.length != 0, phi_instruction->base.source_node); |
| 14061 | 14096 | IrInstGen *branch_instruction = predecessor->instruction_list.pop(); |
| 14062 | 14097 | ir_set_cursor_at_end_gen(&ira->new_irb, predecessor); |
| 14063 | 14098 | IrInstGen *casted_value = ir_implicit_cast(ira, new_value, resolved_type); |
| ... | ... | @@ -14075,8 +14110,9 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i |
| 14075 | 14110 | } |
| 14076 | 14111 | ir_set_cursor_at_end_gen(&ira->new_irb, cur_bb); |
| 14077 | 14112 | |
| 14078 | | IrInstGen *result = ir_build_phi_gen(ira, &phi_instruction->base.base, |
| 14079 | | new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, resolved_type); |
| 14113 | IrInstGen *result = ir_build_phi_gen(ira, phi_instruction->base.scope, |
| 14114 | phi_instruction->base.source_node, new_incoming_blocks.length, |
| 14115 | new_incoming_blocks.items, new_incoming_values.items, resolved_type); |
| 14080 | 14116 | |
| 14081 | 14117 | if (all_stack_ptrs) { |
| 14082 | 14118 | assert(result->value->special == ConstValSpecialRuntime); |
| ... | ... | @@ -14088,9 +14124,9 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i |
| 14088 | 14124 | |
| 14089 | 14125 | static IrInstGen *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstSrcVarPtr *instruction) { |
| 14090 | 14126 | ZigVar *var = instruction->var; |
| 14091 | | IrInstGen *result = ir_get_var_ptr(ira, &instruction->base.base, var); |
| 14127 | IrInstGen *result = ir_get_var_ptr(ira, instruction->base.scope, instruction->base.source_node, var); |
| 14092 | 14128 | if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) { |
| 14093 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 14129 | ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node, |
| 14094 | 14130 | buf_sprintf("'%s' not accessible from inner function", var->name)); |
| 14095 | 14131 | add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node, |
| 14096 | 14132 | buf_sprintf("crossed function definition here")); |
| ... | ... | @@ -14244,8 +14280,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14244 | 14280 | array_type->data.pointer.ptr_len == PtrLenSingle && |
| 14245 | 14281 | array_type->data.pointer.child_type->id == ZigTypeIdArray) |
| 14246 | 14282 | { |
| 14247 | | IrInstGen *ptr_value = ir_get_deref(ira, &elem_ptr_instruction->base.base, |
| 14248 | | array_ptr, nullptr); |
| 14283 | IrInstGen *ptr_value = ir_get_deref(ira, elem_ptr_instruction->base.scope, |
| 14284 | elem_ptr_instruction->base.source_node, array_ptr, nullptr); |
| 14249 | 14285 | if (type_is_invalid(ptr_value->value->type)) |
| 14250 | 14286 | return ira->codegen->invalid_inst_gen; |
| 14251 | 14287 | |
| ... | ... | @@ -14257,7 +14293,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14257 | 14293 | |
| 14258 | 14294 | if (array_type->id == ZigTypeIdArray) { |
| 14259 | 14295 | if(array_type->data.array.len == 0 && array_type->data.array.sentinel == nullptr){ |
| 14260 | | ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf("accessing a zero length array is not allowed")); |
| 14296 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14297 | buf_sprintf("accessing a zero length array is not allowed")); |
| 14261 | 14298 | return ira->codegen->invalid_inst_gen; |
| 14262 | 14299 | } |
| 14263 | 14300 | |
| ... | ... | @@ -14282,7 +14319,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14282 | 14319 | } |
| 14283 | 14320 | } else if (array_type->id == ZigTypeIdPointer) { |
| 14284 | 14321 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { |
| 14285 | | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 14322 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14286 | 14323 | buf_sprintf("index of single-item pointer")); |
| 14287 | 14324 | return ira->codegen->invalid_inst_gen; |
| 14288 | 14325 | } |
| ... | ... | @@ -14301,27 +14338,27 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14301 | 14338 | IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize); |
| 14302 | 14339 | if (type_is_invalid(casted_elem_index->value->type)) |
| 14303 | 14340 | return ira->codegen->invalid_inst_gen; |
| 14304 | | ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base.base); |
| 14341 | src_assert(instr_is_comptime(casted_elem_index), elem_ptr_instruction->base.source_node); |
| 14305 | 14342 | Buf *field_name = buf_alloc(); |
| 14306 | 14343 | bigint_append_buf(field_name, &casted_elem_index->value->data.x_bigint, 10); |
| 14307 | | return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base.base, |
| 14344 | return ir_analyze_inferred_field_ptr(ira, field_name, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, |
| 14308 | 14345 | array_ptr, array_type); |
| 14309 | 14346 | } else if (is_tuple(array_type)) { |
| 14310 | 14347 | uint64_t elem_index_scalar; |
| 14311 | 14348 | if (!ir_resolve_usize(ira, elem_index, &elem_index_scalar)) |
| 14312 | 14349 | return ira->codegen->invalid_inst_gen; |
| 14313 | 14350 | if (elem_index_scalar >= array_type->data.structure.src_field_count) { |
| 14314 | | ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf( |
| 14351 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, buf_sprintf( |
| 14315 | 14352 | "field index %" ZIG_PRI_u64 " outside tuple '%s' which has %" PRIu32 " fields", |
| 14316 | 14353 | elem_index_scalar, buf_ptr(&array_type->name), |
| 14317 | 14354 | array_type->data.structure.src_field_count)); |
| 14318 | 14355 | return ira->codegen->invalid_inst_gen; |
| 14319 | 14356 | } |
| 14320 | 14357 | TypeStructField *field = array_type->data.structure.fields[elem_index_scalar]; |
| 14321 | | return ir_analyze_struct_field_ptr(ira, &elem_ptr_instruction->base.base, field, array_ptr, |
| 14358 | return ir_analyze_struct_field_ptr(ira, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, field, array_ptr, |
| 14322 | 14359 | array_type, false); |
| 14323 | 14360 | } else { |
| 14324 | | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 14361 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14325 | 14362 | buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name))); |
| 14326 | 14363 | return ira->codegen->invalid_inst_gen; |
| 14327 | 14364 | } |
| ... | ... | @@ -14342,7 +14379,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14342 | 14379 | uint64_t array_len = array_type->data.array.len + |
| 14343 | 14380 | (array_type->data.array.sentinel != nullptr); |
| 14344 | 14381 | if (index >= array_len) { |
| 14345 | | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 14382 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14346 | 14383 | buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64, |
| 14347 | 14384 | index, array_len)); |
| 14348 | 14385 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -14351,7 +14388,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14351 | 14388 | } else if (array_type->id == ZigTypeIdVector) { |
| 14352 | 14389 | uint64_t vector_len = array_type->data.vector.len; |
| 14353 | 14390 | if (index >= vector_len) { |
| 14354 | | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 14391 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14355 | 14392 | buf_sprintf("index %" ZIG_PRI_u64 " outside vector of size %" ZIG_PRI_u64, |
| 14356 | 14393 | index, vector_len)); |
| 14357 | 14394 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -14385,13 +14422,13 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14385 | 14422 | (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == ZigTypeIdArray)) |
| 14386 | 14423 | { |
| 14387 | 14424 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 14388 | | elem_ptr_instruction->base.base.source_node, orig_array_ptr_val, UndefBad))) |
| 14425 | elem_ptr_instruction->base.source_node, orig_array_ptr_val, UndefBad))) |
| 14389 | 14426 | { |
| 14390 | 14427 | return ira->codegen->invalid_inst_gen; |
| 14391 | 14428 | } |
| 14392 | 14429 | |
| 14393 | 14430 | ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, |
| 14394 | | elem_ptr_instruction->base.base.source_node); |
| 14431 | elem_ptr_instruction->base.source_node); |
| 14395 | 14432 | if (array_ptr_val == nullptr) |
| 14396 | 14433 | return ira->codegen->invalid_inst_gen; |
| 14397 | 14434 | |
| ... | ... | @@ -14411,7 +14448,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14411 | 14448 | elem_val->parent.data.p_array.elem_index = i; |
| 14412 | 14449 | } |
| 14413 | 14450 | } else if (is_slice(array_type)) { |
| 14414 | | ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base.base); |
| 14451 | src_assert(array_ptr->value->type->id == ZigTypeIdPointer, elem_ptr_instruction->base.source_node); |
| 14415 | 14452 | ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type; |
| 14416 | 14453 | |
| 14417 | 14454 | if (type_is_invalid(actual_array_type)) |
| ... | ... | @@ -14454,12 +14491,12 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14454 | 14491 | array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)) |
| 14455 | 14492 | { |
| 14456 | 14493 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 14457 | | elem_ptr_instruction->base.base.source_node, array_ptr_val, UndefOk))) |
| 14494 | elem_ptr_instruction->base.source_node, array_ptr_val, UndefOk))) |
| 14458 | 14495 | { |
| 14459 | 14496 | return ira->codegen->invalid_inst_gen; |
| 14460 | 14497 | } |
| 14461 | 14498 | if (array_type->id == ZigTypeIdPointer) { |
| 14462 | | IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type); |
| 14499 | IrInstGen *result = ir_const(ira, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, return_type); |
| 14463 | 14500 | ZigValue *out_val = result->value; |
| 14464 | 14501 | out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; |
| 14465 | 14502 | size_t new_index; |
| ... | ... | @@ -14529,7 +14566,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14529 | 14566 | zig_panic("TODO elem ptr on a null pointer"); |
| 14530 | 14567 | } |
| 14531 | 14568 | if (new_index >= mem_size) { |
| 14532 | | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 14569 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14533 | 14570 | buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size)); |
| 14534 | 14571 | return ira->codegen->invalid_inst_gen; |
| 14535 | 14572 | } |
| ... | ... | @@ -14538,21 +14575,22 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14538 | 14575 | expand_undef_struct(ira->codegen, array_ptr_val); |
| 14539 | 14576 | |
| 14540 | 14577 | ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index]; |
| 14541 | | ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base.base); |
| 14578 | src_assert(ptr_field != nullptr, elem_ptr_instruction->base.source_node); |
| 14542 | 14579 | if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 14543 | | return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope, |
| 14544 | | elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, false, |
| 14580 | return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.scope, |
| 14581 | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false, |
| 14545 | 14582 | return_type); |
| 14546 | 14583 | } |
| 14547 | 14584 | ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index]; |
| 14548 | | IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type); |
| 14585 | IrInstGen *result = ir_const(ira, elem_ptr_instruction->base.scope, |
| 14586 | elem_ptr_instruction->base.source_node, return_type); |
| 14549 | 14587 | ZigValue *out_val = result->value; |
| 14550 | 14588 | ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 14551 | 14589 | uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint); |
| 14552 | 14590 | uint64_t full_slice_len = slice_len + |
| 14553 | 14591 | ((slice_ptr_type->data.pointer.sentinel != nullptr) ? 1 : 0); |
| 14554 | 14592 | if (index >= full_slice_len) { |
| 14555 | | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 14593 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14556 | 14594 | buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64, |
| 14557 | 14595 | index, slice_len)); |
| 14558 | 14596 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -14575,7 +14613,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14575 | 14613 | ConstArraySpecialBuf) |
| 14576 | 14614 | { |
| 14577 | 14615 | if (new_index >= ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len) { |
| 14578 | | ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf("out of bounds slice")); |
| 14616 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, buf_sprintf("out of bounds slice")); |
| 14579 | 14617 | return ira->codegen->invalid_inst_gen; |
| 14580 | 14618 | } |
| 14581 | 14619 | } |
| ... | ... | @@ -14606,12 +14644,12 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14606 | 14644 | |
| 14607 | 14645 | IrInstGen *result; |
| 14608 | 14646 | if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 14609 | | result = ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope, |
| 14610 | | elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, |
| 14647 | result = ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.scope, |
| 14648 | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, |
| 14611 | 14649 | false, return_type); |
| 14612 | 14650 | result->value->special = ConstValSpecialStatic; |
| 14613 | 14651 | } else { |
| 14614 | | result = ir_const(ira, &elem_ptr_instruction->base.base, return_type); |
| 14652 | result = ir_const(ira, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, return_type); |
| 14615 | 14653 | } |
| 14616 | 14654 | ZigValue *out_val = result->value; |
| 14617 | 14655 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| ... | ... | @@ -14637,7 +14675,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14637 | 14675 | // runtime known element index |
| 14638 | 14676 | switch (type_requires_comptime(ira->codegen, return_type)) { |
| 14639 | 14677 | case ReqCompTimeYes: |
| 14640 | | ir_add_error(ira, &elem_index->base, |
| 14678 | ir_add_error(ira, elem_index, |
| 14641 | 14679 | buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known", |
| 14642 | 14680 | buf_ptr(&return_type->data.pointer.child_type->name))); |
| 14643 | 14681 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -14667,13 +14705,13 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 14667 | 14705 | } |
| 14668 | 14706 | } |
| 14669 | 14707 | |
| 14670 | | return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope, |
| 14671 | | elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, safety_check_on, return_type); |
| 14708 | return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.scope, |
| 14709 | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on, return_type); |
| 14672 | 14710 | } |
| 14673 | 14711 | |
| 14674 | 14712 | static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 14675 | | ZigType *bare_struct_type, Buf *field_name, IrInst* source_instr, |
| 14676 | | IrInstGen *container_ptr, IrInst *container_ptr_src, ZigType *container_type) |
| 14713 | ZigType *bare_struct_type, Buf *field_name, Scope *scope, AstNode *source_node, |
| 14714 | IrInstGen *container_ptr, AstNode *container_ptr_src, ZigType *container_type) |
| 14677 | 14715 | { |
| 14678 | 14716 | if (!is_slice(bare_struct_type)) { |
| 14679 | 14717 | ScopeDecls *container_scope = get_container_scope(bare_struct_type); |
| ... | ... | @@ -14681,16 +14719,16 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 14681 | 14719 | auto tld = find_container_decl(ira->codegen, container_scope, field_name); |
| 14682 | 14720 | if (tld) { |
| 14683 | 14721 | if (tld->id == TldIdFn) { |
| 14684 | | resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false); |
| 14722 | resolve_top_level_decl(ira->codegen, tld, source_node, false); |
| 14685 | 14723 | if (tld->resolution == TldResolutionInvalid) |
| 14686 | 14724 | return ira->codegen->invalid_inst_gen; |
| 14687 | 14725 | if (tld->resolution == TldResolutionResolving) |
| 14688 | | return ir_error_dependency_loop(ira, source_instr); |
| 14726 | return ir_error_dependency_loop(ira, source_node); |
| 14689 | 14727 | |
| 14690 | 14728 | if (tld->visib_mod == VisibModPrivate && |
| 14691 | | tld->import != get_scope_import(source_instr->scope)) |
| 14729 | tld->import != get_scope_import(scope)) |
| 14692 | 14730 | { |
| 14693 | | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 14731 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 14694 | 14732 | buf_sprintf("'%s' is private", buf_ptr(field_name))); |
| 14695 | 14733 | add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here")); |
| 14696 | 14734 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -14703,15 +14741,15 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 14703 | 14741 | if (type_is_invalid(fn_entry->type_entry)) |
| 14704 | 14742 | return ira->codegen->invalid_inst_gen; |
| 14705 | 14743 | |
| 14706 | | IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn_entry, container_ptr, |
| 14744 | IrInstGen *bound_fn_value = ir_const_bound_fn(ira, scope, source_node, fn_entry, container_ptr, |
| 14707 | 14745 | container_ptr_src); |
| 14708 | | return ir_get_ref(ira, source_instr, bound_fn_value, true, false); |
| 14746 | return ir_get_ref(ira, scope, source_node, bound_fn_value, true, false); |
| 14709 | 14747 | } else if (tld->id == TldIdVar) { |
| 14710 | | resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false); |
| 14748 | resolve_top_level_decl(ira->codegen, tld, source_node, false); |
| 14711 | 14749 | if (tld->resolution == TldResolutionInvalid) |
| 14712 | 14750 | return ira->codegen->invalid_inst_gen; |
| 14713 | 14751 | if (tld->resolution == TldResolutionResolving) |
| 14714 | | return ir_error_dependency_loop(ira, source_instr); |
| 14752 | return ir_error_dependency_loop(ira, source_node); |
| 14715 | 14753 | |
| 14716 | 14754 | TldVar *tld_var = (TldVar *)tld; |
| 14717 | 14755 | ZigVar *var = tld_var->var; |
| ... | ... | @@ -14721,11 +14759,11 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 14721 | 14759 | return ira->codegen->invalid_inst_gen; |
| 14722 | 14760 | |
| 14723 | 14761 | if (var->const_value->type->id == ZigTypeIdFn) { |
| 14724 | | ir_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr); |
| 14762 | src_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_node); |
| 14725 | 14763 | ZigFn *fn = var->const_value->data.x_ptr.data.fn.fn_entry; |
| 14726 | | IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn, container_ptr, |
| 14764 | IrInstGen *bound_fn_value = ir_const_bound_fn(ira, scope, source_node, fn, container_ptr, |
| 14727 | 14765 | container_ptr_src); |
| 14728 | | return ir_get_ref(ira, source_instr, bound_fn_value, true, false); |
| 14766 | return ir_get_ref(ira, scope, source_node, bound_fn_value, true, false); |
| 14729 | 14767 | } |
| 14730 | 14768 | } |
| 14731 | 14769 | } |
| ... | ... | @@ -14744,7 +14782,7 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| 14744 | 14782 | } else { |
| 14745 | 14783 | prefix_name = ""; |
| 14746 | 14784 | } |
| 14747 | | ir_add_error_node(ira, source_instr->source_node, |
| 14785 | ir_add_error_node(ira, source_node, |
| 14748 | 14786 | buf_sprintf("no member named '%s' in %s'%s'", buf_ptr(field_name), prefix_name, buf_ptr(&bare_struct_type->name))); |
| 14749 | 14787 | return ira->codegen->invalid_inst_gen; |
| 14750 | 14788 | } |
| ... | ... | @@ -14762,7 +14800,7 @@ static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, Ty |
| 14762 | 14800 | field->type_entry, nullptr, UndefOk); |
| 14763 | 14801 | } |
| 14764 | 14802 | |
| 14765 | | static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 14803 | static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 14766 | 14804 | TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing) |
| 14767 | 14805 | { |
| 14768 | 14806 | Error err; |
| ... | ... | @@ -14770,21 +14808,21 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins |
| 14770 | 14808 | if (field_type == nullptr) |
| 14771 | 14809 | return ira->codegen->invalid_inst_gen; |
| 14772 | 14810 | if (field->is_comptime) { |
| 14773 | | IrInstGen *elem = ir_const(ira, source_instr, field_type); |
| 14811 | IrInstGen *elem = ir_const(ira, scope, source_node, field_type); |
| 14774 | 14812 | memoize_field_init_val(ira->codegen, struct_type, field); |
| 14775 | 14813 | if(field->init_val != nullptr && type_is_invalid(field->init_val->type)){ |
| 14776 | 14814 | return ira->codegen->invalid_inst_gen; |
| 14777 | 14815 | } |
| 14778 | 14816 | copy_const_val(ira->codegen, elem->value, field->init_val); |
| 14779 | | return ir_get_ref2(ira, source_instr, elem, field_type, true, false); |
| 14817 | return ir_get_ref2(ira, scope, source_node, elem, field_type, true, false); |
| 14780 | 14818 | } |
| 14781 | 14819 | switch (type_has_one_possible_value(ira->codegen, field_type)) { |
| 14782 | 14820 | case OnePossibleValueInvalid: |
| 14783 | 14821 | return ira->codegen->invalid_inst_gen; |
| 14784 | 14822 | case OnePossibleValueYes: { |
| 14785 | | IrInstGen *elem = ir_const_move(ira, source_instr, |
| 14823 | IrInstGen *elem = ir_const_move(ira, scope, source_node, |
| 14786 | 14824 | get_the_one_possible_value(ira->codegen, field_type)); |
| 14787 | | return ir_get_ref(ira, source_instr, elem, |
| 14825 | return ir_get_ref(ira, scope, source_node, elem, |
| 14788 | 14826 | struct_ptr->value->type->data.pointer.is_const, |
| 14789 | 14827 | struct_ptr->value->type->data.pointer.is_volatile); |
| 14790 | 14828 | } |
| ... | ... | @@ -14819,7 +14857,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins |
| 14819 | 14857 | return ira->codegen->invalid_inst_gen; |
| 14820 | 14858 | |
| 14821 | 14859 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 14822 | | ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 14860 | ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node); |
| 14823 | 14861 | if (struct_val == nullptr) |
| 14824 | 14862 | return ira->codegen->invalid_inst_gen; |
| 14825 | 14863 | if (type_is_invalid(struct_val->type)) |
| ... | ... | @@ -14827,7 +14865,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins |
| 14827 | 14865 | |
| 14828 | 14866 | // This to allow lazy values to be resolved. |
| 14829 | 14867 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 14830 | | source_instr->source_node, struct_val, UndefOk))) |
| 14868 | source_node, struct_val, UndefOk))) |
| 14831 | 14869 | { |
| 14832 | 14870 | return ira->codegen->invalid_inst_gen; |
| 14833 | 14871 | } |
| ... | ... | @@ -14846,10 +14884,10 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins |
| 14846 | 14884 | } |
| 14847 | 14885 | IrInstGen *result; |
| 14848 | 14886 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 14849 | | result = ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type); |
| 14887 | result = ir_build_struct_field_ptr(ira, scope, source_node, struct_ptr, field, ptr_type); |
| 14850 | 14888 | result->value->special = ConstValSpecialStatic; |
| 14851 | 14889 | } else { |
| 14852 | | result = ir_const(ira, source_instr, ptr_type); |
| 14890 | result = ir_const(ira, scope, source_node, ptr_type); |
| 14853 | 14891 | } |
| 14854 | 14892 | ZigValue *const_val = result->value; |
| 14855 | 14893 | const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct; |
| ... | ... | @@ -14859,11 +14897,11 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins |
| 14859 | 14897 | return result; |
| 14860 | 14898 | } |
| 14861 | 14899 | } |
| 14862 | | return ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type); |
| 14900 | return ir_build_struct_field_ptr(ira, scope, source_node, struct_ptr, field, ptr_type); |
| 14863 | 14901 | } |
| 14864 | 14902 | |
| 14865 | 14903 | static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 14866 | | IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type) |
| 14904 | Scope *scope, AstNode *source_node, IrInstGen *container_ptr, ZigType *container_type) |
| 14867 | 14905 | { |
| 14868 | 14906 | // The type of the field is not available until a store using this pointer happens. |
| 14869 | 14907 | // So, here we create a special pointer type which has the inferred struct type and |
| ... | ... | @@ -14872,7 +14910,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 14872 | 14910 | // struct. |
| 14873 | 14911 | |
| 14874 | 14912 | ZigType *container_ptr_type = container_ptr->value->type; |
| 14875 | | ir_assert(container_ptr_type->id == ZigTypeIdPointer, source_instr); |
| 14913 | src_assert(container_ptr_type->id == ZigTypeIdPointer, source_node); |
| 14876 | 14914 | |
| 14877 | 14915 | InferredStructField *inferred_struct_field = heap::c_allocator.create<InferredStructField>(); |
| 14878 | 14916 | inferred_struct_field->inferred_struct_type = container_type; |
| ... | ... | @@ -14890,20 +14928,20 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 14890 | 14928 | |
| 14891 | 14929 | IrInstGen *result; |
| 14892 | 14930 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 14893 | | result = ir_build_cast(ira, source_instr, container_ptr_type, container_ptr, CastOpNoop); |
| 14931 | result = ir_build_cast(ira, scope, source_node, container_ptr_type, container_ptr, CastOpNoop); |
| 14894 | 14932 | } else { |
| 14895 | | result = ir_const(ira, source_instr, field_ptr_type); |
| 14933 | result = ir_const(ira, scope, source_node, field_ptr_type); |
| 14896 | 14934 | } |
| 14897 | 14935 | copy_const_val(ira->codegen, result->value, ptr_val); |
| 14898 | 14936 | result->value->type = field_ptr_type; |
| 14899 | 14937 | return result; |
| 14900 | 14938 | } |
| 14901 | 14939 | |
| 14902 | | return ir_build_cast(ira, source_instr, field_ptr_type, container_ptr, CastOpNoop); |
| 14940 | return ir_build_cast(ira, scope, source_node, field_ptr_type, container_ptr, CastOpNoop); |
| 14903 | 14941 | } |
| 14904 | 14942 | |
| 14905 | 14943 | static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 14906 | | IrInst* source_instr, IrInstGen *container_ptr, IrInst *container_ptr_src, |
| 14944 | Scope *scope, AstNode *source_node, IrInstGen *container_ptr, AstNode *container_ptr_src, |
| 14907 | 14945 | ZigType *container_type, bool initializing) |
| 14908 | 14946 | { |
| 14909 | 14947 | Error err; |
| ... | ... | @@ -14913,13 +14951,13 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 14913 | 14951 | if (initializing && bare_type->id == ZigTypeIdStruct && |
| 14914 | 14952 | bare_type->data.structure.resolve_status == ResolveStatusBeingInferred) |
| 14915 | 14953 | { |
| 14916 | | return ir_analyze_inferred_field_ptr(ira, field_name, source_instr, container_ptr, bare_type); |
| 14954 | return ir_analyze_inferred_field_ptr(ira, field_name, scope, source_node, container_ptr, bare_type); |
| 14917 | 14955 | } |
| 14918 | 14956 | |
| 14919 | 14957 | // Tracks wether we should return an undefined value of the correct type. |
| 14920 | 14958 | // We do this if the container pointer is undefined and we are in a TypeOf call. |
| 14921 | 14959 | bool return_undef = container_ptr->value->special == ConstValSpecialUndef && \ |
| 14922 | | get_scope_typeof(source_instr->scope) != nullptr; |
| 14960 | get_scope_typeof(scope) != nullptr; |
| 14923 | 14961 | |
| 14924 | 14962 | if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown))) |
| 14925 | 14963 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -14931,19 +14969,19 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 14931 | 14969 | if (return_undef) { |
| 14932 | 14970 | ZigType *field_ptr_type = get_pointer_to_type(ira->codegen, resolve_struct_field_type(ira->codegen, field), |
| 14933 | 14971 | container_ptr->value->type->data.pointer.is_const); |
| 14934 | | return ir_const_undef(ira, source_instr, field_ptr_type); |
| 14972 | return ir_const_undef(ira, scope, source_node, field_ptr_type); |
| 14935 | 14973 | } |
| 14936 | 14974 | |
| 14937 | | return ir_analyze_struct_field_ptr(ira, source_instr, field, container_ptr, bare_type, initializing); |
| 14975 | return ir_analyze_struct_field_ptr(ira, scope, source_node, field, container_ptr, bare_type, initializing); |
| 14938 | 14976 | } else { |
| 14939 | 14977 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |
| 14940 | | source_instr, container_ptr, container_ptr_src, container_type); |
| 14978 | scope, source_node, container_ptr, container_ptr_src, container_type); |
| 14941 | 14979 | } |
| 14942 | 14980 | } |
| 14943 | 14981 | |
| 14944 | 14982 | if (bare_type->id == ZigTypeIdEnum || bare_type->id == ZigTypeIdOpaque) { |
| 14945 | 14983 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |
| 14946 | | source_instr, container_ptr, container_ptr_src, container_type); |
| 14984 | scope, source_node, container_ptr, container_ptr_src, container_type); |
| 14947 | 14985 | } |
| 14948 | 14986 | |
| 14949 | 14987 | if (bare_type->id == ZigTypeIdUnion) { |
| ... | ... | @@ -14953,7 +14991,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 14953 | 14991 | TypeUnionField *field = find_union_type_field(bare_type, field_name); |
| 14954 | 14992 | if (field == nullptr) { |
| 14955 | 14993 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |
| 14956 | | source_instr, container_ptr, container_ptr_src, container_type); |
| 14994 | scope, source_node, container_ptr, container_ptr_src, container_type); |
| 14957 | 14995 | } |
| 14958 | 14996 | |
| 14959 | 14997 | ZigType *field_type = resolve_union_field_type(ira->codegen, field); |
| ... | ... | @@ -14969,7 +15007,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 14969 | 15007 | |
| 14970 | 15008 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| 14971 | 15009 | ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 14972 | | ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 15010 | ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node); |
| 14973 | 15011 | if (union_val == nullptr) |
| 14974 | 15012 | return ira->codegen->invalid_inst_gen; |
| 14975 | 15013 | if (type_is_invalid(union_val->type)) |
| ... | ... | @@ -14980,7 +15018,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 14980 | 15018 | // its payload slot is UB. |
| 14981 | 15019 | const UndefAllowed allow_undef = initializing ? UndefOk : UndefBad; |
| 14982 | 15020 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 14983 | | source_instr->source_node, union_val, allow_undef))) |
| 15021 | source_node, union_val, allow_undef))) |
| 14984 | 15022 | { |
| 14985 | 15023 | return ira->codegen->invalid_inst_gen; |
| 14986 | 15024 | } |
| ... | ... | @@ -15001,7 +15039,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 15001 | 15039 | zig_unreachable(); |
| 15002 | 15040 | |
| 15003 | 15041 | if (field != actual_field) { |
| 15004 | | ir_add_error_node(ira, source_instr->source_node, |
| 15042 | ir_add_error_node(ira, source_node, |
| 15005 | 15043 | buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name), |
| 15006 | 15044 | buf_ptr(actual_field->name))); |
| 15007 | 15045 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -15013,11 +15051,11 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 15013 | 15051 | |
| 15014 | 15052 | IrInstGen *result; |
| 15015 | 15053 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 15016 | | result = ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true, |
| 15054 | result = ir_build_union_field_ptr(ira, scope, source_node, container_ptr, field, true, |
| 15017 | 15055 | initializing, ptr_type); |
| 15018 | 15056 | result->value->special = ConstValSpecialStatic; |
| 15019 | 15057 | } else { |
| 15020 | | result = ir_const(ira, source_instr, ptr_type); |
| 15058 | result = ir_const(ira, scope, source_node, ptr_type); |
| 15021 | 15059 | } |
| 15022 | 15060 | ZigValue *const_val = result->value; |
| 15023 | 15061 | const_val->data.x_ptr.special = ConstPtrSpecialRef; |
| ... | ... | @@ -15027,7 +15065,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 15027 | 15065 | } |
| 15028 | 15066 | } |
| 15029 | 15067 | |
| 15030 | | return ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true, initializing, ptr_type); |
| 15068 | return ir_build_union_field_ptr(ira, scope, source_node, container_ptr, field, true, initializing, ptr_type); |
| 15031 | 15069 | } |
| 15032 | 15070 | |
| 15033 | 15071 | zig_unreachable(); |
| ... | ... | @@ -15042,18 +15080,18 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, |
| 15042 | 15080 | } |
| 15043 | 15081 | } |
| 15044 | 15082 | |
| 15045 | | static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst* source_instr) { |
| 15046 | | ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected")); |
| 15083 | static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, AstNode* source_node) { |
| 15084 | ir_add_error_node(ira, source_node, buf_sprintf("dependency loop detected")); |
| 15047 | 15085 | return ira->codegen->invalid_inst_gen; |
| 15048 | 15086 | } |
| 15049 | 15087 | |
| 15050 | | static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction, Tld *tld) { |
| 15051 | | resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node, true); |
| 15088 | static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, Scope *scope, AstNode *source_node, Tld *tld) { |
| 15089 | resolve_top_level_decl(ira->codegen, tld, source_node, true); |
| 15052 | 15090 | if (tld->resolution == TldResolutionInvalid) { |
| 15053 | 15091 | return ira->codegen->invalid_inst_gen; |
| 15054 | 15092 | } |
| 15055 | 15093 | if (tld->resolution == TldResolutionResolving) |
| 15056 | | return ir_error_dependency_loop(ira, source_instruction); |
| 15094 | return ir_error_dependency_loop(ira, source_node); |
| 15057 | 15095 | |
| 15058 | 15096 | switch (tld->id) { |
| 15059 | 15097 | case TldIdContainer: |
| ... | ... | @@ -15067,10 +15105,10 @@ static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction |
| 15067 | 15105 | |
| 15068 | 15106 | if (tld_var->extern_lib_name != nullptr) { |
| 15069 | 15107 | add_link_lib_symbol(ira, tld_var->extern_lib_name, buf_create_from_str(var->name), |
| 15070 | | source_instruction->source_node); |
| 15108 | source_node); |
| 15071 | 15109 | } |
| 15072 | 15110 | |
| 15073 | | return ir_get_var_ptr(ira, source_instruction, var); |
| 15111 | return ir_get_var_ptr(ira, scope, source_node, var); |
| 15074 | 15112 | } |
| 15075 | 15113 | case TldIdFn: { |
| 15076 | 15114 | TldFn *tld_fn = (TldFn *)tld; |
| ... | ... | @@ -15081,11 +15119,11 @@ static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction |
| 15081 | 15119 | return ira->codegen->invalid_inst_gen; |
| 15082 | 15120 | |
| 15083 | 15121 | if (tld_fn->extern_lib_name != nullptr) { |
| 15084 | | add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node); |
| 15122 | add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_node); |
| 15085 | 15123 | } |
| 15086 | 15124 | |
| 15087 | | IrInstGen *fn_inst = ir_const_fn(ira, source_instruction, fn_entry); |
| 15088 | | return ir_get_ref(ira, source_instruction, fn_inst, true, false); |
| 15125 | IrInstGen *fn_inst = ir_const_fn(ira, scope, source_node, fn_entry); |
| 15126 | return ir_get_ref(ira, scope, source_node, fn_inst, true, false); |
| 15089 | 15127 | } |
| 15090 | 15128 | } |
| 15091 | 15129 | zig_unreachable(); |
| ... | ... | @@ -15119,27 +15157,30 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel |
| 15119 | 15157 | } |
| 15120 | 15158 | |
| 15121 | 15159 | |
| 15122 | | AstNode *source_node = field_ptr_instruction->base.base.source_node; |
| 15160 | AstNode *source_node = field_ptr_instruction->base.source_node; |
| 15123 | 15161 | |
| 15124 | 15162 | if (type_is_invalid(container_type)) { |
| 15125 | 15163 | return ira->codegen->invalid_inst_gen; |
| 15126 | 15164 | } else if (is_tuple(container_type) && !field_ptr_instruction->initializing && buf_eql_str(field_name, "len")) { |
| 15127 | | IrInstGen *len_inst = ir_const_unsigned(ira, &field_ptr_instruction->base.base, |
| 15165 | IrInstGen *len_inst = ir_const_unsigned(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, |
| 15128 | 15166 | container_type->data.structure.src_field_count); |
| 15129 | | return ir_get_ref(ira, &field_ptr_instruction->base.base, len_inst, true, false); |
| 15167 | return ir_get_ref(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, len_inst, true, false); |
| 15130 | 15168 | } else if (is_slice(container_type) || is_container_ref(container_type)) { |
| 15131 | 15169 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 15132 | 15170 | if (container_type->id == ZigTypeIdPointer) { |
| 15133 | 15171 | ZigType *bare_type = container_ref_type(container_type); |
| 15134 | | IrInstGen *container_child = ir_get_deref(ira, &field_ptr_instruction->base.base, container_ptr, nullptr); |
| 15135 | | IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base, |
| 15136 | | container_child, &field_ptr_instruction->container_ptr->base, bare_type, |
| 15172 | IrInstGen *container_child = ir_get_deref(ira, field_ptr_instruction->base.scope, |
| 15173 | field_ptr_instruction->base.source_node, container_ptr, nullptr); |
| 15174 | IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, |
| 15175 | field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, |
| 15176 | container_child, field_ptr_instruction->container_ptr->source_node, bare_type, |
| 15137 | 15177 | field_ptr_instruction->initializing); |
| 15138 | 15178 | return result; |
| 15139 | 15179 | } else { |
| 15140 | | IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base, |
| 15141 | | container_ptr, &field_ptr_instruction->container_ptr->base, container_type, |
| 15142 | | field_ptr_instruction->initializing); |
| 15180 | IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, |
| 15181 | field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, |
| 15182 | container_ptr, field_ptr_instruction->container_ptr->source_node, |
| 15183 | container_type, field_ptr_instruction->initializing); |
| 15143 | 15184 | return result; |
| 15144 | 15185 | } |
| 15145 | 15186 | } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) { |
| ... | ... | @@ -15154,7 +15195,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel |
| 15154 | 15195 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 15155 | 15196 | bool ptr_is_const = true; |
| 15156 | 15197 | bool ptr_is_volatile = false; |
| 15157 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, len_val, |
| 15198 | return ir_get_const_ptr(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, len_val, |
| 15158 | 15199 | usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15159 | 15200 | } else { |
| 15160 | 15201 | ir_add_error_node(ira, source_node, |
| ... | ... | @@ -15172,7 +15213,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel |
| 15172 | 15213 | if (child_val == nullptr) |
| 15173 | 15214 | return ira->codegen->invalid_inst_gen; |
| 15174 | 15215 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 15175 | | field_ptr_instruction->base.base.source_node, child_val, UndefBad))) |
| 15216 | field_ptr_instruction->base.source_node, child_val, UndefBad))) |
| 15176 | 15217 | { |
| 15177 | 15218 | return ira->codegen->invalid_inst_gen; |
| 15178 | 15219 | } |
| ... | ... | @@ -15189,7 +15230,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel |
| 15189 | 15230 | if (field) { |
| 15190 | 15231 | bool ptr_is_const = true; |
| 15191 | 15232 | bool ptr_is_volatile = false; |
| 15192 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 15233 | return ir_get_const_ptr(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, |
| 15193 | 15234 | create_const_enum(ira->codegen, child_type, &field->value), child_type, |
| 15194 | 15235 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15195 | 15236 | } |
| ... | ... | @@ -15198,14 +15239,14 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel |
| 15198 | 15239 | Tld *tld = find_container_decl(ira->codegen, container_scope, field_name); |
| 15199 | 15240 | if (tld) { |
| 15200 | 15241 | if (tld->visib_mod == VisibModPrivate && |
| 15201 | | tld->import != get_scope_import(field_ptr_instruction->base.base.scope)) |
| 15242 | tld->import != get_scope_import(field_ptr_instruction->base.scope)) |
| 15202 | 15243 | { |
| 15203 | | ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base.base, |
| 15204 | | buf_sprintf("'%s' is private", buf_ptr(field_name))); |
| 15244 | ErrorMsg *msg = ir_add_error_node(ira, field_ptr_instruction->base.source_node, |
| 15245 | buf_sprintf("'%s' is private", buf_ptr(field_name))); |
| 15205 | 15246 | add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here")); |
| 15206 | 15247 | return ira->codegen->invalid_inst_gen; |
| 15207 | 15248 | } |
| 15208 | | return ir_analyze_decl_ref(ira, &field_ptr_instruction->base.base, tld); |
| 15249 | return ir_analyze_decl_ref(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, tld); |
| 15209 | 15250 | } |
| 15210 | 15251 | if (child_type->id == ZigTypeIdUnion && |
| 15211 | 15252 | (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr || |
| ... | ... | @@ -15218,14 +15259,14 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel |
| 15218 | 15259 | ZigType *enum_type = child_type->data.unionation.tag_type; |
| 15219 | 15260 | bool ptr_is_const = true; |
| 15220 | 15261 | bool ptr_is_volatile = false; |
| 15221 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, |
| 15262 | return ir_get_const_ptr(ira, field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, |
| 15222 | 15263 | create_const_enum(ira->codegen, enum_type, &field->enum_field->value), enum_type, |
| 15223 | 15264 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15224 | 15265 | } |
| 15225 | 15266 | } |
| 15226 | 15267 | const char *container_name = (child_type == ira->codegen->root_import) ? |
| 15227 | 15268 | "root source file" : buf_ptr(buf_sprintf("container '%s'", buf_ptr(&child_type->name))); |
| 15228 | | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 15269 | ir_add_error_node(ira, field_ptr_instruction->base.source_node, |
| 15229 | 15270 | buf_sprintf("%s has no member called '%s'", |
| 15230 | 15271 | container_name, buf_ptr(field_name))); |
| 15231 | 15272 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -15238,7 +15279,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel |
| 15238 | 15279 | err_entry = existing_entry->value; |
| 15239 | 15280 | } else { |
| 15240 | 15281 | err_entry = heap::c_allocator.create<ErrorTableEntry>(); |
| 15241 | | err_entry->decl_node = field_ptr_instruction->base.base.source_node; |
| 15282 | err_entry->decl_node = field_ptr_instruction->base.source_node; |
| 15242 | 15283 | buf_init_from_buf(&err_entry->name, field_name); |
| 15243 | 15284 | size_t error_value_count = ira->codegen->errors_by_index.length; |
| 15244 | 15285 | assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)ira->codegen->err_tag_type->data.integral.bit_count)); |
| ... | ... | @@ -15248,17 +15289,17 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel |
| 15248 | 15289 | } |
| 15249 | 15290 | if (err_entry->set_with_only_this_in_it == nullptr) { |
| 15250 | 15291 | err_entry->set_with_only_this_in_it = make_err_set_with_one_item(ira->codegen, |
| 15251 | | field_ptr_instruction->base.base.scope, field_ptr_instruction->base.base.source_node, |
| 15292 | field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node, |
| 15252 | 15293 | err_entry); |
| 15253 | 15294 | } |
| 15254 | 15295 | err_set_type = err_entry->set_with_only_this_in_it; |
| 15255 | 15296 | } else { |
| 15256 | | if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.base.source_node)) { |
| 15297 | if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.source_node)) { |
| 15257 | 15298 | return ira->codegen->invalid_inst_gen; |
| 15258 | 15299 | } |
| 15259 | 15300 | err_entry = find_err_table_entry(child_type, field_name); |
| 15260 | 15301 | if (err_entry == nullptr) { |
| 15261 | | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 15302 | ir_add_error_node(ira, field_ptr_instruction->base.source_node, |
| 15262 | 15303 | buf_sprintf("no error named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&child_type->name))); |
| 15263 | 15304 | return ira->codegen->invalid_inst_gen; |
| 15264 | 15305 | } |
| ... | ... | @@ -15271,19 +15312,20 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel |
| 15271 | 15312 | |
| 15272 | 15313 | bool ptr_is_const = true; |
| 15273 | 15314 | bool ptr_is_volatile = false; |
| 15274 | | return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, const_val, |
| 15315 | return ir_get_const_ptr(ira, field_ptr_instruction->base.scope, |
| 15316 | field_ptr_instruction->base.source_node, const_val, |
| 15275 | 15317 | err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15276 | 15318 | } else { |
| 15277 | | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 15319 | ir_add_error_node(ira, field_ptr_instruction->base.source_node, |
| 15278 | 15320 | buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name))); |
| 15279 | 15321 | return ira->codegen->invalid_inst_gen; |
| 15280 | 15322 | } |
| 15281 | 15323 | } else if (field_ptr_instruction->initializing) { |
| 15282 | | ir_add_error(ira, &field_ptr_instruction->base.base, |
| 15324 | ir_add_error_node(ira, field_ptr_instruction->base.source_node, |
| 15283 | 15325 | buf_sprintf("type '%s' does not support struct initialization syntax", buf_ptr(&container_type->name))); |
| 15284 | 15326 | return ira->codegen->invalid_inst_gen; |
| 15285 | 15327 | } else { |
| 15286 | | ir_add_error_node(ira, field_ptr_instruction->base.base.source_node, |
| 15328 | ir_add_error_node(ira, field_ptr_instruction->base.source_node, |
| 15287 | 15329 | buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name))); |
| 15288 | 15330 | return ira->codegen->invalid_inst_gen; |
| 15289 | 15331 | } |
| ... | ... | @@ -15298,14 +15340,14 @@ static IrInstGen *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstSrcStor |
| 15298 | 15340 | if (type_is_invalid(value->value->type)) |
| 15299 | 15341 | return ira->codegen->invalid_inst_gen; |
| 15300 | 15342 | |
| 15301 | | return ir_analyze_store_ptr(ira, &instruction->base.base, ptr, value, instruction->allow_write_through_const); |
| 15343 | return ir_analyze_store_ptr(ira, instruction->base.scope, instruction->base.source_node, ptr, value, instruction->allow_write_through_const); |
| 15302 | 15344 | } |
| 15303 | 15345 | |
| 15304 | 15346 | static IrInstGen *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstSrcLoadPtr *instruction) { |
| 15305 | 15347 | IrInstGen *ptr = instruction->ptr->child; |
| 15306 | 15348 | if (type_is_invalid(ptr->value->type)) |
| 15307 | 15349 | return ira->codegen->invalid_inst_gen; |
| 15308 | | return ir_get_deref(ira, &instruction->base.base, ptr, nullptr); |
| 15350 | return ir_get_deref(ira, instruction->base.scope, instruction->base.source_node, ptr, nullptr); |
| 15309 | 15351 | } |
| 15310 | 15352 | |
| 15311 | 15353 | static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf *typeof_instruction) { |
| ... | ... | @@ -15325,7 +15367,7 @@ static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf |
| 15325 | 15367 | args[i] = value; |
| 15326 | 15368 | } |
| 15327 | 15369 | |
| 15328 | | type_entry = ir_resolve_peer_types(ira, typeof_instruction->base.base.source_node, |
| 15370 | type_entry = ir_resolve_peer_types(ira, typeof_instruction->base.source_node, |
| 15329 | 15371 | nullptr, args, value_count); |
| 15330 | 15372 | |
| 15331 | 15373 | heap::c_allocator.deallocate(args, value_count); |
| ... | ... | @@ -15334,13 +15376,13 @@ static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf |
| 15334 | 15376 | if (type_is_invalid(type_entry)) |
| 15335 | 15377 | return ira->codegen->invalid_inst_gen; |
| 15336 | 15378 | |
| 15337 | | return ir_const_type(ira, &typeof_instruction->base.base, type_entry); |
| 15379 | return ir_const_type(ira, typeof_instruction->base.scope, typeof_instruction->base.source_node, type_entry); |
| 15338 | 15380 | } |
| 15339 | 15381 | |
| 15340 | 15382 | static IrInstGen *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstSrcSetCold *instruction) { |
| 15341 | 15383 | if (ira->new_irb.exec->is_inline) { |
| 15342 | 15384 | // ignore setCold when running functions at compile time |
| 15343 | | return ir_const_void(ira, &instruction->base.base); |
| 15385 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 15344 | 15386 | } |
| 15345 | 15387 | |
| 15346 | 15388 | IrInstGen *is_cold_value = instruction->is_cold->child; |
| ... | ... | @@ -15348,22 +15390,22 @@ static IrInstGen *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstSrcSetCo |
| 15348 | 15390 | if (!ir_resolve_bool(ira, is_cold_value, &want_cold)) |
| 15349 | 15391 | return ira->codegen->invalid_inst_gen; |
| 15350 | 15392 | |
| 15351 | | ZigFn *fn_entry = scope_fn_entry(instruction->base.base.scope); |
| 15393 | ZigFn *fn_entry = scope_fn_entry(instruction->base.scope); |
| 15352 | 15394 | if (fn_entry == nullptr) { |
| 15353 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("@setCold outside function")); |
| 15395 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@setCold outside function")); |
| 15354 | 15396 | return ira->codegen->invalid_inst_gen; |
| 15355 | 15397 | } |
| 15356 | 15398 | |
| 15357 | 15399 | if (fn_entry->set_cold_node != nullptr) { |
| 15358 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, buf_sprintf("cold set twice in same function")); |
| 15400 | ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("cold set twice in same function")); |
| 15359 | 15401 | add_error_note(ira->codegen, msg, fn_entry->set_cold_node, buf_sprintf("first set here")); |
| 15360 | 15402 | return ira->codegen->invalid_inst_gen; |
| 15361 | 15403 | } |
| 15362 | 15404 | |
| 15363 | | fn_entry->set_cold_node = instruction->base.base.source_node; |
| 15405 | fn_entry->set_cold_node = instruction->base.source_node; |
| 15364 | 15406 | fn_entry->is_cold = want_cold; |
| 15365 | 15407 | |
| 15366 | | return ir_const_void(ira, &instruction->base.base); |
| 15408 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 15367 | 15409 | } |
| 15368 | 15410 | |
| 15369 | 15411 | static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| ... | ... | @@ -15371,13 +15413,14 @@ static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 15371 | 15413 | { |
| 15372 | 15414 | if (ira->new_irb.exec->is_inline) { |
| 15373 | 15415 | // ignore setRuntimeSafety when running functions at compile time |
| 15374 | | return ir_const_void(ira, &set_runtime_safety_instruction->base.base); |
| 15416 | return ir_const_void(ira, set_runtime_safety_instruction->base.scope, |
| 15417 | set_runtime_safety_instruction->base.source_node); |
| 15375 | 15418 | } |
| 15376 | 15419 | |
| 15377 | 15420 | bool *safety_off_ptr; |
| 15378 | 15421 | AstNode **safety_set_node_ptr; |
| 15379 | 15422 | |
| 15380 | | Scope *scope = set_runtime_safety_instruction->base.base.scope; |
| 15423 | Scope *scope = set_runtime_safety_instruction->base.scope; |
| 15381 | 15424 | while (scope != nullptr) { |
| 15382 | 15425 | if (scope->id == ScopeIdBlock) { |
| 15383 | 15426 | ScopeBlock *block_scope = (ScopeBlock *)scope; |
| ... | ... | @@ -15408,7 +15451,7 @@ static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 15408 | 15451 | if (!ir_resolve_bool(ira, safety_on_value, &want_runtime_safety)) |
| 15409 | 15452 | return ira->codegen->invalid_inst_gen; |
| 15410 | 15453 | |
| 15411 | | AstNode *source_node = set_runtime_safety_instruction->base.base.source_node; |
| 15454 | AstNode *source_node = set_runtime_safety_instruction->base.source_node; |
| 15412 | 15455 | if (*safety_set_node_ptr) { |
| 15413 | 15456 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 15414 | 15457 | buf_sprintf("runtime safety set twice for same scope")); |
| ... | ... | @@ -15418,7 +15461,8 @@ static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 15418 | 15461 | *safety_set_node_ptr = source_node; |
| 15419 | 15462 | *safety_off_ptr = !want_runtime_safety; |
| 15420 | 15463 | |
| 15421 | | return ir_const_void(ira, &set_runtime_safety_instruction->base.base); |
| 15464 | return ir_const_void(ira, set_runtime_safety_instruction->base.scope, |
| 15465 | set_runtime_safety_instruction->base.source_node); |
| 15422 | 15466 | } |
| 15423 | 15467 | |
| 15424 | 15468 | static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| ... | ... | @@ -15426,13 +15470,13 @@ static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 15426 | 15470 | { |
| 15427 | 15471 | if (ira->new_irb.exec->is_inline) { |
| 15428 | 15472 | // ignore setFloatMode when running functions at compile time |
| 15429 | | return ir_const_void(ira, &instruction->base.base); |
| 15473 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 15430 | 15474 | } |
| 15431 | 15475 | |
| 15432 | 15476 | bool *fast_math_on_ptr; |
| 15433 | 15477 | AstNode **fast_math_set_node_ptr; |
| 15434 | 15478 | |
| 15435 | | Scope *scope = instruction->base.base.scope; |
| 15479 | Scope *scope = instruction->base.scope; |
| 15436 | 15480 | while (scope != nullptr) { |
| 15437 | 15481 | if (scope->id == ScopeIdBlock) { |
| 15438 | 15482 | ScopeBlock *block_scope = (ScopeBlock *)scope; |
| ... | ... | @@ -15463,7 +15507,7 @@ static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 15463 | 15507 | if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar)) |
| 15464 | 15508 | return ira->codegen->invalid_inst_gen; |
| 15465 | 15509 | |
| 15466 | | AstNode *source_node = instruction->base.base.source_node; |
| 15510 | AstNode *source_node = instruction->base.source_node; |
| 15467 | 15511 | if (*fast_math_set_node_ptr) { |
| 15468 | 15512 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 15469 | 15513 | buf_sprintf("float mode set twice for same scope")); |
| ... | ... | @@ -15473,7 +15517,7 @@ static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 15473 | 15517 | *fast_math_set_node_ptr = source_node; |
| 15474 | 15518 | *fast_math_on_ptr = (float_mode_scalar == FloatModeOptimized); |
| 15475 | 15519 | |
| 15476 | | return ir_const_void(ira, &instruction->base.base); |
| 15520 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 15477 | 15521 | } |
| 15478 | 15522 | |
| 15479 | 15523 | static IrInstGen *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, IrInstSrcAnyFrameType *instruction) { |
| ... | ... | @@ -15485,11 +15529,12 @@ static IrInstGen *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, IrInstSr |
| 15485 | 15529 | } |
| 15486 | 15530 | |
| 15487 | 15531 | ZigType *any_frame_type = get_any_frame_type(ira->codegen, payload_type); |
| 15488 | | return ir_const_type(ira, &instruction->base.base, any_frame_type); |
| 15532 | return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, any_frame_type); |
| 15489 | 15533 | } |
| 15490 | 15534 | |
| 15491 | 15535 | static IrInstGen *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstSrcSliceType *slice_type_instruction) { |
| 15492 | | IrInstGen *result = ir_const(ira, &slice_type_instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 15536 | IrInstGen *result = ir_const(ira, slice_type_instruction->base.scope, |
| 15537 | slice_type_instruction->base.source_node, ira->codegen->builtin_types.entry_type); |
| 15493 | 15538 | result->value->special = ConstValSpecialLazy; |
| 15494 | 15539 | |
| 15495 | 15540 | LazyValueSliceType *lazy_slice_type = heap::c_allocator.create<LazyValueSliceType>(); |
| ... | ... | @@ -15542,10 +15587,10 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_ |
| 15542 | 15587 | static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_instruction) { |
| 15543 | 15588 | Error err; |
| 15544 | 15589 | |
| 15545 | | assert(asm_instruction->base.base.source_node->type == NodeTypeAsmExpr); |
| 15590 | assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr); |
| 15546 | 15591 | |
| 15547 | | AstNode *node = asm_instruction->base.base.source_node; |
| 15548 | | AstNodeAsmExpr *asm_expr = &asm_instruction->base.base.source_node->data.asm_expr; |
| 15592 | AstNode *node = asm_instruction->base.source_node; |
| 15593 | AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr; |
| 15549 | 15594 | |
| 15550 | 15595 | Buf *template_buf = ir_resolve_str(ira, asm_instruction->asm_template->child); |
| 15551 | 15596 | if (template_buf == nullptr) |
| ... | ... | @@ -15555,10 +15600,10 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i |
| 15555 | 15600 | buf_append_char(&ira->codegen->global_asm, '\n'); |
| 15556 | 15601 | buf_append_buf(&ira->codegen->global_asm, template_buf); |
| 15557 | 15602 | |
| 15558 | | return ir_const_void(ira, &asm_instruction->base.base); |
| 15603 | return ir_const_void(ira, asm_instruction->base.scope, asm_instruction->base.source_node); |
| 15559 | 15604 | } |
| 15560 | 15605 | |
| 15561 | | if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base.base)) |
| 15606 | if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base)) |
| 15562 | 15607 | return ira->codegen->invalid_inst_gen; |
| 15563 | 15608 | |
| 15564 | 15609 | ZigList<AsmToken> tok_list = {}; |
| ... | ... | @@ -15606,7 +15651,7 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i |
| 15606 | 15651 | if (instr_is_comptime(input_value) && |
| 15607 | 15652 | (input_value->value->type->id == ZigTypeIdComptimeInt || |
| 15608 | 15653 | input_value->value->type->id == ZigTypeIdComptimeFloat)) { |
| 15609 | | ir_add_error(ira, &input_value->base, |
| 15654 | ir_add_error(ira, input_value, |
| 15610 | 15655 | buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name))); |
| 15611 | 15656 | return ira->codegen->invalid_inst_gen; |
| 15612 | 15657 | } |
| ... | ... | @@ -15614,14 +15659,15 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i |
| 15614 | 15659 | input_list[i] = input_value; |
| 15615 | 15660 | } |
| 15616 | 15661 | |
| 15617 | | return ir_build_asm_gen(ira, &asm_instruction->base.base, |
| 15662 | return ir_build_asm_gen(ira, asm_instruction->base.scope, asm_instruction->base.source_node, |
| 15618 | 15663 | template_buf, tok_list.items, tok_list.length, |
| 15619 | 15664 | input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count, |
| 15620 | 15665 | asm_instruction->has_side_effects, return_type); |
| 15621 | 15666 | } |
| 15622 | 15667 | |
| 15623 | 15668 | static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArrayType *array_type_instruction) { |
| 15624 | | IrInstGen *result = ir_const(ira, &array_type_instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 15669 | IrInstGen *result = ir_const(ira, array_type_instruction->base.scope, |
| 15670 | array_type_instruction->base.source_node, ira->codegen->builtin_types.entry_type); |
| 15625 | 15671 | result->value->special = ConstValSpecialLazy; |
| 15626 | 15672 | |
| 15627 | 15673 | LazyValueArrayType *lazy_array_type = heap::c_allocator.create<LazyValueArrayType>(); |
| ... | ... | @@ -15646,7 +15692,7 @@ static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArr |
| 15646 | 15692 | } |
| 15647 | 15693 | |
| 15648 | 15694 | static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf *instruction) { |
| 15649 | | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 15695 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int); |
| 15650 | 15696 | result->value->special = ConstValSpecialLazy; |
| 15651 | 15697 | |
| 15652 | 15698 | LazyValueSizeOf *lazy_size_of = heap::c_allocator.create<LazyValueSizeOf>(); |
| ... | ... | @@ -15662,7 +15708,7 @@ static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf |
| 15662 | 15708 | return result; |
| 15663 | 15709 | } |
| 15664 | 15710 | |
| 15665 | | static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value) { |
| 15711 | static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value) { |
| 15666 | 15712 | ZigType *type_entry = value->value->type; |
| 15667 | 15713 | |
| 15668 | 15714 | if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) { |
| ... | ... | @@ -15671,30 +15717,30 @@ static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, |
| 15671 | 15717 | if (c_ptr_val == nullptr) |
| 15672 | 15718 | return ira->codegen->invalid_inst_gen; |
| 15673 | 15719 | if (c_ptr_val->special == ConstValSpecialUndef) |
| 15674 | | return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool); |
| 15720 | return ir_const_undef(ira, scope, source_node, ira->codegen->builtin_types.entry_bool); |
| 15675 | 15721 | bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull || |
| 15676 | 15722 | (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr && |
| 15677 | 15723 | c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0); |
| 15678 | | return ir_const_bool(ira, source_inst, !is_null); |
| 15724 | return ir_const_bool(ira, scope, source_node, !is_null); |
| 15679 | 15725 | } |
| 15680 | 15726 | |
| 15681 | | return ir_build_test_non_null_gen(ira, source_inst, value); |
| 15727 | return ir_build_test_non_null_gen(ira, scope, source_node, value); |
| 15682 | 15728 | } else if (type_entry->id == ZigTypeIdOptional) { |
| 15683 | 15729 | if (instr_is_comptime(value)) { |
| 15684 | 15730 | ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk); |
| 15685 | 15731 | if (maybe_val == nullptr) |
| 15686 | 15732 | return ira->codegen->invalid_inst_gen; |
| 15687 | 15733 | if (maybe_val->special == ConstValSpecialUndef) |
| 15688 | | return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool); |
| 15734 | return ir_const_undef(ira, scope, source_node, ira->codegen->builtin_types.entry_bool); |
| 15689 | 15735 | |
| 15690 | | return ir_const_bool(ira, source_inst, !optional_value_is_null(maybe_val)); |
| 15736 | return ir_const_bool(ira, scope, source_node, !optional_value_is_null(maybe_val)); |
| 15691 | 15737 | } |
| 15692 | 15738 | |
| 15693 | | return ir_build_test_non_null_gen(ira, source_inst, value); |
| 15739 | return ir_build_test_non_null_gen(ira, scope, source_node, value); |
| 15694 | 15740 | } else if (type_entry->id == ZigTypeIdNull) { |
| 15695 | | return ir_const_bool(ira, source_inst, false); |
| 15741 | return ir_const_bool(ira, scope, source_node, false); |
| 15696 | 15742 | } else { |
| 15697 | | return ir_const_bool(ira, source_inst, true); |
| 15743 | return ir_const_bool(ira, scope, source_node, true); |
| 15698 | 15744 | } |
| 15699 | 15745 | } |
| 15700 | 15746 | |
| ... | ... | @@ -15703,10 +15749,10 @@ static IrInstGen *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstSrc |
| 15703 | 15749 | if (type_is_invalid(value->value->type)) |
| 15704 | 15750 | return ira->codegen->invalid_inst_gen; |
| 15705 | 15751 | |
| 15706 | | return ir_analyze_test_non_null(ira, &instruction->base.base, value); |
| 15752 | return ir_analyze_test_non_null(ira, instruction->base.scope, instruction->base.source_node, value); |
| 15707 | 15753 | } |
| 15708 | 15754 | |
| 15709 | | static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr, |
| 15755 | static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 15710 | 15756 | IrInstGen *base_ptr, bool safety_check_on, bool initializing) |
| 15711 | 15757 | { |
| 15712 | 15758 | Error err; |
| ... | ... | @@ -15721,14 +15767,14 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou |
| 15721 | 15767 | if (!val) |
| 15722 | 15768 | return ira->codegen->invalid_inst_gen; |
| 15723 | 15769 | if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 15724 | | ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); |
| 15770 | ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_node); |
| 15725 | 15771 | if (c_ptr_val == nullptr) |
| 15726 | 15772 | return ira->codegen->invalid_inst_gen; |
| 15727 | 15773 | bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull || |
| 15728 | 15774 | (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr && |
| 15729 | 15775 | c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0); |
| 15730 | 15776 | if (is_null) { |
| 15731 | | ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null")); |
| 15777 | ir_add_error_node(ira, source_node, buf_sprintf("unable to unwrap null")); |
| 15732 | 15778 | return ira->codegen->invalid_inst_gen; |
| 15733 | 15779 | } |
| 15734 | 15780 | return base_ptr; |
| ... | ... | @@ -15736,13 +15782,13 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou |
| 15736 | 15782 | } |
| 15737 | 15783 | if (!safety_check_on) |
| 15738 | 15784 | return base_ptr; |
| 15739 | | IrInstGen *c_ptr_val = ir_get_deref(ira, source_instr, base_ptr, nullptr); |
| 15740 | | ir_build_assert_non_null(ira, source_instr, c_ptr_val); |
| 15785 | IrInstGen *c_ptr_val = ir_get_deref(ira, scope, source_node, base_ptr, nullptr); |
| 15786 | ir_build_assert_non_null(ira, scope, source_node, c_ptr_val); |
| 15741 | 15787 | return base_ptr; |
| 15742 | 15788 | } |
| 15743 | 15789 | |
| 15744 | 15790 | if (type_entry->id != ZigTypeIdOptional) { |
| 15745 | | ir_add_error(ira, &base_ptr->base, |
| 15791 | ir_add_error(ira, base_ptr, |
| 15746 | 15792 | buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name))); |
| 15747 | 15793 | return ira->codegen->invalid_inst_gen; |
| 15748 | 15794 | } |
| ... | ... | @@ -15759,7 +15805,7 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou |
| 15759 | 15805 | if (ptr_val == nullptr) |
| 15760 | 15806 | return ira->codegen->invalid_inst_gen; |
| 15761 | 15807 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 15762 | | ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 15808 | ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node); |
| 15763 | 15809 | if (optional_val == nullptr) |
| 15764 | 15810 | return ira->codegen->invalid_inst_gen; |
| 15765 | 15811 | |
| ... | ... | @@ -15787,21 +15833,21 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou |
| 15787 | 15833 | } |
| 15788 | 15834 | } else { |
| 15789 | 15835 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| 15790 | | source_instr->source_node, optional_val, UndefBad))) |
| 15836 | source_node, optional_val, UndefBad))) |
| 15791 | 15837 | return ira->codegen->invalid_inst_gen; |
| 15792 | 15838 | if (optional_value_is_null(optional_val)) { |
| 15793 | | ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null")); |
| 15839 | ir_add_error_node(ira, source_node, buf_sprintf("unable to unwrap null")); |
| 15794 | 15840 | return ira->codegen->invalid_inst_gen; |
| 15795 | 15841 | } |
| 15796 | 15842 | } |
| 15797 | 15843 | |
| 15798 | 15844 | IrInstGen *result; |
| 15799 | 15845 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 15800 | | result = ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, false, |
| 15846 | result = ir_build_optional_unwrap_ptr_gen(ira, scope, source_node, base_ptr, false, |
| 15801 | 15847 | initializing, result_type); |
| 15802 | 15848 | result->value->special = ConstValSpecialStatic; |
| 15803 | 15849 | } else { |
| 15804 | | result = ir_const(ira, source_instr, result_type); |
| 15850 | result = ir_const(ira, scope, source_node, result_type); |
| 15805 | 15851 | } |
| 15806 | 15852 | ZigValue *result_val = result->value; |
| 15807 | 15853 | result_val->data.x_ptr.special = ConstPtrSpecialRef; |
| ... | ... | @@ -15826,7 +15872,7 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou |
| 15826 | 15872 | } |
| 15827 | 15873 | } |
| 15828 | 15874 | |
| 15829 | | return ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, safety_check_on, |
| 15875 | return ir_build_optional_unwrap_ptr_gen(ira, scope, source_node, base_ptr, safety_check_on, |
| 15830 | 15876 | initializing, result_type); |
| 15831 | 15877 | } |
| 15832 | 15878 | |
| ... | ... | @@ -15837,7 +15883,7 @@ static IrInstGen *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira, |
| 15837 | 15883 | if (type_is_invalid(base_ptr->value->type)) |
| 15838 | 15884 | return ira->codegen->invalid_inst_gen; |
| 15839 | 15885 | |
| 15840 | | return ir_analyze_unwrap_optional_payload(ira, &instruction->base.base, base_ptr, |
| 15886 | return ir_analyze_unwrap_optional_payload(ira, instruction->base.scope, instruction->base.source_node, base_ptr, |
| 15841 | 15887 | instruction->safety_check_on, false); |
| 15842 | 15888 | } |
| 15843 | 15889 | |
| ... | ... | @@ -15851,20 +15897,20 @@ static IrInstGen *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstSrcCtz *instr |
| 15851 | 15897 | return ira->codegen->invalid_inst_gen; |
| 15852 | 15898 | |
| 15853 | 15899 | if (int_type->data.integral.bit_count == 0) |
| 15854 | | return ir_const_unsigned(ira, &instruction->base.base, 0); |
| 15900 | return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, 0); |
| 15855 | 15901 | |
| 15856 | 15902 | if (instr_is_comptime(op)) { |
| 15857 | 15903 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 15858 | 15904 | if (val == nullptr) |
| 15859 | 15905 | return ira->codegen->invalid_inst_gen; |
| 15860 | 15906 | if (val->special == ConstValSpecialUndef) |
| 15861 | | return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 15907 | return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int); |
| 15862 | 15908 | size_t result_usize = bigint_ctz(&op->value->data.x_bigint, int_type->data.integral.bit_count); |
| 15863 | | return ir_const_unsigned(ira, &instruction->base.base, result_usize); |
| 15909 | return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, result_usize); |
| 15864 | 15910 | } |
| 15865 | 15911 | |
| 15866 | 15912 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); |
| 15867 | | return ir_build_ctz_gen(ira, &instruction->base.base, return_type, op); |
| 15913 | return ir_build_ctz_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, op); |
| 15868 | 15914 | } |
| 15869 | 15915 | |
| 15870 | 15916 | static IrInstGen *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstSrcClz *instruction) { |
| ... | ... | @@ -15877,20 +15923,20 @@ static IrInstGen *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstSrcClz *instr |
| 15877 | 15923 | return ira->codegen->invalid_inst_gen; |
| 15878 | 15924 | |
| 15879 | 15925 | if (int_type->data.integral.bit_count == 0) |
| 15880 | | return ir_const_unsigned(ira, &instruction->base.base, 0); |
| 15926 | return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, 0); |
| 15881 | 15927 | |
| 15882 | 15928 | if (instr_is_comptime(op)) { |
| 15883 | 15929 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 15884 | 15930 | if (val == nullptr) |
| 15885 | 15931 | return ira->codegen->invalid_inst_gen; |
| 15886 | 15932 | if (val->special == ConstValSpecialUndef) |
| 15887 | | return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 15933 | return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int); |
| 15888 | 15934 | size_t result_usize = bigint_clz(&op->value->data.x_bigint, int_type->data.integral.bit_count); |
| 15889 | | return ir_const_unsigned(ira, &instruction->base.base, result_usize); |
| 15935 | return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, result_usize); |
| 15890 | 15936 | } |
| 15891 | 15937 | |
| 15892 | 15938 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); |
| 15893 | | return ir_build_clz_gen(ira, &instruction->base.base, return_type, op); |
| 15939 | return ir_build_clz_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, op); |
| 15894 | 15940 | } |
| 15895 | 15941 | |
| 15896 | 15942 | static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopCount *instruction) { |
| ... | ... | @@ -15903,38 +15949,38 @@ static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopC |
| 15903 | 15949 | return ira->codegen->invalid_inst_gen; |
| 15904 | 15950 | |
| 15905 | 15951 | if (int_type->data.integral.bit_count == 0) |
| 15906 | | return ir_const_unsigned(ira, &instruction->base.base, 0); |
| 15952 | return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, 0); |
| 15907 | 15953 | |
| 15908 | 15954 | if (instr_is_comptime(op)) { |
| 15909 | 15955 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 15910 | 15956 | if (val == nullptr) |
| 15911 | 15957 | return ira->codegen->invalid_inst_gen; |
| 15912 | 15958 | if (val->special == ConstValSpecialUndef) |
| 15913 | | return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 15959 | return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int); |
| 15914 | 15960 | |
| 15915 | 15961 | if (bigint_cmp_zero(&val->data.x_bigint) != CmpLT) { |
| 15916 | 15962 | size_t result = bigint_popcount_unsigned(&val->data.x_bigint); |
| 15917 | | return ir_const_unsigned(ira, &instruction->base.base, result); |
| 15963 | return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, result); |
| 15918 | 15964 | } |
| 15919 | 15965 | size_t result = bigint_popcount_signed(&val->data.x_bigint, int_type->data.integral.bit_count); |
| 15920 | | return ir_const_unsigned(ira, &instruction->base.base, result); |
| 15966 | return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, result); |
| 15921 | 15967 | } |
| 15922 | 15968 | |
| 15923 | 15969 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); |
| 15924 | | return ir_build_pop_count_gen(ira, &instruction->base.base, return_type, op); |
| 15970 | return ir_build_pop_count_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, op); |
| 15925 | 15971 | } |
| 15926 | 15972 | |
| 15927 | | static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value) { |
| 15973 | static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value) { |
| 15928 | 15974 | if (type_is_invalid(value->value->type)) |
| 15929 | 15975 | return ira->codegen->invalid_inst_gen; |
| 15930 | 15976 | |
| 15931 | 15977 | if (value->value->type->id != ZigTypeIdUnion) { |
| 15932 | | ir_add_error(ira, &value->base, |
| 15978 | ir_add_error(ira, value, |
| 15933 | 15979 | buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name))); |
| 15934 | 15980 | return ira->codegen->invalid_inst_gen; |
| 15935 | 15981 | } |
| 15936 | 15982 | if (!value->value->type->data.unionation.have_explicit_tag_type) { |
| 15937 | | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum")); |
| 15983 | ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("union has no associated enum")); |
| 15938 | 15984 | if (value->value->type->data.unionation.decl_node != nullptr) { |
| 15939 | 15985 | add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node, |
| 15940 | 15986 | buf_sprintf("declared here")); |
| ... | ... | @@ -15951,14 +15997,14 @@ static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrI |
| 15951 | 15997 | return ira->codegen->invalid_inst_gen; |
| 15952 | 15998 | |
| 15953 | 15999 | IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb, |
| 15954 | | source_instr->scope, source_instr->source_node); |
| 16000 | scope, source_node); |
| 15955 | 16001 | const_instruction->base.value->type = tag_type; |
| 15956 | 16002 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 15957 | 16003 | bigint_init_bigint(&const_instruction->base.value->data.x_enum_tag, &val->data.x_union.tag); |
| 15958 | 16004 | return &const_instruction->base; |
| 15959 | 16005 | } |
| 15960 | 16006 | |
| 15961 | | return ir_build_union_tag(ira, source_instr, value, tag_type); |
| 16007 | return ir_build_union_tag(ira, scope, source_node, value, tag_type); |
| 15962 | 16008 | } |
| 15963 | 16009 | |
| 15964 | 16010 | static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| ... | ... | @@ -16008,10 +16054,11 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 16008 | 16054 | } |
| 16009 | 16055 | |
| 16010 | 16056 | if (is_comptime || old_dest_block->ref_count == 1) { |
| 16011 | | return ir_inline_bb(ira, &switch_br_instruction->base.base, old_dest_block); |
| 16057 | return ir_inline_bb(ira, switch_br_instruction->base.source_node, old_dest_block); |
| 16012 | 16058 | } else { |
| 16013 | | IrBasicBlockGen *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base.base); |
| 16014 | | IrInstGen *result = ir_build_br_gen(ira, &switch_br_instruction->base.base, new_dest_block); |
| 16059 | IrBasicBlockGen *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base); |
| 16060 | IrInstGen *result = ir_build_br_gen(ira, switch_br_instruction->base.scope, |
| 16061 | switch_br_instruction->base.source_node, new_dest_block); |
| 16015 | 16062 | return ir_finish_anal(ira, result); |
| 16016 | 16063 | } |
| 16017 | 16064 | } |
| ... | ... | @@ -16020,7 +16067,7 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 16020 | 16067 | for (size_t i = 0; i < case_count; i += 1) { |
| 16021 | 16068 | IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i]; |
| 16022 | 16069 | IrInstGenSwitchBrCase *new_case = &cases[i]; |
| 16023 | | new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base.base); |
| 16070 | new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base); |
| 16024 | 16071 | new_case->value = ira->codegen->invalid_inst_gen; |
| 16025 | 16072 | |
| 16026 | 16073 | // Calling ir_get_new_bb set the ref_instruction on the new basic block. |
| ... | ... | @@ -16048,12 +16095,12 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 16048 | 16095 | IrInstGenSwitchBrCase *new_case = &cases[i]; |
| 16049 | 16096 | if (type_is_invalid(new_case->value->value->type)) |
| 16050 | 16097 | return ir_unreach_error(ira); |
| 16051 | | new_case->block->ref_instruction = &switch_br_instruction->base.base; |
| 16098 | new_case->block->ref_instruction = &switch_br_instruction->base; |
| 16052 | 16099 | } |
| 16053 | 16100 | |
| 16054 | | IrBasicBlockGen *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base.base); |
| 16055 | | IrInstGenSwitchBr *switch_br = ir_build_switch_br_gen(ira, &switch_br_instruction->base.base, |
| 16056 | | target_value, new_else_block, case_count, cases); |
| 16101 | IrBasicBlockGen *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base); |
| 16102 | IrInstGenSwitchBr *switch_br = ir_build_switch_br_gen(ira, switch_br_instruction->base.scope, |
| 16103 | switch_br_instruction->base.source_node, target_value, new_else_block, case_count, cases); |
| 16057 | 16104 | return ir_finish_anal(ira, &switch_br->base); |
| 16058 | 16105 | } |
| 16059 | 16106 | |
| ... | ... | @@ -16069,13 +16116,14 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16069 | 16116 | assert(instr_is_comptime(target_value_ptr)); |
| 16070 | 16117 | ZigType *ptr_type = target_value_ptr->value->data.x_type; |
| 16071 | 16118 | assert(ptr_type->id == ZigTypeIdPointer); |
| 16072 | | return ir_const_type(ira, &switch_target_instruction->base.base, ptr_type->data.pointer.child_type); |
| 16119 | return ir_const_type(ira, switch_target_instruction->base.scope, |
| 16120 | switch_target_instruction->base.source_node, ptr_type->data.pointer.child_type); |
| 16073 | 16121 | } |
| 16074 | 16122 | |
| 16075 | 16123 | ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; |
| 16076 | 16124 | ZigValue *pointee_val = nullptr; |
| 16077 | 16125 | if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 16078 | | pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->base.source_node); |
| 16126 | pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->source_node); |
| 16079 | 16127 | if (pointee_val == nullptr) |
| 16080 | 16128 | return ira->codegen->invalid_inst_gen; |
| 16081 | 16129 | |
| ... | ... | @@ -16100,13 +16148,15 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16100 | 16148 | case ZigTypeIdFn: |
| 16101 | 16149 | case ZigTypeIdErrorSet: { |
| 16102 | 16150 | if (pointee_val) { |
| 16103 | | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, nullptr); |
| 16151 | IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope, |
| 16152 | switch_target_instruction->base.source_node, nullptr); |
| 16104 | 16153 | copy_const_val(ira->codegen, result->value, pointee_val); |
| 16105 | 16154 | result->value->type = target_type; |
| 16106 | 16155 | return result; |
| 16107 | 16156 | } |
| 16108 | 16157 | |
| 16109 | | IrInstGen *result = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr); |
| 16158 | IrInstGen *result = ir_get_deref(ira, switch_target_instruction->base.scope, |
| 16159 | switch_target_instruction->base.source_node, target_value_ptr, nullptr); |
| 16110 | 16160 | result->value->type = target_type; |
| 16111 | 16161 | return result; |
| 16112 | 16162 | } |
| ... | ... | @@ -16115,7 +16165,7 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16115 | 16165 | if (!decl_node->data.container_decl.auto_enum && |
| 16116 | 16166 | decl_node->data.container_decl.init_arg_expr == nullptr) |
| 16117 | 16167 | { |
| 16118 | | ErrorMsg *msg = ir_add_error(ira, &target_value_ptr->base, |
| 16168 | ErrorMsg *msg = ir_add_error(ira, target_value_ptr, |
| 16119 | 16169 | buf_sprintf("switch on union which has no attached enum")); |
| 16120 | 16170 | add_error_note(ira->codegen, msg, decl_node, |
| 16121 | 16171 | buf_sprintf("consider 'union(enum)' here")); |
| ... | ... | @@ -16125,22 +16175,23 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16125 | 16175 | assert(tag_type != nullptr); |
| 16126 | 16176 | assert(tag_type->id == ZigTypeIdEnum); |
| 16127 | 16177 | if (pointee_val) { |
| 16128 | | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type); |
| 16178 | IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, tag_type); |
| 16129 | 16179 | bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag); |
| 16130 | 16180 | return result; |
| 16131 | 16181 | } |
| 16132 | 16182 | |
| 16133 | 16183 | if (can_fold_enum_type(tag_type)) { |
| 16134 | | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type); |
| 16184 | IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, tag_type); |
| 16135 | 16185 | TypeEnumField *only_field = &tag_type->data.enumeration.fields[0]; |
| 16136 | 16186 | bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); |
| 16137 | 16187 | return result; |
| 16138 | 16188 | } |
| 16139 | 16189 | |
| 16140 | | IrInstGen *union_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr); |
| 16190 | IrInstGen *union_value = ir_get_deref(ira, switch_target_instruction->base.scope, |
| 16191 | switch_target_instruction->base.source_node, target_value_ptr, nullptr); |
| 16141 | 16192 | union_value->value->type = target_type; |
| 16142 | 16193 | |
| 16143 | | return ir_build_union_tag(ira, &switch_target_instruction->base.base, union_value, tag_type); |
| 16194 | return ir_build_union_tag(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, union_value, tag_type); |
| 16144 | 16195 | } |
| 16145 | 16196 | case ZigTypeIdEnum: { |
| 16146 | 16197 | if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown))) |
| ... | ... | @@ -16148,18 +16199,19 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16148 | 16199 | |
| 16149 | 16200 | if (can_fold_enum_type(target_type)) { |
| 16150 | 16201 | TypeEnumField *only_field = &target_type->data.enumeration.fields[0]; |
| 16151 | | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type); |
| 16202 | IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, target_type); |
| 16152 | 16203 | bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); |
| 16153 | 16204 | return result; |
| 16154 | 16205 | } |
| 16155 | 16206 | |
| 16156 | 16207 | if (pointee_val) { |
| 16157 | | IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type); |
| 16208 | IrInstGen *result = ir_const(ira, switch_target_instruction->base.scope, switch_target_instruction->base.source_node, target_type); |
| 16158 | 16209 | bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag); |
| 16159 | 16210 | return result; |
| 16160 | 16211 | } |
| 16161 | 16212 | |
| 16162 | | IrInstGen *enum_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr); |
| 16213 | IrInstGen *enum_value = ir_get_deref(ira, switch_target_instruction->base.scope, |
| 16214 | switch_target_instruction->base.source_node, target_value_ptr, nullptr); |
| 16163 | 16215 | enum_value->value->type = target_type; |
| 16164 | 16216 | return enum_value; |
| 16165 | 16217 | } |
| ... | ... | @@ -16175,7 +16227,7 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16175 | 16227 | case ZigTypeIdVector: |
| 16176 | 16228 | case ZigTypeIdFnFrame: |
| 16177 | 16229 | case ZigTypeIdAnyFrame: |
| 16178 | | ir_add_error(ira, &switch_target_instruction->base.base, |
| 16230 | ir_add_error_node(ira, switch_target_instruction->base.source_node, |
| 16179 | 16231 | buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name))); |
| 16180 | 16232 | return ira->codegen->invalid_inst_gen; |
| 16181 | 16233 | } |
| ... | ... | @@ -16228,12 +16280,12 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi |
| 16228 | 16280 | ZigType *payload_type = payload_field->type_entry; |
| 16229 | 16281 | if (first_field->type_entry != payload_type) { |
| 16230 | 16282 | if (invalid_payload_msg == nullptr) { |
| 16231 | | invalid_payload_msg = ir_add_error(ira, &instruction->base.base, |
| 16283 | invalid_payload_msg = ir_add_error_node(ira, instruction->base.source_node, |
| 16232 | 16284 | buf_sprintf("capture group with incompatible types")); |
| 16233 | | add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->base.source_node, |
| 16285 | add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->source_node, |
| 16234 | 16286 | buf_sprintf("type '%s' here", buf_ptr(&first_field->type_entry->name))); |
| 16235 | 16287 | } |
| 16236 | | add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->base.source_node, |
| 16288 | add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->source_node, |
| 16237 | 16289 | buf_sprintf("type '%s' here", buf_ptr(&payload_field->type_entry->name))); |
| 16238 | 16290 | } |
| 16239 | 16291 | } |
| ... | ... | @@ -16247,11 +16299,11 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi |
| 16247 | 16299 | if (!target_value_ptr) |
| 16248 | 16300 | return ira->codegen->invalid_inst_gen; |
| 16249 | 16301 | |
| 16250 | | ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.base.source_node); |
| 16302 | ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node); |
| 16251 | 16303 | if (pointee_val == nullptr) |
| 16252 | 16304 | return ira->codegen->invalid_inst_gen; |
| 16253 | 16305 | |
| 16254 | | IrInstGen *result = ir_const(ira, &instruction->base.base, |
| 16306 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, |
| 16255 | 16307 | get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 16256 | 16308 | target_val_ptr->type->data.pointer.is_const)); |
| 16257 | 16309 | ZigValue *out_val = result->value; |
| ... | ... | @@ -16263,7 +16315,7 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi |
| 16263 | 16315 | |
| 16264 | 16316 | ZigType *result_type = get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 16265 | 16317 | target_value_ptr->value->type->data.pointer.is_const); |
| 16266 | | return ir_build_union_field_ptr(ira, &instruction->base.base, target_value_ptr, first_field, |
| 16318 | return ir_build_union_field_ptr(ira, instruction->base.scope, instruction->base.source_node, target_value_ptr, first_field, |
| 16267 | 16319 | false, false, result_type); |
| 16268 | 16320 | } else if (target_type->id == ZigTypeIdErrorSet) { |
| 16269 | 16321 | // construct an error set from the prong values |
| ... | ... | @@ -16293,12 +16345,13 @@ static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwi |
| 16293 | 16345 | ref_type->data.pointer.explicit_alignment, |
| 16294 | 16346 | ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes, |
| 16295 | 16347 | ref_type->data.pointer.allow_zero); |
| 16296 | | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, |
| 16297 | | &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false, false); |
| 16348 | return ir_analyze_ptr_cast(ira, instruction->base.scope, instruction->base.source_node, |
| 16349 | target_value_ptr, instruction->target_value_ptr->source_node, |
| 16350 | new_target_value_ptr_type, instruction->base.source_node, false, false); |
| 16298 | 16351 | } else if (instruction->prongs_len > 1) { |
| 16299 | 16352 | return target_value_ptr; |
| 16300 | 16353 | } else { |
| 16301 | | ir_add_error(ira, &instruction->base.base, |
| 16354 | ir_add_error_node(ira, instruction->base.source_node, |
| 16302 | 16355 | buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name))); |
| 16303 | 16356 | return ira->codegen->invalid_inst_gen; |
| 16304 | 16357 | } |
| ... | ... | @@ -16316,7 +16369,7 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 16316 | 16369 | ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; |
| 16317 | 16370 | if (target_type->id == ZigTypeIdErrorSet) { |
| 16318 | 16371 | // make a new set that has the other cases removed |
| 16319 | | if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.base.source_node)) { |
| 16372 | if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.source_node)) { |
| 16320 | 16373 | return ira->codegen->invalid_inst_gen; |
| 16321 | 16374 | } |
| 16322 | 16375 | if (type_is_global_error_set(target_type)) { |
| ... | ... | @@ -16378,8 +16431,9 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 16378 | 16431 | ref_type->data.pointer.explicit_alignment, |
| 16379 | 16432 | ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes, |
| 16380 | 16433 | ref_type->data.pointer.allow_zero); |
| 16381 | | return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr, |
| 16382 | | &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false, false); |
| 16434 | return ir_analyze_ptr_cast(ira, instruction->base.scope, instruction->base.source_node, |
| 16435 | target_value_ptr, instruction->target_value_ptr->source_node, |
| 16436 | new_target_value_ptr_type, instruction->base.source_node, false, false); |
| 16383 | 16437 | } |
| 16384 | 16438 | |
| 16385 | 16439 | return target_value_ptr; |
| ... | ... | @@ -16393,7 +16447,7 @@ static IrInstGen *ir_analyze_instruction_import(IrAnalyze *ira, IrInstSrcImport |
| 16393 | 16447 | if (!import_target_str) |
| 16394 | 16448 | return ira->codegen->invalid_inst_gen; |
| 16395 | 16449 | |
| 16396 | | AstNode *source_node = import_instruction->base.base.source_node; |
| 16450 | AstNode *source_node = import_instruction->base.source_node; |
| 16397 | 16451 | ZigType *import = source_node->owner; |
| 16398 | 16452 | |
| 16399 | 16453 | ZigType *target_import; |
| ... | ... | @@ -16418,7 +16472,7 @@ static IrInstGen *ir_analyze_instruction_import(IrAnalyze *ira, IrInstSrcImport |
| 16418 | 16472 | } |
| 16419 | 16473 | } |
| 16420 | 16474 | |
| 16421 | | return ir_const_type(ira, &import_instruction->base.base, target_import); |
| 16475 | return ir_const_type(ira, import_instruction->base.scope, import_instruction->base.source_node, target_import); |
| 16422 | 16476 | } |
| 16423 | 16477 | |
| 16424 | 16478 | static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_instruction) { |
| ... | ... | @@ -16434,10 +16488,10 @@ static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_i |
| 16434 | 16488 | is_const = true; |
| 16435 | 16489 | } |
| 16436 | 16490 | |
| 16437 | | return ir_get_ref(ira, &ref_instruction->base.base, value, is_const, is_volatile); |
| 16491 | return ir_get_ref(ira, ref_instruction->base.scope, ref_instruction->base.source_node, value, is_const, is_volatile); |
| 16438 | 16492 | } |
| 16439 | 16493 | |
| 16440 | | static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instruction, |
| 16494 | static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 16441 | 16495 | AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstGen *field_result_loc, |
| 16442 | 16496 | IrInstGen *result_loc) |
| 16443 | 16497 | { |
| ... | ... | @@ -16468,26 +16522,26 @@ static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instructi |
| 16468 | 16522 | } |
| 16469 | 16523 | } |
| 16470 | 16524 | |
| 16471 | | bool is_comptime = ir_should_inline(ira->zir, source_instruction->scope) |
| 16525 | bool is_comptime = ir_should_inline(ira->zir, scope) |
| 16472 | 16526 | || type_requires_comptime(ira->codegen, union_type) == ReqCompTimeYes; |
| 16473 | 16527 | |
| 16474 | | IrInstGen *result = ir_get_deref(ira, source_instruction, result_loc, nullptr); |
| 16528 | IrInstGen *result = ir_get_deref(ira, scope, source_node, result_loc, nullptr); |
| 16475 | 16529 | if (is_comptime && !instr_is_comptime(result)) { |
| 16476 | | ir_add_error(ira, &field_result_loc->base, |
| 16530 | ir_add_error(ira, field_result_loc, |
| 16477 | 16531 | buf_sprintf("unable to evaluate constant expression")); |
| 16478 | 16532 | return ira->codegen->invalid_inst_gen; |
| 16479 | 16533 | } |
| 16480 | 16534 | return result; |
| 16481 | 16535 | } |
| 16482 | 16536 | |
| 16483 | | static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *source_instr, |
| 16537 | static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 16484 | 16538 | ZigType *container_type, size_t instr_field_count, IrInstSrcContainerInitFieldsField *fields, |
| 16485 | 16539 | IrInstGen *result_loc) |
| 16486 | 16540 | { |
| 16487 | 16541 | Error err; |
| 16488 | 16542 | if (container_type->id == ZigTypeIdUnion) { |
| 16489 | 16543 | if (instr_field_count != 1) { |
| 16490 | | ir_add_error(ira, source_instr, |
| 16544 | ir_add_error_node(ira, source_node, |
| 16491 | 16545 | buf_sprintf("union initialization expects exactly one field")); |
| 16492 | 16546 | return ira->codegen->invalid_inst_gen; |
| 16493 | 16547 | } |
| ... | ... | @@ -16496,11 +16550,11 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc |
| 16496 | 16550 | if (type_is_invalid(field_result_loc->value->type)) |
| 16497 | 16551 | return ira->codegen->invalid_inst_gen; |
| 16498 | 16552 | |
| 16499 | | return ir_analyze_union_init(ira, source_instr, field->source_node, container_type, field->name, |
| 16553 | return ir_analyze_union_init(ira, scope, source_node, field->source_node, container_type, field->name, |
| 16500 | 16554 | field_result_loc, result_loc); |
| 16501 | 16555 | } |
| 16502 | 16556 | if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) { |
| 16503 | | ir_add_error(ira, source_instr, |
| 16557 | ir_add_error_node(ira, source_node, |
| 16504 | 16558 | buf_sprintf("type '%s' does not support struct initialization syntax", |
| 16505 | 16559 | buf_ptr(&container_type->name))); |
| 16506 | 16560 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -16521,7 +16575,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc |
| 16521 | 16575 | AstNode **field_assign_nodes = heap::c_allocator.allocate<AstNode *>(actual_field_count); |
| 16522 | 16576 | ZigList<IrInstGen *> const_ptrs = {}; |
| 16523 | 16577 | |
| 16524 | | bool is_comptime = ir_should_inline(ira->zir, source_instr->scope) |
| 16578 | bool is_comptime = ir_should_inline(ira->zir, scope) |
| 16525 | 16579 | || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes; |
| 16526 | 16580 | |
| 16527 | 16581 | |
| ... | ... | @@ -16580,7 +16634,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc |
| 16580 | 16634 | TypeStructField *field = container_type->data.structure.fields[i]; |
| 16581 | 16635 | memoize_field_init_val(ira->codegen, container_type, field); |
| 16582 | 16636 | if (field->init_val == nullptr) { |
| 16583 | | ir_add_error(ira, source_instr, |
| 16637 | ir_add_error_node(ira, source_node, |
| 16584 | 16638 | buf_sprintf("missing field: '%s'", buf_ptr(field->name))); |
| 16585 | 16639 | any_missing = true; |
| 16586 | 16640 | continue; |
| ... | ... | @@ -16588,12 +16642,12 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc |
| 16588 | 16642 | if (type_is_invalid(field->init_val->type)) |
| 16589 | 16643 | return ira->codegen->invalid_inst_gen; |
| 16590 | 16644 | |
| 16591 | | IrInstGen *runtime_inst = ir_const(ira, source_instr, field->init_val->type); |
| 16645 | IrInstGen *runtime_inst = ir_const(ira, scope, source_node, field->init_val->type); |
| 16592 | 16646 | copy_const_val(ira->codegen, runtime_inst->value, field->init_val); |
| 16593 | 16647 | |
| 16594 | | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc, |
| 16648 | IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, field, result_loc, |
| 16595 | 16649 | container_type, true); |
| 16596 | | ir_analyze_store_ptr(ira, source_instr, field_ptr, runtime_inst, false); |
| 16650 | ir_analyze_store_ptr(ira, scope, source_node, field_ptr, runtime_inst, false); |
| 16597 | 16651 | if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 16598 | 16652 | const_ptrs.append(field_ptr); |
| 16599 | 16653 | } else { |
| ... | ... | @@ -16609,18 +16663,20 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc |
| 16609 | 16663 | result_loc->value->special = ConstValSpecialRuntime; |
| 16610 | 16664 | for (size_t i = 0; i < const_ptrs.length; i += 1) { |
| 16611 | 16665 | IrInstGen *field_result_loc = const_ptrs.at(i); |
| 16612 | | IrInstGen *deref = ir_get_deref(ira, &field_result_loc->base, field_result_loc, nullptr); |
| 16666 | IrInstGen *deref = ir_get_deref(ira, field_result_loc->scope, |
| 16667 | field_result_loc->source_node, field_result_loc, nullptr); |
| 16613 | 16668 | field_result_loc->value->special = ConstValSpecialRuntime; |
| 16614 | | ir_analyze_store_ptr(ira, &field_result_loc->base, field_result_loc, deref, false); |
| 16669 | ir_analyze_store_ptr(ira, field_result_loc->scope, field_result_loc->source_node, |
| 16670 | field_result_loc, deref, false); |
| 16615 | 16671 | } |
| 16616 | 16672 | } |
| 16617 | 16673 | } |
| 16618 | 16674 | |
| 16619 | 16675 | const_ptrs.deinit(); |
| 16620 | | IrInstGen *result = ir_get_deref(ira, source_instr, result_loc, nullptr); |
| 16676 | IrInstGen *result = ir_get_deref(ira, scope, source_node, result_loc, nullptr); |
| 16621 | 16677 | |
| 16622 | 16678 | if (is_comptime && !instr_is_comptime(result)) { |
| 16623 | | ir_add_error_node(ira, first_non_const_instruction->base.source_node, |
| 16679 | ir_add_error_node(ira, first_non_const_instruction->source_node, |
| 16624 | 16680 | buf_sprintf("unable to evaluate constant expression")); |
| 16625 | 16681 | return ira->codegen->invalid_inst_gen; |
| 16626 | 16682 | } |
| ... | ... | @@ -16631,14 +16687,14 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc |
| 16631 | 16687 | static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16632 | 16688 | IrInstSrcContainerInitList *instruction) |
| 16633 | 16689 | { |
| 16634 | | ir_assert(instruction->result_loc != nullptr, &instruction->base.base); |
| 16690 | src_assert(instruction->result_loc != nullptr, instruction->base.source_node); |
| 16635 | 16691 | IrInstGen *result_loc = instruction->result_loc->child; |
| 16636 | 16692 | if (type_is_invalid(result_loc->value->type)) |
| 16637 | 16693 | return result_loc; |
| 16638 | 16694 | |
| 16639 | | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base); |
| 16695 | src_assert(result_loc->value->type->id == ZigTypeIdPointer, instruction->base.source_node); |
| 16640 | 16696 | if (result_loc->value->type->data.pointer.is_const) { |
| 16641 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("cannot assign to constant")); |
| 16697 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("cannot assign to constant")); |
| 16642 | 16698 | return ira->codegen->invalid_inst_gen; |
| 16643 | 16699 | } |
| 16644 | 16700 | |
| ... | ... | @@ -16654,19 +16710,19 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16654 | 16710 | |
| 16655 | 16711 | if (container_type->id == ZigTypeIdVoid) { |
| 16656 | 16712 | if (elem_count != 0) { |
| 16657 | | ir_add_error_node(ira, instruction->base.base.source_node, |
| 16713 | ir_add_error_node(ira, instruction->base.source_node, |
| 16658 | 16714 | buf_sprintf("void expression expects no arguments")); |
| 16659 | 16715 | return ira->codegen->invalid_inst_gen; |
| 16660 | 16716 | } |
| 16661 | | return ir_const_void(ira, &instruction->base.base); |
| 16717 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 16662 | 16718 | } |
| 16663 | 16719 | |
| 16664 | 16720 | if (container_type->id == ZigTypeIdStruct && elem_count == 0) { |
| 16665 | | ir_assert(instruction->result_loc != nullptr, &instruction->base.base); |
| 16721 | src_assert(instruction->result_loc != nullptr, instruction->base.source_node); |
| 16666 | 16722 | IrInstGen *result_loc = instruction->result_loc->child; |
| 16667 | 16723 | if (type_is_invalid(result_loc->value->type)) |
| 16668 | 16724 | return result_loc; |
| 16669 | | return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type, 0, nullptr, result_loc); |
| 16725 | return ir_analyze_container_init_fields(ira, instruction->base.scope, instruction->base.source_node, container_type, 0, nullptr, result_loc); |
| 16670 | 16726 | } |
| 16671 | 16727 | |
| 16672 | 16728 | if (container_type->id == ZigTypeIdArray) { |
| ... | ... | @@ -16674,7 +16730,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16674 | 16730 | if (container_type->data.array.len != elem_count) { |
| 16675 | 16731 | ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count, nullptr); |
| 16676 | 16732 | |
| 16677 | | ir_add_error(ira, &instruction->base.base, |
| 16733 | ir_add_error_node(ira, instruction->base.source_node, |
| 16678 | 16734 | buf_sprintf("expected %s literal, found %s literal", |
| 16679 | 16735 | buf_ptr(&container_type->name), buf_ptr(&literal_type->name))); |
| 16680 | 16736 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -16687,7 +16743,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16687 | 16743 | } else if (container_type->id == ZigTypeIdVector || is_tuple(container_type)) { |
| 16688 | 16744 | // OK |
| 16689 | 16745 | } else { |
| 16690 | | ir_add_error(ira, &instruction->base.base, |
| 16746 | ir_add_error_node(ira, instruction->base.source_node, |
| 16691 | 16747 | buf_sprintf("type '%s' does not support array initialization", |
| 16692 | 16748 | buf_ptr(&container_type->name))); |
| 16693 | 16749 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -16697,7 +16753,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16697 | 16753 | case OnePossibleValueInvalid: |
| 16698 | 16754 | return ira->codegen->invalid_inst_gen; |
| 16699 | 16755 | case OnePossibleValueYes: |
| 16700 | | return ir_const_move(ira, &instruction->base.base, |
| 16756 | return ir_const_move(ira, instruction->base.scope, instruction->base.source_node, |
| 16701 | 16757 | get_the_one_possible_value(ira->codegen, container_type)); |
| 16702 | 16758 | case OnePossibleValueNo: |
| 16703 | 16759 | break; |
| ... | ... | @@ -16708,7 +16764,7 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16708 | 16764 | case ReqCompTimeInvalid: |
| 16709 | 16765 | return ira->codegen->invalid_inst_gen; |
| 16710 | 16766 | case ReqCompTimeNo: |
| 16711 | | is_comptime = ir_should_inline(ira->zir, instruction->base.base.scope); |
| 16767 | is_comptime = ir_should_inline(ira->zir, instruction->base.scope); |
| 16712 | 16768 | break; |
| 16713 | 16769 | case ReqCompTimeYes: |
| 16714 | 16770 | is_comptime = true; |
| ... | ... | @@ -16752,32 +16808,35 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16752 | 16808 | // This field will be generated comptime; no need to do this. |
| 16753 | 16809 | continue; |
| 16754 | 16810 | } |
| 16755 | | IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr); |
| 16811 | IrInstGen *deref = ir_get_deref(ira, elem_result_loc->scope, |
| 16812 | elem_result_loc->source_node, elem_result_loc, nullptr); |
| 16756 | 16813 | elem_result_loc->value->special = ConstValSpecialRuntime; |
| 16757 | | ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, false); |
| 16814 | ir_analyze_store_ptr(ira, elem_result_loc->scope, elem_result_loc->source_node, |
| 16815 | elem_result_loc, deref, false); |
| 16758 | 16816 | } |
| 16759 | 16817 | } |
| 16760 | 16818 | } |
| 16761 | 16819 | |
| 16762 | 16820 | const_ptrs.deinit(); |
| 16763 | 16821 | |
| 16764 | | IrInstGen *result = ir_get_deref(ira, &instruction->base.base, result_loc, nullptr); |
| 16822 | IrInstGen *result = ir_get_deref(ira, instruction->base.scope, instruction->base.source_node, |
| 16823 | result_loc, nullptr); |
| 16765 | 16824 | // If the result is a tuple, we are allowed to return a struct that uses ConstValSpecialRuntime fields at comptime. |
| 16766 | 16825 | if (instr_is_comptime(result) || is_tuple(container_type)) |
| 16767 | 16826 | return result; |
| 16768 | 16827 | |
| 16769 | 16828 | if (is_comptime) { |
| 16770 | | ir_add_error(ira, &first_non_const_instruction->base, |
| 16829 | ir_add_error(ira, first_non_const_instruction, |
| 16771 | 16830 | buf_sprintf("unable to evaluate constant expression")); |
| 16772 | 16831 | return ira->codegen->invalid_inst_gen; |
| 16773 | 16832 | } |
| 16774 | 16833 | |
| 16775 | 16834 | ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type; |
| 16776 | 16835 | if (is_slice(result_elem_type)) { |
| 16777 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 16836 | ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node, |
| 16778 | 16837 | buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'", |
| 16779 | 16838 | buf_ptr(&result_elem_type->name))); |
| 16780 | | add_error_note(ira->codegen, msg, first_non_const_instruction->base.source_node, |
| 16839 | add_error_note(ira->codegen, msg, first_non_const_instruction->source_node, |
| 16781 | 16840 | buf_sprintf("this value is not comptime-known")); |
| 16782 | 16841 | return ira->codegen->invalid_inst_gen; |
| 16783 | 16842 | } |
| ... | ... | @@ -16787,20 +16846,20 @@ static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16787 | 16846 | static IrInstGen *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, |
| 16788 | 16847 | IrInstSrcContainerInitFields *instruction) |
| 16789 | 16848 | { |
| 16790 | | ir_assert(instruction->result_loc != nullptr, &instruction->base.base); |
| 16849 | src_assert(instruction->result_loc != nullptr, instruction->base.source_node); |
| 16791 | 16850 | IrInstGen *result_loc = instruction->result_loc->child; |
| 16792 | 16851 | if (type_is_invalid(result_loc->value->type)) |
| 16793 | 16852 | return result_loc; |
| 16794 | 16853 | |
| 16795 | | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base); |
| 16854 | src_assert(result_loc->value->type->id == ZigTypeIdPointer, instruction->base.source_node); |
| 16796 | 16855 | if (result_loc->value->type->data.pointer.is_const) { |
| 16797 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("cannot assign to constant")); |
| 16856 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("cannot assign to constant")); |
| 16798 | 16857 | return ira->codegen->invalid_inst_gen; |
| 16799 | 16858 | } |
| 16800 | 16859 | |
| 16801 | 16860 | ZigType *container_type = result_loc->value->type->data.pointer.child_type; |
| 16802 | 16861 | |
| 16803 | | return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type, |
| 16862 | return ir_analyze_container_init_fields(ira, instruction->base.scope, instruction->base.source_node, container_type, |
| 16804 | 16863 | instruction->field_count, instruction->fields, result_loc); |
| 16805 | 16864 | } |
| 16806 | 16865 | |
| ... | ... | @@ -16810,7 +16869,7 @@ static IrInstGen *ir_analyze_instruction_compile_err(IrAnalyze *ira, IrInstSrcCo |
| 16810 | 16869 | if (!msg_buf) |
| 16811 | 16870 | return ira->codegen->invalid_inst_gen; |
| 16812 | 16871 | |
| 16813 | | ir_add_error(ira, &instruction->base.base, msg_buf); |
| 16872 | ir_add_error_node(ira, instruction->base.source_node, msg_buf); |
| 16814 | 16873 | |
| 16815 | 16874 | return ira->codegen->invalid_inst_gen; |
| 16816 | 16875 | } |
| ... | ... | @@ -16825,7 +16884,7 @@ static IrInstGen *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstSrcCo |
| 16825 | 16884 | buf_resize(&buf, 0); |
| 16826 | 16885 | if (msg->value->special == ConstValSpecialLazy) { |
| 16827 | 16886 | // Resolve any lazy value that's passed, we need its value |
| 16828 | | if (ir_resolve_lazy(ira->codegen, msg->base.source_node, msg->value)) |
| 16887 | if (ir_resolve_lazy(ira->codegen, msg->source_node, msg->value)) |
| 16829 | 16888 | return ira->codegen->invalid_inst_gen; |
| 16830 | 16889 | } |
| 16831 | 16890 | render_const_value(ira->codegen, &buf, msg->value); |
| ... | ... | @@ -16834,15 +16893,15 @@ static IrInstGen *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstSrcCo |
| 16834 | 16893 | } |
| 16835 | 16894 | fprintf(stderr, "\n"); |
| 16836 | 16895 | |
| 16837 | | auto *expr = &instruction->base.base.source_node->data.fn_call_expr; |
| 16896 | auto *expr = &instruction->base.source_node->data.fn_call_expr; |
| 16838 | 16897 | if (!expr->seen) { |
| 16839 | 16898 | // Here we bypass higher level functions such as ir_add_error because we do not want |
| 16840 | 16899 | // invalidate_exec to be called. |
| 16841 | | add_node_error(ira->codegen, instruction->base.base.source_node, buf_sprintf("found compile log statement")); |
| 16900 | add_node_error(ira->codegen, instruction->base.source_node, buf_sprintf("found compile log statement")); |
| 16842 | 16901 | } |
| 16843 | 16902 | expr->seen = true; |
| 16844 | 16903 | |
| 16845 | | return ir_const_void(ira, &instruction->base.base); |
| 16904 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 16846 | 16905 | } |
| 16847 | 16906 | |
| 16848 | 16907 | static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrName *instruction) { |
| ... | ... | @@ -16864,7 +16923,7 @@ static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrNa |
| 16864 | 16923 | ira->codegen, &err->name, |
| 16865 | 16924 | ira->codegen->intern.for_zero_byte()); |
| 16866 | 16925 | } |
| 16867 | | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 16926 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr); |
| 16868 | 16927 | result->value = err->cached_error_name_val; |
| 16869 | 16928 | return result; |
| 16870 | 16929 | } |
| ... | ... | @@ -16875,7 +16934,7 @@ static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrNa |
| 16875 | 16934 | true, false, PtrLenUnknown, 0, 0, 0, false, |
| 16876 | 16935 | VECTOR_INDEX_NONE, nullptr, ira->codegen->intern.for_zero_byte()); |
| 16877 | 16936 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 16878 | | return ir_build_err_name_gen(ira, &instruction->base.base, value, str_type); |
| 16937 | return ir_build_err_name_gen(ira, instruction->base.scope, instruction->base.source_node, value, str_type); |
| 16879 | 16938 | } |
| 16880 | 16939 | |
| 16881 | 16940 | static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrcTagName *instruction) { |
| ... | ... | @@ -16887,7 +16946,7 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc |
| 16887 | 16946 | ZigType *target_type = target->value->type; |
| 16888 | 16947 | |
| 16889 | 16948 | if (target_type->id == ZigTypeIdEnumLiteral) { |
| 16890 | | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 16949 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr); |
| 16891 | 16950 | Buf *field_name = target->value->data.x_enum_literal; |
| 16892 | 16951 | result->value = create_sentineled_str_lit( |
| 16893 | 16952 | ira->codegen, field_name, |
| ... | ... | @@ -16896,21 +16955,21 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc |
| 16896 | 16955 | } |
| 16897 | 16956 | |
| 16898 | 16957 | if (target_type->id == ZigTypeIdUnion) { |
| 16899 | | target = ir_analyze_union_tag(ira, &instruction->base.base, target); |
| 16958 | target = ir_analyze_union_tag(ira, instruction->base.scope, instruction->base.source_node, target); |
| 16900 | 16959 | if (type_is_invalid(target->value->type)) |
| 16901 | 16960 | return ira->codegen->invalid_inst_gen; |
| 16902 | 16961 | target_type = target->value->type; |
| 16903 | 16962 | } |
| 16904 | 16963 | |
| 16905 | 16964 | if (target_type->id != ZigTypeIdEnum) { |
| 16906 | | ir_add_error(ira, &target->base, |
| 16965 | ir_add_error(ira, target, |
| 16907 | 16966 | buf_sprintf("expected enum tag, found '%s'", buf_ptr(&target_type->name))); |
| 16908 | 16967 | return ira->codegen->invalid_inst_gen; |
| 16909 | 16968 | } |
| 16910 | 16969 | |
| 16911 | 16970 | if (can_fold_enum_type(target_type)) { |
| 16912 | 16971 | TypeEnumField *only_field = &target_type->data.enumeration.fields[0]; |
| 16913 | | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 16972 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr); |
| 16914 | 16973 | result->value = create_sentineled_str_lit( |
| 16915 | 16974 | ira->codegen, only_field->name, |
| 16916 | 16975 | ira->codegen->intern.for_zero_byte()); |
| ... | ... | @@ -16925,11 +16984,11 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc |
| 16925 | 16984 | Buf *int_buf = buf_alloc(); |
| 16926 | 16985 | bigint_append_buf(int_buf, &target->value->data.x_bigint, 10); |
| 16927 | 16986 | |
| 16928 | | ir_add_error(ira, &target->base, |
| 16987 | ir_add_error(ira, target, |
| 16929 | 16988 | buf_sprintf("no tag by value %s", buf_ptr(int_buf))); |
| 16930 | 16989 | return ira->codegen->invalid_inst_gen; |
| 16931 | 16990 | } |
| 16932 | | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 16991 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr); |
| 16933 | 16992 | result->value = create_sentineled_str_lit( |
| 16934 | 16993 | ira->codegen, field->name, |
| 16935 | 16994 | ira->codegen->intern.for_zero_byte()); |
| ... | ... | @@ -16941,7 +17000,7 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc |
| 16941 | 17000 | true, false, PtrLenUnknown, 0, 0, 0, false, |
| 16942 | 17001 | VECTOR_INDEX_NONE, nullptr, ira->codegen->intern.for_zero_byte()); |
| 16943 | 17002 | ZigType *result_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 16944 | | return ir_build_tag_name_gen(ira, &instruction->base.base, target, result_type); |
| 17003 | return ir_build_tag_name_gen(ira, instruction->base.scope, instruction->base.source_node, target, result_type); |
| 16945 | 17004 | } |
| 16946 | 17005 | |
| 16947 | 17006 | static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| ... | ... | @@ -16963,7 +17022,7 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 16963 | 17022 | return ira->codegen->invalid_inst_gen; |
| 16964 | 17023 | |
| 16965 | 17024 | if (container_type->id != ZigTypeIdStruct) { |
| 16966 | | ir_add_error(ira, &type_value->base, |
| 17025 | ir_add_error(ira, type_value, |
| 16967 | 17026 | buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); |
| 16968 | 17027 | return ira->codegen->invalid_inst_gen; |
| 16969 | 17028 | } |
| ... | ... | @@ -16973,14 +17032,14 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 16973 | 17032 | |
| 16974 | 17033 | TypeStructField *field = find_struct_type_field(container_type, field_name); |
| 16975 | 17034 | if (field == nullptr) { |
| 16976 | | ir_add_error(ira, &field_name_value->base, |
| 17035 | ir_add_error(ira, field_name_value, |
| 16977 | 17036 | buf_sprintf("struct '%s' has no field '%s'", |
| 16978 | 17037 | buf_ptr(&container_type->name), buf_ptr(field_name))); |
| 16979 | 17038 | return ira->codegen->invalid_inst_gen; |
| 16980 | 17039 | } |
| 16981 | 17040 | |
| 16982 | 17041 | if (field_ptr->value->type->id != ZigTypeIdPointer) { |
| 16983 | | ir_add_error(ira, &field_ptr->base, |
| 17042 | ir_add_error(ira, field_ptr, |
| 16984 | 17043 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name))); |
| 16985 | 17044 | return ira->codegen->invalid_inst_gen; |
| 16986 | 17045 | } |
| ... | ... | @@ -17010,20 +17069,20 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 17010 | 17069 | return ira->codegen->invalid_inst_gen; |
| 17011 | 17070 | |
| 17012 | 17071 | if (field_ptr_val->data.x_ptr.special != ConstPtrSpecialBaseStruct) { |
| 17013 | | ir_add_error(ira, &field_ptr->base, buf_sprintf("pointer value not based on parent struct")); |
| 17072 | ir_add_error(ira, field_ptr, buf_sprintf("pointer value not based on parent struct")); |
| 17014 | 17073 | return ira->codegen->invalid_inst_gen; |
| 17015 | 17074 | } |
| 17016 | 17075 | |
| 17017 | 17076 | size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index; |
| 17018 | 17077 | if (ptr_field_index != field->src_index) { |
| 17019 | | ir_add_error(ira, &instruction->base.base, |
| 17078 | ir_add_error_node(ira, instruction->base.source_node, |
| 17020 | 17079 | buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'", |
| 17021 | 17080 | buf_ptr(field->name), field->src_index, |
| 17022 | 17081 | ptr_field_index, buf_ptr(&container_type->name))); |
| 17023 | 17082 | return ira->codegen->invalid_inst_gen; |
| 17024 | 17083 | } |
| 17025 | 17084 | |
| 17026 | | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 17085 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type); |
| 17027 | 17086 | ZigValue *out_val = result->value; |
| 17028 | 17087 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 17029 | 17088 | out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val; |
| ... | ... | @@ -17031,7 +17090,7 @@ static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 17031 | 17090 | return result; |
| 17032 | 17091 | } |
| 17033 | 17092 | |
| 17034 | | return ir_build_field_parent_ptr_gen(ira, &instruction->base.base, casted_field_ptr, field, result_type); |
| 17093 | return ir_build_field_parent_ptr_gen(ira, instruction->base.scope, instruction->base.source_node, casted_field_ptr, field, result_type); |
| 17035 | 17094 | } |
| 17036 | 17095 | |
| 17037 | 17096 | static TypeStructField *validate_host_int_byte_offset(IrAnalyze *ira, |
| ... | ... | @@ -17052,21 +17111,21 @@ static TypeStructField *validate_host_int_byte_offset(IrAnalyze *ira, |
| 17052 | 17111 | return nullptr; |
| 17053 | 17112 | |
| 17054 | 17113 | if (container_type->id != ZigTypeIdStruct) { |
| 17055 | | ir_add_error(ira, &type_value->base, |
| 17114 | ir_add_error(ira, type_value, |
| 17056 | 17115 | buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); |
| 17057 | 17116 | return nullptr; |
| 17058 | 17117 | } |
| 17059 | 17118 | |
| 17060 | 17119 | TypeStructField *field = find_struct_type_field(container_type, field_name); |
| 17061 | 17120 | if (field == nullptr) { |
| 17062 | | ir_add_error(ira, &field_name_value->base, |
| 17121 | ir_add_error(ira, field_name_value, |
| 17063 | 17122 | buf_sprintf("struct '%s' has no field '%s'", |
| 17064 | 17123 | buf_ptr(&container_type->name), buf_ptr(field_name))); |
| 17065 | 17124 | return nullptr; |
| 17066 | 17125 | } |
| 17067 | 17126 | |
| 17068 | 17127 | if (!type_has_bits(ira->codegen, field->type_entry)) { |
| 17069 | | ir_add_error(ira, &field_name_value->base, |
| 17128 | ir_add_error(ira, field_name_value, |
| 17070 | 17129 | buf_sprintf("zero-bit field '%s' in struct '%s' has no offset", |
| 17071 | 17130 | buf_ptr(field_name), buf_ptr(&container_type->name))); |
| 17072 | 17131 | return nullptr; |
| ... | ... | @@ -17088,7 +17147,7 @@ static IrInstGen *ir_analyze_instruction_offset_of(IrAnalyze *ira, IrInstSrcOffs |
| 17088 | 17147 | return ira->codegen->invalid_inst_gen; |
| 17089 | 17148 | |
| 17090 | 17149 | size_t byte_offset = host_int_byte_offset + (field->bit_offset_in_host / 8); |
| 17091 | | return ir_const_unsigned(ira, &instruction->base.base, byte_offset); |
| 17150 | return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, byte_offset); |
| 17092 | 17151 | } |
| 17093 | 17152 | |
| 17094 | 17153 | static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrcBitOffsetOf *instruction) { |
| ... | ... | @@ -17102,7 +17161,7 @@ static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrc |
| 17102 | 17161 | return ira->codegen->invalid_inst_gen; |
| 17103 | 17162 | |
| 17104 | 17163 | size_t bit_offset = host_int_byte_offset * 8 + field->bit_offset_in_host; |
| 17105 | | return ir_const_unsigned(ira, &instruction->base.base, bit_offset); |
| 17164 | return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, bit_offset); |
| 17106 | 17165 | } |
| 17107 | 17166 | |
| 17108 | 17167 | static void ensure_field_index(ZigType *type, const char *field_name, size_t index) { |
| ... | ... | @@ -17150,7 +17209,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig |
| 17150 | 17209 | return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value); |
| 17151 | 17210 | } |
| 17152 | 17211 | |
| 17153 | | static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigValue *out_val, |
| 17212 | static Error ir_make_type_info_decls(IrAnalyze *ira, AstNode *source_node, ZigValue *out_val, |
| 17154 | 17213 | ScopeDecls *decls_scope, bool resolve_types) |
| 17155 | 17214 | { |
| 17156 | 17215 | Error err; |
| ... | ... | @@ -17174,7 +17233,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa |
| 17174 | 17233 | out_val->data.x_lazy = &lazy_type_info_decls->base; |
| 17175 | 17234 | lazy_type_info_decls->base.id = LazyValueIdTypeInfoDecls; |
| 17176 | 17235 | |
| 17177 | | lazy_type_info_decls->source_instr = source_instr; |
| 17236 | lazy_type_info_decls->source_node = source_node; |
| 17178 | 17237 | lazy_type_info_decls->decls_scope = decls_scope; |
| 17179 | 17238 | |
| 17180 | 17239 | return ErrorNone; |
| ... | ... | @@ -17202,7 +17261,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa |
| 17202 | 17261 | } |
| 17203 | 17262 | |
| 17204 | 17263 | if (curr_entry->value->resolution == TldResolutionResolving) { |
| 17205 | | ir_error_dependency_loop(ira, source_instr); |
| 17264 | ir_error_dependency_loop(ira, source_node); |
| 17206 | 17265 | return ErrorSemanticAnalyzeFail; |
| 17207 | 17266 | } |
| 17208 | 17267 | |
| ... | ... | @@ -17435,7 +17494,7 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) { |
| 17435 | 17494 | zig_unreachable(); |
| 17436 | 17495 | } |
| 17437 | 17496 | |
| 17438 | | static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, IrInst *source_instr, ZigType *ptr_type_entry) { |
| 17497 | static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ptr_type_entry) { |
| 17439 | 17498 | ZigType *attrs_type; |
| 17440 | 17499 | BuiltinPtrSize size_enum_index; |
| 17441 | 17500 | if (is_slice(ptr_type_entry)) { |
| ... | ... | @@ -17489,7 +17548,7 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, IrInst *source_instr, |
| 17489 | 17548 | fields[3]->special = ConstValSpecialLazy; |
| 17490 | 17549 | fields[3]->data.x_lazy = &lazy_align_of->base; |
| 17491 | 17550 | lazy_align_of->base.id = LazyValueIdAlignOf; |
| 17492 | | lazy_align_of->target_type = ir_const_type(ira, source_instr, attrs_type->data.pointer.child_type); |
| 17551 | lazy_align_of->target_type = ir_const_type(ira, scope, source_node, attrs_type->data.pointer.child_type); |
| 17493 | 17552 | } |
| 17494 | 17553 | // child: type |
| 17495 | 17554 | ensure_field_index(result->type, "child", 4); |
| ... | ... | @@ -17532,7 +17591,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn |
| 17532 | 17591 | enum_field_val->data.x_struct.fields = inner_fields; |
| 17533 | 17592 | } |
| 17534 | 17593 | |
| 17535 | | static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry, |
| 17594 | static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *type_entry, |
| 17536 | 17595 | ZigValue **out) |
| 17537 | 17596 | { |
| 17538 | 17597 | Error err; |
| ... | ... | @@ -17601,7 +17660,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 17601 | 17660 | } |
| 17602 | 17661 | case ZigTypeIdPointer: |
| 17603 | 17662 | { |
| 17604 | | result = create_ptr_like_type_info(ira, source_instr, type_entry); |
| 17663 | result = create_ptr_like_type_info(ira, scope, source_node, type_entry); |
| 17605 | 17664 | if (result == nullptr) |
| 17606 | 17665 | return ErrorSemanticAnalyzeFail; |
| 17607 | 17666 | break; |
| ... | ... | @@ -17739,7 +17798,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 17739 | 17798 | } |
| 17740 | 17799 | // decls: []TypeInfo.Declaration |
| 17741 | 17800 | ensure_field_index(result->type, "decls", 3); |
| 17742 | | if ((err = ir_make_type_info_decls(ira, source_instr, fields[3], |
| 17801 | if ((err = ir_make_type_info_decls(ira, source_node, fields[3], |
| 17743 | 17802 | type_entry->data.enumeration.decls_scope, false))) |
| 17744 | 17803 | { |
| 17745 | 17804 | return err; |
| ... | ... | @@ -17759,7 +17818,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 17759 | 17818 | result->type = ir_type_info_get_type(ira, "ErrorSet", nullptr); |
| 17760 | 17819 | |
| 17761 | 17820 | ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr); |
| 17762 | | if (!resolve_inferred_error_set(ira->codegen, type_entry, source_instr->source_node)) { |
| 17821 | if (!resolve_inferred_error_set(ira->codegen, type_entry, source_node)) { |
| 17763 | 17822 | return ErrorSemanticAnalyzeFail; |
| 17764 | 17823 | } |
| 17765 | 17824 | if (type_is_global_error_set(type_entry)) { |
| ... | ... | @@ -17905,7 +17964,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 17905 | 17964 | } |
| 17906 | 17965 | // decls: []TypeInfo.Declaration |
| 17907 | 17966 | ensure_field_index(result->type, "decls", 3); |
| 17908 | | if ((err = ir_make_type_info_decls(ira, source_instr, fields[3], |
| 17967 | if ((err = ir_make_type_info_decls(ira, source_node, fields[3], |
| 17909 | 17968 | type_entry->data.unionation.decls_scope, false))) |
| 17910 | 17969 | { |
| 17911 | 17970 | return err; |
| ... | ... | @@ -17916,7 +17975,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 17916 | 17975 | case ZigTypeIdStruct: |
| 17917 | 17976 | { |
| 17918 | 17977 | if (type_entry->data.structure.special == StructSpecialSlice) { |
| 17919 | | result = create_ptr_like_type_info(ira, source_instr, type_entry); |
| 17978 | result = create_ptr_like_type_info(ira, scope, source_node, type_entry); |
| 17920 | 17979 | if (result == nullptr) |
| 17921 | 17980 | return ErrorSemanticAnalyzeFail; |
| 17922 | 17981 | break; |
| ... | ... | @@ -17997,7 +18056,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 17997 | 18056 | } |
| 17998 | 18057 | // decls: []TypeInfo.Declaration |
| 17999 | 18058 | ensure_field_index(result->type, "decls", 2); |
| 18000 | | if ((err = ir_make_type_info_decls(ira, source_instr, fields[2], |
| 18059 | if ((err = ir_make_type_info_decls(ira, source_node, fields[2], |
| 18001 | 18060 | type_entry->data.structure.decls_scope, false))) |
| 18002 | 18061 | { |
| 18003 | 18062 | return err; |
| ... | ... | @@ -18112,7 +18171,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 18112 | 18171 | { |
| 18113 | 18172 | ZigType *fn_type = type_entry->data.bound_fn.fn_type; |
| 18114 | 18173 | assert(fn_type->id == ZigTypeIdFn); |
| 18115 | | if ((err = ir_make_type_info_value(ira, source_instr, fn_type, &result))) |
| 18174 | if ((err = ir_make_type_info_value(ira, scope, source_node, fn_type, &result))) |
| 18116 | 18175 | return err; |
| 18117 | 18176 | |
| 18118 | 18177 | break; |
| ... | ... | @@ -18128,7 +18187,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 18128 | 18187 | |
| 18129 | 18188 | // decls: []TypeInfo.Declaration |
| 18130 | 18189 | ensure_field_index(result->type, "decls", 0); |
| 18131 | | if ((err = ir_make_type_info_decls(ira, source_instr, fields[0], |
| 18190 | if ((err = ir_make_type_info_decls(ira, source_node, fields[0], |
| 18132 | 18191 | type_entry->data.opaque.decls_scope, false))) |
| 18133 | 18192 | { |
| 18134 | 18193 | return err; |
| ... | ... | @@ -18167,10 +18226,10 @@ static IrInstGen *ir_analyze_instruction_type_info(IrAnalyze *ira, IrInstSrcType |
| 18167 | 18226 | ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr); |
| 18168 | 18227 | |
| 18169 | 18228 | ZigValue *payload; |
| 18170 | | if ((err = ir_make_type_info_value(ira, &instruction->base.base, type_entry, &payload))) |
| 18229 | if ((err = ir_make_type_info_value(ira, instruction->base.scope, instruction->base.source_node, type_entry, &payload))) |
| 18171 | 18230 | return ira->codegen->invalid_inst_gen; |
| 18172 | 18231 | |
| 18173 | | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 18232 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type); |
| 18174 | 18233 | ZigValue *out_val = result->value; |
| 18175 | 18234 | bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry)); |
| 18176 | 18235 | out_val->data.x_union.payload = payload; |
| ... | ... | @@ -18194,14 +18253,14 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue |
| 18194 | 18253 | return val; |
| 18195 | 18254 | } |
| 18196 | 18255 | |
| 18197 | | static Error get_const_field_sentinel(IrAnalyze *ira, IrInst* source_instr, ZigValue *struct_value, |
| 18256 | static Error get_const_field_sentinel(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigValue *struct_value, |
| 18198 | 18257 | const char *name, size_t field_index, ZigType *elem_type, ZigValue **result) |
| 18199 | 18258 | { |
| 18200 | | ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index); |
| 18259 | ZigValue *field_val = get_const_field(ira, source_node, struct_value, name, field_index); |
| 18201 | 18260 | if (field_val == nullptr) |
| 18202 | 18261 | return ErrorSemanticAnalyzeFail; |
| 18203 | 18262 | |
| 18204 | | IrInstGen *field_inst = ir_const_move(ira, source_instr, field_val); |
| 18263 | IrInstGen *field_inst = ir_const_move(ira, scope, source_node, field_val); |
| 18205 | 18264 | IrInstGen *casted_field_inst = ir_implicit_cast(ira, field_inst, |
| 18206 | 18265 | get_optional_type(ira->codegen, elem_type)); |
| 18207 | 18266 | if (type_is_invalid(casted_field_inst->value->type)) |
| ... | ... | @@ -18295,7 +18354,7 @@ static Error get_const_field_buf(IrAnalyze *ira, AstNode *source_node, ZigValue |
| 18295 | 18354 | return ErrorNone; |
| 18296 | 18355 | } |
| 18297 | 18356 | |
| 18298 | | static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeId tagTypeId, ZigValue *payload) { |
| 18357 | static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigTypeId tagTypeId, ZigValue *payload) { |
| 18299 | 18358 | Error err; |
| 18300 | 18359 | switch (tagTypeId) { |
| 18301 | 18360 | case ZigTypeIdInvalid: |
| ... | ... | @@ -18319,7 +18378,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18319 | 18378 | case ZigTypeIdEnumLiteral: |
| 18320 | 18379 | return ira->codegen->builtin_types.entry_enum_literal; |
| 18321 | 18380 | default: |
| 18322 | | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_instr->source_node, payload, UndefBad))) |
| 18381 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_node, payload, UndefBad))) |
| 18323 | 18382 | return ira->codegen->invalid_inst_gen->value->type; |
| 18324 | 18383 | } |
| 18325 | 18384 | switch (tagTypeId) { |
| ... | ... | @@ -18337,10 +18396,10 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18337 | 18396 | case ZigTypeIdInt: { |
| 18338 | 18397 | assert(payload->special == ConstValSpecialStatic); |
| 18339 | 18398 | assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr)); |
| 18340 | | BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 1); |
| 18399 | BigInt *bi = get_const_field_lit_int(ira, source_node, payload, "bits", 1); |
| 18341 | 18400 | if (bi == nullptr) |
| 18342 | 18401 | return ira->codegen->invalid_inst_gen->value->type; |
| 18343 | | ZigValue *value = get_const_field(ira, source_instr->source_node, payload, "signedness", 0); |
| 18402 | ZigValue *value = get_const_field(ira, source_node, payload, "signedness", 0); |
| 18344 | 18403 | if (value == nullptr) |
| 18345 | 18404 | return ira->codegen->invalid_inst_gen->value->type; |
| 18346 | 18405 | assert(value->type == get_builtin_type(ira->codegen, "Signedness")); |
| ... | ... | @@ -18351,7 +18410,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18351 | 18410 | { |
| 18352 | 18411 | assert(payload->special == ConstValSpecialStatic); |
| 18353 | 18412 | assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr)); |
| 18354 | | BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 0); |
| 18413 | BigInt *bi = get_const_field_lit_int(ira, source_node, payload, "bits", 0); |
| 18355 | 18414 | if (bi == nullptr) |
| 18356 | 18415 | return ira->codegen->invalid_inst_gen->value->type; |
| 18357 | 18416 | uint32_t bits = bigint_as_u32(bi); |
| ... | ... | @@ -18361,7 +18420,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18361 | 18420 | case 64: return ira->codegen->builtin_types.entry_f64; |
| 18362 | 18421 | case 128: return ira->codegen->builtin_types.entry_f128; |
| 18363 | 18422 | } |
| 18364 | | ir_add_error(ira, source_instr, buf_sprintf("%d-bit float unsupported", bits)); |
| 18423 | ir_add_error_node(ira, source_node, buf_sprintf("%d-bit float unsupported", bits)); |
| 18365 | 18424 | return ira->codegen->invalid_inst_gen->value->type; |
| 18366 | 18425 | } |
| 18367 | 18426 | case ZigTypeIdPointer: |
| ... | ... | @@ -18369,45 +18428,45 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18369 | 18428 | ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr); |
| 18370 | 18429 | assert(payload->special == ConstValSpecialStatic); |
| 18371 | 18430 | assert(payload->type == type_info_pointer_type); |
| 18372 | | ZigValue *size_value = get_const_field(ira, source_instr->source_node, payload, "size", 0); |
| 18431 | ZigValue *size_value = get_const_field(ira, source_node, payload, "size", 0); |
| 18373 | 18432 | if (size_value == nullptr) |
| 18374 | 18433 | return ira->codegen->invalid_inst_gen->value->type; |
| 18375 | 18434 | |
| 18376 | 18435 | assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type)); |
| 18377 | 18436 | BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag); |
| 18378 | 18437 | PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index); |
| 18379 | | ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 4); |
| 18438 | ZigType *elem_type = get_const_field_meta_type(ira, source_node, payload, "child", 4); |
| 18380 | 18439 | if (type_is_invalid(elem_type)) |
| 18381 | 18440 | return ira->codegen->invalid_inst_gen->value->type; |
| 18382 | 18441 | ZigValue *sentinel; |
| 18383 | | if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 6, |
| 18442 | if ((err = get_const_field_sentinel(ira, scope, source_node, payload, "sentinel", 6, |
| 18384 | 18443 | elem_type, &sentinel))) |
| 18385 | 18444 | { |
| 18386 | 18445 | return ira->codegen->invalid_inst_gen->value->type; |
| 18387 | 18446 | } |
| 18388 | 18447 | if (sentinel != nullptr && (size_enum_index == BuiltinPtrSizeOne || size_enum_index == BuiltinPtrSizeC)) { |
| 18389 | | ir_add_error(ira, source_instr, |
| 18448 | ir_add_error_node(ira, source_node, |
| 18390 | 18449 | buf_sprintf("sentinels are only allowed on slices and unknown-length pointers")); |
| 18391 | 18450 | return ira->codegen->invalid_inst_gen->value->type; |
| 18392 | 18451 | } |
| 18393 | 18452 | |
| 18394 | | BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 3); |
| 18453 | BigInt *alignment = get_const_field_lit_int(ira, source_node, payload, "alignment", 3); |
| 18395 | 18454 | if (alignment == nullptr) |
| 18396 | 18455 | return ira->codegen->invalid_inst_gen->value->type; |
| 18397 | 18456 | |
| 18398 | 18457 | bool is_const; |
| 18399 | | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_const", 1, &is_const))) |
| 18458 | if ((err = get_const_field_bool(ira, source_node, payload, "is_const", 1, &is_const))) |
| 18400 | 18459 | return ira->codegen->invalid_inst_gen->value->type; |
| 18401 | 18460 | |
| 18402 | 18461 | bool is_volatile; |
| 18403 | | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_volatile", 2, |
| 18462 | if ((err = get_const_field_bool(ira, source_node, payload, "is_volatile", 2, |
| 18404 | 18463 | &is_volatile))) |
| 18405 | 18464 | { |
| 18406 | 18465 | return ira->codegen->invalid_inst_gen->value->type; |
| 18407 | 18466 | } |
| 18408 | 18467 | |
| 18409 | 18468 | bool is_allowzero; |
| 18410 | | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_allowzero", 5, |
| 18469 | if ((err = get_const_field_bool(ira, source_node, payload, "is_allowzero", 5, |
| 18411 | 18470 | &is_allowzero))) |
| 18412 | 18471 | { |
| 18413 | 18472 | return ira->codegen->invalid_inst_gen->value->type; |
| ... | ... | @@ -18431,16 +18490,16 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18431 | 18490 | case ZigTypeIdArray: { |
| 18432 | 18491 | assert(payload->special == ConstValSpecialStatic); |
| 18433 | 18492 | assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr)); |
| 18434 | | ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 1); |
| 18493 | ZigType *elem_type = get_const_field_meta_type(ira, source_node, payload, "child", 1); |
| 18435 | 18494 | if (type_is_invalid(elem_type)) |
| 18436 | 18495 | return ira->codegen->invalid_inst_gen->value->type; |
| 18437 | 18496 | ZigValue *sentinel; |
| 18438 | | if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 2, |
| 18497 | if ((err = get_const_field_sentinel(ira, scope, source_node, payload, "sentinel", 2, |
| 18439 | 18498 | elem_type, &sentinel))) |
| 18440 | 18499 | { |
| 18441 | 18500 | return ira->codegen->invalid_inst_gen->value->type; |
| 18442 | 18501 | } |
| 18443 | | BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "len", 0); |
| 18502 | BigInt *bi = get_const_field_lit_int(ira, source_node, payload, "len", 0); |
| 18444 | 18503 | if (bi == nullptr) |
| 18445 | 18504 | return ira->codegen->invalid_inst_gen->value->type; |
| 18446 | 18505 | return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel); |
| ... | ... | @@ -18448,7 +18507,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18448 | 18507 | case ZigTypeIdOptional: { |
| 18449 | 18508 | assert(payload->special == ConstValSpecialStatic); |
| 18450 | 18509 | assert(payload->type == ir_type_info_get_type(ira, "Optional", nullptr)); |
| 18451 | | ZigType *child_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 0); |
| 18510 | ZigType *child_type = get_const_field_meta_type(ira, source_node, payload, "child", 0); |
| 18452 | 18511 | if (type_is_invalid(child_type)) |
| 18453 | 18512 | return ira->codegen->invalid_inst_gen->value->type; |
| 18454 | 18513 | return get_optional_type(ira->codegen, child_type); |
| ... | ... | @@ -18456,11 +18515,11 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18456 | 18515 | case ZigTypeIdErrorUnion: { |
| 18457 | 18516 | assert(payload->special == ConstValSpecialStatic); |
| 18458 | 18517 | assert(payload->type == ir_type_info_get_type(ira, "ErrorUnion", nullptr)); |
| 18459 | | ZigType *err_set_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "error_set", 0); |
| 18518 | ZigType *err_set_type = get_const_field_meta_type(ira, source_node, payload, "error_set", 0); |
| 18460 | 18519 | if (type_is_invalid(err_set_type)) |
| 18461 | 18520 | return ira->codegen->invalid_inst_gen->value->type; |
| 18462 | 18521 | |
| 18463 | | ZigType *payload_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "payload", 1); |
| 18522 | ZigType *payload_type = get_const_field_meta_type(ira, source_node, payload, "payload", 1); |
| 18464 | 18523 | if (type_is_invalid(payload_type)) |
| 18465 | 18524 | return ira->codegen->invalid_inst_gen->value->type; |
| 18466 | 18525 | |
| ... | ... | @@ -18470,7 +18529,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18470 | 18529 | assert(payload->special == ConstValSpecialStatic); |
| 18471 | 18530 | assert(payload->type == ir_type_info_get_type(ira, "Opaque", nullptr)); |
| 18472 | 18531 | |
| 18473 | | ZigValue *decls_value = get_const_field(ira, source_instr->source_node, payload, "decls", 0); |
| 18532 | ZigValue *decls_value = get_const_field(ira, source_node, payload, "decls", 0); |
| 18474 | 18533 | if (decls_value == nullptr) |
| 18475 | 18534 | return ira->codegen->invalid_inst_gen->value->type; |
| 18476 | 18535 | assert(decls_value->special == ConstValSpecialStatic); |
| ... | ... | @@ -18478,25 +18537,25 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18478 | 18537 | ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index]; |
| 18479 | 18538 | size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint); |
| 18480 | 18539 | if (decls_len != 0) { |
| 18481 | | ir_add_error(ira, source_instr, buf_create_from_str("TypeInfo.Struct.decls must be empty for @Type")); |
| 18540 | ir_add_error_node(ira, source_node, buf_create_from_str("TypeInfo.Struct.decls must be empty for @Type")); |
| 18482 | 18541 | return ira->codegen->invalid_inst_gen->value->type; |
| 18483 | 18542 | } |
| 18484 | 18543 | |
| 18485 | 18544 | Buf *bare_name = buf_alloc(); |
| 18486 | 18545 | Buf *full_name = get_anon_type_name(ira->codegen, |
| 18487 | | ira->zir, "opaque", source_instr->scope, source_instr->source_node, bare_name); |
| 18546 | ira->zir, "opaque", scope, source_node, bare_name); |
| 18488 | 18547 | return get_opaque_type(ira->codegen, |
| 18489 | | source_instr->scope, source_instr->source_node, buf_ptr(full_name), bare_name); |
| 18548 | scope, source_node, buf_ptr(full_name), bare_name); |
| 18490 | 18549 | } |
| 18491 | 18550 | case ZigTypeIdVector: { |
| 18492 | 18551 | assert(payload->special == ConstValSpecialStatic); |
| 18493 | 18552 | assert(payload->type == ir_type_info_get_type(ira, "Vector", nullptr)); |
| 18494 | | BigInt *len = get_const_field_lit_int(ira, source_instr->source_node, payload, "len", 0); |
| 18553 | BigInt *len = get_const_field_lit_int(ira, source_node, payload, "len", 0); |
| 18495 | 18554 | if (len == nullptr) |
| 18496 | 18555 | return ira->codegen->invalid_inst_gen->value->type; |
| 18497 | 18556 | |
| 18498 | | ZigType *child_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 1); |
| 18499 | | if ((err = ir_validate_vector_elem_type(ira, source_instr->source_node, child_type))) { |
| 18557 | ZigType *child_type = get_const_field_meta_type(ira, source_node, payload, "child", 1); |
| 18558 | if ((err = ir_validate_vector_elem_type(ira, source_node, child_type))) { |
| 18500 | 18559 | return ira->codegen->invalid_inst_gen->value->type; |
| 18501 | 18560 | } |
| 18502 | 18561 | return get_vector_type(ira->codegen, bigint_as_u32(len), child_type); |
| ... | ... | @@ -18504,7 +18563,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18504 | 18563 | case ZigTypeIdAnyFrame: { |
| 18505 | 18564 | assert(payload->special == ConstValSpecialStatic); |
| 18506 | 18565 | assert(payload->type == ir_type_info_get_type(ira, "AnyFrame", nullptr)); |
| 18507 | | ZigType *child_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "child", 0); |
| 18566 | ZigType *child_type = get_const_field_meta_type_optional(ira, source_node, payload, "child", 0); |
| 18508 | 18567 | if (child_type != nullptr && type_is_invalid(child_type)) |
| 18509 | 18568 | return ira->codegen->invalid_inst_gen->value->type; |
| 18510 | 18569 | |
| ... | ... | @@ -18513,7 +18572,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18513 | 18572 | case ZigTypeIdFnFrame: { |
| 18514 | 18573 | assert(payload->special == ConstValSpecialStatic); |
| 18515 | 18574 | assert(payload->type == ir_type_info_get_type(ira, "Frame", nullptr)); |
| 18516 | | ZigValue *function = get_const_field(ira, source_instr->source_node, payload, "function", 0); |
| 18575 | ZigValue *function = get_const_field(ira, source_node, payload, "function", 0); |
| 18517 | 18576 | if (function == nullptr) |
| 18518 | 18577 | return ira->codegen->invalid_inst_gen->value->type; |
| 18519 | 18578 | |
| ... | ... | @@ -18531,7 +18590,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18531 | 18590 | assert(is_slice(slice->type)); |
| 18532 | 18591 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); |
| 18533 | 18592 | Buf bare_name = BUF_INIT; |
| 18534 | | buf_init_from_buf(&err_set_type->name, get_anon_type_name(ira->codegen, ira->zir, "error", source_instr->scope, source_instr->source_node, &bare_name)); |
| 18593 | buf_init_from_buf(&err_set_type->name, get_anon_type_name(ira->codegen, ira->zir, "error", scope, source_node, &bare_name)); |
| 18535 | 18594 | err_set_type->size_in_bits = ira->codegen->builtin_types.entry_global_error_set->size_in_bits; |
| 18536 | 18595 | err_set_type->abi_align = ira->codegen->builtin_types.entry_global_error_set->abi_align; |
| 18537 | 18596 | err_set_type->abi_size = ira->codegen->builtin_types.entry_global_error_set->abi_size; |
| ... | ... | @@ -18550,8 +18609,8 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18550 | 18609 | ZigValue *error = &arr->data.x_array.data.s_none.elements[i]; |
| 18551 | 18610 | assert(error->type == ir_type_info_get_type(ira, "Error", nullptr)); |
| 18552 | 18611 | ErrorTableEntry *err_entry = heap::c_allocator.create<ErrorTableEntry>(); |
| 18553 | | err_entry->decl_node = source_instr->source_node; |
| 18554 | | if ((err = get_const_field_buf(ira, source_instr->source_node, error, "name", 0, &err_entry->name))) |
| 18612 | err_entry->decl_node = source_node; |
| 18613 | if ((err = get_const_field_buf(ira, source_node, error, "name", 0, &err_entry->name))) |
| 18555 | 18614 | return ira->codegen->invalid_inst_gen->value->type; |
| 18556 | 18615 | auto existing_entry = ira->codegen->error_table.put_unique(&err_entry->name, err_entry); |
| 18557 | 18616 | if (existing_entry) { |
| ... | ... | @@ -18563,7 +18622,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18563 | 18622 | ira->codegen->errors_by_index.append(err_entry); |
| 18564 | 18623 | } |
| 18565 | 18624 | if (already_set[err_entry->value]) { |
| 18566 | | ir_add_error(ira, source_instr, buf_sprintf("duplicate error: %s", buf_ptr(&err_entry->name))); |
| 18625 | ir_add_error_node(ira, source_node, buf_sprintf("duplicate error: %s", buf_ptr(&err_entry->name))); |
| 18567 | 18626 | return ira->codegen->invalid_inst_gen->value->type; |
| 18568 | 18627 | } else { |
| 18569 | 18628 | already_set[err_entry->value] = true; |
| ... | ... | @@ -18576,14 +18635,14 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18576 | 18635 | assert(payload->special == ConstValSpecialStatic); |
| 18577 | 18636 | assert(payload->type == ir_type_info_get_type(ira, "Struct", nullptr)); |
| 18578 | 18637 | |
| 18579 | | ZigValue *layout_value = get_const_field(ira, source_instr->source_node, payload, "layout", 0); |
| 18638 | ZigValue *layout_value = get_const_field(ira, source_node, payload, "layout", 0); |
| 18580 | 18639 | if (layout_value == nullptr) |
| 18581 | 18640 | return ira->codegen->invalid_inst_gen->value->type; |
| 18582 | 18641 | assert(layout_value->special == ConstValSpecialStatic); |
| 18583 | 18642 | assert(layout_value->type == ir_type_info_get_type(ira, "ContainerLayout", nullptr)); |
| 18584 | 18643 | ContainerLayout layout = (ContainerLayout)bigint_as_u32(&layout_value->data.x_enum_tag); |
| 18585 | 18644 | |
| 18586 | | ZigValue *fields_value = get_const_field(ira, source_instr->source_node, payload, "fields", 1); |
| 18645 | ZigValue *fields_value = get_const_field(ira, source_node, payload, "fields", 1); |
| 18587 | 18646 | if (fields_value == nullptr) |
| 18588 | 18647 | return ira->codegen->invalid_inst_gen->value->type; |
| 18589 | 18648 | assert(fields_value->special == ConstValSpecialStatic); |
| ... | ... | @@ -18592,7 +18651,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18592 | 18651 | ZigValue *fields_len_value = fields_value->data.x_struct.fields[slice_len_index]; |
| 18593 | 18652 | size_t fields_len = bigint_as_usize(&fields_len_value->data.x_bigint); |
| 18594 | 18653 | |
| 18595 | | ZigValue *decls_value = get_const_field(ira, source_instr->source_node, payload, "decls", 2); |
| 18654 | ZigValue *decls_value = get_const_field(ira, source_node, payload, "decls", 2); |
| 18596 | 18655 | if (decls_value == nullptr) |
| 18597 | 18656 | return ira->codegen->invalid_inst_gen->value->type; |
| 18598 | 18657 | assert(decls_value->special == ConstValSpecialStatic); |
| ... | ... | @@ -18600,18 +18659,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18600 | 18659 | ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index]; |
| 18601 | 18660 | size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint); |
| 18602 | 18661 | if (decls_len != 0) { |
| 18603 | | ir_add_error(ira, source_instr, buf_create_from_str("TypeInfo.Struct.decls must be empty for @Type")); |
| 18662 | ir_add_error_node(ira, source_node, buf_create_from_str("TypeInfo.Struct.decls must be empty for @Type")); |
| 18604 | 18663 | return ira->codegen->invalid_inst_gen->value->type; |
| 18605 | 18664 | } |
| 18606 | 18665 | |
| 18607 | 18666 | bool is_tuple; |
| 18608 | | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_tuple", 3, &is_tuple))) |
| 18667 | if ((err = get_const_field_bool(ira, source_node, payload, "is_tuple", 3, &is_tuple))) |
| 18609 | 18668 | return ira->codegen->invalid_inst_gen->value->type; |
| 18610 | 18669 | |
| 18611 | 18670 | ZigType *entry = new_type_table_entry(ZigTypeIdStruct); |
| 18612 | 18671 | buf_init_from_buf(&entry->name, |
| 18613 | | get_anon_type_name(ira->codegen, ira->zir, "struct", source_instr->scope, source_instr->source_node, &entry->name)); |
| 18614 | | entry->data.structure.decl_node = source_instr->source_node; |
| 18672 | get_anon_type_name(ira->codegen, ira->zir, "struct", scope, source_node, &entry->name)); |
| 18673 | entry->data.structure.decl_node = source_node; |
| 18615 | 18674 | entry->data.structure.fields = alloc_type_struct_fields(fields_len); |
| 18616 | 18675 | entry->data.structure.fields_by_name.init(fields_len); |
| 18617 | 18676 | entry->data.structure.src_field_count = fields_len; |
| ... | ... | @@ -18619,7 +18678,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18619 | 18678 | entry->data.structure.special = is_tuple ? StructSpecialInferredTuple : StructSpecialNone; |
| 18620 | 18679 | entry->data.structure.created_by_at_type = true; |
| 18621 | 18680 | entry->data.structure.decls_scope = create_decls_scope( |
| 18622 | | ira->codegen, source_instr->source_node, source_instr->scope, entry, get_scope_import(source_instr->scope), &entry->name); |
| 18681 | ira->codegen, source_node, scope, entry, get_scope_import(scope), &entry->name); |
| 18623 | 18682 | |
| 18624 | 18683 | assert(fields_ptr->data.x_ptr.special == ConstPtrSpecialBaseArray); |
| 18625 | 18684 | assert(fields_ptr->data.x_ptr.data.base_array.elem_index == 0); |
| ... | ... | @@ -18631,19 +18690,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18631 | 18690 | assert(field_value->type == ir_type_info_get_type(ira, "StructField", nullptr)); |
| 18632 | 18691 | TypeStructField *field = entry->data.structure.fields[i]; |
| 18633 | 18692 | field->name = buf_alloc(); |
| 18634 | | if ((err = get_const_field_buf(ira, source_instr->source_node, field_value, "name", 0, field->name))) |
| 18693 | if ((err = get_const_field_buf(ira, source_node, field_value, "name", 0, field->name))) |
| 18635 | 18694 | return ira->codegen->invalid_inst_gen->value->type; |
| 18636 | | field->decl_node = source_instr->source_node; |
| 18637 | | ZigValue *type_value = get_const_field(ira, source_instr->source_node, field_value, "field_type", 1); |
| 18695 | field->decl_node = source_node; |
| 18696 | ZigValue *type_value = get_const_field(ira, source_node, field_value, "field_type", 1); |
| 18638 | 18697 | if (type_value == nullptr) |
| 18639 | 18698 | return ira->codegen->invalid_inst_gen->value->type; |
| 18640 | 18699 | field->type_val = type_value; |
| 18641 | 18700 | field->type_entry = type_value->data.x_type; |
| 18642 | 18701 | if (entry->data.structure.fields_by_name.put_unique(field->name, field) != nullptr) { |
| 18643 | | ir_add_error(ira, source_instr, buf_sprintf("duplicate struct field '%s'", buf_ptr(field->name))); |
| 18702 | ir_add_error_node(ira, source_node, buf_sprintf("duplicate struct field '%s'", buf_ptr(field->name))); |
| 18644 | 18703 | return ira->codegen->invalid_inst_gen->value->type; |
| 18645 | 18704 | } |
| 18646 | | ZigValue *default_value = get_const_field(ira, source_instr->source_node, field_value, "default_value", 2); |
| 18705 | ZigValue *default_value = get_const_field(ira, source_node, field_value, "default_value", 2); |
| 18647 | 18706 | if (default_value == nullptr) |
| 18648 | 18707 | return ira->codegen->invalid_inst_gen->value->type; |
| 18649 | 18708 | if (default_value->type->id == ZigTypeIdNull) { |
| ... | ... | @@ -18653,15 +18712,15 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18653 | 18712 | } else if (default_value->type == field->type_entry) { |
| 18654 | 18713 | field->init_val = default_value; |
| 18655 | 18714 | } else { |
| 18656 | | ir_add_error(ira, source_instr, |
| 18715 | ir_add_error_node(ira, source_node, |
| 18657 | 18716 | buf_sprintf("default_value of field '%s' is of type '%s', expected '%s' or '?%s'", |
| 18658 | 18717 | buf_ptr(field->name), buf_ptr(&default_value->type->name), |
| 18659 | 18718 | buf_ptr(&field->type_entry->name), buf_ptr(&field->type_entry->name))); |
| 18660 | 18719 | return ira->codegen->invalid_inst_gen->value->type; |
| 18661 | 18720 | } |
| 18662 | | if ((err = get_const_field_bool(ira, source_instr->source_node, field_value, "is_comptime", 3, &field->is_comptime))) |
| 18721 | if ((err = get_const_field_bool(ira, source_node, field_value, "is_comptime", 3, &field->is_comptime))) |
| 18663 | 18722 | return ira->codegen->invalid_inst_gen->value->type; |
| 18664 | | BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, field_value, "alignment", 4); |
| 18723 | BigInt *alignment = get_const_field_lit_int(ira, source_node, field_value, "alignment", 4); |
| 18665 | 18724 | if (alignment == nullptr) |
| 18666 | 18725 | return ira->codegen->invalid_inst_gen->value->type; |
| 18667 | 18726 | field->align = bigint_as_u32(alignment); |
| ... | ... | @@ -18673,7 +18732,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18673 | 18732 | assert(payload->special == ConstValSpecialStatic); |
| 18674 | 18733 | assert(payload->type == ir_type_info_get_type(ira, "Enum", nullptr)); |
| 18675 | 18734 | |
| 18676 | | ZigValue *layout_value = get_const_field(ira, source_instr->source_node, payload, "layout", 0); |
| 18735 | ZigValue *layout_value = get_const_field(ira, source_node, payload, "layout", 0); |
| 18677 | 18736 | if (layout_value == nullptr) |
| 18678 | 18737 | return ira->codegen->invalid_inst_gen->value->type; |
| 18679 | 18738 | |
| ... | ... | @@ -18681,16 +18740,16 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18681 | 18740 | assert(layout_value->type == ir_type_info_get_type(ira, "ContainerLayout", nullptr)); |
| 18682 | 18741 | ContainerLayout layout = (ContainerLayout)bigint_as_u32(&layout_value->data.x_enum_tag); |
| 18683 | 18742 | |
| 18684 | | ZigType *tag_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "tag_type", 1); |
| 18743 | ZigType *tag_type = get_const_field_meta_type(ira, source_node, payload, "tag_type", 1); |
| 18685 | 18744 | if (type_is_invalid(tag_type)) |
| 18686 | 18745 | return ira->codegen->invalid_inst_gen->value->type; |
| 18687 | 18746 | if (tag_type->id != ZigTypeIdInt) { |
| 18688 | | ir_add_error(ira, source_instr, buf_sprintf( |
| 18747 | ir_add_error_node(ira, source_node, buf_sprintf( |
| 18689 | 18748 | "TypeInfo.Enum.tag_type must be an integer type, not '%s'", buf_ptr(&tag_type->name))); |
| 18690 | 18749 | return ira->codegen->invalid_inst_gen->value->type; |
| 18691 | 18750 | } |
| 18692 | 18751 | |
| 18693 | | ZigValue *fields_value = get_const_field(ira, source_instr->source_node, payload, "fields", 2); |
| 18752 | ZigValue *fields_value = get_const_field(ira, source_node, payload, "fields", 2); |
| 18694 | 18753 | if (fields_value == nullptr) |
| 18695 | 18754 | return ira->codegen->invalid_inst_gen->value->type; |
| 18696 | 18755 | |
| ... | ... | @@ -18700,7 +18759,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18700 | 18759 | ZigValue *fields_len_value = fields_value->data.x_struct.fields[slice_len_index]; |
| 18701 | 18760 | size_t fields_len = bigint_as_usize(&fields_len_value->data.x_bigint); |
| 18702 | 18761 | |
| 18703 | | ZigValue *decls_value = get_const_field(ira, source_instr->source_node, payload, "decls", 3); |
| 18762 | ZigValue *decls_value = get_const_field(ira, source_node, payload, "decls", 3); |
| 18704 | 18763 | if (decls_value == nullptr) |
| 18705 | 18764 | return ira->codegen->invalid_inst_gen->value->type; |
| 18706 | 18765 | |
| ... | ... | @@ -18709,22 +18768,22 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18709 | 18768 | ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index]; |
| 18710 | 18769 | size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint); |
| 18711 | 18770 | if (decls_len != 0) { |
| 18712 | | ir_add_error(ira, source_instr, buf_create_from_str("TypeInfo.Enum.decls must be empty for @Type")); |
| 18771 | ir_add_error_node(ira, source_node, buf_create_from_str("TypeInfo.Enum.decls must be empty for @Type")); |
| 18713 | 18772 | return ira->codegen->invalid_inst_gen->value->type; |
| 18714 | 18773 | } |
| 18715 | 18774 | |
| 18716 | 18775 | Error err; |
| 18717 | 18776 | bool is_exhaustive; |
| 18718 | | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_exhaustive", 4, &is_exhaustive))) |
| 18777 | if ((err = get_const_field_bool(ira, source_node, payload, "is_exhaustive", 4, &is_exhaustive))) |
| 18719 | 18778 | return ira->codegen->invalid_inst_gen->value->type; |
| 18720 | 18779 | |
| 18721 | 18780 | ZigType *entry = new_type_table_entry(ZigTypeIdEnum); |
| 18722 | 18781 | buf_init_from_buf(&entry->name, |
| 18723 | | get_anon_type_name(ira->codegen, ira->zir, "enum", source_instr->scope, source_instr->source_node, &entry->name)); |
| 18724 | | entry->data.enumeration.decl_node = source_instr->source_node; |
| 18782 | get_anon_type_name(ira->codegen, ira->zir, "enum", scope, source_node, &entry->name)); |
| 18783 | entry->data.enumeration.decl_node = source_node; |
| 18725 | 18784 | entry->data.enumeration.tag_int_type = tag_type; |
| 18726 | 18785 | entry->data.enumeration.decls_scope = create_decls_scope( |
| 18727 | | ira->codegen, source_instr->source_node, source_instr->scope, entry, get_scope_import(source_instr->scope), &entry->name); |
| 18786 | ira->codegen, source_node, scope, entry, get_scope_import(scope), &entry->name); |
| 18728 | 18787 | entry->data.enumeration.fields = heap::c_allocator.allocate<TypeEnumField>(fields_len); |
| 18729 | 18788 | entry->data.enumeration.fields_by_name.init(fields_len); |
| 18730 | 18789 | entry->data.enumeration.src_field_count = fields_len; |
| ... | ... | @@ -18741,15 +18800,15 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18741 | 18800 | assert(field_value->type == ir_type_info_get_type(ira, "EnumField", nullptr)); |
| 18742 | 18801 | TypeEnumField *field = &entry->data.enumeration.fields[i]; |
| 18743 | 18802 | field->name = buf_alloc(); |
| 18744 | | if ((err = get_const_field_buf(ira, source_instr->source_node, field_value, "name", 0, field->name))) |
| 18803 | if ((err = get_const_field_buf(ira, source_node, field_value, "name", 0, field->name))) |
| 18745 | 18804 | return ira->codegen->invalid_inst_gen->value->type; |
| 18746 | 18805 | field->decl_index = i; |
| 18747 | | field->decl_node = source_instr->source_node; |
| 18806 | field->decl_node = source_node; |
| 18748 | 18807 | if (entry->data.enumeration.fields_by_name.put_unique(field->name, field) != nullptr) { |
| 18749 | | ir_add_error(ira, source_instr, buf_sprintf("duplicate enum field '%s'", buf_ptr(field->name))); |
| 18808 | ir_add_error_node(ira, source_node, buf_sprintf("duplicate enum field '%s'", buf_ptr(field->name))); |
| 18750 | 18809 | return ira->codegen->invalid_inst_gen->value->type; |
| 18751 | 18810 | } |
| 18752 | | BigInt *field_int_value = get_const_field_lit_int(ira, source_instr->source_node, field_value, "value", 1); |
| 18811 | BigInt *field_int_value = get_const_field_lit_int(ira, source_node, field_value, "value", 1); |
| 18753 | 18812 | if (field_int_value == nullptr) |
| 18754 | 18813 | return ira->codegen->invalid_inst_gen->value->type; |
| 18755 | 18814 | field->value = *field_int_value; |
| ... | ... | @@ -18760,24 +18819,24 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18760 | 18819 | assert(payload->special == ConstValSpecialStatic); |
| 18761 | 18820 | assert(payload->type == ir_type_info_get_type(ira, "Union", nullptr)); |
| 18762 | 18821 | |
| 18763 | | ZigValue *layout_value = get_const_field(ira, source_instr->source_node, payload, "layout", 0); |
| 18822 | ZigValue *layout_value = get_const_field(ira, source_node, payload, "layout", 0); |
| 18764 | 18823 | if (layout_value == nullptr) |
| 18765 | 18824 | return ira->codegen->invalid_inst_gen->value->type; |
| 18766 | 18825 | assert(layout_value->special == ConstValSpecialStatic); |
| 18767 | 18826 | assert(layout_value->type == ir_type_info_get_type(ira, "ContainerLayout", nullptr)); |
| 18768 | 18827 | ContainerLayout layout = (ContainerLayout)bigint_as_u32(&layout_value->data.x_enum_tag); |
| 18769 | 18828 | |
| 18770 | | ZigType *tag_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "tag_type", 1); |
| 18829 | ZigType *tag_type = get_const_field_meta_type_optional(ira, source_node, payload, "tag_type", 1); |
| 18771 | 18830 | if (tag_type != nullptr && type_is_invalid(tag_type)) { |
| 18772 | 18831 | return ira->codegen->invalid_inst_gen->value->type; |
| 18773 | 18832 | } |
| 18774 | 18833 | if (tag_type != nullptr && tag_type->id != ZigTypeIdEnum) { |
| 18775 | | ir_add_error(ira, source_instr, buf_sprintf( |
| 18834 | ir_add_error_node(ira, source_node, buf_sprintf( |
| 18776 | 18835 | "expected enum type, found '%s'", type_id_name(tag_type->id))); |
| 18777 | 18836 | return ira->codegen->invalid_inst_gen->value->type; |
| 18778 | 18837 | } |
| 18779 | 18838 | |
| 18780 | | ZigValue *fields_value = get_const_field(ira, source_instr->source_node, payload, "fields", 2); |
| 18839 | ZigValue *fields_value = get_const_field(ira, source_node, payload, "fields", 2); |
| 18781 | 18840 | if (fields_value == nullptr) |
| 18782 | 18841 | return ira->codegen->invalid_inst_gen->value->type; |
| 18783 | 18842 | |
| ... | ... | @@ -18787,7 +18846,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18787 | 18846 | ZigValue *fields_len_value = fields_value->data.x_struct.fields[slice_len_index]; |
| 18788 | 18847 | size_t fields_len = bigint_as_usize(&fields_len_value->data.x_bigint); |
| 18789 | 18848 | |
| 18790 | | ZigValue *decls_value = get_const_field(ira, source_instr->source_node, payload, "decls", 3); |
| 18849 | ZigValue *decls_value = get_const_field(ira, source_node, payload, "decls", 3); |
| 18791 | 18850 | if (decls_value == nullptr) |
| 18792 | 18851 | return ira->codegen->invalid_inst_gen->value->type; |
| 18793 | 18852 | |
| ... | ... | @@ -18796,18 +18855,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18796 | 18855 | ZigValue *decls_len_value = decls_value->data.x_struct.fields[slice_len_index]; |
| 18797 | 18856 | size_t decls_len = bigint_as_usize(&decls_len_value->data.x_bigint); |
| 18798 | 18857 | if (decls_len != 0) { |
| 18799 | | ir_add_error(ira, source_instr, buf_create_from_str("TypeInfo.Union.decls must be empty for @Type")); |
| 18858 | ir_add_error_node(ira, source_node, buf_create_from_str("TypeInfo.Union.decls must be empty for @Type")); |
| 18800 | 18859 | return ira->codegen->invalid_inst_gen->value->type; |
| 18801 | 18860 | } |
| 18802 | 18861 | |
| 18803 | 18862 | ZigType *entry = new_type_table_entry(ZigTypeIdUnion); |
| 18804 | 18863 | buf_init_from_buf(&entry->name, |
| 18805 | | get_anon_type_name(ira->codegen, ira->zir, "union", source_instr->scope, source_instr->source_node, &entry->name)); |
| 18806 | | entry->data.unionation.decl_node = source_instr->source_node; |
| 18864 | get_anon_type_name(ira->codegen, ira->zir, "union", scope, source_node, &entry->name)); |
| 18865 | entry->data.unionation.decl_node = source_node; |
| 18807 | 18866 | entry->data.unionation.fields = heap::c_allocator.allocate<TypeUnionField>(fields_len); |
| 18808 | 18867 | entry->data.unionation.fields_by_name.init(fields_len); |
| 18809 | 18868 | entry->data.unionation.decls_scope = create_decls_scope( |
| 18810 | | ira->codegen, source_instr->source_node, source_instr->scope, entry, get_scope_import(source_instr->scope), &entry->name); |
| 18869 | ira->codegen, source_node, scope, entry, get_scope_import(scope), &entry->name); |
| 18811 | 18870 | entry->data.unionation.tag_type = tag_type; |
| 18812 | 18871 | entry->data.unionation.src_field_count = fields_len; |
| 18813 | 18872 | entry->data.unionation.layout = layout; |
| ... | ... | @@ -18822,19 +18881,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18822 | 18881 | assert(field_value->type == ir_type_info_get_type(ira, "UnionField", nullptr)); |
| 18823 | 18882 | TypeUnionField *field = &entry->data.unionation.fields[i]; |
| 18824 | 18883 | field->name = buf_alloc(); |
| 18825 | | if ((err = get_const_field_buf(ira, source_instr->source_node, field_value, "name", 0, field->name))) |
| 18884 | if ((err = get_const_field_buf(ira, source_node, field_value, "name", 0, field->name))) |
| 18826 | 18885 | return ira->codegen->invalid_inst_gen->value->type; |
| 18827 | 18886 | if (entry->data.unionation.fields_by_name.put_unique(field->name, field) != nullptr) { |
| 18828 | | ir_add_error(ira, source_instr, buf_sprintf("duplicate union field '%s'", buf_ptr(field->name))); |
| 18887 | ir_add_error_node(ira, source_node, buf_sprintf("duplicate union field '%s'", buf_ptr(field->name))); |
| 18829 | 18888 | return ira->codegen->invalid_inst_gen->value->type; |
| 18830 | 18889 | } |
| 18831 | | field->decl_node = source_instr->source_node; |
| 18832 | | ZigValue *type_value = get_const_field(ira, source_instr->source_node, field_value, "field_type", 1); |
| 18890 | field->decl_node = source_node; |
| 18891 | ZigValue *type_value = get_const_field(ira, source_node, field_value, "field_type", 1); |
| 18833 | 18892 | if (type_value == nullptr) |
| 18834 | 18893 | return ira->codegen->invalid_inst_gen->value->type; |
| 18835 | 18894 | field->type_val = type_value; |
| 18836 | 18895 | field->type_entry = type_value->data.x_type; |
| 18837 | | BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, field_value, "alignment", 2); |
| 18896 | BigInt *alignment = get_const_field_lit_int(ira, source_node, field_value, "alignment", 2); |
| 18838 | 18897 | if (alignment == nullptr) |
| 18839 | 18898 | return ira->codegen->invalid_inst_gen->value->type; |
| 18840 | 18899 | field->align = bigint_as_u32(alignment); |
| ... | ... | @@ -18846,41 +18905,41 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18846 | 18905 | assert(payload->special == ConstValSpecialStatic); |
| 18847 | 18906 | assert(payload->type == ir_type_info_get_type(ira, "Fn", nullptr)); |
| 18848 | 18907 | |
| 18849 | | ZigValue *cc_value = get_const_field(ira, source_instr->source_node, payload, "calling_convention", 0); |
| 18908 | ZigValue *cc_value = get_const_field(ira, source_node, payload, "calling_convention", 0); |
| 18850 | 18909 | if (cc_value == nullptr) |
| 18851 | 18910 | return ira->codegen->invalid_inst_gen->value->type; |
| 18852 | 18911 | assert(cc_value->special == ConstValSpecialStatic); |
| 18853 | 18912 | assert(cc_value->type == get_builtin_type(ira->codegen, "CallingConvention")); |
| 18854 | 18913 | CallingConvention cc = (CallingConvention)bigint_as_u32(&cc_value->data.x_enum_tag); |
| 18855 | 18914 | |
| 18856 | | BigInt *alignment = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 1); |
| 18915 | BigInt *alignment = get_const_field_lit_int(ira, source_node, payload, "alignment", 1); |
| 18857 | 18916 | if (alignment == nullptr) |
| 18858 | 18917 | return ira->codegen->invalid_inst_gen->value->type; |
| 18859 | 18918 | |
| 18860 | 18919 | Error err; |
| 18861 | 18920 | bool is_generic; |
| 18862 | | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_generic", 2, &is_generic))) |
| 18921 | if ((err = get_const_field_bool(ira, source_node, payload, "is_generic", 2, &is_generic))) |
| 18863 | 18922 | return ira->codegen->invalid_inst_gen->value->type; |
| 18864 | 18923 | if (is_generic) { |
| 18865 | | ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.Fn.is_generic must be false for @Type")); |
| 18924 | ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.Fn.is_generic must be false for @Type")); |
| 18866 | 18925 | return ira->codegen->invalid_inst_gen->value->type; |
| 18867 | 18926 | } |
| 18868 | 18927 | |
| 18869 | 18928 | bool is_var_args; |
| 18870 | | if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_var_args", 3, &is_var_args))) |
| 18929 | if ((err = get_const_field_bool(ira, source_node, payload, "is_var_args", 3, &is_var_args))) |
| 18871 | 18930 | return ira->codegen->invalid_inst_gen->value->type; |
| 18872 | 18931 | if (is_var_args && cc != CallingConventionC) { |
| 18873 | | ir_add_error(ira, source_instr, buf_sprintf("varargs functions must have C calling convention")); |
| 18932 | ir_add_error_node(ira, source_node, buf_sprintf("varargs functions must have C calling convention")); |
| 18874 | 18933 | return ira->codegen->invalid_inst_gen->value->type; |
| 18875 | 18934 | } |
| 18876 | 18935 | |
| 18877 | | ZigType *return_type = get_const_field_meta_type_optional(ira, source_instr->source_node, payload, "return_type", 4); |
| 18936 | ZigType *return_type = get_const_field_meta_type_optional(ira, source_node, payload, "return_type", 4); |
| 18878 | 18937 | if (return_type == nullptr) { |
| 18879 | | ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.Fn.return_type must be non-null for @Type")); |
| 18938 | ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.Fn.return_type must be non-null for @Type")); |
| 18880 | 18939 | return ira->codegen->invalid_inst_gen->value->type; |
| 18881 | 18940 | } |
| 18882 | 18941 | |
| 18883 | | ZigValue *args_value = get_const_field(ira, source_instr->source_node, payload, "args", 5); |
| 18942 | ZigValue *args_value = get_const_field(ira, source_node, payload, "args", 5); |
| 18884 | 18943 | if (args_value == nullptr) |
| 18885 | 18944 | return ira->codegen->invalid_inst_gen->value->type; |
| 18886 | 18945 | assert(args_value->special == ConstValSpecialStatic); |
| ... | ... | @@ -18909,18 +18968,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 18909 | 18968 | FnTypeParamInfo *info = &fn_type_id.param_info[i]; |
| 18910 | 18969 | Error err; |
| 18911 | 18970 | bool is_generic; |
| 18912 | | if ((err = get_const_field_bool(ira, source_instr->source_node, arg_value, "is_generic", 0, &is_generic))) |
| 18971 | if ((err = get_const_field_bool(ira, source_node, arg_value, "is_generic", 0, &is_generic))) |
| 18913 | 18972 | return ira->codegen->invalid_inst_gen->value->type; |
| 18914 | 18973 | if (is_generic) { |
| 18915 | | ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.FnArg.is_generic must be false for @Type")); |
| 18974 | ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.FnArg.is_generic must be false for @Type")); |
| 18916 | 18975 | return ira->codegen->invalid_inst_gen->value->type; |
| 18917 | 18976 | } |
| 18918 | | if ((err = get_const_field_bool(ira, source_instr->source_node, arg_value, "is_noalias", 1, &info->is_noalias))) |
| 18977 | if ((err = get_const_field_bool(ira, source_node, arg_value, "is_noalias", 1, &info->is_noalias))) |
| 18919 | 18978 | return ira->codegen->invalid_inst_gen->value->type; |
| 18920 | 18979 | ZigType *type = get_const_field_meta_type_optional( |
| 18921 | | ira, source_instr->source_node, arg_value, "arg_type", 2); |
| 18980 | ira, source_node, arg_value, "arg_type", 2); |
| 18922 | 18981 | if (type == nullptr) { |
| 18923 | | ir_add_error(ira, source_instr, buf_sprintf("TypeInfo.FnArg.arg_type must be non-null for @Type")); |
| 18982 | ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.FnArg.arg_type must be non-null for @Type")); |
| 18924 | 18983 | return ira->codegen->invalid_inst_gen->value->type; |
| 18925 | 18984 | } |
| 18926 | 18985 | info->type = type; |
| ... | ... | @@ -18958,11 +19017,11 @@ static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *ins |
| 18958 | 19017 | if (type_info_val == nullptr) |
| 18959 | 19018 | return ira->codegen->invalid_inst_gen; |
| 18960 | 19019 | ZigTypeId type_id_tag = type_id_at_index(bigint_as_usize(&type_info_val->data.x_union.tag)); |
| 18961 | | ZigType *type = type_info_to_type(ira, &uncasted_type_info->base, type_id_tag, |
| 18962 | | type_info_val->data.x_union.payload); |
| 19020 | ZigType *type = type_info_to_type(ira, uncasted_type_info->scope, |
| 19021 | uncasted_type_info->source_node, type_id_tag, type_info_val->data.x_union.payload); |
| 18963 | 19022 | if (type_is_invalid(type)) |
| 18964 | 19023 | return ira->codegen->invalid_inst_gen; |
| 18965 | | return ir_const_type(ira, &instruction->base.base, type); |
| 19024 | return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, type); |
| 18966 | 19025 | } |
| 18967 | 19026 | |
| 18968 | 19027 | static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira, |
| ... | ... | @@ -18976,7 +19035,7 @@ static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira, |
| 18976 | 19035 | *ira->backward_branch_quota = new_quota; |
| 18977 | 19036 | } |
| 18978 | 19037 | |
| 18979 | | return ir_const_void(ira, &instruction->base.base); |
| 19038 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 18980 | 19039 | } |
| 18981 | 19040 | |
| 18982 | 19041 | static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcTypeName *instruction) { |
| ... | ... | @@ -18988,18 +19047,18 @@ static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcType |
| 18988 | 19047 | if (!type_entry->cached_const_name_val) { |
| 18989 | 19048 | type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry)); |
| 18990 | 19049 | } |
| 18991 | | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 19050 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr); |
| 18992 | 19051 | copy_const_val(ira->codegen, result->value, type_entry->cached_const_name_val); |
| 18993 | 19052 | return result; |
| 18994 | 19053 | } |
| 18995 | 19054 | |
| 18996 | 19055 | static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImport *instruction) { |
| 18997 | 19056 | Error err; |
| 18998 | | AstNode *node = instruction->base.base.source_node; |
| 19057 | AstNode *node = instruction->base.source_node; |
| 18999 | 19058 | assert(node->type == NodeTypeFnCallExpr); |
| 19000 | 19059 | AstNode *block_node = node->data.fn_call_expr.params.at(0); |
| 19001 | 19060 | |
| 19002 | | ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.base.scope); |
| 19061 | ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.scope); |
| 19003 | 19062 | |
| 19004 | 19063 | // Execute the C import block like an inline function |
| 19005 | 19064 | ZigType *void_type = ira->codegen->builtin_types.entry_void; |
| ... | ... | @@ -19015,7 +19074,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo |
| 19015 | 19074 | if (type_is_invalid(cimport_result->type)) |
| 19016 | 19075 | return ira->codegen->invalid_inst_gen; |
| 19017 | 19076 | |
| 19018 | | ZigPackage *cur_scope_pkg = scope_package(instruction->base.base.scope); |
| 19077 | ZigPackage *cur_scope_pkg = scope_package(instruction->base.scope); |
| 19019 | 19078 | RootStruct *root_struct = node->owner->data.structure.root_struct; |
| 19020 | 19079 | TokenLoc tok_loc = root_struct->token_locs[node->main_token]; |
| 19021 | 19080 | Buf *namespace_name = buf_sprintf("%s.cimport:%" PRIu32 ":%" PRIu32, |
| ... | ... | @@ -19072,7 +19131,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo |
| 19072 | 19131 | } |
| 19073 | 19132 | ZigType *child_import = add_source_file(ira->codegen, cimport_pkg, out_zig_path, |
| 19074 | 19133 | import_code, SourceKindCImport); |
| 19075 | | return ir_const_type(ira, &instruction->base.base, child_import); |
| 19134 | return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, child_import); |
| 19076 | 19135 | } |
| 19077 | 19136 | |
| 19078 | 19137 | static IrInstGen *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstSrcCInclude *instruction) { |
| ... | ... | @@ -19090,7 +19149,7 @@ static IrInstGen *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstSrcCInc |
| 19090 | 19149 | |
| 19091 | 19150 | buf_appendf(c_import_buf, "#include <%s>\n", buf_ptr(include_name)); |
| 19092 | 19151 | |
| 19093 | | return ir_const_void(ira, &instruction->base.base); |
| 19152 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 19094 | 19153 | } |
| 19095 | 19154 | |
| 19096 | 19155 | static IrInstGen *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstSrcCDefine *instruction) { |
| ... | ... | @@ -19121,7 +19180,7 @@ static IrInstGen *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstSrcCDefi |
| 19121 | 19180 | buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name), |
| 19122 | 19181 | define_value ? buf_ptr(define_value) : ""); |
| 19123 | 19182 | |
| 19124 | | return ir_const_void(ira, &instruction->base.base); |
| 19183 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 19125 | 19184 | } |
| 19126 | 19185 | |
| 19127 | 19186 | static IrInstGen *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstSrcCUndef *instruction) { |
| ... | ... | @@ -19139,7 +19198,7 @@ static IrInstGen *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstSrcCUndef |
| 19139 | 19198 | |
| 19140 | 19199 | buf_appendf(c_import_buf, "#undef %s\n", buf_ptr(undef_name)); |
| 19141 | 19200 | |
| 19142 | | return ir_const_void(ira, &instruction->base.base); |
| 19201 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 19143 | 19202 | } |
| 19144 | 19203 | |
| 19145 | 19204 | static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmbedFile *instruction) { |
| ... | ... | @@ -19151,7 +19210,7 @@ static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmb |
| 19151 | 19210 | if (!rel_file_path) |
| 19152 | 19211 | return ira->codegen->invalid_inst_gen; |
| 19153 | 19212 | |
| 19154 | | ZigType *import = get_scope_import(instruction->base.base.scope); |
| 19213 | ZigType *import = get_scope_import(instruction->base.scope); |
| 19155 | 19214 | // figure out absolute path to resource |
| 19156 | 19215 | Buf source_dir_path = BUF_INIT; |
| 19157 | 19216 | os_path_dirname(import->data.structure.root_struct->path, &source_dir_path); |
| ... | ... | @@ -19168,17 +19227,17 @@ static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmb |
| 19168 | 19227 | Error err; |
| 19169 | 19228 | if ((err = file_fetch(ira->codegen, file_path, file_contents))) { |
| 19170 | 19229 | if (err == ErrorFileNotFound) { |
| 19171 | | ir_add_error(ira, &instruction->name->base, |
| 19230 | ir_add_error_node(ira, instruction->name->source_node, |
| 19172 | 19231 | buf_sprintf("unable to find '%s'", buf_ptr(file_path))); |
| 19173 | 19232 | return ira->codegen->invalid_inst_gen; |
| 19174 | 19233 | } else { |
| 19175 | | ir_add_error(ira, &instruction->name->base, |
| 19234 | ir_add_error_node(ira, instruction->name->source_node, |
| 19176 | 19235 | buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err))); |
| 19177 | 19236 | return ira->codegen->invalid_inst_gen; |
| 19178 | 19237 | } |
| 19179 | 19238 | } |
| 19180 | 19239 | |
| 19181 | | IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr); |
| 19240 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, nullptr); |
| 19182 | 19241 | init_const_str_lit(ira->codegen, result->value, file_contents, true); |
| 19183 | 19242 | return result; |
| 19184 | 19243 | } |
| ... | ... | @@ -19189,7 +19248,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch |
| 19189 | 19248 | return ira->codegen->invalid_inst_gen; |
| 19190 | 19249 | |
| 19191 | 19250 | if (operand_type->id == ZigTypeIdFloat) { |
| 19192 | | ir_add_error(ira, &instruction->type_value->child->base, |
| 19251 | ir_add_error(ira, instruction->type_value->child, |
| 19193 | 19252 | buf_sprintf("expected bool, integer, enum or pointer type, found '%s'", buf_ptr(&operand_type->name))); |
| 19194 | 19253 | return ira->codegen->invalid_inst_gen; |
| 19195 | 19254 | } |
| ... | ... | @@ -19200,7 +19259,8 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch |
| 19200 | 19259 | |
| 19201 | 19260 | // TODO let this be volatile |
| 19202 | 19261 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 19203 | | IrInstGen *casted_ptr = ir_implicit_cast2(ira, &instruction->ptr->base, ptr, ptr_type); |
| 19262 | IrInstGen *casted_ptr = ir_implicit_cast2(ira, instruction->ptr->scope, |
| 19263 | instruction->ptr->source_node, ptr, ptr_type); |
| 19204 | 19264 | if (type_is_invalid(casted_ptr->value->type)) |
| 19205 | 19265 | return ira->codegen->invalid_inst_gen; |
| 19206 | 19266 | |
| ... | ... | @@ -19228,31 +19288,33 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch |
| 19228 | 19288 | if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order)) |
| 19229 | 19289 | return ira->codegen->invalid_inst_gen; |
| 19230 | 19290 | |
| 19231 | | IrInstGen *casted_cmp_value = ir_implicit_cast2(ira, &instruction->cmp_value->base, cmp_value, operand_type); |
| 19291 | IrInstGen *casted_cmp_value = ir_implicit_cast2(ira, instruction->cmp_value->scope, |
| 19292 | instruction->cmp_value->source_node, cmp_value, operand_type); |
| 19232 | 19293 | if (type_is_invalid(casted_cmp_value->value->type)) |
| 19233 | 19294 | return ira->codegen->invalid_inst_gen; |
| 19234 | 19295 | |
| 19235 | | IrInstGen *casted_new_value = ir_implicit_cast2(ira, &instruction->new_value->base, new_value, operand_type); |
| 19296 | IrInstGen *casted_new_value = ir_implicit_cast2(ira, instruction->new_value->scope, |
| 19297 | instruction->new_value->source_node, new_value, operand_type); |
| 19236 | 19298 | if (type_is_invalid(casted_new_value->value->type)) |
| 19237 | 19299 | return ira->codegen->invalid_inst_gen; |
| 19238 | 19300 | |
| 19239 | 19301 | if (success_order < AtomicOrderMonotonic) { |
| 19240 | | ir_add_error(ira, &success_order_value->base, |
| 19302 | ir_add_error(ira, success_order_value, |
| 19241 | 19303 | buf_sprintf("success atomic ordering must be Monotonic or stricter")); |
| 19242 | 19304 | return ira->codegen->invalid_inst_gen; |
| 19243 | 19305 | } |
| 19244 | 19306 | if (failure_order < AtomicOrderMonotonic) { |
| 19245 | | ir_add_error(ira, &failure_order_value->base, |
| 19307 | ir_add_error(ira, failure_order_value, |
| 19246 | 19308 | buf_sprintf("failure atomic ordering must be Monotonic or stricter")); |
| 19247 | 19309 | return ira->codegen->invalid_inst_gen; |
| 19248 | 19310 | } |
| 19249 | 19311 | if (failure_order > success_order) { |
| 19250 | | ir_add_error(ira, &failure_order_value->base, |
| 19312 | ir_add_error(ira, failure_order_value, |
| 19251 | 19313 | buf_sprintf("failure atomic ordering must be no stricter than success")); |
| 19252 | 19314 | return ira->codegen->invalid_inst_gen; |
| 19253 | 19315 | } |
| 19254 | 19316 | if (failure_order == AtomicOrderRelease || failure_order == AtomicOrderAcqRel) { |
| 19255 | | ir_add_error(ira, &failure_order_value->base, |
| 19317 | ir_add_error(ira, failure_order_value, |
| 19256 | 19318 | buf_sprintf("failure atomic ordering must not be Release or AcqRel")); |
| 19257 | 19319 | return ira->codegen->invalid_inst_gen; |
| 19258 | 19320 | } |
| ... | ... | @@ -19264,7 +19326,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch |
| 19264 | 19326 | case OnePossibleValueInvalid: |
| 19265 | 19327 | return ira->codegen->invalid_inst_gen; |
| 19266 | 19328 | case OnePossibleValueYes: { |
| 19267 | | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 19329 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type); |
| 19268 | 19330 | set_optional_value_to_null(result->value); |
| 19269 | 19331 | return result; |
| 19270 | 19332 | } |
| ... | ... | @@ -19278,7 +19340,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch |
| 19278 | 19340 | if (ptr_val == nullptr) |
| 19279 | 19341 | return ira->codegen->invalid_inst_gen; |
| 19280 | 19342 | |
| 19281 | | ZigValue *stored_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.base.source_node); |
| 19343 | ZigValue *stored_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.source_node); |
| 19282 | 19344 | if (stored_val == nullptr) |
| 19283 | 19345 | return ira->codegen->invalid_inst_gen; |
| 19284 | 19346 | |
| ... | ... | @@ -19291,7 +19353,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch |
| 19291 | 19353 | return ira->codegen->invalid_inst_gen; |
| 19292 | 19354 | |
| 19293 | 19355 | bool eql = const_values_equal(ira->codegen, stored_val, expected_val); |
| 19294 | | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 19356 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, result_type); |
| 19295 | 19357 | if (eql) { |
| 19296 | 19358 | copy_const_val(ira->codegen, stored_val, new_val); |
| 19297 | 19359 | set_optional_value_to_null(result->value); |
| ... | ... | @@ -19303,7 +19365,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch |
| 19303 | 19365 | |
| 19304 | 19366 | IrInstGen *result_loc; |
| 19305 | 19367 | if (handle_is_ptr(ira->codegen, result_type)) { |
| 19306 | | result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 19368 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 19307 | 19369 | result_type, nullptr, true, true); |
| 19308 | 19370 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 19309 | 19371 | return result_loc; |
| ... | ... | @@ -19312,12 +19374,12 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch |
| 19312 | 19374 | result_loc = nullptr; |
| 19313 | 19375 | } |
| 19314 | 19376 | |
| 19315 | | return ir_build_cmpxchg_gen(ira, &instruction->base.base, result_type, |
| 19377 | return ir_build_cmpxchg_gen(ira, instruction->base.scope, instruction->base.source_node, result_type, |
| 19316 | 19378 | casted_ptr, casted_cmp_value, casted_new_value, |
| 19317 | 19379 | success_order, failure_order, instruction->is_weak, result_loc); |
| 19318 | 19380 | } |
| 19319 | 19381 | |
| 19320 | | static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp op, ZigValue *value, ZigValue *out_value) { |
| 19382 | static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, Scope *scope, AstNode *source_node, ReduceOp op, ZigValue *value, ZigValue *out_value) { |
| 19321 | 19383 | assert(value->type->id == ZigTypeIdVector); |
| 19322 | 19384 | ZigType *scalar_type = value->type->data.vector.elem_type; |
| 19323 | 19385 | const size_t len = value->type->data.vector.len; |
| ... | ... | @@ -19371,7 +19433,7 @@ static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp o |
| 19371 | 19433 | default: zig_unreachable(); |
| 19372 | 19434 | } |
| 19373 | 19435 | |
| 19374 | | ErrorMsg *msg = ir_eval_math_op_scalar(ira, source_instr, scalar_type, |
| 19436 | ErrorMsg *msg = ir_eval_math_op_scalar(ira, scope, source_node, scalar_type, |
| 19375 | 19437 | out_value, bin_op, elem_val, out_value); |
| 19376 | 19438 | if (msg != nullptr) |
| 19377 | 19439 | return msg; |
| ... | ... | @@ -19407,7 +19469,7 @@ static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp o |
| 19407 | 19469 | default: zig_unreachable(); |
| 19408 | 19470 | } |
| 19409 | 19471 | |
| 19410 | | ErrorMsg *msg = ir_eval_math_op_scalar(ira, source_instr, scalar_type, |
| 19472 | ErrorMsg *msg = ir_eval_math_op_scalar(ira, scope, source_node, scalar_type, |
| 19411 | 19473 | out_value, bin_op, elem_val, out_value); |
| 19412 | 19474 | if (msg != nullptr) |
| 19413 | 19475 | return msg; |
| ... | ... | @@ -19430,7 +19492,7 @@ static ErrorMsg *ir_eval_reduce(IrAnalyze *ira, IrInst *source_instr, ReduceOp o |
| 19430 | 19492 | default: zig_unreachable(); |
| 19431 | 19493 | } |
| 19432 | 19494 | |
| 19433 | | ErrorMsg *msg = ir_eval_bin_op_cmp_scalar(ira, source_instr, |
| 19495 | ErrorMsg *msg = ir_eval_bin_op_cmp_scalar(ira, scope, source_node, |
| 19434 | 19496 | elem_val, bin_op, candidate_elem_val, dummy_cmp_value); |
| 19435 | 19497 | if (msg != nullptr) |
| 19436 | 19498 | return msg; |
| ... | ... | @@ -19456,7 +19518,7 @@ static IrInstGen *ir_analyze_instruction_reduce(IrAnalyze *ira, IrInstSrcReduce |
| 19456 | 19518 | |
| 19457 | 19519 | ZigType *value_type = value_inst->value->type; |
| 19458 | 19520 | if (value_type->id != ZigTypeIdVector) { |
| 19459 | | ir_add_error(ira, &value_inst->base, |
| 19521 | ir_add_error(ira, value_inst, |
| 19460 | 19522 | buf_sprintf("expected vector type, found '%s'", |
| 19461 | 19523 | buf_ptr(&value_type->name))); |
| 19462 | 19524 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -19472,14 +19534,14 @@ static IrInstGen *ir_analyze_instruction_reduce(IrAnalyze *ira, IrInstSrcReduce |
| 19472 | 19534 | break; |
| 19473 | 19535 | case ZigTypeIdBool: |
| 19474 | 19536 | if (op > ReduceOp_xor) { |
| 19475 | | ir_add_error(ira, &op_inst->base, |
| 19537 | ir_add_error(ira, op_inst, |
| 19476 | 19538 | buf_sprintf("invalid operation for '%s' type", |
| 19477 | 19539 | buf_ptr(&elem_type->name))); |
| 19478 | 19540 | return ira->codegen->invalid_inst_gen; |
| 19479 | 19541 | } break; |
| 19480 | 19542 | case ZigTypeIdFloat: |
| 19481 | 19543 | if (op < ReduceOp_min) { |
| 19482 | | ir_add_error(ira, &op_inst->base, |
| 19544 | ir_add_error(ira, op_inst, |
| 19483 | 19545 | buf_sprintf("invalid operation for '%s' type", |
| 19484 | 19546 | buf_ptr(&elem_type->name))); |
| 19485 | 19547 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -19494,20 +19556,20 @@ static IrInstGen *ir_analyze_instruction_reduce(IrAnalyze *ira, IrInstSrcReduce |
| 19494 | 19556 | case OnePossibleValueInvalid: |
| 19495 | 19557 | return ira->codegen->invalid_inst_gen; |
| 19496 | 19558 | case OnePossibleValueYes: |
| 19497 | | return ir_const_move(ira, &instruction->base.base, |
| 19559 | return ir_const_move(ira, instruction->base.scope, instruction->base.source_node, |
| 19498 | 19560 | get_the_one_possible_value(ira->codegen, elem_type)); |
| 19499 | 19561 | case OnePossibleValueNo: |
| 19500 | 19562 | break; |
| 19501 | 19563 | } |
| 19502 | 19564 | |
| 19503 | 19565 | if (instr_is_comptime(value_inst)) { |
| 19504 | | IrInstGen *result = ir_const(ira, &instruction->base.base, elem_type); |
| 19505 | | if (ir_eval_reduce(ira, &instruction->base.base, op, value_inst->value, result->value)) |
| 19566 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, elem_type); |
| 19567 | if (ir_eval_reduce(ira, instruction->base.scope, instruction->base.source_node, op, value_inst->value, result->value)) |
| 19506 | 19568 | return ira->codegen->invalid_inst_gen; |
| 19507 | 19569 | return result; |
| 19508 | 19570 | } |
| 19509 | 19571 | |
| 19510 | | return ir_build_reduce_gen(ira, &instruction->base.base, op, value_inst, elem_type); |
| 19572 | return ir_build_reduce_gen(ira, instruction->base.scope, instruction->base.source_node, op, value_inst, elem_type); |
| 19511 | 19573 | } |
| 19512 | 19574 | |
| 19513 | 19575 | static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *instruction) { |
| ... | ... | @@ -19520,12 +19582,12 @@ static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *i |
| 19520 | 19582 | return ira->codegen->invalid_inst_gen; |
| 19521 | 19583 | |
| 19522 | 19584 | if (order < AtomicOrderAcquire) { |
| 19523 | | ir_add_error(ira, &order_inst->base, |
| 19585 | ir_add_error(ira, order_inst, |
| 19524 | 19586 | buf_sprintf("atomic ordering must be Acquire or stricter")); |
| 19525 | 19587 | return ira->codegen->invalid_inst_gen; |
| 19526 | 19588 | } |
| 19527 | 19589 | |
| 19528 | | return ir_build_fence_gen(ira, &instruction->base.base, order); |
| 19590 | return ir_build_fence_gen(ira, instruction->base.scope, instruction->base.source_node, order); |
| 19529 | 19591 | } |
| 19530 | 19592 | |
| 19531 | 19593 | static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTruncate *instruction) { |
| ... | ... | @@ -19537,7 +19599,7 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc |
| 19537 | 19599 | if (dest_type->id != ZigTypeIdInt && |
| 19538 | 19600 | dest_type->id != ZigTypeIdComptimeInt) |
| 19539 | 19601 | { |
| 19540 | | ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 19602 | ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 19541 | 19603 | return ira->codegen->invalid_inst_gen; |
| 19542 | 19604 | } |
| 19543 | 19605 | |
| ... | ... | @@ -19549,21 +19611,21 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc |
| 19549 | 19611 | if (src_type->id != ZigTypeIdInt && |
| 19550 | 19612 | src_type->id != ZigTypeIdComptimeInt) |
| 19551 | 19613 | { |
| 19552 | | ir_add_error(ira, &target->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name))); |
| 19614 | ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name))); |
| 19553 | 19615 | return ira->codegen->invalid_inst_gen; |
| 19554 | 19616 | } |
| 19555 | 19617 | |
| 19556 | 19618 | if (dest_type->id == ZigTypeIdComptimeInt) { |
| 19557 | | return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type); |
| 19619 | return ir_implicit_cast2(ira, instruction->target->scope, instruction->target->source_node, target, dest_type); |
| 19558 | 19620 | } |
| 19559 | 19621 | |
| 19560 | 19622 | if (src_type->id != ZigTypeIdComptimeInt) { |
| 19561 | 19623 | if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) { |
| 19562 | 19624 | const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned"; |
| 19563 | | ir_add_error(ira, &target->base, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name))); |
| 19625 | ir_add_error(ira, target, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name))); |
| 19564 | 19626 | return ira->codegen->invalid_inst_gen; |
| 19565 | 19627 | } else if (src_type->data.integral.bit_count > 0 && src_type->data.integral.bit_count < dest_type->data.integral.bit_count) { |
| 19566 | | ir_add_error(ira, &target->base, buf_sprintf("type '%s' has fewer bits than destination type '%s'", |
| 19628 | ir_add_error(ira, target, buf_sprintf("type '%s' has fewer bits than destination type '%s'", |
| 19567 | 19629 | buf_ptr(&src_type->name), buf_ptr(&dest_type->name))); |
| 19568 | 19630 | return ira->codegen->invalid_inst_gen; |
| 19569 | 19631 | } |
| ... | ... | @@ -19574,19 +19636,19 @@ static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTrunc |
| 19574 | 19636 | if (val == nullptr) |
| 19575 | 19637 | return ira->codegen->invalid_inst_gen; |
| 19576 | 19638 | |
| 19577 | | IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type); |
| 19639 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, dest_type); |
| 19578 | 19640 | bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint, |
| 19579 | 19641 | dest_type->data.integral.bit_count, dest_type->data.integral.is_signed); |
| 19580 | 19642 | return result; |
| 19581 | 19643 | } |
| 19582 | 19644 | |
| 19583 | 19645 | if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) { |
| 19584 | | IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type); |
| 19646 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, dest_type); |
| 19585 | 19647 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 19586 | 19648 | return result; |
| 19587 | 19649 | } |
| 19588 | 19650 | |
| 19589 | | return ir_build_truncate_gen(ira, &instruction->base.base, dest_type, target); |
| 19651 | return ir_build_truncate_gen(ira, instruction->base.scope, instruction->base.source_node, dest_type, target); |
| 19590 | 19652 | } |
| 19591 | 19653 | |
| 19592 | 19654 | static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCast *instruction) { |
| ... | ... | @@ -19598,7 +19660,7 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa |
| 19598 | 19660 | dest_type->data.vector.elem_type : dest_type; |
| 19599 | 19661 | |
| 19600 | 19662 | if (scalar_dest_type->id != ZigTypeIdInt && scalar_dest_type->id != ZigTypeIdComptimeInt) { |
| 19601 | | ir_add_error(ira, &instruction->dest_type->base, |
| 19663 | ir_add_error_node(ira, instruction->dest_type->source_node, |
| 19602 | 19664 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&scalar_dest_type->name))); |
| 19603 | 19665 | return ira->codegen->invalid_inst_gen; |
| 19604 | 19666 | } |
| ... | ... | @@ -19611,7 +19673,7 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa |
| 19611 | 19673 | target->value->type->data.vector.elem_type : target->value->type; |
| 19612 | 19674 | |
| 19613 | 19675 | if (scalar_target_type->id != ZigTypeIdInt && scalar_target_type->id != ZigTypeIdComptimeInt) { |
| 19614 | | ir_add_error(ira, &instruction->target->base, buf_sprintf("expected integer type, found '%s'", |
| 19676 | ir_add_error_node(ira, instruction->target->source_node, buf_sprintf("expected integer type, found '%s'", |
| 19615 | 19677 | buf_ptr(&scalar_target_type->name))); |
| 19616 | 19678 | return ira->codegen->invalid_inst_gen; |
| 19617 | 19679 | } |
| ... | ... | @@ -19621,10 +19683,10 @@ static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCa |
| 19621 | 19683 | if (val == nullptr) |
| 19622 | 19684 | return ira->codegen->invalid_inst_gen; |
| 19623 | 19685 | |
| 19624 | | return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type); |
| 19686 | return ir_implicit_cast2(ira, instruction->target->scope, instruction->target->source_node, target, dest_type); |
| 19625 | 19687 | } |
| 19626 | 19688 | |
| 19627 | | return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type); |
| 19689 | return ir_analyze_widen_or_shorten(ira, instruction->base.scope, instruction->base.source_node, target, dest_type); |
| 19628 | 19690 | } |
| 19629 | 19691 | |
| 19630 | 19692 | static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFloatCast *instruction) { |
| ... | ... | @@ -19633,7 +19695,7 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo |
| 19633 | 19695 | return ira->codegen->invalid_inst_gen; |
| 19634 | 19696 | |
| 19635 | 19697 | if (dest_type->id != ZigTypeIdFloat && dest_type->id != ZigTypeIdComptimeFloat) { |
| 19636 | | ir_add_error(ira, &instruction->dest_type->base, |
| 19698 | ir_add_error_node(ira, instruction->dest_type->source_node, |
| 19637 | 19699 | buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name))); |
| 19638 | 19700 | return ira->codegen->invalid_inst_gen; |
| 19639 | 19701 | } |
| ... | ... | @@ -19652,14 +19714,14 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo |
| 19652 | 19714 | } else { |
| 19653 | 19715 | op = CastOpNumLitToConcrete; |
| 19654 | 19716 | } |
| 19655 | | return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, op); |
| 19717 | return ir_resolve_cast(ira, instruction->base.scope, instruction->base.source_node, target, dest_type, op); |
| 19656 | 19718 | } else { |
| 19657 | 19719 | return ira->codegen->invalid_inst_gen; |
| 19658 | 19720 | } |
| 19659 | 19721 | } |
| 19660 | 19722 | |
| 19661 | 19723 | if (target->value->type->id != ZigTypeIdFloat) { |
| 19662 | | ir_add_error(ira, &instruction->target->base, buf_sprintf("expected float type, found '%s'", |
| 19724 | ir_add_error_node(ira, instruction->target->source_node, buf_sprintf("expected float type, found '%s'", |
| 19663 | 19725 | buf_ptr(&target->value->type->name))); |
| 19664 | 19726 | return ira->codegen->invalid_inst_gen; |
| 19665 | 19727 | } |
| ... | ... | @@ -19670,10 +19732,11 @@ static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFlo |
| 19670 | 19732 | return ira->codegen->invalid_inst_gen; |
| 19671 | 19733 | |
| 19672 | 19734 | // XXX: This will trigger an assertion failure if dest_type is comptime_float |
| 19673 | | return ir_analyze_widen_or_shorten(ira, &instruction->target->base, target, dest_type); |
| 19735 | return ir_analyze_widen_or_shorten(ira, instruction->target->scope, |
| 19736 | instruction->target->source_node, target, dest_type); |
| 19674 | 19737 | } |
| 19675 | 19738 | |
| 19676 | | return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type); |
| 19739 | return ir_analyze_widen_or_shorten(ira, instruction->base.scope, instruction->base.source_node, target, dest_type); |
| 19677 | 19740 | } |
| 19678 | 19741 | |
| 19679 | 19742 | static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcErrSetCast *instruction) { |
| ... | ... | @@ -19682,7 +19745,7 @@ static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcE |
| 19682 | 19745 | return ira->codegen->invalid_inst_gen; |
| 19683 | 19746 | |
| 19684 | 19747 | if (dest_type->id != ZigTypeIdErrorSet) { |
| 19685 | | ir_add_error(ira, &instruction->dest_type->base, |
| 19748 | ir_add_error_node(ira, instruction->dest_type->source_node, |
| 19686 | 19749 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name))); |
| 19687 | 19750 | return ira->codegen->invalid_inst_gen; |
| 19688 | 19751 | } |
| ... | ... | @@ -19692,12 +19755,12 @@ static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcE |
| 19692 | 19755 | return ira->codegen->invalid_inst_gen; |
| 19693 | 19756 | |
| 19694 | 19757 | if (target->value->type->id != ZigTypeIdErrorSet) { |
| 19695 | | ir_add_error(ira, &instruction->target->base, |
| 19758 | ir_add_error_node(ira, instruction->target->source_node, |
| 19696 | 19759 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name))); |
| 19697 | 19760 | return ira->codegen->invalid_inst_gen; |
| 19698 | 19761 | } |
| 19699 | 19762 | |
| 19700 | | return ir_analyze_err_set_cast(ira, &instruction->base.base, target, dest_type); |
| 19763 | return ir_analyze_err_set_cast(ira, instruction->base.scope, instruction->base.source_node, target, dest_type); |
| 19701 | 19764 | } |
| 19702 | 19765 | |
| 19703 | 19766 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) { |
| ... | ... | @@ -19731,7 +19794,7 @@ static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcI |
| 19731 | 19794 | return ira->codegen->invalid_inst_gen; |
| 19732 | 19795 | |
| 19733 | 19796 | if (dest_type->id != ZigTypeIdFloat && dest_type->id != ZigTypeIdComptimeFloat) { |
| 19734 | | ir_add_error(ira, &instruction->dest_type->base, |
| 19797 | ir_add_error_node(ira, instruction->dest_type->source_node, |
| 19735 | 19798 | buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name))); |
| 19736 | 19799 | return ira->codegen->invalid_inst_gen; |
| 19737 | 19800 | } |
| ... | ... | @@ -19741,12 +19804,12 @@ static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcI |
| 19741 | 19804 | return ira->codegen->invalid_inst_gen; |
| 19742 | 19805 | |
| 19743 | 19806 | if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) { |
| 19744 | | ir_add_error(ira, &instruction->target->base, buf_sprintf("expected int type, found '%s'", |
| 19745 | | buf_ptr(&target->value->type->name))); |
| 19807 | ir_add_error_node(ira, instruction->target->source_node, |
| 19808 | buf_sprintf("expected int type, found '%s'", buf_ptr(&target->value->type->name))); |
| 19746 | 19809 | return ira->codegen->invalid_inst_gen; |
| 19747 | 19810 | } |
| 19748 | 19811 | |
| 19749 | | return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpIntToFloat); |
| 19812 | return ir_resolve_cast(ira, instruction->base.scope, instruction->base.source_node, target, dest_type, CastOpIntToFloat); |
| 19750 | 19813 | } |
| 19751 | 19814 | |
| 19752 | 19815 | static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcFloatToInt *instruction) { |
| ... | ... | @@ -19755,7 +19818,8 @@ static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcF |
| 19755 | 19818 | return ira->codegen->invalid_inst_gen; |
| 19756 | 19819 | |
| 19757 | 19820 | if (dest_type->id != ZigTypeIdInt && dest_type->id != ZigTypeIdComptimeInt) { |
| 19758 | | ir_add_error(ira, &instruction->dest_type->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 19821 | ir_add_error_node(ira, instruction->dest_type->source_node, |
| 19822 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 19759 | 19823 | return ira->codegen->invalid_inst_gen; |
| 19760 | 19824 | } |
| 19761 | 19825 | |
| ... | ... | @@ -19768,12 +19832,12 @@ static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcF |
| 19768 | 19832 | } |
| 19769 | 19833 | |
| 19770 | 19834 | if (target->value->type->id != ZigTypeIdFloat && target->value->type->id != ZigTypeIdComptimeFloat) { |
| 19771 | | ir_add_error_node(ira, target->base.source_node, buf_sprintf("expected float type, found '%s'", |
| 19835 | ir_add_error_node(ira, target->source_node, buf_sprintf("expected float type, found '%s'", |
| 19772 | 19836 | buf_ptr(&target->value->type->name))); |
| 19773 | 19837 | return ira->codegen->invalid_inst_gen; |
| 19774 | 19838 | } |
| 19775 | 19839 | |
| 19776 | | return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpFloatToInt); |
| 19840 | return ir_resolve_cast(ira, instruction->base.scope, instruction->base.source_node, target, dest_type, CastOpFloatToInt); |
| 19777 | 19841 | } |
| 19778 | 19842 | |
| 19779 | 19843 | static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErrToInt *instruction) { |
| ... | ... | @@ -19790,7 +19854,7 @@ static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErr |
| 19790 | 19854 | return ira->codegen->invalid_inst_gen; |
| 19791 | 19855 | } |
| 19792 | 19856 | |
| 19793 | | return ir_analyze_err_to_int(ira, &instruction->base.base, casted_target, ira->codegen->err_tag_type); |
| 19857 | return ir_analyze_err_to_int(ira, instruction->base.scope, instruction->base.source_node, casted_target, ira->codegen->err_tag_type); |
| 19794 | 19858 | } |
| 19795 | 19859 | |
| 19796 | 19860 | static IrInstGen *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstSrcIntToErr *instruction) { |
| ... | ... | @@ -19802,7 +19866,7 @@ static IrInstGen *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstSrcInt |
| 19802 | 19866 | if (type_is_invalid(casted_target->value->type)) |
| 19803 | 19867 | return ira->codegen->invalid_inst_gen; |
| 19804 | 19868 | |
| 19805 | | return ir_analyze_int_to_err(ira, &instruction->base.base, casted_target, ira->codegen->builtin_types.entry_global_error_set); |
| 19869 | return ir_analyze_int_to_err(ira, instruction->base.scope, instruction->base.source_node, casted_target, ira->codegen->builtin_types.entry_global_error_set); |
| 19806 | 19870 | } |
| 19807 | 19871 | |
| 19808 | 19872 | static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBoolToInt *instruction) { |
| ... | ... | @@ -19811,8 +19875,8 @@ static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBo |
| 19811 | 19875 | return ira->codegen->invalid_inst_gen; |
| 19812 | 19876 | |
| 19813 | 19877 | if (target->value->type->id != ZigTypeIdBool) { |
| 19814 | | ir_add_error(ira, &instruction->target->base, buf_sprintf("expected bool, found '%s'", |
| 19815 | | buf_ptr(&target->value->type->name))); |
| 19878 | ir_add_error_node(ira, instruction->target->source_node, |
| 19879 | buf_sprintf("expected bool, found '%s'", buf_ptr(&target->value->type->name))); |
| 19816 | 19880 | return ira->codegen->invalid_inst_gen; |
| 19817 | 19881 | } |
| 19818 | 19882 | |
| ... | ... | @@ -19821,11 +19885,11 @@ static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBo |
| 19821 | 19885 | if (!ir_resolve_bool(ira, target, &is_true)) |
| 19822 | 19886 | return ira->codegen->invalid_inst_gen; |
| 19823 | 19887 | |
| 19824 | | return ir_const_unsigned(ira, &instruction->base.base, is_true ? 1 : 0); |
| 19888 | return ir_const_unsigned(ira, instruction->base.scope, instruction->base.source_node, is_true ? 1 : 0); |
| 19825 | 19889 | } |
| 19826 | 19890 | |
| 19827 | 19891 | ZigType *u1_type = get_int_type(ira->codegen, false, 1); |
| 19828 | | return ir_resolve_cast(ira, &instruction->base.base, target, u1_type, CastOpBoolToInt); |
| 19892 | return ir_resolve_cast(ira, instruction->base.scope, instruction->base.source_node, target, u1_type, CastOpBoolToInt); |
| 19829 | 19893 | } |
| 19830 | 19894 | |
| 19831 | 19895 | static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) { |
| ... | ... | @@ -19839,16 +19903,16 @@ static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVe |
| 19839 | 19903 | |
| 19840 | 19904 | ZigType *vector_type = get_vector_type(ira->codegen, len, elem_type); |
| 19841 | 19905 | |
| 19842 | | return ir_const_type(ira, &instruction->base.base, vector_type); |
| 19906 | return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, vector_type); |
| 19843 | 19907 | } |
| 19844 | 19908 | |
| 19845 | | static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr, |
| 19909 | static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 19846 | 19910 | ZigType *scalar_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask) |
| 19847 | 19911 | { |
| 19848 | 19912 | Error err; |
| 19849 | | ir_assert(source_instr && scalar_type && a && b && mask, source_instr); |
| 19913 | src_assert(source_node && scalar_type && a && b && mask, source_node); |
| 19850 | 19914 | |
| 19851 | | if ((err = ir_validate_vector_elem_type(ira, source_instr->source_node, scalar_type))) |
| 19915 | if ((err = ir_validate_vector_elem_type(ira, source_node, scalar_type))) |
| 19852 | 19916 | return ira->codegen->invalid_inst_gen; |
| 19853 | 19917 | |
| 19854 | 19918 | uint32_t len_mask; |
| ... | ... | @@ -19857,7 +19921,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr |
| 19857 | 19921 | } else if (mask->value->type->id == ZigTypeIdArray) { |
| 19858 | 19922 | len_mask = mask->value->type->data.array.len; |
| 19859 | 19923 | } else { |
| 19860 | | ir_add_error(ira, &mask->base, |
| 19924 | ir_add_error(ira, mask, |
| 19861 | 19925 | buf_sprintf("expected vector or array, found '%s'", |
| 19862 | 19926 | buf_ptr(&mask->value->type->name))); |
| 19863 | 19927 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -19875,7 +19939,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr |
| 19875 | 19939 | } else if (a->value->type->id == ZigTypeIdUndefined) { |
| 19876 | 19940 | len_a = UINT32_MAX; |
| 19877 | 19941 | } else { |
| 19878 | | ir_add_error(ira, &a->base, |
| 19942 | ir_add_error(ira, a, |
| 19879 | 19943 | buf_sprintf("expected vector or array with element type '%s', found '%s'", |
| 19880 | 19944 | buf_ptr(&scalar_type->name), |
| 19881 | 19945 | buf_ptr(&a->value->type->name))); |
| ... | ... | @@ -19890,7 +19954,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr |
| 19890 | 19954 | } else if (b->value->type->id == ZigTypeIdUndefined) { |
| 19891 | 19955 | len_b = UINT32_MAX; |
| 19892 | 19956 | } else { |
| 19893 | | ir_add_error(ira, &b->base, |
| 19957 | ir_add_error(ira, b, |
| 19894 | 19958 | buf_sprintf("expected vector or array with element type '%s', found '%s'", |
| 19895 | 19959 | buf_ptr(&scalar_type->name), |
| 19896 | 19960 | buf_ptr(&b->value->type->name))); |
| ... | ... | @@ -19898,12 +19962,12 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr |
| 19898 | 19962 | } |
| 19899 | 19963 | |
| 19900 | 19964 | if (len_a == UINT32_MAX && len_b == UINT32_MAX) { |
| 19901 | | return ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_mask, scalar_type)); |
| 19965 | return ir_const_undef(ira, a->scope, a->source_node, get_vector_type(ira->codegen, len_mask, scalar_type)); |
| 19902 | 19966 | } |
| 19903 | 19967 | |
| 19904 | 19968 | if (len_a == UINT32_MAX) { |
| 19905 | 19969 | len_a = len_b; |
| 19906 | | a = ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_a, scalar_type)); |
| 19970 | a = ir_const_undef(ira, a->scope, a->source_node, get_vector_type(ira->codegen, len_a, scalar_type)); |
| 19907 | 19971 | } else { |
| 19908 | 19972 | a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type)); |
| 19909 | 19973 | if (type_is_invalid(a->value->type)) |
| ... | ... | @@ -19912,7 +19976,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr |
| 19912 | 19976 | |
| 19913 | 19977 | if (len_b == UINT32_MAX) { |
| 19914 | 19978 | len_b = len_a; |
| 19915 | | b = ir_const_undef(ira, &b->base, get_vector_type(ira->codegen, len_b, scalar_type)); |
| 19979 | b = ir_const_undef(ira, b->scope, b->source_node, get_vector_type(ira->codegen, len_b, scalar_type)); |
| 19916 | 19980 | } else { |
| 19917 | 19981 | b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type)); |
| 19918 | 19982 | if (type_is_invalid(b->value->type)) |
| ... | ... | @@ -19940,13 +20004,13 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr |
| 19940 | 20004 | chosen_operand = b; |
| 19941 | 20005 | } |
| 19942 | 20006 | if (v >= chosen_operand->value->type->data.vector.len) { |
| 19943 | | ErrorMsg *msg = ir_add_error(ira, &mask->base, |
| 20007 | ErrorMsg *msg = ir_add_error(ira, mask, |
| 19944 | 20008 | buf_sprintf("mask index '%u' has out-of-bounds selection", i)); |
| 19945 | | add_error_note(ira->codegen, msg, chosen_operand->base.source_node, |
| 20009 | add_error_note(ira->codegen, msg, chosen_operand->source_node, |
| 19946 | 20010 | buf_sprintf("selected index '%u' out of bounds of %s", v, |
| 19947 | 20011 | buf_ptr(&chosen_operand->value->type->name))); |
| 19948 | 20012 | if (chosen_operand == a && v < len_a + len_b) { |
| 19949 | | add_error_note(ira->codegen, msg, b->base.source_node, |
| 20013 | add_error_note(ira->codegen, msg, b->source_node, |
| 19950 | 20014 | buf_create_from_str("selections from the second vector are specified with negative numbers")); |
| 19951 | 20015 | } |
| 19952 | 20016 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -19966,7 +20030,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr |
| 19966 | 20030 | expand_undef_array(ira->codegen, a_val); |
| 19967 | 20031 | expand_undef_array(ira->codegen, b_val); |
| 19968 | 20032 | |
| 19969 | | IrInstGen *result = ir_const(ira, source_instr, result_type); |
| 20033 | IrInstGen *result = ir_const(ira, scope, source_node, result_type); |
| 19970 | 20034 | result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_mask); |
| 19971 | 20035 | for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) { |
| 19972 | 20036 | ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i]; |
| ... | ... | @@ -19982,7 +20046,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr |
| 19982 | 20046 | &b->value->data.x_array.data.s_none.elements[~v]; |
| 19983 | 20047 | copy_const_val(ira->codegen, result_elem_val, src_elem_val); |
| 19984 | 20048 | |
| 19985 | | ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr); |
| 20049 | src_assert(result_elem_val->special == ConstValSpecialStatic, source_node); |
| 19986 | 20050 | } |
| 19987 | 20051 | result->value->special = ConstValSpecialStatic; |
| 19988 | 20052 | return result; |
| ... | ... | @@ -19998,7 +20062,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr |
| 19998 | 20062 | uint32_t len_min = min(len_a, len_b); |
| 19999 | 20063 | uint32_t len_max = max(len_a, len_b); |
| 20000 | 20064 | |
| 20001 | | IrInstGen *expand_mask = ir_const(ira, &mask->base, |
| 20065 | IrInstGen *expand_mask = ir_const(ira, mask->scope, mask->source_node, |
| 20002 | 20066 | get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32)); |
| 20003 | 20067 | expand_mask->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_max); |
| 20004 | 20068 | uint32_t i = 0; |
| ... | ... | @@ -20007,17 +20071,17 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr |
| 20007 | 20071 | for (; i < len_max; i += 1) |
| 20008 | 20072 | bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1); |
| 20009 | 20073 | |
| 20010 | | IrInstGen *undef = ir_const_undef(ira, source_instr, |
| 20074 | IrInstGen *undef = ir_const_undef(ira, scope, source_node, |
| 20011 | 20075 | get_vector_type(ira->codegen, len_min, scalar_type)); |
| 20012 | 20076 | |
| 20013 | 20077 | if (len_b < len_a) { |
| 20014 | | b = ir_analyze_shuffle_vector(ira, source_instr, scalar_type, b, undef, expand_mask); |
| 20078 | b = ir_analyze_shuffle_vector(ira, scope, source_node, scalar_type, b, undef, expand_mask); |
| 20015 | 20079 | } else { |
| 20016 | | a = ir_analyze_shuffle_vector(ira, source_instr, scalar_type, a, undef, expand_mask); |
| 20080 | a = ir_analyze_shuffle_vector(ira, scope, source_node, scalar_type, a, undef, expand_mask); |
| 20017 | 20081 | } |
| 20018 | 20082 | } |
| 20019 | 20083 | |
| 20020 | | return ir_build_shuffle_vector_gen(ira, source_instr->scope, source_instr->source_node, |
| 20084 | return ir_build_shuffle_vector_gen(ira, scope, source_node, |
| 20021 | 20085 | result_type, a, b, mask); |
| 20022 | 20086 | } |
| 20023 | 20087 | |
| ... | ... | @@ -20038,7 +20102,7 @@ static IrInstGen *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstSr |
| 20038 | 20102 | if (type_is_invalid(mask->value->type)) |
| 20039 | 20103 | return ira->codegen->invalid_inst_gen; |
| 20040 | 20104 | |
| 20041 | | return ir_analyze_shuffle_vector(ira, &instruction->base.base, scalar_type, a, b, mask); |
| 20105 | return ir_analyze_shuffle_vector(ira, instruction->base.scope, instruction->base.source_node, scalar_type, a, b, mask); |
| 20042 | 20106 | } |
| 20043 | 20107 | |
| 20044 | 20108 | static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *instruction) { |
| ... | ... | @@ -20057,7 +20121,7 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i |
| 20057 | 20121 | return ira->codegen->invalid_inst_gen; |
| 20058 | 20122 | uint32_t len_int = len_u64; |
| 20059 | 20123 | |
| 20060 | | if ((err = ir_validate_vector_elem_type(ira, scalar->base.source_node, scalar->value->type))) |
| 20124 | if ((err = ir_validate_vector_elem_type(ira, scalar->source_node, scalar->value->type))) |
| 20061 | 20125 | return ira->codegen->invalid_inst_gen; |
| 20062 | 20126 | |
| 20063 | 20127 | ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type); |
| ... | ... | @@ -20067,9 +20131,9 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i |
| 20067 | 20131 | if (scalar_val == nullptr) |
| 20068 | 20132 | return ira->codegen->invalid_inst_gen; |
| 20069 | 20133 | if (scalar_val->special == ConstValSpecialUndef) |
| 20070 | | return ir_const_undef(ira, &instruction->base.base, return_type); |
| 20134 | return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, return_type); |
| 20071 | 20135 | |
| 20072 | | IrInstGen *result = ir_const(ira, &instruction->base.base, return_type); |
| 20136 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, return_type); |
| 20073 | 20137 | result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_int); |
| 20074 | 20138 | for (uint32_t i = 0; i < len_int; i += 1) { |
| 20075 | 20139 | copy_const_val(ira->codegen, &result->value->data.x_array.data.s_none.elements[i], scalar_val); |
| ... | ... | @@ -20077,7 +20141,7 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i |
| 20077 | 20141 | return result; |
| 20078 | 20142 | } |
| 20079 | 20143 | |
| 20080 | | return ir_build_splat_gen(ira, &instruction->base.base, return_type, scalar); |
| 20144 | return ir_build_splat_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, scalar); |
| 20081 | 20145 | } |
| 20082 | 20146 | |
| 20083 | 20147 | static IrInstGen *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstSrcBoolNot *instruction) { |
| ... | ... | @@ -20096,10 +20160,10 @@ static IrInstGen *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstSrcBoolN |
| 20096 | 20160 | if (value == nullptr) |
| 20097 | 20161 | return ira->codegen->invalid_inst_gen; |
| 20098 | 20162 | |
| 20099 | | return ir_const_bool(ira, &instruction->base.base, !value->data.x_bool); |
| 20163 | return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, !value->data.x_bool); |
| 20100 | 20164 | } |
| 20101 | 20165 | |
| 20102 | | return ir_build_bool_not_gen(ira, &instruction->base.base, casted_value); |
| 20166 | return ir_build_bool_not_gen(ira, instruction->base.scope, instruction->base.source_node, casted_value); |
| 20103 | 20167 | } |
| 20104 | 20168 | |
| 20105 | 20169 | static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset *instruction) { |
| ... | ... | @@ -20206,7 +20270,7 @@ static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset |
| 20206 | 20270 | size_t count = bigint_as_usize(&count_val->data.x_bigint); |
| 20207 | 20271 | size_t end = start + count; |
| 20208 | 20272 | if (end > bound_end) { |
| 20209 | | ir_add_error(ira, &count_value->base, buf_sprintf("out of bounds pointer access")); |
| 20273 | ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access")); |
| 20210 | 20274 | return ira->codegen->invalid_inst_gen; |
| 20211 | 20275 | } |
| 20212 | 20276 | |
| ... | ... | @@ -20214,11 +20278,11 @@ static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset |
| 20214 | 20278 | copy_const_val(ira->codegen, &dest_elements[i], byte_val); |
| 20215 | 20279 | } |
| 20216 | 20280 | |
| 20217 | | return ir_const_void(ira, &instruction->base.base); |
| 20281 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 20218 | 20282 | } |
| 20219 | 20283 | } |
| 20220 | 20284 | |
| 20221 | | return ir_build_memset_gen(ira, &instruction->base.base, casted_dest_ptr, casted_byte, casted_count); |
| 20285 | return ir_build_memset_gen(ira, instruction->base.scope, instruction->base.source_node, casted_dest_ptr, casted_byte, casted_count); |
| 20222 | 20286 | } |
| 20223 | 20287 | |
| 20224 | 20288 | static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy *instruction) { |
| ... | ... | @@ -20338,7 +20402,7 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy |
| 20338 | 20402 | } |
| 20339 | 20403 | |
| 20340 | 20404 | if (dest_start + count > dest_end) { |
| 20341 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access")); |
| 20405 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds pointer access")); |
| 20342 | 20406 | return ira->codegen->invalid_inst_gen; |
| 20343 | 20407 | } |
| 20344 | 20408 | |
| ... | ... | @@ -20382,7 +20446,7 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy |
| 20382 | 20446 | } |
| 20383 | 20447 | |
| 20384 | 20448 | if (src_start + count > src_end) { |
| 20385 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access")); |
| 20449 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds pointer access")); |
| 20386 | 20450 | return ira->codegen->invalid_inst_gen; |
| 20387 | 20451 | } |
| 20388 | 20452 | |
| ... | ... | @@ -20392,11 +20456,11 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy |
| 20392 | 20456 | copy_const_val(ira->codegen, &dest_elements[dest_start + i], &src_elements[src_start + i]); |
| 20393 | 20457 | } |
| 20394 | 20458 | |
| 20395 | | return ir_const_void(ira, &instruction->base.base); |
| 20459 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 20396 | 20460 | } |
| 20397 | 20461 | } |
| 20398 | 20462 | |
| 20399 | | return ir_build_memcpy_gen(ira, &instruction->base.base, casted_dest_ptr, casted_src_ptr, casted_count); |
| 20463 | return ir_build_memcpy_gen(ira, instruction->base.scope, instruction->base.source_node, casted_dest_ptr, casted_src_ptr, casted_count); |
| 20400 | 20464 | } |
| 20401 | 20465 | |
| 20402 | 20466 | static ZigType *get_result_loc_type(IrAnalyze *ira, ResultLoc *result_loc) { |
| ... | ... | @@ -20465,7 +20529,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i |
| 20465 | 20529 | PtrLenUnknown, |
| 20466 | 20530 | array_type->data.pointer.explicit_alignment, 0, 0, false); |
| 20467 | 20531 | } else { |
| 20468 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of single-item pointer")); |
| 20532 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice of single-item pointer")); |
| 20469 | 20533 | return ira->codegen->invalid_inst_gen; |
| 20470 | 20534 | } |
| 20471 | 20535 | } else { |
| ... | ... | @@ -20484,7 +20548,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i |
| 20484 | 20548 | ZigType *maybe_sentineled_slice_ptr_type = array_type; |
| 20485 | 20549 | non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr); |
| 20486 | 20550 | if (!end) { |
| 20487 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of pointer must include end value")); |
| 20551 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice of pointer must include end value")); |
| 20488 | 20552 | return ira->codegen->invalid_inst_gen; |
| 20489 | 20553 | } |
| 20490 | 20554 | } |
| ... | ... | @@ -20494,7 +20558,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i |
| 20494 | 20558 | non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr); |
| 20495 | 20559 | elem_type = non_sentinel_slice_ptr_type->data.pointer.child_type; |
| 20496 | 20560 | } else { |
| 20497 | | ir_add_error(ira, &instruction->base.base, |
| 20561 | ir_add_error_node(ira, instruction->base.source_node, |
| 20498 | 20562 | buf_sprintf("slice of non-array type '%s'", buf_ptr(&array_type->name))); |
| 20499 | 20563 | return ira->codegen->invalid_inst_gen; |
| 20500 | 20564 | } |
| ... | ... | @@ -20549,7 +20613,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i |
| 20549 | 20613 | uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint); |
| 20550 | 20614 | |
| 20551 | 20615 | if (start_scalar > end_scalar) { |
| 20552 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice")); |
| 20616 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds slice")); |
| 20553 | 20617 | return ira->codegen->invalid_inst_gen; |
| 20554 | 20618 | } |
| 20555 | 20619 | |
| ... | ... | @@ -20592,7 +20656,7 @@ done_with_return_type: |
| 20592 | 20656 | bool ptr_is_undef = false; |
| 20593 | 20657 | if (child_array_type->id == ZigTypeIdArray) { |
| 20594 | 20658 | if (array_type->id == ZigTypeIdPointer) { |
| 20595 | | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node); |
| 20659 | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 20596 | 20660 | if (parent_ptr == nullptr) |
| 20597 | 20661 | return ira->codegen->invalid_inst_gen; |
| 20598 | 20662 | |
| ... | ... | @@ -20606,7 +20670,7 @@ done_with_return_type: |
| 20606 | 20670 | abs_offset = 0; |
| 20607 | 20671 | rel_end = SIZE_MAX; |
| 20608 | 20672 | } else { |
| 20609 | | array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.base.source_node); |
| 20673 | array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node); |
| 20610 | 20674 | if (array_val == nullptr) |
| 20611 | 20675 | return ira->codegen->invalid_inst_gen; |
| 20612 | 20676 | |
| ... | ... | @@ -20614,7 +20678,7 @@ done_with_return_type: |
| 20614 | 20678 | abs_offset = 0; |
| 20615 | 20679 | } |
| 20616 | 20680 | } else { |
| 20617 | | array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node); |
| 20681 | array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 20618 | 20682 | if (array_val == nullptr) |
| 20619 | 20683 | return ira->codegen->invalid_inst_gen; |
| 20620 | 20684 | rel_end = array_type->data.array.len; |
| ... | ... | @@ -20623,7 +20687,7 @@ done_with_return_type: |
| 20623 | 20687 | } |
| 20624 | 20688 | } else if (array_type->id == ZigTypeIdPointer) { |
| 20625 | 20689 | assert(array_type->data.pointer.ptr_len == PtrLenUnknown); |
| 20626 | | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node); |
| 20690 | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 20627 | 20691 | if (parent_ptr == nullptr) |
| 20628 | 20692 | return ira->codegen->invalid_inst_gen; |
| 20629 | 20693 | |
| ... | ... | @@ -20672,18 +20736,18 @@ done_with_return_type: |
| 20672 | 20736 | zig_panic("TODO slice of null ptr"); |
| 20673 | 20737 | } |
| 20674 | 20738 | } else if (is_slice(array_type)) { |
| 20675 | | ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node); |
| 20739 | ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 20676 | 20740 | if (slice_ptr == nullptr) |
| 20677 | 20741 | return ira->codegen->invalid_inst_gen; |
| 20678 | 20742 | |
| 20679 | 20743 | if (slice_ptr->special == ConstValSpecialUndef) { |
| 20680 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined")); |
| 20744 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice of undefined")); |
| 20681 | 20745 | return ira->codegen->invalid_inst_gen; |
| 20682 | 20746 | } |
| 20683 | 20747 | |
| 20684 | 20748 | parent_ptr = slice_ptr->data.x_struct.fields[slice_ptr_index]; |
| 20685 | 20749 | if (parent_ptr->special == ConstValSpecialUndef) { |
| 20686 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined")); |
| 20750 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice of undefined")); |
| 20687 | 20751 | return ira->codegen->invalid_inst_gen; |
| 20688 | 20752 | } |
| 20689 | 20753 | |
| ... | ... | @@ -20732,7 +20796,7 @@ done_with_return_type: |
| 20732 | 20796 | |
| 20733 | 20797 | uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint); |
| 20734 | 20798 | if (!ptr_is_undef && start_scalar > rel_end) { |
| 20735 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice")); |
| 20799 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds slice")); |
| 20736 | 20800 | return ira->codegen->invalid_inst_gen; |
| 20737 | 20801 | } |
| 20738 | 20802 | |
| ... | ... | @@ -20745,16 +20809,16 @@ done_with_return_type: |
| 20745 | 20809 | } |
| 20746 | 20810 | if (!ptr_is_undef) { |
| 20747 | 20811 | if (end_scalar > rel_end) { |
| 20748 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice")); |
| 20812 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("out of bounds slice")); |
| 20749 | 20813 | return ira->codegen->invalid_inst_gen; |
| 20750 | 20814 | } |
| 20751 | 20815 | if (start_scalar > end_scalar) { |
| 20752 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice start is greater than end")); |
| 20816 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice start is greater than end")); |
| 20753 | 20817 | return ira->codegen->invalid_inst_gen; |
| 20754 | 20818 | } |
| 20755 | 20819 | } |
| 20756 | 20820 | if (ptr_is_undef && start_scalar != end_scalar) { |
| 20757 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("non-zero length slice of undefined pointer")); |
| 20821 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("non-zero length slice of undefined pointer")); |
| 20758 | 20822 | return ira->codegen->invalid_inst_gen; |
| 20759 | 20823 | } |
| 20760 | 20824 | |
| ... | ... | @@ -20773,7 +20837,7 @@ done_with_return_type: |
| 20773 | 20837 | } |
| 20774 | 20838 | |
| 20775 | 20839 | // prepare check parameters |
| 20776 | | ZigValue *target = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node); |
| 20840 | ZigValue *target = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 20777 | 20841 | if (target == nullptr) |
| 20778 | 20842 | return ira->codegen->invalid_inst_gen; |
| 20779 | 20843 | |
| ... | ... | @@ -20790,7 +20854,7 @@ done_with_return_type: |
| 20790 | 20854 | break; |
| 20791 | 20855 | } else if (target->type->id == ZigTypeIdPointer && target->type->data.pointer.child_type->id == ZigTypeIdArray) { |
| 20792 | 20856 | // handle `*[N]T` |
| 20793 | | target = const_ptr_pointee(ira, ira->codegen, target, instruction->base.base.source_node); |
| 20857 | target = const_ptr_pointee(ira, ira->codegen, target, instruction->base.source_node); |
| 20794 | 20858 | if (target == nullptr) |
| 20795 | 20859 | return ira->codegen->invalid_inst_gen; |
| 20796 | 20860 | assert(target->type->id == ZigTypeIdArray); |
| ... | ... | @@ -20841,23 +20905,23 @@ done_with_return_type: |
| 20841 | 20905 | // perform check |
| 20842 | 20906 | if (target_sentinel == nullptr) { |
| 20843 | 20907 | if (end_scalar >= target_len) { |
| 20844 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice-sentinel is out of bounds")); |
| 20908 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice-sentinel is out of bounds")); |
| 20845 | 20909 | return ira->codegen->invalid_inst_gen; |
| 20846 | 20910 | } |
| 20847 | 20911 | if (!const_values_equal(ira->codegen, sentinel_val, &target_elements[end_scalar])) { |
| 20848 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice-sentinel does not match memory at target index")); |
| 20912 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice-sentinel does not match memory at target index")); |
| 20849 | 20913 | return ira->codegen->invalid_inst_gen; |
| 20850 | 20914 | } |
| 20851 | 20915 | } else { |
| 20852 | 20916 | assert(end_scalar <= target_len); |
| 20853 | 20917 | if (end_scalar == target_len) { |
| 20854 | 20918 | if (!const_values_equal(ira->codegen, sentinel_val, target_sentinel)) { |
| 20855 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice-sentinel does not match target-sentinel")); |
| 20919 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice-sentinel does not match target-sentinel")); |
| 20856 | 20920 | return ira->codegen->invalid_inst_gen; |
| 20857 | 20921 | } |
| 20858 | 20922 | } else { |
| 20859 | 20923 | if (!const_values_equal(ira->codegen, sentinel_val, &target_elements[end_scalar])) { |
| 20860 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("slice-sentinel does not match memory at target index")); |
| 20924 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("slice-sentinel does not match memory at target index")); |
| 20861 | 20925 | return ira->codegen->invalid_inst_gen; |
| 20862 | 20926 | } |
| 20863 | 20927 | } |
| ... | ... | @@ -20865,7 +20929,7 @@ done_with_return_type: |
| 20865 | 20929 | } |
| 20866 | 20930 | exit_check_sentinel: |
| 20867 | 20931 | |
| 20868 | | IrInstGen *result = ir_const(ira, &instruction->base.base, return_type); |
| 20932 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, return_type); |
| 20869 | 20933 | |
| 20870 | 20934 | ZigValue *ptr_val; |
| 20871 | 20935 | if (return_type->id == ZigTypeIdPointer) { |
| ... | ... | @@ -20936,40 +21000,42 @@ done_with_return_type: |
| 20936 | 21000 | } |
| 20937 | 21001 | |
| 20938 | 21002 | if (generate_non_null_assert) { |
| 20939 | | IrInstGen *ptr_val = ir_get_deref(ira, &instruction->base.base, ptr_ptr, nullptr); |
| 21003 | IrInstGen *ptr_val = ir_get_deref(ira, instruction->base.scope, |
| 21004 | instruction->base.source_node, ptr_ptr, nullptr); |
| 20940 | 21005 | |
| 20941 | 21006 | if (type_is_invalid(ptr_val->value->type)) |
| 20942 | 21007 | return ira->codegen->invalid_inst_gen; |
| 20943 | 21008 | |
| 20944 | | ir_build_assert_non_null(ira, &instruction->base.base, ptr_val); |
| 21009 | ir_build_assert_non_null(ira, instruction->base.scope, instruction->base.source_node, ptr_val); |
| 20945 | 21010 | } |
| 20946 | 21011 | |
| 20947 | 21012 | IrInstGen *result_loc = nullptr; |
| 20948 | 21013 | |
| 20949 | 21014 | if (return_type->id != ZigTypeIdPointer) { |
| 20950 | | result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 21015 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 20951 | 21016 | return_type, nullptr, true, true); |
| 20952 | 21017 | if (result_loc != nullptr) { |
| 20953 | 21018 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 20954 | 21019 | return result_loc; |
| 20955 | 21020 | } |
| 20956 | 21021 | |
| 20957 | | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base); |
| 21022 | src_assert(result_loc->value->type->id == ZigTypeIdPointer, instruction->base.source_node); |
| 20958 | 21023 | if (result_loc->value->type->data.pointer.is_const) { |
| 20959 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("cannot assign to constant")); |
| 21024 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("cannot assign to constant")); |
| 20960 | 21025 | return ira->codegen->invalid_inst_gen; |
| 20961 | 21026 | } |
| 20962 | 21027 | |
| 20963 | | IrInstGen *dummy_value = ir_const(ira, &instruction->base.base, return_type); |
| 21028 | IrInstGen *dummy_value = ir_const(ira, instruction->base.scope, instruction->base.source_node, return_type); |
| 20964 | 21029 | dummy_value->value->special = ConstValSpecialRuntime; |
| 20965 | | IrInstGen *dummy_result = ir_implicit_cast2(ira, &instruction->base.base, |
| 21030 | IrInstGen *dummy_result = ir_implicit_cast2(ira, |
| 21031 | instruction->base.scope, instruction->base.source_node, |
| 20966 | 21032 | dummy_value, result_loc->value->type->data.pointer.child_type); |
| 20967 | 21033 | if (type_is_invalid(dummy_result->value->type)) |
| 20968 | 21034 | return ira->codegen->invalid_inst_gen; |
| 20969 | 21035 | } |
| 20970 | 21036 | } |
| 20971 | 21037 | |
| 20972 | | return ir_build_slice_gen(ira, &instruction->base.base, return_type, ptr_ptr, |
| 21038 | return ir_build_slice_gen(ira, instruction->base.scope, instruction->base.source_node, return_type, ptr_ptr, |
| 20973 | 21039 | casted_start, end, instruction->safety_check_on, result_loc, sentinel_val); |
| 20974 | 21040 | } |
| 20975 | 21041 | |
| ... | ... | @@ -20994,17 +21060,17 @@ static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasF |
| 20994 | 21060 | } else if (container_type->id == ZigTypeIdUnion) { |
| 20995 | 21061 | result = find_union_type_field(container_type, field_name) != nullptr; |
| 20996 | 21062 | } else { |
| 20997 | | ir_add_error(ira, &instruction->container_type->base, |
| 21063 | ir_add_error_node(ira, instruction->container_type->source_node, |
| 20998 | 21064 | buf_sprintf("type '%s' does not support @hasField", buf_ptr(&container_type->name))); |
| 20999 | 21065 | return ira->codegen->invalid_inst_gen; |
| 21000 | 21066 | } |
| 21001 | | return ir_const_bool(ira, &instruction->base.base, result); |
| 21067 | return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, result); |
| 21002 | 21068 | } |
| 21003 | 21069 | |
| 21004 | 21070 | static IrInstGen *ir_analyze_instruction_wasm_memory_size(IrAnalyze *ira, IrInstSrcWasmMemorySize *instruction) { |
| 21005 | 21071 | // TODO generate compile error for target_arch different than 32bit |
| 21006 | 21072 | if (!target_is_wasm(ira->codegen->zig_target)) { |
| 21007 | | ir_add_error_node(ira, instruction->base.base.source_node, |
| 21073 | ir_add_error_node(ira, instruction->base.source_node, |
| 21008 | 21074 | buf_sprintf("@wasmMemorySize is a wasm32 feature only")); |
| 21009 | 21075 | return ira->codegen->invalid_inst_gen; |
| 21010 | 21076 | } |
| ... | ... | @@ -21019,13 +21085,13 @@ static IrInstGen *ir_analyze_instruction_wasm_memory_size(IrAnalyze *ira, IrInst |
| 21019 | 21085 | if (type_is_invalid(casted_index->value->type)) |
| 21020 | 21086 | return ira->codegen->invalid_inst_gen; |
| 21021 | 21087 | |
| 21022 | | return ir_build_wasm_memory_size_gen(ira, &instruction->base.base, casted_index); |
| 21088 | return ir_build_wasm_memory_size_gen(ira, instruction->base.scope, instruction->base.source_node, casted_index); |
| 21023 | 21089 | } |
| 21024 | 21090 | |
| 21025 | 21091 | static IrInstGen *ir_analyze_instruction_wasm_memory_grow(IrAnalyze *ira, IrInstSrcWasmMemoryGrow *instruction) { |
| 21026 | 21092 | // TODO generate compile error for target_arch different than 32bit |
| 21027 | 21093 | if (!target_is_wasm(ira->codegen->zig_target)) { |
| 21028 | | ir_add_error_node(ira, instruction->base.base.source_node, |
| 21094 | ir_add_error_node(ira, instruction->base.source_node, |
| 21029 | 21095 | buf_sprintf("@wasmMemoryGrow is a wasm32 feature only")); |
| 21030 | 21096 | return ira->codegen->invalid_inst_gen; |
| 21031 | 21097 | } |
| ... | ... | @@ -21048,33 +21114,33 @@ static IrInstGen *ir_analyze_instruction_wasm_memory_grow(IrAnalyze *ira, IrInst |
| 21048 | 21114 | if (type_is_invalid(casted_delta->value->type)) |
| 21049 | 21115 | return ira->codegen->invalid_inst_gen; |
| 21050 | 21116 | |
| 21051 | | return ir_build_wasm_memory_grow_gen(ira, &instruction->base.base, casted_index, casted_delta); |
| 21117 | return ir_build_wasm_memory_grow_gen(ira, instruction->base.scope, instruction->base.source_node, casted_index, casted_delta); |
| 21052 | 21118 | } |
| 21053 | 21119 | |
| 21054 | 21120 | static IrInstGen *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstSrcBreakpoint *instruction) { |
| 21055 | | return ir_build_breakpoint_gen(ira, &instruction->base.base); |
| 21121 | return ir_build_breakpoint_gen(ira, instruction->base.scope, instruction->base.source_node); |
| 21056 | 21122 | } |
| 21057 | 21123 | |
| 21058 | 21124 | static IrInstGen *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstSrcReturnAddress *instruction) { |
| 21059 | | return ir_build_return_address_gen(ira, &instruction->base.base); |
| 21125 | return ir_build_return_address_gen(ira, instruction->base.scope, instruction->base.source_node); |
| 21060 | 21126 | } |
| 21061 | 21127 | |
| 21062 | 21128 | static IrInstGen *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstSrcFrameAddress *instruction) { |
| 21063 | | return ir_build_frame_address_gen(ira, &instruction->base.base); |
| 21129 | return ir_build_frame_address_gen(ira, instruction->base.scope, instruction->base.source_node); |
| 21064 | 21130 | } |
| 21065 | 21131 | |
| 21066 | 21132 | static IrInstGen *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstSrcFrameHandle *instruction) { |
| 21067 | 21133 | ZigFn *fn = ira->fn; |
| 21068 | | ir_assert(fn != nullptr, &instruction->base.base); |
| 21134 | src_assert(fn != nullptr, instruction->base.source_node); |
| 21069 | 21135 | |
| 21070 | 21136 | if (fn->inferred_async_node == nullptr) { |
| 21071 | | fn->inferred_async_node = instruction->base.base.source_node; |
| 21137 | fn->inferred_async_node = instruction->base.source_node; |
| 21072 | 21138 | } |
| 21073 | 21139 | |
| 21074 | 21140 | ZigType *frame_type = get_fn_frame_type(ira->codegen, fn); |
| 21075 | 21141 | ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false); |
| 21076 | 21142 | |
| 21077 | | return ir_build_handle_gen(ira, &instruction->base.base, ptr_frame_type); |
| 21143 | return ir_build_handle_gen(ira, instruction->base.scope, instruction->base.source_node, ptr_frame_type); |
| 21078 | 21144 | } |
| 21079 | 21145 | |
| 21080 | 21146 | static IrInstGen *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstSrcFrameType *instruction) { |
| ... | ... | @@ -21083,13 +21149,13 @@ static IrInstGen *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstSrcFra |
| 21083 | 21149 | return ira->codegen->invalid_inst_gen; |
| 21084 | 21150 | |
| 21085 | 21151 | if (fn->type_entry->data.fn.is_generic) { |
| 21086 | | ir_add_error(ira, &instruction->base.base, |
| 21152 | ir_add_error_node(ira, instruction->base.source_node, |
| 21087 | 21153 | buf_sprintf("@Frame() of generic function")); |
| 21088 | 21154 | return ira->codegen->invalid_inst_gen; |
| 21089 | 21155 | } |
| 21090 | 21156 | |
| 21091 | 21157 | ZigType *ty = get_fn_frame_type(ira->codegen, fn); |
| 21092 | | return ir_const_type(ira, &instruction->base.base, ty); |
| 21158 | return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, ty); |
| 21093 | 21159 | } |
| 21094 | 21160 | |
| 21095 | 21161 | static IrInstGen *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstSrcFrameSize *instruction) { |
| ... | ... | @@ -21098,14 +21164,14 @@ static IrInstGen *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstSrcFra |
| 21098 | 21164 | return ira->codegen->invalid_inst_gen; |
| 21099 | 21165 | |
| 21100 | 21166 | if (fn->value->type->id != ZigTypeIdFn) { |
| 21101 | | ir_add_error(ira, &fn->base, |
| 21167 | ir_add_error(ira, fn, |
| 21102 | 21168 | buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name))); |
| 21103 | 21169 | return ira->codegen->invalid_inst_gen; |
| 21104 | 21170 | } |
| 21105 | 21171 | |
| 21106 | 21172 | ira->codegen->need_frame_size_prefix_data = true; |
| 21107 | 21173 | |
| 21108 | | return ir_build_frame_size_gen(ira, &instruction->base.base, fn); |
| 21174 | return ir_build_frame_size_gen(ira, instruction->base.scope, instruction->base.source_node, fn); |
| 21109 | 21175 | } |
| 21110 | 21176 | |
| 21111 | 21177 | static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlignOf *instruction) { |
| ... | ... | @@ -21114,7 +21180,7 @@ static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlign |
| 21114 | 21180 | // const Node = struct { |
| 21115 | 21181 | // field: []align(@alignOf(Node)) Node, |
| 21116 | 21182 | // }; |
| 21117 | | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int); |
| 21183 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int); |
| 21118 | 21184 | result->value->special = ConstValSpecialLazy; |
| 21119 | 21185 | |
| 21120 | 21186 | LazyValueAlignOf *lazy_align_of = heap::c_allocator.create<LazyValueAlignOf>(); |
| ... | ... | @@ -21141,7 +21207,7 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv |
| 21141 | 21207 | return ira->codegen->invalid_inst_gen; |
| 21142 | 21208 | |
| 21143 | 21209 | if (dest_type->id != ZigTypeIdInt) { |
| 21144 | | ir_add_error(ira, &type_value->base, |
| 21210 | ir_add_error(ira, type_value, |
| 21145 | 21211 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 21146 | 21212 | return ira->codegen->invalid_inst_gen; |
| 21147 | 21213 | } |
| ... | ... | @@ -21192,7 +21258,7 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv |
| 21192 | 21258 | |
| 21193 | 21259 | // Don't write anything to the result pointer. |
| 21194 | 21260 | if (dest_type->data.integral.bit_count == 0) |
| 21195 | | return ir_const_bool(ira, &instruction->base.base, false); |
| 21261 | return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false); |
| 21196 | 21262 | |
| 21197 | 21263 | if (instr_is_comptime(casted_op1) && |
| 21198 | 21264 | instr_is_comptime(casted_op2) && |
| ... | ... | @@ -21213,7 +21279,7 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv |
| 21213 | 21279 | BigInt *op1_bigint = &op1_val->data.x_bigint; |
| 21214 | 21280 | BigInt *op2_bigint = &op2_val->data.x_bigint; |
| 21215 | 21281 | ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val, |
| 21216 | | casted_result_ptr->base.source_node); |
| 21282 | casted_result_ptr->source_node); |
| 21217 | 21283 | if (pointee_val == nullptr) |
| 21218 | 21284 | return ira->codegen->invalid_inst_gen; |
| 21219 | 21285 | BigInt *dest_bigint = &pointee_val->data.x_bigint; |
| ... | ... | @@ -21242,14 +21308,14 @@ static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOv |
| 21242 | 21308 | dest_type->data.integral.is_signed); |
| 21243 | 21309 | } |
| 21244 | 21310 | pointee_val->special = ConstValSpecialStatic; |
| 21245 | | return ir_const_bool(ira, &instruction->base.base, result_bool); |
| 21311 | return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, result_bool); |
| 21246 | 21312 | } |
| 21247 | 21313 | |
| 21248 | | return ir_build_overflow_op_gen(ira, &instruction->base.base, instruction->op, |
| 21314 | return ir_build_overflow_op_gen(ira, instruction->base.scope, instruction->base.source_node, instruction->op, |
| 21249 | 21315 | casted_op1, casted_op2, casted_result_ptr, dest_type); |
| 21250 | 21316 | } |
| 21251 | 21317 | |
| 21252 | | static void ir_eval_mul_add(IrAnalyze *ira, IrInstSrcMulAdd *source_instr, ZigType *float_type, |
| 21318 | static void ir_eval_mul_add(IrAnalyze *ira, ZigType *float_type, |
| 21253 | 21319 | ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) { |
| 21254 | 21320 | if (float_type->id == ZigTypeIdComptimeFloat) { |
| 21255 | 21321 | f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value, |
| ... | ... | @@ -21288,7 +21354,7 @@ static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd |
| 21288 | 21354 | // Only allow float types, and vectors of floats. |
| 21289 | 21355 | ZigType *float_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type; |
| 21290 | 21356 | if (float_type->id != ZigTypeIdFloat) { |
| 21291 | | ir_add_error(ira, &type_value->base, |
| 21357 | ir_add_error(ira, type_value, |
| 21292 | 21358 | buf_sprintf("expected float or vector of float type, found '%s'", buf_ptr(&float_type->name))); |
| 21293 | 21359 | return ira->codegen->invalid_inst_gen; |
| 21294 | 21360 | } |
| ... | ... | @@ -21330,7 +21396,7 @@ static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd |
| 21330 | 21396 | if (!op3_const) |
| 21331 | 21397 | return ira->codegen->invalid_inst_gen; |
| 21332 | 21398 | |
| 21333 | | IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type); |
| 21399 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, expr_type); |
| 21334 | 21400 | ZigValue *out_val = result->value; |
| 21335 | 21401 | |
| 21336 | 21402 | if (expr_type->id == ZigTypeIdVector) { |
| ... | ... | @@ -21349,19 +21415,19 @@ static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd |
| 21349 | 21415 | assert(float_operand_op2->type == float_type); |
| 21350 | 21416 | assert(float_operand_op3->type == float_type); |
| 21351 | 21417 | assert(float_out_val->type == float_type); |
| 21352 | | ir_eval_mul_add(ira, instruction, float_type, |
| 21418 | ir_eval_mul_add(ira, float_type, |
| 21353 | 21419 | op1_const, op2_const, op3_const, float_out_val); |
| 21354 | 21420 | float_out_val->type = float_type; |
| 21355 | 21421 | } |
| 21356 | 21422 | out_val->type = expr_type; |
| 21357 | 21423 | out_val->special = ConstValSpecialStatic; |
| 21358 | 21424 | } else { |
| 21359 | | ir_eval_mul_add(ira, instruction, float_type, op1_const, op2_const, op3_const, out_val); |
| 21425 | ir_eval_mul_add(ira, float_type, op1_const, op2_const, op3_const, out_val); |
| 21360 | 21426 | } |
| 21361 | 21427 | return result; |
| 21362 | 21428 | } |
| 21363 | 21429 | |
| 21364 | | return ir_build_mul_add_gen(ira, &instruction->base.base, casted_op1, casted_op2, casted_op3, expr_type); |
| 21430 | return ir_build_mul_add_gen(ira, instruction->base.scope, instruction->base.source_node, casted_op1, casted_op2, casted_op3, expr_type); |
| 21365 | 21431 | } |
| 21366 | 21432 | |
| 21367 | 21433 | static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestErr *instruction) { |
| ... | ... | @@ -21373,7 +21439,8 @@ static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestE |
| 21373 | 21439 | if (instruction->base_ptr_is_payload) { |
| 21374 | 21440 | value = base_ptr; |
| 21375 | 21441 | } else { |
| 21376 | | value = ir_get_deref(ira, &instruction->base.base, base_ptr, nullptr); |
| 21442 | value = ir_get_deref(ira, instruction->base.scope, instruction->base.source_node, |
| 21443 | base_ptr, nullptr); |
| 21377 | 21444 | } |
| 21378 | 21445 | |
| 21379 | 21446 | ZigType *type_entry = value->value->type; |
| ... | ... | @@ -21387,32 +21454,32 @@ static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestE |
| 21387 | 21454 | |
| 21388 | 21455 | if (err_union_val->special != ConstValSpecialRuntime) { |
| 21389 | 21456 | ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set; |
| 21390 | | return ir_const_bool(ira, &instruction->base.base, (err != nullptr)); |
| 21457 | return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, (err != nullptr)); |
| 21391 | 21458 | } |
| 21392 | 21459 | } |
| 21393 | 21460 | |
| 21394 | 21461 | if (instruction->resolve_err_set) { |
| 21395 | 21462 | ZigType *err_set_type = type_entry->data.error_union.err_set_type; |
| 21396 | | if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.base.source_node)) { |
| 21463 | if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) { |
| 21397 | 21464 | return ira->codegen->invalid_inst_gen; |
| 21398 | 21465 | } |
| 21399 | 21466 | if (!type_is_global_error_set(err_set_type) && |
| 21400 | 21467 | err_set_type->data.error_set.err_count == 0) |
| 21401 | 21468 | { |
| 21402 | 21469 | assert(!err_set_type->data.error_set.incomplete); |
| 21403 | | return ir_const_bool(ira, &instruction->base.base, false); |
| 21470 | return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false); |
| 21404 | 21471 | } |
| 21405 | 21472 | } |
| 21406 | 21473 | |
| 21407 | | return ir_build_test_err_gen(ira, &instruction->base.base, value); |
| 21474 | return ir_build_test_err_gen(ira, instruction->base.scope, instruction->base.source_node, value); |
| 21408 | 21475 | } else if (type_entry->id == ZigTypeIdErrorSet) { |
| 21409 | | return ir_const_bool(ira, &instruction->base.base, true); |
| 21476 | return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, true); |
| 21410 | 21477 | } else { |
| 21411 | | return ir_const_bool(ira, &instruction->base.base, false); |
| 21478 | return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false); |
| 21412 | 21479 | } |
| 21413 | 21480 | } |
| 21414 | 21481 | |
| 21415 | | static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr, |
| 21482 | static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 21416 | 21483 | IrInstGen *base_ptr, bool initializing) |
| 21417 | 21484 | { |
| 21418 | 21485 | ZigType *ptr_type = base_ptr->value->type; |
| ... | ... | @@ -21425,7 +21492,7 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst |
| 21425 | 21492 | return ira->codegen->invalid_inst_gen; |
| 21426 | 21493 | |
| 21427 | 21494 | if (type_entry->id != ZigTypeIdErrorUnion) { |
| 21428 | | ir_add_error(ira, &base_ptr->base, |
| 21495 | ir_add_error(ira, base_ptr, |
| 21429 | 21496 | buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name))); |
| 21430 | 21497 | return ira->codegen->invalid_inst_gen; |
| 21431 | 21498 | } |
| ... | ... | @@ -21442,7 +21509,7 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst |
| 21442 | 21509 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| 21443 | 21510 | ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) |
| 21444 | 21511 | { |
| 21445 | | ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 21512 | ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node); |
| 21446 | 21513 | if (err_union_val == nullptr) |
| 21447 | 21514 | return ira->codegen->invalid_inst_gen; |
| 21448 | 21515 | |
| ... | ... | @@ -21465,15 +21532,15 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst |
| 21465 | 21532 | err_union_val->data.x_err_union.error_set = err_set_val; |
| 21466 | 21533 | err_union_val->data.x_err_union.payload = payload_val; |
| 21467 | 21534 | } |
| 21468 | | ir_assert(err_union_val->special != ConstValSpecialRuntime, source_instr); |
| 21535 | src_assert(err_union_val->special != ConstValSpecialRuntime, source_node); |
| 21469 | 21536 | |
| 21470 | 21537 | IrInstGen *result; |
| 21471 | 21538 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 21472 | | result = ir_build_unwrap_err_code_gen(ira, source_instr->scope, |
| 21473 | | source_instr->source_node, base_ptr, result_type); |
| 21539 | result = ir_build_unwrap_err_code_gen(ira, scope, |
| 21540 | source_node, base_ptr, result_type); |
| 21474 | 21541 | result->value->special = ConstValSpecialStatic; |
| 21475 | 21542 | } else { |
| 21476 | | result = ir_const(ira, source_instr, result_type); |
| 21543 | result = ir_const(ira, scope, source_node, result_type); |
| 21477 | 21544 | } |
| 21478 | 21545 | ZigValue *const_val = result->value; |
| 21479 | 21546 | const_val->data.x_ptr.special = ConstPtrSpecialBaseErrorUnionCode; |
| ... | ... | @@ -21483,17 +21550,17 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst |
| 21483 | 21550 | } |
| 21484 | 21551 | } |
| 21485 | 21552 | |
| 21486 | | return ir_build_unwrap_err_code_gen(ira, source_instr->scope, source_instr->source_node, base_ptr, result_type); |
| 21553 | return ir_build_unwrap_err_code_gen(ira, scope, source_node, base_ptr, result_type); |
| 21487 | 21554 | } |
| 21488 | 21555 | |
| 21489 | 21556 | static IrInstGen *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrInstSrcUnwrapErrCode *instruction) { |
| 21490 | 21557 | IrInstGen *base_ptr = instruction->err_union_ptr->child; |
| 21491 | 21558 | if (type_is_invalid(base_ptr->value->type)) |
| 21492 | 21559 | return ira->codegen->invalid_inst_gen; |
| 21493 | | return ir_analyze_unwrap_err_code(ira, &instruction->base.base, base_ptr, false); |
| 21560 | return ir_analyze_unwrap_err_code(ira, instruction->base.scope, instruction->base.source_node, base_ptr, false); |
| 21494 | 21561 | } |
| 21495 | 21562 | |
| 21496 | | static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr, |
| 21563 | static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 21497 | 21564 | IrInstGen *base_ptr, bool safety_check_on, bool initializing) |
| 21498 | 21565 | { |
| 21499 | 21566 | ZigType *ptr_type = base_ptr->value->type; |
| ... | ... | @@ -21506,7 +21573,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source |
| 21506 | 21573 | return ira->codegen->invalid_inst_gen; |
| 21507 | 21574 | |
| 21508 | 21575 | if (type_entry->id != ZigTypeIdErrorUnion) { |
| 21509 | | ir_add_error(ira, &base_ptr->base, |
| 21576 | ir_add_error(ira, base_ptr, |
| 21510 | 21577 | buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name))); |
| 21511 | 21578 | return ira->codegen->invalid_inst_gen; |
| 21512 | 21579 | } |
| ... | ... | @@ -21524,7 +21591,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source |
| 21524 | 21591 | if (!ptr_val) |
| 21525 | 21592 | return ira->codegen->invalid_inst_gen; |
| 21526 | 21593 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 21527 | | ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 21594 | ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_node); |
| 21528 | 21595 | if (err_union_val == nullptr) |
| 21529 | 21596 | return ira->codegen->invalid_inst_gen; |
| 21530 | 21597 | if (initializing && err_union_val->special == ConstValSpecialUndef) { |
| ... | ... | @@ -21547,18 +21614,18 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source |
| 21547 | 21614 | if (err_union_val->special != ConstValSpecialRuntime) { |
| 21548 | 21615 | ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set; |
| 21549 | 21616 | if (err != nullptr) { |
| 21550 | | ir_add_error(ira, source_instr, |
| 21617 | ir_add_error_node(ira, source_node, |
| 21551 | 21618 | buf_sprintf("caught unexpected error '%s'", buf_ptr(&err->name))); |
| 21552 | 21619 | return ira->codegen->invalid_inst_gen; |
| 21553 | 21620 | } |
| 21554 | 21621 | |
| 21555 | 21622 | IrInstGen *result; |
| 21556 | 21623 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 21557 | | result = ir_build_unwrap_err_payload_gen(ira, source_instr->scope, |
| 21558 | | source_instr->source_node, base_ptr, safety_check_on, initializing, result_type); |
| 21624 | result = ir_build_unwrap_err_payload_gen(ira, scope, |
| 21625 | source_node, base_ptr, safety_check_on, initializing, result_type); |
| 21559 | 21626 | result->value->special = ConstValSpecialStatic; |
| 21560 | 21627 | } else { |
| 21561 | | result = ir_const(ira, source_instr, result_type); |
| 21628 | result = ir_const(ira, scope, source_node, result_type); |
| 21562 | 21629 | } |
| 21563 | 21630 | result->value->data.x_ptr.special = ConstPtrSpecialRef; |
| 21564 | 21631 | result->value->data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload; |
| ... | ... | @@ -21568,7 +21635,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source |
| 21568 | 21635 | } |
| 21569 | 21636 | } |
| 21570 | 21637 | |
| 21571 | | return ir_build_unwrap_err_payload_gen(ira, source_instr->scope, source_instr->source_node, |
| 21638 | return ir_build_unwrap_err_payload_gen(ira, scope, source_node, |
| 21572 | 21639 | base_ptr, safety_check_on, initializing, result_type); |
| 21573 | 21640 | } |
| 21574 | 21641 | |
| ... | ... | @@ -21580,14 +21647,14 @@ static IrInstGen *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 21580 | 21647 | if (type_is_invalid(value->value->type)) |
| 21581 | 21648 | return ira->codegen->invalid_inst_gen; |
| 21582 | 21649 | |
| 21583 | | return ir_analyze_unwrap_error_payload(ira, &instruction->base.base, value, instruction->safety_check_on, false); |
| 21650 | return ir_analyze_unwrap_error_payload(ira, instruction->base.scope, instruction->base.source_node, value, instruction->safety_check_on, false); |
| 21584 | 21651 | } |
| 21585 | 21652 | |
| 21586 | 21653 | static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnProto *instruction) { |
| 21587 | | AstNode *proto_node = instruction->base.base.source_node; |
| 21654 | AstNode *proto_node = instruction->base.source_node; |
| 21588 | 21655 | assert(proto_node->type == NodeTypeFnProto); |
| 21589 | 21656 | |
| 21590 | | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 21657 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type); |
| 21591 | 21658 | result->value->special = ConstValSpecialLazy; |
| 21592 | 21659 | |
| 21593 | 21660 | LazyValueFnType *lazy_fn_type = heap::c_allocator.create<LazyValueFnType>(); |
| ... | ... | @@ -21596,7 +21663,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro |
| 21596 | 21663 | lazy_fn_type->base.id = LazyValueIdFnType; |
| 21597 | 21664 | |
| 21598 | 21665 | if (proto_node->data.fn_proto.auto_err_set) { |
| 21599 | | ir_add_error(ira, &instruction->base.base, |
| 21666 | ir_add_error_node(ira, instruction->base.source_node, |
| 21600 | 21667 | buf_sprintf("inferring error set of return type valid only for function definitions")); |
| 21601 | 21668 | return ira->codegen->invalid_inst_gen; |
| 21602 | 21669 | } |
| ... | ... | @@ -21631,7 +21698,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro |
| 21631 | 21698 | if (cc == CallingConventionC) { |
| 21632 | 21699 | break; |
| 21633 | 21700 | } else { |
| 21634 | | ir_add_error(ira, &instruction->base.base, |
| 21701 | ir_add_error_node(ira, instruction->base.source_node, |
| 21635 | 21702 | buf_sprintf("var args only allowed in functions with C calling convention")); |
| 21636 | 21703 | return ira->codegen->invalid_inst_gen; |
| 21637 | 21704 | } |
| ... | ... | @@ -21668,7 +21735,7 @@ static IrInstGen *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstSrc |
| 21668 | 21735 | if (type_is_invalid(value->value->type)) |
| 21669 | 21736 | return ira->codegen->invalid_inst_gen; |
| 21670 | 21737 | |
| 21671 | | return ir_const_bool(ira, &instruction->base.base, instr_is_comptime(value)); |
| 21738 | return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, instr_is_comptime(value)); |
| 21672 | 21739 | } |
| 21673 | 21740 | |
| 21674 | 21741 | static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| ... | ... | @@ -21713,7 +21780,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 21713 | 21780 | bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag); |
| 21714 | 21781 | |
| 21715 | 21782 | if (bigint_cmp(&start_index, &end_index) == CmpGT) { |
| 21716 | | ir_add_error(ira, &start_value->base, |
| 21783 | ir_add_error(ira, start_value, |
| 21717 | 21784 | buf_sprintf("range start value is greater than the end value")); |
| 21718 | 21785 | } |
| 21719 | 21786 | |
| ... | ... | @@ -21724,12 +21791,12 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 21724 | 21791 | if (cmp == CmpGT) { |
| 21725 | 21792 | break; |
| 21726 | 21793 | } |
| 21727 | | auto entry = field_prev_uses.put_unique(field_index, start_value->base.source_node); |
| 21794 | auto entry = field_prev_uses.put_unique(field_index, start_value->source_node); |
| 21728 | 21795 | if (entry) { |
| 21729 | 21796 | AstNode *prev_node = entry->value; |
| 21730 | 21797 | TypeEnumField *enum_field = find_enum_field_by_tag(switch_type, &field_index); |
| 21731 | 21798 | assert(enum_field != nullptr); |
| 21732 | | ErrorMsg *msg = ir_add_error(ira, &start_value->base, |
| 21799 | ErrorMsg *msg = ir_add_error(ira, start_value, |
| 21733 | 21800 | buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), |
| 21734 | 21801 | buf_ptr(enum_field->name))); |
| 21735 | 21802 | add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value here")); |
| ... | ... | @@ -21739,10 +21806,10 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 21739 | 21806 | } |
| 21740 | 21807 | if (have_underscore_prong) { |
| 21741 | 21808 | if (!switch_type->data.enumeration.non_exhaustive) { |
| 21742 | | ir_add_error(ira, &instruction->base.base, |
| 21809 | ir_add_error_node(ira, instruction->base.source_node, |
| 21743 | 21810 | buf_sprintf("switch on exhaustive enum has `_` prong")); |
| 21744 | 21811 | } else if (target_is_originally_union) { |
| 21745 | | ir_add_error(ira, &instruction->base.base, |
| 21812 | ir_add_error_node(ira, instruction->base.source_node, |
| 21746 | 21813 | buf_sprintf("`_` prong not allowed when switching on tagged union")); |
| 21747 | 21814 | } |
| 21748 | 21815 | for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) { |
| ... | ... | @@ -21752,14 +21819,14 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 21752 | 21819 | |
| 21753 | 21820 | auto entry = field_prev_uses.maybe_get(enum_field->value); |
| 21754 | 21821 | if (!entry) { |
| 21755 | | ir_add_error(ira, &instruction->base.base, |
| 21822 | ir_add_error_node(ira, instruction->base.source_node, |
| 21756 | 21823 | buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name), |
| 21757 | 21824 | buf_ptr(enum_field->name))); |
| 21758 | 21825 | } |
| 21759 | 21826 | } |
| 21760 | 21827 | } else if (instruction->else_prong == nullptr) { |
| 21761 | 21828 | if (switch_type->data.enumeration.non_exhaustive && !target_is_originally_union) { |
| 21762 | | ir_add_error(ira, &instruction->base.base, |
| 21829 | ir_add_error_node(ira, instruction->base.source_node, |
| 21763 | 21830 | buf_sprintf("switch on non-exhaustive enum must include `else` or `_` prong")); |
| 21764 | 21831 | } |
| 21765 | 21832 | for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) { |
| ... | ... | @@ -21767,7 +21834,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 21767 | 21834 | |
| 21768 | 21835 | auto entry = field_prev_uses.maybe_get(enum_field->value); |
| 21769 | 21836 | if (!entry) { |
| 21770 | | ir_add_error(ira, &instruction->base.base, |
| 21837 | ir_add_error_node(ira, instruction->base.source_node, |
| 21771 | 21838 | buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name), |
| 21772 | 21839 | buf_ptr(enum_field->name))); |
| 21773 | 21840 | } |
| ... | ... | @@ -21778,7 +21845,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 21778 | 21845 | return ira->codegen->invalid_inst_gen; |
| 21779 | 21846 | } |
| 21780 | 21847 | } else if (switch_type->id == ZigTypeIdErrorSet) { |
| 21781 | | if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->base.source_node)) { |
| 21848 | if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) { |
| 21782 | 21849 | return ira->codegen->invalid_inst_gen; |
| 21783 | 21850 | } |
| 21784 | 21851 | |
| ... | ... | @@ -21802,29 +21869,29 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 21802 | 21869 | if (type_is_invalid(end_value->value->type)) |
| 21803 | 21870 | return ira->codegen->invalid_inst_gen; |
| 21804 | 21871 | |
| 21805 | | ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base); |
| 21872 | src_assert(start_value->value->type->id == ZigTypeIdErrorSet, instruction->base.source_node); |
| 21806 | 21873 | uint32_t start_index = start_value->value->data.x_err_set->value; |
| 21807 | 21874 | |
| 21808 | | ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base); |
| 21875 | src_assert(end_value->value->type->id == ZigTypeIdErrorSet, instruction->base.source_node); |
| 21809 | 21876 | uint32_t end_index = end_value->value->data.x_err_set->value; |
| 21810 | 21877 | |
| 21811 | 21878 | if (start_index != end_index) { |
| 21812 | | ir_add_error(ira, &end_value->base, buf_sprintf("ranges not allowed when switching on errors")); |
| 21879 | ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors")); |
| 21813 | 21880 | return ira->codegen->invalid_inst_gen; |
| 21814 | 21881 | } |
| 21815 | 21882 | |
| 21816 | 21883 | AstNode *prev_node = field_prev_uses[start_index]; |
| 21817 | 21884 | if (prev_node != nullptr) { |
| 21818 | 21885 | Buf *err_name = &ira->codegen->errors_by_index.at(start_index)->name; |
| 21819 | | ErrorMsg *msg = ir_add_error(ira, &start_value->base, |
| 21886 | ErrorMsg *msg = ir_add_error(ira, start_value, |
| 21820 | 21887 | buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(err_name))); |
| 21821 | 21888 | add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value here")); |
| 21822 | 21889 | } |
| 21823 | | field_prev_uses[start_index] = start_value->base.source_node; |
| 21890 | field_prev_uses[start_index] = start_value->source_node; |
| 21824 | 21891 | } |
| 21825 | 21892 | if (instruction->else_prong == nullptr) { |
| 21826 | 21893 | if (type_is_global_error_set(switch_type)) { |
| 21827 | | ir_add_error(ira, &instruction->base.base, |
| 21894 | ir_add_error_node(ira, instruction->base.source_node, |
| 21828 | 21895 | buf_sprintf("else prong required when switching on type 'anyerror'")); |
| 21829 | 21896 | return ira->codegen->invalid_inst_gen; |
| 21830 | 21897 | } else { |
| ... | ... | @@ -21833,7 +21900,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 21833 | 21900 | |
| 21834 | 21901 | AstNode *prev_node = field_prev_uses[err_entry->value]; |
| 21835 | 21902 | if (prev_node == nullptr) { |
| 21836 | | ir_add_error(ira, &instruction->base.base, |
| 21903 | ir_add_error_node(ira, instruction->base.source_node, |
| 21837 | 21904 | buf_sprintf("error.%s not handled in switch", buf_ptr(&err_entry->name))); |
| 21838 | 21905 | } |
| 21839 | 21906 | } |
| ... | ... | @@ -21872,14 +21939,14 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 21872 | 21939 | assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt); |
| 21873 | 21940 | |
| 21874 | 21941 | if (bigint_cmp(&start_val->data.x_bigint, &end_val->data.x_bigint) == CmpGT) { |
| 21875 | | ir_add_error(ira, &start_value->base, |
| 21942 | ir_add_error(ira, start_value, |
| 21876 | 21943 | buf_sprintf("range start value is greater than the end value")); |
| 21877 | 21944 | } |
| 21878 | 21945 | |
| 21879 | 21946 | AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint, |
| 21880 | | start_value->base.source_node); |
| 21947 | start_value->source_node); |
| 21881 | 21948 | if (prev_node != nullptr) { |
| 21882 | | ErrorMsg *msg = ir_add_error(ira, &start_value->base, buf_sprintf("duplicate switch value")); |
| 21949 | ErrorMsg *msg = ir_add_error(ira, start_value, buf_sprintf("duplicate switch value")); |
| 21883 | 21950 | add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value here")); |
| 21884 | 21951 | return ira->codegen->invalid_inst_gen; |
| 21885 | 21952 | } |
| ... | ... | @@ -21891,7 +21958,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 21891 | 21958 | eval_min_max_value_int(ira->codegen, switch_type, &max_val, true); |
| 21892 | 21959 | bool handles_all_cases = rangeset_spans(&rs, &min_val, &max_val); |
| 21893 | 21960 | if (!handles_all_cases && instruction->else_prong == nullptr) { |
| 21894 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities")); |
| 21961 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("switch must handle all possibilities")); |
| 21895 | 21962 | return ira->codegen->invalid_inst_gen; |
| 21896 | 21963 | } else if(handles_all_cases && instruction->else_prong != nullptr) { |
| 21897 | 21964 | ir_add_error_node(ira, instruction->else_prong, |
| ... | ... | @@ -21923,12 +21990,12 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 21923 | 21990 | } |
| 21924 | 21991 | |
| 21925 | 21992 | if ((seenTrue > 1) || (seenFalse > 1)) { |
| 21926 | | ir_add_error(ira, &value->base, buf_sprintf("duplicate switch value")); |
| 21993 | ir_add_error(ira, value, buf_sprintf("duplicate switch value")); |
| 21927 | 21994 | return ira->codegen->invalid_inst_gen; |
| 21928 | 21995 | } |
| 21929 | 21996 | } |
| 21930 | 21997 | if (((seenTrue < 1) || (seenFalse < 1)) && instruction->else_prong == nullptr) { |
| 21931 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities")); |
| 21998 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("switch must handle all possibilities")); |
| 21932 | 21999 | return ira->codegen->invalid_inst_gen; |
| 21933 | 22000 | } |
| 21934 | 22001 | |
| ... | ... | @@ -21938,7 +22005,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 21938 | 22005 | return ira->codegen->invalid_inst_gen; |
| 21939 | 22006 | } |
| 21940 | 22007 | } else if (instruction->else_prong == nullptr) { |
| 21941 | | ir_add_error(ira, &instruction->base.base, |
| 22008 | ir_add_error_node(ira, instruction->base.source_node, |
| 21942 | 22009 | buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name))); |
| 21943 | 22010 | return ira->codegen->invalid_inst_gen; |
| 21944 | 22011 | } else if(switch_type->id == ZigTypeIdMetaType) { |
| ... | ... | @@ -21964,15 +22031,15 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 21964 | 22031 | |
| 21965 | 22032 | auto entry = prevs.put_unique(const_expr_val->data.x_type, value); |
| 21966 | 22033 | if(entry != nullptr) { |
| 21967 | | ErrorMsg *msg = ir_add_error(ira, &value->base, buf_sprintf("duplicate switch value")); |
| 21968 | | add_error_note(ira->codegen, msg, entry->value->base.source_node, buf_sprintf("previous value here")); |
| 22034 | ErrorMsg *msg = ir_add_error(ira, value, buf_sprintf("duplicate switch value")); |
| 22035 | add_error_note(ira->codegen, msg, entry->value->source_node, buf_sprintf("previous value here")); |
| 21969 | 22036 | prevs.deinit(); |
| 21970 | 22037 | return ira->codegen->invalid_inst_gen; |
| 21971 | 22038 | } |
| 21972 | 22039 | } |
| 21973 | 22040 | prevs.deinit(); |
| 21974 | 22041 | } |
| 21975 | | return ir_const_void(ira, &instruction->base.base); |
| 22042 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 21976 | 22043 | } |
| 21977 | 22044 | |
| 21978 | 22045 | static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, |
| ... | ... | @@ -21985,13 +22052,13 @@ static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, |
| 21985 | 22052 | |
| 21986 | 22053 | if (statement_type->id != ZigTypeIdVoid && statement_type->id != ZigTypeIdUnreachable) { |
| 21987 | 22054 | if(statement_type->id == ZigTypeIdErrorUnion || statement_type->id == ZigTypeIdErrorSet) { |
| 21988 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("error is ignored. consider using `try`, `catch`, or `if`")); |
| 22055 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("error is ignored. consider using `try`, `catch`, or `if`")); |
| 21989 | 22056 | }else{ |
| 21990 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("expression value is ignored")); |
| 22057 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("expression value is ignored")); |
| 21991 | 22058 | } |
| 21992 | 22059 | } |
| 21993 | 22060 | |
| 21994 | | return ir_const_void(ira, &instruction->base.base); |
| 22061 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 21995 | 22062 | } |
| 21996 | 22063 | |
| 21997 | 22064 | static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *instruction) { |
| ... | ... | @@ -21999,8 +22066,8 @@ static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *i |
| 21999 | 22066 | if (type_is_invalid(msg->value->type)) |
| 22000 | 22067 | return ir_unreach_error(ira); |
| 22001 | 22068 | |
| 22002 | | if (ir_should_inline(ira->zir, instruction->base.base.scope)) { |
| 22003 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("encountered @panic at compile-time")); |
| 22069 | if (ir_should_inline(ira->zir, instruction->base.scope)) { |
| 22070 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("encountered @panic at compile-time")); |
| 22004 | 22071 | return ir_unreach_error(ira); |
| 22005 | 22072 | } |
| 22006 | 22073 | |
| ... | ... | @@ -22011,7 +22078,7 @@ static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *i |
| 22011 | 22078 | if (type_is_invalid(casted_msg->value->type)) |
| 22012 | 22079 | return ir_unreach_error(ira); |
| 22013 | 22080 | |
| 22014 | | IrInstGen *new_instruction = ir_build_panic_gen(ira, &instruction->base.base, casted_msg); |
| 22081 | IrInstGen *new_instruction = ir_build_panic_gen(ira, instruction->base.scope, instruction->base.source_node, casted_msg); |
| 22015 | 22082 | return ir_finish_anal(ira, new_instruction); |
| 22016 | 22083 | } |
| 22017 | 22084 | |
| ... | ... | @@ -22032,7 +22099,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig |
| 22032 | 22099 | } |
| 22033 | 22100 | |
| 22034 | 22101 | if (safety_check_on && !type_has_bits(ira->codegen, actual_ptr)) { |
| 22035 | | ir_add_error(ira, &target->base, |
| 22102 | ir_add_error(ira, target, |
| 22036 | 22103 | buf_sprintf("cannot adjust alignment of zero sized type '%s'", buf_ptr(&target_type->name))); |
| 22037 | 22104 | return ira->codegen->invalid_inst_gen; |
| 22038 | 22105 | } |
| ... | ... | @@ -22050,7 +22117,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig |
| 22050 | 22117 | if (align_bytes >= get_async_frame_align_bytes(ira->codegen)) { |
| 22051 | 22118 | result_type = target_type; |
| 22052 | 22119 | } else { |
| 22053 | | ir_add_error(ira, &target->base, buf_sprintf("sub-aligned anyframe not allowed")); |
| 22120 | ir_add_error(ira, target, buf_sprintf("sub-aligned anyframe not allowed")); |
| 22054 | 22121 | return ira->codegen->invalid_inst_gen; |
| 22055 | 22122 | } |
| 22056 | 22123 | } else if (target_type->id == ZigTypeIdOptional && |
| ... | ... | @@ -22077,7 +22144,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig |
| 22077 | 22144 | ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes); |
| 22078 | 22145 | result_type = get_slice_type(ira->codegen, result_ptr_type); |
| 22079 | 22146 | } else { |
| 22080 | | ir_add_error(ira, &target->base, |
| 22147 | ir_add_error(ira, target, |
| 22081 | 22148 | buf_sprintf("expected pointer or slice, found '%s'", buf_ptr(&target_type->name))); |
| 22082 | 22149 | return ira->codegen->invalid_inst_gen; |
| 22083 | 22150 | } |
| ... | ... | @@ -22090,28 +22157,28 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig |
| 22090 | 22157 | if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr && |
| 22091 | 22158 | val->data.x_ptr.data.hard_coded_addr.addr % align_bytes != 0) |
| 22092 | 22159 | { |
| 22093 | | ir_add_error(ira, &target->base, |
| 22160 | ir_add_error(ira, target, |
| 22094 | 22161 | buf_sprintf("pointer address 0x%" ZIG_PRI_x64 " is not aligned to %" PRIu32 " bytes", |
| 22095 | 22162 | val->data.x_ptr.data.hard_coded_addr.addr, align_bytes)); |
| 22096 | 22163 | return ira->codegen->invalid_inst_gen; |
| 22097 | 22164 | } |
| 22098 | 22165 | |
| 22099 | | IrInstGen *result = ir_const(ira, &target->base, result_type); |
| 22166 | IrInstGen *result = ir_const(ira, target->scope, target->source_node, result_type); |
| 22100 | 22167 | copy_const_val(ira->codegen, result->value, val); |
| 22101 | 22168 | result->value->type = result_type; |
| 22102 | 22169 | return result; |
| 22103 | 22170 | } |
| 22104 | 22171 | |
| 22105 | 22172 | if (safety_check_on && align_bytes > old_align_bytes && align_bytes != 1) { |
| 22106 | | return ir_build_align_cast_gen(ira, target->base.scope, target->base.source_node, target, result_type); |
| 22173 | return ir_build_align_cast_gen(ira, target->scope, target->source_node, target, result_type); |
| 22107 | 22174 | } else { |
| 22108 | | return ir_build_cast(ira, &target->base, result_type, target, CastOpNoop); |
| 22175 | return ir_build_cast(ira, target->scope, target->source_node, result_type, target, CastOpNoop); |
| 22109 | 22176 | } |
| 22110 | 22177 | } |
| 22111 | 22178 | |
| 22112 | | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr, |
| 22113 | | IrInst *ptr_src, ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on, |
| 22114 | | bool keep_bigger_alignment) |
| 22179 | static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 22180 | IrInstGen *ptr, AstNode *ptr_src, ZigType *dest_type, AstNode *dest_type_src, |
| 22181 | bool safety_check_on, bool keep_bigger_alignment) |
| 22115 | 22182 | { |
| 22116 | 22183 | Error err; |
| 22117 | 22184 | |
| ... | ... | @@ -22134,20 +22201,21 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 22134 | 22201 | |
| 22135 | 22202 | ZigType *src_ptr_type = get_src_ptr_type(src_type); |
| 22136 | 22203 | if (src_ptr_type == nullptr) { |
| 22137 | | ir_add_error(ira, ptr_src, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name))); |
| 22204 | ir_add_error_node(ira, ptr_src, |
| 22205 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name))); |
| 22138 | 22206 | return ira->codegen->invalid_inst_gen; |
| 22139 | 22207 | } |
| 22140 | 22208 | } |
| 22141 | 22209 | |
| 22142 | 22210 | ZigType *dest_ptr_type = get_src_ptr_type(dest_type); |
| 22143 | 22211 | if (dest_ptr_type == nullptr) { |
| 22144 | | ir_add_error(ira, dest_type_src, |
| 22212 | ir_add_error_node(ira, dest_type_src, |
| 22145 | 22213 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name))); |
| 22146 | 22214 | return ira->codegen->invalid_inst_gen; |
| 22147 | 22215 | } |
| 22148 | 22216 | |
| 22149 | 22217 | if (get_ptr_const(ira->codegen, src_type) && !get_ptr_const(ira->codegen, dest_type)) { |
| 22150 | | ir_add_error(ira, source_instr, buf_sprintf("cast discards const qualifier")); |
| 22218 | ir_add_error_node(ira, source_node, buf_sprintf("cast discards const qualifier")); |
| 22151 | 22219 | return ira->codegen->invalid_inst_gen; |
| 22152 | 22220 | } |
| 22153 | 22221 | uint32_t dest_align_bytes; |
| ... | ... | @@ -22170,12 +22238,12 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 22170 | 22238 | type_has_bits(ira->codegen, dest_type) && |
| 22171 | 22239 | !type_has_bits(ira->codegen, if_slice_ptr_type)) |
| 22172 | 22240 | { |
| 22173 | | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| 22241 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 22174 | 22242 | buf_sprintf("'%s' and '%s' do not have the same in-memory representation", |
| 22175 | 22243 | buf_ptr(&src_type->name), buf_ptr(&dest_type->name))); |
| 22176 | | add_error_note(ira->codegen, msg, ptr_src->source_node, |
| 22244 | add_error_note(ira->codegen, msg, ptr_src, |
| 22177 | 22245 | buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name))); |
| 22178 | | add_error_note(ira->codegen, msg, dest_type_src->source_node, |
| 22246 | add_error_note(ira->codegen, msg, dest_type_src, |
| 22179 | 22247 | buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name))); |
| 22180 | 22248 | return ira->codegen->invalid_inst_gen; |
| 22181 | 22249 | } |
| ... | ... | @@ -22183,9 +22251,9 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 22183 | 22251 | // For slices, follow the `ptr` field. |
| 22184 | 22252 | if (is_slice(src_type)) { |
| 22185 | 22253 | TypeStructField *ptr_field = src_type->data.structure.fields[slice_ptr_index]; |
| 22186 | | IrInstGen *ptr_ref = ir_get_ref(ira, source_instr, ptr, true, false); |
| 22187 | | IrInstGen *ptr_ptr = ir_analyze_struct_field_ptr(ira, source_instr, ptr_field, ptr_ref, src_type, false); |
| 22188 | | ptr = ir_get_deref(ira, source_instr, ptr_ptr, nullptr); |
| 22254 | IrInstGen *ptr_ref = ir_get_ref(ira, scope, source_node, ptr, true, false); |
| 22255 | IrInstGen *ptr_ptr = ir_analyze_struct_field_ptr(ira, scope, source_node, ptr_field, ptr_ref, src_type, false); |
| 22256 | ptr = ir_get_deref(ira, scope, source_node, ptr_ptr, nullptr); |
| 22189 | 22257 | } |
| 22190 | 22258 | |
| 22191 | 22259 | if (instr_is_comptime(ptr)) { |
| ... | ... | @@ -22200,7 +22268,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 22200 | 22268 | (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr && |
| 22201 | 22269 | val->data.x_ptr.data.hard_coded_addr.addr == 0); |
| 22202 | 22270 | if (is_addr_zero && !dest_allows_addr_zero) { |
| 22203 | | ir_add_error(ira, source_instr, |
| 22271 | ir_add_error_node(ira, source_node, |
| 22204 | 22272 | buf_sprintf("null pointer casted to type '%s'", buf_ptr(&dest_type->name))); |
| 22205 | 22273 | return ira->codegen->invalid_inst_gen; |
| 22206 | 22274 | } |
| ... | ... | @@ -22208,9 +22276,9 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 22208 | 22276 | |
| 22209 | 22277 | IrInstGen *result; |
| 22210 | 22278 | if (val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 22211 | | result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on); |
| 22279 | result = ir_build_ptr_cast_gen(ira, scope, source_node, dest_type, ptr, safety_check_on); |
| 22212 | 22280 | } else { |
| 22213 | | result = ir_const(ira, source_instr, dest_type); |
| 22281 | result = ir_const(ira, scope, source_node, dest_type); |
| 22214 | 22282 | } |
| 22215 | 22283 | InferredStructField *isf = (val->type->id == ZigTypeIdPointer) ? |
| 22216 | 22284 | val->type->data.pointer.inferred_struct_field : nullptr; |
| ... | ... | @@ -22243,15 +22311,15 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 22243 | 22311 | } |
| 22244 | 22312 | |
| 22245 | 22313 | if (src_align_bytes != 0 && dest_align_bytes > src_align_bytes) { |
| 22246 | | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment")); |
| 22247 | | add_error_note(ira->codegen, msg, ptr_src->source_node, |
| 22314 | ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("cast increases pointer alignment")); |
| 22315 | add_error_note(ira->codegen, msg, ptr_src, |
| 22248 | 22316 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes)); |
| 22249 | | add_error_note(ira->codegen, msg, dest_type_src->source_node, |
| 22317 | add_error_note(ira->codegen, msg, dest_type_src, |
| 22250 | 22318 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes)); |
| 22251 | 22319 | return ira->codegen->invalid_inst_gen; |
| 22252 | 22320 | } |
| 22253 | 22321 | |
| 22254 | | IrInstGen *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on); |
| 22322 | IrInstGen *casted_ptr = ir_build_ptr_cast_gen(ira, scope, source_node, dest_type, ptr, safety_check_on); |
| 22255 | 22323 | |
| 22256 | 22324 | // Keep the bigger alignment, it can only help- unless the target is zero bits. |
| 22257 | 22325 | IrInstGen *result; |
| ... | ... | @@ -22277,8 +22345,9 @@ static IrInstGen *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstSrcPtrCa |
| 22277 | 22345 | return ira->codegen->invalid_inst_gen; |
| 22278 | 22346 | |
| 22279 | 22347 | bool keep_bigger_alignment = true; |
| 22280 | | return ir_analyze_ptr_cast(ira, &instruction->base.base, ptr, &instruction->ptr->base, |
| 22281 | | dest_type, &dest_type_value->base, instruction->safety_check_on, keep_bigger_alignment); |
| 22348 | return ir_analyze_ptr_cast(ira, instruction->base.scope, instruction->base.source_node, ptr, |
| 22349 | instruction->ptr->source_node, dest_type, dest_type_value->source_node, |
| 22350 | instruction->safety_check_on, keep_bigger_alignment); |
| 22282 | 22351 | } |
| 22283 | 22352 | |
| 22284 | 22353 | static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) { |
| ... | ... | @@ -22622,19 +22691,19 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou |
| 22622 | 22691 | zig_unreachable(); |
| 22623 | 22692 | } |
| 22624 | 22693 | |
| 22625 | | static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, |
| 22694 | static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *value, |
| 22626 | 22695 | ZigType *dest_type) |
| 22627 | 22696 | { |
| 22628 | 22697 | Error err; |
| 22629 | 22698 | |
| 22630 | 22699 | ZigType *src_type = value->value->type; |
| 22631 | | ir_assert(type_can_bit_cast(src_type), source_instr); |
| 22632 | | ir_assert(type_can_bit_cast(dest_type), source_instr); |
| 22700 | src_assert(type_can_bit_cast(src_type), source_node); |
| 22701 | src_assert(type_can_bit_cast(dest_type), source_node); |
| 22633 | 22702 | |
| 22634 | 22703 | if (dest_type->id == ZigTypeIdEnum) { |
| 22635 | | ErrorMsg *msg = ir_add_error_node(ira, source_instr->source_node, |
| 22704 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 22636 | 22705 | buf_sprintf("cannot cast a value of type '%s'", buf_ptr(&dest_type->name))); |
| 22637 | | add_error_note(ira->codegen, msg, source_instr->source_node, |
| 22706 | add_error_note(ira->codegen, msg, source_node, |
| 22638 | 22707 | buf_sprintf("use @intToEnum for type coercion")); |
| 22639 | 22708 | return ira->codegen->invalid_inst_gen; |
| 22640 | 22709 | } |
| ... | ... | @@ -22651,7 +22720,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 22651 | 22720 | const uint64_t dest_size_bytes = type_size(ira->codegen, dest_type); |
| 22652 | 22721 | const uint64_t src_size_bytes = type_size(ira->codegen, src_type); |
| 22653 | 22722 | if (dest_size_bytes != src_size_bytes) { |
| 22654 | | ir_add_error(ira, source_instr, |
| 22723 | ir_add_error_node(ira, source_node, |
| 22655 | 22724 | buf_sprintf("destination type '%s' has size %" ZIG_PRI_u64 " but source type '%s' has size %" ZIG_PRI_u64, |
| 22656 | 22725 | buf_ptr(&dest_type->name), dest_size_bytes, |
| 22657 | 22726 | buf_ptr(&src_type->name), src_size_bytes)); |
| ... | ... | @@ -22661,7 +22730,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 22661 | 22730 | const uint64_t dest_size_bits = type_size_bits(ira->codegen, dest_type); |
| 22662 | 22731 | const uint64_t src_size_bits = type_size_bits(ira->codegen, src_type); |
| 22663 | 22732 | if (dest_size_bits != src_size_bits) { |
| 22664 | | ir_add_error(ira, source_instr, |
| 22733 | ir_add_error_node(ira, source_node, |
| 22665 | 22734 | buf_sprintf("destination type '%s' has %" ZIG_PRI_u64 " bits but source type '%s' has %" ZIG_PRI_u64 " bits", |
| 22666 | 22735 | buf_ptr(&dest_type->name), dest_size_bits, |
| 22667 | 22736 | buf_ptr(&src_type->name), src_size_bits)); |
| ... | ... | @@ -22673,10 +22742,10 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 22673 | 22742 | if (!val) |
| 22674 | 22743 | return ira->codegen->invalid_inst_gen; |
| 22675 | 22744 | |
| 22676 | | IrInstGen *result = ir_const(ira, source_instr, dest_type); |
| 22745 | IrInstGen *result = ir_const(ira, scope, source_node, dest_type); |
| 22677 | 22746 | uint8_t *buf = heap::c_allocator.allocate_nonzero<uint8_t>(src_size_bytes); |
| 22678 | 22747 | buf_write_value_bytes(ira->codegen, buf, val); |
| 22679 | | if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value))) |
| 22748 | if ((err = buf_read_value_bytes(ira, ira->codegen, source_node, buf, result->value))) |
| 22680 | 22749 | return ira->codegen->invalid_inst_gen; |
| 22681 | 22750 | heap::c_allocator.deallocate(buf, src_size_bytes); |
| 22682 | 22751 | return result; |
| ... | ... | @@ -22684,19 +22753,19 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn |
| 22684 | 22753 | |
| 22685 | 22754 | if (dest_is_ptr && !src_is_ptr) { |
| 22686 | 22755 | // Spill the scalar into a local memory location and take its address |
| 22687 | | value = ir_get_ref(ira, source_instr, value, false, false); |
| 22756 | value = ir_get_ref(ira, scope, source_node, value, false, false); |
| 22688 | 22757 | } |
| 22689 | 22758 | |
| 22690 | | return ir_build_bit_cast_gen(ira, source_instr, value, dest_type); |
| 22759 | return ir_build_bit_cast_gen(ira, scope, source_node, value, dest_type); |
| 22691 | 22760 | } |
| 22692 | 22761 | |
| 22693 | | static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target, |
| 22762 | static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target, |
| 22694 | 22763 | ZigType *ptr_type) |
| 22695 | 22764 | { |
| 22696 | 22765 | Error err; |
| 22697 | 22766 | |
| 22698 | | ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr); |
| 22699 | | ir_assert(type_has_bits(ira->codegen, ptr_type), source_instr); |
| 22767 | src_assert(get_src_ptr_type(ptr_type) != nullptr, source_node); |
| 22768 | src_assert(type_has_bits(ira->codegen, ptr_type), source_node); |
| 22700 | 22769 | |
| 22701 | 22770 | IrInstGen *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize); |
| 22702 | 22771 | if (type_is_invalid(casted_int->value->type)) |
| ... | ... | @@ -22709,7 +22778,7 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir |
| 22709 | 22778 | |
| 22710 | 22779 | uint64_t addr = bigint_as_u64(&val->data.x_bigint); |
| 22711 | 22780 | if (!ptr_allows_addr_zero(ptr_type) && addr == 0) { |
| 22712 | | ir_add_error(ira, source_instr, |
| 22781 | ir_add_error_node(ira, source_node, |
| 22713 | 22782 | buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name))); |
| 22714 | 22783 | return ira->codegen->invalid_inst_gen; |
| 22715 | 22784 | } |
| ... | ... | @@ -22719,13 +22788,13 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir |
| 22719 | 22788 | return ira->codegen->invalid_inst_gen; |
| 22720 | 22789 | |
| 22721 | 22790 | if (addr != 0 && addr % align_bytes != 0) { |
| 22722 | | ir_add_error(ira, source_instr, |
| 22791 | ir_add_error_node(ira, source_node, |
| 22723 | 22792 | buf_sprintf("pointer type '%s' requires aligned address", |
| 22724 | 22793 | buf_ptr(&ptr_type->name))); |
| 22725 | 22794 | return ira->codegen->invalid_inst_gen; |
| 22726 | 22795 | } |
| 22727 | 22796 | |
| 22728 | | IrInstGen *result = ir_const(ira, source_instr, ptr_type); |
| 22797 | IrInstGen *result = ir_const(ira, scope, source_node, ptr_type); |
| 22729 | 22798 | if (ptr_type->id == ZigTypeIdOptional && addr == 0) { |
| 22730 | 22799 | result->value->data.x_ptr.special = ConstPtrSpecialNull; |
| 22731 | 22800 | result->value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| ... | ... | @@ -22738,7 +22807,7 @@ static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, Ir |
| 22738 | 22807 | return result; |
| 22739 | 22808 | } |
| 22740 | 22809 | |
| 22741 | | return ir_build_int_to_ptr_gen(ira, source_instr->scope, source_instr->source_node, casted_int, ptr_type); |
| 22810 | return ir_build_int_to_ptr_gen(ira, scope, source_node, casted_int, ptr_type); |
| 22742 | 22811 | } |
| 22743 | 22812 | |
| 22744 | 22813 | static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcIntToPtr *instruction) { |
| ... | ... | @@ -22750,7 +22819,7 @@ static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcInt |
| 22750 | 22819 | |
| 22751 | 22820 | // We explicitly check for the size, so we can use get_src_ptr_type |
| 22752 | 22821 | if (get_src_ptr_type(dest_type) == nullptr) { |
| 22753 | | ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name))); |
| 22822 | ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name))); |
| 22754 | 22823 | return ira->codegen->invalid_inst_gen; |
| 22755 | 22824 | } |
| 22756 | 22825 | |
| ... | ... | @@ -22759,7 +22828,7 @@ static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcInt |
| 22759 | 22828 | return ira->codegen->invalid_inst_gen; |
| 22760 | 22829 | |
| 22761 | 22830 | if (!has_bits) { |
| 22762 | | ir_add_error(ira, &dest_type_value->base, |
| 22831 | ir_add_error(ira, dest_type_value, |
| 22763 | 22832 | buf_sprintf("type '%s' has 0 bits and cannot store information", buf_ptr(&dest_type->name))); |
| 22764 | 22833 | return ira->codegen->invalid_inst_gen; |
| 22765 | 22834 | } |
| ... | ... | @@ -22768,11 +22837,11 @@ static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcInt |
| 22768 | 22837 | if (type_is_invalid(target->value->type)) |
| 22769 | 22838 | return ira->codegen->invalid_inst_gen; |
| 22770 | 22839 | |
| 22771 | | return ir_analyze_int_to_ptr(ira, &instruction->base.base, target, dest_type); |
| 22840 | return ir_analyze_int_to_ptr(ira, instruction->base.scope, instruction->base.source_node, target, dest_type); |
| 22772 | 22841 | } |
| 22773 | 22842 | |
| 22774 | 22843 | static IrInstGen *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstSrcDeclRef *instruction) { |
| 22775 | | IrInstGen *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base.base, instruction->tld); |
| 22844 | IrInstGen *ref_instruction = ir_analyze_decl_ref(ira, instruction->base.scope, instruction->base.source_node, instruction->tld); |
| 22776 | 22845 | if (type_is_invalid(ref_instruction->value->type)) { |
| 22777 | 22846 | return ira->codegen->invalid_inst_gen; |
| 22778 | 22847 | } |
| ... | ... | @@ -22780,7 +22849,7 @@ static IrInstGen *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstSrcDeclR |
| 22780 | 22849 | if (instruction->lval == LValPtr || instruction->lval == LValAssign) { |
| 22781 | 22850 | return ref_instruction; |
| 22782 | 22851 | } else { |
| 22783 | | return ir_get_deref(ira, &instruction->base.base, ref_instruction, nullptr); |
| 22852 | return ir_get_deref(ira, instruction->base.scope, instruction->base.source_node, ref_instruction, nullptr); |
| 22784 | 22853 | } |
| 22785 | 22854 | } |
| 22786 | 22855 | |
| ... | ... | @@ -22794,7 +22863,7 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr |
| 22794 | 22863 | |
| 22795 | 22864 | ZigType *src_ptr_type = get_src_ptr_type(target->value->type); |
| 22796 | 22865 | if (src_ptr_type == nullptr) { |
| 22797 | | ir_add_error(ira, &target->base, |
| 22866 | ir_add_error(ira, target, |
| 22798 | 22867 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name))); |
| 22799 | 22868 | return ira->codegen->invalid_inst_gen; |
| 22800 | 22869 | } |
| ... | ... | @@ -22804,7 +22873,7 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr |
| 22804 | 22873 | return ira->codegen->invalid_inst_gen; |
| 22805 | 22874 | |
| 22806 | 22875 | if (!has_bits) { |
| 22807 | | ir_add_error(ira, &target->base, |
| 22876 | ir_add_error(ira, target, |
| 22808 | 22877 | buf_sprintf("pointer to size 0 type has no address")); |
| 22809 | 22878 | return ira->codegen->invalid_inst_gen; |
| 22810 | 22879 | } |
| ... | ... | @@ -22817,25 +22886,25 @@ static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtr |
| 22817 | 22886 | // Since we've already run this type trough get_src_ptr_type it is |
| 22818 | 22887 | // safe to access the x_ptr fields |
| 22819 | 22888 | if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 22820 | | IrInstGen *result = ir_const(ira, &instruction->base.base, usize); |
| 22889 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, usize); |
| 22821 | 22890 | bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); |
| 22822 | 22891 | result->value->type = usize; |
| 22823 | 22892 | return result; |
| 22824 | 22893 | } else if (val->data.x_ptr.special == ConstPtrSpecialNull) { |
| 22825 | | IrInstGen *result = ir_const(ira, &instruction->base.base, usize); |
| 22894 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, usize); |
| 22826 | 22895 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 22827 | 22896 | result->value->type = usize; |
| 22828 | 22897 | return result; |
| 22829 | 22898 | } |
| 22830 | 22899 | } |
| 22831 | 22900 | |
| 22832 | | return ir_build_ptr_to_int_gen(ira, &instruction->base.base, target); |
| 22901 | return ir_build_ptr_to_int_gen(ira, instruction->base.scope, instruction->base.source_node, target); |
| 22833 | 22902 | } |
| 22834 | 22903 | |
| 22835 | 22904 | static IrInstGen *ir_analyze_instruction_ptr_type_simple(IrAnalyze *ira, |
| 22836 | 22905 | IrInstSrcPtrTypeSimple *instruction, bool is_const) |
| 22837 | 22906 | { |
| 22838 | | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 22907 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type); |
| 22839 | 22908 | result->value->special = ConstValSpecialLazy; |
| 22840 | 22909 | |
| 22841 | 22910 | LazyValuePtrTypeSimple *lazy_ptr_type = heap::c_allocator.create<LazyValuePtrTypeSimple>(); |
| ... | ... | @@ -22851,7 +22920,7 @@ static IrInstGen *ir_analyze_instruction_ptr_type_simple(IrAnalyze *ira, |
| 22851 | 22920 | } |
| 22852 | 22921 | |
| 22853 | 22922 | static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrType *instruction) { |
| 22854 | | IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type); |
| 22923 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_type); |
| 22855 | 22924 | result->value->special = ConstValSpecialLazy; |
| 22856 | 22925 | |
| 22857 | 22926 | LazyValuePtrType *lazy_ptr_type = heap::c_allocator.create<LazyValuePtrType>(); |
| ... | ... | @@ -22861,7 +22930,7 @@ static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrTy |
| 22861 | 22930 | |
| 22862 | 22931 | if (instruction->sentinel != nullptr) { |
| 22863 | 22932 | if (instruction->ptr_len != PtrLenUnknown) { |
| 22864 | | ir_add_error(ira, &instruction->base.base, |
| 22933 | ir_add_error_node(ira, instruction->base.source_node, |
| 22865 | 22934 | buf_sprintf("sentinels are only allowed on unknown-length pointers")); |
| 22866 | 22935 | return ira->codegen->invalid_inst_gen; |
| 22867 | 22936 | } |
| ... | ... | @@ -22923,36 +22992,36 @@ static IrInstGen *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstS |
| 22923 | 22992 | return ira->codegen->invalid_inst_gen; |
| 22924 | 22993 | |
| 22925 | 22994 | if (align_bytes > 256) { |
| 22926 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes)); |
| 22995 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes)); |
| 22927 | 22996 | return ira->codegen->invalid_inst_gen; |
| 22928 | 22997 | } |
| 22929 | 22998 | |
| 22930 | 22999 | ZigFn *fn_entry = ira->fn; |
| 22931 | 23000 | if (fn_entry == nullptr) { |
| 22932 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack outside function")); |
| 23001 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@setAlignStack outside function")); |
| 22933 | 23002 | return ira->codegen->invalid_inst_gen; |
| 22934 | 23003 | } |
| 22935 | 23004 | if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionNaked) { |
| 22936 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in naked function")); |
| 23005 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@setAlignStack in naked function")); |
| 22937 | 23006 | return ira->codegen->invalid_inst_gen; |
| 22938 | 23007 | } |
| 22939 | 23008 | |
| 22940 | 23009 | if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionInline) { |
| 22941 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in inline function")); |
| 23010 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@setAlignStack in inline function")); |
| 22942 | 23011 | return ira->codegen->invalid_inst_gen; |
| 22943 | 23012 | } |
| 22944 | 23013 | |
| 22945 | 23014 | if (fn_entry->set_alignstack_node != nullptr) { |
| 22946 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 23015 | ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node, |
| 22947 | 23016 | buf_sprintf("alignstack set twice")); |
| 22948 | 23017 | add_error_note(ira->codegen, msg, fn_entry->set_alignstack_node, buf_sprintf("first set here")); |
| 22949 | 23018 | return ira->codegen->invalid_inst_gen; |
| 22950 | 23019 | } |
| 22951 | 23020 | |
| 22952 | | fn_entry->set_alignstack_node = instruction->base.base.source_node; |
| 23021 | fn_entry->set_alignstack_node = instruction->base.source_node; |
| 22953 | 23022 | fn_entry->alignstack_value = align_bytes; |
| 22954 | 23023 | |
| 22955 | | return ir_const_void(ira, &instruction->base.base); |
| 23024 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 22956 | 23025 | } |
| 22957 | 23026 | |
| 22958 | 23027 | static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgType *instruction, |
| ... | ... | @@ -22973,7 +23042,7 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy |
| 22973 | 23042 | arg_index += 1; |
| 22974 | 23043 | } |
| 22975 | 23044 | if (fn_type->id != ZigTypeIdFn) { |
| 22976 | | ir_add_error(ira, &fn_type_inst->base, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name))); |
| 23045 | ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name))); |
| 22977 | 23046 | return ira->codegen->invalid_inst_gen; |
| 22978 | 23047 | } |
| 22979 | 23048 | |
| ... | ... | @@ -22981,9 +23050,9 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy |
| 22981 | 23050 | if (arg_index >= fn_type_id->param_count) { |
| 22982 | 23051 | if (allow_var) { |
| 22983 | 23052 | // TODO remove this with var args |
| 22984 | | return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_anytype); |
| 23053 | return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_anytype); |
| 22985 | 23054 | } |
| 22986 | | ir_add_error(ira, &arg_index_inst->base, |
| 23055 | ir_add_error(ira, arg_index_inst, |
| 22987 | 23056 | buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " argument(s)", |
| 22988 | 23057 | arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count)); |
| 22989 | 23058 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -22992,18 +23061,18 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy |
| 22992 | 23061 | ZigType *result_type = fn_type_id->param_info[arg_index].type; |
| 22993 | 23062 | if (result_type == nullptr) { |
| 22994 | 23063 | // Args are only unresolved if our function is generic. |
| 22995 | | ir_assert(fn_type->data.fn.is_generic, &instruction->base.base); |
| 23064 | src_assert(fn_type->data.fn.is_generic, instruction->base.source_node); |
| 22996 | 23065 | |
| 22997 | 23066 | if (allow_var) { |
| 22998 | | return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_anytype); |
| 23067 | return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_anytype); |
| 22999 | 23068 | } else { |
| 23000 | | ir_add_error(ira, &arg_index_inst->base, |
| 23069 | ir_add_error(ira, arg_index_inst, |
| 23001 | 23070 | buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic", |
| 23002 | 23071 | arg_index, buf_ptr(&fn_type->name))); |
| 23003 | 23072 | return ira->codegen->invalid_inst_gen; |
| 23004 | 23073 | } |
| 23005 | 23074 | } |
| 23006 | | return ir_const_type(ira, &instruction->base.base, result_type); |
| 23075 | return ir_const_type(ira, instruction->base.scope, instruction->base.source_node, result_type); |
| 23007 | 23076 | } |
| 23008 | 23077 | |
| 23009 | 23078 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) { |
| ... | ... | @@ -23022,7 +23091,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) { |
| 23022 | 23091 | uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch); |
| 23023 | 23092 | |
| 23024 | 23093 | if (bit_count > max_atomic_bits) { |
| 23025 | | ir_add_error(ira, &op->base, |
| 23094 | ir_add_error(ira, op, |
| 23026 | 23095 | buf_sprintf("expected %" PRIu32 "-bit integer type or smaller, found %" PRIu32 "-bit integer type", |
| 23027 | 23096 | max_atomic_bits, bit_count)); |
| 23028 | 23097 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -23030,7 +23099,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) { |
| 23030 | 23099 | } else if (operand_type->id == ZigTypeIdFloat) { |
| 23031 | 23100 | uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch); |
| 23032 | 23101 | if (operand_type->data.floating.bit_count > max_atomic_bits) { |
| 23033 | | ir_add_error(ira, &op->base, |
| 23102 | ir_add_error(ira, op, |
| 23034 | 23103 | buf_sprintf("expected %" PRIu32 "-bit float or smaller, found %" PRIu32 "-bit float", |
| 23035 | 23104 | max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count)); |
| 23036 | 23105 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -23043,7 +23112,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) { |
| 23043 | 23112 | if ((err = get_codegen_ptr_type(ira->codegen, operand_type, &operand_ptr_type))) |
| 23044 | 23113 | return ira->codegen->builtin_types.entry_invalid; |
| 23045 | 23114 | if (operand_ptr_type == nullptr) { |
| 23046 | | ir_add_error(ira, &op->base, |
| 23115 | ir_add_error(ira, op, |
| 23047 | 23116 | buf_sprintf("expected bool, integer, float, enum or pointer type, found '%s'", |
| 23048 | 23117 | buf_ptr(&operand_type->name))); |
| 23049 | 23118 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -23074,15 +23143,15 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto |
| 23074 | 23143 | } |
| 23075 | 23144 | |
| 23076 | 23145 | if (operand_type->id == ZigTypeIdEnum && op != AtomicRmwOp_xchg) { |
| 23077 | | ir_add_error(ira, &instruction->op->base, |
| 23146 | ir_add_error_node(ira, instruction->op->source_node, |
| 23078 | 23147 | buf_sprintf("@atomicRmw with enum only allowed with .Xchg")); |
| 23079 | 23148 | return ira->codegen->invalid_inst_gen; |
| 23080 | 23149 | } else if (operand_type->id == ZigTypeIdBool && op != AtomicRmwOp_xchg) { |
| 23081 | | ir_add_error(ira, &instruction->op->base, |
| 23150 | ir_add_error_node(ira, instruction->op->source_node, |
| 23082 | 23151 | buf_sprintf("@atomicRmw with bool only allowed with .Xchg")); |
| 23083 | 23152 | return ira->codegen->invalid_inst_gen; |
| 23084 | 23153 | } else if (operand_type->id == ZigTypeIdFloat && op > AtomicRmwOp_sub) { |
| 23085 | | ir_add_error(ira, &instruction->op->base, |
| 23154 | ir_add_error_node(ira, instruction->op->source_node, |
| 23086 | 23155 | buf_sprintf("@atomicRmw with float only allowed with .Xchg, .Add and .Sub")); |
| 23087 | 23156 | return ira->codegen->invalid_inst_gen; |
| 23088 | 23157 | } |
| ... | ... | @@ -23099,7 +23168,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto |
| 23099 | 23168 | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 23100 | 23169 | return ira->codegen->invalid_inst_gen; |
| 23101 | 23170 | if (ordering == AtomicOrderUnordered) { |
| 23102 | | ir_add_error(ira, &instruction->ordering->base, |
| 23171 | ir_add_error_node(ira, instruction->ordering->source_node, |
| 23103 | 23172 | buf_sprintf("@atomicRmw atomic ordering must not be Unordered")); |
| 23104 | 23173 | return ira->codegen->invalid_inst_gen; |
| 23105 | 23174 | } |
| ... | ... | @@ -23109,18 +23178,19 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto |
| 23109 | 23178 | case OnePossibleValueInvalid: |
| 23110 | 23179 | return ira->codegen->invalid_inst_gen; |
| 23111 | 23180 | case OnePossibleValueYes: |
| 23112 | | return ir_const_move(ira, &instruction->base.base, get_the_one_possible_value(ira->codegen, operand_type)); |
| 23181 | return ir_const_move(ira, instruction->base.scope, instruction->base.source_node, get_the_one_possible_value(ira->codegen, operand_type)); |
| 23113 | 23182 | case OnePossibleValueNo: |
| 23114 | 23183 | break; |
| 23115 | 23184 | } |
| 23116 | 23185 | |
| 23117 | | IrInst *source_inst = &instruction->base.base; |
| 23186 | Scope *scope = instruction->base.scope; |
| 23187 | AstNode *source_node = instruction->base.source_node; |
| 23118 | 23188 | if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar) { |
| 23119 | 23189 | ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad); |
| 23120 | 23190 | if (ptr_val == nullptr) |
| 23121 | 23191 | return ira->codegen->invalid_inst_gen; |
| 23122 | 23192 | |
| 23123 | | ZigValue *op1_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.base.source_node); |
| 23193 | ZigValue *op1_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.source_node); |
| 23124 | 23194 | if (op1_val == nullptr) |
| 23125 | 23195 | return ira->codegen->invalid_inst_gen; |
| 23126 | 23196 | |
| ... | ... | @@ -23128,7 +23198,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto |
| 23128 | 23198 | if (op2_val == nullptr) |
| 23129 | 23199 | return ira->codegen->invalid_inst_gen; |
| 23130 | 23200 | |
| 23131 | | IrInstGen *result = ir_const(ira, source_inst, operand_type); |
| 23201 | IrInstGen *result = ir_const(ira, scope, source_node, operand_type); |
| 23132 | 23202 | copy_const_val(ira->codegen, result->value, op1_val); |
| 23133 | 23203 | if (op == AtomicRmwOp_xchg) { |
| 23134 | 23204 | copy_const_val(ira->codegen, op1_val, op2_val); |
| ... | ... | @@ -23136,7 +23206,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto |
| 23136 | 23206 | } |
| 23137 | 23207 | |
| 23138 | 23208 | if (operand_type->id == ZigTypeIdPointer || operand_type->id == ZigTypeIdOptional) { |
| 23139 | | ir_add_error(ira, &instruction->ordering->base, |
| 23209 | ir_add_error_node(ira, instruction->ordering->source_node, |
| 23140 | 23210 | buf_sprintf("TODO comptime @atomicRmw with pointers other than .Xchg")); |
| 23141 | 23211 | return ira->codegen->invalid_inst_gen; |
| 23142 | 23212 | } |
| ... | ... | @@ -23151,8 +23221,8 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto |
| 23151 | 23221 | // store op2 if op2 > op1 |
| 23152 | 23222 | bin_op = IrBinOpCmpLessThan; |
| 23153 | 23223 | |
| 23154 | | IrInstGen *dummy_value = ir_const(ira, source_inst, operand_type); |
| 23155 | | msg = ir_eval_bin_op_cmp_scalar(ira, source_inst, op1_val, bin_op, op2_val, dummy_value->value); |
| 23224 | IrInstGen *dummy_value = ir_const(ira, scope, source_node, operand_type); |
| 23225 | msg = ir_eval_bin_op_cmp_scalar(ira, scope, source_node, op1_val, bin_op, op2_val, dummy_value->value); |
| 23156 | 23226 | if (msg != nullptr) { |
| 23157 | 23227 | return ira->codegen->invalid_inst_gen; |
| 23158 | 23228 | } |
| ... | ... | @@ -23188,7 +23258,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto |
| 23188 | 23258 | bin_op = IrBinOpBinXor; |
| 23189 | 23259 | break; |
| 23190 | 23260 | } |
| 23191 | | msg = ir_eval_math_op_scalar(ira, source_inst, operand_type, op1_val, bin_op, op2_val, op1_val); |
| 23261 | msg = ir_eval_math_op_scalar(ira, scope, source_node, operand_type, op1_val, bin_op, op2_val, op1_val); |
| 23192 | 23262 | if (msg != nullptr) { |
| 23193 | 23263 | return ira->codegen->invalid_inst_gen; |
| 23194 | 23264 | } |
| ... | ... | @@ -23200,7 +23270,7 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto |
| 23200 | 23270 | return result; |
| 23201 | 23271 | } |
| 23202 | 23272 | |
| 23203 | | return ir_build_atomic_rmw_gen(ira, source_inst, casted_ptr, casted_operand, op, |
| 23273 | return ir_build_atomic_rmw_gen(ira, scope, source_node, casted_ptr, casted_operand, op, |
| 23204 | 23274 | ordering, operand_type); |
| 23205 | 23275 | } |
| 23206 | 23276 | |
| ... | ... | @@ -23223,19 +23293,20 @@ static IrInstGen *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstSrcAt |
| 23223 | 23293 | return ira->codegen->invalid_inst_gen; |
| 23224 | 23294 | |
| 23225 | 23295 | if (ordering == AtomicOrderRelease || ordering == AtomicOrderAcqRel) { |
| 23226 | | ir_assert(instruction->ordering != nullptr, &instruction->base.base); |
| 23227 | | ir_add_error(ira, &instruction->ordering->base, |
| 23296 | src_assert(instruction->ordering != nullptr, instruction->base.source_node); |
| 23297 | ir_add_error_node(ira, instruction->ordering->source_node, |
| 23228 | 23298 | buf_sprintf("@atomicLoad atomic ordering must not be Release or AcqRel")); |
| 23229 | 23299 | return ira->codegen->invalid_inst_gen; |
| 23230 | 23300 | } |
| 23231 | 23301 | |
| 23232 | 23302 | if (instr_is_comptime(casted_ptr)) { |
| 23233 | | IrInstGen *result = ir_get_deref(ira, &instruction->base.base, casted_ptr, nullptr); |
| 23234 | | ir_assert(result->value->type != nullptr, &instruction->base.base); |
| 23303 | IrInstGen *result = ir_get_deref(ira, instruction->base.scope, |
| 23304 | instruction->base.source_node, casted_ptr, nullptr); |
| 23305 | src_assert(result->value->type != nullptr, instruction->base.source_node); |
| 23235 | 23306 | return result; |
| 23236 | 23307 | } |
| 23237 | 23308 | |
| 23238 | | return ir_build_atomic_load_gen(ira, &instruction->base.base, casted_ptr, ordering, operand_type); |
| 23309 | return ir_build_atomic_load_gen(ira, instruction->base.scope, instruction->base.source_node, casted_ptr, ordering, operand_type); |
| 23239 | 23310 | } |
| 23240 | 23311 | |
| 23241 | 23312 | static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcAtomicStore *instruction) { |
| ... | ... | @@ -23266,8 +23337,8 @@ static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcA |
| 23266 | 23337 | return ira->codegen->invalid_inst_gen; |
| 23267 | 23338 | |
| 23268 | 23339 | if (ordering == AtomicOrderAcquire || ordering == AtomicOrderAcqRel) { |
| 23269 | | ir_assert(instruction->ordering != nullptr, &instruction->base.base); |
| 23270 | | ir_add_error(ira, &instruction->ordering->base, |
| 23340 | src_assert(instruction->ordering != nullptr, instruction->base.source_node); |
| 23341 | ir_add_error_node(ira, instruction->ordering->source_node, |
| 23271 | 23342 | buf_sprintf("@atomicStore atomic ordering must not be Acquire or AcqRel")); |
| 23272 | 23343 | return ira->codegen->invalid_inst_gen; |
| 23273 | 23344 | } |
| ... | ... | @@ -23277,28 +23348,28 @@ static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcA |
| 23277 | 23348 | case OnePossibleValueInvalid: |
| 23278 | 23349 | return ira->codegen->invalid_inst_gen; |
| 23279 | 23350 | case OnePossibleValueYes: |
| 23280 | | return ir_const_void(ira, &instruction->base.base); |
| 23351 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 23281 | 23352 | case OnePossibleValueNo: |
| 23282 | 23353 | break; |
| 23283 | 23354 | } |
| 23284 | 23355 | |
| 23285 | 23356 | if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) { |
| 23286 | | IrInstGen *result = ir_analyze_store_ptr(ira, &instruction->base.base, casted_ptr, value, false); |
| 23357 | IrInstGen *result = ir_analyze_store_ptr(ira, instruction->base.scope, instruction->base.source_node, casted_ptr, value, false); |
| 23287 | 23358 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 23288 | 23359 | return result; |
| 23289 | 23360 | } |
| 23290 | 23361 | |
| 23291 | | return ir_build_atomic_store_gen(ira, &instruction->base.base, casted_ptr, casted_value, ordering); |
| 23362 | return ir_build_atomic_store_gen(ira, instruction->base.scope, instruction->base.source_node, casted_ptr, casted_value, ordering); |
| 23292 | 23363 | } |
| 23293 | 23364 | |
| 23294 | 23365 | static IrInstGen *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstSrcSaveErrRetAddr *instruction) { |
| 23295 | | return ir_build_save_err_ret_addr_gen(ira, &instruction->base.base); |
| 23366 | return ir_build_save_err_ret_addr_gen(ira, instruction->base.scope, instruction->base.source_node); |
| 23296 | 23367 | } |
| 23297 | 23368 | |
| 23298 | | static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinFnId fop, ZigType *float_type, |
| 23369 | static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, Scope *scope, AstNode *source_node, BuiltinFnId fop, ZigType *float_type, |
| 23299 | 23370 | ZigValue *op, ZigValue *out_val) |
| 23300 | 23371 | { |
| 23301 | | assert(ira && source_instr && float_type && out_val && op); |
| 23372 | assert(ira && source_node && float_type && out_val && op); |
| 23302 | 23373 | assert(float_type->id == ZigTypeIdFloat || |
| 23303 | 23374 | float_type->id == ZigTypeIdComptimeFloat); |
| 23304 | 23375 | |
| ... | ... | @@ -23464,7 +23535,7 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinF |
| 23464 | 23535 | break; |
| 23465 | 23536 | } |
| 23466 | 23537 | case 80: |
| 23467 | | return ir_add_error(ira, source_instr, |
| 23538 | return ir_add_error_node(ira, source_node, |
| 23468 | 23539 | buf_sprintf("compiler bug: TODO: implement '%s' for type '%s'. See https://github.com/ziglang/zig/issues/4026", |
| 23469 | 23540 | float_op_to_name(fop), buf_ptr(&float_type->name))); |
| 23470 | 23541 | case 128: { |
| ... | ... | @@ -23503,7 +23574,7 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinF |
| 23503 | 23574 | case BuiltinFnIdLog: |
| 23504 | 23575 | case BuiltinFnIdLog10: |
| 23505 | 23576 | case BuiltinFnIdLog2: |
| 23506 | | return ir_add_error(ira, source_instr, |
| 23577 | return ir_add_error_node(ira, source_node, |
| 23507 | 23578 | buf_sprintf("compiler bug: TODO: implement '%s' for type '%s'. See https://github.com/ziglang/zig/issues/4026", |
| 23508 | 23579 | float_op_to_name(fop), buf_ptr(&float_type->name))); |
| 23509 | 23580 | default: |
| ... | ... | @@ -23529,7 +23600,7 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat |
| 23529 | 23600 | operand_type->data.vector.elem_type : operand_type; |
| 23530 | 23601 | |
| 23531 | 23602 | if (scalar_type->id != ZigTypeIdFloat && scalar_type->id != ZigTypeIdComptimeFloat) { |
| 23532 | | ir_add_error(ira, &operand->base, |
| 23603 | ir_add_error(ira, operand, |
| 23533 | 23604 | buf_sprintf("expected float type, found '%s'", buf_ptr(&scalar_type->name))); |
| 23534 | 23605 | return ira->codegen->invalid_inst_gen; |
| 23535 | 23606 | } |
| ... | ... | @@ -23539,9 +23610,9 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat |
| 23539 | 23610 | if (operand_val == nullptr) |
| 23540 | 23611 | return ira->codegen->invalid_inst_gen; |
| 23541 | 23612 | if (operand_val->special == ConstValSpecialUndef) |
| 23542 | | return ir_const_undef(ira, &instruction->base.base, operand_type); |
| 23613 | return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, operand_type); |
| 23543 | 23614 | |
| 23544 | | IrInstGen *result = ir_const(ira, &instruction->base.base, operand_type); |
| 23615 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, operand_type); |
| 23545 | 23616 | ZigValue *out_val = result->value; |
| 23546 | 23617 | |
| 23547 | 23618 | if (operand_type->id == ZigTypeIdVector) { |
| ... | ... | @@ -23552,12 +23623,12 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat |
| 23552 | 23623 | for (size_t i = 0; i < len; i += 1) { |
| 23553 | 23624 | ZigValue *elem_operand = &operand_val->data.x_array.data.s_none.elements[i]; |
| 23554 | 23625 | ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 23555 | | ir_assert(elem_operand->type == scalar_type, &instruction->base.base); |
| 23556 | | ir_assert(float_out_val->type == scalar_type, &instruction->base.base); |
| 23557 | | ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type, |
| 23626 | src_assert(elem_operand->type == scalar_type, instruction->base.source_node); |
| 23627 | src_assert(float_out_val->type == scalar_type, instruction->base.source_node); |
| 23628 | ErrorMsg *msg = ir_eval_float_op(ira, instruction->base.scope, instruction->base.source_node, instruction->fn_id, scalar_type, |
| 23558 | 23629 | elem_operand, float_out_val); |
| 23559 | 23630 | if (msg != nullptr) { |
| 23560 | | add_error_note(ira->codegen, msg, instruction->base.base.source_node, |
| 23631 | add_error_note(ira->codegen, msg, instruction->base.source_node, |
| 23561 | 23632 | buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i)); |
| 23562 | 23633 | return ira->codegen->invalid_inst_gen; |
| 23563 | 23634 | } |
| ... | ... | @@ -23566,7 +23637,7 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat |
| 23566 | 23637 | out_val->type = operand_type; |
| 23567 | 23638 | out_val->special = ConstValSpecialStatic; |
| 23568 | 23639 | } else { |
| 23569 | | if (ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type, |
| 23640 | if (ir_eval_float_op(ira, instruction->base.scope, instruction->base.source_node, instruction->fn_id, scalar_type, |
| 23570 | 23641 | operand_val, out_val) != nullptr) |
| 23571 | 23642 | { |
| 23572 | 23643 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -23575,9 +23646,9 @@ static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloat |
| 23575 | 23646 | return result; |
| 23576 | 23647 | } |
| 23577 | 23648 | |
| 23578 | | ir_assert(scalar_type->id == ZigTypeIdFloat, &instruction->base.base); |
| 23649 | src_assert(scalar_type->id == ZigTypeIdFloat, instruction->base.source_node); |
| 23579 | 23650 | |
| 23580 | | return ir_build_float_op_gen(ira, &instruction->base.base, operand, instruction->fn_id, operand_type); |
| 23651 | return ir_build_float_op_gen(ira, instruction->base.scope, instruction->base.source_node, operand, instruction->fn_id, operand_type); |
| 23581 | 23652 | } |
| 23582 | 23653 | |
| 23583 | 23654 | static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *instruction) { |
| ... | ... | @@ -23617,7 +23688,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i |
| 23617 | 23688 | return op; |
| 23618 | 23689 | |
| 23619 | 23690 | if (int_type->data.integral.bit_count % 8 != 0) { |
| 23620 | | ir_add_error(ira, &instruction->op->base, |
| 23691 | ir_add_error_node(ira, instruction->op->source_node, |
| 23621 | 23692 | buf_sprintf("@byteSwap integer type '%s' has %" PRIu32 " bits which is not evenly divisible by 8", |
| 23622 | 23693 | buf_ptr(&int_type->name), int_type->data.integral.bit_count)); |
| 23623 | 23694 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -23628,9 +23699,9 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i |
| 23628 | 23699 | if (val == nullptr) |
| 23629 | 23700 | return ira->codegen->invalid_inst_gen; |
| 23630 | 23701 | if (val->special == ConstValSpecialUndef) |
| 23631 | | return ir_const_undef(ira, &instruction->base.base, op_type); |
| 23702 | return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, op_type); |
| 23632 | 23703 | |
| 23633 | | IrInstGen *result = ir_const(ira, &instruction->base.base, op_type); |
| 23704 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, op_type); |
| 23634 | 23705 | const size_t buf_size = int_type->data.integral.bit_count / 8; |
| 23635 | 23706 | uint8_t *buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size); |
| 23636 | 23707 | if (is_vector) { |
| ... | ... | @@ -23638,7 +23709,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i |
| 23638 | 23709 | result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(op_type->data.vector.len); |
| 23639 | 23710 | for (unsigned i = 0; i < op_type->data.vector.len; i += 1) { |
| 23640 | 23711 | ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i]; |
| 23641 | | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.base.source_node, |
| 23712 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node, |
| 23642 | 23713 | op_elem_val, UndefOk))) |
| 23643 | 23714 | { |
| 23644 | 23715 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -23663,7 +23734,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i |
| 23663 | 23734 | return result; |
| 23664 | 23735 | } |
| 23665 | 23736 | |
| 23666 | | return ir_build_bswap_gen(ira, &instruction->base.base, op_type, op); |
| 23737 | return ir_build_bswap_gen(ira, instruction->base.scope, instruction->base.source_node, op_type, op); |
| 23667 | 23738 | } |
| 23668 | 23739 | |
| 23669 | 23740 | static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBitReverse *instruction) { |
| ... | ... | @@ -23676,7 +23747,7 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi |
| 23676 | 23747 | return ira->codegen->invalid_inst_gen; |
| 23677 | 23748 | |
| 23678 | 23749 | if (int_type->data.integral.bit_count == 0) { |
| 23679 | | IrInstGen *result = ir_const(ira, &instruction->base.base, int_type); |
| 23750 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, int_type); |
| 23680 | 23751 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 23681 | 23752 | return result; |
| 23682 | 23753 | } |
| ... | ... | @@ -23686,9 +23757,9 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi |
| 23686 | 23757 | if (val == nullptr) |
| 23687 | 23758 | return ira->codegen->invalid_inst_gen; |
| 23688 | 23759 | if (val->special == ConstValSpecialUndef) |
| 23689 | | return ir_const_undef(ira, &instruction->base.base, int_type); |
| 23760 | return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, int_type); |
| 23690 | 23761 | |
| 23691 | | IrInstGen *result = ir_const(ira, &instruction->base.base, int_type); |
| 23762 | IrInstGen *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, int_type); |
| 23692 | 23763 | size_t num_bits = int_type->data.integral.bit_count; |
| 23693 | 23764 | size_t buf_size = (num_bits + 7) / 8; |
| 23694 | 23765 | uint8_t *comptime_buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size); |
| ... | ... | @@ -23717,7 +23788,7 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi |
| 23717 | 23788 | return result; |
| 23718 | 23789 | } |
| 23719 | 23790 | |
| 23720 | | return ir_build_bit_reverse_gen(ira, &instruction->base.base, int_type, op); |
| 23791 | return ir_build_bit_reverse_gen(ira, instruction->base.scope, instruction->base.source_node, int_type, op); |
| 23721 | 23792 | } |
| 23722 | 23793 | |
| 23723 | 23794 | |
| ... | ... | @@ -23726,7 +23797,7 @@ static IrInstGen *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstSrcEn |
| 23726 | 23797 | if (type_is_invalid(target->value->type)) |
| 23727 | 23798 | return ira->codegen->invalid_inst_gen; |
| 23728 | 23799 | |
| 23729 | | return ir_analyze_enum_to_int(ira, &instruction->base.base, target); |
| 23800 | return ir_analyze_enum_to_int(ira, instruction->base.scope, instruction->base.source_node, target); |
| 23730 | 23801 | } |
| 23731 | 23802 | |
| 23732 | 23803 | static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIntToEnum *instruction) { |
| ... | ... | @@ -23737,7 +23808,7 @@ static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIn |
| 23737 | 23808 | return ira->codegen->invalid_inst_gen; |
| 23738 | 23809 | |
| 23739 | 23810 | if (dest_type->id != ZigTypeIdEnum) { |
| 23740 | | ir_add_error(ira, &instruction->dest_type->base, |
| 23811 | ir_add_error_node(ira, instruction->dest_type->source_node, |
| 23741 | 23812 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name))); |
| 23742 | 23813 | return ira->codegen->invalid_inst_gen; |
| 23743 | 23814 | } |
| ... | ... | @@ -23755,7 +23826,7 @@ static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIn |
| 23755 | 23826 | if (type_is_invalid(casted_target->value->type)) |
| 23756 | 23827 | return ira->codegen->invalid_inst_gen; |
| 23757 | 23828 | |
| 23758 | | return ir_analyze_int_to_enum(ira, &instruction->base.base, casted_target, dest_type); |
| 23829 | return ir_analyze_int_to_enum(ira, instruction->base.scope, instruction->base.source_node, casted_target, dest_type); |
| 23759 | 23830 | } |
| 23760 | 23831 | |
| 23761 | 23832 | static IrInstGen *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstSrcCheckRuntimeScope *instruction) { |
| ... | ... | @@ -23770,14 +23841,14 @@ static IrInstGen *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrI |
| 23770 | 23841 | return ira->codegen->invalid_inst_gen; |
| 23771 | 23842 | |
| 23772 | 23843 | if (!scope_is_comptime && is_comptime) { |
| 23773 | | ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, |
| 23844 | ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node, |
| 23774 | 23845 | buf_sprintf("comptime control flow inside runtime block")); |
| 23775 | | add_error_note(ira->codegen, msg, block_comptime_inst->base.source_node, |
| 23846 | add_error_note(ira->codegen, msg, block_comptime_inst->source_node, |
| 23776 | 23847 | buf_sprintf("runtime block created here")); |
| 23777 | 23848 | return ira->codegen->invalid_inst_gen; |
| 23778 | 23849 | } |
| 23779 | 23850 | |
| 23780 | | return ir_const_void(ira, &instruction->base.base); |
| 23851 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 23781 | 23852 | } |
| 23782 | 23853 | |
| 23783 | 23854 | static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDecl *instruction) { |
| ... | ... | @@ -23790,7 +23861,7 @@ static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDe |
| 23790 | 23861 | return ira->codegen->invalid_inst_gen; |
| 23791 | 23862 | |
| 23792 | 23863 | if (!is_container(container_type)) { |
| 23793 | | ir_add_error(ira, &instruction->container->base, |
| 23864 | ir_add_error_node(ira, instruction->container->source_node, |
| 23794 | 23865 | buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&container_type->name))); |
| 23795 | 23866 | return ira->codegen->invalid_inst_gen; |
| 23796 | 23867 | } |
| ... | ... | @@ -23798,13 +23869,13 @@ static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDe |
| 23798 | 23869 | ScopeDecls *container_scope = get_container_scope(container_type); |
| 23799 | 23870 | Tld *tld = find_container_decl(ira->codegen, container_scope, name); |
| 23800 | 23871 | if (tld == nullptr) |
| 23801 | | return ir_const_bool(ira, &instruction->base.base, false); |
| 23872 | return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false); |
| 23802 | 23873 | |
| 23803 | | if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.base.scope)) { |
| 23804 | | return ir_const_bool(ira, &instruction->base.base, false); |
| 23874 | if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.scope)) { |
| 23875 | return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, false); |
| 23805 | 23876 | } |
| 23806 | 23877 | |
| 23807 | | return ir_const_bool(ira, &instruction->base.base, true); |
| 23878 | return ir_const_bool(ira, instruction->base.scope, instruction->base.source_node, true); |
| 23808 | 23879 | } |
| 23809 | 23880 | |
| 23810 | 23881 | static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode *node, Buf *var_name) { |
| ... | ... | @@ -23826,9 +23897,9 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode |
| 23826 | 23897 | static IrInstGen *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstSrcUndeclaredIdent *instruction) { |
| 23827 | 23898 | // put a variable of same name with invalid type in global scope |
| 23828 | 23899 | // so that future references to this same name will find a variable with an invalid type |
| 23829 | | populate_invalid_variable_in_scope(ira->codegen, instruction->base.base.scope, |
| 23830 | | instruction->base.base.source_node, instruction->name); |
| 23831 | | ir_add_error(ira, &instruction->base.base, |
| 23900 | populate_invalid_variable_in_scope(ira->codegen, instruction->base.scope, |
| 23901 | instruction->base.source_node, instruction->name); |
| 23902 | ir_add_error_node(ira, instruction->base.source_node, |
| 23832 | 23903 | buf_sprintf("use of undeclared identifier '%s'", buf_ptr(instruction->name))); |
| 23833 | 23904 | return ira->codegen->invalid_inst_gen; |
| 23834 | 23905 | } |
| ... | ... | @@ -23839,7 +23910,7 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx |
| 23839 | 23910 | return ira->codegen->invalid_inst_gen; |
| 23840 | 23911 | |
| 23841 | 23912 | bool was_written = instruction->result_loc->written; |
| 23842 | | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 23913 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 23843 | 23914 | value->value->type, value, false, true); |
| 23844 | 23915 | if (result_loc != nullptr) { |
| 23845 | 23916 | if (type_is_invalid(result_loc->value->type)) |
| ... | ... | @@ -23848,7 +23919,7 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx |
| 23848 | 23919 | return result_loc; |
| 23849 | 23920 | |
| 23850 | 23921 | if (!was_written || instruction->result_loc->id == ResultLocIdPeer) { |
| 23851 | | IrInstGen *store_ptr = ir_analyze_store_ptr(ira, &instruction->base.base, result_loc, value, |
| 23922 | IrInstGen *store_ptr = ir_analyze_store_ptr(ira, instruction->base.scope, instruction->base.source_node, result_loc, value, |
| 23852 | 23923 | instruction->result_loc->allow_write_through_const); |
| 23853 | 23924 | if (type_is_invalid(store_ptr->value->type)) { |
| 23854 | 23925 | if (instruction->result_loc->id == ResultLocIdReturn && |
| ... | ... | @@ -23873,7 +23944,7 @@ static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndEx |
| 23873 | 23944 | } |
| 23874 | 23945 | } |
| 23875 | 23946 | |
| 23876 | | return ir_const_void(ira, &instruction->base.base); |
| 23947 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 23877 | 23948 | } |
| 23878 | 23949 | |
| 23879 | 23950 | static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrcImplicitCast *instruction) { |
| ... | ... | @@ -23884,7 +23955,8 @@ static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrc |
| 23884 | 23955 | ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child); |
| 23885 | 23956 | if (type_is_invalid(dest_type)) |
| 23886 | 23957 | return ira->codegen->invalid_inst_gen; |
| 23887 | | return ir_implicit_cast2(ira, &instruction->base.base, operand, dest_type); |
| 23958 | return ir_implicit_cast2(ira, instruction->base.scope, instruction->base.source_node, |
| 23959 | operand, dest_type); |
| 23888 | 23960 | } |
| 23889 | 23961 | |
| 23890 | 23962 | static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcBitCast *instruction) { |
| ... | ... | @@ -23892,7 +23964,7 @@ static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcB |
| 23892 | 23964 | if (type_is_invalid(operand->value->type)) |
| 23893 | 23965 | return operand; |
| 23894 | 23966 | |
| 23895 | | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, |
| 23967 | IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base, |
| 23896 | 23968 | &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, true); |
| 23897 | 23969 | if (result_loc != nullptr && |
| 23898 | 23970 | (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) |
| ... | ... | @@ -23904,7 +23976,7 @@ static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcB |
| 23904 | 23976 | instruction->result_loc_bit_cast->base.source_instruction->child); |
| 23905 | 23977 | if (type_is_invalid(dest_type)) |
| 23906 | 23978 | return ira->codegen->invalid_inst_gen; |
| 23907 | | return ir_analyze_bit_cast(ira, &instruction->base.base, operand, dest_type); |
| 23979 | return ir_analyze_bit_cast(ira, instruction->base.scope, instruction->base.source_node, operand, dest_type); |
| 23908 | 23980 | } |
| 23909 | 23981 | |
| 23910 | 23982 | static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira, |
| ... | ... | @@ -23915,7 +23987,7 @@ static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira, |
| 23915 | 23987 | return ira->codegen->invalid_inst_gen; |
| 23916 | 23988 | |
| 23917 | 23989 | if (union_type->id != ZigTypeIdUnion) { |
| 23918 | | ir_add_error(ira, &instruction->union_type->base, |
| 23990 | ir_add_error_node(ira, instruction->union_type->source_node, |
| 23919 | 23991 | buf_sprintf("non-union type '%s' passed to @unionInit", buf_ptr(&union_type->name))); |
| 23920 | 23992 | return ira->codegen->invalid_inst_gen; |
| 23921 | 23993 | } |
| ... | ... | @@ -23932,32 +24004,32 @@ static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira, |
| 23932 | 24004 | if (type_is_invalid(result_loc->value->type)) |
| 23933 | 24005 | return ira->codegen->invalid_inst_gen; |
| 23934 | 24006 | |
| 23935 | | return ir_analyze_union_init(ira, &instruction->base.base, instruction->base.base.source_node, |
| 24007 | return ir_analyze_union_init(ira, instruction->base.scope, instruction->base.source_node, instruction->base.source_node, |
| 23936 | 24008 | union_type, field_name, field_result_loc, result_loc); |
| 23937 | 24009 | } |
| 23938 | 24010 | |
| 23939 | 24011 | static IrInstGen *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstSrcSuspendBegin *instruction) { |
| 23940 | | return ir_build_suspend_begin_gen(ira, &instruction->base.base); |
| 24012 | return ir_build_suspend_begin_gen(ira, instruction->base.scope, instruction->base.source_node); |
| 23941 | 24013 | } |
| 23942 | 24014 | |
| 23943 | 24015 | static IrInstGen *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, IrInstSrcSuspendFinish *instruction) { |
| 23944 | 24016 | IrInstGen *begin_base = instruction->begin->base.child; |
| 23945 | 24017 | if (type_is_invalid(begin_base->value->type)) |
| 23946 | 24018 | return ira->codegen->invalid_inst_gen; |
| 23947 | | ir_assert(begin_base->id == IrInstGenIdSuspendBegin, &instruction->base.base); |
| 24019 | src_assert(begin_base->id == IrInstGenIdSuspendBegin, instruction->base.source_node); |
| 23948 | 24020 | IrInstGenSuspendBegin *begin = reinterpret_cast<IrInstGenSuspendBegin *>(begin_base); |
| 23949 | 24021 | |
| 23950 | 24022 | ZigFn *fn_entry = ira->fn; |
| 23951 | | ir_assert(fn_entry != nullptr, &instruction->base.base); |
| 24023 | src_assert(fn_entry != nullptr, instruction->base.source_node); |
| 23952 | 24024 | |
| 23953 | 24025 | if (fn_entry->inferred_async_node == nullptr) { |
| 23954 | | fn_entry->inferred_async_node = instruction->base.base.source_node; |
| 24026 | fn_entry->inferred_async_node = instruction->base.source_node; |
| 23955 | 24027 | } |
| 23956 | 24028 | |
| 23957 | | return ir_build_suspend_finish_gen(ira, &instruction->base.base, begin); |
| 24029 | return ir_build_suspend_finish_gen(ira, instruction->base.scope, instruction->base.source_node, begin); |
| 23958 | 24030 | } |
| 23959 | 24031 | |
| 23960 | | static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source_instr, |
| 24032 | static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, Scope *scope, AstNode *source_node, |
| 23961 | 24033 | IrInstGen *frame_ptr, ZigFn **target_fn) |
| 23962 | 24034 | { |
| 23963 | 24035 | if (type_is_invalid(frame_ptr->value->type)) |
| ... | ... | @@ -23976,7 +24048,7 @@ static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source |
| 23976 | 24048 | *target_fn = func; |
| 23977 | 24049 | frame = frame_ptr; |
| 23978 | 24050 | } else { |
| 23979 | | frame = ir_get_deref(ira, source_instr, frame_ptr, nullptr); |
| 24051 | frame = ir_get_deref(ira, scope, source_node, frame_ptr, nullptr); |
| 23980 | 24052 | if (frame->value->type->id == ZigTypeIdPointer && |
| 23981 | 24053 | frame->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 23982 | 24054 | frame->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| ... | ... | @@ -23987,7 +24059,7 @@ static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source |
| 23987 | 24059 | } else if (frame->value->type->id != ZigTypeIdAnyFrame || |
| 23988 | 24060 | frame->value->type->data.any_frame.result_type == nullptr) |
| 23989 | 24061 | { |
| 23990 | | ir_add_error(ira, source_instr, |
| 24062 | ir_add_error_node(ira, source_node, |
| 23991 | 24063 | buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name))); |
| 23992 | 24064 | return ira->codegen->invalid_inst_gen; |
| 23993 | 24065 | } else { |
| ... | ... | @@ -24008,19 +24080,19 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i |
| 24008 | 24080 | if (type_is_invalid(operand->value->type)) |
| 24009 | 24081 | return ira->codegen->invalid_inst_gen; |
| 24010 | 24082 | ZigFn *target_fn; |
| 24011 | | IrInstGen *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base.base, operand, &target_fn); |
| 24083 | IrInstGen *frame = analyze_frame_ptr_to_anyframe_T(ira, instruction->base.scope, instruction->base.source_node, operand, &target_fn); |
| 24012 | 24084 | if (type_is_invalid(frame->value->type)) |
| 24013 | 24085 | return ira->codegen->invalid_inst_gen; |
| 24014 | 24086 | |
| 24015 | 24087 | ZigType *result_type = frame->value->type->data.any_frame.result_type; |
| 24016 | 24088 | |
| 24017 | 24089 | ZigFn *fn_entry = ira->fn; |
| 24018 | | ir_assert(fn_entry != nullptr, &instruction->base.base); |
| 24090 | src_assert(fn_entry != nullptr, instruction->base.source_node); |
| 24019 | 24091 | |
| 24020 | 24092 | // If it's not @Frame(func) then it's definitely a suspend point |
| 24021 | 24093 | if (target_fn == nullptr && !instruction->is_nosuspend) { |
| 24022 | 24094 | if (fn_entry->inferred_async_node == nullptr) { |
| 24023 | | fn_entry->inferred_async_node = instruction->base.base.source_node; |
| 24095 | fn_entry->inferred_async_node = instruction->base.source_node; |
| 24024 | 24096 | } |
| 24025 | 24097 | } |
| 24026 | 24098 | |
| ... | ... | @@ -24030,7 +24102,7 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i |
| 24030 | 24102 | |
| 24031 | 24103 | IrInstGen *result_loc; |
| 24032 | 24104 | if (type_has_bits(ira->codegen, result_type)) { |
| 24033 | | result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc, |
| 24105 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 24034 | 24106 | result_type, nullptr, true, true); |
| 24035 | 24107 | if (result_loc != nullptr && |
| 24036 | 24108 | (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) |
| ... | ... | @@ -24041,7 +24113,7 @@ static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *i |
| 24041 | 24113 | result_loc = nullptr; |
| 24042 | 24114 | } |
| 24043 | 24115 | |
| 24044 | | IrInstGenAwait *result = ir_build_await_gen(ira, &instruction->base.base, frame, result_type, result_loc, |
| 24116 | IrInstGenAwait *result = ir_build_await_gen(ira, instruction->base.scope, instruction->base.source_node, frame, result_type, result_loc, |
| 24045 | 24117 | instruction->is_nosuspend); |
| 24046 | 24118 | result->target_fn = target_fn; |
| 24047 | 24119 | fn_entry->await_list.append(result); |
| ... | ... | @@ -24060,27 +24132,29 @@ static IrInstGen *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstSrcResume |
| 24060 | 24132 | { |
| 24061 | 24133 | frame = frame_ptr; |
| 24062 | 24134 | } else { |
| 24063 | | frame = ir_get_deref(ira, &instruction->base.base, frame_ptr, nullptr); |
| 24135 | frame = ir_get_deref(ira, instruction->base.scope, instruction->base.source_node, |
| 24136 | frame_ptr, nullptr); |
| 24064 | 24137 | } |
| 24065 | 24138 | |
| 24066 | 24139 | ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr); |
| 24067 | | IrInstGen *casted_frame = ir_implicit_cast2(ira, &instruction->frame->base, frame, any_frame_type); |
| 24140 | IrInstGen *casted_frame = ir_implicit_cast2(ira, instruction->frame->scope, |
| 24141 | instruction->frame->source_node, frame, any_frame_type); |
| 24068 | 24142 | if (type_is_invalid(casted_frame->value->type)) |
| 24069 | 24143 | return ira->codegen->invalid_inst_gen; |
| 24070 | 24144 | |
| 24071 | | return ir_build_resume_gen(ira, &instruction->base.base, casted_frame); |
| 24145 | return ir_build_resume_gen(ira, instruction->base.scope, instruction->base.source_node, casted_frame); |
| 24072 | 24146 | } |
| 24073 | 24147 | |
| 24074 | 24148 | static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSpillBegin *instruction) { |
| 24075 | | if (ir_should_inline(ira->zir, instruction->base.base.scope)) |
| 24076 | | return ir_const_void(ira, &instruction->base.base); |
| 24149 | if (ir_should_inline(ira->zir, instruction->base.scope)) |
| 24150 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 24077 | 24151 | |
| 24078 | 24152 | IrInstGen *operand = instruction->operand->child; |
| 24079 | 24153 | if (type_is_invalid(operand->value->type)) |
| 24080 | 24154 | return ira->codegen->invalid_inst_gen; |
| 24081 | 24155 | |
| 24082 | 24156 | if (!type_has_bits(ira->codegen, operand->value->type)) |
| 24083 | | return ir_const_void(ira, &instruction->base.base); |
| 24157 | return ir_const_void(ira, instruction->base.scope, instruction->base.source_node); |
| 24084 | 24158 | |
| 24085 | 24159 | switch (instruction->spill_id) { |
| 24086 | 24160 | case SpillIdInvalid: |
| ... | ... | @@ -24090,7 +24164,7 @@ static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSp |
| 24090 | 24164 | break; |
| 24091 | 24165 | } |
| 24092 | 24166 | |
| 24093 | | return ir_build_spill_begin_gen(ira, &instruction->base.base, operand, instruction->spill_id); |
| 24167 | return ir_build_spill_begin_gen(ira, instruction->base.scope, instruction->base.source_node, operand, instruction->spill_id); |
| 24094 | 24168 | } |
| 24095 | 24169 | |
| 24096 | 24170 | static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpillEnd *instruction) { |
| ... | ... | @@ -24098,23 +24172,23 @@ static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpil |
| 24098 | 24172 | if (type_is_invalid(operand->value->type)) |
| 24099 | 24173 | return ira->codegen->invalid_inst_gen; |
| 24100 | 24174 | |
| 24101 | | if (ir_should_inline(ira->zir, instruction->base.base.scope) || |
| 24175 | if (ir_should_inline(ira->zir, instruction->base.scope) || |
| 24102 | 24176 | !type_has_bits(ira->codegen, operand->value->type) || |
| 24103 | 24177 | instr_is_comptime(operand)) |
| 24104 | 24178 | { |
| 24105 | 24179 | return operand; |
| 24106 | 24180 | } |
| 24107 | 24181 | |
| 24108 | | ir_assert(instruction->begin->base.child->id == IrInstGenIdSpillBegin, &instruction->base.base); |
| 24182 | src_assert(instruction->begin->base.child->id == IrInstGenIdSpillBegin, instruction->base.source_node); |
| 24109 | 24183 | IrInstGenSpillBegin *begin = reinterpret_cast<IrInstGenSpillBegin *>(instruction->begin->base.child); |
| 24110 | 24184 | |
| 24111 | | return ir_build_spill_end_gen(ira, &instruction->base.base, begin, operand->value->type); |
| 24185 | return ir_build_spill_end_gen(ira, instruction->base.scope, instruction->base.source_node, begin, operand->value->type); |
| 24112 | 24186 | } |
| 24113 | 24187 | |
| 24114 | 24188 | static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instruction) { |
| 24115 | | ZigFn *fn_entry = scope_fn_entry(instruction->base.base.scope); |
| 24189 | ZigFn *fn_entry = scope_fn_entry(instruction->base.scope); |
| 24116 | 24190 | if (fn_entry == nullptr) { |
| 24117 | | ir_add_error(ira, &instruction->base.base, buf_sprintf("@src outside function")); |
| 24191 | ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("@src outside function")); |
| 24118 | 24192 | return ira->codegen->invalid_inst_gen; |
| 24119 | 24193 | } |
| 24120 | 24194 | |
| ... | ... | @@ -24140,7 +24214,7 @@ static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instr |
| 24140 | 24214 | ensure_field_index(source_location_type, "file", 0); |
| 24141 | 24215 | fields[0]->special = ConstValSpecialStatic; |
| 24142 | 24216 | |
| 24143 | | ZigType *import = instruction->base.base.source_node->owner; |
| 24217 | ZigType *import = instruction->base.source_node->owner; |
| 24144 | 24218 | RootStruct *root_struct = import->data.structure.root_struct; |
| 24145 | 24219 | Buf *path = root_struct->path; |
| 24146 | 24220 | ZigValue *file_name = create_const_str_lit(ira->codegen, path)->data.x_ptr.data.ref.pointee; |
| ... | ... | @@ -24156,7 +24230,7 @@ static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instr |
| 24156 | 24230 | fields[1]->type = u8_slice; |
| 24157 | 24231 | |
| 24158 | 24232 | |
| 24159 | | TokenLoc tok_loc = root_struct->token_locs[instruction->base.base.source_node->main_token]; |
| 24233 | TokenLoc tok_loc = root_struct->token_locs[instruction->base.source_node->main_token]; |
| 24160 | 24234 | |
| 24161 | 24235 | // line: u32 |
| 24162 | 24236 | ensure_field_index(source_location_type, "line", 2); |
| ... | ... | @@ -24170,7 +24244,7 @@ static IrInstGen *ir_analyze_instruction_src(IrAnalyze *ira, IrInstSrcSrc *instr |
| 24170 | 24244 | fields[3]->type = ira->codegen->builtin_types.entry_u32; |
| 24171 | 24245 | bigint_init_unsigned(&fields[3]->data.x_bigint, tok_loc.column + 1); |
| 24172 | 24246 | |
| 24173 | | return ir_const_move(ira, &instruction->base.base, result); |
| 24247 | return ir_const_move(ira, instruction->base.scope, instruction->base.source_node, result); |
| 24174 | 24248 | } |
| 24175 | 24249 | |
| 24176 | 24250 | static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruction) { |
| ... | ... | @@ -24507,7 +24581,7 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_a |
| 24507 | 24581 | while (ira->old_bb_index < ira->zir->basic_block_list.length) { |
| 24508 | 24582 | IrInstSrc *old_instruction = ira->zir_current_basic_block->instruction_list.at(ira->instruction_index); |
| 24509 | 24583 | |
| 24510 | | if (old_instruction->base.ref_count == 0 && !ir_inst_src_has_side_effects(old_instruction)) { |
| 24584 | if (old_instruction->ref_count == 0 && !ir_inst_src_has_side_effects(old_instruction)) { |
| 24511 | 24585 | ira->instruction_index += 1; |
| 24512 | 24586 | continue; |
| 24513 | 24587 | } |
| ... | ... | @@ -24518,9 +24592,10 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_a |
| 24518 | 24592 | fprintf(stderr, "~ "); |
| 24519 | 24593 | ir_print_inst_src(codegen, stderr, old_instruction, 0); |
| 24520 | 24594 | } |
| 24595 | ira->suspend_source_instr = old_instruction; |
| 24521 | 24596 | IrInstGen *new_instruction = ir_analyze_instruction_base(ira, old_instruction); |
| 24522 | 24597 | if (new_instruction != nullptr) { |
| 24523 | | ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, &old_instruction->base); |
| 24598 | src_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, old_instruction->source_node); |
| 24524 | 24599 | old_instruction->child = new_instruction; |
| 24525 | 24600 | |
| 24526 | 24601 | if (type_is_invalid(new_instruction->value->type)) { |
| ... | ... | @@ -24534,11 +24609,11 @@ ZigType *ir_analyze(CodeGen *codegen, Stage1Zir *stage1_zir, Stage1Air *stage1_a |
| 24534 | 24609 | stage1_air->first_err_trace_msg = ira->codegen->trace_err; |
| 24535 | 24610 | } |
| 24536 | 24611 | if (stage1_air->first_err_trace_msg != nullptr && |
| 24537 | | !old_instruction->base.source_node->already_traced_this_node) |
| 24612 | !old_instruction->source_node->already_traced_this_node) |
| 24538 | 24613 | { |
| 24539 | | old_instruction->base.source_node->already_traced_this_node = true; |
| 24614 | old_instruction->source_node->already_traced_this_node = true; |
| 24540 | 24615 | stage1_air->first_err_trace_msg = add_error_note(ira->codegen, stage1_air->first_err_trace_msg, |
| 24541 | | old_instruction->base.source_node, buf_create_from_str("referenced here")); |
| 24616 | old_instruction->source_node, buf_create_from_str("referenced here")); |
| 24542 | 24617 | } |
| 24543 | 24618 | return ira->codegen->builtin_types.entry_invalid; |
| 24544 | 24619 | } else if (ira->codegen->verbose_ir) { |
| ... | ... | @@ -24908,10 +24983,10 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La |
| 24908 | 24983 | |
| 24909 | 24984 | if(!is_valid_param_type(param_type)){ |
| 24910 | 24985 | if(param_type->id == ZigTypeIdOpaque){ |
| 24911 | | ir_add_error(ira, &param_type_inst->base, |
| 24986 | ir_add_error(ira, param_type_inst, |
| 24912 | 24987 | buf_sprintf("parameter of opaque type '%s' not allowed", buf_ptr(&param_type->name))); |
| 24913 | 24988 | } else { |
| 24914 | | ir_add_error(ira, &param_type_inst->base, |
| 24989 | ir_add_error(ira, param_type_inst, |
| 24915 | 24990 | buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&param_type->name))); |
| 24916 | 24991 | } |
| 24917 | 24992 | |
| ... | ... | @@ -24921,7 +24996,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La |
| 24921 | 24996 | switch (type_requires_comptime(ira->codegen, param_type)) { |
| 24922 | 24997 | case ReqCompTimeYes: |
| 24923 | 24998 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 24924 | | ir_add_error(ira, &param_type_inst->base, |
| 24999 | ir_add_error(ira, param_type_inst, |
| 24925 | 25000 | buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'", |
| 24926 | 25001 | buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc))); |
| 24927 | 25002 | return nullptr; |
| ... | ... | @@ -24939,7 +25014,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La |
| 24939 | 25014 | if ((err = type_has_bits2(ira->codegen, param_type, &has_bits))) |
| 24940 | 25015 | return nullptr; |
| 24941 | 25016 | if (!has_bits) { |
| 24942 | | ir_add_error(ira, &param_type_inst->base, |
| 25017 | ir_add_error(ira, param_type_inst, |
| 24943 | 25018 | buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'", |
| 24944 | 25019 | buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc))); |
| 24945 | 25020 | return nullptr; |
| ... | ... | @@ -24958,7 +25033,8 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La |
| 24958 | 25033 | if (type_is_invalid(fn_type_id.return_type)) |
| 24959 | 25034 | return nullptr; |
| 24960 | 25035 | if (fn_type_id.return_type->id == ZigTypeIdOpaque) { |
| 24961 | | ir_add_error(ira, &lazy_fn_type->return_type->base, buf_create_from_str("return type cannot be opaque")); |
| 25036 | ir_add_error_node(ira, lazy_fn_type->return_type->source_node, |
| 25037 | buf_create_from_str("return type cannot be opaque")); |
| 24962 | 25038 | return nullptr; |
| 24963 | 25039 | } |
| 24964 | 25040 | |
| ... | ... | @@ -24976,7 +25052,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 24976 | 25052 | LazyValueTypeInfoDecls *type_info_decls = reinterpret_cast<LazyValueTypeInfoDecls *>(val->data.x_lazy); |
| 24977 | 25053 | IrAnalyze *ira = type_info_decls->ira; |
| 24978 | 25054 | |
| 24979 | | if ((err = ir_make_type_info_decls(ira, type_info_decls->source_instr, val, type_info_decls->decls_scope, true))) |
| 25055 | if ((err = ir_make_type_info_decls(ira, type_info_decls->source_node, val, type_info_decls->decls_scope, true))) |
| 24980 | 25056 | { |
| 24981 | 25057 | return err; |
| 24982 | 25058 | }; |
| ... | ... | @@ -25002,7 +25078,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 25002 | 25078 | case ZigTypeIdBoundFn: |
| 25003 | 25079 | case ZigTypeIdVoid: |
| 25004 | 25080 | case ZigTypeIdOpaque: |
| 25005 | | ir_add_error(ira, &lazy_align_of->target_type->base, |
| 25081 | ir_add_error_node(ira, lazy_align_of->target_type->source_node, |
| 25006 | 25082 | buf_sprintf("no align available for type '%s'", |
| 25007 | 25083 | buf_ptr(&lazy_align_of->target_type->value->data.x_type->name))); |
| 25008 | 25084 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -25052,7 +25128,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 25052 | 25128 | case ZigTypeIdNull: |
| 25053 | 25129 | case ZigTypeIdBoundFn: |
| 25054 | 25130 | case ZigTypeIdOpaque: |
| 25055 | | ir_add_error(ira, &lazy_size_of->target_type->base, |
| 25131 | ir_add_error_node(ira, lazy_size_of->target_type->source_node, |
| 25056 | 25132 | buf_sprintf("no size available for type '%s'", |
| 25057 | 25133 | buf_ptr(&lazy_size_of->target_type->value->data.x_type->name))); |
| 25058 | 25134 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -25133,7 +25209,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 25133 | 25209 | case ZigTypeIdUndefined: |
| 25134 | 25210 | case ZigTypeIdNull: |
| 25135 | 25211 | case ZigTypeIdOpaque: |
| 25136 | | ir_add_error(ira, &lazy_slice_type->elem_type->base, |
| 25212 | ir_add_error_node(ira, lazy_slice_type->elem_type->source_node, |
| 25137 | 25213 | buf_sprintf("slice of type '%s' not allowed", buf_ptr(&elem_type->name))); |
| 25138 | 25214 | return ErrorSemanticAnalyzeFail; |
| 25139 | 25215 | case ZigTypeIdMetaType: |
| ... | ... | @@ -25206,11 +25282,11 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 25206 | 25282 | } |
| 25207 | 25283 | |
| 25208 | 25284 | if (elem_type->id == ZigTypeIdUnreachable) { |
| 25209 | | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 25285 | ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node, |
| 25210 | 25286 | buf_create_from_str("pointer to noreturn not allowed")); |
| 25211 | 25287 | return ErrorSemanticAnalyzeFail; |
| 25212 | 25288 | } else if (elem_type->id == ZigTypeIdOpaque && lazy_ptr_type->ptr_len == PtrLenUnknown) { |
| 25213 | | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 25289 | ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node, |
| 25214 | 25290 | buf_create_from_str("unknown-length pointer to opaque")); |
| 25215 | 25291 | return ErrorSemanticAnalyzeFail; |
| 25216 | 25292 | } else if (lazy_ptr_type->ptr_len == PtrLenC) { |
| ... | ... | @@ -25218,16 +25294,16 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 25218 | 25294 | if ((err = type_allowed_in_extern(ira->codegen, elem_type, ExternPositionOther, &ok_type))) |
| 25219 | 25295 | return err; |
| 25220 | 25296 | if (!ok_type) { |
| 25221 | | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 25297 | ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node, |
| 25222 | 25298 | buf_sprintf("C pointers cannot point to non-C-ABI-compatible type '%s'", |
| 25223 | 25299 | buf_ptr(&elem_type->name))); |
| 25224 | 25300 | return ErrorSemanticAnalyzeFail; |
| 25225 | 25301 | } else if (elem_type->id == ZigTypeIdOpaque) { |
| 25226 | | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 25302 | ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node, |
| 25227 | 25303 | buf_sprintf("C pointers cannot point to opaque types")); |
| 25228 | 25304 | return ErrorSemanticAnalyzeFail; |
| 25229 | 25305 | } else if (lazy_ptr_type->is_allowzero) { |
| 25230 | | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 25306 | ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node, |
| 25231 | 25307 | buf_sprintf("C pointers always allow address zero")); |
| 25232 | 25308 | return ErrorSemanticAnalyzeFail; |
| 25233 | 25309 | } |
| ... | ... | @@ -25259,7 +25335,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 25259 | 25335 | return ErrorSemanticAnalyzeFail; |
| 25260 | 25336 | |
| 25261 | 25337 | if (elem_type->id == ZigTypeIdUnreachable) { |
| 25262 | | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 25338 | ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node, |
| 25263 | 25339 | buf_create_from_str("pointer to noreturn not allowed")); |
| 25264 | 25340 | return ErrorSemanticAnalyzeFail; |
| 25265 | 25341 | } |
| ... | ... | @@ -25283,7 +25359,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 25283 | 25359 | return ErrorSemanticAnalyzeFail; |
| 25284 | 25360 | |
| 25285 | 25361 | if (elem_type->id == ZigTypeIdUnreachable) { |
| 25286 | | ir_add_error(ira, &lazy_ptr_type->elem_type->base, |
| 25362 | ir_add_error_node(ira, lazy_ptr_type->elem_type->source_node, |
| 25287 | 25363 | buf_create_from_str("pointer to noreturn not allowed")); |
| 25288 | 25364 | return ErrorSemanticAnalyzeFail; |
| 25289 | 25365 | } |
| ... | ... | @@ -25313,7 +25389,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 25313 | 25389 | case ZigTypeIdUndefined: |
| 25314 | 25390 | case ZigTypeIdNull: |
| 25315 | 25391 | case ZigTypeIdOpaque: |
| 25316 | | ir_add_error(ira, &lazy_array_type->elem_type->base, |
| 25392 | ir_add_error_node(ira, lazy_array_type->elem_type->source_node, |
| 25317 | 25393 | buf_sprintf("array of type '%s' not allowed", |
| 25318 | 25394 | buf_ptr(&elem_type->name))); |
| 25319 | 25395 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -25377,7 +25453,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 25377 | 25453 | return ErrorSemanticAnalyzeFail; |
| 25378 | 25454 | |
| 25379 | 25455 | if (payload_type->id == ZigTypeIdOpaque || payload_type->id == ZigTypeIdUnreachable) { |
| 25380 | | ir_add_error(ira, &lazy_opt_type->payload_type->base, |
| 25456 | ir_add_error_node(ira, lazy_opt_type->payload_type->source_node, |
| 25381 | 25457 | buf_sprintf("type '%s' cannot be optional", buf_ptr(&payload_type->name))); |
| 25382 | 25458 | return ErrorSemanticAnalyzeFail; |
| 25383 | 25459 | } |
| ... | ... | @@ -25419,7 +25495,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 25419 | 25495 | return ErrorSemanticAnalyzeFail; |
| 25420 | 25496 | |
| 25421 | 25497 | if (err_set_type->id != ZigTypeIdErrorSet) { |
| 25422 | | ir_add_error(ira, &lazy_err_union_type->err_set_type->base, |
| 25498 | ir_add_error_node(ira, lazy_err_union_type->err_set_type->source_node, |
| 25423 | 25499 | buf_sprintf("expected error set type, found type '%s'", |
| 25424 | 25500 | buf_ptr(&err_set_type->name))); |
| 25425 | 25501 | return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -25455,8 +25531,8 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) { |
| 25455 | 25531 | return ErrorNone; |
| 25456 | 25532 | } |
| 25457 | 25533 | |
| 25458 | | void IrInst::src() { |
| 25459 | | IrInst *inst = this; |
| 25534 | void IrInstGen::src() { |
| 25535 | IrInstGen *inst = this; |
| 25460 | 25536 | if (inst->source_node != nullptr) { |
| 25461 | 25537 | inst->source_node->src(); |
| 25462 | 25538 | } else { |
| ... | ... | @@ -25464,37 +25540,13 @@ void IrInst::src() { |
| 25464 | 25540 | } |
| 25465 | 25541 | } |
| 25466 | 25542 | |
| 25467 | | void IrInst::dump() { |
| 25468 | | this->src(); |
| 25469 | | fprintf(stderr, "IrInst(#%" PRIu32 ")\n", this->debug_id); |
| 25470 | | } |
| 25471 | | |
| 25472 | | void IrInstSrc::src() { |
| 25473 | | this->base.src(); |
| 25474 | | } |
| 25475 | | |
| 25476 | | void IrInstGen::src() { |
| 25477 | | this->base.src(); |
| 25478 | | } |
| 25479 | | |
| 25480 | | void IrInstSrc::dump() { |
| 25481 | | IrInstSrc *inst = this; |
| 25482 | | inst->src(); |
| 25483 | | if (inst->base.scope == nullptr) { |
| 25484 | | fprintf(stderr, "(null scope)\n"); |
| 25485 | | } else { |
| 25486 | | ir_print_inst_src(inst->base.scope->codegen, stderr, inst, 0); |
| 25487 | | fprintf(stderr, "-> "); |
| 25488 | | ir_print_inst_gen(inst->base.scope->codegen, stderr, inst->child, 0); |
| 25489 | | } |
| 25490 | | } |
| 25491 | 25543 | void IrInstGen::dump() { |
| 25492 | 25544 | IrInstGen *inst = this; |
| 25493 | 25545 | inst->src(); |
| 25494 | | if (inst->base.scope == nullptr) { |
| 25546 | if (inst->scope == nullptr) { |
| 25495 | 25547 | fprintf(stderr, "(null scope)\n"); |
| 25496 | 25548 | } else { |
| 25497 | | ir_print_inst_gen(inst->base.scope->codegen, stderr, inst, 0); |
| 25549 | ir_print_inst_gen(inst->scope->codegen, stderr, inst, 0); |
| 25498 | 25550 | } |
| 25499 | 25551 | } |
| 25500 | 25552 | |