[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
https://github.com/samolisov closed https://github.com/llvm/llvm-project/pull/94987 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
https://github.com/samolisov updated https://github.com/llvm/llvm-project/pull/94987 >From 691223b4e873257a74b295bfb77839406adc742a Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Mon, 10 Jun 2024 17:35:14 +0300 Subject: [PATCH 1/2] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC This addresses a clang-tidy suggestion. --- .../clang/Analysis/Analyses/ThreadSafetyCommon.h | 4 ++-- clang/include/clang/Lex/Preprocessor.h | 2 +- clang/include/clang/Sema/SemaObjC.h| 2 +- .../StaticAnalyzer/Core/PathSensitive/MemRegion.h | 2 +- clang/lib/ARCMigrate/TransUnbridgedCasts.cpp | 2 +- clang/lib/AST/ASTImporter.cpp | 2 +- clang/lib/AST/DeclBase.cpp | 2 +- clang/lib/AST/Expr.cpp | 4 ++-- clang/lib/AST/ExprConstant.cpp | 2 +- clang/lib/AST/Mangle.cpp | 2 +- clang/lib/AST/MicrosoftMangle.cpp | 2 +- clang/lib/AST/ParentMap.cpp| 7 +-- clang/lib/AST/StmtPrinter.cpp | 4 ++-- clang/lib/Analysis/UnsafeBufferUsage.cpp | 2 +- clang/lib/CodeGen/CGBlocks.cpp | 2 +- clang/lib/CodeGen/CGClass.cpp | 4 ++-- clang/lib/CodeGen/CGExprConstant.cpp | 2 +- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 3 ++- clang/lib/CodeGen/CGStmtOpenMP.cpp | 6 +++--- clang/lib/CodeGen/CodeGenFunction.cpp | 2 +- clang/lib/Index/IndexBody.cpp | 2 +- clang/lib/Lex/PPMacroExpansion.cpp | 2 +- clang/lib/Sema/AnalysisBasedWarnings.cpp | 8 clang/lib/Sema/SemaCXXScopeSpec.cpp| 2 +- clang/lib/Sema/SemaChecking.cpp| 10 +- clang/lib/Sema/SemaExprCXX.cpp | 8 clang/lib/Sema/SemaInit.cpp| 6 +++--- clang/lib/Sema/SemaStmt.cpp| 2 +- clang/lib/Sema/SemaTemplate.cpp| 2 +- 29 files changed, 52 insertions(+), 48 deletions(-) diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h index 7bdb9052e57e7..e99c5b2466334 100644 --- a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h +++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h @@ -330,9 +330,9 @@ class CapabilityExpr { bool shouldIgnore() const { return sexpr() == nullptr; } - bool isInvalid() const { return sexpr() && isa(sexpr()); } + bool isInvalid() const { return isa_and_nonnull(sexpr()); } - bool isUniversal() const { return sexpr() && isa(sexpr()); } + bool isUniversal() const { return isa_and_nonnull(sexpr()); } }; // Translate clang::Expr to til::SExpr. diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index c0850a8fa9f7f..9b1628d2d86f9 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -1360,7 +1360,7 @@ class Preprocessor { MacroState = CurSubmoduleState->Macros[II]; auto *MD = S.getLatest(); -while (MD && isa(MD)) +while (isa_and_nonnull(MD)) MD = MD->getPrevious(); return MacroDefinition(dyn_cast_or_null(MD), S.getActiveModuleMacros(*this, II), diff --git a/clang/include/clang/Sema/SemaObjC.h b/clang/include/clang/Sema/SemaObjC.h index 91430797e5ed8..bb8887691ce5d 100644 --- a/clang/include/clang/Sema/SemaObjC.h +++ b/clang/include/clang/Sema/SemaObjC.h @@ -383,7 +383,7 @@ class SemaObjC : public SemaBase { void AddAnyMethodToGlobalPool(Decl *D); void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); - bool isObjCMethodDecl(Decl *D) { return D && isa(D); } + bool isObjCMethodDecl(Decl *D) { return isa_and_nonnull(D); } /// CheckImplementationIvars - This routine checks if the instance variables /// listed in the implelementation match those listed in the interface. diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h index 151d3e57c1cb8..59805d01be5db 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h @@ -781,7 +781,7 @@ class SymbolicRegion : public SubRegion { : SubRegion(sreg, SymbolicRegionKind), sym(s) { // Because pointer arithmetic is represented by ElementRegion layers, // the base symbol here should not contain any arithmetic. -assert(s && isa(s)); +assert(isa_and_nonnull(s)); assert(s->getType()->isAnyPointerType() || s->getType()->isReferenceType() ||
[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
@@ -8510,7 +8510,8 @@ class MappableExprsHandler { assert(VDecl == VD && "We got information for the wrong declaration??"); assert(!Components.empty() && "Not expecting declaration with no component lists."); -if (VD && E && VD->getType()->isAnyPointerType() && isa(E)) +if (VD && VD->getType()->isAnyPointerType() && +isa_and_nonnull(E)) HasMapBasePtr = true; if (VD && E && VD->getType()->isAnyPointerType() && (isa(E) || isa(E))) samolisov wrote: I agree and will return this change back to preserve the consistence. https://github.com/llvm/llvm-project/pull/94987 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
@@ -2772,7 +2772,7 @@ fixVariable(const VarDecl *VD, FixitStrategy::Kind K, // also covers call-operator of lamdas isa(FD) || // skip when the function body is a try-block -(FD->hasBody() && isa(FD->getBody())) || +isa_and_nonnull(FD->getBody()) || samolisov wrote: I believe this is just my bad, I undistinguished `->hasBody()` and `->getBody()`. I'll fix it, thank you. https://github.com/llvm/llvm-project/pull/94987 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
@@ -8510,7 +8510,8 @@ class MappableExprsHandler { assert(VDecl == VD && "We got information for the wrong declaration??"); assert(!Components.empty() && "Not expecting declaration with no component lists."); -if (VD && E && VD->getType()->isAnyPointerType() && isa(E)) +if (VD && VD->getType()->isAnyPointerType() && +isa_and_nonnull(E)) HasMapBasePtr = true; if (VD && E && VD->getType()->isAnyPointerType() && (isa(E) || isa(E))) NagyDonat wrote: Consider preserving the analogy between this and the next `if` with two analogous `isa<>()` calls. https://github.com/llvm/llvm-project/pull/94987 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
@@ -2772,7 +2772,7 @@ fixVariable(const VarDecl *VD, FixitStrategy::Kind K, // also covers call-operator of lamdas isa(FD) || // skip when the function body is a try-block -(FD->hasBody() && isa(FD->getBody())) || +isa_and_nonnull(FD->getBody()) || NagyDonat wrote: The comment before the definition of `getBody()` says that ``` /// NOTE: For checking if there is a body, use hasBody() instead, to avoid /// unnecessary AST de-serialization of the body. ``` so perhaps it would be better to keep `hasBody()`. (Although I don't know whether performance is relevant at this point -- if we're handling an unusual case, then the runtime doesn't matter.) https://github.com/llvm/llvm-project/pull/94987 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/94987 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
https://github.com/NagyDonat approved this pull request. LGTM as well, with two optional remarks. https://github.com/llvm/llvm-project/pull/94987 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
https://github.com/steakhal commented: LGTM, thanks! https://github.com/llvm/llvm-project/pull/94987 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
@@ -302,7 +302,7 @@ void MangleContext::mangleBlock(const DeclContext *DC, const BlockDecl *BD, assert((isa(DC) || isa(DC)) && "expected a NamedDecl or BlockDecl"); if (isa(DC)) - for (; DC && isa(DC); DC = DC->getParent()) + for (; isa_and_nonnull(DC); DC = DC->getParent()) (void) getBlockId(cast(DC), true); samolisov wrote: @NagyDonat thank you for the suggestion. I can remove the check after merging this PR as a separate change. https://github.com/llvm/llvm-project/pull/94987 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
@@ -302,7 +302,7 @@ void MangleContext::mangleBlock(const DeclContext *DC, const BlockDecl *BD, assert((isa(DC) || isa(DC)) && "expected a NamedDecl or BlockDecl"); if (isa(DC)) - for (; DC && isa(DC); DC = DC->getParent()) + for (; isa_and_nonnull(DC); DC = DC->getParent()) (void) getBlockId(cast(DC), true); NagyDonat wrote: Could you remove the line `if (isa(DC))` as well? It's completely redundant with the loop condition. Although I see that this is a big automatic change, so perhaps it should be left for a separate change. https://github.com/llvm/llvm-project/pull/94987 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
https://github.com/samolisov updated https://github.com/llvm/llvm-project/pull/94987 >From 691223b4e873257a74b295bfb77839406adc742a Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Mon, 10 Jun 2024 17:35:14 +0300 Subject: [PATCH] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC This addresses a clang-tidy suggestion. --- .../clang/Analysis/Analyses/ThreadSafetyCommon.h | 4 ++-- clang/include/clang/Lex/Preprocessor.h | 2 +- clang/include/clang/Sema/SemaObjC.h| 2 +- .../StaticAnalyzer/Core/PathSensitive/MemRegion.h | 2 +- clang/lib/ARCMigrate/TransUnbridgedCasts.cpp | 2 +- clang/lib/AST/ASTImporter.cpp | 2 +- clang/lib/AST/DeclBase.cpp | 2 +- clang/lib/AST/Expr.cpp | 4 ++-- clang/lib/AST/ExprConstant.cpp | 2 +- clang/lib/AST/Mangle.cpp | 2 +- clang/lib/AST/MicrosoftMangle.cpp | 2 +- clang/lib/AST/ParentMap.cpp| 7 +-- clang/lib/AST/StmtPrinter.cpp | 4 ++-- clang/lib/Analysis/UnsafeBufferUsage.cpp | 2 +- clang/lib/CodeGen/CGBlocks.cpp | 2 +- clang/lib/CodeGen/CGClass.cpp | 4 ++-- clang/lib/CodeGen/CGExprConstant.cpp | 2 +- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 3 ++- clang/lib/CodeGen/CGStmtOpenMP.cpp | 6 +++--- clang/lib/CodeGen/CodeGenFunction.cpp | 2 +- clang/lib/Index/IndexBody.cpp | 2 +- clang/lib/Lex/PPMacroExpansion.cpp | 2 +- clang/lib/Sema/AnalysisBasedWarnings.cpp | 8 clang/lib/Sema/SemaCXXScopeSpec.cpp| 2 +- clang/lib/Sema/SemaChecking.cpp| 10 +- clang/lib/Sema/SemaExprCXX.cpp | 8 clang/lib/Sema/SemaInit.cpp| 6 +++--- clang/lib/Sema/SemaStmt.cpp| 2 +- clang/lib/Sema/SemaTemplate.cpp| 2 +- 29 files changed, 52 insertions(+), 48 deletions(-) diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h index 7bdb9052e57e7..e99c5b2466334 100644 --- a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h +++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h @@ -330,9 +330,9 @@ class CapabilityExpr { bool shouldIgnore() const { return sexpr() == nullptr; } - bool isInvalid() const { return sexpr() && isa(sexpr()); } + bool isInvalid() const { return isa_and_nonnull(sexpr()); } - bool isUniversal() const { return sexpr() && isa(sexpr()); } + bool isUniversal() const { return isa_and_nonnull(sexpr()); } }; // Translate clang::Expr to til::SExpr. diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index c0850a8fa9f7f..9b1628d2d86f9 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -1360,7 +1360,7 @@ class Preprocessor { MacroState = CurSubmoduleState->Macros[II]; auto *MD = S.getLatest(); -while (MD && isa(MD)) +while (isa_and_nonnull(MD)) MD = MD->getPrevious(); return MacroDefinition(dyn_cast_or_null(MD), S.getActiveModuleMacros(*this, II), diff --git a/clang/include/clang/Sema/SemaObjC.h b/clang/include/clang/Sema/SemaObjC.h index 91430797e5ed8..bb8887691ce5d 100644 --- a/clang/include/clang/Sema/SemaObjC.h +++ b/clang/include/clang/Sema/SemaObjC.h @@ -383,7 +383,7 @@ class SemaObjC : public SemaBase { void AddAnyMethodToGlobalPool(Decl *D); void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); - bool isObjCMethodDecl(Decl *D) { return D && isa(D); } + bool isObjCMethodDecl(Decl *D) { return isa_and_nonnull(D); } /// CheckImplementationIvars - This routine checks if the instance variables /// listed in the implelementation match those listed in the interface. diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h index 151d3e57c1cb8..59805d01be5db 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h @@ -781,7 +781,7 @@ class SymbolicRegion : public SubRegion { : SubRegion(sreg, SymbolicRegionKind), sym(s) { // Because pointer arithmetic is represented by ElementRegion layers, // the base symbol here should not contain any arithmetic. -assert(s && isa(s)); +assert(isa_and_nonnull(s)); assert(s->getType()->isAnyPointerType() || s->getType()->isReferenceType() ||
[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff cc8fa1e9206aa69197c891ca2f17b64340c5a6aa 34352ddc7cb351c74ff3758c3990a480adc4c2c2 -- clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h clang/include/clang/Lex/Preprocessor.h clang/include/clang/Sema/SemaObjC.h clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h clang/lib/ARCMigrate/TransUnbridgedCasts.cpp clang/lib/AST/ASTImporter.cpp clang/lib/AST/DeclBase.cpp clang/lib/AST/Expr.cpp clang/lib/AST/ExprConstant.cpp clang/lib/AST/Mangle.cpp clang/lib/AST/MicrosoftMangle.cpp clang/lib/AST/ParentMap.cpp clang/lib/AST/StmtPrinter.cpp clang/lib/Analysis/UnsafeBufferUsage.cpp clang/lib/CodeGen/CGBlocks.cpp clang/lib/CodeGen/CGClass.cpp clang/lib/CodeGen/CGExprConstant.cpp clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/lib/CodeGen/CGStmtOpenMP.cpp clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/Index/IndexBody.cpp clang/lib/Lex/PPMacroExpansion.cpp clang/lib/Sema/AnalysisBasedWarnings.cpp clang/lib/Sema/SemaCXXScopeSpec.cpp clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaInit.cpp clang/lib/Sema/SemaStmt.cpp clang/lib/Sema/SemaTemplate.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/AST/ParentMap.cpp b/clang/lib/AST/ParentMap.cpp index 020f4990bb..e97cb5e226 100644 --- a/clang/lib/AST/ParentMap.cpp +++ b/clang/lib/AST/ParentMap.cpp @@ -139,7 +139,9 @@ Stmt* ParentMap::getParent(Stmt* S) const { } Stmt *ParentMap::getParentIgnoreParens(Stmt *S) const { - do { S = getParent(S); } while (isa_and_nonnull(S)); + do { +S = getParent(S); + } while (isa_and_nonnull(S)); return S; } diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp b/clang/lib/Sema/SemaCXXScopeSpec.cpp index d8db83686d..da88b6cae6 100644 --- a/clang/lib/Sema/SemaCXXScopeSpec.cpp +++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp @@ -974,7 +974,7 @@ bool Sema::ActOnCXXNestedNameSpecifier(Scope *S, R.setBegin(SS.getRange().getBegin()); Diag(CCLoc, diag::err_non_type_template_in_nested_name_specifier) - << isa_and_nonnull(TD) << Template << R; +<< isa_and_nonnull(TD) << Template << R; NoteAllFoundTemplates(Template); return true; } diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index f89cb44089..07cd0727eb 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -3839,11 +3839,11 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, if (CallType != VariadicDoesNotApply && (!FD || FD->getBuiltinID() != Builtin::BI__noop)) { unsigned NumParams = Proto ? Proto->getNumParams() - : isa_and_nonnull(FDecl) - ? cast(FDecl)->getNumParams() - : isa_and_nonnull(FDecl) - ? cast(FDecl)->param_size() - : 0; + : isa_and_nonnull(FDecl) + ? cast(FDecl)->getNumParams() + : isa_and_nonnull(FDecl) + ? cast(FDecl)->param_size() + : 0; for (unsigned ArgIdx = NumParams; ArgIdx < Args.size(); ++ArgIdx) { // Args[ArgIdx] can be null in malformed code. `` https://github.com/llvm/llvm-project/pull/94987 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Pavel Samolysov (samolisov) Changes This addresses a clang-tidy suggestion. --- Patch is 24.54 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/94987.diff 29 Files Affected: - (modified) clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h (+2-2) - (modified) clang/include/clang/Lex/Preprocessor.h (+1-1) - (modified) clang/include/clang/Sema/SemaObjC.h (+1-1) - (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h (+1-1) - (modified) clang/lib/ARCMigrate/TransUnbridgedCasts.cpp (+1-1) - (modified) clang/lib/AST/ASTImporter.cpp (+1-1) - (modified) clang/lib/AST/DeclBase.cpp (+1-1) - (modified) clang/lib/AST/Expr.cpp (+2-2) - (modified) clang/lib/AST/ExprConstant.cpp (+1-1) - (modified) clang/lib/AST/Mangle.cpp (+1-1) - (modified) clang/lib/AST/MicrosoftMangle.cpp (+1-1) - (modified) clang/lib/AST/ParentMap.cpp (+3-2) - (modified) clang/lib/AST/StmtPrinter.cpp (+2-2) - (modified) clang/lib/Analysis/UnsafeBufferUsage.cpp (+1-1) - (modified) clang/lib/CodeGen/CGBlocks.cpp (+1-1) - (modified) clang/lib/CodeGen/CGClass.cpp (+2-2) - (modified) clang/lib/CodeGen/CGExprConstant.cpp (+1-1) - (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+2-1) - (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (+3-3) - (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+1-1) - (modified) clang/lib/Index/IndexBody.cpp (+1-1) - (modified) clang/lib/Lex/PPMacroExpansion.cpp (+1-1) - (modified) clang/lib/Sema/AnalysisBasedWarnings.cpp (+4-4) - (modified) clang/lib/Sema/SemaCXXScopeSpec.cpp (+1-1) - (modified) clang/lib/Sema/SemaChecking.cpp (+2-2) - (modified) clang/lib/Sema/SemaExprCXX.cpp (+4-4) - (modified) clang/lib/Sema/SemaInit.cpp (+3-3) - (modified) clang/lib/Sema/SemaStmt.cpp (+1-1) - (modified) clang/lib/Sema/SemaTemplate.cpp (+1-1) ``diff diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h index 7bdb9052e57e7..e99c5b2466334 100644 --- a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h +++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h @@ -330,9 +330,9 @@ class CapabilityExpr { bool shouldIgnore() const { return sexpr() == nullptr; } - bool isInvalid() const { return sexpr() && isa(sexpr()); } + bool isInvalid() const { return isa_and_nonnull(sexpr()); } - bool isUniversal() const { return sexpr() && isa(sexpr()); } + bool isUniversal() const { return isa_and_nonnull(sexpr()); } }; // Translate clang::Expr to til::SExpr. diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index c0850a8fa9f7f..9b1628d2d86f9 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -1360,7 +1360,7 @@ class Preprocessor { MacroState = CurSubmoduleState->Macros[II]; auto *MD = S.getLatest(); -while (MD && isa(MD)) +while (isa_and_nonnull(MD)) MD = MD->getPrevious(); return MacroDefinition(dyn_cast_or_null(MD), S.getActiveModuleMacros(*this, II), diff --git a/clang/include/clang/Sema/SemaObjC.h b/clang/include/clang/Sema/SemaObjC.h index 91430797e5ed8..bb8887691ce5d 100644 --- a/clang/include/clang/Sema/SemaObjC.h +++ b/clang/include/clang/Sema/SemaObjC.h @@ -383,7 +383,7 @@ class SemaObjC : public SemaBase { void AddAnyMethodToGlobalPool(Decl *D); void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); - bool isObjCMethodDecl(Decl *D) { return D && isa(D); } + bool isObjCMethodDecl(Decl *D) { return isa_and_nonnull(D); } /// CheckImplementationIvars - This routine checks if the instance variables /// listed in the implelementation match those listed in the interface. diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h index 151d3e57c1cb8..59805d01be5db 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h @@ -781,7 +781,7 @@ class SymbolicRegion : public SubRegion { : SubRegion(sreg, SymbolicRegionKind), sym(s) { // Because pointer arithmetic is represented by ElementRegion layers, // the base symbol here should not contain any arithmetic. -assert(s && isa(s)); +assert(isa_and_nonnull(s)); assert(s->getType()->isAnyPointerType() || s->getType()->isReferenceType() || s->getType()->isBlockPointerType()); diff --git a/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp b/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp index 1e6354f71e294..7390ea17c8a4b 100644 --- a/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp +++ b/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp @@ -371,7 +371,7 @@ class UnbridgedCastRewriter : public RecursiveASTVisitor{ Stmt *parent = E;
[clang] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC (PR #94987)
https://github.com/samolisov created https://github.com/llvm/llvm-project/pull/94987 This addresses a clang-tidy suggestion. >From 34352ddc7cb351c74ff3758c3990a480adc4c2c2 Mon Sep 17 00:00:00 2001 From: Pavel Samolysov Date: Mon, 10 Jun 2024 17:35:14 +0300 Subject: [PATCH] [clang] Replace X && isa(X) with isa_and_nonnull(X). NFC This addresses a clang-tidy suggestion. --- .../include/clang/Analysis/Analyses/ThreadSafetyCommon.h | 4 ++-- clang/include/clang/Lex/Preprocessor.h| 2 +- clang/include/clang/Sema/SemaObjC.h | 2 +- .../clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h | 2 +- clang/lib/ARCMigrate/TransUnbridgedCasts.cpp | 2 +- clang/lib/AST/ASTImporter.cpp | 2 +- clang/lib/AST/DeclBase.cpp| 2 +- clang/lib/AST/Expr.cpp| 4 ++-- clang/lib/AST/ExprConstant.cpp| 2 +- clang/lib/AST/Mangle.cpp | 2 +- clang/lib/AST/MicrosoftMangle.cpp | 2 +- clang/lib/AST/ParentMap.cpp | 5 +++-- clang/lib/AST/StmtPrinter.cpp | 4 ++-- clang/lib/Analysis/UnsafeBufferUsage.cpp | 2 +- clang/lib/CodeGen/CGBlocks.cpp| 2 +- clang/lib/CodeGen/CGClass.cpp | 4 ++-- clang/lib/CodeGen/CGExprConstant.cpp | 2 +- clang/lib/CodeGen/CGOpenMPRuntime.cpp | 3 ++- clang/lib/CodeGen/CGStmtOpenMP.cpp| 6 +++--- clang/lib/CodeGen/CodeGenFunction.cpp | 2 +- clang/lib/Index/IndexBody.cpp | 2 +- clang/lib/Lex/PPMacroExpansion.cpp| 2 +- clang/lib/Sema/AnalysisBasedWarnings.cpp | 8 clang/lib/Sema/SemaCXXScopeSpec.cpp | 2 +- clang/lib/Sema/SemaChecking.cpp | 4 ++-- clang/lib/Sema/SemaExprCXX.cpp| 8 clang/lib/Sema/SemaInit.cpp | 6 +++--- clang/lib/Sema/SemaStmt.cpp | 2 +- clang/lib/Sema/SemaTemplate.cpp | 2 +- 29 files changed, 47 insertions(+), 45 deletions(-) diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h index 7bdb9052e57e7..e99c5b2466334 100644 --- a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h +++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h @@ -330,9 +330,9 @@ class CapabilityExpr { bool shouldIgnore() const { return sexpr() == nullptr; } - bool isInvalid() const { return sexpr() && isa(sexpr()); } + bool isInvalid() const { return isa_and_nonnull(sexpr()); } - bool isUniversal() const { return sexpr() && isa(sexpr()); } + bool isUniversal() const { return isa_and_nonnull(sexpr()); } }; // Translate clang::Expr to til::SExpr. diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index c0850a8fa9f7f..9b1628d2d86f9 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -1360,7 +1360,7 @@ class Preprocessor { MacroState = CurSubmoduleState->Macros[II]; auto *MD = S.getLatest(); -while (MD && isa(MD)) +while (isa_and_nonnull(MD)) MD = MD->getPrevious(); return MacroDefinition(dyn_cast_or_null(MD), S.getActiveModuleMacros(*this, II), diff --git a/clang/include/clang/Sema/SemaObjC.h b/clang/include/clang/Sema/SemaObjC.h index 91430797e5ed8..bb8887691ce5d 100644 --- a/clang/include/clang/Sema/SemaObjC.h +++ b/clang/include/clang/Sema/SemaObjC.h @@ -383,7 +383,7 @@ class SemaObjC : public SemaBase { void AddAnyMethodToGlobalPool(Decl *D); void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); - bool isObjCMethodDecl(Decl *D) { return D && isa(D); } + bool isObjCMethodDecl(Decl *D) { return isa_and_nonnull(D); } /// CheckImplementationIvars - This routine checks if the instance variables /// listed in the implelementation match those listed in the interface. diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h index 151d3e57c1cb8..59805d01be5db 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h @@ -781,7 +781,7 @@ class SymbolicRegion : public SubRegion { : SubRegion(sreg, SymbolicRegionKind), sym(s) { // Because pointer arithmetic is represented by ElementRegion layers, // the base symbol here should not contain any arithmetic. -assert(s && isa(s)); +assert(isa_and_nonnull(s)); assert(s->getType()->isAnyPointerType()