fix crash when bit shifting a u1

master
Andrew Kelley 2018-09-17 18:44:45 -04:00
parent cf9200b815
commit 6c71e9a54d
No known key found for this signature in database
GPG Key ID: 4E7CD66038A4D47C
2 changed files with 11 additions and 0 deletions

View File

@ -12070,6 +12070,12 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_
ir_add_error(ira, &bin_op_instruction->base,
buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));
return ira->codegen->builtin_types.entry_invalid;
} else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value.data.x_bigint) == CmpEQ) {
IrInstruction *result = ir_build_cast(&ira->new_irb, bin_op_instruction->base.scope,
bin_op_instruction->base.source_node, op1->value.type, op1, CastOpNoop);
result->value.type = op1->value.type;
ir_link_new_instruction(result, &bin_op_instruction->base);
return result->value.type;
}
ir_build_bin_op_from(&ira->new_irb, &bin_op_instruction->base, op_id,

View File

@ -688,3 +688,8 @@ test "zero extend from u0 to u1" {
var zero_u1: u1 = zero_u0;
assert(zero_u1 == 0);
}
test "bit shift a u1" {
var x: u1 = 1;
var y = x << 0;
}