diff options
author | Carl Meyer <carl@oddbird.net> | 2023-05-18 21:22:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-18 21:22:03 (GMT) |
commit | 0589c6a4d3d822cace42050198cb9a5e99c879ad (patch) | |
tree | ae6785cbe277413976d6513d80f42206477d5f0b /Lib/test/test_peepholer.py | |
parent | dcdc90d384723920e8dea0ee04eae8c219333634 (diff) | |
download | cpython-0589c6a4d3d822cace42050198cb9a5e99c879ad.zip cpython-0589c6a4d3d822cace42050198cb9a5e99c879ad.tar.gz cpython-0589c6a4d3d822cace42050198cb9a5e99c879ad.tar.bz2 |
gh-104615: don't make unsafe swaps in apply_static_swaps (#104620)
Diffstat (limited to 'Lib/test/test_peepholer.py')
-rw-r--r-- | Lib/test/test_peepholer.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index bf7fc42..255e928 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -971,13 +971,14 @@ class TestMarkingVariablesAsUnKnown(BytecodeTestCase): self.assertNotInBytecode(f, "LOAD_FAST_CHECK") -class DirectiCfgOptimizerTests(CfgOptimizationTestCase): +class DirectCfgOptimizerTests(CfgOptimizationTestCase): def cfg_optimization_test(self, insts, expected_insts, - consts=None, expected_consts=None): + consts=None, expected_consts=None, + nlocals=0): if expected_consts is None: expected_consts = consts - opt_insts, opt_consts = self.get_optimized(insts, consts) + opt_insts, opt_consts = self.get_optimized(insts, consts, nlocals) expected_insts = self.normalize_insts(expected_insts) self.assertInstructionsMatch(opt_insts, expected_insts) self.assertEqual(opt_consts, expected_consts) @@ -1058,6 +1059,19 @@ class DirectiCfgOptimizerTests(CfgOptimizationTestCase): ] self.cfg_optimization_test(insts, expected_insts, consts=list(range(5))) + def test_no_unsafe_static_swap(self): + # We can't change order of two stores to the same location + insts = [ + ('LOAD_CONST', 0, 1), + ('LOAD_CONST', 1, 2), + ('LOAD_CONST', 2, 3), + ('SWAP', 3, 4), + ('STORE_FAST', 1, 4), + ('STORE_FAST', 1, 4), + ('POP_TOP', 0, 4), + ('RETURN_VALUE', 5) + ] + self.cfg_optimization_test(insts, insts, consts=list(range(3)), nlocals=1) if __name__ == "__main__": unittest.main() |