Author: gbiv Date: Wed Feb 28 21:43:23 2018 New Revision: 326416 URL: http://llvm.org/viewvc/llvm-project?rev=326416&view=rev Log: Remove redundant casts. NFC
So I wrote a clang-tidy check to lint out redundant `isa`, `cast`, and `dyn_cast`s for fun. This is a portion of what it found for clang; I plan to do similar cleanups in LLVM and other subprojects when I find time. Because of the volume of changes, I explicitly avoided making any change that wasn't highly local and obviously correct to me (e.g. we still have a number of foo(cast<Bar>(baz)) that I didn't touch, since overloading is a thing and the cast<Bar> did actually change the type -- just up the class hierarchy). I also tried to leave the types we were cast<>ing to somewhere nearby, in cases where it wasn't locally obvious what we were dealing with before. Modified: cfe/trunk/include/clang/AST/DeclCXX.h cfe/trunk/include/clang/AST/Expr.h cfe/trunk/include/clang/AST/ExprObjC.h cfe/trunk/lib/AST/ASTContext.cpp cfe/trunk/lib/AST/CXXInheritance.cpp cfe/trunk/lib/AST/Decl.cpp cfe/trunk/lib/AST/DeclCXX.cpp cfe/trunk/lib/AST/DeclPrinter.cpp cfe/trunk/lib/AST/Expr.cpp cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/lib/AST/ItaniumMangle.cpp cfe/trunk/lib/AST/MicrosoftCXXABI.cpp cfe/trunk/lib/AST/MicrosoftMangle.cpp cfe/trunk/lib/AST/RecordLayoutBuilder.cpp cfe/trunk/lib/AST/TemplateBase.cpp cfe/trunk/lib/AST/Type.cpp cfe/trunk/lib/CodeGen/CGCoroutine.cpp cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/lib/CodeGen/CGObjCGNU.cpp cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp cfe/trunk/lib/CodeGen/CodeGenFunction.cpp cfe/trunk/lib/CodeGen/CodeGenModule.cpp cfe/trunk/lib/CodeGen/CodeGenTypes.cpp cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp cfe/trunk/lib/Frontend/ASTUnit.cpp cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/lib/Sema/SemaCodeComplete.cpp cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaDeclAttr.cpp cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/lib/Sema/SemaDeclObjC.cpp cfe/trunk/lib/Sema/SemaExceptionSpec.cpp cfe/trunk/lib/Sema/SemaExprCXX.cpp cfe/trunk/lib/Sema/SemaObjCProperty.cpp cfe/trunk/lib/Sema/SemaOpenMP.cpp cfe/trunk/lib/Sema/SemaTemplate.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/lib/Serialization/ASTReaderDecl.cpp cfe/trunk/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Modified: cfe/trunk/include/clang/AST/DeclCXX.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/DeclCXX.h (original) +++ cfe/trunk/include/clang/AST/DeclCXX.h Wed Feb 28 21:43:23 2018 @@ -2062,8 +2062,7 @@ public: bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); } bool isVirtual() const { - CXXMethodDecl *CD = - cast<CXXMethodDecl>(const_cast<CXXMethodDecl*>(this)->getCanonicalDecl()); + CXXMethodDecl *CD = const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); // Member function is virtual if it is marked explicitly so, or if it is // declared in __interface -- then it is automatically pure virtual. Modified: cfe/trunk/include/clang/AST/Expr.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/Expr.h (original) +++ cfe/trunk/include/clang/AST/Expr.h Wed Feb 28 21:43:23 2018 @@ -2169,19 +2169,19 @@ public: void setRHS(Expr *E) { SubExprs[RHS] = E; } Expr *getBase() { - return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); + return getRHS()->getType()->isIntegerType() ? getLHS() : getRHS(); } const Expr *getBase() const { - return cast<Expr>(getRHS()->getType()->isIntegerType() ? getLHS():getRHS()); + return getRHS()->getType()->isIntegerType() ? getLHS() : getRHS(); } Expr *getIdx() { - return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); + return getRHS()->getType()->isIntegerType() ? getRHS() : getLHS(); } const Expr *getIdx() const { - return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); + return getRHS()->getType()->isIntegerType() ? getRHS() : getLHS(); } SourceLocation getLocStart() const LLVM_READONLY { Modified: cfe/trunk/include/clang/AST/ExprObjC.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprObjC.h?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/ExprObjC.h (original) +++ cfe/trunk/include/clang/AST/ExprObjC.h Wed Feb 28 21:43:23 2018 @@ -212,11 +212,11 @@ public: /// getElement - Return the Element at the specified index. Expr *getElement(unsigned Index) { assert((Index < NumElements) && "Arg access out of range!"); - return cast<Expr>(getElements()[Index]); + return getElements()[Index]; } const Expr *getElement(unsigned Index) const { assert((Index < NumElements) && "Arg access out of range!"); - return cast<Expr>(getElements()[Index]); + return getElements()[Index]; } ObjCMethodDecl *getArrayWithObjectsMethod() const { Modified: cfe/trunk/lib/AST/ASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/AST/ASTContext.cpp (original) +++ cfe/trunk/lib/AST/ASTContext.cpp Wed Feb 28 21:43:23 2018 @@ -2398,7 +2398,7 @@ Expr *ASTContext::getBlockVarCopyInits(c "getBlockVarCopyInits - not __block var"); llvm::DenseMap<const VarDecl*, Expr*>::iterator I = BlockVarCopyInits.find(VD); - return (I != BlockVarCopyInits.end()) ? cast<Expr>(I->second) : nullptr; + return (I != BlockVarCopyInits.end()) ? I->second : nullptr; } /// \brief Set the copy inialization expression of a block var decl. @@ -6575,7 +6575,7 @@ void ASTContext::getObjCEncodingForTypeI SmallVector<const ObjCIvarDecl*, 32> Ivars; DeepCollectObjCIvars(OI, true, Ivars); for (unsigned i = 0, e = Ivars.size(); i != e; ++i) { - const FieldDecl *Field = cast<FieldDecl>(Ivars[i]); + const FieldDecl *Field = Ivars[i]; if (Field->isBitField()) getObjCEncodingForTypeImpl(Field->getType(), S, false, true, Field); else @@ -6636,7 +6636,7 @@ void ASTContext::getObjCEncodingForTypeI SmallVector<const ObjCIvarDecl*, 32> Ivars; DeepCollectObjCIvars(OI, true, Ivars); for (unsigned i = 0, e = Ivars.size(); i != e; ++i) { - if (cast<FieldDecl>(Ivars[i]) == FD) { + if (Ivars[i] == FD) { S += '{'; S += OI->getObjCRuntimeNameAsString(); S += '}'; Modified: cfe/trunk/lib/AST/CXXInheritance.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CXXInheritance.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/AST/CXXInheritance.cpp (original) +++ cfe/trunk/lib/AST/CXXInheritance.cpp Wed Feb 28 21:43:23 2018 @@ -637,8 +637,7 @@ void FinalOverriderCollector::Collect(co OMEnd = BaseOverriders->end(); OM != OMEnd; ++OM) { - const CXXMethodDecl *CanonOM - = cast<CXXMethodDecl>(OM->first->getCanonicalDecl()); + const CXXMethodDecl *CanonOM = OM->first->getCanonicalDecl(); Overriders[CanonOM].add(OM->second); } } @@ -649,7 +648,7 @@ void FinalOverriderCollector::Collect(co if (!M->isVirtual()) continue; - CXXMethodDecl *CanonM = cast<CXXMethodDecl>(M->getCanonicalDecl()); + CXXMethodDecl *CanonM = M->getCanonicalDecl(); using OverriddenMethodsRange = llvm::iterator_range<CXXMethodDecl::method_iterator>; OverriddenMethodsRange OverriddenMethods = CanonM->overridden_methods(); Modified: cfe/trunk/lib/AST/Decl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/AST/Decl.cpp (original) +++ cfe/trunk/lib/AST/Decl.cpp Wed Feb 28 21:43:23 2018 @@ -312,12 +312,12 @@ LinkageComputer::getLVForTemplateArgumen LV.merge(getLVForType(*Arg.getAsType(), computation)); continue; - case TemplateArgument::Declaration: - if (const auto *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) { - assert(!usesTypeVisibility(ND)); - LV.merge(getLVForDecl(ND, computation)); - } + case TemplateArgument::Declaration: { + const NamedDecl *ND = Arg.getAsDecl(); + assert(!usesTypeVisibility(ND)); + LV.merge(getLVForDecl(ND, computation)); continue; + } case TemplateArgument::NullPtr: LV.merge(getTypeLinkageAndVisibility(Arg.getNullPtrType())); Modified: cfe/trunk/lib/AST/DeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/AST/DeclCXX.cpp (original) +++ cfe/trunk/lib/AST/DeclCXX.cpp Wed Feb 28 21:43:23 2018 @@ -1827,9 +1827,10 @@ CXXMethodDecl *CXXMethodDecl::getDevirtu // We can devirtualize calls on an object accessed by a class member access // expression, since by C++11 [basic.life]p6 we know that it can't refer to // a derived class object constructed in the same location. - if (const MemberExpr *ME = dyn_cast<MemberExpr>(Base)) - if (const ValueDecl *VD = dyn_cast<ValueDecl>(ME->getMemberDecl())) - return VD->getType()->isRecordType() ? DevirtualizedMethod : nullptr; + if (const MemberExpr *ME = dyn_cast<MemberExpr>(Base)) { + const ValueDecl *VD = ME->getMemberDecl(); + return VD->getType()->isRecordType() ? DevirtualizedMethod : nullptr; + } // Likewise for calls on an object accessed by a (non-reference) pointer to // member access. Modified: cfe/trunk/lib/AST/DeclPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/AST/DeclPrinter.cpp (original) +++ cfe/trunk/lib/AST/DeclPrinter.cpp Wed Feb 28 21:43:23 2018 @@ -1527,7 +1527,7 @@ void DeclPrinter::VisitOMPThreadPrivateD E = D->varlist_end(); I != E; ++I) { Out << (I == D->varlist_begin() ? '(' : ','); - NamedDecl *ND = cast<NamedDecl>(cast<DeclRefExpr>(*I)->getDecl()); + NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl(); ND->printQualifiedName(Out); } Out << ")"; Modified: cfe/trunk/lib/AST/Expr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/AST/Expr.cpp (original) +++ cfe/trunk/lib/AST/Expr.cpp Wed Feb 28 21:43:23 2018 @@ -3458,10 +3458,11 @@ FieldDecl *Expr::getSourceBitField() { if (Field->isBitField()) return Field; - if (ObjCIvarRefExpr *IvarRef = dyn_cast<ObjCIvarRefExpr>(E)) - if (FieldDecl *Ivar = dyn_cast<FieldDecl>(IvarRef->getDecl())) - if (Ivar->isBitField()) - return Ivar; + if (ObjCIvarRefExpr *IvarRef = dyn_cast<ObjCIvarRefExpr>(E)) { + FieldDecl *Ivar = IvarRef->getDecl(); + if (Ivar->isBitField()) + return Ivar; + } if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) { if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl())) Modified: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Feb 28 21:43:23 2018 @@ -10433,7 +10433,7 @@ static ICEDiag CheckICE(const Expr* E, c case Expr::DeclRefExprClass: { if (isa<EnumConstantDecl>(cast<DeclRefExpr>(E)->getDecl())) return NoDiag(); - const ValueDecl *D = dyn_cast<ValueDecl>(cast<DeclRefExpr>(E)->getDecl()); + const ValueDecl *D = cast<DeclRefExpr>(E)->getDecl(); if (Ctx.getLangOpts().CPlusPlus && D && IsConstNonVolatile(D->getType())) { // Parameter variables are never constants. Without this check, Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/AST/ItaniumMangle.cpp (original) +++ cfe/trunk/lib/AST/ItaniumMangle.cpp Wed Feb 28 21:43:23 2018 @@ -1324,8 +1324,7 @@ void CXXNameMangler::mangleUnqualifiedNa if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) { // We must have an anonymous union or struct declaration. - const RecordDecl *RD = - cast<RecordDecl>(VD->getType()->getAs<RecordType>()->getDecl()); + const RecordDecl *RD = VD->getType()->getAs<RecordType>()->getDecl(); // Itanium C++ ABI 5.1.2: // Modified: cfe/trunk/lib/AST/MicrosoftCXXABI.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftCXXABI.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/AST/MicrosoftCXXABI.cpp (original) +++ cfe/trunk/lib/AST/MicrosoftCXXABI.cpp Wed Feb 28 21:43:23 2018 @@ -106,7 +106,7 @@ public: void addTypedefNameForUnnamedTagDecl(TagDecl *TD, TypedefNameDecl *DD) override { TD = TD->getCanonicalDecl(); - DD = cast<TypedefNameDecl>(DD->getCanonicalDecl()); + DD = DD->getCanonicalDecl(); TypedefNameDecl *&I = UnnamedTagDeclToTypedefNameDecl[TD]; if (!I) I = DD; Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original) +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Wed Feb 28 21:43:23 2018 @@ -1368,7 +1368,7 @@ void MicrosoftCXXNameMangler::mangleTemp break; } case TemplateArgument::Declaration: { - const NamedDecl *ND = cast<NamedDecl>(TA.getAsDecl()); + const NamedDecl *ND = TA.getAsDecl(); if (isa<FieldDecl>(ND) || isa<IndirectFieldDecl>(ND)) { mangleMemberDataPointer( cast<CXXRecordDecl>(ND->getDeclContext())->getMostRecentDecl(), Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original) +++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Wed Feb 28 21:43:23 2018 @@ -3016,7 +3016,7 @@ const CXXMethodDecl *ASTContext::getCurr return nullptr; assert(RD->getDefinition() && "Cannot get key function for forward decl!"); - RD = cast<CXXRecordDecl>(RD->getDefinition()); + RD = RD->getDefinition(); // Beware: // 1) computing the key function might trigger deserialization, which might Modified: cfe/trunk/lib/AST/TemplateBase.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TemplateBase.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/AST/TemplateBase.cpp (original) +++ cfe/trunk/lib/AST/TemplateBase.cpp Wed Feb 28 21:43:23 2018 @@ -406,7 +406,7 @@ void TemplateArgument::print(const Print } case Declaration: { - NamedDecl *ND = cast<NamedDecl>(getAsDecl()); + NamedDecl *ND = getAsDecl(); Out << '&'; if (ND->getDeclName()) { // FIXME: distinguish between pointer and reference args? Modified: cfe/trunk/lib/AST/Type.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/AST/Type.cpp (original) +++ cfe/trunk/lib/AST/Type.cpp Wed Feb 28 21:43:23 2018 @@ -1123,57 +1123,56 @@ QualType QualType::substObjCTypeArgs( // Replace an Objective-C type parameter reference with the corresponding // type argument. if (const auto *OTPTy = dyn_cast<ObjCTypeParamType>(splitType.Ty)) { - if (auto *typeParam = dyn_cast<ObjCTypeParamDecl>(OTPTy->getDecl())) { - // If we have type arguments, use them. - if (!typeArgs.empty()) { - QualType argType = typeArgs[typeParam->getIndex()]; - if (OTPTy->qual_empty()) - return ctx.getQualifiedType(argType, splitType.Quals); - - // Apply protocol lists if exists. - bool hasError; - SmallVector<ObjCProtocolDecl*, 8> protocolsVec; - protocolsVec.append(OTPTy->qual_begin(), - OTPTy->qual_end()); - ArrayRef<ObjCProtocolDecl *> protocolsToApply = protocolsVec; - QualType resultTy = ctx.applyObjCProtocolQualifiers(argType, - protocolsToApply, hasError, true/*allowOnPointerType*/); + ObjCTypeParamDecl *typeParam = OTPTy->getDecl(); + // If we have type arguments, use them. + if (!typeArgs.empty()) { + QualType argType = typeArgs[typeParam->getIndex()]; + if (OTPTy->qual_empty()) + return ctx.getQualifiedType(argType, splitType.Quals); + + // Apply protocol lists if exists. + bool hasError; + SmallVector<ObjCProtocolDecl*, 8> protocolsVec; + protocolsVec.append(OTPTy->qual_begin(), + OTPTy->qual_end()); + ArrayRef<ObjCProtocolDecl *> protocolsToApply = protocolsVec; + QualType resultTy = ctx.applyObjCProtocolQualifiers(argType, + protocolsToApply, hasError, true/*allowOnPointerType*/); - return ctx.getQualifiedType(resultTy, splitType.Quals); - } + return ctx.getQualifiedType(resultTy, splitType.Quals); + } - switch (context) { - case ObjCSubstitutionContext::Ordinary: - case ObjCSubstitutionContext::Parameter: - case ObjCSubstitutionContext::Superclass: - // Substitute the bound. + switch (context) { + case ObjCSubstitutionContext::Ordinary: + case ObjCSubstitutionContext::Parameter: + case ObjCSubstitutionContext::Superclass: + // Substitute the bound. + return ctx.getQualifiedType(typeParam->getUnderlyingType(), + splitType.Quals); + + case ObjCSubstitutionContext::Result: + case ObjCSubstitutionContext::Property: { + // Substitute the __kindof form of the underlying type. + const auto *objPtr = typeParam->getUnderlyingType() + ->castAs<ObjCObjectPointerType>(); + + // __kindof types, id, and Class don't need an additional + // __kindof. + if (objPtr->isKindOfType() || objPtr->isObjCIdOrClassType()) return ctx.getQualifiedType(typeParam->getUnderlyingType(), splitType.Quals); - case ObjCSubstitutionContext::Result: - case ObjCSubstitutionContext::Property: { - // Substitute the __kindof form of the underlying type. - const auto *objPtr = typeParam->getUnderlyingType() - ->castAs<ObjCObjectPointerType>(); - - // __kindof types, id, and Class don't need an additional - // __kindof. - if (objPtr->isKindOfType() || objPtr->isObjCIdOrClassType()) - return ctx.getQualifiedType(typeParam->getUnderlyingType(), - splitType.Quals); - - // Add __kindof. - const auto *obj = objPtr->getObjectType(); - QualType resultTy = ctx.getObjCObjectType(obj->getBaseType(), - obj->getTypeArgsAsWritten(), - obj->getProtocols(), - /*isKindOf=*/true); - - // Rebuild object pointer type. - resultTy = ctx.getObjCObjectPointerType(resultTy); - return ctx.getQualifiedType(resultTy, splitType.Quals); - } - } + // Add __kindof. + const auto *obj = objPtr->getObjectType(); + QualType resultTy = ctx.getObjCObjectType(obj->getBaseType(), + obj->getTypeArgsAsWritten(), + obj->getProtocols(), + /*isKindOf=*/true); + + // Rebuild object pointer type. + resultTy = ctx.getObjCObjectPointerType(resultTy); + return ctx.getQualifiedType(resultTy, splitType.Quals); + } } } @@ -1593,7 +1592,7 @@ CXXRecordDecl *Type::getAsCXXRecordDecl( TagDecl *Type::getAsTagDecl() const { if (const auto *TT = getAs<TagType>()) - return cast<TagDecl>(TT->getDecl()); + return TT->getDecl(); if (const auto *Injected = getAs<InjectedClassNameType>()) return Injected->getDecl(); Modified: cfe/trunk/lib/CodeGen/CGCoroutine.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCoroutine.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGCoroutine.cpp (original) +++ cfe/trunk/lib/CodeGen/CGCoroutine.cpp Wed Feb 28 21:43:23 2018 @@ -315,7 +315,7 @@ namespace { GetParamRef Visitor; Visitor.Visit(const_cast<Expr*>(InitExpr)); assert(Visitor.Expr); - auto *DREOrig = cast<DeclRefExpr>(Visitor.Expr); + DeclRefExpr *DREOrig = Visitor.Expr; auto *PD = DREOrig->getDecl(); auto it = LocalDeclMap.find(PD); Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Feb 28 21:43:23 2018 @@ -3036,7 +3036,7 @@ llvm::DISubprogram *CGDebugInfo::getFunc !FD->isExternallyVisible(), /* isDefinition = */ false, 0, Flags, CGM.getLangOpts().Optimize, TParamsArray.get(), getFunctionDeclaration(FD)); - const auto *CanonDecl = cast<FunctionDecl>(FD->getCanonicalDecl()); + const FunctionDecl *CanonDecl = FD->getCanonicalDecl(); FwdDeclReplaceMap.emplace_back(std::piecewise_construct, std::make_tuple(CanonDecl), std::make_tuple(SP)); @@ -3576,7 +3576,7 @@ llvm::DILocalVariable *CGDebugInfo::Emit } else if (const auto *RT = dyn_cast<RecordType>(VD->getType())) { // If VD is an anonymous union then Storage represents value for // all union fields. - const auto *RD = cast<RecordDecl>(RT->getDecl()); + const RecordDecl *RD = RT->getDecl(); if (RD->isUnion() && RD->isAnonymousStructOrUnion()) { // GDB has trouble finding local variables in anonymous unions, so we emit // artifical local variables for each of the members. Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original) +++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Feb 28 21:43:23 2018 @@ -80,8 +80,7 @@ public: if (!Function) { if (!FunctionName) return nullptr; - Function = - cast<llvm::Constant>(CGM->CreateRuntimeFunction(FTy, FunctionName)); + Function = CGM->CreateRuntimeFunction(FTy, FunctionName); } return Function; } Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original) +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed Feb 28 21:43:23 2018 @@ -3682,9 +3682,7 @@ void CGOpenMPRuntime::loadOffloadInfoMet if (!MD) return; - for (auto I : MD->operands()) { - llvm::MDNode *MN = cast<llvm::MDNode>(I); - + for (llvm::MDNode *MN : MD->operands()) { auto getMDInt = [&](unsigned Idx) { llvm::ConstantAsMetadata *V = cast<llvm::ConstantAsMetadata>(MN->getOperand(Idx)); @@ -6788,7 +6786,7 @@ public: const ValueDecl *VD = Cap->capturesThis() ? nullptr - : cast<ValueDecl>(Cap->getCapturedVar()->getCanonicalDecl()); + : Cap->getCapturedVar()->getCanonicalDecl(); // If this declaration appears in a is_device_ptr clause we just have to // pass the pointer by value. If it is a reference to a declaration, we just Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original) +++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Wed Feb 28 21:43:23 2018 @@ -789,8 +789,7 @@ CGRecordLayout *CodeGenTypes::ComputeRec } // Verify that the LLVM and AST field offsets agree. - llvm::StructType *ST = - dyn_cast<llvm::StructType>(RL->getLLVMType()); + llvm::StructType *ST = RL->getLLVMType(); const llvm::StructLayout *SL = getDataLayout().getStructLayout(ST); const ASTRecordLayout &AST_RL = getContext().getASTRecordLayout(D); Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original) +++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Wed Feb 28 21:43:23 2018 @@ -128,11 +128,9 @@ class OMPLoopScope : public CodeGenFunct }); } (void)PreCondScope.Privatize(); - if (auto *LD = dyn_cast<OMPLoopDirective>(&S)) { - if (auto *PreInits = cast_or_null<DeclStmt>(LD->getPreInits())) { - for (const auto *I : PreInits->decls()) - CGF.EmitVarDecl(cast<VarDecl>(*I)); - } + if (auto *PreInits = cast_or_null<DeclStmt>(S.getPreInits())) { + for (const auto *I : PreInits->decls()) + CGF.EmitVarDecl(cast<VarDecl>(*I)); } } Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Wed Feb 28 21:43:23 2018 @@ -1118,8 +1118,7 @@ void CodeGenFunction::StartFunction(Glob // may have a static invoker function, which may call this operator with // a null 'this' pointer. if (isLambdaCallOperator(MD) && - cast<CXXRecordDecl>(MD->getParent())->getLambdaCaptureDefault() == - LCD_None) + MD->getParent()->getLambdaCaptureDefault() == LCD_None) SkippedChecks.set(SanitizerKind::Null, true); EmitTypeCheck(isa<CXXConstructorDecl>(MD) ? TCK_ConstructorCall Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Feb 28 21:43:23 2018 @@ -2814,7 +2814,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(Str GetAddrOfGlobalVar(D, InitType, IsForDefinition)); // Erase the old global, since it is no longer used. - cast<llvm::GlobalValue>(GV)->eraseFromParent(); + GV->eraseFromParent(); GV = NewGV; } else { GV->setInitializer(Init); Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Wed Feb 28 21:43:23 2018 @@ -767,7 +767,7 @@ bool CodeGenTypes::isZeroInitializable(Q // Records are non-zero-initializable if they contain any // non-zero-initializable subobjects. if (const RecordType *RT = T->getAs<RecordType>()) { - auto RD = cast<RecordDecl>(RT->getDecl()); + const RecordDecl *RD = RT->getDecl(); return isZeroInitializable(RD); } Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original) +++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Wed Feb 28 21:43:23 2018 @@ -1693,8 +1693,7 @@ llvm::Value *ItaniumCXXABI::EmitVirtualD const CGFunctionInfo *FInfo = &CGM.getTypes().arrangeCXXStructorDeclaration( Dtor, getFromDtorType(DtorType)); - auto *Ty = - cast<llvm::FunctionType>(CGF.CGM.getTypes().GetFunctionType(*FInfo)); + llvm::FunctionType *Ty = CGF.CGM.getTypes().GetFunctionType(*FInfo); CGCallee Callee = CGCallee::forVirtual(CE, GlobalDecl(Dtor, DtorType), This, Ty); Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original) +++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Wed Feb 28 21:43:23 2018 @@ -1886,8 +1886,7 @@ llvm::Value *MicrosoftCXXABI::EmitVirtua GlobalDecl GD(Dtor, Dtor_Deleting); const CGFunctionInfo *FInfo = &CGM.getTypes().arrangeCXXStructorDeclaration( Dtor, StructorType::Deleting); - auto *Ty = - cast<llvm::FunctionType>(CGF.CGM.getTypes().GetFunctionType(*FInfo)); + llvm::FunctionType *Ty = CGF.CGM.getTypes().GetFunctionType(*FInfo); CGCallee Callee = CGCallee::forVirtual(CE, GD, This, Ty); ASTContext &Context = getContext(); Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original) +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Wed Feb 28 21:43:23 2018 @@ -237,7 +237,7 @@ static unsigned getDeclShowContexts(cons IsNestedNameSpecifier = false; if (isa<UsingShadowDecl>(ND)) - ND = dyn_cast<NamedDecl>(ND->getUnderlyingDecl()); + ND = ND->getUnderlyingDecl(); if (!ND) return 0; Modified: cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp (original) +++ cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp Wed Feb 28 21:43:23 2018 @@ -1714,7 +1714,7 @@ Stmt *RewriteModernObjC::RewriteObjCForC else { DeclRefExpr *DR = cast<DeclRefExpr>(S->getElement()); elementName = DR->getDecl()->getName(); - ValueDecl *VD = cast<ValueDecl>(DR->getDecl()); + ValueDecl *VD = DR->getDecl(); if (VD->getType()->isObjCQualifiedIdType() || VD->getType()->isObjCQualifiedInterfaceType()) // Simply use 'id' for all qualified types. Modified: cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp (original) +++ cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp Wed Feb 28 21:43:23 2018 @@ -1502,7 +1502,7 @@ Stmt *RewriteObjC::RewriteObjCForCollect else { DeclRefExpr *DR = cast<DeclRefExpr>(S->getElement()); elementName = DR->getDecl()->getName(); - ValueDecl *VD = cast<ValueDecl>(DR->getDecl()); + ValueDecl *VD = DR->getDecl(); if (VD->getType()->isObjCQualifiedIdType() || VD->getType()->isObjCQualifiedInterfaceType()) // Simply use 'id' for all qualified types. Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Feb 28 21:43:23 2018 @@ -10985,9 +10985,9 @@ void Sema::CheckArrayAccess(const Expr * const NamedDecl *ND = nullptr; if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(BaseExpr)) - ND = dyn_cast<NamedDecl>(DRE->getDecl()); + ND = DRE->getDecl(); if (const MemberExpr *ME = dyn_cast<MemberExpr>(BaseExpr)) - ND = dyn_cast<NamedDecl>(ME->getMemberDecl()); + ND = ME->getMemberDecl(); if (index.isUnsigned() || !index.isNegative()) { llvm::APInt size = ArrayTy->getSize(); @@ -11070,9 +11070,9 @@ void Sema::CheckArrayAccess(const Expr * dyn_cast<ArraySubscriptExpr>(BaseExpr)) BaseExpr = ASE->getBase()->IgnoreParenCasts(); if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(BaseExpr)) - ND = dyn_cast<NamedDecl>(DRE->getDecl()); + ND = DRE->getDecl(); if (const MemberExpr *ME = dyn_cast<MemberExpr>(BaseExpr)) - ND = dyn_cast<NamedDecl>(ME->getMemberDecl()); + ND = ME->getMemberDecl(); } if (ND) Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Feb 28 21:43:23 2018 @@ -675,7 +675,7 @@ SimplifiedTypeClass clang::getSimplified /// \brief Get the type that a given expression will have if this declaration /// is used as an expression in its "typical" code-completion form. QualType clang::getDeclUsageType(ASTContext &C, const NamedDecl *ND) { - ND = cast<NamedDecl>(ND->getUnderlyingDecl()); + ND = ND->getUnderlyingDecl(); if (const TypeDecl *Type = dyn_cast<TypeDecl>(ND)) return C.getTypeDeclType(Type); @@ -1074,7 +1074,7 @@ void ResultBuilder::ExitScope() { /// \brief Determines whether this given declaration will be found by /// ordinary name lookup. bool ResultBuilder::IsOrdinaryName(const NamedDecl *ND) const { - ND = cast<NamedDecl>(ND->getUnderlyingDecl()); + ND = ND->getUnderlyingDecl(); // If name lookup finds a local extern declaration, then we are in a // context where it behaves like an ordinary name. @@ -1092,7 +1092,7 @@ bool ResultBuilder::IsOrdinaryName(const /// \brief Determines whether this given declaration will be found by /// ordinary name lookup but is not a type name. bool ResultBuilder::IsOrdinaryNonTypeName(const NamedDecl *ND) const { - ND = cast<NamedDecl>(ND->getUnderlyingDecl()); + ND = ND->getUnderlyingDecl(); if (isa<TypeDecl>(ND)) return false; // Objective-C interfaces names are not filtered by this method because they @@ -1128,7 +1128,7 @@ bool ResultBuilder::IsIntegralConstantVa /// \brief Determines whether this given declaration will be found by /// ordinary name lookup. bool ResultBuilder::IsOrdinaryNonValueName(const NamedDecl *ND) const { - ND = cast<NamedDecl>(ND->getUnderlyingDecl()); + ND = ND->getUnderlyingDecl(); unsigned IDNS = Decl::IDNS_Ordinary | Decl::IDNS_LocalExtern; if (SemaRef.getLangOpts().CPlusPlus) @@ -7453,7 +7453,7 @@ void Sema::CodeCompleteObjCMethodDecl(Sc Decl *IDecl = nullptr; if (CurContext->isObjCContainer()) { ObjCContainerDecl *OCD = dyn_cast<ObjCContainerDecl>(CurContext); - IDecl = cast<Decl>(OCD); + IDecl = OCD; } // Determine where we should start searching for methods. ObjCContainerDecl *SearchDecl = nullptr; Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Feb 28 21:43:23 2018 @@ -1519,9 +1519,7 @@ static bool IsDisallowedCopyOrAssign(con if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(D)) return CD->isCopyConstructor(); - if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D)) - return Method->isCopyAssignmentOperator(); - return false; + return D->isCopyAssignmentOperator(); } // We need this to handle @@ -6887,9 +6885,9 @@ NamedDecl *Sema::ActOnVariableDeclarator } if (D.isRedeclaration() && !Previous.empty()) { - checkDLLAttributeRedeclaration( - *this, dyn_cast<NamedDecl>(Previous.getRepresentativeDecl()), NewVD, - IsMemberSpecialization, D.isFunctionDefinition()); + NamedDecl *Prev = Previous.getRepresentativeDecl(); + checkDLLAttributeRedeclaration(*this, Prev, NewVD, IsMemberSpecialization, + D.isFunctionDefinition()); } if (NewTemplate) { @@ -9039,10 +9037,11 @@ Sema::ActOnFunctionDeclarator(Scope *S, NewFD->setRangeEnd(D.getSourceRange().getEnd()); if (D.isRedeclaration() && !Previous.empty()) { - checkDLLAttributeRedeclaration( - *this, dyn_cast<NamedDecl>(Previous.getRepresentativeDecl()), NewFD, - isMemberSpecialization || isFunctionTemplateSpecialization, - D.isFunctionDefinition()); + NamedDecl *Prev = Previous.getRepresentativeDecl(); + checkDLLAttributeRedeclaration(*this, Prev, NewFD, + isMemberSpecialization || + isFunctionTemplateSpecialization, + D.isFunctionDefinition()); } if (getLangOpts().CUDA) { Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Feb 28 21:43:23 2018 @@ -113,7 +113,7 @@ static SourceRange getFunctionOrMethodPa static QualType getFunctionOrMethodResultType(const Decl *D) { if (const FunctionType *FnTy = D->getFunctionType()) - return cast<FunctionType>(FnTy)->getReturnType(); + return FnTy->getReturnType(); return cast<ObjCMethodDecl>(D)->getReturnType(); } Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Feb 28 21:43:23 2018 @@ -9036,7 +9036,7 @@ Decl *Sema::ActOnUsingDirective(Scope *S // Find enclosing context containing both using-directive and // nominated namespace. - DeclContext *CommonAncestor = cast<DeclContext>(NS); + DeclContext *CommonAncestor = NS; while (CommonAncestor && !CommonAncestor->Encloses(CurContext)) CommonAncestor = CommonAncestor->getParent(); @@ -14536,7 +14536,7 @@ void Sema::MarkVTableUsed(SourceLocation // Try to insert this class into the map. LoadExternalVTableUses(); - Class = cast<CXXRecordDecl>(Class->getCanonicalDecl()); + Class = Class->getCanonicalDecl(); std::pair<llvm::DenseMap<CXXRecordDecl *, bool>::iterator, bool> Pos = VTablesUsed.insert(std::make_pair(Class, DefinitionRequired)); if (!Pos.second) { @@ -14648,7 +14648,7 @@ bool Sema::DefineUsedVTables() { // vtable for this class is required. DefinedAnything = true; MarkVirtualMembersReferenced(Loc, Class); - CXXRecordDecl *Canonical = cast<CXXRecordDecl>(Class->getCanonicalDecl()); + CXXRecordDecl *Canonical = Class->getCanonicalDecl(); if (VTablesUsed[Canonical]) Consumer.HandleVTable(Class); Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Feb 28 21:43:23 2018 @@ -3865,9 +3865,9 @@ Decl *Sema::ActOnAtEnd(Scope *S, SourceR assert(AtEnd.isValid() && "Invalid location for '@end'"); - ObjCContainerDecl *OCD = dyn_cast<ObjCContainerDecl>(CurContext); - Decl *ClassDecl = cast<Decl>(OCD); - + auto *OCD = cast<ObjCContainerDecl>(CurContext); + Decl *ClassDecl = OCD; + bool isInterfaceDeclKind = isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl) || isa<ObjCProtocolDecl>(ClassDecl); @@ -4521,8 +4521,7 @@ Decl *Sema::ActOnMethodDeclaration( Diag(MethodLoc, diag::err_missing_method_context); return nullptr; } - ObjCContainerDecl *OCD = dyn_cast<ObjCContainerDecl>(CurContext); - Decl *ClassDecl = cast<Decl>(OCD); + Decl *ClassDecl = cast<ObjCContainerDecl>(CurContext); QualType resultDeclType; bool HasRelatedResultType = false; @@ -4771,7 +4770,7 @@ void Sema::ActOnDefs(Scope *S, Decl *Tag Context.DeepCollectObjCIvars(Class, true, Ivars); // For each ivar, create a fresh ObjCAtDefsFieldDecl. for (unsigned i = 0; i < Ivars.size(); i++) { - const FieldDecl* ID = cast<FieldDecl>(Ivars[i]); + const FieldDecl* ID = Ivars[i]; RecordDecl *Record = dyn_cast<RecordDecl>(TagD); Decl *FD = ObjCAtDefsFieldDecl::Create(Context, Record, /*FIXME: StartL=*/ID->getLocation(), @@ -4786,7 +4785,7 @@ void Sema::ActOnDefs(Scope *S, Decl *Tag D != Decls.end(); ++D) { FieldDecl *FD = cast<FieldDecl>(*D); if (getLangOpts().CPlusPlus) - PushOnScopeChains(cast<FieldDecl>(FD), S); + PushOnScopeChains(FD, S); else if (RecordDecl *Record = dyn_cast<RecordDecl>(TagD)) Record->addDecl(FD); } Modified: cfe/trunk/lib/Sema/SemaExceptionSpec.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExceptionSpec.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExceptionSpec.cpp (original) +++ cfe/trunk/lib/Sema/SemaExceptionSpec.cpp Wed Feb 28 21:43:23 2018 @@ -203,8 +203,8 @@ Sema::UpdateExceptionSpec(FunctionDecl * if (auto *Listener = getASTMutationListener()) Listener->ResolvedExceptionSpec(FD); - for (auto *Redecl : FD->redecls()) - Context.adjustExceptionSpec(cast<FunctionDecl>(Redecl), ESI); + for (FunctionDecl *Redecl : FD->redecls()) + Context.adjustExceptionSpec(Redecl, ESI); } static bool CheckEquivalentExceptionSpecImpl( Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Feb 28 21:43:23 2018 @@ -7341,8 +7341,7 @@ class TransformTypos : public TreeTransf /// suggest the corrections. Otherwise the diagnostics will not suggest /// anything (having been passed an empty TypoCorrection). void EmitAllDiagnostics() { - for (auto E : TypoExprs) { - TypoExpr *TE = cast<TypoExpr>(E); + for (TypoExpr *TE : TypoExprs) { auto &State = SemaRef.getTypoExprState(TE); if (State.DiagHandler) { TypoCorrection TC = State.Consumer->getCurrentCorrection(); Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original) +++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Wed Feb 28 21:43:23 2018 @@ -618,7 +618,7 @@ ObjCPropertyDecl *Sema::CreatePropertyDe TInfo = Context.getTrivialTypeSourceInfo(T, TLoc); } - DeclContext *DC = cast<DeclContext>(CDecl); + DeclContext *DC = CDecl; ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, DC, FD.D.getIdentifierLoc(), PropertyId, AtLoc, Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original) +++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Wed Feb 28 21:43:23 2018 @@ -1591,7 +1591,7 @@ ExprResult Sema::ActOnOpenMPIdExpression } VarDecl *CanonicalVD = VD->getCanonicalDecl(); - NamedDecl *ND = cast<NamedDecl>(CanonicalVD); + NamedDecl *ND = CanonicalVD; // OpenMP [2.9.2, Restrictions, C/C++, p.2] // A threadprivate directive for file-scope variables must appear outside // any definition or declaration. Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplate.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Feb 28 21:43:23 2018 @@ -3526,7 +3526,7 @@ noteNonDeducibleParameters(Sema &S, Temp const llvm::SmallBitVector &DeducibleParams) { for (unsigned I = 0, N = DeducibleParams.size(); I != N; ++I) { if (!DeducibleParams[I]) { - NamedDecl *Param = cast<NamedDecl>(TemplateParams->getParam(I)); + NamedDecl *Param = TemplateParams->getParam(I); if (Param->getDeclName()) S.Diag(Param->getLocation(), diag::note_non_deducible_parameter) << Param->getDeclName(); @@ -5934,17 +5934,16 @@ static bool CheckTemplateArgumentPointer } // A constant of pointer-to-member type. else if ((DRE = dyn_cast<DeclRefExpr>(Arg))) { - if (ValueDecl *VD = dyn_cast<ValueDecl>(DRE->getDecl())) { - if (VD->getType()->isMemberPointerType()) { - if (isa<NonTypeTemplateParmDecl>(VD)) { - if (Arg->isTypeDependent() || Arg->isValueDependent()) { - Converted = TemplateArgument(Arg); - } else { - VD = cast<ValueDecl>(VD->getCanonicalDecl()); - Converted = TemplateArgument(VD, ParamType); - } - return Invalid; + ValueDecl *VD = DRE->getDecl(); + if (VD->getType()->isMemberPointerType()) { + if (isa<NonTypeTemplateParmDecl>(VD)) { + if (Arg->isTypeDependent() || Arg->isValueDependent()) { + Converted = TemplateArgument(Arg); + } else { + VD = cast<ValueDecl>(VD->getCanonicalDecl()); + Converted = TemplateArgument(VD, ParamType); } + return Invalid; } } @@ -6635,7 +6634,7 @@ Sema::BuildExpressionFromDeclTemplateArg assert(Arg.getKind() == TemplateArgument::Declaration && "Only declaration template arguments permitted here"); - ValueDecl *VD = cast<ValueDecl>(Arg.getAsDecl()); + ValueDecl *VD = Arg.getAsDecl(); if (VD->getDeclContext()->isRecord() && (isa<CXXMethodDecl>(VD) || isa<FieldDecl>(VD) || @@ -9529,8 +9528,7 @@ static bool isEnableIf(NestedNameSpecifi EnableIfTy.getAs<TemplateSpecializationTypeLoc>(); if (!EnableIfTSTLoc || EnableIfTSTLoc.getNumArgs() == 0) return false; - const TemplateSpecializationType *EnableIfTST = - cast<TemplateSpecializationType>(EnableIfTSTLoc.getTypePtr()); + const TemplateSpecializationType *EnableIfTST = EnableIfTSTLoc.getTypePtr(); // ... which names a complete class template declaration... const TemplateDecl *EnableIfDecl = Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Wed Feb 28 21:43:23 2018 @@ -1261,7 +1261,7 @@ ExprResult TemplateInstantiator::transfo arg.getKind() == TemplateArgument::NullPtr) { ValueDecl *VD; if (arg.getKind() == TemplateArgument::Declaration) { - VD = cast<ValueDecl>(arg.getAsDecl()); + VD = arg.getAsDecl(); // Find the instantiation of the template argument. This is // required for nested templates. Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Feb 28 21:43:23 2018 @@ -2688,9 +2688,9 @@ Decl *TemplateDeclInstantiator::VisitUnr Decl *TemplateDeclInstantiator::VisitUsingPackDecl(UsingPackDecl *D) { SmallVector<NamedDecl*, 8> Expansions; for (auto *UD : D->expansions()) { - if (auto *NewUD = + if (NamedDecl *NewUD = SemaRef.FindInstantiatedDecl(D->getLocation(), UD, TemplateArgs)) - Expansions.push_back(cast<NamedDecl>(NewUD)); + Expansions.push_back(NewUD); else return nullptr; } Modified: cfe/trunk/lib/Sema/SemaType.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaType.cpp (original) +++ cfe/trunk/lib/Sema/SemaType.cpp Wed Feb 28 21:43:23 2018 @@ -7877,8 +7877,8 @@ static QualType getDecltypeForExpr(Sema // // We apply the same rules for Objective-C ivar and property references. if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) { - if (const ValueDecl *VD = dyn_cast<ValueDecl>(DRE->getDecl())) - return VD->getType(); + const ValueDecl *VD = DRE->getDecl(); + return VD->getType(); } else if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) { if (const ValueDecl *VD = ME->getMemberDecl()) if (isa<FieldDecl>(VD) || isa<VarDecl>(VD)) Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original) +++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Wed Feb 28 21:43:23 2018 @@ -1911,7 +1911,7 @@ void ASTDeclReader::VisitCXXDestructorDe VisitCXXMethodDecl(D); if (auto *OperatorDelete = ReadDeclAs<FunctionDecl>()) { - auto *Canon = cast<CXXDestructorDecl>(D->getCanonicalDecl()); + CXXDestructorDecl *Canon = D->getCanonicalDecl(); auto *ThisArg = Record.readExpr(); // FIXME: Check consistency if we have an old and new operator delete. if (!Canon->OperatorDelete) { Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp Wed Feb 28 21:43:23 2018 @@ -78,7 +78,7 @@ bool CastToStructVisitor::VisitCastExpr( // Don't warn for references const ValueDecl *VD = nullptr; if (const auto *SE = dyn_cast<DeclRefExpr>(U->getSubExpr())) - VD = dyn_cast<ValueDecl>(SE->getDecl()); + VD = SE->getDecl(); else if (const auto *SE = dyn_cast<MemberExpr>(U->getSubExpr())) VD = SE->getMemberDecl(); if (!VD || VD->getType()->isReferenceType()) Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp Wed Feb 28 21:43:23 2018 @@ -402,13 +402,13 @@ visit(const ObjCImplementationDecl *Impl // Find the setter and the getter. const ObjCMethodDecl *SetterD = PD->getSetterMethodDecl(); if (SetterD) { - SetterD = cast<ObjCMethodDecl>(SetterD->getCanonicalDecl()); + SetterD = SetterD->getCanonicalDecl(); PropSetterToIvarMap[SetterD] = ID; } const ObjCMethodDecl *GetterD = PD->getGetterMethodDecl(); if (GetterD) { - GetterD = cast<ObjCMethodDecl>(GetterD->getCanonicalDecl()); + GetterD = GetterD->getCanonicalDecl(); PropGetterToIvarMap[GetterD] = ID; } } @@ -606,7 +606,7 @@ void IvarInvalidationCheckerImpl::Method const ObjCMessageExpr *ME) { const ObjCMethodDecl *MD = ME->getMethodDecl(); if (MD) { - MD = cast<ObjCMethodDecl>(MD->getCanonicalDecl()); + MD = MD->getCanonicalDecl(); MethToIvarMapTy::const_iterator IvI = PropertyGetterToIvarMap.find(MD); if (IvI != PropertyGetterToIvarMap.end()) markInvalidated(IvI->second); @@ -630,7 +630,7 @@ void IvarInvalidationCheckerImpl::Method if (PA->isImplicitProperty()) { const ObjCMethodDecl *MD = PA->getImplicitPropertySetter(); if (MD) { - MD = cast<ObjCMethodDecl>(MD->getCanonicalDecl()); + MD = MD->getCanonicalDecl(); MethToIvarMapTy::const_iterator IvI =PropertyGetterToIvarMap.find(MD); if (IvI != PropertyGetterToIvarMap.end()) markInvalidated(IvI->second); @@ -702,7 +702,7 @@ void IvarInvalidationCheckerImpl::Method // Check if we call a setter and set the property to 'nil'. if (MD && (ME->getNumArgs() == 1) && isZero(ME->getArg(0))) { - MD = cast<ObjCMethodDecl>(MD->getCanonicalDecl()); + MD = MD->getCanonicalDecl(); MethToIvarMapTy::const_iterator IvI = PropertySetterToIvarMap.find(MD); if (IvI != PropertySetterToIvarMap.end()) { markInvalidated(IvI->second); Modified: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp Wed Feb 28 21:43:23 2018 @@ -1260,7 +1260,7 @@ CallEventManager::getCaller(const StackF if (Optional<CFGAutomaticObjDtor> AutoDtor = E.getAs<CFGAutomaticObjDtor>()) Trigger = AutoDtor->getTriggerStmt(); else if (Optional<CFGDeleteDtor> DeleteDtor = E.getAs<CFGDeleteDtor>()) - Trigger = cast<Stmt>(DeleteDtor->getDeleteExpr()); + Trigger = DeleteDtor->getDeleteExpr(); else Trigger = Dtor->getBody(); Modified: cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp Wed Feb 28 21:43:23 2018 @@ -774,9 +774,9 @@ getStackOrCaptureRegionForDeclContext(co for (BlockDataRegion::referenced_vars_iterator I = BR->referenced_vars_begin(), E = BR->referenced_vars_end(); I != E; ++I) { - if (const VarRegion *VR = dyn_cast<VarRegion>(I.getOriginalRegion())) - if (VR->getDecl() == VD) - return cast<VarRegion>(I.getCapturedRegion()); + const VarRegion *VR = I.getOriginalRegion(); + if (VR->getDecl() == VD) + return cast<VarRegion>(I.getCapturedRegion()); } } Modified: cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp Wed Feb 28 21:43:23 2018 @@ -255,7 +255,7 @@ SVal ProgramState::getSValAsScalarOrLoc( } SVal ProgramState::getSVal(Loc location, QualType T) const { - SVal V = getRawSVal(cast<Loc>(location), T); + SVal V = getRawSVal(location, T); // If 'V' is a symbolic value that is *perfectly* constrained to // be a constant value, use that value instead to lessen the burden Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=326416&r1=326415&r2=326416&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Wed Feb 28 21:43:23 2018 @@ -825,7 +825,7 @@ collectSubRegionBindings(SmallVectorImpl FieldVector FieldsInSymbolicSubregions; if (TopKey.hasSymbolicOffset()) { getSymbolicOffsetFields(TopKey, FieldsInSymbolicSubregions); - Top = cast<SubRegion>(TopKey.getConcreteOffsetRegion()); + Top = TopKey.getConcreteOffsetRegion(); TopKey = BindingKey::Make(Top, BindingKey::Default); } @@ -1774,7 +1774,7 @@ RegionStoreManager::getBindingForFieldOr // quickly result in a warning. bool hasPartialLazyBinding = false; - const SubRegion *SR = dyn_cast<SubRegion>(R); + const SubRegion *SR = R; while (SR) { const MemRegion *Base = SR->getSuperRegion(); if (Optional<SVal> D = getBindingForDerivedDefaultValue(B, Base, R, Ty)) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits