[clang] [clang] Move `-fprofile-instrument-use-path=` check to driver (PR #159667)

Ben Langmuir via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 26 11:20:22 PDT 2025


================
@@ -485,20 +486,48 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
   }
 
   if (ProfileUseArg) {
+    SmallString<128> Path;
+    StringRef UsePath;
     if (ProfileUseArg->getOption().matches(options::OPT_fprofile_instr_use_EQ))
-      CmdArgs.push_back(Args.MakeArgString(
-          Twine("-fprofile-instrument-use-path=") + ProfileUseArg->getValue()));
+      UsePath = ProfileUseArg->getValue();
     else if ((ProfileUseArg->getOption().matches(
                   options::OPT_fprofile_use_EQ) ||
               ProfileUseArg->getOption().matches(
                   options::OPT_fprofile_instr_use))) {
-      SmallString<128> Path(
-          ProfileUseArg->getNumValues() == 0 ? "" : ProfileUseArg->getValue());
+      Path =
+          ProfileUseArg->getNumValues() == 0 ? "" : ProfileUseArg->getValue();
       if (Path.empty() || llvm::sys::fs::is_directory(Path))
         llvm::sys::path::append(Path, "default.profdata");
-      CmdArgs.push_back(
-          Args.MakeArgString(Twine("-fprofile-instrument-use-path=") + Path));
+      UsePath = Path;
+    }
+    StringRef UseKind;
+    auto ReaderOrErr =
+        llvm::IndexedInstrProfReader::create(UsePath, D.getVFS());
+    if (auto E = ReaderOrErr.takeError()) {
+      auto DiagID = D.getDiags().getCustomDiagID(
+          DiagnosticsEngine::Error, "Error in reading profile %0: %1");
----------------
benlangmuir wrote:

Ah sorry, I missed that this was existing code.  I do think it should probably be a real diagnostic, but no need to change it here.  I tried to see if there was a justification when it was added, but didn't find any reason it wouldn't be a normal diagnostic. Funnily this diagnostic code moved half a dozen times back and forth between CodeGenModule.cpp and CodeGenPGO.cpp.

https://github.com/llvm/llvm-project/pull/159667


More information about the cfe-commits mailing list