diff --git a/src/ir.cpp b/src/ir.cpp index f5f1ea3e80..e794e8db03 100644 --- a/src/ir.cpp +++ b/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; } diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 1adf3c3f8e..c42c95465a 100644 --- a/test/compile_errors.zig +++ b/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 }; diff --git a/test/stage1/behavior/atomics.zig b/test/stage1/behavior/atomics.zig index 894f99b7e0..694eb160e4 100644 --- a/test/stage1/behavior/atomics.zig +++ b/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