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

Rollup of 7 pull requests #73388

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a6127e3
Merge pull request #1 from rust-lang/master
richkadel May 22, 2020
591584e
Add tests for 'impl Default for [T; N]'
MikailBag May 26, 2020
3313bf6
Skip leak test on targets without panic=unwind
MikailBag May 28, 2020
d139a72
Merge pull request #2 from rust-lang/master
richkadel Jun 10, 2020
64a6de2
Join mutiple lines if it is more readable
tesuji Jun 15, 2020
9e51008
Complete the std::time documentation to warn about the inconsistencie…
poliorcetics Jun 15, 2020
fe7456c
Use track caller for bug! macro
tesuji Jun 15, 2020
e857696
Tweak "non-primitive cast" error
estebank Jun 15, 2020
b34a417
Add more info to `x.py build --help` on default value for `-j JOBS`.
pnkfelix Jun 15, 2020
71c54db
Fix typo in docs of std::mem
ratijas Jun 15, 2020
395256a
Merge pull request #3 from rust-lang/master
richkadel Jun 15, 2020
5068ae1
[WIP] injects llvm intrinsic instrprof.increment for coverage reports
richkadel Jun 4, 2020
088037a
explained lang_item function body (count_code_region)
richkadel Jun 5, 2020
2c5c2a6
removed experiments for cleaner github PR
richkadel Jun 5, 2020
d2cd59a
Add case for count_code_region() extern lang_item
richkadel Jun 5, 2020
e4df7e7
Update src/libcore/intrinsics.rs
richkadel Jun 5, 2020
7e49a9e
moved to post_borrowck_cleanup & used MirPatch
richkadel Jun 8, 2020
46ebd57
moved instrument_coverage pass, optimized scalar, added FIXME
richkadel Jun 8, 2020
20aba8f
added test, Operand::const_from_scalar, require_lang_item, & comments
richkadel Jun 10, 2020
163e585
updated mir-opt test due to other recent changes to MIR
richkadel Jun 10, 2020
98685a4
Add new `fn_span` to TerminatorKind::Call instance
richkadel Jun 16, 2020
850ab63
Rollup merge of #72628 - MikailBag:array-default-tests, r=shepmaster
Dylan-DPC Jun 16, 2020
4dc89e1
Rollup merge of #72836 - poliorcetics:std-time-os-specificities, r=sh…
Dylan-DPC Jun 16, 2020
395c43d
Rollup merge of #73011 - richkadel:llvm-count-from-mir-pass, r=tmandry
Dylan-DPC Jun 16, 2020
3c22203
Rollup merge of #73361 - estebank:non-primitive-cast, r=davidtwco
Dylan-DPC Jun 16, 2020
8d9fb24
Rollup merge of #73373 - lzutao:bug-trackcaller, r=Amanieu
Dylan-DPC Jun 16, 2020
dfce764
Rollup merge of #73380 - pnkfelix:make-bootstrap-help-print-num-cpus,…
Dylan-DPC Jun 16, 2020
11999c4
Rollup merge of #73381 - ratijas:fix-typo-std-mem, r=jonas-schievink
Dylan-DPC Jun 16, 2020
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
7 changes: 6 additions & 1 deletion src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
"N",
);
opts.optopt("", "src", "path to the root of the rust checkout", "DIR");
opts.optopt("j", "jobs", "number of jobs to run in parallel", "JOBS");
let j_msg = format!(
"number of jobs to run in parallel; \
defaults to {} (this host's logical CPU count)",
num_cpus::get()
);
opts.optopt("j", "jobs", &j_msg, "JOBS");
opts.optflag("h", "help", "print this help message");
opts.optopt(
"",
Expand Down
1 change: 1 addition & 0 deletions src/libcore/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ pub trait Into<T>: Sized {
/// [`Into`]: trait.Into.html
/// [`from`]: trait.From.html#tymethod.from
/// [book]: ../../book/ch09-00-error-handling.html
#[rustc_diagnostic_item = "from_trait"]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_on_unimplemented(on(
all(_Self = "&str", T = "std::string::String"),
Expand Down
7 changes: 7 additions & 0 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,13 @@ extern "rust-intrinsic" {
///
/// Perma-unstable: do not use.
pub fn miri_start_panic(payload: *mut u8) -> !;

/// Internal placeholder for injecting code coverage counters when the "instrument-coverage"
/// option is enabled. The placeholder is replaced with `llvm.instrprof.increment` during code
/// generation.
#[cfg(not(bootstrap))]
#[lang = "count_code_region"]
pub fn count_code_region(_index: u32);
}

// Some functions are defined here because they accidentally got made
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub use crate::intrinsics::transmute;
/// erring on the side of (double-)dropping.
///
/// Also, `ManuallyDrop` prevents us from having to "touch" `v` after transferring the
/// ownership to `s` - the final step of interacting with `v` to dispoe of it without
/// ownership to `s` the final step of interacting with `v` to dispose of it without
/// running its destructor is entirely avoided.
///
/// [drop]: fn.drop.html
Expand Down
9 changes: 3 additions & 6 deletions src/libcore/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ pub struct PanicInfo<'a> {
impl<'a> PanicInfo<'a> {
#[unstable(
feature = "panic_internals",
reason = "internal details of the implementation of the `panic!` \
and related macros",
reason = "internal details of the implementation of the `panic!` and related macros",
issue = "none"
)]
#[doc(hidden)]
Expand All @@ -55,8 +54,7 @@ impl<'a> PanicInfo<'a> {

#[unstable(
feature = "panic_internals",
reason = "internal details of the implementation of the `panic!` \
and related macros",
reason = "internal details of the implementation of the `panic!` and related macros",
issue = "none"
)]
#[doc(hidden)]
Expand Down Expand Up @@ -244,8 +242,7 @@ impl<'a> Location<'a> {
impl<'a> Location<'a> {
#![unstable(
feature = "panic_internals",
reason = "internal details of the implementation of the `panic!` \
and related macros",
reason = "internal details of the implementation of the `panic!` and related macros",
issue = "none"
)]
#[doc(hidden)]
Expand Down
3 changes: 1 addition & 2 deletions src/libcore/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#![allow(dead_code, missing_docs)]
#![unstable(
feature = "core_panic",
reason = "internal details of the implementation of the `panic!` \
and related macros",
reason = "internal details of the implementation of the `panic!` and related macros",
issue = "none"
)]

