diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2023-03-30 12:13:44 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2023-03-30 12:13:44 +0000 |
| commit | 86a71bf45b6252f030d9206f19b9901f4b9322a2 (patch) | |
| tree | 340f86f5ee3644ca57bdbaccd93832690decda25 /src | |
| parent | b2796ecb774883c3b22343ed1992cac390003882 (diff) | |
| parent | 5a7ce4609e3a7c364d9ff8810329242cefb76a4b (diff) | |
| download | rust-86a71bf45b6252f030d9206f19b9901f4b9322a2.tar.gz rust-86a71bf45b6252f030d9206f19b9901f4b9322a2.zip | |
Sync from rust 17c11672167827b0dd92c88ef69f24346d1286dd
Diffstat (limited to 'src')
| -rw-r--r-- | src/constant.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/constant.rs b/src/constant.rs index b23fef6af2d..0b2a1e78517 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -54,12 +54,22 @@ pub(crate) fn codegen_tls_ref<'tcx>( def_id: DefId, layout: TyAndLayout<'tcx>, ) -> CValue<'tcx> { - let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false); - let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); - if fx.clif_comments.enabled() { - fx.add_comment(local_data_id, format!("tls {:?}", def_id)); - } - let tls_ptr = fx.bcx.ins().tls_value(fx.pointer_type, local_data_id); + let tls_ptr = if !def_id.is_local() && fx.tcx.needs_thread_local_shim(def_id) { + let instance = ty::Instance { + def: ty::InstanceDef::ThreadLocalShim(def_id), + substs: ty::InternalSubsts::empty(), + }; + let func_ref = fx.get_function_ref(instance); + let call = fx.bcx.ins().call(func_ref, &[]); + fx.bcx.func.dfg.first_result(call) + } else { + let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false); + let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); + if fx.clif_comments.enabled() { + fx.add_comment(local_data_id, format!("tls {:?}", def_id)); + } + fx.bcx.ins().tls_value(fx.pointer_type, local_data_id) + }; CValue::by_val(tls_ptr, layout) } |
