Skip to content

Commit 3fa563b

Browse files
authored
Merge pull request #19483 from yoff/ruby/more-capturedExitRead
Ruby: More captured exit read nodes
2 parents 7531a95 + 3fcd46e commit 3fa563b

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Captured variables are currently considered live when the capturing function exits normally. Now they are also considered live when the capturing function exits via an exception.

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

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ private predicate writesCapturedVariable(Cfg::BasicBlock bb, LocalVariable v) {
106106
* at index `i` in exit block `bb`.
107107
*/
108108
private predicate capturedExitRead(Cfg::AnnotatedExitBasicBlock bb, int i, LocalVariable v) {
109-
bb.isNormal() and
110109
writesCapturedVariable(bb.getAPredecessor*(), v) and
111110
i = bb.length()
112111
}

ruby/ql/test/query-tests/variables/DeadStoreOfLocal/DeadStoreOfLocal.rb

+30
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,34 @@ def m(y)
3333
y = 3 # OK - the call to `super` sees the value of `y``
3434
super
3535
end
36+
end
37+
38+
def do_twice
39+
yield
40+
yield
41+
end
42+
43+
def get_done_twice x
44+
do_twice do
45+
print x
46+
x += 1 # OK - the block is executed twice
47+
end
48+
end
49+
50+
def retry_once
51+
yield
52+
rescue
53+
yield
54+
end
55+
56+
def get_retried x
57+
retry_once do
58+
print x
59+
if x < 1
60+
begin
61+
x += 1 # OK - the block may be executed again
62+
raise StandardError
63+
end
64+
end
65+
end
3666
end

0 commit comments

Comments
 (0)