diff options
Diffstat (limited to 'tests/test_cfg_structure.py')
| -rw-r--r-- | tests/test_cfg_structure.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/tests/test_cfg_structure.py b/tests/test_cfg_structure.py index f6caa5bd8..761bb21ee 100644 --- a/tests/test_cfg_structure.py +++ b/tests/test_cfg_structure.py | |||
| @@ -255,10 +255,11 @@ def test_deep_sequential_chains_stay_flat_and_iterative(): | |||
| 255 | 255 | ||
| 256 | 256 | ||
| 257 | def test_unwrap_known_pc_guards(): | 257 | def test_unwrap_known_pc_guards(): |
| 258 | def unwrap(succ): | 258 | def unwrap(succ, out_pcs=None): |
| 259 | tree = S.structure(succ) | 259 | if out_pcs is None: |
| 260 | out_pcs = {b: (set(succ[b]) if succ[b] else {S.END}) for b in range(len(succ))} | ||
| 261 | tree = S.structure(succ, out_pcs=out_pcs) | ||
| 260 | assert tree is not None | 262 | assert tree is not None |
| 261 | out_pcs = {b: (set(succ[b]) if succ[b] else {S.END}) for b in range(len(succ))} | ||
| 262 | return S.unwrap_known_pc_guards(tree, out_pcs) | 263 | return S.unwrap_known_pc_guards(tree, out_pcs) |
| 263 | 264 | ||
| 264 | # Single-arm if-then (ms_wave_info_s3 shape: 0 -> {2, 1}, 1 -> {2}, 2 -> []): join block 2 unwraps to top level. | 265 | # Single-arm if-then (ms_wave_info_s3 shape: 0 -> {2, 1}, 1 -> {2}, 2 -> []): join block 2 unwraps to top level. |
| @@ -270,6 +271,18 @@ def test_unwrap_known_pc_guards(): | |||
| 270 | assert unwrap([[0, 1], []]) == [("loop", 0, [("block", 0)]), ("block", 1)] | 271 | assert unwrap([[0, 1], []]) == [("loop", 0, [("block", 0)]), ("block", 1)] |
| 271 | # Early exit in arm 1 (0 -> {1, 2}, 1 -> [], 2 -> []): both arms MUST remain guarded (pc may be END). | 272 | # Early exit in arm 1 (0 -> {1, 2}, 1 -> [], 2 -> []): both arms MUST remain guarded (pc may be END). |
| 272 | assert unwrap([[1, 2], [], []]) == [("block", 0), ("guard", 2, [("block", 2)]), ("guard", 1, [("block", 1)])] | 273 | assert unwrap([[1, 2], [], []]) == [("block", 0), ("guard", 2, [("block", 2)]), ("guard", 1, [("block", 1)])] |
| 274 | # Conditional branch in the last block with no s_endpgm after it (fallthrough writes END): | ||
| 275 | # loop body block 2 has succ [0] but out_pcs {0, END}, so exiting loop 0 leaves pc in {1, END}; | ||
| 276 | # guard 1 MUST stay so falling off the end does not execute block 1. | ||
| 277 | assert unwrap([[2, 1], [], [0]], out_pcs={0: {2, 1}, 1: {S.END}, 2: {0, S.END}}) == [ | ||
| 278 | ("loop", 0, [("block", 0), ("guard", 2, [("block", 2)])]), | ||
| 279 | ("guard", 1, [("block", 1)]), | ||
| 280 | ] | ||
| 281 | # Non-loop conditional branch falling off the end whose single explicit target is immediately dominated by it: | ||
| 282 | # block 2 has succ [1] and out_pcs {1, END}, so structure() and unwrap MUST both keep guard 1. | ||
| 283 | assert unwrap([[2], [], [1]], out_pcs={0: {2}, 1: {S.END}, 2: {1, S.END}}) == [ | ||
| 284 | ("block", 0), ("block", 2), ("guard", 1, [("block", 1)]), | ||
| 285 | ] | ||
| 273 | 286 | ||
| 274 | 287 | ||
| 275 | if __name__ == "__main__": | 288 | if __name__ == "__main__": |