@@ -68,15 +68,13 @@ pub enum OptLevel {
6868 SizeMin , // -Oz
6969}
7070
71+ /// This is what the `LtoCli` values get mapped to after resolving defaults and
72+ /// and taking other command line options into account.
7173#[ derive( Clone , Copy , PartialEq , Hash , Debug ) ]
7274pub enum Lto {
7375 /// Don't do any LTO whatsoever
7476 No ,
7577
76- /// Do a full crate graph LTO. The flavor is determined by the compiler
77- /// (currently the default is "fat").
78- Yes ,
79-
8078 /// Do a full crate graph LTO with ThinLTO
8179 Thin ,
8280
@@ -88,6 +86,23 @@ pub enum Lto {
8886 Fat ,
8987}
9088
89+ /// The different settings that the `-C lto` flag can have.
90+ #[ derive( Clone , Copy , PartialEq , Hash , Debug ) ]
91+ pub enum LtoCli {
92+ /// `-C lto=no`
93+ No ,
94+ /// `-C lto=yes`
95+ Yes ,
96+ /// `-C lto`
97+ NoParam ,
98+ /// `-C lto=thin`
99+ Thin ,
100+ /// `-C lto=fat`
101+ Fat ,
102+ /// No `-C lto` flag passed
103+ Unspecified ,
104+ }
105+
91106#[ derive( Clone , PartialEq , Hash ) ]
92107pub enum CrossLangLto {
93108 LinkerPlugin ( PathBuf ) ,
@@ -801,15 +816,16 @@ macro_rules! options {
801816 pub const parse_unpretty: Option <& ' static str > =
802817 Some ( "`string` or `string=string`" ) ;
803818 pub const parse_lto: Option <& ' static str > =
804- Some ( "one of `thin`, `fat`, or omitted" ) ;
819+ Some ( "either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, \
820+ `fat`, or omitted") ;
805821 pub const parse_cross_lang_lto: Option <& ' static str > =
806822 Some ( "either a boolean (`yes`, `no`, `on`, `off`, etc), \
807823 or the path to the linker plugin") ;
808824 }
809825
810826 #[ allow( dead_code) ]
811827 mod $mod_set {
812- use super :: { $struct_name, Passes , Sanitizer , Lto , CrossLangLto } ;
828+ use super :: { $struct_name, Passes , Sanitizer , LtoCli , CrossLangLto } ;
813829 use rustc_target:: spec:: { LinkerFlavor , PanicStrategy , RelroLevel } ;
814830 use std:: path:: PathBuf ;
815831
@@ -1002,11 +1018,23 @@ macro_rules! options {
10021018 }
10031019 }
10041020
1005- fn parse_lto( slot: & mut Lto , v: Option <& str >) -> bool {
1021+ fn parse_lto( slot: & mut LtoCli , v: Option <& str >) -> bool {
1022+ if v. is_some( ) {
1023+ let mut bool_arg = None ;
1024+ if parse_opt_bool( & mut bool_arg, v) {
1025+ * slot = if bool_arg. unwrap( ) {
1026+ LtoCli :: Yes
1027+ } else {
1028+ LtoCli :: No
1029+ } ;
1030+ return true
1031+ }
1032+ }
1033+
10061034 * slot = match v {
1007- None => Lto :: Yes ,
1008- Some ( "thin" ) => Lto :: Thin ,
1009- Some ( "fat" ) => Lto :: Fat ,
1035+ None => LtoCli :: NoParam ,
1036+ Some ( "thin" ) => LtoCli :: Thin ,
1037+ Some ( "fat" ) => LtoCli :: Fat ,
10101038 Some ( _) => return false ,
10111039 } ;
10121040 true
@@ -1047,7 +1075,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
10471075 "extra arguments to append to the linker invocation (space separated)" ) ,
10481076 link_dead_code: bool = ( false , parse_bool, [ UNTRACKED ] ,
10491077 "don't let linker strip dead code (turning it on can be used for code coverage)" ) ,
1050- lto: Lto = ( Lto :: No , parse_lto, [ TRACKED ] ,
1078+ lto: LtoCli = ( LtoCli :: Unspecified , parse_lto, [ TRACKED ] ,
10511079 "perform LLVM link-time optimizations" ) ,
10521080 target_cpu: Option <String > = ( None , parse_opt_string, [ TRACKED ] ,
10531081 "select target processor (rustc --print target-cpus for details)" ) ,
@@ -2384,8 +2412,8 @@ mod dep_tracking {
23842412 use std:: hash:: Hash ;
23852413 use std:: path:: PathBuf ;
23862414 use std:: collections:: hash_map:: DefaultHasher ;
2387- use super :: { CrateType , DebugInfo , ErrorOutputType , Lto , OptLevel , OutputTypes ,
2388- Passes , Sanitizer , CrossLangLto } ;
2415+ use super :: { CrateType , DebugInfo , ErrorOutputType , OptLevel , OutputTypes ,
2416+ Passes , Sanitizer , LtoCli , CrossLangLto } ;
23892417 use syntax:: feature_gate:: UnstableFeatures ;
23902418 use rustc_target:: spec:: { PanicStrategy , RelroLevel , TargetTriple } ;
23912419 use syntax:: edition:: Edition ;
@@ -2440,7 +2468,7 @@ mod dep_tracking {
24402468 impl_dep_tracking_hash_via_hash ! ( RelroLevel ) ;
24412469 impl_dep_tracking_hash_via_hash ! ( Passes ) ;
24422470 impl_dep_tracking_hash_via_hash ! ( OptLevel ) ;
2443- impl_dep_tracking_hash_via_hash ! ( Lto ) ;
2471+ impl_dep_tracking_hash_via_hash ! ( LtoCli ) ;
24442472 impl_dep_tracking_hash_via_hash ! ( DebugInfo ) ;
24452473 impl_dep_tracking_hash_via_hash ! ( UnstableFeatures ) ;
24462474 impl_dep_tracking_hash_via_hash ! ( OutputTypes ) ;
@@ -2514,7 +2542,7 @@ mod tests {
25142542 use lint;
25152543 use middle:: cstore;
25162544 use session:: config:: { build_configuration, build_session_options_and_crate_config} ;
2517- use session:: config:: { Lto , CrossLangLto } ;
2545+ use session:: config:: { LtoCli , CrossLangLto } ;
25182546 use session:: build_session;
25192547 use std:: collections:: { BTreeMap , BTreeSet } ;
25202548 use std:: iter:: FromIterator ;
@@ -2948,7 +2976,7 @@ mod tests {
29482976
29492977 // Make sure changing a [TRACKED] option changes the hash
29502978 opts = reference. clone ( ) ;
2951- opts. cg . lto = Lto :: Fat ;
2979+ opts. cg . lto = LtoCli :: Fat ;
29522980 assert ! ( reference. dep_tracking_hash( ) != opts. dep_tracking_hash( ) ) ;
29532981
29542982 opts = reference. clone ( ) ;
0 commit comments