Skip to content

Commit

Permalink
Merge pull request #16979 from aschackmull/dataflow/internsets
Browse files Browse the repository at this point in the history
Dataflow: Replace MakeSets with QlBuiltins::InternSets.
  • Loading branch information
aschackmull authored Jul 16, 2024
2 parents 2dc63ef + da5abc8 commit 0fb27fb
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 407 deletions.
24 changes: 1 addition & 23 deletions cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowPrivate.qll
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,7 @@ class CastNode extends Node {
CastNode() { none() } // stub implementation
}

class DataFlowCallable extends Function {
/** Gets a best-effort total ordering. */
int totalorder() {
this =
rank[result](DataFlowCallable c, string file, int startline, int startcolumn |
c.getLocation().hasLocationInfo(file, startline, startcolumn, _, _)
|
c order by file, startline, startcolumn
)
}
}
class DataFlowCallable extends Function { }

class DataFlowExpr = Expr;

Expand All @@ -269,24 +259,12 @@ class DataFlowCall extends Expr instanceof Call {

/** Gets the enclosing callable of this call. */
DataFlowCallable getEnclosingCallable() { result = this.getEnclosingFunction() }

/** Gets a best-effort total ordering. */
int totalorder() {
this =
rank[result](DataFlowCall c, int startline, int startcolumn |
c.getLocation().hasLocationInfo(_, startline, startcolumn, _, _)
|
c order by startline, startcolumn
)
}
}

class NodeRegion instanceof Unit {
string toString() { result = "NodeRegion" }

predicate contains(Node n) { none() }

int totalOrder() { result = 1 }
}

predicate isUnreachableInCall(NodeRegion nr, DataFlowCall call) { none() } // stub implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1060,16 +1060,6 @@ class DataFlowCallable extends TDataFlowCallable {
result = this.asSummarizedCallable() or // SummarizedCallable = Function (in CPP)
result = this.asSourceCallable()
}

/** Gets a best-effort total ordering. */
int totalorder() {
this =
rank[result](DataFlowCallable c, string file, int startline, int startcolumn |
c.getLocation().hasLocationInfo(file, startline, startcolumn, _, _)
|
c order by file, startline, startcolumn
)
}
}

/**
Expand Down Expand Up @@ -1167,16 +1157,6 @@ class DataFlowCall extends TDataFlowCall {
* Gets the location of this call.
*/
Location getLocation() { none() }

/** Gets a best-effort total ordering. */
int totalorder() {
this =
rank[result](DataFlowCall c, int startline, int startcolumn |
c.getLocation().hasLocationInfo(_, startline, startcolumn, _, _)
|
c order by startline, startcolumn
)
}
}

/**
Expand Down Expand Up @@ -1269,15 +1249,6 @@ module IsUnreachableInCall {
string toString() { result = "NodeRegion" }

predicate contains(Node n) { this = n.getBasicBlock() }

int totalOrder() {
this =
rank[result](IRBlock b, int startline, int startcolumn |
b.getLocation().hasLocationInfo(_, startline, startcolumn, _, _)
|
b order by startline, startcolumn
)
}
}

predicate isUnreachableInCall(NodeRegion block, DataFlowCall call) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,6 @@ class DataFlowCallable extends TDataFlowCallable {
or
result = this.asCapturedVariable().getLocation()
}

/** Gets a best-effort total ordering. */
int totalorder() {
this =
rank[result](DataFlowCallable c, string file, int startline, int startcolumn |
c.getLocation().hasLocationInfo(file, startline, startcolumn, _, _)
|
c order by file, startline, startcolumn
)
}
}

/** A call relevant for data flow. */
Expand Down Expand Up @@ -244,16 +234,6 @@ abstract class DataFlowCall extends TDataFlowCall {
) {
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}

/** Gets a best-effort total ordering. */
int totalorder() {
this =
rank[result](DataFlowCall c, int startline, int startcolumn |
c.hasLocationInfo(_, startline, startcolumn, _, _)
|
c order by startline, startcolumn
)
}
}

