@@ -28,53 +28,68 @@ static C_NEVER_INLINED_PATTERN: &'static str = "bl.*<c_never_inlined>";
28
28
static C_NEVER_INLINED_PATTERN : & ' static str = "call.*c_never_inlined" ;
29
29
30
30
fn 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
+
31
40
rustc ( )
41
+ . lto ( lto)
32
42
. linker_plugin_lto ( "on" )
33
43
. output ( static_lib_name ( "rustlib-xlto" ) )
34
44
. opt_level ( "2" )
35
45
. codegen_units ( 1 )
36
46
. input ( "rustlib.rs" )
37
47
. run ( ) ;
38
48
clang ( )
39
- . lto ( "thin" )
49
+ . lto ( clang_lto )
40
50
. use_ld ( "lld" )
41
51
. arg ( "-lrustlib-xlto" )
42
52
. out_exe ( "cmain" )
43
53
. input ( "cmain.c" )
44
54
. arg ( "-O3" )
45
55
. run ( ) ;
56
+
57
+ let dump = llvm_objdump ( ) . disassemble ( ) . input ( "cmain" ) . run ( ) ;
46
58
// Make sure we don't find a call instruction to the function we expect to
47
59
// 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 ) ;
53
61
// As a sanity check, make sure we do find a call instruction to a
54
62
// 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 ( ) ;
61
76
llvm_ar ( ) . obj_to_ar ( ) . output_input ( static_lib_name ( "xyz" ) , "clib.o" ) . run ( ) ;
62
77
rustc ( )
78
+ . lto ( lto)
63
79
. linker_plugin_lto ( "on" )
64
80
. opt_level ( "2" )
65
81
. linker ( & env_var ( "CLANG" ) )
66
82
. link_arg ( "-fuse-ld=lld" )
67
83
. input ( "main.rs" )
68
84
. output ( "rsmain" )
69
85
. 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
+ }
80
95
}
0 commit comments