Merge pull request #19483 from yoff/ruby/more-capturedExitRead

Ruby: More captured exit read nodes
This commit is contained in:
yoff
2025-05-14 11:35:04 +02:00
committed by GitHub
3 changed files with 34 additions and 1 deletions

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* 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.

View File

@@ -106,7 +106,6 @@ private predicate writesCapturedVariable(Cfg::BasicBlock bb, LocalVariable v) {
* at index `i` in exit block `bb`.
*/
private predicate capturedExitRead(Cfg::AnnotatedExitBasicBlock bb, int i, LocalVariable v) {
bb.isNormal() and
writesCapturedVariable(bb.getAPredecessor*(), v) and
i = bb.length()
}

View File

@@ -34,3 +34,33 @@ class Sub < Sup
super
end
end
def do_twice
yield
yield
end
def get_done_twice x
do_twice do
print x
x += 1 # OK - the block is executed twice
end
end
def retry_once
yield
rescue
yield
end
def get_retried x
retry_once do
print x
if x < 1
begin
x += 1 # OK - the block may be executed again
raise StandardError
end
end
end
end