Skip to content

Commit 9630dbb

Browse files
committed
Auto merge of #67091 - JohnTitor:rollup-kitphze, r=JohnTitor
Rollup of 11 pull requests Successful merges: - #66846 (Make try_mark_previous_green aware of cycles.) - #66959 (Remove potential cfgs duplicates) - #66988 (Fix angle bracket formatting when dumping MIR debug vars) - #66998 (Modified the testcases for VxWorks) - #67008 (rustdoc: Add test for fixed issue) - #67023 (SGX: Fix target linker used by bootstrap) - #67033 (Migrate to LLVM{Get,Set}ValueName2) - #67049 (Simplify {IoSlice, IoSliceMut}::advance examples and tests) - #67054 (codegen "unreachable" for invalid SetDiscriminant) - #67081 (Fix Query type docs) - #67085 (Remove boxed closures in address parser.) Failed merges: r? @ghost
2 parents d0126e8 + 931be6c commit 9630dbb

File tree

23 files changed

+214
-101
lines changed

23 files changed

+214
-101
lines changed

src/bootstrap/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ impl Build {
810810
!target.contains("emscripten") &&
811811
!target.contains("wasm32") &&
812812
!target.contains("nvptx") &&
813+
!target.contains("fortanix") &&
813814
!target.contains("fuchsia") {
814815
Some(self.cc(target))
815816
} else {

src/librustc/dep_graph/graph.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -710,14 +710,25 @@ impl DepGraph {
710710
return None
711711
}
712712
None => {
713-
if !tcx.sess.has_errors() {
713+
if !tcx.sess.has_errors_or_delayed_span_bugs() {
714714
bug!("try_mark_previous_green() - Forcing the DepNode \
715715
should have set its color")
716716
} else {
717-
// If the query we just forced has resulted
718-
// in some kind of compilation error, we
719-
// don't expect that the corresponding
720-
// dep-node color has been updated.
717+
// If the query we just forced has resulted in
718+
// some kind of compilation error, we cannot rely on
719+
// the dep-node color having been properly updated.
720+
// This means that the query system has reached an
721+
// invalid state. We let the compiler continue (by
722+
// returning `None`) so it can emit error messages
723+
// and wind down, but rely on the fact that this
724+
// invalid state will not be persisted to the
725+
// incremental compilation cache because of
726+
// compilation errors being present.
727+
debug!("try_mark_previous_green({:?}) - END - \
728+
dependency {:?} resulted in compilation error",
729+
dep_node,
730+
dep_dep_node);
731+
return None
721732
}
722733
}
723734
}

src/librustc_codegen_llvm/back/write.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_fs_util::{path_to_c_string, link_or_copy};
2222
use rustc_data_structures::small_c_str::SmallCStr;
2323
use errors::{Handler, FatalError};
2424

25-
use std::ffi::{CString, CStr};
25+
use std::ffi::CString;
2626
use std::fs;
2727
use std::io::{self, Write};
2828
use std::path::{Path, PathBuf};
@@ -833,16 +833,16 @@ fn create_msvc_imps(
833833
})
834834
.filter_map(|val| {
835835
// Exclude some symbols that we know are not Rust symbols.
836-
let name = CStr::from_ptr(llvm::LLVMGetValueName(val));
837-
if ignored(name.to_bytes()) {
836+
let name = llvm::get_value_name(val);
837+
if ignored(name) {
838838
None
839839
} else {
840840
Some((val, name))
841841
}
842842
})
843843
.map(move |(val, name)| {
844844
let mut imp_name = prefix.as_bytes().to_vec();
845-
imp_name.extend(name.to_bytes());
845+
imp_name.extend(name);
846846
let imp_name = CString::new(imp_name).unwrap();
847847
(imp_name, val)
848848
})

src/librustc_codegen_llvm/consts.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc::ty::layout::{self, Size, Align, LayoutOf};
2121

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

24-
use std::ffi::{CStr, CString};
24+
use std::ffi::CStr;
2525

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

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

403401
let new_g = llvm::LLVMRustGetOrInsertGlobal(
404-
self.llmod, name_string.as_ptr(), val_llty);
402+
self.llmod, name.as_ptr().cast(), name.len(), val_llty);
405403

406404
llvm::LLVMRustSetLinkage(new_g, linkage);
407405
llvm::LLVMRustSetVisibility(new_g, visibility);

src/librustc_codegen_llvm/debuginfo/mod.rs

+6-18
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use rustc_codegen_ssa::mir::debuginfo::{FunctionDebugContext, DebugScope,
3232

3333
use libc::c_uint;
3434
use std::cell::RefCell;
35-
use std::ffi::{CStr, CString};
35+
use std::ffi::CString;
3636

3737
use smallvec::SmallVec;
3838
use syntax_pos::{self, BytePos, Span, Pos};
@@ -255,23 +255,11 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
255255
return;
256256
}
257257

258-
let old_name = unsafe {
259-
CStr::from_ptr(llvm::LLVMGetValueName(value))
260-
};
261-
match old_name.to_str() {
262-
Ok("") => {}
263-
Ok(_) => {
264-
// Avoid replacing the name if it already exists.
265-
// While we could combine the names somehow, it'd
266-
// get noisy quick, and the usefulness is dubious.
267-
return;
268-
}
269-
Err(_) => return,
270-
}
271-
272-
let cname = SmallCStr::new(name);
273-
unsafe {
274-
llvm::LLVMSetValueName(value, cname.as_ptr());
258+
// Avoid replacing the name if it already exists.
259+
// While we could combine the names somehow, it'd
260+
// get noisy quick, and the usefulness is dubious.
261+
if llvm::get_value_name(value).is_empty() {
262+
llvm::set_value_name(value, name.as_bytes());
275263
}
276264
}
277265
}

src/librustc_codegen_llvm/declare.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ impl DeclareMethods<'tcx> for CodegenCx<'ll, 'tcx> {
7676
name: &str, ty: &'ll Type
7777
) -> &'ll Value {
7878
debug!("declare_global(name={:?})", name);
79-
let namebuf = SmallCStr::new(name);
8079
unsafe {
81-
llvm::LLVMRustGetOrInsertGlobal(self.llmod, namebuf.as_ptr(), ty)
80+
llvm::LLVMRustGetOrInsertGlobal(self.llmod, name.as_ptr().cast(), name.len(), ty)
8281
}
8382
}
8483

