Commit 41914321b4
Changed files (3)
src
test
stage1
behavior
src/ir.cpp
@@ -25807,7 +25807,7 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst
if (type_is_invalid(ptr_inst->value.type))
return ira->codegen->invalid_instruction;
- ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);
+ ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
if (type_is_invalid(casted_ptr->value.type))
return ira->codegen->invalid_instruction;
@@ -25837,8 +25837,8 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst
}
if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {
- IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr, nullptr);
- ir_assert(result->value.type != nullptr, &instruction->base);
+ IrInstruction *result = ir_analyze_store_ptr(ira, &instruction->base, casted_ptr, value, false);
+ result->value.type = ira->codegen->builtin_types.entry_void;
return result;
}
test/stage1/behavior/atomics.zig
@@ -131,3 +131,16 @@ test "atomic store" {
@atomicStore(u32, &x, 12345678, .SeqCst);
expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
}
+
+test "atomic store comptime" {
+ comptime testAtomicStore();
+ testAtomicStore();
+}
+
+fn testAtomicStore() void {
+ var x: u32 = 0;
+ @atomicStore(u32, &x, 1, .SeqCst);
+ expect(@atomicLoad(u32, &x, .SeqCst) == 1);
+ @atomicStore(u32, &x, 12345678, .SeqCst);
+ expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
+}
\ No newline at end of file
test/compile_errors.zig
@@ -2,6 +2,16 @@ const tests = @import("tests.zig");
const builtin = @import("builtin");
pub fn addCases(cases: *tests.CompileErrorContext) void {
+ cases.add(
+ "atomic orderings of atomicStore Acquire or AcqRel",
+ \\export fn entry() void {
+ \\ var x: u32 = 0;
+ \\ @atomicStore(u32, &x, 1, .Acquire);
+ \\}
+ ,
+ "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel",
+ );
+
cases.add(
"missing const in slice with nested array type",
\\const Geo3DTex2D = struct { vertices: [][2]f32 };