diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-10-21 21:01:47 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-10-21 21:01:47 +0000 |
commit | b25817ac1f588c4a0a2e12756c7c5eeb426c6fbb (patch) | |
tree | 5b25182ca7deeb1c340c5b6943247a4f8e88bea5 | |
parent | a93ca3c637e02172d9117409a3711bd2fe811e10 (diff) | |
download | bcm5719-llvm-b25817ac1f588c4a0a2e12756c7c5eeb426c6fbb.tar.gz bcm5719-llvm-b25817ac1f588c4a0a2e12756c7c5eeb426c6fbb.zip |
Expand on code gen. for pointer to data members so it works
for base classe members as well. Test case enhanced for this.
llvm-svn: 84780
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 7 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/ptr-to-datamember.cpp | 28 |
2 files changed, 27 insertions, 8 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 2266b25c682..0b56fa94b79 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -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), diff --git a/clang/test/CodeGenCXX/ptr-to-datamember.cpp b/clang/test/CodeGenCXX/ptr-to-datamember.cpp index 86c771a8b0a..7e945a20dcd 100644 --- a/clang/test/CodeGenCXX/ptr-to-datamember.cpp +++ b/clang/test/CodeGenCXX/ptr-to-datamember.cpp @@ -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); } - - |