diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 33a85adeb8781..bb8a44d8afde1 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -413,6 +413,7 @@ impl<'ll> CodegenCx<'ll, '_> { llvm::LLVMRustSetLinkage(new_g, linkage); llvm::LLVMRustSetVisibility(new_g, visibility); + llvm::LLVMSetUnnamedAddress(new_g, llvm::UnnamedAddr::Global); // The old global has had its name removed but is returned by // get_static since it is in the instance cache. Provide an diff --git a/tests/codegen/default-visibility.rs b/tests/codegen/default-visibility.rs index 88ff9fee25447..03a346d06983a 100644 --- a/tests/codegen/default-visibility.rs +++ b/tests/codegen/default-visibility.rs @@ -1,8 +1,8 @@ +// ignore-tidy-linelength // Verifies that `Session::default_visibility` is affected when using the related cmdline // flag. This is a regression test for https://github.com/rust-lang/compiler-team/issues/782. See // also https://github.com/rust-lang/rust/issues/73295 and // https://github.com/rust-lang/rust/issues/37530. - //@ revisions:DEFAULT HIDDEN PROTECTED INTERPOSABLE //@[HIDDEN] compile-flags: -Zdefault-visibility=hidden //@[PROTECTED] compile-flags: -Zdefault-visibility=protected @@ -27,10 +27,10 @@ pub static tested_symbol: [u8; 6] = *b"foobar"; // //@ only-x86_64-unknown-linux-gnu -// HIDDEN: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = hidden constant -// PROTECTED: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = protected constant -// INTERPOSABLE: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = constant -// DEFAULT: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = constant +// HIDDEN: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = hidden unnamed_addr constant +// PROTECTED: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = protected unnamed_addr constant +// INTERPOSABLE: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = unnamed_addr constant +// DEFAULT: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = unnamed_addr constant pub fn do_memcmp(left: &[u8], right: &[u8]) -> i32 { left.cmp(right) as i32 diff --git a/tests/codegen/external-no-mangle-statics.rs b/tests/codegen/external-no-mangle-statics.rs index a44867ff9230f..1a94dea8769e0 100644 --- a/tests/codegen/external-no-mangle-statics.rs +++ b/tests/codegen/external-no-mangle-statics.rs @@ -1,77 +1,76 @@ //@ revisions: lib staticlib //@ ignore-emscripten default visibility is hidden -//@ compile-flags: -O //@ [lib] compile-flags: --crate-type lib //@ [staticlib] compile-flags: --crate-type staticlib // `#[no_mangle]`d static variables always have external linkage, i.e., no `internal` in their // definitions -// CHECK: @A = {{(dso_local )?}}local_unnamed_addr constant +// CHECK: @A = {{(dso_local )?}}unnamed_addr constant #[no_mangle] static A: u8 = 0; -// CHECK: @B = {{(dso_local )?}}local_unnamed_addr global +// CHECK: @B = {{(dso_local )?}}unnamed_addr global #[no_mangle] static mut B: u8 = 0; -// CHECK: @C = {{(dso_local )?}}local_unnamed_addr constant +// CHECK: @C = {{(dso_local )?}}unnamed_addr constant #[no_mangle] pub static C: u8 = 0; -// CHECK: @D = {{(dso_local )?}}local_unnamed_addr global +// CHECK: @D = {{(dso_local )?}}unnamed_addr global #[no_mangle] pub static mut D: u8 = 0; mod private { - // CHECK: @E = {{(dso_local )?}}local_unnamed_addr constant + // CHECK: @E = {{(dso_local )?}}unnamed_addr constant #[no_mangle] static E: u8 = 0; - // CHECK: @F = {{(dso_local )?}}local_unnamed_addr global + // CHECK: @F = {{(dso_local )?}}unnamed_addr global #[no_mangle] static mut F: u8 = 0; - // CHECK: @G = {{(dso_local )?}}local_unnamed_addr constant + // CHECK: @G = {{(dso_local )?}}unnamed_addr constant #[no_mangle] pub static G: u8 = 0; - // CHECK: @H = {{(dso_local )?}}local_unnamed_addr global + // CHECK: @H = {{(dso_local )?}}unnamed_addr global #[no_mangle] pub static mut H: u8 = 0; } const HIDDEN: () = { - // CHECK: @I = {{(dso_local )?}}local_unnamed_addr constant + // CHECK: @I = {{(dso_local )?}}unnamed_addr constant #[no_mangle] static I: u8 = 0; - // CHECK: @J = {{(dso_local )?}}local_unnamed_addr global + // CHECK: @J = {{(dso_local )?}}unnamed_addr global #[no_mangle] static mut J: u8 = 0; - // CHECK: @K = {{(dso_local )?}}local_unnamed_addr constant + // CHECK: @K = {{(dso_local )?}}unnamed_addr constant #[no_mangle] pub static K: u8 = 0; - // CHECK: @L = {{(dso_local )?}}local_unnamed_addr global + // CHECK: @L = {{(dso_local )?}}unnamed_addr global #[no_mangle] pub static mut L: u8 = 0; }; fn x() { - // CHECK: @M = {{(dso_local )?}}local_unnamed_addr constant + // CHECK: @M = {{(dso_local )?}}unnamed_addr constant #[no_mangle] static M: fn() = x; - // CHECK: @N = {{(dso_local )?}}local_unnamed_addr global + // CHECK: @N = {{(dso_local )?}}unnamed_addr global #[no_mangle] static mut N: u8 = 0; - // CHECK: @O = {{(dso_local )?}}local_unnamed_addr constant + // CHECK: @O = {{(dso_local )?}}unnamed_addr constant #[no_mangle] pub static O: u8 = 0; - // CHECK: @P = {{(dso_local )?}}local_unnamed_addr global + // CHECK: @P = {{(dso_local )?}}unnamed_addr global #[no_mangle] pub static mut P: u8 = 0; } diff --git a/tests/codegen/link_section.rs b/tests/codegen/link_section.rs index 196f5edb7d637..d0a1f4c80824b 100644 --- a/tests/codegen/link_section.rs +++ b/tests/codegen/link_section.rs @@ -3,7 +3,7 @@ #![crate_type = "lib"] -// CHECK: @VAR1 = {{(dso_local )?}}constant <{ [4 x i8] }> <{ [4 x i8] c"\01\00\00\00" }>, section ".test_one" +// CHECK: @VAR1 = {{(dso_local )?}}unnamed_addr constant <{ [4 x i8] }> <{ [4 x i8] c"\01\00\00\00" }>, section ".test_one" #[no_mangle] #[link_section = ".test_one"] #[cfg(target_endian = "little")] @@ -19,12 +19,12 @@ pub enum E { B(f32), } -// CHECK: @VAR2 = {{(dso_local )?}}constant {{.*}}, section ".test_two" +// CHECK: @VAR2 = {{(dso_local )?}}unnamed_addr constant {{.*}}, section ".test_two" #[no_mangle] #[link_section = ".test_two"] pub static VAR2: E = E::A(666); -// CHECK: @VAR3 = {{(dso_local )?}}constant {{.*}}, section ".test_three" +// CHECK: @VAR3 = {{(dso_local )?}}unnamed_addr constant {{.*}}, section ".test_three" #[no_mangle] #[link_section = ".test_three"] pub static VAR3: E = E::B(1.); diff --git a/tests/ui/statics/const_generics.rs b/tests/ui/statics/const_generics.rs deleted file mode 100644 index 6cc0a65f77d52..0000000000000 --- a/tests/ui/statics/const_generics.rs +++ /dev/null @@ -1,25 +0,0 @@ -//! Check that we lose the information that `BAR` points to `FOO` -//! when going through a const generic. -//! This is not an intentional guarantee, it just describes the status quo. - -//@ run-pass -// With optimizations, LLVM will deduplicate the constant `X` whose -// value is `&42` to just be a reference to the static. This is correct, -// but obscures the issue we're trying to show. -//@ revisions: opt noopt -//@[noopt] compile-flags: -Copt-level=0 -//@[opt] compile-flags: -O - -#![feature(adt_const_params, unsized_const_params)] -#![allow(incomplete_features)] - -static FOO: usize = 42; -const BAR: &usize = &FOO; -fn foo() { - // Without optimizations, `X` ends up pointing to a copy of `FOO` instead of `FOO` itself. - assert_eq!(cfg!(opt), std::ptr::eq(X, &FOO)); -} - -fn main() { - foo::(); -}