Index: examples/AnnotateFunctions/AnnotateFunctions.cpp =================================================================== --- examples/AnnotateFunctions/AnnotateFunctions.cpp +++ examples/AnnotateFunctions/AnnotateFunctions.cpp @@ -31,7 +31,7 @@ if (!EnableAnnotate) return true; for (auto D : DG) - if (FunctionDecl *FD = dyn_cast(D)) + if (auto *FD = dyn_cast(D)) FD->addAttr(AnnotateAttr::CreateImplicit(FD->getASTContext(), "example_annotation")); return true; Index: examples/PrintFunctionNames/PrintFunctionNames.cpp =================================================================== --- examples/PrintFunctionNames/PrintFunctionNames.cpp +++ examples/PrintFunctionNames/PrintFunctionNames.cpp @@ -35,7 +35,7 @@ bool HandleTopLevelDecl(DeclGroupRef DG) override { for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e; ++i) { const Decl *D = *i; - if (const NamedDecl *ND = dyn_cast(D)) + if (const auto *ND = dyn_cast(D)) llvm::errs() << "top-level-decl: \"" << ND->getNameAsString() << "\"\n"; } Index: examples/clang-interpreter/main.cpp =================================================================== --- examples/clang-interpreter/main.cpp +++ examples/clang-interpreter/main.cpp @@ -38,7 +38,7 @@ std::string GetExecutablePath(const char *Argv0) { // This just needs to be some symbol in the binary; C++ doesn't // allow taking the address of ::main however. - void *MainAddr = (void*) (intptr_t) GetExecutablePath; + auto *MainAddr = (void *)(intptr_t)GetExecutablePath; return llvm::sys::fs::getMainExecutable(Argv0, MainAddr); } @@ -78,11 +78,10 @@ } int main(int argc, const char **argv, char * const *envp) { - void *MainAddr = (void*) (intptr_t) GetExecutablePath; + auto *MainAddr = (void *)(intptr_t)GetExecutablePath; std::string Path = GetExecutablePath(argv[0]); IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); - TextDiagnosticPrinter *DiagClient = - new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); + auto *DiagClient = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient); Index: include/clang/AST/ASTLambda.h =================================================================== --- include/clang/AST/ASTLambda.h +++ include/clang/AST/ASTLambda.h @@ -51,11 +51,10 @@ inline bool isLambdaConversionOperator(Decl *D) { if (!D) return false; - if (CXXConversionDecl *Conv = dyn_cast(D)) - return isLambdaConversionOperator(Conv); - if (FunctionTemplateDecl *F = dyn_cast(D)) - if (CXXConversionDecl *Conv = - dyn_cast_or_null(F->getTemplatedDecl())) + if (auto *Conv = dyn_cast(D)) + return isLambdaConversionOperator(Conv); + if (auto *F = dyn_cast(D)) + if (auto *Conv = dyn_cast_or_null(F->getTemplatedDecl())) return isLambdaConversionOperator(Conv); return false; } Index: include/clang/AST/ASTVector.h =================================================================== --- include/clang/AST/ASTVector.h +++ include/clang/AST/ASTVector.h @@ -380,7 +380,7 @@ NewCapacity = MinSize; // Allocate the memory from the ASTContext. - T *NewElts = new (C, alignof(T)) T[NewCapacity]; + auto *NewElts = new (C, alignof(T)) T[NewCapacity]; // Copy the elements over. if (Begin != End) { Index: include/clang/AST/Decl.h =================================================================== --- include/clang/AST/Decl.h +++ include/clang/AST/Decl.h @@ -3157,7 +3157,7 @@ QualType getIntegerType() const { if (!IntegerType) return QualType(); - if (const Type *T = IntegerType.dyn_cast()) + if (const auto *T = IntegerType.dyn_cast()) return QualType(T, 0); return IntegerType.get()->getType().getUnqualifiedType(); } Index: include/clang/AST/DeclCXX.h =================================================================== --- include/clang/AST/DeclCXX.h +++ include/clang/AST/DeclCXX.h @@ -1431,7 +1431,7 @@ /// \brief If the class is a local class [class.local], returns /// the enclosing function declaration. const FunctionDecl *isLocalClass() const { - if (const CXXRecordDecl *RD = dyn_cast(getDeclContext())) + if (const auto *RD = dyn_cast(getDeclContext())) return RD->isLocalClass(); return dyn_cast(getDeclContext()); @@ -1787,8 +1787,8 @@ bool isVolatile() const { return getType()->castAs()->isVolatile(); } bool isVirtual() const { - CXXMethodDecl *CD = - cast(const_cast(this)->getCanonicalDecl()); + auto *CD = cast( + const_cast(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. @@ -2755,7 +2755,7 @@ /// \brief Retrieve the namespace declaration aliased by this directive. NamespaceDecl *getNamespace() { - if (NamespaceAliasDecl *AD = dyn_cast(Namespace)) + if (auto *AD = dyn_cast(Namespace)) return AD->getNamespace(); return cast(Namespace); Index: include/clang/AST/DeclContextInternals.h =================================================================== --- include/clang/AST/DeclContextInternals.h +++ include/clang/AST/DeclContextInternals.h @@ -86,7 +86,7 @@ if (DeclsTy *Vec = getAsVector()) Data = DeclsAndHasExternalTy(Vec, true); else { - DeclsTy *VT = new DeclsTy(); + auto *VT = new DeclsTy(); if (NamedDecl *OldD = getAsDecl()) VT->push_back(OldD); Data = DeclsAndHasExternalTy(VT, true); @@ -193,7 +193,7 @@ // If this is the second decl added to the list, convert this to vector // form. if (NamedDecl *OldD = getAsDecl()) { - DeclsTy *VT = new DeclsTy(); + auto *VT = new DeclsTy(); VT->push_back(OldD); Data = DeclsAndHasExternalTy(VT, false); } Index: include/clang/AST/DeclFriend.h =================================================================== --- include/clang/AST/DeclFriend.h +++ include/clang/AST/DeclFriend.h @@ -130,13 +130,13 @@ /// Retrieves the source range for the friend declaration. SourceRange getSourceRange() const override LLVM_READONLY { if (NamedDecl *ND = getFriendDecl()) { - if (FunctionDecl *FD = dyn_cast(ND)) + if (auto *FD = dyn_cast(ND)) return FD->getSourceRange(); - if (FunctionTemplateDecl *FTD = dyn_cast(ND)) + if (auto *FTD = dyn_cast(ND)) return FTD->getSourceRange(); - if (ClassTemplateDecl *CTD = dyn_cast(ND)) + if (auto *CTD = dyn_cast(ND)) return CTD->getSourceRange(); - if (DeclaratorDecl *DD = dyn_cast(ND)) { + if (auto *DD = dyn_cast(ND)) { if (DD->getOuterLocStart() != DD->getInnerLocStart()) return DD->getSourceRange(); } Index: include/clang/AST/DeclTemplate.h =================================================================== --- include/clang/AST/DeclTemplate.h +++ include/clang/AST/DeclTemplate.h @@ -1699,8 +1699,8 @@ llvm::PointerUnion getSpecializedTemplateOrPartial() const { - if (SpecializedPartialSpecialization *PartialSpec - = SpecializedTemplate.dyn_cast()) + if (auto *PartialSpec = + SpecializedTemplate.dyn_cast()) return PartialSpec->PartialSpecialization; return SpecializedTemplate.get(); @@ -1718,8 +1718,8 @@ /// deduced template arguments for the class template partial specialization /// itself. const TemplateArgumentList &getTemplateInstantiationArgs() const { - if (SpecializedPartialSpecialization *PartialSpec - = SpecializedTemplate.dyn_cast()) + if (auto *PartialSpec = + SpecializedTemplate.dyn_cast()) return *PartialSpec->TemplateArgs; return getTemplateArgs(); @@ -1732,8 +1732,7 @@ const TemplateArgumentList *TemplateArgs) { assert(!SpecializedTemplate.is() && "Already set to a class template partial specialization!"); - SpecializedPartialSpecialization *PS - = new (getASTContext()) SpecializedPartialSpecialization(); + auto *PS = new (getASTContext()) SpecializedPartialSpecialization(); PS->PartialSpecialization = PartialSpec; PS->TemplateArgs = TemplateArgs; SpecializedTemplate = PS; @@ -1891,7 +1890,7 @@ /// \c Outer::Inner, this function would return /// \c Outer::Inner. ClassTemplatePartialSpecializationDecl *getInstantiatedFromMember() const { - const ClassTemplatePartialSpecializationDecl *First = + const auto *First = cast(getFirstDecl()); return First->InstantiatedFromMember.getPointer(); } @@ -1902,8 +1901,7 @@ void setInstantiatedFromMember( ClassTemplatePartialSpecializationDecl *PartialSpec) { - ClassTemplatePartialSpecializationDecl *First = - cast(getFirstDecl()); + auto *First = cast(getFirstDecl()); First->InstantiatedFromMember.setPointer(PartialSpec); } @@ -1924,15 +1922,13 @@ /// struct X::Inner { /* ... */ }; /// \endcode bool isMemberSpecialization() { - ClassTemplatePartialSpecializationDecl *First = - cast(getFirstDecl()); + auto *First = cast(getFirstDecl()); return First->InstantiatedFromMember.getInt(); } /// \brief Note that this member template is a specialization. void setMemberSpecialization() { - ClassTemplatePartialSpecializationDecl *First = - cast(getFirstDecl()); + auto *First = cast(getFirstDecl()); assert(First->InstantiatedFromMember.getPointer() && "Only member templates can be member template specializations"); return First->InstantiatedFromMember.setInt(true); @@ -2536,7 +2532,7 @@ /// specialization which was specialized by this. llvm::PointerUnion getSpecializedTemplateOrPartial() const { - if (SpecializedPartialSpecialization *PartialSpec = + if (auto *PartialSpec = SpecializedTemplate.dyn_cast()) return PartialSpec->PartialSpecialization; @@ -2555,7 +2551,7 @@ /// return deduced template arguments for the variable template partial /// specialization itself. const TemplateArgumentList &getTemplateInstantiationArgs() const { - if (SpecializedPartialSpecialization *PartialSpec = + if (auto *PartialSpec = SpecializedTemplate.dyn_cast()) return *PartialSpec->TemplateArgs; @@ -2569,8 +2565,7 @@ const TemplateArgumentList *TemplateArgs) { assert(!SpecializedTemplate.is() && "Already set to a variable template partial specialization!"); - SpecializedPartialSpecialization *PS = - new (getASTContext()) SpecializedPartialSpecialization(); + auto *PS = new (getASTContext()) SpecializedPartialSpecialization(); PS->PartialSpecialization = PartialSpec; PS->TemplateArgs = TemplateArgs; SpecializedTemplate = PS; @@ -2720,15 +2715,14 @@ /// \c Outer::Inner, this function would return /// \c Outer::Inner. VarTemplatePartialSpecializationDecl *getInstantiatedFromMember() const { - const VarTemplatePartialSpecializationDecl *First = + const auto *First = cast(getFirstDecl()); return First->InstantiatedFromMember.getPointer(); } void setInstantiatedFromMember(VarTemplatePartialSpecializationDecl *PartialSpec) { - VarTemplatePartialSpecializationDecl *First = - cast(getFirstDecl()); + auto *First = cast(getFirstDecl()); First->InstantiatedFromMember.setPointer(PartialSpec); } @@ -2749,15 +2743,13 @@ /// U* X::Inner = (T*)(0) + 1; /// \endcode bool isMemberSpecialization() { - VarTemplatePartialSpecializationDecl *First = - cast(getFirstDecl()); + auto *First = cast(getFirstDecl()); return First->InstantiatedFromMember.getInt(); } /// \brief Note that this member template is a specialization. void setMemberSpecialization() { - VarTemplatePartialSpecializationDecl *First = - cast(getFirstDecl()); + auto *First = cast(getFirstDecl()); assert(First->InstantiatedFromMember.getPointer() && "Only member templates can be member template specializations"); return First->InstantiatedFromMember.setInt(true); Index: include/clang/AST/Expr.h =================================================================== --- include/clang/AST/Expr.h +++ include/clang/AST/Expr.h @@ -389,7 +389,7 @@ /// getValueKindForType - Given a formal return or parameter type, /// give its value kind. static ExprValueKind getValueKindForType(QualType T) { - if (const ReferenceType *RT = T->getAs()) + if (const auto *RT = T->getAs()) return (isa(RT) ? VK_LValue : (RT->getPointeeType()->isFunctionType() @@ -1977,7 +1977,7 @@ // Iterators child_range children() { - Stmt **begin = reinterpret_cast(getTrailingObjects()); + auto **begin = reinterpret_cast(getTrailingObjects()); return child_range(begin, begin + NumExprs); } friend TrailingObjects; @@ -2791,7 +2791,7 @@ inline Expr *Expr::IgnoreImpCasts() { Expr *e = this; - while (ImplicitCastExpr *ice = dyn_cast(e)) + while (auto *ice = dyn_cast(e)) e = ice->getSubExpr(); return e; } @@ -3333,19 +3333,19 @@ }; inline Expr *AbstractConditionalOperator::getCond() const { - if (const ConditionalOperator *co = dyn_cast(this)) + if (const auto *co = dyn_cast(this)) return co->getCond(); return cast(this)->getCond(); } inline Expr *AbstractConditionalOperator::getTrueExpr() const { - if (const ConditionalOperator *co = dyn_cast(this)) + if (const auto *co = dyn_cast(this)) return co->getTrueExpr(); return cast(this)->getTrueExpr(); } inline Expr *AbstractConditionalOperator::getFalseExpr() const { - if (const ConditionalOperator *co = dyn_cast(this)) + if (const auto *co = dyn_cast(this)) return co->getFalseExpr(); return cast(this)->getFalseExpr(); } @@ -4250,7 +4250,7 @@ // Iterators child_range children() { - Stmt **begin = getTrailingObjects(); + auto **begin = getTrailingObjects(); return child_range(begin, begin + NumSubExprs); } @@ -4913,7 +4913,7 @@ } child_range children() { - Stmt **cs = reinterpret_cast(getSubExprsBuffer()); + auto **cs = reinterpret_cast(getSubExprsBuffer()); return child_range(cs, cs + getNumSubExprs()); } Index: include/clang/AST/ExprCXX.h =================================================================== --- include/clang/AST/ExprCXX.h +++ include/clang/AST/ExprCXX.h @@ -663,7 +663,7 @@ child_range children() { if (isTypeOperand()) return child_range(child_iterator(), child_iterator()); - Stmt **begin = reinterpret_cast(&Operand); + auto **begin = reinterpret_cast(&Operand); return child_range(begin, begin + 1); } }; @@ -866,7 +866,7 @@ child_range children() { if (isTypeOperand()) return child_range(child_iterator(), child_iterator()); - Stmt **begin = reinterpret_cast(&Operand); + auto **begin = reinterpret_cast(&Operand); return child_range(begin, begin + 1); } }; @@ -2532,7 +2532,7 @@ if (isa(E)) { assert(cast(E)->getOpcode() == UO_AddrOf); E = cast(E)->getSubExpr(); - OverloadExpr *Ovl = cast(E->IgnoreParens()); + auto *Ovl = cast(E->IgnoreParens()); Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); Result.IsAddressOfOperand = true; @@ -3094,7 +3094,7 @@ // Iterators child_range children() { - Stmt **begin = reinterpret_cast(arg_begin()); + auto **begin = reinterpret_cast(arg_begin()); return child_range(begin, begin + NumArgs); } }; @@ -3675,7 +3675,7 @@ Length(Length ? *Length : PartialArgs.size()), Pack(Pack) { assert((!Length || PartialArgs.empty()) && "have partial args for non-dependent sizeof... expression"); - TemplateArgument *Args = getTrailingObjects(); + auto *Args = getTrailingObjects(); std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args); } @@ -3726,7 +3726,7 @@ /// \brief Get ArrayRef getPartialArguments() const { assert(isPartiallySubstituted()); - const TemplateArgument *Args = getTrailingObjects(); + const auto *Args = getTrailingObjects(); return llvm::makeArrayRef(Args, Args + Length); } Index: include/clang/AST/ExprObjC.h =================================================================== --- include/clang/AST/ExprObjC.h +++ include/clang/AST/ExprObjC.h @@ -715,7 +715,7 @@ // Iterators child_range children() { if (Receiver.is()) { - Stmt **begin = reinterpret_cast(&Receiver); // hack! + auto **begin = reinterpret_cast(&Receiver); // hack! return child_range(begin, begin+1); } return child_range(child_iterator(), child_iterator()); Index: include/clang/AST/ExternalASTSource.h =================================================================== --- include/clang/AST/ExternalASTSource.h +++ include/clang/AST/ExternalASTSource.h @@ -420,7 +420,7 @@ /// Set the value of this pointer, in the current generation. void set(T NewValue) { - if (LazyData *LazyVal = Value.template dyn_cast()) { + if (auto *LazyVal = Value.template dyn_cast()) { LazyVal->LastValue = NewValue; return; } @@ -432,7 +432,7 @@ /// Get the value of this pointer, updating its owner if necessary. T get(Owner O) { - if (LazyData *LazyVal = Value.template dyn_cast()) { + if (auto *LazyVal = Value.template dyn_cast()) { if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) { LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration(); (LazyVal->ExternalSource->*Update)(O); @@ -444,7 +444,7 @@ /// Get the most recently computed value of this pointer without updating it. T getNotUpdated() const { - if (LazyData *LazyVal = Value.template dyn_cast()) + if (auto *LazyVal = Value.template dyn_cast()) return LazyVal->LastValue; return Value.template get(); } Index: include/clang/AST/RecursiveASTVisitor.h =================================================================== --- include/clang/AST/RecursiveASTVisitor.h +++ include/clang/AST/RecursiveASTVisitor.h @@ -538,7 +538,7 @@ // If we have a binary expr, dispatch to the subcode of the binop. A smart // optimizer (e.g. LLVM) will fold this comparison into the switch stmt // below. - if (BinaryOperator *BinOp = dyn_cast(S)) { + if (auto *BinOp = dyn_cast(S)) { switch (BinOp->getOpcode()) { #define OPERATOR(NAME) \ case BO_##NAME: \ @@ -556,7 +556,7 @@ #undef OPERATOR #undef CAO_LIST } - } else if (UnaryOperator *UnOp = dyn_cast(S)) { + } else if (auto *UnOp = dyn_cast(S)) { switch (UnOp->getOpcode()) { #define OPERATOR(NAME) \ case UO_##NAME: \ @@ -1910,7 +1910,7 @@ } } - if (CXXConstructorDecl *Ctor = dyn_cast(D)) { + if (auto *Ctor = dyn_cast(D)) { // Constructor initializers. for (auto *I : Ctor->inits()) { TRY_TO(TraverseConstructorInitializer(I)); @@ -2218,7 +2218,7 @@ e = S->semantics_end(); i != e; ++i) { Expr *sub = *i; - if (OpaqueValueExpr *OVE = dyn_cast(sub)) + if (auto *OVE = dyn_cast(sub)) sub = OVE->getSourceExpr(); TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(sub); } Index: include/clang/AST/Redeclarable.h =================================================================== --- include/clang/AST/Redeclarable.h +++ include/clang/AST/Redeclarable.h @@ -260,7 +260,7 @@ /// \brief Return the first declaration of this declaration or itself if this /// is the only declaration. decl_type *getFirstDecl() { - decl_type *D = static_cast(this); + auto *D = static_cast(this); if (!D->isFromASTFile()) return D; return cast(getPrimaryMergedDecl(const_cast(D))); @@ -269,7 +269,7 @@ /// \brief Return the first declaration of this declaration or itself if this /// is the only declaration. const decl_type *getFirstDecl() const { - const decl_type *D = static_cast(this); + const auto *D = static_cast(this); if (!D->isFromASTFile()) return D; return cast(getPrimaryMergedDecl(const_cast(D))); Index: include/clang/AST/Stmt.h =================================================================== --- include/clang/AST/Stmt.h +++ include/clang/AST/Stmt.h @@ -734,7 +734,7 @@ SourceLocation getLocEnd() const LLVM_READONLY { // Handle deeply nested case statements with iteration instead of recursion. const CaseStmt *CS = this; - while (const CaseStmt *CS2 = dyn_cast(CS->getSubStmt())) + while (const auto *CS2 = dyn_cast(CS->getSubStmt())) CS = CS2; return CS->getSubStmt()->getLocEnd(); @@ -781,7 +781,7 @@ }; inline SourceLocation SwitchCase::getLocEnd() const { - if (const CaseStmt *CS = dyn_cast(this)) + if (const auto *CS = dyn_cast(this)) return CS->getLocEnd(); return cast(this)->getLocEnd(); } Index: include/clang/AST/StmtOpenMP.h =================================================================== --- include/clang/AST/StmtOpenMP.h +++ include/clang/AST/StmtOpenMP.h @@ -50,7 +50,7 @@ /// \brief Get the clauses storage. MutableArrayRef getClauses() { - OMPClause **ClauseStorage = reinterpret_cast( + auto **ClauseStorage = reinterpret_cast( reinterpret_cast(this) + ClausesOffset); return MutableArrayRef(ClauseStorage, NumClauses); } Index: include/clang/AST/StmtVisitor.h =================================================================== --- include/clang/AST/StmtVisitor.h +++ include/clang/AST/StmtVisitor.h @@ -42,7 +42,7 @@ // If we have a binary expr, dispatch to the subcode of the binop. A smart // optimizer (e.g. LLVM) will fold this comparison into the switch stmt // below. - if (PTR(BinaryOperator) BinOp = dyn_cast(S)) { + if (auto BinOp = dyn_cast(S)) { switch (BinOp->getOpcode()) { case BO_PtrMemD: DISPATCH(BinPtrMemD, BinaryOperator); case BO_PtrMemI: DISPATCH(BinPtrMemI, BinaryOperator); @@ -79,7 +79,7 @@ case BO_XorAssign: DISPATCH(BinXorAssign, CompoundAssignOperator); case BO_Comma: DISPATCH(BinComma, BinaryOperator); } - } else if (PTR(UnaryOperator) UnOp = dyn_cast(S)) { + } else if (auto UnOp = dyn_cast(S)) { switch (UnOp->getOpcode()) { case UO_PostInc: DISPATCH(UnaryPostInc, UnaryOperator); case UO_PostDec: DISPATCH(UnaryPostDec, UnaryOperator); Index: include/clang/AST/Type.h =================================================================== --- include/clang/AST/Type.h +++ include/clang/AST/Type.h @@ -611,8 +611,7 @@ const ExtQualsTypeCommonBase *getCommonPtr() const { assert(!isNull() && "Cannot retrieve a NULL type pointer"); - uintptr_t CommonPtrVal - = reinterpret_cast(Value.getOpaqueValue()); + auto CommonPtrVal = reinterpret_cast(Value.getOpaqueValue()); CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1); return reinterpret_cast(CommonPtrVal); } @@ -3249,7 +3248,7 @@ assert(hasExtParameterInfos()); // Find the end of the exception specification. - const char *ptr = reinterpret_cast(exception_begin()); + const auto *ptr = reinterpret_cast(exception_begin()); ptr += getExceptionSpecSize(); return reinterpret_cast(ptr); @@ -5066,8 +5065,8 @@ inline ObjCInterfaceDecl *ObjCObjectType::getInterface() const { QualType baseType = getBaseType(); - while (const ObjCObjectType *ObjT = baseType->getAs()) { - if (const ObjCInterfaceType *T = dyn_cast(ObjT)) + while (const auto *ObjT = baseType->getAs()) { + if (const auto *T = dyn_cast(ObjT)) return T->getDecl(); baseType = ObjT->getBaseType(); @@ -5480,10 +5479,10 @@ } inline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { - if (const PointerType *PT = t.getAs()) { - if (const FunctionType *FT = PT->getPointeeType()->getAs()) + if (const auto *PT = t.getAs()) { + if (const auto *FT = PT->getPointeeType()->getAs()) return FT->getExtInfo(); - } else if (const FunctionType *FT = t.getAs()) + } else if (const auto *FT = t.getAs()) return FT->getExtInfo(); return FunctionType::ExtInfo(); @@ -5528,7 +5527,7 @@ /// analysis, the expression designates the object or function /// denoted by the reference, and the expression is an lvalue. inline QualType QualType::getNonReferenceType() const { - if (const ReferenceType *RefType = (*this)->getAs()) + if (const auto *RefType = (*this)->getAs()) return RefType->getPointeeType(); else return *this; @@ -5596,7 +5595,7 @@ return isa(CanonicalType); } inline bool Type::isFunctionPointerType() const { - if (const PointerType *T = getAs()) + if (const auto *T = getAs()) return T->getPointeeType()->isFunctionType(); else return false; @@ -5605,13 +5604,13 @@ return isa(CanonicalType); } inline bool Type::isMemberFunctionPointerType() const { - if (const MemberPointerType* T = getAs()) + if (const auto *T = getAs()) return T->isMemberFunctionPointer(); else return false; } inline bool Type::isMemberDataPointerType() const { - if (const MemberPointerType* T = getAs()) + if (const auto *T = getAs()) return T->isMemberDataPointer(); else return false; @@ -5664,27 +5663,27 @@ } inline bool Type::isObjCQualifiedIdType() const { - if (const ObjCObjectPointerType *OPT = getAs()) + if (const auto *OPT = getAs()) return OPT->isObjCQualifiedIdType(); return false; } inline bool Type::isObjCQualifiedClassType() const { - if (const ObjCObjectPointerType *OPT = getAs()) + if (const auto *OPT = getAs()) return OPT->isObjCQualifiedClassType(); return false; } inline bool Type::isObjCIdType() const { - if (const ObjCObjectPointerType *OPT = getAs()) + if (const auto *OPT = getAs()) return OPT->isObjCIdType(); return false; } inline bool Type::isObjCClassType() const { - if (const ObjCObjectPointerType *OPT = getAs()) + if (const auto *OPT = getAs()) return OPT->isObjCClassType(); return false; } inline bool Type::isObjCSelType() const { - if (const PointerType *OPT = getAs()) + if (const auto *OPT = getAs()) return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); return false; } @@ -5750,13 +5749,13 @@ } inline bool Type::isPlaceholderType() const { - if (const BuiltinType *BT = dyn_cast(this)) + if (const auto *BT = dyn_cast(this)) return BT->isPlaceholderType(); return false; } inline const BuiltinType *Type::getAsPlaceholderType() const { - if (const BuiltinType *BT = dyn_cast(this)) + if (const auto *BT = dyn_cast(this)) if (BT->isPlaceholderType()) return BT; return nullptr; @@ -5764,13 +5763,13 @@ inline bool Type::isSpecificPlaceholderType(unsigned K) const { assert(BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K)); - if (const BuiltinType *BT = dyn_cast(this)) + if (const auto *BT = dyn_cast(this)) return (BT->getKind() == (BuiltinType::Kind) K); return false; } inline bool Type::isNonOverloadPlaceholderType() const { - if (const BuiltinType *BT = dyn_cast(this)) + if (const auto *BT = dyn_cast(this)) return BT->isNonOverloadPlaceholderType(); return false; } @@ -5916,7 +5915,7 @@ "ArrayType cannot be used with getAs!"); // If this is directly a T type, return it. - if (const T *Ty = dyn_cast(this)) + if (const auto *Ty = dyn_cast(this)) return Ty; // If the canonical form of this type isn't the right kind, reject it. @@ -5930,7 +5929,7 @@ inline const ArrayType *Type::getAsArrayTypeUnsafe() const { // If this is directly an array type, return it. - if (const ArrayType *arr = dyn_cast(this)) + if (const auto *arr = dyn_cast(this)) return arr; // If the canonical form of this type isn't the right kind, reject it. @@ -5946,14 +5945,16 @@ static_assert(!TypeIsArrayType::value, "ArrayType cannot be used with castAs!"); - if (const T *ty = dyn_cast(this)) return ty; + if (const auto *ty = dyn_cast(this)) + return ty; assert(isa(CanonicalType)); return cast(getUnqualifiedDesugaredType()); } inline const ArrayType *Type::castAsArrayTypeUnsafe() const { assert(isa(CanonicalType)); - if (const ArrayType *arr = dyn_cast(this)) return arr; + if (const auto *arr = dyn_cast(this)) + return arr; return cast(getUnqualifiedDesugaredType()); } Index: include/clang/AST/TypeLoc.h =================================================================== --- include/clang/AST/TypeLoc.h +++ include/clang/AST/TypeLoc.h @@ -253,7 +253,7 @@ UnqualTypeLoc getUnqualifiedLoc() const { unsigned align = TypeLoc::getLocalAlignmentForType(QualType(getTypePtr(), 0)); - uintptr_t dataInt = reinterpret_cast(Data); + auto dataInt = reinterpret_cast(Data); dataInt = llvm::alignTo(dataInt, align); return UnqualTypeLoc(getTypePtr(), reinterpret_cast(dataInt)); } @@ -404,7 +404,7 @@ } void *getNonLocalData() const { - uintptr_t data = reinterpret_cast(Base::Data); + auto data = reinterpret_cast(Base::Data); data += asDerived()->getLocalDataSize(); data = llvm::alignTo(data, getNextTypeAlign()); return reinterpret_cast(data); Index: include/clang/AST/VTableBuilder.h =================================================================== --- include/clang/AST/VTableBuilder.h +++ include/clang/AST/VTableBuilder.h @@ -313,7 +313,7 @@ public: virtual const ThunkInfoVectorTy *getThunkInfo(GlobalDecl GD) { - const CXXMethodDecl *MD = cast(GD.getDecl()->getCanonicalDecl()); + const auto *MD = cast(GD.getDecl()->getCanonicalDecl()); computeVTableRelatedInformation(MD->getParent()); // This assumes that all the destructors present in the vtable Index: include/clang/ASTMatchers/ASTMatchFinder.h =================================================================== --- include/clang/ASTMatchers/ASTMatchFinder.h +++ include/clang/ASTMatchers/ASTMatchFinder.h @@ -267,7 +267,7 @@ const NodeT * selectFirst(StringRef BoundTo, const SmallVectorImpl &Results) { for (const BoundNodes &N : Results) { - if (const NodeT *Node = N.getNodeAs(BoundTo)) + if (const auto *Node = N.getNodeAs(BoundTo)) return Node; } return nullptr; Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -2844,7 +2844,7 @@ AST_MATCHER_P(DeclRefExpr, throughUsingDecl, internal::Matcher, InnerMatcher) { const NamedDecl *FoundDecl = Node.getFoundDecl(); - if (const UsingShadowDecl *UsingDecl = dyn_cast(FoundDecl)) + if (const auto *UsingDecl = dyn_cast(FoundDecl)) return InnerMatcher.matches(*UsingDecl, Finder, Builder); return false; } Index: include/clang/ASTMatchers/ASTMatchersInternal.h =================================================================== --- include/clang/ASTMatchers/ASTMatchersInternal.h +++ include/clang/ASTMatchers/ASTMatchersInternal.h @@ -133,7 +133,7 @@ /// it cannot be converted to the specified type. template const T *getNodeAs(StringRef ID) const { - IDToNodeMap::const_iterator It = NodeMap.find(ID); + auto It = NodeMap.find(ID); if (It == NodeMap.end()) { return nullptr; } @@ -141,7 +141,7 @@ } ast_type_traits::DynTypedNode getNode(StringRef ID) const { - IDToNodeMap::const_iterator It = NodeMap.find(ID); + auto It = NodeMap.find(ID); if (It == NodeMap.end()) { return ast_type_traits::DynTypedNode(); } Index: include/clang/Analysis/Analyses/Consumed.h =================================================================== --- include/clang/Analysis/Analyses/Consumed.h +++ include/clang/Analysis/Analyses/Consumed.h @@ -205,8 +205,8 @@ ConsumedBlockInfo(unsigned int NumBlocks, PostOrderCFGView *SortedGraph) : StateMapsArray(NumBlocks), VisitOrder(NumBlocks, 0) { unsigned int VisitOrderCounter = 0; - for (PostOrderCFGView::iterator BI = SortedGraph->begin(), - BE = SortedGraph->end(); BI != BE; ++BI) { + for (auto BI = SortedGraph->begin(), BE = SortedGraph->end(); BI != BE; + ++BI) { VisitOrder[(*BI)->getBlockID()] = VisitOrderCounter++; } } Index: include/clang/Analysis/Analyses/ThreadSafetyCommon.h =================================================================== --- include/clang/Analysis/Analyses/ThreadSafetyCommon.h +++ include/clang/Analysis/Analyses/ThreadSafetyCommon.h @@ -192,9 +192,9 @@ } case CFGElement::AutomaticObjectDtor: { CFGAutomaticObjDtor AD = BI.castAs(); - CXXDestructorDecl *DD = const_cast( + auto *DD = const_cast( AD.getDestructorDecl(ACtx->getASTContext())); - VarDecl *VD = const_cast(AD.getVarDecl()); + auto *VD = const_cast(AD.getVarDecl()); V.handleDestructorCall(VD, DD); break; } Index: include/clang/Analysis/Analyses/ThreadSafetyTraverse.h =================================================================== --- include/clang/Analysis/Analyses/ThreadSafetyTraverse.h +++ include/clang/Analysis/Analyses/ThreadSafetyTraverse.h @@ -688,8 +688,8 @@ void printProject(const Project *E, StreamType &SS) { if (CStyle) { // Omit the this-> - if (const SApply *SAP = dyn_cast(E->record())) { - if (const Variable *V = dyn_cast(SAP->sfun())) { + if (const auto *SAP = dyn_cast(E->record())) { + if (const auto *V = dyn_cast(SAP->sfun())) { if (!SAP->isDelegation() && V->kind() == Variable::VK_SFun) { SS << E->slotName(); return; Index: include/clang/Analysis/CFG.h =================================================================== --- include/clang/Analysis/CFG.h +++ include/clang/Analysis/CFG.h @@ -462,7 +462,7 @@ } bool isReachable() const { - Kind K = (Kind) UnreachableBlock.getInt(); + auto K = (Kind)UnreachableBlock.getInt(); return K == AB_Normal || K == AB_Alternate; } }; Index: include/clang/Analysis/Support/BumpVector.h =================================================================== --- include/clang/Analysis/Support/BumpVector.h +++ include/clang/Analysis/Support/BumpVector.h @@ -225,8 +225,8 @@ NewCapacity = MinSize; // Allocate the memory from the BumpPtrAllocator. - T *NewElts = C.getAllocator().template Allocate(NewCapacity); - + auto *NewElts = C.getAllocator().template Allocate(NewCapacity); + // Copy the elements over. if (Begin != End) { if (std::is_class::value) { Index: include/clang/Driver/Compilation.h =================================================================== --- include/clang/Driver/Compilation.h +++ include/clang/Driver/Compilation.h @@ -175,7 +175,7 @@ /// /// The new Action is *not* added to the list returned by getActions(). template T *MakeAction(Args &&... Arg) { - T *RawPtr = new T(std::forward(Arg)...); + auto *RawPtr = new T(std::forward(Arg)...); AllActions.push_back(std::unique_ptr(RawPtr)); return RawPtr; } Index: include/clang/Lex/PTHLexer.h =================================================================== --- include/clang/Lex/PTHLexer.h +++ include/clang/Lex/PTHLexer.h @@ -83,7 +83,7 @@ // whether or not we are at a token with kind tok::eof or tok::l_paren. // Just read the first byte from the current token pointer to determine // its kind. - tok::TokenKind x = (tok::TokenKind)*CurPtr; + auto x = (tok::TokenKind)*CurPtr; return x == tok::eof ? 2 : x == tok::l_paren; } Index: include/clang/Rewrite/Core/Rewriter.h =================================================================== --- include/clang/Rewrite/Core/Rewriter.h +++ include/clang/Rewrite/Core/Rewriter.h @@ -168,8 +168,7 @@ /// getRewriteBufferFor - Return the rewrite buffer for the specified FileID. /// If no modification has been made to it, return null. const RewriteBuffer *getRewriteBufferFor(FileID FID) const { - std::map::const_iterator I = - RewriteBuffers.find(FID); + auto I = RewriteBuffers.find(FID); return I == RewriteBuffers.end() ? nullptr : &I->second; } Index: include/clang/Sema/Overload.h =================================================================== --- include/clang/Sema/Overload.h +++ include/clang/Sema/Overload.h @@ -770,8 +770,7 @@ // Assign space from the inline array if there are enough free slots // available. if (NumConversions + NumInlineSequences <= 16) { - ImplicitConversionSequence *I = - (ImplicitConversionSequence *)InlineSpace.buffer; + auto *I = (ImplicitConversionSequence *)InlineSpace.buffer; C.Conversions = &I[NumInlineSequences]; NumInlineSequences += NumConversions; } else { Index: include/clang/Sema/Ownership.h =================================================================== --- include/clang/Sema/Ownership.h +++ include/clang/Sema/Ownership.h @@ -200,7 +200,7 @@ bool isUnset() const { return PtrWithInvalid == 0; } PtrTy get() const { - void *VP = reinterpret_cast(PtrWithInvalid & ~0x01); + auto *VP = reinterpret_cast(PtrWithInvalid & ~0x01); return PtrTraits::getFromVoidPointer(VP); } template T *getAs() { return static_cast(get()); } Index: include/clang/Sema/ParsedTemplate.h =================================================================== --- include/clang/Sema/ParsedTemplate.h +++ include/clang/Sema/ParsedTemplate.h @@ -190,9 +190,9 @@ /// appends it to List. static TemplateIdAnnotation * Allocate(unsigned NumArgs, SmallVectorImpl &List) { - TemplateIdAnnotation *TemplateId - = (TemplateIdAnnotation *)std::malloc(sizeof(TemplateIdAnnotation) + - sizeof(ParsedTemplateArgument) * NumArgs); + auto *TemplateId = (TemplateIdAnnotation *)std::malloc( + sizeof(TemplateIdAnnotation) + + sizeof(ParsedTemplateArgument) * NumArgs); TemplateId->NumArgs = NumArgs; // Default-construct nested-name-specifier. Index: include/clang/Sema/Sema.h =================================================================== --- include/clang/Sema/Sema.h +++ include/clang/Sema/Sema.h @@ -9966,7 +9966,7 @@ const DeclContext *getCurObjCLexicalContext() const { const DeclContext *DC = getCurLexicalContext(); // A category implicitly has the attribute of the interface. - if (const ObjCCategoryDecl *CatD = dyn_cast(DC)) + if (const auto *CatD = dyn_cast(DC)) DC = CatD->getClassInterface(); return DC; } Index: include/clang/Sema/Template.h =================================================================== --- include/clang/Sema/Template.h +++ include/clang/Sema/Template.h @@ -278,8 +278,8 @@ // will overwrite it on construction LocalInstantiationScope *oldScope = SemaRef.CurrentInstantiationScope; - LocalInstantiationScope *newScope = - new LocalInstantiationScope(SemaRef, CombineWithOuterScope); + auto *newScope = + new LocalInstantiationScope(SemaRef, CombineWithOuterScope); newScope->Outer = nullptr; if (Outer) @@ -298,8 +298,8 @@ if (I->second.is()) { Stored = I->second.get(); } else { - DeclArgumentPack *OldPack = I->second.get(); - DeclArgumentPack *NewPack = new DeclArgumentPack(*OldPack); + auto *OldPack = I->second.get(); + auto *NewPack = new DeclArgumentPack(*OldPack); Stored = NewPack; newScope->ArgumentPacks.push_back(NewPack); } Index: include/clang/Serialization/ASTBitCodes.h =================================================================== --- include/clang/Serialization/ASTBitCodes.h +++ include/clang/Serialization/ASTBitCodes.h @@ -114,7 +114,7 @@ static inline unsigned getHashValue(QualType T) { assert(!T.getLocalFastQualifiers() && "hash invalid for types with fast quals"); - uintptr_t v = reinterpret_cast(T.getAsOpaquePtr()); + auto v = reinterpret_cast(T.getAsOpaquePtr()); return (unsigned(v) >> 4) ^ (unsigned(v) >> 9); } }; Index: include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h =================================================================== --- include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h +++ include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h @@ -268,7 +268,7 @@ /// the extra note should appear. void addNote(StringRef Msg, const PathDiagnosticLocation &Pos, ArrayRef Ranges) { - PathDiagnosticNotePiece *P = new PathDiagnosticNotePiece(Pos, Msg); + auto *P = new PathDiagnosticNotePiece(Pos, Msg); for (const auto &R : Ranges) P->addRange(R); Index: include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h =================================================================== --- include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h +++ include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h @@ -599,8 +599,8 @@ void flattenLocations() override { callEnter.flatten(); callReturn.flatten(); - for (PathPieces::iterator I = path.begin(), - E = path.end(); I != E; ++I) (*I)->flattenLocations(); + for (auto I = path.begin(), E = path.end(); I != E; ++I) + (*I)->flattenLocations(); } static PathDiagnosticCallPiece *construct(const ExplodedNode *N, @@ -668,7 +668,8 @@ iterator end() { return LPairs.end(); } void flattenLocations() override { - for (iterator I=begin(), E=end(); I!=E; ++I) I->flatten(); + for (auto I = begin(), E = end(); I != E; ++I) + I->flatten(); } typedef std::vector::const_iterator @@ -698,8 +699,8 @@ void flattenLocations() override { PathDiagnosticSpotPiece::flattenLocations(); - for (PathPieces::iterator I = subPieces.begin(), - E = subPieces.end(); I != E; ++I) (*I)->flattenLocations(); + for (auto I = subPieces.begin(), E = subPieces.end(); I != E; ++I) + (*I)->flattenLocations(); } static inline bool classof(const PathDiagnosticPiece *P) { @@ -842,8 +843,8 @@ void flattenLocations() { Loc.flatten(); - for (PathPieces::iterator I = pathImpl.begin(), E = pathImpl.end(); - I != E; ++I) (*I)->flattenLocations(); + for (auto I = pathImpl.begin(), E = pathImpl.end(); I != E; ++I) + (*I)->flattenLocations(); } /// Profiles the diagnostic, independent of the path it references. Index: include/clang/StaticAnalyzer/Core/CheckerManager.h =================================================================== --- include/clang/StaticAnalyzer/Core/CheckerManager.h +++ include/clang/StaticAnalyzer/Core/CheckerManager.h @@ -139,7 +139,7 @@ if (ref) return static_cast(ref); // already registered. - CHECKER *checker = new CHECKER(); + auto *checker = new CHECKER(); checker->Name = CurrentCheckName; CheckerDtors.push_back(CheckerDtor(checker, destruct)); CHECKER::_register(checker, *this); @@ -154,7 +154,7 @@ if (ref) return static_cast(ref); // already registered. - CHECKER *checker = new CHECKER(AOpts); + auto *checker = new CHECKER(AOpts); checker->Name = CurrentCheckName; CheckerDtors.push_back(CheckerDtor(checker, destruct)); CHECKER::_register(checker, *this); Index: include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h =================================================================== --- include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h +++ include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h @@ -246,7 +246,7 @@ // Special case for implicitly-declared global operator new/delete. // These should be considered system functions. - if (const FunctionDecl *FD = dyn_cast(D)) + if (const auto *FD = dyn_cast(D)) return FD->isOverloadedOperator() && FD->isImplicit() && FD->isGlobal(); return false; @@ -331,7 +331,7 @@ // FIXME: Move this down to AnyFunctionCall once checkers have more // precise callbacks. const IdentifierInfo *getCalleeIdentifier() const { - const NamedDecl *ND = dyn_cast_or_null(getDecl()); + const auto *ND = dyn_cast_or_null(getDecl()); if (!ND) return nullptr; return ND->getIdentifier(); @@ -1089,7 +1089,7 @@ return cast(this); CallEventManager &Mgr = State->getStateManager().getCallEventManager(); - T *Copy = static_cast(Mgr.allocate()); + auto *Copy = static_cast(Mgr.allocate()); cloneTo(Copy); assert(Copy->getKind() == this->getKind() && "Bad copy"); Index: include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h =================================================================== --- include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h +++ include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h @@ -548,7 +548,7 @@ QualType getLocationType() const override { const ASTContext &Ctx = getContext(); - if (const FunctionDecl *D = dyn_cast(FD)) { + if (const auto *D = dyn_cast(FD)) { return Ctx.getPointerType(D->getType()); } @@ -1104,7 +1104,7 @@ template const RegionTy* MemRegion::getAs() const { - if (const RegionTy* RT = dyn_cast(this)) + if (const auto *RT = dyn_cast(this)) return RT; return nullptr; Index: include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h =================================================================== --- include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h +++ include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h @@ -730,7 +730,7 @@ inline SVal ProgramState::getSValAsScalarOrLoc(const Stmt *S, const LocationContext *LCtx) const { - if (const Expr *Ex = dyn_cast(S)) { + if (const auto *Ex = dyn_cast(S)) { QualType T = Ex->getType(); if (Ex->isGLValue() || Loc::isLocType(T) || T->isIntegralOrEnumerationType()) Index: include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h =================================================================== --- include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h +++ include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h @@ -378,21 +378,18 @@ public: Loc getLoc() const { - const std::pair *D = - static_cast *>(Data); + const auto *D = static_cast *>(Data); return D->first.castAs(); } Loc getPersistentLoc() const { - const std::pair *D = - static_cast *>(Data); + const auto *D = static_cast *>(Data); const SVal& V = D->first; return V.castAs(); } unsigned getNumBits() const { - const std::pair *D = - static_cast *>(Data); + const auto *D = static_cast *>(Data); return D->second; } Index: lib/ARCMigrate/ARCMT.cpp =================================================================== --- lib/ARCMigrate/ARCMT.cpp +++ lib/ARCMigrate/ARCMT.cpp @@ -32,7 +32,7 @@ return false; bool cleared = false; - ListTy::iterator I = List.begin(); + auto I = List.begin(); while (I != List.end()) { FullSourceLoc diagLoc = I->getLocation(); if ((IDs.empty() || // empty means clear all diagnostics in the range. @@ -41,7 +41,7 @@ (diagLoc == range.getEnd() || diagLoc.isBeforeInTranslationUnitThan(range.getEnd()))) { cleared = true; - ListTy::iterator eraseS = I++; + auto eraseS = I++; if (eraseS->getLevel() != DiagnosticsEngine::Note) while (I != List.end() && I->getLevel() == DiagnosticsEngine::Note) ++I; @@ -61,7 +61,7 @@ if (range.isInvalid()) return false; - ListTy::const_iterator I = List.begin(); + auto I = List.begin(); while (I != List.end()) { FullSourceLoc diagLoc = I->getLocation(); if ((IDs.empty() || // empty means any diagnostic in the range. @@ -79,12 +79,12 @@ } void CapturedDiagList::reportDiagnostics(DiagnosticsEngine &Diags) const { - for (ListTy::const_iterator I = List.begin(), E = List.end(); I != E; ++I) + for (auto I = List.begin(), E = List.end(); I != E; ++I) Diags.Report(*I); } bool CapturedDiagList::hasErrors() const { - for (ListTy::const_iterator I = List.begin(), E = List.end(); I != E; ++I) + for (auto I = List.begin(), E = List.end(); I != E; ++I) if (I->getLevel() >= DiagnosticsEngine::Error) return true; @@ -202,9 +202,9 @@ // Ignore -Werror flags when migrating. std::vector WarnOpts; - for (std::vector::iterator - I = CInvok->getDiagnosticOpts().Warnings.begin(), - E = CInvok->getDiagnosticOpts().Warnings.end(); I != E; ++I) { + for (auto I = CInvok->getDiagnosticOpts().Warnings.begin(), + E = CInvok->getDiagnosticOpts().Warnings.end(); + I != E; ++I) { if (!StringRef(*I).startswith("error")) WarnOpts.push_back(*I); } @@ -296,8 +296,7 @@ Unit->getPreprocessor()); if (!plistOut.empty()) { SmallVector arcDiags; - for (CapturedDiagList::iterator - I = capturedDiags.begin(), E = capturedDiags.end(); I != E; ++I) + for (auto I = capturedDiags.begin(), E = capturedDiags.end(); I != E; ++I) arcDiags.push_back(*I); writeARCDiagsToPlist(plistOut, arcDiags, Ctx.getSourceManager(), Ctx.getLangOpts()); @@ -595,8 +594,8 @@ if (DiagClient->getNumErrors()) return true; - for (Rewriter::buffer_iterator - I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) { + for (auto I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; + ++I) { FileID FID = I->first; RewriteBuffer &buf = I->second; const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID); Index: lib/ARCMigrate/FileRemapper.cpp =================================================================== --- lib/ARCMigrate/FileRemapper.cpp +++ lib/ARCMigrate/FileRemapper.cpp @@ -135,7 +135,7 @@ infoOut << origPath << '\n'; infoOut << (uint64_t)origFE->getModificationTime() << '\n'; - if (const FileEntry *FE = I->second.dyn_cast()) { + if (const auto *FE = I->second.dyn_cast()) { SmallString<200> newPath = StringRef(FE->getName()); fs::make_absolute(newPath); infoOut << newPath << '\n'; @@ -149,7 +149,7 @@ return report("Could not create file: " + tempPath.str(), Diag); llvm::raw_fd_ostream newOut(fd, /*shouldClose=*/true); - llvm::MemoryBuffer *mem = I->second.get(); + auto *mem = I->second.get(); newOut.write(mem->getBufferStart(), mem->getBufferSize()); newOut.close(); @@ -180,7 +180,7 @@ if (EC) return report(EC.message(), Diag); - llvm::MemoryBuffer *mem = I->second.get(); + auto *mem = I->second.get(); Out.write(mem->getBufferStart(), mem->getBufferSize()); Out.close(); } @@ -192,10 +192,10 @@ void FileRemapper::applyMappings(PreprocessorOptions &PPOpts) const { for (MappingsTy::const_iterator I = FromToMappings.begin(), E = FromToMappings.end(); I != E; ++I) { - if (const FileEntry *FE = I->second.dyn_cast()) { + if (const auto *FE = I->second.dyn_cast()) { PPOpts.addRemappedFile(I->first->getName(), FE->getName()); } else { - llvm::MemoryBuffer *mem = I->second.get(); + auto *mem = I->second.get(); PPOpts.addRemappedFile(I->first->getName(), mem); } } @@ -242,10 +242,10 @@ if (!targ) return; - if (llvm::MemoryBuffer *oldmem = targ.dyn_cast()) { + if (auto *oldmem = targ.dyn_cast()) { delete oldmem; } else { - const FileEntry *toFE = targ.get(); + const auto *toFE = targ.get(); ToFromMappings.erase(toFE); } } Index: lib/ARCMigrate/ObjCMT.cpp =================================================================== --- lib/ARCMigrate/ObjCMT.cpp +++ lib/ARCMigrate/ObjCMT.cpp @@ -165,11 +165,11 @@ bool canModify(const Decl *D) { if (!D) return false; - if (const ObjCCategoryImplDecl *CatImpl = dyn_cast(D)) + if (const auto *CatImpl = dyn_cast(D)) return canModify(CatImpl->getCategoryDecl()); - if (const ObjCImplementationDecl *Impl = dyn_cast(D)) + if (const auto *Impl = dyn_cast(D)) return canModify(Impl->getClassInterface()); - if (const ObjCMethodDecl *MD = dyn_cast(D)) + if (const auto *MD = dyn_cast(D)) return canModify(cast(MD->getDeclContext())); FileID FID = PP.getSourceManager().getFileID(D->getLocation()); @@ -192,8 +192,7 @@ std::unique_ptr ObjCMigrateAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { - PPConditionalDirectiveRecord * - PPRec = new PPConditionalDirectiveRecord(CompInst->getSourceManager()); + auto *PPRec = new PPConditionalDirectiveRecord(CompInst->getSourceManager()); CI.getPreprocessor().addPPCallbacks(std::unique_ptr(PPRec)); std::vector> Consumers; Consumers.push_back(WrapperFrontendAction::CreateASTConsumer(CI, InFile)); @@ -429,8 +428,7 @@ if (RetainableObject && (propertyLifetime == Qualifiers::OCL_Strong || propertyLifetime == Qualifiers::OCL_None)) { - if (const ObjCObjectPointerType *ObjPtrTy = - ArgType->getAs()) { + if (const auto *ObjPtrTy = ArgType->getAs()) { ObjCInterfaceDecl *IDecl = ObjPtrTy->getObjectType()->getInterface(); if (IDecl && IDecl->lookupNestedProtocol(&Context.Idents.get("NSCopying"))) @@ -561,7 +559,7 @@ } static bool IsCategoryNameWithDeprecatedSuffix(ObjCContainerDecl *D) { - if (ObjCCategoryDecl *CatDecl = dyn_cast(D)) { + if (auto *CatDecl = dyn_cast(D)) { StringRef Name = CatDecl->getName(); return Name.endswith("Deprecated"); } @@ -618,12 +616,11 @@ Property->getDeclName().getAsIdentifierInfo(), Property->getQueryKind())) return false; - } - else if (ObjCPropertyDecl *ClassProperty = dyn_cast(R[0])) { - if ((ClassProperty->getPropertyAttributes() - != Property->getPropertyAttributes()) || - !Ctx.hasSameType(ClassProperty->getType(), Property->getType())) - return false; + } else if (auto *ClassProperty = dyn_cast(R[0])) { + if ((ClassProperty->getPropertyAttributes() != + Property->getPropertyAttributes()) || + !Ctx.hasSameType(ClassProperty->getType(), Property->getType())) + return false; } else return false; @@ -647,7 +644,7 @@ bool match = false; HasAtleastOneRequiredMethod = true; for (unsigned I = 0, N = R.size(); I != N; ++I) - if (ObjCMethodDecl *ImpMD = dyn_cast(R[0])) + if (auto *ImpMD = dyn_cast(R[0])) if (Ctx.ObjCMethodsAreEqual(MD, ImpMD)) { match = true; break; @@ -798,7 +795,7 @@ continue; } InitExpr = InitExpr->IgnoreParenCasts(); - if (const BinaryOperator *BO = dyn_cast(InitExpr)) + if (const auto *BO = dyn_cast(InitExpr)) if (BO->isShiftOp() || BO->isBitwiseOp()) return true; @@ -1025,12 +1022,12 @@ } if (!OM->getReturnType()->isObjCIdType()) return; - - ObjCInterfaceDecl *IDecl = dyn_cast(CDecl); + + auto *IDecl = dyn_cast(CDecl); if (!IDecl) { - if (ObjCCategoryDecl *CatDecl = dyn_cast(CDecl)) + if (auto *CatDecl = dyn_cast(CDecl)) IDecl = CatDecl->getClassInterface(); - else if (ObjCImplDecl *ImpDecl = dyn_cast(CDecl)) + else if (auto *ImpDecl = dyn_cast(CDecl)) IDecl = ImpDecl->getClassInterface(); } if (!IDecl || @@ -1051,11 +1048,11 @@ // Also, typedef-of-pointer-to-incomplete-struct is something that we assume // is not an innter pointer type. QualType OrigT = T; - while (const TypedefType *TD = dyn_cast(T.getTypePtr())) + while (const auto *TD = dyn_cast(T.getTypePtr())) T = TD->getDecl()->getUnderlyingType(); if (OrigT == T || !T->isPointerType()) return true; - const PointerType* PT = T->getAs(); + const auto *PT = T->getAs(); QualType UPointeeT = PT->getPointeeType().getUnqualifiedType(); if (UPointeeT->isRecordType()) { const RecordType *RecordTy = UPointeeT->getAs(); @@ -1297,11 +1294,11 @@ // Candidate factory methods are + (id) NaMeXXX : ... which belong to a class // NSYYYNamE with matching names be at least 3 characters long. - ObjCInterfaceDecl *IDecl = dyn_cast(CDecl); + auto *IDecl = dyn_cast(CDecl); if (!IDecl) { - if (ObjCCategoryDecl *CatDecl = dyn_cast(CDecl)) + if (auto *CatDecl = dyn_cast(CDecl)) IDecl = CatDecl->getClassInterface(); - else if (ObjCImplDecl *ImpDecl = dyn_cast(CDecl)) + else if (auto *ImpDecl = dyn_cast(CDecl)) IDecl = ImpDecl->getClassInterface(); } if (!IDecl) @@ -1353,12 +1350,12 @@ static bool IsVoidStarType(QualType Ty) { if (!Ty->isPointerType()) return false; - - while (const TypedefType *TD = dyn_cast(Ty.getTypePtr())) + + while (const auto *TD = dyn_cast(Ty.getTypePtr())) Ty = TD->getDecl()->getUnderlyingType(); // Is the type void*? - const PointerType* PT = Ty->getAs(); + const auto *PT = Ty->getAs(); if (PT->getPointeeType().getUnqualifiedType()->isVoidType()) return true; return IsVoidStarType(PT->getPointeeType()); @@ -1427,7 +1424,7 @@ } // Finction must be annotated first. - if (const FunctionDecl *FuncDecl = dyn_cast(Decl)) { + if (const auto *FuncDecl = dyn_cast(Decl)) { CF_BRIDGING_KIND AuditKind = migrateAddFunctionAnnotation(Ctx, FuncDecl); if (AuditKind == CF_BRIDGING_ENABLE) { CFFunctionIBCandidates.push_back(Decl); @@ -1846,15 +1843,14 @@ if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) AnnotateImplicitBridging(Ctx); } - - if (ObjCInterfaceDecl *CDecl = dyn_cast(*D)) + + if (auto *CDecl = dyn_cast(*D)) if (canModify(CDecl)) migrateObjCContainerDecl(Ctx, CDecl); - if (ObjCCategoryDecl *CatDecl = dyn_cast(*D)) { + if (auto *CatDecl = dyn_cast(*D)) { if (canModify(CatDecl)) migrateObjCContainerDecl(Ctx, CatDecl); - } - else if (ObjCProtocolDecl *PDecl = dyn_cast(*D)) { + } else if (auto *PDecl = dyn_cast(*D)) { ObjCProtocolDecls.insert(PDecl->getCanonicalDecl()); if (canModify(PDecl)) migrateObjCContainerDecl(Ctx, PDecl); @@ -1911,8 +1907,8 @@ canModify(FD)) migrateCFAnnotation(Ctx, FD); } - - if (ObjCContainerDecl *CDecl = dyn_cast(*D)) { + + if (auto *CDecl = dyn_cast(*D)) { bool CanModify = canModify(CDecl); // migrate methods which can have instancetype as their result type. if ((ASTMigrateActions & FrontendOptions::ObjCMT_Instancetype) && @@ -1954,8 +1950,8 @@ RewritesReceiver Rec(rewriter); Editor->applyRewrites(Rec); - for (Rewriter::buffer_iterator - I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) { + for (auto I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; + ++I) { FileID FID = I->first; RewriteBuffer &buf = I->second; const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID); @@ -2004,8 +2000,7 @@ std::unique_ptr MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { - PPConditionalDirectiveRecord * - PPRec = new PPConditionalDirectiveRecord(CI.getSourceManager()); + auto *PPRec = new PPConditionalDirectiveRecord(CI.getSourceManager()); unsigned ObjCMTAction = CI.getFrontendOpts().ObjCMTAction; unsigned ObjCMTOpts = ObjCMTAction; // These are companion flags, they do not enable transformations. @@ -2090,13 +2085,13 @@ if (!Root) return true; - SequenceNode *SeqNode = dyn_cast(Root); + auto *SeqNode = dyn_cast(Root); if (!SeqNode) return true; for (SequenceNode::iterator AI = SeqNode->begin(), AE = SeqNode->end(); AI != AE; ++AI) { - MappingNode *MapNode = dyn_cast(&*AI); + auto *MapNode = dyn_cast(&*AI); if (!MapNode) continue; parseEdit(MapNode, Entries); @@ -2114,13 +2109,13 @@ for (MappingNode::iterator KVI = Node->begin(), KVE = Node->end(); KVI != KVE; ++KVI) { - ScalarNode *KeyString = dyn_cast((*KVI).getKey()); + auto *KeyString = dyn_cast((*KVI).getKey()); if (!KeyString) continue; SmallString<10> KeyStorage; StringRef Key = KeyString->getValue(KeyStorage); - ScalarNode *ValueString = dyn_cast((*KVI).getValue()); + auto *ValueString = dyn_cast((*KVI).getValue()); if (!ValueString) continue; SmallString<64> ValueStorage; Index: lib/ARCMigrate/PlistReporter.cpp =================================================================== --- lib/ARCMigrate/PlistReporter.cpp +++ lib/ARCMigrate/PlistReporter.cpp @@ -49,8 +49,7 @@ AddFID(FM, Fids, SM, D.getLocation()); - for (StoredDiagnostic::range_iterator - RI = D.range_begin(), RE = D.range_end(); RI != RE; ++RI) { + for (auto RI = D.range_begin(), RE = D.range_end(); RI != RE; ++RI) { AddFID(FM, Fids, SM, RI->getBegin()); AddFID(FM, Fids, SM, RI->getEnd()); } Index: lib/ARCMigrate/TransARCAssign.cpp =================================================================== --- lib/ARCMigrate/TransARCAssign.cpp +++ lib/ARCMigrate/TransARCAssign.cpp @@ -46,13 +46,13 @@ Expr *E = Exp->getLHS(); SourceLocation OrigLoc = E->getExprLoc(); SourceLocation Loc = OrigLoc; - DeclRefExpr *declRef = dyn_cast(E->IgnoreParenCasts()); + auto *declRef = dyn_cast(E->IgnoreParenCasts()); if (declRef && isa(declRef->getDecl())) { ASTContext &Ctx = Pass.Ctx; Expr::isModifiableLvalueResult IsLV = E->isModifiableLvalue(Ctx, &Loc); if (IsLV != Expr::MLV_ConstQualified) return true; - VarDecl *var = cast(declRef->getDecl()); + auto *var = cast(declRef->getDecl()); if (var->isARCPseudoStrong()) { Transaction Trans(Pass.TA); if (Pass.TA.clearDiagnostic(diag::err_typecheck_arr_assign_enumeration, Index: lib/ARCMigrate/TransAutoreleasePool.cpp =================================================================== --- lib/ARCMigrate/TransAutoreleasePool.cpp +++ lib/ARCMigrate/TransAutoreleasePool.cpp @@ -54,7 +54,7 @@ if (E->getMethodFamily() != OMF_release) return true; Expr *instance = E->getInstanceReceiver()->IgnoreParenCasts(); - if (DeclRefExpr *DE = dyn_cast(instance)) { + if (auto *DE = dyn_cast(instance)) { if (DE->getDecl() == Dcl) Releases.push_back(E); } @@ -84,8 +84,7 @@ ~AutoreleasePoolRewriter() { SmallVector VarsToHandle; - for (std::map::iterator - I = PoolVars.begin(), E = PoolVars.end(); I != E; ++I) { + for (auto I = PoolVars.begin(), E = PoolVars.end(); I != E; ++I) { VarDecl *var = I->first; PoolVarInfo &info = I->second; @@ -167,9 +166,9 @@ for (Stmt::child_iterator I = S->body_begin(), E = S->body_end(); I != E; ++I) { Stmt *child = getEssential(*I); - if (DeclStmt *DclS = dyn_cast(child)) { + if (auto *DclS = dyn_cast(child)) { if (DclS->isSingleDecl()) { - if (VarDecl *VD = dyn_cast(DclS->getSingleDecl())) { + if (auto *VD = dyn_cast(DclS->getSingleDecl())) { if (isNSAutoreleasePool(VD->getType())) { PoolVarInfo &info = PoolVars[VD]; info.Dcl = DclS; @@ -185,9 +184,9 @@ } } } - } else if (BinaryOperator *bop = dyn_cast(child)) { - if (DeclRefExpr *dref = dyn_cast(bop->getLHS())) { - if (VarDecl *VD = dyn_cast(dref->getDecl())) { + } else if (auto *bop = dyn_cast(child)) { + if (auto *dref = dyn_cast(bop->getLHS())) { + if (auto *VD = dyn_cast(dref->getDecl())) { // Does this statement follow the pattern: // pool = [NSAutoreleasePool new]; if (isNSAutoreleasePool(VD->getType()) && @@ -304,7 +303,7 @@ // Check if the autoreleasepool scope is followed by a simple return // statement, in which case we will include the return in the scope. if (SI != SE) - if (ReturnStmt *retS = dyn_cast(*SI)) + if (auto *retS = dyn_cast(*SI)) if ((retS->getRetValue() == nullptr || isa(retS->getRetValue()->IgnoreParenCasts())) && findLocationAfterSemi(retS->getLocEnd(), Pass.Ctx).isValid()) { @@ -350,7 +349,7 @@ bool isPoolCreation(Expr *E) { if (!E) return false; E = getEssential(E); - ObjCMessageExpr *ME = dyn_cast(E); + auto *ME = dyn_cast(E); if (!ME) return false; if (ME->getMethodFamily() == OMF_new && ME->getReceiverKind() == ObjCMessageExpr::Class && @@ -359,7 +358,7 @@ if (ME->getReceiverKind() == ObjCMessageExpr::Instance && ME->getMethodFamily() == OMF_init) { Expr *rec = getEssential(ME->getInstanceReceiver()); - if (ObjCMessageExpr *recME = dyn_cast_or_null(rec)) { + if (auto *recME = dyn_cast_or_null(rec)) { if (recME->getMethodFamily() == OMF_alloc && recME->getReceiverKind() == ObjCMessageExpr::Class && isNSAutoreleasePool(recME->getReceiverInterface())) @@ -373,11 +372,11 @@ bool isPoolDrain(VarDecl *poolVar, Stmt *S) { if (!S) return false; S = getEssential(S); - ObjCMessageExpr *ME = dyn_cast(S); + auto *ME = dyn_cast(S); if (!ME) return false; if (ME->getReceiverKind() == ObjCMessageExpr::Instance) { Expr *rec = getEssential(ME->getInstanceReceiver()); - if (DeclRefExpr *dref = dyn_cast(rec)) + if (auto *dref = dyn_cast(rec)) if (dref->getDecl() == poolVar) return ME->getMethodFamily() == OMF_release || ME->getSelector() == DrainSel; @@ -403,9 +402,9 @@ return cast(getEssential((Stmt*)E)); } static Stmt *getEssential(Stmt *S) { - if (ExprWithCleanups *EWC = dyn_cast(S)) + if (auto *EWC = dyn_cast(S)) S = EWC->getSubExpr(); - if (Expr *E = dyn_cast(S)) + if (auto *E = dyn_cast(S)) S = E->IgnoreParenCasts(); return S; } Index: lib/ARCMigrate/TransBlockObjCVariable.cpp =================================================================== --- lib/ARCMigrate/TransBlockObjCVariable.cpp +++ lib/ARCMigrate/TransBlockObjCVariable.cpp @@ -49,8 +49,7 @@ BlockVarChecker(VarDecl *var) : Var(var) { } bool TraverseImplicitCastExpr(ImplicitCastExpr *castE) { - if (DeclRefExpr * - ref = dyn_cast(castE->getSubExpr())) { + if (auto *ref = dyn_cast(castE->getSubExpr())) { if (ref->getDecl() == Var) { if (castE->getCastKind() == CK_LValueToRValue) return true; // Using the value of the variable. @@ -134,7 +133,7 @@ for (llvm::DenseSet::iterator I = VarsToChange.begin(), E = VarsToChange.end(); I != E; ++I) { VarDecl *var = *I; - BlocksAttr *attr = var->getAttr(); + auto *attr = var->getAttr(); if(!attr) continue; bool useWeak = canApplyWeak(Pass.Ctx, var->getType()); Index: lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp =================================================================== --- lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp +++ lib/ARCMigrate/TransEmptyStatementsAndDealloc.cpp @@ -43,9 +43,8 @@ return false; SourceManager &SM = Ctx.getSourceManager(); - std::vector::iterator - I = std::upper_bound(MacroLocs.begin(), MacroLocs.end(), SemiLoc, - BeforeThanCompare(SM)); + auto I = std::upper_bound(MacroLocs.begin(), MacroLocs.end(), SemiLoc, + BeforeThanCompare(SM)); --I; SourceLocation AfterMacroLoc = I->getLocWithOffset(getARCMTMacroName().size()); Index: lib/ARCMigrate/TransGCAttrs.cpp =================================================================== --- lib/ARCMigrate/TransGCAttrs.cpp +++ lib/ARCMigrate/TransGCAttrs.cpp @@ -48,11 +48,11 @@ return true; SaveAndRestore Save(FullyMigratable, isMigratable(D)); - - if (ObjCPropertyDecl *PropD = dyn_cast(D)) { + + if (auto *PropD = dyn_cast(D)) { lookForAttribute(PropD, PropD->getTypeSourceInfo()); AllProps.push_back(PropD); - } else if (DeclaratorDecl *DD = dyn_cast(D)) { + } else if (auto *DD = dyn_cast(D)) { lookForAttribute(DD, DD->getTypeSourceInfo()); } return base::TraverseDecl(D); @@ -127,13 +127,13 @@ if (isInMainFile(D)) return true; - if (FunctionDecl *FD = dyn_cast(D)) + if (auto *FD = dyn_cast(D)) return FD->hasBody(); - if (ObjCContainerDecl *ContD = dyn_cast(D)) + if (auto *ContD = dyn_cast(D)) return hasObjCImpl(ContD); - if (CXXRecordDecl *RD = dyn_cast(D)) { + if (auto *RD = dyn_cast(D)) { for (const auto *MI : RD->methods()) { if (MI->isOutOfLine()) return true; @@ -147,10 +147,10 @@ static bool hasObjCImpl(Decl *D) { if (!D) return false; - if (ObjCContainerDecl *ContD = dyn_cast(D)) { - if (ObjCInterfaceDecl *ID = dyn_cast(ContD)) + if (auto *ContD = dyn_cast(D)) { + if (auto *ID = dyn_cast(ContD)) return ID->getImplementation() != nullptr; - if (ObjCCategoryDecl *CD = dyn_cast(ContD)) + if (auto *CD = dyn_cast(ContD)) return CD->getImplementation() != nullptr; return isa(ContD); } Index: lib/ARCMigrate/TransGCCalls.cpp =================================================================== --- lib/ARCMigrate/TransGCCalls.cpp +++ lib/ARCMigrate/TransGCCalls.cpp @@ -44,8 +44,8 @@ } Expr *CEE = E->getCallee()->IgnoreParenImpCasts(); - if (DeclRefExpr *DRE = dyn_cast(CEE)) { - if (FunctionDecl *FD = dyn_cast_or_null(DRE->getDecl())) { + if (auto *DRE = dyn_cast(CEE)) { + if (auto *FD = dyn_cast_or_null(DRE->getDecl())) { if (!FD->getDeclContext()->getRedeclContext()->isFileContext()) return true; Index: lib/ARCMigrate/TransProperties.cpp =================================================================== --- lib/ARCMigrate/TransProperties.cpp +++ lib/ARCMigrate/TransProperties.cpp @@ -115,7 +115,7 @@ if (!ivarD || ivarD->isInvalidDecl()) continue; unsigned rawAtLoc = propD->getAtLoc().getRawEncoding(); - AtPropDeclsTy::iterator findAtLoc = AtProps.find(rawAtLoc); + auto findAtLoc = AtProps.find(rawAtLoc); if (findAtLoc == AtProps.end()) continue; @@ -129,8 +129,7 @@ } } - for (AtPropDeclsTy::iterator - I = AtProps.begin(), E = AtProps.end(); I != E; ++I) { + for (auto I = AtProps.begin(), E = AtProps.end(); I != E; ++I) { SourceLocation atLoc = SourceLocation::getFromRawEncoding(I->first); PropsTy &props = I->second; if (!getPropertyType(props)->isObjCRetainableType()) @@ -290,7 +289,7 @@ bool VisitBinAssign(BinaryOperator *E) { Expr *lhs = E->getLHS()->IgnoreParenImpCasts(); - if (ObjCIvarRefExpr *RE = dyn_cast(lhs)) { + if (auto *RE = dyn_cast(lhs)) { if (RE->getDecl() != Ivar) return true; Index: lib/ARCMigrate/TransRetainReleaseDealloc.cpp =================================================================== --- lib/ARCMigrate/TransRetainReleaseDealloc.cpp +++ lib/ARCMigrate/TransRetainReleaseDealloc.cpp @@ -190,7 +190,7 @@ // Check for "return ;". - if (ReturnStmt *RetS = dyn_cast(nextStmt)) + if (auto *RetS = dyn_cast(nextStmt)) return RefD == getReferencedDecl(RetS->getRetValue()); return false; @@ -218,13 +218,13 @@ // Check for "RefD = [+1 retained object];". - if (BinaryOperator *Bop = dyn_cast(S)) { + if (auto *Bop = dyn_cast(S)) { return (RefD == getReferencedDecl(Bop->getLHS())) && isPlusOneAssign(Bop); } - if (DeclStmt *DS = dyn_cast(S)) { + if (auto *DS = dyn_cast(S)) { if (DS->isSingleDecl() && DS->getSingleDecl() == RefD) { - if (VarDecl *VD = dyn_cast(RefD)) + if (auto *VD = dyn_cast(RefD)) return isPlusOne(VD->getInit()); } return false; @@ -287,7 +287,7 @@ return nullptr; E = E->IgnoreParenCasts(); - if (ObjCMessageExpr *ME = dyn_cast(E)) { + if (auto *ME = dyn_cast(E)) { switch (ME->getMethodFamily()) { case OMF_copy: case OMF_autorelease: @@ -298,11 +298,11 @@ return nullptr; } } - if (DeclRefExpr *DRE = dyn_cast(E)) + if (auto *DRE = dyn_cast(E)) return DRE->getDecl(); - if (MemberExpr *ME = dyn_cast(E)) + if (auto *ME = dyn_cast(E)) return ME->getMemberDecl(); - if (ObjCIvarRefExpr *IRE = dyn_cast(E)) + if (auto *IRE = dyn_cast(E)) return IRE->getDecl(); return nullptr; @@ -338,7 +338,7 @@ StmtExpr *StmtE = nullptr; Stmt *S = Msg; while (S) { - if (StmtExpr *SE = dyn_cast(S)) { + if (auto *SE = dyn_cast(S)) { StmtE = SE; break; } @@ -363,7 +363,7 @@ return; if (!DeclS->isSingleDecl()) return; - VarDecl *VD = dyn_cast_or_null(DeclS->getSingleDecl()); + auto *VD = dyn_cast_or_null(DeclS->getSingleDecl()); if (!VD) return; Expr *Init = VD->getInit(); @@ -372,7 +372,7 @@ RecContainer = StmtE; Rec = Init->IgnoreParenImpCasts(); - if (ExprWithCleanups *EWC = dyn_cast(Rec)) + if (auto *EWC = dyn_cast(Rec)) Rec = EWC->getSubExpr()->IgnoreParenImpCasts(); RecRange = Rec->getSourceRange(); if (SM.isMacroArgExpansion(RecRange.getBegin())) @@ -394,10 +394,10 @@ E = E->IgnoreParenCasts(); // Also look through property-getter sugar. - if (PseudoObjectExpr *pseudoOp = dyn_cast(E)) + if (auto *pseudoOp = dyn_cast(E)) E = pseudoOp->getResultExpr()->IgnoreImplicit(); - if (ObjCMessageExpr *ME = dyn_cast(E)) + if (auto *ME = dyn_cast(E)) return (ME->isInstanceMessage() && ME->getSelector() == DelegateSel); return false; @@ -427,14 +427,13 @@ Stmt *parent = StmtMap->getParent(E); - if (ImplicitCastExpr *castE = dyn_cast_or_null(parent)) + if (auto *castE = dyn_cast_or_null(parent)) return tryRemoving(castE); - if (ParenExpr *parenE = dyn_cast_or_null(parent)) + if (auto *parenE = dyn_cast_or_null(parent)) return tryRemoving(parenE); - if (BinaryOperator * - bopE = dyn_cast_or_null(parent)) { + if (auto *bopE = dyn_cast_or_null(parent)) { if (bopE->getOpcode() == BO_Comma && bopE->getLHS() == E && isRemovable(bopE)) { Pass.TA.replace(bopE->getSourceRange(), bopE->getRHS()->getSourceRange()); Index: lib/ARCMigrate/TransUnbridgedCasts.cpp =================================================================== --- lib/ARCMigrate/TransUnbridgedCasts.cpp +++ lib/ARCMigrate/TransUnbridgedCasts.cpp @@ -132,7 +132,7 @@ // If the cast is directly over the result of a Core Foundation function // try to figure out whether it should be cast as retained or unretained. Expr *inner = E->IgnoreParenCasts(); - if (CallExpr *callE = dyn_cast(inner)) { + if (auto *callE = dyn_cast(inner)) { if (FunctionDecl *FD = callE->getDirectCallee()) { if (FD->hasAttr()) { castToObjCObject(E, /*retained=*/true); @@ -184,7 +184,7 @@ base = cast(base)->getBase()->IgnoreParenImpCasts(); if (isa(base) && isa(StmtMap->getParentIgnoreParenCasts(E))) { - if (ObjCMethodDecl *method = dyn_cast_or_null(ParentD)) { + if (auto *method = dyn_cast_or_null(ParentD)) { if (!method->hasAttr()) { castToObjCObject(E, /*retained=*/false); return; @@ -228,7 +228,7 @@ diag::err_arc_cast_requires_bridge, E->getLocStart()); if (Kind == OBC_Bridge || !Pass.CFBridgingFunctionsDefined()) { - if (CStyleCastExpr *CCE = dyn_cast(E)) { + if (auto *CCE = dyn_cast(E)) { TA.insertAfterToken(CCE->getLParenLoc(), bridge); } else { SourceLocation insertLoc = E->getSubExpr()->getLocStart(); @@ -376,7 +376,7 @@ parent = StmtMap->getParentIgnoreParenImpCasts(parent); } while (parent && isa(parent)); - if (ReturnStmt *retS = dyn_cast_or_null(parent)) { + if (auto *retS = dyn_cast_or_null(parent)) { std::string note = "remove the cast and change return type of function " "to '"; note += E->getSubExpr()->getType().getAsString(Pass.Ctx.getPrintingPolicy()); @@ -388,12 +388,12 @@ Expr *subExpr = E->getSubExpr(); // Look through pseudo-object expressions. - if (PseudoObjectExpr *pseudo = dyn_cast(subExpr)) { + if (auto *pseudo = dyn_cast(subExpr)) { subExpr = pseudo->getResultExpr(); assert(subExpr && "no result for pseudo-object of non-void type?"); } - if (ImplicitCastExpr *implCE = dyn_cast(subExpr)) { + if (auto *implCE = dyn_cast(subExpr)) { if (implCE->getCastKind() == CK_ARCConsumeObject) return rewriteToBridgedCast(E, OBC_BridgeRetained); if (implCE->getCastKind() == CK_ARCReclaimReturnedObject) @@ -408,7 +408,7 @@ static ObjCMethodFamily getFamilyOfMessage(Expr *E) { E = E->IgnoreParenCasts(); - if (ObjCMessageExpr *ME = dyn_cast(E)) + if (auto *ME = dyn_cast(E)) return ME->getMethodFamily(); return OMF_None; @@ -417,8 +417,7 @@ bool isPassedToCFRetain(Expr *E, CallExpr *&callE) const { if ((callE = dyn_cast_or_null( StmtMap->getParentIgnoreParenImpCasts(E)))) - if (FunctionDecl * - FD = dyn_cast_or_null(callE->getCalleeDecl())) + if (auto *FD = dyn_cast_or_null(callE->getCalleeDecl())) if (FD->getName() == "CFRetain" && FD->getNumParams() == 1 && FD->getParent()->isTranslationUnit() && FD->isExternallyVisible()) @@ -428,10 +427,9 @@ } bool isPassedToCParamWithKnownOwnership(Expr *E, bool &isConsumed) const { - if (CallExpr *callE = dyn_cast_or_null( - StmtMap->getParentIgnoreParenImpCasts(E))) - if (FunctionDecl * - FD = dyn_cast_or_null(callE->getCalleeDecl())) { + if (auto *callE = dyn_cast_or_null( + StmtMap->getParentIgnoreParenImpCasts(E))) + if (auto *FD = dyn_cast_or_null(callE->getCalleeDecl())) { unsigned i = 0; for (unsigned e = callE->getNumArgs(); i != e; ++i) { Expr *arg = callE->getArg(i); @@ -452,8 +450,8 @@ bool isSelf(Expr *E) const { E = E->IgnoreParenLValueCasts(); - if (DeclRefExpr *DRE = dyn_cast(E)) - if (ImplicitParamDecl *IPD = dyn_cast(DRE->getDecl())) + if (auto *DRE = dyn_cast(E)) + if (auto *IPD = dyn_cast(DRE->getDecl())) if (IPD->getIdentifier() == SelfII) return true; Index: lib/ARCMigrate/TransZeroOutPropsInDealloc.cpp =================================================================== --- lib/ARCMigrate/TransZeroOutPropsInDealloc.cpp +++ lib/ARCMigrate/TransZeroOutPropsInDealloc.cpp @@ -50,7 +50,7 @@ if (!receiver) return true; - DeclRefExpr *refE = dyn_cast(receiver->IgnoreParenCasts()); + auto *refE = dyn_cast(receiver->IgnoreParenCasts()); if (!refE || refE->getDecl() != SelfD) return true; @@ -104,7 +104,7 @@ if (!D->hasBody()) return true; - ObjCImplDecl *IMD = dyn_cast(D->getDeclContext()); + auto *IMD = dyn_cast(D->getDeclContext()); if (!IMD) return true; @@ -151,9 +151,9 @@ bool isZeroingPropIvar(Expr *E) { E = E->IgnoreParens(); - if (BinaryOperator *BO = dyn_cast(E)) + if (auto *BO = dyn_cast(E)) return isZeroingPropIvar(BO); - if (PseudoObjectExpr *PO = dyn_cast(E)) + if (auto *PO = dyn_cast(E)) return isZeroingPropIvar(PO); return false; } @@ -167,7 +167,7 @@ return false; Expr *LHS = BOE->getLHS(); - if (ObjCIvarRefExpr *IV = dyn_cast(LHS)) { + if (auto *IV = dyn_cast(LHS)) { ObjCIvarDecl *IVDecl = IV->getDecl(); if (!IVDecl->getType()->isObjCObjectPointerType()) return false; @@ -191,12 +191,12 @@ } bool isZeroingPropIvar(PseudoObjectExpr *PO) { - BinaryOperator *BO = dyn_cast(PO->getSyntacticForm()); + auto *BO = dyn_cast(PO->getSyntacticForm()); if (!BO) return false; if (BO->getOpcode() != BO_Assign) return false; - ObjCPropertyRefExpr *PropRefExp = - dyn_cast(BO->getLHS()->IgnoreParens()); + auto *PropRefExp = + dyn_cast(BO->getLHS()->IgnoreParens()); if (!PropRefExp) return false; // TODO: Using implicit property decl. Index: lib/ARCMigrate/TransformActions.cpp =================================================================== --- lib/ARCMigrate/TransformActions.cpp +++ lib/ARCMigrate/TransformActions.cpp @@ -451,7 +451,7 @@ if (StmtRemovals.count(S)) return; // already removed. - if (Expr *E = dyn_cast(S)) { + if (auto *E = dyn_cast(S)) { commitRemove(E->getSourceRange()); commitInsert(E->getSourceRange().getBegin(), getARCMTMacroName()); } else @@ -523,9 +523,9 @@ Inserts.erase(Inserts.upper_bound(newRange.Begin), Inserts.lower_bound(newRange.End)); - std::list::iterator I = Removals.end(); + auto I = Removals.end(); while (I != Removals.begin()) { - std::list::iterator RI = I; + auto RI = I; --RI; RangeComparison comp = newRange.compareWith(*RI); switch (comp) { @@ -554,7 +554,7 @@ void TransformActionsImpl::applyRewrites( TransformActions::RewriteReceiver &receiver) { - for (InsertsMap::iterator I = Inserts.begin(), E = Inserts.end(); I!=E; ++I) { + for (auto I = Inserts.begin(), E = Inserts.end(); I != E; ++I) { SourceLocation loc = I->first; for (TextsVec::iterator TI = I->second.begin(), TE = I->second.end(); TI != TE; ++TI) { @@ -562,15 +562,14 @@ } } - for (std::vector >::iterator - I = IndentationRanges.begin(), E = IndentationRanges.end(); I!=E; ++I) { + for (auto I = IndentationRanges.begin(), E = IndentationRanges.end(); I != E; + ++I) { CharSourceRange range = CharSourceRange::getCharRange(I->first.Begin, I->first.End); receiver.increaseIndentation(range, I->second); } - for (std::list::iterator - I = Removals.begin(), E = Removals.end(); I != E; ++I) { + for (auto I = Removals.begin(), E = Removals.end(); I != E; ++I) { CharSourceRange range = CharSourceRange::getCharRange(I->Begin, I->End); receiver.remove(range); } Index: lib/ARCMigrate/Transforms.cpp =================================================================== --- lib/ARCMigrate/Transforms.cpp +++ lib/ARCMigrate/Transforms.cpp @@ -49,9 +49,9 @@ Ctx.getTargetInfo().getTriple().isWatchOS()) AllowOnUnknownClass = true; - while (const PointerType *ptr = T->getAs()) + while (const auto *ptr = T->getAs()) T = ptr->getPointeeType(); - if (const ObjCObjectPointerType *ObjT = T->getAs()) { + if (const auto *ObjT = T->getAs()) { ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl(); if (!AllowOnUnknownClass && (!Class || Class->getName() == "NSObject")) return false; // id/NSObject is not safe for weak. @@ -74,16 +74,14 @@ bool trans::isPlusOne(const Expr *E) { if (!E) return false; - if (const ExprWithCleanups *EWC = dyn_cast(E)) + if (const auto *EWC = dyn_cast(E)) E = EWC->getSubExpr(); - if (const ObjCMessageExpr * - ME = dyn_cast(E->IgnoreParenCasts())) + if (const auto *ME = dyn_cast(E->IgnoreParenCasts())) if (ME->getMethodFamily() == OMF_retain) return true; - if (const CallExpr * - callE = dyn_cast(E->IgnoreParenCasts())) { + if (const auto *callE = dyn_cast(E->IgnoreParenCasts())) { if (const FunctionDecl *FD = callE->getDirectCallee()) { if (FD->hasAttr()) return true; @@ -104,7 +102,7 @@ } } - const ImplicitCastExpr *implCE = dyn_cast(E); + const auto *implCE = dyn_cast(E); while (implCE && implCE->getCastKind() == CK_BitCast) implCE = dyn_cast(implCE->getSubExpr()); @@ -170,7 +168,7 @@ return false; E = E->IgnoreParenCasts(); - ObjCMessageExpr *ME = dyn_cast(E); + auto *ME = dyn_cast(E); if (!ME) return true; switch (ME->getMethodFamily()) { @@ -196,10 +194,10 @@ bool trans::isGlobalVar(Expr *E) { E = E->IgnoreParenCasts(); - if (DeclRefExpr *DRE = dyn_cast(E)) + if (auto *DRE = dyn_cast(E)) return DRE->getDecl()->getDeclContext()->isFileContext() && DRE->getDecl()->isExternallyVisible(); - if (ConditionalOperator *condOp = dyn_cast(E)) + if (auto *condOp = dyn_cast(E)) return isGlobalVar(condOp->getTrueExpr()) && isGlobalVar(condOp->getFalseExpr()); @@ -286,11 +284,11 @@ private: void mark(Stmt *S) { if (!S) return; - - while (LabelStmt *Label = dyn_cast(S)) + + while (auto *Label = dyn_cast(S)) S = Label->getSubStmt(); S = S->IgnoreImplicit(); - if (Expr *E = dyn_cast(S)) + if (auto *E = dyn_cast(S)) Removables.insert(E); } }; @@ -326,9 +324,9 @@ bool TraverseObjCImplementationDecl(ObjCImplementationDecl *D) { ObjCImplementationContext ImplCtx(MigrateCtx, D); - for (MigrationContext::traverser_iterator - I = MigrateCtx.traversers_begin(), - E = MigrateCtx.traversers_end(); I != E; ++I) + for (auto I = MigrateCtx.traversers_begin(), + E = MigrateCtx.traversers_end(); + I != E; ++I) (*I)->traverseObjCImplementation(ImplCtx); return base::TraverseObjCImplementationDecl(D); @@ -339,9 +337,9 @@ return true; BodyContext BodyCtx(MigrateCtx, rootS); - for (MigrationContext::traverser_iterator - I = MigrateCtx.traversers_begin(), - E = MigrateCtx.traversers_end(); I != E; ++I) + for (auto I = MigrateCtx.traversers_begin(), + E = MigrateCtx.traversers_end(); + I != E; ++I) (*I)->traverseBody(BodyCtx); return true; @@ -351,8 +349,7 @@ } MigrationContext::~MigrationContext() { - for (traverser_iterator - I = traversers_begin(), E = traversers_end(); I != E; ++I) + for (auto I = traversers_begin(), E = traversers_end(); I != E; ++I) delete *I; } @@ -365,9 +362,9 @@ if (T->isArrayType()) T = Pass.Ctx.getBaseElementType(T); - else if (const PointerType *PT = T->getAs()) + else if (const auto *PT = T->getAs()) T = PT->getPointeeType(); - else if (const ReferenceType *RT = T->getAs()) + else if (const auto *RT = T->getAs()) T = RT->getPointeeType(); else break; @@ -507,8 +504,7 @@ } void MigrationContext::traverse(TranslationUnitDecl *TU) { - for (traverser_iterator - I = traversers_begin(), E = traversers_end(); I != E; ++I) + for (auto I = traversers_begin(), E = traversers_end(); I != E; ++I) (*I)->traverseTU(*this); ASTTransform(*this).TraverseDecl(TU); Index: lib/AST/APValue.cpp =================================================================== --- lib/AST/APValue.cpp +++ lib/AST/APValue.cpp @@ -401,7 +401,7 @@ } else if (!IsReference) Out << '&'; - if (const ValueDecl *VD = Base.dyn_cast()) + if (const auto *VD = Base.dyn_cast()) Out << *VD; else { assert(Base.get() != nullptr && @@ -425,11 +425,11 @@ Out << "*(&"; QualType ElemTy; - if (const ValueDecl *VD = Base.dyn_cast()) { + if (const auto *VD = Base.dyn_cast()) { Out << *VD; ElemTy = VD->getType(); } else { - const Expr *E = Base.get(); + const auto *E = Base.get(); assert(E != nullptr && "Expecting non-null Expr"); E->printPretty(Out, nullptr, Ctx.getPrintingPolicy()); ElemTy = E->getType(); @@ -443,11 +443,11 @@ // or member. const Decl *BaseOrMember = BaseOrMemberType::getFromOpaqueValue(Path[I].BaseOrMember).getPointer(); - if (const CXXRecordDecl *RD = dyn_cast(BaseOrMember)) { + if (const auto *RD = dyn_cast(BaseOrMember)) { CastToBase = RD; ElemTy = Ctx.getRecordType(RD); } else { - const ValueDecl *VD = cast(BaseOrMember); + const auto *VD = cast(BaseOrMember); Out << "."; if (CastToBase) Out << *CastToBase << "::"; @@ -495,7 +495,7 @@ const RecordDecl *RD = Ty->getAs()->getDecl(); bool First = true; if (unsigned N = getStructNumBases()) { - const CXXRecordDecl *CD = cast(RD); + const auto *CD = cast(RD); CXXRecordDecl::base_class_const_iterator BI = CD->bases_begin(); for (unsigned I = 0; I != N; ++I, ++BI) { assert(BI != CD->bases_end()); @@ -649,7 +649,7 @@ void APValue::MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember, ArrayRef Path) { assert(isUninit() && "Bad state change"); - MemberPointerData *MPD = new ((void*)(char*)Data.buffer) MemberPointerData; + auto *MPD = new ((void *)(char *)Data.buffer) MemberPointerData; Kind = MemberPointer; MPD->MemberAndIsDerivedMember.setPointer(Member); MPD->MemberAndIsDerivedMember.setInt(IsDerivedMember); Index: lib/AST/ASTContext.cpp =================================================================== --- lib/AST/ASTContext.cpp +++ lib/AST/ASTContext.cpp @@ -80,35 +80,34 @@ return nullptr; // User can not attach documentation to implicit instantiations. - if (const FunctionDecl *FD = dyn_cast(D)) { + if (const auto *FD = dyn_cast(D)) { if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) return nullptr; } - if (const VarDecl *VD = dyn_cast(D)) { + if (const auto *VD = dyn_cast(D)) { if (VD->isStaticDataMember() && VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) return nullptr; } - if (const CXXRecordDecl *CRD = dyn_cast(D)) { + if (const auto *CRD = dyn_cast(D)) { if (CRD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) return nullptr; } - if (const ClassTemplateSpecializationDecl *CTSD = - dyn_cast(D)) { + if (const auto *CTSD = dyn_cast(D)) { TemplateSpecializationKind TSK = CTSD->getSpecializationKind(); if (TSK == TSK_ImplicitInstantiation || TSK == TSK_Undeclared) return nullptr; } - if (const EnumDecl *ED = dyn_cast(D)) { + if (const auto *ED = dyn_cast(D)) { if (ED->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) return nullptr; } - if (const TagDecl *TD = dyn_cast(D)) { + if (const auto *TD = dyn_cast(D)) { // When tag declaration (but not definition!) is part of the // decl-specifier-seq of some other declaration, it doesn't get comment if (TD->isEmbeddedInDeclarator() && !TD->isCompleteDefinition()) @@ -151,7 +150,7 @@ // declared via a macro. Try using declaration's starting location as // the "declaration location". DeclLoc = D->getLocStart(); - } else if (const TagDecl *TD = dyn_cast(D)) { + } else if (const auto *TD = dyn_cast(D)) { // If location of the tag decl is inside a macro, but the spelling of // the tag name comes from a macro argument, it looks like a special // macro like NS_ENUM is being used to define the tag decl. In that @@ -261,7 +260,7 @@ /// refer to the actual template. /// If we have an implicit instantiation, adjust 'D' to refer to template. const Decl *adjustDeclToTemplate(const Decl *D) { - if (const FunctionDecl *FD = dyn_cast(D)) { + if (const auto *FD = dyn_cast(D)) { // Is this function declaration part of a function template? if (const FunctionTemplateDecl *FTD = FD->getDescribedFunctionTemplate()) return FTD; @@ -281,7 +280,7 @@ return D; } - if (const VarDecl *VD = dyn_cast(D)) { + if (const auto *VD = dyn_cast(D)) { // Static data member is instantiated from a member definition of a class // template? if (VD->isStaticDataMember()) @@ -290,15 +289,14 @@ return D; } - if (const CXXRecordDecl *CRD = dyn_cast(D)) { + if (const auto *CRD = dyn_cast(D)) { // Is this class declaration part of a class template? if (const ClassTemplateDecl *CTD = CRD->getDescribedClassTemplate()) return CTD; // Class is an implicit instantiation of a class template or partial // specialization? - if (const ClassTemplateSpecializationDecl *CTSD = - dyn_cast(CRD)) { + if (const auto *CTSD = dyn_cast(CRD)) { if (CTSD->getSpecializationKind() != TSK_ImplicitInstantiation) return D; llvm::PointerUnion(D)) { + if (const auto *ED = dyn_cast(D)) { // Enum is instantiated from a member definition of a class template? if (const EnumDecl *MemberDecl = ED->getInstantiatedFromMemberEnum()) return MemberDecl; @@ -403,7 +401,7 @@ static void addRedeclaredMethods(const ObjCMethodDecl *ObjCMethod, SmallVectorImpl &Redeclared) { const DeclContext *DC = ObjCMethod->getDeclContext(); - if (const ObjCImplDecl *IMD = dyn_cast(DC)) { + if (const auto *IMD = dyn_cast(DC)) { const ObjCInterfaceDecl *ID = IMD->getClassInterface(); if (!ID) return; @@ -419,7 +417,7 @@ comments::FullComment *ASTContext::cloneFullComment(comments::FullComment *FC, const Decl *D) const { - comments::DeclInfo *ThisDeclInfo = new (*this) comments::DeclInfo; + auto *ThisDeclInfo = new (*this) comments::DeclInfo; ThisDeclInfo->CommentDecl = D; ThisDeclInfo->IsFilled = false; ThisDeclInfo->fill(); @@ -463,7 +461,7 @@ if (!RC) { if (isa(D) || isa(D)) { SmallVector Overridden; - const ObjCMethodDecl *OMD = dyn_cast(D); + const auto *OMD = dyn_cast(D); if (OMD && OMD->isPropertyAccessor()) if (const ObjCPropertyDecl *PDecl = OMD->findPropertyDecl()) if (comments::FullComment *FC = getCommentForDecl(PDecl, PP)) @@ -474,29 +472,25 @@ for (unsigned i = 0, e = Overridden.size(); i < e; i++) if (comments::FullComment *FC = getCommentForDecl(Overridden[i], PP)) return cloneFullComment(FC, D); - } - else if (const TypedefNameDecl *TD = dyn_cast(D)) { + } else if (const auto *TD = dyn_cast(D)) { // Attach any tag type's documentation to its typedef if latter // does not have one of its own. QualType QT = TD->getUnderlyingType(); - if (const TagType *TT = QT->getAs()) + if (const auto *TT = QT->getAs()) if (const Decl *TD = TT->getDecl()) if (comments::FullComment *FC = getCommentForDecl(TD, PP)) return cloneFullComment(FC, D); - } - else if (const ObjCInterfaceDecl *IC = dyn_cast(D)) { + } else if (const auto *IC = dyn_cast(D)) { while (IC->getSuperClass()) { IC = IC->getSuperClass(); if (comments::FullComment *FC = getCommentForDecl(IC, PP)) return cloneFullComment(FC, D); } - } - else if (const ObjCCategoryDecl *CD = dyn_cast(D)) { + } else if (const auto *CD = dyn_cast(D)) { if (const ObjCInterfaceDecl *IC = CD->getClassInterface()) if (comments::FullComment *FC = getCommentForDecl(IC, PP)) return cloneFullComment(FC, D); - } - else if (const CXXRecordDecl *RD = dyn_cast(D)) { + } else if (const auto *RD = dyn_cast(D)) { if (!(RD = RD->getDefinition())) return nullptr; // Check non-virtual bases. @@ -556,13 +550,13 @@ for (TemplateParameterList::const_iterator P = Params->begin(), PEnd = Params->end(); P != PEnd; ++P) { - if (TemplateTypeParmDecl *TTP = dyn_cast(*P)) { + if (auto *TTP = dyn_cast(*P)) { ID.AddInteger(0); ID.AddBoolean(TTP->isParameterPack()); continue; } - - if (NonTypeTemplateParmDecl *NTTP = dyn_cast(*P)) { + + if (auto *NTTP = dyn_cast(*P)) { ID.AddInteger(1); ID.AddBoolean(NTTP->isParameterPack()); ID.AddPointer(NTTP->getType().getCanonicalType().getAsOpaquePtr()); @@ -577,8 +571,8 @@ ID.AddBoolean(false); continue; } - - TemplateTemplateParmDecl *TTP = cast(*P); + + auto *TTP = cast(*P); ID.AddInteger(2); Profile(ID, TTP); } @@ -603,7 +597,7 @@ for (TemplateParameterList::const_iterator P = Params->begin(), PEnd = Params->end(); P != PEnd; ++P) { - if (TemplateTypeParmDecl *TTP = dyn_cast(*P)) + if (auto *TTP = dyn_cast(*P)) CanonParams.push_back( TemplateTypeParmDecl::Create(*this, getTranslationUnitDecl(), SourceLocation(), @@ -611,8 +605,7 @@ TTP->getDepth(), TTP->getIndex(), nullptr, false, TTP->isParameterPack())); - else if (NonTypeTemplateParmDecl *NTTP - = dyn_cast(*P)) { + else if (auto *NTTP = dyn_cast(*P)) { QualType T = getCanonicalType(NTTP->getType()); TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(T); NonTypeTemplateParmDecl *Param; @@ -773,13 +766,13 @@ const ASTRecordLayout*>::iterator I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; ) // Increment in loop to prevent using deallocated memory. - if (ASTRecordLayout *R = const_cast((I++)->second)) + if (auto *R = const_cast((I++)->second)) R->Destroy(*this); for (llvm::DenseMap::iterator I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) { // Increment in loop to prevent using deallocated memory. - if (ASTRecordLayout *R = const_cast((I++)->second)) + if (auto *R = const_cast((I++)->second)) R->Destroy(*this); } @@ -1040,7 +1033,7 @@ } void ASTContext::InitBuiltinType(CanQualType &R, BuiltinType::Kind K) { - BuiltinType *Ty = new (*this, TypeAlignment) BuiltinType(K); + auto *Ty = new (*this, TypeAlignment) BuiltinType(K); R = CanQualType::CreateUnsafe(QualType(Ty, 0)); Types.push_back(Ty); } @@ -1369,13 +1362,13 @@ SmallVectorImpl &Overridden) const { assert(D); - if (const CXXMethodDecl *CXXMethod = dyn_cast(D)) { + if (const auto *CXXMethod = dyn_cast(D)) { Overridden.append(overridden_methods_begin(CXXMethod), overridden_methods_end(CXXMethod)); return; } - const ObjCMethodDecl *Method = dyn_cast(D); + const auto *Method = dyn_cast(D); if (!Method) return; @@ -1446,9 +1439,9 @@ if (UseAlignAttrOnly) { // do nothing - } else if (const ValueDecl *VD = dyn_cast(D)) { + } else if (const auto *VD = dyn_cast(D)) { QualType T = VD->getType(); - if (const ReferenceType *RT = T->getAs()) { + if (const auto *RT = T->getAs()) { if (ForAlignof) T = RT->getPointeeType(); else @@ -1469,7 +1462,7 @@ } } Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr())); - if (const VarDecl *VD = dyn_cast(D)) { + if (const auto *VD = dyn_cast(D)) { if (VD->hasGlobalStorage() && !ForAlignof) Align = std::max(Align, getTargetInfo().getMinGlobalAlign()); } @@ -1480,7 +1473,7 @@ // a max-field-alignment constraint (#pragma pack). So calculate // the actual alignment of the field within the struct, and then // (as we're expected to) constrain that by the alignment of the type. - if (const FieldDecl *Field = dyn_cast(VD)) { + if (const auto *Field = dyn_cast(VD)) { const RecordDecl *Parent = Field->getParent(); // We can only produce a sensible answer if the record is valid. if (!Parent->isInvalidDecl()) { @@ -1550,7 +1543,7 @@ std::pair ASTContext::getTypeInfoInChars(const Type *T) const { - if (const ConstantArrayType *CAT = dyn_cast(T)) + if (const auto *CAT = dyn_cast(T)) return getConstantArrayInfoInChars(*this, CAT); TypeInfo Info = getTypeInfo(T); return std::make_pair(toCharUnitsFromBits(Info.Width), @@ -1641,7 +1634,7 @@ break; case Type::ConstantArray: { - const ConstantArrayType *CAT = cast(T); + const auto *CAT = cast(T); TypeInfo EltInfo = getTypeInfo(CAT->getElementType()); uint64_t Size = CAT->getSize().getZExtValue(); @@ -1656,7 +1649,7 @@ } case Type::ExtVector: case Type::Vector: { - const VectorType *VT = cast(T); + const auto *VT = cast(T); TypeInfo EltInfo = getTypeInfo(VT->getElementType()); Width = EltInfo.Width * VT->getNumElements(); Align = Width; @@ -1814,7 +1807,7 @@ break; } case Type::MemberPointer: { - const MemberPointerType *MPT = cast(T); + const auto *MPT = cast(T); std::tie(Width, Align) = ABI->getMemberPointerWidthAndAlign(MPT); break; } @@ -1832,7 +1825,7 @@ case Type::Decayed: return getTypeInfo(cast(T)->getAdjustedType().getTypePtr()); case Type::ObjCInterface: { - const ObjCInterfaceType *ObjCI = cast(T); + const auto *ObjCI = cast(T); const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl()); Width = toBits(Layout.getSize()); Align = toBits(Layout.getAlignment()); @@ -1840,7 +1833,7 @@ } case Type::Record: case Type::Enum: { - const TagType *TT = cast(T); + const auto *TT = cast(T); if (TT->getDecl()->isInvalidDecl()) { Width = 8; @@ -1848,7 +1841,7 @@ break; } - if (const EnumType *ET = dyn_cast(TT)) { + if (const auto *ET = dyn_cast(TT)) { const EnumDecl *ED = ET->getDecl(); TypeInfo Info = getTypeInfo(ED->getIntegerType()->getUnqualifiedDesugaredType()); @@ -1859,7 +1852,7 @@ return Info; } - const RecordType *RT = cast(TT); + const auto *RT = cast(TT); const RecordDecl *RD = RT->getDecl(); const ASTRecordLayout &Layout = getASTRecordLayout(RD); Width = toBits(Layout.getSize()); @@ -1873,7 +1866,7 @@ getReplacementType().getTypePtr()); case Type::Auto: { - const AutoType *A = cast(T); + const auto *A = cast(T); assert(!A->getDeducedType().isNull() && "cannot request the size of an undeduced or dependent auto type"); return getTypeInfo(A->getDeducedType().getTypePtr()); @@ -1998,7 +1991,7 @@ return ABIAlign; // Double and long long should be naturally aligned if possible. - if (const ComplexType *CT = T->getAs()) + if (const auto *CT = T->getAs()) T = CT->getElementType().getTypePtr(); if (const EnumType *ET = T->getAs()) T = ET->getDecl()->getIntegerType().getTypePtr(); @@ -2057,7 +2050,7 @@ for (const auto *I : OI->ivars()) Ivars.push_back(I); } else { - ObjCInterfaceDecl *IDecl = const_cast(OI); + auto *IDecl = const_cast(OI); for (const ObjCIvarDecl *Iv = IDecl->all_declared_ivar_begin(); Iv; Iv= Iv->getNextIvar()) Ivars.push_back(Iv); @@ -2068,7 +2061,7 @@ /// those inherited by it. void ASTContext::CollectInheritedProtocols(const Decl *CDecl, llvm::SmallPtrSet &Protocols) { - if (const ObjCInterfaceDecl *OI = dyn_cast(CDecl)) { + if (const auto *OI = dyn_cast(CDecl)) { // We can use protocol_iterator here instead of // all_referenced_protocol_iterator since we are walking all categories. for (auto *Proto : OI->all_referenced_protocols()) { @@ -2084,11 +2077,11 @@ CollectInheritedProtocols(SD, Protocols); SD = SD->getSuperClass(); } - } else if (const ObjCCategoryDecl *OC = dyn_cast(CDecl)) { + } else if (const auto *OC = dyn_cast(CDecl)) { for (auto *Proto : OC->protocols()) { CollectInheritedProtocols(Proto, Protocols); } - } else if (const ObjCProtocolDecl *OP = dyn_cast(CDecl)) { + } else if (const auto *OP = dyn_cast(CDecl)) { // Insert the protocol. if (!Protocols.insert( const_cast(OP->getCanonicalDecl())).second) @@ -2174,14 +2167,11 @@ const ObjCInterfaceDecl *ASTContext::getObjContainingInterface( const NamedDecl *ND) const { - if (const ObjCInterfaceDecl *ID = - dyn_cast(ND->getDeclContext())) + if (const auto *ID = dyn_cast(ND->getDeclContext())) return ID; - if (const ObjCCategoryDecl *CD = - dyn_cast(ND->getDeclContext())) + if (const auto *CD = dyn_cast(ND->getDeclContext())) return CD->getClassInterface(); - if (const ObjCImplDecl *IMD = - dyn_cast(ND->getDeclContext())) + if (const auto *IMD = dyn_cast(ND->getDeclContext())) return IMD->getClassInterface(); return nullptr; @@ -2214,8 +2204,8 @@ assert(DataSize == TypeLoc::getFullDataSizeForType(T) && "incorrect data size provided to CreateTypeSourceInfo!"); - TypeSourceInfo *TInfo = - (TypeSourceInfo*)BumpAlloc.Allocate(sizeof(TypeSourceInfo) + DataSize, 8); + auto *TInfo = (TypeSourceInfo *)BumpAlloc.Allocate( + sizeof(TypeSourceInfo) + DataSize, 8); new (TInfo) TypeSourceInfo(T); return TInfo; } @@ -2267,7 +2257,7 @@ (void) ExtQualNodes.FindNodeOrInsertPos(ID, insertPos); } - ExtQuals *eq = new (*this, TypeAlignment) ExtQuals(baseType, canon, quals); + auto *eq = new (*this, TypeAlignment) ExtQuals(baseType, canon, quals); ExtQualNodes.InsertNode(eq, insertPos); return QualType(eq, fastQuals); } @@ -2298,7 +2288,7 @@ if (CanT.getObjCGCAttr() == GCAttr) return T; - if (const PointerType *ptr = T->getAs()) { + if (const auto *ptr = T->getAs()) { QualType Pointee = ptr->getPointeeType(); if (Pointee->isAnyPointerType()) { QualType ResultType = getObjCGCQualType(Pointee, GCAttr); @@ -2326,10 +2316,10 @@ return T; QualType Result; - if (const FunctionNoProtoType *FNPT = dyn_cast(T)) { + if (const auto *FNPT = dyn_cast(T)) { Result = getFunctionNoProtoType(FNPT->getReturnType(), Info); } else { - const FunctionProtoType *FPT = cast(T); + const auto *FPT = cast(T); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); EPI.ExtInfo = Info; Result = getFunctionType(FPT->getReturnType(), FPT->getParamTypes(), EPI); @@ -2342,7 +2332,7 @@ QualType ResultType) { FD = FD->getMostRecentDecl(); while (true) { - const FunctionProtoType *FPT = FD->getType()->castAs(); + const auto *FPT = FD->getType()->castAs(); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); FD->setType(getFunctionType(ResultType, FPT->getParamTypes(), EPI)); if (FunctionDecl *Next = FD->getPreviousDecl()) @@ -2376,7 +2366,7 @@ // Anything else must be a function type. Rebuild it with the new exception // specification. - const FunctionProtoType *Proto = cast(Orig); + const auto *Proto = cast(Orig); return Context.getFunctionType( Proto->getReturnType(), Proto->getParamTypes(), Proto->getExtProtoInfo().withExceptionSpec(ESI)); @@ -2432,7 +2422,7 @@ ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos); assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - ComplexType *New = new (*this, TypeAlignment) ComplexType(T, Canonical); + auto *New = new (*this, TypeAlignment) ComplexType(T, Canonical); Types.push_back(New); ComplexTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -2460,7 +2450,7 @@ PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos); assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - PointerType *New = new (*this, TypeAlignment) PointerType(T, Canonical); + auto *New = new (*this, TypeAlignment) PointerType(T, Canonical); Types.push_back(New); PointerTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -2551,8 +2541,7 @@ BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos); assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - BlockPointerType *New - = new (*this, TypeAlignment) BlockPointerType(T, Canonical); + auto *New = new (*this, TypeAlignment) BlockPointerType(T, Canonical); Types.push_back(New); BlockPointerTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -2575,7 +2564,7 @@ LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) return QualType(RT, 0); - const ReferenceType *InnerRef = T->getAs(); + const auto *InnerRef = T->getAs(); // If the referencee type isn't canonical, this won't be a canonical type // either, so fill in the canonical type field. @@ -2590,9 +2579,8 @@ assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - LValueReferenceType *New - = new (*this, TypeAlignment) LValueReferenceType(T, Canonical, - SpelledAsLValue); + auto *New = new (*this, TypeAlignment) + LValueReferenceType(T, Canonical, SpelledAsLValue); Types.push_back(New); LValueReferenceTypes.InsertNode(New, InsertPos); @@ -2612,7 +2600,7 @@ RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) return QualType(RT, 0); - const ReferenceType *InnerRef = T->getAs(); + const auto *InnerRef = T->getAs(); // If the referencee type isn't canonical, this won't be a canonical type // either, so fill in the canonical type field. @@ -2627,8 +2615,7 @@ assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - RValueReferenceType *New - = new (*this, TypeAlignment) RValueReferenceType(T, Canonical); + auto *New = new (*this, TypeAlignment) RValueReferenceType(T, Canonical); Types.push_back(New); RValueReferenceTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -2658,8 +2645,7 @@ MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos); assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - MemberPointerType *New - = new (*this, TypeAlignment) MemberPointerType(T, Cls, Canonical); + auto *New = new (*this, TypeAlignment) MemberPointerType(T, Cls, Canonical); Types.push_back(New); MemberPointerTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -2704,8 +2690,8 @@ assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - ConstantArrayType *New = new(*this,TypeAlignment) - ConstantArrayType(EltTy, Canon, ArySize, ASM, IndexTypeQuals); + auto *New = new (*this, TypeAlignment) + ConstantArrayType(EltTy, Canon, ArySize, ASM, IndexTypeQuals); ConstantArrayTypes.InsertNode(New, InsertPos); Types.push_back(New); return QualType(New, 0); @@ -2774,7 +2760,7 @@ break; case Type::LValueReference: { - const LValueReferenceType *lv = cast(ty); + const auto *lv = cast(ty); result = getLValueReferenceType( getVariableArrayDecayedType(lv->getPointeeType()), lv->isSpelledAsLValue()); @@ -2782,20 +2768,20 @@ } case Type::RValueReference: { - const RValueReferenceType *lv = cast(ty); + const auto *lv = cast(ty); result = getRValueReferenceType( getVariableArrayDecayedType(lv->getPointeeType())); break; } case Type::Atomic: { - const AtomicType *at = cast(ty); + const auto *at = cast(ty); result = getAtomicType(getVariableArrayDecayedType(at->getValueType())); break; } case Type::ConstantArray: { - const ConstantArrayType *cat = cast(ty); + const auto *cat = cast(ty); result = getConstantArrayType( getVariableArrayDecayedType(cat->getElementType()), cat->getSize(), @@ -2805,7 +2791,7 @@ } case Type::DependentSizedArray: { - const DependentSizedArrayType *dat = cast(ty); + const auto *dat = cast(ty); result = getDependentSizedArrayType( getVariableArrayDecayedType(dat->getElementType()), dat->getSizeExpr(), @@ -2817,7 +2803,7 @@ // Turn incomplete types into [*] types. case Type::IncompleteArray: { - const IncompleteArrayType *iat = cast(ty); + const auto *iat = cast(ty); result = getVariableArrayType( getVariableArrayDecayedType(iat->getElementType()), /*size*/ nullptr, @@ -2829,7 +2815,7 @@ // Turn VLA types into [*] types. case Type::VariableArray: { - const VariableArrayType *vat = cast(ty); + const auto *vat = cast(ty); result = getVariableArrayType( getVariableArrayDecayedType(vat->getElementType()), /*size*/ nullptr, @@ -2862,9 +2848,9 @@ IndexTypeQuals, Brackets); Canon = getQualifiedType(Canon, canonSplit.Quals); } - - VariableArrayType *New = new(*this, TypeAlignment) - VariableArrayType(EltTy, Canon, NumElts, ASM, IndexTypeQuals, Brackets); + + auto *New = new (*this, TypeAlignment) + VariableArrayType(EltTy, Canon, NumElts, ASM, IndexTypeQuals, Brackets); VariableArrayTypes.push_back(New); Types.push_back(New); @@ -2934,10 +2920,8 @@ // Otherwise, we need to build a type which follows the spelling // of the element type. - DependentSizedArrayType *sugaredType - = new (*this, TypeAlignment) - DependentSizedArrayType(*this, elementType, canon, numElements, - ASM, elementTypeQuals, brackets); + auto *sugaredType = new (*this, TypeAlignment) DependentSizedArrayType( + *this, elementType, canon, numElements, ASM, elementTypeQuals, brackets); Types.push_back(sugaredType); return QualType(sugaredType, 0); } @@ -2970,8 +2954,8 @@ assert(!existing && "Shouldn't be in the map!"); (void) existing; } - IncompleteArrayType *newType = new (*this, TypeAlignment) - IncompleteArrayType(elementType, canon, ASM, elementTypeQuals); + auto *newType = new (*this, TypeAlignment) + IncompleteArrayType(elementType, canon, ASM, elementTypeQuals); IncompleteArrayTypes.InsertNode(newType, insertPos); Types.push_back(newType); @@ -3002,8 +2986,8 @@ VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - VectorType *New = new (*this, TypeAlignment) - VectorType(vecType, NumElts, Canonical, VecKind); + auto *New = new (*this, TypeAlignment) + VectorType(vecType, NumElts, Canonical, VecKind); VectorTypes.InsertNode(New, InsertPos); Types.push_back(New); return QualType(New, 0); @@ -3033,8 +3017,8 @@ VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - ExtVectorType *New = new (*this, TypeAlignment) - ExtVectorType(vecType, NumElts, Canonical); + auto *New = + new (*this, TypeAlignment) ExtVectorType(vecType, NumElts, Canonical); VectorTypes.InsertNode(New, InsertPos); Types.push_back(New); return QualType(New, 0); @@ -3115,8 +3099,8 @@ assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - FunctionNoProtoType *New = new (*this, TypeAlignment) - FunctionNoProtoType(ResultTy, Canonical, Info); + auto *New = + new (*this, TypeAlignment) FunctionNoProtoType(ResultTy, Canonical, Info); Types.push_back(New); FunctionNoProtoTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -3329,7 +3313,7 @@ Size += NumArgs * sizeof(FunctionProtoType::ExtParameterInfo); } - FunctionProtoType *FTP = (FunctionProtoType*) Allocate(Size, TypeAlignment); + auto *FTP = (FunctionProtoType *)Allocate(Size, TypeAlignment); FunctionProtoType::ExtProtoInfo newEPI = EPI; new (FTP) FunctionProtoType(ResultTy, ArgArray, Canonical, newEPI); Types.push_back(FTP); @@ -3357,7 +3341,7 @@ assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - PipeType *New = new (*this, TypeAlignment) PipeType(T, Canonical, ReadOnly); + auto *New = new (*this, TypeAlignment) PipeType(T, Canonical, ReadOnly); Types.push_back(New); PipeTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -3374,7 +3358,7 @@ #ifndef NDEBUG static bool NeedsInjectedClassNameType(const RecordDecl *D) { if (!isa(D)) return false; - const CXXRecordDecl *RD = cast(D); + const auto *RD = cast(D); if (isa(RD)) return true; if (RD->getDescribedClassTemplate() && @@ -3410,21 +3394,20 @@ assert(Decl && "Passed null for Decl param"); assert(!Decl->TypeForDecl && "TypeForDecl present in slow case"); - if (const TypedefNameDecl *Typedef = dyn_cast(Decl)) + if (const auto *Typedef = dyn_cast(Decl)) return getTypedefType(Typedef); assert(!isa(Decl) && "Template type parameter types are always available."); - if (const RecordDecl *Record = dyn_cast(Decl)) { + if (const auto *Record = dyn_cast(Decl)) { assert(Record->isFirstDecl() && "struct/union has previous declaration"); assert(!NeedsInjectedClassNameType(Record)); return getRecordType(Record); - } else if (const EnumDecl *Enum = dyn_cast(Decl)) { + } else if (const auto *Enum = dyn_cast(Decl)) { assert(Enum->isFirstDecl() && "enum has previous declaration"); return getEnumType(Enum); - } else if (const UnresolvedUsingTypenameDecl *Using = - dyn_cast(Decl)) { + } else if (const auto *Using = dyn_cast(Decl)) { Type *newType = new (*this, TypeAlignment) UnresolvedUsingType(Using); Decl->TypeForDecl = newType; Types.push_back(newType); @@ -3443,8 +3426,8 @@ if (Canonical.isNull()) Canonical = getCanonicalType(Decl->getUnderlyingType()); - TypedefType *newType = new(*this, TypeAlignment) - TypedefType(Type::Typedef, Decl, Canonical); + auto *newType = + new (*this, TypeAlignment) TypedefType(Type::Typedef, Decl, Canonical); Decl->TypeForDecl = newType; Types.push_back(newType); return QualType(newType, 0); @@ -3455,9 +3438,9 @@ if (const RecordDecl *PrevDecl = Decl->getPreviousDecl()) if (PrevDecl->TypeForDecl) - return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0); + return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0); - RecordType *newType = new (*this, TypeAlignment) RecordType(Decl); + auto *newType = new (*this, TypeAlignment) RecordType(Decl); Decl->TypeForDecl = newType; Types.push_back(newType); return QualType(newType, 0); @@ -3468,9 +3451,9 @@ if (const EnumDecl *PrevDecl = Decl->getPreviousDecl()) if (PrevDecl->TypeForDecl) - return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0); + return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0); - EnumType *newType = new (*this, TypeAlignment) EnumType(Decl); + auto *newType = new (*this, TypeAlignment) EnumType(Decl); Decl->TypeForDecl = newType; Types.push_back(newType); return QualType(newType, 0); @@ -3545,9 +3528,8 @@ SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(ID, InsertPos); } - SubstTemplateTypeParmPackType *SubstParm - = new (*this, TypeAlignment) SubstTemplateTypeParmPackType(Parm, Canon, - ArgPack); + auto *SubstParm = new (*this, TypeAlignment) + SubstTemplateTypeParmPackType(Parm, Canon, ArgPack); Types.push_back(SubstParm); SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos); return QualType(SubstParm, 0); @@ -4009,9 +3991,8 @@ size += typeArgs.size() * sizeof(QualType); size += protocols.size() * sizeof(ObjCProtocolDecl *); void *mem = Allocate(size, TypeAlignment); - ObjCObjectTypeImpl *T = - new (mem) ObjCObjectTypeImpl(canonical, baseType, typeArgs, protocols, - isKindOf); + auto *T = new (mem) + ObjCObjectTypeImpl(canonical, baseType, typeArgs, protocols, isKindOf); Types.push_back(T); ObjCObjectTypes.InsertNode(T, InsertPos); @@ -4027,15 +4008,14 @@ bool allowOnPointerType) const { hasError = false; - if (const ObjCTypeParamType *objT = - dyn_cast(type.getTypePtr())) { + if (const auto *objT = dyn_cast(type.getTypePtr())) { return getObjCTypeParamType(objT->getDecl(), protocols); } // Apply protocol qualifiers to ObjCObjectPointerType. if (allowOnPointerType) { - if (const ObjCObjectPointerType *objPtr = - dyn_cast(type.getTypePtr())) { + if (const auto *objPtr = + dyn_cast(type.getTypePtr())) { const ObjCObjectType *objT = objPtr->getObjectType(); // Merge protocol lists and construct ObjCObjectType. SmallVector protocolsVec; @@ -4053,7 +4033,7 @@ } // Apply protocol qualifiers to ObjCObjectType. - if (const ObjCObjectType *objT = dyn_cast(type.getTypePtr())){ + if (const auto *objT = dyn_cast(type.getTypePtr())) { // FIXME: Check for protocols to which the class type is already // known to conform. @@ -4075,7 +4055,7 @@ // id if (type->isObjCIdType()) { - const ObjCObjectPointerType *objPtr = type->castAs(); + const auto *objPtr = type->castAs(); type = getObjCObjectType(ObjCBuiltinIdTy, { }, protocols, objPtr->isKindOfType()); return getObjCObjectPointerType(type); @@ -4083,7 +4063,7 @@ // Class if (type->isObjCClassType()) { - const ObjCObjectPointerType *objPtr = type->castAs(); + const auto *objPtr = type->castAs(); type = getObjCObjectType(ObjCBuiltinClassTy, { }, protocols, objPtr->isKindOfType()); return getObjCObjectPointerType(type); @@ -4120,8 +4100,7 @@ unsigned size = sizeof(ObjCTypeParamType); size += protocols.size() * sizeof(ObjCProtocolDecl *); void *mem = Allocate(size, TypeAlignment); - ObjCTypeParamType *newType = new (mem) - ObjCTypeParamType(Decl, Canonical, protocols); + auto *newType = new (mem) ObjCTypeParamType(Decl, Canonical, protocols); Types.push_back(newType); ObjCTypeParamTypes.InsertNode(newType, InsertPos); @@ -4135,8 +4114,8 @@ ObjCInterfaceDecl *IC) { if (!QT->isObjCQualifiedIdType()) return false; - - if (const ObjCObjectPointerType *OPT = QT->getAs()) { + + if (const auto *OPT = QT->getAs()) { // If both the right and left sides have qualifiers. for (auto *Proto : OPT->quals()) { if (!IC->ClassImplementsProtocol(Proto, false)) @@ -4154,7 +4133,7 @@ ObjCInterfaceDecl *IDecl) { if (!QT->isObjCQualifiedIdType()) return false; - const ObjCObjectPointerType *OPT = QT->getAs(); + const auto *OPT = QT->getAs(); if (!OPT) return false; if (!IDecl->hasDefinition()) @@ -4216,8 +4195,7 @@ // No match. void *Mem = Allocate(sizeof(ObjCObjectPointerType), TypeAlignment); - ObjCObjectPointerType *QType = - new (Mem) ObjCObjectPointerType(Canonical, ObjectT); + auto *QType = new (Mem) ObjCObjectPointerType(Canonical, ObjectT); Types.push_back(QType); ObjCObjectPointerTypes.InsertNode(QType, InsertPos); @@ -4242,7 +4220,7 @@ Decl = Def; void *Mem = Allocate(sizeof(ObjCInterfaceType), TypeAlignment); - ObjCInterfaceType *T = new (Mem) ObjCInterfaceType(Decl); + auto *T = new (Mem) ObjCInterfaceType(Decl); Decl->TypeForDecl = T; Types.push_back(T); return QualType(T, 0); @@ -4289,7 +4267,7 @@ /// on canonical types (which are always unique). QualType ASTContext::getTypeOfType(QualType tofType) const { QualType Canonical = getCanonicalType(tofType); - TypeOfType *tot = new (*this, TypeAlignment) TypeOfType(tofType, Canonical); + auto *tot = new (*this, TypeAlignment) TypeOfType(tofType, Canonical); Types.push_back(tot); return QualType(tot, 0); } @@ -4379,9 +4357,8 @@ if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos)) return QualType(AT, 0); - AutoType *AT = new (*this, TypeAlignment) AutoType(DeducedType, - Keyword, - IsDependent); + auto *AT = + new (*this, TypeAlignment) AutoType(DeducedType, Keyword, IsDependent); Types.push_back(AT); if (InsertPos) AutoTypes.InsertNode(AT, InsertPos); @@ -4410,7 +4387,7 @@ AtomicType *NewIP = AtomicTypes.FindNodeOrInsertPos(ID, InsertPos); assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP; } - AtomicType *New = new (*this, TypeAlignment) AtomicType(T, Canonical); + auto *New = new (*this, TypeAlignment) AtomicType(T, Canonical); Types.push_back(New); AtomicTypes.InsertNode(New, InsertPos); return QualType(New, 0); @@ -4524,8 +4501,8 @@ // the unqualified desugared type and then drops it on the floor. // We then have to strip that sugar back off with // getUnqualifiedDesugaredType(), which is silly. - const ArrayType *AT = - dyn_cast(splitType.Ty->getUnqualifiedDesugaredType()); + const auto *AT = + dyn_cast(splitType.Ty->getUnqualifiedDesugaredType()); // If we don't have an array, just use the results in splitType. if (!AT) { @@ -4549,16 +4526,16 @@ // build the type back up. quals.addConsistentQualifiers(splitType.Quals); - if (const ConstantArrayType *CAT = dyn_cast(AT)) { + if (const auto *CAT = dyn_cast(AT)) { return getConstantArrayType(unqualElementType, CAT->getSize(), CAT->getSizeModifier(), 0); } - if (const IncompleteArrayType *IAT = dyn_cast(AT)) { + if (const auto *IAT = dyn_cast(AT)) { return getIncompleteArrayType(unqualElementType, IAT->getSizeModifier(), 0); } - if (const VariableArrayType *VAT = dyn_cast(AT)) { + if (const auto *VAT = dyn_cast(AT)) { return getVariableArrayType(unqualElementType, VAT->getSizeExpr(), VAT->getSizeModifier(), @@ -4566,7 +4543,7 @@ VAT->getBracketsRange()); } - const DependentSizedArrayType *DSAT = cast(AT); + const auto *DSAT = cast(AT); return getDependentSizedArrayType(unqualElementType, DSAT->getSizeExpr(), DSAT->getSizeModifier(), 0, SourceRange()); @@ -4581,16 +4558,16 @@ /// be called in a loop that successively "unwraps" pointer and /// pointer-to-member types to compare them at each level. bool ASTContext::UnwrapSimilarPointerTypes(QualType &T1, QualType &T2) { - const PointerType *T1PtrType = T1->getAs(), - *T2PtrType = T2->getAs(); + const auto *T1PtrType = T1->getAs(), + *T2PtrType = T2->getAs(); if (T1PtrType && T2PtrType) { T1 = T1PtrType->getPointeeType(); T2 = T2PtrType->getPointeeType(); return true; } - - const MemberPointerType *T1MPType = T1->getAs(), - *T2MPType = T2->getAs(); + + const auto *T1MPType = T1->getAs(), + *T2MPType = T2->getAs(); if (T1MPType && T2MPType && hasSameUnqualifiedType(QualType(T1MPType->getClass(), 0), QualType(T2MPType->getClass(), 0))) { @@ -4600,8 +4577,8 @@ } if (getLangOpts().ObjC1) { - const ObjCObjectPointerType *T1OPType = T1->getAs(), - *T2OPType = T2->getAs(); + const auto *T1OPType = T1->getAs(), + *T2OPType = T2->getAs(); if (T1OPType && T2OPType) { T1 = T1OPType->getPointeeType(); T2 = T2OPType->getPointeeType(); @@ -4669,8 +4646,7 @@ case TemplateName::QualifiedTemplate: case TemplateName::Template: { TemplateDecl *Template = Name.getAsTemplateDecl(); - if (TemplateTemplateParmDecl *TTP - = dyn_cast(Template)) + if (auto *TTP = dyn_cast(Template)) Template = getCanonicalTemplateTemplateParmDecl(TTP); // The canonical template name is the canonical template declaration. @@ -4722,7 +4698,7 @@ return Arg; case TemplateArgument::Declaration: { - ValueDecl *D = cast(Arg.getAsDecl()->getCanonicalDecl()); + auto *D = cast(Arg.getAsDecl()->getCanonicalDecl()); return TemplateArgument(D, Arg.getParamTypeForDecl()); } @@ -4747,9 +4723,8 @@ case TemplateArgument::Pack: { if (Arg.pack_size() == 0) return Arg; - - TemplateArgument *CanonArgs - = new (*this) TemplateArgument[Arg.pack_size()]; + + auto *CanonArgs = new (*this) TemplateArgument[Arg.pack_size()]; unsigned Idx = 0; for (TemplateArgument::pack_iterator A = Arg.pack_begin(), AEnd = Arg.pack_end(); @@ -4800,7 +4775,7 @@ // types, e.g., // typedef typename T::type T1; // typedef typename T1::type T2; - if (const DependentNameType *DNT = T->getAs()) + if (const auto *DNT = T->getAs()) return NestedNameSpecifier::Create(*this, DNT->getQualifier(), const_cast(DNT->getIdentifier())); @@ -4824,7 +4799,7 @@ // Handle the non-qualified case efficiently. if (!T.hasLocalQualifiers()) { // Handle the common positive case fast. - if (const ArrayType *AT = dyn_cast(T)) + if (const auto *AT = dyn_cast(T)) return AT; } @@ -4844,7 +4819,7 @@ Qualifiers qs = split.Quals; // If we have a simple case, just return now. - const ArrayType *ATy = dyn_cast(split.Ty); + const auto *ATy = dyn_cast(split.Ty); if (!ATy || qs.empty()) return ATy; @@ -4852,17 +4827,16 @@ // qualifiers into the array element type and return a new array type. QualType NewEltTy = getQualifiedType(ATy->getElementType(), qs); - if (const ConstantArrayType *CAT = dyn_cast(ATy)) + if (const auto *CAT = dyn_cast(ATy)) return cast(getConstantArrayType(NewEltTy, CAT->getSize(), CAT->getSizeModifier(), CAT->getIndexTypeCVRQualifiers())); - if (const IncompleteArrayType *IAT = dyn_cast(ATy)) + if (const auto *IAT = dyn_cast(ATy)) return cast(getIncompleteArrayType(NewEltTy, IAT->getSizeModifier(), IAT->getIndexTypeCVRQualifiers())); - if (const DependentSizedArrayType *DSAT - = dyn_cast(ATy)) + if (const auto *DSAT = dyn_cast(ATy)) return cast( getDependentSizedArrayType(NewEltTy, DSAT->getSizeExpr(), @@ -4870,7 +4844,7 @@ DSAT->getIndexTypeCVRQualifiers(), DSAT->getBracketsRange())); - const VariableArrayType *VAT = cast(ATy); + const auto *VAT = cast(ATy); return cast(getVariableArrayType(NewEltTy, VAT->getSizeExpr(), VAT->getSizeModifier(), @@ -4964,7 +4938,7 @@ /// getFloatingRank - Return a relative rank for floating point types. /// This routine will assert if passed a built-in type that isn't a float. static FloatingRank getFloatingRank(QualType T) { - if (const ComplexType *CT = T->getAs()) + if (const auto *CT = T->getAs()) return getFloatingRank(CT->getElementType()); assert(T->getAs() && "getFloatingRank(): not a floating type"); @@ -5155,9 +5129,9 @@ return T.getObjCLifetime(); if (T->isArrayType()) T = getBaseElementType(T); - else if (const PointerType *PT = T->getAs()) + else if (const auto *PT = T->getAs()) T = PT->getPointeeType(); - else if (const ReferenceType *RT = T->getAs()) + else if (const auto *RT = T->getAs()) T = RT->getPointeeType(); else break; @@ -5182,9 +5156,9 @@ const Type *RHSC = getCanonicalType(RHS).getTypePtr(); // Unwrap enums to their underlying type. - if (const EnumType *ET = dyn_cast(LHSC)) + if (const auto *ET = dyn_cast(LHSC)) LHSC = getIntegerTypeForEnum(ET); - if (const EnumType *ET = dyn_cast(RHSC)) + if (const auto *ET = dyn_cast(RHSC)) RHSC = getIntegerTypeForEnum(ET); if (LHSC == RHSC) return 0; @@ -5446,7 +5420,7 @@ // This returns true if a type has been typedefed to BOOL: // typedef BOOL; static bool isTypeTypedefedAsBOOL(QualType T) { - if (const TypedefType *TT = dyn_cast(T)) + if (const auto *TT = dyn_cast(T)) if (IdentifierInfo *II = TT->getDecl()->getIdentifier()) return II->isStr("BOOL"); @@ -5678,13 +5652,12 @@ const Decl *Container) const { if (!Container) return nullptr; - if (const ObjCCategoryImplDecl *CID = - dyn_cast(Container)) { + if (const auto *CID = dyn_cast(Container)) { for (auto *PID : CID->property_impls()) if (PID->getPropertyDecl() == PD) return PID; } else { - const ObjCImplementationDecl *OID=cast(Container); + const auto *OID = cast(Container); for (auto *PID : OID->property_impls()) if (PID->getPropertyDecl() == PD) return PID; @@ -5947,21 +5920,21 @@ case Type::Enum: if (FD && FD->isBitField()) return EncodeBitField(this, S, T, FD); - if (const BuiltinType *BT = dyn_cast(CT)) + if (const auto *BT = dyn_cast(CT)) S += getObjCEncodingForPrimitiveKind(this, BT->getKind()); else S += ObjCEncodingForEnumType(this, cast(CT)); return; case Type::Complex: { - const ComplexType *CT = T->castAs(); + const auto *CT = T->castAs(); S += 'j'; getObjCEncodingForTypeImpl(CT->getElementType(), S, false, false, nullptr); return; } case Type::Atomic: { - const AtomicType *AT = T->castAs(); + const auto *AT = T->castAs(); S += 'A'; getObjCEncodingForTypeImpl(AT->getValueType(), S, false, false, nullptr); return; @@ -5973,7 +5946,7 @@ case Type::RValueReference: { QualType PointeeTy; if (isa(CT)) { - const PointerType *PT = T->castAs(); + const auto *PT = T->castAs(); if (PT->isObjCSelType()) { S += ':'; return; @@ -6042,7 +6015,7 @@ case Type::ConstantArray: case Type::IncompleteArray: case Type::VariableArray: { - const ArrayType *AT = cast(CT); + const auto *AT = cast(CT); if (isa(AT) && !StructField) { // Incomplete arrays are encoded as a pointer to the array element. @@ -6053,7 +6026,7 @@ } else { S += '['; - if (const ConstantArrayType *CAT = dyn_cast(AT)) + if (const auto *CAT = dyn_cast(AT)) S += llvm::utostr(CAT->getSize().getZExtValue()); else { //Variable length arrays are encoded as a regular array with 0 elements. @@ -6082,8 +6055,7 @@ // Anonymous structures print as '?' if (const IdentifierInfo *II = RDecl->getIdentifier()) { S += II->getName(); - if (ClassTemplateSpecializationDecl *Spec - = dyn_cast(RDecl)) { + if (auto *Spec = dyn_cast(RDecl)) { const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); llvm::raw_string_ostream OS(S); TemplateSpecializationType::PrintTemplateArgumentList(OS, @@ -6126,11 +6098,11 @@ } case Type::BlockPointer: { - const BlockPointerType *BT = T->castAs(); + const auto *BT = T->castAs(); S += "@?"; // Unlike a pointer-to-function, which is "^?". if (EncodeBlockParameters) { - const FunctionType *FT = BT->getPointeeType()->castAs(); - + const auto *FT = BT->getPointeeType()->castAs(); + S += '<'; // Block return type getObjCEncodingForTypeImpl( @@ -6141,7 +6113,7 @@ // Block self S += "@?"; // Block parameters - if (const FunctionProtoType *FPT = dyn_cast(FT)) { + if (const auto *FPT = dyn_cast(FT)) { for (const auto &I : FPT->param_types()) getObjCEncodingForTypeImpl( I, S, ExpandPointedToStructures, ExpandStructures, FD, @@ -6178,7 +6150,7 @@ SmallVector Ivars; DeepCollectObjCIvars(OI, true, Ivars); for (unsigned i = 0, e = Ivars.size(); i != e; ++i) { - const FieldDecl *Field = cast(Ivars[i]); + const auto *Field = cast(Ivars[i]); if (Field->isBitField()) getObjCEncodingForTypeImpl(Field->getType(), S, false, true, Field); else @@ -6193,7 +6165,7 @@ } case Type::ObjCObjectPointer: { - const ObjCObjectPointerType *OPT = T->castAs(); + const auto *OPT = T->castAs(); if (OPT->isObjCIdType()) { S += '@'; return; @@ -6313,7 +6285,7 @@ if (!RDecl->getDefinition() || RDecl->getDefinition()->isInvalidDecl()) return; - CXXRecordDecl *CXXRec = dyn_cast(RDecl); + auto *CXXRec = dyn_cast(RDecl); std::multimap FieldOrBaseOffsets; const ASTRecordLayout &layout = getASTRecordLayout(RDecl); @@ -6361,8 +6333,7 @@ #ifndef NDEBUG uint64_t CurOffs = 0; #endif - std::multimap::iterator - CurLayObj = FieldOrBaseOffsets.begin(); + auto CurLayObj = FieldOrBaseOffsets.begin(); if (CXXRec && CXXRec->isDynamicClass() && (CurLayObj == FieldOrBaseOffsets.end() || CurLayObj->first != 0)) { @@ -6406,7 +6377,7 @@ if (!dcl) break; // reached end of structure. - if (CXXRecordDecl *base = dyn_cast(dcl)) { + if (auto *base = dyn_cast(dcl)) { // We expand the bases without their virtual bases since those are going // in the initial structure. Note that this differs from gcc which // expands virtual bases each time one is encountered in the hierarchy, @@ -6418,7 +6389,7 @@ CurOffs += toBits(getASTRecordLayout(base).getNonVirtualSize()); #endif } else { - FieldDecl *field = cast(dcl); + auto *field = cast(dcl); if (FD) { S += '"'; S += field->getNameAsString(); @@ -6878,7 +6849,7 @@ void *memory = Allocate(sizeof(OverloadedTemplateStorage) + size * sizeof(FunctionTemplateDecl*)); - OverloadedTemplateStorage *OT = new(memory) OverloadedTemplateStorage(size); + auto *OT = new (memory) OverloadedTemplateStorage(size); NamedDecl **Storage = OT->getStorage(); for (UnresolvedSetIterator I = Begin; I != End; ++I) { @@ -7010,7 +6981,7 @@ TemplateName ASTContext::getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, const TemplateArgument &ArgPack) const { - ASTContext &Self = const_cast(*this); + auto &Self = const_cast(*this); llvm::FoldingSetNodeID ID; SubstTemplateTemplateParmPackStorage::Profile(ID, Self, Param, ArgPack); @@ -7076,7 +7047,7 @@ // pointer. #ifndef NDEBUG QualType CT = Ty->getCanonicalTypeInternal(); - while (const ArrayType *AT = dyn_cast(CT)) + while (const auto *AT = dyn_cast(CT)) CT = AT->getElementType(); assert(CT->isAnyPointerType() || CT->isBlockPointerType()); #endif @@ -7107,8 +7078,8 @@ // Treat Neon vector types and most AltiVec vector types as if they are the // equivalent GCC vector types. - const VectorType *First = FirstVec->getAs(); - const VectorType *Second = SecondVec->getAs(); + const auto *First = FirstVec->getAs(); + const auto *Second = SecondVec->getAs(); if (First->getNumElements() == Second->getNumElements() && hasSameType(First->getElementType(), Second->getElementType()) && First->getVectorKind() != VectorType::AltiVecPixel && @@ -7141,8 +7112,8 @@ /// Class. bool ASTContext::ObjCQualifiedClassTypesAreCompatible(QualType lhs, QualType rhs) { - const ObjCObjectPointerType *lhsQID = lhs->getAs(); - const ObjCObjectPointerType *rhsOPT = rhs->getAs(); + const auto *lhsQID = lhs->getAs(); + const auto *rhsOPT = rhs->getAs(); assert ((lhsQID && rhsOPT) && "ObjCQualifiedClassTypesAreCompatible"); for (auto *lhsProto : lhsQID->quals()) { @@ -7172,7 +7143,7 @@ return true; if (const ObjCObjectPointerType *lhsQID = lhs->getAsObjCQualifiedIdType()) { - const ObjCObjectPointerType *rhsOPT = rhs->getAs(); + const auto *rhsOPT = rhs->getAs(); if (!rhsOPT) return false; @@ -7460,14 +7431,14 @@ static bool canAssignObjCObjectTypes(ASTContext &ctx, QualType lhs, QualType rhs) { // Common case: two object pointers. - const ObjCObjectPointerType *lhsOPT = lhs->getAs(); - const ObjCObjectPointerType *rhsOPT = rhs->getAs(); + const auto *lhsOPT = lhs->getAs(); + const auto *rhsOPT = rhs->getAs(); if (lhsOPT && rhsOPT) return ctx.canAssignObjCInterfaces(lhsOPT, rhsOPT); // Two block pointers. - const BlockPointerType *lhsBlock = lhs->getAs(); - const BlockPointerType *rhsBlock = rhs->getAs(); + const auto *lhsBlock = lhs->getAs(); + const auto *rhsBlock = rhs->getAs(); if (lhsBlock && rhsBlock) return ctx.typesAreBlockPointerCompatible(lhs, rhs); @@ -7705,8 +7676,8 @@ bool ASTContext::areComparableObjCPointerTypes(QualType LHS, QualType RHS) { // get the "pointed to" types - const ObjCObjectPointerType *LHSOPT = LHS->getAs(); - const ObjCObjectPointerType *RHSOPT = RHS->getAs(); + const auto *LHSOPT = LHS->getAs(); + const auto *RHSOPT = RHS->getAs(); if (!LHSOPT || !RHSOPT) return false; @@ -7786,10 +7757,10 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs, bool OfBlockPointer, bool Unqualified) { - const FunctionType *lbase = lhs->getAs(); - const FunctionType *rbase = rhs->getAs(); - const FunctionProtoType *lproto = dyn_cast(lbase); - const FunctionProtoType *rproto = dyn_cast(rbase); + const auto *lbase = lhs->getAs(); + const auto *rbase = rhs->getAs(); + const auto *lproto = dyn_cast(lbase); + const auto *rproto = dyn_cast(rbase); bool allLTypes = true; bool allRTypes = true; @@ -8219,8 +8190,8 @@ // Check if the types are assignment compatible. // FIXME: This should be type compatibility, e.g. whether // "LHS x; RHS x;" at global scope is legal. - const ObjCObjectType* LHSIface = LHS->getAs(); - const ObjCObjectType* RHSIface = RHS->getAs(); + const auto *LHSIface = LHS->getAs(); + const auto *RHSIface = RHS->getAs(); if (canAssignObjCInterfaces(LHSIface, RHSIface)) return LHS; @@ -8302,8 +8273,8 @@ if (ResReturnType == NewReturnType || ResReturnType == OldReturnType) { // id foo(); ... __strong id foo(); or: __strong id foo(); ... id foo(); // In either case, use OldReturnType to build the new function type. - const FunctionType *F = LHS->getAs(); - if (const FunctionProtoType *FPT = cast(F)) { + const auto *F = LHS->getAs(); + if (const auto *FPT = cast(F)) { FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); EPI.ExtInfo = getFunctionExtInfo(LHS); QualType ResultType = @@ -8371,7 +8342,7 @@ assert(T->hasSignedIntegerRepresentation() && "Unexpected type"); // Turn <4 x signed int> -> <4 x unsigned int> - if (const VectorType *VTy = T->getAs()) + if (const auto *VTy = T->getAs()) return getVectorType(getCorrespondingUnsignedType(VTy->getElementType()), VTy->getNumElements(), VTy->getVectorKind()); @@ -8888,7 +8859,7 @@ } bool ASTContext::DeclMustBeEmitted(const Decl *D) { - if (const VarDecl *VD = dyn_cast(D)) { + if (const auto *VD = dyn_cast(D)) { if (!VD->isFileVarDecl()) return false; // Global named register variables (GNU extension) are never emitted. @@ -8897,7 +8868,7 @@ if (VD->getDescribedVarTemplate() || isa(VD)) return false; - } else if (const FunctionDecl *FD = dyn_cast(D)) { + } else if (const auto *FD = dyn_cast(D)) { // We never need to emit an uninstantiated function template. if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate) return false; @@ -8929,7 +8900,7 @@ if (D->hasAttr() || D->hasAttr()) return true; - if (const FunctionDecl *FD = dyn_cast(D)) { + if (const auto *FD = dyn_cast(D)) { // Forward declarations aren't required. if (!FD->doesThisDeclarationHaveABody()) return FD->doesDeclarationForceExternallyVisibleDefinition(); @@ -8941,7 +8912,7 @@ // The key function for a class is required. This rule only comes // into play when inline functions can be key functions, though. if (getTargetInfo().getCXXABI().canKeyFunctionBeInline()) { - if (const CXXMethodDecl *MD = dyn_cast(FD)) { + if (const auto *MD = dyn_cast(FD)) { const CXXRecordDecl *RD = MD->getParent(); if (MD->isOutOfLine() && RD->isDynamicClass()) { const CXXMethodDecl *KeyFunc = getCurrentKeyFunction(RD); @@ -8956,8 +8927,8 @@ // Implicit template instantiations can also be deferred in C++. return !isDiscardableGVALinkage(GetGVALinkageForFunction(FD)); } - - const VarDecl *VD = cast(D); + + const auto *VD = cast(D); assert(VD->isFileVarDecl() && "Expected file scoped var"); if (VD->isThisDeclarationADefinition() == VarDecl::DeclarationOnly && Index: lib/AST/ASTDiagnostic.cpp =================================================================== --- lib/AST/ASTDiagnostic.cpp +++ lib/AST/ASTDiagnostic.cpp @@ -33,33 +33,32 @@ const Type *Ty = QC.strip(QT); // Don't aka just because we saw an elaborated type... - if (const ElaboratedType *ET = dyn_cast(Ty)) { + if (const auto *ET = dyn_cast(Ty)) { QT = ET->desugar(); continue; } // ... or a paren type ... - if (const ParenType *PT = dyn_cast(Ty)) { + if (const auto *PT = dyn_cast(Ty)) { QT = PT->desugar(); continue; } // ...or a substituted template type parameter ... - if (const SubstTemplateTypeParmType *ST = - dyn_cast(Ty)) { + if (const auto *ST = dyn_cast(Ty)) { QT = ST->desugar(); continue; } // ...or an attributed type... - if (const AttributedType *AT = dyn_cast(Ty)) { + if (const auto *AT = dyn_cast(Ty)) { QT = AT->desugar(); continue; } // ...or an adjusted type... - if (const AdjustedType *AT = dyn_cast(Ty)) { + if (const auto *AT = dyn_cast(Ty)) { QT = AT->desugar(); continue; } // ... or an auto type. - if (const AutoType *AT = dyn_cast(Ty)) { + if (const auto *AT = dyn_cast(Ty)) { if (!AT->isSugared()) break; QT = AT->desugar(); @@ -68,7 +67,7 @@ // Desugar FunctionType if return type or any parameter type should be // desugared. Preserve nullability attribute on desugared types. - if (const FunctionType *FT = dyn_cast(Ty)) { + if (const auto *FT = dyn_cast(Ty)) { bool DesugarReturn = false; QualType SugarRT = FT->getReturnType(); QualType RT = Desugar(Context, SugarRT, DesugarReturn); @@ -79,7 +78,7 @@ bool DesugarArgument = false; SmallVector Args; - const FunctionProtoType *FPT = dyn_cast(FT); + const auto *FPT = dyn_cast(FT); if (FPT) { for (QualType SugarPT : FPT->param_types()) { QualType PT = Desugar(Context, SugarPT, DesugarArgument); @@ -102,8 +101,7 @@ // Desugar template specializations if any template argument should be // desugared. - if (const TemplateSpecializationType *TST = - dyn_cast(Ty)) { + if (const auto *TST = dyn_cast(Ty)) { if (!TST->isTypeAlias()) { bool DesugarArgument = false; SmallVector Args; @@ -141,15 +139,15 @@ bool IsSugar = false; switch (Ty->getTypeClass()) { #define ABSTRACT_TYPE(Class, Base) -#define TYPE(Class, Base) \ -case Type::Class: { \ -const Class##Type *CTy = cast(Ty); \ -if (CTy->isSugared()) { \ -IsSugar = true; \ -Underlying = CTy->desugar(); \ -} \ -break; \ -} +#define TYPE(Class, Base) \ + case Type::Class: { \ + const auto *CTy = cast(Ty); \ + if (CTy->isSugared()) { \ + IsSugar = true; \ + Underlying = CTy->desugar(); \ + } \ + break; \ + } #include "clang/AST/TypeNodes.def" } @@ -163,8 +161,8 @@ break; // Don't desugar through the primary typedef of an anonymous type. - if (const TagType *UTT = Underlying->getAs()) - if (const TypedefType *QTT = dyn_cast(QT)) + if (const auto *UTT = Underlying->getAs()) + if (const auto *QTT = dyn_cast(QT)) if (UTT->getDecl()->getTypedefNameForAnonDecl() == QTT->getDecl()) break; @@ -175,16 +173,16 @@ // If we have a pointer-like type, desugar the pointee as well. // FIXME: Handle other pointer-like types. - if (const PointerType *Ty = QT->getAs()) { + if (const auto *Ty = QT->getAs()) { QT = Context.getPointerType(Desugar(Context, Ty->getPointeeType(), ShouldAKA)); } else if (const auto *Ty = QT->getAs()) { QT = Context.getObjCObjectPointerType(Desugar(Context, Ty->getPointeeType(), ShouldAKA)); - } else if (const LValueReferenceType *Ty = QT->getAs()) { + } else if (const auto *Ty = QT->getAs()) { QT = Context.getLValueReferenceType(Desugar(Context, Ty->getPointeeType(), ShouldAKA)); - } else if (const RValueReferenceType *Ty = QT->getAs()) { + } else if (const auto *Ty = QT->getAs()) { QT = Context.getRValueReferenceType(Desugar(Context, Ty->getPointeeType(), ShouldAKA)); } else if (const auto *Ty = QT->getAs()) { @@ -268,7 +266,7 @@ for (unsigned i = 0, e = PrevArgs.size(); i != e; ++i) { // TODO: Handle ak_declcontext case. if (PrevArgs[i].first == DiagnosticsEngine::ak_qualtype) { - void *Ptr = (void*)PrevArgs[i].second; + auto *Ptr = (void *)PrevArgs[i].second; QualType PrevTy(QualType::getFromOpaquePtr(Ptr)); if (PrevTy == Ty) { Repeated = true; @@ -297,7 +295,7 @@ // or displaying complex __attribute__ expressions so add details of the // type and element count. if (Ty->isVectorType()) { - const VectorType *VTy = Ty->getAs(); + const auto *VTy = Ty->getAs(); std::string DecoratedString; llvm::raw_string_ostream OS(DecoratedString); const char *Values = VTy->getNumElements() > 1 ? "values" : "value"; @@ -391,18 +389,18 @@ "Invalid modifier for NamedDecl* argument"); Qualified = false; } - const NamedDecl *ND = reinterpret_cast(Val); + const auto *ND = reinterpret_cast(Val); ND->getNameForDiagnostic(OS, Context.getPrintingPolicy(), Qualified); break; } case DiagnosticsEngine::ak_nestednamespec: { - NestedNameSpecifier *NNS = reinterpret_cast(Val); + auto *NNS = reinterpret_cast(Val); NNS->print(OS, Context.getPrintingPolicy()); NeedQuotes = false; break; } case DiagnosticsEngine::ak_declcontext: { - DeclContext *DC = reinterpret_cast (Val); + auto *DC = reinterpret_cast(Val); assert(DC && "Should never have a null declaration context"); NeedQuotes = false; @@ -416,13 +414,13 @@ OS << "block literal"; } else if (isLambdaCallOperator(DC)) { OS << "lambda expression"; - } else if (TypeDecl *Type = dyn_cast(DC)) { + } else if (auto *Type = dyn_cast(DC)) { OS << ConvertTypeToDiagnosticString(Context, Context.getTypeDeclType(Type), PrevArgs, QualTypeVals); } else { assert(isa(DC) && "Expected a NamedDecl"); - NamedDecl *ND = cast(DC); + auto *ND = cast(DC); if (isa(ND)) OS << "namespace "; else if (isa(ND)) @@ -1307,10 +1305,9 @@ } else if (isa(FromParamND)) { DiffTemplateTemplates(FromIter, ToIter); } else if (isa(FromParamND)) { - NonTypeTemplateParmDecl *FromDefaultNonTypeDecl = + auto *FromDefaultNonTypeDecl = cast(FromParamND); - NonTypeTemplateParmDecl *ToDefaultNonTypeDecl = - cast(ToParamND); + auto *ToDefaultNonTypeDecl = cast(ToParamND); DiffNonTypes(FromIter, ToIter, FromDefaultNonTypeDecl, ToDefaultNonTypeDecl); } else { @@ -1786,7 +1783,7 @@ if (isa(E)) return false; - if (UnaryOperator *UO = dyn_cast(E)) + if (auto *UO = dyn_cast(E)) if (UO->getOpcode() == UO_Minus) if (isa(UO->getSubExpr())) return false; Index: lib/AST/ASTDumper.cpp =================================================================== --- lib/AST/ASTDumper.cpp +++ lib/AST/ASTDumper.cpp @@ -679,7 +679,7 @@ OS << "<<>>"; return; } - if (const LocInfoType *LIT = llvm::dyn_cast(T)) { + if (const auto *LIT = llvm::dyn_cast(T)) { { ColorScope Color(*this, TypeColor); OS << "LocInfo Type"; @@ -732,12 +732,12 @@ } dumpPointer(D); - if (const NamedDecl *ND = dyn_cast(D)) { + if (const auto *ND = dyn_cast(D)) { ColorScope Color(*this, DeclNameColor); OS << " '" << ND->getDeclName() << '\''; } - if (const ValueDecl *VD = dyn_cast(D)) + if (const auto *VD = dyn_cast(D)) dumpType(VD->getType()); } @@ -1040,7 +1040,7 @@ for (Module *M : D->getASTContext().getModulesWithMergedDefinition( const_cast(ND))) dumpChild([=] { OS << "also in " << M->getFullModuleName(); }); - if (const NamedDecl *ND = dyn_cast(D)) + if (const auto *ND = dyn_cast(D)) if (ND->isHidden()) OS << " hidden"; if (D->isImplicit()) @@ -1051,7 +1051,7 @@ OS << " referenced"; if (D->isInvalidDecl()) OS << " invalid"; - if (const FunctionDecl *FD = dyn_cast(D)) + if (const auto *FD = dyn_cast(D)) if (FD->isConstexpr()) OS << " constexpr"; @@ -1149,7 +1149,7 @@ if (D->isTrivial()) OS << " trivial"; - if (const FunctionProtoType *FPT = D->getType()->getAs()) { + if (const auto *FPT = D->getType()->getAs()) { FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); switch (EPI.ExceptionSpec.Type) { default: break; @@ -1172,7 +1172,7 @@ for (const ParmVarDecl *Parameter : D->parameters()) dumpDecl(Parameter); - if (const CXXConstructorDecl *C = dyn_cast(D)) + if (const auto *C = dyn_cast(D)) for (CXXConstructorDecl::init_const_iterator I = C->init_begin(), E = C->init_end(); I != E; ++I) @@ -1773,7 +1773,7 @@ return; } - if (const DeclStmt *DS = dyn_cast(S)) { + if (const auto *DS = dyn_cast(S)) { VisitDeclStmt(DS); return; } @@ -2573,13 +2573,13 @@ void Comment::dump(raw_ostream &OS, const CommandTraits *Traits, const SourceManager *SM) const { - const FullComment *FC = dyn_cast(this); + const auto *FC = dyn_cast(this); ASTDumper D(OS, Traits, SM); D.dumpFullComment(FC); } LLVM_DUMP_METHOD void Comment::dumpColor() const { - const FullComment *FC = dyn_cast(this); + const auto *FC = dyn_cast(this); ASTDumper D(llvm::errs(), nullptr, nullptr, /*ShowColors*/true); D.dumpFullComment(FC); } Index: lib/AST/ASTImporter.cpp =================================================================== --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -296,8 +296,7 @@ bool Failed = false; std::transform(Ibegin, Iend, Obegin, [&ImporterRef, &Failed](ItemT *From) -> ItemT * { - ItemT *To = cast_or_null( - ImporterRef.Import(From)); + auto *To = cast_or_null(ImporterRef.Import(From)); if (!To && From) Failed = true; return To; @@ -568,8 +567,8 @@ case Type::LValueReference: case Type::RValueReference: { - const ReferenceType *Ref1 = cast(T1); - const ReferenceType *Ref2 = cast(T2); + const auto *Ref1 = cast(T1); + const auto *Ref2 = cast(T2); if (Ref1->isSpelledAsLValue() != Ref2->isSpelledAsLValue()) return false; if (Ref1->isInnerRef() != Ref2->isInnerRef()) @@ -582,8 +581,8 @@ } case Type::MemberPointer: { - const MemberPointerType *MemPtr1 = cast(T1); - const MemberPointerType *MemPtr2 = cast(T2); + const auto *MemPtr1 = cast(T1); + const auto *MemPtr2 = cast(T2); if (!IsStructurallyEquivalent(Context, MemPtr1->getPointeeType(), MemPtr2->getPointeeType())) @@ -596,8 +595,8 @@ } case Type::ConstantArray: { - const ConstantArrayType *Array1 = cast(T1); - const ConstantArrayType *Array2 = cast(T2); + const auto *Array1 = cast(T1); + const auto *Array2 = cast(T2); if (!llvm::APInt::isSameValue(Array1->getSize(), Array2->getSize())) return false; @@ -614,8 +613,8 @@ break; case Type::VariableArray: { - const VariableArrayType *Array1 = cast(T1); - const VariableArrayType *Array2 = cast(T2); + const auto *Array1 = cast(T1); + const auto *Array2 = cast(T2); if (!IsStructurallyEquivalent(Context, Array1->getSizeExpr(), Array2->getSizeExpr())) return false; @@ -627,8 +626,8 @@ } case Type::DependentSizedArray: { - const DependentSizedArrayType *Array1 = cast(T1); - const DependentSizedArrayType *Array2 = cast(T2); + const auto *Array1 = cast(T1); + const auto *Array2 = cast(T2); if (!IsStructurallyEquivalent(Context, Array1->getSizeExpr(), Array2->getSizeExpr())) return false; @@ -640,10 +639,8 @@ } case Type::DependentSizedExtVector: { - const DependentSizedExtVectorType *Vec1 - = cast(T1); - const DependentSizedExtVectorType *Vec2 - = cast(T2); + const auto *Vec1 = cast(T1); + const auto *Vec2 = cast(T2); if (!IsStructurallyEquivalent(Context, Vec1->getSizeExpr(), Vec2->getSizeExpr())) return false; @@ -656,8 +653,8 @@ case Type::Vector: case Type::ExtVector: { - const VectorType *Vec1 = cast(T1); - const VectorType *Vec2 = cast(T2); + const auto *Vec1 = cast(T1); + const auto *Vec2 = cast(T2); if (!IsStructurallyEquivalent(Context, Vec1->getElementType(), Vec2->getElementType())) @@ -670,8 +667,8 @@ } case Type::FunctionProto: { - const FunctionProtoType *Proto1 = cast(T1); - const FunctionProtoType *Proto2 = cast(T2); + const auto *Proto1 = cast(T1); + const auto *Proto2 = cast(T2); if (Proto1->getNumParams() != Proto2->getNumParams()) return false; for (unsigned I = 0, N = Proto1->getNumParams(); I != N; ++I) { @@ -705,8 +702,8 @@ } case Type::FunctionNoProto: { - const FunctionType *Function1 = cast(T1); - const FunctionType *Function2 = cast(T2); + const auto *Function1 = cast(T1); + const auto *Function2 = cast(T2); if (!IsStructurallyEquivalent(Context, Function1->getReturnType(), Function2->getReturnType())) return false; @@ -792,8 +789,8 @@ break; case Type::TemplateTypeParm: { - const TemplateTypeParmType *Parm1 = cast(T1); - const TemplateTypeParmType *Parm2 = cast(T2); + const auto *Parm1 = cast(T1); + const auto *Parm2 = cast(T2); if (Parm1->getDepth() != Parm2->getDepth()) return false; if (Parm1->getIndex() != Parm2->getIndex()) @@ -806,10 +803,8 @@ } case Type::SubstTemplateTypeParm: { - const SubstTemplateTypeParmType *Subst1 - = cast(T1); - const SubstTemplateTypeParmType *Subst2 - = cast(T2); + const auto *Subst1 = cast(T1); + const auto *Subst2 = cast(T2); if (!IsStructurallyEquivalent(Context, QualType(Subst1->getReplacedParameter(), 0), QualType(Subst2->getReplacedParameter(), 0))) @@ -822,10 +817,8 @@ } case Type::SubstTemplateTypeParmPack: { - const SubstTemplateTypeParmPackType *Subst1 - = cast(T1); - const SubstTemplateTypeParmPackType *Subst2 - = cast(T2); + const auto *Subst1 = cast(T1); + const auto *Subst2 = cast(T2); if (!IsStructurallyEquivalent(Context, QualType(Subst1->getReplacedParameter(), 0), QualType(Subst2->getReplacedParameter(), 0))) @@ -837,10 +830,8 @@ break; } case Type::TemplateSpecialization: { - const TemplateSpecializationType *Spec1 - = cast(T1); - const TemplateSpecializationType *Spec2 - = cast(T2); + const auto *Spec1 = cast(T1); + const auto *Spec2 = cast(T2); if (!IsStructurallyEquivalent(Context, Spec1->getTemplateName(), Spec2->getTemplateName())) @@ -856,8 +847,8 @@ } case Type::Elaborated: { - const ElaboratedType *Elab1 = cast(T1); - const ElaboratedType *Elab2 = cast(T2); + const auto *Elab1 = cast(T1); + const auto *Elab2 = cast(T2); // CHECKME: what if a keyword is ETK_None or ETK_typename ? if (Elab1->getKeyword() != Elab2->getKeyword()) return false; @@ -873,8 +864,8 @@ } case Type::InjectedClassName: { - const InjectedClassNameType *Inj1 = cast(T1); - const InjectedClassNameType *Inj2 = cast(T2); + const auto *Inj1 = cast(T1); + const auto *Inj2 = cast(T2); if (!IsStructurallyEquivalent(Context, Inj1->getInjectedSpecializationType(), Inj2->getInjectedSpecializationType())) @@ -883,8 +874,8 @@ } case Type::DependentName: { - const DependentNameType *Typename1 = cast(T1); - const DependentNameType *Typename2 = cast(T2); + const auto *Typename1 = cast(T1); + const auto *Typename2 = cast(T2); if (!IsStructurallyEquivalent(Context, Typename1->getQualifier(), Typename2->getQualifier())) @@ -897,10 +888,8 @@ } case Type::DependentTemplateSpecialization: { - const DependentTemplateSpecializationType *Spec1 = - cast(T1); - const DependentTemplateSpecializationType *Spec2 = - cast(T2); + const auto *Spec1 = cast(T1); + const auto *Spec2 = cast(T2); if (!IsStructurallyEquivalent(Context, Spec1->getQualifier(), Spec2->getQualifier())) @@ -926,8 +915,8 @@ break; case Type::ObjCInterface: { - const ObjCInterfaceType *Iface1 = cast(T1); - const ObjCInterfaceType *Iface2 = cast(T2); + const auto *Iface1 = cast(T1); + const auto *Iface2 = cast(T2); if (!IsStructurallyEquivalent(Context, Iface1->getDecl(), Iface2->getDecl())) return false; @@ -935,8 +924,8 @@ } case Type::ObjCTypeParam: { - const ObjCTypeParamType *Obj1 = cast(T1); - const ObjCTypeParamType *Obj2 = cast(T2); + const auto *Obj1 = cast(T1); + const auto *Obj2 = cast(T2); if (!IsStructurallyEquivalent(Context, Obj1->getDecl(), Obj2->getDecl())) return false; @@ -952,8 +941,8 @@ break; } case Type::ObjCObject: { - const ObjCObjectType *Obj1 = cast(T1); - const ObjCObjectType *Obj2 = cast(T2); + const auto *Obj1 = cast(T1); + const auto *Obj2 = cast(T2); if (!IsStructurallyEquivalent(Context, Obj1->getBaseType(), Obj2->getBaseType())) @@ -970,8 +959,8 @@ } case Type::ObjCObjectPointer: { - const ObjCObjectPointerType *Ptr1 = cast(T1); - const ObjCObjectPointerType *Ptr2 = cast(T2); + const auto *Ptr1 = cast(T1); + const auto *Ptr2 = cast(T2); if (!IsStructurallyEquivalent(Context, Ptr1->getPointeeType(), Ptr2->getPointeeType())) @@ -1003,7 +992,7 @@ /// \brief Determine structural equivalence of two fields. static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, FieldDecl *Field1, FieldDecl *Field2) { - RecordDecl *Owner2 = cast(Field2->getDeclContext()); + auto *Owner2 = cast(Field2->getDeclContext()); // For anonymous structs/unions, match up the anonymous struct/union type // declarations directly, so that we don't go off searching for anonymous @@ -1087,7 +1076,7 @@ ASTContext &Context = Anon->getASTContext(); QualType AnonTy = Context.getRecordType(Anon); - RecordDecl *Owner = dyn_cast(Anon->getDeclContext()); + auto *Owner = dyn_cast(Anon->getDeclContext()); if (!Owner) return None; @@ -1148,10 +1137,8 @@ // If both declarations are class template specializations, we know // the ODR applies, so check the template and template arguments. - ClassTemplateSpecializationDecl *Spec1 - = dyn_cast(D1); - ClassTemplateSpecializationDecl *Spec2 - = dyn_cast(D2); + auto *Spec1 = dyn_cast(D1); + auto *Spec2 = dyn_cast(D2); if (Spec1 && Spec2) { // Check that the specialized templates are the same. if (!IsStructurallyEquivalent(Context, Spec1->getSpecializedTemplate(), @@ -1179,9 +1166,9 @@ D2 = D2->getDefinition(); if (!D1 || !D2) return true; - - if (CXXRecordDecl *D1CXX = dyn_cast(D1)) { - if (CXXRecordDecl *D2CXX = dyn_cast(D2)) { + + if (auto *D1CXX = dyn_cast(D1)) { + if (auto *D2CXX = dyn_cast(D2)) { if (D1CXX->getNumBases() != D2CXX->getNumBases()) { if (Context.Complain) { Context.Diag2(D2->getLocation(), diag::warn_odr_tag_type_inconsistent) @@ -1495,8 +1482,8 @@ // FIXME: Switch on all declaration kinds. For now, we're just going to // check the obvious ones. - if (RecordDecl *Record1 = dyn_cast(D1)) { - if (RecordDecl *Record2 = dyn_cast(D2)) { + if (auto *Record1 = dyn_cast(D1)) { + if (auto *Record2 = dyn_cast(D2)) { // Check for equivalent structure names. IdentifierInfo *Name1 = Record1->getIdentifier(); if (!Name1 && Record1->getTypedefNameForAnonDecl()) @@ -1511,8 +1498,8 @@ // Record/non-record mismatch. Equivalent = false; } - } else if (EnumDecl *Enum1 = dyn_cast(D1)) { - if (EnumDecl *Enum2 = dyn_cast(D2)) { + } else if (auto *Enum1 = dyn_cast(D1)) { + if (auto *Enum2 = dyn_cast(D2)) { // Check for equivalent enum names. IdentifierInfo *Name1 = Enum1->getIdentifier(); if (!Name1 && Enum1->getTypedefNameForAnonDecl()) @@ -1527,8 +1514,8 @@ // Enum/non-enum mismatch Equivalent = false; } - } else if (TypedefNameDecl *Typedef1 = dyn_cast(D1)) { - if (TypedefNameDecl *Typedef2 = dyn_cast(D2)) { + } else if (auto *Typedef1 = dyn_cast(D1)) { + if (auto *Typedef2 = dyn_cast(D2)) { if (!::IsStructurallyEquivalent(Typedef1->getIdentifier(), Typedef2->getIdentifier()) || !::IsStructurallyEquivalent(*this, @@ -1539,9 +1526,8 @@ // Typedef/non-typedef mismatch. Equivalent = false; } - } else if (ClassTemplateDecl *ClassTemplate1 - = dyn_cast(D1)) { - if (ClassTemplateDecl *ClassTemplate2 = dyn_cast(D2)) { + } else if (auto *ClassTemplate1 = dyn_cast(D1)) { + if (auto *ClassTemplate2 = dyn_cast(D2)) { if (!::IsStructurallyEquivalent(ClassTemplate1->getIdentifier(), ClassTemplate2->getIdentifier()) || !::IsStructurallyEquivalent(*this, ClassTemplate1, ClassTemplate2)) @@ -1550,28 +1536,24 @@ // Class template/non-class-template mismatch. Equivalent = false; } - } else if (TemplateTypeParmDecl *TTP1= dyn_cast(D1)) { - if (TemplateTypeParmDecl *TTP2 = dyn_cast(D2)) { + } else if (auto *TTP1 = dyn_cast(D1)) { + if (auto *TTP2 = dyn_cast(D2)) { if (!::IsStructurallyEquivalent(*this, TTP1, TTP2)) Equivalent = false; } else { // Kind mismatch. Equivalent = false; } - } else if (NonTypeTemplateParmDecl *NTTP1 - = dyn_cast(D1)) { - if (NonTypeTemplateParmDecl *NTTP2 - = dyn_cast(D2)) { + } else if (auto *NTTP1 = dyn_cast(D1)) { + if (auto *NTTP2 = dyn_cast(D2)) { if (!::IsStructurallyEquivalent(*this, NTTP1, NTTP2)) Equivalent = false; } else { // Kind mismatch. Equivalent = false; } - } else if (TemplateTemplateParmDecl *TTP1 - = dyn_cast(D1)) { - if (TemplateTemplateParmDecl *TTP2 - = dyn_cast(D2)) { + } else if (auto *TTP1 = dyn_cast(D1)) { + if (auto *TTP2 = dyn_cast(D2)) { if (!::IsStructurallyEquivalent(*this, TTP1, TTP2)) Equivalent = false; } else { @@ -1841,8 +1823,8 @@ } QualType ASTNodeImporter::VisitTypedefType(const TypedefType *T) { - TypedefNameDecl *ToDecl - = dyn_cast_or_null(Importer.Import(T->getDecl())); + auto *ToDecl = + dyn_cast_or_null(Importer.Import(T->getDecl())); if (!ToDecl) return QualType(); @@ -1905,7 +1887,7 @@ QualType ASTNodeImporter::VisitInjectedClassNameType( const InjectedClassNameType *T) { - CXXRecordDecl *D = cast_or_null(Importer.Import(T->getDecl())); + auto *D = cast_or_null(Importer.Import(T->getDecl())); if (!D) return QualType(); @@ -1926,8 +1908,7 @@ } QualType ASTNodeImporter::VisitRecordType(const RecordType *T) { - RecordDecl *ToDecl - = dyn_cast_or_null(Importer.Import(T->getDecl())); + auto *ToDecl = dyn_cast_or_null(Importer.Import(T->getDecl())); if (!ToDecl) return QualType(); @@ -1935,8 +1916,7 @@ } QualType ASTNodeImporter::VisitEnumType(const EnumType *T) { - EnumDecl *ToDecl - = dyn_cast_or_null(Importer.Import(T->getDecl())); + auto *ToDecl = dyn_cast_or_null(Importer.Import(T->getDecl())); if (!ToDecl) return QualType(); @@ -1967,7 +1947,7 @@ QualType ASTNodeImporter::VisitTemplateTypeParmType( const TemplateTypeParmType *T) { - TemplateTypeParmDecl *ParmDecl = + auto *ParmDecl = cast_or_null(Importer.Import(T->getDecl())); if (!ParmDecl && T->getDecl()) return QualType(); @@ -2017,8 +1997,8 @@ } QualType ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) { - ObjCInterfaceDecl *Class - = dyn_cast_or_null(Importer.Import(T->getDecl())); + auto *Class = + dyn_cast_or_null(Importer.Import(T->getDecl())); if (!Class) return QualType(); @@ -2041,8 +2021,7 @@ SmallVector Protocols; for (auto *P : T->quals()) { - ObjCProtocolDecl *Protocol - = dyn_cast_or_null(Importer.Import(P)); + auto *Protocol = dyn_cast_or_null(Importer.Import(P)); if (!Protocol) return QualType(); Protocols.push_back(Protocol); @@ -2102,9 +2081,9 @@ if (!ToD) return; } - - if (RecordDecl *FromRecord = dyn_cast(FromD)) { - if (RecordDecl *ToRecord = cast_or_null(ToD)) { + + if (auto *FromRecord = dyn_cast(FromD)) { + if (auto *ToRecord = cast_or_null(ToD)) { if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() && !ToRecord->getDefinition()) { ImportDefinition(FromRecord, ToRecord); } @@ -2112,8 +2091,8 @@ return; } - if (EnumDecl *FromEnum = dyn_cast(FromD)) { - if (EnumDecl *ToEnum = cast_or_null(ToD)) { + if (auto *FromEnum = dyn_cast(FromD)) { + if (auto *ToEnum = cast_or_null(ToD)) { if (FromEnum->getDefinition() && !ToEnum->getDefinition()) { ImportDefinition(FromEnum, ToEnum); } @@ -2178,8 +2157,8 @@ To->startDefinition(); // Add base classes. - if (CXXRecordDecl *ToCXX = dyn_cast(To)) { - CXXRecordDecl *FromCXX = cast(From); + if (auto *ToCXX = dyn_cast(To)) { + auto *FromCXX = cast(From); struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data(); struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data(); @@ -2362,7 +2341,7 @@ } case TemplateArgument::Declaration: { - ValueDecl *To = cast_or_null(Importer.Import(From.getAsDecl())); + auto *To = cast_or_null(Importer.Import(From.getAsDecl())); QualType ToType = Importer.Import(From.getParamTypeForDecl()); if (!To || ToType.isNull()) return TemplateArgument(); @@ -2457,7 +2436,7 @@ // something we're trying to import while completing ToRecord. Decl *ToOrigin = Importer.GetOriginalDecl(ToRecord); if (ToOrigin) { - RecordDecl *ToOriginRecord = dyn_cast(ToOrigin); + auto *ToOriginRecord = dyn_cast(ToOrigin); if (ToOriginRecord) ToRecord = ToOriginRecord; } @@ -2566,7 +2545,7 @@ return nullptr; StringLiteral *FromMsg = D->getMessage(); - StringLiteral *ToMsg = cast_or_null(Importer.Import(FromMsg)); + auto *ToMsg = cast_or_null(Importer.Import(FromMsg)); if (!ToMsg && FromMsg) return nullptr; @@ -2596,7 +2575,7 @@ // This is an anonymous namespace. Adopt an existing anonymous // namespace if we can. // FIXME: Not testable. - if (TranslationUnitDecl *TU = dyn_cast(DC)) + if (auto *TU = dyn_cast(DC)) MergeWithNamespace = TU->getAnonymousNamespace(); else MergeWithNamespace = cast(DC)->getAnonymousNamespace(); @@ -2607,8 +2586,8 @@ for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { if (!FoundDecls[I]->isInIdentifierNamespace(Decl::IDNS_Namespace)) continue; - - if (NamespaceDecl *FoundNS = dyn_cast(FoundDecls[I])) { + + if (auto *FoundNS = dyn_cast(FoundDecls[I])) { MergeWithNamespace = FoundNS; ConflictingDecls.clear(); break; @@ -2638,7 +2617,7 @@ // If this is an anonymous namespace, register it as the anonymous // namespace within its context. if (!Name) { - if (TranslationUnitDecl *TU = dyn_cast(DC)) + if (auto *TU = dyn_cast(DC)) TU->setAnonymousNamespace(ToNamespace); else cast(DC)->setAnonymousNamespace(ToNamespace); @@ -2673,8 +2652,7 @@ for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) continue; - if (TypedefNameDecl *FoundTypedef = - dyn_cast(FoundDecls[I])) { + if (auto *FoundTypedef = dyn_cast(FoundDecls[I])) { if (Importer.IsStructurallyEquivalent(D->getUnderlyingType(), FoundTypedef->getUnderlyingType())) return Importer.Imported(D, FoundTypedef); @@ -2751,7 +2729,7 @@ Name.getAsIdentifierInfo()); Importer.Imported(D, ToLabel); - LabelStmt *Label = cast_or_null(Importer.Import(D->getStmt())); + auto *Label = cast_or_null(Importer.Import(D->getStmt())); if (!Label) return nullptr; @@ -2791,12 +2769,12 @@ continue; Decl *Found = FoundDecls[I]; - if (TypedefNameDecl *Typedef = dyn_cast(Found)) { - if (const TagType *Tag = Typedef->getUnderlyingType()->getAs()) + if (auto *Typedef = dyn_cast(Found)) { + if (const auto *Tag = Typedef->getUnderlyingType()->getAs()) Found = Tag->getDecl(); } - - if (EnumDecl *FoundEnum = dyn_cast(Found)) { + + if (auto *FoundEnum = dyn_cast(Found)) { if (IsStructuralMatch(D, FoundEnum)) return Importer.Imported(D, FoundEnum); } @@ -2880,12 +2858,12 @@ continue; Decl *Found = FoundDecls[I]; - if (TypedefNameDecl *Typedef = dyn_cast(Found)) { - if (const TagType *Tag = Typedef->getUnderlyingType()->getAs()) + if (auto *Typedef = dyn_cast(Found)) { + if (const auto *Tag = Typedef->getUnderlyingType()->getAs()) Found = Tag->getDecl(); } - - if (RecordDecl *FoundRecord = dyn_cast(Found)) { + + if (auto *FoundRecord = dyn_cast(Found)) { if (D->isAnonymousStructOrUnion() && FoundRecord->isAnonymousStructOrUnion()) { // If both anonymous structs/unions are in a record context, make sure @@ -2952,7 +2930,7 @@ SourceLocation StartLoc = Importer.Import(D->getLocStart()); if (!D2) { CXXRecordDecl *D2CXX = nullptr; - if (CXXRecordDecl *DCXX = llvm::dyn_cast(D)) { + if (auto *DCXX = llvm::dyn_cast(D)) { if (DCXX->isLambda()) { TypeSourceInfo *TInfo = Importer.Import(DCXX->getLambdaTypeInfo()); D2CXX = CXXRecordDecl::CreateLambda(Importer.getToContext(), @@ -3028,8 +3006,7 @@ if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) continue; - if (EnumConstantDecl *FoundEnumConstant - = dyn_cast(FoundDecls[I])) { + if (auto *FoundEnumConstant = dyn_cast(FoundDecls[I])) { if (IsStructuralMatch(D, FoundEnumConstant)) return Importer.Imported(D, FoundEnumConstant); } @@ -3082,8 +3059,8 @@ for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) continue; - - if (FunctionDecl *FoundFunction = dyn_cast(FoundDecls[I])) { + + if (auto *FoundFunction = dyn_cast(FoundDecls[I])) { if (FoundFunction->hasExternalFormalLinkage() && D->hasExternalFormalLinkage()) { if (Importer.IsStructurallyEquivalent(D->getType(), @@ -3127,8 +3104,7 @@ QualType FromTy = D->getType(); bool usedDifferentExceptionSpec = false; - if (const FunctionProtoType * - FromFPT = D->getType()->getAs()) { + if (const auto *FromFPT = D->getType()->getAs()) { FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo(); // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the // FunctionDecl that we are importing the FunctionProtoType for. @@ -3152,7 +3128,7 @@ // Import the function parameters. SmallVector Parameters; for (auto P : D->parameters()) { - ParmVarDecl *ToP = cast_or_null(Importer.Import(P)); + auto *ToP = cast_or_null(Importer.Import(P)); if (!ToP) return nullptr; @@ -3163,7 +3139,7 @@ TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo()); FunctionDecl *ToFunction = nullptr; SourceLocation InnerLocStart = Importer.Import(D->getInnerLocStart()); - if (CXXConstructorDecl *FromConstructor = dyn_cast(D)) { + if (auto *FromConstructor = dyn_cast(D)) { ToFunction = CXXConstructorDecl::Create(Importer.getToContext(), cast(DC), InnerLocStart, @@ -3175,16 +3151,15 @@ if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) { SmallVector CtorInitializers; for (CXXCtorInitializer *I : FromConstructor->inits()) { - CXXCtorInitializer *ToI = - cast_or_null(Importer.Import(I)); + auto *ToI = cast_or_null(Importer.Import(I)); if (!ToI && I) return nullptr; CtorInitializers.push_back(ToI); } - CXXCtorInitializer **Memory = + auto **Memory = new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers]; std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory); - CXXConstructorDecl *ToCtor = llvm::cast(ToFunction); + auto *ToCtor = llvm::cast(ToFunction); ToCtor->setCtorInitializers(Memory); ToCtor->setNumCtorInitializers(NumInitializers); } @@ -3195,8 +3170,7 @@ NameInfo, T, TInfo, D->isInlineSpecified(), D->isImplicit()); - } else if (CXXConversionDecl *FromConversion - = dyn_cast(D)) { + } else if (auto *FromConversion = dyn_cast(D)) { ToFunction = CXXConversionDecl::Create(Importer.getToContext(), cast(DC), InnerLocStart, @@ -3205,7 +3179,7 @@ FromConversion->isExplicit(), D->isConstexpr(), Importer.Import(D->getLocEnd())); - } else if (CXXMethodDecl *Method = dyn_cast(D)) { + } else if (auto *Method = dyn_cast(D)) { ToFunction = CXXMethodDecl::Create(Importer.getToContext(), cast(DC), InnerLocStart, @@ -3279,7 +3253,7 @@ } static unsigned getFieldIndex(Decl *F) { - RecordDecl *Owner = dyn_cast(F->getDeclContext()); + auto *Owner = dyn_cast(F->getDeclContext()); if (!Owner) return 0; @@ -3310,7 +3284,7 @@ SmallVector FoundDecls; DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { - if (FieldDecl *FoundField = dyn_cast(FoundDecls[I])) { + if (auto *FoundField = dyn_cast(FoundDecls[I])) { // For anonymous fields, match up by index. if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) continue; @@ -3374,8 +3348,7 @@ SmallVector FoundDecls; DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { - if (IndirectFieldDecl *FoundField - = dyn_cast(FoundDecls[I])) { + if (auto *FoundField = dyn_cast(FoundDecls[I])) { // For anonymous indirect fields, match up by index. if (!Name && getFieldIndex(D) != getFieldIndex(FoundField)) continue; @@ -3404,8 +3377,8 @@ if (T.isNull()) return nullptr; - NamedDecl **NamedChain = - new (Importer.getToContext())NamedDecl*[D->getChainingSize()]; + auto **NamedChain = + new (Importer.getToContext()) NamedDecl *[D->getChainingSize()]; unsigned i = 0; for (auto *PI : D->chain()) { @@ -3470,8 +3443,7 @@ return nullptr; SmallVector ToTPLists(D->NumTPLists); - TemplateParameterList **FromTPLists = - D->getTrailingObjects(); + auto **FromTPLists = D->getTrailingObjects(); for (unsigned I = 0; I < D->NumTPLists; I++) { TemplateParameterList *List = ImportTemplateParameterList(FromTPLists[I]); if (!List) @@ -3508,7 +3480,7 @@ SmallVector FoundDecls; DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { - if (ObjCIvarDecl *FoundIvar = dyn_cast(FoundDecls[I])) { + if (auto *FoundIvar = dyn_cast(FoundDecls[I])) { if (Importer.IsStructurallyEquivalent(D->getType(), FoundIvar->getType())) { Importer.Imported(D, FoundIvar); @@ -3568,8 +3540,8 @@ for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { if (!FoundDecls[I]->isInIdentifierNamespace(IDNS)) continue; - - if (VarDecl *FoundVar = dyn_cast(FoundDecls[I])) { + + if (auto *FoundVar = dyn_cast(FoundDecls[I])) { // We have found a variable that we may need to merge with. Check it. if (FoundVar->hasExternalFormalLinkage() && D->hasExternalFormalLinkage()) { @@ -3747,7 +3719,7 @@ SmallVector FoundDecls; DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { - if (ObjCMethodDecl *FoundMethod = dyn_cast(FoundDecls[I])) { + if (auto *FoundMethod = dyn_cast(FoundDecls[I])) { if (FoundMethod->isInstanceMethod() != D->isInstanceMethod()) continue; @@ -3825,7 +3797,7 @@ // Import the parameters SmallVector ToParams; for (auto *FromP : D->parameters()) { - ParmVarDecl *ToP = cast_or_null(Importer.Import(FromP)); + auto *ToP = cast_or_null(Importer.Import(FromP)); if (!ToP) return nullptr; @@ -3887,8 +3859,8 @@ if (ToD) return ToD; - ObjCInterfaceDecl *ToInterface - = cast_or_null(Importer.Import(D->getClassInterface())); + auto *ToInterface = + cast_or_null(Importer.Import(D->getClassInterface())); if (!ToInterface) return nullptr; @@ -3923,8 +3895,8 @@ FromProtoEnd = D->protocol_end(); FromProto != FromProtoEnd; ++FromProto, ++FromProtoLoc) { - ObjCProtocolDecl *ToProto - = cast_or_null(Importer.Import(*FromProto)); + auto *ToProto = + cast_or_null(Importer.Import(*FromProto)); if (!ToProto) return nullptr; Protocols.push_back(ToProto); @@ -3944,9 +3916,8 @@ // If we have an implementation, import it as well. if (D->getImplementation()) { - ObjCCategoryImplDecl *Impl - = cast_or_null( - Importer.Import(D->getImplementation())); + auto *Impl = cast_or_null( + Importer.Import(D->getImplementation())); if (!Impl) return nullptr; @@ -3977,8 +3948,7 @@ FromProtoEnd = From->protocol_end(); FromProto != FromProtoEnd; ++FromProto, ++FromProtoLoc) { - ObjCProtocolDecl *ToProto - = cast_or_null(Importer.Import(*FromProto)); + auto *ToProto = cast_or_null(Importer.Import(*FromProto)); if (!ToProto) return true; Protocols.push_back(ToProto); @@ -4138,8 +4108,7 @@ FromProtoEnd = From->protocol_end(); FromProto != FromProtoEnd; ++FromProto, ++FromProtoLoc) { - ObjCProtocolDecl *ToProto - = cast_or_null(Importer.Import(*FromProto)); + auto *ToProto = cast_or_null(Importer.Import(*FromProto)); if (!ToProto) return true; Protocols.push_back(ToProto); @@ -4157,8 +4126,8 @@ // If we have an @implementation, import it as well. if (From->getImplementation()) { - ObjCImplementationDecl *Impl = cast_or_null( - Importer.Import(From->getImplementation())); + auto *Impl = cast_or_null( + Importer.Import(From->getImplementation())); if (!Impl) return true; @@ -4253,8 +4222,8 @@ } Decl *ASTNodeImporter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { - ObjCCategoryDecl *Category = cast_or_null( - Importer.Import(D->getCategoryDecl())); + auto *Category = + cast_or_null(Importer.Import(D->getCategoryDecl())); if (!Category) return nullptr; @@ -4292,8 +4261,8 @@ Decl *ASTNodeImporter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { // Find the corresponding interface. - ObjCInterfaceDecl *Iface = cast_or_null( - Importer.Import(D->getClassInterface())); + auto *Iface = + cast_or_null(Importer.Import(D->getClassInterface())); if (!Iface) return nullptr; @@ -4383,8 +4352,7 @@ SmallVector FoundDecls; DC->getRedeclContext()->localUncachedLookup(Name, FoundDecls); for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) { - if (ObjCPropertyDecl *FoundProp - = dyn_cast(FoundDecls[I])) { + if (auto *FoundProp = dyn_cast(FoundDecls[I])) { // Check property types. if (!Importer.IsStructurallyEquivalent(D->getType(), FoundProp->getType())) { @@ -4436,8 +4404,8 @@ } Decl *ASTNodeImporter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { - ObjCPropertyDecl *Property = cast_or_null( - Importer.Import(D->getPropertyDecl())); + auto *Property = + cast_or_null(Importer.Import(D->getPropertyDecl())); if (!Property) return nullptr; @@ -4453,7 +4421,7 @@ return nullptr; } - ObjCImplDecl *InImpl = dyn_cast(LexicalDC); + auto *InImpl = dyn_cast(LexicalDC); if (!InImpl) return nullptr; @@ -4594,8 +4562,8 @@ // If this record has a definition in the translation unit we're coming from, // but this particular declaration is not that definition, import the // definition and map to that. - CXXRecordDecl *Definition - = cast_or_null(D->getTemplatedDecl()->getDefinition()); + auto *Definition = + cast_or_null(D->getTemplatedDecl()->getDefinition()); if (Definition && Definition != D->getTemplatedDecl()) { Decl *ImportedDef = Importer.Import(Definition->getDescribedClassTemplate()); @@ -4625,8 +4593,7 @@ continue; Decl *Found = FoundDecls[I]; - if (ClassTemplateDecl *FoundTemplate - = dyn_cast(Found)) { + if (auto *FoundTemplate = dyn_cast(Found)) { if (IsStructuralMatch(D, FoundTemplate)) { // The class templates structurally match; call it the same template. // FIXME: We may be filling in a forward declaration here. Handle @@ -4654,8 +4621,7 @@ // Create the declaration that is being templated. // Create the declaration that is being templated. - CXXRecordDecl *D2Templated = cast_or_null( - Importer.Import(DTemplated)); + auto *D2Templated = cast_or_null(Importer.Import(DTemplated)); if (!D2Templated) return nullptr; @@ -4705,9 +4671,8 @@ return Importer.Imported(D, ImportedDef); } - ClassTemplateDecl *ClassTemplate - = cast_or_null(Importer.Import( - D->getSpecializedTemplate())); + auto *ClassTemplate = cast_or_null( + Importer.Import(D->getSpecializedTemplate())); if (!ClassTemplate) return nullptr; @@ -4785,7 +4750,7 @@ // from, // but this particular declaration is not that definition, import the // definition and map to that. - VarDecl *Definition = + auto *Definition = cast_or_null(D->getTemplatedDecl()->getDefinition()); if (Definition && Definition != D->getTemplatedDecl()) { Decl *ImportedDef = Importer.Import(Definition->getDescribedVarTemplate()); @@ -4816,7 +4781,7 @@ continue; Decl *Found = FoundDecls[I]; - if (VarTemplateDecl *FoundTemplate = dyn_cast(Found)) { + if (auto *FoundTemplate = dyn_cast(Found)) { if (IsStructuralMatch(D, FoundTemplate)) { // The variable templates structurally match; call it the same template. Importer.Imported(D->getTemplatedDecl(), @@ -4902,7 +4867,7 @@ return Importer.Imported(D, ImportedDef); } - VarTemplateDecl *VarTemplate = cast_or_null( + auto *VarTemplate = cast_or_null( Importer.Import(D->getSpecializedTemplate())); if (!VarTemplate) return nullptr; @@ -5024,8 +4989,8 @@ SmallVector Clobbers; for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) { - StringLiteral *Clobber = cast_or_null( - Importer.Import(S->getClobberStringLiteral(I))); + auto *Clobber = cast_or_null( + Importer.Import(S->getClobberStringLiteral(I))); if (!Clobber) return nullptr; Clobbers.push_back(Clobber); @@ -5033,16 +4998,16 @@ SmallVector Constraints; for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) { - StringLiteral *Output = cast_or_null( - Importer.Import(S->getOutputConstraintLiteral(I))); + auto *Output = cast_or_null( + Importer.Import(S->getOutputConstraintLiteral(I))); if (!Output) return nullptr; Constraints.push_back(Output); } for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) { - StringLiteral *Input = cast_or_null( - Importer.Import(S->getInputConstraintLiteral(I))); + auto *Input = cast_or_null( + Importer.Import(S->getInputConstraintLiteral(I))); if (!Input) return nullptr; Constraints.push_back(Input); @@ -5055,8 +5020,8 @@ if (ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs())) return nullptr; - StringLiteral *AsmStr = cast_or_null( - Importer.Import(S->getAsmString())); + auto *AsmStr = + cast_or_null(Importer.Import(S->getAsmString())); if (!AsmStr) return nullptr; @@ -5133,8 +5098,7 @@ Stmt *ASTNodeImporter::VisitLabelStmt(LabelStmt *S) { SourceLocation ToIdentLoc = Importer.Import(S->getIdentLoc()); - LabelDecl *ToLabelDecl = - cast_or_null(Importer.Import(S->getDecl())); + auto *ToLabelDecl = cast_or_null(Importer.Import(S->getDecl())); if (!ToLabelDecl && S->getDecl()) return nullptr; Stmt *ToSubStmt = Importer.Import(S->getSubStmt()); @@ -5208,9 +5172,8 @@ Expr *ToCondition = Importer.Import(S->getCond()); if (!ToCondition && S->getCond()) return nullptr; - SwitchStmt *ToStmt = new (Importer.getToContext()) SwitchStmt( - Importer.getToContext(), ToInit, - ToConditionVariable, ToCondition); + auto *ToStmt = new (Importer.getToContext()) SwitchStmt( + Importer.getToContext(), ToInit, ToConditionVariable, ToCondition); Stmt *ToBody = Importer.Import(S->getBody()); if (!ToBody && S->getBody()) return nullptr; @@ -5220,7 +5183,7 @@ SwitchCase *LastChainedSwitchCase = nullptr; for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr; SC = SC->getNextSwitchCase()) { - SwitchCase *ToSC = dyn_cast_or_null(Importer.Import(SC)); + auto *ToSC = dyn_cast_or_null(Importer.Import(SC)); if (!ToSC) return nullptr; if (LastChainedSwitchCase) @@ -5337,8 +5300,8 @@ Expr *ToRetExpr = Importer.Import(S->getRetValue()); if (!ToRetExpr && S->getRetValue()) return nullptr; - VarDecl *NRVOCandidate = const_cast(S->getNRVOCandidate()); - VarDecl *ToNRVOCandidate = cast_or_null(Importer.Import(NRVOCandidate)); + auto *NRVOCandidate = const_cast(S->getNRVOCandidate()); + auto *ToNRVOCandidate = cast_or_null(Importer.Import(NRVOCandidate)); if (!ToNRVOCandidate && NRVOCandidate) return nullptr; return new (Importer.getToContext()) ReturnStmt(ToRetLoc, ToRetExpr, @@ -5380,16 +5343,15 @@ } Stmt *ASTNodeImporter::VisitCXXForRangeStmt(CXXForRangeStmt *S) { - DeclStmt *ToRange = - dyn_cast_or_null(Importer.Import(S->getRangeStmt())); + auto *ToRange = + dyn_cast_or_null(Importer.Import(S->getRangeStmt())); if (!ToRange && S->getRangeStmt()) return nullptr; - DeclStmt *ToBegin = - dyn_cast_or_null(Importer.Import(S->getBeginStmt())); + auto *ToBegin = + dyn_cast_or_null(Importer.Import(S->getBeginStmt())); if (!ToBegin && S->getBeginStmt()) return nullptr; - DeclStmt *ToEnd = - dyn_cast_or_null(Importer.Import(S->getEndStmt())); + auto *ToEnd = dyn_cast_or_null(Importer.Import(S->getEndStmt())); if (!ToEnd && S->getEndStmt()) return nullptr; Expr *ToCond = Importer.Import(S->getCond()); @@ -5398,8 +5360,8 @@ Expr *ToInc = Importer.Import(S->getInc()); if (!ToInc && S->getInc()) return nullptr; - DeclStmt *ToLoopVar = - dyn_cast_or_null(Importer.Import(S->getLoopVarStmt())); + auto *ToLoopVar = + dyn_cast_or_null(Importer.Import(S->getLoopVarStmt())); if (!ToLoopVar && S->getLoopVarStmt()) return nullptr; Stmt *ToBody = Importer.Import(S->getBody()); @@ -5558,8 +5520,7 @@ if (T.isNull()) return nullptr; - StringLiteral *SL = cast_or_null( - Importer.Import(E->getFunctionName())); + auto *SL = cast_or_null(Importer.Import(E->getFunctionName())); if (!SL && E->getFunctionName()) return nullptr; @@ -5568,7 +5529,7 @@ } Expr *ASTNodeImporter::VisitDeclRefExpr(DeclRefExpr *E) { - ValueDecl *ToD = cast_or_null(Importer.Import(E->getDecl())); + auto *ToD = cast_or_null(Importer.Import(E->getDecl())); if (!ToD) return nullptr; @@ -5640,14 +5601,14 @@ Expr *ASTNodeImporter::VisitDesignatedInitExpr(DesignatedInitExpr *DIE) { - Expr *Init = cast_or_null(Importer.Import(DIE->getInit())); + auto *Init = cast_or_null(Importer.Import(DIE->getInit())); if (!Init) return nullptr; SmallVector IndexExprs(DIE->getNumSubExprs() - 1); // List elements from the second, the first is Init itself for (unsigned I = 1, E = DIE->getNumSubExprs(); I < E; I++) { - if (Expr *Arg = cast_or_null(Importer.Import(DIE->getSubExpr(I)))) + if (auto *Arg = cast_or_null(Importer.Import(DIE->getSubExpr(I)))) IndexExprs[I - 1] = Arg; else return nullptr; @@ -5760,7 +5721,7 @@ if (T.isNull()) return nullptr; - LabelDecl *ToLabel = cast_or_null(Importer.Import(E->getLabel())); + auto *ToLabel = cast_or_null(Importer.Import(E->getLabel())); if (!ToLabel) return nullptr; @@ -5795,8 +5756,8 @@ if (T.isNull()) return nullptr; - CompoundStmt *ToSubStmt = cast_or_null( - Importer.Import(E->getSubStmt())); + auto *ToSubStmt = + cast_or_null(Importer.Import(E->getSubStmt())); if (!ToSubStmt && E->getSubStmt()) return nullptr; @@ -5901,8 +5862,8 @@ if (!Cond) return nullptr; - OpaqueValueExpr *OpaqueValue = cast_or_null( - Importer.Import(E->getOpaqueValue())); + auto *OpaqueValue = + cast_or_null(Importer.Import(E->getOpaqueValue())); if (!OpaqueValue) return nullptr; @@ -6060,7 +6021,7 @@ switch (E->getStmtClass()) { case Stmt::CStyleCastExprClass: { - CStyleCastExpr *CCE = cast(E); + auto *CCE = cast(E); return CStyleCastExpr::Create(Importer.getToContext(), T, E->getValueKind(), E->getCastKind(), SubExpr, &BasePath, TInfo, @@ -6069,7 +6030,7 @@ } case Stmt::CXXFunctionalCastExprClass: { - CXXFunctionalCastExpr *FCE = cast(E); + auto *FCE = cast(E); return CXXFunctionalCastExpr::Create(Importer.getToContext(), T, E->getValueKind(), TInfo, E->getCastKind(), SubExpr, &BasePath, @@ -6078,17 +6039,17 @@ } case Stmt::ObjCBridgedCastExprClass: { - ObjCBridgedCastExpr *OCE = cast(E); - return new (Importer.getToContext()) ObjCBridgedCastExpr( - Importer.Import(OCE->getLParenLoc()), OCE->getBridgeKind(), - E->getCastKind(), Importer.Import(OCE->getBridgeKeywordLoc()), - TInfo, SubExpr); + auto *OCE = cast(E); + return new (Importer.getToContext()) ObjCBridgedCastExpr( + Importer.Import(OCE->getLParenLoc()), OCE->getBridgeKind(), + E->getCastKind(), Importer.Import(OCE->getBridgeKeywordLoc()), TInfo, + SubExpr); } default: break; // just fall through } - CXXNamedCastExpr *Named = cast(E); + auto *Named = cast(E); SourceLocation ExprLoc = Importer.Import(Named->getOperatorLoc()), RParenLoc = Importer.Import(Named->getRParenLoc()); SourceRange Brackets = Importer.Import(Named->getAngleBrackets()); @@ -6146,7 +6107,7 @@ break; } case OffsetOfNode::Field: { - FieldDecl *FD = cast_or_null(Importer.Import(Node.getField())); + auto *FD = cast_or_null(Importer.Import(Node.getField())); if (!FD) return nullptr; Nodes.push_back(OffsetOfNode(Importer.Import(Node.getLocStart()), FD, @@ -6217,8 +6178,7 @@ } Expr *ASTNodeImporter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { - ParmVarDecl *Param = cast_or_null( - Importer.Import(E->getParam())); + auto *Param = cast_or_null(Importer.Import(E->getParam())); if (!Param) return nullptr; @@ -6293,8 +6253,8 @@ if (!TempE) return nullptr; - ValueDecl *ExtendedBy = cast_or_null( - Importer.Import(const_cast(E->getExtendingDecl()))); + auto *ExtendedBy = cast_or_null( + Importer.Import(const_cast(E->getExtendingDecl()))); if (!ExtendedBy && E->getExtendingDecl()) return nullptr; @@ -6315,13 +6275,13 @@ if (ImportContainerChecked(CE->placement_arguments(), PlacementArgs)) return nullptr; - FunctionDecl *OperatorNewDecl = cast_or_null( - Importer.Import(CE->getOperatorNew())); + auto *OperatorNewDecl = + cast_or_null(Importer.Import(CE->getOperatorNew())); if (!OperatorNewDecl && CE->getOperatorNew()) return nullptr; - FunctionDecl *OperatorDeleteDecl = cast_or_null( - Importer.Import(CE->getOperatorDelete())); + auto *OperatorDeleteDecl = + cast_or_null(Importer.Import(CE->getOperatorDelete())); if (!OperatorDeleteDecl && CE->getOperatorDelete()) return nullptr; @@ -6355,8 +6315,8 @@ if (T.isNull()) return nullptr; - FunctionDecl *OperatorDeleteDecl = cast_or_null( - Importer.Import(E->getOperatorDelete())); + auto *OperatorDeleteDecl = + cast_or_null(Importer.Import(E->getOperatorDelete())); if (!OperatorDeleteDecl && E->getOperatorDelete()) return nullptr; @@ -6379,8 +6339,8 @@ if (T.isNull()) return nullptr; - CXXConstructorDecl *ToCCD = - dyn_cast_or_null(Importer.Import(E->getConstructor())); + auto *ToCCD = dyn_cast_or_null( + Importer.Import(E->getConstructor())); if (!ToCCD) return nullptr; @@ -6406,8 +6366,7 @@ SmallVector Objs(EWC->getNumObjects()); for (unsigned I = 0, E = EWC->getNumObjects(); I < E; I++) - if (ExprWithCleanups::CleanupObject Obj = - cast_or_null(Importer.Import(EWC->getObject(I)))) + if (auto Obj = cast_or_null(Importer.Import(EWC->getObject(I)))) Objs[I] = Obj; else return nullptr; @@ -6463,7 +6422,7 @@ if (!ToBase && E->getBase()) return nullptr; - ValueDecl *ToMember = dyn_cast(Importer.Import(E->getMemberDecl())); + auto *ToMember = dyn_cast(Importer.Import(E->getMemberDecl())); if (!ToMember && E->getMemberDecl()) return nullptr; @@ -6510,8 +6469,7 @@ ToArgs[ai] = ToArg; } - Expr **ToArgs_Copied = new (Importer.getToContext()) - Expr*[NumArgs]; + auto **ToArgs_Copied = new (Importer.getToContext()) Expr *[NumArgs]; for (unsigned ai = 0, ae = NumArgs; ai != ae; ++ai) ToArgs_Copied[ai] = ToArgs[ai]; @@ -6545,15 +6503,14 @@ } if (FieldDecl *FromFD = ILE->getInitializedFieldInUnion()) { - FieldDecl *ToFD = cast_or_null(Importer.Import(FromFD)); + auto *ToFD = cast_or_null(Importer.Import(FromFD)); if (!ToFD) return nullptr; To->setInitializedFieldInUnion(ToFD); } if (InitListExpr *SyntForm = ILE->getSyntacticForm()) { - InitListExpr *ToSyntForm = cast_or_null( - Importer.Import(SyntForm)); + auto *ToSyntForm = cast_or_null(Importer.Import(SyntForm)); if (!ToSyntForm) return nullptr; To->setSyntacticForm(ToSyntForm); @@ -6591,8 +6548,8 @@ } Expr *ASTNodeImporter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) { - FieldDecl *ToField = llvm::dyn_cast_or_null( - Importer.Import(DIE->getField())); + auto *ToField = + llvm::dyn_cast_or_null(Importer.Import(DIE->getField())); if (!ToField && DIE->getField()) return nullptr; @@ -6717,12 +6674,12 @@ // Record the imported declaration. ImportedDecls[FromD] = ToD; - - if (TagDecl *FromTag = dyn_cast(FromD)) { + + if (auto *FromTag = dyn_cast(FromD)) { // Keep track of anonymous tags that have an associated typedef. if (FromTag->getTypedefNameForAnonDecl()) AnonTagsWithPendingTypedefs.push_back(FromTag); - } else if (TypedefNameDecl *FromTypedef = dyn_cast(FromD)) { + } else if (auto *FromTypedef = dyn_cast(FromD)) { // When we've finished transforming a typedef, see whether it was the // typedef for an anonymous tag. for (SmallVectorImpl::iterator @@ -6730,7 +6687,7 @@ FromTagEnd = AnonTagsWithPendingTypedefs.end(); FromTag != FromTagEnd; ++FromTag) { if ((*FromTag)->getTypedefNameForAnonDecl() == FromTypedef) { - if (TagDecl *ToTag = cast_or_null(Import(*FromTag))) { + if (auto *ToTag = cast_or_null(Import(*FromTag))) { // We found the typedef for an anonymous tag; link them. ToTag->setTypedefNameForAnonDecl(cast(ToD)); AnonTagsWithPendingTypedefs.erase(FromTag); @@ -6747,14 +6704,14 @@ if (!FromDC) return FromDC; - DeclContext *ToDC = cast_or_null(Import(cast(FromDC))); + auto *ToDC = cast_or_null(Import(cast(FromDC))); if (!ToDC) return nullptr; // When we're using a record/enum/Objective-C class/protocol as a context, we // need it to have a definition. - if (RecordDecl *ToRecord = dyn_cast(ToDC)) { - RecordDecl *FromRecord = cast(FromDC); + if (auto *ToRecord = dyn_cast(ToDC)) { + auto *FromRecord = cast(FromDC); if (ToRecord->isCompleteDefinition()) { // Do nothing. } else if (FromRecord->isCompleteDefinition()) { @@ -6763,8 +6720,8 @@ } else { CompleteDecl(ToRecord); } - } else if (EnumDecl *ToEnum = dyn_cast(ToDC)) { - EnumDecl *FromEnum = cast(FromDC); + } else if (auto *ToEnum = dyn_cast(ToDC)) { + auto *FromEnum = cast(FromDC); if (ToEnum->isCompleteDefinition()) { // Do nothing. } else if (FromEnum->isCompleteDefinition()) { @@ -6772,9 +6729,9 @@ ASTNodeImporter::IDK_Basic); } else { CompleteDecl(ToEnum); - } - } else if (ObjCInterfaceDecl *ToClass = dyn_cast(ToDC)) { - ObjCInterfaceDecl *FromClass = cast(FromDC); + } + } else if (auto *ToClass = dyn_cast(ToDC)) { + auto *FromClass = cast(FromDC); if (ToClass->getDefinition()) { // Do nothing. } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) { @@ -6783,8 +6740,8 @@ } else { CompleteDecl(ToClass); } - } else if (ObjCProtocolDecl *ToProto = dyn_cast(ToDC)) { - ObjCProtocolDecl *FromProto = cast(FromDC); + } else if (auto *ToProto = dyn_cast(ToDC)) { + auto *FromProto = cast(FromDC); if (ToProto->getDefinition()) { // Do nothing. } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) { @@ -6839,15 +6796,14 @@ return nullptr; case NestedNameSpecifier::Namespace: - if (NamespaceDecl *NS = - cast(Import(FromNNS->getAsNamespace()))) { + if (auto *NS = cast(Import(FromNNS->getAsNamespace()))) { return NestedNameSpecifier::Create(ToContext, prefix, NS); } return nullptr; case NestedNameSpecifier::NamespaceAlias: - if (NamespaceAliasDecl *NSAD = - cast(Import(FromNNS->getAsNamespaceAlias()))) { + if (auto *NSAD = + cast(Import(FromNNS->getAsNamespaceAlias()))) { return NestedNameSpecifier::Create(ToContext, prefix, NSAD); } return nullptr; @@ -6856,8 +6812,7 @@ return NestedNameSpecifier::GlobalSpecifier(ToContext); case NestedNameSpecifier::Super: - if (CXXRecordDecl *RD = - cast(Import(FromNNS->getAsRecordDecl()))) { + if (auto *RD = cast(Import(FromNNS->getAsRecordDecl()))) { return NestedNameSpecifier::SuperSpecifier(ToContext, RD); } return nullptr; @@ -6886,8 +6841,8 @@ TemplateName ASTImporter::Import(TemplateName From) { switch (From.getKind()) { case TemplateName::Template: - if (TemplateDecl *ToTemplate - = cast_or_null(Import(From.getAsTemplateDecl()))) + if (auto *ToTemplate = + cast_or_null(Import(From.getAsTemplateDecl()))) return TemplateName(ToTemplate); return TemplateName(); @@ -6898,7 +6853,7 @@ for (OverloadedTemplateStorage::iterator I = FromStorage->begin(), E = FromStorage->end(); I != E; ++I) { - if (NamedDecl *To = cast_or_null(Import(*I))) + if (auto *To = cast_or_null(Import(*I))) ToTemplates.addDecl(To); else return TemplateName(); @@ -6912,9 +6867,9 @@ NestedNameSpecifier *Qualifier = Import(QTN->getQualifier()); if (!Qualifier) return TemplateName(); - - if (TemplateDecl *ToTemplate - = cast_or_null(Import(From.getAsTemplateDecl()))) + + if (auto *ToTemplate = + cast_or_null(Import(From.getAsTemplateDecl()))) return ToContext.getQualifiedTemplateName(Qualifier, QTN->hasTemplateKeyword(), ToTemplate); @@ -6939,8 +6894,8 @@ case TemplateName::SubstTemplateTemplateParm: { SubstTemplateTemplateParmStorage *subst = From.getAsSubstTemplateTemplateParm(); - TemplateTemplateParmDecl *param - = cast_or_null(Import(subst->getParameter())); + auto *param = + cast_or_null(Import(subst->getParameter())); if (!param) return TemplateName(); @@ -6953,9 +6908,8 @@ case TemplateName::SubstTemplateTemplateParmPack: { SubstTemplateTemplateParmPackStorage *SubstPack = From.getAsSubstTemplateTemplateParmPack(); - TemplateTemplateParmDecl *Param - = cast_or_null( - Import(SubstPack->getParameterPack())); + auto *Param = cast_or_null( + Import(SubstPack->getParameterPack())); if (!Param) return TemplateName(); @@ -7055,8 +7009,7 @@ From->isPackExpansion() ? Import(From->getEllipsisLoc()) : SourceLocation()); } else if (From->isMemberInitializer()) { - FieldDecl *ToField = - llvm::cast_or_null(Import(From->getMember())); + auto *ToField = llvm::cast_or_null(Import(From->getMember())); if (!ToField && From->getMember()) return nullptr; @@ -7064,7 +7017,7 @@ ToContext, ToField, Import(From->getMemberLocation()), Import(From->getLParenLoc()), ToExpr, Import(From->getRParenLoc())); } else if (From->isIndirectMemberInitializer()) { - IndirectFieldDecl *ToIField = llvm::cast_or_null( + auto *ToIField = llvm::cast_or_null( Import(From->getIndirectMember())); if (!ToIField && From->getIndirectMember()) return nullptr; @@ -7105,11 +7058,11 @@ Decl *To = Import(From); if (!To) return; - - if (DeclContext *FromDC = cast(From)) { + + if (auto *FromDC = cast(From)) { ASTNodeImporter Importer(*this); - - if (RecordDecl *ToRecord = dyn_cast(To)) { + + if (auto *ToRecord = dyn_cast(To)) { if (!ToRecord->getDefinition()) { Importer.ImportDefinition(cast(FromDC), ToRecord, ASTNodeImporter::IDK_Everything); @@ -7117,15 +7070,15 @@ } } - if (EnumDecl *ToEnum = dyn_cast(To)) { + if (auto *ToEnum = dyn_cast(To)) { if (!ToEnum->getDefinition()) { Importer.ImportDefinition(cast(FromDC), ToEnum, ASTNodeImporter::IDK_Everything); return; } } - - if (ObjCInterfaceDecl *ToIFace = dyn_cast(To)) { + + if (auto *ToIFace = dyn_cast(To)) { if (!ToIFace->getDefinition()) { Importer.ImportDefinition(cast(FromDC), ToIFace, ASTNodeImporter::IDK_Everything); @@ -7133,7 +7086,7 @@ } } - if (ObjCProtocolDecl *ToProto = dyn_cast(To)) { + if (auto *ToProto = dyn_cast(To)) { if (!ToProto->getDefinition()) { Importer.ImportDefinition(cast(FromDC), ToProto, ASTNodeImporter::IDK_Everything); @@ -7249,15 +7202,13 @@ } void ASTImporter::CompleteDecl (Decl *D) { - if (ObjCInterfaceDecl *ID = dyn_cast(D)) { + if (auto *ID = dyn_cast(D)) { if (!ID->getDefinition()) ID->startDefinition(); - } - else if (ObjCProtocolDecl *PD = dyn_cast(D)) { + } else if (auto *PD = dyn_cast(D)) { if (!PD->getDefinition()) PD->startDefinition(); - } - else if (TagDecl *TD = dyn_cast(D)) { + } else if (auto *TD = dyn_cast(D)) { if (!TD->getDefinition() && !TD->isBeingDefined()) { TD->startDefinition(); TD->setCompleteDefinition(true); Index: lib/AST/ASTTypeTraits.cpp =================================================================== --- lib/AST/ASTTypeTraits.cpp +++ lib/AST/ASTTypeTraits.cpp @@ -108,49 +108,49 @@ void DynTypedNode::print(llvm::raw_ostream &OS, const PrintingPolicy &PP) const { - if (const TemplateArgument *TA = get()) + if (const auto *TA = get()) TA->print(PP, OS); - else if (const TemplateName *TN = get()) + else if (const auto *TN = get()) TN->print(OS, PP); - else if (const NestedNameSpecifier *NNS = get()) + else if (const auto *NNS = get()) NNS->print(OS, PP); - else if (const NestedNameSpecifierLoc *NNSL = get()) + else if (const auto *NNSL = get()) NNSL->getNestedNameSpecifier()->print(OS, PP); - else if (const QualType *QT = get()) + else if (const auto *QT = get()) QT->print(OS, PP); - else if (const TypeLoc *TL = get()) + else if (const auto *TL = get()) TL->getType().print(OS, PP); - else if (const Decl *D = get()) + else if (const auto *D = get()) D->print(OS, PP); - else if (const Stmt *S = get()) + else if (const auto *S = get()) S->printPretty(OS, nullptr, PP); - else if (const Type *T = get()) + else if (const auto *T = get()) QualType(T, 0).print(OS, PP); else OS << "Unable to print values of type " << NodeKind.asStringRef() << "\n"; } void DynTypedNode::dump(llvm::raw_ostream &OS, SourceManager &SM) const { - if (const Decl *D = get()) + if (const auto *D = get()) D->dump(OS); - else if (const Stmt *S = get()) + else if (const auto *S = get()) S->dump(OS, SM); - else if (const Type *T = get()) + else if (const auto *T = get()) T->dump(OS); else OS << "Unable to dump values of type " << NodeKind.asStringRef() << "\n"; } SourceRange DynTypedNode::getSourceRange() const { - if (const CXXCtorInitializer *CCI = get()) + if (const auto *CCI = get()) return CCI->getSourceRange(); - if (const NestedNameSpecifierLoc *NNSL = get()) + if (const auto *NNSL = get()) return NNSL->getSourceRange(); - if (const TypeLoc *TL = get()) + if (const auto *TL = get()) return TL->getSourceRange(); - if (const Decl *D = get()) + if (const auto *D = get()) return D->getSourceRange(); - if (const Stmt *S = get()) + if (const auto *S = get()) return S->getSourceRange(); return SourceRange(); } Index: lib/AST/CXXInheritance.cpp =================================================================== --- lib/AST/CXXInheritance.cpp +++ lib/AST/CXXInheritance.cpp @@ -26,7 +26,7 @@ "Already computed the set of declarations"); llvm::SetVector > Decls; - for (paths_iterator Path = begin(), PathEnd = end(); Path != PathEnd; ++Path) + for (auto Path = begin(), PathEnd = end(); Path != PathEnd; ++Path) Decls.insert(Path->Decls.front()); NumDeclsFound = Decls.size(); @@ -148,8 +148,7 @@ continue; } - CXXRecordDecl *Base = - cast_or_null(Ty->getDecl()->getDefinition()); + auto *Base = cast_or_null(Ty->getDecl()->getDefinition()); if (!Base || (Base->isDependentContext() && !Base->isCurrentInstantiation(Record))) { @@ -262,9 +261,8 @@ return FoundPath; } } else if (VisitBase) { - CXXRecordDecl *BaseRecord - = cast(BaseSpec.getType()->castAs() - ->getDecl()); + auto *BaseRecord = cast( + BaseSpec.getType()->castAs()->getDecl()); if (lookupInBases(Context, BaseRecord, BaseMatches)) { // C++ [class.member.lookup]p2: // A member name f in one sub-object B hides a member name f in @@ -448,7 +446,7 @@ } void OverridingMethods::add(const OverridingMethods &Other) { - for (const_iterator I = Other.begin(), IE = Other.end(); I != IE; ++I) { + for (auto I = Other.begin(), IE = Other.end(); I != IE; ++I) { for (overriding_const_iterator M = I->second.begin(), MEnd = I->second.end(); M != MEnd; @@ -458,7 +456,7 @@ } void OverridingMethods::replaceAll(UniqueVirtualMethod Overriding) { - for (iterator I = begin(), IEnd = end(); I != IEnd; ++I) { + for (auto I = begin(), IEnd = end(); I != IEnd; ++I) { I->second.clear(); I->second.push_back(Overriding); } @@ -532,12 +530,10 @@ // Merge the overriders from this base class into our own set of // overriders. - for (CXXFinalOverriderMap::iterator OM = BaseOverriders->begin(), - OMEnd = BaseOverriders->end(); - OM != OMEnd; - ++OM) { - const CXXMethodDecl *CanonOM - = cast(OM->first->getCanonicalDecl()); + for (auto OM = BaseOverriders->begin(), OMEnd = BaseOverriders->end(); + OM != OMEnd; ++OM) { + const auto *CanonOM = + cast(OM->first->getCanonicalDecl()); Overriders[CanonOM].add(OM->second); } } @@ -548,7 +544,7 @@ if (!M->isVirtual()) continue; - CXXMethodDecl *CanonM = cast(M->getCanonicalDecl()); + auto *CanonM = cast(M->getCanonicalDecl()); if (CanonM->begin_overridden_methods() == CanonM->end_overridden_methods()) { Index: lib/AST/Comment.cpp =================================================================== --- lib/AST/Comment.cpp +++ lib/AST/Comment.cpp @@ -213,7 +213,7 @@ case Decl::CXXConstructor: case Decl::CXXDestructor: case Decl::CXXConversion: { - const FunctionDecl *FD = cast(CommentDecl); + const auto *FD = cast(CommentDecl); Kind = FunctionKind; ParamVars = FD->parameters(); ReturnType = FD->getReturnType(); @@ -226,14 +226,14 @@ if (K == Decl::CXXMethod || K == Decl::CXXConstructor || K == Decl::CXXDestructor || K == Decl::CXXConversion) { - const CXXMethodDecl *MD = cast(CommentDecl); + const auto *MD = cast(CommentDecl); IsInstanceMethod = MD->isInstance(); IsClassMethod = !IsInstanceMethod; } break; } case Decl::ObjCMethod: { - const ObjCMethodDecl *MD = cast(CommentDecl); + const auto *MD = cast(CommentDecl); Kind = FunctionKind; ParamVars = MD->parameters(); ReturnType = MD->getReturnType(); @@ -243,7 +243,7 @@ break; } case Decl::FunctionTemplate: { - const FunctionTemplateDecl *FTD = cast(CommentDecl); + const auto *FTD = cast(CommentDecl); Kind = FunctionKind; TemplateKind = Template; const FunctionDecl *FD = FTD->getTemplatedDecl(); @@ -253,14 +253,14 @@ break; } case Decl::ClassTemplate: { - const ClassTemplateDecl *CTD = cast(CommentDecl); + const auto *CTD = cast(CommentDecl); Kind = ClassKind; TemplateKind = Template; TemplateParameters = CTD->getTemplateParameters(); break; } case Decl::ClassTemplatePartialSpecialization: { - const ClassTemplatePartialSpecializationDecl *CTPSD = + const auto *CTPSD = cast(CommentDecl); Kind = ClassKind; TemplateKind = TemplatePartialSpecialization; @@ -306,7 +306,7 @@ break; } case Decl::TypeAliasTemplate: { - const TypeAliasTemplateDecl *TAT = cast(CommentDecl); + const auto *TAT = cast(CommentDecl); Kind = TypedefKind; TemplateKind = Template; TemplateParameters = TAT->getTemplateParameters(); @@ -348,8 +348,7 @@ if (i == e-1) return TPL->getParam(getIndex(i))->getName(); const NamedDecl *Param = TPL->getParam(getIndex(i)); - if (const TemplateTemplateParmDecl *TTP = - dyn_cast(Param)) + if (const auto *TTP = dyn_cast(Param)) TPL = TTP->getTemplateParameters(); } return ""; Index: lib/AST/CommentCommandTraits.cpp =================================================================== --- lib/AST/CommentCommandTraits.cpp +++ lib/AST/CommentCommandTraits.cpp @@ -23,9 +23,8 @@ void CommandTraits::registerCommentOptions( const CommentOptions &CommentOptions) { - for (CommentOptions::BlockCommandNamesTy::const_iterator - I = CommentOptions.BlockCommandNames.begin(), - E = CommentOptions.BlockCommandNames.end(); + for (auto I = CommentOptions.BlockCommandNames.begin(), + E = CommentOptions.BlockCommandNames.end(); I != E; I++) { registerBlockCommand(*I); } @@ -82,12 +81,12 @@ } CommandInfo *CommandTraits::createCommandInfoWithName(StringRef CommandName) { - char *Name = Allocator.Allocate(CommandName.size() + 1); + auto *Name = Allocator.Allocate(CommandName.size() + 1); memcpy(Name, CommandName.data(), CommandName.size()); Name[CommandName.size()] = '\0'; // Value-initialize (=zero-initialize in this case) a new CommandInfo. - CommandInfo *Info = new (Allocator) CommandInfo(); + auto *Info = new (Allocator) CommandInfo(); Info->Name = Name; // We only have a limited number of bits to encode command IDs in the // CommandInfo structure, so the ID numbers can potentially wrap around. Index: lib/AST/CommentLexer.cpp =================================================================== --- lib/AST/CommentLexer.cpp +++ lib/AST/CommentLexer.cpp @@ -40,7 +40,7 @@ static inline StringRef convertCodePointToUTF8( llvm::BumpPtrAllocator &Allocator, unsigned CodePoint) { - char *Resolved = Allocator.Allocate(UNI_MAX_UTF8_BYTES_PER_CODE_POINT); + auto *Resolved = Allocator.Allocate(UNI_MAX_UTF8_BYTES_PER_CODE_POINT); char *ResolvedPtr = Resolved; if (llvm::ConvertCodePointToUTF8(CodePoint, ResolvedPtr)) return StringRef(Resolved, ResolvedPtr - Resolved); Index: lib/AST/CommentParser.cpp =================================================================== --- lib/AST/CommentParser.cpp +++ lib/AST/CommentParser.cpp @@ -175,7 +175,7 @@ return false; } - char *TextPtr = Allocator.Allocate(Length + 1); + auto *TextPtr = Allocator.Allocate(Length + 1); memcpy(TextPtr, WordText.c_str(), Length + 1); StringRef Text = StringRef(TextPtr, Length); @@ -220,7 +220,7 @@ } const unsigned Length = WordText.size(); - char *TextPtr = Allocator.Allocate(Length + 1); + auto *TextPtr = Allocator.Allocate(Length + 1); memcpy(TextPtr, WordText.c_str(), Length + 1); StringRef Text = StringRef(TextPtr, Length); @@ -294,8 +294,7 @@ TextTokenRetokenizer &Retokenizer, unsigned NumArgs) { typedef BlockCommandComment::Argument Argument; - Argument *Args = - new (Allocator.Allocate(NumArgs)) Argument[NumArgs]; + auto *Args = new (Allocator.Allocate(NumArgs)) Argument[NumArgs]; unsigned ParsedArgs = 0; Token Arg; while (ParsedArgs < NumArgs && Retokenizer.lexWord(Arg)) { Index: lib/AST/CommentSema.cpp =================================================================== --- lib/AST/CommentSema.cpp +++ lib/AST/CommentSema.cpp @@ -52,9 +52,8 @@ SourceLocation LocEnd, unsigned CommandID, CommandMarkerKind CommandMarker) { - BlockCommandComment *BC = new (Allocator) BlockCommandComment(LocBegin, LocEnd, - CommandID, - CommandMarker); + auto *BC = new (Allocator) + BlockCommandComment(LocBegin, LocEnd, CommandID, CommandMarker); checkContainerDecl(BC); return BC; } @@ -82,9 +81,8 @@ SourceLocation LocEnd, unsigned CommandID, CommandMarkerKind CommandMarker) { - ParamCommandComment *Command = - new (Allocator) ParamCommandComment(LocBegin, LocEnd, CommandID, - CommandMarker); + auto *Command = new (Allocator) + ParamCommandComment(LocBegin, LocEnd, CommandID, CommandMarker); if (!isFunctionDecl()) Diag(Command->getLocation(), @@ -283,9 +281,8 @@ SourceLocation LocEnd, unsigned CommandID, CommandMarkerKind CommandMarker) { - TParamCommandComment *Command = - new (Allocator) TParamCommandComment(LocBegin, LocEnd, CommandID, - CommandMarker); + auto *Command = new (Allocator) + TParamCommandComment(LocBegin, LocEnd, CommandID, CommandMarker); if (!isTemplateOrSpecialization()) Diag(Command->getLocation(), @@ -476,8 +473,7 @@ HTMLEndTagComment *Sema::actOnHTMLEndTag(SourceLocation LocBegin, SourceLocation LocEnd, StringRef TagName) { - HTMLEndTagComment *HET = - new (Allocator) HTMLEndTagComment(LocBegin, LocEnd, TagName); + auto *HET = new (Allocator) HTMLEndTagComment(LocBegin, LocEnd, TagName); if (isHTMLEndTagForbidden(TagName)) { Diag(HET->getLocation(), diag::warn_doc_html_end_forbidden) << TagName << HET->getSourceRange(); @@ -543,7 +539,7 @@ FullComment *Sema::actOnFullComment( ArrayRef Blocks) { - FullComment *FC = new (Allocator) FullComment(Blocks, ThisDeclInfo); + auto *FC = new (Allocator) FullComment(Blocks, ThisDeclInfo); resolveParamCommandIndexes(FC); // Complain about HTML tags that are not closed. @@ -678,7 +674,7 @@ << Command->getSourceRange(); // Try to emit a fixit with a deprecation attribute. - if (const FunctionDecl *FD = dyn_cast(D)) { + if (const auto *FD = dyn_cast(D)) { // Don't emit a Fix-It for non-member function definitions. GCC does not // accept attributes on them. const DeclContext *Ctx = FD->getDeclContext(); @@ -727,7 +723,7 @@ // First pass over all \\param commands: resolve all parameter names. for (Comment::child_iterator I = FC->child_begin(), E = FC->child_end(); I != E; ++I) { - ParamCommandComment *PCC = dyn_cast(*I); + auto *PCC = dyn_cast(*I); if (!PCC || !PCC->hasParamName()) continue; StringRef ParamName = PCC->getParamNameAsWritten(); @@ -813,14 +809,12 @@ bool Sema::isFunctionOrMethodVariadic() { if (!isAnyFunctionDecl() && !isObjCMethodDecl() && !isFunctionTemplateDecl()) return false; - if (const FunctionDecl *FD = - dyn_cast(ThisDeclInfo->CurrentDecl)) + if (const auto *FD = dyn_cast(ThisDeclInfo->CurrentDecl)) return FD->isVariadic(); - if (const FunctionTemplateDecl *FTD = - dyn_cast(ThisDeclInfo->CurrentDecl)) + if (const auto *FTD = + dyn_cast(ThisDeclInfo->CurrentDecl)) return FTD->getTemplatedDecl()->isVariadic(); - if (const ObjCMethodDecl *MD = - dyn_cast(ThisDeclInfo->CurrentDecl)) + if (const auto *MD = dyn_cast(ThisDeclInfo->CurrentDecl)) return MD->isVariadic(); return false; } @@ -836,7 +830,7 @@ if (!ThisDeclInfo->IsFilled) inspectThisDecl(); if (ThisDeclInfo->getKind() == DeclInfo::VariableKind) { - if (const VarDecl *VD = dyn_cast_or_null(ThisDeclInfo->CurrentDecl)) { + if (const auto *VD = dyn_cast_or_null(ThisDeclInfo->CurrentDecl)) { QualType QT = VD->getType(); return QT->isFunctionPointerType(); } @@ -874,8 +868,7 @@ return false; if (!ThisDeclInfo->IsFilled) inspectThisDecl(); - if (const RecordDecl *RD = - dyn_cast_or_null(ThisDeclInfo->CurrentDecl)) + if (const auto *RD = dyn_cast_or_null(ThisDeclInfo->CurrentDecl)) return RD->isUnion(); return false; } @@ -1026,8 +1019,7 @@ return true; } - if (const TemplateTemplateParmDecl *TTP = - dyn_cast(Param)) { + if (const auto *TTP = dyn_cast(Param)) { Position->push_back(i); if (ResolveTParamReferenceHelper(Name, TTP->getTemplateParameters(), Position)) @@ -1058,8 +1050,7 @@ const NamedDecl *Param = TemplateParameters->getParam(i); Corrector.addDecl(Param); - if (const TemplateTemplateParmDecl *TTP = - dyn_cast(Param)) + if (const auto *TTP = dyn_cast(Param)) CorrectTypoInTParamReferenceHelper(TTP->getTemplateParameters(), Corrector); } Index: lib/AST/Decl.cpp =================================================================== --- lib/AST/Decl.cpp +++ lib/AST/Decl.cpp @@ -143,9 +143,8 @@ /// that records that it already has explicit visibility. static LVComputationKind withExplicitVisibilityAlready(LVComputationKind oldKind) { - LVComputationKind newKind = - static_cast(unsigned(oldKind) | - IgnoreExplicitVisibilityBit); + auto newKind = static_cast(unsigned(oldKind) | + IgnoreExplicitVisibilityBit); assert(oldKind != LVForType || newKind == LVForExplicitType); assert(oldKind != LVForValue || newKind == LVForExplicitValue); assert(oldKind != LVForExplicitType || newKind == LVForExplicitType); @@ -2197,7 +2196,7 @@ } APValue *VarDecl::getEvaluatedValue() const { - if (EvaluatedStmt *Eval = Init.dyn_cast()) + if (auto *Eval = Init.dyn_cast()) if (Eval->WasEvaluated) return &Eval->Evaluated; @@ -2205,7 +2204,7 @@ } bool VarDecl::isInitKnownICE() const { - if (EvaluatedStmt *Eval = Init.dyn_cast()) + if (auto *Eval = Init.dyn_cast()) return Eval->CheckedICE; return false; @@ -2354,8 +2353,7 @@ getMemberSpecializationInfo()) && "not a variable or static data member template specialization"); - if (VarTemplateSpecializationDecl *Spec = - dyn_cast(this)) { + if (auto *Spec = dyn_cast(this)) { Spec->setSpecializationKind(TSK); if (TSK != TSK_ExplicitSpecialization && PointOfInstantiation.isValid() && Spec->getPointOfInstantiation().isInvalid()) @@ -2575,15 +2573,15 @@ } bool FunctionDecl::isMain() const { - const TranslationUnitDecl *tunit = - dyn_cast(getDeclContext()->getRedeclContext()); + const auto *tunit = + dyn_cast(getDeclContext()->getRedeclContext()); return tunit && !tunit->getASTContext().getLangOpts().Freestanding && isNamed(this, "main"); } bool FunctionDecl::isMSVCRTEntryPoint() const { - const TranslationUnitDecl *TUnit = + const auto *TUnit = dyn_cast(getDeclContext()->getRedeclContext()); if (!TUnit) return false; @@ -3230,9 +3228,8 @@ } FunctionTemplateDecl *FunctionDecl::getPrimaryTemplate() const { - if (FunctionTemplateSpecializationInfo *Info - = TemplateOrSpecialization - .dyn_cast()) { + if (auto *Info = TemplateOrSpecialization + .dyn_cast()) { return Info->Template.getPointer(); } return nullptr; @@ -3250,9 +3247,8 @@ const TemplateArgumentList * FunctionDecl::getTemplateSpecializationArgs() const { - if (FunctionTemplateSpecializationInfo *Info - = TemplateOrSpecialization - .dyn_cast()) { + if (auto *Info = TemplateOrSpecialization + .dyn_cast()) { return Info->TemplateArguments; } return nullptr; @@ -3260,9 +3256,8 @@ const ASTTemplateArgumentListInfo * FunctionDecl::getTemplateSpecializationArgsAsWritten() const { - if (FunctionTemplateSpecializationInfo *Info - = TemplateOrSpecialization - .dyn_cast()) { + if (auto *Info = TemplateOrSpecialization + .dyn_cast()) { return Info->TemplateArgumentsAsWritten; } return nullptr; @@ -3278,8 +3273,8 @@ SourceLocation PointOfInstantiation) { assert(TSK != TSK_Undeclared && "Must specify the type of function template specialization"); - FunctionTemplateSpecializationInfo *Info - = TemplateOrSpecialization.dyn_cast(); + auto *Info = + TemplateOrSpecialization.dyn_cast(); if (!Info) Info = FunctionTemplateSpecializationInfo::Create(C, this, Template, TSK, TemplateArgs, @@ -3324,11 +3319,11 @@ NumTemplates = Ts.size(); NumArgs = TArgs.size(); - FunctionTemplateDecl **TsArray = getTrailingObjects(); + auto **TsArray = getTrailingObjects(); for (unsigned I = 0, E = Ts.size(); I != E; ++I) TsArray[I] = cast(Ts[I]->getUnderlyingDecl()); - TemplateArgumentLoc *ArgsArray = getTrailingObjects(); + auto *ArgsArray = getTrailingObjects(); for (unsigned I = 0, E = TArgs.size(); I != E; ++I) new (&ArgsArray[I]) TemplateArgumentLoc(TArgs[I]); } @@ -3336,13 +3331,13 @@ TemplateSpecializationKind FunctionDecl::getTemplateSpecializationKind() const { // For a function template specialization, query the specialization // information object. - FunctionTemplateSpecializationInfo *FTSInfo - = TemplateOrSpecialization.dyn_cast(); + auto *FTSInfo = + TemplateOrSpecialization.dyn_cast(); if (FTSInfo) return FTSInfo->getTemplateSpecializationKind(); - MemberSpecializationInfo *MSInfo - = TemplateOrSpecialization.dyn_cast(); + auto *MSInfo = + TemplateOrSpecialization.dyn_cast(); if (MSInfo) return MSInfo->getTemplateSpecializationKind(); @@ -3352,16 +3347,15 @@ void FunctionDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation) { - if (FunctionTemplateSpecializationInfo *FTSInfo - = TemplateOrSpecialization.dyn_cast< - FunctionTemplateSpecializationInfo*>()) { + if (auto *FTSInfo = TemplateOrSpecialization + .dyn_cast()) { FTSInfo->setTemplateSpecializationKind(TSK); if (TSK != TSK_ExplicitSpecialization && PointOfInstantiation.isValid() && FTSInfo->getPointOfInstantiation().isInvalid()) FTSInfo->setPointOfInstantiation(PointOfInstantiation); - } else if (MemberSpecializationInfo *MSInfo - = TemplateOrSpecialization.dyn_cast()) { + } else if (auto *MSInfo = TemplateOrSpecialization + .dyn_cast()) { MSInfo->setTemplateSpecializationKind(TSK); if (TSK != TSK_ExplicitSpecialization && PointOfInstantiation.isValid() && @@ -3372,12 +3366,11 @@ } SourceLocation FunctionDecl::getPointOfInstantiation() const { - if (FunctionTemplateSpecializationInfo *FTSInfo - = TemplateOrSpecialization.dyn_cast< - FunctionTemplateSpecializationInfo*>()) + if (auto *FTSInfo = TemplateOrSpecialization + .dyn_cast()) return FTSInfo->getPointOfInstantiation(); - else if (MemberSpecializationInfo *MSInfo - = TemplateOrSpecialization.dyn_cast()) + else if (auto *MSInfo = + TemplateOrSpecialization.dyn_cast()) return MSInfo->getPointOfInstantiation(); return SourceLocation(); @@ -3614,8 +3607,7 @@ IsBeingDefined = true; if (auto *D = dyn_cast(this)) { - struct CXXRecordDecl::DefinitionData *Data = - new (getASTContext()) struct CXXRecordDecl::DefinitionData(D); + auto *Data = new (getASTContext()) struct CXXRecordDecl::DefinitionData(D); for (auto I : redecls()) cast(I)->DefinitionData = Data; } @@ -3798,8 +3790,8 @@ RecordDecl *RecordDecl::Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl* PrevDecl) { - RecordDecl *R = new (C, DC) RecordDecl(Record, TK, C, DC, - StartLoc, IdLoc, Id, PrevDecl); + auto *R = + new (C, DC) RecordDecl(Record, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl); R->MayHaveOutOfDateDef = C.getLangOpts().Modules; C.getTypeDeclType(R, PrevDecl); @@ -3997,9 +3989,8 @@ SourceLocation CommentLoc, PragmaMSCommentKind CommentKind, StringRef Arg) { - PragmaCommentDecl *PCD = - new (C, DC, additionalSizeToAlloc(Arg.size() + 1)) - PragmaCommentDecl(DC, CommentLoc, CommentKind); + auto *PCD = new (C, DC, additionalSizeToAlloc(Arg.size() + 1)) + PragmaCommentDecl(DC, CommentLoc, CommentKind); memcpy(PCD->getTrailingObjects(), Arg.data(), Arg.size()); PCD->getTrailingObjects()[Arg.size()] = '\0'; return PCD; @@ -4019,7 +4010,7 @@ SourceLocation Loc, StringRef Name, StringRef Value) { size_t ValueStart = Name.size() + 1; - PragmaDetectMismatchDecl *PDMD = + auto *PDMD = new (C, DC, additionalSizeToAlloc(ValueStart + Value.size() + 1)) PragmaDetectMismatchDecl(DC, Loc, ValueStart); memcpy(PDMD->getTrailingObjects(), Name.data(), Name.size()); @@ -4064,7 +4055,7 @@ } void LabelDecl::setMSAsmLabel(StringRef Name) { - char *Buffer = new (getASTContext(), 1) char[Name.size() + 1]; + auto *Buffer = new (getASTContext(), 1) char[Name.size() + 1]; memcpy(Buffer, Name.data(), Name.size()); Buffer[Name.size()] = '\0'; MSAsmName = Buffer; @@ -4103,7 +4094,7 @@ bool isInlineSpecified, bool hasWrittenPrototype, bool isConstexprSpecified) { - FunctionDecl *New = + auto *New = new (C, DC) FunctionDecl(Function, C, DC, StartLoc, NameInfo, T, TInfo, SC, isInlineSpecified, isConstexprSpecified); New->HasWrittenPrototype = hasWrittenPrototype; @@ -4323,7 +4314,7 @@ SourceLocation StartLoc, Module *Imported, SourceLocation EndLoc) { - ImportDecl *Import = new (C, DC, additionalSizeToAlloc(1)) + auto *Import = new (C, DC, additionalSizeToAlloc(1)) ImportDecl(DC, StartLoc, Imported, EndLoc); Import->setImplicit(); return Import; Index: lib/AST/DeclBase.cpp =================================================================== --- lib/AST/DeclBase.cpp +++ lib/AST/DeclBase.cpp @@ -80,7 +80,7 @@ // padding at the start if required. size_t ExtraAlign = llvm::OffsetToAlignment(sizeof(Module *), alignof(Decl)); - char *Buffer = reinterpret_cast( + auto *Buffer = reinterpret_cast( ::operator new(ExtraAlign + sizeof(Module *) + Size + Extra, Ctx)); Buffer += ExtraAlign; return new (Buffer) Module*(nullptr) + 1; @@ -122,7 +122,7 @@ // Marking a DecompositionDecl as invalid implies all the child BindingDecl's // are invalid too. - if (DecompositionDecl *DD = dyn_cast(this)) { + if (auto *DD = dyn_cast(this)) { for (BindingDecl *Binding : DD->bindings()) { Binding->setInvalidDecl(); } @@ -176,26 +176,24 @@ } bool Decl::isTemplateParameterPack() const { - if (const TemplateTypeParmDecl *TTP = dyn_cast(this)) + if (const auto *TTP = dyn_cast(this)) return TTP->isParameterPack(); - if (const NonTypeTemplateParmDecl *NTTP - = dyn_cast(this)) + if (const auto *NTTP = dyn_cast(this)) return NTTP->isParameterPack(); - if (const TemplateTemplateParmDecl *TTP - = dyn_cast(this)) + if (const auto *TTP = dyn_cast(this)) return TTP->isParameterPack(); return false; } bool Decl::isParameterPack() const { - if (const ParmVarDecl *Parm = dyn_cast(this)) + if (const auto *Parm = dyn_cast(this)) return Parm->isParameterPack(); return isTemplateParameterPack(); } FunctionDecl *Decl::getAsFunction() { - if (FunctionDecl *FD = dyn_cast(this)) + if (auto *FD = dyn_cast(this)) return FD; if (const FunctionTemplateDecl *FTD = dyn_cast(this)) return FTD->getTemplatedDecl(); @@ -244,7 +242,7 @@ OS << Message; - if (const NamedDecl *DN = dyn_cast_or_null(TheDecl)) { + if (const auto *DN = dyn_cast_or_null(TheDecl)) { OS << " '"; DN->printQualifiedName(OS); OS << '\''; @@ -280,7 +278,7 @@ if (SemaDC == LexicalDC) { DeclCtx = SemaDC; } else { - Decl::MultipleDC *MDC = new (Ctx) Decl::MultipleDC(); + auto *MDC = new (Ctx) Decl::MultipleDC(); MDC->SemanticDC = SemaDC; MDC->LexicalDC = LexicalDC; DeclCtx = MDC; @@ -302,7 +300,7 @@ bool Decl::isInAnonymousNamespace() const { const DeclContext *DC = getDeclContext(); do { - if (const NamespaceDecl *ND = dyn_cast(DC)) + if (const auto *ND = dyn_cast(DC)) if (ND->isAnonymousNamespace()) return true; } while ((DC = DC->getParent())); @@ -315,7 +313,7 @@ } TranslationUnitDecl *Decl::getTranslationUnitDecl() { - if (TranslationUnitDecl *TUD = dyn_cast(this)) + if (auto *TUD = dyn_cast(this)) return TUD; DeclContext *DC = getDeclContext(); @@ -408,9 +406,9 @@ } const Attr *Decl::getDefiningAttr() const { - if (AliasAttr *AA = getAttr()) + if (auto *AA = getAttr()) return AA; - if (IFuncAttr *IFA = getAttr()) + if (auto *IFA = getAttr()) return IFA; return nullptr; } @@ -571,7 +569,7 @@ IsDefinition = false; // Variables, if they aren't definitions. - if (const VarDecl *Var = dyn_cast(this)) { + if (const auto *Var = dyn_cast(this)) { if (Var->isThisDeclarationADefinition()) { IsDefinition = true; return false; @@ -579,7 +577,7 @@ return true; // Functions, if they aren't definitions. - } else if (const FunctionDecl *FD = dyn_cast(this)) { + } else if (const auto *FD = dyn_cast(this)) { if (FD->hasBody()) { IsDefinition = true; return false; @@ -794,7 +792,7 @@ SourceLocation Decl::getBodyRBrace() const { // Special handling of FunctionDecl to avoid de-serializing the body from PCH. // FunctionDecl stores EndRangeLoc for this purpose. - if (const FunctionDecl *FD = dyn_cast(this)) { + if (const auto *FD = dyn_cast(this)) { const FunctionDecl *Definition; if (FD->hasBody(Definition)) return Definition->getSourceRange().getEnd(); @@ -842,9 +840,9 @@ const FunctionType *Decl::getFunctionType(bool BlocksToo) const { QualType Ty; - if (const ValueDecl *D = dyn_cast(this)) + if (const auto *D = dyn_cast(this)) Ty = D->getType(); - else if (const TypedefNameDecl *D = dyn_cast(this)) + else if (const auto *D = dyn_cast(this)) Ty = D->getUnderlyingType(); else return nullptr; @@ -862,18 +860,18 @@ /// code context that is not a closure (a lambda, block, etc.). template static Decl *getNonClosureContext(T *D) { if (getKind(D) == Decl::CXXMethod) { - CXXMethodDecl *MD = cast(D); + auto *MD = cast(D); if (MD->getOverloadedOperator() == OO_Call && MD->getParent()->isLambda()) return getNonClosureContext(MD->getParent()->getParent()); return MD; - } else if (FunctionDecl *FD = dyn_cast(D)) { + } else if (auto *FD = dyn_cast(D)) { return FD; - } else if (ObjCMethodDecl *MD = dyn_cast(D)) { + } else if (auto *MD = dyn_cast(D)) { return MD; - } else if (BlockDecl *BD = dyn_cast(D)) { + } else if (auto *BD = dyn_cast(D)) { return getNonClosureContext(BD->getParent()); - } else if (CapturedDecl *CD = dyn_cast(D)) { + } else if (auto *CD = dyn_cast(D)) { return getNonClosureContext(CD->getParent()); } else { return nullptr; @@ -937,7 +935,7 @@ if (!isNamespace()) return false; - const NamespaceDecl *ND = cast(this); + const auto *ND = cast(this); if (ND->isInline()) { return ND->getParent()->isStdNamespace(); } @@ -956,15 +954,15 @@ if (isa(this)) return true; - if (const CXXRecordDecl *Record = dyn_cast(this)) { + if (const auto *Record = dyn_cast(this)) { if (Record->getDescribedClassTemplate()) return true; if (Record->isDependentLambda()) return true; } - - if (const FunctionDecl *Function = dyn_cast(this)) { + + if (const auto *Function = dyn_cast(this)) { if (Function->getDescribedFunctionTemplate()) return true; @@ -1072,12 +1070,12 @@ if (DeclKind >= Decl::firstTag && DeclKind <= Decl::lastTag) { // If this is a tag type that has a definition or is currently // being defined, that definition is our primary context. - TagDecl *Tag = cast(this); + auto *Tag = cast(this); if (TagDecl *Def = Tag->getDefinition()) return Def; - if (const TagType *TagTy = dyn_cast(Tag->getTypeForDecl())) { + if (const auto *TagTy = dyn_cast(Tag->getTypeForDecl())) { // Note, TagType::getDecl returns the (partial) definition one exists. TagDecl *PossiblePartialDef = TagTy->getDecl(); if (PossiblePartialDef->isBeingDefined()) @@ -1103,8 +1101,8 @@ Contexts.push_back(this); return; } - - NamespaceDecl *Self = static_cast(this); + + auto *Self = static_cast(this); for (NamespaceDecl *N = Self->getMostRecentDecl(); N; N = N->getPreviousDecl()) Contexts.push_back(N); @@ -1167,7 +1165,7 @@ // We may have already loaded just the fields of this record, in which case // we need to ignore them. bool FieldsAlreadyLoaded = false; - if (const RecordDecl *RD = dyn_cast(this)) + if (const auto *RD = dyn_cast(this)) FieldsAlreadyLoaded = RD->LoadedFieldsFromExternalStorage; // Splice the newly-read declarations into the beginning of the list @@ -1292,7 +1290,7 @@ // Remove D from the lookup table if necessary. if (isa(D)) { - NamedDecl *ND = cast(D); + auto *ND = cast(D); // Remove only decls that have a name if (!ND->getDeclName()) return; @@ -1325,13 +1323,13 @@ // Notify a C++ record declaration that we've added a member, so it can // update its class-specific state. - if (CXXRecordDecl *Record = dyn_cast(this)) + if (auto *Record = dyn_cast(this)) Record->addedMember(D); // If this is a newly-created (not de-serialized) import declaration, wire // it in to the list of local import declarations. if (!D->isFromASTFile()) { - if (ImportDecl *Import = dyn_cast(D)) + if (auto *Import = dyn_cast(D)) D->getASTContext().addedLocalImportDecl(Import); } } @@ -1339,7 +1337,7 @@ void DeclContext::addDecl(Decl *D) { addHiddenDecl(D); - if (NamedDecl *ND = dyn_cast(D)) + if (auto *ND = dyn_cast(D)) ND->getDeclContext()->getPrimaryContext()-> makeDeclVisibleInContextWithFlags(ND, false, true); } @@ -1347,7 +1345,7 @@ void DeclContext::addDeclInternal(Decl *D) { addHiddenDecl(D); - if (NamedDecl *ND = dyn_cast(D)) + if (auto *ND = dyn_cast(D)) ND->getDeclContext()->getPrimaryContext()-> makeDeclVisibleInContextWithFlags(ND, true, true); } @@ -1371,7 +1369,7 @@ // from being visible? if (isa(D)) return true; - if (FunctionDecl *FD = dyn_cast(D)) + if (auto *FD = dyn_cast(D)) if (FD->isFunctionTemplateSpecialization()) return true; @@ -1428,7 +1426,7 @@ // FindExternalVisibleDeclsByName if needed. Exception: if we're not // in C++, we do not track external visible decls for the TU, so in // that case we need to collect them all here. - if (NamedDecl *ND = dyn_cast(D)) + if (auto *ND = dyn_cast(D)) if (ND->getDeclContext() == DCtx && !shouldBeHidden(ND) && (!ND->isFromASTFile() || (isTranslationUnit() && @@ -1438,7 +1436,7 @@ // If this declaration is itself a transparent declaration context // or inline namespace, add the members of this declaration of that // context (recursively). - if (DeclContext *InnerCtx = dyn_cast(D)) + if (auto *InnerCtx = dyn_cast(D)) if (InnerCtx->isTransparentContext() || InnerCtx->isInlineNamespace()) buildLookupImpl(InnerCtx, Internal); } @@ -1568,7 +1566,7 @@ // FIXME: If we have lazy external declarations, this will not find them! // FIXME: Should we CollectAllContexts and walk them all here? for (Decl *D = FirstDecl; D; D = D->getNextDeclInContext()) { - if (NamedDecl *ND = dyn_cast(D)) + if (auto *ND = dyn_cast(D)) if (ND->getDeclName() == Name) Results.push_back(ND); } @@ -1610,7 +1608,7 @@ if (O->Equals(this)) return true; - const NamespaceDecl *NS = dyn_cast(O); + const auto *NS = dyn_cast(O); if (!NS || !NS->isInline()) break; O = NS->getParent(); @@ -1669,7 +1667,7 @@ getParent()->getPrimaryContext()-> makeDeclVisibleInContextWithFlags(D, Internal, Recoverable); - Decl *DCAsDecl = cast(this); + auto *DCAsDecl = cast(this); // Notify that a decl was made visible unless we are a Tag being defined. if (!(isa(DCAsDecl) && cast(DCAsDecl)->isBeingDefined())) if (ASTMutationListener *L = DCAsDecl->getASTMutationListener()) @@ -1787,16 +1785,15 @@ if (!Parent->LookupPtr) Parent->CreateStoredDeclsMap(C); - DependentStoredDeclsMap *Map = - static_cast(Parent->LookupPtr); + auto *Map = static_cast(Parent->LookupPtr); // Allocate the copy of the PartialDiagnostic via the ASTContext's // BumpPtrAllocator, rather than the ASTContext itself. PartialDiagnostic::Storage *DiagStorage = nullptr; if (PDiag.hasStorage()) DiagStorage = new (C) PartialDiagnostic::Storage; - - DependentDiagnostic *DD = new (C) DependentDiagnostic(PDiag, DiagStorage); + + auto *DD = new (C) DependentDiagnostic(PDiag, DiagStorage); // TODO: Maybe we shouldn't reverse the order during insertion. DD->NextDiagnostic = Map->FirstDiagnostic; Index: lib/AST/DeclCXX.cpp =================================================================== --- lib/AST/DeclCXX.cpp +++ lib/AST/DeclCXX.cpp @@ -96,8 +96,8 @@ SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl* PrevDecl, bool DelayTypeCreation) { - CXXRecordDecl *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc, - IdLoc, Id, PrevDecl); + auto *R = new (C, DC) + CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl); R->MayHaveOutOfDateDef = C.getLangOpts().Modules; // FIXME: DelayTypeCreation seems like such a hack @@ -111,9 +111,8 @@ TypeSourceInfo *Info, SourceLocation Loc, bool Dependent, bool IsGeneric, LambdaCaptureDefault CaptureDefault) { - CXXRecordDecl *R = - new (C, DC) CXXRecordDecl(CXXRecord, TTK_Class, C, DC, Loc, Loc, - nullptr, nullptr); + auto *R = new (C, DC) + CXXRecordDecl(CXXRecord, TTK_Class, C, DC, Loc, Loc, nullptr, nullptr); R->IsBeingDefined = true; R->DefinitionData = new (C) struct LambdaDefinitionData(R, Info, Dependent, IsGeneric, @@ -169,8 +168,8 @@ // Skip dependent types; we can't do any checking on them now. if (BaseType->isDependentType()) continue; - CXXRecordDecl *BaseClassDecl - = cast(BaseType->getAs()->getDecl()); + auto *BaseClassDecl = + cast(BaseType->getAs()->getDecl()); if (!BaseClassDecl->isEmpty()) { if (!data().Empty) { @@ -444,8 +443,8 @@ // Ignore friends and invalid declarations. if (D->getFriendObjectKind() || D->isInvalidDecl()) return; - - FunctionTemplateDecl *FunTmpl = dyn_cast(D); + + auto *FunTmpl = dyn_cast(D); if (FunTmpl) D = FunTmpl->getTemplatedDecl(); @@ -453,12 +452,11 @@ Decl *DUnderlying = D; if (auto *ND = dyn_cast(DUnderlying)) { DUnderlying = ND->getUnderlyingDecl(); - if (FunctionTemplateDecl *UnderlyingFunTmpl = - dyn_cast(DUnderlying)) + if (auto *UnderlyingFunTmpl = dyn_cast(DUnderlying)) DUnderlying = UnderlyingFunTmpl->getTemplatedDecl(); } - - if (CXXMethodDecl *Method = dyn_cast(D)) { + + if (auto *Method = dyn_cast(D)) { if (Method->isVirtual()) { // C++ [dcl.init.aggr]p1: // An aggregate is an array or a class with [...] no virtual functions. @@ -500,7 +498,7 @@ unsigned SMKind = 0; // Handle constructors. - if (CXXConstructorDecl *Constructor = dyn_cast(D)) { + if (auto *Constructor = dyn_cast(D)) { if (!Constructor->isImplicit()) { // Note that we have a user-declared constructor. data().UserDeclaredConstructor = true; @@ -547,8 +545,7 @@ } // Handle constructors, including those inherited from base classes. - if (CXXConstructorDecl *Constructor = - dyn_cast(DUnderlying)) { + if (auto *Constructor = dyn_cast(DUnderlying)) { // Record if we see any constexpr constructors which are neither copy // nor move constructors. // C++1z [basic.types]p10: @@ -560,7 +557,7 @@ } // Handle destructors. - if (CXXDestructorDecl *DD = dyn_cast(D)) { + if (auto *DD = dyn_cast(D)) { SMKind |= SMF_Destructor; if (DD->isUserProvided()) @@ -576,12 +573,12 @@ } // Handle member functions. - if (CXXMethodDecl *Method = dyn_cast(D)) { + if (auto *Method = dyn_cast(D)) { if (Method->isCopyAssignmentOperator()) { SMKind |= SMF_CopyAssignment; - const ReferenceType *ParamTy = - Method->getParamDecl(0)->getType()->getAs(); + const auto *ParamTy = + Method->getParamDecl(0)->getType()->getAs(); if (!ParamTy || ParamTy->getPointeeType().isConstQualified()) data().HasDeclaredCopyAssignmentWithConstParam = true; } @@ -590,7 +587,7 @@ SMKind |= SMF_MoveAssignment; // Keep the list of conversion functions up-to-date. - if (CXXConversionDecl *Conversion = dyn_cast(D)) { + if (auto *Conversion = dyn_cast(D)) { // FIXME: We use the 'unsafe' accessor for the access specifier here, // because Sema may not have set it yet. That's really just a misdesign // in Sema. However, LLDB *will* have set the access specifier correctly, @@ -655,7 +652,7 @@ } // Handle non-static data members. - if (FieldDecl *Field = dyn_cast(D)) { + if (auto *Field = dyn_cast(D)) { // C++ [class.bit]p2: // A declaration for a bit-field that omits the identifier declares an // unnamed bit-field. Unnamed bit-fields are not members and cannot be @@ -779,7 +776,7 @@ data().DefaultedMoveAssignmentIsDeleted = true; if (const RecordType *RecordTy = T->getAs()) { - CXXRecordDecl* FieldRec = cast(RecordTy->getDecl()); + auto *FieldRec = cast(RecordTy->getDecl()); if (FieldRec->getDefinition()) { addedClassSubobject(FieldRec); @@ -976,7 +973,7 @@ } // Handle using declarations of conversion functions. - if (UsingShadowDecl *Shadow = dyn_cast(D)) { + if (auto *Shadow = dyn_cast(D)) { if (Shadow->getDeclName().getNameKind() == DeclarationName::CXXConversionFunctionName) { ASTContext &Ctx = getASTContext(); @@ -984,7 +981,7 @@ } } - if (UsingDecl *Using = dyn_cast(D)) { + if (auto *Using = dyn_cast(D)) { if (Using->getDeclName().getNameKind() == DeclarationName::CXXConstructorName) { data().HasInheritedConstructor = true; @@ -1004,7 +1001,7 @@ // The kind of special member this declaration is, if any. unsigned SMKind = 0; - if (CXXConstructorDecl *Constructor = dyn_cast(D)) { + if (auto *Constructor = dyn_cast(D)) { if (Constructor->isDefaultConstructor()) { SMKind |= SMF_DefaultConstructor; if (Constructor->isConstexpr()) @@ -1059,8 +1056,7 @@ assert(Calls.size() == 1 && "More than one lambda call operator!"); NamedDecl *CallOp = Calls.front(); - if (FunctionTemplateDecl *CallOpTmpl = - dyn_cast(CallOp)) + if (auto *CallOpTmpl = dyn_cast(CallOp)) return cast(CallOpTmpl->getTemplatedDecl()); return cast(CallOp); @@ -1074,8 +1070,7 @@ if (Invoker.empty()) return nullptr; assert(Invoker.size() == 1 && "More than one static invoker operator!"); NamedDecl *InvokerFun = Invoker.front(); - if (FunctionTemplateDecl *InvokerTemplate = - dyn_cast(InvokerFun)) + if (auto *InvokerTemplate = dyn_cast(InvokerFun)) return cast(InvokerTemplate->getTemplatedDecl()); return cast(InvokerFun); @@ -1188,7 +1183,7 @@ = CXXRecordDecl::MergeAccess(Access, I.getAccessSpecifier()); bool BaseInVirtual = InVirtual || I.isVirtual(); - CXXRecordDecl *Base = cast(RT->getDecl()); + auto *Base = cast(RT->getDecl()); CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess, *HiddenTypes, Output, VOutput, HiddenVBaseCs); } @@ -1315,8 +1310,7 @@ } TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{ - if (const ClassTemplateSpecializationDecl *Spec - = dyn_cast(this)) + if (const auto *Spec = dyn_cast(this)) return Spec->getSpecializationKind(); if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) @@ -1327,8 +1321,7 @@ void CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) { - if (ClassTemplateSpecializationDecl *Spec - = dyn_cast(this)) { + if (auto *Spec = dyn_cast(this)) { Spec->setSpecializationKind(TSK); return; } @@ -1391,7 +1384,7 @@ if (R.empty()) return nullptr; - CXXDestructorDecl *Dtor = cast(R.front()); + auto *Dtor = cast(R.front()); return Dtor; } @@ -1434,11 +1427,9 @@ } bool Done = false; - for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(), - MEnd = FinalOverriders->end(); + for (auto M = FinalOverriders->begin(), MEnd = FinalOverriders->end(); M != MEnd && !Done; ++M) { - for (OverridingMethods::iterator SO = M->second.begin(), - SOEnd = M->second.end(); + for (auto SO = M->second.begin(), SOEnd = M->second.end(); SO != SOEnd && !Done; ++SO) { assert(SO->second.size() > 0 && "All virtual functions have overridding virtual functions"); @@ -1468,8 +1459,8 @@ return false; for (const auto &B : bases()) { - CXXRecordDecl *BaseDecl - = cast(B.getType()->getAs()->getDecl()); + auto *BaseDecl = + cast(B.getType()->getAs()->getDecl()); if (BaseDecl->isAbstract()) return true; } @@ -1521,7 +1512,7 @@ } for (auto *ND : RD->lookup(getDeclName())) { - CXXMethodDecl *MD = dyn_cast(ND); + auto *MD = dyn_cast(ND); if (!MD) continue; if (recursivelyOverrides(MD, this)) @@ -1633,7 +1624,7 @@ return false; QualType ParamType = getParamDecl(0)->getType(); - if (const LValueReferenceType *Ref = ParamType->getAs()) + if (const auto *Ref = ParamType->getAs()) ParamType = Ref->getPointeeType(); ASTContext &Context = getASTContext(); @@ -1796,7 +1787,7 @@ if (isAnyMemberInitializer()) return getMemberLocation(); - if (TypeSourceInfo *TSInfo = Initializee.get()) + if (auto *TSInfo = Initializee.get()) return TSInfo->getTypeLoc().getLocalSourceRange().getBegin(); return SourceLocation(); @@ -1851,7 +1842,7 @@ CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const { assert(isDelegatingConstructor() && "Not a delegating constructor!"); Expr *E = (*init_begin())->getInit()->IgnoreImplicit(); - if (CXXConstructExpr *Construct = dyn_cast(E)) + if (auto *Construct = dyn_cast(E)) return Construct->getConstructor(); return nullptr; @@ -1896,8 +1887,8 @@ const ParmVarDecl *Param = getParamDecl(0); - // Do we have a reference type? - const ReferenceType *ParamRefType = Param->getType()->getAs(); + // Do we have a reference type? + const auto *ParamRefType = Param->getType()->getAs(); if (!ParamRefType) return false; @@ -2043,7 +2034,7 @@ SourceLocation IdentLoc, NamedDecl *Used, DeclContext *CommonAncestor) { - if (NamespaceDecl *NS = dyn_cast_or_null(Used)) + if (auto *NS = dyn_cast_or_null(Used)) Used = NS->getOriginalNamespace(); return new (C, DC) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc, IdentLoc, Used, CommonAncestor); @@ -2058,8 +2049,7 @@ } NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { - if (NamespaceAliasDecl *NA = - dyn_cast_or_null(NominatedNamespace)) + if (auto *NA = dyn_cast_or_null(NominatedNamespace)) return NA->getNamespace(); return cast_or_null(NominatedNamespace); } @@ -2135,7 +2125,7 @@ SourceLocation IdentLoc, NamedDecl *Namespace) { // FIXME: Preserve the aliased namespace as written. - if (NamespaceDecl *NS = dyn_cast_or_null(Namespace)) + if (auto *NS = dyn_cast_or_null(Namespace)) Namespace = NS->getOriginalNamespace(); return new (C, DC) NamespaceAliasDecl(C, DC, UsingLoc, AliasLoc, Alias, QualifierLoc, IdentLoc, Namespace); Index: lib/AST/DeclFriend.cpp =================================================================== --- lib/AST/DeclFriend.cpp +++ lib/AST/DeclFriend.cpp @@ -31,7 +31,7 @@ ArrayRef FriendTypeTPLists) { #ifndef NDEBUG if (Friend.is()) { - NamedDecl *D = Friend.get(); + auto *D = Friend.get(); assert(isa(D) || isa(D) || isa(D) || @@ -49,8 +49,8 @@ std::size_t Extra = FriendDecl::additionalSizeToAlloc( FriendTypeTPLists.size()); - FriendDecl *FD = new (C, DC, Extra) FriendDecl(DC, L, Friend, FriendL, - FriendTypeTPLists); + auto *FD = + new (C, DC, Extra) FriendDecl(DC, L, Friend, FriendL, FriendTypeTPLists); cast(DC)->pushFriendDecl(FD); return FD; } Index: lib/AST/DeclObjC.cpp =================================================================== --- lib/AST/DeclObjC.cpp +++ lib/AST/DeclObjC.cpp @@ -57,7 +57,7 @@ lookup_result R = lookup(Id); for (lookup_iterator Ivar = R.begin(), IvarEnd = R.end(); Ivar != IvarEnd; ++Ivar) { - if (ObjCIvarDecl *ivar = dyn_cast(*Ivar)) + if (auto *ivar = dyn_cast(*Ivar)) return ivar; } return nullptr; @@ -69,7 +69,7 @@ bool AllowHidden) const { // If this context is a hidden protocol definition, don't find any // methods there. - if (const ObjCProtocolDecl *Proto = dyn_cast(this)) { + if (const auto *Proto = dyn_cast(this)) { if (const ObjCProtocolDecl *Def = Proto->getDefinition()) if (Def->isHidden() && !AllowHidden) return nullptr; @@ -86,7 +86,7 @@ lookup_result R = lookup(Sel); for (lookup_iterator Meth = R.begin(), MethEnd = R.end(); Meth != MethEnd; ++Meth) { - ObjCMethodDecl *MD = dyn_cast(*Meth); + auto *MD = dyn_cast(*Meth); if (MD && MD->isInstanceMethod() == isInstance) return MD; } @@ -104,12 +104,12 @@ lookup_result R = lookup(Sel); for (lookup_iterator Meth = R.begin(), MethEnd = R.end(); Meth != MethEnd; ++Meth) { - ObjCMethodDecl *MD = dyn_cast(*Meth); + auto *MD = dyn_cast(*Meth); if (MD && MD->isInstanceMethod() && !MD->isImplicit()) return true; } - if (const ObjCInterfaceDecl *ID = dyn_cast(this)) { + if (const auto *ID = dyn_cast(this)) { // Also look into categories, including class extensions, looking // for a user declared instance method. for (const auto *Cat : ID->visible_categories()) { @@ -143,7 +143,7 @@ OSC = OSC->getSuperClass(); } } - if (const ObjCProtocolDecl *PD = dyn_cast(this)) + if (const auto *PD = dyn_cast(this)) for (const auto *PI : PD->protocols()) if (PI->HasUserDeclaredSetterMethod(Property)) return true; @@ -156,7 +156,7 @@ ObjCPropertyQueryKind queryKind) { // If this context is a hidden protocol definition, don't find any // property. - if (const ObjCProtocolDecl *Proto = dyn_cast(DC)) { + if (const auto *Proto = dyn_cast(DC)) { if (const ObjCProtocolDecl *Def = Proto->getDefinition()) if (Def->isHidden()) return nullptr; @@ -176,7 +176,7 @@ ObjCPropertyDecl *classProp = nullptr; for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; ++I) - if (ObjCPropertyDecl *PD = dyn_cast(*I)) { + if (auto *PD = dyn_cast(*I)) { // If queryKind is unknown, we return the instance property if one // exists; otherwise we return the class property. if ((queryKind == ObjCPropertyQueryKind::OBJC_PR_query_unknown && @@ -214,7 +214,7 @@ const IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const { // Don't find properties within hidden protocol definitions. - if (const ObjCProtocolDecl *Proto = dyn_cast(this)) { + if (const auto *Proto = dyn_cast(this)) { if (const ObjCProtocolDecl *Def = Proto->getDefinition()) if (Def->isHidden()) return nullptr; @@ -238,7 +238,7 @@ default: break; case Decl::ObjCProtocol: { - const ObjCProtocolDecl *PID = cast(this); + const auto *PID = cast(this); for (const auto *I : PID->protocols()) if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId, QueryKind)) @@ -246,7 +246,7 @@ break; } case Decl::ObjCInterface: { - const ObjCInterfaceDecl *OID = cast(this); + const auto *OID = cast(this); // Look through categories (but not extensions; they were handled above). for (const auto *Cat : OID->visible_categories()) { if (!Cat->IsClassExtension()) @@ -267,7 +267,7 @@ break; } case Decl::ObjCCategory: { - const ObjCCategoryDecl *OCD = cast(this); + const auto *OCD = cast(this); // Look through protocols. if (!OCD->IsClassExtension()) for (const auto *I : OCD->protocols()) @@ -843,27 +843,25 @@ if (Redecl) return Redecl; - Decl *CtxD = cast(getDeclContext()); + auto *CtxD = cast(getDeclContext()); if (!CtxD->isInvalidDecl()) { - if (ObjCInterfaceDecl *IFD = dyn_cast(CtxD)) { + if (auto *IFD = dyn_cast(CtxD)) { if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD)) if (!ImplD->isInvalidDecl()) Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); - } else if (ObjCCategoryDecl *CD = dyn_cast(CtxD)) { + } else if (auto *CD = dyn_cast(CtxD)) { if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD)) if (!ImplD->isInvalidDecl()) Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); - } else if (ObjCImplementationDecl *ImplD = - dyn_cast(CtxD)) { + } else if (auto *ImplD = dyn_cast(CtxD)) { if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) if (!IFD->isInvalidDecl()) Redecl = IFD->getMethod(getSelector(), isInstanceMethod()); - } else if (ObjCCategoryImplDecl *CImplD = - dyn_cast(CtxD)) { + } else if (auto *CImplD = dyn_cast(CtxD)) { if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) if (!CatD->isInvalidDecl()) Redecl = CatD->getMethod(getSelector(), isInstanceMethod()); @@ -886,16 +884,15 @@ } ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() { - Decl *CtxD = cast(getDeclContext()); + auto *CtxD = cast(getDeclContext()); - if (ObjCImplementationDecl *ImplD = dyn_cast(CtxD)) { + if (auto *ImplD = dyn_cast(CtxD)) { if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(), isInstanceMethod())) return MD; - } else if (ObjCCategoryImplDecl *CImplD = - dyn_cast(CtxD)) { + } else if (auto *CImplD = dyn_cast(CtxD)) { if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(), isInstanceMethod())) @@ -920,7 +917,7 @@ } ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const { - ObjCMethodFamily family = static_cast(Family); + auto family = static_cast(Family); if (family != static_cast(InvalidObjCMethodFamily)) return family; @@ -1078,11 +1075,11 @@ } ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() { - if (ObjCInterfaceDecl *ID = dyn_cast(getDeclContext())) + if (auto *ID = dyn_cast(getDeclContext())) return ID; - if (ObjCCategoryDecl *CD = dyn_cast(getDeclContext())) + if (auto *CD = dyn_cast(getDeclContext())) return CD->getClassInterface(); - if (ObjCImplDecl *IMD = dyn_cast(getDeclContext())) + if (auto *IMD = dyn_cast(getDeclContext())) return IMD->getClassInterface(); if (isa(getDeclContext())) return nullptr; @@ -1120,8 +1117,7 @@ // In categories look for overriden methods from protocols. A method from // category is not "overriden" since it is considered as the "same" method // (same USR) as the one from the interface. - if (const ObjCCategoryDecl * - Category = dyn_cast(Container)) { + if (const auto *Category = dyn_cast(Container)) { // Check whether we have a matching method at this category but only if we // are at the super class level. if (MovedToSuper) @@ -1153,13 +1149,12 @@ return; } - if (const ObjCProtocolDecl *Protocol = dyn_cast(Container)){ + if (const auto *Protocol = dyn_cast(Container)) { for (const auto *P : Protocol->protocols()) CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper); } - if (const ObjCInterfaceDecl * - Interface = dyn_cast(Container)) { + if (const auto *Interface = dyn_cast(Container)) { for (const auto *P : Interface->protocols()) CollectOverriddenMethodsRecurse(P, Method, Methods, MovedToSuper); @@ -1183,12 +1178,12 @@ SmallVectorImpl &overridden) { assert(Method->isOverriding()); - if (const ObjCProtocolDecl * - ProtD = dyn_cast(Method->getDeclContext())) { + if (const auto *ProtD = + dyn_cast(Method->getDeclContext())) { CollectOverriddenMethods(ProtD, Method, overridden); - } else if (const ObjCImplDecl * - IMD = dyn_cast(Method->getDeclContext())) { + } else if (const auto *IMD = + dyn_cast(Method->getDeclContext())) { const ObjCInterfaceDecl *ID = IMD->getClassInterface(); if (!ID) return; @@ -1200,8 +1195,8 @@ Method = IFaceMeth; CollectOverriddenMethods(ID, Method, overridden); - } else if (const ObjCCategoryDecl * - CatD = dyn_cast(Method->getDeclContext())) { + } else if (const auto *CatD = + dyn_cast(Method->getDeclContext())) { const ObjCInterfaceDecl *ID = CatD->getClassInterface(); if (!ID) return; @@ -1244,7 +1239,7 @@ return nullptr; if (isPropertyAccessor()) { - const ObjCContainerDecl *Container = cast(getParent()); + const auto *Container = cast(getParent()); bool IsGetter = (NumArgs == 0); bool IsInstance = isInstanceMethod(); @@ -1402,9 +1397,8 @@ ObjCInterfaceDecl *PrevDecl, SourceLocation ClassLoc, bool isInternal){ - ObjCInterfaceDecl *Result = new (C, DC) - ObjCInterfaceDecl(C, DC, atLoc, Id, typeParamList, ClassLoc, PrevDecl, - isInternal); + auto *Result = new (C, DC) ObjCInterfaceDecl(C, DC, atLoc, Id, typeParamList, + ClassLoc, PrevDecl, isInternal); Result->Data.setInt(!C.getLangOpts().Modules); C.getObjCInterfaceType(Result, PrevDecl); return Result; @@ -1476,7 +1470,7 @@ StringRef ObjCInterfaceDecl::getObjCRuntimeNameAsString() const { - if (ObjCRuntimeNameAttr *ObjCRTName = getAttr()) + if (auto *ObjCRTName = getAttr()) return ObjCRTName->getMetadataName(); return getName(); @@ -1709,9 +1703,9 @@ "Invalid ivar decl context!"); // Once a new ivar is created in any of class/class-extension/implementation // decl contexts, the previously built IvarList must be rebuilt. - ObjCInterfaceDecl *ID = dyn_cast(DC); + auto *ID = dyn_cast(DC); if (!ID) { - if (ObjCImplementationDecl *IM = dyn_cast(DC)) + if (auto *IM = dyn_cast(DC)) ID = IM->getClassInterface(); else ID = cast(DC)->getClassInterface(); @@ -1730,7 +1724,7 @@ } const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const { - const ObjCContainerDecl *DC = cast(getDeclContext()); + const auto *DC = cast(getDeclContext()); switch (DC->getKind()) { default: @@ -1740,7 +1734,7 @@ // Ivars can only appear in class extension categories. case ObjCCategory: { - const ObjCCategoryDecl *CD = cast(DC); + const auto *CD = cast(DC); assert(CD->IsClassExtension() && "invalid container for ivar!"); return CD->getClassInterface(); } @@ -1800,7 +1794,7 @@ SourceLocation nameLoc, SourceLocation atStartLoc, ObjCProtocolDecl *PrevDecl) { - ObjCProtocolDecl *Result = + auto *Result = new (C, DC) ObjCProtocolDecl(C, DC, Id, nameLoc, atStartLoc, PrevDecl); Result->Data.setInt(!C.getLangOpts().Modules); return Result; @@ -1904,7 +1898,7 @@ StringRef ObjCProtocolDecl::getObjCRuntimeNameAsString() const { - if (ObjCRuntimeNameAttr *ObjCRTName = getAttr()) + if (auto *ObjCRTName = getAttr()) return ObjCRTName->getMetadataName(); return getName(); @@ -1940,10 +1934,9 @@ ObjCTypeParamList *typeParamList, SourceLocation IvarLBraceLoc, SourceLocation IvarRBraceLoc) { - ObjCCategoryDecl *CatDecl = - new (C, DC) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id, - IDecl, typeParamList, IvarLBraceLoc, - IvarRBraceLoc); + auto *CatDecl = new (C, DC) + ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id, IDecl, + typeParamList, IvarLBraceLoc, IvarRBraceLoc); if (IDecl) { // Link this category into its class's category list. CatDecl->NextClassCategory = IDecl->getCategoryListRaw(); @@ -2028,13 +2021,11 @@ void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) { ASTContext &Ctx = getASTContext(); - if (ObjCImplementationDecl *ImplD - = dyn_cast_or_null(this)) { + if (auto *ImplD = dyn_cast_or_null(this)) { if (IFace) Ctx.setObjCImplementation(IFace, ImplD); - } else if (ObjCCategoryImplDecl *ImplD = - dyn_cast_or_null(this)) { + } else if (auto *ImplD = dyn_cast_or_null(this)) { if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier())) Ctx.setObjCImplementation(CD, ImplD); } @@ -2125,8 +2116,7 @@ unsigned numInitializers) { if (numInitializers > 0) { NumIvarInitializers = numInitializers; - CXXCtorInitializer **ivarInitializers = - new (C) CXXCtorInitializer*[NumIvarInitializers]; + auto **ivarInitializers = new (C) CXXCtorInitializer *[NumIvarInitializers]; memcpy(ivarInitializers, initializers, numInitializers * sizeof(CXXCtorInitializer*)); IvarInitializers = ivarInitializers; Index: lib/AST/DeclOpenMP.cpp =================================================================== --- lib/AST/DeclOpenMP.cpp +++ lib/AST/DeclOpenMP.cpp @@ -30,9 +30,8 @@ DeclContext *DC, SourceLocation L, ArrayRef VL) { - OMPThreadPrivateDecl *D = - new (C, DC, additionalSizeToAlloc(VL.size())) - OMPThreadPrivateDecl(OMPThreadPrivate, DC, L); + auto *D = new (C, DC, additionalSizeToAlloc(VL.size())) + OMPThreadPrivateDecl(OMPThreadPrivate, DC, L); D->NumVars = VL.size(); D->setVars(VL); return D; Index: lib/AST/DeclPrinter.cpp =================================================================== --- lib/AST/DeclPrinter.cpp +++ lib/AST/DeclPrinter.cpp @@ -125,19 +125,19 @@ while (!BaseType->isSpecifierType()) { if (isa(BaseType)) break; - else if (const PointerType* PTy = BaseType->getAs()) + else if (const auto *PTy = BaseType->getAs()) BaseType = PTy->getPointeeType(); - else if (const BlockPointerType *BPy = BaseType->getAs()) + else if (const auto *BPy = BaseType->getAs()) BaseType = BPy->getPointeeType(); - else if (const ArrayType* ATy = dyn_cast(BaseType)) + else if (const auto *ATy = dyn_cast(BaseType)) BaseType = ATy->getElementType(); - else if (const FunctionType* FTy = BaseType->getAs()) + else if (const auto *FTy = BaseType->getAs()) BaseType = FTy->getReturnType(); - else if (const VectorType *VTy = BaseType->getAs()) + else if (const auto *VTy = BaseType->getAs()) BaseType = VTy->getElementType(); - else if (const ReferenceType *RTy = BaseType->getAs()) + else if (const auto *RTy = BaseType->getAs()) BaseType = RTy->getPointeeType(); - else if (const AutoType *ATy = BaseType->getAs()) + else if (const auto *ATy = BaseType->getAs()) BaseType = ATy->getDeducedType(); else llvm_unreachable("Unknown declarator!"); @@ -146,9 +146,9 @@ } static QualType getDeclType(Decl* D) { - if (TypedefNameDecl* TDD = dyn_cast(D)) + if (auto *TDD = dyn_cast(D)) return TDD->getUnderlyingType(); - if (ValueDecl* VD = dyn_cast(D)) + if (auto *VD = dyn_cast(D)) return VD->getType(); return QualType(); } @@ -162,7 +162,7 @@ } Decl** End = Begin + NumDecls; - TagDecl* TD = dyn_cast(*Begin); + auto *TD = dyn_cast(*Begin); if (TD) ++Begin; @@ -478,8 +478,8 @@ if (D->isFunctionTemplateSpecialization()) Out << "template<> "; - CXXConstructorDecl *CDecl = dyn_cast(D); - CXXConversionDecl *ConversionDecl = dyn_cast(D); + auto *CDecl = dyn_cast(D); + auto *ConversionDecl = dyn_cast(D); if (!Policy.SuppressSpecifiers) { switch (D->getStorageClass()) { case SC_None: break; @@ -509,12 +509,12 @@ } QualType Ty = D->getType(); - while (const ParenType *PT = dyn_cast(Ty)) { + while (const auto *PT = dyn_cast(Ty)) { Proto = '(' + Proto + ')'; Ty = PT->getInnerType(); } - if (const FunctionType *AFT = Ty->getAs()) { + if (const auto *AFT = Ty->getAs()) { const FunctionProtoType *FT = nullptr; if (D->hasWrittenPrototype()) FT = dyn_cast(AFT); @@ -613,7 +613,7 @@ // Nothing to print } else { Expr *Init = BMInitializer->getInit(); - if (ExprWithCleanups *Tmp = dyn_cast(Init)) + if (auto *Tmp = dyn_cast(Init)) Init = Tmp->getSubExpr(); Init = Init->IgnoreParens(); @@ -621,11 +621,10 @@ Expr *SimpleInit = nullptr; Expr **Args = nullptr; unsigned NumArgs = 0; - if (ParenListExpr *ParenList = dyn_cast(Init)) { + if (auto *ParenList = dyn_cast(Init)) { Args = ParenList->getExprs(); NumArgs = ParenList->getNumExprs(); - } else if (CXXConstructExpr *Construct - = dyn_cast(Init)) { + } else if (auto *Construct = dyn_cast(Init)) { Args = Construct->getArgs(); NumArgs = Construct->getNumArgs(); } else @@ -703,19 +702,13 @@ printTemplateParameters(D->getFriendTypeTemplateParameterList(i)); Out << "friend "; Out << " " << TSI->getType().getAsString(Policy); - } - else if (FunctionDecl *FD = - dyn_cast(D->getFriendDecl())) { + } else if (auto *FD = dyn_cast(D->getFriendDecl())) { Out << "friend "; VisitFunctionDecl(FD); - } - else if (FunctionTemplateDecl *FTD = - dyn_cast(D->getFriendDecl())) { + } else if (auto *FTD = dyn_cast(D->getFriendDecl())) { Out << "friend "; VisitFunctionTemplateDecl(FTD); - } - else if (ClassTemplateDecl *CTD = - dyn_cast(D->getFriendDecl())) { + } else if (auto *CTD = dyn_cast(D->getFriendDecl())) { Out << "friend "; VisitRedeclarableTemplateDecl(CTD); } @@ -790,8 +783,7 @@ Expr *Init = D->getInit(); if (!Policy.SuppressInitializers && Init) { bool ImplicitInit = false; - if (CXXConstructExpr *Construct = - dyn_cast(Init->IgnoreImplicit())) { + if (auto *Construct = dyn_cast(Init->IgnoreImplicit())) { if (D->getInitStyle() == VarDecl::CallInit && !Construct->isListInitialization()) { ImplicitInit = Construct->getNumArgs() == 0 || @@ -1028,8 +1020,7 @@ void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) { printTemplateParameters(D->getTemplateParameters()); - if (const TemplateTemplateParmDecl *TTP = - dyn_cast(D)) { + if (const auto *TTP = dyn_cast(D)) { Out << "class "; if (TTP->isParameterPack()) Out << "..."; @@ -1479,7 +1470,7 @@ E = D->varlist_end(); I != E; ++I) { Out << (I == D->varlist_begin() ? '(' : ','); - NamedDecl *ND = cast(cast(*I)->getDecl()); + auto *ND = cast(cast(*I)->getDecl()); ND->printQualifiedName(Out); } Out << ")"; Index: lib/AST/DeclTemplate.cpp =================================================================== --- lib/AST/DeclTemplate.cpp +++ lib/AST/DeclTemplate.cpp @@ -41,11 +41,11 @@ begin()[Idx] = P; if (!P->isTemplateParameterPack()) { - if (NonTypeTemplateParmDecl *NTTP = dyn_cast(P)) + if (auto *NTTP = dyn_cast(P)) if (NTTP->getType()->containsUnexpandedParameterPack()) ContainsUnexpandedParameterPack = true; - if (TemplateTemplateParmDecl *TTP = dyn_cast(P)) + if (auto *TTP = dyn_cast(P)) if (TTP->getTemplateParameters()->containsUnexpandedParameterPack()) ContainsUnexpandedParameterPack = true; @@ -103,11 +103,9 @@ return 0; const NamedDecl *FirstParm = getParam(0); - if (const TemplateTypeParmDecl *TTP - = dyn_cast(FirstParm)) + if (const auto *TTP = dyn_cast(FirstParm)) return TTP->getDepth(); - else if (const NonTypeTemplateParmDecl *NTTP - = dyn_cast(FirstParm)) + else if (const auto *NTTP = dyn_cast(FirstParm)) return NTTP->getDepth(); else return cast(FirstParm)->getDepth(); @@ -268,7 +266,7 @@ RedeclarableTemplateDecl::CommonBase * FunctionTemplateDecl::newCommon(ASTContext &C) const { - Common *CommonPtr = new (C) Common; + auto *CommonPtr = new (C) Common; C.AddDeallocation(DeallocateCommon, CommonPtr); return CommonPtr; } @@ -335,8 +333,7 @@ NamedDecl *Decl, ClassTemplateDecl *PrevDecl) { AdoptTemplateParameterList(Params, cast(Decl)); - ClassTemplateDecl *New = new (C, DC) ClassTemplateDecl(C, DC, L, Name, - Params, Decl); + auto *New = new (C, DC) ClassTemplateDecl(C, DC, L, Name, Params, Decl); New->setPreviousDecl(PrevDecl); return New; } @@ -376,7 +373,7 @@ RedeclarableTemplateDecl::CommonBase * ClassTemplateDecl::newCommon(ASTContext &C) const { - Common *CommonPtr = new (C) Common; + auto *CommonPtr = new (C) Common; C.AddDeallocation(DeallocateCommon, CommonPtr); return CommonPtr; } @@ -481,8 +478,8 @@ SourceLocation KeyLoc, SourceLocation NameLoc, unsigned D, unsigned P, IdentifierInfo *Id, bool Typename, bool ParameterPack) { - TemplateTypeParmDecl *TTPDecl = - new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename); + auto *TTPDecl = + new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename); QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl); TTPDecl->setTypeForDecl(TTPType.getTypePtr()); return TTPDecl; @@ -738,10 +735,9 @@ ClassTemplateDecl *SpecializedTemplate, ArrayRef Args, ClassTemplateSpecializationDecl *PrevDecl) { - ClassTemplateSpecializationDecl *Result = - new (Context, DC) ClassTemplateSpecializationDecl( - Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc, - SpecializedTemplate, Args, PrevDecl); + auto *Result = new (Context, DC) ClassTemplateSpecializationDecl( + Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc, + SpecializedTemplate, Args, PrevDecl); Result->MayHaveOutOfDateDef = false; Context.getTypeDeclType(Result, PrevDecl); @@ -751,8 +747,8 @@ ClassTemplateSpecializationDecl * ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - ClassTemplateSpecializationDecl *Result = - new (C, ID) ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization); + auto *Result = new (C, ID) + ClassTemplateSpecializationDecl(C, ClassTemplateSpecialization); Result->MayHaveOutOfDateDef = false; return Result; } @@ -768,8 +764,8 @@ ClassTemplateDecl * ClassTemplateSpecializationDecl::getSpecializedTemplate() const { - if (SpecializedPartialSpecialization *PartialSpec - = SpecializedTemplate.dyn_cast()) + if (auto *PartialSpec = + SpecializedTemplate.dyn_cast()) return PartialSpec->PartialSpecialization->getSpecializedTemplate(); return SpecializedTemplate.get(); } @@ -794,7 +790,7 @@ // uses ExplicitInfo to record the TypeAsWritten, but the source // locations should be retrieved from the instantiation pattern. typedef ClassTemplatePartialSpecializationDecl CTPSDecl; - CTPSDecl *ctpsd = const_cast(cast(this)); + auto *ctpsd = const_cast(cast(this)); CTPSDecl *inst_from = ctpsd->getInstantiatedFromMember(); assert(inst_from != nullptr); return inst_from->getSourceRange(); @@ -806,7 +802,7 @@ inst_from = getInstantiatedFrom(); if (inst_from.isNull()) return getSpecializedTemplate()->getSourceRange(); - if (ClassTemplateDecl *ctd = inst_from.dyn_cast()) + if (auto *ctd = inst_from.dyn_cast()) return ctd->getSourceRange(); return inst_from.get() ->getSourceRange(); @@ -852,10 +848,9 @@ const ASTTemplateArgumentListInfo *ASTArgInfos = ASTTemplateArgumentListInfo::Create(Context, ArgInfos); - ClassTemplatePartialSpecializationDecl *Result = new (Context, DC) - ClassTemplatePartialSpecializationDecl(Context, TK, DC, StartLoc, IdLoc, - Params, SpecializedTemplate, Args, - ASTArgInfos, PrevDecl); + auto *Result = new (Context, DC) ClassTemplatePartialSpecializationDecl( + Context, TK, DC, StartLoc, IdLoc, Params, SpecializedTemplate, Args, + ASTArgInfos, PrevDecl); Result->setSpecializationKind(TSK_ExplicitSpecialization); Result->MayHaveOutOfDateDef = false; @@ -866,8 +861,7 @@ ClassTemplatePartialSpecializationDecl * ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) { - ClassTemplatePartialSpecializationDecl *Result = - new (C, ID) ClassTemplatePartialSpecializationDecl(C); + auto *Result = new (C, ID) ClassTemplatePartialSpecializationDecl(C); Result->MayHaveOutOfDateDef = false; return Result; } @@ -916,7 +910,7 @@ } RedeclarableTemplateDecl::CommonBase * TypeAliasTemplateDecl::newCommon(ASTContext &C) const { - Common *CommonPtr = new (C) Common; + auto *CommonPtr = new (C) Common; C.AddDeallocation(DeallocateCommon, CommonPtr); return CommonPtr; } @@ -996,7 +990,7 @@ RedeclarableTemplateDecl::CommonBase * VarTemplateDecl::newCommon(ASTContext &C) const { - Common *CommonPtr = new (C) Common; + auto *CommonPtr = new (C) Common; C.AddDeallocation(DeallocateCommon, CommonPtr); return CommonPtr; } @@ -1099,7 +1093,7 @@ } VarTemplateDecl *VarTemplateSpecializationDecl::getSpecializedTemplate() const { - if (SpecializedPartialSpecialization *PartialSpec = + if (auto *PartialSpec = SpecializedTemplate.dyn_cast()) return PartialSpec->PartialSpecialization->getSpecializedTemplate(); return SpecializedTemplate.get(); @@ -1143,10 +1137,9 @@ const ASTTemplateArgumentListInfo *ASTArgInfos = ASTTemplateArgumentListInfo::Create(Context, ArgInfos); - VarTemplatePartialSpecializationDecl *Result = - new (Context, DC) VarTemplatePartialSpecializationDecl( - Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo, - S, Args, ASTArgInfos); + auto *Result = new (Context, DC) VarTemplatePartialSpecializationDecl( + Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo, S, + Args, ASTArgInfos); Result->setSpecializationKind(TSK_ExplicitSpecialization); return Result; } Index: lib/AST/DeclarationName.cpp =================================================================== --- lib/AST/DeclarationName.cpp +++ lib/AST/DeclarationName.cpp @@ -353,7 +353,7 @@ static const DeclarationNameExtra UDirExtra = { DeclarationNameExtra::CXXUsingDirective }; - uintptr_t Ptr = reinterpret_cast(&UDirExtra); + auto Ptr = reinterpret_cast(&UDirExtra); Ptr |= StoredDeclarationNameExtra; return DeclarationName(Ptr); @@ -377,11 +377,11 @@ } DeclarationNameTable::~DeclarationNameTable() { - llvm::FoldingSet *SpecialNames = - static_cast*>(CXXSpecialNamesImpl); - llvm::FoldingSet *LiteralNames - = static_cast*> - (CXXLiteralOperatorNames); + auto *SpecialNames = + static_cast *>(CXXSpecialNamesImpl); + auto *LiteralNames = + static_cast *>( + CXXLiteralOperatorNames); delete SpecialNames; delete LiteralNames; @@ -408,8 +408,8 @@ assert(Kind >= DeclarationName::CXXConstructorName && Kind <= DeclarationName::CXXConversionFunctionName && "Kind must be a C++ special name kind"); - llvm::FoldingSet *SpecialNames - = static_cast*>(CXXSpecialNamesImpl); + auto *SpecialNames = + static_cast *>(CXXSpecialNamesImpl); DeclarationNameExtra::ExtraKind EKind; switch (Kind) { @@ -437,7 +437,7 @@ if (CXXSpecialName *Name = SpecialNames->FindNodeOrInsertPos(ID, InsertPos)) return DeclarationName(Name); - CXXSpecialName *SpecialName = new (Ctx) CXXSpecialName; + auto *SpecialName = new (Ctx) CXXSpecialName; SpecialName->ExtraKindOrNumArgs = EKind; SpecialName->Type = Ty; SpecialName->FETokenInfo = nullptr; @@ -453,9 +453,9 @@ DeclarationName DeclarationNameTable::getCXXLiteralOperatorName(IdentifierInfo *II) { - llvm::FoldingSet *LiteralNames - = static_cast*> - (CXXLiteralOperatorNames); + auto *LiteralNames = + static_cast *>( + CXXLiteralOperatorNames); llvm::FoldingSetNodeID ID; ID.AddPointer(II); @@ -464,8 +464,8 @@ if (CXXLiteralOperatorIdName *Name = LiteralNames->FindNodeOrInsertPos(ID, InsertPos)) return DeclarationName (Name); - - CXXLiteralOperatorIdName *LiteralName = new (Ctx) CXXLiteralOperatorIdName; + + auto *LiteralName = new (Ctx) CXXLiteralOperatorIdName; LiteralName->ExtraKindOrNumArgs = DeclarationNameExtra::CXXLiteralOperator; LiteralName->ID = II; LiteralName->FETokenInfo = nullptr; Index: lib/AST/Expr.cpp =================================================================== --- lib/AST/Expr.cpp +++ lib/AST/Expr.cpp @@ -63,7 +63,7 @@ const CXXRecordDecl *Expr::getBestDynamicClassType() const { const Expr *E = getBestDynamicClassTypeExpr(); QualType DerivedType = E->getType(); - if (const PointerType *PTy = DerivedType->getAs()) + if (const auto *PTy = DerivedType->getAs()) DerivedType = PTy->getPointeeType(); if (DerivedType->isDependentType()) @@ -81,13 +81,13 @@ while (true) { E = E->IgnoreParens(); - if (const CastExpr *CE = dyn_cast(E)) { + if (const auto *CE = dyn_cast(E)) { if ((CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_UncheckedDerivedToBase) && E->getType()->isRecordType()) { E = CE->getSubExpr(); - CXXRecordDecl *Derived - = cast(E->getType()->getAs()->getDecl()); + auto *Derived = + cast(E->getType()->getAs()->getDecl()); Adjustments.push_back(SubobjectAdjustment(CE, Derived)); continue; } @@ -96,10 +96,10 @@ E = CE->getSubExpr(); continue; } - } else if (const MemberExpr *ME = dyn_cast(E)) { + } else if (const auto *ME = dyn_cast(E)) { if (!ME->isArrow()) { assert(ME->getBase()->getType()->isRecordType()); - if (FieldDecl *Field = dyn_cast(ME->getMemberDecl())) { + if (auto *Field = dyn_cast(ME->getMemberDecl())) { if (!Field->isBitField() && !Field->getType()->isReferenceType()) { E = ME->getBase(); Adjustments.push_back(SubobjectAdjustment(Field)); @@ -107,12 +107,11 @@ } } } - } else if (const BinaryOperator *BO = dyn_cast(E)) { + } else if (const auto *BO = dyn_cast(E)) { if (BO->isPtrMemOp()) { assert(BO->getRHS()->isRValue()); E = BO->getLHS(); - const MemberPointerType *MPT = - BO->getRHS()->getType()->getAs(); + const auto *MPT = BO->getRHS()->getType()->getAs(); Adjustments.push_back(SubobjectAdjustment(MPT, BO->getRHS())); continue; } else if (BO->getOpcode() == BO_Comma) { @@ -139,8 +138,8 @@ if (E->getType()->isBooleanType()) return true; // If this is a non-scalar-integer type, we don't care enough to try. if (!E->getType()->isIntegralOrEnumerationType()) return false; - - if (const UnaryOperator *UO = dyn_cast(E)) { + + if (const auto *UO = dyn_cast(E)) { switch (UO->getOpcode()) { case UO_Plus: return UO->getSubExpr()->isKnownToHaveBooleanValue(); @@ -153,10 +152,10 @@ // Only look through implicit casts. If the user writes // '(int) (a && b)' treat it as an arbitrary int. - if (const ImplicitCastExpr *CE = dyn_cast(E)) + if (const auto *CE = dyn_cast(E)) return CE->getSubExpr()->isKnownToHaveBooleanValue(); - - if (const BinaryOperator *BO = dyn_cast(E)) { + + if (const auto *BO = dyn_cast(E)) { switch (BO->getOpcode()) { default: return false; case BO_LT: // Relational operators. @@ -181,8 +180,8 @@ return BO->getRHS()->isKnownToHaveBooleanValue(); } } - - if (const ConditionalOperator *CO = dyn_cast(E)) + + if (const auto *CO = dyn_cast(E)) return CO->getTrueExpr()->isKnownToHaveBooleanValue() && CO->getFalseExpr()->isKnownToHaveBooleanValue(); @@ -289,7 +288,7 @@ // (VD) - FIXME: Missing from the standard: // - an entity with reference type and is initialized with an // expression that is value-dependent [C++11] - if (VarDecl *Var = dyn_cast(D)) { + if (auto *Var = dyn_cast(D)) { if ((Ctx.getLangOpts().CPlusPlus11 ? Var->getType()->isLiteralType(Ctx) : Var->getType()->isIntegralOrEnumerationType()) && @@ -496,16 +495,16 @@ ASTContext &Context = CurrentDecl->getASTContext(); if (IT == PredefinedExpr::FuncDName) { - if (const NamedDecl *ND = dyn_cast(CurrentDecl)) { + if (const auto *ND = dyn_cast(CurrentDecl)) { std::unique_ptr MC; MC.reset(Context.createMangleContext()); if (MC->shouldMangleDeclName(ND)) { SmallString<256> Buffer; llvm::raw_svector_ostream Out(Buffer); - if (const CXXConstructorDecl *CD = dyn_cast(ND)) + if (const auto *CD = dyn_cast(ND)) MC->mangleCXXCtor(CD, Ctor_Base, Out); - else if (const CXXDestructorDecl *DD = dyn_cast(ND)) + else if (const auto *DD = dyn_cast(ND)) MC->mangleCXXDtor(DD, Dtor_Base, Out); else MC->mangleName(ND, Out); @@ -535,14 +534,14 @@ Out << ComputeName(IT, DCDecl) << "_block_invoke"; return Out.str(); } - if (const FunctionDecl *FD = dyn_cast(CurrentDecl)) { + if (const auto *FD = dyn_cast(CurrentDecl)) { if (IT != PrettyFunction && IT != PrettyFunctionNoVirtual && IT != FuncSig) return FD->getNameAsString(); SmallString<256> Name; llvm::raw_svector_ostream Out(Name); - if (const CXXMethodDecl *MD = dyn_cast(FD)) { + if (const auto *MD = dyn_cast(FD)) { if (MD->isVirtual() && IT != PrettyFunctionNoVirtual) Out << "virtual "; if (MD->isStatic()) @@ -556,7 +555,7 @@ const FunctionDecl *Decl = FD; if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern()) Decl = Pattern; - const FunctionType *AFT = Decl->getType()->getAs(); + const auto *AFT = Decl->getType()->getAs(); const FunctionProtoType *FT = nullptr; if (FD->hasWrittenPrototype()) FT = dyn_cast(AFT); @@ -591,8 +590,8 @@ } POut << ")"; - if (const CXXMethodDecl *MD = dyn_cast(FD)) { - const FunctionType *FT = MD->getType()->castAs(); + if (const auto *MD = dyn_cast(FD)) { + const auto *FT = MD->getType()->castAs(); if (FT->isConst()) POut << " const"; if (FT->isVolatile()) @@ -608,8 +607,7 @@ SpecsTy Specs; const DeclContext *Ctx = FD->getDeclContext(); while (Ctx && isa(Ctx)) { - const ClassTemplateSpecializationDecl *Spec - = dyn_cast(Ctx); + const auto *Spec = dyn_cast(Ctx); if (Spec && !Spec->isExplicitSpecialization()) Specs.push_back(Spec); Ctx = Ctx->getParent(); @@ -676,7 +674,7 @@ return Name.str().str(); } - if (const CapturedDecl *CD = dyn_cast(CurrentDecl)) { + if (const auto *CD = dyn_cast(CurrentDecl)) { for (const DeclContext *DC = CD->getParent(); DC; DC = DC->getParent()) // Skip to its enclosing function or method, but not its enclosing // CapturedDecl. @@ -686,7 +684,7 @@ } llvm_unreachable("CapturedDecl not inside a function or method"); } - if (const ObjCMethodDecl *MD = dyn_cast(CurrentDecl)) { + if (const auto *MD = dyn_cast(CurrentDecl)) { SmallString<256> Name; llvm::raw_svector_ostream Out(Name); Out << (MD->isInstanceMethod() ? '-' : '+'); @@ -697,8 +695,7 @@ if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) Out << *ID; - if (const ObjCCategoryImplDecl *CID = - dyn_cast(MD->getDeclContext())) + if (const auto *CID = dyn_cast(MD->getDeclContext())) Out << '(' << *CID << ')'; Out << ' '; @@ -861,7 +858,7 @@ void *Mem = C.Allocate(sizeof(StringLiteral) + sizeof(SourceLocation) * (NumStrs - 1), alignof(StringLiteral)); - StringLiteral *SL = new (Mem) StringLiteral(Ty); + auto *SL = new (Mem) StringLiteral(Ty); // OPTIMIZE: could allocate this appended to the StringLiteral. SL->setString(C,Str,Kind,Pascal); @@ -996,19 +993,19 @@ switch(CharByteWidth) { case 1: { - char *AStrData = new (C) char[Length]; + auto *AStrData = new (C) char[Length]; std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); StrData.asChar = AStrData; break; } case 2: { - uint16_t *AStrData = new (C) uint16_t[Length]; + auto *AStrData = new (C) uint16_t[Length]; std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); StrData.asUInt16 = AStrData; break; } case 4: { - uint32_t *AStrData = new (C) uint32_t[Length]; + auto *AStrData = new (C) uint32_t[Length]; std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData)); StrData.asUInt32 = AStrData; break; @@ -1221,23 +1218,22 @@ Decl *Expr::getReferencedDeclOfCallee() { Expr *CEE = IgnoreParenImpCasts(); - - while (SubstNonTypeTemplateParmExpr *NTTP - = dyn_cast(CEE)) { + + while (auto *NTTP = dyn_cast(CEE)) { CEE = NTTP->getReplacement()->IgnoreParenCasts(); } // If we're calling a dereference, look at the pointer instead. - if (BinaryOperator *BO = dyn_cast(CEE)) { + if (auto *BO = dyn_cast(CEE)) { if (BO->isPtrMemOp()) CEE = BO->getRHS()->IgnoreParenCasts(); - } else if (UnaryOperator *UO = dyn_cast(CEE)) { + } else if (auto *UO = dyn_cast(CEE)) { if (UO->getOpcode() == UO_Deref) CEE = UO->getSubExpr()->IgnoreParenCasts(); } - if (DeclRefExpr *DRE = dyn_cast(CEE)) + if (auto *DRE = dyn_cast(CEE)) return DRE->getDecl(); - if (MemberExpr *ME = dyn_cast(CEE)) + if (auto *ME = dyn_cast(CEE)) return ME->getMemberDecl(); return nullptr; @@ -1258,7 +1254,7 @@ // Otherwise, we are growing the # arguments. New an bigger argument array. unsigned NumPreArgs = getNumPreArgs(); - Stmt **NewSubExprs = new (C) Stmt*[NumArgs+PREARGS_START+NumPreArgs]; + auto **NewSubExprs = new (C) Stmt *[NumArgs + PREARGS_START + NumPreArgs]; // Copy over args. for (unsigned i = 0; i != getNumArgs()+PREARGS_START+NumPreArgs; ++i) NewSubExprs[i] = SubExprs[i]; @@ -1278,15 +1274,15 @@ // All simple function calls (e.g. func()) are implicitly cast to pointer to // function. As a result, we try and obtain the DeclRefExpr from the // ImplicitCastExpr. - const ImplicitCastExpr *ICE = dyn_cast(getCallee()); + const auto *ICE = dyn_cast(getCallee()); if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). return 0; - const DeclRefExpr *DRE = dyn_cast(ICE->getSubExpr()); + const auto *DRE = dyn_cast(ICE->getSubExpr()); if (!DRE) return 0; - const FunctionDecl *FDecl = dyn_cast(DRE->getDecl()); + const auto *FDecl = dyn_cast(DRE->getDecl()); if (!FDecl) return 0; @@ -1317,7 +1313,7 @@ CalleeType = Expr::findBoundMemberType(Callee); } - const FunctionType *FnType = CalleeType->castAs(); + const auto *FnType = CalleeType->castAs(); return FnType->getReturnType(); } @@ -1451,7 +1447,7 @@ targs ? targs->size() : 0); void *Mem = C.Allocate(Size, alignof(MemberExpr)); - MemberExpr *E = new (Mem) + auto *E = new (Mem) MemberExpr(base, isarrow, OperatorLoc, memberdecl, nameinfo, ty, vk, ok); if (hasQualOrFound) { @@ -1467,8 +1463,7 @@ E->HasQualifierOrFoundDecl = true; - MemberExprNameQualifier *NQ = - E->getTrailingObjects(); + auto *NQ = E->getTrailingObjects(); NQ->QualifierLoc = QualifierLoc; NQ->FoundDecl = founddecl; } @@ -1643,12 +1638,11 @@ SubExpr = E->getSubExpr(); // Skip through reference binding to temporary. - if (MaterializeTemporaryExpr *Materialize - = dyn_cast(SubExpr)) + if (auto *Materialize = dyn_cast(SubExpr)) SubExpr = Materialize->GetTemporaryExpr(); // Skip any temporary bindings; they're implicit. - if (CXXBindTemporaryExpr *Binder = dyn_cast(SubExpr)) + if (auto *Binder = dyn_cast(SubExpr)) SubExpr = Binder->getSubExpr(); // Conversions by constructor and conversion functions have a @@ -1689,8 +1683,7 @@ ExprValueKind VK) { unsigned PathSize = (BasePath ? BasePath->size() : 0); void *Buffer = C.Allocate(totalSizeToAlloc(PathSize)); - ImplicitCastExpr *E = - new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); + auto *E = new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK); if (PathSize) std::uninitialized_copy_n(BasePath->data(), BasePath->size(), E->getTrailingObjects()); @@ -1711,8 +1704,8 @@ SourceLocation L, SourceLocation R) { unsigned PathSize = (BasePath ? BasePath->size() : 0); void *Buffer = C.Allocate(totalSizeToAlloc(PathSize)); - CStyleCastExpr *E = - new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R); + auto *E = + new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R); if (PathSize) std::uninitialized_copy_n(BasePath->data(), BasePath->size(), E->getTrailingObjects()); @@ -1835,7 +1828,7 @@ return nullptr; } - Expr *Result = cast_or_null(InitExprs[Init]); + auto *Result = cast_or_null(InitExprs[Init]); setInit(Init, expr); return Result; } @@ -1971,7 +1964,7 @@ return cast(this)->getChosenSubExpr()-> isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); case UnaryOperatorClass: { - const UnaryOperator *UO = cast(this); + const auto *UO = cast(this); switch (UO->getOpcode()) { case UO_Plus: @@ -2005,7 +1998,7 @@ return true; } case BinaryOperatorClass: { - const BinaryOperator *BO = cast(this); + const auto *BO = cast(this); switch (BO->getOpcode()) { default: break; @@ -2014,8 +2007,7 @@ case BO_Comma: // ((foo = ), 0) is an idiom for hiding the result (and // lvalue-ness) of an assignment written in a macro. - if (IntegerLiteral *IE = - dyn_cast(BO->getRHS()->IgnoreParens())) + if (auto *IE = dyn_cast(BO->getRHS()->IgnoreParens())) if (IE->getValue() == 0) return false; return BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); @@ -2044,7 +2036,7 @@ // If only one of the LHS or RHS is a warning, the operator might // be being used for control flow. Only warn if both the LHS and // RHS are warnings. - const ConditionalOperator *Exp = cast(this); + const auto *Exp = cast(this); if (!Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx)) return false; if (!Exp->getLHS()) @@ -2073,7 +2065,7 @@ // warning: operators == and != are commonly typo'ed, and so warning on them // provides additional value as well. If this list is updated, // DiagnoseUnusedComparison should be as well. - const CXXOperatorCallExpr *Op = cast(this); + const auto *Op = cast(this); switch (Op->getOperator()) { default: break; @@ -2098,9 +2090,9 @@ case CXXMemberCallExprClass: case UserDefinedLiteralClass: { // If this is a direct call, get the callee. - const CallExpr *CE = cast(this); + const auto *CE = cast(this); if (const Decl *FD = CE->getCalleeDecl()) { - const FunctionDecl *Func = dyn_cast(FD); + const auto *Func = dyn_cast(FD); bool HasWarnUnusedResultAttr = Func ? Func->hasUnusedResultAttr() : FD->hasAttr(); @@ -2143,7 +2135,7 @@ } case ObjCMessageExprClass: { - const ObjCMessageExpr *ME = cast(this); + const auto *ME = cast(this); if (Ctx.getLangOpts().ObjCAutoRefCount && ME->isInstanceMessage() && !ME->getType()->isVoidType() && @@ -2171,7 +2163,7 @@ return true; case PseudoObjectExprClass: { - const PseudoObjectExpr *PO = cast(this); + const auto *PO = cast(this); // Only complain about things that have the form of a getter. if (isa(PO->getSyntacticForm()) || @@ -2192,10 +2184,10 @@ // warning. const CompoundStmt *CS = cast(this)->getSubStmt(); if (!CS->body_empty()) { - if (const Expr *E = dyn_cast(CS->body_back())) + if (const auto *E = dyn_cast(CS->body_back())) return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); - if (const LabelStmt *Label = dyn_cast(CS->body_back())) - if (const Expr *E = dyn_cast(Label->getSubStmt())) + if (const auto *Label = dyn_cast(CS->body_back())) + if (const auto *E = dyn_cast(Label->getSubStmt())) return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); } @@ -2210,11 +2202,11 @@ case CStyleCastExprClass: { // Ignore an explicit cast to void unless the operand is a non-trivial // volatile lvalue. - const CastExpr *CE = cast(this); + const auto *CE = cast(this); if (CE->getCastKind() == CK_ToVoid) { if (CE->getSubExpr()->isGLValue() && CE->getSubExpr()->getType().isVolatileQualified()) { - const DeclRefExpr *DRE = + const auto *DRE = dyn_cast(CE->getSubExpr()->IgnoreParens()); if (!(DRE && isa(DRE->getDecl()) && cast(DRE->getDecl())->hasLocalStorage())) { @@ -2231,12 +2223,11 @@ return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); WarnE = this; - if (const CXXFunctionalCastExpr *CXXCE = - dyn_cast(this)) { + if (const auto *CXXCE = dyn_cast(this)) { Loc = CXXCE->getLocStart(); R1 = CXXCE->getSubExpr()->getSourceRange(); } else { - const CStyleCastExpr *CStyleCE = cast(this); + const auto *CStyleCE = cast(this); Loc = CStyleCE->getLParenLoc(); R1 = CStyleCE->getSubExpr()->getSourceRange(); } @@ -2296,8 +2287,8 @@ return cast(E)->getSubExpr()->isOBJCGCCandidate(Ctx); case DeclRefExprClass: { const Decl *D = cast(E)->getDecl(); - - if (const VarDecl *VD = dyn_cast(D)) { + + if (const auto *VD = dyn_cast(D)) { if (VD->hasGlobalStorage()) return true; QualType T = VD->getType(); @@ -2309,7 +2300,7 @@ return false; } case MemberExprClass: { - const MemberExpr *M = cast(E); + const auto *M = cast(E); return M->getBase()->isOBJCGCCandidate(Ctx); } case ArraySubscriptExprClass: @@ -2331,12 +2322,12 @@ // (possibly parenthesized) expr = expr->IgnoreParens(); - if (const MemberExpr *mem = dyn_cast(expr)) { + if (const auto *mem = dyn_cast(expr)) { assert(isa(mem->getMemberDecl())); return mem->getMemberDecl()->getType(); } - if (const BinaryOperator *op = dyn_cast(expr)) { + if (const auto *op = dyn_cast(expr)) { QualType type = op->getRHS()->getType()->castAs() ->getPointeeType(); assert(type->isFunctionType()); @@ -2350,23 +2341,23 @@ Expr* Expr::IgnoreParens() { Expr* E = this; while (true) { - if (ParenExpr* P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { E = P->getSubExpr(); continue; } - if (UnaryOperator* P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { if (P->getOpcode() == UO_Extension) { E = P->getSubExpr(); continue; } } - if (GenericSelectionExpr* P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { if (!P->isResultDependent()) { E = P->getResultExpr(); continue; } } - if (ChooseExpr* P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { if (!P->isConditionDependent()) { E = P->getChosenSubExpr(); continue; @@ -2382,17 +2373,15 @@ Expr *E = this; while (true) { E = E->IgnoreParens(); - if (CastExpr *P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { E = P->getSubExpr(); continue; } - if (MaterializeTemporaryExpr *Materialize - = dyn_cast(E)) { + if (auto *Materialize = dyn_cast(E)) { E = Materialize->GetTemporaryExpr(); continue; } - if (SubstNonTypeTemplateParmExpr *NTTP - = dyn_cast(E)) { + if (auto *NTTP = dyn_cast(E)) { E = NTTP->getReplacement(); continue; } @@ -2403,17 +2392,15 @@ Expr *Expr::IgnoreCasts() { Expr *E = this; while (true) { - if (CastExpr *P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { E = P->getSubExpr(); continue; } - if (MaterializeTemporaryExpr *Materialize - = dyn_cast(E)) { + if (auto *Materialize = dyn_cast(E)) { E = Materialize->GetTemporaryExpr(); continue; } - if (SubstNonTypeTemplateParmExpr *NTTP - = dyn_cast(E)) { + if (auto *NTTP = dyn_cast(E)) { E = NTTP->getReplacement(); continue; } @@ -2429,17 +2416,15 @@ Expr *E = this; while (true) { E = E->IgnoreParens(); - if (CastExpr *P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { if (P->getCastKind() == CK_LValueToRValue) { E = P->getSubExpr(); continue; } - } else if (MaterializeTemporaryExpr *Materialize - = dyn_cast(E)) { + } else if (auto *Materialize = dyn_cast(E)) { E = Materialize->GetTemporaryExpr(); continue; - } else if (SubstNonTypeTemplateParmExpr *NTTP - = dyn_cast(E)) { + } else if (auto *NTTP = dyn_cast(E)) { E = NTTP->getReplacement(); continue; } @@ -2452,7 +2437,7 @@ Expr *E = this; while (true) { E = E->IgnoreParens(); - if (CastExpr *CE = dyn_cast(E)) { + if (auto *CE = dyn_cast(E)) { if (CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_UncheckedDerivedToBase || CE->getCastKind() == CK_NoOp) { @@ -2469,17 +2454,15 @@ Expr *E = this; while (true) { E = E->IgnoreParens(); - if (ImplicitCastExpr *P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { E = P->getSubExpr(); continue; } - if (MaterializeTemporaryExpr *Materialize - = dyn_cast(E)) { + if (auto *Materialize = dyn_cast(E)) { E = Materialize->GetTemporaryExpr(); continue; } - if (SubstNonTypeTemplateParmExpr *NTTP - = dyn_cast(E)) { + if (auto *NTTP = dyn_cast(E)) { E = NTTP->getReplacement(); continue; } @@ -2488,7 +2471,7 @@ } Expr *Expr::IgnoreConversionOperator() { - if (CXXMemberCallExpr *MCE = dyn_cast(this)) { + if (auto *MCE = dyn_cast(this)) { if (MCE->getMethodDecl() && isa(MCE->getMethodDecl())) return MCE->getImplicitObjectArgument(); } @@ -2503,7 +2486,7 @@ while (true) { E = E->IgnoreParens(); - if (CastExpr *P = dyn_cast(E)) { + if (auto *P = dyn_cast(E)) { // We ignore integer <-> casts that are of the same width, ptr<->ptr and // ptr<->int casts of the same width. We also ignore all identity casts. Expr *SE = P->getSubExpr(); @@ -2523,8 +2506,7 @@ } } - if (SubstNonTypeTemplateParmExpr *NTTP - = dyn_cast(E)) { + if (auto *NTTP = dyn_cast(E)) { E = NTTP->getReplacement(); continue; } @@ -2535,10 +2517,10 @@ bool Expr::isDefaultArgument() const { const Expr *E = this; - if (const MaterializeTemporaryExpr *M = dyn_cast(E)) + if (const auto *M = dyn_cast(E)) E = M->GetTemporaryExpr(); - while (const ImplicitCastExpr *ICE = dyn_cast(E)) + while (const auto *ICE = dyn_cast(E)) E = ICE->getSubExprAsWritten(); return isa(E); @@ -2547,20 +2529,20 @@ /// \brief Skip over any no-op casts and any temporary-binding /// expressions. static const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) { - if (const MaterializeTemporaryExpr *M = dyn_cast(E)) + if (const auto *M = dyn_cast(E)) E = M->GetTemporaryExpr(); - while (const ImplicitCastExpr *ICE = dyn_cast(E)) { + while (const auto *ICE = dyn_cast(E)) { if (ICE->getCastKind() == CK_NoOp) E = ICE->getSubExpr(); else break; } - while (const CXXBindTemporaryExpr *BE = dyn_cast(E)) + while (const auto *BE = dyn_cast(E)) E = BE->getSubExpr(); - while (const ImplicitCastExpr *ICE = dyn_cast(E)) { + while (const auto *ICE = dyn_cast(E)) { if (ICE->getCastKind() == CK_NoOp) E = ICE->getSubExpr(); else @@ -2603,7 +2585,7 @@ if (isa(E)) return false; - if (const BinaryOperator *BO = dyn_cast(E)) + if (const auto *BO = dyn_cast(E)) if (BO->isPtrMemOp()) return false; @@ -2619,12 +2601,12 @@ // Strip away parentheses and casts we don't care about. while (true) { - if (const ParenExpr *Paren = dyn_cast(E)) { + if (const auto *Paren = dyn_cast(E)) { E = Paren->getSubExpr(); continue; } - - if (const ImplicitCastExpr *ICE = dyn_cast(E)) { + + if (const auto *ICE = dyn_cast(E)) { if (ICE->getCastKind() == CK_NoOp || ICE->getCastKind() == CK_LValueToRValue || ICE->getCastKind() == CK_DerivedToBase || @@ -2633,24 +2615,23 @@ continue; } } - - if (const UnaryOperator* UnOp = dyn_cast(E)) { + + if (const auto *UnOp = dyn_cast(E)) { if (UnOp->getOpcode() == UO_Extension) { E = UnOp->getSubExpr(); continue; } } - - if (const MaterializeTemporaryExpr *M - = dyn_cast(E)) { + + if (const auto *M = dyn_cast(E)) { E = M->GetTemporaryExpr(); continue; } break; } - - if (const CXXThisExpr *This = dyn_cast(E)) + + if (const auto *This = dyn_cast(E)) return This->isImplicit(); return false; @@ -2693,7 +2674,7 @@ return true; case CXXTemporaryObjectExprClass: case CXXConstructExprClass: { - const CXXConstructExpr *CE = cast(this); + const auto *CE = cast(this); if (CE->getConstructor()->isTrivial() && CE->getConstructor()->getParent()->hasTrivialDestructor()) { @@ -2715,12 +2696,12 @@ return Exp->isConstantInitializer(Ctx, false, Culprit); } case DesignatedInitUpdateExprClass: { - const DesignatedInitUpdateExpr *DIUE = cast(this); + const auto *DIUE = cast(this); return DIUE->getBase()->isConstantInitializer(Ctx, false, Culprit) && DIUE->getUpdater()->isConstantInitializer(Ctx, false, Culprit); } case InitListExprClass: { - const InitListExpr *ILE = cast(this); + const auto *ILE = cast(this); if (ILE->getType()->isArrayType()) { unsigned numInits = ILE->getNumInits(); for (unsigned i = 0; i < numInits; i++) { @@ -2782,7 +2763,7 @@ return cast(this)->getChosenSubExpr() ->isConstantInitializer(Ctx, IsForRef, Culprit); case UnaryOperatorClass: { - const UnaryOperator* Exp = cast(this); + const auto *Exp = cast(this); if (Exp->getOpcode() == UO_Extension) return Exp->getSubExpr()->isConstantInitializer(Ctx, false, Culprit); break; @@ -2795,7 +2776,7 @@ case CXXDynamicCastExprClass: case CXXReinterpretCastExprClass: case CXXConstCastExprClass: { - const CastExpr *CE = cast(this); + const auto *CE = cast(this); // Handle misc casts we want to ignore. if (CE->getCastKind() == CK_NoOp || @@ -3027,7 +3008,7 @@ case CXXDynamicCastExprClass: { // A dynamic_cast expression has side-effects if it can throw. - const CXXDynamicCastExpr *DCE = cast(this); + const auto *DCE = cast(this); if (DCE->getTypeAsWritten()->isReferenceType() && DCE->getCastKind() == CK_Dynamic) return true; @@ -3045,7 +3026,7 @@ if (!IncludePossibleEffects) break; - const CastExpr *CE = cast(this); + const auto *CE = cast(this); if (CE->getCastKind() == CK_LValueToRValue && CE->getSubExpr()->getType().isVolatileQualified()) return true; @@ -3059,7 +3040,7 @@ case CXXConstructExprClass: case CXXTemporaryObjectExprClass: { - const CXXConstructExpr *CE = cast(this); + const auto *CE = cast(this); if (!CE->getConstructor()->isTrivial() && IncludePossibleEffects) return true; // A trivial constructor does not add any side-effects of its own. Just look @@ -3075,7 +3056,7 @@ } case LambdaExprClass: { - const LambdaExpr *LE = cast(this); + const auto *LE = cast(this); for (LambdaExpr::capture_iterator I = LE->capture_begin(), E = LE->capture_end(); I != E; ++I) if (I->getCaptureKind() == LCK_ByCopy) @@ -3088,12 +3069,12 @@ case PseudoObjectExprClass: { // Only look for side-effects in the semantic form, and look past // OpaqueValueExpr bindings in that form. - const PseudoObjectExpr *PO = cast(this); + const auto *PO = cast(this); for (PseudoObjectExpr::const_semantics_iterator I = PO->semantics_begin(), E = PO->semantics_end(); I != E; ++I) { const Expr *Subexpr = *I; - if (const OpaqueValueExpr *OVE = dyn_cast(Subexpr)) + if (const auto *OVE = dyn_cast(Subexpr)) Subexpr = OVE->getSourceExpr(); if (Subexpr->HasSideEffects(Ctx, IncludePossibleEffects)) return true; @@ -3142,8 +3123,8 @@ bool hasNonTrivialCall() const { return NonTrivial; } void VisitCallExpr(const CallExpr *E) { - if (const CXXMethodDecl *Method - = dyn_cast_or_null(E->getCalleeDecl())) { + if (const auto *Method = + dyn_cast_or_null(E->getCalleeDecl())) { if (Method->isTrivial()) { // Recurse to children of the call. Inherited::VisitStmt(E); @@ -3206,10 +3187,10 @@ } // Strip off a cast to void*, if it exists. Except in C++. - if (const ExplicitCastExpr *CE = dyn_cast(this)) { + if (const auto *CE = dyn_cast(this)) { if (!Ctx.getLangOpts().CPlusPlus) { // Check that it is a cast to void*. - if (const PointerType *PT = CE->getType()->getAs()) { + if (const auto *PT = CE->getType()->getAs()) { QualType Pointee = PT->getPointeeType(); Qualifiers Q = Pointee.getQualifiers(); // In OpenCL v2.0 generic address space acts as a placeholder @@ -3228,37 +3209,33 @@ return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); } } - } else if (const ImplicitCastExpr *ICE = dyn_cast(this)) { + } else if (const auto *ICE = dyn_cast(this)) { // Ignore the ImplicitCastExpr type entirely. return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC); - } else if (const ParenExpr *PE = dyn_cast(this)) { + } else if (const auto *PE = dyn_cast(this)) { // Accept ((void*)0) as a null pointer constant, as many other // implementations do. return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC); - } else if (const GenericSelectionExpr *GE = - dyn_cast(this)) { + } else if (const auto *GE = dyn_cast(this)) { if (GE->isResultDependent()) return NPCK_NotNull; return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC); - } else if (const ChooseExpr *CE = dyn_cast(this)) { + } else if (const auto *CE = dyn_cast(this)) { if (CE->isConditionDependent()) return NPCK_NotNull; return CE->getChosenSubExpr()->isNullPointerConstant(Ctx, NPC); - } else if (const CXXDefaultArgExpr *DefaultArg - = dyn_cast(this)) { + } else if (const auto *DefaultArg = dyn_cast(this)) { // See through default argument expressions. return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC); - } else if (const CXXDefaultInitExpr *DefaultInit - = dyn_cast(this)) { + } else if (const auto *DefaultInit = dyn_cast(this)) { // See through default initializer expressions. return DefaultInit->getExpr()->isNullPointerConstant(Ctx, NPC); } else if (isa(this)) { // The GNU __null extension is always a null pointer constant. return NPCK_GNUNull; - } else if (const MaterializeTemporaryExpr *M - = dyn_cast(this)) { + } else if (const auto *M = dyn_cast(this)) { return M->GetTemporaryExpr()->isNullPointerConstant(Ctx, NPC); - } else if (const OpaqueValueExpr *OVE = dyn_cast(this)) { + } else if (const auto *OVE = dyn_cast(this)) { if (const Expr *Source = OVE->getSourceExpr()) return Source->isNullPointerConstant(Ctx, NPC); } @@ -3270,9 +3247,9 @@ if (const RecordType *UT = getType()->getAsUnionType()) if (!Ctx.getLangOpts().CPlusPlus11 && UT && UT->getDecl()->hasAttr()) - if (const CompoundLiteralExpr *CLE = dyn_cast(this)){ + if (const auto *CLE = dyn_cast(this)) { const Expr *InitExpr = CLE->getInitializer(); - if (const InitListExpr *ILE = dyn_cast(InitExpr)) + if (const auto *ILE = dyn_cast(InitExpr)) return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC); } // This expression must be an integer type. @@ -3284,7 +3261,7 @@ // C++11 [conv.ptr]p1: A null pointer constant is an integer literal with // value zero or a prvalue of type std::nullptr_t. // Microsoft mode permits C++98 rules reflecting MSVC behavior. - const IntegerLiteral *Lit = dyn_cast(this); + const auto *Lit = dyn_cast(this); if (Lit && !Lit->getValue()) return NPCK_ZeroLiteral; else if (!Ctx.getLangOpts().MSVCCompat || !isCXX98IntegralConstantExpr(Ctx)) @@ -3313,7 +3290,7 @@ E->getObjectKind() == OK_ObjCProperty) && "expression is not a property reference"); E = E->IgnoreParenCasts(); - if (const BinaryOperator *BO = dyn_cast(E)) { + if (const auto *BO = dyn_cast(E)) { if (BO->getOpcode() == BO_Comma) { E = BO->getRHS(); continue; @@ -3329,15 +3306,15 @@ bool Expr::isObjCSelfExpr() const { const Expr *E = IgnoreParenImpCasts(); - const DeclRefExpr *DRE = dyn_cast(E); + const auto *DRE = dyn_cast(E); if (!DRE) return false; - const ImplicitParamDecl *Param = dyn_cast(DRE->getDecl()); + const auto *Param = dyn_cast(DRE->getDecl()); if (!Param) return false; - const ObjCMethodDecl *M = dyn_cast(Param->getDeclContext()); + const auto *M = dyn_cast(Param->getDeclContext()); if (!M) return false; @@ -3347,7 +3324,7 @@ FieldDecl *Expr::getSourceBitField() { Expr *E = this->IgnoreParens(); - while (ImplicitCastExpr *ICE = dyn_cast(E)) { + while (auto *ICE = dyn_cast(E)) { if (ICE->getCastKind() == CK_LValueToRValue || (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp)) E = ICE->getSubExpr()->IgnoreParens(); @@ -3355,27 +3332,27 @@ break; } - if (MemberExpr *MemRef = dyn_cast(E)) - if (FieldDecl *Field = dyn_cast(MemRef->getMemberDecl())) + if (auto *MemRef = dyn_cast(E)) + if (auto *Field = dyn_cast(MemRef->getMemberDecl())) if (Field->isBitField()) return Field; - if (ObjCIvarRefExpr *IvarRef = dyn_cast(E)) - if (FieldDecl *Ivar = dyn_cast(IvarRef->getDecl())) + if (auto *IvarRef = dyn_cast(E)) + if (auto *Ivar = dyn_cast(IvarRef->getDecl())) if (Ivar->isBitField()) return Ivar; - if (DeclRefExpr *DeclRef = dyn_cast(E)) { - if (FieldDecl *Field = dyn_cast(DeclRef->getDecl())) + if (auto *DeclRef = dyn_cast(E)) { + if (auto *Field = dyn_cast(DeclRef->getDecl())) if (Field->isBitField()) return Field; - if (BindingDecl *BD = dyn_cast(DeclRef->getDecl())) + if (auto *BD = dyn_cast(DeclRef->getDecl())) if (Expr *E = BD->getBinding()) return E->getSourceBitField(); } - if (BinaryOperator *BinOp = dyn_cast(E)) { + if (auto *BinOp = dyn_cast(E)) { if (BinOp->isAssignmentOp() && BinOp->getLHS()) return BinOp->getLHS()->getSourceBitField(); @@ -3383,7 +3360,7 @@ return BinOp->getRHS()->getSourceBitField(); } - if (UnaryOperator *UnOp = dyn_cast(E)) + if (auto *UnOp = dyn_cast(E)) if (UnOp->isPrefix() && UnOp->isIncrementDecrementOp()) return UnOp->getSubExpr()->getSourceBitField(); @@ -3393,16 +3370,16 @@ bool Expr::refersToVectorElement() const { // FIXME: Why do we not just look at the ObjectKind here? const Expr *E = this->IgnoreParens(); - - while (const ImplicitCastExpr *ICE = dyn_cast(E)) { + + while (const auto *ICE = dyn_cast(E)) { if (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp) E = ICE->getSubExpr()->IgnoreParens(); else break; } - - if (const ArraySubscriptExpr *ASE = dyn_cast(E)) + + if (const auto *ASE = dyn_cast(E)) return ASE->getBase()->getType()->isVectorType(); if (isa(E)) @@ -3419,7 +3396,7 @@ bool Expr::refersToGlobalRegisterVar() const { const Expr *E = this->IgnoreParenImpCasts(); - if (const DeclRefExpr *DRE = dyn_cast(E)) + if (const auto *DRE = dyn_cast(E)) if (const auto *VD = dyn_cast(DRE->getDecl())) if (VD->getStorageClass() == SC_Register && VD->hasAttr() && !VD->isLocalVarDecl()) @@ -3435,7 +3412,7 @@ } unsigned ExtVectorElementExpr::getNumElements() const { - if (const VectorType *VT = getType()->getAs()) + if (const auto *VT = getType()->getAs()) return VT->getNumElements(); return 1; } @@ -3684,7 +3661,7 @@ } SourceRange DesignatedInitExpr::getDesignatorsSourceRange() const { - DesignatedInitExpr *DIE = const_cast(this); + auto *DIE = const_cast(this); if (size() == 1) return DIE->getDesignator(0)->getSourceRange(); return SourceRange(DIE->getDesignator(0)->getLocStart(), @@ -3744,8 +3721,8 @@ return; } - Designator *NewDesignators - = new (C) Designator[NumDesignators - 1 + NumNewDesignators]; + auto *NewDesignators = + new (C) Designator[NumDesignators - 1 + NumNewDesignators]; std::copy(Designators, Designators + Idx, NewDesignators); std::copy(First, Last, NewDesignators + Idx); std::copy(Designators + Idx + 1, Designators + NumDesignators, @@ -3795,12 +3772,12 @@ } const OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) { - if (const ExprWithCleanups *ewc = dyn_cast(e)) + if (const auto *ewc = dyn_cast(e)) e = ewc->getSubExpr(); - if (const MaterializeTemporaryExpr *m = dyn_cast(e)) + if (const auto *m = dyn_cast(e)) e = m->GetTemporaryExpr(); e = cast(e)->getArg(0); - while (const ImplicitCastExpr *ice = dyn_cast(e)) + while (const auto *ice = dyn_cast(e)) e = ice->getSubExpr(); return cast(e); } @@ -3881,8 +3858,8 @@ // size expression of the VLA needs to be treated as an executable expression. // Why isn't this weirdness documented better in StmtIterator? if (isArgumentType()) { - if (const VariableArrayType* T = dyn_cast( - getArgumentType().getTypePtr())) + if (const auto *T = + dyn_cast(getArgumentType().getTypePtr())) return child_range(child_iterator(T), child_iterator()); return child_range(child_iterator(), child_iterator()); } Index: lib/AST/ExprCXX.cpp =================================================================== --- lib/AST/ExprCXX.cpp +++ lib/AST/ExprCXX.cpp @@ -474,9 +474,9 @@ Expr *CXXMemberCallExpr::getImplicitObjectArgument() const { const Expr *Callee = getCallee()->IgnoreParens(); - if (const MemberExpr *MemExpr = dyn_cast(Callee)) + if (const auto *MemExpr = dyn_cast(Callee)) return MemExpr->getBase(); - if (const BinaryOperator *BO = dyn_cast(Callee)) + if (const auto *BO = dyn_cast(Callee)) if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI) return BO->getLHS(); @@ -485,8 +485,7 @@ } CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const { - if (const MemberExpr *MemExpr = - dyn_cast(getCallee()->IgnoreParens())) + if (const auto *MemExpr = dyn_cast(getCallee()->IgnoreParens())) return cast(MemExpr->getMemberDecl()); // FIXME: Will eventually need to cope with member pointers. @@ -533,9 +532,8 @@ SourceRange AngleBrackets) { unsigned PathSize = (BasePath ? BasePath->size() : 0); void *Buffer = C.Allocate(totalSizeToAlloc(PathSize)); - CXXStaticCastExpr *E = - new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, - RParenLoc, AngleBrackets); + auto *E = new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, + RParenLoc, AngleBrackets); if (PathSize) std::uninitialized_copy_n(BasePath->data(), BasePath->size(), E->getTrailingObjects()); @@ -558,9 +556,8 @@ SourceRange AngleBrackets) { unsigned PathSize = (BasePath ? BasePath->size() : 0); void *Buffer = C.Allocate(totalSizeToAlloc(PathSize)); - CXXDynamicCastExpr *E = - new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, - RParenLoc, AngleBrackets); + auto *E = new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, + L, RParenLoc, AngleBrackets); if (PathSize) std::uninitialized_copy_n(BasePath->data(), BasePath->size(), E->getTrailingObjects()); @@ -586,7 +583,7 @@ QualType SrcType = getSubExpr()->getType(); QualType DestType = getType(); - if (const PointerType *SrcPTy = SrcType->getAs()) { + if (const auto *SrcPTy = SrcType->getAs()) { SrcType = SrcPTy->getPointeeType(); DestType = DestType->castAs()->getPointeeType(); } @@ -615,9 +612,8 @@ SourceRange AngleBrackets) { unsigned PathSize = (BasePath ? BasePath->size() : 0); void *Buffer = C.Allocate(totalSizeToAlloc(PathSize)); - CXXReinterpretCastExpr *E = - new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, - RParenLoc, AngleBrackets); + auto *E = new (Buffer) CXXReinterpretCastExpr( + T, VK, K, Op, PathSize, WrittenTy, L, RParenLoc, AngleBrackets); if (PathSize) std::uninitialized_copy_n(BasePath->data(), BasePath->size(), E->getTrailingObjects()); @@ -650,8 +646,8 @@ SourceLocation L, SourceLocation R) { unsigned PathSize = (BasePath ? BasePath->size() : 0); void *Buffer = C.Allocate(totalSizeToAlloc(PathSize)); - CXXFunctionalCastExpr *E = - new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R); + auto *E = + new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R); if (PathSize) std::uninitialized_copy_n(BasePath->data(), BasePath->size(), E->getTrailingObjects()); @@ -1058,7 +1054,7 @@ LParenLoc(LParenLoc), RParenLoc(RParenLoc), NumArgs(Args.size()) { - Expr **StoredArgs = getTrailingObjects(); + auto **StoredArgs = getTrailingObjects(); for (unsigned I = 0; I != Args.size(); ++I) { if (Args[I]->containsUnexpandedParameterPack()) ExprBits.ContainsUnexpandedParameterPack = true; @@ -1277,7 +1273,7 @@ else { QualType BaseType = getBaseType().getNonReferenceType(); if (isArrow()) { - const PointerType *PT = BaseType->getAs(); + const auto *PT = BaseType->getAs(); assert(PT && "base of arrow member access is not pointer"); BaseType = PT->getPointeeType(); } @@ -1383,7 +1379,7 @@ TypeTraitExprBits.Value = Value; TypeTraitExprBits.NumArgs = Args.size(); - TypeSourceInfo **ToArgs = getTrailingObjects(); + auto **ToArgs = getTrailingObjects(); for (unsigned I = 0, N = Args.size(); I != N; ++I) { if (Args[I]->getType()->isDependentType()) Index: lib/AST/ExprClassification.cpp =================================================================== --- lib/AST/ExprClassification.cpp +++ lib/AST/ExprClassification.cpp @@ -348,14 +348,14 @@ case Expr::BinaryConditionalOperatorClass: { if (!Lang.CPlusPlus) return Cl::CL_PRValue; - const BinaryConditionalOperator *co = cast(E); + const auto *co = cast(E); return ClassifyConditional(Ctx, co->getTrueExpr(), co->getFalseExpr()); } case Expr::ConditionalOperatorClass: { // Once again, only C++ is interesting. if (!Lang.CPlusPlus) return Cl::CL_PRValue; - const ConditionalOperator *co = cast(E); + const auto *co = cast(E); return ClassifyConditional(Ctx, co->getTrueExpr(), co->getFalseExpr()); } @@ -385,7 +385,7 @@ case Expr::StmtExprClass: { const CompoundStmt *S = cast(E)->getSubStmt(); - if (const Expr *LastExpr = dyn_cast_or_null(S->body_back())) + if (const auto *LastExpr = dyn_cast_or_null(S->body_back())) return ClassifyUnnamed(Ctx, LastExpr->getType()); return Cl::CL_PRValue; } @@ -433,8 +433,7 @@ return Cl::CL_MemberFunction; bool islvalue; - if (const NonTypeTemplateParmDecl *NTTParm = - dyn_cast(D)) + if (const auto *NTTParm = dyn_cast(D)) islvalue = NTTParm->getType()->isReferenceType(); else islvalue = isa(D) || isa(D) || @@ -460,7 +459,7 @@ // otherwise. if (T->isLValueReferenceType()) return Cl::CL_LValue; - const RValueReferenceType *RV = T->getAs(); + const auto *RV = T->getAs(); if (!RV) // Could still be a class temporary, though. return ClassifyTemporary(T); @@ -490,7 +489,7 @@ // C++ [expr.ref]p3: E1->E2 is converted to the equivalent form (*(E1)).E2. // C++ [expr.ref]p4: If E2 is declared to have type "reference to T", then // E1.E2 is an lvalue. - if (ValueDecl *Value = dyn_cast(Member)) + if (auto *Value = dyn_cast(Member)) if (Value->getType()->isReferenceType()) return Cl::CL_LValue; @@ -516,7 +515,7 @@ // -- If it refers to a static member function [...], then E1.E2 is an // lvalue; [...] // -- Otherwise [...] E1.E2 is a prvalue. - if (CXXMethodDecl *Method = dyn_cast(Member)) + if (auto *Method = dyn_cast(Member)) return Method->isStatic() ? Cl::CL_LValue : Cl::CL_MemberFunction; // -- If E2 is a member enumerator [...], the expression E1.E2 is a prvalue. @@ -598,8 +597,7 @@ if (Kind == Cl::CL_PRValue) { // For the sake of better diagnostics, we want to specifically recognize // use of the GCC cast-as-lvalue extension. - if (const ExplicitCastExpr *CE = - dyn_cast(E->IgnoreParens())) { + if (const auto *CE = dyn_cast(E->IgnoreParens())) { if (CE->getSubExpr()->IgnoreParenImpCasts()->isLValue()) { Loc = CE->getExprLoc(); return Cl::CM_LValueCast; @@ -616,7 +614,7 @@ // Assignment to a property in ObjC is an implicit setter access. But a // setter might not exist. - if (const ObjCPropertyRefExpr *Expr = dyn_cast(E)) { + if (const auto *Expr = dyn_cast(E)) { if (Expr->isImplicitProperty() && Expr->getImplicitPropertySetter() == nullptr) return Cl::CM_NoSetterProperty; Index: lib/AST/ExprConstant.cpp =================================================================== --- lib/AST/ExprConstant.cpp +++ lib/AST/ExprConstant.cpp @@ -61,15 +61,14 @@ static QualType getType(APValue::LValueBase B) { if (!B) return QualType(); - if (const ValueDecl *D = B.dyn_cast()) + if (const auto *D = B.dyn_cast()) return D->getType(); - const Expr *Base = B.get(); + const auto *Base = B.get(); // For a materialized temporary, the type of the temporary we materialized // may not be the type of the expression. - if (const MaterializeTemporaryExpr *MTE = - dyn_cast(Base)) { + if (const auto *MTE = dyn_cast(Base)) { SmallVector CommaLHSs; SmallVector Adjustments; const Expr *Temp = MTE->GetTemporaryExpr(); @@ -120,14 +119,13 @@ Type = Base; for (unsigned I = 0, N = Path.size(); I != N; ++I) { if (Type->isArrayType()) { - const ConstantArrayType *CAT = - cast(Ctx.getAsArrayType(Type)); + const auto *CAT = cast(Ctx.getAsArrayType(Type)); Type = CAT->getElementType(); ArraySize = CAT->getSize().getZExtValue(); MostDerivedLength = I + 1; IsArray = true; } else if (Type->isAnyComplexType()) { - const ComplexType *CT = Type->castAs(); + const auto *CT = Type->castAs(); Type = CT->getElementType(); ArraySize = 2; MostDerivedLength = I + 1; @@ -256,7 +254,7 @@ Entries.push_back(Entry); // If this isn't a base class, it's a new most-derived object. - if (const FieldDecl *FD = dyn_cast(D)) { + if (const auto *FD = dyn_cast(D)) { MostDerivedType = FD->getType(); MostDerivedIsArrayElement = false; MostDerivedArraySize = 0; @@ -339,7 +337,7 @@ ~CallStackFrame(); APValue *getTemporary(const void *Key) { - MapTy::iterator I = Temporaries.find(Key); + auto I = Temporaries.find(Key); return I == Temporaries.end() ? nullptr : &I->second; } APValue &createTemporary(const void *Key, bool IsLifetimeExtended); @@ -1373,20 +1371,20 @@ // std::nullptr_t. if (!B) return true; - if (const ValueDecl *D = B.dyn_cast()) { + if (const auto *D = B.dyn_cast()) { // ... the address of an object with static storage duration, - if (const VarDecl *VD = dyn_cast(D)) + if (const auto *VD = dyn_cast(D)) return VD->hasGlobalStorage(); // ... the address of a function, return isa(D); } - const Expr *E = B.get(); + const auto *E = B.get(); switch (E->getStmtClass()) { default: return false; case Expr::CompoundLiteralExprClass: { - const CompoundLiteralExpr *CLE = cast(E); + const auto *CLE = cast(E); return CLE->isFileScope() && CLE->isLValue(); } case Expr::MaterializeTemporaryExprClass: @@ -1423,7 +1421,7 @@ static void NoteLValueLocation(EvalInfo &Info, APValue::LValueBase Base) { assert(Base && "no location for a null lvalue"); - const ValueDecl *VD = Base.dyn_cast(); + const auto *VD = Base.dyn_cast(); if (VD) Info.Note(VD->getLocation(), diag::note_declared_at); else @@ -1446,7 +1444,7 @@ // assumed to be global here. if (!IsGlobalLValue(Base)) { if (Info.getLangOpts().CPlusPlus11) { - const ValueDecl *VD = Base.dyn_cast(); + const auto *VD = Base.dyn_cast(); Info.FFDiag(Loc, diag::note_constexpr_non_global, 1) << IsReferenceType << !Designator.Entries.empty() << !!VD << VD; @@ -1461,8 +1459,8 @@ LVal.getLValueCallIndex() == 0) && "have call index for global lvalue"); - if (const ValueDecl *VD = Base.dyn_cast()) { - if (const VarDecl *Var = dyn_cast(VD)) { + if (const auto *VD = Base.dyn_cast()) { + if (const auto *Var = dyn_cast(VD)) { // Check if this is a thread-local variable. if (Var->getTLSKind()) return false; @@ -1501,7 +1499,7 @@ // Does this refer one past the end of some object? if (!Designator.Invalid && Designator.isOnePastTheEnd()) { - const ValueDecl *VD = Base.dyn_cast(); + const auto *VD = Base.dyn_cast(); Info.FFDiag(Loc, diag::note_constexpr_past_end, 1) << !Designator.Entries.empty() << !!VD << VD; NoteLValueLocation(Info, Base); @@ -1546,7 +1544,7 @@ // We allow _Atomic(T) to be initialized from anything that T can be // initialized from. - if (const AtomicType *AT = Type->getAs()) + if (const auto *AT = Type->getAs()) Type = AT->getValueType(); // Core issue 1454: For a literal constant expression of array or class type, @@ -1604,7 +1602,7 @@ static bool IsLiteralLValue(const LValue &Value) { if (Value.CallIndex) return false; - const Expr *E = Value.Base.dyn_cast(); + const auto *E = Value.Base.dyn_cast(); return E && !isa(E); } @@ -1635,7 +1633,7 @@ // We have a non-null base. These are generally known to be true, but if it's // a weak declaration it can be null at runtime. Result = true; - const ValueDecl *Decl = Value.getLValueBase().dyn_cast(); + const auto *Decl = Value.getLValueBase().dyn_cast(); return !Decl || !Decl->isWeak(); } @@ -1884,7 +1882,7 @@ shift_left: // C++11 [expr.shift]p1: Shift width must be less than the bit width of // the shifted type. - unsigned SA = (unsigned) RHS.getLimitedValue(LHS.getBitWidth()-1); + auto SA = (unsigned)RHS.getLimitedValue(LHS.getBitWidth() - 1); if (SA != RHS) { Info.CCEDiag(E, diag::note_constexpr_large_shift) << RHS << E->getType() << LHS.getBitWidth(); @@ -1915,7 +1913,7 @@ shift_right: // C++11 [expr.shift]p1: Shift width must be less than the bit width of the // shifted type. - unsigned SA = (unsigned) RHS.getLimitedValue(LHS.getBitWidth()-1); + auto SA = (unsigned)RHS.getLimitedValue(LHS.getBitWidth() - 1); if (SA != RHS) Info.CCEDiag(E, diag::note_constexpr_large_shift) << RHS << E->getType() << LHS.getBitWidth(); @@ -2144,7 +2142,7 @@ APValue *&Result) { // If this is a parameter to an active constexpr function call, perform // argument substitution. - if (const ParmVarDecl *PVD = dyn_cast(VD)) { + if (const auto *PVD = dyn_cast(VD)) { // Assume arguments of a potential constant expression are unknown // constant expressions. if (Info.checkingPotentialConstantExpression()) @@ -2249,7 +2247,7 @@ // FIXME: Support ObjCEncodeExpr, MakeStringConstant if (auto PE = dyn_cast(Lit)) Lit = PE->getFunctionName(); - const StringLiteral *S = cast(Lit); + const auto *S = cast(Lit); const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(S->getType()); assert(CAT && "string literal isn't an array"); @@ -2266,7 +2264,7 @@ // Expand a string literal into an array of characters. static void expandStringLiteral(EvalInfo &Info, const Expr *Lit, APValue &Result) { - const StringLiteral *S = cast(Lit); + const auto *S = cast(Lit); const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(S->getType()); assert(CAT && "string literal isn't an array"); @@ -2754,7 +2752,7 @@ APValue *BaseVal = nullptr; QualType BaseType = getType(LVal.Base); - if (const ValueDecl *D = LVal.Base.dyn_cast()) { + if (const auto *D = LVal.Base.dyn_cast()) { // In C++98, const, non-volatile integers initialized with ICEs are ICEs. // In C++11, constexpr, non-volatile variables initialized with constant // expressions are constant expressions too. Inside constexpr functions, @@ -2762,7 +2760,7 @@ // In C++1y, objects local to a constant expression (those with a Frame) are // both readable and writable inside constant expressions. // In C, such things can also be folded, although they are not ICEs. - const VarDecl *VD = dyn_cast(D); + const auto *VD = dyn_cast(D); if (VD) { if (const VarDecl *VDef = VD->getDefinition(Info.Ctx)) VD = VDef; @@ -2840,11 +2838,10 @@ if (!evaluateVarDeclInit(Info, E, VD, Frame, BaseVal)) return CompleteObject(); } else { - const Expr *Base = LVal.Base.dyn_cast(); + const auto *Base = LVal.Base.dyn_cast(); if (!Frame) { - if (const MaterializeTemporaryExpr *MTE = - dyn_cast(Base)) { + if (const auto *MTE = dyn_cast(Base)) { assert(MTE->getStorageDuration() == SD_Static && "should have a frame for a non-global materialized temporary"); @@ -2862,7 +2859,7 @@ // int x = ++r; // constexpr int k = r; // Therefore we use the C++1y rules in C++11 too. - const ValueDecl *VD = Info.EvaluatingDecl.dyn_cast(); + const auto *VD = Info.EvaluatingDecl.dyn_cast(); const ValueDecl *ED = MTE->getExtendingDecl(); if (!(BaseType.isConstQualified() && BaseType->isIntegralOrEnumerationType()) && @@ -2936,9 +2933,9 @@ return false; // Check for special cases where there is no existing APValue to look at. - const Expr *Base = LVal.Base.dyn_cast(); + const auto *Base = LVal.Base.dyn_cast(); if (Base && !LVal.CallIndex && !Type.isVolatileQualified()) { - if (const CompoundLiteralExpr *CLE = dyn_cast(Base)) { + if (const auto *CLE = dyn_cast(Base)) { // In C99, a CompoundLiteralExpr is an lvalue, and we defer evaluating the // initializer until now for such expressions. Such an expression can't be // an ICE in C, so this only matters for fold. @@ -3056,7 +3053,7 @@ return false; QualType PointeeType; - if (const PointerType *PT = SubobjType->getAs()) + if (const auto *PT = SubobjType->getAs()) PointeeType = PT->getPointeeType(); if (PointeeType.isNull() || !RHS.isInt() || @@ -3214,7 +3211,7 @@ return false; QualType PointeeType; - if (const PointerType *PT = SubobjType->getAs()) + if (const auto *PT = SubobjType->getAs()) PointeeType = PT->getPointeeType(); else { Info.FFDiag(E); @@ -3327,7 +3324,7 @@ MemPtr.Path.size() + IncludeMember); // Walk down to the appropriate base class. - if (const PointerType *PT = LVType->getAs()) + if (const auto *PT = LVType->getAs()) LVType = PT->getPointeeType(); const CXXRecordDecl *RD = LVType->getAsCXXRecordDecl(); assert(RD && "member pointer access on non-class-type expression"); @@ -3346,11 +3343,11 @@ // Add the member. Note that we cannot build bound member functions here. if (IncludeMember) { - if (const FieldDecl *FD = dyn_cast(MemPtr.getDecl())) { + if (const auto *FD = dyn_cast(MemPtr.getDecl())) { if (!HandleLValueMember(Info, RHS, LV, FD)) return nullptr; - } else if (const IndirectFieldDecl *IFD = - dyn_cast(MemPtr.getDecl())) { + } else if (const auto *IFD = + dyn_cast(MemPtr.getDecl())) { if (!HandleLValueIndirectMember(Info, RHS, LV, IFD)) return nullptr; } else { @@ -3388,7 +3385,7 @@ return false; QualType TargetQT = E->getType(); - if (const PointerType *PT = TargetQT->getAs()) + if (const auto *PT = TargetQT->getAs()) TargetQT = PT->getPointeeType(); // Check this cast lands within the final derived-to-base subobject path. @@ -3467,10 +3464,10 @@ static bool EvaluateDecl(EvalInfo &Info, const Decl *D) { bool OK = true; - if (const VarDecl *VD = dyn_cast(D)) + if (const auto *VD = dyn_cast(D)) OK &= EvaluateVarDecl(Info, VD); - if (const DecompositionDecl *DD = dyn_cast(D)) + if (const auto *DD = dyn_cast(D)) for (auto *BD : DD->bindings()) if (auto *VD = BD->getHoldingVar()) OK &= EvaluateDecl(Info, VD); @@ -3553,7 +3550,7 @@ continue; } - const CaseStmt *CS = cast(SC); + const auto *CS = cast(SC); APSInt LHS = CS->getLHS()->EvaluateKnownConstInt(Info.Ctx); APSInt RHS = CS->getRHS() ? CS->getRHS()->EvaluateKnownConstInt(Info.Ctx) : LHS; @@ -3616,7 +3613,7 @@ case Stmt::IfStmtClass: { // FIXME: Precompute which side of an 'if' we would jump to, and go // straight there rather than scanning both sides. - const IfStmt *IS = cast(S); + const auto *IS = cast(S); // Wrap the evaluation in a block scope, in case it's a DeclStmt // preceded by our switch label. @@ -3637,7 +3634,7 @@ } case Stmt::ForStmtClass: { - const ForStmt *FS = cast(S); + const auto *FS = cast(S); EvalStmtResult ESR = EvaluateLoopBody(Result, Info, FS->getBody(), Case); if (ESR != ESR_Continue) @@ -3660,7 +3657,7 @@ switch (S->getStmtClass()) { default: - if (const Expr *E = dyn_cast(S)) { + if (const auto *E = dyn_cast(S)) { // Don't bother evaluating beyond an expression-statement which couldn't // be evaluated. FullExpressionRAII Scope(Info); @@ -3676,7 +3673,7 @@ return ESR_Succeeded; case Stmt::DeclStmtClass: { - const DeclStmt *DS = cast(S); + const auto *DS = cast(S); for (const auto *DclIt : DS->decls()) { // Each declaration initialization is its own full-expression. // FIXME: This isn't quite right; if we're performing aggregate @@ -3702,7 +3699,7 @@ case Stmt::CompoundStmtClass: { BlockScopeRAII Scope(Info); - const CompoundStmt *CS = cast(S); + const auto *CS = cast(S); for (const auto *BI : CS->body()) { EvalStmtResult ESR = EvaluateStmt(Result, Info, BI, Case); if (ESR == ESR_Succeeded) @@ -3714,7 +3711,7 @@ } case Stmt::IfStmtClass: { - const IfStmt *IS = cast(S); + const auto *IS = cast(S); // Evaluate the condition, as either a var decl or as an expression. BlockScopeRAII Scope(Info); @@ -3736,7 +3733,7 @@ } case Stmt::WhileStmtClass: { - const WhileStmt *WS = cast(S); + const auto *WS = cast(S); while (true) { BlockScopeRAII Scope(Info); bool Continue; @@ -3754,7 +3751,7 @@ } case Stmt::DoStmtClass: { - const DoStmt *DS = cast(S); + const auto *DS = cast(S); bool Continue; do { EvalStmtResult ESR = EvaluateLoopBody(Result, Info, DS->getBody(), Case); @@ -3770,7 +3767,7 @@ } case Stmt::ForStmtClass: { - const ForStmt *FS = cast(S); + const auto *FS = cast(S); BlockScopeRAII Scope(Info); if (FS->getInit()) { EvalStmtResult ESR = EvaluateStmt(Result, Info, FS->getInit()); @@ -3800,7 +3797,7 @@ } case Stmt::CXXForRangeStmtClass: { - const CXXForRangeStmt *FS = cast(S); + const auto *FS = cast(S); BlockScopeRAII Scope(Info); // Initialize the __range variable. @@ -4005,7 +4002,7 @@ // // Skip this for non-union classes with no fields; in that case, the defaulted // copy/move does not actually read the object. - const CXXMethodDecl *MD = dyn_cast(Callee); + const auto *MD = dyn_cast(Callee); if (MD && MD->isDefaulted() && (MD->getParent()->isUnion() || (MD->isTrivial() && hasFields(MD->getParent())))) { @@ -4135,7 +4132,7 @@ // and make sure we've initialized every step along it. for (auto *C : IFD->chain()) { FD = cast(C); - CXXRecordDecl *CD = cast(FD->getParent()); + auto *CD = cast(FD->getParent()); // Switch the union field if it differs. This happens if we had // preceding zero-initialization, and we're now initializing a union // subobject other than the first. @@ -4404,14 +4401,14 @@ // Extract function decl and 'this' pointer from the callee. if (CalleeType->isSpecificBuiltinType(BuiltinType::BoundMember)) { const ValueDecl *Member = nullptr; - if (const MemberExpr *ME = dyn_cast(Callee)) { + if (const auto *ME = dyn_cast(Callee)) { // Explicit bound member calls, such as x.f() or p->g(); if (!EvaluateObjectArgument(Info, ME->getBase(), ThisVal)) return false; Member = ME->getMemberDecl(); This = &ThisVal; HasQualifier = ME->hasQualifier(); - } else if (const BinaryOperator *BE = dyn_cast(Callee)) { + } else if (const auto *BE = dyn_cast(Callee)) { // Indirect bound member calls ('.*' or '->*'). Member = HandleMemberPointerAccess(Info, BE, ThisVal, false); if (!Member) return false; @@ -4436,7 +4433,7 @@ // Overloaded operator calls to member functions are represented as normal // calls with '*this' as the first argument. - const CXXMethodDecl *MD = dyn_cast(FD); + const auto *MD = dyn_cast(FD); if (MD && !MD->isStatic()) { // FIXME: When selecting an implicit conversion for an overloaded // operator delete, we sometimes try to evaluate calls to conversion @@ -4686,7 +4683,7 @@ (void)BaseTy; if (!HandleLValueMember(this->Info, E, Result, FD)) return false; - } else if (const IndirectFieldDecl *IFD = dyn_cast(MD)) { + } else if (const auto *IFD = dyn_cast(MD)) { if (!HandleLValueIndirectMember(this->Info, E, Result, IFD)) return false; } else @@ -4828,11 +4825,11 @@ } bool LValueExprEvaluator::VisitDeclRefExpr(const DeclRefExpr *E) { - if (const FunctionDecl *FD = dyn_cast(E->getDecl())) + if (const auto *FD = dyn_cast(E->getDecl())) return Success(FD); - if (const VarDecl *VD = dyn_cast(E->getDecl())) + if (const auto *VD = dyn_cast(E->getDecl())) return VisitVarDecl(E, VD); - if (const BindingDecl *BD = dyn_cast(E->getDecl())) + if (const auto *BD = dyn_cast(E->getDecl())) return Visit(BD->getBinding()); return Error(E); } @@ -5276,7 +5273,7 @@ // C++ [expr.alignof]p3: // When alignof is applied to a reference type, the result is the // alignment of the referenced type. - if (const ReferenceType *Ref = T->getAs()) + if (const auto *Ref = T->getAs()) T = Ref->getPointeeType(); // __alignof is defined to return the preferred alignment. @@ -5293,11 +5290,11 @@ // alignof decl is always accepted, even if it doesn't make sense: we default // to 1 in those cases. - if (const DeclRefExpr *DRE = dyn_cast(E)) + if (const auto *DRE = dyn_cast(E)) return Info.Ctx.getDeclAlign(DRE->getDecl(), /*RefAsPointee*/true); - if (const MemberExpr *ME = dyn_cast(E)) + if (const auto *ME = dyn_cast(E)) return Info.Ctx.getDeclAlign(ME->getMemberDecl(), /*RefAsPointee*/true); @@ -5344,8 +5341,7 @@ // If there is a base object, then it must have the correct alignment. if (OffsetResult.Base) { CharUnits BaseAlignment; - if (const ValueDecl *VD = - OffsetResult.Base.dyn_cast()) { + if (const auto *VD = OffsetResult.Base.dyn_cast()) { BaseAlignment = Info.Ctx.getDeclAlign(VD); } else { BaseAlignment = @@ -5405,7 +5401,7 @@ APSInt Desired; if (!EvaluateInteger(E->getArg(1), Desired, Info)) return false; - uint64_t MaxLength = uint64_t(-1); + auto MaxLength = uint64_t(-1); if (BuiltinOp != Builtin::BIstrchr && BuiltinOp != Builtin::BIwcschr && BuiltinOp != Builtin::BI__builtin_strchr && @@ -5610,7 +5606,7 @@ const RecordDecl *RD, const LValue &This, APValue &Result) { assert(!RD->isUnion() && "Expected non-union class type"); - const CXXRecordDecl *CD = dyn_cast(RD); + const auto *CD = dyn_cast(RD); Result = APValue(APValue::UninitStruct(), CD ? CD->getNumBases() : 0, std::distance(RD->field_begin(), RD->field_end())); @@ -5840,8 +5836,7 @@ // Avoid materializing a temporary for an elidable copy/move constructor. if (E->isElidable() && !ZeroInit) - if (const MaterializeTemporaryExpr *ME - = dyn_cast(E->getArg(0))) + if (const auto *ME = dyn_cast(E->getArg(0))) return Visit(ME->GetTemporaryExpr()); if (ZeroInit && !ZeroInitialization(E, T)) @@ -6028,7 +6023,7 @@ } bool VectorExprEvaluator::VisitCastExpr(const CastExpr *E) { - const VectorType *VTy = E->getType()->castAs(); + const auto *VTy = E->getType()->castAs(); unsigned NElts = VTy->getNumElements(); const Expr *SE = E->getSubExpr(); @@ -6099,7 +6094,7 @@ bool VectorExprEvaluator::VisitInitListExpr(const InitListExpr *E) { - const VectorType *VT = E->getType()->castAs(); + const auto *VT = E->getType()->castAs(); unsigned NumInits = E->getNumInits(); unsigned NumElements = VT->getNumElements(); @@ -6148,7 +6143,7 @@ bool VectorExprEvaluator::ZeroInitialization(const Expr *E) { - const VectorType *VT = E->getType()->getAs(); + const auto *VT = E->getType()->getAs(); QualType EltTy = VT->getElementType(); APValue ZeroElement; if (EltTy->isIntegerType()) @@ -6548,7 +6543,7 @@ /// try. bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) { // Enums are integer constant exprs. - if (const EnumConstantDecl *ECD = dyn_cast(D)) { + if (const auto *ECD = dyn_cast(D)) { // Check for signedness/width mismatches between E type and ECD value. bool SameSign = (ECD->getInitVal().isSigned() == E->getType()->isSignedIntegerOrEnumerationType()); @@ -6594,7 +6589,7 @@ return no_type_class; QualType CanTy = E->getArg(0)->getType().getCanonicalType(); - const BuiltinType *BT = dyn_cast(CanTy); + const auto *BT = dyn_cast(CanTy); switch (CanTy->getTypeClass()) { #define TYPE(ID, BASE) @@ -6719,7 +6714,7 @@ /// character of a string literal. template static bool EvaluateBuiltinConstantPForLValue(const LValue &LV) { - const Expr *E = LV.getLValueBase().template dyn_cast(); + const auto *E = LV.getLValueBase().template dyn_cast(); return E && isa(E) && LV.getLValueOffset().isZero(); } @@ -6770,10 +6765,10 @@ /// Retrieves the "underlying object type" of the given expression, /// as used by __builtin_object_size. static QualType getObjectType(APValue::LValueBase B) { - if (const ValueDecl *D = B.dyn_cast()) { - if (const VarDecl *VD = dyn_cast(D)) + if (const auto *D = B.dyn_cast()) { + if (const auto *VD = dyn_cast(D)) return VD->getType(); - } else if (const Expr *E = B.get()) { + } else if (const auto *E = B.get()) { if (isa(E)) return E->getType(); } @@ -7246,7 +7241,7 @@ QualType CharTy = E->getArg(0)->getType()->getPointeeType(); // Fast path: if it's a string literal, search the string value. - if (const StringLiteral *S = dyn_cast_or_null( + if (const auto *S = dyn_cast_or_null( String.getLValueBase().dyn_cast())) { // The string literal may have embedded null characters. Find the first // one and truncate there. @@ -7308,7 +7303,7 @@ QualType CharTy = E->getArg(0)->getType()->getPointeeType(); - uint64_t MaxLength = uint64_t(-1); + auto MaxLength = uint64_t(-1); if (BuiltinOp != Builtin::BIstrcmp && BuiltinOp != Builtin::BIwcscmp && BuiltinOp != Builtin::BI__builtin_strcmp && @@ -7664,12 +7659,12 @@ if (!LHSVal.getLValueOffset().isZero() || !RHSVal.getLValueOffset().isZero()) return false; - const Expr *LHSExpr = LHSVal.getLValueBase().dyn_cast(); - const Expr *RHSExpr = RHSVal.getLValueBase().dyn_cast(); + const auto *LHSExpr = LHSVal.getLValueBase().dyn_cast(); + const auto *RHSExpr = RHSVal.getLValueBase().dyn_cast(); if (!LHSExpr || !RHSExpr) return false; - const AddrLabelExpr *LHSAddrExpr = dyn_cast(LHSExpr); - const AddrLabelExpr *RHSAddrExpr = dyn_cast(RHSExpr); + const auto *LHSAddrExpr = dyn_cast(LHSExpr); + const auto *RHSAddrExpr = dyn_cast(RHSExpr); if (!LHSAddrExpr || !RHSAddrExpr) return false; // Make sure both labels come from the same function. @@ -7700,7 +7695,7 @@ switch (job.Kind) { case Job::AnyExprKind: { - if (const BinaryOperator *Bop = dyn_cast(job.E)) { + if (const auto *Bop = dyn_cast(job.E)) { if (shouldEnqueue(Bop)) { job.Kind = Job::BinOpKind; enqueue(Bop->getLHS()); @@ -7714,7 +7709,7 @@ } case Job::BinOpKind: { - const BinaryOperator *Bop = cast(job.E); + const auto *Bop = cast(job.E); bool SuppressRHSDiags = false; if (!VisitBinOpLHSOnly(Result, Bop, SuppressRHSDiags)) { Queue.pop_back(); @@ -7729,7 +7724,7 @@ } case Job::BinOpVisitedLHSKind: { - const BinaryOperator *Bop = cast(job.E); + const auto *Bop = cast(job.E); EvalResult RHS; RHS.swap(Result); Result.Failed = !VisitBinOp(job.LHSResult, RHS, Bop, Result.Val); @@ -7886,12 +7881,12 @@ // Handle &&A - &&B. if (!LHSValue.Offset.isZero() || !RHSValue.Offset.isZero()) return Error(E); - const Expr *LHSExpr = LHSValue.Base.dyn_cast(); - const Expr *RHSExpr = RHSValue.Base.dyn_cast(); + const auto *LHSExpr = LHSValue.Base.dyn_cast(); + const auto *RHSExpr = RHSValue.Base.dyn_cast(); if (!LHSExpr || !RHSExpr) return Error(E); - const AddrLabelExpr *LHSAddrExpr = dyn_cast(LHSExpr); - const AddrLabelExpr *RHSAddrExpr = dyn_cast(RHSExpr); + const auto *LHSAddrExpr = dyn_cast(LHSExpr); + const auto *RHSAddrExpr = dyn_cast(RHSExpr); if (!LHSAddrExpr || !RHSAddrExpr) return Error(E); // Make sure both labels come from the same function. @@ -8106,10 +8101,10 @@ // Otherwise if either is a pointer to a virtual member function, the // result is unspecified. - if (const CXXMethodDecl *MD = dyn_cast(LHSValue.getDecl())) + if (const auto *MD = dyn_cast(LHSValue.getDecl())) if (MD->isVirtual()) CCEDiag(E, diag::note_constexpr_compare_virtual_mem_ptr) << MD; - if (const CXXMethodDecl *MD = dyn_cast(RHSValue.getDecl())) + if (const auto *MD = dyn_cast(RHSValue.getDecl())) if (MD->isVirtual()) CCEDiag(E, diag::note_constexpr_compare_virtual_mem_ptr) << MD; @@ -8170,7 +8165,7 @@ QualType SrcTy = E->getTypeOfArgument(); // C++ [expr.sizeof]p2: "When applied to a reference or a reference type, // the result is the size of the referenced type." - if (const ReferenceType *Ref = SrcTy->getAs()) + if (const auto *Ref = SrcTy->getAs()) SrcTy = Ref->getPointeeType(); CharUnits Sizeof; @@ -8527,7 +8522,7 @@ const Expr *Arg, bool SNaN, llvm::APFloat &Result) { - const StringLiteral *S = dyn_cast(Arg->IgnoreParenCasts()); + const auto *S = dyn_cast(Arg->IgnoreParenCasts()); if (!S) return false; const llvm::fltSemantics &Sem = Context.getFloatTypeSemantics(ResultTy); @@ -9407,7 +9402,7 @@ const ASTContext &Ctx, bool &IsConst) { // Fast-path evaluations of integer literals, since we sometimes see files // containing vast quantities of these. - if (const IntegerLiteral *L = dyn_cast(Exp)) { + if (const auto *L = dyn_cast(Exp)) { Result.Val = APValue(APSInt(L->getValue(), L->getType()->isUnsignedIntegerType())); IsConst = true; @@ -9754,7 +9749,7 @@ // C99 6.6/3 allows function calls within unevaluated subexpressions of // constant expressions, but they can never be ICEs because an ICE cannot // contain an operand of (pointer to) function type. - const CallExpr *CE = cast(E); + const auto *CE = cast(E); if (CE->getBuiltinCallee()) return CheckEvalInICE(E, Ctx); return ICEDiag(IK_NotICE, E->getLocStart()); @@ -9762,7 +9757,7 @@ case Expr::DeclRefExprClass: { if (isa(cast(E)->getDecl())) return NoDiag(); - const ValueDecl *D = dyn_cast(cast(E)->getDecl()); + const auto *D = dyn_cast(cast(E)->getDecl()); if (Ctx.getLangOpts().CPlusPlus && D && IsConstNonVolatile(D->getType())) { // Parameter variables are never constants. Without this check, @@ -9774,7 +9769,7 @@ // C++ 7.1.5.1p2 // A variable of non-volatile const-qualified integral or enumeration // type initialized by an ICE can be used in ICEs. - if (const VarDecl *Dcl = dyn_cast(D)) { + if (const auto *Dcl = dyn_cast(D)) { if (!Dcl->getType()->isIntegralOrEnumerationType()) return ICEDiag(IK_NotICE, cast(E)->getLocation()); @@ -9790,7 +9785,7 @@ return ICEDiag(IK_NotICE, E->getLocStart()); } case Expr::UnaryOperatorClass: { - const UnaryOperator *Exp = cast(E); + const auto *Exp = cast(E); switch (Exp->getOpcode()) { case UO_PostInc: case UO_PostDec: @@ -9825,14 +9820,14 @@ return CheckEvalInICE(E, Ctx); } case Expr::UnaryExprOrTypeTraitExprClass: { - const UnaryExprOrTypeTraitExpr *Exp = cast(E); + const auto *Exp = cast(E); if ((Exp->getKind() == UETT_SizeOf) && Exp->getTypeOfArgument()->isVariableArrayType()) return ICEDiag(IK_NotICE, E->getLocStart()); return NoDiag(); } case Expr::BinaryOperatorClass: { - const BinaryOperator *Exp = cast(E); + const auto *Exp = cast(E); switch (Exp->getOpcode()) { case BO_PtrMemD: case BO_PtrMemI: @@ -9926,8 +9921,8 @@ case Expr::ObjCBridgedCastExprClass: { const Expr *SubExpr = cast(E)->getSubExpr(); if (isa(E)) { - if (const FloatingLiteral *FL - = dyn_cast(SubExpr->IgnoreParenImpCasts())) { + if (const auto *FL = + dyn_cast(SubExpr->IgnoreParenImpCasts())) { unsigned DestWidth = Ctx.getIntWidth(E->getType()); bool DestSigned = E->getType()->isSignedIntegerOrEnumerationType(); APSInt IgnoredVal(DestWidth, !DestSigned); @@ -9955,7 +9950,7 @@ } } case Expr::BinaryConditionalOperatorClass: { - const BinaryConditionalOperator *Exp = cast(E); + const auto *Exp = cast(E); ICEDiag CommonResult = CheckICE(Exp->getCommon(), Ctx); if (CommonResult.Kind == IK_NotICE) return CommonResult; ICEDiag FalseResult = CheckICE(Exp->getFalseExpr(), Ctx); @@ -9966,7 +9961,7 @@ return FalseResult; } case Expr::ConditionalOperatorClass: { - const ConditionalOperator *Exp = cast(E); + const auto *Exp = cast(E); // If the condition (ignoring parens) is a __builtin_constant_p call, // then only the true side is actually considered in an integer constant // expression, and it is fully evaluated. This is an important GNU @@ -10129,7 +10124,7 @@ EvalInfo Info(FD->getASTContext(), Status, EvalInfo::EM_PotentialConstantExpression); - const CXXMethodDecl *MD = dyn_cast(FD); + const auto *MD = dyn_cast(FD); const CXXRecordDecl *RD = MD ? MD->getParent()->getCanonicalDecl() : nullptr; // Fabricate an arbitrary expression on the stack and pretend that it @@ -10141,7 +10136,7 @@ ArrayRef Args; APValue Scratch; - if (const CXXConstructorDecl *CD = dyn_cast(FD)) { + if (const auto *CD = dyn_cast(FD)) { // Evaluate the call as a constant initializer, to allow the construction // of objects of non-literal types. Info.setEvaluatingDecl(This.getLValueBase(), Scratch); Index: lib/AST/ExprObjC.cpp =================================================================== --- lib/AST/ExprObjC.cpp +++ lib/AST/ExprObjC.cpp @@ -58,7 +58,7 @@ false, false), NumElements(VK.size()), HasPackExpansions(HasPackExpansions), Range(SR), DictWithObjectsMethod(method) { - KeyValuePair *KeyValues = getTrailingObjects(); + auto *KeyValues = getTrailingObjects(); ExpansionData *Expansions = HasPackExpansions ? getTrailingObjects() : nullptr; for (unsigned I = 0; I < NumElements; I++) { @@ -327,10 +327,10 @@ ObjCInterfaceDecl *ObjCMessageExpr::getReceiverInterface() const { QualType T = getReceiverType(); - if (const ObjCObjectPointerType *Ptr = T->getAs()) + if (const auto *Ptr = T->getAs()) return Ptr->getInterfaceDecl(); - if (const ObjCObjectType *Ty = T->getAs()) + if (const auto *Ty = T->getAs()) return Ty->getInterface(); return nullptr; Index: lib/AST/InheritViz.cpp =================================================================== --- lib/AST/InheritViz.cpp +++ lib/AST/InheritViz.cpp @@ -91,8 +91,8 @@ Out << " \"];\n"; // Display the base classes. - const CXXRecordDecl *Decl - = static_cast(Type->getAs()->getDecl()); + const auto *Decl = + static_cast(Type->getAs()->getDecl()); for (const auto &Base : Decl->bases()) { QualType CanonBaseType = Context.getCanonicalType(Base.getType()); Index: lib/AST/ItaniumCXXABI.cpp =================================================================== --- lib/AST/ItaniumCXXABI.cpp +++ lib/AST/ItaniumCXXABI.cpp @@ -59,8 +59,7 @@ public: unsigned getManglingNumber(const CXXMethodDecl *CallOperator) override { - const FunctionProtoType *Proto = - CallOperator->getType()->getAs(); + const auto *Proto = CallOperator->getType()->getAs(); ASTContext &Context = CallOperator->getASTContext(); FunctionProtoType::ExtProtoInfo EPI; Index: lib/AST/ItaniumMangle.cpp =================================================================== --- lib/AST/ItaniumMangle.cpp +++ lib/AST/ItaniumMangle.cpp @@ -52,17 +52,17 @@ // not the case: the lambda closure type ends up living in the context // where the function itself resides, because the function declaration itself // had not yet been created. Fix the context here. - if (const CXXRecordDecl *RD = dyn_cast(D)) { + if (const auto *RD = dyn_cast(D)) { if (RD->isLambda()) - if (ParmVarDecl *ContextParam - = dyn_cast_or_null(RD->getLambdaContextDecl())) + if (auto *ContextParam = + dyn_cast_or_null(RD->getLambdaContextDecl())) return ContextParam->getDeclContext(); } // Perform the same check for block literals. - if (const BlockDecl *BD = dyn_cast(D)) { - if (ParmVarDecl *ContextParam - = dyn_cast_or_null(BD->getBlockManglingContextDecl())) + if (const auto *BD = dyn_cast(D)) { + if (auto *ContextParam = + dyn_cast_or_null(BD->getBlockManglingContextDecl())) return ContextParam->getDeclContext(); } @@ -109,12 +109,12 @@ } static const NamedDecl *getStructor(const NamedDecl *decl) { - const FunctionDecl *fn = dyn_cast_or_null(decl); + const auto *fn = dyn_cast_or_null(decl); return (fn ? getStructor(fn) : decl); } static bool isLambda(const NamedDecl *ND) { - const CXXRecordDecl *Record = dyn_cast(ND); + const auto *Record = dyn_cast(ND); if (!Record) return false; @@ -182,7 +182,7 @@ return false; // Anonymous tags are already numbered. - if (const TagDecl *Tag = dyn_cast(ND)) { + if (const auto *Tag = dyn_cast(ND)) { if (Tag->getName().empty() && !Tag->getTypedefNameForAnonDecl()) return false; } @@ -576,7 +576,7 @@ } bool ItaniumMangleContextImpl::shouldMangleCXXName(const NamedDecl *D) { - const FunctionDecl *FD = dyn_cast(D); + const auto *FD = dyn_cast(D); if (FD) { LanguageLinkage L = FD->getLanguageLinkage(); // Overloadable functions need mangling. @@ -601,7 +601,7 @@ if (!getASTContext().getLangOpts().CPlusPlus) return false; - const VarDecl *VD = dyn_cast(D); + const auto *VD = dyn_cast(D); if (VD && !isa(D)) { // C variables are not mangled. if (VD->isExternC()) @@ -639,11 +639,11 @@ // ::= // ::= Out << "_Z"; - if (const FunctionDecl *FD = dyn_cast(D)) + if (const auto *FD = dyn_cast(D)) mangleFunctionEncoding(FD); - else if (const VarDecl *VD = dyn_cast(D)) + else if (const auto *VD = dyn_cast(D)) mangleName(VD); - else if (const IndirectFieldDecl *IFD = dyn_cast(D)) + else if (const auto *IFD = dyn_cast(D)) mangleName(IFD->getAnonField()); else mangleName(cast(D)); @@ -709,7 +709,7 @@ for (AttrVec::const_reverse_iterator I = FD->getAttrs().rbegin(), E = FD->getAttrs().rend(); I != E; ++I) { - EnableIfAttr *EIA = dyn_cast(*I); + auto *EIA = dyn_cast(*I); if (!EIA) continue; Out << 'X'; @@ -786,7 +786,7 @@ static const TemplateDecl * isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs) { // Check if we have a function template. - if (const FunctionDecl *FD = dyn_cast(ND)) { + if (const auto *FD = dyn_cast(ND)) { if (const TemplateDecl *TD = FD->getPrimaryTemplate()) { TemplateArgs = FD->getTemplateSpecializationArgs(); return TD; @@ -794,15 +794,13 @@ } // Check if we have a class template. - if (const ClassTemplateSpecializationDecl *Spec = - dyn_cast(ND)) { + if (const auto *Spec = dyn_cast(ND)) { TemplateArgs = &Spec->getTemplateArgs(); return Spec->getSpecializedTemplate(); } // Check if we have a variable template. - if (const VarTemplateSpecializationDecl *Spec = - dyn_cast(ND)) { + if (const auto *Spec = dyn_cast(ND)) { TemplateArgs = &Spec->getTemplateArgs(); return Spec->getSpecializedTemplate(); } @@ -811,7 +809,7 @@ } void CXXNameMangler::mangleName(const NamedDecl *ND) { - if (const VarDecl *VD = dyn_cast(ND)) { + if (const auto *VD = dyn_cast(ND)) { // Variables should have implicit tags from its type. AbiTagList VariableTypeAbiTags = makeVariableTypeTags(VD); if (VariableTypeAbiTags.empty()) { @@ -1258,7 +1256,7 @@ // Otherwise, an anonymous entity. We must have a declaration. assert(ND && "mangling empty name without declaration"); - if (const NamespaceDecl *NS = dyn_cast(ND)) { + if (const auto *NS = dyn_cast(ND)) { if (NS->isAnonymousNamespace()) { // This is how gcc mangles these names. Out << "12_GLOBAL__N_1"; @@ -1266,7 +1264,7 @@ } } - if (const VarDecl *VD = dyn_cast(ND)) { + if (const auto *VD = dyn_cast(ND)) { // We must have an anonymous union or struct declaration. const RecordDecl *RD = cast(VD->getType()->getAs()->getDecl()); @@ -1305,7 +1303,7 @@ break; // We must have an anonymous struct. - const TagDecl *TD = cast(ND); + const auto *TD = cast(ND); if (const TypedefNameDecl *D = TD->getTypedefNameForAnonDecl()) { assert(TD->getDeclContext() == D->getDeclContext() && "Typedef should not be in another decl context!"); @@ -1323,7 +1321,7 @@ // // ::= Ul E [ ] _ // ::= + # Parameter types or 'v' for 'void'. - if (const CXXRecordDecl *Record = dyn_cast(TD)) { + if (const auto *Record = dyn_cast(TD)) { if (Record->isLambda() && Record->getLambdaManglingNumber()) { assert(!AdditionalAbiTags && "Lambda type cannot have additional abi tags"); @@ -1449,7 +1447,7 @@ // E Out << 'N'; - if (const CXXMethodDecl *Method = dyn_cast(ND)) { + if (const auto *Method = dyn_cast(ND)) { Qualifiers MethodQuals = Qualifiers::fromCVRMask(Method->getTypeQualifiers()); // We do not consider restrict a distinguishing attribute for overloading @@ -1501,9 +1499,9 @@ { AbiTagState LocalAbiTags(AbiTags); - if (const ObjCMethodDecl *MD = dyn_cast(DC)) + if (const auto *MD = dyn_cast(DC)) mangleObjCMethodName(MD); - else if (const BlockDecl *BD = dyn_cast(DC)) + else if (const auto *BD = dyn_cast(DC)) mangleBlockForPrefix(BD); else mangleFunctionEncoding(cast(DC)); @@ -1524,12 +1522,11 @@ // will of course contain a : Its // numbering will be local to the particular argument in which it appears // -- other default arguments do not affect its encoding. - const CXXRecordDecl *CXXRD = dyn_cast(RD); + const auto *CXXRD = dyn_cast(RD); if (CXXRD && CXXRD->isLambda()) { if (const ParmVarDecl *Parm = dyn_cast_or_null(CXXRD->getLambdaContextDecl())) { - if (const FunctionDecl *Func - = dyn_cast(Parm->getDeclContext())) { + if (const auto *Func = dyn_cast(Parm->getDeclContext())) { Out << 'd'; unsigned Num = Func->getNumParams() - Parm->getFunctionScopeIndex(); if (Num > 1) @@ -1543,22 +1540,21 @@ // equality ok because RD derived from ND above if (D == RD) { mangleUnqualifiedName(RD, AdditionalAbiTags); - } else if (const BlockDecl *BD = dyn_cast(D)) { + } else if (const auto *BD = dyn_cast(D)) { manglePrefix(getEffectiveDeclContext(BD), true /*NoFunction*/); assert(!AdditionalAbiTags && "Block cannot have additional abi tags"); mangleUnqualifiedBlock(BD); } else { - const NamedDecl *ND = cast(D); + const auto *ND = cast(D); mangleNestedName(ND, getEffectiveDeclContext(ND), AdditionalAbiTags, true /*NoFunction*/); } - } else if (const BlockDecl *BD = dyn_cast(D)) { + } else if (const auto *BD = dyn_cast(D)) { // Mangle a block in a default parameter; see above explanation for // lambdas. if (const ParmVarDecl *Parm = dyn_cast_or_null(BD->getBlockManglingContextDecl())) { - if (const FunctionDecl *Func - = dyn_cast(Parm->getDeclContext())) { + if (const auto *Func = dyn_cast(Parm->getDeclContext())) { Out << 'd'; unsigned Num = Func->getNumParams() - Parm->getFunctionScopeIndex(); if (Num > 1) @@ -1573,7 +1569,7 @@ mangleUnqualifiedName(cast(D), AdditionalAbiTags); } - if (const NamedDecl *ND = dyn_cast(RD ? RD : D)) { + if (const auto *ND = dyn_cast(RD ? RD : D)) { unsigned disc; if (Context.getNextDiscriminator(ND, disc)) { if (disc < 10) @@ -1644,8 +1640,8 @@ } Out << "Ul"; - const FunctionProtoType *Proto = Lambda->getLambdaTypeInfo()->getType()-> - getAs(); + const auto *Proto = + Lambda->getLambdaTypeInfo()->getType()->getAs(); mangleBareFunctionType(Proto, /*MangleReturnType=*/false, Lambda->getLambdaStaticInvoker()); Out << "E"; @@ -1714,7 +1710,7 @@ assert(!isLocalContainerContext(DC)); - const NamedDecl *ND = cast(DC); + const auto *ND = cast(DC); if (mangleSubstitution(ND)) return; @@ -1924,8 +1920,7 @@ break; case Type::TemplateSpecialization: { - const TemplateSpecializationType *TST = - cast(Ty); + const auto *TST = cast(Ty); TemplateName TN = TST->getTemplateName(); switch (TN.getKind()) { case TemplateName::Template: @@ -1977,8 +1972,7 @@ break; case Type::DependentTemplateSpecialization: { - const DependentTemplateSpecializationType *DTST = - cast(Ty); + const auto *DTST = cast(Ty); mangleSourceName(DTST->getIdentifier()); mangleTemplateArgs(DTST->getArgs(), DTST->getNumArgs()); break; @@ -2285,8 +2279,7 @@ do { // Don't desugar through template specialization types that aren't // type aliases. We need to mangle the template arguments as written. - if (const TemplateSpecializationType *TST - = dyn_cast(T)) + if (const auto *TST = dyn_cast(T)) if (!TST->isTypeAlias()) break; @@ -2739,7 +2732,7 @@ Out << 'M'; mangleType(QualType(T->getClass(), 0)); QualType PointeeType = T->getPointeeType(); - if (const FunctionProtoType *FPT = dyn_cast(PointeeType)) { + if (const auto *FPT = dyn_cast(PointeeType)) { mangleType(FPT); // Itanium C++ ABI 5.1.8: @@ -3228,7 +3221,7 @@ if (callee == fn) return false; // Must be an unresolved lookup. - const UnresolvedLookupExpr *lookup = dyn_cast(fn); + const auto *lookup = dyn_cast(fn); if (!lookup) return false; assert(!lookup->requiresADL()); @@ -3247,7 +3240,7 @@ } void CXXNameMangler::mangleCastExpression(const Expr *E, StringRef CastEncoding) { - const ExplicitCastExpr *ECE = cast(E); + const auto *ECE = cast(E); Out << CastEncoding; mangleType(ECE->getType()); mangleExpression(ECE->getSubExpr()); @@ -3360,7 +3353,7 @@ } case Expr::CXXUuidofExprClass: { - const CXXUuidofExpr *UE = cast(E); + const auto *UE = cast(E); if (UE->isTypeOperand()) { QualType UuidT = UE->getTypeOperand(Context.getASTContext()); Out << "u8__uuidoft"; @@ -3417,7 +3410,7 @@ // operator. case Expr::CXXMemberCallExprClass: // fallthrough case Expr::CallExprClass: { - const CallExpr *CE = cast(E); + const auto *CE = cast(E); // ::= cp * E // We use this mangling only when the call would use ADL except @@ -3447,7 +3440,7 @@ } case Expr::CXXNewExprClass: { - const CXXNewExpr *New = cast(E); + const auto *New = cast(E); if (New->isGlobalNew()) Out << "gs"; Out << (New->isArray() ? "na" : "nw"); for (CXXNewExpr::const_arg_iterator I = New->placement_arg_begin(), @@ -3461,13 +3454,13 @@ else Out << "pi"; const Expr *Init = New->getInitializer(); - if (const CXXConstructExpr *CCE = dyn_cast(Init)) { + if (const auto *CCE = dyn_cast(Init)) { // Directly inline the initializers. for (CXXConstructExpr::const_arg_iterator I = CCE->arg_begin(), E = CCE->arg_end(); I != E; ++I) mangleExpression(*I); - } else if (const ParenListExpr *PLE = dyn_cast(Init)) { + } else if (const auto *PLE = dyn_cast(Init)) { for (unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i) mangleExpression(PLE->getExpr(i)); } else if (New->getInitializationStyle() == CXXNewExpr::ListInit && @@ -3509,7 +3502,7 @@ } case Expr::MemberExprClass: { - const MemberExpr *ME = cast(E); + const auto *ME = cast(E); mangleMemberExpr(ME->getBase(), ME->isArrow(), ME->getQualifier(), nullptr, ME->getMemberDecl()->getDeclName(), @@ -3519,7 +3512,7 @@ } case Expr::UnresolvedMemberExprClass: { - const UnresolvedMemberExpr *ME = cast(E); + const auto *ME = cast(E); mangleMemberExpr(ME->isImplicitAccess() ? nullptr : ME->getBase(), ME->isArrow(), ME->getQualifier(), nullptr, ME->getMemberName(), @@ -3529,8 +3522,7 @@ } case Expr::CXXDependentScopeMemberExprClass: { - const CXXDependentScopeMemberExpr *ME - = cast(E); + const auto *ME = cast(E); mangleMemberExpr(ME->isImplicitAccess() ? nullptr : ME->getBase(), ME->isArrow(), ME->getQualifier(), ME->getFirstQualifierFoundInScope(), @@ -3541,7 +3533,7 @@ } case Expr::UnresolvedLookupExprClass: { - const UnresolvedLookupExpr *ULE = cast(E); + const auto *ULE = cast(E); mangleUnresolvedName(ULE->getQualifier(), ULE->getName(), ULE->getTemplateArgs(), ULE->getNumTemplateArgs(), Arity); @@ -3549,7 +3541,7 @@ } case Expr::CXXUnresolvedConstructExprClass: { - const CXXUnresolvedConstructExpr *CE = cast(E); + const auto *CE = cast(E); unsigned N = CE->arg_size(); Out << "cv"; @@ -3617,8 +3609,8 @@ break; case Expr::UnaryExprOrTypeTraitExprClass: { - const UnaryExprOrTypeTraitExpr *SAE = cast(E); - + const auto *SAE = cast(E); + if (!SAE->isInstantiationDependent()) { // Itanium C++ ABI: // If the operand of a sizeof or alignof operator is not @@ -3669,7 +3661,7 @@ } case Expr::CXXThrowExprClass: { - const CXXThrowExpr *TE = cast(E); + const auto *TE = cast(E); // ::= tw # throw expression // ::= tr # rethrow if (TE->getSubExpr()) { @@ -3682,7 +3674,7 @@ } case Expr::CXXTypeidExprClass: { - const CXXTypeidExpr *TIE = cast(E); + const auto *TIE = cast(E); // ::= ti # typeid (type) // ::= te # typeid (expression) if (TIE->isTypeOperand()) { @@ -3696,7 +3688,7 @@ } case Expr::CXXDeleteExprClass: { - const CXXDeleteExpr *DE = cast(E); + const auto *DE = cast(E); // ::= [gs] dl # [::] delete expr // ::= [gs] da # [::] delete [] expr if (DE->isGlobalDelete()) Out << "gs"; @@ -3706,7 +3698,7 @@ } case Expr::UnaryOperatorClass: { - const UnaryOperator *UO = cast(E); + const auto *UO = cast(E); mangleOperatorName(UnaryOperator::getOverloadedOperator(UO->getOpcode()), /*Arity=*/1); mangleExpression(UO->getSubExpr()); @@ -3714,7 +3706,7 @@ } case Expr::ArraySubscriptExprClass: { - const ArraySubscriptExpr *AE = cast(E); + const auto *AE = cast(E); // Array subscript is treated as a syntactically weird form of // binary operator. @@ -3726,7 +3718,7 @@ case Expr::CompoundAssignOperatorClass: // fallthrough case Expr::BinaryOperatorClass: { - const BinaryOperator *BO = cast(E); + const auto *BO = cast(E); if (BO->getOpcode() == BO_PtrMemD) Out << "ds"; else @@ -3738,7 +3730,7 @@ } case Expr::ConditionalOperatorClass: { - const ConditionalOperator *CO = cast(E); + const auto *CO = cast(E); mangleOperatorName(OO_Conditional, /*Arity=*/3); mangleExpression(CO->getCond()); mangleExpression(CO->getLHS(), Arity); @@ -3797,7 +3789,7 @@ break; case Expr::CXXOperatorCallExprClass: { - const CXXOperatorCallExpr *CE = cast(E); + const auto *CE = cast(E); unsigned NumArgs = CE->getNumArgs(); // A CXXOperatorCallExpr for OO_Arrow models only semantics, not syntax // (the enclosing MemberExpr covers the syntactic portion). @@ -3829,13 +3821,13 @@ break; case Decl::EnumConstant: { - const EnumConstantDecl *ED = cast(D); + const auto *ED = cast(D); mangleIntegerLiteral(ED->getType(), ED->getInitVal()); break; } case Decl::NonTypeTemplateParm: { - const NonTypeTemplateParmDecl *PD = cast(D); + const auto *PD = cast(D); mangleTemplateParameter(PD->getIndex()); break; } @@ -3855,14 +3847,14 @@ case Expr::FunctionParmPackExprClass: { // FIXME: not clear how to mangle this! - const FunctionParmPackExpr *FPPE = cast(E); + const auto *FPPE = cast(E); Out << "v110_SUBSTPACK"; mangleFunctionParam(FPPE->getParameterPack()); break; } case Expr::DependentScopeDeclRefExprClass: { - const DependentScopeDeclRefExpr *DRE = cast(E); + const auto *DRE = cast(E); mangleUnresolvedName(DRE->getQualifier(), DRE->getDeclName(), DRE->getTemplateArgs(), DRE->getNumTemplateArgs(), Arity); @@ -3878,7 +3870,7 @@ break; case Expr::FloatingLiteralClass: { - const FloatingLiteral *FL = cast(E); + const auto *FL = cast(E); Out << 'L'; mangleType(FL->getType()); mangleFloat(FL->getValue()); @@ -3915,13 +3907,12 @@ } case Expr::ImaginaryLiteralClass: { - const ImaginaryLiteral *IE = cast(E); + const auto *IE = cast(E); // Mangle as if a complex literal. // Proposal from David Vandevoorde, 2010.06.30. Out << 'L'; mangleType(E->getType()); - if (const FloatingLiteral *Imag = - dyn_cast(IE->getSubExpr())) { + if (const auto *Imag = dyn_cast(IE->getSubExpr())) { // Mangle a floating-point zero of the appropriate type. mangleFloat(llvm::APFloat(Imag->getValue().getSemantics())); Out << '_'; @@ -3972,13 +3963,11 @@ Out << "sZ"; const NamedDecl *Pack = SPE->getPack(); - if (const TemplateTypeParmDecl *TTP = dyn_cast(Pack)) + if (const auto *TTP = dyn_cast(Pack)) mangleTemplateParameter(TTP->getIndex()); - else if (const NonTypeTemplateParmDecl *NTTP - = dyn_cast(Pack)) + else if (const auto *NTTP = dyn_cast(Pack)) mangleTemplateParameter(NTTP->getIndex()); - else if (const TemplateTemplateParmDecl *TempTP - = dyn_cast(Pack)) + else if (const auto *TempTP = dyn_cast(Pack)) mangleTemplateParameter(TempTP->getIndex()); else mangleFunctionParam(cast(Pack)); @@ -4196,7 +4185,7 @@ // dependent cases, in which case we should mangle as a // declaration. const Expr *E = A.getAsExpr()->IgnoreParens(); - if (const DeclRefExpr *DRE = dyn_cast(E)) { + if (const auto *DRE = dyn_cast(E)) { const ValueDecl *D = DRE->getDecl(); if (isa(D) || isa(D)) { Out << 'L'; @@ -4314,7 +4303,7 @@ return mangleSubstitution(RT->getDecl()); } - uintptr_t TypePtr = reinterpret_cast(T.getAsOpaquePtr()); + auto TypePtr = reinterpret_cast(T.getAsOpaquePtr()); return mangleSubstitution(TypePtr); } @@ -4397,14 +4386,14 @@ bool CXXNameMangler::mangleStandardSubstitution(const NamedDecl *ND) { // ::= St # ::std:: - if (const NamespaceDecl *NS = dyn_cast(ND)) { + if (const auto *NS = dyn_cast(ND)) { if (isStd(NS)) { Out << "St"; return true; } } - if (const ClassTemplateDecl *TD = dyn_cast(ND)) { + if (const auto *TD = dyn_cast(ND)) { if (!isStdNamespace(getEffectiveDeclContext(TD))) return false; @@ -4421,8 +4410,7 @@ } } - if (const ClassTemplateSpecializationDecl *SD = - dyn_cast(ND)) { + if (const auto *SD = dyn_cast(ND)) { if (!isStdNamespace(getEffectiveDeclContext(SD))) return false; @@ -4480,7 +4468,7 @@ } } - uintptr_t TypePtr = reinterpret_cast(T.getAsOpaquePtr()); + auto TypePtr = reinterpret_cast(T.getAsOpaquePtr()); addSubstitution(TypePtr); } @@ -4515,7 +4503,7 @@ CXXNameMangler TrackReturnTypeTags(*this, NullOutStream); TrackReturnTypeTags.disableDerivedAbiTags(); - const FunctionProtoType *Proto = + const auto *Proto = cast(FD->getType()->getAs()); TrackReturnTypeTags.FunctionTypeDepth.enterResultType(); TrackReturnTypeTags.mangleType(Proto->getReturnType()); Index: lib/AST/Mangle.cpp =================================================================== --- lib/AST/Mangle.cpp +++ lib/AST/Mangle.cpp @@ -58,7 +58,7 @@ }; static bool isExternC(const NamedDecl *ND) { - if (const FunctionDecl *FD = dyn_cast(ND)) + if (const auto *FD = dyn_cast(ND)) return FD->isExternC(); return cast(ND)->isExternC(); } @@ -76,12 +76,12 @@ TI.getCXXABI() == TargetCXXABI::Microsoft) return CCM_Other; - const FunctionDecl *FD = dyn_cast(ND); + const auto *FD = dyn_cast(ND); if (!FD) return CCM_Other; QualType T = FD->getType(); - const FunctionType *FT = T->castAs(); + const auto *FT = T->castAs(); CallingConv CC = FT->getCallConv(); switch (CC) { @@ -141,7 +141,7 @@ bool MCXX = shouldMangleCXXName(D); const TargetInfo &TI = Context.getTargetInfo(); if (CC == CCM_Other || (MCXX && TI.getCXXABI() == TargetCXXABI::Microsoft)) { - if (const ObjCMethodDecl *OMD = dyn_cast(D)) + if (const auto *OMD = dyn_cast(D)) mangleObjCMethodName(OMD, Out); else mangleCXXName(D, Out); @@ -158,14 +158,14 @@ if (!MCXX) Out << D->getIdentifier()->getName(); - else if (const ObjCMethodDecl *OMD = dyn_cast(D)) + else if (const auto *OMD = dyn_cast(D)) mangleObjCMethodName(OMD, Out); else mangleCXXName(D, Out); - const FunctionDecl *FD = cast(D); - const FunctionType *FT = FD->getType()->castAs(); - const FunctionProtoType *Proto = dyn_cast(FT); + const auto *FD = cast(D); + const auto *FT = FD->getType()->castAs(); + const auto *Proto = dyn_cast(FT); if (CC == CCM_Vector) Out << '@'; Out << '@'; @@ -175,7 +175,7 @@ } assert(!Proto->isVariadic()); unsigned ArgWords = 0; - if (const CXXMethodDecl *MD = dyn_cast(FD)) + if (const auto *MD = dyn_cast(FD)) if (!MD->isStatic()) ++ArgWords; for (const auto &AT : Proto->param_types()) @@ -227,7 +227,7 @@ SmallString<64> Buffer; llvm::raw_svector_ostream Stream(Buffer); - if (const ObjCMethodDecl *Method = dyn_cast(DC)) { + if (const auto *Method = dyn_cast(DC)) { mangleObjCMethodName(Method, Stream); } else { assert((isa(DC) || isa(DC)) && @@ -259,11 +259,10 @@ void MangleContext::mangleObjCMethodNameWithoutSize(const ObjCMethodDecl *MD, raw_ostream &OS) { - const ObjCContainerDecl *CD = - dyn_cast(MD->getDeclContext()); + const auto *CD = dyn_cast(MD->getDeclContext()); assert (CD && "Missing container decl in GetNameForMethod"); OS << (MD->isInstanceMethod() ? '-' : '+') << '[' << CD->getName(); - if (const ObjCCategoryImplDecl *CID = dyn_cast(CD)) + if (const auto *CID = dyn_cast(CD)) OS << '(' << *CID << ')'; OS << ' '; MD->getSelector().print(OS); Index: lib/AST/MicrosoftCXXABI.cpp =================================================================== --- lib/AST/MicrosoftCXXABI.cpp +++ lib/AST/MicrosoftCXXABI.cpp @@ -167,13 +167,13 @@ MSInheritanceAttr::Spelling CXXRecordDecl::getMSInheritanceModel() const { - MSInheritanceAttr *IA = getAttr(); + auto *IA = getAttr(); assert(IA && "Expected MSInheritanceAttr on the CXXRecordDecl!"); return IA->getSemanticSpelling(); } MSVtorDispAttr::Mode CXXRecordDecl::getMSVtorDispMode() const { - if (MSVtorDispAttr *VDA = getAttr()) + if (auto *VDA = getAttr()) return VDA->getVtorDispMode(); return MSVtorDispAttr::Mode(getASTContext().getLangOpts().VtorDispMode); } Index: lib/AST/MicrosoftMangle.cpp =================================================================== --- lib/AST/MicrosoftMangle.cpp +++ lib/AST/MicrosoftMangle.cpp @@ -89,8 +89,8 @@ return LDADC; // Perform the same check for block literals. - if (const BlockDecl *BD = dyn_cast(D)) { - if (ParmVarDecl *ContextParam = + if (const auto *BD = dyn_cast(D)) { + if (auto *ContextParam = dyn_cast_or_null(BD->getBlockManglingContextDecl())) return ContextParam->getDeclContext(); } @@ -212,7 +212,7 @@ } // Anonymous tags are already numbered. - if (const TagDecl *Tag = dyn_cast(ND)) { + if (const auto *Tag = dyn_cast(ND)) { if (!Tag->hasNameForLinkage() && !getASTContext().getDeclaratorForUnnamedTagDecl(Tag) && !getASTContext().getTypedefNameForUnnamedTagDecl(Tag)) @@ -362,7 +362,7 @@ } bool MicrosoftMangleContextImpl::shouldMangleCXXName(const NamedDecl *D) { - if (const FunctionDecl *FD = dyn_cast(D)) { + if (const auto *FD = dyn_cast(D)) { LanguageLinkage L = FD->getLanguageLinkage(); // Overloadable functions need mangling. if (FD->hasAttr()) @@ -394,7 +394,7 @@ if (!getASTContext().getLangOpts().CPlusPlus) return false; - const VarDecl *VD = dyn_cast(D); + const auto *VD = dyn_cast(D); if (VD && !isa(D)) { // C variables are not mangled. if (VD->isExternC()) @@ -431,9 +431,9 @@ // ::= ? Out << Prefix; mangleName(D); - if (const FunctionDecl *FD = dyn_cast(D)) + if (const auto *FD = dyn_cast(D)) mangleFunctionEncoding(FD, Context.shouldMangleDeclName(FD)); - else if (const VarDecl *VD = dyn_cast(D)) + else if (const auto *VD = dyn_cast(D)) mangleVariableEncoding(VD); else llvm_unreachable("Tried to mangle unexpected NamedDecl!"); @@ -450,7 +450,7 @@ // We should never ever see a FunctionNoProtoType at this point. // We don't even know how to mangle their types anyway :). - const FunctionProtoType *FT = FD->getType()->castAs(); + const auto *FT = FD->getType()->castAs(); // extern "C" functions can hold entities that must be mangled. // As it stands, these functions still need to get expressed in the full @@ -505,7 +505,7 @@ mangleType(Ty, SR, QMM_Drop); manglePointerExtQualifiers( Ty.getDesugaredType(getASTContext()).getLocalQualifiers(), QualType()); - if (const MemberPointerType *MPT = Ty->getAs()) { + if (const auto *MPT = Ty->getAs()) { mangleQualifiers(MPT->getPointeeType().getQualifiers(), true); // Member pointers are suffixed with a back reference to the member // pointer's class name. @@ -597,7 +597,7 @@ if (MD) { Out << '$' << Code << '?'; if (MD->isVirtual()) { - MicrosoftVTableContext *VTContext = + auto *VTContext = cast(getASTContext().getVTableContext()); const MicrosoftVTableContext::MethodVFTableLocation &ML = VTContext->getMethodVFTableLocation(GlobalDecl(MD)); @@ -670,7 +670,7 @@ // // ::= [?] - uint64_t Value = static_cast(Number); + auto Value = static_cast(Number); if (Number < 0) { Value = -Value; Out << '?'; @@ -697,7 +697,7 @@ static const TemplateDecl * isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs) { // Check if we have a function template. - if (const FunctionDecl *FD = dyn_cast(ND)) { + if (const auto *FD = dyn_cast(ND)) { if (const TemplateDecl *TD = FD->getPrimaryTemplate()) { TemplateArgs = FD->getTemplateSpecializationArgs(); return TD; @@ -705,15 +705,13 @@ } // Check if we have a class template. - if (const ClassTemplateSpecializationDecl *Spec = - dyn_cast(ND)) { + if (const auto *Spec = dyn_cast(ND)) { TemplateArgs = &Spec->getTemplateArgs(); return Spec->getSpecializedTemplate(); } // Check if we have a variable template. - if (const VarTemplateSpecializationDecl *Spec = - dyn_cast(ND)) { + if (const auto *Spec = dyn_cast(ND)) { TemplateArgs = &Spec->getTemplateArgs(); return Spec->getSpecializedTemplate(); } @@ -774,14 +772,14 @@ // Otherwise, an anonymous entity. We must have a declaration. assert(ND && "mangling empty name without declaration"); - if (const NamespaceDecl *NS = dyn_cast(ND)) { + if (const auto *NS = dyn_cast(ND)) { if (NS->isAnonymousNamespace()) { Out << "?A@"; break; } } - if (const DecompositionDecl *DD = dyn_cast(ND)) { + if (const auto *DD = dyn_cast(ND)) { // FIXME: Invented mangling for decomposition declarations: // [X,Y,Z] // where X,Y,Z are the names of the bindings. @@ -796,7 +794,7 @@ break; } - if (const VarDecl *VD = dyn_cast(ND)) { + if (const auto *VD = dyn_cast(ND)) { // We must have an anonymous union or struct declaration. const CXXRecordDecl *RD = VD->getType()->getAsCXXRecordDecl(); assert(RD && "expected variable decl to have a record type"); @@ -811,7 +809,7 @@ } // We must have an anonymous struct. - const TagDecl *TD = cast(ND); + const auto *TD = cast(ND); if (const TypedefNameDecl *D = TD->getTypedefNameForAnonDecl()) { assert(TD->getDeclContext() == D->getDeclContext() && "Typedef should not be in another decl context!"); @@ -821,7 +819,7 @@ break; } - if (const CXXRecordDecl *Record = dyn_cast(TD)) { + if (const auto *Record = dyn_cast(TD)) { if (Record->isLambda()) { llvm::SmallString<10> Name("(DC)) { + if (const auto *BD = dyn_cast(DC)) { DiagnosticsEngine &Diags = Context.getDiags(); unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, @@ -962,11 +960,11 @@ // for how this should be done. Out << "__block_invoke" << Context.getBlockId(BD, false); Out << '@'; - } else if (const ObjCMethodDecl *Method = dyn_cast(DC)) { + } else if (const auto *Method = dyn_cast(DC)) { mangleObjCMethodName(Method); } else if (isa(DC)) { ND = cast(DC); - if (const FunctionDecl *FD = dyn_cast(ND)) { + if (const auto *FD = dyn_cast(ND)) { mangle(FD, "?"); break; } else { @@ -1209,7 +1207,7 @@ E = E->IgnoreParenNoopCasts(Context.getASTContext()); const CXXUuidofExpr *UE = nullptr; - if (const UnaryOperator *UO = dyn_cast(E)) { + if (const auto *UO = dyn_cast(E)) { if (UO->getOpcode() == UO_AddrOf) UE = dyn_cast(UO->getSubExpr()); } else @@ -1292,8 +1290,8 @@ mangleMemberDataPointer( cast(ND->getDeclContext())->getMostRecentDecl(), cast(ND)); - } else if (const FunctionDecl *FD = dyn_cast(ND)) { - const CXXMethodDecl *MD = dyn_cast(FD); + } else if (const auto *FD = dyn_cast(ND)) { + const auto *MD = dyn_cast(FD); if (MD && MD->isInstance()) { mangleMemberFunctionPointer(MD->getParent()->getMostRecentDecl(), MD); } else { @@ -1312,7 +1310,7 @@ break; case TemplateArgument::NullPtr: { QualType T = TA.getNullPtrType(); - if (const MemberPointerType *MPT = T->getAs()) { + if (const auto *MPT = T->getAs()) { const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl(); if (MPT->isMemberFunctionPointerType() && !isa(TD)) { @@ -1609,7 +1607,7 @@ case QMM_Drop: break; case QMM_Mangle: - if (const FunctionType *FT = dyn_cast(T)) { + if (const auto *FT = dyn_cast(T)) { Out << '6'; mangleFunctionType(FT); return; @@ -1836,7 +1834,7 @@ bool ForceThisQuals) { // ::= // - const FunctionProtoType *Proto = dyn_cast(T); + const auto *Proto = dyn_cast(T); SourceRange Range; if (D) Range = D->getSourceRange(); @@ -1844,7 +1842,7 @@ bool IsInLambda = false; bool IsStructor = false, HasThisQuals = ForceThisQuals, IsCtorClosure = false; CallingConv CC = T->getCallConv(); - if (const CXXMethodDecl *MD = dyn_cast_or_null(D)) { + if (const auto *MD = dyn_cast_or_null(D)) { if (MD->getParent()->isLambda()) IsInLambda = true; if (MD->isInstance()) @@ -1990,7 +1988,7 @@ // ::= V # public: virtual far // ::= Y # global near // ::= Z # global far - if (const CXXMethodDecl *MD = dyn_cast(FD)) { + if (const auto *MD = dyn_cast(FD)) { switch (MD->getAccess()) { case AS_none: llvm_unreachable("Unsupported access specifier"); @@ -2207,7 +2205,7 @@ QualType PointeeType = T->getPointeeType(); manglePointerCVQualifiers(Quals); manglePointerExtQualifiers(Quals, PointeeType); - if (const FunctionProtoType *FPT = PointeeType->getAs()) { + if (const auto *FPT = PointeeType->getAs()) { Out << '8'; mangleName(T->getClass()->castAs()->getDecl()); mangleFunctionType(FPT, nullptr, true); @@ -2593,7 +2591,7 @@ void MicrosoftMangleContextImpl::mangleVirtualMemPtrThunk(const CXXMethodDecl *MD, raw_ostream &Out) { - MicrosoftVTableContext *VTContext = + auto *VTContext = cast(getASTContext().getVTableContext()); const MicrosoftVTableContext::MethodVFTableLocation &ML = VTContext->getMethodVFTableLocation(GlobalDecl(MD)); Index: lib/AST/NSAPI.cpp =================================================================== --- lib/AST/NSAPI.cpp +++ lib/AST/NSAPI.cpp @@ -79,7 +79,7 @@ Optional NSAPI::getNSStringMethodKind(Selector Sel) const { for (unsigned i = 0; i != NumNSStringMethods; ++i) { - NSStringMethodKind MK = NSStringMethodKind(i); + auto MK = NSStringMethodKind(i); if (Sel == getNSStringSelector(MK)) return MK; } @@ -156,7 +156,7 @@ Optional NSAPI::getNSArrayMethodKind(Selector Sel) { for (unsigned i = 0; i != NumNSArrayMethods; ++i) { - NSArrayMethodKind MK = NSArrayMethodKind(i); + auto MK = NSArrayMethodKind(i); if (Sel == getNSArraySelector(MK)) return MK; } @@ -258,7 +258,7 @@ Optional NSAPI::getNSDictionaryMethodKind(Selector Sel) { for (unsigned i = 0; i != NumNSDictionaryMethods; ++i) { - NSDictionaryMethodKind MK = NSDictionaryMethodKind(i); + auto MK = NSDictionaryMethodKind(i); if (Sel == getNSDictionarySelector(MK)) return MK; } @@ -315,7 +315,7 @@ Optional NSAPI::getNSSetMethodKind(Selector Sel) { for (unsigned i = 0; i != NumNSSetMethods; ++i) { - NSSetMethodKind MK = NSSetMethodKind(i); + auto MK = NSSetMethodKind(i); if (Sel == getNSSetSelector(MK)) return MK; } @@ -378,7 +378,7 @@ Optional NSAPI::getNSNumberLiteralMethodKind(Selector Sel) const { for (unsigned i = 0; i != NumNSNumberLiteralMethods; ++i) { - NSNumberLiteralMethodKind MK = NSNumberLiteralMethodKind(i); + auto MK = NSNumberLiteralMethodKind(i); if (isNSNumberLiteralSelector(MK, Sel)) return MK; } @@ -563,9 +563,8 @@ if (!II) II = &Ctx.Idents.get(name); - if (const DeclRefExpr *DRE = dyn_cast(E->IgnoreParenImpCasts())) - if (const EnumConstantDecl * - EnumD = dyn_cast_or_null(DRE->getDecl())) + if (const auto *DRE = dyn_cast(E->IgnoreParenImpCasts())) + if (const auto *EnumD = dyn_cast_or_null(DRE->getDecl())) return EnumD->getIdentifier() == II; return false; Index: lib/AST/NestedNameSpecifier.cpp =================================================================== --- lib/AST/NestedNameSpecifier.cpp +++ lib/AST/NestedNameSpecifier.cpp @@ -136,7 +136,7 @@ return Identifier; case StoredDecl: { - NamedDecl *ND = static_cast(Specifier); + auto *ND = static_cast(Specifier); if (isa(ND)) return Super; return isa(ND) ? Namespace : NamespaceAlias; @@ -199,7 +199,7 @@ return false; case Super: { - CXXRecordDecl *RD = static_cast(Specifier); + auto *RD = static_cast(Specifier); for (const auto &Base : RD->bases()) if (Base.getType()->isDependentType()) return true; @@ -306,8 +306,7 @@ // suppress that nested-name-specifier during printing. assert(!isa(T) && "Elaborated type in nested-name-specifier"); - if (const TemplateSpecializationType *SpecType - = dyn_cast(T)) { + if (const auto *SpecType = dyn_cast(T)) { // Print the template name without its corresponding // nested-name-specifier. SpecType->getTemplateName().print(OS, InnerPolicy, true); @@ -456,7 +455,7 @@ unsigned NewCapacity = std::max( (unsigned)(BufferCapacity ? BufferCapacity * 2 : sizeof(void *) * 2), (unsigned)(BufferSize + (End - Start))); - char *NewBuffer = static_cast(malloc(NewCapacity)); + auto *NewBuffer = static_cast(malloc(NewCapacity)); if (BufferCapacity) { memcpy(NewBuffer, Buffer, BufferSize); free(Buffer); Index: lib/AST/OpenMPClause.cpp =================================================================== --- lib/AST/OpenMPClause.cpp +++ lib/AST/OpenMPClause.cpp @@ -174,7 +174,7 @@ ArrayRef VL, ArrayRef PrivateVL) { // Allocate space for private variables and initializer expressions. void *Mem = C.Allocate(totalSizeToAlloc(2 * VL.size())); - OMPPrivateClause *Clause = + auto *Clause = new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); Clause->setPrivateCopies(PrivateVL); @@ -205,7 +205,7 @@ ArrayRef VL, ArrayRef PrivateVL, ArrayRef InitVL, Stmt *PreInit) { void *Mem = C.Allocate(totalSizeToAlloc(3 * VL.size())); - OMPFirstprivateClause *Clause = + auto *Clause = new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); Clause->setPrivateCopies(PrivateVL); @@ -254,7 +254,7 @@ ArrayRef DstExprs, ArrayRef AssignmentOps, Stmt *PreInit, Expr *PostUpdate) { void *Mem = C.Allocate(totalSizeToAlloc(5 * VL.size())); - OMPLastprivateClause *Clause = + auto *Clause = new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); Clause->setSourceExprs(SrcExprs); @@ -277,7 +277,7 @@ SourceLocation EndLoc, ArrayRef VL) { void *Mem = C.Allocate(totalSizeToAlloc(VL.size())); - OMPSharedClause *Clause = + auto *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); return Clause; @@ -321,7 +321,7 @@ // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions // (Step and CalcStep). void *Mem = C.Allocate(totalSizeToAlloc(5 * VL.size() + 2)); - OMPLinearClause *Clause = new (Mem) OMPLinearClause( + auto *Clause = new (Mem) OMPLinearClause( StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); Clause->setPrivates(PL); @@ -352,7 +352,7 @@ SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef VL, Expr *A) { void *Mem = C.Allocate(totalSizeToAlloc(VL.size() + 1)); - OMPAlignedClause *Clause = new (Mem) + auto *Clause = new (Mem) OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); Clause->setAlignment(A); @@ -392,7 +392,7 @@ SourceLocation EndLoc, ArrayRef VL, ArrayRef SrcExprs, ArrayRef DstExprs, ArrayRef AssignmentOps) { void *Mem = C.Allocate(totalSizeToAlloc(4 * VL.size())); - OMPCopyinClause *Clause = + auto *Clause = new (Mem) OMPCopyinClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); Clause->setSourceExprs(SrcExprs); @@ -433,7 +433,7 @@ SourceLocation EndLoc, ArrayRef VL, ArrayRef SrcExprs, ArrayRef DstExprs, ArrayRef AssignmentOps) { void *Mem = C.Allocate(totalSizeToAlloc(4 * VL.size())); - OMPCopyprivateClause *Clause = + auto *Clause = new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); Clause->setSourceExprs(SrcExprs); @@ -483,7 +483,7 @@ ArrayRef RHSExprs, ArrayRef ReductionOps, Stmt *PreInit, Expr *PostUpdate) { void *Mem = C.Allocate(totalSizeToAlloc(5 * VL.size())); - OMPReductionClause *Clause = new (Mem) OMPReductionClause( + auto *Clause = new (Mem) OMPReductionClause( StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); Clause->setVarRefs(VL); Clause->setPrivates(Privates); @@ -507,7 +507,7 @@ SourceLocation EndLoc, ArrayRef VL) { void *Mem = C.Allocate(totalSizeToAlloc(VL.size() + 1)); - OMPFlushClause *Clause = + auto *Clause = new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); return Clause; @@ -523,7 +523,7 @@ SourceLocation EndLoc, OpenMPDependClauseKind DepKind, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef VL) { void *Mem = C.Allocate(totalSizeToAlloc(VL.size() + 1)); - OMPDependClause *Clause = + auto *Clause = new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size()); Clause->setVarRefs(VL); Clause->setDependencyKind(DepKind); @@ -609,7 +609,7 @@ OMPClauseMappableExprCommon::MappableComponent>( NumVars, NumUniqueDeclarations, NumUniqueDeclarations + NumComponentLists, NumComponents)); - OMPMapClause *Clause = new (Mem) OMPMapClause( + auto *Clause = new (Mem) OMPMapClause( TypeModifier, Type, TypeIsImplicit, TypeLoc, StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents); @@ -661,7 +661,7 @@ NumVars, NumUniqueDeclarations, NumUniqueDeclarations + NumComponentLists, NumComponents)); - OMPToClause *Clause = new (Mem) + auto *Clause = new (Mem) OMPToClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents); @@ -710,7 +710,7 @@ NumVars, NumUniqueDeclarations, NumUniqueDeclarations + NumComponentLists, NumComponents)); - OMPFromClause *Clause = new (Mem) + auto *Clause = new (Mem) OMPFromClause(StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents); @@ -771,7 +771,7 @@ 3 * NumVars, NumUniqueDeclarations, NumUniqueDeclarations + NumComponentLists, NumComponents)); - OMPUseDevicePtrClause *Clause = new (Mem) OMPUseDevicePtrClause( + auto *Clause = new (Mem) OMPUseDevicePtrClause( StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents); @@ -822,7 +822,7 @@ NumVars, NumUniqueDeclarations, NumUniqueDeclarations + NumComponentLists, NumComponents)); - OMPIsDevicePtrClause *Clause = new (Mem) OMPIsDevicePtrClause( + auto *Clause = new (Mem) OMPIsDevicePtrClause( StartLoc, LParenLoc, EndLoc, NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents); Index: lib/AST/ParentMap.cpp =================================================================== --- lib/AST/ParentMap.cpp +++ lib/AST/ParentMap.cpp @@ -34,7 +34,7 @@ switch (S->getStmtClass()) { case Stmt::PseudoObjectExprClass: { assert(OVMode == OV_Transparent && "Should not appear alongside OVEs"); - PseudoObjectExpr *POE = cast(S); + auto *POE = cast(S); // If we are rebuilding the map, clear out any existing state. if (M[POE->getSyntacticForm()]) @@ -54,7 +54,7 @@ } case Stmt::BinaryConditionalOperatorClass: { assert(OVMode == OV_Transparent && "Should not appear alongside OVEs"); - BinaryConditionalOperator *BCO = cast(S); + auto *BCO = cast(S); M[BCO->getCommon()] = S; BuildParentMap(M, BCO->getCommon(), OV_Transparent); @@ -76,7 +76,7 @@ // OpaqueValueExpr is shared among multiple parent expressions. // The right thing to do is to give the OpaqueValueExpr its syntactic // parent, then not reassign that when traversing the semantic expressions. - OpaqueValueExpr *OVE = cast(S); + auto *OVE = cast(S); if (OVMode == OV_Transparent || !M[OVE->getSourceExpr()]) { M[OVE->getSourceExpr()] = S; BuildParentMap(M, OVE->getSourceExpr(), OV_Transparent); @@ -96,7 +96,7 @@ ParentMap::ParentMap(Stmt *S) : Impl(nullptr) { if (S) { - MapTy *M = new MapTy(); + auto *M = new MapTy(); BuildParentMap(*M, S); Impl = M; } @@ -115,12 +115,12 @@ void ParentMap::setParent(const Stmt *S, const Stmt *Parent) { assert(S); assert(Parent); - MapTy *M = reinterpret_cast(Impl); + auto *M = reinterpret_cast(Impl); M->insert(std::make_pair(const_cast(S), const_cast(Parent))); } Stmt* ParentMap::getParent(Stmt* S) const { - MapTy* M = (MapTy*) Impl; + auto *M = (MapTy *)Impl; MapTy::iterator I = M->find(S); return I == M->end() ? nullptr : I->second; } @@ -176,7 +176,7 @@ case Stmt::DeclStmtClass: return true; case Stmt::BinaryOperatorClass: { - BinaryOperator *BE = cast(P); + auto *BE = cast(P); // If it is a comma, only the right side is consumed. // If it isn't a comma, both sides are consumed. return BE->getOpcode()!=BO_Comma ||DirectChild==BE->getRHS(); Index: lib/AST/RawCommentList.cpp =================================================================== --- lib/AST/RawCommentList.cpp +++ lib/AST/RawCommentList.cpp @@ -191,7 +191,7 @@ const std::string Result = P.Parse(); const unsigned BriefTextLength = Result.size(); - char *BriefTextPtr = new (Context) char[BriefTextLength + 1]; + auto *BriefTextPtr = new (Context) char[BriefTextLength + 1]; memcpy(BriefTextPtr, Result.c_str(), BriefTextLength + 1); BriefText = BriefTextPtr; BriefTextValid = true; Index: lib/AST/RecordLayoutBuilder.cpp =================================================================== --- lib/AST/RecordLayoutBuilder.cpp +++ lib/AST/RecordLayoutBuilder.cpp @@ -1227,7 +1227,7 @@ } void ItaniumRecordLayoutBuilder::InitializeLayout(const Decl *D) { - if (const RecordDecl *RD = dyn_cast(D)) { + if (const auto *RD = dyn_cast(D)) { IsUnion = RD->isUnion(); IsMsStruct = RD->isMsStruct(Context); } @@ -1256,7 +1256,7 @@ } // If there is an external AST source, ask it for the various offsets. - if (const RecordDecl *RD = dyn_cast(D)) + if (const auto *RD = dyn_cast(D)) if (ExternalASTSource *Source = Context.getExternalSource()) { UseExternalLayout = Source->layoutRecordType( RD, External.Size, External.Align, External.FieldOffsets, @@ -1728,7 +1728,7 @@ FieldSize = CharUnits::Zero(); const ArrayType* ATy = Context.getAsArrayType(D->getType()); FieldAlign = Context.getTypeAlignInChars(ATy->getElementType()); - } else if (const ReferenceType *RT = D->getType()->getAs()) { + } else if (const auto *RT = D->getType()->getAs()) { unsigned AS = RT->getPointeeType().getAddressSpace(); FieldSize = Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(AS)); @@ -1831,7 +1831,7 @@ void ItaniumRecordLayoutBuilder::FinishLayout(const NamedDecl *D) { // In C++, records cannot be of size 0. if (Context.getLangOpts().CPlusPlus && getSizeInBits() == 0) { - if (const CXXRecordDecl *RD = dyn_cast(D)) { + if (const auto *RD = dyn_cast(D)) { // Compatibility with gcc requires a class (pod or non-pod) // which is not empty but of size 0; such as having fields of // array of zero-length, remains of Size 0 @@ -1867,7 +1867,7 @@ setSize(RoundedSize); unsigned CharBitNum = Context.getTargetInfo().getCharWidth(); - if (const RecordDecl *RD = dyn_cast(D)) { + if (const auto *RD = dyn_cast(D)) { // Warn if padding was introduced to the struct/class/union. if (getSizeInBits() > UnpaddedSize) { unsigned PadSize = getSizeInBits() - UnpaddedSize; @@ -3060,10 +3060,10 @@ uint64_t ASTContext::getFieldOffset(const ValueDecl *VD) const { uint64_t OffsetInBits; - if (const FieldDecl *FD = dyn_cast(VD)) { + if (const auto *FD = dyn_cast(VD)) { OffsetInBits = ::getFieldOffset(*this, FD); } else { - const IndirectFieldDecl *IFD = cast(VD); + const auto *IFD = cast(VD); OffsetInBits = 0; for (const NamedDecl *ND : IFD->chain()) Index: lib/AST/Stmt.cpp =================================================================== --- lib/AST/Stmt.cpp +++ lib/AST/Stmt.cpp @@ -138,11 +138,11 @@ const Stmt *Stmt::stripLabelLikeStatements() const { const Stmt *S = this; while (true) { - if (const LabelStmt *LS = dyn_cast(S)) + if (const auto *LS = dyn_cast(S)) S = LS->getSubStmt(); - else if (const SwitchCase *SC = dyn_cast(S)) + else if (const auto *SC = dyn_cast(S)) S = SC->getSubStmt(); - else if (const AttributedStmt *AS = dyn_cast(S)) + else if (const auto *AS = dyn_cast(S)) S = AS->getSubStmt(); else return S; @@ -328,49 +328,49 @@ } std::string AsmStmt::generateAsmString(const ASTContext &C) const { - if (const GCCAsmStmt *gccAsmStmt = dyn_cast(this)) + if (const auto *gccAsmStmt = dyn_cast(this)) return gccAsmStmt->generateAsmString(C); - if (const MSAsmStmt *msAsmStmt = dyn_cast(this)) + if (const auto *msAsmStmt = dyn_cast(this)) return msAsmStmt->generateAsmString(C); llvm_unreachable("unknown asm statement kind!"); } StringRef AsmStmt::getOutputConstraint(unsigned i) const { - if (const GCCAsmStmt *gccAsmStmt = dyn_cast(this)) + if (const auto *gccAsmStmt = dyn_cast(this)) return gccAsmStmt->getOutputConstraint(i); - if (const MSAsmStmt *msAsmStmt = dyn_cast(this)) + if (const auto *msAsmStmt = dyn_cast(this)) return msAsmStmt->getOutputConstraint(i); llvm_unreachable("unknown asm statement kind!"); } const Expr *AsmStmt::getOutputExpr(unsigned i) const { - if (const GCCAsmStmt *gccAsmStmt = dyn_cast(this)) + if (const auto *gccAsmStmt = dyn_cast(this)) return gccAsmStmt->getOutputExpr(i); - if (const MSAsmStmt *msAsmStmt = dyn_cast(this)) + if (const auto *msAsmStmt = dyn_cast(this)) return msAsmStmt->getOutputExpr(i); llvm_unreachable("unknown asm statement kind!"); } StringRef AsmStmt::getInputConstraint(unsigned i) const { - if (const GCCAsmStmt *gccAsmStmt = dyn_cast(this)) + if (const auto *gccAsmStmt = dyn_cast(this)) return gccAsmStmt->getInputConstraint(i); - if (const MSAsmStmt *msAsmStmt = dyn_cast(this)) + if (const auto *msAsmStmt = dyn_cast(this)) return msAsmStmt->getInputConstraint(i); llvm_unreachable("unknown asm statement kind!"); } const Expr *AsmStmt::getInputExpr(unsigned i) const { - if (const GCCAsmStmt *gccAsmStmt = dyn_cast(this)) + if (const auto *gccAsmStmt = dyn_cast(this)) return gccAsmStmt->getInputExpr(i); - if (const MSAsmStmt *msAsmStmt = dyn_cast(this)) + if (const auto *msAsmStmt = dyn_cast(this)) return msAsmStmt->getInputExpr(i); llvm_unreachable("unknown asm statement kind!"); } StringRef AsmStmt::getClobber(unsigned i) const { - if (const GCCAsmStmt *gccAsmStmt = dyn_cast(this)) + if (const auto *gccAsmStmt = dyn_cast(this)) return gccAsmStmt->getClobber(i); - if (const MSAsmStmt *msAsmStmt = dyn_cast(this)) + if (const auto *msAsmStmt = dyn_cast(this)) return msAsmStmt->getClobber(i); llvm_unreachable("unknown asm statement kind!"); } @@ -610,7 +610,7 @@ DiagOffs = CurPtr-StrStart-1; // Find the ']'. - const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr); + const auto *NameEnd = (const char *)memchr(CurPtr, ']', StrEnd - CurPtr); if (NameEnd == nullptr) return diag::err_asm_unterminated_symbolic_operand_name; if (NameEnd == CurPtr) @@ -781,7 +781,7 @@ if (!SubExprs[VAR]) return nullptr; - DeclStmt *DS = cast(SubExprs[VAR]); + auto *DS = cast(SubExprs[VAR]); return cast(DS->getSingleDecl()); } @@ -816,7 +816,7 @@ if (!SubExprs[CONDVAR]) return nullptr; - DeclStmt *DS = cast(SubExprs[CONDVAR]); + auto *DS = cast(SubExprs[CONDVAR]); return cast(DS->getSingleDecl()); } @@ -844,7 +844,7 @@ if (!SubExprs[VAR]) return nullptr; - DeclStmt *DS = cast(SubExprs[VAR]); + auto *DS = cast(SubExprs[VAR]); return cast(DS->getSingleDecl()); } @@ -878,7 +878,7 @@ if (!SubExprs[VAR]) return nullptr; - DeclStmt *DS = cast(SubExprs[VAR]); + auto *DS = cast(SubExprs[VAR]); return cast(DS->getSingleDecl()); } @@ -895,8 +895,7 @@ // IndirectGotoStmt LabelDecl *IndirectGotoStmt::getConstantTarget() { - if (AddrLabelExpr *E = - dyn_cast(getTarget()->IgnoreParenImpCasts())) + if (auto *E = dyn_cast(getTarget()->IgnoreParenImpCasts())) return E->getLabel(); return nullptr; } Index: lib/AST/StmtCXX.cpp =================================================================== --- lib/AST/StmtCXX.cpp +++ lib/AST/StmtCXX.cpp @@ -44,7 +44,7 @@ CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, ArrayRef handlers) : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) { - Stmt **Stmts = reinterpret_cast(this + 1); + auto **Stmts = reinterpret_cast(this + 1); Stmts[0] = tryBlock; std::copy(handlers.begin(), handlers.end(), Stmts + 1); } @@ -68,7 +68,7 @@ Expr *CXXForRangeStmt::getRangeInit() { DeclStmt *RangeStmt = getRangeStmt(); - VarDecl *RangeDecl = dyn_cast_or_null(RangeStmt->getSingleDecl()); + auto *RangeDecl = dyn_cast_or_null(RangeStmt->getSingleDecl()); assert(RangeDecl && "for-range should have a single var decl"); return RangeDecl->getInit(); } Index: lib/AST/StmtIterator.cpp =================================================================== --- lib/AST/StmtIterator.cpp +++ lib/AST/StmtIterator.cpp @@ -19,8 +19,8 @@ // FIXME: Add support for dependent-sized array types in C++? // Does it even make sense to build a CFG for an uninstantiated template? static inline const VariableArrayType *FindVA(const Type* t) { - while (const ArrayType *vt = dyn_cast(t)) { - if (const VariableArrayType *vat = dyn_cast(vt)) + while (const auto *vt = dyn_cast(t)) { + if (const auto *vat = dyn_cast(vt)) if (vat->getSizeExpr()) return vat; @@ -41,7 +41,7 @@ return; if (inDeclGroup()) { - if (VarDecl* VD = dyn_cast(*DGI)) + if (auto *VD = dyn_cast(*DGI)) if (VD->hasInit()) return; @@ -68,7 +68,7 @@ } bool StmtIteratorBase::HandleDecl(Decl* D) { - if (VarDecl* VD = dyn_cast(D)) { + if (auto *VD = dyn_cast(D)) { if (const VariableArrayType* VAPtr = FindVA(VD->getType().getTypePtr())) { setVAPtr(VAPtr); return true; @@ -76,15 +76,13 @@ if (VD->getInit()) return true; - } - else if (TypedefNameDecl* TD = dyn_cast(D)) { + } else if (auto *TD = dyn_cast(D)) { if (const VariableArrayType* VAPtr = FindVA(TD->getUnderlyingType().getTypePtr())) { setVAPtr(VAPtr); return true; } - } - else if (EnumConstantDecl* ECD = dyn_cast(D)) { + } else if (auto *ECD = dyn_cast(D)) { if (ECD->getInitExpr()) return true; } @@ -109,6 +107,6 @@ } assert (inDeclGroup()); - VarDecl* VD = cast(*DGI); + auto *VD = cast(*DGI); return *VD->getInitAddress(); } Index: lib/AST/StmtOpenMP.cpp =================================================================== --- lib/AST/StmtOpenMP.cpp +++ lib/AST/StmtOpenMP.cpp @@ -61,8 +61,7 @@ llvm::alignTo(sizeof(OMPParallelDirective), alignof(OMPClause *)); void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPParallelDirective *Dir = - new (Mem) OMPParallelDirective(StartLoc, EndLoc, Clauses.size()); + auto *Dir = new (Mem) OMPParallelDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); Dir->setHasCancel(HasCancel); @@ -88,7 +87,7 @@ void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd)); - OMPSimdDirective *Dir = new (Mem) + auto *Dir = new (Mem) OMPSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -128,7 +127,7 @@ void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for)); - OMPForDirective *Dir = + auto *Dir = new (Mem) OMPForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -180,7 +179,7 @@ void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd)); - OMPForSimdDirective *Dir = new (Mem) + auto *Dir = new (Mem) OMPForSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -229,8 +228,7 @@ llvm::alignTo(sizeof(OMPSectionsDirective), alignof(OMPClause *)); void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPSectionsDirective *Dir = - new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size()); + auto *Dir = new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); Dir->setHasCancel(HasCancel); @@ -254,7 +252,7 @@ bool HasCancel) { unsigned Size = llvm::alignTo(sizeof(OMPSectionDirective), alignof(Stmt *)); void *Mem = C.Allocate(Size + sizeof(Stmt *)); - OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc); + auto *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc); Dir->setAssociatedStmt(AssociatedStmt); Dir->setHasCancel(HasCancel); return Dir; @@ -276,8 +274,7 @@ llvm::alignTo(sizeof(OMPSingleDirective), alignof(OMPClause *)); void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPSingleDirective *Dir = - new (Mem) OMPSingleDirective(StartLoc, EndLoc, Clauses.size()); + auto *Dir = new (Mem) OMPSingleDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); return Dir; @@ -299,7 +296,7 @@ Stmt *AssociatedStmt) { unsigned Size = llvm::alignTo(sizeof(OMPMasterDirective), alignof(Stmt *)); void *Mem = C.Allocate(Size + sizeof(Stmt *)); - OMPMasterDirective *Dir = new (Mem) OMPMasterDirective(StartLoc, EndLoc); + auto *Dir = new (Mem) OMPMasterDirective(StartLoc, EndLoc); Dir->setAssociatedStmt(AssociatedStmt); return Dir; } @@ -319,7 +316,7 @@ llvm::alignTo(sizeof(OMPCriticalDirective), alignof(OMPClause *)); void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPCriticalDirective *Dir = + auto *Dir = new (Mem) OMPCriticalDirective(Name, StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -345,7 +342,7 @@ void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for)); - OMPParallelForDirective *Dir = new (Mem) + auto *Dir = new (Mem) OMPParallelForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -396,7 +393,7 @@ void *Mem = C.Allocate( Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd)); - OMPParallelForSimdDirective *Dir = new (Mem) OMPParallelForSimdDirective( + auto *Dir = new (Mem) OMPParallelForSimdDirective( StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -445,7 +442,7 @@ llvm::alignTo(sizeof(OMPParallelSectionsDirective), alignof(OMPClause *)); void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPParallelSectionsDirective *Dir = + auto *Dir = new (Mem) OMPParallelSectionsDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -470,8 +467,7 @@ unsigned Size = llvm::alignTo(sizeof(OMPTaskDirective), alignof(OMPClause *)); void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPTaskDirective *Dir = - new (Mem) OMPTaskDirective(StartLoc, EndLoc, Clauses.size()); + auto *Dir = new (Mem) OMPTaskDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); Dir->setHasCancel(HasCancel); @@ -491,8 +487,7 @@ SourceLocation StartLoc, SourceLocation EndLoc) { void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective)); - OMPTaskyieldDirective *Dir = - new (Mem) OMPTaskyieldDirective(StartLoc, EndLoc); + auto *Dir = new (Mem) OMPTaskyieldDirective(StartLoc, EndLoc); return Dir; } @@ -506,7 +501,7 @@ SourceLocation StartLoc, SourceLocation EndLoc) { void *Mem = C.Allocate(sizeof(OMPBarrierDirective)); - OMPBarrierDirective *Dir = new (Mem) OMPBarrierDirective(StartLoc, EndLoc); + auto *Dir = new (Mem) OMPBarrierDirective(StartLoc, EndLoc); return Dir; } @@ -520,7 +515,7 @@ SourceLocation StartLoc, SourceLocation EndLoc) { void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); - OMPTaskwaitDirective *Dir = new (Mem) OMPTaskwaitDirective(StartLoc, EndLoc); + auto *Dir = new (Mem) OMPTaskwaitDirective(StartLoc, EndLoc); return Dir; } @@ -536,8 +531,7 @@ Stmt *AssociatedStmt) { unsigned Size = llvm::alignTo(sizeof(OMPTaskgroupDirective), alignof(Stmt *)); void *Mem = C.Allocate(Size + sizeof(Stmt *)); - OMPTaskgroupDirective *Dir = - new (Mem) OMPTaskgroupDirective(StartLoc, EndLoc); + auto *Dir = new (Mem) OMPTaskgroupDirective(StartLoc, EndLoc); Dir->setAssociatedStmt(AssociatedStmt); return Dir; } @@ -555,8 +549,7 @@ unsigned Size = llvm::alignTo(sizeof(OMPCancellationPointDirective), alignof(Stmt *)); void *Mem = C.Allocate(Size); - OMPCancellationPointDirective *Dir = - new (Mem) OMPCancellationPointDirective(StartLoc, EndLoc); + auto *Dir = new (Mem) OMPCancellationPointDirective(StartLoc, EndLoc); Dir->setCancelRegion(CancelRegion); return Dir; } @@ -577,8 +570,7 @@ sizeof(OMPClause *) * Clauses.size(), alignof(Stmt *)); void *Mem = C.Allocate(Size); - OMPCancelDirective *Dir = - new (Mem) OMPCancelDirective(StartLoc, EndLoc, Clauses.size()); + auto *Dir = new (Mem) OMPCancelDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); Dir->setCancelRegion(CancelRegion); return Dir; @@ -601,8 +593,7 @@ unsigned Size = llvm::alignTo(sizeof(OMPFlushDirective), alignof(OMPClause *)); void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size()); - OMPFlushDirective *Dir = - new (Mem) OMPFlushDirective(StartLoc, EndLoc, Clauses.size()); + auto *Dir = new (Mem) OMPFlushDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); return Dir; } @@ -625,8 +616,7 @@ llvm::alignTo(sizeof(OMPOrderedDirective), alignof(OMPClause *)); void *Mem = C.Allocate(Size + sizeof(Stmt *) + sizeof(OMPClause *) * Clauses.size()); - OMPOrderedDirective *Dir = - new (Mem) OMPOrderedDirective(StartLoc, EndLoc, Clauses.size()); + auto *Dir = new (Mem) OMPOrderedDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); return Dir; @@ -650,8 +640,7 @@ llvm::alignTo(sizeof(OMPAtomicDirective), alignof(OMPClause *)); void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + 5 * sizeof(Stmt *)); - OMPAtomicDirective *Dir = - new (Mem) OMPAtomicDirective(StartLoc, EndLoc, Clauses.size()); + auto *Dir = new (Mem) OMPAtomicDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); Dir->setX(X); @@ -682,8 +671,7 @@ llvm::alignTo(sizeof(OMPTargetDirective), alignof(OMPClause *)); void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPTargetDirective *Dir = - new (Mem) OMPTargetDirective(StartLoc, EndLoc, Clauses.size()); + auto *Dir = new (Mem) OMPTargetDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); return Dir; @@ -706,7 +694,7 @@ llvm::alignTo(sizeof(OMPTargetParallelDirective), alignof(OMPClause *)); void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPTargetParallelDirective *Dir = + auto *Dir = new (Mem) OMPTargetParallelDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -732,7 +720,7 @@ void *Mem = C.Allocate( Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_target_parallel_for)); - OMPTargetParallelForDirective *Dir = new (Mem) OMPTargetParallelForDirective( + auto *Dir = new (Mem) OMPTargetParallelForDirective( StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -781,7 +769,7 @@ void *Mem = C.Allocate( llvm::alignTo(sizeof(OMPTargetDataDirective), alignof(OMPClause *)) + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPTargetDataDirective *Dir = + auto *Dir = new (Mem) OMPTargetDataDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -803,7 +791,7 @@ void *Mem = C.Allocate( llvm::alignTo(sizeof(OMPTargetEnterDataDirective), alignof(OMPClause *)) + sizeof(OMPClause *) * Clauses.size()); - OMPTargetEnterDataDirective *Dir = + auto *Dir = new (Mem) OMPTargetEnterDataDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); return Dir; @@ -825,7 +813,7 @@ void *Mem = C.Allocate( llvm::alignTo(sizeof(OMPTargetExitDataDirective), alignof(OMPClause *)) + sizeof(OMPClause *) * Clauses.size()); - OMPTargetExitDataDirective *Dir = + auto *Dir = new (Mem) OMPTargetExitDataDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); return Dir; @@ -849,8 +837,7 @@ llvm::alignTo(sizeof(OMPTeamsDirective), alignof(OMPClause *)); void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); - OMPTeamsDirective *Dir = - new (Mem) OMPTeamsDirective(StartLoc, EndLoc, Clauses.size()); + auto *Dir = new (Mem) OMPTeamsDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); return Dir; @@ -875,7 +862,7 @@ void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_taskloop)); - OMPTaskLoopDirective *Dir = new (Mem) + auto *Dir = new (Mem) OMPTaskLoopDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -926,7 +913,7 @@ void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_taskloop_simd)); - OMPTaskLoopSimdDirective *Dir = new (Mem) + auto *Dir = new (Mem) OMPTaskLoopSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -976,7 +963,7 @@ void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_distribute)); - OMPDistributeDirective *Dir = new (Mem) + auto *Dir = new (Mem) OMPDistributeDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -1024,7 +1011,7 @@ unsigned Size = llvm::alignTo(sizeof(OMPTargetUpdateDirective), alignof(OMPClause *)); void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size()); - OMPTargetUpdateDirective *Dir = + auto *Dir = new (Mem) OMPTargetUpdateDirective(StartLoc, EndLoc, Clauses.size()); Dir->setClauses(Clauses); return Dir; @@ -1049,9 +1036,8 @@ Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_distribute_parallel_for)); - OMPDistributeParallelForDirective *Dir = - new (Mem) OMPDistributeParallelForDirective(StartLoc, EndLoc, - CollapsedNum, Clauses.size()); + auto *Dir = new (Mem) OMPDistributeParallelForDirective( + StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); Dir->setIterationVariable(Exprs.IterationVarRef); @@ -1105,9 +1091,8 @@ Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_distribute_parallel_for_simd)); - OMPDistributeParallelForSimdDirective *Dir = new (Mem) - OMPDistributeParallelForSimdDirective(StartLoc, EndLoc, CollapsedNum, - Clauses.size()); + auto *Dir = new (Mem) OMPDistributeParallelForSimdDirective( + StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); Dir->setIterationVariable(Exprs.IterationVarRef); @@ -1161,7 +1146,7 @@ Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_distribute_simd)); - OMPDistributeSimdDirective *Dir = new (Mem) OMPDistributeSimdDirective( + auto *Dir = new (Mem) OMPDistributeSimdDirective( StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -1214,9 +1199,8 @@ Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_target_parallel_for_simd)); - OMPTargetParallelForSimdDirective *Dir = - new (Mem) OMPTargetParallelForSimdDirective(StartLoc, EndLoc, - CollapsedNum, Clauses.size()); + auto *Dir = new (Mem) OMPTargetParallelForSimdDirective( + StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); Dir->setIterationVariable(Exprs.IterationVarRef); @@ -1269,7 +1253,7 @@ void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_target_simd)); - OMPTargetSimdDirective *Dir = new (Mem) + auto *Dir = new (Mem) OMPTargetSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -1309,7 +1293,7 @@ void *Mem = C.Allocate( Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_teams_distribute)); - OMPTeamsDistributeDirective *Dir = new (Mem) OMPTeamsDistributeDirective( + auto *Dir = new (Mem) OMPTeamsDistributeDirective( StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); @@ -1361,9 +1345,8 @@ C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_teams_distribute_simd)); - OMPTeamsDistributeSimdDirective *Dir = - new (Mem) OMPTeamsDistributeSimdDirective(StartLoc, EndLoc, CollapsedNum, - Clauses.size()); + auto *Dir = new (Mem) OMPTeamsDistributeSimdDirective( + StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); Dir->setIterationVariable(Exprs.IterationVarRef); @@ -1416,9 +1399,8 @@ sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_teams_distribute_parallel_for_simd)); - OMPTeamsDistributeParallelForSimdDirective *Dir = new (Mem) - OMPTeamsDistributeParallelForSimdDirective(StartLoc, EndLoc, CollapsedNum, - Clauses.size()); + auto *Dir = new (Mem) OMPTeamsDistributeParallelForSimdDirective( + StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); Dir->setIterationVariable(Exprs.IterationVarRef); @@ -1474,9 +1456,8 @@ Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_teams_distribute_parallel_for)); - OMPTeamsDistributeParallelForDirective *Dir = new (Mem) - OMPTeamsDistributeParallelForDirective(StartLoc, EndLoc, CollapsedNum, - Clauses.size()); + auto *Dir = new (Mem) OMPTeamsDistributeParallelForDirective( + StartLoc, EndLoc, CollapsedNum, Clauses.size()); Dir->setClauses(Clauses); Dir->setAssociatedStmt(AssociatedStmt); Dir->setIterationVariable(Exprs.IterationVarRef); Index: lib/AST/StmtPrinter.cpp =================================================================== --- lib/AST/StmtPrinter.cpp +++ lib/AST/StmtPrinter.cpp @@ -185,7 +185,7 @@ PrintExpr(If->getCond()); OS << ')'; - if (CompoundStmt *CS = dyn_cast(If->getThen())) { + if (auto *CS = dyn_cast(If->getThen())) { OS << ' '; PrintRawCompoundStmt(CS); OS << (If->getElse() ? ' ' : '\n'); @@ -198,11 +198,11 @@ if (Stmt *Else = If->getElse()) { OS << "else"; - if (CompoundStmt *CS = dyn_cast(Else)) { + if (auto *CS = dyn_cast(Else)) { OS << ' '; PrintRawCompoundStmt(CS); OS << '\n'; - } else if (IfStmt *ElseIf = dyn_cast(Else)) { + } else if (auto *ElseIf = dyn_cast(Else)) { OS << ' '; PrintRawIfStmt(ElseIf); } else { @@ -226,7 +226,7 @@ OS << ")"; // Pretty print compoundstmt bodies (very common). - if (CompoundStmt *CS = dyn_cast(Node->getBody())) { + if (auto *CS = dyn_cast(Node->getBody())) { OS << " "; PrintRawCompoundStmt(CS); OS << "\n"; @@ -248,7 +248,7 @@ void StmtPrinter::VisitDoStmt(DoStmt *Node) { Indent() << "do "; - if (CompoundStmt *CS = dyn_cast(Node->getBody())) { + if (auto *CS = dyn_cast(Node->getBody())) { PrintRawCompoundStmt(CS); OS << " "; } else { @@ -265,7 +265,7 @@ void StmtPrinter::VisitForStmt(ForStmt *Node) { Indent() << "for ("; if (Node->getInit()) { - if (DeclStmt *DS = dyn_cast(Node->getInit())) + if (auto *DS = dyn_cast(Node->getInit())) PrintRawDeclStmt(DS); else PrintExpr(cast(Node->getInit())); @@ -282,7 +282,7 @@ } OS << ") "; - if (CompoundStmt *CS = dyn_cast(Node->getBody())) { + if (auto *CS = dyn_cast(Node->getBody())) { PrintRawCompoundStmt(CS); OS << "\n"; } else { @@ -293,7 +293,7 @@ void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) { Indent() << "for ("; - if (DeclStmt *DS = dyn_cast(Node->getElement())) + if (auto *DS = dyn_cast(Node->getElement())) PrintRawDeclStmt(DS); else PrintExpr(cast(Node->getElement())); @@ -301,7 +301,7 @@ PrintExpr(Node->getCollection()); OS << ") "; - if (CompoundStmt *CS = dyn_cast(Node->getBody())) { + if (auto *CS = dyn_cast(Node->getBody())) { PrintRawCompoundStmt(CS); OS << "\n"; } else { @@ -454,7 +454,7 @@ void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) { Indent() << "@try"; - if (CompoundStmt *TS = dyn_cast(Node->getTryBody())) { + if (auto *TS = dyn_cast(Node->getTryBody())) { PrintRawCompoundStmt(TS); OS << "\n"; } @@ -467,14 +467,13 @@ PrintRawDecl(DS); } OS << ")"; - if (CompoundStmt *CS = dyn_cast(catchStmt->getCatchBody())) { + if (auto *CS = dyn_cast(catchStmt->getCatchBody())) { PrintRawCompoundStmt(CS); OS << "\n"; } } - if (ObjCAtFinallyStmt *FS = static_cast( - Node->getFinallyStmt())) { + if (auto *FS = static_cast(Node->getFinallyStmt())) { Indent() << "@finally"; PrintRawCompoundStmt(dyn_cast(FS->getFinallyBody())); OS << "\n"; @@ -772,7 +771,7 @@ I != E; ++I) { assert(*I && "Expected non-null Stmt"); OS << (I == Node->varlist_begin() ? StartSym : ','); - if (DeclRefExpr *DRE = dyn_cast(*I)) { + if (auto *DRE = dyn_cast(*I)) { if (isa(DRE->getDecl())) DRE->printPretty(OS, nullptr, Policy, 0); else @@ -1575,14 +1574,14 @@ // FIXME: Suppress printing implicit bases (like "this") PrintExpr(Node->getBase()); - MemberExpr *ParentMember = dyn_cast(Node->getBase()); + auto *ParentMember = dyn_cast(Node->getBase()); FieldDecl *ParentDecl = ParentMember ? dyn_cast(ParentMember->getMemberDecl()) : nullptr; if (!ParentDecl || !ParentDecl->isAnonymousStructOrUnion()) OS << (Node->isArrow() ? "->" : "."); - if (FieldDecl *FD = dyn_cast(Node->getMemberDecl())) + if (auto *FD = dyn_cast(Node->getMemberDecl())) if (FD->isAnonymousStructOrUnion()) return; @@ -1977,7 +1976,7 @@ OS << cast(Node->getArg(0)->IgnoreImpCasts())->getString(); break; case UserDefinedLiteral::LOK_Template: { - DeclRefExpr *DRE = cast(Node->getCallee()->IgnoreImpCasts()); + auto *DRE = cast(Node->getCallee()->IgnoreImpCasts()); const TemplateArgumentList *Args = cast(DRE->getDecl())->getTemplateSpecializationArgs(); assert(Args); @@ -1999,13 +1998,13 @@ } case UserDefinedLiteral::LOK_Integer: { // Print integer literal without suffix. - IntegerLiteral *Int = cast(Node->getCookedLiteral()); + auto *Int = cast(Node->getCookedLiteral()); OS << Int->getValue().toString(10, /*isSigned*/false); break; } case UserDefinedLiteral::LOK_Floating: { // Print floating literal without suffix. - FloatingLiteral *Float = cast(Node->getCookedLiteral()); + auto *Float = cast(Node->getCookedLiteral()); PrintFloatingLiteral(OS, Float, /*PrintSuffix=*/false); break; } @@ -2159,8 +2158,7 @@ if (Node->isMutable()) OS << " mutable"; - const FunctionProtoType *Proto - = Method->getType()->getAs(); + const auto *Proto = Method->getType()->getAs(); Proto->printExceptionSpecification(OS, Policy); // FIXME: Attributes @@ -2578,7 +2576,7 @@ (*AI)->getType().print(OS, Policy, ParamStr); } - const FunctionProtoType *FT = cast(AFT); + const auto *FT = cast(AFT); if (FT->isVariadic()) { if (!BD->param_empty()) OS << ", "; OS << "..."; Index: lib/AST/StmtProfile.cpp =================================================================== --- lib/AST/StmtProfile.cpp +++ lib/AST/StmtProfile.cpp @@ -1015,7 +1015,7 @@ for (PseudoObjectExpr::const_semantics_iterator i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i) // Normally, we would not profile the source expressions of OVEs. - if (const OpaqueValueExpr *OVE = dyn_cast(*i)) + if (const auto *OVE = dyn_cast(*i)) Visit(OVE->getSourceExpr()); } @@ -1676,8 +1676,7 @@ ID.AddInteger(D? D->getKind() : 0); if (Canonical && D) { - if (const NonTypeTemplateParmDecl *NTTP = - dyn_cast(D)) { + if (const auto *NTTP = dyn_cast(D)) { ID.AddInteger(NTTP->getDepth()); ID.AddInteger(NTTP->getIndex()); ID.AddBoolean(NTTP->isParameterPack()); @@ -1685,7 +1684,7 @@ return; } - if (const ParmVarDecl *Parm = dyn_cast(D)) { + if (const auto *Parm = dyn_cast(D)) { // The Itanium C++ ABI uses the type, scope depth, and scope // index of a parameter when mangling expressions that involve // function parameters, so we will use the parameter's type for @@ -1699,16 +1698,14 @@ return; } - if (const TemplateTypeParmDecl *TTP = - dyn_cast(D)) { + if (const auto *TTP = dyn_cast(D)) { ID.AddInteger(TTP->getDepth()); ID.AddInteger(TTP->getIndex()); ID.AddBoolean(TTP->isParameterPack()); return; } - if (const TemplateTemplateParmDecl *TTP = - dyn_cast(D)) { + if (const auto *TTP = dyn_cast(D)) { ID.AddInteger(TTP->getDepth()); ID.AddInteger(TTP->getIndex()); ID.AddBoolean(TTP->isParameterPack()); Index: lib/AST/TemplateBase.cpp =================================================================== --- lib/AST/TemplateBase.cpp +++ lib/AST/TemplateBase.cpp @@ -113,7 +113,7 @@ return true; case Declaration: - if (DeclContext *DC = dyn_cast(getAsDecl())) + if (auto *DC = dyn_cast(getAsDecl())) return DC->isDependentContext(); return getAsDecl()->getDeclContext()->isDependentContext(); @@ -153,7 +153,7 @@ return true; case Declaration: - if (DeclContext *DC = dyn_cast(getAsDecl())) + if (auto *DC = dyn_cast(getAsDecl())) return DC->isDependentContext(); return getAsDecl()->getDeclContext()->isDependentContext(); @@ -265,9 +265,8 @@ case Template: case TemplateExpansion: { TemplateName Template = getAsTemplateOrTemplatePattern(); - if (TemplateTemplateParmDecl *TTP - = dyn_cast_or_null( - Template.getAsTemplateDecl())) { + if (auto *TTP = dyn_cast_or_null( + Template.getAsTemplateDecl())) { ID.AddBoolean(true); ID.AddInteger(TTP->getDepth()); ID.AddInteger(TTP->getPosition()); @@ -366,7 +365,7 @@ } case Declaration: { - NamedDecl *ND = cast(getAsDecl()); + auto *ND = cast(getAsDecl()); Out << '&'; if (ND->getDeclName()) { // FIXME: distinguish between pointer and reference args? @@ -540,7 +539,7 @@ RAngleLoc = Info.getRAngleLoc(); NumTemplateArgs = Info.size(); - TemplateArgumentLoc *ArgBuffer = getTrailingObjects(); + auto *ArgBuffer = getTrailingObjects(); for (unsigned i = 0; i != NumTemplateArgs; ++i) new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]); } Index: lib/AST/TemplateName.cpp =================================================================== --- lib/AST/TemplateName.cpp +++ lib/AST/TemplateName.cpp @@ -75,8 +75,7 @@ if (Storage.is()) return QualifiedTemplate; - UncommonTemplateNameStorage *uncommon - = Storage.get(); + auto *uncommon = Storage.get(); if (uncommon->getAsOverloadedStorage()) return OverloadedTemplate; if (uncommon->getAsSubstTemplateTemplateParm()) @@ -85,7 +84,7 @@ } TemplateDecl *TemplateName::getAsTemplateDecl() const { - if (TemplateDecl *Template = Storage.dyn_cast()) + if (auto *Template = Storage.dyn_cast()) return Template; if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) @@ -98,8 +97,7 @@ } OverloadedTemplateStorage *TemplateName::getAsOverloadedTemplate() const { - if (UncommonTemplateNameStorage *Uncommon = - Storage.dyn_cast()) + if (auto *Uncommon = Storage.dyn_cast()) return Uncommon->getAsOverloadedStorage(); return nullptr; @@ -107,8 +105,7 @@ SubstTemplateTemplateParmStorage * TemplateName::getAsSubstTemplateTemplateParm() const { - if (UncommonTemplateNameStorage *uncommon = - Storage.dyn_cast()) + if (auto *uncommon = Storage.dyn_cast()) return uncommon->getAsSubstTemplateTemplateParm(); return nullptr; @@ -116,8 +113,7 @@ SubstTemplateTemplateParmPackStorage * TemplateName::getAsSubstTemplateTemplateParmPack() const { - if (UncommonTemplateNameStorage *Uncommon = - Storage.dyn_cast()) + if (auto *Uncommon = Storage.dyn_cast()) return Uncommon->getAsSubstTemplateTemplateParmPack(); return nullptr; @@ -160,8 +156,7 @@ bool TemplateName::containsUnexpandedParameterPack() const { if (TemplateDecl *Template = getAsTemplateDecl()) { - if (TemplateTemplateParmDecl *TTP - = dyn_cast(Template)) + if (auto *TTP = dyn_cast(Template)) return TTP->isParameterPack(); return false; @@ -177,7 +172,7 @@ void TemplateName::print(raw_ostream &OS, const PrintingPolicy &Policy, bool SuppressNNS) const { - if (TemplateDecl *Template = Storage.dyn_cast()) + if (auto *Template = Storage.dyn_cast()) OS << *Template; else if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName()) { if (!SuppressNNS) Index: lib/AST/Type.cpp =================================================================== --- lib/AST/Type.cpp +++ lib/AST/Type.cpp @@ -189,7 +189,7 @@ /// This method should never be used when type qualifiers are meaningful. const Type *Type::getArrayElementTypeNoTypeQual() const { // If this is directly an array type, return it. - if (const ArrayType *ATy = dyn_cast(this)) + if (const auto *ATy = dyn_cast(this)) return ATy->getElementType().getTypePtr(); // If the canonical form of this type isn't the right kind, reject it. @@ -223,11 +223,12 @@ QualType Type::getLocallyUnqualifiedSingleStepDesugaredType() const { switch (getTypeClass()) { #define ABSTRACT_TYPE(Class, Parent) -#define TYPE(Class, Parent) \ - case Type::Class: { \ - const Class##Type *ty = cast(this); \ - if (!ty->isSugared()) return QualType(ty, 0); \ - return ty->desugar(); \ +#define TYPE(Class, Parent) \ + case Type::Class: { \ + const auto *ty = cast(this); \ + if (!ty->isSugared()) \ + return QualType(ty, 0); \ + return ty->desugar(); \ } #include "clang/AST/TypeNodes.def" } @@ -242,14 +243,14 @@ const Type *CurTy = Qs.strip(Cur); switch (CurTy->getTypeClass()) { #define ABSTRACT_TYPE(Class, Parent) -#define TYPE(Class, Parent) \ - case Type::Class: { \ - const Class##Type *Ty = cast(CurTy); \ - if (!Ty->isSugared()) \ - return SplitQualType(Ty, Qs); \ - Cur = Ty->desugar(); \ - break; \ - } +#define TYPE(Class, Parent) \ + case Type::Class: { \ + const auto *Ty = cast(CurTy); \ + if (!Ty->isSugared()) \ + return SplitQualType(Ty, Qs); \ + Cur = Ty->desugar(); \ + break; \ + } #include "clang/AST/TypeNodes.def" } } @@ -271,13 +272,14 @@ // sugared. switch (split.Ty->getTypeClass()) { #define ABSTRACT_TYPE(Class, Parent) -#define TYPE(Class, Parent) \ - case Type::Class: { \ - const Class##Type *ty = cast(split.Ty); \ - if (!ty->isSugared()) goto done; \ - next = ty->desugar(); \ - break; \ - } +#define TYPE(Class, Parent) \ + case Type::Class: { \ + const auto *ty = cast(split.Ty); \ + if (!ty->isSugared()) \ + goto done; \ + next = ty->desugar(); \ + break; \ + } #include "clang/AST/TypeNodes.def" } @@ -296,7 +298,7 @@ QualType QualType::IgnoreParens(QualType T) { // FIXME: this seems inherently un-qualifiers-safe. - while (const ParenType *PT = T->getAs()) + while (const auto *PT = T->getAs()) T = PT->getInnerType(); return T; } @@ -306,17 +308,18 @@ /// reaches a T or a non-sugared type. template static const T *getAsSugar(const Type *Cur) { while (true) { - if (const T *Sugar = dyn_cast(Cur)) + if (const auto *Sugar = dyn_cast(Cur)) return Sugar; switch (Cur->getTypeClass()) { #define ABSTRACT_TYPE(Class, Parent) -#define TYPE(Class, Parent) \ - case Type::Class: { \ - const Class##Type *Ty = cast(Cur); \ - if (!Ty->isSugared()) return 0; \ - Cur = Ty->desugar().getTypePtr(); \ - break; \ - } +#define TYPE(Class, Parent) \ + case Type::Class: { \ + const auto *Ty = cast(Cur); \ + if (!Ty->isSugared()) \ + return 0; \ + Cur = Ty->desugar().getTypePtr(); \ + break; \ + } #include "clang/AST/TypeNodes.def" } } @@ -382,7 +385,7 @@ return false; } bool Type::isVoidPointerType() const { - if (const PointerType *PT = getAs()) + if (const auto *PT = getAs()) return PT->getPointeeType()->isVoidType(); return false; } @@ -405,31 +408,31 @@ } const ComplexType *Type::getAsComplexIntegerType() const { - if (const ComplexType *Complex = getAs()) + if (const auto *Complex = getAs()) if (Complex->getElementType()->isIntegerType()) return Complex; return nullptr; } QualType Type::getPointeeType() const { - if (const PointerType *PT = getAs()) + if (const auto *PT = getAs()) return PT->getPointeeType(); - if (const ObjCObjectPointerType *OPT = getAs()) + if (const auto *OPT = getAs()) return OPT->getPointeeType(); - if (const BlockPointerType *BPT = getAs()) + if (const auto *BPT = getAs()) return BPT->getPointeeType(); - if (const ReferenceType *RT = getAs()) + if (const auto *RT = getAs()) return RT->getPointeeType(); - if (const MemberPointerType *MPT = getAs()) + if (const auto *MPT = getAs()) return MPT->getPointeeType(); - if (const DecayedType *DT = getAs()) + if (const auto *DT = getAs()) return DT->getPointeeType(); return QualType(); } const RecordType *Type::getAsStructureType() const { // If this is directly a structure type, return it. - if (const RecordType *RT = dyn_cast(this)) { + if (const auto *RT = dyn_cast(this)) { if (RT->getDecl()->isStruct()) return RT; } @@ -448,7 +451,7 @@ const RecordType *Type::getAsUnionType() const { // If this is directly a union type, return it. - if (const RecordType *RT = dyn_cast(this)) { + if (const auto *RT = dyn_cast(this)) { if (RT->getDecl()->isUnion()) return RT; } @@ -470,7 +473,7 @@ const ObjCObjectType *&bound) const { bound = nullptr; - const ObjCObjectPointerType *OPT = getAs(); + const auto *OPT = getAs(); if (!OPT) return false; @@ -493,7 +496,7 @@ } bool Type::isObjCClassOrClassKindOfType() const { - const ObjCObjectPointerType *OPT = getAs(); + const auto *OPT = getAs(); if (!OPT) return false; @@ -637,8 +640,7 @@ // Recursively strip __kindof. SplitQualType splitBaseType = getBaseType().split(); QualType baseType(splitBaseType.Ty, 0); - if (const ObjCObjectType *baseObj - = splitBaseType.Ty->getAs()) { + if (const auto *baseObj = splitBaseType.Ty->getAs()) { baseType = baseObj->stripObjCKindOfTypeAndQuals(ctx); } @@ -1308,7 +1310,7 @@ // Find the class or category in which the type we're substituting // was declared. - const ObjCInterfaceDecl *dcClassDecl = dyn_cast(dc); + const auto *dcClassDecl = dyn_cast(dc); const ObjCCategoryDecl *dcCategoryDecl = nullptr; ObjCTypeParamList *dcTypeParams = nullptr; if (dcClassDecl) { @@ -1485,7 +1487,7 @@ // There is no sugar for ObjCObjectType's, just return the canonical // type pointer if it is the right class. There is no typedef information to // return and these cannot be Address-space qualified. - if (const ObjCObjectType *T = getAs()) + if (const auto *T = getAs()) if (T->getNumProtocols() && T->getInterface()) return T; return nullptr; @@ -1498,7 +1500,7 @@ const ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { // There is no sugar for ObjCQualifiedIdType's, just return the canonical // type pointer if it is the right class. - if (const ObjCObjectPointerType *OPT = getAs()) { + if (const auto *OPT = getAs()) { if (OPT->isObjCQualifiedIdType()) return OPT; } @@ -1508,7 +1510,7 @@ const ObjCObjectPointerType *Type::getAsObjCQualifiedClassType() const { // There is no sugar for ObjCQualifiedClassType's, just return the canonical // type pointer if it is the right class. - if (const ObjCObjectPointerType *OPT = getAs()) { + if (const auto *OPT = getAs()) { if (OPT->isObjCQualifiedClassType()) return OPT; } @@ -1516,14 +1518,14 @@ } const ObjCObjectType *Type::getAsObjCInterfaceType() const { - if (const ObjCObjectType *OT = getAs()) { + if (const auto *OT = getAs()) { if (OT->getInterface()) return OT; } return nullptr; } const ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { - if (const ObjCObjectPointerType *OPT = getAs()) { + if (const auto *OPT = getAs()) { if (OPT->getInterfaceType()) return OPT; } @@ -1532,9 +1534,9 @@ const CXXRecordDecl *Type::getPointeeCXXRecordDecl() const { QualType PointeeType; - if (const PointerType *PT = getAs()) + if (const auto *PT = getAs()) PointeeType = PT->getPointeeType(); - else if (const ReferenceType *RT = getAs()) + else if (const auto *RT = getAs()) PointeeType = RT->getPointeeType(); else return nullptr; @@ -1850,7 +1852,7 @@ assert(isScalarType()); const Type *T = CanonicalType.getTypePtr(); - if (const BuiltinType *BT = dyn_cast(T)) { + if (const auto *BT = dyn_cast(T)) { if (BT->getKind() == BuiltinType::Bool) return STK_Bool; if (BT->getKind() == BuiltinType::NullPtr) return STK_CPointer; if (BT->isInteger()) return STK_Integral; @@ -1867,7 +1869,7 @@ } else if (isa(T)) { assert(cast(T)->getDecl()->isComplete()); return STK_Integral; - } else if (const ComplexType *CT = dyn_cast(T)) { + } else if (const auto *CT = dyn_cast(T)) { if (CT->getElementType()->isRealFloatingType()) return STK_FloatingComplex; return STK_IntegralComplex; @@ -1887,7 +1889,7 @@ /// includes union types. bool Type::isAggregateType() const { if (const RecordType *Record = dyn_cast(CanonicalType)) { - if (CXXRecordDecl *ClassDecl = dyn_cast(Record->getDecl())) + if (auto *ClassDecl = dyn_cast(Record->getDecl())) return ClassDecl->isAggregate(); return true; @@ -2043,8 +2045,8 @@ return true; case Type::Record: - if (CXXRecordDecl *ClassDecl - = dyn_cast(cast(CanonicalType)->getDecl())) + if (auto *ClassDecl = + dyn_cast(cast(CanonicalType)->getDecl())) return ClassDecl->isPOD(); // C struct/union is POD. @@ -2227,7 +2229,7 @@ } // We treat _Atomic T as a literal type if T is a literal type. - if (const AtomicType *AT = BaseTy->getAs()) + if (const auto *AT = BaseTy->getAs()) return AT->getValueType()->isLiteralType(Ctx); // If this type hasn't been deduced yet, then conservatively assume that @@ -2522,12 +2524,12 @@ bool Type::isElaboratedTypeSpecifier() const { ElaboratedTypeKeyword Keyword; - if (const ElaboratedType *Elab = dyn_cast(this)) + if (const auto *Elab = dyn_cast(this)) Keyword = Elab->getKeyword(); - else if (const DependentNameType *DepName = dyn_cast(this)) + else if (const auto *DepName = dyn_cast(this)) Keyword = DepName->getKeyword(); - else if (const DependentTemplateSpecializationType *DepTST = - dyn_cast(this)) + else if (const auto *DepTST = + dyn_cast(this)) Keyword = DepTST->getKeyword(); else return false; @@ -2642,7 +2644,7 @@ } QualType QualType::getNonLValueExprType(const ASTContext &Context) const { - if (const ReferenceType *RefType = getTypePtr()->getAs()) + if (const auto *RefType = getTypePtr()->getAs()) return RefType->getPointeeType(); // C++0x [basic.lval]: @@ -2700,7 +2702,7 @@ FunctionTypeBits.RefQualifier = epi.RefQualifier; // Fill in the trailing argument array. - QualType *argSlot = reinterpret_cast(this+1); + auto *argSlot = reinterpret_cast(this + 1); for (unsigned i = 0; i != NumParams; ++i) { if (params[i]->isDependentType()) setDependent(); @@ -2731,7 +2733,7 @@ } } else if (getExceptionSpecType() == EST_ComputedNoexcept) { // Store the noexcept expression and context. - Expr **noexSlot = reinterpret_cast(argSlot + NumParams); + auto **noexSlot = reinterpret_cast(argSlot + NumParams); *noexSlot = epi.ExceptionSpec.NoexceptExpr; if (epi.ExceptionSpec.NoexceptExpr) { @@ -2745,8 +2747,7 @@ } else if (getExceptionSpecType() == EST_Uninstantiated) { // Store the function decl from which we will resolve our // exception specification. - FunctionDecl **slot = - reinterpret_cast(argSlot + NumParams); + auto **slot = reinterpret_cast(argSlot + NumParams); slot[0] = epi.ExceptionSpec.SourceDecl; slot[1] = epi.ExceptionSpec.SourceTemplate; // This exception specification doesn't make the type dependent, because @@ -2754,8 +2755,7 @@ } else if (getExceptionSpecType() == EST_Unevaluated) { // Store the function decl from which we will resolve our // exception specification. - FunctionDecl **slot = - reinterpret_cast(argSlot + NumParams); + auto **slot = reinterpret_cast(argSlot + NumParams); slot[0] = epi.ExceptionSpec.SourceDecl; } @@ -2773,8 +2773,8 @@ } if (epi.ExtParameterInfos) { - ExtParameterInfo *extParamInfos = - const_cast(getExtParameterInfosBuffer()); + auto *extParamInfos = + const_cast(getExtParameterInfosBuffer()); for (unsigned i = 0; i != NumParams; ++i) extParamInfos[i] = epi.ExtParameterInfos[i]; } @@ -3191,8 +3191,7 @@ T.getKind() == TemplateName::SubstTemplateTemplateParmPack) && "Unexpected template name for TemplateSpecializationType"); - TemplateArgument *TemplateArgs - = reinterpret_cast(this + 1); + auto *TemplateArgs = reinterpret_cast(this + 1); for (const TemplateArgument &Arg : Args) { // Update instantiation-dependent and variably-modified bits. // If the canonical type exists and is non-dependent, the template @@ -3214,7 +3213,7 @@ // Store the aliased type if this is a type alias template specialization. if (TypeAlias) { - TemplateArgument *Begin = reinterpret_cast(this + 1); + auto *Begin = reinterpret_cast(this + 1); *reinterpret_cast(Begin + getNumArgs()) = AliasedType; } } @@ -3403,7 +3402,7 @@ case Type::RValueReference: return Cache::get(cast(T)->getPointeeType()); case Type::MemberPointer: { - const MemberPointerType *MPT = cast(T); + const auto *MPT = cast(T); return merge(Cache::get(MPT->getClass()), Cache::get(MPT->getPointeeType())); } @@ -3417,7 +3416,7 @@ case Type::FunctionNoProto: return Cache::get(cast(T)->getReturnType()); case Type::FunctionProto: { - const FunctionProtoType *FPT = cast(T); + const auto *FPT = cast(T); CachedProperties result = Cache::get(FPT->getReturnType()); for (const auto &ai : FPT->param_types()) result = merge(result, Cache::get(ai)); @@ -3488,7 +3487,7 @@ case Type::RValueReference: return computeLinkageInfo(cast(T)->getPointeeType()); case Type::MemberPointer: { - const MemberPointerType *MPT = cast(T); + const auto *MPT = cast(T); LinkageInfo LV = computeLinkageInfo(MPT->getClass()); LV.merge(computeLinkageInfo(MPT->getPointeeType())); return LV; @@ -3503,7 +3502,7 @@ case Type::FunctionNoProto: return computeLinkageInfo(cast(T)->getReturnType()); case Type::FunctionProto: { - const FunctionProtoType *FPT = cast(T); + const auto *FPT = cast(T); LinkageInfo LV = computeLinkageInfo(FPT->getReturnType()); for (const auto &ai : FPT->param_types()) LV.merge(computeLinkageInfo(ai)); @@ -3696,7 +3695,7 @@ } bool Type::isBlockCompatibleObjCPointerType(ASTContext &ctx) const { - const ObjCObjectPointerType *objcPtr = getAs(); + const auto *objcPtr = getAs(); if (!objcPtr) return false; @@ -3741,11 +3740,10 @@ const Type *canon = getCanonicalTypeInternal().getTypePtr(); // Walk down to the base type. We don't care about qualifiers for this. - while (const ArrayType *array = dyn_cast(canon)) + while (const auto *array = dyn_cast(canon)) canon = array->getElementType().getTypePtr(); - if (const ObjCObjectPointerType *opt - = dyn_cast(canon)) { + if (const auto *opt = dyn_cast(canon)) { // Class and Class don't require retention. if (opt->getObjectType()->isObjCClass()) return true; @@ -3757,7 +3755,7 @@ bool Type::isObjCNSObjectType() const { const Type *cur = this; while (true) { - if (const TypedefType *typedefType = dyn_cast(cur)) + if (const auto *typedefType = dyn_cast(cur)) return typedefType->getDecl()->hasAttr(); // Single-step desugar until we run out of sugar. @@ -3768,7 +3766,7 @@ } bool Type::isObjCIndependentClassType() const { - if (const TypedefType *typedefType = dyn_cast(this)) + if (const auto *typedefType = dyn_cast(this)) return typedefType->getDecl()->hasAttr(); return false; } @@ -3780,11 +3778,11 @@ bool Type::isObjCIndirectLifetimeType() const { if (isObjCLifetimeType()) return true; - if (const PointerType *OPT = getAs()) + if (const auto *OPT = getAs()) return OPT->getPointeeType()->isObjCIndirectLifetimeType(); - if (const ReferenceType *Ref = getAs()) + if (const auto *Ref = getAs()) return Ref->getPointeeType()->isObjCIndirectLifetimeType(); - if (const MemberPointerType *MemPtr = getAs()) + if (const auto *MemPtr = getAs()) return MemPtr->getPointeeType()->isObjCIndirectLifetimeType(); return false; } @@ -3806,7 +3804,7 @@ /// \brief Determine whether the given type T is a "bridgeable" C type. bool Type::isCARCBridgableType() const { - const PointerType *Pointer = getAs(); + const auto *Pointer = getAs(); if (!Pointer) return false; @@ -3817,9 +3815,9 @@ bool Type::hasSizedVLAType() const { if (!isVariablyModifiedType()) return false; - if (const PointerType *ptr = getAs()) + if (const auto *ptr = getAs()) return ptr->getPointeeType()->hasSizedVLAType(); - if (const ReferenceType *ref = getAs()) + if (const auto *ref = getAs()) return ref->getPointeeType()->hasSizedVLAType(); if (const ArrayType *arr = getAsArrayTypeUnsafe()) { if (isa(arr) && Index: lib/AST/TypePrinter.cpp =================================================================== --- lib/AST/TypePrinter.cpp +++ lib/AST/TypePrinter.cpp @@ -168,10 +168,9 @@ bool CanPrefixQualifiers = false; NeedARCStrongQualifier = false; Type::TypeClass TC = T->getTypeClass(); - if (const AutoType *AT = dyn_cast(T)) + if (const auto *AT = dyn_cast(T)) TC = AT->desugar()->getTypeClass(); - if (const SubstTemplateTypeParmType *Subst - = dyn_cast(T)) + if (const auto *Subst = dyn_cast(T)) TC = Subst->getReplacementType()->getTypeClass(); switch (TC) { @@ -242,8 +241,7 @@ // If we have cv1 T, where T is substituted for cv2 U, only print cv1 - cv2 // at this level. Qualifiers Quals = Split.Quals; - if (const SubstTemplateTypeParmType *Subst = - dyn_cast(Split.Ty)) + if (const auto *Subst = dyn_cast(Split.Ty)) Quals -= QualType(Subst, 0).getQualifiers(); printBefore(Split.Ty, Quals, OS); @@ -918,7 +916,7 @@ if (DC->isFunctionOrMethod()) return; AppendScope(DC->getParent(), OS); - if (NamespaceDecl *NS = dyn_cast(DC)) { + if (auto *NS = dyn_cast(DC)) { if (Policy.SuppressUnwrittenScope && (NS->isAnonymousNamespace() || NS->isInline())) return; @@ -926,15 +924,14 @@ OS << NS->getName() << "::"; else OS << "(anonymous namespace)::"; - } else if (ClassTemplateSpecializationDecl *Spec - = dyn_cast(DC)) { + } else if (auto *Spec = dyn_cast(DC)) { IncludeStrongLifetimeRAII Strong(Policy); OS << Spec->getIdentifier()->getName(); const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); TemplateSpecializationType::PrintTemplateArgumentList( OS, TemplateArgs.asArray(), Policy); OS << "::"; - } else if (TagDecl *Tag = dyn_cast(DC)) { + } else if (auto *Tag = dyn_cast(DC)) { if (TypedefNameDecl *Typedef = Tag->getTypedefNameForAnonDecl()) OS << Typedef->getIdentifier()->getName() << "::"; else if (Tag->getIdentifier()) @@ -1007,8 +1004,7 @@ // If this is a class template specialization, print the template // arguments. - if (ClassTemplateSpecializationDecl *Spec - = dyn_cast(D)) { + if (auto *Spec = dyn_cast(D)) { ArrayRef Args; if (TypeSourceInfo *TAW = Spec->getTypeAsWritten()) { const TemplateSpecializationType *TST = @@ -1269,7 +1265,7 @@ case AttributedType::attr_vector_size: { OS << "__vector_size__("; - if (const VectorType *vector =T->getEquivalentType()->getAs()) { + if (const auto *vector = T->getEquivalentType()->getAs()) { OS << vector->getNumElements(); OS << " * sizeof("; print(vector->getElementType(), OS, StringRef()); @@ -1285,7 +1281,7 @@ OS << "neon_vector_type("; else OS << "neon_polyvector_type("; - const VectorType *vector = T->getEquivalentType()->getAs(); + const auto *vector = T->getEquivalentType()->getAs(); OS << vector->getNumElements(); OS << ')'; break; Index: lib/AST/VTableBuilder.cpp =================================================================== --- lib/AST/VTableBuilder.cpp +++ lib/AST/VTableBuilder.cpp @@ -271,9 +271,9 @@ ComputeReturnAdjustmentBaseOffset(ASTContext &Context, const CXXMethodDecl *DerivedMD, const CXXMethodDecl *BaseMD) { - const FunctionType *BaseFT = BaseMD->getType()->getAs(); - const FunctionType *DerivedFT = DerivedMD->getType()->getAs(); - + const auto *BaseFT = BaseMD->getType()->getAs(); + const auto *DerivedFT = DerivedMD->getType()->getAs(); + // Canonicalize the return types. CanQualType CanDerivedReturnType = Context.getCanonicalType(DerivedFT->getReturnType()); @@ -1296,7 +1296,7 @@ void ItaniumVTableBuilder::AddMethod(const CXXMethodDecl *MD, ReturnAdjustment ReturnAdjustment) { - if (const CXXDestructorDecl *DD = dyn_cast(MD)) { + if (const auto *DD = dyn_cast(MD)) { assert(ReturnAdjustment.isEmpty() && "Destructor can't have return adjustment!"); @@ -1547,7 +1547,7 @@ } } - if (const CXXDestructorDecl *DD = dyn_cast(MD)) { + if (const auto *DD = dyn_cast(MD)) { if (MD->isImplicit()) { // Itanium C++ ABI 2.5.2: // If a class has an implicitly-defined virtual destructor, @@ -1673,7 +1673,7 @@ for (const auto &I : MethodInfoMap) { const CXXMethodDecl *MD = I.first; const MethodInfo &MI = I.second; - if (const CXXDestructorDecl *DD = dyn_cast(MD)) { + if (const auto *DD = dyn_cast(MD)) { MethodVTableIndices[GlobalDecl(DD, Dtor_Complete)] = MI.VTableIndex - AddressPoint; MethodVTableIndices[GlobalDecl(DD, Dtor_Deleting)] @@ -2169,7 +2169,7 @@ PredefinedExpr::ComputeName(PredefinedExpr::PrettyFunctionNoVirtual, MD); - if (const CXXDestructorDecl *DD = dyn_cast(MD)) { + if (const auto *DD = dyn_cast(MD)) { GlobalDecl GD(DD, Dtor_Complete); assert(MethodVTableIndices.count(GD)); uint64_t VTableIndex = MethodVTableIndices[GD]; @@ -2480,7 +2480,7 @@ VTableThunks[Components.size()] = TI; AddThunk(MD, TI); } - if (const CXXDestructorDecl *DD = dyn_cast(MD)) { + if (const auto *DD = dyn_cast(MD)) { assert(TI.Return.isEmpty() && "Destructor can't have return adjustment!"); Components.push_back(VTableComponent::MakeDeletingDtor(DD)); @@ -2516,7 +2516,7 @@ continue; MethodVFTableLocation Loc(MI.VBTableIndex, WhichVFPtr.getVBaseWithVPtr(), WhichVFPtr.NonVirtualOffset, MI.VFTableIndex); - if (const CXXDestructorDecl *DD = dyn_cast(MD)) { + if (const auto *DD = dyn_cast(MD)) { MethodVFTableLocations[GlobalDecl(DD, Dtor_Deleting)] = Loc; } else { MethodVFTableLocations[MD] = Loc; @@ -3601,7 +3601,7 @@ bool HasNonzeroOffset = false; for (const auto &I : NewMethods) { - const CXXMethodDecl *MD = cast(I.first.getDecl()); + const auto *MD = cast(I.first.getDecl()); assert(MD->isVirtual()); std::string MethodName = PredefinedExpr::ComputeName( Index: lib/ASTMatchers/ASTMatchFinder.cpp =================================================================== --- lib/ASTMatchers/ASTMatchFinder.cpp +++ lib/ASTMatchers/ASTMatchFinder.cpp @@ -112,19 +112,17 @@ // recursion. bool findMatch(const ast_type_traits::DynTypedNode &DynNode) { reset(); - if (const Decl *D = DynNode.get()) + if (const auto *D = DynNode.get()) traverse(*D); - else if (const Stmt *S = DynNode.get()) + else if (const auto *S = DynNode.get()) traverse(*S); - else if (const NestedNameSpecifier *NNS = - DynNode.get()) + else if (const auto *NNS = DynNode.get()) traverse(*NNS); - else if (const NestedNameSpecifierLoc *NNSLoc = - DynNode.get()) + else if (const auto *NNSLoc = DynNode.get()) traverse(*NNSLoc); - else if (const QualType *Q = DynNode.get()) + else if (const auto *Q = DynNode.get()) traverse(*Q); - else if (const TypeLoc *T = DynNode.get()) + else if (const auto *T = DynNode.get()) traverse(*T); else if (const auto *C = DynNode.get()) traverse(*C); @@ -401,7 +399,7 @@ // Note that we key on the bindings *before* the match. Key.BoundNodes = *Builder; - MemoizationMap::iterator I = ResultCache.find(Key); + auto I = ResultCache.find(Key); if (I != ResultCache.end()) { *Builder = I->second.Nodes; return I->second.ResultOfMatch; @@ -645,7 +643,7 @@ // Note that we cannot use insert and reuse the iterator, as recursive // calls to match might invalidate the result cache iterators. - MemoizationMap::iterator I = ResultCache.find(Key); + auto I = ResultCache.find(Key); if (I != ResultCache.end()) { *Builder = I->second.Nodes; return I->second.ResultOfMatch; Index: lib/ASTMatchers/Dynamic/Marshallers.h =================================================================== --- lib/ASTMatchers/Dynamic/Marshallers.h +++ lib/ASTMatchers/Dynamic/Marshallers.h @@ -302,7 +302,7 @@ VariantMatcher variadicMatcherDescriptor(StringRef MatcherName, SourceRange NameRange, ArrayRef Args, Diagnostics *Error) { - ArgT **InnerArgs = new ArgT *[Args.size()](); + auto **InnerArgs = new ArgT *[Args.size()](); bool HasError = false; for (size_t i = 0, e = Args.size(); i != e; ++i) { Index: lib/ASTMatchers/Dynamic/Parser.cpp =================================================================== --- lib/ASTMatchers/Dynamic/Parser.cpp +++ lib/ASTMatchers/Dynamic/Parser.cpp @@ -465,9 +465,7 @@ // We cannot complete code if there is an invalid element on the context // stack. - for (ContextStackTy::iterator I = ContextStack.begin(), - E = ContextStack.end(); - I != E; ++I) { + for (auto I = ContextStack.begin(), E = ContextStack.end(); I != E; ++I) { if (!I->first) return; } Index: lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- lib/ASTMatchers/Dynamic/Registry.cpp +++ lib/ASTMatchers/Dynamic/Registry.cpp @@ -449,8 +449,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const std::set &KS) { unsigned Count = 0; - for (std::set::const_iterator I = KS.begin(), E = KS.end(); - I != E; ++I) { + for (auto I = KS.begin(), E = KS.end(); I != E; ++I) { if (I != KS.begin()) OS << "|"; if (Count++ == 3) { Index: lib/Analysis/AnalysisDeclContext.cpp =================================================================== --- lib/Analysis/AnalysisDeclContext.cpp +++ lib/Analysis/AnalysisDeclContext.cpp @@ -84,13 +84,13 @@ void AnalysisDeclContextManager::clear() { Contexts.clear(); } static BodyFarm &getBodyFarm(ASTContext &C, CodeInjector *injector = nullptr) { - static BodyFarm *BF = new BodyFarm(C, injector); + static auto *BF = new BodyFarm(C, injector); return *BF; } Stmt *AnalysisDeclContext::getBody(bool &IsAutosynthesized) const { IsAutosynthesized = false; - if (const FunctionDecl *FD = dyn_cast(D)) { + if (const auto *FD = dyn_cast(D)) { Stmt *Body = FD->getBody(); if (Manager && Manager->synthesizeBodies()) { Stmt *SynthesizedBody = @@ -101,8 +101,7 @@ } } return Body; - } - else if (const ObjCMethodDecl *MD = dyn_cast(D)) { + } else if (const auto *MD = dyn_cast(D)) { Stmt *Body = MD->getBody(); if (Manager && Manager->synthesizeBodies()) { Stmt *SynthesizedBody = @@ -113,10 +112,9 @@ } } return Body; - } else if (const BlockDecl *BD = dyn_cast(D)) + } else if (const auto *BD = dyn_cast(D)) return BD->getBody(); - else if (const FunctionTemplateDecl *FunTmpl - = dyn_cast_or_null(D)) + else if (const auto *FunTmpl = dyn_cast_or_null(D)) return FunTmpl->getTemplatedDecl()->getBody(); llvm_unreachable("unknown code decl"); @@ -145,9 +143,9 @@ } const ImplicitParamDecl *AnalysisDeclContext::getSelfDecl() const { - if (const ObjCMethodDecl *MD = dyn_cast(D)) + if (const auto *MD = dyn_cast(D)) return MD->getSelfDecl(); - if (const BlockDecl *BD = dyn_cast(D)) { + if (const auto *BD = dyn_cast(D)) { // See if 'self' was captured by the block. for (const auto &I : BD->captures()) { const VarDecl *VD = I.getVariable(); @@ -180,7 +178,7 @@ if (!forcedBlkExprs) forcedBlkExprs = new CFG::BuildOptions::ForcedBlkExprs(); // Default construct an entry for 'stmt'. - if (const Expr *e = dyn_cast(stmt)) + if (const auto *e = dyn_cast(stmt)) stmt = e->IgnoreParens(); (void) (*forcedBlkExprs)[stmt]; } @@ -188,7 +186,7 @@ const CFGBlock * AnalysisDeclContext::getBlockForRegisteredExpression(const Stmt *stmt) { assert(forcedBlkExprs); - if (const Expr *e = dyn_cast(stmt)) + if (const auto *e = dyn_cast(stmt)) stmt = e->IgnoreParens(); CFG::BuildOptions::ForcedBlkExprs::const_iterator itr = forcedBlkExprs->find(stmt); @@ -278,7 +276,7 @@ ParentMap &AnalysisDeclContext::getParentMap() { if (!PM) { PM.reset(new ParentMap(getBody())); - if (const CXXConstructorDecl *C = dyn_cast(getDecl())) { + if (const auto *C = dyn_cast(getDecl())) { for (const auto *I : C->inits()) { PM->addStmt(I->getInit()); } @@ -298,7 +296,7 @@ } AnalysisDeclContext *AnalysisDeclContextManager::getContext(const Decl *D) { - if (const FunctionDecl *FD = dyn_cast(D)) { + if (const auto *FD = dyn_cast(D)) { // Calling 'hasBody' replaces 'FD' in place with the FunctionDecl // that has the body. FD->hasBody(FD); @@ -327,7 +325,7 @@ bool AnalysisDeclContext::isInStdNamespace(const Decl *D) { const DeclContext *DC = D->getDeclContext()->getEnclosingNamespaceContext(); - const NamespaceDecl *ND = dyn_cast(DC); + const auto *ND = dyn_cast(DC); if (!ND) return false; @@ -386,7 +384,7 @@ LOC::Profile(ID, ctx, parent, d); void *InsertPos; - LOC *L = cast_or_null(Contexts.FindNodeOrInsertPos(ID, InsertPos)); + auto *L = cast_or_null(Contexts.FindNodeOrInsertPos(ID, InsertPos)); if (!L) { L = new LOC(ctx, parent, d); @@ -403,8 +401,8 @@ llvm::FoldingSetNodeID ID; StackFrameContext::Profile(ID, ctx, parent, s, blk, idx); void *InsertPos; - StackFrameContext *L = - cast_or_null(Contexts.FindNodeOrInsertPos(ID, InsertPos)); + auto *L = cast_or_null( + Contexts.FindNodeOrInsertPos(ID, InsertPos)); if (!L) { L = new StackFrameContext(ctx, parent, s, blk, idx); Contexts.InsertNode(L, InsertPos); @@ -427,9 +425,8 @@ llvm::FoldingSetNodeID ID; BlockInvocationContext::Profile(ID, ctx, parent, BD, ContextData); void *InsertPos; - BlockInvocationContext *L = - cast_or_null(Contexts.FindNodeOrInsertPos(ID, - InsertPos)); + auto *L = cast_or_null( + Contexts.FindNodeOrInsertPos(ID, InsertPos)); if (!L) { L = new BlockInvocationContext(ctx, parent, BD, ContextData); Contexts.InsertNode(L, InsertPos); @@ -444,7 +441,7 @@ const StackFrameContext *LocationContext::getCurrentStackFrame() const { const LocationContext *LC = this; while (LC) { - if (const StackFrameContext *SFC = dyn_cast(LC)) + if (const auto *SFC = dyn_cast(LC)) return SFC; LC = LC->getParent(); } @@ -537,7 +534,7 @@ for (PseudoObjectExpr::semantics_iterator it = PE->semantics_begin(), et = PE->semantics_end(); it != et; ++it) { Expr *Semantic = *it; - if (OpaqueValueExpr *OVE = dyn_cast(Semantic)) + if (auto *OVE = dyn_cast(Semantic)) Semantic = OVE->getSourceExpr(); Visit(Semantic); } @@ -554,7 +551,7 @@ return (DeclVec*) Vec; BumpVectorContext BC(A); - DeclVec *BV = (DeclVec*) A.Allocate(); + auto *BV = (DeclVec *)A.Allocate(); new (BV) DeclVec(BC, 10); // Go through the capture list. @@ -583,7 +580,7 @@ ManagedAnalysis *&AnalysisDeclContext::getAnalysisImpl(const void *tag) { if (!ManagedAnalyses) ManagedAnalyses = new ManagedAnalysisMap(); - ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses; + auto *M = (ManagedAnalysisMap *)ManagedAnalyses; return (*M)[tag]; } @@ -598,7 +595,7 @@ delete ReferencedBlockVars; // Release the managed analyses. if (ManagedAnalyses) { - ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses; + auto *M = (ManagedAnalysisMap *)ManagedAnalyses; llvm::DeleteContainerSeconds(*M); delete M; } Index: lib/Analysis/BodyFarm.cpp =================================================================== --- lib/Analysis/BodyFarm.cpp +++ lib/Analysis/BodyFarm.cpp @@ -28,14 +28,13 @@ static bool isDispatchBlock(QualType Ty) { // Is it a block pointer? - const BlockPointerType *BPT = Ty->getAs(); + const auto *BPT = Ty->getAs(); if (!BPT) return false; // Check if the block pointer type takes no arguments and // returns void. - const FunctionProtoType *FT = - BPT->getPointeeType()->getAs(); + const auto *FT = BPT->getPointeeType()->getAs(); return FT && FT->getReturnType()->isVoidType() && FT->getNumParams() == 0; } @@ -176,7 +175,7 @@ // Check if the first parameter is a pointer to integer type. const ParmVarDecl *Predicate = D->getParamDecl(0); QualType PredicateQPtrTy = Predicate->getType(); - const PointerType *PredicatePtrTy = PredicateQPtrTy->getAs(); + const auto *PredicatePtrTy = PredicateQPtrTy->getAs(); if (!PredicatePtrTy) return nullptr; QualType PredicateTy = PredicatePtrTy->getPointeeType(); @@ -303,7 +302,7 @@ const ParmVarDecl *TheValue = D->getParamDecl(2); QualType TheValueTy = TheValue->getType(); - const PointerType *PT = TheValueTy->getAs(); + const auto *PT = TheValueTy->getAs(); if (!PT) return nullptr; QualType PointeeTy = PT->getPointeeType(); Index: lib/Analysis/CFG.cpp =================================================================== --- lib/Analysis/CFG.cpp +++ lib/Analysis/CFG.cpp @@ -33,7 +33,7 @@ namespace { static SourceLocation GetEndLoc(Decl *D) { - if (VarDecl *VD = dyn_cast(D)) + if (auto *VD = dyn_cast(D)) if (Expr *Ex = VD->getInit()) return Ex->getSourceRange().getEnd(); return D->getLocation(); @@ -325,14 +325,14 @@ reverse_children::reverse_children(Stmt *S) { - if (CallExpr *CE = dyn_cast(S)) { + if (auto *CE = dyn_cast(S)) { children = CE->getRawSubExprs(); return; } switch (S->getStmtClass()) { // Note: Fill in this switch with more cases we want to optimize. case Stmt::InitListExprClass: { - InitListExpr *IE = cast(S); + auto *IE = cast(S); children = llvm::makeArrayRef(reinterpret_cast(IE->getInits()), IE->getNumInits()); return; @@ -645,7 +645,7 @@ const Expr *LHSExpr = B->getLHS()->IgnoreParens(); const Expr *RHSExpr = B->getRHS()->IgnoreParens(); - const IntegerLiteral *IntLiteral = dyn_cast(LHSExpr); + const auto *IntLiteral = dyn_cast(LHSExpr); const Expr *BoolExpr = RHSExpr; bool IntFirst = true; if (!IntLiteral) { @@ -684,7 +684,7 @@ const Expr *LHSExpr = B->getLHS()->IgnoreParens(); const Expr *RHSExpr = B->getRHS()->IgnoreParens(); - const IntegerLiteral *IntLiteral = dyn_cast(LHSExpr); + const auto *IntLiteral = dyn_cast(LHSExpr); const Expr *BoolExpr = RHSExpr; if (!IntLiteral) { @@ -695,13 +695,13 @@ if (!IntLiteral) return TryResult(); - const BinaryOperator *BitOp = dyn_cast(BoolExpr); + const auto *BitOp = dyn_cast(BoolExpr); if (BitOp && (BitOp->getOpcode() == BO_And || BitOp->getOpcode() == BO_Or)) { const Expr *LHSExpr2 = BitOp->getLHS()->IgnoreParens(); const Expr *RHSExpr2 = BitOp->getRHS()->IgnoreParens(); - const IntegerLiteral *IntLiteral2 = dyn_cast(LHSExpr2); + const auto *IntLiteral2 = dyn_cast(LHSExpr2); if (!IntLiteral2) IntLiteral2 = dyn_cast(RHSExpr2); @@ -866,7 +866,7 @@ S->isTypeDependent() || S->isValueDependent()) return TryResult(); - if (BinaryOperator *Bop = dyn_cast(S)) { + if (auto *Bop = dyn_cast(S)) { if (Bop->isLogicalOp()) { // Check the cache first. CachedBoolEvalsTy::iterator I = CachedBoolEvals.find(S); @@ -909,7 +909,7 @@ /// \brief Evaluate as boolean \param E without using the cache. TryResult evaluateAsBooleanConditionNoCache(Expr *E) { - if (BinaryOperator *Bop = dyn_cast(E)) { + if (auto *Bop = dyn_cast(E)) { if (Bop->isLogicalOp()) { TryResult LHS = tryEvaluateBool(Bop->getLHS()); if (LHS.isKnown()) { @@ -1003,8 +1003,8 @@ // FIXME: Add support for dependent-sized array types in C++? // Does it even make sense to build a CFG for an uninstantiated template? static const VariableArrayType *FindVA(const Type *t) { - while (const ArrayType *vt = dyn_cast(t)) { - if (const VariableArrayType *vat = dyn_cast(vt)) + while (const auto *vt = dyn_cast(t)) { + if (const auto *vat = dyn_cast(vt)) if (vat->getSizeExpr()) return vat; @@ -1032,7 +1032,7 @@ Block = nullptr; // the EXIT block is empty. Create all other blocks lazily. if (BuildOpts.AddImplicitDtors) - if (const CXXDestructorDecl *DD = dyn_cast_or_null(D)) + if (const auto *DD = dyn_cast_or_null(D)) addImplicitDtorsForDestructor(DD); // Visit the statements and create the CFG. @@ -1042,7 +1042,7 @@ return nullptr; // For C++ constructor add initializers to CFG. - if (const CXXConstructorDecl *CD = dyn_cast_or_null(D)) { + if (const auto *CD = dyn_cast_or_null(D)) { for (auto *I : llvm::reverse(CD->inits())) { B = addInitializer(I); if (badCFG) @@ -1055,8 +1055,8 @@ // Backpatch the gotos whose label -> block mappings we didn't know when we // encountered them. - for (BackpatchBlocksTy::iterator I = BackpatchBlocks.begin(), - E = BackpatchBlocks.end(); I != E; ++I ) { + for (auto I = BackpatchBlocks.begin(), E = BackpatchBlocks.end(); I != E; + ++I) { CFGBlock *B = I->block; const GotoStmt *G = cast(B->getTerminator()); @@ -1143,7 +1143,7 @@ return Visit(cast(Init)->getSubExpr()); } if (BuildOpts.AddCXXDefaultInitExprInCtors) { - if (CXXDefaultInitExpr *Default = dyn_cast(Init)) { + if (auto *Default = dyn_cast(Init)) { // In general, appending the expression wrapped by a CXXDefaultInitExpr // may cause the same Expr to appear more than once in the CFG. Doing it // here is safe because there's only one initializer per field. @@ -1171,14 +1171,13 @@ Init = Init->IgnoreParens(); // Skip through cleanups. - if (const ExprWithCleanups *EWC = dyn_cast(Init)) { + if (const auto *EWC = dyn_cast(Init)) { Init = EWC->getSubExpr(); continue; } // Skip through the temporary-materialization expression. - if (const MaterializeTemporaryExpr *MTE - = dyn_cast(Init)) { + if (const auto *MTE = dyn_cast(Init)) { Init = MTE->GetTemporaryExpr(); if (FoundMTE) *FoundMTE = true; @@ -1186,7 +1185,7 @@ } // Skip derived-to-base and no-op casts. - if (const CastExpr *CE = dyn_cast(Init)) { + if (const auto *CE = dyn_cast(Init)) { if ((CE->getCastKind() == CK_DerivedToBase || CE->getCastKind() == CK_UncheckedDerivedToBase || CE->getCastKind() == CK_NoOp) && @@ -1197,7 +1196,7 @@ } // Skip member accesses into rvalues. - if (const MemberExpr *ME = dyn_cast(Init)) { + if (const auto *ME = dyn_cast(Init)) { if (!ME->isArrow() && ME->getBase()->isRValue()) { Init = ME->getBase(); continue; @@ -1315,10 +1314,10 @@ LocalScope *Scope = nullptr; // For compound statement we will be creating explicit scope. - if (CompoundStmt *CS = dyn_cast(S)) { + if (auto *CS = dyn_cast(S)) { for (auto *BI : CS->body()) { Stmt *SI = BI->stripLabelLikeStatements(); - if (DeclStmt *DS = dyn_cast(SI)) + if (auto *DS = dyn_cast(SI)) Scope = addLocalScopeForDeclStmt(DS, Scope); } return; @@ -1326,7 +1325,7 @@ // For any other statement scope will be implicit and as such will be // interesting only for DeclStmt. - if (DeclStmt *DS = dyn_cast(S->stripLabelLikeStatements())) + if (auto *DS = dyn_cast(S->stripLabelLikeStatements())) addLocalScopeForDeclStmt(DS); } @@ -1338,7 +1337,7 @@ return Scope; for (auto *DI : DS->decls()) - if (VarDecl *VD = dyn_cast(DI)) + if (auto *VD = dyn_cast(DI)) Scope = addLocalScopeForVarDecl(VD, Scope); return Scope; } @@ -1436,7 +1435,7 @@ return nullptr; } - if (Expr *E = dyn_cast(S)) + if (auto *E = dyn_cast(S)) S = E->IgnoreParens(); switch (S->getStmtClass()) { @@ -1677,7 +1676,7 @@ CFGBlock *RHSBlock, *ExitBlock; do { - if (BinaryOperator *B_RHS = dyn_cast(RHS)) + if (auto *B_RHS = dyn_cast(RHS)) if (B_RHS->isLogicalOp()) { std::tie(RHSBlock, ExitBlock) = VisitLogicalOperator(B_RHS, Term, TrueBlock, FalseBlock); @@ -1714,7 +1713,7 @@ // Generate the blocks for evaluating the LHS. Expr *LHS = B->getLHS()->IgnoreParens(); - if (BinaryOperator *B_LHS = dyn_cast(LHS)) + if (auto *B_LHS = dyn_cast(LHS)) if (B_LHS->isLogicalOp()) { if (B->getOpcode() == BO_LOr) FalseBlock = RHSBlock; @@ -1827,9 +1826,9 @@ else if (Ty->isBlockPointerType()) Ty = Ty->getAs()->getPointeeType(); - const FunctionType *FT = Ty->getAs(); + const auto *FT = Ty->getAs(); if (FT) { - if (const FunctionProtoType *Proto = dyn_cast(FT)) + if (const auto *Proto = dyn_cast(FT)) if (!isUnresolvedExceptionSpec(Proto->getExceptionSpecType()) && Proto->isNothrow(Ctx)) return false; @@ -2006,8 +2005,7 @@ return nullptr; // If the condition is a logical '&&' or '||', build a more accurate CFG. - if (BinaryOperator *Cond = - dyn_cast(C->getCond()->IgnoreParens())) + if (auto *Cond = dyn_cast(C->getCond()->IgnoreParens())) if (Cond->isLogicalOp()) return VisitLogicalOperator(Cond, C, LHSBlock, RHSBlock).first; @@ -2073,7 +2071,7 @@ /// DeclStmts and initializers in them. CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) { assert(DS->isSingleDecl() && "Can handle single declarations only."); - VarDecl *VD = dyn_cast(DS->getSingleDecl()); + auto *VD = dyn_cast(DS->getSingleDecl()); if (!VD) { // Of everything that can be declared in a DeclStmt, only VarDecls impact @@ -2124,7 +2122,7 @@ if (HasTemporaries) { // For expression with temporaries go directly to subexpression to omit // generating destructors for the second time. - ExprWithCleanups *EC = cast(Init); + auto *EC = cast(Init); if (CFGBlock *newBlock = Visit(EC->getSubExpr())) LastBlock = newBlock; } @@ -2253,8 +2251,7 @@ // control-flow transfer of '&&' or '||' go directly into the then/else // blocks directly. if (!I->getConditionVariable()) - if (BinaryOperator *Cond = - dyn_cast(I->getCond()->IgnoreParens())) + if (auto *Cond = dyn_cast(I->getCond()->IgnoreParens())) if (Cond->isLogicalOp()) return VisitLogicalOperator(Cond, I, ThenBlock, ElseBlock).first; @@ -2493,7 +2490,7 @@ // Specially handle logical operators, which have a slightly // more optimal CFG representation. - if (BinaryOperator *Cond = + if (auto *Cond = dyn_cast_or_null(C ? C->IgnoreParens() : nullptr)) if (Cond->isLogicalOp()) { std::tie(EntryConditionBlock, ExitConditionBlock) = @@ -2728,7 +2725,7 @@ // If the semantic is an opaque value, we're being asked to bind // it to its source expression. - if (OpaqueValueExpr *OVE = dyn_cast(Semantic)) + if (auto *OVE = dyn_cast(Semantic)) Semantic = OVE->getSourceExpr(); if (CFGBlock *B = Visit(Semantic)) @@ -2811,7 +2808,7 @@ // Specially handle logical operators, which have a slightly // more optimal CFG representation. - if (BinaryOperator *Cond = dyn_cast(C->IgnoreParens())) + if (auto *Cond = dyn_cast(C->IgnoreParens())) if (Cond->isLogicalOp()) { std::tie(EntryConditionBlock, ExitConditionBlock) = VisitLogicalOperator(Cond, W, BodyBlock, LoopSuccessor); @@ -3874,7 +3871,7 @@ bool first_block = begin() == end(); // Create the block. - CFGBlock *Mem = getAllocator().Allocate(); + auto *Mem = getAllocator().Allocate(); new (Mem) CFGBlock(NumBlockIDs++, BlkBVC, this); Blocks.push_back(Mem, BlkBVC); @@ -3986,8 +3983,8 @@ if (To && From && F.IgnoreDefaultsWithCoveredEnums) { // If the 'To' has no label or is labeled but the label isn't a // CaseStmt then filter this edge. - if (const SwitchStmt *S = - dyn_cast_or_null(From->getTerminator().getStmt())) { + if (const auto *S = + dyn_cast_or_null(From->getTerminator().getStmt())) { if (S->isAllEnumCasesCovered()) { const Stmt *L = To->getLabel(); if (!L || !isa(L)) @@ -4137,7 +4134,7 @@ } void VisitDeclStmt(DeclStmt *DS) { - VarDecl *VD = cast(DS->getSingleDecl()); + auto *VD = cast(DS->getSingleDecl()); OS << "static init " << VD->getName(); } @@ -4235,7 +4232,7 @@ assert(S != nullptr && "Expecting non-null Stmt"); // special printing for statement-expressions. - if (const StmtExpr *SE = dyn_cast(S)) { + if (const auto *SE = dyn_cast(S)) { const CompoundStmt *Sub = SE->getSubStmt(); auto Children = Sub->children(); @@ -4247,7 +4244,7 @@ } } // special printing for comma expressions. - if (const BinaryOperator* B = dyn_cast(S)) { + if (const auto *B = dyn_cast(S)) { if (B->getOpcode() == BO_Comma) { OS << "... , "; Helper.handledStmt(B->getRHS(),OS); @@ -4262,11 +4259,9 @@ } else if (isa(S)) { OS << " (BindTemporary)"; - } - else if (const CXXConstructExpr *CCE = dyn_cast(S)) { + } else if (const auto *CCE = dyn_cast(S)) { OS << " (CXXConstructExpr, " << CCE->getType().getAsString() << ")"; - } - else if (const CastExpr *CE = dyn_cast(S)) { + } else if (const auto *CE = dyn_cast(S)) { OS << " (" << CE->getStmtClassName() << ", " << CE->getCastKindName() << ", " << CE->getType().getAsString() @@ -4302,7 +4297,7 @@ Helper.handleDecl(VD, OS); const Type* T = VD->getType().getTypePtr(); - if (const ReferenceType* RT = T->getAs()) + if (const auto *RT = T->getAs()) T = RT->getPointeeType().getTypePtr(); T = T->getBaseElementTypeUnsafe(); @@ -4318,8 +4313,7 @@ const CXXRecordDecl *RD = DE->getCXXRecordDecl(); if (!RD) return; - CXXDeleteExpr *DelExpr = - const_cast(DE->getDeleteExpr()); + auto *DelExpr = const_cast(DE->getDeleteExpr()); Helper.handledStmt(cast(DelExpr->getArgument()), OS); OS << "->~" << RD->getName().str() << "()"; OS << " (Implicit destructor)\n"; @@ -4371,14 +4365,14 @@ OS.resetColor(); // Print the label of this block. - if (Stmt *Label = const_cast(B.getLabel())) { + if (auto *Label = const_cast(B.getLabel())) { if (print_edges) OS << " "; - if (LabelStmt *L = dyn_cast(Label)) + if (auto *L = dyn_cast(Label)) OS << L->getName(); - else if (CaseStmt *C = dyn_cast(Label)) { + else if (auto *C = dyn_cast(Label)) { OS << "case "; if (C->getLHS()) C->getLHS()->printPretty(OS, &Helper, @@ -4390,7 +4384,7 @@ } } else if (isa(Label)) OS << "default"; - else if (CXXCatchStmt *CS = dyn_cast(Label)) { + else if (auto *CS = dyn_cast(Label)) { OS << "catch ("; if (CS->getExceptionDecl()) CS->getExceptionDecl()->print(OS, PrintingPolicy(Helper.getLangOpts()), Index: lib/Analysis/CFGStmtMap.cpp =================================================================== --- lib/Analysis/CFGStmtMap.cpp +++ lib/Analysis/CFGStmtMap.cpp @@ -79,7 +79,7 @@ if (!C || !PM) return nullptr; - SMap *SM = new SMap(); + auto *SM = new SMap(); // Walk all blocks, accumulating the block-level expressions, labels, // and terminators. Index: lib/Analysis/CallGraph.cpp =================================================================== --- lib/Analysis/CallGraph.cpp +++ lib/Analysis/CallGraph.cpp @@ -44,7 +44,7 @@ // Simple detection of a call through a block. Expr *CEE = CE->getCallee()->IgnoreParenImpCasts(); - if (BlockExpr *Block = dyn_cast(CEE)) { + if (auto *Block = dyn_cast(CEE)) { NumBlockCallEdges++; return Block->getBlockDecl(); } @@ -92,7 +92,7 @@ } // end anonymous namespace void CallGraph::addNodesForBlocks(DeclContext *D) { - if (BlockDecl *BD = dyn_cast(D)) + if (auto *BD = dyn_cast(D)) addNodeForDecl(BD, true); for (auto *I : D->decls()) @@ -111,7 +111,7 @@ if (!D->hasBody()) return false; - if (const FunctionDecl *FD = dyn_cast(D)) { + if (const auto *FD = dyn_cast(D)) { // We skip function template definitions, as their semantics is // only determined when they are instantiated. if (FD->isDependentContext()) @@ -164,8 +164,7 @@ // We are going to print the graph in reverse post order, partially, to make // sure the output is deterministic. llvm::ReversePostOrderTraversal RPOT(this); - for (llvm::ReversePostOrderTraversal::rpo_iterator - I = RPOT.begin(), E = RPOT.end(); I != E; ++I) { + for (auto I = RPOT.begin(), E = RPOT.end(); I != E; ++I) { const CallGraphNode *N = *I; OS << " Function: "; Index: lib/Analysis/CloneDetection.cpp =================================================================== --- lib/Analysis/CloneDetection.cpp +++ lib/Analysis/CloneDetection.cpp @@ -427,7 +427,7 @@ auto numDecls = std::distance(S->decl_begin(), S->decl_end()); addData(static_cast(numDecls)); for (const Decl *D : S->decls()) { - if (const VarDecl *VD = dyn_cast(D)) { + if (const auto *VD = dyn_cast(D)) { addData(VD->getType()); } } @@ -501,7 +501,7 @@ // Storage for the signatures of the direct child statements. This is only // needed if the current statement is a CompoundStmt. std::vector ChildSignatures; - const CompoundStmt *CS = dyn_cast(S); + const auto *CS = dyn_cast(S); // The signature of a statement includes the signatures of its children. // Therefore we create the signatures for every child and add them to the Index: lib/Analysis/CocoaConventions.cpp =================================================================== --- lib/Analysis/CocoaConventions.cpp +++ lib/Analysis/CocoaConventions.cpp @@ -39,7 +39,7 @@ return false; // Is the type void*? - const PointerType* PT = RetTy->getAs(); + const auto *PT = RetTy->getAs(); if (!(PT->getPointeeType().getUnqualifiedType()->isVoidType())) return false; @@ -59,9 +59,9 @@ bool cocoa::isCocoaObjectRef(QualType Ty) { if (!Ty->isObjCObjectPointerType()) return false; - - const ObjCObjectPointerType *PT = Ty->getAs(); - + + const auto *PT = Ty->getAs(); + // Can be true for objects with the 'NSObject' attribute. if (!PT) return true; Index: lib/Analysis/Consumed.cpp =================================================================== --- lib/Analysis/Consumed.cpp +++ lib/Analysis/Consumed.cpp @@ -630,7 +630,7 @@ PropagationInfo PInfo = Entry->second; // Check that the parameter is in the correct state. - if (ParamTypestateAttr *PTA = Param->getAttr()) { + if (auto *PTA = Param->getAttr()) { ConsumedState ParamState = PInfo.getAsState(StateMap); ConsumedState ExpectedState = mapParamTypestateAttrState(PTA); @@ -646,7 +646,7 @@ // Adjust state on the caller side. if (isRValueRef(ParamType)) setStateForVarOrTmp(StateMap, PInfo, consumed::CS_Consumed); - else if (ReturnTypestateAttr *RT = Param->getAttr()) + else if (auto *RT = Param->getAttr()) setStateForVarOrTmp(StateMap, PInfo, mapReturnTypestateAttrState(RT)); else if (isPointerOrRef(ParamType) && (!ParamType->getPointeeType().isConstQualified() || @@ -663,7 +663,7 @@ PropagationInfo PInfo = Entry->second; checkCallability(PInfo, FunD, Call->getExprLoc()); - if (SetTypestateAttr *STA = FunD->getAttr()) { + if (auto *STA = FunD->getAttr()) { if (PInfo.isVar()) { StateMap->setState(PInfo.getVar(), mapSetTypestateAttrState(STA)); return true; @@ -690,7 +690,7 @@ if (isConsumableType(RetType)) { ConsumedState ReturnState; - if (ReturnTypestateAttr *RTA = Fun->getAttr()) + if (auto *RTA = Fun->getAttr()) ReturnState = mapReturnTypestateAttrState(RTA); else ReturnState = mapConsumableAttrState(RetType); @@ -784,7 +784,7 @@ return; // FIXME: What should happen if someone annotates the move constructor? - if (ReturnTypestateAttr *RTA = Constructor->getAttr()) { + if (auto *RTA = Constructor->getAttr()) { // TODO: Adjust state of args appropriately. ConsumedState RetState = mapReturnTypestateAttrState(RTA); PropagationMap.insert(PairType(Call, PropagationInfo(RetState))); @@ -821,8 +821,7 @@ void ConsumedStmtVisitor::VisitCXXOperatorCallExpr( const CXXOperatorCallExpr *Call) { - const FunctionDecl *FunDecl = - dyn_cast_or_null(Call->getDirectCallee()); + const auto *FunDecl = dyn_cast_or_null(Call->getDirectCallee()); if (!FunDecl) return; if (Call->getOperator() == OO_Equal) { @@ -832,7 +831,7 @@ return; } - if (const CXXMemberCallExpr *MCall = dyn_cast(Call)) + if (const auto *MCall = dyn_cast(Call)) handleCall(MCall, MCall->getImplicitObjectArgument(), FunDecl); else handleCall(Call, Call->getArg(0), FunDecl); @@ -841,7 +840,7 @@ } void ConsumedStmtVisitor::VisitDeclRefExpr(const DeclRefExpr *DeclRef) { - if (const VarDecl *Var = dyn_cast_or_null(DeclRef->getDecl())) + if (const auto *Var = dyn_cast_or_null(DeclRef->getDecl())) if (StateMap->getState(Var) != consumed::CS_None) PropagationMap.insert(PairType(DeclRef, PropagationInfo(Var))); } @@ -852,7 +851,7 @@ VisitVarDecl(cast(DI)); if (DeclS->isSingleDecl()) - if (const VarDecl *Var = dyn_cast_or_null(DeclS->getSingleDecl())) + if (const auto *Var = dyn_cast_or_null(DeclS->getSingleDecl())) PropagationMap.insert(PairType(DeclS, PropagationInfo(Var))); } @@ -1120,7 +1119,7 @@ for (const auto &DM : VarMap) { if (isa(DM.first)) { - const ParmVarDecl *Param = cast(DM.first); + const auto *Param = cast(DM.first); const ReturnTypestateAttr *RTA = Param->getAttr(); if (!RTA) @@ -1227,7 +1226,7 @@ void ConsumedAnalyzer::determineExpectedReturnState(AnalysisDeclContext &AC, const FunctionDecl *D) { QualType ReturnType; - if (const CXXConstructorDecl *Constructor = dyn_cast(D)) { + if (const auto *Constructor = dyn_cast(D)) { ASTContext &CurrContext = AC.getASTContext(); ReturnType = Constructor->getThisType(CurrContext)->getPointeeType(); } else @@ -1261,10 +1260,10 @@ std::unique_ptr FalseStates( new ConsumedStateMap(*CurrStates)); PropagationInfo PInfo; - - if (const IfStmt *IfNode = - dyn_cast_or_null(CurrBlock->getTerminator().getStmt())) { - + + if (const auto *IfNode = + dyn_cast_or_null(CurrBlock->getTerminator().getStmt())) { + const Expr *Cond = IfNode->getCond(); PInfo = Visitor.getInfo(Cond); @@ -1285,10 +1284,10 @@ } else { return false; } - - } else if (const BinaryOperator *BinOp = - dyn_cast_or_null(CurrBlock->getTerminator().getStmt())) { - + + } else if (const auto *BinOp = dyn_cast_or_null( + CurrBlock->getTerminator().getStmt())) { + PInfo = Visitor.getInfo(BinOp->getLHS()); if (!PInfo.isVarTest()) { if ((BinOp = dyn_cast_or_null(BinOp->getLHS()))) { @@ -1340,7 +1339,7 @@ } void ConsumedAnalyzer::run(AnalysisDeclContext &AC) { - const FunctionDecl *D = dyn_cast_or_null(AC.getDecl()); + const auto *D = dyn_cast_or_null(AC.getDecl()); if (!D) return; @@ -1350,7 +1349,7 @@ determineExpectedReturnState(AC, D); - PostOrderCFGView *SortedGraph = AC.getAnalysis(); + auto *SortedGraph = AC.getAnalysis(); // AC.getCFG()->viewCFG(LangOptions()); BlockInfo = ConsumedBlockInfo(CFGraph->getNumBlockIDs(), SortedGraph); Index: lib/Analysis/FormatString.cpp =================================================================== --- lib/Analysis/FormatString.cpp +++ lib/Analysis/FormatString.cpp @@ -266,9 +266,8 @@ if (SpecifierBegin + 1 >= FmtStrEnd) return false; - const llvm::UTF8 *SB = - reinterpret_cast(SpecifierBegin + 1); - const llvm::UTF8 *SE = reinterpret_cast(FmtStrEnd); + const auto *SB = reinterpret_cast(SpecifierBegin + 1); + const auto *SE = reinterpret_cast(FmtStrEnd); const char FirstByte = *SB; // If the invalid specifier is a multibyte UTF-8 string, return the @@ -292,7 +291,7 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const { if (Ptr) { // It has to be a pointer. - const PointerType *PT = argTy->getAs(); + const auto *PT = argTy->getAs(); if (!PT) return NoMatch; @@ -377,7 +376,7 @@ } case CStrTy: { - const PointerType *PT = argTy->getAs(); + const auto *PT = argTy->getAs(); if (!PT) return NoMatch; QualType pointeeTy = PT->getPointeeType(); @@ -397,7 +396,7 @@ } case WCStrTy: { - const PointerType *PT = argTy->getAs(); + const auto *PT = argTy->getAs(); if (!PT) return NoMatch; QualType pointeeTy = @@ -439,7 +438,7 @@ return Match; // Handle implicit toll-free bridging. - if (const PointerType *PT = argTy->getAs()) { + if (const auto *PT = argTy->getAs()) { // Things such as CFTypeRef are really just opaque pointers // to C structs representing CF types that can often be bridged // to Objective-C objects. Since the compiler doesn't know which Index: lib/Analysis/LiveVariables.cpp =================================================================== --- lib/Analysis/LiveVariables.cpp +++ lib/Analysis/LiveVariables.cpp @@ -209,8 +209,8 @@ static const VariableArrayType *FindVA(QualType Ty) { const Type *ty = Ty.getTypePtr(); - while (const ArrayType *VT = dyn_cast(ty)) { - if (const VariableArrayType *VAT = dyn_cast(VT)) + while (const auto *VT = dyn_cast(ty)) { + if (const auto *VAT = dyn_cast(VT)) if (VAT->getSizeExpr()) return VAT; @@ -222,13 +222,13 @@ static const Stmt *LookThroughStmt(const Stmt *S) { while (S) { - if (const Expr *Ex = dyn_cast(S)) - S = Ex->IgnoreParens(); - if (const ExprWithCleanups *EWC = dyn_cast(S)) { + if (const auto *Ex = dyn_cast(S)) + S = Ex->IgnoreParens(); + if (const auto *EWC = dyn_cast(S)) { S = EWC->getSubExpr(); continue; } - if (const OpaqueValueExpr *OVE = dyn_cast(S)) { + if (const auto *OVE = dyn_cast(S)) { S = OVE->getSourceExpr(); continue; } @@ -265,7 +265,7 @@ } case Stmt::CXXMemberCallExprClass: { // Include the implicit "this" pointer as being live. - CXXMemberCallExpr *CE = cast(S); + auto *CE = cast(S); if (Expr *ImplicitObj = CE->getImplicitObjectArgument()) { AddLiveStmt(val.liveStmts, LV.SSetFact, ImplicitObj); } @@ -273,7 +273,7 @@ } case Stmt::ObjCMessageExprClass: { // In calls to super, include the implicit "self" pointer as being live. - ObjCMessageExpr *CE = cast(S); + auto *CE = cast(S); if (CE->getReceiverKind() == ObjCMessageExpr::SuperInstance) val.liveDecls = LV.DSetFact.add(val.liveDecls, LV.analysisContext.getSelfDecl()); @@ -281,7 +281,7 @@ } case Stmt::DeclStmtClass: { const DeclStmt *DS = cast(S); - if (const VarDecl *VD = dyn_cast(DS->getSingleDecl())) { + if (const auto *VD = dyn_cast(DS->getSingleDecl())) { for (const VariableArrayType* VA = FindVA(VD->getType()); VA != nullptr; VA = FindVA(VA->getElementType())) { AddLiveStmt(val.liveStmts, LV.SSetFact, VA->getSizeExpr()); @@ -294,7 +294,7 @@ // expression. Expr *child = cast(S)->getResultExpr(); if (!child) return; - if (OpaqueValueExpr *OV = dyn_cast(child)) + if (auto *OV = dyn_cast(child)) child = OV->getSourceExpr(); child = child->IgnoreParens(); val.liveStmts = LV.SSetFact.add(val.liveStmts, child); @@ -329,8 +329,8 @@ // Assigning to a variable? Expr *LHS = B->getLHS()->IgnoreParens(); - - if (DeclRefExpr *DR = dyn_cast(LHS)) + + if (auto *DR = dyn_cast(LHS)) if (const VarDecl *VD = dyn_cast(DR->getDecl())) { // Assignments to references don't kill the ref's address if (VD->getType()->isReferenceType()) @@ -376,7 +376,7 @@ const VarDecl *VD = nullptr; Stmt *element = OS->getElement(); - if (DeclStmt *DS = dyn_cast(element)) { + if (auto *DS = dyn_cast(element)) { VD = cast(DS->getSingleDecl()); } else if ((DR = dyn_cast(cast(element)->IgnoreParens()))) { @@ -422,8 +422,8 @@ case UO_PreDec: break; } - - if (DeclRefExpr *DR = dyn_cast(UO->getSubExpr()->IgnoreParens())) + + if (auto *DR = dyn_cast(UO->getSubExpr()->IgnoreParens())) if (isa(DR->getDecl())) { // Treat ++/-- as a kill. observer->observerKill(DR); @@ -488,7 +488,7 @@ if (cfg->getNumBlockIDs() > 300000) return nullptr; - LiveVariablesImpl *LV = new LiveVariablesImpl(AC, killAtAssign); + auto *LV = new LiveVariablesImpl(AC, killAtAssign); // Construct the dataflow worklist. Enqueue the exit block as the // start of the analysis. @@ -508,8 +508,7 @@ for (CFGBlock::const_iterator bi = block->begin(), be = block->end(); bi != be; ++bi) { if (Optional cs = bi->getAs()) { - if (const BinaryOperator *BO = - dyn_cast(cs->getStmt())) { + if (const auto *BO = dyn_cast(cs->getStmt())) { if (BO->getOpcode() == BO_Assign) { if (const DeclRefExpr *DR = dyn_cast(BO->getLHS()->IgnoreParens())) { @@ -569,8 +568,7 @@ std::vector declVec; - for (std::vector::iterator - it = vec.begin(), ei = vec.end(); it != ei; ++it) { + for (auto it = vec.begin(), ei = vec.end(); it != ei; ++it) { llvm::errs() << "\n[ B" << (*it)->getBlockID() << " (live variables at block exit) ]\n"; @@ -587,8 +585,7 @@ return A->getLocStart() < B->getLocStart(); }); - for (std::vector::iterator di = declVec.begin(), - de = declVec.end(); di != de; ++di) { + for (auto di = declVec.begin(), de = declVec.end(); di != de; ++di) { llvm::errs() << " " << (*di)->getDeclName().getAsString() << " <"; (*di)->getLocation().dump(M); Index: lib/Analysis/OSLog.cpp =================================================================== --- lib/Analysis/OSLog.cpp +++ lib/Analysis/OSLog.cpp @@ -165,7 +165,7 @@ llvm_unreachable("non-os_log builtin passed to computeOSLogBufferLayout"); } - const StringLiteral *Lit = cast(StringArg->IgnoreParenCasts()); + const auto *Lit = cast(StringArg->IgnoreParenCasts()); assert(Lit && (Lit->isAscii() || Lit->isUTF8())); StringRef Data = Lit->getString(); OSLogFormatStringHandler H(VarArgs); Index: lib/Analysis/PseudoConstantAnalysis.cpp =================================================================== --- lib/Analysis/PseudoConstantAnalysis.cpp +++ lib/Analysis/PseudoConstantAnalysis.cpp @@ -46,7 +46,7 @@ Analyzed = true; } - VarDeclSet *NonConstants = (VarDeclSet*)NonConstantsImpl; + auto *NonConstants = (VarDeclSet *)NonConstantsImpl; return !NonConstants->count(VD); } @@ -58,14 +58,14 @@ Analyzed = true; } - VarDeclSet *UsedVars = (VarDeclSet*)UsedVarsImpl; + auto *UsedVars = (VarDeclSet *)UsedVarsImpl; return UsedVars->count(VD); } // Returns a Decl from a (Block)DeclRefExpr (if any) const Decl *PseudoConstantAnalysis::getDecl(const Expr *E) { - if (const DeclRefExpr *DR = dyn_cast(E)) + if (const auto *DR = dyn_cast(E)) return DR->getDecl(); else return nullptr; @@ -73,8 +73,8 @@ void PseudoConstantAnalysis::RunAnalysis() { std::deque WorkList; - VarDeclSet *NonConstants = (VarDeclSet*)NonConstantsImpl; - VarDeclSet *UsedVars = (VarDeclSet*)UsedVarsImpl; + auto *NonConstants = (VarDeclSet *)NonConstantsImpl; + auto *UsedVars = (VarDeclSet *)UsedVarsImpl; // Start with the top level statement of the function WorkList.push_back(DeclBody); @@ -83,13 +83,13 @@ const Stmt *Head = WorkList.front(); WorkList.pop_front(); - if (const Expr *Ex = dyn_cast(Head)) + if (const auto *Ex = dyn_cast(Head)) Head = Ex->IgnoreParenCasts(); switch (Head->getStmtClass()) { // Case 1: Assignment operators modifying VarDecls case Stmt::BinaryOperatorClass: { - const BinaryOperator *BO = cast(Head); + const auto *BO = cast(Head); // Look for a Decl on the LHS const Decl *LHSDecl = getDecl(BO->getLHS()->IgnoreParenCasts()); if (!LHSDecl) @@ -119,7 +119,7 @@ case BO_XorAssign: case BO_ShlAssign: case BO_ShrAssign: { - const VarDecl *VD = dyn_cast(LHSDecl); + const auto *VD = dyn_cast(LHSDecl); // The DeclRefExpr is being assigned to - mark it as non-constant if (VD) NonConstants->insert(VD); @@ -134,7 +134,7 @@ // Case 2: Pre/post increment/decrement and address of case Stmt::UnaryOperatorClass: { - const UnaryOperator *UO = cast(Head); + const auto *UO = cast(Head); // Look for a DeclRef in the subexpression const Decl *D = getDecl(UO->getSubExpr()->IgnoreParenCasts()); @@ -153,7 +153,7 @@ case UO_AddrOf: { // If we are taking the address of the DeclRefExpr, assume it is // non-constant. - const VarDecl *VD = dyn_cast(D); + const auto *VD = dyn_cast(D); if (VD) NonConstants->insert(VD); break; @@ -167,11 +167,11 @@ // Case 3: Reference Declarations case Stmt::DeclStmtClass: { - const DeclStmt *DS = cast(Head); + const auto *DS = cast(Head); // Iterate over each decl and see if any of them contain reference decls for (const auto *I : DS->decls()) { // We only care about VarDecls - const VarDecl *VD = dyn_cast(I); + const auto *VD = dyn_cast(I); if (!VD) continue; @@ -186,7 +186,7 @@ // If the reference is to another var, add the var to the non-constant // list - if (const VarDecl *RefVD = dyn_cast(D)) { + if (const auto *RefVD = dyn_cast(D)) { NonConstants->insert(RefVD); continue; } @@ -196,8 +196,8 @@ // Case 4: Variable references case Stmt::DeclRefExprClass: { - const DeclRefExpr *DR = cast(Head); - if (const VarDecl *VD = dyn_cast(DR->getDecl())) { + const auto *DR = cast(Head); + if (const auto *VD = dyn_cast(DR->getDecl())) { // Add the Decl to the used list UsedVars->insert(VD); continue; @@ -207,7 +207,7 @@ // Case 5: Block expressions case Stmt::BlockExprClass: { - const BlockExpr *B = cast(Head); + const auto *B = cast(Head); // Add the body of the block to the list WorkList.push_back(B->getBody()); continue; Index: lib/Analysis/ReachableCode.cpp =================================================================== --- lib/Analysis/ReachableCode.cpp +++ lib/Analysis/ReachableCode.cpp @@ -32,7 +32,7 @@ //===----------------------------------------------------------------------===// static bool isEnumConstant(const Expr *Ex) { - const DeclRefExpr *DR = dyn_cast(Ex); + const auto *DR = dyn_cast(Ex); if (!DR) return false; return isa(DR->getDecl()); @@ -50,7 +50,7 @@ // Check if the block ends with a do...while() and see if 'S' is the // condition. if (const Stmt *Term = B->getTerminator()) { - if (const DoStmt *DS = dyn_cast(Term)) { + if (const auto *DS = dyn_cast(Term)) { const Expr *Cond = DS->getCond()->IgnoreParenCasts(); return Cond == S && isTrivialExpression(Cond); } @@ -68,7 +68,7 @@ E = Current->rend(); I != E; ++I) { if (Optional CS = I->getAs()) { - if (const ReturnStmt *RS = dyn_cast(CS->getStmt())) { + if (const auto *RS = dyn_cast(CS->getStmt())) { if (RS == S) return true; if (const Expr *RE = RS->getRetValue()) { @@ -166,24 +166,24 @@ S = S->IgnoreImplicit(); - if (const Expr *Ex = dyn_cast(S)) + if (const auto *Ex = dyn_cast(S)) S = Ex->IgnoreCasts(); // Special case looking for the sigil '()' around an integer literal. - if (const ParenExpr *PE = dyn_cast(S)) + if (const auto *PE = dyn_cast(S)) if (!PE->getLocStart().isMacroID()) return isConfigurationValue(PE->getSubExpr(), PP, SilenceableCondVal, IncludeIntegers, true); - if (const Expr *Ex = dyn_cast(S)) + if (const auto *Ex = dyn_cast(S)) S = Ex->IgnoreCasts(); bool IgnoreYES_NO = false; switch (S->getStmtClass()) { case Stmt::CallExprClass: { - const FunctionDecl *Callee = - dyn_cast_or_null(cast(S)->getCalleeDecl()); + const auto *Callee = + dyn_cast_or_null(cast(S)->getCalleeDecl()); return Callee ? Callee->isConstexpr() : false; } case Stmt::DeclRefExprClass: @@ -193,7 +193,7 @@ // Fallthrough. case Stmt::CXXBoolLiteralExprClass: case Stmt::IntegerLiteralClass: { - const Expr *E = cast(S); + const auto *E = cast(S); if (IncludeIntegers) { if (SilenceableCondVal && !SilenceableCondVal->getBegin().isValid()) *SilenceableCondVal = E->getSourceRange(); @@ -206,7 +206,7 @@ case Stmt::UnaryExprOrTypeTraitExprClass: return true; case Stmt::BinaryOperatorClass: { - const BinaryOperator *B = cast(S); + const auto *B = cast(S); // Only include raw integers (not enums) as configuration // values if they are used in a logical or comparison operator // (not arithmetic). @@ -217,7 +217,7 @@ IncludeIntegers); } case Stmt::UnaryOperatorClass: { - const UnaryOperator *UO = cast(S); + const auto *UO = cast(S); if (SilenceableCondVal) *SilenceableCondVal = UO->getSourceRange(); return UO->getOpcode() == UO_LNot && @@ -230,9 +230,9 @@ } static bool isConfigurationValue(const ValueDecl *D, Preprocessor &PP) { - if (const EnumConstantDecl *ED = dyn_cast(D)) + if (const auto *ED = dyn_cast(D)) return isConfigurationValue(ED->getInitExpr(), PP); - if (const VarDecl *VD = dyn_cast(D)) { + if (const auto *VD = dyn_cast(D)) { // As a heuristic, treat globals as configuration values. Note // that we only will get here if Sema evaluated this // condition to a constant expression, which means the global @@ -408,7 +408,7 @@ static bool isValidDeadStmt(const Stmt *S) { if (S->getLocStart().isInvalid()) return false; - if (const BinaryOperator *BO = dyn_cast(S)) + if (const auto *BO = dyn_cast(S)) return BO->getOpcode() != BO_Comma; return true; } @@ -508,49 +508,48 @@ SourceRange &R2) { R1 = R2 = SourceRange(); - if (const Expr *Ex = dyn_cast(S)) + if (const auto *Ex = dyn_cast(S)) S = Ex->IgnoreParenImpCasts(); switch (S->getStmtClass()) { case Expr::BinaryOperatorClass: { - const BinaryOperator *BO = cast(S); + const auto *BO = cast(S); return BO->getOperatorLoc(); } case Expr::UnaryOperatorClass: { - const UnaryOperator *UO = cast(S); + const auto *UO = cast(S); R1 = UO->getSubExpr()->getSourceRange(); return UO->getOperatorLoc(); } case Expr::CompoundAssignOperatorClass: { - const CompoundAssignOperator *CAO = cast(S); + const auto *CAO = cast(S); R1 = CAO->getLHS()->getSourceRange(); R2 = CAO->getRHS()->getSourceRange(); return CAO->getOperatorLoc(); } case Expr::BinaryConditionalOperatorClass: case Expr::ConditionalOperatorClass: { - const AbstractConditionalOperator *CO = - cast(S); + const auto *CO = cast(S); return CO->getQuestionLoc(); } case Expr::MemberExprClass: { - const MemberExpr *ME = cast(S); + const auto *ME = cast(S); R1 = ME->getSourceRange(); return ME->getMemberLoc(); } case Expr::ArraySubscriptExprClass: { - const ArraySubscriptExpr *ASE = cast(S); + const auto *ASE = cast(S); R1 = ASE->getLHS()->getSourceRange(); R2 = ASE->getRHS()->getSourceRange(); return ASE->getRBracketLoc(); } case Expr::CStyleCastExprClass: { - const CStyleCastExpr *CSC = cast(S); + const auto *CSC = cast(S); R1 = CSC->getSubExpr()->getSourceRange(); return CSC->getLParenLoc(); } case Expr::CXXFunctionalCastExprClass: { - const CXXFunctionalCastExpr *CE = cast (S); + const auto *CE = cast(S); R1 = CE->getSubExpr()->getSourceRange(); return CE->getLocStart(); } @@ -558,7 +557,7 @@ return cast(S)->getHandler(0)->getCatchLoc(); } case Expr::ObjCBridgedCastExprClass: { - const ObjCBridgedCastExpr *CSC = cast(S); + const auto *CSC = cast(S); R1 = CSC->getSubExpr()->getSourceRange(); return CSC->getLParenLoc(); } @@ -594,7 +593,7 @@ SourceLocation Loc = LoopTarget->getLocStart(); SourceRange R1(Loc, Loc), R2; - if (const ForStmt *FS = dyn_cast(LoopTarget)) { + if (const auto *FS = dyn_cast(LoopTarget)) { const Expr *Inc = FS->getInc(); Loc = Inc->getLocStart(); R2 = Inc->getSourceRange(); @@ -654,8 +653,8 @@ // If there aren't explicit EH edges, we should include the 'try' dispatch // blocks as roots. if (!AC.getCFGBuildOptions().AddEHEdges) { - for (CFG::try_block_iterator I = cfg->try_blocks_begin(), - E = cfg->try_blocks_end() ; I != E; ++I) { + for (auto I = cfg->try_blocks_begin(), E = cfg->try_blocks_end(); I != E; + ++I) { numReachable += scanMaybeReachableFromBlock(*I, PP, reachable); } if (numReachable == cfg->getNumBlockIDs()) Index: lib/Analysis/ThreadSafety.cpp =================================================================== --- lib/Analysis/ThreadSafety.cpp +++ lib/Analysis/ThreadSafety.cpp @@ -586,7 +586,7 @@ Expr *LHSExp = BO->getLHS()->IgnoreParenCasts(); // Update the variable map and current context. - if (DeclRefExpr *DRE = dyn_cast(LHSExp)) { + if (auto *DRE = dyn_cast(LHSExp)) { ValueDecl *VDec = DRE->getDecl(); if (Ctx.lookup(VDec)) { if (BO->getOpcode() == BO_Assign) @@ -1285,9 +1285,9 @@ Expr *BrE, bool Neg) { // Find out which branch has the lock bool branch = false; - if (CXXBoolLiteralExpr *BLE = dyn_cast_or_null(BrE)) + if (auto *BLE = dyn_cast_or_null(BrE)) branch = BLE->getValue(); - else if (IntegerLiteral *ILE = dyn_cast_or_null(BrE)) + else if (auto *ILE = dyn_cast_or_null(BrE)) branch = ILE->getValue().getBoolValue(); int branchnum = branch ? 0 : 1; @@ -1307,13 +1307,13 @@ if (isa(E) || isa(E)) { TCond = false; return true; - } else if (CXXBoolLiteralExpr *BLE = dyn_cast(E)) { + } else if (auto *BLE = dyn_cast(E)) { TCond = BLE->getValue(); return true; - } else if (IntegerLiteral *ILE = dyn_cast(E)) { + } else if (auto *ILE = dyn_cast(E)) { TCond = ILE->getValue().getBoolValue(); return true; - } else if (ImplicitCastExpr *CE = dyn_cast(E)) { + } else if (auto *CE = dyn_cast(E)) { return getStaticBooleanValue(CE->getSubExpr(), TCond); } return false; @@ -1329,30 +1329,24 @@ if (!Cond) return nullptr; - if (const CallExpr *CallExp = dyn_cast(Cond)) { + if (const auto *CallExp = dyn_cast(Cond)) { return CallExp; - } - else if (const ParenExpr *PE = dyn_cast(Cond)) { + } else if (const auto *PE = dyn_cast(Cond)) { return getTrylockCallExpr(PE->getSubExpr(), C, Negate); - } - else if (const ImplicitCastExpr *CE = dyn_cast(Cond)) { + } else if (const auto *CE = dyn_cast(Cond)) { return getTrylockCallExpr(CE->getSubExpr(), C, Negate); - } - else if (const ExprWithCleanups* EWC = dyn_cast(Cond)) { + } else if (const auto *EWC = dyn_cast(Cond)) { return getTrylockCallExpr(EWC->getSubExpr(), C, Negate); - } - else if (const DeclRefExpr *DRE = dyn_cast(Cond)) { + } else if (const auto *DRE = dyn_cast(Cond)) { const Expr *E = LocalVarMap.lookupExpr(DRE->getDecl(), C); return getTrylockCallExpr(E, C, Negate); - } - else if (const UnaryOperator *UOP = dyn_cast(Cond)) { + } else if (const auto *UOP = dyn_cast(Cond)) { if (UOP->getOpcode() == UO_LNot) { Negate = !Negate; return getTrylockCallExpr(UOP->getSubExpr(), C, Negate); } return nullptr; - } - else if (const BinaryOperator *BOP = dyn_cast(Cond)) { + } else if (const auto *BOP = dyn_cast(Cond)) { if (BOP->getOpcode() == BO_EQ || BOP->getOpcode() == BO_NE) { if (BOP->getOpcode() == BO_NE) Negate = !Negate; @@ -1405,7 +1399,7 @@ if (!Exp) return; - NamedDecl *FunDecl = dyn_cast_or_null(Exp->getCalleeDecl()); + auto *FunDecl = dyn_cast_or_null(Exp->getCalleeDecl()); if(!FunDecl || !FunDecl->hasAttrs()) return; @@ -1416,16 +1410,14 @@ for (auto *Attr : FunDecl->attrs()) { switch (Attr->getKind()) { case attr::ExclusiveTrylockFunction: { - ExclusiveTrylockFunctionAttr *A = - cast(Attr); + auto *A = cast(Attr); getMutexIDs(ExclusiveLocksToAdd, A, Exp, FunDecl, PredBlock, CurrBlock, A->getSuccessValue(), Negate); CapDiagKind = ClassifyDiagnostic(A); break; } case attr::SharedTrylockFunction: { - SharedTrylockFunctionAttr *A = - cast(Attr); + auto *A = cast(Attr); getMutexIDs(SharedLocksToAdd, A, Exp, FunDecl, PredBlock, CurrBlock, A->getSuccessValue(), Negate); CapDiagKind = ClassifyDiagnostic(A); @@ -1600,19 +1592,19 @@ break; } - if (const UnaryOperator *UO = dyn_cast(Exp)) { + if (const auto *UO = dyn_cast(Exp)) { // For dereferences if (UO->getOpcode() == clang::UO_Deref) checkPtAccess(UO->getSubExpr(), AK, POK); return; } - if (const ArraySubscriptExpr *AE = dyn_cast(Exp)) { + if (const auto *AE = dyn_cast(Exp)) { checkPtAccess(AE->getLHS(), AK, POK); return; } - if (const MemberExpr *ME = dyn_cast(Exp)) { + if (const auto *ME = dyn_cast(Exp)) { if (ME->isArrow()) checkPtAccess(ME->getBase(), AK, POK); else @@ -1638,11 +1630,11 @@ void BuildLockset::checkPtAccess(const Expr *Exp, AccessKind AK, ProtectedOperationKind POK) { while (true) { - if (const ParenExpr *PE = dyn_cast(Exp)) { + if (const auto *PE = dyn_cast(Exp)) { Exp = PE->getSubExpr(); continue; } - if (const CastExpr *CE = dyn_cast(Exp)) { + if (const auto *CE = dyn_cast(Exp)) { if (CE->getCastKind() == CK_ArrayToPointerDecay) { // If it's an actual array, and not a pointer, then it's elements // are protected by GUARDED_BY, not PT_GUARDED_BY; @@ -1692,7 +1684,7 @@ // Figure out if we're calling the constructor of scoped lockable class bool isScopedVar = false; if (VD) { - if (const CXXConstructorDecl *CD = dyn_cast(D)) { + if (const auto *CD = dyn_cast(D)) { const CXXRecordDecl* PD = CD->getParent(); if (PD && PD->hasAttr()) isScopedVar = true; @@ -1700,7 +1692,7 @@ } for(Attr *Atconst : D->attrs()) { - Attr* At = const_cast(Atconst); + auto *At = const_cast(Atconst); switch (At->getKind()) { // When we encounter a lock function, we need to add the lock to our // lockset. @@ -1718,7 +1710,7 @@ // a warning if it is already there, and will not generate a warning // if it is not removed. case attr::AssertExclusiveLock: { - AssertExclusiveLockAttr *A = cast(At); + auto *A = cast(At); CapExprSet AssertLocks; Analyzer->getMutexIDs(AssertLocks, A, Exp, D, VD); @@ -1730,7 +1722,7 @@ break; } case attr::AssertSharedLock: { - AssertSharedLockAttr *A = cast(At); + auto *A = cast(At); CapExprSet AssertLocks; Analyzer->getMutexIDs(AssertLocks, A, Exp, D, VD); @@ -1757,7 +1749,7 @@ } case attr::RequiresCapability: { - RequiresCapabilityAttr *A = cast(At); + auto *A = cast(At); for (auto *Arg : A->args()) { warnIfMutexNotHeld(D, Exp, A->isShared() ? AK_Read : AK_Written, Arg, POK_FunctionCall, ClassifyDiagnostic(A), @@ -1773,7 +1765,7 @@ } case attr::LocksExcluded: { - LocksExcludedAttr *A = cast(At); + auto *A = cast(At); for (auto *Arg : A->args()) warnIfMutexHeld(D, Exp, Arg, ClassifyDiagnostic(A)); break; @@ -1869,8 +1861,8 @@ bool ExamineArgs = true; bool OperatorFun = false; - if (CXXMemberCallExpr *CE = dyn_cast(Exp)) { - MemberExpr *ME = dyn_cast(CE->getCallee()); + if (auto *CE = dyn_cast(Exp)) { + auto *ME = dyn_cast(CE->getCallee()); // ME can be null when calling a method pointer CXXMethodDecl *MD = CE->getMethodDecl(); @@ -1888,7 +1880,7 @@ checkAccess(CE->getImplicitObjectArgument(), AK_Read); } } - } else if (CXXOperatorCallExpr *OE = dyn_cast(Exp)) { + } else if (auto *OE = dyn_cast(Exp)) { OperatorFun = true; auto OEop = OE->getOperator(); @@ -1961,7 +1953,7 @@ } } - NamedDecl *D = dyn_cast_or_null(Exp->getCalleeDecl()); + auto *D = dyn_cast_or_null(Exp->getCalleeDecl()); if(!D || !D->hasAttrs()) return; handleCall(Exp, D); @@ -1981,14 +1973,14 @@ LVarCtx = Analyzer->LocalVarMap.getNextContext(CtxIndex, S, LVarCtx); for (auto *D : S->getDeclGroup()) { - if (VarDecl *VD = dyn_cast_or_null(D)) { + if (auto *VD = dyn_cast_or_null(D)) { Expr *E = VD->getInit(); // handle constructors that involve temporaries - if (ExprWithCleanups *EWC = dyn_cast_or_null(E)) + if (auto *EWC = dyn_cast_or_null(E)) E = EWC->getSubExpr(); - if (CXXConstructExpr *CE = dyn_cast_or_null(E)) { - NamedDecl *CtorD = dyn_cast_or_null(CE->getConstructor()); + if (auto *CE = dyn_cast_or_null(E)) { + auto *CtorD = dyn_cast_or_null(CE->getConstructor()); if (!CtorD || !CtorD->hasAttrs()) return; handleCall(CE, CtorD, VD); @@ -2095,7 +2087,7 @@ CFG *CFGraph = walker.getGraph(); const NamedDecl *D = walker.getDecl(); - const FunctionDecl *CurrentFunction = dyn_cast(D); + const auto *CurrentFunction = dyn_cast(D); CurrentMethod = dyn_cast(D); if (D->hasAttr()) @@ -2302,13 +2294,13 @@ // Ignore BaseDtor, MemberDtor, and TemporaryDtor for now. case CFGElement::AutomaticObjectDtor: { CFGAutomaticObjDtor AD = BI->castAs(); - CXXDestructorDecl *DD = const_cast( + auto *DD = const_cast( AD.getDestructorDecl(AC.getASTContext())); if (!DD->hasAttrs()) break; // Create a dummy expression, - VarDecl *VD = const_cast(AD.getVarDecl()); + auto *VD = const_cast(AD.getVarDecl()); DeclRefExpr DRE(VD, false, VD->getType().getNonReferenceType(), VK_LValue, AD.getTriggerStmt()->getLocEnd()); LocksetBuilder.handleCall(&DRE, DD); Index: lib/Analysis/ThreadSafetyCommon.cpp =================================================================== --- lib/Analysis/ThreadSafetyCommon.cpp +++ lib/Analysis/ThreadSafetyCommon.cpp @@ -74,7 +74,7 @@ } static bool isCalleeArrow(const Expr *E) { - const MemberExpr *ME = dyn_cast(E->IgnoreParenCasts()); + const auto *ME = dyn_cast(E->IgnoreParenCasts()); return ME ? ME->isArrow() : false; } @@ -97,20 +97,18 @@ // Examine DeclExp to find SelfArg and FunArgs, which are used to substitute // for formal parameters when we call buildMutexID later. - if (const MemberExpr *ME = dyn_cast(DeclExp)) { + if (const auto *ME = dyn_cast(DeclExp)) { Ctx.SelfArg = ME->getBase(); Ctx.SelfArrow = ME->isArrow(); - } else if (const CXXMemberCallExpr *CE = - dyn_cast(DeclExp)) { + } else if (const auto *CE = dyn_cast(DeclExp)) { Ctx.SelfArg = CE->getImplicitObjectArgument(); Ctx.SelfArrow = isCalleeArrow(CE->getCallee()); Ctx.NumArgs = CE->getNumArgs(); Ctx.FunArgs = CE->getArgs(); - } else if (const CallExpr *CE = dyn_cast(DeclExp)) { + } else if (const auto *CE = dyn_cast(DeclExp)) { Ctx.NumArgs = CE->getNumArgs(); Ctx.FunArgs = CE->getArgs(); - } else if (const CXXConstructExpr *CE = - dyn_cast(DeclExp)) { + } else if (const auto *CE = dyn_cast(DeclExp)) { Ctx.SelfArg = nullptr; // Will be set below Ctx.NumArgs = CE->getNumArgs(); Ctx.FunArgs = CE->getArgs(); @@ -254,7 +252,7 @@ default: break; } - if (const CastExpr *CE = dyn_cast(S)) + if (const auto *CE = dyn_cast(S)) return translateCastExpr(CE, Ctx); return new (Arena) til::Undefined(S); @@ -262,10 +260,10 @@ til::SExpr *SExprBuilder::translateDeclRefExpr(const DeclRefExpr *DRE, CallingContext *Ctx) { - const ValueDecl *VD = cast(DRE->getDecl()->getCanonicalDecl()); + const auto *VD = cast(DRE->getDecl()->getCanonicalDecl()); // Function parameters require substitution and/or renaming. - if (const ParmVarDecl *PV = dyn_cast_or_null(VD)) { + if (const auto *PV = dyn_cast_or_null(VD)) { const FunctionDecl *FD = cast(PV->getDeclContext())->getCanonicalDecl(); unsigned I = PV->getFunctionScopeIndex(); @@ -338,7 +336,7 @@ if (auto *VD = dyn_cast(D)) D = getFirstVirtualDecl(VD); - til::Project *P = new (Arena) til::Project(E, D); + auto *P = new (Arena) til::Project(E, D); if (hasCppPointerType(BE)) P->setArrow(true); return P; @@ -350,7 +348,7 @@ if (CapabilityExprMode) { // Handle LOCK_RETURNED const FunctionDecl *FD = CE->getDirectCallee()->getMostRecentDecl(); - if (LockReturnedAttr* At = FD->getAttr()) { + if (auto *At = FD->getAttr()) { CallingContext LRCallCtx(Ctx); LRCallCtx.AttrDecl = CE->getDirectCallee(); LRCallCtx.SelfArg = SelfE; @@ -410,7 +408,7 @@ case UO_AddrOf: { if (CapabilityExprMode) { // interpret &Graph::mu_ as an existential. - if (DeclRefExpr* DRE = dyn_cast(UO->getSubExpr())) { + if (auto *DRE = dyn_cast(UO->getSubExpr())) { if (DRE->getDecl()->isCXXInstanceMember()) { // This is a pointer-to-member expression, e.g. &MyClass::mu_. // We interpret this syntax specially, as a wildcard. @@ -470,7 +468,7 @@ const ValueDecl *VD = nullptr; til::SExpr *CV = nullptr; - if (const DeclRefExpr *DRE = dyn_cast(LHS)) { + if (const auto *DRE = dyn_cast(LHS)) { VD = DRE->getDecl(); CV = lookupVarDecl(VD); } @@ -535,7 +533,7 @@ clang::CastKind K = CE->getCastKind(); switch (K) { case CK_LValueToRValue: { - if (const DeclRefExpr *DRE = dyn_cast(CE->getSubExpr())) { + if (const auto *DRE = dyn_cast(CE->getSubExpr())) { til::SExpr *E0 = lookupVarDecl(DRE->getDecl()); if (E0) return E0; @@ -584,7 +582,7 @@ SExprBuilder::translateDeclStmt(const DeclStmt *S, CallingContext *Ctx) { DeclGroupRef DGrp = S->getDeclGroup(); for (DeclGroupRef::iterator I = DGrp.begin(), E = DGrp.end(); I != E; ++I) { - if (VarDecl *VD = dyn_cast_or_null(*I)) { + if (auto *VD = dyn_cast_or_null(*I)) { Expr *E = VD->getInit(); til::SExpr* SE = translate(E, Ctx); @@ -631,7 +629,7 @@ static void maybeUpdateVD(til::SExpr *E, const ValueDecl *VD) { if (!E) return; - if (til::Variable *V = dyn_cast(E)) { + if (auto *V = dyn_cast(E)) { if (!V->clangDecl()) V->setClangDecl(VD); } @@ -671,7 +669,7 @@ if (CurrE->block() == CurrentBB) { // We already have a Phi node in the current block, // so just add the new variable to the Phi node. - til::Phi *Ph = dyn_cast(CurrE); + auto *Ph = dyn_cast(CurrE); assert(Ph && "Expecting Phi node."); if (E) Ph->values()[ArgIndex] = E; @@ -680,7 +678,7 @@ // Make a new phi node: phi(..., E) // All phi args up to the current index are set to the current value. - til::Phi *Ph = new (Arena) til::Phi(Arena, NPreds); + auto *Ph = new (Arena) til::Phi(Arena, NPreds); Ph->values().setValues(NPreds, nullptr); for (unsigned PIdx = 0; PIdx < ArgIndex; ++PIdx) Ph->values()[PIdx] = CurrE; @@ -771,7 +769,7 @@ assert(ArgIndex > 0 && ArgIndex < BB->numPredecessors()); for (til::SExpr *PE : BB->arguments()) { - til::Phi *Ph = dyn_cast_or_null(PE); + auto *Ph = dyn_cast_or_null(PE); assert(Ph && "Expecting Phi Node."); assert(Ph->values()[ArgIndex] == nullptr && "Wrong index for back edge."); Index: lib/Analysis/ThreadSafetyTIL.cpp =================================================================== --- lib/Analysis/ThreadSafetyTIL.cpp +++ lib/Analysis/ThreadSafetyTIL.cpp @@ -58,7 +58,7 @@ Predecessors.reserveCheck(1, Arena); Predecessors.push_back(Pred); for (SExpr *E : Args) { - if (Phi* Ph = dyn_cast(E)) { + if (auto *Ph = dyn_cast(E)) { Ph->values().reserveCheck(1, Arena); Ph->values().push_back(nullptr); } @@ -70,7 +70,7 @@ void BasicBlock::reservePredecessors(unsigned NumPreds) { Predecessors.reserve(NumPreds, Arena); for (SExpr *E : Args) { - if (Phi* Ph = dyn_cast(E)) { + if (auto *Ph = dyn_cast(E)) { Ph->values().reserve(NumPreds, Arena); } } @@ -87,7 +87,7 @@ continue; } } - if (const Phi *Ph = dyn_cast(E)) { + if (const auto *Ph = dyn_cast(E)) { if (Ph->status() == Phi::PH_SingleVal) { E = Ph->values()[0]; continue; Index: lib/Analysis/UninitializedValues.cpp =================================================================== --- lib/Analysis/UninitializedValues.cpp +++ lib/Analysis/UninitializedValues.cpp @@ -277,7 +277,7 @@ static const Expr *stripCasts(ASTContext &C, const Expr *Ex) { while (Ex) { Ex = Ex->IgnoreParenNoopCasts(C); - if (const CastExpr *CE = dyn_cast(Ex)) { + if (const auto *CE = dyn_cast(Ex)) { if (CE->getCastKind() == CK_LValueBitCast) { Ex = CE->getSubExpr(); continue; @@ -291,9 +291,9 @@ /// If E is an expression comprising a reference to a single variable, find that /// variable. static FindVarResult findVar(const Expr *E, const DeclContext *DC) { - if (const DeclRefExpr *DRE = - dyn_cast(stripCasts(DC->getParentASTContext(), E))) - if (const VarDecl *VD = dyn_cast(DRE->getDecl())) + if (const auto *DRE = + dyn_cast(stripCasts(DC->getParentASTContext(), E))) + if (const auto *VD = dyn_cast(DRE->getDecl())) if (isTrackedVar(VD, DC)) return FindVarResult(VD, DRE); return FindVarResult(nullptr, nullptr); @@ -338,7 +338,7 @@ if (I != Classification.end()) return I->second; - const VarDecl *VD = dyn_cast(DRE->getDecl()); + const auto *VD = dyn_cast(DRE->getDecl()); if (!VD || !isTrackedVar(VD)) return Ignore; @@ -351,8 +351,8 @@ if (VD->getType()->isRecordType()) return nullptr; if (Expr *Init = VD->getInit()) { - const DeclRefExpr *DRE - = dyn_cast(stripCasts(VD->getASTContext(), Init)); + const auto *DRE = + dyn_cast(stripCasts(VD->getASTContext(), Init)); if (DRE && DRE->getDecl() == VD) return DRE; } @@ -362,32 +362,31 @@ void ClassifyRefs::classify(const Expr *E, Class C) { // The result of a ?: could also be an lvalue. E = E->IgnoreParens(); - if (const ConditionalOperator *CO = dyn_cast(E)) { + if (const auto *CO = dyn_cast(E)) { classify(CO->getTrueExpr(), C); classify(CO->getFalseExpr(), C); return; } - if (const BinaryConditionalOperator *BCO = - dyn_cast(E)) { + if (const auto *BCO = dyn_cast(E)) { classify(BCO->getFalseExpr(), C); return; } - if (const OpaqueValueExpr *OVE = dyn_cast(E)) { + if (const auto *OVE = dyn_cast(E)) { classify(OVE->getSourceExpr(), C); return; } - if (const MemberExpr *ME = dyn_cast(E)) { - if (VarDecl *VD = dyn_cast(ME->getMemberDecl())) { + if (const auto *ME = dyn_cast(E)) { + if (auto *VD = dyn_cast(ME->getMemberDecl())) { if (!VD->isStaticDataMember()) classify(ME->getBase(), C); } return; } - if (const BinaryOperator *BO = dyn_cast(E)) { + if (const auto *BO = dyn_cast(E)) { switch (BO->getOpcode()) { case BO_PtrMemD: case BO_PtrMemI: @@ -408,7 +407,7 @@ void ClassifyRefs::VisitDeclStmt(DeclStmt *DS) { for (auto *DI : DS->decls()) { - VarDecl *VD = dyn_cast(DI); + auto *VD = dyn_cast(DI); if (VD && isTrackedVar(VD)) if (const DeclRefExpr *DRE = getSelfInitExpr(VD)) Classification[DRE] = SelfInit; @@ -462,7 +461,7 @@ classify((*I), Ignore); } else if (isPointerToConst((*I)->getType())) { const Expr *Ex = stripCasts(DC->getParentASTContext(), *I); - const UnaryOperator *UO = dyn_cast(Ex); + const auto *UO = dyn_cast(Ex); if (UO && UO->getOpcode() == UO_AddrOf) Ex = UO->getSubExpr(); classify(Ex, Ignore); @@ -473,7 +472,7 @@ void ClassifyRefs::VisitCastExpr(CastExpr *CE) { if (CE->getCastKind() == CK_LValueToRValue) classify(CE->getSubExpr(), Use); - else if (CStyleCastExpr *CSE = dyn_cast(CE)) { + else if (auto *CSE = dyn_cast(CE)) { if (CSE->getType()->isVoidType()) { // Squelch any detected load of an uninitialized value if // we cast it to void. @@ -683,7 +682,7 @@ void TransferFunctions::VisitObjCForCollectionStmt(ObjCForCollectionStmt *FS) { // This represents an initialization of the 'element' value. - if (DeclStmt *DS = dyn_cast(FS->getElement())) { + if (auto *DS = dyn_cast(FS->getElement())) { const VarDecl *VD = cast(DS->getSingleDecl()); if (isTrackedVar(VD)) vals[VD] = Initialized; @@ -753,7 +752,7 @@ void TransferFunctions::VisitDeclStmt(DeclStmt *DS) { for (auto *DI : DS->decls()) { - VarDecl *VD = dyn_cast(DI); + auto *VD = dyn_cast(DI); if (VD && isTrackedVar(VD)) { if (getSelfInitExpr(VD)) { // If the initializer consists solely of a reference to itself, we Index: lib/Basic/Diagnostic.cpp =================================================================== --- lib/Basic/Diagnostic.cpp +++ lib/Basic/Diagnostic.cpp @@ -170,7 +170,7 @@ if (Loc.isInvalid()) return DiagStatePoints.end() - 1; - DiagStatePointsTy::iterator Pos = DiagStatePoints.end(); + auto Pos = DiagStatePoints.end(); FullSourceLoc LastStateChangePos = DiagStatePoints.back().Loc; if (LastStateChangePos.isValid() && Loc.isBeforeInTranslationUnitThan(LastStateChangePos)) @@ -223,12 +223,11 @@ // We allow setting the diagnostic state in random source order for // completeness but it should not be actually happening in normal practice. - DiagStatePointsTy::iterator Pos = GetDiagStatePointForLoc(Loc); + auto Pos = GetDiagStatePointForLoc(Loc); assert(Pos != DiagStatePoints.end()); // Update all diagnostic states that are active after the given location. - for (DiagStatePointsTy::iterator - I = Pos+1, E = DiagStatePoints.end(); I != E; ++I) { + for (auto I = Pos + 1, E = DiagStatePoints.end(); I != E; ++I) { I->State->setMapping(Diag, Mapping); } @@ -815,7 +814,7 @@ } // ---- TOKEN SPELLINGS ---- case DiagnosticsEngine::ak_tokenkind: { - tok::TokenKind Kind = static_cast(getRawArg(ArgNo)); + auto Kind = static_cast(getRawArg(ArgNo)); assert(ModifierLen == 0 && "No modifiers for token kinds yet"); llvm::raw_svector_ostream Out(OutStr); @@ -870,7 +869,7 @@ TDT.ElideType = getDiags()->ElideType; TDT.ShowColors = getDiags()->ShowColors; TDT.TemplateDiffUsed = false; - intptr_t val = reinterpret_cast(&TDT); + auto val = reinterpret_cast(&TDT); const char *ArgumentEnd = Argument + ArgumentLen; const char *Pipe = ScanFormat(Argument, ArgumentEnd, '|'); Index: lib/Basic/DiagnosticIDs.cpp =================================================================== --- lib/Basic/DiagnosticIDs.cpp +++ lib/Basic/DiagnosticIDs.cpp @@ -276,7 +276,7 @@ DiagnosticIDs &Diags) { DiagDesc D(L, Message); // Check to see if it already exists. - std::map::iterator I = DiagIDs.lower_bound(D); + auto I = DiagIDs.lower_bound(D); if (I != DiagIDs.end() && I->first == D) return I->second; @@ -411,8 +411,7 @@ // to error. Errors can only be mapped to fatal. diag::Severity Result = diag::Severity::Fatal; - DiagnosticsEngine::DiagStatePointsTy::iterator - Pos = Diag.GetDiagStatePointForLoc(Loc); + auto Pos = Diag.GetDiagStatePointForLoc(Loc); DiagnosticsEngine::DiagState *State = Pos->State; // Get the mapping information, or compute it lazily. Index: lib/Basic/IdentifierTable.cpp =================================================================== --- lib/Basic/IdentifierTable.cpp +++ lib/Basic/IdentifierTable.cpp @@ -365,7 +365,7 @@ ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys; // Fill in the trailing keyword array. - IdentifierInfo **KeyInfo = reinterpret_cast(this+1); + auto **KeyInfo = reinterpret_cast(this + 1); for (unsigned i = 0; i != nKeys; ++i) KeyInfo[i] = IIV[i]; } @@ -622,9 +622,8 @@ // MultiKeywordSelector objects are not allocated with new because they have a // variable size array (for parameter types) at the end of them. unsigned Size = sizeof(MultiKeywordSelector) + nKeys*sizeof(IdentifierInfo *); - MultiKeywordSelector *SI = - (MultiKeywordSelector *)SelTabImpl.Allocator.Allocate( - Size, alignof(MultiKeywordSelector)); + auto *SI = (MultiKeywordSelector *)SelTabImpl.Allocator.Allocate( + Size, alignof(MultiKeywordSelector)); new (SI) MultiKeywordSelector(nKeys, IIV); SelTabImpl.Table.InsertNode(SI, InsertPos); return Selector(SI); Index: lib/Basic/Module.cpp =================================================================== --- lib/Basic/Module.cpp +++ lib/Basic/Module.cpp @@ -51,8 +51,7 @@ } Module::~Module() { - for (submodule_iterator I = submodule_begin(), IEnd = submodule_end(); - I != IEnd; ++I) { + for (auto I = submodule_begin(), IEnd = submodule_end(); I != IEnd; ++I) { delete *I; } } @@ -162,8 +161,8 @@ ArrayRef Module::getTopHeaders(FileManager &FileMgr) { if (!TopHeaderNames.empty()) { - for (std::vector::iterator - I = TopHeaderNames.begin(), E = TopHeaderNames.end(); I != E; ++I) { + for (auto I = TopHeaderNames.begin(), E = TopHeaderNames.end(); I != E; + ++I) { if (const FileEntry *FE = FileMgr.getFile(*I)) TopHeaders.insert(FE); } @@ -222,8 +221,8 @@ Current->IsAvailable = false; Current->IsMissingRequirement |= MissingRequirement; - for (submodule_iterator Sub = Current->submodule_begin(), - SubEnd = Current->submodule_end(); + for (auto Sub = Current->submodule_begin(), + SubEnd = Current->submodule_end(); Sub != SubEnd; ++Sub) { if (needUpdate(*Sub)) Stack.push_back(*Sub); @@ -249,9 +248,7 @@ void Module::getExportedModules(SmallVectorImpl &Exported) const { // All non-explicit submodules are exported. - for (std::vector::const_iterator I = SubModules.begin(), - E = SubModules.end(); - I != E; ++I) { + for (auto I = SubModules.begin(), E = SubModules.end(); I != E; ++I) { Module *Mod = *I; if (!Mod->IsExplicit) Exported.push_back(Mod); @@ -401,8 +398,7 @@ } } - for (submodule_const_iterator MI = submodule_begin(), MIEnd = submodule_end(); - MI != MIEnd; ++MI) + for (auto MI = submodule_begin(), MIEnd = submodule_end(); MI != MIEnd; ++MI) // Print inferred subframework modules so that we don't need to re-infer // them (requires expensive directory iteration + stat calls) when we build // the module. Regular inferred submodules are OK, as we need to look at all Index: lib/Basic/SourceManager.cpp =================================================================== --- lib/Basic/SourceManager.cpp +++ lib/Basic/SourceManager.cpp @@ -111,7 +111,7 @@ StringRef FillStr("<<>>\n"); Buffer.setPointer(MemoryBuffer::getNewUninitMemBuffer( ContentsEntry->getSize(), "").release()); - char *Ptr = const_cast(Buffer.getPointer()->getBufferStart()); + auto *Ptr = const_cast(Buffer.getPointer()->getBufferStart()); for (unsigned i = 0, e = ContentsEntry->getSize(); i != e; ++i) Ptr[i] = FillStr[i % FillStr.size()]; @@ -262,8 +262,7 @@ return &Entries.back(); // Do a binary search to find the maximal element that is still before Offset. - std::vector::const_iterator I = - std::upper_bound(Entries.begin(), Entries.end(), Offset); + auto I = std::upper_bound(Entries.begin(), Entries.end(), Offset); if (I == Entries.begin()) return nullptr; return &*--I; } @@ -447,7 +446,7 @@ const ContentCache *SourceManager::createMemBufferContentCache( std::unique_ptr Buffer) { // Add a new ContentCache to the MemBufferInfos list and return it. - ContentCache *Entry = ContentCacheAlloc.Allocate(); + auto *Entry = ContentCacheAlloc.Allocate(); new (Entry) ContentCache(); MemBufferInfos.push_back(Entry); Entry->setBuffer(std::move(Buffer)); @@ -1209,12 +1208,12 @@ // Line #1 starts at char 0. LineOffsets.push_back(0); - const unsigned char *Buf = (const unsigned char *)Buffer->getBufferStart(); - const unsigned char *End = (const unsigned char *)Buffer->getBufferEnd(); + const auto *Buf = (const unsigned char *)Buffer->getBufferStart(); + const auto *End = (const unsigned char *)Buffer->getBufferEnd(); unsigned Offs = 0; while (1) { // Skip over the contents of the line. - const unsigned char *NextBuf = (const unsigned char *)Buf; + const auto *NextBuf = (const unsigned char *)Buf; #ifdef __SSE2__ // Try to skip to the next newline using SSE instructions. This is very @@ -1739,8 +1738,7 @@ if (Line == 1 && Col == 1) return FileLoc; - ContentCache *Content - = const_cast(Entry.getFile().getContentCache()); + auto *Content = const_cast(Entry.getFile().getContentCache()); if (!Content) return SourceLocation(); @@ -1908,7 +1906,7 @@ // previous chunks, we only need to find where the ending of the new macro // chunk is mapped to and update the map with new begin/end mappings. - MacroArgsMap::iterator I = MacroArgsCache.upper_bound(EndOffs); + auto I = MacroArgsCache.upper_bound(EndOffs); --I; SourceLocation EndOffsMappedLoc = I->second; MacroArgsCache[BeginOffs] = ExpansionLoc; @@ -1942,7 +1940,7 @@ } assert(!MacroArgsCache->empty()); - MacroArgsMap::iterator I = MacroArgsCache->upper_bound(Offset); + auto I = MacroArgsCache->upper_bound(Offset); --I; unsigned MacroArgBeginOffs = I->first; Index: lib/Basic/VirtualFileSystem.cpp =================================================================== --- lib/Basic/VirtualFileSystem.cpp +++ lib/Basic/VirtualFileSystem.cpp @@ -986,7 +986,7 @@ // false on error bool parseScalarString(yaml::Node *N, StringRef &Result, SmallVectorImpl &Storage) { - yaml::ScalarNode *S = dyn_cast(N); + auto *S = dyn_cast(N); if (!S) { error(N, "expected string"); return false; @@ -1118,7 +1118,7 @@ } std::unique_ptr parseEntry(yaml::Node *N, RedirectingFileSystem *FS) { - yaml::MappingNode *M = dyn_cast(N); + auto *M = dyn_cast(N); if (!M) { error(N, "expected mapping node for file or directory entry"); return nullptr; @@ -1186,8 +1186,7 @@ return nullptr; } HasContents = true; - yaml::SequenceNode *Contents = - dyn_cast(I->getValue()); + auto *Contents = dyn_cast(I->getValue()); if (!Contents) { // FIXME: this is only for directories, what about files? error(I->getValue(), "expected array"); @@ -1304,7 +1303,7 @@ // false on error bool parse(yaml::Node *Root, RedirectingFileSystem *FS) { - yaml::MappingNode *Top = dyn_cast(Root); + auto *Top = dyn_cast(Root); if (!Top) { error(Root, "expected mapping node"); return false; @@ -1334,7 +1333,7 @@ return false; if (Key == "roots") { - yaml::SequenceNode *Roots = dyn_cast(I->getValue()); + auto *Roots = dyn_cast(I->getValue()); if (!Roots) { error(I->getValue(), "expected array"); return false; Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -158,8 +158,8 @@ static void addSanitizerCoveragePass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) { - const PassManagerBuilderWrapper &BuilderWrapper = - static_cast(Builder); + const auto &BuilderWrapper = + static_cast(Builder); const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); SanitizerCoverageOptions Opts; Opts.CoverageType = @@ -177,8 +177,8 @@ static void addAddressSanitizerPasses(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) { - const PassManagerBuilderWrapper &BuilderWrapper = - static_cast(Builder); + const auto &BuilderWrapper = + static_cast(Builder); const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::Address); bool UseAfterScope = CGOpts.SanitizeAddressUseAfterScope; @@ -198,8 +198,8 @@ static void addMemorySanitizerPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) { - const PassManagerBuilderWrapper &BuilderWrapper = - static_cast(Builder); + const auto &BuilderWrapper = + static_cast(Builder); const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); int TrackOrigins = CGOpts.SanitizeMemoryTrackOrigins; bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::Memory); @@ -225,16 +225,16 @@ static void addDataFlowSanitizerPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) { - const PassManagerBuilderWrapper &BuilderWrapper = - static_cast(Builder); + const auto &BuilderWrapper = + static_cast(Builder); const LangOptions &LangOpts = BuilderWrapper.getLangOpts(); PM.add(createDataFlowSanitizerPass(LangOpts.SanitizerBlacklistFiles)); } static void addEfficiencySanitizerPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) { - const PassManagerBuilderWrapper &BuilderWrapper = - static_cast(Builder); + const auto &BuilderWrapper = + static_cast(Builder); const LangOptions &LangOpts = BuilderWrapper.getLangOpts(); EfficiencySanitizerOptions Opts; if (LangOpts.Sanitize.has(SanitizerKind::EfficiencyCacheFrag)) @@ -246,7 +246,7 @@ static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple, const CodeGenOptions &CodeGenOpts) { - TargetLibraryInfoImpl *TLII = new TargetLibraryInfoImpl(TargetTriple); + auto *TLII = new TargetLibraryInfoImpl(TargetTriple); if (!CodeGenOpts.SimplifyLibCalls) TLII->disableAllFunctions(); else { @@ -511,7 +511,7 @@ .Case("default", llvm::CodeModel::Default) .Default(~0u); assert(CodeModel != ~0u && "invalid code model!"); - llvm::CodeModel::Model CM = static_cast(CodeModel); + auto CM = static_cast(CodeModel); std::string FeaturesStr = llvm::join(TargetOpts.Features.begin(), TargetOpts.Features.end(), ","); Index: lib/CodeGen/CGAtomic.cpp =================================================================== --- lib/CodeGen/CGAtomic.cpp +++ lib/CodeGen/CGAtomic.cpp @@ -409,7 +409,7 @@ uint64_t Size, llvm::AtomicOrdering SuccessOrder) { llvm::AtomicOrdering FailureOrder; - if (llvm::ConstantInt *FO = dyn_cast(FailureOrderVal)) { + if (auto *FO = dyn_cast(FailureOrderVal)) { auto FOS = FO->getSExtValue(); if (!llvm::isValidAtomicOrderingCABI(FOS)) FailureOrder = llvm::AtomicOrdering::Monotonic; @@ -490,7 +490,7 @@ llvm::Value *IsWeak, llvm::Value *FailureOrder, uint64_t Size, llvm::AtomicOrdering Order) { llvm::AtomicRMWInst::BinOp Op = llvm::AtomicRMWInst::Add; - llvm::Instruction::BinaryOps PostOp = (llvm::Instruction::BinaryOps)0; + auto PostOp = (llvm::Instruction::BinaryOps)0; switch (E->getOp()) { case AtomicExpr::AO__c11_atomic_init: @@ -506,7 +506,7 @@ return; case AtomicExpr::AO__atomic_compare_exchange: case AtomicExpr::AO__atomic_compare_exchange_n: { - if (llvm::ConstantInt *IsWeakC = dyn_cast(IsWeak)) { + if (auto *IsWeakC = dyn_cast(IsWeak)) { emitAtomicCmpXchgFailureSet(CGF, E, IsWeakC->getZExtValue(), Dest, Ptr, Val1, Val2, FailureOrder, Size, Order); } else { @@ -661,7 +661,7 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) { QualType AtomicTy = E->getPtr()->getType()->getPointeeType(); QualType MemTy = AtomicTy; - if (const AtomicType *AT = AtomicTy->getAs()) + if (const auto *AT = AtomicTy->getAs()) MemTy = AT->getValueType(); CharUnits sizeChars, alignChars; std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy); @@ -841,7 +841,7 @@ MemTy->isPointerType() ? getContext().getIntPtrType() : MemTy; QualType RetTy; bool HaveRetTy = false; - llvm::Instruction::BinaryOps PostOp = (llvm::Instruction::BinaryOps)0; + auto PostOp = (llvm::Instruction::BinaryOps)0; switch (E->getOp()) { case AtomicExpr::AO__c11_atomic_init: llvm_unreachable("Already handled!"); Index: lib/CodeGen/CGBlocks.cpp =================================================================== --- lib/CodeGen/CGBlocks.cpp +++ lib/CodeGen/CGBlocks.cpp @@ -78,8 +78,8 @@ const CGBlockInfo &blockInfo) { ASTContext &C = CGM.getContext(); - llvm::IntegerType *ulong = - cast(CGM.getTypes().ConvertType(C.UnsignedLongTy)); + auto *ulong = + cast(CGM.getTypes().ConvertType(C.UnsignedLongTy)); llvm::PointerType *i8p = nullptr; if (CGM.getLangOpts().OpenCL) i8p = @@ -968,8 +968,7 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue) { - const BlockPointerType *BPT = - E->getCallee()->getType()->getAs(); + const auto *BPT = E->getCallee()->getType()->getAs(); llvm::Value *BlockPtr = EmitScalarExpr(E->getCallee()); @@ -998,7 +997,7 @@ // Load the function. llvm::Value *Func = Builder.CreateAlignedLoad(FuncPtr, getPointerAlign()); - const FunctionType *FuncTy = FnType->castAs(); + const auto *FuncTy = FnType->castAs(); const CGFunctionInfo &FnInfo = CGM.getTypes().arrangeBlockFunctionCall(Args, FuncTy); @@ -1941,7 +1940,7 @@ generator.CopyHelper = buildByrefCopyHelper(CGM, byrefInfo, generator); generator.DisposeHelper = buildByrefDisposeHelper(CGM, byrefInfo, generator); - T *copy = new (CGM.getContext()) T(std::forward(generator)); + auto *copy = new (CGM.getContext()) T(std::forward(generator)); CGM.ByrefHelpersCache.InsertNode(copy, insertPos); return copy; } @@ -2157,8 +2156,8 @@ Address addr = emission.Addr; // That's an alloca of the byref structure type. - llvm::StructType *byrefType = cast( - cast(addr.getPointer()->getType())->getElementType()); + auto *byrefType = cast( + cast(addr.getPointer()->getType())->getElementType()); unsigned nextHeaderIndex = 0; CharUnits nextHeaderOffset; Index: lib/CodeGen/CGBuiltin.cpp =================================================================== --- lib/CodeGen/CGBuiltin.cpp +++ lib/CodeGen/CGBuiltin.cpp @@ -53,8 +53,7 @@ else Name = Context.BuiltinInfo.getName(BuiltinID) + 10; - llvm::FunctionType *Ty = - cast(getTypes().ConvertType(FD->getType())); + auto *Ty = cast(getTypes().ConvertType(FD->getType())); return GetOrCreateLLVMFunction(Name, Ty, D, /*ForVTable=*/false); } @@ -894,8 +893,8 @@ (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : nullptr; Value *AlignmentValue = EmitScalarExpr(E->getArg(1)); - ConstantInt *AlignmentCI = cast(AlignmentValue); - unsigned Alignment = (unsigned) AlignmentCI->getZExtValue(); + auto *AlignmentCI = cast(AlignmentValue); + auto Alignment = (unsigned)AlignmentCI->getZExtValue(); EmitAlignmentAssumption(PtrValue, Alignment, OffsetValue); return RValue::get(PtrValue); @@ -1303,8 +1302,7 @@ return RValue::get(Result); } case Builtin::BI__builtin_dwarf_sp_column: { - llvm::IntegerType *Ty - = cast(ConvertType(E->getType())); + auto *Ty = cast(ConvertType(E->getType())); int Column = getTargetHooks().getDwarfEHStackPointer(CGM); if (Column == -1) { CGM.ErrorUnsupported(E, "__builtin_dwarf_sp_column"); @@ -1322,7 +1320,7 @@ Value *Int = EmitScalarExpr(E->getArg(0)); Value *Ptr = EmitScalarExpr(E->getArg(1)); - llvm::IntegerType *IntTy = cast(Int->getType()); + auto *IntTy = cast(Int->getType()); assert((IntTy->getBitWidth() == 32 || IntTy->getBitWidth() == 64) && "LLVM's __builtin_eh_return only supports 32- and 64-bit variants"); Value *F = CGM.getIntrinsic(IntTy->getBitWidth() == 32 @@ -2104,7 +2102,7 @@ // __noop always evaluates to an integer literal zero. return RValue::get(ConstantInt::get(IntTy, 0)); case Builtin::BI__builtin_call_with_static_chain: { - const CallExpr *Call = cast(E->getArg(0)); + const auto *Call = cast(E->getArg(0)); const Expr *Chain = E->getArg(1); return EmitCall(Call->getCallee()->getType(), EmitCallee(Call->getCallee()), Call, ReturnValue, @@ -2912,7 +2910,7 @@ Value *CodeGenFunction::EmitNeonRShiftImm(Value *Vec, Value *Shift, llvm::Type *Ty, bool usgn, const char *name) { - llvm::VectorType *VTy = cast(Ty); + auto *VTy = cast(Ty); int ShiftAmt = cast(Shift)->getSExtValue(); int EltSize = VTy->getScalarSizeInBits(); @@ -4085,7 +4083,7 @@ // codegen context to find out what needs doing. Unfortunately TableGen // currently gives us exactly the same calls for vceqz_f32 and vceqz_s32 // (etc). - if (BitCastInst *BI = dyn_cast(Op)) + if (auto *BI = dyn_cast(Op)) OTy = BI->getOperand(0)->getType(); Op = Builder.CreateBitCast(Op, OTy); @@ -4107,7 +4105,7 @@ // Build a vector containing sequential number like (0, 1, 2, ..., 15) SmallVector Indices; - llvm::VectorType *TblTy = cast(Ops[0]->getType()); + auto *TblTy = cast(Ops[0]->getType()); for (unsigned i = 0, e = TblTy->getNumElements(); i != e; ++i) { Indices.push_back(2*i); Indices.push_back(2*i+1); @@ -4325,7 +4323,7 @@ for (unsigned i = 0; i < 2; i++) Ops[i] = EmitScalarExpr(E->getArg(i)); llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType()); - llvm::FunctionType *FTy = cast(Ty); + auto *FTy = cast(Ty); StringRef Name = FD->getName(); return EmitNounwindRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Ops); } @@ -4894,7 +4892,7 @@ } llvm::Type *Tys[] = {Ty, Int8PtrTy}; Function *F = CGM.getIntrinsic(Int, Tys); - llvm::StructType *STy = cast(F->getReturnType()); + auto *STy = cast(F->getReturnType()); SmallVector Args; Args.push_back(Ops[1]); @@ -5165,7 +5163,7 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E) { - unsigned HintID = static_cast(-1); + auto HintID = static_cast(-1); switch (BuiltinID) { default: break; case AArch64::BI__builtin_arm_nop: @@ -5238,7 +5236,7 @@ for (unsigned i = 0; i < 2; i++) Ops[i] = EmitScalarExpr(E->getArg(i)); llvm::Type *Ty = CGM.getTypes().ConvertType(FD->getType()); - llvm::FunctionType *FTy = cast(Ty); + auto *FTy = cast(Ty); StringRef Name = FD->getName(); return EmitNounwindRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Ops); } @@ -5810,19 +5808,19 @@ } case NEON::BI__builtin_neon_vshld_n_s64: case NEON::BI__builtin_neon_vshld_n_u64: { - llvm::ConstantInt *Amt = cast(EmitScalarExpr(E->getArg(1))); + auto *Amt = cast(EmitScalarExpr(E->getArg(1))); return Builder.CreateShl( Ops[0], ConstantInt::get(Int64Ty, Amt->getZExtValue()), "shld_n"); } case NEON::BI__builtin_neon_vshrd_n_s64: { - llvm::ConstantInt *Amt = cast(EmitScalarExpr(E->getArg(1))); + auto *Amt = cast(EmitScalarExpr(E->getArg(1))); return Builder.CreateAShr( Ops[0], ConstantInt::get(Int64Ty, std::min(static_cast(63), Amt->getZExtValue())), "shrd_n"); } case NEON::BI__builtin_neon_vshrd_n_u64: { - llvm::ConstantInt *Amt = cast(EmitScalarExpr(E->getArg(1))); + auto *Amt = cast(EmitScalarExpr(E->getArg(1))); uint64_t ShiftAmt = Amt->getZExtValue(); // Right-shifting an unsigned value by its size yields 0. if (ShiftAmt == 64) @@ -5831,7 +5829,7 @@ "shrd_n"); } case NEON::BI__builtin_neon_vsrad_n_s64: { - llvm::ConstantInt *Amt = cast(EmitScalarExpr(E->getArg(2))); + auto *Amt = cast(EmitScalarExpr(E->getArg(2))); Ops[1] = Builder.CreateAShr( Ops[1], ConstantInt::get(Int64Ty, std::min(static_cast(63), Amt->getZExtValue())), @@ -5839,7 +5837,7 @@ return Builder.CreateAdd(Ops[0], Ops[1]); } case NEON::BI__builtin_neon_vsrad_n_u64: { - llvm::ConstantInt *Amt = cast(EmitScalarExpr(E->getArg(2))); + auto *Amt = cast(EmitScalarExpr(E->getArg(2))); uint64_t ShiftAmt = Amt->getZExtValue(); // Right-shifting an unsigned value by its size yields 0. // As Op + 0 = Op, return Ops[0] directly. @@ -5956,7 +5954,7 @@ llvm::Type *SourceTy = BuiltinID == NEON::BI__builtin_neon_vfmaq_lane_v ? llvm::VectorType::get(VTy->getElementType(), VTy->getNumElements() / 2) : VTy; - llvm::Constant *cst = cast(Ops[3]); + auto *cst = cast(Ops[3]); Value *SV = llvm::ConstantVector::getSplat(VTy->getNumElements(), cst); Ops[1] = Builder.CreateBitCast(Ops[1], SourceTy); Ops[1] = Builder.CreateShuffleVector(Ops[1], Ops[1], SV, "lane"); @@ -5966,7 +5964,7 @@ return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "fmla"); } case NEON::BI__builtin_neon_vfma_laneq_v: { - llvm::VectorType *VTy = cast(Ty); + auto *VTy = cast(Ty); // v1f64 fma should be mapped to Neon scalar f64 fma if (VTy && VTy->getElementType() == DoubleTy) { Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy); @@ -6037,7 +6035,7 @@ case NEON::BI__builtin_neon_vpadal_v: case NEON::BI__builtin_neon_vpadalq_v: { unsigned ArgElts = VTy->getNumElements(); - llvm::IntegerType *EltTy = cast(VTy->getElementType()); + auto *EltTy = cast(VTy->getElementType()); unsigned BitWidth = EltTy->getBitWidth(); llvm::Type *ArgTy = llvm::VectorType::get( llvm::IntegerType::get(getLLVMContext(), BitWidth/2), 2*ArgElts); @@ -7175,7 +7173,7 @@ // additional support via __builtin_isnan()). auto getVectorFCmpIR = [this, &Ops](CmpInst::Predicate Pred) { Value *Cmp = Builder.CreateFCmp(Pred, Ops[0], Ops[1]); - llvm::VectorType *FPVecTy = cast(Ops[0]->getType()); + auto *FPVecTy = cast(Ops[0]->getType()); llvm::VectorType *IntVecTy = llvm::VectorType::getInteger(FPVecTy); Value *Sext = Builder.CreateSExt(Cmp, IntVecTy); return Builder.CreateBitCast(Sext, FPVecTy); @@ -8305,8 +8303,8 @@ return emitFPIntBuiltin(*this, E, Intrinsic::amdgcn_class); case AMDGPU::BI__builtin_amdgcn_read_exec: { - CallInst *CI = cast( - EmitSpecialRegisterBuiltin(*this, E, Int64Ty, Int64Ty, true, "exec")); + auto *CI = cast( + EmitSpecialRegisterBuiltin(*this, E, Int64Ty, Int64Ty, true, "exec")); CI->setConvergent(); return CI; } Index: lib/CodeGen/CGCUDANV.cpp =================================================================== --- lib/CodeGen/CGCUDANV.cpp +++ lib/CodeGen/CGCUDANV.cpp @@ -62,8 +62,7 @@ llvm::Constant *Zeros[] = {llvm::ConstantInt::get(SizeTy, 0), llvm::ConstantInt::get(SizeTy, 0)}; auto ConstStr = CGM.GetAddrOfConstantCString(Str, Name.c_str()); - llvm::GlobalVariable *GV = - cast(ConstStr.getPointer()); + auto *GV = cast(ConstStr.getPointer()); if (!SectionName.empty()) GV->setSection(SectionName); if (Alignment) Index: lib/CodeGen/CGCXXABI.cpp =================================================================== --- lib/CodeGen/CGCXXABI.cpp +++ lib/CodeGen/CGCXXABI.cpp @@ -80,8 +80,7 @@ ErrorUnsupportedABI(CGF, "calls through member pointers"); ThisPtrForCall = This.getPointer(); - const FunctionProtoType *FPT = - MPT->getPointeeType()->getAs(); + const auto *FPT = MPT->getPointeeType()->getAs(); const CXXRecordDecl *RD = cast(MPT->getClass()->getAs()->getDecl()); llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType( @@ -155,7 +154,7 @@ } void CGCXXABI::buildThisParam(CodeGenFunction &CGF, FunctionArgList ¶ms) { - const CXXMethodDecl *MD = cast(CGF.CurGD.getDecl()); + const auto *MD = cast(CGF.CurGD.getDecl()); // FIXME: I'm not entirely sure I like using a fake decl just for code // generation. Maybe we can come up with a better way? @@ -288,7 +287,7 @@ CharUnits ThisAdjustment = CharUnits::Zero(); ArrayRef Path = MP.getMemberPointerPath(); bool DerivedMember = MP.isMemberPointerToDerivedMember(); - const CXXRecordDecl *RD = cast(MPD->getDeclContext()); + const auto *RD = cast(MPD->getDeclContext()); for (unsigned I = 0, N = Path.size(); I != N; ++I) { const CXXRecordDecl *Base = RD; const CXXRecordDecl *Derived = Path[I]; Index: lib/CodeGen/CGCall.cpp =================================================================== --- lib/CodeGen/CGCall.cpp +++ lib/CodeGen/CGCall.cpp @@ -186,7 +186,7 @@ if (D->hasAttr()) return CC_X86Pascal; - if (PcsAttr *PCS = D->getAttr()) + if (auto *PCS = D->getAttr()) return (PCS->getPCS() == PcsAttr::AAPCS ? CC_AAPCS : CC_AAPCS_VFP); if (D->hasAttr()) @@ -383,7 +383,7 @@ /// definition of the given function. const CGFunctionInfo & CodeGenTypes::arrangeFunctionDeclaration(const FunctionDecl *FD) { - if (const CXXMethodDecl *MD = dyn_cast(FD)) + if (const auto *MD = dyn_cast(FD)) if (MD->isInstance()) return arrangeCXXMethodDeclaration(MD); @@ -460,12 +460,12 @@ const CGFunctionInfo & CodeGenTypes::arrangeGlobalDeclaration(GlobalDecl GD) { // FIXME: Do we need to handle ObjCMethodDecl? - const FunctionDecl *FD = cast(GD.getDecl()); + const auto *FD = cast(GD.getDecl()); - if (const CXXConstructorDecl *CD = dyn_cast(FD)) + if (const auto *CD = dyn_cast(FD)) return arrangeCXXStructorDeclaration(CD, getFromCtorType(GD.getCtorType())); - if (const CXXDestructorDecl *DD = dyn_cast(FD)) + if (const auto *DD = dyn_cast(FD)) return arrangeCXXStructorDeclaration(DD, getFromDtorType(GD.getDtorType())); return arrangeFunctionDeclaration(FD); @@ -525,7 +525,7 @@ // If we have a variadic prototype, the required arguments are the // extra prefix plus the arguments in the prototype. - if (const FunctionProtoType *proto = dyn_cast(fnType)) { + if (const auto *proto = dyn_cast(fnType)) { if (proto->isVariadic()) required = RequiredArgs(proto->getNumParams() + numExtraRequiredArgs); @@ -743,7 +743,7 @@ operator new(totalSizeToAlloc( argTypes.size() + 1, paramInfos.size())); - CGFunctionInfo *FI = new(buffer) CGFunctionInfo(); + auto *FI = new (buffer) CGFunctionInfo(); FI->CallingConvention = llvmCC; FI->EffectiveCallingConvention = llvmCC; FI->ASTCallingConvention = info.getCC(); @@ -885,7 +885,7 @@ return llvm::make_unique(std::move(Bases), std::move(Fields)); } - if (const ComplexType *CT = Ty->getAs()) { + if (const auto *CT = Ty->getAs()) { return llvm::make_unique(CT->getElementType()); } return llvm::make_unique(); @@ -1075,7 +1075,7 @@ // If the first element is a struct, recurse. llvm::Type *SrcTy = SrcPtr.getElementType(); - if (llvm::StructType *SrcSTy = dyn_cast(SrcTy)) + if (auto *SrcSTy = dyn_cast(SrcTy)) return EnterStructPointerForCoercedAccess(SrcPtr, SrcSTy, DstSize, CGF); return SrcPtr; @@ -1152,7 +1152,7 @@ uint64_t DstSize = CGF.CGM.getDataLayout().getTypeAllocSize(Ty); - if (llvm::StructType *SrcSTy = dyn_cast(SrcTy)) { + if (auto *SrcSTy = dyn_cast(SrcTy)) { Src = EnterStructPointerForCoercedAccess(Src, SrcSTy, DstSize, CGF); SrcTy = Src.getType()->getElementType(); } @@ -1196,8 +1196,7 @@ static void BuildAggStore(CodeGenFunction &CGF, llvm::Value *Val, Address Dest, bool DestIsVolatile) { // Prefer scalar stores to first-class aggregate stores. - if (llvm::StructType *STy = - dyn_cast(Val->getType())) { + if (auto *STy = dyn_cast(Val->getType())) { const llvm::StructLayout *Layout = CGF.CGM.getDataLayout().getStructLayout(STy); @@ -1231,7 +1230,7 @@ uint64_t SrcSize = CGF.CGM.getDataLayout().getTypeAllocSize(SrcTy); - if (llvm::StructType *DstSTy = dyn_cast(DstTy)) { + if (auto *DstSTy = dyn_cast(DstTy)) { Dst = EnterStructPointerForCoercedAccess(Dst, DstSTy, SrcSize, CGF); DstTy = Dst.getType()->getElementType(); } @@ -1380,7 +1379,7 @@ case ABIArgInfo::Extend: case ABIArgInfo::Direct: { // FIXME: handle sseregparm someday... - llvm::StructType *STy = dyn_cast(AI.getCoerceToType()); + auto *STy = dyn_cast(AI.getCoerceToType()); if (AI.isDirect() && AI.getCanBeFlattened() && STy) { IRArgs.NumberOfArgs = STy->getNumElements(); } else { @@ -1452,7 +1451,7 @@ } bool CodeGenModule::ReturnTypeUsesFP2Ret(QualType ResultType) { - if (const ComplexType *CT = ResultType->getAs()) { + if (const auto *CT = ResultType->getAs()) { if (const BuiltinType *BT = CT->getElementType()->getAs()) { if (BT->getKind() == BuiltinType::LongDouble) return getTarget().useObjCFP2RetForComplexLongDouble(); @@ -1560,7 +1559,7 @@ // Fast-isel and the optimizer generally like scalar values better than // FCAs, so we flatten them if this is safe to do for this argument. llvm::Type *argType = ArgInfo.getCoerceToType(); - llvm::StructType *st = dyn_cast(argType); + auto *st = dyn_cast(argType); if (st && ArgInfo.isDirect() && ArgInfo.getCanBeFlattened()) { assert(NumIRArgs == st->getNumElements()); for (unsigned i = 0, e = st->getNumElements(); i != e; ++i) @@ -1596,8 +1595,8 @@ } llvm::Type *CodeGenTypes::GetFunctionTypeForVTable(GlobalDecl GD) { - const CXXMethodDecl *MD = cast(GD.getDecl()); - const FunctionProtoType *FPT = MD->getType()->getAs(); + const auto *MD = cast(GD.getDecl()); + const auto *FPT = MD->getType()->getAs(); if (!isFuncTypeConvertible(FPT)) return llvm::StructType::get(getLLVMContext()); @@ -1655,12 +1654,12 @@ if (TargetDecl->hasAttr()) FuncAttrs.addAttribute(llvm::Attribute::Convergent); - if (const FunctionDecl *Fn = dyn_cast(TargetDecl)) { + if (const auto *Fn = dyn_cast(TargetDecl)) { AddAttributesFromFunctionProtoType( getContext(), FuncAttrs, Fn->getType()->getAs()); // Don't use [[noreturn]] or _Noreturn for a call to a virtual function. // These attributes are not inherited by overloads. - const CXXMethodDecl *MD = dyn_cast(Fn); + const auto *MD = dyn_cast(Fn); if (Fn->isNoReturn() && !(AttrOnCallSite && MD && MD->isVirtual())) FuncAttrs.addAttribute(llvm::Attribute::NoReturn); } @@ -1770,7 +1769,7 @@ // we have a decl for the function and it has a target attribute then // parse that and add it to the feature set. StringRef TargetCPU = getTarget().getTargetOpts().CPU; - const FunctionDecl *FD = dyn_cast_or_null(TargetDecl); + const auto *FD = dyn_cast_or_null(TargetDecl); if (FD && FD->hasAttr()) { llvm::StringMap FeatureMap; getFunctionFeatureMap(FeatureMap, FD); @@ -2109,7 +2108,7 @@ // initialize the return value. TODO: it might be nice to have // a more general mechanism for this that didn't require synthesized // return statements. - if (const FunctionDecl *FD = dyn_cast_or_null(CurCodeDecl)) { + if (const auto *FD = dyn_cast_or_null(CurCodeDecl)) { if (FD->hasImplicitReturnZero()) { QualType RetTy = FD->getReturnType().getUnqualifiedType(); llvm::Type* LLVMTy = CGM.getTypes().ConvertType(RetTy); @@ -2235,7 +2234,7 @@ llvm::Value *V = FnArgs[FirstIRArg]; auto AI = cast(V); - if (const ParmVarDecl *PVD = dyn_cast(Arg)) { + if (const auto *PVD = dyn_cast(Arg)) { if (getNonNullAttr(CurCodeDecl, PVD, PVD->getType(), PVD->getFunctionScopeIndex())) AI->addAttr(llvm::AttributeSet::get(getLLVMContext(), @@ -2284,8 +2283,7 @@ if (AVAttr) { llvm::Value *AlignmentValue = EmitScalarExpr(AVAttr->getAlignment()); - llvm::ConstantInt *AlignmentCI = - cast(AlignmentValue); + auto *AlignmentCI = cast(AlignmentValue); unsigned Alignment = std::min((unsigned) AlignmentCI->getZExtValue(), +llvm::Value::MaximumAlignment); @@ -2348,7 +2346,7 @@ // Fast-isel and the optimizer generally like scalar values better than // FCAs, so we flatten them if this is safe to do for this argument. - llvm::StructType *STy = dyn_cast(ArgI.getCoerceToType()); + auto *STy = dyn_cast(ArgI.getCoerceToType()); if (ArgI.isDirect() && ArgI.getCanBeFlattened() && STy && STy->getNumElements() > 1) { auto SrcLayout = CGM.getDataLayout().getStructLayout(STy); @@ -2465,7 +2463,7 @@ static void eraseUnusedBitCasts(llvm::Instruction *insn) { while (insn->use_empty()) { - llvm::BitCastInst *bitcast = dyn_cast(insn); + auto *bitcast = dyn_cast(insn); if (!bitcast) return; // This is "safe" because we would have used a ConstantExpr otherwise. @@ -2485,13 +2483,13 @@ llvm::Type *resultType = result->getType(); // result is in a BasicBlock and is therefore an Instruction. - llvm::Instruction *generator = cast(result); + auto *generator = cast(result); SmallVector InstsToKill; // Look for: // %generator = bitcast %type1* %generator2 to %type2* - while (llvm::BitCastInst *bitcast = dyn_cast(generator)) { + while (auto *bitcast = dyn_cast(generator)) { // We would have emitted this as a constant if the operand weren't // an Instruction. generator = cast(bitcast->getOperand(0)); @@ -2507,7 +2505,7 @@ // %generator = call i8* @objc_retain(i8* %originalResult) // or // %generator = call i8* @objc_retainAutoreleasedReturnValue(i8* %originalResult) - llvm::CallInst *call = dyn_cast(generator); + auto *call = dyn_cast(generator); if (!call) return nullptr; bool doRetainAutorelease; @@ -2544,7 +2542,7 @@ // Keep killing bitcasts, for sanity. Note that we no longer care // about precise ordering as long as there's exactly one use. - while (llvm::BitCastInst *bitcast = dyn_cast(result)) { + while (auto *bitcast = dyn_cast(result)) { if (!bitcast->hasOneUse()) break; InstsToKill.push_back(bitcast); result = bitcast->getOperand(0); @@ -2566,23 +2564,20 @@ static llvm::Value *tryRemoveRetainOfSelf(CodeGenFunction &CGF, llvm::Value *result) { // This is only applicable to a method with an immutable 'self'. - const ObjCMethodDecl *method = - dyn_cast_or_null(CGF.CurCodeDecl); + const auto *method = dyn_cast_or_null(CGF.CurCodeDecl); if (!method) return nullptr; const VarDecl *self = method->getSelfDecl(); if (!self->getType().isConstQualified()) return nullptr; // Look for a retain call. - llvm::CallInst *retainCall = - dyn_cast(result->stripPointerCasts()); + auto *retainCall = dyn_cast(result->stripPointerCasts()); if (!retainCall || retainCall->getCalledValue() != CGF.CGM.getObjCEntrypoints().objc_retain) return nullptr; // Look for an ordinary load of 'self'. llvm::Value *retainedValue = retainCall->getArgOperand(0); - llvm::LoadInst *load = - dyn_cast(retainedValue->stripPointerCasts()); + auto *load = dyn_cast(retainedValue->stripPointerCasts()); if (!load || load->isAtomic() || load->isVolatile() || load->getPointerOperand() != CGF.GetAddrOfLocalVar(self).getPointer()) return nullptr; @@ -2646,8 +2641,7 @@ for (llvm::BasicBlock::reverse_iterator II = IP->rbegin(), IE = IP->rend(); II != IE; ++II) { - if (llvm::IntrinsicInst *Intrinsic = - dyn_cast(&*II)) { + if (auto *Intrinsic = dyn_cast(&*II)) { if (Intrinsic->getIntrinsicID() == llvm::Intrinsic::lifetime_end) { const llvm::Value *CastAddr = Intrinsic->getArgOperand(1); ++II; @@ -3027,7 +3021,7 @@ } static const Expr *maybeGetUnaryAddrOfOperand(const Expr *E) { - if (const UnaryOperator *uop = dyn_cast(E->IgnoreParens())) + if (const auto *uop = dyn_cast(E->IgnoreParens())) if (uop->getOpcode() == UO_AddrOf) return uop->getSubExpr(); return nullptr; @@ -3059,8 +3053,7 @@ // The dest and src types don't necessarily match in LLVM terms // because of the crazy ObjC compatibility rules. - llvm::PointerType *destType = - cast(CGF.ConvertType(CRE->getType())); + auto *destType = cast(CGF.ConvertType(CRE->getType())); // If the address is a constant null, just pass the appropriate null. if (isProvablyNull(srcAddr.getPointer())) { @@ -3302,8 +3295,7 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E, QualType type) { DisableDebugLocationUpdates Dis(*this, E); - if (const ObjCIndirectCopyRestoreExpr *CRE - = dyn_cast(E)) { + if (const auto *CRE = dyn_cast(E)) { assert(getLangOpts().ObjCAutoRefCount); assert(getContext().hasSameUnqualifiedType(E->getType(), type)); return emitWritebackArg(*this, args, CRE); @@ -3642,8 +3634,7 @@ assert(getTarget().getTriple().getArch() == llvm::Triple::x86); if (RV.isAggregate()) { // Replace the placeholder with the appropriate argument slot GEP. - llvm::Instruction *Placeholder = - cast(RV.getAggregatePointer()); + auto *Placeholder = cast(RV.getAggregatePointer()); CGBuilderTy::InsertPoint IP = Builder.saveIP(); Builder.SetInsertPoint(Placeholder); Address Addr = createInAllocaStructGEP(ArgInfo.getInAllocaFieldIndex()); @@ -3774,8 +3765,7 @@ // Fast-isel and the optimizer generally like scalar values better than // FCAs, so we flatten them if this is safe to do for this argument. - llvm::StructType *STy = - dyn_cast(ArgInfo.getCoerceToType()); + auto *STy = dyn_cast(ArgInfo.getCoerceToType()); if (STy && ArgInfo.isDirect() && ArgInfo.getCanBeFlattened()) { llvm::Type *SrcTy = Src.getType()->getElementType(); uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(SrcTy); @@ -3886,7 +3876,7 @@ #ifndef NDEBUG // Assert that these structs have equivalent element types. llvm::StructType *FullTy = CallInfo.getArgStruct(); - llvm::StructType *DeclaredTy = cast( + auto *DeclaredTy = cast( cast(LastParamTy)->getElementType()); assert(DeclaredTy->getNumElements() == FullTy->getNumElements()); for (llvm::StructType::element_iterator DI = DeclaredTy->element_begin(), @@ -3910,17 +3900,17 @@ // // This makes the IR nicer, but more importantly it ensures that we // can inline the function at -O0 if it is marked always_inline. - auto simplifyVariadicCallee = [](llvm::Value *Ptr) -> llvm::Value* { - llvm::FunctionType *CalleeFT = - cast(Ptr->getType()->getPointerElementType()); + auto simplifyVariadicCallee = [](llvm::Value *Ptr) -> llvm::Value * { + auto *CalleeFT = + cast(Ptr->getType()->getPointerElementType()); if (!CalleeFT->isVarArg()) return Ptr; - llvm::ConstantExpr *CE = dyn_cast(Ptr); + auto *CE = dyn_cast(Ptr); if (!CE || CE->getOpcode() != llvm::Instruction::BitCast) return Ptr; - llvm::Function *OrigFn = dyn_cast(CE->getOperand(0)); + auto *OrigFn = dyn_cast(CE->getOperand(0)); if (!OrigFn) return Ptr; @@ -4052,7 +4042,7 @@ AddObjCARCExceptionMetadata(CI); // Suppress tail calls if requested. - if (llvm::CallInst *Call = dyn_cast(CI)) { + if (auto *Call = dyn_cast(CI)) { const Decl *TargetDecl = Callee.getAbstractInfo().getCalleeDecl(); if (TargetDecl && TargetDecl->hasAttr()) Call->setTailCallKind(llvm::CallInst::TCK_NoTail); @@ -4201,7 +4191,7 @@ OffsetValue = EmitScalarExpr(Offset); llvm::Value *Alignment = EmitScalarExpr(AA->getAlignment()); - llvm::ConstantInt *AlignmentCI = cast(Alignment); + auto *AlignmentCI = cast(Alignment); EmitAlignmentAssumption(Ret.getScalarVal(), AlignmentCI->getZExtValue(), OffsetValue); } Index: lib/CodeGen/CGClass.cpp =================================================================== --- lib/CodeGen/CGClass.cpp +++ lib/CodeGen/CGClass.cpp @@ -527,8 +527,8 @@ Address ThisPtr = CGF.LoadCXXThisAddress(); const Type *BaseType = BaseInit->getBaseClass(); - CXXRecordDecl *BaseClassDecl = - cast(BaseType->getAs()->getDecl()); + auto *BaseClassDecl = + cast(BaseType->getAs()->getDecl()); bool isBaseVirtual = BaseInit->isBaseVirtual(); @@ -623,7 +623,7 @@ if (Array && Constructor->isDefaulted() && Constructor->isCopyOrMoveConstructor()) { QualType BaseElementTy = CGF.getContext().getBaseElementType(Array); - CXXConstructExpr *CE = dyn_cast(MemberInit->getInit()); + auto *CE = dyn_cast(MemberInit->getInit()); if (BaseElementTy.isPODType(CGF.getContext()) || (CE && isMemcpyEquivalentSpecialMember(CE->getConstructor()))) { unsigned SrcArgIndex = @@ -797,7 +797,7 @@ /// EmitConstructorBody - Emits the body of the current constructor. void CodeGenFunction::EmitConstructorBody(FunctionArgList &Args) { EmitAsanPrologueOrEpilogue(true); - const CXXConstructorDecl *Ctor = cast(CurGD.getDecl()); + const auto *Ctor = cast(CurGD.getDecl()); CXXCtorType CtorType = CurGD.getCtorType(); assert((CGM.getTarget().getCXXABI().hasConstructorVariants() || @@ -1025,7 +1025,7 @@ FieldDecl *Field = MemberInit->getMember(); assert(Field && "No field for member init."); QualType FieldType = Field->getType(); - CXXConstructExpr *CE = dyn_cast(MemberInit->getInit()); + auto *CE = dyn_cast(MemberInit->getInit()); // Bail out on non-memcpyable, not-trivially-copyable members. if (!(CE && isMemcpyEquivalentSpecialMember(CE->getConstructor())) && @@ -1116,62 +1116,62 @@ FieldDecl *getMemcpyableField(Stmt *S) { if (!AssignmentsMemcpyable) return nullptr; - if (BinaryOperator *BO = dyn_cast(S)) { + if (auto *BO = dyn_cast(S)) { // Recognise trivial assignments. if (BO->getOpcode() != BO_Assign) return nullptr; - MemberExpr *ME = dyn_cast(BO->getLHS()); + auto *ME = dyn_cast(BO->getLHS()); if (!ME) return nullptr; - FieldDecl *Field = dyn_cast(ME->getMemberDecl()); + auto *Field = dyn_cast(ME->getMemberDecl()); if (!Field || !isMemcpyableField(Field)) return nullptr; Stmt *RHS = BO->getRHS(); - if (ImplicitCastExpr *EC = dyn_cast(RHS)) + if (auto *EC = dyn_cast(RHS)) RHS = EC->getSubExpr(); if (!RHS) return nullptr; - MemberExpr *ME2 = dyn_cast(RHS); + auto *ME2 = dyn_cast(RHS); if (dyn_cast(ME2->getMemberDecl()) != Field) return nullptr; return Field; - } else if (CXXMemberCallExpr *MCE = dyn_cast(S)) { - CXXMethodDecl *MD = dyn_cast(MCE->getCalleeDecl()); + } else if (auto *MCE = dyn_cast(S)) { + auto *MD = dyn_cast(MCE->getCalleeDecl()); if (!(MD && isMemcpyEquivalentSpecialMember(MD))) return nullptr; - MemberExpr *IOA = dyn_cast(MCE->getImplicitObjectArgument()); + auto *IOA = dyn_cast(MCE->getImplicitObjectArgument()); if (!IOA) return nullptr; - FieldDecl *Field = dyn_cast(IOA->getMemberDecl()); + auto *Field = dyn_cast(IOA->getMemberDecl()); if (!Field || !isMemcpyableField(Field)) return nullptr; - MemberExpr *Arg0 = dyn_cast(MCE->getArg(0)); + auto *Arg0 = dyn_cast(MCE->getArg(0)); if (!Arg0 || Field != dyn_cast(Arg0->getMemberDecl())) return nullptr; return Field; - } else if (CallExpr *CE = dyn_cast(S)) { - FunctionDecl *FD = dyn_cast(CE->getCalleeDecl()); + } else if (auto *CE = dyn_cast(S)) { + auto *FD = dyn_cast(CE->getCalleeDecl()); if (!FD || FD->getBuiltinID() != Builtin::BI__builtin_memcpy) return nullptr; Expr *DstPtr = CE->getArg(0); - if (ImplicitCastExpr *DC = dyn_cast(DstPtr)) + if (auto *DC = dyn_cast(DstPtr)) DstPtr = DC->getSubExpr(); - UnaryOperator *DUO = dyn_cast(DstPtr); + auto *DUO = dyn_cast(DstPtr); if (!DUO || DUO->getOpcode() != UO_AddrOf) return nullptr; - MemberExpr *ME = dyn_cast(DUO->getSubExpr()); + auto *ME = dyn_cast(DUO->getSubExpr()); if (!ME) return nullptr; - FieldDecl *Field = dyn_cast(ME->getMemberDecl()); + auto *Field = dyn_cast(ME->getMemberDecl()); if (!Field || !isMemcpyableField(Field)) return nullptr; Expr *SrcPtr = CE->getArg(1); - if (ImplicitCastExpr *SC = dyn_cast(SrcPtr)) + if (auto *SC = dyn_cast(SrcPtr)) SrcPtr = SC->getSubExpr(); - UnaryOperator *SUO = dyn_cast(SrcPtr); + auto *SUO = dyn_cast(SrcPtr); if (!SUO || SUO->getOpcode() != UO_AddrOf) return nullptr; - MemberExpr *ME2 = dyn_cast(SUO->getSubExpr()); + auto *ME2 = dyn_cast(SUO->getSubExpr()); if (!ME2 || Field != dyn_cast(ME2->getMemberDecl())) return nullptr; return Field; @@ -1351,7 +1351,7 @@ if (!RT) return true; - CXXRecordDecl *FieldClassDecl = cast(RT->getDecl()); + auto *FieldClassDecl = cast(RT->getDecl()); // The destructor for an implicit anonymous union member is never invoked. if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion()) @@ -1381,7 +1381,7 @@ /// EmitDestructorBody - Emits the body of the current destructor. void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) { - const CXXDestructorDecl *Dtor = cast(CurGD.getDecl()); + const auto *Dtor = cast(CurGD.getDecl()); CXXDtorType DtorType = CurGD.getDtorType(); Stmt *Body = Dtor->getBody(); @@ -1476,11 +1476,11 @@ } void CodeGenFunction::emitImplicitAssignmentOperatorBody(FunctionArgList &Args) { - const CXXMethodDecl *AssignOp = cast(CurGD.getDecl()); + const auto *AssignOp = cast(CurGD.getDecl()); const Stmt *RootS = AssignOp->getBody(); assert(isa(RootS) && "Body of an implicit assignment operator should be compound stmt."); - const CompoundStmt *RootCS = cast(RootS); + const auto *RootCS = cast(RootS); LexicalScope Scope(*this, RootCS->getSourceRange()); @@ -1497,7 +1497,7 @@ CallDtorDelete() {} void Emit(CodeGenFunction &CGF, Flags flags) override { - const CXXDestructorDecl *Dtor = cast(CGF.CurCodeDecl); + const auto *Dtor = cast(CGF.CurCodeDecl); const CXXRecordDecl *ClassDecl = Dtor->getParent(); CGF.EmitDeleteCall(Dtor->getOperatorDelete(), CGF.LoadCXXThis(), CGF.getContext().getTagDeclType(ClassDecl)); @@ -1521,7 +1521,7 @@ CGF.Builder.CreateCondBr(ShouldCallDelete, continueBB, callDeleteBB); CGF.EmitBlock(callDeleteBB); - const CXXDestructorDecl *Dtor = cast(CGF.CurCodeDecl); + const auto *Dtor = cast(CGF.CurCodeDecl); const CXXRecordDecl *ClassDecl = Dtor->getParent(); CGF.EmitDeleteCall(Dtor->getOperatorDelete(), CGF.LoadCXXThis(), CGF.getContext().getTagDeclType(ClassDecl)); @@ -1724,8 +1724,8 @@ // We push them in the forward order so that they'll be popped in // the reverse order. for (const auto &Base : ClassDecl->vbases()) { - CXXRecordDecl *BaseClassDecl - = cast(Base.getType()->getAs()->getDecl()); + auto *BaseClassDecl = + cast(Base.getType()->getAs()->getDecl()); // Ignore trivial destructors. if (BaseClassDecl->hasTrivialDestructor()) @@ -1827,8 +1827,7 @@ llvm::BranchInst *zeroCheckBranch = nullptr; // Optimize for a constant count. - llvm::ConstantInt *constantCount - = dyn_cast(numElements); + auto *constantCount = dyn_cast(numElements); if (constantCount) { // Just skip out if the constant count is zero. if (constantCount->isZero()) return; @@ -1949,7 +1948,7 @@ } // Add the rest of the user-supplied arguments. - const FunctionProtoType *FPT = D->getType()->castAs(); + const auto *FPT = D->getType()->castAs(); EmitCallArgs(Args, FPT, E->arguments(), E->getConstructor()); EmitCXXConstructorCall(D, Type, ForVirtualBase, Delegating, This, Args); @@ -2173,7 +2172,7 @@ CodeGenFunction::EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, Address This, Address Src, const CXXConstructExpr *E) { - const FunctionProtoType *FPT = D->getType()->castAs(); + const auto *FPT = D->getType()->castAs(); CallArgList Args; @@ -2391,8 +2390,8 @@ // Traverse bases. for (const auto &I : RD->bases()) { - CXXRecordDecl *BaseDecl - = cast(I.getType()->getAs()->getDecl()); + auto *BaseDecl = + cast(I.getType()->getAs()->getDecl()); // Ignore classes without a vtable. if (!BaseDecl->isDynamicClass()) @@ -2731,8 +2730,8 @@ if (BestDynamicDecl->hasAttr()) return true; - if (const DeclRefExpr *DRE = dyn_cast(Base)) { - if (const VarDecl *VD = dyn_cast(DRE->getDecl())) { + if (const auto *DRE = dyn_cast(Base)) { + if (const auto *VD = dyn_cast(DRE->getDecl())) { // This is a record decl. We know the type and can devirtualize it. return VD->getType()->isRecordType(); } @@ -2743,7 +2742,7 @@ // 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(Base)) + if (const auto *ME = dyn_cast(Base)) if (const ValueDecl *VD = dyn_cast(ME->getMemberDecl())) return VD->getType()->isRecordType(); @@ -2772,8 +2771,7 @@ CGM.getTypes().GetFunctionType(calleeFnInfo)); // Prepare the return slot. - const FunctionProtoType *FPT = - callOperator->getType()->castAs(); + const auto *FPT = callOperator->getType()->castAs(); QualType resultType = FPT->getReturnType(); ReturnValueSlot returnSlot; if (!resultType->isVoidType() && Index: lib/CodeGen/CGCleanup.h =================================================================== --- lib/CodeGen/CGCleanup.h +++ lib/CodeGen/CGCleanup.h @@ -575,7 +575,7 @@ inline void EHScopeStack::popCatch() { assert(!empty() && "popping exception stack when not empty"); - EHCatchScope &scope = cast(*begin()); + auto &scope = cast(*begin()); InnermostEHScope = scope.getEnclosingEHScope(); deallocate(EHCatchScope::getSizeForNumHandlers(scope.getNumHandlers())); } @@ -583,7 +583,7 @@ inline void EHScopeStack::popTerminate() { assert(!empty() && "popping exception stack when not empty"); - EHTerminateScope &scope = cast(*begin()); + auto &scope = cast(*begin()); InnermostEHScope = scope.getEnclosingEHScope(); deallocate(EHTerminateScope::getSize()); } Index: lib/CodeGen/CGCleanup.cpp =================================================================== --- lib/CodeGen/CGCleanup.cpp +++ lib/CodeGen/CGCleanup.cpp @@ -127,7 +127,7 @@ NewCapacity *= 2; } while (NewCapacity < UsedCapacity + Size); - char *NewStartOfBuffer = new char[NewCapacity]; + auto *NewStartOfBuffer = new char[NewCapacity]; char *NewEndOfBuffer = NewStartOfBuffer + NewCapacity; char *NewStartOfData = NewEndOfBuffer - UsedCapacity; memcpy(NewStartOfData, StartOfData, UsedCapacity); @@ -149,7 +149,7 @@ bool EHScopeStack::containsOnlyLifetimeMarkers( EHScopeStack::stable_iterator Old) const { for (EHScopeStack::iterator it = begin(); stabilize(it) != Old; it++) { - EHCleanupScope *cleanup = dyn_cast(&*it); + auto *cleanup = dyn_cast(&*it); if (!cleanup || !cleanup->isLifetimeMarker()) return false; } @@ -175,7 +175,7 @@ EHScopeStack::getInnermostActiveNormalCleanup() const { for (stable_iterator si = getInnermostNormalCleanup(), se = stable_end(); si != se; ) { - EHCleanupScope &cleanup = cast(*find(si)); + auto &cleanup = cast(*find(si)); if (cleanup.isActive()) return si; si = cleanup.getEnclosingNormalCleanup(); } @@ -189,14 +189,9 @@ bool IsEHCleanup = Kind & EHCleanup; bool IsActive = !(Kind & InactiveCleanup); bool IsLifetimeMarker = Kind & LifetimeMarker; - EHCleanupScope *Scope = - new (Buffer) EHCleanupScope(IsNormalCleanup, - IsEHCleanup, - IsActive, - Size, - BranchFixups.size(), - InnermostNormalCleanup, - InnermostEHScope); + auto *Scope = new (Buffer) EHCleanupScope( + IsNormalCleanup, IsEHCleanup, IsActive, Size, BranchFixups.size(), + InnermostNormalCleanup, InnermostEHScope); if (IsNormalCleanup) InnermostNormalCleanup = stable_begin(); if (IsEHCleanup) @@ -211,7 +206,7 @@ assert(!empty() && "popping exception stack when not empty"); assert(isa(*begin())); - EHCleanupScope &Cleanup = cast(*begin()); + auto &Cleanup = cast(*begin()); InnermostNormalCleanup = Cleanup.getEnclosingNormalCleanup(); InnermostEHScope = Cleanup.getEnclosingEHScope(); deallocate(Cleanup.getAllocatedSize()); @@ -235,7 +230,7 @@ EHFilterScope *EHScopeStack::pushFilter(unsigned numFilters) { assert(getInnermostEHScope() == stable_end()); char *buffer = allocate(EHFilterScope::getSizeForNumFilters(numFilters)); - EHFilterScope *filter = new (buffer) EHFilterScope(numFilters); + auto *filter = new (buffer) EHFilterScope(numFilters); InnermostEHScope = stable_begin(); return filter; } @@ -243,7 +238,7 @@ void EHScopeStack::popFilter() { assert(!empty() && "popping exception stack when not empty"); - EHFilterScope &filter = cast(*begin()); + auto &filter = cast(*begin()); deallocate(EHFilterScope::getSizeForNumFilters(filter.getNumFilters())); InnermostEHScope = filter.getEnclosingEHScope(); @@ -251,8 +246,7 @@ EHCatchScope *EHScopeStack::pushCatch(unsigned numHandlers) { char *buffer = allocate(EHCatchScope::getSizeForNumHandlers(numHandlers)); - EHCatchScope *scope = - new (buffer) EHCatchScope(numHandlers, InnermostEHScope); + auto *scope = new (buffer) EHCatchScope(numHandlers, InnermostEHScope); InnermostEHScope = stable_begin(); return scope; } @@ -295,7 +289,7 @@ Builder.CreateStore(Builder.getTrue(), active); // Set that as the active flag in the cleanup. - EHCleanupScope &cleanup = cast(*EHStack.begin()); + auto &cleanup = cast(*EHStack.begin()); assert(!cleanup.hasActiveFlag() && "cleanup already has active flag?"); cleanup.setActiveFlag(active); @@ -366,7 +360,7 @@ llvm::TerminatorInst *Term = Block->getTerminator(); assert(Term && "can't transition block without terminator"); - if (llvm::BranchInst *Br = dyn_cast(Term)) { + if (auto *Br = dyn_cast(Term)) { assert(Br->isUnconditional()); auto Load = createLoadInstBefore(CGF.getNormalCleanupDestSlot(), "cleanup.dest", Term); @@ -422,7 +416,7 @@ assert(Old.isValid()); while (EHStack.stable_begin() != Old) { - EHCleanupScope &Scope = cast(*EHStack.begin()); + auto &Scope = cast(*EHStack.begin()); // As long as Old strictly encloses the scope's enclosing normal // cleanup, we're going to emit another normal cleanup which @@ -448,9 +442,8 @@ assert((I % alignof(LifetimeExtendedCleanupHeader) == 0) && "misaligned cleanup stack entry"); - LifetimeExtendedCleanupHeader &Header = - reinterpret_cast( - LifetimeExtendedCleanupStack[I]); + auto &Header = reinterpret_cast( + LifetimeExtendedCleanupStack[I]); I += sizeof(Header); EHStack.pushCopyOfCleanup(Header.getKind(), @@ -482,7 +475,7 @@ llvm::BasicBlock *Pred = Entry->getSinglePredecessor(); if (!Pred) return Entry; - llvm::BranchInst *Br = dyn_cast(Pred->getTerminator()); + auto *Br = dyn_cast(Pred->getTerminator()); if (!Br || Br->isConditional()) return Entry; assert(Br->getSuccessor(0) == Entry); @@ -543,11 +536,11 @@ // an unconditional branch or a switch. llvm::TerminatorInst *Term = Exit->getTerminator(); - if (llvm::BranchInst *Br = dyn_cast(Term)) { + if (auto *Br = dyn_cast(Term)) { assert(Br->isUnconditional() && Br->getSuccessor(0) == From); Br->setSuccessor(0, To); } else { - llvm::SwitchInst *Switch = cast(Term); + auto *Switch = cast(Term); for (unsigned I = 0, E = Switch->getNumSuccessors(); I != E; ++I) if (Switch->getSuccessor(I) == From) Switch->setSuccessor(I, To); @@ -575,13 +568,13 @@ use.set(unreachableBB); // The only uses should be fixup switches. - llvm::SwitchInst *si = cast(use.getUser()); + auto *si = cast(use.getUser()); if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) { // Replace the switch with a branch. llvm::BranchInst::Create(si->case_begin().getCaseSuccessor(), si); // The switch operand is a load from the cleanup-dest alloca. - llvm::LoadInst *condition = cast(si->getCondition()); + auto *condition = cast(si->getCondition()); // Destroy the switch. si->eraseFromParent(); @@ -603,7 +596,7 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) { assert(!EHStack.empty() && "cleanup stack is empty!"); assert(isa(*EHStack.begin()) && "top not a cleanup!"); - EHCleanupScope &Scope = cast(*EHStack.begin()); + auto &Scope = cast(*EHStack.begin()); assert(Scope.getFixupDepth() <= EHStack.getNumBranchFixups()); // Remember activation information. @@ -791,7 +784,7 @@ assert(!BranchThroughDest || !IsActive); // Clean up the possibly dead store to the cleanup dest slot. - llvm::Instruction *NormalCleanupDestSlot = + auto *NormalCleanupDestSlot = cast(getNormalCleanupDestSlot().getPointer()); if (NormalCleanupDestSlot->hasOneUse()) { NormalCleanupDestSlot->user_back()->eraseFromParent(); @@ -1038,8 +1031,7 @@ // Adjust BI to point to the first cleanup block. { - EHCleanupScope &Scope = - cast(*EHStack.find(TopCleanup)); + auto &Scope = cast(*EHStack.find(TopCleanup)); BI->setSuccessor(0, CreateNormalEntry(*this, Scope)); } @@ -1048,7 +1040,7 @@ EHScopeStack::stable_iterator E = Dest.getScopeDepth(); if (E.strictlyEncloses(I)) { while (true) { - EHCleanupScope &Scope = cast(*EHStack.find(I)); + auto &Scope = cast(*EHStack.find(I)); assert(Scope.isNormalCleanup()); I = Scope.getEnclosingNormalCleanup(); @@ -1081,7 +1073,7 @@ I = EHStack.getInnermostNormalCleanup(); I != C; ) { assert(C.strictlyEncloses(I)); - EHCleanupScope &S = cast(*EHStack.find(I)); + auto &S = cast(*EHStack.find(I)); if (S.getNormalBlock()) return true; I = S.getEnclosingNormalCleanup(); } @@ -1124,7 +1116,7 @@ EHScopeStack::stable_iterator C, ForActivation_t kind, llvm::Instruction *dominatingIP) { - EHCleanupScope &Scope = cast(*CGF.EHStack.find(C)); + auto &Scope = cast(*CGF.EHStack.find(C)); // We always need the flag if we're activating the cleanup in a // conditional context, because we have to assume that the current @@ -1181,7 +1173,7 @@ void CodeGenFunction::ActivateCleanupBlock(EHScopeStack::stable_iterator C, llvm::Instruction *dominatingIP) { assert(C != EHStack.stable_end() && "activating bottom of stack?"); - EHCleanupScope &Scope = cast(*EHStack.find(C)); + auto &Scope = cast(*EHStack.find(C)); assert(!Scope.isActive() && "double activation"); SetupCleanupBlockActivation(*this, C, ForActivation, dominatingIP); @@ -1193,7 +1185,7 @@ void CodeGenFunction::DeactivateCleanupBlock(EHScopeStack::stable_iterator C, llvm::Instruction *dominatingIP) { assert(C != EHStack.stable_end() && "deactivating bottom of stack?"); - EHCleanupScope &Scope = cast(*EHStack.find(C)); + auto &Scope = cast(*EHStack.find(C)); assert(Scope.isActive() && "double deactivation"); // If it's the top of the stack, just pop it. Index: lib/CodeGen/CGDebugInfo.h =================================================================== --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -553,7 +553,7 @@ /// and return a reference to it. If multiple arguments are given the strings /// are concatenated. StringRef internString(StringRef A, StringRef B = StringRef()) { - char *Data = DebugInfoNames.Allocate(A.size() + B.size()); + auto *Data = DebugInfoNames.Allocate(A.size() + B.size()); if (!A.empty()) std::memcpy(Data, A.data(), A.size()); if (!B.empty()) Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -1168,7 +1168,7 @@ llvm::DISubroutineType * CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method, llvm::DIFile *Unit) { - const FunctionProtoType *Func = Method->getType()->getAs(); + const auto *Func = Method->getType()->getAs(); if (Method->isStatic()) return cast_or_null( getOrCreateType(QualType(Func, 0), Unit)); @@ -1193,7 +1193,7 @@ const CXXRecordDecl *RD = ThisPtr->getPointeeCXXRecordDecl(); if (isa(RD)) { // Create pointer type directly in this case. - const PointerType *ThisPtrTy = cast(ThisPtr); + const auto *ThisPtrTy = cast(ThisPtr); QualType PointeeTy = ThisPtrTy->getPointeeType(); unsigned AS = CGM.getContext().getTargetAddressSpace(PointeeTy); uint64_t Size = CGM.getTarget().getPointerWidth(AS); @@ -1790,7 +1790,7 @@ llvm::DIType *CGDebugInfo::CreateType(const RecordType *Ty) { RecordDecl *RD = Ty->getDecl(); - llvm::DIType *T = cast_or_null(getTypeOrNull(QualType(Ty, 0))); + auto *T = cast_or_null(getTypeOrNull(QualType(Ty, 0))); if (T || shouldOmitDefinition(DebugKind, DebugTypeExtRefs, RD, CGM.getLangOpts())) { if (!T) @@ -2278,8 +2278,7 @@ getOrCreateType(Ty->getPointeeType(), U), ClassType, Size, /*Align=*/0, Flags); - const FunctionProtoType *FPT = - Ty->getPointeeType()->getAs(); + const auto *FPT = Ty->getPointeeType()->getAs(); return DBuilder.createMemberPointerType( getOrCreateInstanceMethodType(CGM.getContext().getPointerType(QualType( Ty->getClass(), FPT->getTypeQuals())), @@ -2746,11 +2745,11 @@ LinkageName = StringRef(); if (DebugKind >= codegenoptions::LimitedDebugInfo) { - if (const NamespaceDecl *NSDecl = - dyn_cast_or_null(FD->getDeclContext())) + if (const auto *NSDecl = + dyn_cast_or_null(FD->getDeclContext())) FDContext = getOrCreateNameSpace(NSDecl); - else if (const RecordDecl *RDecl = - dyn_cast_or_null(FD->getDeclContext())) { + else if (const auto *RDecl = + dyn_cast_or_null(FD->getDeclContext())) { llvm::DIScope *Mod = getParentModuleOrNull(RDecl); FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU); } Index: lib/CodeGen/CGDecl.cpp =================================================================== --- lib/CodeGen/CGDecl.cpp +++ lib/CodeGen/CGDecl.cpp @@ -119,7 +119,7 @@ return; case Decl::Var: case Decl::Decomposition: { - const VarDecl &VD = cast(D); + const auto &VD = cast(D); assert(VD.isLocalVarDecl() && "Should not see file-scope variables inside a function!"); EmitVarDecl(VD); @@ -135,7 +135,7 @@ case Decl::Typedef: // typedef int X; case Decl::TypeAlias: { // using X = int; [C++0x] - const TypedefNameDecl &TD = cast(D); + const auto &TD = cast(D); QualType Ty = TD.getUnderlyingType(); if (Ty->isVariablyModifiedType()) @@ -256,7 +256,7 @@ // Ensure that the static local gets initialized by making sure the parent // function gets emitted eventually. - const Decl *DC = cast(D.getDeclContext()); + const auto *DC = cast(D.getDeclContext()); // We can't name blocks or captured statements directly, so try to emit their // parents. @@ -379,8 +379,7 @@ // Save the type in case adding the initializer forces a type change. llvm::Type *expectedType = addr->getType(); - llvm::GlobalVariable *var = - cast(addr->stripPointerCasts()); + auto *var = cast(addr->stripPointerCasts()); // CUDA's local and local static __shared__ variables should not // have any non-empty initializers. This is ensured by Sema. @@ -580,14 +579,14 @@ } static bool isAccessedBy(const VarDecl &var, const Stmt *s) { - if (const Expr *e = dyn_cast(s)) { + if (const auto *e = dyn_cast(s)) { // Skip the most common kinds of expressions that make // hierarchy-walking expensive. s = e = e->IgnoreParenCasts(); - if (const DeclRefExpr *ref = dyn_cast(e)) + if (const auto *ref = dyn_cast(e)) return (ref->getDecl() == &var); - if (const BlockExpr *be = dyn_cast(e)) { + if (const auto *be = dyn_cast(e)) { const BlockDecl *block = be->getBlockDecl(); for (const auto &I : block->captures()) { if (I.getVariable() == &var) @@ -607,7 +606,7 @@ static bool isAccessedBy(const ValueDecl *decl, const Expr *e) { if (!decl) return false; if (!isa(decl)) return false; - const VarDecl *var = cast(decl); + const auto *var = cast(decl); return isAccessedBy(*var, e); } @@ -678,12 +677,12 @@ return; } - if (const CXXDefaultInitExpr *DIE = dyn_cast(init)) + if (const auto *DIE = dyn_cast(init)) init = DIE->getExpr(); // If we're emitting a value with lifetime, we have to do the // initialization *before* we leave the cleanup scopes. - if (const ExprWithCleanups *ewc = dyn_cast(init)) { + if (const auto *ewc = dyn_cast(init)) { enterFullExpression(ewc); init = ewc->getSubExpr(); } @@ -793,15 +792,14 @@ // See if we can emit each element. if (isa(Init) || isa(Init)) { for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) { - llvm::Constant *Elt = cast(Init->getOperand(i)); + auto *Elt = cast(Init->getOperand(i)); if (!canEmitInitWithFewStoresAfterMemset(Elt, NumStores)) return false; } return true; } - if (llvm::ConstantDataSequential *CDS = - dyn_cast(Init)) { + if (auto *CDS = dyn_cast(Init)) { for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) { llvm::Constant *Elt = CDS->getElementAsConstant(i); if (!canEmitInitWithFewStoresAfterMemset(Elt, NumStores)) @@ -829,8 +827,7 @@ return; } - if (llvm::ConstantDataSequential *CDS = - dyn_cast(Init)) { + if (auto *CDS = dyn_cast(Init)) { for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) { llvm::Constant *Elt = CDS->getElementAsConstant(i); @@ -847,7 +844,7 @@ "Unknown value type!"); for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) { - llvm::Constant *Elt = cast(Init->getOperand(i)); + auto *Elt = cast(Init->getOperand(i)); // If necessary, get a pointer to the element and emit it. if (!Elt->isNullValue() && !isa(Elt)) @@ -1089,7 +1086,7 @@ // hierarchy-walking expensive. e = e->IgnoreParenCasts(); - if (const BlockExpr *be = dyn_cast(e)) { + if (const auto *be = dyn_cast(e)) { const BlockDecl *block = be->getBlockDecl(); for (const auto &I : block->captures()) { if (I.getVariable() == &var) @@ -1100,7 +1097,7 @@ return false; } - if (const StmtExpr *SE = dyn_cast(e)) { + if (const auto *SE = dyn_cast(e)) { const CompoundStmt *CS = SE->getSubStmt(); for (const auto *BI : CS->body()) if (const auto *E = dyn_cast(BI)) { @@ -1137,7 +1134,7 @@ if (!Init) return true; - if (const CXXConstructExpr *Construct = dyn_cast(Init)) + if (const auto *Construct = dyn_cast(Init)) if (CXXConstructorDecl *Constructor = Construct->getConstructor()) if (Constructor->isTrivial() && Constructor->isDefaultConstructor() && @@ -1497,7 +1494,7 @@ bool checkZeroLength = true; // But if the array length is constant, we can suppress that. - if (llvm::ConstantInt *constLength = dyn_cast(length)) { + if (auto *constLength = dyn_cast(length)) { // ...and if it's constant zero, we can just skip the entire thing. if (constLength->isZero()) return; checkZeroLength = false; @@ -1744,8 +1741,7 @@ // Apply any prologue 'this' adjustments required by the ABI. Be careful to // handle the case where 'this' is passed indirectly as part of an inalloca // struct. - if (const CXXMethodDecl *MD = - dyn_cast_or_null(CurCodeDecl)) { + if (const auto *MD = dyn_cast_or_null(CurCodeDecl)) { if (MD->isVirtual() && IPD == CXXABIThisDecl) { llvm::Value *This = Arg.isIndirect() ? Builder.CreateLoad(Arg.getIndirectAddress()) @@ -1803,7 +1799,7 @@ // 'self' is always formally __strong, but if this is not an // init method then we don't want to retain it. if (D.isARCPseudoStrong()) { - const ObjCMethodDecl *method = cast(CurCodeDecl); + const auto *method = cast(CurCodeDecl); assert(&D == method->getSelfDecl()); assert(lt == Qualifiers::OCL_Strong); assert(qs.hasConst()); Index: lib/CodeGen/CGDeclCXX.cpp =================================================================== --- lib/CodeGen/CGDeclCXX.cpp +++ lib/CodeGen/CGDeclCXX.cpp @@ -216,8 +216,7 @@ llvm::CallInst *call = CGF.Builder.CreateCall(dtor, addr); // Make sure the call and the callee agree on calling convention. - if (llvm::Function *dtorFn = - dyn_cast(dtor->stripPointerCasts())) + if (auto *dtorFn = dyn_cast(dtor->stripPointerCasts())) call->setCallingConv(dtorFn->getCallingConv()); CGF.FinishFunction(); @@ -238,7 +237,7 @@ llvm::Constant *atexit = CGM.CreateRuntimeFunction(atexitTy, "atexit"); - if (llvm::Function *atexitFn = dyn_cast(atexit)) + if (auto *atexitFn = dyn_cast(atexit)) atexitFn->setDoesNotThrow(); EmitNounwindRuntimeCall(atexit, dtorStub); @@ -589,7 +588,7 @@ llvm::CallInst *CI = Builder.CreateCall(Callee, DtorsAndObjects[e - i - 1].second); // Make sure the call and the callee agree on calling convention. - if (llvm::Function *F = dyn_cast(Callee)) + if (auto *F = dyn_cast(Callee)) CI->setCallingConv(F->getCallingConv()); } } Index: lib/CodeGen/CGException.cpp =================================================================== --- lib/CodeGen/CGException.cpp +++ lib/CodeGen/CGException.cpp @@ -241,18 +241,17 @@ llvm::Value *Val = LPI->getClause(I)->stripPointerCasts(); if (LPI->isCatch(I)) { // Check if the catch value has the ObjC prefix. - if (llvm::GlobalVariable *GV = dyn_cast(Val)) + if (auto *GV = dyn_cast(Val)) // ObjC EH selector entries are always global variables with // names starting like this. if (GV->getName().startswith("OBJC_EHTYPE")) return false; } else { // Check if any of the filter values have the ObjC prefix. - llvm::Constant *CVal = cast(Val); + auto *CVal = cast(Val); for (llvm::User::op_iterator II = CVal->op_begin(), IE = CVal->op_end(); II != IE; ++II) { - if (llvm::GlobalVariable *GV = - cast((*II)->stripPointerCasts())) + if (auto *GV = cast((*II)->stripPointerCasts())) // ObjC EH selector entries are always global variables with // names starting like this. if (GV->getName().startswith("OBJC_EHTYPE")) @@ -268,7 +267,7 @@ static bool PersonalityHasOnlyCXXUses(llvm::Constant *Fn) { for (llvm::User *U : Fn->users()) { // Conditionally white-list bitcasts. - if (llvm::ConstantExpr *CE = dyn_cast(U)) { + if (auto *CE = dyn_cast(U)) { if (CE->getOpcode() != llvm::Instruction::BitCast) return false; if (!PersonalityHasOnlyCXXUses(CE)) return false; @@ -276,7 +275,7 @@ } // Otherwise it must be a function. - llvm::Function *F = dyn_cast(U); + auto *F = dyn_cast(U); if (!F) return false; for (auto BB = F->begin(), E = F->end(); BB != E; ++BB) { @@ -424,17 +423,17 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) { if (!CGM.getLangOpts().CXXExceptions) return; - - const FunctionDecl* FD = dyn_cast_or_null(D); + + const auto *FD = dyn_cast_or_null(D); if (!FD) { // Check if CapturedDecl is nothrow and create terminate scope for it. - if (const CapturedDecl* CD = dyn_cast_or_null(D)) { + if (const auto *CD = dyn_cast_or_null(D)) { if (CD->isNothrow()) EHStack.pushTerminate(); } return; } - const FunctionProtoType *Proto = FD->getType()->getAs(); + const auto *Proto = FD->getType()->getAs(); if (!Proto) return; @@ -503,17 +502,17 @@ void CodeGenFunction::EmitEndEHSpec(const Decl *D) { if (!CGM.getLangOpts().CXXExceptions) return; - - const FunctionDecl* FD = dyn_cast_or_null(D); + + const auto *FD = dyn_cast_or_null(D); if (!FD) { // Check if CapturedDecl is nothrow and pop terminate scope for it. - if (const CapturedDecl* CD = dyn_cast_or_null(D)) { + if (const auto *CD = dyn_cast_or_null(D)) { if (CD->isNothrow()) EHStack.popTerminate(); } return; } - const FunctionProtoType *Proto = FD->getType()->getAs(); + const auto *Proto = FD->getType()->getAs(); if (!Proto) return; @@ -527,7 +526,7 @@ // encode these in an object file but MSVC doesn't do anything with it. if (getTarget().getCXXABI().isMicrosoft()) return; - EHFilterScope &filterScope = cast(*EHStack.begin()); + auto &filterScope = cast(*EHStack.begin()); emitFilterDispatchBlock(*this, filterScope); EHStack.popFilter(); } @@ -590,7 +589,7 @@ switch (scope.getKind()) { case EHScope::Catch: { // Apply a special case to a single catch-all. - EHCatchScope &catchScope = cast(scope); + auto &catchScope = cast(scope); if (catchScope.getNumHandlers() == 1 && catchScope.getHandler(0).isCatchAll()) { dispatchBlock = catchScope.getHandler(0).Block; @@ -791,7 +790,7 @@ assert(!hasCatchAll && "EH filter reached after catch-all"); // Filter scopes get added to the landingpad in weird ways. - EHFilterScope &filter = cast(*I); + auto &filter = cast(*I); hasFilter = true; // Add all the filter values. @@ -813,7 +812,7 @@ llvm_unreachable("PadEnd unnecessary for Itanium!"); } - EHCatchScope &catchScope = cast(*I); + auto &catchScope = cast(*I); for (unsigned hi = 0, he = catchScope.getNumHandlers(); hi != he; ++hi) { EHCatchScope::Handler handler = catchScope.getHandler(hi); assert(handler.Type.Flags == 0 && @@ -998,7 +997,7 @@ } void CodeGenFunction::popCatchScope() { - EHCatchScope &catchScope = cast(*EHStack.begin()); + auto &catchScope = cast(*EHStack.begin()); if (catchScope.hasEHBranches()) emitCatchDispatchBlock(*this, catchScope); EHStack.popCatch(); @@ -1006,7 +1005,7 @@ void CodeGenFunction::ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock) { unsigned NumHandlers = S.getNumHandlers(); - EHCatchScope &CatchScope = cast(*EHStack.begin()); + auto &CatchScope = cast(*EHStack.begin()); assert(CatchScope.getNumHandlers() == NumHandlers); // If the catch was not required, bail out now. @@ -1207,8 +1206,7 @@ // In the latter case we need to pass it the exception object. // But we can't use the exception slot because the @finally might // have a landing pad (which would overwrite the exception slot). - llvm::FunctionType *rethrowFnTy = - cast( + auto *rethrowFnTy = cast( cast(rethrowFn->getType())->getElementType()); SavedExnVar = nullptr; if (rethrowFnTy->getNumParams()) @@ -1248,7 +1246,7 @@ void CodeGenFunction::FinallyInfo::exit(CodeGenFunction &CGF) { // Leave the finally catch-all. - EHCatchScope &catchScope = cast(*CGF.EHStack.begin()); + auto &catchScope = cast(*CGF.EHStack.begin()); llvm::BasicBlock *catchBB = catchScope.getHandler(0).Block; CGF.popCatchScope(); @@ -1830,7 +1828,7 @@ // Otherwise, we must have an __except block. const SEHExceptStmt *Except = S.getExceptHandler(); assert(Except && "__try must have __finally xor __except"); - EHCatchScope &CatchScope = cast(*EHStack.begin()); + auto &CatchScope = cast(*EHStack.begin()); // Don't emit the __except block if the __try block lacked invokes. // TODO: Model unwind edges from instructions, either with iload / istore or @@ -1860,8 +1858,7 @@ // __except blocks don't get outlined into funclets, so immediately do a // catchret. - llvm::CatchPadInst *CPI = - cast(CatchPadBB->getFirstNonPHI()); + auto *CPI = cast(CatchPadBB->getFirstNonPHI()); llvm::BasicBlock *ExceptBB = createBasicBlock("__except"); Builder.CreateCatchRet(CPI, ExceptBB); EmitBlock(ExceptBB); Index: lib/CodeGen/CGExpr.cpp =================================================================== --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -112,7 +112,7 @@ /// expression and compare the result against zero, returning an Int1Ty value. llvm::Value *CodeGenFunction::EvaluateExprAsBool(const Expr *E) { PGO.setCurrentStmt(E); - if (const MemberPointerType *MPT = E->getType()->getAs()) { + if (const auto *MPT = E->getType()->getAs()) { llvm::Value *MemPtr = EmitScalarExpr(E); return CGM.getCXXABI().EmitMemberPointerIsNotNull(*this, MemPtr, MPT); } @@ -724,7 +724,7 @@ static llvm::Value *getArrayIndexingBound( CodeGenFunction &CGF, const Expr *Base, QualType &IndexedType) { // For the vector indexing extension, the bound is the number of elements. - if (const VectorType *VT = Base->getType()->getAs()) { + if (const auto *VT = Base->getType()->getAs()) { IndexedType = Base->getType(); return CGF.Builder.getInt32(VT->getNumElements()); } @@ -831,7 +831,7 @@ E = E->IgnoreParens(); // Casts: - if (const CastExpr *CE = dyn_cast(E)) { + if (const auto *CE = dyn_cast(E)) { if (const auto *ECE = dyn_cast(CE)) CGM.EmitExplicitCastExprType(ECE, this); @@ -891,7 +891,7 @@ } // Unary &. - if (const UnaryOperator *UO = dyn_cast(E)) { + if (const auto *UO = dyn_cast(E)) { if (UO->getOpcode() == UO_AddrOf) { LValue LV = EmitLValue(UO->getSubExpr()); if (Source) *Source = LV.getAlignmentSource(); @@ -989,7 +989,7 @@ return EmitBinaryOperatorLValue(cast(E)); case Expr::CompoundAssignOperatorClass: { QualType Ty = E->getType(); - if (const AtomicType *AT = Ty->getAs()) + if (const auto *AT = Ty->getAs()) Ty = AT->getValueType(); if (!Ty->isAnyComplexType()) return EmitCompoundAssignmentLValue(cast(E)); @@ -1215,7 +1215,7 @@ if (const EnumType *ET = Ty->getAs()) return ET->getDecl()->getIntegerType()->isBooleanType(); - if (const AtomicType *AT = Ty->getAs()) + if (const auto *AT = Ty->getAs()) return hasBooleanRepresentation(AT->getValueType()); return false; @@ -1528,7 +1528,7 @@ // If the result of the expression is a non-vector type, we must be extracting // a single element. Just codegen as an extractelement. - const VectorType *ExprVT = LV.getType()->getAs(); + const auto *ExprVT = LV.getType()->getAs(); if (!ExprVT) { unsigned InIdx = getAccessedFieldNo(0, Elts); llvm::Value *Elt = llvm::ConstantInt::get(SizeTy, InIdx); @@ -1551,7 +1551,7 @@ /// @brief Generates lvalue for partial ext_vector access. Address CodeGenFunction::EmitExtVectorElementLValue(LValue LV) { Address VectorAddress = LV.getExtVectorAddress(); - const VectorType *ExprVT = LV.getType()->getAs(); + const auto *ExprVT = LV.getType()->getAs(); QualType EQT = ExprVT->getElementType(); llvm::Type *VectorElementTy = CGM.getTypes().ConvertType(EQT); @@ -1574,7 +1574,7 @@ RValue CodeGenFunction::EmitLoadOfGlobalRegLValue(LValue LV) { assert((LV.getType()->isIntegerType() || LV.getType()->isPointerType()) && "Bad type for register variable"); - llvm::MDNode *RegName = cast( + auto *RegName = cast( cast(LV.getGlobalReg())->getMetadata()); // We accept integer and pointer types only @@ -1770,7 +1770,7 @@ llvm::Value *SrcVal = Src.getScalarVal(); - if (const VectorType *VTy = Dst.getType()->getAs()) { + if (const auto *VTy = Dst.getType()->getAs()) { unsigned NumSrcElts = VTy->getNumElements(); unsigned NumDstElts = Vec->getType()->getVectorNumElements(); if (NumDstElts == NumSrcElts) { @@ -1834,7 +1834,7 @@ void CodeGenFunction::EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst) { assert((Dst.getType()->isIntegerType() || Dst.getType()->isPointerType()) && "Bad type for register variable"); - llvm::MDNode *RegName = cast( + auto *RegName = cast( cast(Dst.getGlobalReg())->getMetadata()); assert(RegName && "Register LValue is not metadata"); @@ -2038,8 +2038,7 @@ llvm::Constant *V = CGM.GetAddrOfFunction(FD); if (!FD->hasPrototype()) { - if (const FunctionProtoType *Proto = - FD->getType()->getAs()) { + if (const auto *Proto = FD->getType()->getAs()) { // Ugly case: for a K&R-style definition, the type of the definition // isn't the same as the type of a use. Correct for this with a // bitcast. @@ -2075,7 +2074,7 @@ /// passed down via the metadata node. static LValue EmitGlobalNamedRegister(const VarDecl *VD, CodeGenModule &CGM) { SmallString<64> Name("llvm.named.register."); - AsmLabelAttr *Asm = VD->getAttr(); + auto *Asm = VD->getAttr(); assert(Asm->getLabel().size() < 64-Name.size() && "Register name too big"); Name.append(Asm->getLabel()); @@ -3010,7 +3009,7 @@ Addr = emitArraySubscriptGEP(*this, Addr, Idx, vla->getElementType(), !getLangOpts().isSignedOverflowDefined()); - } else if (const ObjCObjectType *OIT = E->getType()->getAs()){ + } else if (const auto *OIT = E->getType()->getAs()) { // Indexing over an interface, as in "NSString *P; P[4];" // Emit the base pointer. @@ -3278,7 +3277,7 @@ // it. AlignmentSource AlignSource; Address Ptr = EmitPointerWithAlignment(E->getBase(), &AlignSource); - const PointerType *PT = E->getBase()->getType()->getAs(); + const auto *PT = E->getBase()->getType()->getAs(); Base = MakeAddrLValue(Ptr, PT->getPointeeType(), AlignSource); Base.getQuals().removeObjCGCAttr(); } else if (E->getBase()->isGLValue()) { @@ -3436,7 +3435,7 @@ addr = emitAddrOfFieldStorage(*this, addr, field); // If this is a reference field, load the reference right now. - if (const ReferenceType *refType = type->getAs()) { + if (const auto *refType = type->getAs()) { llvm::LoadInst *load = Builder.CreateLoad(addr, "ref"); if (cvr & Qualifiers::Volatile) load->setVolatile(true); @@ -3829,8 +3828,7 @@ return EmitCUDAKernelCallExpr(CE, ReturnValue); if (const auto *CE = dyn_cast(E)) - if (const CXXMethodDecl *MD = - dyn_cast_or_null(CE->getCalleeDecl())) + if (const auto *MD = dyn_cast_or_null(CE->getCalleeDecl())) return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue); CGCallee callee = EmitCallee(E->getCallee()); @@ -4093,7 +4091,7 @@ const Decl *TargetDecl = OrigCallee.getAbstractInfo().getCalleeDecl(); - if (const FunctionDecl *FD = dyn_cast_or_null(TargetDecl)) + if (const auto *FD = dyn_cast_or_null(TargetDecl)) // We can only guarantee that a function is called from the correct // context/function based on the appropriate target attributes, // so only check in the case where we have both always_inline and target @@ -4269,8 +4267,7 @@ llvm::Value *OffsetV = EmitScalarExpr(E->getRHS()); - const MemberPointerType *MPT - = E->getRHS()->getType()->getAs(); + const auto *MPT = E->getRHS()->getType()->getAs(); AlignmentSource AlignSource; Address MemberAddr = Index: lib/CodeGen/CGExprAgg.cpp =================================================================== --- lib/CodeGen/CGExprAgg.cpp +++ lib/CodeGen/CGExprAgg.cpp @@ -564,7 +564,7 @@ static Expr *findPeephole(Expr *op, CastKind kind) { while (true) { op = op->IgnoreParens(); - if (CastExpr *castE = dyn_cast(op)) { + if (auto *castE = dyn_cast(op)) { if (castE->getCastKind() == kind) return castE->getSubExpr(); if (castE->getCastKind() == CK_NoOp) @@ -802,15 +802,15 @@ E = E->IgnoreParens(); // Check for a direct reference to a __block variable. - if (const DeclRefExpr *DRE = dyn_cast(E)) { - const VarDecl *var = dyn_cast(DRE->getDecl()); + if (const auto *DRE = dyn_cast(E)) { + const auto *var = dyn_cast(DRE->getDecl()); return (var && var->hasAttr()); } // More complicated stuff. // Binary operators. - if (const BinaryOperator *op = dyn_cast(E)) { + if (const auto *op = dyn_cast(E)) { // For an assignment or pointer-to-member operation, just care // about the LHS. if (op->isAssignmentOp() || op->isPtrMemOp()) @@ -824,14 +824,12 @@ return false; // Check both sides of a conditional operator. - } else if (const AbstractConditionalOperator *op - = dyn_cast(E)) { + } else if (const auto *op = dyn_cast(E)) { return isBlockVarRef(op->getTrueExpr()) || isBlockVarRef(op->getFalseExpr()); // OVEs are required to support BinaryConditionalOperators. - } else if (const OpaqueValueExpr *op - = dyn_cast(E)) { + } else if (const auto *op = dyn_cast(E)) { if (const Expr *src = op->getSourceExpr()) return isBlockVarRef(src); @@ -839,22 +837,22 @@ // We don't really care about the kind of cast here, except // we don't want to look through l2r casts, because it's okay // to get the *value* in a __block variable. - } else if (const CastExpr *cast = dyn_cast(E)) { + } else if (const auto *cast = dyn_cast(E)) { if (cast->getCastKind() == CK_LValueToRValue) return false; return isBlockVarRef(cast->getSubExpr()); // Handle unary operators. Again, just aggressively look through // it, ignoring the operation. - } else if (const UnaryOperator *uop = dyn_cast(E)) { + } else if (const auto *uop = dyn_cast(E)) { return isBlockVarRef(uop->getSubExpr()); // Look into the base of a field access. - } else if (const MemberExpr *mem = dyn_cast(E)) { + } else if (const auto *mem = dyn_cast(E)) { return isBlockVarRef(mem->getBase()); // Look into the base of a subscript. - } else if (const ArraySubscriptExpr *sub = dyn_cast(E)) { + } else if (const auto *sub = dyn_cast(E)) { return isBlockVarRef(sub->getBase()); } @@ -1041,21 +1039,21 @@ E = E->IgnoreParens(); // 0 - if (const IntegerLiteral *IL = dyn_cast(E)) + if (const auto *IL = dyn_cast(E)) return IL->getValue() == 0; // +0.0 - if (const FloatingLiteral *FL = dyn_cast(E)) + if (const auto *FL = dyn_cast(E)) return FL->getValue().isPosZero(); // int() if ((isa(E) || isa(E)) && CGF.getTypes().isZeroInitializable(E->getType())) return true; // (int*)0 - Null pointer expressions. - if (const CastExpr *ICE = dyn_cast(E)) + if (const auto *ICE = dyn_cast(E)) return ICE->getCastKind() == CK_NullToPointer && CGF.getTypes().isPointerZeroInitializable(E->getType()); // '\0' - if (const CharacterLiteral *CL = dyn_cast(E)) + if (const auto *CL = dyn_cast(E)) return CL->getValue() == 0; // Otherwise, hard case: conservatively return false. @@ -1293,9 +1291,8 @@ // If the GEP didn't get used because of a dead zero init or something // else, clean it up for -O0 builds and general tidiness. - if (!pushedCleanup && LV.isSimple()) - if (llvm::GetElementPtrInst *GEP = - dyn_cast(LV.getPointer())) + if (!pushedCleanup && LV.isSimple()) + if (auto *GEP = dyn_cast(LV.getPointer())) if (GEP->use_empty()) GEP->eraseFromParent(); } @@ -1331,7 +1328,7 @@ // emitting multiple destructor loops in that case. if (!outerBegin) outerBegin = begin; - ArrayInitLoopExpr *InnerLoop = dyn_cast(E->getSubExpr()); + auto *InnerLoop = dyn_cast(E->getSubExpr()); QualType elementType = CGF.getContext().getAsArrayType(E->getType())->getElementType(); @@ -1425,7 +1422,7 @@ // If this is an initlist expr, sum up the size of sizes of the (present) // elements. If this is something weird, assume the whole thing is non-zero. - const InitListExpr *ILE = dyn_cast(E); + const auto *ILE = dyn_cast(E); if (!ILE || !CGF.getTypes().isZeroInitializable(ILE->getType())) return CGF.getContext().getTypeSizeInChars(E->getType()); @@ -1550,7 +1547,7 @@ if (getLangOpts().CPlusPlus) { if (const RecordType *RT = Ty->getAs()) { - CXXRecordDecl *Record = cast(RT->getDecl()); + auto *Record = cast(RT->getDecl()); assert((Record->hasTrivialCopyConstructor() || Record->hasTrivialCopyAssignment() || Record->hasTrivialMoveConstructor() || Index: lib/CodeGen/CGExprCXX.cpp =================================================================== --- lib/CodeGen/CGExprCXX.cpp +++ lib/CodeGen/CGExprCXX.cpp @@ -46,7 +46,7 @@ Args.add(RValue::get(ImplicitParam), ImplicitParamTy); } - const FunctionProtoType *FPT = MD->getType()->castAs(); + const auto *FPT = MD->getType()->castAs(); RequiredArgs required = RequiredArgs::forPrototypePlus(FPT, Args.size(), MD); // And the rest of the call args. @@ -73,7 +73,7 @@ ReturnValueSlot ReturnValue, llvm::Value *This, llvm::Value *ImplicitParam, QualType ImplicitParamTy, const CallExpr *CE, CallArgList *RtlArgs) { - const FunctionProtoType *FPT = MD->getType()->castAs(); + const auto *FPT = MD->getType()->castAs(); CallArgList Args; RequiredArgs required = commonEmitCXXMemberOrOperatorCall( *this, MD, This, ImplicitParam, ImplicitParamTy, CE, Args, RtlArgs); @@ -106,7 +106,7 @@ // If this is s.x, emit s as an lvalue. If it is s->x, emit s as a scalar. if (E->isArrow()) { BaseValue = EmitPointerWithAlignment(BaseExpr); - const PointerType *PTy = BaseExpr->getType()->getAs(); + const auto *PTy = BaseExpr->getType()->getAs(); BaseQuals = PTy->getPointeeType().getQualifiers(); } else { LValue BaseLV = EmitLValue(BaseExpr); @@ -145,7 +145,7 @@ static CXXRecordDecl *getCXXRecord(const Expr *E) { QualType T = E->getType(); - if (const PointerType *PTy = T->getAs()) + if (const auto *PTy = T->getAs()) T = PTy->getPointeeType(); const RecordType *Ty = T->castAs(); return cast(Ty->getDecl()); @@ -160,7 +160,7 @@ if (isa(callee)) return EmitCXXMemberPointerCallExpr(CE, ReturnValue); - const MemberExpr *ME = cast(callee); + const auto *ME = cast(callee); const CXXMethodDecl *MD = cast(ME->getMemberDecl()); if (MD->isStatic()) { @@ -305,8 +305,8 @@ // We also don't emit a virtual call if the base expression has a record type // because then we know what the type is. bool UseVirtualCall = CanUseVirtualCall && !DevirtualizedMethod; - - if (const CXXDestructorDecl *Dtor = dyn_cast(MD)) { + + if (const auto *Dtor = dyn_cast(MD)) { assert(CE->arg_begin() == CE->arg_end() && "Destructor shouldn't have explicit parameters"); assert(ReturnValue.isNull() && "Destructor shouldn't have return value"); @@ -322,8 +322,7 @@ CGM.getAddrOfCXXStructor(Dtor, StructorType::Complete, FInfo, Ty), Dtor); else { - const CXXDestructorDecl *DDtor = - cast(DevirtualizedMethod); + const auto *DDtor = cast(DevirtualizedMethod); Callee = CGCallee::forDirect( CGM.GetAddrOfFunction(GlobalDecl(DDtor, Dtor_Complete), Ty), DDtor); @@ -336,7 +335,7 @@ } CGCallee Callee; - if (const CXXConstructorDecl *Ctor = dyn_cast(MD)) { + if (const auto *Ctor = dyn_cast(MD)) { Callee = CGCallee::forDirect( CGM.GetAddrOfFunction(GlobalDecl(Ctor, Ctor_Complete), Ty), Ctor); @@ -375,16 +374,13 @@ RValue CodeGenFunction::EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue) { - const BinaryOperator *BO = - cast(E->getCallee()->IgnoreParens()); + const auto *BO = cast(E->getCallee()->IgnoreParens()); const Expr *BaseExpr = BO->getLHS(); const Expr *MemFnExpr = BO->getRHS(); - - const MemberPointerType *MPT = - MemFnExpr->getType()->castAs(); - const FunctionProtoType *FPT = - MPT->getPointeeType()->castAs(); + const auto *MPT = MemFnExpr->getType()->castAs(); + + const auto *FPT = MPT->getPointeeType()->castAs(); const CXXRecordDecl *RD = cast(MPT->getClass()->getAs()->getDecl()); @@ -602,11 +598,11 @@ void CodeGenFunction::EmitSynthesizedCXXCopyCtor(Address Dest, Address Src, const Expr *Exp) { - if (const ExprWithCleanups *E = dyn_cast(Exp)) + if (const auto *E = dyn_cast(Exp)) Exp = E->getSubExpr(); assert(isa(Exp) && "EmitSynthesizedCXXCopyCtor - unknown copy ctor expr"); - const CXXConstructExpr* E = cast(Exp); + const auto *E = cast(Exp); const CXXConstructorDecl *CD = E->getConstructor(); RunCleanupsScope Scope(*this); @@ -670,8 +666,7 @@ // the cookie size would bring the total size >= 0. bool isSigned = e->getArraySize()->getType()->isSignedIntegerOrEnumerationType(); - llvm::IntegerType *numElementsType - = cast(numElements->getType()); + auto *numElementsType = cast(numElements->getType()); unsigned numElementsWidth = numElementsType->getBitWidth(); // Compute the constant factor. @@ -691,8 +686,7 @@ // If someone is doing 'new int[42]' there is no need to do a dynamic check. // Don't bloat the -O0 code. - if (llvm::ConstantInt *numElementsC = - dyn_cast(numElements)) { + if (auto *numElementsC = dyn_cast(numElements)) { const llvm::APInt &count = numElementsC->getValue(); bool hasAnyOverflow = false; @@ -969,7 +963,7 @@ }; // If the initializer is an initializer list, first do the explicit elements. - if (const InitListExpr *ILE = dyn_cast(Init)) { + if (const auto *ILE = dyn_cast(Init)) { // Initializing from a (braced) string literal is a special case; the init // list element does not initialize a (single) array element. if (ILE->isStringLiteralInit()) { @@ -995,7 +989,7 @@ ElementSize)); // Zero out the rest, if any remain. - llvm::ConstantInt *ConstNum = dyn_cast(NumElements); + auto *ConstNum = dyn_cast(NumElements); if (!ConstNum || !ConstNum->equalsInt(InitListElements)) { bool OK = TryMemsetInitialization(); (void)OK; @@ -1009,7 +1003,7 @@ // If this is a multi-dimensional array new, we will initialize multiple // elements with each init list element. QualType AllocType = E->getAllocatedType(); - if (const ConstantArrayType *CAT = dyn_cast_or_null( + if (const auto *CAT = dyn_cast_or_null( AllocType->getAsArrayTypeUnsafe())) { ElementTy = ConvertTypeForMem(AllocType); CurPtr = Builder.CreateElementBitCast(CurPtr, ElementTy); @@ -1072,7 +1066,7 @@ // If all elements have already been initialized, skip any further // initialization. - llvm::ConstantInt *ConstNum = dyn_cast(NumElements); + auto *ConstNum = dyn_cast(NumElements); if (ConstNum && ConstNum->getZExtValue() <= InitListElements) { // If there was a Cleanup, deactivate it. if (CleanupDominator) @@ -1084,7 +1078,7 @@ // If this is a constructor call, try to optimize it out, and failing that // emit a single loop to initialize all remaining elements. - if (const CXXConstructExpr *CCE = dyn_cast(Init)) { + if (const auto *CCE = dyn_cast(Init)) { CXXConstructorDecl *Ctor = CCE->getConstructor(); if (Ctor->isTrivial()) { // If new expression did not specify value-initialization, then there @@ -1251,14 +1245,14 @@ /// to a replaceable global allocation function. /// /// We model such elidable calls with the 'builtin' attribute. - llvm::Function *Fn = dyn_cast(CalleePtr); + auto *Fn = dyn_cast(CalleePtr); if (CalleeDecl->isReplaceableGlobalAllocationFunction() && Fn && Fn->hasFnAttribute(llvm::Attribute::NoBuiltin)) { // FIXME: Add addAttribute to CallSite. - if (llvm::CallInst *CI = dyn_cast(CallOrInvoke)) + if (auto *CI = dyn_cast(CallOrInvoke)) CI->addAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::Builtin); - else if (llvm::InvokeInst *II = dyn_cast(CallOrInvoke)) + else if (auto *II = dyn_cast(CallOrInvoke)) II->addAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::Builtin); else @@ -1356,8 +1350,7 @@ } void Emit(CodeGenFunction &CGF, Flags flags) override { - const FunctionProtoType *FPT = - OperatorDelete->getType()->getAs(); + const auto *FPT = OperatorDelete->getType()->getAs(); CallArgList DeleteArgs; // The first argument is always a void*. @@ -1425,14 +1418,9 @@ typedef CallDeleteDuringNew DirectCleanup; - DirectCleanup *Cleanup = CGF.EHStack - .pushCleanupWithExtra(EHCleanup, - E->getNumPlacementArgs(), - E->getOperatorDelete(), - NewPtr.getPointer(), - AllocSize, - E->passAlignment(), - AllocAlign); + auto *Cleanup = CGF.EHStack.pushCleanupWithExtra( + EHCleanup, E->getNumPlacementArgs(), E->getOperatorDelete(), + NewPtr.getPointer(), AllocSize, E->passAlignment(), AllocAlign); for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { auto &Arg = NewArgs[I + NumNonPlacementArgs]; Cleanup->setPlacementArg(I, Arg.RV, Arg.Ty); @@ -1456,14 +1444,9 @@ }; typedef CallDeleteDuringNew ConditionalCleanup; - ConditionalCleanup *Cleanup = CGF.EHStack - .pushCleanupWithExtra(EHCleanup, - E->getNumPlacementArgs(), - E->getOperatorDelete(), - SavedNewPtr, - SavedAllocSize, - E->passAlignment(), - AllocAlign); + auto *Cleanup = CGF.EHStack.pushCleanupWithExtra( + EHCleanup, E->getNumPlacementArgs(), E->getOperatorDelete(), SavedNewPtr, + SavedAllocSize, E->passAlignment(), AllocAlign); for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) { auto &Arg = NewArgs[I + NumNonPlacementArgs]; Cleanup->setPlacementArg(I, DominatingValue::save(CGF, Arg.RV), @@ -1483,7 +1466,7 @@ // If there is a brace-initializer, cannot allocate fewer elements than inits. unsigned minElements = 0; if (E->isArray() && E->hasInitializer()) { - const InitListExpr *ILE = dyn_cast(E->getInitializer()); + const auto *ILE = dyn_cast(E->getInitializer()); if (ILE && ILE->isStringLiteralInit()) minElements = cast(ILE->getType()->getAsArrayTypeUnsafe()) @@ -1525,8 +1508,8 @@ } } else { - const FunctionProtoType *allocatorType = - allocator->getType()->castAs(); + const auto *allocatorType = + allocator->getType()->castAs(); unsigned ParamsToSkip = 0; // The allocation size is the first argument. @@ -1683,8 +1666,7 @@ assert((!NumElements && CookieSize.isZero()) || DeleteFD->getOverloadedOperator() == OO_Array_Delete); - const FunctionProtoType *DeleteFTy = - DeleteFD->getType()->getAs(); + const auto *DeleteFTy = DeleteFD->getType()->getAs(); CallArgList DeleteArgs; @@ -1778,7 +1760,7 @@ // destructor is virtual, we'll just emit the vcall and return. const CXXDestructorDecl *Dtor = nullptr; if (const RecordType *RT = ElementType->getAs()) { - CXXRecordDecl *RD = cast(RT->getDecl()); + auto *RD = cast(RT->getDecl()); if (RD->hasDefinition() && !RD->hasTrivialDestructor()) { Dtor = RD->getDestructor(); @@ -2057,7 +2039,7 @@ // C++ [expr.dynamic.cast]p7: // If T is "pointer to cv void," then the result is a pointer to the most // derived object pointed to by v. - const PointerType *DestPTy = DestTy->getAs(); + const auto *DestPTy = DestTy->getAs(); bool isDynamicCastToVoid; QualType SrcRecordTy; Index: lib/CodeGen/CGExprComplex.cpp =================================================================== --- lib/CodeGen/CGExprComplex.cpp +++ lib/CodeGen/CGExprComplex.cpp @@ -32,7 +32,7 @@ /// Return the complex type that we are meant to emit. static const ComplexType *getComplexType(QualType type) { type = type.getCanonicalType(); - if (const ComplexType *comp = dyn_cast(type)) { + if (const auto *comp = dyn_cast(type)) { return comp; } else { return cast(cast(type)->getValueType()); @@ -825,7 +825,7 @@ TestAndClearIgnoreReal(); TestAndClearIgnoreImag(); QualType LHSTy = E->getLHS()->getType(); - if (const AtomicType *AT = LHSTy->getAs()) + if (const auto *AT = LHSTy->getAs()) LHSTy = AT->getValueType(); BinOpInfo OpInfo; Index: lib/CodeGen/CGExprConstant.cpp =================================================================== --- lib/CodeGen/CGExprConstant.cpp +++ lib/CodeGen/CGExprConstant.cpp @@ -225,7 +225,7 @@ // 'or' in the bits that go into the previous byte. llvm::Value *LastElt = Elements.back(); - if (llvm::ConstantInt *Val = dyn_cast(LastElt)) + if (auto *Val = dyn_cast(LastElt)) Tmp |= Val->getValue(); else { assert(isa(LastElt)); @@ -238,7 +238,7 @@ // padding and then an hole for our i8 to get plopped into. assert(isa(LastElt->getType()) && "Expected array padding of undefs"); - llvm::ArrayType *AT = cast(LastElt->getType()); + auto *AT = cast(LastElt->getType()); assert(AT->getElementType()->isIntegerTy(CharWidth) && AT->getNumElements() != 0 && "Expected non-empty array padding of undefs"); @@ -437,7 +437,7 @@ CharUnits Offset) { const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD); - if (const CXXRecordDecl *CD = dyn_cast(RD)) { + if (const auto *CD = dyn_cast(RD)) { // Add a vtable pointer, if we need one and it hasn't already been added. if (CD->isDynamicClass() && !IsPrimaryBase) { llvm::Constant *VTableAddressPoint = @@ -545,7 +545,7 @@ llvm::ConstantStruct::getTypeForElements(CGM.getLLVMContext(), Elements, Packed); llvm::Type *ValTy = CGM.getTypes().ConvertType(Ty); - if (llvm::StructType *ValSTy = dyn_cast(ValTy)) { + if (auto *ValSTy = dyn_cast(ValTy)) { if (ValSTy->isLayoutIdentical(STy)) STy = ValSTy; } @@ -588,7 +588,7 @@ ConstStructBuilder Builder(CGM, CGF); const RecordDecl *RD = ValTy->castAs()->getDecl(); - const CXXRecordDecl *CD = dyn_cast(RD); + const auto *CD = dyn_cast(RD); Builder.Build(Val, RD, false, CD, CharUnits::Zero()); return Builder.Finalize(ValTy); @@ -779,8 +779,7 @@ } llvm::Constant *EmitArrayInitialization(InitListExpr *ILE) { - llvm::ArrayType *AType = - cast(ConvertType(ILE->getType())); + auto *AType = cast(ConvertType(ILE->getType())); llvm::Type *ElemTy = AType->getElementType(); unsigned NumInitElements = ILE->getNumInits(); unsigned NumElements = AType->getNumElements(); @@ -860,7 +859,7 @@ QualType ExprType = Updater->getType(); if (ExprType->isArrayType()) { - llvm::ArrayType *AType = cast(ConvertType(ExprType)); + auto *AType = cast(ConvertType(ExprType)); llvm::Type *ElemType = AType->getElementType(); unsigned NumInitElements = Updater->getNumInits(); @@ -869,12 +868,10 @@ std::vector Elts; Elts.reserve(NumElements); - if (llvm::ConstantDataArray *DataArray = - dyn_cast(Base)) + if (auto *DataArray = dyn_cast(Base)) for (unsigned i = 0; i != NumElements; ++i) Elts.push_back(DataArray->getElementAsConstant(i)); - else if (llvm::ConstantArray *Array = - dyn_cast(Base)) + else if (auto *Array = dyn_cast(Base)) for (unsigned i = 0; i != NumElements; ++i) Elts.push_back(Array->getOperand(i)); else @@ -895,7 +892,7 @@ Elts[i] = fillC; else if (!Init || isa(Init)) ; // Do nothing. - else if (InitListExpr *ChildILE = dyn_cast(Init)) + else if (auto *ChildILE = dyn_cast(Init)) Elts[i] = EmitDesignatedInitUpdater(Elts[i], ChildILE); else Elts[i] = CGM.EmitConstantExpr(Init, Init->getType(), CGF); @@ -978,7 +975,7 @@ QualType T = E->getType(); if (T->getTypeClass() == Type::TypeOfExpr) T = cast(T)->getUnderlyingExpr()->getType(); - const ConstantArrayType *CAT = cast(T); + const auto *CAT = cast(T); // Resize the string to the right size, adding zeros at the end, or // truncating as needed. @@ -997,12 +994,12 @@ public: ConstantAddress EmitLValue(APValue::LValueBase LVBase) { - if (const ValueDecl *Decl = LVBase.dyn_cast()) { + if (const auto *Decl = LVBase.dyn_cast()) { if (Decl->hasAttr()) return CGM.GetWeakRefReference(Decl); - if (const FunctionDecl *FD = dyn_cast(Decl)) + if (const auto *FD = dyn_cast(Decl)) return ConstantAddress(CGM.GetAddrOfFunction(FD), CharUnits::One()); - if (const VarDecl* VD = dyn_cast(Decl)) { + if (const auto *VD = dyn_cast(Decl)) { // We can never refer to a variable with local storage. if (!VD->hasLocalStorage()) { CharUnits Align = CGM.getContext().getDeclAlign(VD); @@ -1018,13 +1015,13 @@ return ConstantAddress::invalid(); } - Expr *E = const_cast(LVBase.get()); + auto *E = const_cast(LVBase.get()); switch (E->getStmtClass()) { default: break; case Expr::CompoundLiteralExprClass: { // Note that due to the nature of compound literals, this is guaranteed // to be the only use of the variable, so we just generate it here. - CompoundLiteralExpr *CLE = cast(E); + auto *CLE = cast(E); llvm::Constant* C = CGM.EmitConstantExpr(CLE->getInitializer(), CLE->getType(), CGF); // FIXME: "Leaked" on failure. @@ -1046,7 +1043,7 @@ case Expr::ObjCEncodeExprClass: return CGM.GetAddrOfConstantStringFromObjCEncode(cast(E)); case Expr::ObjCStringLiteralClass: { - ObjCStringLiteral* SL = cast(E); + auto *SL = cast(E); ConstantAddress C = CGM.getObjCRuntime().GenerateConstantString(SL->getString()); return C.getElementBitCast(ConvertType(E->getType())); @@ -1070,7 +1067,7 @@ return ConstantAddress(Ptr, CharUnits::One()); } case Expr::CallExprClass: { - CallExpr* CE = cast(E); + auto *CE = cast(E); unsigned builtin = CE->getBuiltinCallee(); if (builtin != Builtin::BI__builtin___CFStringMakeConstantString && @@ -1078,7 +1075,7 @@ Builtin::BI__builtin___NSStringMakeConstantString) break; const Expr *Arg = CE->getArg(0)->IgnoreParenCasts(); - const StringLiteral *Literal = cast(Arg); + const auto *Literal = cast(Arg); if (builtin == Builtin::BI__builtin___NSStringMakeConstantString) { return CGM.getObjCRuntime().GenerateConstantString(Literal); @@ -1099,7 +1096,7 @@ return ConstantAddress(Ptr, CGM.getPointerAlign()); } case Expr::CXXTypeidExprClass: { - CXXTypeidExpr *Typeid = cast(E); + auto *Typeid = cast(E); QualType T; if (Typeid->isTypeOperand()) T = Typeid->getTypeOperand(CGM.getContext()); @@ -1112,7 +1109,7 @@ return CGM.GetAddrOfUuidDescriptor(cast(E)); } case Expr::MaterializeTemporaryExprClass: { - MaterializeTemporaryExpr *MTE = cast(E); + auto *MTE = cast(E); assert(MTE->getStorageDuration() == SD_Static); SmallVector CommaLHSs; SmallVector Adjustments; @@ -1175,7 +1172,7 @@ if (!Init || isa(Init)) ; // Do nothing. - else if (InitListExpr *ChildILE = dyn_cast(Init)) + else if (auto *ChildILE = dyn_cast(Init)) EltInit = Emitter->EmitDesignatedInitUpdater(EltInit, ChildILE); else EltInit = CGM.EmitConstantExpr(Init, Field->getType(), CGF); @@ -1187,7 +1184,7 @@ if (!Field->isBitField()) AppendField(Field, Layout.getFieldOffset(FieldNo), EltInit); - else if (llvm::ConstantInt *CI = dyn_cast(EltInit)) + else if (auto *CI = dyn_cast(EltInit)) AppendBitField(Field, Layout.getFieldOffset(FieldNo), CI); else // Initializing a bitfield with a non-trivial constant? @@ -1207,8 +1204,7 @@ if (Ty->isArrayType()) Ty = Context.getBaseElementType(Ty); if (Ty->isRecordType()) - if (const CXXConstructExpr *E = - dyn_cast_or_null(D.getInit())) { + if (const auto *E = dyn_cast_or_null(D.getInit())) { const CXXConstructorDecl *CD = E->getConstructor(); if (CD->isTrivial() && CD->isDefaultConstructor()) return EmitNullConstant(D.getType()); @@ -1504,7 +1500,7 @@ const ValueDecl *decl = cast(uo->getSubExpr())->getDecl(); // A member function pointer. - if (const CXXMethodDecl *method = dyn_cast(decl)) + if (const auto *method = dyn_cast(decl)) return getCXXABI().EmitMemberFunctionPointer(method); // Otherwise, a member data pointer. @@ -1625,8 +1621,7 @@ return llvm::Constant::getNullValue(getTypes().ConvertTypeForMem(T)); if (const ConstantArrayType *CAT = Context.getAsConstantArrayType(T)) { - llvm::ArrayType *ATy = - cast(getTypes().ConvertTypeForMem(T)); + auto *ATy = cast(getTypes().ConvertTypeForMem(T)); QualType ElementTy = CAT->getElementType(); Index: lib/CodeGen/CGExprScalar.cpp =================================================================== --- lib/CodeGen/CGExprScalar.cpp +++ lib/CodeGen/CGExprScalar.cpp @@ -122,7 +122,7 @@ return; Value *AlignmentValue = CGF.EmitScalarExpr(AVAttr->getAlignment()); - llvm::ConstantInt *AlignmentCI = cast(AlignmentValue); + auto *AlignmentCI = cast(AlignmentValue); CGF.EmitAlignmentAssumption(V, AlignmentCI->getZExtValue()); } @@ -182,7 +182,7 @@ // Because of the type rules of C, we often end up computing a // logical value, then zero extending it to int, then wanting it // as a logical value again. Optimize this common case. - if (llvm::ZExtInst *ZI = dyn_cast(V)) { + if (auto *ZI = dyn_cast(V)) { if (ZI->getOperand(0)->getType() == Builder.getInt1Ty()) { Value *Result = ZI->getOperand(0); // If there aren't any more uses, zap the instruction to save space. @@ -588,7 +588,7 @@ if (SrcType->isRealFloatingType()) return EmitFloatToBoolConversion(Src); - if (const MemberPointerType *MPT = dyn_cast(SrcType)) + if (const auto *MPT = dyn_cast(SrcType)) return CGF.CGM.getCXXABI().EmitMemberPointerIsNotNull(CGF, Src, MPT); assert((SrcType->isIntegerType() || isa(Src->getType())) && @@ -611,7 +611,7 @@ llvm::Type *SrcTy = Src->getType(); llvm::Value *Check = nullptr; - if (llvm::IntegerType *IntTy = dyn_cast(SrcTy)) { + if (auto *IntTy = dyn_cast(SrcTy)) { // Integer to floating-point. This can fail for unsigned short -> __half // or unsigned __int128 -> float. assert(DstType->isFloatingType()); @@ -943,7 +943,7 @@ Opcode = BinaryOperator::getOpForCompoundAssignment(Opcode); StaticData.push_back(CGF.EmitCheckSourceLocation(Info.E->getExprLoc())); - const UnaryOperator *UO = dyn_cast(Info.E); + const auto *UO = dyn_cast(Info.E); if (UO && UO->getOpcode() == UO_Minus) { Check = SanitizerHandler::NegateOverflow; StaticData.push_back(CGF.EmitCheckTypeDescriptor(UO->getType())); @@ -952,7 +952,7 @@ if (BinaryOperator::isShiftOp(Opcode)) { // Shift LHS negative or too large, or RHS out of bounds. Check = SanitizerHandler::ShiftOutOfBounds; - const BinaryOperator *BO = cast(Info.E); + const auto *BO = cast(Info.E); StaticData.push_back( CGF.EmitCheckTypeDescriptor(BO->getLHS()->getType())); StaticData.push_back( @@ -996,12 +996,12 @@ Value *RHS = CGF.EmitScalarExpr(E->getExpr(1)); Value *Mask; - llvm::VectorType *LTy = cast(LHS->getType()); + auto *LTy = cast(LHS->getType()); unsigned LHSElts = LTy->getNumElements(); Mask = RHS; - llvm::VectorType *MTy = cast(Mask->getType()); + auto *MTy = cast(Mask->getType()); // Mask off the high bits of each shuffle index. Value *MaskBits = @@ -1180,8 +1180,7 @@ if (E->hadArrayRangeDesignator()) CGF.ErrorUnsupported(E, "GNU array range designator extension"); - llvm::VectorType *VType = - dyn_cast(ConvertType(E->getType())); + auto *VType = dyn_cast(ConvertType(E->getType())); if (!VType) { if (NumInitElements == 0) { @@ -1207,17 +1206,17 @@ Value *Init = Visit(IE); SmallVector Args; - llvm::VectorType *VVT = dyn_cast(Init->getType()); + auto *VVT = dyn_cast(Init->getType()); // Handle scalar elements. If the scalar initializer is actually one // element of a different vector of the same width, use shuffle instead of // extract+insert. if (!VVT) { if (isa(IE)) { - llvm::ExtractElementInst *EI = cast(Init); + auto *EI = cast(Init); if (EI->getVectorOperandType()->getNumElements() == ResElts) { - llvm::ConstantInt *C = cast(EI->getIndexOperand()); + auto *C = cast(EI->getIndexOperand()); Value *LHS = nullptr, *RHS = nullptr; if (CurIdx == 0) { // insert into undef -> shuffle (src, undef) @@ -1230,7 +1229,7 @@ VIsUndefShuffle = true; } else if (VIsUndefShuffle) { // insert into undefshuffle && size match -> shuffle (v, src) - llvm::ShuffleVectorInst *SVV = cast(V); + auto *SVV = cast(V); for (unsigned j = 0; j != CurIdx; ++j) Args.push_back(getMaskElt(SVV, j, 0, CGF.Int32Ty)); Args.push_back(Builder.getInt32(ResElts + C->getZExtValue())); @@ -1262,9 +1261,9 @@ // optimized shuffle of the swizzle input into the result. unsigned Offset = (CurIdx == 0) ? 0 : ResElts; if (isa(IE)) { - llvm::ShuffleVectorInst *SVI = cast(Init); + auto *SVI = cast(Init); Value *SVOp = SVI->getOperand(0); - llvm::VectorType *OpTy = cast(SVOp->getType()); + auto *OpTy = cast(SVOp->getType()); if (OpTy->getNumElements() == ResElts) { for (unsigned j = 0; j != CurIdx; ++j) { @@ -1340,7 +1339,7 @@ return false; } - if (const ImplicitCastExpr *ICE = dyn_cast(CE)) { + if (const auto *ICE = dyn_cast(CE)) { // And that glvalue casts are never null. if (ICE->getValueKind() != VK_RValue) return false; @@ -1479,7 +1478,7 @@ if (MustVisitNullValue(E)) (void) Visit(E); - const MemberPointerType *MPT = CE->getType()->getAs(); + const auto *MPT = CE->getType()->getAs(); return CGF.CGM.getCXXABI().EmitNullMemberPointer(MPT); } @@ -1571,7 +1570,7 @@ return EmitFloatToBoolConversion(Visit(E)); case CK_MemberPointerToBoolean: { llvm::Value *MemPtr = Visit(E); - const MemberPointerType *MPT = E->getType()->getAs(); + const auto *MPT = E->getType()->getAs(); return CGF.CGM.getCXXABI().EmitMemberPointerIsNotNull(CGF, MemPtr, MPT); } @@ -1656,7 +1655,7 @@ int amount = (isInc ? 1 : -1); - if (const AtomicType *atomicTy = type->getAs()) { + if (const auto *atomicTy = type->getAs()) { type = atomicTy->getValueType(); if (isInc && type->isBooleanType()) { llvm::Value *True = CGF.EmitToMemory(Builder.getTrue(), type); @@ -1733,7 +1732,7 @@ } // Next most common: pointer increment. - } else if (const PointerType *ptr = type->getAs()) { + } else if (const auto *ptr = type->getAs()) { QualType type = ptr->getPointeeType(); // VLA types don't have constant size. @@ -1833,7 +1832,7 @@ // Objective-C pointer types. } else { - const ObjCObjectPointerType *OPT = type->castAs(); + const auto *OPT = type->castAs(); value = CGF.EmitCastToVoidPtr(value); CharUnits size = CGF.getContext().getTypeSizeInChars(OPT->getObjectType()); @@ -2000,7 +1999,7 @@ // Compute the offset to the base. const RecordType *BaseRT = CurrentType->getAs(); - CXXRecordDecl *BaseRD = cast(BaseRT->getDecl()); + auto *BaseRD = cast(BaseRT->getDecl()); CharUnits OffsetInt = RL.getBaseClassOffset(BaseRD); Offset = llvm::ConstantInt::get(ResultType, OffsetInt.getQuantity()); break; @@ -2133,7 +2132,7 @@ LValue LHSLV = EmitCheckedLValue(E->getLHS(), CodeGenFunction::TCK_Store); llvm::PHINode *atomicPHI = nullptr; - if (const AtomicType *atomicTy = LHSTy->getAs()) { + if (const auto *atomicTy = LHSTy->getAs()) { QualType type = atomicTy->getValueType(); if (!type->isBooleanType() && type->isIntegerType() && !(type->isUnsignedIntegerType() && @@ -2260,7 +2259,7 @@ if (CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow) && Ops.Ty->hasSignedIntegerRepresentation()) { - llvm::IntegerType *Ty = cast(Zero->getType()); + auto *Ty = cast(Zero->getType()); llvm::Value *IntMin = Builder.getInt(llvm::APInt::getSignedMinValue(Ty->getBitWidth())); @@ -2442,7 +2441,7 @@ bool isSubtraction) { // Must have binary (not unary) expr here. Unary pointer // increment/decrement doesn't use this path. - const BinaryOperator *expr = cast(op.E); + const auto *expr = cast(op.E); Value *pointer = op.LHS; Expr *pointerOperand = expr->getLHS(); @@ -2474,8 +2473,7 @@ CGF.EmitBoundsCheck(op.E, pointerOperand, index, indexOperand->getType(), /*Accessed*/ false); - const PointerType *pointerType - = pointerOperand->getType()->getAs(); + const auto *pointerType = pointerOperand->getType()->getAs(); if (!pointerType) { QualType objectType = pointerOperand->getType() ->castAs() @@ -2675,7 +2673,7 @@ Value *diffInChars = Builder.CreateSub(LHS, RHS, "sub.ptr.sub"); // Okay, figure out the element size. - const BinaryOperator *expr = cast(op.E); + const auto *expr = cast(op.E); QualType elementType = expr->getLHS()->getType()->getPointeeType(); llvm::Value *divisor = nullptr; @@ -2720,7 +2718,7 @@ Value *ScalarExprEmitter::GetWidthMinusOneValue(Value* LHS,Value* RHS) { llvm::IntegerType *Ty; - if (llvm::VectorType *VT = dyn_cast(LHS->getType())) + if (auto *VT = dyn_cast(LHS->getType())) Ty = cast(VT->getElementType()); else Ty = cast(LHS->getType()); @@ -2858,7 +2856,7 @@ Value *Result; QualType LHSTy = E->getLHS()->getType(); QualType RHSTy = E->getRHS()->getType(); - if (const MemberPointerType *MPT = LHSTy->getAs()) { + if (const auto *MPT = LHSTy->getAs()) { assert(E->getOpcode() == BO_EQ || E->getOpcode() == BO_NE); Value *LHS = CGF.EmitScalarExpr(E->getLHS()); @@ -3284,7 +3282,7 @@ llvm::Value *RHS = Visit(rhsExpr); llvm::Type *condType = ConvertType(condExpr->getType()); - llvm::VectorType *vecTy = cast(condType); + auto *vecTy = cast(condType); unsigned numElem = vecTy->getNumElements(); llvm::Type *elemType = vecTy->getElementType(); @@ -3301,7 +3299,7 @@ llvm::Value *RHSTmp = RHS; llvm::Value *LHSTmp = LHS; bool wasCast = false; - llvm::VectorType *rhsVTy = cast(RHS->getType()); + auto *rhsVTy = cast(RHS->getType()); if (rhsVTy->getElementType()->isFloatingPointTy()) { RHSTmp = Builder.CreateBitCast(RHS, tmp2->getType()); LHSTmp = Builder.CreateBitCast(LHS, tmp->getType()); Index: lib/CodeGen/CGLoopInfo.cpp =================================================================== --- lib/CodeGen/CGLoopInfo.cpp +++ lib/CodeGen/CGLoopInfo.cpp @@ -141,9 +141,8 @@ // Identify loop hint attributes from Attrs. for (const auto *Attr : Attrs) { - const LoopHintAttr *LH = dyn_cast(Attr); - const OpenCLUnrollHintAttr *OpenCLHint = - dyn_cast(Attr); + const auto *LH = dyn_cast(Attr); + const auto *OpenCLHint = dyn_cast(Attr); // Skip non loop hint attributes if (!LH && !OpenCLHint) { @@ -291,7 +290,7 @@ if (!L.getLoopID()) return; - if (TerminatorInst *TI = dyn_cast(I)) { + if (auto *TI = dyn_cast(I)) { for (unsigned i = 0, ie = TI->getNumSuccessors(); i < ie; ++i) if (TI->getSuccessor(i) == L.getHeader()) { TI->setMetadata(llvm::LLVMContext::MD_loop, L.getLoopID()); Index: lib/CodeGen/CGObjC.cpp =================================================================== --- lib/CodeGen/CGObjC.cpp +++ lib/CodeGen/CGObjC.cpp @@ -114,7 +114,7 @@ const ObjCMethodDecl *MethodWithObjects) { ASTContext &Context = CGM.getContext(); const ObjCDictionaryLiteral *DLE = nullptr; - const ObjCArrayLiteral *ALE = dyn_cast(E); + const auto *ALE = dyn_cast(E); if (!ALE) DLE = cast(E); @@ -280,7 +280,7 @@ receiver = opaque->getSourceExpr()->IgnoreParens(); } - const ImplicitCastExpr *ice = dyn_cast(receiver); + const auto *ice = dyn_cast(receiver); if (!ice || ice->getCastKind() != CK_LValueToRValue) return true; receiver = ice->getSubExpr()->IgnoreParens(); @@ -299,9 +299,9 @@ return false; // Otherwise, check for variables. - const DeclRefExpr *declRef = dyn_cast(ice->getSubExpr()); + const auto *declRef = dyn_cast(ice->getSubExpr()); if (!declRef) return true; - const VarDecl *var = dyn_cast(declRef->getDecl()); + const auto *var = dyn_cast(declRef->getDecl()); if (!var) return true; // All variables have precise lifetime except local variables with @@ -390,7 +390,7 @@ case ObjCMessageExpr::Class: { ReceiverType = E->getClassReceiver(); - const ObjCObjectType *ObjTy = ReceiverType->getAs(); + const auto *ObjTy = ReceiverType->getAs(); assert(ObjTy && "Invalid Objective-C class message send"); OID = ObjTy->getInterface(); assert(OID && "Invalid Objective-C class message send"); @@ -449,7 +449,7 @@ RValue result; if (isSuperMessage) { // super is only valid in an Objective-C method - const ObjCMethodDecl *OMD = cast(CurFuncDecl); + const auto *OMD = cast(CurFuncDecl); bool isCategoryImpl = isa(OMD->getDeclContext()); result = Runtime.GenerateMessageSendSuper(*this, Return, ResultType, E->getSelector(), @@ -487,9 +487,9 @@ namespace { struct FinishARCDealloc final : EHScopeStack::Cleanup { void Emit(CodeGenFunction &CGF, Flags flags) override { - const ObjCMethodDecl *method = cast(CGF.CurCodeDecl); + const auto *method = cast(CGF.CurCodeDecl); - const ObjCImplDecl *impl = cast(method->getDeclContext()); + const auto *impl = cast(method->getDeclContext()); const ObjCInterfaceDecl *iface = impl->getClassInterface(); if (!iface->getSuperClass()) return; @@ -821,7 +821,7 @@ return false; // If we selected a trivial copy-constructor, we're okay. - if (const CXXConstructExpr *construct = dyn_cast(getter)) + if (const auto *construct = dyn_cast(getter)) return (construct->getConstructor()->isTrivial()); // The constructor might require cleanups (in which case it's never @@ -959,7 +959,7 @@ RValue RV = EmitCall( getTypes().arrangeBuiltinFunctionCall(propType, args), callee, ReturnValueSlot(), args, &CallInstruction); - if (llvm::CallInst *call = dyn_cast(CallInstruction)) + if (auto *call = dyn_cast(CallInstruction)) call->setTailCall(); // We need to fix the type here. Ivars with copy & retain are @@ -1127,7 +1127,7 @@ // the arguments, because operator= can only be trivial if it's a // synthesized assignment operator and therefore both parameters are // references. - if (CallExpr *call = dyn_cast(setter)) { + if (auto *call = dyn_cast(setter)) { if (const FunctionDecl *callee = dyn_cast_or_null(call->getCalleeDecl())) if (callee->isTrivial()) @@ -1418,7 +1418,7 @@ for (const auto *IvarInit : IMP->inits()) { FieldDecl *Field = IvarInit->getAnyMember(); - ObjCIvarDecl *Ivar = cast(Field); + auto *Ivar = cast(Field); LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), Ivar, 0); EmitAggExpr(IvarInit->getInit(), @@ -1448,7 +1448,7 @@ } QualType CodeGenFunction::TypeOfSelfObject() { - const ObjCMethodDecl *OMD = cast(CurFuncDecl); + const auto *OMD = cast(CurFuncDecl); ImplicitParamDecl *selfDecl = OMD->getSelfDecl(); const ObjCObjectPointerType *PTy = cast( getContext().getCanonicalType(selfDecl->getType())); @@ -1471,7 +1471,7 @@ // The local variable comes into scope immediately. AutoVarEmission variable = AutoVarEmission::invalid(); - if (const DeclStmt *SD = dyn_cast(S.getElement())) + if (const auto *SD = dyn_cast(S.getElement())) variable = EmitAutoVarAlloca(*cast(SD->getSingleDecl())); JumpDest LoopEnd = getJumpDestInCurrentScope("forcoll.end"); @@ -1625,11 +1625,11 @@ bool elementIsVariable; LValue elementLValue; QualType elementType; - if (const DeclStmt *SD = dyn_cast(S.getElement())) { + if (const auto *SD = dyn_cast(S.getElement())) { // Initialize the variable, in case it's a __block variable or something. EmitAutoVarInit(variable); - const VarDecl* D = cast(SD->getSingleDecl()); + const auto *D = cast(SD->getSingleDecl()); DeclRefExpr tempDRE(const_cast(D), false, D->getType(), VK_LValue, SourceLocation()); elementLValue = EmitLValue(&tempDRE); @@ -1807,7 +1807,7 @@ StringRef fnName) { llvm::Constant *fn = CGM.CreateRuntimeFunction(type, fnName); - if (llvm::Function *f = dyn_cast(fn)) { + if (auto *f = dyn_cast(fn)) { // If the target runtime doesn't naturally support ARC, emit weak // references to the runtime support library. We don't really // permit this to fail, but we need a particular relocation style. @@ -1969,8 +1969,7 @@ // block doesn't escape, where being passed as an argument doesn't // count as escaping. if (!mandatory && isa(result)) { - llvm::CallInst *call - = cast(result->stripPointerCasts()); + auto *call = cast(result->stripPointerCasts()); assert(call->getCalledValue() == CGM.getObjCEntrypoints().objc_retainBlock); call->setMetadata("clang.arc.copy_on_escape", @@ -2474,7 +2473,7 @@ llvm::Value *value, ValueTransform doAfterCall, ValueTransform doFallback) { - if (llvm::CallInst *call = dyn_cast(value)) { + if (auto *call = dyn_cast(value)) { CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP(); // Place the retain immediately following the call. @@ -2484,7 +2483,7 @@ CGF.Builder.restoreIP(ip); return value; - } else if (llvm::InvokeInst *invoke = dyn_cast(value)) { + } else if (auto *invoke = dyn_cast(value)) { CGBuilderTy::InsertPoint ip = CGF.Builder.saveIP(); // Place the retain at the beginning of the normal destination block. @@ -2497,7 +2496,7 @@ // Bitcasts can arise because of related-result returns. Rewrite // the operand. - } else if (llvm::BitCastInst *bitcast = dyn_cast(value)) { + } else if (auto *bitcast = dyn_cast(value)) { llvm::Value *operand = bitcast->getOperand(0); operand = emitARCOperationAfterCall(CGF, operand, doAfterCall, doFallback); bitcast->setOperand(0, operand); @@ -2562,7 +2561,7 @@ if (isa(e)) return false; - if (const CastExpr *cast = dyn_cast(e)) { + if (const auto *cast = dyn_cast(e)) { switch (cast->getCastKind()) { // Emitting these operations in +1 contexts is goodness. case CK_LValueToRValue: @@ -2639,7 +2638,7 @@ // If this semantic expression is an opaque value, bind it // to the result of its source expression. - if (const OpaqueValueExpr *ov = dyn_cast(semantic)) { + if (const auto *ov = dyn_cast(semantic)) { typedef CodeGenFunction::OpaqueValueMappingData OVMA; OVMA opaqueData; @@ -2797,7 +2796,7 @@ e = e->IgnoreParens(); // Handle certain kinds of casts. - if (const CastExpr *ce = dyn_cast(e)) { + if (const auto *ce = dyn_cast(e)) { return asImpl().visitCastExpr(ce); // Handle the comma operator. @@ -2816,7 +2815,7 @@ return asImpl().visitCall(e); // Look through pseudo-object expressions. - } else if (const PseudoObjectExpr *pseudo = dyn_cast(e)) { + } else if (const auto *pseudo = dyn_cast(e)) { return asImpl().visitPseudoObjectExpr(pseudo); } @@ -2927,7 +2926,7 @@ /// retained objects. llvm::Value *CodeGenFunction::EmitARCRetainScalarExpr(const Expr *e) { // The retain needs to happen within the full-expression. - if (const ExprWithCleanups *cleanups = dyn_cast(e)) { + if (const auto *cleanups = dyn_cast(e)) { enterFullExpression(cleanups); RunCleanupsScope scope(*this); return EmitARCRetainScalarExpr(cleanups->getSubExpr()); @@ -2943,7 +2942,7 @@ llvm::Value * CodeGenFunction::EmitARCRetainAutoreleaseScalarExpr(const Expr *e) { // The retain needs to happen within the full-expression. - if (const ExprWithCleanups *cleanups = dyn_cast(e)) { + if (const auto *cleanups = dyn_cast(e)) { enterFullExpression(cleanups); RunCleanupsScope scope(*this); return EmitARCRetainAutoreleaseScalarExpr(cleanups->getSubExpr()); @@ -3054,7 +3053,7 @@ /// with objc_unsafeClaimAutoreleasedReturnValue. llvm::Value *CodeGenFunction::EmitARCUnsafeUnretainedScalarExpr(const Expr *e) { // Look through full-expressions. - if (const ExprWithCleanups *cleanups = dyn_cast(e)) { + if (const auto *cleanups = dyn_cast(e)) { enterFullExpression(cleanups); RunCleanupsScope scope(*this); return emitARCUnsafeUnretainedScalarExpr(*this, cleanups->getSubExpr()); @@ -3126,7 +3125,7 @@ void CodeGenFunction::EmitObjCAutoreleasePoolStmt( const ObjCAutoreleasePoolStmt &ARPS) { const Stmt *subStmt = ARPS.getSubStmt(); - const CompoundStmt &S = cast(*subStmt); + const auto &S = cast(*subStmt); CGDebugInfo *DI = getDebugInfo(); if (DI) @@ -3235,7 +3234,7 @@ VK_LValue, OK_Ordinary, SourceLocation()); Expr *Args[2] = { &DST, &SRC }; - CallExpr *CalleeExp = cast(PID->getSetterCXXAssignment()); + auto *CalleeExp = cast(PID->getSetterCXXAssignment()); CXXOperatorCallExpr TheCall(C, OO_Equal, CalleeExp->getCallee(), Args, DestTy->getPointeeType(), VK_LValue, SourceLocation(), false); @@ -3309,10 +3308,9 @@ UnaryOperator SRC(&SrcExpr, UO_Deref, SrcTy->getPointeeType(), VK_LValue, OK_Ordinary, SourceLocation()); - - CXXConstructExpr *CXXConstExpr = - cast(PID->getGetterCXXConstructor()); - + + auto *CXXConstExpr = cast(PID->getGetterCXXConstructor()); + SmallVector ConstructorArgs; ConstructorArgs.push_back(&SRC); ConstructorArgs.append(std::next(CXXConstExpr->arg_begin()), Index: lib/CodeGen/CGObjCGNU.cpp =================================================================== --- lib/CodeGen/CGObjCGNU.cpp +++ lib/CodeGen/CGObjCGNU.cpp @@ -1135,7 +1135,7 @@ } // All other types should be Objective-C interface pointer types. - const ObjCObjectPointerType *OPT = T->getAs(); + const auto *OPT = T->getAs(); assert(OPT && "Invalid @catch type."); const ObjCInterfaceDecl *IDecl = OPT->getObjectType()->getInterface(); assert(IDecl && "Invalid @catch type."); @@ -1163,8 +1163,7 @@ return llvm::ConstantExpr::getBitCast(IDEHType, PtrToInt8Ty); } - const ObjCObjectPointerType *PT = - T->getAs(); + const auto *PT = T->getAs(); assert(PT && "Invalid @catch type."); const ObjCInterfaceType *IT = PT->getInterfaceType(); assert(IT && "Invalid @catch type."); @@ -2144,8 +2143,7 @@ void CGObjCGNU::RegisterAlias(const ObjCCompatibleAliasDecl *OAD) { // Get the class declaration for which the alias is specified. - ObjCInterfaceDecl *ClassDecl = - const_cast(OAD->getClassInterface()); + auto *ClassDecl = const_cast(OAD->getClassInterface()); ClassAliases.emplace_back(ClassDecl->getNameAsString(), OAD->getNameAsString()); } @@ -2163,8 +2161,7 @@ } // Get the class name - ObjCInterfaceDecl *ClassDecl = - const_cast(OID->getClassInterface()); + auto *ClassDecl = const_cast(OID->getClassInterface()); std::string ClassName = ClassDecl->getNameAsString(); // Emit the symbol that is used to generate linker errors if this class is @@ -2396,8 +2393,7 @@ // Add all referenced protocols to a category. GenerateProtocolHolderCategory(); - llvm::StructType *selStructTy = - dyn_cast(SelectorTy->getElementType()); + auto *selStructTy = dyn_cast(SelectorTy->getElementType()); llvm::Type *selStructPtrTy = SelectorTy; if (!selStructTy) { selStructTy = llvm::StructType::get(CGM.getLLVMContext(), @@ -2609,15 +2605,14 @@ // The true branch (has alias registration function): Builder.SetInsertPoint(AliasBB); // Emit alias registration calls: - for (std::vector::iterator iter = ClassAliases.begin(); - iter != ClassAliases.end(); ++iter) { - llvm::Constant *TheClass = + for (auto iter = ClassAliases.begin(); iter != ClassAliases.end(); ++iter) { + llvm::Constant *TheClass = TheModule.getGlobalVariable("_OBJC_CLASS_" + iter->first, true); - if (TheClass) { - TheClass = llvm::ConstantExpr::getBitCast(TheClass, PtrTy); - Builder.CreateCall(RegisterAlias, - {TheClass, MakeConstantString(iter->second)}); - } + if (TheClass) { + TheClass = llvm::ConstantExpr::getBitCast(TheClass, PtrTy); + Builder.CreateCall(RegisterAlias, + {TheClass, MakeConstantString(iter->second)}); + } } // Jump to end: Builder.CreateBr(NoAliasBB); @@ -2632,8 +2627,7 @@ llvm::Function *CGObjCGNU::GenerateMethod(const ObjCMethodDecl *OMD, const ObjCContainerDecl *CD) { - const ObjCCategoryImplDecl *OCD = - dyn_cast(OMD->getDeclContext()); + const auto *OCD = dyn_cast(OMD->getDeclContext()); StringRef CategoryName = OCD ? OCD->getName() : ""; StringRef ClassName = CD->getName(); Selector MethodName = OMD->getSelector(); Index: lib/CodeGen/CGObjCMac.cpp =================================================================== --- lib/CodeGen/CGObjCMac.cpp +++ lib/CodeGen/CGObjCMac.cpp @@ -1538,8 +1538,7 @@ // base of the ivar access is a parameter to an Objective C method. // However, because the parameters are not available in the current // interface, we cannot perform this check. - if (const ObjCMethodDecl *MD = - dyn_cast_or_null(CGF.CurFuncDecl)) + if (const auto *MD = dyn_cast_or_null(CGF.CurFuncDecl)) if (MD->isInstanceMethod()) if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) return IV->getContainingInterface()->isSuperClassOf(ID); @@ -2200,7 +2199,7 @@ // Walk into C pointer types, but only in GC. if (Ctx.getLangOpts().getGC() != LangOptions::NonGC) { - if (const PointerType *PT = FQT->getAs()) + if (const auto *PT = FQT->getAs()) return GetGCAttrTypeForType(Ctx, PT->getPointeeType(), /*pointee*/ true); } @@ -2439,14 +2438,12 @@ } if (const ArrayType *Array = CGM.getContext().getAsArrayType(FQT)) { - const ConstantArrayType *CArray = - dyn_cast_or_null(Array); + const auto *CArray = dyn_cast_or_null(Array); uint64_t ElCount = CArray->getSize().getZExtValue(); assert(CArray && "only array with known element size is supported"); FQT = CArray->getElementType(); while (const ArrayType *Array = CGM.getContext().getAsArrayType(FQT)) { - const ConstantArrayType *CArray = - dyn_cast_or_null(Array); + const auto *CArray = dyn_cast_or_null(Array); ElCount *= CArray->getSize().getZExtValue(); FQT = CArray->getElementType(); } @@ -2704,7 +2701,7 @@ while (!Layout.empty()) { unsigned char inst = Layout.back(); - enum BLOCK_LAYOUT_OPCODE opcode = (enum BLOCK_LAYOUT_OPCODE) (inst >> 4); + auto opcode = (enum BLOCK_LAYOUT_OPCODE)(inst >> 4); if (opcode == BLOCK_LAYOUT_NON_OBJECT_BYTES || opcode == BLOCK_LAYOUT_NON_OBJECT_WORDS) Layout.pop_back(); else @@ -2744,7 +2741,7 @@ printf("\n Block variable layout: "); for (unsigned i = 0, e = BitMap.size(); i != e; i++) { unsigned char inst = BitMap[i]; - enum BLOCK_LAYOUT_OPCODE opcode = (enum BLOCK_LAYOUT_OPCODE) (inst >> 4); + auto opcode = (enum BLOCK_LAYOUT_OPCODE)(inst >> 4); unsigned delta = 1; switch (opcode) { case BLOCK_LAYOUT_OPERATOR: @@ -3131,7 +3128,7 @@ SmallVector Properties; llvm::SmallPtrSet PropertySet; - if (const ObjCInterfaceDecl *OID = dyn_cast(OCD)) + if (const auto *OID = dyn_cast(OCD)) for (const ObjCCategoryDecl *ClassExt : OID->known_extensions()) for (auto *PD : ClassExt->properties()) { if (IsClassProperty != PD->isClassProperty()) @@ -3150,11 +3147,10 @@ Properties.push_back(PD); } - if (const ObjCInterfaceDecl *OID = dyn_cast(OCD)) { + if (const auto *OID = dyn_cast(OCD)) { for (const auto *P : OID->all_referenced_protocols()) PushProtocolProperties(PropertySet, Properties, P, IsClassProperty); - } - else if (const ObjCCategoryDecl *CD = dyn_cast(OCD)) { + } else if (const auto *CD = dyn_cast(OCD)) { for (const auto *P : CD->protocols()) PushProtocolProperties(PropertySet, Properties, P, IsClassProperty); } @@ -3396,8 +3392,7 @@ std::string ClassName = ID->getNameAsString(); // FIXME: Gross - ObjCInterfaceDecl *Interface = - const_cast(ID->getClassInterface()); + auto *Interface = const_cast(ID->getClassInterface()); llvm::Constant *Protocols = EmitProtocolList("OBJC_CLASS_PROTOCOLS_" + ID->getName(), Interface->all_referenced_protocol_begin(), @@ -3880,9 +3875,9 @@ CharUnits Align, bool AddToUsed) { llvm::Type *Ty = Init->getType(); - llvm::GlobalVariable *GV = - new llvm::GlobalVariable(CGM.getModule(), Ty, false, - llvm::GlobalValue::PrivateLinkage, Init, Name); + auto *GV = + new llvm::GlobalVariable(CGM.getModule(), Ty, false, + llvm::GlobalValue::PrivateLinkage, Init, Name); if (!Section.empty()) GV->setSection(Section); GV->setAlignment(Align.getQuantity()); @@ -4435,7 +4430,7 @@ // benefit of any @throws in the handlers. CGF.ObjCEHValueStack.push_back(Caught); - const ObjCAtTryStmt* AtTryStmt = cast(&S); + const auto *AtTryStmt = cast(&S); bool HasFinally = (AtTryStmt->getFinallyStmt() != nullptr); @@ -5389,8 +5384,7 @@ assert (CD && "Missing container decl in GetNameForMethod"); OS << '\01' << (D->isInstanceMethod() ? '-' : '+') << '[' << CD->getName(); - if (const ObjCCategoryImplDecl *CID = - dyn_cast(D->getDeclContext())) + if (const auto *CID = dyn_cast(D->getDeclContext())) OS << '(' << *CID << ')'; OS << ' ' << D->getSelector().getAsString() << ']'; } @@ -6187,8 +6181,8 @@ values.add(ObjCEmptyVtableVar); values.add(ClassRoGV); - llvm::GlobalVariable *GV = - cast(GetClassGlobal(CI, isMetaclass, ForDefinition)); + auto *GV = cast( + GetClassGlobal(CI, isMetaclass, ForDefinition)); values.finishAndSetAsInitializer(GV); if (CGM.getTriple().isOSBinFormatMachO()) @@ -7468,7 +7462,7 @@ } // All other types should be Objective-C interface pointer types. - const ObjCObjectPointerType *PT = T->getAs(); + const auto *PT = T->getAs(); assert(PT && "Invalid @catch type."); const ObjCInterfaceType *IT = PT->getInterfaceType(); Index: lib/CodeGen/CGOpenCLRuntime.cpp =================================================================== --- lib/CodeGen/CGOpenCLRuntime.cpp +++ lib/CodeGen/CGOpenCLRuntime.cpp @@ -88,7 +88,7 @@ } llvm::Value *CGOpenCLRuntime::getPipeElemSize(const Expr *PipeArg) { - const PipeType *PipeTy = PipeArg->getType()->getAs(); + const auto *PipeTy = PipeArg->getType()->getAs(); // The type of the last (implicit) argument to be passed. llvm::Type *Int32Ty = llvm::IntegerType::getInt32Ty(CGM.getLLVMContext()); unsigned TypeSize = CGM.getContext() @@ -98,7 +98,7 @@ } llvm::Value *CGOpenCLRuntime::getPipeElemAlign(const Expr *PipeArg) { - const PipeType *PipeTy = PipeArg->getType()->getAs(); + const auto *PipeTy = PipeArg->getType()->getAs(); // The type of the last (implicit) argument to be passed. llvm::Type *Int32Ty = llvm::IntegerType::getInt32Ty(CGM.getLLVMContext()); unsigned TypeSize = CGM.getContext() Index: lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- lib/CodeGen/CGOpenMPRuntime.cpp +++ lib/CodeGen/CGOpenMPRuntime.cpp @@ -967,8 +967,7 @@ // Build debug location PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc); OS2 << ";" << PLoc.getFilename() << ";"; - if (const FunctionDecl *FD = - dyn_cast_or_null(CGF.CurFuncDecl)) { + if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl)) { OS2 << FD->getQualifiedNameAsString(); } OS2 << ";" << PLoc.getLine() << ";" << PLoc.getColumn() << ";;"; @@ -3029,7 +3028,7 @@ return; for (auto I : MD->operands()) { - llvm::MDNode *MN = cast(I); + auto *MN = cast(I); auto getMDInt = [&](unsigned Idx) { llvm::ConstantAsMetadata *V = @@ -5676,7 +5675,7 @@ if (CI.capturesThis()) { CurBasePointers.push_back(CV); CurPointers.push_back(CV); - const PointerType *PtrTy = cast(RI.getType().getTypePtr()); + const auto *PtrTy = cast(RI.getType().getTypePtr()); CurSizes.push_back(CGF.getTypeSize(PtrTy->getPointeeType())); // Default map type. CurMapTypes.push_back(OMP_MAP_TO | OMP_MAP_FROM); @@ -5699,8 +5698,7 @@ CurBasePointers.push_back(CV); CurPointers.push_back(CV); - const ReferenceType *PtrTy = - cast(RI.getType().getTypePtr()); + const auto *PtrTy = cast(RI.getType().getTypePtr()); QualType ElementType = PtrTy->getPointeeType(); CurSizes.push_back(CGF.getTypeSize(ElementType)); // The default map type for a scalar/complex type is 'to' because by @@ -6111,7 +6109,7 @@ return; } - if (const OMPExecutableDirective *E = dyn_cast(S)) { + if (const auto *E = dyn_cast(S)) { if (!E->hasAssociatedStmt()) return; Index: lib/CodeGen/CGRecordLayoutBuilder.cpp =================================================================== --- lib/CodeGen/CGRecordLayoutBuilder.cpp +++ lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -544,11 +544,10 @@ } void CGRecordLowering::clipTailPadding() { - std::vector::iterator Prior = Members.begin(); + auto Prior = Members.begin(); CharUnits Tail = getSize(Prior->Data); - for (std::vector::iterator Member = Prior + 1, - MemberEnd = Members.end(); - Member != MemberEnd; ++Member) { + for (auto Member = Prior + 1, MemberEnd = Members.end(); Member != MemberEnd; + ++Member) { // Only members with data and the scissor can cut into tail padding. if (!Member->Data && Member->Kind != MemberInfo::Scissor) continue; @@ -710,9 +709,8 @@ // but we may need to recursively layout D while laying D out as a base type. Ty->setBody(Builder.FieldTypes, Builder.Packed); - CGRecordLayout *RL = - new CGRecordLayout(Ty, BaseTy, Builder.IsZeroInitializable, - Builder.IsZeroInitializableAsBase); + auto *RL = new CGRecordLayout(Ty, BaseTy, Builder.IsZeroInitializable, + Builder.IsZeroInitializableAsBase); RL->NonVirtualBases.swap(Builder.NonVirtualBases); RL->CompleteObjectVirtualBases.swap(Builder.VirtualBases); @@ -752,8 +750,7 @@ } // Verify that the LLVM and AST field offsets agree. - llvm::StructType *ST = - dyn_cast(RL->getLLVMType()); + auto *ST = dyn_cast(RL->getLLVMType()); const llvm::StructLayout *SL = getDataLayout().getStructLayout(ST); const ASTRecordLayout &AST_RL = getContext().getASTRecordLayout(D); Index: lib/CodeGen/CGStmt.cpp =================================================================== --- lib/CodeGen/CGStmt.cpp +++ lib/CodeGen/CGStmt.cpp @@ -148,7 +148,7 @@ CGM.ErrorUnsupported(S, "coroutine"); break; case Stmt::CapturedStmtClass: { - const CapturedStmt *CS = cast(S); + const auto *CS = cast(S); EmitCapturedStmt(*CS, CS->getCapturedRegionKind()); } break; @@ -368,7 +368,7 @@ // subexpression. Handle this by walking through all labels we encounter, // emitting them before we evaluate the subexpr. const Stmt *LastStmt = S.body_back(); - while (const LabelStmt *LS = dyn_cast(LastStmt)) { + while (const auto *LS = dyn_cast(LastStmt)) { EmitLabel(LS->getDecl()); LastStmt = LS->getSubStmt(); } @@ -393,7 +393,7 @@ } void CodeGenFunction::SimplifyForwardingBlocks(llvm::BasicBlock *BB) { - llvm::BranchInst *BI = dyn_cast(BB->getTerminator()); + auto *BI = dyn_cast(BB->getTerminator()); // If there is a cleanup stack, then we it isn't worth trying to // simplify this block (we would need to remove it from the scope map @@ -454,7 +454,7 @@ void CodeGenFunction::EmitBlockAfterUses(llvm::BasicBlock *block) { bool inserted = false; for (llvm::User *u : block->users()) { - if (llvm::Instruction *insn = dyn_cast(u)) { + if (auto *insn = dyn_cast(u)) { CurFn->getBasicBlockList().insertAfter(insn->getParent()->getIterator(), block); inserted = true; @@ -703,7 +703,7 @@ // while(1) is common, avoid extra exit blocks. Be sure // to correctly handle break/continue though. bool EmitBoolCondBranch = true; - if (llvm::ConstantInt *C = dyn_cast(BoolCondVal)) + if (auto *C = dyn_cast(BoolCondVal)) if (C->isOne()) EmitBoolCondBranch = false; @@ -791,7 +791,7 @@ // "do {} while (0)" is common in macros, avoid extra blocks. Be sure // to correctly handle break/continue though. bool EmitBoolCondBranch = true; - if (llvm::ConstantInt *C = dyn_cast(BoolCondVal)) + if (auto *C = dyn_cast(BoolCondVal)) if (C->isZero()) EmitBoolCondBranch = false; @@ -1019,8 +1019,7 @@ // exception to our over-conservative rules about not jumping to // statements following block literals with non-trivial cleanups. RunCleanupsScope cleanupScope(*this); - if (const ExprWithCleanups *cleanups = - dyn_cast_or_null(RV)) { + if (const auto *cleanups = dyn_cast_or_null(RV)) { enterFullExpression(cleanups); RV = cleanups->getSubExpr(); } @@ -1251,7 +1250,7 @@ // deep recursion which can run into stack depth limitations. Handle // sequential non-range case statements specially. const CaseStmt *CurCase = &S; - const CaseStmt *NextCase = dyn_cast(S.getSubStmt()); + const auto *NextCase = dyn_cast(S.getSubStmt()); // Otherwise, iteratively add consecutive cases to this switch stmt. while (NextCase && NextCase->getRHS() == nullptr) { @@ -1326,7 +1325,7 @@ // If this is the switchcase (case 4: or default) that we're looking for, then // we're in business. Just add the substatement. - if (const SwitchCase *SC = dyn_cast(S)) { + if (const auto *SC = dyn_cast(S)) { if (S == Case) { FoundCase = true; return CollectStatementsForCase(SC->getSubStmt(), nullptr, FoundCase, @@ -1345,7 +1344,7 @@ // If this is a switch statement, then it might contain the SwitchCase, the // break, or neither. - if (const CompoundStmt *CS = dyn_cast(S)) { + if (const auto *CS = dyn_cast(S)) { // Handle this as two cases: we might be looking for the SwitchCase (if so // the skipped statements must be skippable) or we might already have it. CompoundStmt::const_body_iterator I = CS->body_begin(), E = CS->body_end(); @@ -1484,13 +1483,13 @@ for (; Case; Case = Case->getNextSwitchCase()) { // It's either a default or case. Just remember the default statement in // case we're not jumping to any numbered cases. - if (const DefaultStmt *DS = dyn_cast(Case)) { + if (const auto *DS = dyn_cast(Case)) { DefaultCase = DS; continue; } // Check to see if this case is the one we're looking for. - const CaseStmt *CS = cast(Case); + const auto *CS = cast(Case); // Don't handle case ranges yet. if (CS->getRHS()) return false; @@ -1729,16 +1728,16 @@ AddVariableConstraints(const std::string &Constraint, const Expr &AsmExpr, const TargetInfo &Target, CodeGenModule &CGM, const AsmStmt &Stmt, const bool EarlyClobber) { - const DeclRefExpr *AsmDeclRef = dyn_cast(&AsmExpr); + const auto *AsmDeclRef = dyn_cast(&AsmExpr); if (!AsmDeclRef) return Constraint; const ValueDecl &Value = *AsmDeclRef->getDecl(); - const VarDecl *Variable = dyn_cast(&Value); + const auto *Variable = dyn_cast(&Value); if (!Variable) return Constraint; if (Variable->getStorageClass() != SC_Register) return Constraint; - AsmLabelAttr *Attr = Variable->getAttr(); + auto *Attr = Variable->getAttr(); if (!Attr) return Constraint; StringRef Register = Attr->getLabel(); @@ -1853,7 +1852,7 @@ for (unsigned i = 0, e = S.getNumOutputs(); i != e; i++) { StringRef Name; - if (const GCCAsmStmt *GAS = dyn_cast(&S)) + if (const auto *GAS = dyn_cast(&S)) Name = GAS->getOutputName(i); TargetInfo::ConstraintInfo Info(S.getOutputConstraint(i), Name); bool IsValid = getTarget().validateOutputConstraint(Info); (void)IsValid; @@ -1863,7 +1862,7 @@ for (unsigned i = 0, e = S.getNumInputs(); i != e; i++) { StringRef Name; - if (const GCCAsmStmt *GAS = dyn_cast(&S)) + if (const auto *GAS = dyn_cast(&S)) Name = GAS->getInputName(i); TargetInfo::ConstraintInfo Info(S.getInputConstraint(i), Name); bool IsValid = @@ -2123,7 +2122,7 @@ // Slap the source location of the inline asm into a !srcloc metadata on the // call. - if (const GCCAsmStmt *gccAsmStmt = dyn_cast(&S)) { + if (const auto *gccAsmStmt = dyn_cast(&S)) { Result->setMetadata("srcloc", getAsmSrcLocInfo(gccAsmStmt->getAsmString(), *this)); } else { Index: lib/CodeGen/CGStmtOpenMP.cpp =================================================================== --- lib/CodeGen/CGStmtOpenMP.cpp +++ lib/CodeGen/CGStmtOpenMP.cpp @@ -1538,7 +1538,7 @@ if (const auto *C = D.getSingleClause()) { RValue Len = CGF.EmitAnyExpr(C->getSimdlen(), AggValueSlot::ignored(), /*ignoreResult=*/true); - llvm::ConstantInt *Val = cast(Len.getScalarVal()); + auto *Val = cast(Len.getScalarVal()); CGF.LoopStack.setVectorizeWidth(Val->getZExtValue()); // In presence of finite 'safelen', it may be unsafe to mark all // the memory instructions parallel, because loop-carried @@ -1548,7 +1548,7 @@ } else if (const auto *C = D.getSingleClause()) { RValue Len = CGF.EmitAnyExpr(C->getSafelen(), AggValueSlot::ignored(), /*ignoreResult=*/true); - llvm::ConstantInt *Val = cast(Len.getScalarVal()); + auto *Val = cast(Len.getScalarVal()); CGF.LoopStack.setVectorizeWidth(Val->getZExtValue()); // In presence of finite 'safelen', it may be unsafe to mark all // the memory instructions parallel, because loop-carried @@ -1639,7 +1639,7 @@ // Emit the loop iteration variable. const Expr *IVExpr = S.getIterationVariable(); - const VarDecl *IVDecl = cast(cast(IVExpr)->getDecl()); + const auto *IVDecl = cast(cast(IVExpr)->getDecl()); CGF.EmitVarDecl(*IVDecl); CGF.EmitIgnoredExpr(S.getInit()); @@ -3421,8 +3421,8 @@ *CS->getCapturedDecl()->param_begin(), InnermostKind, CodeGen); const OMPTeamsDirective &TD = *dyn_cast(&S); - const OMPNumTeamsClause *NT = TD.getSingleClause(); - const OMPThreadLimitClause *TL = TD.getSingleClause(); + const auto *NT = TD.getSingleClause(); + const auto *TL = TD.getSingleClause(); if (NT || TL) { Expr *NumTeams = (NT) ? NT->getNumTeams() : nullptr; Expr *ThreadLimit = (TL) ? TL->getThreadLimit() : nullptr; @@ -3771,7 +3771,7 @@ (void)LoopScope.Privatize(); // Emit the loop iteration variable. const Expr *IVExpr = S.getIterationVariable(); - const VarDecl *IVDecl = cast(cast(IVExpr)->getDecl()); + const auto *IVDecl = cast(cast(IVExpr)->getDecl()); CGF.EmitVarDecl(*IVDecl); CGF.EmitIgnoredExpr(S.getInit()); Index: lib/CodeGen/CGVTables.cpp =================================================================== --- lib/CodeGen/CGVTables.cpp +++ lib/CodeGen/CGVTables.cpp @@ -32,12 +32,12 @@ llvm::Constant *CodeGenModule::GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk) { - const CXXMethodDecl *MD = cast(GD.getDecl()); + const auto *MD = cast(GD.getDecl()); // Compute the mangled name. SmallString<256> Name; llvm::raw_svector_ostream Out(Name); - if (const CXXDestructorDecl* DD = dyn_cast(MD)) + if (const auto *DD = dyn_cast(MD)) getCXXABI().getMangleContext().mangleCXXDtorThunk(DD, GD.getDtorType(), Thunk.This, Out); else @@ -61,7 +61,7 @@ !Thunk.Return.isEmpty()); // Set the right visibility. - const CXXMethodDecl *MD = cast(GD.getDecl()); + const auto *MD = cast(GD.getDecl()); setThunkVisibility(CGM, MD, Thunk, ThunkFn); if (CGM.supportsCOMDAT() && ThunkFn->isWeakForLinker()) @@ -142,15 +142,15 @@ CodeGenFunction::GenerateVarArgsThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, GlobalDecl GD, const ThunkInfo &Thunk) { - const CXXMethodDecl *MD = cast(GD.getDecl()); - const FunctionProtoType *FPT = MD->getType()->getAs(); + const auto *MD = cast(GD.getDecl()); + const auto *FPT = MD->getType()->getAs(); QualType ResultType = FPT->getReturnType(); // Get the original function assert(FnInfo.isVariadic()); llvm::Type *Ty = CGM.getTypes().GetFunctionType(FnInfo); llvm::Value *Callee = CGM.GetAddrOfFunction(GD, Ty, /*ForVTable=*/true); - llvm::Function *BaseFn = cast(Callee); + auto *BaseFn = cast(Callee); // Clone to thunk. llvm::ValueToValueMapTy VMap; @@ -210,9 +210,9 @@ CurFuncIsThunk = true; // Build FunctionArgs. - const CXXMethodDecl *MD = cast(GD.getDecl()); + const auto *MD = cast(GD.getDecl()); QualType ThisType = MD->getThisType(getContext()); - const FunctionProtoType *FPT = MD->getType()->getAs(); + const auto *FPT = MD->getType()->getAs(); QualType ResultType = CGM.getCXXABI().HasThisReturn(GD) ? ThisType : CGM.getCXXABI().hasMostDerivedReturn(GD) @@ -256,7 +256,7 @@ const ThunkInfo *Thunk) { assert(isa(CurGD.getDecl()) && "Please use a new CGF for this thunk"); - const CXXMethodDecl *MD = cast(CurGD.getDecl()); + const auto *MD = cast(CurGD.getDecl()); // Adjust the 'this' pointer if necessary llvm::Value *AdjustedThisPtr = @@ -288,7 +288,7 @@ for (const ParmVarDecl *PD : MD->parameters()) EmitDelegateCallArg(CallArgs, PD, SourceLocation()); - const FunctionProtoType *FPT = MD->getType()->getAs(); + const auto *FPT = MD->getType()->getAs(); #ifndef NDEBUG const CGFunctionInfo &CallFnInfo = CGM.getTypes().arrangeCXXMethodCall( @@ -327,7 +327,7 @@ // Consider return adjustment if we have ThunkInfo. if (Thunk && !Thunk->Return.isEmpty()) RV = PerformReturnAdjustment(*this, ResultType, RV, *Thunk); - else if (llvm::CallInst* Call = dyn_cast(CallOrInvoke)) + else if (auto *Call = dyn_cast(CallOrInvoke)) Call->setTailCallKind(llvm::CallInst::TCK_Tail); // Emit return. @@ -421,7 +421,7 @@ llvm::GlobalValue *Entry; // Strip off a bitcast if we got one back. - if (llvm::ConstantExpr *CE = dyn_cast(C)) { + if (auto *CE = dyn_cast(C)) { assert(CE->getOpcode() == llvm::Instruction::BitCast); Entry = cast(CE->getOperand(0)); } else { @@ -453,7 +453,7 @@ OldThunkFn->eraseFromParent(); } - llvm::Function *ThunkFn = cast(Entry); + auto *ThunkFn = cast(Entry); bool ABIHasKeyFunctions = CGM.getTarget().getCXXABI().hasKeyFunctions(); bool UseAvailableExternallyLinkage = ForVTable && ABIHasKeyFunctions; @@ -498,7 +498,7 @@ return; // We can't emit thunks for member functions with incomplete types. - const CXXMethodDecl *MD = cast(GD.getDecl()); + const auto *MD = cast(GD.getDecl()); if (!CGM.getTypes().isFuncTypeConvertible( MD->getType()->castAs())) return; @@ -573,7 +573,7 @@ // Emit NULL for methods we can't codegen on this // side. Otherwise we'd end up with vtable with unresolved // references. - const CXXMethodDecl *MD = cast(GD.getDecl()); + const auto *MD = cast(GD.getDecl()); // OK on device side: functions w/ __device__ attribute // OK on host side: anything except __device__-only functions. bool CanEmitMethod = Index: lib/CodeGen/CodeGenAction.cpp =================================================================== --- lib/CodeGen/CodeGenAction.cpp +++ lib/CodeGen/CodeGenAction.cpp @@ -767,7 +767,7 @@ std::unique_ptr CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { - BackendAction BA = static_cast(Act); + auto BA = static_cast(Act); std::unique_ptr OS = GetOutputStream(CI, InFile, BA); if (BA != Backend_EmitNothing && !OS) return nullptr; @@ -840,7 +840,7 @@ void CodeGenAction::ExecuteAction() { // If this is an IR file, we have to treat it specially. if (getCurrentFileKind() == IK_LLVM_IR) { - BackendAction BA = static_cast(Act); + auto BA = static_cast(Act); CompilerInstance &CI = getCompilerInstance(); std::unique_ptr OS = GetOutputStream(CI, getCurrentFile(), BA); Index: lib/CodeGen/CodeGenFunction.h =================================================================== --- lib/CodeGen/CodeGenFunction.h +++ lib/CodeGen/CodeGenFunction.h @@ -939,7 +939,7 @@ // Leave Data empty. return; - const BinaryConditionalOperator *e = cast(op); + const auto *e = cast(op); Data = OpaqueValueMappingData::bind(CGF, e->getOpaqueValue(), e->getCommon()); } @@ -3494,11 +3494,11 @@ // that may have type parameters in its signature. static bool isObjCMethodWithTypeParams(const ObjCMethodDecl *method) { const DeclContext *dc = method->getDeclContext(); - if (const ObjCInterfaceDecl *classDecl= dyn_cast(dc)) { + if (const auto *classDecl = dyn_cast(dc)) { return classDecl->getTypeParamListAsWritten(); } - if (const ObjCCategoryDecl *catDecl = dyn_cast(dc)) { + if (const auto *catDecl = dyn_cast(dc)) { return catDecl->getTypeParamList(); } Index: lib/CodeGen/CodeGenFunction.cpp =================================================================== --- lib/CodeGen/CodeGenFunction.cpp +++ lib/CodeGen/CodeGenFunction.cpp @@ -260,8 +260,8 @@ // branch then we can just put the code in that block instead. This // cleans up functions which started with a unified return block. if (ReturnBlock.getBlock()->hasOneUse()) { - llvm::BranchInst *BI = - dyn_cast(*ReturnBlock.getBlock()->user_begin()); + auto *BI = + dyn_cast(*ReturnBlock.getBlock()->user_begin()); if (BI && BI->isUnconditional() && BI->getSuccessor(0) == ReturnBlock.getBlock()) { // Record/return the DebugLoc of the simple 'return' expression to be used @@ -381,7 +381,7 @@ // If someone took the address of a label but never did an indirect goto, we // made a zero entry PHI node, which is illegal, zap it now. if (IndirectBranch) { - llvm::PHINode *PN = cast(IndirectBranch->getAddress()); + auto *PN = cast(IndirectBranch->getAddress()); if (PN->getNumIncomingValues() == 0) { PN->replaceAllUsesWith(llvm::UndefValue::get(PN->getType())); PN->eraseFromParent(); @@ -659,7 +659,7 @@ if (const VecTypeHintAttr *A = FD->getAttr()) { QualType hintQTy = A->getTypeHint(); - const ExtVectorType *hintEltQTy = hintQTy->getAs(); + const auto *hintEltQTy = hintQTy->getAs(); bool isSignedInteger = hintQTy->isSignedIntegerType() || (hintEltQTy && hintEltQTy->getElementType()->isSignedIntegerType()); @@ -780,7 +780,7 @@ // attribute to all functions that are not marked AlwaysInline, or // to all functions that are not marked inline or implicitly inline // in the case of -finline-hint-functions. - if (const FunctionDecl *FD = dyn_cast_or_null(D)) { + if (const auto *FD = dyn_cast_or_null(D)) { const CodeGenOptions& CodeGenOpts = CGM.getCodeGenOpts(); if (!CodeGenOpts.NoInline) { for (auto RI : FD->redecls()) @@ -803,14 +803,14 @@ if (getLangOpts().OpenCL) { // Add metadata for a kernel function. - if (const FunctionDecl *FD = dyn_cast_or_null(D)) + if (const auto *FD = dyn_cast_or_null(D)) EmitOpenCLKernelMetadata(FD, Fn); } // If we are checking function types, emit a function type signature as // prologue data. if (getLangOpts().CPlusPlus && SanOpts.has(SanitizerKind::Function)) { - if (const FunctionDecl *FD = dyn_cast_or_null(D)) { + if (const auto *FD = dyn_cast_or_null(D)) { if (llvm::Constant *PrologueSig = CGM.getTargetCodeGenInfo().getUBSanFunctionSignature(CGM)) { llvm::Constant *FTRTTIConst = @@ -827,7 +827,7 @@ // to be norecurse by the standard (3.6.1.3 "The function main shall not be // used within a program"). if (getLangOpts().CPlusPlus) - if (const FunctionDecl *FD = dyn_cast_or_null(D)) + if (const auto *FD = dyn_cast_or_null(D)) if (FD->isMain()) Fn->addFnAttr(llvm::Attribute::NoRecurse); @@ -913,7 +913,7 @@ if (D && isa(D) && cast(D)->isInstance()) { CGM.getCXXABI().EmitInstanceFunctionProlog(*this); - const CXXMethodDecl *MD = cast(D); + const auto *MD = cast(D); if (MD->getParent()->isLambda() && MD->getOverloadedOperator() == OO_Call) { // We're in a lambda; figure out the captures. @@ -963,7 +963,7 @@ // the standard (C99 6.9.1p10) requires this, but we're following the // precedent set by gcc. QualType Ty; - if (const ParmVarDecl *PVD = dyn_cast(VD)) + if (const auto *PVD = dyn_cast(VD)) Ty = PVD->getOriginalType(); else Ty = VD->getType(); @@ -979,7 +979,7 @@ void CodeGenFunction::EmitFunctionBody(FunctionArgList &Args, const Stmt *Body) { incrementProfileCounter(Body); - if (const CompoundStmt *S = dyn_cast(Body)) + if (const auto *S = dyn_cast(Body)) EmitCompoundStmtWithoutScope(*S); else EmitStmt(Body); @@ -1025,10 +1025,10 @@ QualType CodeGenFunction::BuildFunctionArgList(GlobalDecl GD, FunctionArgList &Args) { - const FunctionDecl *FD = cast(GD.getDecl()); + const auto *FD = cast(GD.getDecl()); QualType ResTy = FD->getReturnType(); - const CXXMethodDecl *MD = dyn_cast(FD); + const auto *MD = dyn_cast(FD); if (MD && MD->isInstance()) { if (CGM.getCXXABI().HasThisReturn(GD)) ResTy = MD->getThisType(getContext()); @@ -1041,7 +1041,7 @@ // virtual base is not passed any arguments (because it doesn't actually call // the inherited constructor). bool PassedParams = true; - if (const CXXConstructorDecl *CD = dyn_cast(FD)) + if (const auto *CD = dyn_cast(FD)) if (auto Inherited = CD->getInheritedConstructor()) PassedParams = getTypes().inheritingCtorHasParams(Inherited, GD.getCtorType()); @@ -1069,7 +1069,7 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo) { - const FunctionDecl *FD = cast(GD.getDecl()); + const auto *FD = cast(GD.getDecl()); CurGD = GD; FunctionArgList Args; @@ -1291,7 +1291,7 @@ uint64_t TrueCount) { Cond = Cond->IgnoreParens(); - if (const BinaryOperator *CondBOp = dyn_cast(Cond)) { + if (const auto *CondBOp = dyn_cast(Cond)) { // Handle X && Y in a condition. if (CondBOp->getOpcode() == BO_LAnd) { @@ -1391,7 +1391,7 @@ } } - if (const UnaryOperator *CondUOp = dyn_cast(Cond)) { + if (const auto *CondUOp = dyn_cast(Cond)) { // br(!x, t, f) -> br(x, f, t) if (CondUOp->getOpcode() == UO_LNot) { // Negate the count. @@ -1402,7 +1402,7 @@ } } - if (const ConditionalOperator *CondOp = dyn_cast(Cond)) { + if (const auto *CondOp = dyn_cast(Cond)) { // br(c ? x : y, t, f) -> br(c, br(x, t, f), br(y, t, f)) llvm::BasicBlock *LHSBlock = createBasicBlock("cond.true"); llvm::BasicBlock *RHSBlock = createBasicBlock("cond.false"); @@ -1442,7 +1442,7 @@ return; } - if (const CXXThrowExpr *Throw = dyn_cast(Cond)) { + if (const auto *Throw = dyn_cast(Cond)) { // Conditional operator handling can give us a throw expression as a // condition for a case like: // br(c ? throw x : y, t, f) -> br(c, br(throw x, t, f), br(y, t, f) @@ -1560,9 +1560,8 @@ // Don't bother emitting a zero-byte memset. if (size.isZero()) { // But note that getTypeInfo returns 0 for a VLA. - if (const VariableArrayType *vlaType = - dyn_cast_or_null( - getContext().getAsArrayType(Ty))) { + if (const auto *vlaType = dyn_cast_or_null( + getContext().getAsArrayType(Ty))) { QualType eltType; llvm::Value *numElts; std::tie(numElts, eltType) = getVLASize(vlaType); @@ -1682,8 +1681,7 @@ uint64_t countFromCLAs = 1; QualType eltType; - llvm::ArrayType *llvmArrayType = - dyn_cast(addr.getElementType()); + auto *llvmArrayType = dyn_cast(addr.getElementType()); while (llvmArrayType) { assert(isa(arrayType)); assert(cast(arrayType)->getSize().getZExtValue() @@ -1833,7 +1831,7 @@ case Type::VariableArray: { // Losing element qualification here is fine. - const VariableArrayType *vat = cast(ty); + const auto *vat = cast(ty); // Unknown size indication requires no size computation. // Otherwise, evaluate and record it. @@ -2064,7 +2062,7 @@ // Get the current enclosing function if it exists. If it doesn't // we can't check the target features anyhow. - const FunctionDecl *FD = dyn_cast_or_null(CurFuncDecl); + const auto *FD = dyn_cast_or_null(CurFuncDecl); if (!FD) return; Index: lib/CodeGen/CodeGenModule.cpp =================================================================== --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -303,8 +303,8 @@ << IsIFunc << IsIFunc; } else if (IsIFunc) { // Check resolver function type. - llvm::FunctionType *FTy = dyn_cast( - GV->getType()->getPointerElementType()); + auto *FTy = + dyn_cast(GV->getType()->getPointerElementType()); assert(FTy); if (!FTy->getReturnType()->isPointerTy()) Diags.Report(Location, diag::err_ifunc_resolver_return); @@ -815,7 +815,7 @@ } llvm::ConstantInt *CodeGenModule::CreateCrossDsoCfiTypeId(llvm::Metadata *MD) { - llvm::MDString *MDS = dyn_cast(MD); + auto *MDS = dyn_cast(MD); if (!MDS) return nullptr; return llvm::ConstantInt::get(Int64Ty, llvm::MD5Hash(MDS->getString())); @@ -1226,8 +1226,7 @@ bool AnyChildren = false; // Visit the submodules of this module. - for (clang::Module::submodule_iterator Sub = Mod->submodule_begin(), - SubEnd = Mod->submodule_end(); + for (auto Sub = Mod->submodule_begin(), SubEnd = Mod->submodule_end(); Sub != SubEnd; ++Sub) { // Skip explicit children; they need to be explicitly imported to be // linked against. @@ -1295,8 +1294,7 @@ // to get GlobalValue with exactly the type we need, not something that // might had been created for another decl with the same mangled name but // different type. - llvm::GlobalValue *GV = dyn_cast( - GetAddrOfGlobal(D, ForDefinition)); + auto *GV = dyn_cast(GetAddrOfGlobal(D, ForDefinition)); // In case of different address spaces, we may still get a cast, even with // IsForDefinition equal to true. Query mangled names table to get @@ -1673,7 +1671,7 @@ const FunctionDecl *FD = E->getDirectCallee(); if (!FD) return true; - AsmLabelAttr *Attr = FD->getAttr(); + auto *Attr = FD->getAttr(); if (Attr && Name == Attr->getLabel()) { Result = true; return false; @@ -1708,7 +1706,7 @@ ValueDecl *VD = E->getDecl(); if (isa(VD)) SafeToInline = VD->hasAttr(); - else if (VarDecl *V = dyn_cast(VD)) + else if (auto *V = dyn_cast(VD)) SafeToInline = !V->hasGlobalStorage() || V->hasAttr(); return SafeToInline; } @@ -1735,7 +1733,7 @@ StringRef Name; if (getCXXABI().getMangleContext().shouldMangleDeclName(FD)) { // asm labels are a special kind of mangling we have to support. - AsmLabelAttr *Attr = FD->getAttr(); + auto *Attr = FD->getAttr(); if (!Attr) return false; Name = Attr->getLabel(); @@ -1750,8 +1748,8 @@ // Check if T is a class type with a destructor that's not dllimport. static bool HasNonDllImportDtor(QualType T) { - if (const RecordType *RT = dyn_cast(T)) - if (CXXRecordDecl *RD = dyn_cast(RT->getDecl())) + if (const auto *RT = dyn_cast(T)) + if (auto *RD = dyn_cast(RT->getDecl())) if (RD->getDestructor() && !RD->getDestructor()->hasAttr()) return true; @@ -1772,7 +1770,7 @@ if (!Visitor.SafeToInline) return false; - if (const CXXDestructorDecl *Dtor = dyn_cast(F)) { + if (const auto *Dtor = dyn_cast(F)) { // Implicit destructor invocations aren't captured in the AST, so the // check above can't see them. Check for them manually here. for (const Decl *Member : Dtor->getParent()->decls()) @@ -1871,7 +1869,7 @@ llvm::GlobalValue *Entry = GetGlobalValue(MangledName); if (Entry) { if (WeakRefReferences.erase(Entry)) { - const FunctionDecl *FD = cast_or_null(D); + const auto *FD = cast_or_null(D); if (FD && !FD->hasAttr()) Entry->setLinkage(llvm::Function::ExternalLinkage); } @@ -3121,7 +3119,7 @@ IsUTF16 = true; SmallVector ToBuf(NumBytes + 1); // +1 for ending nulls. - const llvm::UTF8 *FromPtr = (const llvm::UTF8 *)String.data(); + const auto *FromPtr = (const llvm::UTF8 *)String.data(); llvm::UTF16 *ToPtr = &ToBuf[0]; (void)llvm::ConvertUTF8toUTF16(&FromPtr, FromPtr + NumBytes, &ToPtr, @@ -3164,7 +3162,7 @@ IdentifierInfo &II = getContext().Idents.get(GV->getName()); TranslationUnitDecl *TUDecl = getContext().getTranslationUnitDecl(); DeclContext *DC = TranslationUnitDecl::castToDeclContext(TUDecl); - llvm::GlobalValue *CGV = cast(GV); + auto *CGV = cast(GV); const VarDecl *VD = nullptr; for (const auto &Result : DC->lookup(&II)) @@ -3859,8 +3857,7 @@ EmitTopLevelDecl(D); // Visit the submodules of this module. - for (clang::Module::submodule_iterator Sub = Mod->submodule_begin(), - SubEnd = Mod->submodule_end(); + for (auto Sub = Mod->submodule_begin(), SubEnd = Mod->submodule_end(); Sub != SubEnd; ++Sub) { // Skip explicit children; they need to be explicitly imported to emit // the initializers. @@ -3991,7 +3988,7 @@ /// Turns the given pointer into a constant. static llvm::Constant *GetPointerConstant(llvm::LLVMContext &Context, const void *Ptr) { - uintptr_t PtrInt = reinterpret_cast(Ptr); + auto PtrInt = reinterpret_cast(Ptr); llvm::Type *i64 = llvm::Type::getInt64Ty(Context); return llvm::ConstantInt::get(i64, PtrInt); } Index: lib/CodeGen/CodeGenPGO.cpp =================================================================== --- lib/CodeGen/CodeGenPGO.cpp +++ lib/CodeGen/CodeGenPGO.cpp @@ -187,7 +187,7 @@ case Stmt::BinaryConditionalOperatorClass: return PGOHash::BinaryConditionalOperator; case Stmt::BinaryOperatorClass: { - const BinaryOperator *BO = cast(S); + const auto *BO = cast(S); if (BO->getOpcode() == BO_LAnd) return PGOHash::BinaryOperatorLAnd; if (BO->getOpcode() == BO_LOr) @@ -586,7 +586,7 @@ // Pass through MD5 if enough work has built up. if (Count && Count % NumTypesPerWord == 0) { using namespace llvm::support; - uint64_t Swapped = endian::byte_swap(Working); + auto Swapped = endian::byte_swap(Working); MD5.update(llvm::makeArrayRef((uint8_t *)&Swapped, sizeof(Swapped))); Working = 0; } @@ -650,13 +650,13 @@ void CodeGenPGO::mapRegionCounters(const Decl *D) { RegionCounterMap.reset(new llvm::DenseMap); MapRegionCounters Walker(*RegionCounterMap); - if (const FunctionDecl *FD = dyn_cast_or_null(D)) + if (const auto *FD = dyn_cast_or_null(D)) Walker.TraverseDecl(const_cast(FD)); - else if (const ObjCMethodDecl *MD = dyn_cast_or_null(D)) + else if (const auto *MD = dyn_cast_or_null(D)) Walker.TraverseDecl(const_cast(MD)); - else if (const BlockDecl *BD = dyn_cast_or_null(D)) + else if (const auto *BD = dyn_cast_or_null(D)) Walker.TraverseDecl(const_cast(BD)); - else if (const CapturedDecl *CD = dyn_cast_or_null(D)) + else if (const auto *CD = dyn_cast_or_null(D)) Walker.TraverseDecl(const_cast(CD)); assert(Walker.NextCounter > 0 && "no entry counter mapped for decl"); NumRegionCounters = Walker.NextCounter; @@ -717,13 +717,13 @@ void CodeGenPGO::computeRegionCounts(const Decl *D) { StmtCountMap.reset(new llvm::DenseMap); ComputeRegionCounts Walker(*StmtCountMap, *this); - if (const FunctionDecl *FD = dyn_cast_or_null(D)) + if (const auto *FD = dyn_cast_or_null(D)) Walker.VisitFunctionDecl(FD); - else if (const ObjCMethodDecl *MD = dyn_cast_or_null(D)) + else if (const auto *MD = dyn_cast_or_null(D)) Walker.VisitObjCMethodDecl(MD); - else if (const BlockDecl *BD = dyn_cast_or_null(D)) + else if (const auto *BD = dyn_cast_or_null(D)) Walker.VisitBlockDecl(BD); - else if (const CapturedDecl *CD = dyn_cast_or_null(D)) + else if (const auto *CD = dyn_cast_or_null(D)) Walker.VisitCapturedDecl(const_cast(CD)); } Index: lib/CodeGen/CodeGenTBAA.cpp =================================================================== --- lib/CodeGen/CodeGenTBAA.cpp +++ lib/CodeGen/CodeGenTBAA.cpp @@ -74,11 +74,11 @@ static bool TypeHasMayAlias(QualType QTy) { // Tagged types have declarations, and therefore may have attributes. - if (const TagType *TTy = dyn_cast(QTy)) + if (const auto *TTy = dyn_cast(QTy)) return TTy->getDecl()->hasAttr(); // Typedef types have declarations, and therefore may have attributes. - if (const TypedefType *TTy = dyn_cast(QTy)) { + if (const auto *TTy = dyn_cast(QTy)) { if (TTy->getDecl()->hasAttr()) return true; // Also, their underlying types may have relevant attributes. @@ -105,7 +105,7 @@ return N; // Handle builtin types. - if (const BuiltinType *BTy = dyn_cast(Ty)) { + if (const auto *BTy = dyn_cast(Ty)) { switch (BTy->getKind()) { // Character types are special and can alias anything. // In C++, this technically only includes "char" and "unsigned char", @@ -148,7 +148,7 @@ // Enum types are distinct types. In C++ they have "underlying types", // however they aren't related for TBAA. - if (const EnumType *ETy = dyn_cast(Ty)) { + if (const auto *ETy = dyn_cast(Ty)) { // In C++ mode, types have linkage, so we can rely on the ODR and // on their mangled names, if they're external. // TODO: Is there a way to get a program-wide unique name for a @@ -184,7 +184,7 @@ return false; // TODO: Handle C++ base classes. - if (const CXXRecordDecl *Decl = dyn_cast(RD)) + if (const auto *Decl = dyn_cast(RD)) if (Decl->bases_begin() != Decl->bases_end()) return false; Index: lib/CodeGen/CodeGenTypes.cpp =================================================================== --- lib/CodeGen/CodeGenTypes.cpp +++ lib/CodeGen/CodeGenTypes.cpp @@ -130,7 +130,7 @@ // out, don't do it. This includes virtual base classes which get laid out // when a class is translated, even though they aren't embedded by-value into // the class. - if (const CXXRecordDecl *CRD = dyn_cast(RD)) { + if (const auto *CRD = dyn_cast(RD)) { for (const auto &I : CRD->bases()) if (!isSafeToConvert(I.getType()->getAs()->getDecl(), CGT, AlreadyChecked)) @@ -195,7 +195,7 @@ return getCXXABI().isMemberPointerConvertible(MPT); // If this isn't a tagged type, we can convert it! - const TagType *TT = Ty->getAs(); + const auto *TT = Ty->getAs(); if (!TT) return true; // Incomplete types cannot be converted. @@ -203,7 +203,7 @@ return false; // If this is an enum, then it is always safe to convert. - const RecordType *RT = dyn_cast(TT); + const auto *RT = dyn_cast(TT); if (!RT) return true; // Otherwise, we have to be careful. If it is a struct that we're in the @@ -225,8 +225,8 @@ bool CodeGenTypes::isFuncTypeConvertible(const FunctionType *FT) { if (!isFuncParamTypeConvertible(FT->getReturnType())) return false; - - if (const FunctionProtoType *FPT = dyn_cast(FT)) + + if (const auto *FPT = dyn_cast(FT)) for (unsigned i = 0, e = FPT->getNumParams(); i != e; i++) if (!isFuncParamTypeConvertible(FPT->getParamType(i))) return false; @@ -240,7 +240,7 @@ // If this is an enum being completed, then we flush all non-struct types from // the cache. This allows function types and other things that may be derived // from the enum to be recomputed. - if (const EnumDecl *ED = dyn_cast(TD)) { + if (const auto *ED = dyn_cast(TD)) { // Only flush the cache if we've actually already converted this type. if (TypeCache.count(ED->getTypeForDecl())) { // Okay, we formed some types based on this. We speculated that the enum @@ -258,7 +258,7 @@ // If we completed a RecordDecl that we previously used and converted to an // anonymous type, then go ahead and complete it now. - const RecordDecl *RD = cast(TD); + const auto *RD = cast(TD); if (RD->isDependentType()) return; // Only complete it if we converted it already. If we haven't converted it @@ -309,7 +309,7 @@ const FunctionDecl *FD) { assert(QFT.isCanonical()); const Type *Ty = QFT.getTypePtr(); - const FunctionType *FT = cast(QFT.getTypePtr()); + const auto *FT = cast(QFT.getTypePtr()); // First, check whether we can build the full function type. If the // function type depends on an incomplete type (e.g. a struct or enum), we // cannot lower the function type. @@ -320,7 +320,7 @@ // we re-convert the FunctionType when appropriate. if (const RecordType *RT = FT->getReturnType()->getAs()) ConvertRecordDeclType(RT->getDecl()); - if (const FunctionProtoType *FPT = dyn_cast(FT)) + if (const auto *FPT = dyn_cast(FT)) for (unsigned i = 0, e = FPT->getNumParams(); i != e; i++) if (const RecordType *RT = FPT->getParamType(i)->getAs()) ConvertRecordDeclType(RT->getDecl()); @@ -342,11 +342,11 @@ // The function type can be built; call the appropriate routines to // build it. const CGFunctionInfo *FI; - if (const FunctionProtoType *FPT = dyn_cast(FT)) { + if (const auto *FPT = dyn_cast(FT)) { FI = &arrangeFreeFunctionType( CanQual::CreateUnsafe(QualType(FPT, 0)), FD); } else { - const FunctionNoProtoType *FNPT = cast(FT); + const auto *FNPT = cast(FT); FI = &arrangeFreeFunctionType( CanQual::CreateUnsafe(QualType(FNPT, 0))); } @@ -382,7 +382,7 @@ const Type *Ty = T.getTypePtr(); // RecordTypes are cached and processed specially. - if (const RecordType *RT = dyn_cast(Ty)) + if (const auto *RT = dyn_cast(Ty)) return ConvertRecordDeclType(RT->getDecl()); // See if type is already cached. @@ -495,7 +495,7 @@ } case Type::LValueReference: case Type::RValueReference: { - const ReferenceType *RTy = cast(Ty); + const auto *RTy = cast(Ty); QualType ETy = RTy->getPointeeType(); llvm::Type *PointeeType = ConvertTypeForMem(ETy); unsigned AS = Context.getTargetAddressSpace(ETy); @@ -503,7 +503,7 @@ break; } case Type::Pointer: { - const PointerType *PTy = cast(Ty); + const auto *PTy = cast(Ty); QualType ETy = PTy->getPointeeType(); llvm::Type *PointeeType = ConvertTypeForMem(ETy); if (PointeeType->isVoidTy()) @@ -514,7 +514,7 @@ } case Type::VariableArray: { - const VariableArrayType *A = cast(Ty); + const auto *A = cast(Ty); assert(A->getIndexTypeCVRQualifiers() == 0 && "FIXME: We only handle trivial array types so far!"); // VLAs resolve to the innermost element type; this matches @@ -523,7 +523,7 @@ break; } case Type::IncompleteArray: { - const IncompleteArrayType *A = cast(Ty); + const auto *A = cast(Ty); assert(A->getIndexTypeCVRQualifiers() == 0 && "FIXME: We only handle trivial array types so far!"); // int X[] -> [0 x int], unless the element type is not sized. If it is @@ -537,7 +537,7 @@ break; } case Type::ConstantArray: { - const ConstantArrayType *A = cast(Ty); + const auto *A = cast(Ty); llvm::Type *EltTy = ConvertTypeForMem(A->getElementType()); // Lower arrays of undefined struct type to arrays of i8 just to have a @@ -552,7 +552,7 @@ } case Type::ExtVector: case Type::Vector: { - const VectorType *VT = cast(Ty); + const auto *VT = cast(Ty); ResultType = llvm::VectorType::get(ConvertType(VT->getElementType()), VT->getNumElements()); break; @@ -687,7 +687,7 @@ assert(InsertResult && "Recursively compiling a struct?"); // Force conversion of non-virtual base classes recursively. - if (const CXXRecordDecl *CRD = dyn_cast(RD)) { + if (const auto *CRD = dyn_cast(RD)) { for (const auto &I : CRD->bases()) { if (I.isVirtual()) continue; @@ -762,7 +762,7 @@ } // We have to ask the ABI about member pointers. - if (const MemberPointerType *MPT = T->getAs()) + if (const auto *MPT = T->getAs()) return getCXXABI().isZeroInitializable(MPT); // Everything else is okay. Index: lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- lib/CodeGen/ItaniumCXXABI.cpp +++ lib/CodeGen/ItaniumCXXABI.cpp @@ -527,8 +527,7 @@ llvm::Value *MemFnPtr, const MemberPointerType *MPT) { CGBuilderTy &Builder = CGF.Builder; - const FunctionProtoType *FPT = - MPT->getPointeeType()->getAs(); + const auto *FPT = MPT->getPointeeType()->getAs(); const CXXRecordDecl *RD = cast(MPT->getClass()->getAs()->getDecl()); @@ -685,8 +684,7 @@ CGBuilderTy &Builder = CGF.Builder; bool isDerivedToBase = (E->getCastKind() == CK_DerivedToBaseMemberPointer); - const MemberPointerType *destTy = - E->getType()->castAs(); + const auto *destTy = E->getType()->castAs(); // For member data pointers, this is just a matter of adding the // offset if the source is non-null. @@ -736,8 +734,7 @@ bool isDerivedToBase = (E->getCastKind() == CK_DerivedToBaseMemberPointer); - const MemberPointerType *destTy = - E->getType()->castAs(); + const auto *destTy = E->getType()->castAs(); // For member data pointers, this is just a matter of adding the // offset if the source is non-null. @@ -831,7 +828,7 @@ ThisAdjustment.getQuantity()); } } else { - const FunctionProtoType *FPT = MD->getType()->castAs(); + const auto *FPT = MD->getType()->castAs(); llvm::Type *Ty; // Check whether the function has a computable LLVM signature. if (Types.isFuncTypeConvertible(FPT)) { @@ -855,14 +852,14 @@ llvm::Constant *ItaniumCXXABI::EmitMemberPointer(const APValue &MP, QualType MPType) { - const MemberPointerType *MPT = MPType->castAs(); + const auto *MPT = MPType->castAs(); const ValueDecl *MPD = MP.getMemberPointerDecl(); if (!MPD) return EmitNullMemberPointer(MPT); CharUnits ThisAdjustment = getMemberPointerPathAdjustment(MP); - if (const CXXMethodDecl *MD = dyn_cast(MPD)) + if (const auto *MD = dyn_cast(MPD)) return BuildMemberPointer(MD, ThisAdjustment); CharUnits FieldOffset = @@ -1103,7 +1100,7 @@ // trivial destructor (or isn't a record), we just pass null. llvm::Constant *Dtor = nullptr; if (const RecordType *RecordTy = ThrowType->getAs()) { - CXXRecordDecl *Record = cast(RecordTy->getDecl()); + auto *Record = cast(RecordTy->getDecl()); if (!Record->hasTrivialDestructor()) { CXXDestructorDecl *DtorD = Record->getDestructor(); Dtor = CGM.getAddrOfCXXStructor(DtorD, StructorType::Complete); @@ -1385,7 +1382,7 @@ void ItaniumCXXABI::addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy, FunctionArgList &Params) { - const CXXMethodDecl *MD = cast(CGF.CurGD.getDecl()); + const auto *MD = cast(CGF.CurGD.getDecl()); assert(isa(MD) || isa(MD)); // Check if we need a VTT parameter as well. @@ -2155,7 +2152,7 @@ // Fetch the actual function. llvm::Constant *atexit = CGF.CGM.CreateRuntimeFunction(atexitTy, Name); - if (llvm::Function *fn = dyn_cast(atexit)) + if (auto *fn = dyn_cast(atexit)) fn->setDoesNotThrow(); // Create a variable that binds the atexit to this shared object. @@ -2298,7 +2295,7 @@ } } for (const VarDecl *VD : CXXThreadLocals) { - llvm::GlobalVariable *Var = + auto *Var = cast(CGM.GetGlobalValue(CGM.getMangledName(VD))); // Some targets require that all access to thread local variables go through @@ -2400,8 +2397,8 @@ /// Return whether the given global decl needs a VTT parameter, which it does /// if it's a base constructor or destructor with virtual bases. bool ItaniumCXXABI::NeedsVTTParameter(GlobalDecl GD) { - const CXXMethodDecl *MD = cast(GD.getDecl()); - + const auto *MD = cast(GD.getDecl()); + // We don't have any virtual bases, just return early. if (!MD->getParent()->getNumVBases()) return false; @@ -2550,7 +2547,7 @@ /*Constant=*/true, llvm::GlobalValue::ExternalLinkage, nullptr, Name); - if (const RecordType *RecordTy = dyn_cast(Ty)) { + if (const auto *RecordTy = dyn_cast(Ty)) { const CXXRecordDecl *RD = cast(RecordTy->getDecl()); if (RD->hasAttr()) GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass); @@ -2635,7 +2632,7 @@ static bool TypeInfoIsInStandardLibrary(const PointerType *PointerTy) { QualType PointeeTy = PointerTy->getPointeeType(); - const BuiltinType *BuiltinTy = dyn_cast(PointeeTy); + const auto *BuiltinTy = dyn_cast(PointeeTy); if (!BuiltinTy) return false; @@ -2653,12 +2650,12 @@ /// information for the given type exists in the standard library. static bool IsStandardLibraryRTTIDescriptor(QualType Ty) { // Type info for builtin types is defined in the standard library. - if (const BuiltinType *BuiltinTy = dyn_cast(Ty)) + if (const auto *BuiltinTy = dyn_cast(Ty)) return TypeInfoIsInStandardLibrary(BuiltinTy); // Type info for some pointer types to builtin types is defined in the // standard library. - if (const PointerType *PointerTy = dyn_cast(Ty)) + if (const auto *PointerTy = dyn_cast(Ty)) return TypeInfoIsInStandardLibrary(PointerTy); return false; @@ -2676,7 +2673,7 @@ // translation unit that defines any potential key function, too. if (!Context.getLangOpts().RTTI) return false; - if (const RecordType *RecordTy = dyn_cast(Ty)) { + if (const auto *RecordTy = dyn_cast(Ty)) { const CXXRecordDecl *RD = cast(RecordTy->getDecl()); if (!RD->hasDefinition()) return false; @@ -2716,18 +2713,17 @@ /// incomplete class type. /// is an indirect or direct pointer to an incomplete class type. static bool ContainsIncompleteClassType(QualType Ty) { - if (const RecordType *RecordTy = dyn_cast(Ty)) { + if (const auto *RecordTy = dyn_cast(Ty)) { if (IsIncompleteClassType(RecordTy)) return true; } - if (const PointerType *PointerTy = dyn_cast(Ty)) + if (const auto *PointerTy = dyn_cast(Ty)) return ContainsIncompleteClassType(PointerTy->getPointeeType()); - if (const MemberPointerType *MemberPointerTy = - dyn_cast(Ty)) { + if (const auto *MemberPointerTy = dyn_cast(Ty)) { // Check if the class type is incomplete. - const RecordType *ClassType = cast(MemberPointerTy->getClass()); + const auto *ClassType = cast(MemberPointerTy->getClass()); if (IsIncompleteClassType(ClassType)) return true; @@ -2920,7 +2916,7 @@ if (!CGM.getLangOpts().RTTI) return llvm::GlobalValue::LinkOnceODRLinkage; - if (const RecordType *Record = dyn_cast(Ty)) { + if (const auto *Record = dyn_cast(Ty)) { const CXXRecordDecl *RD = cast(Record->getDecl()); if (RD->hasAttr()) return llvm::GlobalValue::WeakODRLinkage; @@ -3397,7 +3393,7 @@ // attributes of the type pointed to. unsigned Flags = extractPBaseFlags(CGM.getContext(), PointeeTy); - const RecordType *ClassType = cast(Ty->getClass()); + const auto *ClassType = cast(Ty->getClass()); if (IsIncompleteClassType(ClassType)) Flags |= PTI_ContainingClassIncomplete; @@ -3699,7 +3695,7 @@ // We have no way to tell the personality function that we're // catching by reference, so if we're catching a pointer, // __cxa_begin_catch will actually return that pointer by value. - if (const PointerType *PT = dyn_cast(CaughtType)) { + if (const auto *PT = dyn_cast(CaughtType)) { QualType PointeeType = PT->getPointeeType(); // When catching by reference, generally we should just ignore @@ -3901,7 +3897,7 @@ llvm::Constant *fnRef = CGM.CreateRuntimeFunction(fnTy, "__clang_call_terminate"); - llvm::Function *fn = dyn_cast(fnRef); + auto *fn = dyn_cast(fnRef); if (fn && fn->empty()) { fn->setDoesNotThrow(); fn->setDoesNotReturn(); Index: lib/CodeGen/MicrosoftCXXABI.cpp =================================================================== --- lib/CodeGen/MicrosoftCXXABI.cpp +++ lib/CodeGen/MicrosoftCXXABI.cpp @@ -911,8 +911,7 @@ // responsible for destruction. VarDecl *CatchParam = S->getExceptionDecl(); llvm::BasicBlock *CatchPadBB = CGF.Builder.GetInsertBlock(); - llvm::CatchPadInst *CPI = - cast(CatchPadBB->getFirstNonPHI()); + auto *CPI = cast(CatchPadBB->getFirstNonPHI()); CGF.CurrentFuncletPad = CPI; // If this is a catch-all or the catch parameter is unnamed, we don't need to @@ -1277,7 +1276,7 @@ // after 'this' if it's variadic and last if it's not. const CXXRecordDecl *Class = CD->getParent(); - const FunctionProtoType *FPT = CD->getType()->castAs(); + const auto *FPT = CD->getType()->castAs(); if (Class->getNumVBases()) { if (FPT->isVariadic()) ArgTys.insert(ArgTys.begin() + 1, getContext().IntTy); @@ -1295,10 +1294,10 @@ CharUnits MicrosoftCXXABI::getVirtualFunctionPrologueThisAdjustment(GlobalDecl GD) { GD = GD.getCanonicalDecl(); - const CXXMethodDecl *MD = cast(GD.getDecl()); + const auto *MD = cast(GD.getDecl()); GlobalDecl LookupGD = GD; - if (const CXXDestructorDecl *DD = dyn_cast(MD)) { + if (const auto *DD = dyn_cast(MD)) { // Complete destructors take a pointer to the complete object as a // parameter, thus don't need this adjustment. if (GD.getDtorType() == Dtor_Complete) @@ -1345,10 +1344,10 @@ } GD = GD.getCanonicalDecl(); - const CXXMethodDecl *MD = cast(GD.getDecl()); + const auto *MD = cast(GD.getDecl()); GlobalDecl LookupGD = GD; - if (const CXXDestructorDecl *DD = dyn_cast(MD)) { + if (const auto *DD = dyn_cast(MD)) { // Complete dtors take a pointer to the complete object, // thus don't need adjustment. if (GD.getDtorType() == Dtor_Complete) @@ -1403,7 +1402,7 @@ QualType &ResTy, FunctionArgList &Params) { ASTContext &Context = getContext(); - const CXXMethodDecl *MD = cast(CGF.CurGD.getDecl()); + const auto *MD = cast(CGF.CurGD.getDecl()); assert(isa(MD) || isa(MD)); if (isa(MD) && MD->getParent()->getNumVBases()) { ImplicitParamDecl *IsMostDerived @@ -1413,7 +1412,7 @@ Context.IntTy); // The 'most_derived' parameter goes second if the ctor is variadic and last // if it's not. Dtors can't be variadic. - const FunctionProtoType *FPT = MD->getType()->castAs(); + const auto *FPT = MD->getType()->castAs(); if (FPT->isVariadic()) Params.insert(Params.begin() + 1, IsMostDerived); else @@ -1473,7 +1472,7 @@ CGF.Builder.CreateStore(CGF.EmitCastToVoidPtr(getThisValue(CGF)), CGF.ReturnValue); - const CXXMethodDecl *MD = cast(CGF.CurGD.getDecl()); + const auto *MD = cast(CGF.CurGD.getDecl()); if (isa(MD) && MD->getParent()->getNumVBases()) { assert(getStructorImplicitParamDecl(CGF) && "no implicit parameter for a constructor with virtual bases?"); @@ -1503,7 +1502,7 @@ return 0; // Add the 'most_derived' argument second if we are variadic or last if not. - const FunctionProtoType *FPT = D->getType()->castAs(); + const auto *FPT = D->getType()->castAs(); llvm::Value *MostDerivedArg; if (Delegating) { MostDerivedArg = getStructorImplicitParamValue(CGF); @@ -2205,7 +2204,7 @@ llvm::Constant *TLRegDtor = CGF.CGM.CreateRuntimeFunction(TLRegDtorTy, "__tlregdtor"); - if (llvm::Function *TLRegDtorFn = dyn_cast(TLRegDtor)) + if (auto *TLRegDtorFn = dyn_cast(TLRegDtor)) TLRegDtorFn->setDoesNotThrow(); CGF.EmitNounwindRuntimeCall(TLRegDtor, DtorStub); @@ -2250,7 +2249,7 @@ std::vector NonComdatInits; for (size_t I = 0, E = CXXThreadLocalInitVars.size(); I != E; ++I) { - llvm::GlobalVariable *GV = cast( + auto *GV = cast( CGM.GetGlobalValue(CGM.getMangledName(CXXThreadLocalInitVars[I]))); llvm::Function *F = CXXThreadLocalInits[I]; @@ -2644,7 +2643,7 @@ llvm::Constant *MicrosoftCXXABI::EmitMemberPointer(const APValue &MP, QualType MPType) { - const MemberPointerType *DstTy = MPType->castAs(); + const auto *DstTy = MPType->castAs(); const ValueDecl *MPD = MP.getMemberPointerDecl(); if (!MPD) return EmitNullMemberPointer(DstTy); @@ -2653,7 +2652,7 @@ ArrayRef MemberPointerPath = MP.getMemberPointerPath(); llvm::Constant *C; - if (const CXXMethodDecl *MD = dyn_cast(MPD)) { + if (const auto *MD = dyn_cast(MPD)) { C = EmitMemberFunctionPointer(MD); } else { CharUnits FieldOffset = Ctx.toCharUnitsFromBits(Ctx.getFieldOffset(MPD)); @@ -2661,9 +2660,9 @@ } if (!MemberPointerPath.empty()) { - const CXXRecordDecl *SrcRD = cast(MPD->getDeclContext()); + const auto *SrcRD = cast(MPD->getDeclContext()); const Type *SrcRecTy = Ctx.getTypeDeclType(SrcRD).getTypePtr(); - const MemberPointerType *SrcTy = + const auto *SrcTy = Ctx.getMemberPointerType(DstTy->getPointeeType(), SrcRecTy) ->castAs(); @@ -2707,7 +2706,7 @@ unsigned VBTableIndex = 0; llvm::Constant *FirstField; - const FunctionProtoType *FPT = MD->getType()->castAs(); + const auto *FPT = MD->getType()->castAs(); if (!MD->isVirtual()) { llvm::Type *Ty; // Check whether the function has a computable LLVM signature. @@ -2781,7 +2780,7 @@ // Compare everything other than the first field. llvm::Value *Res = nullptr; - llvm::StructType *LType = cast(L->getType()); + auto *LType = cast(L->getType()); for (unsigned I = 1, E = LType->getNumElements(); I != E; ++I) { llvm::Value *LF = Builder.CreateExtractValue(L, I); llvm::Value *RF = Builder.CreateExtractValue(R, I); @@ -3021,9 +3020,8 @@ // We may be adding or dropping fields from the member pointer, so we need // both types and the inheritance models of both records. - const MemberPointerType *SrcTy = - E->getSubExpr()->getType()->castAs(); - const MemberPointerType *DstTy = E->getType()->castAs(); + const auto *SrcTy = E->getSubExpr()->getType()->castAs(); + const auto *DstTy = E->getType()->castAs(); bool IsFunc = SrcTy->isMemberFunctionPointer(); // If the classes use the same null representation, reinterpret_cast is a nop. @@ -3217,9 +3215,8 @@ llvm::Constant * MicrosoftCXXABI::EmitMemberPointerConversion(const CastExpr *E, llvm::Constant *Src) { - const MemberPointerType *SrcTy = - E->getSubExpr()->getType()->castAs(); - const MemberPointerType *DstTy = E->getType()->castAs(); + const auto *SrcTy = E->getSubExpr()->getType()->castAs(); + const auto *DstTy = E->getType()->castAs(); CastKind CK = E->getCastKind(); @@ -3257,8 +3254,7 @@ llvm::Value *&ThisPtrForCall, llvm::Value *MemPtr, const MemberPointerType *MPT) { assert(MPT->isMemberFunctionPointer()); - const FunctionProtoType *FPT = - MPT->getPointeeType()->castAs(); + const auto *FPT = MPT->getPointeeType()->castAs(); const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl(); llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType( CGM.getTypes().arrangeCXXMethodType(RD, FPT, /*FD=*/nullptr)); Index: lib/CodeGen/ModuleBuilder.cpp =================================================================== --- lib/CodeGen/ModuleBuilder.cpp +++ lib/CodeGen/ModuleBuilder.cpp @@ -215,7 +215,7 @@ // inline initializers as definitions. if (Ctx->getTargetInfo().getCXXABI().isMicrosoft()) { for (Decl *Member : D->decls()) { - if (VarDecl *VD = dyn_cast(Member)) { + if (auto *VD = dyn_cast(Member)) { if (Ctx->isMSStaticDataMemberInlineDefinition(VD) && Ctx->DeclMustBeEmitted(VD)) { Builder->EmitGlobal(VD); @@ -243,7 +243,7 @@ HandlingTopLevelDeclRAII HandlingDecl(*this, /*EmitDeferred=*/false); if (CodeGen::CGDebugInfo *DI = Builder->getModuleDebugInfo()) - if (const RecordDecl *RD = dyn_cast(D)) + if (const auto *RD = dyn_cast(D)) DI->completeRequiredType(RD); } Index: lib/CodeGen/ObjectFilePCHContainerOperations.cpp =================================================================== --- lib/CodeGen/ObjectFilePCHContainerOperations.cpp +++ lib/CodeGen/ObjectFilePCHContainerOperations.cpp @@ -221,7 +221,7 @@ if (Diags.hasErrorOccurred()) return; - if (const RecordDecl *RD = dyn_cast(D)) + if (const auto *RD = dyn_cast(D)) Builder->getModuleDebugInfo()->completeRequiredType(RD); } Index: lib/CodeGen/TargetInfo.cpp =================================================================== --- lib/CodeGen/TargetInfo.cpp +++ lib/CodeGen/TargetInfo.cpp @@ -461,7 +461,7 @@ return false; // If this is a C++ record, check the bases first. - if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) + if (const auto *CXXRD = dyn_cast(RD)) for (const auto &I : CXXRD->bases()) if (!isEmptyRecord(Context, I.getType(), true)) return false; @@ -492,7 +492,7 @@ const Type *Found = nullptr; // If this is a C++ record, check the bases first. - if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) { + if (const auto *CXXRD = dyn_cast(RD)) { for (const auto &I : CXXRD->bases()) { // Ignore empty records. if (isEmptyRecord(Context, I.getType(), true)) @@ -855,7 +855,7 @@ if (const BuiltinType *BT = Ty->getAs()) { if (BT->isFloatingPoint() && BT->getKind() != BuiltinType::Half) return true; - } else if (const VectorType *VT = Ty->getAs()) { + } else if (const auto *VT = Ty->getAs()) { // vectorcall can pass XMM, YMM, and ZMM vectors. We don't pass SSE1 MMX // registers specially. unsigned VecSize = Context.getTypeSize(VT); @@ -1166,7 +1166,7 @@ static bool is32Or64BitBasicType(QualType Ty, ASTContext &Context) { // Treat complex types as the element type. - if (const ComplexType *CTy = Ty->getAs()) + if (const auto *CTy = Ty->getAs()) Ty = CTy->getElementType(); // Check for a type which we know has a simple scalar argument-passing @@ -1190,7 +1190,7 @@ if (!RT) return false; const RecordDecl *RD = RT->getDecl(); - if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) { + if (const auto *CXXRD = dyn_cast(RD)) { if (!IsWin32StructABI ) { // On non-Windows, we have to conservatively match our old bitcode // prototypes in order to be ABI-compatible at the bitcode level. @@ -1255,7 +1255,7 @@ return ABIArgInfo::getDirect(); } - if (const VectorType *VT = RetTy->getAs()) { + if (const auto *VT = RetTy->getAs()) { // On Darwin, some vectors are returned in registers. if (IsDarwinVectorABI) { uint64_t Size = getContext().getTypeSize(RetTy); @@ -1337,7 +1337,7 @@ const RecordDecl *RD = RT->getDecl(); // If this is a C++ record, check the bases first. - if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) + if (const auto *CXXRD = dyn_cast(RD)) for (const auto &I : CXXRD->bases()) if (!isRecordWithSSEVectorType(Context, I.getType())) return false; @@ -1570,7 +1570,7 @@ return getIndirectResult(Ty, true, State); } - if (const VectorType *VT = Ty->getAs()) { + if (const auto *VT = Ty->getAs()) { // On Darwin, some vectors are passed in memory, we handle this by passing // it as an i8/i16/i32/i64. if (IsDarwinVectorABI) { @@ -1789,10 +1789,10 @@ void X86_32TargetCodeGenInfo::setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM) const { - if (const FunctionDecl *FD = dyn_cast_or_null(D)) { + if (const auto *FD = dyn_cast_or_null(D)) { if (FD->hasAttr()) { // Get the LLVM function. - llvm::Function *Fn = cast(GV); + auto *Fn = cast(GV); // Now add the 'alignstack' attribute with a value of 16. llvm::AttrBuilder B; @@ -1803,7 +1803,7 @@ B)); } if (FD->hasAttr()) { - llvm::Function *Fn = cast(GV); + auto *Fn = cast(GV); Fn->setCallingConv(llvm::CallingConv::X86_INTR); } } @@ -2009,7 +2009,7 @@ /*isNamedArg*/true); if (info.isDirect()) { llvm::Type *ty = info.getCoerceToType(); - if (llvm::VectorType *vectorTy = dyn_cast_or_null(ty)) + if (auto *vectorTy = dyn_cast_or_null(ty)) return (vectorTy->getBitWidth() > 128); } return false; @@ -2148,9 +2148,9 @@ void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM) const override { - if (const FunctionDecl *FD = dyn_cast_or_null(D)) { + if (const auto *FD = dyn_cast_or_null(D)) { if (FD->hasAttr()) { - llvm::Function *Fn = cast(GV); + auto *Fn = cast(GV); Fn->setCallingConv(llvm::CallingConv::X86_INTR); } } @@ -2215,7 +2215,7 @@ CodeGen::CodeGenModule &CGM) { if (D && isa(D)) { if (CGM.getCodeGenOpts().StackProbeSize != 4096) { - llvm::Function *Fn = cast(GV); + auto *Fn = cast(GV); Fn->addFnAttr("stack-probe-size", llvm::utostr(CGM.getCodeGenOpts().StackProbeSize)); @@ -2272,9 +2272,9 @@ CodeGen::CodeGenModule &CGM) const { TargetCodeGenInfo::setTargetAttributes(D, GV, CGM); - if (const FunctionDecl *FD = dyn_cast_or_null(D)) { + if (const auto *FD = dyn_cast_or_null(D)) { if (FD->hasAttr()) { - llvm::Function *Fn = cast(GV); + auto *Fn = cast(GV); Fn->setCallingConv(llvm::CallingConv::X86_INTR); } } @@ -2435,7 +2435,7 @@ return; } - if (const VectorType *VT = Ty->getAs()) { + if (const auto *VT = Ty->getAs()) { uint64_t Size = getContext().getTypeSize(VT); if (Size == 1 || Size == 8 || Size == 16 || Size == 32) { // gcc passes the following as integer: @@ -2495,7 +2495,7 @@ return; } - if (const ComplexType *CT = Ty->getAs()) { + if (const auto *CT = Ty->getAs()) { QualType ET = getContext().getCanonicalType(CT->getElementType()); uint64_t Size = getContext().getTypeSize(Ty); @@ -2601,7 +2601,7 @@ Current = NoClass; // If this is a C++ record, classify the bases first. - if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) { + if (const auto *CXXRD = dyn_cast(RD)) { for (const auto &I : CXXRD->bases()) { assert(!I.isVirtual() && !I.getType()->isDependentType() && "Unexpected base class!"); @@ -2712,7 +2712,7 @@ } bool X86_64ABIInfo::IsIllegalVectorType(QualType Ty) const { - if (const VectorType *VecTy = Ty->getAs()) { + if (const auto *VecTy = Ty->getAs()) { uint64_t Size = getContext().getTypeSize(VecTy); unsigned LargestVector = getNativeVectorSizeForAVXABI(AVXLevel); if (Size <= 64 || Size > LargestVector) @@ -2816,13 +2816,13 @@ // If the bytes being queried are off the end of the type, there is no user // data hiding here. This handles analysis of builtins, vectors and other // types that don't contain interesting padding. - unsigned TySize = (unsigned)Context.getTypeSize(Ty); + auto TySize = (unsigned)Context.getTypeSize(Ty); if (TySize <= StartBit) return true; if (const ConstantArrayType *AT = Context.getAsConstantArrayType(Ty)) { unsigned EltSize = (unsigned)Context.getTypeSize(AT->getElementType()); - unsigned NumElts = (unsigned)AT->getSize().getZExtValue(); + auto NumElts = (unsigned)AT->getSize().getZExtValue(); // Check each element to see if the element overlaps with the queried range. for (unsigned i = 0; i != NumElts; ++i) { @@ -2844,7 +2844,7 @@ const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); // If this is a C++ record, check the bases first. - if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) { + if (const auto *CXXRD = dyn_cast(RD)) { for (const auto &I : CXXRD->bases()) { assert(!I.isVirtual() && !I.getType()->isDependentType() && "Unexpected base class!"); @@ -2869,7 +2869,7 @@ unsigned idx = 0; for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); i != e; ++i, ++idx) { - unsigned FieldOffset = (unsigned)Layout.getFieldOffset(idx); + auto FieldOffset = (unsigned)Layout.getFieldOffset(idx); // If we found a field after the region we care about, then we're done. if (FieldOffset >= EndBit) break; @@ -2899,7 +2899,7 @@ return true; // If this is a struct, recurse into the field at the specified offset. - if (llvm::StructType *STy = dyn_cast(IRType)) { + if (auto *STy = dyn_cast(IRType)) { const llvm::StructLayout *SL = TD.getStructLayout(STy); unsigned Elt = SL->getElementContainingOffset(IROffset); IROffset -= SL->getElementOffset(Elt); @@ -2907,7 +2907,7 @@ } // If this is an array, recurse into the field at the specified offset. - if (llvm::ArrayType *ATy = dyn_cast(IRType)) { + if (auto *ATy = dyn_cast(IRType)) { llvm::Type *EltTy = ATy->getElementType(); unsigned EltSize = TD.getTypeAllocSize(EltTy); IROffset -= IROffset/EltSize*EltSize; @@ -2984,7 +2984,7 @@ } } - if (llvm::StructType *STy = dyn_cast(IRType)) { + if (auto *STy = dyn_cast(IRType)) { // If this is a struct, recurse into the field at the specified offset. const llvm::StructLayout *SL = getDataLayout().getStructLayout(STy); if (IROffset < SL->getSizeInBytes()) { @@ -2996,7 +2996,7 @@ } } - if (llvm::ArrayType *ATy = dyn_cast(IRType)) { + if (auto *ATy = dyn_cast(IRType)) { llvm::Type *EltTy = ATy->getElementType(); unsigned EltSize = getDataLayout().getTypeAllocSize(EltTy); unsigned EltOffset = IROffset/EltSize*EltSize; @@ -3030,7 +3030,7 @@ // at offset 8. If the high and low parts we inferred are both 4-byte types // (e.g. i32 and i32) then the resultant struct type ({i32,i32}) won't have // the second element at offset 8. Check for this: - unsigned LoSize = (unsigned)TD.getTypeAllocSize(Lo); + auto LoSize = (unsigned)TD.getTypeAllocSize(Lo); unsigned HiAlign = TD.getABITypeAlignment(Hi); unsigned HiStart = llvm::alignTo(LoSize, HiAlign); assert(HiStart != 0 && HiStart <= 8 && "Invalid x86-64 argument pair!"); @@ -3558,7 +3558,7 @@ if (neededInt && neededSSE) { // FIXME: Cleanup. assert(AI.isDirect() && "Unexpected ABI info for mixed regs"); - llvm::StructType *ST = cast(AI.getCoerceToType()); + auto *ST = cast(AI.getCoerceToType()); Address Tmp = CGF.CreateMemTemp(Ty); Tmp = CGF.Builder.CreateElementBitCast(Tmp, ST); assert(ST->getNumElements() == 2 && "Unexpected ABI info for mixed regs"); @@ -3834,7 +3834,7 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAList, QualType Ty) const { const unsigned OverflowLimit = 8; - if (const ComplexType *CTy = Ty->getAs()) { + if (const auto *CTy = Ty->getAs()) { // TODO: Implement this. For now ignore. (void)CTy; return Address::invalid(); // FIXME? @@ -4040,7 +4040,7 @@ if (!HasQPX) return false; - if (const VectorType *VT = Ty->getAs()) { + if (const auto *VT = Ty->getAs()) { unsigned NumElements = VT->getNumElements(); if (NumElements == 1) return false; @@ -4173,7 +4173,7 @@ /// higher alignment in the parameter area. Always returns at least 8. CharUnits PPC64_SVR4_ABIInfo::getParamTypeAlignment(QualType Ty) const { // Complex types are passed just like their elements. - if (const ComplexType *CTy = Ty->getAs()) + if (const auto *CTy = Ty->getAs()) Ty = CTy->getElementType(); // Only vector types of size 16 bytes need alignment (larger types are @@ -4247,7 +4247,7 @@ Members = 0; // If this is a C++ record, check the bases first. - if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) { + if (const auto *CXXRD = dyn_cast(RD)) { for (const auto &I : CXXRD->bases()) { // Ignore empty records. if (isEmptyRecord(getContext(), I.getType(), true)) @@ -4295,7 +4295,7 @@ return false; } else { Members = 1; - if (const ComplexType *CT = Ty->getAs()) { + if (const auto *CT = Ty->getAs()) { Members = 2; Ty = CT->getElementType(); } @@ -4312,7 +4312,7 @@ Base = TyPtr; // If it's a non-power-of-2 vector, its size is already a power-of-2, // so make sure to widen it explicitly. - if (const VectorType *VT = Base->getAs()) { + if (const auto *VT = Base->getAs()) { QualType EltTy = VT->getElementType(); unsigned NumElements = getContext().getTypeSize(VT) / getContext().getTypeSize(EltTy); @@ -4341,7 +4341,7 @@ return true; } } - if (const VectorType *VT = Ty->getAs()) { + if (const auto *VT = Ty->getAs()) { if (getContext().getTypeSize(VT) == 128 || IsQPXVectorTy(Ty)) return true; } @@ -4499,7 +4499,7 @@ // pointer to a structure with the two parts packed tightly. So generate // loads of the real and imaginary parts relative to the va_list pointer, // and store them to a temporary structure. - if (const ComplexType *CTy = Ty->getAs()) { + if (const auto *CTy = Ty->getAs()) { CharUnits EltSize = TypeInfo.first / 2; if (EltSize < SlotSize) { Address Addr = emitVoidPtrDirectVAArg(CGF, VAListAddr, CGF.Int8Ty, @@ -4813,7 +4813,7 @@ /// isIllegalVectorType - check whether the vector type is legal for AArch64. bool AArch64ABIInfo::isIllegalVectorType(QualType Ty) const { - if (const VectorType *VT = Ty->getAs()) { + if (const auto *VT = Ty->getAs()) { // Check whether VT is legal. unsigned NumElements = VT->getNumElements(); uint64_t Size = getContext().getTypeSize(VT); @@ -4833,7 +4833,7 @@ if (const BuiltinType *BT = Ty->getAs()) { if (BT->isFloatingPoint()) return true; - } else if (const VectorType *VT = Ty->getAs()) { + } else if (const auto *VT = Ty->getAs()) { unsigned VecSize = getContext().getTypeSize(VT); if (VecSize == 64 || VecSize == 128) return true; @@ -4859,7 +4859,7 @@ BaseTy = AI.getCoerceToType(); unsigned NumRegs = 1; - if (llvm::ArrayType *ArrTy = dyn_cast(BaseTy)) { + if (auto *ArrTy = dyn_cast(BaseTy)) { BaseTy = ArrTy->getElementType(); NumRegs = ArrTy->getNumElements(); } @@ -5248,7 +5248,7 @@ void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM) const override { - const FunctionDecl *FD = dyn_cast_or_null(D); + const auto *FD = dyn_cast_or_null(D); if (!FD) return; @@ -5266,7 +5266,7 @@ case ARMInterruptAttr::UNDEF: Kind = "UNDEF"; break; } - llvm::Function *Fn = cast(GV); + auto *Fn = cast(GV); Fn->addFnAttr("interrupt", Kind); @@ -5536,7 +5536,7 @@ return true; // Small complex integer types are "integer like". - if (const ComplexType *CT = Ty->getAs()) + if (const auto *CT = Ty->getAs()) return isIntegerLikeType(CT->getElementType(), Context, VMContext); // Single element and zero sized arrays should be allowed, by the definition @@ -5703,7 +5703,7 @@ /// isIllegalVector - check whether Ty is an illegal vector type. bool ARMABIInfo::isIllegalVectorType(QualType Ty) const { - if (const VectorType *VT = Ty->getAs ()) { + if (const auto *VT = Ty->getAs()) { if (isAndroid()) { // Android shipped using Clang 3.1, which supported a slightly different // vector ABI. The primary differences were that 3-element vector types @@ -5736,7 +5736,7 @@ BT->getKind() == BuiltinType::Double || BT->getKind() == BuiltinType::LongDouble) return true; - } else if (const VectorType *VT = Ty->getAs()) { + } else if (const auto *VT = Ty->getAs()) { unsigned VecSize = getContext().getTypeSize(VT); if (VecSize == 64 || VecSize == 128) return true; @@ -5879,10 +5879,10 @@ void NVPTXTargetCodeGenInfo:: setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const{ - const FunctionDecl *FD = dyn_cast_or_null(D); + const auto *FD = dyn_cast_or_null(D); if (!FD) return; - llvm::Function *F = cast(GV); + auto *F = cast(GV); // Perform special handling in OpenCL mode if (M.getLangOpts().OpenCL) { @@ -5906,7 +5906,7 @@ // Create !{, metadata !"kernel", i32 1} node addNVVMMetadata(F, "kernel", 1); } - if (CUDALaunchBoundsAttr *Attr = FD->getAttr()) { + if (auto *Attr = FD->getAttr()) { // Create !{, metadata !"maxntidx", i32 } node llvm::APSInt MaxThreads(32); MaxThreads = Attr->getMaxThreads()->EvaluateKnownConstInt(M.getContext()); @@ -6046,7 +6046,7 @@ QualType Found; // If this is a C++ record, check the bases first. - if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) + if (const auto *CXXRD = dyn_cast(RD)) for (const auto &I : CXXRD->bases()) { QualType Base = I.getType(); @@ -6322,10 +6322,10 @@ void MSP430TargetCodeGenInfo::setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const { - if (const FunctionDecl *FD = dyn_cast_or_null(D)) { + if (const auto *FD = dyn_cast_or_null(D)) { if (const MSP430InterruptAttr *attr = FD->getAttr()) { // Handle 'interrupt' attribute: - llvm::Function *F = cast(GV); + auto *F = cast(GV); // Step 1: Set ISR calling convention. F->setCallingConv(llvm::CallingConv::MSP430_INTR); @@ -6381,9 +6381,9 @@ void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM) const override { - const FunctionDecl *FD = dyn_cast_or_null(D); + const auto *FD = dyn_cast_or_null(D); if (!FD) return; - llvm::Function *Fn = cast(GV); + auto *Fn = cast(GV); if (FD->hasAttr()) { Fn->addFnAttr("mips16"); } @@ -6748,10 +6748,10 @@ void TCETargetCodeGenInfo::setTargetAttributes( const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const { - const FunctionDecl *FD = dyn_cast_or_null(D); + const auto *FD = dyn_cast_or_null(D); if (!FD) return; - llvm::Function *F = cast(GV); + auto *F = cast(GV); if (M.getLangOpts().OpenCL) { if (FD->hasAttr()) { @@ -7066,7 +7066,7 @@ /// \brief Classify argument of given type \p Ty. ABIArgInfo AMDGPUABIInfo::classifyArgumentType(QualType Ty) const { - llvm::StructType *StrTy = dyn_cast(CGT.ConvertType(Ty)); + auto *StrTy = dyn_cast(CGT.ConvertType(Ty)); if (!StrTy) { return DefaultABIInfo::classifyArgumentType(Ty); } @@ -7101,11 +7101,11 @@ const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const { - const FunctionDecl *FD = dyn_cast_or_null(D); + const auto *FD = dyn_cast_or_null(D); if (!FD) return; - llvm::Function *F = cast(GV); + auto *F = cast(GV); if (const auto *Attr = FD->getAttr()) { unsigned Min = Attr->getMin(); @@ -7393,7 +7393,7 @@ // This is a small aggregate type that should be passed in registers. // Build a coercion type from the LLVM struct type. - llvm::StructType *StrTy = dyn_cast(CGT.ConvertType(Ty)); + auto *StrTy = dyn_cast(CGT.ConvertType(Ty)); if (!StrTy) return ABIArgInfo::getDirect(); @@ -8087,7 +8087,7 @@ if (AT->getSizeModifier() != ArrayType::Normal) return false; Enc += "a("; - if (const ConstantArrayType *CAT = dyn_cast(AT)) + if (const auto *CAT = dyn_cast(AT)) CAT->getSize().toStringUnsigned(Enc); else Enc += NoSizeEnc; // Global arrays use "*", otherwise it is "". @@ -8109,7 +8109,7 @@ if (!appendType(Enc, FT->getReturnType(), CGM, TSC)) return false; Enc += "}("; - if (const FunctionProtoType *FPT = FT->getAs()) { + if (const auto *FPT = FT->getAs()) { // N.B. we are only interested in the adjusted param types. auto I = FPT->param_type_begin(); auto E = FPT->param_type_end(); @@ -8152,7 +8152,7 @@ if (const BuiltinType *BT = QT->getAs()) return appendBuiltinType(Enc, BT); - if (const PointerType *PT = QT->getAs()) + if (const auto *PT = QT->getAs()) return appendPointerType(Enc, PT, CGM, TSC); if (const EnumType *ET = QT->getAs()) @@ -8164,7 +8164,7 @@ if (const RecordType *RT = QT->getAsUnionType()) return appendRecordType(Enc, RT, CGM, TSC, QT.getBaseTypeIdentifier()); - if (const FunctionType *FT = QT->getAs()) + if (const auto *FT = QT->getAs()) return appendFunctionType(Enc, FT, CGM, TSC); return false; @@ -8175,13 +8175,13 @@ if (!D) return false; - if (const FunctionDecl *FD = dyn_cast(D)) { + if (const auto *FD = dyn_cast(D)) { if (FD->getLanguageLinkage() != CLanguageLinkage) return false; return appendType(Enc, FD->getType(), CGM, TSC); } - if (const VarDecl *VD = dyn_cast(D)) { + if (const auto *VD = dyn_cast(D)) { if (VD->getLanguageLinkage() != CLanguageLinkage) return false; QualType QT = VD->getType().getCanonicalType(); Index: lib/CodeGen/VarBypassDetector.cpp =================================================================== --- lib/CodeGen/VarBypassDetector.cpp +++ lib/CodeGen/VarBypassDetector.cpp @@ -34,13 +34,13 @@ /// which vars are being bypassed. bool VarBypassDetector::BuildScopeInformation(const Decl *D, unsigned &ParentScope) { - const VarDecl *VD = dyn_cast(D); + const auto *VD = dyn_cast(D); if (VD && VD->hasLocalStorage()) { Scopes.push_back({ParentScope, VD}); ParentScope = Scopes.size() - 1; } - if (const VarDecl *VD = dyn_cast(D)) + if (const auto *VD = dyn_cast(D)) if (const Expr *Init = VD->getInit()) return BuildScopeInformation(Init, ParentScope); @@ -85,7 +85,7 @@ break; case Stmt::DeclStmtClass: { - const DeclStmt *DS = cast(S); + const auto *DS = cast(S); for (auto *I : DS->decls()) if (!BuildScopeInformation(I, origParentScope)) return false; @@ -115,9 +115,9 @@ // order to avoid blowing out the stack. while (true) { const Stmt *Next; - if (const SwitchCase *SC = dyn_cast(SubStmt)) + if (const auto *SC = dyn_cast(SubStmt)) Next = SC->getSubStmt(); - else if (const LabelStmt *LS = dyn_cast(SubStmt)) + else if (const auto *LS = dyn_cast(SubStmt)) Next = LS->getSubStmt(); else break; @@ -138,10 +138,10 @@ for (const auto &S : FromScopes) { const Stmt *St = S.first; unsigned from = S.second; - if (const GotoStmt *GS = dyn_cast(St)) { + if (const auto *GS = dyn_cast(St)) { if (const LabelStmt *LS = GS->getLabel()->getStmt()) Detect(from, ToScopes[LS]); - } else if (const SwitchStmt *SS = dyn_cast(St)) { + } else if (const auto *SS = dyn_cast(St)) { for (const SwitchCase *SC = SS->getSwitchCaseList(); SC; SC = SC->getNextSwitchCase()) { Detect(from, ToScopes[SC]); Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -224,7 +224,7 @@ } DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const { - DerivedArgList *DAL = new DerivedArgList(Args); + auto *DAL = new DerivedArgList(Args); bool HasNostdlib = Args.hasArg(options::OPT_nostdlib); bool HasNodefaultlib = Args.hasArg(options::OPT_nodefaultlibs); @@ -660,7 +660,7 @@ *UArgs, computeTargetTriple(*this, DefaultTargetTriple, *UArgs)); // The compilation takes ownership of Args. - Compilation *C = new Compilation(*this, TC, UArgs.release(), TranslatedArgs); + auto *C = new Compilation(*this, TC, UArgs.release(), TranslatedArgs); if (!HandleImmediateArgs(*C)) return C; @@ -1024,7 +1024,7 @@ // Remove result files if we're not saving temps. if (!isSaveTempsEnabled()) { - const JobAction *JA = cast(&FailingCommand->getSource()); + const auto *JA = cast(&FailingCommand->getSource()); C.CleanupFileMap(C.getResultFiles(), JA, true); // Failure result files are valid unless we crashed. @@ -1230,12 +1230,12 @@ llvm::raw_string_ostream os(str); os << Action::getClassName(A->getKind()) << ", "; - if (InputAction *IA = dyn_cast(A)) { + if (auto *IA = dyn_cast(A)) { os << "\"" << IA->getInputArg().getValue() << "\""; - } else if (BindArchAction *BIA = dyn_cast(A)) { + } else if (auto *BIA = dyn_cast(A)) { os << '"' << BIA->getArchName() << '"' << ", {" << PrintActions1(C, *BIA->input_begin(), Ids) << "}"; - } else if (OffloadAction *OA = dyn_cast(A)) { + } else if (auto *OA = dyn_cast(A)) { bool IsFirst = true; OA->doOnEachDependence( [&](Action *A, const ToolChain *TC, const char *BoundArch) { @@ -3097,7 +3097,7 @@ InputInfoList OffloadDependencesInputInfo; bool BuildingForOffloadDevice = TargetDeviceOffloadKind != Action::OFK_None; - if (const OffloadAction *OA = dyn_cast(A)) { + if (const auto *OA = dyn_cast(A)) { // The offload action is expected to be used in four different situations. // // a) Set a toolchain/architecture/kind for a host action: @@ -3152,7 +3152,7 @@ : OA->getHostDependence(); } - if (const InputAction *IA = dyn_cast(A)) { + if (const auto *IA = dyn_cast(A)) { // FIXME: It would be nice to not claim this here; maybe the old scheme of // just using Args was better? const Arg &Input = IA->getInputArg(); @@ -3164,7 +3164,7 @@ return InputInfo(A, &Input, /* BaseInput = */ ""); } - if (const BindArchAction *BAA = dyn_cast(A)) { + if (const auto *BAA = dyn_cast(A)) { const ToolChain *TC; StringRef ArchName = BAA->getArchName(); @@ -3183,7 +3183,7 @@ const ActionList *Inputs = &A->getInputs(); - const JobAction *JA = cast(A); + const auto *JA = cast(A); ActionList CollapsedOffloadActions; ToolSelector TS(JA, *TC, C, isSaveTempsEnabled(), embedBitcodeInObject()); Index: lib/Driver/MSVCToolChain.cpp =================================================================== --- lib/Driver/MSVCToolChain.cpp +++ lib/Driver/MSVCToolChain.cpp @@ -834,7 +834,7 @@ llvm::opt::DerivedArgList * MSVCToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch, Action::OffloadKind) const { - DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); + auto *DAL = new DerivedArgList(Args.getBaseArgs()); const OptTable &Opts = getDriver().getOpts(); // /Oy and /Oy- only has an effect under X86-32. Index: lib/Driver/ToolChains.cpp =================================================================== --- lib/Driver/ToolChains.cpp +++ lib/Driver/ToolChains.cpp @@ -818,7 +818,7 @@ DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch, Action::OffloadKind) const { - DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); + auto *DAL = new DerivedArgList(Args.getBaseArgs()); const OptTable &Opts = getDriver().getOpts(); // FIXME: We really want to get out of the tool chain level argument @@ -2993,7 +2993,7 @@ // user passed to the host. This is required because the runtime library // is required to load the device image dynamically at run time. if (DeviceOffloadKind == Action::OFK_OpenMP) { - DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); + auto *DAL = new DerivedArgList(Args.getBaseArgs()); const OptTable &Opts = getDriver().getOpts(); // Request the shared library. Given that these options are decided Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -9151,7 +9151,7 @@ const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { - const toolchains::FreeBSD &ToolChain = + const auto &ToolChain = static_cast(getToolChain()); const Driver &D = ToolChain.getDriver(); const llvm::Triple::ArchType Arch = ToolChain.getArch(); @@ -9967,7 +9967,7 @@ const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { - const toolchains::Linux &ToolChain = + const auto &ToolChain = static_cast(getToolChain()); const Driver &D = ToolChain.getDriver(); @@ -10234,7 +10234,7 @@ const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { - const toolchains::NaClToolChain &ToolChain = + const auto &ToolChain = static_cast(getToolChain()); InputInfo NaClMacros(types::TY_PP_Asm, ToolChain.GetNaClArmMacrosPath(), "nacl-arm-macros.s"); @@ -10255,7 +10255,7 @@ const ArgList &Args, const char *LinkingOutput) const { - const toolchains::NaClToolChain &ToolChain = + const auto &ToolChain = static_cast(getToolChain()); const Driver &D = ToolChain.getDriver(); const llvm::Triple::ArchType Arch = ToolChain.getArch(); @@ -10402,7 +10402,7 @@ const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { - const toolchains::Fuchsia &ToolChain = + const auto &ToolChain = static_cast(getToolChain()); const Driver &D = ToolChain.getDriver(); @@ -11747,7 +11747,7 @@ const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) { - const toolchains::FreeBSD &ToolChain = + const auto &ToolChain = static_cast(T.getToolChain()); const Driver &D = ToolChain.getDriver(); ArgStringList CmdArgs; @@ -11806,7 +11806,7 @@ const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) { - const toolchains::FreeBSD &ToolChain = + const auto &ToolChain = static_cast(T.getToolChain()); const Driver &D = ToolChain.getDriver(); ArgStringList CmdArgs; @@ -11982,7 +11982,7 @@ const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { - const toolchains::FreeBSD &ToolChain = + const auto &ToolChain = static_cast(getToolChain()); const Driver &D = ToolChain.getDriver(); bool PS4Linker; Index: lib/Driver/Types.cpp =================================================================== --- lib/Driver/Types.cpp +++ lib/Driver/Types.cpp @@ -236,7 +236,7 @@ types::ID types::lookupTypeForTypeSpecifier(const char *Name) { for (unsigned i=0; ifirst != Offs) return false; // position has been removed. @@ -132,7 +132,7 @@ SmallString<128> StrVec; FileOffset BeginOffs = InsertFromRangeOffs; FileOffset EndOffs = BeginOffs.getWithOffset(Len); - FileEditsTy::iterator I = FileEdits.upper_bound(BeginOffs); + auto I = FileEdits.upper_bound(BeginOffs); if (I != FileEdits.begin()) --I; @@ -186,7 +186,7 @@ return; FileOffset EndOffs = BeginOffs.getWithOffset(Len); - FileEditsTy::iterator I = FileEdits.upper_bound(BeginOffs); + auto I = FileEdits.upper_bound(BeginOffs); if (I != FileEdits.begin()) --I; @@ -203,8 +203,7 @@ FileEdit *TopFA = nullptr; if (I == FileEdits.end()) { - FileEditsTy::iterator - NewI = FileEdits.insert(I, std::make_pair(BeginOffs, FileEdit())); + auto NewI = FileEdits.insert(I, std::make_pair(BeginOffs, FileEdit())); NewI->second.RemoveLen = Len; return; } @@ -213,8 +212,7 @@ FileOffset B = I->first; FileOffset E = B.getWithOffset(FA.RemoveLen); if (BeginOffs < B) { - FileEditsTy::iterator - NewI = FileEdits.insert(I, std::make_pair(BeginOffs, FileEdit())); + auto NewI = FileEdits.insert(I, std::make_pair(BeginOffs, FileEdit())); TopBegin = BeginOffs; TopEnd = EndOffs; TopFA = &NewI->second; @@ -395,14 +393,14 @@ if (FileEdits.empty()) return; - FileEditsTy::iterator I = FileEdits.begin(); + auto I = FileEdits.begin(); CurOffs = I->first; StrVec = I->second.Text; CurLen = I->second.RemoveLen; CurEnd = CurOffs.getWithOffset(CurLen); ++I; - for (FileEditsTy::iterator E = FileEdits.end(); I != E; ++I) { + for (auto E = FileEdits.end(); I != E; ++I) { FileOffset offs = I->first; FileEdit act = I->second; assert(offs >= CurEnd); @@ -444,7 +442,7 @@ EditedSource::FileEditsTy::iterator EditedSource::getActionForOffset(FileOffset Offs) { - FileEditsTy::iterator I = FileEdits.upper_bound(Offs); + auto I = FileEdits.upper_bound(Offs); if (I == FileEdits.begin()) return FileEdits.end(); --I; Index: lib/Edit/RewriteObjCFoundationAPI.cpp =================================================================== --- lib/Edit/RewriteObjCFoundationAPI.cpp +++ lib/Edit/RewriteObjCFoundationAPI.cpp @@ -41,8 +41,8 @@ // since the change from +1 to +0 will be handled fine by ARC. if (LangOpts.ObjCAutoRefCount) { if (Msg->getReceiverKind() == ObjCMessageExpr::Instance) { - if (const ObjCMessageExpr *Rec = dyn_cast( - Msg->getInstanceReceiver()->IgnoreParenImpCasts())) { + if (const auto *Rec = dyn_cast( + Msg->getInstanceReceiver()->IgnoreParenImpCasts())) { if (Rec->getMethodFamily() == OMF_alloc) return true; } @@ -115,8 +115,8 @@ if (!Ctx.isObjCIdType(Receiver->getType().getUnqualifiedType())) return IFace; - const ObjCMessageExpr * - InnerMsg = dyn_cast(Receiver->IgnoreParenCasts()); + const auto *InnerMsg = + dyn_cast(Receiver->IgnoreParenCasts()); if (!InnerMsg) return IFace; @@ -139,7 +139,7 @@ // ...and it is the result of a class message... - const ObjCObjectType *ObjTy = ClassRec->getAs(); + const auto *ObjTy = ClassRec->getAs(); if (!ObjTy) return IFace; const ObjCInterfaceDecl *OID = ObjTy->getInterface(); @@ -379,7 +379,7 @@ const NSAPI &NS, Commit &commit, const ParentMap *PMap) { if (PMap) { - const ObjCMessageExpr *ParentMsg = + const auto *ParentMsg = dyn_cast_or_null(PMap->getParentIgnoreParenCasts(Msg)); if (shouldNotRewriteImmediateMessageArgs(ParentMsg, NS)) return false; @@ -446,7 +446,7 @@ if (!E) return false; - if (const ObjCMessageExpr *Msg = dyn_cast(E)) { + if (const auto *Msg = dyn_cast(E)) { IdentifierInfo *Cls = nullptr; if (!checkForLiteralCreation(Msg, Cls, NS.getASTContext().getLangOpts())) return false; @@ -478,7 +478,7 @@ return true; } - } else if (const ObjCArrayLiteral *ArrLit = dyn_cast(E)) { + } else if (const auto *ArrLit = dyn_cast(E)) { for (unsigned i = 0, e = ArrLit->getNumElements(); i != e; ++i) Objs.push_back(ArrLit->getElement(i)); return true; @@ -757,15 +757,15 @@ return false; const Expr *Arg = Msg->getArg(0)->IgnoreParenImpCasts(); - if (const CharacterLiteral *CharE = dyn_cast(Arg)) + if (const auto *CharE = dyn_cast(Arg)) return rewriteToCharLiteral(Msg, CharE, NS, commit); - if (const ObjCBoolLiteralExpr *BE = dyn_cast(Arg)) + if (const auto *BE = dyn_cast(Arg)) return rewriteToBoolLiteral(Msg, BE, NS, commit); - if (const CXXBoolLiteralExpr *BE = dyn_cast(Arg)) + if (const auto *BE = dyn_cast(Arg)) return rewriteToBoolLiteral(Msg, BE, NS, commit); const Expr *literalE = Arg; - if (const UnaryOperator *UOE = dyn_cast(literalE)) { + if (const auto *UOE = dyn_cast(literalE)) { if (UOE->getOpcode() == UO_Plus || UOE->getOpcode() == UO_Minus) literalE = UOE->getSubExpr(); } @@ -850,7 +850,7 @@ LiteralInfo LitInfo; bool isIntZero = false; - if (const IntegerLiteral *IntE = dyn_cast(literalE)) + if (const auto *IntE = dyn_cast(literalE)) isIntZero = !IntE->getValue().getBoolValue(); if (!getLiteralInfo(ArgRange, LitIsFloat, isIntZero, Ctx, LitInfo)) return rewriteToNumericBoxedExpression(Msg, NS, commit); @@ -942,7 +942,7 @@ QualType T = E->getType(); if (T->isObjCObjectPointerType()) { - if (const ImplicitCastExpr *ICE = dyn_cast(E)) { + if (const auto *ICE = dyn_cast(E)) { if (ICE->getCastKind() != CK_CPointerToObjCPointerCast) return; } else { @@ -963,7 +963,7 @@ //===----------------------------------------------------------------------===// static bool isEnumConstant(const Expr *E) { - if (const DeclRefExpr *DRE = dyn_cast(E->IgnoreParenImpCasts())) + if (const auto *DRE = dyn_cast(E->IgnoreParenImpCasts())) if (const ValueDecl *VD = DRE->getDecl()) return isa(VD); @@ -996,7 +996,7 @@ bool isTruncated = FinalTySize < OrigTySize; bool needsCast = false; - if (const ImplicitCastExpr *ICE = dyn_cast(Arg)) { + if (const auto *ICE = dyn_cast(Arg)) { switch (ICE->getCastKind()) { case CK_LValueToRValue: case CK_NoOp: @@ -1123,14 +1123,13 @@ if (OrigTy->isArrayType()) OrigTy = Ctx.getArrayDecayedType(OrigTy); - if (const StringLiteral * - StrE = dyn_cast(OrigArg->IgnoreParens())) { + if (const auto *StrE = dyn_cast(OrigArg->IgnoreParens())) { commit.replaceWithInner(Msg->getSourceRange(), StrE->getSourceRange()); commit.insert(StrE->getLocStart(), "@"); return true; } - if (const PointerType *PT = OrigTy->getAs()) { + if (const auto *PT = OrigTy->getAs()) { QualType PointeeType = PT->getPointeeType(); if (Ctx.hasSameUnqualifiedType(PointeeType, Ctx.CharTy)) { SourceRange ArgRange = OrigArg->getSourceRange(); Index: lib/Format/Encoding.h =================================================================== --- lib/Format/Encoding.h +++ lib/Format/Encoding.h @@ -33,8 +33,8 @@ /// \brief Detects encoding of the Text. If the Text can be decoded using UTF-8, /// it is considered UTF8, otherwise we treat it as some 8-bit encoding. inline Encoding detectEncoding(StringRef Text) { - const llvm::UTF8 *Ptr = reinterpret_cast(Text.begin()); - const llvm::UTF8 *BufEnd = reinterpret_cast(Text.end()); + const auto *Ptr = reinterpret_cast(Text.begin()); + const auto *BufEnd = reinterpret_cast(Text.end()); if (llvm::isLegalUTF8String(&Ptr, BufEnd)) return Encoding_UTF8; return Encoding_Unknown; Index: lib/Format/TokenAnalyzer.cpp =================================================================== --- lib/Format/TokenAnalyzer.cpp +++ lib/Format/TokenAnalyzer.cpp @@ -111,9 +111,7 @@ DEBUG({ llvm::dbgs() << "Replacements for run " << Run << ":\n"; - for (tooling::Replacements::const_iterator I = RunResult.begin(), - E = RunResult.end(); - I != E; ++I) { + for (auto I = RunResult.begin(), E = RunResult.end(); I != E; ++I) { llvm::dbgs() << I->toString() << "\n"; } }); Index: lib/Format/TokenAnnotator.h =================================================================== --- lib/Format/TokenAnnotator.h +++ lib/Format/TokenAnnotator.h @@ -50,9 +50,7 @@ // left them in a different state. First->Previous = nullptr; FormatToken *Current = First; - for (std::list::const_iterator I = ++Line.Tokens.begin(), - E = Line.Tokens.end(); - I != E; ++I) { + for (auto I = ++Line.Tokens.begin(), E = Line.Tokens.end(); I != E; ++I) { const UnwrappedLineNode &Node = *I; Current->Next = I->Tok; I->Tok->Previous = Current; Index: lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- lib/Format/UnwrappedLineFormatter.cpp +++ lib/Format/UnwrappedLineFormatter.cpp @@ -691,7 +691,7 @@ QueueType Queue; // Insert start element into queue. - StateNode *Node = + auto *Node = new (Allocator.Allocate()) StateNode(InitialState, false, nullptr); Queue.push(QueueItem(OrderedPenalty(0, Count), Node)); ++Count; @@ -752,7 +752,7 @@ if (!NewLine && Indenter->mustBreak(PreviousNode->State)) return; - StateNode *Node = new (Allocator.Allocate()) + auto *Node = new (Allocator.Allocate()) StateNode(PreviousNode->State, NewLine, PreviousNode); if (!formatChildren(Node->State, NewLine, /*DryRun=*/true, Penalty)) return; @@ -772,8 +772,7 @@ Path.push_front(Best); Best = Best->Previous; } - for (std::deque::iterator I = Path.begin(), E = Path.end(); - I != E; ++I) { + for (auto I = Path.begin(), E = Path.end(); I != E; ++I) { unsigned Penalty = 0; formatChildren(State, (*I)->NewLine, /*DryRun=*/false, Penalty); Penalty += Indenter->addTokenToState(State, (*I)->NewLine, false); Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -1985,14 +1985,10 @@ StringRef Prefix = "") { llvm::dbgs() << Prefix << "Line(" << Line.Level << ")" << (Line.InPPDirective ? " MACRO" : "") << ": "; - for (std::list::const_iterator I = Line.Tokens.begin(), - E = Line.Tokens.end(); - I != E; ++I) { + for (auto I = Line.Tokens.begin(), E = Line.Tokens.end(); I != E; ++I) { llvm::dbgs() << I->Tok->Tok.getName() << "[" << I->Tok->Type << "] "; } - for (std::list::const_iterator I = Line.Tokens.begin(), - E = Line.Tokens.end(); - I != E; ++I) { + for (auto I = Line.Tokens.begin(), E = Line.Tokens.end(); I != E; ++I) { const UnwrappedLineNode &Node = *I; for (SmallVectorImpl::const_iterator I = Node.Children.begin(), Index: lib/Frontend/ASTConsumers.cpp =================================================================== --- lib/Frontend/ASTConsumers.cpp +++ lib/Frontend/ASTConsumers.cpp @@ -78,7 +78,7 @@ } void print(Decl *D) { if (DumpLookups) { - if (DeclContext *DC = dyn_cast(D)) { + if (auto *DC = dyn_cast(D)) { if (DC == DC->getPrimaryContext()) DC->dumpLookups(Out, Dump); else @@ -205,12 +205,12 @@ break; case Decl::Namespace: { Out << "[namespace] "; - const NamespaceDecl* ND = cast(DC); + const auto *ND = cast(DC); Out << *ND; break; } case Decl::Enum: { - const EnumDecl* ED = cast(DC); + const auto *ED = cast(DC); if (ED->isCompleteDefinition()) Out << "[enum] "; else @@ -219,7 +219,7 @@ break; } case Decl::Record: { - const RecordDecl* RD = cast(DC); + const auto *RD = cast(DC); if (RD->isCompleteDefinition()) Out << "[struct] "; else @@ -228,7 +228,7 @@ break; } case Decl::CXXRecord: { - const CXXRecordDecl* RD = cast(DC); + const auto *RD = cast(DC); if (RD->isCompleteDefinition()) Out << "[class] "; else @@ -261,7 +261,7 @@ Out << "[block]"; break; case Decl::Function: { - const FunctionDecl* FD = cast(DC); + const auto *FD = cast(DC); if (FD->doesThisDeclarationHaveABody()) Out << "[function] "; else @@ -281,7 +281,7 @@ break; } case Decl::CXXMethod: { - const CXXMethodDecl* D = cast(DC); + const auto *D = cast(DC); if (D->isOutOfLine()) Out << "[c++ method] "; else if (D->isImplicit()) @@ -310,7 +310,7 @@ break; } case Decl::CXXConstructor: { - const CXXConstructorDecl* D = cast(DC); + const auto *D = cast(DC); if (D->isOutOfLine()) Out << "[c++ ctor] "; else if (D->isImplicit()) @@ -338,7 +338,7 @@ break; } case Decl::CXXDestructor: { - const CXXDestructorDecl* D = cast(DC); + const auto *D = cast(DC); if (D->isOutOfLine()) Out << "[c++ dtor] "; else if (D->isImplicit()) @@ -354,7 +354,7 @@ break; } case Decl::CXXConversion: { - const CXXConversionDecl* D = cast(DC); + const auto *D = cast(DC); if (D->isOutOfLine()) Out << "[c++ conversion] "; else if (D->isImplicit()) @@ -401,58 +401,58 @@ case Decl::CXXDestructor: case Decl::CXXConversion: { - DeclContext* DC = cast(I); + auto *DC = cast(I); PrintDeclContext(DC, Indentation+2); break; } case Decl::IndirectField: { - IndirectFieldDecl* IFD = cast(I); + auto *IFD = cast(I); Out << " " << *IFD << '\n'; break; } case Decl::Label: { - LabelDecl *LD = cast(I); + auto *LD = cast(I); Out << "