Skip to content

Commit e318af1

Browse files
committed
tests: add an assembly scanning test for s390x backchain switch
1 parent e98e88b commit e318af1

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//@ revisions: enable-backchain disable-backchain
2+
//@ assembly-output: emit-asm
3+
//@ compile-flags: -O --crate-type=lib --target=s390x-unknown-linux-gnu
4+
//@ needs-llvm-components: systemz
5+
//@[enable-backchain] compile-flags: -Ctarget-feature=+backchain
6+
//@[disable-backchain] compile-flags: -Ctarget-feature=-backchain
7+
#![feature(no_core, lang_items)]
8+
#![no_std]
9+
#![no_core]
10+
11+
#[lang = "sized"]
12+
trait Sized {}
13+
14+
extern "C" {
15+
fn extern_func();
16+
}
17+
18+
// CHECK-LABEL: test_backchain
19+
#[no_mangle]
20+
extern "C" fn test_backchain() -> i32 {
21+
// Here we try to match if backchain register is saved to the parameter area (stored in r15/sp)
22+
// And also if a new parameter area (160 bytes) is allocated for the upcoming function call
23+
// enable-backchain: lgr [[REG1:.*]], %r15
24+
// enable-backchain-NEXT: aghi %r15, -160
25+
// enable-backchain: stg [[REG1]], 0(%r15)
26+
// disable-backchain: aghi %r15, -160
27+
// disable-backchain-NOT: stg %r{{.*}}, 0(%r15)
28+
unsafe {
29+
extern_func();
30+
}
31+
// enable-backchain-NEXT: brasl %r{{.*}}, extern_func@PLT
32+
33+
// Make sure that the expected return value is written into %r2 (return register):
34+
// enable-backchain-NEXT: lghi %r2, 1
35+
// disable-backchain: lghi %r2, 0
36+
#[cfg(target_feature = "backchain")]
37+
{
38+
1
39+
}
40+
#[cfg(not(target_feature = "backchain"))]
41+
{
42+
0
43+
}
44+
// CHECK: br %r{{.*}}
45+
}

0 commit comments

Comments
 (0)