From 98ca9434cfa9807cc57527f0b602e89f6c2ef77a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 9 May 2014 00:08:36 +0000 Subject: [PATCH] Use auto to avoid duplicating the type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208374 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGBlocks.cpp | 8 +- lib/CodeGen/CGCXX.cpp | 18 ++-- lib/CodeGen/CGExpr.cpp | 122 +++++++++++++------------- lib/CodeGen/CodeGenModule.cpp | 157 ++++++++++++++++------------------ 4 files changed, 145 insertions(+), 160 deletions(-) diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 165f7eac2a..941410a741 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -246,7 +246,7 @@ static bool isSafeForCXXConstantCapture(QualType type) { // Only records can be unsafe. if (!recordType) return true; - const CXXRecordDecl *record = cast(recordType->getDecl()); + const auto *record = cast(recordType->getDecl()); // Maintain semantics for classes with non-trivial dtors or copy ctors. if (!record->hasTrivialDestructor()) return false; @@ -1093,7 +1093,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, // to be local to this function as well, in case they're directly // referenced in a block. for (DeclMapTy::const_iterator i = ldm.begin(), e = ldm.end(); i != e; ++i) { - const VarDecl *var = dyn_cast(i->first); + const auto *var = dyn_cast(i->first); if (var && !var->hasLocalStorage()) LocalDeclMap[var] = i->second; } @@ -1396,7 +1396,7 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) { // storeStrong doesn't over-release) and then call storeStrong. // This is a workaround to not having an initStrong call. if (CGM.getCodeGenOpts().OptimizationLevel == 0) { - llvm::PointerType *ty = cast(srcValue->getType()); + auto *ty = cast(srcValue->getType()); llvm::Value *null = llvm::ConstantPointerNull::get(ty); Builder.CreateStore(null, dstField); EmitARCStoreStrongCall(dstField, srcValue, true); @@ -2231,7 +2231,7 @@ static void configureBlocksRuntimeObject(CodeGenModule &CGM, llvm::Constant *C) { if (!CGM.getLangOpts().BlocksRuntimeOptional) return; - llvm::GlobalValue *GV = cast(C->stripPointerCasts()); + auto *GV = cast(C->stripPointerCasts()); if (GV->isDeclaration() && GV->hasExternalLinkage()) GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); } diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index d2b6276347..f13bf26f55 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -68,8 +68,8 @@ bool CodeGenModule::TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) { if (I.isVirtual()) continue; // Skip base classes with trivial destructors. - const CXXRecordDecl *Base - = cast(I.getType()->getAs()->getDecl()); + const auto *Base = + cast(I.getType()->getAs()->getDecl()); if (Base->hasTrivialDestructor()) continue; // If we've already found a base class with a non-trivial @@ -137,7 +137,7 @@ bool CodeGenModule::TryEmitDefinitionAsAlias(GlobalDecl AliasDecl, // Find the referent. Some aliases might require a bitcast, in // which case the caller is responsible for ensuring the soundness // of these semantics. - llvm::GlobalValue *Ref = cast(GetAddrOfGlobal(TargetDecl)); + auto *Ref = cast(GetAddrOfGlobal(TargetDecl)); llvm::Constant *Aliasee = Ref; if (Ref->getType() != AliasType) Aliasee = llvm::ConstantExpr::getBitCast(Ref, AliasType); @@ -211,7 +211,7 @@ void CodeGenModule::EmitCXXConstructor(const CXXConstructorDecl *ctor, const CGFunctionInfo &fnInfo = getTypes().arrangeCXXConstructorDeclaration(ctor, ctorType); - llvm::Function *fn = cast( + auto *fn = cast( GetAddrOfCXXConstructor(ctor, ctorType, &fnInfo, true)); setFunctionLinkage(GlobalDecl(ctor, ctorType), fn); @@ -268,7 +268,7 @@ void CodeGenModule::EmitCXXDestructor(const CXXDestructorDecl *dtor, const CGFunctionInfo &fnInfo = getTypes().arrangeCXXDestructor(dtor, dtorType); - llvm::Function *fn = cast( + auto *fn = cast( GetAddrOfCXXDestructor(dtor, dtorType, &fnInfo, 0, true)); setFunctionLinkage(GlobalDecl(dtor, dtorType), fn); @@ -335,9 +335,9 @@ CodeGenFunction::BuildAppleKextVirtualCall(const CXXMethodDecl *MD, QualType T = QualType(QTy, 0); const RecordType *RT = T->getAs(); assert(RT && "BuildAppleKextVirtualCall - Qual type must be record"); - const CXXRecordDecl *RD = cast(RT->getDecl()); - - if (const CXXDestructorDecl *DD = dyn_cast(MD)) + const auto *RD = cast(RT->getDecl()); + + if (const auto *DD = dyn_cast(MD)) return BuildAppleKextVirtualDestructorCall(DD, Dtor_Complete, RD); return ::BuildAppleKextVirtualCall(*this, MD, Ty, RD); @@ -350,7 +350,7 @@ CodeGenFunction::BuildAppleKextVirtualDestructorCall( const CXXDestructorDecl *DD, CXXDtorType Type, const CXXRecordDecl *RD) { - const CXXMethodDecl *MD = cast(DD); + const auto *MD = cast(DD); // FIXME. Dtor_Base dtor is always direct!! // It need be somehow inline expanded into the caller. // -O does that. But need to support -O0 as well. diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index badde1b7c9..40870f8906 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -59,7 +59,7 @@ llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, void CodeGenFunction::InitTempAlloca(llvm::AllocaInst *Var, llvm::Value *Init) { - llvm::StoreInst *Store = new llvm::StoreInst(Init, Var); + auto *Store = new llvm::StoreInst(Init, Var); llvm::BasicBlock *Block = AllocaInsertPt->getParent(); Block->getInstList().insertAfter(&*AllocaInsertPt, Store); } @@ -245,7 +245,7 @@ pushTemporaryCleanup(CodeGenFunction &CGF, const MaterializeTemporaryExpr *M, if (const RecordType *RT = E->getType()->getBaseElementTypeUnsafe()->getAs()) { // Get the destructor for the reference temporary. - CXXRecordDecl *ClassDecl = cast(RT->getDecl()); + auto *ClassDecl = cast(RT->getDecl()); if (!ClassDecl->hasTrivialDestructor()) ReferenceTemporaryDtor = ClassDecl->getDestructor(); } @@ -323,7 +323,7 @@ LValue CodeGenFunction::EmitMaterializeTemporaryExpr( llvm::Value *Object = createReferenceTemporary(*this, M, E); LValue RefTempDst = MakeAddrLValue(Object, M->getType()); - if (llvm::GlobalVariable *Var = dyn_cast(Object)) { + if (auto *Var = dyn_cast(Object)) { // We should not have emitted the initializer for this temporary as a // constant. assert(!Var->hasInitializer()); @@ -343,7 +343,7 @@ LValue CodeGenFunction::EmitMaterializeTemporaryExpr( for (unsigned I = 0, N = CommaLHSs.size(); I != N; ++I) EmitIgnoredExpr(CommaLHSs[I]); - if (const OpaqueValueExpr *opaque = dyn_cast(E)) { + if (const auto *opaque = dyn_cast(E)) { if (opaque->getType()->isRecordType()) { assert(Adjustments.empty()); return EmitOpaqueValueLValue(opaque); @@ -352,7 +352,7 @@ LValue CodeGenFunction::EmitMaterializeTemporaryExpr( // Create and initialize the reference temporary. llvm::Value *Object = createReferenceTemporary(*this, M, E); - if (llvm::GlobalVariable *Var = dyn_cast(Object)) { + if (auto *Var = dyn_cast(Object)) { // If the temporary is a global and has a constant initializer, we may // have already initialized it. if (!Var->hasInitializer()) { @@ -590,7 +590,7 @@ static bool isFlexibleArrayMemberExpr(const Expr *E) { // For compatibility with existing code, we treat arrays of length 0 or // 1 as flexible array members. const ArrayType *AT = E->getType()->castAsArrayTypeUnsafe(); - if (const ConstantArrayType *CAT = dyn_cast(AT)) { + if (const auto *CAT = dyn_cast(AT)) { if (CAT->getSize().ugt(1)) return false; } else if (!isa(AT)) @@ -599,10 +599,10 @@ static bool isFlexibleArrayMemberExpr(const Expr *E) { E = E->IgnoreParens(); // A flexible array member must be the last member in the class. - if (const MemberExpr *ME = dyn_cast(E)) { + if (const auto *ME = dyn_cast(E)) { // FIXME: If the base type of the member expr is not FD->getParent(), // this should not be treated as a flexible array member access. - if (const FieldDecl *FD = dyn_cast(ME->getMemberDecl())) { + if (const auto *FD = dyn_cast(ME->getMemberDecl())) { RecordDecl::field_iterator FI( DeclContext::decl_iterator(const_cast(FD))); return ++FI == FD->getParent()->field_end(); @@ -624,14 +624,14 @@ static llvm::Value *getArrayIndexingBound( Base = Base->IgnoreParens(); - if (const CastExpr *CE = dyn_cast(Base)) { + if (const auto *CE = dyn_cast(Base)) { if (CE->getCastKind() == CK_ArrayToPointerDecay && !isFlexibleArrayMemberExpr(CE->getSubExpr())) { IndexedType = CE->getSubExpr()->getType(); const ArrayType *AT = IndexedType->castAsArrayTypeUnsafe(); - if (const ConstantArrayType *CAT = dyn_cast(AT)) + if (const auto *CAT = dyn_cast(AT)) return CGF.Builder.getInt(CAT->getSize()); - else if (const VariableArrayType *VAT = dyn_cast(AT)) + else if (const auto *VAT = dyn_cast(AT)) return CGF.getVLASize(VAT).first; } } @@ -820,7 +820,7 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) { return EmitLambdaLValue(cast(E)); case Expr::ExprWithCleanupsClass: { - const ExprWithCleanups *cleanups = cast(E); + const auto *cleanups = cast(E); enterFullExpression(cleanups); RunCleanupsScope Scope(*this); return EmitLValue(cleanups->getSubExpr()); @@ -888,8 +888,8 @@ static bool isConstantEmittableObjectType(QualType type) { // Otherwise, all object types satisfy this except C++ classes with // mutable subobjects or non-trivial copy/destroy behavior. - if (const RecordType *RT = dyn_cast(type)) - if (const CXXRecordDecl *RD = dyn_cast(RT->getDecl())) + if (const auto *RT = dyn_cast(type)) + if (const auto *RD = dyn_cast(RT->getDecl())) if (RD->hasMutableFields() || !RD->isTrivial()) return false; @@ -911,7 +911,7 @@ enum ConstantEmissionKind { }; static ConstantEmissionKind checkVarTypeForConstantEmission(QualType type) { type = type.getCanonicalType(); - if (const ReferenceType *ref = dyn_cast(type)) { + if (const auto *ref = dyn_cast(type)) { if (isConstantEmittableObjectType(ref->getPointeeType())) return CEK_AsValueOrReference; return CEK_AsReferenceOnly; @@ -934,7 +934,7 @@ CodeGenFunction::tryEmitAsConstant(DeclRefExpr *refExpr) { ConstantEmissionKind CEK; if (isa(value)) { CEK = CEK_None; - } else if (VarDecl *var = dyn_cast(value)) { + } else if (auto *var = dyn_cast(value)) { CEK = checkVarTypeForConstantEmission(var->getType()); } else if (isa(value)) { CEK = CEK_AsValueOnly; @@ -1065,7 +1065,7 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, const llvm::Type *EltTy = cast(Addr->getType())->getElementType(); - const llvm::VectorType *VTy = cast(EltTy); + const auto *VTy = cast(EltTy); // Handle vectors of size 3, like size 4 for better performance. if (VTy->getNumElements() == 3) { @@ -1181,7 +1181,7 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, // Handle vectors differently to get better performance. if (Ty->isVectorType()) { llvm::Type *SrcTy = Value->getType(); - llvm::VectorType *VecTy = cast(SrcTy); + auto *VecTy = cast(SrcTy); // Handle vec3 special. if (VecTy->getNumElements() == 3) { llvm::LLVMContext &VMContext = getLLVMContext(); @@ -1202,7 +1202,7 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, MaskV, "extractVec"); SrcTy = llvm::VectorType::get(VecTy->getElementType(), 4); } - llvm::PointerType *DstPtr = cast(Addr->getType()); + auto *DstPtr = cast(Addr->getType()); if (DstPtr->getElementType() != SrcTy) { llvm::Type *MemTy = llvm::PointerType::get(SrcTy, DstPtr->getAddressSpace()); @@ -1603,14 +1603,14 @@ static void setObjCGCLValueClass(const ASTContext &Ctx, const Expr *E, } } LV.setObjCIvar(true); - ObjCIvarRefExpr *Exp = cast(const_cast(E)); + auto *Exp = cast(const_cast(E)); LV.setBaseIvarExp(Exp->getBase()); LV.setObjCArray(E->getType()->isArrayType()); return; } - if (const DeclRefExpr *Exp = dyn_cast(E)) { - if (const VarDecl *VD = dyn_cast(Exp->getDecl())) { + if (const auto *Exp = dyn_cast(E)) { + if (const auto *VD = dyn_cast(Exp->getDecl())) { if (VD->hasGlobalStorage()) { LV.setGlobalObjCRef(true); LV.setThreadLocalRef(VD->getTLSKind() != VarDecl::TLS_None); @@ -1620,12 +1620,12 @@ static void setObjCGCLValueClass(const ASTContext &Ctx, const Expr *E, return; } - if (const UnaryOperator *Exp = dyn_cast(E)) { + if (const auto *Exp = dyn_cast(E)) { setObjCGCLValueClass(Ctx, Exp->getSubExpr(), LV, IsMemberAccess); return; } - if (const ParenExpr *Exp = dyn_cast(E)) { + if (const auto *Exp = dyn_cast(E)) { setObjCGCLValueClass(Ctx, Exp->getSubExpr(), LV, IsMemberAccess); if (LV.isObjCIvar()) { // If cast is to a structure pointer, follow gcc's behavior and make it @@ -1639,27 +1639,27 @@ static void setObjCGCLValueClass(const ASTContext &Ctx, const Expr *E, return; } - if (const GenericSelectionExpr *Exp = dyn_cast(E)) { + if (const auto *Exp = dyn_cast(E)) { setObjCGCLValueClass(Ctx, Exp->getResultExpr(), LV); return; } - if (const ImplicitCastExpr *Exp = dyn_cast(E)) { + if (const auto *Exp = dyn_cast(E)) { setObjCGCLValueClass(Ctx, Exp->getSubExpr(), LV, IsMemberAccess); return; } - if (const CStyleCastExpr *Exp = dyn_cast(E)) { + if (const auto *Exp = dyn_cast(E)) { setObjCGCLValueClass(Ctx, Exp->getSubExpr(), LV, IsMemberAccess); return; } - if (const ObjCBridgedCastExpr *Exp = dyn_cast(E)) { + if (const auto *Exp = dyn_cast(E)) { setObjCGCLValueClass(Ctx, Exp->getSubExpr(), LV, IsMemberAccess); return; } - if (const ArraySubscriptExpr *Exp = dyn_cast(E)) { + if (const auto *Exp = dyn_cast(E)) { setObjCGCLValueClass(Ctx, Exp->getBase(), LV); if (LV.isObjCIvar() && !LV.isObjCArray()) // Using array syntax to assigning to what an ivar points to is not @@ -1672,7 +1672,7 @@ static void setObjCGCLValueClass(const ASTContext &Ctx, const Expr *E, return; } - if (const MemberExpr *Exp = dyn_cast(E)) { + if (const auto *Exp = dyn_cast(E)) { setObjCGCLValueClass(Ctx, Exp->getBase(), LV, true); // We don't know if member is an 'ivar', but this flag is looked at // only in the context of LV.isObjCIvar(). @@ -1747,7 +1747,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { // A DeclRefExpr for a reference initialized by a constant expression can // appear without being odr-used. Directly emit the constant initializer. - if (const VarDecl *VD = dyn_cast(ND)) { + if (const auto *VD = dyn_cast(ND)) { const Expr *Init = VD->getAnyInitializer(VD); if (Init && !isa(VD) && VD->getType()->isReferenceType() && VD->isUsableInConstantExpressions(getContext()) && @@ -1768,12 +1768,12 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { "Should not use decl without marking it used!"); if (ND->hasAttr()) { - const ValueDecl *VD = cast(ND); + const auto *VD = cast(ND); llvm::Constant *Aliasee = CGM.GetWeakRefReference(VD); return MakeAddrLValue(Aliasee, T, Alignment); } - if (const VarDecl *VD = dyn_cast(ND)) { + if (const auto *VD = dyn_cast(ND)) { // Check if this is a global variable. if (VD->hasLinkage() || VD->isStaticDataMember()) return EmitGlobalVarDeclLValue(*this, E, VD); @@ -1832,7 +1832,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { return LV; } - if (const FunctionDecl *FD = dyn_cast(ND)) + if (const auto *FD = dyn_cast(ND)) return EmitFunctionDeclLValue(*this, E, FD); llvm_unreachable("Unhandled DeclRefExpr"); @@ -1922,11 +1922,9 @@ GetAddrOfConstantWideString(StringRef Str, /*Pascal = */false, Ty, Loc); llvm::Constant *C = CGM.GetConstantArrayFromStringLiteral(SL); - llvm::GlobalVariable *GV = - new llvm::GlobalVariable(CGM.getModule(), C->getType(), - !CGM.getLangOpts().WritableStrings, - llvm::GlobalValue::PrivateLinkage, - C, GlobalName); + auto *GV = new llvm::GlobalVariable( + CGM.getModule(), C->getType(), !CGM.getLangOpts().WritableStrings, + llvm::GlobalValue::PrivateLinkage, C, GlobalName); const unsigned WideAlignment = Context.getTypeAlignInChars(Ty).getQuantity(); GV->setAlignment(WideAlignment); @@ -2057,11 +2055,9 @@ llvm::Constant *CodeGenFunction::EmitCheckTypeDescriptor(QualType T) { }; llvm::Constant *Descriptor = llvm::ConstantStruct::getAnon(Components); - llvm::GlobalVariable *GV = - new llvm::GlobalVariable(CGM.getModule(), Descriptor->getType(), - /*isConstant=*/true, - llvm::GlobalVariable::PrivateLinkage, - Descriptor); + auto *GV = new llvm::GlobalVariable( + CGM.getModule(), Descriptor->getType(), + /*isConstant=*/true, llvm::GlobalVariable::PrivateLinkage, Descriptor); GV->setUnnamedAddr(true); // Remember the descriptor for this type. @@ -2145,7 +2141,7 @@ void CodeGenFunction::EmitCheck(llvm::Value *Checked, StringRef CheckName, EmitBlock(Handler); llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs); - llvm::GlobalValue *InfoPtr = + auto *InfoPtr = new llvm::GlobalVariable(CGM.getModule(), Info->getType(), false, llvm::GlobalVariable::PrivateLinkage, Info); InfoPtr->setUnnamedAddr(true); @@ -2224,7 +2220,7 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked) { /// array to pointer, return the array subexpression. static const Expr *isSimpleArrayDecayOperand(const Expr *E) { // If this isn't just an array->pointer decay, bail out. - const CastExpr *CE = dyn_cast(E); + const auto *CE = dyn_cast(E); if (CE == 0 || CE->getCastKind() != CK_ArrayToPointerDecay) return 0; @@ -2309,7 +2305,7 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E, LValue ArrayLV; // For simple multidimensional array indexing, set the 'accessed' flag for // better bounds-checking of the base expression. - if (const ArraySubscriptExpr *ASE = dyn_cast(Array)) + if (const auto *ASE = dyn_cast(Array)) ArrayLV = EmitArraySubscriptExpr(ASE, /*Accessed*/ true); else ArrayLV = EmitLValue(Array); @@ -2436,16 +2432,16 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) { BaseLV = EmitCheckedLValue(BaseExpr, TCK_MemberAccess); NamedDecl *ND = E->getMemberDecl(); - if (FieldDecl *Field = dyn_cast(ND)) { + if (auto *Field = dyn_cast(ND)) { LValue LV = EmitLValueForField(BaseLV, Field); setObjCGCLValueClass(getContext(), E, LV); return LV; } - if (VarDecl *VD = dyn_cast(ND)) + if (auto *VD = dyn_cast(ND)) return EmitGlobalVarDeclLValue(*this, E, VD); - if (const FunctionDecl *FD = dyn_cast(ND)) + if (const auto *FD = dyn_cast(ND)) return EmitFunctionDeclLValue(*this, E, FD); llvm_unreachable("Unhandled member declaration!"); @@ -2761,7 +2757,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { case CK_Dynamic: { LValue LV = EmitLValue(E->getSubExpr()); llvm::Value *V = LV.getAddress(); - const CXXDynamicCastExpr *DCE = cast(E); + const auto *DCE = cast(E); return MakeAddrLValue(EmitDynamicCast(V, DCE), E->getType()); } @@ -2777,8 +2773,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { case CK_DerivedToBase: { const RecordType *DerivedClassTy = E->getSubExpr()->getType()->getAs(); - CXXRecordDecl *DerivedClassDecl = - cast(DerivedClassTy->getDecl()); + auto *DerivedClassDecl = cast(DerivedClassTy->getDecl()); LValue LV = EmitLValue(E->getSubExpr()); llvm::Value *This = LV.getAddress(); @@ -2795,8 +2790,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { return EmitAggExprToLValue(E); case CK_BaseToDerived: { const RecordType *DerivedClassTy = E->getType()->getAs(); - CXXRecordDecl *DerivedClassDecl = - cast(DerivedClassTy->getDecl()); + auto *DerivedClassDecl = cast(DerivedClassTy->getDecl()); LValue LV = EmitLValue(E->getSubExpr()); @@ -2816,7 +2810,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { } case CK_LValueBitCast: { // This must be a reinterpret_cast (or c-style equivalent). - const ExplicitCastExpr *CE = cast(E); + const auto *CE = cast(E); LValue LV = EmitLValue(E->getSubExpr()); llvm::Value *V = Builder.CreateBitCast(LV.getAddress(), @@ -2877,10 +2871,10 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E, if (E->getCallee()->getType()->isBlockPointerType()) return EmitBlockCallExpr(E, ReturnValue); - if (const CXXMemberCallExpr *CE = dyn_cast(E)) + if (const auto *CE = dyn_cast(E)) return EmitCXXMemberCallExpr(CE, ReturnValue); - if (const CUDAKernelCallExpr *CE = dyn_cast(E)) + if (const auto *CE = dyn_cast(E)) return EmitCUDAKernelCallExpr(CE, ReturnValue); const Decl *TargetDecl = E->getCalleeDecl(); @@ -2889,12 +2883,12 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E, return EmitBuiltinExpr(FD, builtinID, E); } - if (const CXXOperatorCallExpr *CE = dyn_cast(E)) + if (const auto *CE = dyn_cast(E)) if (const CXXMethodDecl *MD = dyn_cast_or_null(TargetDecl)) return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue); - if (const CXXPseudoDestructorExpr *PseudoDtor - = dyn_cast(E->getCallee()->IgnoreParens())) { + if (const auto *PseudoDtor = + dyn_cast(E->getCallee()->IgnoreParens())) { QualType DestroyedType = PseudoDtor->getDestroyedType(); if (getLangOpts().ObjCAutoRefCount && DestroyedType->isObjCLifetimeType() && @@ -3132,8 +3126,8 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, llvm::Value *Callee, CalleeType = getContext().getCanonicalType(CalleeType); - const FunctionType *FnType - = cast(cast(CalleeType)->getPointeeType()); + const auto *FnType = + cast(cast(CalleeType)->getPointeeType()); // Force column info to differentiate multiple inlined call sites on // the same line, analoguous to EmitCallExpr. @@ -3289,7 +3283,7 @@ static LValueOrRValue emitPseudoObjectExpr(CodeGenFunction &CGF, // 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)) { // If this is the result expression, we may need to evaluate // directly into the slot. diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index cdd240ee2a..d474c1b464 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -200,13 +200,13 @@ void CodeGenModule::applyReplacements() { llvm::GlobalValue *Entry = GetGlobalValue(MangledName); if (!Entry) continue; - llvm::Function *OldF = cast(Entry); - llvm::Function *NewF = dyn_cast(Replacement); + auto *OldF = cast(Entry); + auto *NewF = dyn_cast(Replacement); if (!NewF) { - if (llvm::GlobalAlias *Alias = dyn_cast(Replacement)) { + if (auto *Alias = dyn_cast(Replacement)) { NewF = dyn_cast(Alias->getAliasedGlobal()); } else { - llvm::ConstantExpr *CE = cast(Replacement); + auto *CE = cast(Replacement); assert(CE->getOpcode() == llvm::Instruction::BitCast || CE->getOpcode() == llvm::Instruction::GetElementPtr); NewF = dyn_cast(CE->getOperand(0)); @@ -232,11 +232,11 @@ void CodeGenModule::checkAliases() { for (std::vector::iterator I = Aliases.begin(), E = Aliases.end(); I != E; ++I) { const GlobalDecl &GD = *I; - const ValueDecl *D = cast(GD.getDecl()); + const auto *D = cast(GD.getDecl()); const AliasAttr *AA = D->getAttr(); StringRef MangledName = getMangledName(GD); llvm::GlobalValue *Entry = GetGlobalValue(MangledName); - llvm::GlobalAlias *Alias = cast(Entry); + auto *Alias = cast(Entry); llvm::GlobalValue *GV = Alias->getAliasedGlobal(); if (!GV) { Error = true; @@ -287,7 +287,7 @@ void CodeGenModule::checkAliases() { const GlobalDecl &GD = *I; StringRef MangledName = getMangledName(GD); llvm::GlobalValue *Entry = GetGlobalValue(MangledName); - llvm::GlobalAlias *Alias = cast(Entry); + auto *Alias = cast(Entry); Alias->replaceAllUsesWith(llvm::UndefValue::get(Alias->getType())); Alias->eraseFromParent(); } @@ -483,7 +483,7 @@ void CodeGenModule::setTLSMode(llvm::GlobalVariable *GV, } StringRef CodeGenModule::getMangledName(GlobalDecl GD) { - const NamedDecl *ND = cast(GD.getDecl()); + const auto *ND = cast(GD.getDecl()); StringRef &Str = MangledDeclNames[GD.getCanonicalDecl()]; if (!Str.empty()) @@ -499,9 +499,9 @@ StringRef CodeGenModule::getMangledName(GlobalDecl GD) { SmallString<256> Buffer; llvm::raw_svector_ostream Out(Buffer); - if (const CXXConstructorDecl *D = dyn_cast(ND)) + if (const auto *D = dyn_cast(ND)) getCXXABI().getMangleContext().mangleCXXCtor(D, GD.getCtorType(), Out); - else if (const CXXDestructorDecl *D = dyn_cast(ND)) + else if (const auto *D = dyn_cast(ND)) getCXXABI().getMangleContext().mangleCXXDtor(D, GD.getDtorType(), Out); else getCXXABI().getMangleContext().mangleName(ND, Out); @@ -525,9 +525,9 @@ void CodeGenModule::getBlockMangledName(GlobalDecl GD, MangleBuffer &Buffer, if (D == 0) MangleCtx.mangleGlobalBlock(BD, dyn_cast_or_null(initializedGlobalDecl.getDecl()), Out); - else if (const CXXConstructorDecl *CD = dyn_cast(D)) + else if (const auto *CD = dyn_cast(D)) MangleCtx.mangleCtorBlock(CD, GD.getCtorType(), BD, Out); - else if (const CXXDestructorDecl *DD = dyn_cast(D)) + else if (const auto *DD = dyn_cast(D)) MangleCtx.mangleDtorBlock(DD, GD.getDtorType(), BD, Out); else MangleCtx.mangleBlock(cast(D), BD, Out); @@ -581,7 +581,7 @@ void CodeGenModule::EmitCtorList(const CtorList &Fns, const char *GlobalName) { llvm::GlobalValue::LinkageTypes CodeGenModule::getFunctionLinkage(GlobalDecl GD) { - const FunctionDecl *D = cast(GD.getDecl()); + const auto *D = cast(GD.getDecl()); GVALinkage Linkage = getContext().GetGVALinkageForFunction(D); @@ -700,7 +700,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, if (isa(D) || isa(D)) F->setUnnamedAddr(true); - else if (const CXXMethodDecl *MD = dyn_cast(D)) + else if (const auto *MD = dyn_cast(D)) if (MD->isVirtual()) F->setUnnamedAddr(true); @@ -715,7 +715,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, void CodeGenModule::SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV) { - if (const NamedDecl *ND = dyn_cast(D)) + if (const auto *ND = dyn_cast(D)) setGlobalVisibility(GV, ND); else GV->setVisibility(llvm::GlobalValue::DefaultVisibility); @@ -782,7 +782,7 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, return; } - const FunctionDecl *FD = cast(GD.getDecl()); + const auto *FD = cast(GD.getDecl()); if (!IsIncompleteFunction) SetLLVMFunctionAttributes(FD, getTypes().arrangeGlobalDeclaration(GD), F); @@ -846,11 +846,9 @@ static void emitUsed(CodeGenModule &CGM, StringRef Name, return; llvm::ArrayType *ATy = llvm::ArrayType::get(CGM.Int8PtrTy, UsedArray.size()); - llvm::GlobalVariable *GV = - new llvm::GlobalVariable(CGM.getModule(), ATy, false, - llvm::GlobalValue::AppendingLinkage, - llvm::ConstantArray::get(ATy, UsedArray), - Name); + auto *GV = new llvm::GlobalVariable( + CGM.getModule(), ATy, false, llvm::GlobalValue::AppendingLinkage, + llvm::ConstantArray::get(ATy, UsedArray), Name); GV->setSection("llvm.metadata"); } @@ -1031,9 +1029,9 @@ void CodeGenModule::EmitGlobalAnnotations() { // Create a new global variable for the ConstantStruct in the Module. llvm::Constant *Array = llvm::ConstantArray::get(llvm::ArrayType::get( Annotations[0]->getType(), Annotations.size()), Annotations); - llvm::GlobalValue *gv = new llvm::GlobalVariable(getModule(), - Array->getType(), false, llvm::GlobalValue::AppendingLinkage, Array, - "llvm.global.annotations"); + auto *gv = new llvm::GlobalVariable(getModule(), Array->getType(), false, + llvm::GlobalValue::AppendingLinkage, + Array, "llvm.global.annotations"); gv->setSection(AnnotationSection); } @@ -1044,8 +1042,9 @@ llvm::Constant *CodeGenModule::EmitAnnotationString(StringRef Str) { // Not found yet, create a new global. llvm::Constant *s = llvm::ConstantDataArray::getString(getLLVMContext(), Str); - llvm::GlobalValue *gv = new llvm::GlobalVariable(getModule(), s->getType(), - true, llvm::GlobalValue::PrivateLinkage, s, ".str"); + auto *gv = + new llvm::GlobalVariable(getModule(), s->getType(), true, + llvm::GlobalValue::PrivateLinkage, s, ".str"); gv->setSection(AnnotationSection); gv->setUnnamedAddr(true); AStr = gv; @@ -1117,7 +1116,7 @@ llvm::Constant *CodeGenModule::GetAddrOfUuidDescriptor( llvm::Constant *Init = EmitUuidofInitializer(Uuid, E->getType()); assert(Init && "failed to initialize as constant"); - llvm::GlobalVariable *GV = new llvm::GlobalVariable( + auto *GV = new llvm::GlobalVariable( getModule(), Init->getType(), /*isConstant=*/true, llvm::GlobalValue::LinkOnceODRLinkage, Init, Name); return GV; @@ -1145,7 +1144,7 @@ llvm::Constant *CodeGenModule::GetWeakRefReference(const ValueDecl *VD) { Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(), llvm::PointerType::getUnqual(DeclTy), 0); - llvm::GlobalValue* F = cast(Aliasee); + auto *F = cast(Aliasee); F->setLinkage(llvm::Function::ExternalWeakLinkage); WeakRefReferences.insert(F); @@ -1153,7 +1152,7 @@ llvm::Constant *CodeGenModule::GetWeakRefReference(const ValueDecl *VD) { } void CodeGenModule::EmitGlobal(GlobalDecl GD) { - const ValueDecl *Global = cast(GD.getDecl()); + const auto *Global = cast(GD.getDecl()); // Weak references don't produce any output by themselves. if (Global->hasAttr()) @@ -1182,7 +1181,7 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) { } // Ignore declarations, they will be emitted on their first use. - if (const FunctionDecl *FD = dyn_cast(Global)) { + if (const auto *FD = dyn_cast(Global)) { // Forward declarations are emitted lazily on first use. if (!FD->doesThisDeclarationHaveABody()) { if (!FD->doesDeclarationForceExternallyVisibleDefinition()) @@ -1199,7 +1198,7 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) { return; } } else { - const VarDecl *VD = cast(Global); + const auto *VD = cast(Global); assert(VD->isFileVarDecl() && "Cannot emit local var decl as global."); if (VD->isThisDeclarationADefinition() != VarDecl::Definition) @@ -1294,7 +1293,7 @@ bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) { if (getFunctionLinkage(GD) != llvm::Function::AvailableExternallyLinkage) return true; - const FunctionDecl *F = cast(GD.getDecl()); + const auto *F = cast(GD.getDecl()); if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr()) return false; // PR9614. Avoid cases where the source code is lying to us. An available @@ -1316,14 +1315,13 @@ void CodeGenModule::CompleteDIClassType(const CXXMethodDecl* D) { if (CGDebugInfo *DI = getModuleDebugInfo()) if (getCodeGenOpts().getDebugInfo() >= CodeGenOptions::LimitedDebugInfo) { - const PointerType *ThisPtr = - cast(D->getThisType(getContext())); + const auto *ThisPtr = cast(D->getThisType(getContext())); DI->getOrCreateRecordType(ThisPtr->getPointeeType(), D->getLocation()); } } void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD, llvm::GlobalValue *GV) { - const ValueDecl *D = cast(GD.getDecl()); + const auto *D = cast(GD.getDecl()); PrettyStackTraceDecl CrashInfo(const_cast(D), D->getLocation(), Context.getSourceManager(), @@ -1335,13 +1333,13 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD, llvm::GlobalValue *GV) { if (!shouldEmitFunction(GD)) return; - if (const CXXMethodDecl *Method = dyn_cast(D)) { + if (const auto *Method = dyn_cast(D)) { CompleteDIClassType(Method); // Make sure to emit the definition(s) before we emit the thunks. // This is necessary for the generation of certain thunks. - if (const CXXConstructorDecl *CD = dyn_cast(Method)) + if (const auto *CD = dyn_cast(Method)) EmitCXXConstructor(CD, GD.getCtorType()); - else if (const CXXDestructorDecl *DD =dyn_cast(Method)) + else if (const auto *DD = dyn_cast(Method)) EmitCXXDestructor(DD, GD.getDtorType()); else EmitGlobalFunctionDefinition(GD, GV); @@ -1354,8 +1352,8 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD, llvm::GlobalValue *GV) { return EmitGlobalFunctionDefinition(GD, GV); } - - if (const VarDecl *VD = dyn_cast(D)) + + if (const auto *VD = dyn_cast(D)) return EmitGlobalVarDefinition(VD); llvm_unreachable("Invalid argument to EmitGlobalDefinition()"); @@ -1460,7 +1458,7 @@ CodeGenModule::GetOrCreateLLVMFunction(StringRef MangledName, // in a vtable, unless it's already marked as used. } else if (getLangOpts().CPlusPlus && D) { // Look for a declaration that's lexically in a record. - const FunctionDecl *FD = cast(D); + const auto *FD = cast(D); FD = FD->getMostRecentDecl(); do { if (isa(FD->getLexicalDeclContext())) { @@ -1515,7 +1513,7 @@ CodeGenModule::CreateRuntimeFunction(llvm::FunctionType *FTy, llvm::Constant *C = GetOrCreateLLVMFunction(Name, FTy, GlobalDecl(), /*ForVTable=*/false, /*DontDefer=*/false, ExtraAttrs); - if (llvm::Function *F = dyn_cast(C)) + if (auto *F = dyn_cast(C)) if (F->empty()) F->setCallingConv(getRuntimeCC()); return C; @@ -1587,11 +1585,10 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, } unsigned AddrSpace = GetGlobalVarAddressSpace(D, Ty->getAddressSpace()); - llvm::GlobalVariable *GV = - new llvm::GlobalVariable(getModule(), Ty->getElementType(), false, - llvm::GlobalValue::ExternalLinkage, - 0, MangledName, 0, - llvm::GlobalVariable::NotThreadLocal, AddrSpace); + auto *GV = new llvm::GlobalVariable( + getModule(), Ty->getElementType(), false, + llvm::GlobalValue::ExternalLinkage, 0, MangledName, 0, + llvm::GlobalVariable::NotThreadLocal, AddrSpace); // This is the first use or definition of a mangled name. If there is a // deferred decl with this name, remember that we need to emit it at the end @@ -1828,7 +1825,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { llvm::Constant *Entry = GetAddrOfGlobalVar(D, InitType); // Strip off a bitcast if we got one back. - if (llvm::ConstantExpr *CE = dyn_cast(Entry)) { + if (auto *CE = dyn_cast(Entry)) { assert(CE->getOpcode() == llvm::Instruction::BitCast || CE->getOpcode() == llvm::Instruction::AddrSpaceCast || // All zero index gep. @@ -1837,7 +1834,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { } // Entry is now either a Function or GlobalVariable. - llvm::GlobalVariable *GV = dyn_cast(Entry); + auto *GV = dyn_cast(Entry); // We have a definition after a declaration with the wrong type. // We must make a new GlobalVariable* and update everything that used OldGV @@ -2050,7 +2047,7 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old, // Recognize and replace uses of bitcasts. Most calls to // unprototyped functions will use bitcasts. - if (llvm::ConstantExpr *bitcast = dyn_cast(user)) { + if (auto *bitcast = dyn_cast(user)) { if (bitcast->getOpcode() == llvm::Instruction::BitCast) replaceUsesOfNonProtoConstant(bitcast, newFn); continue; @@ -2114,8 +2111,7 @@ static void replaceUsesOfNonProtoConstant(llvm::Constant *old, newCall = llvm::CallInst::Create(newFn, newArgs, "", callSite.getInstruction()); } else { - llvm::InvokeInst *oldInvoke = - cast(callSite.getInstruction()); + auto *oldInvoke = cast(callSite.getInstruction()); newCall = llvm::InvokeInst::Create(newFn, oldInvoke->getNormalDest(), oldInvoke->getUnwindDest(), @@ -2170,7 +2166,7 @@ void CodeGenModule::HandleCXXStaticMemberVarInstantiation(VarDecl *VD) { void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV) { - const FunctionDecl *D = cast(GD.getDecl()); + const auto *D = cast(GD.getDecl()); // Compute the function info and LLVM type. const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD); @@ -2182,7 +2178,7 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, GetAddrOfFunction(GD, Ty, /*ForVTable=*/false, /*DontDefer*/ true); // 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); GV = cast(CE->getOperand(0)); } else { @@ -2239,7 +2235,7 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, // generating code for it because various parts of IR generation // want to propagate this information down (e.g. to local static // declarations). - llvm::Function *Fn = cast(GV); + auto *Fn = cast(GV); setFunctionLinkage(GD, Fn); // FIXME: this is redundant with part of setFunctionDefinitionAttributes @@ -2261,7 +2257,7 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, } void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) { - const ValueDecl *D = cast(GD.getDecl()); + const auto *D = cast(GD.getDecl()); const AliasAttr *AA = D->getAttr(); assert(AA && "Not an alias?"); @@ -2288,10 +2284,9 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) { llvm::PointerType::getUnqual(DeclTy), 0); // Create the new alias itself, but don't set a name yet. - llvm::GlobalValue *GA = - new llvm::GlobalAlias(Aliasee->getType(), - llvm::Function::ExternalLinkage, - "", Aliasee, &getModule()); + auto *GA = + new llvm::GlobalAlias(Aliasee->getType(), llvm::Function::ExternalLinkage, + "", Aliasee, &getModule()); if (Entry) { assert(Entry->isDeclaration()); @@ -2316,7 +2311,7 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) { // specialization of the attributes which may be set on a global // variable/function. if (D->hasAttr()) { - if (const FunctionDecl *FD = dyn_cast(D)) { + if (const auto *FD = dyn_cast(D)) { // The dllexport attribute is ignored for undefined symbols. if (FD->hasBody()) GA->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); @@ -2414,8 +2409,7 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) { QualType CFTy = getContext().getCFConstantStringType(); - llvm::StructType *STy = - cast(getTypes().ConvertType(CFTy)); + auto *STy = cast(getTypes().ConvertType(CFTy)); llvm::Constant *Fields[4]; @@ -2441,7 +2435,7 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) { // Note: -fwritable-strings doesn't make the backing store strings of // CFStrings writable. (See ) - llvm::GlobalVariable *GV = + auto *GV = new llvm::GlobalVariable(getModule(), C->getType(), /*isConstant=*/true, llvm::GlobalValue::PrivateLinkage, C, ".str"); GV->setUnnamedAddr(true); @@ -2567,10 +2561,9 @@ CodeGenModule::GetAddrOfConstantString(const StringLiteral *Literal) { bool isConstant; Linkage = llvm::GlobalValue::PrivateLinkage; isConstant = !LangOpts.WritableStrings; - - llvm::GlobalVariable *GV = - new llvm::GlobalVariable(getModule(), C->getType(), isConstant, Linkage, C, - ".str"); + + auto *GV = new llvm::GlobalVariable(getModule(), C->getType(), isConstant, + Linkage, C, ".str"); GV->setUnnamedAddr(true); // Don't enforce the target's minimum global alignment, since the only use // of the string is via this class initializer. @@ -2646,9 +2639,8 @@ CodeGenModule::GetConstantArrayFromStringLiteral(const StringLiteral *E) { Str.resize(CAT->getSize().getZExtValue()); return llvm::ConstantDataArray::getString(VMContext, Str, false); } - - llvm::ArrayType *AType = - cast(getTypes().ConvertType(E->getType())); + + auto *AType = cast(getTypes().ConvertType(E->getType())); llvm::Type *ElemTy = AType->getElementType(); unsigned NumElements = AType->getNumElements(); @@ -2769,7 +2761,7 @@ static llvm::GlobalVariable *GenerateStringLiteral(StringRef str, AddrSpace = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant); // Create a global variable for this string - llvm::GlobalVariable *GV = new llvm::GlobalVariable( + auto *GV = new llvm::GlobalVariable( CGM.getModule(), C->getType(), constant, llvm::GlobalValue::PrivateLinkage, C, GlobalName, 0, llvm::GlobalVariable::NotThreadLocal, AddrSpace); @@ -2832,7 +2824,7 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalTemporary( const MaterializeTemporaryExpr *E, const Expr *Init) { assert((E->getStorageDuration() == SD_Static || E->getStorageDuration() == SD_Thread) && "not a global temporary"); - const VarDecl *VD = cast(E->getExtendingDecl()); + const auto *VD = cast(E->getExtendingDecl()); // If we're not materializing a subobject of the temporary, keep the // cv-qualifiers from the type of the MaterializeTemporaryExpr. @@ -2893,7 +2885,7 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalTemporary( Linkage = llvm::GlobalVariable::PrivateLinkage; unsigned AddrSpace = GetGlobalVarAddressSpace( VD, getContext().getTargetAddressSpace(MaterializedType)); - llvm::GlobalVariable *GV = new llvm::GlobalVariable( + auto *GV = new llvm::GlobalVariable( getModule(), Type, Constant, Linkage, InitialValue, Name.c_str(), /*InsertBefore=*/nullptr, llvm::GlobalVariable::NotThreadLocal, AddrSpace); @@ -3096,7 +3088,7 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { break; case Decl::ObjCProtocol: { - ObjCProtocolDecl *Proto = cast(D); + auto *Proto = cast(D); if (Proto->isThisDeclarationADefinition()) ObjCRuntime->GenerateProtocol(Proto); break; @@ -3109,7 +3101,7 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { break; case Decl::ObjCImplementation: { - ObjCImplementationDecl *OMD = cast(D); + auto *OMD = cast(D); EmitObjCPropertyImplementations(OMD); EmitObjCIvarInitializations(OMD); ObjCRuntime->GenerateClass(OMD); @@ -3121,7 +3113,7 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { break; } case Decl::ObjCMethod: { - ObjCMethodDecl *OMD = cast(D); + auto *OMD = cast(D); // If this is not a prototype, emit the body. if (OMD->getBody()) CodeGenFunction(*this).GenerateObjCMethod(OMD); @@ -3136,7 +3128,7 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { break; case Decl::FileScopeAsm: { - FileScopeAsmDecl *AD = cast(D); + auto *AD = cast(D); StringRef AsmString = AD->getAsmString()->getString(); const std::string &S = getModule().getModuleInlineAsm(); @@ -3150,7 +3142,7 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { } case Decl::Import: { - ImportDecl *Import = cast(D); + auto *Import = cast(D); // Ignore import declarations that come from imported modules. if (clang::Module *Owner = Import->getOwningModule()) { @@ -3164,8 +3156,7 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { } case Decl::ClassTemplateSpecialization: { - const ClassTemplateSpecializationDecl *Spec = - cast(D); + const auto *Spec = cast(D); if (DebugInfo && Spec->getSpecializationKind() == TSK_ExplicitInstantiationDefinition) DebugInfo->completeTemplateDefinition(*Spec); @@ -3256,10 +3247,10 @@ void CodeGenFunction::EmitDeclMetadata() { const Decl *D = I->first; llvm::Value *Addr = I->second; - if (llvm::AllocaInst *Alloca = dyn_cast(Addr)) { + if (auto *Alloca = dyn_cast(Addr)) { llvm::Value *DAddr = GetPointerConstant(getLLVMContext(), D); Alloca->setMetadata(DeclPtrKind, llvm::MDNode::get(Context, DAddr)); - } else if (llvm::GlobalValue *GV = dyn_cast(Addr)) { + } else if (auto *GV = dyn_cast(Addr)) { GlobalDecl GD = GlobalDecl(cast(D)); EmitGlobalDeclMetadata(CGM, GlobalMetadata, GD, GV); } -- 2.40.0