[cfe-commits] r84771 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h test/CodeGenCXX/ptr-to-datamember.cpp
Fariborz Jahanian
fjahanian at apple.com
Wed Oct 21 11:38:00 PDT 2009
Author: fjahanian
Date: Wed Oct 21 13:38:00 2009
New Revision: 84771
URL: http://llvm.org/viewvc/llvm-project?rev=84771&view=rev
Log:
Code gen for pointer-to-datamember - WIP.
Added:
cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=84771&r1=84770&r2=84771&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Oct 21 13:38:00 2009
@@ -866,6 +866,9 @@
llvm::Value *V = LocalDeclMap[IPD];
assert(V && "BlockVarDecl not entered in LocalDeclMap?");
return LValue::MakeAddr(V, MakeQualifiers(E->getType()));
+ } else if (const QualifiedDeclRefExpr *QDRExpr =
+ dyn_cast<QualifiedDeclRefExpr>(E)) {
+ return EmitPointerToDataMemberLValue(QDRExpr);
}
assert(0 && "Unimp declref");
//an invalid LValue, but the assert will
@@ -1513,6 +1516,24 @@
}
+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));
+ NNSpecTy = getContext().getPointerType(NNSpecTy);
+ llvm::Value *V = llvm::Constant::getNullValue(ConvertType(NNSpecTy));
+ LValue MemExpLV = EmitLValueForField(V, const_cast<FieldDecl*>(Field),
+ /*isUnion*/false, /*Qualifiers*/0);
+ const llvm::Type* ResultType = ConvertType(
+ getContext().getPointerDiffType());
+ V = Builder.CreatePtrToInt(MemExpLV.getAddress(), ResultType,
+ "datamember");
+ LValue LV = LValue::MakeAddr(V, MakeQualifiers(E->getType()));
+ return LV;
+}
+
RValue CodeGenFunction::EmitCall(llvm::Value *Callee, QualType CalleeType,
CallExpr::const_arg_iterator ArgBeg,
CallExpr::const_arg_iterator ArgEnd,
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=84771&r1=84770&r2=84771&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Oct 21 13:38:00 2009
@@ -819,6 +819,7 @@
LValue EmitConditionalOperatorLValue(const ConditionalOperator *E);
LValue EmitCastLValue(const CastExpr *E);
LValue EmitNullInitializationLValue(const CXXZeroInitValueExpr *E);
+ LValue EmitPointerToDataMemberLValue(const QualifiedDeclRefExpr *E);
llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
const ObjCIvarDecl *Ivar);
Added: cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp?rev=84771&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp Wed Oct 21 13:38:00 2009
@@ -0,0 +1,25 @@
+// RUN: clang-cc -emit-llvm -o - %s
+
+extern "C" int printf(...);
+
+class A {
+public:
+ A() : f(1.0), d(2.0), Ai(100) {}
+ float f;
+ double d;
+ int Ai;
+};
+
+int main()
+{
+ A a1;
+ int A::* pa = &A::Ai;
+ float A::* pf = &A::f;
+ double A::* pd = &A::d;
+ printf("%d %d %d\n", &A::Ai, &A::f, &A::d);
+
+ // FIXME. NYI
+ // printf(" %d, %f, %f \n", a1.*pa, a1.f, a1.d);
+}
+
+
More information about the cfe-commits
mailing list