[llvm] llvm-profdata: Resolve tilde for weighted input filenames (PR #146206)

Yi Kong via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 28 03:33:08 PDT 2025


https://github.com/kongy updated https://github.com/llvm/llvm-project/pull/146206

>From c7272cad4caf890e2d482b11faae8390a2baa3ac Mon Sep 17 00:00:00 2001
From: Yi Kong <yikong at google.com>
Date: Sat, 28 Jun 2025 15:24:41 +0900
Subject: [PATCH] [llvm-profdata] Resolve tilde in weighted input filenames

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.
---
 llvm/tools/llvm-profdata/llvm-profdata.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

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) {



More information about the llvm-commits mailing list