atomics A.0c: harden guards (scalar-kind, ordering validity, align bail)
Adversarial review of A.0 found two silent-wrong defects reachable via the public atomic_load/atomic_store intrinsics (raw LLVM verifier errors, not clean sx diagnostics) + a latent alignment fallback. All fixed: - scalar-kind allowlist (call.zig): the size-only T guard admitted same-sized aggregates ([8]u8, 8-byte structs) -> invalid 'load atomic [8 x i8]'. Now an allowlist switch (integer/float/bool/pointer/enum/vector) rejects loudly. - per-op ordering validity (call.zig): load cannot release/acq_rel, store cannot acquire/acq_rel -> loud diagnostic instead of invalid LLVM. - val_ty align fallback (ops.zig): the 'else .i64' (align 8) default would over-align a sub-8 store -> now bails loudly on a missing val_ty. Locked by examples 1130 (non-scalar) + 1131 (bad ordering). Suite green (713/0).
This commit is contained in:
@@ -410,10 +410,19 @@ pub const Ops = struct {
|
||||
};
|
||||
if (target_ty) |tt| val = self.e.coerceArg(val, tt);
|
||||
}
|
||||
// Alignment MUST come from the actual stored type — never a fixed
|
||||
// fallback (an `.i64`/align-8 default silently over-aligns a sub-8
|
||||
// store, which the verifier rejects). Lowering always sets val_ty; a
|
||||
// missing one is a compiler bug, so bail loudly rather than guess.
|
||||
if (a.val_ty == .void) {
|
||||
std.debug.print("error: atomic store missing val_ty (cannot derive alignment)\n", .{});
|
||||
self.e.comptime_failed = true;
|
||||
self.e.advanceRefCounter();
|
||||
return;
|
||||
}
|
||||
const st = c.LLVMBuildStore(self.e.builder, val, ptr);
|
||||
c.LLVMSetOrdering(st, llvmOrdering(a.ordering));
|
||||
const align_ty = if (a.val_ty != .void) a.val_ty else .i64;
|
||||
c.LLVMSetAlignment(st, @intCast(self.e.ir_mod.types.typeSizeBytes(align_ty)));
|
||||
c.LLVMSetAlignment(st, @intCast(self.e.ir_mod.types.typeSizeBytes(a.val_ty)));
|
||||
}
|
||||
self.e.advanceRefCounter();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user