Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
b1ffafb1
Commit
b1ffafb1
authored
Dec 24, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix constant folding of PrimaryCmpNode operands
parent
10d51a67
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
+30
-2
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+2
-2
tests/run/constant_folding.py
tests/run/constant_folding.py
+28
-0
No files found.
Cython/Compiler/Optimize.py
View file @
b1ffafb1
...
...
@@ -3343,12 +3343,12 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
def
visit_PrimaryCmpNode
(
self
,
node
):
# calculate constant partial results in the comparison cascade
self
.
visitchildren
(
node
,
[
'operand1'
])
left_node
=
node
.
operand1
self
.
_calculate_const
(
left_node
)
cmp_node
=
node
while
cmp_node
is
not
None
:
self
.
visitchildren
(
cmp_node
,
[
'operand2'
])
right_node
=
cmp_node
.
operand2
self
.
_calculate_const
(
right_node
)
cmp_node
.
constant_result
=
not_a_constant
if
left_node
.
has_constant_result
()
and
right_node
.
has_constant_result
():
try
:
...
...
tests/run/constant_folding.py
View file @
b1ffafb1
...
...
@@ -428,3 +428,31 @@ def cascaded_cmp_with_partial_constants_and_false_end(a, b, c):
"""
x
=
1
<
2
<
a
<
4
<
5
<
b
<
7
<
7
<
c
return
x
@
cython
.
test_assert_path_exists
(
'//PrimaryCmpNode'
,
'//PrimaryCmpNode//IntNode'
,
'//PrimaryCmpNode//IntNode[@value = "0"]'
,
'//PrimaryCmpNode//IntNode[@value = "4294967296"]'
,
)
@
cython
.
test_fail_if_path_exists
(
'//PrimaryCmpNode//IntBinopNode'
,
'//PrimaryCmpNode//IntNode[@value = "1"]'
,
'//PrimaryCmpNode//IntNode[@value = "32"]'
,
)
def
const_in_binop
(
v
):
"""
>>> const_in_binop(-1)
1
>>> const_in_binop(0)
0
>>> const_in_binop(1 << 32)
1
>>> const_in_binop(1 << 32 - 1)
0
"""
if
v
<
0
or
v
>=
(
1L
<<
32
):
return
1
else
:
return
0
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment