More member pointer work.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79922 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index 93c0647..2be22f9 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -783,6 +783,10 @@
 }
 
 llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) {
+  // No need to check for member pointers when not compiling C++.
+  if (!getContext().getLangOptions().CPlusPlus)
+    return llvm::Constant::getNullValue(getTypes().ConvertTypeForMem(T));
+    
   if (const ConstantArrayType *CAT = Context.getAsConstantArrayType(T)) {
     
     QualType ElementTy = CAT->getElementType();
@@ -801,15 +805,17 @@
     }
   }
 
-#if 0
   if (const RecordType *RT = T->getAs<RecordType>()) {
-    const CGRecordLayout *Layout = Types.getCGRecordLayout(RT->getDecl());
-    if (Layout->containsMemberPointer()) {
+    const RecordDecl *RD = RT->getDecl();
+    // FIXME: It would be better if there was a way to explicitly compute the 
+    // record layout instead of converting to a type.
+    Types.ConvertTagDeclType(RD);
+    
+    const CGRecordLayout &Layout = Types.getCGRecordLayout(RD);
+    if (Layout.containsMemberPointer()) {
       assert(0 && "FIXME: No support for structs with member pointers yet!");
     }
-
   }
-#endif
   
   // FIXME: Handle structs that contain member pointers.
   if (T->isMemberPointerType()) 
diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp
index 52499d9..48f8192 100644
--- a/lib/CodeGen/CodeGenTypes.cpp
+++ b/lib/CodeGen/CodeGenTypes.cpp
@@ -479,7 +479,7 @@
 }
 
 /// getCGRecordLayout - Return record layout info for the given llvm::Type.
-const CGRecordLayout *
+const CGRecordLayout &
 CodeGenTypes::getCGRecordLayout(const TagDecl *TD) const {
   const Type *Key = 
     Context.getTagDeclType(TD).getTypePtr();
@@ -487,5 +487,5 @@
     = CGRecordLayouts.find(Key);
   assert (I != CGRecordLayouts.end() 
           && "Unable to find record layout information for type");
-  return I->second;
+  return *I->second;
 }
diff --git a/lib/CodeGen/CodeGenTypes.h b/lib/CodeGen/CodeGenTypes.h
index 22ebbf1..f8df1b4 100644
--- a/lib/CodeGen/CodeGenTypes.h
+++ b/lib/CodeGen/CodeGenTypes.h
@@ -162,7 +162,7 @@
   const llvm::FunctionType *GetFunctionType(const CGFunctionInfo &Info,
                                             bool IsVariadic);
   
-  const CGRecordLayout *getCGRecordLayout(const TagDecl*) const;
+  const CGRecordLayout &getCGRecordLayout(const TagDecl*) const;
   
   /// getLLVMFieldNo - Return llvm::StructType element number
   /// that corresponds to the field FD.