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...@@ -19451,10 +19451,12 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
19451 if (type_is_invalid(casted_count->value.type))19451 if (type_is_invalid(casted_count->value.type))
19452 return ira->codegen->invalid_instruction;19452 return ira->codegen->invalid_instruction;
1945319453
19454 // TODO test this at comptime with u8 and non-u8 types
19454 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&19455 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&
19455 casted_byte->value.special == ConstValSpecialStatic &&19456 casted_byte->value.special == ConstValSpecialStatic &&
19456 casted_count->value.special == ConstValSpecialStatic &&19457 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)
19458 {19460 {
19459 ConstExprValue *dest_ptr_val = &casted_dest_ptr->value;19461 ConstExprValue *dest_ptr_val = &casted_dest_ptr->value;
1946019462
...@@ -19573,6 +19575,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -19573,6 +19575,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
19573 if (type_is_invalid(casted_count->value.type))19575 if (type_is_invalid(casted_count->value.type))
19574 return ira->codegen->invalid_instruction;19576 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
19576 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&19580 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&
19577 casted_src_ptr->value.special == ConstValSpecialStatic &&19581 casted_src_ptr->value.special == ConstValSpecialStatic &&
19578 casted_count->value.special == ConstValSpecialStatic &&19582 casted_count->value.special == ConstValSpecialStatic &&
test/stage1/behavior.zig+1
...@@ -25,6 +25,7 @@ comptime {...@@ -25,6 +25,7 @@ comptime {
25 _ = @import("behavior/bugs/655.zig");25 _ = @import("behavior/bugs/655.zig");
26 _ = @import("behavior/bugs/656.zig");26 _ = @import("behavior/bugs/656.zig");
27 _ = @import("behavior/bugs/704.zig");27 _ = @import("behavior/bugs/704.zig");
28 _ = @import("behavior/bugs/718.zig");
28 _ = @import("behavior/bugs/726.zig");29 _ = @import("behavior/bugs/726.zig");
29 _ = @import("behavior/bugs/828.zig");30 _ = @import("behavior/bugs/828.zig");
30 _ = @import("behavior/bugs/920.zig");31 _ = @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}