Use clang-tidy to simplify boolean conditional return statements

http://reviews.llvm.org/D10019

Files:
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaCodeComplete.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaFixItUtils.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaStmt.cpp
  lib/Sema/SemaTemplateDeduction.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -4624,10 +4624,7 @@
   if (!ND || !ND->getIdentifier() || !ND->getIdentifier()->isStr("std"))
     return false;
 
-  if (!isa<TranslationUnitDecl>(ND->getDeclContext()))
-    return false;
-
-  return true;
+  return isa<TranslationUnitDecl>(ND->getDeclContext());
 }
 
 // Warn when using the wrong abs() function.
@@ -8676,11 +8673,8 @@
     RHS = cast->getSubExpr();
   }
 
-  if (LT == Qualifiers::OCL_Weak &&
-      checkUnsafeAssignLiteral(S, Loc, RHS, isProperty))
-    return true;
-
-  return false;
+  return LT == Qualifiers::OCL_Weak &&
+         checkUnsafeAssignLiteral(S, Loc, RHS, isProperty);
 }
 
 bool Sema::checkUnsafeAssigns(SourceLocation Loc,
@@ -8690,10 +8684,7 @@
   if (LT != Qualifiers::OCL_Weak && LT != Qualifiers::OCL_ExplicitNone)
     return false;
 
-  if (checkUnsafeAssignObject(*this, Loc, LT, RHS, false))
-    return true;
-
-  return false;
+  return checkUnsafeAssignObject(*this, Loc, LT, RHS, false);
 }
 
 void Sema::checkUnsafeExprAssigns(SourceLocation Loc,
@@ -8788,10 +8779,7 @@
     return false;
 
   // Warn if null statement and body are on the same line.
-  if (StmtLine != BodyLine)
-    return false;
-
-  return true;
+  return StmtLine == BodyLine;
 }
 } // Unnamed namespace
 
@@ -9048,10 +9036,7 @@
     if (!isLayoutCompatible(C, *Field1, *Field2))
       return false;
   }
-  if (Field1 != Field1End || Field2 != Field2End)
-    return false;
-
-  return true;
+  return Field1 == Field1End && Field2 == Field2End;
 }
 
 /// \brief Check if two standard-layout unions are layout-compatible.
Index: lib/Sema/SemaCodeComplete.cpp
===================================================================
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -4797,16 +4797,12 @@
                                              ObjCDeclSpec::DQ_PR_retain |
                                              ObjCDeclSpec::DQ_PR_strong |
                                              ObjCDeclSpec::DQ_PR_weak);
-  if (AssignCopyRetMask &&
-      AssignCopyRetMask != ObjCDeclSpec::DQ_PR_assign &&
-      AssignCopyRetMask != ObjCDeclSpec::DQ_PR_unsafe_unretained &&
-      AssignCopyRetMask != ObjCDeclSpec::DQ_PR_copy &&
-      AssignCopyRetMask != ObjCDeclSpec::DQ_PR_retain &&
-      AssignCopyRetMask != ObjCDeclSpec::DQ_PR_strong &&
-      AssignCopyRetMask != ObjCDeclSpec::DQ_PR_weak)
-    return true;
-  
-  return false;
+  return AssignCopyRetMask && AssignCopyRetMask != ObjCDeclSpec::DQ_PR_assign &&
+         AssignCopyRetMask != ObjCDeclSpec::DQ_PR_unsafe_unretained &&
+         AssignCopyRetMask != ObjCDeclSpec::DQ_PR_copy &&
+         AssignCopyRetMask != ObjCDeclSpec::DQ_PR_retain &&
+         AssignCopyRetMask != ObjCDeclSpec::DQ_PR_strong &&
+         AssignCopyRetMask != ObjCDeclSpec::DQ_PR_weak;
 }
 
 void Sema::CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS) { 
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2528,9 +2528,7 @@
   LanguageLinkage OldLinkage = Old->getLanguageLinkage();
   if (OldLinkage == CXXLanguageLinkage && New->isInExternCContext())
     return true;
-  if (OldLinkage == CLanguageLinkage && New->isInExternCXXContext())
-    return true;
-  return false;
+  return OldLinkage == CLanguageLinkage && New->isInExternCXXContext();
 }
 
 /// MergeFunctionDecl - We just parsed a function 'New' from
