Skip to content

Commit

Permalink
address review
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardssmith committed Dec 12, 2024
1 parent aeaf45e commit 4a2f5f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions Compiler/src/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2244,21 +2244,30 @@ end
return boundscheck Bool && memtype GenericMemoryRef && order Symbol
end

@nospecs function memorynew_nothrow(argtypes::Vector{Any})
if !(argtypes[1] isa Const && argtypes[2] isa Const)
return false
end
MemT = argtypes[1].val
if !(isconcretetype(MemT) && MemT <: GenericMemory)
return false
end
len = argtypes[2].val
if !(len isa Int && 0 <= len < typemax(Int))
return false
end
elsz = datatype_layoutsize(MemT)
overflows = checked_smul_int(len, elsz)[2]
return !overflows
end
# Query whether the given builtin is guaranteed not to throw given the `argtypes`.
# `argtypes` can be assumed not to contain varargs.
function _builtin_nothrow(𝕃::AbstractLattice, @nospecialize(f::Builtin), argtypes::Vector{Any},
@nospecialize(rt))
= partialorder(𝕃)
na = length(argtypes)
if f === Core.memorynew
argtypes[1] isa Const && argtypes[2] isa Const || return false
MemT = argtypes[1].val
isconcretetype(MemT) && MemT <: GenericMemory || return false
len = argtypes[2].val
len isa Int && 0 <= len < typemax(Int) || return false
elsz = datatype_layoutsize(MemT)
checked_smul_int(len, elsz)[2] && return false
return true
return memorynew_nothrow(argtypes)
elseif f === memoryrefnew
return memoryref_builtin_common_nothrow(argtypes)
elseif f === memoryrefoffset
Expand Down
2 changes: 1 addition & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ static const auto &builtin_func_map() {
{ jl_f_nfields_addr, new JuliaFunction<>{XSTR(jl_f_nfields), get_func_sig, get_func_attrs} },
{ jl_f__expr_addr, new JuliaFunction<>{XSTR(jl_f__expr), get_func_sig, get_func_attrs} },
{ jl_f__typevar_addr, new JuliaFunction<>{XSTR(jl_f__typevar), get_func_sig, get_func_attrs} },
{ jl_f_memorynew_addr, new JuliaFunction<>{XSTR(jl_f_memorynew), get_func_sig, get_func_attrs} },
{ jl_f_memorynew_addr, new JuliaFunction<>{XSTR(jl_f_memorynew), get_func_sig, get_func_attrs} },
{ jl_f_memoryref_addr, new JuliaFunction<>{XSTR(jl_f_memoryref), get_func_sig, get_func_attrs} },
{ jl_f_memoryrefoffset_addr, new JuliaFunction<>{XSTR(jl_f_memoryrefoffset), get_func_sig, get_func_attrs} },
{ jl_f_memoryrefset_addr, new JuliaFunction<>{XSTR(jl_f_memoryrefset), get_func_sig, get_func_attrs} },
Expand Down

0 comments on commit 4a2f5f3

Please sign in to comment.