Skip to content

Commit 68d83fa

Browse files
authored
[llvm-profdata] Resolve tilde for weighted input filenames (#146206)
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.
1 parent 25d52fb commit 68d83fa

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llvm/tools/llvm-profdata/llvm-profdata.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,10 @@ static WeightedFile parseWeightedFile(const StringRef &WeightedFilename) {
17051705
if (WeightStr.getAsInteger(10, Weight) || Weight < 1)
17061706
exitWithError("input weight must be a positive integer");
17071707

1708-
return {std::string(FileName), Weight};
1708+
llvm::SmallString<128> ResolvedFileName;
1709+
llvm::sys::fs::expand_tilde(FileName, ResolvedFileName);
1710+
1711+
return {std::string(ResolvedFileName), Weight};
17091712
}
17101713

17111714
static void addWeightedInput(WeightedFileVector &WNI, const WeightedFile &WF) {

0 commit comments

Comments
 (0)