@@ -533,10 +533,8 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
533
533
// We're creating a complex value here, so we need to
534
534
// allocate storage for it.
535
535
if (!Initializing) {
536
- std::optional<unsigned > LocalIndex = allocateLocal (CE);
537
- if (!LocalIndex)
538
- return false ;
539
- if (!this ->emitGetPtrLocal (*LocalIndex, CE))
536
+ unsigned LocalIndex = allocateTemporary (CE);
537
+ if (!this ->emitGetPtrLocal (LocalIndex, CE))
540
538
return false ;
541
539
}
542
540
@@ -671,10 +669,8 @@ bool Compiler<Emitter>::VisitImaginaryLiteral(const ImaginaryLiteral *E) {
671
669
return true ;
672
670
673
671
if (!Initializing) {
674
- std::optional<unsigned > LocalIndex = allocateLocal (E);
675
- if (!LocalIndex)
676
- return false ;
677
- if (!this ->emitGetPtrLocal (*LocalIndex, E))
672
+ unsigned LocalIndex = allocateTemporary (E);
673
+ if (!this ->emitGetPtrLocal (LocalIndex, E))
678
674
return false ;
679
675
}
680
676
@@ -986,10 +982,8 @@ template <class Emitter>
986
982
bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
987
983
// Prepare storage for result.
988
984
if (!Initializing) {
989
- std::optional<unsigned > LocalIndex = allocateLocal (E);
990
- if (!LocalIndex)
991
- return false ;
992
- if (!this ->emitGetPtrLocal (*LocalIndex, E))
985
+ unsigned LocalIndex = allocateTemporary (E);
986
+ if (!this ->emitGetPtrLocal (LocalIndex, E))
993
987
return false ;
994
988
}
995
989
@@ -1045,10 +1039,7 @@ bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
1045
1039
1046
1040
if (!LHSIsComplex) {
1047
1041
// This is using the RHS type for the fake-complex LHS.
1048
- if (auto LHSO = allocateLocal (RHS))
1049
- LHSOffset = *LHSO;
1050
- else
1051
- return false ;
1042
+ LHSOffset = allocateTemporary (RHS);
1052
1043
1053
1044
if (!this ->emitGetPtrLocal (LHSOffset, E))
1054
1045
return false ;
@@ -1881,15 +1872,26 @@ bool Compiler<Emitter>::VisitAbstractConditionalOperator(
1881
1872
if (!this ->jumpFalse (LabelFalse))
1882
1873
return false ;
1883
1874
1884
- if (!this ->delegate (TrueExpr))
1885
- return false ;
1875
+ {
1876
+ LocalScope<Emitter> S (this );
1877
+ if (!this ->delegate (TrueExpr))
1878
+ return false ;
1879
+ if (!S.destroyLocals ())
1880
+ return false ;
1881
+ }
1882
+
1886
1883
if (!this ->jump (LabelEnd))
1887
1884
return false ;
1888
1885
1889
1886
this ->emitLabel (LabelFalse);
1890
1887
1891
- if (!this ->delegate (FalseExpr))
1892
- return false ;
1888
+ {
1889
+ LocalScope<Emitter> S (this );
1890
+ if (!this ->delegate (FalseExpr))
1891
+ return false ;
1892
+ if (!S.destroyLocals ())
1893
+ return false ;
1894
+ }
1893
1895
1894
1896
this ->fallthrough (LabelEnd);
1895
1897
this ->emitLabel (LabelEnd);
@@ -3549,6 +3551,27 @@ Compiler<Emitter>::allocateLocal(DeclTy &&Src, const ValueDecl *ExtendingDecl) {
3549
3551
return Local.Offset ;
3550
3552
}
3551
3553
3554
+ template <class Emitter >
3555
+ unsigned Compiler<Emitter>::allocateTemporary(const Expr *E) {
3556
+ QualType Ty = E->getType ();
3557
+ assert (!Ty->isRecordType ());
3558
+
3559
+ Descriptor *D = P.createDescriptor (
3560
+ E, Ty.getTypePtr (), Descriptor::InlineDescMD, Ty.isConstQualified (),
3561
+ /* IsTemporary=*/ true , /* IsMutable=*/ false , /* Init=*/ nullptr );
3562
+ assert (D);
3563
+
3564
+ Scope::Local Local = this ->createLocal (D);
3565
+ VariableScope<Emitter> *S = VarScope;
3566
+ assert (S);
3567
+ // Attach to topmost scope.
3568
+ while (S->getParent ())
3569
+ S = S->getParent ();
3570
+ assert (S && !S->getParent ());
3571
+ S->addLocal (Local);
3572
+ return Local.Offset ;
3573
+ }
3574
+
3552
3575
template <class Emitter >
3553
3576
const RecordType *Compiler<Emitter>::getRecordTy(QualType Ty) {
3554
3577
if (const PointerType *PT = dyn_cast<PointerType>(Ty))
0 commit comments