Skip to content

Commit 3ec5a99

Browse files
committed
Auto merge of #48209 - kennytm:try-fix-48116, r=alexcrichton
Try to fix 48116 and 48192 The bug #48116 happens because of a misoptimization of the `import_path_to_string` function, where a `names` slice is empty but the `!names.is_empty()` branch is executed. https://github.com/rust-lang/rust/blob/4d2d3fc5dadf894a8ad709a5860a549f2c0b1032/src/librustc_resolve/resolve_imports.rs#L1015-L1042 Yesterday, @eddyb had locally reproduced the bug, and [came across the `position` function](https://mozilla.logbot.info/rust-infra/20180214#c14296834) where the `assume()` call is found to be suspicious. We have *not* concluded that this `assume()` causes #48116, but given [the reputation of `assume()`](#45501 (comment)), this seems higher relevant. Here we try to see if commenting it out can fix the errors. Later @alexcrichton has bisected and found a potential bug [in the LLVM side](#48116 (comment)). We are currently testing if reverting that LLVM commit is enough to stop the bug. If true, this PR can be reverted (keep the `assume()`) and we could backport the LLVM patch instead. (This PR also includes an earlier commit from #48127 for help debugging ICE happening in compile-fail/parse-fail tests.) The PR also reverts #48059, which seems to cause #48192. r? @alexcrichton cc @eddyb, @arthurprs (#47333)
2 parents 4d2d3fc + e0da990 commit 3ec5a99

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

src/bootstrap/builder.rs

+5-22
Original file line numberDiff line numberDiff line change
@@ -600,25 +600,9 @@ impl<'a> Builder<'a> {
600600
//
601601
// FIXME: the guard against msvc shouldn't need to be here
602602
if !target.contains("msvc") {
603-
let ccache = self.config.ccache.as_ref();
604-
let ccacheify = |s: &Path| {
605-
let ccache = match ccache {
606-
Some(ref s) => s,
607-
None => return s.display().to_string(),
608-
};
609-
// FIXME: the cc-rs crate only recognizes the literal strings
610-
// `ccache` and `sccache` when doing caching compilations, so we
611-
// mirror that here. It should probably be fixed upstream to
612-
// accept a new env var or otherwise work with custom ccache
613-
// vars.
614-
match &ccache[..] {
615-
"ccache" | "sccache" => format!("{} {}", ccache, s.display()),
616-
_ => s.display().to_string(),
617-
}
618-
};
619-
let cc = ccacheify(&self.cc(target));
620-
cargo.env(format!("CC_{}", target), &cc)
621-
.env("CC", &cc);
603+
let cc = self.cc(target);
604+
cargo.env(format!("CC_{}", target), cc)
605+
.env("CC", cc);
622606

623607
let cflags = self.cflags(target).join(" ");
624608
cargo.env(format!("CFLAGS_{}", target), cflags.clone())
@@ -633,9 +617,8 @@ impl<'a> Builder<'a> {
633617
}
634618

635619
if let Ok(cxx) = self.cxx(target) {
636-
let cxx = ccacheify(&cxx);
637-
cargo.env(format!("CXX_{}", target), &cxx)
638-
.env("CXX", &cxx)
620+
cargo.env(format!("CXX_{}", target), cxx)
621+
.env("CXX", cxx)
639622
.env(format!("CXXFLAGS_{}", target), cflags.clone())
640623
.env("CXXFLAGS", cflags);
641624
}

src/libcore/slice/mod.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -1246,15 +1246,18 @@ macro_rules! iterator {
12461246
{
12471247
// The addition might panic on overflow
12481248
// Use the len of the slice to hint optimizer to remove result index bounds check.
1249-
let n = make_slice!(self.ptr, self.end).len();
1249+
let _n = make_slice!(self.ptr, self.end).len();
12501250
self.try_fold(0, move |i, x| {
12511251
if predicate(x) { Err(i) }
12521252
else { Ok(i + 1) }
12531253
}).err()
1254-
.map(|i| {
1255-
unsafe { assume(i < n) };
1256-
i
1257-
})
1254+
// // FIXME(#48116/#45964):
1255+
// // This assume() causes misoptimization on LLVM 6.
1256+
// // Commented out until it is fixed again.
1257+
// .map(|i| {
1258+
// unsafe { assume(i < n) };
1259+
// i
1260+
// })
12581261
}
12591262

12601263
#[inline]
@@ -1271,10 +1274,13 @@ macro_rules! iterator {
12711274
if predicate(x) { Err(i) }
12721275
else { Ok(i) }
12731276
}).err()
1274-
.map(|i| {
1275-
unsafe { assume(i < n) };
1276-
i
1277-
})
1277+
// // FIXME(#48116/#45964):
1278+
// // This assume() causes misoptimization on LLVM 6.
1279+
// // Commented out until it is fixed again.
1280+
// .map(|i| {
1281+
// unsafe { assume(i < n) };
1282+
// i
1283+
// })
12781284
}
12791285
}
12801286

src/librustc_resolve/resolve_imports.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,8 @@ fn import_path_to_string(names: &[SpannedIdent],
10261026
if names.is_empty() {
10271027
import_directive_subclass_to_string(subclass)
10281028
} else {
1029+
// FIXME: Remove this entire logic after #48116 is fixed.
1030+
//
10291031
// Note that this code looks a little wonky, it's currently here to
10301032
// hopefully help debug #48116, but otherwise isn't intended to
10311033
// cause any problems.
@@ -1034,8 +1036,17 @@ fn import_path_to_string(names: &[SpannedIdent],
10341036
names_to_string(names),
10351037
import_directive_subclass_to_string(subclass),
10361038
);
1037-
assert!(!names.is_empty());
1038-
assert!(!x.starts_with("::"));
1039+
if names.is_empty() || x.starts_with("::") {
1040+
span_bug!(
1041+
span,
1042+
"invalid name `{}` at {:?}; global = {}, names = {:?}, subclass = {:?}",
1043+
x,
1044+
span,
1045+
global,
1046+
names,
1047+
subclass
1048+
);
1049+
}
10391050
return x
10401051
}
10411052
}

src/tools/compiletest/src/runtest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ impl<'test> TestCx<'test> {
250250
fn run_cfail_test(&self) {
251251
let proc_res = self.compile_test();
252252
self.check_if_test_should_compile(&proc_res);
253+
self.check_no_compiler_crash(&proc_res);
253254

254255
let output_to_check = self.get_output(&proc_res);
255256
let expected_errors = errors::load_errors(&self.testpaths.file, self.revision);
@@ -262,7 +263,6 @@ impl<'test> TestCx<'test> {
262263
self.check_error_patterns(&output_to_check, &proc_res);
263264
}
264265

265-
self.check_no_compiler_crash(&proc_res);
266266
self.check_forbid_output(&output_to_check, &proc_res);
267267
}
268268

0 commit comments

Comments
 (0)