Skip to content

Commit 231f267

Browse files
JeffBezansonjohanmon
authored andcommitted
fix JuliaLang#34288, method errors in nothrow inference of division intrinsics (JuliaLang#41178)
1 parent 68d0fd1 commit 231f267

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

base/compiler/tfuncs.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,10 @@ end
15681568

15691569
# Query whether the given intrinsic is nothrow
15701570

1571+
_iszero(x) = x === Intrinsics.xor_int(x, x)
1572+
_isneg1(x) = _iszero(Intrinsics.not_int(x))
1573+
_istypemin(x) = !_iszero(x) && Intrinsics.neg_int(x) === x
1574+
15711575
function intrinsic_nothrow(f::IntrinsicFunction, argtypes::Array{Any, 1})
15721576
# First check that we have the correct number of arguments
15731577
iidx = Int(reinterpret(Int32, f::IntrinsicFunction)) + 1
@@ -1594,11 +1598,10 @@ function intrinsic_nothrow(f::IntrinsicFunction, argtypes::Array{Any, 1})
15941598
return false
15951599
end
15961600
den_val = argtypes[2].val
1597-
den_val !== zero(typeof(den_val)) || return false
1601+
_iszero(den_val) && return false
15981602
f !== Intrinsics.checked_sdiv_int && return true
15991603
# Nothrow as long as we additionally don't do typemin(T)/-1
1600-
return den_val !== -1 || (isa(argtypes[1], Const) &&
1601-
argtypes[1].val !== typemin(typeof(den_val)))
1604+
return !_isneg1(den_val) || (isa(argtypes[1], Const) && !_istypemin(argtypes[1].val))
16021605
end
16031606
if f === Intrinsics.pointerref
16041607
# Nothrow as long as the types are ok. N.B.: dereferencability is not

test/compiler/inference.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3319,3 +3319,7 @@ end |> first === Tuple{Int, String}
33193319
# issue #40804
33203320
@test Base.return_types(()) do; ===(); end == Any[Union{}]
33213321
@test Base.return_types(()) do; typeassert(); end == Any[Union{}]
3322+
3323+
primitive type UInt24ish 24 end
3324+
f34288(x) = Core.Intrinsics.checked_sdiv_int(x, Core.Intrinsics.trunc_int(UInt24ish, 0))
3325+
@test Base.return_types(f34288, (UInt24ish,)) == Any[UInt24ish]

0 commit comments

Comments
 (0)