Expand Down
49 changes: 49 additions & 0 deletions src/libcore/tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,52 @@ fn iterator_drops() {
}
assert_eq!(i.get(), 5);
}

// This test does not work on targets without panic=unwind support.
// To work around this problem, test is marked is should_panic, so it will
// be automagically skipped on unsuitable targets, such as
// wasm32-unknown-unkown.
//
// It means that we use panic for indicating success.
#[test]
#[should_panic(expected = "test succeeded")]
fn array_default_impl_avoids_leaks_on_panic() {
use core::sync::atomic::{AtomicUsize, Ordering::Relaxed};
static COUNTER: AtomicUsize = AtomicUsize::new(0);
#[derive(Debug)]
struct Bomb(usize);

impl Default for Bomb {
fn default() -> Bomb {
if COUNTER.load(Relaxed) == 3 {
panic!("bomb limit exceeded");
}

COUNTER.fetch_add(1, Relaxed);
Bomb(COUNTER.load(Relaxed))
}
}

impl Drop for Bomb {
fn drop(&mut self) {
COUNTER.fetch_sub(1, Relaxed);
}
}

let res = std::panic::catch_unwind(|| <[Bomb; 5]>::default());
let panic_msg = match res {
Ok(_) => unreachable!(),
Err(p) => p.downcast::<&'static str>().unwrap(),
};
assert_eq!(*panic_msg, "bomb limit exceeded");
// check that all bombs are successfully dropped
assert_eq!(COUNTER.load(Relaxed), 0);
panic!("test succeeded")
}

#[test]
fn empty_array_is_always_default() {
struct DoesNotImplDefault;

let _arr = <[DoesNotImplDefault; 0]>::default();
}
27 changes: 27 additions & 0 deletions src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,33 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
self.call_lifetime_intrinsic("llvm.lifetime.end.p0i8", ptr, size);
}

fn instrprof_increment(
&mut self,
fn_name: &'ll Value,
hash: &'ll Value,
num_counters: &'ll Value,
index: &'ll Value,
) -> &'ll Value {
debug!(
"instrprof_increment() with args ({:?}, {:?}, {:?}, {:?})",
fn_name, hash, num_counters, index
);

let llfn = unsafe { llvm::LLVMRustGetInstrprofIncrementIntrinsic(self.cx().llmod) };
let args = &[fn_name, hash, num_counters, index];
let args = self.check_call("call", llfn, args);

unsafe {
llvm::LLVMRustBuildCall(
self.llbuilder,
llfn,
args.as_ptr() as *const &llvm::Value,
args.len() as c_uint,
None,
)
}
}

