Skip to content

Commit

Permalink
llvm: store undef if safety is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Apr 11, 2023
1 parent 23d7921 commit 0fb0dff
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/codegen/llvm.zig
Expand Up @@ -8226,27 +8226,23 @@ pub const FuncGen = struct {
// possibly do the safety 0xaa bytes for undefined.
const val_is_undef = if (self.air.value(bin_op.rhs)) |val| val.isUndefDeep() else false;
if (val_is_undef) {
{
// TODO let's handle this in AIR rather than by having each backend
// check the optimization mode of the compilation because the plan is
// to support setting the optimization mode at finer grained scopes
// which happens in Sema. Codegen should not be aware of this logic.
// I think this comment is basically the same as the other TODO comment just
// above but I'm leaving them both here to make it look super messy and
// thereby bait contributors (or let's be honest, probably myself) into
// fixing this instead of letting it rot.
const safety = switch (self.dg.module.comp.bin_file.options.optimize_mode) {
.ReleaseSmall, .ReleaseFast => false,
.Debug, .ReleaseSafe => true,
};
if (!safety) {
return null;
}
}
// TODO let's handle this in AIR rather than by having each backend
// check the optimization mode of the compilation because the plan is
// to support setting the optimization mode at finer grained scopes
// which happens in Sema. Codegen should not be aware of this logic.
// I think this comment is basically the same as the other TODO comment just
// above but I'm leaving them both here to make it look super messy and
// thereby bait contributors (or let's be honest, probably myself) into
// fixing this instead of letting it rot.
const safety = switch (self.dg.module.comp.bin_file.options.optimize_mode) {
.ReleaseSmall, .ReleaseFast => false,
.Debug, .ReleaseSafe => true,
};

const target = self.dg.module.getTarget();
const operand_size = operand_ty.abiSize(target);
const u8_llvm_ty = self.context.intType(8);
const fill_char = u8_llvm_ty.constInt(0xaa, .False);
const fill_char = if (safety) u8_llvm_ty.constInt(0xaa, .False) else u8_llvm_ty.getUndef();
const dest_ptr_align = ptr_ty.ptrAlignment(target);
const usize_llvm_ty = try self.dg.lowerType(Type.usize);
const len = usize_llvm_ty.constInt(operand_size, .False);
Expand Down Expand Up @@ -8522,7 +8518,15 @@ pub const FuncGen = struct {
const val_is_undef = if (self.air.value(extra.lhs)) |val| val.isUndefDeep() else false;
const len = try self.resolveInst(extra.rhs);
const u8_llvm_ty = self.context.intType(8);
const fill_char = if (val_is_undef) u8_llvm_ty.constInt(0xaa, .False) else value;
const fill_char = blk: {
if (!val_is_undef) break :blk value;
const safety = switch (self.dg.module.comp.bin_file.options.optimize_mode) {
.ReleaseSmall, .ReleaseFast => false,
.Debug, .ReleaseSafe => true,
};
if (safety) break :blk u8_llvm_ty.constInt(0xaa, .False);
break :blk u8_llvm_ty.getUndef();
};
const target = self.dg.module.getTarget();
const dest_ptr_align = ptr_ty.ptrAlignment(target);
_ = self.builder.buildMemSet(dest_ptr, fill_char, len, dest_ptr_align, ptr_ty.isVolatilePtr());
Expand Down

0 comments on commit 0fb0dff

Please sign in to comment.