Skip to content

Commit

Permalink
Auto merge of #69919 - Centril:rollup-fxo33zs, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - #66472 (--show-coverage json)
 - #69603 (tidy: replace `make check` with `./x.py test` in documentation)
 - #69760 (Improve expression & attribute parsing)
 - #69828 (fix memory leak when vec::IntoIter panics during drop)
 - #69850 (panic_bounds_check: use caller_location, like PanicFnLangItem)
 - #69876 (Add long error explanation for E0739)
 - #69888 ([Miri] Use a session variable instead of checking for an env var always)
 - #69893 (librustc_codegen_llvm: Use slices instead of 0-terminated strings)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Mar 11, 2020
2 parents 303d8af + a77206f commit c20d7ee
Show file tree
Hide file tree
Showing 92 changed files with 1,262 additions and 511 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ the issue in question.
Please make sure your pull request is in compliance with Rust's style
guidelines by running

$ python x.py test src/tools/tidy
$ python x.py test tidy

Make this check before every pull request (and every new commit in a pull
request); you can add [git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ The script accepts commands, flags, and arguments to determine what to do:
# run all unit tests
./x.py test
# execute tool tests
./x.py test tidy
# execute the UI test suite
./x.py test src/test/ui
Expand Down
6 changes: 5 additions & 1 deletion src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ Arguments:
subcommand_help.push_str(
"\n
Arguments:
This subcommand accepts a number of paths to directories to tests that
This subcommand accepts a number of paths to test directories that
should be compiled and run. For example:
./x.py test src/test/ui
Expand All @@ -372,6 +372,10 @@ Arguments:
just like `build src/libstd --stage N` it tests the compiler produced by the previous
stage.
Execute tool tests with a tool name argument:
./x.py test tidy
If no arguments are passed then the complete artifacts for that stage are
compiled and tested.
Expand Down
16 changes: 12 additions & 4 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2626,13 +2626,21 @@ impl<T: Clone> Clone for IntoIter<T> {
#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<#[may_dangle] T> Drop for IntoIter<T> {
fn drop(&mut self) {
struct DropGuard<'a, T>(&'a mut IntoIter<T>);

impl<T> Drop for DropGuard<'_, T> {
fn drop(&mut self) {
// RawVec handles deallocation
let _ = unsafe { RawVec::from_raw_parts(self.0.buf.as_ptr(), self.0.cap) };
}
}

let guard = DropGuard(self);
// destroy the remaining elements
unsafe {
ptr::drop_in_place(self.as_mut_slice());
ptr::drop_in_place(guard.0.as_mut_slice());
}

// RawVec handles deallocation
let _ = unsafe { RawVec::from_raw_parts(self.buf.as_ptr(), self.cap) };
// now `guard` will be dropped and do the rest
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/libcore/macros/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(bootstrap)]
#[doc(include = "panic.md")]
#[macro_export]
#[allow_internal_unstable(core_panic, track_caller)]
Expand All @@ -20,6 +21,26 @@ macro_rules! panic {
);
}

#[cfg(not(bootstrap))]
#[doc(include = "panic.md")]
#[macro_export]
#[allow_internal_unstable(core_panic, track_caller)]
#[stable(feature = "core", since = "1.6.0")]
macro_rules! panic {
() => (
$crate::panic!("explicit panic")
);
($msg:expr) => (
$crate::panicking::panic($msg)
);
($msg:expr,) => (
$crate::panic!($msg)
);
($fmt:expr, $($arg:tt)+) => (
$crate::panicking::panic_fmt($crate::format_args!($fmt, $($arg)+))
);
}

/// Asserts that two expressions are equal to each other (using [`PartialEq`]).
///
/// On panic, this macro will print the values of the expressions with their
Expand Down
30 changes: 28 additions & 2 deletions src/libcore/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use crate::fmt;
use crate::panic::{Location, PanicInfo};

/// The underlying implementation of libcore's `panic!` macro when no formatting is used.
#[cold]
// never inline unless panic_immediate_abort to avoid code
// bloat at the call sites as much as possible
Expand All @@ -49,9 +50,28 @@ pub fn panic(expr: &str) -> ! {
// truncation and padding (even though none is used here). Using
// Arguments::new_v1 may allow the compiler to omit Formatter::pad from the
// output binary, saving up to a few kilobytes.
panic_fmt(fmt::Arguments::new_v1(&[expr], &[]), Location::caller())
#[cfg(not(bootstrap))]
panic_fmt(fmt::Arguments::new_v1(&[expr], &[]));
#[cfg(bootstrap)]
panic_fmt(fmt::Arguments::new_v1(&[expr], &[]), Location::caller());
}

#[cfg(not(bootstrap))]
#[cold]
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
#[track_caller]
#[lang = "panic_bounds_check"] // needed by codegen for panic on OOB array/slice access
fn panic_bounds_check(index: usize, len: usize) -> ! {
if cfg!(feature = "panic_immediate_abort") {
unsafe { super::intrinsics::abort() }
}

panic!("index out of bounds: the len is {} but the index is {}", len, index)
}