@@ -4590,13 +4588,11 @@
     // C++ constructors and destructors with incorrect scopes can break
     // our AST invariants by having the wrong underlying types. If
     // that's the case, then drop this declaration entirely.
-    if ((Name.getNameKind() == DeclarationName::CXXConstructorName ||
-         Name.getNameKind() == DeclarationName::CXXDestructorName) &&
-        !Context.hasSameType(Name.getCXXNameType(),
-                             Context.getTypeDeclType(cast<CXXRecordDecl>(Cur))))
-      return true;
-    
-    return false;
+    return (Name.getNameKind() == DeclarationName::CXXConstructorName ||
+            Name.getNameKind() == DeclarationName::CXXDestructorName) &&
+           !Context.hasSameType(
+               Name.getCXXNameType(),
+               Context.getTypeDeclType(cast<CXXRecordDecl>(Cur)));
   }
   
   // C++11 [dcl.meaning]p1:
@@ -13608,11 +13604,8 @@
   if (!EnumConstant)
     return true;
 
-  if (cast<EnumDecl>(TagDecl::castFromDeclContext(ECD->getDeclContext())) !=
-      Enum)
-    return true;
-
-  return false;
+  return cast<EnumDecl>(TagDecl::castFromDeclContext(ECD->getDeclContext())) !=
+         Enum;
 }
 
 struct DupKey {
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -363,10 +363,7 @@
 
   DeclContextLookupResult Res2 = RT->getDecl()->lookup(
       S.Context.DeclarationNames.getCXXOperatorName(OO_Arrow));
-  if (Res2.empty())
-    return false;
-
-  return true;
+  return !Res2.empty();
 }
 
 /// \brief Check if passed in Decl is a pointer type.
@@ -457,10 +454,7 @@
   if (checkTypedefTypeForCapability(Ty))
     return true;
 
-  if (checkRecordTypeForCapability(S, Ty))
-    return true;
-
-  return false;
+  return checkRecordTypeForCapability(S, Ty);
 }
 
 static bool isCapabilityExpr(Sema &S, const Expr *Ex) {
@@ -639,10 +633,7 @@
 
   // Check that all arguments are lockable objects.
   checkAttrArgsAreCapabilityObjs(S, D, Attr, Args);
-  if (Args.empty())
-    return false;
-
-  return true;
+  return !Args.empty();
 }
 
 static void handleAcquiredAfterAttr(Sema &S, Decl *D,
@@ -1811,10 +1802,7 @@
   if (X == Y)
     return true;
 
-  if (BeforeIsOkay && X < Y)
-    return true;
-
-  return false;
+  return BeforeIsOkay && X < Y;
 }
 
 AvailabilityAttr *Sema::mergeAvailabilityAttr(NamedDecl *D, SourceRange Range,
@@ -4426,10 +4414,7 @@
   }
 
   // Check whether the attribute appertains to the given subject.
-  if (!Attr.diagnoseAppertainsTo(S, D))
-    return true;
-
-  return false;
+  return !Attr.diagnoseAppertainsTo(S, D);
 }
 
 //===----------------------------------------------------------------------===//
Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -851,10 +851,7 @@
   }
 
   // - each of its parameter types shall be a literal type;
-  if (!CheckConstexprParameterTypes(*this, NewFD))
-    return false;
-
-  return true;
+  return CheckConstexprParameterTypes(*this, NewFD);
 }
 
 /// Check the given declaration statement is legal within a constexpr function
