Skip to content

Commit

Permalink
[mypyc] Fix test case testI64Cast on 32-bit architectures (python#14691)
Browse files Browse the repository at this point in the history
Add 64-bit and 32-bit variants of the test.

Fixes python#14633.
  • Loading branch information
JukkaL authored and ilinum committed Feb 14, 2023
1 parent 83db085 commit e9eb3c5
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion mypyc/test-data/irbuild-i64.test
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,46 @@ def f5():
L0:
return 4

[case testI64Cast]
[case testI64OperationsWithBools]
from mypy_extensions import i64

# TODO: Other mixed operations

def add_bool_to_int(n: i64, b: bool) -> i64:
return n + b

def compare_bool_to_i64(n: i64, b: bool) -> bool:
if n == b:
return b != n
return True
[out]
def add_bool_to_int(n, b):
n :: int64
b :: bool
r0, r1 :: int64
L0:
r0 = extend b: builtins.bool to int64
r1 = n + r0
return r1
def compare_bool_to_i64(n, b):
n :: int64
b :: bool
r0 :: int64
r1 :: bit
r2 :: int64
r3 :: bit
L0:
r0 = extend b: builtins.bool to int64
r1 = n == r0
if r1 goto L1 else goto L2 :: bool
L1:
r2 = extend b: builtins.bool to int64
r3 = r2 != n
return r3
L2:
return 1

[case testI64Cast_64bit]
from typing import cast
from mypy_extensions import i64

Expand Down Expand Up @@ -1772,6 +1811,39 @@ L2:
L3:
return r3

[case testI64Cast_32bit]
from typing import cast
from mypy_extensions import i64

def cast_int(x: int) -> i64:
return cast(i64, x)
[out]
def cast_int(x):
x :: int
r0 :: native_int
r1 :: bit
r2, r3, r4 :: int64
r5 :: ptr
r6 :: c_ptr
r7 :: int64
L0:
r0 = x & 1
r1 = r0 == 0
if r1 goto L1 else goto L2 :: bool
L1:
r2 = extend signed x: builtins.int to int64
r3 = r2 >> 1
r4 = r3
goto L3
L2:
r5 = x ^ 1
r6 = r5
r7 = CPyLong_AsInt64(r6)
r4 = r7
keep_alive x
L3:
return r4

[case testI64ExplicitConversionFromVariousTypes]
from mypy_extensions import i64

Expand Down

0 comments on commit e9eb3c5

Please sign in to comment.