add compile error for @atomicRmw on enum not being an .Xchg

This commit is contained in:
Vexu 2019-11-13 12:05:15 +02:00 committed by Andrew Kelley
parent c806de8ae7
commit b83ce08a3b
2 changed files with 22 additions and 0 deletions

View File

@ -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; IrInstruction *operand = instruction->operand->child;
if (type_is_invalid(operand->value.type)) if (type_is_invalid(operand->value.type))
return ira->codegen->invalid_instruction; return ira->codegen->invalid_instruction;

View File

@ -2,6 +2,22 @@ const tests = @import("tests.zig");
const builtin = @import("builtin"); const builtin = @import("builtin");
pub fn addCases(cases: *tests.CompileErrorContext) void { 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( cases.add(
"atomic orderings of atomicStore Acquire or AcqRel", "atomic orderings of atomicStore Acquire or AcqRel",
\\export fn entry() void { \\export fn entry() void {