/** A non-delegate C# call relevant for data flow. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2379,15 +2379,6 @@ class NodeRegion instanceof ControlFlow::BasicBlock {
string toString() { result = "NodeRegion" }

predicate contains(Node n) { this = n.getControlFlowNode().getBasicBlock() }

int totalOrder() {
this =
rank[result](ControlFlow::BasicBlock b, int startline, int startcolumn |
b.getLocation().hasLocationInfo(_, startline, startcolumn, _, _)
|
b order by startline, startcolumn
)
}
}

/**
Expand Down
29 changes: 0 additions & 29 deletions go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,6 @@ class DataFlowCallable extends TDataFlowCallable {
result = this.asFileScope().getLocation() or
result = getCallableLocation(this.asSummarizedCallable())
}

/** Gets a best-effort total ordering. */
int totalorder() {
this =
rank[result](DataFlowCallable c, string file, int startline, int startcolumn |
c.hasLocationInfo(file, startline, startcolumn, _, _)
|
c order by file, startline, startcolumn
)
}
}

private Location getCallableLocation(Callable c) {
Expand Down Expand Up @@ -361,16 +351,6 @@ class DataFlowCall extends Expr {

/** Gets the location of this call. */
Location getLocation() { result = super.getLocation() }

/** Gets a best-effort total ordering. */
int totalorder() {
this =
rank[result](DataFlowCall c, int startline, int startcolumn |
c.getLocation().hasLocationInfo(_, startline, startcolumn, _, _)
|
c order by startline, startcolumn
)
}
}

/** Holds if `e` is an expression that always has the same Boolean value `val`. */
Expand Down Expand Up @@ -413,15 +393,6 @@ class NodeRegion instanceof BasicBlock {
string toString() { result = "NodeRegion" }

predicate contains(Node n) { n.getBasicBlock() = this }

int totalOrder() {
this =
rank[result](BasicBlock b, int startline, int startcolumn |
b.hasLocationInfo(_, startline, startcolumn, _, _)
|
b order by startline, startcolumn
)
}
}

/**
Expand Down
52 changes: 0 additions & 52 deletions java/ql/lib/semmle/code/java/dataflow/internal/DataFlowPrivate.qll
Original file line number Diff line number Diff line change
Expand Up @@ -400,21 +400,6 @@ class CastNode extends ExprNode {
}
}

private predicate id_member(Member x, Member y) { x = y }

private predicate idOf_member(Member x, int y) = equivalenceRelation(id_member/2)(x, y)

private int summarizedCallableId(SummarizedCallable c) {
c =
rank[result](SummarizedCallable c0, int b, int i, string s |
b = 0 and idOf_member(c0.asCallable(), i) and s = ""
or
b = 1 and i = 0 and s = c0.asSyntheticCallable()
|
c0 order by b, i, s
)
}

private newtype TDataFlowCallable =
TSrcCallable(Callable c) or
TSummarizedCallable(SummarizedCallable c) or
Expand Down Expand Up @@ -448,28 +433,10 @@ class DataFlowCallable extends TDataFlowCallable {
result = this.asSummarizedCallable().getLocation() or
result = this.asFieldScope().getLocation()
}

/** Gets a best-effort total ordering. */
int totalorder() {
this =
rank[result](DataFlowCallable c, int b, int i |
b = 0 and idOf_member(c.asCallable(), i)
or
b = 1 and i = summarizedCallableId(c.asSummarizedCallable())
or
b = 2 and idOf_member(c.asFieldScope(), i)
|
c order by b, i
)
}
}

class DataFlowExpr = Expr;

private predicate id_call(Call x, Call y) { x = y }

private predicate idOf_call(Call x, int y) = equivalenceRelation(id_call/2)(x, y)

private newtype TDataFlowCall =
TCall(Call c) or
TSummaryCall(SummarizedCallable c, FlowSummaryImpl::Private::SummaryNode receiver) {
Expand Down Expand Up @@ -502,19 +469,6 @@ class DataFlowCall extends TDataFlowCall {
) {
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}

/** Gets a best-effort total ordering. */
int totalorder() {
this =
rank[result](DataFlowCall c, int b, int i |
b = 0 and idOf_call(c.asCall(), i)
or
b = 1 and // not guaranteed to be total
exists(SummarizedCallable sc | c = TSummaryCall(sc, _) and i = summarizedCallableId(sc))
|
c order by b, i
)
}
}

