@@ -88,13 +88,11 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
8888 // ===--------------------------------------------------------------------===//
8989
9090 mlir::Value emitPromotedValue (mlir::Value result, QualType promotionType) {
91- cgf.cgm .errorNYI (result.getLoc (), " floating cast for promoted value" );
92- return {};
91+ return builder.createFloatingCast (result, cgf.convertType (promotionType));
9392 }
9493
9594 mlir::Value emitUnPromotedValue (mlir::Value result, QualType exprType) {
96- cgf.cgm .errorNYI (result.getLoc (), " floating cast for unpromoted value" );
97- return {};
95+ return builder.createFloatingCast (result, cgf.convertType (exprType));
9896 }
9997
10098 mlir::Value emitPromoted (const Expr *e, QualType promotionType);
@@ -446,37 +444,35 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
446444 llvm_unreachable (" Unexpected signed overflow behavior kind" );
447445 }
448446
449- mlir::Value VisitUnaryPlus (const UnaryOperator *e,
450- QualType promotionType = QualType()) {
451- if (!promotionType.isNull ())
452- cgf.cgm .errorNYI (e->getSourceRange (), " VisitUnaryPlus: promotionType" );
453- assert (!cir::MissingFeatures::opUnaryPromotionType ());
454- mlir::Value result = emitUnaryPlusOrMinus (e, cir::UnaryOpKind::Plus);
455- return result;
447+ mlir::Value VisitUnaryPlus (const UnaryOperator *e) {
448+ return emitUnaryPlusOrMinus (e, cir::UnaryOpKind::Plus);
456449 }
457450
458- mlir::Value VisitUnaryMinus (const UnaryOperator *e,
459- QualType promotionType = QualType()) {
460- if (!promotionType.isNull ())
461- cgf.cgm .errorNYI (e->getSourceRange (), " VisitUnaryMinus: promotionType" );
462- assert (!cir::MissingFeatures::opUnaryPromotionType ());
463- mlir::Value result = emitUnaryPlusOrMinus (e, cir::UnaryOpKind::Minus);
464- return result;
451+ mlir::Value VisitUnaryMinus (const UnaryOperator *e) {
452+ return emitUnaryPlusOrMinus (e, cir::UnaryOpKind::Minus);
465453 }
466454
467455 mlir::Value emitUnaryPlusOrMinus (const UnaryOperator *e,
468456 cir::UnaryOpKind kind) {
469457 ignoreResultAssign = false ;
470458
471- assert (!cir::MissingFeatures::opUnaryPromotionType ());
472- mlir::Value operand = Visit (e->getSubExpr ());
459+ QualType promotionType = getPromotionType (e->getSubExpr ()->getType ());
460+
461+ mlir::Value operand;
462+ if (!promotionType.isNull ())
463+ operand = cgf.emitPromotedScalarExpr (e->getSubExpr (), promotionType);
464+ else
465+ operand = Visit (e->getSubExpr ());
473466
474467 bool nsw =
475468 kind == cir::UnaryOpKind::Minus && e->getType ()->isSignedIntegerType ();
476469
477470 // NOTE: LLVM codegen will lower this directly to either a FNeg
478471 // or a Sub instruction. In CIR this will be handled later in LowerToLLVM.
479- return emitUnaryOp (e, kind, operand, nsw);
472+ mlir::Value result = emitUnaryOp (e, kind, operand, nsw);
473+ if (result && !promotionType.isNull ())
474+ return emitUnPromotedValue (result, e->getType ());
475+ return result;
480476 }
481477
482478 mlir::Value emitUnaryOp (const UnaryOperator *e, cir::UnaryOpKind kind,
0 commit comments