authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-17 18:13:38-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-17 18:13:38-04:00
logcf9200b81594071d6378df2294da1c737c780c05
tree2ad8766ea3e088fb2bc6fba6792b49ce7239d217
parent4c6f1e614a204293732004ef844e8bb057bdc212
signaturelock-open Commit is signed but in an unrecognized format.

dereferencing a *u0 is comptime-known to be 0


2 files changed, 13 insertions(+), 0 deletions(-)

src/ir.cpp+7
......@@ -11187,6 +11187,13 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1118711187 }
1118811188 }
1118911189 }
11190 // dereferencing a *u0 is comptime known to be 0
11191 if (child_type->id == ZigTypeIdInt && child_type->data.integral.bit_count == 0) {
11192 IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope,
11193 source_instruction->source_node, child_type);
11194 init_const_unsigned_negative(&result->value, child_type, 0, false);
11195 return result;
11196 }
1119011197 // TODO if the instruction is a const ref instruction we can skip it
1119111198 IrInstruction *load_ptr_instruction = ir_build_load_ptr(&ira->new_irb, source_instruction->scope,
1119211199 source_instruction->source_node, ptr);
test/cases/eval.zig+6
......@@ -682,3 +682,9 @@ test "refer to the type of a generic function" {
682682}
683683
684684fn doNothingWithType(comptime T: type) void {}
685
686test "zero extend from u0 to u1" {
687 var zero_u0: u0 = 0;
688 var zero_u1: u1 = zero_u0;
689 assert(zero_u1 == 0);
690}