Skip to content

Commit c78f3f8

Browse files
authored
Merge pull request #336 from aschackmull/java/dataflow-cleanup
Approved by yh-semmle
2 parents 465a55f + 0b46ffa commit c78f3f8

File tree

14 files changed

+139
-641
lines changed

14 files changed

+139
-641
lines changed

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 11 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -724,76 +724,27 @@ private predicate localFlowBigStep(
724724
localFlowExit(node2, config)
725725
}
726726

727-
/**
728-
* Holds if `f` may contain an object of the same type, `t`, as the one
729-
* that contains `f`, and if this fact should be used to compress
730-
* access paths.
731-
*
732-
* Examples include the tail pointer in a linked list or the left and right
733-
* pointers in a binary tree.
734-
*/
735-
private predicate selfRef(Content f, RefType t) {
736-
t = f.getDeclaringType() and
737-
f.isSelfRef()
738-
}
739-
740-
private newtype TFlowContainer =
741-
TRegularContent(Content f) { not selfRef(f, _) } or
742-
TSelfRefContent(RefType t) { selfRef(_, t) }
743-
744-
/**
745-
* A `Content` or a `Content` abstracted as its declaring type.
746-
*
747-
* Sequences of one or more `Content`s in the same declaring type for which
748-
* `isSelfRef()` holds are represented as a single `FlowContainer` in an
749-
* `AccessPath`.
750-
*/
751-
private class FlowContainer extends TFlowContainer {
752-
string toString() {
753-
exists(Content f | this = TRegularContent(f) and result = f.toString())
754-
or
755-
exists(RefType t | this = TSelfRefContent(t) and result = t.toString())
756-
}
757-
758-
predicate usesContent(Content f) {
759-
this = TRegularContent(f)
760-
or
761-
exists(RefType t | this = TSelfRefContent(t) and selfRef(f, t))
762-
}
763-
764-
RefType getContainerType() {
765-
exists(Content f | this = TRegularContent(f) and result = f.getDeclaringType())
766-
or
767-
this = TSelfRefContent(result)
768-
}
769-
}
770-
771727
private newtype TAccessPathFront =
772728
TFrontNil(Type t) or
773-
TFrontHead(FlowContainer f)
729+
TFrontHead(Content f)
774730

775731
/**
776732
* The front of an `AccessPath`. This is either a head or a nil.
777733
*/
778734
private class AccessPathFront extends TAccessPathFront {
779735
string toString() {
780-
exists(Type t | this = TFrontNil(t) | result = t.toString())
736+
exists(Type t | this = TFrontNil(t) | result = ppReprType(t))
781737
or
782-
exists(FlowContainer f | this = TFrontHead(f) | result = f.toString())
738+
exists(Content f | this = TFrontHead(f) | result = f.toString())
783739
}
784740

785741
Type getType() {
786742
this = TFrontNil(result)
787743
or
788-
exists(FlowContainer head | this = TFrontHead(head) | result = head.getContainerType())
744+
exists(Content head | this = TFrontHead(head) | result = head.getContainerType())
789745
}
790746

791-
predicate headUsesContent(Content f) {
792-
exists(FlowContainer fc |
793-
fc.usesContent(f) and
794-
this = TFrontHead(fc)
795-
)
796-
}
747+
predicate headUsesContent(Content f) { this = TFrontHead(f) }
797748
}
798749

799750
private class AccessPathFrontNil extends AccessPathFront, TFrontNil { }
@@ -1004,7 +955,7 @@ private predicate consCand(Content f, AccessPathFront apf, Configuration config)
1004955

1005956
private newtype TAccessPath =
1006957
TNil(Type t) or
1007-
TCons(FlowContainer f, int len) { len in [1 .. 5] }
958+
TCons(Content f, int len) { len in [1 .. 5] }
1008959

