From: Simon Pilgrim Date: Wed, 2 Oct 2019 14:02:27 +0000 (+0000) Subject: SemaOverload - silence static analyzer getAs<> null dereference warnings. NFCI. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e1b70ba580df4456bd12f526172a2056facf8da4;p=clang SemaOverload - silence static analyzer getAs<> null dereference warnings. NFCI. The static analyzer is warning about potential null dereferences, but in these cases we should be able to use castAs<> directly and if not assert will fire for us. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373475 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index b8e1d2c035..3db8e3d2e5 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -1473,14 +1473,14 @@ bool Sema::IsFunctionConversion(QualType FromType, QualType ToType, if (TyClass != CanFrom->getTypeClass()) return false; if (TyClass != Type::FunctionProto && TyClass != Type::FunctionNoProto) { if (TyClass == Type::Pointer) { - CanTo = CanTo.getAs()->getPointeeType(); - CanFrom = CanFrom.getAs()->getPointeeType(); + CanTo = CanTo.castAs()->getPointeeType(); + CanFrom = CanFrom.castAs()->getPointeeType(); } else if (TyClass == Type::BlockPointer) { - CanTo = CanTo.getAs()->getPointeeType(); - CanFrom = CanFrom.getAs()->getPointeeType(); + CanTo = CanTo.castAs()->getPointeeType(); + CanFrom = CanFrom.castAs()->getPointeeType(); } else if (TyClass == Type::MemberPointer) { - auto ToMPT = CanTo.getAs(); - auto FromMPT = CanFrom.getAs(); + auto ToMPT = CanTo.castAs(); + auto FromMPT = CanFrom.castAs(); // A function pointer conversion cannot change the class of the function. if (ToMPT->getClass() != FromMPT->getClass()) return false; @@ -2283,7 +2283,7 @@ bool Sema::IsPointerConversion(Expr *From, QualType FromType, QualType ToType, // Blocks: Block pointers can be converted to void*. if (FromType->isBlockPointerType() && ToType->isPointerType() && - ToType->getAs()->getPointeeType()->isVoidType()) { + ToType->castAs()->getPointeeType()->isVoidType()) { ConvertedType = ToType; return true; } @@ -3282,7 +3282,7 @@ IsInitializerListConstructorConversion(Sema &S, Expr *From, QualType ToType, User.ConversionFunction = Constructor; User.FoundConversionFunction = Best->FoundDecl; User.After.setAsIdentityConversion(); - User.After.setFromType(ThisType->getAs()->getPointeeType()); + User.After.setFromType(ThisType->castAs()->getPointeeType()); User.After.setAllToTypes(ToType); return Result; } @@ -3473,7 +3473,7 @@ IsUserDefinedConversion(Sema &S, Expr *From, QualType ToType, User.ConversionFunction = Constructor; User.FoundConversionFunction = Best->FoundDecl; User.After.setAsIdentityConversion(); - User.After.setFromType(ThisType->getAs()->getPointeeType()); + User.After.setFromType(ThisType->castAs()->getPointeeType()); User.After.setAllToTypes(ToType); return Result; } @@ -4115,14 +4115,14 @@ CompareDerivedToBaseConversions(Sema &S, SourceLocation Loc, /*FIXME: Remove if Objective-C id conversions get their own rank*/ FromType1->isPointerType() && FromType2->isPointerType() && ToType1->isPointerType() && ToType2->isPointerType()) { - QualType FromPointee1 - = FromType1->getAs()->getPointeeType().getUnqualifiedType(); - QualType ToPointee1 - = ToType1->getAs()->getPointeeType().getUnqualifiedType(); - QualType FromPointee2 - = FromType2->getAs()->getPointeeType().getUnqualifiedType(); - QualType ToPointee2 - = ToType2->getAs()->getPointeeType().getUnqualifiedType(); + QualType FromPointee1 = + FromType1->castAs()->getPointeeType().getUnqualifiedType(); + QualType ToPointee1 = + ToType1->castAs()->getPointeeType().getUnqualifiedType(); + QualType FromPointee2 = + FromType2->castAs()->getPointeeType().getUnqualifiedType(); + QualType ToPointee2 = + ToType2->castAs()->getPointeeType().getUnqualifiedType(); // -- conversion of C* to B* is better than conversion of C* to A*, if (FromPointee1 == FromPointee2 && ToPointee1 != ToPointee2) { @@ -4402,7 +4402,7 @@ FindConversionForRefInit(Sema &S, ImplicitConversionSequence &ICS, bool AllowExplicit) { assert(T2->isRecordType() && "Can only find conversions of record types."); CXXRecordDecl *T2RecordDecl - = dyn_cast(T2->getAs()->getDecl()); + = dyn_cast(T2->castAs()->getDecl()); OverloadCandidateSet CandidateSet( DeclLoc, OverloadCandidateSet::CSK_InitByUserDefinedConversion); @@ -4533,7 +4533,7 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType, ImplicitConversionSequence ICS; ICS.setBad(BadConversionSequence::no_conversion, Init, DeclType); - QualType T1 = DeclType->getAs()->getPointeeType(); + QualType T1 = DeclType->castAs()->getPointeeType(); QualType T2 = Init->getType(); // If the initializer is the address of an overloaded function, try @@ -4957,7 +4957,7 @@ TryListConversion(Sema &S, InitListExpr *From, QualType ToType, // mention initializer lists in any way. So we go by what list- // initialization would do and try to extrapolate from that. - QualType T1 = ToType->getAs()->getPointeeType(); + QualType T1 = ToType->castAs()->getPointeeType(); // If the initializer list has a single element that is reference-related // to the parameter type, we initialize the reference from that. @@ -5227,7 +5227,7 @@ Sema::PerformObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method) { QualType FromRecordType, DestType; QualType ImplicitParamRecordType = - Method->getThisType()->getAs()->getPointeeType(); + Method->getThisType()->castAs()->getPointeeType(); Expr::Classification FromClassification; if (const PointerType *PT = From->getType()->getAs()) { @@ -7014,7 +7014,7 @@ void Sema::AddConversionCandidate( if (const PointerType *FromPtrType = ImplicitParamType->getAs()) ImplicitParamType = FromPtrType->getPointeeType(); CXXRecordDecl *ConversionContext - = cast(ImplicitParamType->getAs()->getDecl()); + = cast(ImplicitParamType->castAs()->getDecl()); Candidate.Conversions[0] = TryObjectArgumentInitialization( *this, CandidateSet.getLocation(), From->getType(), @@ -8774,7 +8774,7 @@ public: Enum = CandidateTypes[ArgIdx].enumeration_begin(), EnumEnd = CandidateTypes[ArgIdx].enumeration_end(); Enum != EnumEnd; ++Enum) { - if (!(*Enum)->getAs()->getDecl()->isScoped()) + if (!(*Enum)->castAs()->getDecl()->isScoped()) continue; if (!AddedTypes.insert(S.Context.getCanonicalType(*Enum)).second) @@ -10799,12 +10799,12 @@ static void CompleteNonViableCandidate(Sema &S, OverloadCandidate *Cand, = Cand->Surrogate->getConversionType().getNonReferenceType(); if (const PointerType *ConvPtrType = ConvType->getAs()) ConvType = ConvPtrType->getPointeeType(); - ParamTypes = ConvType->getAs()->getParamTypes(); + ParamTypes = ConvType->castAs()->getParamTypes(); // Conversion 0 is 'this', which doesn't have a corresponding argument. ConvIdx = 1; } else if (Cand->Function) { ParamTypes = - Cand->Function->getType()->getAs()->getParamTypes(); + Cand->Function->getType()->castAs()->getParamTypes(); if (isa(Cand->Function) && !isa(Cand->Function)) { // Conversion 0 is 'this', which doesn't have a corresponding argument.