-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Expand file tree
/
Copy pathcold-attribute.rs
More file actions
78 lines (67 loc) · 1.85 KB
/
cold-attribute.rs
File metadata and controls
78 lines (67 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Checks that the cold attribute adds the llvm cold attribute.
//
//@ reference: attributes.codegen.cold.intro
//@ reference: attributes.codegen.cold.trait
//@ edition:2024
//@ compile-flags: -Copt-level=0
#![crate_type = "lib"]
// CHECK-LABEL: ; cold_attribute::free_function
// CHECK-NEXT: Function Attrs: cold {{.*}}
#[cold]
pub fn free_function() {}
// CHECK-LABEL: ; cold_attribute::async_block
// CHECK-NEXT: Function Attrs: cold {{.*}}
#[cold]
pub async fn async_block() {
async fn x(f: impl Future<Output = ()>) {
f.await;
}
x(
// CHECK-LABEL: ; cold_attribute::async_block::{closure#0}::{closure#0}
// CHECK-NEXT: Function Attrs: cold {{.*}}
#[cold]
async {},
)
.await;
}
pub fn closure() {
fn x(f: impl Fn()) {
f()
}
x(
// CHECK-LABEL: ; cold_attribute::closure::{closure#0}
// CHECK-NEXT: Function Attrs: cold {{.*}}
#[cold]
|| {},
);
}
pub struct S;
impl S {
// CHECK-LABEL: ; <cold_attribute::S>::method
// CHECK-NEXT: Function Attrs: cold {{.*}}
#[cold]
pub fn method(&self) {}
}
pub trait Trait {
// CHECK-LABEL: ; <cold_attribute::S as cold_attribute::Trait>::trait_fn
// CHECK-NEXT: Function Attrs: cold {{.*}}
#[cold]
fn trait_fn(&self) {}
#[cold]
fn trait_fn_overridden(&self) {}
fn impl_fn(&self);
}
impl Trait for S {
// CHECK-LABEL: ; <cold_attribute::S as cold_attribute::Trait>::impl_fn
// CHECK-NEXT: Function Attrs: cold {{.*}}
#[cold]
fn impl_fn(&self) {
self.trait_fn();
}
// This does not have #[cold], and does not inherit the cold attribute from the trait.
// CHECK-LABEL: ; <cold_attribute::S as cold_attribute::Trait>::trait_fn_overridden
// CHECK: ; Function Attrs:
// CHECK-NOT: cold
// CHECK: define
fn trait_fn_overridden(&self) {}
}