Skip to content

Commit 5870f78

Browse files
committed
Address review feedback
1 parent d51bb76 commit 5870f78

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
@@ -158,16 +158,13 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
158158

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

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

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

285-
mlir::Value VisitMinus(const UnaryOperator *e) {
272+
mlir::Value emitUnaryPlusOrMinus(const UnaryOperator *e,
273+
cir::UnaryOpKind kind) {
286274
ignoreResultAssign = false;
287275

288276
assert(!cir::MissingFeatures::opUnaryPromotionType());
@@ -292,7 +280,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
292280

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

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

0 commit comments

Comments
 (0)