@@ -194,12 +194,12 @@ template <class Emitter> class StmtExprScope final {
194
194
template <class Emitter >
195
195
bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
196
196
const Expr *SubExpr = CE->getSubExpr ();
197
- switch (CE->getCastKind ()) {
198
197
199
- case CK_LValueToRValue: {
200
- if (DiscardResult)
201
- return this ->discard (SubExpr);
198
+ if (DiscardResult)
199
+ return this ->delegate (SubExpr);
202
200
201
+ switch (CE->getCastKind ()) {
202
+ case CK_LValueToRValue: {
203
203
std::optional<PrimType> SubExprT = classify (SubExpr->getType ());
204
204
// Prepare storage for the result.
205
205
if (!Initializing && !SubExprT) {
@@ -253,9 +253,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
253
253
254
254
case CK_UncheckedDerivedToBase:
255
255
case CK_DerivedToBase: {
256
- if (DiscardResult)
257
- return this ->discard (SubExpr);
258
-
259
256
if (!this ->delegate (SubExpr))
260
257
return false ;
261
258
@@ -285,9 +282,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
285
282
}
286
283
287
284
case CK_BaseToDerived: {
288
- if (DiscardResult)
289
- return this ->discard (SubExpr);
290
-
291
285
if (!this ->delegate (SubExpr))
292
286
return false ;
293
287
@@ -302,17 +296,13 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
302
296
if (!SubExpr->getType ()->isFloatingType () ||
303
297
!CE->getType ()->isFloatingType ())
304
298
return false ;
305
- if (DiscardResult)
306
- return this ->discard (SubExpr);
307
299
if (!this ->visit (SubExpr))
308
300
return false ;
309
301
const auto *TargetSemantics = &Ctx.getFloatSemantics (CE->getType ());
310
302
return this ->emitCastFP (TargetSemantics, getRoundingMode (CE), CE);
311
303
}
312
304
313
305
case CK_IntegralToFloating: {
314
- if (DiscardResult)
315
- return this ->discard (SubExpr);
316
306
std::optional<PrimType> FromT = classify (SubExpr->getType ());
317
307
if (!FromT)
318
308
return false ;
@@ -327,8 +317,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
327
317
328
318
case CK_FloatingToBoolean:
329
319
case CK_FloatingToIntegral: {
330
- if (DiscardResult)
331
- return this ->discard (SubExpr);
332
320
333
321
std::optional<PrimType> ToT = classify (CE->getType ());
334
322
@@ -352,9 +340,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
352
340
case CK_NullToMemberPointer: {
353
341
if (!this ->discard (SubExpr))
354
342
return false ;
355
- if (DiscardResult)
356
- return true ;
357
-
358
343
const Descriptor *Desc = nullptr ;
359
344
const QualType PointeeType = CE->getType ()->getPointeeType ();
360
345
if (!PointeeType.isNull ()) {
@@ -371,9 +356,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
371
356
}
372
357
373
358
case CK_PointerToIntegral: {
374
- if (DiscardResult)
375
- return this ->discard (SubExpr);
376
-
377
359
if (!this ->visit (SubExpr))
378
360
return false ;
379
361
@@ -399,8 +381,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
399
381
return false ;
400
382
if (!this ->emitArrayDecay (CE))
401
383
return false ;
402
- if (DiscardResult)
403
- return this ->emitPopPtr (CE);
404
384
return true ;
405
385
}
406
386
@@ -412,9 +392,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
412
392
// FIXME: I think the discard is wrong since the int->ptr cast might cause a
413
393
// diagnostic.
414
394
PrimType T = classifyPrim (IntType);
415
- if (DiscardResult)
416
- return this ->emitPop (T, CE);
417
-
418
395
QualType PtrType = CE->getType ();
419
396
const Descriptor *Desc;
420
397
if (std::optional<PrimType> T = classify (PtrType->getPointeeType ()))
@@ -454,10 +431,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
454
431
return false ;
455
432
return this ->emitInvalidCast (CastKind::Reinterpret, /* Fatal=*/ true , CE);
456
433
}
457
-
458
- if (DiscardResult)
459
- return this ->discard (SubExpr);
460
-
461
434
QualType SubExprTy = SubExpr->getType ();
462
435
std::optional<PrimType> FromT = classify (SubExprTy);
463
436
// Casts from integer/vector to vector.
@@ -493,8 +466,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
493
466
case CK_FixedPointToBoolean:
494
467
case CK_BooleanToSignedIntegral:
495
468
case CK_IntegralCast: {
496
- if (DiscardResult)
497
- return this ->discard (SubExpr);
498
469
std::optional<PrimType> FromT = classify (SubExpr->getType ());
499
470
std::optional<PrimType> ToT = classify (CE->getType ());
500
471
@@ -546,8 +517,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
546
517
547
518
case CK_IntegralComplexToBoolean:
548
519
case CK_FloatingComplexToBoolean: {
549
- if (DiscardResult)
550
- return this ->discard (SubExpr);
551
520
if (!this ->visit (SubExpr))
552
521
return false ;
553
522
return this ->emitComplexBoolCast (SubExpr);
@@ -585,9 +554,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
585
554
case CK_FloatingComplexToIntegralComplex: {
586
555
assert (CE->getType ()->isAnyComplexType ());
587
556
assert (SubExpr->getType ()->isAnyComplexType ());
588
- if (DiscardResult)
589
- return this ->discard (SubExpr);
590
-
591
557
if (!Initializing) {
592
558
std::optional<unsigned > LocalIndex = allocateLocal (CE);
593
559
if (!LocalIndex)
@@ -633,9 +599,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
633
599
assert (classify (SubExpr->getType ()));
634
600
assert (CE->getType ()->isVectorType ());
635
601
636
- if (DiscardResult)
637
- return this ->discard (SubExpr);
638
-
639
602
if (!Initializing) {
640
603
std::optional<unsigned > LocalIndex = allocateLocal (CE);
641
604
if (!LocalIndex)
0 commit comments