Skip to content

Commit d45d34c

Browse files
committed
Address review feedback
1 parent f73ddec commit d45d34c

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,13 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
160160

161161
// TODO(cir): Currently, we store bitwidths in CIR types only for
162162
// 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");
167163

168164
assert(
169165
(!canPerformLossyDemotionCheck ||
170166
type->isSignedIntegerOrEnumerationType() ||
171167
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()) &&
173170
"The following check expects that if we do promotion to different "
174171
"underlying canonical type, at least one of the types (either "
175172
"base or promoted) will be signed, or the bitwidths will match.");
@@ -261,30 +258,21 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
261258
if (!promotionType.isNull())
262259
cgf.cgm.errorNYI(e->getSourceRange(), "VisitUnaryPlus: promotionType");
263260
assert(!cir::MissingFeatures::opUnaryPromotionType());
264-
mlir::Value result = VisitPlus(e);
261+
mlir::Value result = emitUnaryPlusOrMinus(e, cir::UnaryOpKind::Plus);
265262
return result;
266263
}
267264

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-
278265
mlir::Value VisitUnaryMinus(const UnaryOperator *e,
279266
QualType promotionType = QualType()) {
280267
if (!promotionType.isNull())
281268
cgf.cgm.errorNYI(e->getSourceRange(), "VisitUnaryMinus: promotionType");
282269
assert(!cir::MissingFeatures::opUnaryPromotionType());
283-
mlir::Value result = VisitMinus(e);
270+
mlir::Value result = emitUnaryPlusOrMinus(e, cir::UnaryOpKind::Minus);
284271
return result;
285272
}
286273

287-
mlir::Value VisitMinus(const UnaryOperator *e) {
274+
mlir::Value emitUnaryPlusOrMinus(const UnaryOperator *e,
275+
cir::UnaryOpKind kind) {
288276
ignoreResultAssign = false;
289277

290278
assert(!cir::MissingFeatures::opUnaryPromotionType());
@@ -294,7 +282,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
294282

295283
// NOTE: LLVM codegen will lower this directly to either a FNeg
296284
// 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);
298286
}
299287

300288
mlir::Value emitUnaryOp(const UnaryOperator *e, cir::UnaryOpKind kind,

0 commit comments

Comments
 (0)