Skip to content

Commit e747d6b

Browse files
committed
Do not make local copy of inline(always) fns in debug mode
1 parent 5099914 commit e747d6b

File tree

2 files changed

+13
-6
lines changed
  • compiler/rustc_middle/src/mir
  • src/test/run-make-fulldeps/inline-always-many-cgu

2 files changed

+13
-6
lines changed

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ impl<'tcx> MonoItem<'tcx> {
107107
}
108108

109109
// Finally, if this is `#[inline(always)]` we're sure to respect
110-
// that with an inline copy per CGU, but otherwise we'll be
111-
// creating one copy of this `#[inline]` function which may
112-
// conflict with upstream crates as it could be an exported
113-
// symbol.
110+
// that (unless in OptLevel::No) with an inline copy per CGU,
111+
// but otherwise we'll be creating one copy of this `#[inline]`
112+
// function which may conflict with upstream crates as it could
113+
// be an exported symbol.
114114
match tcx.codegen_fn_attrs(instance.def_id()).inline {
115-
InlineAttr::Always => InstantiationMode::LocalCopy,
115+
InlineAttr::Always if tcx.sess.opts.optimize != OptLevel::No => {
116+
InstantiationMode::LocalCopy
117+
}
116118
_ => InstantiationMode::GloballyShared { may_conflict: true },
117119
}
118120
}

src/test/run-make-fulldeps/inline-always-many-cgu/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
-include ../tools.mk
22

33
all:
4-
$(RUSTC) foo.rs --emit llvm-ir -C codegen-units=2
4+
$(RUSTC) foo.rs --emit llvm-ir -C codegen-units=2 -C opt-level=0
5+
if ![cat $(TMPDIR)/*.ll | $(CGREP) -e '\bcall\b']; then \
6+
echo "not found call instruction when one was expected"; \
7+
exit 1; \
8+
fi
9+
$(RUSTC) foo.rs --emit llvm-ir -C codegen-units=2 -C opt-level=1
510
if cat $(TMPDIR)/*.ll | $(CGREP) -e '\bcall\b'; then \
611
echo "found call instruction when one wasn't expected"; \
712
exit 1; \

0 commit comments

Comments
 (0)