diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-08-29 16:52:31 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-08-29 16:52:31 -0400 |
| commit | 816689a3b1c98ec008438e7f868e1a123889b2a7 (patch) | |
| tree | 84dcf5e1cb51689543fea4c39b4c9f24dde681e9 /std | |
| parent | be94299666e57486be6bdb8fee2b79dbf3623c5d (diff) | |
| download | zig-816689a3b1c98ec008438e7f868e1a123889b2a7.tar.gz zig-816689a3b1c98ec008438e7f868e1a123889b2a7.zip | |
ptrCast gives compile error for increasing alignment
See #37
Diffstat (limited to 'std')
| -rw-r--r-- | std/os/darwin.zig | 2 | ||||
| -rw-r--r-- | std/special/builtin.zig | 6 | ||||
| -rw-r--r-- | std/special/compiler_rt/udivmod.zig | 10 |
3 files changed, 9 insertions, 9 deletions
diff --git a/std/os/darwin.zig b/std/os/darwin.zig index fcd356156e..8a034f966b 100644 --- a/std/os/darwin.zig +++ b/std/os/darwin.zig @@ -172,7 +172,7 @@ pub fn fork() -> usize { pub fn pipe(fds: &[2]i32) -> usize { comptime assert(i32.bit_count == c_int.bit_count); - errnoWrap(c.pipe(@ptrCast(&c_int, &(*fds)[0]))) + errnoWrap(c.pipe(@ptrCast(&c_int, fds))) } pub fn mkdir(path: &const u8, mode: u32) -> usize { diff --git a/std/special/builtin.zig b/std/special/builtin.zig index ede7b4abb8..95a41b07b5 100644 --- a/std/special/builtin.zig +++ b/std/special/builtin.zig @@ -49,8 +49,8 @@ fn generic_fmod(comptime T: type, x: T, y: T) -> T { const exp_bits = if (T == f32) 9 else 12; const bits_minus_1 = T.bit_count - 1; const mask = if (T == f32) 0xff else 0x7ff; - var ux = *@ptrCast(&const uint, &x); - var uy = *@ptrCast(&const uint, &y); + var ux = @bitCast(uint, x); + var uy = @bitCast(uint, y); var ex = i32((ux >> digits) & mask); var ey = i32((uy >> digits) & mask); const sx = if (T == f32) u32(ux & 0x80000000) else i32(ux >> bits_minus_1); @@ -113,7 +113,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) -> T { } else { ux |= uint(sx) << bits_minus_1; } - return *@ptrCast(&const T, &ux); + return @bitCast(T, ux); } fn isNan(comptime T: type, bits: T) -> bool { diff --git a/std/special/compiler_rt/udivmod.zig b/std/special/compiler_rt/udivmod.zig index ef15e77546..efe5e85a73 100644 --- a/std/special/compiler_rt/udivmod.zig +++ b/std/special/compiler_rt/udivmod.zig @@ -54,7 +54,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: if (maybe_rem) |rem| { r[high] = n[high] % d[high]; r[low] = 0; - *rem = *@ptrCast(&DoubleInt, &r[0]); // TODO issue #421 + *rem = *@ptrCast(&align @alignOf(SingleInt) DoubleInt, &r[0]); // TODO issue #421 } return n[high] / d[high]; } @@ -66,7 +66,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: if (maybe_rem) |rem| { r[low] = n[low]; r[high] = n[high] & (d[high] - 1); - *rem = *@ptrCast(&DoubleInt, &r[0]); // TODO issue #421 + *rem = *@ptrCast(&align @alignOf(SingleInt) DoubleInt, &r[0]); // TODO issue #421 } return n[high] >> Log2SingleInt(@ctz(d[high])); } @@ -106,7 +106,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: sr = @ctz(d[low]); q[high] = n[high] >> Log2SingleInt(sr); q[low] = (n[high] << Log2SingleInt(SingleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr)); - return *@ptrCast(&DoubleInt, &q[0]); // TODO issue #421 + return *@ptrCast(&align @alignOf(SingleInt) DoubleInt, &q[0]); // TODO issue #421 } // K X // --- @@ -180,13 +180,13 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: // r.all -= b; // carry = 1; // } - r_all = *@ptrCast(&DoubleInt, &r[0]); // TODO issue #421 + r_all = *@ptrCast(&align @alignOf(SingleInt) DoubleInt, &r[0]); // TODO issue #421 const s: SignedDoubleInt = SignedDoubleInt(b -% r_all -% 1) >> (DoubleInt.bit_count - 1); carry = u32(s & 1); r_all -= b & @bitCast(DoubleInt, s); r = *@ptrCast(&[2]SingleInt, &r_all); // TODO issue #421 } - const q_all = ((*@ptrCast(&DoubleInt, &q[0])) << 1) | carry; // TODO issue #421 + const q_all = ((*@ptrCast(&align @alignOf(SingleInt) DoubleInt, &q[0])) << 1) | carry; // TODO issue #421 if (maybe_rem) |rem| { *rem = r_all; } |
