| ... | ... | @@ -5977,8 +5977,13 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 5977 | 5977 | return sema.fail(block, src, "unable to cast runtime value to 'comptime_int'", .{}); |
| 5978 | 5978 | } |
| 5979 | 5979 | |
| 5980 | | try sema.requireRuntimeBlock(block, operand_src); |
| 5981 | 5980 | // TODO insert safety check to make sure the value fits in the dest type |
| 5981 | |
| 5982 | if ((try sema.typeHasOnePossibleValue(block, dest_ty_src, dest_ty))) |opv| { |
| 5983 | return sema.addConstant(dest_ty, opv); |
| 5984 | } |
| 5985 | |
| 5986 | try sema.requireRuntimeBlock(block, operand_src); |
| 5982 | 5987 | return block.addTyOp(.intcast, dest_ty, operand); |
| 5983 | 5988 | } |
| 5984 | 5989 | |
| ... | ... | @@ -7537,17 +7542,21 @@ fn zirShl( |
| 7537 | 7542 | const maybe_lhs_val = try sema.resolveMaybeUndefVal(block, lhs_src, lhs); |
| 7538 | 7543 | const maybe_rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs); |
| 7539 | 7544 | |
| 7545 | if (maybe_rhs_val) |rhs_val| { |
| 7546 | if (rhs_val.isUndef()) { |
| 7547 | return sema.addConstUndef(sema.typeOf(lhs)); |
| 7548 | } |
| 7549 | if (rhs_val.compareWithZero(.eq)) { |
| 7550 | return lhs; |
| 7551 | } |
| 7552 | } |
| 7553 | |
| 7540 | 7554 | const runtime_src = if (maybe_lhs_val) |lhs_val| rs: { |
| 7541 | 7555 | const lhs_ty = sema.typeOf(lhs); |
| 7542 | 7556 | |
| 7543 | 7557 | if (lhs_val.isUndef()) return sema.addConstUndef(lhs_ty); |
| 7544 | 7558 | const rhs_val = maybe_rhs_val orelse break :rs rhs_src; |
| 7545 | | if (rhs_val.isUndef()) return sema.addConstUndef(lhs_ty); |
| 7546 | 7559 | |
| 7547 | | // If rhs is 0, return lhs without doing any calculations. |
| 7548 | | if (rhs_val.compareWithZero(.eq)) { |
| 7549 | | return sema.addConstant(lhs_ty, lhs_val); |
| 7550 | | } |
| 7551 | 7560 | const target = sema.mod.getTarget(); |
| 7552 | 7561 | const val = switch (air_tag) { |
| 7553 | 7562 | .shl_exact => val: { |
| ... | ... | @@ -7577,12 +7586,7 @@ fn zirShl( |
| 7577 | 7586 | }; |
| 7578 | 7587 | |
| 7579 | 7588 | return sema.addConstant(lhs_ty, val); |
| 7580 | | } else rs: { |
| 7581 | | if (maybe_rhs_val) |rhs_val| { |
| 7582 | | if (rhs_val.isUndef()) return sema.addConstUndef(sema.typeOf(lhs)); |
| 7583 | | } |
| 7584 | | break :rs lhs_src; |
| 7585 | | }; |
| 7589 | } else lhs_src; |
| 7586 | 7590 | |
| 7587 | 7591 | // TODO: insert runtime safety check for shl_exact |
| 7588 | 7592 | |