Skip to content

Commit

Permalink
Auto merge of rust-lang#131952 - clubby789:static-unnamed-addr, r=<try>
Browse files Browse the repository at this point in the history
Always emit `unnamed_addr` for statics

Fixes rust-lang#18297

Mostly to see if anything breaks/perf

r? `@ghost`
  • Loading branch information
bors committed Oct 19, 2024
2 parents da93539 + 9dfa14b commit dc781d9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 50 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/codegen/default-visibility.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
33 changes: 16 additions & 17 deletions tests/codegen/external-no-mangle-statics.rs
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 3 additions & 3 deletions tests/codegen/link_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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.);
Expand Down
25 changes: 0 additions & 25 deletions tests/ui/statics/const_generics.rs

This file was deleted.

0 comments on commit dc781d9

Please sign in to comment.