| ... | ... | @@ -421,11 +421,11 @@ static bool value_is_comptime(ZigValue *const_val) { |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | static bool instr_is_comptime(IrInstruction *instruction) { |
| 424 | | return value_is_comptime(&instruction->value); |
| 424 | return value_is_comptime(instruction->value); |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | static bool instr_is_unreachable(IrInstruction *instruction) { |
| 428 | | return instruction->value.type && instruction->value.type->id == ZigTypeIdUnreachable; |
| 428 | return instruction->value->type && instruction->value->type->id == ZigTypeIdUnreachable; |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | static void ir_link_new_bb(IrBasicBlock *new_bb, IrBasicBlock *old_bb) { |
| ... | ... | @@ -1156,7 +1156,8 @@ static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_no |
| 1156 | 1156 | special_instruction->base.source_node = source_node; |
| 1157 | 1157 | special_instruction->base.debug_id = exec_next_debug_id(irb->exec); |
| 1158 | 1158 | special_instruction->base.owner_bb = irb->current_basic_block; |
| 1159 | | special_instruction->base.value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs"); |
| 1159 | special_instruction->base.value = allocate<ZigValue>(1, "ZigValue"); |
| 1160 | special_instruction->base.value->global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs"); |
| 1160 | 1161 | return special_instruction; |
| 1161 | 1162 | } |
| 1162 | 1163 | |
| ... | ... | @@ -1184,8 +1185,8 @@ static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *so |
| 1184 | 1185 | IrBasicBlock *then_block, IrBasicBlock *else_block, IrInstruction *is_comptime) |
| 1185 | 1186 | { |
| 1186 | 1187 | IrInstructionCondBr *cond_br_instruction = ir_build_instruction<IrInstructionCondBr>(irb, scope, source_node); |
| 1187 | | cond_br_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 1188 | | cond_br_instruction->base.value.special = ConstValSpecialStatic; |
| 1188 | cond_br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 1189 | cond_br_instruction->base.value->special = ConstValSpecialStatic; |
| 1189 | 1190 | cond_br_instruction->condition = condition; |
| 1190 | 1191 | cond_br_instruction->then_block = then_block; |
| 1191 | 1192 | cond_br_instruction->else_block = else_block; |
| ... | ... | @@ -1203,8 +1204,8 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1203 | 1204 | IrInstruction *operand) |
| 1204 | 1205 | { |
| 1205 | 1206 | IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node); |
| 1206 | | return_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 1207 | | return_instruction->base.value.special = ConstValSpecialStatic; |
| 1207 | return_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 1208 | return_instruction->base.value->special = ConstValSpecialStatic; |
| 1208 | 1209 | return_instruction->operand = operand; |
| 1209 | 1210 | |
| 1210 | 1211 | if (operand != nullptr) ir_ref_instruction(operand, irb->current_basic_block); |
| ... | ... | @@ -1214,54 +1215,54 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1214 | 1215 | |
| 1215 | 1216 | static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1216 | 1217 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1217 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 1218 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1218 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 1219 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1219 | 1220 | return &const_instruction->base; |
| 1220 | 1221 | } |
| 1221 | 1222 | |
| 1222 | 1223 | static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1223 | 1224 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1224 | | const_instruction->base.value.special = ConstValSpecialUndef; |
| 1225 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_undef; |
| 1225 | const_instruction->base.value->special = ConstValSpecialUndef; |
| 1226 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_undef; |
| 1226 | 1227 | return &const_instruction->base; |
| 1227 | 1228 | } |
| 1228 | 1229 | |
| 1229 | 1230 | static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) { |
| 1230 | 1231 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1231 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_num_lit_int; |
| 1232 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1233 | | bigint_init_unsigned(&const_instruction->base.value.data.x_bigint, value); |
| 1232 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int; |
| 1233 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1234 | bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value); |
| 1234 | 1235 | return &const_instruction->base; |
| 1235 | 1236 | } |
| 1236 | 1237 | |
| 1237 | 1238 | static IrInstruction *ir_build_const_bigint(IrBuilder *irb, Scope *scope, AstNode *source_node, BigInt *bigint) { |
| 1238 | 1239 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1239 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_num_lit_int; |
| 1240 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1241 | | bigint_init_bigint(&const_instruction->base.value.data.x_bigint, bigint); |
| 1240 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int; |
| 1241 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1242 | bigint_init_bigint(&const_instruction->base.value->data.x_bigint, bigint); |
| 1242 | 1243 | return &const_instruction->base; |
| 1243 | 1244 | } |
| 1244 | 1245 | |
| 1245 | 1246 | static IrInstruction *ir_build_const_bigfloat(IrBuilder *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) { |
| 1246 | 1247 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1247 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_num_lit_float; |
| 1248 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1249 | | bigfloat_init_bigfloat(&const_instruction->base.value.data.x_bigfloat, bigfloat); |
| 1248 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_float; |
| 1249 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1250 | bigfloat_init_bigfloat(&const_instruction->base.value->data.x_bigfloat, bigfloat); |
| 1250 | 1251 | return &const_instruction->base; |
| 1251 | 1252 | } |
| 1252 | 1253 | |
| 1253 | 1254 | static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1254 | 1255 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1255 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_null; |
| 1256 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1256 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_null; |
| 1257 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1257 | 1258 | return &const_instruction->base; |
| 1258 | 1259 | } |
| 1259 | 1260 | |
| 1260 | 1261 | static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) { |
| 1261 | 1262 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1262 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_usize; |
| 1263 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1264 | | bigint_init_unsigned(&const_instruction->base.value.data.x_bigint, value); |
| 1263 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_usize; |
| 1264 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1265 | bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value); |
| 1265 | 1266 | return &const_instruction->base; |
| 1266 | 1267 | } |
| 1267 | 1268 | |
| ... | ... | @@ -1269,9 +1270,9 @@ static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode |
| 1269 | 1270 | ZigType *type_entry) |
| 1270 | 1271 | { |
| 1271 | 1272 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1272 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_type; |
| 1273 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1274 | | const_instruction->base.value.data.x_type = type_entry; |
| 1273 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_type; |
| 1274 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1275 | const_instruction->base.value->data.x_type = type_entry; |
| 1275 | 1276 | return &const_instruction->base; |
| 1276 | 1277 | } |
| 1277 | 1278 | |
| ... | ... | @@ -1285,35 +1286,35 @@ static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode |
| 1285 | 1286 | |
| 1286 | 1287 | static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) { |
| 1287 | 1288 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1288 | | const_instruction->base.value.type = fn_entry->type_entry; |
| 1289 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1290 | | const_instruction->base.value.data.x_ptr.data.fn.fn_entry = fn_entry; |
| 1291 | | const_instruction->base.value.data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 1292 | | const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialFunction; |
| 1289 | const_instruction->base.value->type = fn_entry->type_entry; |
| 1290 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1291 | const_instruction->base.value->data.x_ptr.data.fn.fn_entry = fn_entry; |
| 1292 | const_instruction->base.value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 1293 | const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialFunction; |
| 1293 | 1294 | return &const_instruction->base; |
| 1294 | 1295 | } |
| 1295 | 1296 | |
| 1296 | 1297 | static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *import) { |
| 1297 | 1298 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1298 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_type; |
| 1299 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1300 | | const_instruction->base.value.data.x_type = import; |
| 1299 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_type; |
| 1300 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1301 | const_instruction->base.value->data.x_type = import; |
| 1301 | 1302 | return &const_instruction->base; |
| 1302 | 1303 | } |
| 1303 | 1304 | |
| 1304 | 1305 | static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) { |
| 1305 | 1306 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1306 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_bool; |
| 1307 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1308 | | const_instruction->base.value.data.x_bool = value; |
| 1307 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_bool; |
| 1308 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1309 | const_instruction->base.value->data.x_bool = value; |
| 1309 | 1310 | return &const_instruction->base; |
| 1310 | 1311 | } |
| 1311 | 1312 | |
| 1312 | 1313 | static IrInstruction *ir_build_const_enum_literal(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *name) { |
| 1313 | 1314 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1314 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_enum_literal; |
| 1315 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1316 | | const_instruction->base.value.data.x_enum_literal = name; |
| 1315 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_enum_literal; |
| 1316 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1317 | const_instruction->base.value->data.x_enum_literal = name; |
| 1317 | 1318 | return &const_instruction->base; |
| 1318 | 1319 | } |
| 1319 | 1320 | |
| ... | ... | @@ -1321,19 +1322,20 @@ static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstN |
| 1321 | 1322 | ZigFn *fn_entry, IrInstruction *first_arg) |
| 1322 | 1323 | { |
| 1323 | 1324 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1324 | | const_instruction->base.value.type = get_bound_fn_type(irb->codegen, fn_entry); |
| 1325 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1326 | | const_instruction->base.value.data.x_bound_fn.fn = fn_entry; |
| 1327 | | const_instruction->base.value.data.x_bound_fn.first_arg = first_arg; |
| 1325 | const_instruction->base.value->type = get_bound_fn_type(irb->codegen, fn_entry); |
| 1326 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1327 | const_instruction->base.value->data.x_bound_fn.fn = fn_entry; |
| 1328 | const_instruction->base.value->data.x_bound_fn.first_arg = first_arg; |
| 1328 | 1329 | return &const_instruction->base; |
| 1329 | 1330 | } |
| 1330 | 1331 | |
| 1331 | 1332 | static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| 1332 | 1333 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1333 | | init_const_str_lit(irb->codegen, &const_instruction->base.value, str); |
| 1334 | init_const_str_lit(irb->codegen, const_instruction->base.value, str); |
| 1334 | 1335 | |
| 1335 | 1336 | return &const_instruction->base; |
| 1336 | 1337 | } |
| 1338 | |
| 1337 | 1339 | static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| 1338 | 1340 | IrInstruction *instruction = ir_create_const_str_lit(irb, scope, source_node, str); |
| 1339 | 1341 | ir_instruction_append(irb->current_basic_block, instruction); |
| ... | ... | @@ -1388,7 +1390,7 @@ static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *so |
| 1388 | 1390 | static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { |
| 1389 | 1391 | IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb, |
| 1390 | 1392 | source_instruction->scope, source_instruction->source_node); |
| 1391 | | instruction->base.value.type = ty; |
| 1393 | instruction->base.value->type = ty; |
| 1392 | 1394 | return &instruction->base; |
| 1393 | 1395 | } |
| 1394 | 1396 | |
| ... | ... | @@ -1513,7 +1515,7 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so |
| 1513 | 1515 | { |
| 1514 | 1516 | IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb, |
| 1515 | 1517 | source_instruction->scope, source_instruction->source_node); |
| 1516 | | call_instruction->base.value.type = return_type; |
| 1518 | call_instruction->base.value->type = return_type; |
| 1517 | 1519 | call_instruction->fn_entry = fn_entry; |
| 1518 | 1520 | call_instruction->fn_ref = fn_ref; |
| 1519 | 1521 | call_instruction->fn_inline = fn_inline; |
| ... | ... | @@ -1558,8 +1560,8 @@ static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source |
| 1558 | 1560 | IrBasicBlock *dest_block, IrInstruction *is_comptime) |
| 1559 | 1561 | { |
| 1560 | 1562 | IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb, scope, source_node); |
| 1561 | | br_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 1562 | | br_instruction->base.value.special = ConstValSpecialStatic; |
| 1563 | br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 1564 | br_instruction->base.value->special = ConstValSpecialStatic; |
| 1563 | 1565 | br_instruction->dest_block = dest_block; |
| 1564 | 1566 | br_instruction->is_comptime = is_comptime; |
| 1565 | 1567 | |
| ... | ... | @@ -1659,8 +1661,8 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop |
| 1659 | 1661 | static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1660 | 1662 | IrInstructionUnreachable *unreachable_instruction = |
| 1661 | 1663 | ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node); |
| 1662 | | unreachable_instruction->base.value.special = ConstValSpecialStatic; |
| 1663 | | unreachable_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 1664 | unreachable_instruction->base.value->special = ConstValSpecialStatic; |
| 1665 | unreachable_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 1664 | 1666 | return &unreachable_instruction->base; |
| 1665 | 1667 | } |
| 1666 | 1668 | |
| ... | ... | @@ -1668,8 +1670,8 @@ static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, A |
| 1668 | 1670 | IrInstruction *ptr, IrInstruction *value) |
| 1669 | 1671 | { |
| 1670 | 1672 | IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node); |
| 1671 | | instruction->base.value.special = ConstValSpecialStatic; |
| 1672 | | instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 1673 | instruction->base.value->special = ConstValSpecialStatic; |
| 1674 | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 1673 | 1675 | instruction->ptr = ptr; |
| 1674 | 1676 | instruction->value = value; |
| 1675 | 1677 | |
| ... | ... | @@ -1684,7 +1686,7 @@ static IrInstruction *ir_build_vector_store_elem(IrAnalyze *ira, IrInstruction * |
| 1684 | 1686 | { |
| 1685 | 1687 | IrInstructionVectorStoreElem *inst = ir_build_instruction<IrInstructionVectorStoreElem>( |
| 1686 | 1688 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1687 | | inst->base.value.type = ira->codegen->builtin_types.entry_void; |
| 1689 | inst->base.value->type = ira->codegen->builtin_types.entry_void; |
| 1688 | 1690 | inst->vector_ptr = vector_ptr; |
| 1689 | 1691 | inst->index = index; |
| 1690 | 1692 | inst->value = value; |
| ... | ... | @@ -1700,8 +1702,8 @@ static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNod |
| 1700 | 1702 | ZigVar *var, IrInstruction *align_value, IrInstruction *ptr) |
| 1701 | 1703 | { |
| 1702 | 1704 | IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node); |
| 1703 | | decl_var_instruction->base.value.special = ConstValSpecialStatic; |
| 1704 | | decl_var_instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 1705 | decl_var_instruction->base.value->special = ConstValSpecialStatic; |
| 1706 | decl_var_instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 1705 | 1707 | decl_var_instruction->var = var; |
| 1706 | 1708 | decl_var_instruction->align_value = align_value; |
| 1707 | 1709 | decl_var_instruction->ptr = ptr; |
| ... | ... | @@ -1717,8 +1719,8 @@ static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *sourc |
| 1717 | 1719 | { |
| 1718 | 1720 | IrInstructionDeclVarGen *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarGen>(&ira->new_irb, |
| 1719 | 1721 | source_instruction->scope, source_instruction->source_node); |
| 1720 | | decl_var_instruction->base.value.special = ConstValSpecialStatic; |
| 1721 | | decl_var_instruction->base.value.type = ira->codegen->builtin_types.entry_void; |
| 1722 | decl_var_instruction->base.value->special = ConstValSpecialStatic; |
| 1723 | decl_var_instruction->base.value->type = ira->codegen->builtin_types.entry_void; |
| 1722 | 1724 | decl_var_instruction->var = var; |
| 1723 | 1725 | decl_var_instruction->var_ptr = var_ptr; |
| 1724 | 1726 | |
| ... | ... | @@ -1732,7 +1734,7 @@ static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *sourc |
| 1732 | 1734 | { |
| 1733 | 1735 | IrInstructionResizeSlice *instruction = ir_build_instruction<IrInstructionResizeSlice>(&ira->new_irb, |
| 1734 | 1736 | source_instruction->scope, source_instruction->source_node); |
| 1735 | | instruction->base.value.type = ty; |
| 1737 | instruction->base.value->type = ty; |
| 1736 | 1738 | instruction->operand = operand; |
| 1737 | 1739 | instruction->result_loc = result_loc; |
| 1738 | 1740 | |
| ... | ... | @@ -1747,8 +1749,8 @@ static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1747 | 1749 | { |
| 1748 | 1750 | IrInstructionExport *export_instruction = ir_build_instruction<IrInstructionExport>( |
| 1749 | 1751 | irb, scope, source_node); |
| 1750 | | export_instruction->base.value.special = ConstValSpecialStatic; |
| 1751 | | export_instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 1752 | export_instruction->base.value->special = ConstValSpecialStatic; |
| 1753 | export_instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 1752 | 1754 | export_instruction->name = name; |
| 1753 | 1755 | export_instruction->target = target; |
| 1754 | 1756 | export_instruction->linkage = linkage; |
| ... | ... | @@ -1925,7 +1927,7 @@ static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *sour |
| 1925 | 1927 | { |
| 1926 | 1928 | IrInstructionOptionalWrap *instruction = ir_build_instruction<IrInstructionOptionalWrap>( |
| 1927 | 1929 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1928 | | instruction->base.value.type = result_ty; |
| 1930 | instruction->base.value->type = result_ty; |
| 1929 | 1931 | instruction->operand = operand; |
| 1930 | 1932 | instruction->result_loc = result_loc; |
| 1931 | 1933 | |
| ... | ... | @@ -1940,7 +1942,7 @@ static IrInstruction *ir_build_err_wrap_payload(IrAnalyze *ira, IrInstruction *s |
| 1940 | 1942 | { |
| 1941 | 1943 | IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>( |
| 1942 | 1944 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1943 | | instruction->base.value.type = result_type; |
| 1945 | instruction->base.value->type = result_type; |
| 1944 | 1946 | instruction->operand = operand; |
| 1945 | 1947 | instruction->result_loc = result_loc; |
| 1946 | 1948 | |
| ... | ... | @@ -1955,7 +1957,7 @@ static IrInstruction *ir_build_err_wrap_code(IrAnalyze *ira, IrInstruction *sour |
| 1955 | 1957 | { |
| 1956 | 1958 | IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>( |
| 1957 | 1959 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1958 | | instruction->base.value.type = result_type; |
| 1960 | instruction->base.value->type = result_type; |
| 1959 | 1961 | instruction->operand = operand; |
| 1960 | 1962 | instruction->result_loc = result_loc; |
| 1961 | 1963 | |
| ... | ... | @@ -2025,8 +2027,8 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A |
| 2025 | 2027 | IrInstruction *switch_prongs_void) |
| 2026 | 2028 | { |
| 2027 | 2029 | IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, scope, source_node); |
| 2028 | | instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 2029 | | instruction->base.value.special = ConstValSpecialStatic; |
| 2030 | instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 2031 | instruction->base.value->special = ConstValSpecialStatic; |
| 2030 | 2032 | instruction->target_value = target_value; |
| 2031 | 2033 | instruction->else_block = else_block; |
| 2032 | 2034 | instruction->case_count = case_count; |
| ... | ... | @@ -2122,7 +2124,7 @@ static IrInstruction *ir_build_ref_gen(IrAnalyze *ira, IrInstruction *source_ins |
| 2122 | 2124 | { |
| 2123 | 2125 | IrInstructionRefGen *instruction = ir_build_instruction<IrInstructionRefGen>(&ira->new_irb, |
| 2124 | 2126 | source_instruction->scope, source_instruction->source_node); |
| 2125 | | instruction->base.value.type = result_type; |
| 2127 | instruction->base.value->type = result_type; |
| 2126 | 2128 | instruction->operand = operand; |
| 2127 | 2129 | instruction->result_loc = result_loc; |
| 2128 | 2130 | |
| ... | ... | @@ -2237,7 +2239,7 @@ static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source |
| 2237 | 2239 | { |
| 2238 | 2240 | IrInstructionCmpxchgGen *instruction = ir_build_instruction<IrInstructionCmpxchgGen>(&ira->new_irb, |
| 2239 | 2241 | source_instruction->scope, source_instruction->source_node); |
| 2240 | | instruction->base.value.type = result_type; |
| 2242 | instruction->base.value->type = result_type; |
| 2241 | 2243 | instruction->ptr = ptr; |
| 2242 | 2244 | instruction->cmp_value = cmp_value; |
| 2243 | 2245 | instruction->new_value = new_value; |
| ... | ... | @@ -2482,7 +2484,7 @@ static IrInstruction *ir_build_splat_gen(IrAnalyze *ira, IrInstruction *source_i |
| 2482 | 2484 | { |
| 2483 | 2485 | IrInstructionSplatGen *instruction = ir_build_instruction<IrInstructionSplatGen>( |
| 2484 | 2486 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2485 | | instruction->base.value.type = result_type; |
| 2487 | instruction->base.value->type = result_type; |
| 2486 | 2488 | instruction->scalar = scalar; |
| 2487 | 2489 | |
| 2488 | 2490 | ir_ref_instruction(scalar, ira->new_irb.current_basic_block); |
| ... | ... | @@ -2495,7 +2497,7 @@ static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_i |
| 2495 | 2497 | { |
| 2496 | 2498 | IrInstructionSliceGen *instruction = ir_build_instruction<IrInstructionSliceGen>( |
| 2497 | 2499 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2498 | | instruction->base.value.type = slice_type; |
| 2500 | instruction->base.value->type = slice_type; |
| 2499 | 2501 | instruction->ptr = ptr; |
| 2500 | 2502 | instruction->start = start; |
| 2501 | 2503 | instruction->end = end; |
| ... | ... | @@ -2709,7 +2711,7 @@ static IrInstruction *ir_build_test_err_gen(IrAnalyze *ira, IrInstruction *sourc |
| 2709 | 2711 | { |
| 2710 | 2712 | IrInstructionTestErrGen *instruction = ir_build_instruction<IrInstructionTestErrGen>( |
| 2711 | 2713 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2712 | | instruction->base.value.type = ira->codegen->builtin_types.entry_bool; |
| 2714 | instruction->base.value->type = ira->codegen->builtin_types.entry_bool; |
| 2713 | 2715 | instruction->err_union = err_union; |
| 2714 | 2716 | |
| 2715 | 2717 | ir_ref_instruction(err_union, ira->new_irb.current_basic_block); |
| ... | ... | @@ -2792,7 +2794,7 @@ static IrInstruction *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInstruction *sourc |
| 2792 | 2794 | { |
| 2793 | 2795 | IrInstructionPtrCastGen *instruction = ir_build_instruction<IrInstructionPtrCastGen>( |
| 2794 | 2796 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2795 | | instruction->base.value.type = ptr_type; |
| 2797 | instruction->base.value->type = ptr_type; |
| 2796 | 2798 | instruction->ptr = ptr; |
| 2797 | 2799 | instruction->safety_check_on = safety_check_on; |
| 2798 | 2800 | |
| ... | ... | @@ -2806,7 +2808,7 @@ static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *sourc |
| 2806 | 2808 | { |
| 2807 | 2809 | IrInstructionLoadPtrGen *instruction = ir_build_instruction<IrInstructionLoadPtrGen>( |
| 2808 | 2810 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2809 | | instruction->base.value.type = ty; |
| 2811 | instruction->base.value->type = ty; |
| 2810 | 2812 | instruction->ptr = ptr; |
| 2811 | 2813 | instruction->result_loc = result_loc; |
| 2812 | 2814 | |
| ... | ... | @@ -2845,7 +2847,7 @@ static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *sourc |
| 2845 | 2847 | { |
| 2846 | 2848 | IrInstructionBitCastGen *instruction = ir_build_instruction<IrInstructionBitCastGen>( |
| 2847 | 2849 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2848 | | instruction->base.value.type = ty; |
| 2850 | instruction->base.value->type = ty; |
| 2849 | 2851 | instruction->operand = operand; |
| 2850 | 2852 | |
| 2851 | 2853 | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| ... | ... | @@ -2997,8 +2999,8 @@ static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *s |
| 2997 | 2999 | |
| 2998 | 3000 | static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) { |
| 2999 | 3001 | IrInstructionPanic *instruction = ir_build_instruction<IrInstructionPanic>(irb, scope, source_node); |
| 3000 | | instruction->base.value.special = ConstValSpecialStatic; |
| 3001 | | instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 3002 | instruction->base.value->special = ConstValSpecialStatic; |
| 3003 | instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 3002 | 3004 | instruction->msg = msg; |
| 3003 | 3005 | |
| 3004 | 3006 | ir_ref_instruction(msg, irb->current_basic_block); |
| ... | ... | @@ -3328,7 +3330,7 @@ static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *so |
| 3328 | 3330 | { |
| 3329 | 3331 | IrInstructionVectorToArray *instruction = ir_build_instruction<IrInstructionVectorToArray>(&ira->new_irb, |
| 3330 | 3332 | source_instruction->scope, source_instruction->source_node); |
| 3331 | | instruction->base.value.type = result_type; |
| 3333 | instruction->base.value->type = result_type; |
| 3332 | 3334 | instruction->vector = vector; |
| 3333 | 3335 | instruction->result_loc = result_loc; |
| 3334 | 3336 | |
| ... | ... | @@ -3343,7 +3345,7 @@ static IrInstruction *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInstructi |
| 3343 | 3345 | { |
| 3344 | 3346 | IrInstructionPtrOfArrayToSlice *instruction = ir_build_instruction<IrInstructionPtrOfArrayToSlice>(&ira->new_irb, |
| 3345 | 3347 | source_instruction->scope, source_instruction->source_node); |
| 3346 | | instruction->base.value.type = result_type; |
| 3348 | instruction->base.value->type = result_type; |
| 3347 | 3349 | instruction->operand = operand; |
| 3348 | 3350 | instruction->result_loc = result_loc; |
| 3349 | 3351 | |
| ... | ... | @@ -3358,7 +3360,7 @@ static IrInstruction *ir_build_array_to_vector(IrAnalyze *ira, IrInstruction *so |
| 3358 | 3360 | { |
| 3359 | 3361 | IrInstructionArrayToVector *instruction = ir_build_instruction<IrInstructionArrayToVector>(&ira->new_irb, |
| 3360 | 3362 | source_instruction->scope, source_instruction->source_node); |
| 3361 | | instruction->base.value.type = result_type; |
| 3363 | instruction->base.value->type = result_type; |
| 3362 | 3364 | instruction->array = array; |
| 3363 | 3365 | |
| 3364 | 3366 | ir_ref_instruction(array, ira->new_irb.current_basic_block); |
| ... | ... | @@ -3371,7 +3373,7 @@ static IrInstruction *ir_build_assert_zero(IrAnalyze *ira, IrInstruction *source |
| 3371 | 3373 | { |
| 3372 | 3374 | IrInstructionAssertZero *instruction = ir_build_instruction<IrInstructionAssertZero>(&ira->new_irb, |
| 3373 | 3375 | source_instruction->scope, source_instruction->source_node); |
| 3374 | | instruction->base.value.type = ira->codegen->builtin_types.entry_void; |
| 3376 | instruction->base.value->type = ira->codegen->builtin_types.entry_void; |
| 3375 | 3377 | instruction->target = target; |
| 3376 | 3378 | |
| 3377 | 3379 | ir_ref_instruction(target, ira->new_irb.current_basic_block); |
| ... | ... | @@ -3384,7 +3386,7 @@ static IrInstruction *ir_build_assert_non_null(IrAnalyze *ira, IrInstruction *so |
| 3384 | 3386 | { |
| 3385 | 3387 | IrInstructionAssertNonNull *instruction = ir_build_instruction<IrInstructionAssertNonNull>(&ira->new_irb, |
| 3386 | 3388 | source_instruction->scope, source_instruction->source_node); |
| 3387 | | instruction->base.value.type = ira->codegen->builtin_types.entry_void; |
| 3389 | instruction->base.value->type = ira->codegen->builtin_types.entry_void; |
| 3388 | 3390 | instruction->target = target; |
| 3389 | 3391 | |
| 3390 | 3392 | ir_ref_instruction(target, ira->new_irb.current_basic_block); |
| ... | ... | @@ -3433,7 +3435,7 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s |
| 3433 | 3435 | |
| 3434 | 3436 | static IrInstructionSuspendBegin *ir_build_suspend_begin(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 3435 | 3437 | IrInstructionSuspendBegin *instruction = ir_build_instruction<IrInstructionSuspendBegin>(irb, scope, source_node); |
| 3436 | | instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 3438 | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 3437 | 3439 | |
| 3438 | 3440 | return instruction; |
| 3439 | 3441 | } |
| ... | ... | @@ -3442,7 +3444,7 @@ static IrInstruction *ir_build_suspend_finish(IrBuilder *irb, Scope *scope, AstN |
| 3442 | 3444 | IrInstructionSuspendBegin *begin) |
| 3443 | 3445 | { |
| 3444 | 3446 | IrInstructionSuspendFinish *instruction = ir_build_instruction<IrInstructionSuspendFinish>(irb, scope, source_node); |
| 3445 | | instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 3447 | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 3446 | 3448 | instruction->begin = begin; |
| 3447 | 3449 | |
| 3448 | 3450 | ir_ref_instruction(&begin->base, irb->current_basic_block); |
| ... | ... | @@ -3467,7 +3469,7 @@ static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction * |
| 3467 | 3469 | { |
| 3468 | 3470 | IrInstructionAwaitGen *instruction = ir_build_instruction<IrInstructionAwaitGen>(&ira->new_irb, |
| 3469 | 3471 | source_instruction->scope, source_instruction->source_node); |
| 3470 | | instruction->base.value.type = result_type; |
| 3472 | instruction->base.value->type = result_type; |
| 3471 | 3473 | instruction->frame = frame; |
| 3472 | 3474 | instruction->result_loc = result_loc; |
| 3473 | 3475 | |
| ... | ... | @@ -3479,7 +3481,7 @@ static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction * |
| 3479 | 3481 | |
| 3480 | 3482 | static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *frame) { |
| 3481 | 3483 | IrInstructionResume *instruction = ir_build_instruction<IrInstructionResume>(irb, scope, source_node); |
| 3482 | | instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 3484 | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 3483 | 3485 | instruction->frame = frame; |
| 3484 | 3486 | |
| 3485 | 3487 | ir_ref_instruction(frame, irb->current_basic_block); |
| ... | ... | @@ -3491,8 +3493,8 @@ static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scop |
| 3491 | 3493 | IrInstruction *operand, SpillId spill_id) |
| 3492 | 3494 | { |
| 3493 | 3495 | IrInstructionSpillBegin *instruction = ir_build_instruction<IrInstructionSpillBegin>(irb, scope, source_node); |
| 3494 | | instruction->base.value.special = ConstValSpecialStatic; |
| 3495 | | instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 3496 | instruction->base.value->special = ConstValSpecialStatic; |
| 3497 | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 3496 | 3498 | instruction->operand = operand; |
| 3497 | 3499 | instruction->spill_id = spill_id; |
| 3498 | 3500 | |
| ... | ... | @@ -3517,7 +3519,7 @@ static IrInstruction *ir_build_vector_extract_elem(IrAnalyze *ira, IrInstruction |
| 3517 | 3519 | { |
| 3518 | 3520 | IrInstructionVectorExtractElem *instruction = ir_build_instruction<IrInstructionVectorExtractElem>( |
| 3519 | 3521 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 3520 | | instruction->base.value.type = vector->value.type->data.vector.elem_type; |
| 3522 | instruction->base.value->type = vector->value->type->data.vector.elem_type; |
| 3521 | 3523 | instruction->vector = vector; |
| 3522 | 3524 | instruction->index = index; |
| 3523 | 3525 | |
| ... | ... | @@ -3588,8 +3590,8 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o |
| 3588 | 3590 | Scope *defer_expr_scope = defer_node->data.defer.expr_scope; |
| 3589 | 3591 | IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope); |
| 3590 | 3592 | if (defer_expr_value != irb->codegen->invalid_instruction) { |
| 3591 | | if (defer_expr_value->value.type != nullptr && |
| 3592 | | defer_expr_value->value.type->id == ZigTypeIdUnreachable) |
| 3593 | if (defer_expr_value->value->type != nullptr && |
| 3594 | defer_expr_value->value->type->id == ZigTypeIdUnreachable) |
| 3593 | 3595 | { |
| 3594 | 3596 | is_noreturn = true; |
| 3595 | 3597 | } else { |
| ... | ... | @@ -4411,7 +4413,7 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode |
| 4411 | 4413 | init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base); |
| 4412 | 4414 | tld_var->base.resolution = TldResolutionInvalid; |
| 4413 | 4415 | tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false, |
| 4414 | | &g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid); |
| 4416 | g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid); |
| 4415 | 4417 | scope_decls->decl_table.put(var_name, &tld_var->base); |
| 4416 | 4418 | } |
| 4417 | 4419 | |
| ... | ... | @@ -4424,10 +4426,10 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4424 | 4426 | if (buf_eql_str(variable_name, "_")) { |
| 4425 | 4427 | if (lval == LValPtr) { |
| 4426 | 4428 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node); |
| 4427 | | const_instruction->base.value.type = get_pointer_to_type(irb->codegen, |
| 4429 | const_instruction->base.value->type = get_pointer_to_type(irb->codegen, |
| 4428 | 4430 | irb->codegen->builtin_types.entry_void, false); |
| 4429 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 4430 | | const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialDiscard; |
| 4431 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 4432 | const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialDiscard; |
| 4431 | 4433 | return &const_instruction->base; |
| 4432 | 4434 | } else { |
| 4433 | 4435 | add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to")); |
| ... | ... | @@ -8747,12 +8749,12 @@ static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { |
| 8747 | 8749 | if (instruction->id == IrInstructionIdReturn) { |
| 8748 | 8750 | IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction; |
| 8749 | 8751 | IrInstruction *operand = ret_inst->operand; |
| 8750 | | if (operand->value.special == ConstValSpecialRuntime) { |
| 8752 | if (operand->value->special == ConstValSpecialRuntime) { |
| 8751 | 8753 | exec_add_error_node(codegen, exec, operand->source_node, |
| 8752 | 8754 | buf_sprintf("unable to evaluate constant expression")); |
| 8753 | | return &codegen->invalid_instruction->value; |
| 8755 | return codegen->invalid_instruction->value; |
| 8754 | 8756 | } |
| 8755 | | return &operand->value; |
| 8757 | return operand->value; |
| 8756 | 8758 | } else if (ir_has_side_effects(instruction)) { |
| 8757 | 8759 | if (instr_is_comptime(instruction)) { |
| 8758 | 8760 | switch (instruction->id) { |
| ... | ... | @@ -8769,7 +8771,7 @@ static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { |
| 8769 | 8771 | } |
| 8770 | 8772 | exec_add_error_node(codegen, exec, instruction->source_node, |
| 8771 | 8773 | buf_sprintf("unable to evaluate constant expression")); |
| 8772 | | return &codegen->invalid_instruction->value; |
| 8774 | return codegen->invalid_instruction->value; |
| 8773 | 8775 | } |
| 8774 | 8776 | } |
| 8775 | 8777 | zig_unreachable(); |
| ... | ... | @@ -10217,13 +10219,13 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10217 | 10219 | size_t i = 0; |
| 10218 | 10220 | for (;;) { |
| 10219 | 10221 | prev_inst = instructions[i]; |
| 10220 | | if (type_is_invalid(prev_inst->value.type)) { |
| 10222 | if (type_is_invalid(prev_inst->value->type)) { |
| 10221 | 10223 | return ira->codegen->builtin_types.entry_invalid; |
| 10222 | 10224 | } |
| 10223 | | if (prev_inst->value.type->id == ZigTypeIdUnreachable) { |
| 10225 | if (prev_inst->value->type->id == ZigTypeIdUnreachable) { |
| 10224 | 10226 | i += 1; |
| 10225 | 10227 | if (i == instruction_count) { |
| 10226 | | return prev_inst->value.type; |
| 10228 | return prev_inst->value->type; |
| 10227 | 10229 | } |
| 10228 | 10230 | continue; |
| 10229 | 10231 | } |
| ... | ... | @@ -10232,14 +10234,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10232 | 10234 | ErrorTableEntry **errors = nullptr; |
| 10233 | 10235 | size_t errors_count = 0; |
| 10234 | 10236 | ZigType *err_set_type = nullptr; |
| 10235 | | if (prev_inst->value.type->id == ZigTypeIdErrorSet) { |
| 10236 | | if (!resolve_inferred_error_set(ira->codegen, prev_inst->value.type, prev_inst->source_node)) { |
| 10237 | if (prev_inst->value->type->id == ZigTypeIdErrorSet) { |
| 10238 | if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->source_node)) { |
| 10237 | 10239 | return ira->codegen->builtin_types.entry_invalid; |
| 10238 | 10240 | } |
| 10239 | | if (type_is_global_error_set(prev_inst->value.type)) { |
| 10241 | if (type_is_global_error_set(prev_inst->value->type)) { |
| 10240 | 10242 | err_set_type = ira->codegen->builtin_types.entry_global_error_set; |
| 10241 | 10243 | } else { |
| 10242 | | err_set_type = prev_inst->value.type; |
| 10244 | err_set_type = prev_inst->value->type; |
| 10243 | 10245 | update_errors_helper(ira->codegen, &errors, &errors_count); |
| 10244 | 10246 | |
| 10245 | 10247 | for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) { |
| ... | ... | @@ -10250,12 +10252,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10250 | 10252 | } |
| 10251 | 10253 | } |
| 10252 | 10254 | |
| 10253 | | bool any_are_null = (prev_inst->value.type->id == ZigTypeIdNull); |
| 10255 | bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull); |
| 10254 | 10256 | bool convert_to_const_slice = false; |
| 10255 | 10257 | for (; i < instruction_count; i += 1) { |
| 10256 | 10258 | IrInstruction *cur_inst = instructions[i]; |
| 10257 | | ZigType *cur_type = cur_inst->value.type; |
| 10258 | | ZigType *prev_type = prev_inst->value.type; |
| 10259 | ZigType *cur_type = cur_inst->value->type; |
| 10260 | ZigType *prev_type = prev_inst->value->type; |
| 10259 | 10261 | |
| 10260 | 10262 | if (type_is_invalid(cur_type)) { |
| 10261 | 10263 | return cur_type; |
| ... | ... | @@ -10559,20 +10561,20 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10559 | 10561 | } |
| 10560 | 10562 | |
| 10561 | 10563 | if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdEnumLiteral) { |
| 10562 | | TypeEnumField *field = find_enum_type_field(prev_type, cur_inst->value.data.x_enum_literal); |
| 10564 | TypeEnumField *field = find_enum_type_field(prev_type, cur_inst->value->data.x_enum_literal); |
| 10563 | 10565 | if (field != nullptr) { |
| 10564 | 10566 | continue; |
| 10565 | 10567 | } |
| 10566 | 10568 | } |
| 10567 | 10569 | if (is_tagged_union(prev_type) && cur_type->id == ZigTypeIdEnumLiteral) { |
| 10568 | | TypeUnionField *field = find_union_type_field(prev_type, cur_inst->value.data.x_enum_literal); |
| 10570 | TypeUnionField *field = find_union_type_field(prev_type, cur_inst->value->data.x_enum_literal); |
| 10569 | 10571 | if (field != nullptr) { |
| 10570 | 10572 | continue; |
| 10571 | 10573 | } |
| 10572 | 10574 | } |
| 10573 | 10575 | |
| 10574 | 10576 | if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdEnumLiteral) { |
| 10575 | | TypeEnumField *field = find_enum_type_field(cur_type, prev_inst->value.data.x_enum_literal); |
| 10577 | TypeEnumField *field = find_enum_type_field(cur_type, prev_inst->value->data.x_enum_literal); |
| 10576 | 10578 | if (field != nullptr) { |
| 10577 | 10579 | prev_inst = cur_inst; |
| 10578 | 10580 | continue; |
| ... | ... | @@ -10580,7 +10582,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10580 | 10582 | } |
| 10581 | 10583 | |
| 10582 | 10584 | if (is_tagged_union(cur_type) && prev_type->id == ZigTypeIdEnumLiteral) { |
| 10583 | | TypeUnionField *field = find_union_type_field(cur_type, prev_inst->value.data.x_enum_literal); |
| 10585 | TypeUnionField *field = find_union_type_field(cur_type, prev_inst->value->data.x_enum_literal); |
| 10584 | 10586 | if (field != nullptr) { |
| 10585 | 10587 | prev_inst = cur_inst; |
| 10586 | 10588 | continue; |
| ... | ... | @@ -10906,9 +10908,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10906 | 10908 | free(errors); |
| 10907 | 10909 | |
| 10908 | 10910 | if (convert_to_const_slice) { |
| 10909 | | if (prev_inst->value.type->id == ZigTypeIdArray) { |
| 10911 | if (prev_inst->value->type->id == ZigTypeIdArray) { |
| 10910 | 10912 | ZigType *ptr_type = get_pointer_to_type_extra( |
| 10911 | | ira->codegen, prev_inst->value.type->data.array.child_type, |
| 10913 | ira->codegen, prev_inst->value->type->data.array.child_type, |
| 10912 | 10914 | true, false, PtrLenUnknown, |
| 10913 | 10915 | 0, 0, 0, false); |
| 10914 | 10916 | ZigType *slice_type = get_slice_type(ira->codegen, ptr_type); |
| ... | ... | @@ -10917,12 +10919,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10917 | 10919 | } else { |
| 10918 | 10920 | return slice_type; |
| 10919 | 10921 | } |
| 10920 | | } else if (prev_inst->value.type->id == ZigTypeIdPointer) { |
| 10921 | | ZigType *array_type = prev_inst->value.type->data.pointer.child_type; |
| 10922 | } else if (prev_inst->value->type->id == ZigTypeIdPointer) { |
| 10923 | ZigType *array_type = prev_inst->value->type->data.pointer.child_type; |
| 10922 | 10924 | src_assert(array_type->id == ZigTypeIdArray, source_node); |
| 10923 | 10925 | ZigType *ptr_type = get_pointer_to_type_extra2( |
| 10924 | 10926 | ira->codegen, array_type->data.array.child_type, |
| 10925 | | prev_inst->value.type->data.pointer.is_const, false, |
| 10927 | prev_inst->value->type->data.pointer.is_const, false, |
| 10926 | 10928 | PtrLenUnknown, |
| 10927 | 10929 | 0, 0, 0, false, |
| 10928 | 10930 | VECTOR_INDEX_NONE, nullptr, array_type->data.array.sentinel); |
| ... | ... | @@ -10936,10 +10938,10 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10936 | 10938 | zig_unreachable(); |
| 10937 | 10939 | } |
| 10938 | 10940 | } else if (err_set_type != nullptr) { |
| 10939 | | if (prev_inst->value.type->id == ZigTypeIdErrorSet) { |
| 10941 | if (prev_inst->value->type->id == ZigTypeIdErrorSet) { |
| 10940 | 10942 | return err_set_type; |
| 10941 | | } else if (prev_inst->value.type->id == ZigTypeIdErrorUnion) { |
| 10942 | | ZigType *payload_type = prev_inst->value.type->data.error_union.payload_type; |
| 10943 | } else if (prev_inst->value->type->id == ZigTypeIdErrorUnion) { |
| 10944 | ZigType *payload_type = prev_inst->value->type->data.error_union.payload_type; |
| 10943 | 10945 | if ((err = type_resolve(ira->codegen, payload_type, ResolveStatusSizeKnown))) |
| 10944 | 10946 | return ira->codegen->builtin_types.entry_invalid; |
| 10945 | 10947 | return get_error_union_type(ira->codegen, err_set_type, payload_type); |
| ... | ... | @@ -10949,38 +10951,38 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10949 | 10951 | return ira->codegen->builtin_types.entry_invalid; |
| 10950 | 10952 | return get_error_union_type(ira->codegen, err_set_type, payload_type); |
| 10951 | 10953 | } else { |
| 10952 | | if (prev_inst->value.type->id == ZigTypeIdComptimeInt || |
| 10953 | | prev_inst->value.type->id == ZigTypeIdComptimeFloat) |
| 10954 | if (prev_inst->value->type->id == ZigTypeIdComptimeInt || |
| 10955 | prev_inst->value->type->id == ZigTypeIdComptimeFloat) |
| 10954 | 10956 | { |
| 10955 | 10957 | ir_add_error_node(ira, source_node, |
| 10956 | 10958 | buf_sprintf("unable to make error union out of number literal")); |
| 10957 | 10959 | return ira->codegen->builtin_types.entry_invalid; |
| 10958 | | } else if (prev_inst->value.type->id == ZigTypeIdNull) { |
| 10960 | } else if (prev_inst->value->type->id == ZigTypeIdNull) { |
| 10959 | 10961 | ir_add_error_node(ira, source_node, |
| 10960 | 10962 | buf_sprintf("unable to make error union out of null literal")); |
| 10961 | 10963 | return ira->codegen->builtin_types.entry_invalid; |
| 10962 | 10964 | } else { |
| 10963 | | if ((err = type_resolve(ira->codegen, prev_inst->value.type, ResolveStatusSizeKnown))) |
| 10965 | if ((err = type_resolve(ira->codegen, prev_inst->value->type, ResolveStatusSizeKnown))) |
| 10964 | 10966 | return ira->codegen->builtin_types.entry_invalid; |
| 10965 | | return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type); |
| 10967 | return get_error_union_type(ira->codegen, err_set_type, prev_inst->value->type); |
| 10966 | 10968 | } |
| 10967 | 10969 | } |
| 10968 | | } else if (any_are_null && prev_inst->value.type->id != ZigTypeIdNull) { |
| 10969 | | if (prev_inst->value.type->id == ZigTypeIdComptimeInt || |
| 10970 | | prev_inst->value.type->id == ZigTypeIdComptimeFloat) |
| 10970 | } else if (any_are_null && prev_inst->value->type->id != ZigTypeIdNull) { |
| 10971 | if (prev_inst->value->type->id == ZigTypeIdComptimeInt || |
| 10972 | prev_inst->value->type->id == ZigTypeIdComptimeFloat) |
| 10971 | 10973 | { |
| 10972 | 10974 | ir_add_error_node(ira, source_node, |
| 10973 | 10975 | buf_sprintf("unable to make maybe out of number literal")); |
| 10974 | 10976 | return ira->codegen->builtin_types.entry_invalid; |
| 10975 | | } else if (prev_inst->value.type->id == ZigTypeIdOptional) { |
| 10976 | | return prev_inst->value.type; |
| 10977 | } else if (prev_inst->value->type->id == ZigTypeIdOptional) { |
| 10978 | return prev_inst->value->type; |
| 10977 | 10979 | } else { |
| 10978 | | if ((err = type_resolve(ira->codegen, prev_inst->value.type, ResolveStatusSizeKnown))) |
| 10980 | if ((err = type_resolve(ira->codegen, prev_inst->value->type, ResolveStatusSizeKnown))) |
| 10979 | 10981 | return ira->codegen->builtin_types.entry_invalid; |
| 10980 | | return get_optional_type(ira->codegen, prev_inst->value.type); |
| 10982 | return get_optional_type(ira->codegen, prev_inst->value->type); |
| 10981 | 10983 | } |
| 10982 | 10984 | } else { |
| 10983 | | return prev_inst->value.type; |
| 10985 | return prev_inst->value->type; |
| 10984 | 10986 | } |
| 10985 | 10987 | } |
| 10986 | 10988 | |
| ... | ... | @@ -11106,8 +11108,8 @@ static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, Z |
| 11106 | 11108 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 11107 | 11109 | old_instruction->scope, old_instruction->source_node); |
| 11108 | 11110 | IrInstruction *new_instruction = &const_instruction->base; |
| 11109 | | new_instruction->value.type = ty; |
| 11110 | | new_instruction->value.special = ConstValSpecialStatic; |
| 11111 | new_instruction->value->type = ty; |
| 11112 | new_instruction->value->special = ConstValSpecialStatic; |
| 11111 | 11113 | return new_instruction; |
| 11112 | 11114 | } |
| 11113 | 11115 | |
| ... | ... | @@ -11116,15 +11118,15 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 11116 | 11118 | { |
| 11117 | 11119 | if (instr_is_comptime(value) || !type_has_bits(wanted_type)) { |
| 11118 | 11120 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 11119 | | if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, &value->value, value->value.type, |
| 11120 | | &result->value, wanted_type)) |
| 11121 | if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type, |
| 11122 | result->value, wanted_type)) |
| 11121 | 11123 | { |
| 11122 | 11124 | return ira->codegen->invalid_instruction; |
| 11123 | 11125 | } |
| 11124 | 11126 | return result; |
| 11125 | 11127 | } else { |
| 11126 | 11128 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op); |
| 11127 | | result->value.type = wanted_type; |
| 11129 | result->value->type = wanted_type; |
| 11128 | 11130 | return result; |
| 11129 | 11131 | } |
| 11130 | 11132 | } |
| ... | ... | @@ -11132,35 +11134,35 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 11132 | 11134 | static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 11133 | 11135 | IrInstruction *value, ZigType *wanted_type) |
| 11134 | 11136 | { |
| 11135 | | assert(value->value.type->id == ZigTypeIdPointer); |
| 11137 | assert(value->value->type->id == ZigTypeIdPointer); |
| 11136 | 11138 | |
| 11137 | 11139 | Error err; |
| 11138 | 11140 | |
| 11139 | | if ((err = type_resolve(ira->codegen, value->value.type->data.pointer.child_type, |
| 11141 | if ((err = type_resolve(ira->codegen, value->value->type->data.pointer.child_type, |
| 11140 | 11142 | ResolveStatusAlignmentKnown))) |
| 11141 | 11143 | { |
| 11142 | 11144 | return ira->codegen->invalid_instruction; |
| 11143 | 11145 | } |
| 11144 | 11146 | |
| 11145 | | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value.type)); |
| 11147 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value->type)); |
| 11146 | 11148 | |
| 11147 | 11149 | if (instr_is_comptime(value)) { |
| 11148 | | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, &value->value, source_instr->source_node); |
| 11150 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, value->value, source_instr->source_node); |
| 11149 | 11151 | if (pointee == nullptr) |
| 11150 | 11152 | return ira->codegen->invalid_instruction; |
| 11151 | 11153 | if (pointee->special != ConstValSpecialRuntime) { |
| 11152 | 11154 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 11153 | | result->value.data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 11154 | | result->value.data.x_ptr.mut = value->value.data.x_ptr.mut; |
| 11155 | | result->value.data.x_ptr.data.base_array.array_val = pointee; |
| 11156 | | result->value.data.x_ptr.data.base_array.elem_index = 0; |
| 11155 | result->value->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 11156 | result->value->data.x_ptr.mut = value->value->data.x_ptr.mut; |
| 11157 | result->value->data.x_ptr.data.base_array.array_val = pointee; |
| 11158 | result->value->data.x_ptr.data.base_array.elem_index = 0; |
| 11157 | 11159 | return result; |
| 11158 | 11160 | } |
| 11159 | 11161 | } |
| 11160 | 11162 | |
| 11161 | 11163 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, |
| 11162 | 11164 | wanted_type, value, CastOpBitCast); |
| 11163 | | result->value.type = wanted_type; |
| 11165 | result->value->type = wanted_type; |
| 11164 | 11166 | return result; |
| 11165 | 11167 | } |
| 11166 | 11168 | |
| ... | ... | @@ -11169,28 +11171,28 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc |
| 11169 | 11171 | { |
| 11170 | 11172 | Error err; |
| 11171 | 11173 | |
| 11172 | | if ((err = type_resolve(ira->codegen, array_ptr->value.type->data.pointer.child_type, |
| 11174 | if ((err = type_resolve(ira->codegen, array_ptr->value->type->data.pointer.child_type, |
| 11173 | 11175 | ResolveStatusAlignmentKnown))) |
| 11174 | 11176 | { |
| 11175 | 11177 | return ira->codegen->invalid_instruction; |
| 11176 | 11178 | } |
| 11177 | 11179 | |
| 11178 | | wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value.type)); |
| 11180 | wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type)); |
| 11179 | 11181 | |
| 11180 | 11182 | if (instr_is_comptime(array_ptr)) { |
| 11181 | | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, &array_ptr->value, source_instr->source_node); |
| 11183 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr->value, source_instr->source_node); |
| 11182 | 11184 | if (pointee == nullptr) |
| 11183 | 11185 | return ira->codegen->invalid_instruction; |
| 11184 | 11186 | if (pointee->special != ConstValSpecialRuntime) { |
| 11185 | | assert(array_ptr->value.type->id == ZigTypeIdPointer); |
| 11186 | | ZigType *array_type = array_ptr->value.type->data.pointer.child_type; |
| 11187 | assert(array_ptr->value->type->id == ZigTypeIdPointer); |
| 11188 | ZigType *array_type = array_ptr->value->type->data.pointer.child_type; |
| 11187 | 11189 | assert(is_slice(wanted_type)); |
| 11188 | 11190 | bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const; |
| 11189 | 11191 | |
| 11190 | 11192 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 11191 | | init_const_slice(ira->codegen, &result->value, pointee, 0, array_type->data.array.len, is_const); |
| 11192 | | result->value.data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value.data.x_ptr.mut; |
| 11193 | | result->value.type = wanted_type; |
| 11193 | init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const); |
| 11194 | result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value->data.x_ptr.mut; |
| 11195 | result->value->type = wanted_type; |
| 11194 | 11196 | return result; |
| 11195 | 11197 | } |
| 11196 | 11198 | } |
| ... | ... | @@ -11198,7 +11200,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc |
| 11198 | 11200 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 11199 | 11201 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, |
| 11200 | 11202 | false, true); |
| 11201 | | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11203 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 11202 | 11204 | return result_loc_inst; |
| 11203 | 11205 | } |
| 11204 | 11206 | return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst); |
| ... | ... | @@ -11403,32 +11405,32 @@ static IrInstruction *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruc |
| 11403 | 11405 | } |
| 11404 | 11406 | |
| 11405 | 11407 | static IrInstruction *ir_finish_anal(IrAnalyze *ira, IrInstruction *instruction) { |
| 11406 | | if (instruction->value.type->id == ZigTypeIdUnreachable) |
| 11408 | if (instruction->value->type->id == ZigTypeIdUnreachable) |
| 11407 | 11409 | ir_finish_bb(ira); |
| 11408 | 11410 | return instruction; |
| 11409 | 11411 | } |
| 11410 | 11412 | |
| 11411 | 11413 | static IrInstruction *ir_const_type(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { |
| 11412 | 11414 | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type); |
| 11413 | | result->value.data.x_type = ty; |
| 11415 | result->value->data.x_type = ty; |
| 11414 | 11416 | return result; |
| 11415 | 11417 | } |
| 11416 | 11418 | |
| 11417 | 11419 | static IrInstruction *ir_const_bool(IrAnalyze *ira, IrInstruction *source_instruction, bool value) { |
| 11418 | 11420 | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool); |
| 11419 | | result->value.data.x_bool = value; |
| 11421 | result->value->data.x_bool = value; |
| 11420 | 11422 | return result; |
| 11421 | 11423 | } |
| 11422 | 11424 | |
| 11423 | 11425 | static IrInstruction *ir_const_undef(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { |
| 11424 | 11426 | IrInstruction *result = ir_const(ira, source_instruction, ty); |
| 11425 | | result->value.special = ConstValSpecialUndef; |
| 11427 | result->value->special = ConstValSpecialUndef; |
| 11426 | 11428 | return result; |
| 11427 | 11429 | } |
| 11428 | 11430 | |
| 11429 | 11431 | static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source_instruction) { |
| 11430 | 11432 | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_unreachable); |
| 11431 | | result->value.special = ConstValSpecialStatic; |
| 11433 | result->value->special = ConstValSpecialStatic; |
| 11432 | 11434 | return result; |
| 11433 | 11435 | } |
| 11434 | 11436 | |
| ... | ... | @@ -11438,7 +11440,7 @@ static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instru |
| 11438 | 11440 | |
| 11439 | 11441 | static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_instruction, uint64_t value) { |
| 11440 | 11442 | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int); |
| 11441 | | bigint_init_unsigned(&result->value.data.x_bigint, value); |
| 11443 | bigint_init_unsigned(&result->value->data.x_bigint, value); |
| 11442 | 11444 | return result; |
| 11443 | 11445 | } |
| 11444 | 11446 | |
| ... | ... | @@ -11449,7 +11451,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio |
| 11449 | 11451 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, |
| 11450 | 11452 | ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false); |
| 11451 | 11453 | IrInstruction *const_instr = ir_const(ira, instruction, ptr_type); |
| 11452 | | ZigValue *const_val = &const_instr->value; |
| 11454 | ZigValue *const_val = const_instr->value; |
| 11453 | 11455 | const_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 11454 | 11456 | const_val->data.x_ptr.mut = ptr_mut; |
| 11455 | 11457 | const_val->data.x_ptr.data.ref.pointee = pointee; |
| ... | ... | @@ -11493,11 +11495,11 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode |
| 11493 | 11495 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) { |
| 11494 | 11496 | Error err; |
| 11495 | 11497 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node, |
| 11496 | | &value->value, undef_allowed))) |
| 11498 | value->value, undef_allowed))) |
| 11497 | 11499 | { |
| 11498 | 11500 | return nullptr; |
| 11499 | 11501 | } |
| 11500 | | return &value->value; |
| 11502 | return value->value; |
| 11501 | 11503 | } |
| 11502 | 11504 | |
| 11503 | 11505 | ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| ... | ... | @@ -11508,7 +11510,7 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 11508 | 11510 | Error err; |
| 11509 | 11511 | |
| 11510 | 11512 | if (expected_type != nullptr && type_is_invalid(expected_type)) |
| 11511 | | return &codegen->invalid_instruction->value; |
| 11513 | return codegen->invalid_instruction->value; |
| 11512 | 11514 | |
| 11513 | 11515 | IrExecutable *ir_executable = allocate<IrExecutable>(1); |
| 11514 | 11516 | ir_executable->source_node = source_node; |
| ... | ... | @@ -11522,7 +11524,7 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 11522 | 11524 | |
| 11523 | 11525 | if (ir_executable->first_err_trace_msg != nullptr) { |
| 11524 | 11526 | codegen->trace_err = ir_executable->first_err_trace_msg; |
| 11525 | | return &codegen->invalid_instruction->value; |
| 11527 | return codegen->invalid_instruction->value; |
| 11526 | 11528 | } |
| 11527 | 11529 | |
| 11528 | 11530 | if (codegen->verbose_ir) { |
| ... | ... | @@ -11545,7 +11547,7 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 11545 | 11547 | analyzed_executable->begin_scope = scope; |
| 11546 | 11548 | ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node); |
| 11547 | 11549 | if (type_is_invalid(result_type)) { |
| 11548 | | return &codegen->invalid_instruction->value; |
| 11550 | return codegen->invalid_instruction->value; |
| 11549 | 11551 | } |
| 11550 | 11552 | |
| 11551 | 11553 | if (codegen->verbose_ir) { |
| ... | ... | @@ -11556,21 +11558,21 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 11556 | 11558 | |
| 11557 | 11559 | ZigValue *result = ir_exec_const_result(codegen, analyzed_executable); |
| 11558 | 11560 | if (type_is_invalid(result->type)) |
| 11559 | | return &codegen->invalid_instruction->value; |
| 11561 | return codegen->invalid_instruction->value; |
| 11560 | 11562 | |
| 11561 | 11563 | if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed))) |
| 11562 | | return &codegen->invalid_instruction->value; |
| 11564 | return codegen->invalid_instruction->value; |
| 11563 | 11565 | |
| 11564 | 11566 | return result; |
| 11565 | 11567 | } |
| 11566 | 11568 | |
| 11567 | 11569 | static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_value) { |
| 11568 | | if (type_is_invalid(err_value->value.type)) |
| 11570 | if (type_is_invalid(err_value->value->type)) |
| 11569 | 11571 | return nullptr; |
| 11570 | 11572 | |
| 11571 | | if (err_value->value.type->id != ZigTypeIdErrorSet) { |
| 11573 | if (err_value->value->type->id != ZigTypeIdErrorSet) { |
| 11572 | 11574 | ir_add_error(ira, err_value, |
| 11573 | | buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value.type->name))); |
| 11575 | buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name))); |
| 11574 | 11576 | return nullptr; |
| 11575 | 11577 | } |
| 11576 | 11578 | |
| ... | ... | @@ -11594,23 +11596,23 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN |
| 11594 | 11596 | } |
| 11595 | 11597 | |
| 11596 | 11598 | static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) { |
| 11597 | | if (type_is_invalid(type_value->value.type)) |
| 11599 | if (type_is_invalid(type_value->value->type)) |
| 11598 | 11600 | return nullptr; |
| 11599 | 11601 | |
| 11600 | | if (type_value->value.type->id != ZigTypeIdMetaType) { |
| 11602 | if (type_value->value->type->id != ZigTypeIdMetaType) { |
| 11601 | 11603 | ir_add_error(ira, type_value, |
| 11602 | | buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name))); |
| 11604 | buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name))); |
| 11603 | 11605 | return nullptr; |
| 11604 | 11606 | } |
| 11605 | 11607 | |
| 11606 | 11608 | Error err; |
| 11607 | 11609 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->source_node, |
| 11608 | | &type_value->value, LazyOk))) |
| 11610 | type_value->value, LazyOk))) |
| 11609 | 11611 | { |
| 11610 | 11612 | return nullptr; |
| 11611 | 11613 | } |
| 11612 | 11614 | |
| 11613 | | return &type_value->value; |
| 11615 | return type_value->value; |
| 11614 | 11616 | } |
| 11615 | 11617 | |
| 11616 | 11618 | static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) { |
| ... | ... | @@ -11663,12 +11665,12 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) { |
| 11663 | 11665 | } |
| 11664 | 11666 | |
| 11665 | 11667 | static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_source, IrInstruction *type_value) { |
| 11666 | | if (type_is_invalid(type_value->value.type)) |
| 11668 | if (type_is_invalid(type_value->value->type)) |
| 11667 | 11669 | return ira->codegen->builtin_types.entry_invalid; |
| 11668 | 11670 | |
| 11669 | | if (type_value->value.type->id != ZigTypeIdMetaType) { |
| 11671 | if (type_value->value->type->id != ZigTypeIdMetaType) { |
| 11670 | 11672 | ErrorMsg *msg = ir_add_error(ira, type_value, |
| 11671 | | buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value.type->name))); |
| 11673 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name))); |
| 11672 | 11674 | add_error_note(ira->codegen, msg, op_source->source_node, |
| 11673 | 11675 | buf_sprintf("`||` merges error sets; `or` performs boolean OR")); |
| 11674 | 11676 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -11694,12 +11696,12 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { |
| 11694 | 11696 | if (fn_value == ira->codegen->invalid_instruction) |
| 11695 | 11697 | return nullptr; |
| 11696 | 11698 | |
| 11697 | | if (type_is_invalid(fn_value->value.type)) |
| 11699 | if (type_is_invalid(fn_value->value->type)) |
| 11698 | 11700 | return nullptr; |
| 11699 | 11701 | |
| 11700 | | if (fn_value->value.type->id != ZigTypeIdFn) { |
| 11702 | if (fn_value->value->type->id != ZigTypeIdFn) { |
| 11701 | 11703 | ir_add_error_node(ira, fn_value->source_node, |
| 11702 | | buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name))); |
| 11704 | buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name))); |
| 11703 | 11705 | return nullptr; |
| 11704 | 11706 | } |
| 11705 | 11707 | |
| ... | ... | @@ -11722,7 +11724,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so |
| 11722 | 11724 | if (instr_is_comptime(value)) { |
| 11723 | 11725 | ZigType *payload_type = wanted_type->data.maybe.child_type; |
| 11724 | 11726 | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 11725 | | if (type_is_invalid(casted_payload->value.type)) |
| 11727 | if (type_is_invalid(casted_payload->value->type)) |
| 11726 | 11728 | return ira->codegen->invalid_instruction; |
| 11727 | 11729 | |
| 11728 | 11730 | ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk); |
| ... | ... | @@ -11731,13 +11733,13 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so |
| 11731 | 11733 | |
| 11732 | 11734 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 11733 | 11735 | source_instr->scope, source_instr->source_node); |
| 11734 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 11736 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 11735 | 11737 | if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) { |
| 11736 | | copy_const_val(&const_instruction->base.value, val, val->data.x_ptr.mut == ConstPtrMutComptimeConst); |
| 11738 | copy_const_val(const_instruction->base.value, val, val->data.x_ptr.mut == ConstPtrMutComptimeConst); |
| 11737 | 11739 | } else { |
| 11738 | | const_instruction->base.value.data.x_optional = val; |
| 11740 | const_instruction->base.value->data.x_optional = val; |
| 11739 | 11741 | } |
| 11740 | | const_instruction->base.value.type = wanted_type; |
| 11742 | const_instruction->base.value->type = wanted_type; |
| 11741 | 11743 | return &const_instruction->base; |
| 11742 | 11744 | } |
| 11743 | 11745 | |
| ... | ... | @@ -11747,12 +11749,12 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so |
| 11747 | 11749 | IrInstruction *result_loc_inst = nullptr; |
| 11748 | 11750 | if (result_loc != nullptr) { |
| 11749 | 11751 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); |
| 11750 | | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11752 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 11751 | 11753 | return result_loc_inst; |
| 11752 | 11754 | } |
| 11753 | 11755 | } |
| 11754 | 11756 | IrInstruction *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst); |
| 11755 | | result->value.data.rh_maybe = RuntimeHintOptionalNonNull; |
| 11757 | result->value->data.rh_maybe = RuntimeHintOptionalNonNull; |
| 11756 | 11758 | return result; |
| 11757 | 11759 | } |
| 11758 | 11760 | |
| ... | ... | @@ -11765,7 +11767,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 11765 | 11767 | ZigType *err_set_type = wanted_type->data.error_union.err_set_type; |
| 11766 | 11768 | if (instr_is_comptime(value)) { |
| 11767 | 11769 | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 11768 | | if (type_is_invalid(casted_payload->value.type)) |
| 11770 | if (type_is_invalid(casted_payload->value->type)) |
| 11769 | 11771 | return ira->codegen->invalid_instruction; |
| 11770 | 11772 | |
| 11771 | 11773 | ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad); |
| ... | ... | @@ -11779,10 +11781,10 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 11779 | 11781 | |
| 11780 | 11782 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 11781 | 11783 | source_instr->scope, source_instr->source_node); |
| 11782 | | const_instruction->base.value.type = wanted_type; |
| 11783 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 11784 | | const_instruction->base.value.data.x_err_union.error_set = err_set_val; |
| 11785 | | const_instruction->base.value.data.x_err_union.payload = val; |
| 11784 | const_instruction->base.value->type = wanted_type; |
| 11785 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 11786 | const_instruction->base.value->data.x_err_union.error_set = err_set_val; |
| 11787 | const_instruction->base.value->data.x_err_union.payload = val; |
| 11786 | 11788 | return &const_instruction->base; |
| 11787 | 11789 | } |
| 11788 | 11790 | |
| ... | ... | @@ -11790,7 +11792,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 11790 | 11792 | if (handle_is_ptr(wanted_type)) { |
| 11791 | 11793 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 11792 | 11794 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); |
| 11793 | | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11795 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 11794 | 11796 | return result_loc_inst; |
| 11795 | 11797 | } |
| 11796 | 11798 | } else { |
| ... | ... | @@ -11798,14 +11800,14 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 11798 | 11800 | } |
| 11799 | 11801 | |
| 11800 | 11802 | IrInstruction *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst); |
| 11801 | | result->value.data.rh_error_union = RuntimeHintErrorUnionNonError; |
| 11803 | result->value->data.rh_error_union = RuntimeHintErrorUnionNonError; |
| 11802 | 11804 | return result; |
| 11803 | 11805 | } |
| 11804 | 11806 | |
| 11805 | 11807 | static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 11806 | 11808 | ZigType *wanted_type) |
| 11807 | 11809 | { |
| 11808 | | assert(value->value.type->id == ZigTypeIdErrorSet); |
| 11810 | assert(value->value->type->id == ZigTypeIdErrorSet); |
| 11809 | 11811 | assert(wanted_type->id == ZigTypeIdErrorSet); |
| 11810 | 11812 | |
| 11811 | 11813 | if (instr_is_comptime(value)) { |
| ... | ... | @@ -11834,14 +11836,14 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou |
| 11834 | 11836 | |
| 11835 | 11837 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 11836 | 11838 | source_instr->scope, source_instr->source_node); |
| 11837 | | const_instruction->base.value.type = wanted_type; |
| 11838 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 11839 | | const_instruction->base.value.data.x_err_set = val->data.x_err_set; |
| 11839 | const_instruction->base.value->type = wanted_type; |
| 11840 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 11841 | const_instruction->base.value->data.x_err_set = val->data.x_err_set; |
| 11840 | 11842 | return &const_instruction->base; |
| 11841 | 11843 | } |
| 11842 | 11844 | |
| 11843 | 11845 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, CastOpErrSet); |
| 11844 | | result->value.type = wanted_type; |
| 11846 | result->value->type = wanted_type; |
| 11845 | 11847 | return result; |
| 11846 | 11848 | } |
| 11847 | 11849 | |
| ... | ... | @@ -11861,7 +11863,7 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc |
| 11861 | 11863 | |
| 11862 | 11864 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, |
| 11863 | 11865 | wanted_type, frame_ptr, CastOpBitCast); |
| 11864 | | result->value.type = wanted_type; |
| 11866 | result->value->type = wanted_type; |
| 11865 | 11867 | return result; |
| 11866 | 11868 | } |
| 11867 | 11869 | |
| ... | ... | @@ -11874,7 +11876,7 @@ static IrInstruction *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInstruct |
| 11874 | 11876 | |
| 11875 | 11877 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, |
| 11876 | 11878 | wanted_type, value, CastOpBitCast); |
| 11877 | | result->value.type = wanted_type; |
| 11879 | result->value->type = wanted_type; |
| 11878 | 11880 | return result; |
| 11879 | 11881 | } |
| 11880 | 11882 | |
| ... | ... | @@ -11898,10 +11900,10 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 11898 | 11900 | |
| 11899 | 11901 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 11900 | 11902 | source_instr->scope, source_instr->source_node); |
| 11901 | | const_instruction->base.value.type = wanted_type; |
| 11902 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 11903 | | const_instruction->base.value.data.x_err_union.error_set = err_set_val; |
| 11904 | | const_instruction->base.value.data.x_err_union.payload = nullptr; |
| 11903 | const_instruction->base.value->type = wanted_type; |
| 11904 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 11905 | const_instruction->base.value->data.x_err_union.error_set = err_set_val; |
| 11906 | const_instruction->base.value->data.x_err_union.payload = nullptr; |
| 11905 | 11907 | return &const_instruction->base; |
| 11906 | 11908 | } |
| 11907 | 11909 | |
| ... | ... | @@ -11909,7 +11911,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 11909 | 11911 | if (handle_is_ptr(wanted_type)) { |
| 11910 | 11912 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 11911 | 11913 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); |
| 11912 | | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11914 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 11913 | 11915 | return result_loc_inst; |
| 11914 | 11916 | } |
| 11915 | 11917 | } else { |
| ... | ... | @@ -11918,7 +11920,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 11918 | 11920 | |
| 11919 | 11921 | |
| 11920 | 11922 | IrInstruction *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst); |
| 11921 | | result->value.data.rh_error_union = RuntimeHintErrorUnionError; |
| 11923 | result->value->data.rh_error_union = RuntimeHintErrorUnionError; |
| 11922 | 11924 | return result; |
| 11923 | 11925 | } |
| 11924 | 11926 | |
| ... | ... | @@ -11930,13 +11932,13 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so |
| 11930 | 11932 | assert(val != nullptr); |
| 11931 | 11933 | |
| 11932 | 11934 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 11933 | | result->value.special = ConstValSpecialStatic; |
| 11935 | result->value->special = ConstValSpecialStatic; |
| 11934 | 11936 | if (get_codegen_ptr_type(wanted_type) != nullptr) { |
| 11935 | | result->value.data.x_ptr.special = ConstPtrSpecialNull; |
| 11937 | result->value->data.x_ptr.special = ConstPtrSpecialNull; |
| 11936 | 11938 | } else if (is_opt_err_set(wanted_type)) { |
| 11937 | | result->value.data.x_err_set = nullptr; |
| 11939 | result->value->data.x_err_set = nullptr; |
| 11938 | 11940 | } else { |
| 11939 | | result->value.data.x_optional = nullptr; |
| 11941 | result->value->data.x_optional = nullptr; |
| 11940 | 11942 | } |
| 11941 | 11943 | return result; |
| 11942 | 11944 | } |
| ... | ... | @@ -11952,8 +11954,8 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction |
| 11952 | 11954 | assert(val != nullptr); |
| 11953 | 11955 | |
| 11954 | 11956 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 11955 | | result->value.data.x_ptr.special = ConstPtrSpecialNull; |
| 11956 | | result->value.data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 11957 | result->value->data.x_ptr.special = ConstPtrSpecialNull; |
| 11958 | result->value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 11957 | 11959 | return result; |
| 11958 | 11960 | } |
| 11959 | 11961 | |
| ... | ... | @@ -11962,36 +11964,36 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi |
| 11962 | 11964 | { |
| 11963 | 11965 | Error err; |
| 11964 | 11966 | |
| 11965 | | if (type_is_invalid(value->value.type)) |
| 11967 | if (type_is_invalid(value->value->type)) |
| 11966 | 11968 | return ira->codegen->invalid_instruction; |
| 11967 | 11969 | |
| 11968 | | if ((err = type_resolve(ira->codegen, value->value.type, ResolveStatusZeroBitsKnown))) |
| 11970 | if ((err = type_resolve(ira->codegen, value->value->type, ResolveStatusZeroBitsKnown))) |
| 11969 | 11971 | return ira->codegen->invalid_instruction; |
| 11970 | 11972 | |
| 11971 | 11973 | if (instr_is_comptime(value)) { |
| 11972 | 11974 | ZigValue *val = ir_resolve_const(ira, value, LazyOk); |
| 11973 | 11975 | if (!val) |
| 11974 | 11976 | return ira->codegen->invalid_instruction; |
| 11975 | | return ir_get_const_ptr(ira, source_instruction, val, value->value.type, |
| 11977 | return ir_get_const_ptr(ira, source_instruction, val, value->value->type, |
| 11976 | 11978 | ConstPtrMutComptimeConst, is_const, is_volatile, 0); |
| 11977 | 11979 | } |
| 11978 | 11980 | |
| 11979 | | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type, |
| 11981 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value->type, |
| 11980 | 11982 | is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); |
| 11981 | 11983 | |
| 11982 | 11984 | if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown))) |
| 11983 | 11985 | return ira->codegen->invalid_instruction; |
| 11984 | 11986 | |
| 11985 | 11987 | IrInstruction *result_loc; |
| 11986 | | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value.type)) { |
| 11987 | | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value.type, nullptr, true, |
| 11988 | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) { |
| 11989 | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, nullptr, true, |
| 11988 | 11990 | false, true); |
| 11989 | 11991 | } else { |
| 11990 | 11992 | result_loc = nullptr; |
| 11991 | 11993 | } |
| 11992 | 11994 | |
| 11993 | 11995 | IrInstruction *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc); |
| 11994 | | new_instruction->value.data.rh_ptr = RuntimeHintPtrStack; |
| 11996 | new_instruction->value->data.rh_ptr = RuntimeHintPtrStack; |
| 11995 | 11997 | return new_instruction; |
| 11996 | 11998 | } |
| 11997 | 11999 | |
| ... | ... | @@ -12004,39 +12006,39 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s |
| 12004 | 12006 | |
| 12005 | 12007 | IrInstruction *array_ptr = nullptr; |
| 12006 | 12008 | IrInstruction *array; |
| 12007 | | if (array_arg->value.type->id == ZigTypeIdPointer) { |
| 12009 | if (array_arg->value->type->id == ZigTypeIdPointer) { |
| 12008 | 12010 | array = ir_get_deref(ira, source_instr, array_arg, nullptr); |
| 12009 | 12011 | array_ptr = array_arg; |
| 12010 | 12012 | } else { |
| 12011 | 12013 | array = array_arg; |
| 12012 | 12014 | } |
| 12013 | | ZigType *array_type = array->value.type; |
| 12015 | ZigType *array_type = array->value->type; |
| 12014 | 12016 | assert(array_type->id == ZigTypeIdArray); |
| 12015 | 12017 | |
| 12016 | 12018 | if (instr_is_comptime(array) || array_type->data.array.len == 0) { |
| 12017 | 12019 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12018 | | init_const_slice(ira->codegen, &result->value, &array->value, 0, array_type->data.array.len, true); |
| 12019 | | result->value.type = wanted_type; |
| 12020 | init_const_slice(ira->codegen, result->value, array->value, 0, array_type->data.array.len, true); |
| 12021 | result->value->type = wanted_type; |
| 12020 | 12022 | return result; |
| 12021 | 12023 | } |
| 12022 | 12024 | |
| 12023 | 12025 | IrInstruction *start = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize); |
| 12024 | | init_const_usize(ira->codegen, &start->value, 0); |
| 12026 | init_const_usize(ira->codegen, start->value, 0); |
| 12025 | 12027 | |
| 12026 | 12028 | IrInstruction *end = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize); |
| 12027 | | init_const_usize(ira->codegen, &end->value, array_type->data.array.len); |
| 12029 | init_const_usize(ira->codegen, end->value, array_type->data.array.len); |
| 12028 | 12030 | |
| 12029 | 12031 | if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false); |
| 12030 | 12032 | |
| 12031 | 12033 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 12032 | 12034 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, |
| 12033 | 12035 | true, false, true); |
| 12034 | | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 12036 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 12035 | 12037 | return result_loc_inst; |
| 12036 | 12038 | } |
| 12037 | 12039 | IrInstruction *result = ir_build_slice_gen(ira, source_instr, wanted_type, array_ptr, start, end, false, result_loc_inst); |
| 12038 | | result->value.data.rh_slice.id = RuntimeHintSliceIdLen; |
| 12039 | | result->value.data.rh_slice.len = array_type->data.array.len; |
| 12040 | result->value->data.rh_slice.id = RuntimeHintSliceIdLen; |
| 12041 | result->value->data.rh_slice.len = array_type->data.array.len; |
| 12040 | 12042 | |
| 12041 | 12043 | return result; |
| 12042 | 12044 | } |
| ... | ... | @@ -12065,19 +12067,19 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour |
| 12065 | 12067 | |
| 12066 | 12068 | IrInstruction *enum_target; |
| 12067 | 12069 | ZigType *enum_type; |
| 12068 | | if (target->value.type->id == ZigTypeIdUnion) { |
| 12069 | | enum_type = ir_resolve_union_tag_type(ira, target, target->value.type); |
| 12070 | if (target->value->type->id == ZigTypeIdUnion) { |
| 12071 | enum_type = ir_resolve_union_tag_type(ira, target, target->value->type); |
| 12070 | 12072 | if (type_is_invalid(enum_type)) |
| 12071 | 12073 | return ira->codegen->invalid_instruction; |
| 12072 | 12074 | enum_target = ir_implicit_cast(ira, target, enum_type); |
| 12073 | | if (type_is_invalid(enum_target->value.type)) |
| 12075 | if (type_is_invalid(enum_target->value->type)) |
| 12074 | 12076 | return ira->codegen->invalid_instruction; |
| 12075 | | } else if (target->value.type->id == ZigTypeIdEnum) { |
| 12077 | } else if (target->value->type->id == ZigTypeIdEnum) { |
| 12076 | 12078 | enum_target = target; |
| 12077 | | enum_type = target->value.type; |
| 12079 | enum_type = target->value->type; |
| 12078 | 12080 | } else { |
| 12079 | 12081 | ir_add_error(ira, target, |
| 12080 | | buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name))); |
| 12082 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name))); |
| 12081 | 12083 | return ira->codegen->invalid_instruction; |
| 12082 | 12084 | } |
| 12083 | 12085 | |
| ... | ... | @@ -12092,7 +12094,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour |
| 12092 | 12094 | enum_type->data.enumeration.src_field_count == 1) |
| 12093 | 12095 | { |
| 12094 | 12096 | IrInstruction *result = ir_const(ira, source_instr, tag_type); |
| 12095 | | init_const_bigint(&result->value, tag_type, |
| 12097 | init_const_bigint(result->value, tag_type, |
| 12096 | 12098 | &enum_type->data.enumeration.fields[0].value); |
| 12097 | 12099 | return result; |
| 12098 | 12100 | } |
| ... | ... | @@ -12102,31 +12104,31 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour |
| 12102 | 12104 | if (!val) |
| 12103 | 12105 | return ira->codegen->invalid_instruction; |
| 12104 | 12106 | IrInstruction *result = ir_const(ira, source_instr, tag_type); |
| 12105 | | init_const_bigint(&result->value, tag_type, &val->data.x_enum_tag); |
| 12107 | init_const_bigint(result->value, tag_type, &val->data.x_enum_tag); |
| 12106 | 12108 | return result; |
| 12107 | 12109 | } |
| 12108 | 12110 | |
| 12109 | 12111 | IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope, |
| 12110 | 12112 | source_instr->source_node, enum_target); |
| 12111 | | result->value.type = tag_type; |
| 12113 | result->value->type = tag_type; |
| 12112 | 12114 | return result; |
| 12113 | 12115 | } |
| 12114 | 12116 | |
| 12115 | 12117 | static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr, |
| 12116 | 12118 | IrInstruction *target, ZigType *wanted_type) |
| 12117 | 12119 | { |
| 12118 | | assert(target->value.type->id == ZigTypeIdUnion); |
| 12120 | assert(target->value->type->id == ZigTypeIdUnion); |
| 12119 | 12121 | assert(wanted_type->id == ZigTypeIdEnum); |
| 12120 | | assert(wanted_type == target->value.type->data.unionation.tag_type); |
| 12122 | assert(wanted_type == target->value->type->data.unionation.tag_type); |
| 12121 | 12123 | |
| 12122 | 12124 | if (instr_is_comptime(target)) { |
| 12123 | 12125 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12124 | 12126 | if (!val) |
| 12125 | 12127 | return ira->codegen->invalid_instruction; |
| 12126 | 12128 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12127 | | result->value.special = ConstValSpecialStatic; |
| 12128 | | result->value.type = wanted_type; |
| 12129 | | bigint_init_bigint(&result->value.data.x_enum_tag, &val->data.x_union.tag); |
| 12129 | result->value->special = ConstValSpecialStatic; |
| 12130 | result->value->type = wanted_type; |
| 12131 | bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag); |
| 12130 | 12132 | return result; |
| 12131 | 12133 | } |
| 12132 | 12134 | |
| ... | ... | @@ -12135,16 +12137,16 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou |
| 12135 | 12137 | wanted_type->data.enumeration.src_field_count == 1) |
| 12136 | 12138 | { |
| 12137 | 12139 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12138 | | result->value.special = ConstValSpecialStatic; |
| 12139 | | result->value.type = wanted_type; |
| 12140 | | TypeEnumField *enum_field = target->value.type->data.unionation.fields[0].enum_field; |
| 12141 | | bigint_init_bigint(&result->value.data.x_enum_tag, &enum_field->value); |
| 12140 | result->value->special = ConstValSpecialStatic; |
| 12141 | result->value->type = wanted_type; |
| 12142 | TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field; |
| 12143 | bigint_init_bigint(&result->value->data.x_enum_tag, &enum_field->value); |
| 12142 | 12144 | return result; |
| 12143 | 12145 | } |
| 12144 | 12146 | |
| 12145 | 12147 | IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope, |
| 12146 | 12148 | source_instr->source_node, target); |
| 12147 | | result->value.type = wanted_type; |
| 12149 | result->value->type = wanted_type; |
| 12148 | 12150 | return result; |
| 12149 | 12151 | } |
| 12150 | 12152 | |
| ... | ... | @@ -12152,7 +12154,7 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc |
| 12152 | 12154 | IrInstruction *target, ZigType *wanted_type) |
| 12153 | 12155 | { |
| 12154 | 12156 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12155 | | result->value.special = ConstValSpecialUndef; |
| 12157 | result->value->special = ConstValSpecialUndef; |
| 12156 | 12158 | return result; |
| 12157 | 12159 | } |
| 12158 | 12160 | |
| ... | ... | @@ -12166,7 +12168,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 12166 | 12168 | return ira->codegen->invalid_instruction; |
| 12167 | 12169 | |
| 12168 | 12170 | IrInstruction *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type); |
| 12169 | | if (type_is_invalid(target->value.type)) |
| 12171 | if (type_is_invalid(target->value->type)) |
| 12170 | 12172 | return ira->codegen->invalid_instruction; |
| 12171 | 12173 | |
| 12172 | 12174 | if (instr_is_comptime(target)) { |
| ... | ... | @@ -12201,12 +12203,12 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 12201 | 12203 | } |
| 12202 | 12204 | |
| 12203 | 12205 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12204 | | result->value.special = ConstValSpecialStatic; |
| 12205 | | result->value.type = wanted_type; |
| 12206 | | bigint_init_bigint(&result->value.data.x_union.tag, &val->data.x_enum_tag); |
| 12207 | | result->value.data.x_union.payload = create_const_vals(1); |
| 12208 | | result->value.data.x_union.payload->special = ConstValSpecialStatic; |
| 12209 | | result->value.data.x_union.payload->type = field_type; |
| 12206 | result->value->special = ConstValSpecialStatic; |
| 12207 | result->value->type = wanted_type; |
| 12208 | bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag); |
| 12209 | result->value->data.x_union.payload = create_const_vals(1); |
| 12210 | result->value->data.x_union.payload->special = ConstValSpecialStatic; |
| 12211 | result->value->data.x_union.payload->type = field_type; |
| 12210 | 12212 | return result; |
| 12211 | 12213 | } |
| 12212 | 12214 | |
| ... | ... | @@ -12214,7 +12216,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 12214 | 12216 | // and in fact it's a noop cast because the union value is just the enum value |
| 12215 | 12217 | if (wanted_type->data.unionation.gen_field_count == 0) { |
| 12216 | 12218 | IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, wanted_type, target, CastOpNoop); |
| 12217 | | result->value.type = wanted_type; |
| 12219 | result->value->type = wanted_type; |
| 12218 | 12220 | return result; |
| 12219 | 12221 | } |
| 12220 | 12222 | |
| ... | ... | @@ -12259,16 +12261,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction |
| 12259 | 12261 | { |
| 12260 | 12262 | ir_add_error(ira, source_instr, |
| 12261 | 12263 | buf_sprintf("cast from '%s' to '%s' truncates bits", |
| 12262 | | buf_ptr(&target->value.type->name), buf_ptr(&wanted_type->name))); |
| 12264 | buf_ptr(&target->value->type->name), buf_ptr(&wanted_type->name))); |
| 12263 | 12265 | return ira->codegen->invalid_instruction; |
| 12264 | 12266 | } |
| 12265 | 12267 | } |
| 12266 | 12268 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12267 | | result->value.type = wanted_type; |
| 12269 | result->value->type = wanted_type; |
| 12268 | 12270 | if (wanted_type->id == ZigTypeIdInt) { |
| 12269 | | bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); |
| 12271 | bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint); |
| 12270 | 12272 | } else { |
| 12271 | | float_init_float(&result->value, val); |
| 12273 | float_init_float(result->value, val); |
| 12272 | 12274 | } |
| 12273 | 12275 | return result; |
| 12274 | 12276 | } |
| ... | ... | @@ -12278,16 +12280,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction |
| 12278 | 12280 | // the target is zero. |
| 12279 | 12281 | if (!type_has_bits(wanted_type)) { |
| 12280 | 12282 | assert(wanted_type->id == ZigTypeIdInt); |
| 12281 | | assert(type_has_bits(target->value.type)); |
| 12283 | assert(type_has_bits(target->value->type)); |
| 12282 | 12284 | ir_build_assert_zero(ira, source_instr, target); |
| 12283 | 12285 | IrInstruction *result = ir_const_unsigned(ira, source_instr, 0); |
| 12284 | | result->value.type = wanted_type; |
| 12286 | result->value->type = wanted_type; |
| 12285 | 12287 | return result; |
| 12286 | 12288 | } |
| 12287 | 12289 | |
| 12288 | 12290 | IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope, |
| 12289 | 12291 | source_instr->source_node, target); |
| 12290 | | result->value.type = wanted_type; |
| 12292 | result->value->type = wanted_type; |
| 12291 | 12293 | return result; |
| 12292 | 12294 | } |
| 12293 | 12295 | |
| ... | ... | @@ -12297,7 +12299,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 12297 | 12299 | Error err; |
| 12298 | 12300 | assert(wanted_type->id == ZigTypeIdEnum); |
| 12299 | 12301 | |
| 12300 | | ZigType *actual_type = target->value.type; |
| 12302 | ZigType *actual_type = target->value->type; |
| 12301 | 12303 | |
| 12302 | 12304 | if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown))) |
| 12303 | 12305 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -12330,13 +12332,13 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 12330 | 12332 | } |
| 12331 | 12333 | |
| 12332 | 12334 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12333 | | bigint_init_bigint(&result->value.data.x_enum_tag, &val->data.x_bigint); |
| 12335 | bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint); |
| 12334 | 12336 | return result; |
| 12335 | 12337 | } |
| 12336 | 12338 | |
| 12337 | 12339 | IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope, |
| 12338 | 12340 | source_instr->source_node, nullptr, target); |
| 12339 | | result->value.type = wanted_type; |
| 12341 | result->value->type = wanted_type; |
| 12340 | 12342 | return result; |
| 12341 | 12343 | } |
| 12342 | 12344 | |
| ... | ... | @@ -12349,9 +12351,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction |
| 12349 | 12351 | |
| 12350 | 12352 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12351 | 12353 | if (wanted_type->id == ZigTypeIdComptimeFloat) { |
| 12352 | | float_init_float(&result->value, val); |
| 12354 | float_init_float(result->value, val); |
| 12353 | 12355 | } else if (wanted_type->id == ZigTypeIdComptimeInt) { |
| 12354 | | bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); |
| 12356 | bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint); |
| 12355 | 12357 | } else { |
| 12356 | 12358 | zig_unreachable(); |
| 12357 | 12359 | } |
| ... | ... | @@ -12361,8 +12363,8 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction |
| 12361 | 12363 | static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 12362 | 12364 | ZigType *wanted_type) |
| 12363 | 12365 | { |
| 12364 | | assert(target->value.type->id == ZigTypeIdInt); |
| 12365 | | assert(!target->value.type->data.integral.is_signed); |
| 12366 | assert(target->value->type->id == ZigTypeIdInt); |
| 12367 | assert(!target->value->type->data.integral.is_signed); |
| 12366 | 12368 | assert(wanted_type->id == ZigTypeIdErrorSet); |
| 12367 | 12369 | |
| 12368 | 12370 | if (instr_is_comptime(target)) { |
| ... | ... | @@ -12389,7 +12391,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 12389 | 12391 | } |
| 12390 | 12392 | |
| 12391 | 12393 | size_t index = bigint_as_usize(&val->data.x_bigint); |
| 12392 | | result->value.data.x_err_set = ira->codegen->errors_by_index.at(index); |
| 12394 | result->value->data.x_err_set = ira->codegen->errors_by_index.at(index); |
| 12393 | 12395 | return result; |
| 12394 | 12396 | } else { |
| 12395 | 12397 | ErrorTableEntry *err = nullptr; |
| ... | ... | @@ -12412,13 +12414,13 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 12412 | 12414 | return ira->codegen->invalid_instruction; |
| 12413 | 12415 | } |
| 12414 | 12416 | |
| 12415 | | result->value.data.x_err_set = err; |
| 12417 | result->value->data.x_err_set = err; |
| 12416 | 12418 | return result; |
| 12417 | 12419 | } |
| 12418 | 12420 | } |
| 12419 | 12421 | |
| 12420 | 12422 | IrInstruction *result = ir_build_int_to_err(&ira->new_irb, source_instr->scope, source_instr->source_node, target); |
| 12421 | | result->value.type = wanted_type; |
| 12423 | result->value->type = wanted_type; |
| 12422 | 12424 | return result; |
| 12423 | 12425 | } |
| 12424 | 12426 | |
| ... | ... | @@ -12427,7 +12429,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12427 | 12429 | { |
| 12428 | 12430 | assert(wanted_type->id == ZigTypeIdInt); |
| 12429 | 12431 | |
| 12430 | | ZigType *err_type = target->value.type; |
| 12432 | ZigType *err_type = target->value->type; |
| 12431 | 12433 | |
| 12432 | 12434 | if (instr_is_comptime(target)) { |
| 12433 | 12435 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| ... | ... | @@ -12444,11 +12446,11 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12444 | 12446 | } else { |
| 12445 | 12447 | zig_unreachable(); |
| 12446 | 12448 | } |
| 12447 | | result->value.type = wanted_type; |
| 12449 | result->value->type = wanted_type; |
| 12448 | 12450 | uint64_t err_value = err ? err->value : 0; |
| 12449 | | bigint_init_unsigned(&result->value.data.x_bigint, err_value); |
| 12451 | bigint_init_unsigned(&result->value->data.x_bigint, err_value); |
| 12450 | 12452 | |
| 12451 | | if (!bigint_fits_in_bits(&result->value.data.x_bigint, |
| 12453 | if (!bigint_fits_in_bits(&result->value->data.x_bigint, |
| 12452 | 12454 | wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) |
| 12453 | 12455 | { |
| 12454 | 12456 | ir_add_error_node(ira, source_instr->source_node, |
| ... | ... | @@ -12474,12 +12476,12 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12474 | 12476 | } |
| 12475 | 12477 | if (err_set_type->data.error_set.err_count == 0) { |
| 12476 | 12478 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12477 | | bigint_init_unsigned(&result->value.data.x_bigint, 0); |
| 12479 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 12478 | 12480 | return result; |
| 12479 | 12481 | } else if (err_set_type->data.error_set.err_count == 1) { |
| 12480 | 12482 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12481 | 12483 | ErrorTableEntry *err = err_set_type->data.error_set.errors[0]; |
| 12482 | | bigint_init_unsigned(&result->value.data.x_bigint, err->value); |
| 12484 | bigint_init_unsigned(&result->value->data.x_bigint, err->value); |
| 12483 | 12485 | return result; |
| 12484 | 12486 | } |
| 12485 | 12487 | } |
| ... | ... | @@ -12493,7 +12495,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12493 | 12495 | } |
| 12494 | 12496 | |
| 12495 | 12497 | IrInstruction *result = ir_build_err_to_int(&ira->new_irb, source_instr->scope, source_instr->source_node, target); |
| 12496 | | result->value.type = wanted_type; |
| 12498 | result->value->type = wanted_type; |
| 12497 | 12499 | return result; |
| 12498 | 12500 | } |
| 12499 | 12501 | |
| ... | ... | @@ -12502,10 +12504,10 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 12502 | 12504 | { |
| 12503 | 12505 | assert(wanted_type->id == ZigTypeIdPointer); |
| 12504 | 12506 | Error err; |
| 12505 | | if ((err = type_resolve(ira->codegen, target->value.type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 12507 | if ((err = type_resolve(ira->codegen, target->value->type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 12506 | 12508 | return ira->codegen->invalid_instruction; |
| 12507 | | assert((wanted_type->data.pointer.is_const && target->value.type->data.pointer.is_const) || !target->value.type->data.pointer.is_const); |
| 12508 | | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value.type)); |
| 12509 | assert((wanted_type->data.pointer.is_const && target->value->type->data.pointer.is_const) || !target->value->type->data.pointer.is_const); |
| 12510 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value->type)); |
| 12509 | 12511 | ZigType *array_type = wanted_type->data.pointer.child_type; |
| 12510 | 12512 | assert(array_type->id == ZigTypeIdArray); |
| 12511 | 12513 | assert(array_type->data.array.len == 1); |
| ... | ... | @@ -12530,11 +12532,11 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 12530 | 12532 | |
| 12531 | 12533 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 12532 | 12534 | source_instr->scope, source_instr->source_node); |
| 12533 | | const_instruction->base.value.type = wanted_type; |
| 12534 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 12535 | | const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialRef; |
| 12536 | | const_instruction->base.value.data.x_ptr.data.ref.pointee = array_val; |
| 12537 | | const_instruction->base.value.data.x_ptr.mut = val->data.x_ptr.mut; |
| 12535 | const_instruction->base.value->type = wanted_type; |
| 12536 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 12537 | const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialRef; |
| 12538 | const_instruction->base.value->data.x_ptr.data.ref.pointee = array_val; |
| 12539 | const_instruction->base.value->data.x_ptr.mut = val->data.x_ptr.mut; |
| 12538 | 12540 | return &const_instruction->base; |
| 12539 | 12541 | } |
| 12540 | 12542 | } |
| ... | ... | @@ -12542,7 +12544,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 12542 | 12544 | // pointer to array and pointer to single item are represented the same way at runtime |
| 12543 | 12545 | IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, |
| 12544 | 12546 | wanted_type, target, CastOpBitCast); |
| 12545 | | result->value.type = wanted_type; |
| 12547 | result->value->type = wanted_type; |
| 12546 | 12548 | return result; |
| 12547 | 12549 | } |
| 12548 | 12550 | |
| ... | ... | @@ -12726,8 +12728,8 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction * |
| 12726 | 12728 | if (instr_is_comptime(array)) { |
| 12727 | 12729 | // arrays and vectors have the same ZigValue representation |
| 12728 | 12730 | IrInstruction *result = ir_const(ira, source_instr, vector_type); |
| 12729 | | copy_const_val(&result->value, &array->value, false); |
| 12730 | | result->value.type = vector_type; |
| 12731 | copy_const_val(result->value, array->value, false); |
| 12732 | result->value->type = vector_type; |
| 12731 | 12733 | return result; |
| 12732 | 12734 | } |
| 12733 | 12735 | return ir_build_array_to_vector(ira, source_instr, array, vector_type); |
| ... | ... | @@ -12739,8 +12741,8 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * |
| 12739 | 12741 | if (instr_is_comptime(vector)) { |
| 12740 | 12742 | // arrays and vectors have the same ZigValue representation |
| 12741 | 12743 | IrInstruction *result = ir_const(ira, source_instr, array_type); |
| 12742 | | copy_const_val(&result->value, &vector->value, false); |
| 12743 | | result->value.type = array_type; |
| 12744 | copy_const_val(result->value, vector->value, false); |
| 12745 | result->value->type = array_type; |
| 12744 | 12746 | return result; |
| 12745 | 12747 | } |
| 12746 | 12748 | if (result_loc == nullptr) { |
| ... | ... | @@ -12748,7 +12750,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * |
| 12748 | 12750 | } |
| 12749 | 12751 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, |
| 12750 | 12752 | true, false, true); |
| 12751 | | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 12753 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 12752 | 12754 | return result_loc_inst; |
| 12753 | 12755 | } |
| 12754 | 12756 | return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst); |
| ... | ... | @@ -12761,23 +12763,23 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou |
| 12761 | 12763 | if (instr_is_comptime(integer)) { |
| 12762 | 12764 | unsigned_integer = integer; |
| 12763 | 12765 | } else { |
| 12764 | | assert(integer->value.type->id == ZigTypeIdInt); |
| 12766 | assert(integer->value->type->id == ZigTypeIdInt); |
| 12765 | 12767 | |
| 12766 | | if (integer->value.type->data.integral.bit_count > |
| 12768 | if (integer->value->type->data.integral.bit_count > |
| 12767 | 12769 | ira->codegen->builtin_types.entry_usize->data.integral.bit_count) |
| 12768 | 12770 | { |
| 12769 | 12771 | ir_add_error(ira, source_instr, |
| 12770 | 12772 | buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'", |
| 12771 | | buf_ptr(&integer->value.type->name), |
| 12773 | buf_ptr(&integer->value->type->name), |
| 12772 | 12774 | buf_ptr(&dest_type->name))); |
| 12773 | 12775 | return ira->codegen->invalid_instruction; |
| 12774 | 12776 | } |
| 12775 | 12777 | |
| 12776 | | if (integer->value.type->data.integral.is_signed) { |
| 12778 | if (integer->value->type->data.integral.is_signed) { |
| 12777 | 12779 | ZigType *unsigned_int_type = get_int_type(ira->codegen, false, |
| 12778 | | integer->value.type->data.integral.bit_count); |
| 12780 | integer->value->type->data.integral.bit_count); |
| 12779 | 12781 | unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type); |
| 12780 | | if (type_is_invalid(unsigned_integer->value.type)) |
| 12782 | if (type_is_invalid(unsigned_integer->value->type)) |
| 12781 | 12783 | return ira->codegen->invalid_instruction; |
| 12782 | 12784 | } else { |
| 12783 | 12785 | unsigned_integer = integer; |
| ... | ... | @@ -12807,16 +12809,16 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou |
| 12807 | 12809 | if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown))) |
| 12808 | 12810 | return ira->codegen->invalid_instruction; |
| 12809 | 12811 | |
| 12810 | | TypeEnumField *field = find_enum_type_field(enum_type, value->value.data.x_enum_literal); |
| 12812 | TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal); |
| 12811 | 12813 | if (field == nullptr) { |
| 12812 | 12814 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("enum '%s' has no field named '%s'", |
| 12813 | | buf_ptr(&enum_type->name), buf_ptr(value->value.data.x_enum_literal))); |
| 12815 | buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal))); |
| 12814 | 12816 | add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node, |
| 12815 | 12817 | buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name))); |
| 12816 | 12818 | return ira->codegen->invalid_instruction; |
| 12817 | 12819 | } |
| 12818 | 12820 | IrInstruction *result = ir_const(ira, source_instr, enum_type); |
| 12819 | | bigint_init_bigint(&result->value.data.x_enum_tag, &field->value); |
| 12821 | bigint_init_bigint(&result->value->data.x_enum_tag, &field->value); |
| 12820 | 12822 | |
| 12821 | 12823 | return result; |
| 12822 | 12824 | } |
| ... | ... | @@ -12885,7 +12887,7 @@ static IrInstruction *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst |
| 12885 | 12887 | { |
| 12886 | 12888 | IrInstruction *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false); |
| 12887 | 12889 | IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr, |
| 12888 | | struct_operand->value.type, false); |
| 12890 | struct_operand->value->type, false); |
| 12889 | 12891 | return ir_get_deref(ira, source_instr, field_ptr, nullptr); |
| 12890 | 12892 | } |
| 12891 | 12893 | |
| ... | ... | @@ -12893,7 +12895,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12893 | 12895 | ZigType *wanted_type, IrInstruction *value) |
| 12894 | 12896 | { |
| 12895 | 12897 | Error err; |
| 12896 | | ZigType *actual_type = value->value.type; |
| 12898 | ZigType *actual_type = value->value->type; |
| 12897 | 12899 | AstNode *source_node = source_instr->source_node; |
| 12898 | 12900 | |
| 12899 | 12901 | if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) { |
| ... | ... | @@ -12915,13 +12917,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12915 | 12917 | } |
| 12916 | 12918 | |
| 12917 | 12919 | if (const_cast_result.id == ConstCastResultIdFnCC) { |
| 12918 | | ir_assert(value->value.type->id == ZigTypeIdFn, source_instr); |
| 12920 | ir_assert(value->value->type->id == ZigTypeIdFn, source_instr); |
| 12919 | 12921 | // ConstCastResultIdFnCC is guaranteed to be the last one reported, meaning everything else is ok. |
| 12920 | 12922 | if (wanted_type->data.fn.fn_type_id.cc == CallingConventionAsync && |
| 12921 | 12923 | actual_type->data.fn.fn_type_id.cc == CallingConventionUnspecified) |
| 12922 | 12924 | { |
| 12923 | | ir_assert(value->value.data.x_ptr.special == ConstPtrSpecialFunction, source_instr); |
| 12924 | | ZigFn *fn = value->value.data.x_ptr.data.fn.fn_entry; |
| 12925 | ir_assert(value->value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr); |
| 12926 | ZigFn *fn = value->value->data.x_ptr.data.fn.fn_entry; |
| 12925 | 12927 | if (fn->inferred_async_node == nullptr) { |
| 12926 | 12928 | fn->inferred_async_node = source_instr->source_node; |
| 12927 | 12929 | } |
| ... | ... | @@ -12963,7 +12965,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12963 | 12965 | { |
| 12964 | 12966 | IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, |
| 12965 | 12967 | wanted_child_type); |
| 12966 | | if (type_is_invalid(cast1->value.type)) |
| 12968 | if (type_is_invalid(cast1->value->type)) |
| 12967 | 12969 | return ira->codegen->invalid_instruction; |
| 12968 | 12970 | return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr); |
| 12969 | 12971 | } |
| ... | ... | @@ -12999,11 +13001,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12999 | 13001 | actual_type->id == ZigTypeIdComptimeFloat) |
| 13000 | 13002 | { |
| 13001 | 13003 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 13002 | | if (type_is_invalid(cast1->value.type)) |
| 13004 | if (type_is_invalid(cast1->value->type)) |
| 13003 | 13005 | return ira->codegen->invalid_instruction; |
| 13004 | 13006 | |
| 13005 | 13007 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13006 | | if (type_is_invalid(cast2->value.type)) |
| 13008 | if (type_is_invalid(cast2->value->type)) |
| 13007 | 13009 | return ira->codegen->invalid_instruction; |
| 13008 | 13010 | |
| 13009 | 13011 | return cast2; |
| ... | ... | @@ -13018,29 +13020,29 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13018 | 13020 | (wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdComptimeInt || |
| 13019 | 13021 | wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat)) |
| 13020 | 13022 | { |
| 13021 | | if (value->value.special == ConstValSpecialUndef) { |
| 13023 | if (value->value->special == ConstValSpecialUndef) { |
| 13022 | 13024 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13023 | | result->value.special = ConstValSpecialUndef; |
| 13025 | result->value->special = ConstValSpecialUndef; |
| 13024 | 13026 | return result; |
| 13025 | 13027 | } |
| 13026 | 13028 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) { |
| 13027 | 13029 | if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) { |
| 13028 | 13030 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13029 | 13031 | if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) { |
| 13030 | | copy_const_val(&result->value, &value->value, false); |
| 13031 | | result->value.type = wanted_type; |
| 13032 | copy_const_val(result->value, value->value, false); |
| 13033 | result->value->type = wanted_type; |
| 13032 | 13034 | } else { |
| 13033 | | float_init_bigint(&result->value.data.x_bigint, &value->value); |
| 13035 | float_init_bigint(&result->value->data.x_bigint, value->value); |
| 13034 | 13036 | } |
| 13035 | 13037 | return result; |
| 13036 | 13038 | } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) { |
| 13037 | 13039 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13038 | 13040 | if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) { |
| 13039 | 13041 | BigFloat bf; |
| 13040 | | bigfloat_init_bigint(&bf, &value->value.data.x_bigint); |
| 13041 | | float_init_bigfloat(&result->value, &bf); |
| 13042 | bigfloat_init_bigint(&bf, &value->value->data.x_bigint); |
| 13043 | float_init_bigfloat(result->value, &bf); |
| 13042 | 13044 | } else { |
| 13043 | | float_init_float(&result->value, &value->value); |
| 13045 | float_init_float(result->value, value->value); |
| 13044 | 13046 | } |
| 13045 | 13047 | return result; |
| 13046 | 13048 | } |
| ... | ... | @@ -13102,11 +13104,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13102 | 13104 | source_node, false).id == ConstCastResultIdOk) |
| 13103 | 13105 | { |
| 13104 | 13106 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); |
| 13105 | | if (type_is_invalid(cast1->value.type)) |
| 13107 | if (type_is_invalid(cast1->value->type)) |
| 13106 | 13108 | return ira->codegen->invalid_instruction; |
| 13107 | 13109 | |
| 13108 | 13110 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13109 | | if (type_is_invalid(cast2->value.type)) |
| 13111 | if (type_is_invalid(cast2->value->type)) |
| 13110 | 13112 | return ira->codegen->invalid_instruction; |
| 13111 | 13113 | |
| 13112 | 13114 | return cast2; |
| ... | ... | @@ -13121,11 +13123,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13121 | 13123 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) |
| 13122 | 13124 | { |
| 13123 | 13125 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); |
| 13124 | | if (type_is_invalid(cast1->value.type)) |
| 13126 | if (type_is_invalid(cast1->value->type)) |
| 13125 | 13127 | return ira->codegen->invalid_instruction; |
| 13126 | 13128 | |
| 13127 | 13129 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13128 | | if (type_is_invalid(cast2->value.type)) |
| 13130 | if (type_is_invalid(cast2->value->type)) |
| 13129 | 13131 | return ira->codegen->invalid_instruction; |
| 13130 | 13132 | |
| 13131 | 13133 | return cast2; |
| ... | ... | @@ -13202,11 +13204,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13202 | 13204 | if (ok_align) { |
| 13203 | 13205 | if (wanted_type->id == ZigTypeIdErrorUnion) { |
| 13204 | 13206 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value); |
| 13205 | | if (type_is_invalid(cast1->value.type)) |
| 13207 | if (type_is_invalid(cast1->value->type)) |
| 13206 | 13208 | return ira->codegen->invalid_instruction; |
| 13207 | 13209 | |
| 13208 | 13210 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13209 | | if (type_is_invalid(cast2->value.type)) |
| 13211 | if (type_is_invalid(cast2->value->type)) |
| 13210 | 13212 | return ira->codegen->invalid_instruction; |
| 13211 | 13213 | |
| 13212 | 13214 | return cast2; |
| ... | ... | @@ -13309,11 +13311,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13309 | 13311 | source_node, false).id == ConstCastResultIdOk) |
| 13310 | 13312 | { |
| 13311 | 13313 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 13312 | | if (type_is_invalid(cast1->value.type)) |
| 13314 | if (type_is_invalid(cast1->value->type)) |
| 13313 | 13315 | return ira->codegen->invalid_instruction; |
| 13314 | 13316 | |
| 13315 | 13317 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13316 | | if (type_is_invalid(cast2->value.type)) |
| 13318 | if (type_is_invalid(cast2->value->type)) |
| 13317 | 13319 | return ira->codegen->invalid_instruction; |
| 13318 | 13320 | |
| 13319 | 13321 | return cast2; |
| ... | ... | @@ -13529,13 +13531,13 @@ static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_sou |
| 13529 | 13531 | assert(value); |
| 13530 | 13532 | assert(value != ira->codegen->invalid_instruction); |
| 13531 | 13533 | assert(!expected_type || !type_is_invalid(expected_type)); |
| 13532 | | assert(value->value.type); |
| 13533 | | assert(!type_is_invalid(value->value.type)); |
| 13534 | assert(value->value->type); |
| 13535 | assert(!type_is_invalid(value->value->type)); |
| 13534 | 13536 | if (expected_type == nullptr) |
| 13535 | 13537 | return value; // anything will do |
| 13536 | | if (expected_type == value->value.type) |
| 13538 | if (expected_type == value->value->type) |
| 13537 | 13539 | return value; // match |
| 13538 | | if (value->value.type->id == ZigTypeIdUnreachable) |
| 13540 | if (value->value->type->id == ZigTypeIdUnreachable) |
| 13539 | 13541 | return value; |
| 13540 | 13542 | |
| 13541 | 13543 | return ir_analyze_cast(ira, value_source_instr, expected_type, value); |
| ... | ... | @@ -13549,7 +13551,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 13549 | 13551 | ResultLoc *result_loc) |
| 13550 | 13552 | { |
| 13551 | 13553 | Error err; |
| 13552 | | ZigType *ptr_type = ptr->value.type; |
| 13554 | ZigType *ptr_type = ptr->value->type; |
| 13553 | 13555 | if (type_is_invalid(ptr_type)) |
| 13554 | 13556 | return ira->codegen->invalid_instruction; |
| 13555 | 13557 | |
| ... | ... | @@ -13571,24 +13573,24 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 13571 | 13573 | break; |
| 13572 | 13574 | } |
| 13573 | 13575 | if (instr_is_comptime(ptr)) { |
| 13574 | | if (ptr->value.special == ConstValSpecialUndef) { |
| 13576 | if (ptr->value->special == ConstValSpecialUndef) { |
| 13575 | 13577 | ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value")); |
| 13576 | 13578 | return ira->codegen->invalid_instruction; |
| 13577 | 13579 | } |
| 13578 | | if (ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 13579 | | ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, &ptr->value); |
| 13580 | if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 13581 | ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr->value); |
| 13580 | 13582 | if (child_type == ira->codegen->builtin_types.entry_var) { |
| 13581 | 13583 | child_type = pointee->type; |
| 13582 | 13584 | } |
| 13583 | 13585 | if (pointee->special != ConstValSpecialRuntime) { |
| 13584 | 13586 | IrInstruction *result = ir_const(ira, source_instruction, child_type); |
| 13585 | 13587 | |
| 13586 | | if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, &result->value, |
| 13587 | | &ptr->value))) |
| 13588 | if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value, |
| 13589 | ptr->value))) |
| 13588 | 13590 | { |
| 13589 | 13591 | return ira->codegen->invalid_instruction; |
| 13590 | 13592 | } |
| 13591 | | result->value.type = child_type; |
| 13593 | result->value->type = child_type; |
| 13592 | 13594 | return result; |
| 13593 | 13595 | } |
| 13594 | 13596 | } |
| ... | ... | @@ -13626,7 +13628,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 13626 | 13628 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 13627 | 13629 | result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, |
| 13628 | 13630 | true, false, true); |
| 13629 | | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 13631 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 13630 | 13632 | return result_loc_inst; |
| 13631 | 13633 | } |
| 13632 | 13634 | } else { |
| ... | ... | @@ -13660,15 +13662,15 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode |
| 13660 | 13662 | } |
| 13661 | 13663 | |
| 13662 | 13664 | static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem_type, uint32_t *out) { |
| 13663 | | if (type_is_invalid(value->value.type)) |
| 13665 | if (type_is_invalid(value->value->type)) |
| 13664 | 13666 | return false; |
| 13665 | 13667 | |
| 13666 | 13668 | // Look for this pattern: `*align(@alignOf(T)) T`. |
| 13667 | 13669 | // This can be resolved to be `*out = 0` without resolving any alignment. |
| 13668 | | if (elem_type != nullptr && value->value.special == ConstValSpecialLazy && |
| 13669 | | value->value.data.x_lazy->id == LazyValueIdAlignOf) |
| 13670 | if (elem_type != nullptr && value->value->special == ConstValSpecialLazy && |
| 13671 | value->value->data.x_lazy->id == LazyValueIdAlignOf) |
| 13670 | 13672 | { |
| 13671 | | LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(value->value.data.x_lazy); |
| 13673 | LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(value->value->data.x_lazy); |
| 13672 | 13674 | |
| 13673 | 13675 | ZigType *lazy_elem_type = ir_resolve_type(lazy_align_of->ira, lazy_align_of->target_type); |
| 13674 | 13676 | if (type_is_invalid(lazy_elem_type)) |
| ... | ... | @@ -13681,19 +13683,19 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem |
| 13681 | 13683 | } |
| 13682 | 13684 | |
| 13683 | 13685 | IrInstruction *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen)); |
| 13684 | | if (type_is_invalid(casted_value->value.type)) |
| 13686 | if (type_is_invalid(casted_value->value->type)) |
| 13685 | 13687 | return false; |
| 13686 | 13688 | |
| 13687 | 13689 | return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->source_node, |
| 13688 | | &casted_value->value, out); |
| 13690 | casted_value->value, out); |
| 13689 | 13691 | } |
| 13690 | 13692 | |
| 13691 | 13693 | static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *int_type, uint64_t *out) { |
| 13692 | | if (type_is_invalid(value->value.type)) |
| 13694 | if (type_is_invalid(value->value->type)) |
| 13693 | 13695 | return false; |
| 13694 | 13696 | |
| 13695 | 13697 | IrInstruction *casted_value = ir_implicit_cast(ira, value, int_type); |
| 13696 | | if (type_is_invalid(casted_value->value.type)) |
| 13698 | if (type_is_invalid(casted_value->value->type)) |
| 13697 | 13699 | return false; |
| 13698 | 13700 | |
| 13699 | 13701 | ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| ... | ... | @@ -13709,11 +13711,11 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out |
| 13709 | 13711 | } |
| 13710 | 13712 | |
| 13711 | 13713 | static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) { |
| 13712 | | if (type_is_invalid(value->value.type)) |
| 13714 | if (type_is_invalid(value->value->type)) |
| 13713 | 13715 | return false; |
| 13714 | 13716 | |
| 13715 | 13717 | IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool); |
| 13716 | | if (type_is_invalid(casted_value->value.type)) |
| 13718 | if (type_is_invalid(casted_value->value->type)) |
| 13717 | 13719 | return false; |
| 13718 | 13720 | |
| 13719 | 13721 | ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| ... | ... | @@ -13733,7 +13735,7 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out) |
| 13733 | 13735 | } |
| 13734 | 13736 | |
| 13735 | 13737 | static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) { |
| 13736 | | if (type_is_invalid(value->value.type)) |
| 13738 | if (type_is_invalid(value->value->type)) |
| 13737 | 13739 | return false; |
| 13738 | 13740 | |
| 13739 | 13741 | ZigValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder"); |
| ... | ... | @@ -13741,7 +13743,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic |
| 13741 | 13743 | ZigType *atomic_order_type = atomic_order_val->data.x_type; |
| 13742 | 13744 | |
| 13743 | 13745 | IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type); |
| 13744 | | if (type_is_invalid(casted_value->value.type)) |
| 13746 | if (type_is_invalid(casted_value->value->type)) |
| 13745 | 13747 | return false; |
| 13746 | 13748 | |
| 13747 | 13749 | ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| ... | ... | @@ -13753,7 +13755,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic |
| 13753 | 13755 | } |
| 13754 | 13756 | |
| 13755 | 13757 | static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, AtomicRmwOp *out) { |
| 13756 | | if (type_is_invalid(value->value.type)) |
| 13758 | if (type_is_invalid(value->value->type)) |
| 13757 | 13759 | return false; |
| 13758 | 13760 | |
| 13759 | 13761 | ZigValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp"); |
| ... | ... | @@ -13761,7 +13763,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi |
| 13761 | 13763 | ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type; |
| 13762 | 13764 | |
| 13763 | 13765 | IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type); |
| 13764 | | if (type_is_invalid(casted_value->value.type)) |
| 13766 | if (type_is_invalid(casted_value->value->type)) |
| 13765 | 13767 | return false; |
| 13766 | 13768 | |
| 13767 | 13769 | ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| ... | ... | @@ -13773,7 +13775,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi |
| 13773 | 13775 | } |
| 13774 | 13776 | |
| 13775 | 13777 | static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, GlobalLinkageId *out) { |
| 13776 | | if (type_is_invalid(value->value.type)) |
| 13778 | if (type_is_invalid(value->value->type)) |
| 13777 | 13779 | return false; |
| 13778 | 13780 | |
| 13779 | 13781 | ZigValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage"); |
| ... | ... | @@ -13781,7 +13783,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob |
| 13781 | 13783 | ZigType *global_linkage_type = global_linkage_val->data.x_type; |
| 13782 | 13784 | |
| 13783 | 13785 | IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type); |
| 13784 | | if (type_is_invalid(casted_value->value.type)) |
| 13786 | if (type_is_invalid(casted_value->value->type)) |
| 13785 | 13787 | return false; |
| 13786 | 13788 | |
| 13787 | 13789 | ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| ... | ... | @@ -13793,7 +13795,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob |
| 13793 | 13795 | } |
| 13794 | 13796 | |
| 13795 | 13797 | static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMode *out) { |
| 13796 | | if (type_is_invalid(value->value.type)) |
| 13798 | if (type_is_invalid(value->value->type)) |
| 13797 | 13799 | return false; |
| 13798 | 13800 | |
| 13799 | 13801 | ZigValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode"); |
| ... | ... | @@ -13801,7 +13803,7 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod |
| 13801 | 13803 | ZigType *float_mode_type = float_mode_val->data.x_type; |
| 13802 | 13804 | |
| 13803 | 13805 | IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type); |
| 13804 | | if (type_is_invalid(casted_value->value.type)) |
| 13806 | if (type_is_invalid(casted_value->value->type)) |
| 13805 | 13807 | return false; |
| 13806 | 13808 | |
| 13807 | 13809 | ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| ... | ... | @@ -13813,14 +13815,14 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod |
| 13813 | 13815 | } |
| 13814 | 13816 | |
| 13815 | 13817 | static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 13816 | | if (type_is_invalid(value->value.type)) |
| 13818 | if (type_is_invalid(value->value->type)) |
| 13817 | 13819 | return nullptr; |
| 13818 | 13820 | |
| 13819 | 13821 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 13820 | 13822 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| 13821 | 13823 | ZigType *str_type = get_slice_type(ira->codegen, ptr_type); |
| 13822 | 13824 | IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); |
| 13823 | | if (type_is_invalid(casted_value->value.type)) |
| 13825 | if (type_is_invalid(casted_value->value->type)) |
| 13824 | 13826 | return nullptr; |
| 13825 | 13827 | |
| 13826 | 13828 | ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| ... | ... | @@ -13858,7 +13860,7 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze |
| 13858 | 13860 | IrInstructionAddImplicitReturnType *instruction) |
| 13859 | 13861 | { |
| 13860 | 13862 | IrInstruction *value = instruction->value->child; |
| 13861 | | if (type_is_invalid(value->value.type)) |
| 13863 | if (type_is_invalid(value->value->type)) |
| 13862 | 13864 | return ir_unreach_error(ira); |
| 13863 | 13865 | |
| 13864 | 13866 | if (instruction->result_loc_ret == nullptr || !instruction->result_loc_ret->implicit_return_type_done) { |
| ... | ... | @@ -13870,11 +13872,11 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze |
| 13870 | 13872 | |
| 13871 | 13873 | static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *instruction) { |
| 13872 | 13874 | IrInstruction *operand = instruction->operand->child; |
| 13873 | | if (type_is_invalid(operand->value.type)) |
| 13875 | if (type_is_invalid(operand->value->type)) |
| 13874 | 13876 | return ir_unreach_error(ira); |
| 13875 | 13877 | |
| 13876 | 13878 | IrInstruction *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type); |
| 13877 | | if (type_is_invalid(casted_operand->value.type)) { |
| 13879 | if (type_is_invalid(casted_operand->value->type)) { |
| 13878 | 13880 | AstNode *source_node = ira->explicit_return_type_source_node; |
| 13879 | 13881 | if (source_node != nullptr) { |
| 13880 | 13882 | ErrorMsg *msg = ira->codegen->errors.last(); |
| ... | ... | @@ -13890,13 +13892,13 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio |
| 13890 | 13892 | // result location mechanism took care of it. |
| 13891 | 13893 | IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope, |
| 13892 | 13894 | instruction->base.source_node, nullptr); |
| 13893 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 13895 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 13894 | 13896 | return ir_finish_anal(ira, result); |
| 13895 | 13897 | } |
| 13896 | 13898 | |
| 13897 | | if (casted_operand->value.special == ConstValSpecialRuntime && |
| 13898 | | casted_operand->value.type->id == ZigTypeIdPointer && |
| 13899 | | casted_operand->value.data.rh_ptr == RuntimeHintPtrStack) |
| 13899 | if (casted_operand->value->special == ConstValSpecialRuntime && |
| 13900 | casted_operand->value->type->id == ZigTypeIdPointer && |
| 13901 | casted_operand->value->data.rh_ptr == RuntimeHintPtrStack) |
| 13900 | 13902 | { |
| 13901 | 13903 | ir_add_error(ira, casted_operand, buf_sprintf("function returns address of local variable")); |
| 13902 | 13904 | return ir_unreach_error(ira); |
| ... | ... | @@ -13904,23 +13906,23 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio |
| 13904 | 13906 | |
| 13905 | 13907 | IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope, |
| 13906 | 13908 | instruction->base.source_node, casted_operand); |
| 13907 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 13909 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 13908 | 13910 | return ir_finish_anal(ira, result); |
| 13909 | 13911 | } |
| 13910 | 13912 | |
| 13911 | 13913 | static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) { |
| 13912 | 13914 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 13913 | | copy_const_val(&result->value, &instruction->base.value, true); |
| 13915 | copy_const_val(result->value, instruction->base.value, true); |
| 13914 | 13916 | return result; |
| 13915 | 13917 | } |
| 13916 | 13918 | |
| 13917 | 13919 | static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 13918 | 13920 | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 13919 | | if (type_is_invalid(op1->value.type)) |
| 13921 | if (type_is_invalid(op1->value->type)) |
| 13920 | 13922 | return ira->codegen->invalid_instruction; |
| 13921 | 13923 | |
| 13922 | 13924 | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 13923 | | if (type_is_invalid(op2->value.type)) |
| 13925 | if (type_is_invalid(op2->value->type)) |
| 13924 | 13926 | return ira->codegen->invalid_instruction; |
| 13925 | 13927 | |
| 13926 | 13928 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| ... | ... | @@ -13942,8 +13944,8 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp |
| 13942 | 13944 | if (op2_val == nullptr) |
| 13943 | 13945 | return ira->codegen->invalid_instruction; |
| 13944 | 13946 | |
| 13945 | | assert(casted_op1->value.type->id == ZigTypeIdBool); |
| 13946 | | assert(casted_op2->value.type->id == ZigTypeIdBool); |
| 13947 | assert(casted_op1->value->type->id == ZigTypeIdBool); |
| 13948 | assert(casted_op2->value->type->id == ZigTypeIdBool); |
| 13947 | 13949 | bool result_bool; |
| 13948 | 13950 | if (bin_op_instruction->op_id == IrBinOpBoolOr) { |
| 13949 | 13951 | result_bool = op1_val->data.x_bool || op2_val->data.x_bool; |
| ... | ... | @@ -13958,7 +13960,7 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp |
| 13958 | 13960 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 13959 | 13961 | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 13960 | 13962 | bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 13961 | | result->value.type = bool_type; |
| 13963 | result->value->type = bool_type; |
| 13962 | 13964 | return result; |
| 13963 | 13965 | } |
| 13964 | 13966 | |
| ... | ... | @@ -14079,7 +14081,7 @@ static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) { |
| 14079 | 14081 | LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy); |
| 14080 | 14082 | IrAnalyze *ira = lazy_size_of->ira; |
| 14081 | 14083 | bool is_zero_bits; |
| 14082 | | if ((err = type_val_resolve_zero_bits(ira->codegen, &lazy_size_of->target_type->value, |
| 14084 | if ((err = type_val_resolve_zero_bits(ira->codegen, lazy_size_of->target_type->value, |
| 14083 | 14085 | nullptr, nullptr, &is_zero_bits))) |
| 14084 | 14086 | { |
| 14085 | 14087 | return err; |
| ... | ... | @@ -14098,27 +14100,27 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14098 | 14100 | Error err; |
| 14099 | 14101 | |
| 14100 | 14102 | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 14101 | | if (type_is_invalid(op1->value.type)) |
| 14103 | if (type_is_invalid(op1->value->type)) |
| 14102 | 14104 | return ira->codegen->invalid_instruction; |
| 14103 | 14105 | |
| 14104 | 14106 | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 14105 | | if (type_is_invalid(op2->value.type)) |
| 14107 | if (type_is_invalid(op2->value->type)) |
| 14106 | 14108 | return ira->codegen->invalid_instruction; |
| 14107 | 14109 | |
| 14108 | 14110 | AstNode *source_node = bin_op_instruction->base.source_node; |
| 14109 | 14111 | |
| 14110 | 14112 | IrBinOp op_id = bin_op_instruction->op_id; |
| 14111 | 14113 | bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq); |
| 14112 | | if (is_equality_cmp && op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull) { |
| 14114 | if (is_equality_cmp && op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdNull) { |
| 14113 | 14115 | return ir_const_bool(ira, &bin_op_instruction->base, (op_id == IrBinOpCmpEq)); |
| 14114 | 14116 | } else if (is_equality_cmp && |
| 14115 | | ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdOptional) || |
| 14116 | | (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdOptional))) |
| 14117 | ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) || |
| 14118 | (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional))) |
| 14117 | 14119 | { |
| 14118 | 14120 | IrInstruction *maybe_op; |
| 14119 | | if (op1->value.type->id == ZigTypeIdNull) { |
| 14121 | if (op1->value->type->id == ZigTypeIdNull) { |
| 14120 | 14122 | maybe_op = op2; |
| 14121 | | } else if (op2->value.type->id == ZigTypeIdNull) { |
| 14123 | } else if (op2->value->type->id == ZigTypeIdNull) { |
| 14122 | 14124 | maybe_op = op1; |
| 14123 | 14125 | } else { |
| 14124 | 14126 | zig_unreachable(); |
| ... | ... | @@ -14134,26 +14136,26 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14134 | 14136 | |
| 14135 | 14137 | IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope, |
| 14136 | 14138 | source_node, maybe_op); |
| 14137 | | is_non_null->value.type = ira->codegen->builtin_types.entry_bool; |
| 14139 | is_non_null->value->type = ira->codegen->builtin_types.entry_bool; |
| 14138 | 14140 | |
| 14139 | 14141 | if (op_id == IrBinOpCmpEq) { |
| 14140 | 14142 | IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope, |
| 14141 | 14143 | bin_op_instruction->base.source_node, is_non_null); |
| 14142 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 14144 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 14143 | 14145 | return result; |
| 14144 | 14146 | } else { |
| 14145 | 14147 | return is_non_null; |
| 14146 | 14148 | } |
| 14147 | 14149 | } else if (is_equality_cmp && |
| 14148 | | ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdPointer && |
| 14149 | | op2->value.type->data.pointer.ptr_len == PtrLenC) || |
| 14150 | | (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdPointer && |
| 14151 | | op1->value.type->data.pointer.ptr_len == PtrLenC))) |
| 14150 | ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdPointer && |
| 14151 | op2->value->type->data.pointer.ptr_len == PtrLenC) || |
| 14152 | (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdPointer && |
| 14153 | op1->value->type->data.pointer.ptr_len == PtrLenC))) |
| 14152 | 14154 | { |
| 14153 | 14155 | IrInstruction *c_ptr_op; |
| 14154 | | if (op1->value.type->id == ZigTypeIdNull) { |
| 14156 | if (op1->value->type->id == ZigTypeIdNull) { |
| 14155 | 14157 | c_ptr_op = op2; |
| 14156 | | } else if (op2->value.type->id == ZigTypeIdNull) { |
| 14158 | } else if (op2->value->type->id == ZigTypeIdNull) { |
| 14157 | 14159 | c_ptr_op = op1; |
| 14158 | 14160 | } else { |
| 14159 | 14161 | zig_unreachable(); |
| ... | ... | @@ -14172,38 +14174,38 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14172 | 14174 | } |
| 14173 | 14175 | IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope, |
| 14174 | 14176 | source_node, c_ptr_op); |
| 14175 | | is_non_null->value.type = ira->codegen->builtin_types.entry_bool; |
| 14177 | is_non_null->value->type = ira->codegen->builtin_types.entry_bool; |
| 14176 | 14178 | |
| 14177 | 14179 | if (op_id == IrBinOpCmpEq) { |
| 14178 | 14180 | IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope, |
| 14179 | 14181 | bin_op_instruction->base.source_node, is_non_null); |
| 14180 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 14182 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 14181 | 14183 | return result; |
| 14182 | 14184 | } else { |
| 14183 | 14185 | return is_non_null; |
| 14184 | 14186 | } |
| 14185 | | } else if (op1->value.type->id == ZigTypeIdNull || op2->value.type->id == ZigTypeIdNull) { |
| 14186 | | ZigType *non_null_type = (op1->value.type->id == ZigTypeIdNull) ? op2->value.type : op1->value.type; |
| 14187 | } else if (op1->value->type->id == ZigTypeIdNull || op2->value->type->id == ZigTypeIdNull) { |
| 14188 | ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type; |
| 14187 | 14189 | ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null", |
| 14188 | 14190 | buf_ptr(&non_null_type->name))); |
| 14189 | 14191 | return ira->codegen->invalid_instruction; |
| 14190 | 14192 | } else if (is_equality_cmp && ( |
| 14191 | | (op1->value.type->id == ZigTypeIdEnumLiteral && op2->value.type->id == ZigTypeIdUnion) || |
| 14192 | | (op2->value.type->id == ZigTypeIdEnumLiteral && op1->value.type->id == ZigTypeIdUnion))) |
| 14193 | (op1->value->type->id == ZigTypeIdEnumLiteral && op2->value->type->id == ZigTypeIdUnion) || |
| 14194 | (op2->value->type->id == ZigTypeIdEnumLiteral && op1->value->type->id == ZigTypeIdUnion))) |
| 14193 | 14195 | { |
| 14194 | 14196 | // Support equality comparison between a union's tag value and a enum literal |
| 14195 | | IrInstruction *union_val = op1->value.type->id == ZigTypeIdUnion ? op1 : op2; |
| 14196 | | IrInstruction *enum_val = op1->value.type->id == ZigTypeIdUnion ? op2 : op1; |
| 14197 | IrInstruction *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2; |
| 14198 | IrInstruction *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1; |
| 14197 | 14199 | |
| 14198 | | ZigType *tag_type = union_val->value.type->data.unionation.tag_type; |
| 14200 | ZigType *tag_type = union_val->value->type->data.unionation.tag_type; |
| 14199 | 14201 | assert(tag_type != nullptr); |
| 14200 | 14202 | |
| 14201 | 14203 | IrInstruction *casted_union = ir_implicit_cast(ira, union_val, tag_type); |
| 14202 | | if (type_is_invalid(casted_union->value.type)) |
| 14204 | if (type_is_invalid(casted_union->value->type)) |
| 14203 | 14205 | return ira->codegen->invalid_instruction; |
| 14204 | 14206 | |
| 14205 | 14207 | IrInstruction *casted_val = ir_implicit_cast(ira, enum_val, tag_type); |
| 14206 | | if (type_is_invalid(casted_val->value.type)) |
| 14208 | if (type_is_invalid(casted_val->value->type)) |
| 14207 | 14209 | return ira->codegen->invalid_instruction; |
| 14208 | 14210 | |
| 14209 | 14211 | if (instr_is_comptime(casted_union)) { |
| ... | ... | @@ -14224,17 +14226,17 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14224 | 14226 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 14225 | 14227 | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 14226 | 14228 | op_id, casted_union, casted_val, bin_op_instruction->safety_check_on); |
| 14227 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 14229 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 14228 | 14230 | |
| 14229 | 14231 | return result; |
| 14230 | 14232 | } |
| 14231 | 14233 | |
| 14232 | | if (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) { |
| 14234 | if (op1->value->type->id == ZigTypeIdErrorSet && op2->value->type->id == ZigTypeIdErrorSet) { |
| 14233 | 14235 | if (!is_equality_cmp) { |
| 14234 | 14236 | ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors")); |
| 14235 | 14237 | return ira->codegen->invalid_instruction; |
| 14236 | 14238 | } |
| 14237 | | ZigType *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node); |
| 14239 | ZigType *intersect_type = get_error_set_intersection(ira, op1->value->type, op2->value->type, source_node); |
| 14238 | 14240 | if (type_is_invalid(intersect_type)) { |
| 14239 | 14241 | return ira->codegen->invalid_instruction; |
| 14240 | 14242 | } |
| ... | ... | @@ -14247,7 +14249,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14247 | 14249 | // (and make it comptime known) |
| 14248 | 14250 | // this is a function which is evaluated at comptime and returns an inferred error set will have an empty |
| 14249 | 14251 | // error set. |
| 14250 | | if (op1->value.type->data.error_set.err_count == 0 || op2->value.type->data.error_set.err_count == 0) { |
| 14252 | if (op1->value->type->data.error_set.err_count == 0 || op2->value->type->data.error_set.err_count == 0) { |
| 14251 | 14253 | bool are_equal = false; |
| 14252 | 14254 | bool answer; |
| 14253 | 14255 | if (op_id == IrBinOpCmpEq) { |
| ... | ... | @@ -14264,10 +14266,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14264 | 14266 | if (intersect_type->data.error_set.err_count == 0) { |
| 14265 | 14267 | ir_add_error_node(ira, source_node, |
| 14266 | 14268 | buf_sprintf("error sets '%s' and '%s' have no common errors", |
| 14267 | | buf_ptr(&op1->value.type->name), buf_ptr(&op2->value.type->name))); |
| 14269 | buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name))); |
| 14268 | 14270 | return ira->codegen->invalid_instruction; |
| 14269 | 14271 | } |
| 14270 | | if (op1->value.type->data.error_set.err_count == 1 && op2->value.type->data.error_set.err_count == 1) { |
| 14272 | if (op1->value->type->data.error_set.err_count == 1 && op2->value->type->data.error_set.err_count == 1) { |
| 14271 | 14273 | bool are_equal = true; |
| 14272 | 14274 | bool answer; |
| 14273 | 14275 | if (op_id == IrBinOpCmpEq) { |
| ... | ... | @@ -14305,7 +14307,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14305 | 14307 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 14306 | 14308 | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 14307 | 14309 | op_id, op1, op2, bin_op_instruction->safety_check_on); |
| 14308 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 14310 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 14309 | 14311 | return result; |
| 14310 | 14312 | } |
| 14311 | 14313 | |
| ... | ... | @@ -14390,12 +14392,12 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14390 | 14392 | // Before resolving the values, we special case comparisons against zero. These can often be done |
| 14391 | 14393 | // without resolving lazy values, preventing potential dependency loops. |
| 14392 | 14394 | Cmp op1_cmp_zero; |
| 14393 | | if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, &casted_op1->value, &op1_cmp_zero))) { |
| 14395 | if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, casted_op1->value, &op1_cmp_zero))) { |
| 14394 | 14396 | if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally; |
| 14395 | 14397 | return ira->codegen->invalid_instruction; |
| 14396 | 14398 | } |
| 14397 | 14399 | Cmp op2_cmp_zero; |
| 14398 | | if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, &casted_op2->value, &op2_cmp_zero))) { |
| 14400 | if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, casted_op2->value, &op2_cmp_zero))) { |
| 14399 | 14401 | if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally; |
| 14400 | 14402 | return ira->codegen->invalid_instruction; |
| 14401 | 14403 | } |
| ... | ... | @@ -14430,26 +14432,26 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14430 | 14432 | } |
| 14431 | 14433 | never_mind_just_calculate_it_normally: |
| 14432 | 14434 | |
| 14433 | | ZigValue *op1_val = one_possible_value ? &casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad); |
| 14435 | ZigValue *op1_val = one_possible_value ? casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad); |
| 14434 | 14436 | if (op1_val == nullptr) |
| 14435 | 14437 | return ira->codegen->invalid_instruction; |
| 14436 | | ZigValue *op2_val = one_possible_value ? &casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad); |
| 14438 | ZigValue *op2_val = one_possible_value ? casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad); |
| 14437 | 14439 | if (op2_val == nullptr) |
| 14438 | 14440 | return ira->codegen->invalid_instruction; |
| 14439 | 14441 | if (resolved_type->id != ZigTypeIdVector) |
| 14440 | 14442 | return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, bin_op_instruction, op_id, one_possible_value); |
| 14441 | 14443 | IrInstruction *result = ir_const(ira, &bin_op_instruction->base, |
| 14442 | 14444 | get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool)); |
| 14443 | | result->value.data.x_array.data.s_none.elements = |
| 14445 | result->value->data.x_array.data.s_none.elements = |
| 14444 | 14446 | create_const_vals(resolved_type->data.vector.len); |
| 14445 | 14447 | |
| 14446 | | expand_undef_array(ira->codegen, &result->value); |
| 14448 | expand_undef_array(ira->codegen, result->value); |
| 14447 | 14449 | for (size_t i = 0;i < resolved_type->data.vector.len;i++) { |
| 14448 | 14450 | IrInstruction *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type, |
| 14449 | 14451 | &op1_val->data.x_array.data.s_none.elements[i], |
| 14450 | 14452 | &op2_val->data.x_array.data.s_none.elements[i], |
| 14451 | 14453 | bin_op_instruction, op_id, one_possible_value); |
| 14452 | | copy_const_val(&result->value.data.x_array.data.s_none.elements[i], &cur_res->value, false); |
| 14454 | copy_const_val(&result->value->data.x_array.data.s_none.elements[i], cur_res->value, false); |
| 14453 | 14455 | } |
| 14454 | 14456 | return result; |
| 14455 | 14457 | } |
| ... | ... | @@ -14495,10 +14497,10 @@ never_mind_just_calculate_it_normally: |
| 14495 | 14497 | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 14496 | 14498 | op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 14497 | 14499 | if (resolved_type->id == ZigTypeIdVector) { |
| 14498 | | result->value.type = get_vector_type(ira->codegen, resolved_type->data.vector.len, |
| 14500 | result->value->type = get_vector_type(ira->codegen, resolved_type->data.vector.len, |
| 14499 | 14501 | ira->codegen->builtin_types.entry_bool); |
| 14500 | 14502 | } else { |
| 14501 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 14503 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 14502 | 14504 | } |
| 14503 | 14505 | return result; |
| 14504 | 14506 | } |
| ... | ... | @@ -14687,7 +14689,7 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i |
| 14687 | 14689 | ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val) |
| 14688 | 14690 | { |
| 14689 | 14691 | IrInstruction *result_instruction = ir_const(ira, source_instr, type_entry); |
| 14690 | | ZigValue *out_val = &result_instruction->value; |
| 14692 | ZigValue *out_val = result_instruction->value; |
| 14691 | 14693 | if (type_entry->id == ZigTypeIdVector) { |
| 14692 | 14694 | expand_undef_array(ira->codegen, op1_val); |
| 14693 | 14695 | expand_undef_array(ira->codegen, op2_val); |
| ... | ... | @@ -14722,52 +14724,52 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i |
| 14722 | 14724 | |
| 14723 | 14725 | static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 14724 | 14726 | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 14725 | | if (type_is_invalid(op1->value.type)) |
| 14727 | if (type_is_invalid(op1->value->type)) |
| 14726 | 14728 | return ira->codegen->invalid_instruction; |
| 14727 | 14729 | |
| 14728 | | if (op1->value.type->id != ZigTypeIdInt && op1->value.type->id != ZigTypeIdComptimeInt) { |
| 14730 | if (op1->value->type->id != ZigTypeIdInt && op1->value->type->id != ZigTypeIdComptimeInt) { |
| 14729 | 14731 | ir_add_error(ira, bin_op_instruction->op1, |
| 14730 | 14732 | buf_sprintf("bit shifting operation expected integer type, found '%s'", |
| 14731 | | buf_ptr(&op1->value.type->name))); |
| 14733 | buf_ptr(&op1->value->type->name))); |
| 14732 | 14734 | return ira->codegen->invalid_instruction; |
| 14733 | 14735 | } |
| 14734 | 14736 | |
| 14735 | 14737 | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 14736 | | if (type_is_invalid(op2->value.type)) |
| 14738 | if (type_is_invalid(op2->value->type)) |
| 14737 | 14739 | return ira->codegen->invalid_instruction; |
| 14738 | 14740 | |
| 14739 | | if (op2->value.type->id != ZigTypeIdInt && op2->value.type->id != ZigTypeIdComptimeInt) { |
| 14741 | if (op2->value->type->id != ZigTypeIdInt && op2->value->type->id != ZigTypeIdComptimeInt) { |
| 14740 | 14742 | ir_add_error(ira, bin_op_instruction->op2, |
| 14741 | 14743 | buf_sprintf("shift amount has to be an integer type, but found '%s'", |
| 14742 | | buf_ptr(&op2->value.type->name))); |
| 14744 | buf_ptr(&op2->value->type->name))); |
| 14743 | 14745 | return ira->codegen->invalid_instruction; |
| 14744 | 14746 | } |
| 14745 | 14747 | |
| 14746 | 14748 | IrInstruction *casted_op2; |
| 14747 | 14749 | IrBinOp op_id = bin_op_instruction->op_id; |
| 14748 | | if (op1->value.type->id == ZigTypeIdComptimeInt) { |
| 14750 | if (op1->value->type->id == ZigTypeIdComptimeInt) { |
| 14749 | 14751 | casted_op2 = op2; |
| 14750 | 14752 | |
| 14751 | 14753 | if (op_id == IrBinOpBitShiftLeftLossy) { |
| 14752 | 14754 | op_id = IrBinOpBitShiftLeftExact; |
| 14753 | 14755 | } |
| 14754 | 14756 | |
| 14755 | | if (casted_op2->value.data.x_bigint.is_negative) { |
| 14757 | if (casted_op2->value->data.x_bigint.is_negative) { |
| 14756 | 14758 | Buf *val_buf = buf_alloc(); |
| 14757 | | bigint_append_buf(val_buf, &casted_op2->value.data.x_bigint, 10); |
| 14759 | bigint_append_buf(val_buf, &casted_op2->value->data.x_bigint, 10); |
| 14758 | 14760 | ir_add_error(ira, casted_op2, buf_sprintf("shift by negative value %s", buf_ptr(val_buf))); |
| 14759 | 14761 | return ira->codegen->invalid_instruction; |
| 14760 | 14762 | } |
| 14761 | 14763 | } else { |
| 14762 | 14764 | ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, |
| 14763 | | op1->value.type->data.integral.bit_count - 1); |
| 14765 | op1->value->type->data.integral.bit_count - 1); |
| 14764 | 14766 | if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy && |
| 14765 | | op2->value.type->id == ZigTypeIdComptimeInt) { |
| 14766 | | if (!bigint_fits_in_bits(&op2->value.data.x_bigint, |
| 14767 | op2->value->type->id == ZigTypeIdComptimeInt) { |
| 14768 | if (!bigint_fits_in_bits(&op2->value->data.x_bigint, |
| 14767 | 14769 | shift_amt_type->data.integral.bit_count, |
| 14768 | | op2->value.data.x_bigint.is_negative)) { |
| 14770 | op2->value->data.x_bigint.is_negative)) { |
| 14769 | 14771 | Buf *val_buf = buf_alloc(); |
| 14770 | | bigint_append_buf(val_buf, &op2->value.data.x_bigint, 10); |
| 14772 | bigint_append_buf(val_buf, &op2->value->data.x_bigint, 10); |
| 14771 | 14773 | ErrorMsg* msg = ir_add_error(ira, |
| 14772 | 14774 | &bin_op_instruction->base, |
| 14773 | 14775 | buf_sprintf("RHS of shift is too large for LHS type")); |
| ... | ... | @@ -14796,22 +14798,22 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b |
| 14796 | 14798 | if (op2_val == nullptr) |
| 14797 | 14799 | return ira->codegen->invalid_instruction; |
| 14798 | 14800 | |
| 14799 | | return ir_analyze_math_op(ira, &bin_op_instruction->base, op1->value.type, op1_val, op_id, op2_val); |
| 14800 | | } else if (op1->value.type->id == ZigTypeIdComptimeInt) { |
| 14801 | return ir_analyze_math_op(ira, &bin_op_instruction->base, op1->value->type, op1_val, op_id, op2_val); |
| 14802 | } else if (op1->value->type->id == ZigTypeIdComptimeInt) { |
| 14801 | 14803 | ir_add_error(ira, &bin_op_instruction->base, |
| 14802 | 14804 | buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known")); |
| 14803 | 14805 | return ira->codegen->invalid_instruction; |
| 14804 | | } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value.data.x_bigint) == CmpEQ) { |
| 14806 | } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value->data.x_bigint) == CmpEQ) { |
| 14805 | 14807 | IrInstruction *result = ir_build_cast(&ira->new_irb, bin_op_instruction->base.scope, |
| 14806 | | bin_op_instruction->base.source_node, op1->value.type, op1, CastOpNoop); |
| 14807 | | result->value.type = op1->value.type; |
| 14808 | bin_op_instruction->base.source_node, op1->value->type, op1, CastOpNoop); |
| 14809 | result->value->type = op1->value->type; |
| 14808 | 14810 | return result; |
| 14809 | 14811 | } |
| 14810 | 14812 | |
| 14811 | 14813 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope, |
| 14812 | 14814 | bin_op_instruction->base.source_node, op_id, |
| 14813 | 14815 | op1, casted_op2, bin_op_instruction->safety_check_on); |
| 14814 | | result->value.type = op1->value.type; |
| 14816 | result->value->type = op1->value->type; |
| 14815 | 14817 | return result; |
| 14816 | 14818 | } |
| 14817 | 14819 | |
| ... | ... | @@ -14880,19 +14882,19 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 14880 | 14882 | Error err; |
| 14881 | 14883 | |
| 14882 | 14884 | IrInstruction *op1 = instruction->op1->child; |
| 14883 | | if (type_is_invalid(op1->value.type)) |
| 14885 | if (type_is_invalid(op1->value->type)) |
| 14884 | 14886 | return ira->codegen->invalid_instruction; |
| 14885 | 14887 | |
| 14886 | 14888 | IrInstruction *op2 = instruction->op2->child; |
| 14887 | | if (type_is_invalid(op2->value.type)) |
| 14889 | if (type_is_invalid(op2->value->type)) |
| 14888 | 14890 | return ira->codegen->invalid_instruction; |
| 14889 | 14891 | |
| 14890 | 14892 | IrBinOp op_id = instruction->op_id; |
| 14891 | 14893 | |
| 14892 | 14894 | // look for pointer math |
| 14893 | | if (is_pointer_arithmetic_allowed(op1->value.type, op_id)) { |
| 14895 | if (is_pointer_arithmetic_allowed(op1->value->type, op_id)) { |
| 14894 | 14896 | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize); |
| 14895 | | if (type_is_invalid(casted_op2->value.type)) |
| 14897 | if (type_is_invalid(casted_op2->value->type)) |
| 14896 | 14898 | return ira->codegen->invalid_instruction; |
| 14897 | 14899 | |
| 14898 | 14900 | // If either operand is undef, result is undef. |
| ... | ... | @@ -14903,19 +14905,19 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 14903 | 14905 | if (op1_val == nullptr) |
| 14904 | 14906 | return ira->codegen->invalid_instruction; |
| 14905 | 14907 | if (op1_val->special == ConstValSpecialUndef) |
| 14906 | | return ir_const_undef(ira, &instruction->base, op1->value.type); |
| 14908 | return ir_const_undef(ira, &instruction->base, op1->value->type); |
| 14907 | 14909 | } |
| 14908 | 14910 | if (instr_is_comptime(casted_op2)) { |
| 14909 | 14911 | op2_val = ir_resolve_const(ira, casted_op2, UndefOk); |
| 14910 | 14912 | if (op2_val == nullptr) |
| 14911 | 14913 | return ira->codegen->invalid_instruction; |
| 14912 | 14914 | if (op2_val->special == ConstValSpecialUndef) |
| 14913 | | return ir_const_undef(ira, &instruction->base, op1->value.type); |
| 14915 | return ir_const_undef(ira, &instruction->base, op1->value->type); |
| 14914 | 14916 | } |
| 14915 | 14917 | |
| 14916 | 14918 | if (op2_val != nullptr && op1_val != nullptr && |
| 14917 | | (op1->value.data.x_ptr.special == ConstPtrSpecialHardCodedAddr || |
| 14918 | | op1->value.data.x_ptr.special == ConstPtrSpecialNull)) |
| 14919 | (op1->value->data.x_ptr.special == ConstPtrSpecialHardCodedAddr || |
| 14920 | op1->value->data.x_ptr.special == ConstPtrSpecialNull)) |
| 14919 | 14921 | { |
| 14920 | 14922 | uint64_t start_addr = (op1_val->data.x_ptr.special == ConstPtrSpecialNull) ? |
| 14921 | 14923 | 0 : op1_val->data.x_ptr.data.hard_coded_addr.addr; |
| ... | ... | @@ -14935,15 +14937,15 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 14935 | 14937 | zig_unreachable(); |
| 14936 | 14938 | } |
| 14937 | 14939 | IrInstruction *result = ir_const(ira, &instruction->base, op1_val->type); |
| 14938 | | result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 14939 | | result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 14940 | | result->value.data.x_ptr.data.hard_coded_addr.addr = new_addr; |
| 14940 | result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 14941 | result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 14942 | result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr; |
| 14941 | 14943 | return result; |
| 14942 | 14944 | } |
| 14943 | 14945 | |
| 14944 | 14946 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope, |
| 14945 | 14947 | instruction->base.source_node, op_id, op1, casted_op2, true); |
| 14946 | | result->value.type = op1->value.type; |
| 14948 | result->value->type = op1->value->type; |
| 14947 | 14949 | return result; |
| 14948 | 14950 | } |
| 14949 | 14951 | |
| ... | ... | @@ -14958,11 +14960,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 14958 | 14960 | (resolved_type->id == ZigTypeIdInt && resolved_type->data.integral.is_signed) || |
| 14959 | 14961 | resolved_type->id == ZigTypeIdFloat || |
| 14960 | 14962 | (resolved_type->id == ZigTypeIdComptimeFloat && |
| 14961 | | ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) != |
| 14962 | | (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) || |
| 14963 | ((bigfloat_cmp_zero(&op1->value->data.x_bigfloat) != CmpGT) != |
| 14964 | (bigfloat_cmp_zero(&op2->value->data.x_bigfloat) != CmpGT))) || |
| 14963 | 14965 | (resolved_type->id == ZigTypeIdComptimeInt && |
| 14964 | | ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) != |
| 14965 | | (bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT))) |
| 14966 | ((bigint_cmp_zero(&op1->value->data.x_bigint) != CmpGT) != |
| 14967 | (bigint_cmp_zero(&op2->value->data.x_bigint) != CmpGT))) |
| 14966 | 14968 | ); |
| 14967 | 14969 | if (op_id == IrBinOpDivUnspecified && is_int) { |
| 14968 | 14970 | if (is_signed_div) { |
| ... | ... | @@ -14995,8 +14997,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 14995 | 14997 | if (!ok) { |
| 14996 | 14998 | ir_add_error(ira, &instruction->base, |
| 14997 | 14999 | buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact", |
| 14998 | | buf_ptr(&op1->value.type->name), |
| 14999 | | buf_ptr(&op2->value.type->name))); |
| 15000 | buf_ptr(&op1->value->type->name), |
| 15001 | buf_ptr(&op2->value->type->name))); |
| 15000 | 15002 | return ira->codegen->invalid_instruction; |
| 15001 | 15003 | } |
| 15002 | 15004 | } else { |
| ... | ... | @@ -15015,7 +15017,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15015 | 15017 | if (op2_val == nullptr) |
| 15016 | 15018 | return ira->codegen->invalid_instruction; |
| 15017 | 15019 | |
| 15018 | | if (bigint_cmp_zero(&op2->value.data.x_bigint) == CmpEQ) { |
| 15020 | if (bigint_cmp_zero(&op2->value->data.x_bigint) == CmpEQ) { |
| 15019 | 15021 | // the division by zero error will be caught later, but we don't |
| 15020 | 15022 | // have a remainder function ambiguity problem |
| 15021 | 15023 | ok = true; |
| ... | ... | @@ -15035,7 +15037,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15035 | 15037 | if (op2_val == nullptr) |
| 15036 | 15038 | return ira->codegen->invalid_instruction; |
| 15037 | 15039 | |
| 15038 | | if (float_cmp_zero(&casted_op2->value) == CmpEQ) { |
| 15040 | if (float_cmp_zero(casted_op2->value) == CmpEQ) { |
| 15039 | 15041 | // the division by zero error will be caught later, but we don't |
| 15040 | 15042 | // have a remainder function ambiguity problem |
| 15041 | 15043 | ok = true; |
| ... | ... | @@ -15051,8 +15053,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15051 | 15053 | if (!ok) { |
| 15052 | 15054 | ir_add_error(ira, &instruction->base, |
| 15053 | 15055 | buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod", |
| 15054 | | buf_ptr(&op1->value.type->name), |
| 15055 | | buf_ptr(&op2->value.type->name))); |
| 15056 | buf_ptr(&op1->value->type->name), |
| 15057 | buf_ptr(&op2->value->type->name))); |
| 15056 | 15058 | return ira->codegen->invalid_instruction; |
| 15057 | 15059 | } |
| 15058 | 15060 | } |
| ... | ... | @@ -15076,8 +15078,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15076 | 15078 | AstNode *source_node = instruction->base.source_node; |
| 15077 | 15079 | ir_add_error_node(ira, source_node, |
| 15078 | 15080 | buf_sprintf("invalid operands to binary expression: '%s' and '%s'", |
| 15079 | | buf_ptr(&op1->value.type->name), |
| 15080 | | buf_ptr(&op2->value.type->name))); |
| 15081 | buf_ptr(&op1->value->type->name), |
| 15082 | buf_ptr(&op2->value->type->name))); |
| 15081 | 15083 | return ira->codegen->invalid_instruction; |
| 15082 | 15084 | } |
| 15083 | 15085 | |
| ... | ... | @@ -15112,18 +15114,18 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15112 | 15114 | |
| 15113 | 15115 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope, |
| 15114 | 15116 | instruction->base.source_node, op_id, casted_op1, casted_op2, instruction->safety_check_on); |
| 15115 | | result->value.type = resolved_type; |
| 15117 | result->value->type = resolved_type; |
| 15116 | 15118 | return result; |
| 15117 | 15119 | } |
| 15118 | 15120 | |
| 15119 | 15121 | static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 15120 | 15122 | IrInstruction *op1 = instruction->op1->child; |
| 15121 | | ZigType *op1_type = op1->value.type; |
| 15123 | ZigType *op1_type = op1->value->type; |
| 15122 | 15124 | if (type_is_invalid(op1_type)) |
| 15123 | 15125 | return ira->codegen->invalid_instruction; |
| 15124 | 15126 | |
| 15125 | 15127 | IrInstruction *op2 = instruction->op2->child; |
| 15126 | | ZigType *op2_type = op2->value.type; |
| 15128 | ZigType *op2_type = op2->value->type; |
| 15127 | 15129 | if (type_is_invalid(op2_type)) |
| 15128 | 15130 | return ira->codegen->invalid_instruction; |
| 15129 | 15131 | |
| ... | ... | @@ -15178,8 +15180,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15178 | 15180 | op1_array_end = array_type->data.array.len; |
| 15179 | 15181 | sentinel1 = array_type->data.array.sentinel; |
| 15180 | 15182 | } else { |
| 15181 | | ir_add_error(ira, op1, |
| 15182 | | buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value.type->name))); |
| 15183 | ir_add_error(ira, op1, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name))); |
| 15183 | 15184 | return ira->codegen->invalid_instruction; |
| 15184 | 15185 | } |
| 15185 | 15186 | |
| ... | ... | @@ -15229,13 +15230,13 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15229 | 15230 | sentinel2 = array_type->data.array.sentinel; |
| 15230 | 15231 | } else { |
| 15231 | 15232 | ir_add_error(ira, op2, |
| 15232 | | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value.type->name))); |
| 15233 | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name))); |
| 15233 | 15234 | return ira->codegen->invalid_instruction; |
| 15234 | 15235 | } |
| 15235 | 15236 | if (!op2_type_valid) { |
| 15236 | 15237 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 15237 | 15238 | buf_ptr(&child_type->name), |
| 15238 | | buf_ptr(&op2->value.type->name))); |
| 15239 | buf_ptr(&op2->value->type->name))); |
| 15239 | 15240 | return ira->codegen->invalid_instruction; |
| 15240 | 15241 | } |
| 15241 | 15242 | |
| ... | ... | @@ -15254,13 +15255,12 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15254 | 15255 | |
| 15255 | 15256 | // The type of result is populated in the following if blocks |
| 15256 | 15257 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 15257 | | ZigValue *out_val = &result->value; |
| 15258 | ZigValue *out_val = result->value; |
| 15258 | 15259 | |
| 15259 | 15260 | ZigValue *out_array_val; |
| 15260 | 15261 | size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index); |
| 15261 | 15262 | if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) { |
| 15262 | | result->value.type = get_array_type(ira->codegen, child_type, new_len, sentinel); |
| 15263 | | |
| 15263 | result->value->type = get_array_type(ira->codegen, child_type, new_len, sentinel); |
| 15264 | 15264 | out_array_val = out_val; |
| 15265 | 15265 | } else if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) { |
| 15266 | 15266 | out_array_val = create_const_vals(1); |
| ... | ... | @@ -15274,7 +15274,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15274 | 15274 | ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen, child_type, |
| 15275 | 15275 | true, false, PtrLenUnknown, 0, 0, 0, false, |
| 15276 | 15276 | VECTOR_INDEX_NONE, nullptr, sentinel); |
| 15277 | | result->value.type = get_slice_type(ira->codegen, ptr_type); |
| 15277 | result->value->type = get_slice_type(ira->codegen, ptr_type); |
| 15278 | 15278 | out_array_val = create_const_vals(1); |
| 15279 | 15279 | out_array_val->special = ConstValSpecialStatic; |
| 15280 | 15280 | out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel); |
| ... | ... | @@ -15291,9 +15291,8 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15291 | 15291 | out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic; |
| 15292 | 15292 | bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len); |
| 15293 | 15293 | } else { |
| 15294 | | result->value.type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown, |
| 15294 | result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown, |
| 15295 | 15295 | 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel); |
| 15296 | | |
| 15297 | 15296 | out_array_val = create_const_vals(1); |
| 15298 | 15297 | out_array_val->special = ConstValSpecialStatic; |
| 15299 | 15298 | out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel); |
| ... | ... | @@ -15345,34 +15344,34 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15345 | 15344 | |
| 15346 | 15345 | static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 15347 | 15346 | IrInstruction *op1 = instruction->op1->child; |
| 15348 | | if (type_is_invalid(op1->value.type)) |
| 15347 | if (type_is_invalid(op1->value->type)) |
| 15349 | 15348 | return ira->codegen->invalid_instruction; |
| 15350 | 15349 | |
| 15351 | 15350 | IrInstruction *op2 = instruction->op2->child; |
| 15352 | | if (type_is_invalid(op2->value.type)) |
| 15351 | if (type_is_invalid(op2->value->type)) |
| 15353 | 15352 | return ira->codegen->invalid_instruction; |
| 15354 | 15353 | |
| 15355 | 15354 | bool want_ptr_to_array = false; |
| 15356 | 15355 | ZigType *array_type; |
| 15357 | 15356 | ZigValue *array_val; |
| 15358 | | if (op1->value.type->id == ZigTypeIdArray) { |
| 15359 | | array_type = op1->value.type; |
| 15357 | if (op1->value->type->id == ZigTypeIdArray) { |
| 15358 | array_type = op1->value->type; |
| 15360 | 15359 | array_val = ir_resolve_const(ira, op1, UndefOk); |
| 15361 | 15360 | if (array_val == nullptr) |
| 15362 | 15361 | return ira->codegen->invalid_instruction; |
| 15363 | | } else if (op1->value.type->id == ZigTypeIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenSingle && |
| 15364 | | op1->value.type->data.pointer.child_type->id == ZigTypeIdArray) |
| 15362 | } else if (op1->value->type->id == ZigTypeIdPointer && op1->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 15363 | op1->value->type->data.pointer.child_type->id == ZigTypeIdArray) |
| 15365 | 15364 | { |
| 15366 | | array_type = op1->value.type->data.pointer.child_type; |
| 15365 | array_type = op1->value->type->data.pointer.child_type; |
| 15367 | 15366 | IrInstruction *array_inst = ir_get_deref(ira, op1, op1, nullptr); |
| 15368 | | if (type_is_invalid(array_inst->value.type)) |
| 15367 | if (type_is_invalid(array_inst->value->type)) |
| 15369 | 15368 | return ira->codegen->invalid_instruction; |
| 15370 | 15369 | array_val = ir_resolve_const(ira, array_inst, UndefOk); |
| 15371 | 15370 | if (array_val == nullptr) |
| 15372 | 15371 | return ira->codegen->invalid_instruction; |
| 15373 | 15372 | want_ptr_to_array = true; |
| 15374 | 15373 | } else { |
| 15375 | | ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name))); |
| 15374 | ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name))); |
| 15376 | 15375 | return ira->codegen->invalid_instruction; |
| 15377 | 15376 | } |
| 15378 | 15377 | |
| ... | ... | @@ -15397,7 +15396,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * |
| 15397 | 15396 | array_result = ir_const_undef(ira, &instruction->base, result_array_type); |
| 15398 | 15397 | } else { |
| 15399 | 15398 | array_result = ir_const(ira, &instruction->base, result_array_type); |
| 15400 | | ZigValue *out_val = &array_result->value; |
| 15399 | ZigValue *out_val = array_result->value; |
| 15401 | 15400 | |
| 15402 | 15401 | switch (type_has_one_possible_value(ira->codegen, result_array_type)) { |
| 15403 | 15402 | case OnePossibleValueInvalid: |
| ... | ... | @@ -15554,16 +15553,16 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 15554 | 15553 | IrInstruction *var_ptr = decl_var_instruction->ptr->child; |
| 15555 | 15554 | // if this is null, a compiler error happened and did not initialize the variable. |
| 15556 | 15555 | // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation. |
| 15557 | | if (var_ptr == nullptr || type_is_invalid(var_ptr->value.type)) { |
| 15556 | if (var_ptr == nullptr || type_is_invalid(var_ptr->value->type)) { |
| 15558 | 15557 | ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base); |
| 15559 | 15558 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 15560 | 15559 | return ira->codegen->invalid_instruction; |
| 15561 | 15560 | } |
| 15562 | 15561 | |
| 15563 | 15562 | // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value. |
| 15564 | | ir_assert(var_ptr->value.type->id == ZigTypeIdPointer, &decl_var_instruction->base); |
| 15563 | ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base); |
| 15565 | 15564 | |
| 15566 | | ZigType *result_type = var_ptr->value.type->data.pointer.child_type; |
| 15565 | ZigType *result_type = var_ptr->value->type->data.pointer.child_type; |
| 15567 | 15566 | if (type_is_invalid(result_type)) { |
| 15568 | 15567 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 15569 | 15568 | } else if (result_type->id == ZigTypeIdUnreachable || result_type->id == ZigTypeIdOpaque) { |
| ... | ... | @@ -15571,8 +15570,8 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 15571 | 15570 | } |
| 15572 | 15571 | |
| 15573 | 15572 | ZigValue *init_val = nullptr; |
| 15574 | | if (instr_is_comptime(var_ptr) && var_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 15575 | | init_val = const_ptr_pointee(ira, ira->codegen, &var_ptr->value, decl_var_instruction->base.source_node); |
| 15573 | if (instr_is_comptime(var_ptr) && var_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 15574 | init_val = const_ptr_pointee(ira, ira->codegen, var_ptr->value, decl_var_instruction->base.source_node); |
| 15576 | 15575 | if (is_comptime_var) { |
| 15577 | 15576 | if (var->gen_is_const) { |
| 15578 | 15577 | var->const_value = init_val; |
| ... | ... | @@ -15665,23 +15664,23 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 15665 | 15664 | if (init_val != nullptr && value_is_comptime(init_val)) { |
| 15666 | 15665 | // Resolve ConstPtrMutInfer |
| 15667 | 15666 | if (var->gen_is_const) { |
| 15668 | | var_ptr->value.data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 15667 | var_ptr->value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 15669 | 15668 | } else if (is_comptime_var) { |
| 15670 | | var_ptr->value.data.x_ptr.mut = ConstPtrMutComptimeVar; |
| 15669 | var_ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar; |
| 15671 | 15670 | } else { |
| 15672 | 15671 | // we need a runtime ptr but we have a comptime val. |
| 15673 | 15672 | // since it's a comptime val there are no instructions for it. |
| 15674 | 15673 | // we memcpy the init value here |
| 15675 | 15674 | IrInstruction *deref = ir_get_deref(ira, var_ptr, var_ptr, nullptr); |
| 15676 | | if (type_is_invalid(deref->value.type)) { |
| 15675 | if (type_is_invalid(deref->value->type)) { |
| 15677 | 15676 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 15678 | 15677 | return ira->codegen->invalid_instruction; |
| 15679 | 15678 | } |
| 15680 | 15679 | // If this assertion trips, something is wrong with the IR instructions, because |
| 15681 | 15680 | // we expected the above deref to return a constant value, but it created a runtime |
| 15682 | 15681 | // instruction. |
| 15683 | | assert(deref->value.special != ConstValSpecialRuntime); |
| 15684 | | var_ptr->value.special = ConstValSpecialRuntime; |
| 15682 | assert(deref->value->special != ConstValSpecialRuntime); |
| 15683 | var_ptr->value->special = ConstValSpecialRuntime; |
| 15685 | 15684 | ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false); |
| 15686 | 15685 | } |
| 15687 | 15686 | |
| ... | ... | @@ -15718,7 +15717,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 15718 | 15717 | } |
| 15719 | 15718 | |
| 15720 | 15719 | IrInstruction *target = instruction->target->child; |
| 15721 | | if (type_is_invalid(target->value.type)) { |
| 15720 | if (type_is_invalid(target->value->type)) { |
| 15722 | 15721 | return ira->codegen->invalid_instruction; |
| 15723 | 15722 | } |
| 15724 | 15723 | |
| ... | ... | @@ -15748,13 +15747,13 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 15748 | 15747 | } |
| 15749 | 15748 | |
| 15750 | 15749 | bool want_var_export = false; |
| 15751 | | switch (target->value.type->id) { |
| 15750 | switch (target->value->type->id) { |
| 15752 | 15751 | case ZigTypeIdInvalid: |
| 15753 | 15752 | case ZigTypeIdUnreachable: |
| 15754 | 15753 | zig_unreachable(); |
| 15755 | 15754 | case ZigTypeIdFn: { |
| 15756 | | assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction); |
| 15757 | | ZigFn *fn_entry = target->value.data.x_ptr.data.fn.fn_entry; |
| 15755 | assert(target->value->data.x_ptr.special == ConstPtrSpecialFunction); |
| 15756 | ZigFn *fn_entry = target->value->data.x_ptr.data.fn.fn_entry; |
| 15758 | 15757 | tld_fn->fn_entry = fn_entry; |
| 15759 | 15758 | CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc; |
| 15760 | 15759 | switch (cc) { |
| ... | ... | @@ -15778,51 +15777,51 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 15778 | 15777 | } |
| 15779 | 15778 | } break; |
| 15780 | 15779 | case ZigTypeIdStruct: |
| 15781 | | if (is_slice(target->value.type)) { |
| 15780 | if (is_slice(target->value->type)) { |
| 15782 | 15781 | ir_add_error(ira, target, |
| 15783 | | buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value.type->name))); |
| 15784 | | } else if (target->value.type->data.structure.layout != ContainerLayoutExtern) { |
| 15782 | buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name))); |
| 15783 | } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) { |
| 15785 | 15784 | ErrorMsg *msg = ir_add_error(ira, target, |
| 15786 | 15785 | buf_sprintf("exported struct value must be declared extern")); |
| 15787 | | add_error_note(ira->codegen, msg, target->value.type->data.structure.decl_node, buf_sprintf("declared here")); |
| 15786 | add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here")); |
| 15788 | 15787 | } else { |
| 15789 | 15788 | want_var_export = true; |
| 15790 | 15789 | } |
| 15791 | 15790 | break; |
| 15792 | 15791 | case ZigTypeIdUnion: |
| 15793 | | if (target->value.type->data.unionation.layout != ContainerLayoutExtern) { |
| 15792 | if (target->value->type->data.unionation.layout != ContainerLayoutExtern) { |
| 15794 | 15793 | ErrorMsg *msg = ir_add_error(ira, target, |
| 15795 | 15794 | buf_sprintf("exported union value must be declared extern")); |
| 15796 | | add_error_note(ira->codegen, msg, target->value.type->data.unionation.decl_node, buf_sprintf("declared here")); |
| 15795 | add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here")); |
| 15797 | 15796 | } else { |
| 15798 | 15797 | want_var_export = true; |
| 15799 | 15798 | } |
| 15800 | 15799 | break; |
| 15801 | 15800 | case ZigTypeIdEnum: |
| 15802 | | if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) { |
| 15801 | if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) { |
| 15803 | 15802 | ErrorMsg *msg = ir_add_error(ira, target, |
| 15804 | 15803 | buf_sprintf("exported enum value must be declared extern")); |
| 15805 | | add_error_note(ira->codegen, msg, target->value.type->data.enumeration.decl_node, buf_sprintf("declared here")); |
| 15804 | add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here")); |
| 15806 | 15805 | } else { |
| 15807 | 15806 | want_var_export = true; |
| 15808 | 15807 | } |
| 15809 | 15808 | break; |
| 15810 | 15809 | case ZigTypeIdArray: { |
| 15811 | 15810 | bool ok_type; |
| 15812 | | if ((err = type_allowed_in_extern(ira->codegen, target->value.type->data.array.child_type, &ok_type))) |
| 15811 | if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, &ok_type))) |
| 15813 | 15812 | return ira->codegen->invalid_instruction; |
| 15814 | 15813 | |
| 15815 | 15814 | if (!ok_type) { |
| 15816 | 15815 | ir_add_error(ira, target, |
| 15817 | 15816 | buf_sprintf("array element type '%s' not extern-compatible", |
| 15818 | | buf_ptr(&target->value.type->data.array.child_type->name))); |
| 15817 | buf_ptr(&target->value->type->data.array.child_type->name))); |
| 15819 | 15818 | } else { |
| 15820 | 15819 | want_var_export = true; |
| 15821 | 15820 | } |
| 15822 | 15821 | break; |
| 15823 | 15822 | } |
| 15824 | 15823 | case ZigTypeIdMetaType: { |
| 15825 | | ZigType *type_value = target->value.data.x_type; |
| 15824 | ZigType *type_value = target->value->data.x_type; |
| 15826 | 15825 | switch (type_value->id) { |
| 15827 | 15826 | case ZigTypeIdInvalid: |
| 15828 | 15827 | zig_unreachable(); |
| ... | ... | @@ -15898,7 +15897,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 15898 | 15897 | case ZigTypeIdErrorUnion: |
| 15899 | 15898 | case ZigTypeIdErrorSet: |
| 15900 | 15899 | case ZigTypeIdVector: |
| 15901 | | zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name)); |
| 15900 | zig_panic("TODO export const value of type %s", buf_ptr(&target->value->type->name)); |
| 15902 | 15901 | case ZigTypeIdBoundFn: |
| 15903 | 15902 | case ZigTypeIdArgTuple: |
| 15904 | 15903 | case ZigTypeIdOpaque: |
| ... | ... | @@ -15906,7 +15905,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 15906 | 15905 | case ZigTypeIdFnFrame: |
| 15907 | 15906 | case ZigTypeIdAnyFrame: |
| 15908 | 15907 | ir_add_error(ira, target, |
| 15909 | | buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name))); |
| 15908 | buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name))); |
| 15910 | 15909 | break; |
| 15911 | 15910 | } |
| 15912 | 15911 | |
| ... | ... | @@ -15936,7 +15935,7 @@ static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 15936 | 15935 | ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type); |
| 15937 | 15936 | if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) { |
| 15938 | 15937 | IrInstruction *result = ir_const(ira, &instruction->base, optional_type); |
| 15939 | | ZigValue *out_val = &result->value; |
| 15938 | ZigValue *out_val = result->value; |
| 15940 | 15939 | assert(get_codegen_ptr_type(optional_type) != nullptr); |
| 15941 | 15940 | out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 15942 | 15941 | out_val->data.x_ptr.data.hard_coded_addr.addr = 0; |
| ... | ... | @@ -15944,13 +15943,13 @@ static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 15944 | 15943 | } |
| 15945 | 15944 | IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope, |
| 15946 | 15945 | instruction->base.source_node, instruction->optional); |
| 15947 | | new_instruction->value.type = optional_type; |
| 15946 | new_instruction->value->type = optional_type; |
| 15948 | 15947 | return new_instruction; |
| 15949 | 15948 | } else { |
| 15950 | 15949 | assert(ira->codegen->have_err_ret_tracing); |
| 15951 | 15950 | IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope, |
| 15952 | 15951 | instruction->base.source_node, instruction->optional); |
| 15953 | | new_instruction->value.type = ptr_to_stack_trace_type; |
| 15952 | new_instruction->value->type = ptr_to_stack_trace_type; |
| 15954 | 15953 | return new_instruction; |
| 15955 | 15954 | } |
| 15956 | 15955 | } |
| ... | ... | @@ -15959,11 +15958,11 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira, |
| 15959 | 15958 | IrInstructionErrorUnion *instruction) |
| 15960 | 15959 | { |
| 15961 | 15960 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 15962 | | result->value.special = ConstValSpecialLazy; |
| 15961 | result->value->special = ConstValSpecialLazy; |
| 15963 | 15962 | |
| 15964 | 15963 | LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1); |
| 15965 | 15964 | lazy_err_union_type->ira = ira; |
| 15966 | | result->value.data.x_lazy = &lazy_err_union_type->base; |
| 15965 | result->value->data.x_lazy = &lazy_err_union_type->base; |
| 15967 | 15966 | lazy_err_union_type->base.id = LazyValueIdErrUnionType; |
| 15968 | 15967 | |
| 15969 | 15968 | lazy_err_union_type->err_set_type = instruction->err_set->child; |
| ... | ... | @@ -15986,10 +15985,10 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in |
| 15986 | 15985 | pointee->special = ConstValSpecialUndef; |
| 15987 | 15986 | |
| 15988 | 15987 | IrInstructionAllocaGen *result = ir_build_alloca_gen(ira, source_inst, align, name_hint); |
| 15989 | | result->base.value.special = ConstValSpecialStatic; |
| 15990 | | result->base.value.data.x_ptr.special = ConstPtrSpecialRef; |
| 15991 | | result->base.value.data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer; |
| 15992 | | result->base.value.data.x_ptr.data.ref.pointee = pointee; |
| 15988 | result->base.value->special = ConstValSpecialStatic; |
| 15989 | result->base.value->data.x_ptr.special = ConstPtrSpecialRef; |
| 15990 | result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer; |
| 15991 | result->base.value->data.x_ptr.data.ref.pointee = pointee; |
| 15993 | 15992 | |
| 15994 | 15993 | bool var_type_has_bits; |
| 15995 | 15994 | if ((err = type_has_bits2(ira->codegen, var_type, &var_type_has_bits))) |
| ... | ... | @@ -16004,10 +16003,10 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in |
| 16004 | 16003 | return ira->codegen->invalid_instruction; |
| 16005 | 16004 | } |
| 16006 | 16005 | } |
| 16007 | | assert(result->base.value.data.x_ptr.special != ConstPtrSpecialInvalid); |
| 16006 | assert(result->base.value->data.x_ptr.special != ConstPtrSpecialInvalid); |
| 16008 | 16007 | |
| 16009 | 16008 | pointee->type = var_type; |
| 16010 | | result->base.value.type = get_pointer_to_type_extra(ira->codegen, var_type, false, false, |
| 16009 | result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false, |
| 16011 | 16010 | PtrLenSingle, align, 0, 0, false); |
| 16012 | 16011 | |
| 16013 | 16012 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| ... | ... | @@ -16031,7 +16030,7 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspe |
| 16031 | 16030 | case ResultLocIdCast: |
| 16032 | 16031 | return nullptr; |
| 16033 | 16032 | case ResultLocIdInstruction: |
| 16034 | | return result_loc->source_instruction->child->value.type; |
| 16033 | return result_loc->source_instruction->child->value->type; |
| 16035 | 16034 | case ResultLocIdReturn: |
| 16036 | 16035 | return ira->explicit_return_type; |
| 16037 | 16036 | case ResultLocIdPeer: |
| ... | ... | @@ -16064,12 +16063,12 @@ static bool type_can_bit_cast(ZigType *t) { |
| 16064 | 16063 | |
| 16065 | 16064 | static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) { |
| 16066 | 16065 | ZigValue *undef_child = create_const_vals(1); |
| 16067 | | undef_child->type = ptr->value.type->data.pointer.child_type; |
| 16066 | undef_child->type = ptr->value->type->data.pointer.child_type; |
| 16068 | 16067 | undef_child->special = ConstValSpecialUndef; |
| 16069 | | ptr->value.special = ConstValSpecialStatic; |
| 16070 | | ptr->value.data.x_ptr.mut = ConstPtrMutInfer; |
| 16071 | | ptr->value.data.x_ptr.special = ConstPtrSpecialRef; |
| 16072 | | ptr->value.data.x_ptr.data.ref.pointee = undef_child; |
| 16068 | ptr->value->special = ConstValSpecialStatic; |
| 16069 | ptr->value->data.x_ptr.mut = ConstPtrMutInfer; |
| 16070 | ptr->value->data.x_ptr.special = ConstPtrSpecialRef; |
| 16071 | ptr->value->data.x_ptr.data.ref.pointee = undef_child; |
| 16073 | 16072 | } |
| 16074 | 16073 | |
| 16075 | 16074 | static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out) { |
| ... | ... | @@ -16105,7 +16104,7 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su |
| 16105 | 16104 | ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime) |
| 16106 | 16105 | { |
| 16107 | 16106 | IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, ""); |
| 16108 | | alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false, |
| 16107 | alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false, |
| 16109 | 16108 | PtrLenSingle, 0, 0, 0, false); |
| 16110 | 16109 | set_up_result_loc_for_inferred_comptime(&alloca_gen->base); |
| 16111 | 16110 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| ... | ... | @@ -16158,7 +16157,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16158 | 16157 | if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime)) |
| 16159 | 16158 | return ira->codegen->invalid_instruction; |
| 16160 | 16159 | bool is_comptime = force_comptime || (value != nullptr && |
| 16161 | | value->value.special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const); |
| 16160 | value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const); |
| 16162 | 16161 | |
| 16163 | 16162 | if (alloca_src->base.child == nullptr || is_comptime) { |
| 16164 | 16163 | uint32_t align = 0; |
| ... | ... | @@ -16167,8 +16166,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16167 | 16166 | } |
| 16168 | 16167 | IrInstruction *alloca_gen; |
| 16169 | 16168 | if (is_comptime && value != nullptr) { |
| 16170 | | if (align > value->value.global_refs->align) { |
| 16171 | | value->value.global_refs->align = align; |
| 16169 | if (align > value->value->global_refs->align) { |
| 16170 | value->value->global_refs->align = align; |
| 16172 | 16171 | } |
| 16173 | 16172 | alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false); |
| 16174 | 16173 | } else { |
| ... | ... | @@ -16191,7 +16190,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16191 | 16190 | } |
| 16192 | 16191 | case ResultLocIdReturn: { |
| 16193 | 16192 | if (!non_null_comptime) { |
| 16194 | | bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime; |
| 16193 | bool is_comptime = value != nullptr && value->value->special != ConstValSpecialRuntime; |
| 16195 | 16194 | if (is_comptime) |
| 16196 | 16195 | return nullptr; |
| 16197 | 16196 | } |
| ... | ... | @@ -16222,8 +16221,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16222 | 16221 | value_type, value, force_runtime, non_null_comptime, true); |
| 16223 | 16222 | result_peer->suspend_pos.basic_block_index = SIZE_MAX; |
| 16224 | 16223 | result_peer->suspend_pos.instruction_index = SIZE_MAX; |
| 16225 | | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| 16226 | | parent_result_loc->value.type->id == ZigTypeIdUnreachable) |
| 16224 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 16225 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 16227 | 16226 | { |
| 16228 | 16227 | return parent_result_loc; |
| 16229 | 16228 | } |
| ... | ... | @@ -16270,19 +16269,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16270 | 16269 | |
| 16271 | 16270 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 16272 | 16271 | peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true); |
| 16273 | | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| 16274 | | parent_result_loc->value.type->id == ZigTypeIdUnreachable) |
| 16272 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 16273 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 16275 | 16274 | { |
| 16276 | 16275 | return parent_result_loc; |
| 16277 | 16276 | } |
| 16278 | 16277 | // because is_comptime is false, we mark this a runtime pointer |
| 16279 | | parent_result_loc->value.special = ConstValSpecialRuntime; |
| 16278 | parent_result_loc->value->special = ConstValSpecialRuntime; |
| 16280 | 16279 | result_loc->written = true; |
| 16281 | 16280 | result_loc->resolved_loc = parent_result_loc; |
| 16282 | 16281 | return result_loc->resolved_loc; |
| 16283 | 16282 | } |
| 16284 | 16283 | case ResultLocIdCast: { |
| 16285 | | if (value != nullptr && value->value.special != ConstValSpecialRuntime) |
| 16284 | if (value != nullptr && value->value->special != ConstValSpecialRuntime) |
| 16286 | 16285 | return nullptr; |
| 16287 | 16286 | ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc); |
| 16288 | 16287 | ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child); |
| ... | ... | @@ -16313,19 +16312,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16313 | 16312 | casted_value = nullptr; |
| 16314 | 16313 | } |
| 16315 | 16314 | |
| 16316 | | if (casted_value != nullptr && type_is_invalid(casted_value->value.type)) { |
| 16315 | if (casted_value != nullptr && type_is_invalid(casted_value->value->type)) { |
| 16317 | 16316 | return casted_value; |
| 16318 | 16317 | } |
| 16319 | 16318 | |
| 16320 | 16319 | bool old_parent_result_loc_written = result_cast->parent->written; |
| 16321 | 16320 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent, |
| 16322 | 16321 | dest_type, casted_value, force_runtime, non_null_comptime, true); |
| 16323 | | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| 16324 | | parent_result_loc->value.type->id == ZigTypeIdUnreachable) |
| 16322 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 16323 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 16325 | 16324 | { |
| 16326 | 16325 | return parent_result_loc; |
| 16327 | 16326 | } |
| 16328 | | ZigType *parent_ptr_type = parent_result_loc->value.type; |
| 16327 | ZigType *parent_ptr_type = parent_result_loc->value->type; |
| 16329 | 16328 | assert(parent_ptr_type->id == ZigTypeIdPointer); |
| 16330 | 16329 | if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type, |
| 16331 | 16330 | ResolveStatusAlignmentKnown))) |
| ... | ... | @@ -16358,7 +16357,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16358 | 16357 | { |
| 16359 | 16358 | // we also need to check that this cast is OK. |
| 16360 | 16359 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira, |
| 16361 | | parent_result_loc->value.type, ptr_type, |
| 16360 | parent_result_loc->value->type, ptr_type, |
| 16362 | 16361 | result_cast->base.source_instruction->source_node, false); |
| 16363 | 16362 | if (const_cast_result.id == ConstCastResultIdInvalid) |
| 16364 | 16363 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -16413,18 +16412,18 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16413 | 16412 | bitcasted_value = nullptr; |
| 16414 | 16413 | } |
| 16415 | 16414 | |
| 16416 | | if (bitcasted_value == nullptr || type_is_invalid(bitcasted_value->value.type)) { |
| 16415 | if (bitcasted_value == nullptr || type_is_invalid(bitcasted_value->value->type)) { |
| 16417 | 16416 | return bitcasted_value; |
| 16418 | 16417 | } |
| 16419 | 16418 | |
| 16420 | 16419 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, |
| 16421 | 16420 | dest_type, bitcasted_value, force_runtime, non_null_comptime, true); |
| 16422 | | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| 16423 | | parent_result_loc->value.type->id == ZigTypeIdUnreachable) |
| 16421 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 16422 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 16424 | 16423 | { |
| 16425 | 16424 | return parent_result_loc; |
| 16426 | 16425 | } |
| 16427 | | ZigType *parent_ptr_type = parent_result_loc->value.type; |
| 16426 | ZigType *parent_ptr_type = parent_result_loc->value->type; |
| 16428 | 16427 | assert(parent_ptr_type->id == ZigTypeIdPointer); |
| 16429 | 16428 | if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type, |
| 16430 | 16429 | ResolveStatusAlignmentKnown))) |
| ... | ... | @@ -16454,24 +16453,24 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 16454 | 16453 | { |
| 16455 | 16454 | if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction && |
| 16456 | 16455 | instr_is_comptime(result_loc_pass1->source_instruction) && |
| 16457 | | result_loc_pass1->source_instruction->value.type->id == ZigTypeIdPointer && |
| 16458 | | result_loc_pass1->source_instruction->value.data.x_ptr.special == ConstPtrSpecialDiscard) |
| 16456 | result_loc_pass1->source_instruction->value->type->id == ZigTypeIdPointer && |
| 16457 | result_loc_pass1->source_instruction->value->data.x_ptr.special == ConstPtrSpecialDiscard) |
| 16459 | 16458 | { |
| 16460 | 16459 | result_loc_pass1 = no_result_loc(); |
| 16461 | 16460 | } |
| 16462 | 16461 | IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, |
| 16463 | 16462 | value, force_runtime, non_null_comptime); |
| 16464 | | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value.type))) |
| 16463 | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type))) |
| 16465 | 16464 | return result_loc; |
| 16466 | 16465 | |
| 16467 | 16466 | if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) && |
| 16468 | | result_loc_pass1->written && result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) |
| 16467 | result_loc_pass1->written && result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) |
| 16469 | 16468 | { |
| 16470 | | result_loc->value.special = ConstValSpecialRuntime; |
| 16469 | result_loc->value->special = ConstValSpecialRuntime; |
| 16471 | 16470 | } |
| 16472 | 16471 | |
| 16473 | | ir_assert(result_loc->value.type->id == ZigTypeIdPointer, suspend_source_instr); |
| 16474 | | ZigType *actual_elem_type = result_loc->value.type->data.pointer.child_type; |
| 16472 | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr); |
| 16473 | ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type; |
| 16475 | 16474 | if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && |
| 16476 | 16475 | value_type->id != ZigTypeIdNull) |
| 16477 | 16476 | { |
| ... | ... | @@ -16544,18 +16543,18 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, |
| 16544 | 16543 | result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(), |
| 16545 | 16544 | implicit_elem_type, nullptr, false, true, true); |
| 16546 | 16545 | if (result_loc != nullptr && |
| 16547 | | (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) |
| 16546 | (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 16548 | 16547 | { |
| 16549 | 16548 | return result_loc; |
| 16550 | 16549 | } |
| 16551 | | result_loc->value.special = ConstValSpecialRuntime; |
| 16550 | result_loc->value->special = ConstValSpecialRuntime; |
| 16552 | 16551 | return result_loc; |
| 16553 | 16552 | } |
| 16554 | 16553 | |
| 16555 | 16554 | IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type); |
| 16556 | | result->value.special = ConstValSpecialUndef; |
| 16555 | result->value->special = ConstValSpecialUndef; |
| 16557 | 16556 | IrInstruction *ptr = ir_get_ref(ira, &instruction->base, result, false, false); |
| 16558 | | ptr->value.data.x_ptr.mut = ConstPtrMutComptimeVar; |
| 16557 | ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar; |
| 16559 | 16558 | return ptr; |
| 16560 | 16559 | } |
| 16561 | 16560 | |
| ... | ... | @@ -16605,9 +16604,9 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstructionCal |
| 16605 | 16604 | { |
| 16606 | 16605 | ir_assert(call_instruction->is_async_call_builtin, &call_instruction->base); |
| 16607 | 16606 | IrInstruction *ret_ptr_uncasted = call_instruction->args[call_instruction->arg_count]->child; |
| 16608 | | if (type_is_invalid(ret_ptr_uncasted->value.type)) |
| 16607 | if (type_is_invalid(ret_ptr_uncasted->value->type)) |
| 16609 | 16608 | return ira->codegen->invalid_instruction; |
| 16610 | | if (ret_ptr_uncasted->value.type->id == ZigTypeIdVoid) { |
| 16609 | if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) { |
| 16611 | 16610 | // Result location will be inside the async frame. |
| 16612 | 16611 | return nullptr; |
| 16613 | 16612 | } |
| ... | ... | @@ -16632,7 +16631,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc |
| 16632 | 16631 | if (casted_new_stack != nullptr) { |
| 16633 | 16632 | ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type; |
| 16634 | 16633 | IrInstruction *ret_ptr = get_async_call_result_loc(ira, call_instruction, fn_ret_type); |
| 16635 | | if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value.type)) |
| 16634 | if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type)) |
| 16636 | 16635 | return ira->codegen->invalid_instruction; |
| 16637 | 16636 | |
| 16638 | 16637 | ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type); |
| ... | ... | @@ -16645,11 +16644,11 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc |
| 16645 | 16644 | ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry); |
| 16646 | 16645 | IrInstruction *result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 16647 | 16646 | frame_type, nullptr, true, true, false); |
| 16648 | | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 16647 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 16649 | 16648 | return result_loc; |
| 16650 | 16649 | } |
| 16651 | 16650 | result_loc = ir_implicit_cast(ira, result_loc, get_pointer_to_type(ira->codegen, frame_type, false)); |
| 16652 | | if (type_is_invalid(result_loc->value.type)) |
| 16651 | if (type_is_invalid(result_loc->value->type)) |
| 16653 | 16652 | return ira->codegen->invalid_instruction; |
| 16654 | 16653 | return &ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, arg_count, |
| 16655 | 16654 | casted_args, FnInlineAuto, CallModifierAsync, casted_new_stack, |
| ... | ... | @@ -16670,7 +16669,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 16670 | 16669 | return false; |
| 16671 | 16670 | |
| 16672 | 16671 | casted_arg = ir_implicit_cast(ira, arg, param_type); |
| 16673 | | if (type_is_invalid(casted_arg->value.type)) |
| 16672 | if (type_is_invalid(casted_arg->value->type)) |
| 16674 | 16673 | return false; |
| 16675 | 16674 | } else { |
| 16676 | 16675 | casted_arg = arg; |
| ... | ... | @@ -16710,7 +16709,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 16710 | 16709 | return false; |
| 16711 | 16710 | |
| 16712 | 16711 | casted_arg = ir_implicit_cast(ira, arg, param_type); |
| 16713 | | if (type_is_invalid(casted_arg->value.type)) |
| 16712 | if (type_is_invalid(casted_arg->value->type)) |
| 16714 | 16713 | return false; |
| 16715 | 16714 | } else { |
| 16716 | 16715 | arg_part_of_generic_id = true; |
| ... | ... | @@ -16719,7 +16718,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 16719 | 16718 | } |
| 16720 | 16719 | |
| 16721 | 16720 | bool comptime_arg = param_decl_node->data.param_decl.is_comptime || |
| 16722 | | casted_arg->value.type->id == ZigTypeIdComptimeInt || casted_arg->value.type->id == ZigTypeIdComptimeFloat; |
| 16721 | casted_arg->value->type->id == ZigTypeIdComptimeInt || casted_arg->value->type->id == ZigTypeIdComptimeFloat; |
| 16723 | 16722 | |
| 16724 | 16723 | ZigValue *arg_val; |
| 16725 | 16724 | |
| ... | ... | @@ -16729,7 +16728,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 16729 | 16728 | if (!arg_val) |
| 16730 | 16729 | return false; |
| 16731 | 16730 | } else { |
| 16732 | | arg_val = create_const_runtime(casted_arg->value.type); |
| 16731 | arg_val = create_const_runtime(casted_arg->value->type); |
| 16733 | 16732 | } |
| 16734 | 16733 | if (arg_part_of_generic_id) { |
| 16735 | 16734 | copy_const_val(&generic_id->params[generic_id->param_count], arg_val, true); |
| ... | ... | @@ -16745,8 +16744,8 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 16745 | 16744 | var->shadowable = !comptime_arg; |
| 16746 | 16745 | |
| 16747 | 16746 | *next_proto_i += 1; |
| 16748 | | } else if (casted_arg->value.type->id == ZigTypeIdComptimeInt || |
| 16749 | | casted_arg->value.type->id == ZigTypeIdComptimeFloat) |
| 16747 | } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt || |
| 16748 | casted_arg->value->type->id == ZigTypeIdComptimeFloat) |
| 16750 | 16749 | { |
| 16751 | 16750 | ir_add_error(ira, casted_arg, |
| 16752 | 16751 | buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557")); |
| ... | ... | @@ -16754,10 +16753,10 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 16754 | 16753 | } |
| 16755 | 16754 | |
| 16756 | 16755 | if (!comptime_arg) { |
| 16757 | | switch (type_requires_comptime(ira->codegen, casted_arg->value.type)) { |
| 16756 | switch (type_requires_comptime(ira->codegen, casted_arg->value->type)) { |
| 16758 | 16757 | case ReqCompTimeYes: |
| 16759 | 16758 | ir_add_error(ira, casted_arg, |
| 16760 | | buf_sprintf("parameter of type '%s' requires comptime", buf_ptr(&casted_arg->value.type->name))); |
| 16759 | buf_sprintf("parameter of type '%s' requires comptime", buf_ptr(&casted_arg->value->type->name))); |
| 16761 | 16760 | return false; |
| 16762 | 16761 | case ReqCompTimeInvalid: |
| 16763 | 16762 | return false; |
| ... | ... | @@ -16767,7 +16766,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 16767 | 16766 | |
| 16768 | 16767 | casted_args[fn_type_id->param_count] = casted_arg; |
| 16769 | 16768 | FnTypeParamInfo *param_info = &fn_type_id->param_info[fn_type_id->param_count]; |
| 16770 | | param_info->type = casted_arg->value.type; |
| 16769 | param_info->type = casted_arg->value->type; |
| 16771 | 16770 | param_info->is_noalias = param_decl_node->data.param_decl.is_noalias; |
| 16772 | 16771 | impl_fn->param_source_nodes[fn_type_id->param_count] = param_decl_node; |
| 16773 | 16772 | fn_type_id->param_count += 1; |
| ... | ... | @@ -16813,7 +16812,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 16813 | 16812 | |
| 16814 | 16813 | IrInstruction *result = ir_build_var_ptr(&ira->new_irb, |
| 16815 | 16814 | instruction->scope, instruction->source_node, var); |
| 16816 | | result->value.type = get_pointer_to_type_extra(ira->codegen, var->var_type, |
| 16815 | result->value->type = get_pointer_to_type_extra(ira->codegen, var->var_type, |
| 16817 | 16816 | var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false); |
| 16818 | 16817 | |
| 16819 | 16818 | if (linkage_makes_it_runtime) |
| ... | ... | @@ -16846,10 +16845,10 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 16846 | 16845 | assert(!comptime_var_mem); |
| 16847 | 16846 | ptr_mut = ConstPtrMutRuntimeVar; |
| 16848 | 16847 | } |
| 16849 | | result->value.special = ConstValSpecialStatic; |
| 16850 | | result->value.data.x_ptr.mut = ptr_mut; |
| 16851 | | result->value.data.x_ptr.special = ConstPtrSpecialRef; |
| 16852 | | result->value.data.x_ptr.data.ref.pointee = mem_slot; |
| 16848 | result->value->special = ConstValSpecialStatic; |
| 16849 | result->value->data.x_ptr.mut = ptr_mut; |
| 16850 | result->value->data.x_ptr.special = ConstPtrSpecialRef; |
| 16851 | result->value->data.x_ptr.data.ref.pointee = mem_slot; |
| 16853 | 16852 | return result; |
| 16854 | 16853 | } |
| 16855 | 16854 | } |
| ... | ... | @@ -16859,7 +16858,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 16859 | 16858 | no_mem_slot: |
| 16860 | 16859 | |
| 16861 | 16860 | bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr); |
| 16862 | | result->value.data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; |
| 16861 | result->value->data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; |
| 16863 | 16862 | |
| 16864 | 16863 | return result; |
| 16865 | 16864 | } |
| ... | ... | @@ -16881,11 +16880,11 @@ static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_ins |
| 16881 | 16880 | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 16882 | 16881 | IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const) |
| 16883 | 16882 | { |
| 16884 | | assert(ptr->value.type->id == ZigTypeIdPointer); |
| 16883 | assert(ptr->value->type->id == ZigTypeIdPointer); |
| 16885 | 16884 | |
| 16886 | | if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) { |
| 16887 | | if (uncasted_value->value.type->id == ZigTypeIdErrorUnion || |
| 16888 | | uncasted_value->value.type->id == ZigTypeIdErrorSet) |
| 16885 | if (ptr->value->data.x_ptr.special == ConstPtrSpecialDiscard) { |
| 16886 | if (uncasted_value->value->type->id == ZigTypeIdErrorUnion || |
| 16887 | uncasted_value->value->type->id == ZigTypeIdErrorSet) |
| 16889 | 16888 | { |
| 16890 | 16889 | ir_add_error(ira, source_instr, buf_sprintf("error is discarded")); |
| 16891 | 16890 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -16893,7 +16892,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16893 | 16892 | return ir_const_void(ira, source_instr); |
| 16894 | 16893 | } |
| 16895 | 16894 | |
| 16896 | | InferredStructField *isf = ptr->value.type->data.pointer.inferred_struct_field; |
| 16895 | InferredStructField *isf = ptr->value->type->data.pointer.inferred_struct_field; |
| 16897 | 16896 | if (allow_write_through_const && isf != nullptr) { |
| 16898 | 16897 | // Now it's time to add the field to the struct type. |
| 16899 | 16898 | uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count; |
| ... | ... | @@ -16904,7 +16903,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16904 | 16903 | |
| 16905 | 16904 | TypeStructField *field = isf->inferred_struct_type->data.structure.fields[old_field_count]; |
| 16906 | 16905 | field->name = isf->field_name; |
| 16907 | | field->type_entry = uncasted_value->value.type; |
| 16906 | field->type_entry = uncasted_value->value->type; |
| 16908 | 16907 | field->type_val = create_const_type(ira->codegen, field->type_entry); |
| 16909 | 16908 | field->src_index = old_field_count; |
| 16910 | 16909 | field->decl_node = uncasted_value->source_node; |
| ... | ... | @@ -16913,12 +16912,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16913 | 16912 | IrInstruction *casted_ptr; |
| 16914 | 16913 | if (instr_is_comptime(ptr)) { |
| 16915 | 16914 | casted_ptr = ir_const(ira, source_instr, struct_ptr_type); |
| 16916 | | copy_const_val(&casted_ptr->value, &ptr->value, false); |
| 16917 | | casted_ptr->value.type = struct_ptr_type; |
| 16915 | copy_const_val(casted_ptr->value, ptr->value, false); |
| 16916 | casted_ptr->value->type = struct_ptr_type; |
| 16918 | 16917 | } else { |
| 16919 | 16918 | casted_ptr = ir_build_cast(&ira->new_irb, source_instr->scope, |
| 16920 | 16919 | source_instr->source_node, struct_ptr_type, ptr, CastOpNoop); |
| 16921 | | casted_ptr->value.type = struct_ptr_type; |
| 16920 | casted_ptr->value->type = struct_ptr_type; |
| 16922 | 16921 | } |
| 16923 | 16922 | if (instr_is_comptime(casted_ptr)) { |
| 16924 | 16923 | ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad); |
| ... | ... | @@ -16944,12 +16943,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16944 | 16943 | isf->inferred_struct_type, true); |
| 16945 | 16944 | } |
| 16946 | 16945 | |
| 16947 | | if (ptr->value.type->data.pointer.is_const && !allow_write_through_const) { |
| 16946 | if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) { |
| 16948 | 16947 | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); |
| 16949 | 16948 | return ira->codegen->invalid_instruction; |
| 16950 | 16949 | } |
| 16951 | 16950 | |
| 16952 | | ZigType *child_type = ptr->value.type->data.pointer.child_type; |
| 16951 | ZigType *child_type = ptr->value->type->data.pointer.child_type; |
| 16953 | 16952 | IrInstruction *value = ir_implicit_cast(ira, uncasted_value, child_type); |
| 16954 | 16953 | if (value == ira->codegen->invalid_instruction) |
| 16955 | 16954 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -16963,16 +16962,16 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16963 | 16962 | break; |
| 16964 | 16963 | } |
| 16965 | 16964 | |
| 16966 | | if (instr_is_comptime(ptr) && ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 16967 | | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst) { |
| 16965 | if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 16966 | if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) { |
| 16968 | 16967 | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); |
| 16969 | 16968 | return ira->codegen->invalid_instruction; |
| 16970 | 16969 | } |
| 16971 | | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar || |
| 16972 | | ptr->value.data.x_ptr.mut == ConstPtrMutInfer) |
| 16970 | if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar || |
| 16971 | ptr->value->data.x_ptr.mut == ConstPtrMutInfer) |
| 16973 | 16972 | { |
| 16974 | 16973 | if (instr_is_comptime(value)) { |
| 16975 | | ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, &ptr->value, source_instr->source_node); |
| 16974 | ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node); |
| 16976 | 16975 | if (dest_val == nullptr) |
| 16977 | 16976 | return ira->codegen->invalid_instruction; |
| 16978 | 16977 | if (dest_val->special != ConstValSpecialRuntime) { |
| ... | ... | @@ -16982,9 +16981,9 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16982 | 16981 | // * "string literal used as comptime slice is memoized" |
| 16983 | 16982 | // * "comptime modification of const struct field" - except modified to avoid |
| 16984 | 16983 | // ConstPtrMutComptimeVar, thus defeating the logic below. |
| 16985 | | bool same_global_refs = ptr->value.data.x_ptr.mut != ConstPtrMutComptimeVar; |
| 16986 | | copy_const_val(dest_val, &value->value, same_global_refs); |
| 16987 | | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar && |
| 16984 | bool same_global_refs = ptr->value->data.x_ptr.mut != ConstPtrMutComptimeVar; |
| 16985 | copy_const_val(dest_val, value->value, same_global_refs); |
| 16986 | if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar && |
| 16988 | 16987 | !ira->new_irb.current_basic_block->must_be_comptime_source_instr) |
| 16989 | 16988 | { |
| 16990 | 16989 | ira->new_irb.current_basic_block->must_be_comptime_source_instr = source_instr; |
| ... | ... | @@ -16992,12 +16991,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16992 | 16991 | return ir_const_void(ira, source_instr); |
| 16993 | 16992 | } |
| 16994 | 16993 | } |
| 16995 | | if (ptr->value.data.x_ptr.mut == ConstPtrMutInfer) { |
| 16996 | | ptr->value.special = ConstValSpecialRuntime; |
| 16994 | if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 16995 | ptr->value->special = ConstValSpecialRuntime; |
| 16997 | 16996 | } else { |
| 16998 | 16997 | ir_add_error(ira, source_instr, |
| 16999 | 16998 | buf_sprintf("cannot store runtime value in compile time variable")); |
| 17000 | | ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, &ptr->value); |
| 16999 | ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value); |
| 17001 | 17000 | dest_val->type = ira->codegen->builtin_types.entry_invalid; |
| 17002 | 17001 | |
| 17003 | 17002 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -17009,7 +17008,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 17009 | 17008 | case ReqCompTimeInvalid: |
| 17010 | 17009 | return ira->codegen->invalid_instruction; |
| 17011 | 17010 | case ReqCompTimeYes: |
| 17012 | | switch (type_has_one_possible_value(ira->codegen, ptr->value.type)) { |
| 17011 | switch (type_has_one_possible_value(ira->codegen, ptr->value->type)) { |
| 17013 | 17012 | case OnePossibleValueInvalid: |
| 17014 | 17013 | return ira->codegen->invalid_instruction; |
| 17015 | 17014 | case OnePossibleValueNo: |
| ... | ... | @@ -17025,7 +17024,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 17025 | 17024 | } |
| 17026 | 17025 | |
| 17027 | 17026 | if (instr_is_comptime(value)) { |
| 17028 | | mark_comptime_value_escape(ira, source_instr, &value->value); |
| 17027 | mark_comptime_value_escape(ira, source_instr, value->value); |
| 17029 | 17028 | } |
| 17030 | 17029 | |
| 17031 | 17030 | // If this is a store to a pointer with a runtime-known vector index, |
| ... | ... | @@ -17034,7 +17033,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 17034 | 17033 | // explaining why it is impossible for this store to work. Which is that |
| 17035 | 17034 | // the pointer address is of the vector; without the element index being known |
| 17036 | 17035 | // we cannot properly perform the insertion. |
| 17037 | | if (ptr->value.type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) { |
| 17036 | if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) { |
| 17038 | 17037 | if (ptr->id == IrInstructionIdElemPtr) { |
| 17039 | 17038 | IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr; |
| 17040 | 17039 | return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr, |
| ... | ... | @@ -17042,7 +17041,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 17042 | 17041 | } |
| 17043 | 17042 | ir_add_error(ira, ptr, |
| 17044 | 17043 | buf_sprintf("unable to determine vector element index of type '%s'", |
| 17045 | | buf_ptr(&ptr->value.type->name))); |
| 17044 | buf_ptr(&ptr->value->type->name))); |
| 17046 | 17045 | return ira->codegen->invalid_instruction; |
| 17047 | 17046 | } |
| 17048 | 17047 | |
| ... | ... | @@ -17058,12 +17057,12 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstructionCall |
| 17058 | 17057 | return nullptr; |
| 17059 | 17058 | |
| 17060 | 17059 | IrInstruction *new_stack = call_instruction->new_stack->child; |
| 17061 | | if (type_is_invalid(new_stack->value.type)) |
| 17060 | if (type_is_invalid(new_stack->value->type)) |
| 17062 | 17061 | return ira->codegen->invalid_instruction; |
| 17063 | 17062 | |
| 17064 | 17063 | if (call_instruction->is_async_call_builtin && |
| 17065 | | fn_entry != nullptr && new_stack->value.type->id == ZigTypeIdPointer && |
| 17066 | | new_stack->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 17064 | fn_entry != nullptr && new_stack->value->type->id == ZigTypeIdPointer && |
| 17065 | new_stack->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 17067 | 17066 | { |
| 17068 | 17067 | ZigType *needed_frame_type = get_pointer_to_type(ira->codegen, |
| 17069 | 17068 | get_fn_frame_type(ira->codegen, fn_entry), false); |
| ... | ... | @@ -17097,7 +17096,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17097 | 17096 | |
| 17098 | 17097 | size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0; |
| 17099 | 17098 | for (size_t i = 0; i < call_instruction->arg_count; i += 1) { |
| 17100 | | ZigValue *arg_tuple_value = &call_instruction->args[i]->child->value; |
| 17099 | ZigValue *arg_tuple_value = call_instruction->args[i]->child->value; |
| 17101 | 17100 | if (arg_tuple_value->type->id == ZigTypeIdArgTuple) { |
| 17102 | 17101 | call_param_count -= 1; |
| 17103 | 17102 | call_param_count += arg_tuple_value->data.x_arg_tuple.end_index - |
| ... | ... | @@ -17152,7 +17151,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17152 | 17151 | |
| 17153 | 17152 | size_t next_proto_i = 0; |
| 17154 | 17153 | if (first_arg_ptr) { |
| 17155 | | assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); |
| 17154 | assert(first_arg_ptr->value->type->id == ZigTypeIdPointer); |
| 17156 | 17155 | |
| 17157 | 17156 | bool first_arg_known_bare = false; |
| 17158 | 17157 | if (fn_type_id->next_param_index >= 1) { |
| ... | ... | @@ -17163,11 +17162,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17163 | 17162 | } |
| 17164 | 17163 | |
| 17165 | 17164 | IrInstruction *first_arg; |
| 17166 | | if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) { |
| 17165 | if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) { |
| 17167 | 17166 | first_arg = first_arg_ptr; |
| 17168 | 17167 | } else { |
| 17169 | 17168 | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); |
| 17170 | | if (type_is_invalid(first_arg->value.type)) |
| 17169 | if (type_is_invalid(first_arg->value->type)) |
| 17171 | 17170 | return ira->codegen->invalid_instruction; |
| 17172 | 17171 | } |
| 17173 | 17172 | |
| ... | ... | @@ -17184,7 +17183,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17184 | 17183 | |
| 17185 | 17184 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 17186 | 17185 | IrInstruction *old_arg = call_instruction->args[call_i]->child; |
| 17187 | | if (type_is_invalid(old_arg->value.type)) |
| 17186 | if (type_is_invalid(old_arg->value->type)) |
| 17188 | 17187 | return ira->codegen->invalid_instruction; |
| 17189 | 17188 | |
| 17190 | 17189 | if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i)) |
| ... | ... | @@ -17250,8 +17249,8 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17250 | 17249 | } |
| 17251 | 17250 | |
| 17252 | 17251 | IrInstruction *new_instruction = ir_const(ira, &call_instruction->base, result->type); |
| 17253 | | copy_const_val(&new_instruction->value, result, true); |
| 17254 | | new_instruction->value.type = return_type; |
| 17252 | copy_const_val(new_instruction->value, result, true); |
| 17253 | new_instruction->value->type = return_type; |
| 17255 | 17254 | return ir_finish_anal(ira, new_instruction); |
| 17256 | 17255 | } |
| 17257 | 17256 | |
| ... | ... | @@ -17266,11 +17265,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17266 | 17265 | size_t new_fn_arg_count = first_arg_1_or_0; |
| 17267 | 17266 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 17268 | 17267 | IrInstruction *arg = call_instruction->args[call_i]->child; |
| 17269 | | if (type_is_invalid(arg->value.type)) |
| 17268 | if (type_is_invalid(arg->value->type)) |
| 17270 | 17269 | return ira->codegen->invalid_instruction; |
| 17271 | 17270 | |
| 17272 | | if (arg->value.type->id == ZigTypeIdArgTuple) { |
| 17273 | | new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index; |
| 17271 | if (arg->value->type->id == ZigTypeIdArgTuple) { |
| 17272 | new_fn_arg_count += arg->value->data.x_arg_tuple.end_index - arg->value->data.x_arg_tuple.start_index; |
| 17274 | 17273 | } else { |
| 17275 | 17274 | new_fn_arg_count += 1; |
| 17276 | 17275 | } |
| ... | ... | @@ -17299,7 +17298,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17299 | 17298 | size_t next_proto_i = 0; |
| 17300 | 17299 | |
| 17301 | 17300 | if (first_arg_ptr) { |
| 17302 | | assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); |
| 17301 | assert(first_arg_ptr->value->type->id == ZigTypeIdPointer); |
| 17303 | 17302 | |
| 17304 | 17303 | bool first_arg_known_bare = false; |
| 17305 | 17304 | if (fn_type_id->next_param_index >= 1) { |
| ... | ... | @@ -17310,11 +17309,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17310 | 17309 | } |
| 17311 | 17310 | |
| 17312 | 17311 | IrInstruction *first_arg; |
| 17313 | | if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) { |
| 17312 | if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) { |
| 17314 | 17313 | first_arg = first_arg_ptr; |
| 17315 | 17314 | } else { |
| 17316 | 17315 | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); |
| 17317 | | if (type_is_invalid(first_arg->value.type)) |
| 17316 | if (type_is_invalid(first_arg->value->type)) |
| 17318 | 17317 | return ira->codegen->invalid_instruction; |
| 17319 | 17318 | } |
| 17320 | 17319 | |
| ... | ... | @@ -17332,12 +17331,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17332 | 17331 | assert(parent_fn_entry); |
| 17333 | 17332 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 17334 | 17333 | IrInstruction *arg = call_instruction->args[call_i]->child; |
| 17335 | | if (type_is_invalid(arg->value.type)) |
| 17334 | if (type_is_invalid(arg->value->type)) |
| 17336 | 17335 | return ira->codegen->invalid_instruction; |
| 17337 | 17336 | |
| 17338 | | if (arg->value.type->id == ZigTypeIdArgTuple) { |
| 17339 | | for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index; |
| 17340 | | arg_tuple_i < arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1) |
| 17337 | if (arg->value->type->id == ZigTypeIdArgTuple) { |
| 17338 | for (size_t arg_tuple_i = arg->value->data.x_arg_tuple.start_index; |
| 17339 | arg_tuple_i < arg->value->data.x_arg_tuple.end_index; arg_tuple_i += 1) |
| 17341 | 17340 | { |
| 17342 | 17341 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i); |
| 17343 | 17342 | assert(param_decl_node->type == NodeTypeParamDecl); |
| ... | ... | @@ -17354,11 +17353,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17354 | 17353 | return ira->codegen->invalid_instruction; |
| 17355 | 17354 | } |
| 17356 | 17355 | IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var); |
| 17357 | | if (type_is_invalid(arg_var_ptr_inst->value.type)) |
| 17356 | if (type_is_invalid(arg_var_ptr_inst->value->type)) |
| 17358 | 17357 | return ira->codegen->invalid_instruction; |
| 17359 | 17358 | |
| 17360 | 17359 | IrInstruction *arg_tuple_arg = ir_get_deref(ira, arg, arg_var_ptr_inst, nullptr); |
| 17361 | | if (type_is_invalid(arg_tuple_arg->value.type)) |
| 17360 | if (type_is_invalid(arg_tuple_arg->value->type)) |
| 17362 | 17361 | return ira->codegen->invalid_instruction; |
| 17363 | 17362 | |
| 17364 | 17363 | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg_tuple_arg, &impl_fn->child_scope, |
| ... | ... | @@ -17407,7 +17406,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17407 | 17406 | nullptr, UndefBad); |
| 17408 | 17407 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 17409 | 17408 | impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr); |
| 17410 | | copy_const_val(&const_instruction->base.value, align_result, true); |
| 17409 | copy_const_val(const_instruction->base.value, align_result, true); |
| 17411 | 17410 | |
| 17412 | 17411 | uint32_t align_bytes = 0; |
| 17413 | 17412 | ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes); |
| ... | ... | @@ -17468,7 +17467,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17468 | 17467 | } |
| 17469 | 17468 | |
| 17470 | 17469 | IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, call_instruction, impl_fn); |
| 17471 | | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value.type)) |
| 17470 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) |
| 17472 | 17471 | return ira->codegen->invalid_instruction; |
| 17473 | 17472 | |
| 17474 | 17473 | size_t impl_param_count = impl_fn_type_id->param_count; |
| ... | ... | @@ -17483,17 +17482,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17483 | 17482 | result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 17484 | 17483 | impl_fn_type_id->return_type, nullptr, true, true, false); |
| 17485 | 17484 | if (result_loc != nullptr) { |
| 17486 | | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 17485 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 17487 | 17486 | return result_loc; |
| 17488 | 17487 | } |
| 17489 | | if (!handle_is_ptr(result_loc->value.type->data.pointer.child_type)) { |
| 17488 | if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) { |
| 17490 | 17489 | ir_reset_result(call_instruction->result_loc); |
| 17491 | 17490 | result_loc = nullptr; |
| 17492 | 17491 | } |
| 17493 | 17492 | } |
| 17494 | 17493 | } else if (call_instruction->is_async_call_builtin) { |
| 17495 | 17494 | result_loc = get_async_call_result_loc(ira, call_instruction, impl_fn_type_id->return_type); |
| 17496 | | if (result_loc != nullptr && type_is_invalid(result_loc->value.type)) |
| 17495 | if (result_loc != nullptr && type_is_invalid(result_loc->value->type)) |
| 17497 | 17496 | return ira->codegen->invalid_instruction; |
| 17498 | 17497 | } else { |
| 17499 | 17498 | result_loc = nullptr; |
| ... | ... | @@ -17530,7 +17529,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17530 | 17529 | IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count); |
| 17531 | 17530 | size_t next_arg_index = 0; |
| 17532 | 17531 | if (first_arg_ptr) { |
| 17533 | | assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); |
| 17532 | assert(first_arg_ptr->value->type->id == ZigTypeIdPointer); |
| 17534 | 17533 | |
| 17535 | 17534 | ZigType *param_type = fn_type_id->param_info[next_arg_index].type; |
| 17536 | 17535 | if (type_is_invalid(param_type)) |
| ... | ... | @@ -17538,17 +17537,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17538 | 17537 | |
| 17539 | 17538 | IrInstruction *first_arg; |
| 17540 | 17539 | if (param_type->id == ZigTypeIdPointer && |
| 17541 | | handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) |
| 17540 | handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) |
| 17542 | 17541 | { |
| 17543 | 17542 | first_arg = first_arg_ptr; |
| 17544 | 17543 | } else { |
| 17545 | 17544 | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); |
| 17546 | | if (type_is_invalid(first_arg->value.type)) |
| 17545 | if (type_is_invalid(first_arg->value->type)) |
| 17547 | 17546 | return ira->codegen->invalid_instruction; |
| 17548 | 17547 | } |
| 17549 | 17548 | |
| 17550 | 17549 | IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type); |
| 17551 | | if (type_is_invalid(casted_arg->value.type)) |
| 17550 | if (type_is_invalid(casted_arg->value->type)) |
| 17552 | 17551 | return ira->codegen->invalid_instruction; |
| 17553 | 17552 | |
| 17554 | 17553 | casted_args[next_arg_index] = casted_arg; |
| ... | ... | @@ -17556,12 +17555,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17556 | 17555 | } |
| 17557 | 17556 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 17558 | 17557 | IrInstruction *old_arg = call_instruction->args[call_i]->child; |
| 17559 | | if (type_is_invalid(old_arg->value.type)) |
| 17558 | if (type_is_invalid(old_arg->value->type)) |
| 17560 | 17559 | return ira->codegen->invalid_instruction; |
| 17561 | 17560 | |
| 17562 | | if (old_arg->value.type->id == ZigTypeIdArgTuple) { |
| 17563 | | for (size_t arg_tuple_i = old_arg->value.data.x_arg_tuple.start_index; |
| 17564 | | arg_tuple_i < old_arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1) |
| 17561 | if (old_arg->value->type->id == ZigTypeIdArgTuple) { |
| 17562 | for (size_t arg_tuple_i = old_arg->value->data.x_arg_tuple.start_index; |
| 17563 | arg_tuple_i < old_arg->value->data.x_arg_tuple.end_index; arg_tuple_i += 1) |
| 17565 | 17564 | { |
| 17566 | 17565 | ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i); |
| 17567 | 17566 | if (arg_var == nullptr) { |
| ... | ... | @@ -17570,11 +17569,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17570 | 17569 | return ira->codegen->invalid_instruction; |
| 17571 | 17570 | } |
| 17572 | 17571 | IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, old_arg, arg_var); |
| 17573 | | if (type_is_invalid(arg_var_ptr_inst->value.type)) |
| 17572 | if (type_is_invalid(arg_var_ptr_inst->value->type)) |
| 17574 | 17573 | return ira->codegen->invalid_instruction; |
| 17575 | 17574 | |
| 17576 | 17575 | IrInstruction *arg_tuple_arg = ir_get_deref(ira, old_arg, arg_var_ptr_inst, nullptr); |
| 17577 | | if (type_is_invalid(arg_tuple_arg->value.type)) |
| 17576 | if (type_is_invalid(arg_tuple_arg->value->type)) |
| 17578 | 17577 | return ira->codegen->invalid_instruction; |
| 17579 | 17578 | |
| 17580 | 17579 | IrInstruction *casted_arg; |
| ... | ... | @@ -17583,7 +17582,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17583 | 17582 | if (type_is_invalid(param_type)) |
| 17584 | 17583 | return ira->codegen->invalid_instruction; |
| 17585 | 17584 | casted_arg = ir_implicit_cast(ira, arg_tuple_arg, param_type); |
| 17586 | | if (type_is_invalid(casted_arg->value.type)) |
| 17585 | if (type_is_invalid(casted_arg->value->type)) |
| 17587 | 17586 | return ira->codegen->invalid_instruction; |
| 17588 | 17587 | } else { |
| 17589 | 17588 | casted_arg = arg_tuple_arg; |
| ... | ... | @@ -17599,7 +17598,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17599 | 17598 | if (type_is_invalid(param_type)) |
| 17600 | 17599 | return ira->codegen->invalid_instruction; |
| 17601 | 17600 | casted_arg = ir_implicit_cast(ira, old_arg, param_type); |
| 17602 | | if (type_is_invalid(casted_arg->value.type)) |
| 17601 | if (type_is_invalid(casted_arg->value->type)) |
| 17603 | 17602 | return ira->codegen->invalid_instruction; |
| 17604 | 17603 | } else { |
| 17605 | 17604 | casted_arg = old_arg; |
| ... | ... | @@ -17623,7 +17622,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17623 | 17622 | } |
| 17624 | 17623 | |
| 17625 | 17624 | IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, call_instruction, fn_entry); |
| 17626 | | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value.type)) |
| 17625 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) |
| 17627 | 17626 | return ira->codegen->invalid_instruction; |
| 17628 | 17627 | |
| 17629 | 17628 | if (call_instruction->modifier == CallModifierAsync) { |
| ... | ... | @@ -17645,17 +17644,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17645 | 17644 | result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 17646 | 17645 | return_type, nullptr, true, true, false); |
| 17647 | 17646 | if (result_loc != nullptr) { |
| 17648 | | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 17647 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 17649 | 17648 | return result_loc; |
| 17650 | 17649 | } |
| 17651 | | if (!handle_is_ptr(result_loc->value.type->data.pointer.child_type)) { |
| 17650 | if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) { |
| 17652 | 17651 | ir_reset_result(call_instruction->result_loc); |
| 17653 | 17652 | result_loc = nullptr; |
| 17654 | 17653 | } |
| 17655 | 17654 | } |
| 17656 | 17655 | } else if (call_instruction->is_async_call_builtin) { |
| 17657 | 17656 | result_loc = get_async_call_result_loc(ira, call_instruction, return_type); |
| 17658 | | if (result_loc != nullptr && type_is_invalid(result_loc->value.type)) |
| 17657 | if (result_loc != nullptr && type_is_invalid(result_loc->value->type)) |
| 17659 | 17658 | return ira->codegen->invalid_instruction; |
| 17660 | 17659 | } else { |
| 17661 | 17660 | result_loc = nullptr; |
| ... | ... | @@ -17672,14 +17671,14 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17672 | 17671 | |
| 17673 | 17672 | static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction) { |
| 17674 | 17673 | IrInstruction *fn_ref = call_instruction->fn_ref->child; |
| 17675 | | if (type_is_invalid(fn_ref->value.type)) |
| 17674 | if (type_is_invalid(fn_ref->value->type)) |
| 17676 | 17675 | return ira->codegen->invalid_instruction; |
| 17677 | 17676 | |
| 17678 | 17677 | bool is_comptime = call_instruction->is_comptime || |
| 17679 | 17678 | ir_should_inline(ira->new_irb.exec, call_instruction->base.scope); |
| 17680 | 17679 | |
| 17681 | 17680 | if (is_comptime || instr_is_comptime(fn_ref)) { |
| 17682 | | if (fn_ref->value.type->id == ZigTypeIdMetaType) { |
| 17681 | if (fn_ref->value->type->id == ZigTypeIdMetaType) { |
| 17683 | 17682 | ZigType *ty = ir_resolve_type(ira, fn_ref); |
| 17684 | 17683 | if (ty == nullptr) |
| 17685 | 17684 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -17688,30 +17687,30 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC |
| 17688 | 17687 | add_error_note(ira->codegen, msg, call_instruction->base.source_node, |
| 17689 | 17688 | buf_sprintf("use @as builtin for type coercion")); |
| 17690 | 17689 | return ira->codegen->invalid_instruction; |
| 17691 | | } else if (fn_ref->value.type->id == ZigTypeIdFn) { |
| 17690 | } else if (fn_ref->value->type->id == ZigTypeIdFn) { |
| 17692 | 17691 | ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); |
| 17693 | | ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value.type; |
| 17692 | ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value->type; |
| 17694 | 17693 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_type, |
| 17695 | 17694 | fn_ref, nullptr, is_comptime, call_instruction->fn_inline); |
| 17696 | | } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) { |
| 17697 | | assert(fn_ref->value.special == ConstValSpecialStatic); |
| 17698 | | ZigFn *fn_table_entry = fn_ref->value.data.x_bound_fn.fn; |
| 17699 | | IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg; |
| 17695 | } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) { |
| 17696 | assert(fn_ref->value->special == ConstValSpecialStatic); |
| 17697 | ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn; |
| 17698 | IrInstruction *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg; |
| 17700 | 17699 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, |
| 17701 | 17700 | fn_ref, first_arg_ptr, is_comptime, call_instruction->fn_inline); |
| 17702 | 17701 | } else { |
| 17703 | 17702 | ir_add_error_node(ira, fn_ref->source_node, |
| 17704 | | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name))); |
| 17703 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name))); |
| 17705 | 17704 | return ira->codegen->invalid_instruction; |
| 17706 | 17705 | } |
| 17707 | 17706 | } |
| 17708 | 17707 | |
| 17709 | | if (fn_ref->value.type->id == ZigTypeIdFn) { |
| 17710 | | return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type, |
| 17708 | if (fn_ref->value->type->id == ZigTypeIdFn) { |
| 17709 | return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value->type, |
| 17711 | 17710 | fn_ref, nullptr, false, call_instruction->fn_inline); |
| 17712 | 17711 | } else { |
| 17713 | 17712 | ir_add_error_node(ira, fn_ref->source_node, |
| 17714 | | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name))); |
| 17713 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name))); |
| 17715 | 17714 | return ira->codegen->invalid_instruction; |
| 17716 | 17715 | } |
| 17717 | 17716 | } |
| ... | ... | @@ -17803,11 +17802,11 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source |
| 17803 | 17802 | |
| 17804 | 17803 | static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 17805 | 17804 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 17806 | | result->value.special = ConstValSpecialLazy; |
| 17805 | result->value->special = ConstValSpecialLazy; |
| 17807 | 17806 | |
| 17808 | 17807 | LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1); |
| 17809 | 17808 | lazy_opt_type->ira = ira; |
| 17810 | | result->value.data.x_lazy = &lazy_opt_type->base; |
| 17809 | result->value->data.x_lazy = &lazy_opt_type->base; |
| 17811 | 17810 | lazy_opt_type->base.id = LazyValueIdOptType; |
| 17812 | 17811 | |
| 17813 | 17812 | lazy_opt_type->payload_type = instruction->value->child; |
| ... | ... | @@ -17854,7 +17853,7 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_i |
| 17854 | 17853 | |
| 17855 | 17854 | static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 17856 | 17855 | IrInstruction *value = instruction->value->child; |
| 17857 | | ZigType *expr_type = value->value.type; |
| 17856 | ZigType *expr_type = value->value->type; |
| 17858 | 17857 | if (type_is_invalid(expr_type)) |
| 17859 | 17858 | return ira->codegen->invalid_instruction; |
| 17860 | 17859 | |
| ... | ... | @@ -17877,7 +17876,7 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins |
| 17877 | 17876 | return ira->codegen->invalid_instruction; |
| 17878 | 17877 | |
| 17879 | 17878 | IrInstruction *result_instruction = ir_const(ira, &instruction->base, expr_type); |
| 17880 | | ZigValue *out_val = &result_instruction->value; |
| 17879 | ZigValue *out_val = result_instruction->value; |
| 17881 | 17880 | if (expr_type->id == ZigTypeIdVector) { |
| 17882 | 17881 | expand_undef_array(ira->codegen, operand_val); |
| 17883 | 17882 | out_val->special = ConstValSpecialUndef; |
| ... | ... | @@ -17911,13 +17910,13 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins |
| 17911 | 17910 | IrInstruction *result = ir_build_un_op(&ira->new_irb, |
| 17912 | 17911 | instruction->base.scope, instruction->base.source_node, |
| 17913 | 17912 | instruction->op_id, value); |
| 17914 | | result->value.type = expr_type; |
| 17913 | result->value->type = expr_type; |
| 17915 | 17914 | return result; |
| 17916 | 17915 | } |
| 17917 | 17916 | |
| 17918 | 17917 | static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 17919 | 17918 | IrInstruction *value = instruction->value->child; |
| 17920 | | ZigType *expr_type = value->value.type; |
| 17919 | ZigType *expr_type = value->value->type; |
| 17921 | 17920 | if (type_is_invalid(expr_type)) |
| 17922 | 17921 | return ira->codegen->invalid_instruction; |
| 17923 | 17922 | |
| ... | ... | @@ -17928,14 +17927,14 @@ static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *inst |
| 17928 | 17927 | return ira->codegen->invalid_instruction; |
| 17929 | 17928 | |
| 17930 | 17929 | IrInstruction *result = ir_const(ira, &instruction->base, expr_type); |
| 17931 | | bigint_not(&result->value.data.x_bigint, &target_const_val->data.x_bigint, |
| 17930 | bigint_not(&result->value->data.x_bigint, &target_const_val->data.x_bigint, |
| 17932 | 17931 | expr_type->data.integral.bit_count, expr_type->data.integral.is_signed); |
| 17933 | 17932 | return result; |
| 17934 | 17933 | } |
| 17935 | 17934 | |
| 17936 | 17935 | IrInstruction *result = ir_build_un_op(&ira->new_irb, instruction->base.scope, |
| 17937 | 17936 | instruction->base.source_node, IrUnOpBinNot, value); |
| 17938 | | result->value.type = expr_type; |
| 17937 | result->value->type = expr_type; |
| 17939 | 17938 | return result; |
| 17940 | 17939 | } |
| 17941 | 17940 | |
| ... | ... | @@ -17956,9 +17955,9 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction |
| 17956 | 17955 | return ir_analyze_negation(ira, instruction); |
| 17957 | 17956 | case IrUnOpDereference: { |
| 17958 | 17957 | IrInstruction *ptr = instruction->value->child; |
| 17959 | | if (type_is_invalid(ptr->value.type)) |
| 17958 | if (type_is_invalid(ptr->value->type)) |
| 17960 | 17959 | return ira->codegen->invalid_instruction; |
| 17961 | | ZigType *ptr_type = ptr->value.type; |
| 17960 | ZigType *ptr_type = ptr->value->type; |
| 17962 | 17961 | if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) { |
| 17963 | 17962 | ir_add_error_node(ira, instruction->base.source_node, |
| 17964 | 17963 | buf_sprintf("index syntax required for unknown-length pointer type '%s'", |
| ... | ... | @@ -17971,9 +17970,9 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction |
| 17971 | 17970 | return ira->codegen->invalid_instruction; |
| 17972 | 17971 | |
| 17973 | 17972 | // If the result needs to be an lvalue, type check it |
| 17974 | | if (instruction->lval == LValPtr && result->value.type->id != ZigTypeIdPointer) { |
| 17973 | if (instruction->lval == LValPtr && result->value->type->id != ZigTypeIdPointer) { |
| 17975 | 17974 | ir_add_error(ira, &instruction->base, |
| 17976 | | buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value.type->name))); |
| 17975 | buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name))); |
| 17977 | 17976 | return ira->codegen->invalid_instruction; |
| 17978 | 17977 | } |
| 17979 | 17978 | |
| ... | ... | @@ -18016,13 +18015,13 @@ static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr |
| 18016 | 18015 | |
| 18017 | 18016 | IrInstruction *result = ir_build_br(&ira->new_irb, |
| 18018 | 18017 | br_instruction->base.scope, br_instruction->base.source_node, new_bb, nullptr); |
| 18019 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 18018 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 18020 | 18019 | return ir_finish_anal(ira, result); |
| 18021 | 18020 | } |
| 18022 | 18021 | |
| 18023 | 18022 | static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) { |
| 18024 | 18023 | IrInstruction *condition = cond_br_instruction->condition->child; |
| 18025 | | if (type_is_invalid(condition->value.type)) |
| 18024 | if (type_is_invalid(condition->value->type)) |
| 18026 | 18025 | return ir_unreach_error(ira); |
| 18027 | 18026 | |
| 18028 | 18027 | bool is_comptime; |
| ... | ... | @@ -18031,7 +18030,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi |
| 18031 | 18030 | |
| 18032 | 18031 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 18033 | 18032 | IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type); |
| 18034 | | if (type_is_invalid(casted_condition->value.type)) |
| 18033 | if (type_is_invalid(casted_condition->value->type)) |
| 18035 | 18034 | return ir_unreach_error(ira); |
| 18036 | 18035 | |
| 18037 | 18036 | if (is_comptime || instr_is_comptime(casted_condition)) { |
| ... | ... | @@ -18053,7 +18052,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi |
| 18053 | 18052 | |
| 18054 | 18053 | IrInstruction *result = ir_build_br(&ira->new_irb, |
| 18055 | 18054 | cond_br_instruction->base.scope, cond_br_instruction->base.source_node, new_dest_block, nullptr); |
| 18056 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 18055 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 18057 | 18056 | return ir_finish_anal(ira, result); |
| 18058 | 18057 | } |
| 18059 | 18058 | |
| ... | ... | @@ -18072,7 +18071,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi |
| 18072 | 18071 | IrInstruction *result = ir_build_cond_br(&ira->new_irb, |
| 18073 | 18072 | cond_br_instruction->base.scope, cond_br_instruction->base.source_node, |
| 18074 | 18073 | casted_condition, new_then_block, new_else_block, nullptr); |
| 18075 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 18074 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 18076 | 18075 | return ir_finish_anal(ira, result); |
| 18077 | 18076 | } |
| 18078 | 18077 | |
| ... | ... | @@ -18081,7 +18080,7 @@ static IrInstruction *ir_analyze_instruction_unreachable(IrAnalyze *ira, |
| 18081 | 18080 | { |
| 18082 | 18081 | IrInstruction *result = ir_build_unreachable(&ira->new_irb, |
| 18083 | 18082 | unreachable_instruction->base.scope, unreachable_instruction->base.source_node); |
| 18084 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 18083 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 18085 | 18084 | return ir_finish_anal(ira, result); |
| 18086 | 18085 | } |
| 18087 | 18086 | |
| ... | ... | @@ -18094,13 +18093,13 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18094 | 18093 | if (predecessor != ira->const_predecessor_bb) |
| 18095 | 18094 | continue; |
| 18096 | 18095 | IrInstruction *value = phi_instruction->incoming_values[i]->child; |
| 18097 | | assert(value->value.type); |
| 18098 | | if (type_is_invalid(value->value.type)) |
| 18096 | assert(value->value->type); |
| 18097 | if (type_is_invalid(value->value->type)) |
| 18099 | 18098 | return ira->codegen->invalid_instruction; |
| 18100 | 18099 | |
| 18101 | | if (value->value.special != ConstValSpecialRuntime) { |
| 18100 | if (value->value->special != ConstValSpecialRuntime) { |
| 18102 | 18101 | IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr); |
| 18103 | | copy_const_val(&result->value, &value->value, true); |
| 18102 | copy_const_val(result->value, value->value, true); |
| 18104 | 18103 | return result; |
| 18105 | 18104 | } else { |
| 18106 | 18105 | return value; |
| ... | ... | @@ -18126,7 +18125,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18126 | 18125 | } else { |
| 18127 | 18126 | instructions[i] = ir_const(ira, this_peer->base.source_instruction, |
| 18128 | 18127 | this_peer->base.implicit_elem_type); |
| 18129 | | instructions[i]->value.special = ConstValSpecialRuntime; |
| 18128 | instructions[i]->value->special = ConstValSpecialRuntime; |
| 18130 | 18129 | } |
| 18131 | 18130 | } else { |
| 18132 | 18131 | instructions[i] = gen_instruction; |
| ... | ... | @@ -18147,7 +18146,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18147 | 18146 | IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent, |
| 18148 | 18147 | peer_parent->resolved_type, nullptr, false, false, true); |
| 18149 | 18148 | if (parent_result_loc != nullptr && |
| 18150 | | (type_is_invalid(parent_result_loc->value.type) || instr_is_unreachable(parent_result_loc))) |
| 18149 | (type_is_invalid(parent_result_loc->value->type) || instr_is_unreachable(parent_result_loc))) |
| 18151 | 18150 | { |
| 18152 | 18151 | return parent_result_loc; |
| 18153 | 18152 | } |
| ... | ... | @@ -18160,7 +18159,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18160 | 18159 | if (instrs_to_move.length != 0) { |
| 18161 | 18160 | IrBasicBlock *predecessor = peer_parent->base.source_instruction->child->owner_bb; |
| 18162 | 18161 | IrInstruction *branch_instruction = predecessor->instruction_list.pop(); |
| 18163 | | ir_assert(branch_instruction->value.type->id == ZigTypeIdUnreachable, &phi_instruction->base); |
| 18162 | ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base); |
| 18164 | 18163 | while (instrs_to_move.length != 0) { |
| 18165 | 18164 | predecessor->instruction_list.append(instrs_to_move.pop()); |
| 18166 | 18165 | } |
| ... | ... | @@ -18197,10 +18196,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18197 | 18196 | IrInstruction *old_value = phi_instruction->incoming_values[i]; |
| 18198 | 18197 | assert(old_value); |
| 18199 | 18198 | IrInstruction *new_value = old_value->child; |
| 18200 | | if (!new_value || new_value->value.type->id == ZigTypeIdUnreachable || predecessor->other == nullptr) |
| 18199 | if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->other == nullptr) |
| 18201 | 18200 | continue; |
| 18202 | 18201 | |
| 18203 | | if (type_is_invalid(new_value->value.type)) |
| 18202 | if (type_is_invalid(new_value->value->type)) |
| 18204 | 18203 | return ira->codegen->invalid_instruction; |
| 18205 | 18204 | |
| 18206 | 18205 | |
| ... | ... | @@ -18212,7 +18211,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18212 | 18211 | if (new_incoming_blocks.length == 0) { |
| 18213 | 18212 | IrInstruction *result = ir_build_unreachable(&ira->new_irb, |
| 18214 | 18213 | phi_instruction->base.scope, phi_instruction->base.source_node); |
| 18215 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 18214 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 18216 | 18215 | return ir_finish_anal(ira, result); |
| 18217 | 18216 | } |
| 18218 | 18217 | |
| ... | ... | @@ -18233,7 +18232,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18233 | 18232 | if (type_is_invalid(resolved_type)) |
| 18234 | 18233 | return ira->codegen->invalid_instruction; |
| 18235 | 18234 | } else { |
| 18236 | | ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value.type; |
| 18235 | ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type; |
| 18237 | 18236 | ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base); |
| 18238 | 18237 | resolved_type = resolved_loc_ptr_type->data.pointer.child_type; |
| 18239 | 18238 | } |
| ... | ... | @@ -18281,14 +18280,14 @@ skip_resolve_peer_types: |
| 18281 | 18280 | IrInstruction *branch_instruction = predecessor->instruction_list.pop(); |
| 18282 | 18281 | ir_set_cursor_at_end(&ira->new_irb, predecessor); |
| 18283 | 18282 | IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type); |
| 18284 | | if (type_is_invalid(casted_value->value.type)) { |
| 18283 | if (type_is_invalid(casted_value->value->type)) { |
| 18285 | 18284 | return ira->codegen->invalid_instruction; |
| 18286 | 18285 | } |
| 18287 | 18286 | new_incoming_values.items[i] = casted_value; |
| 18288 | 18287 | predecessor->instruction_list.append(branch_instruction); |
| 18289 | 18288 | |
| 18290 | | if (all_stack_ptrs && (casted_value->value.special != ConstValSpecialRuntime || |
| 18291 | | casted_value->value.data.rh_ptr != RuntimeHintPtrStack)) |
| 18289 | if (all_stack_ptrs && (casted_value->value->special != ConstValSpecialRuntime || |
| 18290 | casted_value->value->data.rh_ptr != RuntimeHintPtrStack)) |
| 18292 | 18291 | { |
| 18293 | 18292 | all_stack_ptrs = false; |
| 18294 | 18293 | } |
| ... | ... | @@ -18298,11 +18297,11 @@ skip_resolve_peer_types: |
| 18298 | 18297 | IrInstruction *result = ir_build_phi(&ira->new_irb, |
| 18299 | 18298 | phi_instruction->base.scope, phi_instruction->base.source_node, |
| 18300 | 18299 | new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, nullptr); |
| 18301 | | result->value.type = resolved_type; |
| 18300 | result->value->type = resolved_type; |
| 18302 | 18301 | |
| 18303 | 18302 | if (all_stack_ptrs) { |
| 18304 | | assert(result->value.special == ConstValSpecialRuntime); |
| 18305 | | result->value.data.rh_ptr = RuntimeHintPtrStack; |
| 18303 | assert(result->value->special == ConstValSpecialRuntime); |
| 18304 | result->value->data.rh_ptr = RuntimeHintPtrStack; |
| 18306 | 18305 | } |
| 18307 | 18306 | |
| 18308 | 18307 | return result; |
| ... | ... | @@ -18358,13 +18357,13 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { |
| 18358 | 18357 | static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { |
| 18359 | 18358 | Error err; |
| 18360 | 18359 | IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->child; |
| 18361 | | if (type_is_invalid(array_ptr->value.type)) |
| 18360 | if (type_is_invalid(array_ptr->value->type)) |
| 18362 | 18361 | return ira->codegen->invalid_instruction; |
| 18363 | 18362 | |
| 18364 | | ZigValue *orig_array_ptr_val = &array_ptr->value; |
| 18363 | ZigValue *orig_array_ptr_val = array_ptr->value; |
| 18365 | 18364 | |
| 18366 | 18365 | IrInstruction *elem_index = elem_ptr_instruction->elem_index->child; |
| 18367 | | if (type_is_invalid(elem_index->value.type)) |
| 18366 | if (type_is_invalid(elem_index->value->type)) |
| 18368 | 18367 | return ira->codegen->invalid_instruction; |
| 18369 | 18368 | |
| 18370 | 18369 | ZigType *ptr_type = orig_array_ptr_val->type; |
| ... | ... | @@ -18471,7 +18470,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18471 | 18470 | return ira->codegen->invalid_instruction; |
| 18472 | 18471 | ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base); |
| 18473 | 18472 | Buf *field_name = buf_alloc(); |
| 18474 | | bigint_append_buf(field_name, &casted_elem_index->value.data.x_bigint, 10); |
| 18473 | bigint_append_buf(field_name, &casted_elem_index->value->data.x_bigint, 10); |
| 18475 | 18474 | return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base, |
| 18476 | 18475 | array_ptr, array_type); |
| 18477 | 18476 | } else { |
| ... | ... | @@ -18487,13 +18486,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18487 | 18486 | |
| 18488 | 18487 | bool safety_check_on = elem_ptr_instruction->safety_check_on; |
| 18489 | 18488 | if (instr_is_comptime(casted_elem_index)) { |
| 18490 | | uint64_t index = bigint_as_u64(&casted_elem_index->value.data.x_bigint); |
| 18489 | uint64_t index = bigint_as_u64(&casted_elem_index->value->data.x_bigint); |
| 18491 | 18490 | if (array_type->id == ZigTypeIdArray) { |
| 18492 | 18491 | uint64_t array_len = array_type->data.array.len; |
| 18493 | 18492 | if (index == array_len && array_type->data.array.sentinel != nullptr) { |
| 18494 | 18493 | ZigType *elem_type = array_type->data.array.child_type; |
| 18495 | 18494 | IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type); |
| 18496 | | copy_const_val(&sentinel_elem->value, array_type->data.array.sentinel, false); |
| 18495 | copy_const_val(sentinel_elem->value, array_type->data.array.sentinel, false); |
| 18497 | 18496 | return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false); |
| 18498 | 18497 | } |
| 18499 | 18498 | if (index >= array_len) { |
| ... | ... | @@ -18565,8 +18564,8 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18565 | 18564 | elem_val->parent.data.p_array.elem_index = i; |
| 18566 | 18565 | } |
| 18567 | 18566 | } else if (is_slice(array_type)) { |
| 18568 | | ir_assert(array_ptr->value.type->id == ZigTypeIdPointer, &elem_ptr_instruction->base); |
| 18569 | | ZigType *actual_array_type = array_ptr->value.type->data.pointer.child_type; |
| 18567 | ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base); |
| 18568 | ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type; |
| 18570 | 18569 | |
| 18571 | 18570 | if (type_is_invalid(actual_array_type)) |
| 18572 | 18571 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -18608,7 +18607,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18608 | 18607 | { |
| 18609 | 18608 | if (array_type->id == ZigTypeIdPointer) { |
| 18610 | 18609 | IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 18611 | | ZigValue *out_val = &result->value; |
| 18610 | ZigValue *out_val = result->value; |
| 18612 | 18611 | out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; |
| 18613 | 18612 | size_t new_index; |
| 18614 | 18613 | size_t mem_size; |
| ... | ... | @@ -18688,12 +18687,12 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18688 | 18687 | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, |
| 18689 | 18688 | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false, |
| 18690 | 18689 | elem_ptr_instruction->ptr_len, nullptr); |
| 18691 | | result->value.type = return_type; |
| 18690 | result->value->type = return_type; |
| 18692 | 18691 | return result; |
| 18693 | 18692 | } |
| 18694 | 18693 | ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index]; |
| 18695 | 18694 | IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 18696 | | ZigValue *out_val = &result->value; |
| 18695 | ZigValue *out_val = result->value; |
| 18697 | 18696 | ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 18698 | 18697 | uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint); |
| 18699 | 18698 | uint64_t full_slice_len = slice_len + |
| ... | ... | @@ -18752,12 +18751,12 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18752 | 18751 | result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, |
| 18753 | 18752 | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, |
| 18754 | 18753 | false, elem_ptr_instruction->ptr_len, nullptr); |
| 18755 | | result->value.type = return_type; |
| 18756 | | result->value.special = ConstValSpecialStatic; |
| 18754 | result->value->type = return_type; |
| 18755 | result->value->special = ConstValSpecialStatic; |
| 18757 | 18756 | } else { |
| 18758 | 18757 | result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 18759 | 18758 | } |
| 18760 | | ZigValue *out_val = &result->value; |
| 18759 | ZigValue *out_val = result->value; |
| 18761 | 18760 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 18762 | 18761 | out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut; |
| 18763 | 18762 | out_val->data.x_ptr.data.base_array.array_val = array_ptr_val; |
| ... | ... | @@ -18814,7 +18813,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18814 | 18813 | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, |
| 18815 | 18814 | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on, |
| 18816 | 18815 | elem_ptr_instruction->ptr_len, nullptr); |
| 18817 | | result->value.type = return_type; |
| 18816 | result->value->type = return_type; |
| 18818 | 18817 | return result; |
| 18819 | 18818 | } |
| 18820 | 18819 | |
| ... | ... | @@ -18892,8 +18891,8 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 18892 | 18891 | case OnePossibleValueNo: |
| 18893 | 18892 | break; |
| 18894 | 18893 | } |
| 18895 | | bool is_const = struct_ptr->value.type->data.pointer.is_const; |
| 18896 | | bool is_volatile = struct_ptr->value.type->data.pointer.is_volatile; |
| 18894 | bool is_const = struct_ptr->value->type->data.pointer.is_const; |
| 18895 | bool is_volatile = struct_ptr->value->type->data.pointer.is_volatile; |
| 18897 | 18896 | ZigType *ptr_type; |
| 18898 | 18897 | if (struct_type->data.structure.is_inferred) { |
| 18899 | 18898 | ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, |
| ... | ... | @@ -18904,9 +18903,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 18904 | 18903 | ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown; |
| 18905 | 18904 | if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status))) |
| 18906 | 18905 | return ira->codegen->invalid_instruction; |
| 18907 | | assert(struct_ptr->value.type->id == ZigTypeIdPointer); |
| 18908 | | uint32_t ptr_bit_offset = struct_ptr->value.type->data.pointer.bit_offset_in_host; |
| 18909 | | uint32_t ptr_host_int_bytes = struct_ptr->value.type->data.pointer.host_int_bytes; |
| 18906 | assert(struct_ptr->value->type->id == ZigTypeIdPointer); |
| 18907 | uint32_t ptr_bit_offset = struct_ptr->value->type->data.pointer.bit_offset_in_host; |
| 18908 | uint32_t ptr_host_int_bytes = struct_ptr->value->type->data.pointer.host_int_bytes; |
| 18910 | 18909 | uint32_t host_int_bytes_for_result_type = (ptr_host_int_bytes == 0) ? |
| 18911 | 18910 | get_host_int_bytes(ira->codegen, struct_type, field) : ptr_host_int_bytes; |
| 18912 | 18911 | ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, |
| ... | ... | @@ -18942,12 +18941,12 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 18942 | 18941 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 18943 | 18942 | result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, |
| 18944 | 18943 | source_instr->source_node, struct_ptr, field); |
| 18945 | | result->value.type = ptr_type; |
| 18946 | | result->value.special = ConstValSpecialStatic; |
| 18944 | result->value->type = ptr_type; |
| 18945 | result->value->special = ConstValSpecialStatic; |
| 18947 | 18946 | } else { |
| 18948 | 18947 | result = ir_const(ira, source_instr, ptr_type); |
| 18949 | 18948 | } |
| 18950 | | ZigValue *const_val = &result->value; |
| 18949 | ZigValue *const_val = result->value; |
| 18951 | 18950 | const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct; |
| 18952 | 18951 | const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut; |
| 18953 | 18952 | const_val->data.x_ptr.data.base_struct.struct_val = struct_val; |
| ... | ... | @@ -18957,7 +18956,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 18957 | 18956 | } |
| 18958 | 18957 | IrInstruction *result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, |
| 18959 | 18958 | struct_ptr, field); |
| 18960 | | result->value.type = ptr_type; |
| 18959 | result->value->type = ptr_type; |
| 18961 | 18960 | return result; |
| 18962 | 18961 | } |
| 18963 | 18962 | |
| ... | ... | @@ -18970,7 +18969,7 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n |
| 18970 | 18969 | // the field type will then be available, and the field will be added to the inferred |
| 18971 | 18970 | // struct. |
| 18972 | 18971 | |
| 18973 | | ZigType *container_ptr_type = container_ptr->value.type; |
| 18972 | ZigType *container_ptr_type = container_ptr->value->type; |
| 18974 | 18973 | ir_assert(container_ptr_type->id == ZigTypeIdPointer, source_instr); |
| 18975 | 18974 | |
| 18976 | 18975 | InferredStructField *inferred_struct_field = allocate<InferredStructField>(1, "InferredStructField"); |
| ... | ... | @@ -18984,14 +18983,14 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n |
| 18984 | 18983 | |
| 18985 | 18984 | if (instr_is_comptime(container_ptr)) { |
| 18986 | 18985 | IrInstruction *result = ir_const(ira, source_instr, field_ptr_type); |
| 18987 | | copy_const_val(&result->value, &container_ptr->value, false); |
| 18988 | | result->value.type = field_ptr_type; |
| 18986 | copy_const_val(result->value, container_ptr->value, false); |
| 18987 | result->value->type = field_ptr_type; |
| 18989 | 18988 | return result; |
| 18990 | 18989 | } |
| 18991 | 18990 | |
| 18992 | 18991 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, |
| 18993 | 18992 | source_instr->source_node, field_ptr_type, container_ptr, CastOpNoop); |
| 18994 | | result->value.type = field_ptr_type; |
| 18993 | result->value->type = field_ptr_type; |
| 18995 | 18994 | return result; |
| 18996 | 18995 | } |
| 18997 | 18996 | |
| ... | ... | @@ -19011,7 +19010,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 19011 | 19010 | if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown))) |
| 19012 | 19011 | return ira->codegen->invalid_instruction; |
| 19013 | 19012 | |
| 19014 | | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 19013 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 19015 | 19014 | if (bare_type->id == ZigTypeIdStruct) { |
| 19016 | 19015 | TypeStructField *field = find_struct_type_field(bare_type, field_name); |
| 19017 | 19016 | if (field != nullptr) { |
| ... | ... | @@ -19028,8 +19027,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 19028 | 19027 | } |
| 19029 | 19028 | |
| 19030 | 19029 | if (bare_type->id == ZigTypeIdUnion) { |
| 19031 | | bool is_const = container_ptr->value.type->data.pointer.is_const; |
| 19032 | | bool is_volatile = container_ptr->value.type->data.pointer.is_volatile; |
| 19030 | bool is_const = container_ptr->value->type->data.pointer.is_const; |
| 19031 | bool is_volatile = container_ptr->value->type->data.pointer.is_volatile; |
| 19033 | 19032 | |
| 19034 | 19033 | TypeUnionField *field = find_union_type_field(bare_type, field_name); |
| 19035 | 19034 | if (field == nullptr) { |
| ... | ... | @@ -19085,14 +19084,14 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 19085 | 19084 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 19086 | 19085 | result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, |
| 19087 | 19086 | source_instr->source_node, container_ptr, field, true, initializing); |
| 19088 | | result->value.type = ptr_type; |
| 19089 | | result->value.special = ConstValSpecialStatic; |
| 19087 | result->value->type = ptr_type; |
| 19088 | result->value->special = ConstValSpecialStatic; |
| 19090 | 19089 | } else { |
| 19091 | 19090 | result = ir_const(ira, source_instr, ptr_type); |
| 19092 | 19091 | } |
| 19093 | | ZigValue *const_val = &result->value; |
| 19092 | ZigValue *const_val = result->value; |
| 19094 | 19093 | const_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 19095 | | const_val->data.x_ptr.mut = container_ptr->value.data.x_ptr.mut; |
| 19094 | const_val->data.x_ptr.mut = container_ptr->value->data.x_ptr.mut; |
| 19096 | 19095 | const_val->data.x_ptr.data.ref.pointee = payload_val; |
| 19097 | 19096 | return result; |
| 19098 | 19097 | } |
| ... | ... | @@ -19100,7 +19099,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 19100 | 19099 | |
| 19101 | 19100 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, |
| 19102 | 19101 | source_instr->source_node, container_ptr, field, true, initializing); |
| 19103 | | result->value.type = ptr_type; |
| 19102 | result->value->type = ptr_type; |
| 19104 | 19103 | return result; |
| 19105 | 19104 | } |
| 19106 | 19105 | |
| ... | ... | @@ -19205,10 +19204,10 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n |
| 19205 | 19204 | static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) { |
| 19206 | 19205 | Error err; |
| 19207 | 19206 | IrInstruction *container_ptr = field_ptr_instruction->container_ptr->child; |
| 19208 | | if (type_is_invalid(container_ptr->value.type)) |
| 19207 | if (type_is_invalid(container_ptr->value->type)) |
| 19209 | 19208 | return ira->codegen->invalid_instruction; |
| 19210 | 19209 | |
| 19211 | | ZigType *container_type = container_ptr->value.type->data.pointer.child_type; |
| 19210 | ZigType *container_type = container_ptr->value->type->data.pointer.child_type; |
| 19212 | 19211 | |
| 19213 | 19212 | Buf *field_name = field_ptr_instruction->field_name_buffer; |
| 19214 | 19213 | if (!field_name) { |
| ... | ... | @@ -19224,7 +19223,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 19224 | 19223 | if (type_is_invalid(container_type)) { |
| 19225 | 19224 | return ira->codegen->invalid_instruction; |
| 19226 | 19225 | } else if (is_slice(container_type) || is_container_ref(container_type)) { |
| 19227 | | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 19226 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 19228 | 19227 | if (container_type->id == ZigTypeIdPointer) { |
| 19229 | 19228 | ZigType *bare_type = container_ref_type(container_type); |
| 19230 | 19229 | IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr, nullptr); |
| ... | ... | @@ -19259,7 +19258,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 19259 | 19258 | if (!container_ptr_val) |
| 19260 | 19259 | return ira->codegen->invalid_instruction; |
| 19261 | 19260 | |
| 19262 | | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 19261 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 19263 | 19262 | ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node); |
| 19264 | 19263 | if (child_val == nullptr) |
| 19265 | 19264 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -19285,7 +19284,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 19285 | 19284 | if (!container_ptr_val) |
| 19286 | 19285 | return ira->codegen->invalid_instruction; |
| 19287 | 19286 | |
| 19288 | | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 19287 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 19289 | 19288 | ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node); |
| 19290 | 19289 | if (child_val == nullptr) |
| 19291 | 19290 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -19567,11 +19566,11 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 19567 | 19566 | |
| 19568 | 19567 | static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *instruction) { |
| 19569 | 19568 | IrInstruction *ptr = instruction->ptr->child; |
| 19570 | | if (type_is_invalid(ptr->value.type)) |
| 19569 | if (type_is_invalid(ptr->value->type)) |
| 19571 | 19570 | return ira->codegen->invalid_instruction; |
| 19572 | 19571 | |
| 19573 | 19572 | IrInstruction *value = instruction->value->child; |
| 19574 | | if (type_is_invalid(value->value.type)) |
| 19573 | if (type_is_invalid(value->value->type)) |
| 19575 | 19574 | return ira->codegen->invalid_instruction; |
| 19576 | 19575 | |
| 19577 | 19576 | return ir_analyze_store_ptr(ira, &instruction->base, ptr, value, instruction->allow_write_through_const); |
| ... | ... | @@ -19579,14 +19578,14 @@ static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstruc |
| 19579 | 19578 | |
| 19580 | 19579 | static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) { |
| 19581 | 19580 | IrInstruction *ptr = instruction->ptr->child; |
| 19582 | | if (type_is_invalid(ptr->value.type)) |
| 19581 | if (type_is_invalid(ptr->value->type)) |
| 19583 | 19582 | return ira->codegen->invalid_instruction; |
| 19584 | 19583 | return ir_get_deref(ira, &instruction->base, ptr, nullptr); |
| 19585 | 19584 | } |
| 19586 | 19585 | |
| 19587 | 19586 | static IrInstruction *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) { |
| 19588 | 19587 | IrInstruction *expr_value = typeof_instruction->value->child; |
| 19589 | | ZigType *type_entry = expr_value->value.type; |
| 19588 | ZigType *type_entry = expr_value->value->type; |
| 19590 | 19589 | if (type_is_invalid(type_entry)) |
| 19591 | 19590 | return ira->codegen->invalid_instruction; |
| 19592 | 19591 | return ir_const_type(ira, &typeof_instruction->base, type_entry); |
| ... | ... | @@ -19749,11 +19748,11 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 19749 | 19748 | IrInstructionSliceType *slice_type_instruction) |
| 19750 | 19749 | { |
| 19751 | 19750 | IrInstruction *result = ir_const(ira, &slice_type_instruction->base, ira->codegen->builtin_types.entry_type); |
| 19752 | | result->value.special = ConstValSpecialLazy; |
| 19751 | result->value->special = ConstValSpecialLazy; |
| 19753 | 19752 | |
| 19754 | 19753 | LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1); |
| 19755 | 19754 | lazy_slice_type->ira = ira; |
| 19756 | | result->value.data.x_lazy = &lazy_slice_type->base; |
| 19755 | result->value->data.x_lazy = &lazy_slice_type->base; |
| 19757 | 19756 | lazy_slice_type->base.id = LazyValueIdSliceType; |
| 19758 | 19757 | |
| 19759 | 19758 | if (slice_type_instruction->align_value != nullptr) { |
| ... | ... | @@ -19812,14 +19811,14 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs |
| 19812 | 19811 | |
| 19813 | 19812 | for (size_t i = 0; i < asm_expr->input_list.length; i += 1) { |
| 19814 | 19813 | IrInstruction *const input_value = asm_instruction->input_list[i]->child; |
| 19815 | | if (type_is_invalid(input_value->value.type)) |
| 19814 | if (type_is_invalid(input_value->value->type)) |
| 19816 | 19815 | return ira->codegen->invalid_instruction; |
| 19817 | 19816 | |
| 19818 | 19817 | if (instr_is_comptime(input_value) && |
| 19819 | | (input_value->value.type->id == ZigTypeIdComptimeInt || |
| 19820 | | input_value->value.type->id == ZigTypeIdComptimeFloat)) { |
| 19818 | (input_value->value->type->id == ZigTypeIdComptimeInt || |
| 19819 | input_value->value->type->id == ZigTypeIdComptimeFloat)) { |
| 19821 | 19820 | ir_add_error_node(ira, input_value->source_node, |
| 19822 | | buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value.type->name))); |
| 19821 | buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name))); |
| 19823 | 19822 | return ira->codegen->invalid_instruction; |
| 19824 | 19823 | } |
| 19825 | 19824 | |
| ... | ... | @@ -19831,7 +19830,7 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs |
| 19831 | 19830 | asm_instruction->asm_template, asm_instruction->token_list, asm_instruction->token_list_len, |
| 19832 | 19831 | input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count, |
| 19833 | 19832 | asm_instruction->has_side_effects); |
| 19834 | | result->value.type = return_type; |
| 19833 | result->value->type = return_type; |
| 19835 | 19834 | return result; |
| 19836 | 19835 | } |
| 19837 | 19836 | |
| ... | ... | @@ -19853,10 +19852,10 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 19853 | 19852 | ZigValue *sentinel_val; |
| 19854 | 19853 | if (array_type_instruction->sentinel != nullptr) { |
| 19855 | 19854 | IrInstruction *uncasted_sentinel = array_type_instruction->sentinel->child; |
| 19856 | | if (type_is_invalid(uncasted_sentinel->value.type)) |
| 19855 | if (type_is_invalid(uncasted_sentinel->value->type)) |
| 19857 | 19856 | return ira->codegen->invalid_instruction; |
| 19858 | 19857 | IrInstruction *sentinel = ir_implicit_cast(ira, uncasted_sentinel, child_type); |
| 19859 | | if (type_is_invalid(sentinel->value.type)) |
| 19858 | if (type_is_invalid(sentinel->value->type)) |
| 19860 | 19859 | return ira->codegen->invalid_instruction; |
| 19861 | 19860 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| 19862 | 19861 | if (sentinel_val == nullptr) |
| ... | ... | @@ -19909,11 +19908,11 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 19909 | 19908 | |
| 19910 | 19909 | static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructionSizeOf *instruction) { |
| 19911 | 19910 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 19912 | | result->value.special = ConstValSpecialLazy; |
| 19911 | result->value->special = ConstValSpecialLazy; |
| 19913 | 19912 | |
| 19914 | 19913 | LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1); |
| 19915 | 19914 | lazy_size_of->ira = ira; |
| 19916 | | result->value.data.x_lazy = &lazy_size_of->base; |
| 19915 | result->value->data.x_lazy = &lazy_size_of->base; |
| 19917 | 19916 | lazy_size_of->base.id = LazyValueIdSizeOf; |
| 19918 | 19917 | |
| 19919 | 19918 | lazy_size_of->target_type = instruction->type_value->child; |
| ... | ... | @@ -19924,7 +19923,7 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi |
| 19924 | 19923 | } |
| 19925 | 19924 | |
| 19926 | 19925 | static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value) { |
| 19927 | | ZigType *type_entry = value->value.type; |
| 19926 | ZigType *type_entry = value->value->type; |
| 19928 | 19927 | |
| 19929 | 19928 | if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) { |
| 19930 | 19929 | if (instr_is_comptime(value)) { |
| ... | ... | @@ -19941,7 +19940,7 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so |
| 19941 | 19940 | |
| 19942 | 19941 | IrInstruction *result = ir_build_test_nonnull(&ira->new_irb, |
| 19943 | 19942 | source_inst->scope, source_inst->source_node, value); |
| 19944 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 19943 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 19945 | 19944 | return result; |
| 19946 | 19945 | } else if (type_entry->id == ZigTypeIdOptional) { |
| 19947 | 19946 | if (instr_is_comptime(value)) { |
| ... | ... | @@ -19956,7 +19955,7 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so |
| 19956 | 19955 | |
| 19957 | 19956 | IrInstruction *result = ir_build_test_nonnull(&ira->new_irb, |
| 19958 | 19957 | source_inst->scope, source_inst->source_node, value); |
| 19959 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 19958 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 19960 | 19959 | return result; |
| 19961 | 19960 | } else if (type_entry->id == ZigTypeIdNull) { |
| 19962 | 19961 | return ir_const_bool(ira, source_inst, false); |
| ... | ... | @@ -19967,23 +19966,23 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so |
| 19967 | 19966 | |
| 19968 | 19967 | static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) { |
| 19969 | 19968 | IrInstruction *value = instruction->value->child; |
| 19970 | | if (type_is_invalid(value->value.type)) |
| 19969 | if (type_is_invalid(value->value->type)) |
| 19971 | 19970 | return ira->codegen->invalid_instruction; |
| 19972 | 19971 | |
| 19973 | 19972 | return ir_analyze_test_non_null(ira, &instruction->base, value); |
| 19974 | 19973 | } |
| 19975 | 19974 | |
| 19976 | 19975 | static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) { |
| 19977 | | ir_assert(ptr->value.type->id == ZigTypeIdPointer, ptr); |
| 19978 | | ZigType *elem_type = ptr->value.type->data.pointer.child_type; |
| 19976 | ir_assert(ptr->value->type->id == ZigTypeIdPointer, ptr); |
| 19977 | ZigType *elem_type = ptr->value->type->data.pointer.child_type; |
| 19979 | 19978 | if (elem_type != g->builtin_types.entry_var) |
| 19980 | 19979 | return elem_type; |
| 19981 | 19980 | |
| 19982 | | if (ir_resolve_lazy(g, ptr->source_node, &ptr->value)) |
| 19981 | if (ir_resolve_lazy(g, ptr->source_node, ptr->value)) |
| 19983 | 19982 | return g->builtin_types.entry_invalid; |
| 19984 | 19983 | |
| 19985 | | assert(value_is_comptime(&ptr->value)); |
| 19986 | | ZigValue *pointee = const_ptr_pointee_unchecked(g, &ptr->value); |
| 19984 | assert(value_is_comptime(ptr->value)); |
| 19985 | ZigValue *pointee = const_ptr_pointee_unchecked(g, ptr->value); |
| 19987 | 19986 | return pointee->type; |
| 19988 | 19987 | } |
| 19989 | 19988 | |
| ... | ... | @@ -20028,7 +20027,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 20028 | 20027 | |
| 20029 | 20028 | ZigType *child_type = type_entry->data.maybe.child_type; |
| 20030 | 20029 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 20031 | | base_ptr->value.type->data.pointer.is_const, base_ptr->value.type->data.pointer.is_volatile, |
| 20030 | base_ptr->value->type->data.pointer.is_const, base_ptr->value->type->data.pointer.is_volatile, |
| 20032 | 20031 | PtrLenSingle, 0, 0, 0, false); |
| 20033 | 20032 | |
| 20034 | 20033 | bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, child_type, type_entry); |
| ... | ... | @@ -20079,12 +20078,12 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 20079 | 20078 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 20080 | 20079 | result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope, |
| 20081 | 20080 | source_instr->source_node, base_ptr, false, initializing); |
| 20082 | | result->value.type = result_type; |
| 20083 | | result->value.special = ConstValSpecialStatic; |
| 20081 | result->value->type = result_type; |
| 20082 | result->value->special = ConstValSpecialStatic; |
| 20084 | 20083 | } else { |
| 20085 | 20084 | result = ir_const(ira, source_instr, result_type); |
| 20086 | 20085 | } |
| 20087 | | ZigValue *result_val = &result->value; |
| 20086 | ZigValue *result_val = result->value; |
| 20088 | 20087 | result_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 20089 | 20088 | result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut; |
| 20090 | 20089 | switch (type_has_one_possible_value(ira->codegen, child_type)) { |
| ... | ... | @@ -20109,7 +20108,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 20109 | 20108 | |
| 20110 | 20109 | IrInstruction *result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope, |
| 20111 | 20110 | source_instr->source_node, base_ptr, safety_check_on, initializing); |
| 20112 | | result->value.type = result_type; |
| 20111 | result->value->type = result_type; |
| 20113 | 20112 | return result; |
| 20114 | 20113 | } |
| 20115 | 20114 | |
| ... | ... | @@ -20117,7 +20116,7 @@ static IrInstruction *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira, |
| 20117 | 20116 | IrInstructionOptionalUnwrapPtr *instruction) |
| 20118 | 20117 | { |
| 20119 | 20118 | IrInstruction *base_ptr = instruction->base_ptr->child; |
| 20120 | | if (type_is_invalid(base_ptr->value.type)) |
| 20119 | if (type_is_invalid(base_ptr->value->type)) |
| 20121 | 20120 | return ira->codegen->invalid_instruction; |
| 20122 | 20121 | |
| 20123 | 20122 | return ir_analyze_unwrap_optional_payload(ira, &instruction->base, base_ptr, |
| ... | ... | @@ -20130,7 +20129,7 @@ static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCt |
| 20130 | 20129 | return ira->codegen->invalid_instruction; |
| 20131 | 20130 | |
| 20132 | 20131 | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 20133 | | if (type_is_invalid(op->value.type)) |
| 20132 | if (type_is_invalid(op->value->type)) |
| 20134 | 20133 | return ira->codegen->invalid_instruction; |
| 20135 | 20134 | |
| 20136 | 20135 | if (int_type->data.integral.bit_count == 0) |
| ... | ... | @@ -20142,14 +20141,14 @@ static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCt |
| 20142 | 20141 | return ira->codegen->invalid_instruction; |
| 20143 | 20142 | if (val->special == ConstValSpecialUndef) |
| 20144 | 20143 | return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 20145 | | size_t result_usize = bigint_ctz(&op->value.data.x_bigint, int_type->data.integral.bit_count); |
| 20144 | size_t result_usize = bigint_ctz(&op->value->data.x_bigint, int_type->data.integral.bit_count); |
| 20146 | 20145 | return ir_const_unsigned(ira, &instruction->base, result_usize); |
| 20147 | 20146 | } |
| 20148 | 20147 | |
| 20149 | 20148 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); |
| 20150 | 20149 | IrInstruction *result = ir_build_ctz(&ira->new_irb, instruction->base.scope, |
| 20151 | 20150 | instruction->base.source_node, nullptr, op); |
| 20152 | | result->value.type = return_type; |
| 20151 | result->value->type = return_type; |
| 20153 | 20152 | return result; |
| 20154 | 20153 | } |
| 20155 | 20154 | |
| ... | ... | @@ -20159,7 +20158,7 @@ static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionCl |
| 20159 | 20158 | return ira->codegen->invalid_instruction; |
| 20160 | 20159 | |
| 20161 | 20160 | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 20162 | | if (type_is_invalid(op->value.type)) |
| 20161 | if (type_is_invalid(op->value->type)) |
| 20163 | 20162 | return ira->codegen->invalid_instruction; |
| 20164 | 20163 | |
| 20165 | 20164 | if (int_type->data.integral.bit_count == 0) |
| ... | ... | @@ -20171,14 +20170,14 @@ static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionCl |
| 20171 | 20170 | return ira->codegen->invalid_instruction; |
| 20172 | 20171 | if (val->special == ConstValSpecialUndef) |
| 20173 | 20172 | return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 20174 | | size_t result_usize = bigint_clz(&op->value.data.x_bigint, int_type->data.integral.bit_count); |
| 20173 | size_t result_usize = bigint_clz(&op->value->data.x_bigint, int_type->data.integral.bit_count); |
| 20175 | 20174 | return ir_const_unsigned(ira, &instruction->base, result_usize); |
| 20176 | 20175 | } |
| 20177 | 20176 | |
| 20178 | 20177 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); |
| 20179 | 20178 | IrInstruction *result = ir_build_clz(&ira->new_irb, instruction->base.scope, |
| 20180 | 20179 | instruction->base.source_node, nullptr, op); |
| 20181 | | result->value.type = return_type; |
| 20180 | result->value->type = return_type; |
| 20182 | 20181 | return result; |
| 20183 | 20182 | } |
| 20184 | 20183 | |
| ... | ... | @@ -20188,7 +20187,7 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc |
| 20188 | 20187 | return ira->codegen->invalid_instruction; |
| 20189 | 20188 | |
| 20190 | 20189 | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 20191 | | if (type_is_invalid(op->value.type)) |
| 20190 | if (type_is_invalid(op->value->type)) |
| 20192 | 20191 | return ira->codegen->invalid_instruction; |
| 20193 | 20192 | |
| 20194 | 20193 | if (int_type->data.integral.bit_count == 0) |
| ... | ... | @@ -20212,33 +20211,33 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc |
| 20212 | 20211 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); |
| 20213 | 20212 | IrInstruction *result = ir_build_pop_count(&ira->new_irb, instruction->base.scope, |
| 20214 | 20213 | instruction->base.source_node, nullptr, op); |
| 20215 | | result->value.type = return_type; |
| 20214 | result->value->type = return_type; |
| 20216 | 20215 | return result; |
| 20217 | 20216 | } |
| 20218 | 20217 | |
| 20219 | 20218 | static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) { |
| 20220 | | if (type_is_invalid(value->value.type)) |
| 20219 | if (type_is_invalid(value->value->type)) |
| 20221 | 20220 | return ira->codegen->invalid_instruction; |
| 20222 | 20221 | |
| 20223 | | if (value->value.type->id == ZigTypeIdEnum) { |
| 20222 | if (value->value->type->id == ZigTypeIdEnum) { |
| 20224 | 20223 | return value; |
| 20225 | 20224 | } |
| 20226 | 20225 | |
| 20227 | | if (value->value.type->id != ZigTypeIdUnion) { |
| 20226 | if (value->value->type->id != ZigTypeIdUnion) { |
| 20228 | 20227 | ir_add_error(ira, value, |
| 20229 | | buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name))); |
| 20228 | buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name))); |
| 20230 | 20229 | return ira->codegen->invalid_instruction; |
| 20231 | 20230 | } |
| 20232 | | if (!value->value.type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) { |
| 20231 | if (!value->value->type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) { |
| 20233 | 20232 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum")); |
| 20234 | | if (value->value.type->data.unionation.decl_node != nullptr) { |
| 20235 | | add_error_note(ira->codegen, msg, value->value.type->data.unionation.decl_node, |
| 20233 | if (value->value->type->data.unionation.decl_node != nullptr) { |
| 20234 | add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node, |
| 20236 | 20235 | buf_sprintf("declared here")); |
| 20237 | 20236 | } |
| 20238 | 20237 | return ira->codegen->invalid_instruction; |
| 20239 | 20238 | } |
| 20240 | 20239 | |
| 20241 | | ZigType *tag_type = value->value.type->data.unionation.tag_type; |
| 20240 | ZigType *tag_type = value->value->type->data.unionation.tag_type; |
| 20242 | 20241 | assert(tag_type->id == ZigTypeIdEnum); |
| 20243 | 20242 | |
| 20244 | 20243 | if (instr_is_comptime(value)) { |
| ... | ... | @@ -20248,14 +20247,14 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source |
| 20248 | 20247 | |
| 20249 | 20248 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 20250 | 20249 | source_instr->scope, source_instr->source_node); |
| 20251 | | const_instruction->base.value.type = tag_type; |
| 20252 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 20253 | | bigint_init_bigint(&const_instruction->base.value.data.x_enum_tag, &val->data.x_union.tag); |
| 20250 | const_instruction->base.value->type = tag_type; |
| 20251 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 20252 | bigint_init_bigint(&const_instruction->base.value->data.x_enum_tag, &val->data.x_union.tag); |
| 20254 | 20253 | return &const_instruction->base; |
| 20255 | 20254 | } |
| 20256 | 20255 | |
| 20257 | 20256 | IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope, source_instr->source_node, value); |
| 20258 | | result->value.type = tag_type; |
| 20257 | result->value->type = tag_type; |
| 20259 | 20258 | return result; |
| 20260 | 20259 | } |
| 20261 | 20260 | |
| ... | ... | @@ -20263,11 +20262,11 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 20263 | 20262 | IrInstructionSwitchBr *switch_br_instruction) |
| 20264 | 20263 | { |
| 20265 | 20264 | IrInstruction *target_value = switch_br_instruction->target_value->child; |
| 20266 | | if (type_is_invalid(target_value->value.type)) |
| 20265 | if (type_is_invalid(target_value->value->type)) |
| 20267 | 20266 | return ir_unreach_error(ira); |
| 20268 | 20267 | |
| 20269 | 20268 | if (switch_br_instruction->switch_prongs_void != nullptr) { |
| 20270 | | if (type_is_invalid(switch_br_instruction->switch_prongs_void->child->value.type)) { |
| 20269 | if (type_is_invalid(switch_br_instruction->switch_prongs_void->child->value->type)) { |
| 20271 | 20270 | return ir_unreach_error(ira); |
| 20272 | 20271 | } |
| 20273 | 20272 | } |
| ... | ... | @@ -20288,17 +20287,17 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 20288 | 20287 | for (size_t i = 0; i < case_count; i += 1) { |
| 20289 | 20288 | IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i]; |
| 20290 | 20289 | IrInstruction *case_value = old_case->value->child; |
| 20291 | | if (type_is_invalid(case_value->value.type)) |
| 20290 | if (type_is_invalid(case_value->value->type)) |
| 20292 | 20291 | return ir_unreach_error(ira); |
| 20293 | 20292 | |
| 20294 | | if (case_value->value.type->id == ZigTypeIdEnum) { |
| 20293 | if (case_value->value->type->id == ZigTypeIdEnum) { |
| 20295 | 20294 | case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value); |
| 20296 | | if (type_is_invalid(case_value->value.type)) |
| 20295 | if (type_is_invalid(case_value->value->type)) |
| 20297 | 20296 | return ir_unreach_error(ira); |
| 20298 | 20297 | } |
| 20299 | 20298 | |
| 20300 | | IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value.type); |
| 20301 | | if (type_is_invalid(casted_case_value->value.type)) |
| 20299 | IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type); |
| 20300 | if (type_is_invalid(casted_case_value->value->type)) |
| 20302 | 20301 | return ir_unreach_error(ira); |
| 20303 | 20302 | |
| 20304 | 20303 | ZigValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad); |
| ... | ... | @@ -20318,7 +20317,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 20318 | 20317 | IrInstruction *result = ir_build_br(&ira->new_irb, |
| 20319 | 20318 | switch_br_instruction->base.scope, switch_br_instruction->base.source_node, |
| 20320 | 20319 | new_dest_block, nullptr); |
| 20321 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 20320 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 20322 | 20321 | return ir_finish_anal(ira, result); |
| 20323 | 20322 | } |
| 20324 | 20323 | } |
| ... | ... | @@ -20338,17 +20337,17 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 20338 | 20337 | |
| 20339 | 20338 | IrInstruction *old_value = old_case->value; |
| 20340 | 20339 | IrInstruction *new_value = old_value->child; |
| 20341 | | if (type_is_invalid(new_value->value.type)) |
| 20340 | if (type_is_invalid(new_value->value->type)) |
| 20342 | 20341 | continue; |
| 20343 | 20342 | |
| 20344 | | if (new_value->value.type->id == ZigTypeIdEnum) { |
| 20343 | if (new_value->value->type->id == ZigTypeIdEnum) { |
| 20345 | 20344 | new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value); |
| 20346 | | if (type_is_invalid(new_value->value.type)) |
| 20345 | if (type_is_invalid(new_value->value->type)) |
| 20347 | 20346 | continue; |
| 20348 | 20347 | } |
| 20349 | 20348 | |
| 20350 | | IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value.type); |
| 20351 | | if (type_is_invalid(casted_new_value->value.type)) |
| 20349 | IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type); |
| 20350 | if (type_is_invalid(casted_new_value->value->type)) |
| 20352 | 20351 | continue; |
| 20353 | 20352 | |
| 20354 | 20353 | if (!ir_resolve_const(ira, casted_new_value, UndefBad)) |
| ... | ... | @@ -20368,7 +20367,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 20368 | 20367 | IrInstructionSwitchBr *switch_br = ir_build_switch_br(&ira->new_irb, |
| 20369 | 20368 | switch_br_instruction->base.scope, switch_br_instruction->base.source_node, |
| 20370 | 20369 | target_value, new_else_block, case_count, cases, nullptr, nullptr); |
| 20371 | | switch_br->base.value.type = ira->codegen->builtin_types.entry_unreachable; |
| 20370 | switch_br->base.value->type = ira->codegen->builtin_types.entry_unreachable; |
| 20372 | 20371 | return ir_finish_anal(ira, &switch_br->base); |
| 20373 | 20372 | } |
| 20374 | 20373 | |
| ... | ... | @@ -20377,20 +20376,20 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 20377 | 20376 | { |
| 20378 | 20377 | Error err; |
| 20379 | 20378 | IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->child; |
| 20380 | | if (type_is_invalid(target_value_ptr->value.type)) |
| 20379 | if (type_is_invalid(target_value_ptr->value->type)) |
| 20381 | 20380 | return ira->codegen->invalid_instruction; |
| 20382 | 20381 | |
| 20383 | | if (target_value_ptr->value.type->id == ZigTypeIdMetaType) { |
| 20382 | if (target_value_ptr->value->type->id == ZigTypeIdMetaType) { |
| 20384 | 20383 | assert(instr_is_comptime(target_value_ptr)); |
| 20385 | | ZigType *ptr_type = target_value_ptr->value.data.x_type; |
| 20384 | ZigType *ptr_type = target_value_ptr->value->data.x_type; |
| 20386 | 20385 | assert(ptr_type->id == ZigTypeIdPointer); |
| 20387 | 20386 | return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type); |
| 20388 | 20387 | } |
| 20389 | 20388 | |
| 20390 | | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 20389 | ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; |
| 20391 | 20390 | ZigValue *pointee_val = nullptr; |
| 20392 | | if (instr_is_comptime(target_value_ptr) && target_value_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 20393 | | pointee_val = const_ptr_pointee(ira, ira->codegen, &target_value_ptr->value, target_value_ptr->source_node); |
| 20391 | if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 20392 | pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->source_node); |
| 20394 | 20393 | if (pointee_val == nullptr) |
| 20395 | 20394 | return ira->codegen->invalid_instruction; |
| 20396 | 20395 | |
| ... | ... | @@ -20416,13 +20415,13 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 20416 | 20415 | case ZigTypeIdErrorSet: { |
| 20417 | 20416 | if (pointee_val) { |
| 20418 | 20417 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr); |
| 20419 | | copy_const_val(&result->value, pointee_val, true); |
| 20420 | | result->value.type = target_type; |
| 20418 | copy_const_val(result->value, pointee_val, true); |
| 20419 | result->value->type = target_type; |
| 20421 | 20420 | return result; |
| 20422 | 20421 | } |
| 20423 | 20422 | |
| 20424 | 20423 | IrInstruction *result = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); |
| 20425 | | result->value.type = target_type; |
| 20424 | result->value->type = target_type; |
| 20426 | 20425 | return result; |
| 20427 | 20426 | } |
| 20428 | 20427 | case ZigTypeIdUnion: { |
| ... | ... | @@ -20441,22 +20440,22 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 20441 | 20440 | assert(tag_type->id == ZigTypeIdEnum); |
| 20442 | 20441 | if (pointee_val) { |
| 20443 | 20442 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type); |
| 20444 | | bigint_init_bigint(&result->value.data.x_enum_tag, &pointee_val->data.x_union.tag); |
| 20443 | bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag); |
| 20445 | 20444 | return result; |
| 20446 | 20445 | } |
| 20447 | 20446 | if (tag_type->data.enumeration.src_field_count == 1) { |
| 20448 | 20447 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type); |
| 20449 | 20448 | TypeEnumField *only_field = &tag_type->data.enumeration.fields[0]; |
| 20450 | | bigint_init_bigint(&result->value.data.x_enum_tag, &only_field->value); |
| 20449 | bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); |
| 20451 | 20450 | return result; |
| 20452 | 20451 | } |
| 20453 | 20452 | |
| 20454 | 20453 | IrInstruction *union_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); |
| 20455 | | union_value->value.type = target_type; |
| 20454 | union_value->value->type = target_type; |
| 20456 | 20455 | |
| 20457 | 20456 | IrInstruction *union_tag_inst = ir_build_union_tag(&ira->new_irb, switch_target_instruction->base.scope, |
| 20458 | 20457 | switch_target_instruction->base.source_node, union_value); |
| 20459 | | union_tag_inst->value.type = tag_type; |
| 20458 | union_tag_inst->value->type = tag_type; |
| 20460 | 20459 | return union_tag_inst; |
| 20461 | 20460 | } |
| 20462 | 20461 | case ZigTypeIdEnum: { |
| ... | ... | @@ -20465,18 +20464,18 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 20465 | 20464 | if (target_type->data.enumeration.src_field_count < 2) { |
| 20466 | 20465 | TypeEnumField *only_field = &target_type->data.enumeration.fields[0]; |
| 20467 | 20466 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type); |
| 20468 | | bigint_init_bigint(&result->value.data.x_enum_tag, &only_field->value); |
| 20467 | bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); |
| 20469 | 20468 | return result; |
| 20470 | 20469 | } |
| 20471 | 20470 | |
| 20472 | 20471 | if (pointee_val) { |
| 20473 | 20472 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type); |
| 20474 | | bigint_init_bigint(&result->value.data.x_enum_tag, &pointee_val->data.x_enum_tag); |
| 20473 | bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag); |
| 20475 | 20474 | return result; |
| 20476 | 20475 | } |
| 20477 | 20476 | |
| 20478 | 20477 | IrInstruction *enum_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); |
| 20479 | | enum_value->value.type = target_type; |
| 20478 | enum_value->value->type = target_type; |
| 20480 | 20479 | return enum_value; |
| 20481 | 20480 | } |
| 20482 | 20481 | case ZigTypeIdErrorUnion: |
| ... | ... | @@ -20501,12 +20500,12 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 20501 | 20500 | |
| 20502 | 20501 | static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) { |
| 20503 | 20502 | IrInstruction *target_value_ptr = instruction->target_value_ptr->child; |
| 20504 | | if (type_is_invalid(target_value_ptr->value.type)) |
| 20503 | if (type_is_invalid(target_value_ptr->value->type)) |
| 20505 | 20504 | return ira->codegen->invalid_instruction; |
| 20506 | 20505 | |
| 20507 | | ZigType *ref_type = target_value_ptr->value.type; |
| 20506 | ZigType *ref_type = target_value_ptr->value->type; |
| 20508 | 20507 | assert(ref_type->id == ZigTypeIdPointer); |
| 20509 | | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 20508 | ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; |
| 20510 | 20509 | if (target_type->id == ZigTypeIdUnion) { |
| 20511 | 20510 | ZigType *enum_type = target_type->data.unionation.tag_type; |
| 20512 | 20511 | assert(enum_type != nullptr); |
| ... | ... | @@ -20514,11 +20513,11 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 20514 | 20513 | assert(instruction->prongs_len > 0); |
| 20515 | 20514 | |
| 20516 | 20515 | IrInstruction *first_prong_value = instruction->prongs_ptr[0]->child; |
| 20517 | | if (type_is_invalid(first_prong_value->value.type)) |
| 20516 | if (type_is_invalid(first_prong_value->value->type)) |
| 20518 | 20517 | return ira->codegen->invalid_instruction; |
| 20519 | 20518 | |
| 20520 | 20519 | IrInstruction *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type); |
| 20521 | | if (type_is_invalid(first_casted_prong_value->value.type)) |
| 20520 | if (type_is_invalid(first_casted_prong_value->value->type)) |
| 20522 | 20521 | return ira->codegen->invalid_instruction; |
| 20523 | 20522 | |
| 20524 | 20523 | ZigValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad); |
| ... | ... | @@ -20530,11 +20529,11 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 20530 | 20529 | ErrorMsg *invalid_payload_msg = nullptr; |
| 20531 | 20530 | for (size_t prong_i = 1; prong_i < instruction->prongs_len; prong_i += 1) { |
| 20532 | 20531 | IrInstruction *this_prong_inst = instruction->prongs_ptr[prong_i]->child; |
| 20533 | | if (type_is_invalid(this_prong_inst->value.type)) |
| 20532 | if (type_is_invalid(this_prong_inst->value->type)) |
| 20534 | 20533 | return ira->codegen->invalid_instruction; |
| 20535 | 20534 | |
| 20536 | 20535 | IrInstruction *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type); |
| 20537 | | if (type_is_invalid(this_casted_prong_value->value.type)) |
| 20536 | if (type_is_invalid(this_casted_prong_value->value->type)) |
| 20538 | 20537 | return ira->codegen->invalid_instruction; |
| 20539 | 20538 | |
| 20540 | 20539 | ZigValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad); |
| ... | ... | @@ -20571,7 +20570,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 20571 | 20570 | IrInstruction *result = ir_const(ira, &instruction->base, |
| 20572 | 20571 | get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 20573 | 20572 | target_val_ptr->type->data.pointer.is_const)); |
| 20574 | | ZigValue *out_val = &result->value; |
| 20573 | ZigValue *out_val = result->value; |
| 20575 | 20574 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 20576 | 20575 | out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut; |
| 20577 | 20576 | out_val->data.x_ptr.data.ref.pointee = pointee_val->data.x_union.payload; |
| ... | ... | @@ -20580,8 +20579,8 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 20580 | 20579 | |
| 20581 | 20580 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, |
| 20582 | 20581 | instruction->base.scope, instruction->base.source_node, target_value_ptr, first_field, false, false); |
| 20583 | | result->value.type = get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 20584 | | target_value_ptr->value.type->data.pointer.is_const); |
| 20582 | result->value->type = get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 20583 | target_value_ptr->value->type->data.pointer.is_const); |
| 20585 | 20584 | return result; |
| 20586 | 20585 | } else if (target_type->id == ZigTypeIdErrorSet) { |
| 20587 | 20586 | // construct an error set from the prong values |
| ... | ... | @@ -20624,12 +20623,12 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 20624 | 20623 | IrInstructionSwitchElseVar *instruction) |
| 20625 | 20624 | { |
| 20626 | 20625 | IrInstruction *target_value_ptr = instruction->target_value_ptr->child; |
| 20627 | | if (type_is_invalid(target_value_ptr->value.type)) |
| 20626 | if (type_is_invalid(target_value_ptr->value->type)) |
| 20628 | 20627 | return ira->codegen->invalid_instruction; |
| 20629 | 20628 | |
| 20630 | | ZigType *ref_type = target_value_ptr->value.type; |
| 20629 | ZigType *ref_type = target_value_ptr->value->type; |
| 20631 | 20630 | assert(ref_type->id == ZigTypeIdPointer); |
| 20632 | | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 20631 | ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; |
| 20633 | 20632 | if (target_type->id == ZigTypeIdErrorSet) { |
| 20634 | 20633 | // make a new set that has the other cases removed |
| 20635 | 20634 | if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.source_node)) { |
| ... | ... | @@ -20645,12 +20644,12 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 20645 | 20644 | for (size_t case_i = 0; case_i < instruction->switch_br->case_count; case_i += 1) { |
| 20646 | 20645 | IrInstructionSwitchBrCase *br_case = &instruction->switch_br->cases[case_i]; |
| 20647 | 20646 | IrInstruction *case_expr = br_case->value->child; |
| 20648 | | if (case_expr->value.type->id == ZigTypeIdErrorSet) { |
| 20647 | if (case_expr->value->type->id == ZigTypeIdErrorSet) { |
| 20649 | 20648 | ErrorTableEntry *err = ir_resolve_error(ira, case_expr); |
| 20650 | 20649 | if (err == nullptr) |
| 20651 | 20650 | return ira->codegen->invalid_instruction; |
| 20652 | 20651 | errors[err->value] = err; |
| 20653 | | } else if (case_expr->value.type->id == ZigTypeIdMetaType) { |
| 20652 | } else if (case_expr->value->type->id == ZigTypeIdMetaType) { |
| 20654 | 20653 | ZigType *err_set_type = ir_resolve_type(ira, case_expr); |
| 20655 | 20654 | if (type_is_invalid(err_set_type)) |
| 20656 | 20655 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -20742,7 +20741,7 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio |
| 20742 | 20741 | |
| 20743 | 20742 | static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) { |
| 20744 | 20743 | IrInstruction *value = ref_instruction->value->child; |
| 20745 | | if (type_is_invalid(value->value.type)) |
| 20744 | if (type_is_invalid(value->value->type)) |
| 20746 | 20745 | return ira->codegen->invalid_instruction; |
| 20747 | 20746 | return ir_get_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile); |
| 20748 | 20747 | } |
| ... | ... | @@ -20768,13 +20767,13 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc |
| 20768 | 20767 | if (type_is_invalid(type_field->type_entry)) |
| 20769 | 20768 | return ira->codegen->invalid_instruction; |
| 20770 | 20769 | |
| 20771 | | if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) { |
| 20770 | if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 20772 | 20771 | if (instr_is_comptime(field_result_loc) && |
| 20773 | | field_result_loc->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 20772 | field_result_loc->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 20774 | 20773 | { |
| 20775 | 20774 | // nothing |
| 20776 | 20775 | } else { |
| 20777 | | result_loc->value.special = ConstValSpecialRuntime; |
| 20776 | result_loc->value->special = ConstValSpecialRuntime; |
| 20778 | 20777 | } |
| 20779 | 20778 | } |
| 20780 | 20779 | |
| ... | ... | @@ -20803,7 +20802,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 20803 | 20802 | } |
| 20804 | 20803 | IrInstructionContainerInitFieldsField *field = &fields[0]; |
| 20805 | 20804 | IrInstruction *field_result_loc = field->result_loc->child; |
| 20806 | | if (type_is_invalid(field_result_loc->value.type)) |
| 20805 | if (type_is_invalid(field_result_loc->value->type)) |
| 20807 | 20806 | return ira->codegen->invalid_instruction; |
| 20808 | 20807 | |
| 20809 | 20808 | return ir_analyze_union_init(ira, instruction, field->source_node, container_type, field->name, |
| ... | ... | @@ -20850,7 +20849,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 20850 | 20849 | IrInstructionContainerInitFieldsField *field = &fields[i]; |
| 20851 | 20850 | |
| 20852 | 20851 | IrInstruction *field_result_loc = field->result_loc->child; |
| 20853 | | if (type_is_invalid(field_result_loc->value.type)) |
| 20852 | if (type_is_invalid(field_result_loc->value->type)) |
| 20854 | 20853 | return ira->codegen->invalid_instruction; |
| 20855 | 20854 | |
| 20856 | 20855 | TypeStructField *type_field = find_struct_type_field(container_type, field->name); |
| ... | ... | @@ -20874,7 +20873,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 20874 | 20873 | field_assign_nodes[field_index] = field->source_node; |
| 20875 | 20874 | |
| 20876 | 20875 | if (instr_is_comptime(field_result_loc) && |
| 20877 | | field_result_loc->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 20876 | field_result_loc->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 20878 | 20877 | { |
| 20879 | 20878 | const_ptrs.append(field_result_loc); |
| 20880 | 20879 | } else { |
| ... | ... | @@ -20912,12 +20911,12 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 20912 | 20911 | return ira->codegen->invalid_instruction; |
| 20913 | 20912 | |
| 20914 | 20913 | IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type); |
| 20915 | | copy_const_val(&runtime_inst->value, field->init_val, true); |
| 20914 | copy_const_val(runtime_inst->value, field->init_val, true); |
| 20916 | 20915 | |
| 20917 | 20916 | IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc, |
| 20918 | 20917 | container_type, true); |
| 20919 | 20918 | ir_analyze_store_ptr(ira, instruction, field_ptr, runtime_inst, false); |
| 20920 | | if (instr_is_comptime(field_ptr) && field_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 20919 | if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 20921 | 20920 | const_ptrs.append(field_ptr); |
| 20922 | 20921 | } else { |
| 20923 | 20922 | first_non_const_instruction = result_loc; |
| ... | ... | @@ -20926,13 +20925,13 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 20926 | 20925 | if (any_missing) |
| 20927 | 20926 | return ira->codegen->invalid_instruction; |
| 20928 | 20927 | |
| 20929 | | if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) { |
| 20928 | if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 20930 | 20929 | if (const_ptrs.length != actual_field_count) { |
| 20931 | | result_loc->value.special = ConstValSpecialRuntime; |
| 20930 | result_loc->value->special = ConstValSpecialRuntime; |
| 20932 | 20931 | for (size_t i = 0; i < const_ptrs.length; i += 1) { |
| 20933 | 20932 | IrInstruction *field_result_loc = const_ptrs.at(i); |
| 20934 | 20933 | IrInstruction *deref = ir_get_deref(ira, field_result_loc, field_result_loc, nullptr); |
| 20935 | | field_result_loc->value.special = ConstValSpecialRuntime; |
| 20934 | field_result_loc->value->special = ConstValSpecialRuntime; |
| 20936 | 20935 | ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref, false); |
| 20937 | 20936 | } |
| 20938 | 20937 | } |
| ... | ... | @@ -20954,11 +20953,11 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 20954 | 20953 | { |
| 20955 | 20954 | ir_assert(instruction->result_loc != nullptr, &instruction->base); |
| 20956 | 20955 | IrInstruction *result_loc = instruction->result_loc->child; |
| 20957 | | if (type_is_invalid(result_loc->value.type)) |
| 20956 | if (type_is_invalid(result_loc->value->type)) |
| 20958 | 20957 | return result_loc; |
| 20959 | | ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base); |
| 20958 | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base); |
| 20960 | 20959 | |
| 20961 | | ZigType *container_type = result_loc->value.type->data.pointer.child_type; |
| 20960 | ZigType *container_type = result_loc->value->type->data.pointer.child_type; |
| 20962 | 20961 | |
| 20963 | 20962 | size_t elem_count = instruction->item_count; |
| 20964 | 20963 | |
| ... | ... | @@ -20980,7 +20979,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 20980 | 20979 | if (container_type->id == ZigTypeIdStruct && elem_count == 0) { |
| 20981 | 20980 | ir_assert(instruction->result_loc != nullptr, &instruction->base); |
| 20982 | 20981 | IrInstruction *result_loc = instruction->result_loc->child; |
| 20983 | | if (type_is_invalid(result_loc->value.type)) |
| 20982 | if (type_is_invalid(result_loc->value->type)) |
| 20984 | 20983 | return result_loc; |
| 20985 | 20984 | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr, result_loc); |
| 20986 | 20985 | } |
| ... | ... | @@ -21041,13 +21040,13 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 21041 | 21040 | |
| 21042 | 21041 | for (size_t i = 0; i < elem_count; i += 1) { |
| 21043 | 21042 | IrInstruction *elem_result_loc = instruction->elem_result_loc_list[i]->child; |
| 21044 | | if (type_is_invalid(elem_result_loc->value.type)) |
| 21043 | if (type_is_invalid(elem_result_loc->value->type)) |
| 21045 | 21044 | return ira->codegen->invalid_instruction; |
| 21046 | 21045 | |
| 21047 | | assert(elem_result_loc->value.type->id == ZigTypeIdPointer); |
| 21046 | assert(elem_result_loc->value->type->id == ZigTypeIdPointer); |
| 21048 | 21047 | |
| 21049 | 21048 | if (instr_is_comptime(elem_result_loc) && |
| 21050 | | elem_result_loc->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 21049 | elem_result_loc->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 21051 | 21050 | { |
| 21052 | 21051 | const_ptrs.append(elem_result_loc); |
| 21053 | 21052 | } else { |
| ... | ... | @@ -21055,14 +21054,14 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 21055 | 21054 | } |
| 21056 | 21055 | } |
| 21057 | 21056 | |
| 21058 | | if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) { |
| 21057 | if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 21059 | 21058 | if (const_ptrs.length != elem_count) { |
| 21060 | | result_loc->value.special = ConstValSpecialRuntime; |
| 21059 | result_loc->value->special = ConstValSpecialRuntime; |
| 21061 | 21060 | for (size_t i = 0; i < const_ptrs.length; i += 1) { |
| 21062 | 21061 | IrInstruction *elem_result_loc = const_ptrs.at(i); |
| 21063 | | assert(elem_result_loc->value.special == ConstValSpecialStatic); |
| 21062 | assert(elem_result_loc->value->special == ConstValSpecialStatic); |
| 21064 | 21063 | IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr); |
| 21065 | | elem_result_loc->value.special = ConstValSpecialRuntime; |
| 21064 | elem_result_loc->value->special = ConstValSpecialRuntime; |
| 21066 | 21065 | ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false); |
| 21067 | 21066 | } |
| 21068 | 21067 | } |
| ... | ... | @@ -21078,7 +21077,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 21078 | 21077 | return ira->codegen->invalid_instruction; |
| 21079 | 21078 | } |
| 21080 | 21079 | |
| 21081 | | ZigType *result_elem_type = result_loc->value.type->data.pointer.child_type; |
| 21080 | ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type; |
| 21082 | 21081 | if (is_slice(result_elem_type)) { |
| 21083 | 21082 | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| 21084 | 21083 | buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'", |
| ... | ... | @@ -21095,11 +21094,11 @@ static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ir |
| 21095 | 21094 | { |
| 21096 | 21095 | ir_assert(instruction->result_loc != nullptr, &instruction->base); |
| 21097 | 21096 | IrInstruction *result_loc = instruction->result_loc->child; |
| 21098 | | if (type_is_invalid(result_loc->value.type)) |
| 21097 | if (type_is_invalid(result_loc->value->type)) |
| 21099 | 21098 | return result_loc; |
| 21100 | 21099 | |
| 21101 | | ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base); |
| 21102 | | ZigType *container_type = result_loc->value.type->data.pointer.child_type; |
| 21100 | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base); |
| 21101 | ZigType *container_type = result_loc->value->type->data.pointer.child_type; |
| 21103 | 21102 | |
| 21104 | 21103 | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, |
| 21105 | 21104 | instruction->field_count, instruction->fields, result_loc); |
| ... | ... | @@ -21123,15 +21122,15 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr |
| 21123 | 21122 | fprintf(stderr, "| "); |
| 21124 | 21123 | for (size_t i = 0; i < instruction->msg_count; i += 1) { |
| 21125 | 21124 | IrInstruction *msg = instruction->msg_list[i]->child; |
| 21126 | | if (type_is_invalid(msg->value.type)) |
| 21125 | if (type_is_invalid(msg->value->type)) |
| 21127 | 21126 | return ira->codegen->invalid_instruction; |
| 21128 | 21127 | buf_resize(&buf, 0); |
| 21129 | | if (msg->value.special == ConstValSpecialLazy) { |
| 21128 | if (msg->value->special == ConstValSpecialLazy) { |
| 21130 | 21129 | // Resolve any lazy value that's passed, we need its value |
| 21131 | | if (ir_resolve_lazy(ira->codegen, msg->source_node, &msg->value)) |
| 21130 | if (ir_resolve_lazy(ira->codegen, msg->source_node, msg->value)) |
| 21132 | 21131 | return ira->codegen->invalid_instruction; |
| 21133 | 21132 | } |
| 21134 | | render_const_value(ira->codegen, &buf, &msg->value); |
| 21133 | render_const_value(ira->codegen, &buf, msg->value); |
| 21135 | 21134 | const char *comma_str = (i != 0) ? ", " : ""; |
| 21136 | 21135 | fprintf(stderr, "%s%s", comma_str, buf_ptr(&buf)); |
| 21137 | 21136 | } |
| ... | ... | @@ -21150,11 +21149,11 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr |
| 21150 | 21149 | |
| 21151 | 21150 | static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) { |
| 21152 | 21151 | IrInstruction *value = instruction->value->child; |
| 21153 | | if (type_is_invalid(value->value.type)) |
| 21152 | if (type_is_invalid(value->value->type)) |
| 21154 | 21153 | return ira->codegen->invalid_instruction; |
| 21155 | 21154 | |
| 21156 | 21155 | IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set); |
| 21157 | | if (type_is_invalid(casted_value->value.type)) |
| 21156 | if (type_is_invalid(casted_value->value->type)) |
| 21158 | 21157 | return ira->codegen->invalid_instruction; |
| 21159 | 21158 | |
| 21160 | 21159 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| ... | ... | @@ -21164,14 +21163,14 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct |
| 21164 | 21163 | ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad); |
| 21165 | 21164 | if (val == nullptr) |
| 21166 | 21165 | return ira->codegen->invalid_instruction; |
| 21167 | | ErrorTableEntry *err = casted_value->value.data.x_err_set; |
| 21166 | ErrorTableEntry *err = casted_value->value->data.x_err_set; |
| 21168 | 21167 | if (!err->cached_error_name_val) { |
| 21169 | 21168 | ZigValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee; |
| 21170 | 21169 | err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true); |
| 21171 | 21170 | } |
| 21172 | 21171 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 21173 | | copy_const_val(&result->value, err->cached_error_name_val, true); |
| 21174 | | result->value.type = str_type; |
| 21172 | copy_const_val(result->value, err->cached_error_name_val, true); |
| 21173 | result->value->type = str_type; |
| 21175 | 21174 | return result; |
| 21176 | 21175 | } |
| 21177 | 21176 | |
| ... | ... | @@ -21179,25 +21178,25 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct |
| 21179 | 21178 | |
| 21180 | 21179 | IrInstruction *result = ir_build_err_name(&ira->new_irb, |
| 21181 | 21180 | instruction->base.scope, instruction->base.source_node, value); |
| 21182 | | result->value.type = str_type; |
| 21181 | result->value->type = str_type; |
| 21183 | 21182 | return result; |
| 21184 | 21183 | } |
| 21185 | 21184 | |
| 21186 | 21185 | static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) { |
| 21187 | 21186 | Error err; |
| 21188 | 21187 | IrInstruction *target = instruction->target->child; |
| 21189 | | if (type_is_invalid(target->value.type)) |
| 21188 | if (type_is_invalid(target->value->type)) |
| 21190 | 21189 | return ira->codegen->invalid_instruction; |
| 21191 | 21190 | |
| 21192 | | assert(target->value.type->id == ZigTypeIdEnum); |
| 21191 | assert(target->value->type->id == ZigTypeIdEnum); |
| 21193 | 21192 | |
| 21194 | 21193 | if (instr_is_comptime(target)) { |
| 21195 | | if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown))) |
| 21194 | if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown))) |
| 21196 | 21195 | return ira->codegen->invalid_instruction; |
| 21197 | | TypeEnumField *field = find_enum_field_by_tag(target->value.type, &target->value.data.x_bigint); |
| 21196 | TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint); |
| 21198 | 21197 | ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee; |
| 21199 | 21198 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 21200 | | init_const_slice(ira->codegen, &result->value, array_val, 0, buf_len(field->name), true); |
| 21199 | init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field->name), true); |
| 21201 | 21200 | return result; |
| 21202 | 21201 | } |
| 21203 | 21202 | |
| ... | ... | @@ -21207,7 +21206,7 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns |
| 21207 | 21206 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 21208 | 21207 | true, false, PtrLenUnknown, |
| 21209 | 21208 | 0, 0, 0, false); |
| 21210 | | result->value.type = get_slice_type(ira->codegen, u8_ptr_type); |
| 21209 | result->value->type = get_slice_type(ira->codegen, u8_ptr_type); |
| 21211 | 21210 | return result; |
| 21212 | 21211 | } |
| 21213 | 21212 | |
| ... | ... | @@ -21226,7 +21225,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 21226 | 21225 | return ira->codegen->invalid_instruction; |
| 21227 | 21226 | |
| 21228 | 21227 | IrInstruction *field_ptr = instruction->field_ptr->child; |
| 21229 | | if (type_is_invalid(field_ptr->value.type)) |
| 21228 | if (type_is_invalid(field_ptr->value->type)) |
| 21230 | 21229 | return ira->codegen->invalid_instruction; |
| 21231 | 21230 | |
| 21232 | 21231 | if (container_type->id != ZigTypeIdStruct) { |
| ... | ... | @@ -21246,9 +21245,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 21246 | 21245 | return ira->codegen->invalid_instruction; |
| 21247 | 21246 | } |
| 21248 | 21247 | |
| 21249 | | if (field_ptr->value.type->id != ZigTypeIdPointer) { |
| 21248 | if (field_ptr->value->type->id != ZigTypeIdPointer) { |
| 21250 | 21249 | ir_add_error(ira, field_ptr, |
| 21251 | | buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name))); |
| 21250 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name))); |
| 21252 | 21251 | return ira->codegen->invalid_instruction; |
| 21253 | 21252 | } |
| 21254 | 21253 | |
| ... | ... | @@ -21257,17 +21256,17 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 21257 | 21256 | uint32_t parent_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, container_type); |
| 21258 | 21257 | |
| 21259 | 21258 | ZigType *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry, |
| 21260 | | field_ptr->value.type->data.pointer.is_const, |
| 21261 | | field_ptr->value.type->data.pointer.is_volatile, |
| 21259 | field_ptr->value->type->data.pointer.is_const, |
| 21260 | field_ptr->value->type->data.pointer.is_volatile, |
| 21262 | 21261 | PtrLenSingle, |
| 21263 | 21262 | field_ptr_align, 0, 0, false); |
| 21264 | 21263 | IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type); |
| 21265 | | if (type_is_invalid(casted_field_ptr->value.type)) |
| 21264 | if (type_is_invalid(casted_field_ptr->value->type)) |
| 21266 | 21265 | return ira->codegen->invalid_instruction; |
| 21267 | 21266 | |
| 21268 | 21267 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type, |
| 21269 | | casted_field_ptr->value.type->data.pointer.is_const, |
| 21270 | | casted_field_ptr->value.type->data.pointer.is_volatile, |
| 21268 | casted_field_ptr->value->type->data.pointer.is_const, |
| 21269 | casted_field_ptr->value->type->data.pointer.is_volatile, |
| 21271 | 21270 | PtrLenSingle, |
| 21272 | 21271 | parent_ptr_align, 0, 0, false); |
| 21273 | 21272 | |
| ... | ... | @@ -21291,7 +21290,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 21291 | 21290 | } |
| 21292 | 21291 | |
| 21293 | 21292 | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 21294 | | ZigValue *out_val = &result->value; |
| 21293 | ZigValue *out_val = result->value; |
| 21295 | 21294 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 21296 | 21295 | out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val; |
| 21297 | 21296 | out_val->data.x_ptr.mut = field_ptr_val->data.x_ptr.mut; |
| ... | ... | @@ -21300,7 +21299,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 21300 | 21299 | |
| 21301 | 21300 | IrInstruction *result = ir_build_field_parent_ptr(&ira->new_irb, instruction->base.scope, |
| 21302 | 21301 | instruction->base.source_node, type_value, field_name_value, casted_field_ptr, field); |
| 21303 | | result->value.type = result_type; |
| 21302 | result->value->type = result_type; |
| 21304 | 21303 | return result; |
| 21305 | 21304 | } |
| 21306 | 21305 | |
| ... | ... | @@ -21350,7 +21349,7 @@ static IrInstruction *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, |
| 21350 | 21349 | IrInstructionByteOffsetOf *instruction) |
| 21351 | 21350 | { |
| 21352 | 21351 | IrInstruction *type_value = instruction->type_value->child; |
| 21353 | | if (type_is_invalid(type_value->value.type)) |
| 21352 | if (type_is_invalid(type_value->value->type)) |
| 21354 | 21353 | return ira->codegen->invalid_instruction; |
| 21355 | 21354 | |
| 21356 | 21355 | IrInstruction *field_name_value = instruction->field_name->child; |
| ... | ... | @@ -21366,7 +21365,7 @@ static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, |
| 21366 | 21365 | IrInstructionBitOffsetOf *instruction) |
| 21367 | 21366 | { |
| 21368 | 21367 | IrInstruction *type_value = instruction->type_value->child; |
| 21369 | | if (type_is_invalid(type_value->value.type)) |
| 21368 | if (type_is_invalid(type_value->value->type)) |
| 21370 | 21369 | return ira->codegen->invalid_instruction; |
| 21371 | 21370 | IrInstruction *field_name_value = instruction->field_name->child; |
| 21372 | 21371 | size_t byte_offset = 0; |
| ... | ... | @@ -22381,7 +22380,7 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 22381 | 22380 | return ira->codegen->invalid_instruction; |
| 22382 | 22381 | |
| 22383 | 22382 | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 22384 | | ZigValue *out_val = &result->value; |
| 22383 | ZigValue *out_val = result->value; |
| 22385 | 22384 | bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry)); |
| 22386 | 22385 | out_val->data.x_union.payload = payload; |
| 22387 | 22386 | |
| ... | ... | @@ -22407,10 +22406,10 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst |
| 22407 | 22406 | IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type); |
| 22408 | 22407 | IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst, |
| 22409 | 22408 | get_optional_type(ira->codegen, elem_type)); |
| 22410 | | if (type_is_invalid(casted_field_inst->value.type)) |
| 22409 | if (type_is_invalid(casted_field_inst->value->type)) |
| 22411 | 22410 | return ErrorSemanticAnalyzeFail; |
| 22412 | 22411 | |
| 22413 | | *result = casted_field_inst->value.data.x_optional; |
| 22412 | *result = casted_field_inst->value->data.x_optional; |
| 22414 | 22413 | return ErrorNone; |
| 22415 | 22414 | } |
| 22416 | 22415 | |
| ... | ... | @@ -22549,11 +22548,11 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi |
| 22549 | 22548 | |
| 22550 | 22549 | static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionType *instruction) { |
| 22551 | 22550 | IrInstruction *type_info_ir = instruction->type_info->child; |
| 22552 | | if (type_is_invalid(type_info_ir->value.type)) |
| 22551 | if (type_is_invalid(type_info_ir->value->type)) |
| 22553 | 22552 | return ira->codegen->invalid_instruction; |
| 22554 | 22553 | |
| 22555 | 22554 | IrInstruction *casted_ir = ir_implicit_cast(ira, type_info_ir, ir_type_info_get_type(ira, nullptr, nullptr)); |
| 22556 | | if (type_is_invalid(casted_ir->value.type)) |
| 22555 | if (type_is_invalid(casted_ir->value->type)) |
| 22557 | 22556 | return ira->codegen->invalid_instruction; |
| 22558 | 22557 | |
| 22559 | 22558 | ZigValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad); |
| ... | ... | @@ -22579,7 +22578,7 @@ static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira, |
| 22579 | 22578 | ZigType *result_type = var_value->data.x_type; |
| 22580 | 22579 | |
| 22581 | 22580 | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 22582 | | bigint_init_unsigned(&result->value.data.x_enum_tag, type_id_index(type_entry)); |
| 22581 | bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry)); |
| 22583 | 22582 | return result; |
| 22584 | 22583 | } |
| 22585 | 22584 | |
| ... | ... | @@ -22607,7 +22606,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc |
| 22607 | 22606 | type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry)); |
| 22608 | 22607 | } |
| 22609 | 22608 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 22610 | | copy_const_val(&result->value, type_entry->cached_const_name_val, true); |
| 22609 | copy_const_val(result->value, type_entry->cached_const_name_val, true); |
| 22611 | 22610 | return result; |
| 22612 | 22611 | } |
| 22613 | 22612 | |
| ... | ... | @@ -22796,7 +22795,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 22796 | 22795 | |
| 22797 | 22796 | static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) { |
| 22798 | 22797 | IrInstruction *name_value = instruction->name->child; |
| 22799 | | if (type_is_invalid(name_value->value.type)) |
| 22798 | if (type_is_invalid(name_value->value->type)) |
| 22800 | 22799 | return ira->codegen->invalid_instruction; |
| 22801 | 22800 | |
| 22802 | 22801 | Buf *include_name = ir_resolve_str(ira, name_value); |
| ... | ... | @@ -22814,7 +22813,7 @@ static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstruc |
| 22814 | 22813 | |
| 22815 | 22814 | static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) { |
| 22816 | 22815 | IrInstruction *name = instruction->name->child; |
| 22817 | | if (type_is_invalid(name->value.type)) |
| 22816 | if (type_is_invalid(name->value->type)) |
| 22818 | 22817 | return ira->codegen->invalid_instruction; |
| 22819 | 22818 | |
| 22820 | 22819 | Buf *define_name = ir_resolve_str(ira, name); |
| ... | ... | @@ -22822,12 +22821,12 @@ static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruct |
| 22822 | 22821 | return ira->codegen->invalid_instruction; |
| 22823 | 22822 | |
| 22824 | 22823 | IrInstruction *value = instruction->value->child; |
| 22825 | | if (type_is_invalid(value->value.type)) |
| 22824 | if (type_is_invalid(value->value->type)) |
| 22826 | 22825 | return ira->codegen->invalid_instruction; |
| 22827 | 22826 | |
| 22828 | 22827 | Buf *define_value = nullptr; |
| 22829 | 22828 | // The second parameter is either a string or void (equivalent to "") |
| 22830 | | if (value->value.type->id != ZigTypeIdVoid) { |
| 22829 | if (value->value->type->id != ZigTypeIdVoid) { |
| 22831 | 22830 | define_value = ir_resolve_str(ira, value); |
| 22832 | 22831 | if (!define_value) |
| 22833 | 22832 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -22845,7 +22844,7 @@ static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruct |
| 22845 | 22844 | |
| 22846 | 22845 | static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) { |
| 22847 | 22846 | IrInstruction *name = instruction->name->child; |
| 22848 | | if (type_is_invalid(name->value.type)) |
| 22847 | if (type_is_invalid(name->value->type)) |
| 22849 | 22848 | return ira->codegen->invalid_instruction; |
| 22850 | 22849 | |
| 22851 | 22850 | Buf *undef_name = ir_resolve_str(ira, name); |
| ... | ... | @@ -22863,7 +22862,7 @@ static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructi |
| 22863 | 22862 | |
| 22864 | 22863 | static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) { |
| 22865 | 22864 | IrInstruction *name = instruction->name->child; |
| 22866 | | if (type_is_invalid(name->value.type)) |
| 22865 | if (type_is_invalid(name->value->type)) |
| 22867 | 22866 | return ira->codegen->invalid_instruction; |
| 22868 | 22867 | |
| 22869 | 22868 | Buf *rel_file_path = ir_resolve_str(ira, name); |
| ... | ... | @@ -22898,7 +22897,7 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru |
| 22898 | 22897 | ZigType *result_type = get_array_type(ira->codegen, |
| 22899 | 22898 | ira->codegen->builtin_types.entry_u8, buf_len(file_contents), nullptr); |
| 22900 | 22899 | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 22901 | | init_const_str_lit(ira->codegen, &result->value, file_contents); |
| 22900 | init_const_str_lit(ira->codegen, result->value, file_contents); |
| 22902 | 22901 | return result; |
| 22903 | 22902 | } |
| 22904 | 22903 | |
| ... | ... | @@ -22908,25 +22907,25 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 22908 | 22907 | return ira->codegen->invalid_instruction; |
| 22909 | 22908 | |
| 22910 | 22909 | IrInstruction *ptr = instruction->ptr->child; |
| 22911 | | if (type_is_invalid(ptr->value.type)) |
| 22910 | if (type_is_invalid(ptr->value->type)) |
| 22912 | 22911 | return ira->codegen->invalid_instruction; |
| 22913 | 22912 | |
| 22914 | 22913 | // TODO let this be volatile |
| 22915 | 22914 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 22916 | 22915 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type); |
| 22917 | | if (type_is_invalid(casted_ptr->value.type)) |
| 22916 | if (type_is_invalid(casted_ptr->value->type)) |
| 22918 | 22917 | return ira->codegen->invalid_instruction; |
| 22919 | 22918 | |
| 22920 | 22919 | IrInstruction *cmp_value = instruction->cmp_value->child; |
| 22921 | | if (type_is_invalid(cmp_value->value.type)) |
| 22920 | if (type_is_invalid(cmp_value->value->type)) |
| 22922 | 22921 | return ira->codegen->invalid_instruction; |
| 22923 | 22922 | |
| 22924 | 22923 | IrInstruction *new_value = instruction->new_value->child; |
| 22925 | | if (type_is_invalid(new_value->value.type)) |
| 22924 | if (type_is_invalid(new_value->value->type)) |
| 22926 | 22925 | return ira->codegen->invalid_instruction; |
| 22927 | 22926 | |
| 22928 | 22927 | IrInstruction *success_order_value = instruction->success_order_value->child; |
| 22929 | | if (type_is_invalid(success_order_value->value.type)) |
| 22928 | if (type_is_invalid(success_order_value->value->type)) |
| 22930 | 22929 | return ira->codegen->invalid_instruction; |
| 22931 | 22930 | |
| 22932 | 22931 | AtomicOrder success_order; |
| ... | ... | @@ -22934,7 +22933,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 22934 | 22933 | return ira->codegen->invalid_instruction; |
| 22935 | 22934 | |
| 22936 | 22935 | IrInstruction *failure_order_value = instruction->failure_order_value->child; |
| 22937 | | if (type_is_invalid(failure_order_value->value.type)) |
| 22936 | if (type_is_invalid(failure_order_value->value->type)) |
| 22938 | 22937 | return ira->codegen->invalid_instruction; |
| 22939 | 22938 | |
| 22940 | 22939 | AtomicOrder failure_order; |
| ... | ... | @@ -22942,11 +22941,11 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 22942 | 22941 | return ira->codegen->invalid_instruction; |
| 22943 | 22942 | |
| 22944 | 22943 | IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type); |
| 22945 | | if (type_is_invalid(casted_cmp_value->value.type)) |
| 22944 | if (type_is_invalid(casted_cmp_value->value->type)) |
| 22946 | 22945 | return ira->codegen->invalid_instruction; |
| 22947 | 22946 | |
| 22948 | 22947 | IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, operand_type); |
| 22949 | | if (type_is_invalid(casted_new_value->value.type)) |
| 22948 | if (type_is_invalid(casted_new_value->value->type)) |
| 22950 | 22949 | return ira->codegen->invalid_instruction; |
| 22951 | 22950 | |
| 22952 | 22951 | if (success_order < AtomicOrderMonotonic) { |
| ... | ... | @@ -22970,7 +22969,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 22970 | 22969 | return ira->codegen->invalid_instruction; |
| 22971 | 22970 | } |
| 22972 | 22971 | |
| 22973 | | if (instr_is_comptime(casted_ptr) && casted_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| 22972 | if (instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| 22974 | 22973 | instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) { |
| 22975 | 22974 | zig_panic("TODO compile-time execution of cmpxchg"); |
| 22976 | 22975 | } |
| ... | ... | @@ -22980,7 +22979,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 22980 | 22979 | if (handle_is_ptr(result_type)) { |
| 22981 | 22980 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 22982 | 22981 | result_type, nullptr, true, false, true); |
| 22983 | | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 22982 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 22984 | 22983 | return result_loc; |
| 22985 | 22984 | } |
| 22986 | 22985 | } else { |
| ... | ... | @@ -22994,7 +22993,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 22994 | 22993 | |
| 22995 | 22994 | static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) { |
| 22996 | 22995 | IrInstruction *order_value = instruction->order_value->child; |
| 22997 | | if (type_is_invalid(order_value->value.type)) |
| 22996 | if (type_is_invalid(order_value->value->type)) |
| 22998 | 22997 | return ira->codegen->invalid_instruction; |
| 22999 | 22998 | |
| 23000 | 22999 | AtomicOrder order; |
| ... | ... | @@ -23009,7 +23008,7 @@ static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstruction |
| 23009 | 23008 | |
| 23010 | 23009 | IrInstruction *result = ir_build_fence(&ira->new_irb, |
| 23011 | 23010 | instruction->base.scope, instruction->base.source_node, order_value, order); |
| 23012 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 23011 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 23013 | 23012 | return result; |
| 23014 | 23013 | } |
| 23015 | 23014 | |
| ... | ... | @@ -23027,7 +23026,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct |
| 23027 | 23026 | } |
| 23028 | 23027 | |
| 23029 | 23028 | IrInstruction *target = instruction->target->child; |
| 23030 | | ZigType *src_type = target->value.type; |
| 23029 | ZigType *src_type = target->value->type; |
| 23031 | 23030 | if (type_is_invalid(src_type)) |
| 23032 | 23031 | return ira->codegen->invalid_instruction; |
| 23033 | 23032 | |
| ... | ... | @@ -23048,14 +23047,14 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct |
| 23048 | 23047 | return ira->codegen->invalid_instruction; |
| 23049 | 23048 | |
| 23050 | 23049 | IrInstruction *result = ir_const(ira, &instruction->base, dest_type); |
| 23051 | | bigint_truncate(&result->value.data.x_bigint, &val->data.x_bigint, |
| 23050 | bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint, |
| 23052 | 23051 | dest_type->data.integral.bit_count, dest_type->data.integral.is_signed); |
| 23053 | 23052 | return result; |
| 23054 | 23053 | } |
| 23055 | 23054 | |
| 23056 | 23055 | if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) { |
| 23057 | 23056 | IrInstruction *result = ir_const(ira, &instruction->base, dest_type); |
| 23058 | | bigint_init_unsigned(&result->value.data.x_bigint, 0); |
| 23057 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 23059 | 23058 | return result; |
| 23060 | 23059 | } |
| 23061 | 23060 | |
| ... | ... | @@ -23071,7 +23070,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct |
| 23071 | 23070 | |
| 23072 | 23071 | IrInstruction *new_instruction = ir_build_truncate(&ira->new_irb, instruction->base.scope, |
| 23073 | 23072 | instruction->base.source_node, dest_type_value, target); |
| 23074 | | new_instruction->value.type = dest_type; |
| 23073 | new_instruction->value->type = dest_type; |
| 23075 | 23074 | return new_instruction; |
| 23076 | 23075 | } |
| 23077 | 23076 | |
| ... | ... | @@ -23086,12 +23085,12 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct |
| 23086 | 23085 | } |
| 23087 | 23086 | |
| 23088 | 23087 | IrInstruction *target = instruction->target->child; |
| 23089 | | if (type_is_invalid(target->value.type)) |
| 23088 | if (type_is_invalid(target->value->type)) |
| 23090 | 23089 | return ira->codegen->invalid_instruction; |
| 23091 | 23090 | |
| 23092 | | if (target->value.type->id != ZigTypeIdInt && target->value.type->id != ZigTypeIdComptimeInt) { |
| 23091 | if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) { |
| 23093 | 23092 | ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'", |
| 23094 | | buf_ptr(&target->value.type->name))); |
| 23093 | buf_ptr(&target->value->type->name))); |
| 23095 | 23094 | return ira->codegen->invalid_instruction; |
| 23096 | 23095 | } |
| 23097 | 23096 | |
| ... | ... | @@ -23120,15 +23119,15 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru |
| 23120 | 23119 | } |
| 23121 | 23120 | |
| 23122 | 23121 | IrInstruction *target = instruction->target->child; |
| 23123 | | if (type_is_invalid(target->value.type)) |
| 23122 | if (type_is_invalid(target->value->type)) |
| 23124 | 23123 | return ira->codegen->invalid_instruction; |
| 23125 | 23124 | |
| 23126 | | if (target->value.type->id == ZigTypeIdComptimeInt || |
| 23127 | | target->value.type->id == ZigTypeIdComptimeFloat) |
| 23125 | if (target->value->type->id == ZigTypeIdComptimeInt || |
| 23126 | target->value->type->id == ZigTypeIdComptimeFloat) |
| 23128 | 23127 | { |
| 23129 | 23128 | if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) { |
| 23130 | 23129 | CastOp op; |
| 23131 | | if (target->value.type->id == ZigTypeIdComptimeInt) { |
| 23130 | if (target->value->type->id == ZigTypeIdComptimeInt) { |
| 23132 | 23131 | op = CastOpIntToFloat; |
| 23133 | 23132 | } else { |
| 23134 | 23133 | op = CastOpNumLitToConcrete; |
| ... | ... | @@ -23139,9 +23138,9 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru |
| 23139 | 23138 | } |
| 23140 | 23139 | } |
| 23141 | 23140 | |
| 23142 | | if (target->value.type->id != ZigTypeIdFloat) { |
| 23141 | if (target->value->type->id != ZigTypeIdFloat) { |
| 23143 | 23142 | ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", |
| 23144 | | buf_ptr(&target->value.type->name))); |
| 23143 | buf_ptr(&target->value->type->name))); |
| 23145 | 23144 | return ira->codegen->invalid_instruction; |
| 23146 | 23145 | } |
| 23147 | 23146 | |
| ... | ... | @@ -23160,12 +23159,12 @@ static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInst |
| 23160 | 23159 | } |
| 23161 | 23160 | |
| 23162 | 23161 | IrInstruction *target = instruction->target->child; |
| 23163 | | if (type_is_invalid(target->value.type)) |
| 23162 | if (type_is_invalid(target->value->type)) |
| 23164 | 23163 | return ira->codegen->invalid_instruction; |
| 23165 | 23164 | |
| 23166 | | if (target->value.type->id != ZigTypeIdErrorSet) { |
| 23165 | if (target->value->type->id != ZigTypeIdErrorSet) { |
| 23167 | 23166 | ir_add_error(ira, instruction->target, |
| 23168 | | buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name))); |
| 23167 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name))); |
| 23169 | 23168 | return ira->codegen->invalid_instruction; |
| 23170 | 23169 | } |
| 23171 | 23170 | |
| ... | ... | @@ -23180,20 +23179,20 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 23180 | 23179 | return ira->codegen->invalid_instruction; |
| 23181 | 23180 | |
| 23182 | 23181 | IrInstruction *target = instruction->target->child; |
| 23183 | | if (type_is_invalid(target->value.type)) |
| 23182 | if (type_is_invalid(target->value->type)) |
| 23184 | 23183 | return ira->codegen->invalid_instruction; |
| 23185 | 23184 | |
| 23186 | 23185 | bool src_ptr_const; |
| 23187 | 23186 | bool src_ptr_volatile; |
| 23188 | 23187 | uint32_t src_ptr_align; |
| 23189 | | if (target->value.type->id == ZigTypeIdPointer) { |
| 23190 | | src_ptr_const = target->value.type->data.pointer.is_const; |
| 23191 | | src_ptr_volatile = target->value.type->data.pointer.is_volatile; |
| 23188 | if (target->value->type->id == ZigTypeIdPointer) { |
| 23189 | src_ptr_const = target->value->type->data.pointer.is_const; |
| 23190 | src_ptr_volatile = target->value->type->data.pointer.is_volatile; |
| 23192 | 23191 | |
| 23193 | | if ((err = resolve_ptr_align(ira, target->value.type, &src_ptr_align))) |
| 23192 | if ((err = resolve_ptr_align(ira, target->value->type, &src_ptr_align))) |
| 23194 | 23193 | return ira->codegen->invalid_instruction; |
| 23195 | | } else if (is_slice(target->value.type)) { |
| 23196 | | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry; |
| 23194 | } else if (is_slice(target->value->type)) { |
| 23195 | ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry; |
| 23197 | 23196 | src_ptr_const = src_ptr_type->data.pointer.is_const; |
| 23198 | 23197 | src_ptr_volatile = src_ptr_type->data.pointer.is_volatile; |
| 23199 | 23198 | |
| ... | ... | @@ -23203,10 +23202,10 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 23203 | 23202 | src_ptr_const = true; |
| 23204 | 23203 | src_ptr_volatile = false; |
| 23205 | 23204 | |
| 23206 | | if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusAlignmentKnown))) |
| 23205 | if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusAlignmentKnown))) |
| 23207 | 23206 | return ira->codegen->invalid_instruction; |
| 23208 | 23207 | |
| 23209 | | src_ptr_align = get_abi_alignment(ira->codegen, target->value.type); |
| 23208 | src_ptr_align = get_abi_alignment(ira->codegen, target->value->type); |
| 23210 | 23209 | } |
| 23211 | 23210 | |
| 23212 | 23211 | if (src_ptr_align != 0) { |
| ... | ... | @@ -23225,7 +23224,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 23225 | 23224 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 23226 | 23225 | |
| 23227 | 23226 | IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice); |
| 23228 | | if (type_is_invalid(casted_value->value.type)) |
| 23227 | if (type_is_invalid(casted_value->value->type)) |
| 23229 | 23228 | return ira->codegen->invalid_instruction; |
| 23230 | 23229 | |
| 23231 | 23230 | bool have_known_len = false; |
| ... | ... | @@ -23245,12 +23244,12 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 23245 | 23244 | |
| 23246 | 23245 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 23247 | 23246 | dest_slice_type, nullptr, true, false, true); |
| 23248 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) { |
| 23247 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) { |
| 23249 | 23248 | return result_loc; |
| 23250 | 23249 | } |
| 23251 | 23250 | |
| 23252 | | if (casted_value->value.data.rh_slice.id == RuntimeHintSliceIdLen) { |
| 23253 | | known_len = casted_value->value.data.rh_slice.len; |
| 23251 | if (casted_value->value->data.rh_slice.id == RuntimeHintSliceIdLen) { |
| 23252 | known_len = casted_value->value->data.rh_slice.len; |
| 23254 | 23253 | have_known_len = true; |
| 23255 | 23254 | } |
| 23256 | 23255 | |
| ... | ... | @@ -23277,16 +23276,16 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 23277 | 23276 | Error err; |
| 23278 | 23277 | |
| 23279 | 23278 | IrInstruction *target = instruction->target->child; |
| 23280 | | if (type_is_invalid(target->value.type)) |
| 23279 | if (type_is_invalid(target->value->type)) |
| 23281 | 23280 | return ira->codegen->invalid_instruction; |
| 23282 | 23281 | |
| 23283 | | if (!is_slice(target->value.type)) { |
| 23282 | if (!is_slice(target->value->type)) { |
| 23284 | 23283 | ir_add_error(ira, instruction->target, |
| 23285 | | buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value.type->name))); |
| 23284 | buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value->type->name))); |
| 23286 | 23285 | return ira->codegen->invalid_instruction; |
| 23287 | 23286 | } |
| 23288 | 23287 | |
| 23289 | | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry; |
| 23288 | ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry; |
| 23290 | 23289 | |
| 23291 | 23290 | uint32_t alignment; |
| 23292 | 23291 | if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment))) |
| ... | ... | @@ -23303,14 +23302,14 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 23303 | 23302 | return ira->codegen->invalid_instruction; |
| 23304 | 23303 | |
| 23305 | 23304 | IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type); |
| 23306 | | result->value.data.x_struct.fields = alloc_const_vals_ptrs(2); |
| 23305 | result->value->data.x_struct.fields = alloc_const_vals_ptrs(2); |
| 23307 | 23306 | |
| 23308 | | ZigValue *ptr_val = result->value.data.x_struct.fields[slice_ptr_index]; |
| 23307 | ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index]; |
| 23309 | 23308 | ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index]; |
| 23310 | 23309 | copy_const_val(ptr_val, target_ptr_val, false); |
| 23311 | 23310 | ptr_val->type = dest_ptr_type; |
| 23312 | 23311 | |
| 23313 | | ZigValue *len_val = result->value.data.x_struct.fields[slice_len_index]; |
| 23312 | ZigValue *len_val = result->value->data.x_struct.fields[slice_len_index]; |
| 23314 | 23313 | len_val->special = ConstValSpecialStatic; |
| 23315 | 23314 | len_val->type = ira->codegen->builtin_types.entry_usize; |
| 23316 | 23315 | ZigValue *target_len_val = target_val->data.x_struct.fields[slice_len_index]; |
| ... | ... | @@ -23324,7 +23323,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 23324 | 23323 | |
| 23325 | 23324 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 23326 | 23325 | dest_slice_type, nullptr, true, false, true); |
| 23327 | | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 23326 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 23328 | 23327 | return result_loc; |
| 23329 | 23328 | } |
| 23330 | 23329 | |
| ... | ... | @@ -23351,12 +23350,12 @@ static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInst |
| 23351 | 23350 | return ira->codegen->invalid_instruction; |
| 23352 | 23351 | |
| 23353 | 23352 | IrInstruction *target = instruction->target->child; |
| 23354 | | if (type_is_invalid(target->value.type)) |
| 23353 | if (type_is_invalid(target->value->type)) |
| 23355 | 23354 | return ira->codegen->invalid_instruction; |
| 23356 | 23355 | |
| 23357 | | if (target->value.type->id != ZigTypeIdInt && target->value.type->id != ZigTypeIdComptimeInt) { |
| 23356 | if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) { |
| 23358 | 23357 | ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'", |
| 23359 | | buf_ptr(&target->value.type->name))); |
| 23358 | buf_ptr(&target->value->type->name))); |
| 23360 | 23359 | return ira->codegen->invalid_instruction; |
| 23361 | 23360 | } |
| 23362 | 23361 | |
| ... | ... | @@ -23369,16 +23368,16 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst |
| 23369 | 23368 | return ira->codegen->invalid_instruction; |
| 23370 | 23369 | |
| 23371 | 23370 | IrInstruction *target = instruction->target->child; |
| 23372 | | if (type_is_invalid(target->value.type)) |
| 23371 | if (type_is_invalid(target->value->type)) |
| 23373 | 23372 | return ira->codegen->invalid_instruction; |
| 23374 | 23373 | |
| 23375 | | if (target->value.type->id == ZigTypeIdComptimeInt) { |
| 23374 | if (target->value->type->id == ZigTypeIdComptimeInt) { |
| 23376 | 23375 | return ir_implicit_cast(ira, target, dest_type); |
| 23377 | 23376 | } |
| 23378 | 23377 | |
| 23379 | | if (target->value.type->id != ZigTypeIdFloat && target->value.type->id != ZigTypeIdComptimeFloat) { |
| 23378 | if (target->value->type->id != ZigTypeIdFloat && target->value->type->id != ZigTypeIdComptimeFloat) { |
| 23380 | 23379 | ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", |
| 23381 | | buf_ptr(&target->value.type->name))); |
| 23380 | buf_ptr(&target->value->type->name))); |
| 23382 | 23381 | return ira->codegen->invalid_instruction; |
| 23383 | 23382 | } |
| 23384 | 23383 | |
| ... | ... | @@ -23387,15 +23386,15 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst |
| 23387 | 23386 | |
| 23388 | 23387 | static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) { |
| 23389 | 23388 | IrInstruction *target = instruction->target->child; |
| 23390 | | if (type_is_invalid(target->value.type)) |
| 23389 | if (type_is_invalid(target->value->type)) |
| 23391 | 23390 | return ira->codegen->invalid_instruction; |
| 23392 | 23391 | |
| 23393 | 23392 | IrInstruction *casted_target; |
| 23394 | | if (target->value.type->id == ZigTypeIdErrorSet) { |
| 23393 | if (target->value->type->id == ZigTypeIdErrorSet) { |
| 23395 | 23394 | casted_target = target; |
| 23396 | 23395 | } else { |
| 23397 | 23396 | casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set); |
| 23398 | | if (type_is_invalid(casted_target->value.type)) |
| 23397 | if (type_is_invalid(casted_target->value->type)) |
| 23399 | 23398 | return ira->codegen->invalid_instruction; |
| 23400 | 23399 | } |
| 23401 | 23400 | |
| ... | ... | @@ -23404,11 +23403,11 @@ static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstru |
| 23404 | 23403 | |
| 23405 | 23404 | static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) { |
| 23406 | 23405 | IrInstruction *target = instruction->target->child; |
| 23407 | | if (type_is_invalid(target->value.type)) |
| 23406 | if (type_is_invalid(target->value->type)) |
| 23408 | 23407 | return ira->codegen->invalid_instruction; |
| 23409 | 23408 | |
| 23410 | 23409 | IrInstruction *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type); |
| 23411 | | if (type_is_invalid(casted_target->value.type)) |
| 23410 | if (type_is_invalid(casted_target->value->type)) |
| 23412 | 23411 | return ira->codegen->invalid_instruction; |
| 23413 | 23412 | |
| 23414 | 23413 | return ir_analyze_int_to_err(ira, &instruction->base, casted_target, ira->codegen->builtin_types.entry_global_error_set); |
| ... | ... | @@ -23416,12 +23415,12 @@ static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstru |
| 23416 | 23415 | |
| 23417 | 23416 | static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) { |
| 23418 | 23417 | IrInstruction *target = instruction->target->child; |
| 23419 | | if (type_is_invalid(target->value.type)) |
| 23418 | if (type_is_invalid(target->value->type)) |
| 23420 | 23419 | return ira->codegen->invalid_instruction; |
| 23421 | 23420 | |
| 23422 | | if (target->value.type->id != ZigTypeIdBool) { |
| 23421 | if (target->value->type->id != ZigTypeIdBool) { |
| 23423 | 23422 | ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'", |
| 23424 | | buf_ptr(&target->value.type->name))); |
| 23423 | buf_ptr(&target->value->type->name))); |
| 23425 | 23424 | return ira->codegen->invalid_instruction; |
| 23426 | 23425 | } |
| 23427 | 23426 | |
| ... | ... | @@ -23472,48 +23471,48 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23472 | 23471 | ir_assert(is_valid_vector_elem_type(scalar_type), source_instr); |
| 23473 | 23472 | |
| 23474 | 23473 | uint32_t len_mask; |
| 23475 | | if (mask->value.type->id == ZigTypeIdVector) { |
| 23476 | | len_mask = mask->value.type->data.vector.len; |
| 23477 | | } else if (mask->value.type->id == ZigTypeIdArray) { |
| 23478 | | len_mask = mask->value.type->data.array.len; |
| 23474 | if (mask->value->type->id == ZigTypeIdVector) { |
| 23475 | len_mask = mask->value->type->data.vector.len; |
| 23476 | } else if (mask->value->type->id == ZigTypeIdArray) { |
| 23477 | len_mask = mask->value->type->data.array.len; |
| 23479 | 23478 | } else { |
| 23480 | 23479 | ir_add_error(ira, mask, |
| 23481 | 23480 | buf_sprintf("expected vector or array, found '%s'", |
| 23482 | | buf_ptr(&mask->value.type->name))); |
| 23481 | buf_ptr(&mask->value->type->name))); |
| 23483 | 23482 | return ira->codegen->invalid_instruction; |
| 23484 | 23483 | } |
| 23485 | 23484 | mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask, |
| 23486 | 23485 | ira->codegen->builtin_types.entry_i32)); |
| 23487 | | if (type_is_invalid(mask->value.type)) |
| 23486 | if (type_is_invalid(mask->value->type)) |
| 23488 | 23487 | return ira->codegen->invalid_instruction; |
| 23489 | 23488 | |
| 23490 | 23489 | uint32_t len_a; |
| 23491 | | if (a->value.type->id == ZigTypeIdVector) { |
| 23492 | | len_a = a->value.type->data.vector.len; |
| 23493 | | } else if (a->value.type->id == ZigTypeIdArray) { |
| 23494 | | len_a = a->value.type->data.array.len; |
| 23495 | | } else if (a->value.type->id == ZigTypeIdUndefined) { |
| 23490 | if (a->value->type->id == ZigTypeIdVector) { |
| 23491 | len_a = a->value->type->data.vector.len; |
| 23492 | } else if (a->value->type->id == ZigTypeIdArray) { |
| 23493 | len_a = a->value->type->data.array.len; |
| 23494 | } else if (a->value->type->id == ZigTypeIdUndefined) { |
| 23496 | 23495 | len_a = UINT32_MAX; |
| 23497 | 23496 | } else { |
| 23498 | 23497 | ir_add_error(ira, a, |
| 23499 | 23498 | buf_sprintf("expected vector or array with element type '%s', found '%s'", |
| 23500 | 23499 | buf_ptr(&scalar_type->name), |
| 23501 | | buf_ptr(&a->value.type->name))); |
| 23500 | buf_ptr(&a->value->type->name))); |
| 23502 | 23501 | return ira->codegen->invalid_instruction; |
| 23503 | 23502 | } |
| 23504 | 23503 | |
| 23505 | 23504 | uint32_t len_b; |
| 23506 | | if (b->value.type->id == ZigTypeIdVector) { |
| 23507 | | len_b = b->value.type->data.vector.len; |
| 23508 | | } else if (b->value.type->id == ZigTypeIdArray) { |
| 23509 | | len_b = b->value.type->data.array.len; |
| 23510 | | } else if (b->value.type->id == ZigTypeIdUndefined) { |
| 23505 | if (b->value->type->id == ZigTypeIdVector) { |
| 23506 | len_b = b->value->type->data.vector.len; |
| 23507 | } else if (b->value->type->id == ZigTypeIdArray) { |
| 23508 | len_b = b->value->type->data.array.len; |
| 23509 | } else if (b->value->type->id == ZigTypeIdUndefined) { |
| 23511 | 23510 | len_b = UINT32_MAX; |
| 23512 | 23511 | } else { |
| 23513 | 23512 | ir_add_error(ira, b, |
| 23514 | 23513 | buf_sprintf("expected vector or array with element type '%s', found '%s'", |
| 23515 | 23514 | buf_ptr(&scalar_type->name), |
| 23516 | | buf_ptr(&b->value.type->name))); |
| 23515 | buf_ptr(&b->value->type->name))); |
| 23517 | 23516 | return ira->codegen->invalid_instruction; |
| 23518 | 23517 | } |
| 23519 | 23518 | |
| ... | ... | @@ -23526,7 +23525,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23526 | 23525 | a = ir_const_undef(ira, a, get_vector_type(ira->codegen, len_a, scalar_type)); |
| 23527 | 23526 | } else { |
| 23528 | 23527 | a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type)); |
| 23529 | | if (type_is_invalid(a->value.type)) |
| 23528 | if (type_is_invalid(a->value->type)) |
| 23530 | 23529 | return ira->codegen->invalid_instruction; |
| 23531 | 23530 | } |
| 23532 | 23531 | |
| ... | ... | @@ -23535,7 +23534,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23535 | 23534 | b = ir_const_undef(ira, b, get_vector_type(ira->codegen, len_b, scalar_type)); |
| 23536 | 23535 | } else { |
| 23537 | 23536 | b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type)); |
| 23538 | | if (type_is_invalid(b->value.type)) |
| 23537 | if (type_is_invalid(b->value->type)) |
| 23539 | 23538 | return ira->codegen->invalid_instruction; |
| 23540 | 23539 | } |
| 23541 | 23540 | |
| ... | ... | @@ -23559,12 +23558,12 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23559 | 23558 | v = (uint32_t)~v_i32; |
| 23560 | 23559 | chosen_operand = b; |
| 23561 | 23560 | } |
| 23562 | | if (v >= chosen_operand->value.type->data.vector.len) { |
| 23561 | if (v >= chosen_operand->value->type->data.vector.len) { |
| 23563 | 23562 | ErrorMsg *msg = ir_add_error(ira, mask, |
| 23564 | 23563 | buf_sprintf("mask index '%u' has out-of-bounds selection", i)); |
| 23565 | 23564 | add_error_note(ira->codegen, msg, chosen_operand->source_node, |
| 23566 | 23565 | buf_sprintf("selected index '%u' out of bounds of %s", v, |
| 23567 | | buf_ptr(&chosen_operand->value.type->name))); |
| 23566 | buf_ptr(&chosen_operand->value->type->name))); |
| 23568 | 23567 | if (chosen_operand == a && v < len_a + len_b) { |
| 23569 | 23568 | add_error_note(ira->codegen, msg, b->source_node, |
| 23570 | 23569 | buf_create_from_str("selections from the second vector are specified with negative numbers")); |
| ... | ... | @@ -23587,10 +23586,10 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23587 | 23586 | expand_undef_array(ira->codegen, b_val); |
| 23588 | 23587 | |
| 23589 | 23588 | IrInstruction *result = ir_const(ira, source_instr, result_type); |
| 23590 | | result->value.data.x_array.data.s_none.elements = create_const_vals(len_mask); |
| 23589 | result->value->data.x_array.data.s_none.elements = create_const_vals(len_mask); |
| 23591 | 23590 | for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) { |
| 23592 | 23591 | ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i]; |
| 23593 | | ZigValue *result_elem_val = &result->value.data.x_array.data.s_none.elements[i]; |
| 23592 | ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i]; |
| 23594 | 23593 | if (mask_elem_val->special == ConstValSpecialUndef) { |
| 23595 | 23594 | result_elem_val->special = ConstValSpecialUndef; |
| 23596 | 23595 | continue; |
| ... | ... | @@ -23598,13 +23597,13 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23598 | 23597 | int32_t v = bigint_as_signed(&mask_elem_val->data.x_bigint); |
| 23599 | 23598 | // We've already checked for and emitted compile errors for index out of bounds here. |
| 23600 | 23599 | ZigValue *src_elem_val = (v >= 0) ? |
| 23601 | | &a->value.data.x_array.data.s_none.elements[v] : |
| 23602 | | &b->value.data.x_array.data.s_none.elements[~v]; |
| 23600 | &a->value->data.x_array.data.s_none.elements[v] : |
| 23601 | &b->value->data.x_array.data.s_none.elements[~v]; |
| 23603 | 23602 | copy_const_val(result_elem_val, src_elem_val, false); |
| 23604 | 23603 | |
| 23605 | 23604 | ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr); |
| 23606 | 23605 | } |
| 23607 | | result->value.special = ConstValSpecialStatic; |
| 23606 | result->value->special = ConstValSpecialStatic; |
| 23608 | 23607 | return result; |
| 23609 | 23608 | } |
| 23610 | 23609 | |
| ... | ... | @@ -23620,12 +23619,12 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23620 | 23619 | |
| 23621 | 23620 | IrInstruction *expand_mask = ir_const(ira, mask, |
| 23622 | 23621 | get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32)); |
| 23623 | | expand_mask->value.data.x_array.data.s_none.elements = create_const_vals(len_max); |
| 23622 | expand_mask->value->data.x_array.data.s_none.elements = create_const_vals(len_max); |
| 23624 | 23623 | uint32_t i = 0; |
| 23625 | 23624 | for (; i < len_min; i += 1) |
| 23626 | | bigint_init_unsigned(&expand_mask->value.data.x_array.data.s_none.elements[i].data.x_bigint, i); |
| 23625 | bigint_init_unsigned(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, i); |
| 23627 | 23626 | for (; i < len_max; i += 1) |
| 23628 | | bigint_init_signed(&expand_mask->value.data.x_array.data.s_none.elements[i].data.x_bigint, -1); |
| 23627 | bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1); |
| 23629 | 23628 | |
| 23630 | 23629 | IrInstruction *undef = ir_const_undef(ira, source_instr, |
| 23631 | 23630 | get_vector_type(ira->codegen, len_min, scalar_type)); |
| ... | ... | @@ -23640,7 +23639,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23640 | 23639 | IrInstruction *result = ir_build_shuffle_vector(&ira->new_irb, |
| 23641 | 23640 | source_instr->scope, source_instr->source_node, |
| 23642 | 23641 | nullptr, a, b, mask); |
| 23643 | | result->value.type = result_type; |
| 23642 | result->value->type = result_type; |
| 23644 | 23643 | return result; |
| 23645 | 23644 | } |
| 23646 | 23645 | |
| ... | ... | @@ -23650,15 +23649,15 @@ static IrInstruction *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrIn |
| 23650 | 23649 | return ira->codegen->invalid_instruction; |
| 23651 | 23650 | |
| 23652 | 23651 | IrInstruction *a = instruction->a->child; |
| 23653 | | if (type_is_invalid(a->value.type)) |
| 23652 | if (type_is_invalid(a->value->type)) |
| 23654 | 23653 | return ira->codegen->invalid_instruction; |
| 23655 | 23654 | |
| 23656 | 23655 | IrInstruction *b = instruction->b->child; |
| 23657 | | if (type_is_invalid(b->value.type)) |
| 23656 | if (type_is_invalid(b->value->type)) |
| 23658 | 23657 | return ira->codegen->invalid_instruction; |
| 23659 | 23658 | |
| 23660 | 23659 | IrInstruction *mask = instruction->mask->child; |
| 23661 | | if (type_is_invalid(mask->value.type)) |
| 23660 | if (type_is_invalid(mask->value->type)) |
| 23662 | 23661 | return ira->codegen->invalid_instruction; |
| 23663 | 23662 | |
| 23664 | 23663 | return ir_analyze_shuffle_vector(ira, &instruction->base, scalar_type, a, b, mask); |
| ... | ... | @@ -23668,11 +23667,11 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction |
| 23668 | 23667 | Error err; |
| 23669 | 23668 | |
| 23670 | 23669 | IrInstruction *len = instruction->len->child; |
| 23671 | | if (type_is_invalid(len->value.type)) |
| 23670 | if (type_is_invalid(len->value->type)) |
| 23672 | 23671 | return ira->codegen->invalid_instruction; |
| 23673 | 23672 | |
| 23674 | 23673 | IrInstruction *scalar = instruction->scalar->child; |
| 23675 | | if (type_is_invalid(scalar->value.type)) |
| 23674 | if (type_is_invalid(scalar->value->type)) |
| 23676 | 23675 | return ira->codegen->invalid_instruction; |
| 23677 | 23676 | |
| 23678 | 23677 | uint64_t len_u64; |
| ... | ... | @@ -23680,10 +23679,10 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction |
| 23680 | 23679 | return ira->codegen->invalid_instruction; |
| 23681 | 23680 | uint32_t len_int = len_u64; |
| 23682 | 23681 | |
| 23683 | | if ((err = ir_validate_vector_elem_type(ira, scalar, scalar->value.type))) |
| 23682 | if ((err = ir_validate_vector_elem_type(ira, scalar, scalar->value->type))) |
| 23684 | 23683 | return ira->codegen->invalid_instruction; |
| 23685 | 23684 | |
| 23686 | | ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value.type); |
| 23685 | ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type); |
| 23687 | 23686 | |
| 23688 | 23687 | if (instr_is_comptime(scalar)) { |
| 23689 | 23688 | ZigValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk); |
| ... | ... | @@ -23693,9 +23692,9 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction |
| 23693 | 23692 | return ir_const_undef(ira, &instruction->base, return_type); |
| 23694 | 23693 | |
| 23695 | 23694 | IrInstruction *result = ir_const(ira, &instruction->base, return_type); |
| 23696 | | result->value.data.x_array.data.s_none.elements = create_const_vals(len_int); |
| 23695 | result->value->data.x_array.data.s_none.elements = create_const_vals(len_int); |
| 23697 | 23696 | for (uint32_t i = 0; i < len_int; i += 1) { |
| 23698 | | copy_const_val(&result->value.data.x_array.data.s_none.elements[i], scalar_val, false); |
| 23697 | copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val, false); |
| 23699 | 23698 | } |
| 23700 | 23699 | return result; |
| 23701 | 23700 | } |
| ... | ... | @@ -23705,13 +23704,13 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction |
| 23705 | 23704 | |
| 23706 | 23705 | static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) { |
| 23707 | 23706 | IrInstruction *value = instruction->value->child; |
| 23708 | | if (type_is_invalid(value->value.type)) |
| 23707 | if (type_is_invalid(value->value->type)) |
| 23709 | 23708 | return ira->codegen->invalid_instruction; |
| 23710 | 23709 | |
| 23711 | 23710 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 23712 | 23711 | |
| 23713 | 23712 | IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type); |
| 23714 | | if (type_is_invalid(casted_value->value.type)) |
| 23713 | if (type_is_invalid(casted_value->value->type)) |
| 23715 | 23714 | return ira->codegen->invalid_instruction; |
| 23716 | 23715 | |
| 23717 | 23716 | if (instr_is_comptime(casted_value)) { |
| ... | ... | @@ -23724,7 +23723,7 @@ static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruct |
| 23724 | 23723 | |
| 23725 | 23724 | IrInstruction *result = ir_build_bool_not(&ira->new_irb, instruction->base.scope, |
| 23726 | 23725 | instruction->base.source_node, casted_value); |
| 23727 | | result->value.type = bool_type; |
| 23726 | result->value->type = bool_type; |
| 23728 | 23727 | return result; |
| 23729 | 23728 | } |
| 23730 | 23729 | |
| ... | ... | @@ -23732,18 +23731,18 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 23732 | 23731 | Error err; |
| 23733 | 23732 | |
| 23734 | 23733 | IrInstruction *dest_ptr = instruction->dest_ptr->child; |
| 23735 | | if (type_is_invalid(dest_ptr->value.type)) |
| 23734 | if (type_is_invalid(dest_ptr->value->type)) |
| 23736 | 23735 | return ira->codegen->invalid_instruction; |
| 23737 | 23736 | |
| 23738 | 23737 | IrInstruction *byte_value = instruction->byte->child; |
| 23739 | | if (type_is_invalid(byte_value->value.type)) |
| 23738 | if (type_is_invalid(byte_value->value->type)) |
| 23740 | 23739 | return ira->codegen->invalid_instruction; |
| 23741 | 23740 | |
| 23742 | 23741 | IrInstruction *count_value = instruction->count->child; |
| 23743 | | if (type_is_invalid(count_value->value.type)) |
| 23742 | if (type_is_invalid(count_value->value->type)) |
| 23744 | 23743 | return ira->codegen->invalid_instruction; |
| 23745 | 23744 | |
| 23746 | | ZigType *dest_uncasted_type = dest_ptr->value.type; |
| 23745 | ZigType *dest_uncasted_type = dest_ptr->value->type; |
| 23747 | 23746 | bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && |
| 23748 | 23747 | dest_uncasted_type->data.pointer.is_volatile; |
| 23749 | 23748 | |
| ... | ... | @@ -23760,15 +23759,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 23760 | 23759 | PtrLenUnknown, dest_align, 0, 0, false); |
| 23761 | 23760 | |
| 23762 | 23761 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr); |
| 23763 | | if (type_is_invalid(casted_dest_ptr->value.type)) |
| 23762 | if (type_is_invalid(casted_dest_ptr->value->type)) |
| 23764 | 23763 | return ira->codegen->invalid_instruction; |
| 23765 | 23764 | |
| 23766 | 23765 | IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8); |
| 23767 | | if (type_is_invalid(casted_byte->value.type)) |
| 23766 | if (type_is_invalid(casted_byte->value->type)) |
| 23768 | 23767 | return ira->codegen->invalid_instruction; |
| 23769 | 23768 | |
| 23770 | 23769 | IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 23771 | | if (type_is_invalid(casted_count->value.type)) |
| 23770 | if (type_is_invalid(casted_count->value->type)) |
| 23772 | 23771 | return ira->codegen->invalid_instruction; |
| 23773 | 23772 | |
| 23774 | 23773 | // TODO test this at comptime with u8 and non-u8 types |
| ... | ... | @@ -23788,8 +23787,8 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 23788 | 23787 | if (count_val == nullptr) |
| 23789 | 23788 | return ira->codegen->invalid_instruction; |
| 23790 | 23789 | |
| 23791 | | if (casted_dest_ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr && |
| 23792 | | casted_dest_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 23790 | if (casted_dest_ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr && |
| 23791 | casted_dest_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 23793 | 23792 | { |
| 23794 | 23793 | ZigValue *dest_elements; |
| 23795 | 23794 | size_t start; |
| ... | ... | @@ -23845,7 +23844,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 23845 | 23844 | |
| 23846 | 23845 | IrInstruction *result = ir_build_memset(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 23847 | 23846 | casted_dest_ptr, casted_byte, casted_count); |
| 23848 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 23847 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 23849 | 23848 | return result; |
| 23850 | 23849 | } |
| 23851 | 23850 | |
| ... | ... | @@ -23853,20 +23852,20 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 23853 | 23852 | Error err; |
| 23854 | 23853 | |
| 23855 | 23854 | IrInstruction *dest_ptr = instruction->dest_ptr->child; |
| 23856 | | if (type_is_invalid(dest_ptr->value.type)) |
| 23855 | if (type_is_invalid(dest_ptr->value->type)) |
| 23857 | 23856 | return ira->codegen->invalid_instruction; |
| 23858 | 23857 | |
| 23859 | 23858 | IrInstruction *src_ptr = instruction->src_ptr->child; |
| 23860 | | if (type_is_invalid(src_ptr->value.type)) |
| 23859 | if (type_is_invalid(src_ptr->value->type)) |
| 23861 | 23860 | return ira->codegen->invalid_instruction; |
| 23862 | 23861 | |
| 23863 | 23862 | IrInstruction *count_value = instruction->count->child; |
| 23864 | | if (type_is_invalid(count_value->value.type)) |
| 23863 | if (type_is_invalid(count_value->value->type)) |
| 23865 | 23864 | return ira->codegen->invalid_instruction; |
| 23866 | 23865 | |
| 23867 | 23866 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 23868 | | ZigType *dest_uncasted_type = dest_ptr->value.type; |
| 23869 | | ZigType *src_uncasted_type = src_ptr->value.type; |
| 23867 | ZigType *dest_uncasted_type = dest_ptr->value->type; |
| 23868 | ZigType *src_uncasted_type = src_ptr->value->type; |
| 23870 | 23869 | bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && |
| 23871 | 23870 | dest_uncasted_type->data.pointer.is_volatile; |
| 23872 | 23871 | bool src_is_volatile = (src_uncasted_type->id == ZigTypeIdPointer) && |
| ... | ... | @@ -23895,15 +23894,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 23895 | 23894 | PtrLenUnknown, src_align, 0, 0, false); |
| 23896 | 23895 | |
| 23897 | 23896 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut); |
| 23898 | | if (type_is_invalid(casted_dest_ptr->value.type)) |
| 23897 | if (type_is_invalid(casted_dest_ptr->value->type)) |
| 23899 | 23898 | return ira->codegen->invalid_instruction; |
| 23900 | 23899 | |
| 23901 | 23900 | IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const); |
| 23902 | | if (type_is_invalid(casted_src_ptr->value.type)) |
| 23901 | if (type_is_invalid(casted_src_ptr->value->type)) |
| 23903 | 23902 | return ira->codegen->invalid_instruction; |
| 23904 | 23903 | |
| 23905 | 23904 | IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 23906 | | if (type_is_invalid(casted_count->value.type)) |
| 23905 | if (type_is_invalid(casted_count->value->type)) |
| 23907 | 23906 | return ira->codegen->invalid_instruction; |
| 23908 | 23907 | |
| 23909 | 23908 | // TODO test this at comptime with u8 and non-u8 types |
| ... | ... | @@ -24024,35 +24023,35 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 24024 | 24023 | |
| 24025 | 24024 | IrInstruction *result = ir_build_memcpy(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 24026 | 24025 | casted_dest_ptr, casted_src_ptr, casted_count); |
| 24027 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 24026 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 24028 | 24027 | return result; |
| 24029 | 24028 | } |
| 24030 | 24029 | |
| 24031 | 24030 | static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSliceSrc *instruction) { |
| 24032 | 24031 | IrInstruction *ptr_ptr = instruction->ptr->child; |
| 24033 | | if (type_is_invalid(ptr_ptr->value.type)) |
| 24032 | if (type_is_invalid(ptr_ptr->value->type)) |
| 24034 | 24033 | return ira->codegen->invalid_instruction; |
| 24035 | 24034 | |
| 24036 | | ZigType *ptr_ptr_type = ptr_ptr->value.type; |
| 24035 | ZigType *ptr_ptr_type = ptr_ptr->value->type; |
| 24037 | 24036 | assert(ptr_ptr_type->id == ZigTypeIdPointer); |
| 24038 | 24037 | ZigType *array_type = ptr_ptr_type->data.pointer.child_type; |
| 24039 | 24038 | |
| 24040 | 24039 | IrInstruction *start = instruction->start->child; |
| 24041 | | if (type_is_invalid(start->value.type)) |
| 24040 | if (type_is_invalid(start->value->type)) |
| 24042 | 24041 | return ira->codegen->invalid_instruction; |
| 24043 | 24042 | |
| 24044 | 24043 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 24045 | 24044 | IrInstruction *casted_start = ir_implicit_cast(ira, start, usize); |
| 24046 | | if (type_is_invalid(casted_start->value.type)) |
| 24045 | if (type_is_invalid(casted_start->value->type)) |
| 24047 | 24046 | return ira->codegen->invalid_instruction; |
| 24048 | 24047 | |
| 24049 | 24048 | IrInstruction *end; |
| 24050 | 24049 | if (instruction->end) { |
| 24051 | 24050 | end = instruction->end->child; |
| 24052 | | if (type_is_invalid(end->value.type)) |
| 24051 | if (type_is_invalid(end->value->type)) |
| 24053 | 24052 | return ira->codegen->invalid_instruction; |
| 24054 | 24053 | end = ir_implicit_cast(ira, end, usize); |
| 24055 | | if (type_is_invalid(end->value.type)) |
| 24054 | if (type_is_invalid(end->value->type)) |
| 24056 | 24055 | return ira->codegen->invalid_instruction; |
| 24057 | 24056 | } else { |
| 24058 | 24057 | end = nullptr; |
| ... | ... | @@ -24061,8 +24060,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24061 | 24060 | ZigType *return_type; |
| 24062 | 24061 | |
| 24063 | 24062 | if (array_type->id == ZigTypeIdArray) { |
| 24064 | | bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic && |
| 24065 | | ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst; |
| 24063 | bool is_comptime_const = ptr_ptr->value->special == ConstValSpecialStatic && |
| 24064 | ptr_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst; |
| 24066 | 24065 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type, |
| 24067 | 24066 | ptr_ptr_type->data.pointer.is_const || is_comptime_const, |
| 24068 | 24067 | ptr_ptr_type->data.pointer.is_volatile, |
| ... | ... | @@ -24103,8 +24102,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24103 | 24102 | } |
| 24104 | 24103 | |
| 24105 | 24104 | if (instr_is_comptime(ptr_ptr) && |
| 24106 | | value_is_comptime(&casted_start->value) && |
| 24107 | | (!end || value_is_comptime(&end->value))) |
| 24105 | value_is_comptime(casted_start->value) && |
| 24106 | (!end || value_is_comptime(end->value))) |
| 24108 | 24107 | { |
| 24109 | 24108 | ZigValue *array_val; |
| 24110 | 24109 | ZigValue *parent_ptr; |
| ... | ... | @@ -24117,7 +24116,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24117 | 24116 | if (array_type->id == ZigTypeIdPointer) { |
| 24118 | 24117 | ZigType *child_array_type = array_type->data.pointer.child_type; |
| 24119 | 24118 | assert(child_array_type->id == ZigTypeIdArray); |
| 24120 | | parent_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); |
| 24119 | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 24121 | 24120 | if (parent_ptr == nullptr) |
| 24122 | 24121 | return ira->codegen->invalid_instruction; |
| 24123 | 24122 | |
| ... | ... | @@ -24136,7 +24135,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24136 | 24135 | abs_offset = 0; |
| 24137 | 24136 | } |
| 24138 | 24137 | } else { |
| 24139 | | array_val = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); |
| 24138 | array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 24140 | 24139 | if (array_val == nullptr) |
| 24141 | 24140 | return ira->codegen->invalid_instruction; |
| 24142 | 24141 | rel_end = array_type->data.array.len; |
| ... | ... | @@ -24145,7 +24144,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24145 | 24144 | } |
| 24146 | 24145 | } else if (array_type->id == ZigTypeIdPointer) { |
| 24147 | 24146 | assert(array_type->data.pointer.ptr_len == PtrLenUnknown); |
| 24148 | | parent_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); |
| 24147 | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 24149 | 24148 | if (parent_ptr == nullptr) |
| 24150 | 24149 | return ira->codegen->invalid_instruction; |
| 24151 | 24150 | |
| ... | ... | @@ -24193,7 +24192,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24193 | 24192 | zig_panic("TODO slice of null ptr"); |
| 24194 | 24193 | } |
| 24195 | 24194 | } else if (is_slice(array_type)) { |
| 24196 | | ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); |
| 24195 | ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 24197 | 24196 | if (slice_ptr == nullptr) |
| 24198 | 24197 | return ira->codegen->invalid_instruction; |
| 24199 | 24198 | |
| ... | ... | @@ -24279,7 +24278,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24279 | 24278 | } |
| 24280 | 24279 | |
| 24281 | 24280 | IrInstruction *result = ir_const(ira, &instruction->base, return_type); |
| 24282 | | ZigValue *out_val = &result->value; |
| 24281 | ZigValue *out_val = result->value; |
| 24283 | 24282 | out_val->data.x_struct.fields = alloc_const_vals_ptrs(2); |
| 24284 | 24283 | |
| 24285 | 24284 | ZigValue *ptr_val = out_val->data.x_struct.fields[slice_ptr_index]; |
| ... | ... | @@ -24289,7 +24288,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24289 | 24288 | bool is_const = slice_is_const(return_type); |
| 24290 | 24289 | init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const, PtrLenUnknown); |
| 24291 | 24290 | if (array_type->id == ZigTypeIdArray) { |
| 24292 | | ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut; |
| 24291 | ptr_val->data.x_ptr.mut = ptr_ptr->value->data.x_ptr.mut; |
| 24293 | 24292 | } else if (is_slice(array_type)) { |
| 24294 | 24293 | ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut; |
| 24295 | 24294 | } else if (array_type->id == ZigTypeIdPointer) { |
| ... | ... | @@ -24337,7 +24336,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24337 | 24336 | |
| 24338 | 24337 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 24339 | 24338 | return_type, nullptr, true, false, true); |
| 24340 | | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 24339 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 24341 | 24340 | return result_loc; |
| 24342 | 24341 | } |
| 24343 | 24342 | return ir_build_slice_gen(ira, &instruction->base, return_type, |
| ... | ... | @@ -24347,7 +24346,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24347 | 24346 | static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) { |
| 24348 | 24347 | Error err; |
| 24349 | 24348 | IrInstruction *container = instruction->container->child; |
| 24350 | | if (type_is_invalid(container->value.type)) |
| 24349 | if (type_is_invalid(container->value->type)) |
| 24351 | 24350 | return ira->codegen->invalid_instruction; |
| 24352 | 24351 | ZigType *container_type = ir_resolve_type(ira, container); |
| 24353 | 24352 | |
| ... | ... | @@ -24448,7 +24447,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr |
| 24448 | 24447 | TypeStructField *field = container_type->data.structure.fields[member_index]; |
| 24449 | 24448 | |
| 24450 | 24449 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 24451 | | init_const_str_lit(ira->codegen, &result->value, field->name); |
| 24450 | init_const_str_lit(ira->codegen, result->value, field->name); |
| 24452 | 24451 | return result; |
| 24453 | 24452 | } else if (container_type->id == ZigTypeIdEnum) { |
| 24454 | 24453 | if (member_index >= container_type->data.enumeration.src_field_count) { |
| ... | ... | @@ -24460,7 +24459,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr |
| 24460 | 24459 | TypeEnumField *field = &container_type->data.enumeration.fields[member_index]; |
| 24461 | 24460 | |
| 24462 | 24461 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 24463 | | init_const_str_lit(ira->codegen, &result->value, field->name); |
| 24462 | init_const_str_lit(ira->codegen, result->value, field->name); |
| 24464 | 24463 | return result; |
| 24465 | 24464 | } else if (container_type->id == ZigTypeIdUnion) { |
| 24466 | 24465 | if (member_index >= container_type->data.unionation.src_field_count) { |
| ... | ... | @@ -24472,7 +24471,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr |
| 24472 | 24471 | TypeUnionField *field = &container_type->data.unionation.fields[member_index]; |
| 24473 | 24472 | |
| 24474 | 24473 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 24475 | | init_const_str_lit(ira->codegen, &result->value, field->name); |
| 24474 | init_const_str_lit(ira->codegen, result->value, field->name); |
| 24476 | 24475 | return result; |
| 24477 | 24476 | } else { |
| 24478 | 24477 | ir_add_error(ira, container_type_value, |
| ... | ... | @@ -24512,21 +24511,21 @@ static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstruc |
| 24512 | 24511 | static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) { |
| 24513 | 24512 | IrInstruction *result = ir_build_breakpoint(&ira->new_irb, |
| 24514 | 24513 | instruction->base.scope, instruction->base.source_node); |
| 24515 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 24514 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 24516 | 24515 | return result; |
| 24517 | 24516 | } |
| 24518 | 24517 | |
| 24519 | 24518 | static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) { |
| 24520 | 24519 | IrInstruction *result = ir_build_return_address(&ira->new_irb, |
| 24521 | 24520 | instruction->base.scope, instruction->base.source_node); |
| 24522 | | result->value.type = ira->codegen->builtin_types.entry_usize; |
| 24521 | result->value->type = ira->codegen->builtin_types.entry_usize; |
| 24523 | 24522 | return result; |
| 24524 | 24523 | } |
| 24525 | 24524 | |
| 24526 | 24525 | static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) { |
| 24527 | 24526 | IrInstruction *result = ir_build_frame_address(&ira->new_irb, |
| 24528 | 24527 | instruction->base.scope, instruction->base.source_node); |
| 24529 | | result->value.type = ira->codegen->builtin_types.entry_usize; |
| 24528 | result->value->type = ira->codegen->builtin_types.entry_usize; |
| 24530 | 24529 | return result; |
| 24531 | 24530 | } |
| 24532 | 24531 | |
| ... | ... | @@ -24542,7 +24541,7 @@ static IrInstruction *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInst |
| 24542 | 24541 | ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false); |
| 24543 | 24542 | |
| 24544 | 24543 | IrInstruction *result = ir_build_handle(&ira->new_irb, instruction->base.scope, instruction->base.source_node); |
| 24545 | | result->value.type = ptr_frame_type; |
| 24544 | result->value->type = ptr_frame_type; |
| 24546 | 24545 | return result; |
| 24547 | 24546 | } |
| 24548 | 24547 | |
| ... | ... | @@ -24563,12 +24562,12 @@ static IrInstruction *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstru |
| 24563 | 24562 | |
| 24564 | 24563 | static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstructionFrameSizeSrc *instruction) { |
| 24565 | 24564 | IrInstruction *fn = instruction->fn->child; |
| 24566 | | if (type_is_invalid(fn->value.type)) |
| 24565 | if (type_is_invalid(fn->value->type)) |
| 24567 | 24566 | return ira->codegen->invalid_instruction; |
| 24568 | 24567 | |
| 24569 | | if (fn->value.type->id != ZigTypeIdFn) { |
| 24568 | if (fn->value->type->id != ZigTypeIdFn) { |
| 24570 | 24569 | ir_add_error(ira, fn, |
| 24571 | | buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value.type->name))); |
| 24570 | buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name))); |
| 24572 | 24571 | return ira->codegen->invalid_instruction; |
| 24573 | 24572 | } |
| 24574 | 24573 | |
| ... | ... | @@ -24576,7 +24575,7 @@ static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstru |
| 24576 | 24575 | |
| 24577 | 24576 | IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope, |
| 24578 | 24577 | instruction->base.source_node, fn); |
| 24579 | | result->value.type = ira->codegen->builtin_types.entry_usize; |
| 24578 | result->value->type = ira->codegen->builtin_types.entry_usize; |
| 24580 | 24579 | return result; |
| 24581 | 24580 | } |
| 24582 | 24581 | |
| ... | ... | @@ -24587,11 +24586,11 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct |
| 24587 | 24586 | // field: []align(@alignOf(Node)) Node, |
| 24588 | 24587 | // }; |
| 24589 | 24588 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 24590 | | result->value.special = ConstValSpecialLazy; |
| 24589 | result->value->special = ConstValSpecialLazy; |
| 24591 | 24590 | |
| 24592 | 24591 | LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1); |
| 24593 | 24592 | lazy_align_of->ira = ira; |
| 24594 | | result->value.data.x_lazy = &lazy_align_of->base; |
| 24593 | result->value->data.x_lazy = &lazy_align_of->base; |
| 24595 | 24594 | lazy_align_of->base.id = LazyValueIdAlignOf; |
| 24596 | 24595 | |
| 24597 | 24596 | lazy_align_of->target_type = instruction->type_value->child; |
| ... | ... | @@ -24605,7 +24604,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 24605 | 24604 | Error err; |
| 24606 | 24605 | |
| 24607 | 24606 | IrInstruction *type_value = instruction->type_value->child; |
| 24608 | | if (type_is_invalid(type_value->value.type)) |
| 24607 | if (type_is_invalid(type_value->value->type)) |
| 24609 | 24608 | return ira->codegen->invalid_instruction; |
| 24610 | 24609 | |
| 24611 | 24610 | ZigType *dest_type = ir_resolve_type(ira, type_value); |
| ... | ... | @@ -24619,15 +24618,15 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 24619 | 24618 | } |
| 24620 | 24619 | |
| 24621 | 24620 | IrInstruction *op1 = instruction->op1->child; |
| 24622 | | if (type_is_invalid(op1->value.type)) |
| 24621 | if (type_is_invalid(op1->value->type)) |
| 24623 | 24622 | return ira->codegen->invalid_instruction; |
| 24624 | 24623 | |
| 24625 | 24624 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 24626 | | if (type_is_invalid(casted_op1->value.type)) |
| 24625 | if (type_is_invalid(casted_op1->value->type)) |
| 24627 | 24626 | return ira->codegen->invalid_instruction; |
| 24628 | 24627 | |
| 24629 | 24628 | IrInstruction *op2 = instruction->op2->child; |
| 24630 | | if (type_is_invalid(op2->value.type)) |
| 24629 | if (type_is_invalid(op2->value->type)) |
| 24631 | 24630 | return ira->codegen->invalid_instruction; |
| 24632 | 24631 | |
| 24633 | 24632 | IrInstruction *casted_op2; |
| ... | ... | @@ -24638,20 +24637,20 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 24638 | 24637 | } else { |
| 24639 | 24638 | casted_op2 = ir_implicit_cast(ira, op2, dest_type); |
| 24640 | 24639 | } |
| 24641 | | if (type_is_invalid(casted_op2->value.type)) |
| 24640 | if (type_is_invalid(casted_op2->value->type)) |
| 24642 | 24641 | return ira->codegen->invalid_instruction; |
| 24643 | 24642 | |
| 24644 | 24643 | IrInstruction *result_ptr = instruction->result_ptr->child; |
| 24645 | | if (type_is_invalid(result_ptr->value.type)) |
| 24644 | if (type_is_invalid(result_ptr->value->type)) |
| 24646 | 24645 | return ira->codegen->invalid_instruction; |
| 24647 | 24646 | |
| 24648 | 24647 | ZigType *expected_ptr_type; |
| 24649 | | if (result_ptr->value.type->id == ZigTypeIdPointer) { |
| 24648 | if (result_ptr->value->type->id == ZigTypeIdPointer) { |
| 24650 | 24649 | uint32_t alignment; |
| 24651 | | if ((err = resolve_ptr_align(ira, result_ptr->value.type, &alignment))) |
| 24650 | if ((err = resolve_ptr_align(ira, result_ptr->value->type, &alignment))) |
| 24652 | 24651 | return ira->codegen->invalid_instruction; |
| 24653 | 24652 | expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, |
| 24654 | | false, result_ptr->value.type->data.pointer.is_volatile, |
| 24653 | false, result_ptr->value->type->data.pointer.is_volatile, |
| 24655 | 24654 | PtrLenSingle, |
| 24656 | 24655 | alignment, 0, 0, false); |
| 24657 | 24656 | } else { |
| ... | ... | @@ -24659,7 +24658,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 24659 | 24658 | } |
| 24660 | 24659 | |
| 24661 | 24660 | IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type); |
| 24662 | | if (type_is_invalid(casted_result_ptr->value.type)) |
| 24661 | if (type_is_invalid(casted_result_ptr->value->type)) |
| 24663 | 24662 | return ira->codegen->invalid_instruction; |
| 24664 | 24663 | |
| 24665 | 24664 | if (instr_is_comptime(casted_op1) && |
| ... | ... | @@ -24716,7 +24715,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 24716 | 24715 | IrInstruction *result = ir_build_overflow_op(&ira->new_irb, |
| 24717 | 24716 | instruction->base.scope, instruction->base.source_node, |
| 24718 | 24717 | instruction->op, type_value, casted_op1, casted_op2, casted_result_ptr, dest_type); |
| 24719 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 24718 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 24720 | 24719 | return result; |
| 24721 | 24720 | } |
| 24722 | 24721 | |
| ... | ... | @@ -24749,7 +24748,7 @@ static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, Z |
| 24749 | 24748 | |
| 24750 | 24749 | static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructionMulAdd *instruction) { |
| 24751 | 24750 | IrInstruction *type_value = instruction->type_value->child; |
| 24752 | | if (type_is_invalid(type_value->value.type)) |
| 24751 | if (type_is_invalid(type_value->value->type)) |
| 24753 | 24752 | return ira->codegen->invalid_instruction; |
| 24754 | 24753 | |
| 24755 | 24754 | ZigType *expr_type = ir_resolve_type(ira, type_value); |
| ... | ... | @@ -24765,27 +24764,27 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi |
| 24765 | 24764 | } |
| 24766 | 24765 | |
| 24767 | 24766 | IrInstruction *op1 = instruction->op1->child; |
| 24768 | | if (type_is_invalid(op1->value.type)) |
| 24767 | if (type_is_invalid(op1->value->type)) |
| 24769 | 24768 | return ira->codegen->invalid_instruction; |
| 24770 | 24769 | |
| 24771 | 24770 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, expr_type); |
| 24772 | | if (type_is_invalid(casted_op1->value.type)) |
| 24771 | if (type_is_invalid(casted_op1->value->type)) |
| 24773 | 24772 | return ira->codegen->invalid_instruction; |
| 24774 | 24773 | |
| 24775 | 24774 | IrInstruction *op2 = instruction->op2->child; |
| 24776 | | if (type_is_invalid(op2->value.type)) |
| 24775 | if (type_is_invalid(op2->value->type)) |
| 24777 | 24776 | return ira->codegen->invalid_instruction; |
| 24778 | 24777 | |
| 24779 | 24778 | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, expr_type); |
| 24780 | | if (type_is_invalid(casted_op2->value.type)) |
| 24779 | if (type_is_invalid(casted_op2->value->type)) |
| 24781 | 24780 | return ira->codegen->invalid_instruction; |
| 24782 | 24781 | |
| 24783 | 24782 | IrInstruction *op3 = instruction->op3->child; |
| 24784 | | if (type_is_invalid(op3->value.type)) |
| 24783 | if (type_is_invalid(op3->value->type)) |
| 24785 | 24784 | return ira->codegen->invalid_instruction; |
| 24786 | 24785 | |
| 24787 | 24786 | IrInstruction *casted_op3 = ir_implicit_cast(ira, op3, expr_type); |
| 24788 | | if (type_is_invalid(casted_op3->value.type)) |
| 24787 | if (type_is_invalid(casted_op3->value->type)) |
| 24789 | 24788 | return ira->codegen->invalid_instruction; |
| 24790 | 24789 | |
| 24791 | 24790 | if (instr_is_comptime(casted_op1) && |
| ... | ... | @@ -24802,7 +24801,7 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi |
| 24802 | 24801 | return ira->codegen->invalid_instruction; |
| 24803 | 24802 | |
| 24804 | 24803 | IrInstruction *result = ir_const(ira, &instruction->base, expr_type); |
| 24805 | | ZigValue *out_val = &result->value; |
| 24804 | ZigValue *out_val = result->value; |
| 24806 | 24805 | |
| 24807 | 24806 | if (expr_type->id == ZigTypeIdVector) { |
| 24808 | 24807 | expand_undef_array(ira->codegen, op1_const); |
| ... | ... | @@ -24835,13 +24834,13 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi |
| 24835 | 24834 | IrInstruction *result = ir_build_mul_add(&ira->new_irb, |
| 24836 | 24835 | instruction->base.scope, instruction->base.source_node, |
| 24837 | 24836 | type_value, casted_op1, casted_op2, casted_op3); |
| 24838 | | result->value.type = expr_type; |
| 24837 | result->value->type = expr_type; |
| 24839 | 24838 | return result; |
| 24840 | 24839 | } |
| 24841 | 24840 | |
| 24842 | 24841 | static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErrSrc *instruction) { |
| 24843 | 24842 | IrInstruction *base_ptr = instruction->base_ptr->child; |
| 24844 | | if (type_is_invalid(base_ptr->value.type)) |
| 24843 | if (type_is_invalid(base_ptr->value->type)) |
| 24845 | 24844 | return ira->codegen->invalid_instruction; |
| 24846 | 24845 | |
| 24847 | 24846 | IrInstruction *value; |
| ... | ... | @@ -24851,7 +24850,7 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct |
| 24851 | 24850 | value = ir_get_deref(ira, &instruction->base, base_ptr, nullptr); |
| 24852 | 24851 | } |
| 24853 | 24852 | |
| 24854 | | ZigType *type_entry = value->value.type; |
| 24853 | ZigType *type_entry = value->value->type; |
| 24855 | 24854 | if (type_is_invalid(type_entry)) |
| 24856 | 24855 | return ira->codegen->invalid_instruction; |
| 24857 | 24856 | if (type_entry->id == ZigTypeIdErrorUnion) { |
| ... | ... | @@ -24890,7 +24889,7 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct |
| 24890 | 24889 | static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr, |
| 24891 | 24890 | IrInstruction *base_ptr, bool initializing) |
| 24892 | 24891 | { |
| 24893 | | ZigType *ptr_type = base_ptr->value.type; |
| 24892 | ZigType *ptr_type = base_ptr->value->type; |
| 24894 | 24893 | |
| 24895 | 24894 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. |
| 24896 | 24895 | assert(ptr_type->id == ZigTypeIdPointer); |
| ... | ... | @@ -24946,12 +24945,12 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * |
| 24946 | 24945 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 24947 | 24946 | result = ir_build_unwrap_err_code(&ira->new_irb, source_instr->scope, |
| 24948 | 24947 | source_instr->source_node, base_ptr); |
| 24949 | | result->value.type = result_type; |
| 24950 | | result->value.special = ConstValSpecialStatic; |
| 24948 | result->value->type = result_type; |
| 24949 | result->value->special = ConstValSpecialStatic; |
| 24951 | 24950 | } else { |
| 24952 | 24951 | result = ir_const(ira, source_instr, result_type); |
| 24953 | 24952 | } |
| 24954 | | ZigValue *const_val = &result->value; |
| 24953 | ZigValue *const_val = result->value; |
| 24955 | 24954 | const_val->data.x_ptr.special = ConstPtrSpecialBaseErrorUnionCode; |
| 24956 | 24955 | const_val->data.x_ptr.data.base_err_union_code.err_union_val = err_union_val; |
| 24957 | 24956 | const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut; |
| ... | ... | @@ -24961,7 +24960,7 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * |
| 24961 | 24960 | |
| 24962 | 24961 | IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb, |
| 24963 | 24962 | source_instr->scope, source_instr->source_node, base_ptr); |
| 24964 | | result->value.type = result_type; |
| 24963 | result->value->type = result_type; |
| 24965 | 24964 | return result; |
| 24966 | 24965 | } |
| 24967 | 24966 | |
| ... | ... | @@ -24969,7 +24968,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 24969 | 24968 | IrInstructionUnwrapErrCode *instruction) |
| 24970 | 24969 | { |
| 24971 | 24970 | IrInstruction *base_ptr = instruction->err_union_ptr->child; |
| 24972 | | if (type_is_invalid(base_ptr->value.type)) |
| 24971 | if (type_is_invalid(base_ptr->value->type)) |
| 24973 | 24972 | return ira->codegen->invalid_instruction; |
| 24974 | 24973 | return ir_analyze_unwrap_err_code(ira, &instruction->base, base_ptr, false); |
| 24975 | 24974 | } |
| ... | ... | @@ -24977,7 +24976,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 24977 | 24976 | static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 24978 | 24977 | IrInstruction *base_ptr, bool safety_check_on, bool initializing) |
| 24979 | 24978 | { |
| 24980 | | ZigType *ptr_type = base_ptr->value.type; |
| 24979 | ZigType *ptr_type = base_ptr->value->type; |
| 24981 | 24980 | |
| 24982 | 24981 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. |
| 24983 | 24982 | assert(ptr_type->id == ZigTypeIdPointer); |
| ... | ... | @@ -25036,14 +25035,14 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 25036 | 25035 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 25037 | 25036 | result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope, |
| 25038 | 25037 | source_instr->source_node, base_ptr, safety_check_on, initializing); |
| 25039 | | result->value.type = result_type; |
| 25040 | | result->value.special = ConstValSpecialStatic; |
| 25038 | result->value->type = result_type; |
| 25039 | result->value->special = ConstValSpecialStatic; |
| 25041 | 25040 | } else { |
| 25042 | 25041 | result = ir_const(ira, source_instr, result_type); |
| 25043 | 25042 | } |
| 25044 | | result->value.data.x_ptr.special = ConstPtrSpecialRef; |
| 25045 | | result->value.data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload; |
| 25046 | | result->value.data.x_ptr.mut = ptr_val->data.x_ptr.mut; |
| 25043 | result->value->data.x_ptr.special = ConstPtrSpecialRef; |
| 25044 | result->value->data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload; |
| 25045 | result->value->data.x_ptr.mut = ptr_val->data.x_ptr.mut; |
| 25047 | 25046 | return result; |
| 25048 | 25047 | } |
| 25049 | 25048 | } |
| ... | ... | @@ -25051,7 +25050,7 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 25051 | 25050 | |
| 25052 | 25051 | IrInstruction *result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope, |
| 25053 | 25052 | source_instr->source_node, base_ptr, safety_check_on, initializing); |
| 25054 | | result->value.type = result_type; |
| 25053 | result->value->type = result_type; |
| 25055 | 25054 | return result; |
| 25056 | 25055 | } |
| 25057 | 25056 | |
| ... | ... | @@ -25060,7 +25059,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 25060 | 25059 | { |
| 25061 | 25060 | assert(instruction->value->child); |
| 25062 | 25061 | IrInstruction *value = instruction->value->child; |
| 25063 | | if (type_is_invalid(value->value.type)) |
| 25062 | if (type_is_invalid(value->value->type)) |
| 25064 | 25063 | return ira->codegen->invalid_instruction; |
| 25065 | 25064 | |
| 25066 | 25065 | return ir_analyze_unwrap_error_payload(ira, &instruction->base, value, instruction->safety_check_on, false); |
| ... | ... | @@ -25071,11 +25070,11 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 25071 | 25070 | assert(proto_node->type == NodeTypeFnProto); |
| 25072 | 25071 | |
| 25073 | 25072 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 25074 | | result->value.special = ConstValSpecialLazy; |
| 25073 | result->value->special = ConstValSpecialLazy; |
| 25075 | 25074 | |
| 25076 | 25075 | LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1); |
| 25077 | 25076 | lazy_fn_type->ira = ira; |
| 25078 | | result->value.data.x_lazy = &lazy_fn_type->base; |
| 25077 | result->value->data.x_lazy = &lazy_fn_type->base; |
| 25079 | 25078 | lazy_fn_type->base.id = LazyValueIdFnType; |
| 25080 | 25079 | |
| 25081 | 25080 | if (proto_node->data.fn_proto.auto_err_set) { |
| ... | ... | @@ -25110,7 +25109,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 25110 | 25109 | } |
| 25111 | 25110 | |
| 25112 | 25111 | IrInstruction *param_type_value = instruction->param_types[param_index]->child; |
| 25113 | | if (type_is_invalid(param_type_value->value.type)) |
| 25112 | if (type_is_invalid(param_type_value->value->type)) |
| 25114 | 25113 | return ira->codegen->invalid_instruction; |
| 25115 | 25114 | if (ir_resolve_const(ira, param_type_value, LazyOk) == nullptr) |
| 25116 | 25115 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -25132,7 +25131,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 25132 | 25131 | |
| 25133 | 25132 | static IrInstruction *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) { |
| 25134 | 25133 | IrInstruction *value = instruction->value->child; |
| 25135 | | if (type_is_invalid(value->value.type)) |
| 25134 | if (type_is_invalid(value->value->type)) |
| 25136 | 25135 | return ira->codegen->invalid_instruction; |
| 25137 | 25136 | |
| 25138 | 25137 | return ir_const_bool(ira, &instruction->base, instr_is_comptime(value)); |
| ... | ... | @@ -25142,7 +25141,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 25142 | 25141 | IrInstructionCheckSwitchProngs *instruction) |
| 25143 | 25142 | { |
| 25144 | 25143 | IrInstruction *target_value = instruction->target_value->child; |
| 25145 | | ZigType *switch_type = target_value->value.type; |
| 25144 | ZigType *switch_type = target_value->value->type; |
| 25146 | 25145 | if (type_is_invalid(switch_type)) |
| 25147 | 25146 | return ira->codegen->invalid_instruction; |
| 25148 | 25147 | |
| ... | ... | @@ -25154,25 +25153,25 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 25154 | 25153 | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 25155 | 25154 | |
| 25156 | 25155 | IrInstruction *start_value_uncasted = range->start->child; |
| 25157 | | if (type_is_invalid(start_value_uncasted->value.type)) |
| 25156 | if (type_is_invalid(start_value_uncasted->value->type)) |
| 25158 | 25157 | return ira->codegen->invalid_instruction; |
| 25159 | 25158 | IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type); |
| 25160 | | if (type_is_invalid(start_value->value.type)) |
| 25159 | if (type_is_invalid(start_value->value->type)) |
| 25161 | 25160 | return ira->codegen->invalid_instruction; |
| 25162 | 25161 | |
| 25163 | 25162 | IrInstruction *end_value_uncasted = range->end->child; |
| 25164 | | if (type_is_invalid(end_value_uncasted->value.type)) |
| 25163 | if (type_is_invalid(end_value_uncasted->value->type)) |
| 25165 | 25164 | return ira->codegen->invalid_instruction; |
| 25166 | 25165 | IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type); |
| 25167 | | if (type_is_invalid(end_value->value.type)) |
| 25166 | if (type_is_invalid(end_value->value->type)) |
| 25168 | 25167 | return ira->codegen->invalid_instruction; |
| 25169 | 25168 | |
| 25170 | 25169 | BigInt start_index; |
| 25171 | | bigint_init_bigint(&start_index, &start_value->value.data.x_enum_tag); |
| 25170 | bigint_init_bigint(&start_index, &start_value->value->data.x_enum_tag); |
| 25172 | 25171 | |
| 25173 | | assert(end_value->value.type->id == ZigTypeIdEnum); |
| 25172 | assert(end_value->value->type->id == ZigTypeIdEnum); |
| 25174 | 25173 | BigInt end_index; |
| 25175 | | bigint_init_bigint(&end_index, &end_value->value.data.x_enum_tag); |
| 25174 | bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag); |
| 25176 | 25175 | |
| 25177 | 25176 | BigInt field_index; |
| 25178 | 25177 | bigint_init_bigint(&field_index, &start_index); |
| ... | ... | @@ -25218,24 +25217,24 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 25218 | 25217 | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 25219 | 25218 | |
| 25220 | 25219 | IrInstruction *start_value_uncasted = range->start->child; |
| 25221 | | if (type_is_invalid(start_value_uncasted->value.type)) |
| 25220 | if (type_is_invalid(start_value_uncasted->value->type)) |
| 25222 | 25221 | return ira->codegen->invalid_instruction; |
| 25223 | 25222 | IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type); |
| 25224 | | if (type_is_invalid(start_value->value.type)) |
| 25223 | if (type_is_invalid(start_value->value->type)) |
| 25225 | 25224 | return ira->codegen->invalid_instruction; |
| 25226 | 25225 | |
| 25227 | 25226 | IrInstruction *end_value_uncasted = range->end->child; |
| 25228 | | if (type_is_invalid(end_value_uncasted->value.type)) |
| 25227 | if (type_is_invalid(end_value_uncasted->value->type)) |
| 25229 | 25228 | return ira->codegen->invalid_instruction; |
| 25230 | 25229 | IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type); |
| 25231 | | if (type_is_invalid(end_value->value.type)) |
| 25230 | if (type_is_invalid(end_value->value->type)) |
| 25232 | 25231 | return ira->codegen->invalid_instruction; |
| 25233 | 25232 | |
| 25234 | | ir_assert(start_value->value.type->id == ZigTypeIdErrorSet, &instruction->base); |
| 25235 | | uint32_t start_index = start_value->value.data.x_err_set->value; |
| 25233 | ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base); |
| 25234 | uint32_t start_index = start_value->value->data.x_err_set->value; |
| 25236 | 25235 | |
| 25237 | | ir_assert(end_value->value.type->id == ZigTypeIdErrorSet, &instruction->base); |
| 25238 | | uint32_t end_index = end_value->value.data.x_err_set->value; |
| 25236 | ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base); |
| 25237 | uint32_t end_index = end_value->value->data.x_err_set->value; |
| 25239 | 25238 | |
| 25240 | 25239 | if (start_index != end_index) { |
| 25241 | 25240 | ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors")); |
| ... | ... | @@ -25276,17 +25275,17 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 25276 | 25275 | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 25277 | 25276 | |
| 25278 | 25277 | IrInstruction *start_value = range->start->child; |
| 25279 | | if (type_is_invalid(start_value->value.type)) |
| 25278 | if (type_is_invalid(start_value->value->type)) |
| 25280 | 25279 | return ira->codegen->invalid_instruction; |
| 25281 | 25280 | IrInstruction *casted_start_value = ir_implicit_cast(ira, start_value, switch_type); |
| 25282 | | if (type_is_invalid(casted_start_value->value.type)) |
| 25281 | if (type_is_invalid(casted_start_value->value->type)) |
| 25283 | 25282 | return ira->codegen->invalid_instruction; |
| 25284 | 25283 | |
| 25285 | 25284 | IrInstruction *end_value = range->end->child; |
| 25286 | | if (type_is_invalid(end_value->value.type)) |
| 25285 | if (type_is_invalid(end_value->value->type)) |
| 25287 | 25286 | return ira->codegen->invalid_instruction; |
| 25288 | 25287 | IrInstruction *casted_end_value = ir_implicit_cast(ira, end_value, switch_type); |
| 25289 | | if (type_is_invalid(casted_end_value->value.type)) |
| 25288 | if (type_is_invalid(casted_end_value->value->type)) |
| 25290 | 25289 | return ira->codegen->invalid_instruction; |
| 25291 | 25290 | |
| 25292 | 25291 | ZigValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad); |
| ... | ... | @@ -25326,7 +25325,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 25326 | 25325 | IrInstruction *value = range->start->child; |
| 25327 | 25326 | |
| 25328 | 25327 | IrInstruction *casted_value = ir_implicit_cast(ira, value, switch_type); |
| 25329 | | if (type_is_invalid(casted_value->value.type)) |
| 25328 | if (type_is_invalid(casted_value->value->type)) |
| 25330 | 25329 | return ira->codegen->invalid_instruction; |
| 25331 | 25330 | |
| 25332 | 25331 | ZigValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad); |
| ... | ... | @@ -25362,7 +25361,7 @@ static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze * |
| 25362 | 25361 | IrInstructionCheckStatementIsVoid *instruction) |
| 25363 | 25362 | { |
| 25364 | 25363 | IrInstruction *statement_value = instruction->statement_value->child; |
| 25365 | | ZigType *statement_type = statement_value->value.type; |
| 25364 | ZigType *statement_type = statement_value->value->type; |
| 25366 | 25365 | if (type_is_invalid(statement_type)) |
| 25367 | 25366 | return ira->codegen->invalid_instruction; |
| 25368 | 25367 | |
| ... | ... | @@ -25375,7 +25374,7 @@ static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze * |
| 25375 | 25374 | |
| 25376 | 25375 | static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) { |
| 25377 | 25376 | IrInstruction *msg = instruction->msg->child; |
| 25378 | | if (type_is_invalid(msg->value.type)) |
| 25377 | if (type_is_invalid(msg->value->type)) |
| 25379 | 25378 | return ir_unreach_error(ira); |
| 25380 | 25379 | |
| 25381 | 25380 | if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) { |
| ... | ... | @@ -25387,7 +25386,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction |
| 25387 | 25386 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| 25388 | 25387 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 25389 | 25388 | IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type); |
| 25390 | | if (type_is_invalid(casted_msg->value.type)) |
| 25389 | if (type_is_invalid(casted_msg->value->type)) |
| 25391 | 25390 | return ir_unreach_error(ira); |
| 25392 | 25391 | |
| 25393 | 25392 | IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope, |
| ... | ... | @@ -25398,7 +25397,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction |
| 25398 | 25397 | static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) { |
| 25399 | 25398 | Error err; |
| 25400 | 25399 | |
| 25401 | | ZigType *target_type = target->value.type; |
| 25400 | ZigType *target_type = target->value->type; |
| 25402 | 25401 | assert(!type_is_invalid(target_type)); |
| 25403 | 25402 | |
| 25404 | 25403 | ZigType *result_type; |
| ... | ... | @@ -25457,8 +25456,8 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 25457 | 25456 | } |
| 25458 | 25457 | |
| 25459 | 25458 | IrInstruction *result = ir_const(ira, target, result_type); |
| 25460 | | copy_const_val(&result->value, val, true); |
| 25461 | | result->value.type = result_type; |
| 25459 | copy_const_val(result->value, val, true); |
| 25460 | result->value->type = result_type; |
| 25462 | 25461 | return result; |
| 25463 | 25462 | } |
| 25464 | 25463 | |
| ... | ... | @@ -25468,7 +25467,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 25468 | 25467 | } else { |
| 25469 | 25468 | result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, result_type, target, CastOpNoop); |
| 25470 | 25469 | } |
| 25471 | | result->value.type = result_type; |
| 25470 | result->value->type = result_type; |
| 25472 | 25471 | return result; |
| 25473 | 25472 | } |
| 25474 | 25473 | |
| ... | ... | @@ -25477,7 +25476,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 25477 | 25476 | { |
| 25478 | 25477 | Error err; |
| 25479 | 25478 | |
| 25480 | | ZigType *src_type = ptr->value.type; |
| 25479 | ZigType *src_type = ptr->value->type; |
| 25481 | 25480 | assert(!type_is_invalid(src_type)); |
| 25482 | 25481 | |
| 25483 | 25482 | if (src_type == dest_type) { |
| ... | ... | @@ -25531,7 +25530,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 25531 | 25530 | } |
| 25532 | 25531 | |
| 25533 | 25532 | IrInstruction *result; |
| 25534 | | if (ptr->value.data.x_ptr.mut == ConstPtrMutInfer) { |
| 25533 | if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 25535 | 25534 | result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on); |
| 25536 | 25535 | |
| 25537 | 25536 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) |
| ... | ... | @@ -25539,8 +25538,8 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 25539 | 25538 | } else { |
| 25540 | 25539 | result = ir_const(ira, source_instr, dest_type); |
| 25541 | 25540 | } |
| 25542 | | copy_const_val(&result->value, val, true); |
| 25543 | | result->value.type = dest_type; |
| 25541 | copy_const_val(result->value, val, true); |
| 25542 | result->value->type = dest_type; |
| 25544 | 25543 | |
| 25545 | 25544 | // Keep the bigger alignment, it can only help- |
| 25546 | 25545 | // unless the target is zero bits. |
| ... | ... | @@ -25584,7 +25583,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 25584 | 25583 | IrInstruction *result; |
| 25585 | 25584 | if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) { |
| 25586 | 25585 | result = ir_align_cast(ira, casted_ptr, src_align_bytes, false); |
| 25587 | | if (type_is_invalid(result->value.type)) |
| 25586 | if (type_is_invalid(result->value->type)) |
| 25588 | 25587 | return ira->codegen->invalid_instruction; |
| 25589 | 25588 | } else { |
| 25590 | 25589 | result = casted_ptr; |
| ... | ... | @@ -25599,7 +25598,7 @@ static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruct |
| 25599 | 25598 | return ira->codegen->invalid_instruction; |
| 25600 | 25599 | |
| 25601 | 25600 | IrInstruction *ptr = instruction->ptr->child; |
| 25602 | | ZigType *src_type = ptr->value.type; |
| 25601 | ZigType *src_type = ptr->value->type; |
| 25603 | 25602 | if (type_is_invalid(src_type)) |
| 25604 | 25603 | return ira->codegen->invalid_instruction; |
| 25605 | 25604 | |
| ... | ... | @@ -25941,7 +25940,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 25941 | 25940 | { |
| 25942 | 25941 | Error err; |
| 25943 | 25942 | |
| 25944 | | ZigType *src_type = value->value.type; |
| 25943 | ZigType *src_type = value->value->type; |
| 25945 | 25944 | ir_assert(get_codegen_ptr_type(src_type) == nullptr, source_instr); |
| 25946 | 25945 | ir_assert(type_can_bit_cast(src_type), source_instr); |
| 25947 | 25946 | ir_assert(get_codegen_ptr_type(dest_type) == nullptr, source_instr); |
| ... | ... | @@ -25982,7 +25981,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 25982 | 25981 | IrInstruction *result = ir_const(ira, source_instr, dest_type); |
| 25983 | 25982 | uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes); |
| 25984 | 25983 | buf_write_value_bytes(ira->codegen, buf, val); |
| 25985 | | if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, &result->value))) |
| 25984 | if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value))) |
| 25986 | 25985 | return ira->codegen->invalid_instruction; |
| 25987 | 25986 | return result; |
| 25988 | 25987 | } |
| ... | ... | @@ -25997,7 +25996,7 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc |
| 25997 | 25996 | ir_assert(type_has_bits(ptr_type), source_instr); |
| 25998 | 25997 | |
| 25999 | 25998 | IrInstruction *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize); |
| 26000 | | if (type_is_invalid(casted_int->value.type)) |
| 25999 | if (type_is_invalid(casted_int->value->type)) |
| 26001 | 26000 | return ira->codegen->invalid_instruction; |
| 26002 | 26001 | |
| 26003 | 26002 | if (instr_is_comptime(casted_int)) { |
| ... | ... | @@ -26013,15 +26012,15 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc |
| 26013 | 26012 | } |
| 26014 | 26013 | |
| 26015 | 26014 | IrInstruction *result = ir_const(ira, source_instr, ptr_type); |
| 26016 | | result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 26017 | | result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 26018 | | result->value.data.x_ptr.data.hard_coded_addr.addr = addr; |
| 26015 | result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 26016 | result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 26017 | result->value->data.x_ptr.data.hard_coded_addr.addr = addr; |
| 26019 | 26018 | return result; |
| 26020 | 26019 | } |
| 26021 | 26020 | |
| 26022 | 26021 | IrInstruction *result = ir_build_int_to_ptr(&ira->new_irb, source_instr->scope, |
| 26023 | 26022 | source_instr->source_node, nullptr, casted_int); |
| 26024 | | result->value.type = ptr_type; |
| 26023 | result->value->type = ptr_type; |
| 26025 | 26024 | return result; |
| 26026 | 26025 | } |
| 26027 | 26026 | |
| ... | ... | @@ -26048,7 +26047,7 @@ static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstru |
| 26048 | 26047 | |
| 26049 | 26048 | |
| 26050 | 26049 | IrInstruction *target = instruction->target->child; |
| 26051 | | if (type_is_invalid(target->value.type)) |
| 26050 | if (type_is_invalid(target->value->type)) |
| 26052 | 26051 | return ira->codegen->invalid_instruction; |
| 26053 | 26052 | |
| 26054 | 26053 | return ir_analyze_int_to_ptr(ira, &instruction->base, target, dest_type); |
| ... | ... | @@ -26058,7 +26057,7 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 26058 | 26057 | IrInstructionDeclRef *instruction) |
| 26059 | 26058 | { |
| 26060 | 26059 | IrInstruction *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base, instruction->tld); |
| 26061 | | if (type_is_invalid(ref_instruction->value.type)) { |
| 26060 | if (type_is_invalid(ref_instruction->value->type)) { |
| 26062 | 26061 | return ira->codegen->invalid_instruction; |
| 26063 | 26062 | } |
| 26064 | 26063 | |
| ... | ... | @@ -26072,21 +26071,21 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 26072 | 26071 | static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) { |
| 26073 | 26072 | Error err; |
| 26074 | 26073 | IrInstruction *target = instruction->target->child; |
| 26075 | | if (type_is_invalid(target->value.type)) |
| 26074 | if (type_is_invalid(target->value->type)) |
| 26076 | 26075 | return ira->codegen->invalid_instruction; |
| 26077 | 26076 | |
| 26078 | 26077 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 26079 | 26078 | |
| 26080 | 26079 | // We check size explicitly so we can use get_src_ptr_type here. |
| 26081 | | if (get_src_ptr_type(target->value.type) == nullptr) { |
| 26080 | if (get_src_ptr_type(target->value->type) == nullptr) { |
| 26082 | 26081 | ir_add_error(ira, target, |
| 26083 | | buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value.type->name))); |
| 26082 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name))); |
| 26084 | 26083 | return ira->codegen->invalid_instruction; |
| 26085 | 26084 | } |
| 26086 | 26085 | |
| 26087 | | if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown))) |
| 26086 | if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown))) |
| 26088 | 26087 | return ira->codegen->invalid_instruction; |
| 26089 | | if (!type_has_bits(target->value.type)) { |
| 26088 | if (!type_has_bits(target->value->type)) { |
| 26090 | 26089 | ir_add_error(ira, target, |
| 26091 | 26090 | buf_sprintf("pointer to size 0 type has no address")); |
| 26092 | 26091 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -26098,25 +26097,25 @@ static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstru |
| 26098 | 26097 | return ira->codegen->invalid_instruction; |
| 26099 | 26098 | if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 26100 | 26099 | IrInstruction *result = ir_const(ira, &instruction->base, usize); |
| 26101 | | bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); |
| 26102 | | result->value.type = usize; |
| 26100 | bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); |
| 26101 | result->value->type = usize; |
| 26103 | 26102 | return result; |
| 26104 | 26103 | } |
| 26105 | 26104 | } |
| 26106 | 26105 | |
| 26107 | 26106 | IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, instruction->base.scope, |
| 26108 | 26107 | instruction->base.source_node, target); |
| 26109 | | result->value.type = usize; |
| 26108 | result->value->type = usize; |
| 26110 | 26109 | return result; |
| 26111 | 26110 | } |
| 26112 | 26111 | |
| 26113 | 26112 | static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) { |
| 26114 | 26113 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 26115 | | result->value.special = ConstValSpecialLazy; |
| 26114 | result->value->special = ConstValSpecialLazy; |
| 26116 | 26115 | |
| 26117 | 26116 | LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1); |
| 26118 | 26117 | lazy_ptr_type->ira = ira; |
| 26119 | | result->value.data.x_lazy = &lazy_ptr_type->base; |
| 26118 | result->value->data.x_lazy = &lazy_ptr_type->base; |
| 26120 | 26119 | lazy_ptr_type->base.id = LazyValueIdPtrType; |
| 26121 | 26120 | |
| 26122 | 26121 | if (instruction->sentinel != nullptr) { |
| ... | ... | @@ -26147,15 +26146,15 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct |
| 26147 | 26146 | |
| 26148 | 26147 | static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) { |
| 26149 | 26148 | IrInstruction *target = instruction->target->child; |
| 26150 | | if (type_is_invalid(target->value.type)) |
| 26149 | if (type_is_invalid(target->value->type)) |
| 26151 | 26150 | return ira->codegen->invalid_instruction; |
| 26152 | 26151 | |
| 26153 | 26152 | ZigType *elem_type = nullptr; |
| 26154 | | if (is_slice(target->value.type)) { |
| 26155 | | ZigType *slice_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry; |
| 26153 | if (is_slice(target->value->type)) { |
| 26154 | ZigType *slice_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry; |
| 26156 | 26155 | elem_type = slice_ptr_type->data.pointer.child_type; |
| 26157 | | } else if (target->value.type->id == ZigTypeIdPointer) { |
| 26158 | | elem_type = target->value.type->data.pointer.child_type; |
| 26156 | } else if (target->value->type->id == ZigTypeIdPointer) { |
| 26157 | elem_type = target->value->type->data.pointer.child_type; |
| 26159 | 26158 | } |
| 26160 | 26159 | |
| 26161 | 26160 | uint32_t align_bytes; |
| ... | ... | @@ -26164,7 +26163,7 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru |
| 26164 | 26163 | return ira->codegen->invalid_instruction; |
| 26165 | 26164 | |
| 26166 | 26165 | IrInstruction *result = ir_align_cast(ira, target, align_bytes, true); |
| 26167 | | if (type_is_invalid(result->value.type)) |
| 26166 | if (type_is_invalid(result->value->type)) |
| 26168 | 26167 | return ira->codegen->invalid_instruction; |
| 26169 | 26168 | |
| 26170 | 26169 | return result; |
| ... | ... | @@ -26350,13 +26349,13 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru |
| 26350 | 26349 | return ira->codegen->invalid_instruction; |
| 26351 | 26350 | |
| 26352 | 26351 | IrInstruction *ptr_inst = instruction->ptr->child; |
| 26353 | | if (type_is_invalid(ptr_inst->value.type)) |
| 26352 | if (type_is_invalid(ptr_inst->value->type)) |
| 26354 | 26353 | return ira->codegen->invalid_instruction; |
| 26355 | 26354 | |
| 26356 | 26355 | // TODO let this be volatile |
| 26357 | 26356 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 26358 | 26357 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 26359 | | if (type_is_invalid(casted_ptr->value.type)) |
| 26358 | if (type_is_invalid(casted_ptr->value->type)) |
| 26360 | 26359 | return ira->codegen->invalid_instruction; |
| 26361 | 26360 | |
| 26362 | 26361 | AtomicRmwOp op; |
| ... | ... | @@ -26375,11 +26374,11 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru |
| 26375 | 26374 | } |
| 26376 | 26375 | |
| 26377 | 26376 | IrInstruction *operand = instruction->operand->child; |
| 26378 | | if (type_is_invalid(operand->value.type)) |
| 26377 | if (type_is_invalid(operand->value->type)) |
| 26379 | 26378 | return ira->codegen->invalid_instruction; |
| 26380 | 26379 | |
| 26381 | 26380 | IrInstruction *casted_operand = ir_implicit_cast(ira, operand, operand_type); |
| 26382 | | if (type_is_invalid(casted_operand->value.type)) |
| 26381 | if (type_is_invalid(casted_operand->value->type)) |
| 26383 | 26382 | return ira->codegen->invalid_instruction; |
| 26384 | 26383 | |
| 26385 | 26384 | AtomicOrder ordering; |
| ... | ... | @@ -26395,7 +26394,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru |
| 26395 | 26394 | } |
| 26396 | 26395 | } |
| 26397 | 26396 | |
| 26398 | | if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) |
| 26397 | if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar) |
| 26399 | 26398 | { |
| 26400 | 26399 | zig_panic("TODO compile-time execution of atomicRmw"); |
| 26401 | 26400 | } |
| ... | ... | @@ -26403,7 +26402,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru |
| 26403 | 26402 | IrInstruction *result = ir_build_atomic_rmw(&ira->new_irb, instruction->base.scope, |
| 26404 | 26403 | instruction->base.source_node, nullptr, casted_ptr, nullptr, casted_operand, nullptr, |
| 26405 | 26404 | op, ordering); |
| 26406 | | result->value.type = operand_type; |
| 26405 | result->value->type = operand_type; |
| 26407 | 26406 | return result; |
| 26408 | 26407 | } |
| 26409 | 26408 | |
| ... | ... | @@ -26413,12 +26412,12 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr |
| 26413 | 26412 | return ira->codegen->invalid_instruction; |
| 26414 | 26413 | |
| 26415 | 26414 | IrInstruction *ptr_inst = instruction->ptr->child; |
| 26416 | | if (type_is_invalid(ptr_inst->value.type)) |
| 26415 | if (type_is_invalid(ptr_inst->value->type)) |
| 26417 | 26416 | return ira->codegen->invalid_instruction; |
| 26418 | 26417 | |
| 26419 | 26418 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true); |
| 26420 | 26419 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 26421 | | if (type_is_invalid(casted_ptr->value.type)) |
| 26420 | if (type_is_invalid(casted_ptr->value->type)) |
| 26422 | 26421 | return ira->codegen->invalid_instruction; |
| 26423 | 26422 | |
| 26424 | 26423 | AtomicOrder ordering; |
| ... | ... | @@ -26438,13 +26437,13 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr |
| 26438 | 26437 | |
| 26439 | 26438 | if (instr_is_comptime(casted_ptr)) { |
| 26440 | 26439 | IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr, nullptr); |
| 26441 | | ir_assert(result->value.type != nullptr, &instruction->base); |
| 26440 | ir_assert(result->value->type != nullptr, &instruction->base); |
| 26442 | 26441 | return result; |
| 26443 | 26442 | } |
| 26444 | 26443 | |
| 26445 | 26444 | IrInstruction *result = ir_build_atomic_load(&ira->new_irb, instruction->base.scope, |
| 26446 | 26445 | instruction->base.source_node, nullptr, casted_ptr, nullptr, ordering); |
| 26447 | | result->value.type = operand_type; |
| 26446 | result->value->type = operand_type; |
| 26448 | 26447 | return result; |
| 26449 | 26448 | } |
| 26450 | 26449 | |
| ... | ... | @@ -26454,20 +26453,20 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst |
| 26454 | 26453 | return ira->codegen->invalid_instruction; |
| 26455 | 26454 | |
| 26456 | 26455 | IrInstruction *ptr_inst = instruction->ptr->child; |
| 26457 | | if (type_is_invalid(ptr_inst->value.type)) |
| 26456 | if (type_is_invalid(ptr_inst->value->type)) |
| 26458 | 26457 | return ira->codegen->invalid_instruction; |
| 26459 | 26458 | |
| 26460 | 26459 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 26461 | 26460 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 26462 | | if (type_is_invalid(casted_ptr->value.type)) |
| 26461 | if (type_is_invalid(casted_ptr->value->type)) |
| 26463 | 26462 | return ira->codegen->invalid_instruction; |
| 26464 | 26463 | |
| 26465 | 26464 | IrInstruction *value = instruction->value->child; |
| 26466 | | if (type_is_invalid(value->value.type)) |
| 26465 | if (type_is_invalid(value->value->type)) |
| 26467 | 26466 | return ira->codegen->invalid_instruction; |
| 26468 | 26467 | |
| 26469 | 26468 | IrInstruction *casted_value = ir_implicit_cast(ira, value, operand_type); |
| 26470 | | if (type_is_invalid(casted_value->value.type)) |
| 26469 | if (type_is_invalid(casted_value->value->type)) |
| 26471 | 26470 | return ira->codegen->invalid_instruction; |
| 26472 | 26471 | |
| 26473 | 26472 | |
| ... | ... | @@ -26488,20 +26487,20 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst |
| 26488 | 26487 | |
| 26489 | 26488 | if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) { |
| 26490 | 26489 | IrInstruction *result = ir_analyze_store_ptr(ira, &instruction->base, casted_ptr, value, false); |
| 26491 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 26490 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 26492 | 26491 | return result; |
| 26493 | 26492 | } |
| 26494 | 26493 | |
| 26495 | 26494 | IrInstruction *result = ir_build_atomic_store(&ira->new_irb, instruction->base.scope, |
| 26496 | 26495 | instruction->base.source_node, nullptr, casted_ptr, casted_value, nullptr, ordering); |
| 26497 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 26496 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 26498 | 26497 | return result; |
| 26499 | 26498 | } |
| 26500 | 26499 | |
| 26501 | 26500 | static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) { |
| 26502 | 26501 | IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope, |
| 26503 | 26502 | instruction->base.source_node); |
| 26504 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 26503 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 26505 | 26504 | return result; |
| 26506 | 26505 | } |
| 26507 | 26506 | |
| ... | ... | @@ -26687,7 +26686,7 @@ static void ir_eval_float_op(IrAnalyze *ira, IrInstructionFloatOp *source_instr, |
| 26687 | 26686 | |
| 26688 | 26687 | static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstructionFloatOp *instruction) { |
| 26689 | 26688 | IrInstruction *type = instruction->type->child; |
| 26690 | | if (type_is_invalid(type->value.type)) |
| 26689 | if (type_is_invalid(type->value->type)) |
| 26691 | 26690 | return ira->codegen->invalid_instruction; |
| 26692 | 26691 | |
| 26693 | 26692 | ZigType *expr_type = ir_resolve_type(ira, type); |
| ... | ... | @@ -26702,11 +26701,11 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct |
| 26702 | 26701 | } |
| 26703 | 26702 | |
| 26704 | 26703 | IrInstruction *op1 = instruction->op1->child; |
| 26705 | | if (type_is_invalid(op1->value.type)) |
| 26704 | if (type_is_invalid(op1->value->type)) |
| 26706 | 26705 | return ira->codegen->invalid_instruction; |
| 26707 | 26706 | |
| 26708 | 26707 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, float_type); |
| 26709 | | if (type_is_invalid(casted_op1->value.type)) |
| 26708 | if (type_is_invalid(casted_op1->value->type)) |
| 26710 | 26709 | return ira->codegen->invalid_instruction; |
| 26711 | 26710 | |
| 26712 | 26711 | if (instr_is_comptime(casted_op1)) { |
| ... | ... | @@ -26724,7 +26723,7 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct |
| 26724 | 26723 | return ira->codegen->invalid_instruction; |
| 26725 | 26724 | |
| 26726 | 26725 | IrInstruction *result = ir_const(ira, &instruction->base, expr_type); |
| 26727 | | ZigValue *out_val = &result->value; |
| 26726 | ZigValue *out_val = result->value; |
| 26728 | 26727 | |
| 26729 | 26728 | if (expr_type->id == ZigTypeIdVector) { |
| 26730 | 26729 | expand_undef_array(ira->codegen, op1_const); |
| ... | ... | @@ -26752,7 +26751,7 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct |
| 26752 | 26751 | |
| 26753 | 26752 | IrInstruction *result = ir_build_float_op(&ira->new_irb, instruction->base.scope, |
| 26754 | 26753 | instruction->base.source_node, nullptr, casted_op1, instruction->op); |
| 26755 | | result->value.type = expr_type; |
| 26754 | result->value->type = expr_type; |
| 26756 | 26755 | return result; |
| 26757 | 26756 | } |
| 26758 | 26757 | |
| ... | ... | @@ -26764,16 +26763,16 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 26764 | 26763 | return ira->codegen->invalid_instruction; |
| 26765 | 26764 | |
| 26766 | 26765 | IrInstruction *uncasted_op = instruction->op->child; |
| 26767 | | if (type_is_invalid(uncasted_op->value.type)) |
| 26766 | if (type_is_invalid(uncasted_op->value->type)) |
| 26768 | 26767 | return ira->codegen->invalid_instruction; |
| 26769 | 26768 | |
| 26770 | 26769 | uint32_t vector_len; // UINT32_MAX means not a vector |
| 26771 | | if (uncasted_op->value.type->id == ZigTypeIdArray && |
| 26772 | | is_valid_vector_elem_type(uncasted_op->value.type->data.array.child_type)) |
| 26770 | if (uncasted_op->value->type->id == ZigTypeIdArray && |
| 26771 | is_valid_vector_elem_type(uncasted_op->value->type->data.array.child_type)) |
| 26773 | 26772 | { |
| 26774 | | vector_len = uncasted_op->value.type->data.array.len; |
| 26775 | | } else if (uncasted_op->value.type->id == ZigTypeIdVector) { |
| 26776 | | vector_len = uncasted_op->value.type->data.vector.len; |
| 26773 | vector_len = uncasted_op->value->type->data.array.len; |
| 26774 | } else if (uncasted_op->value->type->id == ZigTypeIdVector) { |
| 26775 | vector_len = uncasted_op->value->type->data.vector.len; |
| 26777 | 26776 | } else { |
| 26778 | 26777 | vector_len = UINT32_MAX; |
| 26779 | 26778 | } |
| ... | ... | @@ -26782,7 +26781,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 26782 | 26781 | ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type; |
| 26783 | 26782 | |
| 26784 | 26783 | IrInstruction *op = ir_implicit_cast(ira, uncasted_op, op_type); |
| 26785 | | if (type_is_invalid(op->value.type)) |
| 26784 | if (type_is_invalid(op->value->type)) |
| 26786 | 26785 | return ira->codegen->invalid_instruction; |
| 26787 | 26786 | |
| 26788 | 26787 | if (int_type->data.integral.bit_count == 8 || int_type->data.integral.bit_count == 0) |
| ... | ... | @@ -26807,7 +26806,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 26807 | 26806 | uint8_t *buf = allocate_nonzero<uint8_t>(buf_size); |
| 26808 | 26807 | if (is_vector) { |
| 26809 | 26808 | expand_undef_array(ira->codegen, val); |
| 26810 | | result->value.data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len); |
| 26809 | result->value->data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len); |
| 26811 | 26810 | for (unsigned i = 0; i < op_type->data.vector.len; i += 1) { |
| 26812 | 26811 | ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i]; |
| 26813 | 26812 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node, |
| ... | ... | @@ -26815,20 +26814,20 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 26815 | 26814 | { |
| 26816 | 26815 | return ira->codegen->invalid_instruction; |
| 26817 | 26816 | } |
| 26818 | | ZigValue *result_elem_val = &result->value.data.x_array.data.s_none.elements[i]; |
| 26817 | ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i]; |
| 26819 | 26818 | result_elem_val->type = int_type; |
| 26820 | 26819 | result_elem_val->special = op_elem_val->special; |
| 26821 | 26820 | if (op_elem_val->special == ConstValSpecialUndef) |
| 26822 | 26821 | continue; |
| 26823 | 26822 | |
| 26824 | 26823 | bigint_write_twos_complement(&op_elem_val->data.x_bigint, buf, int_type->data.integral.bit_count, true); |
| 26825 | | bigint_read_twos_complement(&result->value.data.x_array.data.s_none.elements[i].data.x_bigint, |
| 26824 | bigint_read_twos_complement(&result->value->data.x_array.data.s_none.elements[i].data.x_bigint, |
| 26826 | 26825 | buf, int_type->data.integral.bit_count, false, |
| 26827 | 26826 | int_type->data.integral.is_signed); |
| 26828 | 26827 | } |
| 26829 | 26828 | } else { |
| 26830 | 26829 | bigint_write_twos_complement(&val->data.x_bigint, buf, int_type->data.integral.bit_count, true); |
| 26831 | | bigint_read_twos_complement(&result->value.data.x_bigint, buf, int_type->data.integral.bit_count, false, |
| 26830 | bigint_read_twos_complement(&result->value->data.x_bigint, buf, int_type->data.integral.bit_count, false, |
| 26832 | 26831 | int_type->data.integral.is_signed); |
| 26833 | 26832 | } |
| 26834 | 26833 | free(buf); |
| ... | ... | @@ -26837,7 +26836,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 26837 | 26836 | |
| 26838 | 26837 | IrInstruction *result = ir_build_bswap(&ira->new_irb, instruction->base.scope, |
| 26839 | 26838 | instruction->base.source_node, nullptr, op); |
| 26840 | | result->value.type = op_type; |
| 26839 | result->value->type = op_type; |
| 26841 | 26840 | return result; |
| 26842 | 26841 | } |
| 26843 | 26842 | |
| ... | ... | @@ -26847,12 +26846,12 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr |
| 26847 | 26846 | return ira->codegen->invalid_instruction; |
| 26848 | 26847 | |
| 26849 | 26848 | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 26850 | | if (type_is_invalid(op->value.type)) |
| 26849 | if (type_is_invalid(op->value->type)) |
| 26851 | 26850 | return ira->codegen->invalid_instruction; |
| 26852 | 26851 | |
| 26853 | 26852 | if (int_type->data.integral.bit_count == 0) { |
| 26854 | 26853 | IrInstruction *result = ir_const(ira, &instruction->base, int_type); |
| 26855 | | bigint_init_unsigned(&result->value.data.x_bigint, 0); |
| 26854 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 26856 | 26855 | return result; |
| 26857 | 26856 | } |
| 26858 | 26857 | |
| ... | ... | @@ -26881,7 +26880,7 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr |
| 26881 | 26880 | } |
| 26882 | 26881 | } |
| 26883 | 26882 | |
| 26884 | | bigint_read_twos_complement(&result->value.data.x_bigint, |
| 26883 | bigint_read_twos_complement(&result->value->data.x_bigint, |
| 26885 | 26884 | result_buf, |
| 26886 | 26885 | int_type->data.integral.bit_count, |
| 26887 | 26886 | ira->codegen->is_big_endian, |
| ... | ... | @@ -26892,14 +26891,14 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr |
| 26892 | 26891 | |
| 26893 | 26892 | IrInstruction *result = ir_build_bit_reverse(&ira->new_irb, instruction->base.scope, |
| 26894 | 26893 | instruction->base.source_node, nullptr, op); |
| 26895 | | result->value.type = int_type; |
| 26894 | result->value->type = int_type; |
| 26896 | 26895 | return result; |
| 26897 | 26896 | } |
| 26898 | 26897 | |
| 26899 | 26898 | |
| 26900 | 26899 | static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) { |
| 26901 | 26900 | IrInstruction *target = instruction->target->child; |
| 26902 | | if (type_is_invalid(target->value.type)) |
| 26901 | if (type_is_invalid(target->value->type)) |
| 26903 | 26902 | return ira->codegen->invalid_instruction; |
| 26904 | 26903 | |
| 26905 | 26904 | return ir_analyze_enum_to_int(ira, &instruction->base, target); |
| ... | ... | @@ -26924,11 +26923,11 @@ static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstr |
| 26924 | 26923 | ZigType *tag_type = dest_type->data.enumeration.tag_int_type; |
| 26925 | 26924 | |
| 26926 | 26925 | IrInstruction *target = instruction->target->child; |
| 26927 | | if (type_is_invalid(target->value.type)) |
| 26926 | if (type_is_invalid(target->value->type)) |
| 26928 | 26927 | return ira->codegen->invalid_instruction; |
| 26929 | 26928 | |
| 26930 | 26929 | IrInstruction *casted_target = ir_implicit_cast(ira, target, tag_type); |
| 26931 | | if (type_is_invalid(casted_target->value.type)) |
| 26930 | if (type_is_invalid(casted_target->value->type)) |
| 26932 | 26931 | return ira->codegen->invalid_instruction; |
| 26933 | 26932 | |
| 26934 | 26933 | return ir_analyze_int_to_enum(ira, &instruction->base, casted_target, dest_type); |
| ... | ... | @@ -26995,33 +26994,33 @@ static IrInstruction *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, Ir |
| 26995 | 26994 | |
| 26996 | 26995 | static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstructionEndExpr *instruction) { |
| 26997 | 26996 | IrInstruction *value = instruction->value->child; |
| 26998 | | if (type_is_invalid(value->value.type)) |
| 26997 | if (type_is_invalid(value->value->type)) |
| 26999 | 26998 | return ira->codegen->invalid_instruction; |
| 27000 | 26999 | |
| 27001 | 27000 | bool was_written = instruction->result_loc->written; |
| 27002 | 27001 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 27003 | | value->value.type, value, false, false, true); |
| 27002 | value->value->type, value, false, false, true); |
| 27004 | 27003 | if (result_loc != nullptr) { |
| 27005 | | if (type_is_invalid(result_loc->value.type)) |
| 27004 | if (type_is_invalid(result_loc->value->type)) |
| 27006 | 27005 | return ira->codegen->invalid_instruction; |
| 27007 | | if (result_loc->value.type->id == ZigTypeIdUnreachable) |
| 27006 | if (result_loc->value->type->id == ZigTypeIdUnreachable) |
| 27008 | 27007 | return result_loc; |
| 27009 | 27008 | |
| 27010 | 27009 | if (!was_written || instruction->result_loc->id == ResultLocIdPeer) { |
| 27011 | 27010 | IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value, |
| 27012 | 27011 | instruction->result_loc->allow_write_through_const); |
| 27013 | | if (type_is_invalid(store_ptr->value.type)) { |
| 27012 | if (type_is_invalid(store_ptr->value->type)) { |
| 27014 | 27013 | return ira->codegen->invalid_instruction; |
| 27015 | 27014 | } |
| 27016 | 27015 | } |
| 27017 | 27016 | |
| 27018 | | if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer && |
| 27017 | if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer && |
| 27019 | 27018 | instruction->result_loc->id != ResultLocIdPeer) |
| 27020 | 27019 | { |
| 27021 | 27020 | if (instr_is_comptime(value)) { |
| 27022 | | result_loc->value.data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 27021 | result_loc->value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 27023 | 27022 | } else { |
| 27024 | | result_loc->value.special = ConstValSpecialRuntime; |
| 27023 | result_loc->value->special = ConstValSpecialRuntime; |
| 27025 | 27024 | } |
| 27026 | 27025 | } |
| 27027 | 27026 | } |
| ... | ... | @@ -27031,12 +27030,12 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 27031 | 27030 | |
| 27032 | 27031 | static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) { |
| 27033 | 27032 | IrInstruction *operand = instruction->operand->child; |
| 27034 | | if (type_is_invalid(operand->value.type)) |
| 27033 | if (type_is_invalid(operand->value->type)) |
| 27035 | 27034 | return operand; |
| 27036 | 27035 | |
| 27037 | 27036 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, |
| 27038 | | &instruction->result_loc_cast->base, operand->value.type, operand, false, false, true); |
| 27039 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) |
| 27037 | &instruction->result_loc_cast->base, operand->value->type, operand, false, false, true); |
| 27038 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 27040 | 27039 | return result_loc; |
| 27041 | 27040 | |
| 27042 | 27041 | if (instruction->result_loc_cast->parent->gen_instruction != nullptr) { |
| ... | ... | @@ -27051,12 +27050,12 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns |
| 27051 | 27050 | |
| 27052 | 27051 | static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) { |
| 27053 | 27052 | IrInstruction *operand = instruction->operand->child; |
| 27054 | | if (type_is_invalid(operand->value.type)) |
| 27053 | if (type_is_invalid(operand->value->type)) |
| 27055 | 27054 | return operand; |
| 27056 | 27055 | |
| 27057 | 27056 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, |
| 27058 | | &instruction->result_loc_bit_cast->base, operand->value.type, operand, false, false, true); |
| 27059 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) |
| 27057 | &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, false, true); |
| 27058 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 27060 | 27059 | return result_loc; |
| 27061 | 27060 | |
| 27062 | 27061 | if (instruction->result_loc_bit_cast->parent->gen_instruction != nullptr) { |
| ... | ... | @@ -27084,11 +27083,11 @@ static IrInstruction *ir_analyze_instruction_union_init_named_field(IrAnalyze *i |
| 27084 | 27083 | return ira->codegen->invalid_instruction; |
| 27085 | 27084 | |
| 27086 | 27085 | IrInstruction *field_result_loc = instruction->field_result_loc->child; |
| 27087 | | if (type_is_invalid(field_result_loc->value.type)) |
| 27086 | if (type_is_invalid(field_result_loc->value->type)) |
| 27088 | 27087 | return ira->codegen->invalid_instruction; |
| 27089 | 27088 | |
| 27090 | 27089 | IrInstruction *result_loc = instruction->result_loc->child; |
| 27091 | | if (type_is_invalid(result_loc->value.type)) |
| 27090 | if (type_is_invalid(result_loc->value->type)) |
| 27092 | 27091 | return ira->codegen->invalid_instruction; |
| 27093 | 27092 | |
| 27094 | 27093 | return ir_analyze_union_init(ira, &instruction->base, instruction->base.source_node, |
| ... | ... | @@ -27105,7 +27104,7 @@ static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, |
| 27105 | 27104 | IrInstructionSuspendFinish *instruction) |
| 27106 | 27105 | { |
| 27107 | 27106 | IrInstruction *begin_base = instruction->begin->base.child; |
| 27108 | | if (type_is_invalid(begin_base->value.type)) |
| 27107 | if (type_is_invalid(begin_base->value->type)) |
| 27109 | 27108 | return ira->codegen->invalid_instruction; |
| 27110 | 27109 | ir_assert(begin_base->id == IrInstructionIdSuspendBegin, &instruction->base); |
| 27111 | 27110 | IrInstructionSuspendBegin *begin = reinterpret_cast<IrInstructionSuspendBegin *>(begin_base); |
| ... | ... | @@ -27123,44 +27122,44 @@ static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, |
| 27123 | 27122 | static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruction *source_instr, |
| 27124 | 27123 | IrInstruction *frame_ptr, ZigFn **target_fn) |
| 27125 | 27124 | { |
| 27126 | | if (type_is_invalid(frame_ptr->value.type)) |
| 27125 | if (type_is_invalid(frame_ptr->value->type)) |
| 27127 | 27126 | return ira->codegen->invalid_instruction; |
| 27128 | 27127 | |
| 27129 | 27128 | *target_fn = nullptr; |
| 27130 | 27129 | |
| 27131 | 27130 | ZigType *result_type; |
| 27132 | 27131 | IrInstruction *frame; |
| 27133 | | if (frame_ptr->value.type->id == ZigTypeIdPointer && |
| 27134 | | frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle && |
| 27135 | | frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 27132 | if (frame_ptr->value->type->id == ZigTypeIdPointer && |
| 27133 | frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 27134 | frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 27136 | 27135 | { |
| 27137 | | ZigFn *func = frame_ptr->value.type->data.pointer.child_type->data.frame.fn; |
| 27136 | ZigFn *func = frame_ptr->value->type->data.pointer.child_type->data.frame.fn; |
| 27138 | 27137 | result_type = func->type_entry->data.fn.fn_type_id.return_type; |
| 27139 | 27138 | *target_fn = func; |
| 27140 | 27139 | frame = frame_ptr; |
| 27141 | 27140 | } else { |
| 27142 | 27141 | frame = ir_get_deref(ira, source_instr, frame_ptr, nullptr); |
| 27143 | | if (frame->value.type->id == ZigTypeIdPointer && |
| 27144 | | frame->value.type->data.pointer.ptr_len == PtrLenSingle && |
| 27145 | | frame->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 27142 | if (frame->value->type->id == ZigTypeIdPointer && |
| 27143 | frame->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 27144 | frame->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 27146 | 27145 | { |
| 27147 | | ZigFn *func = frame->value.type->data.pointer.child_type->data.frame.fn; |
| 27146 | ZigFn *func = frame->value->type->data.pointer.child_type->data.frame.fn; |
| 27148 | 27147 | result_type = func->type_entry->data.fn.fn_type_id.return_type; |
| 27149 | 27148 | *target_fn = func; |
| 27150 | | } else if (frame->value.type->id != ZigTypeIdAnyFrame || |
| 27151 | | frame->value.type->data.any_frame.result_type == nullptr) |
| 27149 | } else if (frame->value->type->id != ZigTypeIdAnyFrame || |
| 27150 | frame->value->type->data.any_frame.result_type == nullptr) |
| 27152 | 27151 | { |
| 27153 | 27152 | ir_add_error(ira, source_instr, |
| 27154 | | buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value.type->name))); |
| 27153 | buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name))); |
| 27155 | 27154 | return ira->codegen->invalid_instruction; |
| 27156 | 27155 | } else { |
| 27157 | | result_type = frame->value.type->data.any_frame.result_type; |
| 27156 | result_type = frame->value->type->data.any_frame.result_type; |
| 27158 | 27157 | } |
| 27159 | 27158 | } |
| 27160 | 27159 | |
| 27161 | 27160 | ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type); |
| 27162 | 27161 | IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type); |
| 27163 | | if (type_is_invalid(casted_frame->value.type)) |
| 27162 | if (type_is_invalid(casted_frame->value->type)) |
| 27164 | 27163 | return ira->codegen->invalid_instruction; |
| 27165 | 27164 | |
| 27166 | 27165 | return casted_frame; |
| ... | ... | @@ -27168,14 +27167,14 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct |
| 27168 | 27167 | |
| 27169 | 27168 | static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstructionAwaitSrc *instruction) { |
| 27170 | 27169 | IrInstruction *operand = instruction->frame->child; |
| 27171 | | if (type_is_invalid(operand->value.type)) |
| 27170 | if (type_is_invalid(operand->value->type)) |
| 27172 | 27171 | return ira->codegen->invalid_instruction; |
| 27173 | 27172 | ZigFn *target_fn; |
| 27174 | 27173 | IrInstruction *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base, operand, &target_fn); |
| 27175 | | if (type_is_invalid(frame->value.type)) |
| 27174 | if (type_is_invalid(frame->value->type)) |
| 27176 | 27175 | return ira->codegen->invalid_instruction; |
| 27177 | 27176 | |
| 27178 | | ZigType *result_type = frame->value.type->data.any_frame.result_type; |
| 27177 | ZigType *result_type = frame->value->type->data.any_frame.result_type; |
| 27179 | 27178 | |
| 27180 | 27179 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 27181 | 27180 | ir_assert(fn_entry != nullptr, &instruction->base); |
| ... | ... | @@ -27195,7 +27194,7 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction |
| 27195 | 27194 | if (type_has_bits(result_type)) { |
| 27196 | 27195 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 27197 | 27196 | result_type, nullptr, true, true, true); |
| 27198 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) |
| 27197 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 27199 | 27198 | return result_loc; |
| 27200 | 27199 | } else { |
| 27201 | 27200 | result_loc = nullptr; |
| ... | ... | @@ -27209,13 +27208,13 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction |
| 27209 | 27208 | |
| 27210 | 27209 | static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructionResume *instruction) { |
| 27211 | 27210 | IrInstruction *frame_ptr = instruction->frame->child; |
| 27212 | | if (type_is_invalid(frame_ptr->value.type)) |
| 27211 | if (type_is_invalid(frame_ptr->value->type)) |
| 27213 | 27212 | return ira->codegen->invalid_instruction; |
| 27214 | 27213 | |
| 27215 | 27214 | IrInstruction *frame; |
| 27216 | | if (frame_ptr->value.type->id == ZigTypeIdPointer && |
| 27217 | | frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle && |
| 27218 | | frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 27215 | if (frame_ptr->value->type->id == ZigTypeIdPointer && |
| 27216 | frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 27217 | frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 27219 | 27218 | { |
| 27220 | 27219 | frame = frame_ptr; |
| 27221 | 27220 | } else { |
| ... | ... | @@ -27224,7 +27223,7 @@ static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructio |
| 27224 | 27223 | |
| 27225 | 27224 | ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr); |
| 27226 | 27225 | IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type); |
| 27227 | | if (type_is_invalid(casted_frame->value.type)) |
| 27226 | if (type_is_invalid(casted_frame->value->type)) |
| 27228 | 27227 | return ira->codegen->invalid_instruction; |
| 27229 | 27228 | |
| 27230 | 27229 | return ir_build_resume(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_frame); |
| ... | ... | @@ -27235,10 +27234,10 @@ static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstr |
| 27235 | 27234 | return ir_const_void(ira, &instruction->base); |
| 27236 | 27235 | |
| 27237 | 27236 | IrInstruction *operand = instruction->operand->child; |
| 27238 | | if (type_is_invalid(operand->value.type)) |
| 27237 | if (type_is_invalid(operand->value->type)) |
| 27239 | 27238 | return ira->codegen->invalid_instruction; |
| 27240 | 27239 | |
| 27241 | | if (!type_has_bits(operand->value.type)) |
| 27240 | if (!type_has_bits(operand->value->type)) |
| 27242 | 27241 | return ir_const_void(ira, &instruction->base); |
| 27243 | 27242 | |
| 27244 | 27243 | ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base); |
| ... | ... | @@ -27251,10 +27250,10 @@ static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstr |
| 27251 | 27250 | |
| 27252 | 27251 | static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstructionSpillEnd *instruction) { |
| 27253 | 27252 | IrInstruction *operand = instruction->begin->operand->child; |
| 27254 | | if (type_is_invalid(operand->value.type)) |
| 27253 | if (type_is_invalid(operand->value->type)) |
| 27255 | 27254 | return ira->codegen->invalid_instruction; |
| 27256 | 27255 | |
| 27257 | | if (ir_should_inline(ira->new_irb.exec, instruction->base.scope) || !type_has_bits(operand->value.type)) |
| 27256 | if (ir_should_inline(ira->new_irb.exec, instruction->base.scope) || !type_has_bits(operand->value->type)) |
| 27258 | 27257 | return operand; |
| 27259 | 27258 | |
| 27260 | 27259 | ir_assert(instruction->begin->base.child->id == IrInstructionIdSpillBegin, &instruction->base); |
| ... | ... | @@ -27262,7 +27261,7 @@ static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstruc |
| 27262 | 27261 | |
| 27263 | 27262 | IrInstruction *result = ir_build_spill_end(&ira->new_irb, instruction->base.scope, |
| 27264 | 27263 | instruction->base.source_node, begin); |
| 27265 | | result->value.type = operand->value.type; |
| 27264 | result->value->type = operand->value->type; |
| 27266 | 27265 | return result; |
| 27267 | 27266 | } |
| 27268 | 27267 | |
| ... | ... | @@ -27628,10 +27627,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 27628 | 27627 | } |
| 27629 | 27628 | IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction); |
| 27630 | 27629 | if (new_instruction != nullptr) { |
| 27631 | | ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction); |
| 27630 | ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, old_instruction); |
| 27632 | 27631 | old_instruction->child = new_instruction; |
| 27633 | 27632 | |
| 27634 | | if (type_is_invalid(new_instruction->value.type)) { |
| 27633 | if (type_is_invalid(new_instruction->value->type)) { |
| 27635 | 27634 | if (new_exec->first_err_trace_msg != nullptr) { |
| 27636 | 27635 | ira->codegen->trace_err = new_exec->first_err_trace_msg; |
| 27637 | 27636 | } else { |
| ... | ... | @@ -27648,7 +27647,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 27648 | 27647 | } |
| 27649 | 27648 | |
| 27650 | 27649 | // unreachable instructions do their own control flow. |
| 27651 | | if (new_instruction->value.type->id == ZigTypeIdUnreachable) |
| 27650 | if (new_instruction->value->type->id == ZigTypeIdUnreachable) |
| 27652 | 27651 | continue; |
| 27653 | 27652 | } |
| 27654 | 27653 | |
| ... | ... | @@ -27958,8 +27957,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 27958 | 27957 | LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(val->data.x_lazy); |
| 27959 | 27958 | IrAnalyze *ira = lazy_align_of->ira; |
| 27960 | 27959 | |
| 27961 | | if (lazy_align_of->target_type->value.special == ConstValSpecialStatic) { |
| 27962 | | switch (lazy_align_of->target_type->value.data.x_type->id) { |
| 27960 | if (lazy_align_of->target_type->value->special == ConstValSpecialStatic) { |
| 27961 | switch (lazy_align_of->target_type->value->data.x_type->id) { |
| 27963 | 27962 | case ZigTypeIdInvalid: |
| 27964 | 27963 | zig_unreachable(); |
| 27965 | 27964 | case ZigTypeIdMetaType: |
| ... | ... | @@ -27975,7 +27974,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 27975 | 27974 | case ZigTypeIdOpaque: |
| 27976 | 27975 | ir_add_error(ira, lazy_align_of->target_type, |
| 27977 | 27976 | buf_sprintf("no align available for type '%s'", |
| 27978 | | buf_ptr(&lazy_align_of->target_type->value.data.x_type->name))); |
| 27977 | buf_ptr(&lazy_align_of->target_type->value->data.x_type->name))); |
| 27979 | 27978 | return ErrorSemanticAnalyzeFail; |
| 27980 | 27979 | case ZigTypeIdBool: |
| 27981 | 27980 | case ZigTypeIdInt: |
| ... | ... | @@ -27997,7 +27996,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 27997 | 27996 | } |
| 27998 | 27997 | |
| 27999 | 27998 | uint32_t align_in_bytes; |
| 28000 | | if ((err = type_val_resolve_abi_align(ira->codegen, &lazy_align_of->target_type->value, |
| 27999 | if ((err = type_val_resolve_abi_align(ira->codegen, lazy_align_of->target_type->value, |
| 28001 | 28000 | &align_in_bytes))) |
| 28002 | 28001 | { |
| 28003 | 28002 | return err; |
| ... | ... | @@ -28012,8 +28011,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 28012 | 28011 | LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy); |
| 28013 | 28012 | IrAnalyze *ira = lazy_size_of->ira; |
| 28014 | 28013 | |
| 28015 | | if (lazy_size_of->target_type->value.special == ConstValSpecialStatic) { |
| 28016 | | switch (lazy_size_of->target_type->value.data.x_type->id) { |
| 28014 | if (lazy_size_of->target_type->value->special == ConstValSpecialStatic) { |
| 28015 | switch (lazy_size_of->target_type->value->data.x_type->id) { |
| 28017 | 28016 | case ZigTypeIdInvalid: // handled above |
| 28018 | 28017 | zig_unreachable(); |
| 28019 | 28018 | case ZigTypeIdUnreachable: |
| ... | ... | @@ -28024,7 +28023,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 28024 | 28023 | case ZigTypeIdOpaque: |
| 28025 | 28024 | ir_add_error(ira, lazy_size_of->target_type, |
| 28026 | 28025 | buf_sprintf("no size available for type '%s'", |
| 28027 | | buf_ptr(&lazy_size_of->target_type->value.data.x_type->name))); |
| 28026 | buf_ptr(&lazy_size_of->target_type->value->data.x_type->name))); |
| 28028 | 28027 | return ErrorSemanticAnalyzeFail; |
| 28029 | 28028 | case ZigTypeIdMetaType: |
| 28030 | 28029 | case ZigTypeIdEnumLiteral: |
| ... | ... | @@ -28052,7 +28051,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 28052 | 28051 | |
| 28053 | 28052 | size_t abi_size; |
| 28054 | 28053 | size_t size_in_bits; |
| 28055 | | if ((err = type_val_resolve_abi_size(ira->codegen, source_node, &lazy_size_of->target_type->value, |
| 28054 | if ((err = type_val_resolve_abi_size(ira->codegen, source_node, lazy_size_of->target_type->value, |
| 28056 | 28055 | &abi_size, &size_in_bits))) |
| 28057 | 28056 | { |
| 28058 | 28057 | return err; |
| ... | ... | @@ -28073,10 +28072,10 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 28073 | 28072 | |
| 28074 | 28073 | ZigValue *sentinel_val; |
| 28075 | 28074 | if (lazy_slice_type->sentinel != nullptr) { |
| 28076 | | if (type_is_invalid(lazy_slice_type->sentinel->value.type)) |
| 28075 | if (type_is_invalid(lazy_slice_type->sentinel->value->type)) |
| 28077 | 28076 | return ErrorSemanticAnalyzeFail; |
| 28078 | 28077 | IrInstruction *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type); |
| 28079 | | if (type_is_invalid(sentinel->value.type)) |
| 28078 | if (type_is_invalid(sentinel->value->type)) |
| 28080 | 28079 | return ErrorSemanticAnalyzeFail; |
| 28081 | 28080 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| 28082 | 28081 | if (sentinel_val == nullptr) |
| ... | ... | @@ -28151,10 +28150,10 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 28151 | 28150 | |
| 28152 | 28151 | ZigValue *sentinel_val; |
| 28153 | 28152 | if (lazy_ptr_type->sentinel != nullptr) { |
| 28154 | | if (type_is_invalid(lazy_ptr_type->sentinel->value.type)) |
| 28153 | if (type_is_invalid(lazy_ptr_type->sentinel->value->type)) |
| 28155 | 28154 | return ErrorSemanticAnalyzeFail; |
| 28156 | 28155 | IrInstruction *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type); |
| 28157 | | if (type_is_invalid(sentinel->value.type)) |
| 28156 | if (type_is_invalid(sentinel->value->type)) |
| 28158 | 28157 | return ErrorSemanticAnalyzeFail; |
| 28159 | 28158 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| 28160 | 28159 | if (sentinel_val == nullptr) |