[llvm] 48df948 - [NFC] Suppress spurious deprecation warning with MSVC (#124764)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 28 07:55:48 PST 2025


Author: Jeremy Morse
Date: 2025-01-28T15:55:45Z
New Revision: 48df9480dab57f99aa466ade1df6c46e71da25b5

URL: https://github.com/llvm/llvm-project/commit/48df9480dab57f99aa466ade1df6c46e71da25b5
DIFF: https://github.com/llvm/llvm-project/commit/48df9480dab57f99aa466ade1df6c46e71da25b5.diff

LOG: [NFC] Suppress spurious deprecation warning with MSVC (#124764)

gcc and clang won't complain about calls to deprecated functions, if
you're calling from a function that is deprecated too. However, MSVC
does care, and expands into maaany deprecation warnings for
getFirstNonPHI.

Suppress this by converting the inlineable copy of getFirstNonPHI into a
non-inline copy.

Added: 
    

Modified: 
    llvm/include/llvm/IR/BasicBlock.h
    llvm/lib/IR/BasicBlock.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/BasicBlock.h b/llvm/include/llvm/IR/BasicBlock.h
index 2ee17ce8f483ea..c9169cb6018096 100644
--- a/llvm/include/llvm/IR/BasicBlock.h
+++ b/llvm/include/llvm/IR/BasicBlock.h
@@ -287,10 +287,7 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
   const Instruction *getFirstNonPHI() const;
   LLVM_DEPRECATED("Use iterators as instruction positions instead",
                   "getFirstNonPHIIt")
-  Instruction *getFirstNonPHI() {
-    return const_cast<Instruction *>(
-        static_cast<const BasicBlock *>(this)->getFirstNonPHI());
-  }
+  Instruction *getFirstNonPHI();
 
   /// Returns an iterator to the first instruction in this block that is not a
   /// PHINode instruction.

diff  --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 8eaa6e522f826a..dca42a57fa9e32 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -371,6 +371,13 @@ const Instruction* BasicBlock::getFirstNonPHI() const {
   return nullptr;
 }
 
+Instruction *BasicBlock::getFirstNonPHI() {
+  for (Instruction &I : *this)
+    if (!isa<PHINode>(I))
+      return &I;
+  return nullptr;
+}
+
 BasicBlock::const_iterator BasicBlock::getFirstNonPHIIt() const {
   for (const Instruction &I : *this) {
     if (isa<PHINode>(I))


        


More information about the llvm-commits mailing list