[llvm] [NFC] Suppress spurious deprecation warning with MSVC (PR #124764)

Jeremy Morse via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 28 07:18:23 PST 2025


https://github.com/jmorse created https://github.com/llvm/llvm-project/pull/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.

>From d321c21bd2c80048d03be845fae93e3d9117bbd2 Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Tue, 28 Jan 2025 15:15:34 +0000
Subject: [PATCH] [NFC] Suppress spurious deprecation warning with MSVC

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.
---
 llvm/include/llvm/IR/BasicBlock.h | 5 +----
 llvm/lib/IR/BasicBlock.cpp        | 7 +++++++
 2 files changed, 8 insertions(+), 4 deletions(-)

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..d3d382fe500e9f 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