Commit 4b446b49 authored by Stefan Behnel's avatar Stefan Behnel

patch cleanup and test fix (avoid uninitialised variable)

--HG--
rename : tests/bugs/rangeOptimization_T203.pyx => tests/run/range_optimisation_T203.pyx
parent fc263982
...@@ -3967,26 +3967,21 @@ class ForFromStatNode(LoopNode, StatNode): ...@@ -3967,26 +3967,21 @@ class ForFromStatNode(LoopNode, StatNode):
decop = "%s=%s" % (decop[0], step) decop = "%s=%s" % (decop[0], step)
loopvar_name = self.loopvar_node.result() loopvar_name = self.loopvar_node.result()
if from_range: if from_range:
temp_range_bound = code.funcstate.allocate_temp(self.bound2.type, manage_ref=False) range_bound = code.funcstate.allocate_temp(self.bound2.type, manage_ref=False)
code.putln("%s = %s;" % (temp_range_bound, self.bound2.result())) code.putln("%s = %s;" % (range_bound, self.bound2.result()))
# Skip the loop entirely (and avoid assigning to the loopvar) if # Skip the loop entirely (and avoid assigning to the loopvar) if
# the loop is empty: # the loop is empty:
code.putln("if (%s%s %s %s) {" % ( code.putln("if (%s%s %s %s) {" % (
self.bound1.result(), offset, self.relation2, temp_range_bound self.bound1.result(), offset, self.relation2, range_bound
)) ))
code.putln(
"for (%s = %s%s; %s %s %s; %s%s) {" % (
loopvar_name,
self.bound1.result(), offset,
loopvar_name, self.relation2, temp_range_bound,
loopvar_name, incop))
else: else:
code.putln( range_bound = self.bound2.result()
"for (%s = %s%s; %s %s %s; %s%s) {" % ( code.putln(
loopvar_name, "for (%s = %s%s; %s %s %s; %s%s) {" % (
self.bound1.result(), offset, loopvar_name,
loopvar_name, self.relation2, self.bound2.result(), self.bound1.result(), offset,
loopvar_name, incop)) loopvar_name, self.relation2, range_bound,
loopvar_name, incop))
if self.py_loopvar_node: if self.py_loopvar_node:
self.py_loopvar_node.generate_evaluation_code(code) self.py_loopvar_node.generate_evaluation_code(code)
self.target.generate_assignment_code(self.py_loopvar_node, code) self.target.generate_assignment_code(self.py_loopvar_node, code)
...@@ -3997,7 +3992,7 @@ class ForFromStatNode(LoopNode, StatNode): ...@@ -3997,7 +3992,7 @@ class ForFromStatNode(LoopNode, StatNode):
code.putln("} %s%s;" % (loopvar_name, decop)) code.putln("} %s%s;" % (loopvar_name, decop))
# End the outer if statement: # End the outer if statement:
code.putln("} /* end if */") code.putln("} /* end if */")
code.funcstate.release_temp(temp_range_bound) code.funcstate.release_temp(range_bound)
else: else:
code.putln("}") code.putln("}")
break_label = code.break_label break_label = code.break_label
......
...@@ -53,7 +53,7 @@ cdef int g(): ...@@ -53,7 +53,7 @@ cdef int g():
return 3 return 3
def f(): def f():
cdef int i cdef int i = -1
for i in range(g()): for i in range(g()):
print i print i
print i print i
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment