Skip to content

Commit

Permalink
Fix handling of Array argument type in ccall.
Browse files Browse the repository at this point in the history
Fixes #17204

(cherry picked from commit 8536543)
ref #17237
  • Loading branch information
yuyichao authored and tkelman committed Sep 13, 2016
1 parent 9d6006c commit d45443f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/abi_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ static Type *classify_arg(jl_value_t *ty, bool *fpreg, bool *onstack,

bool use_sret(AbiState*, jl_value_t *ty)
{
// Assume jl_is_datatype(ty) && !jl_is_abstracttype(ty)
// Assume (jl_is_datatype(ty) && !jl_is_abstracttype(ty) &&
// !jl_is_array_type(ty))
// Section 5.5
// If the type, T, of the result of a function is such that
//
Expand All @@ -320,7 +321,7 @@ bool use_sret(AbiState*, jl_value_t *ty)

Type *preferred_llvm_type(jl_value_t *ty, bool)
{
if (!jl_is_datatype(ty) || jl_is_abstracttype(ty))
if (!jl_is_datatype(ty) || jl_is_abstracttype(ty) || jl_is_array_type(ty))
return NULL;
jl_datatype_t *dt = (jl_datatype_t*)ty;
if (Type *fptype = get_llvm_fptype(dt))
Expand Down
5 changes: 3 additions & 2 deletions src/abi_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ static void classify_return_arg(jl_value_t *ty, bool *reg,

bool use_sret(AbiState *state, jl_value_t *ty)
{
// Assume jl_is_datatype(ty) && !jl_is_abstracttype(ty)
// Assume (jl_is_datatype(ty) && !jl_is_abstracttype(ty) &&
// !jl_is_array_type(ty))

bool reg = false;
bool onstack = false;
Expand Down Expand Up @@ -253,7 +254,7 @@ static void classify_arg(jl_value_t *ty, bool *reg,

Type *preferred_llvm_type(jl_value_t *ty, bool isret)
{
if (!jl_is_datatype(ty) || jl_is_abstracttype(ty))
if (!jl_is_datatype(ty) || jl_is_abstracttype(ty) || jl_is_array_type(ty))
return NULL;
jl_datatype_t *dt = (jl_datatype_t*)ty;

Expand Down
4 changes: 3 additions & 1 deletion src/abi_win64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const AbiState default_abi_state = {};

bool use_sret(AbiState *state, jl_value_t *ty)
{
if(!jl_is_datatype(ty) || jl_is_abstracttype(ty) || jl_is_cpointer_type(ty) || jl_is_array_type(ty))
// Assume (jl_is_datatype(ty) && !jl_is_abstracttype(ty) &&
// !jl_is_array_type(ty))
if (jl_is_cpointer_type(ty))
return false;
size_t size = jl_datatype_size(ty);
if (size <= 8)
Expand Down
4 changes: 3 additions & 1 deletion src/abi_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ inline bool is_complex128(jl_value_t *ty)

bool use_sret(AbiState *state, jl_value_t *ty)
{
if (!jl_is_datatype(ty) || jl_is_abstracttype(ty) || jl_is_cpointer_type(ty) || jl_is_array_type(ty))
// Assume (jl_is_datatype(ty) && !jl_is_abstracttype(ty) &&
// !jl_is_array_type(ty))
if (jl_is_cpointer_type(ty))
return false;
size_t size = jl_datatype_size(ty);
if (size == 0)
Expand Down
3 changes: 2 additions & 1 deletion src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,8 @@ static std::string generate_func_sig(Type **lrt, Type **prt, int &sret,
if (*prt == NULL)
*prt = *lrt;

if (jl_is_datatype(rt) && !jl_is_abstracttype(rt) && use_sret(&abi, rt)) {
if (jl_is_datatype(rt) && !jl_is_abstracttype(rt) &&
!jl_is_array_type(rt) && use_sret(&abi, rt)) {
paramattrs.push_back(AttrBuilder());
paramattrs[0].clear();
#if !defined(_OS_WINDOWS_) || defined(LLVM35)
Expand Down
11 changes: 11 additions & 0 deletions test/ccall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,14 @@ ccall(foo13031p, Cint, (Ref{Tuple{}},), ())
foo13031(x,y,z) = z
foo13031p = cfunction(foo13031, Cint, (Ref{Tuple{}},Ref{Tuple{}},Cint))
ccall(foo13031p, Cint, (Ref{Tuple{}},Ref{Tuple{}},Cint), (), (), 8)

# Special calling convention for `Array`
function f17204(a)
b = similar(a)
for i in eachindex(a)
b[i] = a[i] + 10
end
return b
end
@test ccall(cfunction(f17204, Vector{Any}, Tuple{Vector{Any}}),
Vector{Any}, (Vector{Any},), Any[1:10;]) == Any[11:20;]

0 comments on commit d45443f

Please sign in to comment.