Skip to content

Commit 4428f8b

Browse files
committed
- Revert ASTContecxt refactor
- return nullptr -> {} - Add braces after else
1 parent 455edf2 commit 4428f8b

File tree

5 files changed

+47
-32
lines changed

5 files changed

+47
-32
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,9 +2999,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
29992999
/// 6.3.1.1p2, assuming that \p PromotableType is a promotable integer type.
30003000
QualType getPromotedIntegerType(QualType PromotableType) const;
30013001

3002-
/// If \p E is a widened promoted integer, get its base (unpromoted) type.
3003-
std::optional<QualType> getUnwidenedIntegerType(const Expr *E) const;
3004-
30053002
/// Recurses in pointer/array types until it finds an Objective-C
30063003
/// retainable type and returns its ownership.
30073004
Qualifiers::ObjCLifetime getInnerObjCOwnership(QualType T) const;

clang/lib/AST/ASTContext.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7998,22 +7998,6 @@ QualType ASTContext::getPromotedIntegerType(QualType Promotable) const {
79987998
return (PromotableSize != IntSize) ? IntTy : UnsignedIntTy;
79997999
}
80008000

8001-
/// getUnwidenedIntegerType - If \p E is a widened promoted integer, get its
8002-
/// base (unpromoted) type.
8003-
std::optional<QualType>
8004-
ASTContext::getUnwidenedIntegerType(const Expr *E) const {
8005-
const Expr *Base = E->IgnoreImpCasts();
8006-
if (E == Base)
8007-
return std::nullopt;
8008-
8009-
QualType BaseTy = Base->getType();
8010-
if (!isPromotableIntegerType(BaseTy) ||
8011-
getTypeSize(BaseTy) >= getTypeSize(E->getType()))
8012-
return std::nullopt;
8013-
8014-
return BaseTy;
8015-
}
8016-
80178001
/// Recurses in pointer/array types until it finds an objc retainable
80188002
/// type and returns its ownership.
80198003
Qualifiers::ObjCLifetime ASTContext::getInnerObjCOwnership(QualType T) const {

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
8989

9090
mlir::Value emitPromotedValue(mlir::Value result, QualType promotionType) {
9191
cgf.cgm.errorNYI(result.getLoc(), "floating cast for promoted value");
92-
return nullptr;
92+
return {};
9393
}
9494

9595
mlir::Value emitUnPromotedValue(mlir::Value result, QualType exprType) {
9696
cgf.cgm.errorNYI(result.getLoc(), "floating cast for unpromoted value");
97-
return nullptr;
97+
return {};
9898
}
9999

100100
mlir::Value emitPromoted(const Expr *e, QualType promotionType);
@@ -867,10 +867,25 @@ mlir::Value CIRGenFunction::emitPromotedScalarExpr(const Expr *e,
867867
return e->getType()->isNullPtrType();
868868
}
869869

870+
/// If \p e is a widened promoted integer, get its base (unpromoted) type.
871+
static std::optional<QualType>
872+
getUnwidenedIntegerType(const ASTContext &astContext, const Expr *e) {
873+
const Expr *base = e->IgnoreImpCasts();
874+
if (e == base)
875+
return std::nullopt;
876+
877+
QualType baseTy = base->getType();
878+
if (!astContext.isPromotableIntegerType(baseTy) ||
879+
astContext.getTypeSize(baseTy) >= astContext.getTypeSize(e->getType()))
880+
return std::nullopt;
881+
882+
return baseTy;
883+
}
884+
870885
/// Check if \p e is a widened promoted integer.
871886
[[maybe_unused]] static bool isWidenedIntegerOp(const ASTContext &astContext,
872887
const Expr *e) {
873-
return astContext.getUnwidenedIntegerType(e).has_value();
888+
return getUnwidenedIntegerType(astContext, e).has_value();
874889
}
875890

876891
/// Check if we can skip the overflow check for \p Op.
@@ -892,12 +907,12 @@ mlir::Value CIRGenFunction::emitPromotedScalarExpr(const Expr *e,
892907
// Multiplication with promoted unsigned operands is a special case.
893908
const auto *bo = cast<BinaryOperator>(op.e);
894909
std::optional<QualType> optionalLHSTy =
895-
astContext.getUnwidenedIntegerType(bo->getLHS());
910+
getUnwidenedIntegerType(astContext, bo->getLHS());
896911
if (!optionalLHSTy)
897912
return false;
898913

899914
std::optional<QualType> optionalRHSTy =
900-
astContext.getUnwidenedIntegerType(bo->getRHS());
915+
getUnwidenedIntegerType(astContext, bo->getRHS());
901916
if (!optionalRHSTy)
902917
return false;
903918

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,8 +1045,9 @@ mlir::LogicalResult CIRToLLVMBinOpLowering::matchAndRewrite(
10451045
}
10461046
rewriter.replaceOpWithNewOp<mlir::LLVM::AddOp>(op, llvmTy, lhs, rhs,
10471047
getIntOverflowFlag(op));
1048-
} else
1048+
} else {
10491049
rewriter.replaceOpWithNewOp<mlir::LLVM::FAddOp>(op, lhs, rhs);
1050+
}
10501051
break;
10511052
case cir::BinOpKind::Sub:
10521053
if (mlir::isa<mlir::IntegerType>(llvmEltTy)) {
@@ -1060,8 +1061,9 @@ mlir::LogicalResult CIRToLLVMBinOpLowering::matchAndRewrite(
10601061
}
10611062
rewriter.replaceOpWithNewOp<mlir::LLVM::SubOp>(op, llvmTy, lhs, rhs,
10621063
getIntOverflowFlag(op));
1063-
} else
1064+
} else {
10641065
rewriter.replaceOpWithNewOp<mlir::LLVM::FSubOp>(op, lhs, rhs);
1066+
}
10651067
break;
10661068
case cir::BinOpKind::Mul:
10671069
if (mlir::isa<mlir::IntegerType>(llvmEltTy))
@@ -1077,8 +1079,9 @@ mlir::LogicalResult CIRToLLVMBinOpLowering::matchAndRewrite(
10771079
rewriter.replaceOpWithNewOp<mlir::LLVM::UDivOp>(op, lhs, rhs);
10781080
else
10791081
rewriter.replaceOpWithNewOp<mlir::LLVM::SDivOp>(op, lhs, rhs);
1080-
} else
1082+
} else {
10811083
rewriter.replaceOpWithNewOp<mlir::LLVM::FDivOp>(op, lhs, rhs);
1084+
}
10821085
break;
10831086
case cir::BinOpKind::Rem:
10841087
if (mlir::isa<mlir::IntegerType>(llvmEltTy)) {
@@ -1087,8 +1090,9 @@ mlir::LogicalResult CIRToLLVMBinOpLowering::matchAndRewrite(
10871090
rewriter.replaceOpWithNewOp<mlir::LLVM::URemOp>(op, lhs, rhs);
10881091
else
10891092
rewriter.replaceOpWithNewOp<mlir::LLVM::SRemOp>(op, lhs, rhs);
1090-
} else
1093+
} else {
10911094
rewriter.replaceOpWithNewOp<mlir::LLVM::FRemOp>(op, lhs, rhs);
1095+
}
10921096
break;
10931097
case cir::BinOpKind::And:
10941098
rewriter.replaceOpWithNewOp<mlir::LLVM::AndOp>(op, lhs, rhs);
@@ -1251,8 +1255,8 @@ void ConvertCIRToLLVMPass::runOnOperation() {
12511255
dl);
12521256
patterns.add<
12531257
// clang-format off
1254-
CIRToLLVMBrCondOpLowering,
12551258
CIRToLLVMBinOpLowering,
1259+
CIRToLLVMBrCondOpLowering,
12561260
CIRToLLVMBrOpLowering,
12571261
CIRToLLVMFuncOpLowering,
12581262
CIRToLLVMTrapOpLowering,

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,24 @@ static bool MustVisitNullValue(const Expr *E) {
168168
return E->getType()->isNullPtrType();
169169
}
170170