1009960
/**
1010961
* Conceptually a list of `Content`s followed by a `Type`, but only the first
@@ -1016,7 +967,7 @@ private newtype TAccessPath =
1016967
private class AccessPath extends TAccessPath {
1017968
abstract string toString();
1018969

1019-
FlowContainer getHead() { this = TCons(result, _) }
970+
Content getHead() { this = TCons(result, _) }
1020971

1021972
int len() {
1022973
this = TNil(_) and result = 0
@@ -1027,27 +978,27 @@ private class AccessPath extends TAccessPath {
1027978
Type getType() {
1028979
this = TNil(result)
1029980
or
1030-
exists(FlowContainer head | this = TCons(head, _) | result = head.getContainerType())
981+
exists(Content head | this = TCons(head, _) | result = head.getContainerType())
1031982
}
1032983

1033984
abstract AccessPathFront getFront();
1034985
}
1035986

1036987
private class AccessPathNil extends AccessPath, TNil {
1037-
override string toString() { exists(Type t | this = TNil(t) | result = t.toString()) }
988+
override string toString() { exists(Type t | this = TNil(t) | result = ppReprType(t)) }
1038989

1039990
override AccessPathFront getFront() { exists(Type t | this = TNil(t) | result = TFrontNil(t)) }
1040991
}
1041992

1042993
private class AccessPathCons extends AccessPath, TCons {
1043994
override string toString() {
1044-
exists(FlowContainer f, int len | this = TCons(f, len) |
995+
exists(Content f, int len | this = TCons(f, len) |
1045996
result = f.toString() + ", ... (" + len.toString() + ")"
1046997
)
1047998
}
1048999

10491000
override AccessPathFront getFront() {
1050-
exists(FlowContainer f | this = TCons(f, _) | result = TFrontHead(f))
1001+
exists(Content f | this = TCons(f, _) | result = TFrontHead(f))
10511002
}
10521003
}
10531004

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl2.qll

Lines changed: 11 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -724,76 +724,27 @@ private predicate localFlowBigStep(
724724
localFlowExit(node2, config)
725725
}
726726

727-
/**
728-
* Holds if `f` may contain an object of the same type, `t`, as the one
729-
* that contains `f`, and if this fact should be used to compress
730-
* access paths.
731-
*
732-
* Examples include the tail pointer in a linked list or the left and right
733-
* pointers in a binary tree.
734-
*/
735-
private predicate selfRef(Content f, RefType t) {
736-
t = f.getDeclaringType() and
737-
f.isSelfRef()
738-
}
739-
740-
private newtype TFlowContainer =
741-
TRegularContent(Content f) { not selfRef(f, _) } or
742-
TSelfRefContent(RefType t) { selfRef(_, t) }
743-
744-
/**
745-
* A `Content` or a `Content` abstracted as its declaring type.
746-
*
747-
* Sequences of one or more `Content`s in the same declaring type for which
748-
* `isSelfRef()` holds are represented as a single `FlowContainer` in an
749-
* `AccessPath`.
750-
*/
751-
private class FlowContainer extends TFlowContainer {
752-
string toString() {
753-
exists(Content f | this = TRegularContent(f) and result = f.toString())
754-
or
755-
exists(RefType t | this = TSelfRefContent(t) and result = t.toString())
756-
}
757-
758-
predicate usesContent(Content f) {
759-
this = TRegularContent(f)
760-
or
761-
exists(RefType t | this = TSelfRefContent(t) and selfRef(f, t))
762-
}
763-
764-
RefType getContainerType() {
765-
exists(Content f | this = TRegularContent(f) and result = f.getDeclaringType())
766-
or
767-
this = TSelfRefContent(result)
768-
}
769-
}
770-
771727
private newtype TAccessPathFront =
772728
TFrontNil(Type t) or
773-
TFrontHead(FlowContainer f)
729+
TFrontHead(Content f)
774730

775731
/**
776732
* The front of an `AccessPath`. This is either a head or a nil.
777733
*/
778734
private class AccessPathFront extends TAccessPathFront {
779735
string toString() {
780-
exists(Type t | this = TFrontNil(t) | result = t.toString())
736+
exists(Type t | this = TFrontNil(t) | result = ppReprType(t))
781737
or
782-
exists(FlowContainer f | this = TFrontHead(f) | result = f.toString())
738+
exists(Content f | this = TFrontHead(f) | result = f.toString())
783739
}
784740

785741
Type getType() {
786742
this = TFrontNil(result)
787743
or
788-
exists(FlowContainer head | this = TFrontHead(head) | result = head.getContainerType())
744+
exists(Content head | this = TFrontHead(head) | result = head.getContainerType())
789745
}
790746

791-
predicate headUsesContent(Content f) {
792-
exists(FlowContainer fc |
793-
fc.usesContent(f) and
794-
this = TFrontHead(fc)
795-
)
796-
}
747+
predicate headUsesContent(Content f) { this = TFrontHead(f) }
797748
}
798749

