diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index be8cceb611896..a65a461a228ad 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -2280,6 +2280,7 @@ bitflags! { const NAKED = 0b0001_0000; const NO_MANGLE = 0b0010_0000; const RUSTC_STD_INTERNAL_SYMBOL = 0b0100_0000; + const NO_DEBUG = 0b1000_0000; } } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index b9bcbccb30ef3..75416e319cd19 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -24,6 +24,7 @@ #![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(set_stdio)] +#![feature(no_debug)] extern crate arena; extern crate getopts; @@ -230,6 +231,9 @@ fn load_backend_from_dylib(path: &Path) -> fn() -> Box { pub fn get_trans(sess: &Session) -> Box { static INIT: Once = ONCE_INIT; + + #[allow(deprecated)] + #[no_debug] static mut LOAD: fn() -> Box = || unreachable!(); INIT.call_once(|| { diff --git a/src/librustc_trans/debuginfo/metadata.rs b/src/librustc_trans/debuginfo/metadata.rs index f3d95cf794bab..eb550d7a605c5 100644 --- a/src/librustc_trans/debuginfo/metadata.rs +++ b/src/librustc_trans/debuginfo/metadata.rs @@ -23,6 +23,7 @@ use llvm::{self, ValueRef}; use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, DICompositeType, DILexicalBlock, DIFlags}; +use rustc::hir::TransFnAttrFlags; use rustc::hir::def::CtorKind; use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE}; use rustc::ty::fold::TypeVisitor; @@ -41,7 +42,7 @@ use std::ffi::CString; use std::fmt::Write; use std::ptr; use std::path::{Path, PathBuf}; -use syntax::{ast, attr}; +use syntax::ast; use syntax::symbol::{Interner, InternedString, Symbol}; use syntax_pos::{self, Span, FileName}; @@ -1644,11 +1645,17 @@ pub fn create_global_var_metadata(cx: &CodegenCx, } let tcx = cx.tcx; - let no_mangle = attr::contains_name(&tcx.get_attrs(def_id), "no_mangle"); + let attrs = tcx.trans_fn_attrs(def_id); + + if attrs.flags.contains(TransFnAttrFlags::NO_DEBUG) { + return; + } + + let no_mangle = attrs.flags.contains(TransFnAttrFlags::NO_MANGLE); // We may want to remove the namespace scope if we're in an extern block, see: // https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952 let var_scope = get_namespace_for_item(cx, def_id); - let span = cx.tcx.def_span(def_id); + let span = tcx.def_span(def_id); let (file_metadata, line_number) = if span != syntax_pos::DUMMY_SP { let loc = span_start(cx, span); diff --git a/src/librustc_trans/debuginfo/mod.rs b/src/librustc_trans/debuginfo/mod.rs index 7664c88679e0e..762e705e7ed32 100644 --- a/src/librustc_trans/debuginfo/mod.rs +++ b/src/librustc_trans/debuginfo/mod.rs @@ -23,6 +23,7 @@ use self::source_loc::InternalDebugLocation::{self, UnknownLocation}; use llvm; use llvm::{ModuleRef, ContextRef, ValueRef}; use llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilderRef, DISubprogram, DIArray, DIFlags}; +use rustc::hir::TransFnAttrFlags; use rustc::hir::def_id::{DefId, CrateNum}; use rustc::ty::subst::Substs; @@ -30,7 +31,7 @@ use abi::Abi; use common::CodegenCx; use builder::Builder; use monomorphize::Instance; -use rustc::ty::{self, ParamEnv, Ty}; +use rustc::ty::{self, ParamEnv, Ty, InstanceDef}; use rustc::mir; use rustc::session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo}; use rustc::util::nodemap::{DefIdMap, FxHashMap, FxHashSet}; @@ -210,13 +211,12 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, return FunctionDebugContext::DebugInfoDisabled; } - for attr in instance.def.attrs(cx.tcx).iter() { - if attr.check_name("no_debug") { + if let InstanceDef::Item(def_id) = instance.def { + if cx.tcx.trans_fn_attrs(def_id).flags.contains(TransFnAttrFlags::NO_DEBUG) { return FunctionDebugContext::FunctionWithoutDebugInfo; } } - let containing_scope = get_containing_scope(cx, instance); let span = mir.span; // 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>, } let def_id = instance.def_id(); + let containing_scope = get_containing_scope(cx, instance); let loc = span_start(cx, span); let file_metadata = file_metadata(cx, &loc.file.name, def_id.krate); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 59156bf0dfeaa..b2bc5114034d5 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1785,6 +1785,8 @@ fn trans_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> TransFnAt trans_fn_attrs.flags |= TransFnAttrFlags::NO_MANGLE; } else if attr.check_name("rustc_std_internal_symbol") { trans_fn_attrs.flags |= TransFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL; + } else if attr.check_name("no_debug") { + trans_fn_attrs.flags |= TransFnAttrFlags::NO_DEBUG; } else if attr.check_name("inline") { trans_fn_attrs.inline = attrs.iter().fold(InlineAttr::None, |ia, attr| { if attr.path != "inline" {