llvm: partial fix of store undefined to packed result location

prefer marking too few undefined bits, rather than too many that may overwrite nearby values.
partially resolves https://github.com/ziglang/zig/issues/15337
This commit is contained in:
Xavier Bouchoux
2023-07-28 19:41:21 +02:00
parent 417b92f085
commit 46abf20454
2 changed files with 9 additions and 1 deletions

View File

@@ -8753,6 +8753,15 @@ pub const FuncGen = struct {
const val_is_undef = if (try self.air.value(bin_op.rhs, mod)) |val| val.isUndefDeep(mod) else false;
if (val_is_undef) {
const ptr_info = ptr_ty.ptrInfo(mod);
const needs_bitmask = (ptr_info.packed_offset.host_size != 0);
if (needs_bitmask) {
// TODO: only some bits are to be undef, we cannot write with a simple memset.
// meanwhile, ignore the write rather than stomping over valid bits.
// https://github.com/ziglang/zig/issues/15337
return .none;
}
// Even if safety is disabled, we still emit a memset to undefined since it conveys
// extra information to LLVM. However, safety makes the difference between using
// 0xaa or actual undefined for the fill byte.

View File

@@ -632,7 +632,6 @@ test "pointer to container level packed struct field" {
test "store undefined to packed result location" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_llvm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;