| ... | ... | @@ -140,7 +140,7 @@ struct ConstCastErrSetMismatch { |
| 140 | 140 | |
| 141 | 141 | static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope); |
| 142 | 142 | static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval); |
| 143 | | static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction); |
| 143 | static IrInstruction *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction); |
| 144 | 144 | static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type); |
| 145 | 145 | static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr); |
| 146 | 146 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg); |
| ... | ... | @@ -261,11 +261,6 @@ static bool instr_is_unreachable(IrInstruction *instruction) { |
| 261 | 261 | return instruction->value.type && instruction->value.type->id == ZigTypeIdUnreachable; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | | static void ir_link_new_instruction(IrInstruction *new_instruction, IrInstruction *old_instruction) { |
| 265 | | new_instruction->other = old_instruction; |
| 266 | | old_instruction->other = new_instruction; |
| 267 | | } |
| 268 | | |
| 269 | 264 | static void ir_link_new_bb(IrBasicBlock *new_bb, IrBasicBlock *old_bb) { |
| 270 | 265 | new_bb->other = old_bb; |
| 271 | 266 | old_bb->other = new_bb; |
| ... | ... | @@ -919,15 +914,6 @@ static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *so |
| 919 | 914 | return &cond_br_instruction->base; |
| 920 | 915 | } |
| 921 | 916 | |
| 922 | | static IrInstruction *ir_build_cond_br_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 923 | | IrInstruction *condition, IrBasicBlock *then_block, IrBasicBlock *else_block, IrInstruction *is_comptime) |
| 924 | | { |
| 925 | | IrInstruction *new_instruction = ir_build_cond_br(irb, old_instruction->scope, old_instruction->source_node, |
| 926 | | condition, then_block, else_block, is_comptime); |
| 927 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 928 | | return new_instruction; |
| 929 | | } |
| 930 | | |
| 931 | 917 | static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *return_value) { |
| 932 | 918 | IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node); |
| 933 | 919 | return_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| ... | ... | @@ -1098,15 +1084,6 @@ static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1098 | 1084 | return &bin_op_instruction->base; |
| 1099 | 1085 | } |
| 1100 | 1086 | |
| 1101 | | static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_instruction, IrBinOp op_id, |
| 1102 | | IrInstruction *op1, IrInstruction *op2, bool safety_check_on) |
| 1103 | | { |
| 1104 | | IrInstruction *new_instruction = ir_build_bin_op(irb, old_instruction->scope, |
| 1105 | | old_instruction->source_node, op_id, op1, op2, safety_check_on); |
| 1106 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1107 | | return new_instruction; |
| 1108 | | } |
| 1109 | | |
| 1110 | 1087 | static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var, |
| 1111 | 1088 | ScopeFnDef *crossed_fndef_scope) |
| 1112 | 1089 | { |
| ... | ... | @@ -1189,15 +1166,6 @@ static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, Ast |
| 1189 | 1166 | return &instruction->base; |
| 1190 | 1167 | } |
| 1191 | 1168 | |
| 1192 | | static IrInstruction *ir_build_union_field_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1193 | | IrInstruction *union_ptr, TypeUnionField *type_union_field) |
| 1194 | | { |
| 1195 | | IrInstruction *new_instruction = ir_build_union_field_ptr(irb, old_instruction->scope, |
| 1196 | | old_instruction->source_node, union_ptr, type_union_field); |
| 1197 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1198 | | return new_instruction; |
| 1199 | | } |
| 1200 | | |
| 1201 | 1169 | static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1202 | 1170 | ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, |
| 1203 | 1171 | bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator, |
| ... | ... | @@ -1226,17 +1194,6 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc |
| 1226 | 1194 | return &call_instruction->base; |
| 1227 | 1195 | } |
| 1228 | 1196 | |
| 1229 | | static IrInstruction *ir_build_call_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1230 | | ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, |
| 1231 | | bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator, |
| 1232 | | IrInstruction *new_stack) |
| 1233 | | { |
| 1234 | | IrInstruction *new_instruction = ir_build_call(irb, old_instruction->scope, |
| 1235 | | old_instruction->source_node, fn_entry, fn_ref, arg_count, args, is_comptime, fn_inline, is_async, async_allocator, new_stack); |
| 1236 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1237 | | return new_instruction; |
| 1238 | | } |
| 1239 | | |
| 1240 | 1197 | static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1241 | 1198 | size_t incoming_count, IrBasicBlock **incoming_blocks, IrInstruction **incoming_values) |
| 1242 | 1199 | { |
| ... | ... | @@ -1256,15 +1213,6 @@ static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source |
| 1256 | 1213 | return &phi_instruction->base; |
| 1257 | 1214 | } |
| 1258 | 1215 | |
| 1259 | | static IrInstruction *ir_build_phi_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1260 | | size_t incoming_count, IrBasicBlock **incoming_blocks, IrInstruction **incoming_values) |
| 1261 | | { |
| 1262 | | IrInstruction *new_instruction = ir_build_phi(irb, old_instruction->scope, old_instruction->source_node, |
| 1263 | | incoming_count, incoming_blocks, incoming_values); |
| 1264 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1265 | | return new_instruction; |
| 1266 | | } |
| 1267 | | |
| 1268 | 1216 | static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1269 | 1217 | IrBasicBlock *dest_block, IrInstruction *is_comptime) |
| 1270 | 1218 | { |
| ... | ... | @@ -1288,12 +1236,6 @@ static IrInstruction *ir_build_br(IrBuilder *irb, Scope *scope, AstNode *source_ |
| 1288 | 1236 | return instruction; |
| 1289 | 1237 | } |
| 1290 | 1238 | |
| 1291 | | static IrInstruction *ir_build_br_from(IrBuilder *irb, IrInstruction *old_instruction, IrBasicBlock *dest_block) { |
| 1292 | | IrInstruction *new_instruction = ir_build_br(irb, old_instruction->scope, old_instruction->source_node, dest_block, nullptr); |
| 1293 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1294 | | return new_instruction; |
| 1295 | | } |
| 1296 | | |
| 1297 | 1239 | static IrInstruction *ir_build_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1298 | 1240 | IrInstruction *child_type, bool is_const, bool is_volatile, PtrLen ptr_len, |
| 1299 | 1241 | IrInstruction *align_value, uint32_t bit_offset_start, uint32_t host_int_bytes) |
| ... | ... | @@ -1323,15 +1265,6 @@ static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *sour |
| 1323 | 1265 | return &br_instruction->base; |
| 1324 | 1266 | } |
| 1325 | 1267 | |
| 1326 | | static IrInstruction *ir_build_un_op_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1327 | | IrUnOp op_id, IrInstruction *value) |
| 1328 | | { |
| 1329 | | IrInstruction *new_instruction = ir_build_un_op(irb, old_instruction->scope, |
| 1330 | | old_instruction->source_node, op_id, value); |
| 1331 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1332 | | return new_instruction; |
| 1333 | | } |
| 1334 | | |
| 1335 | 1268 | static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1336 | 1269 | IrInstruction *container_type, size_t item_count, IrInstruction **items) |
| 1337 | 1270 | { |
| ... | ... | @@ -1349,15 +1282,6 @@ static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, |
| 1349 | 1282 | return &container_init_list_instruction->base; |
| 1350 | 1283 | } |
| 1351 | 1284 | |
| 1352 | | static IrInstruction *ir_build_container_init_list_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1353 | | IrInstruction *container_type, size_t item_count, IrInstruction **items) |
| 1354 | | { |
| 1355 | | IrInstruction *new_instruction = ir_build_container_init_list(irb, old_instruction->scope, |
| 1356 | | old_instruction->source_node, container_type, item_count, items); |
| 1357 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1358 | | return new_instruction; |
| 1359 | | } |
| 1360 | | |
| 1361 | 1285 | static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1362 | 1286 | IrInstruction *container_type, size_t field_count, IrInstructionContainerInitFieldsField *fields) |
| 1363 | 1287 | { |
| ... | ... | @@ -1389,15 +1313,6 @@ static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode |
| 1389 | 1313 | return &struct_init_instruction->base; |
| 1390 | 1314 | } |
| 1391 | 1315 | |
| 1392 | | static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1393 | | ZigType *struct_type, size_t field_count, IrInstructionStructInitField *fields) |
| 1394 | | { |
| 1395 | | IrInstruction *new_instruction = ir_build_struct_init(irb, old_instruction->scope, |
| 1396 | | old_instruction->source_node, struct_type, field_count, fields); |
| 1397 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1398 | | return new_instruction; |
| 1399 | | } |
| 1400 | | |
| 1401 | 1316 | static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1402 | 1317 | ZigType *union_type, TypeUnionField *field, IrInstruction *init_value) |
| 1403 | 1318 | { |
| ... | ... | @@ -1411,15 +1326,6 @@ static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode |
| 1411 | 1326 | return &union_init_instruction->base; |
| 1412 | 1327 | } |
| 1413 | 1328 | |
| 1414 | | static IrInstruction *ir_build_union_init_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1415 | | ZigType *union_type, TypeUnionField *field, IrInstruction *init_value) |
| 1416 | | { |
| 1417 | | IrInstruction *new_instruction = ir_build_union_init(irb, old_instruction->scope, |
| 1418 | | old_instruction->source_node, union_type, field, init_value); |
| 1419 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1420 | | return new_instruction; |
| 1421 | | } |
| 1422 | | |
| 1423 | 1329 | static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1424 | 1330 | IrInstructionUnreachable *unreachable_instruction = |
| 1425 | 1331 | ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node); |
| ... | ... | @@ -1428,12 +1334,6 @@ static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode |
| 1428 | 1334 | return &unreachable_instruction->base; |
| 1429 | 1335 | } |
| 1430 | 1336 | |
| 1431 | | static IrInstruction *ir_build_unreachable_from(IrBuilder *irb, IrInstruction *old_instruction) { |
| 1432 | | IrInstruction *new_instruction = ir_build_unreachable(irb, old_instruction->scope, old_instruction->source_node); |
| 1433 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1434 | | return new_instruction; |
| 1435 | | } |
| 1436 | | |
| 1437 | 1337 | static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1438 | 1338 | IrInstruction *ptr, IrInstruction *value) |
| 1439 | 1339 | { |
| ... | ... | @@ -1449,15 +1349,6 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode * |
| 1449 | 1349 | return &instruction->base; |
| 1450 | 1350 | } |
| 1451 | 1351 | |
| 1452 | | static IrInstruction *ir_build_store_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1453 | | IrInstruction *ptr, IrInstruction *value) |
| 1454 | | { |
| 1455 | | IrInstruction *new_instruction = ir_build_store_ptr(irb, old_instruction->scope, |
| 1456 | | old_instruction->source_node, ptr, value); |
| 1457 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1458 | | return new_instruction; |
| 1459 | | } |
| 1460 | | |
| 1461 | 1352 | static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1462 | 1353 | ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value) |
| 1463 | 1354 | { |
| ... | ... | @@ -1476,15 +1367,6 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s |
| 1476 | 1367 | return &decl_var_instruction->base; |
| 1477 | 1368 | } |
| 1478 | 1369 | |
| 1479 | | static IrInstruction *ir_build_var_decl_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1480 | | ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value) |
| 1481 | | { |
| 1482 | | IrInstruction *new_instruction = ir_build_var_decl(irb, old_instruction->scope, |
| 1483 | | old_instruction->source_node, var, var_type, align_value, init_value); |
| 1484 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1485 | | return new_instruction; |
| 1486 | | } |
| 1487 | | |
| 1488 | 1370 | static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1489 | 1371 | IrInstruction *name, IrInstruction *target, IrInstruction *linkage) |
| 1490 | 1372 | { |
| ... | ... | @@ -1512,13 +1394,6 @@ static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *s |
| 1512 | 1394 | return &instruction->base; |
| 1513 | 1395 | } |
| 1514 | 1396 | |
| 1515 | | static IrInstruction *ir_build_load_ptr_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *ptr) { |
| 1516 | | IrInstruction *new_instruction = ir_build_load_ptr(irb, old_instruction->scope, |
| 1517 | | old_instruction->source_node, ptr); |
| 1518 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1519 | | return new_instruction; |
| 1520 | | } |
| 1521 | | |
| 1522 | 1397 | static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 1523 | 1398 | IrInstructionTypeOf *instruction = ir_build_instruction<IrInstructionTypeOf>(irb, scope, source_node); |
| 1524 | 1399 | instruction->value = value; |
| ... | ... | @@ -1643,15 +1518,6 @@ static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source |
| 1643 | 1518 | return &instruction->base; |
| 1644 | 1519 | } |
| 1645 | 1520 | |
| 1646 | | static IrInstruction *ir_build_asm_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction **input_list, |
| 1647 | | IrInstruction **output_types, ZigVar **output_vars, size_t return_count, bool has_side_effects) |
| 1648 | | { |
| 1649 | | IrInstruction *new_instruction = ir_build_asm(irb, old_instruction->scope, |
| 1650 | | old_instruction->source_node, input_list, output_types, output_vars, return_count, has_side_effects); |
| 1651 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1652 | | return new_instruction; |
| 1653 | | } |
| 1654 | | |
| 1655 | 1521 | static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_value) { |
| 1656 | 1522 | IrInstructionSizeOf *instruction = ir_build_instruction<IrInstructionSizeOf>(irb, scope, source_node); |
| 1657 | 1523 | instruction->type_value = type_value; |
| ... | ... | @@ -1670,15 +1536,6 @@ static IrInstruction *ir_build_test_nonnull(IrBuilder *irb, Scope *scope, AstNod |
| 1670 | 1536 | return &instruction->base; |
| 1671 | 1537 | } |
| 1672 | 1538 | |
| 1673 | | static IrInstruction *ir_build_test_nonnull_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1674 | | IrInstruction *value) |
| 1675 | | { |
| 1676 | | IrInstruction *new_instruction = ir_build_test_nonnull(irb, old_instruction->scope, |
| 1677 | | old_instruction->source_node, value); |
| 1678 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1679 | | return new_instruction; |
| 1680 | | } |
| 1681 | | |
| 1682 | 1539 | static IrInstruction *ir_build_unwrap_maybe(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value, |
| 1683 | 1540 | bool safety_check_on) |
| 1684 | 1541 | { |
| ... | ... | @@ -1691,15 +1548,6 @@ static IrInstruction *ir_build_unwrap_maybe(IrBuilder *irb, Scope *scope, AstNod |
| 1691 | 1548 | return &instruction->base; |
| 1692 | 1549 | } |
| 1693 | 1550 | |
| 1694 | | static IrInstruction *ir_build_unwrap_maybe_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1695 | | IrInstruction *value, bool safety_check_on) |
| 1696 | | { |
| 1697 | | IrInstruction *new_instruction = ir_build_unwrap_maybe(irb, old_instruction->scope, old_instruction->source_node, |
| 1698 | | value, safety_check_on); |
| 1699 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1700 | | return new_instruction; |
| 1701 | | } |
| 1702 | | |
| 1703 | 1551 | static IrInstruction *ir_build_maybe_wrap(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 1704 | 1552 | IrInstructionOptionalWrap *instruction = ir_build_instruction<IrInstructionOptionalWrap>(irb, scope, source_node); |
| 1705 | 1553 | instruction->value = value; |
| ... | ... | @@ -1736,12 +1584,6 @@ static IrInstruction *ir_build_clz(IrBuilder *irb, Scope *scope, AstNode *source |
| 1736 | 1584 | return &instruction->base; |
| 1737 | 1585 | } |
| 1738 | 1586 | |
| 1739 | | static IrInstruction *ir_build_clz_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *value) { |
| 1740 | | IrInstruction *new_instruction = ir_build_clz(irb, old_instruction->scope, old_instruction->source_node, value); |
| 1741 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1742 | | return new_instruction; |
| 1743 | | } |
| 1744 | | |
| 1745 | 1587 | static IrInstruction *ir_build_ctz(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 1746 | 1588 | IrInstructionCtz *instruction = ir_build_instruction<IrInstructionCtz>(irb, scope, source_node); |
| 1747 | 1589 | instruction->value = value; |
| ... | ... | @@ -1751,12 +1593,6 @@ static IrInstruction *ir_build_ctz(IrBuilder *irb, Scope *scope, AstNode *source |
| 1751 | 1593 | return &instruction->base; |
| 1752 | 1594 | } |
| 1753 | 1595 | |
| 1754 | | static IrInstruction *ir_build_ctz_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *value) { |
| 1755 | | IrInstruction *new_instruction = ir_build_ctz(irb, old_instruction->scope, old_instruction->source_node, value); |
| 1756 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1757 | | return new_instruction; |
| 1758 | | } |
| 1759 | | |
| 1760 | 1596 | static IrInstruction *ir_build_pop_count(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) { |
| 1761 | 1597 | IrInstructionPopCount *instruction = ir_build_instruction<IrInstructionPopCount>(irb, scope, source_node); |
| 1762 | 1598 | instruction->value = value; |
| ... | ... | @@ -1793,16 +1629,6 @@ static IrInstruction *ir_build_switch_br(IrBuilder *irb, Scope *scope, AstNode * |
| 1793 | 1629 | return &instruction->base; |
| 1794 | 1630 | } |
| 1795 | 1631 | |
| 1796 | | static IrInstruction *ir_build_switch_br_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 1797 | | IrInstruction *target_value, IrBasicBlock *else_block, size_t case_count, |
| 1798 | | IrInstructionSwitchBrCase *cases, IrInstruction *is_comptime, IrInstruction *switch_prongs_void) |
| 1799 | | { |
| 1800 | | IrInstruction *new_instruction = ir_build_switch_br(irb, old_instruction->scope, old_instruction->source_node, |
| 1801 | | target_value, else_block, case_count, cases, is_comptime, switch_prongs_void); |
| 1802 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1803 | | return new_instruction; |
| 1804 | | } |
| 1805 | | |
| 1806 | 1632 | static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1807 | 1633 | IrInstruction *target_value_ptr) |
| 1808 | 1634 | { |
| ... | ... | @@ -1917,13 +1743,6 @@ static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *s |
| 1917 | 1743 | return &instruction->base; |
| 1918 | 1744 | } |
| 1919 | 1745 | |
| 1920 | | static IrInstruction *ir_build_err_name_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *value) { |
| 1921 | | IrInstruction *new_instruction = ir_build_err_name(irb, old_instruction->scope, |
| 1922 | | old_instruction->source_node, value); |
| 1923 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 1924 | | return new_instruction; |
| 1925 | | } |
| 1926 | | |
| 1927 | 1746 | static IrInstruction *ir_build_c_import(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1928 | 1747 | IrInstructionCImport *instruction = ir_build_instruction<IrInstructionCImport>(irb, scope, source_node); |
| 1929 | 1748 | return &instruction->base; |
| ... | ... | @@ -2005,12 +1824,6 @@ static IrInstruction *ir_build_fence(IrBuilder *irb, Scope *scope, AstNode *sour |
| 2005 | 1824 | return &instruction->base; |
| 2006 | 1825 | } |
| 2007 | 1826 | |
| 2008 | | static IrInstruction *ir_build_fence_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *order_value, AtomicOrder order) { |
| 2009 | | IrInstruction *new_instruction = ir_build_fence(irb, old_instruction->scope, old_instruction->source_node, order_value, order); |
| 2010 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 2011 | | return new_instruction; |
| 2012 | | } |
| 2013 | | |
| 2014 | 1827 | static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) { |
| 2015 | 1828 | IrInstructionTruncate *instruction = ir_build_instruction<IrInstructionTruncate>(irb, scope, source_node); |
| 2016 | 1829 | instruction->dest_type = dest_type; |
| ... | ... | @@ -2126,12 +1939,6 @@ static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *s |
| 2126 | 1939 | return &instruction->base; |
| 2127 | 1940 | } |
| 2128 | 1941 | |
| 2129 | | static IrInstruction *ir_build_bool_not_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *value) { |
| 2130 | | IrInstruction *new_instruction = ir_build_bool_not(irb, old_instruction->scope, old_instruction->source_node, value); |
| 2131 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 2132 | | return new_instruction; |
| 2133 | | } |
| 2134 | | |
| 2135 | 1942 | static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2136 | 1943 | IrInstruction *dest_ptr, IrInstruction *byte, IrInstruction *count) |
| 2137 | 1944 | { |
| ... | ... | @@ -2147,14 +1954,6 @@ static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *sou |
| 2147 | 1954 | return &instruction->base; |
| 2148 | 1955 | } |
| 2149 | 1956 | |
| 2150 | | static IrInstruction *ir_build_memset_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 2151 | | IrInstruction *dest_ptr, IrInstruction *byte, IrInstruction *count) |
| 2152 | | { |
| 2153 | | IrInstruction *new_instruction = ir_build_memset(irb, old_instruction->scope, old_instruction->source_node, dest_ptr, byte, count); |
| 2154 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 2155 | | return new_instruction; |
| 2156 | | } |
| 2157 | | |
| 2158 | 1957 | static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2159 | 1958 | IrInstruction *dest_ptr, IrInstruction *src_ptr, IrInstruction *count) |
| 2160 | 1959 | { |
| ... | ... | @@ -2170,14 +1969,6 @@ static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *sou |
| 2170 | 1969 | return &instruction->base; |
| 2171 | 1970 | } |
| 2172 | 1971 | |
| 2173 | | static IrInstruction *ir_build_memcpy_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 2174 | | IrInstruction *dest_ptr, IrInstruction *src_ptr, IrInstruction *count) |
| 2175 | | { |
| 2176 | | IrInstruction *new_instruction = ir_build_memcpy(irb, old_instruction->scope, old_instruction->source_node, dest_ptr, src_ptr, count); |
| 2177 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 2178 | | return new_instruction; |
| 2179 | | } |
| 2180 | | |
| 2181 | 1972 | static IrInstruction *ir_build_slice(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2182 | 1973 | IrInstruction *ptr, IrInstruction *start, IrInstruction *end, bool safety_check_on) |
| 2183 | 1974 | { |
| ... | ... | @@ -2194,15 +1985,6 @@ static IrInstruction *ir_build_slice(IrBuilder *irb, Scope *scope, AstNode *sour |
| 2194 | 1985 | return &instruction->base; |
| 2195 | 1986 | } |
| 2196 | 1987 | |
| 2197 | | static IrInstruction *ir_build_slice_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 2198 | | IrInstruction *ptr, IrInstruction *start, IrInstruction *end, bool safety_check_on) |
| 2199 | | { |
| 2200 | | IrInstruction *new_instruction = ir_build_slice(irb, old_instruction->scope, |
| 2201 | | old_instruction->source_node, ptr, start, end, safety_check_on); |
| 2202 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 2203 | | return new_instruction; |
| 2204 | | } |
| 2205 | | |
| 2206 | 1988 | static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *container) { |
| 2207 | 1989 | IrInstructionMemberCount *instruction = ir_build_instruction<IrInstructionMemberCount>(irb, scope, source_node); |
| 2208 | 1990 | instruction->container = container; |
| ... | ... | @@ -2243,45 +2025,21 @@ static IrInstruction *ir_build_breakpoint(IrBuilder *irb, Scope *scope, AstNode |
| 2243 | 2025 | return &instruction->base; |
| 2244 | 2026 | } |
| 2245 | 2027 | |
| 2246 | | static IrInstruction *ir_build_breakpoint_from(IrBuilder *irb, IrInstruction *old_instruction) { |
| 2247 | | IrInstruction *new_instruction = ir_build_breakpoint(irb, old_instruction->scope, old_instruction->source_node); |
| 2248 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 2249 | | return new_instruction; |
| 2250 | | } |
| 2251 | | |
| 2252 | 2028 | static IrInstruction *ir_build_return_address(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 2253 | 2029 | IrInstructionReturnAddress *instruction = ir_build_instruction<IrInstructionReturnAddress>(irb, scope, source_node); |
| 2254 | 2030 | return &instruction->base; |
| 2255 | 2031 | } |
| 2256 | 2032 | |
| 2257 | | static IrInstruction *ir_build_return_address_from(IrBuilder *irb, IrInstruction *old_instruction) { |
| 2258 | | IrInstruction *new_instruction = ir_build_return_address(irb, old_instruction->scope, old_instruction->source_node); |
| 2259 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 2260 | | return new_instruction; |
| 2261 | | } |
| 2262 | | |
| 2263 | 2033 | static IrInstruction *ir_build_frame_address(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 2264 | 2034 | IrInstructionFrameAddress *instruction = ir_build_instruction<IrInstructionFrameAddress>(irb, scope, source_node); |
| 2265 | 2035 | return &instruction->base; |
| 2266 | 2036 | } |
| 2267 | 2037 | |
| 2268 | | static IrInstruction *ir_build_frame_address_from(IrBuilder *irb, IrInstruction *old_instruction) { |
| 2269 | | IrInstruction *new_instruction = ir_build_frame_address(irb, old_instruction->scope, old_instruction->source_node); |
| 2270 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 2271 | | return new_instruction; |
| 2272 | | } |
| 2273 | | |
| 2274 | 2038 | static IrInstruction *ir_build_handle(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 2275 | 2039 | IrInstructionHandle *instruction = ir_build_instruction<IrInstructionHandle>(irb, scope, source_node); |
| 2276 | 2040 | return &instruction->base; |
| 2277 | 2041 | } |
| 2278 | 2042 | |
| 2279 | | static IrInstruction *ir_build_handle_from(IrBuilder *irb, IrInstruction *old_instruction) { |
| 2280 | | IrInstruction *new_instruction = ir_build_handle(irb, old_instruction->scope, old_instruction->source_node); |
| 2281 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 2282 | | return new_instruction; |
| 2283 | | } |
| 2284 | | |
| 2285 | 2043 | static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2286 | 2044 | IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2, |
| 2287 | 2045 | IrInstruction *result_ptr, ZigType *result_ptr_type) |
| ... | ... | @@ -2302,16 +2060,6 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode |
| 2302 | 2060 | return &instruction->base; |
| 2303 | 2061 | } |
| 2304 | 2062 | |
| 2305 | | static IrInstruction *ir_build_overflow_op_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 2306 | | IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2, |
| 2307 | | IrInstruction *result_ptr, ZigType *result_ptr_type) |
| 2308 | | { |
| 2309 | | IrInstruction *new_instruction = ir_build_overflow_op(irb, old_instruction->scope, old_instruction->source_node, |
| 2310 | | op, type_value, op1, op2, result_ptr, result_ptr_type); |
| 2311 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 2312 | | return new_instruction; |
| 2313 | | } |
| 2314 | | |
| 2315 | 2063 | static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_value) { |
| 2316 | 2064 | IrInstructionAlignOf *instruction = ir_build_instruction<IrInstructionAlignOf>(irb, scope, source_node); |
| 2317 | 2065 | instruction->type_value = type_value; |
| ... | ... | @@ -2332,13 +2080,6 @@ static IrInstruction *ir_build_test_err(IrBuilder *irb, Scope *scope, AstNode *s |
| 2332 | 2080 | return &instruction->base; |
| 2333 | 2081 | } |
| 2334 | 2082 | |
| 2335 | | static IrInstruction *ir_build_test_err_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction *value) { |
| 2336 | | IrInstruction *new_instruction = ir_build_test_err(irb, old_instruction->scope, old_instruction->source_node, |
| 2337 | | value); |
| 2338 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 2339 | | return new_instruction; |
| 2340 | | } |
| 2341 | | |
| 2342 | 2083 | static IrInstruction *ir_build_unwrap_err_code(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2343 | 2084 | IrInstruction *value) |
| 2344 | 2085 | { |
| ... | ... | @@ -2350,15 +2091,6 @@ static IrInstruction *ir_build_unwrap_err_code(IrBuilder *irb, Scope *scope, Ast |
| 2350 | 2091 | return &instruction->base; |
| 2351 | 2092 | } |
| 2352 | 2093 | |
| 2353 | | static IrInstruction *ir_build_unwrap_err_code_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 2354 | | IrInstruction *value) |
| 2355 | | { |
| 2356 | | IrInstruction *new_instruction = ir_build_unwrap_err_code(irb, old_instruction->scope, |
| 2357 | | old_instruction->source_node, value); |
| 2358 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 2359 | | return new_instruction; |
| 2360 | | } |
| 2361 | | |
| 2362 | 2094 | static IrInstruction *ir_build_unwrap_err_payload(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2363 | 2095 | IrInstruction *value, bool safety_check_on) |
| 2364 | 2096 | { |
| ... | ... | @@ -2371,15 +2103,6 @@ static IrInstruction *ir_build_unwrap_err_payload(IrBuilder *irb, Scope *scope, |
| 2371 | 2103 | return &instruction->base; |
| 2372 | 2104 | } |
| 2373 | 2105 | |
| 2374 | | static IrInstruction *ir_build_unwrap_err_payload_from(IrBuilder *irb, IrInstruction *old_instruction, |
| 2375 | | IrInstruction *value, bool safety_check_on) |
| 2376 | | { |
| 2377 | | IrInstruction *new_instruction = ir_build_unwrap_err_payload(irb, old_instruction->scope, |
| 2378 | | old_instruction->source_node, value, safety_check_on); |
| 2379 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 2380 | | return new_instruction; |
| 2381 | | } |
| 2382 | | |
| 2383 | 2106 | static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 2384 | 2107 | IrInstruction **param_types, IrInstruction *align_value, IrInstruction *return_type, |
| 2385 | 2108 | IrInstruction *async_allocator_type_value, bool is_var_args) |
| ... | ... | @@ -3343,6 +3066,10 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s |
| 3343 | 3066 | variable_entry->src_arg_index = SIZE_MAX; |
| 3344 | 3067 | variable_entry->value = create_const_vals(1); |
| 3345 | 3068 | |
| 3069 | if (is_comptime != nullptr) { |
| 3070 | is_comptime->ref_count += 1; |
| 3071 | } |
| 3072 | |
| 3346 | 3073 | if (name) { |
| 3347 | 3074 | buf_init_from_buf(&variable_entry->name, name); |
| 3348 | 3075 | |
| ... | ... | @@ -9691,10 +9418,10 @@ static void ir_finish_bb(IrAnalyze *ira) { |
| 9691 | 9418 | } |
| 9692 | 9419 | } |
| 9693 | 9420 | |
| 9694 | | static ZigType *ir_unreach_error(IrAnalyze *ira) { |
| 9421 | static IrInstruction *ir_unreach_error(IrAnalyze *ira) { |
| 9695 | 9422 | ira->old_bb_index = SIZE_MAX; |
| 9696 | 9423 | ira->new_irb.exec->invalid = true; |
| 9697 | | return ira->codegen->builtin_types.entry_unreachable; |
| 9424 | return ira->codegen->unreach_instruction; |
| 9698 | 9425 | } |
| 9699 | 9426 | |
| 9700 | 9427 | static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instruction) { |
| ... | ... | @@ -9714,7 +9441,7 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru |
| 9714 | 9441 | return true; |
| 9715 | 9442 | } |
| 9716 | 9443 | |
| 9717 | | static ZigType *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) { |
| 9444 | static IrInstruction *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) { |
| 9718 | 9445 | if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) { |
| 9719 | 9446 | if (!ir_emit_backward_branch(ira, source_instruction)) |
| 9720 | 9447 | return ir_unreach_error(ira); |
| ... | ... | @@ -9722,32 +9449,50 @@ static ZigType *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, |
| 9722 | 9449 | |
| 9723 | 9450 | old_bb->other = ira->old_irb.current_basic_block->other; |
| 9724 | 9451 | ir_start_bb(ira, old_bb, ira->old_irb.current_basic_block); |
| 9725 | | return ira->codegen->builtin_types.entry_unreachable; |
| 9452 | return ira->codegen->unreach_instruction; |
| 9726 | 9453 | } |
| 9727 | 9454 | |
| 9728 | | static ZigType *ir_finish_anal(IrAnalyze *ira, ZigType *result_type) { |
| 9729 | | if (result_type->id == ZigTypeIdUnreachable) |
| 9455 | static IrInstruction *ir_finish_anal(IrAnalyze *ira, IrInstruction *instruction) { |
| 9456 | if (instruction->value.type->id == ZigTypeIdUnreachable) |
| 9730 | 9457 | ir_finish_bb(ira); |
| 9731 | | return result_type; |
| 9458 | return instruction; |
| 9732 | 9459 | } |
| 9733 | 9460 | |
| 9734 | | static IrInstruction *ir_get_const(IrAnalyze *ira, IrInstruction *old_instruction) { |
| 9461 | static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, ZigType *ty) { |
| 9735 | 9462 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 9736 | 9463 | old_instruction->scope, old_instruction->source_node); |
| 9737 | 9464 | IrInstruction *new_instruction = &const_instruction->base; |
| 9465 | new_instruction->value.type = ty; |
| 9738 | 9466 | new_instruction->value.special = ConstValSpecialStatic; |
| 9739 | 9467 | return new_instruction; |
| 9740 | 9468 | } |
| 9741 | 9469 | |
| 9742 | | static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_instruction) { |
| 9743 | | IrInstruction *new_instruction = ir_get_const(ira, old_instruction); |
| 9744 | | ir_link_new_instruction(new_instruction, old_instruction); |
| 9745 | | return &new_instruction->value; |
| 9470 | static IrInstruction *ir_const_type(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { |
| 9471 | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type); |
| 9472 | result->value.data.x_type = ty; |
| 9473 | return result; |
| 9474 | } |
| 9475 | |
| 9476 | static IrInstruction *ir_const_bool(IrAnalyze *ira, IrInstruction *source_instruction, bool value) { |
| 9477 | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool); |
| 9478 | result->value.data.x_bool = value; |
| 9479 | return result; |
| 9480 | } |
| 9481 | |
| 9482 | static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instruction) { |
| 9483 | return ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_void); |
| 9484 | } |
| 9485 | |
| 9486 | static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_instruction, uint64_t value) { |
| 9487 | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int); |
| 9488 | bigint_init_unsigned(&result->value.data.x_bigint, value); |
| 9489 | return result; |
| 9746 | 9490 | } |
| 9747 | 9491 | |
| 9748 | | static ZigType *ir_analyze_void(IrAnalyze *ira, IrInstruction *instruction) { |
| 9749 | | ir_build_const_from(ira, instruction); |
| 9750 | | return ira->codegen->builtin_types.entry_void; |
| 9492 | static IrInstruction *ir_const_usize(IrAnalyze *ira, IrInstruction *source_instruction, uint64_t value) { |
| 9493 | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_usize); |
| 9494 | bigint_init_unsigned(&result->value.data.x_bigint, value); |
| 9495 | return result; |
| 9751 | 9496 | } |
| 9752 | 9497 | |
| 9753 | 9498 | static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| ... | ... | @@ -9756,31 +9501,14 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio |
| 9756 | 9501 | { |
| 9757 | 9502 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, |
| 9758 | 9503 | ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0); |
| 9759 | | IrInstruction *const_instr = ir_get_const(ira, instruction); |
| 9504 | IrInstruction *const_instr = ir_const(ira, instruction, ptr_type); |
| 9760 | 9505 | ConstExprValue *const_val = &const_instr->value; |
| 9761 | | const_val->type = ptr_type; |
| 9762 | 9506 | const_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 9763 | 9507 | const_val->data.x_ptr.mut = ptr_mut; |
| 9764 | 9508 | const_val->data.x_ptr.data.ref.pointee = pointee; |
| 9765 | 9509 | return const_instr; |
| 9766 | 9510 | } |
| 9767 | 9511 | |
| 9768 | | static ZigType *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 9769 | | ConstExprValue *pointee, ZigType *pointee_type, |
| 9770 | | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile) |
| 9771 | | { |
| 9772 | | IrInstruction *const_instr = ir_get_const_ptr(ira, instruction, pointee, |
| 9773 | | pointee_type, ptr_mut, ptr_is_const, ptr_is_volatile, 0); |
| 9774 | | ir_link_new_instruction(const_instr, instruction); |
| 9775 | | return const_instr->value.type; |
| 9776 | | } |
| 9777 | | |
| 9778 | | static ZigType *ir_analyze_const_usize(IrAnalyze *ira, IrInstruction *instruction, uint64_t value) { |
| 9779 | | ConstExprValue *const_val = ir_build_const_from(ira, instruction); |
| 9780 | | bigint_init_unsigned(&const_val->data.x_bigint, value); |
| 9781 | | return ira->codegen->builtin_types.entry_usize; |
| 9782 | | } |
| 9783 | | |
| 9784 | 9512 | enum UndefAllowed { |
| 9785 | 9513 | UndefOk, |
| 9786 | 9514 | UndefBad, |
| ... | ... | @@ -11283,14 +11011,6 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 11283 | 11011 | } |
| 11284 | 11012 | } |
| 11285 | 11013 | |
| 11286 | | static ZigType *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value, |
| 11287 | | bool is_const, bool is_volatile) |
| 11288 | | { |
| 11289 | | IrInstruction *result = ir_get_ref(ira, source_instruction, value, is_const, is_volatile); |
| 11290 | | ir_link_new_instruction(result, source_instruction); |
| 11291 | | return result->value.type; |
| 11292 | | } |
| 11293 | | |
| 11294 | 11014 | static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, uint32_t *out) { |
| 11295 | 11015 | if (type_is_invalid(value->value.type)) |
| 11296 | 11016 | return false; |
| ... | ... | @@ -11485,29 +11205,25 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 11485 | 11205 | return result; |
| 11486 | 11206 | } |
| 11487 | 11207 | |
| 11488 | | static ZigType *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira, |
| 11208 | static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira, |
| 11489 | 11209 | IrInstructionAddImplicitReturnType *instruction) |
| 11490 | 11210 | { |
| 11491 | | IrInstruction *value = instruction->value->other; |
| 11211 | IrInstruction *value = instruction->value->child; |
| 11492 | 11212 | if (type_is_invalid(value->value.type)) |
| 11493 | 11213 | return ir_unreach_error(ira); |
| 11494 | 11214 | |
| 11495 | 11215 | ira->src_implicit_return_type_list.append(value); |
| 11496 | 11216 | |
| 11497 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 11498 | | out_val->type = ira->codegen->builtin_types.entry_void; |
| 11499 | | return out_val->type; |
| 11217 | return ir_const_void(ira, &instruction->base); |
| 11500 | 11218 | } |
| 11501 | 11219 | |
| 11502 | | static ZigType *ir_analyze_instruction_return(IrAnalyze *ira, |
| 11503 | | IrInstructionReturn *return_instruction) |
| 11504 | | { |
| 11505 | | IrInstruction *value = return_instruction->value->other; |
| 11220 | static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *instruction) { |
| 11221 | IrInstruction *value = instruction->value->child; |
| 11506 | 11222 | if (type_is_invalid(value->value.type)) |
| 11507 | 11223 | return ir_unreach_error(ira); |
| 11508 | 11224 | |
| 11509 | 11225 | IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->explicit_return_type); |
| 11510 | | if (casted_value == ira->codegen->invalid_instruction) |
| 11226 | if (type_is_invalid(casted_value->value.type)) |
| 11511 | 11227 | return ir_unreach_error(ira); |
| 11512 | 11228 | |
| 11513 | 11229 | if (casted_value->value.special == ConstValSpecialRuntime && |
| ... | ... | @@ -11517,63 +11233,65 @@ static ZigType *ir_analyze_instruction_return(IrAnalyze *ira, |
| 11517 | 11233 | ir_add_error(ira, casted_value, buf_sprintf("function returns address of local variable")); |
| 11518 | 11234 | return ir_unreach_error(ira); |
| 11519 | 11235 | } |
| 11520 | | IrInstruction *result = ir_build_return(&ira->new_irb, return_instruction->base.scope, |
| 11521 | | return_instruction->base.source_node, casted_value); |
| 11236 | IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope, |
| 11237 | instruction->base.source_node, casted_value); |
| 11522 | 11238 | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 11523 | | ir_link_new_instruction(result, &return_instruction->base); |
| 11524 | | return ir_finish_anal(ira, result->value.type); |
| 11239 | return ir_finish_anal(ira, result); |
| 11525 | 11240 | } |
| 11526 | 11241 | |
| 11527 | | static ZigType *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) { |
| 11528 | | ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base); |
| 11529 | | *out_val = const_instruction->base.value; |
| 11530 | | return const_instruction->base.value.type; |
| 11242 | static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) { |
| 11243 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 11244 | // TODO determine if we need to use copy_const_val here |
| 11245 | result->value = instruction->base.value; |
| 11246 | return result; |
| 11531 | 11247 | } |
| 11532 | 11248 | |
| 11533 | | static ZigType *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 11534 | | IrInstruction *op1 = bin_op_instruction->op1->other; |
| 11249 | static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 11250 | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 11535 | 11251 | if (type_is_invalid(op1->value.type)) |
| 11536 | | return ira->codegen->builtin_types.entry_invalid; |
| 11252 | return ira->codegen->invalid_instruction; |
| 11537 | 11253 | |
| 11538 | | IrInstruction *op2 = bin_op_instruction->op2->other; |
| 11254 | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 11539 | 11255 | if (type_is_invalid(op2->value.type)) |
| 11540 | | return ira->codegen->builtin_types.entry_invalid; |
| 11256 | return ira->codegen->invalid_instruction; |
| 11541 | 11257 | |
| 11542 | 11258 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 11543 | 11259 | |
| 11544 | 11260 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type); |
| 11545 | 11261 | if (casted_op1 == ira->codegen->invalid_instruction) |
| 11546 | | return ira->codegen->builtin_types.entry_invalid; |
| 11262 | return ira->codegen->invalid_instruction; |
| 11547 | 11263 | |
| 11548 | 11264 | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, bool_type); |
| 11549 | 11265 | if (casted_op2 == ira->codegen->invalid_instruction) |
| 11550 | | return ira->codegen->builtin_types.entry_invalid; |
| 11266 | return ira->codegen->invalid_instruction; |
| 11551 | 11267 | |
| 11552 | 11268 | if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) { |
| 11553 | | ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); |
| 11554 | 11269 | ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 11555 | 11270 | if (op1_val == nullptr) |
| 11556 | | return ira->codegen->builtin_types.entry_invalid; |
| 11271 | return ira->codegen->invalid_instruction; |
| 11557 | 11272 | |
| 11558 | 11273 | ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 11559 | 11274 | if (op2_val == nullptr) |
| 11560 | | return ira->codegen->builtin_types.entry_invalid; |
| 11275 | return ira->codegen->invalid_instruction; |
| 11561 | 11276 | |
| 11562 | 11277 | assert(casted_op1->value.type->id == ZigTypeIdBool); |
| 11563 | 11278 | assert(casted_op2->value.type->id == ZigTypeIdBool); |
| 11279 | bool result_bool; |
| 11564 | 11280 | if (bin_op_instruction->op_id == IrBinOpBoolOr) { |
| 11565 | | out_val->data.x_bool = op1_val->data.x_bool || op2_val->data.x_bool; |
| 11281 | result_bool = op1_val->data.x_bool || op2_val->data.x_bool; |
| 11566 | 11282 | } else if (bin_op_instruction->op_id == IrBinOpBoolAnd) { |
| 11567 | | out_val->data.x_bool = op1_val->data.x_bool && op2_val->data.x_bool; |
| 11283 | result_bool = op1_val->data.x_bool && op2_val->data.x_bool; |
| 11568 | 11284 | } else { |
| 11569 | 11285 | zig_unreachable(); |
| 11570 | 11286 | } |
| 11571 | | return bool_type; |
| 11287 | return ir_const_bool(ira, &bin_op_instruction->base, result_bool); |
| 11572 | 11288 | } |
| 11573 | 11289 | |
| 11574 | | ir_build_bin_op_from(&ira->new_irb, &bin_op_instruction->base, bin_op_instruction->op_id, |
| 11575 | | casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 11576 | | return bool_type; |
| 11290 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 11291 | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 11292 | bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 11293 | result->value.type = bool_type; |
| 11294 | return result; |
| 11577 | 11295 | } |
| 11578 | 11296 | |
| 11579 | 11297 | static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) { |
| ... | ... | @@ -11604,15 +11322,15 @@ static bool optional_value_is_null(ConstExprValue *val) { |
| 11604 | 11322 | } |
| 11605 | 11323 | } |
| 11606 | 11324 | |
| 11607 | | static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 11325 | static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 11608 | 11326 | Error err; |
| 11609 | | IrInstruction *op1 = bin_op_instruction->op1->other; |
| 11327 | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 11610 | 11328 | if (type_is_invalid(op1->value.type)) |
| 11611 | | return ira->codegen->builtin_types.entry_invalid; |
| 11329 | return ira->codegen->invalid_instruction; |
| 11612 | 11330 | |
| 11613 | | IrInstruction *op2 = bin_op_instruction->op2->other; |
| 11331 | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 11614 | 11332 | if (type_is_invalid(op2->value.type)) |
| 11615 | | return ira->codegen->builtin_types.entry_invalid; |
| 11333 | return ira->codegen->invalid_instruction; |
| 11616 | 11334 | |
| 11617 | 11335 | AstNode *source_node = bin_op_instruction->base.source_node; |
| 11618 | 11336 | |
| ... | ... | @@ -11624,9 +11342,7 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11624 | 11342 | (op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull))) |
| 11625 | 11343 | { |
| 11626 | 11344 | if (op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull) { |
| 11627 | | ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); |
| 11628 | | out_val->data.x_bool = (op_id == IrBinOpCmpEq); |
| 11629 | | return ira->codegen->builtin_types.entry_bool; |
| 11345 | return ir_const_bool(ira, &bin_op_instruction->base, (op_id == IrBinOpCmpEq)); |
| 11630 | 11346 | } |
| 11631 | 11347 | IrInstruction *maybe_op; |
| 11632 | 11348 | if (op1->value.type->id == ZigTypeIdNull) { |
| ... | ... | @@ -11639,11 +11355,10 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11639 | 11355 | if (instr_is_comptime(maybe_op)) { |
| 11640 | 11356 | ConstExprValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad); |
| 11641 | 11357 | if (!maybe_val) |
| 11642 | | return ira->codegen->builtin_types.entry_invalid; |
| 11358 | return ira->codegen->invalid_instruction; |
| 11643 | 11359 | bool is_null = optional_value_is_null(maybe_val); |
| 11644 | | ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); |
| 11645 | | out_val->data.x_bool = (op_id == IrBinOpCmpEq) ? is_null : !is_null; |
| 11646 | | return ira->codegen->builtin_types.entry_bool; |
| 11360 | bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null; |
| 11361 | return ir_const_bool(ira, &bin_op_instruction->base, bool_result); |
| 11647 | 11362 | } |
| 11648 | 11363 | |
| 11649 | 11364 | IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope, |
| ... | ... | @@ -11651,28 +11366,30 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11651 | 11366 | is_non_null->value.type = ira->codegen->builtin_types.entry_bool; |
| 11652 | 11367 | |
| 11653 | 11368 | if (op_id == IrBinOpCmpEq) { |
| 11654 | | ir_build_bool_not_from(&ira->new_irb, &bin_op_instruction->base, is_non_null); |
| 11369 | IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope, |
| 11370 | bin_op_instruction->base.source_node, is_non_null); |
| 11371 | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 11372 | return result; |
| 11655 | 11373 | } else { |
| 11656 | | ir_link_new_instruction(is_non_null, &bin_op_instruction->base); |
| 11374 | return is_non_null; |
| 11657 | 11375 | } |
| 11658 | | return ira->codegen->builtin_types.entry_bool; |
| 11659 | 11376 | } else if (op1->value.type->id == ZigTypeIdNull || op2->value.type->id == ZigTypeIdNull) { |
| 11660 | 11377 | ir_add_error_node(ira, source_node, buf_sprintf("comparison against null can only be done with optionals")); |
| 11661 | | return ira->codegen->builtin_types.entry_invalid; |
| 11378 | return ira->codegen->invalid_instruction; |
| 11662 | 11379 | } |
| 11663 | 11380 | |
| 11664 | 11381 | if (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) { |
| 11665 | 11382 | if (!is_equality_cmp) { |
| 11666 | 11383 | ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors")); |
| 11667 | | return ira->codegen->builtin_types.entry_invalid; |
| 11384 | return ira->codegen->invalid_instruction; |
| 11668 | 11385 | } |
| 11669 | 11386 | ZigType *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node); |
| 11670 | 11387 | if (type_is_invalid(intersect_type)) { |
| 11671 | | return ira->codegen->builtin_types.entry_invalid; |
| 11388 | return ira->codegen->invalid_instruction; |
| 11672 | 11389 | } |
| 11673 | 11390 | |
| 11674 | 11391 | if (!resolve_inferred_error_set(ira->codegen, intersect_type, source_node)) { |
| 11675 | | return ira->codegen->builtin_types.entry_invalid; |
| 11392 | return ira->codegen->invalid_instruction; |
| 11676 | 11393 | } |
| 11677 | 11394 | |
| 11678 | 11395 | // exception if one of the operators has the type of the empty error set, we allow the comparison |
| ... | ... | @@ -11689,9 +11406,7 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11689 | 11406 | } else { |
| 11690 | 11407 | zig_unreachable(); |
| 11691 | 11408 | } |
| 11692 | | ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); |
| 11693 | | out_val->data.x_bool = answer; |
| 11694 | | return ira->codegen->builtin_types.entry_bool; |
| 11409 | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 11695 | 11410 | } |
| 11696 | 11411 | |
| 11697 | 11412 | if (!type_is_global_error_set(intersect_type)) { |
| ... | ... | @@ -11699,7 +11414,7 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11699 | 11414 | ir_add_error_node(ira, source_node, |
| 11700 | 11415 | buf_sprintf("error sets '%s' and '%s' have no common errors", |
| 11701 | 11416 | buf_ptr(&op1->value.type->name), buf_ptr(&op2->value.type->name))); |
| 11702 | | return ira->codegen->builtin_types.entry_invalid; |
| 11417 | return ira->codegen->invalid_instruction; |
| 11703 | 11418 | } |
| 11704 | 11419 | if (op1->value.type->data.error_set.err_count == 1 && op2->value.type->data.error_set.err_count == 1) { |
| 11705 | 11420 | bool are_equal = true; |
| ... | ... | @@ -11711,19 +11426,17 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11711 | 11426 | } else { |
| 11712 | 11427 | zig_unreachable(); |
| 11713 | 11428 | } |
| 11714 | | ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); |
| 11715 | | out_val->data.x_bool = answer; |
| 11716 | | return ira->codegen->builtin_types.entry_bool; |
| 11429 | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 11717 | 11430 | } |
| 11718 | 11431 | } |
| 11719 | 11432 | |
| 11720 | 11433 | if (instr_is_comptime(op1) && instr_is_comptime(op2)) { |
| 11721 | 11434 | ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 11722 | 11435 | if (op1_val == nullptr) |
| 11723 | | return ira->codegen->builtin_types.entry_invalid; |
| 11436 | return ira->codegen->invalid_instruction; |
| 11724 | 11437 | ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 11725 | 11438 | if (op2_val == nullptr) |
| 11726 | | return ira->codegen->builtin_types.entry_invalid; |
| 11439 | return ira->codegen->invalid_instruction; |
| 11727 | 11440 | |
| 11728 | 11441 | bool answer; |
| 11729 | 11442 | bool are_equal = op1_val->data.x_err_set->value == op2_val->data.x_err_set->value; |
| ... | ... | @@ -11735,21 +11448,20 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11735 | 11448 | zig_unreachable(); |
| 11736 | 11449 | } |
| 11737 | 11450 | |
| 11738 | | ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); |
| 11739 | | out_val->data.x_bool = answer; |
| 11740 | | return ira->codegen->builtin_types.entry_bool; |
| 11451 | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 11741 | 11452 | } |
| 11742 | 11453 | |
| 11743 | | ir_build_bin_op_from(&ira->new_irb, &bin_op_instruction->base, op_id, |
| 11744 | | op1, op2, bin_op_instruction->safety_check_on); |
| 11745 | | |
| 11746 | | return ira->codegen->builtin_types.entry_bool; |
| 11454 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 11455 | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 11456 | op_id, op1, op2, bin_op_instruction->safety_check_on); |
| 11457 | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 11458 | return result; |
| 11747 | 11459 | } |
| 11748 | 11460 | |
| 11749 | 11461 | IrInstruction *instructions[] = {op1, op2}; |
| 11750 | 11462 | ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2); |
| 11751 | 11463 | if (type_is_invalid(resolved_type)) |
| 11752 | | return resolved_type; |
| 11464 | return ira->codegen->invalid_instruction; |
| 11753 | 11465 | |
| 11754 | 11466 | bool operator_allowed; |
| 11755 | 11467 | switch (resolved_type->id) { |
| ... | ... | @@ -11794,28 +11506,28 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11794 | 11506 | if (!operator_allowed) { |
| 11795 | 11507 | ir_add_error_node(ira, source_node, |
| 11796 | 11508 | buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name))); |
| 11797 | | return ira->codegen->builtin_types.entry_invalid; |
| 11509 | return ira->codegen->invalid_instruction; |
| 11798 | 11510 | } |
| 11799 | 11511 | |
| 11800 | 11512 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type); |
| 11801 | 11513 | if (casted_op1 == ira->codegen->invalid_instruction) |
| 11802 | | return ira->codegen->builtin_types.entry_invalid; |
| 11514 | return ira->codegen->invalid_instruction; |
| 11803 | 11515 | |
| 11804 | 11516 | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type); |
| 11805 | 11517 | if (casted_op2 == ira->codegen->invalid_instruction) |
| 11806 | | return ira->codegen->builtin_types.entry_invalid; |
| 11518 | return ira->codegen->invalid_instruction; |
| 11807 | 11519 | |
| 11808 | 11520 | if ((err = type_resolve(ira->codegen, resolved_type, ResolveStatusZeroBitsKnown))) |
| 11809 | | return resolved_type; |
| 11521 | return ira->codegen->invalid_instruction; |
| 11810 | 11522 | |
| 11811 | 11523 | bool one_possible_value = !type_requires_comptime(resolved_type) && !type_has_bits(resolved_type); |
| 11812 | 11524 | if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) { |
| 11813 | 11525 | ConstExprValue *op1_val = one_possible_value ? &casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad); |
| 11814 | 11526 | if (op1_val == nullptr) |
| 11815 | | return ira->codegen->builtin_types.entry_invalid; |
| 11527 | return ira->codegen->invalid_instruction; |
| 11816 | 11528 | ConstExprValue *op2_val = one_possible_value ? &casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad); |
| 11817 | 11529 | if (op2_val == nullptr) |
| 11818 | | return ira->codegen->builtin_types.entry_invalid; |
| 11530 | return ira->codegen->invalid_instruction; |
| 11819 | 11531 | |
| 11820 | 11532 | bool answer; |
| 11821 | 11533 | if (resolved_type->id == ZigTypeIdComptimeFloat || resolved_type->id == ZigTypeIdFloat) { |
| ... | ... | @@ -11835,9 +11547,7 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11835 | 11547 | } |
| 11836 | 11548 | } |
| 11837 | 11549 | |
| 11838 | | ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); |
| 11839 | | out_val->data.x_bool = answer; |
| 11840 | | return ira->codegen->builtin_types.entry_bool; |
| 11550 | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 11841 | 11551 | } |
| 11842 | 11552 | |
| 11843 | 11553 | // some comparisons with unsigned numbers can be evaluated |
| ... | ... | @@ -11847,13 +11557,13 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11847 | 11557 | if (instr_is_comptime(casted_op1)) { |
| 11848 | 11558 | known_left_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 11849 | 11559 | if (known_left_val == nullptr) |
| 11850 | | return ira->codegen->builtin_types.entry_invalid; |
| 11560 | return ira->codegen->invalid_instruction; |
| 11851 | 11561 | |
| 11852 | 11562 | flipped_op_id = op_id; |
| 11853 | 11563 | } else if (instr_is_comptime(casted_op2)) { |
| 11854 | 11564 | known_left_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 11855 | 11565 | if (known_left_val == nullptr) |
| 11856 | | return ira->codegen->builtin_types.entry_invalid; |
| 11566 | return ira->codegen->invalid_instruction; |
| 11857 | 11567 | |
| 11858 | 11568 | if (op_id == IrBinOpCmpLessThan) { |
| 11859 | 11569 | flipped_op_id = IrBinOpCmpGreaterThan; |
| ... | ... | @@ -11873,16 +11583,15 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11873 | 11583 | (flipped_op_id == IrBinOpCmpLessOrEq || flipped_op_id == IrBinOpCmpGreaterThan)) |
| 11874 | 11584 | { |
| 11875 | 11585 | bool answer = (flipped_op_id == IrBinOpCmpLessOrEq); |
| 11876 | | ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); |
| 11877 | | out_val->data.x_bool = answer; |
| 11878 | | return ira->codegen->builtin_types.entry_bool; |
| 11586 | return ir_const_bool(ira, &bin_op_instruction->base, answer); |
| 11879 | 11587 | } |
| 11880 | 11588 | } |
| 11881 | 11589 | |
| 11882 | | ir_build_bin_op_from(&ira->new_irb, &bin_op_instruction->base, op_id, |
| 11883 | | casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 11884 | | |
| 11885 | | return ira->codegen->builtin_types.entry_bool; |
| 11590 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 11591 | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 11592 | op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 11593 | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 11594 | return result; |
| 11886 | 11595 | } |
| 11887 | 11596 | |
| 11888 | 11597 | static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val, |
| ... | ... | @@ -12065,21 +11774,21 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val, |
| 12065 | 11774 | return 0; |
| 12066 | 11775 | } |
| 12067 | 11776 | |
| 12068 | | static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 12069 | | IrInstruction *op1 = bin_op_instruction->op1->other; |
| 11777 | static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 11778 | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 12070 | 11779 | if (type_is_invalid(op1->value.type)) |
| 12071 | | return ira->codegen->builtin_types.entry_invalid; |
| 11780 | return ira->codegen->invalid_instruction; |
| 12072 | 11781 | |
| 12073 | 11782 | if (op1->value.type->id != ZigTypeIdInt && op1->value.type->id != ZigTypeIdComptimeInt) { |
| 12074 | 11783 | ir_add_error(ira, &bin_op_instruction->base, |
| 12075 | 11784 | buf_sprintf("bit shifting operation expected integer type, found '%s'", |
| 12076 | 11785 | buf_ptr(&op1->value.type->name))); |
| 12077 | | return ira->codegen->builtin_types.entry_invalid; |
| 11786 | return ira->codegen->invalid_instruction; |
| 12078 | 11787 | } |
| 12079 | 11788 | |
| 12080 | | IrInstruction *op2 = bin_op_instruction->op2->other; |
| 11789 | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 12081 | 11790 | if (type_is_invalid(op2->value.type)) |
| 12082 | | return ira->codegen->builtin_types.entry_invalid; |
| 11791 | return ira->codegen->invalid_instruction; |
| 12083 | 11792 | |
| 12084 | 11793 | IrInstruction *casted_op2; |
| 12085 | 11794 | IrBinOp op_id = bin_op_instruction->op_id; |
| ... | ... | @@ -12094,7 +11803,7 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_ |
| 12094 | 11803 | Buf *val_buf = buf_alloc(); |
| 12095 | 11804 | bigint_append_buf(val_buf, &casted_op2->value.data.x_bigint, 10); |
| 12096 | 11805 | ir_add_error(ira, casted_op2, buf_sprintf("shift by negative value %s", buf_ptr(val_buf))); |
| 12097 | | return ira->codegen->builtin_types.entry_invalid; |
| 11806 | return ira->codegen->invalid_instruction; |
| 12098 | 11807 | } |
| 12099 | 11808 | } else { |
| 12100 | 11809 | ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, |
| ... | ... | @@ -12116,71 +11825,70 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_ |
| 12116 | 11825 | buf_sprintf("value %s cannot fit into type %s", |
| 12117 | 11826 | buf_ptr(val_buf), |
| 12118 | 11827 | buf_ptr(&shift_amt_type->name))); |
| 12119 | | return ira->codegen->builtin_types.entry_invalid; |
| 11828 | return ira->codegen->invalid_instruction; |
| 12120 | 11829 | } |
| 12121 | 11830 | } |
| 12122 | 11831 | |
| 12123 | 11832 | casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type); |
| 12124 | 11833 | if (casted_op2 == ira->codegen->invalid_instruction) |
| 12125 | | return ira->codegen->builtin_types.entry_invalid; |
| 11834 | return ira->codegen->invalid_instruction; |
| 12126 | 11835 | } |
| 12127 | 11836 | |
| 12128 | 11837 | if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) { |
| 12129 | 11838 | ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 12130 | 11839 | if (op1_val == nullptr) |
| 12131 | | return ira->codegen->builtin_types.entry_invalid; |
| 11840 | return ira->codegen->invalid_instruction; |
| 12132 | 11841 | |
| 12133 | 11842 | ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 12134 | 11843 | if (op2_val == nullptr) |
| 12135 | | return ira->codegen->builtin_types.entry_invalid; |
| 11844 | return ira->codegen->invalid_instruction; |
| 12136 | 11845 | |
| 12137 | | IrInstruction *result_instruction = ir_get_const(ira, &bin_op_instruction->base); |
| 12138 | | ir_link_new_instruction(result_instruction, &bin_op_instruction->base); |
| 12139 | | ConstExprValue *out_val = &result_instruction->value; |
| 11846 | IrInstruction *result_instruction = ir_const(ira, &bin_op_instruction->base, op1->value.type); |
| 12140 | 11847 | |
| 12141 | 11848 | int err; |
| 12142 | | if ((err = ir_eval_math_op(op1->value.type, op1_val, op_id, op2_val, out_val))) { |
| 11849 | if ((err = ir_eval_math_op(op1->value.type, op1_val, op_id, op2_val, &result_instruction->value))) { |
| 12143 | 11850 | if (err == ErrorOverflow) { |
| 12144 | 11851 | ir_add_error(ira, &bin_op_instruction->base, buf_sprintf("operation caused overflow")); |
| 12145 | | return ira->codegen->builtin_types.entry_invalid; |
| 11852 | return ira->codegen->invalid_instruction; |
| 12146 | 11853 | } else if (err == ErrorShiftedOutOneBits) { |
| 12147 | 11854 | ir_add_error(ira, &bin_op_instruction->base, buf_sprintf("exact shift shifted out 1 bits")); |
| 12148 | | return ira->codegen->builtin_types.entry_invalid; |
| 11855 | return ira->codegen->invalid_instruction; |
| 12149 | 11856 | } else { |
| 12150 | 11857 | zig_unreachable(); |
| 12151 | 11858 | } |
| 12152 | | return ira->codegen->builtin_types.entry_invalid; |
| 11859 | return ira->codegen->invalid_instruction; |
| 12153 | 11860 | } |
| 12154 | 11861 | |
| 12155 | 11862 | ir_num_lit_fits_in_other_type(ira, result_instruction, op1->value.type, false); |
| 12156 | | return op1->value.type; |
| 11863 | return result_instruction; |
| 12157 | 11864 | } else if (op1->value.type->id == ZigTypeIdComptimeInt) { |
| 12158 | 11865 | ir_add_error(ira, &bin_op_instruction->base, |
| 12159 | 11866 | buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known")); |
| 12160 | | return ira->codegen->builtin_types.entry_invalid; |
| 11867 | return ira->codegen->invalid_instruction; |
| 12161 | 11868 | } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value.data.x_bigint) == CmpEQ) { |
| 12162 | 11869 | IrInstruction *result = ir_build_cast(&ira->new_irb, bin_op_instruction->base.scope, |
| 12163 | 11870 | bin_op_instruction->base.source_node, op1->value.type, op1, CastOpNoop); |
| 12164 | 11871 | result->value.type = op1->value.type; |
| 12165 | | ir_link_new_instruction(result, &bin_op_instruction->base); |
| 12166 | | return result->value.type; |
| 11872 | return result; |
| 12167 | 11873 | } |
| 12168 | 11874 | |
| 12169 | | ir_build_bin_op_from(&ira->new_irb, &bin_op_instruction->base, op_id, |
| 11875 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope, |
| 11876 | bin_op_instruction->base.source_node, op_id, |
| 12170 | 11877 | op1, casted_op2, bin_op_instruction->safety_check_on); |
| 12171 | | return op1->value.type; |
| 11878 | result->value.type = op1->value.type; |
| 11879 | return result; |
| 12172 | 11880 | } |
| 12173 | 11881 | |
| 12174 | | static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 12175 | | IrInstruction *op1 = bin_op_instruction->op1->other; |
| 11882 | static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 11883 | IrInstruction *op1 = instruction->op1->child; |
| 12176 | 11884 | if (type_is_invalid(op1->value.type)) |
| 12177 | | return ira->codegen->builtin_types.entry_invalid; |
| 11885 | return ira->codegen->invalid_instruction; |
| 12178 | 11886 | |
| 12179 | | IrInstruction *op2 = bin_op_instruction->op2->other; |
| 11887 | IrInstruction *op2 = instruction->op2->child; |
| 12180 | 11888 | if (type_is_invalid(op2->value.type)) |
| 12181 | | return ira->codegen->builtin_types.entry_invalid; |
| 11889 | return ira->codegen->invalid_instruction; |
| 12182 | 11890 | |
| 12183 | | IrBinOp op_id = bin_op_instruction->op_id; |
| 11891 | IrBinOp op_id = instruction->op_id; |
| 12184 | 11892 | |
| 12185 | 11893 | // look for pointer math |
| 12186 | 11894 | if (op1->value.type->id == ZigTypeIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenUnknown && |
| ... | ... | @@ -12188,19 +11896,18 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o |
| 12188 | 11896 | { |
| 12189 | 11897 | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize); |
| 12190 | 11898 | if (casted_op2 == ira->codegen->invalid_instruction) |
| 12191 | | return ira->codegen->builtin_types.entry_invalid; |
| 11899 | return ira->codegen->invalid_instruction; |
| 12192 | 11900 | |
| 12193 | | IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope, |
| 12194 | | bin_op_instruction->base.source_node, op_id, op1, casted_op2, true); |
| 11901 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope, |
| 11902 | instruction->base.source_node, op_id, op1, casted_op2, true); |
| 12195 | 11903 | result->value.type = op1->value.type; |
| 12196 | | ir_link_new_instruction(result, &bin_op_instruction->base); |
| 12197 | | return result->value.type; |
| 11904 | return result; |
| 12198 | 11905 | } |
| 12199 | 11906 | |
| 12200 | 11907 | IrInstruction *instructions[] = {op1, op2}; |
| 12201 | | ZigType *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, nullptr, instructions, 2); |
| 11908 | ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.source_node, nullptr, instructions, 2); |
| 12202 | 11909 | if (type_is_invalid(resolved_type)) |
| 12203 | | return resolved_type; |
| 11910 | return ira->codegen->invalid_instruction; |
| 12204 | 11911 | |
| 12205 | 11912 | bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt; |
| 12206 | 11913 | bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat; |
| ... | ... | @@ -12220,11 +11927,11 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o |
| 12220 | 11927 | if (instr_is_comptime(op1) && instr_is_comptime(op2)) { |
| 12221 | 11928 | ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 12222 | 11929 | if (op1_val == nullptr) |
| 12223 | | return ira->codegen->builtin_types.entry_invalid; |
| 11930 | return ira->codegen->invalid_instruction; |
| 12224 | 11931 | |
| 12225 | 11932 | ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 12226 | 11933 | if (op2_val == nullptr) |
| 12227 | | return ira->codegen->builtin_types.entry_invalid; |
| 11934 | return ira->codegen->invalid_instruction; |
| 12228 | 11935 | |
| 12229 | 11936 | if (bigint_cmp_zero(&op2_val->data.x_bigint) == CmpEQ) { |
| 12230 | 11937 | // the division by zero error will be caught later, but we don't have a |
| ... | ... | @@ -12243,11 +11950,11 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o |
| 12243 | 11950 | } |
| 12244 | 11951 | } |
| 12245 | 11952 | if (!ok) { |
| 12246 | | ir_add_error(ira, &bin_op_instruction->base, |
| 11953 | ir_add_error(ira, &instruction->base, |
| 12247 | 11954 | buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact", |
| 12248 | 11955 | buf_ptr(&op1->value.type->name), |
| 12249 | 11956 | buf_ptr(&op2->value.type->name))); |
| 12250 | | return ira->codegen->builtin_types.entry_invalid; |
| 11957 | return ira->codegen->invalid_instruction; |
| 12251 | 11958 | } |
| 12252 | 11959 | } else { |
| 12253 | 11960 | op_id = IrBinOpDivTrunc; |
| ... | ... | @@ -12258,12 +11965,12 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o |
| 12258 | 11965 | if (instr_is_comptime(op1) && instr_is_comptime(op2)) { |
| 12259 | 11966 | ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 12260 | 11967 | if (op1_val == nullptr) |
| 12261 | | return ira->codegen->builtin_types.entry_invalid; |
| 11968 | return ira->codegen->invalid_instruction; |
| 12262 | 11969 | |
| 12263 | 11970 | if (is_int) { |
| 12264 | 11971 | ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 12265 | 11972 | if (op2_val == nullptr) |
| 12266 | | return ira->codegen->builtin_types.entry_invalid; |
| 11973 | return ira->codegen->invalid_instruction; |
| 12267 | 11974 | |
| 12268 | 11975 | if (bigint_cmp_zero(&op2->value.data.x_bigint) == CmpEQ) { |
| 12269 | 11976 | // the division by zero error will be caught later, but we don't |
| ... | ... | @@ -12279,11 +11986,11 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o |
| 12279 | 11986 | } else { |
| 12280 | 11987 | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type); |
| 12281 | 11988 | if (casted_op2 == ira->codegen->invalid_instruction) |
| 12282 | | return ira->codegen->builtin_types.entry_invalid; |
| 11989 | return ira->codegen->invalid_instruction; |
| 12283 | 11990 | |
| 12284 | 11991 | ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 12285 | 11992 | if (op2_val == nullptr) |
| 12286 | | return ira->codegen->builtin_types.entry_invalid; |
| 11993 | return ira->codegen->invalid_instruction; |
| 12287 | 11994 | |
| 12288 | 11995 | if (float_cmp_zero(&casted_op2->value) == CmpEQ) { |
| 12289 | 11996 | // the division by zero error will be caught later, but we don't |
| ... | ... | @@ -12299,11 +12006,11 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o |
| 12299 | 12006 | } |
| 12300 | 12007 | } |
| 12301 | 12008 | if (!ok) { |
| 12302 | | ir_add_error(ira, &bin_op_instruction->base, |
| 12009 | ir_add_error(ira, &instruction->base, |
| 12303 | 12010 | buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod", |
| 12304 | 12011 | buf_ptr(&op1->value.type->name), |
| 12305 | 12012 | buf_ptr(&op2->value.type->name))); |
| 12306 | | return ira->codegen->builtin_types.entry_invalid; |
| 12013 | return ira->codegen->invalid_instruction; |
| 12307 | 12014 | } |
| 12308 | 12015 | } |
| 12309 | 12016 | op_id = IrBinOpRemRem; |
| ... | ... | @@ -12324,12 +12031,12 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o |
| 12324 | 12031 | { |
| 12325 | 12032 | // float |
| 12326 | 12033 | } else { |
| 12327 | | AstNode *source_node = bin_op_instruction->base.source_node; |
| 12034 | AstNode *source_node = instruction->base.source_node; |
| 12328 | 12035 | ir_add_error_node(ira, source_node, |
| 12329 | 12036 | buf_sprintf("invalid operands to binary expression: '%s' and '%s'", |
| 12330 | 12037 | buf_ptr(&op1->value.type->name), |
| 12331 | 12038 | buf_ptr(&op2->value.type->name))); |
| 12332 | | return ira->codegen->builtin_types.entry_invalid; |
| 12039 | return ira->codegen->invalid_instruction; |
| 12333 | 12040 | } |
| 12334 | 12041 | |
| 12335 | 12042 | if (resolved_type->id == ZigTypeIdComptimeInt) { |
| ... | ... | @@ -12344,72 +12051,70 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o |
| 12344 | 12051 | |
| 12345 | 12052 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type); |
| 12346 | 12053 | if (casted_op1 == ira->codegen->invalid_instruction) |
| 12347 | | return ira->codegen->builtin_types.entry_invalid; |
| 12054 | return ira->codegen->invalid_instruction; |
| 12348 | 12055 | |
| 12349 | 12056 | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type); |
| 12350 | 12057 | if (casted_op2 == ira->codegen->invalid_instruction) |
| 12351 | | return ira->codegen->builtin_types.entry_invalid; |
| 12058 | return ira->codegen->invalid_instruction; |
| 12352 | 12059 | |
| 12353 | 12060 | if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) { |
| 12354 | 12061 | ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 12355 | 12062 | if (op1_val == nullptr) |
| 12356 | | return ira->codegen->builtin_types.entry_invalid; |
| 12063 | return ira->codegen->invalid_instruction; |
| 12357 | 12064 | ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 12358 | 12065 | if (op2_val == nullptr) |
| 12359 | | return ira->codegen->builtin_types.entry_invalid; |
| 12066 | return ira->codegen->invalid_instruction; |
| 12360 | 12067 | |
| 12361 | | IrInstruction *result_instruction = ir_get_const(ira, &bin_op_instruction->base); |
| 12362 | | ir_link_new_instruction(result_instruction, &bin_op_instruction->base); |
| 12363 | | ConstExprValue *out_val = &result_instruction->value; |
| 12068 | IrInstruction *result_instruction = ir_const(ira, &instruction->base, resolved_type); |
| 12364 | 12069 | |
| 12365 | 12070 | int err; |
| 12366 | | if ((err = ir_eval_math_op(resolved_type, op1_val, op_id, op2_val, out_val))) { |
| 12071 | if ((err = ir_eval_math_op(resolved_type, op1_val, op_id, op2_val, &result_instruction->value))) { |
| 12367 | 12072 | if (err == ErrorDivByZero) { |
| 12368 | | ir_add_error(ira, &bin_op_instruction->base, buf_sprintf("division by zero")); |
| 12369 | | return ira->codegen->builtin_types.entry_invalid; |
| 12073 | ir_add_error(ira, &instruction->base, buf_sprintf("division by zero")); |
| 12074 | return ira->codegen->invalid_instruction; |
| 12370 | 12075 | } else if (err == ErrorOverflow) { |
| 12371 | | ir_add_error(ira, &bin_op_instruction->base, buf_sprintf("operation caused overflow")); |
| 12372 | | return ira->codegen->builtin_types.entry_invalid; |
| 12076 | ir_add_error(ira, &instruction->base, buf_sprintf("operation caused overflow")); |
| 12077 | return ira->codegen->invalid_instruction; |
| 12373 | 12078 | } else if (err == ErrorExactDivRemainder) { |
| 12374 | | ir_add_error(ira, &bin_op_instruction->base, buf_sprintf("exact division had a remainder")); |
| 12375 | | return ira->codegen->builtin_types.entry_invalid; |
| 12079 | ir_add_error(ira, &instruction->base, buf_sprintf("exact division had a remainder")); |
| 12080 | return ira->codegen->invalid_instruction; |
| 12376 | 12081 | } else if (err == ErrorNegativeDenominator) { |
| 12377 | | ir_add_error(ira, &bin_op_instruction->base, buf_sprintf("negative denominator")); |
| 12378 | | return ira->codegen->builtin_types.entry_invalid; |
| 12082 | ir_add_error(ira, &instruction->base, buf_sprintf("negative denominator")); |
| 12083 | return ira->codegen->invalid_instruction; |
| 12379 | 12084 | } else { |
| 12380 | 12085 | zig_unreachable(); |
| 12381 | 12086 | } |
| 12382 | | return ira->codegen->builtin_types.entry_invalid; |
| 12087 | return ira->codegen->invalid_instruction; |
| 12383 | 12088 | } |
| 12384 | 12089 | |
| 12385 | 12090 | ir_num_lit_fits_in_other_type(ira, result_instruction, resolved_type, false); |
| 12386 | | return resolved_type; |
| 12091 | return result_instruction; |
| 12387 | 12092 | } |
| 12388 | 12093 | |
| 12389 | | ir_build_bin_op_from(&ira->new_irb, &bin_op_instruction->base, op_id, |
| 12390 | | casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 12391 | | return resolved_type; |
| 12094 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope, |
| 12095 | instruction->base.source_node, op_id, casted_op1, casted_op2, instruction->safety_check_on); |
| 12096 | result->value.type = resolved_type; |
| 12097 | return result; |
| 12392 | 12098 | } |
| 12393 | 12099 | |
| 12394 | | |
| 12395 | | static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 12396 | | IrInstruction *op1 = instruction->op1->other; |
| 12100 | static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 12101 | IrInstruction *op1 = instruction->op1->child; |
| 12397 | 12102 | ZigType *op1_type = op1->value.type; |
| 12398 | 12103 | if (type_is_invalid(op1_type)) |
| 12399 | | return ira->codegen->builtin_types.entry_invalid; |
| 12104 | return ira->codegen->invalid_instruction; |
| 12400 | 12105 | |
| 12401 | | IrInstruction *op2 = instruction->op2->other; |
| 12106 | IrInstruction *op2 = instruction->op2->child; |
| 12402 | 12107 | ZigType *op2_type = op2->value.type; |
| 12403 | 12108 | if (type_is_invalid(op2_type)) |
| 12404 | | return ira->codegen->builtin_types.entry_invalid; |
| 12109 | return ira->codegen->invalid_instruction; |
| 12405 | 12110 | |
| 12406 | 12111 | ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 12407 | 12112 | if (!op1_val) |
| 12408 | | return ira->codegen->builtin_types.entry_invalid; |
| 12113 | return ira->codegen->invalid_instruction; |
| 12409 | 12114 | |
| 12410 | 12115 | ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 12411 | 12116 | if (!op2_val) |
| 12412 | | return ira->codegen->builtin_types.entry_invalid; |
| 12117 | return ira->codegen->invalid_instruction; |
| 12413 | 12118 | |
| 12414 | 12119 | ConstExprValue *op1_array_val; |
| 12415 | 12120 | size_t op1_array_index; |
| ... | ... | @@ -12441,7 +12146,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc |
| 12441 | 12146 | } else { |
| 12442 | 12147 | ir_add_error(ira, op1, |
| 12443 | 12148 | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op1->value.type->name))); |
| 12444 | | return ira->codegen->builtin_types.entry_invalid; |
| 12149 | return ira->codegen->invalid_instruction; |
| 12445 | 12150 | } |
| 12446 | 12151 | |
| 12447 | 12152 | ConstExprValue *op2_array_val; |
| ... | ... | @@ -12452,7 +12157,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc |
| 12452 | 12157 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 12453 | 12158 | buf_ptr(&child_type->name), |
| 12454 | 12159 | buf_ptr(&op2->value.type->name))); |
| 12455 | | return ira->codegen->builtin_types.entry_invalid; |
| 12160 | return ira->codegen->invalid_instruction; |
| 12456 | 12161 | } |
| 12457 | 12162 | op2_array_val = op2_val; |
| 12458 | 12163 | op2_array_index = 0; |
| ... | ... | @@ -12466,7 +12171,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc |
| 12466 | 12171 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 12467 | 12172 | buf_ptr(&child_type->name), |
| 12468 | 12173 | buf_ptr(&op2->value.type->name))); |
| 12469 | | return ira->codegen->builtin_types.entry_invalid; |
| 12174 | return ira->codegen->invalid_instruction; |
| 12470 | 12175 | } |
| 12471 | 12176 | op2_array_val = op2_val->data.x_ptr.data.base_array.array_val; |
| 12472 | 12177 | op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index; |
| ... | ... | @@ -12477,7 +12182,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc |
| 12477 | 12182 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 12478 | 12183 | buf_ptr(&child_type->name), |
| 12479 | 12184 | buf_ptr(&op2->value.type->name))); |
| 12480 | | return ira->codegen->builtin_types.entry_invalid; |
| 12185 | return ira->codegen->invalid_instruction; |
| 12481 | 12186 | } |
| 12482 | 12187 | ConstExprValue *ptr_val = &op2_val->data.x_struct.fields[slice_ptr_index]; |
| 12483 | 12188 | assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); |
| ... | ... | @@ -12489,22 +12194,23 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc |
| 12489 | 12194 | } else { |
| 12490 | 12195 | ir_add_error(ira, op2, |
| 12491 | 12196 | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value.type->name))); |
| 12492 | | return ira->codegen->builtin_types.entry_invalid; |
| 12197 | return ira->codegen->invalid_instruction; |
| 12493 | 12198 | } |
| 12494 | 12199 | |
| 12495 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 12200 | // The type of result is populated in the following if blocks |
| 12201 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 12202 | ConstExprValue *out_val = &result->value; |
| 12496 | 12203 | |
| 12497 | | ZigType *result_type; |
| 12498 | 12204 | ConstExprValue *out_array_val; |
| 12499 | 12205 | size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index); |
| 12500 | 12206 | if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) { |
| 12501 | | result_type = get_array_type(ira->codegen, child_type, new_len); |
| 12207 | result->value.type = get_array_type(ira->codegen, child_type, new_len); |
| 12502 | 12208 | |
| 12503 | 12209 | out_array_val = out_val; |
| 12504 | 12210 | } else if (is_slice(op1_type) || is_slice(op2_type)) { |
| 12505 | 12211 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 12506 | 12212 | true, false, PtrLenUnknown, 0, 0, 0); |
| 12507 | | result_type = get_slice_type(ira->codegen, ptr_type); |
| 12213 | result->value.type = get_slice_type(ira->codegen, ptr_type); |
| 12508 | 12214 | out_array_val = create_const_vals(1); |
| 12509 | 12215 | out_array_val->special = ConstValSpecialStatic; |
| 12510 | 12216 | out_array_val->type = get_array_type(ira->codegen, child_type, new_len); |
| ... | ... | @@ -12524,7 +12230,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc |
| 12524 | 12230 | new_len += 1; // null byte |
| 12525 | 12231 | |
| 12526 | 12232 | // TODO make this `[*]null T` instead of `[*]T` |
| 12527 | | result_type = get_pointer_to_type_extra(ira->codegen, child_type, true, false, PtrLenUnknown, 0, 0, 0); |
| 12233 | result->value.type = get_pointer_to_type_extra(ira->codegen, child_type, true, false, PtrLenUnknown, 0, 0, 0); |
| 12528 | 12234 | |
| 12529 | 12235 | out_array_val = create_const_vals(1); |
| 12530 | 12236 | out_array_val->special = ConstValSpecialStatic; |
| ... | ... | @@ -12538,7 +12244,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc |
| 12538 | 12244 | if (op1_array_val->data.x_array.special == ConstArraySpecialUndef && |
| 12539 | 12245 | op2_array_val->data.x_array.special == ConstArraySpecialUndef) { |
| 12540 | 12246 | out_array_val->data.x_array.special = ConstArraySpecialUndef; |
| 12541 | | return result_type; |
| 12247 | return result; |
| 12542 | 12248 | } |
| 12543 | 12249 | |
| 12544 | 12250 | out_array_val->data.x_array.data.s_none.elements = create_const_vals(new_len); |
| ... | ... | @@ -12560,30 +12266,30 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc |
| 12560 | 12266 | } |
| 12561 | 12267 | assert(next_index == new_len); |
| 12562 | 12268 | |
| 12563 | | return result_type; |
| 12269 | return result; |
| 12564 | 12270 | } |
| 12565 | 12271 | |
| 12566 | | static ZigType *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 12567 | | IrInstruction *op1 = instruction->op1->other; |
| 12272 | static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 12273 | IrInstruction *op1 = instruction->op1->child; |
| 12568 | 12274 | if (type_is_invalid(op1->value.type)) |
| 12569 | | return ira->codegen->builtin_types.entry_invalid; |
| 12275 | return ira->codegen->invalid_instruction; |
| 12570 | 12276 | |
| 12571 | | IrInstruction *op2 = instruction->op2->other; |
| 12277 | IrInstruction *op2 = instruction->op2->child; |
| 12572 | 12278 | if (type_is_invalid(op2->value.type)) |
| 12573 | | return ira->codegen->builtin_types.entry_invalid; |
| 12279 | return ira->codegen->invalid_instruction; |
| 12574 | 12280 | |
| 12575 | 12281 | ConstExprValue *array_val = ir_resolve_const(ira, op1, UndefBad); |
| 12576 | 12282 | if (!array_val) |
| 12577 | | return ira->codegen->builtin_types.entry_invalid; |
| 12283 | return ira->codegen->invalid_instruction; |
| 12578 | 12284 | |
| 12579 | 12285 | uint64_t mult_amt; |
| 12580 | 12286 | if (!ir_resolve_usize(ira, op2, &mult_amt)) |
| 12581 | | return ira->codegen->builtin_types.entry_invalid; |
| 12287 | return ira->codegen->invalid_instruction; |
| 12582 | 12288 | |
| 12583 | 12289 | ZigType *array_type = op1->value.type; |
| 12584 | 12290 | if (array_type->id != ZigTypeIdArray) { |
| 12585 | 12291 | ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name))); |
| 12586 | | return ira->codegen->builtin_types.entry_invalid; |
| 12292 | return ira->codegen->invalid_instruction; |
| 12587 | 12293 | } |
| 12588 | 12294 | |
| 12589 | 12295 | uint64_t old_array_len = array_type->data.array.len; |
| ... | ... | @@ -12592,15 +12298,17 @@ static ZigType *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instru |
| 12592 | 12298 | if (mul_u64_overflow(old_array_len, mult_amt, &new_array_len)) |
| 12593 | 12299 | { |
| 12594 | 12300 | ir_add_error(ira, &instruction->base, buf_sprintf("operation results in overflow")); |
| 12595 | | return ira->codegen->builtin_types.entry_invalid; |
| 12301 | return ira->codegen->invalid_instruction; |
| 12596 | 12302 | } |
| 12597 | 12303 | |
| 12598 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 12304 | ZigType *child_type = array_type->data.array.child_type; |
| 12305 | |
| 12306 | IrInstruction *result = ir_const(ira, &instruction->base, |
| 12307 | get_array_type(ira->codegen, child_type, new_array_len)); |
| 12308 | ConstExprValue *out_val = &result->value; |
| 12599 | 12309 | if (array_val->data.x_array.special == ConstArraySpecialUndef) { |
| 12600 | 12310 | out_val->data.x_array.special = ConstArraySpecialUndef; |
| 12601 | | |
| 12602 | | ZigType *child_type = array_type->data.array.child_type; |
| 12603 | | return get_array_type(ira->codegen, child_type, new_array_len); |
| 12311 | return result; |
| 12604 | 12312 | } |
| 12605 | 12313 | |
| 12606 | 12314 | // TODO optimize the buf case |
| ... | ... | @@ -12616,45 +12324,42 @@ static ZigType *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instru |
| 12616 | 12324 | } |
| 12617 | 12325 | assert(i == new_array_len); |
| 12618 | 12326 | |
| 12619 | | ZigType *child_type = array_type->data.array.child_type; |
| 12620 | | return get_array_type(ira->codegen, child_type, new_array_len); |
| 12327 | return result; |
| 12621 | 12328 | } |
| 12622 | 12329 | |
| 12623 | | static ZigType *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 12624 | | ZigType *op1_type = ir_resolve_type(ira, instruction->op1->other); |
| 12330 | static IrInstruction *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 12331 | ZigType *op1_type = ir_resolve_type(ira, instruction->op1->child); |
| 12625 | 12332 | if (type_is_invalid(op1_type)) |
| 12626 | | return ira->codegen->builtin_types.entry_invalid; |
| 12333 | return ira->codegen->invalid_instruction; |
| 12627 | 12334 | |
| 12628 | 12335 | if (op1_type->id != ZigTypeIdErrorSet) { |
| 12629 | 12336 | ir_add_error(ira, instruction->op1, |
| 12630 | 12337 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&op1_type->name))); |
| 12631 | | return ira->codegen->builtin_types.entry_invalid; |
| 12338 | return ira->codegen->invalid_instruction; |
| 12632 | 12339 | } |
| 12633 | 12340 | |
| 12634 | | ZigType *op2_type = ir_resolve_type(ira, instruction->op2->other); |
| 12341 | ZigType *op2_type = ir_resolve_type(ira, instruction->op2->child); |
| 12635 | 12342 | if (type_is_invalid(op2_type)) |
| 12636 | | return ira->codegen->builtin_types.entry_invalid; |
| 12343 | return ira->codegen->invalid_instruction; |
| 12637 | 12344 | |
| 12638 | 12345 | if (op2_type->id != ZigTypeIdErrorSet) { |
| 12639 | 12346 | ir_add_error(ira, instruction->op2, |
| 12640 | 12347 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&op2_type->name))); |
| 12641 | | return ira->codegen->builtin_types.entry_invalid; |
| 12348 | return ira->codegen->invalid_instruction; |
| 12642 | 12349 | } |
| 12643 | 12350 | |
| 12644 | 12351 | if (type_is_global_error_set(op1_type) || |
| 12645 | 12352 | type_is_global_error_set(op2_type)) |
| 12646 | 12353 | { |
| 12647 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 12648 | | out_val->data.x_type = ira->codegen->builtin_types.entry_global_error_set; |
| 12649 | | return ira->codegen->builtin_types.entry_type; |
| 12354 | return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_global_error_set); |
| 12650 | 12355 | } |
| 12651 | 12356 | |
| 12652 | | if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->other->source_node)) { |
| 12653 | | return ira->codegen->builtin_types.entry_invalid; |
| 12357 | if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->source_node)) { |
| 12358 | return ira->codegen->invalid_instruction; |
| 12654 | 12359 | } |
| 12655 | 12360 | |
| 12656 | | if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->other->source_node)) { |
| 12657 | | return ira->codegen->builtin_types.entry_invalid; |
| 12361 | if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->source_node)) { |
| 12362 | return ira->codegen->invalid_instruction; |
| 12658 | 12363 | } |
| 12659 | 12364 | |
| 12660 | 12365 | ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length); |
| ... | ... | @@ -12666,13 +12371,10 @@ static ZigType *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp * |
| 12666 | 12371 | ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type); |
| 12667 | 12372 | free(errors); |
| 12668 | 12373 | |
| 12669 | | |
| 12670 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 12671 | | out_val->data.x_type = result_type; |
| 12672 | | return ira->codegen->builtin_types.entry_type; |
| 12374 | return ir_const_type(ira, &instruction->base, result_type); |
| 12673 | 12375 | } |
| 12674 | 12376 | |
| 12675 | | static ZigType *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 12377 | static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 12676 | 12378 | IrBinOp op_id = bin_op_instruction->op_id; |
| 12677 | 12379 | switch (op_id) { |
| 12678 | 12380 | case IrBinOpInvalid: |
| ... | ... | @@ -12719,25 +12421,25 @@ static ZigType *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp |
| 12719 | 12421 | zig_unreachable(); |
| 12720 | 12422 | } |
| 12721 | 12423 | |
| 12722 | | static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDeclVar *decl_var_instruction) { |
| 12424 | static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDeclVar *decl_var_instruction) { |
| 12723 | 12425 | Error err; |
| 12724 | 12426 | ZigVar *var = decl_var_instruction->var; |
| 12725 | 12427 | |
| 12726 | | IrInstruction *init_value = decl_var_instruction->init_value->other; |
| 12428 | IrInstruction *init_value = decl_var_instruction->init_value->child; |
| 12727 | 12429 | if (type_is_invalid(init_value->value.type)) { |
| 12728 | 12430 | var->value->type = ira->codegen->builtin_types.entry_invalid; |
| 12729 | | return var->value->type; |
| 12431 | return ira->codegen->invalid_instruction; |
| 12730 | 12432 | } |
| 12731 | 12433 | |
| 12732 | 12434 | ZigType *explicit_type = nullptr; |
| 12733 | 12435 | IrInstruction *var_type = nullptr; |
| 12734 | 12436 | if (decl_var_instruction->var_type != nullptr) { |
| 12735 | | var_type = decl_var_instruction->var_type->other; |
| 12437 | var_type = decl_var_instruction->var_type->child; |
| 12736 | 12438 | ZigType *proposed_type = ir_resolve_type(ira, var_type); |
| 12737 | 12439 | explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type); |
| 12738 | 12440 | if (type_is_invalid(explicit_type)) { |
| 12739 | 12441 | var->value->type = ira->codegen->builtin_types.entry_invalid; |
| 12740 | | return var->value->type; |
| 12442 | return ira->codegen->invalid_instruction; |
| 12741 | 12443 | } |
| 12742 | 12444 | } |
| 12743 | 12445 | |
| ... | ... | @@ -12815,19 +12517,17 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec |
| 12815 | 12517 | assert(var->value->type); |
| 12816 | 12518 | |
| 12817 | 12519 | if (type_is_invalid(result_type)) { |
| 12818 | | decl_var_instruction->base.other = &decl_var_instruction->base; |
| 12819 | | return ira->codegen->builtin_types.entry_void; |
| 12520 | return ir_const_void(ira, &decl_var_instruction->base); |
| 12820 | 12521 | } |
| 12821 | 12522 | |
| 12822 | 12523 | if (decl_var_instruction->align_value == nullptr) { |
| 12823 | 12524 | if ((err = type_resolve(ira->codegen, result_type, ResolveStatusAlignmentKnown))) { |
| 12824 | 12525 | var->value->type = ira->codegen->builtin_types.entry_invalid; |
| 12825 | | decl_var_instruction->base.other = &decl_var_instruction->base; |
| 12826 | | return ira->codegen->builtin_types.entry_void; |
| 12526 | return ir_const_void(ira, &decl_var_instruction->base); |
| 12827 | 12527 | } |
| 12828 | 12528 | var->align_bytes = get_abi_alignment(ira->codegen, result_type); |
| 12829 | 12529 | } else { |
| 12830 | | if (!ir_resolve_align(ira, decl_var_instruction->align_value->other, &var->align_bytes)) { |
| 12530 | if (!ir_resolve_align(ira, decl_var_instruction->align_value->child, &var->align_bytes)) { |
| 12831 | 12531 | var->value->type = ira->codegen->builtin_types.entry_invalid; |
| 12832 | 12532 | } |
| 12833 | 12533 | } |
| ... | ... | @@ -12839,43 +12539,44 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec |
| 12839 | 12539 | copy_const_val(mem_slot, &casted_init_value->value, !is_comptime_var || var->gen_is_const); |
| 12840 | 12540 | |
| 12841 | 12541 | if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) { |
| 12842 | | ir_build_const_from(ira, &decl_var_instruction->base); |
| 12843 | | return ira->codegen->builtin_types.entry_void; |
| 12542 | return ir_const_void(ira, &decl_var_instruction->base); |
| 12844 | 12543 | } |
| 12845 | 12544 | } |
| 12846 | 12545 | } else if (is_comptime_var) { |
| 12847 | 12546 | ir_add_error(ira, &decl_var_instruction->base, |
| 12848 | 12547 | buf_sprintf("cannot store runtime value in compile time variable")); |
| 12849 | 12548 | var->value->type = ira->codegen->builtin_types.entry_invalid; |
| 12850 | | return ira->codegen->builtin_types.entry_invalid; |
| 12549 | return ira->codegen->invalid_instruction; |
| 12851 | 12550 | } |
| 12852 | 12551 | |
| 12853 | | ir_build_var_decl_from(&ira->new_irb, &decl_var_instruction->base, var, var_type, nullptr, casted_init_value); |
| 12854 | | |
| 12855 | 12552 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 12856 | 12553 | if (fn_entry) |
| 12857 | 12554 | fn_entry->variable_list.append(var); |
| 12858 | 12555 | |
| 12859 | | return ira->codegen->builtin_types.entry_void; |
| 12556 | IrInstruction *result = ir_build_var_decl(&ira->new_irb, |
| 12557 | decl_var_instruction->base.scope, decl_var_instruction->base.source_node, |
| 12558 | var, var_type, nullptr, casted_init_value); |
| 12559 | result->value.type = ira->codegen->builtin_types.entry_void; |
| 12560 | return result; |
| 12860 | 12561 | } |
| 12861 | 12562 | |
| 12862 | | static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) { |
| 12863 | | IrInstruction *name = instruction->name->other; |
| 12563 | static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) { |
| 12564 | IrInstruction *name = instruction->name->child; |
| 12864 | 12565 | Buf *symbol_name = ir_resolve_str(ira, name); |
| 12865 | 12566 | if (symbol_name == nullptr) { |
| 12866 | | return ira->codegen->builtin_types.entry_invalid; |
| 12567 | return ira->codegen->invalid_instruction; |
| 12867 | 12568 | } |
| 12868 | 12569 | |
| 12869 | | IrInstruction *target = instruction->target->other; |
| 12570 | IrInstruction *target = instruction->target->child; |
| 12870 | 12571 | if (type_is_invalid(target->value.type)) { |
| 12871 | | return ira->codegen->builtin_types.entry_invalid; |
| 12572 | return ira->codegen->invalid_instruction; |
| 12872 | 12573 | } |
| 12873 | 12574 | |
| 12874 | 12575 | GlobalLinkageId global_linkage_id = GlobalLinkageIdStrong; |
| 12875 | 12576 | if (instruction->linkage != nullptr) { |
| 12876 | | IrInstruction *linkage_value = instruction->linkage->other; |
| 12577 | IrInstruction *linkage_value = instruction->linkage->child; |
| 12877 | 12578 | if (!ir_resolve_global_linkage(ira, linkage_value, &global_linkage_id)) { |
| 12878 | | return ira->codegen->builtin_types.entry_invalid; |
| 12579 | return ira->codegen->invalid_instruction; |
| 12879 | 12580 | } |
| 12880 | 12581 | } |
| 12881 | 12582 | |
| ... | ... | @@ -13023,8 +12724,7 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor |
| 13023 | 12724 | break; |
| 13024 | 12725 | } |
| 13025 | 12726 | |
| 13026 | | ir_build_const_from(ira, &instruction->base); |
| 13027 | | return ira->codegen->builtin_types.entry_void; |
| 12727 | return ir_const_void(ira, &instruction->base); |
| 13028 | 12728 | } |
| 13029 | 12729 | |
| 13030 | 12730 | static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) { |
| ... | ... | @@ -13032,59 +12732,58 @@ static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) { |
| 13032 | 12732 | return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing; |
| 13033 | 12733 | } |
| 13034 | 12734 | |
| 13035 | | static ZigType *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 12735 | static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 13036 | 12736 | IrInstructionErrorReturnTrace *instruction) |
| 13037 | 12737 | { |
| 13038 | 12738 | if (instruction->optional == IrInstructionErrorReturnTrace::Null) { |
| 13039 | 12739 | ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(ira->codegen); |
| 13040 | 12740 | ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type); |
| 13041 | 12741 | if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) { |
| 13042 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 12742 | IrInstruction *result = ir_const(ira, &instruction->base, optional_type); |
| 12743 | ConstExprValue *out_val = &result->value; |
| 13043 | 12744 | assert(get_codegen_ptr_type(optional_type) != nullptr); |
| 13044 | 12745 | out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 13045 | 12746 | out_val->data.x_ptr.data.hard_coded_addr.addr = 0; |
| 13046 | | return optional_type; |
| 12747 | return result; |
| 13047 | 12748 | } |
| 13048 | 12749 | IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope, |
| 13049 | 12750 | instruction->base.source_node, instruction->optional); |
| 13050 | | ir_link_new_instruction(new_instruction, &instruction->base); |
| 13051 | | return optional_type; |
| 12751 | new_instruction->value.type = optional_type; |
| 12752 | return new_instruction; |
| 13052 | 12753 | } else { |
| 13053 | 12754 | assert(ira->codegen->have_err_ret_tracing); |
| 13054 | 12755 | IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope, |
| 13055 | 12756 | instruction->base.source_node, instruction->optional); |
| 13056 | | ir_link_new_instruction(new_instruction, &instruction->base); |
| 13057 | | return get_ptr_to_stack_trace_type(ira->codegen); |
| 12757 | new_instruction->value.type = get_ptr_to_stack_trace_type(ira->codegen); |
| 12758 | return new_instruction; |
| 13058 | 12759 | } |
| 13059 | 12760 | } |
| 13060 | 12761 | |
| 13061 | | static ZigType *ir_analyze_instruction_error_union(IrAnalyze *ira, |
| 12762 | static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira, |
| 13062 | 12763 | IrInstructionErrorUnion *instruction) |
| 13063 | 12764 | { |
| 13064 | 12765 | Error err; |
| 13065 | 12766 | |
| 13066 | | ZigType *err_set_type = ir_resolve_type(ira, instruction->err_set->other); |
| 12767 | ZigType *err_set_type = ir_resolve_type(ira, instruction->err_set->child); |
| 13067 | 12768 | if (type_is_invalid(err_set_type)) |
| 13068 | | return ira->codegen->builtin_types.entry_invalid; |
| 12769 | return ira->codegen->invalid_instruction; |
| 13069 | 12770 | |
| 13070 | | ZigType *payload_type = ir_resolve_type(ira, instruction->payload->other); |
| 12771 | ZigType *payload_type = ir_resolve_type(ira, instruction->payload->child); |
| 13071 | 12772 | if (type_is_invalid(payload_type)) |
| 13072 | | return ira->codegen->builtin_types.entry_invalid; |
| 12773 | return ira->codegen->invalid_instruction; |
| 13073 | 12774 | |
| 13074 | 12775 | if (err_set_type->id != ZigTypeIdErrorSet) { |
| 13075 | | ir_add_error(ira, instruction->err_set->other, |
| 12776 | ir_add_error(ira, instruction->err_set->child, |
| 13076 | 12777 | buf_sprintf("expected error set type, found type '%s'", |
| 13077 | 12778 | buf_ptr(&err_set_type->name))); |
| 13078 | | return ira->codegen->builtin_types.entry_invalid; |
| 12779 | return ira->codegen->invalid_instruction; |
| 13079 | 12780 | } |
| 13080 | 12781 | |
| 13081 | 12782 | if ((err = type_resolve(ira->codegen, payload_type, ResolveStatusSizeKnown))) |
| 13082 | | return ira->codegen->builtin_types.entry_invalid; |
| 12783 | return ira->codegen->invalid_instruction; |
| 13083 | 12784 | ZigType *result_type = get_error_union_type(ira->codegen, err_set_type, payload_type); |
| 13084 | 12785 | |
| 13085 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 13086 | | out_val->data.x_type = result_type; |
| 13087 | | return ira->codegen->builtin_types.entry_type; |
| 12786 | return ir_const_type(ira, &instruction->base, result_type); |
| 13088 | 12787 | } |
| 13089 | 12788 | |
| 13090 | 12789 | IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_instr, ImplicitAllocatorId id) { |
| ... | ... | @@ -13362,7 +13061,7 @@ no_mem_slot: |
| 13362 | 13061 | return var_ptr_instruction; |
| 13363 | 13062 | } |
| 13364 | 13063 | |
| 13365 | | static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction, |
| 13064 | static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction, |
| 13366 | 13065 | ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref, |
| 13367 | 13066 | IrInstruction *first_arg_ptr, bool comptime_fn_call, FnInline fn_inline) |
| 13368 | 13067 | { |
| ... | ... | @@ -13382,7 +13081,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13382 | 13081 | |
| 13383 | 13082 | size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0; |
| 13384 | 13083 | for (size_t i = 0; i < call_instruction->arg_count; i += 1) { |
| 13385 | | ConstExprValue *arg_tuple_value = &call_instruction->args[i]->other->value; |
| 13084 | ConstExprValue *arg_tuple_value = &call_instruction->args[i]->child->value; |
| 13386 | 13085 | if (arg_tuple_value->type->id == ZigTypeIdArgTuple) { |
| 13387 | 13086 | call_param_count -= 1; |
| 13388 | 13087 | call_param_count += arg_tuple_value->data.x_arg_tuple.end_index - |
| ... | ... | @@ -13398,21 +13097,21 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13398 | 13097 | if (fn_proto_node) { |
| 13399 | 13098 | add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here")); |
| 13400 | 13099 | } |
| 13401 | | return ira->codegen->builtin_types.entry_invalid; |
| 13100 | return ira->codegen->invalid_instruction; |
| 13402 | 13101 | } |
| 13403 | 13102 | if (fn_type_id->cc == CallingConventionAsync && !call_instruction->is_async) { |
| 13404 | 13103 | ErrorMsg *msg = ir_add_error(ira, fn_ref, buf_sprintf("must use async keyword to call async function")); |
| 13405 | 13104 | if (fn_proto_node) { |
| 13406 | 13105 | add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here")); |
| 13407 | 13106 | } |
| 13408 | | return ira->codegen->builtin_types.entry_invalid; |
| 13107 | return ira->codegen->invalid_instruction; |
| 13409 | 13108 | } |
| 13410 | 13109 | if (fn_type_id->cc != CallingConventionAsync && call_instruction->is_async) { |
| 13411 | 13110 | ErrorMsg *msg = ir_add_error(ira, fn_ref, buf_sprintf("cannot use async keyword to call non-async function")); |
| 13412 | 13111 | if (fn_proto_node) { |
| 13413 | 13112 | add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here")); |
| 13414 | 13113 | } |
| 13415 | | return ira->codegen->builtin_types.entry_invalid; |
| 13114 | return ira->codegen->invalid_instruction; |
| 13416 | 13115 | } |
| 13417 | 13116 | |
| 13418 | 13117 | |
| ... | ... | @@ -13424,7 +13123,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13424 | 13123 | add_error_note(ira->codegen, msg, fn_proto_node, |
| 13425 | 13124 | buf_sprintf("declared here")); |
| 13426 | 13125 | } |
| 13427 | | return ira->codegen->builtin_types.entry_invalid; |
| 13126 | return ira->codegen->invalid_instruction; |
| 13428 | 13127 | } |
| 13429 | 13128 | } else if (src_param_count != call_param_count) { |
| 13430 | 13129 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| ... | ... | @@ -13433,18 +13132,18 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13433 | 13132 | add_error_note(ira->codegen, msg, fn_proto_node, |
| 13434 | 13133 | buf_sprintf("declared here")); |
| 13435 | 13134 | } |
| 13436 | | return ira->codegen->builtin_types.entry_invalid; |
| 13135 | return ira->codegen->invalid_instruction; |
| 13437 | 13136 | } |
| 13438 | 13137 | |
| 13439 | 13138 | if (comptime_fn_call) { |
| 13440 | 13139 | // No special handling is needed for compile time evaluation of generic functions. |
| 13441 | 13140 | if (!fn_entry || fn_entry->body_node == nullptr) { |
| 13442 | 13141 | ir_add_error(ira, fn_ref, buf_sprintf("unable to evaluate constant expression")); |
| 13443 | | return ira->codegen->builtin_types.entry_invalid; |
| 13142 | return ira->codegen->invalid_instruction; |
| 13444 | 13143 | } |
| 13445 | 13144 | |
| 13446 | 13145 | if (!ir_emit_backward_branch(ira, &call_instruction->base)) |
| 13447 | | return ira->codegen->builtin_types.entry_invalid; |
| 13146 | return ira->codegen->invalid_instruction; |
| 13448 | 13147 | |
| 13449 | 13148 | // Fork a scope of the function with known values for the parameters. |
| 13450 | 13149 | Scope *exec_scope = &fn_entry->fndef_scope->base; |
| ... | ... | @@ -13457,7 +13156,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13457 | 13156 | if (fn_type_id->next_param_index >= 1) { |
| 13458 | 13157 | ZigType *param_type = fn_type_id->param_info[next_proto_i].type; |
| 13459 | 13158 | if (type_is_invalid(param_type)) |
| 13460 | | return ira->codegen->builtin_types.entry_invalid; |
| 13159 | return ira->codegen->invalid_instruction; |
| 13461 | 13160 | first_arg_known_bare = param_type->id != ZigTypeIdPointer; |
| 13462 | 13161 | } |
| 13463 | 13162 | |
| ... | ... | @@ -13467,39 +13166,39 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13467 | 13166 | } else { |
| 13468 | 13167 | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr); |
| 13469 | 13168 | if (type_is_invalid(first_arg->value.type)) |
| 13470 | | return ira->codegen->builtin_types.entry_invalid; |
| 13169 | return ira->codegen->invalid_instruction; |
| 13471 | 13170 | } |
| 13472 | 13171 | |
| 13473 | 13172 | if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, first_arg, &exec_scope, &next_proto_i)) |
| 13474 | | return ira->codegen->builtin_types.entry_invalid; |
| 13173 | return ira->codegen->invalid_instruction; |
| 13475 | 13174 | } |
| 13476 | 13175 | |
| 13477 | 13176 | if (fn_proto_node->data.fn_proto.is_var_args) { |
| 13478 | 13177 | ir_add_error(ira, &call_instruction->base, |
| 13479 | 13178 | buf_sprintf("compiler bug: unable to call var args function at compile time. https://github.com/ziglang/zig/issues/313")); |
| 13480 | | return ira->codegen->builtin_types.entry_invalid; |
| 13179 | return ira->codegen->invalid_instruction; |
| 13481 | 13180 | } |
| 13482 | 13181 | |
| 13483 | 13182 | |
| 13484 | 13183 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 13485 | | IrInstruction *old_arg = call_instruction->args[call_i]->other; |
| 13184 | IrInstruction *old_arg = call_instruction->args[call_i]->child; |
| 13486 | 13185 | if (type_is_invalid(old_arg->value.type)) |
| 13487 | | return ira->codegen->builtin_types.entry_invalid; |
| 13186 | return ira->codegen->invalid_instruction; |
| 13488 | 13187 | |
| 13489 | 13188 | if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i)) |
| 13490 | | return ira->codegen->builtin_types.entry_invalid; |
| 13189 | return ira->codegen->invalid_instruction; |
| 13491 | 13190 | } |
| 13492 | 13191 | |
| 13493 | 13192 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; |
| 13494 | 13193 | ZigType *specified_return_type = analyze_type_expr(ira->codegen, exec_scope, return_type_node); |
| 13495 | 13194 | if (type_is_invalid(specified_return_type)) |
| 13496 | | return ira->codegen->builtin_types.entry_invalid; |
| 13195 | return ira->codegen->invalid_instruction; |
| 13497 | 13196 | ZigType *return_type; |
| 13498 | 13197 | ZigType *inferred_err_set_type = nullptr; |
| 13499 | 13198 | if (fn_proto_node->data.fn_proto.auto_err_set) { |
| 13500 | 13199 | inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry); |
| 13501 | 13200 | if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown))) |
| 13502 | | return ira->codegen->builtin_types.entry_invalid; |
| 13201 | return ira->codegen->invalid_instruction; |
| 13503 | 13202 | return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); |
| 13504 | 13203 | } else { |
| 13505 | 13204 | return_type = specified_return_type; |
| ... | ... | @@ -13542,12 +13241,14 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13542 | 13241 | } |
| 13543 | 13242 | |
| 13544 | 13243 | if (type_is_invalid(result->value.type)) |
| 13545 | | return ira->codegen->builtin_types.entry_invalid; |
| 13244 | return ira->codegen->invalid_instruction; |
| 13546 | 13245 | } |
| 13547 | 13246 | |
| 13548 | | ConstExprValue *out_val = ir_build_const_from(ira, &call_instruction->base); |
| 13549 | | *out_val = result->value; |
| 13550 | | return ir_finish_anal(ira, return_type); |
| 13247 | IrInstruction *new_instruction = ir_const(ira, &call_instruction->base, result->value.type); |
| 13248 | // TODO should we use copy_const_val? |
| 13249 | new_instruction->value = result->value; |
| 13250 | new_instruction->value.type = return_type; |
| 13251 | return ir_finish_anal(ira, new_instruction); |
| 13551 | 13252 | } |
| 13552 | 13253 | |
| 13553 | 13254 | IrInstruction *casted_new_stack = nullptr; |
| ... | ... | @@ -13555,28 +13256,28 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13555 | 13256 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 13556 | 13257 | false, false, PtrLenUnknown, 0, 0, 0); |
| 13557 | 13258 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 13558 | | IrInstruction *new_stack = call_instruction->new_stack->other; |
| 13259 | IrInstruction *new_stack = call_instruction->new_stack->child; |
| 13559 | 13260 | if (type_is_invalid(new_stack->value.type)) |
| 13560 | | return ira->codegen->builtin_types.entry_invalid; |
| 13261 | return ira->codegen->invalid_instruction; |
| 13561 | 13262 | |
| 13562 | 13263 | casted_new_stack = ir_implicit_cast(ira, new_stack, u8_slice); |
| 13563 | 13264 | if (type_is_invalid(casted_new_stack->value.type)) |
| 13564 | | return ira->codegen->builtin_types.entry_invalid; |
| 13265 | return ira->codegen->invalid_instruction; |
| 13565 | 13266 | } |
| 13566 | 13267 | |
| 13567 | 13268 | if (fn_type->data.fn.is_generic) { |
| 13568 | 13269 | if (!fn_entry) { |
| 13569 | 13270 | ir_add_error(ira, call_instruction->fn_ref, |
| 13570 | 13271 | buf_sprintf("calling a generic function requires compile-time known function value")); |
| 13571 | | return ira->codegen->builtin_types.entry_invalid; |
| 13272 | return ira->codegen->invalid_instruction; |
| 13572 | 13273 | } |
| 13573 | 13274 | |
| 13574 | 13275 | // Count the arguments of the function type id we are creating |
| 13575 | 13276 | size_t new_fn_arg_count = first_arg_1_or_0; |
| 13576 | 13277 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 13577 | | IrInstruction *arg = call_instruction->args[call_i]->other; |
| 13278 | IrInstruction *arg = call_instruction->args[call_i]->child; |
| 13578 | 13279 | if (type_is_invalid(arg->value.type)) |
| 13579 | | return ira->codegen->builtin_types.entry_invalid; |
| 13280 | return ira->codegen->invalid_instruction; |
| 13580 | 13281 | |
| 13581 | 13282 | if (arg->value.type->id == ZigTypeIdArgTuple) { |
| 13582 | 13283 | new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index; |
| ... | ... | @@ -13614,7 +13315,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13614 | 13315 | if (fn_type_id->next_param_index >= 1) { |
| 13615 | 13316 | ZigType *param_type = fn_type_id->param_info[next_proto_i].type; |
| 13616 | 13317 | if (type_is_invalid(param_type)) |
| 13617 | | return ira->codegen->builtin_types.entry_invalid; |
| 13318 | return ira->codegen->invalid_instruction; |
| 13618 | 13319 | first_arg_known_bare = param_type->id != ZigTypeIdPointer; |
| 13619 | 13320 | } |
| 13620 | 13321 | |
| ... | ... | @@ -13624,13 +13325,13 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13624 | 13325 | } else { |
| 13625 | 13326 | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr); |
| 13626 | 13327 | if (type_is_invalid(first_arg->value.type)) |
| 13627 | | return ira->codegen->builtin_types.entry_invalid; |
| 13328 | return ira->codegen->invalid_instruction; |
| 13628 | 13329 | } |
| 13629 | 13330 | |
| 13630 | 13331 | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, &impl_fn->child_scope, |
| 13631 | 13332 | &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn)) |
| 13632 | 13333 | { |
| 13633 | | return ira->codegen->builtin_types.entry_invalid; |
| 13334 | return ira->codegen->invalid_instruction; |
| 13634 | 13335 | } |
| 13635 | 13336 | } |
| 13636 | 13337 | |
| ... | ... | @@ -13640,9 +13341,9 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13640 | 13341 | ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 13641 | 13342 | assert(parent_fn_entry); |
| 13642 | 13343 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 13643 | | IrInstruction *arg = call_instruction->args[call_i]->other; |
| 13344 | IrInstruction *arg = call_instruction->args[call_i]->child; |
| 13644 | 13345 | if (type_is_invalid(arg->value.type)) |
| 13645 | | return ira->codegen->builtin_types.entry_invalid; |
| 13346 | return ira->codegen->invalid_instruction; |
| 13646 | 13347 | |
| 13647 | 13348 | if (arg->value.type->id == ZigTypeIdArgTuple) { |
| 13648 | 13349 | for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index; |
| ... | ... | @@ -13660,20 +13361,20 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13660 | 13361 | if (arg_var == nullptr) { |
| 13661 | 13362 | ir_add_error(ira, arg, |
| 13662 | 13363 | buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557")); |
| 13663 | | return ira->codegen->builtin_types.entry_invalid; |
| 13364 | return ira->codegen->invalid_instruction; |
| 13664 | 13365 | } |
| 13665 | 13366 | IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var); |
| 13666 | 13367 | if (type_is_invalid(arg_var_ptr_inst->value.type)) |
| 13667 | | return ira->codegen->builtin_types.entry_invalid; |
| 13368 | return ira->codegen->invalid_instruction; |
| 13668 | 13369 | |
| 13669 | 13370 | IrInstruction *arg_tuple_arg = ir_get_deref(ira, arg, arg_var_ptr_inst); |
| 13670 | 13371 | if (type_is_invalid(arg_tuple_arg->value.type)) |
| 13671 | | return ira->codegen->builtin_types.entry_invalid; |
| 13372 | return ira->codegen->invalid_instruction; |
| 13672 | 13373 | |
| 13673 | 13374 | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg_tuple_arg, &impl_fn->child_scope, |
| 13674 | 13375 | &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn)) |
| 13675 | 13376 | { |
| 13676 | | return ira->codegen->builtin_types.entry_invalid; |
| 13377 | return ira->codegen->invalid_instruction; |
| 13677 | 13378 | } |
| 13678 | 13379 | } |
| 13679 | 13380 | } else { |
| ... | ... | @@ -13688,7 +13389,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13688 | 13389 | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope, |
| 13689 | 13390 | &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn)) |
| 13690 | 13391 | { |
| 13691 | | return ira->codegen->builtin_types.entry_invalid; |
| 13392 | return ira->codegen->invalid_instruction; |
| 13692 | 13393 | } |
| 13693 | 13394 | } |
| 13694 | 13395 | } |
| ... | ... | @@ -13724,18 +13425,18 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13724 | 13425 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; |
| 13725 | 13426 | ZigType *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node); |
| 13726 | 13427 | if (type_is_invalid(specified_return_type)) |
| 13727 | | return ira->codegen->builtin_types.entry_invalid; |
| 13428 | return ira->codegen->invalid_instruction; |
| 13728 | 13429 | if (fn_proto_node->data.fn_proto.auto_err_set) { |
| 13729 | 13430 | ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn); |
| 13730 | 13431 | if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown))) |
| 13731 | | return ira->codegen->builtin_types.entry_invalid; |
| 13432 | return ira->codegen->invalid_instruction; |
| 13732 | 13433 | inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); |
| 13733 | 13434 | } else { |
| 13734 | 13435 | inst_fn_type_id.return_type = specified_return_type; |
| 13735 | 13436 | } |
| 13736 | 13437 | |
| 13737 | 13438 | if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusZeroBitsKnown))) |
| 13738 | | return ira->codegen->builtin_types.entry_invalid; |
| 13439 | return ira->codegen->invalid_instruction; |
| 13739 | 13440 | |
| 13740 | 13441 | if (type_requires_comptime(specified_return_type)) { |
| 13741 | 13442 | // Throw out our work and call the function as if it were comptime. |
| ... | ... | @@ -13748,7 +13449,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13748 | 13449 | if (async_allocator_type_node != nullptr) { |
| 13749 | 13450 | ZigType *async_allocator_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, async_allocator_type_node); |
| 13750 | 13451 | if (type_is_invalid(async_allocator_type)) |
| 13751 | | return ira->codegen->builtin_types.entry_invalid; |
| 13452 | return ira->codegen->invalid_instruction; |
| 13752 | 13453 | inst_fn_type_id.async_allocator_type = async_allocator_type; |
| 13753 | 13454 | } |
| 13754 | 13455 | IrInstruction *uncasted_async_allocator_inst; |
| ... | ... | @@ -13756,18 +13457,18 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13756 | 13457 | uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base, |
| 13757 | 13458 | ImplicitAllocatorIdLocalVar); |
| 13758 | 13459 | if (type_is_invalid(uncasted_async_allocator_inst->value.type)) |
| 13759 | | return ira->codegen->builtin_types.entry_invalid; |
| 13460 | return ira->codegen->invalid_instruction; |
| 13760 | 13461 | } else { |
| 13761 | | uncasted_async_allocator_inst = call_instruction->async_allocator->other; |
| 13462 | uncasted_async_allocator_inst = call_instruction->async_allocator->child; |
| 13762 | 13463 | if (type_is_invalid(uncasted_async_allocator_inst->value.type)) |
| 13763 | | return ira->codegen->builtin_types.entry_invalid; |
| 13464 | return ira->codegen->invalid_instruction; |
| 13764 | 13465 | } |
| 13765 | 13466 | if (inst_fn_type_id.async_allocator_type == nullptr) { |
| 13766 | 13467 | inst_fn_type_id.async_allocator_type = uncasted_async_allocator_inst->value.type; |
| 13767 | 13468 | } |
| 13768 | 13469 | async_allocator_inst = ir_implicit_cast(ira, uncasted_async_allocator_inst, inst_fn_type_id.async_allocator_type); |
| 13769 | 13470 | if (type_is_invalid(async_allocator_inst->value.type)) |
| 13770 | | return ira->codegen->builtin_types.entry_invalid; |
| 13471 | return ira->codegen->invalid_instruction; |
| 13771 | 13472 | } |
| 13772 | 13473 | |
| 13773 | 13474 | auto existing_entry = ira->codegen->generic_table.put_unique(generic_id, impl_fn); |
| ... | ... | @@ -13778,7 +13479,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13778 | 13479 | // finish instantiating the function |
| 13779 | 13480 | impl_fn->type_entry = get_fn_type(ira->codegen, &inst_fn_type_id); |
| 13780 | 13481 | if (type_is_invalid(impl_fn->type_entry)) |
| 13781 | | return ira->codegen->builtin_types.entry_invalid; |
| 13482 | return ira->codegen->invalid_instruction; |
| 13782 | 13483 | |
| 13783 | 13484 | impl_fn->ir_executable.source_node = call_instruction->base.source_node; |
| 13784 | 13485 | impl_fn->ir_executable.parent_exec = ira->new_irb.exec; |
| ... | ... | @@ -13797,21 +13498,22 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13797 | 13498 | |
| 13798 | 13499 | size_t impl_param_count = impl_fn->type_entry->data.fn.fn_type_id.param_count; |
| 13799 | 13500 | if (call_instruction->is_async) { |
| 13800 | | IrInstruction *result = ir_analyze_async_call(ira, call_instruction, impl_fn, impl_fn->type_entry, fn_ref, casted_args, impl_param_count, |
| 13801 | | async_allocator_inst); |
| 13802 | | ir_link_new_instruction(result, &call_instruction->base); |
| 13501 | IrInstruction *result = ir_analyze_async_call(ira, call_instruction, impl_fn, impl_fn->type_entry, |
| 13502 | fn_ref, casted_args, impl_param_count, async_allocator_inst); |
| 13803 | 13503 | ir_add_alloca(ira, result, result->value.type); |
| 13804 | | return ir_finish_anal(ira, result->value.type); |
| 13504 | return ir_finish_anal(ira, result); |
| 13805 | 13505 | } |
| 13806 | 13506 | |
| 13807 | 13507 | assert(async_allocator_inst == nullptr); |
| 13808 | | IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base, |
| 13508 | IrInstruction *new_call_instruction = ir_build_call(&ira->new_irb, |
| 13509 | call_instruction->base.scope, call_instruction->base.source_node, |
| 13809 | 13510 | impl_fn, nullptr, impl_param_count, casted_args, false, fn_inline, |
| 13810 | 13511 | call_instruction->is_async, nullptr, casted_new_stack); |
| 13512 | new_call_instruction->value.type = return_type; |
| 13811 | 13513 | |
| 13812 | 13514 | ir_add_alloca(ira, new_call_instruction, return_type); |
| 13813 | 13515 | |
| 13814 | | return ir_finish_anal(ira, return_type); |
| 13516 | return ir_finish_anal(ira, new_call_instruction); |
| 13815 | 13517 | } |
| 13816 | 13518 | |
| 13817 | 13519 | ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); |
| ... | ... | @@ -13829,7 +13531,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13829 | 13531 | |
| 13830 | 13532 | ZigType *param_type = fn_type_id->param_info[next_arg_index].type; |
| 13831 | 13533 | if (type_is_invalid(param_type)) |
| 13832 | | return ira->codegen->builtin_types.entry_invalid; |
| 13534 | return ira->codegen->invalid_instruction; |
| 13833 | 13535 | |
| 13834 | 13536 | IrInstruction *first_arg; |
| 13835 | 13537 | if (param_type->id == ZigTypeIdPointer && |
| ... | ... | @@ -13839,28 +13541,28 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13839 | 13541 | } else { |
| 13840 | 13542 | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr); |
| 13841 | 13543 | if (type_is_invalid(first_arg->value.type)) |
| 13842 | | return ira->codegen->builtin_types.entry_invalid; |
| 13544 | return ira->codegen->invalid_instruction; |
| 13843 | 13545 | } |
| 13844 | 13546 | |
| 13845 | 13547 | IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type); |
| 13846 | 13548 | if (type_is_invalid(casted_arg->value.type)) |
| 13847 | | return ira->codegen->builtin_types.entry_invalid; |
| 13549 | return ira->codegen->invalid_instruction; |
| 13848 | 13550 | |
| 13849 | 13551 | casted_args[next_arg_index] = casted_arg; |
| 13850 | 13552 | next_arg_index += 1; |
| 13851 | 13553 | } |
| 13852 | 13554 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 13853 | | IrInstruction *old_arg = call_instruction->args[call_i]->other; |
| 13555 | IrInstruction *old_arg = call_instruction->args[call_i]->child; |
| 13854 | 13556 | if (type_is_invalid(old_arg->value.type)) |
| 13855 | | return ira->codegen->builtin_types.entry_invalid; |
| 13557 | return ira->codegen->invalid_instruction; |
| 13856 | 13558 | IrInstruction *casted_arg; |
| 13857 | 13559 | if (next_arg_index < src_param_count) { |
| 13858 | 13560 | ZigType *param_type = fn_type_id->param_info[next_arg_index].type; |
| 13859 | 13561 | if (type_is_invalid(param_type)) |
| 13860 | | return ira->codegen->builtin_types.entry_invalid; |
| 13562 | return ira->codegen->invalid_instruction; |
| 13861 | 13563 | casted_arg = ir_implicit_cast(ira, old_arg, param_type); |
| 13862 | 13564 | if (type_is_invalid(casted_arg->value.type)) |
| 13863 | | return ira->codegen->builtin_types.entry_invalid; |
| 13565 | return ira->codegen->invalid_instruction; |
| 13864 | 13566 | } else { |
| 13865 | 13567 | casted_arg = old_arg; |
| 13866 | 13568 | } |
| ... | ... | @@ -13873,7 +13575,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13873 | 13575 | |
| 13874 | 13576 | ZigType *return_type = fn_type_id->return_type; |
| 13875 | 13577 | if (type_is_invalid(return_type)) |
| 13876 | | return ira->codegen->builtin_types.entry_invalid; |
| 13578 | return ira->codegen->invalid_instruction; |
| 13877 | 13579 | |
| 13878 | 13580 | if (call_instruction->is_async) { |
| 13879 | 13581 | IrInstruction *uncasted_async_allocator_inst; |
| ... | ... | @@ -13881,41 +13583,41 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13881 | 13583 | uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base, |
| 13882 | 13584 | ImplicitAllocatorIdLocalVar); |
| 13883 | 13585 | if (type_is_invalid(uncasted_async_allocator_inst->value.type)) |
| 13884 | | return ira->codegen->builtin_types.entry_invalid; |
| 13586 | return ira->codegen->invalid_instruction; |
| 13885 | 13587 | } else { |
| 13886 | | uncasted_async_allocator_inst = call_instruction->async_allocator->other; |
| 13588 | uncasted_async_allocator_inst = call_instruction->async_allocator->child; |
| 13887 | 13589 | if (type_is_invalid(uncasted_async_allocator_inst->value.type)) |
| 13888 | | return ira->codegen->builtin_types.entry_invalid; |
| 13590 | return ira->codegen->invalid_instruction; |
| 13889 | 13591 | |
| 13890 | 13592 | } |
| 13891 | 13593 | IrInstruction *async_allocator_inst = ir_implicit_cast(ira, uncasted_async_allocator_inst, fn_type_id->async_allocator_type); |
| 13892 | 13594 | if (type_is_invalid(async_allocator_inst->value.type)) |
| 13893 | | return ira->codegen->builtin_types.entry_invalid; |
| 13595 | return ira->codegen->invalid_instruction; |
| 13894 | 13596 | |
| 13895 | | IrInstruction *result = ir_analyze_async_call(ira, call_instruction, fn_entry, fn_type, fn_ref, casted_args, call_param_count, |
| 13896 | | async_allocator_inst); |
| 13897 | | ir_link_new_instruction(result, &call_instruction->base); |
| 13597 | IrInstruction *result = ir_analyze_async_call(ira, call_instruction, fn_entry, fn_type, fn_ref, |
| 13598 | casted_args, call_param_count, async_allocator_inst); |
| 13898 | 13599 | ir_add_alloca(ira, result, result->value.type); |
| 13899 | | return ir_finish_anal(ira, result->value.type); |
| 13600 | return ir_finish_anal(ira, result); |
| 13900 | 13601 | } |
| 13901 | 13602 | |
| 13902 | 13603 | if (fn_entry != nullptr && fn_entry->fn_inline == FnInlineAlways && fn_inline == FnInlineNever) { |
| 13903 | 13604 | ir_add_error(ira, &call_instruction->base, |
| 13904 | 13605 | buf_sprintf("no-inline call of inline function")); |
| 13905 | | return ira->codegen->builtin_types.entry_invalid; |
| 13606 | return ira->codegen->invalid_instruction; |
| 13906 | 13607 | } |
| 13907 | 13608 | |
| 13908 | | IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base, |
| 13609 | IrInstruction *new_call_instruction = ir_build_call(&ira->new_irb, |
| 13610 | call_instruction->base.scope, call_instruction->base.source_node, |
| 13909 | 13611 | fn_entry, fn_ref, call_param_count, casted_args, false, fn_inline, false, nullptr, casted_new_stack); |
| 13910 | | |
| 13612 | new_call_instruction->value.type = return_type; |
| 13911 | 13613 | ir_add_alloca(ira, new_call_instruction, return_type); |
| 13912 | | return ir_finish_anal(ira, return_type); |
| 13614 | return ir_finish_anal(ira, new_call_instruction); |
| 13913 | 13615 | } |
| 13914 | 13616 | |
| 13915 | | static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) { |
| 13916 | | IrInstruction *fn_ref = call_instruction->fn_ref->other; |
| 13617 | static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) { |
| 13618 | IrInstruction *fn_ref = call_instruction->fn_ref->child; |
| 13917 | 13619 | if (type_is_invalid(fn_ref->value.type)) |
| 13918 | | return ira->codegen->builtin_types.entry_invalid; |
| 13620 | return ira->codegen->invalid_instruction; |
| 13919 | 13621 | |
| 13920 | 13622 | bool is_comptime = call_instruction->is_comptime || |
| 13921 | 13623 | ir_should_inline(ira->new_irb.exec, call_instruction->base.scope); |
| ... | ... | @@ -13924,28 +13626,26 @@ static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *c |
| 13924 | 13626 | if (fn_ref->value.type->id == ZigTypeIdMetaType) { |
| 13925 | 13627 | ZigType *dest_type = ir_resolve_type(ira, fn_ref); |
| 13926 | 13628 | if (type_is_invalid(dest_type)) |
| 13927 | | return ira->codegen->builtin_types.entry_invalid; |
| 13629 | return ira->codegen->invalid_instruction; |
| 13928 | 13630 | |
| 13929 | 13631 | size_t actual_param_count = call_instruction->arg_count; |
| 13930 | 13632 | |
| 13931 | 13633 | if (actual_param_count != 1) { |
| 13932 | 13634 | ir_add_error_node(ira, call_instruction->base.source_node, |
| 13933 | 13635 | buf_sprintf("cast expression expects exactly one parameter")); |
| 13934 | | return ira->codegen->builtin_types.entry_invalid; |
| 13636 | return ira->codegen->invalid_instruction; |
| 13935 | 13637 | } |
| 13936 | 13638 | |
| 13937 | | IrInstruction *arg = call_instruction->args[0]->other; |
| 13639 | IrInstruction *arg = call_instruction->args[0]->child; |
| 13938 | 13640 | |
| 13939 | 13641 | IrInstruction *cast_instruction = ir_analyze_cast(ira, &call_instruction->base, dest_type, arg); |
| 13940 | 13642 | if (type_is_invalid(cast_instruction->value.type)) |
| 13941 | | return ira->codegen->builtin_types.entry_invalid; |
| 13942 | | |
| 13943 | | ir_link_new_instruction(cast_instruction, &call_instruction->base); |
| 13944 | | return ir_finish_anal(ira, cast_instruction->value.type); |
| 13643 | return ira->codegen->invalid_instruction; |
| 13644 | return ir_finish_anal(ira, cast_instruction); |
| 13945 | 13645 | } else if (fn_ref->value.type->id == ZigTypeIdFn) { |
| 13946 | 13646 | ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); |
| 13947 | 13647 | if (fn_table_entry == nullptr) |
| 13948 | | return ira->codegen->builtin_types.entry_invalid; |
| 13648 | return ira->codegen->invalid_instruction; |
| 13949 | 13649 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, |
| 13950 | 13650 | fn_ref, nullptr, is_comptime, call_instruction->fn_inline); |
| 13951 | 13651 | } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) { |
| ... | ... | @@ -13957,7 +13657,7 @@ static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *c |
| 13957 | 13657 | } else { |
| 13958 | 13658 | ir_add_error_node(ira, fn_ref->source_node, |
| 13959 | 13659 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name))); |
| 13960 | | return ira->codegen->builtin_types.entry_invalid; |
| 13660 | return ira->codegen->invalid_instruction; |
| 13961 | 13661 | } |
| 13962 | 13662 | } |
| 13963 | 13663 | |
| ... | ... | @@ -13967,7 +13667,7 @@ static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *c |
| 13967 | 13667 | } else { |
| 13968 | 13668 | ir_add_error_node(ira, fn_ref->source_node, |
| 13969 | 13669 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name))); |
| 13970 | | return ira->codegen->builtin_types.entry_invalid; |
| 13670 | return ira->codegen->invalid_instruction; |
| 13971 | 13671 | } |
| 13972 | 13672 | } |
| 13973 | 13673 | |
| ... | ... | @@ -14008,14 +13708,14 @@ static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node, |
| 14008 | 13708 | return ErrorNone; |
| 14009 | 13709 | } |
| 14010 | 13710 | |
| 14011 | | static ZigType *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { |
| 13711 | static IrInstruction *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { |
| 14012 | 13712 | Error err; |
| 14013 | | IrInstruction *value = un_op_instruction->value->other; |
| 13713 | IrInstruction *value = un_op_instruction->value->child; |
| 14014 | 13714 | ZigType *type_entry = ir_resolve_type(ira, value); |
| 14015 | 13715 | if (type_is_invalid(type_entry)) |
| 14016 | | return ira->codegen->builtin_types.entry_invalid; |
| 13716 | return ira->codegen->invalid_instruction; |
| 14017 | 13717 | if ((err = ensure_complete_type(ira->codegen, type_entry))) |
| 14018 | | return ira->codegen->builtin_types.entry_invalid; |
| 13718 | return ira->codegen->invalid_instruction; |
| 14019 | 13719 | |
| 14020 | 13720 | switch (type_entry->id) { |
| 14021 | 13721 | case ZigTypeIdInvalid: |
| ... | ... | @@ -14042,27 +13742,23 @@ static ZigType *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instru |
| 14042 | 13742 | case ZigTypeIdBoundFn: |
| 14043 | 13743 | case ZigTypeIdArgTuple: |
| 14044 | 13744 | case ZigTypeIdPromise: |
| 14045 | | { |
| 14046 | | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base); |
| 14047 | | out_val->data.x_type = get_optional_type(ira->codegen, type_entry); |
| 14048 | | return ira->codegen->builtin_types.entry_type; |
| 14049 | | } |
| 13745 | return ir_const_type(ira, &un_op_instruction->base, get_optional_type(ira->codegen, type_entry)); |
| 14050 | 13746 | case ZigTypeIdUnreachable: |
| 14051 | 13747 | case ZigTypeIdOpaque: |
| 14052 | 13748 | ir_add_error_node(ira, un_op_instruction->base.source_node, |
| 14053 | 13749 | buf_sprintf("type '%s' not optional", buf_ptr(&type_entry->name))); |
| 14054 | | return ira->codegen->builtin_types.entry_invalid; |
| 13750 | return ira->codegen->invalid_instruction; |
| 14055 | 13751 | } |
| 14056 | 13752 | zig_unreachable(); |
| 14057 | 13753 | } |
| 14058 | 13754 | |
| 14059 | | static ZigType *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { |
| 14060 | | IrInstruction *value = un_op_instruction->value->other; |
| 13755 | static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 13756 | IrInstruction *value = instruction->value->child; |
| 14061 | 13757 | ZigType *expr_type = value->value.type; |
| 14062 | 13758 | if (type_is_invalid(expr_type)) |
| 14063 | | return ira->codegen->builtin_types.entry_invalid; |
| 13759 | return ira->codegen->invalid_instruction; |
| 14064 | 13760 | |
| 14065 | | bool is_wrap_op = (un_op_instruction->op_id == IrUnOpNegationWrap); |
| 13761 | bool is_wrap_op = (instruction->op_id == IrUnOpNegationWrap); |
| 14066 | 13762 | |
| 14067 | 13763 | bool is_float = (expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat); |
| 14068 | 13764 | |
| ... | ... | @@ -14072,9 +13768,10 @@ static ZigType *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_ins |
| 14072 | 13768 | if (instr_is_comptime(value)) { |
| 14073 | 13769 | ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad); |
| 14074 | 13770 | if (!target_const_val) |
| 14075 | | return ira->codegen->builtin_types.entry_invalid; |
| 13771 | return ira->codegen->invalid_instruction; |
| 14076 | 13772 | |
| 14077 | | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base); |
| 13773 | IrInstruction *result = ir_const(ira, &instruction->base, expr_type); |
| 13774 | ConstExprValue *out_val = &result->value; |
| 14078 | 13775 | if (is_float) { |
| 14079 | 13776 | float_negate(out_val, target_const_val); |
| 14080 | 13777 | } else if (is_wrap_op) { |
| ... | ... | @@ -14084,92 +13781,96 @@ static ZigType *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_ins |
| 14084 | 13781 | bigint_negate(&out_val->data.x_bigint, &target_const_val->data.x_bigint); |
| 14085 | 13782 | } |
| 14086 | 13783 | if (is_wrap_op || is_float || expr_type->id == ZigTypeIdComptimeInt) { |
| 14087 | | return expr_type; |
| 13784 | return result; |
| 14088 | 13785 | } |
| 14089 | 13786 | |
| 14090 | 13787 | if (!bigint_fits_in_bits(&out_val->data.x_bigint, expr_type->data.integral.bit_count, true)) { |
| 14091 | | ir_add_error(ira, &un_op_instruction->base, buf_sprintf("negation caused overflow")); |
| 14092 | | return ira->codegen->builtin_types.entry_invalid; |
| 13788 | ir_add_error(ira, &instruction->base, buf_sprintf("negation caused overflow")); |
| 13789 | return ira->codegen->invalid_instruction; |
| 14093 | 13790 | } |
| 14094 | | return expr_type; |
| 13791 | return result; |
| 14095 | 13792 | } |
| 14096 | 13793 | |
| 14097 | | ir_build_un_op_from(&ira->new_irb, &un_op_instruction->base, un_op_instruction->op_id, value); |
| 14098 | | return expr_type; |
| 13794 | IrInstruction *result = ir_build_un_op(&ira->new_irb, |
| 13795 | instruction->base.scope, instruction->base.source_node, |
| 13796 | instruction->op_id, value); |
| 13797 | result->value.type = expr_type; |
| 13798 | return result; |
| 14099 | 13799 | } |
| 14100 | 13800 | |
| 14101 | 13801 | const char *fmt = is_wrap_op ? "invalid wrapping negation type: '%s'" : "invalid negation type: '%s'"; |
| 14102 | | ir_add_error(ira, &un_op_instruction->base, buf_sprintf(fmt, buf_ptr(&expr_type->name))); |
| 14103 | | return ira->codegen->builtin_types.entry_invalid; |
| 13802 | ir_add_error(ira, &instruction->base, buf_sprintf(fmt, buf_ptr(&expr_type->name))); |
| 13803 | return ira->codegen->invalid_instruction; |
| 14104 | 13804 | } |
| 14105 | 13805 | |
| 14106 | | static ZigType *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 14107 | | IrInstruction *value = instruction->value->other; |
| 13806 | static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 13807 | IrInstruction *value = instruction->value->child; |
| 14108 | 13808 | ZigType *expr_type = value->value.type; |
| 14109 | 13809 | if (type_is_invalid(expr_type)) |
| 14110 | | return ira->codegen->builtin_types.entry_invalid; |
| 13810 | return ira->codegen->invalid_instruction; |
| 14111 | 13811 | |
| 14112 | 13812 | if (expr_type->id == ZigTypeIdInt) { |
| 14113 | 13813 | if (instr_is_comptime(value)) { |
| 14114 | 13814 | ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad); |
| 14115 | 13815 | if (target_const_val == nullptr) |
| 14116 | | return ira->codegen->builtin_types.entry_invalid; |
| 13816 | return ira->codegen->invalid_instruction; |
| 14117 | 13817 | |
| 14118 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 14119 | | bigint_not(&out_val->data.x_bigint, &target_const_val->data.x_bigint, |
| 13818 | IrInstruction *result = ir_const(ira, &instruction->base, expr_type); |
| 13819 | bigint_not(&result->value.data.x_bigint, &target_const_val->data.x_bigint, |
| 14120 | 13820 | expr_type->data.integral.bit_count, expr_type->data.integral.is_signed); |
| 14121 | | return expr_type; |
| 13821 | return result; |
| 14122 | 13822 | } |
| 14123 | 13823 | |
| 14124 | | ir_build_un_op_from(&ira->new_irb, &instruction->base, IrUnOpBinNot, value); |
| 14125 | | return expr_type; |
| 13824 | IrInstruction *result = ir_build_un_op(&ira->new_irb, instruction->base.scope, |
| 13825 | instruction->base.source_node, IrUnOpBinNot, value); |
| 13826 | result->value.type = expr_type; |
| 13827 | return result; |
| 14126 | 13828 | } |
| 14127 | 13829 | |
| 14128 | 13830 | ir_add_error(ira, &instruction->base, |
| 14129 | 13831 | buf_sprintf("unable to perform binary not operation on type '%s'", buf_ptr(&expr_type->name))); |
| 14130 | | return ira->codegen->builtin_types.entry_invalid; |
| 13832 | return ira->codegen->invalid_instruction; |
| 14131 | 13833 | } |
| 14132 | 13834 | |
| 14133 | | static ZigType *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { |
| 14134 | | IrUnOp op_id = un_op_instruction->op_id; |
| 13835 | static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 13836 | IrUnOp op_id = instruction->op_id; |
| 14135 | 13837 | switch (op_id) { |
| 14136 | 13838 | case IrUnOpInvalid: |
| 14137 | 13839 | zig_unreachable(); |
| 14138 | 13840 | case IrUnOpBinNot: |
| 14139 | | return ir_analyze_bin_not(ira, un_op_instruction); |
| 13841 | return ir_analyze_bin_not(ira, instruction); |
| 14140 | 13842 | case IrUnOpNegation: |
| 14141 | 13843 | case IrUnOpNegationWrap: |
| 14142 | | return ir_analyze_negation(ira, un_op_instruction); |
| 13844 | return ir_analyze_negation(ira, instruction); |
| 14143 | 13845 | case IrUnOpDereference: { |
| 14144 | | IrInstruction *ptr = un_op_instruction->value->other; |
| 13846 | IrInstruction *ptr = instruction->value->child; |
| 14145 | 13847 | if (type_is_invalid(ptr->value.type)) |
| 14146 | | return ira->codegen->builtin_types.entry_invalid; |
| 13848 | return ira->codegen->invalid_instruction; |
| 14147 | 13849 | ZigType *ptr_type = ptr->value.type; |
| 14148 | 13850 | if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) { |
| 14149 | | ir_add_error_node(ira, un_op_instruction->base.source_node, |
| 13851 | ir_add_error_node(ira, instruction->base.source_node, |
| 14150 | 13852 | buf_sprintf("index syntax required for unknown-length pointer type '%s'", |
| 14151 | 13853 | buf_ptr(&ptr_type->name))); |
| 14152 | | return ira->codegen->builtin_types.entry_invalid; |
| 13854 | return ira->codegen->invalid_instruction; |
| 14153 | 13855 | } |
| 14154 | 13856 | // this dereference is always an rvalue because in the IR gen we identify lvalue and emit |
| 14155 | 13857 | // one of the ptr instructions |
| 14156 | | IrInstruction *result = ir_get_deref(ira, &un_op_instruction->base, ptr); |
| 13858 | IrInstruction *result = ir_get_deref(ira, &instruction->base, ptr); |
| 14157 | 13859 | if (result == ira->codegen->invalid_instruction) |
| 14158 | | return ira->codegen->builtin_types.entry_invalid; |
| 14159 | | ir_link_new_instruction(result, &un_op_instruction->base); |
| 14160 | | return result->value.type; |
| 13860 | return ira->codegen->invalid_instruction; |
| 13861 | return result; |
| 14161 | 13862 | } |
| 14162 | 13863 | case IrUnOpOptional: |
| 14163 | | return ir_analyze_maybe(ira, un_op_instruction); |
| 13864 | return ir_analyze_maybe(ira, instruction); |
| 14164 | 13865 | } |
| 14165 | 13866 | zig_unreachable(); |
| 14166 | 13867 | } |
| 14167 | 13868 | |
| 14168 | | static ZigType *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) { |
| 13869 | static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) { |
| 14169 | 13870 | IrBasicBlock *old_dest_block = br_instruction->dest_block; |
| 14170 | 13871 | |
| 14171 | 13872 | bool is_comptime; |
| 14172 | | if (!ir_resolve_comptime(ira, br_instruction->is_comptime->other, &is_comptime)) |
| 13873 | if (!ir_resolve_comptime(ira, br_instruction->is_comptime->child, &is_comptime)) |
| 14173 | 13874 | return ir_unreach_error(ira); |
| 14174 | 13875 | |
| 14175 | 13876 | if (is_comptime || old_dest_block->ref_count == 1) |
| ... | ... | @@ -14179,17 +13880,19 @@ static ZigType *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_in |
| 14179 | 13880 | if (new_bb == nullptr) |
| 14180 | 13881 | return ir_unreach_error(ira); |
| 14181 | 13882 | |
| 14182 | | ir_build_br_from(&ira->new_irb, &br_instruction->base, new_bb); |
| 14183 | | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 13883 | IrInstruction *result = ir_build_br(&ira->new_irb, |
| 13884 | br_instruction->base.scope, br_instruction->base.source_node, new_bb, nullptr); |
| 13885 | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 13886 | return ir_finish_anal(ira, result); |
| 14184 | 13887 | } |
| 14185 | 13888 | |
| 14186 | | static ZigType *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) { |
| 14187 | | IrInstruction *condition = cond_br_instruction->condition->other; |
| 13889 | static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) { |
| 13890 | IrInstruction *condition = cond_br_instruction->condition->child; |
| 14188 | 13891 | if (type_is_invalid(condition->value.type)) |
| 14189 | 13892 | return ir_unreach_error(ira); |
| 14190 | 13893 | |
| 14191 | 13894 | bool is_comptime; |
| 14192 | | if (!ir_resolve_comptime(ira, cond_br_instruction->is_comptime->other, &is_comptime)) |
| 13895 | if (!ir_resolve_comptime(ira, cond_br_instruction->is_comptime->child, &is_comptime)) |
| 14193 | 13896 | return ir_unreach_error(ira); |
| 14194 | 13897 | |
| 14195 | 13898 | if (is_comptime || instr_is_comptime(condition)) { |
| ... | ... | @@ -14207,8 +13910,10 @@ static ZigType *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCond |
| 14207 | 13910 | if (new_dest_block == nullptr) |
| 14208 | 13911 | return ir_unreach_error(ira); |
| 14209 | 13912 | |
| 14210 | | ir_build_br_from(&ira->new_irb, &cond_br_instruction->base, new_dest_block); |
| 14211 | | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 13913 | IrInstruction *result = ir_build_br(&ira->new_irb, |
| 13914 | cond_br_instruction->base.scope, cond_br_instruction->base.source_node, new_dest_block, nullptr); |
| 13915 | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 13916 | return ir_finish_anal(ira, result); |
| 14212 | 13917 | } |
| 14213 | 13918 | |
| 14214 | 13919 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| ... | ... | @@ -14225,36 +13930,41 @@ static ZigType *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCond |
| 14225 | 13930 | if (new_else_block == nullptr) |
| 14226 | 13931 | return ir_unreach_error(ira); |
| 14227 | 13932 | |
| 14228 | | ir_build_cond_br_from(&ira->new_irb, &cond_br_instruction->base, |
| 13933 | IrInstruction *result = ir_build_cond_br(&ira->new_irb, |
| 13934 | cond_br_instruction->base.scope, cond_br_instruction->base.source_node, |
| 14229 | 13935 | casted_condition, new_then_block, new_else_block, nullptr); |
| 14230 | | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 13936 | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 13937 | return ir_finish_anal(ira, result); |
| 14231 | 13938 | } |
| 14232 | 13939 | |
| 14233 | | static ZigType *ir_analyze_instruction_unreachable(IrAnalyze *ira, |
| 13940 | static IrInstruction *ir_analyze_instruction_unreachable(IrAnalyze *ira, |
| 14234 | 13941 | IrInstructionUnreachable *unreachable_instruction) |
| 14235 | 13942 | { |
| 14236 | | ir_build_unreachable_from(&ira->new_irb, &unreachable_instruction->base); |
| 14237 | | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 13943 | IrInstruction *result = ir_build_unreachable(&ira->new_irb, |
| 13944 | unreachable_instruction->base.scope, unreachable_instruction->base.source_node); |
| 13945 | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 13946 | return ir_finish_anal(ira, result); |
| 14238 | 13947 | } |
| 14239 | 13948 | |
| 14240 | | static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) { |
| 13949 | static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) { |
| 14241 | 13950 | if (ira->const_predecessor_bb) { |
| 14242 | 13951 | for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) { |
| 14243 | 13952 | IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i]; |
| 14244 | 13953 | if (predecessor != ira->const_predecessor_bb) |
| 14245 | 13954 | continue; |
| 14246 | | IrInstruction *value = phi_instruction->incoming_values[i]->other; |
| 13955 | IrInstruction *value = phi_instruction->incoming_values[i]->child; |
| 14247 | 13956 | assert(value->value.type); |
| 14248 | 13957 | if (type_is_invalid(value->value.type)) |
| 14249 | | return ira->codegen->builtin_types.entry_invalid; |
| 13958 | return ira->codegen->invalid_instruction; |
| 14250 | 13959 | |
| 14251 | 13960 | if (value->value.special != ConstValSpecialRuntime) { |
| 14252 | | ConstExprValue *out_val = ir_build_const_from(ira, &phi_instruction->base); |
| 14253 | | *out_val = value->value; |
| 13961 | IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr); |
| 13962 | // TODO use copy_const_val? |
| 13963 | result->value = value->value; |
| 13964 | return result; |
| 14254 | 13965 | } else { |
| 14255 | | phi_instruction->base.other = value; |
| 13966 | return value; |
| 14256 | 13967 | } |
| 14257 | | return value->value.type; |
| 14258 | 13968 | } |
| 14259 | 13969 | zig_unreachable(); |
| 14260 | 13970 | } |
| ... | ... | @@ -14270,12 +13980,12 @@ static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi |
| 14270 | 13980 | |
| 14271 | 13981 | IrInstruction *old_value = phi_instruction->incoming_values[i]; |
| 14272 | 13982 | assert(old_value); |
| 14273 | | IrInstruction *new_value = old_value->other; |
| 13983 | IrInstruction *new_value = old_value->child; |
| 14274 | 13984 | if (!new_value || new_value->value.type->id == ZigTypeIdUnreachable || predecessor->other == nullptr) |
| 14275 | 13985 | continue; |
| 14276 | 13986 | |
| 14277 | 13987 | if (type_is_invalid(new_value->value.type)) |
| 14278 | | return ira->codegen->builtin_types.entry_invalid; |
| 13988 | return ira->codegen->invalid_instruction; |
| 14279 | 13989 | |
| 14280 | 13990 | |
| 14281 | 13991 | assert(predecessor->other); |
| ... | ... | @@ -14284,20 +13994,20 @@ static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi |
| 14284 | 13994 | } |
| 14285 | 13995 | |
| 14286 | 13996 | if (new_incoming_blocks.length == 0) { |
| 14287 | | ir_build_unreachable_from(&ira->new_irb, &phi_instruction->base); |
| 14288 | | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 13997 | IrInstruction *result = ir_build_unreachable(&ira->new_irb, |
| 13998 | phi_instruction->base.scope, phi_instruction->base.source_node); |
| 13999 | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 14000 | return ir_finish_anal(ira, result); |
| 14289 | 14001 | } |
| 14290 | 14002 | |
| 14291 | 14003 | if (new_incoming_blocks.length == 1) { |
| 14292 | | IrInstruction *first_value = new_incoming_values.at(0); |
| 14293 | | phi_instruction->base.other = first_value; |
| 14294 | | return first_value->value.type; |
| 14004 | return new_incoming_values.at(0); |
| 14295 | 14005 | } |
| 14296 | 14006 | |
| 14297 | 14007 | ZigType *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr, |
| 14298 | 14008 | new_incoming_values.items, new_incoming_values.length); |
| 14299 | 14009 | if (type_is_invalid(resolved_type)) |
| 14300 | | return resolved_type; |
| 14010 | return ira->codegen->invalid_instruction; |
| 14301 | 14011 | |
| 14302 | 14012 | if (resolved_type->id == ZigTypeIdComptimeFloat || |
| 14303 | 14013 | resolved_type->id == ZigTypeIdComptimeInt || |
| ... | ... | @@ -14306,7 +14016,7 @@ static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi |
| 14306 | 14016 | { |
| 14307 | 14017 | ir_add_error_node(ira, phi_instruction->base.source_node, |
| 14308 | 14018 | buf_sprintf("unable to infer expression type")); |
| 14309 | | return ira->codegen->builtin_types.entry_invalid; |
| 14019 | return ira->codegen->invalid_instruction; |
| 14310 | 14020 | } |
| 14311 | 14021 | |
| 14312 | 14022 | bool all_stack_ptrs = (resolved_type->id == ZigTypeIdPointer); |
| ... | ... | @@ -14322,7 +14032,7 @@ static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi |
| 14322 | 14032 | ir_set_cursor_at_end(&ira->new_irb, predecessor); |
| 14323 | 14033 | IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type); |
| 14324 | 14034 | if (casted_value == ira->codegen->invalid_instruction) { |
| 14325 | | return ira->codegen->builtin_types.entry_invalid; |
| 14035 | return ira->codegen->invalid_instruction; |
| 14326 | 14036 | } |
| 14327 | 14037 | new_incoming_values.items[i] = casted_value; |
| 14328 | 14038 | predecessor->instruction_list.append(branch_instruction); |
| ... | ... | @@ -14335,24 +14045,20 @@ static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi |
| 14335 | 14045 | } |
| 14336 | 14046 | ir_set_cursor_at_end(&ira->new_irb, cur_bb); |
| 14337 | 14047 | |
| 14338 | | IrInstruction *result = ir_build_phi_from(&ira->new_irb, &phi_instruction->base, new_incoming_blocks.length, |
| 14339 | | new_incoming_blocks.items, new_incoming_values.items); |
| 14048 | IrInstruction *result = ir_build_phi(&ira->new_irb, |
| 14049 | phi_instruction->base.scope, phi_instruction->base.source_node, |
| 14050 | new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items); |
| 14051 | result->value.type = resolved_type; |
| 14340 | 14052 | |
| 14341 | 14053 | if (all_stack_ptrs) { |
| 14342 | 14054 | assert(result->value.special == ConstValSpecialRuntime); |
| 14343 | 14055 | result->value.data.rh_ptr = RuntimeHintPtrStack; |
| 14344 | 14056 | } |
| 14345 | 14057 | |
| 14346 | | return resolved_type; |
| 14347 | | } |
| 14348 | | |
| 14349 | | static ZigType *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var) { |
| 14350 | | IrInstruction *result = ir_get_var_ptr(ira, instruction, var); |
| 14351 | | ir_link_new_instruction(result, instruction); |
| 14352 | | return result->value.type; |
| 14058 | return result; |
| 14353 | 14059 | } |
| 14354 | 14060 | |
| 14355 | | static ZigType *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *instruction) { |
| 14061 | static IrInstruction *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *instruction) { |
| 14356 | 14062 | ZigVar *var = instruction->var; |
| 14357 | 14063 | IrInstruction *result = ir_get_var_ptr(ira, &instruction->base, var); |
| 14358 | 14064 | if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) { |
| ... | ... | @@ -14362,10 +14068,9 @@ static ZigType *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarP |
| 14362 | 14068 | buf_sprintf("crossed function definition here")); |
| 14363 | 14069 | add_error_note(ira->codegen, msg, var->decl_node, |
| 14364 | 14070 | buf_sprintf("declared here")); |
| 14365 | | return ira->codegen->builtin_types.entry_invalid; |
| 14071 | return ira->codegen->invalid_instruction; |
| 14366 | 14072 | } |
| 14367 | | ir_link_new_instruction(result, &instruction->base); |
| 14368 | | return result->value.type; |
| 14073 | return result; |
| 14369 | 14074 | } |
| 14370 | 14075 | |
| 14371 | 14076 | static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align) { |
| ... | ... | @@ -14395,17 +14100,17 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { |
| 14395 | 14100 | ptr_type->data.pointer.bit_offset_in_host, ptr_type->data.pointer.host_int_bytes); |
| 14396 | 14101 | } |
| 14397 | 14102 | |
| 14398 | | static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { |
| 14103 | static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { |
| 14399 | 14104 | Error err; |
| 14400 | | IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other; |
| 14105 | IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->child; |
| 14401 | 14106 | if (type_is_invalid(array_ptr->value.type)) |
| 14402 | | return ira->codegen->builtin_types.entry_invalid; |
| 14107 | return ira->codegen->invalid_instruction; |
| 14403 | 14108 | |
| 14404 | 14109 | ConstExprValue *orig_array_ptr_val = &array_ptr->value; |
| 14405 | 14110 | |
| 14406 | | IrInstruction *elem_index = elem_ptr_instruction->elem_index->other; |
| 14111 | IrInstruction *elem_index = elem_ptr_instruction->elem_index->child; |
| 14407 | 14112 | if (type_is_invalid(elem_index->value.type)) |
| 14408 | | return ira->codegen->builtin_types.entry_invalid; |
| 14113 | return ira->codegen->invalid_instruction; |
| 14409 | 14114 | |
| 14410 | 14115 | ZigType *ptr_type = orig_array_ptr_val->type; |
| 14411 | 14116 | assert(ptr_type->id == ZigTypeIdPointer); |
| ... | ... | @@ -14417,7 +14122,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14417 | 14122 | ZigType *return_type; |
| 14418 | 14123 | |
| 14419 | 14124 | if (type_is_invalid(array_type)) { |
| 14420 | | return array_type; |
| 14125 | return ira->codegen->invalid_instruction; |
| 14421 | 14126 | } else if (array_type->id == ZigTypeIdArray || |
| 14422 | 14127 | (array_type->id == ZigTypeIdPointer && |
| 14423 | 14128 | array_type->data.pointer.ptr_len == PtrLenSingle && |
| ... | ... | @@ -14430,13 +14135,13 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14430 | 14135 | orig_array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val, |
| 14431 | 14136 | elem_ptr_instruction->base.source_node); |
| 14432 | 14137 | if (orig_array_ptr_val == nullptr) |
| 14433 | | return ira->codegen->builtin_types.entry_invalid; |
| 14138 | return ira->codegen->invalid_instruction; |
| 14434 | 14139 | } |
| 14435 | 14140 | } |
| 14436 | 14141 | if (array_type->data.array.len == 0) { |
| 14437 | 14142 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14438 | 14143 | buf_sprintf("index 0 outside array of size 0")); |
| 14439 | | return ira->codegen->builtin_types.entry_invalid; |
| 14144 | return ira->codegen->invalid_instruction; |
| 14440 | 14145 | } |
| 14441 | 14146 | ZigType *child_type = array_type->data.array.child_type; |
| 14442 | 14147 | if (ptr_type->data.pointer.host_int_bytes == 0) { |
| ... | ... | @@ -14447,7 +14152,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14447 | 14152 | } else { |
| 14448 | 14153 | uint64_t elem_val_scalar; |
| 14449 | 14154 | if (!ir_resolve_usize(ira, elem_index, &elem_val_scalar)) |
| 14450 | | return ira->codegen->builtin_types.entry_invalid; |
| 14155 | return ira->codegen->invalid_instruction; |
| 14451 | 14156 | |
| 14452 | 14157 | size_t bit_width = type_size_bits(ira->codegen, child_type); |
| 14453 | 14158 | size_t bit_offset = bit_width * elem_val_scalar; |
| ... | ... | @@ -14461,7 +14166,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14461 | 14166 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { |
| 14462 | 14167 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14463 | 14168 | buf_sprintf("index of single-item pointer")); |
| 14464 | | return ira->codegen->builtin_types.entry_invalid; |
| 14169 | return ira->codegen->invalid_instruction; |
| 14465 | 14170 | } |
| 14466 | 14171 | return_type = adjust_ptr_len(ira->codegen, array_type, elem_ptr_instruction->ptr_len); |
| 14467 | 14172 | } else if (is_slice(array_type)) { |
| ... | ... | @@ -14470,21 +14175,21 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14470 | 14175 | } else if (array_type->id == ZigTypeIdArgTuple) { |
| 14471 | 14176 | ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); |
| 14472 | 14177 | if (!ptr_val) |
| 14473 | | return ira->codegen->builtin_types.entry_invalid; |
| 14178 | return ira->codegen->invalid_instruction; |
| 14474 | 14179 | ConstExprValue *args_val = ir_const_ptr_pointee(ira, ptr_val, elem_ptr_instruction->base.source_node); |
| 14475 | 14180 | if (args_val == nullptr) |
| 14476 | | return ira->codegen->builtin_types.entry_invalid; |
| 14181 | return ira->codegen->invalid_instruction; |
| 14477 | 14182 | size_t start = args_val->data.x_arg_tuple.start_index; |
| 14478 | 14183 | size_t end = args_val->data.x_arg_tuple.end_index; |
| 14479 | 14184 | uint64_t elem_index_val; |
| 14480 | 14185 | if (!ir_resolve_usize(ira, elem_index, &elem_index_val)) |
| 14481 | | return ira->codegen->builtin_types.entry_invalid; |
| 14186 | return ira->codegen->invalid_instruction; |
| 14482 | 14187 | size_t index = elem_index_val; |
| 14483 | 14188 | size_t len = end - start; |
| 14484 | 14189 | if (index >= len) { |
| 14485 | 14190 | ir_add_error(ira, &elem_ptr_instruction->base, |
| 14486 | 14191 | buf_sprintf("index %" ZIG_PRI_usize " outside argument list of size %" ZIG_PRI_usize "", index, len)); |
| 14487 | | return ira->codegen->builtin_types.entry_invalid; |
| 14192 | return ira->codegen->invalid_instruction; |
| 14488 | 14193 | } |
| 14489 | 14194 | size_t abs_index = start + index; |
| 14490 | 14195 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| ... | ... | @@ -14493,25 +14198,25 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14493 | 14198 | bool is_const = true; |
| 14494 | 14199 | bool is_volatile = false; |
| 14495 | 14200 | if (var) { |
| 14496 | | return ir_analyze_var_ptr(ira, &elem_ptr_instruction->base, var); |
| 14201 | return ir_get_var_ptr(ira, &elem_ptr_instruction->base, var); |
| 14497 | 14202 | } else { |
| 14498 | | return ir_analyze_const_ptr(ira, &elem_ptr_instruction->base, &ira->codegen->const_void_val, |
| 14499 | | ira->codegen->builtin_types.entry_void, ConstPtrMutComptimeConst, is_const, is_volatile); |
| 14203 | return ir_get_const_ptr(ira, &elem_ptr_instruction->base, &ira->codegen->const_void_val, |
| 14204 | ira->codegen->builtin_types.entry_void, ConstPtrMutComptimeConst, is_const, is_volatile, 0); |
| 14500 | 14205 | } |
| 14501 | 14206 | } else { |
| 14502 | 14207 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14503 | 14208 | buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name))); |
| 14504 | | return ira->codegen->builtin_types.entry_invalid; |
| 14209 | return ira->codegen->invalid_instruction; |
| 14505 | 14210 | } |
| 14506 | 14211 | |
| 14507 | 14212 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 14508 | 14213 | IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize); |
| 14509 | 14214 | if (casted_elem_index == ira->codegen->invalid_instruction) |
| 14510 | | return ira->codegen->builtin_types.entry_invalid; |
| 14215 | return ira->codegen->invalid_instruction; |
| 14511 | 14216 | |
| 14512 | 14217 | bool safety_check_on = elem_ptr_instruction->safety_check_on; |
| 14513 | 14218 | if ((err = ensure_complete_type(ira->codegen, return_type->data.pointer.child_type))) |
| 14514 | | return ira->codegen->builtin_types.entry_invalid; |
| 14219 | return ira->codegen->invalid_instruction; |
| 14515 | 14220 | |
| 14516 | 14221 | uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type); |
| 14517 | 14222 | uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type); |
| ... | ... | @@ -14524,7 +14229,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14524 | 14229 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14525 | 14230 | buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64, |
| 14526 | 14231 | index, array_len)); |
| 14527 | | return ira->codegen->builtin_types.entry_invalid; |
| 14232 | return ira->codegen->invalid_instruction; |
| 14528 | 14233 | } |
| 14529 | 14234 | safety_check_on = false; |
| 14530 | 14235 | } |
| ... | ... | @@ -14556,14 +14261,15 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14556 | 14261 | ConstExprValue *array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val, |
| 14557 | 14262 | elem_ptr_instruction->base.source_node); |
| 14558 | 14263 | if (array_ptr_val == nullptr) |
| 14559 | | return ira->codegen->builtin_types.entry_invalid; |
| 14264 | return ira->codegen->invalid_instruction; |
| 14560 | 14265 | |
| 14561 | 14266 | if (array_ptr_val->special != ConstValSpecialRuntime && |
| 14562 | 14267 | (array_type->id != ZigTypeIdPointer || |
| 14563 | 14268 | array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)) |
| 14564 | 14269 | { |
| 14565 | 14270 | if (array_type->id == ZigTypeIdPointer) { |
| 14566 | | ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base); |
| 14271 | IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 14272 | ConstExprValue *out_val = &result->value; |
| 14567 | 14273 | out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; |
| 14568 | 14274 | size_t new_index; |
| 14569 | 14275 | size_t mem_size; |
| ... | ... | @@ -14608,26 +14314,26 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14608 | 14314 | if (new_index >= mem_size) { |
| 14609 | 14315 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14610 | 14316 | buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size)); |
| 14611 | | return ira->codegen->builtin_types.entry_invalid; |
| 14317 | return ira->codegen->invalid_instruction; |
| 14612 | 14318 | } |
| 14613 | | return return_type; |
| 14319 | return result; |
| 14614 | 14320 | } else if (is_slice(array_type)) { |
| 14615 | 14321 | ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index]; |
| 14616 | 14322 | if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 14617 | 14323 | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, |
| 14618 | 14324 | array_ptr, casted_elem_index, false, elem_ptr_instruction->ptr_len); |
| 14619 | 14325 | result->value.type = return_type; |
| 14620 | | ir_link_new_instruction(result, &elem_ptr_instruction->base); |
| 14621 | | return return_type; |
| 14326 | return result; |
| 14622 | 14327 | } |
| 14623 | 14328 | ConstExprValue *len_field = &array_ptr_val->data.x_struct.fields[slice_len_index]; |
| 14624 | | ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base); |
| 14329 | IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 14330 | ConstExprValue *out_val = &result->value; |
| 14625 | 14331 | uint64_t slice_len = bigint_as_unsigned(&len_field->data.x_bigint); |
| 14626 | 14332 | if (index >= slice_len) { |
| 14627 | 14333 | ir_add_error_node(ira, elem_ptr_instruction->base.source_node, |
| 14628 | 14334 | buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64, |
| 14629 | 14335 | index, slice_len)); |
| 14630 | | return ira->codegen->builtin_types.entry_invalid; |
| 14336 | return ira->codegen->invalid_instruction; |
| 14631 | 14337 | } |
| 14632 | 14338 | out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut; |
| 14633 | 14339 | switch (ptr_field->data.x_ptr.special) { |
| ... | ... | @@ -14658,14 +14364,15 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14658 | 14364 | case ConstPtrSpecialFunction: |
| 14659 | 14365 | zig_panic("TODO elem ptr on a slice that was ptrcast from a function"); |
| 14660 | 14366 | } |
| 14661 | | return return_type; |
| 14367 | return result; |
| 14662 | 14368 | } else if (array_type->id == ZigTypeIdArray) { |
| 14663 | | ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base); |
| 14369 | IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 14370 | ConstExprValue *out_val = &result->value; |
| 14664 | 14371 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 14665 | 14372 | out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut; |
| 14666 | 14373 | out_val->data.x_ptr.data.base_array.array_val = array_ptr_val; |
| 14667 | 14374 | out_val->data.x_ptr.data.base_array.elem_index = index; |
| 14668 | | return return_type; |
| 14375 | return result; |
| 14669 | 14376 | } else { |
| 14670 | 14377 | zig_unreachable(); |
| 14671 | 14378 | } |
| ... | ... | @@ -14678,7 +14385,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14678 | 14385 | ir_add_error(ira, elem_index, |
| 14679 | 14386 | buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known", |
| 14680 | 14387 | buf_ptr(&return_type->data.pointer.child_type->name))); |
| 14681 | | return ira->codegen->builtin_types.entry_invalid; |
| 14388 | return ira->codegen->invalid_instruction; |
| 14682 | 14389 | } |
| 14683 | 14390 | if (ptr_align < abi_align) { |
| 14684 | 14391 | if (elem_size >= ptr_align && elem_size % ptr_align == 0) { |
| ... | ... | @@ -14695,8 +14402,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14695 | 14402 | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, elem_ptr_instruction->base.source_node, |
| 14696 | 14403 | array_ptr, casted_elem_index, safety_check_on, elem_ptr_instruction->ptr_len); |
| 14697 | 14404 | result->value.type = return_type; |
| 14698 | | ir_link_new_instruction(result, &elem_ptr_instruction->base); |
| 14699 | | return return_type; |
| 14405 | return result; |
| 14700 | 14406 | } |
| 14701 | 14407 | |
| 14702 | 14408 | static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, |
| ... | ... | @@ -14776,13 +14482,12 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 14776 | 14482 | is_const, is_volatile, PtrLenSingle, align_bytes, |
| 14777 | 14483 | (uint32_t)(ptr_bit_offset + field->bit_offset_in_host), |
| 14778 | 14484 | (uint32_t)host_int_bytes_for_result_type); |
| 14779 | | IrInstruction *result = ir_get_const(ira, source_instr); |
| 14485 | IrInstruction *result = ir_const(ira, source_instr, ptr_type); |
| 14780 | 14486 | ConstExprValue *const_val = &result->value; |
| 14781 | 14487 | const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct; |
| 14782 | 14488 | const_val->data.x_ptr.mut = container_ptr->value.data.x_ptr.mut; |
| 14783 | 14489 | const_val->data.x_ptr.data.base_struct.struct_val = struct_val; |
| 14784 | 14490 | const_val->data.x_ptr.data.base_struct.field_index = field->src_index; |
| 14785 | | const_val->type = ptr_type; |
| 14786 | 14491 | return result; |
| 14787 | 14492 | } |
| 14788 | 14493 | } |
| ... | ... | @@ -14840,12 +14545,11 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 14840 | 14545 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, |
| 14841 | 14546 | is_const, is_volatile, PtrLenSingle, 0, 0, 0); |
| 14842 | 14547 | |
| 14843 | | IrInstruction *result = ir_get_const(ira, source_instr); |
| 14548 | IrInstruction *result = ir_const(ira, source_instr, ptr_type); |
| 14844 | 14549 | ConstExprValue *const_val = &result->value; |
| 14845 | 14550 | const_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 14846 | 14551 | const_val->data.x_ptr.mut = container_ptr->value.data.x_ptr.mut; |
| 14847 | 14552 | const_val->data.x_ptr.data.ref.pointee = payload_val; |
| 14848 | | const_val->type = ptr_type; |
| 14849 | 14553 | return result; |
| 14850 | 14554 | } |
| 14851 | 14555 | } |
| ... | ... | @@ -14882,11 +14586,11 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, |
| 14882 | 14586 | } |
| 14883 | 14587 | |
| 14884 | 14588 | |
| 14885 | | static ZigType *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) { |
| 14589 | static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) { |
| 14886 | 14590 | bool pointer_only = false; |
| 14887 | 14591 | resolve_top_level_decl(ira->codegen, tld, pointer_only, source_instruction->source_node); |
| 14888 | 14592 | if (tld->resolution == TldResolutionInvalid) |
| 14889 | | return ira->codegen->builtin_types.entry_invalid; |
| 14593 | return ira->codegen->invalid_instruction; |
| 14890 | 14594 | |
| 14891 | 14595 | switch (tld->id) { |
| 14892 | 14596 | case TldIdContainer: |
| ... | ... | @@ -14900,7 +14604,7 @@ static ZigType *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instru |
| 14900 | 14604 | add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node); |
| 14901 | 14605 | } |
| 14902 | 14606 | |
| 14903 | | return ir_analyze_var_ptr(ira, source_instruction, var); |
| 14607 | return ir_get_var_ptr(ira, source_instruction, var); |
| 14904 | 14608 | } |
| 14905 | 14609 | case TldIdFn: |
| 14906 | 14610 | { |
| ... | ... | @@ -14909,7 +14613,7 @@ static ZigType *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instru |
| 14909 | 14613 | assert(fn_entry->type_entry); |
| 14910 | 14614 | |
| 14911 | 14615 | if (type_is_invalid(fn_entry->type_entry)) |
| 14912 | | return ira->codegen->builtin_types.entry_invalid; |
| 14616 | return ira->codegen->invalid_instruction; |
| 14913 | 14617 | |
| 14914 | 14618 | // TODO instead of allocating this every time, put it in the tld value and we can reference |
| 14915 | 14619 | // the same one every time |
| ... | ... | @@ -14926,8 +14630,8 @@ static ZigType *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instru |
| 14926 | 14630 | |
| 14927 | 14631 | bool ptr_is_const = true; |
| 14928 | 14632 | bool ptr_is_volatile = false; |
| 14929 | | return ir_analyze_const_ptr(ira, source_instruction, const_val, fn_entry->type_entry, |
| 14930 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14633 | return ir_get_const_ptr(ira, source_instruction, const_val, fn_entry->type_entry, |
| 14634 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 14931 | 14635 | } |
| 14932 | 14636 | } |
| 14933 | 14637 | zig_unreachable(); |
| ... | ... | @@ -14944,45 +14648,43 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n |
| 14944 | 14648 | return nullptr; |
| 14945 | 14649 | } |
| 14946 | 14650 | |
| 14947 | | static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) { |
| 14651 | static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) { |
| 14948 | 14652 | Error err; |
| 14949 | | IrInstruction *container_ptr = field_ptr_instruction->container_ptr->other; |
| 14653 | IrInstruction *container_ptr = field_ptr_instruction->container_ptr->child; |
| 14950 | 14654 | if (type_is_invalid(container_ptr->value.type)) |
| 14951 | | return ira->codegen->builtin_types.entry_invalid; |
| 14655 | return ira->codegen->invalid_instruction; |
| 14952 | 14656 | |
| 14953 | 14657 | if (container_ptr->value.type->id != ZigTypeIdPointer) { |
| 14954 | 14658 | ir_add_error_node(ira, field_ptr_instruction->base.source_node, |
| 14955 | 14659 | buf_sprintf("attempt to dereference non-pointer type '%s'", |
| 14956 | 14660 | buf_ptr(&container_ptr->value.type->name))); |
| 14957 | | return ira->codegen->builtin_types.entry_invalid; |
| 14661 | return ira->codegen->invalid_instruction; |
| 14958 | 14662 | } |
| 14959 | 14663 | ZigType *container_type = container_ptr->value.type->data.pointer.child_type; |
| 14960 | 14664 | |
| 14961 | 14665 | Buf *field_name = field_ptr_instruction->field_name_buffer; |
| 14962 | 14666 | if (!field_name) { |
| 14963 | | IrInstruction *field_name_expr = field_ptr_instruction->field_name_expr->other; |
| 14667 | IrInstruction *field_name_expr = field_ptr_instruction->field_name_expr->child; |
| 14964 | 14668 | field_name = ir_resolve_str(ira, field_name_expr); |
| 14965 | 14669 | if (!field_name) |
| 14966 | | return ira->codegen->builtin_types.entry_invalid; |
| 14670 | return ira->codegen->invalid_instruction; |
| 14967 | 14671 | } |
| 14968 | 14672 | |
| 14969 | 14673 | |
| 14970 | 14674 | AstNode *source_node = field_ptr_instruction->base.source_node; |
| 14971 | 14675 | |
| 14972 | 14676 | if (type_is_invalid(container_type)) { |
| 14973 | | return container_type; |
| 14677 | return ira->codegen->invalid_instruction; |
| 14974 | 14678 | } else if (is_container_ref(container_type)) { |
| 14975 | 14679 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 14976 | 14680 | if (container_type->id == ZigTypeIdPointer) { |
| 14977 | 14681 | ZigType *bare_type = container_ref_type(container_type); |
| 14978 | 14682 | IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr); |
| 14979 | 14683 | IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type); |
| 14980 | | ir_link_new_instruction(result, &field_ptr_instruction->base); |
| 14981 | | return result->value.type; |
| 14684 | return result; |
| 14982 | 14685 | } else { |
| 14983 | 14686 | IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_ptr, container_type); |
| 14984 | | ir_link_new_instruction(result, &field_ptr_instruction->base); |
| 14985 | | return result->value.type; |
| 14687 | return result; |
| 14986 | 14688 | } |
| 14987 | 14689 | } else if (is_array_ref(container_type)) { |
| 14988 | 14690 | if (buf_eql_str(field_name, "len")) { |
| ... | ... | @@ -14996,23 +14698,23 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi |
| 14996 | 14698 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 14997 | 14699 | bool ptr_is_const = true; |
| 14998 | 14700 | bool ptr_is_volatile = false; |
| 14999 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val, |
| 15000 | | usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14701 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, len_val, |
| 14702 | usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15001 | 14703 | } else { |
| 15002 | 14704 | ir_add_error_node(ira, source_node, |
| 15003 | 14705 | buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), |
| 15004 | 14706 | buf_ptr(&container_type->name))); |
| 15005 | | return ira->codegen->builtin_types.entry_invalid; |
| 14707 | return ira->codegen->invalid_instruction; |
| 15006 | 14708 | } |
| 15007 | 14709 | } else if (container_type->id == ZigTypeIdArgTuple) { |
| 15008 | 14710 | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 15009 | 14711 | if (!container_ptr_val) |
| 15010 | | return ira->codegen->builtin_types.entry_invalid; |
| 14712 | return ira->codegen->invalid_instruction; |
| 15011 | 14713 | |
| 15012 | 14714 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 15013 | 14715 | ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node); |
| 15014 | 14716 | if (child_val == nullptr) |
| 15015 | | return ira->codegen->builtin_types.entry_invalid; |
| 14717 | return ira->codegen->invalid_instruction; |
| 15016 | 14718 | |
| 15017 | 14719 | if (buf_eql_str(field_name, "len")) { |
| 15018 | 14720 | ConstExprValue *len_val = create_const_vals(1); |
| ... | ... | @@ -15022,27 +14724,27 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi |
| 15022 | 14724 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 15023 | 14725 | bool ptr_is_const = true; |
| 15024 | 14726 | bool ptr_is_volatile = false; |
| 15025 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val, |
| 15026 | | usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14727 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, len_val, |
| 14728 | usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15027 | 14729 | } else { |
| 15028 | 14730 | ir_add_error_node(ira, source_node, |
| 15029 | 14731 | buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), |
| 15030 | 14732 | buf_ptr(&container_type->name))); |
| 15031 | | return ira->codegen->builtin_types.entry_invalid; |
| 14733 | return ira->codegen->invalid_instruction; |
| 15032 | 14734 | } |
| 15033 | 14735 | } else if (container_type->id == ZigTypeIdMetaType) { |
| 15034 | 14736 | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 15035 | 14737 | if (!container_ptr_val) |
| 15036 | | return ira->codegen->builtin_types.entry_invalid; |
| 14738 | return ira->codegen->invalid_instruction; |
| 15037 | 14739 | |
| 15038 | 14740 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 15039 | 14741 | ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node); |
| 15040 | 14742 | if (child_val == nullptr) |
| 15041 | | return ira->codegen->builtin_types.entry_invalid; |
| 14743 | return ira->codegen->invalid_instruction; |
| 15042 | 14744 | ZigType *child_type = child_val->data.x_type; |
| 15043 | 14745 | |
| 15044 | 14746 | if (type_is_invalid(child_type)) { |
| 15045 | | return ira->codegen->builtin_types.entry_invalid; |
| 14747 | return ira->codegen->invalid_instruction; |
| 15046 | 14748 | } else if (is_container(child_type)) { |
| 15047 | 14749 | if (is_slice(child_type) && buf_eql_str(field_name, "Child")) { |
| 15048 | 14750 | bool ptr_is_const = true; |
| ... | ... | @@ -15050,22 +14752,22 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi |
| 15050 | 14752 | TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index]; |
| 15051 | 14753 | assert(ptr_field->type_entry->id == ZigTypeIdPointer); |
| 15052 | 14754 | ZigType *child_type = ptr_field->type_entry->data.pointer.child_type; |
| 15053 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14755 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15054 | 14756 | create_const_type(ira->codegen, child_type), |
| 15055 | 14757 | ira->codegen->builtin_types.entry_type, |
| 15056 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14758 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15057 | 14759 | } |
| 15058 | 14760 | if (child_type->id == ZigTypeIdEnum) { |
| 15059 | 14761 | if ((err = ensure_complete_type(ira->codegen, child_type))) |
| 15060 | | return ira->codegen->builtin_types.entry_invalid; |
| 14762 | return ira->codegen->invalid_instruction; |
| 15061 | 14763 | |
| 15062 | 14764 | TypeEnumField *field = find_enum_type_field(child_type, field_name); |
| 15063 | 14765 | if (field) { |
| 15064 | 14766 | bool ptr_is_const = true; |
| 15065 | 14767 | bool ptr_is_volatile = false; |
| 15066 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14768 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15067 | 14769 | create_const_enum(child_type, &field->value), child_type, |
| 15068 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14770 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15069 | 14771 | } |
| 15070 | 14772 | } |
| 15071 | 14773 | ScopeDecls *container_scope = get_container_scope(child_type); |
| ... | ... | @@ -15081,21 +14783,21 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi |
| 15081 | 14783 | child_type->data.unionation.decl_node->data.container_decl.auto_enum)) |
| 15082 | 14784 | { |
| 15083 | 14785 | if ((err = ensure_complete_type(ira->codegen, child_type))) |
| 15084 | | return ira->codegen->builtin_types.entry_invalid; |
| 14786 | return ira->codegen->invalid_instruction; |
| 15085 | 14787 | TypeUnionField *field = find_union_type_field(child_type, field_name); |
| 15086 | 14788 | if (field) { |
| 15087 | 14789 | ZigType *enum_type = child_type->data.unionation.tag_type; |
| 15088 | 14790 | bool ptr_is_const = true; |
| 15089 | 14791 | bool ptr_is_volatile = false; |
| 15090 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14792 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15091 | 14793 | create_const_enum(enum_type, &field->enum_field->value), enum_type, |
| 15092 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14794 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15093 | 14795 | } |
| 15094 | 14796 | } |
| 15095 | 14797 | ir_add_error(ira, &field_ptr_instruction->base, |
| 15096 | 14798 | buf_sprintf("container '%s' has no member called '%s'", |
| 15097 | 14799 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 15098 | | return ira->codegen->builtin_types.entry_invalid; |
| 14800 | return ira->codegen->invalid_instruction; |
| 15099 | 14801 | } else if (child_type->id == ZigTypeIdErrorSet) { |
| 15100 | 14802 | ErrorTableEntry *err_entry; |
| 15101 | 14803 | ZigType *err_set_type; |
| ... | ... | @@ -15123,13 +14825,13 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi |
| 15123 | 14825 | err_set_type = err_entry->set_with_only_this_in_it; |
| 15124 | 14826 | } else { |
| 15125 | 14827 | if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.source_node)) { |
| 15126 | | return ira->codegen->builtin_types.entry_invalid; |
| 14828 | return ira->codegen->invalid_instruction; |
| 15127 | 14829 | } |
| 15128 | 14830 | err_entry = find_err_table_entry(child_type, field_name); |
| 15129 | 14831 | if (err_entry == nullptr) { |
| 15130 | 14832 | ir_add_error(ira, &field_ptr_instruction->base, |
| 15131 | 14833 | buf_sprintf("no error named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&child_type->name))); |
| 15132 | | return ira->codegen->builtin_types.entry_invalid; |
| 14834 | return ira->codegen->invalid_instruction; |
| 15133 | 14835 | } |
| 15134 | 14836 | err_set_type = child_type; |
| 15135 | 14837 | } |
| ... | ... | @@ -15140,128 +14842,128 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi |
| 15140 | 14842 | |
| 15141 | 14843 | bool ptr_is_const = true; |
| 15142 | 14844 | bool ptr_is_volatile = false; |
| 15143 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, const_val, |
| 15144 | | err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14845 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, const_val, |
| 14846 | err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15145 | 14847 | } else if (child_type->id == ZigTypeIdInt) { |
| 15146 | 14848 | if (buf_eql_str(field_name, "bit_count")) { |
| 15147 | 14849 | bool ptr_is_const = true; |
| 15148 | 14850 | bool ptr_is_volatile = false; |
| 15149 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14851 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15150 | 14852 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, |
| 15151 | 14853 | child_type->data.integral.bit_count, false), |
| 15152 | 14854 | ira->codegen->builtin_types.entry_num_lit_int, |
| 15153 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14855 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15154 | 14856 | } else if (buf_eql_str(field_name, "is_signed")) { |
| 15155 | 14857 | bool ptr_is_const = true; |
| 15156 | 14858 | bool ptr_is_volatile = false; |
| 15157 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14859 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15158 | 14860 | create_const_bool(ira->codegen, child_type->data.integral.is_signed), |
| 15159 | 14861 | ira->codegen->builtin_types.entry_bool, |
| 15160 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14862 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15161 | 14863 | } else { |
| 15162 | 14864 | ir_add_error(ira, &field_ptr_instruction->base, |
| 15163 | 14865 | buf_sprintf("type '%s' has no member called '%s'", |
| 15164 | 14866 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 15165 | | return ira->codegen->builtin_types.entry_invalid; |
| 14867 | return ira->codegen->invalid_instruction; |
| 15166 | 14868 | } |
| 15167 | 14869 | } else if (child_type->id == ZigTypeIdFloat) { |
| 15168 | 14870 | if (buf_eql_str(field_name, "bit_count")) { |
| 15169 | 14871 | bool ptr_is_const = true; |
| 15170 | 14872 | bool ptr_is_volatile = false; |
| 15171 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14873 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15172 | 14874 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, |
| 15173 | 14875 | child_type->data.floating.bit_count, false), |
| 15174 | 14876 | ira->codegen->builtin_types.entry_num_lit_int, |
| 15175 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14877 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15176 | 14878 | } else { |
| 15177 | 14879 | ir_add_error(ira, &field_ptr_instruction->base, |
| 15178 | 14880 | buf_sprintf("type '%s' has no member called '%s'", |
| 15179 | 14881 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 15180 | | return ira->codegen->builtin_types.entry_invalid; |
| 14882 | return ira->codegen->invalid_instruction; |
| 15181 | 14883 | } |
| 15182 | 14884 | } else if (child_type->id == ZigTypeIdPointer) { |
| 15183 | 14885 | if (buf_eql_str(field_name, "Child")) { |
| 15184 | 14886 | bool ptr_is_const = true; |
| 15185 | 14887 | bool ptr_is_volatile = false; |
| 15186 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14888 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15187 | 14889 | create_const_type(ira->codegen, child_type->data.pointer.child_type), |
| 15188 | 14890 | ira->codegen->builtin_types.entry_type, |
| 15189 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14891 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15190 | 14892 | } else if (buf_eql_str(field_name, "alignment")) { |
| 15191 | 14893 | bool ptr_is_const = true; |
| 15192 | 14894 | bool ptr_is_volatile = false; |
| 15193 | 14895 | if ((err = type_resolve(ira->codegen, child_type->data.pointer.child_type, |
| 15194 | 14896 | ResolveStatusAlignmentKnown))) |
| 15195 | 14897 | { |
| 15196 | | return ira->codegen->builtin_types.entry_invalid; |
| 14898 | return ira->codegen->invalid_instruction; |
| 15197 | 14899 | } |
| 15198 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14900 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15199 | 14901 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, |
| 15200 | 14902 | get_ptr_align(ira->codegen, child_type), false), |
| 15201 | 14903 | ira->codegen->builtin_types.entry_num_lit_int, |
| 15202 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14904 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15203 | 14905 | } else { |
| 15204 | 14906 | ir_add_error(ira, &field_ptr_instruction->base, |
| 15205 | 14907 | buf_sprintf("type '%s' has no member called '%s'", |
| 15206 | 14908 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 15207 | | return ira->codegen->builtin_types.entry_invalid; |
| 14909 | return ira->codegen->invalid_instruction; |
| 15208 | 14910 | } |
| 15209 | 14911 | } else if (child_type->id == ZigTypeIdArray) { |
| 15210 | 14912 | if (buf_eql_str(field_name, "Child")) { |
| 15211 | 14913 | bool ptr_is_const = true; |
| 15212 | 14914 | bool ptr_is_volatile = false; |
| 15213 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14915 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15214 | 14916 | create_const_type(ira->codegen, child_type->data.array.child_type), |
| 15215 | 14917 | ira->codegen->builtin_types.entry_type, |
| 15216 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14918 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15217 | 14919 | } else if (buf_eql_str(field_name, "len")) { |
| 15218 | 14920 | bool ptr_is_const = true; |
| 15219 | 14921 | bool ptr_is_volatile = false; |
| 15220 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14922 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15221 | 14923 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, |
| 15222 | 14924 | child_type->data.array.len, false), |
| 15223 | 14925 | ira->codegen->builtin_types.entry_num_lit_int, |
| 15224 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14926 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15225 | 14927 | } else { |
| 15226 | 14928 | ir_add_error(ira, &field_ptr_instruction->base, |
| 15227 | 14929 | buf_sprintf("type '%s' has no member called '%s'", |
| 15228 | 14930 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 15229 | | return ira->codegen->builtin_types.entry_invalid; |
| 14931 | return ira->codegen->invalid_instruction; |
| 15230 | 14932 | } |
| 15231 | 14933 | } else if (child_type->id == ZigTypeIdErrorUnion) { |
| 15232 | 14934 | if (buf_eql_str(field_name, "Payload")) { |
| 15233 | 14935 | bool ptr_is_const = true; |
| 15234 | 14936 | bool ptr_is_volatile = false; |
| 15235 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14937 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15236 | 14938 | create_const_type(ira->codegen, child_type->data.error_union.payload_type), |
| 15237 | 14939 | ira->codegen->builtin_types.entry_type, |
| 15238 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14940 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15239 | 14941 | } else if (buf_eql_str(field_name, "ErrorSet")) { |
| 15240 | 14942 | bool ptr_is_const = true; |
| 15241 | 14943 | bool ptr_is_volatile = false; |
| 15242 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14944 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15243 | 14945 | create_const_type(ira->codegen, child_type->data.error_union.err_set_type), |
| 15244 | 14946 | ira->codegen->builtin_types.entry_type, |
| 15245 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14947 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15246 | 14948 | } else { |
| 15247 | 14949 | ir_add_error(ira, &field_ptr_instruction->base, |
| 15248 | 14950 | buf_sprintf("type '%s' has no member called '%s'", |
| 15249 | 14951 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 15250 | | return ira->codegen->builtin_types.entry_invalid; |
| 14952 | return ira->codegen->invalid_instruction; |
| 15251 | 14953 | } |
| 15252 | 14954 | } else if (child_type->id == ZigTypeIdOptional) { |
| 15253 | 14955 | if (buf_eql_str(field_name, "Child")) { |
| 15254 | 14956 | bool ptr_is_const = true; |
| 15255 | 14957 | bool ptr_is_volatile = false; |
| 15256 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14958 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15257 | 14959 | create_const_type(ira->codegen, child_type->data.maybe.child_type), |
| 15258 | 14960 | ira->codegen->builtin_types.entry_type, |
| 15259 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14961 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15260 | 14962 | } else { |
| 15261 | 14963 | ir_add_error(ira, &field_ptr_instruction->base, |
| 15262 | 14964 | buf_sprintf("type '%s' has no member called '%s'", |
| 15263 | 14965 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 15264 | | return ira->codegen->builtin_types.entry_invalid; |
| 14966 | return ira->codegen->invalid_instruction; |
| 15265 | 14967 | } |
| 15266 | 14968 | } else if (child_type->id == ZigTypeIdFn) { |
| 15267 | 14969 | if (buf_eql_str(field_name, "ReturnType")) { |
| ... | ... | @@ -15271,50 +14973,50 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi |
| 15271 | 14973 | |
| 15272 | 14974 | ir_add_error(ira, &field_ptr_instruction->base, |
| 15273 | 14975 | buf_sprintf("ReturnType has not been resolved because '%s' is generic", buf_ptr(&child_type->name))); |
| 15274 | | return ira->codegen->builtin_types.entry_invalid; |
| 14976 | return ira->codegen->invalid_instruction; |
| 15275 | 14977 | } |
| 15276 | 14978 | |
| 15277 | 14979 | bool ptr_is_const = true; |
| 15278 | 14980 | bool ptr_is_volatile = false; |
| 15279 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14981 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15280 | 14982 | create_const_type(ira->codegen, child_type->data.fn.fn_type_id.return_type), |
| 15281 | 14983 | ira->codegen->builtin_types.entry_type, |
| 15282 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14984 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15283 | 14985 | } else if (buf_eql_str(field_name, "is_var_args")) { |
| 15284 | 14986 | bool ptr_is_const = true; |
| 15285 | 14987 | bool ptr_is_volatile = false; |
| 15286 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14988 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15287 | 14989 | create_const_bool(ira->codegen, child_type->data.fn.fn_type_id.is_var_args), |
| 15288 | 14990 | ira->codegen->builtin_types.entry_bool, |
| 15289 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14991 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15290 | 14992 | } else if (buf_eql_str(field_name, "arg_count")) { |
| 15291 | 14993 | bool ptr_is_const = true; |
| 15292 | 14994 | bool ptr_is_volatile = false; |
| 15293 | | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 14995 | return ir_get_const_ptr(ira, &field_ptr_instruction->base, |
| 15294 | 14996 | create_const_usize(ira->codegen, child_type->data.fn.fn_type_id.param_count), |
| 15295 | 14997 | ira->codegen->builtin_types.entry_usize, |
| 15296 | | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 14998 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); |
| 15297 | 14999 | } else { |
| 15298 | 15000 | ir_add_error(ira, &field_ptr_instruction->base, |
| 15299 | 15001 | buf_sprintf("type '%s' has no member called '%s'", |
| 15300 | 15002 | buf_ptr(&child_type->name), buf_ptr(field_name))); |
| 15301 | | return ira->codegen->builtin_types.entry_invalid; |
| 15003 | return ira->codegen->invalid_instruction; |
| 15302 | 15004 | } |
| 15303 | 15005 | } else { |
| 15304 | 15006 | ir_add_error(ira, &field_ptr_instruction->base, |
| 15305 | 15007 | buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name))); |
| 15306 | | return ira->codegen->builtin_types.entry_invalid; |
| 15008 | return ira->codegen->invalid_instruction; |
| 15307 | 15009 | } |
| 15308 | 15010 | } else if (container_type->id == ZigTypeIdNamespace) { |
| 15309 | 15011 | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 15310 | 15012 | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 15311 | 15013 | if (!container_ptr_val) |
| 15312 | | return ira->codegen->builtin_types.entry_invalid; |
| 15014 | return ira->codegen->invalid_instruction; |
| 15313 | 15015 | |
| 15314 | 15016 | ConstExprValue *namespace_val = ir_const_ptr_pointee(ira, container_ptr_val, |
| 15315 | 15017 | field_ptr_instruction->base.source_node); |
| 15316 | 15018 | if (namespace_val == nullptr) |
| 15317 | | return ira->codegen->builtin_types.entry_invalid; |
| 15019 | return ira->codegen->invalid_instruction; |
| 15318 | 15020 | assert(namespace_val->special == ConstValSpecialStatic); |
| 15319 | 15021 | |
| 15320 | 15022 | ImportTableEntry *namespace_import = namespace_val->data.x_import; |
| ... | ... | @@ -15327,78 +15029,74 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi |
| 15327 | 15029 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 15328 | 15030 | buf_sprintf("'%s' is private", buf_ptr(field_name))); |
| 15329 | 15031 | add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here")); |
| 15330 | | return ira->codegen->builtin_types.entry_invalid; |
| 15032 | return ira->codegen->invalid_instruction; |
| 15331 | 15033 | } |
| 15332 | 15034 | return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld); |
| 15333 | 15035 | } else { |
| 15334 | 15036 | const char *import_name = namespace_import->path ? buf_ptr(namespace_import->path) : "(C import)"; |
| 15335 | 15037 | ir_add_error_node(ira, source_node, |
| 15336 | 15038 | buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), import_name)); |
| 15337 | | return ira->codegen->builtin_types.entry_invalid; |
| 15039 | return ira->codegen->invalid_instruction; |
| 15338 | 15040 | } |
| 15339 | 15041 | } else { |
| 15340 | 15042 | ir_add_error_node(ira, field_ptr_instruction->base.source_node, |
| 15341 | 15043 | buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name))); |
| 15342 | | return ira->codegen->builtin_types.entry_invalid; |
| 15044 | return ira->codegen->invalid_instruction; |
| 15343 | 15045 | } |
| 15344 | 15046 | } |
| 15345 | 15047 | |
| 15346 | | static ZigType *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *load_ptr_instruction) { |
| 15347 | | IrInstruction *ptr = load_ptr_instruction->ptr->other; |
| 15048 | static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *load_ptr_instruction) { |
| 15049 | IrInstruction *ptr = load_ptr_instruction->ptr->child; |
| 15348 | 15050 | if (type_is_invalid(ptr->value.type)) |
| 15349 | | return ira->codegen->builtin_types.entry_invalid; |
| 15350 | | |
| 15351 | | IrInstruction *result = ir_get_deref(ira, &load_ptr_instruction->base, ptr); |
| 15352 | | ir_link_new_instruction(result, &load_ptr_instruction->base); |
| 15353 | | assert(result->value.type); |
| 15354 | | return result->value.type; |
| 15051 | return ira->codegen->invalid_instruction; |
| 15052 | return ir_get_deref(ira, &load_ptr_instruction->base, ptr); |
| 15355 | 15053 | } |
| 15356 | 15054 | |
| 15357 | | static ZigType *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) { |
| 15358 | | IrInstruction *ptr = store_ptr_instruction->ptr->other; |
| 15055 | static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) { |
| 15056 | IrInstruction *ptr = store_ptr_instruction->ptr->child; |
| 15359 | 15057 | if (type_is_invalid(ptr->value.type)) |
| 15360 | | return ptr->value.type; |
| 15058 | return ira->codegen->invalid_instruction; |
| 15361 | 15059 | |
| 15362 | | IrInstruction *value = store_ptr_instruction->value->other; |
| 15060 | IrInstruction *value = store_ptr_instruction->value->child; |
| 15363 | 15061 | if (type_is_invalid(value->value.type)) |
| 15364 | | return value->value.type; |
| 15062 | return ira->codegen->invalid_instruction; |
| 15365 | 15063 | |
| 15366 | 15064 | if (ptr->value.type->id != ZigTypeIdPointer) { |
| 15367 | 15065 | ir_add_error(ira, ptr, |
| 15368 | 15066 | buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name))); |
| 15369 | | return ira->codegen->builtin_types.entry_invalid; |
| 15067 | return ira->codegen->invalid_instruction; |
| 15370 | 15068 | } |
| 15371 | 15069 | |
| 15372 | 15070 | if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) { |
| 15373 | | return ir_analyze_void(ira, &store_ptr_instruction->base); |
| 15071 | return ir_const_void(ira, &store_ptr_instruction->base); |
| 15374 | 15072 | } |
| 15375 | 15073 | |
| 15376 | 15074 | if (ptr->value.type->data.pointer.is_const && !store_ptr_instruction->base.is_gen) { |
| 15377 | 15075 | ir_add_error(ira, &store_ptr_instruction->base, buf_sprintf("cannot assign to constant")); |
| 15378 | | return ira->codegen->builtin_types.entry_invalid; |
| 15076 | return ira->codegen->invalid_instruction; |
| 15379 | 15077 | } |
| 15380 | 15078 | |
| 15381 | 15079 | ZigType *child_type = ptr->value.type->data.pointer.child_type; |
| 15382 | 15080 | IrInstruction *casted_value = ir_implicit_cast(ira, value, child_type); |
| 15383 | 15081 | if (casted_value == ira->codegen->invalid_instruction) |
| 15384 | | return ira->codegen->builtin_types.entry_invalid; |
| 15082 | return ira->codegen->invalid_instruction; |
| 15385 | 15083 | |
| 15386 | 15084 | if (instr_is_comptime(ptr) && ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 15387 | 15085 | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst) { |
| 15388 | 15086 | ir_add_error(ira, &store_ptr_instruction->base, buf_sprintf("cannot assign to constant")); |
| 15389 | | return ira->codegen->builtin_types.entry_invalid; |
| 15087 | return ira->codegen->invalid_instruction; |
| 15390 | 15088 | } |
| 15391 | 15089 | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) { |
| 15392 | 15090 | if (instr_is_comptime(casted_value)) { |
| 15393 | 15091 | ConstExprValue *dest_val = ir_const_ptr_pointee(ira, &ptr->value, store_ptr_instruction->base.source_node); |
| 15394 | 15092 | if (dest_val == nullptr) |
| 15395 | | return ira->codegen->builtin_types.entry_invalid; |
| 15093 | return ira->codegen->invalid_instruction; |
| 15396 | 15094 | if (dest_val->special != ConstValSpecialRuntime) { |
| 15397 | 15095 | *dest_val = casted_value->value; |
| 15398 | 15096 | if (!ira->new_irb.current_basic_block->must_be_comptime_source_instr) { |
| 15399 | 15097 | ira->new_irb.current_basic_block->must_be_comptime_source_instr = &store_ptr_instruction->base; |
| 15400 | 15098 | } |
| 15401 | | return ir_analyze_void(ira, &store_ptr_instruction->base); |
| 15099 | return ir_const_void(ira, &store_ptr_instruction->base); |
| 15402 | 15100 | } |
| 15403 | 15101 | } |
| 15404 | 15102 | ir_add_error(ira, &store_ptr_instruction->base, |
| ... | ... | @@ -15406,19 +15104,22 @@ static ZigType *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionSt |
| 15406 | 15104 | ConstExprValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, &ptr->value); |
| 15407 | 15105 | dest_val->type = ira->codegen->builtin_types.entry_invalid; |
| 15408 | 15106 | |
| 15409 | | return ira->codegen->builtin_types.entry_invalid; |
| 15107 | return ira->codegen->invalid_instruction; |
| 15410 | 15108 | } |
| 15411 | 15109 | } |
| 15412 | 15110 | |
| 15413 | | ir_build_store_ptr_from(&ira->new_irb, &store_ptr_instruction->base, ptr, casted_value); |
| 15414 | | return ira->codegen->builtin_types.entry_void; |
| 15111 | IrInstruction *result = ir_build_store_ptr(&ira->new_irb, |
| 15112 | store_ptr_instruction->base.scope, store_ptr_instruction->base.source_node, |
| 15113 | ptr, casted_value); |
| 15114 | result->value.type = ira->codegen->builtin_types.entry_void; |
| 15115 | return result; |
| 15415 | 15116 | } |
| 15416 | 15117 | |
| 15417 | | static ZigType *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) { |
| 15418 | | IrInstruction *expr_value = typeof_instruction->value->other; |
| 15118 | static IrInstruction *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) { |
| 15119 | IrInstruction *expr_value = typeof_instruction->value->child; |
| 15419 | 15120 | ZigType *type_entry = expr_value->value.type; |
| 15420 | 15121 | if (type_is_invalid(type_entry)) |
| 15421 | | return ira->codegen->builtin_types.entry_invalid; |
| 15122 | return ira->codegen->invalid_instruction; |
| 15422 | 15123 | switch (type_entry->id) { |
| 15423 | 15124 | case ZigTypeIdInvalid: |
| 15424 | 15125 | zig_unreachable(); // handled above |
| ... | ... | @@ -15446,24 +15147,19 @@ static ZigType *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeO |
| 15446 | 15147 | case ZigTypeIdArgTuple: |
| 15447 | 15148 | case ZigTypeIdOpaque: |
| 15448 | 15149 | case ZigTypeIdPromise: |
| 15449 | | { |
| 15450 | | ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base); |
| 15451 | | out_val->data.x_type = type_entry; |
| 15452 | | |
| 15453 | | return ira->codegen->builtin_types.entry_type; |
| 15454 | | } |
| 15150 | return ir_const_type(ira, &typeof_instruction->base, type_entry); |
| 15455 | 15151 | } |
| 15456 | 15152 | |
| 15457 | 15153 | zig_unreachable(); |
| 15458 | 15154 | } |
| 15459 | 15155 | |
| 15460 | | static ZigType *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, |
| 15156 | static IrInstruction *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, |
| 15461 | 15157 | IrInstructionToPtrType *to_ptr_type_instruction) |
| 15462 | 15158 | { |
| 15463 | | IrInstruction *value = to_ptr_type_instruction->value->other; |
| 15159 | IrInstruction *value = to_ptr_type_instruction->value->child; |
| 15464 | 15160 | ZigType *type_entry = value->value.type; |
| 15465 | 15161 | if (type_is_invalid(type_entry)) |
| 15466 | | return type_entry; |
| 15162 | return ira->codegen->invalid_instruction; |
| 15467 | 15163 | |
| 15468 | 15164 | ZigType *ptr_type; |
| 15469 | 15165 | if (type_entry->id == ZigTypeIdArray) { |
| ... | ... | @@ -15473,76 +15169,69 @@ static ZigType *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, |
| 15473 | 15169 | } else if (type_entry->id == ZigTypeIdArgTuple) { |
| 15474 | 15170 | ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad); |
| 15475 | 15171 | if (!arg_tuple_val) |
| 15476 | | return ira->codegen->builtin_types.entry_invalid; |
| 15172 | return ira->codegen->invalid_instruction; |
| 15477 | 15173 | zig_panic("TODO for loop on var args"); |
| 15478 | 15174 | } else { |
| 15479 | 15175 | ir_add_error_node(ira, to_ptr_type_instruction->base.source_node, |
| 15480 | 15176 | buf_sprintf("expected array type, found '%s'", buf_ptr(&type_entry->name))); |
| 15481 | | return ira->codegen->builtin_types.entry_invalid; |
| 15177 | return ira->codegen->invalid_instruction; |
| 15482 | 15178 | } |
| 15483 | 15179 | |
| 15484 | | ConstExprValue *out_val = ir_build_const_from(ira, &to_ptr_type_instruction->base); |
| 15485 | | out_val->data.x_type = ptr_type; |
| 15486 | | return ira->codegen->builtin_types.entry_type; |
| 15180 | return ir_const_type(ira, &to_ptr_type_instruction->base, ptr_type); |
| 15487 | 15181 | } |
| 15488 | 15182 | |
| 15489 | | static ZigType *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira, |
| 15183 | static IrInstruction *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira, |
| 15490 | 15184 | IrInstructionPtrTypeChild *ptr_type_child_instruction) |
| 15491 | 15185 | { |
| 15492 | | IrInstruction *type_value = ptr_type_child_instruction->value->other; |
| 15186 | IrInstruction *type_value = ptr_type_child_instruction->value->child; |
| 15493 | 15187 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 15494 | 15188 | if (type_is_invalid(type_entry)) |
| 15495 | | return type_entry; |
| 15189 | return ira->codegen->invalid_instruction; |
| 15496 | 15190 | |
| 15497 | 15191 | if (type_entry->id != ZigTypeIdPointer) { |
| 15498 | 15192 | ir_add_error_node(ira, ptr_type_child_instruction->base.source_node, |
| 15499 | 15193 | buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name))); |
| 15500 | | return ira->codegen->builtin_types.entry_invalid; |
| 15194 | return ira->codegen->invalid_instruction; |
| 15501 | 15195 | } |
| 15502 | 15196 | |
| 15503 | | ConstExprValue *out_val = ir_build_const_from(ira, &ptr_type_child_instruction->base); |
| 15504 | | out_val->data.x_type = type_entry->data.pointer.child_type; |
| 15505 | | return ira->codegen->builtin_types.entry_type; |
| 15197 | return ir_const_type(ira, &ptr_type_child_instruction->base, type_entry->data.pointer.child_type); |
| 15506 | 15198 | } |
| 15507 | 15199 | |
| 15508 | | static ZigType *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) { |
| 15200 | static IrInstruction *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) { |
| 15509 | 15201 | if (ira->new_irb.exec->is_inline) { |
| 15510 | 15202 | // ignore setCold when running functions at compile time |
| 15511 | | ir_build_const_from(ira, &instruction->base); |
| 15512 | | return ira->codegen->builtin_types.entry_void; |
| 15203 | return ir_const_void(ira, &instruction->base); |
| 15513 | 15204 | } |
| 15514 | 15205 | |
| 15515 | | IrInstruction *is_cold_value = instruction->is_cold->other; |
| 15206 | IrInstruction *is_cold_value = instruction->is_cold->child; |
| 15516 | 15207 | bool want_cold; |
| 15517 | 15208 | if (!ir_resolve_bool(ira, is_cold_value, &want_cold)) |
| 15518 | | return ira->codegen->builtin_types.entry_invalid; |
| 15209 | return ira->codegen->invalid_instruction; |
| 15519 | 15210 | |
| 15520 | 15211 | ZigFn *fn_entry = scope_fn_entry(instruction->base.scope); |
| 15521 | 15212 | if (fn_entry == nullptr) { |
| 15522 | 15213 | ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function")); |
| 15523 | | return ira->codegen->builtin_types.entry_invalid; |
| 15214 | return ira->codegen->invalid_instruction; |
| 15524 | 15215 | } |
| 15525 | 15216 | |
| 15526 | 15217 | if (fn_entry->set_cold_node != nullptr) { |
| 15527 | 15218 | ErrorMsg *msg = ir_add_error(ira, &instruction->base, buf_sprintf("cold set twice in same function")); |
| 15528 | 15219 | add_error_note(ira->codegen, msg, fn_entry->set_cold_node, buf_sprintf("first set here")); |
| 15529 | | return ira->codegen->builtin_types.entry_invalid; |
| 15220 | return ira->codegen->invalid_instruction; |
| 15530 | 15221 | } |
| 15531 | 15222 | |
| 15532 | 15223 | fn_entry->set_cold_node = instruction->base.source_node; |
| 15533 | 15224 | fn_entry->is_cold = want_cold; |
| 15534 | 15225 | |
| 15535 | | ir_build_const_from(ira, &instruction->base); |
| 15536 | | return ira->codegen->builtin_types.entry_void; |
| 15226 | return ir_const_void(ira, &instruction->base); |
| 15537 | 15227 | } |
| 15538 | 15228 | |
| 15539 | | static ZigType *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 15229 | static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 15540 | 15230 | IrInstructionSetRuntimeSafety *set_runtime_safety_instruction) |
| 15541 | 15231 | { |
| 15542 | 15232 | if (ira->new_irb.exec->is_inline) { |
| 15543 | 15233 | // ignore setRuntimeSafety when running functions at compile time |
| 15544 | | ir_build_const_from(ira, &set_runtime_safety_instruction->base); |
| 15545 | | return ira->codegen->builtin_types.entry_void; |
| 15234 | return ir_const_void(ira, &set_runtime_safety_instruction->base); |
| 15546 | 15235 | } |
| 15547 | 15236 | |
| 15548 | 15237 | bool *safety_off_ptr; |
| ... | ... | @@ -15574,32 +15263,30 @@ static ZigType *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, |
| 15574 | 15263 | } |
| 15575 | 15264 | assert(scope != nullptr); |
| 15576 | 15265 | |
| 15577 | | IrInstruction *safety_on_value = set_runtime_safety_instruction->safety_on->other; |
| 15266 | IrInstruction *safety_on_value = set_runtime_safety_instruction->safety_on->child; |
| 15578 | 15267 | bool want_runtime_safety; |
| 15579 | 15268 | if (!ir_resolve_bool(ira, safety_on_value, &want_runtime_safety)) |
| 15580 | | return ira->codegen->builtin_types.entry_invalid; |
| 15269 | return ira->codegen->invalid_instruction; |
| 15581 | 15270 | |
| 15582 | 15271 | AstNode *source_node = set_runtime_safety_instruction->base.source_node; |
| 15583 | 15272 | if (*safety_set_node_ptr) { |
| 15584 | 15273 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 15585 | 15274 | buf_sprintf("runtime safety set twice for same scope")); |
| 15586 | 15275 | add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here")); |
| 15587 | | return ira->codegen->builtin_types.entry_invalid; |
| 15276 | return ira->codegen->invalid_instruction; |
| 15588 | 15277 | } |
| 15589 | 15278 | *safety_set_node_ptr = source_node; |
| 15590 | 15279 | *safety_off_ptr = !want_runtime_safety; |
| 15591 | 15280 | |
| 15592 | | ir_build_const_from(ira, &set_runtime_safety_instruction->base); |
| 15593 | | return ira->codegen->builtin_types.entry_void; |
| 15281 | return ir_const_void(ira, &set_runtime_safety_instruction->base); |
| 15594 | 15282 | } |
| 15595 | 15283 | |
| 15596 | | static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 15284 | static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 15597 | 15285 | IrInstructionSetFloatMode *instruction) |
| 15598 | 15286 | { |
| 15599 | 15287 | if (ira->new_irb.exec->is_inline) { |
| 15600 | 15288 | // ignore setFloatMode when running functions at compile time |
| 15601 | | ir_build_const_from(ira, &instruction->base); |
| 15602 | | return ira->codegen->builtin_types.entry_void; |
| 15289 | return ir_const_void(ira, &instruction->base); |
| 15603 | 15290 | } |
| 15604 | 15291 | |
| 15605 | 15292 | bool *fast_math_on_ptr; |
| ... | ... | @@ -15631,38 +15318,37 @@ static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, |
| 15631 | 15318 | } |
| 15632 | 15319 | assert(scope != nullptr); |
| 15633 | 15320 | |
| 15634 | | IrInstruction *float_mode_value = instruction->mode_value->other; |
| 15321 | IrInstruction *float_mode_value = instruction->mode_value->child; |
| 15635 | 15322 | FloatMode float_mode_scalar; |
| 15636 | 15323 | if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar)) |
| 15637 | | return ira->codegen->builtin_types.entry_invalid; |
| 15324 | return ira->codegen->invalid_instruction; |
| 15638 | 15325 | |
| 15639 | 15326 | AstNode *source_node = instruction->base.source_node; |
| 15640 | 15327 | if (*fast_math_set_node_ptr) { |
| 15641 | 15328 | ErrorMsg *msg = ir_add_error_node(ira, source_node, |
| 15642 | 15329 | buf_sprintf("float mode set twice for same scope")); |
| 15643 | 15330 | add_error_note(ira->codegen, msg, *fast_math_set_node_ptr, buf_sprintf("first set here")); |
| 15644 | | return ira->codegen->builtin_types.entry_invalid; |
| 15331 | return ira->codegen->invalid_instruction; |
| 15645 | 15332 | } |
| 15646 | 15333 | *fast_math_set_node_ptr = source_node; |
| 15647 | 15334 | *fast_math_on_ptr = (float_mode_scalar == FloatModeOptimized); |
| 15648 | 15335 | |
| 15649 | | ir_build_const_from(ira, &instruction->base); |
| 15650 | | return ira->codegen->builtin_types.entry_void; |
| 15336 | return ir_const_void(ira, &instruction->base); |
| 15651 | 15337 | } |
| 15652 | 15338 | |
| 15653 | | static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15339 | static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15654 | 15340 | IrInstructionSliceType *slice_type_instruction) |
| 15655 | 15341 | { |
| 15656 | 15342 | Error err; |
| 15657 | 15343 | uint32_t align_bytes = 0; |
| 15658 | 15344 | if (slice_type_instruction->align_value != nullptr) { |
| 15659 | | if (!ir_resolve_align(ira, slice_type_instruction->align_value->other, &align_bytes)) |
| 15660 | | return ira->codegen->builtin_types.entry_invalid; |
| 15345 | if (!ir_resolve_align(ira, slice_type_instruction->align_value->child, &align_bytes)) |
| 15346 | return ira->codegen->invalid_instruction; |
| 15661 | 15347 | } |
| 15662 | 15348 | |
| 15663 | | ZigType *child_type = ir_resolve_type(ira, slice_type_instruction->child_type->other); |
| 15349 | ZigType *child_type = ir_resolve_type(ira, slice_type_instruction->child_type->child); |
| 15664 | 15350 | if (type_is_invalid(child_type)) |
| 15665 | | return ira->codegen->builtin_types.entry_invalid; |
| 15351 | return ira->codegen->invalid_instruction; |
| 15666 | 15352 | |
| 15667 | 15353 | bool is_const = slice_type_instruction->is_const; |
| 15668 | 15354 | bool is_volatile = slice_type_instruction->is_volatile; |
| ... | ... | @@ -15677,7 +15363,7 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15677 | 15363 | case ZigTypeIdOpaque: |
| 15678 | 15364 | ir_add_error_node(ira, slice_type_instruction->base.source_node, |
| 15679 | 15365 | buf_sprintf("slice of type '%s' not allowed", buf_ptr(&child_type->name))); |
| 15680 | | return ira->codegen->builtin_types.entry_invalid; |
| 15366 | return ira->codegen->invalid_instruction; |
| 15681 | 15367 | case ZigTypeIdMetaType: |
| 15682 | 15368 | case ZigTypeIdVoid: |
| 15683 | 15369 | case ZigTypeIdBool: |
| ... | ... | @@ -15699,19 +15385,17 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15699 | 15385 | case ZigTypeIdPromise: |
| 15700 | 15386 | { |
| 15701 | 15387 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusZeroBitsKnown))) |
| 15702 | | return ira->codegen->builtin_types.entry_invalid; |
| 15388 | return ira->codegen->invalid_instruction; |
| 15703 | 15389 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 15704 | 15390 | is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0); |
| 15705 | 15391 | ZigType *result_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 15706 | | ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base); |
| 15707 | | out_val->data.x_type = result_type; |
| 15708 | | return ira->codegen->builtin_types.entry_type; |
| 15392 | return ir_const_type(ira, &slice_type_instruction->base, result_type); |
| 15709 | 15393 | } |
| 15710 | 15394 | } |
| 15711 | 15395 | zig_unreachable(); |
| 15712 | 15396 | } |
| 15713 | 15397 | |
| 15714 | | static ZigType *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsm *asm_instruction) { |
| 15398 | static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsm *asm_instruction) { |
| 15715 | 15399 | assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr); |
| 15716 | 15400 | |
| 15717 | 15401 | AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr; |
| ... | ... | @@ -15723,18 +15407,17 @@ static ZigType *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsm *asm |
| 15723 | 15407 | { |
| 15724 | 15408 | ir_add_error(ira, &asm_instruction->base, |
| 15725 | 15409 | buf_sprintf("global assembly cannot have inputs, outputs, or clobbers")); |
| 15726 | | return ira->codegen->builtin_types.entry_invalid; |
| 15410 | return ira->codegen->invalid_instruction; |
| 15727 | 15411 | } |
| 15728 | 15412 | |
| 15729 | 15413 | buf_append_char(&ira->codegen->global_asm, '\n'); |
| 15730 | 15414 | buf_append_buf(&ira->codegen->global_asm, asm_expr->asm_template); |
| 15731 | 15415 | |
| 15732 | | ir_build_const_from(ira, &asm_instruction->base); |
| 15733 | | return ira->codegen->builtin_types.entry_void; |
| 15416 | return ir_const_void(ira, &asm_instruction->base); |
| 15734 | 15417 | } |
| 15735 | 15418 | |
| 15736 | 15419 | if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base)) |
| 15737 | | return ira->codegen->builtin_types.entry_invalid; |
| 15420 | return ira->codegen->invalid_instruction; |
| 15738 | 15421 | |
| 15739 | 15422 | // TODO validate the output types and variable types |
| 15740 | 15423 | |
| ... | ... | @@ -15745,38 +15428,41 @@ static ZigType *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsm *asm |
| 15745 | 15428 | for (size_t i = 0; i < asm_expr->output_list.length; i += 1) { |
| 15746 | 15429 | AsmOutput *asm_output = asm_expr->output_list.at(i); |
| 15747 | 15430 | if (asm_output->return_type) { |
| 15748 | | output_types[i] = asm_instruction->output_types[i]->other; |
| 15431 | output_types[i] = asm_instruction->output_types[i]->child; |
| 15749 | 15432 | return_type = ir_resolve_type(ira, output_types[i]); |
| 15750 | 15433 | if (type_is_invalid(return_type)) |
| 15751 | | return ira->codegen->builtin_types.entry_invalid; |
| 15434 | return ira->codegen->invalid_instruction; |
| 15752 | 15435 | } |
| 15753 | 15436 | } |
| 15754 | 15437 | |
| 15755 | 15438 | for (size_t i = 0; i < asm_expr->input_list.length; i += 1) { |
| 15756 | | input_list[i] = asm_instruction->input_list[i]->other; |
| 15439 | input_list[i] = asm_instruction->input_list[i]->child; |
| 15757 | 15440 | if (type_is_invalid(input_list[i]->value.type)) |
| 15758 | | return ira->codegen->builtin_types.entry_invalid; |
| 15441 | return ira->codegen->invalid_instruction; |
| 15759 | 15442 | } |
| 15760 | 15443 | |
| 15761 | | ir_build_asm_from(&ira->new_irb, &asm_instruction->base, input_list, output_types, |
| 15762 | | asm_instruction->output_vars, asm_instruction->return_count, asm_instruction->has_side_effects); |
| 15763 | | return return_type; |
| 15444 | IrInstruction *result = ir_build_asm(&ira->new_irb, |
| 15445 | asm_instruction->base.scope, asm_instruction->base.source_node, |
| 15446 | input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count, |
| 15447 | asm_instruction->has_side_effects); |
| 15448 | result->value.type = return_type; |
| 15449 | return result; |
| 15764 | 15450 | } |
| 15765 | 15451 | |
| 15766 | | static ZigType *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 15452 | static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 15767 | 15453 | IrInstructionArrayType *array_type_instruction) |
| 15768 | 15454 | { |
| 15769 | 15455 | Error err; |
| 15770 | 15456 | |
| 15771 | | IrInstruction *size_value = array_type_instruction->size->other; |
| 15457 | IrInstruction *size_value = array_type_instruction->size->child; |
| 15772 | 15458 | uint64_t size; |
| 15773 | 15459 | if (!ir_resolve_usize(ira, size_value, &size)) |
| 15774 | | return ira->codegen->builtin_types.entry_invalid; |
| 15460 | return ira->codegen->invalid_instruction; |
| 15775 | 15461 | |
| 15776 | | IrInstruction *child_type_value = array_type_instruction->child_type->other; |
| 15462 | IrInstruction *child_type_value = array_type_instruction->child_type->child; |
| 15777 | 15463 | ZigType *child_type = ir_resolve_type(ira, child_type_value); |
| 15778 | 15464 | if (type_is_invalid(child_type)) |
| 15779 | | return ira->codegen->builtin_types.entry_invalid; |
| 15465 | return ira->codegen->invalid_instruction; |
| 15780 | 15466 | switch (child_type->id) { |
| 15781 | 15467 | case ZigTypeIdInvalid: // handled above |
| 15782 | 15468 | zig_unreachable(); |
| ... | ... | @@ -15787,7 +15473,7 @@ static ZigType *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 15787 | 15473 | case ZigTypeIdOpaque: |
| 15788 | 15474 | ir_add_error_node(ira, array_type_instruction->base.source_node, |
| 15789 | 15475 | buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name))); |
| 15790 | | return ira->codegen->builtin_types.entry_invalid; |
| 15476 | return ira->codegen->invalid_instruction; |
| 15791 | 15477 | case ZigTypeIdMetaType: |
| 15792 | 15478 | case ZigTypeIdVoid: |
| 15793 | 15479 | case ZigTypeIdBool: |
| ... | ... | @@ -15809,43 +15495,39 @@ static ZigType *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 15809 | 15495 | case ZigTypeIdPromise: |
| 15810 | 15496 | { |
| 15811 | 15497 | if ((err = ensure_complete_type(ira->codegen, child_type))) |
| 15812 | | return ira->codegen->builtin_types.entry_invalid; |
| 15498 | return ira->codegen->invalid_instruction; |
| 15813 | 15499 | ZigType *result_type = get_array_type(ira->codegen, child_type, size); |
| 15814 | | ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base); |
| 15815 | | out_val->data.x_type = result_type; |
| 15816 | | return ira->codegen->builtin_types.entry_type; |
| 15500 | return ir_const_type(ira, &array_type_instruction->base, result_type); |
| 15817 | 15501 | } |
| 15818 | 15502 | } |
| 15819 | 15503 | zig_unreachable(); |
| 15820 | 15504 | } |
| 15821 | 15505 | |
| 15822 | | static ZigType *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) { |
| 15506 | static IrInstruction *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) { |
| 15823 | 15507 | ZigType *promise_type; |
| 15824 | 15508 | |
| 15825 | 15509 | if (instruction->payload_type == nullptr) { |
| 15826 | 15510 | promise_type = ira->codegen->builtin_types.entry_promise; |
| 15827 | 15511 | } else { |
| 15828 | | ZigType *payload_type = ir_resolve_type(ira, instruction->payload_type->other); |
| 15512 | ZigType *payload_type = ir_resolve_type(ira, instruction->payload_type->child); |
| 15829 | 15513 | if (type_is_invalid(payload_type)) |
| 15830 | | return ira->codegen->builtin_types.entry_invalid; |
| 15514 | return ira->codegen->invalid_instruction; |
| 15831 | 15515 | |
| 15832 | 15516 | promise_type = get_promise_type(ira->codegen, payload_type); |
| 15833 | 15517 | } |
| 15834 | 15518 | |
| 15835 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 15836 | | out_val->data.x_type = promise_type; |
| 15837 | | return ira->codegen->builtin_types.entry_type; |
| 15519 | return ir_const_type(ira, &instruction->base, promise_type); |
| 15838 | 15520 | } |
| 15839 | 15521 | |
| 15840 | | static ZigType *ir_analyze_instruction_size_of(IrAnalyze *ira, |
| 15522 | static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, |
| 15841 | 15523 | IrInstructionSizeOf *size_of_instruction) |
| 15842 | 15524 | { |
| 15843 | 15525 | Error err; |
| 15844 | | IrInstruction *type_value = size_of_instruction->type_value->other; |
| 15526 | IrInstruction *type_value = size_of_instruction->type_value->child; |
| 15845 | 15527 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 15846 | 15528 | |
| 15847 | 15529 | if ((err = ensure_complete_type(ira->codegen, type_entry))) |
| 15848 | | return ira->codegen->builtin_types.entry_invalid; |
| 15530 | return ira->codegen->invalid_instruction; |
| 15849 | 15531 | |
| 15850 | 15532 | switch (type_entry->id) { |
| 15851 | 15533 | case ZigTypeIdInvalid: // handled above |
| ... | ... | @@ -15862,7 +15544,7 @@ static ZigType *ir_analyze_instruction_size_of(IrAnalyze *ira, |
| 15862 | 15544 | case ZigTypeIdOpaque: |
| 15863 | 15545 | ir_add_error_node(ira, size_of_instruction->base.source_node, |
| 15864 | 15546 | buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name))); |
| 15865 | | return ira->codegen->builtin_types.entry_invalid; |
| 15547 | return ira->codegen->invalid_instruction; |
| 15866 | 15548 | case ZigTypeIdVoid: |
| 15867 | 15549 | case ZigTypeIdBool: |
| 15868 | 15550 | case ZigTypeIdInt: |
| ... | ... | @@ -15879,18 +15561,16 @@ static ZigType *ir_analyze_instruction_size_of(IrAnalyze *ira, |
| 15879 | 15561 | case ZigTypeIdPromise: |
| 15880 | 15562 | { |
| 15881 | 15563 | uint64_t size_in_bytes = type_size(ira->codegen, type_entry); |
| 15882 | | ConstExprValue *out_val = ir_build_const_from(ira, &size_of_instruction->base); |
| 15883 | | bigint_init_unsigned(&out_val->data.x_bigint, size_in_bytes); |
| 15884 | | return ira->codegen->builtin_types.entry_num_lit_int; |
| 15564 | return ir_const_unsigned(ira, &size_of_instruction->base, size_in_bytes); |
| 15885 | 15565 | } |
| 15886 | 15566 | } |
| 15887 | 15567 | zig_unreachable(); |
| 15888 | 15568 | } |
| 15889 | 15569 | |
| 15890 | | static ZigType *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) { |
| 15891 | | IrInstruction *value = instruction->value->other; |
| 15570 | static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) { |
| 15571 | IrInstruction *value = instruction->value->child; |
| 15892 | 15572 | if (type_is_invalid(value->value.type)) |
| 15893 | | return ira->codegen->builtin_types.entry_invalid; |
| 15573 | return ira->codegen->invalid_instruction; |
| 15894 | 15574 | |
| 15895 | 15575 | ZigType *type_entry = value->value.type; |
| 15896 | 15576 | |
| ... | ... | @@ -15898,43 +15578,39 @@ static ZigType *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructi |
| 15898 | 15578 | if (instr_is_comptime(value)) { |
| 15899 | 15579 | ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefBad); |
| 15900 | 15580 | if (!maybe_val) |
| 15901 | | return ira->codegen->builtin_types.entry_invalid; |
| 15581 | return ira->codegen->invalid_instruction; |
| 15902 | 15582 | |
| 15903 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 15904 | | out_val->data.x_bool = !optional_value_is_null(maybe_val); |
| 15905 | | return ira->codegen->builtin_types.entry_bool; |
| 15583 | return ir_const_bool(ira, &instruction->base, !optional_value_is_null(maybe_val)); |
| 15906 | 15584 | } |
| 15907 | 15585 | |
| 15908 | | ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value); |
| 15909 | | return ira->codegen->builtin_types.entry_bool; |
| 15586 | IrInstruction *result = ir_build_test_nonnull(&ira->new_irb, |
| 15587 | instruction->base.scope, instruction->base.source_node, value); |
| 15588 | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 15589 | return result; |
| 15910 | 15590 | } else if (type_entry->id == ZigTypeIdNull) { |
| 15911 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 15912 | | out_val->data.x_bool = false; |
| 15913 | | return ira->codegen->builtin_types.entry_bool; |
| 15591 | return ir_const_bool(ira, &instruction->base, false); |
| 15914 | 15592 | } else { |
| 15915 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 15916 | | out_val->data.x_bool = true; |
| 15917 | | return ira->codegen->builtin_types.entry_bool; |
| 15593 | return ir_const_bool(ira, &instruction->base, true); |
| 15918 | 15594 | } |
| 15919 | 15595 | } |
| 15920 | 15596 | |
| 15921 | | static ZigType *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 15597 | static IrInstruction *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 15922 | 15598 | IrInstructionUnwrapOptional *unwrap_maybe_instruction) |
| 15923 | 15599 | { |
| 15924 | | IrInstruction *value = unwrap_maybe_instruction->value->other; |
| 15600 | IrInstruction *value = unwrap_maybe_instruction->value->child; |
| 15925 | 15601 | if (type_is_invalid(value->value.type)) |
| 15926 | | return ira->codegen->builtin_types.entry_invalid; |
| 15602 | return ira->codegen->invalid_instruction; |
| 15927 | 15603 | |
| 15928 | 15604 | ZigType *ptr_type = value->value.type; |
| 15929 | 15605 | assert(ptr_type->id == ZigTypeIdPointer); |
| 15930 | 15606 | |
| 15931 | 15607 | ZigType *type_entry = ptr_type->data.pointer.child_type; |
| 15932 | 15608 | if (type_is_invalid(type_entry)) { |
| 15933 | | return ira->codegen->builtin_types.entry_invalid; |
| 15609 | return ira->codegen->invalid_instruction; |
| 15934 | 15610 | } else if (type_entry->id != ZigTypeIdOptional) { |
| 15935 | 15611 | ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node, |
| 15936 | 15612 | buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name))); |
| 15937 | | return ira->codegen->builtin_types.entry_invalid; |
| 15613 | return ira->codegen->invalid_instruction; |
| 15938 | 15614 | } |
| 15939 | 15615 | ZigType *child_type = type_entry->data.maybe.child_type; |
| 15940 | 15616 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| ... | ... | @@ -15943,17 +15619,18 @@ static ZigType *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 15943 | 15619 | if (instr_is_comptime(value)) { |
| 15944 | 15620 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| 15945 | 15621 | if (!val) |
| 15946 | | return ira->codegen->builtin_types.entry_invalid; |
| 15622 | return ira->codegen->invalid_instruction; |
| 15947 | 15623 | ConstExprValue *maybe_val = ir_const_ptr_pointee(ira, val, unwrap_maybe_instruction->base.source_node); |
| 15948 | 15624 | if (maybe_val == nullptr) |
| 15949 | | return ira->codegen->builtin_types.entry_invalid; |
| 15625 | return ira->codegen->invalid_instruction; |
| 15950 | 15626 | |
| 15951 | 15627 | if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 15952 | 15628 | if (optional_value_is_null(maybe_val)) { |
| 15953 | 15629 | ir_add_error(ira, &unwrap_maybe_instruction->base, buf_sprintf("unable to unwrap null")); |
| 15954 | | return ira->codegen->builtin_types.entry_invalid; |
| 15630 | return ira->codegen->invalid_instruction; |
| 15955 | 15631 | } |
| 15956 | | ConstExprValue *out_val = ir_build_const_from(ira, &unwrap_maybe_instruction->base); |
| 15632 | IrInstruction *result = ir_const(ira, &unwrap_maybe_instruction->base, result_type); |
| 15633 | ConstExprValue *out_val = &result->value; |
| 15957 | 15634 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 15958 | 15635 | out_val->data.x_ptr.mut = val->data.x_ptr.mut; |
| 15959 | 15636 | if (type_is_codegen_pointer(child_type)) { |
| ... | ... | @@ -15961,83 +15638,87 @@ static ZigType *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 15961 | 15638 | } else { |
| 15962 | 15639 | out_val->data.x_ptr.data.ref.pointee = maybe_val->data.x_optional; |
| 15963 | 15640 | } |
| 15964 | | return result_type; |
| 15641 | return result; |
| 15965 | 15642 | } |
| 15966 | 15643 | } |
| 15967 | 15644 | |
| 15968 | | ir_build_unwrap_maybe_from(&ira->new_irb, &unwrap_maybe_instruction->base, value, |
| 15969 | | unwrap_maybe_instruction->safety_check_on); |
| 15970 | | return result_type; |
| 15645 | IrInstruction *result = ir_build_unwrap_maybe(&ira->new_irb, |
| 15646 | unwrap_maybe_instruction->base.scope, unwrap_maybe_instruction->base.source_node, |
| 15647 | value, unwrap_maybe_instruction->safety_check_on); |
| 15648 | result->value.type = result_type; |
| 15649 | return result; |
| 15971 | 15650 | } |
| 15972 | 15651 | |
| 15973 | | static ZigType *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) { |
| 15974 | | IrInstruction *value = ctz_instruction->value->other; |
| 15652 | static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) { |
| 15653 | IrInstruction *value = ctz_instruction->value->child; |
| 15975 | 15654 | if (type_is_invalid(value->value.type)) { |
| 15976 | | return ira->codegen->builtin_types.entry_invalid; |
| 15655 | return ira->codegen->invalid_instruction; |
| 15977 | 15656 | } else if (value->value.type->id == ZigTypeIdInt) { |
| 15978 | 15657 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, |
| 15979 | 15658 | value->value.type->data.integral.bit_count); |
| 15980 | 15659 | if (value->value.special != ConstValSpecialRuntime) { |
| 15981 | | size_t result = bigint_ctz(&value->value.data.x_bigint, |
| 15660 | size_t result_usize = bigint_ctz(&value->value.data.x_bigint, |
| 15982 | 15661 | value->value.type->data.integral.bit_count); |
| 15983 | | ConstExprValue *out_val = ir_build_const_from(ira, &ctz_instruction->base); |
| 15984 | | bigint_init_unsigned(&out_val->data.x_bigint, result); |
| 15985 | | return return_type; |
| 15662 | IrInstruction *result = ir_const(ira, &ctz_instruction->base, return_type); |
| 15663 | bigint_init_unsigned(&result->value.data.x_bigint, result_usize); |
| 15664 | return result; |
| 15986 | 15665 | } |
| 15987 | 15666 | |
| 15988 | | ir_build_ctz_from(&ira->new_irb, &ctz_instruction->base, value); |
| 15989 | | return return_type; |
| 15667 | IrInstruction *result = ir_build_ctz(&ira->new_irb, |
| 15668 | ctz_instruction->base.scope, ctz_instruction->base.source_node, value); |
| 15669 | result->value.type = return_type; |
| 15670 | return result; |
| 15990 | 15671 | } else { |
| 15991 | 15672 | ir_add_error_node(ira, ctz_instruction->base.source_node, |
| 15992 | 15673 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name))); |
| 15993 | | return ira->codegen->builtin_types.entry_invalid; |
| 15674 | return ira->codegen->invalid_instruction; |
| 15994 | 15675 | } |
| 15995 | 15676 | } |
| 15996 | 15677 | |
| 15997 | | static ZigType *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) { |
| 15998 | | IrInstruction *value = clz_instruction->value->other; |
| 15678 | static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) { |
| 15679 | IrInstruction *value = clz_instruction->value->child; |
| 15999 | 15680 | if (type_is_invalid(value->value.type)) { |
| 16000 | | return ira->codegen->builtin_types.entry_invalid; |
| 15681 | return ira->codegen->invalid_instruction; |
| 16001 | 15682 | } else if (value->value.type->id == ZigTypeIdInt) { |
| 16002 | 15683 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, |
| 16003 | 15684 | value->value.type->data.integral.bit_count); |
| 16004 | 15685 | if (value->value.special != ConstValSpecialRuntime) { |
| 16005 | | size_t result = bigint_clz(&value->value.data.x_bigint, |
| 15686 | size_t result_usize = bigint_clz(&value->value.data.x_bigint, |
| 16006 | 15687 | value->value.type->data.integral.bit_count); |
| 16007 | | ConstExprValue *out_val = ir_build_const_from(ira, &clz_instruction->base); |
| 16008 | | bigint_init_unsigned(&out_val->data.x_bigint, result); |
| 16009 | | return return_type; |
| 15688 | IrInstruction *result = ir_const(ira, &clz_instruction->base, return_type); |
| 15689 | bigint_init_unsigned(&result->value.data.x_bigint, result_usize); |
| 15690 | return result; |
| 16010 | 15691 | } |
| 16011 | 15692 | |
| 16012 | | ir_build_clz_from(&ira->new_irb, &clz_instruction->base, value); |
| 16013 | | return return_type; |
| 15693 | IrInstruction *result = ir_build_clz(&ira->new_irb, |
| 15694 | clz_instruction->base.scope, clz_instruction->base.source_node, value); |
| 15695 | result->value.type = return_type; |
| 15696 | return result; |
| 16014 | 15697 | } else { |
| 16015 | 15698 | ir_add_error_node(ira, clz_instruction->base.source_node, |
| 16016 | 15699 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name))); |
| 16017 | | return ira->codegen->builtin_types.entry_invalid; |
| 15700 | return ira->codegen->invalid_instruction; |
| 16018 | 15701 | } |
| 16019 | 15702 | } |
| 16020 | 15703 | |
| 16021 | | static ZigType *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) { |
| 16022 | | IrInstruction *value = instruction->value->other; |
| 15704 | static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) { |
| 15705 | IrInstruction *value = instruction->value->child; |
| 16023 | 15706 | if (type_is_invalid(value->value.type)) |
| 16024 | | return ira->codegen->builtin_types.entry_invalid; |
| 15707 | return ira->codegen->invalid_instruction; |
| 16025 | 15708 | |
| 16026 | 15709 | if (value->value.type->id != ZigTypeIdInt && value->value.type->id != ZigTypeIdComptimeInt) { |
| 16027 | 15710 | ir_add_error(ira, value, |
| 16028 | 15711 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name))); |
| 16029 | | return ira->codegen->builtin_types.entry_invalid; |
| 15712 | return ira->codegen->invalid_instruction; |
| 16030 | 15713 | } |
| 16031 | 15714 | |
| 16032 | 15715 | if (instr_is_comptime(value)) { |
| 16033 | 15716 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| 16034 | 15717 | if (!val) |
| 16035 | | return ira->codegen->builtin_types.entry_invalid; |
| 15718 | return ira->codegen->invalid_instruction; |
| 16036 | 15719 | if (bigint_cmp_zero(&val->data.x_bigint) != CmpLT) { |
| 16037 | 15720 | size_t result = bigint_popcount_unsigned(&val->data.x_bigint); |
| 16038 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 16039 | | bigint_init_unsigned(&out_val->data.x_bigint, result); |
| 16040 | | return ira->codegen->builtin_types.entry_num_lit_int; |
| 15721 | return ir_const_unsigned(ira, &instruction->base, result); |
| 16041 | 15722 | } |
| 16042 | 15723 | if (value->value.type->id == ZigTypeIdComptimeInt) { |
| 16043 | 15724 | Buf *val_buf = buf_alloc(); |
| ... | ... | @@ -16045,19 +15726,16 @@ static ZigType *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPo |
| 16045 | 15726 | ir_add_error(ira, &instruction->base, |
| 16046 | 15727 | buf_sprintf("@popCount on negative %s value %s", |
| 16047 | 15728 | buf_ptr(&value->value.type->name), buf_ptr(val_buf))); |
| 16048 | | return ira->codegen->builtin_types.entry_invalid; |
| 15729 | return ira->codegen->invalid_instruction; |
| 16049 | 15730 | } |
| 16050 | 15731 | size_t result = bigint_popcount_signed(&val->data.x_bigint, value->value.type->data.integral.bit_count); |
| 16051 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 16052 | | bigint_init_unsigned(&out_val->data.x_bigint, result); |
| 16053 | | return ira->codegen->builtin_types.entry_num_lit_int; |
| 15732 | return ir_const_unsigned(ira, &instruction->base, result); |
| 16054 | 15733 | } |
| 16055 | 15734 | |
| 16056 | 15735 | IrInstruction *result = ir_build_pop_count(&ira->new_irb, instruction->base.scope, |
| 16057 | 15736 | instruction->base.source_node, value); |
| 16058 | 15737 | result->value.type = get_smallest_unsigned_int_type(ira->codegen, value->value.type->data.integral.bit_count); |
| 16059 | | ir_link_new_instruction(result, &instruction->base); |
| 16060 | | return result->value.type; |
| 15738 | return result; |
| 16061 | 15739 | } |
| 16062 | 15740 | |
| 16063 | 15741 | static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) { |
| ... | ... | @@ -16103,15 +15781,15 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source |
| 16103 | 15781 | return result; |
| 16104 | 15782 | } |
| 16105 | 15783 | |
| 16106 | | static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 15784 | static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 16107 | 15785 | IrInstructionSwitchBr *switch_br_instruction) |
| 16108 | 15786 | { |
| 16109 | | IrInstruction *target_value = switch_br_instruction->target_value->other; |
| 15787 | IrInstruction *target_value = switch_br_instruction->target_value->child; |
| 16110 | 15788 | if (type_is_invalid(target_value->value.type)) |
| 16111 | 15789 | return ir_unreach_error(ira); |
| 16112 | 15790 | |
| 16113 | 15791 | if (switch_br_instruction->switch_prongs_void != nullptr) { |
| 16114 | | if (type_is_invalid(switch_br_instruction->switch_prongs_void->other->value.type)) { |
| 15792 | if (type_is_invalid(switch_br_instruction->switch_prongs_void->child->value.type)) { |
| 16115 | 15793 | return ir_unreach_error(ira); |
| 16116 | 15794 | } |
| 16117 | 15795 | } |
| ... | ... | @@ -16120,8 +15798,8 @@ static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 16120 | 15798 | size_t case_count = switch_br_instruction->case_count; |
| 16121 | 15799 | |
| 16122 | 15800 | bool is_comptime; |
| 16123 | | if (!ir_resolve_comptime(ira, switch_br_instruction->is_comptime->other, &is_comptime)) |
| 16124 | | return ira->codegen->builtin_types.entry_invalid; |
| 15801 | if (!ir_resolve_comptime(ira, switch_br_instruction->is_comptime->child, &is_comptime)) |
| 15802 | return ira->codegen->invalid_instruction; |
| 16125 | 15803 | |
| 16126 | 15804 | if (is_comptime || instr_is_comptime(target_value)) { |
| 16127 | 15805 | ConstExprValue *target_val = ir_resolve_const(ira, target_value, UndefBad); |
| ... | ... | @@ -16131,7 +15809,7 @@ static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 16131 | 15809 | IrBasicBlock *old_dest_block = switch_br_instruction->else_block; |
| 16132 | 15810 | for (size_t i = 0; i < case_count; i += 1) { |
| 16133 | 15811 | IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i]; |
| 16134 | | IrInstruction *case_value = old_case->value->other; |
| 15812 | IrInstruction *case_value = old_case->value->child; |
| 16135 | 15813 | if (type_is_invalid(case_value->value.type)) |
| 16136 | 15814 | return ir_unreach_error(ira); |
| 16137 | 15815 | |
| ... | ... | @@ -16159,8 +15837,11 @@ static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 16159 | 15837 | return ir_inline_bb(ira, &switch_br_instruction->base, old_dest_block); |
| 16160 | 15838 | } else { |
| 16161 | 15839 | IrBasicBlock *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base); |
| 16162 | | ir_build_br_from(&ira->new_irb, &switch_br_instruction->base, new_dest_block); |
| 16163 | | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 15840 | IrInstruction *result = ir_build_br(&ira->new_irb, |
| 15841 | switch_br_instruction->base.scope, switch_br_instruction->base.source_node, |
| 15842 | new_dest_block, nullptr); |
| 15843 | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 15844 | return ir_finish_anal(ira, result); |
| 16164 | 15845 | } |
| 16165 | 15846 | } |
| 16166 | 15847 | |
| ... | ... | @@ -16178,7 +15859,7 @@ static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 16178 | 15859 | new_case->block->ref_instruction = nullptr; |
| 16179 | 15860 | |
| 16180 | 15861 | IrInstruction *old_value = old_case->value; |
| 16181 | | IrInstruction *new_value = old_value->other; |
| 15862 | IrInstruction *new_value = old_value->child; |
| 16182 | 15863 | if (type_is_invalid(new_value->value.type)) |
| 16183 | 15864 | continue; |
| 16184 | 15865 | |
| ... | ... | @@ -16206,32 +15887,31 @@ static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 16206 | 15887 | } |
| 16207 | 15888 | |
| 16208 | 15889 | IrBasicBlock *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base); |
| 16209 | | ir_build_switch_br_from(&ira->new_irb, &switch_br_instruction->base, |
| 16210 | | target_value, new_else_block, case_count, cases, nullptr, nullptr); |
| 16211 | | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 15890 | IrInstruction *result = ir_build_switch_br(&ira->new_irb, |
| 15891 | switch_br_instruction->base.scope, switch_br_instruction->base.source_node, |
| 15892 | target_value, new_else_block, case_count, cases, nullptr, nullptr); |
| 15893 | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 15894 | return ir_finish_anal(ira, result); |
| 16212 | 15895 | } |
| 16213 | 15896 | |
| 16214 | | static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15897 | static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16215 | 15898 | IrInstructionSwitchTarget *switch_target_instruction) |
| 16216 | 15899 | { |
| 16217 | 15900 | Error err; |
| 16218 | | IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->other; |
| 15901 | IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->child; |
| 16219 | 15902 | if (type_is_invalid(target_value_ptr->value.type)) |
| 16220 | | return ira->codegen->builtin_types.entry_invalid; |
| 15903 | return ira->codegen->invalid_instruction; |
| 16221 | 15904 | |
| 16222 | 15905 | if (target_value_ptr->value.type->id == ZigTypeIdMetaType) { |
| 16223 | 15906 | assert(instr_is_comptime(target_value_ptr)); |
| 16224 | 15907 | ZigType *ptr_type = target_value_ptr->value.data.x_type; |
| 16225 | 15908 | assert(ptr_type->id == ZigTypeIdPointer); |
| 16226 | | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); |
| 16227 | | out_val->type = ira->codegen->builtin_types.entry_type; |
| 16228 | | out_val->data.x_type = ptr_type->data.pointer.child_type; |
| 16229 | | return out_val->type; |
| 15909 | return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type); |
| 16230 | 15910 | } |
| 16231 | 15911 | |
| 16232 | 15912 | if (target_value_ptr->value.type->id != ZigTypeIdPointer) { |
| 16233 | 15913 | ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target")); |
| 16234 | | return ira->codegen->builtin_types.entry_invalid; |
| 15914 | return ira->codegen->invalid_instruction; |
| 16235 | 15915 | } |
| 16236 | 15916 | |
| 16237 | 15917 | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| ... | ... | @@ -16239,13 +15919,13 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16239 | 15919 | if (instr_is_comptime(target_value_ptr)) { |
| 16240 | 15920 | pointee_val = ir_const_ptr_pointee(ira, &target_value_ptr->value, target_value_ptr->source_node); |
| 16241 | 15921 | if (pointee_val == nullptr) |
| 16242 | | return ira->codegen->builtin_types.entry_invalid; |
| 15922 | return ira->codegen->invalid_instruction; |
| 16243 | 15923 | |
| 16244 | 15924 | if (pointee_val->special == ConstValSpecialRuntime) |
| 16245 | 15925 | pointee_val = nullptr; |
| 16246 | 15926 | } |
| 16247 | 15927 | if ((err = ensure_complete_type(ira->codegen, target_type))) |
| 16248 | | return ira->codegen->builtin_types.entry_invalid; |
| 15928 | return ira->codegen->invalid_instruction; |
| 16249 | 15929 | |
| 16250 | 15930 | switch (target_type->id) { |
| 16251 | 15931 | case ZigTypeIdInvalid: |
| ... | ... | @@ -16261,16 +15941,20 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16261 | 15941 | case ZigTypeIdPromise: |
| 16262 | 15942 | case ZigTypeIdFn: |
| 16263 | 15943 | case ZigTypeIdNamespace: |
| 16264 | | case ZigTypeIdErrorSet: |
| 15944 | case ZigTypeIdErrorSet: { |
| 16265 | 15945 | if (pointee_val) { |
| 16266 | | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); |
| 16267 | | copy_const_val(out_val, pointee_val, true); |
| 16268 | | out_val->type = target_type; |
| 16269 | | return target_type; |
| 15946 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr); |
| 15947 | copy_const_val(&result->value, pointee_val, true); |
| 15948 | result->value.type = target_type; |
| 15949 | return result; |
| 16270 | 15950 | } |
| 16271 | 15951 | |
| 16272 | | ir_build_load_ptr_from(&ira->new_irb, &switch_target_instruction->base, target_value_ptr); |
| 16273 | | return target_type; |
| 15952 | IrInstruction *result = ir_build_load_ptr(&ira->new_irb, |
| 15953 | switch_target_instruction->base.scope, switch_target_instruction->base.source_node, |
| 15954 | target_value_ptr); |
| 15955 | result->value.type = target_type; |
| 15956 | return result; |
| 15957 | } |
| 16274 | 15958 | case ZigTypeIdUnion: { |
| 16275 | 15959 | AstNode *decl_node = target_type->data.unionation.decl_node; |
| 16276 | 15960 | if (!decl_node->data.container_decl.auto_enum && |
| ... | ... | @@ -16280,21 +15964,21 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16280 | 15964 | buf_sprintf("switch on union which has no attached enum")); |
| 16281 | 15965 | add_error_note(ira->codegen, msg, decl_node, |
| 16282 | 15966 | buf_sprintf("consider 'union(enum)' here")); |
| 16283 | | return ira->codegen->builtin_types.entry_invalid; |
| 15967 | return ira->codegen->invalid_instruction; |
| 16284 | 15968 | } |
| 16285 | 15969 | ZigType *tag_type = target_type->data.unionation.tag_type; |
| 16286 | 15970 | assert(tag_type != nullptr); |
| 16287 | 15971 | assert(tag_type->id == ZigTypeIdEnum); |
| 16288 | 15972 | if (pointee_val) { |
| 16289 | | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); |
| 16290 | | bigint_init_bigint(&out_val->data.x_enum_tag, &pointee_val->data.x_union.tag); |
| 16291 | | return tag_type; |
| 15973 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type); |
| 15974 | bigint_init_bigint(&result->value.data.x_enum_tag, &pointee_val->data.x_union.tag); |
| 15975 | return result; |
| 16292 | 15976 | } |
| 16293 | 15977 | if (tag_type->data.enumeration.src_field_count == 1) { |
| 16294 | | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); |
| 15978 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type); |
| 16295 | 15979 | TypeEnumField *only_field = &tag_type->data.enumeration.fields[0]; |
| 16296 | | bigint_init_bigint(&out_val->data.x_enum_tag, &only_field->value); |
| 16297 | | return tag_type; |
| 15980 | bigint_init_bigint(&result->value.data.x_enum_tag, &only_field->value); |
| 15981 | return result; |
| 16298 | 15982 | } |
| 16299 | 15983 | |
| 16300 | 15984 | IrInstruction *union_value = ir_build_load_ptr(&ira->new_irb, switch_target_instruction->base.scope, |
| ... | ... | @@ -16304,30 +15988,28 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16304 | 15988 | IrInstruction *union_tag_inst = ir_build_union_tag(&ira->new_irb, switch_target_instruction->base.scope, |
| 16305 | 15989 | switch_target_instruction->base.source_node, union_value); |
| 16306 | 15990 | union_tag_inst->value.type = tag_type; |
| 16307 | | ir_link_new_instruction(union_tag_inst, &switch_target_instruction->base); |
| 16308 | | return tag_type; |
| 15991 | return union_tag_inst; |
| 16309 | 15992 | } |
| 16310 | 15993 | case ZigTypeIdEnum: { |
| 16311 | 15994 | if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown))) |
| 16312 | | return ira->codegen->builtin_types.entry_invalid; |
| 15995 | return ira->codegen->invalid_instruction; |
| 16313 | 15996 | if (target_type->data.enumeration.src_field_count < 2) { |
| 16314 | 15997 | TypeEnumField *only_field = &target_type->data.enumeration.fields[0]; |
| 16315 | | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); |
| 16316 | | bigint_init_bigint(&out_val->data.x_enum_tag, &only_field->value); |
| 16317 | | return target_type; |
| 15998 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type); |
| 15999 | bigint_init_bigint(&result->value.data.x_enum_tag, &only_field->value); |
| 16000 | return result; |
| 16318 | 16001 | } |
| 16319 | 16002 | |
| 16320 | 16003 | if (pointee_val) { |
| 16321 | | ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); |
| 16322 | | bigint_init_bigint(&out_val->data.x_enum_tag, &pointee_val->data.x_enum_tag); |
| 16323 | | return target_type; |
| 16004 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type); |
| 16005 | bigint_init_bigint(&result->value.data.x_enum_tag, &pointee_val->data.x_enum_tag); |
| 16006 | return result; |
| 16324 | 16007 | } |
| 16325 | 16008 | |
| 16326 | 16009 | IrInstruction *enum_value = ir_build_load_ptr(&ira->new_irb, switch_target_instruction->base.scope, |
| 16327 | 16010 | switch_target_instruction->base.source_node, target_value_ptr); |
| 16328 | 16011 | enum_value->value.type = target_type; |
| 16329 | | ir_link_new_instruction(enum_value, &switch_target_instruction->base); |
| 16330 | | return target_type; |
| 16012 | return enum_value; |
| 16331 | 16013 | } |
| 16332 | 16014 | case ZigTypeIdErrorUnion: |
| 16333 | 16015 | case ZigTypeIdUnreachable: |
| ... | ... | @@ -16341,26 +16023,26 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16341 | 16023 | case ZigTypeIdOpaque: |
| 16342 | 16024 | ir_add_error(ira, &switch_target_instruction->base, |
| 16343 | 16025 | buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name))); |
| 16344 | | return ira->codegen->builtin_types.entry_invalid; |
| 16026 | return ira->codegen->invalid_instruction; |
| 16345 | 16027 | } |
| 16346 | 16028 | zig_unreachable(); |
| 16347 | 16029 | } |
| 16348 | 16030 | |
| 16349 | | static ZigType *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) { |
| 16350 | | IrInstruction *target_value_ptr = instruction->target_value_ptr->other; |
| 16031 | static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) { |
| 16032 | IrInstruction *target_value_ptr = instruction->target_value_ptr->child; |
| 16351 | 16033 | if (type_is_invalid(target_value_ptr->value.type)) |
| 16352 | | return ira->codegen->builtin_types.entry_invalid; |
| 16034 | return ira->codegen->invalid_instruction; |
| 16353 | 16035 | |
| 16354 | | IrInstruction *prong_value = instruction->prong_value->other; |
| 16036 | IrInstruction *prong_value = instruction->prong_value->child; |
| 16355 | 16037 | if (type_is_invalid(prong_value->value.type)) |
| 16356 | | return ira->codegen->builtin_types.entry_invalid; |
| 16038 | return ira->codegen->invalid_instruction; |
| 16357 | 16039 | |
| 16358 | 16040 | assert(target_value_ptr->value.type->id == ZigTypeIdPointer); |
| 16359 | 16041 | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 16360 | 16042 | if (target_type->id == ZigTypeIdUnion) { |
| 16361 | 16043 | ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad); |
| 16362 | 16044 | if (!prong_val) |
| 16363 | | return ira->codegen->builtin_types.entry_invalid; |
| 16045 | return ira->codegen->invalid_instruction; |
| 16364 | 16046 | |
| 16365 | 16047 | assert(prong_value->value.type->id == ZigTypeIdEnum); |
| 16366 | 16048 | TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag); |
| ... | ... | @@ -16368,43 +16050,46 @@ static ZigType *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionS |
| 16368 | 16050 | if (instr_is_comptime(target_value_ptr)) { |
| 16369 | 16051 | ConstExprValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad); |
| 16370 | 16052 | if (!target_value_ptr) |
| 16371 | | return ira->codegen->builtin_types.entry_invalid; |
| 16053 | return ira->codegen->invalid_instruction; |
| 16372 | 16054 | |
| 16373 | 16055 | ConstExprValue *pointee_val = ir_const_ptr_pointee(ira, target_val_ptr, instruction->base.source_node); |
| 16374 | 16056 | if (pointee_val == nullptr) |
| 16375 | | return ira->codegen->builtin_types.entry_invalid; |
| 16057 | return ira->codegen->invalid_instruction; |
| 16376 | 16058 | |
| 16377 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 16059 | IrInstruction *result = ir_const(ira, &instruction->base, |
| 16060 | get_pointer_to_type(ira->codegen, field->type_entry, |
| 16061 | target_val_ptr->type->data.pointer.is_const)); |
| 16062 | ConstExprValue *out_val = &result->value; |
| 16378 | 16063 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 16379 | 16064 | out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut; |
| 16380 | 16065 | out_val->data.x_ptr.data.ref.pointee = pointee_val->data.x_union.payload; |
| 16381 | | return get_pointer_to_type(ira->codegen, field->type_entry, target_val_ptr->type->data.pointer.is_const); |
| 16066 | return result; |
| 16382 | 16067 | } |
| 16383 | 16068 | |
| 16384 | | ir_build_union_field_ptr_from(&ira->new_irb, &instruction->base, target_value_ptr, field); |
| 16385 | | return get_pointer_to_type(ira->codegen, field->type_entry, |
| 16069 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, |
| 16070 | instruction->base.scope, instruction->base.source_node, target_value_ptr, field); |
| 16071 | result->value.type = get_pointer_to_type(ira->codegen, field->type_entry, |
| 16386 | 16072 | target_value_ptr->value.type->data.pointer.is_const); |
| 16073 | return result; |
| 16387 | 16074 | } else { |
| 16388 | 16075 | ir_add_error(ira, &instruction->base, |
| 16389 | 16076 | buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name))); |
| 16390 | | return ira->codegen->builtin_types.entry_invalid; |
| 16077 | return ira->codegen->invalid_instruction; |
| 16391 | 16078 | } |
| 16392 | 16079 | } |
| 16393 | 16080 | |
| 16394 | | static ZigType *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) { |
| 16395 | | IrInstruction *value = instruction->value->other; |
| 16396 | | IrInstruction *new_instruction = ir_analyze_union_tag(ira, &instruction->base, value); |
| 16397 | | ir_link_new_instruction(new_instruction, &instruction->base); |
| 16398 | | return new_instruction->value.type; |
| 16081 | static IrInstruction *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) { |
| 16082 | IrInstruction *value = instruction->value->child; |
| 16083 | return ir_analyze_union_tag(ira, &instruction->base, value); |
| 16399 | 16084 | } |
| 16400 | 16085 | |
| 16401 | | static ZigType *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) { |
| 16086 | static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) { |
| 16402 | 16087 | Error err; |
| 16403 | 16088 | |
| 16404 | | IrInstruction *name_value = import_instruction->name->other; |
| 16089 | IrInstruction *name_value = import_instruction->name->child; |
| 16405 | 16090 | Buf *import_target_str = ir_resolve_str(ira, name_value); |
| 16406 | 16091 | if (!import_target_str) |
| 16407 | | return ira->codegen->builtin_types.entry_invalid; |
| 16092 | return ira->codegen->invalid_instruction; |
| 16408 | 16093 | |
| 16409 | 16094 | AstNode *source_node = import_instruction->base.source_node; |
| 16410 | 16095 | ImportTableEntry *import = source_node->owner; |
| ... | ... | @@ -16439,20 +16124,21 @@ static ZigType *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImpor |
| 16439 | 16124 | |
| 16440 | 16125 | auto import_entry = ira->codegen->import_table.maybe_get(resolved_path); |
| 16441 | 16126 | if (import_entry) { |
| 16442 | | ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base); |
| 16443 | | out_val->data.x_import = import_entry->value; |
| 16444 | | return ira->codegen->builtin_types.entry_namespace; |
| 16127 | IrInstruction *result = ir_const(ira, &import_instruction->base, |
| 16128 | ira->codegen->builtin_types.entry_namespace); |
| 16129 | result->value.data.x_import = import_entry->value; |
| 16130 | return result; |
| 16445 | 16131 | } |
| 16446 | 16132 | |
| 16447 | 16133 | if ((err = file_fetch(ira->codegen, resolved_path, import_code))) { |
| 16448 | 16134 | if (err == ErrorFileNotFound) { |
| 16449 | 16135 | ir_add_error_node(ira, source_node, |
| 16450 | 16136 | buf_sprintf("unable to find '%s'", buf_ptr(import_target_path))); |
| 16451 | | return ira->codegen->builtin_types.entry_invalid; |
| 16137 | return ira->codegen->invalid_instruction; |
| 16452 | 16138 | } else { |
| 16453 | 16139 | ir_add_error_node(ira, source_node, |
| 16454 | 16140 | buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err))); |
| 16455 | | return ira->codegen->builtin_types.entry_invalid; |
| 16141 | return ira->codegen->invalid_instruction; |
| 16456 | 16142 | } |
| 16457 | 16143 | } |
| 16458 | 16144 | |
| ... | ... | @@ -16460,27 +16146,26 @@ static ZigType *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImpor |
| 16460 | 16146 | |
| 16461 | 16147 | scan_import(ira->codegen, target_import); |
| 16462 | 16148 | |
| 16463 | | ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base); |
| 16464 | | out_val->data.x_import = target_import; |
| 16465 | | return ira->codegen->builtin_types.entry_namespace; |
| 16466 | | |
| 16149 | IrInstruction *result = ir_const(ira, &import_instruction->base, ira->codegen->builtin_types.entry_namespace); |
| 16150 | result->value.data.x_import = target_import; |
| 16151 | return result; |
| 16467 | 16152 | } |
| 16468 | 16153 | |
| 16469 | | static ZigType *ir_analyze_instruction_array_len(IrAnalyze *ira, |
| 16154 | static IrInstruction *ir_analyze_instruction_array_len(IrAnalyze *ira, |
| 16470 | 16155 | IrInstructionArrayLen *array_len_instruction) |
| 16471 | 16156 | { |
| 16472 | | IrInstruction *array_value = array_len_instruction->array_value->other; |
| 16157 | IrInstruction *array_value = array_len_instruction->array_value->child; |
| 16473 | 16158 | ZigType *type_entry = array_value->value.type; |
| 16474 | 16159 | if (type_is_invalid(type_entry)) { |
| 16475 | | return ira->codegen->builtin_types.entry_invalid; |
| 16160 | return ira->codegen->invalid_instruction; |
| 16476 | 16161 | } else if (type_entry->id == ZigTypeIdArray) { |
| 16477 | | return ir_analyze_const_usize(ira, &array_len_instruction->base, |
| 16162 | return ir_const_usize(ira, &array_len_instruction->base, |
| 16478 | 16163 | type_entry->data.array.len); |
| 16479 | 16164 | } else if (is_slice(type_entry)) { |
| 16480 | 16165 | if (array_value->value.special != ConstValSpecialRuntime) { |
| 16481 | 16166 | ConstExprValue *len_val = &array_value->value.data.x_struct.fields[slice_len_index]; |
| 16482 | 16167 | if (len_val->special != ConstValSpecialRuntime) { |
| 16483 | | return ir_analyze_const_usize(ira, &array_len_instruction->base, |
| 16168 | return ir_const_usize(ira, &array_len_instruction->base, |
| 16484 | 16169 | bigint_as_unsigned(&len_val->data.x_bigint)); |
| 16485 | 16170 | } |
| 16486 | 16171 | } |
| ... | ... | @@ -16488,57 +16173,61 @@ static ZigType *ir_analyze_instruction_array_len(IrAnalyze *ira, |
| 16488 | 16173 | IrInstruction *len_ptr = ir_build_struct_field_ptr(&ira->new_irb, array_len_instruction->base.scope, |
| 16489 | 16174 | array_len_instruction->base.source_node, array_value, field); |
| 16490 | 16175 | len_ptr->value.type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_usize, true); |
| 16491 | | ir_build_load_ptr_from(&ira->new_irb, &array_len_instruction->base, len_ptr); |
| 16492 | | return ira->codegen->builtin_types.entry_usize; |
| 16176 | IrInstruction *result = ir_build_load_ptr(&ira->new_irb, |
| 16177 | array_len_instruction->base.scope, array_len_instruction->base.source_node, len_ptr); |
| 16178 | result->value.type = ira->codegen->builtin_types.entry_usize; |
| 16179 | return result; |
| 16493 | 16180 | } else { |
| 16494 | 16181 | ir_add_error_node(ira, array_len_instruction->base.source_node, |
| 16495 | 16182 | buf_sprintf("type '%s' has no field 'len'", buf_ptr(&array_value->value.type->name))); |
| 16496 | | return ira->codegen->builtin_types.entry_invalid; |
| 16183 | return ira->codegen->invalid_instruction; |
| 16497 | 16184 | } |
| 16498 | 16185 | } |
| 16499 | 16186 | |
| 16500 | | static ZigType *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) { |
| 16501 | | IrInstruction *value = ref_instruction->value->other; |
| 16502 | | return ir_analyze_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile); |
| 16187 | static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) { |
| 16188 | IrInstruction *value = ref_instruction->value->child; |
| 16189 | if (type_is_invalid(value->value.type)) |
| 16190 | return ira->codegen->invalid_instruction; |
| 16191 | return ir_get_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile); |
| 16503 | 16192 | } |
| 16504 | 16193 | |
| 16505 | | static ZigType *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruction *instruction, |
| 16194 | static IrInstruction *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruction *instruction, |
| 16506 | 16195 | ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) |
| 16507 | 16196 | { |
| 16508 | 16197 | Error err; |
| 16509 | 16198 | assert(container_type->id == ZigTypeIdUnion); |
| 16510 | 16199 | |
| 16511 | 16200 | if ((err = ensure_complete_type(ira->codegen, container_type))) |
| 16512 | | return ira->codegen->builtin_types.entry_invalid; |
| 16201 | return ira->codegen->invalid_instruction; |
| 16513 | 16202 | |
| 16514 | 16203 | if (instr_field_count != 1) { |
| 16515 | 16204 | ir_add_error(ira, instruction, |
| 16516 | 16205 | buf_sprintf("union initialization expects exactly one field")); |
| 16517 | | return ira->codegen->builtin_types.entry_invalid; |
| 16206 | return ira->codegen->invalid_instruction; |
| 16518 | 16207 | } |
| 16519 | 16208 | |
| 16520 | 16209 | IrInstructionContainerInitFieldsField *field = &fields[0]; |
| 16521 | | IrInstruction *field_value = field->value->other; |
| 16210 | IrInstruction *field_value = field->value->child; |
| 16522 | 16211 | if (type_is_invalid(field_value->value.type)) |
| 16523 | | return ira->codegen->builtin_types.entry_invalid; |
| 16212 | return ira->codegen->invalid_instruction; |
| 16524 | 16213 | |
| 16525 | 16214 | TypeUnionField *type_field = find_union_type_field(container_type, field->name); |
| 16526 | 16215 | if (!type_field) { |
| 16527 | 16216 | ir_add_error_node(ira, field->source_node, |
| 16528 | 16217 | buf_sprintf("no member named '%s' in union '%s'", |
| 16529 | 16218 | buf_ptr(field->name), buf_ptr(&container_type->name))); |
| 16530 | | return ira->codegen->builtin_types.entry_invalid; |
| 16219 | return ira->codegen->invalid_instruction; |
| 16531 | 16220 | } |
| 16532 | 16221 | |
| 16533 | 16222 | if (type_is_invalid(type_field->type_entry)) |
| 16534 | | return ira->codegen->builtin_types.entry_invalid; |
| 16223 | return ira->codegen->invalid_instruction; |
| 16535 | 16224 | |
| 16536 | 16225 | IrInstruction *casted_field_value = ir_implicit_cast(ira, field_value, type_field->type_entry); |
| 16537 | 16226 | if (casted_field_value == ira->codegen->invalid_instruction) |
| 16538 | | return ira->codegen->builtin_types.entry_invalid; |
| 16227 | return ira->codegen->invalid_instruction; |
| 16539 | 16228 | |
| 16540 | 16229 | if ((err = type_resolve(ira->codegen, casted_field_value->value.type, ResolveStatusZeroBitsKnown))) |
| 16541 | | return ira->codegen->builtin_types.entry_invalid; |
| 16230 | return ira->codegen->invalid_instruction; |
| 16542 | 16231 | |
| 16543 | 16232 | bool is_comptime = ir_should_inline(ira->new_irb.exec, instruction->scope); |
| 16544 | 16233 | if (is_comptime || casted_field_value->value.special != ConstValSpecialRuntime || |
| ... | ... | @@ -16546,9 +16235,10 @@ static ZigType *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruc |
| 16546 | 16235 | { |
| 16547 | 16236 | ConstExprValue *field_val = ir_resolve_const(ira, casted_field_value, UndefOk); |
| 16548 | 16237 | if (!field_val) |
| 16549 | | return ira->codegen->builtin_types.entry_invalid; |
| 16238 | return ira->codegen->invalid_instruction; |
| 16550 | 16239 | |
| 16551 | | ConstExprValue *out_val = ir_build_const_from(ira, instruction); |
| 16240 | IrInstruction *result = ir_const(ira, instruction, container_type); |
| 16241 | ConstExprValue *out_val = &result->value; |
| 16552 | 16242 | out_val->data.x_union.payload = field_val; |
| 16553 | 16243 | out_val->data.x_union.tag = type_field->enum_field->value; |
| 16554 | 16244 | |
| ... | ... | @@ -16558,17 +16248,18 @@ static ZigType *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruc |
| 16558 | 16248 | parent->data.p_union.union_val = out_val; |
| 16559 | 16249 | } |
| 16560 | 16250 | |
| 16561 | | return container_type; |
| 16251 | return result; |
| 16562 | 16252 | } |
| 16563 | 16253 | |
| 16564 | | IrInstruction *new_instruction = ir_build_union_init_from(&ira->new_irb, instruction, |
| 16254 | IrInstruction *new_instruction = ir_build_union_init(&ira->new_irb, |
| 16255 | instruction->scope, instruction->source_node, |
| 16565 | 16256 | container_type, type_field, casted_field_value); |
| 16566 | | |
| 16257 | new_instruction->value.type = container_type; |
| 16567 | 16258 | ir_add_alloca(ira, new_instruction, container_type); |
| 16568 | | return container_type; |
| 16259 | return new_instruction; |
| 16569 | 16260 | } |
| 16570 | 16261 | |
| 16571 | | static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction, |
| 16262 | static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction, |
| 16572 | 16263 | ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) |
| 16573 | 16264 | { |
| 16574 | 16265 | Error err; |
| ... | ... | @@ -16579,11 +16270,11 @@ static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction * |
| 16579 | 16270 | ir_add_error(ira, instruction, |
| 16580 | 16271 | buf_sprintf("type '%s' does not support struct initialization syntax", |
| 16581 | 16272 | buf_ptr(&container_type->name))); |
| 16582 | | return ira->codegen->builtin_types.entry_invalid; |
| 16273 | return ira->codegen->invalid_instruction; |
| 16583 | 16274 | } |
| 16584 | 16275 | |
| 16585 | 16276 | if ((err = ensure_complete_type(ira->codegen, container_type))) |
| 16586 | | return ira->codegen->builtin_types.entry_invalid; |
| 16277 | return ira->codegen->invalid_instruction; |
| 16587 | 16278 | |
| 16588 | 16279 | size_t actual_field_count = container_type->data.structure.src_field_count; |
| 16589 | 16280 | |
| ... | ... | @@ -16602,31 +16293,31 @@ static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction * |
| 16602 | 16293 | for (size_t i = 0; i < instr_field_count; i += 1) { |
| 16603 | 16294 | IrInstructionContainerInitFieldsField *field = &fields[i]; |
| 16604 | 16295 | |
| 16605 | | IrInstruction *field_value = field->value->other; |
| 16296 | IrInstruction *field_value = field->value->child; |
| 16606 | 16297 | if (type_is_invalid(field_value->value.type)) |
| 16607 | | return ira->codegen->builtin_types.entry_invalid; |
| 16298 | return ira->codegen->invalid_instruction; |
| 16608 | 16299 | |
| 16609 | 16300 | TypeStructField *type_field = find_struct_type_field(container_type, field->name); |
| 16610 | 16301 | if (!type_field) { |
| 16611 | 16302 | ir_add_error_node(ira, field->source_node, |
| 16612 | 16303 | buf_sprintf("no member named '%s' in struct '%s'", |
| 16613 | 16304 | buf_ptr(field->name), buf_ptr(&container_type->name))); |
| 16614 | | return ira->codegen->builtin_types.entry_invalid; |
| 16305 | return ira->codegen->invalid_instruction; |
| 16615 | 16306 | } |
| 16616 | 16307 | |
| 16617 | 16308 | if (type_is_invalid(type_field->type_entry)) |
| 16618 | | return ira->codegen->builtin_types.entry_invalid; |
| 16309 | return ira->codegen->invalid_instruction; |
| 16619 | 16310 | |
| 16620 | 16311 | IrInstruction *casted_field_value = ir_implicit_cast(ira, field_value, type_field->type_entry); |
| 16621 | 16312 | if (casted_field_value == ira->codegen->invalid_instruction) |
| 16622 | | return ira->codegen->builtin_types.entry_invalid; |
| 16313 | return ira->codegen->invalid_instruction; |
| 16623 | 16314 | |
| 16624 | 16315 | size_t field_index = type_field->src_index; |
| 16625 | 16316 | AstNode *existing_assign_node = field_assign_nodes[field_index]; |
| 16626 | 16317 | if (existing_assign_node) { |
| 16627 | 16318 | ErrorMsg *msg = ir_add_error_node(ira, field->source_node, buf_sprintf("duplicate field")); |
| 16628 | 16319 | add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here")); |
| 16629 | | return ira->codegen->builtin_types.entry_invalid; |
| 16320 | return ira->codegen->invalid_instruction; |
| 16630 | 16321 | } |
| 16631 | 16322 | field_assign_nodes[field_index] = field->source_node; |
| 16632 | 16323 | |
| ... | ... | @@ -16637,7 +16328,7 @@ static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction * |
| 16637 | 16328 | if (is_comptime || casted_field_value->value.special != ConstValSpecialRuntime) { |
| 16638 | 16329 | ConstExprValue *field_val = ir_resolve_const(ira, casted_field_value, UndefOk); |
| 16639 | 16330 | if (!field_val) |
| 16640 | | return ira->codegen->builtin_types.entry_invalid; |
| 16331 | return ira->codegen->invalid_instruction; |
| 16641 | 16332 | |
| 16642 | 16333 | copy_const_val(&const_val.data.x_struct.fields[field_index], field_val, true); |
| 16643 | 16334 | } else { |
| ... | ... | @@ -16656,11 +16347,14 @@ static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction * |
| 16656 | 16347 | } |
| 16657 | 16348 | } |
| 16658 | 16349 | if (any_missing) |
| 16659 | | return ira->codegen->builtin_types.entry_invalid; |
| 16350 | return ira->codegen->invalid_instruction; |
| 16660 | 16351 | |
| 16661 | 16352 | if (const_val.special == ConstValSpecialStatic) { |
| 16662 | | ConstExprValue *out_val = ir_build_const_from(ira, instruction); |
| 16353 | IrInstruction *result = ir_const(ira, instruction, nullptr); |
| 16354 | ConstExprValue *out_val = &result->value; |
| 16355 | // TODO copy_const_val? |
| 16663 | 16356 | *out_val = const_val; |
| 16357 | result->value.type = container_type; |
| 16664 | 16358 | |
| 16665 | 16359 | for (size_t i = 0; i < instr_field_count; i += 1) { |
| 16666 | 16360 | ConstExprValue *field_val = &out_val->data.x_struct.fields[i]; |
| ... | ... | @@ -16672,34 +16366,35 @@ static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction * |
| 16672 | 16366 | } |
| 16673 | 16367 | } |
| 16674 | 16368 | |
| 16675 | | return container_type; |
| 16369 | return result; |
| 16676 | 16370 | } |
| 16677 | 16371 | |
| 16678 | 16372 | if (is_comptime) { |
| 16679 | 16373 | ir_add_error_node(ira, first_non_const_instruction->source_node, |
| 16680 | 16374 | buf_sprintf("unable to evaluate constant expression")); |
| 16681 | | return ira->codegen->builtin_types.entry_invalid; |
| 16375 | return ira->codegen->invalid_instruction; |
| 16682 | 16376 | } |
| 16683 | 16377 | |
| 16684 | | IrInstruction *new_instruction = ir_build_struct_init_from(&ira->new_irb, instruction, |
| 16378 | IrInstruction *new_instruction = ir_build_struct_init(&ira->new_irb, |
| 16379 | instruction->scope, instruction->source_node, |
| 16685 | 16380 | container_type, actual_field_count, new_fields); |
| 16686 | | |
| 16381 | new_instruction->value.type = container_type; |
| 16687 | 16382 | ir_add_alloca(ira, new_instruction, container_type); |
| 16688 | | return container_type; |
| 16383 | return new_instruction; |
| 16689 | 16384 | } |
| 16690 | 16385 | |
| 16691 | | static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16386 | static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16692 | 16387 | IrInstructionContainerInitList *instruction) |
| 16693 | 16388 | { |
| 16694 | | IrInstruction *container_type_value = instruction->container_type->other; |
| 16389 | IrInstruction *container_type_value = instruction->container_type->child; |
| 16695 | 16390 | if (type_is_invalid(container_type_value->value.type)) |
| 16696 | | return ira->codegen->builtin_types.entry_invalid; |
| 16391 | return ira->codegen->invalid_instruction; |
| 16697 | 16392 | |
| 16698 | 16393 | size_t elem_count = instruction->item_count; |
| 16699 | 16394 | if (container_type_value->value.type->id == ZigTypeIdMetaType) { |
| 16700 | 16395 | ZigType *container_type = ir_resolve_type(ira, container_type_value); |
| 16701 | 16396 | if (type_is_invalid(container_type)) |
| 16702 | | return ira->codegen->builtin_types.entry_invalid; |
| 16397 | return ira->codegen->invalid_instruction; |
| 16703 | 16398 | |
| 16704 | 16399 | if (container_type->id == ZigTypeIdStruct && !is_slice(container_type) && elem_count == 0) { |
| 16705 | 16400 | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, |
| ... | ... | @@ -16715,7 +16410,7 @@ static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16715 | 16410 | ir_add_error(ira, &instruction->base, |
| 16716 | 16411 | buf_sprintf("expected %s literal, found %s literal", |
| 16717 | 16412 | buf_ptr(&container_type->name), buf_ptr(&literal_type->name))); |
| 16718 | | return ira->codegen->builtin_types.entry_invalid; |
| 16413 | return ira->codegen->invalid_instruction; |
| 16719 | 16414 | } |
| 16720 | 16415 | } else { |
| 16721 | 16416 | ZigType *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry; |
| ... | ... | @@ -16737,13 +16432,13 @@ static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16737 | 16432 | IrInstruction *first_non_const_instruction = nullptr; |
| 16738 | 16433 | |
| 16739 | 16434 | for (size_t i = 0; i < elem_count; i += 1) { |
| 16740 | | IrInstruction *arg_value = instruction->items[i]->other; |
| 16435 | IrInstruction *arg_value = instruction->items[i]->child; |
| 16741 | 16436 | if (type_is_invalid(arg_value->value.type)) |
| 16742 | | return ira->codegen->builtin_types.entry_invalid; |
| 16437 | return ira->codegen->invalid_instruction; |
| 16743 | 16438 | |
| 16744 | 16439 | IrInstruction *casted_arg = ir_implicit_cast(ira, arg_value, child_type); |
| 16745 | 16440 | if (casted_arg == ira->codegen->invalid_instruction) |
| 16746 | | return ira->codegen->builtin_types.entry_invalid; |
| 16441 | return ira->codegen->invalid_instruction; |
| 16747 | 16442 | |
| 16748 | 16443 | new_items[i] = casted_arg; |
| 16749 | 16444 | |
| ... | ... | @@ -16751,7 +16446,7 @@ static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16751 | 16446 | if (is_comptime || casted_arg->value.special != ConstValSpecialRuntime) { |
| 16752 | 16447 | ConstExprValue *elem_val = ir_resolve_const(ira, casted_arg, UndefBad); |
| 16753 | 16448 | if (!elem_val) |
| 16754 | | return ira->codegen->builtin_types.entry_invalid; |
| 16449 | return ira->codegen->invalid_instruction; |
| 16755 | 16450 | |
| 16756 | 16451 | copy_const_val(&const_val.data.x_array.data.s_none.elements[i], elem_val, true); |
| 16757 | 16452 | } else { |
| ... | ... | @@ -16762,8 +16457,11 @@ static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16762 | 16457 | } |
| 16763 | 16458 | |
| 16764 | 16459 | if (const_val.special == ConstValSpecialStatic) { |
| 16765 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 16460 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 16461 | ConstExprValue *out_val = &result->value; |
| 16462 | // TODO copy_const_val? |
| 16766 | 16463 | *out_val = const_val; |
| 16464 | result->value.type = fixed_size_array_type; |
| 16767 | 16465 | for (size_t i = 0; i < elem_count; i += 1) { |
| 16768 | 16466 | ConstExprValue *elem_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 16769 | 16467 | ConstParent *parent = get_const_val_parent(ira->codegen, elem_val); |
| ... | ... | @@ -16773,70 +16471,73 @@ static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 16773 | 16471 | parent->data.p_array.elem_index = i; |
| 16774 | 16472 | } |
| 16775 | 16473 | } |
| 16776 | | return fixed_size_array_type; |
| 16474 | return result; |
| 16777 | 16475 | } |
| 16778 | 16476 | |
| 16779 | 16477 | if (is_comptime) { |
| 16780 | 16478 | ir_add_error_node(ira, first_non_const_instruction->source_node, |
| 16781 | 16479 | buf_sprintf("unable to evaluate constant expression")); |
| 16782 | | return ira->codegen->builtin_types.entry_invalid; |
| 16480 | return ira->codegen->invalid_instruction; |
| 16783 | 16481 | } |
| 16784 | 16482 | |
| 16785 | | IrInstruction *new_instruction = ir_build_container_init_list_from(&ira->new_irb, &instruction->base, |
| 16483 | IrInstruction *new_instruction = ir_build_container_init_list(&ira->new_irb, |
| 16484 | instruction->base.scope, instruction->base.source_node, |
| 16786 | 16485 | container_type_value, elem_count, new_items); |
| 16486 | new_instruction->value.type = fixed_size_array_type; |
| 16787 | 16487 | ir_add_alloca(ira, new_instruction, fixed_size_array_type); |
| 16788 | | return fixed_size_array_type; |
| 16488 | return new_instruction; |
| 16789 | 16489 | } else if (container_type->id == ZigTypeIdVoid) { |
| 16790 | 16490 | if (elem_count != 0) { |
| 16791 | 16491 | ir_add_error_node(ira, instruction->base.source_node, |
| 16792 | 16492 | buf_sprintf("void expression expects no arguments")); |
| 16793 | | return ira->codegen->builtin_types.entry_invalid; |
| 16493 | return ira->codegen->invalid_instruction; |
| 16794 | 16494 | } |
| 16795 | | return ir_analyze_void(ira, &instruction->base); |
| 16495 | return ir_const_void(ira, &instruction->base); |
| 16796 | 16496 | } else { |
| 16797 | 16497 | ir_add_error_node(ira, instruction->base.source_node, |
| 16798 | 16498 | buf_sprintf("type '%s' does not support array initialization", |
| 16799 | 16499 | buf_ptr(&container_type->name))); |
| 16800 | | return ira->codegen->builtin_types.entry_invalid; |
| 16500 | return ira->codegen->invalid_instruction; |
| 16801 | 16501 | } |
| 16802 | 16502 | } else { |
| 16803 | 16503 | ir_add_error(ira, container_type_value, |
| 16804 | 16504 | buf_sprintf("expected type, found '%s' value", buf_ptr(&container_type_value->value.type->name))); |
| 16805 | | return ira->codegen->builtin_types.entry_invalid; |
| 16505 | return ira->codegen->invalid_instruction; |
| 16806 | 16506 | } |
| 16807 | 16507 | } |
| 16808 | 16508 | |
| 16809 | | static ZigType *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, IrInstructionContainerInitFields *instruction) { |
| 16810 | | IrInstruction *container_type_value = instruction->container_type->other; |
| 16509 | static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, IrInstructionContainerInitFields *instruction) { |
| 16510 | IrInstruction *container_type_value = instruction->container_type->child; |
| 16811 | 16511 | ZigType *container_type = ir_resolve_type(ira, container_type_value); |
| 16812 | 16512 | if (type_is_invalid(container_type)) |
| 16813 | | return ira->codegen->builtin_types.entry_invalid; |
| 16513 | return ira->codegen->invalid_instruction; |
| 16814 | 16514 | |
| 16815 | 16515 | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, |
| 16816 | 16516 | instruction->field_count, instruction->fields); |
| 16817 | 16517 | } |
| 16818 | 16518 | |
| 16819 | | static ZigType *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction, |
| 16519 | static IrInstruction *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction, |
| 16820 | 16520 | IrInstruction *target_type_value, bool is_max) |
| 16821 | 16521 | { |
| 16822 | 16522 | ZigType *target_type = ir_resolve_type(ira, target_type_value); |
| 16823 | 16523 | if (type_is_invalid(target_type)) |
| 16824 | | return ira->codegen->builtin_types.entry_invalid; |
| 16524 | return ira->codegen->invalid_instruction; |
| 16825 | 16525 | switch (target_type->id) { |
| 16826 | 16526 | case ZigTypeIdInvalid: |
| 16827 | 16527 | zig_unreachable(); |
| 16828 | 16528 | case ZigTypeIdInt: |
| 16829 | 16529 | { |
| 16830 | | ConstExprValue *out_val = ir_build_const_from(ira, source_instruction); |
| 16831 | | eval_min_max_value(ira->codegen, target_type, out_val, is_max); |
| 16832 | | return ira->codegen->builtin_types.entry_num_lit_int; |
| 16530 | IrInstruction *result = ir_const(ira, source_instruction, |
| 16531 | ira->codegen->builtin_types.entry_num_lit_int); |
| 16532 | eval_min_max_value(ira->codegen, target_type, &result->value, is_max); |
| 16533 | return result; |
| 16833 | 16534 | } |
| 16834 | 16535 | case ZigTypeIdBool: |
| 16835 | 16536 | case ZigTypeIdVoid: |
| 16836 | 16537 | { |
| 16837 | | ConstExprValue *out_val = ir_build_const_from(ira, source_instruction); |
| 16838 | | eval_min_max_value(ira->codegen, target_type, out_val, is_max); |
| 16839 | | return target_type; |
| 16538 | IrInstruction *result = ir_const(ira, source_instruction, target_type); |
| 16539 | eval_min_max_value(ira->codegen, target_type, &result->value, is_max); |
| 16540 | return result; |
| 16840 | 16541 | } |
| 16841 | 16542 | case ZigTypeIdEnum: |
| 16842 | 16543 | case ZigTypeIdFloat: |
| ... | ... | @@ -16865,31 +16566,31 @@ static ZigType *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruc |
| 16865 | 16566 | "no min value available for type '%s'"; |
| 16866 | 16567 | ir_add_error(ira, source_instruction, |
| 16867 | 16568 | buf_sprintf(err_format, buf_ptr(&target_type->name))); |
| 16868 | | return ira->codegen->builtin_types.entry_invalid; |
| 16569 | return ira->codegen->invalid_instruction; |
| 16869 | 16570 | } |
| 16870 | 16571 | } |
| 16871 | 16572 | zig_unreachable(); |
| 16872 | 16573 | } |
| 16873 | 16574 | |
| 16874 | | static ZigType *ir_analyze_instruction_min_value(IrAnalyze *ira, |
| 16575 | static IrInstruction *ir_analyze_instruction_min_value(IrAnalyze *ira, |
| 16875 | 16576 | IrInstructionMinValue *instruction) |
| 16876 | 16577 | { |
| 16877 | | return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, false); |
| 16578 | return ir_analyze_min_max(ira, &instruction->base, instruction->value->child, false); |
| 16878 | 16579 | } |
| 16879 | 16580 | |
| 16880 | | static ZigType *ir_analyze_instruction_max_value(IrAnalyze *ira, |
| 16581 | static IrInstruction *ir_analyze_instruction_max_value(IrAnalyze *ira, |
| 16881 | 16582 | IrInstructionMaxValue *instruction) |
| 16882 | 16583 | { |
| 16883 | | return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, true); |
| 16584 | return ir_analyze_min_max(ira, &instruction->base, instruction->value->child, true); |
| 16884 | 16585 | } |
| 16885 | 16586 | |
| 16886 | | static ZigType *ir_analyze_instruction_compile_err(IrAnalyze *ira, |
| 16587 | static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira, |
| 16887 | 16588 | IrInstructionCompileErr *instruction) |
| 16888 | 16589 | { |
| 16889 | | IrInstruction *msg_value = instruction->msg->other; |
| 16590 | IrInstruction *msg_value = instruction->msg->child; |
| 16890 | 16591 | Buf *msg_buf = ir_resolve_str(ira, msg_value); |
| 16891 | 16592 | if (!msg_buf) |
| 16892 | | return ira->codegen->builtin_types.entry_invalid; |
| 16593 | return ira->codegen->invalid_instruction; |
| 16893 | 16594 | |
| 16894 | 16595 | ErrorMsg *msg = ir_add_error(ira, &instruction->base, msg_buf); |
| 16895 | 16596 | size_t i = ira->codegen->tld_ref_source_node_stack.length; |
| ... | ... | @@ -16904,16 +16605,16 @@ static ZigType *ir_analyze_instruction_compile_err(IrAnalyze *ira, |
| 16904 | 16605 | } |
| 16905 | 16606 | } |
| 16906 | 16607 | |
| 16907 | | return ira->codegen->builtin_types.entry_invalid; |
| 16608 | return ira->codegen->invalid_instruction; |
| 16908 | 16609 | } |
| 16909 | 16610 | |
| 16910 | | static ZigType *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) { |
| 16611 | static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) { |
| 16911 | 16612 | Buf buf = BUF_INIT; |
| 16912 | 16613 | fprintf(stderr, "| "); |
| 16913 | 16614 | for (size_t i = 0; i < instruction->msg_count; i += 1) { |
| 16914 | | IrInstruction *msg = instruction->msg_list[i]->other; |
| 16615 | IrInstruction *msg = instruction->msg_list[i]->child; |
| 16915 | 16616 | if (type_is_invalid(msg->value.type)) |
| 16916 | | return ira->codegen->builtin_types.entry_invalid; |
| 16617 | return ira->codegen->invalid_instruction; |
| 16917 | 16618 | buf_resize(&buf, 0); |
| 16918 | 16619 | render_const_value(ira->codegen, &buf, &msg->value); |
| 16919 | 16620 | const char *comma_str = (i != 0) ? ", " : ""; |
| ... | ... | @@ -16925,18 +16626,17 @@ static ZigType *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstruction |
| 16925 | 16626 | // invalidate_exec to be called. |
| 16926 | 16627 | add_node_error(ira->codegen, instruction->base.source_node, buf_sprintf("found compile log statement")); |
| 16927 | 16628 | |
| 16928 | | ir_build_const_from(ira, &instruction->base); |
| 16929 | | return ira->codegen->builtin_types.entry_void; |
| 16629 | return ir_const_void(ira, &instruction->base); |
| 16930 | 16630 | } |
| 16931 | 16631 | |
| 16932 | | static ZigType *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) { |
| 16933 | | IrInstruction *value = instruction->value->other; |
| 16632 | static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) { |
| 16633 | IrInstruction *value = instruction->value->child; |
| 16934 | 16634 | if (type_is_invalid(value->value.type)) |
| 16935 | | return ira->codegen->builtin_types.entry_invalid; |
| 16635 | return ira->codegen->invalid_instruction; |
| 16936 | 16636 | |
| 16937 | 16637 | IrInstruction *casted_value = ir_implicit_cast(ira, value, value->value.type); |
| 16938 | 16638 | if (type_is_invalid(casted_value->value.type)) |
| 16939 | | return ira->codegen->builtin_types.entry_invalid; |
| 16639 | return ira->codegen->invalid_instruction; |
| 16940 | 16640 | |
| 16941 | 16641 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 16942 | 16642 | true, false, PtrLenUnknown, 0, 0, 0); |
| ... | ... | @@ -16947,84 +16647,87 @@ static ZigType *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErr |
| 16947 | 16647 | ConstExprValue *array_val = create_const_str_lit(ira->codegen, &err->name); |
| 16948 | 16648 | err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true); |
| 16949 | 16649 | } |
| 16950 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 16951 | | copy_const_val(out_val, err->cached_error_name_val, true); |
| 16952 | | return str_type; |
| 16650 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 16651 | copy_const_val(&result->value, err->cached_error_name_val, true); |
| 16652 | result->value.type = str_type; |
| 16653 | return result; |
| 16953 | 16654 | } |
| 16954 | 16655 | |
| 16955 | 16656 | ira->codegen->generate_error_name_table = true; |
| 16956 | | ir_build_err_name_from(&ira->new_irb, &instruction->base, value); |
| 16957 | | return str_type; |
| 16657 | |
| 16658 | IrInstruction *result = ir_build_err_name(&ira->new_irb, |
| 16659 | instruction->base.scope, instruction->base.source_node, value); |
| 16660 | result->value.type = str_type; |
| 16661 | return result; |
| 16958 | 16662 | } |
| 16959 | 16663 | |
| 16960 | | static ZigType *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) { |
| 16664 | static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) { |
| 16961 | 16665 | Error err; |
| 16962 | | IrInstruction *target = instruction->target->other; |
| 16666 | IrInstruction *target = instruction->target->child; |
| 16963 | 16667 | if (type_is_invalid(target->value.type)) |
| 16964 | | return ira->codegen->builtin_types.entry_invalid; |
| 16668 | return ira->codegen->invalid_instruction; |
| 16965 | 16669 | |
| 16966 | 16670 | assert(target->value.type->id == ZigTypeIdEnum); |
| 16967 | 16671 | |
| 16968 | 16672 | if (instr_is_comptime(target)) { |
| 16969 | 16673 | if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown))) |
| 16970 | | return ira->codegen->builtin_types.entry_invalid; |
| 16674 | return ira->codegen->invalid_instruction; |
| 16971 | 16675 | TypeEnumField *field = find_enum_field_by_tag(target->value.type, &target->value.data.x_bigint); |
| 16972 | 16676 | ConstExprValue *array_val = create_const_str_lit(ira->codegen, field->name); |
| 16973 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 16974 | | init_const_slice(ira->codegen, out_val, array_val, 0, buf_len(field->name), true); |
| 16975 | | return out_val->type; |
| 16677 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 16678 | init_const_slice(ira->codegen, &result->value, array_val, 0, buf_len(field->name), true); |
| 16679 | return result; |
| 16976 | 16680 | } |
| 16977 | 16681 | |
| 16978 | 16682 | IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope, |
| 16979 | 16683 | instruction->base.source_node, target); |
| 16980 | | ir_link_new_instruction(result, &instruction->base); |
| 16981 | 16684 | ZigType *u8_ptr_type = get_pointer_to_type_extra( |
| 16982 | 16685 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 16983 | 16686 | true, false, PtrLenUnknown, |
| 16984 | 16687 | 0, 0, 0); |
| 16985 | 16688 | result->value.type = get_slice_type(ira->codegen, u8_ptr_type); |
| 16986 | | return result->value.type; |
| 16689 | return result; |
| 16987 | 16690 | } |
| 16988 | 16691 | |
| 16989 | | static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 16692 | static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 16990 | 16693 | IrInstructionFieldParentPtr *instruction) |
| 16991 | 16694 | { |
| 16992 | 16695 | Error err; |
| 16993 | | IrInstruction *type_value = instruction->type_value->other; |
| 16696 | IrInstruction *type_value = instruction->type_value->child; |
| 16994 | 16697 | ZigType *container_type = ir_resolve_type(ira, type_value); |
| 16995 | 16698 | if (type_is_invalid(container_type)) |
| 16996 | | return ira->codegen->builtin_types.entry_invalid; |
| 16699 | return ira->codegen->invalid_instruction; |
| 16997 | 16700 | |
| 16998 | | IrInstruction *field_name_value = instruction->field_name->other; |
| 16701 | IrInstruction *field_name_value = instruction->field_name->child; |
| 16999 | 16702 | Buf *field_name = ir_resolve_str(ira, field_name_value); |
| 17000 | 16703 | if (!field_name) |
| 17001 | | return ira->codegen->builtin_types.entry_invalid; |
| 16704 | return ira->codegen->invalid_instruction; |
| 17002 | 16705 | |
| 17003 | | IrInstruction *field_ptr = instruction->field_ptr->other; |
| 16706 | IrInstruction *field_ptr = instruction->field_ptr->child; |
| 17004 | 16707 | if (type_is_invalid(field_ptr->value.type)) |
| 17005 | | return ira->codegen->builtin_types.entry_invalid; |
| 16708 | return ira->codegen->invalid_instruction; |
| 17006 | 16709 | |
| 17007 | 16710 | if (container_type->id != ZigTypeIdStruct) { |
| 17008 | 16711 | ir_add_error(ira, type_value, |
| 17009 | 16712 | buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); |
| 17010 | | return ira->codegen->builtin_types.entry_invalid; |
| 16713 | return ira->codegen->invalid_instruction; |
| 17011 | 16714 | } |
| 17012 | 16715 | |
| 17013 | 16716 | if ((err = ensure_complete_type(ira->codegen, container_type))) |
| 17014 | | return ira->codegen->builtin_types.entry_invalid; |
| 16717 | return ira->codegen->invalid_instruction; |
| 17015 | 16718 | |
| 17016 | 16719 | TypeStructField *field = find_struct_type_field(container_type, field_name); |
| 17017 | 16720 | if (field == nullptr) { |
| 17018 | 16721 | ir_add_error(ira, field_name_value, |
| 17019 | 16722 | buf_sprintf("struct '%s' has no field '%s'", |
| 17020 | 16723 | buf_ptr(&container_type->name), buf_ptr(field_name))); |
| 17021 | | return ira->codegen->builtin_types.entry_invalid; |
| 16724 | return ira->codegen->invalid_instruction; |
| 17022 | 16725 | } |
| 17023 | 16726 | |
| 17024 | 16727 | if (field_ptr->value.type->id != ZigTypeIdPointer) { |
| 17025 | 16728 | ir_add_error(ira, field_ptr, |
| 17026 | 16729 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name))); |
| 17027 | | return ira->codegen->builtin_types.entry_invalid; |
| 16730 | return ira->codegen->invalid_instruction; |
| 17028 | 16731 | } |
| 17029 | 16732 | |
| 17030 | 16733 | bool is_packed = (container_type->data.structure.layout == ContainerLayoutPacked); |
| ... | ... | @@ -17038,7 +16741,7 @@ static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 17038 | 16741 | field_ptr_align, 0, 0); |
| 17039 | 16742 | IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type); |
| 17040 | 16743 | if (type_is_invalid(casted_field_ptr->value.type)) |
| 17041 | | return ira->codegen->builtin_types.entry_invalid; |
| 16744 | return ira->codegen->invalid_instruction; |
| 17042 | 16745 | |
| 17043 | 16746 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type, |
| 17044 | 16747 | casted_field_ptr->value.type->data.pointer.is_const, |
| ... | ... | @@ -17049,11 +16752,11 @@ static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 17049 | 16752 | if (instr_is_comptime(casted_field_ptr)) { |
| 17050 | 16753 | ConstExprValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad); |
| 17051 | 16754 | if (!field_ptr_val) |
| 17052 | | return ira->codegen->builtin_types.entry_invalid; |
| 16755 | return ira->codegen->invalid_instruction; |
| 17053 | 16756 | |
| 17054 | 16757 | if (field_ptr_val->data.x_ptr.special != ConstPtrSpecialBaseStruct) { |
| 17055 | 16758 | ir_add_error(ira, field_ptr, buf_sprintf("pointer value not based on parent struct")); |
| 17056 | | return ira->codegen->builtin_types.entry_invalid; |
| 16759 | return ira->codegen->invalid_instruction; |
| 17057 | 16760 | } |
| 17058 | 16761 | |
| 17059 | 16762 | size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index; |
| ... | ... | @@ -17062,21 +16765,21 @@ static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 17062 | 16765 | buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'", |
| 17063 | 16766 | buf_ptr(field->name), field->src_index, |
| 17064 | 16767 | ptr_field_index, buf_ptr(&container_type->name))); |
| 17065 | | return ira->codegen->builtin_types.entry_invalid; |
| 16768 | return ira->codegen->invalid_instruction; |
| 17066 | 16769 | } |
| 17067 | 16770 | |
| 17068 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 16771 | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 16772 | ConstExprValue *out_val = &result->value; |
| 17069 | 16773 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 17070 | 16774 | out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val; |
| 17071 | 16775 | out_val->data.x_ptr.mut = field_ptr_val->data.x_ptr.mut; |
| 17072 | | |
| 17073 | | return result_type; |
| 16776 | return result; |
| 17074 | 16777 | } |
| 17075 | 16778 | |
| 17076 | 16779 | IrInstruction *result = ir_build_field_parent_ptr(&ira->new_irb, instruction->base.scope, |
| 17077 | 16780 | instruction->base.source_node, type_value, field_name_value, casted_field_ptr, field); |
| 17078 | | ir_link_new_instruction(result, &instruction->base); |
| 17079 | | return result_type; |
| 16781 | result->value.type = result_type; |
| 16782 | return result; |
| 17080 | 16783 | } |
| 17081 | 16784 | |
| 17082 | 16785 | static TypeStructField *validate_byte_offset(IrAnalyze *ira, |
| ... | ... | @@ -17121,44 +16824,39 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira, |
| 17121 | 16824 | return field; |
| 17122 | 16825 | } |
| 17123 | 16826 | |
| 17124 | | static ZigType *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, |
| 16827 | static IrInstruction *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, |
| 17125 | 16828 | IrInstructionByteOffsetOf *instruction) |
| 17126 | 16829 | { |
| 17127 | | IrInstruction *type_value = instruction->type_value->other; |
| 16830 | IrInstruction *type_value = instruction->type_value->child; |
| 17128 | 16831 | if (type_is_invalid(type_value->value.type)) |
| 17129 | | return ira->codegen->builtin_types.entry_invalid; |
| 16832 | return ira->codegen->invalid_instruction; |
| 17130 | 16833 | |
| 17131 | | IrInstruction *field_name_value = instruction->field_name->other; |
| 16834 | IrInstruction *field_name_value = instruction->field_name->child; |
| 17132 | 16835 | size_t byte_offset = 0; |
| 17133 | 16836 | if (!validate_byte_offset(ira, type_value, field_name_value, &byte_offset)) |
| 17134 | | return ira->codegen->builtin_types.entry_invalid; |
| 16837 | return ira->codegen->invalid_instruction; |
| 17135 | 16838 | |
| 17136 | 16839 | |
| 17137 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 17138 | | bigint_init_unsigned(&out_val->data.x_bigint, byte_offset); |
| 17139 | | return ira->codegen->builtin_types.entry_num_lit_int; |
| 16840 | return ir_const_unsigned(ira, &instruction->base, byte_offset); |
| 17140 | 16841 | } |
| 17141 | 16842 | |
| 17142 | | static ZigType *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, |
| 16843 | static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, |
| 17143 | 16844 | IrInstructionBitOffsetOf *instruction) |
| 17144 | 16845 | { |
| 17145 | | IrInstruction *type_value = instruction->type_value->other; |
| 16846 | IrInstruction *type_value = instruction->type_value->child; |
| 17146 | 16847 | if (type_is_invalid(type_value->value.type)) |
| 17147 | | return ira->codegen->builtin_types.entry_invalid; |
| 17148 | | IrInstruction *field_name_value = instruction->field_name->other; |
| 16848 | return ira->codegen->invalid_instruction; |
| 16849 | IrInstruction *field_name_value = instruction->field_name->child; |
| 17149 | 16850 | size_t byte_offset = 0; |
| 17150 | 16851 | TypeStructField *field = nullptr; |
| 17151 | 16852 | if (!(field = validate_byte_offset(ira, type_value, field_name_value, &byte_offset))) |
| 17152 | | return ira->codegen->builtin_types.entry_invalid; |
| 16853 | return ira->codegen->invalid_instruction; |
| 17153 | 16854 | |
| 17154 | 16855 | size_t bit_offset = byte_offset * 8 + field->bit_offset_in_host; |
| 17155 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 17156 | | bigint_init_unsigned(&out_val->data.x_bigint, bit_offset); |
| 17157 | | return ira->codegen->builtin_types.entry_num_lit_int; |
| 16856 | return ir_const_unsigned(ira, &instruction->base, bit_offset); |
| 17158 | 16857 | } |
| 17159 | 16858 | |
| 17160 | | static void ensure_field_index(ZigType *type, const char *field_name, size_t index) |
| 17161 | | { |
| 16859 | static void ensure_field_index(ZigType *type, const char *field_name, size_t index) { |
| 17162 | 16860 | Buf *field_name_buf; |
| 17163 | 16861 | |
| 17164 | 16862 | assert(type != nullptr && !type_is_invalid(type)); |
| ... | ... | @@ -17170,8 +16868,8 @@ static void ensure_field_index(ZigType *type, const char *field_name, size_t ind |
| 17170 | 16868 | |
| 17171 | 16869 | static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, ZigType *root) { |
| 17172 | 16870 | Error err; |
| 17173 | | static ConstExprValue *type_info_var = nullptr; |
| 17174 | | static ZigType *type_info_type = nullptr; |
| 16871 | static ConstExprValue *type_info_var = nullptr; // TODO oops this global variable made it past code review |
| 16872 | static ZigType *type_info_type = nullptr; // TODO oops this global variable made it past code review |
| 17175 | 16873 | if (type_info_var == nullptr) { |
| 17176 | 16874 | type_info_var = get_builtin_value(ira->codegen, "TypeInfo"); |
| 17177 | 16875 | assert(type_info_var->type->id == ZigTypeIdMetaType); |
| ... | ... | @@ -18080,23 +17778,23 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE |
| 18080 | 17778 | return ErrorNone; |
| 18081 | 17779 | } |
| 18082 | 17780 | |
| 18083 | | static ZigType *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 17781 | static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 18084 | 17782 | IrInstructionTypeInfo *instruction) |
| 18085 | 17783 | { |
| 18086 | 17784 | Error err; |
| 18087 | | IrInstruction *type_value = instruction->type_value->other; |
| 17785 | IrInstruction *type_value = instruction->type_value->child; |
| 18088 | 17786 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 18089 | 17787 | if (type_is_invalid(type_entry)) |
| 18090 | | return ira->codegen->builtin_types.entry_invalid; |
| 17788 | return ira->codegen->invalid_instruction; |
| 18091 | 17789 | |
| 18092 | 17790 | ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr); |
| 18093 | 17791 | |
| 18094 | 17792 | ConstExprValue *payload; |
| 18095 | 17793 | if ((err = ir_make_type_info_value(ira, type_entry, &payload))) |
| 18096 | | return ira->codegen->builtin_types.entry_invalid; |
| 17794 | return ira->codegen->invalid_instruction; |
| 18097 | 17795 | |
| 18098 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 18099 | | out_val->type = result_type; |
| 17796 | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 17797 | ConstExprValue *out_val = &result->value; |
| 18100 | 17798 | bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry)); |
| 18101 | 17799 | out_val->data.x_union.payload = payload; |
| 18102 | 17800 | |
| ... | ... | @@ -18106,66 +17804,65 @@ static ZigType *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 18106 | 17804 | payload->data.x_struct.parent.data.p_union.union_val = out_val; |
| 18107 | 17805 | } |
| 18108 | 17806 | |
| 18109 | | return result_type; |
| 17807 | return result; |
| 18110 | 17808 | } |
| 18111 | 17809 | |
| 18112 | | static ZigType *ir_analyze_instruction_type_id(IrAnalyze *ira, |
| 17810 | static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira, |
| 18113 | 17811 | IrInstructionTypeId *instruction) |
| 18114 | 17812 | { |
| 18115 | | IrInstruction *type_value = instruction->type_value->other; |
| 17813 | IrInstruction *type_value = instruction->type_value->child; |
| 18116 | 17814 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 18117 | 17815 | if (type_is_invalid(type_entry)) |
| 18118 | | return ira->codegen->builtin_types.entry_invalid; |
| 17816 | return ira->codegen->invalid_instruction; |
| 18119 | 17817 | |
| 18120 | 17818 | ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId"); |
| 18121 | 17819 | assert(var_value->type->id == ZigTypeIdMetaType); |
| 18122 | 17820 | ZigType *result_type = var_value->data.x_type; |
| 18123 | 17821 | |
| 18124 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 18125 | | bigint_init_unsigned(&out_val->data.x_enum_tag, type_id_index(type_entry)); |
| 18126 | | return result_type; |
| 17822 | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 17823 | bigint_init_unsigned(&result->value.data.x_enum_tag, type_id_index(type_entry)); |
| 17824 | return result; |
| 18127 | 17825 | } |
| 18128 | 17826 | |
| 18129 | | static ZigType *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira, |
| 17827 | static IrInstruction *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira, |
| 18130 | 17828 | IrInstructionSetEvalBranchQuota *instruction) |
| 18131 | 17829 | { |
| 18132 | 17830 | if (ira->new_irb.exec->parent_exec != nullptr && !ira->new_irb.exec->is_generic_instantiation) { |
| 18133 | 17831 | ir_add_error(ira, &instruction->base, |
| 18134 | 17832 | buf_sprintf("@setEvalBranchQuota must be called from the top of the comptime stack")); |
| 18135 | | return ira->codegen->builtin_types.entry_invalid; |
| 17833 | return ira->codegen->invalid_instruction; |
| 18136 | 17834 | } |
| 18137 | 17835 | |
| 18138 | 17836 | uint64_t new_quota; |
| 18139 | | if (!ir_resolve_usize(ira, instruction->new_quota->other, &new_quota)) |
| 18140 | | return ira->codegen->builtin_types.entry_invalid; |
| 17837 | if (!ir_resolve_usize(ira, instruction->new_quota->child, &new_quota)) |
| 17838 | return ira->codegen->invalid_instruction; |
| 18141 | 17839 | |
| 18142 | 17840 | if (new_quota > ira->new_irb.exec->backward_branch_quota) { |
| 18143 | 17841 | ira->new_irb.exec->backward_branch_quota = new_quota; |
| 18144 | 17842 | } |
| 18145 | 17843 | |
| 18146 | | ir_build_const_from(ira, &instruction->base); |
| 18147 | | return ira->codegen->builtin_types.entry_void; |
| 17844 | return ir_const_void(ira, &instruction->base); |
| 18148 | 17845 | } |
| 18149 | 17846 | |
| 18150 | | static ZigType *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) { |
| 18151 | | IrInstruction *type_value = instruction->type_value->other; |
| 17847 | static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) { |
| 17848 | IrInstruction *type_value = instruction->type_value->child; |
| 18152 | 17849 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 18153 | 17850 | if (type_is_invalid(type_entry)) |
| 18154 | | return ira->codegen->builtin_types.entry_invalid; |
| 17851 | return ira->codegen->invalid_instruction; |
| 18155 | 17852 | |
| 18156 | 17853 | if (!type_entry->cached_const_name_val) { |
| 18157 | 17854 | type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, &type_entry->name); |
| 18158 | 17855 | } |
| 18159 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 18160 | | copy_const_val(out_val, type_entry->cached_const_name_val, true); |
| 18161 | | return out_val->type; |
| 17856 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 17857 | copy_const_val(&result->value, type_entry->cached_const_name_val, true); |
| 17858 | return result; |
| 18162 | 17859 | } |
| 18163 | 17860 | |
| 18164 | | static ZigType *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) { |
| 17861 | static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) { |
| 18165 | 17862 | if (ira->codegen->enable_cache) { |
| 18166 | 17863 | ir_add_error(ira, &instruction->base, |
| 18167 | 17864 | buf_sprintf("TODO @cImport is incompatible with --cache on. The cache system currently is unable to detect subsequent changes in .h files.")); |
| 18168 | | return ira->codegen->builtin_types.entry_invalid; |
| 17865 | return ira->codegen->invalid_instruction; |
| 18169 | 17866 | } |
| 18170 | 17867 | |
| 18171 | 17868 | AstNode *node = instruction->base.source_node; |
| ... | ... | @@ -18176,11 +17873,11 @@ static ZigType *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCIm |
| 18176 | 17873 | |
| 18177 | 17874 | // Execute the C import block like an inline function |
| 18178 | 17875 | ZigType *void_type = ira->codegen->builtin_types.entry_void; |
| 18179 | | IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, |
| 17876 | IrInstruction *cimport_result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, |
| 18180 | 17877 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, |
| 18181 | 17878 | &cimport_scope->buf, block_node, nullptr, nullptr); |
| 18182 | | if (type_is_invalid(result->value.type)) |
| 18183 | | return ira->codegen->builtin_types.entry_invalid; |
| 17879 | if (type_is_invalid(cimport_result->value.type)) |
| 17880 | return ira->codegen->invalid_instruction; |
| 18184 | 17881 | |
| 18185 | 17882 | find_libc_include_path(ira->codegen); |
| 18186 | 17883 | |
| ... | ... | @@ -18199,7 +17896,7 @@ static ZigType *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCIm |
| 18199 | 17896 | if ((err = parse_h_buf(child_import, &errors, &cimport_scope->buf, ira->codegen, node))) { |
| 18200 | 17897 | if (err != ErrorCCompileErrors) { |
| 18201 | 17898 | ir_add_error_node(ira, node, buf_sprintf("C import failed: %s", err_str(err))); |
| 18202 | | return ira->codegen->builtin_types.entry_invalid; |
| 17899 | return ira->codegen->invalid_instruction; |
| 18203 | 17900 | } |
| 18204 | 17901 | } |
| 18205 | 17902 | |
| ... | ... | @@ -18210,7 +17907,7 @@ static ZigType *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCIm |
| 18210 | 17907 | err_msg_add_note(parent_err_msg, err_msg); |
| 18211 | 17908 | } |
| 18212 | 17909 | |
| 18213 | | return ira->codegen->builtin_types.entry_invalid; |
| 17910 | return ira->codegen->invalid_instruction; |
| 18214 | 17911 | } |
| 18215 | 17912 | |
| 18216 | 17913 | if (ira->codegen->verbose_cimport) { |
| ... | ... | @@ -18221,19 +17918,19 @@ static ZigType *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCIm |
| 18221 | 17918 | |
| 18222 | 17919 | scan_decls(ira->codegen, child_import->decls_scope, child_import->root); |
| 18223 | 17920 | |
| 18224 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 18225 | | out_val->data.x_import = child_import; |
| 18226 | | return ira->codegen->builtin_types.entry_namespace; |
| 17921 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_namespace); |
| 17922 | result->value.data.x_import = child_import; |
| 17923 | return result; |
| 18227 | 17924 | } |
| 18228 | 17925 | |
| 18229 | | static ZigType *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) { |
| 18230 | | IrInstruction *name_value = instruction->name->other; |
| 17926 | static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) { |
| 17927 | IrInstruction *name_value = instruction->name->child; |
| 18231 | 17928 | if (type_is_invalid(name_value->value.type)) |
| 18232 | | return ira->codegen->builtin_types.entry_invalid; |
| 17929 | return ira->codegen->invalid_instruction; |
| 18233 | 17930 | |
| 18234 | 17931 | Buf *include_name = ir_resolve_str(ira, name_value); |
| 18235 | 17932 | if (!include_name) |
| 18236 | | return ira->codegen->builtin_types.entry_invalid; |
| 17933 | return ira->codegen->invalid_instruction; |
| 18237 | 17934 | |
| 18238 | 17935 | Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec); |
| 18239 | 17936 | // We check for this error in pass1 |
| ... | ... | @@ -18241,26 +17938,25 @@ static ZigType *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCI |
| 18241 | 17938 | |
| 18242 | 17939 | buf_appendf(c_import_buf, "#include <%s>\n", buf_ptr(include_name)); |
| 18243 | 17940 | |
| 18244 | | ir_build_const_from(ira, &instruction->base); |
| 18245 | | return ira->codegen->builtin_types.entry_void; |
| 17941 | return ir_const_void(ira, &instruction->base); |
| 18246 | 17942 | } |
| 18247 | 17943 | |
| 18248 | | static ZigType *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) { |
| 18249 | | IrInstruction *name = instruction->name->other; |
| 17944 | static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) { |
| 17945 | IrInstruction *name = instruction->name->child; |
| 18250 | 17946 | if (type_is_invalid(name->value.type)) |
| 18251 | | return ira->codegen->builtin_types.entry_invalid; |
| 17947 | return ira->codegen->invalid_instruction; |
| 18252 | 17948 | |
| 18253 | 17949 | Buf *define_name = ir_resolve_str(ira, name); |
| 18254 | 17950 | if (!define_name) |
| 18255 | | return ira->codegen->builtin_types.entry_invalid; |
| 17951 | return ira->codegen->invalid_instruction; |
| 18256 | 17952 | |
| 18257 | | IrInstruction *value = instruction->value->other; |
| 17953 | IrInstruction *value = instruction->value->child; |
| 18258 | 17954 | if (type_is_invalid(value->value.type)) |
| 18259 | | return ira->codegen->builtin_types.entry_invalid; |
| 17955 | return ira->codegen->invalid_instruction; |
| 18260 | 17956 | |
| 18261 | 17957 | Buf *define_value = ir_resolve_str(ira, value); |
| 18262 | 17958 | if (!define_value) |
| 18263 | | return ira->codegen->builtin_types.entry_invalid; |
| 17959 | return ira->codegen->invalid_instruction; |
| 18264 | 17960 | |
| 18265 | 17961 | Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec); |
| 18266 | 17962 | // We check for this error in pass1 |
| ... | ... | @@ -18268,18 +17964,17 @@ static ZigType *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDe |
| 18268 | 17964 | |
| 18269 | 17965 | buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name), buf_ptr(define_value)); |
| 18270 | 17966 | |
| 18271 | | ir_build_const_from(ira, &instruction->base); |
| 18272 | | return ira->codegen->builtin_types.entry_void; |
| 17967 | return ir_const_void(ira, &instruction->base); |
| 18273 | 17968 | } |
| 18274 | 17969 | |
| 18275 | | static ZigType *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) { |
| 18276 | | IrInstruction *name = instruction->name->other; |
| 17970 | static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) { |
| 17971 | IrInstruction *name = instruction->name->child; |
| 18277 | 17972 | if (type_is_invalid(name->value.type)) |
| 18278 | | return ira->codegen->builtin_types.entry_invalid; |
| 17973 | return ira->codegen->invalid_instruction; |
| 18279 | 17974 | |
| 18280 | 17975 | Buf *undef_name = ir_resolve_str(ira, name); |
| 18281 | 17976 | if (!undef_name) |
| 18282 | | return ira->codegen->builtin_types.entry_invalid; |
| 17977 | return ira->codegen->invalid_instruction; |
| 18283 | 17978 | |
| 18284 | 17979 | Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec); |
| 18285 | 17980 | // We check for this error in pass1 |
| ... | ... | @@ -18287,18 +17982,17 @@ static ZigType *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUnd |
| 18287 | 17982 | |
| 18288 | 17983 | buf_appendf(c_import_buf, "#undef %s\n", buf_ptr(undef_name)); |
| 18289 | 17984 | |
| 18290 | | ir_build_const_from(ira, &instruction->base); |
| 18291 | | return ira->codegen->builtin_types.entry_void; |
| 17985 | return ir_const_void(ira, &instruction->base); |
| 18292 | 17986 | } |
| 18293 | 17987 | |
| 18294 | | static ZigType *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) { |
| 18295 | | IrInstruction *name = instruction->name->other; |
| 17988 | static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) { |
| 17989 | IrInstruction *name = instruction->name->child; |
| 18296 | 17990 | if (type_is_invalid(name->value.type)) |
| 18297 | | return ira->codegen->builtin_types.entry_invalid; |
| 17991 | return ira->codegen->invalid_instruction; |
| 18298 | 17992 | |
| 18299 | 17993 | Buf *rel_file_path = ir_resolve_str(ira, name); |
| 18300 | 17994 | if (!rel_file_path) |
| 18301 | | return ira->codegen->builtin_types.entry_invalid; |
| 17995 | return ira->codegen->invalid_instruction; |
| 18302 | 17996 | |
| 18303 | 17997 | ImportTableEntry *import = get_scope_import(instruction->base.scope); |
| 18304 | 17998 | // figure out absolute path to resource |
| ... | ... | @@ -18318,85 +18012,86 @@ static ZigType *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionE |
| 18318 | 18012 | if ((err = file_fetch(ira->codegen, file_path, file_contents))) { |
| 18319 | 18013 | if (err == ErrorFileNotFound) { |
| 18320 | 18014 | ir_add_error(ira, instruction->name, buf_sprintf("unable to find '%s'", buf_ptr(file_path))); |
| 18321 | | return ira->codegen->builtin_types.entry_invalid; |
| 18015 | return ira->codegen->invalid_instruction; |
| 18322 | 18016 | } else { |
| 18323 | 18017 | ir_add_error(ira, instruction->name, buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err))); |
| 18324 | | return ira->codegen->builtin_types.entry_invalid; |
| 18018 | return ira->codegen->invalid_instruction; |
| 18325 | 18019 | } |
| 18326 | 18020 | } |
| 18327 | 18021 | |
| 18328 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 18329 | | init_const_str_lit(ira->codegen, out_val, file_contents); |
| 18330 | | |
| 18331 | | return get_array_type(ira->codegen, ira->codegen->builtin_types.entry_u8, buf_len(file_contents)); |
| 18022 | ZigType *result_type = get_array_type(ira->codegen, |
| 18023 | ira->codegen->builtin_types.entry_u8, buf_len(file_contents)); |
| 18024 | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 18025 | init_const_str_lit(ira->codegen, &result->value, file_contents); |
| 18026 | return result; |
| 18332 | 18027 | } |
| 18333 | 18028 | |
| 18334 | | static ZigType *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) { |
| 18335 | | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->other); |
| 18029 | static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) { |
| 18030 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->child); |
| 18336 | 18031 | if (type_is_invalid(operand_type)) |
| 18337 | | return ira->codegen->builtin_types.entry_invalid; |
| 18032 | return ira->codegen->invalid_instruction; |
| 18338 | 18033 | |
| 18339 | | IrInstruction *ptr = instruction->ptr->other; |
| 18034 | IrInstruction *ptr = instruction->ptr->child; |
| 18340 | 18035 | if (type_is_invalid(ptr->value.type)) |
| 18341 | | return ira->codegen->builtin_types.entry_invalid; |
| 18036 | return ira->codegen->invalid_instruction; |
| 18342 | 18037 | |
| 18343 | 18038 | // TODO let this be volatile |
| 18344 | 18039 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 18345 | 18040 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type); |
| 18346 | 18041 | if (type_is_invalid(casted_ptr->value.type)) |
| 18347 | | return ira->codegen->builtin_types.entry_invalid; |
| 18042 | return ira->codegen->invalid_instruction; |
| 18348 | 18043 | |
| 18349 | | IrInstruction *cmp_value = instruction->cmp_value->other; |
| 18044 | IrInstruction *cmp_value = instruction->cmp_value->child; |
| 18350 | 18045 | if (type_is_invalid(cmp_value->value.type)) |
| 18351 | | return ira->codegen->builtin_types.entry_invalid; |
| 18046 | return ira->codegen->invalid_instruction; |
| 18352 | 18047 | |
| 18353 | | IrInstruction *new_value = instruction->new_value->other; |
| 18048 | IrInstruction *new_value = instruction->new_value->child; |
| 18354 | 18049 | if (type_is_invalid(new_value->value.type)) |
| 18355 | | return ira->codegen->builtin_types.entry_invalid; |
| 18050 | return ira->codegen->invalid_instruction; |
| 18356 | 18051 | |
| 18357 | | IrInstruction *success_order_value = instruction->success_order_value->other; |
| 18052 | IrInstruction *success_order_value = instruction->success_order_value->child; |
| 18358 | 18053 | if (type_is_invalid(success_order_value->value.type)) |
| 18359 | | return ira->codegen->builtin_types.entry_invalid; |
| 18054 | return ira->codegen->invalid_instruction; |
| 18360 | 18055 | |
| 18361 | 18056 | AtomicOrder success_order; |
| 18362 | 18057 | if (!ir_resolve_atomic_order(ira, success_order_value, &success_order)) |
| 18363 | | return ira->codegen->builtin_types.entry_invalid; |
| 18058 | return ira->codegen->invalid_instruction; |
| 18364 | 18059 | |
| 18365 | | IrInstruction *failure_order_value = instruction->failure_order_value->other; |
| 18060 | IrInstruction *failure_order_value = instruction->failure_order_value->child; |
| 18366 | 18061 | if (type_is_invalid(failure_order_value->value.type)) |
| 18367 | | return ira->codegen->builtin_types.entry_invalid; |
| 18062 | return ira->codegen->invalid_instruction; |
| 18368 | 18063 | |
| 18369 | 18064 | AtomicOrder failure_order; |
| 18370 | 18065 | if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order)) |
| 18371 | | return ira->codegen->builtin_types.entry_invalid; |
| 18066 | return ira->codegen->invalid_instruction; |
| 18372 | 18067 | |
| 18373 | 18068 | IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type); |
| 18374 | 18069 | if (type_is_invalid(casted_cmp_value->value.type)) |
| 18375 | | return ira->codegen->builtin_types.entry_invalid; |
| 18070 | return ira->codegen->invalid_instruction; |
| 18376 | 18071 | |
| 18377 | 18072 | IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, operand_type); |
| 18378 | 18073 | if (type_is_invalid(casted_new_value->value.type)) |
| 18379 | | return ira->codegen->builtin_types.entry_invalid; |
| 18074 | return ira->codegen->invalid_instruction; |
| 18380 | 18075 | |
| 18381 | 18076 | if (success_order < AtomicOrderMonotonic) { |
| 18382 | 18077 | ir_add_error(ira, success_order_value, |
| 18383 | 18078 | buf_sprintf("success atomic ordering must be Monotonic or stricter")); |
| 18384 | | return ira->codegen->builtin_types.entry_invalid; |
| 18079 | return ira->codegen->invalid_instruction; |
| 18385 | 18080 | } |
| 18386 | 18081 | if (failure_order < AtomicOrderMonotonic) { |
| 18387 | 18082 | ir_add_error(ira, failure_order_value, |
| 18388 | 18083 | buf_sprintf("failure atomic ordering must be Monotonic or stricter")); |
| 18389 | | return ira->codegen->builtin_types.entry_invalid; |
| 18084 | return ira->codegen->invalid_instruction; |
| 18390 | 18085 | } |
| 18391 | 18086 | if (failure_order > success_order) { |
| 18392 | 18087 | ir_add_error(ira, failure_order_value, |
| 18393 | 18088 | buf_sprintf("failure atomic ordering must be no stricter than success")); |
| 18394 | | return ira->codegen->builtin_types.entry_invalid; |
| 18089 | return ira->codegen->invalid_instruction; |
| 18395 | 18090 | } |
| 18396 | 18091 | if (failure_order == AtomicOrderRelease || failure_order == AtomicOrderAcqRel) { |
| 18397 | 18092 | ir_add_error(ira, failure_order_value, |
| 18398 | 18093 | buf_sprintf("failure atomic ordering must not be Release or AcqRel")); |
| 18399 | | return ira->codegen->builtin_types.entry_invalid; |
| 18094 | return ira->codegen->invalid_instruction; |
| 18400 | 18095 | } |
| 18401 | 18096 | |
| 18402 | 18097 | if (instr_is_comptime(casted_ptr) && instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) { |
| ... | ... | @@ -18407,127 +18102,118 @@ static ZigType *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpx |
| 18407 | 18102 | nullptr, casted_ptr, casted_cmp_value, casted_new_value, nullptr, nullptr, instruction->is_weak, |
| 18408 | 18103 | operand_type, success_order, failure_order); |
| 18409 | 18104 | result->value.type = get_optional_type(ira->codegen, operand_type); |
| 18410 | | ir_link_new_instruction(result, &instruction->base); |
| 18411 | 18105 | ir_add_alloca(ira, result, result->value.type); |
| 18412 | | return result->value.type; |
| 18106 | return result; |
| 18413 | 18107 | } |
| 18414 | 18108 | |
| 18415 | | static ZigType *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) { |
| 18416 | | IrInstruction *order_value = instruction->order_value->other; |
| 18109 | static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) { |
| 18110 | IrInstruction *order_value = instruction->order_value->child; |
| 18417 | 18111 | if (type_is_invalid(order_value->value.type)) |
| 18418 | | return ira->codegen->builtin_types.entry_invalid; |
| 18112 | return ira->codegen->invalid_instruction; |
| 18419 | 18113 | |
| 18420 | 18114 | AtomicOrder order; |
| 18421 | 18115 | if (!ir_resolve_atomic_order(ira, order_value, &order)) |
| 18422 | | return ira->codegen->builtin_types.entry_invalid; |
| 18116 | return ira->codegen->invalid_instruction; |
| 18423 | 18117 | |
| 18424 | | ir_build_fence_from(&ira->new_irb, &instruction->base, order_value, order); |
| 18425 | | return ira->codegen->builtin_types.entry_void; |
| 18118 | IrInstruction *result = ir_build_fence(&ira->new_irb, |
| 18119 | instruction->base.scope, instruction->base.source_node, order_value, order); |
| 18120 | result->value.type = ira->codegen->builtin_types.entry_void; |
| 18121 | return result; |
| 18426 | 18122 | } |
| 18427 | 18123 | |
| 18428 | | static ZigType *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) { |
| 18429 | | IrInstruction *dest_type_value = instruction->dest_type->other; |
| 18124 | static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) { |
| 18125 | IrInstruction *dest_type_value = instruction->dest_type->child; |
| 18430 | 18126 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 18431 | 18127 | if (type_is_invalid(dest_type)) |
| 18432 | | return ira->codegen->builtin_types.entry_invalid; |
| 18128 | return ira->codegen->invalid_instruction; |
| 18433 | 18129 | |
| 18434 | 18130 | if (dest_type->id != ZigTypeIdInt && |
| 18435 | 18131 | dest_type->id != ZigTypeIdComptimeInt) |
| 18436 | 18132 | { |
| 18437 | 18133 | ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 18438 | | return ira->codegen->builtin_types.entry_invalid; |
| 18134 | return ira->codegen->invalid_instruction; |
| 18439 | 18135 | } |
| 18440 | 18136 | |
| 18441 | | IrInstruction *target = instruction->target->other; |
| 18137 | IrInstruction *target = instruction->target->child; |
| 18442 | 18138 | ZigType *src_type = target->value.type; |
| 18443 | 18139 | if (type_is_invalid(src_type)) |
| 18444 | | return ira->codegen->builtin_types.entry_invalid; |
| 18140 | return ira->codegen->invalid_instruction; |
| 18445 | 18141 | |
| 18446 | 18142 | if (src_type->id != ZigTypeIdInt && |
| 18447 | 18143 | src_type->id != ZigTypeIdComptimeInt) |
| 18448 | 18144 | { |
| 18449 | 18145 | ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name))); |
| 18450 | | return ira->codegen->builtin_types.entry_invalid; |
| 18146 | return ira->codegen->invalid_instruction; |
| 18451 | 18147 | } |
| 18452 | 18148 | |
| 18453 | 18149 | if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) { |
| 18454 | 18150 | const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned"; |
| 18455 | 18151 | ir_add_error(ira, target, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name))); |
| 18456 | | return ira->codegen->builtin_types.entry_invalid; |
| 18152 | return ira->codegen->invalid_instruction; |
| 18457 | 18153 | } else if (src_type->data.integral.bit_count < dest_type->data.integral.bit_count) { |
| 18458 | 18154 | ir_add_error(ira, target, buf_sprintf("type '%s' has fewer bits than destination type '%s'", |
| 18459 | 18155 | buf_ptr(&src_type->name), buf_ptr(&dest_type->name))); |
| 18460 | | return ira->codegen->builtin_types.entry_invalid; |
| 18156 | return ira->codegen->invalid_instruction; |
| 18461 | 18157 | } |
| 18462 | 18158 | |
| 18463 | 18159 | if (target->value.special == ConstValSpecialStatic) { |
| 18464 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 18465 | | bigint_truncate(&out_val->data.x_bigint, &target->value.data.x_bigint, dest_type->data.integral.bit_count, |
| 18466 | | dest_type->data.integral.is_signed); |
| 18467 | | return dest_type; |
| 18160 | IrInstruction *result = ir_const(ira, &instruction->base, dest_type); |
| 18161 | bigint_truncate(&result->value.data.x_bigint, &target->value.data.x_bigint, |
| 18162 | dest_type->data.integral.bit_count, dest_type->data.integral.is_signed); |
| 18163 | return result; |
| 18468 | 18164 | } |
| 18469 | 18165 | |
| 18470 | 18166 | IrInstruction *new_instruction = ir_build_truncate(&ira->new_irb, instruction->base.scope, |
| 18471 | 18167 | instruction->base.source_node, dest_type_value, target); |
| 18472 | | ir_link_new_instruction(new_instruction, &instruction->base); |
| 18473 | | return dest_type; |
| 18168 | new_instruction->value.type = dest_type; |
| 18169 | return new_instruction; |
| 18474 | 18170 | } |
| 18475 | 18171 | |
| 18476 | | static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) { |
| 18477 | | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18172 | static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) { |
| 18173 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 18478 | 18174 | if (type_is_invalid(dest_type)) |
| 18479 | | return ira->codegen->builtin_types.entry_invalid; |
| 18175 | return ira->codegen->invalid_instruction; |
| 18480 | 18176 | |
| 18481 | 18177 | if (dest_type->id != ZigTypeIdInt) { |
| 18482 | 18178 | ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 18483 | | return ira->codegen->builtin_types.entry_invalid; |
| 18179 | return ira->codegen->invalid_instruction; |
| 18484 | 18180 | } |
| 18485 | 18181 | |
| 18486 | | IrInstruction *target = instruction->target->other; |
| 18182 | IrInstruction *target = instruction->target->child; |
| 18487 | 18183 | if (type_is_invalid(target->value.type)) |
| 18488 | | return ira->codegen->builtin_types.entry_invalid; |
| 18184 | return ira->codegen->invalid_instruction; |
| 18489 | 18185 | |
| 18490 | 18186 | if (target->value.type->id == ZigTypeIdComptimeInt) { |
| 18491 | 18187 | if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) { |
| 18492 | | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, |
| 18493 | | CastOpNumLitToConcrete, false); |
| 18494 | | if (type_is_invalid(result->value.type)) |
| 18495 | | return ira->codegen->builtin_types.entry_invalid; |
| 18496 | | ir_link_new_instruction(result, &instruction->base); |
| 18497 | | return dest_type; |
| 18188 | return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpNumLitToConcrete, false); |
| 18498 | 18189 | } else { |
| 18499 | | return ira->codegen->builtin_types.entry_invalid; |
| 18190 | return ira->codegen->invalid_instruction; |
| 18500 | 18191 | } |
| 18501 | 18192 | } |
| 18502 | 18193 | |
| 18503 | 18194 | if (target->value.type->id != ZigTypeIdInt) { |
| 18504 | 18195 | ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'", |
| 18505 | 18196 | buf_ptr(&target->value.type->name))); |
| 18506 | | return ira->codegen->builtin_types.entry_invalid; |
| 18197 | return ira->codegen->invalid_instruction; |
| 18507 | 18198 | } |
| 18508 | 18199 | |
| 18509 | | IrInstruction *result = ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type); |
| 18510 | | if (type_is_invalid(result->value.type)) |
| 18511 | | return ira->codegen->builtin_types.entry_invalid; |
| 18512 | | |
| 18513 | | ir_link_new_instruction(result, &instruction->base); |
| 18514 | | return dest_type; |
| 18200 | return ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type); |
| 18515 | 18201 | } |
| 18516 | 18202 | |
| 18517 | | static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) { |
| 18518 | | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18203 | static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) { |
| 18204 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 18519 | 18205 | if (type_is_invalid(dest_type)) |
| 18520 | | return ira->codegen->builtin_types.entry_invalid; |
| 18206 | return ira->codegen->invalid_instruction; |
| 18521 | 18207 | |
| 18522 | 18208 | if (dest_type->id != ZigTypeIdFloat) { |
| 18523 | 18209 | ir_add_error(ira, instruction->dest_type, |
| 18524 | 18210 | buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name))); |
| 18525 | | return ira->codegen->builtin_types.entry_invalid; |
| 18211 | return ira->codegen->invalid_instruction; |
| 18526 | 18212 | } |
| 18527 | 18213 | |
| 18528 | | IrInstruction *target = instruction->target->other; |
| 18214 | IrInstruction *target = instruction->target->child; |
| 18529 | 18215 | if (type_is_invalid(target->value.type)) |
| 18530 | | return ira->codegen->builtin_types.entry_invalid; |
| 18216 | return ira->codegen->invalid_instruction; |
| 18531 | 18217 | |
| 18532 | 18218 | if (target->value.type->id == ZigTypeIdComptimeInt || |
| 18533 | 18219 | target->value.type->id == ZigTypeIdComptimeFloat) |
| ... | ... | @@ -18539,55 +18225,43 @@ static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionF |
| 18539 | 18225 | } else { |
| 18540 | 18226 | op = CastOpNumLitToConcrete; |
| 18541 | 18227 | } |
| 18542 | | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, op, false); |
| 18543 | | if (type_is_invalid(result->value.type)) |
| 18544 | | return ira->codegen->builtin_types.entry_invalid; |
| 18545 | | ir_link_new_instruction(result, &instruction->base); |
| 18546 | | return dest_type; |
| 18228 | return ir_resolve_cast(ira, &instruction->base, target, dest_type, op, false); |
| 18547 | 18229 | } else { |
| 18548 | | return ira->codegen->builtin_types.entry_invalid; |
| 18230 | return ira->codegen->invalid_instruction; |
| 18549 | 18231 | } |
| 18550 | 18232 | } |
| 18551 | 18233 | |
| 18552 | 18234 | if (target->value.type->id != ZigTypeIdFloat) { |
| 18553 | 18235 | ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", |
| 18554 | 18236 | buf_ptr(&target->value.type->name))); |
| 18555 | | return ira->codegen->builtin_types.entry_invalid; |
| 18237 | return ira->codegen->invalid_instruction; |
| 18556 | 18238 | } |
| 18557 | 18239 | |
| 18558 | | IrInstruction *result = ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type); |
| 18559 | | if (type_is_invalid(result->value.type)) |
| 18560 | | return ira->codegen->builtin_types.entry_invalid; |
| 18561 | | ir_link_new_instruction(result, &instruction->base); |
| 18562 | | return dest_type; |
| 18240 | return ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type); |
| 18563 | 18241 | } |
| 18564 | 18242 | |
| 18565 | | static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) { |
| 18566 | | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18243 | static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) { |
| 18244 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 18567 | 18245 | if (type_is_invalid(dest_type)) |
| 18568 | | return ira->codegen->builtin_types.entry_invalid; |
| 18246 | return ira->codegen->invalid_instruction; |
| 18569 | 18247 | |
| 18570 | 18248 | if (dest_type->id != ZigTypeIdErrorSet) { |
| 18571 | 18249 | ir_add_error(ira, instruction->dest_type, |
| 18572 | 18250 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name))); |
| 18573 | | return ira->codegen->builtin_types.entry_invalid; |
| 18251 | return ira->codegen->invalid_instruction; |
| 18574 | 18252 | } |
| 18575 | 18253 | |
| 18576 | | IrInstruction *target = instruction->target->other; |
| 18254 | IrInstruction *target = instruction->target->child; |
| 18577 | 18255 | if (type_is_invalid(target->value.type)) |
| 18578 | | return ira->codegen->builtin_types.entry_invalid; |
| 18256 | return ira->codegen->invalid_instruction; |
| 18579 | 18257 | |
| 18580 | 18258 | if (target->value.type->id != ZigTypeIdErrorSet) { |
| 18581 | 18259 | ir_add_error(ira, instruction->target, |
| 18582 | 18260 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name))); |
| 18583 | | return ira->codegen->builtin_types.entry_invalid; |
| 18261 | return ira->codegen->invalid_instruction; |
| 18584 | 18262 | } |
| 18585 | 18263 | |
| 18586 | | IrInstruction *result = ir_analyze_err_set_cast(ira, &instruction->base, target, dest_type); |
| 18587 | | if (type_is_invalid(result->value.type)) |
| 18588 | | return ira->codegen->builtin_types.entry_invalid; |
| 18589 | | ir_link_new_instruction(result, &instruction->base); |
| 18590 | | return dest_type; |
| 18264 | return ir_analyze_err_set_cast(ira, &instruction->base, target, dest_type); |
| 18591 | 18265 | } |
| 18592 | 18266 | |
| 18593 | 18267 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) { |
| ... | ... | @@ -18602,16 +18276,16 @@ static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_ali |
| 18602 | 18276 | return ErrorNone; |
| 18603 | 18277 | } |
| 18604 | 18278 | |
| 18605 | | static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) { |
| 18279 | static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) { |
| 18606 | 18280 | Error err; |
| 18607 | 18281 | |
| 18608 | | ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other); |
| 18282 | ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child); |
| 18609 | 18283 | if (type_is_invalid(dest_child_type)) |
| 18610 | | return ira->codegen->builtin_types.entry_invalid; |
| 18284 | return ira->codegen->invalid_instruction; |
| 18611 | 18285 | |
| 18612 | | IrInstruction *target = instruction->target->other; |
| 18286 | IrInstruction *target = instruction->target->child; |
| 18613 | 18287 | if (type_is_invalid(target->value.type)) |
| 18614 | | return ira->codegen->builtin_types.entry_invalid; |
| 18288 | return ira->codegen->invalid_instruction; |
| 18615 | 18289 | |
| 18616 | 18290 | bool src_ptr_const; |
| 18617 | 18291 | bool src_ptr_volatile; |
| ... | ... | @@ -18621,26 +18295,26 @@ static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionF |
| 18621 | 18295 | src_ptr_volatile = target->value.type->data.pointer.is_volatile; |
| 18622 | 18296 | |
| 18623 | 18297 | if ((err = resolve_ptr_align(ira, target->value.type, &src_ptr_align))) |
| 18624 | | return ira->codegen->builtin_types.entry_invalid; |
| 18298 | return ira->codegen->invalid_instruction; |
| 18625 | 18299 | } else if (is_slice(target->value.type)) { |
| 18626 | 18300 | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; |
| 18627 | 18301 | src_ptr_const = src_ptr_type->data.pointer.is_const; |
| 18628 | 18302 | src_ptr_volatile = src_ptr_type->data.pointer.is_volatile; |
| 18629 | 18303 | |
| 18630 | 18304 | if ((err = resolve_ptr_align(ira, src_ptr_type, &src_ptr_align))) |
| 18631 | | return ira->codegen->builtin_types.entry_invalid; |
| 18305 | return ira->codegen->invalid_instruction; |
| 18632 | 18306 | } else { |
| 18633 | 18307 | src_ptr_const = true; |
| 18634 | 18308 | src_ptr_volatile = false; |
| 18635 | 18309 | |
| 18636 | 18310 | if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusAlignmentKnown))) |
| 18637 | | return ira->codegen->builtin_types.entry_invalid; |
| 18311 | return ira->codegen->invalid_instruction; |
| 18638 | 18312 | |
| 18639 | 18313 | src_ptr_align = get_abi_alignment(ira->codegen, target->value.type); |
| 18640 | 18314 | } |
| 18641 | 18315 | |
| 18642 | 18316 | if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusSizeKnown))) |
| 18643 | | return ira->codegen->builtin_types.entry_invalid; |
| 18317 | return ira->codegen->invalid_instruction; |
| 18644 | 18318 | |
| 18645 | 18319 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type, |
| 18646 | 18320 | src_ptr_const, src_ptr_volatile, PtrLenUnknown, |
| ... | ... | @@ -18654,7 +18328,7 @@ static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionF |
| 18654 | 18328 | |
| 18655 | 18329 | IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice); |
| 18656 | 18330 | if (type_is_invalid(casted_value->value.type)) |
| 18657 | | return ira->codegen->builtin_types.entry_invalid; |
| 18331 | return ira->codegen->invalid_instruction; |
| 18658 | 18332 | |
| 18659 | 18333 | bool have_known_len = false; |
| 18660 | 18334 | uint64_t known_len; |
| ... | ... | @@ -18662,7 +18336,7 @@ static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionF |
| 18662 | 18336 | if (instr_is_comptime(casted_value)) { |
| 18663 | 18337 | ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad); |
| 18664 | 18338 | if (!val) |
| 18665 | | return ira->codegen->builtin_types.entry_invalid; |
| 18339 | return ira->codegen->invalid_instruction; |
| 18666 | 18340 | |
| 18667 | 18341 | ConstExprValue *len_val = &val->data.x_struct.fields[slice_len_index]; |
| 18668 | 18342 | if (value_is_comptime(len_val)) { |
| ... | ... | @@ -18686,96 +18360,84 @@ static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionF |
| 18686 | 18360 | add_error_note(ira->codegen, msg, instruction->dest_child_type->source_node, |
| 18687 | 18361 | buf_sprintf("%s has size %" ZIG_PRI_u64 "; remaining bytes: %" ZIG_PRI_u64, |
| 18688 | 18362 | buf_ptr(&dest_child_type->name), child_type_size, remainder)); |
| 18689 | | return ira->codegen->builtin_types.entry_invalid; |
| 18363 | return ira->codegen->invalid_instruction; |
| 18690 | 18364 | } |
| 18691 | 18365 | } |
| 18692 | 18366 | |
| 18693 | | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, casted_value, dest_slice_type, CastOpResizeSlice, true); |
| 18694 | | ir_link_new_instruction(result, &instruction->base); |
| 18695 | | return dest_slice_type; |
| 18367 | return ir_resolve_cast(ira, &instruction->base, casted_value, dest_slice_type, CastOpResizeSlice, true); |
| 18696 | 18368 | } |
| 18697 | 18369 | |
| 18698 | | static ZigType *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) { |
| 18370 | static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) { |
| 18699 | 18371 | Error err; |
| 18700 | 18372 | |
| 18701 | | IrInstruction *target = instruction->target->other; |
| 18373 | IrInstruction *target = instruction->target->child; |
| 18702 | 18374 | if (type_is_invalid(target->value.type)) |
| 18703 | | return ira->codegen->builtin_types.entry_invalid; |
| 18375 | return ira->codegen->invalid_instruction; |
| 18704 | 18376 | |
| 18705 | 18377 | if (!is_slice(target->value.type)) { |
| 18706 | 18378 | ir_add_error(ira, instruction->target, |
| 18707 | 18379 | buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value.type->name))); |
| 18708 | | return ira->codegen->builtin_types.entry_invalid; |
| 18380 | return ira->codegen->invalid_instruction; |
| 18709 | 18381 | } |
| 18710 | 18382 | |
| 18711 | 18383 | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; |
| 18712 | 18384 | |
| 18713 | 18385 | uint32_t alignment; |
| 18714 | 18386 | if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment))) |
| 18715 | | return ira->codegen->builtin_types.entry_invalid; |
| 18387 | return ira->codegen->invalid_instruction; |
| 18716 | 18388 | |
| 18717 | 18389 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 18718 | 18390 | src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown, |
| 18719 | 18391 | alignment, 0, 0); |
| 18720 | 18392 | ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); |
| 18721 | 18393 | |
| 18722 | | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_slice_type, CastOpResizeSlice, true); |
| 18723 | | ir_link_new_instruction(result, &instruction->base); |
| 18724 | | return dest_slice_type; |
| 18394 | return ir_resolve_cast(ira, &instruction->base, target, dest_slice_type, CastOpResizeSlice, true); |
| 18725 | 18395 | } |
| 18726 | 18396 | |
| 18727 | | static ZigType *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) { |
| 18728 | | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18397 | static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) { |
| 18398 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 18729 | 18399 | if (type_is_invalid(dest_type)) |
| 18730 | | return ira->codegen->builtin_types.entry_invalid; |
| 18400 | return ira->codegen->invalid_instruction; |
| 18731 | 18401 | |
| 18732 | | IrInstruction *target = instruction->target->other; |
| 18402 | IrInstruction *target = instruction->target->child; |
| 18733 | 18403 | if (type_is_invalid(target->value.type)) |
| 18734 | | return ira->codegen->builtin_types.entry_invalid; |
| 18404 | return ira->codegen->invalid_instruction; |
| 18735 | 18405 | |
| 18736 | 18406 | if (target->value.type->id != ZigTypeIdInt && target->value.type->id != ZigTypeIdComptimeInt) { |
| 18737 | 18407 | ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'", |
| 18738 | 18408 | buf_ptr(&target->value.type->name))); |
| 18739 | | return ira->codegen->builtin_types.entry_invalid; |
| 18409 | return ira->codegen->invalid_instruction; |
| 18740 | 18410 | } |
| 18741 | 18411 | |
| 18742 | | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpIntToFloat, false); |
| 18743 | | ir_link_new_instruction(result, &instruction->base); |
| 18744 | | return dest_type; |
| 18412 | return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpIntToFloat, false); |
| 18745 | 18413 | } |
| 18746 | 18414 | |
| 18747 | | static ZigType *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) { |
| 18748 | | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); |
| 18415 | static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) { |
| 18416 | ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child); |
| 18749 | 18417 | if (type_is_invalid(dest_type)) |
| 18750 | | return ira->codegen->builtin_types.entry_invalid; |
| 18418 | return ira->codegen->invalid_instruction; |
| 18751 | 18419 | |
| 18752 | | IrInstruction *target = instruction->target->other; |
| 18420 | IrInstruction *target = instruction->target->child; |
| 18753 | 18421 | if (type_is_invalid(target->value.type)) |
| 18754 | | return ira->codegen->builtin_types.entry_invalid; |
| 18422 | return ira->codegen->invalid_instruction; |
| 18755 | 18423 | |
| 18756 | 18424 | if (target->value.type->id == ZigTypeIdComptimeInt) { |
| 18757 | | IrInstruction *casted_value = ir_implicit_cast(ira, target, dest_type); |
| 18758 | | if (type_is_invalid(casted_value->value.type)) |
| 18759 | | return ira->codegen->builtin_types.entry_invalid; |
| 18760 | | ir_link_new_instruction(casted_value, &instruction->base); |
| 18761 | | return casted_value->value.type; |
| 18425 | return ir_implicit_cast(ira, target, dest_type); |
| 18762 | 18426 | } |
| 18763 | 18427 | |
| 18764 | 18428 | if (target->value.type->id != ZigTypeIdFloat && target->value.type->id != ZigTypeIdComptimeFloat) { |
| 18765 | 18429 | ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", |
| 18766 | 18430 | buf_ptr(&target->value.type->name))); |
| 18767 | | return ira->codegen->builtin_types.entry_invalid; |
| 18431 | return ira->codegen->invalid_instruction; |
| 18768 | 18432 | } |
| 18769 | 18433 | |
| 18770 | | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false); |
| 18771 | | ir_link_new_instruction(result, &instruction->base); |
| 18772 | | return dest_type; |
| 18434 | return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpFloatToInt, false); |
| 18773 | 18435 | } |
| 18774 | 18436 | |
| 18775 | | static ZigType *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) { |
| 18776 | | IrInstruction *target = instruction->target->other; |
| 18437 | static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) { |
| 18438 | IrInstruction *target = instruction->target->child; |
| 18777 | 18439 | if (type_is_invalid(target->value.type)) |
| 18778 | | return ira->codegen->builtin_types.entry_invalid; |
| 18440 | return ira->codegen->invalid_instruction; |
| 18779 | 18441 | |
| 18780 | 18442 | IrInstruction *casted_target; |
| 18781 | 18443 | if (target->value.type->id == ZigTypeIdErrorSet) { |
| ... | ... | @@ -18783,110 +18445,100 @@ static ZigType *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionE |
| 18783 | 18445 | } else { |
| 18784 | 18446 | casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set); |
| 18785 | 18447 | if (type_is_invalid(casted_target->value.type)) |
| 18786 | | return ira->codegen->builtin_types.entry_invalid; |
| 18448 | return ira->codegen->invalid_instruction; |
| 18787 | 18449 | } |
| 18788 | 18450 | |
| 18789 | | IrInstruction *result = ir_analyze_err_to_int(ira, &instruction->base, casted_target, ira->codegen->err_tag_type); |
| 18790 | | ir_link_new_instruction(result, &instruction->base); |
| 18791 | | return result->value.type; |
| 18451 | return ir_analyze_err_to_int(ira, &instruction->base, casted_target, ira->codegen->err_tag_type); |
| 18792 | 18452 | } |
| 18793 | 18453 | |
| 18794 | | static ZigType *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) { |
| 18795 | | IrInstruction *target = instruction->target->other; |
| 18454 | static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) { |
| 18455 | IrInstruction *target = instruction->target->child; |
| 18796 | 18456 | if (type_is_invalid(target->value.type)) |
| 18797 | | return ira->codegen->builtin_types.entry_invalid; |
| 18457 | return ira->codegen->invalid_instruction; |
| 18798 | 18458 | |
| 18799 | 18459 | IrInstruction *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type); |
| 18800 | 18460 | if (type_is_invalid(casted_target->value.type)) |
| 18801 | | return ira->codegen->builtin_types.entry_invalid; |
| 18461 | return ira->codegen->invalid_instruction; |
| 18802 | 18462 | |
| 18803 | | IrInstruction *result = ir_analyze_int_to_err(ira, &instruction->base, casted_target, ira->codegen->builtin_types.entry_global_error_set); |
| 18804 | | ir_link_new_instruction(result, &instruction->base); |
| 18805 | | return result->value.type; |
| 18463 | return ir_analyze_int_to_err(ira, &instruction->base, casted_target, ira->codegen->builtin_types.entry_global_error_set); |
| 18806 | 18464 | } |
| 18807 | 18465 | |
| 18808 | | static ZigType *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) { |
| 18809 | | IrInstruction *target = instruction->target->other; |
| 18466 | static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) { |
| 18467 | IrInstruction *target = instruction->target->child; |
| 18810 | 18468 | if (type_is_invalid(target->value.type)) |
| 18811 | | return ira->codegen->builtin_types.entry_invalid; |
| 18469 | return ira->codegen->invalid_instruction; |
| 18812 | 18470 | |
| 18813 | 18471 | if (target->value.type->id != ZigTypeIdBool) { |
| 18814 | 18472 | ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'", |
| 18815 | 18473 | buf_ptr(&target->value.type->name))); |
| 18816 | | return ira->codegen->builtin_types.entry_invalid; |
| 18474 | return ira->codegen->invalid_instruction; |
| 18817 | 18475 | } |
| 18818 | 18476 | |
| 18819 | 18477 | if (instr_is_comptime(target)) { |
| 18820 | 18478 | bool is_true; |
| 18821 | 18479 | if (!ir_resolve_bool(ira, target, &is_true)) |
| 18822 | | return ira->codegen->builtin_types.entry_invalid; |
| 18480 | return ira->codegen->invalid_instruction; |
| 18823 | 18481 | |
| 18824 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 18825 | | bigint_init_unsigned(&out_val->data.x_bigint, is_true ? 1 : 0); |
| 18826 | | return ira->codegen->builtin_types.entry_num_lit_int; |
| 18482 | return ir_const_unsigned(ira, &instruction->base, is_true ? 1 : 0); |
| 18827 | 18483 | } |
| 18828 | 18484 | |
| 18829 | 18485 | ZigType *u1_type = get_int_type(ira->codegen, false, 1); |
| 18830 | | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt, false); |
| 18831 | | ir_link_new_instruction(result, &instruction->base); |
| 18832 | | return u1_type; |
| 18486 | return ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt, false); |
| 18833 | 18487 | } |
| 18834 | 18488 | |
| 18835 | | static ZigType *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) { |
| 18836 | | IrInstruction *is_signed_value = instruction->is_signed->other; |
| 18489 | static IrInstruction *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) { |
| 18490 | IrInstruction *is_signed_value = instruction->is_signed->child; |
| 18837 | 18491 | bool is_signed; |
| 18838 | 18492 | if (!ir_resolve_bool(ira, is_signed_value, &is_signed)) |
| 18839 | | return ira->codegen->builtin_types.entry_invalid; |
| 18493 | return ira->codegen->invalid_instruction; |
| 18840 | 18494 | |
| 18841 | | IrInstruction *bit_count_value = instruction->bit_count->other; |
| 18495 | IrInstruction *bit_count_value = instruction->bit_count->child; |
| 18842 | 18496 | uint64_t bit_count; |
| 18843 | 18497 | if (!ir_resolve_unsigned(ira, bit_count_value, ira->codegen->builtin_types.entry_u32, &bit_count)) |
| 18844 | | return ira->codegen->builtin_types.entry_invalid; |
| 18498 | return ira->codegen->invalid_instruction; |
| 18845 | 18499 | |
| 18846 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 18847 | | out_val->data.x_type = get_int_type(ira->codegen, is_signed, (uint32_t)bit_count); |
| 18848 | | return ira->codegen->builtin_types.entry_type; |
| 18500 | return ir_const_type(ira, &instruction->base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count)); |
| 18849 | 18501 | } |
| 18850 | 18502 | |
| 18851 | | static ZigType *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) { |
| 18852 | | IrInstruction *value = instruction->value->other; |
| 18503 | static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) { |
| 18504 | IrInstruction *value = instruction->value->child; |
| 18853 | 18505 | if (type_is_invalid(value->value.type)) |
| 18854 | | return ira->codegen->builtin_types.entry_invalid; |
| 18506 | return ira->codegen->invalid_instruction; |
| 18855 | 18507 | |
| 18856 | 18508 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 18857 | 18509 | |
| 18858 | 18510 | IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type); |
| 18859 | 18511 | if (type_is_invalid(casted_value->value.type)) |
| 18860 | | return ira->codegen->builtin_types.entry_invalid; |
| 18512 | return ira->codegen->invalid_instruction; |
| 18861 | 18513 | |
| 18862 | 18514 | if (instr_is_comptime(casted_value)) { |
| 18863 | 18515 | ConstExprValue *value = ir_resolve_const(ira, casted_value, UndefBad); |
| 18864 | 18516 | if (value == nullptr) |
| 18865 | | return ira->codegen->builtin_types.entry_invalid; |
| 18517 | return ira->codegen->invalid_instruction; |
| 18866 | 18518 | |
| 18867 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 18868 | | out_val->data.x_bool = !value->data.x_bool; |
| 18869 | | return bool_type; |
| 18519 | return ir_const_bool(ira, &instruction->base, !value->data.x_bool); |
| 18870 | 18520 | } |
| 18871 | 18521 | |
| 18872 | | ir_build_bool_not_from(&ira->new_irb, &instruction->base, casted_value); |
| 18873 | | return bool_type; |
| 18522 | IrInstruction *result = ir_build_bool_not(&ira->new_irb, instruction->base.scope, |
| 18523 | instruction->base.source_node, casted_value); |
| 18524 | result->value.type = bool_type; |
| 18525 | return result; |
| 18874 | 18526 | } |
| 18875 | 18527 | |
| 18876 | | static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) { |
| 18528 | static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) { |
| 18877 | 18529 | Error err; |
| 18878 | 18530 | |
| 18879 | | IrInstruction *dest_ptr = instruction->dest_ptr->other; |
| 18531 | IrInstruction *dest_ptr = instruction->dest_ptr->child; |
| 18880 | 18532 | if (type_is_invalid(dest_ptr->value.type)) |
| 18881 | | return ira->codegen->builtin_types.entry_invalid; |
| 18533 | return ira->codegen->invalid_instruction; |
| 18882 | 18534 | |
| 18883 | | IrInstruction *byte_value = instruction->byte->other; |
| 18535 | IrInstruction *byte_value = instruction->byte->child; |
| 18884 | 18536 | if (type_is_invalid(byte_value->value.type)) |
| 18885 | | return ira->codegen->builtin_types.entry_invalid; |
| 18537 | return ira->codegen->invalid_instruction; |
| 18886 | 18538 | |
| 18887 | | IrInstruction *count_value = instruction->count->other; |
| 18539 | IrInstruction *count_value = instruction->count->child; |
| 18888 | 18540 | if (type_is_invalid(count_value->value.type)) |
| 18889 | | return ira->codegen->builtin_types.entry_invalid; |
| 18541 | return ira->codegen->invalid_instruction; |
| 18890 | 18542 | |
| 18891 | 18543 | ZigType *dest_uncasted_type = dest_ptr->value.type; |
| 18892 | 18544 | bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && |
| ... | ... | @@ -18897,7 +18549,7 @@ static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemse |
| 18897 | 18549 | uint32_t dest_align; |
| 18898 | 18550 | if (dest_uncasted_type->id == ZigTypeIdPointer) { |
| 18899 | 18551 | if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align))) |
| 18900 | | return ira->codegen->builtin_types.entry_invalid; |
| 18552 | return ira->codegen->invalid_instruction; |
| 18901 | 18553 | } else { |
| 18902 | 18554 | dest_align = get_abi_alignment(ira->codegen, u8); |
| 18903 | 18555 | } |
| ... | ... | @@ -18906,15 +18558,15 @@ static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemse |
| 18906 | 18558 | |
| 18907 | 18559 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr); |
| 18908 | 18560 | if (type_is_invalid(casted_dest_ptr->value.type)) |
| 18909 | | return ira->codegen->builtin_types.entry_invalid; |
| 18561 | return ira->codegen->invalid_instruction; |
| 18910 | 18562 | |
| 18911 | 18563 | IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8); |
| 18912 | 18564 | if (type_is_invalid(casted_byte->value.type)) |
| 18913 | | return ira->codegen->builtin_types.entry_invalid; |
| 18565 | return ira->codegen->invalid_instruction; |
| 18914 | 18566 | |
| 18915 | 18567 | IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 18916 | 18568 | if (type_is_invalid(casted_count->value.type)) |
| 18917 | | return ira->codegen->builtin_types.entry_invalid; |
| 18569 | return ira->codegen->invalid_instruction; |
| 18918 | 18570 | |
| 18919 | 18571 | if (casted_dest_ptr->value.special == ConstValSpecialStatic && |
| 18920 | 18572 | casted_byte->value.special == ConstValSpecialStatic && |
| ... | ... | @@ -18956,7 +18608,7 @@ static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemse |
| 18956 | 18608 | size_t end = start + count; |
| 18957 | 18609 | if (end > bound_end) { |
| 18958 | 18610 | ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access")); |
| 18959 | | return ira->codegen->builtin_types.entry_invalid; |
| 18611 | return ira->codegen->invalid_instruction; |
| 18960 | 18612 | } |
| 18961 | 18613 | |
| 18962 | 18614 | ConstExprValue *byte_val = &casted_byte->value; |
| ... | ... | @@ -18964,28 +18616,29 @@ static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemse |
| 18964 | 18616 | dest_elements[i] = *byte_val; |
| 18965 | 18617 | } |
| 18966 | 18618 | |
| 18967 | | ir_build_const_from(ira, &instruction->base); |
| 18968 | | return ira->codegen->builtin_types.entry_void; |
| 18619 | return ir_const_void(ira, &instruction->base); |
| 18969 | 18620 | } |
| 18970 | 18621 | |
| 18971 | | ir_build_memset_from(&ira->new_irb, &instruction->base, casted_dest_ptr, casted_byte, casted_count); |
| 18972 | | return ira->codegen->builtin_types.entry_void; |
| 18622 | IrInstruction *result = ir_build_memset(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 18623 | casted_dest_ptr, casted_byte, casted_count); |
| 18624 | result->value.type = ira->codegen->builtin_types.entry_void; |
| 18625 | return result; |
| 18973 | 18626 | } |
| 18974 | 18627 | |
| 18975 | | static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) { |
| 18628 | static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) { |
| 18976 | 18629 | Error err; |
| 18977 | 18630 | |
| 18978 | | IrInstruction *dest_ptr = instruction->dest_ptr->other; |
| 18631 | IrInstruction *dest_ptr = instruction->dest_ptr->child; |
| 18979 | 18632 | if (type_is_invalid(dest_ptr->value.type)) |
| 18980 | | return ira->codegen->builtin_types.entry_invalid; |
| 18633 | return ira->codegen->invalid_instruction; |
| 18981 | 18634 | |
| 18982 | | IrInstruction *src_ptr = instruction->src_ptr->other; |
| 18635 | IrInstruction *src_ptr = instruction->src_ptr->child; |
| 18983 | 18636 | if (type_is_invalid(src_ptr->value.type)) |
| 18984 | | return ira->codegen->builtin_types.entry_invalid; |
| 18637 | return ira->codegen->invalid_instruction; |
| 18985 | 18638 | |
| 18986 | | IrInstruction *count_value = instruction->count->other; |
| 18639 | IrInstruction *count_value = instruction->count->child; |
| 18987 | 18640 | if (type_is_invalid(count_value->value.type)) |
| 18988 | | return ira->codegen->builtin_types.entry_invalid; |
| 18641 | return ira->codegen->invalid_instruction; |
| 18989 | 18642 | |
| 18990 | 18643 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 18991 | 18644 | ZigType *dest_uncasted_type = dest_ptr->value.type; |
| ... | ... | @@ -18998,7 +18651,7 @@ static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcp |
| 18998 | 18651 | uint32_t dest_align; |
| 18999 | 18652 | if (dest_uncasted_type->id == ZigTypeIdPointer) { |
| 19000 | 18653 | if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align))) |
| 19001 | | return ira->codegen->builtin_types.entry_invalid; |
| 18654 | return ira->codegen->invalid_instruction; |
| 19002 | 18655 | } else { |
| 19003 | 18656 | dest_align = get_abi_alignment(ira->codegen, u8); |
| 19004 | 18657 | } |
| ... | ... | @@ -19006,7 +18659,7 @@ static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcp |
| 19006 | 18659 | uint32_t src_align; |
| 19007 | 18660 | if (src_uncasted_type->id == ZigTypeIdPointer) { |
| 19008 | 18661 | if ((err = resolve_ptr_align(ira, src_uncasted_type, &src_align))) |
| 19009 | | return ira->codegen->builtin_types.entry_invalid; |
| 18662 | return ira->codegen->invalid_instruction; |
| 19010 | 18663 | } else { |
| 19011 | 18664 | src_align = get_abi_alignment(ira->codegen, u8); |
| 19012 | 18665 | } |
| ... | ... | @@ -19019,15 +18672,15 @@ static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcp |
| 19019 | 18672 | |
| 19020 | 18673 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut); |
| 19021 | 18674 | if (type_is_invalid(casted_dest_ptr->value.type)) |
| 19022 | | return ira->codegen->builtin_types.entry_invalid; |
| 18675 | return ira->codegen->invalid_instruction; |
| 19023 | 18676 | |
| 19024 | 18677 | IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const); |
| 19025 | 18678 | if (type_is_invalid(casted_src_ptr->value.type)) |
| 19026 | | return ira->codegen->builtin_types.entry_invalid; |
| 18679 | return ira->codegen->invalid_instruction; |
| 19027 | 18680 | |
| 19028 | 18681 | IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 19029 | 18682 | if (type_is_invalid(casted_count->value.type)) |
| 19030 | | return ira->codegen->builtin_types.entry_invalid; |
| 18683 | return ira->codegen->invalid_instruction; |
| 19031 | 18684 | |
| 19032 | 18685 | if (casted_dest_ptr->value.special == ConstValSpecialStatic && |
| 19033 | 18686 | casted_src_ptr->value.special == ConstValSpecialStatic && |
| ... | ... | @@ -19068,7 +18721,7 @@ static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcp |
| 19068 | 18721 | |
| 19069 | 18722 | if (dest_start + count > dest_end) { |
| 19070 | 18723 | ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds pointer access")); |
| 19071 | | return ira->codegen->builtin_types.entry_invalid; |
| 18724 | return ira->codegen->invalid_instruction; |
| 19072 | 18725 | } |
| 19073 | 18726 | |
| 19074 | 18727 | ConstExprValue *src_ptr_val = &casted_src_ptr->value; |
| ... | ... | @@ -19104,7 +18757,7 @@ static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcp |
| 19104 | 18757 | |
| 19105 | 18758 | if (src_start + count > src_end) { |
| 19106 | 18759 | ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds pointer access")); |
| 19107 | | return ira->codegen->builtin_types.entry_invalid; |
| 18760 | return ira->codegen->invalid_instruction; |
| 19108 | 18761 | } |
| 19109 | 18762 | |
| 19110 | 18763 | // TODO check for noalias violations - this should be generalized to work for any function |
| ... | ... | @@ -19113,40 +18766,41 @@ static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcp |
| 19113 | 18766 | dest_elements[dest_start + i] = src_elements[src_start + i]; |
| 19114 | 18767 | } |
| 19115 | 18768 | |
| 19116 | | ir_build_const_from(ira, &instruction->base); |
| 19117 | | return ira->codegen->builtin_types.entry_void; |
| 18769 | return ir_const_void(ira, &instruction->base); |
| 19118 | 18770 | } |
| 19119 | 18771 | |
| 19120 | | ir_build_memcpy_from(&ira->new_irb, &instruction->base, casted_dest_ptr, casted_src_ptr, casted_count); |
| 19121 | | return ira->codegen->builtin_types.entry_void; |
| 18772 | IrInstruction *result = ir_build_memcpy(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 18773 | casted_dest_ptr, casted_src_ptr, casted_count); |
| 18774 | result->value.type = ira->codegen->builtin_types.entry_void; |
| 18775 | return result; |
| 19122 | 18776 | } |
| 19123 | 18777 | |
| 19124 | | static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) { |
| 19125 | | IrInstruction *ptr_ptr = instruction->ptr->other; |
| 18778 | static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) { |
| 18779 | IrInstruction *ptr_ptr = instruction->ptr->child; |
| 19126 | 18780 | if (type_is_invalid(ptr_ptr->value.type)) |
| 19127 | | return ira->codegen->builtin_types.entry_invalid; |
| 18781 | return ira->codegen->invalid_instruction; |
| 19128 | 18782 | |
| 19129 | 18783 | ZigType *ptr_type = ptr_ptr->value.type; |
| 19130 | 18784 | assert(ptr_type->id == ZigTypeIdPointer); |
| 19131 | 18785 | ZigType *array_type = ptr_type->data.pointer.child_type; |
| 19132 | 18786 | |
| 19133 | | IrInstruction *start = instruction->start->other; |
| 18787 | IrInstruction *start = instruction->start->child; |
| 19134 | 18788 | if (type_is_invalid(start->value.type)) |
| 19135 | | return ira->codegen->builtin_types.entry_invalid; |
| 18789 | return ira->codegen->invalid_instruction; |
| 19136 | 18790 | |
| 19137 | 18791 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 19138 | 18792 | IrInstruction *casted_start = ir_implicit_cast(ira, start, usize); |
| 19139 | 18793 | if (type_is_invalid(casted_start->value.type)) |
| 19140 | | return ira->codegen->builtin_types.entry_invalid; |
| 18794 | return ira->codegen->invalid_instruction; |
| 19141 | 18795 | |
| 19142 | 18796 | IrInstruction *end; |
| 19143 | 18797 | if (instruction->end) { |
| 19144 | | end = instruction->end->other; |
| 18798 | end = instruction->end->child; |
| 19145 | 18799 | if (type_is_invalid(end->value.type)) |
| 19146 | | return ira->codegen->builtin_types.entry_invalid; |
| 18800 | return ira->codegen->invalid_instruction; |
| 19147 | 18801 | end = ir_implicit_cast(ira, end, usize); |
| 19148 | 18802 | if (type_is_invalid(end->value.type)) |
| 19149 | | return ira->codegen->builtin_types.entry_invalid; |
| 18803 | return ira->codegen->invalid_instruction; |
| 19150 | 18804 | } else { |
| 19151 | 18805 | end = nullptr; |
| 19152 | 18806 | } |
| ... | ... | @@ -19174,13 +18828,13 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 19174 | 18828 | return_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 19175 | 18829 | } else { |
| 19176 | 18830 | ir_add_error(ira, &instruction->base, buf_sprintf("slice of single-item pointer")); |
| 19177 | | return ira->codegen->builtin_types.entry_invalid; |
| 18831 | return ira->codegen->invalid_instruction; |
| 19178 | 18832 | } |
| 19179 | 18833 | } else { |
| 19180 | 18834 | return_type = get_slice_type(ira->codegen, array_type); |
| 19181 | 18835 | if (!end) { |
| 19182 | 18836 | ir_add_error(ira, &instruction->base, buf_sprintf("slice of pointer must include end value")); |
| 19183 | | return ira->codegen->builtin_types.entry_invalid; |
| 18837 | return ira->codegen->invalid_instruction; |
| 19184 | 18838 | } |
| 19185 | 18839 | } |
| 19186 | 18840 | } else if (is_slice(array_type)) { |
| ... | ... | @@ -19189,7 +18843,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 19189 | 18843 | } else { |
| 19190 | 18844 | ir_add_error(ira, &instruction->base, |
| 19191 | 18845 | buf_sprintf("slice of non-array type '%s'", buf_ptr(&array_type->name))); |
| 19192 | | return ira->codegen->builtin_types.entry_invalid; |
| 18846 | return ira->codegen->invalid_instruction; |
| 19193 | 18847 | } |
| 19194 | 18848 | |
| 19195 | 18849 | if (instr_is_comptime(ptr_ptr) && |
| ... | ... | @@ -19209,18 +18863,18 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 19209 | 18863 | assert(child_array_type->id == ZigTypeIdArray); |
| 19210 | 18864 | parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node); |
| 19211 | 18865 | if (parent_ptr == nullptr) |
| 19212 | | return ira->codegen->builtin_types.entry_invalid; |
| 18866 | return ira->codegen->invalid_instruction; |
| 19213 | 18867 | |
| 19214 | 18868 | array_val = ir_const_ptr_pointee(ira, parent_ptr, instruction->base.source_node); |
| 19215 | 18869 | if (array_val == nullptr) |
| 19216 | | return ira->codegen->builtin_types.entry_invalid; |
| 18870 | return ira->codegen->invalid_instruction; |
| 19217 | 18871 | |
| 19218 | 18872 | rel_end = child_array_type->data.array.len; |
| 19219 | 18873 | abs_offset = 0; |
| 19220 | 18874 | } else { |
| 19221 | 18875 | array_val = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node); |
| 19222 | 18876 | if (array_val == nullptr) |
| 19223 | | return ira->codegen->builtin_types.entry_invalid; |
| 18877 | return ira->codegen->invalid_instruction; |
| 19224 | 18878 | rel_end = array_type->data.array.len; |
| 19225 | 18879 | parent_ptr = nullptr; |
| 19226 | 18880 | abs_offset = 0; |
| ... | ... | @@ -19229,7 +18883,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 19229 | 18883 | assert(array_type->data.pointer.ptr_len == PtrLenUnknown); |
| 19230 | 18884 | parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node); |
| 19231 | 18885 | if (parent_ptr == nullptr) |
| 19232 | | return ira->codegen->builtin_types.entry_invalid; |
| 18886 | return ira->codegen->invalid_instruction; |
| 19233 | 18887 | |
| 19234 | 18888 | if (parent_ptr->special == ConstValSpecialUndef) { |
| 19235 | 18889 | array_val = nullptr; |
| ... | ... | @@ -19269,12 +18923,12 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 19269 | 18923 | } else if (is_slice(array_type)) { |
| 19270 | 18924 | ConstExprValue *slice_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node); |
| 19271 | 18925 | if (slice_ptr == nullptr) |
| 19272 | | return ira->codegen->builtin_types.entry_invalid; |
| 18926 | return ira->codegen->invalid_instruction; |
| 19273 | 18927 | |
| 19274 | 18928 | parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index]; |
| 19275 | 18929 | if (parent_ptr->special == ConstValSpecialUndef) { |
| 19276 | 18930 | ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined")); |
| 19277 | | return ira->codegen->builtin_types.entry_invalid; |
| 18931 | return ira->codegen->invalid_instruction; |
| 19278 | 18932 | } |
| 19279 | 18933 | |
| 19280 | 18934 | ConstExprValue *len_val = &slice_ptr->data.x_struct.fields[slice_len_index]; |
| ... | ... | @@ -19310,7 +18964,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 19310 | 18964 | uint64_t start_scalar = bigint_as_unsigned(&casted_start->value.data.x_bigint); |
| 19311 | 18965 | if (!ptr_is_undef && start_scalar > rel_end) { |
| 19312 | 18966 | ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice")); |
| 19313 | | return ira->codegen->builtin_types.entry_invalid; |
| 18967 | return ira->codegen->invalid_instruction; |
| 19314 | 18968 | } |
| 19315 | 18969 | |
| 19316 | 18970 | uint64_t end_scalar; |
| ... | ... | @@ -19322,19 +18976,20 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 19322 | 18976 | if (!ptr_is_undef) { |
| 19323 | 18977 | if (end_scalar > rel_end) { |
| 19324 | 18978 | ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice")); |
| 19325 | | return ira->codegen->builtin_types.entry_invalid; |
| 18979 | return ira->codegen->invalid_instruction; |
| 19326 | 18980 | } |
| 19327 | 18981 | if (start_scalar > end_scalar) { |
| 19328 | 18982 | ir_add_error(ira, &instruction->base, buf_sprintf("slice start is greater than end")); |
| 19329 | | return ira->codegen->builtin_types.entry_invalid; |
| 18983 | return ira->codegen->invalid_instruction; |
| 19330 | 18984 | } |
| 19331 | 18985 | } |
| 19332 | 18986 | if (ptr_is_undef && start_scalar != end_scalar) { |
| 19333 | 18987 | ir_add_error(ira, &instruction->base, buf_sprintf("non-zero length slice of undefined pointer")); |
| 19334 | | return ira->codegen->builtin_types.entry_invalid; |
| 18988 | return ira->codegen->invalid_instruction; |
| 19335 | 18989 | } |
| 19336 | 18990 | |
| 19337 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 18991 | IrInstruction *result = ir_const(ira, &instruction->base, return_type); |
| 18992 | ConstExprValue *out_val = &result->value; |
| 19338 | 18993 | out_val->data.x_struct.fields = create_const_vals(2); |
| 19339 | 18994 | |
| 19340 | 18995 | ConstExprValue *ptr_val = &out_val->data.x_struct.fields[slice_ptr_index]; |
| ... | ... | @@ -19379,29 +19034,30 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 19379 | 19034 | ConstExprValue *len_val = &out_val->data.x_struct.fields[slice_len_index]; |
| 19380 | 19035 | init_const_usize(ira->codegen, len_val, end_scalar - start_scalar); |
| 19381 | 19036 | |
| 19382 | | return return_type; |
| 19037 | return result; |
| 19383 | 19038 | } |
| 19384 | 19039 | |
| 19385 | | IrInstruction *new_instruction = ir_build_slice_from(&ira->new_irb, &instruction->base, ptr_ptr, |
| 19386 | | casted_start, end, instruction->safety_check_on); |
| 19040 | IrInstruction *new_instruction = ir_build_slice(&ira->new_irb, |
| 19041 | instruction->base.scope, instruction->base.source_node, |
| 19042 | ptr_ptr, casted_start, end, instruction->safety_check_on); |
| 19043 | new_instruction->value.type = return_type; |
| 19387 | 19044 | ir_add_alloca(ira, new_instruction, return_type); |
| 19388 | | |
| 19389 | | return return_type; |
| 19045 | return new_instruction; |
| 19390 | 19046 | } |
| 19391 | 19047 | |
| 19392 | | static ZigType *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) { |
| 19048 | static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) { |
| 19393 | 19049 | Error err; |
| 19394 | | IrInstruction *container = instruction->container->other; |
| 19050 | IrInstruction *container = instruction->container->child; |
| 19395 | 19051 | if (type_is_invalid(container->value.type)) |
| 19396 | | return ira->codegen->builtin_types.entry_invalid; |
| 19052 | return ira->codegen->invalid_instruction; |
| 19397 | 19053 | ZigType *container_type = ir_resolve_type(ira, container); |
| 19398 | 19054 | |
| 19399 | 19055 | if ((err = ensure_complete_type(ira->codegen, container_type))) |
| 19400 | | return ira->codegen->builtin_types.entry_invalid; |
| 19056 | return ira->codegen->invalid_instruction; |
| 19401 | 19057 | |
| 19402 | 19058 | uint64_t result; |
| 19403 | 19059 | if (type_is_invalid(container_type)) { |
| 19404 | | return ira->codegen->builtin_types.entry_invalid; |
| 19060 | return ira->codegen->invalid_instruction; |
| 19405 | 19061 | } else if (container_type->id == ZigTypeIdEnum) { |
| 19406 | 19062 | result = container_type->data.enumeration.src_field_count; |
| 19407 | 19063 | } else if (container_type->id == ZigTypeIdStruct) { |
| ... | ... | @@ -19410,166 +19066,164 @@ static ZigType *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructio |
| 19410 | 19066 | result = container_type->data.unionation.src_field_count; |
| 19411 | 19067 | } else if (container_type->id == ZigTypeIdErrorSet) { |
| 19412 | 19068 | if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) { |
| 19413 | | return ira->codegen->builtin_types.entry_invalid; |
| 19069 | return ira->codegen->invalid_instruction; |
| 19414 | 19070 | } |
| 19415 | 19071 | if (type_is_global_error_set(container_type)) { |
| 19416 | 19072 | ir_add_error(ira, &instruction->base, buf_sprintf("global error set member count not available at comptime")); |
| 19417 | | return ira->codegen->builtin_types.entry_invalid; |
| 19073 | return ira->codegen->invalid_instruction; |
| 19418 | 19074 | } |
| 19419 | 19075 | result = container_type->data.error_set.err_count; |
| 19420 | 19076 | } else { |
| 19421 | 19077 | ir_add_error(ira, &instruction->base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name))); |
| 19422 | | return ira->codegen->builtin_types.entry_invalid; |
| 19078 | return ira->codegen->invalid_instruction; |
| 19423 | 19079 | } |
| 19424 | 19080 | |
| 19425 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19426 | | bigint_init_unsigned(&out_val->data.x_bigint, result); |
| 19427 | | return ira->codegen->builtin_types.entry_num_lit_int; |
| 19081 | return ir_const_unsigned(ira, &instruction->base, result); |
| 19428 | 19082 | } |
| 19429 | 19083 | |
| 19430 | | static ZigType *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) { |
| 19084 | static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) { |
| 19431 | 19085 | Error err; |
| 19432 | | IrInstruction *container_type_value = instruction->container_type->other; |
| 19086 | IrInstruction *container_type_value = instruction->container_type->child; |
| 19433 | 19087 | ZigType *container_type = ir_resolve_type(ira, container_type_value); |
| 19434 | 19088 | if (type_is_invalid(container_type)) |
| 19435 | | return ira->codegen->builtin_types.entry_invalid; |
| 19089 | return ira->codegen->invalid_instruction; |
| 19436 | 19090 | |
| 19437 | 19091 | if ((err = ensure_complete_type(ira->codegen, container_type))) |
| 19438 | | return ira->codegen->builtin_types.entry_invalid; |
| 19092 | return ira->codegen->invalid_instruction; |
| 19439 | 19093 | |
| 19440 | 19094 | |
| 19441 | 19095 | uint64_t member_index; |
| 19442 | | IrInstruction *index_value = instruction->member_index->other; |
| 19096 | IrInstruction *index_value = instruction->member_index->child; |
| 19443 | 19097 | if (!ir_resolve_usize(ira, index_value, &member_index)) |
| 19444 | | return ira->codegen->builtin_types.entry_invalid; |
| 19098 | return ira->codegen->invalid_instruction; |
| 19445 | 19099 | |
| 19446 | 19100 | if (container_type->id == ZigTypeIdStruct) { |
| 19447 | 19101 | if (member_index >= container_type->data.structure.src_field_count) { |
| 19448 | 19102 | ir_add_error(ira, index_value, |
| 19449 | 19103 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 19450 | 19104 | member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count)); |
| 19451 | | return ira->codegen->builtin_types.entry_invalid; |
| 19105 | return ira->codegen->invalid_instruction; |
| 19452 | 19106 | } |
| 19453 | 19107 | TypeStructField *field = &container_type->data.structure.fields[member_index]; |
| 19454 | 19108 | |
| 19455 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19456 | | out_val->data.x_type = field->type_entry; |
| 19457 | | return ira->codegen->builtin_types.entry_type; |
| 19109 | return ir_const_type(ira, &instruction->base, field->type_entry); |
| 19458 | 19110 | } else if (container_type->id == ZigTypeIdUnion) { |
| 19459 | 19111 | if (member_index >= container_type->data.unionation.src_field_count) { |
| 19460 | 19112 | ir_add_error(ira, index_value, |
| 19461 | 19113 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 19462 | 19114 | member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count)); |
| 19463 | | return ira->codegen->builtin_types.entry_invalid; |
| 19115 | return ira->codegen->invalid_instruction; |
| 19464 | 19116 | } |
| 19465 | 19117 | TypeUnionField *field = &container_type->data.unionation.fields[member_index]; |
| 19466 | 19118 | |
| 19467 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19468 | | out_val->data.x_type = field->type_entry; |
| 19469 | | return ira->codegen->builtin_types.entry_type; |
| 19119 | return ir_const_type(ira, &instruction->base, field->type_entry); |
| 19470 | 19120 | } else { |
| 19471 | 19121 | ir_add_error(ira, container_type_value, |
| 19472 | 19122 | buf_sprintf("type '%s' does not support @memberType", buf_ptr(&container_type->name))); |
| 19473 | | return ira->codegen->builtin_types.entry_invalid; |
| 19123 | return ira->codegen->invalid_instruction; |
| 19474 | 19124 | } |
| 19475 | 19125 | } |
| 19476 | 19126 | |
| 19477 | | static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) { |
| 19127 | static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) { |
| 19478 | 19128 | Error err; |
| 19479 | | IrInstruction *container_type_value = instruction->container_type->other; |
| 19129 | IrInstruction *container_type_value = instruction->container_type->child; |
| 19480 | 19130 | ZigType *container_type = ir_resolve_type(ira, container_type_value); |
| 19481 | 19131 | if (type_is_invalid(container_type)) |
| 19482 | | return ira->codegen->builtin_types.entry_invalid; |
| 19132 | return ira->codegen->invalid_instruction; |
| 19483 | 19133 | |
| 19484 | 19134 | if ((err = ensure_complete_type(ira->codegen, container_type))) |
| 19485 | | return ira->codegen->builtin_types.entry_invalid; |
| 19135 | return ira->codegen->invalid_instruction; |
| 19486 | 19136 | |
| 19487 | 19137 | uint64_t member_index; |
| 19488 | | IrInstruction *index_value = instruction->member_index->other; |
| 19138 | IrInstruction *index_value = instruction->member_index->child; |
| 19489 | 19139 | if (!ir_resolve_usize(ira, index_value, &member_index)) |
| 19490 | | return ira->codegen->builtin_types.entry_invalid; |
| 19140 | return ira->codegen->invalid_instruction; |
| 19491 | 19141 | |
| 19492 | 19142 | if (container_type->id == ZigTypeIdStruct) { |
| 19493 | 19143 | if (member_index >= container_type->data.structure.src_field_count) { |
| 19494 | 19144 | ir_add_error(ira, index_value, |
| 19495 | 19145 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 19496 | 19146 | member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count)); |
| 19497 | | return ira->codegen->builtin_types.entry_invalid; |
| 19147 | return ira->codegen->invalid_instruction; |
| 19498 | 19148 | } |
| 19499 | 19149 | TypeStructField *field = &container_type->data.structure.fields[member_index]; |
| 19500 | 19150 | |
| 19501 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19502 | | init_const_str_lit(ira->codegen, out_val, field->name); |
| 19503 | | return out_val->type; |
| 19151 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 19152 | init_const_str_lit(ira->codegen, &result->value, field->name); |
| 19153 | return result; |
| 19504 | 19154 | } else if (container_type->id == ZigTypeIdEnum) { |
| 19505 | 19155 | if (member_index >= container_type->data.enumeration.src_field_count) { |
| 19506 | 19156 | ir_add_error(ira, index_value, |
| 19507 | 19157 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 19508 | 19158 | member_index, buf_ptr(&container_type->name), container_type->data.enumeration.src_field_count)); |
| 19509 | | return ira->codegen->builtin_types.entry_invalid; |
| 19159 | return ira->codegen->invalid_instruction; |
| 19510 | 19160 | } |
| 19511 | 19161 | TypeEnumField *field = &container_type->data.enumeration.fields[member_index]; |
| 19512 | 19162 | |
| 19513 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19514 | | init_const_str_lit(ira->codegen, out_val, field->name); |
| 19515 | | return out_val->type; |
| 19163 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 19164 | init_const_str_lit(ira->codegen, &result->value, field->name); |
| 19165 | return result; |
| 19516 | 19166 | } else if (container_type->id == ZigTypeIdUnion) { |
| 19517 | 19167 | if (member_index >= container_type->data.unionation.src_field_count) { |
| 19518 | 19168 | ir_add_error(ira, index_value, |
| 19519 | 19169 | buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", |
| 19520 | 19170 | member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count)); |
| 19521 | | return ira->codegen->builtin_types.entry_invalid; |
| 19171 | return ira->codegen->invalid_instruction; |
| 19522 | 19172 | } |
| 19523 | 19173 | TypeUnionField *field = &container_type->data.unionation.fields[member_index]; |
| 19524 | 19174 | |
| 19525 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19526 | | init_const_str_lit(ira->codegen, out_val, field->name); |
| 19527 | | return out_val->type; |
| 19175 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 19176 | init_const_str_lit(ira->codegen, &result->value, field->name); |
| 19177 | return result; |
| 19528 | 19178 | } else { |
| 19529 | 19179 | ir_add_error(ira, container_type_value, |
| 19530 | 19180 | buf_sprintf("type '%s' does not support @memberName", buf_ptr(&container_type->name))); |
| 19531 | | return ira->codegen->builtin_types.entry_invalid; |
| 19181 | return ira->codegen->invalid_instruction; |
| 19532 | 19182 | } |
| 19533 | 19183 | } |
| 19534 | 19184 | |
| 19535 | | static ZigType *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) { |
| 19536 | | ir_build_breakpoint_from(&ira->new_irb, &instruction->base); |
| 19537 | | return ira->codegen->builtin_types.entry_void; |
| 19185 | static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) { |
| 19186 | IrInstruction *result = ir_build_breakpoint(&ira->new_irb, |
| 19187 | instruction->base.scope, instruction->base.source_node); |
| 19188 | result->value.type = ira->codegen->builtin_types.entry_void; |
| 19189 | return result; |
| 19538 | 19190 | } |
| 19539 | 19191 | |
| 19540 | | static ZigType *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) { |
| 19541 | | ir_build_return_address_from(&ira->new_irb, &instruction->base); |
| 19542 | | |
| 19192 | static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) { |
| 19193 | IrInstruction *result = ir_build_return_address(&ira->new_irb, |
| 19194 | instruction->base.scope, instruction->base.source_node); |
| 19543 | 19195 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 19544 | 19196 | ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); |
| 19545 | | return u8_ptr_const; |
| 19197 | result->value.type = u8_ptr_const; |
| 19198 | return result; |
| 19546 | 19199 | } |
| 19547 | 19200 | |
| 19548 | | static ZigType *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) { |
| 19549 | | ir_build_frame_address_from(&ira->new_irb, &instruction->base); |
| 19550 | | |
| 19201 | static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) { |
| 19202 | IrInstruction *result = ir_build_frame_address(&ira->new_irb, |
| 19203 | instruction->base.scope, instruction->base.source_node); |
| 19551 | 19204 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 19552 | 19205 | ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); |
| 19553 | | return u8_ptr_const; |
| 19206 | result->value.type = u8_ptr_const; |
| 19207 | return result; |
| 19554 | 19208 | } |
| 19555 | 19209 | |
| 19556 | | static ZigType *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) { |
| 19557 | | ir_build_handle_from(&ira->new_irb, &instruction->base); |
| 19558 | | |
| 19210 | static IrInstruction *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) { |
| 19211 | IrInstruction *result = ir_build_handle(&ira->new_irb, instruction->base.scope, instruction->base.source_node); |
| 19559 | 19212 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 19560 | 19213 | assert(fn_entry != nullptr); |
| 19561 | | return get_promise_type(ira->codegen, fn_entry->type_entry->data.fn.fn_type_id.return_type); |
| 19214 | result->value.type = get_promise_type(ira->codegen, fn_entry->type_entry->data.fn.fn_type_id.return_type); |
| 19215 | return result; |
| 19562 | 19216 | } |
| 19563 | 19217 | |
| 19564 | | static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) { |
| 19218 | static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) { |
| 19565 | 19219 | Error err; |
| 19566 | | IrInstruction *type_value = instruction->type_value->other; |
| 19220 | IrInstruction *type_value = instruction->type_value->child; |
| 19567 | 19221 | if (type_is_invalid(type_value->value.type)) |
| 19568 | | return ira->codegen->builtin_types.entry_invalid; |
| 19222 | return ira->codegen->invalid_instruction; |
| 19569 | 19223 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 19570 | 19224 | |
| 19571 | 19225 | if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusAlignmentKnown))) |
| 19572 | | return ira->codegen->builtin_types.entry_invalid; |
| 19226 | return ira->codegen->invalid_instruction; |
| 19573 | 19227 | |
| 19574 | 19228 | switch (type_entry->id) { |
| 19575 | 19229 | case ZigTypeIdInvalid: |
| ... | ... | @@ -19587,7 +19241,7 @@ static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAli |
| 19587 | 19241 | case ZigTypeIdOpaque: |
| 19588 | 19242 | ir_add_error(ira, instruction->type_value, |
| 19589 | 19243 | buf_sprintf("no align available for type '%s'", buf_ptr(&type_entry->name))); |
| 19590 | | return ira->codegen->builtin_types.entry_invalid; |
| 19244 | return ira->codegen->invalid_instruction; |
| 19591 | 19245 | case ZigTypeIdBool: |
| 19592 | 19246 | case ZigTypeIdInt: |
| 19593 | 19247 | case ZigTypeIdFloat: |
| ... | ... | @@ -19603,42 +19257,40 @@ static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAli |
| 19603 | 19257 | case ZigTypeIdFn: |
| 19604 | 19258 | { |
| 19605 | 19259 | uint64_t align_in_bytes = get_abi_alignment(ira->codegen, type_entry); |
| 19606 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19607 | | bigint_init_unsigned(&out_val->data.x_bigint, align_in_bytes); |
| 19608 | | return ira->codegen->builtin_types.entry_num_lit_int; |
| 19260 | return ir_const_unsigned(ira, &instruction->base, align_in_bytes); |
| 19609 | 19261 | } |
| 19610 | 19262 | } |
| 19611 | 19263 | zig_unreachable(); |
| 19612 | 19264 | } |
| 19613 | 19265 | |
| 19614 | | static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) { |
| 19266 | static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) { |
| 19615 | 19267 | Error err; |
| 19616 | 19268 | |
| 19617 | | IrInstruction *type_value = instruction->type_value->other; |
| 19269 | IrInstruction *type_value = instruction->type_value->child; |
| 19618 | 19270 | if (type_is_invalid(type_value->value.type)) |
| 19619 | | return ira->codegen->builtin_types.entry_invalid; |
| 19271 | return ira->codegen->invalid_instruction; |
| 19620 | 19272 | |
| 19621 | 19273 | ZigType *dest_type = ir_resolve_type(ira, type_value); |
| 19622 | 19274 | if (type_is_invalid(dest_type)) |
| 19623 | | return ira->codegen->builtin_types.entry_invalid; |
| 19275 | return ira->codegen->invalid_instruction; |
| 19624 | 19276 | |
| 19625 | 19277 | if (dest_type->id != ZigTypeIdInt) { |
| 19626 | 19278 | ir_add_error(ira, type_value, |
| 19627 | 19279 | buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); |
| 19628 | | return ira->codegen->builtin_types.entry_invalid; |
| 19280 | return ira->codegen->invalid_instruction; |
| 19629 | 19281 | } |
| 19630 | 19282 | |
| 19631 | | IrInstruction *op1 = instruction->op1->other; |
| 19283 | IrInstruction *op1 = instruction->op1->child; |
| 19632 | 19284 | if (type_is_invalid(op1->value.type)) |
| 19633 | | return ira->codegen->builtin_types.entry_invalid; |
| 19285 | return ira->codegen->invalid_instruction; |
| 19634 | 19286 | |
| 19635 | 19287 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 19636 | 19288 | if (type_is_invalid(casted_op1->value.type)) |
| 19637 | | return ira->codegen->builtin_types.entry_invalid; |
| 19289 | return ira->codegen->invalid_instruction; |
| 19638 | 19290 | |
| 19639 | | IrInstruction *op2 = instruction->op2->other; |
| 19291 | IrInstruction *op2 = instruction->op2->child; |
| 19640 | 19292 | if (type_is_invalid(op2->value.type)) |
| 19641 | | return ira->codegen->builtin_types.entry_invalid; |
| 19293 | return ira->codegen->invalid_instruction; |
| 19642 | 19294 | |
| 19643 | 19295 | IrInstruction *casted_op2; |
| 19644 | 19296 | if (instruction->op == IrOverflowOpShl) { |
| ... | ... | @@ -19649,17 +19301,17 @@ static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstruction |
| 19649 | 19301 | casted_op2 = ir_implicit_cast(ira, op2, dest_type); |
| 19650 | 19302 | } |
| 19651 | 19303 | if (type_is_invalid(casted_op2->value.type)) |
| 19652 | | return ira->codegen->builtin_types.entry_invalid; |
| 19304 | return ira->codegen->invalid_instruction; |
| 19653 | 19305 | |
| 19654 | | IrInstruction *result_ptr = instruction->result_ptr->other; |
| 19306 | IrInstruction *result_ptr = instruction->result_ptr->child; |
| 19655 | 19307 | if (type_is_invalid(result_ptr->value.type)) |
| 19656 | | return ira->codegen->builtin_types.entry_invalid; |
| 19308 | return ira->codegen->invalid_instruction; |
| 19657 | 19309 | |
| 19658 | 19310 | ZigType *expected_ptr_type; |
| 19659 | 19311 | if (result_ptr->value.type->id == ZigTypeIdPointer) { |
| 19660 | 19312 | uint32_t alignment; |
| 19661 | 19313 | if ((err = resolve_ptr_align(ira, result_ptr->value.type, &alignment))) |
| 19662 | | return ira->codegen->builtin_types.entry_invalid; |
| 19314 | return ira->codegen->invalid_instruction; |
| 19663 | 19315 | expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, |
| 19664 | 19316 | false, result_ptr->value.type->data.pointer.is_volatile, |
| 19665 | 19317 | PtrLenSingle, |
| ... | ... | @@ -19670,18 +19322,17 @@ static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstruction |
| 19670 | 19322 | |
| 19671 | 19323 | IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type); |
| 19672 | 19324 | if (type_is_invalid(casted_result_ptr->value.type)) |
| 19673 | | return ira->codegen->builtin_types.entry_invalid; |
| 19325 | return ira->codegen->invalid_instruction; |
| 19674 | 19326 | |
| 19675 | 19327 | if (casted_op1->value.special == ConstValSpecialStatic && |
| 19676 | 19328 | casted_op2->value.special == ConstValSpecialStatic && |
| 19677 | 19329 | casted_result_ptr->value.special == ConstValSpecialStatic) |
| 19678 | 19330 | { |
| 19679 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19680 | 19331 | BigInt *op1_bigint = &casted_op1->value.data.x_bigint; |
| 19681 | 19332 | BigInt *op2_bigint = &casted_op2->value.data.x_bigint; |
| 19682 | 19333 | ConstExprValue *pointee_val = ir_const_ptr_pointee(ira, &casted_result_ptr->value, casted_result_ptr->source_node); |
| 19683 | 19334 | if (pointee_val == nullptr) |
| 19684 | | return ira->codegen->builtin_types.entry_invalid; |
| 19335 | return ira->codegen->invalid_instruction; |
| 19685 | 19336 | BigInt *dest_bigint = &pointee_val->data.x_bigint; |
| 19686 | 19337 | switch (instruction->op) { |
| 19687 | 19338 | case IrOverflowOpAdd: |
| ... | ... | @@ -19697,77 +19348,74 @@ static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstruction |
| 19697 | 19348 | bigint_shl(dest_bigint, op1_bigint, op2_bigint); |
| 19698 | 19349 | break; |
| 19699 | 19350 | } |
| 19351 | bool result_bool = false; |
| 19700 | 19352 | if (!bigint_fits_in_bits(dest_bigint, dest_type->data.integral.bit_count, |
| 19701 | 19353 | dest_type->data.integral.is_signed)) |
| 19702 | 19354 | { |
| 19703 | | out_val->data.x_bool = true; |
| 19355 | result_bool = true; |
| 19704 | 19356 | BigInt tmp_bigint; |
| 19705 | 19357 | bigint_init_bigint(&tmp_bigint, dest_bigint); |
| 19706 | 19358 | bigint_truncate(dest_bigint, &tmp_bigint, dest_type->data.integral.bit_count, |
| 19707 | 19359 | dest_type->data.integral.is_signed); |
| 19708 | 19360 | } |
| 19709 | 19361 | pointee_val->special = ConstValSpecialStatic; |
| 19710 | | return ira->codegen->builtin_types.entry_bool; |
| 19362 | return ir_const_bool(ira, &instruction->base, result_bool); |
| 19711 | 19363 | } |
| 19712 | 19364 | |
| 19713 | | ir_build_overflow_op_from(&ira->new_irb, &instruction->base, instruction->op, type_value, |
| 19714 | | casted_op1, casted_op2, casted_result_ptr, dest_type); |
| 19715 | | return ira->codegen->builtin_types.entry_bool; |
| 19365 | IrInstruction *result = ir_build_overflow_op(&ira->new_irb, |
| 19366 | instruction->base.scope, instruction->base.source_node, |
| 19367 | instruction->op, type_value, casted_op1, casted_op2, casted_result_ptr, dest_type); |
| 19368 | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 19369 | return result; |
| 19716 | 19370 | } |
| 19717 | 19371 | |
| 19718 | | static ZigType *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) { |
| 19719 | | IrInstruction *value = instruction->value->other; |
| 19372 | static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) { |
| 19373 | IrInstruction *value = instruction->value->child; |
| 19720 | 19374 | if (type_is_invalid(value->value.type)) |
| 19721 | | return ira->codegen->builtin_types.entry_invalid; |
| 19375 | return ira->codegen->invalid_instruction; |
| 19722 | 19376 | |
| 19723 | 19377 | ZigType *type_entry = value->value.type; |
| 19724 | 19378 | if (type_is_invalid(type_entry)) { |
| 19725 | | return ira->codegen->builtin_types.entry_invalid; |
| 19379 | return ira->codegen->invalid_instruction; |
| 19726 | 19380 | } else if (type_entry->id == ZigTypeIdErrorUnion) { |
| 19727 | 19381 | if (instr_is_comptime(value)) { |
| 19728 | 19382 | ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad); |
| 19729 | 19383 | if (!err_union_val) |
| 19730 | | return ira->codegen->builtin_types.entry_invalid; |
| 19384 | return ira->codegen->invalid_instruction; |
| 19731 | 19385 | |
| 19732 | 19386 | if (err_union_val->special != ConstValSpecialRuntime) { |
| 19733 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19734 | | out_val->data.x_bool = (err_union_val->data.x_err_union.err != nullptr); |
| 19735 | | return ira->codegen->builtin_types.entry_bool; |
| 19387 | return ir_const_bool(ira, &instruction->base, (err_union_val->data.x_err_union.err != nullptr)); |
| 19736 | 19388 | } |
| 19737 | 19389 | } |
| 19738 | 19390 | |
| 19739 | 19391 | ZigType *err_set_type = type_entry->data.error_union.err_set_type; |
| 19740 | 19392 | if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) { |
| 19741 | | return ira->codegen->builtin_types.entry_invalid; |
| 19393 | return ira->codegen->invalid_instruction; |
| 19742 | 19394 | } |
| 19743 | 19395 | if (!type_is_global_error_set(err_set_type) && |
| 19744 | 19396 | err_set_type->data.error_set.err_count == 0) |
| 19745 | 19397 | { |
| 19746 | 19398 | assert(err_set_type->data.error_set.infer_fn == nullptr); |
| 19747 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19748 | | out_val->data.x_bool = false; |
| 19749 | | return ira->codegen->builtin_types.entry_bool; |
| 19399 | return ir_const_bool(ira, &instruction->base, false); |
| 19750 | 19400 | } |
| 19751 | 19401 | |
| 19752 | | ir_build_test_err_from(&ira->new_irb, &instruction->base, value); |
| 19753 | | return ira->codegen->builtin_types.entry_bool; |
| 19402 | IrInstruction *result = ir_build_test_err(&ira->new_irb, |
| 19403 | instruction->base.scope, instruction->base.source_node, value); |
| 19404 | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 19405 | return result; |
| 19754 | 19406 | } else if (type_entry->id == ZigTypeIdErrorSet) { |
| 19755 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19756 | | out_val->data.x_bool = true; |
| 19757 | | return ira->codegen->builtin_types.entry_bool; |
| 19407 | return ir_const_bool(ira, &instruction->base, true); |
| 19758 | 19408 | } else { |
| 19759 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19760 | | out_val->data.x_bool = false; |
| 19761 | | return ira->codegen->builtin_types.entry_bool; |
| 19409 | return ir_const_bool(ira, &instruction->base, false); |
| 19762 | 19410 | } |
| 19763 | 19411 | } |
| 19764 | 19412 | |
| 19765 | | static ZigType *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 19413 | static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 19766 | 19414 | IrInstructionUnwrapErrCode *instruction) |
| 19767 | 19415 | { |
| 19768 | | IrInstruction *value = instruction->value->other; |
| 19416 | IrInstruction *value = instruction->value->child; |
| 19769 | 19417 | if (type_is_invalid(value->value.type)) |
| 19770 | | return ira->codegen->builtin_types.entry_invalid; |
| 19418 | return ira->codegen->invalid_instruction; |
| 19771 | 19419 | ZigType *ptr_type = value->value.type; |
| 19772 | 19420 | |
| 19773 | 19421 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. |
| ... | ... | @@ -19775,41 +19423,44 @@ static ZigType *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 19775 | 19423 | |
| 19776 | 19424 | ZigType *type_entry = ptr_type->data.pointer.child_type; |
| 19777 | 19425 | if (type_is_invalid(type_entry)) { |
| 19778 | | return ira->codegen->builtin_types.entry_invalid; |
| 19426 | return ira->codegen->invalid_instruction; |
| 19779 | 19427 | } else if (type_entry->id == ZigTypeIdErrorUnion) { |
| 19780 | 19428 | if (instr_is_comptime(value)) { |
| 19781 | 19429 | ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); |
| 19782 | 19430 | if (!ptr_val) |
| 19783 | | return ira->codegen->builtin_types.entry_invalid; |
| 19431 | return ira->codegen->invalid_instruction; |
| 19784 | 19432 | ConstExprValue *err_union_val = ir_const_ptr_pointee(ira, ptr_val, instruction->base.source_node); |
| 19785 | 19433 | if (err_union_val == nullptr) |
| 19786 | | return ira->codegen->builtin_types.entry_invalid; |
| 19434 | return ira->codegen->invalid_instruction; |
| 19787 | 19435 | if (err_union_val->special != ConstValSpecialRuntime) { |
| 19788 | 19436 | ErrorTableEntry *err = err_union_val->data.x_err_union.err; |
| 19789 | 19437 | assert(err); |
| 19790 | 19438 | |
| 19791 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19792 | | out_val->data.x_err_set = err; |
| 19793 | | return type_entry->data.error_union.err_set_type; |
| 19439 | IrInstruction *result = ir_const(ira, &instruction->base, |
| 19440 | type_entry->data.error_union.err_set_type); |
| 19441 | result->value.data.x_err_set = err; |
| 19442 | return result; |
| 19794 | 19443 | } |
| 19795 | 19444 | } |
| 19796 | 19445 | |
| 19797 | | ir_build_unwrap_err_code_from(&ira->new_irb, &instruction->base, value); |
| 19798 | | return type_entry->data.error_union.err_set_type; |
| 19446 | IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb, |
| 19447 | instruction->base.scope, instruction->base.source_node, value); |
| 19448 | result->value.type = type_entry->data.error_union.err_set_type; |
| 19449 | return result; |
| 19799 | 19450 | } else { |
| 19800 | 19451 | ir_add_error(ira, value, |
| 19801 | 19452 | buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name))); |
| 19802 | | return ira->codegen->builtin_types.entry_invalid; |
| 19453 | return ira->codegen->invalid_instruction; |
| 19803 | 19454 | } |
| 19804 | 19455 | } |
| 19805 | 19456 | |
| 19806 | | static ZigType *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 19457 | static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 19807 | 19458 | IrInstructionUnwrapErrPayload *instruction) |
| 19808 | 19459 | { |
| 19809 | | assert(instruction->value->other); |
| 19810 | | IrInstruction *value = instruction->value->other; |
| 19460 | assert(instruction->value->child); |
| 19461 | IrInstruction *value = instruction->value->child; |
| 19811 | 19462 | if (type_is_invalid(value->value.type)) |
| 19812 | | return ira->codegen->builtin_types.entry_invalid; |
| 19463 | return ira->codegen->invalid_instruction; |
| 19813 | 19464 | ZigType *ptr_type = value->value.type; |
| 19814 | 19465 | |
| 19815 | 19466 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. |
| ... | ... | @@ -19817,11 +19468,11 @@ static ZigType *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 19817 | 19468 | |
| 19818 | 19469 | ZigType *type_entry = ptr_type->data.pointer.child_type; |
| 19819 | 19470 | if (type_is_invalid(type_entry)) { |
| 19820 | | return ira->codegen->builtin_types.entry_invalid; |
| 19471 | return ira->codegen->invalid_instruction; |
| 19821 | 19472 | } else if (type_entry->id == ZigTypeIdErrorUnion) { |
| 19822 | 19473 | ZigType *payload_type = type_entry->data.error_union.payload_type; |
| 19823 | 19474 | if (type_is_invalid(payload_type)) { |
| 19824 | | return ira->codegen->builtin_types.entry_invalid; |
| 19475 | return ira->codegen->invalid_instruction; |
| 19825 | 19476 | } |
| 19826 | 19477 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type, |
| 19827 | 19478 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| ... | ... | @@ -19829,36 +19480,38 @@ static ZigType *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 19829 | 19480 | if (instr_is_comptime(value)) { |
| 19830 | 19481 | ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); |
| 19831 | 19482 | if (!ptr_val) |
| 19832 | | return ira->codegen->builtin_types.entry_invalid; |
| 19483 | return ira->codegen->invalid_instruction; |
| 19833 | 19484 | ConstExprValue *err_union_val = ir_const_ptr_pointee(ira, ptr_val, instruction->base.source_node); |
| 19834 | 19485 | if (err_union_val == nullptr) |
| 19835 | | return ira->codegen->builtin_types.entry_invalid; |
| 19486 | return ira->codegen->invalid_instruction; |
| 19836 | 19487 | if (err_union_val->special != ConstValSpecialRuntime) { |
| 19837 | 19488 | ErrorTableEntry *err = err_union_val->data.x_err_union.err; |
| 19838 | 19489 | if (err != nullptr) { |
| 19839 | 19490 | ir_add_error(ira, &instruction->base, |
| 19840 | 19491 | buf_sprintf("caught unexpected error '%s'", buf_ptr(&err->name))); |
| 19841 | | return ira->codegen->builtin_types.entry_invalid; |
| 19492 | return ira->codegen->invalid_instruction; |
| 19842 | 19493 | } |
| 19843 | 19494 | |
| 19844 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19845 | | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 19846 | | out_val->data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload; |
| 19847 | | return result_type; |
| 19495 | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 19496 | result->value.data.x_ptr.special = ConstPtrSpecialRef; |
| 19497 | result->value.data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload; |
| 19498 | return result; |
| 19848 | 19499 | } |
| 19849 | 19500 | } |
| 19850 | 19501 | |
| 19851 | | ir_build_unwrap_err_payload_from(&ira->new_irb, &instruction->base, value, instruction->safety_check_on); |
| 19852 | | return result_type; |
| 19502 | IrInstruction *result = ir_build_unwrap_err_payload(&ira->new_irb, |
| 19503 | instruction->base.scope, instruction->base.source_node, value, instruction->safety_check_on); |
| 19504 | result->value.type = result_type; |
| 19505 | return result; |
| 19853 | 19506 | } else { |
| 19854 | 19507 | ir_add_error(ira, value, |
| 19855 | 19508 | buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name))); |
| 19856 | | return ira->codegen->builtin_types.entry_invalid; |
| 19509 | return ira->codegen->invalid_instruction; |
| 19857 | 19510 | } |
| 19858 | 19511 | |
| 19859 | 19512 | } |
| 19860 | 19513 | |
| 19861 | | static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) { |
| 19514 | static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) { |
| 19862 | 19515 | Error err; |
| 19863 | 19516 | AstNode *proto_node = instruction->base.source_node; |
| 19864 | 19517 | assert(proto_node->type == NodeTypeFnProto); |
| ... | ... | @@ -19866,7 +19519,7 @@ static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnP |
| 19866 | 19519 | if (proto_node->data.fn_proto.auto_err_set) { |
| 19867 | 19520 | ir_add_error(ira, &instruction->base, |
| 19868 | 19521 | buf_sprintf("inferring error set of return type valid only for function definitions")); |
| 19869 | | return ira->codegen->builtin_types.entry_invalid; |
| 19522 | return ira->codegen->invalid_instruction; |
| 19870 | 19523 | } |
| 19871 | 19524 | |
| 19872 | 19525 | FnTypeId fn_type_id = {0}; |
| ... | ... | @@ -19882,9 +19535,7 @@ static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnP |
| 19882 | 19535 | fn_type_id.param_count = fn_type_id.next_param_index; |
| 19883 | 19536 | continue; |
| 19884 | 19537 | } else if (fn_type_id.cc == CallingConventionUnspecified) { |
| 19885 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19886 | | out_val->data.x_type = get_generic_fn_type(ira->codegen, &fn_type_id); |
| 19887 | | return ira->codegen->builtin_types.entry_type; |
| 19538 | return ir_const_type(ira, &instruction->base, get_generic_fn_type(ira->codegen, &fn_type_id)); |
| 19888 | 19539 | } else { |
| 19889 | 19540 | zig_unreachable(); |
| 19890 | 19541 | } |
| ... | ... | @@ -19894,36 +19545,32 @@ static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnP |
| 19894 | 19545 | |
| 19895 | 19546 | if (instruction->param_types[fn_type_id.next_param_index] == nullptr) { |
| 19896 | 19547 | param_info->type = nullptr; |
| 19897 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19898 | | out_val->data.x_type = get_generic_fn_type(ira->codegen, &fn_type_id); |
| 19899 | | return ira->codegen->builtin_types.entry_type; |
| 19548 | return ir_const_type(ira, &instruction->base, get_generic_fn_type(ira->codegen, &fn_type_id)); |
| 19900 | 19549 | } else { |
| 19901 | | IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->other; |
| 19550 | IrInstruction *param_type_value = instruction->param_types[fn_type_id.next_param_index]->child; |
| 19902 | 19551 | if (type_is_invalid(param_type_value->value.type)) |
| 19903 | | return ira->codegen->builtin_types.entry_invalid; |
| 19552 | return ira->codegen->invalid_instruction; |
| 19904 | 19553 | ZigType *param_type = ir_resolve_type(ira, param_type_value); |
| 19905 | 19554 | if (type_is_invalid(param_type)) |
| 19906 | | return ira->codegen->builtin_types.entry_invalid; |
| 19555 | return ira->codegen->invalid_instruction; |
| 19907 | 19556 | if ((err = type_resolve(ira->codegen, param_type, ResolveStatusZeroBitsKnown))) |
| 19908 | | return ira->codegen->builtin_types.entry_invalid; |
| 19557 | return ira->codegen->invalid_instruction; |
| 19909 | 19558 | if (type_requires_comptime(param_type)) { |
| 19910 | 19559 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 19911 | 19560 | ir_add_error(ira, param_type_value, |
| 19912 | 19561 | buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'", |
| 19913 | 19562 | buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc))); |
| 19914 | | return ira->codegen->builtin_types.entry_invalid; |
| 19563 | return ira->codegen->invalid_instruction; |
| 19915 | 19564 | } |
| 19916 | 19565 | param_info->type = param_type; |
| 19917 | 19566 | fn_type_id.next_param_index += 1; |
| 19918 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19919 | | out_val->data.x_type = get_generic_fn_type(ira->codegen, &fn_type_id); |
| 19920 | | return ira->codegen->builtin_types.entry_type; |
| 19567 | return ir_const_type(ira, &instruction->base, get_generic_fn_type(ira->codegen, &fn_type_id)); |
| 19921 | 19568 | } |
| 19922 | 19569 | if (!type_has_bits(param_type) && !calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 19923 | 19570 | ir_add_error(ira, param_type_value, |
| 19924 | 19571 | buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'", |
| 19925 | 19572 | buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc))); |
| 19926 | | return ira->codegen->builtin_types.entry_invalid; |
| 19573 | return ira->codegen->invalid_instruction; |
| 19927 | 19574 | } |
| 19928 | 19575 | param_info->type = param_type; |
| 19929 | 19576 | } |
| ... | ... | @@ -19931,54 +19578,50 @@ static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnP |
| 19931 | 19578 | } |
| 19932 | 19579 | |
| 19933 | 19580 | if (instruction->align_value != nullptr) { |
| 19934 | | if (!ir_resolve_align(ira, instruction->align_value->other, &fn_type_id.alignment)) |
| 19935 | | return ira->codegen->builtin_types.entry_invalid; |
| 19581 | if (!ir_resolve_align(ira, instruction->align_value->child, &fn_type_id.alignment)) |
| 19582 | return ira->codegen->invalid_instruction; |
| 19936 | 19583 | } |
| 19937 | 19584 | |
| 19938 | | IrInstruction *return_type_value = instruction->return_type->other; |
| 19585 | IrInstruction *return_type_value = instruction->return_type->child; |
| 19939 | 19586 | fn_type_id.return_type = ir_resolve_type(ira, return_type_value); |
| 19940 | 19587 | if (type_is_invalid(fn_type_id.return_type)) |
| 19941 | | return ira->codegen->builtin_types.entry_invalid; |
| 19588 | return ira->codegen->invalid_instruction; |
| 19942 | 19589 | if (fn_type_id.return_type->id == ZigTypeIdOpaque) { |
| 19943 | 19590 | ir_add_error(ira, instruction->return_type, |
| 19944 | 19591 | buf_sprintf("return type cannot be opaque")); |
| 19945 | | return ira->codegen->builtin_types.entry_invalid; |
| 19592 | return ira->codegen->invalid_instruction; |
| 19946 | 19593 | } |
| 19947 | 19594 | |
| 19948 | 19595 | if (fn_type_id.cc == CallingConventionAsync) { |
| 19949 | 19596 | if (instruction->async_allocator_type_value == nullptr) { |
| 19950 | 19597 | ir_add_error(ira, &instruction->base, |
| 19951 | 19598 | buf_sprintf("async fn proto missing allocator type")); |
| 19952 | | return ira->codegen->builtin_types.entry_invalid; |
| 19599 | return ira->codegen->invalid_instruction; |
| 19953 | 19600 | } |
| 19954 | | IrInstruction *async_allocator_type_value = instruction->async_allocator_type_value->other; |
| 19601 | IrInstruction *async_allocator_type_value = instruction->async_allocator_type_value->child; |
| 19955 | 19602 | fn_type_id.async_allocator_type = ir_resolve_type(ira, async_allocator_type_value); |
| 19956 | 19603 | if (type_is_invalid(fn_type_id.async_allocator_type)) |
| 19957 | | return ira->codegen->builtin_types.entry_invalid; |
| 19604 | return ira->codegen->invalid_instruction; |
| 19958 | 19605 | } |
| 19959 | 19606 | |
| 19960 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19961 | | out_val->data.x_type = get_fn_type(ira->codegen, &fn_type_id); |
| 19962 | | return ira->codegen->builtin_types.entry_type; |
| 19607 | return ir_const_type(ira, &instruction->base, get_fn_type(ira->codegen, &fn_type_id)); |
| 19963 | 19608 | } |
| 19964 | 19609 | |
| 19965 | | static ZigType *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) { |
| 19966 | | IrInstruction *value = instruction->value->other; |
| 19610 | static IrInstruction *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) { |
| 19611 | IrInstruction *value = instruction->value->child; |
| 19967 | 19612 | if (type_is_invalid(value->value.type)) |
| 19968 | | return ira->codegen->builtin_types.entry_invalid; |
| 19613 | return ira->codegen->invalid_instruction; |
| 19969 | 19614 | |
| 19970 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 19971 | | out_val->data.x_bool = instr_is_comptime(value); |
| 19972 | | return ira->codegen->builtin_types.entry_bool; |
| 19615 | return ir_const_bool(ira, &instruction->base, instr_is_comptime(value)); |
| 19973 | 19616 | } |
| 19974 | 19617 | |
| 19975 | | static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 19618 | static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 19976 | 19619 | IrInstructionCheckSwitchProngs *instruction) |
| 19977 | 19620 | { |
| 19978 | | IrInstruction *target_value = instruction->target_value->other; |
| 19621 | IrInstruction *target_value = instruction->target_value->child; |
| 19979 | 19622 | ZigType *switch_type = target_value->value.type; |
| 19980 | 19623 | if (type_is_invalid(switch_type)) |
| 19981 | | return ira->codegen->builtin_types.entry_invalid; |
| 19624 | return ira->codegen->invalid_instruction; |
| 19982 | 19625 | |
| 19983 | 19626 | if (switch_type->id == ZigTypeIdEnum) { |
| 19984 | 19627 | HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {}; |
| ... | ... | @@ -19987,17 +19630,17 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 19987 | 19630 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { |
| 19988 | 19631 | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 19989 | 19632 | |
| 19990 | | IrInstruction *start_value = range->start->other; |
| 19633 | IrInstruction *start_value = range->start->child; |
| 19991 | 19634 | if (type_is_invalid(start_value->value.type)) |
| 19992 | | return ira->codegen->builtin_types.entry_invalid; |
| 19635 | return ira->codegen->invalid_instruction; |
| 19993 | 19636 | |
| 19994 | | IrInstruction *end_value = range->end->other; |
| 19637 | IrInstruction *end_value = range->end->child; |
| 19995 | 19638 | if (type_is_invalid(end_value->value.type)) |
| 19996 | | return ira->codegen->builtin_types.entry_invalid; |
| 19639 | return ira->codegen->invalid_instruction; |
| 19997 | 19640 | |
| 19998 | 19641 | if (start_value->value.type->id != ZigTypeIdEnum) { |
| 19999 | 19642 | ir_add_error(ira, range->start, buf_sprintf("not an enum type")); |
| 20000 | | return ira->codegen->builtin_types.entry_invalid; |
| 19643 | return ira->codegen->invalid_instruction; |
| 20001 | 19644 | } |
| 20002 | 19645 | |
| 20003 | 19646 | BigInt start_index; |
| ... | ... | @@ -20041,7 +19684,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 20041 | 19684 | } |
| 20042 | 19685 | } else if (switch_type->id == ZigTypeIdErrorSet) { |
| 20043 | 19686 | if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) { |
| 20044 | | return ira->codegen->builtin_types.entry_invalid; |
| 19687 | return ira->codegen->invalid_instruction; |
| 20045 | 19688 | } |
| 20046 | 19689 | |
| 20047 | 19690 | AstNode **field_prev_uses = allocate<AstNode *>(ira->codegen->errors_by_index.length); |
| ... | ... | @@ -20049,13 +19692,13 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 20049 | 19692 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { |
| 20050 | 19693 | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 20051 | 19694 | |
| 20052 | | IrInstruction *start_value = range->start->other; |
| 19695 | IrInstruction *start_value = range->start->child; |
| 20053 | 19696 | if (type_is_invalid(start_value->value.type)) |
| 20054 | | return ira->codegen->builtin_types.entry_invalid; |
| 19697 | return ira->codegen->invalid_instruction; |
| 20055 | 19698 | |
| 20056 | | IrInstruction *end_value = range->end->other; |
| 19699 | IrInstruction *end_value = range->end->child; |
| 20057 | 19700 | if (type_is_invalid(end_value->value.type)) |
| 20058 | | return ira->codegen->builtin_types.entry_invalid; |
| 19701 | return ira->codegen->invalid_instruction; |
| 20059 | 19702 | |
| 20060 | 19703 | assert(start_value->value.type->id == ZigTypeIdErrorSet); |
| 20061 | 19704 | uint32_t start_index = start_value->value.data.x_err_set->value; |
| ... | ... | @@ -20065,7 +19708,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 20065 | 19708 | |
| 20066 | 19709 | if (start_index != end_index) { |
| 20067 | 19710 | ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors")); |
| 20068 | | return ira->codegen->builtin_types.entry_invalid; |
| 19711 | return ira->codegen->invalid_instruction; |
| 20069 | 19712 | } |
| 20070 | 19713 | |
| 20071 | 19714 | AstNode *prev_node = field_prev_uses[start_index]; |
| ... | ... | @@ -20081,7 +19724,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 20081 | 19724 | if (type_is_global_error_set(switch_type)) { |
| 20082 | 19725 | ir_add_error(ira, &instruction->base, |
| 20083 | 19726 | buf_sprintf("else prong required when switching on type 'error'")); |
| 20084 | | return ira->codegen->builtin_types.entry_invalid; |
| 19727 | return ira->codegen->invalid_instruction; |
| 20085 | 19728 | } else { |
| 20086 | 19729 | for (uint32_t i = 0; i < switch_type->data.error_set.err_count; i += 1) { |
| 20087 | 19730 | ErrorTableEntry *err_entry = switch_type->data.error_set.errors[i]; |
| ... | ... | @@ -20101,27 +19744,27 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 20101 | 19744 | for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { |
| 20102 | 19745 | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 20103 | 19746 | |
| 20104 | | IrInstruction *start_value = range->start->other; |
| 19747 | IrInstruction *start_value = range->start->child; |
| 20105 | 19748 | if (type_is_invalid(start_value->value.type)) |
| 20106 | | return ira->codegen->builtin_types.entry_invalid; |
| 19749 | return ira->codegen->invalid_instruction; |
| 20107 | 19750 | IrInstruction *casted_start_value = ir_implicit_cast(ira, start_value, switch_type); |
| 20108 | 19751 | if (type_is_invalid(casted_start_value->value.type)) |
| 20109 | | return ira->codegen->builtin_types.entry_invalid; |
| 19752 | return ira->codegen->invalid_instruction; |
| 20110 | 19753 | |
| 20111 | | IrInstruction *end_value = range->end->other; |
| 19754 | IrInstruction *end_value = range->end->child; |
| 20112 | 19755 | if (type_is_invalid(end_value->value.type)) |
| 20113 | | return ira->codegen->builtin_types.entry_invalid; |
| 19756 | return ira->codegen->invalid_instruction; |
| 20114 | 19757 | IrInstruction *casted_end_value = ir_implicit_cast(ira, end_value, switch_type); |
| 20115 | 19758 | if (type_is_invalid(casted_end_value->value.type)) |
| 20116 | | return ira->codegen->builtin_types.entry_invalid; |
| 19759 | return ira->codegen->invalid_instruction; |
| 20117 | 19760 | |
| 20118 | 19761 | ConstExprValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad); |
| 20119 | 19762 | if (!start_val) |
| 20120 | | return ira->codegen->builtin_types.entry_invalid; |
| 19763 | return ira->codegen->invalid_instruction; |
| 20121 | 19764 | |
| 20122 | 19765 | ConstExprValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad); |
| 20123 | 19766 | if (!end_val) |
| 20124 | | return ira->codegen->builtin_types.entry_invalid; |
| 19767 | return ira->codegen->invalid_instruction; |
| 20125 | 19768 | |
| 20126 | 19769 | assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt); |
| 20127 | 19770 | assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt); |
| ... | ... | @@ -20130,7 +19773,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 20130 | 19773 | if (prev_node != nullptr) { |
| 20131 | 19774 | ErrorMsg *msg = ir_add_error(ira, start_value, buf_sprintf("duplicate switch value")); |
| 20132 | 19775 | add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value is here")); |
| 20133 | | return ira->codegen->builtin_types.entry_invalid; |
| 19776 | return ira->codegen->invalid_instruction; |
| 20134 | 19777 | } |
| 20135 | 19778 | } |
| 20136 | 19779 | if (!instruction->have_else_prong) { |
| ... | ... | @@ -20140,36 +19783,34 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 20140 | 19783 | eval_min_max_value_int(ira->codegen, switch_type, &max_val, true); |
| 20141 | 19784 | if (!rangeset_spans(&rs, &min_val, &max_val)) { |
| 20142 | 19785 | ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities")); |
| 20143 | | return ira->codegen->builtin_types.entry_invalid; |
| 19786 | return ira->codegen->invalid_instruction; |
| 20144 | 19787 | } |
| 20145 | 19788 | } |
| 20146 | 19789 | } else if (!instruction->have_else_prong) { |
| 20147 | 19790 | ir_add_error(ira, &instruction->base, |
| 20148 | 19791 | buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name))); |
| 20149 | | return ira->codegen->builtin_types.entry_invalid; |
| 19792 | return ira->codegen->invalid_instruction; |
| 20150 | 19793 | } |
| 20151 | | ir_build_const_from(ira, &instruction->base); |
| 20152 | | return ira->codegen->builtin_types.entry_void; |
| 19794 | return ir_const_void(ira, &instruction->base); |
| 20153 | 19795 | } |
| 20154 | 19796 | |
| 20155 | | static ZigType *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, |
| 19797 | static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, |
| 20156 | 19798 | IrInstructionCheckStatementIsVoid *instruction) |
| 20157 | 19799 | { |
| 20158 | | IrInstruction *statement_value = instruction->statement_value->other; |
| 19800 | IrInstruction *statement_value = instruction->statement_value->child; |
| 20159 | 19801 | ZigType *statement_type = statement_value->value.type; |
| 20160 | 19802 | if (type_is_invalid(statement_type)) |
| 20161 | | return ira->codegen->builtin_types.entry_invalid; |
| 19803 | return ira->codegen->invalid_instruction; |
| 20162 | 19804 | |
| 20163 | 19805 | if (statement_type->id != ZigTypeIdVoid) { |
| 20164 | 19806 | ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored")); |
| 20165 | 19807 | } |
| 20166 | 19808 | |
| 20167 | | ir_build_const_from(ira, &instruction->base); |
| 20168 | | return ira->codegen->builtin_types.entry_void; |
| 19809 | return ir_const_void(ira, &instruction->base); |
| 20169 | 19810 | } |
| 20170 | 19811 | |
| 20171 | | static ZigType *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) { |
| 20172 | | IrInstruction *msg = instruction->msg->other; |
| 19812 | static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) { |
| 19813 | IrInstruction *msg = instruction->msg->child; |
| 20173 | 19814 | if (type_is_invalid(msg->value.type)) |
| 20174 | 19815 | return ir_unreach_error(ira); |
| 20175 | 19816 | |
| ... | ... | @@ -20187,8 +19828,7 @@ static ZigType *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic |
| 20187 | 19828 | |
| 20188 | 19829 | IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope, |
| 20189 | 19830 | instruction->base.source_node, casted_msg); |
| 20190 | | ir_link_new_instruction(new_instruction, &instruction->base); |
| 20191 | | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 19831 | return ir_finish_anal(ira, new_instruction); |
| 20192 | 19832 | } |
| 20193 | 19833 | |
| 20194 | 19834 | static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) { |
| ... | ... | @@ -20352,23 +19992,18 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 20352 | 19992 | return result; |
| 20353 | 19993 | } |
| 20354 | 19994 | |
| 20355 | | static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) { |
| 20356 | | IrInstruction *dest_type_value = instruction->dest_type->other; |
| 19995 | static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) { |
| 19996 | IrInstruction *dest_type_value = instruction->dest_type->child; |
| 20357 | 19997 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 20358 | 19998 | if (type_is_invalid(dest_type)) |
| 20359 | | return ira->codegen->builtin_types.entry_invalid; |
| 19999 | return ira->codegen->invalid_instruction; |
| 20360 | 20000 | |
| 20361 | | IrInstruction *ptr = instruction->ptr->other; |
| 20001 | IrInstruction *ptr = instruction->ptr->child; |
| 20362 | 20002 | ZigType *src_type = ptr->value.type; |
| 20363 | 20003 | if (type_is_invalid(src_type)) |
| 20364 | | return ira->codegen->builtin_types.entry_invalid; |
| 20365 | | |
| 20366 | | IrInstruction *result = ir_analyze_ptr_cast(ira, &instruction->base, ptr, dest_type, dest_type_value); |
| 20367 | | if (type_is_invalid(result->value.type)) |
| 20368 | | return ira->codegen->builtin_types.entry_invalid; |
| 20004 | return ira->codegen->invalid_instruction; |
| 20369 | 20005 | |
| 20370 | | ir_link_new_instruction(result, &instruction->base); |
| 20371 | | return result->value.type; |
| 20006 | return ir_analyze_ptr_cast(ira, &instruction->base, ptr, dest_type, dest_type_value); |
| 20372 | 20007 | } |
| 20373 | 20008 | |
| 20374 | 20009 | static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) { |
| ... | ... | @@ -20498,28 +20133,28 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 20498 | 20133 | zig_unreachable(); |
| 20499 | 20134 | } |
| 20500 | 20135 | |
| 20501 | | static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) { |
| 20136 | static IrInstruction *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) { |
| 20502 | 20137 | Error err; |
| 20503 | | IrInstruction *dest_type_value = instruction->dest_type->other; |
| 20138 | IrInstruction *dest_type_value = instruction->dest_type->child; |
| 20504 | 20139 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 20505 | 20140 | if (type_is_invalid(dest_type)) |
| 20506 | | return ira->codegen->builtin_types.entry_invalid; |
| 20141 | return ira->codegen->invalid_instruction; |
| 20507 | 20142 | |
| 20508 | | IrInstruction *value = instruction->value->other; |
| 20143 | IrInstruction *value = instruction->value->child; |
| 20509 | 20144 | ZigType *src_type = value->value.type; |
| 20510 | 20145 | if (type_is_invalid(src_type)) |
| 20511 | | return ira->codegen->builtin_types.entry_invalid; |
| 20146 | return ira->codegen->invalid_instruction; |
| 20512 | 20147 | |
| 20513 | 20148 | if ((err = ensure_complete_type(ira->codegen, dest_type))) |
| 20514 | | return ira->codegen->builtin_types.entry_invalid; |
| 20149 | return ira->codegen->invalid_instruction; |
| 20515 | 20150 | |
| 20516 | 20151 | if ((err = ensure_complete_type(ira->codegen, src_type))) |
| 20517 | | return ira->codegen->builtin_types.entry_invalid; |
| 20152 | return ira->codegen->invalid_instruction; |
| 20518 | 20153 | |
| 20519 | 20154 | if (get_codegen_ptr_type(src_type) != nullptr) { |
| 20520 | 20155 | ir_add_error(ira, value, |
| 20521 | 20156 | buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&src_type->name))); |
| 20522 | | return ira->codegen->builtin_types.entry_invalid; |
| 20157 | return ira->codegen->invalid_instruction; |
| 20523 | 20158 | } |
| 20524 | 20159 | |
| 20525 | 20160 | switch (src_type->id) { |
| ... | ... | @@ -20536,7 +20171,7 @@ static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBit |
| 20536 | 20171 | case ZigTypeIdNull: |
| 20537 | 20172 | ir_add_error(ira, dest_type_value, |
| 20538 | 20173 | buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name))); |
| 20539 | | return ira->codegen->builtin_types.entry_invalid; |
| 20174 | return ira->codegen->invalid_instruction; |
| 20540 | 20175 | default: |
| 20541 | 20176 | break; |
| 20542 | 20177 | } |
| ... | ... | @@ -20544,7 +20179,7 @@ static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBit |
| 20544 | 20179 | if (get_codegen_ptr_type(dest_type) != nullptr) { |
| 20545 | 20180 | ir_add_error(ira, dest_type_value, |
| 20546 | 20181 | buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name))); |
| 20547 | | return ira->codegen->builtin_types.entry_invalid; |
| 20182 | return ira->codegen->invalid_instruction; |
| 20548 | 20183 | } |
| 20549 | 20184 | |
| 20550 | 20185 | switch (dest_type->id) { |
| ... | ... | @@ -20561,7 +20196,7 @@ static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBit |
| 20561 | 20196 | case ZigTypeIdNull: |
| 20562 | 20197 | ir_add_error(ira, dest_type_value, |
| 20563 | 20198 | buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name))); |
| 20564 | | return ira->codegen->builtin_types.entry_invalid; |
| 20199 | return ira->codegen->invalid_instruction; |
| 20565 | 20200 | default: |
| 20566 | 20201 | break; |
| 20567 | 20202 | } |
| ... | ... | @@ -20573,76 +20208,74 @@ static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBit |
| 20573 | 20208 | buf_sprintf("destination type '%s' has size %" ZIG_PRI_u64 " but source type '%s' has size %" ZIG_PRI_u64, |
| 20574 | 20209 | buf_ptr(&dest_type->name), dest_size_bytes, |
| 20575 | 20210 | buf_ptr(&src_type->name), src_size_bytes)); |
| 20576 | | return ira->codegen->builtin_types.entry_invalid; |
| 20211 | return ira->codegen->invalid_instruction; |
| 20577 | 20212 | } |
| 20578 | 20213 | |
| 20579 | 20214 | if (instr_is_comptime(value)) { |
| 20580 | 20215 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| 20581 | 20216 | if (!val) |
| 20582 | | return ira->codegen->builtin_types.entry_invalid; |
| 20217 | return ira->codegen->invalid_instruction; |
| 20583 | 20218 | |
| 20584 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20585 | | out_val->type = dest_type; |
| 20219 | IrInstruction *result = ir_const(ira, &instruction->base, dest_type); |
| 20586 | 20220 | uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes); |
| 20587 | 20221 | buf_write_value_bytes(ira->codegen, buf, val); |
| 20588 | | buf_read_value_bytes(ira->codegen, buf, out_val); |
| 20589 | | return dest_type; |
| 20222 | buf_read_value_bytes(ira->codegen, buf, &result->value); |
| 20223 | return result; |
| 20590 | 20224 | } |
| 20591 | 20225 | |
| 20592 | 20226 | IrInstruction *result = ir_build_bit_cast(&ira->new_irb, instruction->base.scope, |
| 20593 | 20227 | instruction->base.source_node, nullptr, value); |
| 20594 | | ir_link_new_instruction(result, &instruction->base); |
| 20595 | 20228 | result->value.type = dest_type; |
| 20596 | | return dest_type; |
| 20229 | return result; |
| 20597 | 20230 | } |
| 20598 | 20231 | |
| 20599 | | static ZigType *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) { |
| 20232 | static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) { |
| 20600 | 20233 | Error err; |
| 20601 | | IrInstruction *dest_type_value = instruction->dest_type->other; |
| 20234 | IrInstruction *dest_type_value = instruction->dest_type->child; |
| 20602 | 20235 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 20603 | 20236 | if (type_is_invalid(dest_type)) |
| 20604 | | return ira->codegen->builtin_types.entry_invalid; |
| 20237 | return ira->codegen->invalid_instruction; |
| 20605 | 20238 | |
| 20606 | 20239 | // We explicitly check for the size, so we can use get_src_ptr_type |
| 20607 | 20240 | if (get_src_ptr_type(dest_type) == nullptr) { |
| 20608 | 20241 | ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name))); |
| 20609 | | return ira->codegen->builtin_types.entry_invalid; |
| 20242 | return ira->codegen->invalid_instruction; |
| 20610 | 20243 | } |
| 20611 | 20244 | |
| 20612 | 20245 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) |
| 20613 | | return ira->codegen->builtin_types.entry_invalid; |
| 20246 | return ira->codegen->invalid_instruction; |
| 20614 | 20247 | if (!type_has_bits(dest_type)) { |
| 20615 | 20248 | ir_add_error(ira, dest_type_value, |
| 20616 | 20249 | buf_sprintf("type '%s' has 0 bits and cannot store information", buf_ptr(&dest_type->name))); |
| 20617 | | return ira->codegen->builtin_types.entry_invalid; |
| 20250 | return ira->codegen->invalid_instruction; |
| 20618 | 20251 | } |
| 20619 | 20252 | |
| 20620 | | IrInstruction *target = instruction->target->other; |
| 20253 | IrInstruction *target = instruction->target->child; |
| 20621 | 20254 | if (type_is_invalid(target->value.type)) |
| 20622 | | return ira->codegen->builtin_types.entry_invalid; |
| 20255 | return ira->codegen->invalid_instruction; |
| 20623 | 20256 | |
| 20624 | 20257 | IrInstruction *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize); |
| 20625 | 20258 | if (type_is_invalid(casted_int->value.type)) |
| 20626 | | return ira->codegen->builtin_types.entry_invalid; |
| 20259 | return ira->codegen->invalid_instruction; |
| 20627 | 20260 | |
| 20628 | 20261 | if (instr_is_comptime(casted_int)) { |
| 20629 | 20262 | ConstExprValue *val = ir_resolve_const(ira, casted_int, UndefBad); |
| 20630 | 20263 | if (!val) |
| 20631 | | return ira->codegen->builtin_types.entry_invalid; |
| 20264 | return ira->codegen->invalid_instruction; |
| 20632 | 20265 | |
| 20633 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20634 | | out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 20635 | | out_val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&val->data.x_bigint); |
| 20636 | | return dest_type; |
| 20266 | IrInstruction *result = ir_const(ira, &instruction->base, dest_type); |
| 20267 | result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 20268 | result->value.data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&val->data.x_bigint); |
| 20269 | return result; |
| 20637 | 20270 | } |
| 20638 | 20271 | |
| 20639 | 20272 | IrInstruction *result = ir_build_int_to_ptr(&ira->new_irb, instruction->base.scope, |
| 20640 | 20273 | instruction->base.source_node, nullptr, casted_int); |
| 20641 | | ir_link_new_instruction(result, &instruction->base); |
| 20642 | | return dest_type; |
| 20274 | result->value.type = dest_type; |
| 20275 | return result; |
| 20643 | 20276 | } |
| 20644 | 20277 | |
| 20645 | | static ZigType *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 20278 | static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 20646 | 20279 | IrInstructionDeclRef *instruction) |
| 20647 | 20280 | { |
| 20648 | 20281 | Tld *tld = instruction->tld; |
| ... | ... | @@ -20650,7 +20283,7 @@ static ZigType *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 20650 | 20283 | |
| 20651 | 20284 | resolve_top_level_decl(ira->codegen, tld, lval == LValPtr, instruction->base.source_node); |
| 20652 | 20285 | if (tld->resolution == TldResolutionInvalid) |
| 20653 | | return ira->codegen->builtin_types.entry_invalid; |
| 20286 | return ira->codegen->invalid_instruction; |
| 20654 | 20287 | |
| 20655 | 20288 | switch (tld->id) { |
| 20656 | 20289 | case TldIdContainer: |
| ... | ... | @@ -20663,19 +20296,16 @@ static ZigType *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 20663 | 20296 | |
| 20664 | 20297 | IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var); |
| 20665 | 20298 | if (type_is_invalid(var_ptr->value.type)) |
| 20666 | | return ira->codegen->builtin_types.entry_invalid; |
| 20299 | return ira->codegen->invalid_instruction; |
| 20667 | 20300 | |
| 20668 | 20301 | if (tld_var->extern_lib_name != nullptr) { |
| 20669 | 20302 | add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, instruction->base.source_node); |
| 20670 | 20303 | } |
| 20671 | 20304 | |
| 20672 | 20305 | if (lval == LValPtr) { |
| 20673 | | ir_link_new_instruction(var_ptr, &instruction->base); |
| 20674 | | return var_ptr->value.type; |
| 20306 | return var_ptr; |
| 20675 | 20307 | } else { |
| 20676 | | IrInstruction *loaded_instr = ir_get_deref(ira, &instruction->base, var_ptr); |
| 20677 | | ir_link_new_instruction(loaded_instr, &instruction->base); |
| 20678 | | return loaded_instr->value.type; |
| 20308 | return ir_get_deref(ira, &instruction->base, var_ptr); |
| 20679 | 20309 | } |
| 20680 | 20310 | } |
| 20681 | 20311 | case TldIdFn: |
| ... | ... | @@ -20691,22 +20321,19 @@ static ZigType *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 20691 | 20321 | IrInstruction *ref_instruction = ir_create_const_fn(&ira->new_irb, instruction->base.scope, |
| 20692 | 20322 | instruction->base.source_node, fn_entry); |
| 20693 | 20323 | if (lval == LValPtr) { |
| 20694 | | IrInstruction *ptr_instr = ir_get_ref(ira, &instruction->base, ref_instruction, true, false); |
| 20695 | | ir_link_new_instruction(ptr_instr, &instruction->base); |
| 20696 | | return ptr_instr->value.type; |
| 20324 | return ir_get_ref(ira, &instruction->base, ref_instruction, true, false); |
| 20697 | 20325 | } else { |
| 20698 | | ir_link_new_instruction(ref_instruction, &instruction->base); |
| 20699 | | return ref_instruction->value.type; |
| 20326 | return ref_instruction; |
| 20700 | 20327 | } |
| 20701 | 20328 | } |
| 20702 | 20329 | } |
| 20703 | 20330 | zig_unreachable(); |
| 20704 | 20331 | } |
| 20705 | 20332 | |
| 20706 | | static ZigType *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) { |
| 20707 | | IrInstruction *target = instruction->target->other; |
| 20333 | static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) { |
| 20334 | IrInstruction *target = instruction->target->child; |
| 20708 | 20335 | if (type_is_invalid(target->value.type)) |
| 20709 | | return ira->codegen->builtin_types.entry_invalid; |
| 20336 | return ira->codegen->invalid_instruction; |
| 20710 | 20337 | |
| 20711 | 20338 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 20712 | 20339 | |
| ... | ... | @@ -20714,151 +20341,144 @@ static ZigType *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionP |
| 20714 | 20341 | if (get_src_ptr_type(target->value.type) == nullptr) { |
| 20715 | 20342 | ir_add_error(ira, target, |
| 20716 | 20343 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value.type->name))); |
| 20717 | | return ira->codegen->builtin_types.entry_invalid; |
| 20344 | return ira->codegen->invalid_instruction; |
| 20718 | 20345 | } |
| 20719 | 20346 | |
| 20720 | 20347 | if (!type_has_bits(target->value.type)) { |
| 20721 | 20348 | ir_add_error(ira, target, |
| 20722 | 20349 | buf_sprintf("pointer to size 0 type has no address")); |
| 20723 | | return ira->codegen->builtin_types.entry_invalid; |
| 20350 | return ira->codegen->invalid_instruction; |
| 20724 | 20351 | } |
| 20725 | 20352 | |
| 20726 | 20353 | if (instr_is_comptime(target)) { |
| 20727 | 20354 | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 20728 | 20355 | if (!val) |
| 20729 | | return ira->codegen->builtin_types.entry_invalid; |
| 20356 | return ira->codegen->invalid_instruction; |
| 20730 | 20357 | if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 20731 | 20358 | IrInstruction *result = ir_create_const(&ira->new_irb, instruction->base.scope, |
| 20732 | 20359 | instruction->base.source_node, usize); |
| 20733 | 20360 | bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); |
| 20734 | | ir_link_new_instruction(result, &instruction->base); |
| 20735 | | return usize; |
| 20361 | result->value.type = usize; |
| 20362 | return result; |
| 20736 | 20363 | } |
| 20737 | 20364 | } |
| 20738 | 20365 | |
| 20739 | 20366 | IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, instruction->base.scope, |
| 20740 | 20367 | instruction->base.source_node, target); |
| 20741 | 20368 | result->value.type = usize; |
| 20742 | | ir_link_new_instruction(result, &instruction->base); |
| 20743 | | return usize; |
| 20369 | return result; |
| 20744 | 20370 | } |
| 20745 | 20371 | |
| 20746 | | static ZigType *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) { |
| 20372 | static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) { |
| 20747 | 20373 | Error err; |
| 20748 | | ZigType *child_type = ir_resolve_type(ira, instruction->child_type->other); |
| 20374 | ZigType *child_type = ir_resolve_type(ira, instruction->child_type->child); |
| 20749 | 20375 | if (type_is_invalid(child_type)) |
| 20750 | | return ira->codegen->builtin_types.entry_invalid; |
| 20376 | return ira->codegen->invalid_instruction; |
| 20751 | 20377 | |
| 20752 | 20378 | if (child_type->id == ZigTypeIdUnreachable) { |
| 20753 | 20379 | ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed")); |
| 20754 | | return ira->codegen->builtin_types.entry_invalid; |
| 20380 | return ira->codegen->invalid_instruction; |
| 20755 | 20381 | } else if (child_type->id == ZigTypeIdOpaque && instruction->ptr_len == PtrLenUnknown) { |
| 20756 | 20382 | ir_add_error(ira, &instruction->base, buf_sprintf("unknown-length pointer to opaque")); |
| 20757 | | return ira->codegen->builtin_types.entry_invalid; |
| 20383 | return ira->codegen->invalid_instruction; |
| 20758 | 20384 | } |
| 20759 | 20385 | |
| 20760 | 20386 | uint32_t align_bytes; |
| 20761 | 20387 | if (instruction->align_value != nullptr) { |
| 20762 | | if (!ir_resolve_align(ira, instruction->align_value->other, &align_bytes)) |
| 20763 | | return ira->codegen->builtin_types.entry_invalid; |
| 20388 | if (!ir_resolve_align(ira, instruction->align_value->child, &align_bytes)) |
| 20389 | return ira->codegen->invalid_instruction; |
| 20764 | 20390 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusAlignmentKnown))) |
| 20765 | | return ira->codegen->builtin_types.entry_invalid; |
| 20391 | return ira->codegen->invalid_instruction; |
| 20766 | 20392 | } else { |
| 20767 | 20393 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusZeroBitsKnown))) |
| 20768 | | return ira->codegen->builtin_types.entry_invalid; |
| 20394 | return ira->codegen->invalid_instruction; |
| 20769 | 20395 | align_bytes = 0; |
| 20770 | 20396 | } |
| 20771 | 20397 | |
| 20772 | | |
| 20773 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20774 | | out_val->data.x_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 20398 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 20775 | 20399 | instruction->is_const, instruction->is_volatile, |
| 20776 | 20400 | instruction->ptr_len, align_bytes, |
| 20777 | 20401 | instruction->bit_offset_start, instruction->host_int_bytes); |
| 20778 | | |
| 20779 | | return ira->codegen->builtin_types.entry_type; |
| 20402 | return ir_const_type(ira, &instruction->base, result_type); |
| 20780 | 20403 | } |
| 20781 | 20404 | |
| 20782 | | static ZigType *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) { |
| 20405 | static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) { |
| 20783 | 20406 | uint32_t align_bytes; |
| 20784 | | IrInstruction *align_bytes_inst = instruction->align_bytes->other; |
| 20407 | IrInstruction *align_bytes_inst = instruction->align_bytes->child; |
| 20785 | 20408 | if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes)) |
| 20786 | | return ira->codegen->builtin_types.entry_invalid; |
| 20409 | return ira->codegen->invalid_instruction; |
| 20787 | 20410 | |
| 20788 | | IrInstruction *target = instruction->target->other; |
| 20411 | IrInstruction *target = instruction->target->child; |
| 20789 | 20412 | if (type_is_invalid(target->value.type)) |
| 20790 | | return ira->codegen->builtin_types.entry_invalid; |
| 20413 | return ira->codegen->invalid_instruction; |
| 20791 | 20414 | |
| 20792 | 20415 | IrInstruction *result = ir_align_cast(ira, target, align_bytes, true); |
| 20793 | 20416 | if (type_is_invalid(result->value.type)) |
| 20794 | | return ira->codegen->builtin_types.entry_invalid; |
| 20417 | return ira->codegen->invalid_instruction; |
| 20795 | 20418 | |
| 20796 | | ir_link_new_instruction(result, &instruction->base); |
| 20797 | | return result->value.type; |
| 20419 | return result; |
| 20798 | 20420 | } |
| 20799 | 20421 | |
| 20800 | | static ZigType *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) { |
| 20422 | static IrInstruction *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) { |
| 20801 | 20423 | Buf *name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", instruction->base.source_node); |
| 20802 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20803 | | out_val->data.x_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node, |
| 20424 | ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node, |
| 20804 | 20425 | buf_ptr(name)); |
| 20805 | | return ira->codegen->builtin_types.entry_type; |
| 20426 | return ir_const_type(ira, &instruction->base, result_type); |
| 20806 | 20427 | } |
| 20807 | 20428 | |
| 20808 | | static ZigType *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) { |
| 20429 | static IrInstruction *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) { |
| 20809 | 20430 | uint32_t align_bytes; |
| 20810 | | IrInstruction *align_bytes_inst = instruction->align_bytes->other; |
| 20431 | IrInstruction *align_bytes_inst = instruction->align_bytes->child; |
| 20811 | 20432 | if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes)) |
| 20812 | | return ira->codegen->builtin_types.entry_invalid; |
| 20433 | return ira->codegen->invalid_instruction; |
| 20813 | 20434 | |
| 20814 | 20435 | if (align_bytes > 256) { |
| 20815 | 20436 | ir_add_error(ira, &instruction->base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes)); |
| 20816 | | return ira->codegen->builtin_types.entry_invalid; |
| 20437 | return ira->codegen->invalid_instruction; |
| 20817 | 20438 | } |
| 20818 | 20439 | |
| 20819 | 20440 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 20820 | 20441 | if (fn_entry == nullptr) { |
| 20821 | 20442 | ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function")); |
| 20822 | | return ira->codegen->builtin_types.entry_invalid; |
| 20443 | return ira->codegen->invalid_instruction; |
| 20823 | 20444 | } |
| 20824 | 20445 | if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionNaked) { |
| 20825 | 20446 | ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack in naked function")); |
| 20826 | | return ira->codegen->builtin_types.entry_invalid; |
| 20447 | return ira->codegen->invalid_instruction; |
| 20827 | 20448 | } |
| 20828 | 20449 | |
| 20829 | 20450 | if (fn_entry->fn_inline == FnInlineAlways) { |
| 20830 | 20451 | ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack in inline function")); |
| 20831 | | return ira->codegen->builtin_types.entry_invalid; |
| 20452 | return ira->codegen->invalid_instruction; |
| 20832 | 20453 | } |
| 20833 | 20454 | |
| 20834 | 20455 | if (fn_entry->set_alignstack_node != nullptr) { |
| 20835 | 20456 | ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node, |
| 20836 | 20457 | buf_sprintf("alignstack set twice")); |
| 20837 | 20458 | add_error_note(ira->codegen, msg, fn_entry->set_alignstack_node, buf_sprintf("first set here")); |
| 20838 | | return ira->codegen->builtin_types.entry_invalid; |
| 20459 | return ira->codegen->invalid_instruction; |
| 20839 | 20460 | } |
| 20840 | 20461 | |
| 20841 | 20462 | fn_entry->set_alignstack_node = instruction->base.source_node; |
| 20842 | 20463 | fn_entry->alignstack_value = align_bytes; |
| 20843 | 20464 | |
| 20844 | | ir_build_const_from(ira, &instruction->base); |
| 20845 | | return ira->codegen->builtin_types.entry_void; |
| 20465 | return ir_const_void(ira, &instruction->base); |
| 20846 | 20466 | } |
| 20847 | 20467 | |
| 20848 | | static ZigType *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) { |
| 20849 | | IrInstruction *fn_type_inst = instruction->fn_type->other; |
| 20468 | static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) { |
| 20469 | IrInstruction *fn_type_inst = instruction->fn_type->child; |
| 20850 | 20470 | ZigType *fn_type = ir_resolve_type(ira, fn_type_inst); |
| 20851 | 20471 | if (type_is_invalid(fn_type)) |
| 20852 | | return ira->codegen->builtin_types.entry_invalid; |
| 20472 | return ira->codegen->invalid_instruction; |
| 20853 | 20473 | |
| 20854 | | IrInstruction *arg_index_inst = instruction->arg_index->other; |
| 20474 | IrInstruction *arg_index_inst = instruction->arg_index->child; |
| 20855 | 20475 | uint64_t arg_index; |
| 20856 | 20476 | if (!ir_resolve_usize(ira, arg_index_inst, &arg_index)) |
| 20857 | | return ira->codegen->builtin_types.entry_invalid; |
| 20477 | return ira->codegen->invalid_instruction; |
| 20858 | 20478 | |
| 20859 | 20479 | if (fn_type->id != ZigTypeIdFn) { |
| 20860 | 20480 | ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name))); |
| 20861 | | return ira->codegen->builtin_types.entry_invalid; |
| 20481 | return ira->codegen->invalid_instruction; |
| 20862 | 20482 | } |
| 20863 | 20483 | |
| 20864 | 20484 | FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; |
| ... | ... | @@ -20866,226 +20486,207 @@ static ZigType *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArg |
| 20866 | 20486 | ir_add_error(ira, arg_index_inst, |
| 20867 | 20487 | buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " arguments", |
| 20868 | 20488 | arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count)); |
| 20869 | | return ira->codegen->builtin_types.entry_invalid; |
| 20489 | return ira->codegen->invalid_instruction; |
| 20870 | 20490 | } |
| 20871 | 20491 | |
| 20872 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20873 | | out_val->data.x_type = fn_type_id->param_info[arg_index].type; |
| 20874 | | if (out_val->data.x_type == nullptr) { |
| 20492 | ZigType *result_type = fn_type_id->param_info[arg_index].type; |
| 20493 | if (result_type == nullptr) { |
| 20875 | 20494 | // Args are only unresolved if our function is generic. |
| 20876 | 20495 | assert(fn_type->data.fn.is_generic); |
| 20877 | 20496 | |
| 20878 | 20497 | ir_add_error(ira, arg_index_inst, |
| 20879 | 20498 | buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic", |
| 20880 | 20499 | arg_index, buf_ptr(&fn_type->name))); |
| 20881 | | return ira->codegen->builtin_types.entry_invalid; |
| 20500 | return ira->codegen->invalid_instruction; |
| 20882 | 20501 | } |
| 20883 | | |
| 20884 | | return ira->codegen->builtin_types.entry_type; |
| 20502 | return ir_const_type(ira, &instruction->base, result_type); |
| 20885 | 20503 | } |
| 20886 | 20504 | |
| 20887 | | static ZigType *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) { |
| 20505 | static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) { |
| 20888 | 20506 | Error err; |
| 20889 | | IrInstruction *target_inst = instruction->target->other; |
| 20507 | IrInstruction *target_inst = instruction->target->child; |
| 20890 | 20508 | ZigType *enum_type = ir_resolve_type(ira, target_inst); |
| 20891 | 20509 | if (type_is_invalid(enum_type)) |
| 20892 | | return ira->codegen->builtin_types.entry_invalid; |
| 20510 | return ira->codegen->invalid_instruction; |
| 20893 | 20511 | |
| 20894 | 20512 | if (enum_type->id == ZigTypeIdEnum) { |
| 20895 | 20513 | if ((err = ensure_complete_type(ira->codegen, enum_type))) |
| 20896 | | return ira->codegen->builtin_types.entry_invalid; |
| 20514 | return ira->codegen->invalid_instruction; |
| 20897 | 20515 | |
| 20898 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20899 | | out_val->data.x_type = enum_type->data.enumeration.tag_int_type; |
| 20900 | | return ira->codegen->builtin_types.entry_type; |
| 20516 | return ir_const_type(ira, &instruction->base, enum_type->data.enumeration.tag_int_type); |
| 20901 | 20517 | } else if (enum_type->id == ZigTypeIdUnion) { |
| 20902 | 20518 | if ((err = ensure_complete_type(ira->codegen, enum_type))) |
| 20903 | | return ira->codegen->builtin_types.entry_invalid; |
| 20519 | return ira->codegen->invalid_instruction; |
| 20904 | 20520 | |
| 20905 | 20521 | AstNode *decl_node = enum_type->data.unionation.decl_node; |
| 20906 | 20522 | if (decl_node->data.container_decl.auto_enum || decl_node->data.container_decl.init_arg_expr != nullptr) { |
| 20907 | 20523 | assert(enum_type->data.unionation.tag_type != nullptr); |
| 20908 | 20524 | |
| 20909 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20910 | | out_val->data.x_type = enum_type->data.unionation.tag_type; |
| 20911 | | return ira->codegen->builtin_types.entry_type; |
| 20525 | return ir_const_type(ira, &instruction->base, enum_type->data.unionation.tag_type); |
| 20912 | 20526 | } else { |
| 20913 | 20527 | ErrorMsg *msg = ir_add_error(ira, target_inst, buf_sprintf("union '%s' has no tag", |
| 20914 | 20528 | buf_ptr(&enum_type->name))); |
| 20915 | 20529 | add_error_note(ira->codegen, msg, decl_node, buf_sprintf("consider 'union(enum)' here")); |
| 20916 | | return ira->codegen->builtin_types.entry_invalid; |
| 20530 | return ira->codegen->invalid_instruction; |
| 20917 | 20531 | } |
| 20918 | 20532 | } else { |
| 20919 | 20533 | ir_add_error(ira, target_inst, buf_sprintf("expected enum or union, found '%s'", |
| 20920 | 20534 | buf_ptr(&enum_type->name))); |
| 20921 | | return ira->codegen->builtin_types.entry_invalid; |
| 20535 | return ira->codegen->invalid_instruction; |
| 20922 | 20536 | } |
| 20923 | 20537 | } |
| 20924 | 20538 | |
| 20925 | | static ZigType *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) { |
| 20926 | | IrInstruction *target_inst = instruction->target->other; |
| 20539 | static IrInstruction *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) { |
| 20540 | IrInstruction *target_inst = instruction->target->child; |
| 20927 | 20541 | if (type_is_invalid(target_inst->value.type)) |
| 20928 | | return ira->codegen->builtin_types.entry_invalid; |
| 20542 | return ira->codegen->invalid_instruction; |
| 20929 | 20543 | IrInstruction *casted_target = ir_implicit_cast(ira, target_inst, ira->codegen->builtin_types.entry_promise); |
| 20930 | 20544 | if (type_is_invalid(casted_target->value.type)) |
| 20931 | | return ira->codegen->builtin_types.entry_invalid; |
| 20545 | return ira->codegen->invalid_instruction; |
| 20932 | 20546 | |
| 20933 | 20547 | IrInstruction *result = ir_build_cancel(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_target); |
| 20934 | 20548 | result->value.type = ira->codegen->builtin_types.entry_void; |
| 20935 | 20549 | result->value.special = ConstValSpecialStatic; |
| 20936 | | ir_link_new_instruction(result, &instruction->base); |
| 20937 | | return result->value.type; |
| 20550 | return result; |
| 20938 | 20551 | } |
| 20939 | 20552 | |
| 20940 | | static ZigType *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstructionCoroId *instruction) { |
| 20941 | | IrInstruction *promise_ptr = instruction->promise_ptr->other; |
| 20553 | static IrInstruction *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstructionCoroId *instruction) { |
| 20554 | IrInstruction *promise_ptr = instruction->promise_ptr->child; |
| 20942 | 20555 | if (type_is_invalid(promise_ptr->value.type)) |
| 20943 | | return ira->codegen->builtin_types.entry_invalid; |
| 20556 | return ira->codegen->invalid_instruction; |
| 20944 | 20557 | |
| 20945 | 20558 | IrInstruction *result = ir_build_coro_id(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 20946 | 20559 | promise_ptr); |
| 20947 | | ir_link_new_instruction(result, &instruction->base); |
| 20948 | 20560 | result->value.type = ira->codegen->builtin_types.entry_usize; |
| 20949 | | return result->value.type; |
| 20561 | return result; |
| 20950 | 20562 | } |
| 20951 | 20563 | |
| 20952 | | static ZigType *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstructionCoroAlloc *instruction) { |
| 20953 | | IrInstruction *coro_id = instruction->coro_id->other; |
| 20564 | static IrInstruction *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstructionCoroAlloc *instruction) { |
| 20565 | IrInstruction *coro_id = instruction->coro_id->child; |
| 20954 | 20566 | if (type_is_invalid(coro_id->value.type)) |
| 20955 | | return ira->codegen->builtin_types.entry_invalid; |
| 20567 | return ira->codegen->invalid_instruction; |
| 20956 | 20568 | |
| 20957 | 20569 | IrInstruction *result = ir_build_coro_alloc(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 20958 | 20570 | coro_id); |
| 20959 | | ir_link_new_instruction(result, &instruction->base); |
| 20960 | 20571 | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 20961 | | return result->value.type; |
| 20572 | return result; |
| 20962 | 20573 | } |
| 20963 | 20574 | |
| 20964 | | static ZigType *ir_analyze_instruction_coro_size(IrAnalyze *ira, IrInstructionCoroSize *instruction) { |
| 20575 | static IrInstruction *ir_analyze_instruction_coro_size(IrAnalyze *ira, IrInstructionCoroSize *instruction) { |
| 20965 | 20576 | IrInstruction *result = ir_build_coro_size(&ira->new_irb, instruction->base.scope, instruction->base.source_node); |
| 20966 | | ir_link_new_instruction(result, &instruction->base); |
| 20967 | 20577 | result->value.type = ira->codegen->builtin_types.entry_usize; |
| 20968 | | return result->value.type; |
| 20578 | return result; |
| 20969 | 20579 | } |
| 20970 | 20580 | |
| 20971 | | static ZigType *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstructionCoroBegin *instruction) { |
| 20972 | | IrInstruction *coro_id = instruction->coro_id->other; |
| 20581 | static IrInstruction *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstructionCoroBegin *instruction) { |
| 20582 | IrInstruction *coro_id = instruction->coro_id->child; |
| 20973 | 20583 | if (type_is_invalid(coro_id->value.type)) |
| 20974 | | return ira->codegen->builtin_types.entry_invalid; |
| 20584 | return ira->codegen->invalid_instruction; |
| 20975 | 20585 | |
| 20976 | | IrInstruction *coro_mem_ptr = instruction->coro_mem_ptr->other; |
| 20586 | IrInstruction *coro_mem_ptr = instruction->coro_mem_ptr->child; |
| 20977 | 20587 | if (type_is_invalid(coro_mem_ptr->value.type)) |
| 20978 | | return ira->codegen->builtin_types.entry_invalid; |
| 20588 | return ira->codegen->invalid_instruction; |
| 20979 | 20589 | |
| 20980 | 20590 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 20981 | 20591 | assert(fn_entry != nullptr); |
| 20982 | 20592 | IrInstruction *result = ir_build_coro_begin(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 20983 | 20593 | coro_id, coro_mem_ptr); |
| 20984 | | ir_link_new_instruction(result, &instruction->base); |
| 20985 | 20594 | result->value.type = get_promise_type(ira->codegen, fn_entry->type_entry->data.fn.fn_type_id.return_type); |
| 20986 | | return result->value.type; |
| 20595 | return result; |
| 20987 | 20596 | } |
| 20988 | 20597 | |
| 20989 | | static ZigType *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) { |
| 20990 | | IrInstruction *result = ir_get_implicit_allocator(ira, &instruction->base, instruction->id); |
| 20991 | | ir_link_new_instruction(result, &instruction->base); |
| 20992 | | return result->value.type; |
| 20598 | static IrInstruction *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) { |
| 20599 | return ir_get_implicit_allocator(ira, &instruction->base, instruction->id); |
| 20993 | 20600 | } |
| 20994 | 20601 | |
| 20995 | | static ZigType *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, IrInstructionCoroAllocFail *instruction) { |
| 20996 | | IrInstruction *err_val = instruction->err_val->other; |
| 20602 | static IrInstruction *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, IrInstructionCoroAllocFail *instruction) { |
| 20603 | IrInstruction *err_val = instruction->err_val->child; |
| 20997 | 20604 | if (type_is_invalid(err_val->value.type)) |
| 20998 | 20605 | return ir_unreach_error(ira); |
| 20999 | 20606 | |
| 21000 | 20607 | IrInstruction *result = ir_build_coro_alloc_fail(&ira->new_irb, instruction->base.scope, instruction->base.source_node, err_val); |
| 21001 | | ir_link_new_instruction(result, &instruction->base); |
| 21002 | 20608 | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 21003 | | return ir_finish_anal(ira, result->value.type); |
| 20609 | return ir_finish_anal(ira, result); |
| 21004 | 20610 | } |
| 21005 | 20611 | |
| 21006 | | static ZigType *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrInstructionCoroSuspend *instruction) { |
| 20612 | static IrInstruction *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrInstructionCoroSuspend *instruction) { |
| 21007 | 20613 | IrInstruction *save_point = nullptr; |
| 21008 | 20614 | if (instruction->save_point != nullptr) { |
| 21009 | | save_point = instruction->save_point->other; |
| 20615 | save_point = instruction->save_point->child; |
| 21010 | 20616 | if (type_is_invalid(save_point->value.type)) |
| 21011 | | return ira->codegen->builtin_types.entry_invalid; |
| 20617 | return ira->codegen->invalid_instruction; |
| 21012 | 20618 | } |
| 21013 | 20619 | |
| 21014 | | IrInstruction *is_final = instruction->is_final->other; |
| 20620 | IrInstruction *is_final = instruction->is_final->child; |
| 21015 | 20621 | if (type_is_invalid(is_final->value.type)) |
| 21016 | | return ira->codegen->builtin_types.entry_invalid; |
| 20622 | return ira->codegen->invalid_instruction; |
| 21017 | 20623 | |
| 21018 | 20624 | IrInstruction *result = ir_build_coro_suspend(&ira->new_irb, instruction->base.scope, |
| 21019 | 20625 | instruction->base.source_node, save_point, is_final); |
| 21020 | | ir_link_new_instruction(result, &instruction->base); |
| 21021 | 20626 | result->value.type = ira->codegen->builtin_types.entry_u8; |
| 21022 | | return result->value.type; |
| 20627 | return result; |
| 21023 | 20628 | } |
| 21024 | 20629 | |
| 21025 | | static ZigType *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstructionCoroEnd *instruction) { |
| 20630 | static IrInstruction *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstructionCoroEnd *instruction) { |
| 21026 | 20631 | IrInstruction *result = ir_build_coro_end(&ira->new_irb, instruction->base.scope, |
| 21027 | 20632 | instruction->base.source_node); |
| 21028 | | ir_link_new_instruction(result, &instruction->base); |
| 21029 | 20633 | result->value.type = ira->codegen->builtin_types.entry_void; |
| 21030 | | return result->value.type; |
| 20634 | return result; |
| 21031 | 20635 | } |
| 21032 | 20636 | |
| 21033 | | static ZigType *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstructionCoroFree *instruction) { |
| 21034 | | IrInstruction *coro_id = instruction->coro_id->other; |
| 20637 | static IrInstruction *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstructionCoroFree *instruction) { |
| 20638 | IrInstruction *coro_id = instruction->coro_id->child; |
| 21035 | 20639 | if (type_is_invalid(coro_id->value.type)) |
| 21036 | | return ira->codegen->builtin_types.entry_invalid; |
| 20640 | return ira->codegen->invalid_instruction; |
| 21037 | 20641 | |
| 21038 | | IrInstruction *coro_handle = instruction->coro_handle->other; |
| 20642 | IrInstruction *coro_handle = instruction->coro_handle->child; |
| 21039 | 20643 | if (type_is_invalid(coro_handle->value.type)) |
| 21040 | | return ira->codegen->builtin_types.entry_invalid; |
| 20644 | return ira->codegen->invalid_instruction; |
| 21041 | 20645 | |
| 21042 | 20646 | IrInstruction *result = ir_build_coro_free(&ira->new_irb, instruction->base.scope, |
| 21043 | 20647 | instruction->base.source_node, coro_id, coro_handle); |
| 21044 | | ir_link_new_instruction(result, &instruction->base); |
| 21045 | 20648 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false); |
| 21046 | 20649 | result->value.type = get_optional_type(ira->codegen, ptr_type); |
| 21047 | | return result->value.type; |
| 20650 | return result; |
| 21048 | 20651 | } |
| 21049 | 20652 | |
| 21050 | | static ZigType *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstructionCoroResume *instruction) { |
| 21051 | | IrInstruction *awaiter_handle = instruction->awaiter_handle->other; |
| 20653 | static IrInstruction *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstructionCoroResume *instruction) { |
| 20654 | IrInstruction *awaiter_handle = instruction->awaiter_handle->child; |
| 21052 | 20655 | if (type_is_invalid(awaiter_handle->value.type)) |
| 21053 | | return ira->codegen->builtin_types.entry_invalid; |
| 20656 | return ira->codegen->invalid_instruction; |
| 21054 | 20657 | |
| 21055 | 20658 | IrInstruction *casted_target = ir_implicit_cast(ira, awaiter_handle, ira->codegen->builtin_types.entry_promise); |
| 21056 | 20659 | if (type_is_invalid(casted_target->value.type)) |
| 21057 | | return ira->codegen->builtin_types.entry_invalid; |
| 20660 | return ira->codegen->invalid_instruction; |
| 21058 | 20661 | |
| 21059 | 20662 | IrInstruction *result = ir_build_coro_resume(&ira->new_irb, instruction->base.scope, |
| 21060 | 20663 | instruction->base.source_node, casted_target); |
| 21061 | | ir_link_new_instruction(result, &instruction->base); |
| 21062 | 20664 | result->value.type = ira->codegen->builtin_types.entry_void; |
| 21063 | | return result->value.type; |
| 20665 | return result; |
| 21064 | 20666 | } |
| 21065 | 20667 | |
| 21066 | | static ZigType *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstructionCoroSave *instruction) { |
| 21067 | | IrInstruction *coro_handle = instruction->coro_handle->other; |
| 20668 | static IrInstruction *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstructionCoroSave *instruction) { |
| 20669 | IrInstruction *coro_handle = instruction->coro_handle->child; |
| 21068 | 20670 | if (type_is_invalid(coro_handle->value.type)) |
| 21069 | | return ira->codegen->builtin_types.entry_invalid; |
| 20671 | return ira->codegen->invalid_instruction; |
| 21070 | 20672 | |
| 21071 | 20673 | IrInstruction *result = ir_build_coro_save(&ira->new_irb, instruction->base.scope, |
| 21072 | 20674 | instruction->base.source_node, coro_handle); |
| 21073 | | ir_link_new_instruction(result, &instruction->base); |
| 21074 | 20675 | result->value.type = ira->codegen->builtin_types.entry_usize; |
| 21075 | | return result->value.type; |
| 20676 | return result; |
| 21076 | 20677 | } |
| 21077 | 20678 | |
| 21078 | | static ZigType *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructionCoroPromise *instruction) { |
| 21079 | | IrInstruction *coro_handle = instruction->coro_handle->other; |
| 20679 | static IrInstruction *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructionCoroPromise *instruction) { |
| 20680 | IrInstruction *coro_handle = instruction->coro_handle->child; |
| 21080 | 20681 | if (type_is_invalid(coro_handle->value.type)) |
| 21081 | | return ira->codegen->builtin_types.entry_invalid; |
| 20682 | return ira->codegen->invalid_instruction; |
| 21082 | 20683 | |
| 21083 | 20684 | if (coro_handle->value.type->id != ZigTypeIdPromise || |
| 21084 | 20685 | coro_handle->value.type->data.promise.result_type == nullptr) |
| 21085 | 20686 | { |
| 21086 | 20687 | ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'", |
| 21087 | 20688 | buf_ptr(&coro_handle->value.type->name))); |
| 21088 | | return ira->codegen->builtin_types.entry_invalid; |
| 20689 | return ira->codegen->invalid_instruction; |
| 21089 | 20690 | } |
| 21090 | 20691 | |
| 21091 | 20692 | ZigType *coro_frame_type = get_promise_frame_type(ira->codegen, |
| ... | ... | @@ -21093,26 +20694,24 @@ static ZigType *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructio |
| 21093 | 20694 | |
| 21094 | 20695 | IrInstruction *result = ir_build_coro_promise(&ira->new_irb, instruction->base.scope, |
| 21095 | 20696 | instruction->base.source_node, coro_handle); |
| 21096 | | ir_link_new_instruction(result, &instruction->base); |
| 21097 | 20697 | result->value.type = get_pointer_to_type(ira->codegen, coro_frame_type, false); |
| 21098 | | return result->value.type; |
| 20698 | return result; |
| 21099 | 20699 | } |
| 21100 | 20700 | |
| 21101 | | static ZigType *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, IrInstructionCoroAllocHelper *instruction) { |
| 21102 | | IrInstruction *alloc_fn = instruction->alloc_fn->other; |
| 20701 | static IrInstruction *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, IrInstructionCoroAllocHelper *instruction) { |
| 20702 | IrInstruction *alloc_fn = instruction->alloc_fn->child; |
| 21103 | 20703 | if (type_is_invalid(alloc_fn->value.type)) |
| 21104 | | return ira->codegen->builtin_types.entry_invalid; |
| 20704 | return ira->codegen->invalid_instruction; |
| 21105 | 20705 | |
| 21106 | | IrInstruction *coro_size = instruction->coro_size->other; |
| 20706 | IrInstruction *coro_size = instruction->coro_size->child; |
| 21107 | 20707 | if (type_is_invalid(coro_size->value.type)) |
| 21108 | | return ira->codegen->builtin_types.entry_invalid; |
| 20708 | return ira->codegen->invalid_instruction; |
| 21109 | 20709 | |
| 21110 | 20710 | IrInstruction *result = ir_build_coro_alloc_helper(&ira->new_irb, instruction->base.scope, |
| 21111 | 20711 | instruction->base.source_node, alloc_fn, coro_size); |
| 21112 | | ir_link_new_instruction(result, &instruction->base); |
| 21113 | 20712 | ZigType *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false); |
| 21114 | 20713 | result->value.type = get_optional_type(ira->codegen, u8_ptr_type); |
| 21115 | | return result->value.type; |
| 20714 | return result; |
| 21116 | 20715 | } |
| 21117 | 20716 | |
| 21118 | 20717 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) { |
| ... | ... | @@ -21147,48 +20746,48 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op |
| 21147 | 20746 | return operand_type; |
| 21148 | 20747 | } |
| 21149 | 20748 | |
| 21150 | | static ZigType *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) { |
| 21151 | | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other); |
| 20749 | static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) { |
| 20750 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child); |
| 21152 | 20751 | if (type_is_invalid(operand_type)) |
| 21153 | | return ira->codegen->builtin_types.entry_invalid; |
| 20752 | return ira->codegen->invalid_instruction; |
| 21154 | 20753 | |
| 21155 | | IrInstruction *ptr_inst = instruction->ptr->other; |
| 20754 | IrInstruction *ptr_inst = instruction->ptr->child; |
| 21156 | 20755 | if (type_is_invalid(ptr_inst->value.type)) |
| 21157 | | return ira->codegen->builtin_types.entry_invalid; |
| 20756 | return ira->codegen->invalid_instruction; |
| 21158 | 20757 | |
| 21159 | 20758 | // TODO let this be volatile |
| 21160 | 20759 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 21161 | 20760 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 21162 | 20761 | if (type_is_invalid(casted_ptr->value.type)) |
| 21163 | | return ira->codegen->builtin_types.entry_invalid; |
| 20762 | return ira->codegen->invalid_instruction; |
| 21164 | 20763 | |
| 21165 | 20764 | AtomicRmwOp op; |
| 21166 | 20765 | if (instruction->op == nullptr) { |
| 21167 | 20766 | op = instruction->resolved_op; |
| 21168 | 20767 | } else { |
| 21169 | | if (!ir_resolve_atomic_rmw_op(ira, instruction->op->other, &op)) { |
| 21170 | | return ira->codegen->builtin_types.entry_invalid; |
| 20768 | if (!ir_resolve_atomic_rmw_op(ira, instruction->op->child, &op)) { |
| 20769 | return ira->codegen->invalid_instruction; |
| 21171 | 20770 | } |
| 21172 | 20771 | } |
| 21173 | 20772 | |
| 21174 | | IrInstruction *operand = instruction->operand->other; |
| 20773 | IrInstruction *operand = instruction->operand->child; |
| 21175 | 20774 | if (type_is_invalid(operand->value.type)) |
| 21176 | | return ira->codegen->builtin_types.entry_invalid; |
| 20775 | return ira->codegen->invalid_instruction; |
| 21177 | 20776 | |
| 21178 | 20777 | IrInstruction *casted_operand = ir_implicit_cast(ira, operand, operand_type); |
| 21179 | 20778 | if (type_is_invalid(casted_operand->value.type)) |
| 21180 | | return ira->codegen->builtin_types.entry_invalid; |
| 20779 | return ira->codegen->invalid_instruction; |
| 21181 | 20780 | |
| 21182 | 20781 | AtomicOrder ordering; |
| 21183 | 20782 | if (instruction->ordering == nullptr) { |
| 21184 | 20783 | ordering = instruction->resolved_ordering; |
| 21185 | 20784 | } else { |
| 21186 | | if (!ir_resolve_atomic_order(ira, instruction->ordering->other, &ordering)) |
| 21187 | | return ira->codegen->builtin_types.entry_invalid; |
| 20785 | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 20786 | return ira->codegen->invalid_instruction; |
| 21188 | 20787 | if (ordering == AtomicOrderUnordered) { |
| 21189 | 20788 | ir_add_error(ira, instruction->ordering, |
| 21190 | 20789 | buf_sprintf("@atomicRmw atomic ordering must not be Unordered")); |
| 21191 | | return ira->codegen->builtin_types.entry_invalid; |
| 20790 | return ira->codegen->invalid_instruction; |
| 21192 | 20791 | } |
| 21193 | 20792 | } |
| 21194 | 20793 | |
| ... | ... | @@ -21200,74 +20799,69 @@ static ZigType *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionA |
| 21200 | 20799 | IrInstruction *result = ir_build_atomic_rmw(&ira->new_irb, instruction->base.scope, |
| 21201 | 20800 | instruction->base.source_node, nullptr, casted_ptr, nullptr, casted_operand, nullptr, |
| 21202 | 20801 | op, ordering); |
| 21203 | | ir_link_new_instruction(result, &instruction->base); |
| 21204 | 20802 | result->value.type = operand_type; |
| 21205 | | return result->value.type; |
| 20803 | return result; |
| 21206 | 20804 | } |
| 21207 | 20805 | |
| 21208 | | static ZigType *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) { |
| 21209 | | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other); |
| 20806 | static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) { |
| 20807 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child); |
| 21210 | 20808 | if (type_is_invalid(operand_type)) |
| 21211 | | return ira->codegen->builtin_types.entry_invalid; |
| 20809 | return ira->codegen->invalid_instruction; |
| 21212 | 20810 | |
| 21213 | | IrInstruction *ptr_inst = instruction->ptr->other; |
| 20811 | IrInstruction *ptr_inst = instruction->ptr->child; |
| 21214 | 20812 | if (type_is_invalid(ptr_inst->value.type)) |
| 21215 | | return ira->codegen->builtin_types.entry_invalid; |
| 20813 | return ira->codegen->invalid_instruction; |
| 21216 | 20814 | |
| 21217 | 20815 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true); |
| 21218 | 20816 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 21219 | 20817 | if (type_is_invalid(casted_ptr->value.type)) |
| 21220 | | return ira->codegen->builtin_types.entry_invalid; |
| 20818 | return ira->codegen->invalid_instruction; |
| 21221 | 20819 | |
| 21222 | 20820 | AtomicOrder ordering; |
| 21223 | 20821 | if (instruction->ordering == nullptr) { |
| 21224 | 20822 | ordering = instruction->resolved_ordering; |
| 21225 | 20823 | } else { |
| 21226 | | if (!ir_resolve_atomic_order(ira, instruction->ordering->other, &ordering)) |
| 21227 | | return ira->codegen->builtin_types.entry_invalid; |
| 20824 | if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering)) |
| 20825 | return ira->codegen->invalid_instruction; |
| 21228 | 20826 | } |
| 21229 | 20827 | |
| 21230 | 20828 | if (ordering == AtomicOrderRelease || ordering == AtomicOrderAcqRel) { |
| 21231 | 20829 | assert(instruction->ordering != nullptr); |
| 21232 | 20830 | ir_add_error(ira, instruction->ordering, |
| 21233 | 20831 | buf_sprintf("@atomicLoad atomic ordering must not be Release or AcqRel")); |
| 21234 | | return ira->codegen->builtin_types.entry_invalid; |
| 20832 | return ira->codegen->invalid_instruction; |
| 21235 | 20833 | } |
| 21236 | 20834 | |
| 21237 | 20835 | if (instr_is_comptime(casted_ptr)) { |
| 21238 | 20836 | IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr); |
| 21239 | | ir_link_new_instruction(result, &instruction->base); |
| 21240 | 20837 | assert(result->value.type != nullptr); |
| 21241 | | return result->value.type; |
| 20838 | return result; |
| 21242 | 20839 | } |
| 21243 | 20840 | |
| 21244 | 20841 | IrInstruction *result = ir_build_atomic_load(&ira->new_irb, instruction->base.scope, |
| 21245 | 20842 | instruction->base.source_node, nullptr, casted_ptr, nullptr, ordering); |
| 21246 | | ir_link_new_instruction(result, &instruction->base); |
| 21247 | 20843 | result->value.type = operand_type; |
| 21248 | | return result->value.type; |
| 20844 | return result; |
| 21249 | 20845 | } |
| 21250 | 20846 | |
| 21251 | | static ZigType *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) { |
| 21252 | | ZigType *promise_type = ir_resolve_type(ira, instruction->promise_type->other); |
| 20847 | static IrInstruction *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) { |
| 20848 | ZigType *promise_type = ir_resolve_type(ira, instruction->promise_type->child); |
| 21253 | 20849 | if (type_is_invalid(promise_type)) |
| 21254 | | return ira->codegen->builtin_types.entry_invalid; |
| 20850 | return ira->codegen->invalid_instruction; |
| 21255 | 20851 | |
| 21256 | 20852 | if (promise_type->id != ZigTypeIdPromise || promise_type->data.promise.result_type == nullptr) { |
| 21257 | 20853 | ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'", |
| 21258 | 20854 | buf_ptr(&promise_type->name))); |
| 21259 | | return ira->codegen->builtin_types.entry_invalid; |
| 20855 | return ira->codegen->invalid_instruction; |
| 21260 | 20856 | } |
| 21261 | 20857 | |
| 21262 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 21263 | | out_val->data.x_type = promise_type->data.promise.result_type; |
| 21264 | | return ira->codegen->builtin_types.entry_type; |
| 20858 | return ir_const_type(ira, &instruction->base, promise_type->data.promise.result_type); |
| 21265 | 20859 | } |
| 21266 | 20860 | |
| 21267 | | static ZigType *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) { |
| 21268 | | ZigType *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->other); |
| 20861 | static IrInstruction *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) { |
| 20862 | ZigType *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->child); |
| 21269 | 20863 | if (type_is_invalid(promise_result_type)) |
| 21270 | | return ira->codegen->builtin_types.entry_invalid; |
| 20864 | return ira->codegen->invalid_instruction; |
| 21271 | 20865 | |
| 21272 | 20866 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 21273 | 20867 | assert(fn_entry != nullptr); |
| ... | ... | @@ -21276,17 +20870,15 @@ static ZigType *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstr |
| 21276 | 20870 | fn_entry->calls_or_awaits_errorable_fn = true; |
| 21277 | 20871 | } |
| 21278 | 20872 | |
| 21279 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 21280 | | out_val->type = ira->codegen->builtin_types.entry_void; |
| 21281 | | return out_val->type; |
| 20873 | return ir_const_void(ira, &instruction->base); |
| 21282 | 20874 | } |
| 21283 | 20875 | |
| 21284 | | static ZigType *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira, |
| 20876 | static IrInstruction *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira, |
| 21285 | 20877 | IrInstructionMergeErrRetTraces *instruction) |
| 21286 | 20878 | { |
| 21287 | | IrInstruction *coro_promise_ptr = instruction->coro_promise_ptr->other; |
| 20879 | IrInstruction *coro_promise_ptr = instruction->coro_promise_ptr->child; |
| 21288 | 20880 | if (type_is_invalid(coro_promise_ptr->value.type)) |
| 21289 | | return ira->codegen->builtin_types.entry_invalid; |
| 20881 | return ira->codegen->invalid_instruction; |
| 21290 | 20882 | |
| 21291 | 20883 | assert(coro_promise_ptr->value.type->id == ZigTypeIdPointer); |
| 21292 | 20884 | ZigType *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type; |
| ... | ... | @@ -21294,71 +20886,67 @@ static ZigType *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira, |
| 21294 | 20886 | ZigType *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry; |
| 21295 | 20887 | |
| 21296 | 20888 | if (!type_can_fail(promise_result_type)) { |
| 21297 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 21298 | | out_val->type = ira->codegen->builtin_types.entry_void; |
| 21299 | | return out_val->type; |
| 20889 | return ir_const_void(ira, &instruction->base); |
| 21300 | 20890 | } |
| 21301 | 20891 | |
| 21302 | | IrInstruction *src_err_ret_trace_ptr = instruction->src_err_ret_trace_ptr->other; |
| 20892 | IrInstruction *src_err_ret_trace_ptr = instruction->src_err_ret_trace_ptr->child; |
| 21303 | 20893 | if (type_is_invalid(src_err_ret_trace_ptr->value.type)) |
| 21304 | | return ira->codegen->builtin_types.entry_invalid; |
| 20894 | return ira->codegen->invalid_instruction; |
| 21305 | 20895 | |
| 21306 | | IrInstruction *dest_err_ret_trace_ptr = instruction->dest_err_ret_trace_ptr->other; |
| 20896 | IrInstruction *dest_err_ret_trace_ptr = instruction->dest_err_ret_trace_ptr->child; |
| 21307 | 20897 | if (type_is_invalid(dest_err_ret_trace_ptr->value.type)) |
| 21308 | | return ira->codegen->builtin_types.entry_invalid; |
| 20898 | return ira->codegen->invalid_instruction; |
| 21309 | 20899 | |
| 21310 | 20900 | IrInstruction *result = ir_build_merge_err_ret_traces(&ira->new_irb, instruction->base.scope, |
| 21311 | 20901 | instruction->base.source_node, coro_promise_ptr, src_err_ret_trace_ptr, dest_err_ret_trace_ptr); |
| 21312 | | ir_link_new_instruction(result, &instruction->base); |
| 21313 | 20902 | result->value.type = ira->codegen->builtin_types.entry_void; |
| 21314 | | return result->value.type; |
| 20903 | return result; |
| 21315 | 20904 | } |
| 21316 | 20905 | |
| 21317 | | static ZigType *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) { |
| 20906 | static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) { |
| 21318 | 20907 | IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope, |
| 21319 | 20908 | instruction->base.source_node); |
| 21320 | | ir_link_new_instruction(result, &instruction->base); |
| 21321 | 20909 | result->value.type = ira->codegen->builtin_types.entry_void; |
| 21322 | | return result->value.type; |
| 20910 | return result; |
| 21323 | 20911 | } |
| 21324 | 20912 | |
| 21325 | | static ZigType *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *ira, IrInstructionMarkErrRetTracePtr *instruction) { |
| 21326 | | IrInstruction *err_ret_trace_ptr = instruction->err_ret_trace_ptr->other; |
| 20913 | static IrInstruction *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *ira, IrInstructionMarkErrRetTracePtr *instruction) { |
| 20914 | IrInstruction *err_ret_trace_ptr = instruction->err_ret_trace_ptr->child; |
| 21327 | 20915 | if (type_is_invalid(err_ret_trace_ptr->value.type)) |
| 21328 | | return ira->codegen->builtin_types.entry_invalid; |
| 20916 | return ira->codegen->invalid_instruction; |
| 21329 | 20917 | |
| 21330 | 20918 | IrInstruction *result = ir_build_mark_err_ret_trace_ptr(&ira->new_irb, instruction->base.scope, |
| 21331 | 20919 | instruction->base.source_node, err_ret_trace_ptr); |
| 21332 | | ir_link_new_instruction(result, &instruction->base); |
| 21333 | 20920 | result->value.type = ira->codegen->builtin_types.entry_void; |
| 21334 | | return result->value.type; |
| 20921 | return result; |
| 21335 | 20922 | } |
| 21336 | 20923 | |
| 21337 | | static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) { |
| 21338 | | ZigType *float_type = ir_resolve_type(ira, instruction->type->other); |
| 20924 | static IrInstruction *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) { |
| 20925 | ZigType *float_type = ir_resolve_type(ira, instruction->type->child); |
| 21339 | 20926 | if (type_is_invalid(float_type)) |
| 21340 | | return ira->codegen->builtin_types.entry_invalid; |
| 20927 | return ira->codegen->invalid_instruction; |
| 21341 | 20928 | |
| 21342 | | IrInstruction *op = instruction->op->other; |
| 20929 | IrInstruction *op = instruction->op->child; |
| 21343 | 20930 | if (type_is_invalid(op->value.type)) |
| 21344 | | return ira->codegen->builtin_types.entry_invalid; |
| 20931 | return ira->codegen->invalid_instruction; |
| 21345 | 20932 | |
| 21346 | 20933 | bool ok_type = float_type->id == ZigTypeIdComptimeFloat || float_type->id == ZigTypeIdFloat; |
| 21347 | 20934 | if (!ok_type) { |
| 21348 | 20935 | ir_add_error(ira, instruction->type, buf_sprintf("@sqrt does not support type '%s'", buf_ptr(&float_type->name))); |
| 21349 | | return ira->codegen->builtin_types.entry_invalid; |
| 20936 | return ira->codegen->invalid_instruction; |
| 21350 | 20937 | } |
| 21351 | 20938 | |
| 21352 | 20939 | IrInstruction *casted_op = ir_implicit_cast(ira, op, float_type); |
| 21353 | 20940 | if (type_is_invalid(casted_op->value.type)) |
| 21354 | | return ira->codegen->builtin_types.entry_invalid; |
| 20941 | return ira->codegen->invalid_instruction; |
| 21355 | 20942 | |
| 21356 | 20943 | if (instr_is_comptime(casted_op)) { |
| 21357 | 20944 | ConstExprValue *val = ir_resolve_const(ira, casted_op, UndefBad); |
| 21358 | 20945 | if (!val) |
| 21359 | | return ira->codegen->builtin_types.entry_invalid; |
| 20946 | return ira->codegen->invalid_instruction; |
| 21360 | 20947 | |
| 21361 | | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20948 | IrInstruction *result = ir_const(ira, &instruction->base, float_type); |
| 20949 | ConstExprValue *out_val = &result->value; |
| 21362 | 20950 | |
| 21363 | 20951 | if (float_type->id == ZigTypeIdComptimeFloat) { |
| 21364 | 20952 | bigfloat_sqrt(&out_val->data.x_bigfloat, &val->data.x_bigfloat); |
| ... | ... | @@ -21383,7 +20971,7 @@ static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *i |
| 21383 | 20971 | zig_unreachable(); |
| 21384 | 20972 | } |
| 21385 | 20973 | |
| 21386 | | return float_type; |
| 20974 | return result; |
| 21387 | 20975 | } |
| 21388 | 20976 | |
| 21389 | 20977 | assert(float_type->id == ZigTypeIdFloat); |
| ... | ... | @@ -21391,93 +20979,87 @@ static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *i |
| 21391 | 20979 | float_type->data.floating.bit_count != 32 && |
| 21392 | 20980 | float_type->data.floating.bit_count != 64) { |
| 21393 | 20981 | ir_add_error(ira, instruction->type, buf_sprintf("compiler TODO: add implementation of sqrt for '%s'", buf_ptr(&float_type->name))); |
| 21394 | | return ira->codegen->builtin_types.entry_invalid; |
| 20982 | return ira->codegen->invalid_instruction; |
| 21395 | 20983 | } |
| 21396 | 20984 | |
| 21397 | 20985 | IrInstruction *result = ir_build_sqrt(&ira->new_irb, instruction->base.scope, |
| 21398 | 20986 | instruction->base.source_node, nullptr, casted_op); |
| 21399 | | ir_link_new_instruction(result, &instruction->base); |
| 21400 | 20987 | result->value.type = float_type; |
| 21401 | | return result->value.type; |
| 20988 | return result; |
| 21402 | 20989 | } |
| 21403 | 20990 | |
| 21404 | | static ZigType *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) { |
| 20991 | static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) { |
| 21405 | 20992 | Error err; |
| 21406 | | IrInstruction *target = instruction->target->other; |
| 20993 | IrInstruction *target = instruction->target->child; |
| 21407 | 20994 | if (type_is_invalid(target->value.type)) |
| 21408 | | return ira->codegen->builtin_types.entry_invalid; |
| 20995 | return ira->codegen->invalid_instruction; |
| 21409 | 20996 | |
| 21410 | 20997 | if (target->value.type->id != ZigTypeIdEnum) { |
| 21411 | 20998 | ir_add_error(ira, instruction->target, |
| 21412 | 20999 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name))); |
| 21413 | | return ira->codegen->builtin_types.entry_invalid; |
| 21000 | return ira->codegen->invalid_instruction; |
| 21414 | 21001 | } |
| 21415 | 21002 | |
| 21416 | 21003 | if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown))) |
| 21417 | | return ira->codegen->builtin_types.entry_invalid; |
| 21004 | return ira->codegen->invalid_instruction; |
| 21418 | 21005 | |
| 21419 | 21006 | ZigType *tag_type = target->value.type->data.enumeration.tag_int_type; |
| 21420 | 21007 | |
| 21421 | | IrInstruction *result = ir_analyze_enum_to_int(ira, &instruction->base, target, tag_type); |
| 21422 | | ir_link_new_instruction(result, &instruction->base); |
| 21423 | | return result->value.type; |
| 21008 | return ir_analyze_enum_to_int(ira, &instruction->base, target, tag_type); |
| 21424 | 21009 | } |
| 21425 | 21010 | |
| 21426 | | static ZigType *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) { |
| 21011 | static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) { |
| 21427 | 21012 | Error err; |
| 21428 | | IrInstruction *dest_type_value = instruction->dest_type->other; |
| 21013 | IrInstruction *dest_type_value = instruction->dest_type->child; |
| 21429 | 21014 | ZigType *dest_type = ir_resolve_type(ira, dest_type_value); |
| 21430 | 21015 | if (type_is_invalid(dest_type)) |
| 21431 | | return ira->codegen->builtin_types.entry_invalid; |
| 21016 | return ira->codegen->invalid_instruction; |
| 21432 | 21017 | |
| 21433 | 21018 | if (dest_type->id != ZigTypeIdEnum) { |
| 21434 | 21019 | ir_add_error(ira, instruction->dest_type, |
| 21435 | 21020 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name))); |
| 21436 | | return ira->codegen->builtin_types.entry_invalid; |
| 21021 | return ira->codegen->invalid_instruction; |
| 21437 | 21022 | } |
| 21438 | 21023 | |
| 21439 | 21024 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) |
| 21440 | | return ira->codegen->builtin_types.entry_invalid; |
| 21025 | return ira->codegen->invalid_instruction; |
| 21441 | 21026 | |
| 21442 | 21027 | ZigType *tag_type = dest_type->data.enumeration.tag_int_type; |
| 21443 | 21028 | |
| 21444 | | IrInstruction *target = instruction->target->other; |
| 21029 | IrInstruction *target = instruction->target->child; |
| 21445 | 21030 | if (type_is_invalid(target->value.type)) |
| 21446 | | return ira->codegen->builtin_types.entry_invalid; |
| 21031 | return ira->codegen->invalid_instruction; |
| 21447 | 21032 | |
| 21448 | 21033 | IrInstruction *casted_target = ir_implicit_cast(ira, target, tag_type); |
| 21449 | 21034 | if (type_is_invalid(casted_target->value.type)) |
| 21450 | | return ira->codegen->builtin_types.entry_invalid; |
| 21035 | return ira->codegen->invalid_instruction; |
| 21451 | 21036 | |
| 21452 | | IrInstruction *result = ir_analyze_int_to_enum(ira, &instruction->base, casted_target, dest_type); |
| 21453 | | ir_link_new_instruction(result, &instruction->base); |
| 21454 | | return result->value.type; |
| 21037 | return ir_analyze_int_to_enum(ira, &instruction->base, casted_target, dest_type); |
| 21455 | 21038 | } |
| 21456 | 21039 | |
| 21457 | | static ZigType *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstructionCheckRuntimeScope *instruction) { |
| 21458 | | IrInstruction *block_comptime_inst = instruction->scope_is_comptime->other; |
| 21040 | static IrInstruction *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstructionCheckRuntimeScope *instruction) { |
| 21041 | IrInstruction *block_comptime_inst = instruction->scope_is_comptime->child; |
| 21459 | 21042 | bool scope_is_comptime; |
| 21460 | 21043 | if (!ir_resolve_bool(ira, block_comptime_inst, &scope_is_comptime)) |
| 21461 | | return ira->codegen->builtin_types.entry_invalid; |
| 21044 | return ira->codegen->invalid_instruction; |
| 21462 | 21045 | |
| 21463 | | IrInstruction *is_comptime_inst = instruction->is_comptime->other; |
| 21046 | IrInstruction *is_comptime_inst = instruction->is_comptime->child; |
| 21464 | 21047 | bool is_comptime; |
| 21465 | 21048 | if (!ir_resolve_bool(ira, is_comptime_inst, &is_comptime)) |
| 21466 | | return ira->codegen->builtin_types.entry_invalid; |
| 21049 | return ira->codegen->invalid_instruction; |
| 21467 | 21050 | |
| 21468 | 21051 | if (!scope_is_comptime && is_comptime) { |
| 21469 | 21052 | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| 21470 | 21053 | buf_sprintf("comptime control flow inside runtime block")); |
| 21471 | 21054 | add_error_note(ira->codegen, msg, block_comptime_inst->source_node, |
| 21472 | 21055 | buf_sprintf("runtime block created here")); |
| 21473 | | return ira->codegen->builtin_types.entry_invalid; |
| 21056 | return ira->codegen->invalid_instruction; |
| 21474 | 21057 | } |
| 21475 | 21058 | |
| 21476 | | ir_build_const_from(ira, &instruction->base); |
| 21477 | | return ira->codegen->builtin_types.entry_void; |
| 21059 | return ir_const_void(ira, &instruction->base); |
| 21478 | 21060 | } |
| 21479 | 21061 | |
| 21480 | | static ZigType *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { |
| 21062 | static IrInstruction *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { |
| 21481 | 21063 | switch (instruction->id) { |
| 21482 | 21064 | case IrInstructionIdInvalid: |
| 21483 | 21065 | case IrInstructionIdWidenOrShorten: |
| ... | ... | @@ -21761,19 +21343,11 @@ static ZigType *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *ins |
| 21761 | 21343 | zig_unreachable(); |
| 21762 | 21344 | } |
| 21763 | 21345 | |
| 21764 | | static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) { |
| 21765 | | ZigType *instruction_type = ir_analyze_instruction_nocast(ira, instruction); |
| 21766 | | instruction->value.type = instruction_type; |
| 21767 | | |
| 21768 | | if (instruction->other) { |
| 21769 | | instruction->other->value.type = instruction_type; |
| 21770 | | } else { |
| 21771 | | assert(instruction_type->id == ZigTypeIdInvalid || |
| 21772 | | instruction_type->id == ZigTypeIdUnreachable); |
| 21773 | | instruction->other = instruction; |
| 21774 | | } |
| 21775 | | |
| 21776 | | return instruction_type; |
| 21346 | static IrInstruction *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *old_instruction) { |
| 21347 | IrInstruction *new_instruction = ir_analyze_instruction_nocast(ira, old_instruction); |
| 21348 | assert(new_instruction->value.type != nullptr); |
| 21349 | old_instruction->child = new_instruction; |
| 21350 | return new_instruction; |
| 21777 | 21351 | } |
| 21778 | 21352 | |
| 21779 | 21353 | // This function attempts to evaluate IR code while doing type checking and other analysis. |
| ... | ... | @@ -21820,13 +21394,13 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 21820 | 21394 | continue; |
| 21821 | 21395 | } |
| 21822 | 21396 | |
| 21823 | | ZigType *return_type = ir_analyze_instruction(ira, old_instruction); |
| 21824 | | if (type_is_invalid(return_type) && ir_should_inline(new_exec, old_instruction->scope)) { |
| 21397 | IrInstruction *new_instruction = ir_analyze_instruction(ira, old_instruction); |
| 21398 | if (type_is_invalid(new_instruction->value.type) && ir_should_inline(new_exec, old_instruction->scope)) { |
| 21825 | 21399 | return ira->codegen->builtin_types.entry_invalid; |
| 21826 | 21400 | } |
| 21827 | 21401 | |
| 21828 | 21402 | // unreachable instructions do their own control flow. |
| 21829 | | if (return_type->id == ZigTypeIdUnreachable) |
| 21403 | if (new_instruction->value.type->id == ZigTypeIdUnreachable) |
| 21830 | 21404 | continue; |
| 21831 | 21405 | |
| 21832 | 21406 | ira->instruction_index += 1; |