@@ -1073,11 +1070,9 @@
     if (!CheckConstexprFunctionStmt(SemaRef, Dcl, If->getThen(), ReturnStmts,
                                     Cxx1yLoc))
       return false;
-    if (If->getElse() &&
-        !CheckConstexprFunctionStmt(SemaRef, Dcl, If->getElse(), ReturnStmts,
-                                    Cxx1yLoc))
-      return false;
-    return true;
+    return !If->getElse() ||
+           CheckConstexprFunctionStmt(SemaRef, Dcl, If->getElse(), ReturnStmts,
+                                      Cxx1yLoc);
   }
 
   case Stmt::WhileStmtClass:
@@ -11577,13 +11572,10 @@
   // C++ [basic.stc.dynamic.deallocation]p2:
   //   Each deallocation function shall return void and its first parameter 
   //   shall be void*.
-  if (CheckOperatorNewDeleteTypes(SemaRef, FnDecl, SemaRef.Context.VoidTy, 
-                                  SemaRef.Context.VoidPtrTy,
-                                 diag::err_operator_delete_dependent_param_type,
-                                 diag::err_operator_delete_param_type))
-    return true;
-
-  return false;
+  return CheckOperatorNewDeleteTypes(
+      SemaRef, FnDecl, SemaRef.Context.VoidTy, SemaRef.Context.VoidPtrTy,
+      diag::err_operator_delete_dependent_param_type,
+      diag::err_operator_delete_param_type);
 }
 
 /// CheckOverloadedOperatorDeclaration - Check whether the declaration
Index: lib/Sema/SemaExceptionSpec.cpp
===================================================================
--- lib/Sema/SemaExceptionSpec.cpp
+++ lib/Sema/SemaExceptionSpec.cpp
@@ -110,13 +110,10 @@
   //   A type denoted in an exception-specification shall not denote a
   //   pointer or reference to an incomplete type, other than (cv) void* or a
   //   pointer or reference to a class currently being defined.
-  if (!(PointeeT->isRecordType() &&
+  return !(PointeeT->isRecordType() &&
         PointeeT->getAs<RecordType>()->isBeingDefined()) &&
       RequireCompleteType(Range.getBegin(), PointeeT,
-                          diag::err_incomplete_in_exception_spec, Kind, Range))
-    return true;
-
-  return false;
+                          diag::err_incomplete_in_exception_spec, Kind, Range);
 }
 
 /// CheckDistantExceptionSpec - Check if the given type is a pointer or pointer
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -66,11 +66,8 @@
   }
 
   // See if this function is unavailable.
-  if (D->getAvailability() == AR_Unavailable &&
-      cast<Decl>(CurContext)->getAvailability() != AR_Unavailable)
-    return false;
-
-  return true;
+  return !(D->getAvailability() == AR_Unavailable &&
+      cast<Decl>(CurContext)->getAvailability() != AR_Unavailable);
 }
 
 static void DiagnoseUnusedOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc) {
@@ -3690,11 +3687,8 @@
     return true;
   }
 
-  if (CheckObjCTraitOperandConstraints(*this, ExprType, OpLoc, ExprRange,
-                                       ExprKind))
-    return true;
-
-  return false;
+  return CheckObjCTraitOperandConstraints(*this, ExprType, OpLoc, ExprRange,
+                                       ExprKind);
 }
 
 static bool CheckAlignOfExpr(Sema &S, Expr *E) {
@@ -6424,10 +6418,7 @@
     return IsLogicOp(OP->getOpcode());
   if (UnaryOperator *OP = dyn_cast<UnaryOperator>(E))
     return OP->getOpcode() == UO_LNot;
-  if (E->getType()->isPointerType())
-    return true;
-
-  return false;
+  return E->getType()->isPointerType();
 }
 
 /// DiagnoseConditionalPrecedence - Emit a warning when a conditional operator
@@ -7527,9 +7518,7 @@
     return !S.getLangOpts().CPlusPlus;
   }
 
