@@ -194,12 +194,12 @@ template <class Emitter> class StmtExprScope final {
194194template <class Emitter >
195195bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
196196 const Expr *SubExpr = CE->getSubExpr ();
197- switch (CE->getCastKind ()) {
198197
199- case CK_LValueToRValue: {
200- if (DiscardResult)
201- return this ->discard (SubExpr);
198+ if (DiscardResult)
199+ return this ->delegate (SubExpr);
202200
201+ switch (CE->getCastKind ()) {
202+ case CK_LValueToRValue: {
203203 std::optional<PrimType> SubExprT = classify (SubExpr->getType ());
204204 // Prepare storage for the result.
205205 if (!Initializing && !SubExprT) {
@@ -253,9 +253,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
253253
254254 case CK_UncheckedDerivedToBase:
255255 case CK_DerivedToBase: {
256- if (DiscardResult)
257- return this ->discard (SubExpr);
258-
259256 if (!this ->delegate (SubExpr))
260257 return false ;
261258
@@ -285,9 +282,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
285282 }
286283
287284 case CK_BaseToDerived: {
288- if (DiscardResult)
289- return this ->discard (SubExpr);
290-
291285 if (!this ->delegate (SubExpr))
292286 return false ;
293287
@@ -302,17 +296,13 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
302296 if (!SubExpr->getType ()->isFloatingType () ||
303297 !CE->getType ()->isFloatingType ())
304298 return false ;
305- if (DiscardResult)
306- return this ->discard (SubExpr);
307299 if (!this ->visit (SubExpr))
308300 return false ;
309301 const auto *TargetSemantics = &Ctx.getFloatSemantics (CE->getType ());
310302 return this ->emitCastFP (TargetSemantics, getRoundingMode (CE), CE);
311303 }
312304
313305 case CK_IntegralToFloating: {
314- if (DiscardResult)
315- return this ->discard (SubExpr);
316306 std::optional<PrimType> FromT = classify (SubExpr->getType ());
317307 if (!FromT)
318308 return false ;
@@ -327,8 +317,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
327317
328318 case CK_FloatingToBoolean:
329319 case CK_FloatingToIntegral: {
330- if (DiscardResult)
331- return this ->discard (SubExpr);
332320
333321 std::optional<PrimType> ToT = classify (CE->getType ());
334322
@@ -352,9 +340,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
352340 case CK_NullToMemberPointer: {
353341 if (!this ->discard (SubExpr))
354342 return false ;
355- if (DiscardResult)
356- return true ;
357-
358343 const Descriptor *Desc = nullptr ;
359344 const QualType PointeeType = CE->getType ()->getPointeeType ();
360345 if (!PointeeType.isNull ()) {
@@ -371,9 +356,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
371356 }
372357
373358 case CK_PointerToIntegral: {
374- if (DiscardResult)
375- return this ->discard (SubExpr);
376-
377359 if (!this ->visit (SubExpr))
378360 return false ;
379361
@@ -399,8 +381,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
399381 return false ;
400382 if (!this ->emitArrayDecay (CE))
401383 return false ;
402- if (DiscardResult)
403- return this ->emitPopPtr (CE);
404384 return true ;
405385 }
406386
@@ -412,9 +392,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
412392 // FIXME: I think the discard is wrong since the int->ptr cast might cause a
413393 // diagnostic.
414394 PrimType T = classifyPrim (IntType);
415- if (DiscardResult)
416- return this ->emitPop (T, CE);
417-
418395 QualType PtrType = CE->getType ();
419396 const Descriptor *Desc;
420397 if (std::optional<PrimType> T = classify (PtrType->getPointeeType ()))
@@ -454,10 +431,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
454431 return false ;
455432 return this ->emitInvalidCast (CastKind::Reinterpret, /* Fatal=*/ true , CE);
456433 }
457-
458- if (DiscardResult)
459- return this ->discard (SubExpr);
460-
461434 QualType SubExprTy = SubExpr->getType ();
462435 std::optional<PrimType> FromT = classify (SubExprTy);
463436 // Casts from integer/vector to vector.
@@ -493,8 +466,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
493466 case CK_FixedPointToBoolean:
494467 case CK_BooleanToSignedIntegral:
495468 case CK_IntegralCast: {
496- if (DiscardResult)
497- return this ->discard (SubExpr);
498469 std::optional<PrimType> FromT = classify (SubExpr->getType ());
499470 std::optional<PrimType> ToT = classify (CE->getType ());
500471
@@ -546,8 +517,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
546517
547518 case CK_IntegralComplexToBoolean:
548519 case CK_FloatingComplexToBoolean: {
549- if (DiscardResult)
550- return this ->discard (SubExpr);
551520 if (!this ->visit (SubExpr))
552521 return false ;
553522 return this ->emitComplexBoolCast (SubExpr);
@@ -585,9 +554,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
585554 case CK_FloatingComplexToIntegralComplex: {
586555 assert (CE->getType ()->isAnyComplexType ());
587556 assert (SubExpr->getType ()->isAnyComplexType ());
588- if (DiscardResult)
589- return this ->discard (SubExpr);
590-
591557 if (!Initializing) {
592558 std::optional<unsigned > LocalIndex = allocateLocal (CE);
593559 if (!LocalIndex)
@@ -633,9 +599,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
633599 assert (classify (SubExpr->getType ()));
634600 assert (CE->getType ()->isVectorType ());
635601
636- if (DiscardResult)
637- return this ->discard (SubExpr);
638-
639602 if (!Initializing) {
640603 std::optional<unsigned > LocalIndex = allocateLocal (CE);
641604 if (!LocalIndex)
0 commit comments