Skip to content

Commit 09bab38

Browse files
Fix #83045 by moving some crate loading verification code to a better place.
1 parent bba4088 commit 09bab38

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

compiler/rustc_metadata/src/creader.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -350,16 +350,13 @@ impl<'a> CrateLoader<'a> {
350350
let Library { source, metadata } = lib;
351351
let crate_root = metadata.get_root();
352352
let host_hash = host_lib.as_ref().map(|lib| lib.metadata.get_root().hash());
353-
self.verify_no_symbol_conflicts(&crate_root)?;
354353

355354
let private_dep =
356355
self.sess.opts.externs.get(&name.as_str()).map_or(false, |e| e.is_private_dep);
357356

358357
// Claim this crate number and cache it
359358
let cnum = self.cstore.alloc_new_crate_num();
360359

361-
self.verify_no_stable_crate_id_hash_conflicts(&crate_root, cnum)?;
362-
363360
info!(
364361
"register crate `{}` (cnum = {}. private_dep = {})",
365362
crate_root.name(),
@@ -394,6 +391,14 @@ impl<'a> CrateLoader<'a> {
394391
None
395392
};
396393

394+
// Perform some verification *after* resolve_crate_deps() above is
395+
// known to have been successful. It seems that - in error cases - the
396+
// cstore can be in a temporarily invalid state between cnum allocation
397+
// and dependency resolution and the verification code would produce
398+
// ICEs in that case (see #83045).
399+
self.verify_no_symbol_conflicts(&crate_root)?;
400+
self.verify_no_stable_crate_id_hash_conflicts(&crate_root, cnum)?;
401+
397402
let crate_metadata = CrateMetadata::new(
398403
self.sess,
399404
metadata,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
include ../../run-make-fulldeps/tools.mk
2+
3+
# This test case creates a situation where the crate loader would run
4+
# into an ICE when confronted with an invalid setup where it cannot
5+
# find the dependency of a direct dependency.
6+
#
7+
# The test case makes sure that the compiler produces the expected
8+
# error message but does not ICE immediately after.
9+
#
10+
# See https://github.com/rust-lang/rust/issues/83045
11+
12+
# This is a platform-independent issue, no need to waste time testing
13+
# everywhere.
14+
# only-x86_64
15+
# only-linux
16+
17+
# NOTE: We use BARE_RUSTC below so that the compiler can't find liba.rlib
18+
# If we used RUSTC the additional '-L TMPDIR' option would allow rustc to
19+
# actually find the crate.
20+
#
21+
# We check that we get the expected error message
22+
# But that we do not get an ICE
23+
24+
all:
25+
$(RUSTC) --crate-name=a --crate-type=rlib a.rs --verbose
26+
$(RUSTC) --crate-name=b --crate-type=rlib --extern a=$(TMPDIR)/liba.rlib b.rs --verbose
27+
$(BARE_RUSTC) --out-dir $(TMPDIR) \
28+
--extern b=$(TMPDIR)/libb.rlib \
29+
--crate-type=rlib \
30+
--edition=2018 \
31+
c.rs 2>&1 | tee $(TMPDIR)/output.txt || exit 0
32+
$(CGREP) E0463 < $(TMPDIR)/output.txt
33+
$(CGREP) -v "internal compiler error" < $(TMPDIR)/output.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// empty on purpose
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extern crate a;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use b as _;

0 commit comments

Comments
 (0)