| author | |
| committer | |
| log | 640c11171bf8d13776629941f3305cf11c62c1f3 |
| tree | fb9cd08cb1bd6c6c156e977a4cbed0bdf8cec84a |
| parent | 98e9dde3892a2c24cdb69fef26b7ac84b60d8a78 |
closes #250672 files changed, 19 insertions(+), 0 deletions(-)
src/codegen/llvm.zig+1| ... | @@ -9773,6 +9773,7 @@ pub const FuncGen = struct { | ... | @@ -9773,6 +9773,7 @@ pub const FuncGen = struct { |
| 9773 | const ptr = try fg.resolveInst(ty_op.operand); | 9773 | const ptr = try fg.resolveInst(ty_op.operand); |
| 9774 | 9774 | ||
| 9775 | elide: { | 9775 | elide: { |
| 9776 | if (ptr_info.flags.alignment != .none) break :elide; | ||
| 9776 | if (!isByRef(Type.fromInterned(ptr_info.child), zcu)) break :elide; | 9777 | if (!isByRef(Type.fromInterned(ptr_info.child), zcu)) break :elide; |
| 9777 | if (!canElideLoad(fg, body_tail)) break :elide; | 9778 | if (!canElideLoad(fg, body_tail)) break :elide; |
| 9778 | return ptr; | 9779 | return ptr; |
test/behavior/struct.zig+18| ... | @@ -2136,3 +2136,21 @@ test "field access through mem ptr arg" { | ... | @@ -2136,3 +2136,21 @@ test "field access through mem ptr arg" { |
| 2136 | &.{ .field = 0x0ced271f }, | 2136 | &.{ .field = 0x0ced271f }, |
| 2137 | ) == 0x0ced271f); | 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 | } |