aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-11-21 19:39:32 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-11-21 19:43:08 -0700
commit6afcaf4a08b6fb1cce0cdb2393fc1d4cd041509c (patch)
treebf4a17c51d53b720077e8315c5d0a38f20eba219 /src/value.zig
parent96e5f661bd34d98bba89bcb70c9db059aaf38641 (diff)
downloadzig-6afcaf4a08b6fb1cce0cdb2393fc1d4cd041509c.tar.gz
zig-6afcaf4a08b6fb1cce0cdb2393fc1d4cd041509c.zip
stage2: fix the build for 32-bit architectures
* Introduce a mechanism into Sema for emitting a compile error when an integer is too big and we need it to fit into a usize. * Add `@intCast` where necessary * link/MachO: fix an unnecessary allocation when all that was happening was appending zeroes to an ArrayList. * Add `error.Overflow` as a possible error to some codepaths, allowing usage of `math.intCast`. closes #9710
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig26
1 files changed, 4 insertions, 22 deletions
diff --git a/src/value.zig b/src/value.zig
index 4eaa865149..d4ee5bcf0c 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -995,24 +995,6 @@ pub const Value = extern union {
};
}
- pub fn bitCast(
- val: Value,
- old_ty: Type,
- new_ty: Type,
- target: Target,
- gpa: *Allocator,
- arena: *Allocator,
- ) !Value {
- if (old_ty.eql(new_ty)) return val;
-
- // For types with well-defined memory layouts, we serialize them a byte buffer,
- // then deserialize to the new type.
- const buffer = try gpa.alloc(u8, old_ty.abiSize(target));
- defer gpa.free(buffer);
- val.writeToMemory(old_ty, target, buffer);
- return Value.readFromMemory(new_ty, target, buffer, arena);
- }
-
pub fn writeToMemory(val: Value, ty: Type, target: Target, buffer: []u8) void {
switch (ty.zigTypeTag()) {
.Int => {
@@ -1039,7 +1021,7 @@ pub const Value = extern union {
.Array, .Vector => {
const len = ty.arrayLen();
const elem_ty = ty.childType();
- const elem_size = elem_ty.abiSize(target);
+ const elem_size = @intCast(usize, elem_ty.abiSize(target));
var elem_i: usize = 0;
var elem_value_buf: ElemValueBuffer = undefined;
var buf_off: usize = 0;
@@ -2494,7 +2476,7 @@ pub const Value = extern union {
// resorting to BigInt first.
var lhs_space: Value.BigIntSpace = undefined;
const lhs_bigint = lhs.toBigInt(&lhs_space);
- const shift = rhs.toUnsignedInt();
+ const shift = @intCast(usize, rhs.toUnsignedInt());
const limbs = try allocator.alloc(
std.math.big.Limb,
lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,
@@ -2521,7 +2503,7 @@ pub const Value = extern union {
var lhs_space: Value.BigIntSpace = undefined;
const lhs_bigint = lhs.toBigInt(&lhs_space);
- const shift = rhs.toUnsignedInt();
+ const shift = @intCast(usize, rhs.toUnsignedInt());
const limbs = try arena.alloc(
std.math.big.Limb,
std.math.big.int.calcTwosCompLimbCount(info.bits),
@@ -2540,7 +2522,7 @@ pub const Value = extern union {
// resorting to BigInt first.
var lhs_space: Value.BigIntSpace = undefined;
const lhs_bigint = lhs.toBigInt(&lhs_space);
- const shift = rhs.toUnsignedInt();
+ const shift = @intCast(usize, rhs.toUnsignedInt());
const limbs = try allocator.alloc(
std.math.big.Limb,
lhs_bigint.limbs.len - (shift / (@sizeOf(std.math.big.Limb) * 8)),