Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_llvm/src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,11 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
) -> &'ll Value {
debug!("declare_rust_fn(name={:?}, fn_abi={:?})", name, fn_abi);

// Function addresses in Rust are never significant, allowing functions to
// be merged.
let llfn = declare_raw_fn(
self,
name,
fn_abi.llvm_cconv(self),
llvm::UnnamedAddr::Global,
llvm::UnnamedAddr::No,
llvm::Visibility::Default,
fn_abi.llvm_type(self),
);
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,12 +1284,11 @@ fn intrinsic_fn<'ll, 'tcx>(
return llfn;
}

// Function addresses in Rust are never significant, allowing functions to be merged.
let llfn = declare_raw_fn(
bx,
name,
llvm::CCallConv,
llvm::UnnamedAddr::Global,
llvm::UnnamedAddr::No,
llvm::Visibility::Default,
rust_fn_ty,
);
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-llvm/backchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ use minicore::*;

#[no_mangle]
pub fn test_backchain() {
// CHECK: @test_backchain() unnamed_addr #0
// CHECK: @test_backchain() local_unnamed_addr #0
}
// CHECK: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+backchain{{.*}} }
2 changes: 1 addition & 1 deletion tests/codegen-llvm/box-uninit-bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ pub fn box_lotsa_padding() -> Box<LotsaPadding> {

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

// CHECK-DAG: attributes [[RUST_ALLOC_ATTRS]] = { {{.*}} allockind("alloc,uninitialized,aligned"){{.*}} allocsize(0) {{(uwtable )?}}{{.*}}"alloc-family"="__rust_alloc" {{.*}} }
2 changes: 1 addition & 1 deletion tests/codegen-llvm/bpf-alu32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use minicore::*;

#[no_mangle]
#[target_feature(enable = "alu32")]
// CHECK: define {{.*}}i8 @foo(i8 {{.*}}%arg) unnamed_addr #0
// CHECK: define {{.*}}i8 @foo(i8 {{.*}}%arg) #0
// CHECK: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+alu32{{.*}} }
pub unsafe fn foo(arg: u8) -> u8 {
arg
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-llvm/fixed-x18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use minicore::*;

#[no_mangle]
pub fn foo() {
// CHECK: @foo() unnamed_addr #0
// CHECK: @foo() local_unnamed_addr #0

// unset-NOT: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+reserve-x18{{.*}} }
// set: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+reserve-x18{{.*}} }
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-llvm/function-return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use minicore::*;

#[no_mangle]
pub fn foo() {
// CHECK: @foo() unnamed_addr #0
// CHECK: @foo()

// unset-NOT: fn_ret_thunk_extern
// keep-NOT: fn_ret_thunk_extern
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen-llvm/gpu-convergent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ extern "C" {
fn ext();
}

// CHECK: define {{.*}}_kernel void @fun(i32{{.*}}) unnamed_addr #[[ATTR:[0-9]+]]
// CHECK: declare void @ext() unnamed_addr #[[ATTR]]
// CHECK: define {{.*}}_kernel void @fun(i32{{.*}}) local_unnamed_addr #[[ATTR:[0-9]+]]
// CHECK: declare void @ext() local_unnamed_addr #[[ATTR]]
// CHECK: attributes #[[ATTR]] = {{.*}} convergent
#[no_mangle]
pub extern "gpu-kernel" fn fun(_: i32) {
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-llvm/instrument-coverage/testprog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn main() {
// CHECK-SAME: @__llvm_prf_nm
// CHECK-SAME: section "llvm.metadata"

// CHECK: define internal { {{.*}} } @_R{{[a-zA-Z0-9_]+}}testprog14will_be_called() unnamed_addr #{{[0-9]+}}
// CHECK: define internal { {{.*}} } @_R{{[a-zA-Z0-9_]+}}testprog14will_be_called() #{{[0-9]+}}
// CHECK-NEXT: start:
// CHECK-NOT: define internal
// CHECK: atomicrmw add ptr
Expand Down
10 changes: 5 additions & 5 deletions tests/codegen-llvm/instrument_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ extern crate minicore;
use minicore::*;

#[no_mangle]
// CHECK: define {{.*}}void @instrument_default() {{.*}} [[DFLT_ATTR:#[0-9]+]]
// CHECK: define {{.*}}void @instrument_default() [[DFLT_ATTR:#[0-9]+]]
fn instrument_default() {}

#[no_mangle]
#[instrument_fn = "off"]
// CHECK: define {{.*}}void @instrument_off() {{.*}} [[OFF_ATTR:#[0-9]+]]
// CHECK: define {{.*}}void @instrument_off() [[OFF_ATTR:#[0-9]+]]
fn instrument_off() {}

#[no_mangle]
#[instrument_fn = "on"]
// MCOUNT: define {{.*}}void @instrument_on() {{.*}} [[DFLT_ATTR]]
// FENTRY: define void @instrument_on() {{.*}} [[DFLT_ATTR]]
// XRAY: define void @instrument_on() {{.*}} [[ON_ATTR:#[0-9]+]]
// MCOUNT: define {{.*}}void @instrument_on() [[DFLT_ATTR]]
// FENTRY: define void @instrument_on() [[DFLT_ATTR]]
// XRAY: define void @instrument_on() [[ON_ATTR:#[0-9]+]]
fn instrument_on() {}

// MCOUNT: attributes [[DFLT_ATTR]] {{.*}} "instrument-function-entry-inlined"=
Expand Down
12 changes: 6 additions & 6 deletions tests/codegen-llvm/maybe_dangling_refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@

use std::mem::MaybeDangling;

// CHECK: define {{(dso_local )?}}noundef nonnull ptr @f(ptr noundef nonnull %x) unnamed_addr
// CHECK: define {{(dso_local )?}}noundef nonnull ptr @f(ptr noundef nonnull %x)
#[no_mangle]
pub fn f(x: MaybeDangling<Box<u8>>) -> MaybeDangling<Box<u8>> {
x
}

// CHECK: define {{(dso_local )?}}noundef nonnull ptr @g(ptr noundef nonnull %x) unnamed_addr
// CHECK: define {{(dso_local )?}}noundef nonnull ptr @g(ptr noundef nonnull %x)
#[no_mangle]
pub fn g(x: MaybeDangling<&u8>) -> MaybeDangling<&u8> {
x
}

// CHECK: define {{(dso_local )?}}noundef nonnull ptr @h(ptr noundef nonnull %x) unnamed_addr
// CHECK: define {{(dso_local )?}}noundef nonnull ptr @h(ptr noundef nonnull %x)
#[no_mangle]
pub fn h(x: MaybeDangling<&mut u8>) -> MaybeDangling<&mut u8> {
x
}

// CHECK: define {{(dso_local )?}}noundef nonnull align 4 ptr @i(ptr noundef nonnull align 4 %x) unnamed_addr
// CHECK: define {{(dso_local )?}}noundef nonnull align 4 ptr @i(ptr noundef nonnull align 4 %x)
#[no_mangle]
pub fn i(x: MaybeDangling<Box<u32>>) -> MaybeDangling<Box<u32>> {
x
}

// CHECK: define {{(dso_local )?}}noundef nonnull align 4 ptr @j(ptr noundef nonnull align 4 %x) unnamed_addr
// CHECK: define {{(dso_local )?}}noundef nonnull align 4 ptr @j(ptr noundef nonnull align 4 %x)
#[no_mangle]
pub fn j(x: MaybeDangling<&u32>) -> MaybeDangling<&u32> {
x
}

// CHECK: define {{(dso_local )?}}noundef nonnull align 4 ptr @k(ptr noundef nonnull align 4 %x) unnamed_addr
// CHECK: define {{(dso_local )?}}noundef nonnull align 4 ptr @k(ptr noundef nonnull align 4 %x)
#[no_mangle]
pub fn k(x: MaybeDangling<&mut u32>) -> MaybeDangling<&mut u32> {
x
Expand Down
16 changes: 0 additions & 16 deletions tests/codegen-llvm/merge-functions.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/codegen-llvm/no-jump-tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use minicore::*;

#[no_mangle]
pub fn foo() {
// CHECK: @foo() unnamed_addr #0
// CHECK: @foo() local_unnamed_addr #0

// unset-NOT: attributes #0 = { {{.*}}"no-jump-tables"="true"{{.*}} }
// set_yes-NOT: attributes #0 = { {{.*}}"no-jump-tables"="true"{{.*}} }
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen-llvm/noreturn-uninhabited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub enum EmptyEnum {}

#[no_mangle]
pub fn empty(x: &EmptyEnum) -> EmptyEnum {
// CHECK: @empty({{.*}}) unnamed_addr #0
// CHECK: @empty({{.*}}) #0
// CHECK-NOT: ret void
// CHECK: call void @llvm.trap()
// CHECK: unreachable
Expand All @@ -18,7 +18,7 @@ pub struct Foo(String, EmptyEnum);

#[no_mangle]
pub fn foo(x: String, y: &EmptyEnum) -> Foo {
// CHECK: @foo({{.*}}) unnamed_addr #0
// CHECK: @foo({{.*}}) #0
// CHECK-NOT: ret %Foo
// CHECK: call void @llvm.trap()
// CHECK: unreachable
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen-llvm/noreturnflag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

#[no_mangle]
pub fn foo() -> ! {
// CHECK: @foo() unnamed_addr #0
// CHECK: @foo() #0
loop {}
}

pub enum EmptyEnum {}

#[no_mangle]
pub fn bar() -> EmptyEnum {
// CHECK: @bar() unnamed_addr #0
// CHECK: @bar() #0
loop {}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/codegen-llvm/nounwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate nounwind;
#[no_mangle]
pub fn foo() {
nounwind::bar();
// CHECK: @foo() unnamed_addr #0
// CHECK: @bar() unnamed_addr #0
// CHECK: @foo() #0
// CHECK: @bar() #0
// CHECK: attributes #0 = { {{.*}}nounwind{{.*}} }
}
2 changes: 1 addition & 1 deletion tests/codegen-llvm/packedstack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use minicore::*;
#[no_mangle]

pub fn test_packedstack() {
// CHECK: @test_packedstack() unnamed_addr #0
// CHECK: @test_packedstack() local_unnamed_addr #0
}

// CHECK: attributes #0 = { {{.*}}"packed-stack"{{.*}} }
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ pub fn fun8() {}
#[patchable_function_entry(entry_nops = 5, section = "baz")]
pub fn fun9() {}

// CHECK: @fun0() unnamed_addr #0
// CHECK: @fun1() unnamed_addr #1
// CHECK: @fun2() unnamed_addr #2
// CHECK: @fun3() unnamed_addr #3
// CHECK: @fun4() unnamed_addr #4
// CHECK: @fun5() unnamed_addr #5
// CHECK: @fun6() unnamed_addr #6
// CHECK: @fun7() unnamed_addr #7
// CHECK: @fun8() unnamed_addr #8
// CHECK: @fun9() unnamed_addr #9
// CHECK: @fun0(){{.*}} #0
// CHECK: @fun1(){{.*}} #1
// CHECK: @fun2(){{.*}} #2
// CHECK: @fun3(){{.*}} #3
// CHECK: @fun4(){{.*}} #4
// CHECK: @fun5(){{.*}} #5
// CHECK: @fun6(){{.*}} #6
// CHECK: @fun7(){{.*}} #7
// CHECK: @fun8(){{.*}} #8
// CHECK: @fun9(){{.*}} #9

// CHECK: attributes #0 = { {{.*}}"patchable-function-entry"="5"{{.*}}"patchable-function-prefix"="10" {{.*}} }
// CHECK: attributes #1 = { {{.*}}"patchable-function-entry"="2"{{.*}}"patchable-function-prefix"="1" {{.*}} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ pub fn fun2() {}
#[patchable_function_entry(prefix_nops = 4)]
pub fn fun3() {}

// CHECK: @fun0() unnamed_addr #0
// CHECK: @fun1() unnamed_addr #1
// CHECK: @fun2() unnamed_addr #2
// CHECK: @fun3() unnamed_addr #3
// CHECK: @fun0(){{.*}} #0
// CHECK: @fun1(){{.*}} #1
// CHECK: @fun2(){{.*}} #2
// CHECK: @fun3(){{.*}} #3

// CHECK-NOT: attributes #0 = { {{.*}}patchable-function-entry{{.*}} }
// CHECK-NOT: attributes #0 = { {{.*}}patchable-function-prefix{{.*}} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ pub fn fun5() {}
#[patchable_function_entry(prefix_nops = 4)]
pub fn fun6() {}

// CHECK: @fun0() unnamed_addr #0
// CHECK: @fun1() unnamed_addr #1
// CHECK: @fun2() unnamed_addr #2
// CHECK: @fun3() unnamed_addr #3
// CHECK: @fun4() unnamed_addr #4
// CHECK: @fun5() unnamed_addr #5
// CHECK: @fun6() unnamed_addr #6
// CHECK: @fun0(){{.*}} #0
// CHECK: @fun1(){{.*}} #1
// CHECK: @fun2(){{.*}} #2
// CHECK: @fun3(){{.*}} #3
// CHECK: @fun4(){{.*}} #4
// CHECK: @fun5(){{.*}} #5
// CHECK: @fun6(){{.*}} #6

// CHECK: attributes #0 = { {{.*}}"patchable-function-entry"="15" {{.*}} }
// CHECK-NOT: attributes #0 = { {{.*}}patchable-function-prefix{{.*}} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub fn fun0() {}
#[patchable_function_entry(section = "bar_section")]
pub fn fun1() {}

// CHECK: @fun0() unnamed_addr #0
// CHECK: @fun1() unnamed_addr #1
// CHECK: @fun0(){{.*}} #0
// CHECK: @fun1(){{.*}} #1

// CHECK: attributes #0 = { {{.*}}"patchable-function-entry"="5"{{.*}}"patchable-function-entry-section"="default_foo_section"{{.*}}"patchable-function-prefix"="10" {{.*}} }
// CHECK: attributes #1 = { {{.*}}"patchable-function-entry"="5"{{.*}}"patchable-function-entry-section"="bar_section"{{.*}}"patchable-function-prefix"="10" {{.*}} }
13 changes: 8 additions & 5 deletions tests/codegen-llvm/range-iter-loop-opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use std::num::NonZeroU8;
use std::ops::{Range, RangeInclusive};

// CHECK-LABEL: @rangeinclusive_noop_loop = unnamed_addr alias void (), ptr @range_noop_loop
// CHECK-LABEL: @rangeinclusive_nz_noop_loop = unnamed_addr alias void (), ptr @range_noop_loop

// CHECK-LABEL: @range_noop_loop(
#[no_mangle]
pub unsafe fn range_noop_loop() {
Expand All @@ -37,9 +34,12 @@ pub unsafe fn range_count(s: u8, e: u8) -> usize {
count
}

// Deduplicated to alias of range_noop_loop, checked above
// CHECK-LABEL: @rangeinclusive_noop_loop(
#[no_mangle]
pub unsafe fn rangeinclusive_noop_loop() {
// CHECK-NEXT: start:
// CHECK-NEXT: ret void

// This loop should be optimized out entirely.
for _ in 0_u8..=100 {
()
Expand All @@ -60,9 +60,12 @@ pub unsafe fn rangeinclusive_count(s: u8, e: u8) -> usize {
count
}

// Deduplicated to alias of range_noop_loop, checked above
// CHECK-LABEL: @rangeinclusive_nz_noop_loop(
#[no_mangle]
pub unsafe fn rangeinclusive_nz_noop_loop() {
// CHECK-NEXT: start:
// CHECK-NEXT: ret void

// This loop should be optimized out entirely.
for _ in NonZeroU8::new(1).unwrap()..=NonZeroU8::new(100).unwrap() {
()
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-llvm/retpoline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern crate minicore;

#[no_mangle]
pub fn foo() {
// CHECK: @foo() unnamed_addr #0
// CHECK: @foo(){{.*}} #0

// disabled-NOT: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+retpoline-external-thunk{{.*}} }
// disabled-NOT: attributes #0 = { {{.*}}"target-features"="{{[^"]*}}+retpoline-indirect-branches{{.*}} }
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-llvm/sanitizer/cfi/external_weak_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ fn main() {
}
}

// CHECK: declare !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} extern_weak void @FOO(double) unnamed_addr #{{[0-9]+}}
// CHECK: declare !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}} extern_weak void @FOO(double) #{{[0-9]+}}
2 changes: 1 addition & 1 deletion tests/codegen-llvm/sanitizer/riscv64-shadow-call-stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern crate minicore;
use minicore::*;

// CHECK: ; Function Attrs:{{.*}}shadowcallstack
// CHECK: define dso_local void @foo() unnamed_addr #0
// CHECK: define dso_local void @foo() local_unnamed_addr #0
#[no_mangle]
pub fn foo() {}

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-llvm/stack-probes-inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ use minicore::*;

#[no_mangle]
pub fn foo() {
// CHECK: @foo() unnamed_addr #0
// CHECK: @foo() #0
// CHECK: attributes #0 = { {{.*}}"probe-stack"="inline-asm"{{.*}} }
}
2 changes: 1 addition & 1 deletion tests/codegen-llvm/stack-protector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#[no_mangle]
pub fn foo() {
// CHECK: @foo() unnamed_addr #0
// CHECK: @foo(){{.*}} #0

// all-NOT: attributes #0 = { {{.*}}sspstrong {{.*}} }
// all-NOT: attributes #0 = { {{.*}}ssp {{.*}} }
Expand Down
Loading
Loading