Skip to content

Commit 69e9e77

Browse files
authored
[clang] Replace X && isa<Y>(X) with isa_and_nonnull<Y>(X). NFC (#94987)
This addresses a clang-tidy suggestion.
1 parent cb63abc commit 69e9e77

27 files changed

+49
-46
lines changed

clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ class CapabilityExpr {
330330

331331
bool shouldIgnore() const { return sexpr() == nullptr; }
332332

333-
bool isInvalid() const { return sexpr() && isa<til::Undefined>(sexpr()); }
333+
bool isInvalid() const { return isa_and_nonnull<til::Undefined>(sexpr()); }
334334

335-
bool isUniversal() const { return sexpr() && isa<til::Wildcard>(sexpr()); }
335+
bool isUniversal() const { return isa_and_nonnull<til::Wildcard>(sexpr()); }
336336
};
337337

338338
// Translate clang::Expr to til::SExpr.

clang/include/clang/Lex/Preprocessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ class Preprocessor {
13601360

13611361
MacroState &S = CurSubmoduleState->Macros[II];
13621362
auto *MD = S.getLatest();
1363-
while (MD && isa<VisibilityMacroDirective>(MD))
1363+
while (isa_and_nonnull<VisibilityMacroDirective>(MD))
13641364
MD = MD->getPrevious();
13651365
return MacroDefinition(dyn_cast_or_null<DefMacroDirective>(MD),
13661366
S.getActiveModuleMacros(*this, II),

clang/include/clang/Sema/SemaObjC.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class SemaObjC : public SemaBase {
383383
void AddAnyMethodToGlobalPool(Decl *D);
384384

385385
void ActOnStartOfObjCMethodDef(Scope *S, Decl *D);
386-
bool isObjCMethodDecl(Decl *D) { return D && isa<ObjCMethodDecl>(D); }
386+
bool isObjCMethodDecl(Decl *D) { return isa_and_nonnull<ObjCMethodDecl>(D); }
387387

388388
/// CheckImplementationIvars - This routine checks if the instance variables
389389
/// listed in the implelementation match those listed in the interface.

clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ class SymbolicRegion : public SubRegion {
781781
: SubRegion(sreg, SymbolicRegionKind), sym(s) {
782782
// Because pointer arithmetic is represented by ElementRegion layers,
783783
// the base symbol here should not contain any arithmetic.
784-
assert(s && isa<SymbolData>(s));
784+
assert(isa_and_nonnull<SymbolData>(s));
785785
assert(s->getType()->isAnyPointerType() ||
786786
s->getType()->isReferenceType() ||
787787
s->getType()->isBlockPointerType());

clang/lib/ARCMigrate/TransUnbridgedCasts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class UnbridgedCastRewriter : public RecursiveASTVisitor<UnbridgedCastRewriter>{
371371
Stmt *parent = E;
372372
do {
373373
parent = StmtMap->getParentIgnoreParenImpCasts(parent);
374-
} while (parent && isa<FullExpr>(parent));
374+
} while (isa_and_nonnull<FullExpr>(parent));
375375

376376
if (ReturnStmt *retS = dyn_cast_or_null<ReturnStmt>(parent)) {
377377
std::string note = "remove the cast and change return type of function "

clang/lib/AST/ASTImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ ExpectedType ASTNodeImporter::VisitInjectedClassNameType(
15051505
// The InjectedClassNameType is created in VisitRecordDecl when the
15061506
// T->getDecl() is imported. Here we can return the existing type.
15071507
const Type *Ty = (*ToDeclOrErr)->getTypeForDecl();
1508-
assert(Ty && isa<InjectedClassNameType>(Ty));
1508+
assert(isa_and_nonnull<InjectedClassNameType>(Ty));
15091509
return QualType(Ty, 0);
15101510
}
15111511

clang/lib/AST/DeclBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ bool Decl::isInExportDeclContext() const {
11161116
while (DC && !isa<ExportDecl>(DC))
11171117
DC = DC->getLexicalParent();
11181118

1119-
return DC && isa<ExportDecl>(DC);
1119+
return isa_and_nonnull<ExportDecl>(DC);
11201120
}
11211121

11221122
bool Decl::isInAnotherModuleUnit() const {

clang/lib/AST/Expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind IK,
837837
typedef SmallVector<const ClassTemplateSpecializationDecl *, 8> SpecsTy;
838838
SpecsTy Specs;
839839
const DeclContext *Ctx = FD->getDeclContext();
840-
while (Ctx && isa<NamedDecl>(Ctx)) {
840+
while (isa_and_nonnull<NamedDecl>(Ctx)) {
841841
const ClassTemplateSpecializationDecl *Spec
842842
= dyn_cast<ClassTemplateSpecializationDecl>(Ctx);
843843
if (Spec && !Spec->isExplicitSpecialization())
@@ -3067,7 +3067,7 @@ Expr *Expr::IgnoreParenCasts() {
30673067

30683068
Expr *Expr::IgnoreConversionOperatorSingleStep() {
30693069
if (auto *MCE = dyn_cast<CXXMemberCallExpr>(this)) {
3070-
if (MCE->getMethodDecl() && isa<CXXConversionDecl>(MCE->getMethodDecl()))
3070+
if (isa_and_nonnull<CXXConversionDecl>(MCE->getMethodDecl()))
30713071
return MCE->getImplicitObjectArgument();
30723072
}
30733073
return this;

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,7 @@ static bool IsWeakLValue(const LValue &Value) {
21302130

21312131
static bool isZeroSized(const LValue &Value) {
21322132
const ValueDecl *Decl = GetLValueBaseDecl(Value);
2133-
if (Decl && isa<VarDecl>(Decl)) {
2133+
if (isa_and_nonnull<VarDecl>(Decl)) {
21342134
QualType Ty = Decl->getType();
21352135
if (Ty->isArrayType())
21362136
return Ty->isIncompleteType() ||

clang/lib/AST/Mangle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void MangleContext::mangleBlock(const DeclContext *DC, const BlockDecl *BD,
302302
assert((isa<NamedDecl>(DC) || isa<BlockDecl>(DC)) &&
303303
"expected a NamedDecl or BlockDecl");
304304
if (isa<BlockDecl>(DC))
305-
for (; DC && isa<BlockDecl>(DC); DC = DC->getParent())
305+
for (; isa_and_nonnull<BlockDecl>(DC); DC = DC->getParent())
306306
(void) getBlockId(cast<BlockDecl>(DC), true);
307307
assert((isa<TranslationUnitDecl>(DC) || isa<NamedDecl>(DC)) &&
308308
"expected a TranslationUnitDecl or a NamedDecl");

0 commit comments

Comments
 (0)