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...@@ -25807,7 +25807,7 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst
25807 if (type_is_invalid(ptr_inst->value.type))25807 if (type_is_invalid(ptr_inst->value.type))
25808 return ira->codegen->invalid_instruction;25808 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);
25811 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);25811 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
25812 if (type_is_invalid(casted_ptr->value.type))25812 if (type_is_invalid(casted_ptr->value.type))
25813 return ira->codegen->invalid_instruction;25813 return ira->codegen->invalid_instruction;
...@@ -25837,8 +25837,8 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst...@@ -25837,8 +25837,8 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst
25837 }25837 }
2583825838
25839 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {25839 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {
25840 IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr, nullptr);25840 IrInstruction *result = ir_analyze_store_ptr(ira, &instruction->base, casted_ptr, value, false);
25841 ir_assert(result->value.type != nullptr, &instruction->base);25841 result->value.type = ira->codegen->builtin_types.entry_void;
25842 return result;25842 return result;
25843 }25843 }
2584425844
test/compile_errors.zig+10
...@@ -2,6 +2,16 @@ const tests = @import("tests.zig");...@@ -2,6 +2,16 @@ const tests = @import("tests.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub fn addCases(cases: *tests.CompileErrorContext) void {4pub 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
5 cases.add(15 cases.add(
6 "missing const in slice with nested array type",16 "missing const in slice with nested array type",
7 \\const Geo3DTex2D = struct { vertices: [][2]f32 };17 \\const Geo3DTex2D = struct { vertices: [][2]f32 };
test/stage1/behavior/atomics.zig+13
...@@ -131,3 +131,16 @@ test "atomic store" {...@@ -131,3 +131,16 @@ test "atomic store" {
131 @atomicStore(u32, &x, 12345678, .SeqCst);131 @atomicStore(u32, &x, 12345678, .SeqCst);
132 expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);132 expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
133}133}
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