-  if (checkArithmeticIncompletePointerType(S, Loc, Operand)) return false;
-
-  return true;
+  return !checkArithmeticIncompletePointerType(S, Loc, Operand);
 }
 
 /// \brief Check the validity of a binary arithmetic operation w.r.t. pointer
@@ -7588,10 +7577,7 @@
 
   if (isLHSPointer && checkArithmeticIncompletePointerType(S, Loc, LHSExpr))
     return false;
-  if (isRHSPointer && checkArithmeticIncompletePointerType(S, Loc, RHSExpr))
-    return false;
-
-  return true;
+  return !(isRHSPointer && checkArithmeticIncompletePointerType(S, Loc, RHSExpr));
 }
 
 /// diagnoseStringPlusInt - Emit a warning when adding an integer to a string
@@ -8208,10 +8194,7 @@
     return false;
 
   QualType R = Method->getReturnType();
-  if (!R->isScalarType())
-    return false;
-
-  return true;
+  return R->isScalarType();
 }
 
 Sema::ObjCLiteralKind Sema::CheckLiteralKind(Expr *FromE) {
@@ -13478,10 +13461,7 @@
     }
   } Diagnoser(FD, CE);
   
-  if (RequireCompleteType(Loc, ReturnType, Diagnoser))
-    return true;
-
-  return false;
+  return RequireCompleteType(Loc, ReturnType, Diagnoser);
 }
 
 // Diagnose the s/=/==/ and s/\|=/!=/ typos. Note that adding parentheses
Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2300,11 +2300,8 @@
       return true;
     }
 
-    if (CheckAllocationAccess(StartLoc, SourceRange(), Found.getNamingClass(),
-                              Matches[0], Diagnose) == AR_inaccessible)
-      return true;
-
-    return false;
+    return CheckAllocationAccess(StartLoc, SourceRange(), Found.getNamingClass(),
+                              Matches[0], Diagnose) == AR_inaccessible;
 
   // We found multiple suitable operators;  complain about the ambiguity.
   } else if (!Matches.empty()) {
@@ -6117,10 +6114,7 @@
   }
 
   // Objective-C++ extensions to the rule.
-  if (isa<PseudoObjectExpr>(E) || isa<ObjCIvarRefExpr>(E))
-    return true;
-
-  return false;
+  return isa<PseudoObjectExpr>(E) || isa<ObjCIvarRefExpr>(E);
 }
 
 /// Perform the conversions required for an expression used in a
Index: lib/Sema/SemaFixItUtils.cpp
===================================================================
--- lib/Sema/SemaFixItUtils.cpp
+++ lib/Sema/SemaFixItUtils.cpp
@@ -42,10 +42,8 @@
   const CanQualType FromUnq = From.getUnqualifiedType();
   const CanQualType ToUnq = To.getUnqualifiedType();
 
-  if ((FromUnq == ToUnq || (S.IsDerivedFrom(FromUnq, ToUnq)) ) &&
-      To.isAtLeastAsQualifiedAs(From))
-    return true;
-  return false;
+  return (FromUnq == ToUnq || (S.IsDerivedFrom(FromUnq, ToUnq))) &&
+         To.isAtLeastAsQualifiedAs(From);
 }
 
 bool ConversionFixItGenerator::tryToFixConversion(const Expr *FullExpr,
Index: lib/Sema/SemaOpenMP.cpp
===================================================================
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -5320,9 +5320,7 @@
         return true;
       DSAStackTy::DSAVarData DVarPrivate =
           Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false);
-      if (DVarPrivate.CKind != OMPC_unknown)
-        return true;
-      return false;
+      return DVarPrivate.CKind != OMPC_unknown;
     }
     return false;
   }
Index: lib/Sema/SemaOverload.cpp
===================================================================
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -208,15 +208,12 @@
   // array-to-pointer or function-to-pointer implicit conversions, so
   // check for their presence as well as checking whether FromType is
   // a pointer.
