[cfe-commits] r84910 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CGExprAgg.cpp lib/CodeGen/CGExprScalar.cpp lib/CodeGen/CodeGenFunction.h test/CodeGenCXX/ptr-to-datamember.cpp
Fariborz Jahanian
fjahanian at apple.com
Thu Oct 22 15:57:31 PDT 2009
Author: fjahanian
Date: Thu Oct 22 17:57:31 2009
New Revision: 84910
URL: http://llvm.org/viewvc/llvm-project?rev=84910&view=rev
Log:
Complete code gen for '.*' binary expression for
both scalar and aggregates.
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
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=84910&r1=84909&r2=84910&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Oct 22 17:57:31 2009
@@ -1379,6 +1379,9 @@
return EmitLValue(E->getRHS());
}
+ if (E->getOpcode() == BinaryOperator::PtrMemD)
+ return EmitPointerToDataMemberBinaryExpr(E);
+
// Can only get l-value for binary operator expressions which are a
// simple assignment of aggregate type.
if (E->getOpcode() != BinaryOperator::Assign)
@@ -1560,3 +1563,25 @@
CallingConvention),
Callee, Args, TargetDecl);
}
+
+LValue CodeGenFunction::EmitPointerToDataMemberBinaryExpr(
+ const BinaryOperator *E) {
+ llvm::Value *BaseV = EmitLValue(E->getLHS()).getAddress();
+ const llvm::Type *i8Ty = llvm::Type::getInt8PtrTy(getLLVMContext());
+ BaseV = Builder.CreateBitCast(BaseV, i8Ty);
+ LValue RHSLV = EmitLValue(E->getRHS());
+ llvm::Value *OffsetV =
+ EmitLoadOfLValue(RHSLV, E->getRHS()->getType()).getScalarVal();
+ const llvm::Type* ResultType = ConvertType(getContext().getPointerDiffType());
+ OffsetV = Builder.CreateBitCast(OffsetV, ResultType);
+ llvm::Value *AddV = Builder.CreateInBoundsGEP(BaseV, OffsetV, "add.ptr");
+ QualType Ty = E->getRHS()->getType();
+ const MemberPointerType *MemPtrType = Ty->getAs<MemberPointerType>();
+ Ty = MemPtrType->getPointeeType();
+ const llvm::Type* PType =
+ ConvertType(getContext().getPointerType(Ty));
+ AddV = Builder.CreateBitCast(AddV, PType);
+ LValue LV = LValue::MakeAddr(AddV, MakeQualifiers(Ty));
+ return LV;
+}
+
Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=84910&r1=84909&r2=84910&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Thu Oct 22 17:57:31 2009
@@ -92,6 +92,7 @@
void VisitCallExpr(const CallExpr *E);
void VisitStmtExpr(const StmtExpr *E);
void VisitBinaryOperator(const BinaryOperator *BO);
+ void VisitPointerToDataMemberBinaryOperator(const BinaryOperator *BO);
void VisitBinAssign(const BinaryOperator *E);
void VisitBinComma(const BinaryOperator *E);
void VisitUnaryAddrOf(const UnaryOperator *E);
@@ -328,7 +329,16 @@
}
void AggExprEmitter::VisitBinaryOperator(const BinaryOperator *E) {
- CGF.ErrorUnsupported(E, "aggregate binary expression");
+ if (E->getOpcode() == BinaryOperator::PtrMemD)
+ VisitPointerToDataMemberBinaryOperator(E);
+ else
+ CGF.ErrorUnsupported(E, "aggregate binary expression");
+}
+
+void AggExprEmitter::VisitPointerToDataMemberBinaryOperator(
+ const BinaryOperator *E) {
+ LValue LV = CGF.EmitPointerToDataMemberBinaryExpr(E);
+ EmitFinalDestCopy(E, LV);
}
void AggExprEmitter::VisitBinAssign(const BinaryOperator *E) {
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=84910&r1=84909&r2=84910&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu Oct 22 17:57:31 2009
@@ -106,7 +106,6 @@
return 0;
}
Value *VisitExpr(Expr *S);
- Value *VisitPointerToDataMemberBinaryExpr(const BinaryOperator *BExpr);
Value *VisitParenExpr(ParenExpr *PE) { return Visit(PE->getSubExpr()); }
@@ -539,8 +538,11 @@
Value *ScalarExprEmitter::VisitExpr(Expr *E) {
if (const BinaryOperator *BExpr = dyn_cast<BinaryOperator>(E))
- if (BExpr->getOpcode() == BinaryOperator::PtrMemD)
- return VisitPointerToDataMemberBinaryExpr(BExpr);
+ if (BExpr->getOpcode() == BinaryOperator::PtrMemD) {
+ LValue LV = CGF.EmitPointerToDataMemberBinaryExpr(BExpr);
+ Value *InVal = CGF.EmitLoadOfLValue(LV, E->getType()).getScalarVal();
+ return InVal;
+ }
CGF.ErrorUnsupported(E, "scalar expression");
if (E->getType()->isVoidType())
@@ -548,27 +550,6 @@
return llvm::UndefValue::get(CGF.ConvertType(E->getType()));
}
-Value *ScalarExprEmitter::VisitPointerToDataMemberBinaryExpr(
- const BinaryOperator *E) {
- Value *BaseV = EmitLValue(E->getLHS()).getAddress();
- const llvm::Type *i8Ty = llvm::Type::getInt8PtrTy(CGF.getLLVMContext());
- BaseV = Builder.CreateBitCast(BaseV, i8Ty);
- Value *OffsetV = EmitLoadOfLValue(E->getRHS());
- const llvm::Type* ResultType = ConvertType(
- CGF.getContext().getPointerDiffType());
- OffsetV = Builder.CreateBitCast(OffsetV, ResultType);
- Value *AddV = Builder.CreateInBoundsGEP(BaseV, OffsetV, "add.ptr");
- QualType Ty = E->getRHS()->getType();
- const MemberPointerType *MemPtrType = Ty->getAs<MemberPointerType>();
- Ty = MemPtrType->getPointeeType();
- const llvm::Type* PType =
- ConvertType(CGF.getContext().getPointerType(Ty));
- AddV = Builder.CreateBitCast(AddV, PType);
- LValue LV = LValue::MakeAddr(AddV, CGF.MakeQualifiers(Ty));
- Value *InVal = CGF.EmitLoadOfLValue(LV, Ty).getScalarVal();
- return InVal;
-}
-
Value *ScalarExprEmitter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
llvm::SmallVector<llvm::Constant*, 32> indices;
for (unsigned i = 2; i < E->getNumSubExprs(); i++) {
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=84910&r1=84909&r2=84910&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Oct 22 17:57:31 2009
@@ -845,7 +845,8 @@
LValue EmitObjCKVCRefLValue(const ObjCImplicitSetterGetterRefExpr *E);
LValue EmitObjCSuperExprLValue(const ObjCSuperExpr *E);
LValue EmitStmtExprLValue(const StmtExpr *E);
-
+ LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E);
+
//===--------------------------------------------------------------------===//
// Scalar Expression Emission
//===--------------------------------------------------------------------===//
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=84910&r1=84909&r2=84910&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp Thu Oct 22 17:57:31 2009
@@ -2,6 +2,12 @@
extern "C" int printf(...);
+struct F {
+ F() : iF(1), fF(2.0) {}
+ int iF;
+ float fF;
+};
+
struct V {
double d;
int iV;
@@ -23,8 +29,28 @@
float f;
double d;
int Ai;
+ F Af;
};
+void pr(const F& b) {
+ printf(" %d %f\n", b.iF, b.fF);
+}
+
+void test_aggr_pdata(A& a1) {
+ F A::* af = &A::Af;
+ pr(a1.*af);
+
+ (a1.*af).iF = 100;
+ (a1.*af).fF = 200.00;
+ printf(" %d %f\n", (a1.*af).iF, (a1.*af).fF);
+ pr(a1.*af);
+
+ (a1.*af).iF++;
+ (a1.*af).fF--;
+ --(a1.*af).fF;
+ pr(a1.*af);
+}
+
int main()
{
A a1;
@@ -40,4 +66,5 @@
printf("%d\n", &A::B::V::iV);
printf("%d\n", &A::B1::V::iV);
printf("%d, %f, %f \n", a1.*pa, a1.*pf, a1.*pd);
+ test_aggr_pdata(a1);
}
More information about the cfe-commits
mailing list