Skip to content

Rollup of 11 pull requests #67091

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

Merged
merged 25 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b85d5f4
Fix angle bracket formatting when dumping MIR debug vars
osa1 Dec 3, 2019
dc1a428
Modified the testcases for VxWorks
Nov 26, 2019
b6b0fd9
rustdoc: Add test for fixed issue
ollie27 Dec 4, 2019
a8ec620
Remove potential cfgs duplicates
GuillaumeGomez Dec 3, 2019
22d9f20
SGX: Fix target linker used by bootstrap
Dec 4, 2019
16d2178
Migrate to LLVM{Get,Set}ValueName2
cuviper Dec 4, 2019
92bc35f
Simplify {IoSlice, IoSliceMut}::advance examples and tests
tmiasko Dec 5, 2019
8655ad5
codegen: mark invalid SetDiscriminant unreachable
RalfJung Dec 5, 2019
e822235
add a test
RalfJung Dec 5, 2019
e5d50e3
comments
RalfJung Dec 5, 2019
f5bd947
use abort instead of unreachable
RalfJung Dec 5, 2019
5ddfbc2
Fix Query type docs
osa1 Dec 6, 2019
de255a9
Make try_mark_previous_green aware of cycles.
gizmondo Dec 6, 2019
79f8764
Remove boxed closures in address parser.
reitermarkus Dec 6, 2019
2a4f638
Rollup merge of #66846 - gizmondo:master, r=michaelwoerister
JohnTitor Dec 6, 2019
afd9e95
Rollup merge of #66959 - GuillaumeGomez:cfg-duplicates, r=eddyb
JohnTitor Dec 6, 2019
7249af0
Rollup merge of #66988 - osa1:issue66985, r=matthewjasper
JohnTitor Dec 6, 2019
cdbdb68
Rollup merge of #66998 - Wind-River:master_up, r=alexcrichton
JohnTitor Dec 6, 2019
0df1609
Rollup merge of #67008 - ollie27:rustdoc_issue_61732, r=Centril
JohnTitor Dec 6, 2019
fd4cec0
Rollup merge of #67023 - jethrogb:jb/bootstrap-target-linker, r=alexc…
JohnTitor Dec 6, 2019
0b471bf
Rollup merge of #67033 - cuviper:ValueName2, r=rkruppe
JohnTitor Dec 6, 2019
d1397db
Rollup merge of #67049 - tmiasko:io-slice-advance, r=rkruppe
JohnTitor Dec 6, 2019
c85284e
Rollup merge of #67054 - RalfJung:set-discriminant-unreachable, r=oli…
JohnTitor Dec 6, 2019
cc7c45f
Rollup merge of #67081 - osa1:fix_query_type_docs, r=Dylan-DPC
JohnTitor Dec 6, 2019
931be6c
Rollup merge of #67085 - reitermarkus:addr-parser, r=Mark-Simulacrum
JohnTitor Dec 6, 2019
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/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ impl Build {
!target.contains("emscripten") &&
!target.contains("wasm32") &&
!target.contains("nvptx") &&
!target.contains("fortanix") &&
!target.contains("fuchsia") {
Some(self.cc(target))
} else {
Expand Down
21 changes: 16 additions & 5 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,14 +710,25 @@ impl DepGraph {
return None
}
None => {
if !tcx.sess.has_errors() {
if !tcx.sess.has_errors_or_delayed_span_bugs() {
bug!("try_mark_previous_green() - Forcing the DepNode \
should have set its color")
} else {
// If the query we just forced has resulted
// in some kind of compilation error, we
// don't expect that the corresponding
// dep-node color has been updated.
// If the query we just forced has resulted in
// some kind of compilation error, we cannot rely on
// the dep-node color having been properly updated.
// This means that the query system has reached an
// invalid state. We let the compiler continue (by
// returning `None`) so it can emit error messages
// and wind down, but rely on the fact that this
// invalid state will not be persisted to the
// incremental compilation cache because of
// compilation errors being present.
debug!("try_mark_previous_green({:?}) - END - \
dependency {:?} resulted in compilation error",
dep_node,
dep_dep_node);
return None
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rustc_fs_util::{path_to_c_string, link_or_copy};
use rustc_data_structures::small_c_str::SmallCStr;
use errors::{Handler, FatalError};

use std::ffi::{CString, CStr};
use std::ffi::CString;
use std::fs;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -833,16 +833,16 @@ fn create_msvc_imps(
})
.filter_map(|val| {
// Exclude some symbols that we know are not Rust symbols.
let name = CStr::from_ptr(llvm::LLVMGetValueName(val));
if ignored(name.to_bytes()) {
let name = llvm::get_value_name(val);
if ignored(name) {
None
} else {
Some((val, name))
}
})
.map(move |(val, name)| {
let mut imp_name = prefix.as_bytes().to_vec();
imp_name.extend(name.to_bytes());
imp_name.extend(name);
let imp_name = CString::new(imp_name).unwrap();
(imp_name, val)
})
Expand Down
10 changes: 4 additions & 6 deletions src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rustc::ty::layout::{self, Size, Align, LayoutOf};

use rustc::hir::{self, CodegenFnAttrs, CodegenFnAttrFlags};

use std::ffi::{CStr, CString};
use std::ffi::CStr;

pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll Value {
let mut llvals = Vec::with_capacity(alloc.relocations().len() + 1);
Expand Down Expand Up @@ -392,16 +392,14 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
} else {
// If we created the global with the wrong type,
// correct the type.
let empty_string = const_cstr!("");
let name_str_ref = CStr::from_ptr(llvm::LLVMGetValueName(g));
let name_string = CString::new(name_str_ref.to_bytes()).unwrap();
llvm::LLVMSetValueName(g, empty_string.as_ptr());
let name = llvm::get_value_name(g).to_vec();
llvm::set_value_name(g, b"");

let linkage = llvm::LLVMRustGetLinkage(g);
let visibility = llvm::LLVMRustGetVisibility(g);

let new_g = llvm::LLVMRustGetOrInsertGlobal(
self.llmod, name_string.as_ptr(), val_llty);
self.llmod, name.as_ptr().cast(), name.len(), val_llty);

llvm::LLVMRustSetLinkage(new_g, linkage);
llvm::LLVMRustSetVisibility(new_g, visibility);
Expand Down
24 changes: 6 additions & 18 deletions src/librustc_codegen_llvm/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use rustc_codegen_ssa::mir::debuginfo::{FunctionDebugContext, DebugScope,

use libc::c_uint;
use std::cell::RefCell;
use std::ffi::{CStr, CString};
use std::ffi::CString;

use smallvec::SmallVec;
use syntax_pos::{self, BytePos, Span, Pos};
Expand Down Expand Up @@ -255,23 +255,11 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
return;
}

let old_name = unsafe {
CStr::from_ptr(llvm::LLVMGetValueName(value))
};
match old_name.to_str() {
Ok("") => {}
Ok(_) => {
// Avoid replacing the name if it already exists.
// While we could combine the names somehow, it'd
// get noisy quick, and the usefulness is dubious.
return;
}
Err(_) => return,
}

let cname = SmallCStr::new(name);
unsafe {
llvm::LLVMSetValueName(value, cname.as_ptr());
// Avoid replacing the name if it already exists.
// While we could combine the names somehow, it'd
// get noisy quick, and the usefulness is dubious.
if llvm::get_value_name(value).is_empty() {
llvm::set_value_name(value, name.as_bytes());
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_codegen_llvm/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ impl DeclareMethods<'tcx> for CodegenCx<'ll, 'tcx> {
name: &str, ty: &'ll Type
) -> &'ll Value {
debug!("declare_global(name={:?})", name);
let namebuf = SmallCStr::new(name);
unsafe {
llvm::LLVMRustGetOrInsertGlobal(self.llmod, namebuf.as_ptr(), ty)
llvm::LLVMRustGetOrInsertGlobal(self.llmod, name.as_ptr().cast(), name.len(), ty)
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,8 @@ extern "C" {

// Operations on all values
pub fn LLVMTypeOf(Val: &Value) -> &Type;
pub fn LLVMGetValueName(Val: &Value) -> *const c_char;
pub fn LLVMSetValueName(Val: &Value, Name: *const c_char);
pub fn LLVMGetValueName2(Val: &Value, Length: *mut size_t) -> *const c_char;
pub fn LLVMSetValueName2(Val: &Value, Name: *const c_char, NameLen: size_t);
pub fn LLVMReplaceAllUsesWith(OldVal: &'a Value, NewVal: &'a Value);
pub fn LLVMSetMetadata(Val: &'a Value, KindID: c_uint, Node: &'a Value);

Expand Down Expand Up @@ -774,7 +774,8 @@ extern "C" {
pub fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;
pub fn LLVMAddGlobal(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value;
pub fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>;
pub fn LLVMRustGetOrInsertGlobal(M: &'a Module, Name: *const c_char, T: &'a Type) -> &'a Value;
pub fn LLVMRustGetOrInsertGlobal(M: &'a Module, Name: *const c_char, NameLen: size_t,
T: &'a Type) -> &'a Value;
pub fn LLVMRustInsertPrivateGlobal(M: &'a Module, T: &'a Type) -> &'a Value;
pub fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>;
pub fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>;
Expand Down Expand Up @@ -1811,7 +1812,7 @@ extern "C" {

pub fn LLVMRustPositionBuilderAtStart(B: &Builder<'a>, BB: &'a BasicBlock);

pub fn LLVMRustSetComdat(M: &'a Module, V: &'a Value, Name: *const c_char);
pub fn LLVMRustSetComdat(M: &'a Module, V: &'a Value, Name: *const c_char, NameLen: size_t);
pub fn LLVMRustUnsetComdat(V: &Value);
pub fn LLVMRustSetModulePICLevel(M: &Module);
pub fn LLVMRustSetModulePIELevel(M: &Module);
Expand Down
20 changes: 19 additions & 1 deletion src/librustc_codegen_llvm/llvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ pub fn SetFunctionCallConv(fn_: &'a Value, cc: CallConv) {
// For more details on COMDAT sections see e.g., http://www.airs.com/blog/archives/52
pub fn SetUniqueComdat(llmod: &Module, val: &'a Value) {
unsafe {
LLVMRustSetComdat(llmod, val, LLVMGetValueName(val));
let name = get_value_name(val);
LLVMRustSetComdat(llmod, val, name.as_ptr().cast(), name.len());
}
}

Expand Down Expand Up @@ -217,6 +218,23 @@ pub fn get_param(llfn: &'a Value, index: c_uint) -> &'a Value {
}
}

/// Safe wrapper for `LLVMGetValueName2` into a byte slice
pub fn get_value_name(value: &'a Value) -> &'a [u8] {
unsafe {
let mut len = 0;
let data = LLVMGetValueName2(value, &mut len);
std::slice::from_raw_parts(data.cast(), len)
}
}

/// Safe wrapper for `LLVMSetValueName2` from a byte slice
pub fn set_value_name(value: &Value, name: &[u8]) {
unsafe {
let data = name.as_ptr().cast();
LLVMSetValueName2(value, data, name.len());
}
}

pub fn build_string(f: impl FnOnce(&RustString)) -> Result<String, FromUtf8Error> {
let sr = RustString {
bytes: RefCell::new(Vec::new()),
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
if self.fn_abi.ret.layout.abi.is_uninhabited() {
// Functions with uninhabited return values are marked `noreturn`,
// so we should make sure that we never actually do.
// We play it safe by using a well-defined `abort`, but we could go for immediate UB
// if that turns out to be helpful.
bx.abort();
// `abort` does not terminate the block, so we still need to generate
// an `unreachable` terminator after it.
bx.unreachable();
return;
}
Expand Down Expand Up @@ -825,6 +829,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

mir::TerminatorKind::Abort => {
bx.abort();
// `abort` does not terminate the block, so we still need to generate
// an `unreachable` terminator after it.
bx.unreachable();
}

Expand Down
5 changes: 3 additions & 2 deletions src/librustc_codegen_ssa/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
},
}
// Allow RalfJ to sleep soundly knowing that even refactorings that remove
// the above error (or silence it under some conditions) will not cause UB
// the above error (or silence it under some conditions) will not cause UB.
bx.abort();
// We've errored, so we don't have to produce working code.
// We still have to return an operand but it doesn't matter,
// this code is unreachable.
let ty = self.monomorphize(&constant.literal.ty);
let layout = bx.cx().layout_of(ty);
bx.load_operand(PlaceRef::new_sized(
Expand Down
9 changes: 7 additions & 2 deletions src/librustc_codegen_ssa/mir/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
variant_index: VariantIdx
) {
if self.layout.for_variant(bx.cx(), variant_index).abi.is_uninhabited() {
// We play it safe by using a well-defined `abort`, but we could go for immediate UB
// if that turns out to be helpful.
bx.abort();
return;
}
match self.layout.variants {
Expand Down Expand Up @@ -488,10 +491,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
},
Err(_) => {
// This is unreachable as long as runtime
// and compile-time agree on values
// and compile-time agree perfectly.
// With floats that won't always be true,
// so we generate an abort.
// so we generate a (safe) abort.
bx.abort();
// We still have to return a place but it doesn't matter,
// this code is unreachable.
let llval = bx.cx().const_undef(
bx.cx().type_ptr_to(bx.cx().backend_type(layout))
);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_interface/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::mem;
use syntax::{self, ast};

/// Represent the result of a query.
/// This result can be stolen with the `take` method and returned with the `give` method.
/// This result can be stolen with the `take` method and generated with the `compute` method.
pub struct Query<T> {
result: RefCell<Option<Result<T>>>,
}
Expand All @@ -37,7 +37,7 @@ impl<T> Query<T> {
}

/// Takes ownership of the query result. Further attempts to take or peek the query
/// result will panic unless it is returned by calling the `give` method.
/// result will panic unless it is generated by calling the `compute` method.
pub fn take(&self) -> T {
self.result
.borrow_mut()
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/util/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ fn write_graph_label<'tcx, W: Write>(
}

for var_debug_info in &body.var_debug_info {
write!(w, r#"debug {} => {};<br align="left"/>"#,
write!(w, r#"debug {} =&gt; {};<br align="left"/>"#,
var_debug_info.name, escape(&var_debug_info.place))?;
}

Expand Down
6 changes: 6 additions & 0 deletions src/librustdoc/clean/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ impl ops::Not for Cfg {

impl ops::BitAndAssign for Cfg {
fn bitand_assign(&mut self, other: Cfg) {
if *self == other {
return;
}
match (self, other) {
(&mut Cfg::False, _) | (_, Cfg::True) => {},
(s, Cfg::False) => *s = Cfg::False,
Expand Down Expand Up @@ -238,6 +241,9 @@ impl ops::BitAnd for Cfg {

impl ops::BitOrAssign for Cfg {
fn bitor_assign(&mut self, other: Cfg) {
if *self == other {
return;
}
match (self, other) {
(&mut Cfg::True, _) | (_, Cfg::False) => {},
(s, Cfg::True) => *s = Cfg::True,
Expand Down
11 changes: 9 additions & 2 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2339,8 +2339,10 @@ mod tests {
let filename = &tmpdir.join("file_that_does_not_exist.txt");
let result = File::open(filename);

#[cfg(unix)]
#[cfg(all(unix, not(target_os = "vxworks")))]
error!(result, "No such file or directory");
#[cfg(target_os = "vxworks")]
error!(result, "no such file or directory");
#[cfg(windows)]
error!(result, 2); // ERROR_FILE_NOT_FOUND
}
Expand All @@ -2352,8 +2354,10 @@ mod tests {

let result = fs::remove_file(filename);

#[cfg(unix)]
#[cfg(all(unix, not(target_os = "vxworks")))]
error!(result, "No such file or directory");
#[cfg(target_os = "vxworks")]
error!(result, "no such file or directory");
#[cfg(windows)]
error!(result, 2); // ERROR_FILE_NOT_FOUND
}
Expand Down Expand Up @@ -2553,7 +2557,10 @@ mod tests {

check!(fs::set_permissions(filename, fs::Permissions::from_mode(0o1777)));
let metadata1 = check!(fs::metadata(filename));
#[cfg(all(unix, not(target_os = "vxworks")))]
assert_eq!(mask & metadata1.permissions().mode(), 0o1777);
#[cfg(target_os = "vxworks")]
assert_eq!(mask & metadata1.permissions().mode(), 0o0777);
}

#[test]
Expand Down
Loading