Author: Henrik G. Olsson Date: 2026-05-20T23:54:06-07:00 New Revision: ac09b41daec4df16e26011abb021c17844db66c7
URL: https://github.com/llvm/llvm-project/commit/ac09b41daec4df16e26011abb021c17844db66c7 DIFF: https://github.com/llvm/llvm-project/commit/ac09b41daec4df16e26011abb021c17844db66c7.diff LOG: remove redundant uses of `isa` caught by clang-tidy (NFC) (#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 Added: Modified: clang/lib/Interpreter/Interpreter.cpp clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp llvm/lib/IR/IntrinsicInst.cpp llvm/lib/Transforms/Scalar/LoopInterchange.cpp Removed: ################################################################################ diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 2684a00ce5f07..7586c26235449 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -66,13 +66,13 @@ 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"); // The one job we find should be to invoke clang again. - const driver::Command *Cmd = cast<driver::Command>(&(*Jobs.begin())); + const driver::Command *Cmd = &*Jobs.begin(); if (llvm::StringRef(Cmd->getCreator().getName()) != "clang") return llvm::createStringError(llvm::errc::not_supported, "Driver initialization failed"); 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 6be6a66f87741..ab431af8ff391 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp @@ -337,49 +337,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(); + std::string className = safeGetName(calleeMethodsClass); + std::string 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)) { + QualType QT = maybeRefToRawOperator->getConversionType(); + const Type *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)) { + QualType QT = maybeRefToRawOperator->getConversionType(); + const Type *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)) { + QualType QT = maybeRefToRawOperator->getConversionType(); + const Type *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 1939a8217eb80..51f4b88e2170a 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; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
