Skip to content

Commit dc781d9

Browse files
committed
Auto merge of rust-lang#131952 - clubby789:static-unnamed-addr, r=<try>
Always emit `unnamed_addr` for statics Fixes rust-lang#18297 Mostly to see if anything breaks/perf r? `@ghost`
2 parents da93539 + 9dfa14b commit dc781d9

File tree

5 files changed

+25
-50
lines changed

5 files changed

+25
-50
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ impl<'ll> CodegenCx<'ll, '_> {
413413

414414
llvm::LLVMRustSetLinkage(new_g, linkage);
415415
llvm::LLVMRustSetVisibility(new_g, visibility);
416+
llvm::LLVMSetUnnamedAddress(new_g, llvm::UnnamedAddr::Global);
416417

417418
// The old global has had its name removed but is returned by
418419
// get_static since it is in the instance cache. Provide an

tests/codegen/default-visibility.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
// ignore-tidy-linelength
12
// Verifies that `Session::default_visibility` is affected when using the related cmdline
23
// flag. This is a regression test for https://github.com/rust-lang/compiler-team/issues/782. See
34
// also https://github.com/rust-lang/rust/issues/73295 and
45
// https://github.com/rust-lang/rust/issues/37530.
5-
66
//@ revisions:DEFAULT HIDDEN PROTECTED INTERPOSABLE
77
//@[HIDDEN] compile-flags: -Zdefault-visibility=hidden
88
//@[PROTECTED] compile-flags: -Zdefault-visibility=protected
@@ -27,10 +27,10 @@ pub static tested_symbol: [u8; 6] = *b"foobar";
2727
//
2828
//@ only-x86_64-unknown-linux-gnu
2929

30-
// HIDDEN: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = hidden constant
31-
// PROTECTED: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = protected constant
32-
// INTERPOSABLE: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = constant
33-
// DEFAULT: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = constant
30+
// HIDDEN: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = hidden unnamed_addr constant
31+
// PROTECTED: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = protected unnamed_addr constant
32+
// INTERPOSABLE: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = unnamed_addr constant
33+
// DEFAULT: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = unnamed_addr constant
3434

