More LValue related code cleanup.

llvm-svn: 86413
This commit is contained in:
Anders Carlsson 2009-11-07 23:06:58 +00:00
parent 2ff6395ddc
commit ea4c30b39a
1 changed files with 27 additions and 18 deletions

View File

@ -813,21 +813,27 @@ static void setObjCGCLValueClass(const ASTContext &Ctx, const Expr *E,
} }
} }
static LValue EmitGlobalVarDeclLValue(CodeGenFunction &CGF,
const Expr *E, const VarDecl *VD) {
assert(VD->hasExternalStorage() || VD->isFileVarDecl() &&
"Var decl must have external storage or be a file var decl!");
llvm::Value *V = CGF.CGM.GetAddrOfGlobalVar(VD);
if (VD->getType()->isReferenceType())
V = CGF.Builder.CreateLoad(V, "tmp");
LValue LV = LValue::MakeAddr(V, CGF.MakeQualifiers(E->getType()));
setObjCGCLValueClass(CGF.getContext(), E, LV);
return LV;
}
LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
const NamedDecl *ND = E->getDecl(); const NamedDecl *ND = E->getDecl();
if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) { if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
LValue LV;
// Check if this is a global variable. // Check if this is a global variable.
if (VD->hasExternalStorage() || VD->isFileVarDecl()) { if (VD->hasExternalStorage() || VD->isFileVarDecl())
llvm::Value *V = CGM.GetAddrOfGlobalVar(VD); return EmitGlobalVarDeclLValue(*this, E, VD);
if (VD->getType()->isReferenceType())
V = Builder.CreateLoad(V, "tmp");
LV = LValue::MakeAddr(V, MakeQualifiers(E->getType()));
setObjCGCLValueClass(getContext(), E, LV);
return LV;
}
bool NonGCable = VD->hasLocalStorage() && !VD->hasAttr<BlocksAttr>(); bool NonGCable = VD->hasLocalStorage() && !VD->hasAttr<BlocksAttr>();
@ -847,7 +853,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
} }
if (VD->getType()->isReferenceType()) if (VD->getType()->isReferenceType())
V = Builder.CreateLoad(V, "tmp"); V = Builder.CreateLoad(V, "tmp");
LV = LValue::MakeAddr(V, Quals); LValue LV = LValue::MakeAddr(V, Quals);
LValue::SetObjCNonGC(LV, NonGCable); LValue::SetObjCNonGC(LV, NonGCable);
setObjCGCLValueClass(getContext(), E, LV); setObjCGCLValueClass(getContext(), E, LV);
return LV; return LV;
@ -1140,14 +1146,17 @@ LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
BaseQuals = BaseTy.getQualifiers(); BaseQuals = BaseTy.getQualifiers();
} }
FieldDecl *Field = dyn_cast<FieldDecl>(E->getMemberDecl()); NamedDecl *ND = E->getMemberDecl();
// FIXME: Handle non-field member expressions if (FieldDecl *Field = dyn_cast<FieldDecl>(ND)) {
assert(Field && "No code generation for non-field member references"); LValue LV = EmitLValueForField(BaseValue, Field, isUnion,
LValue MemExpLV = EmitLValueForField(BaseValue, Field, isUnion, BaseQuals.getCVRQualifiers());
BaseQuals.getCVRQualifiers()); LValue::SetObjCNonGC(LV, isNonGC);
LValue::SetObjCNonGC(MemExpLV, isNonGC); setObjCGCLValueClass(getContext(), E, LV);
setObjCGCLValueClass(getContext(), E, MemExpLV); return LV;
return MemExpLV; }
assert(false && "Unhandled member declaration!");
return LValue();
} }
LValue CodeGenFunction::EmitLValueForBitfield(llvm::Value* BaseValue, LValue CodeGenFunction::EmitLValueForBitfield(llvm::Value* BaseValue,