@@ -97,65 +97,61 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
97
97
// has been applied to the definition (wherever that definition may be).
98
98
99
99
llvm:: set_linkage ( llfn, llvm:: Linkage :: ExternalLinkage ) ;
100
- unsafe {
101
- let is_generic = instance. args . non_erasable_generics ( ) . next ( ) . is_some ( ) ;
102
-
103
- let is_hidden = if is_generic {
104
- // This is a monomorphization of a generic function.
105
- if !( cx. tcx . sess . opts . share_generics ( )
106
- || tcx. codegen_fn_attrs ( instance_def_id) . inline
107
- == rustc_attr_parsing:: InlineAttr :: Never )
108
- {
109
- // When not sharing generics, all instances are in the same
110
- // crate and have hidden visibility.
111
- true
112
- } else {
113
- if let Some ( instance_def_id) = instance_def_id. as_local ( ) {
114
- // This is a monomorphization of a generic function
115
- // defined in the current crate. It is hidden if:
116
- // - the definition is unreachable for downstream
117
- // crates, or
118
- // - the current crate does not re-export generics
119
- // (because the crate is a C library or executable)
120
- cx. tcx . is_unreachable_local_definition ( instance_def_id)
121
- || !cx. tcx . local_crate_exports_generics ( )
122
- } else {
123
- // This is a monomorphization of a generic function
124
- // defined in an upstream crate. It is hidden if:
125
- // - it is instantiated in this crate, and
126
- // - the current crate does not re-export generics
127
- instance. upstream_monomorphization ( tcx) . is_none ( )
128
- && !cx. tcx . local_crate_exports_generics ( )
129
- }
130
- }
131
- } else {
132
- // This is a non-generic function. It is hidden if:
133
- // - it is instantiated in the local crate, and
134
- // - it is defined an upstream crate (non-local), or
135
- // - it is not reachable
136
- cx. tcx . is_codegened_item ( instance_def_id)
137
- && ( !instance_def_id. is_local ( )
138
- || !cx. tcx . is_reachable_non_generic ( instance_def_id) )
139
- } ;
140
- if is_hidden {
141
- llvm:: set_visibility ( llfn, llvm:: Visibility :: Hidden ) ;
142
- }
100
+ let is_generic = instance. args . non_erasable_generics ( ) . next ( ) . is_some ( ) ;
143
101
144
- // MinGW: For backward compatibility we rely on the linker to decide whether it
145
- // should use dllimport for functions.
146
- if cx. use_dll_storage_attrs
147
- && let Some ( library) = tcx. native_library ( instance_def_id)
148
- && library. kind . is_dllimport ( )
149
- && !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 )
150
107
{
151
- llvm:: set_dllimport_storage_class ( llfn) ;
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
+ }
152
129
}
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
+ }
153
142
154
- if cx. should_assume_dso_local ( llfn, true ) {
155
- llvm:: LLVMRustSetDSOLocal ( llfn, true ) ;
156
- }
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) ;
157
151
}
158
152
153
+ cx. assume_dso_local ( llfn, true ) ;
154
+
159
155
llfn
160
156
} ;
161
157
0 commit comments