src/librustc_codegen_llvm/llvm/ffi.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,8 @@ extern "C" {
701701

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

@@ -774,7 +774,8 @@ extern "C" {
774774
pub fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;
775775
pub fn LLVMAddGlobal(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value;
776776
pub fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>;
777-
pub fn LLVMRustGetOrInsertGlobal(M: &'a Module, Name: *const c_char, T: &'a Type) -> &'a Value;
777+
pub fn LLVMRustGetOrInsertGlobal(M: &'a Module, Name: *const c_char, NameLen: size_t,
778+
T: &'a Type) -> &'a Value;
778779
pub fn LLVMRustInsertPrivateGlobal(M: &'a Module, T: &'a Type) -> &'a Value;
779780
pub fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>;
780781
pub fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>;
@@ -1811,7 +1812,7 @@ extern "C" {
18111812

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

1814-
pub fn LLVMRustSetComdat(M: &'a Module, V: &'a Value, Name: *const c_char);
1815+
pub fn LLVMRustSetComdat(M: &'a Module, V: &'a Value, Name: *const c_char, NameLen: size_t);
18151816
pub fn LLVMRustUnsetComdat(V: &Value);
18161817
pub fn LLVMRustSetModulePICLevel(M: &Module);
18171818
pub fn LLVMRustSetModulePIELevel(M: &Module);

src/librustc_codegen_llvm/llvm/mod.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ pub fn SetFunctionCallConv(fn_: &'a Value, cc: CallConv) {
115115
// For more details on COMDAT sections see e.g., http://www.airs.com/blog/archives/52
116116
pub fn SetUniqueComdat(llmod: &Module, val: &'a Value) {
117117
unsafe {
118-
LLVMRustSetComdat(llmod, val, LLVMGetValueName(val));
118+
let name = get_value_name(val);
119+
LLVMRustSetComdat(llmod, val, name.as_ptr().cast(), name.len());
119120
}
120121
}
121122

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

221+
/// Safe wrapper for `LLVMGetValueName2` into a byte slice
222+
pub fn get_value_name(value: &'a Value) -> &'a [u8] {
223+
unsafe {
224+
let mut len = 0;
225+
let data = LLVMGetValueName2(value, &mut len);
226+
std::slice::from_raw_parts(data.cast(), len)
227+
}
228+
}
229+
230+
/// Safe wrapper for `LLVMSetValueName2` from a byte slice
231+
pub fn set_value_name(value: &Value, name: &[u8]) {
232+
unsafe {
233+
let data = name.as_ptr().cast();
234+
LLVMSetValueName2(value, data, name.len());
235+
}
236+
}
237+
220238
pub fn build_string(f: impl FnOnce(&RustString)) -> Result<String, FromUtf8Error> {
221239
let sr = RustString {
222240
bytes: RefCell::new(Vec::new()),

src/librustc_codegen_ssa/mir/block.rs

+6
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
261261
if self.fn_abi.ret.layout.abi.is_uninhabited() {
262262
// Functions with uninhabited return values are marked `noreturn`,
263263
// so we should make sure that we never actually do.
264+
// We play it safe by using a well-defined `abort`, but we could go for immediate UB
265+
// if that turns out to be helpful.
264266
bx.abort();
267+
// `abort` does not terminate the block, so we still need to generate
268+
// an `unreachable` terminator after it.
265269
bx.unreachable();
266270
return;
267271
}
@@ -825,6 +829,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
825829

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

src/librustc_codegen_ssa/mir/operand.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
475475
},
476476
}
477477
// Allow RalfJ to sleep soundly knowing that even refactorings that remove
478-
// the above error (or silence it under some conditions) will not cause UB
478+
// the above error (or silence it under some conditions) will not cause UB.
479479
bx.abort();
480-
// We've errored, so we don't have to produce working code.
480+
// We still have to return an operand but it doesn't matter,
481+
// this code is unreachable.
481482
let ty = self.monomorphize(&constant.literal.ty);
482483
let layout = bx.cx().layout_of(ty);
483484
bx.load_operand(PlaceRef::new_sized(

src/librustc_codegen_ssa/mir/place.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
333333
variant_index: VariantIdx
334334
) {
335335
if self.layout.for_variant(bx.cx(), variant_index).abi.is_uninhabited() {
336+
// We play it safe by using a well-defined `abort`, but we could go for immediate UB
337+
// if that turns out to be helpful.
338+
bx.abort();
336339
return;
337340
}
338341
match self.layout.variants {
@@ -488,10 +491,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
488491
},
489492
Err(_) => {
490493
// This is unreachable as long as runtime
491-
// and compile-time agree on values
494+
// and compile-time agree perfectly.
492495
// With floats that won't always be true,
493-
// so we generate an abort.
496+
// so we generate a (safe) abort.
494497
bx.abort();
498+
// We still have to return a place but it doesn't matter,
499+
// this code is unreachable.
495500
let llval = bx.cx().const_undef(
496501
bx.cx().type_ptr_to(bx.cx().backend_type(layout))
497502
);

src/librustc_interface/queries.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::mem;
2222
use syntax::{self, ast};
2323

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

3939
/// Takes ownership of the query result. Further attempts to take or peek the query
40-
/// result will panic unless it is returned by calling the `give` method.
40+
/// result will panic unless it is generated by calling the `compute` method.
4141
pub fn take(&self) -> T {
4242
self.result
4343
.borrow_mut()

src/librustc_mir/util/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn write_graph_label<'tcx, W: Write>(
202202
}
203203

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

src/librustdoc/clean/cfg.rs

+6
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ impl ops::Not for Cfg {
209209

210210
impl ops::BitAndAssign for Cfg {
211211
fn bitand_assign(&mut self, other: Cfg) {
212+
if *self == other {
213+
return;
214+
}
212215
match (self, other) {
213216
(&mut Cfg::False, _) | (_, Cfg::True) => {},
214217
(s, Cfg::False) => *s = Cfg::False,
@@ -238,6 +241,9 @@ impl ops::BitAnd for Cfg {
238241

239242
impl ops::BitOrAssign for Cfg {
240243
fn bitor_assign(&mut self, other: Cfg) {
244+
if *self == other {
245+
return;
246+
}
241247
match (self, other) {
242248
(&mut Cfg::True, _) | (_, Cfg::False) => {},
243249
(s, Cfg::True) => *s = Cfg::True,

src/libstd/fs.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -2339,8 +2339,10 @@ mod tests {
23392339
let filename = &tmpdir.join("file_that_does_not_exist.txt");
23402340
let result = File::open(filename);
23412341

2342-
#[cfg(unix)]
2342+
#[cfg(all(unix, not(target_os = "vxworks")))]
23432343
error!(result, "No such file or directory");
2344+
#[cfg(target_os = "vxworks")]
2345+
error!(result, "no such file or directory");
23442346
#[cfg(windows)]
23452347
error!(result, 2); // ERROR_FILE_NOT_FOUND
23462348
}
@@ -2352,8 +2354,10 @@ mod tests {
23522354

23532355
let result = fs::remove_file(filename);
23542356

2355-
#[cfg(unix)]
2357+
#[cfg(all(unix, not(target_os = "vxworks")))]
23562358
error!(result, "No such file or directory");
2359+
#[cfg(target_os = "vxworks")]
2360+
error!(result, "no such file or directory");
23572361
#[cfg(windows)]
23582362
error!(result, 2); // ERROR_FILE_NOT_FOUND
23592363
}
@@ -2553,7 +2557,10 @@ mod tests {
25532557

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

25592566
#[test]

0 commit comments

Comments
 (0)