Skip to content

Commit 28069fd

Browse files
committed
Fix undefined function error
1 parent 3cb8b1b commit 28069fd

File tree

2 files changed

+33
-55
lines changed

2 files changed

+33
-55
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
8888
- name: Clean
8989
run: |
90-
./y.sh clean all
90+
./y.sh clean all
9191
9292
- name: Prepare dependencies
9393
run: |

src/callee.rs

Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -100,67 +100,45 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)
100100
// has been applied to the definition (wherever that definition may be).
101101
let is_generic = instance.args.non_erasable_generics().next().is_some();
102102

103-
if is_generic {
104-
// This is a monomorphization. Its expected visibility depends
105-
// on whether we are in share-generics mode.
106-
107-
if cx.tcx.sess.opts.share_generics() {
108-
// We are in share_generics mode.
109-
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::InlineAttr::Never)
108+
{
109+
// When not sharing generics, all instances are in the same
110+
// crate and have hidden visibility.
111+
true
112+
} else {
110113
if let Some(instance_def_id) = instance_def_id.as_local() {
111-
// This is a definition from the current crate. If the
112-
// definition is unreachable for downstream crates or
113-
// the current crate does not re-export generics, the
114-
// definition of the instance will have been declared
115-
// as `hidden`.
116-
if cx.tcx.is_unreachable_local_definition(instance_def_id)
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)
117121
|| !cx.tcx.local_crate_exports_generics()
118-
{
119-
#[cfg(feature = "master")]
120-
func.add_attribute(FnAttribute::Visibility(Visibility::Hidden));
121-
}
122122
} else {
123123
// This is a monomorphization of a generic function
124-
// defined in an upstream crate.
125-
if instance.upstream_monomorphization(tcx).is_some() {
126-
// This is instantiated in another crate. It cannot
127-
// be `hidden`.
128-
} else {
129-
// This is a local instantiation of an upstream definition.
130-
// If the current crate does not re-export it
131-
// (because it is a C library or an executable), it
132-
// will have been declared `hidden`.
133-
if !cx.tcx.local_crate_exports_generics() {
134-
#[cfg(feature = "master")]
135-
func.add_attribute(FnAttribute::Visibility(Visibility::Hidden));
136-
}
137-
}
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()
138129
}
139-
} else {
140-
// When not sharing generics, all instances are in the same
141-
// crate and have hidden visibility
142-
#[cfg(feature = "master")]
143-
func.add_attribute(FnAttribute::Visibility(Visibility::Hidden));
144130
}
145131
} else {
146-
// This is a non-generic function
147-
if cx.tcx.is_codegened_item(instance_def_id) {
148-
// This is a function that is instantiated in the local crate
149-
150-
if instance_def_id.is_local() {
151-
// This is function that is defined in the local crate.
152-
// If it is not reachable, it is hidden.
153-
if !cx.tcx.is_reachable_non_generic(instance_def_id) {
154-
#[cfg(feature = "master")]
155-
func.add_attribute(FnAttribute::Visibility(Visibility::Hidden));
156-
}
157-
} else {
158-
// This is a function from an upstream crate that has
159-
// been instantiated here. These are always hidden.
160-
#[cfg(feature = "master")]
161-
func.add_attribute(FnAttribute::Visibility(Visibility::Hidden));
162-
}
163-
}
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+
func.add_attribute(FnAttribute::Visibility(Visibility::Hidden));
164142
}
165143

166144
func

0 commit comments

Comments
 (0)