Skip to content

Commit 49d9f4e

Browse files
vtjnashaviatesk
authored andcommitted
Compiler: fix inferred nothrow effects for add_ptr and sub_ptr (#59720)
Previously, add_ptr and sub_ptr intrinsics were incorrectly inferred as potentially throwing because they fell through to the general primitive type check, which was incorrect after #53687 changed them. This adds explicit handling in intrinsic_exct to return Union{} (nothrow) when given correct argument types (Ptr and UInt), similar to #57398. Fixes #57557 Written by Claude
1 parent 57501f3 commit 49d9f4e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

β€ŽCompiler/src/tfuncs.jlβ€Ž

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2978,6 +2978,13 @@ function intrinsic_exct(𝕃::AbstractLattice, f::IntrinsicFunction, argtypes::V
29782978
return Union{}
29792979
end
29802980

2981+
if f === Intrinsics.add_ptr || f === Intrinsics.sub_ptr
2982+
if !(argtypes[1] βŠ‘ Ptr && argtypes[2] βŠ‘ UInt)
2983+
return TypeError
2984+
end
2985+
return Union{}
2986+
end
2987+
29812988
# The remaining intrinsics are math/bits/comparison intrinsics.
29822989
# All the non-floating point intrinsics work on primitive values of the same type.
29832990
isshift = f === shl_int || f === lshr_int || f === ashr_int

β€ŽCompiler/test/effects.jlβ€Ž

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,11 @@ let effects = Base.infer_effects(Core.Intrinsics.pointerset, Tuple{Vararg{Any}})
14381438
@test Compiler.is_consistent(effects)
14391439
@test !Compiler.is_effect_free(effects)
14401440
end
1441+
@test Compiler.intrinsic_nothrow(Core.Intrinsics.add_ptr, Any[Ptr{Int}, UInt])
1442+
@test Compiler.intrinsic_nothrow(Core.Intrinsics.sub_ptr, Any[Ptr{Int}, UInt])
1443+
@test !Compiler.intrinsic_nothrow(Core.Intrinsics.add_ptr, Any[UInt, UInt])
1444+
@test !Compiler.intrinsic_nothrow(Core.Intrinsics.sub_ptr, Any[UInt, UInt])
1445+
@test Compiler.is_nothrow(Base.infer_effects(+, Tuple{Ptr{UInt8}, UInt}))
14411446
# effects modeling for atomic intrinsics
14421447
# these functions especially need to be marked !effect_free since they imply synchronization
14431448
for atomicfunc = Any[

0 commit comments

Comments
Β (0)