@@ -88,13 +88,11 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
88
88
// ===--------------------------------------------------------------------===//
89
89
90
90
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));
93
92
}
94
93
95
94
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));
98
96
}
99
97
100
98
mlir::Value emitPromoted (const Expr *e, QualType promotionType);
@@ -448,36 +446,34 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
448
446
llvm_unreachable (" Unexpected signed overflow behavior kind" );
449
447
}
450
448
451
- mlir::Value VisitUnaryPlus (const UnaryOperator *e,
452
- QualType promotionType = QualType()) {
453
- if (!promotionType.isNull ())
454
- cgf.cgm .errorNYI (e->getSourceRange (), " VisitUnaryPlus: promotionType" );
455
- assert (!cir::MissingFeatures::opUnaryPromotionType ());
456
- mlir::Value result = emitUnaryPlusOrMinus (e, cir::UnaryOpKind::Plus);
457
- return result;
449
+ mlir::Value VisitUnaryPlus (const UnaryOperator *e) {
450
+ return emitUnaryPlusOrMinus (e, cir::UnaryOpKind::Plus);
458
451
}
459
452
460
- mlir::Value VisitUnaryMinus (const UnaryOperator *e,
461
- QualType promotionType = QualType()) {
462
- if (!promotionType.isNull ())
463
- cgf.cgm .errorNYI (e->getSourceRange (), " VisitUnaryMinus: promotionType" );
464
- assert (!cir::MissingFeatures::opUnaryPromotionType ());
465
- mlir::Value result = emitUnaryPlusOrMinus (e, cir::UnaryOpKind::Minus);
466
- return result;
453
+ mlir::Value VisitUnaryMinus (const UnaryOperator *e) {
454
+ return emitUnaryPlusOrMinus (e, cir::UnaryOpKind::Minus);
467
455
}
468
456
469
457
mlir::Value emitUnaryPlusOrMinus (const UnaryOperator *e,
470
458
cir::UnaryOpKind kind) {
471
459
ignoreResultAssign = false ;
472
460
473
- assert (!cir::MissingFeatures::opUnaryPromotionType ());
474
- mlir::Value operand = Visit (e->getSubExpr ());
461
+ QualType promotionType = getPromotionType (e->getSubExpr ()->getType ());
462
+
463
+ mlir::Value operand;
464
+ if (!promotionType.isNull ())
465
+ operand = cgf.emitPromotedScalarExpr (e->getSubExpr (), promotionType);
466
+ else
467
+ operand = Visit (e->getSubExpr ());
475
468
476
469
assert (!cir::MissingFeatures::opUnarySignedOverflow ());
477
470
478
471
// NOTE: LLVM codegen will lower this directly to either a FNeg
479
472
// or a Sub instruction. In CIR this will be handled later in LowerToLLVM.
480
- return emitUnaryOp (e, kind, operand);
473
+ mlir::Value result = emitUnaryOp (e, kind, operand);
474
+ if (result && !promotionType.isNull ())
475
+ return emitUnPromotedValue (result, e->getType ());
476
+ return result;
481
477
}
482
478
483
479
mlir::Value emitUnaryOp (const UnaryOperator *e, cir::UnaryOpKind kind,
0 commit comments