mirror of
https://github.com/github/codeql.git
synced 2025-12-21 19:26:31 +01:00
Pattern cases: support type-flow
This commit is contained in:
@@ -440,6 +440,21 @@ predicate arrayInstanceOfGuarded(ArrayAccess aa, RefType t) {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `va` is an access to a value that is guarded by `case T t`.
|
||||
*/
|
||||
private predicate patternCaseGuarded(VarAccess va, RefType t) {
|
||||
exists(PatternCase pc, BaseSsaVariable v |
|
||||
va = v.getAUse() and
|
||||
(
|
||||
pc.getSwitch().getExpr() = v.getAUse() or
|
||||
pc.getSwitchExpr().getExpr() = v.getAUse()
|
||||
) and
|
||||
pc.getDecl().getBasicBlock().bbDominates(va.getBasicBlock()) and
|
||||
t = pc.getDecl().getType()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `t` is the type of the `this` value corresponding to the the
|
||||
* `SuperAccess`. As the `SuperAccess` expression has the type of the supertype,
|
||||
@@ -465,7 +480,8 @@ private predicate typeFlowBaseCand(TypeFlowNode n, RefType t) {
|
||||
instanceOfGuarded(n.asExpr(), srctype) or
|
||||
arrayInstanceOfGuarded(n.asExpr(), srctype) or
|
||||
n.asExpr().(FunctionalExpr).getConstructedType() = srctype or
|
||||
superAccess(n.asExpr(), srctype)
|
||||
superAccess(n.asExpr(), srctype) or
|
||||
patternCaseGuarded(n.asExpr(), srctype)
|
||||
|
|
||||
t = srctype.(BoundedType).getAnUltimateUpperBoundType()
|
||||
or
|
||||
|
||||
@@ -44,6 +44,10 @@ public class UnionTypes {
|
||||
if (x instanceof Inter) {
|
||||
x.hashCode();
|
||||
}
|
||||
var hashCode = switch (x) {
|
||||
case Inter i -> x.hashCode();
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
void m3(Object d) {
|
||||
|
||||
@@ -14,3 +14,4 @@
|
||||
| A.java:70:23:70:24 | x2 | Integer | false |
|
||||
| A.java:92:18:92:18 | n | Integer | false |
|
||||
| UnionTypes.java:45:7:45:7 | x | Inter | false |
|
||||
| UnionTypes.java:48:23:48:23 | x | Inter | false |
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
| UnionTypes.java:44:9:44:9 | x | 3 | A3 | false |
|
||||
| UnionTypes.java:45:7:45:7 | x | 2 | A1 | false |
|
||||
| UnionTypes.java:45:7:45:7 | x | 2 | A2 | true |
|
||||
| UnionTypes.java:51:7:51:7 | d | 3 | A1 | false |
|
||||
| UnionTypes.java:51:7:51:7 | d | 3 | A2 | false |
|
||||
| UnionTypes.java:51:7:51:7 | d | 3 | A3 | false |
|
||||
| UnionTypes.java:47:28:47:28 | x | 3 | A1 | false |
|
||||
| UnionTypes.java:47:28:47:28 | x | 3 | A2 | true |
|
||||
| UnionTypes.java:47:28:47:28 | x | 3 | A3 | false |
|
||||
| UnionTypes.java:48:23:48:23 | x | 2 | A1 | false |
|
||||
| UnionTypes.java:48:23:48:23 | x | 2 | A2 | true |
|
||||
| UnionTypes.java:55:7:55:7 | d | 3 | A1 | false |
|
||||
| UnionTypes.java:55:7:55:7 | d | 3 | A2 | false |
|
||||
| UnionTypes.java:55:7:55:7 | d | 3 | A3 | false |
|
||||
|
||||
Reference in New Issue
Block a user