@@ -594,6 +594,8 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
594594 << PGOGenerateArg->getSpelling () << ProfileGenerateArg->getSpelling ();
595595
596596 auto *ProfileUseArg = getLastProfileUseArg (Args);
597+ auto *ProfileSampleUseArg = Args.getLastArg (
598+ options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ);
597599
598600 if (PGOGenerateArg && ProfileUseArg)
599601 D.Diag (diag::err_drv_argument_not_allowed_with)
@@ -677,6 +679,25 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
677679 }
678680 }
679681
682+ if (ProfileSampleUseArg) {
683+ if ((ProfileSampleUseArg->getOption ().matches (
684+ options::OPT_fprofile_sample_use) ||
685+ ProfileSampleUseArg->getOption ().matches (
686+ options::OPT_fprofile_sample_use_EQ))) {
687+ SmallString<128 > Path (ProfileSampleUseArg->getNumValues () == 0
688+ ? " "
689+ : ProfileSampleUseArg->getValue ());
690+ if (Path.empty () || llvm::sys::fs::is_directory (Path))
691+ llvm::sys::path::append (Path, " default.profdata" );
692+
693+ if (!llvm::sys::fs::exists (Path))
694+ D.Diag (diag::err_drv_no_such_file) << Path;
695+
696+ CmdArgs.push_back (
697+ Args.MakeArgString (Twine (" -fprofile-sample-use=" ) + Path));
698+ }
699+ }
700+
680701 bool EmitCovNotes = Args.hasFlag (options::OPT_ftest_coverage,
681702 options::OPT_fno_test_coverage, false ) ||
682703 Args.hasArg (options::OPT_coverage);
0 commit comments