Skip to content

Commit fe0157d

Browse files
committed
Also perform uninitialized check on temp locals.
Fixes #4251.
1 parent 9eee303 commit fe0157d

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

core/src/main/java/org/jruby/ir/dataflow/analyses/DefinedVariableNode.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.jruby.ir.instructions.ResultInstr;
88
import org.jruby.ir.operands.LocalVariable;
99
import org.jruby.ir.operands.Operand;
10+
import org.jruby.ir.operands.TemporaryLocalVariable;
11+
import org.jruby.ir.operands.TemporaryVariable;
1012
import org.jruby.ir.operands.Variable;
1113
import org.jruby.ir.operands.WrappedIRClosure;
1214
import org.jruby.ir.IRClosure;
@@ -79,7 +81,11 @@ public void applyTransferFunction(Instr i) {
7981
// Variables that belong to outer scopes should always
8082
// be considered defined.
8183
for (Variable v: i.getUsedVariables()) {
82-
if (v instanceof LocalVariable && ((LocalVariable)v).getScopeDepth() > 0) {
84+
if (v instanceof LocalVariable) {
85+
if (((LocalVariable)v).getScopeDepth() > 0) {
86+
tmp.set(problem.getDFVar(v));
87+
}
88+
} else if (v instanceof TemporaryLocalVariable) {
8389
tmp.set(problem.getDFVar(v));
8490
}
8591
}
@@ -116,17 +122,22 @@ public void identifyInits(Set<Variable> undefinedVars) {
116122
initSolution();
117123
for (Instr i: basicBlock.getInstrs()) {
118124
for (Variable v: i.getUsedVariables()) {
119-
LocalVariable lv;
120125
if (!v.isSelf()) {
121126
if (v instanceof LocalVariable) {
122-
lv = (LocalVariable)v;
127+
LocalVariable lv = (LocalVariable) v;
123128
// Variables that belong to outer scopes
124129
// are considered already defined.
125130
if (lv.getScopeDepth() < parentScopeDepth && !tmp.get(problem.getDFVar(v))) {
126131
// We want lv suitable for initializing in this scope
127132
undefinedVars.add(lv.getScopeDepth() == 0 ? lv : lv.cloneForDepth(0));
128133
}
129134
tmp.set(problem.getDFVar(lv));
135+
} else if (v instanceof TemporaryLocalVariable) {
136+
TemporaryLocalVariable tlv = (TemporaryLocalVariable) v;
137+
if (!tmp.get(problem.getDFVar(v))) {
138+
undefinedVars.add(tlv);
139+
}
140+
tmp.set(problem.getDFVar(tlv));
130141
}
131142
}
132143
}

0 commit comments

Comments
 (0)