Commit cc8a670b authored by Stefan Behnel's avatar Stefan Behnel

discard constant True condition in while loops

parent ff18a041
...@@ -904,7 +904,8 @@ class ControlFlowAnalysis(CythonTransform): ...@@ -904,7 +904,8 @@ class ControlFlowAnalysis(CythonTransform):
next_block = self.flow.newblock() next_block = self.flow.newblock()
# Condition block # Condition block
self.flow.loops.append(LoopDescr(next_block, condition_block)) self.flow.loops.append(LoopDescr(next_block, condition_block))
self._visit(node.condition) if node.condition:
self._visit(node.condition)
# Body block # Body block
self.flow.nextblock() self.flow.nextblock()
self._visit(node.body) self._visit(node.body)
......
...@@ -3382,6 +3382,7 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations): ...@@ -3382,6 +3382,7 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
self.visitchildren(node) self.visitchildren(node)
if node.condition.has_constant_result(): if node.condition.has_constant_result():
if node.condition.constant_result: if node.condition.constant_result:
node.condition = None
node.else_clause = None node.else_clause = None
else: else:
return node.else_clause return node.else_clause
......
...@@ -192,6 +192,9 @@ def while_false_else(): ...@@ -192,6 +192,9 @@ def while_false_else():
@cython.test_fail_if_path_exists( @cython.test_fail_if_path_exists(
"//WhileStatNode//PrintStatNode", "//WhileStatNode//PrintStatNode",
"//WhileStatNode//PrimaryCmpNode",
"//WhileStatNode/BoolNode",
"//WhileStatNode/IntNode",
) )
@cython.test_assert_path_exists( @cython.test_assert_path_exists(
"//WhileStatNode", "//WhileStatNode",
......
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