Commit 2f740fa19f

LemonBoy <thatlemon@gmail.com>
2019-11-04 09:54:13
Fix cmpxchg trying to execute at CT
Fixes #3582
1 parent 711520d
Changed files (2)
src
test
stage1
behavior
src/ir.cpp
@@ -21798,7 +21798,8 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
         return ira->codegen->invalid_instruction;
     }
 
-    if (instr_is_comptime(casted_ptr) && instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) {
+    if (instr_is_comptime(casted_ptr) && casted_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar &&
+        instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) {
         zig_panic("TODO compile-time execution of cmpxchg");
     }
 
test/stage1/behavior/atomics.zig
@@ -100,3 +100,10 @@ test "cmpxchg with ignored result" {
 
     expectEqual(i32(5678), x);
 }
+
+var a_global_variable = u32(1234);
+
+test "cmpxchg on a global variable" {
+    _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic);
+    expectEqual(u32(42), a_global_variable);
+}