@@ -413,41 +413,42 @@ private predicate downcastSuccessor(VarAccess va, RefType t) {
413
413
)
414
414
}
415
415
416
- private Expr getAProbableAlias ( Expr e ) {
417
- exists ( BaseSsaVariable v |
418
- e = v .getAUse ( ) and
419
- result = v .getAUse ( )
416
+ private predicate isTypeTestGuard ( Guard test , Expr tested , Type t ) {
417
+ exists ( InstanceOfExpr ioe |
418
+ test = ioe and
419
+ ioe .getExpr ( ) = tested and
420
+ t = ioe .getCheckedType ( )
420
421
)
421
422
or
422
- exists ( BaseSsaVariable v1 , BaseSsaVariable v2 , ArrayAccess aa1 , ArrayAccess aa2 |
423
- e = aa1 and
424
- result = aa2 and
425
- aa1 .getArray ( ) = v1 .getAUse ( ) and
426
- aa1 .getIndexExpr ( ) = v2 .getAUse ( ) and
427
- aa2 .getArray ( ) = v1 .getAUse ( ) and
428
- aa2 .getIndexExpr ( ) = v2 .getAUse ( )
423
+ exists ( PatternCase pc |
424
+ test = pc and
425
+ pc .getSelectorExpr ( ) = tested and
426
+ t = pc .getPattern ( ) .getType ( )
429
427
)
430
428
}
431
429
432
430
/**
433
- * Holds if `e ` is an access to a value that is guarded by `instanceof t`.
431
+ * Holds if `va ` is an access to a value that is guarded by `instanceof t` or `case e t`.
434
432
*/
435
- private predicate instanceOfGuarded ( Expr e , RefType t ) {
436
- exists ( InstanceOfExpr ioe |
437
- t = ioe . getCheckedType ( ) and
438
- e = getAProbableAlias ( ioe . getExpr ( ) ) and
439
- guardControls_v1 ( ioe , e .getBasicBlock ( ) , true )
433
+ private predicate typeTestGuarded ( VarAccess va , RefType t ) {
434
+ exists ( Guard typeTest , BaseSsaVariable v |
435
+ isTypeTestGuard ( typeTest , v . getAUse ( ) , t ) and
436
+ va = v . getAUse ( ) and
437
+ guardControls_v1 ( typeTest , va .getBasicBlock ( ) , true )
440
438
)
441
439
}
442
440
443
441
/**
444
- * Holds if `e ` is an access to a value that is guarded by `case T t`.
442
+ * Holds if `aa ` is an access to a value that is guarded by `instanceof t` or ` case e t`.
445
443
*/
446
- private predicate patternCaseGuarded ( Expr e , RefType t ) {
447
- exists ( PatternCase pc |
448
- e = getAProbableAlias ( pc .getSelectorExpr ( ) ) and
449
- guardControls_v1 ( pc , e .getBasicBlock ( ) , true ) and
450
- t = pc .getPattern ( ) .getType ( )
444
+ predicate arrayTypeTestGuarded ( ArrayAccess aa , RefType t ) {
445
+ exists ( Guard typeTest , BaseSsaVariable v1 , BaseSsaVariable v2 , ArrayAccess aa1 |
446
+ isTypeTestGuard ( typeTest , aa1 , t ) and
447
+ aa1 .getArray ( ) = v1 .getAUse ( ) and
448
+ aa1 .getIndexExpr ( ) = v2 .getAUse ( ) and
449
+ aa .getArray ( ) = v1 .getAUse ( ) and
450
+ aa .getIndexExpr ( ) = v2 .getAUse ( ) and
451
+ guardControls_v1 ( typeTest , aa .getBasicBlock ( ) , true )
451
452
)
452
453
}
453
454
@@ -473,10 +474,10 @@ private predicate typeFlowBaseCand(TypeFlowNode n, RefType t) {
473
474
upcast ( n , srctype ) or
474
475
upcastEnhancedForStmt ( n .asSsa ( ) , srctype ) or
475
476
downcastSuccessor ( n .asExpr ( ) , srctype ) or
476
- instanceOfGuarded ( n .asExpr ( ) , srctype ) or
477
+ typeTestGuarded ( n .asExpr ( ) , srctype ) or
478
+ arrayTypeTestGuarded ( n .asExpr ( ) , srctype ) or
477
479
n .asExpr ( ) .( FunctionalExpr ) .getConstructedType ( ) = srctype or
478
- superAccess ( n .asExpr ( ) , srctype ) or
479
- patternCaseGuarded ( n .asExpr ( ) , srctype )
480
+ superAccess ( n .asExpr ( ) , srctype )
480
481
|
481
482
t = srctype .( BoundedType ) .getAnUltimateUpperBoundType ( )
482
483
or
0 commit comments