Skip to content

Commit 6efa595

Browse files
authored
Merge pull request github#7688 from hvitved/dataflow/required-component-stack
Data flow: Restructure `RequiredSummaryComponentStack`
2 parents b59fd40 + 64f1963 commit 6efa595

File tree

5 files changed

+32
-42
lines changed

5 files changed

+32
-42
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/FlowSummary.qll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,11 @@ private class SummarizedCallableDefaultClearsContent extends Impl::Public::Summa
153153
class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStack;
154154

155155
private class RecordConstructorFlowRequiredSummaryComponentStack extends RequiredSummaryComponentStack {
156-
private SummaryComponent head;
157-
158-
RecordConstructorFlowRequiredSummaryComponentStack() {
156+
override predicate required(SummaryComponent head, SummaryComponentStack tail) {
159157
exists(Property p |
160158
recordConstructorFlow(_, _, p) and
161159
head = SummaryComponent::property(p) and
162-
this = SummaryComponentStack::return()
160+
tail = SummaryComponentStack::return()
163161
)
164162
}
165-
166-
override predicate required(SummaryComponent c) { c = head }
167163
}

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ module Public {
175175
* A class that exists for QL technical reasons only (the IPA type used
176176
* to represent component stacks needs to be bounded).
177177
*/
178-
abstract class RequiredSummaryComponentStack extends SummaryComponentStack {
178+
class RequiredSummaryComponentStack extends Unit {
179179
/**
180180
* Holds if the stack obtained by pushing `head` onto `tail` is required.
181181
*/
182-
abstract predicate required(SummaryComponent c);
182+
abstract predicate required(SummaryComponent head, SummaryComponentStack tail);
183183
}
184184

185185
/** A callable with a flow summary. */
@@ -240,9 +240,9 @@ module Private {
240240
newtype TSummaryComponentStack =
241241
TSingletonSummaryComponentStack(SummaryComponent c) or
242242
TConsSummaryComponentStack(SummaryComponent head, SummaryComponentStack tail) {
243-
tail.(RequiredSummaryComponentStack).required(head)
243+
any(RequiredSummaryComponentStack x).required(head, tail)
244244
or
245-
tail.(RequiredSummaryComponentStack).required(TParameterSummaryComponent(_)) and
245+
any(RequiredSummaryComponentStack x).required(TParameterSummaryComponent(_), tail) and
246246
head = thisParam()
247247
or
248248
derivedFluentFlowPush(_, _, _, head, tail, _)
@@ -890,9 +890,9 @@ module Private {
890890
}
891891

892892
private class MkStack extends RequiredSummaryComponentStack {
893-
MkStack() { interpretSpec(_, _, _, this) }
894-
895-
override predicate required(SummaryComponent c) { interpretSpec(_, _, c, this) }
893+
override predicate required(SummaryComponent head, SummaryComponentStack tail) {
894+
interpretSpec(_, _, head, tail)
895+
}
896896
}
897897

898898
private class SummarizedCallableExternal extends SummarizedCallable {

csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,10 @@ module EntityFramework {
9191
abstract class EFSummarizedCallable extends SummarizedCallable { }
9292

9393
private class DbSetAddOrUpdateRequiredSummaryComponentStack extends RequiredSummaryComponentStack {
94-
private SummaryComponent head;
95-
96-
DbSetAddOrUpdateRequiredSummaryComponentStack() {
97-
this = SummaryComponentStack::argument([-1, 0]) and
98-
head = SummaryComponent::element()
94+
override predicate required(SummaryComponent head, SummaryComponentStack tail) {
95+
head = SummaryComponent::element() and
96+
tail = SummaryComponentStack::argument([-1, 0])
9997
}
100-
101-
override predicate required(SummaryComponent c) { c = head }
10298
}
10399

104100
private class DbSetAddOrUpdate extends EFSummarizedCallable {
@@ -462,14 +458,12 @@ module EntityFramework {
462458
}
463459

464460
private class DbContextSaveChangesRequiredSummaryComponentStack extends RequiredSummaryComponentStack {
465-
private Content head;
466-
467-
DbContextSaveChangesRequiredSummaryComponentStack() {
468-
any(DbContextClass c).requiresComponentStackIn(head, _, this, _)
469-
or
470-
any(DbContextClass c).requiresComponentStackOut(head, _, this, _)
461+
override predicate required(SummaryComponent head, SummaryComponentStack tail) {
462+
exists(Content c | head = SummaryComponent::content(c) |
463+
any(DbContextClass cls).requiresComponentStackIn(c, _, tail, _)
464+
or
465+
any(DbContextClass cls).requiresComponentStackOut(c, _, tail, _)
466+
)
471467
}
472-
473-
override predicate required(SummaryComponent c) { c = SummaryComponent::content(head) }
474468
}
475469
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ module Public {
175175
* A class that exists for QL technical reasons only (the IPA type used
176176
* to represent component stacks needs to be bounded).
177177
*/
178-
abstract class RequiredSummaryComponentStack extends SummaryComponentStack {
178+
class RequiredSummaryComponentStack extends Unit {
179179
/**
180180
* Holds if the stack obtained by pushing `head` onto `tail` is required.
181181
*/
182-
abstract predicate required(SummaryComponent c);
182+
abstract predicate required(SummaryComponent head, SummaryComponentStack tail);
183183
}
184184

185185
/** A callable with a flow summary. */
@@ -240,9 +240,9 @@ module Private {
240240
newtype TSummaryComponentStack =
241241
TSingletonSummaryComponentStack(SummaryComponent c) or
242242
TConsSummaryComponentStack(SummaryComponent head, SummaryComponentStack tail) {
243-
tail.(RequiredSummaryComponentStack).required(head)
243+
any(RequiredSummaryComponentStack x).required(head, tail)
244244
or
245-
tail.(RequiredSummaryComponentStack).required(TParameterSummaryComponent(_)) and
245+
any(RequiredSummaryComponentStack x).required(TParameterSummaryComponent(_), tail) and
246246
head = thisParam()
247247
or
248248
derivedFluentFlowPush(_, _, _, head, tail, _)
@@ -890,9 +890,9 @@ module Private {
890890
}
891891

892892
private class MkStack extends RequiredSummaryComponentStack {
893-
MkStack() { interpretSpec(_, _, _, this) }
894-
895-
override predicate required(SummaryComponent c) { interpretSpec(_, _, c, this) }
893+
override predicate required(SummaryComponent head, SummaryComponentStack tail) {
894+
interpretSpec(_, _, head, tail)
895+
}
896896
}
897897

898898
private class SummarizedCallableExternal extends SummarizedCallable {

ruby/ql/lib/codeql/ruby/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ module Public {
175175
* A class that exists for QL technical reasons only (the IPA type used
176176
* to represent component stacks needs to be bounded).
177177
*/
178-
abstract class RequiredSummaryComponentStack extends SummaryComponentStack {
178+
class RequiredSummaryComponentStack extends Unit {
179179
/**
180180
* Holds if the stack obtained by pushing `head` onto `tail` is required.
181181
*/
182-
abstract predicate required(SummaryComponent c);
182+
abstract predicate required(SummaryComponent head, SummaryComponentStack tail);
183183
}
184184

185185
/** A callable with a flow summary. */
@@ -240,9 +240,9 @@ module Private {
240240
newtype TSummaryComponentStack =
241241
TSingletonSummaryComponentStack(SummaryComponent c) or
242242
TConsSummaryComponentStack(SummaryComponent head, SummaryComponentStack tail) {
243-
tail.(RequiredSummaryComponentStack).required(head)
243+
any(RequiredSummaryComponentStack x).required(head, tail)
244244
or
245-
tail.(RequiredSummaryComponentStack).required(TParameterSummaryComponent(_)) and
245+
any(RequiredSummaryComponentStack x).required(TParameterSummaryComponent(_), tail) and
246246
head = thisParam()
247247
or
248248
derivedFluentFlowPush(_, _, _, head, tail, _)
@@ -890,9 +890,9 @@ module Private {
890890
}
891891

892892
private class MkStack extends RequiredSummaryComponentStack {
893-
MkStack() { interpretSpec(_, _, _, this) }
894-
895-
override predicate required(SummaryComponent c) { interpretSpec(_, _, c, this) }
893+
override predicate required(SummaryComponent head, SummaryComponentStack tail) {
894+
interpretSpec(_, _, head, tail)
895+
}
896896
}
897897

898898
private class SummarizedCallableExternal extends SummarizedCallable {

0 commit comments

Comments
 (0)