[cfe-commits] r83039 - in /cfe/trunk/lib/CodeGen: CGExprAgg.cpp CGExprConstant.cpp CodeGenFunction.cpp

Anders Carlsson andersca at mac.com
Mon Sep 28 19:09:01 PDT 2009


Author: andersca
Date: Mon Sep 28 21:09:01 2009
New Revision: 83039

URL: http://llvm.org/viewvc/llvm-project?rev=83039&view=rev
Log:
Improve support for member function pointers.

Modified:
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Mon Sep 28 21:09:01 2009
@@ -198,6 +198,21 @@
            "Implicit cast types must be compatible");
     Visit(E->getSubExpr());
     break;
+
+  case CastExpr::CK_NullToMemberPointer: {
+    QualType T = E->getType();
+    const llvm::Type *PtrDiffTy = 
+      CGF.ConvertType(CGF.getContext().getPointerDiffType());
+
+    llvm::Value *NullValue = llvm::Constant::getNullValue(PtrDiffTy);
+    llvm::Value *Ptr = Builder.CreateStructGEP(DestPtr, 0, "ptr");
+    Builder.CreateStore(NullValue, Ptr, VolatileDest);
+    
+    llvm::Value *Adj = Builder.CreateStructGEP(DestPtr, 1, "adj");
+    Builder.CreateStore(NullValue, Adj, VolatileDest);
+
+    break;
+  }
   }
 }
 

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Mon Sep 28 21:09:01 2009
@@ -785,6 +785,13 @@
   return C;
 }
 
+static inline bool isDataMemberPointerType(QualType T) {
+  if (const MemberPointerType *MPT = T->getAs<MemberPointerType>())
+    return !MPT->getPointeeType()->isFunctionType();
+  
+  return false;
+}
+
 llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) {
   // No need to check for member pointers when not compiling C++.
   if (!getContext().getLangOptions().CPlusPlus)
@@ -795,7 +802,7 @@
     QualType ElementTy = CAT->getElementType();
 
     // FIXME: Handle arrays of structs that contain member pointers.
-    if (Context.getBaseElementType(ElementTy)->isMemberPointerType()) {
+    if (isDataMemberPointerType(Context.getBaseElementType(ElementTy))) {
       llvm::Constant *Element = EmitNullConstant(ElementTy);
       uint64_t NumElements = CAT->getSize().getZExtValue();
       std::vector<llvm::Constant *> Array(NumElements);
@@ -821,7 +828,7 @@
   }
 
   // FIXME: Handle structs that contain member pointers.
-  if (T->isMemberPointerType())
+  if (isDataMemberPointerType(T))
     return llvm::Constant::getAllOnesValue(getTypes().ConvertTypeForMem(T));
 
   return llvm::Constant::getNullValue(getTypes().ConvertTypeForMem(T));

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Mon Sep 28 21:09:01 2009
@@ -66,7 +66,8 @@
 }
 
 bool CodeGenFunction::hasAggregateLLVMType(QualType T) {
-  return T->isRecordType() || T->isArrayType() || T->isAnyComplexType();
+  return T->isRecordType() || T->isArrayType() || T->isAnyComplexType() ||
+    T->isMemberFunctionPointerType();
 }
 
 void CodeGenFunction::EmitReturnBlock() {





More information about the cfe-commits mailing list