diff --git a/src/ir.cpp b/src/ir.cpp index f4b727412ea0d55ce2e0ef3dbe5b400b0832b77f..e2bcbcffee3e86edb7a8c51d4b220ef16ed3fe65 100644 --- a/src/ir.cpp +++ b/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, diff --git a/test/cases/eval.zig b/test/cases/eval.zig index 7f8ad8ed0746c7657c56c07aee1b2d4a45e9497f..104fa8f58cd5b2ea11050259d2eb44ec9ced31bf 100644 --- a/test/cases/eval.zig +++ b/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; +}