@@ -619,38 +619,26 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
619619 QualType promotionTy = PromotionType.isNull ()
620620 ? getPromotionType (E->getSubExpr ()->getType ())
621621 : PromotionType;
622- auto result = VisitPlus (E , promotionTy);
622+ auto result = emitUnaryPlusOrMinus (E, cir::UnaryOpKind::Plus , promotionTy);
623623 if (result && !promotionTy.isNull ())
624624 return emitUnPromotedValue (result, E->getType ());
625625 return result;
626626 }
627627
628- mlir::Value VisitPlus (const UnaryOperator *E,
629- QualType PromotionType = QualType()) {
630- // This differs from gcc, though, most likely due to a bug in gcc.
631- TestAndClearIgnoreResultAssign ();
632-
633- mlir::Value operand;
634- if (!PromotionType.isNull ())
635- operand = CGF.emitPromotedScalarExpr (E->getSubExpr (), PromotionType);
636- else
637- operand = Visit (E->getSubExpr ());
638-
639- return emitUnaryOp (E, cir::UnaryOpKind::Plus, operand);
640- }
641-
642628 mlir::Value VisitUnaryMinus (const UnaryOperator *E,
643629 QualType PromotionType = QualType()) {
644630 QualType promotionTy = PromotionType.isNull ()
645631 ? getPromotionType (E->getSubExpr ()->getType ())
646632 : PromotionType;
647- auto result = VisitMinus (E , promotionTy);
633+ auto result = emitUnaryPlusOrMinus (E, cir::UnaryOpKind::Minus , promotionTy);
648634 if (result && !promotionTy.isNull ())
649635 return emitUnPromotedValue (result, E->getType ());
650636 return result;
651637 }
652638
653- mlir::Value VisitMinus (const UnaryOperator *E, QualType PromotionType) {
639+ mlir::Value emitUnaryPlusOrMinus (const UnaryOperator *E,
640+ cir::UnaryOpKind kind,
641+ QualType PromotionType) {
654642 TestAndClearIgnoreResultAssign ();
655643
656644 mlir::Value operand;
@@ -661,7 +649,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
661649
662650 // NOTE: LLVM codegen will lower this directly to either a FNeg
663651 // or a Sub instruction. In CIR this will be handled later in LowerToLLVM.
664- return emitUnaryOp (E, cir::UnaryOpKind::Minus , operand);
652+ return emitUnaryOp (E, kind , operand);
665653 }
666654
667655 mlir::Value VisitUnaryNot (const UnaryOperator *E) {
@@ -2335,9 +2323,9 @@ mlir::Value ScalarExprEmitter::emitPromoted(const Expr *E,
23352323 case UO_Real:
23362324 llvm_unreachable (" NYI" );
23372325 case UO_Minus:
2338- return VisitMinus (UO, PromotionType);
2326+ return emitUnaryPlusOrMinus (UO, cir::UnaryOpKind::Minus , PromotionType);
23392327 case UO_Plus:
2340- return VisitPlus (UO, PromotionType);
2328+ return emitUnaryPlusOrMinus (UO, cir::UnaryOpKind::Plus , PromotionType);
23412329 default :
23422330 break ;
23432331 }
0 commit comments