add compile error for @atomicRmw on enum not being an .Xchg
This commit is contained in:
parent
c806de8ae7
commit
b83ce08a3b
@ -25824,6 +25824,12 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru
|
||||
}
|
||||
}
|
||||
|
||||
if (operand_type->id == ZigTypeIdEnum && op != AtomicRmwOp_xchg) {
|
||||
ir_add_error(ira, instruction->op,
|
||||
buf_sprintf("@atomicRmw on enum only works with .Xchg"));
|
||||
return ira->codegen->invalid_instruction;
|
||||
}
|
||||
|
||||
IrInstruction *operand = instruction->operand->child;
|
||||
if (type_is_invalid(operand->value.type))
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
@ -2,6 +2,22 @@ const tests = @import("tests.zig");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
cases.add(
|
||||
"atomicrmw with enum op not .Xchg",
|
||||
\\export fn entry() void {
|
||||
\\ const E = enum(u8) {
|
||||
\\ a,
|
||||
\\ b,
|
||||
\\ c,
|
||||
\\ d,
|
||||
\\ };
|
||||
\\ var x: E = .a;
|
||||
\\ _ = @atomicRmw(E, &x, .Add, .b, .SeqCst);
|
||||
\\}
|
||||
,
|
||||
"tmp.zig:9:27: error: @atomicRmw on enum only works with .Xchg",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
"atomic orderings of atomicStore Acquire or AcqRel",
|
||||
\\export fn entry() void {
|
||||
|
Loading…
x
Reference in New Issue
Block a user