Skip to content

Commit 7a1a6f3

Browse files
authored
codegen: use correct rettype ABI for aotcompile (#57082)
This only really can differ in aotcompile, so it was hard to notice that that the attempted code simplification in db25494 wasn't correct and could lead to ABI mismatches at runtime. Fixes #57018
1 parent ff5f66c commit 7a1a6f3

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/aotcompile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2223,7 +2223,7 @@ void jl_get_llvmf_defn_impl(jl_llvmf_dump_t* dump, jl_method_instance_t *mi, jl_
22232223
output.imaging_mode = jl_options.image_codegen;
22242224
output.temporary_roots = jl_alloc_array_1d(jl_array_any_type, 0);
22252225
JL_GC_PUSH1(&output.temporary_roots);
2226-
auto decls = jl_emit_code(m, mi, src, NULL, output);
2226+
auto decls = jl_emit_code(m, mi, src, mi->specTypes, src->rettype, output);
22272227
output.temporary_roots = nullptr;
22282228
JL_GC_POP(); // GC the global_targets array contents now since reflection doesn't need it
22292229

src/codegen.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4381,7 +4381,7 @@ static jl_llvm_functions_t
43814381
jl_method_instance_t *lam,
43824382
jl_code_info_t *src,
43834383
jl_value_t *abi,
4384-
jl_value_t *rettype,
4384+
jl_value_t *jlrettype,
43854385
jl_codegen_params_t &params);
43864386

43874387
static void emit_hasnofield_error_ifnot(jl_codectx_t &ctx, Value *ok, jl_datatype_t *type, jl_cgval_t name);
@@ -5533,12 +5533,12 @@ static jl_value_t *get_ci_abi(jl_code_instance_t *ci)
55335533
return jl_get_ci_mi(ci)->specTypes;
55345534
}
55355535

5536-
static jl_cgval_t emit_call_specfun_other(jl_codectx_t &ctx, jl_code_instance_t *ci, jl_value_t *jlretty, StringRef specFunctionObject, jl_code_instance_t *fromexternal,
5536+
static jl_cgval_t emit_call_specfun_other(jl_codectx_t &ctx, jl_code_instance_t *ci, StringRef specFunctionObject, jl_code_instance_t *fromexternal,
55375537
ArrayRef<jl_cgval_t> argv, size_t nargs, jl_returninfo_t::CallingConv *cc, unsigned *return_roots, jl_value_t *inferred_retty, Value *age_ok)
55385538
{
55395539
jl_method_instance_t *mi = jl_get_ci_mi(ci);
55405540
bool is_opaque_closure = jl_is_method(mi->def.value) && mi->def.method->is_for_opaque_closure;
5541-
return emit_call_specfun_other(ctx, is_opaque_closure, get_ci_abi(ci), jlretty, NULL,
5541+
return emit_call_specfun_other(ctx, is_opaque_closure, get_ci_abi(ci), ci->rettype, NULL,
55425542
specFunctionObject, fromexternal, argv, nargs, cc, return_roots, inferred_retty, age_ok);
55435543
}
55445544

@@ -5688,7 +5688,7 @@ static jl_cgval_t emit_invoke(jl_codectx_t &ctx, const jl_cgval_t &lival, ArrayR
56885688
jl_returninfo_t::CallingConv cc = jl_returninfo_t::CallingConv::Boxed;
56895689
unsigned return_roots = 0;
56905690
if (specsig)
5691-
result = emit_call_specfun_other(ctx, codeinst, codeinst->rettype, protoname, external ? codeinst : nullptr, argv, nargs, &cc, &return_roots, rt, age_ok);
5691+
result = emit_call_specfun_other(ctx, codeinst, protoname, external ? codeinst : nullptr, argv, nargs, &cc, &return_roots, rt, age_ok);
56925692
else
56935693
result = emit_call_specfun_boxed(ctx, codeinst->rettype, protoname, external ? codeinst : nullptr, argv, nargs, rt, age_ok);
56945694
if (need_to_emit) {
@@ -10029,7 +10029,8 @@ jl_llvm_functions_t jl_emit_code(
1002910029
orc::ThreadSafeModule &m,
1003010030
jl_method_instance_t *li,
1003110031
jl_code_info_t *src,
10032-
jl_value_t *abi,
10032+
jl_value_t *abi_at,
10033+
jl_value_t *abi_rt,
1003310034
jl_codegen_params_t &params)
1003410035
{
1003510036
JL_TIMING(CODEGEN, CODEGEN_LLVM);
@@ -10038,10 +10039,8 @@ jl_llvm_functions_t jl_emit_code(
1003810039
assert((params.params == &jl_default_cgparams /* fast path */ || !params.cache ||
1003910040
compare_cgparams(params.params, &jl_default_cgparams)) &&
1004010041
"functions compiled with custom codegen params must not be cached");
10041-
if (!abi)
10042-
abi = li->specTypes;
1004310042
JL_TRY {
10044-
decls = emit_function(m, li, src, abi, src->rettype, params);
10043+
decls = emit_function(m, li, src, abi_at, abi_rt, params);
1004510044
auto stream = *jl_ExecutionEngine->get_dump_emitted_mi_name_stream();
1004610045
if (stream) {
1004710046
jl_printf(stream, "%s\t", decls.specFunctionObject.c_str());
@@ -10112,7 +10111,7 @@ jl_llvm_functions_t jl_emit_codeinst(
1011210111
return jl_llvm_functions_t(); // user error
1011310112
}
1011410113
//assert(jl_egal((jl_value_t*)jl_atomic_load_relaxed(&codeinst->debuginfo), (jl_value_t*)src->debuginfo) && "trying to generate code for a codeinst for an incompatible src");
10115-
jl_llvm_functions_t decls = jl_emit_code(m, jl_get_ci_mi(codeinst), src, get_ci_abi(codeinst), params);
10114+
jl_llvm_functions_t decls = jl_emit_code(m, jl_get_ci_mi(codeinst), src, get_ci_abi(codeinst), codeinst->rettype, params);
1011610115
return decls;
1011710116
}
1011810117

src/jitlayers.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ jl_llvm_functions_t jl_emit_code(
278278
orc::ThreadSafeModule &M,
279279
jl_method_instance_t *mi,
280280
jl_code_info_t *src,
281-
jl_value_t *abi,
281+
jl_value_t *abi_at,
282+
jl_value_t *abi_rt,
282283
jl_codegen_params_t &params);
283284

284285
jl_llvm_functions_t jl_emit_codeinst(

0 commit comments

Comments
 (0)