mem: fix UB in readInt/writeInt and delete variants#17802
mem: fix UB in readInt/writeInt and delete variants#17802andrewrk merged 5 commits intoziglang:masterfrom
readInt/writeInt and delete variants#17802Conversation
09ceb0b to
763c7cb
Compare
763c7cb to
ecb7344
Compare
|
These warnings are new when bootstrapping: |
squeek502
left a comment
There was a problem hiding this comment.
Changes to resinator look correct.
huh. I don't understand how that passed the CI before, or why it's passing on x86_64-windows-debug. |
Have a fix, but waiting for a CI run to complete.
It's obvious what happened (clash between f-max and fma-x), but like you said, who knows why it happened on this run in particular. I can only assume either a bad roll gave us a different image (different compiler version?) somehow, or an msvc bugs means the error is not consistent. |
|
Well, not related to the changes in this PR at least: https://github.com/ziglang/zig/actions/runs/6710563026/job/18236031654 |
Use inline to vastly simplify the exposed API. This allows a comptime-known endian parameter to be propogated, making extra functions for a specific endianness completely unnecessary.
After deleting all potentially incorrect usages, there were no more remaining.
Let's take this breaking change opportunity to fix the style of this enum.
ecb7344 to
13b1e10
Compare
In Zig, loads and stores affect
@sizeOf(T)bytes of memory. The old implementations of these functions were pointer casting a buffer of@divExact(@bitSizeOf(T), 8)bytes which is not guaranteed to be large enough to perform a load or store ofTdirectly. This only ever worked because llvm has weird store size rules, and in fact, after this change, some non-llvm backends mysteriously started passing these tests.By making use of
inline, the complicated nest of variant functions could all be reduced to four functions without compromising functionality. After removing some incorrect uses of two of these, there were no references to them remaining, so I deleted them too.Migration guide
These apply to both the functions in
std.memand the methods onstd.io.GenericReader,std.io.AnyReader, andstd.io.Writer.readInt(...)→readInt(...)readIntLittle(...)→readInt(..., .little)readIntBig(...)→std.mem.readInt(..., .big)readIntNative(...)→std.mem.readInt(..., @import("builtin").cpu.arch.endian())or just@as(T, @bitCast(buffer.*))for thestd.memversionreadIntForeign(...)→@byteSwap(std.mem.readInt(..., @import("builtin").cpu.arch.endian()))or just@byteSwap(@as(T, @bitCast(buffer.*)))for thestd.memversionwriteInt(...)→std.mem.writeInt(...)writeIntLittle(...)→std.mem.writeInt(..., .little)writeIntBig(...)→std.mem.writeInt(..., .big)writeIntNative(...)→std.mem.writeInt(..., @import("builtin").cpu.arch.endian())or justbuffer.* = @bitCast(value)for thestd.memversionwriteIntForeign(...)→std.mem.writeInt(..., @byteSwap(value), @import("builtin").cpu.arch.endian())or justbuffer.* = @bitCast(@byteSwap(value))for thestd.memversion@Luukdegram unfortunately, this new pattern regressed the self-hosted wasm backend, so just letting you know that there are three new
.stage2_wasmchecks inlib/test_runner.zig,test/behavior/bugs/1851.zig, andtest/behavior/struct.zig.