diff options
| author | Alex Rønne Petersen <alex@alexrp.com> | 2025-02-15 02:44:58 +0100 |
|---|---|---|
| committer | Alex Rønne Petersen <alex@alexrp.com> | 2025-02-22 04:12:46 +0100 |
| commit | fc7a0c4878dac2d721ec18cafe1b6bcff7faa771 (patch) | |
| tree | 5b9e4ef2d18e3daaf4bee34ae1bfe5af97916e8a /test/behavior/align.zig | |
| parent | d31bda13cb1ece7dd2ba22339172a8704a84823c (diff) | |
| download | zig-fc7a0c4878dac2d721ec18cafe1b6bcff7faa771.tar.gz zig-fc7a0c4878dac2d721ec18cafe1b6bcff7faa771.zip | |
Sema: Fix fnptr alignment safety checks to account for potential ISA tag.
As seen on e.g. Arm/Thumb and MIPS (MIPS16/microMIPS).
Fixes #22888.
Diffstat (limited to 'test/behavior/align.zig')
| -rw-r--r-- | test/behavior/align.zig | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/test/behavior/align.zig b/test/behavior/align.zig index e6917eb649..88094d16e5 100644 --- a/test/behavior/align.zig +++ b/test/behavior/align.zig @@ -613,3 +613,14 @@ test "zero-bit fields in extern struct pad fields appropriately" { try expect(@intFromPtr(&s.y) == @intFromPtr(&s.a)); try expect(@as(*S, @fieldParentPtr("a", &s.a)) == &s); } + +test "function pointer @intFromPtr/@ptrFromInt roundtrip" { + // This only succeeds on Thumb if we handle the Thumb bit correctly; if not, the `@ptrFromInt` + // will incorrectly trip an alignment safety check. + + const nothing_ptr: *const fn () callconv(.c) void = ¬hing; + const nothing_int: usize = @intFromPtr(nothing_ptr); + const nothing_ptr2: *const fn () callconv(.c) void = @ptrFromInt(nothing_int); + + try std.testing.expectEqual(nothing_ptr, nothing_ptr2); +} |
