@@ -160,16 +160,13 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
160
160
161
161
// TODO(cir): Currently, we store bitwidths in CIR types only for
162
162
// integers. This might also be required for other types.
163
- auto srcCirTy = mlir::dyn_cast<cir::IntType>(cgf.convertType (type));
164
- auto promotedCirTy =
165
- mlir::dyn_cast<cir::IntType>(cgf.convertType (type));
166
- assert (srcCirTy && promotedCirTy && " Expected integer type" );
167
163
168
164
assert (
169
165
(!canPerformLossyDemotionCheck ||
170
166
type->isSignedIntegerOrEnumerationType () ||
171
167
promotedType->isSignedIntegerOrEnumerationType () ||
172
- srcCirTy.getWidth () == promotedCirTy.getWidth ()) &&
168
+ mlir::cast<cir::IntType>(cgf.convertType (type)).getWidth () ==
169
+ mlir::cast<cir::IntType>(cgf.convertType (type)).getWidth ()) &&
173
170
" The following check expects that if we do promotion to different "
174
171
" underlying canonical type, at least one of the types (either "
175
172
" base or promoted) will be signed, or the bitwidths will match." );
@@ -261,30 +258,21 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
261
258
if (!promotionType.isNull ())
262
259
cgf.cgm .errorNYI (e->getSourceRange (), " VisitUnaryPlus: promotionType" );
263
260
assert (!cir::MissingFeatures::opUnaryPromotionType ());
264
- mlir::Value result = VisitPlus (e );
261
+ mlir::Value result = emitUnaryPlusOrMinus (e, cir::UnaryOpKind::Plus );
265
262
return result;
266
263
}
267
264
268
- mlir::Value VisitPlus (const UnaryOperator *e) {
269
- // This differs from gcc, though, most likely due to a bug in gcc.
270
- ignoreResultAssign = false ;
271
-
272
- assert (!cir::MissingFeatures::opUnaryPromotionType ());
273
- mlir::Value operand = Visit (e->getSubExpr ());
274
-
275
- return emitUnaryOp (e, cir::UnaryOpKind::Plus, operand);
276
- }
277
-
278
265
mlir::Value VisitUnaryMinus (const UnaryOperator *e,
279
266
QualType promotionType = QualType()) {
280
267
if (!promotionType.isNull ())
281
268
cgf.cgm .errorNYI (e->getSourceRange (), " VisitUnaryMinus: promotionType" );
282
269
assert (!cir::MissingFeatures::opUnaryPromotionType ());
283
- mlir::Value result = VisitMinus (e );
270
+ mlir::Value result = emitUnaryPlusOrMinus (e, cir::UnaryOpKind::Minus );
284
271
return result;
285
272
}
286
273
287
- mlir::Value VisitMinus (const UnaryOperator *e) {
274
+ mlir::Value emitUnaryPlusOrMinus (const UnaryOperator *e,
275
+ cir::UnaryOpKind kind) {
288
276
ignoreResultAssign = false ;
289
277
290
278
assert (!cir::MissingFeatures::opUnaryPromotionType ());
@@ -294,7 +282,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
294
282
295
283
// NOTE: LLVM codegen will lower this directly to either a FNeg
296
284
// or a Sub instruction. In CIR this will be handled later in LowerToLLVM.
297
- return emitUnaryOp (e, cir::UnaryOpKind::Minus , operand);
285
+ return emitUnaryOp (e, kind , operand);
298
286
}
299
287
300
288
mlir::Value emitUnaryOp (const UnaryOperator *e, cir::UnaryOpKind kind,
0 commit comments