authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-11-04 09:54:13+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-11-04 09:54:13+01:00
log2f740fa19ff88981d028289162b3eb469b7f5315
treee8a4f78bbb908a887fc44f7a9a2c4808a0323274
parent711520d935fd7f6367f1d3a0c2c01c140647b4d0

Fix cmpxchg trying to execute at CT

Fixes #3582

2 files changed, 9 insertions(+), 1 deletions(-)

src/ir.cpp+2-1
......@@ -21798,7 +21798,8 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
2179821798 return ira->codegen->invalid_instruction;
2179921799 }
2180021800
21801 if (instr_is_comptime(casted_ptr) && instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) {
21801 if (instr_is_comptime(casted_ptr) && casted_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar &&
21802 instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) {
2180221803 zig_panic("TODO compile-time execution of cmpxchg");
2180321804 }
2180421805
test/stage1/behavior/atomics.zig+7
......@@ -100,3 +100,10 @@ test "cmpxchg with ignored result" {
100100
101101 expectEqual(i32(5678), x);
102102}
103
104var a_global_variable = u32(1234);
105
106test "cmpxchg on a global variable" {
107 _ = @cmpxchgWeak(u32, &a_global_variable, 1234, 42, .Acquire, .Monotonic);
108 expectEqual(u32(42), a_global_variable);
109}