authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-25 20:28:09-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-25 20:33:40-05:00
log7571db05de3efcbc70a8404de6f479909b465eaa
tree7ed637211a9c29358fc870c16eb9511183797720
parent4b7e285b763046052c154b71a95a0ff05472f41f
signaturelock-open Commit is signed but in an unrecognized format.

fix incorrectly trying to memset at comptime

closes #718

3 files changed, 23 insertions(+), 1 deletions(-)

src/ir.cpp+5-1
......@@ -19451,10 +19451,12 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
1945119451 if (type_is_invalid(casted_count->value.type))
1945219452 return ira->codegen->invalid_instruction;
1945319453
19454 // TODO test this at comptime with u8 and non-u8 types
1945419455 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&
1945519456 casted_byte->value.special == ConstValSpecialStatic &&
1945619457 casted_count->value.special == ConstValSpecialStatic &&
19457 casted_dest_ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr)
19458 casted_dest_ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
19459 casted_dest_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar)
1945819460 {
1945919461 ConstExprValue *dest_ptr_val = &casted_dest_ptr->value;
1946019462
......@@ -19573,6 +19575,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
1957319575 if (type_is_invalid(casted_count->value.type))
1957419576 return ira->codegen->invalid_instruction;
1957519577
19578 // TODO test this at comptime with u8 and non-u8 types
19579 // TODO test with dest ptr being a global runtime variable
1957619580 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&
1957719581 casted_src_ptr->value.special == ConstValSpecialStatic &&
1957819582 casted_count->value.special == ConstValSpecialStatic &&
test/stage1/behavior.zig+1
......@@ -25,6 +25,7 @@ comptime {
2525 _ = @import("behavior/bugs/655.zig");
2626 _ = @import("behavior/bugs/656.zig");
2727 _ = @import("behavior/bugs/704.zig");
28 _ = @import("behavior/bugs/718.zig");
2829 _ = @import("behavior/bugs/726.zig");
2930 _ = @import("behavior/bugs/828.zig");
3031 _ = @import("behavior/bugs/920.zig");
test/stage1/behavior/bugs/718.zig created+17
......@@ -0,0 +1,17 @@
1const std = @import("std");
2const mem = std.mem;
3const expect = std.testing.expect;
4const Keys = struct {
5 up: bool,
6 down: bool,
7 left: bool,
8 right: bool,
9};
10var keys: Keys = undefined;
11test "zero keys with @memset" {
12 @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@typeOf(keys)));
13 expect(!keys.up);
14 expect(!keys.down);
15 expect(!keys.left);
16 expect(!keys.right);
17}