Skip to content

Commit 24a767d

Browse files
committed
Add assembly tests for -Zreg-struct-return
1 parent d06c2d4 commit 24a767d

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Test the reg-struct-return ABI.
2+
//@ add-core-stubs
3+
//@ assembly-output: emit-asm
4+
//@ compile-flags: -O --target=i686-unknown-linux-gnu -Crelocation-model=static
5+
//@ revisions: WITH WITHOUT
6+
//@[WITH] compile-flags: -Zreg-struct-return
7+
//@ needs-llvm-components: x86
8+
9+
#![feature(no_core)]
10+
#![no_std]
11+
#![no_core]
12+
#![crate_type = "lib"]
13+
14+
extern crate minicore;
15+
use minicore::*;
16+
17+
struct div_t {
18+
quot: i32,
19+
rem: i32,
20+
}
21+
22+
unsafe extern "C" {
23+
fn div(numerator: i32, denominator: i32) -> div_t;
24+
}
25+
26+
#[unsafe(no_mangle)]
27+
pub unsafe extern "C" fn direct_construction(numerator: i32, denominator: i32) -> div_t {
28+
// WITH-LABEL: direct_construction
29+
// WITH: movl $42, %eax
30+
// WITH: movl $42, %edx
31+
// WITH: retl
32+
33+
// WITHOUT-LABEL: direct_construction
34+
// WITHOUT: movl 4(%esp), %eax
35+
// WITHOUT: movl $42, (%eax)
36+
// WITHOUT: movl $42, 4(%eax)
37+
// WITHOUT: retl $4
38+
div_t { quot: 42, rem: 42 }
39+
}
40+
41+
#[unsafe(no_mangle)]
42+
pub unsafe extern "C" fn builtin_call(numerator: i32, denominator: i32) -> div_t {
43+
// WITH-LABEL: builtin_call
44+
// WITH: jmp div
45+
46+
// WITHOUT-LABEL: builtin_call
47+
// WITHOUT: pushl %esi
48+
// WITHOUT: subl $8, %esp
49+
// WITHOUT: movl 16(%esp), %esi
50+
// WITHOUT: subl $4, %esp
51+
// WITHOUT: pushl 28(%esp)
52+
// WITHOUT: pushl 28(%esp)
53+
// WITHOUT: pushl %esi
54+
// WITHOUT: calll div
55+
// WITHOUT: addl $12, %esp
56+
// WITHOUT: movl %esi, %eax
57+
// WITHOUT: addl $8, %esp
58+
// WITHOUT: popl %esi
59+
// WITHOUT: retl $4
60+
div(numerator, denominator)
61+
}

0 commit comments

Comments
 (0)