fn call(
&mut self,
llfn: &'ll Value,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,8 @@ impl CodegenCx<'b, 'tcx> {
ifn!("llvm.lifetime.start.p0i8", fn(t_i64, i8p) -> void);
ifn!("llvm.lifetime.end.p0i8", fn(t_i64, i8p) -> void);

ifn!("llvm.instrprof.increment", fn(i8p, t_i64, t_i32, t_i32) -> void);

ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
ifn!("llvm.eh.typeid.for", fn(i8p) -> t_i32);
ifn!("llvm.localescape", fn(...) -> void);
Expand Down
26 changes: 26 additions & 0 deletions src/librustc_codegen_llvm/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::type_of::LayoutLlvmExt;
use crate::va_arg::emit_va_arg;
use crate::value::Value;

use log::debug;

use rustc_ast::ast;
use rustc_codegen_ssa::base::{compare_simd_types, to_immediate, wants_msvc_seh};
use rustc_codegen_ssa::common::span_invalid_monomorphization_error;
Expand All @@ -21,6 +23,7 @@ use rustc_middle::ty::layout::{FnAbiExt, HasTyCtxt};
use rustc_middle::ty::{self, Ty};
use rustc_middle::{bug, span_bug};
use rustc_span::Span;
use rustc_span::Symbol;
use rustc_target::abi::{self, HasDataLayout, LayoutOf, Primitive};
use rustc_target::spec::PanicStrategy;

Expand Down Expand Up @@ -86,6 +89,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
args: &[OperandRef<'tcx, &'ll Value>],
llresult: &'ll Value,
span: Span,
caller_instance: ty::Instance<'tcx>,
) {
let tcx = self.tcx;
let callee_ty = instance.monomorphic_ty(tcx);
Expand Down Expand Up @@ -136,6 +140,28 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
let llfn = self.get_intrinsic(&("llvm.debugtrap"));
self.call(llfn, &[], None)
}
"count_code_region" => {
if let ty::InstanceDef::Item(fn_def_id) = caller_instance.def {
let caller_fn_path = tcx.def_path_str(fn_def_id);
debug!(
"count_code_region to llvm.instrprof.increment(fn_name={})",
caller_fn_path
);

// FIXME(richkadel): (1) Replace raw function name with mangled function name;
// (2) Replace hardcoded `1234` in `hash` with a computed hash (as discussed in)
// the MCP (compiler-team/issues/278); and replace the hardcoded `1` for
// `num_counters` with the actual number of counters per function (when the
// changes are made to inject more than one counter per function).
let (fn_name, _len_val) = self.const_str(Symbol::intern(&caller_fn_path));
let index = args[0].immediate();
let hash = self.const_u64(1234);
let num_counters = self.const_u32(1);
self.instrprof_increment(fn_name, hash, num_counters, index)
} else {
bug!("intrinsic count_code_region: no src.instance");
}
}
"va_start" => self.va_start(args[0].immediate()),
"va_end" => self.va_end(args[0].immediate()),
"va_copy" => {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,7 @@ extern "C" {

// Miscellaneous instructions
pub fn LLVMBuildPhi(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
pub fn LLVMRustGetInstrprofIncrementIntrinsic(M: &Module) -> &'a Value;
pub fn LLVMRustBuildCall(
B: &Builder<'a>,
Fn: &'a Value,
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ impl ModuleConfig {
if sess.opts.debugging_opts.profile && !is_compiler_builtins {
passes.push("insert-gcov-profiling".to_owned());
}

// The rustc option `-Zinstrument_coverage` injects intrinsic calls to
// `llvm.instrprof.increment()`, which requires the LLVM `instrprof` pass.
if sess.opts.debugging_opts.instrument_coverage {
passes.push("instrprof".to_owned());
}
passes
},
vec![]
Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
&args,
dest,
terminator.source_info.span,
self.instance,
);

if let ReturnDest::IndirectOperand(dst, _) = ret_dest {
Expand Down
8 changes: 8 additions & 0 deletions src/librustc_codegen_ssa/traits/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ pub trait BuilderMethods<'a, 'tcx>:
/// Called for `StorageDead`
fn lifetime_end(&mut self, ptr: Self::Value, size: Size);

fn instrprof_increment(
&mut self,
fn_name: Self::Value,
hash: Self::Value,
num_counters: Self::Value,
index: Self::Value,
) -> Self::Value;

fn call(
&mut self,
llfn: Self::Value,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_ssa/traits/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub trait IntrinsicCallMethods<'tcx>: BackendTypes {
args: &[OperandRef<'tcx, Self::Value>],
llresult: Self::Value,
span: Span,
caller_instance: ty::Instance<'tcx>,
);

fn abort(&mut self);
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_hir/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ language_item_table! {

StartFnLangItem, "start", start_fn, Target::Fn;

CountCodeRegionFnLangItem, "count_code_region", count_code_region_fn, Target::Fn;

EhPersonalityLangItem, "eh_personality", eh_personality, Target::Fn;
EhCatchTypeinfoLangItem, "eh_catch_typeinfo", eh_catch_typeinfo, Target::Static;

Expand Down
1 change: 1 addition & 0 deletions src/librustc_interface/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ fn test_debugging_options_tracking_hash() {
tracked!(human_readable_cgu_names, true);
tracked!(inline_in_all_cgus, Some(true));
tracked!(insert_sideeffect, true);
tracked!(instrument_coverage, true);
tracked!(instrument_mcount, true);
tracked!(link_only, true);
tracked!(merge_functions, Some(MergeFunctions::Disabled));
Expand Down
18 changes: 11 additions & 7 deletions src/librustc_middle/macros.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#[macro_export]
macro_rules! bug {
() => ( bug!("impossible case reached") );
($($message:tt)*) => ({
$crate::util::bug::bug_fmt(file!(), line!(), format_args!($($message)*))
})
() => ( $crate::bug!("impossible case reached") );
($msg:expr) => ({ $crate::util::bug::bug_fmt(::std::format_args!($msg)) });
($msg:expr,) => ({ $crate::bug!($msg) });
($fmt:expr, $($arg:tt)+) => ({
$crate::util::bug::bug_fmt(::std::format_args!($fmt, $($arg)+))
});
}

#[macro_export]
macro_rules! span_bug {
($span:expr, $($message:tt)*) => ({
$crate::util::bug::span_bug_fmt(file!(), line!(), $span, format_args!($($message)*))
})
($span:expr, $msg:expr) => ({ $crate::util::bug::span_bug_fmt($span, ::std::format_args!($msg)) });
($span:expr, $msg:expr,) => ({ $crate::span_bug!($span, $msg) });
($span:expr, $fmt:expr, $($arg:tt)+) => ({
$crate::util::bug::span_bug_fmt($span, ::std::format_args!($fmt, $($arg)+))
});
}

///////////////////////////////////////////////////////////////////////////
Expand Down
28 changes: 28 additions & 0 deletions src/librustc_middle/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use rustc_macros::HashStable;
use rustc_serialize::{Decodable, Encodable};
use rustc_span::symbol::Symbol;
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi;
use rustc_target::asm::InlineAsmRegOrRegClass;
use std::borrow::Cow;
use std::fmt::{self, Debug, Display, Formatter, Write};
Expand Down Expand Up @@ -2218,6 +2219,33 @@ impl<'tcx> Operand<'tcx> {
})
}

/// Convenience helper to make a literal-like constant from a given scalar value.
/// Since this is used to synthesize MIR, assumes `user_ty` is None.
pub fn const_from_scalar(
tcx: TyCtxt<'tcx>,
ty: Ty<'tcx>,
val: Scalar,
span: Span,
) -> Operand<'tcx> {
debug_assert!({
let param_env_and_ty = ty::ParamEnv::empty().and(ty);
let type_size = tcx
.layout_of(param_env_and_ty)
.unwrap_or_else(|e| panic!("could not compute layout for {:?}: {:?}", ty, e))
.size;
let scalar_size = abi::Size::from_bytes(match val {
Scalar::Raw { size, .. } => size,
_ => panic!("Invalid scalar type {:?}", val),
});
scalar_size == type_size
});
Operand::Constant(box Constant {
span,
user_ty: None,
literal: ty::Const::from_scalar(tcx, val, ty),
})
}

pub fn to_copy(&self) -> Self {
match *self {
Operand::Copy(_) | Operand::Constant(_) => self.clone(),
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ fn validate_hir_id_for_typeck_tables(
if hir_id.owner != hir_owner {
ty::tls::with(|tcx| {
bug!(
"node {} with HirId::owner {:?} cannot be placed in \
TypeckTables with hir_owner {:?}",
"node {} with HirId::owner {:?} cannot be placed in TypeckTables with hir_owner {:?}",
tcx.hir().node_to_string(hir_id),
hir_id.owner,
hir_owner
Expand Down
Loading