committed by
Alex Rønne Petersen
parent
cbc3c0dc59
commit
61f4475233
@@ -9761,6 +9761,7 @@ pub const FuncGen = struct {
|
||||
const ptr = try fg.resolveInst(ty_op.operand);
|
||||
|
||||
elide: {
|
||||
if (ptr_info.flags.alignment != .none) break :elide;
|
||||
if (!isByRef(Type.fromInterned(ptr_info.child), zcu)) break :elide;
|
||||
if (!canElideLoad(fg, body_tail)) break :elide;
|
||||
return ptr;
|
||||
|
||||
@@ -2136,3 +2136,21 @@ test "field access through mem ptr arg" {
|
||||
&.{ .field = 0x0ced271f },
|
||||
) == 0x0ced271f);
|
||||
}
|
||||
|
||||
test "align 1 struct parameter dereferenced and returned" {
|
||||
if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
|
||||
|
||||
const S = extern struct {
|
||||
a: u32,
|
||||
|
||||
fn gimme(p: *align(1) @This()) @This() {
|
||||
return p.*;
|
||||
}
|
||||
};
|
||||
var buffer: [5]u8 align(4) = .{ 1, 2, 3, 4, 5 };
|
||||
const s = S.gimme(@ptrCast(buffer[1..]));
|
||||
switch (native_endian) {
|
||||
.big => try expect(s.a == 0x02030405),
|
||||
.little => try expect(s.a == 0x05040302),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user