Skip to content

Commit dcf5482

Browse files
committed
Add an idealistic test for optimize attribute
Alas it does not currently work, because of limitations in compiletest…
1 parent f38d0da commit dcf5482

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/test/codegen/optimize-attr-1.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// revisions: NO-OPT SIZE-OPT SPEED-OPT
2+
// [NO-OPT]compile-flags: -Copt-level=0
3+
// [SIZE-OPT]compile-flags: -Copt-level=s
4+
// [SPEED-OPT]compile-flags: -Copt-level=3
5+
6+
#![feature(optimize_attribute)]
7+
#![crate_type="rlib"]
8+
9+
// NO-OPT: Function Attrs:{{.*}}optnone
10+
// NO-OPT-NOT: {{optsize|minsize}}
11+
// NO-OPT-NEXT: @nothing
12+
// NO-OPT: ret i32 %1
13+
//
14+
// SIZE-OPT: Function Attrs:{{.*}}optsize
15+
// SIZE-OPT-NOT: {{minsize|optnone}}
16+
// SIZE-OPT-NEXT: @nothing
17+
// SIZE-OPT-NEXT: start
18+
// SIZE-OPT-NEXT: ret i32 4
19+
//
20+
// SPEED-OPT: Function Attrs:
21+
// SPEED-OPT-NOT: {{minsize|optnone|optsize}}
22+
// SPEED-OPT-NEXT: @nothing
23+
// SPEED-OPT-NEXT: start
24+
// SPEED-OPT-NEXT: ret i32 4
25+
#[no_mangle]
26+
pub fn nothing() -> i32 {
27+
2 + 2
28+
}
29+
30+
// CHECK: Function Attrs:{{.*}} minsize{{.*}}optsize
31+
// CHECK-NEXT: @size
32+
// CHECK-NEXT: start
33+
// CHECK-NEXT: ret i32 4
34+
#[optimize(size)]
35+
#[no_mangle]
36+
pub fn size() -> i32 {
37+
2 + 2
38+
}
39+
40+
// CHECK: Function Attrs:
41+
// CHECK-NOT: {{minsize|optsize|optnone}}
42+
// CHECK-NEXT: @speed
43+
// CHECK-NEXT: start
44+
// CHECK-NEXT: ret i32 4
45+
#[optimize(speed)]
46+
#[no_mangle]
47+
pub fn speed() -> i32 {
48+
2 + 2
49+
}

0 commit comments

Comments
 (0)