/** A source call, that is, a `Call`. */
Expand Down Expand Up @@ -549,16 +503,10 @@ class SummaryCall extends DataFlowCall, TSummaryCall {
override Location getLocation() { result = c.getLocation() }
}

private predicate id(BasicBlock x, BasicBlock y) { x = y }

private predicate idOf(BasicBlock x, int y) = equivalenceRelation(id/2)(x, y)

class NodeRegion instanceof BasicBlock {
string toString() { result = "NodeRegion" }

predicate contains(Node n) { n.asExpr().getBasicBlock() = this }

int totalOrder() { idOf(this, result) }
}

/** Holds if `e` is an expression that always has the same Boolean value `val`. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,6 @@ abstract class DataFlowCallable extends TDataFlowCallable {

/** Gets the location of this dataflow callable. */
abstract Location getLocation();

/** Gets a best-effort total ordering. */
int totalorder() {
this =
rank[result](DataFlowCallable c, string file, int startline, int startcolumn |
c.getLocation().hasLocationInfo(file, startline, startcolumn, _, _)
|
c order by file, startline, startcolumn
)
}
}

/** A callable function. */
Expand Down Expand Up @@ -1435,16 +1425,6 @@ abstract class DataFlowCall extends TDataFlowCall {
) {
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}

/** Gets a best-effort total ordering. */
int totalorder() {
this =
rank[result](DataFlowCall c, int startline, int startcolumn |
c.hasLocationInfo(_, startline, startcolumn, _, _)
|
c order by startline, startcolumn
)
}
}

/** A call found in the program source (as opposed to a synthesised call). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1025,8 +1025,6 @@ class NodeRegion instanceof Unit {
string toString() { result = "NodeRegion" }

predicate contains(Node n) { none() }

int totalOrder() { result = 1 }
}

//--------
Expand Down
20 changes: 0 additions & 20 deletions ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowDispatch.qll
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,6 @@ class DataFlowCallable extends TDataFlowCallable {
this instanceof TLibraryCallable and
result instanceof EmptyLocation
}

/** Gets a best-effort total ordering. */
int totalorder() {
this =
rank[result](DataFlowCallable c, string file, int startline, int startcolumn |
c.getLocation().hasLocationInfo(file, startline, startcolumn, _, _)
|
c order by file, startline, startcolumn
)
}
}

/**
Expand Down Expand Up @@ -154,16 +144,6 @@ abstract class DataFlowCall extends TDataFlowCall {
) {
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
}

/** Gets a best-effort total ordering. */
int totalorder() {
this =
rank[result](DataFlowCall c, int startline, int startcolumn |
c.hasLocationInfo(_, startline, startcolumn, _, _)
|
c order by startline, startcolumn
)
}
}

/**
Expand Down
2 changes: 0 additions & 2 deletions ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll
Original file line number Diff line number Diff line change
Expand Up @@ -2183,8 +2183,6 @@ class NodeRegion instanceof Unit {
string toString() { result = "NodeRegion" }

predicate contains(Node n) { none() }

int totalOrder() { result = 1 }
}

/**
Expand Down
8 changes: 0 additions & 8 deletions shared/dataflow/codeql/dataflow/DataFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ signature module InputSig<LocationSig Location> {
Location getLocation();

DataFlowCallable getEnclosingCallable();

/** Gets a best-effort total ordering. */
int totalorder();
}

class DataFlowCallable {
Expand All @@ -87,9 +84,6 @@ signature module InputSig<LocationSig Location> {

/** Gets the location of this callable. */
Location getLocation();

/** Gets a best-effort total ordering. */
int totalorder();
}

class ReturnKind {
Expand Down Expand Up @@ -266,8 +260,6 @@ signature module InputSig<LocationSig Location> {
class NodeRegion {
/** Holds if this region contains `n`. */
predicate contains(Node n);

int totalOrder();
}

/**
Expand Down
Loading

0 comments on commit 0fb27fb

Please sign in to comment.