]> git.lizzy.rs Git - rust.git/blob - src/test/ui/statics/issue-91050-1.rs
Auto merge of #95454 - randomicon00:fix95444, r=wesleywiser
[rust.git] / src / test / ui / statics / issue-91050-1.rs
1 // build-pass
2 // compile-flags: --crate-type=rlib --emit=llvm-ir -Cno-prepopulate-passes
3
4 // This test declares globals by the same name with different types, which
5 // caused problems because Module::getOrInsertGlobal would return a Constant*
6 // bitcast instead of a GlobalVariable* that could access linkage/visibility.
7 // In alt builds with LLVM assertions this would fail:
8 //
9 // rustc: /checkout/src/llvm-project/llvm/include/llvm/Support/Casting.h:269:
10 // typename cast_retty<X, Y *>::ret_type llvm::cast(Y *) [X = llvm::GlobalValue, Y = llvm::Value]:
11 // Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
12 //
13 // In regular builds, the bad cast was UB, like "Invalid LLVMRustVisibility value!"
14
15 pub mod before {
16     #[no_mangle]
17     pub static GLOBAL1: [u8; 1] = [1];
18 }
19
20 pub mod inner {
21     extern "C" {
22         pub static GLOBAL1: u8;
23         pub static GLOBAL2: u8;
24     }
25
26     pub fn call() {
27         drop(unsafe { (GLOBAL1, GLOBAL2) });
28     }
29 }
30
31 pub mod after {
32     #[no_mangle]
33     pub static GLOBAL2: [u8; 1] = [2];
34 }