[clang] Use isa instead of dyn_cast (NFC)

This commit is contained in:
Kazu Hirata 2021-11-14 09:32:40 -08:00
parent 7379736774
commit d0ac215dd5
21 changed files with 28 additions and 29 deletions

View File

@ -86,7 +86,7 @@ public:
/// Determine whether this capture handles a variable. /// Determine whether this capture handles a variable.
bool capturesVariable() const { bool capturesVariable() const {
return dyn_cast_or_null<VarDecl>(DeclAndBits.getPointer()); return isa_and_nonnull<VarDecl>(DeclAndBits.getPointer());
} }
/// Determine whether this captures a variable length array bound /// Determine whether this captures a variable length array bound

View File

@ -488,7 +488,7 @@ public:
/// Determine whether this is an array new with an unknown bound. /// Determine whether this is an array new with an unknown bound.
bool isVariableLengthArrayNew() const { bool isVariableLengthArrayNew() const {
return getKind() == EK_New && dyn_cast_or_null<IncompleteArrayType>( return getKind() == EK_New && isa_and_nonnull<IncompleteArrayType>(
getType()->getAsArrayTypeUnsafe()); getType()->getAsArrayTypeUnsafe());
} }

View File

@ -296,7 +296,7 @@ static NestedNameSpecifier *createNestedNameSpecifierForScopeOf(
} else if (const auto *TD = dyn_cast<TagDecl>(Outer)) { } else if (const auto *TD = dyn_cast<TagDecl>(Outer)) {
return createNestedNameSpecifier( return createNestedNameSpecifier(
Ctx, TD, FullyQualified, WithGlobalNsPrefix); Ctx, TD, FullyQualified, WithGlobalNsPrefix);
} else if (dyn_cast<TranslationUnitDecl>(Outer)) { } else if (isa<TranslationUnitDecl>(Outer)) {
// Context is the TU. Nothing needs to be done. // Context is the TU. Nothing needs to be done.
return nullptr; return nullptr;
} else { } else {

View File

@ -1892,7 +1892,7 @@ DeducedType *Type::getContainedDeducedType() const {
} }
bool Type::hasAutoForTrailingReturnType() const { bool Type::hasAutoForTrailingReturnType() const {
return dyn_cast_or_null<FunctionType>( return isa_and_nonnull<FunctionType>(
GetContainedDeducedTypeVisitor(true).Visit(this)); GetContainedDeducedTypeVisitor(true).Visit(this));
} }

View File

