@@ -1512,8 +1512,6 @@ fold_constant_intrinsic_list_to_tuple(basicblock *bb, int i,
15121512 return ERROR ;
15131513 }
15141514
1515- bool expect_append = true;
1516-
15171515 for (int pos = i - 1 ; pos >= 0 ; pos -- ) {
15181516 cfg_instr * instr = & bb -> b_instr [pos ];
15191517
@@ -1522,10 +1520,6 @@ fold_constant_intrinsic_list_to_tuple(basicblock *bb, int i,
15221520 }
15231521
15241522 if (instr -> i_opcode == BUILD_LIST && instr -> i_oparg == 0 ) {
1525- if (!expect_append ) {
1526- /* Not a sequence start */
1527- goto exit ;
1528- }
15291523 /* Sequence start, we are done. */
15301524 if (PyList_Reverse (list ) < 0 ) {
15311525 goto error ;
@@ -1540,27 +1534,30 @@ fold_constant_intrinsic_list_to_tuple(basicblock *bb, int i,
15401534 return instr_make_load_const (intrinsic , newconst , consts , const_cache );
15411535 }
15421536
1543- if (expect_append ) {
1544- if (!(instr -> i_opcode == LIST_APPEND && instr -> i_oparg == 1 )) {
1545- goto exit ;
1546- }
1537+ if (pos < 1 ) {
1538+ /* Can't process 2 instructions. */
1539+ goto exit ;
15471540 }
1548- else {
1549- if (!loads_const (instr -> i_opcode )) {
1550- goto exit ;
1551- }
1552- PyObject * constant = get_const_value (instr -> i_opcode , instr -> i_oparg , consts );
1553- if (constant == NULL ) {
1554- goto error ;
1555- }
1556- int r = PyList_Append (list , constant );
1557- Py_DECREF (constant );
1558- if (r < 0 ) {
1559- goto error ;
1560- }
1541+
1542+ if (!(instr -> i_opcode == LIST_APPEND && instr -> i_oparg == 1 )) {
1543+ goto exit ;
1544+ }
1545+
1546+ instr = & bb -> b_instr [-- pos ];
1547+ if (!loads_const (instr -> i_opcode )) {
1548+ goto exit ;
15611549 }
15621550
1563- expect_append = !expect_append ;
1551+ PyObject * constant = get_const_value (instr -> i_opcode , instr -> i_oparg , consts );
1552+ if (constant == NULL ) {
1553+ goto error ;
1554+ }
1555+
1556+ int r = PyList_Append (list , constant );
1557+ Py_DECREF (constant );
1558+ if (r < 0 ) {
1559+ goto error ;
1560+ }
15641561 }
15651562
15661563exit :
@@ -2472,7 +2469,7 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
24722469 INSTR_SET_OP0 (inst , NOP );
24732470 }
24742471 else {
2475- fold_constant_intrinsic_list_to_tuple (bb , i , consts , const_cache );
2472+ RETURN_IF_ERROR ( fold_constant_intrinsic_list_to_tuple (bb , i , consts , const_cache ) );
24762473 }
24772474 }
24782475 else if (oparg == INTRINSIC_UNARY_POSITIVE ) {
0 commit comments