| ... | @@ -1555,7 +1555,8 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -1555,7 +1555,8 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 1555 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; | 1555 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; |
| 1556 | const pointee_ty = try sema.resolveType(block, src, bin_inst.lhs); | 1556 | const pointee_ty = try sema.resolveType(block, src, bin_inst.lhs); |
| 1557 | const ptr = sema.resolveInst(bin_inst.rhs); | 1557 | const ptr = sema.resolveInst(bin_inst.rhs); |
| 1558 | const addr_space = target_util.defaultAddressSpace(sema.mod.getTarget(), .local); | 1558 | const target = sema.mod.getTarget(); |
| | 1559 | const addr_space = target_util.defaultAddressSpace(target, .local); |
| 1559 | | 1560 | |
| 1560 | if (Air.refToIndex(ptr)) |ptr_inst| { | 1561 | if (Air.refToIndex(ptr)) |ptr_inst| { |
| 1561 | if (sema.air_instructions.items(.tag)[ptr_inst] == .constant) { | 1562 | if (sema.air_instructions.items(.tag)[ptr_inst] == .constant) { |
| ... | @@ -1575,7 +1576,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -1575,7 +1576,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 1575 | try inferred_alloc.stored_inst_list.append(sema.arena, operand); | 1576 | try inferred_alloc.stored_inst_list.append(sema.arena, operand); |
| 1576 | | 1577 | |
| 1577 | try sema.requireRuntimeBlock(block, src); | 1578 | try sema.requireRuntimeBlock(block, src); |
| 1578 | const ptr_ty = try Type.ptr(sema.arena, .{ | 1579 | const ptr_ty = try Type.ptr(sema.arena, target, .{ |
| 1579 | .pointee_type = pointee_ty, | 1580 | .pointee_type = pointee_ty, |
| 1580 | .@"align" = inferred_alloc.alignment, | 1581 | .@"align" = inferred_alloc.alignment, |
| 1581 | .@"addrspace" = addr_space, | 1582 | .@"addrspace" = addr_space, |
| ... | @@ -1593,7 +1594,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -1593,7 +1594,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 1593 | try pointee_ty.copy(anon_decl.arena()), | 1594 | try pointee_ty.copy(anon_decl.arena()), |
| 1594 | Value.undef, | 1595 | Value.undef, |
| 1595 | ); | 1596 | ); |
| 1596 | const ptr_ty = try Type.ptr(sema.arena, .{ | 1597 | const ptr_ty = try Type.ptr(sema.arena, target, .{ |
| 1597 | .pointee_type = pointee_ty, | 1598 | .pointee_type = pointee_ty, |
| 1598 | .@"align" = iac.data.alignment, | 1599 | .@"align" = iac.data.alignment, |
| 1599 | .@"addrspace" = addr_space, | 1600 | .@"addrspace" = addr_space, |
| ... | @@ -1642,7 +1643,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -1642,7 +1643,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 1642 | } | 1643 | } |
| 1643 | } | 1644 | } |
| 1644 | | 1645 | |
| 1645 | const ptr_ty = try Type.ptr(sema.arena, .{ | 1646 | const ptr_ty = try Type.ptr(sema.arena, target, .{ |
| 1646 | .pointee_type = pointee_ty, | 1647 | .pointee_type = pointee_ty, |
| 1647 | .@"addrspace" = addr_space, | 1648 | .@"addrspace" = addr_space, |
| 1648 | }); | 1649 | }); |
| ... | @@ -1663,7 +1664,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -1663,7 +1664,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 1663 | } | 1664 | } |
| 1664 | const ty_op = air_datas[trash_inst].ty_op; | 1665 | const ty_op = air_datas[trash_inst].ty_op; |
| 1665 | const operand_ty = sema.getTmpAir().typeOf(ty_op.operand); | 1666 | const operand_ty = sema.getTmpAir().typeOf(ty_op.operand); |
| 1666 | const ptr_operand_ty = try Type.ptr(sema.arena, .{ | 1667 | const ptr_operand_ty = try Type.ptr(sema.arena, target, .{ |
| 1667 | .pointee_type = operand_ty, | 1668 | .pointee_type = operand_ty, |
| 1668 | .@"addrspace" = addr_space, | 1669 | .@"addrspace" = addr_space, |
| 1669 | }); | 1670 | }); |
| ... | @@ -2225,9 +2226,10 @@ fn zirRetPtr( | ... | @@ -2225,9 +2226,10 @@ fn zirRetPtr( |
| 2225 | return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0, src); | 2226 | return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0, src); |
| 2226 | } | 2227 | } |
| 2227 | | 2228 | |
| 2228 | const ptr_type = try Type.ptr(sema.arena, .{ | 2229 | const target = sema.mod.getTarget(); |
| | 2230 | const ptr_type = try Type.ptr(sema.arena, target, .{ |
| 2229 | .pointee_type = sema.fn_ret_ty, | 2231 | .pointee_type = sema.fn_ret_ty, |
| 2230 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | 2232 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 2231 | }); | 2233 | }); |
| 2232 | | 2234 | |
| 2233 | if (block.inlining != null) { | 2235 | if (block.inlining != null) { |
| ... | @@ -2389,10 +2391,11 @@ fn zirAllocExtended( | ... | @@ -2389,10 +2391,11 @@ fn zirAllocExtended( |
| 2389 | if (!small.is_const) { | 2391 | if (!small.is_const) { |
| 2390 | try sema.validateVarType(block, ty_src, var_ty, false); | 2392 | try sema.validateVarType(block, ty_src, var_ty, false); |
| 2391 | } | 2393 | } |
| 2392 | const ptr_type = try Type.ptr(sema.arena, .{ | 2394 | const target = sema.mod.getTarget(); |
| | 2395 | const ptr_type = try Type.ptr(sema.arena, target, .{ |
| 2393 | .pointee_type = var_ty, | 2396 | .pointee_type = var_ty, |
| 2394 | .@"align" = alignment, | 2397 | .@"align" = alignment, |
| 2395 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | 2398 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 2396 | }); | 2399 | }); |
| 2397 | try sema.requireRuntimeBlock(block, src); | 2400 | try sema.requireRuntimeBlock(block, src); |
| 2398 | try sema.resolveTypeLayout(block, src, var_ty); | 2401 | try sema.resolveTypeLayout(block, src, var_ty); |
| ... | @@ -2450,9 +2453,10 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -2450,9 +2453,10 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 2450 | if (block.is_comptime) { | 2453 | if (block.is_comptime) { |
| 2451 | return sema.analyzeComptimeAlloc(block, var_ty, 0, ty_src); | 2454 | return sema.analyzeComptimeAlloc(block, var_ty, 0, ty_src); |
| 2452 | } | 2455 | } |
| 2453 | const ptr_type = try Type.ptr(sema.arena, .{ | 2456 | const target = sema.mod.getTarget(); |
| | 2457 | const ptr_type = try Type.ptr(sema.arena, target, .{ |
| 2454 | .pointee_type = var_ty, | 2458 | .pointee_type = var_ty, |
| 2455 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | 2459 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 2456 | }); | 2460 | }); |
| 2457 | try sema.requireRuntimeBlock(block, var_decl_src); | 2461 | try sema.requireRuntimeBlock(block, var_decl_src); |
| 2458 | try sema.resolveTypeLayout(block, ty_src, var_ty); | 2462 | try sema.resolveTypeLayout(block, ty_src, var_ty); |
| ... | @@ -2471,9 +2475,10 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -2471,9 +2475,10 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 2471 | return sema.analyzeComptimeAlloc(block, var_ty, 0, ty_src); | 2475 | return sema.analyzeComptimeAlloc(block, var_ty, 0, ty_src); |
| 2472 | } | 2476 | } |
| 2473 | try sema.validateVarType(block, ty_src, var_ty, false); | 2477 | try sema.validateVarType(block, ty_src, var_ty, false); |
| 2474 | const ptr_type = try Type.ptr(sema.arena, .{ | 2478 | const target = sema.mod.getTarget(); |
| | 2479 | const ptr_type = try Type.ptr(sema.arena, target, .{ |
| 2475 | .pointee_type = var_ty, | 2480 | .pointee_type = var_ty, |
| 2476 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | 2481 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 2477 | }); | 2482 | }); |
| 2478 | try sema.requireRuntimeBlock(block, var_decl_src); | 2483 | try sema.requireRuntimeBlock(block, var_decl_src); |
| 2479 | try sema.resolveTypeLayout(block, ty_src, var_ty); | 2484 | try sema.resolveTypeLayout(block, ty_src, var_ty); |
| ... | @@ -2542,7 +2547,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -2542,7 +2547,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 2542 | try sema.mod.declareDeclDependency(sema.owner_decl, decl); | 2547 | try sema.mod.declareDeclDependency(sema.owner_decl, decl); |
| 2543 | | 2548 | |
| 2544 | const final_elem_ty = try decl.ty.copy(sema.arena); | 2549 | const final_elem_ty = try decl.ty.copy(sema.arena); |
| 2545 | const final_ptr_ty = try Type.ptr(sema.arena, .{ | 2550 | const final_ptr_ty = try Type.ptr(sema.arena, target, .{ |
| 2546 | .pointee_type = final_elem_ty, | 2551 | .pointee_type = final_elem_ty, |
| 2547 | .mutable = var_is_mut, | 2552 | .mutable = var_is_mut, |
| 2548 | .@"align" = iac.data.alignment, | 2553 | .@"align" = iac.data.alignment, |
| ... | @@ -2565,7 +2570,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -2565,7 +2570,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 2565 | const peer_inst_list = inferred_alloc.data.stored_inst_list.items; | 2570 | const peer_inst_list = inferred_alloc.data.stored_inst_list.items; |
| 2566 | const final_elem_ty = try sema.resolvePeerTypes(block, ty_src, peer_inst_list, .none); | 2571 | const final_elem_ty = try sema.resolvePeerTypes(block, ty_src, peer_inst_list, .none); |
| 2567 | | 2572 | |
| 2568 | const final_ptr_ty = try Type.ptr(sema.arena, .{ | 2573 | const final_ptr_ty = try Type.ptr(sema.arena, target, .{ |
| 2569 | .pointee_type = final_elem_ty, | 2574 | .pointee_type = final_elem_ty, |
| 2570 | .mutable = var_is_mut, | 2575 | .mutable = var_is_mut, |
| 2571 | .@"align" = inferred_alloc.data.alignment, | 2576 | .@"align" = inferred_alloc.data.alignment, |
| ... | @@ -3335,10 +3340,11 @@ fn storeToInferredAlloc( | ... | @@ -3335,10 +3340,11 @@ fn storeToInferredAlloc( |
| 3335 | // for the inferred allocation. | 3340 | // for the inferred allocation. |
| 3336 | try inferred_alloc.data.stored_inst_list.append(sema.arena, operand); | 3341 | try inferred_alloc.data.stored_inst_list.append(sema.arena, operand); |
| 3337 | // Create a runtime bitcast instruction with exactly the type the pointer wants. | 3342 | // Create a runtime bitcast instruction with exactly the type the pointer wants. |
| 3338 | const ptr_ty = try Type.ptr(sema.arena, .{ | 3343 | const target = sema.mod.getTarget(); |
| | 3344 | const ptr_ty = try Type.ptr(sema.arena, target, .{ |
| 3339 | .pointee_type = operand_ty, | 3345 | .pointee_type = operand_ty, |
| 3340 | .@"align" = inferred_alloc.data.alignment, | 3346 | .@"align" = inferred_alloc.data.alignment, |
| 3341 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | 3347 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 3342 | }); | 3348 | }); |
| 3343 | const bitcasted_ptr = try block.addBitCast(ptr_ty, ptr); | 3349 | const bitcasted_ptr = try block.addBitCast(ptr_ty, ptr); |
| 3344 | return sema.storePtr(block, src, bitcasted_ptr, operand); | 3350 | return sema.storePtr(block, src, bitcasted_ptr, operand); |
| ... | @@ -5444,7 +5450,8 @@ fn analyzeOptionalPayloadPtr( | ... | @@ -5444,7 +5450,8 @@ fn analyzeOptionalPayloadPtr( |
| 5444 | } | 5450 | } |
| 5445 | | 5451 | |
| 5446 | const child_type = try opt_type.optionalChildAlloc(sema.arena); | 5452 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| 5447 | const child_pointer = try Type.ptr(sema.arena, .{ | 5453 | const target = sema.mod.getTarget(); |
| | 5454 | const child_pointer = try Type.ptr(sema.arena, target, .{ |
| 5448 | .pointee_type = child_type, | 5455 | .pointee_type = child_type, |
| 5449 | .mutable = !optional_ptr_ty.isConstPtr(), | 5456 | .mutable = !optional_ptr_ty.isConstPtr(), |
| 5450 | .@"addrspace" = optional_ptr_ty.ptrAddressSpace(), | 5457 | .@"addrspace" = optional_ptr_ty.ptrAddressSpace(), |
| ... | @@ -5509,7 +5516,8 @@ fn zirOptionalPayload( | ... | @@ -5509,7 +5516,8 @@ fn zirOptionalPayload( |
| 5509 | return sema.failWithExpectedOptionalType(block, src, operand_ty); | 5516 | return sema.failWithExpectedOptionalType(block, src, operand_ty); |
| 5510 | } | 5517 | } |
| 5511 | const ptr_info = operand_ty.ptrInfo().data; | 5518 | const ptr_info = operand_ty.ptrInfo().data; |
| 5512 | break :t try Type.ptr(sema.arena, .{ | 5519 | const target = sema.mod.getTarget(); |
| | 5520 | break :t try Type.ptr(sema.arena, target, .{ |
| 5513 | .pointee_type = try ptr_info.pointee_type.copy(sema.arena), | 5521 | .pointee_type = try ptr_info.pointee_type.copy(sema.arena), |
| 5514 | .@"align" = ptr_info.@"align", | 5522 | .@"align" = ptr_info.@"align", |
| 5515 | .@"addrspace" = ptr_info.@"addrspace", | 5523 | .@"addrspace" = ptr_info.@"addrspace", |
| ... | @@ -5607,7 +5615,8 @@ fn analyzeErrUnionPayloadPtr( | ... | @@ -5607,7 +5615,8 @@ fn analyzeErrUnionPayloadPtr( |
| 5607 | return sema.fail(block, src, "expected error union type, found {}", .{operand_ty.elemType()}); | 5615 | return sema.fail(block, src, "expected error union type, found {}", .{operand_ty.elemType()}); |
| 5608 | | 5616 | |
| 5609 | const payload_ty = operand_ty.elemType().errorUnionPayload(); | 5617 | const payload_ty = operand_ty.elemType().errorUnionPayload(); |
| 5610 | const operand_pointer_ty = try Type.ptr(sema.arena, .{ | 5618 | const target = sema.mod.getTarget(); |
| | 5619 | const operand_pointer_ty = try Type.ptr(sema.arena, target, .{ |
| 5611 | .pointee_type = payload_ty, | 5620 | .pointee_type = payload_ty, |
| 5612 | .mutable = !operand_ty.isConstPtr(), | 5621 | .mutable = !operand_ty.isConstPtr(), |
| 5613 | .@"addrspace" = operand_ty.ptrAddressSpace(), | 5622 | .@"addrspace" = operand_ty.ptrAddressSpace(), |
| ... | @@ -6517,7 +6526,8 @@ fn zirSwitchCapture( | ... | @@ -6517,7 +6526,8 @@ fn zirSwitchCapture( |
| 6517 | if (is_ref) { | 6526 | if (is_ref) { |
| 6518 | assert(operand_is_ref); | 6527 | assert(operand_is_ref); |
| 6519 | | 6528 | |
| 6520 | const field_ty_ptr = try Type.ptr(sema.arena, .{ | 6529 | const target = sema.mod.getTarget(); |
| | 6530 | const field_ty_ptr = try Type.ptr(sema.arena, target, .{ |
| 6521 | .pointee_type = field.ty, | 6531 | .pointee_type = field.ty, |
| 6522 | .@"addrspace" = .generic, | 6532 | .@"addrspace" = .generic, |
| 6523 | .mutable = operand_ptr_ty.ptrIsMutable(), | 6533 | .mutable = operand_ptr_ty.ptrIsMutable(), |
| ... | @@ -11327,7 +11337,8 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -11327,7 +11337,8 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 11327 | | 11337 | |
| 11328 | const inst_data = sema.code.instructions.items(.data)[inst].ptr_type_simple; | 11338 | const inst_data = sema.code.instructions.items(.data)[inst].ptr_type_simple; |
| 11329 | const elem_type = try sema.resolveType(block, .unneeded, inst_data.elem_type); | 11339 | const elem_type = try sema.resolveType(block, .unneeded, inst_data.elem_type); |
| 11330 | const ty = try Type.ptr(sema.arena, .{ | 11340 | const target = sema.mod.getTarget(); |
| | 11341 | const ty = try Type.ptr(sema.arena, target, .{ |
| 11331 | .pointee_type = elem_type, | 11342 | .pointee_type = elem_type, |
| 11332 | .@"addrspace" = .generic, | 11343 | .@"addrspace" = .generic, |
| 11333 | .mutable = inst_data.is_mutable, | 11344 | .mutable = inst_data.is_mutable, |
| ... | @@ -11343,6 +11354,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -11343,6 +11354,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 11343 | defer tracy.end(); | 11354 | defer tracy.end(); |
| 11344 | | 11355 | |
| 11345 | const src: LazySrcLoc = .unneeded; | 11356 | const src: LazySrcLoc = .unneeded; |
| | 11357 | const elem_ty_src: LazySrcLoc = .unneeded; |
| 11346 | const inst_data = sema.code.instructions.items(.data)[inst].ptr_type; | 11358 | const inst_data = sema.code.instructions.items(.data)[inst].ptr_type; |
| 11347 | const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index); | 11359 | const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index); |
| 11348 | | 11360 | |
| ... | @@ -11366,41 +11378,40 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -11366,41 +11378,40 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 11366 | break :blk try sema.analyzeAddrspace(block, .unneeded, ref, .pointer); | 11378 | break :blk try sema.analyzeAddrspace(block, .unneeded, ref, .pointer); |
| 11367 | } else .generic; | 11379 | } else .generic; |
| 11368 | | 11380 | |
| 11369 | const bit_start = if (inst_data.flags.has_bit_range) blk: { | 11381 | const bit_offset = if (inst_data.flags.has_bit_range) blk: { |
| 11370 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); | 11382 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); |
| 11371 | extra_i += 1; | 11383 | extra_i += 1; |
| 11372 | break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u16); | 11384 | break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u16); |
| 11373 | } else 0; | 11385 | } else 0; |
| 11374 | | 11386 | |
| 11375 | var host_size: u16 = if (inst_data.flags.has_bit_range) blk: { | 11387 | const host_size: u16 = if (inst_data.flags.has_bit_range) blk: { |
| 11376 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); | 11388 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); |
| 11377 | extra_i += 1; | 11389 | extra_i += 1; |
| 11378 | break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u16); | 11390 | break :blk try sema.resolveAlreadyCoercedInt(block, .unneeded, ref, u16); |
| 11379 | } else 0; | 11391 | } else 0; |
| 11380 | | 11392 | |
| 11381 | const elem_type = try sema.resolveType(block, .unneeded, extra.data.elem_type); | 11393 | if (host_size != 0 and bit_offset >= host_size * 8) { |
| 11382 | | 11394 | return sema.fail(block, src, "bit offset starts after end of host integer", .{}); |
| 11383 | if (host_size != 0) { | | |
| 11384 | if (bit_start >= host_size * 8) { | | |
| 11385 | return sema.fail(block, src, "bit offset starts after end of host integer", .{}); | | |
| 11386 | } | | |
| 11387 | const target = sema.mod.getTarget(); | | |
| 11388 | const elem_type_bits = elem_type.bitSize(target); | | |
| 11389 | if (host_size * 8 == elem_type_bits) { | | |
| 11390 | assert(bit_start == 0); | | |
| 11391 | host_size = 0; | | |
| 11392 | } | | |
| 11393 | } | 11395 | } |
| 11394 | | 11396 | |
| 11395 | const ty = try Type.ptr(sema.arena, .{ | 11397 | const unresolved_elem_ty = try sema.resolveType(block, elem_ty_src, extra.data.elem_type); |
| 11396 | .pointee_type = elem_type, | 11398 | const elem_ty = if (abi_align == 0) |
| | 11399 | unresolved_elem_ty |
| | 11400 | else t: { |
| | 11401 | const elem_ty = try sema.resolveTypeFields(block, elem_ty_src, unresolved_elem_ty); |
| | 11402 | try sema.resolveTypeLayout(block, elem_ty_src, elem_ty); |
| | 11403 | break :t elem_ty; |
| | 11404 | }; |
| | 11405 | const target = sema.mod.getTarget(); |
| | 11406 | const ty = try Type.ptr(sema.arena, target, .{ |
| | 11407 | .pointee_type = elem_ty, |
| 11397 | .sentinel = sentinel, | 11408 | .sentinel = sentinel, |
| 11398 | .@"align" = abi_align, | 11409 | .@"align" = abi_align, |
| 11399 | .@"addrspace" = address_space, | 11410 | .@"addrspace" = address_space, |
| 11400 | .bit_offset = bit_start, | 11411 | .bit_offset = bit_offset, |
| 11401 | .host_size = host_size, | 11412 | .host_size = host_size, |
| 11402 | .mutable = inst_data.flags.is_mutable, | 11413 | .mutable = inst_data.flags.is_mutable, |
| 11403 | .@"allowzero" = inst_data.flags.is_allowzero or inst_data.size == .C, | 11414 | .@"allowzero" = inst_data.flags.is_allowzero, |
| 11404 | .@"volatile" = inst_data.flags.is_volatile, | 11415 | .@"volatile" = inst_data.flags.is_volatile, |
| 11405 | .size = inst_data.size, | 11416 | .size = inst_data.size, |
| 11406 | }); | 11417 | }); |
| ... | @@ -11721,15 +11732,16 @@ fn zirArrayInit( | ... | @@ -11721,15 +11732,16 @@ fn zirArrayInit( |
| 11721 | try sema.resolveTypeLayout(block, src, elem_ty); | 11732 | try sema.resolveTypeLayout(block, src, elem_ty); |
| 11722 | | 11733 | |
| 11723 | if (is_ref) { | 11734 | if (is_ref) { |
| 11724 | const alloc_ty = try Type.ptr(sema.arena, .{ | 11735 | const target = sema.mod.getTarget(); |
| | 11736 | const alloc_ty = try Type.ptr(sema.arena, target, .{ |
| 11725 | .pointee_type = array_ty, | 11737 | .pointee_type = array_ty, |
| 11726 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | 11738 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 11727 | }); | 11739 | }); |
| 11728 | const alloc = try block.addTy(.alloc, alloc_ty); | 11740 | const alloc = try block.addTy(.alloc, alloc_ty); |
| 11729 | | 11741 | |
| 11730 | const elem_ptr_ty = try Type.ptr(sema.arena, .{ | 11742 | const elem_ptr_ty = try Type.ptr(sema.arena, target, .{ |
| 11731 | .mutable = true, | 11743 | .mutable = true, |
| 11732 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | 11744 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 11733 | .pointee_type = elem_ty, | 11745 | .pointee_type = elem_ty, |
| 11734 | }); | 11746 | }); |
| 11735 | const elem_ptr_ty_ref = try sema.addType(elem_ptr_ty); | 11747 | const elem_ptr_ty_ref = try sema.addType(elem_ptr_ty); |
| ... | @@ -11788,12 +11800,13 @@ fn zirArrayInitAnon( | ... | @@ -11788,12 +11800,13 @@ fn zirArrayInitAnon( |
| 11788 | try sema.requireRuntimeBlock(block, runtime_src); | 11800 | try sema.requireRuntimeBlock(block, runtime_src); |
| 11789 | | 11801 | |
| 11790 | if (is_ref) { | 11802 | if (is_ref) { |
| | 11803 | const target = sema.mod.getTarget(); |
| 11791 | const alloc = try block.addTy(.alloc, tuple_ty); | 11804 | const alloc = try block.addTy(.alloc, tuple_ty); |
| 11792 | for (operands) |operand, i_usize| { | 11805 | for (operands) |operand, i_usize| { |
| 11793 | const i = @intCast(u32, i_usize); | 11806 | const i = @intCast(u32, i_usize); |
| 11794 | const field_ptr_ty = try Type.ptr(sema.arena, .{ | 11807 | const field_ptr_ty = try Type.ptr(sema.arena, target, .{ |
| 11795 | .mutable = true, | 11808 | .mutable = true, |
| 11796 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | 11809 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 11797 | .pointee_type = types[i], | 11810 | .pointee_type = types[i], |
| 11798 | }); | 11811 | }); |
| 11799 | const field_ptr = try block.addStructFieldPtr(alloc, i, field_ptr_ty); | 11812 | const field_ptr = try block.addStructFieldPtr(alloc, i, field_ptr_ty); |
| ... | @@ -12068,6 +12081,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -12068,6 +12081,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 12068 | const union_val = val.cast(Value.Payload.Union).?.data; | 12081 | const union_val = val.cast(Value.Payload.Union).?.data; |
| 12069 | const tag_ty = type_info_ty.unionTagType().?; | 12082 | const tag_ty = type_info_ty.unionTagType().?; |
| 12070 | const tag_index = tag_ty.enumTagFieldIndex(union_val.tag).?; | 12083 | const tag_index = tag_ty.enumTagFieldIndex(union_val.tag).?; |
| | 12084 | const target = sema.mod.getTarget(); |
| 12071 | switch (@intToEnum(std.builtin.TypeId, tag_index)) { | 12085 | switch (@intToEnum(std.builtin.TypeId, tag_index)) { |
| 12072 | .Type => return Air.Inst.Ref.type_type, | 12086 | .Type => return Air.Inst.Ref.type_type, |
| 12073 | .Void => return Air.Inst.Ref.void_type, | 12087 | .Void => return Air.Inst.Ref.void_type, |
| ... | @@ -12146,11 +12160,14 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -12146,11 +12160,14 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 12146 | return sema.fail(block, src, "sentinels are only allowed on slices and unknown-length pointers", .{}); | 12160 | return sema.fail(block, src, "sentinels are only allowed on slices and unknown-length pointers", .{}); |
| 12147 | } | 12161 | } |
| 12148 | const sentinel_ptr_val = sentinel_val.castTag(.opt_payload).?.data; | 12162 | const sentinel_ptr_val = sentinel_val.castTag(.opt_payload).?.data; |
| 12149 | const ptr_ty = try Type.ptr(sema.arena, .{ .@"addrspace" = .generic, .pointee_type = child_ty }); | 12163 | const ptr_ty = try Type.ptr(sema.arena, target, .{ |
| | 12164 | .@"addrspace" = .generic, |
| | 12165 | .pointee_type = child_ty, |
| | 12166 | }); |
| 12150 | actual_sentinel = (try sema.pointerDeref(block, src, sentinel_ptr_val, ptr_ty)).?; | 12167 | actual_sentinel = (try sema.pointerDeref(block, src, sentinel_ptr_val, ptr_ty)).?; |
| 12151 | } | 12168 | } |
| 12152 | | 12169 | |
| 12153 | const ty = try Type.ptr(sema.arena, .{ | 12170 | const ty = try Type.ptr(sema.arena, target, .{ |
| 12154 | .size = ptr_size, | 12171 | .size = ptr_size, |
| 12155 | .mutable = !is_const_val.toBool(), | 12172 | .mutable = !is_const_val.toBool(), |
| 12156 | .@"volatile" = is_volatile_val.toBool(), | 12173 | .@"volatile" = is_volatile_val.toBool(), |
| ... | @@ -12176,7 +12193,10 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -12176,7 +12193,10 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 12176 | var buffer: Value.ToTypeBuffer = undefined; | 12193 | var buffer: Value.ToTypeBuffer = undefined; |
| 12177 | const child_ty = try child_val.toType(&buffer).copy(sema.arena); | 12194 | const child_ty = try child_val.toType(&buffer).copy(sema.arena); |
| 12178 | const sentinel = if (sentinel_val.castTag(.opt_payload)) |p| blk: { | 12195 | const sentinel = if (sentinel_val.castTag(.opt_payload)) |p| blk: { |
| 12179 | const ptr_ty = try Type.ptr(sema.arena, .{ .@"addrspace" = .generic, .pointee_type = child_ty }); | 12196 | const ptr_ty = try Type.ptr(sema.arena, target, .{ |
| | 12197 | .@"addrspace" = .generic, |
| | 12198 | .pointee_type = child_ty, |
| | 12199 | }); |
| 12180 | break :blk (try sema.pointerDeref(block, src, p.data, ptr_ty)).?; | 12200 | break :blk (try sema.pointerDeref(block, src, p.data, ptr_ty)).?; |
| 12181 | } else null; | 12201 | } else null; |
| 12182 | | 12202 | |
| ... | @@ -12468,7 +12488,8 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -12468,7 +12488,8 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 12468 | // TODO insert safety check that the alignment is correct | 12488 | // TODO insert safety check that the alignment is correct |
| 12469 | | 12489 | |
| 12470 | const ptr_info = ptr_ty.ptrInfo().data; | 12490 | const ptr_info = ptr_ty.ptrInfo().data; |
| 12471 | const dest_ty = try Type.ptr(sema.arena, .{ | 12491 | const target = sema.mod.getTarget(); |
| | 12492 | const dest_ty = try Type.ptr(sema.arena, target, .{ |
| 12472 | .pointee_type = ptr_info.pointee_type, | 12493 | .pointee_type = ptr_info.pointee_type, |
| 12473 | .@"align" = dest_align, | 12494 | .@"align" = dest_align, |
| 12474 | .@"addrspace" = ptr_info.@"addrspace", | 12495 | .@"addrspace" = ptr_info.@"addrspace", |
| ... | @@ -13408,11 +13429,12 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -13408,11 +13429,12 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 13408 | ptr_ty_data.@"align" = @intCast(u32, field.abi_align.toUnsignedInt()); | 13429 | ptr_ty_data.@"align" = @intCast(u32, field.abi_align.toUnsignedInt()); |
| 13409 | } | 13430 | } |
| 13410 | | 13431 | |
| 13411 | const actual_field_ptr_ty = try Type.ptr(sema.arena, ptr_ty_data); | 13432 | const target = sema.mod.getTarget(); |
| | 13433 | const actual_field_ptr_ty = try Type.ptr(sema.arena, target, ptr_ty_data); |
| 13412 | const casted_field_ptr = try sema.coerce(block, actual_field_ptr_ty, field_ptr, ptr_src); | 13434 | const casted_field_ptr = try sema.coerce(block, actual_field_ptr_ty, field_ptr, ptr_src); |
| 13413 | | 13435 | |
| 13414 | ptr_ty_data.pointee_type = struct_ty; | 13436 | ptr_ty_data.pointee_type = struct_ty; |
| 13415 | const result_ptr = try Type.ptr(sema.arena, ptr_ty_data); | 13437 | const result_ptr = try Type.ptr(sema.arena, target, ptr_ty_data); |
| 13416 | | 13438 | |
| 13417 | if (try sema.resolveDefinedValue(block, src, casted_field_ptr)) |field_ptr_val| { | 13439 | if (try sema.resolveDefinedValue(block, src, casted_field_ptr)) |field_ptr_val| { |
| 13418 | const payload = field_ptr_val.castTag(.field_ptr).?.data; | 13440 | const payload = field_ptr_val.castTag(.field_ptr).?.data; |
| ... | @@ -13509,7 +13531,8 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -13509,7 +13531,8 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 13509 | const uncasted_src_ptr_ty = sema.typeOf(uncasted_src_ptr); | 13531 | const uncasted_src_ptr_ty = sema.typeOf(uncasted_src_ptr); |
| 13510 | try sema.checkPtrOperand(block, src_src, uncasted_src_ptr_ty); | 13532 | try sema.checkPtrOperand(block, src_src, uncasted_src_ptr_ty); |
| 13511 | const src_ptr_info = uncasted_src_ptr_ty.ptrInfo().data; | 13533 | const src_ptr_info = uncasted_src_ptr_ty.ptrInfo().data; |
| 13512 | const wanted_src_ptr_ty = try Type.ptr(sema.arena, .{ | 13534 | const target = sema.mod.getTarget(); |
| | 13535 | const wanted_src_ptr_ty = try Type.ptr(sema.arena, target, .{ |
| 13513 | .pointee_type = dest_ptr_ty.elemType2(), | 13536 | .pointee_type = dest_ptr_ty.elemType2(), |
| 13514 | .@"align" = src_ptr_info.@"align", | 13537 | .@"align" = src_ptr_info.@"align", |
| 13515 | .@"addrspace" = src_ptr_info.@"addrspace", | 13538 | .@"addrspace" = src_ptr_info.@"addrspace", |
| ... | @@ -14149,9 +14172,10 @@ fn panicWithMsg( | ... | @@ -14149,9 +14172,10 @@ fn panicWithMsg( |
| 14149 | const panic_fn = try sema.getBuiltin(block, src, "panic"); | 14172 | const panic_fn = try sema.getBuiltin(block, src, "panic"); |
| 14150 | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace"); | 14173 | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace"); |
| 14151 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); | 14174 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); |
| 14152 | const ptr_stack_trace_ty = try Type.ptr(arena, .{ | 14175 | const target = mod.getTarget(); |
| | 14176 | const ptr_stack_trace_ty = try Type.ptr(arena, target, .{ |
| 14153 | .pointee_type = stack_trace_ty, | 14177 | .pointee_type = stack_trace_ty, |
| 14154 | .@"addrspace" = target_util.defaultAddressSpace(mod.getTarget(), .global_constant), // TODO might need a place that is more dynamic | 14178 | .@"addrspace" = target_util.defaultAddressSpace(target, .global_constant), // TODO might need a place that is more dynamic |
| 14155 | }); | 14179 | }); |
| 14156 | const null_stack_trace = try sema.addConstant( | 14180 | const null_stack_trace = try sema.addConstant( |
| 14157 | try Type.optional(arena, ptr_stack_trace_ty), | 14181 | try Type.optional(arena, ptr_stack_trace_ty), |
| ... | @@ -14405,6 +14429,8 @@ fn fieldPtr( | ... | @@ -14405,6 +14429,8 @@ fn fieldPtr( |
| 14405 | else | 14429 | else |
| 14406 | object_ty; | 14430 | object_ty; |
| 14407 | | 14431 | |
| | 14432 | const target = sema.mod.getTarget(); |
| | 14433 | |
| 14408 | switch (inner_ty.zigTypeTag()) { | 14434 | switch (inner_ty.zigTypeTag()) { |
| 14409 | .Array => { | 14435 | .Array => { |
| 14410 | if (mem.eql(u8, field_name, "len")) { | 14436 | if (mem.eql(u8, field_name, "len")) { |
| ... | @@ -14444,7 +14470,7 @@ fn fieldPtr( | ... | @@ -14444,7 +14470,7 @@ fn fieldPtr( |
| 14444 | } | 14470 | } |
| 14445 | try sema.requireRuntimeBlock(block, src); | 14471 | try sema.requireRuntimeBlock(block, src); |
| 14446 | | 14472 | |
| 14447 | const result_ty = try Type.ptr(sema.arena, .{ | 14473 | const result_ty = try Type.ptr(sema.arena, target, .{ |
| 14448 | .pointee_type = slice_ptr_ty, | 14474 | .pointee_type = slice_ptr_ty, |
| 14449 | .mutable = object_ptr_ty.ptrIsMutable(), | 14475 | .mutable = object_ptr_ty.ptrIsMutable(), |
| 14450 | .@"addrspace" = object_ptr_ty.ptrAddressSpace(), | 14476 | .@"addrspace" = object_ptr_ty.ptrAddressSpace(), |
| ... | @@ -14463,7 +14489,7 @@ fn fieldPtr( | ... | @@ -14463,7 +14489,7 @@ fn fieldPtr( |
| 14463 | } | 14489 | } |
| 14464 | try sema.requireRuntimeBlock(block, src); | 14490 | try sema.requireRuntimeBlock(block, src); |
| 14465 | | 14491 | |
| 14466 | const result_ty = try Type.ptr(sema.arena, .{ | 14492 | const result_ty = try Type.ptr(sema.arena, target, .{ |
| 14467 | .pointee_type = Type.usize, | 14493 | .pointee_type = Type.usize, |
| 14468 | .mutable = object_ptr_ty.ptrIsMutable(), | 14494 | .mutable = object_ptr_ty.ptrIsMutable(), |
| 14469 | .@"addrspace" = object_ptr_ty.ptrAddressSpace(), | 14495 | .@"addrspace" = object_ptr_ty.ptrAddressSpace(), |
| ... | @@ -14692,7 +14718,8 @@ fn finishFieldCallBind( | ... | @@ -14692,7 +14718,8 @@ fn finishFieldCallBind( |
| 14692 | object_ptr: Air.Inst.Ref, | 14718 | object_ptr: Air.Inst.Ref, |
| 14693 | ) CompileError!Air.Inst.Ref { | 14719 | ) CompileError!Air.Inst.Ref { |
| 14694 | const arena = sema.arena; | 14720 | const arena = sema.arena; |
| 14695 | const ptr_field_ty = try Type.ptr(arena, .{ | 14721 | const target = sema.mod.getTarget(); |
| | 14722 | const ptr_field_ty = try Type.ptr(arena, target, .{ |
| 14696 | .pointee_type = field_ty, | 14723 | .pointee_type = field_ty, |
| 14697 | .mutable = ptr_ty.ptrIsMutable(), | 14724 | .mutable = ptr_ty.ptrIsMutable(), |
| 14698 | .@"addrspace" = ptr_ty.ptrAddressSpace(), | 14725 | .@"addrspace" = ptr_ty.ptrAddressSpace(), |
| ... | @@ -14831,7 +14858,8 @@ fn structFieldPtrByIndex( | ... | @@ -14831,7 +14858,8 @@ fn structFieldPtrByIndex( |
| 14831 | } | 14858 | } |
| 14832 | } | 14859 | } |
| 14833 | | 14860 | |
| 14834 | const ptr_field_ty = try Type.ptr(sema.arena, ptr_ty_data); | 14861 | const target = sema.mod.getTarget(); |
| | 14862 | const ptr_field_ty = try Type.ptr(sema.arena, target, ptr_ty_data); |
| 14835 | | 14863 | |
| 14836 | if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| { | 14864 | if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| { |
| 14837 | return sema.addConstant( | 14865 | return sema.addConstant( |
| ... | @@ -14959,7 +14987,8 @@ fn unionFieldPtr( | ... | @@ -14959,7 +14987,8 @@ fn unionFieldPtr( |
| 14959 | const field_index = @intCast(u32, field_index_big); | 14987 | const field_index = @intCast(u32, field_index_big); |
| 14960 | | 14988 | |
| 14961 | const field = union_obj.fields.values()[field_index]; | 14989 | const field = union_obj.fields.values()[field_index]; |
| 14962 | const ptr_field_ty = try Type.ptr(arena, .{ | 14990 | const target = sema.mod.getTarget(); |
| | 14991 | const ptr_field_ty = try Type.ptr(arena, target, .{ |
| 14963 | .pointee_type = field.ty, | 14992 | .pointee_type = field.ty, |
| 14964 | .mutable = union_ptr_ty.ptrIsMutable(), | 14993 | .mutable = union_ptr_ty.ptrIsMutable(), |
| 14965 | .@"addrspace" = union_ptr_ty.ptrAddressSpace(), | 14994 | .@"addrspace" = union_ptr_ty.ptrAddressSpace(), |
| ... | @@ -15033,7 +15062,8 @@ fn elemPtr( | ... | @@ -15033,7 +15062,8 @@ fn elemPtr( |
| 15033 | .Pointer => { | 15062 | .Pointer => { |
| 15034 | // In all below cases, we have to deref the ptr operand to get the actual array pointer. | 15063 | // In all below cases, we have to deref the ptr operand to get the actual array pointer. |
| 15035 | const array = try sema.analyzeLoad(block, array_ptr_src, array_ptr, array_ptr_src); | 15064 | const array = try sema.analyzeLoad(block, array_ptr_src, array_ptr, array_ptr_src); |
| 15036 | const result_ty = try array_ty.elemPtrType(sema.arena); | 15065 | const target = sema.mod.getTarget(); |
| | 15066 | const result_ty = try array_ty.elemPtrType(sema.arena, target); |
| 15037 | switch (array_ty.ptrSize()) { | 15067 | switch (array_ty.ptrSize()) { |
| 15038 | .Slice => { | 15068 | .Slice => { |
| 15039 | const maybe_slice_val = try sema.resolveDefinedValue(block, array_ptr_src, array); | 15069 | const maybe_slice_val = try sema.resolveDefinedValue(block, array_ptr_src, array); |
| ... | @@ -15172,7 +15202,8 @@ fn tupleFieldPtr( | ... | @@ -15172,7 +15202,8 @@ fn tupleFieldPtr( |
| 15172 | } | 15202 | } |
| 15173 | | 15203 | |
| 15174 | const field_ty = tuple_info.types[field_index]; | 15204 | const field_ty = tuple_info.types[field_index]; |
| 15175 | const ptr_field_ty = try Type.ptr(sema.arena, .{ | 15205 | const target = sema.mod.getTarget(); |
| | 15206 | const ptr_field_ty = try Type.ptr(sema.arena, target, .{ |
| 15176 | .pointee_type = field_ty, | 15207 | .pointee_type = field_ty, |
| 15177 | .mutable = tuple_ptr_ty.ptrIsMutable(), | 15208 | .mutable = tuple_ptr_ty.ptrIsMutable(), |
| 15178 | .@"addrspace" = tuple_ptr_ty.ptrAddressSpace(), | 15209 | .@"addrspace" = tuple_ptr_ty.ptrAddressSpace(), |
| ... | @@ -15264,7 +15295,8 @@ fn elemPtrArray( | ... | @@ -15264,7 +15295,8 @@ fn elemPtrArray( |
| 15264 | elem_index_src: LazySrcLoc, | 15295 | elem_index_src: LazySrcLoc, |
| 15265 | ) CompileError!Air.Inst.Ref { | 15296 | ) CompileError!Air.Inst.Ref { |
| 15266 | const array_ptr_ty = sema.typeOf(array_ptr); | 15297 | const array_ptr_ty = sema.typeOf(array_ptr); |
| 15267 | const result_ty = try array_ptr_ty.elemPtrType(sema.arena); | 15298 | const target = sema.mod.getTarget(); |
| | 15299 | const result_ty = try array_ptr_ty.elemPtrType(sema.arena, target); |
| 15268 | | 15300 | |
| 15269 | if (try sema.resolveDefinedValue(block, src, array_ptr)) |array_ptr_val| { | 15301 | if (try sema.resolveDefinedValue(block, src, array_ptr)) |array_ptr_val| { |
| 15270 | if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| { | 15302 | if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| { |
| ... | @@ -15957,15 +15989,28 @@ fn coerceInMemoryAllowedPtrs( | ... | @@ -15957,15 +15989,28 @@ fn coerceInMemoryAllowedPtrs( |
| 15957 | // In this case, if they share the same child type, no need to resolve | 15989 | // In this case, if they share the same child type, no need to resolve |
| 15958 | // pointee type alignment. Otherwise both pointee types must have their alignment | 15990 | // pointee type alignment. Otherwise both pointee types must have their alignment |
| 15959 | // resolved and we compare the alignment numerically. | 15991 | // resolved and we compare the alignment numerically. |
| 15960 | if (src_info.@"align" != 0 or dest_info.@"align" != 0 or | 15992 | alignment: { |
| 15961 | !dest_info.pointee_type.eql(src_info.pointee_type)) | 15993 | if (src_info.@"align" == 0 and dest_info.@"align" == 0 and |
| 15962 | { | 15994 | dest_info.pointee_type.eql(src_info.pointee_type)) |
| 15963 | const src_align = src_info.@"align"; | 15995 | { |
| 15964 | const dest_align = dest_info.@"align"; | 15996 | break :alignment; |
| | 15997 | } |
| | 15998 | |
| | 15999 | const src_align = if (src_info.@"align" != 0) |
| | 16000 | src_info.@"align" |
| | 16001 | else |
| | 16002 | src_info.pointee_type.abiAlignment(target); |
| | 16003 | |
| | 16004 | const dest_align = if (dest_info.@"align" != 0) |
| | 16005 | dest_info.@"align" |
| | 16006 | else |
| | 16007 | dest_info.pointee_type.abiAlignment(target); |
| 15965 | | 16008 | |
| 15966 | if (dest_align > src_align) { | 16009 | if (dest_align > src_align) { |
| 15967 | return .no_match; | 16010 | return .no_match; |
| 15968 | } | 16011 | } |
| | 16012 | |
| | 16013 | break :alignment; |
| 15969 | } | 16014 | } |
| 15970 | | 16015 | |
| 15971 | return .ok; | 16016 | return .ok; |
| ... | @@ -16874,6 +16919,7 @@ fn analyzeDeclRef(sema: *Sema, decl: *Decl) CompileError!Air.Inst.Ref { | ... | @@ -16874,6 +16919,7 @@ fn analyzeDeclRef(sema: *Sema, decl: *Decl) CompileError!Air.Inst.Ref { |
| 16874 | try sema.mod.declareDeclDependency(sema.owner_decl, decl); | 16919 | try sema.mod.declareDeclDependency(sema.owner_decl, decl); |
| 16875 | try sema.ensureDeclAnalyzed(decl); | 16920 | try sema.ensureDeclAnalyzed(decl); |
| 16876 | | 16921 | |
| | 16922 | const target = sema.mod.getTarget(); |
| 16877 | const decl_tv = try decl.typedValue(); | 16923 | const decl_tv = try decl.typedValue(); |
| 16878 | if (decl_tv.val.castTag(.variable)) |payload| { | 16924 | if (decl_tv.val.castTag(.variable)) |payload| { |
| 16879 | const variable = payload.data; | 16925 | const variable = payload.data; |
| ... | @@ -16881,7 +16927,7 @@ fn analyzeDeclRef(sema: *Sema, decl: *Decl) CompileError!Air.Inst.Ref { | ... | @@ -16881,7 +16927,7 @@ fn analyzeDeclRef(sema: *Sema, decl: *Decl) CompileError!Air.Inst.Ref { |
| 16881 | 0 | 16927 | 0 |
| 16882 | else | 16928 | else |
| 16883 | @intCast(u32, decl.align_val.toUnsignedInt()); | 16929 | @intCast(u32, decl.align_val.toUnsignedInt()); |
| 16884 | const ty = try Type.ptr(sema.arena, .{ | 16930 | const ty = try Type.ptr(sema.arena, target, .{ |
| 16885 | .pointee_type = decl_tv.ty, | 16931 | .pointee_type = decl_tv.ty, |
| 16886 | .mutable = variable.is_mutable, | 16932 | .mutable = variable.is_mutable, |
| 16887 | .@"addrspace" = decl.@"addrspace", | 16933 | .@"addrspace" = decl.@"addrspace", |
| ... | @@ -16890,7 +16936,7 @@ fn analyzeDeclRef(sema: *Sema, decl: *Decl) CompileError!Air.Inst.Ref { | ... | @@ -16890,7 +16936,7 @@ fn analyzeDeclRef(sema: *Sema, decl: *Decl) CompileError!Air.Inst.Ref { |
| 16890 | return sema.addConstant(ty, try Value.Tag.decl_ref.create(sema.arena, decl)); | 16936 | return sema.addConstant(ty, try Value.Tag.decl_ref.create(sema.arena, decl)); |
| 16891 | } | 16937 | } |
| 16892 | return sema.addConstant( | 16938 | return sema.addConstant( |
| 16893 | try Type.ptr(sema.arena, .{ | 16939 | try Type.ptr(sema.arena, target, .{ |
| 16894 | .pointee_type = decl_tv.ty, | 16940 | .pointee_type = decl_tv.ty, |
| 16895 | .mutable = false, | 16941 | .mutable = false, |
| 16896 | .@"addrspace" = decl.@"addrspace", | 16942 | .@"addrspace" = decl.@"addrspace", |
| ... | @@ -16918,12 +16964,13 @@ fn analyzeRef( | ... | @@ -16918,12 +16964,13 @@ fn analyzeRef( |
| 16918 | | 16964 | |
| 16919 | try sema.requireRuntimeBlock(block, src); | 16965 | try sema.requireRuntimeBlock(block, src); |
| 16920 | const address_space = target_util.defaultAddressSpace(sema.mod.getTarget(), .local); | 16966 | const address_space = target_util.defaultAddressSpace(sema.mod.getTarget(), .local); |
| 16921 | const ptr_type = try Type.ptr(sema.arena, .{ | 16967 | const target = sema.mod.getTarget(); |
| | 16968 | const ptr_type = try Type.ptr(sema.arena, target, .{ |
| 16922 | .pointee_type = operand_ty, | 16969 | .pointee_type = operand_ty, |
| 16923 | .mutable = false, | 16970 | .mutable = false, |
| 16924 | .@"addrspace" = address_space, | 16971 | .@"addrspace" = address_space, |
| 16925 | }); | 16972 | }); |
| 16926 | const mut_ptr_type = try Type.ptr(sema.arena, .{ | 16973 | const mut_ptr_type = try Type.ptr(sema.arena, target, .{ |
| 16927 | .pointee_type = operand_ty, | 16974 | .pointee_type = operand_ty, |
| 16928 | .@"addrspace" = address_space, | 16975 | .@"addrspace" = address_space, |
| 16929 | }); | 16976 | }); |
| ... | @@ -17174,11 +17221,12 @@ fn analyzeSlice( | ... | @@ -17174,11 +17221,12 @@ fn analyzeSlice( |
| 17174 | | 17221 | |
| 17175 | const new_ptr_ty_info = sema.typeOf(new_ptr).ptrInfo().data; | 17222 | const new_ptr_ty_info = sema.typeOf(new_ptr).ptrInfo().data; |
| 17176 | const new_allowzero = new_ptr_ty_info.@"allowzero" and sema.typeOf(ptr).ptrSize() != .C; | 17223 | const new_allowzero = new_ptr_ty_info.@"allowzero" and sema.typeOf(ptr).ptrSize() != .C; |
| | 17224 | const target = sema.mod.getTarget(); |
| 17177 | | 17225 | |
| 17178 | if (opt_new_len_val) |new_len_val| { | 17226 | if (opt_new_len_val) |new_len_val| { |
| 17179 | const new_len_int = new_len_val.toUnsignedInt(); | 17227 | const new_len_int = new_len_val.toUnsignedInt(); |
| 17180 | | 17228 | |
| 17181 | const return_ty = try Type.ptr(sema.arena, .{ | 17229 | const return_ty = try Type.ptr(sema.arena, target, .{ |
| 17182 | .pointee_type = try Type.array(sema.arena, new_len_int, sentinel, elem_ty), | 17230 | .pointee_type = try Type.array(sema.arena, new_len_int, sentinel, elem_ty), |
| 17183 | .sentinel = null, | 17231 | .sentinel = null, |
| 17184 | .@"align" = new_ptr_ty_info.@"align", | 17232 | .@"align" = new_ptr_ty_info.@"align", |
| ... | @@ -17206,7 +17254,7 @@ fn analyzeSlice( | ... | @@ -17206,7 +17254,7 @@ fn analyzeSlice( |
| 17206 | return sema.fail(block, ptr_src, "non-zero length slice of undefined pointer", .{}); | 17254 | return sema.fail(block, ptr_src, "non-zero length slice of undefined pointer", .{}); |
| 17207 | } | 17255 | } |
| 17208 | | 17256 | |
| 17209 | const return_ty = try Type.ptr(sema.arena, .{ | 17257 | const return_ty = try Type.ptr(sema.arena, target, .{ |
| 17210 | .pointee_type = elem_ty, | 17258 | .pointee_type = elem_ty, |
| 17211 | .sentinel = sentinel, | 17259 | .sentinel = sentinel, |
| 17212 | .@"align" = new_ptr_ty_info.@"align", | 17260 | .@"align" = new_ptr_ty_info.@"align", |
| ... | @@ -17904,14 +17952,14 @@ fn resolvePeerTypes( | ... | @@ -17904,14 +17952,14 @@ fn resolvePeerTypes( |
| 17904 | else => unreachable, | 17952 | else => unreachable, |
| 17905 | }; | 17953 | }; |
| 17906 | | 17954 | |
| 17907 | return Type.ptr(sema.arena, info.data); | 17955 | return Type.ptr(sema.arena, target, info.data); |
| 17908 | } | 17956 | } |
| 17909 | | 17957 | |
| 17910 | if (make_the_slice_const) { | 17958 | if (make_the_slice_const) { |
| 17911 | // turn []T => []const T | 17959 | // turn []T => []const T |
| 17912 | var info = chosen_ty.ptrInfo(); | 17960 | var info = chosen_ty.ptrInfo(); |
| 17913 | info.data.mutable = false; | 17961 | info.data.mutable = false; |
| 17914 | return Type.ptr(sema.arena, info.data); | 17962 | return Type.ptr(sema.arena, target, info.data); |
| 17915 | } | 17963 | } |
| 17916 | | 17964 | |
| 17917 | return chosen_ty; | 17965 | return chosen_ty; |
| ... | @@ -19121,7 +19169,8 @@ fn analyzeComptimeAlloc( | ... | @@ -19121,7 +19169,8 @@ fn analyzeComptimeAlloc( |
| 19121 | // Needed to make an anon decl with type `var_type` (the `finish()` call below). | 19169 | // Needed to make an anon decl with type `var_type` (the `finish()` call below). |
| 19122 | _ = try sema.typeHasOnePossibleValue(block, src, var_type); | 19170 | _ = try sema.typeHasOnePossibleValue(block, src, var_type); |
| 19123 | | 19171 | |
| 19124 | const ptr_type = try Type.ptr(sema.arena, .{ | 19172 | const target = sema.mod.getTarget(); |
| | 19173 | const ptr_type = try Type.ptr(sema.arena, target, .{ |
| 19125 | .pointee_type = var_type, | 19174 | .pointee_type = var_type, |
| 19126 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .global_constant), | 19175 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .global_constant), |
| 19127 | .@"align" = alignment, | 19176 | .@"align" = alignment, |