From c8d2ae52c15b4c886e70587cbc3f61aaa7bd6692 Mon Sep 17 00:00:00 2001 From: Kirill Bobyrev Date: Mon, 25 Jan 2021 11:09:56 +0100 Subject: [PATCH] [clang] NFC: Remove else-after-return pattern from some files Follow-up on D95336. A bunch of these cases were found manually, the rest made sense to be included to eliminate llvm-else-after-return Clang-Tidy warnings. --- clang/include/clang/AST/ASTContext.h | 10 +++--- clang/lib/AST/Decl.cpp | 47 +++++++++++++--------------- clang/lib/AST/DeclBase.cpp | 31 +++++++++--------- clang/lib/AST/Expr.cpp | 17 +++++----- 4 files changed, 49 insertions(+), 56 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 0c5d82b3e9aa..bc86022d3743 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -2401,12 +2401,10 @@ public: return (*SuperTnullability == NullabilityKind::NonNull && *SubTnullability == NullabilityKind::Nullable); } - else { - // For the return type, it's okay for the superclass method to specify - // "nullable" and the subclass method specify "nonnull" - return (*SuperTnullability == NullabilityKind::Nullable && - *SubTnullability == NullabilityKind::NonNull); - } + // For the return type, it's okay for the superclass method to specify + // "nullable" and the subclass method specify "nonnull" + return (*SuperTnullability == NullabilityKind::Nullable && + *SubTnullability == NullabilityKind::NonNull); } return true; } diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 3cea3c23b527..feb9b0645ebc 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1823,8 +1823,7 @@ template static SourceLocation getTemplateOrInnerLocStart(const DeclT *decl) { if (decl->getNumTemplateParameterLists() > 0) return decl->getTemplateParameterList(0)->getTemplateLoc(); - else - return decl->getInnerLocStart(); + return decl->getInnerLocStart(); } SourceLocation DeclaratorDecl::getTypeSpecStartLoc() const { @@ -2132,10 +2131,9 @@ VarDecl::isThisDeclarationADefinition(ASTContext &C) const { TSK_ExplicitSpecialization) || isa(this))) return Definition; - else if (!isOutOfLine() && isInline()) + if (!isOutOfLine() && isInline()) return Definition; - else - return DeclarationOnly; + return DeclarationOnly; } // C99 6.7p5: // A definition of an identifier is a declaration for that identifier that @@ -2198,7 +2196,7 @@ VarDecl *VarDecl::getActingDefinition() { Kind = I->isThisDeclarationADefinition(); if (Kind == Definition) return nullptr; - else if (Kind == TentativeDefinition) + if (Kind == TentativeDefinition) LastTentative = I; } return LastTentative; @@ -2270,8 +2268,7 @@ VarDecl *VarDecl::getInitializingDeclaration() { if (I->isThisDeclarationADefinition()) { if (isStaticDataMember()) return I; - else - Def = I; + Def = I; } } return Def; @@ -3595,8 +3592,7 @@ bool FunctionDecl::isInlineDefinitionExternallyVisible() const { OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const { if (getDeclName().getNameKind() == DeclarationName::CXXOperatorName) return getDeclName().getCXXOverloadedOperator(); - else - return OO_None; + return OO_None; } /// getLiteralIdentifier - The literal suffix identifier this function @@ -3604,8 +3600,7 @@ OverloadedOperatorKind FunctionDecl::getOverloadedOperator() const { const IdentifierInfo *FunctionDecl::getLiteralIdentifier() const { if (getDeclName().getNameKind() == DeclarationName::CXXLiteralOperatorName) return getDeclName().getCXXLiteralIdentifier(); - else - return nullptr; + return nullptr; } FunctionDecl::TemplatedKind FunctionDecl::getTemplatedKind() const { @@ -3938,8 +3933,8 @@ SourceLocation FunctionDecl::getPointOfInstantiation() const { = TemplateOrSpecialization.dyn_cast< FunctionTemplateSpecializationInfo*>()) return FTSInfo->getPointOfInstantiation(); - else if (MemberSpecializationInfo *MSInfo - = TemplateOrSpecialization.dyn_cast()) + if (MemberSpecializationInfo *MSInfo = + TemplateOrSpecialization.dyn_cast()) return MSInfo->getPointOfInstantiation(); return SourceLocation(); @@ -4053,29 +4048,29 @@ unsigned FunctionDecl::getMemoryFunctionKind() const { if (isExternC()) { if (FnInfo->isStr("memset")) return Builtin::BImemset; - else if (FnInfo->isStr("memcpy")) + if (FnInfo->isStr("memcpy")) return Builtin::BImemcpy; - else if (FnInfo->isStr("mempcpy")) + if (FnInfo->isStr("mempcpy")) return Builtin::BImempcpy; - else if (FnInfo->isStr("memmove")) + if (FnInfo->isStr("memmove")) return Builtin::BImemmove; - else if (FnInfo->isStr("memcmp")) + if (FnInfo->isStr("memcmp")) return Builtin::BImemcmp; - else if (FnInfo->isStr("bcmp")) + if (FnInfo->isStr("bcmp")) return Builtin::BIbcmp; - else if (FnInfo->isStr("strncpy")) + if (FnInfo->isStr("strncpy")) return Builtin::BIstrncpy; - else if (FnInfo->isStr("strncmp")) + if (FnInfo->isStr("strncmp")) return Builtin::BIstrncmp; - else if (FnInfo->isStr("strncasecmp")) + if (FnInfo->isStr("strncasecmp")) return Builtin::BIstrncasecmp; - else if (FnInfo->isStr("strncat")) + if (FnInfo->isStr("strncat")) return Builtin::BIstrncat; - else if (FnInfo->isStr("strndup")) + if (FnInfo->isStr("strndup")) return Builtin::BIstrndup; - else if (FnInfo->isStr("strlen")) + if (FnInfo->isStr("strlen")) return Builtin::BIstrlen; - else if (FnInfo->isStr("bzero")) + if (FnInfo->isStr("bzero")) return Builtin::BIbzero; } else if (isInStdNamespace()) { if (FnInfo->isStr("free")) diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 1b59f217e3c1..c26d6d1a42ea 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -230,11 +230,11 @@ bool Decl::isTemplateDecl() const { TemplateDecl *Decl::getDescribedTemplate() const { if (auto *FD = dyn_cast(this)) return FD->getDescribedFunctionTemplate(); - else if (auto *RD = dyn_cast(this)) + if (auto *RD = dyn_cast(this)) return RD->getDescribedClassTemplate(); - else if (auto *VD = dyn_cast(this)) + if (auto *VD = dyn_cast(this)) return VD->getDescribedVarTemplate(); - else if (auto *AD = dyn_cast(this)) + if (auto *AD = dyn_cast(this)) return AD->getDescribedAliasTemplate(); return nullptr; @@ -695,24 +695,23 @@ bool Decl::canBeWeakImported(bool &IsDefinition) const { return false; } return true; - + } // Functions, if they aren't definitions. - } else if (const auto *FD = dyn_cast(this)) { + if (const auto *FD = dyn_cast(this)) { if (FD->hasBody()) { IsDefinition = true; return false; } return true; + } // Objective-C classes, if this is the non-fragile runtime. - } else if (isa(this) && + if (isa(this) && getASTContext().getLangOpts().ObjCRuntime.hasWeakClassImport()) { return true; - - // Nothing else. - } else { - return false; } + // Nothing else. + return false; } bool Decl::isWeakImported() const { @@ -1027,16 +1026,16 @@ template static Decl *getNonClosureContext(T *D) { MD->getParent()->isLambda()) return getNonClosureContext(MD->getParent()->getParent()); return MD; - } else if (auto *FD = dyn_cast(D)) + } + if (auto *FD = dyn_cast(D)) return FD; - else if (auto *MD = dyn_cast(D)) + if (auto *MD = dyn_cast(D)) return MD; - else if (auto *BD = dyn_cast(D)) + if (auto *BD = dyn_cast(D)) return getNonClosureContext(BD->getParent()); - else if (auto *CD = dyn_cast(D)) + if (auto *CD = dyn_cast(D)) return getNonClosureContext(CD->getParent()); - else - return nullptr; + return nullptr; } Decl *Decl::getNonClosureContext() { diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 5d7066cc2699..adb33036a168 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -117,7 +117,8 @@ const Expr *Expr::skipRValueSubobjectAdjustments( BO->getRHS()->getType()->getAs(); Adjustments.push_back(SubobjectAdjustment(MPT, BO->getRHS())); continue; - } else if (BO->getOpcode() == BO_Comma) { + } + if (BO->getOpcode() == BO_Comma) { CommaLHSs.push_back(BO->getLHS()); E = BO->getRHS(); continue; @@ -586,8 +587,8 @@ std::string PredefinedExpr::ComputeName(IdentKind IK, const Decl *CurrentDecl) { if (!Buffer.empty() && Buffer.front() == '\01') return std::string(Buffer.substr(1)); return std::string(Buffer.str()); - } else - return std::string(ND->getIdentifier()->getName()); + } + return std::string(ND->getIdentifier()->getName()); } return ""; } @@ -3700,7 +3701,7 @@ Expr::isNullPointerConstant(ASTContext &Ctx, const IntegerLiteral *Lit = dyn_cast(this); if (Lit && !Lit->getValue()) return NPCK_ZeroLiteral; - else if (!Ctx.getLangOpts().MSVCCompat || !isCXX98IntegralConstantExpr(Ctx)) + if (!Ctx.getLangOpts().MSVCCompat || !isCXX98IntegralConstantExpr(Ctx)) return NPCK_NotNull; } else { // If we have an integer constant expression, we need to *evaluate* it and @@ -4129,9 +4130,8 @@ GenericSelectionExpr::CreateEmpty(const ASTContext &Context, IdentifierInfo *DesignatedInitExpr::Designator::getFieldName() const { assert(Kind == FieldDesignator && "Only valid on a field designator"); if (Field.NameOrField & 0x01) - return reinterpret_cast(Field.NameOrField&~0x01); - else - return getField()->getIdentifier(); + return reinterpret_cast(Field.NameOrField & ~0x01); + return getField()->getIdentifier(); } DesignatedInitExpr::DesignatedInitExpr(const ASTContext &C, QualType Ty, @@ -4249,7 +4249,8 @@ void DesignatedInitExpr::ExpandDesignator(const ASTContext &C, unsigned Idx, Designators + Idx); --NumNewDesignators; return; - } else if (NumNewDesignators == 1) { + } + if (NumNewDesignators == 1) { Designators[Idx] = *First; return; }