]> granicus.if.org Git - clang/commitdiff
Expand on code gen. for pointer to data members so it works
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 21 Oct 2009 21:01:47 +0000 (21:01 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 21 Oct 2009 21:01:47 +0000 (21:01 +0000)
for base classe members as well. Test case enhanced for this.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84780 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
test/CodeGenCXX/ptr-to-datamember.cpp

index 2266b25c682ffd105f800bf9581ef5db0d634278..0b56fa94b795075d842d0870cb452c170713550a 100644 (file)
@@ -1519,9 +1519,10 @@ LValue CodeGenFunction::EmitStmtExprLValue(const StmtExpr *E) {
 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), 
index 86c771a8b0a21b5d821df98f3416e7595599bf46..7e945a20dcdb167ae7fdc3feeda8364332f54317 100644 (file)
@@ -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 @@ int main()
   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);
 }
-
-