@@ -46,7 +46,7 @@ impl CCompilerImpl for GCC {
46
46
arguments : & [ OsString ] ,
47
47
cwd : & Path ,
48
48
) -> CompilerArguments < ParsedArguments > {
49
- parse_arguments ( arguments, cwd, & ARGS [ ..] , self . gplusplus )
49
+ parse_arguments ( arguments, cwd, & ARGS [ ..] , self . gplusplus , CCompilerKind :: GCC )
50
50
}
51
51
52
52
fn preprocess < T > (
@@ -119,6 +119,7 @@ ArgData! { pub
119
119
Language ( OsString ) ,
120
120
SplitDwarf ,
121
121
ProfileGenerate ,
122
+ ProfileUse ( PathBuf ) ,
122
123
TestCoverage ,
123
124
Coverage ,
124
125
ExtraHashFile ( PathBuf ) ,
@@ -169,7 +170,7 @@ counted_array!(pub static ARGS: [ArgInfo<ArgData>; _] = [
169
170
flag!( "-fplugin=libcc1plugin" , TooHardFlag ) ,
170
171
flag!( "-fprofile-arcs" , ProfileGenerate ) ,
171
172
flag!( "-fprofile-generate" , ProfileGenerate ) ,
172
- take_arg!( "-fprofile-use" , OsString , Concatenated , TooHard ) ,
173
+ take_arg!( "-fprofile-use" , PathBuf , Concatenated ( '=' ) , ProfileUse ) ,
173
174
flag!( "-frepo" , TooHardFlag ) ,
174
175
flag!( "-fsyntax-only" , TooHardFlag ) ,
175
176
flag!( "-ftest-coverage" , TestCoverage ) ,
@@ -214,6 +215,7 @@ pub fn parse_arguments<S>(
214
215
cwd : & Path ,
215
216
arg_info : S ,
216
217
plusplus : bool ,
218
+ compiler_kind : CCompilerKind ,
217
219
) -> CompilerArguments < ParsedArguments >
218
220
where
219
221
S : SearchableArgInfo < ArgData > ,
@@ -275,6 +277,14 @@ where
275
277
OsString :: from ( arg. flag_str ( ) . expect ( "Compilation flag expected" ) ) ;
276
278
}
277
279
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
+ } ,
278
288
Some ( TestCoverage ) => outputs_gcno = true ,
279
289
Some ( Coverage ) => {
280
290
outputs_gcno = true ;
@@ -341,6 +351,20 @@ where
341
351
| Some ( Arch ( _) )
342
352
| Some ( PassThrough ( _) )
343
353
| 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
+ }
344
368
Some ( ExtraHashFile ( path) ) => {
345
369
extra_hash_files. push ( cwd. join ( path) ) ;
346
370
& mut common_args
@@ -376,6 +400,7 @@ where
376
400
let args = match arg. get_data ( ) {
377
401
Some ( SplitDwarf )
378
402
| Some ( ProfileGenerate )
403
+ | Some ( ProfileUse ( _) )
379
404
| Some ( TestCoverage )
380
405
| Some ( Coverage )
381
406
| Some ( DoCompilation )
@@ -742,7 +767,7 @@ mod test {
742
767
plusplus : bool ,
743
768
) -> CompilerArguments < ParsedArguments > {
744
769
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 )
746
771
}
747
772
748
773
#[ test]
@@ -1204,15 +1229,16 @@ mod test {
1204
1229
1205
1230
#[ test]
1206
1231
fn test_parse_arguments_pgo ( ) {
1232
+ let only_clang_supported = || Some ( "only Clang supported" . to_string ( ) ) ;
1207
1233
assert_eq ! (
1208
- CompilerArguments :: CannotCache ( "-fprofile-use" , None ) ,
1234
+ CompilerArguments :: CannotCache ( "-fprofile-use" , only_clang_supported ( ) ) ,
1209
1235
parse_arguments_(
1210
1236
stringvec![ "-c" , "foo.c" , "-fprofile-use" , "-o" , "foo.o" ] ,
1211
1237
false
1212
1238
)
1213
1239
) ;
1214
1240
assert_eq ! (
1215
- CompilerArguments :: CannotCache ( "-fprofile-use" , None ) ,
1241
+ CompilerArguments :: CannotCache ( "-fprofile-use" , only_clang_supported ( ) ) ,
1216
1242
parse_arguments_(
1217
1243
stringvec![ "-c" , "foo.c" , "-fprofile-use=file" , "-o" , "foo.o" ] ,
1218
1244
false
0 commit comments