From: Rafael Espindola Date: Sat, 27 Oct 2012 00:40:06 +0000 (+0000) Subject: Refactor some code into a new skipRValueSubobjectAdjustments function. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=582e185a5a9dc5fb9c347f370f530499d1fe5181;p=clang Refactor some code into a new skipRValueSubobjectAdjustments function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166848 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index a9777478d2..11dd064270 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -227,6 +227,52 @@ CreateReferenceTemporary(CodeGenFunction &CGF, QualType Type, return CGF.CreateMemTemp(Type, "ref.tmp"); } +static const Expr * +skipRValueSubobjectAdjustments(const Expr *E, + SmallVectorImpl &Adjustments) { + while (true) { + E = E->IgnoreParens(); + + if (const CastExpr *CE = dyn_cast(E)) { + if ((CE->getCastKind() == CK_DerivedToBase || + CE->getCastKind() == CK_UncheckedDerivedToBase) && + E->getType()->isRecordType()) { + E = CE->getSubExpr(); + CXXRecordDecl *Derived + = cast(E->getType()->getAs()->getDecl()); + Adjustments.push_back(SubobjectAdjustment(CE, Derived)); + continue; + } + + if (CE->getCastKind() == CK_NoOp) { + E = CE->getSubExpr(); + continue; + } + } else if (const MemberExpr *ME = dyn_cast(E)) { + if (!ME->isArrow() && ME->getBase()->isRValue()) { + assert(ME->getBase()->getType()->isRecordType()); + if (FieldDecl *Field = dyn_cast(ME->getMemberDecl())) { + E = ME->getBase(); + Adjustments.push_back(SubobjectAdjustment(Field)); + continue; + } + } + } else if (const BinaryOperator *BO = dyn_cast(E)) { + if (BO->isPtrMemOp()) { + assert(BO->getLHS()->isRValue()); + E = BO->getLHS(); + const MemberPointerType *MPT = + BO->getRHS()->getType()->getAs(); + Adjustments.push_back(SubobjectAdjustment(MPT, BO->getRHS())); + } + } + + // Nothing changed. + break; + } + return E; +} + static llvm::Value * EmitExprForReferenceBinding(CodeGenFunction &CGF, const Expr *E, llvm::Value *&ReferenceTemporary, @@ -336,53 +382,13 @@ EmitExprForReferenceBinding(CodeGenFunction &CGF, const Expr *E, return ReferenceTemporary; } - - SmallVector Adjustments; - while (true) { - E = E->IgnoreParens(); - - if (const CastExpr *CE = dyn_cast(E)) { - if ((CE->getCastKind() == CK_DerivedToBase || - CE->getCastKind() == CK_UncheckedDerivedToBase) && - E->getType()->isRecordType()) { - E = CE->getSubExpr(); - CXXRecordDecl *Derived - = cast(E->getType()->getAs()->getDecl()); - Adjustments.push_back(SubobjectAdjustment(CE, Derived)); - continue; - } - - if (CE->getCastKind() == CK_NoOp) { - E = CE->getSubExpr(); - continue; - } - } else if (const MemberExpr *ME = dyn_cast(E)) { - if (!ME->isArrow() && ME->getBase()->isRValue()) { - assert(ME->getBase()->getType()->isRecordType()); - if (FieldDecl *Field = dyn_cast(ME->getMemberDecl())) { - E = ME->getBase(); - Adjustments.push_back(SubobjectAdjustment(Field)); - continue; - } - } - } else if (const BinaryOperator *BO = dyn_cast(E)) { - if (BO->isPtrMemOp()) { - assert(BO->getLHS()->isRValue()); - E = BO->getLHS(); - const MemberPointerType *MPT = - BO->getRHS()->getType()->getAs(); - Adjustments.push_back(SubobjectAdjustment(MPT, BO->getRHS())); - } - } - if (const OpaqueValueExpr *opaque = dyn_cast(E)) - if (opaque->getType()->isRecordType()) - return CGF.EmitOpaqueValueLValue(opaque).getAddress(); + SmallVector Adjustments; + E = skipRValueSubobjectAdjustments(E, Adjustments); + if (const OpaqueValueExpr *opaque = dyn_cast(E)) + if (opaque->getType()->isRecordType()) + return CGF.EmitOpaqueValueLValue(opaque).getAddress(); - // Nothing changed. - break; - } - // Create a reference temporary if necessary. AggValueSlot AggSlot = AggValueSlot::ignored(); if (CGF.hasAggregateLLVMType(E->getType()) &&