Skip to content

Commit 0f4bb2f

Browse files
committed
Rollup merge of #50046 - michaelwoerister:backport-no-debug, r=alexcrichton
Backport of #49904 See #49904.
2 parents 7e2aada + 775d70b commit 0f4bb2f

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

src/librustc/hir/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,7 @@ bitflags! {
22802280
const NAKED = 0b0001_0000;
22812281
const NO_MANGLE = 0b0010_0000;
22822282
const RUSTC_STD_INTERNAL_SYMBOL = 0b0100_0000;
2283+
const NO_DEBUG = 0b1000_0000;
22832284
}
22842285
}
22852286

src/librustc_driver/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#![feature(quote)]
2525
#![feature(rustc_diagnostic_macros)]
2626
#![feature(set_stdio)]
27+
#![feature(no_debug)]
2728

2829
extern crate arena;
2930
extern crate getopts;
@@ -230,6 +231,9 @@ fn load_backend_from_dylib(path: &Path) -> fn() -> Box<TransCrate> {
230231

231232
pub fn get_trans(sess: &Session) -> Box<TransCrate> {
232233
static INIT: Once = ONCE_INIT;
234+
235+
#[allow(deprecated)]
236+
#[no_debug]
233237
static mut LOAD: fn() -> Box<TransCrate> = || unreachable!();
234238

235239
INIT.call_once(|| {

src/librustc_trans/debuginfo/metadata.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use llvm::{self, ValueRef};
2323
use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor,
2424
DICompositeType, DILexicalBlock, DIFlags};
2525

26+
use rustc::hir::TransFnAttrFlags;
2627
use rustc::hir::def::CtorKind;
2728
use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
2829
use rustc::ty::fold::TypeVisitor;
@@ -41,7 +42,7 @@ use std::ffi::CString;
4142
use std::fmt::Write;
4243
use std::ptr;
4344
use std::path::{Path, PathBuf};
44-
use syntax::{ast, attr};
45+
use syntax::ast;
4546
use syntax::symbol::{Interner, InternedString, Symbol};
4647
use syntax_pos::{self, Span, FileName};
4748

@@ -1644,11 +1645,17 @@ pub fn create_global_var_metadata(cx: &CodegenCx,
16441645
}
16451646

16461647
let tcx = cx.tcx;
1647-
let no_mangle = attr::contains_name(&tcx.get_attrs(def_id), "no_mangle");
1648+
let attrs = tcx.trans_fn_attrs(def_id);
1649+
1650+
if attrs.flags.contains(TransFnAttrFlags::NO_DEBUG) {
1651+
return;
1652+
}
1653+
1654+
let no_mangle = attrs.flags.contains(TransFnAttrFlags::NO_MANGLE);
16481655
// We may want to remove the namespace scope if we're in an extern block, see:
16491656
// https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952
16501657
let var_scope = get_namespace_for_item(cx, def_id);
1651-
let span = cx.tcx.def_span(def_id);
1658+
let span = tcx.def_span(def_id);
16521659

16531660
let (file_metadata, line_number) = if span != syntax_pos::DUMMY_SP {
16541661
let loc = span_start(cx, span);

src/librustc_trans/debuginfo/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ use self::source_loc::InternalDebugLocation::{self, UnknownLocation};
2323
use llvm;
2424
use llvm::{ModuleRef, ContextRef, ValueRef};
2525
use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilderRef, DISubprogram, DIArray, DIFlags};
26+
use rustc::hir::TransFnAttrFlags;
2627
use rustc::hir::def_id::{DefId, CrateNum};
2728
use rustc::ty::subst::Substs;
2829

2930
use abi::Abi;
3031
use common::CodegenCx;
3132
use builder::Builder;
3233
use monomorphize::Instance;
33-
use rustc::ty::{self, ParamEnv, Ty};
34+
use rustc::ty::{self, ParamEnv, Ty, InstanceDef};
3435
use rustc::mir;
3536
use rustc::session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
3637
use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet};
@@ -210,13 +211,12 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
210211
return FunctionDebugContext::DebugInfoDisabled;
211212
}
212213

213-
for attr in instance.def.attrs(cx.tcx).iter() {
214-
if attr.check_name("no_debug") {
214+
if let InstanceDef::Item(def_id) = instance.def {
215+
if cx.tcx.trans_fn_attrs(def_id).flags.contains(TransFnAttrFlags::NO_DEBUG) {
215216
return FunctionDebugContext::FunctionWithoutDebugInfo;
216217
}
217218
}
218219

219-
let containing_scope = get_containing_scope(cx, instance);
220220
let span = mir.span;
221221

222222
// This can be the case for functions inlined from another crate
@@ -226,6 +226,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
226226
}
227227

228228
let def_id = instance.def_id();
229+
let containing_scope = get_containing_scope(cx, instance);
229230
let loc = span_start(cx, span);
230231
let file_metadata = file_metadata(cx, &loc.file.name, def_id.krate);
231232

src/librustc_typeck/collect.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,8 @@ fn trans_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> TransFnAt
17851785
trans_fn_attrs.flags |= TransFnAttrFlags::NO_MANGLE;
17861786
} else if attr.check_name("rustc_std_internal_symbol") {
17871787
trans_fn_attrs.flags |= TransFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
1788+
} else if attr.check_name("no_debug") {
1789+
trans_fn_attrs.flags |= TransFnAttrFlags::NO_DEBUG;
17881790
} else if attr.check_name("inline") {
17891791
trans_fn_attrs.inline = attrs.iter().fold(InlineAttr::None, |ia, attr| {
17901792
if attr.path != "inline" {

0 commit comments

Comments
 (0)