@@ -25,6 +25,7 @@ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
25
25
#define sym_set_non_null _Py_uop_sym_set_non_null
26
26
#define sym_set_type _Py_uop_sym_set_type
27
27
#define sym_set_const _Py_uop_sym_set_const
28
+ #define sym_is_bottom _Py_uop_sym_is_bottom
28
29
#define frame_new _Py_uop_frame_new
29
30
#define frame_pop _Py_uop_frame_pop
30
31
@@ -107,15 +108,19 @@ dummy_func(void) {
107
108
}
108
109
109
110
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
+ {
111
114
assert (PyLong_CheckExact (sym_get_const (left )));
112
115
assert (PyLong_CheckExact (sym_get_const (right )));
113
116
PyObject * temp = _PyLong_Add ((PyLongObject * )sym_get_const (left ),
114
117
(PyLongObject * )sym_get_const (right ));
115
118
if (temp == NULL ) {
116
119
goto error ;
117
120
}
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 );
119
124
// TODO gh-115506:
120
125
// replace opcode with constant propagated one and add tests!
121
126
}
@@ -125,15 +130,19 @@ dummy_func(void) {
125
130
}
126
131
127
132
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
+ {
129
136
assert (PyLong_CheckExact (sym_get_const (left )));
130
137
assert (PyLong_CheckExact (sym_get_const (right )));
131
138
PyObject * temp = _PyLong_Subtract ((PyLongObject * )sym_get_const (left ),
132
139
(PyLongObject * )sym_get_const (right ));
133
140
if (temp == NULL ) {
134
141
goto error ;
135
142
}
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 );
137
146
// TODO gh-115506:
138
147
// replace opcode with constant propagated one and add tests!
139
148
}
@@ -143,15 +152,19 @@ dummy_func(void) {
143
152
}
144
153
145
154
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
+ {
147
158
assert (PyLong_CheckExact (sym_get_const (left )));
148
159
assert (PyLong_CheckExact (sym_get_const (right )));
149
160
PyObject * temp = _PyLong_Multiply ((PyLongObject * )sym_get_const (left ),
150
161
(PyLongObject * )sym_get_const (right ));
151
162
if (temp == NULL ) {
152
163
goto error ;
153
164
}
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 );
155
168
// TODO gh-115506:
156
169
// replace opcode with constant propagated one and add tests!
157
170
}
@@ -161,7 +174,9 @@ dummy_func(void) {
161
174
}
162
175
163
176
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
+ {
165
180
assert (PyFloat_CheckExact (sym_get_const (left )));
166
181
assert (PyFloat_CheckExact (sym_get_const (right )));
167
182
PyObject * temp = PyFloat_FromDouble (
@@ -171,6 +186,8 @@ dummy_func(void) {
171
186
goto error ;
172
187
}
173
188
res = sym_new_const (ctx , temp );
189
+ Py_DECREF (temp );
190
+ OUT_OF_SPACE_IF_NULL (res );
174
191
// TODO gh-115506:
175
192
// replace opcode with constant propagated one and update tests!
176
193
}
@@ -180,7 +197,9 @@ dummy_func(void) {
180
197
}
181
198
182
199
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
+ {
184
203
assert (PyFloat_CheckExact (sym_get_const (left )));
185
204
assert (PyFloat_CheckExact (sym_get_const (right )));
186
205
PyObject * temp = PyFloat_FromDouble (
@@ -190,6 +209,8 @@ dummy_func(void) {
190
209
goto error ;
191
210
}
192
211
res = sym_new_const (ctx , temp );
212
+ Py_DECREF (temp );
213
+ OUT_OF_SPACE_IF_NULL (res );
193
214
// TODO gh-115506:
194
215
// replace opcode with constant propagated one and update tests!
195
216
}
@@ -199,7 +220,9 @@ dummy_func(void) {
199
220
}
200
221
201
222
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
+ {
203
226
assert (PyFloat_CheckExact (sym_get_const (left )));
204
227
assert (PyFloat_CheckExact (sym_get_const (right )));
205
228
PyObject * temp = PyFloat_FromDouble (
@@ -209,6 +232,8 @@ dummy_func(void) {
209
232
goto error ;
210
233
}
211
234
res = sym_new_const (ctx , temp );
235
+ Py_DECREF (temp );
236
+ OUT_OF_SPACE_IF_NULL (res );
212
237
// TODO gh-115506:
213
238
// replace opcode with constant propagated one and update tests!
214
239
}
0 commit comments