Skip to content

Commit c997d6c

Browse files
Rename ConstantFoldsToSimpleInteger and remove it from missingFeatures
1 parent 25dff99 commit c997d6c

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ struct MissingFeatures {
111111
static bool lvalueBaseInfo() { return false; }
112112
static bool alignCXXRecordDecl() { return false; }
113113
static bool setNonGC() { return false; }
114-
static bool constantFoldsToSimpleInteger() { return false; }
115114
static bool incrementProfileCounter() { return false; }
116115
static bool insertBuiltinUnpredictable() { return false; }
117116

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,20 +1484,6 @@ mlir::Value ScalarExprEmitter::VisitUnaryLNot(const UnaryOperator *e) {
14841484
return {};
14851485
}
14861486

1487-
/// If the specified expression does not fold
1488-
/// to a constant, or if it does but contains a label, return false. If it
1489-
/// constant folds return true and set the boolean result in Result.
1490-
bool CIRGenFunction::constantFoldsToSimpleInteger(const Expr *cond,
1491-
bool &resultBool,
1492-
bool allowLabels) {
1493-
llvm::APSInt resultInt;
1494-
if (!constantFoldsToSimpleInteger(cond, resultInt, allowLabels))
1495-
return false;
1496-
1497-
resultBool = resultInt.getBoolValue();
1498-
return true;
1499-
}
1500-
15011487
/// Return the size or alignment of the type of argument of the sizeof
15021488
/// expression as an integer.
15031489
mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ bool CIRGenFunction::containsLabel(const Stmt *s, bool ignoreCaseStmts) {
153153
if (isa<SwitchCase>(s) && !ignoreCaseStmts)
154154
return true;
155155

156-
// If this is a switch statement, we want to ignore cases below it.
156+
// If this is a switch statement, we want to ignore case statements when we
157+
// recursively process the sub-statements of the switch. If we haven't
158+
// encountered a switch statement, we treat case statements like labels, but
159+
// if we are processing a switch statement, case statements are expected.
157160
if (isa<SwitchStmt>(s))
158161
ignoreCaseStmts = true;
159162

@@ -164,6 +167,19 @@ bool CIRGenFunction::containsLabel(const Stmt *s, bool ignoreCaseStmts) {
164167
});
165168
}
166169

170+
/// If the specified expression does not fold to a constant, or if it does but
171+
/// contains a label, return false. If it constant folds return true and set
172+
/// the boolean result in Result.
173+
bool CIRGenFunction::constantFoldsToBool(const Expr *cond, bool &resultBool,
174+
bool allowLabels) {
175+
llvm::APSInt resultInt;
176+
if (!constantFoldsToSimpleInteger(cond, resultInt, allowLabels))
177+
return false;
178+
179+
resultBool = resultInt.getBoolValue();
180+
return true;
181+
}
182+
167183
/// If the specified expression does not fold to a constant, or if it does
168184
/// fold but contains a label, return false. If it constant folds, return
169185
/// true and set the folded value.

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ class CIRGenFunction : public CIRGenTypeCache {
170170
/// If the specified expression does not fold to a constant, or if it does but
171171
/// contains a label, return false. If it constant folds return true and set
172172
/// the boolean result in Result.
173-
bool constantFoldsToSimpleInteger(const clang::Expr *cond, bool &resultBool,
174-
bool allowLabels = false);
173+
bool constantFoldsToBool(const clang::Expr *cond, bool &resultBool,
174+
bool allowLabels = false);
175175
bool constantFoldsToSimpleInteger(const clang::Expr *cond,
176176
llvm::APSInt &resultInt,
177177
bool allowLabels = false);

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ mlir::LogicalResult CIRGenFunction::emitIfStmt(const IfStmt &s) {
311311
// If the condition folds to a constant and this is an 'if constexpr',
312312
// we simplify it early in CIRGen to avoid emitting the full 'if'.
313313
bool condConstant;
314-
if (constantFoldsToSimpleInteger(s.getCond(), condConstant,
315-
s.isConstexpr())) {
314+
if (constantFoldsToBool(s.getCond(), condConstant, s.isConstexpr())) {
316315
if (s.isConstexpr()) {
317316
// Handle "if constexpr" explicitly here to avoid generating some
318317
// ill-formed code since in CIR the "if" is no longer simplified

0 commit comments

Comments
 (0)