-  if (getToType(1)->isBooleanType() &&
-      (getFromType()->isPointerType() ||
-       getFromType()->isObjCObjectPointerType() ||
-       getFromType()->isBlockPointerType() ||
-       getFromType()->isNullPtrType() ||
-       First == ICK_Array_To_Pointer || First == ICK_Function_To_Pointer))
-    return true;
-
-  return false;
+  return getToType(1)->isBooleanType() &&
+         (getFromType()->isPointerType() ||
+          getFromType()->isObjCObjectPointerType() ||
+          getFromType()->isBlockPointerType() ||
+          getFromType()->isNullPtrType() || First == ICK_Array_To_Pointer ||
+          First == ICK_Function_To_Pointer);
 }
 
 /// isPointerConversionToVoidPointer - Determines whether this
@@ -1668,10 +1665,7 @@
 
   // If we have not converted the argument type to the parameter type,
   // this is a bad conversion sequence.
-  if (CanonFrom != CanonTo)
-    return false;
-
-  return true;
+  return CanonFrom == CanonTo;
 }
   
 static bool
@@ -1840,11 +1834,7 @@
 
   // An rvalue of type bool can be converted to an rvalue of type int,
   // with false becoming zero and true becoming one (C++ 4.5p4).
-  if (FromType->isBooleanType() && To->getKind() == BuiltinType::Int) {
-    return true;
-  }
-
-  return false;
+  return FromType->isBooleanType() && To->getKind() == BuiltinType::Int;
 }
 
 /// IsFloatingPointPromotion - Determines whether the conversion from
@@ -2777,11 +2767,8 @@
 static bool isNonTrivialObjCLifetimeConversion(Qualifiers FromQuals,
                                                Qualifiers ToQuals) {
   // Converting anything to const __unsafe_unretained is trivial.
-  if (ToQuals.hasConst() && 
-      ToQuals.getObjCLifetime() == Qualifiers::OCL_ExplicitNone)
-    return false;
-
-  return true;
+  return !ToQuals.hasConst() ||
+         ToQuals.getObjCLifetime() != Qualifiers::OCL_ExplicitNone;
 }
 
 /// IsQualificationConversion - Determines whether the conversion from
Index: lib/Sema/SemaStmt.cpp
===================================================================
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -539,11 +539,9 @@
   if (lhs.first < rhs.first)
     return true;
 
-  if (lhs.first == rhs.first &&
-      lhs.second->getCaseLoc().getRawEncoding()
-       < rhs.second->getCaseLoc().getRawEncoding())
-    return true;
-  return false;
+  return lhs.first == rhs.first &&
+         lhs.second->getCaseLoc().getRawEncoding() <
+             rhs.second->getCaseLoc().getRawEncoding();
 }
 
 /// CmpEnumVals - Comparison predicate for sorting enumeration values.
@@ -2684,11 +2682,8 @@
 
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
-  if (!VD->getType()->isDependentType() && VD->hasAttr<AlignedAttr>() &&
-      Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VD->getType()))
-    return false;
-
-  return true;
+  return VD->getType()->isDependentType() || !VD->hasAttr<AlignedAttr>() ||
+         Context.getDeclAlign(VD) <= Context.getTypeAlignInChars(VD->getType());
 }
 
 /// \brief Perform the initialization of a potentially-movable value, which
Index: lib/Sema/SemaTemplateDeduction.cpp
===================================================================
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -2728,12 +2728,9 @@
   
   if (Context.hasSameUnqualifiedType(A, DeducedA))
     return false;
-  
-  if (A->isRecordType() && isSimpleTemplateIdType(OriginalParamType) &&
-      S.IsDerivedFrom(A, DeducedA))
-    return false;
-  
-  return true;
+
+  return !A->isRecordType() || !isSimpleTemplateIdType(OriginalParamType) ||
+         !S.IsDerivedFrom(A, DeducedA);
 }
 
 /// \brief Finish template argument deduction for a function template,
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to