Commit 6c71e9a54d

Andrew Kelley <superjoe30@gmail.com>
2018-09-18 00:44:45
fix crash when bit shifting a u1
1 parent cf9200b
Changed files (2)
src
test
cases
src/ir.cpp
@@ -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,
test/cases/eval.zig
@@ -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;
+}