authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-13 01:32:16+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2019-11-13 01:32:16+02:00
log41914321b4593e3ed246cadda705e1076ab670d7
treea321302412dd377fbcc95a9ff364243cb369c47a
parentf0c94d95dde320ba5e7509dc1499b33e54a1c951
signaturelock-open Commit is signed but in an unrecognized format.

fix comptime atomicStore and add tests


3 files changed, 26 insertions(+), 3 deletions(-)

src/ir.cpp+3-3
......@@ -25807,7 +25807,7 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst
2580725807 if (type_is_invalid(ptr_inst->value.type))
2580825808 return ira->codegen->invalid_instruction;
2580925809
25810 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);
25810 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
2581125811 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
2581225812 if (type_is_invalid(casted_ptr->value.type))
2581325813 return ira->codegen->invalid_instruction;
......@@ -25837,8 +25837,8 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst
2583725837 }
2583825838
2583925839 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {
25840 IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr, nullptr);
25841 ir_assert(result->value.type != nullptr, &instruction->base);
25840 IrInstruction *result = ir_analyze_store_ptr(ira, &instruction->base, casted_ptr, value, false);
25841 result->value.type = ira->codegen->builtin_types.entry_void;
2584225842 return result;
2584325843 }
2584425844
test/compile_errors.zig+10
......@@ -2,6 +2,16 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add(
6 "atomic orderings of atomicStore Acquire or AcqRel",
7 \\export fn entry() void {
8 \\ var x: u32 = 0;
9 \\ @atomicStore(u32, &x, 1, .Acquire);
10 \\}
11 ,
12 "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel",
13 );
14
515 cases.add(
616 "missing const in slice with nested array type",
717 \\const Geo3DTex2D = struct { vertices: [][2]f32 };
test/stage1/behavior/atomics.zig+13
......@@ -131,3 +131,16 @@ test "atomic store" {
131131 @atomicStore(u32, &x, 12345678, .SeqCst);
132132 expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
133133}
134
135test "atomic store comptime" {
136 comptime testAtomicStore();
137 testAtomicStore();
138}
139
140fn testAtomicStore() void {
141 var x: u32 = 0;
142 @atomicStore(u32, &x, 1, .SeqCst);
143 expect(@atomicLoad(u32, &x, .SeqCst) == 1);
144 @atomicStore(u32, &x, 12345678, .SeqCst);
145 expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
146}
\ No newline at end of file