From: Chris Lattner Date: Sun, 26 Aug 2007 22:37:40 +0000 (+0000) Subject: Implement compound assignment operators whose LHS is scalar but RHS is complex. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=04dc76496e869460a1acb7923fc00163c0128b0a;p=clang Implement compound assignment operators whose LHS is scalar but RHS is complex. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41464 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/CodeGen/CGExprScalar.cpp b/CodeGen/CGExprScalar.cpp index ee0ccd644e..1499054b6c 100644 --- a/CodeGen/CGExprScalar.cpp +++ b/CodeGen/CGExprScalar.cpp @@ -554,21 +554,31 @@ Value *ScalarExprEmitter::EmitCompoundAssign(const CompoundAssignOperator *E, // Load the LHS and RHS operands. LValue LHSLV = EmitLValue(E->getLHS()); OpInfo.LHS = EmitLoadOfLValue(LHSLV, LHSTy); + + // Determine the computation type. If the RHS is complex, then this is one of + // the add/sub/mul/div operators. All of these operators can be computed in + // with just their real component even though the computation domain really is + // complex. + QualType ComputeType = E->getComputationType(); - // FIXME: It is possible for the RHS to be complex. - OpInfo.RHS = Visit(E->getRHS()); + // If the computation type is complex, then the RHS is complex. Emit the RHS. + if (const ComplexType *CT = ComputeType->getAsComplexType()) { + ComputeType = CT->getElementType(); + + // Emit the RHS, only keeping the real component. + OpInfo.RHS = CGF.EmitComplexExpr(E->getRHS()).first; + RHSTy = RHSTy->getAsComplexType()->getElementType(); + } else { + // Otherwise the RHS is a simple scalar value. + OpInfo.RHS = Visit(E->getRHS()); + } // Convert the LHS/RHS values to the computation type. - QualType ComputeType = E->getComputationType(); - - // FIXME: it's possible for the computation type to be complex if the RHS - // is complex. Handle this! OpInfo.LHS = EmitScalarConversion(OpInfo.LHS, LHSTy, ComputeType); // Do not merge types for -= where the LHS is a pointer. if (E->getOpcode() != BinaryOperator::SubAssign || !E->getLHS()->getType()->isPointerType()) { - // FIXME: the computation type may be complex. OpInfo.RHS = EmitScalarConversion(OpInfo.RHS, RHSTy, ComputeType); } OpInfo.Ty = ComputeType;