Repository: rust
Issue: UI tests `linkage-detect-local-generated-name-collision.rs` and `linkage-detect-extern-generated-name-collision.rs` trigger LLVM asserts when compiled with CGUs = 1
Labels: A-linkage,I-crash,A-LLVM,T-compiler,C-bug

This was discovered in https://github.com/rust-lang/rust/pull/81942#issuecomment-812958466 which lowers the default CGU count to 1. The tests were modified to explicitly request 16CGUs to make them pass, but the underlying issue remains.

This should be reproducible by setting `assertions = true` in config.toml and running `./x.py test --stage 1 src/test/ui` on commit 01c682043d3632dab421c263b8a2263b08b01bab (base commit aef11409b43) or by adding `// compile-flags: -Ccodegen-units=1` to the tests.

```
---- [ui] ui/linkage-attr/linkage-detect-local-generated-name-collision.rs stdout ----

error: Error: expected failure status (Some(1)) but received status None.
status: signal: 6 (core dumped)
command: "/home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "/home/the8472/workspace/rust/src/test/ui/linkage-attr/linkage-detect-local-generated-name-collision.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zemit-future-incompat-report" "-C" "prefer-dynamic" "--out-dir" "/home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/test/ui/linkage-attr/linkage-detect-local-generated-name-collision" "-A" "unused" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-Clink-args=-fuse-ld=lld" "-Clink-arg=-Wl,--threads=1" "-Ccodegen-units=2" "-L" "/home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/test/ui/linkage-attr/linkage-detect-local-generated-name-collision/auxiliary"
stdout:
------------------------------------------

------------------------------------------
stderr:
------------------------------------------
rustc: /home/the8472/workspace/rust/src/llvm-project/llvm/include/llvm/Support/Casting.h:269: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = llvm::GlobalValue; Y = llvm::Value; typename llvm::cast_retty<X, Y*>::ret_type = llvm::GlobalValue*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

------------------------------------------


---- [ui] ui/linkage-attr/linkage-detect-extern-generated-name-collision.rs stdout ----

error: Error: expected failure status (Some(1)) but received status None.
status: signal: 6 (core dumped)
command: "/home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "/home/the8472/workspace/rust/src/test/ui/linkage-attr/linkage-detect-extern-generated-name-collision.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zemit-future-incompat-report" "-C" "prefer-dynamic" "--out-dir" "/home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/test/ui/linkage-attr/linkage-detect-extern-generated-name-collision" "-A" "unused" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-Clink-args=-fuse-ld=lld" "-Clink-arg=-Wl,--threads=1" "-Ccodegen-units=2" "-L" "/home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/test/ui/linkage-attr/linkage-detect-extern-generated-name-collision/auxiliary"
stdout:
------------------------------------------

------------------------------------------
stderr:
------------------------------------------
rustc: /home/the8472/workspace/rust/src/llvm-project/llvm/include/llvm/Support/Casting.h:269: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = llvm::GlobalValue; Y = llvm::Value; typename llvm::cast_retty<X, Y*>::ret_type = llvm::GlobalValue*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

------------------------------------------



failures:
    [ui] ui/linkage-attr/linkage-detect-extern-generated-name-collision.rs
    [ui] ui/linkage-attr/linkage-detect-local-generated-name-collision.rs
```