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