[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:24:24 PST 2025
https://github.com/jmorse updated https://github.com/llvm/llvm-project/pull/124764
>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 1/2] [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))
>From f5a7c3631f553acbbc97e2816dfd0ccaf053aa4c Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Tue, 28 Jan 2025 15:24:04 +0000
Subject: [PATCH 2/2] clang-format
---
llvm/lib/IR/BasicBlock.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index d3d382fe500e9f..dca42a57fa9e32 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -371,7 +371,7 @@ const Instruction* BasicBlock::getFirstNonPHI() const {
return nullptr;
}
-Instruction* BasicBlock::getFirstNonPHI() {
+Instruction *BasicBlock::getFirstNonPHI() {
for (Instruction &I : *this)
if (!isa<PHINode>(I))
return &I;
More information about the llvm-commits
mailing list