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

Shivam Gupta via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 8 22:01:58 PST 2023


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

>From 400c889a4f0e867e3e2ceee43ae5c91f62f63c4d Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivam98.tkg at gmail.com>
Date: Thu, 19 Oct 2023 18:20:05 +0530
Subject: [PATCH 1/2] [Clang][InstrProf] Allow absolute path in fun.list of
 -fprofile-list=

---
 clang/lib/Basic/ProfileList.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/clang/lib/Basic/ProfileList.cpp b/clang/lib/Basic/ProfileList.cpp
index 8fa16e2eb069a52..1853a3e34ec35ed 100644
--- a/clang/lib/Basic/ProfileList.cpp
+++ b/clang/lib/Basic/ProfileList.cpp
@@ -139,12 +139,22 @@ 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;
+  if (SCL->inSection(Section, "src", CanonicalFileName))
+    return Allow;
   return std::nullopt;
 }

>From 42416cdec2e9675fc3d2dfafffcd3b7cf858cc4f Mon Sep 17 00:00:00 2001
From: Shivam Gupta <Shivam.Gupta2 at amd.com>
Date: Thu, 9 Nov 2023 11:27:40 +0530
Subject: [PATCH 2/2] add testing

---
 clang/lib/Basic/ProfileList.cpp     | 15 +++++++--------
 clang/test/CodeGen/profile-filter.c |  3 ++-
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Basic/ProfileList.cpp b/clang/lib/Basic/ProfileList.cpp
index 1853a3e34ec35ed..3dc01096a69e2ef 100644
--- a/clang/lib/Basic/ProfileList.cpp
+++ b/clang/lib/Basic/ProfileList.cpp
@@ -139,21 +139,20 @@ 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;
diff --git a/clang/test/CodeGen/profile-filter.c b/clang/test/CodeGen/profile-filter.c
index e33e4a0a60b3d4f..2db9d5059e4ccea 100644
--- a/clang/test/CodeGen/profile-filter.c
+++ b/clang/test/CodeGen/profile-filter.c
@@ -4,7 +4,8 @@
 // RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -fprofile-list=%t-func.list -emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
 
 // RUN: echo "src:%s" | sed -e 's/\\/\\\\/g' > %t-file.list
-// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -fprofile-list=%t-file.list -emit-llvm %s -o - | FileCheck %s --check-prefix=FILE
+// RUN: cd %S
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -fprofile-list=%t-file.list -emit-llvm profile-filter.c -o - | FileCheck %s --check-prefix=FILE
 
 // RUN: echo -e "[clang]\nfun:test1\n[llvm]\nfun:test2" > %t-section.list
 // RUN: %clang_cc1 -fprofile-instrument=llvm -fprofile-list=%t-section.list -emit-llvm %s -o - | FileCheck %s --check-prefix=SECTION



More information about the cfe-commits mailing list