aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorCody Tapscott <topolarity@tapscott.me>2022-02-13 11:54:37 -0700
committerCody Tapscott <topolarity@tapscott.me>2022-02-13 13:26:59 -0700
commit7b72fc6bbc5554643bc27933310899e32783b81b (patch)
treec367a314c4e46e4bcefce3d5f9ab21addc3620cc /src/value.zig
parenteeb043f5833db03ac3250f9943ba8be0b518432f (diff)
downloadzig-7b72fc6bbc5554643bc27933310899e32783b81b.tar.gz
zig-7b72fc6bbc5554643bc27933310899e32783b81b.zip
Add `abi_size` parameter to read/writeTwosComplement
Big-int functions were updated to respect the provided abi_size, rather than inferring a potentially incorrect abi_size implicitly. In combination with the convention that any required padding bits are added on the MSB end, this means that exotic integers can potentially have a well-defined memory layout.
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/value.zig b/src/value.zig
index 2018eb3df3..a3dd6501e4 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -1046,7 +1046,8 @@ pub const Value = extern union {
var bigint_buffer: BigIntSpace = undefined;
const bigint = val.toBigInt(&bigint_buffer);
const bits = ty.intInfo(target).bits;
- bigint.writeTwosComplement(buffer, bits, target.cpu.arch.endian());
+ const abi_size = ty.abiSize(target);
+ bigint.writeTwosComplement(buffer, bits, abi_size, target.cpu.arch.endian());
},
.Enum => {
var enum_buffer: Payload.U64 = undefined;
@@ -1054,7 +1055,8 @@ pub const Value = extern union {
var bigint_buffer: BigIntSpace = undefined;
const bigint = int_val.toBigInt(&bigint_buffer);
const bits = ty.intInfo(target).bits;
- bigint.writeTwosComplement(buffer, bits, target.cpu.arch.endian());
+ const abi_size = ty.abiSize(target);
+ bigint.writeTwosComplement(buffer, bits, abi_size, target.cpu.arch.endian());
},
.Float => switch (ty.floatBits(target)) {
16 => return floatWriteToMemory(f16, val.toFloat(f16), target, buffer),
@@ -1096,8 +1098,9 @@ pub const Value = extern union {
const Limb = std.math.big.Limb;
const limb_count = (buffer.len + @sizeOf(Limb) - 1) / @sizeOf(Limb);
const limbs_buffer = try arena.alloc(Limb, limb_count);
+ const abi_size = ty.abiSize(target);
var bigint = BigIntMutable.init(limbs_buffer, 0);
- bigint.readTwosComplement(buffer, int_info.bits, endian, int_info.signedness);
+ bigint.readTwosComplement(buffer, int_info.bits, abi_size, endian, int_info.signedness);
return fromBigInt(arena, bigint.toConst());
},
.Float => switch (ty.floatBits(target)) {