From: Anders Carlsson Date: Mon, 25 Aug 2008 01:53:23 +0000 (+0000) Subject: Make code generation of ivar ref exprs more like member exprs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29b7e5071c4ac0979ba907d0db78f5bd7ff83fe8;p=clang Make code generation of ivar ref exprs more like member exprs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55298 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index a191610d1f..de0f634bdf 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -762,27 +762,33 @@ LValue CodeGenFunction::EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E) { assert(0 && "FIXME: Implement support for late-bound instance variables"); return LValue(); // Not reached. } + + // FIXME: A lot of the code below could be shared with EmitMemberExpr. + llvm::Value *BaseValue = 0; + const Expr *BaseExpr = E->getBase(); + unsigned CVRQualifiers = 0; + if (E->isArrow()) { + BaseValue = EmitScalarExpr(BaseExpr); + const PointerType *PTy = + cast(getContext().getCanonicalType(BaseExpr->getType())); + CVRQualifiers = PTy->getPointeeType().getCVRQualifiers(); + } else { + LValue BaseLV = EmitLValue(BaseExpr); + // FIXME: this isn't right for bitfields. + BaseValue = BaseLV.getAddress(); + CVRQualifiers = BaseExpr->getType().getCVRQualifiers(); + } - // Get a structure type for the object - QualType ExprTy = E->getBase()->getType(); - const llvm::Type *ObjectType = ConvertType(ExprTy); + const ObjCIvarDecl *Field = E->getDecl(); + assert(!Field->isBitField() && + "Bitfields are currently not supported!"); + // TODO: Add a special case for isa (index 0) - // Work out which index the ivar is - const ObjCIvarDecl *Decl = E->getDecl(); - unsigned Index = CGM.getTypes().getLLVMFieldNo(Decl); - - // Get object pointer and coerce object pointer to correct type. - llvm::Value *Object = EmitLValue(E->getBase()).getAddress(); - // FIXME: Volatility - Object = Builder.CreateLoad(Object, E->getDecl()->getName()); - if (Object->getType() != ObjectType) - Object = Builder.CreateBitCast(Object, ObjectType); - - - // Return a pointer to the right element. - // FIXME: volatile - return LValue::MakeAddr(Builder.CreateStructGEP(Object, Index, - Decl->getName()),0); + unsigned Index = CGM.getTypes().getLLVMFieldNo(Field); + + llvm::Value *V = Builder.CreateStructGEP(BaseValue, Index, "tmp"); + return LValue::MakeAddr(V, + Field->getType().getCVRQualifiers()|CVRQualifiers); } RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType,