@@ -204,25 +204,68 @@ private class BinarySignExpr extends FlowSignExpr {
204
204
}
205
205
}
206
206
207
+ /**
208
+ * A `Convert`, `Box`, or `Unbox` expression.
209
+ */
210
+ private class SemCastExpr extends SemUnaryExpr {
211
+ SemCastExpr ( ) {
212
+ this instanceof SemConvertExpr
213
+ or
214
+ this instanceof SemBoxExpr
215
+ or
216
+ this instanceof SemUnboxExpr
217
+ }
218
+ }
219
+
207
220
/** A unary expression whose sign is computed from the sign of its operand. */
208
221
private class UnarySignExpr extends FlowSignExpr {
209
222
SemUnaryExpr unary ;
210
223
211
- UnarySignExpr ( ) { unary = this }
224
+ UnarySignExpr ( ) { unary = this and not this instanceof SemCastExpr }
212
225
213
226
override Sign getSignRestriction ( ) {
214
227
result = semExprSign ( unary .getOperand ( ) ) .applyUnaryOp ( unary .getOpcode ( ) )
215
228
}
216
229
}
217
230
218
231
/**
219
- * A `Convert` expression, whose sign is computed based on sign of its operand and the source and
220
- * destination types.
232
+ * A `Convert`, `Box`, or `Unbox` expression, whose sign is computed based on
233
+ * the sign of its operand and the source and destination types.
221
234
*/
222
- private class ConvertSignExpr extends UnarySignExpr {
223
- override SemConvertExpr unary ;
235
+ abstract private class CastSignExpr extends FlowSignExpr {
236
+ SemUnaryExpr cast ;
237
+
238
+ CastSignExpr ( ) { cast = this and cast instanceof SemCastExpr }
239
+
240
+ override Sign getSignRestriction ( ) { result = semExprSign ( cast .getOperand ( ) ) }
241
+ }
224
242
225
- override Sign getSignRestriction ( ) { result = semExprSign ( unary .getOperand ( ) ) }
243
+ /**
244
+ * A `Convert` expression.
245
+ */
246
+ private class ConvertSignExpr extends CastSignExpr {
247
+ override SemConvertExpr cast ;
248
+ }
249
+
250
+ /**
251
+ * A `Box` expression.
252
+ */
253
+ private class BoxSignExpr extends CastSignExpr {
254
+ override SemBoxExpr cast ;
255
+ }
256
+
257
+ /**
258
+ * An `Unbox` expression.
259
+ */
260
+ private class UnboxSignExpr extends CastSignExpr {
261
+ override SemUnboxExpr cast ;
262
+
263
+ UnboxSignExpr ( ) {
264
+ exists ( SemType fromType | fromType = getTrackedType ( cast .getOperand ( ) ) |
265
+ // Only numeric source types are handled here.
266
+ fromType instanceof SemNumericType
267
+ )
268
+ }
226
269
}
227
270
228
271
private predicate unknownSign ( SemExpr e ) { e instanceof UnknownSignExpr }
0 commit comments