fix comptime atomicStore and add tests

master
Vexu 2019-11-13 01:32:16 +02:00
parent f0c94d95dd
commit 41914321b4
No known key found for this signature in database
GPG Key ID: 5AEABFCAFF5CD8D6
3 changed files with 26 additions and 3 deletions

View File

@ -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;
}

View File

@ -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 };

View File

@ -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);
}