[cfe-commits] r84780 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGenCXX/ptr-to-datamember.cpp

Fariborz Jahanian fjahanian at apple.com
Wed Oct 21 14:01:48 PDT 2009


Author: fjahanian
Date: Wed Oct 21 16:01:47 2009
New Revision: 84780

URL: http://llvm.org/viewvc/llvm-project?rev=84780&view=rev
Log:
Expand on code gen. for pointer to data members so it works
for base classe members as well. Test case enhanced for this.


Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Oct 21 16:01:47 2009
@@ -1519,9 +1519,10 @@
 LValue CodeGenFunction::EmitPointerToDataMemberLValue(
                                               const QualifiedDeclRefExpr *E) {
   const FieldDecl *Field = cast<FieldDecl>(E->getDecl());
-  const NestedNameSpecifier *NNSpec = E->getQualifier();
-  const Type *NNSpecType = NNSpec->getAsType();
-  QualType NNSpecTy = getContext().getCanonicalType(QualType(NNSpecType, 0));
+  const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(Field->getDeclContext());
+  QualType NNSpecTy = 
+    getContext().getCanonicalType(
+      getContext().getTypeDeclType(const_cast<CXXRecordDecl*>(ClassDecl)));
   NNSpecTy = getContext().getPointerType(NNSpecTy);
   llvm::Value *V = llvm::Constant::getNullValue(ConvertType(NNSpecTy));
   LValue MemExpLV = EmitLValueForField(V, const_cast<FieldDecl*>(Field), 

Modified: cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp?rev=84780&r1=84779&r2=84780&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp Wed Oct 21 16:01:47 2009
@@ -2,9 +2,23 @@
 
 extern "C" int printf(...);
 
-class A {
+struct V {
+  double d;
+  int iV;
+};
+
+struct B  : virtual V{
+  double d;
+  int iB;
+};
+
+struct B1  : virtual V{
+  double d;
+  int iB1;
+};
+
+class A  : public B, public B1 {
 public:
-  A() : f(1.0), d(2.0), Ai(100) {}
   float f;
   double d;
   int Ai;
@@ -17,9 +31,13 @@
   float A::* pf = &A::f;
   double A::* pd = &A::d;
   printf("%d %d %d\n", &A::Ai, &A::f, &A::d);
-
+  printf("%d\n", &A::B::iB);
+  printf("%d\n", &A::B1::iB1);
+  printf("%d\n", &A::f);
+  printf("%d\n", &A::B::iV);
+  printf("%d\n", &A::B1::iV);
+  printf("%d\n", &A::B::V::iV);
+  printf("%d\n", &A::B1::V::iV);
   // FIXME. NYI
   //  printf(" %d, %f, %f  \n", a1.*pa, a1.f, a1.d);
 }
-
-





More information about the cfe-commits mailing list