@@ -2713,8 +2713,9 @@ static void jl_name_jlfuncparams_args(jl_codegen_params_t ¶ms, Function *F)
27132713 F->getArg (3 )->setName (" sparams::Any" );
27142714}
27152715
2716- void jl_init_function (Function *F, const Triple &TT ) JL_NOTSAFEPOINT
2716+ void jl_init_function (Function *F, const jl_codegen_params_t ¶ms ) JL_NOTSAFEPOINT
27172717{
2718+ auto &TT = params.TargetTriple ;
27182719 // set any attributes that *must* be set on all functions
27192720 AttrBuilder attr (F->getContext ());
27202721 if (TT.isOSWindows () && TT.getArch () == Triple::x86) {
@@ -2727,22 +2728,18 @@ void jl_init_function(Function *F, const Triple &TT) JL_NOTSAFEPOINT
27272728 attr.addUWTableAttr (llvm::UWTableKind::Default); // force NeedsWinEH
27282729 }
27292730 attr.addAttribute (" frame-pointer" , " all" );
2730- if (!TT.isOSWindows ()) {
2731- #if !defined(_COMPILER_ASAN_ENABLED_)
2731+ if (!TT.isOSWindows () && !JL_FEAT_TEST (params, sanitize_address)) {
27322732 // ASAN won't like us accessing undefined memory causing spurious issues,
27332733 // and Windows has platform-specific handling which causes it to mishandle
27342734 // this annotation. Other platforms should just ignore this if they don't
27352735 // implement it.
27362736 attr.addAttribute (" probe-stack" , " inline-asm" );
27372737 // attr.addAttribute("stack-probe-size", "4096"); // can use this to change the default
2738- #endif
27392738 }
2740- #if defined(_COMPILER_ASAN_ENABLED_)
2741- attr.addAttribute (Attribute::SanitizeAddress);
2742- #endif
2743- #if defined(_COMPILER_MSAN_ENABLED_)
2744- attr.addAttribute (Attribute::SanitizeMemory);
2745- #endif
2739+ if (JL_FEAT_TEST (params, sanitize_address))
2740+ attr.addAttribute (Attribute::SanitizeAddress);
2741+ if (JL_FEAT_TEST (params, sanitize_memory))
2742+ attr.addAttribute (Attribute::SanitizeMemory);
27462743 F->addFnAttrs (attr);
27472744}
27482745
@@ -6247,7 +6244,7 @@ static std::pair<Function*, Function*> get_oc_function(jl_codectx_t &ctx, jl_met
62476244 F = Function::Create (get_func_sig (ctx.builder .getContext ()),
62486245 Function::ExternalLinkage,
62496246 proto_oc, jl_Module);
6250- jl_init_function (F, ctx.emission_context . TargetTriple );
6247+ jl_init_function (F, ctx.emission_context );
62516248 jl_name_jlfunc_args (ctx.emission_context , F);
62526249 F->setAttributes (AttributeList::get (ctx.builder .getContext (), {get_func_attrs (ctx.builder .getContext ()), F->getAttributes ()}));
62536250 }
@@ -6770,7 +6767,7 @@ static Function *emit_modifyhelper(jl_codectx_t &ctx2, const jl_cgval_t &op, con
67706767 ArgTy.push_back (ctx.builder .getPtrTy ());
67716768 FunctionType *FT = FunctionType::get (elty, ArgTy, false );
67726769 Function *w = Function::Create (FT, GlobalVariable::PrivateLinkage, " " , M);
6773- jl_init_function (w, ctx.emission_context . TargetTriple );
6770+ jl_init_function (w, ctx.emission_context );
67746771 w->addFnAttr (Attribute::AlwaysInline);
67756772 w->setUnnamedAddr (GlobalValue::UnnamedAddr::Global);
67766773 Function::arg_iterator AI = w->arg_begin ();
@@ -6829,7 +6826,7 @@ Function *emit_tojlinvoke(jl_code_instance_t *codeinst, Value *theFunc, Module *
68296826 Function *f = Function::Create (ctx.types ().T_jlfunc ,
68306827 GlobalVariable::InternalLinkage,
68316828 name, M);
6832- jl_init_function (f, params. TargetTriple );
6829+ jl_init_function (f, params);
68336830 jl_name_jlfunc_args (params, f);
68346831 // f->setAlwaysInline();
68356832 ctx.f = f; // for jl_Module
@@ -7027,7 +7024,7 @@ void emit_specsig_to_fptr1(
70277024static void emit_fptr1_wrapper (Module *M, StringRef gf_thunk_name, Value *target, jl_value_t *rettype_const, jl_value_t *declrt, jl_value_t *jlrettype, jl_codegen_params_t ¶ms)
70287025{
70297026 Function *w = Function::Create (get_func_sig (M->getContext ()), GlobalVariable::ExternalLinkage, gf_thunk_name, M);
7030- jl_init_function (w, params. TargetTriple );
7027+ jl_init_function (w, params);
70317028 w->setAttributes (AttributeList::get (M->getContext (), {get_func_attrs (M->getContext ()), w->getAttributes ()}));
70327029 w->addFnAttr (Attribute::OptimizeNone);
70337030 w->addFnAttr (Attribute::NoInline);
@@ -7071,7 +7068,7 @@ static void emit_specsig_to_specsig(
70717068{
70727069 jl_returninfo_t returninfo = get_specsig_function (params, M, nullptr , gf_thunk_name, calltype, rettype, is_for_opaque_closure);
70737070 Function *gf_thunk = cast<Function>(returninfo.decl .getCallee ());
7074- jl_init_function (gf_thunk, params. TargetTriple );
7071+ jl_init_function (gf_thunk, params);
70757072 gf_thunk->setAttributes (AttributeList::get (gf_thunk->getContext (), {returninfo.attrs , gf_thunk->getAttributes ()}));
70767073 emit_specsig_to_specsig (gf_thunk, returninfo.cc , returninfo.return_roots , calltype, rettype, is_for_opaque_closure, nargs, params, target, targetsig, targetrt, targetspec, rettype_const);
70777074}
@@ -7317,7 +7314,7 @@ static Function *gen_cfun_wrapper(
73177314 Function *cw = Function::Create (functype,
73187315 GlobalVariable::ExternalLinkage,
73197316 funcName, M);
7320- jl_init_function (cw, params. TargetTriple );
7317+ jl_init_function (cw, params);
73217318 cw->setAttributes (AttributeList::get (M->getContext (), {attributes, cw->getAttributes ()}));
73227319
73237320 jl_codectx_t ctx (M->getContext (), params, 0 , 0 );
@@ -7539,7 +7536,7 @@ static Function *gen_cfun_wrapper(
75397536 FunctionType::get (getPointerTy (ctx.builder .getContext ()), { getPointerTy (ctx.builder .getContext ()), ctx.types ().T_ppjlvalue }, false ),
75407537 GlobalVariable::ExternalLinkage,
75417538 funcName, M);
7542- jl_init_function (cw_make, ctx.emission_context . TargetTriple );
7539+ jl_init_function (cw_make, ctx.emission_context );
75437540 cw_make->getArg (0 )->setName (" wrapper" );
75447541 cw_make->getArg (1 )->setName (" newval" );
75457542 BasicBlock *b0 = BasicBlock::Create (ctx.builder .getContext (), " top" , cw_make);
@@ -7799,7 +7796,7 @@ static void gen_invoke_wrapper(jl_method_instance_t *lam, jl_value_t *abi, jl_va
77997796{
78007797 ++GeneratedInvokeWrappers;
78017798 Function *w = Function::Create (get_func_sig (M->getContext ()), GlobalVariable::ExternalLinkage, funcName, M);
7802- jl_init_function (w, params. TargetTriple );
7799+ jl_init_function (w, params);
78037800 jl_name_jlfunc_args (params, w);
78047801 w->setAttributes (AttributeList::get (M->getContext (), {get_func_attrs (M->getContext ()), w->getAttributes ()}));
78057802 w->addFnAttr (Attribute::OptimizeNone);
@@ -8040,7 +8037,7 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t ¶ms, Module
80408037 Function *f = M ? cast_or_null<Function>(M->getNamedValue (name)) : NULL ;
80418038 if (f == NULL ) {
80428039 f = Function::Create (ftype, GlobalVariable::ExternalLinkage, name, M);
8043- jl_init_function (f, params. TargetTriple );
8040+ jl_init_function (f, params);
80448041 if (params.params ->debug_info_level >= 2 ) {
80458042 ios_t sigbuf;
80468043 ios_mem (&sigbuf, 0 );
@@ -8327,7 +8324,7 @@ static jl_llvm_functions_t
83278324 ArgNames, nreq);
83288325 f = cast<Function>(returninfo.decl .getCallee ());
83298326 has_sret = (returninfo.cc == jl_returninfo_t ::SRet || returninfo.cc == jl_returninfo_t ::Union);
8330- jl_init_function (f, ctx.emission_context . TargetTriple );
8327+ jl_init_function (f, ctx.emission_context );
83318328
83328329 // common pattern: see if all return statements are an argument in that
83338330 // case the apply-generic call can re-use the original box for the return
@@ -8366,7 +8363,7 @@ static jl_llvm_functions_t
83668363 f = Function::Create (needsparams ? ctx.types ().T_jlfuncparams : ctx.types ().T_jlfunc ,
83678364 GlobalVariable::ExternalLinkage,
83688365 declarations.specFunctionObject , M);
8369- jl_init_function (f, ctx.emission_context . TargetTriple );
8366+ jl_init_function (f, ctx.emission_context );
83708367 if (needsparams)
83718368 jl_name_jlfuncparams_args (ctx.emission_context , f);
83728369 else
@@ -8402,11 +8399,9 @@ static jl_llvm_functions_t
84028399 FnAttrs.addAttribute (Attribute::StackProtectStrong);
84038400#endif
84048401
8405- #ifdef _COMPILER_TSAN_ENABLED_
8406- // TODO: enable this only when a argument like `-race` is passed to Julia
8407- // add a macro for no_sanitize_thread
8408- FnAttrs.addAttribute (llvm::Attribute::SanitizeThread);
8409- #endif
8402+ // TODO: add a macro for no_sanitize_thread
8403+ if (JL_FEAT_TEST (ctx, sanitize_thread))
8404+ FnAttrs.addAttribute (llvm::Attribute::SanitizeThread);
84108405
84118406 // add the optimization level specified for this module, if any
84128407 int optlevel = jl_get_module_optlevel (ctx.module );
@@ -9773,7 +9768,7 @@ jl_llvm_functions_t jl_emit_codedecls(
97739768 Function *f = Function::Create (needsparams ? JuliaType::get_jlfuncparams_ty (M.getContext ()) : JuliaType::get_jlfunc_ty (M.getContext ()),
97749769 GlobalVariable::ExternalLinkage,
97759770 decls.specFunctionObject , M);
9776- jl_init_function (f, params. TargetTriple );
9771+ jl_init_function (f, params);
97779772 f->setAttributes (AttributeList::get (M.getContext (), {get_func_attrs (M.getContext ()), f->getAttributes ()}));
97789773 }
97799774 });
@@ -9836,7 +9831,7 @@ static jl_llvm_functions_t jl_emit_oc_wrapper(orc::ThreadSafeModule &m, jl_codeg
98369831 std::string funcName = get_function_name (true , false , ctx.name , ctx.emission_context .TargetTriple );
98379832 jl_returninfo_t returninfo = get_specsig_function (params, M, NULL , funcName, mi->specTypes , rettype, true );
98389833 Function *gf_thunk = cast<Function>(returninfo.decl .getCallee ());
9839- jl_init_function (gf_thunk, ctx.emission_context . TargetTriple );
9834+ jl_init_function (gf_thunk, ctx.emission_context );
98409835 size_t nrealargs = jl_nparams (mi->specTypes );
98419836 emit_specsig_to_fptr1 (gf_thunk, returninfo.cc , returninfo.return_roots ,
98429837 mi->specTypes , rettype, true , nrealargs, ctx.emission_context ,
0 commit comments