Skip to content

Commit dc1ed9d

Browse files
committed
codegen: allow the dso_local attribute
The attribute is injected into most items when static relocation is enabled in a target.
1 parent 5fdeae6 commit dc1ed9d

9 files changed

+50
-50
lines changed

tests/codegen/box-maybe-uninit-llvm14.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ pub fn box_uninitialized2() -> Box<MaybeUninit<[usize; 1024 * 1024]>> {
3131
// Hide the LLVM 15+ `allocalign` attribute in the declaration of __rust_alloc
3232
// from the CHECK-NOT above. We don't check the attributes here because we can't rely
3333
// on all of them being set until LLVM 15.
34-
// CHECK: declare noalias{{.*}} @__rust_alloc(i{{[0-9]+}} noundef, i{{[0-9]+.*}} noundef)
34+
// CHECK: declare {{(dso_local )?}}noalias{{.*}} @__rust_alloc(i{{[0-9]+}} noundef, i{{[0-9]+.*}} noundef)

tests/codegen/box-maybe-uninit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ pub fn box_uninitialized2() -> Box<MaybeUninit<[usize; 1024 * 1024]>> {
2828

2929
// Hide the `allocalign` attribute in the declaration of __rust_alloc
3030
// from the CHECK-NOT above, and also verify the attributes got set reasonably.
31-
// CHECK: declare noalias noundef ptr @__rust_alloc(i{{[0-9]+}} noundef, i{{[0-9]+}} allocalign noundef) unnamed_addr [[RUST_ALLOC_ATTRS:#[0-9]+]]
31+
// CHECK: declare {{(dso_local )?}}noalias noundef ptr @__rust_alloc(i{{[0-9]+}} noundef, i{{[0-9]+}} allocalign noundef) unnamed_addr [[RUST_ALLOC_ATTRS:#[0-9]+]]
3232

3333
// CHECK-DAG: attributes [[RUST_ALLOC_ATTRS]] = { {{.*}} allockind("alloc,uninitialized,aligned") allocsize(0) uwtable "alloc-family"="__rust_alloc" {{.*}} }

tests/codegen/external-no-mangle-statics.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,72 +6,72 @@
66
// `#[no_mangle]`d static variables always have external linkage, i.e., no `internal` in their
77
// definitions
88

9-
// CHECK: @A = local_unnamed_addr constant
9+
// CHECK: @A = {{(dso_local )?}}local_unnamed_addr constant
1010
#[no_mangle]
1111
static A: u8 = 0;
1212

13-
// CHECK: @B = local_unnamed_addr global
13+
// CHECK: @B = {{(dso_local )?}}local_unnamed_addr global
1414
#[no_mangle]
1515
static mut B: u8 = 0;
1616

17-
// CHECK: @C = local_unnamed_addr constant
17+
// CHECK: @C = {{(dso_local )?}}local_unnamed_addr constant
1818
#[no_mangle]
1919
pub static C: u8 = 0;
2020

21-
// CHECK: @D = local_unnamed_addr global
21+
// CHECK: @D = {{(dso_local )?}}local_unnamed_addr global
2222
#[no_mangle]
2323
pub static mut D: u8 = 0;
2424

2525
mod private {
26-
// CHECK: @E = local_unnamed_addr constant
26+
// CHECK: @E = {{(dso_local )?}}local_unnamed_addr constant
2727
#[no_mangle]
2828
static E: u8 = 0;
2929

30-
// CHECK: @F = local_unnamed_addr global
30+
// CHECK: @F = {{(dso_local )?}}local_unnamed_addr global
3131
#[no_mangle]
3232
static mut F: u8 = 0;
3333

34-
// CHECK: @G = local_unnamed_addr constant
34+
// CHECK: @G = {{(dso_local )?}}local_unnamed_addr constant
3535
#[no_mangle]
3636
pub static G: u8 = 0;
3737

38-
// CHECK: @H = local_unnamed_addr global
38+
// CHECK: @H = {{(dso_local )?}}local_unnamed_addr global
3939
#[no_mangle]
4040
pub static mut H: u8 = 0;
4141
}
4242

4343
const HIDDEN: () = {
44-
// CHECK: @I = local_unnamed_addr constant
44+
// CHECK: @I = {{(dso_local )?}}local_unnamed_addr constant
4545
#[no_mangle]
4646
static I: u8 = 0;
4747

48-
// CHECK: @J = local_unnamed_addr global
48+
// CHECK: @J = {{(dso_local )?}}local_unnamed_addr global
4949
#[no_mangle]
5050
static mut J: u8 = 0;
5151

52-
// CHECK: @K = local_unnamed_addr constant
52+
// CHECK: @K = {{(dso_local )?}}local_unnamed_addr constant
5353
#[no_mangle]
5454
pub static K: u8 = 0;
5555

56-
// CHECK: @L = local_unnamed_addr global
56+
// CHECK: @L = {{(dso_local )?}}local_unnamed_addr global
5757
#[no_mangle]
5858
pub static mut L: u8 = 0;
5959
};
6060

6161
fn x() {
62-
// CHECK: @M = local_unnamed_addr constant
62+
// CHECK: @M = {{(dso_local )?}}local_unnamed_addr constant
6363
#[no_mangle]
6464
static M: fn() = x;
6565

66-
// CHECK: @N = local_unnamed_addr global
66+
// CHECK: @N = {{(dso_local )?}}local_unnamed_addr global
6767
#[no_mangle]
6868
static mut N: u8 = 0;
6969

70-
// CHECK: @O = local_unnamed_addr constant
70+
// CHECK: @O = {{(dso_local )?}}local_unnamed_addr constant
7171
#[no_mangle]
7272
pub static O: u8 = 0;
7373

74-
// CHECK: @P = local_unnamed_addr global
74+
// CHECK: @P = {{(dso_local )?}}local_unnamed_addr global
7575
#[no_mangle]
7676
pub static mut P: u8 = 0;
7777
}

tests/codegen/issues/issue-86106.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#![crate_type = "lib"]
99

10-
// CHECK-LABEL: define void @string_new
10+
// CHECK-LABEL: define {{(dso_local )?}}void @string_new
1111
#[no_mangle]
1212
pub fn string_new() -> String {
1313
// CHECK: store ptr inttoptr
@@ -17,7 +17,7 @@ pub fn string_new() -> String {
1717
String::new()
1818
}
1919

20-
// CHECK-LABEL: define void @empty_to_string
20+
// CHECK-LABEL: define {{(dso_local )?}}void @empty_to_string
2121
#[no_mangle]
2222
pub fn empty_to_string() -> String {
2323
// CHECK: store ptr inttoptr

tests/codegen/link_section.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#![crate_type = "lib"]
55

6-
// CHECK: @VAR1 = constant <{ [4 x i8] }> <{ [4 x i8] c"\01\00\00\00" }>, section ".test_one"
6+
// CHECK: @VAR1 = {{(dso_local )?}}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,17 +19,17 @@ pub enum E {
1919
B(f32)
2020
}
2121

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

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

32-
// CHECK: define void @fn1() {{.*}} section ".test_four" {
32+
// CHECK: define {{(dso_local )?}}void @fn1() {{.*}} section ".test_four" {
3333
#[no_mangle]
3434
#[link_section = ".test_four"]
3535
pub fn fn1() {}

tests/codegen/naked-noinline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::arch::asm;
1212
pub unsafe extern "C" fn f() {
1313
// Check that f has naked and noinline attributes.
1414
//
15-
// CHECK: define void @f() unnamed_addr [[ATTR:#[0-9]+]]
15+
// CHECK: define {{(dso_local )?}}void @f() unnamed_addr [[ATTR:#[0-9]+]]
1616
// CHECK-NEXT: start:
1717
// CHECK-NEXT: call void asm
1818
asm!("", options(noreturn));
@@ -22,7 +22,7 @@ pub unsafe extern "C" fn f() {
2222
pub unsafe fn g() {
2323
// Check that call to f is not inlined.
2424
//
25-
// CHECK-LABEL: define void @g()
25+
// CHECK-LABEL: define {{(dso_local )?}}void @g()
2626
// CHECK-NEXT: start:
2727
// CHECK-NEXT: call void @f()
2828
f();

tests/codegen/ptr-read-metadata.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use std::mem::MaybeUninit;
1111

12-
// CHECK-LABEL: define noundef i8 @copy_byte(
12+
// CHECK-LABEL: define {{(dso_local )?}}noundef i8 @copy_byte(
1313
#[no_mangle]
1414
pub unsafe fn copy_byte(p: *const u8) -> u8 {
1515
// CHECK-NOT: load
@@ -19,7 +19,7 @@ pub unsafe fn copy_byte(p: *const u8) -> u8 {
1919
*p
2020
}
2121

22-
// CHECK-LABEL: define noundef i8 @read_byte(
22+
// CHECK-LABEL: define {{(dso_local )?}}noundef i8 @read_byte(
2323
#[no_mangle]
2424
pub unsafe fn read_byte(p: *const u8) -> u8 {
2525
// CHECK-NOT: load
@@ -29,7 +29,7 @@ pub unsafe fn read_byte(p: *const u8) -> u8 {
2929
p.read()
3030
}
3131

32-
// CHECK-LABEL: define i8 @read_byte_maybe_uninit(
32+
// CHECK-LABEL: define {{(dso_local )?}}i8 @read_byte_maybe_uninit(
3333
#[no_mangle]
3434
pub unsafe fn read_byte_maybe_uninit(p: *const MaybeUninit<u8>) -> MaybeUninit<u8> {
3535
// CHECK-NOT: load
@@ -39,7 +39,7 @@ pub unsafe fn read_byte_maybe_uninit(p: *const MaybeUninit<u8>) -> MaybeUninit<u
3939
p.read()
4040
}
4141

42-
// CHECK-LABEL: define noundef i8 @read_byte_assume_init(
42+
// CHECK-LABEL: define {{(dso_local )?}}noundef i8 @read_byte_assume_init(
4343
#[no_mangle]
4444
pub unsafe fn read_byte_assume_init(p: &MaybeUninit<u8>) -> u8 {
4545
// CHECK-NOT: load
@@ -49,7 +49,7 @@ pub unsafe fn read_byte_assume_init(p: &MaybeUninit<u8>) -> u8 {
4949
p.assume_init_read()
5050
}
5151

52-
// CHECK-LABEL: define noundef i32 @copy_char(
52+
// CHECK-LABEL: define {{(dso_local )?}}noundef i32 @copy_char(
5353
#[no_mangle]
5454
pub unsafe fn copy_char(p: *const char) -> char {
5555
// CHECK-NOT: load
@@ -60,7 +60,7 @@ pub unsafe fn copy_char(p: *const char) -> char {
6060
*p
6161
}
6262

63-
// CHECK-LABEL: define noundef i32 @read_char(
63+
// CHECK-LABEL: define {{(dso_local )?}}noundef i32 @read_char(
6464
#[no_mangle]
6565
pub unsafe fn read_char(p: *const char) -> char {
6666
// CHECK-NOT: load
@@ -71,7 +71,7 @@ pub unsafe fn read_char(p: *const char) -> char {
7171
p.read()
7272
}
7373

74-
// CHECK-LABEL: define i32 @read_char_maybe_uninit(
74+
// CHECK-LABEL: define {{(dso_local )?}}i32 @read_char_maybe_uninit(
7575
#[no_mangle]
7676
pub unsafe fn read_char_maybe_uninit(p: *const MaybeUninit<char>) -> MaybeUninit<char> {
7777
// CHECK-NOT: load
@@ -82,7 +82,7 @@ pub unsafe fn read_char_maybe_uninit(p: *const MaybeUninit<char>) -> MaybeUninit
8282
p.read()
8383
}
8484

85-
// CHECK-LABEL: define noundef i32 @read_char_assume_init(
85+
// CHECK-LABEL: define {{(dso_local )?}}noundef i32 @read_char_assume_init(
8686
#[no_mangle]
8787
pub unsafe fn read_char_assume_init(p: &MaybeUninit<char>) -> char {
8888
// CHECK-NOT: load

tests/codegen/tuple-layout-opt.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@
66
#![crate_type="lib"]
77

88
type ScalarZstLast = (u128, ());
9-
// CHECK: define i128 @test_ScalarZstLast(i128 %_1)
9+
// CHECK: define {{(dso_local )?}}i128 @test_ScalarZstLast(i128 %_1)
1010
#[no_mangle]
1111
pub fn test_ScalarZstLast(_: ScalarZstLast) -> ScalarZstLast { loop {} }
1212

1313
type ScalarZstFirst = ((), u128);
14-
// CHECK: define i128 @test_ScalarZstFirst(i128 %_1)
14+
// CHECK: define {{(dso_local )?}}i128 @test_ScalarZstFirst(i128 %_1)
1515
#[no_mangle]
1616
pub fn test_ScalarZstFirst(_: ScalarZstFirst) -> ScalarZstFirst { loop {} }
1717

1818
type ScalarPairZstLast = (u8, u128, ());
19-
// CHECK: define { i128, i8 } @test_ScalarPairZstLast(i128 %_1.0, i8 %_1.1)
19+
// CHECK: define {{(dso_local )?}}{ i128, i8 } @test_ScalarPairZstLast(i128 %_1.0, i8 %_1.1)
2020
#[no_mangle]
2121
pub fn test_ScalarPairZstLast(_: ScalarPairZstLast) -> ScalarPairZstLast { loop {} }
2222

2323
type ScalarPairZstFirst = ((), u8, u128);
24-
// CHECK: define { i8, i128 } @test_ScalarPairZstFirst(i8 %_1.0, i128 %_1.1)
24+
// CHECK: define {{(dso_local )?}}{ i8, i128 } @test_ScalarPairZstFirst(i8 %_1.0, i128 %_1.1)
2525
#[no_mangle]
2626
pub fn test_ScalarPairZstFirst(_: ScalarPairZstFirst) -> ScalarPairZstFirst { loop {} }
2727

2828
type ScalarPairLotsOfZsts = ((), u8, (), u128, ());
29-
// CHECK: define { i128, i8 } @test_ScalarPairLotsOfZsts(i128 %_1.0, i8 %_1.1)
29+
// CHECK: define {{(dso_local )?}}{ i128, i8 } @test_ScalarPairLotsOfZsts(i128 %_1.0, i8 %_1.1)
3030
#[no_mangle]
3131
pub fn test_ScalarPairLotsOfZsts(_: ScalarPairLotsOfZsts) -> ScalarPairLotsOfZsts { loop {} }
3232

3333
type ScalarPairLottaNesting = (((), ((), u8, (), u128, ())), ());
34-
// CHECK: define { i128, i8 } @test_ScalarPairLottaNesting(i128 %_1.0, i8 %_1.1)
34+
// CHECK: define {{(dso_local )?}}{ i128, i8 } @test_ScalarPairLottaNesting(i128 %_1.0, i8 %_1.1)
3535
#[no_mangle]
3636
pub fn test_ScalarPairLottaNesting(_: ScalarPairLottaNesting) -> ScalarPairLottaNesting { loop {} }

tests/codegen/union-abi.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,60 +17,60 @@ pub struct i64x4(i64, i64, i64, i64);
1717
#[derive(Copy, Clone)]
1818
pub union UnionI64x4{ a:(), b: i64x4 }
1919

20-
// CHECK: define void @test_UnionI64x4({{<4 x i64>\*|ptr}} {{.*}} %_1)
20+
// CHECK: define {{(dso_local )?}}void @test_UnionI64x4({{<4 x i64>\*|ptr}} {{.*}} %_1)
2121
#[no_mangle]
2222
pub fn test_UnionI64x4(_: UnionI64x4) { loop {} }
2323

2424
pub union UnionI64x4_{ a: i64x4, b: (), c:i64x4, d: Unhab, e: ((),()), f: UnionI64x4 }
2525

26-
// CHECK: define void @test_UnionI64x4_({{<4 x i64>\*|ptr}} {{.*}} %_1)
26+
// CHECK: define {{(dso_local )?}}void @test_UnionI64x4_({{<4 x i64>\*|ptr}} {{.*}} %_1)
2727
#[no_mangle]
2828
pub fn test_UnionI64x4_(_: UnionI64x4_) { loop {} }
2929

3030
pub union UnionI64x4I64{ a: i64x4, b: i64 }
3131

32-
// CHECK: define void @test_UnionI64x4I64({{%UnionI64x4I64\*|ptr}} {{.*}} %_1)
32+
// CHECK: define {{(dso_local )?}}void @test_UnionI64x4I64({{%UnionI64x4I64\*|ptr}} {{.*}} %_1)
3333
#[no_mangle]
3434
pub fn test_UnionI64x4I64(_: UnionI64x4I64) { loop {} }
3535

3636
pub union UnionI64x4Tuple{ a: i64x4, b: (i64, i64, i64, i64) }
3737

38-
// CHECK: define void @test_UnionI64x4Tuple({{%UnionI64x4Tuple\*|ptr}} {{.*}} %_1)
38+
// CHECK: define {{(dso_local )?}}void @test_UnionI64x4Tuple({{%UnionI64x4Tuple\*|ptr}} {{.*}} %_1)
3939
#[no_mangle]
4040
pub fn test_UnionI64x4Tuple(_: UnionI64x4Tuple) { loop {} }
4141

4242

4343
pub union UnionF32{a:f32}
4444

45-
// CHECK: define float @test_UnionF32(float %_1)
45+
// CHECK: define {{(dso_local )?}}float @test_UnionF32(float %_1)
4646
#[no_mangle]
4747
pub fn test_UnionF32(_: UnionF32) -> UnionF32 { loop {} }
4848

4949
pub union UnionF32F32{a:f32, b:f32}
5050

51-
// CHECK: define float @test_UnionF32F32(float %_1)
51+
// CHECK: define {{(dso_local )?}}float @test_UnionF32F32(float %_1)
5252
#[no_mangle]
5353
pub fn test_UnionF32F32(_: UnionF32F32) -> UnionF32F32 { loop {} }
5454

5555
pub union UnionF32U32{a:f32, b:u32}
5656

57-
// CHECK: define i32 @test_UnionF32U32(i32{{( %0)?}})
57+
// CHECK: define {{(dso_local )?}}i32 @test_UnionF32U32(i32{{( %0)?}})
5858
#[no_mangle]
5959
pub fn test_UnionF32U32(_: UnionF32U32) -> UnionF32U32 { loop {} }
6060

6161
pub union UnionU128{a:u128}
62-
// CHECK: define i128 @test_UnionU128(i128 %_1)
62+
// CHECK: define {{(dso_local )?}}i128 @test_UnionU128(i128 %_1)
6363
#[no_mangle]
6464
pub fn test_UnionU128(_: UnionU128) -> UnionU128 { loop {} }
6565

6666
#[repr(C)]
6767
pub union CUnionU128{a:u128}
68-
// CHECK: define void @test_CUnionU128({{%CUnionU128\*|ptr}} {{.*}} %_1)
68+
// CHECK: define {{(dso_local )?}}void @test_CUnionU128({{%CUnionU128\*|ptr}} {{.*}} %_1)
6969
#[no_mangle]
7070
pub fn test_CUnionU128(_: CUnionU128) { loop {} }
7171

7272
pub union UnionBool { b:bool }
73-
// CHECK: define noundef zeroext i1 @test_UnionBool(i8 %b)
73+
// CHECK: define {{(dso_local )?}}noundef zeroext i1 @test_UnionBool(i8 %b)
7474
#[no_mangle]
7575
pub fn test_UnionBool(b: UnionBool) -> bool { unsafe { b.b } }
7676
// CHECK: %0 = trunc i8 %b to i1

0 commit comments

Comments
 (0)