-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[NFC] Suppress spurious deprecation warning with MSVC #124764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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/pr-subscribers-llvm-ir Author: Jeremy Morse (jmorse) Changesgcc 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. Full diff: https://github.com/llvm/llvm-project/pull/124764.diff 2 Files Affected:
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))
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Is there a way to suppress this warning/error without changing getFirstNonPHI to be defined out-of-line? Also, it seems odd to me that doing so results in the MSVC diagnostic being suppressed, do you have a reference to the buildbot (if any) where these problems appeared? |
Not to my knowledge, but no man knoweth the ways of MSVC,
No buildbots that I'm aware of -- but I replicated it locally, and @RKSimon experienced it with MSVC too. The suppression comes from the fact that there are no longer any callers to the deprecated call, and part of that is because I copy+pasted the body of getFirstNonPHI rather than calling the const-version of it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see now - seems like a reasonable way to avoid this problem to me then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/13656 Here is the relevant piece of the build log for the reference
|
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.