From d0ac215dd5496a44ce8a6660378ea40a6e1c148d Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 14 Nov 2021 09:32:40 -0800 Subject: [PATCH] [clang] Use isa instead of dyn_cast (NFC) --- clang/include/clang/AST/LambdaCapture.h | 2 +- clang/include/clang/Sema/Initialization.h | 2 +- clang/lib/AST/QualTypeNames.cpp | 2 +- clang/lib/AST/Type.cpp | 2 +- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 2 +- clang/lib/CodeGen/CGStmtOpenMP.cpp | 2 +- clang/lib/CodeGen/CodeGenFunction.h | 2 +- clang/lib/CodeGen/CodeGenModule.cpp | 4 ++-- clang/lib/CodeGen/CoverageMappingGen.cpp | 2 +- clang/lib/Sema/SemaChecking.cpp | 8 ++++---- clang/lib/Sema/SemaDecl.cpp | 4 ++-- clang/lib/Sema/SemaDeclObjC.cpp | 2 +- clang/lib/Sema/SemaExpr.cpp | 2 +- clang/lib/Sema/SemaOverload.cpp | 6 +++--- clang/lib/Sema/SemaTemplate.cpp | 2 +- clang/lib/Sema/SemaType.cpp | 2 +- .../StaticAnalyzer/Checkers/DynamicTypePropagation.cpp | 2 +- .../Checkers/RetainCountChecker/RetainCountChecker.cpp | 2 +- .../Checkers/WebKit/UncountedCallArgsChecker.cpp | 3 +-- clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | 2 +- clang/tools/libclang/CXCursor.cpp | 2 +- 21 files changed, 28 insertions(+), 29 deletions(-) diff --git a/clang/include/clang/AST/LambdaCapture.h b/clang/include/clang/AST/LambdaCapture.h index 8e2806545dd6..7ad1e2361e42 100644 --- a/clang/include/clang/AST/LambdaCapture.h +++ b/clang/include/clang/AST/LambdaCapture.h @@ -86,7 +86,7 @@ public: /// Determine whether this capture handles a variable. bool capturesVariable() const { - return dyn_cast_or_null(DeclAndBits.getPointer()); + return isa_and_nonnull(DeclAndBits.getPointer()); } /// Determine whether this captures a variable length array bound diff --git a/clang/include/clang/Sema/Initialization.h b/clang/include/clang/Sema/Initialization.h index 8c1856f20827..679e12ee22d4 100644 --- a/clang/include/clang/Sema/Initialization.h +++ b/clang/include/clang/Sema/Initialization.h @@ -488,7 +488,7 @@ public: /// Determine whether this is an array new with an unknown bound. bool isVariableLengthArrayNew() const { - return getKind() == EK_New && dyn_cast_or_null( + return getKind() == EK_New && isa_and_nonnull( getType()->getAsArrayTypeUnsafe()); } diff --git a/clang/lib/AST/QualTypeNames.cpp b/clang/lib/AST/QualTypeNames.cpp index 9a1b418f5ac1..673821078345 100644 --- a/clang/lib/AST/QualTypeNames.cpp +++ b/clang/lib/AST/QualTypeNames.cpp @@ -296,7 +296,7 @@ static NestedNameSpecifier *createNestedNameSpecifierForScopeOf( } else if (const auto *TD = dyn_cast(Outer)) { return createNestedNameSpecifier( Ctx, TD, FullyQualified, WithGlobalNsPrefix); - } else if (dyn_cast(Outer)) { + } else if (isa(Outer)) { // Context is the TU. Nothing needs to be done. return nullptr; } else { diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index 4adf367f2da6..e0ac3f5b1351 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -1892,7 +1892,7 @@ DeducedType *Type::getContainedDeducedType() const { } bool Type::hasAutoForTrailingReturnType() const { - return dyn_cast_or_null( + return isa_and_nonnull( GetContainedDeducedTypeVisitor(true).Visit(this)); } diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 9f4e0f12e023..8606e80418d7 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -3913,7 +3913,7 @@ static void emitPrivatesInit(CodeGenFunction &CGF, SharedRefLValue.getTBAAInfo()); } else if (CGF.LambdaCaptureFields.count( Pair.second.Original->getCanonicalDecl()) > 0 || - dyn_cast_or_null(CGF.CurCodeDecl)) { + isa_and_nonnull(CGF.CurCodeDecl)) { SharedRefLValue = CGF.EmitLValue(Pair.second.OriginalRef); } else { // Processing for implicitly captured variables. diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index 2cf01939d9b6..3ca50503c62c 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -4720,7 +4720,7 @@ void CodeGenFunction::EmitOMPTargetTaskBasedDirective( [&InputInfo]() { return InputInfo.SizesArray; }); // If there is no user-defined mapper, the mapper array will be nullptr. In // this case, we don't need to privatize it. - if (!dyn_cast_or_null( + if (!isa_and_nonnull( InputInfo.MappersArray.getPointer())) { MVD = createImplicitFirstprivateForType( getContext(), Data, BaseAndPointerAndMapperType, CD, S.getBeginLoc()); diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index d5ac17ca4f19..ff5b6634da1c 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -499,7 +499,7 @@ public: AbstractCallee(const FunctionDecl *FD) : CalleeDecl(FD) {} AbstractCallee(const ObjCMethodDecl *OMD) : CalleeDecl(OMD) {} bool hasFunctionDecl() const { - return dyn_cast_or_null(CalleeDecl); + return isa_and_nonnull(CalleeDecl); } const Decl *getDecl() const { return CalleeDecl; } unsigned getNumParams() const { diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index c28c2e2e85d8..1f094ed72724 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1953,7 +1953,7 @@ void CodeGenModule::setLLVMFunctionFEnvAttributes(const FunctionDecl *D, void CodeGenModule::SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV) { const Decl *D = GD.getDecl(); - if (dyn_cast_or_null(D)) + if (isa_and_nonnull(D)) setGVProperties(GV, GD); else GV->setVisibility(llvm::GlobalValue::DefaultVisibility); @@ -4807,7 +4807,7 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old, callSite->getOperandBundlesAsDefs(newBundles); llvm::CallBase *newCall; - if (dyn_cast(callSite)) { + if (isa(callSite)) { newCall = llvm::CallInst::Create(newFn, newArgs, newBundles, "", callSite); } else { diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index 2d11495b4ff0..9b81c8a670f5 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -969,7 +969,7 @@ struct CounterCoverageMappingBuilder // If last statement contains terminate statements, add a gap area // between the two statements. Skipping attributed statements, because // they don't have valid start location. - if (LastStmt && HasTerminateStmt && !dyn_cast(Child)) { + if (LastStmt && HasTerminateStmt && !isa(Child)) { auto Gap = findGapAreaBetween(getEnd(LastStmt), getStart(Child)); if (Gap) fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index e7b2a118bdaf..6b38877bee11 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -2741,8 +2741,8 @@ static bool isValidBPFPreserveFieldInfoArg(Expr *Arg) { // to BPF backend to check whether the access is a // field access or not. return (Arg->IgnoreParens()->getObjectKind() == OK_BitField || - dyn_cast(Arg->IgnoreParens()) || - dyn_cast(Arg->IgnoreParens())); + isa(Arg->IgnoreParens()) || + isa(Arg->IgnoreParens())); } static bool isEltOfVectorTy(ASTContext &Context, CallExpr *Call, Sema &S, @@ -2766,8 +2766,8 @@ static bool isValidBPFPreserveTypeInfoArg(Expr *Arg) { // 1. __builtin_preserve_type_info(*( *)0, flag); // 2. var; // __builtin_preserve_type_info(var, flag); - if (!dyn_cast(Arg->IgnoreParens()) && - !dyn_cast(Arg->IgnoreParens())) + if (!isa(Arg->IgnoreParens()) && + !isa(Arg->IgnoreParens())) return false; // Typedef type. diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 5d15fd2aec58..4fcc01012d44 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5781,8 +5781,8 @@ bool Sema::diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, NestedNameSpecifierLoc SpecLoc(SS.getScopeRep(), SS.location_data()); while (SpecLoc.getPrefix()) SpecLoc = SpecLoc.getPrefix(); - if (dyn_cast_or_null( - SpecLoc.getNestedNameSpecifier()->getAsType())) + if (isa_and_nonnull( + SpecLoc.getNestedNameSpecifier()->getAsType())) Diag(Loc, diag::err_decltype_in_declarator) << SpecLoc.getTypeLoc().getSourceRange(); diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index f8cf8a3d5dc8..d6e659e17069 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -611,7 +611,7 @@ ActOnSuperClassOfClassInterface(Scope *S, } } - if (!dyn_cast_or_null(PrevDecl)) { + if (!isa_and_nonnull(PrevDecl)) { if (!SuperClassDecl) Diag(SuperLoc, diag::err_undef_superclass) << SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc); diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 24187367f3d0..3297c01047ad 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5709,7 +5709,7 @@ Sema::VariadicCallType Sema::getVariadicCallType(FunctionDecl *FDecl, const FunctionProtoType *Proto, Expr *Fn) { if (Proto && Proto->isVariadic()) { - if (dyn_cast_or_null(FDecl)) + if (isa_and_nonnull(FDecl)) return VariadicConstructor; else if (Fn && Fn->getType()->isBlockPointerType()) return VariadicBlock; diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index a2af2ac6f7ee..cce5d901ba90 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -9860,9 +9860,9 @@ bool clang::isBetterOverloadCandidate( // F1 and F2 have the same type. // FIXME: Implement the "all parameters have the same type" check. bool Cand1IsInherited = - dyn_cast_or_null(Cand1.FoundDecl.getDecl()); + isa_and_nonnull(Cand1.FoundDecl.getDecl()); bool Cand2IsInherited = - dyn_cast_or_null(Cand2.FoundDecl.getDecl()); + isa_and_nonnull(Cand2.FoundDecl.getDecl()); if (Cand1IsInherited != Cand2IsInherited) return Cand2IsInherited; else if (Cand1IsInherited) { @@ -12673,7 +12673,7 @@ static void AddOverloadedCallCandidate(Sema &S, return; } // Prevent ill-formed function decls to be added as overload candidates. - if (!dyn_cast(Func->getType()->getAs())) + if (!isa(Func->getType()->getAs())) return; S.AddOverloadCandidate(Func, FoundDecl, Args, CandidateSet, diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 46b5fbe7a350..f4fd2ea5aa8e 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -743,7 +743,7 @@ Sema::ActOnDependentIdExpression(const CXXScopeSpec &SS, // Check if the nested name specifier is an enum type. bool IsEnum = false; if (NestedNameSpecifier *NNS = SS.getScopeRep()) - IsEnum = dyn_cast_or_null(NNS->getAsType()); + IsEnum = isa_and_nonnull(NNS->getAsType()); if (!MightBeCxx11UnevalField && !isAddressOfOperand && !IsEnum && isa(DC) && cast(DC)->isInstance()) { diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index f99b032427e8..d2ee669debd0 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -5428,7 +5428,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, // Avoid emitting extra errors if we already errored on the scope. D.setInvalidType(true); } else if (S.isDependentScopeSpecifier(SS) || - dyn_cast_or_null(S.computeDeclContext(SS))) { + isa_and_nonnull(S.computeDeclContext(SS))) { NestedNameSpecifier *NNS = SS.getScopeRep(); NestedNameSpecifier *NNSPrefix = NNS->getPrefix(); switch (NNS->getKind()) { diff --git a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp index 14ba5d769969..b07f59125a82 100644 --- a/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp @@ -384,7 +384,7 @@ void DynamicTypePropagation::checkPostCall(const CallEvent &Call, // FIXME: Instead of relying on the ParentMap, we should have the // trigger-statement (InitListExpr in this case) available in this // callback, ideally as part of CallEvent. - if (dyn_cast_or_null( + if (isa_and_nonnull( LCtx->getParentMap().getParent(Ctor->getOriginExpr()))) return; diff --git a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp index b256117fd78d..0bde088d0e85 100644 --- a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp @@ -290,7 +290,7 @@ void RetainCountChecker::checkPostStmt(const ObjCIvarRefExpr *IRE, ProgramStateRef State = C.getState(); SymbolRef Sym = State->getSVal(*IVarLoc).getAsSymbol(); - if (!Sym || !dyn_cast_or_null(Sym->getOriginRegion())) + if (!Sym || !isa_and_nonnull(Sym->getOriginRegion())) return; // Accessing an ivar directly is unusual. If we've done that, be more diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp index d70bd9489d2c..e6d0948f71bb 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp @@ -68,8 +68,7 @@ public: if (auto *F = CE->getDirectCallee()) { // Skip the first argument for overloaded member operators (e. g. lambda // or std::function call operator). - unsigned ArgIdx = - isa(CE) && dyn_cast_or_null(F); + unsigned ArgIdx = isa(CE) && isa_and_nonnull(F); for (auto P = F->param_begin(); // FIXME: Also check variadic function parameters. diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp index cab65687444b..ba105f34a915 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp @@ -531,7 +531,7 @@ void ExprEngine::handleConstructor(const Expr *E, // FIXME: Instead of relying on the ParentMap, we should have the // trigger-statement (InitListExpr in this case) passed down from CFG or // otherwise always available during construction. - if (dyn_cast_or_null(LCtx->getParentMap().getParent(E))) { + if (isa_and_nonnull(LCtx->getParentMap().getParent(E))) { MemRegionManager &MRMgr = getSValBuilder().getRegionManager(); Target = loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(E, LCtx)); CallOpts.IsCtorOrDtorWithImproperlyModeledTargetRegion = true; diff --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp index 590797474b00..db02e0c71ceb 100644 --- a/clang/tools/libclang/CXCursor.cpp +++ b/clang/tools/libclang/CXCursor.cpp @@ -1711,7 +1711,7 @@ CXType clang_Cursor_getReceiverType(CXCursor C) { ME = dyn_cast_or_null(CE->getCallee()); if (ME) { - if (dyn_cast_or_null(ME->getMemberDecl())) { + if (isa_and_nonnull(ME->getMemberDecl())) { auto receiverTy = ME->getBase()->IgnoreImpCasts()->getType(); return cxtype::MakeCXType(receiverTy, TU); }