Commit 0ff396c34f

Vexu <15308111+Vexu@users.noreply.github.com>
2019-08-17 21:51:25
add compile error for incorrect atomic ordering in fence #3082
1 parent 4d8a6f6
Changed files (2)
src/ir.cpp
@@ -20860,6 +20860,12 @@ static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstruction
     if (!ir_resolve_atomic_order(ira, order_value, &order))
         return ira->codegen->invalid_instruction;
 
+    if (order < AtomicOrderAcquire) {
+        ir_add_error(ira, order_value,
+                buf_sprintf("atomic ordering must be Acquire or stricter"));
+        return ira->codegen->invalid_instruction;
+    }
+
     IrInstruction *result = ir_build_fence(&ira->new_irb,
         instruction->base.scope, instruction->base.source_node, order_value, order);
     result->value.type = ira->codegen->builtin_types.entry_void;
test/compile_errors.zig
@@ -14,6 +14,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
         "tmp.zig:4:21: error: expected type '[]align(16) u8', found '*[64]u8'",
     );
 
+    cases.add(
+        "atomic orderings of fence Acquire or stricter",
+        \\export fn entry() void {
+        \\    @fence(.Monotonic);
+        \\}
+    ,
+        "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter",
+    );
+
     cases.add(
         "bad alignment in implicit cast from array pointer to slice",
         \\export fn a() void {