799750
private class AccessPathFrontNil extends AccessPathFront, TFrontNil { }
@@ -1004,7 +955,7 @@ private predicate consCand(Content f, AccessPathFront apf, Configuration config)
1004955

1005956
private newtype TAccessPath =
1006957
TNil(Type t) or
1007-
TCons(FlowContainer f, int len) { len in [1 .. 5] }
958+
TCons(Content f, int len) { len in [1 .. 5] }
1008959

1009960
/**
1010961
* Conceptually a list of `Content`s followed by a `Type`, but only the first
@@ -1016,7 +967,7 @@ private newtype TAccessPath =
1016967
private class AccessPath extends TAccessPath {
1017968
abstract string toString();
1018969

1019-
FlowContainer getHead() { this = TCons(result, _) }
970+
Content getHead() { this = TCons(result, _) }
1020971

1021972
int len() {
1022973
this = TNil(_) and result = 0
@@ -1027,27 +978,27 @@ private class AccessPath extends TAccessPath {
1027978
Type getType() {
1028979
this = TNil(result)
1029980
or
1030-
exists(FlowContainer head | this = TCons(head, _) | result = head.getContainerType())
981+
exists(Content head | this = TCons(head, _) | result = head.getContainerType())
1031982
}
1032983

1033984
abstract AccessPathFront getFront();
1034985
}
1035986

1036987
private class AccessPathNil extends AccessPath, TNil {
1037-
override string toString() { exists(Type t | this = TNil(t) | result = t.toString()) }
988+
override string toString() { exists(Type t | this = TNil(t) | result = ppReprType(t)) }
1038989

1039990
override AccessPathFront getFront() { exists(Type t | this = TNil(t) | result = TFrontNil(t)) }
1040991
}
1041992

1042993
private class AccessPathCons extends AccessPath, TCons {
1043994
override string toString() {
1044-
exists(FlowContainer f, int len | this = TCons(f, len) |
995+
exists(Content f, int len | this = TCons(f, len) |
1045996
result = f.toString() + ", ... (" + len.toString() + ")"
1046997
)
1047998
}
1048999

10491000
override AccessPathFront getFront() {
1050-
exists(FlowContainer f | this = TCons(f, _) | result = TFrontHead(f))
1001+
exists(Content f | this = TCons(f, _) | result = TFrontHead(f))
10511002
}
10521003
}
10531004

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl3.qll

Lines changed: 11 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -724,76 +724,27 @@ private predicate localFlowBigStep(
724724
localFlowExit(node2, config)
725725
}
726726

727-
/**
728-
* Holds if `f` may contain an object of the same type, `t`, as the one
729-
* that contains `f`, and if this fact should be used to compress
730-
* access paths.
731-
*
732-
* Examples include the tail pointer in a linked list or the left and right
733-
* pointers in a binary tree.
734-
*/
735-
private predicate selfRef(Content f, RefType t) {
736-
t = f.getDeclaringType() and
737-
f.isSelfRef()
738-
}
739-
740-
private newtype TFlowContainer =
741-
TRegularContent(Content f) { not selfRef(f, _) } or
742-
TSelfRefContent(RefType t) { selfRef(_, t) }
743-
744-
/**
745-
* A `Content` or a `Content` abstracted as its declaring type.
746-
*
747-
* Sequences of one or more `Content`s in the same declaring type for which
748-
* `isSelfRef()` holds are represented as a single `FlowContainer` in an
749-
* `AccessPath`.
750-
*/
751-
private class FlowContainer extends TFlowContainer {
752-
string toString() {
753-
exists(Content f | this = TRegularContent(f) and result = f.toString())
754-
or
755-
exists(RefType t | this = TSelfRefContent(t) and result = t.toString())
756-
}
757-
758-
predicate usesContent(Content f) {
759-
this = TRegularContent(f)
760-
or
761-
exists(RefType t | this = TSelfRefContent(t) and selfRef(f, t))
762-
}
763-
764-
RefType getContainerType() {
765-
exists(Content f | this = TRegularContent(f) and result = f.getDeclaringType())
766-
or
767-
this = TSelfRefContent(result)
768-
}
769-
}
770-
771727
private newtype TAccessPathFront =
772728
TFrontNil(Type t) or
773-
TFrontHead(FlowContainer f)
729+
TFrontHead(Content f)
774730

