@@ -971,13 +971,14 @@ def trace(frame, event, arg):
971971 self .assertNotInBytecode (f , "LOAD_FAST_CHECK" )
972972
973973
974- class DirectiCfgOptimizerTests (CfgOptimizationTestCase ):
974+ class DirectCfgOptimizerTests (CfgOptimizationTestCase ):
975975
976976 def cfg_optimization_test (self , insts , expected_insts ,
977- consts = None , expected_consts = None ):
977+ consts = None , expected_consts = None ,
978+ nlocals = 0 ):
978979 if expected_consts is None :
979980 expected_consts = consts
980- opt_insts , opt_consts = self .get_optimized (insts , consts )
981+ opt_insts , opt_consts = self .get_optimized (insts , consts , nlocals )
981982 expected_insts = self .normalize_insts (expected_insts )
982983 self .assertInstructionsMatch (opt_insts , expected_insts )
983984 self .assertEqual (opt_consts , expected_consts )
@@ -1058,6 +1059,19 @@ def test_conditional_jump_backward_const_condition(self):
10581059 ]
10591060 self .cfg_optimization_test (insts , expected_insts , consts = list (range (5 )))
10601061
1062+ def test_no_unsafe_static_swap (self ):
1063+ # We can't change order of two stores to the same location
1064+ insts = [
1065+ ('LOAD_CONST' , 0 , 1 ),
1066+ ('LOAD_CONST' , 1 , 2 ),
1067+ ('LOAD_CONST' , 2 , 3 ),
1068+ ('SWAP' , 3 , 4 ),
1069+ ('STORE_FAST' , 1 , 4 ),
1070+ ('STORE_FAST' , 1 , 4 ),
1071+ ('POP_TOP' , 0 , 4 ),
1072+ ('RETURN_VALUE' , 5 )
1073+ ]
1074+ self .cfg_optimization_test (insts , insts , consts = list (range (3 )), nlocals = 1 )
10611075
10621076if __name__ == "__main__" :
10631077 unittest .main ()
0 commit comments