3535
pub fn do_memcmp(left: &[u8], right: &[u8]) -> i32 {
3636
left.cmp(right) as i32
+16-17
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,76 @@
11
//@ revisions: lib staticlib
22
//@ ignore-emscripten default visibility is hidden
3-
//@ compile-flags: -O
43
//@ [lib] compile-flags: --crate-type lib
54
//@ [staticlib] compile-flags: --crate-type staticlib
65
// `#[no_mangle]`d static variables always have external linkage, i.e., no `internal` in their
76
// definitions
87

9-
// CHECK: @A = {{(dso_local )?}}local_unnamed_addr constant
8+
// CHECK: @A = {{(dso_local )?}}unnamed_addr constant
109
#[no_mangle]
1110
static A: u8 = 0;
1211

13-
// CHECK: @B = {{(dso_local )?}}local_unnamed_addr global
12+
// CHECK: @B = {{(dso_local )?}}unnamed_addr global
1413
#[no_mangle]
1514
static mut B: u8 = 0;
1615

17-
// CHECK: @C = {{(dso_local )?}}local_unnamed_addr constant
16+
// CHECK: @C = {{(dso_local )?}}unnamed_addr constant
1817
#[no_mangle]
1918
pub static C: u8 = 0;
2019

21-
// CHECK: @D = {{(dso_local )?}}local_unnamed_addr global
20+
// CHECK: @D = {{(dso_local )?}}unnamed_addr global
2221
#[no_mangle]
2322
pub static mut D: u8 = 0;
2423

2524
mod private {
26-
// CHECK: @E = {{(dso_local )?}}local_unnamed_addr constant
25+
// CHECK: @E = {{(dso_local )?}}unnamed_addr constant
2726
#[no_mangle]
2827
static E: u8 = 0;
2928

30-
// CHECK: @F = {{(dso_local )?}}local_unnamed_addr global
29+
// CHECK: @F = {{(dso_local )?}}unnamed_addr global
3130
#[no_mangle]
3231
static mut F: u8 = 0;
3332

34-
// CHECK: @G = {{(dso_local )?}}local_unnamed_addr constant
33+
// CHECK: @G = {{(dso_local )?}}unnamed_addr constant
3534
#[no_mangle]
3635
pub static G: u8 = 0;
3736

38-
// CHECK: @H = {{(dso_local )?}}local_unnamed_addr global
37+
// CHECK: @H = {{(dso_local )?}}unnamed_addr global
3938
#[no_mangle]
4039
pub static mut H: u8 = 0;
4140
}
4241

4342
const HIDDEN: () = {
44-
// CHECK: @I = {{(dso_local )?}}local_unnamed_addr constant
43+
// CHECK: @I = {{(dso_local )?}}unnamed_addr constant
4544
#[no_mangle]
4645
static I: u8 = 0;
4746

48-
// CHECK: @J = {{(dso_local )?}}local_unnamed_addr global
47+
// CHECK: @J = {{(dso_local )?}}unnamed_addr global
4948
#[no_mangle]
5049
static mut J: u8 = 0;
5150

52-
// CHECK: @K = {{(dso_local )?}}local_unnamed_addr constant
51+
// CHECK: @K = {{(dso_local )?}}unnamed_addr constant
5352
#[no_mangle]
5453
pub static K: u8 = 0;
5554

56-
// CHECK: @L = {{(dso_local )?}}local_unnamed_addr global
55+
// CHECK: @L = {{(dso_local )?}}unnamed_addr global
5756
#[no_mangle]
5857
pub static mut L: u8 = 0;
5958
};
6059

6160
fn x() {
62-
// CHECK: @M = {{(dso_local )?}}local_unnamed_addr constant
61+
// CHECK: @M = {{(dso_local )?}}unnamed_addr constant
6362
#[no_mangle]
6463
static M: fn() = x;
6564

66-
// CHECK: @N = {{(dso_local )?}}local_unnamed_addr global
65+
// CHECK: @N = {{(dso_local )?}}unnamed_addr global
6766
#[no_mangle]
6867
static mut N: u8 = 0;
6968

70-
// CHECK: @O = {{(dso_local )?}}local_unnamed_addr constant
69+
// CHECK: @O = {{(dso_local )?}}unnamed_addr constant
7170
#[no_mangle]
7271
pub static O: u8 = 0;
7372

74-
// CHECK: @P = {{(dso_local )?}}local_unnamed_addr global
73+
// CHECK: @P = {{(dso_local )?}}unnamed_addr global
7574
#[no_mangle]
7675
pub static mut P: u8 = 0;
7776
}

tests/codegen/link_section.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#![crate_type = "lib"]
55

6-
// CHECK: @VAR1 = {{(dso_local )?}}constant <{ [4 x i8] }> <{ [4 x i8] c"\01\00\00\00" }>, section ".test_one"
6+
// CHECK: @VAR1 = {{(dso_local )?}}unnamed_addr constant <{ [4 x i8] }> <{ [4 x i8] c"\01\00\00\00" }>, section ".test_one"
77
#[no_mangle]
88
#[link_section = ".test_one"]
99
#[cfg(target_endian = "little")]
@@ -19,12 +19,12 @@ pub enum E {
1919
B(f32),
2020
}
2121

22-
// CHECK: @VAR2 = {{(dso_local )?}}constant {{.*}}, section ".test_two"
22+
// CHECK: @VAR2 = {{(dso_local )?}}unnamed_addr constant {{.*}}, section ".test_two"
2323
#[no_mangle]
2424
#[link_section = ".test_two"]
2525
pub static VAR2: E = E::A(666);
2626

27-
// CHECK: @VAR3 = {{(dso_local )?}}constant {{.*}}, section ".test_three"
27+
// CHECK: @VAR3 = {{(dso_local )?}}unnamed_addr constant {{.*}}, section ".test_three"
2828
#[no_mangle]
2929
#[link_section = ".test_three"]
3030
pub static VAR3: E = E::B(1.);

tests/ui/statics/const_generics.rs

-25
This file was deleted.

0 commit comments

Comments
 (0)