diff --git a/src/ir.cpp b/src/ir.cpp index a53367a324c630e30861416e4a20c822304b52c8..ce0e204e6378b512170f80cce5201ec90c971a11 100644 --- a/src/ir.cpp +++ b/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"); } diff --git a/test/stage1/behavior/atomics.zig b/test/stage1/behavior/atomics.zig index 1a941cf21c133a37da81d1d723fe20dc1c314461..8c4a186032b00b154498b9f3109722ebcade319e 100644 --- a/test/stage1/behavior/atomics.zig +++ b/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); +}