From: John McCall Date: Fri, 15 Oct 2010 04:57:14 +0000 (+0000) Subject: Death to blocks, or at least the word "block" in one particular obnoxiously X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b6bbcc9995186799a60ce17d0c1acff31601653a;p=clang Death to blocks, or at least the word "block" in one particular obnoxiously ambiguous context. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116567 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 04a18a93e0..16fc86a877 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -630,13 +630,13 @@ public: /// external, C linkage. bool isExternC() const; - /// isBlockVarDecl - Returns true for local variable declarations. Note that - /// this includes static variables inside of functions. It also includes - /// variables inside blocks. + /// isLocalVarDecl - Returns true for local variable declarations + /// other than parameters. Note that this includes static variables + /// inside of functions. It also includes variables inside blocks. /// /// void foo() { int x; static int y; extern int z; } /// - bool isBlockVarDecl() const { + bool isLocalVarDecl() const { if (getKind() != Decl::Var) return false; if (const DeclContext *DC = getDeclContext()) @@ -644,8 +644,8 @@ public: return false; } - /// isFunctionOrMethodVarDecl - Similar to isBlockVarDecl, but excludes - /// variables declared in blocks. + /// isFunctionOrMethodVarDecl - Similar to isLocalVarDecl, but + /// excludes variables declared in blocks. bool isFunctionOrMethodVarDecl() const { if (getKind() != Decl::Var) return false; diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp index 0f43efa58c..5e8331f282 100644 --- a/lib/Analysis/UninitializedValues.cpp +++ b/lib/Analysis/UninitializedValues.cpp @@ -87,7 +87,7 @@ static const bool Uninitialized = true; bool TransferFuncs::VisitDeclRefExpr(DeclRefExpr* DR) { if (VarDecl* VD = dyn_cast(DR->getDecl())) - if (VD->isBlockVarDecl()) { + if (VD->isLocalVarDecl()) { if (AD.Observer) AD.Observer->ObserveDeclRefExpr(V, AD, DR, VD); @@ -112,7 +112,7 @@ static VarDecl* FindBlockVarDecl(Expr* E) { if (DeclRefExpr* DR = dyn_cast(E->IgnoreParenCasts())) if (VarDecl* VD = dyn_cast(DR->getDecl())) - if (VD->isBlockVarDecl()) return VD; + if (VD->isLocalVarDecl()) return VD; return NULL; } @@ -133,7 +133,7 @@ bool TransferFuncs::VisitBinaryOperator(BinaryOperator* B) { bool TransferFuncs::VisitDeclStmt(DeclStmt* S) { for (DeclStmt::decl_iterator I=S->decl_begin(), E=S->decl_end(); I!=E; ++I) { VarDecl *VD = dyn_cast(*I); - if (VD && VD->isBlockVarDecl()) { + if (VD && VD->isLocalVarDecl()) { if (Stmt* I = VD->getInit()) { // Visit the subexpression to check for uses of uninitialized values, // even if we don't propagate that value. @@ -170,7 +170,7 @@ bool TransferFuncs::VisitUnaryOperator(UnaryOperator* U) { switch (U->getOpcode()) { case UO_AddrOf: { VarDecl* VD = FindBlockVarDecl(U->getSubExpr()); - if (VD && VD->isBlockVarDecl()) + if (VD && VD->isLocalVarDecl()) return V(VD,AD) = Initialized; break; } diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp index c8f23f3f0c..33d1f6e206 100644 --- a/lib/CodeGen/CGClass.cpp +++ b/lib/CodeGen/CGClass.cpp @@ -589,7 +589,7 @@ static void EmitMemberInitializer(CodeGenFunction &CGF, // Emit the block variables for the array indices, if any. for (unsigned I = 0, N = MemberInit->getNumArrayIndices(); I != N; ++I) - CGF.EmitLocalBlockVarDecl(*MemberInit->getArrayIndex(I)); + CGF.EmitAutoVarDecl(*MemberInit->getArrayIndex(I)); } EmitAggMemberInitializer(CGF, LHS, ArrayIndexVar, MemberInit, FieldType, 0); diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index e1be2d29be..e381e97947 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -85,9 +85,9 @@ void CodeGenFunction::EmitDecl(const Decl &D) { case Decl::Var: { const VarDecl &VD = cast(D); - assert(VD.isBlockVarDecl() && + assert(VD.isLocalVarDecl() && "Should not see file-scope variables inside a function!"); - return EmitBlockVarDecl(VD); + return EmitVarDecl(VD); } case Decl::Typedef: { // typedef int X; @@ -100,9 +100,9 @@ void CodeGenFunction::EmitDecl(const Decl &D) { } } -/// EmitBlockVarDecl - This method handles emission of any variable declaration +/// EmitVarDecl - This method handles emission of any variable declaration /// inside a function, including static vars etc. -void CodeGenFunction::EmitBlockVarDecl(const VarDecl &D) { +void CodeGenFunction::EmitVarDecl(const VarDecl &D) { if (D.hasAttr()) CGM.ErrorUnsupported(&D, "__asm__"); @@ -110,7 +110,7 @@ void CodeGenFunction::EmitBlockVarDecl(const VarDecl &D) { case SC_None: case SC_Auto: case SC_Register: - return EmitLocalBlockVarDecl(D); + return EmitAutoVarDecl(D); case SC_Static: { llvm::GlobalValue::LinkageTypes Linkage = llvm::GlobalValue::InternalLinkage; @@ -124,7 +124,7 @@ void CodeGenFunction::EmitBlockVarDecl(const VarDecl &D) { if (llvm::GlobalValue::isWeakForLinker(CurFn->getLinkage())) Linkage = CurFn->getLinkage(); - return EmitStaticBlockVarDecl(D, Linkage); + return EmitStaticVarDecl(D, Linkage); } case SC_Extern: case SC_PrivateExtern: @@ -157,9 +157,9 @@ static std::string GetStaticDeclName(CodeGenFunction &CGF, const VarDecl &D, } llvm::GlobalVariable * -CodeGenFunction::CreateStaticBlockVarDecl(const VarDecl &D, - const char *Separator, - llvm::GlobalValue::LinkageTypes Linkage) { +CodeGenFunction::CreateStaticVarDecl(const VarDecl &D, + const char *Separator, + llvm::GlobalValue::LinkageTypes Linkage) { QualType Ty = D.getType(); assert(Ty->isConstantSizeType() && "VLAs can't be static"); @@ -175,13 +175,13 @@ CodeGenFunction::CreateStaticBlockVarDecl(const VarDecl &D, return GV; } -/// AddInitializerToGlobalBlockVarDecl - Add the initializer for 'D' to the +/// AddInitializerToStaticVarDecl - Add the initializer for 'D' to the /// global variable that has already been created for it. If the initializer /// has a different type than GV does, this may free GV and return a different /// one. Otherwise it just returns GV. llvm::GlobalVariable * -CodeGenFunction::AddInitializerToGlobalBlockVarDecl(const VarDecl &D, - llvm::GlobalVariable *GV) { +CodeGenFunction::AddInitializerToStaticVarDecl(const VarDecl &D, + llvm::GlobalVariable *GV) { llvm::Constant *Init = CGM.EmitConstantExpr(D.getInit(), D.getType(), this); // If constant emission failed, then this should be a C++ static @@ -228,12 +228,12 @@ CodeGenFunction::AddInitializerToGlobalBlockVarDecl(const VarDecl &D, return GV; } -void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D, +void CodeGenFunction::EmitStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage) { llvm::Value *&DMEntry = LocalDeclMap[&D]; assert(DMEntry == 0 && "Decl already exists in localdeclmap!"); - llvm::GlobalVariable *GV = CreateStaticBlockVarDecl(D, ".", Linkage); + llvm::GlobalVariable *GV = CreateStaticVarDecl(D, ".", Linkage); // Store into LocalDeclMap before generating initializer to handle // circular references. @@ -251,7 +251,7 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D, // If this value has an initializer, emit it. if (D.getInit()) - GV = AddInitializerToGlobalBlockVarDecl(D, GV); + GV = AddInitializerToStaticVarDecl(D, GV); GV->setAlignment(getContext().getDeclAlign(&D).getQuantity()); @@ -492,11 +492,11 @@ namespace { }; } -/// EmitLocalBlockVarDecl - Emit code and set up an entry in LocalDeclMap for a +/// EmitLocalVarDecl - Emit code and set up an entry in LocalDeclMap for a /// variable declaration with auto, register, or no storage class specifier. /// These turn into simple stack objects, or GlobalValues depending on target. -void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D, - SpecialInitFn *SpecialInit) { +void CodeGenFunction::EmitAutoVarDecl(const VarDecl &D, + SpecialInitFn *SpecialInit) { QualType Ty = D.getType(); unsigned Alignment = getContext().getDeclAlign(&D).getQuantity(); bool isByRef = D.hasAttr(); @@ -521,7 +521,7 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D, // If this variable is marked 'const', emit the value as a global. if (CGM.getCodeGenOpts().MergeAllConstants && Ty.isConstant(getContext())) { - EmitStaticBlockVarDecl(D, llvm::GlobalValue::InternalLinkage); + EmitStaticVarDecl(D, llvm::GlobalValue::InternalLinkage); return; } @@ -570,9 +570,8 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D, // Targets that don't support recursion emit locals as globals. const char *Class = D.getStorageClass() == SC_Register ? ".reg." : ".auto."; - DeclPtr = CreateStaticBlockVarDecl(D, Class, - llvm::GlobalValue - ::InternalLinkage); + DeclPtr = CreateStaticVarDecl(D, Class, + llvm::GlobalValue::InternalLinkage); } // FIXME: Can this happen? diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp index d2df1fba1d..79646f3316 100644 --- a/lib/CodeGen/CGException.cpp +++ b/lib/CodeGen/CGException.cpp @@ -1300,7 +1300,7 @@ static void BeginCatch(CodeGenFunction &CGF, } // Emit the local. - CGF.EmitLocalBlockVarDecl(*CatchParam, &InitCatchParam); + CGF.EmitAutoVarDecl(*CatchParam, &InitCatchParam); } namespace { diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 5b695cd52c..d45cd2ad63 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -1064,8 +1064,7 @@ static void setObjCGCLValueClass(const ASTContext &Ctx, const Expr *E, if (const DeclRefExpr *Exp = dyn_cast(E)) { if (const VarDecl *VD = dyn_cast(Exp->getDecl())) { - if ((VD->isBlockVarDecl() && !VD->hasLocalStorage()) || - VD->isFileVarDecl()) { + if (VD->hasGlobalStorage()) { LV.setGlobalObjCRef(true); LV.setThreadLocalRef(VD->isThreadSpecified()); } diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 9c31c2a3d5..b99529a105 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -755,7 +755,7 @@ public: if (!VD->hasLocalStorage()) { if (VD->isFileVarDecl() || VD->hasExternalStorage()) return CGM.GetAddrOfGlobalVar(VD); - else if (VD->isBlockVarDecl()) { + else if (VD->isLocalVarDecl()) { assert(CGF && "Can't access static local vars without CGF"); return CGF->GetAddrOfStaticLocalVar(VD); } diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index 0b3e31db04..eb45d5bcf3 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -2008,7 +2008,7 @@ void CGObjCGNU::EmitTryStmt(CodeGen::CodeGenFunction &CGF, const llvm::Type *CatchType = CGF.ConvertType(CatchParam->getType()); Exn = CGF.Builder.CreateBitCast(Exn, CatchType); - CGF.EmitLocalBlockVarDecl(*CatchParam); + CGF.EmitAutoVarDecl(*CatchParam); CGF.Builder.CreateStore(Exn, CGF.GetAddrOfLocalVar(CatchParam)); } diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index c7e4c5ffcf..8b3fd499b6 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -3105,7 +3105,7 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, CodeGenFunction::RunCleanupsScope CatchVarCleanups(CGF); if (CatchParam) { - CGF.EmitLocalBlockVarDecl(*CatchParam); + CGF.EmitAutoVarDecl(*CatchParam); assert(CGF.HaveInsertPoint() && "DeclStmt destroyed insert point?"); // These types work out because ConvertType(id) == i8*. @@ -3149,7 +3149,7 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, // the end of the catch body. CodeGenFunction::RunCleanupsScope CatchVarCleanups(CGF); - CGF.EmitLocalBlockVarDecl(*CatchParam); + CGF.EmitAutoVarDecl(*CatchParam); assert(CGF.HaveInsertPoint() && "DeclStmt destroyed insert point?"); // Initialize the catch variable. @@ -6137,7 +6137,7 @@ void CGObjCNonFragileABIMac::EmitTryStmt(CodeGen::CodeGenFunction &CGF, const llvm::Type *CatchType = CGF.ConvertType(CatchParam->getType()); llvm::Value *CastExn = CGF.Builder.CreateBitCast(Exn, CatchType); - CGF.EmitLocalBlockVarDecl(*CatchParam); + CGF.EmitAutoVarDecl(*CatchParam); CGF.Builder.CreateStore(CastExn, CGF.GetAddrOfLocalVar(CatchParam)); } diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index e83bea6d58..008c07514e 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -320,7 +320,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { RunCleanupsScope ConditionScope(*this); if (S.getConditionVariable()) - EmitLocalBlockVarDecl(*S.getConditionVariable()); + EmitAutoVarDecl(*S.getConditionVariable()); // If the condition constant folds and can be elided, try to avoid emitting // the condition and the dead arm of the if/else. @@ -395,7 +395,7 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S) { RunCleanupsScope ConditionScope(*this); if (S.getConditionVariable()) - EmitLocalBlockVarDecl(*S.getConditionVariable()); + EmitAutoVarDecl(*S.getConditionVariable()); // Evaluate the conditional in the while header. C99 6.8.5.1: The // evaluation of the controlling expression takes place before each @@ -527,7 +527,7 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S) { // declaration. llvm::BasicBlock *ExitBlock = LoopExit.getBlock(); if (S.getConditionVariable()) { - EmitLocalBlockVarDecl(*S.getConditionVariable()); + EmitAutoVarDecl(*S.getConditionVariable()); } // If there are any cleanups between here and the loop-exit scope, @@ -798,7 +798,7 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) { RunCleanupsScope ConditionScope(*this); if (S.getConditionVariable()) - EmitLocalBlockVarDecl(*S.getConditionVariable()); + EmitAutoVarDecl(*S.getConditionVariable()); llvm::Value *CondV = EmitScalarExpr(S.getCond()); diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 6061b8fee8..e1505aaa72 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -1227,21 +1227,21 @@ public: /// This function can be called with a null (unreachable) insert point. void EmitDecl(const Decl &D); - /// EmitBlockVarDecl - Emit a block variable declaration. + /// EmitVarDecl - Emit a local variable declaration. /// /// This function can be called with a null (unreachable) insert point. - void EmitBlockVarDecl(const VarDecl &D); + void EmitVarDecl(const VarDecl &D); typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D, llvm::Value *Address); - /// EmitLocalBlockVarDecl - Emit a local block variable declaration. + /// EmitAutoVarDecl - Emit an auto variable declaration. /// /// This function can be called with a null (unreachable) insert point. - void EmitLocalBlockVarDecl(const VarDecl &D, SpecialInitFn *SpecialInit = 0); + void EmitAutoVarDecl(const VarDecl &D, SpecialInitFn *SpecialInit = 0); - void EmitStaticBlockVarDecl(const VarDecl &D, - llvm::GlobalValue::LinkageTypes Linkage); + void EmitStaticVarDecl(const VarDecl &D, + llvm::GlobalValue::LinkageTypes Linkage); /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl. void EmitParmDecl(const VarDecl &D, llvm::Value *Arg); @@ -1593,19 +1593,19 @@ public: /// LoadComplexFromAddr - Load a complex number from the specified address. ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile); - /// CreateStaticBlockVarDecl - Create a zero-initialized LLVM global for a - /// static block var decl. - llvm::GlobalVariable *CreateStaticBlockVarDecl(const VarDecl &D, - const char *Separator, + /// CreateStaticVarDecl - Create a zero-initialized LLVM global for + /// a static local variable. + llvm::GlobalVariable *CreateStaticVarDecl(const VarDecl &D, + const char *Separator, llvm::GlobalValue::LinkageTypes Linkage); - /// AddInitializerToGlobalBlockVarDecl - Add the initializer for 'D' to the + /// AddInitializerToStaticVarDecl - Add the initializer for 'D' to the /// global variable that has already been created for it. If the initializer /// has a different type than GV does, this may free GV and return a different /// one. Otherwise it just returns GV. llvm::GlobalVariable * - AddInitializerToGlobalBlockVarDecl(const VarDecl &D, - llvm::GlobalVariable *GV); + AddInitializerToStaticVarDecl(const VarDecl &D, + llvm::GlobalVariable *GV); /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++ diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 4a834cd560..bced4a0b8c 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4239,7 +4239,7 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) { // Get the decls type and save a reference for later, since // CheckInitializerTypes may change it. QualType DclT = VDecl->getType(), SavT = DclT; - if (VDecl->isBlockVarDecl()) { + if (VDecl->isLocalVarDecl()) { if (VDecl->hasExternalStorage()) { // C99 6.7.8p5 Diag(VDecl->getLocation(), diag::err_block_extern_cant_init); VDecl->setInvalidDecl(); @@ -4478,7 +4478,7 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl, // Block scope. C99 6.7p7: If an identifier for an object is // declared with no linkage (C99 6.2.2p6), the type for the // object shall be complete. - if (!Type->isDependentType() && Var->isBlockVarDecl() && + if (!Type->isDependentType() && Var->isLocalVarDecl() && !Var->getLinkage() && !Var->isInvalidDecl() && RequireCompleteType(Var->getLocation(), Type, diag::err_typecheck_decl_incomplete_type)) diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index ee0b172ee6..14d746acb7 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -90,7 +90,7 @@ namespace { // C++ [dcl.fct.default]p7 // Local variables shall not be used in default argument // expressions. - if (VDecl->isBlockVarDecl()) + if (VDecl->isLocalVarDecl()) return S->Diag(DRE->getSourceRange().getBegin(), diag::err_param_default_argument_references_local) << VDecl->getDeclName() << DefaultArg->getSourceRange(); diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index fd196af198..ddee9cca6d 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -914,7 +914,7 @@ Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, for (DeclStmt::decl_iterator DI=DS->decl_begin(), DE=DS->decl_end(); DI!=DE; ++DI) { VarDecl *VD = dyn_cast(*DI); - if (VD && VD->isBlockVarDecl() && !VD->hasLocalStorage()) + if (VD && VD->isLocalVarDecl() && !VD->hasLocalStorage()) VD = 0; if (VD == 0) Diag((*DI)->getLocation(), diag::err_non_variable_decl_in_for); @@ -962,7 +962,7 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, // declare identifiers for objects having storage class 'auto' or // 'register'. VarDecl *VD = cast(D); - if (VD->isBlockVarDecl() && !VD->hasLocalStorage()) + if (VD->isLocalVarDecl() && !VD->hasLocalStorage()) return StmtError(Diag(VD->getLocation(), diag::err_non_variable_decl_in_for)); } else {