@@ -66,9 +66,7 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
6666 // LLVM will prefix the name with `__imp_`. Ideally, we'd like the
6767 // existing logic below to set the Storage Class, but it has an
6868 // exemption for MinGW for backwards compatibility.
69- unsafe {
70- llvm:: LLVMSetDLLStorageClass ( llfn, llvm:: DLLStorageClass :: DllImport ) ;
71- }
69+ llvm:: set_dllimport_storage_class ( llfn) ;
7270 llfn
7371 } else {
7472 cx. declare_fn ( sym, fn_abi, Some ( instance) )
@@ -99,65 +97,61 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
9997 // has been applied to the definition (wherever that definition may be).
10098
10199 llvm:: set_linkage ( llfn, llvm:: Linkage :: ExternalLinkage ) ;
102- unsafe {
103- let is_generic = instance. args . non_erasable_generics ( ) . next ( ) . is_some ( ) ;
104-
105- let is_hidden = if is_generic {
106- // This is a monomorphization of a generic function.
107- if !( cx. tcx . sess . opts . share_generics ( )
108- || tcx. codegen_fn_attrs ( instance_def_id) . inline
109- == rustc_attr_parsing:: InlineAttr :: Never )
110- {
111- // When not sharing generics, all instances are in the same
112- // crate and have hidden visibility.
113- true
114- } else {
115- if let Some ( instance_def_id) = instance_def_id. as_local ( ) {
116- // This is a monomorphization of a generic function
117- // defined in the current crate. It is hidden if:
118- // - the definition is unreachable for downstream
119- // crates, or
120- // - the current crate does not re-export generics
121- // (because the crate is a C library or executable)
122- cx. tcx . is_unreachable_local_definition ( instance_def_id)
123- || !cx. tcx . local_crate_exports_generics ( )
124- } else {
125- // This is a monomorphization of a generic function
126- // defined in an upstream crate. It is hidden if:
127- // - it is instantiated in this crate, and
128- // - the current crate does not re-export generics
129- instance. upstream_monomorphization ( tcx) . is_none ( )
130- && !cx. tcx . local_crate_exports_generics ( )
131- }
132- }
133- } else {
134- // This is a non-generic function. It is hidden if:
135- // - it is instantiated in the local crate, and
136- // - it is defined an upstream crate (non-local), or
137- // - it is not reachable
138- cx. tcx . is_codegened_item ( instance_def_id)
139- && ( !instance_def_id. is_local ( )
140- || !cx. tcx . is_reachable_non_generic ( instance_def_id) )
141- } ;
142- if is_hidden {
143- llvm:: set_visibility ( llfn, llvm:: Visibility :: Hidden ) ;
144- }
100+ let is_generic = instance. args . non_erasable_generics ( ) . next ( ) . is_some ( ) ;
145101
146- // MinGW: For backward compatibility we rely on the linker to decide whether it
147- // should use dllimport for functions.
148- if cx. use_dll_storage_attrs
149- && let Some ( library) = tcx. native_library ( instance_def_id)
150- && library. kind . is_dllimport ( )
151- && !matches ! ( tcx. sess. target. env. as_ref( ) , "gnu" | "uclibc" )
102+ let is_hidden = if is_generic {
103+ // This is a monomorphization of a generic function.
104+ if !( cx. tcx . sess . opts . share_generics ( )
105+ || tcx. codegen_fn_attrs ( instance_def_id) . inline
106+ == rustc_attr_parsing:: InlineAttr :: Never )
152107 {
153- llvm:: LLVMSetDLLStorageClass ( llfn, llvm:: DLLStorageClass :: DllImport ) ;
108+ // When not sharing generics, all instances are in the same
109+ // crate and have hidden visibility.
110+ true
111+ } else {
112+ if let Some ( instance_def_id) = instance_def_id. as_local ( ) {
113+ // This is a monomorphization of a generic function
114+ // defined in the current crate. It is hidden if:
115+ // - the definition is unreachable for downstream
116+ // crates, or
117+ // - the current crate does not re-export generics
118+ // (because the crate is a C library or executable)
119+ cx. tcx . is_unreachable_local_definition ( instance_def_id)
120+ || !cx. tcx . local_crate_exports_generics ( )
121+ } else {
122+ // This is a monomorphization of a generic function
123+ // defined in an upstream crate. It is hidden if:
124+ // - it is instantiated in this crate, and
125+ // - the current crate does not re-export generics
126+ instance. upstream_monomorphization ( tcx) . is_none ( )
127+ && !cx. tcx . local_crate_exports_generics ( )
128+ }
154129 }
130+ } else {
131+ // This is a non-generic function. It is hidden if:
132+ // - it is instantiated in the local crate, and
133+ // - it is defined an upstream crate (non-local), or
134+ // - it is not reachable
135+ cx. tcx . is_codegened_item ( instance_def_id)
136+ && ( !instance_def_id. is_local ( )
137+ || !cx. tcx . is_reachable_non_generic ( instance_def_id) )
138+ } ;
139+ if is_hidden {
140+ llvm:: set_visibility ( llfn, llvm:: Visibility :: Hidden ) ;
141+ }
155142
156- if cx. should_assume_dso_local ( llfn, true ) {
157- llvm:: LLVMRustSetDSOLocal ( llfn, true ) ;
158- }
143+ // MinGW: For backward compatibility we rely on the linker to decide whether it
144+ // should use dllimport for functions.
145+ if cx. use_dll_storage_attrs
146+ && let Some ( library) = tcx. native_library ( instance_def_id)
147+ && library. kind . is_dllimport ( )
148+ && !matches ! ( tcx. sess. target. env. as_ref( ) , "gnu" | "uclibc" )
149+ {
150+ llvm:: set_dllimport_storage_class ( llfn) ;
159151 }
160152
153+ cx. assume_dso_local ( llfn, true ) ;
154+
161155 llfn
162156 } ;
163157
0 commit comments