Ensure volatile status for all atomic operations

Fixes #2410
This commit is contained in:
Feoramund
2025-06-20 19:43:41 -04:00
parent 62c5805c91
commit 5b1113acb4
+14 -12
View File
@@ -2774,16 +2774,19 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu
LLVMSetMetadata(instr, kind_id, LLVMMetadataAsValue(p->module->ctx, node)); LLVMSetMetadata(instr, kind_id, LLVMMetadataAsValue(p->module->ctx, node));
} }
break; break;
case BuiltinProc_volatile_store: LLVMSetVolatile(instr, true); break; case BuiltinProc_volatile_store:
case BuiltinProc_atomic_store: LLVMSetOrdering(instr, LLVMAtomicOrderingSequentiallyConsistent); break; LLVMSetVolatile(instr, true);
break;
case BuiltinProc_atomic_store:
LLVMSetOrdering(instr, LLVMAtomicOrderingSequentiallyConsistent);
LLVMSetVolatile(instr, true);
break;
case BuiltinProc_atomic_store_explicit: case BuiltinProc_atomic_store_explicit:
{ {
auto ordering = llvm_atomic_ordering_from_odin(ce->args[2]); auto ordering = llvm_atomic_ordering_from_odin(ce->args[2]);
LLVMSetOrdering(instr, ordering); LLVMSetOrdering(instr, ordering);
if (ordering == LLVMAtomicOrderingUnordered) {
LLVMSetVolatile(instr, true); LLVMSetVolatile(instr, true);
} }
}
break; break;
} }
@@ -2808,16 +2811,19 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu
} }
break; break;
break; break;
case BuiltinProc_volatile_load: LLVMSetVolatile(instr, true); break; case BuiltinProc_volatile_load:
case BuiltinProc_atomic_load: LLVMSetOrdering(instr, LLVMAtomicOrderingSequentiallyConsistent); break; LLVMSetVolatile(instr, true);
break;
case BuiltinProc_atomic_load:
LLVMSetOrdering(instr, LLVMAtomicOrderingSequentiallyConsistent);
LLVMSetVolatile(instr, true);
break;
case BuiltinProc_atomic_load_explicit: case BuiltinProc_atomic_load_explicit:
{ {
auto ordering = llvm_atomic_ordering_from_odin(ce->args[1]); auto ordering = llvm_atomic_ordering_from_odin(ce->args[1]);
LLVMSetOrdering(instr, ordering); LLVMSetOrdering(instr, ordering);
if (ordering == LLVMAtomicOrderingUnordered) {
LLVMSetVolatile(instr, true); LLVMSetVolatile(instr, true);
} }
}
break; break;
} }
LLVMSetAlignment(instr, cast(unsigned)type_align_of(type_deref(dst.type))); LLVMSetAlignment(instr, cast(unsigned)type_align_of(type_deref(dst.type)));
@@ -2901,9 +2907,7 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu
lbValue res = {}; lbValue res = {};
res.value = LLVMBuildAtomicRMW(p->builder, op, dst.value, val.value, ordering, false); res.value = LLVMBuildAtomicRMW(p->builder, op, dst.value, val.value, ordering, false);
res.type = tv.type; res.type = tv.type;
if (ordering == LLVMAtomicOrderingUnordered) {
LLVMSetVolatile(res.value, true); LLVMSetVolatile(res.value, true);
}
return res; return res;
} }
@@ -2939,9 +2943,7 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu
single_threaded single_threaded
); );
LLVMSetWeak(value, weak); LLVMSetWeak(value, weak);
if (success_ordering == LLVMAtomicOrderingUnordered || failure_ordering == LLVMAtomicOrderingUnordered) {
LLVMSetVolatile(value, true); LLVMSetVolatile(value, true);
}
if (is_type_tuple(tv.type)) { if (is_type_tuple(tv.type)) {
Type *fix_typed = alloc_type_tuple(); Type *fix_typed = alloc_type_tuple();