Skip to content

Commit 06b6ec0

Browse files
authored
Merge pull request rust-lang#211 from rust-lang/fix/used-function-attribute-inline-asm
Add used function attribute from inline asm
2 parents 9d6b4a9 + 5c2dec0 commit 06b6ec0

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/asm.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@ impl<'gcc, 'tcx> AsmMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
718718
}
719719

720720
GlobalAsmOperandRef::SymFn { instance } => {
721+
let function = self.rvalue_as_function(get_fn(self, instance));
722+
self.add_used_function(function);
721723
// TODO(@Amanieu): Additional mangling is needed on
722724
// some targets to add a leading underscore (Mach-O)
723725
// or byte count suffixes (x86 Windows).
@@ -726,6 +728,7 @@ impl<'gcc, 'tcx> AsmMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
726728
}
727729

728730
GlobalAsmOperandRef::SymStatic { def_id } => {
731+
// TODO(antoyo): set the global variable as used.
729732
// TODO(@Amanieu): Additional mangling is needed on
730733
// some targets to add a leading underscore (Mach-O).
731734
let instance = Instance::mono(self.tcx, def_id);

src/consts.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use gccjit::{GlobalKind, LValue, RValue, ToRValue, Type};
1+
#[cfg(feature = "master")]
2+
use gccjit::FnAttribute;
3+
use gccjit::{Function, GlobalKind, LValue, RValue, ToRValue, Type};
24
use rustc_codegen_ssa::traits::{BaseTypeMethods, ConstMethods, DerivedTypeMethods, StaticMethods};
35
use rustc_hir as hir;
46
use rustc_hir::Node;
@@ -159,12 +161,19 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
159161
// TODO(antoyo)
160162
}
161163

162-
fn add_compiler_used_global(&self, _global: RValue<'gcc>) {
163-
// TODO(antoyo)
164+
fn add_compiler_used_global(&self, global: RValue<'gcc>) {
165+
// NOTE: seems like GCC does not make the distinction between compiler.used and used.
166+
self.add_used_global(global);
164167
}
165168
}
166169

167170
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
171+
#[cfg_attr(not(feature="master"), allow(unused_variables))]
172+
pub fn add_used_function(&self, function: Function<'gcc>) {
173+
#[cfg(feature = "master")]
174+
function.add_attribute(FnAttribute::Used);
175+
}
176+
168177
pub fn static_addr_of_mut(&self, cv: RValue<'gcc>, align: Align, kind: Option<&str>) -> RValue<'gcc> {
169178
let global =
170179
match kind {

0 commit comments

Comments
 (0)