@@ -28,53 +28,68 @@ static C_NEVER_INLINED_PATTERN: &'static str = "bl.*<c_never_inlined>";
2828static C_NEVER_INLINED_PATTERN : & ' static str = "call.*c_never_inlined" ;
2929
3030fn main ( ) {
31+ test_lto ( false ) ;
32+ test_lto ( true ) ;
33+ }
34+
35+ fn test_lto ( fat_lto : bool ) {
36+ let lto = if fat_lto { "fat" } else { "thin" } ;
37+ let clang_lto = if fat_lto { "full" } else { "thin" } ;
38+ println ! ( "Running {lto} lto" ) ;
39+
3140 rustc ( )
41+ . lto ( lto)
3242 . linker_plugin_lto ( "on" )
3343 . output ( static_lib_name ( "rustlib-xlto" ) )
3444 . opt_level ( "2" )
3545 . codegen_units ( 1 )
3646 . input ( "rustlib.rs" )
3747 . run ( ) ;
3848 clang ( )
39- . lto ( "thin" )
49+ . lto ( clang_lto )
4050 . use_ld ( "lld" )
4151 . arg ( "-lrustlib-xlto" )
4252 . out_exe ( "cmain" )
4353 . input ( "cmain.c" )
4454 . arg ( "-O3" )
4555 . run ( ) ;
56+
57+ let dump = llvm_objdump ( ) . disassemble ( ) . input ( "cmain" ) . run ( ) ;
4658 // Make sure we don't find a call instruction to the function we expect to
4759 // always be inlined.
48- llvm_objdump ( )
49- . disassemble ( )
50- . input ( "cmain" )
51- . run ( )
52- . assert_stdout_not_contains_regex ( RUST_ALWAYS_INLINED_PATTERN ) ;
60+ dump. assert_stdout_not_contains_regex ( RUST_ALWAYS_INLINED_PATTERN ) ;
5361 // As a sanity check, make sure we do find a call instruction to a
5462 // non-inlined function
55- llvm_objdump ( )
56- . disassemble ( )
57- . input ( "cmain" )
58- . run ( )
59- . assert_stdout_contains_regex ( RUST_NEVER_INLINED_PATTERN ) ;
60- clang ( ) . input ( "clib.c" ) . lto ( "thin" ) . arg ( "-c" ) . out_exe ( "clib.o" ) . arg ( "-O2" ) . run ( ) ;
63+ #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
64+ dump. assert_stdout_contains_regex ( RUST_NEVER_INLINED_PATTERN ) ;
65+ #[ cfg( any( target_arch = "aarch64" , target_arch = "arm" ) ) ]
66+ {
67+ if fat_lto {
68+ // fat lto inlines this anyway
69+ dump. assert_stdout_not_contains_regex ( RUST_NEVER_INLINED_PATTERN ) ;
70+ } else {
71+ dump. assert_stdout_contains_regex ( RUST_NEVER_INLINED_PATTERN ) ;
72+ }
73+ }
74+
75+ clang ( ) . input ( "clib.c" ) . lto ( clang_lto) . arg ( "-c" ) . out_exe ( "clib.o" ) . arg ( "-O2" ) . run ( ) ;
6176 llvm_ar ( ) . obj_to_ar ( ) . output_input ( static_lib_name ( "xyz" ) , "clib.o" ) . run ( ) ;
6277 rustc ( )
78+ . lto ( lto)
6379 . linker_plugin_lto ( "on" )
6480 . opt_level ( "2" )
6581 . linker ( & env_var ( "CLANG" ) )
6682 . link_arg ( "-fuse-ld=lld" )
6783 . input ( "main.rs" )
6884 . output ( "rsmain" )
6985 . run ( ) ;
70- llvm_objdump ( )
71- . disassemble ( )
72- . input ( "rsmain" )
73- . run ( )
74- . assert_stdout_not_contains_regex ( C_ALWAYS_INLINED_PATTERN ) ;
75- llvm_objdump ( )
76- . disassemble ( )
77- . input ( "rsmain" )
78- . run ( )
79- . assert_stdout_contains_regex ( C_NEVER_INLINED_PATTERN ) ;
86+
87+ let dump = llvm_objdump ( ) . disassemble ( ) . input ( "rsmain" ) . run ( ) ;
88+ dump. assert_stdout_not_contains_regex ( C_ALWAYS_INLINED_PATTERN ) ;
89+ if fat_lto {
90+ // fat lto inlines this anyway
91+ dump. assert_stdout_not_contains_regex ( C_NEVER_INLINED_PATTERN ) ;
92+ } else {
93+ dump. assert_stdout_contains_regex ( C_NEVER_INLINED_PATTERN ) ;
94+ }
8095}
0 commit comments