forked from OSchip/llvm-project
Fix "pointer is null" clang static analyzer warnings. NFCI.
Use cast<>/castAs<> instead of dyn_cast<>/getAs<> since the pointers are always dereferenced and cast<>/castAs<> will perform the null assertion for us.
This commit is contained in:
parent
e2b8e2113a
commit
ab9dbc1d12
|
@ -2853,8 +2853,8 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
|
|||
|
||||
// Get the function type from the pointers.
|
||||
if (FromType->isMemberPointerType() && ToType->isMemberPointerType()) {
|
||||
const MemberPointerType *FromMember = FromType->getAs<MemberPointerType>(),
|
||||
*ToMember = ToType->getAs<MemberPointerType>();
|
||||
const auto *FromMember = FromType->castAs<MemberPointerType>(),
|
||||
*ToMember = ToType->castAs<MemberPointerType>();
|
||||
if (!Context.hasSameType(FromMember->getClass(), ToMember->getClass())) {
|
||||
PDiag << ft_different_class << QualType(ToMember->getClass(), 0)
|
||||
<< QualType(FromMember->getClass(), 0);
|
||||
|
@ -3304,8 +3304,7 @@ static bool tryAtomicConversion(Sema &S, Expr *From, QualType ToType,
|
|||
static bool isFirstArgumentCompatibleWithType(ASTContext &Context,
|
||||
CXXConstructorDecl *Constructor,
|
||||
QualType Type) {
|
||||
const FunctionProtoType *CtorType =
|
||||
Constructor->getType()->getAs<FunctionProtoType>();
|
||||
const auto *CtorType = Constructor->getType()->castAs<FunctionProtoType>();
|
||||
if (CtorType->getNumParams() > 0) {
|
||||
QualType FirstArg = CtorType->getParamType(0);
|
||||
if (Context.hasSameUnqualifiedType(Type, FirstArg.getNonReferenceType()))
|
||||
|
@ -4346,14 +4345,10 @@ CompareDerivedToBaseConversions(Sema &S, SourceLocation Loc,
|
|||
if (SCS1.Second == ICK_Pointer_Member && SCS2.Second == ICK_Pointer_Member &&
|
||||
FromType1->isMemberPointerType() && FromType2->isMemberPointerType() &&
|
||||
ToType1->isMemberPointerType() && ToType2->isMemberPointerType()) {
|
||||
const MemberPointerType * FromMemPointer1 =
|
||||
FromType1->getAs<MemberPointerType>();
|
||||
const MemberPointerType * ToMemPointer1 =
|
||||
ToType1->getAs<MemberPointerType>();
|
||||
const MemberPointerType * FromMemPointer2 =
|
||||
FromType2->getAs<MemberPointerType>();
|
||||
const MemberPointerType * ToMemPointer2 =
|
||||
ToType2->getAs<MemberPointerType>();
|
||||
const auto *FromMemPointer1 = FromType1->castAs<MemberPointerType>();
|
||||
const auto *ToMemPointer1 = ToType1->castAs<MemberPointerType>();
|
||||
const auto *FromMemPointer2 = FromType2->castAs<MemberPointerType>();
|
||||
const auto *ToMemPointer2 = ToType2->castAs<MemberPointerType>();
|
||||
const Type *FromPointeeType1 = FromMemPointer1->getClass();
|
||||
const Type *ToPointeeType1 = ToMemPointer1->getClass();
|
||||
const Type *FromPointeeType2 = FromMemPointer2->getClass();
|
||||
|
@ -4534,8 +4529,7 @@ FindConversionForRefInit(Sema &S, ImplicitConversionSequence &ICS,
|
|||
Expr *Init, QualType T2, bool AllowRvalues,
|
||||
bool AllowExplicit) {
|
||||
assert(T2->isRecordType() && "Can only find conversions of record types.");
|
||||
CXXRecordDecl *T2RecordDecl
|
||||
= dyn_cast<CXXRecordDecl>(T2->castAs<RecordType>()->getDecl());
|
||||
auto *T2RecordDecl = cast<CXXRecordDecl>(T2->castAs<RecordType>()->getDecl());
|
||||
|
||||
OverloadCandidateSet CandidateSet(
|
||||
DeclLoc, OverloadCandidateSet::CSK_InitByUserDefinedConversion);
|
||||
|
@ -6097,7 +6091,7 @@ static bool IsAcceptableNonMemberOperatorCandidate(ASTContext &Context,
|
|||
if (T1->isRecordType() || (!T2.isNull() && T2->isRecordType()))
|
||||
return true;
|
||||
|
||||
const FunctionProtoType *Proto = Fn->getType()->getAs<FunctionProtoType>();
|
||||
const auto *Proto = Fn->getType()->castAs<FunctionProtoType>();
|
||||
if (Proto->getNumParams() < 1)
|
||||
return false;
|
||||
|
||||
|
@ -10403,7 +10397,7 @@ static void DiagnoseArityMismatch(Sema &S, NamedDecl *Found, Decl *D,
|
|||
FunctionDecl *Fn = cast<FunctionDecl>(D);
|
||||
|
||||
// TODO: treat calls to a missing default constructor as a special case
|
||||
const FunctionProtoType *FnTy = Fn->getType()->getAs<FunctionProtoType>();
|
||||
const auto *FnTy = Fn->getType()->castAs<FunctionProtoType>();
|
||||
unsigned MinParams = Fn->getMinRequiredArguments();
|
||||
|
||||
// at least / at most / exactly
|
||||
|
@ -13970,7 +13964,7 @@ Sema::BuildCallToMemberFunction(Scope *S, Expr *MemExprE,
|
|||
ResultType = ResultType.getNonLValueExprType(Context);
|
||||
|
||||
assert(Method && "Member call to something that isn't a method?");
|
||||
const auto *Proto = Method->getType()->getAs<FunctionProtoType>();
|
||||
const auto *Proto = Method->getType()->castAs<FunctionProtoType>();
|
||||
CXXMemberCallExpr *TheCall =
|
||||
CXXMemberCallExpr::Create(Context, MemExprE, Args, ResultType, VK,
|
||||
RParenLoc, Proto->getNumParams());
|
||||
|
@ -14067,7 +14061,6 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
|
|||
|
||||
assert(Object.get()->getType()->isRecordType() &&
|
||||
"Requires object type argument");
|
||||
const RecordType *Record = Object.get()->getType()->getAs<RecordType>();
|
||||
|
||||
// C++ [over.call.object]p1:
|
||||
// If the primary-expression E in the function call syntax
|
||||
|
@ -14084,6 +14077,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
|
|||
diag::err_incomplete_object_call, Object.get()))
|
||||
return true;
|
||||
|
||||
const auto *Record = Object.get()->getType()->castAs<RecordType>();
|
||||
LookupResult R(*this, OpName, LParenLoc, LookupOrdinaryName);
|
||||
LookupQualifiedName(R, Record->getDecl());
|
||||
R.suppressDiagnostics();
|
||||
|
@ -14231,9 +14225,7 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
|
|||
if (Method->isInvalidDecl())
|
||||
return ExprError();
|
||||
|
||||
const FunctionProtoType *Proto =
|
||||
Method->getType()->getAs<FunctionProtoType>();
|
||||
|
||||
const auto *Proto = Method->getType()->castAs<FunctionProtoType>();
|
||||
unsigned NumParams = Proto->getNumParams();
|
||||
|
||||
DeclarationNameInfo OpLocInfo(
|
||||
|
@ -14354,14 +14346,13 @@ Sema::BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
|
|||
DeclarationName OpName =
|
||||
Context.DeclarationNames.getCXXOperatorName(OO_Arrow);
|
||||
OverloadCandidateSet CandidateSet(Loc, OverloadCandidateSet::CSK_Operator);
|
||||
const RecordType *BaseRecord = Base->getType()->getAs<RecordType>();
|
||||
|
||||
if (RequireCompleteType(Loc, Base->getType(),
|
||||
diag::err_typecheck_incomplete_tag, Base))
|
||||
return ExprError();
|
||||
|
||||
LookupResult R(*this, OpName, OpLoc, LookupOrdinaryName);
|
||||
LookupQualifiedName(R, BaseRecord->getDecl());
|
||||
LookupQualifiedName(R, Base->getType()->castAs<RecordType>()->getDecl());
|
||||
R.suppressDiagnostics();
|
||||
|
||||
for (LookupResult::iterator Oper = R.begin(), OperEnd = R.end();
|
||||
|
|
Loading…
Reference in New Issue