// For bootstrap, we need a variant with the old argument order, and a corresponding
// `panic_fmt`.
#[cfg(bootstrap)]
#[cold]
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
#[lang = "panic_bounds_check"] // needed by codegen for panic on OOB array/slice access
Expand All @@ -66,10 +86,12 @@ fn panic_bounds_check(location: &Location<'_>, index: usize, len: usize) -> ! {
)
}

/// The underlying implementation of libcore's `panic!` macro when formatting is used.
#[cold]
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
#[cfg_attr(feature = "panic_immediate_abort", inline)]
pub fn panic_fmt(fmt: fmt::Arguments<'_>, location: &Location<'_>) -> ! {
#[cfg_attr(not(bootstrap), track_caller)]
pub fn panic_fmt(fmt: fmt::Arguments<'_>, #[cfg(bootstrap)] location: &Location<'_>) -> ! {
if cfg!(feature = "panic_immediate_abort") {
unsafe { super::intrinsics::abort() }
}
Expand All @@ -81,6 +103,10 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>, location: &Location<'_>) -> ! {
fn panic_impl(pi: &PanicInfo<'_>) -> !;
}

#[cfg(bootstrap)]
let pi = PanicInfo::internal_constructor(Some(&fmt), location);
#[cfg(not(bootstrap))]
let pi = PanicInfo::internal_constructor(Some(&fmt), Location::caller());

unsafe { panic_impl(&pi) }
}
33 changes: 20 additions & 13 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ use crate::mir;
use crate::mir::interpret::ConstValue;
use crate::ty::layout::{Align, LayoutError, Size};
use crate::ty::query::TyCtxtAt;
use crate::ty::tls;
use crate::ty::{self, layout, Ty};

use backtrace::Backtrace;
use rustc_data_structures::sync::Lock;
use rustc_errors::{struct_span_err, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_macros::HashStable;
use rustc_session::CtfeBacktrace;
use rustc_span::{Pos, Span};
use rustc_target::spec::abi::Abi;
use std::{any::Any, env, fmt};
use std::{any::Any, fmt};

#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable, RustcEncodable, RustcDecodable)]
pub enum ErrorHandled {
Expand Down Expand Up @@ -257,21 +260,25 @@ impl From<ErrorHandled> for InterpErrorInfo<'_> {

impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {
fn from(kind: InterpError<'tcx>) -> Self {
let backtrace = match env::var("RUSTC_CTFE_BACKTRACE") {
// Matching `RUST_BACKTRACE` -- we treat "0" the same as "not present".
Ok(ref val) if val != "0" => {
let mut backtrace = Backtrace::new_unresolved();
let capture_backtrace = tls::with_context_opt(|ctxt| {
if let Some(ctxt) = ctxt {
*Lock::borrow(&ctxt.tcx.sess.ctfe_backtrace)
} else {
CtfeBacktrace::Disabled
}
});

if val == "immediate" {
// Print it now.
print_backtrace(&mut backtrace);
None
} else {
Some(Box::new(backtrace))
}
let backtrace = match capture_backtrace {
CtfeBacktrace::Disabled => None,
CtfeBacktrace::Capture => Some(Box::new(Backtrace::new_unresolved())),
CtfeBacktrace::Immediate => {
// Print it now.
let mut backtrace = Backtrace::new_unresolved();
print_backtrace(&mut backtrace);
None
}
_ => None,
};

InterpErrorInfo { kind, backtrace }
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/librustc_ast/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,16 @@ impl Token {
false
}

// Is the token an interpolated block (`$b:block`)?
pub fn is_whole_block(&self) -> bool {
if let Interpolated(ref nt) = self.kind {
if let NtBlock(..) = **nt {
return true;
}
}
false
}

/// Returns `true` if the token is either the `mut` or `const` keyword.
pub fn is_mutability(&self) -> bool {
self.is_keyword(kw::Mut) || self.is_keyword(kw::Const)
Expand Down
21 changes: 7 additions & 14 deletions src/librustc_codegen_llvm/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::ffi::CString;

use crate::attributes;
use libc::c_uint;
use rustc::bug;
Expand Down Expand Up @@ -50,8 +48,8 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut ModuleLlvm, kind: Alloc
args.len() as c_uint,
False,
);
let name = CString::new(format!("__rust_{}", method.name)).unwrap();
let llfn = llvm::LLVMRustGetOrInsertFunction(llmod, name.as_ptr(), ty);
let name = format!("__rust_{}", method.name);
let llfn = llvm::LLVMRustGetOrInsertFunction(llmod, name.as_ptr().cast(), name.len(), ty);

if tcx.sess.target.target.options.default_hidden_visibility {
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
Expand All @@ -60,8 +58,9 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut ModuleLlvm, kind: Alloc
attributes::emit_uwtable(llfn, true);
}

let callee = CString::new(kind.fn_name(method.name)).unwrap();
let callee = llvm::LLVMRustGetOrInsertFunction(llmod, callee.as_ptr(), ty);
let callee = kind.fn_name(method.name);
let callee =
llvm::LLVMRustGetOrInsertFunction(llmod, callee.as_ptr().cast(), callee.len(), ty);
llvm::LLVMRustSetVisibility(callee, llvm::Visibility::Hidden);

let llbb = llvm::LLVMAppendBasicBlockInContext(llcx, llfn, "entry\0".as_ptr().cast());
Expand All @@ -73,14 +72,8 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut ModuleLlvm, kind: Alloc
.enumerate()
.map(|(i, _)| llvm::LLVMGetParam(llfn, i as c_uint))
.collect::<Vec<_>>();
let ret = llvm::LLVMRustBuildCall(
llbuilder,
callee,
args.as_ptr(),
args.len() as c_uint,
None,
"\0".as_ptr().cast(),
);
let ret =
llvm::LLVMRustBuildCall(llbuilder, callee, args.as_ptr(), args.len() as c_uint, None);
llvm::LLVMSetTailCall(ret, True);
if output.is_some() {
llvm::LLVMBuildRet(llbuilder, ret);
Expand Down
22 changes: 11 additions & 11 deletions src/librustc_codegen_llvm/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use rustc_span::Span;

use libc::{c_char, c_uint};
use log::debug;
use std::ffi::{CStr, CString};

impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
fn codegen_inline_asm(
Expand Down Expand Up @@ -80,12 +79,11 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
_ => self.type_struct(&output_types, false),
};

let asm = CString::new(ia.asm.as_str().as_bytes()).unwrap();
let constraint_cstr = CString::new(all_constraints).unwrap();
let asm = ia.asm.as_str();
let r = inline_asm_call(
self,
&asm,
&constraint_cstr,
&all_constraints,
&inputs,
output_type,
ia.volatile,
Expand Down Expand Up @@ -125,17 +123,17 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {

impl AsmMethods for CodegenCx<'ll, 'tcx> {
fn codegen_global_asm(&self, ga: &hir::GlobalAsm) {
let asm = CString::new(ga.asm.as_str().as_bytes()).unwrap();
let asm = ga.asm.as_str();
unsafe {
llvm::LLVMRustAppendModuleInlineAsm(self.llmod, asm.as_ptr());
llvm::LLVMRustAppendModuleInlineAsm(self.llmod, asm.as_ptr().cast(), asm.len());
}
}
}

fn inline_asm_call(
bx: &mut Builder<'a, 'll, 'tcx>,
asm: &CStr,
cons: &CStr,
asm: &str,
cons: &str,
inputs: &[&'ll Value],
output: &'ll llvm::Type,
volatile: bool,
Expand All @@ -157,13 +155,15 @@ fn inline_asm_call(
let fty = bx.cx.type_func(&argtys[..], output);
unsafe {
// Ask LLVM to verify that the constraints are well-formed.
let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr());
let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons.as_ptr().cast(), cons.len());
debug!("constraint verification result: {:?}", constraints_ok);
if constraints_ok {
let v = llvm::LLVMRustInlineAsm(
fty,
asm.as_ptr(),
cons.as_ptr(),
asm.as_ptr().cast(),
asm.len(),
cons.as_ptr().cast(),
cons.len(),
volatile,
alignstack,
llvm::AsmDialect::from_generic(dia),
Expand Down
1 change: 0 additions & 1 deletion src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
args.as_ptr() as *const &llvm::Value,
args.len() as c_uint,
bundle,
UNNAMED,
)
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/librustc_codegen_llvm/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::value::Value;
use log::debug;
use rustc::ty::Ty;
use rustc_codegen_ssa::traits::*;
use rustc_data_structures::small_c_str::SmallCStr;

/// Declare a function.
///
Expand All @@ -34,8 +33,9 @@ fn declare_raw_fn(
ty: &'ll Type,
) -> &'ll Value {
debug!("declare_raw_fn(name={:?}, ty={:?})", name, ty);
let namebuf = SmallCStr::new(name);
let llfn = unsafe { llvm::LLVMRustGetOrInsertFunction(cx.llmod, namebuf.as_ptr(), ty) };
let llfn = unsafe {
llvm::LLVMRustGetOrInsertFunction(cx.llmod, name.as_ptr().cast(), name.len(), ty)
};

llvm::SetFunctionCallConv(llfn, callconv);
// Function addresses in Rust are never significant, allowing functions to
Expand Down Expand Up @@ -83,8 +83,7 @@ impl DeclareMethods<'tcx> for CodegenCx<'ll, 'tcx> {

fn get_declared_value(&self, name: &str) -> Option<&'ll Value> {
debug!("get_declared_value(name={:?})", name);
let namebuf = SmallCStr::new(name);
unsafe { llvm::LLVMRustGetNamedValue(self.llmod, namebuf.as_ptr()) }
unsafe { llvm::LLVMRustGetNamedValue(self.llmod, name.as_ptr().cast(), name.len()) }
}

fn get_defined_value(&self, name: &str) -> Option<&'ll Value> {
Expand Down
Loading

0 comments on commit c20d7ee

Please sign in to comment.