Handle
foo()->a = 42;
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43315 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp
index f6e772d..b03caaa 100644
--- a/CodeGen/CGExpr.cpp
+++ b/CodeGen/CGExpr.cpp
@@ -384,27 +384,36 @@
LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
+ Expr *BaseExpr = E->getBase();
// FIXME: Handle union members.
- if (E->getBase()->getType()->isUnionType()) {
+ if (BaseExpr->getType()->isUnionType()) {
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();
+
+ llvm::Value *BaseValue = NULL;
+ if (const CallExpr *CE = dyn_cast<CallExpr>(BaseExpr)) {
+ RValue Base = EmitCallExpr(CE);
+ BaseValue = Base.getScalarVal();
+ }
+ else {
+ LValue BaseLV = EmitLValue(BaseExpr);
+ BaseValue = BaseLV.getAddress();
+
+ if (E->isArrow()) {
+ QualType PTy = cast<PointerType>(BaseExpr->getType())->getPointeeType();
+ BaseValue = Builder.CreateBitCast(BaseValue,
+ llvm::PointerType::get(ConvertType(PTy)),
+ "tmp");
+ }
+ }
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"));