[cfe-commits] r81315 - in /cfe/trunk/lib/CodeGen: CGBlocks.cpp CGDecl.cpp CodeGenFunction.h

Anders Carlsson andersca at mac.com
Tue Sep 8 19:51:03 PDT 2009


Author: andersca
Date: Tue Sep  8 21:51:03 2009
New Revision: 81315

URL: http://llvm.org/viewvc/llvm-project?rev=81315&view=rev
Log:
Make BuildByRefType take a ValueDecl instead of a QualType and an alignment.

Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Tue Sep  8 21:51:03 2009
@@ -185,8 +185,7 @@
       const BlockDeclRefExpr *BDRE = dyn_cast<BlockDeclRefExpr>(E);
       QualType Ty = E->getType();
       if (BDRE && BDRE->isByRef()) {
-        uint64_t Align = getContext().getDeclAlignInBytes(BDRE->getDecl());
-        Types[i+5] = llvm::PointerType::get(BuildByRefType(Ty, Align), 0);
+        Types[i+5] = llvm::PointerType::get(BuildByRefType(BDRE->getDecl()), 0);
       } else
         Types[i+5] = ConvertType(Ty);
     }
@@ -464,9 +463,8 @@
                                      "block.literal");
   if (E->isByRef()) {
     bool needsCopyDispose = BlockRequiresCopying(E->getType());
-    uint64_t Align = getContext().getDeclAlignInBytes(E->getDecl());
     const llvm::Type *PtrStructTy
-      = llvm::PointerType::get(BuildByRefType(E->getType(), Align), 0);
+      = llvm::PointerType::get(BuildByRefType(E->getDecl()), 0);
     // The block literal will need a copy/destroy helper.
     BlockHasCopyDispose = true;
     Ty = PtrStructTy;

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Tue Sep  8 21:51:03 2009
@@ -213,8 +213,10 @@
 ///      } x
 ///
 /// Align is the alignment needed in bytes for x.
-const llvm::Type *CodeGenFunction::BuildByRefType(QualType Ty,
-                                                  uint64_t Align) {
+const llvm::Type *CodeGenFunction::BuildByRefType(const ValueDecl *D) {
+  QualType Ty = D->getType();
+  uint64_t Align = getContext().getDeclAlignInBytes(D);
+  
   const llvm::Type *LTy = ConvertType(Ty);
   bool needsCopyDispose = BlockRequiresCopying(Ty);
   std::vector<const llvm::Type *> Types(needsCopyDispose*2+5);
@@ -251,7 +253,7 @@
       const llvm::Type *LTy = ConvertTypeForMem(Ty);
       Align = getContext().getDeclAlignInBytes(&D);
       if (isByRef)
-        LTy = BuildByRefType(Ty, Align);
+        LTy = BuildByRefType(&D);
       llvm::AllocaInst *Alloc = CreateTempAlloca(LTy);
       Alloc->setName(D.getNameAsString().c_str());
       
@@ -326,6 +328,12 @@
     if (Target.useGlobalsForAutomaticVariables()) {
       DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(DeclPtr), &D);
     } else if (isByRef) {
+      // FIXME: This code is broken and will not emit debug info for the 
+      // variable. The right way to do this would be to tell LLVM that this is a
+      // byref pointer, and what the offset is. Unfortunately, right now it's
+      // not possible unless we create a DIType that corresponds to the byref
+      // struct. 
+      /*
       llvm::Value *Loc;
       bool needsCopyDispose = BlockRequiresCopying(Ty);
       Loc = Builder.CreateStructGEP(DeclPtr, 1, "forwarding");
@@ -333,6 +341,7 @@
       Loc = Builder.CreateBitCast(Loc, DeclPtr->getType());
       Loc = Builder.CreateStructGEP(Loc, needsCopyDispose*2+4, "x");
       DI->EmitDeclareOfAutoVariable(&D, Loc, Builder);
+      */
     } else
       DI->EmitDeclareOfAutoVariable(&D, DeclPtr, Builder);
   }

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=81315&r1=81314&r2=81315&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Sep  8 21:51:03 2009
@@ -343,8 +343,7 @@
   llvm::Value *LoadBlockStruct();
 
   llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E);
-
-  const llvm::Type *BuildByRefType(QualType Ty, uint64_t Align);
+  const llvm::Type *BuildByRefType(const ValueDecl *D);
 
   void GenerateCode(const FunctionDecl *FD,
                     llvm::Function *Fn);





More information about the cfe-commits mailing list