@@ -46,7 +46,7 @@ impl CCompilerImpl for GCC {
4646        arguments :  & [ OsString ] , 
4747        cwd :  & Path , 
4848    )  -> CompilerArguments < ParsedArguments >  { 
49-         parse_arguments ( arguments,  cwd,  & ARGS [ ..] ,  self . gplusplus ) 
49+         parse_arguments ( arguments,  cwd,  & ARGS [ ..] ,  self . gplusplus ,   CCompilerKind :: GCC ) 
5050    } 
5151
5252    fn  preprocess < T > ( 
@@ -119,6 +119,7 @@ ArgData! { pub
119119    Language ( OsString ) , 
120120    SplitDwarf , 
121121    ProfileGenerate , 
122+     ProfileUse ( PathBuf ) , 
122123    TestCoverage , 
123124    Coverage , 
124125    ExtraHashFile ( PathBuf ) , 
@@ -169,7 +170,7 @@ counted_array!(pub static ARGS: [ArgInfo<ArgData>; _] = [
169170    flag!( "-fplugin=libcc1plugin" ,  TooHardFlag ) , 
170171    flag!( "-fprofile-arcs" ,  ProfileGenerate ) , 
171172    flag!( "-fprofile-generate" ,  ProfileGenerate ) , 
172-     take_arg!( "-fprofile-use" ,  OsString ,  Concatenated ,   TooHard ) , 
173+     take_arg!( "-fprofile-use" ,  PathBuf ,  Concatenated ( '=' ) ,   ProfileUse ) , 
173174    flag!( "-frepo" ,  TooHardFlag ) , 
174175    flag!( "-fsyntax-only" ,  TooHardFlag ) , 
175176    flag!( "-ftest-coverage" ,  TestCoverage ) , 
@@ -214,6 +215,7 @@ pub fn parse_arguments<S>(
214215    cwd :  & Path , 
215216    arg_info :  S , 
216217    plusplus :  bool , 
218+     compiler_kind :  CCompilerKind , 
217219)  -> CompilerArguments < ParsedArguments > 
218220where 
219221    S :  SearchableArgInfo < ArgData > , 
@@ -275,6 +277,14 @@ where
275277                    OsString :: from ( arg. flag_str ( ) . expect ( "Compilation flag expected" ) ) ; 
276278            } 
277279            Some ( ProfileGenerate )  => profile_generate = true , 
280+             Some ( ProfileUse ( _) )  => { 
281+                 if  compiler_kind != CCompilerKind :: Clang  { 
282+                     cannot_cache ! ( 
283+                         arg. flag_str( ) . unwrap( ) , 
284+                         "only Clang supported" . into( ) 
285+                     ) 
286+                 } 
287+             } , 
278288            Some ( TestCoverage )  => outputs_gcno = true , 
279289            Some ( Coverage )  => { 
280290                outputs_gcno = true ; 
@@ -341,6 +351,20 @@ where
341351            | Some ( Arch ( _) ) 
342352            | Some ( PassThrough ( _) ) 
343353            | Some ( PassThroughPath ( _) )  => & mut  common_args, 
354+             Some ( ProfileUse ( path) )  => { 
355+                 debug_assert ! ( compiler_kind == CCompilerKind :: Clang ) ; 
356+ 
357+                 let  mut  path = cwd. join ( path) ; 
358+ 
359+                 // Clang allows specifying a directory here, in which case it 
360+                 // will look for the file `default.profdata` in that directory. 
361+                 if  path. is_dir ( )  { 
362+                     path. push ( "default.profdata" ) ; 
363+                 } 
364+ 
365+                 extra_hash_files. push ( path) ; 
366+                 & mut  common_args
367+             } 
344368            Some ( ExtraHashFile ( path) )  => { 
345369                extra_hash_files. push ( cwd. join ( path) ) ; 
346370                & mut  common_args
@@ -376,6 +400,7 @@ where
376400        let  args = match  arg. get_data ( )  { 
377401            Some ( SplitDwarf ) 
378402            | Some ( ProfileGenerate ) 
403+             | Some ( ProfileUse ( _) ) 
379404            | Some ( TestCoverage ) 
380405            | Some ( Coverage ) 
381406            | Some ( DoCompilation ) 
@@ -742,7 +767,7 @@ mod test {
742767        plusplus :  bool , 
743768    )  -> CompilerArguments < ParsedArguments >  { 
744769        let  args = arguments. iter ( ) . map ( OsString :: from) . collect :: < Vec < _ > > ( ) ; 
745-         parse_arguments ( & args,  "." . as_ref ( ) ,  & ARGS [ ..] ,  plusplus) 
770+         parse_arguments ( & args,  "." . as_ref ( ) ,  & ARGS [ ..] ,  plusplus,   CCompilerKind :: GCC ) 
746771    } 
747772
748773    #[ test]  
@@ -1204,15 +1229,16 @@ mod test {
12041229
12051230    #[ test]  
12061231    fn  test_parse_arguments_pgo ( )  { 
1232+         let  only_clang_supported = || Some ( "only Clang supported" . to_string ( ) ) ; 
12071233        assert_eq ! ( 
1208-             CompilerArguments :: CannotCache ( "-fprofile-use" ,  None ) , 
1234+             CompilerArguments :: CannotCache ( "-fprofile-use" ,  only_clang_supported ( ) ) , 
12091235            parse_arguments_( 
12101236                stringvec![ "-c" ,  "foo.c" ,  "-fprofile-use" ,  "-o" ,  "foo.o" ] , 
12111237                false 
12121238            ) 
12131239        ) ; 
12141240        assert_eq ! ( 
1215-             CompilerArguments :: CannotCache ( "-fprofile-use" ,  None ) , 
1241+             CompilerArguments :: CannotCache ( "-fprofile-use" ,  only_clang_supported ( ) ) , 
12161242            parse_arguments_( 
12171243                stringvec![ "-c" ,  "foo.c" ,  "-fprofile-use=file" ,  "-o" ,  "foo.o" ] , 
12181244                false 
0 commit comments