@@ -413,41 +413,42 @@ private predicate downcastSuccessor(VarAccess va, RefType t) {
413413 )
414414}
415415
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 ( )
420421 )
421422 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 ( )
429427 )
430428}
431429
432430/**
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`.
434432 */
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 )
440438 )
441439}
442440
443441/**
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`.
445443 */
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 )
451452 )
452453}
453454
@@ -473,10 +474,10 @@ private predicate typeFlowBaseCand(TypeFlowNode n, RefType t) {
473474 upcast ( n , srctype ) or
474475 upcastEnhancedForStmt ( n .asSsa ( ) , srctype ) or
475476 downcastSuccessor ( n .asExpr ( ) , srctype ) or
476- instanceOfGuarded ( n .asExpr ( ) , srctype ) or
477+ typeTestGuarded ( n .asExpr ( ) , srctype ) or
478+ arrayTypeTestGuarded ( n .asExpr ( ) , srctype ) or
477479 n .asExpr ( ) .( FunctionalExpr ) .getConstructedType ( ) = srctype or
478- superAccess ( n .asExpr ( ) , srctype ) or
479- patternCaseGuarded ( n .asExpr ( ) , srctype )
480+ superAccess ( n .asExpr ( ) , srctype )
480481 |
481482 t = srctype .( BoundedType ) .getAnUltimateUpperBoundType ( )
482483 or
0 commit comments