From e747d6b317ed5919894dac6601e00e573224eb97 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 18 Sep 2020 13:57:08 -0300 Subject: [PATCH] Do not make local copy of inline(always) fns in debug mode --- compiler/rustc_middle/src/mir/mono.rs | 12 +++++++----- .../inline-always-many-cgu/Makefile | 7 ++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index 79e2c5aac2385..5ae6d109981e6 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -107,12 +107,14 @@ impl<'tcx> MonoItem<'tcx> { } // Finally, if this is `#[inline(always)]` we're sure to respect - // that with an inline copy per CGU, but otherwise we'll be - // creating one copy of this `#[inline]` function which may - // conflict with upstream crates as it could be an exported - // symbol. + // that (unless in OptLevel::No) with an inline copy per CGU, + // but otherwise we'll be creating one copy of this `#[inline]` + // function which may conflict with upstream crates as it could + // be an exported symbol. match tcx.codegen_fn_attrs(instance.def_id()).inline { - InlineAttr::Always => InstantiationMode::LocalCopy, + InlineAttr::Always if tcx.sess.opts.optimize != OptLevel::No => { + InstantiationMode::LocalCopy + } _ => InstantiationMode::GloballyShared { may_conflict: true }, } } diff --git a/src/test/run-make-fulldeps/inline-always-many-cgu/Makefile b/src/test/run-make-fulldeps/inline-always-many-cgu/Makefile index 0cab955f6442b..d12a23fbbf013 100644 --- a/src/test/run-make-fulldeps/inline-always-many-cgu/Makefile +++ b/src/test/run-make-fulldeps/inline-always-many-cgu/Makefile @@ -1,7 +1,12 @@ -include ../tools.mk all: - $(RUSTC) foo.rs --emit llvm-ir -C codegen-units=2 + $(RUSTC) foo.rs --emit llvm-ir -C codegen-units=2 -C opt-level=0 + if ![cat $(TMPDIR)/*.ll | $(CGREP) -e '\bcall\b']; then \ + echo "not found call instruction when one was expected"; \ + exit 1; \ + fi + $(RUSTC) foo.rs --emit llvm-ir -C codegen-units=2 -C opt-level=1 if cat $(TMPDIR)/*.ll | $(CGREP) -e '\bcall\b'; then \ echo "found call instruction when one wasn't expected"; \ exit 1; \