Check if src fits in target_type range, branch to overflow_block if not. On success, continues in a newly activated block where the value is known to be in range. Args: src: Source value to check target_type: Target fixed-width type defining the vali
(
self, src: Value, target_type: RPrimitive, overflow_block: BasicBlock, line: int
)
| 564 | return res |
| 565 | |
| 566 | def check_fixed_width_range( |
| 567 | self, src: Value, target_type: RPrimitive, overflow_block: BasicBlock, line: int |
| 568 | ) -> None: |
| 569 | """Check if src fits in target_type range, branch to overflow_block if not. |
| 570 | |
| 571 | On success, continues in a newly activated block where the value is |
| 572 | known to be in range. |
| 573 | |
| 574 | Args: |
| 575 | src: Source value to check |
| 576 | target_type: Target fixed-width type defining the valid range |
| 577 | overflow_block: Block to branch to if value is out of range |
| 578 | line: Line number |
| 579 | """ |
| 580 | in_range, in_range2 = BasicBlock(), BasicBlock() |
| 581 | |
| 582 | size = target_type.size |
| 583 | upper_bound = 1 << (size * 8 - 1) |
| 584 | if not target_type.is_signed: |
| 585 | upper_bound *= 2 |
| 586 | |
| 587 | # Check if value < upper_bound |
| 588 | check_upper = self.add( |
| 589 | ComparisonOp(src, Integer(upper_bound, src.type), ComparisonOp.SLT, line) |
| 590 | ) |
| 591 | self.add(Branch(check_upper, in_range, overflow_block, Branch.BOOL, line)) |
| 592 | |
| 593 | self.activate_block(in_range) |
| 594 | |
| 595 | # Check if value >= lower_bound |
| 596 | if target_type.is_signed: |
| 597 | lower_bound = -upper_bound |
| 598 | else: |
| 599 | lower_bound = 0 |
| 600 | check_lower = self.add( |
| 601 | ComparisonOp(src, Integer(lower_bound, src.type), ComparisonOp.SGE, line) |
| 602 | ) |
| 603 | self.add(Branch(check_lower, in_range2, overflow_block, Branch.BOOL, line)) |
| 604 | |
| 605 | self.activate_block(in_range2) |
| 606 | |
| 607 | def coerce_tagged_to_fixed_width_with_range_check( |
| 608 | self, |
no test coverage detected