Skip to content

Commit c841b5f

Browse files
authored
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 968b16c commit c841b5f

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
@@ -3017,6 +3017,13 @@ function intrinsic_exct(𝕃::AbstractLattice, f::IntrinsicFunction, argtypes::V
30173017
return Union{}
30183018
end
30193019

3020+
if f === Intrinsics.add_ptr || f === Intrinsics.sub_ptr
3021+
if !(argtypes[1] Ptr && argtypes[2] UInt)
3022+
return TypeError
3023+
end
3024+
return Union{}
3025+
end
3026+
30203027
# The remaining intrinsics are math/bits/comparison intrinsics.
30213028
# All the non-floating point intrinsics work on primitive values of the same type.
30223029
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
@@ -1440,6 +1440,11 @@ let effects = Base.infer_effects(Core.Intrinsics.pointerset, Tuple{Vararg{Any}})
14401440
@test Compiler.is_consistent(effects)
14411441
@test !Compiler.is_effect_free(effects)
14421442
end
1443+
@test Compiler.intrinsic_nothrow(Core.Intrinsics.add_ptr, Any[Ptr{Int}, UInt])
1444+
@test Compiler.intrinsic_nothrow(Core.Intrinsics.sub_ptr, Any[Ptr{Int}, UInt])
1445+
@test !Compiler.intrinsic_nothrow(Core.Intrinsics.add_ptr, Any[UInt, UInt])
1446+
@test !Compiler.intrinsic_nothrow(Core.Intrinsics.sub_ptr, Any[UInt, UInt])
1447+
@test Compiler.is_nothrow(Base.infer_effects(+, Tuple{Ptr{UInt8}, UInt}))
14431448
# effects modeling for atomic intrinsics
14441449
# these functions especially need to be marked !effect_free since they imply synchronization
14451450
for atomicfunc = Any[

0 commit comments

Comments
 (0)