Skip to content

Commit b13b2ce

Browse files
committed
Ruby: fix join order when building append relation
1 parent 3498a04 commit b13b2ce

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

ruby/ql/lib/codeql/ruby/typetracking/TypeTracker.qll

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ private module Cached {
1616
LoadStep(TypeTrackerContentSet contents) or
1717
JumpStep()
1818

19+
pragma[nomagic]
20+
private TypeTracker noContentTypeTracker(boolean hasCall) {
21+
result = MkTypeTracker(hasCall, noContent())
22+
}
23+
1924
/** Gets the summary resulting from appending `step` to type-tracking summary `tt`. */
2025
cached
2126
TypeTracker append(TypeTracker tt, StepSummary step) {
@@ -28,21 +33,24 @@ private module Cached {
2833
or
2934
step = ReturnStep() and hasCall = false and result = tt
3035
or
31-
exists(TypeTrackerContentSet contents |
32-
step = LoadStep(contents) and
33-
currentContent = contents.getAReadContent() and
34-
result = MkTypeTracker(hasCall, noContent())
35-
)
36-
or
37-
exists(TypeTrackerContentSet contents |
38-
step = StoreStep(contents) and
39-
currentContent = noContent() and
40-
result = MkTypeTracker(hasCall, contents.getAStoreContent())
41-
)
42-
or
4336
step = JumpStep() and
4437
result = MkTypeTracker(false, currentContent)
4538
)
39+
or
40+
exists(TypeTrackerContentSet contents, boolean hasCall |
41+
step = LoadStep(pragma[only_bind_into](contents)) and
42+
tt = MkTypeTracker(hasCall, contents.getAReadContent()) and
43+
result = noContentTypeTracker(hasCall)
44+
or
45+
step = StoreStep(pragma[only_bind_into](contents)) and
46+
tt = noContentTypeTracker(hasCall) and
47+
result = MkTypeTracker(hasCall, contents.getAStoreContent())
48+
)
49+
}
50+
51+
pragma[nomagic]
52+
private TypeBackTracker noContentTypeBackTracker(boolean hasReturn) {
53+
result = MkTypeBackTracker(hasReturn, noContent())
4654
}
4755

4856
/** Gets the summary resulting from prepending `step` to this type-tracking summary. */
@@ -57,21 +65,19 @@ private module Cached {
5765
or
5866
step = ReturnStep() and result = MkTypeBackTracker(true, content)
5967
or
60-
exists(TypeTrackerContentSet contents |
61-
step = LoadStep(contents) and
62-
content = noContent() and
63-
result = MkTypeBackTracker(hasReturn, contents.getAStoreContent())
64-
)
65-
or
66-
exists(TypeTrackerContentSet contents |
67-
step = StoreStep(contents) and
68-
content = contents.getAReadContent() and
69-
result = MkTypeBackTracker(hasReturn, noContent())
70-
)
71-
or
7268
step = JumpStep() and
7369
result = MkTypeBackTracker(false, content)
7470
)
71+
or
72+
exists(TypeTrackerContentSet contents, boolean hasReturn |
73+
step = StoreStep(pragma[only_bind_into](contents)) and
74+
tbt = MkTypeBackTracker(hasReturn, contents.getAReadContent()) and
75+
result = noContentTypeBackTracker(hasReturn)
76+
or
77+
step = LoadStep(pragma[only_bind_into](contents)) and
78+
tbt = noContentTypeBackTracker(hasReturn) and
79+
result = MkTypeBackTracker(hasReturn, contents.getAStoreContent())
80+
)
7581
}
7682

7783
/**

0 commit comments

Comments
 (0)