| author | |
| committer | |
| log | 61f447523350a467fde242b846ed27b084ed1f50 |
| tree | a3171036a6fb2806bc5ed9d20bdc0d20484557c5 |
| parent | cbc3c0dc594341faddb8841fb466254f2f6f3b35 |
| signature |
closes #250672 files changed, 19 insertions(+), 0 deletions(-)
src/codegen/llvm.zig+1| ... | ... | @@ -9761,6 +9761,7 @@ pub const FuncGen = struct { |
| 9761 | 9761 | const ptr = try fg.resolveInst(ty_op.operand); |
| 9762 | 9762 | |
| 9763 | 9763 | elide: { |
| 9764 | if (ptr_info.flags.alignment != .none) break :elide; | |
| 9764 | 9765 | if (!isByRef(Type.fromInterned(ptr_info.child), zcu)) break :elide; |
| 9765 | 9766 | if (!canElideLoad(fg, body_tail)) break :elide; |
| 9766 | 9767 | return ptr; |
test/behavior/struct.zig+18| ... | ... | @@ -2136,3 +2136,21 @@ test "field access through mem ptr arg" { |
| 2136 | 2136 | &.{ .field = 0x0ced271f }, |
| 2137 | 2137 | ) == 0x0ced271f); |
| 2138 | 2138 | } |
| 2139 | ||
| 2140 | test "align 1 struct parameter dereferenced and returned" { | |
| 2141 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | |
| 2142 | ||
| 2143 | const S = extern struct { | |
| 2144 | a: u32, | |
| 2145 | ||
| 2146 | fn gimme(p: *align(1) @This()) @This() { | |
| 2147 | return p.*; | |
| 2148 | } | |
| 2149 | }; | |
| 2150 | var buffer: [5]u8 align(4) = .{ 1, 2, 3, 4, 5 }; | |
| 2151 | const s = S.gimme(@ptrCast(buffer[1..])); | |
| 2152 | switch (native_endian) { | |
| 2153 | .big => try expect(s.a == 0x02030405), | |
| 2154 | .little => try expect(s.a == 0x05040302), | |
| 2155 | } | |
| 2156 | } |