775731
/**
776732
* The front of an `AccessPath`. This is either a head or a nil.
777733
*/
778734
private class AccessPathFront extends TAccessPathFront {
779735
string toString() {
780-
exists(Type t | this = TFrontNil(t) | result = t.toString())
736+
exists(Type t | this = TFrontNil(t) | result = ppReprType(t))
781737
or
782-
exists(FlowContainer f | this = TFrontHead(f) | result = f.toString())
738+
exists(Content f | this = TFrontHead(f) | result = f.toString())
783739
}
784740

785741
Type getType() {
786742
this = TFrontNil(result)
787743
or
788-
exists(FlowContainer head | this = TFrontHead(head) | result = head.getContainerType())
744+
exists(Content head | this = TFrontHead(head) | result = head.getContainerType())
789745
}
790746

791-
predicate headUsesContent(Content f) {
792-
exists(FlowContainer fc |
793-
fc.usesContent(f) and
794-
this = TFrontHead(fc)
795-
)
796-
}
747+
predicate headUsesContent(Content f) { this = TFrontHead(f) }
797748
}
798749

799750
private class AccessPathFrontNil extends AccessPathFront, TFrontNil { }
@@ -1004,7 +955,7 @@ private predicate consCand(Content f, AccessPathFront apf, Configuration config)
1004955

1005956
private newtype TAccessPath =
1006957
TNil(Type t) or
1007-
TCons(FlowContainer f, int len) { len in [1 .. 5] }
958+
TCons(Content f, int len) { len in [1 .. 5] }
1008959

1009960
/**
1010961
* Conceptually a list of `Content`s followed by a `Type`, but only the first
@@ -1016,7 +967,7 @@ private newtype TAccessPath =
1016967
private class AccessPath extends TAccessPath {
1017968
abstract string toString();
1018969

1019-
FlowContainer getHead() { this = TCons(result, _) }
970+
Content getHead() { this = TCons(result, _) }
1020971

1021972
int len() {
1022973
this = TNil(_) and result = 0
@@ -1027,27 +978,27 @@ private class AccessPath extends TAccessPath {
1027978
Type getType() {
1028979
this = TNil(result)
1029980
or
1030-
exists(FlowContainer head | this = TCons(head, _) | result = head.getContainerType())
981+
exists(Content head | this = TCons(head, _) | result = head.getContainerType())
1031982
}
1032983

1033984
abstract AccessPathFront getFront();
1034985
}
1035986

1036987
private class AccessPathNil extends AccessPath, TNil {
1037-
override string toString() { exists(Type t | this = TNil(t) | result = t.toString()) }
988+
override string toString() { exists(Type t | this = TNil(t) | result = ppReprType(t)) }
1038989

1039990
override AccessPathFront getFront() { exists(Type t | this = TNil(t) | result = TFrontNil(t)) }
1040991
}
1041992

1042993
private class AccessPathCons extends AccessPath, TCons {
1043994
override string toString() {
1044-
exists(FlowContainer f, int len | this = TCons(f, len) |
995+
exists(Content f, int len | this = TCons(f, len) |
1045996
result = f.toString() + ", ... (" + len.toString() + ")"
1046997
)
1047998
}
1048999

10491000
override AccessPathFront getFront() {
1050-
exists(FlowContainer f | this = TCons(f, _) | result = TFrontHead(f))
1001+
exists(Content f | this = TCons(f, _) | result = TFrontHead(f))
10511002
}
10521003
}
10531004

0 commit comments

Comments
 (0)