[clang] [llvm] [clang] NFC: Deprecate `FileEntry::getName()` (PR #68157)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 4 11:58:07 PST 2023


https://github.com/jansvoboda11 updated https://github.com/llvm/llvm-project/pull/68157

>From e3a96bef47d029e1109dcad51840bab672c7351c Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Tue, 3 Oct 2023 13:40:07 -0700
Subject: [PATCH 1/2] [clang] NFC: Deprecate `FileEntry::getName()`

---
 clang/include/clang/Basic/FileEntry.h     | 1 +
 clang/unittests/Basic/FileManagerTest.cpp | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h
index bc65463735488..6351aeae92e2c 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -394,6 +394,7 @@ class FileEntry {
 
 public:
   ~FileEntry();
+  LLVM_DEPRECATED("Use FileEntryRef::getName() instead.", "")
   StringRef getName() const { return LastRef->getName(); }
 
   StringRef tryGetRealPathName() const { return RealPathName; }
diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp
index bf30fabb7cd88..d32036d975ce9 100644
--- a/clang/unittests/Basic/FileManagerTest.cpp
+++ b/clang/unittests/Basic/FileManagerTest.cpp
@@ -284,7 +284,6 @@ TEST_F(FileManagerTest, getFileRefReturnsCorrectNameForDifferentStatPath) {
   ASSERT_FALSE(!F1Alias);
   ASSERT_FALSE(!F1Alias2);
   EXPECT_EQ("dir/f1.cpp", F1->getName());
-  EXPECT_EQ("dir/f1.cpp", F1->getFileEntry().getName());
   EXPECT_EQ("dir/f1.cpp", F1Alias->getName());
   EXPECT_EQ("dir/f1.cpp", F1Alias2->getName());
   EXPECT_EQ(&F1->getFileEntry(), &F1Alias->getFileEntry());
@@ -303,7 +302,6 @@ TEST_F(FileManagerTest, getFileRefReturnsCorrectNameForDifferentStatPath) {
   ASSERT_FALSE(!F2Alias);
   ASSERT_FALSE(!F2Alias2);
   EXPECT_EQ("dir/f2.cpp", F2->getName());
-  EXPECT_EQ("dir/f2.cpp", F2->getFileEntry().getName());
   EXPECT_EQ("dir/f2.cpp", F2Alias->getName());
   EXPECT_EQ("dir/f2.cpp", F2Alias2->getName());
   EXPECT_EQ(&F2->getFileEntry(), &F2Alias->getFileEntry());

>From d5f953f9f8880dd32ae21aa8cf3d0b30479b271c Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Mon, 4 Dec 2023 11:55:07 -0800
Subject: [PATCH 2/2] [clang] Keep testing `getName()`, disable deprecation
 warnings

---
 clang/unittests/Basic/FileManagerTest.cpp |  6 ++++++
 llvm/include/llvm/Support/Compiler.h      | 19 +++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp
index d32036d975ce9..9de8b72bf5a78 100644
--- a/clang/unittests/Basic/FileManagerTest.cpp
+++ b/clang/unittests/Basic/FileManagerTest.cpp
@@ -284,6 +284,9 @@ TEST_F(FileManagerTest, getFileRefReturnsCorrectNameForDifferentStatPath) {
   ASSERT_FALSE(!F1Alias);
   ASSERT_FALSE(!F1Alias2);
   EXPECT_EQ("dir/f1.cpp", F1->getName());
+  LLVM_IGNORE_DEPRECATIONS_OF_DECLARATIONS_BEGIN
+  EXPECT_EQ("dir/f1.cpp", F1->getFileEntry().getName());
+  LLVM_IGNORE_DEPRECATIONS_OF_DECLARATIONS_END
   EXPECT_EQ("dir/f1.cpp", F1Alias->getName());
   EXPECT_EQ("dir/f1.cpp", F1Alias2->getName());
   EXPECT_EQ(&F1->getFileEntry(), &F1Alias->getFileEntry());
@@ -302,6 +305,9 @@ TEST_F(FileManagerTest, getFileRefReturnsCorrectNameForDifferentStatPath) {
   ASSERT_FALSE(!F2Alias);
   ASSERT_FALSE(!F2Alias2);
   EXPECT_EQ("dir/f2.cpp", F2->getName());
+  LLVM_IGNORE_DEPRECATIONS_OF_DECLARATIONS_BEGIN
+  EXPECT_EQ("dir/f2.cpp", F2->getFileEntry().getName());
+  LLVM_IGNORE_DEPRECATIONS_OF_DECLARATIONS_END
   EXPECT_EQ("dir/f2.cpp", F2Alias->getName());
   EXPECT_EQ("dir/f2.cpp", F2Alias2->getName());
   EXPECT_EQ(&F2->getFileEntry(), &F2Alias->getFileEntry());
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 6b13952bb2f41..26a46a279e7b2 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -157,6 +157,25 @@
 #define LLVM_DEPRECATED(MSG, FIX) [[deprecated(MSG)]]
 #endif
 
+// clang-format off
+#if defined(__clang__) || defined(__GNUC__)
+#define LLVM_IGNORE_DEPRECATIONS_OF_DECLARATIONS_BEGIN                         \
+  _Pragma("GCC diagnostic push")                                               \
+  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
+#define LLVM_IGNORE_DEPRECATIONS_OF_DECLARATIONS_END                           \
+  _Pragma("GCC diagnostic pop")
+#elif defined(_MSC_VER)
+#define LLVM_IGNORE_DEPRECATIONS_OF_DECLARATIONS_BEGIN                         \
+  _Pragma("warning(push)")                                                     \
+  _Pragma("warning(disable : 4996)")
+#define LLVM_IGNORE_DEPRECATIONS_OF_DECLARATIONS_END                           \
+  _Pragma("warning(pop)")
+#else
+#define LLVM_IGNORE_DEPRECATIONS_OF_DECLARATIONS_BEGIN
+#define LLVM_IGNORE_DEPRECATIONS_OF_DECLARATIONS_END
+#endif
+// clang-format on
+
 // Indicate that a non-static, non-const C++ member function reinitializes
 // the entire object to a known state, independent of the previous state of
 // the object.



More information about the cfe-commits mailing list