@@ -25,6 +25,7 @@ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
2525#define sym_set_non_null _Py_uop_sym_set_non_null
2626#define sym_set_type _Py_uop_sym_set_type
2727#define sym_set_const _Py_uop_sym_set_const
28+ #define sym_is_bottom _Py_uop_sym_is_bottom
2829#define frame_new _Py_uop_frame_new
2930#define frame_pop _Py_uop_frame_pop
3031
@@ -107,15 +108,19 @@ dummy_func(void) {
107108 }
108109
109110 op (_BINARY_OP_ADD_INT , (left , right -- res )) {
110- if (sym_is_const (left ) && sym_is_const (right )) {
111+ if (sym_is_const (left ) && sym_is_const (right ) &&
112+ sym_matches_type (left , & PyLong_Type ) && sym_matches_type (right , & PyLong_Type ))
113+ {
111114 assert (PyLong_CheckExact (sym_get_const (left )));
112115 assert (PyLong_CheckExact (sym_get_const (right )));
113116 PyObject * temp = _PyLong_Add ((PyLongObject * )sym_get_const (left ),
114117 (PyLongObject * )sym_get_const (right ));
115118 if (temp == NULL ) {
116119 goto error ;
117120 }
118- OUT_OF_SPACE_IF_NULL (res = sym_new_const (ctx , temp ));
121+ res = sym_new_const (ctx , temp );
122+ Py_DECREF (temp );
123+ OUT_OF_SPACE_IF_NULL (res );
119124 // TODO gh-115506:
120125 // replace opcode with constant propagated one and add tests!
121126 }
@@ -125,15 +130,19 @@ dummy_func(void) {
125130 }
126131
127132 op (_BINARY_OP_SUBTRACT_INT , (left , right -- res )) {
128- if (sym_is_const (left ) && sym_is_const (right )) {
133+ if (sym_is_const (left ) && sym_is_const (right ) &&
134+ sym_matches_type (left , & PyLong_Type ) && sym_matches_type (right , & PyLong_Type ))
135+ {
129136 assert (PyLong_CheckExact (sym_get_const (left )));
130137 assert (PyLong_CheckExact (sym_get_const (right )));
131138 PyObject * temp = _PyLong_Subtract ((PyLongObject * )sym_get_const (left ),
132139 (PyLongObject * )sym_get_const (right ));
133140 if (temp == NULL ) {
134141 goto error ;
135142 }
136- OUT_OF_SPACE_IF_NULL (res = sym_new_const (ctx , temp ));
143+ res = sym_new_const (ctx , temp );
144+ Py_DECREF (temp );
145+ OUT_OF_SPACE_IF_NULL (res );
137146 // TODO gh-115506:
138147 // replace opcode with constant propagated one and add tests!
139148 }
@@ -143,15 +152,19 @@ dummy_func(void) {
143152 }
144153
145154 op (_BINARY_OP_MULTIPLY_INT , (left , right -- res )) {
146- if (sym_is_const (left ) && sym_is_const (right )) {
155+ if (sym_is_const (left ) && sym_is_const (right ) &&
156+ sym_matches_type (left , & PyLong_Type ) && sym_matches_type (right , & PyLong_Type ))
157+ {
147158 assert (PyLong_CheckExact (sym_get_const (left )));
148159 assert (PyLong_CheckExact (sym_get_const (right )));
149160 PyObject * temp = _PyLong_Multiply ((PyLongObject * )sym_get_const (left ),
150161 (PyLongObject * )sym_get_const (right ));
151162 if (temp == NULL ) {
152163 goto error ;
153164 }
154- OUT_OF_SPACE_IF_NULL (res = sym_new_const (ctx , temp ));
165+ res = sym_new_const (ctx , temp );
166+ Py_DECREF (temp );
167+ OUT_OF_SPACE_IF_NULL (res );
155168 // TODO gh-115506:
156169 // replace opcode with constant propagated one and add tests!
157170 }
@@ -161,7 +174,9 @@ dummy_func(void) {
161174 }
162175
163176 op (_BINARY_OP_ADD_FLOAT , (left , right -- res )) {
164- if (sym_is_const (left ) && sym_is_const (right )) {
177+ if (sym_is_const (left ) && sym_is_const (right ) &&
178+ sym_matches_type (left , & PyFloat_Type ) && sym_matches_type (right , & PyFloat_Type ))
179+ {
165180 assert (PyFloat_CheckExact (sym_get_const (left )));
166181 assert (PyFloat_CheckExact (sym_get_const (right )));
167182 PyObject * temp = PyFloat_FromDouble (
@@ -171,6 +186,8 @@ dummy_func(void) {
171186 goto error ;
172187 }
173188 res = sym_new_const (ctx , temp );
189+ Py_DECREF (temp );
190+ OUT_OF_SPACE_IF_NULL (res );
174191 // TODO gh-115506:
175192 // replace opcode with constant propagated one and update tests!
176193 }
@@ -180,7 +197,9 @@ dummy_func(void) {
180197 }
181198
182199 op (_BINARY_OP_SUBTRACT_FLOAT , (left , right -- res )) {
183- if (sym_is_const (left ) && sym_is_const (right )) {
200+ if (sym_is_const (left ) && sym_is_const (right ) &&
201+ sym_matches_type (left , & PyFloat_Type ) && sym_matches_type (right , & PyFloat_Type ))
202+ {
184203 assert (PyFloat_CheckExact (sym_get_const (left )));
185204 assert (PyFloat_CheckExact (sym_get_const (right )));
186205 PyObject * temp = PyFloat_FromDouble (
@@ -190,6 +209,8 @@ dummy_func(void) {
190209 goto error ;
191210 }
192211 res = sym_new_const (ctx , temp );
212+ Py_DECREF (temp );
213+ OUT_OF_SPACE_IF_NULL (res );
193214 // TODO gh-115506:
194215 // replace opcode with constant propagated one and update tests!
195216 }
@@ -199,7 +220,9 @@ dummy_func(void) {
199220 }
200221
201222 op (_BINARY_OP_MULTIPLY_FLOAT , (left , right -- res )) {
202- if (sym_is_const (left ) && sym_is_const (right )) {
223+ if (sym_is_const (left ) && sym_is_const (right ) &&
224+ sym_matches_type (left , & PyFloat_Type ) && sym_matches_type (right , & PyFloat_Type ))
225+ {
203226 assert (PyFloat_CheckExact (sym_get_const (left )));
204227 assert (PyFloat_CheckExact (sym_get_const (right )));
205228 PyObject * temp = PyFloat_FromDouble (
@@ -209,6 +232,8 @@ dummy_func(void) {
209232 goto error ;
210233 }
211234 res = sym_new_const (ctx , temp );
235+ Py_DECREF (temp );
236+ OUT_OF_SPACE_IF_NULL (res );
212237 // TODO gh-115506:
213238 // replace opcode with constant propagated one and update tests!
214239 }
0 commit comments