Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of #49904 #50046

Merged
merged 4 commits into from
Apr 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(set_stdio)]
#![feature(no_debug)]

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

pub fn get_trans(sess: &Session) -> Box<TransCrate> {
static INIT: Once = ONCE_INIT;

#[allow(deprecated)]
#[no_debug]
static mut LOAD: fn() -> Box<TransCrate> = || unreachable!();

INIT.call_once(|| {
Expand Down
13 changes: 10 additions & 3 deletions src/librustc_trans/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};

Expand Down Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_trans/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ 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;

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};
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down