[cfe-commits] r43315 - in /cfe/trunk: CodeGen/CGExpr.cpp test/CodeGen/struct.c
Devang Patel
dpatel at apple.com
Wed Oct 24 15:26:28 PDT 2007
Author: dpatel
Date: Wed Oct 24 17:26:28 2007
New Revision: 43315
URL: http://llvm.org/viewvc/llvm-project?rev=43315&view=rev
Log:
Handle
foo()->a = 42;
Modified:
cfe/trunk/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGen/struct.c
Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=43315&r1=43314&r2=43315&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Wed Oct 24 17:26:28 2007
@@ -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"));
Modified: cfe/trunk/test/CodeGen/struct.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/struct.c?rev=43315&r1=43314&r2=43315&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/struct.c (original)
+++ cfe/trunk/test/CodeGen/struct.c Wed Oct 24 17:26:28 2007
@@ -55,3 +55,7 @@
void f2() { NB b; }
+extern NB *f3();
+void f4() {
+ f3()->d1 = 42;
+}
More information about the cfe-commits
mailing list