Handle simple struct member expr.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43258 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp
index 7fbd1f1..c57b38d 100644
--- a/CodeGen/CGExpr.cpp
+++ b/CodeGen/CGExpr.cpp
@@ -101,6 +101,7 @@
return EmitArraySubscriptExpr(cast<ArraySubscriptExpr>(E));
case Expr::OCUVectorElementExprClass:
return EmitOCUVectorElementExpr(cast<OCUVectorElementExpr>(E));
+ case Expr::MemberExprClass: return EmitMemberExpr(cast<MemberExpr>(E));
}
}
@@ -381,6 +382,36 @@
E->getEncodedElementAccess());
}
+LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
+
+ // FIXME: Handle union members.
+ if (E->getBase()->getType()->getAsUnionType()) {
+ fprintf(stderr, "Unimplemented lvalue expr!\n");
+ E->dump(getContext().SourceMgr);
+ llvm::Type *Ty = llvm::PointerType::get(ConvertType(E->getType()));
+ return LValue::MakeAddr(llvm::UndefValue::get(Ty));
+ }
+
+ LValue BaseLV = EmitLValue(E->getBase());
+ llvm::Value *BaseValue = BaseLV.getAddress();
+
+ FieldDecl *Field = E->getMemberDecl();
+ unsigned idx = CGM.getTypes().getLLVMFieldNo(Field);
+ llvm::Value *Idxs[2] = { llvm::Constant::getNullValue(llvm::Type::Int32Ty),
+ llvm::ConstantInt::get(llvm::Type::Int32Ty, idx) };
+ if (E->isArrow()) {
+ QualType PTy = cast<PointerType>(E->getBase()->getType())->getPointeeType();
+ BaseValue = Builder.CreateBitCast(BaseValue,
+ llvm::PointerType::get(ConvertType(PTy)),
+ "tmp");
+ }
+
+ return LValue::MakeAddr(Builder.CreateGEP(BaseValue,Idxs, Idxs + 2, "tmp"));
+
+ // FIXME: If record field does not have one to one match with llvm::StructType
+ // field then apply appropriate masks to select only member field bits.
+}
+
//===--------------------------------------------------------------------===//
// Expression Emission
//===--------------------------------------------------------------------===//