@@ -3832,17 +3832,19 @@ Value *ScalarExprEmitter::VisitReal(const UnaryOperator *E,
38323832 // If it's an l-value, load through the appropriate subobject l-value.
38333833 // Note that we have to ask E because Op might be an l-value that
38343834 // this won't work for, e.g. an Obj-C property.
3835- if (E->isGLValue ()) {
3835+ if (E->isGLValue ()) {
38363836 if (!PromotionType.isNull ()) {
38373837 CodeGenFunction::ComplexPairTy result = CGF.EmitComplexExpr (
38383838 Op, /* IgnoreReal*/ IgnoreResultAssign, /* IgnoreImag*/ true );
3839- if (result.first )
3840- result.first = CGF.EmitPromotedValue (result, PromotionType).first ;
3841- return result.first ;
3842- } else {
3843- return CGF.EmitLoadOfLValue (CGF.EmitLValue (E), E->getExprLoc ())
3844- .getScalarVal ();
3839+ PromotionType = PromotionType->isAnyComplexType ()
3840+ ? PromotionType
3841+ : CGF.getContext ().getComplexType (PromotionType);
3842+ return result.first ? CGF.EmitPromotedValue (result, PromotionType).first
3843+ : result.first ;
38453844 }
3845+
3846+ return CGF.EmitLoadOfLValue (CGF.EmitLValue (E), E->getExprLoc ())
3847+ .getScalarVal ();
38463848 }
38473849 // Otherwise, calculate and project.
38483850 return CGF.EmitComplexExpr (Op, false , true ).first ;
@@ -3875,13 +3877,16 @@ Value *ScalarExprEmitter::VisitImag(const UnaryOperator *E,
38753877 if (!PromotionType.isNull ()) {
38763878 CodeGenFunction::ComplexPairTy result = CGF.EmitComplexExpr (
38773879 Op, /* IgnoreReal*/ true , /* IgnoreImag*/ IgnoreResultAssign);
3878- if (result. second )
3879- result. second = CGF. EmitPromotedValue (result, PromotionType). second ;
3880- return result. second ;
3881- } else {
3882- return CGF.EmitLoadOfLValue (CGF. EmitLValue (E), E-> getExprLoc ())
3883- . getScalarVal () ;
3880+ PromotionType = PromotionType-> isAnyComplexType ( )
3881+ ? PromotionType
3882+ : CGF. getContext (). getComplexType (PromotionType) ;
3883+ return result. second
3884+ ? CGF.EmitPromotedValue (result, PromotionType). second
3885+ : result. second ;
38843886 }
3887+
3888+ return CGF.EmitLoadOfLValue (CGF.EmitLValue (E), E->getExprLoc ())
3889+ .getScalarVal ();
38853890 }
38863891 // Otherwise, calculate and project.
38873892 return CGF.EmitComplexExpr (Op, true , false ).second ;
0 commit comments