@ -3913,7 +3913,7 @@ static void emitPrivatesInit(CodeGenFunction &CGF,
SharedRefLValue.getTBAAInfo()); SharedRefLValue.getTBAAInfo());
} else if (CGF.LambdaCaptureFields.count( } else if (CGF.LambdaCaptureFields.count(
Pair.second.Original->getCanonicalDecl()) > 0 || Pair.second.Original->getCanonicalDecl()) > 0 ||
dyn_cast_or_null<BlockDecl>(CGF.CurCodeDecl)) { isa_and_nonnull<BlockDecl>(CGF.CurCodeDecl)) {
SharedRefLValue = CGF.EmitLValue(Pair.second.OriginalRef); SharedRefLValue = CGF.EmitLValue(Pair.second.OriginalRef);
} else { } else {
// Processing for implicitly captured variables. // Processing for implicitly captured variables.

View File

@ -4720,7 +4720,7 @@ void CodeGenFunction::EmitOMPTargetTaskBasedDirective(
[&InputInfo]() { return InputInfo.SizesArray; }); [&InputInfo]() { return InputInfo.SizesArray; });
// If there is no user-defined mapper, the mapper array will be nullptr. In // If there is no user-defined mapper, the mapper array will be nullptr. In
// this case, we don't need to privatize it. // this case, we don't need to privatize it.
if (!dyn_cast_or_null<llvm::ConstantPointerNull>( if (!isa_and_nonnull<llvm::ConstantPointerNull>(
InputInfo.MappersArray.getPointer())) { InputInfo.MappersArray.getPointer())) {
MVD = createImplicitFirstprivateForType( MVD = createImplicitFirstprivateForType(
getContext(), Data, BaseAndPointerAndMapperType, CD, S.getBeginLoc()); getContext(), Data, BaseAndPointerAndMapperType, CD, S.getBeginLoc());

View File

@ -499,7 +499,7 @@ public:
AbstractCallee(const FunctionDecl *FD) : CalleeDecl(FD) {} AbstractCallee(const FunctionDecl *FD) : CalleeDecl(FD) {}
AbstractCallee(const ObjCMethodDecl *OMD) : CalleeDecl(OMD) {} AbstractCallee(const ObjCMethodDecl *OMD) : CalleeDecl(OMD) {}
bool hasFunctionDecl() const { bool hasFunctionDecl() const {
return dyn_cast_or_null<FunctionDecl>(CalleeDecl); return isa_and_nonnull<FunctionDecl>(CalleeDecl);
} }
const Decl *getDecl() const { return CalleeDecl; } const Decl *getDecl() const { return CalleeDecl; }
unsigned getNumParams() const { unsigned getNumParams() const {

View File

@ -1953,7 +1953,7 @@ void CodeGenModule::setLLVMFunctionFEnvAttributes(const FunctionDecl *D,
void CodeGenModule::SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV) { void CodeGenModule::SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV) {
const Decl *D = GD.getDecl(); const Decl *D = GD.getDecl();
if (dyn_cast_or_null<NamedDecl>(D)) if (isa_and_nonnull<NamedDecl>(D))
setGVProperties(GV, GD); setGVProperties(GV, GD);
else else
GV->setVisibility(llvm::GlobalValue::DefaultVisibility); GV->setVisibility(llvm::GlobalValue::DefaultVisibility);
@ -4807,7 +4807,7 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old,
callSite->getOperandBundlesAsDefs(newBundles); callSite->getOperandBundlesAsDefs(newBundles);
llvm::CallBase *newCall; llvm::CallBase *newCall;
if (dyn_cast<llvm::CallInst>(callSite)) { if (isa<llvm::CallInst>(callSite)) {
newCall = newCall =
llvm::CallInst::Create(newFn, newArgs, newBundles, "", callSite); llvm::CallInst::Create(newFn, newArgs, newBundles, "", callSite);
} else { } else {

View File

@ -969,7 +969,7 @@ struct CounterCoverageMappingBuilder
// If last statement contains terminate statements, add a gap area // If last statement contains terminate statements, add a gap area
// between the two statements. Skipping attributed statements, because // between the two statements. Skipping attributed statements, because
// they don't have valid start location. // they don't have valid start location.
if (LastStmt && HasTerminateStmt && !dyn_cast<AttributedStmt>(Child)) { if (LastStmt && HasTerminateStmt && !isa<AttributedStmt>(Child)) {
auto Gap = findGapAreaBetween(getEnd(LastStmt), getStart(Child)); auto Gap = findGapAreaBetween(getEnd(LastStmt), getStart(Child));
if (Gap) if (Gap)
fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(),

View File

@ -2741,8 +2741,8 @@ static bool isValidBPFPreserveFieldInfoArg(Expr *Arg) {
// to BPF backend to check whether the access is a // to BPF backend to check whether the access is a
// field access or not. // field access or not.
return (Arg->IgnoreParens()->getObjectKind() == OK_BitField || return (Arg->IgnoreParens()->getObjectKind() == OK_BitField ||
dyn_cast<MemberExpr>(Arg->IgnoreParens()) || isa<MemberExpr>(Arg->IgnoreParens()) ||
dyn_cast<ArraySubscriptExpr>(Arg->IgnoreParens())); isa<ArraySubscriptExpr>(Arg->IgnoreParens()));
} }
static bool isEltOfVectorTy(ASTContext &Context, CallExpr *Call, Sema &S, static bool isEltOfVectorTy(ASTContext &Context, CallExpr *Call, Sema &S,
@ -2766,8 +2766,8 @@ static bool isValidBPFPreserveTypeInfoArg(Expr *Arg) {
// 1. __builtin_preserve_type_info(*(<type> *)0, flag); // 1. __builtin_preserve_type_info(*(<type> *)0, flag);
// 2. <type> var; // 2. <type> var;
// __builtin_preserve_type_info(var, flag); // __builtin_preserve_type_info(var, flag);
if (!dyn_cast<DeclRefExpr>(Arg->IgnoreParens()) && if (!isa<DeclRefExpr>(Arg->IgnoreParens()) &&
!dyn_cast<UnaryOperator>(Arg->IgnoreParens())) !isa<UnaryOperator>(Arg->IgnoreParens()))
return false; return false;
// Typedef type. // Typedef type.

View File

@ -5781,7 +5781,7 @@ bool Sema::diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC,
NestedNameSpecifierLoc SpecLoc(SS.getScopeRep(), SS.location_data()); NestedNameSpecifierLoc SpecLoc(SS.getScopeRep(), SS.location_data());
while (SpecLoc.getPrefix()) while (SpecLoc.getPrefix())
SpecLoc = SpecLoc.getPrefix(); SpecLoc = SpecLoc.getPrefix();
if (dyn_cast_or_null<DecltypeType>( if (isa_and_nonnull<DecltypeType>(
SpecLoc.getNestedNameSpecifier()->getAsType())) SpecLoc.getNestedNameSpecifier()->getAsType()))
Diag(Loc, diag::err_decltype_in_declarator) Diag(Loc, diag::err_decltype_in_declarator)
<< SpecLoc.getTypeLoc().getSourceRange(); << SpecLoc.getTypeLoc().getSourceRange();

View File

@ -611,7 +611,7 @@ ActOnSuperClassOfClassInterface(Scope *S,
} }
} }
if (!dyn_cast_or_null<TypedefNameDecl>(PrevDecl)) { if (!isa_and_nonnull<TypedefNameDecl>(PrevDecl)) {
if (!SuperClassDecl) if (!SuperClassDecl)
Diag(SuperLoc, diag::err_undef_superclass) Diag(SuperLoc, diag::err_undef_superclass)
<< SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc); << SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc);

View File

@ -5709,7 +5709,7 @@ Sema::VariadicCallType
Sema::getVariadicCallType(FunctionDecl *FDecl, const FunctionProtoType *Proto, Sema::getVariadicCallType(FunctionDecl *FDecl, const FunctionProtoType *Proto,
Expr *Fn) { Expr *Fn) {
if (Proto && Proto->isVariadic()) { if (Proto && Proto->isVariadic()) {
if (dyn_cast_or_null<CXXConstructorDecl>(FDecl)) if (isa_and_nonnull<CXXConstructorDecl>(FDecl))
return VariadicConstructor; return VariadicConstructor;
else if (Fn && Fn->getType()->isBlockPointerType()) else if (Fn && Fn->getType()->isBlockPointerType())
return VariadicBlock; return VariadicBlock;

View File

@ -9860,9 +9860,9 @@ bool clang::isBetterOverloadCandidate(
// F1 and F2 have the same type. // F1 and F2 have the same type.
// FIXME: Implement the "all parameters have the same type" check. // FIXME: Implement the "all parameters have the same type" check.
bool Cand1IsInherited = bool Cand1IsInherited =
dyn_cast_or_null<ConstructorUsingShadowDecl>(Cand1.FoundDecl.getDecl()); isa_and_nonnull<ConstructorUsingShadowDecl>(Cand1.FoundDecl.getDecl());
bool Cand2IsInherited = bool Cand2IsInherited =
dyn_cast_or_null<ConstructorUsingShadowDecl>(Cand2.FoundDecl.getDecl()); isa_and_nonnull<ConstructorUsingShadowDecl>(Cand2.FoundDecl.getDecl());
if (Cand1IsInherited != Cand2IsInherited) if (Cand1IsInherited != Cand2IsInherited)
return Cand2IsInherited; return Cand2IsInherited;
else if (Cand1IsInherited) { else if (Cand1IsInherited) {
@ -12673,7 +12673,7 @@ static void AddOverloadedCallCandidate(Sema &S,
return; return;
} }
// Prevent ill-formed function decls to be added as overload candidates. // Prevent ill-formed function decls to be added as overload candidates.
if (!dyn_cast<FunctionProtoType>(Func->getType()->getAs<FunctionType>())) if (!isa<FunctionProtoType>(Func->getType()->getAs<FunctionType>()))
return; return;
S.AddOverloadCandidate(Func, FoundDecl, Args, CandidateSet, S.AddOverloadCandidate(Func, FoundDecl, Args, CandidateSet,

View File

@ -743,7 +743,7 @@ Sema::ActOnDependentIdExpression(const CXXScopeSpec &SS,
// Check if the nested name specifier is an enum type. // Check if the nested name specifier is an enum type.
bool IsEnum = false; bool IsEnum = false;
if (NestedNameSpecifier *NNS = SS.getScopeRep()) if (NestedNameSpecifier *NNS = SS.getScopeRep())
IsEnum = dyn_cast_or_null<EnumType>(NNS->getAsType()); IsEnum = isa_and_nonnull<EnumType>(NNS->getAsType());
if (!MightBeCxx11UnevalField && !isAddressOfOperand && !IsEnum && if (!MightBeCxx11UnevalField && !isAddressOfOperand && !IsEnum &&
isa<CXXMethodDecl>(DC) && cast<CXXMethodDecl>(DC)->isInstance()) { isa<CXXMethodDecl>(DC) && cast<CXXMethodDecl>(DC)->isInstance()) {

View File

@ -5428,7 +5428,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
// Avoid emitting extra errors if we already errored on the scope. // Avoid emitting extra errors if we already errored on the scope.
D.setInvalidType(true); D.setInvalidType(true);
} else if (S.isDependentScopeSpecifier(SS) || } else if (S.isDependentScopeSpecifier(SS) ||
dyn_cast_or_null<CXXRecordDecl>(S.computeDeclContext(SS))) { isa_and_nonnull<CXXRecordDecl>(S.computeDeclContext(SS))) {
NestedNameSpecifier *NNS = SS.getScopeRep(); NestedNameSpecifier *NNS = SS.getScopeRep();
NestedNameSpecifier *NNSPrefix = NNS->getPrefix(); NestedNameSpecifier *NNSPrefix = NNS->getPrefix();
switch (NNS->getKind()) { switch (NNS->getKind()) {

View File

@ -384,7 +384,7 @@ void DynamicTypePropagation::checkPostCall(const CallEvent &Call,
// FIXME: Instead of relying on the ParentMap, we should have the // FIXME: Instead of relying on the ParentMap, we should have the
// trigger-statement (InitListExpr in this case) available in this // trigger-statement (InitListExpr in this case) available in this
// callback, ideally as part of CallEvent. // callback, ideally as part of CallEvent.
if (dyn_cast_or_null<InitListExpr>( if (isa_and_nonnull<InitListExpr>(
LCtx->getParentMap().getParent(Ctor->getOriginExpr()))) LCtx->getParentMap().getParent(Ctor->getOriginExpr())))
return; return;

View File

@ -290,7 +290,7 @@ void RetainCountChecker::checkPostStmt(const ObjCIvarRefExpr *IRE,
ProgramStateRef State = C.getState(); ProgramStateRef State = C.getState();
SymbolRef Sym = State->getSVal(*IVarLoc).getAsSymbol(); SymbolRef Sym = State->getSVal(*IVarLoc).getAsSymbol();
if (!Sym || !dyn_cast_or_null<ObjCIvarRegion>(Sym->getOriginRegion())) if (!Sym || !isa_and_nonnull<ObjCIvarRegion>(Sym->getOriginRegion()))
return; return;
// Accessing an ivar directly is unusual. If we've done that, be more // Accessing an ivar directly is unusual. If we've done that, be more

View File

@ -68,8 +68,7 @@ public:
if (auto *F = CE->getDirectCallee()) { if (auto *F = CE->getDirectCallee()) {
// Skip the first argument for overloaded member operators (e. g. lambda // Skip the first argument for overloaded member operators (e. g. lambda
// or std::function call operator). // or std::function call operator).
unsigned ArgIdx = unsigned ArgIdx = isa<CXXOperatorCallExpr>(CE) && isa_and_nonnull<CXXMethodDecl>(F);
isa<CXXOperatorCallExpr>(CE) && dyn_cast_or_null<CXXMethodDecl>(F);
for (auto P = F->param_begin(); for (auto P = F->param_begin();
// FIXME: Also check variadic function parameters. // FIXME: Also check variadic function parameters.

View File

@ -531,7 +531,7 @@ void ExprEngine::handleConstructor(const Expr *E,
// FIXME: Instead of relying on the ParentMap, we should have the // FIXME: Instead of relying on the ParentMap, we should have the
// trigger-statement (InitListExpr in this case) passed down from CFG or // trigger-statement (InitListExpr in this case) passed down from CFG or
// otherwise always available during construction. // otherwise always available during construction.
if (dyn_cast_or_null<InitListExpr>(LCtx->getParentMap().getParent(E))) { if (isa_and_nonnull<InitListExpr>(LCtx->getParentMap().getParent(E))) {
MemRegionManager &MRMgr = getSValBuilder().getRegionManager(); MemRegionManager &MRMgr = getSValBuilder().getRegionManager();
Target = loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(E, LCtx)); Target = loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(E, LCtx));
CallOpts.IsCtorOrDtorWithImproperlyModeledTargetRegion = true; CallOpts.IsCtorOrDtorWithImproperlyModeledTargetRegion = true;

View File

@ -1711,7 +1711,7 @@ CXType clang_Cursor_getReceiverType(CXCursor C) {
ME = dyn_cast_or_null<MemberExpr>(CE->getCallee()); ME = dyn_cast_or_null<MemberExpr>(CE->getCallee());
if (ME) { if (ME) {
if (dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl())) { if (isa_and_nonnull<CXXMethodDecl>(ME->getMemberDecl())) {
auto receiverTy = ME->getBase()->IgnoreImpCasts()->getType(); auto receiverTy = ME->getBase()->IgnoreImpCasts()->getType();
return cxtype::MakeCXType(receiverTy, TU); return cxtype::MakeCXType(receiverTy, TU);
} }