| ... | ... | @@ -1415,10 +1415,6 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 1415 | 1415 | const ptr = sema.resolveInst(bin_inst.rhs); |
| 1416 | 1416 | |
| 1417 | 1417 | const addr_space = target_util.defaultAddressSpace(sema.mod.getTarget(), .local); |
| 1418 | | const ptr_ty = try Type.ptr(sema.arena, .{ |
| 1419 | | .pointee_type = pointee_ty, |
| 1420 | | .@"addrspace" = addr_space, |
| 1421 | | }); |
| 1422 | 1418 | |
| 1423 | 1419 | if (Air.refToIndex(ptr)) |ptr_inst| { |
| 1424 | 1420 | if (sema.air_instructions.items(.tag)[ptr_inst] == .constant) { |
| ... | ... | @@ -1438,6 +1434,11 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 1438 | 1434 | try inferred_alloc.stored_inst_list.append(sema.arena, operand); |
| 1439 | 1435 | |
| 1440 | 1436 | try sema.requireRuntimeBlock(block, src); |
| 1437 | const ptr_ty = try Type.ptr(sema.arena, .{ |
| 1438 | .pointee_type = pointee_ty, |
| 1439 | .@"align" = inferred_alloc.alignment, |
| 1440 | .@"addrspace" = addr_space, |
| 1441 | }); |
| 1441 | 1442 | const bitcasted_ptr = try block.addBitCast(ptr_ty, ptr); |
| 1442 | 1443 | return bitcasted_ptr; |
| 1443 | 1444 | }, |
| ... | ... | @@ -1447,19 +1448,30 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 1447 | 1448 | // The alloc will turn into a Decl. |
| 1448 | 1449 | var anon_decl = try block.startAnonDecl(); |
| 1449 | 1450 | defer anon_decl.deinit(); |
| 1450 | | iac.data = try anon_decl.finish( |
| 1451 | iac.data.decl = try anon_decl.finish( |
| 1451 | 1452 | try pointee_ty.copy(anon_decl.arena()), |
| 1452 | 1453 | Value.undef, |
| 1453 | 1454 | ); |
| 1455 | const ptr_ty = try Type.ptr(sema.arena, .{ |
| 1456 | .pointee_type = pointee_ty, |
| 1457 | .@"align" = iac.data.alignment, |
| 1458 | .@"addrspace" = addr_space, |
| 1459 | }); |
| 1454 | 1460 | return sema.addConstant( |
| 1455 | 1461 | ptr_ty, |
| 1456 | 1462 | try Value.Tag.decl_ref_mut.create(sema.arena, .{ |
| 1457 | | .decl = iac.data, |
| 1463 | .decl = iac.data.decl, |
| 1458 | 1464 | .runtime_index = block.runtime_index, |
| 1459 | 1465 | }), |
| 1460 | 1466 | ); |
| 1461 | 1467 | }, |
| 1462 | | .decl_ref_mut => return sema.addConstant(ptr_ty, ptr_val), |
| 1468 | .decl_ref_mut => { |
| 1469 | const ptr_ty = try Type.ptr(sema.arena, .{ |
| 1470 | .pointee_type = pointee_ty, |
| 1471 | .@"addrspace" = addr_space, |
| 1472 | }); |
| 1473 | return sema.addConstant(ptr_ty, ptr_val); |
| 1474 | }, |
| 1463 | 1475 | else => {}, |
| 1464 | 1476 | } |
| 1465 | 1477 | } |
| ... | ... | @@ -1491,6 +1503,11 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 1491 | 1503 | sema.air_instructions.len -= 1; |
| 1492 | 1504 | } |
| 1493 | 1505 | |
| 1506 | const ptr_ty = try Type.ptr(sema.arena, .{ |
| 1507 | .pointee_type = pointee_ty, |
| 1508 | .@"addrspace" = addr_space, |
| 1509 | }); |
| 1510 | |
| 1494 | 1511 | var new_ptr = ptr; |
| 1495 | 1512 | |
| 1496 | 1513 | while (true) { |
| ... | ... | @@ -2183,7 +2200,10 @@ fn zirAllocExtended( |
| 2183 | 2200 | } else { |
| 2184 | 2201 | return sema.addConstant( |
| 2185 | 2202 | inferred_alloc_ty, |
| 2186 | | try Value.Tag.inferred_alloc_comptime.create(sema.arena, undefined), |
| 2203 | try Value.Tag.inferred_alloc_comptime.create(sema.arena, .{ |
| 2204 | .decl = undefined, |
| 2205 | .alignment = alignment, |
| 2206 | }), |
| 2187 | 2207 | ); |
| 2188 | 2208 | } |
| 2189 | 2209 | } |
| ... | ... | @@ -2208,7 +2228,7 @@ fn zirAllocExtended( |
| 2208 | 2228 | // to the block even though it is currently a `.constant`. |
| 2209 | 2229 | const result = try sema.addConstant( |
| 2210 | 2230 | inferred_alloc_ty, |
| 2211 | | try Value.Tag.inferred_alloc.create(sema.arena, .{}), |
| 2231 | try Value.Tag.inferred_alloc.create(sema.arena, .{ .alignment = alignment }), |
| 2212 | 2232 | ); |
| 2213 | 2233 | try sema.requireFunctionBlock(block, src); |
| 2214 | 2234 | try block.instructions.append(sema.gpa, Air.refToIndex(result).?); |
| ... | ... | @@ -2302,7 +2322,7 @@ fn zirAllocInferred( |
| 2302 | 2322 | // to the block even though it is currently a `.constant`. |
| 2303 | 2323 | const result = try sema.addConstant( |
| 2304 | 2324 | inferred_alloc_ty, |
| 2305 | | try Value.Tag.inferred_alloc.create(sema.arena, .{}), |
| 2325 | try Value.Tag.inferred_alloc.create(sema.arena, .{ .alignment = 0 }), |
| 2306 | 2326 | ); |
| 2307 | 2327 | try sema.requireFunctionBlock(block, src); |
| 2308 | 2328 | try block.instructions.append(sema.gpa, Air.refToIndex(result).?); |
| ... | ... | @@ -2331,12 +2351,13 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 2331 | 2351 | switch (ptr_val.tag()) { |
| 2332 | 2352 | .inferred_alloc_comptime => { |
| 2333 | 2353 | const iac = ptr_val.castTag(.inferred_alloc_comptime).?; |
| 2334 | | const decl = iac.data; |
| 2354 | const decl = iac.data.decl; |
| 2335 | 2355 | try sema.mod.declareDeclDependency(sema.owner_decl, decl); |
| 2336 | 2356 | |
| 2337 | 2357 | const final_elem_ty = try decl.ty.copy(sema.arena); |
| 2338 | 2358 | const final_ptr_ty = try Type.ptr(sema.arena, .{ |
| 2339 | 2359 | .pointee_type = final_elem_ty, |
| 2360 | .@"align" = iac.data.alignment, |
| 2340 | 2361 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 2341 | 2362 | }); |
| 2342 | 2363 | const final_ptr_ty_inst = try sema.addType(final_ptr_ty); |
| ... | ... | @@ -2365,6 +2386,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 2365 | 2386 | // Change it to a normal alloc. |
| 2366 | 2387 | const final_ptr_ty = try Type.ptr(sema.arena, .{ |
| 2367 | 2388 | .pointee_type = final_elem_ty, |
| 2389 | .@"align" = inferred_alloc.data.alignment, |
| 2368 | 2390 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 2369 | 2391 | }); |
| 2370 | 2392 | sema.air_instructions.set(ptr_inst, .{ |
| ... | ... | @@ -2681,10 +2703,11 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 2681 | 2703 | } |
| 2682 | 2704 | var anon_decl = try block.startAnonDecl(); |
| 2683 | 2705 | defer anon_decl.deinit(); |
| 2684 | | iac.data = try anon_decl.finish( |
| 2706 | iac.data.decl = try anon_decl.finish( |
| 2685 | 2707 | try operand_ty.copy(anon_decl.arena()), |
| 2686 | 2708 | try operand_val.copy(anon_decl.arena()), |
| 2687 | 2709 | ); |
| 2710 | // TODO set the alignment on the decl |
| 2688 | 2711 | return; |
| 2689 | 2712 | } else { |
| 2690 | 2713 | return sema.failWithNeededComptime(block, src); |
| ... | ... | @@ -2698,6 +2721,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 2698 | 2721 | // Create a runtime bitcast instruction with exactly the type the pointer wants. |
| 2699 | 2722 | const ptr_ty = try Type.ptr(sema.arena, .{ |
| 2700 | 2723 | .pointee_type = operand_ty, |
| 2724 | .@"align" = inferred_alloc.data.alignment, |
| 2701 | 2725 | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .local), |
| 2702 | 2726 | }); |
| 2703 | 2727 | const bitcasted_ptr = try block.addBitCast(ptr_ty, ptr); |