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