diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 12900e8b9d3a..66aeea3540c8 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -82,7 +82,7 @@ RValue CodeGenFunction::EmitAnyExpr(const Expr *E, llvm::Value *AggLoc, LValue CodeGenFunction::EmitLValue(const Expr *E) { switch (E->getStmtClass()) { default: { - printf("Statement class: %d\n", E->getStmtClass()); + printf("Statement class: %d\n", E->getStmtClass()); WarnUnsupported(E, "l-value expression"); llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType())); return LValue::MakeAddr(llvm::UndefValue::get(Ty)); @@ -566,32 +566,27 @@ LValue CodeGenFunction::EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E) { // a class without recompiling all of the subclasses. If this is the case // then the CGObjCRuntime subclass must return true to LateBoundIvars and // implement the lookup itself. - if(CGM.getObjCRuntime()->LateBoundIVars()) { + if (CGM.getObjCRuntime()->LateBoundIVars()) { assert(0 && "FIXME: Implement support for late-bound instance variables"); return LValue(); // Not reached. } - else { - // Get a structure type for the object - QualType ExprTy = E->getBase()->getType(); - const llvm::Type *ObjectType = ConvertType(ExprTy); - //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 a structure type for the object + QualType ExprTy = E->getBase()->getType(); + const llvm::Type *ObjectType = ConvertType(ExprTy); + // 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 - llvm::Value * Object = EmitLValue(E->getBase()).getAddress(); - // Coerce object pointer to correct type. - if (Object->getType() != ObjectType) { - Object = Builder.CreateBitCast(Object, ObjectType); - } - // Get the correct element - llvm::Value * Element = Builder.CreateStructGEP(Object, - Index, - Decl->getName()); - // Element = Builder.CreateLoad(Element); - return LValue::MakeAddr(Element); - } + // Get object pointer and coerce object pointer to correct type. + llvm::Value *Object = EmitLValue(E->getBase()).getAddress(); + if (Object->getType() != ObjectType) + Object = Builder.CreateBitCast(Object, ObjectType); + + // Return a pointer to the right element. + return LValue::MakeAddr(Builder.CreateStructGEP(Object, Index, + Decl->getName())); } RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType, diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 6c5326105fea..9497ece6fbd4 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -19,7 +19,6 @@ #include "llvm/GlobalVariable.h" #include "llvm/Intrinsics.h" #include "llvm/Support/Compiler.h" -#include "llvm/ValueSymbolTable.h" #include using namespace clang; @@ -51,7 +50,6 @@ public: Builder(CGF.Builder), Runtime(CGF.CGM.getObjCRuntime()) { } - //===--------------------------------------------------------------------===// // Utilities @@ -127,7 +125,7 @@ public: return EmitLoadOfLValue(E); } Value *VisitObjCMessageExpr(ObjCMessageExpr *E); - Value *VisitObjCIvarRefExpr(ObjCIvarRefExpr *E); + Value *VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { return EmitLoadOfLValue(E);} Value *VisitArraySubscriptExpr(ArraySubscriptExpr *E); Value *VisitMemberExpr(Expr *E) { return EmitLoadOfLValue(E); } Value *VisitOCUVectorElementExpr(Expr *E) { return EmitLoadOfLValue(E); } @@ -451,22 +449,18 @@ Value *ScalarExprEmitter::VisitExpr(Expr *E) { return llvm::UndefValue::get(CGF.ConvertType(E->getType())); } -Value *ScalarExprEmitter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { - return Builder.CreateLoad(CGF.EmitObjCIvarRefLValue(E).getAddress()); -} - Value *ScalarExprEmitter::VisitObjCMessageExpr(ObjCMessageExpr *E) { // Only the lookup mechanism and first two arguments of the method // implementation vary between runtimes. We can get the receiver and // arguments in generic code. // Find the receiver - llvm::Value * Receiver = CGF.EmitScalarExpr(E->getReceiver()); + llvm::Value *Receiver = CGF.EmitScalarExpr(E->getReceiver()); // Process the arguments - unsigned int ArgC = E->getNumArgs(); + unsigned ArgC = E->getNumArgs(); llvm::SmallVector Args; - for(unsigned i=0 ; igetArg(i); QualType ArgTy = ArgExpr->getType(); if (!CGF.hasAggregateLLVMType(ArgTy)) { @@ -489,13 +483,11 @@ Value *ScalarExprEmitter::VisitObjCMessageExpr(ObjCMessageExpr *E) { llvm::Constant *Selector = CGF.CGM.GetAddrOfConstantString(SelStr); llvm::Value *SelPtr = Builder.CreateStructGEP(Selector, 0); - return Runtime->generateMessageSend(Builder, - ConvertType(E->getType()), - CGF.CurFn->getValueSymbolTable().lookup("self"), - Receiver, - SelPtr, - &Args[0], - Args.size()); + return Runtime->generateMessageSend(Builder, ConvertType(E->getType()), + // FIXME: Self can be assigned to! + CGF.CurFn->arg_begin(), + Receiver, SelPtr, + &Args[0], Args.size()); } Value *ScalarExprEmitter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) { diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 3e811a73b71d..5f47bb78c6bd 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -26,7 +26,7 @@ using namespace CodeGen; CodeGenFunction::CodeGenFunction(CodeGenModule &cgm) : CGM(cgm), Target(CGM.getContext().Target), SwitchInsn(NULL), - CaseRangeBlock(NULL) {} + CaseRangeBlock(NULL) {} ASTContext &CodeGenFunction::getContext() const { return CGM.getContext(); @@ -64,11 +64,11 @@ void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) { for (unsigned i=0 ; iparam_size() ; i++) { ParamTypes.push_back(ConvertType(OMD->getParamDecl(i)->getType())); } - CurFn = CGM.getObjCRuntime()->MethodPreamble(ConvertType(OMD->getResultType()), - llvm::PointerType::getUnqual(llvm::Type::Int32Ty), - ParamTypes.begin(), - OMD->param_size(), - OMD->isVariadic()); + CurFn =CGM.getObjCRuntime()->MethodPreamble(ConvertType(OMD->getResultType()), + llvm::PointerType::getUnqual(llvm::Type::Int32Ty), + ParamTypes.begin(), + OMD->param_size(), + OMD->isVariadic()); llvm::BasicBlock *EntryBB = new llvm::BasicBlock("entry", CurFn); // Create a marker to make it easy to insert allocas into the entryblock diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 8374f2bab6c0..21b372b3477b 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -41,9 +41,8 @@ CodeGenModule::CodeGenModule(ASTContext &C, const LangOptions &LO, CodeGenModule::~CodeGenModule() { llvm::Function *ObjCInitFunction = Runtime->ModuleInitFunction(); - if (ObjCInitFunction) { + if (ObjCInitFunction) AddGlobalCtor(ObjCInitFunction); - } EmitGlobalCtors(); delete Runtime; } @@ -80,15 +79,15 @@ void CodeGenModule::AddGlobalCtor(llvm::Function * Ctor) { /// called on module load, if any have been registered with AddGlobalCtor. void CodeGenModule::EmitGlobalCtors() { if (GlobalCtors.empty()) return; + // Get the type of @llvm.global_ctors std::vector CtorFields; CtorFields.push_back(llvm::IntegerType::get(32)); // Constructor function type std::vector VoidArgs; - llvm::FunctionType* CtorFuncTy = llvm::FunctionType::get( - llvm::Type::VoidTy, - VoidArgs, - false); + llvm::FunctionType* CtorFuncTy = + llvm::FunctionType::get(llvm::Type::VoidTy, VoidArgs, false); + // i32, function type pair const llvm::Type *FPType = llvm::PointerType::getUnqual(CtorFuncTy); llvm::StructType* CtorStructTy = @@ -120,7 +119,6 @@ void CodeGenModule::EmitGlobalCtors() { GlobalCtorsVal->setInitializer(llvm::ConstantArray::get(GlobalCtorsTy, CtorValues)); - } diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp index afa20e411071..a16543eebeb7 100644 --- a/clang/lib/CodeGen/CodeGenTypes.cpp +++ b/clang/lib/CodeGen/CodeGenTypes.cpp @@ -148,16 +148,14 @@ void CodeGenTypes::UpdateCompletedType(const TagDecl *TD) { /// Objective-C object, in the order that they appear. Used to create LLVM /// structures corresponding to Objective-C objects. void CodeGenTypes::CollectObjCIvarTypes(ObjCInterfaceDecl *ObjCClass, - std::vector &IvarTypes) { + std::vector &IvarTypes) { ObjCInterfaceDecl *SuperClass = ObjCClass->getSuperClass(); - if(SuperClass) { + if (SuperClass) CollectObjCIvarTypes(SuperClass, IvarTypes); - } - for(ObjCInterfaceDecl::ivar_iterator ivar=ObjCClass->ivar_begin() ; - ivar != ObjCClass->ivar_end() ; - ivar++) { - IvarTypes.push_back(ConvertType((*ivar)->getType())); - ObjCIvarInfo[*ivar] = IvarTypes.size() - 1; + for (ObjCInterfaceDecl::ivar_iterator I = ObjCClass->ivar_begin(), + E = ObjCClass->ivar_end(); I != E; ++I) { + IvarTypes.push_back(ConvertType((*I)->getType())); + ObjCIvarInfo[*I] = IvarTypes.size() - 1; } } @@ -420,8 +418,7 @@ const llvm::Type *CodeGenTypes::ConvertTagDeclType(const TagDecl *TD) { /// getLLVMFieldNo - Return llvm::StructType element number /// that corresponds to the field FD. unsigned CodeGenTypes::getLLVMFieldNo(const FieldDecl *FD) { - llvm::DenseMap::iterator - I = FieldInfo.find(FD); + llvm::DenseMap::iterator I = FieldInfo.find(FD); assert (I != FieldInfo.end() && "Unable to find field info"); return I->second; } @@ -429,7 +426,7 @@ unsigned CodeGenTypes::getLLVMFieldNo(const FieldDecl *FD) { unsigned CodeGenTypes::getLLVMFieldNo(const ObjCIvarDecl *OID) { llvm::DenseMap::iterator I = ObjCIvarInfo.find(OID); - assert (I != ObjCIvarInfo.end() && "Unable to find field info"); + assert(I != ObjCIvarInfo.end() && "Unable to find field info"); return I->second; }