171+
/// If \p E is a widened promoted integer, get its base (unpromoted) type.
172+
static std::optional<QualType> getUnwidenedIntegerType(const ASTContext &Ctx,
173+
const Expr *E) {
174+
const Expr *Base = E->IgnoreImpCasts();
175+
if (E == Base)
176+
return std::nullopt;
177+
178+
QualType BaseTy = Base->getType();
179+
if (!Ctx.isPromotableIntegerType(BaseTy) ||
180+
Ctx.getTypeSize(BaseTy) >= Ctx.getTypeSize(E->getType()))
181+
return std::nullopt;
182+
183+
return BaseTy;
184+
}
185+
171186
/// Check if \p E is a widened promoted integer.
172187
static bool IsWidenedIntegerOp(const ASTContext &Ctx, const Expr *E) {
173-
return Ctx.getUnwidenedIntegerType(E).has_value();
188+
return getUnwidenedIntegerType(Ctx, E).has_value();
174189
}
175190

176191
/// Check if we can skip the overflow check for \p Op.
@@ -213,11 +228,11 @@ static bool CanElideOverflowCheck(const ASTContext &Ctx, const BinOpInfo &Op) {
213228
if (BO->hasExcludedOverflowPattern())
214229
return true;
215230

216-
auto OptionalLHSTy = Ctx.getUnwidenedIntegerType(BO->getLHS());
231+
auto OptionalLHSTy = getUnwidenedIntegerType(Ctx, BO->getLHS());
217232
if (!OptionalLHSTy)
218233
return false;
219234

220-
auto OptionalRHSTy = Ctx.getUnwidenedIntegerType(BO->getRHS());
235+
auto OptionalRHSTy = getUnwidenedIntegerType(Ctx, BO->getRHS());
221236
if (!OptionalRHSTy)
222237
return false;
223238

0 commit comments

Comments
 (0)