File tree Expand file tree Collapse file tree 5 files changed +69
-0
lines changed
src/test/run-make-fulldeps/cross-lang-lto-clang Expand file tree Collapse file tree 5 files changed +69
-0
lines changed Original file line number Diff line number Diff line change
1
+ # needs-matching-clang
2
+
3
+ # This test makes sure that cross-language inlining actually works by checking
4
+ # the generated machine code.
5
+
6
+ -include ../tools.mk
7
+
8
+ all : cpp-executable rust-executable
9
+
10
+ cpp-executable :
11
+ $(RUSTC ) -Zcross-lang-lto=on -o $(TMPDIR ) /librustlib-xlto.a -Copt-level=2 -Ccodegen-units=1 ./rustlib.rs
12
+ clang -flto=thin -fuse-ld=lld -L $(TMPDIR ) -lrustlib-xlto -o $(TMPDIR ) /cmain ./cmain.c -O3
13
+ # Make sure we don't find a call instruction to the function we expect to
14
+ # always be inlined.
15
+ llvm-objdump -d $(TMPDIR ) /cmain | $(CGREP ) -v -e " call.*rust_always_inlined"
16
+ # As a sanity check, make sure we do find a call instruction to a
17
+ # non-inlined function
18
+ llvm-objdump -d $(TMPDIR ) /cmain | $(CGREP ) -e " call.*rust_never_inlined"
19
+
20
+ rust-executable :
21
+ clang ./clib.c -flto=thin -c -o $(TMPDIR ) /clib.o -O2
22
+ (cd $( TMPDIR) ; $( AR) crus ./libxyz.a ./clib.o)
23
+ $(RUSTC ) -Zcross-lang-lto=on -L$(TMPDIR ) -Copt-level=2 -Clinker=clang -Clink-arg=-fuse-ld=lld ./main.rs -o $(TMPDIR ) /rsmain
24
+ llvm-objdump -d $(TMPDIR ) /rsmain | $(CGREP ) -e " call.*c_never_inlined"
25
+ llvm-objdump -d $(TMPDIR ) /rsmain | $(CGREP ) -v -e " call.*c_always_inlined"
Original file line number Diff line number Diff line change
1
+ #include <stdint.h>
2
+
3
+ uint32_t c_always_inlined () {
4
+ return 1234 ;
5
+ }
6
+
7
+ __attribute__((noinline )) uint32_t c_never_inlined () {
8
+ return 12345 ;
9
+ }
Original file line number Diff line number Diff line change
1
+ #include <stdint.h>
2
+
3
+ // A trivial function defined in Rust, returning a constant value. This should
4
+ // always be inlined.
5
+ uint32_t rust_always_inlined ();
6
+
7
+
8
+ uint32_t rust_never_inlined ();
9
+
10
+ int main (int argc , char * * argv ) {
11
+ return rust_never_inlined () + rust_always_inlined ();
12
+ }
Original file line number Diff line number Diff line change
1
+ #[ link( name = "xyz" ) ]
2
+ extern "C" {
3
+ fn c_always_inlined ( ) -> u32 ;
4
+ fn c_never_inlined ( ) -> u32 ;
5
+ }
6
+
7
+ fn main ( ) {
8
+ unsafe {
9
+ println ! ( "blub: {}" , c_always_inlined( ) + c_never_inlined( ) ) ;
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ #![ crate_type="staticlib" ]
2
+
3
+ #[ no_mangle]
4
+ pub extern "C" fn rust_always_inlined ( ) -> u32 {
5
+ 42
6
+ }
7
+
8
+ #[ no_mangle]
9
+ #[ inline( never) ]
10
+ pub extern "C" fn rust_never_inlined ( ) -> u32 {
11
+ 421
12
+ }
You can’t perform that action at this time.
0 commit comments