[clang] [llvm] remove redundant uses of `isa` caught by clang-tidy (NFC) (PR #192813)
Henrik G. Olsson via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 18 15:44:06 PDT 2026
https://github.com/hnrklssn created https://github.com/llvm/llvm-project/pull/192813
These calls to `isa` are always true. Also includes a drive-by cleanup of a use of `isa_and_nonnull` where the value was already null-checked.
Caught by applying https://github.com/llvm/llvm-project/pull/191081
>From a4c647f89412b8bf8a315aa2a96977df34dbf922 Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" <h_olsson at apple.com>
Date: Sat, 18 Apr 2026 14:41:52 -0700
Subject: [PATCH] remove redundant uses of `isa` caught by clang-tidy (NFC)
These calls to `isa` are always true. Also includes a drive-by cleanup
of a use of `isa_and_nonnull` where the value was already null-checked.
Caught by applying https://github.com/llvm/llvm-project/pull/191081
---
clang/lib/Interpreter/Interpreter.cpp | 2 +-
.../Checkers/DynamicTypePropagation.cpp | 9 ++-
.../Checkers/WebKit/ForwardDeclChecker.cpp | 11 +--
.../Checkers/WebKit/PtrTypesSemantics.cpp | 68 +++++++++----------
llvm/lib/IR/IntrinsicInst.cpp | 6 +-
.../lib/Transforms/Scalar/LoopInterchange.cpp | 2 -
6 files changed, 42 insertions(+), 56 deletions(-)
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 2684a00ce5f07..e1128d1904c11 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -66,7 +66,7 @@ GetCC1Arguments(DiagnosticsEngine *Diagnostics,
// We expect to get back exactly one Command job, if we didn't something
// failed. Extract that job from the Compilation.
const driver::JobList &Jobs = Compilation->getJobs();
- if (!Jobs.size() || !isa<driver::Command>(*Jobs.begin()))
+ if (!Jobs.size())
return llvm::createStringError(llvm::errc::not_supported,
"Driver initialization failed. "
"Unable to create a driver job");
diff --git a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
index cee744aecb686..45176a7911a67 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
@@ -718,11 +718,10 @@ static bool isObjCTypeParamDependent(QualType Type) {
public:
IsObjCTypeParamDependentTypeVisitor() = default;
bool VisitObjCTypeParamType(ObjCTypeParamType *Type) override {
- if (isa<ObjCTypeParamDecl>(Type->getDecl())) {
- Result = true;
- return false;
- }
- return true;
+ static_assert(
+ std::is_same_v<decltype(Type->getDecl()), ObjCTypeParamDecl *>);
+ Result = true;
+ return false;
}
bool Result = false;
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
index f207323dd1222..8cdea79956fc0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
@@ -212,8 +212,7 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
if (auto *F = CE->getDirectCallee()) {
// Skip the first argument for overloaded member operators (e. g. lambda
// or std::function call operator).
- unsigned ArgIdx =
- isa<CXXOperatorCallExpr>(CE) && isa_and_nonnull<CXXMethodDecl>(F);
+ unsigned ArgIdx = isa<CXXOperatorCallExpr>(CE) && isa<CXXMethodDecl>(F);
for (auto P = F->param_begin();
P < F->param_end() && ArgIdx < CE->getNumArgs(); ++P, ++ArgIdx)
@@ -227,12 +226,8 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
if (BR->getSourceManager().isInSystemHeader(CE->getExprLoc()))
return;
- if (auto *F = CE->getConstructor()) {
- // Skip the first argument for overloaded member operators (e. g. lambda
- // or std::function call operator).
- unsigned ArgIdx =
- isa<CXXOperatorCallExpr>(CE) && isa_and_nonnull<CXXMethodDecl>(F);
-
+ if (const CXXMethodDecl *F = CE->getConstructor()) {
+ unsigned ArgIdx = 0;
for (auto P = F->param_begin();
P < F->param_end() && ArgIdx < CE->getNumArgs(); ++P, ++ArgIdx)
visitCallArg(CE->getArg(ArgIdx), *P, DeclWithIssue);
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index d239ed4c8a5ae..25d909a1df701 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -325,49 +325,47 @@ std::optional<bool> isUncheckedPtr(const QualType T) {
std::optional<bool> isGetterOfSafePtr(const CXXMethodDecl *M) {
assert(M);
- if (isa<CXXMethodDecl>(M)) {
- const CXXRecordDecl *calleeMethodsClass = M->getParent();
- auto className = safeGetName(calleeMethodsClass);
- auto method = safeGetName(M);
+ const CXXRecordDecl *calleeMethodsClass = M->getParent();
+ auto className = safeGetName(calleeMethodsClass);
+ auto method = safeGetName(M);
- if (isCheckedPtr(className) && (method == "get" || method == "ptr"))
- return true;
+ if (isCheckedPtr(className) && (method == "get" || method == "ptr"))
+ return true;
- if ((isRefType(className) && (method == "get" || method == "ptr")) ||
- ((className == "String" || className == "AtomString" ||
- className == "AtomStringImpl" || className == "UniqueString" ||
- className == "UniqueStringImpl" || className == "Identifier") &&
- method == "impl"))
- return true;
+ if ((isRefType(className) && (method == "get" || method == "ptr")) ||
+ ((className == "String" || className == "AtomString" ||
+ className == "AtomStringImpl" || className == "UniqueString" ||
+ className == "UniqueStringImpl" || className == "Identifier") &&
+ method == "impl"))
+ return true;
- if (isRetainPtrOrOSPtr(className) && method == "get")
- return true;
+ if (isRetainPtrOrOSPtr(className) && method == "get")
+ return true;
- // Ref<T> -> T conversion
- // FIXME: Currently allowing any Ref<T> -> whatever cast.
- if (isRefType(className)) {
- if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
- auto QT = maybeRefToRawOperator->getConversionType();
- auto *T = QT.getTypePtrOrNull();
- return T && (T->isPointerType() || T->isReferenceType());
- }
+ // Ref<T> -> T conversion
+ // FIXME: Currently allowing any Ref<T> -> whatever cast.
+ if (isRefType(className)) {
+ if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
+ auto QT = maybeRefToRawOperator->getConversionType();
+ auto *T = QT.getTypePtrOrNull();
+ return T && (T->isPointerType() || T->isReferenceType());
}
+ }
- if (isCheckedPtr(className)) {
- if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
- auto QT = maybeRefToRawOperator->getConversionType();
- auto *T = QT.getTypePtrOrNull();
- return T && (T->isPointerType() || T->isReferenceType());
- }
+ if (isCheckedPtr(className)) {
+ if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
+ auto QT = maybeRefToRawOperator->getConversionType();
+ auto *T = QT.getTypePtrOrNull();
+ return T && (T->isPointerType() || T->isReferenceType());
}
+ }
- if (isRetainPtrOrOSPtr(className)) {
- if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
- auto QT = maybeRefToRawOperator->getConversionType();
- auto *T = QT.getTypePtrOrNull();
- return T && (T->isPointerType() || T->isReferenceType() ||
- T->isObjCObjectPointerType());
- }
+ if (isRetainPtrOrOSPtr(className)) {
+ if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
+ auto QT = maybeRefToRawOperator->getConversionType();
+ auto *T = QT.getTypePtrOrNull();
+ return T && (T->isPointerType() || T->isReferenceType() ||
+ T->isObjCObjectPointerType());
}
}
return false;
diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp
index 5b3e3cf45397f..3e9f3257956a1 100644
--- a/llvm/lib/IR/IntrinsicInst.cpp
+++ b/llvm/lib/IR/IntrinsicInst.cpp
@@ -263,11 +263,7 @@ Value *InstrProfIncrementInst::getStep() const {
return ConstantInt::get(Type::getInt64Ty(Context), 1);
}
-Value *InstrProfCallsite::getCallee() const {
- if (isa<InstrProfCallsite>(this))
- return getArgOperand(4);
- return nullptr;
-}
+Value *InstrProfCallsite::getCallee() const { return getArgOperand(4); }
void InstrProfCallsite::setCallee(Value *Callee) {
assert(isa<InstrProfCallsite>(this));
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index 49a9e77ef8deb..75dfad5c99067 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -181,8 +181,6 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
for (BasicBlock *BB : L->blocks()) {
// Scan the BB and collect legal loads and stores.
for (Instruction &I : *BB) {
- if (!isa<Instruction>(I))
- return false;
if (auto *Ld = dyn_cast<LoadInst>(&I)) {
if (!Ld->isSimple())
return false;
More information about the cfe-commits
mailing list