[clang] [Clang][InstrProf] Allow absolute path in fun.list of -fprofile-list= (PR #67519)

Henrik G. Olsson via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 20 05:53:55 PDT 2023


================
@@ -139,9 +139,23 @@ std::optional<ProfileList::ExclusionType>
 ProfileList::isFileExcluded(StringRef FileName,
                             CodeGenOptions::ProfileInstrKind Kind) const {
   StringRef Section = getSectionName(Kind);
-  // Check for "source:<regex>=<case>"
+
+  // Convert the input file path to its canonical (absolute) form
+  llvm::SmallString<128> CanonicalFileName(FileName);
+  llvm::sys::fs::make_absolute(CanonicalFileName);
----------------
hnrklssn wrote:

> IIRC you mean first check the relative file name and then use the relative filename to get the absolute file name and then finally check for the absolute filename.
> 
> Like this -
> 
> ```
> diff --git a/clang/lib/Basic/ProfileList.cpp b/clang/lib/Basic/ProfileList.cpp
> index 1853a3e34ec3..a561db4e7e49 100644
> --- a/clang/lib/Basic/ProfileList.cpp
> +++ b/clang/lib/Basic/ProfileList.cpp
> @@ -139,21 +139,21 @@ std::optional<ProfileList::ExclusionType>
>  ProfileList::isFileExcluded(StringRef FileName,
>                              CodeGenOptions::ProfileInstrKind Kind) const {
>    StringRef Section = getSectionName(Kind);
> -  // Convert the input file path to its canonical (absolute) form
> -  llvm::SmallString<128> CanonicalFileName(FileName);
> -  llvm::sys::fs::make_absolute(CanonicalFileName);
> -
>    // Check for "source:<regex>=<case>"
>    if (auto V = inSection(Section, "source", FileName))
>      return V;
> -  if (auto V = inSection(Section, "source", CanonicalFileName))
> -    return V;
>    if (SCL->inSection(Section, "!src", FileName))
>      return Forbid;
> -  if (SCL->inSection(Section, "!src", CanonicalFileName))
> -    return Forbid;
>    if (SCL->inSection(Section, "src", FileName))
>      return Allow;
> +
> +  // Convert the input file path to its canonical (absolute) form
> +  llvm::SmallString<128> CanonicalFileName(FileName);
> +  llvm::sys::fs::make_absolute(CanonicalFileName);
> +  if (auto V = inSection(Section, "source", CanonicalFileName))
> +    return V;
> +  if (SCL->inSection(Section, "!src", CanonicalFileName))
> +    return Forbid;
>    if (SCL->inSection(Section, "src", CanonicalFileName))
>      return Allow;
>    return std::nullopt;
> ```
> 
> For me both are fine, let me know if you think the same as I understand and want this version.

Yeah that's what I meant. I won't block on it though, because the performance aspect probably doesn't matter too much. But please do add tests.

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


More information about the cfe-commits mailing list