[cfe-commits] r66904 - in /cfe/trunk: include/clang/AST/Decl.h lib/AST/Decl.cpp lib/CodeGen/CGBlocks.cpp lib/Sema/SemaExpr.cpp

Steve Naroff snaroff at apple.com
Fri Mar 13 09:56:44 PDT 2009


Author: snaroff
Date: Fri Mar 13 11:56:44 2009
New Revision: 66904

URL: http://llvm.org/viewvc/llvm-project?rev=66904&view=rev
Log:
Fix <rdar://problem/6675489> BlockDecl should not use llvm::smallvector.

Also changed BlockDecl API to be more consistent (wrt FunctionDecl).

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=66904&r1=66903&r2=66904&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Mar 13 11:56:44 2009
@@ -1183,12 +1183,18 @@
 /// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
 ///
 class BlockDecl : public Decl, public DeclContext {
-  llvm::SmallVector<ParmVarDecl*, 8> Args;
+  /// ParamInfo - new[]'d array of pointers to ParmVarDecls for the formal
+  /// parameters of this function.  This is null if a prototype or if there are
+  /// no formals.
+  ParmVarDecl **ParamInfo;
+  unsigned NumParams;
+  
   Stmt *Body;
   
 protected:
   BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
-    : Decl(Block, DC, CaretLoc), DeclContext(Block), Body(0) {}
+    : Decl(Block, DC, CaretLoc), DeclContext(Block), 
+      ParamInfo(0), NumParams(0), Body(0) {}
 
   virtual ~BlockDecl();
   virtual void Destroy(ASTContext& C);
@@ -1201,16 +1207,28 @@
   CompoundStmt *getBody() const { return (CompoundStmt*) Body; }
   void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
 
-  void setArgs(ParmVarDecl **args, unsigned numargs) {
-    Args.clear(); 
-    Args.insert(Args.begin(), args, args+numargs);
-  }
+  // Iterator access to formal parameters.
+  unsigned param_size() const { return getNumParams(); }
+  typedef ParmVarDecl **param_iterator;
+  typedef ParmVarDecl * const *param_const_iterator;
+  
+  bool param_empty() const { return NumParams == 0; }
+  param_iterator param_begin()  { return ParamInfo; }
+  param_iterator param_end()   { return ParamInfo+param_size(); }
   
-  /// arg_iterator - Iterate over the ParmVarDecl's for this block.
-  typedef llvm::SmallVector<ParmVarDecl*, 8>::const_iterator param_iterator;
-  bool param_empty() const { return Args.empty(); }
-  param_iterator param_begin() const { return Args.begin(); }
-  param_iterator param_end() const { return Args.end(); }
+  param_const_iterator param_begin() const { return ParamInfo; }
+  param_const_iterator param_end() const   { return ParamInfo+param_size(); }
+  
+  unsigned getNumParams() const;
+  const ParmVarDecl *getParamDecl(unsigned i) const {
+    assert(i < getNumParams() && "Illegal param #");
+    return ParamInfo[i];
+  }
+  ParmVarDecl *getParamDecl(unsigned i) {
+    assert(i < getNumParams() && "Illegal param #");
+    return ParamInfo[i];
+  }
+  void setParams(ASTContext& C, ParmVarDecl **NewParamInfo, unsigned NumParams);
     
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return D->getKind() == Block; }

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=66904&r1=66903&r2=66904&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Fri Mar 13 11:56:44 2009
@@ -514,3 +514,20 @@
     
   Decl::Destroy(C);
 }
+
+void BlockDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo,
+                          unsigned NParms) {
+  assert(ParamInfo == 0 && "Already has param info!");
+  
+  // Zero params -> null pointer.
+  if (NParms) {
+    NumParams = NParms;
+    void *Mem = C.Allocate(sizeof(ParmVarDecl*)*NumParams);
+    ParamInfo = new (Mem) ParmVarDecl*[NumParams];
+    memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
+  }
+}
+
+unsigned BlockDecl::getNumParams() const {
+  return NumParams;
+}

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=66904&r1=66903&r2=66904&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri Mar 13 11:56:44 2009
@@ -624,7 +624,7 @@
   Args.push_back(std::make_pair(SelfDecl, SelfDecl->getType()));
   BlockStructDecl = SelfDecl;
 
-  for (BlockDecl::param_iterator i = BD->param_begin(),
+  for (BlockDecl::param_const_iterator i = BD->param_begin(),
        e = BD->param_end(); i != e; ++i)
     Args.push_back(std::make_pair(*i, (*i)->getType()));
 

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=66904&r1=66903&r2=66904&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Mar 13 11:56:44 2009
@@ -4595,7 +4595,8 @@
     if (!RetTy->isDependentType())
       CurBlock->ReturnType = RetTy;
   }
-  CurBlock->TheDecl->setArgs(&CurBlock->Params[0], CurBlock->Params.size());
+  CurBlock->TheDecl->setParams(Context, &CurBlock->Params[0], 
+                                        CurBlock->Params.size());
 
   for (BlockDecl::param_iterator AI = CurBlock->TheDecl->param_begin(),
        E = CurBlock->TheDecl->param_end(); AI != E; ++AI)





More information about the cfe-commits mailing list