@@ -1197,6 +1197,21 @@ Address CIRGenFunction::emitArrayToPointerDecay(const Expr *e) {
1197
1197
return Address (ptr, addr.getAlignment ());
1198
1198
}
1199
1199
1200
+ // / Emit the operand of a glvalue conditional operator. This is either a glvalue
1201
+ // / or a (possibly-parenthesized) throw-expression. If this is a throw, no
1202
+ // / LValue is returned and the current block has been terminated.
1203
+ static std::optional<LValue> emitLValueOrThrowExpression (CIRGenFunction &cgf,
1204
+ const Expr *operand) {
1205
+ if (isa<CXXThrowExpr>(operand->IgnoreParens ())) {
1206
+ assert (!cir::MissingFeatures::throwOp ());
1207
+ cgf.cgm .errorNYI (operand->getSourceRange (),
1208
+ " throw expressions in conditional operator" );
1209
+ return std::nullopt;
1210
+ }
1211
+
1212
+ return cgf.emitLValue (operand);
1213
+ }
1214
+
1200
1215
// Handle the case where the condition is a constant evaluatable simple integer,
1201
1216
// which means we don't have to separately handle the true/false blocks.
1202
1217
static std::optional<LValue> handleConditionalOperatorLValueSimpleCase (
@@ -1208,40 +1223,21 @@ static std::optional<LValue> handleConditionalOperatorLValueSimpleCase(
1208
1223
if (!condExprBool)
1209
1224
std::swap (live, dead);
1210
1225
1226
+ // If there's a label in the "dead" branch we can't eliminate that as it
1227
+ // could be a used jump target.
1211
1228
if (!cgf.containsLabel (dead)) {
1212
1229
// If the true case is live, we need to track its region.
1213
1230
if (condExprBool) {
1214
1231
assert (!cir::MissingFeatures::incrementProfileCounter ());
1215
1232
}
1216
1233
// If a throw expression we emit it and return an undefined lvalue
1217
1234
// because it can't be used.
1218
- if (isa<CXXThrowExpr>(live->IgnoreParens ())) {
1219
- assert (!cir::MissingFeatures::throwOp ());
1220
- cgf.cgm .errorNYI (live->getSourceRange (),
1221
- " throw expressions in conditional operator" );
1222
- return std::nullopt;
1223
- }
1224
- return cgf.emitLValue (live);
1235
+ return emitLValueOrThrowExpression (cgf, live);
1225
1236
}
1226
1237
}
1227
1238
return std::nullopt;
1228
1239
}
1229
1240
1230
- // / Emit the operand of a glvalue conditional operator. This is either a glvalue
1231
- // / or a (possibly-parenthesized) throw-expression. If this is a throw, no
1232
- // / LValue is returned and the current block has been terminated.
1233
- static std::optional<LValue> emitLValueOrThrowExpression (CIRGenFunction &cgf,
1234
- const Expr *operand) {
1235
- if (isa<CXXThrowExpr>(operand->IgnoreParens ())) {
1236
- assert (!cir::MissingFeatures::throwOp ());
1237
- cgf.cgm .errorNYI (operand->getSourceRange (),
1238
- " throw expressions in conditional operator" );
1239
- return std::nullopt;
1240
- }
1241
-
1242
- return cgf.emitLValue (operand);
1243
- }
1244
-
1245
1241
// Create and generate the 3 blocks for a conditional operator.
1246
1242
// Leaves the 'current block' in the continuation basic block.
1247
1243
template <typename FuncTy>
@@ -1252,7 +1248,6 @@ CIRGenFunction::emitConditionalBlocks(const AbstractConditionalOperator *e,
1252
1248
CIRGenFunction &cgf = *this ;
1253
1249
ConditionalEvaluation eval (cgf);
1254
1250
mlir::Location loc = cgf.getLoc (e->getSourceRange ());
1255
- CIRGenBuilderTy &builder = cgf.getBuilder ();
1256
1251
Expr *trueExpr = e->getTrueExpr ();
1257
1252
Expr *falseExpr = e->getFalseExpr ();
1258
1253
@@ -1266,10 +1261,10 @@ CIRGenFunction::emitConditionalBlocks(const AbstractConditionalOperator *e,
1266
1261
cgf.curLexScope ->setAsTernary ();
1267
1262
1268
1263
assert (!cir::MissingFeatures::incrementProfileCounter ());
1269
- eval.begin (cgf );
1264
+ eval.beginEvaluation ( );
1270
1265
branchInfo = branchGenFunc (cgf, expr);
1271
1266
mlir::Value branch = branchInfo->getPointer ();
1272
- eval.end (cgf );
1267
+ eval.endEvaluation ( );
1273
1268
1274
1269
if (branch) {
1275
1270
yieldTy = branch.getType ();
@@ -1315,47 +1310,6 @@ CIRGenFunction::emitConditionalBlocks(const AbstractConditionalOperator *e,
1315
1310
return info;
1316
1311
}
1317
1312
1318
- LValue CIRGenFunction::emitConditionalOperatorLValue (
1319
- const AbstractConditionalOperator *expr) {
1320
- if (!expr->isGLValue ()) {
1321
- // ?: here should be an aggregate.
1322
- assert (hasAggregateEvaluationKind (expr->getType ()) &&
1323
- " Unexpected conditional operator!" );
1324
- return emitAggExprToLValue (expr);
1325
- }
1326
-
1327
- OpaqueValueMapping binding (*this , expr);
1328
- if (std::optional<LValue> res =
1329
- handleConditionalOperatorLValueSimpleCase (*this , expr))
1330
- return *res;
1331
-
1332
- ConditionalInfo info =
1333
- emitConditionalBlocks (expr, [](CIRGenFunction &cgf, const Expr *e) {
1334
- return emitLValueOrThrowExpression (cgf, e);
1335
- });
1336
-
1337
- if ((info.lhs && !info.lhs ->isSimple ()) ||
1338
- (info.rhs && !info.rhs ->isSimple ())) {
1339
- cgm.errorNYI (expr->getSourceRange (), " unsupported conditional operator" );
1340
- return {};
1341
- }
1342
-
1343
- if (info.lhs && info.rhs ) {
1344
- Address lhsAddr = info.lhs ->getAddress ();
1345
- Address rhsAddr = info.rhs ->getAddress ();
1346
- Address result (info.result , lhsAddr.getElementType (),
1347
- std::min (lhsAddr.getAlignment (), rhsAddr.getAlignment ()));
1348
- AlignmentSource alignSource =
1349
- std::max (info.lhs ->getBaseInfo ().getAlignmentSource (),
1350
- info.rhs ->getBaseInfo ().getAlignmentSource ());
1351
- assert (!cir::MissingFeatures::opTBAA ());
1352
- return makeAddrLValue (result, expr->getType (), LValueBaseInfo (alignSource));
1353
- }
1354
- assert ((info.lhs || info.rhs ) &&
1355
- " both operands of glvalue conditional are throw-expressions?" );
1356
- return info.lhs ? *info.lhs : *info.rhs ;
1357
- }
1358
-
1359
1313
// / Emit an `if` on a boolean condition, filling `then` and `else` into
1360
1314
// / appropriated regions.
1361
1315
mlir::LogicalResult CIRGenFunction::emitIfOnBoolExpr (const Expr *cond,
0 commit comments