Skip to content

Commit ff3e45e

Browse files
committed
Dataflow: Eliminate TypedContentApprox.
1 parent 748bcba commit ff3e45e

File tree

2 files changed

+12
-50
lines changed

2 files changed

+12
-50
lines changed

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImpl.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,12 +2168,12 @@ module Impl<FullStateConfigSig Config> {
21682168
Typ getTyp(DataFlowType t) { result = t }
21692169

21702170
bindingset[tc, t, tail]
2171-
Ap apCons(TypedContent tc, Typ t, Ap tail) { result.getAHead() = tc and exists(t) and exists(tail) }
2171+
Ap apCons(TypedContent tc, Typ t, Ap tail) { result.getAHead() = tc.getContent() and exists(t) and exists(tail) }
21722172

21732173
class ApHeadContent = ContentApprox;
21742174

21752175
pragma[noinline]
2176-
ApHeadContent getHeadContent(Ap ap) { result = ap.getHead().getContent() }
2176+
ApHeadContent getHeadContent(Ap ap) { result = ap.getHead() }
21772177

21782178
predicate projectToHeadContent = getContentApprox/1;
21792179

@@ -2203,7 +2203,7 @@ module Impl<FullStateConfigSig Config> {
22032203
PrevStage::revFlow(node) and
22042204
PrevStage::readStepCand(_, c, _) and
22052205
expectsContentEx(node, c) and
2206-
c = ap.getAHead().getContent()
2206+
c = ap.getAHead()
22072207
)
22082208
}
22092209

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -934,27 +934,9 @@ private module Cached {
934934
TReturnCtxNoFlowThrough() or
935935
TReturnCtxMaybeFlowThrough(ReturnPosition pos)
936936

937-
cached
938-
newtype TTypedContentApprox =
939-
MkTypedContentApprox(ContentApprox c, DataFlowType t) {
940-
exists(Content cont |
941-
c = getContentApprox(cont) and
942-
store(_, cont, _, _, t)
943-
)
944-
}
945-
946937
cached
947938
newtype TTypedContent = MkTypedContent(Content c, DataFlowType t) { store(_, c, _, _, t) }
948939

949-
cached
950-
TypedContent getATypedContent(TypedContentApprox c) {
951-
exists(ContentApprox cls, DataFlowType t, Content cont |
952-
c = MkTypedContentApprox(cls, pragma[only_bind_into](t)) and
953-
result = MkTypedContent(cont, pragma[only_bind_into](t)) and
954-
cls = getContentApprox(cont)
955-
)
956-
}
957-
958940
cached
959941
newtype TAccessPathFront =
960942
TFrontNil() or
@@ -963,7 +945,7 @@ private module Cached {
963945
cached
964946
newtype TApproxAccessPathFront =
965947
TApproxFrontNil() or
966-
TApproxFrontHead(TypedContentApprox tc)
948+
TApproxFrontHead(ContentApprox c)
967949

968950
cached
969951
newtype TAccessPathFrontOption =
@@ -1389,26 +1371,6 @@ class ReturnCtx extends TReturnCtx {
13891371
}
13901372
}
13911373

1392-
/** An approximated `Content` tagged with the type of a containing object. */
1393-
class TypedContentApprox extends MkTypedContentApprox {
1394-
private ContentApprox c;
1395-
private DataFlowType t;
1396-
1397-
TypedContentApprox() { this = MkTypedContentApprox(c, t) }
1398-
1399-
/** Gets a typed content approximated by this value. */
1400-
TypedContent getATypedContent() { result = getATypedContent(this) }
1401-
1402-
/** Gets the content. */
1403-
ContentApprox getContent() { result = c }
1404-
1405-
/** Gets the container type. */
1406-
DataFlowType getContainerType() { result = t }
1407-
1408-
/** Gets a textual representation of this approximated content. */
1409-
string toString() { result = c.toString() }
1410-
}
1411-
14121374
/**
14131375
* The front of an approximated access path. This is either a head or a nil.
14141376
*/
@@ -1417,13 +1379,13 @@ abstract class ApproxAccessPathFront extends TApproxAccessPathFront {
14171379

14181380
abstract boolean toBoolNonEmpty();
14191381

1420-
TypedContentApprox getHead() { this = TApproxFrontHead(result) }
1382+
ContentApprox getHead() { this = TApproxFrontHead(result) }
14211383

14221384
pragma[nomagic]
1423-
TypedContent getAHead() {
1424-
exists(TypedContentApprox cont |
1385+
Content getAHead() {
1386+
exists(ContentApprox cont |
14251387
this = TApproxFrontHead(cont) and
1426-
result = cont.getATypedContent()
1388+
cont = getContentApprox(result)
14271389
)
14281390
}
14291391
}
@@ -1435,11 +1397,11 @@ class ApproxAccessPathFrontNil extends ApproxAccessPathFront, TApproxFrontNil {
14351397
}
14361398

14371399
class ApproxAccessPathFrontHead extends ApproxAccessPathFront, TApproxFrontHead {
1438-
private TypedContentApprox tc;
1400+
private ContentApprox c;
14391401

1440-
ApproxAccessPathFrontHead() { this = TApproxFrontHead(tc) }
1402+
ApproxAccessPathFrontHead() { this = TApproxFrontHead(c) }
14411403

1442-
override string toString() { result = tc.toString() }
1404+
override string toString() { result = c.toString() }
14431405

14441406
override boolean toBoolNonEmpty() { result = true }
14451407
}
@@ -1501,7 +1463,7 @@ class AccessPathFrontHead extends AccessPathFront, TFrontHead {
15011463

15021464
override string toString() { result = tc.toString() }
15031465

1504-
override ApproxAccessPathFront toApprox() { result.getAHead() = tc }
1466+
override ApproxAccessPathFront toApprox() { result.getAHead() = tc.getContent() }
15051467
}
15061468

15071469
/** An optional access path front. */

0 commit comments

Comments
 (0)