Skip to content

[llvm-profdata] Resolve tilde for weighted input filenames #146206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kongy
Copy link
Collaborator

@kongy kongy commented Jun 28, 2025

Since the weighted input argument is in the format of "<weight>,<filename>", shell does not automatically expand the tilde in the file name.

@llvmbot llvmbot added the PGO Profile Guided Optimizations label Jun 28, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 28, 2025

@llvm/pr-subscribers-pgo

Author: Yi Kong (kongy)

Changes

Since the weighted input argument is in the format of <weight>,<filename>, shell does not automatically expand the tilde in the file name.


Full diff: https://github.com/llvm/llvm-project/pull/146206.diff

1 Files Affected:

  • (modified) llvm/tools/llvm-profdata/llvm-profdata.cpp (+4-1)
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index a7cbd4bfc8387..45eac90aef935 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -1705,7 +1705,10 @@ static WeightedFile parseWeightedFile(const StringRef &WeightedFilename) {
   if (WeightStr.getAsInteger(10, Weight) || Weight < 1)
     exitWithError("input weight must be a positive integer");
 
-  return {std::string(FileName), Weight};
+  llvm::SmallString<128> ResolvedFileName;
+  llvm::sys::fs::expand_tilde(FileName, ResolvedFileName);
+
+  return {std::string(ResolvedFileName), Weight};
 }
 
 static void addWeightedInput(WeightedFileVector &WNI, const WeightedFile &WF) {

When specifying a weighted input file, the shell does not automatically
expand the tilde (`~`) character in the filename because the argument
is passed as a single string in the format `<weight>,<filename>`.

This commit fixes the issue by using `llvm::sys::fs::expand_tilde` to
explicitly resolve the tilde in the filename, ensuring that paths
like `~/path/to/file` are correctly handled.
@kongy kongy force-pushed the profdata-weighted-input-tilde branch from 26c7f3d to c7272ca Compare June 28, 2025 10:33
@kongy kongy changed the title llvm-profdata: Resolve tilde for weighted input filenames [llvm-profdata] Resolve tilde for weighted input filenames Jun 28, 2025
Copy link
Contributor

@kazutakahirata kazutakahirata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants