@@ -4421,70 +4421,66 @@ class MaterializeTemporaryExpr : public Expr {
4421
4421
friend class ASTStmtReader ;
4422
4422
friend class ASTStmtWriter ;
4423
4423
4424
- struct ExtraState {
4425
- // / The temporary-generating expression whose value will be
4426
- // / materialized.
4427
- Stmt *Temporary;
4428
-
4429
- // / The declaration which lifetime-extended this reference, if any.
4430
- // / Either a VarDecl, or (for a ctor-initializer) a FieldDecl.
4431
- const ValueDecl *ExtendingDecl;
4432
-
4433
- unsigned ManglingNumber;
4434
- };
4435
- llvm::PointerUnion<Stmt *, ExtraState *> State;
4424
+ llvm::PointerUnion<Stmt *, LifetimeExtendedTemporaryDecl *> State;
4436
4425
4437
4426
public:
4438
4427
MaterializeTemporaryExpr (QualType T, Expr *Temporary,
4439
- bool BoundToLvalueReference)
4440
- : Expr(MaterializeTemporaryExprClass, T,
4441
- BoundToLvalueReference? VK_LValue : VK_XValue, OK_Ordinary,
4442
- Temporary->isTypeDependent (), Temporary->isValueDependent(),
4443
- Temporary->isInstantiationDependent(),
4444
- Temporary->containsUnexpandedParameterPack()),
4445
- State(Temporary) {}
4428
+ bool BoundToLvalueReference,
4429
+ LifetimeExtendedTemporaryDecl *MTD = nullptr );
4446
4430
4447
4431
MaterializeTemporaryExpr (EmptyShell Empty)
4448
4432
: Expr(MaterializeTemporaryExprClass, Empty) {}
4449
4433
4450
- Stmt *getTemporary () const {
4451
- return State.is <Stmt *>() ? State.get <Stmt *>()
4452
- : State.get <ExtraState *>()->Temporary ;
4453
- }
4454
-
4455
4434
// / Retrieve the temporary-generating subexpression whose value will
4456
4435
// / be materialized into a glvalue.
4457
- Expr *GetTemporaryExpr () const { return static_cast <Expr *>(getTemporary ()); }
4436
+ Expr *getSubExpr () const {
4437
+ return cast<Expr>(
4438
+ State.is <Stmt *>()
4439
+ ? State.get <Stmt *>()
4440
+ : State.get <LifetimeExtendedTemporaryDecl *>()->getTemporaryExpr ());
4441
+ }
4458
4442
4459
4443
// / Retrieve the storage duration for the materialized temporary.
4460
4444
StorageDuration getStorageDuration () const {
4461
- const ValueDecl *ExtendingDecl = getExtendingDecl ();
4462
- if (!ExtendingDecl)
4463
- return SD_FullExpression;
4464
- // FIXME: This is not necessarily correct for a temporary materialized
4465
- // within a default initializer.
4466
- if (isa<FieldDecl>(ExtendingDecl))
4467
- return SD_Automatic;
4468
- // FIXME: This only works because storage class specifiers are not allowed
4469
- // on decomposition declarations.
4470
- if (isa<BindingDecl>(ExtendingDecl))
4471
- return ExtendingDecl->getDeclContext ()->isFunctionOrMethod ()
4472
- ? SD_Automatic
4473
- : SD_Static;
4474
- return cast<VarDecl>(ExtendingDecl)->getStorageDuration ();
4445
+ return State.is <Stmt *>() ? SD_FullExpression
4446
+ : State.get <LifetimeExtendedTemporaryDecl *>()
4447
+ ->getStorageDuration ();
4448
+ }
4449
+
4450
+ // / Get the storage for the constant value of a materialized temporary
4451
+ // / of static storage duration.
4452
+ APValue *getOrCreateValue (bool MayCreate) const {
4453
+ assert (State.is <LifetimeExtendedTemporaryDecl *>() &&
4454
+ " the temporary has not been lifetime extended" );
4455
+ return State.get <LifetimeExtendedTemporaryDecl *>()->getOrCreateValue (
4456
+ MayCreate);
4457
+ }
4458
+
4459
+ LifetimeExtendedTemporaryDecl *getLifetimeExtendedTemporaryDecl () {
4460
+ return State.dyn_cast <LifetimeExtendedTemporaryDecl *>();
4461
+ }
4462
+ const LifetimeExtendedTemporaryDecl *
4463
+ getLifetimeExtendedTemporaryDecl () const {
4464
+ return State.dyn_cast <LifetimeExtendedTemporaryDecl *>();
4475
4465
}
4476
4466
4477
4467
// / Get the declaration which triggered the lifetime-extension of this
4478
4468
// / temporary, if any.
4479
- const ValueDecl *getExtendingDecl () const {
4469
+ ValueDecl *getExtendingDecl () {
4480
4470
return State.is <Stmt *>() ? nullptr
4481
- : State.get <ExtraState *>()->ExtendingDecl ;
4471
+ : State.get <LifetimeExtendedTemporaryDecl *>()
4472
+ ->getExtendingDecl ();
4473
+ }
4474
+ const ValueDecl *getExtendingDecl () const {
4475
+ return const_cast <MaterializeTemporaryExpr *>(this )->getExtendingDecl ();
4482
4476
}
4483
4477
4484
- void setExtendingDecl (const ValueDecl *ExtendedBy, unsigned ManglingNumber);
4478
+ void setExtendingDecl (ValueDecl *ExtendedBy, unsigned ManglingNumber);
4485
4479
4486
4480
unsigned getManglingNumber () const {
4487
- return State.is <Stmt *>() ? 0 : State.get <ExtraState *>()->ManglingNumber ;
4481
+ return State.is <Stmt *>() ? 0
4482
+ : State.get <LifetimeExtendedTemporaryDecl *>()
4483
+ ->getManglingNumber ();
4488
4484
}
4489
4485
4490
4486
// / Determine whether this materialized temporary is bound to an
@@ -4494,11 +4490,11 @@ class MaterializeTemporaryExpr : public Expr {
4494
4490
}
4495
4491
4496
4492
SourceLocation getBeginLoc () const LLVM_READONLY {
4497
- return getTemporary ()->getBeginLoc ();
4493
+ return getSubExpr ()->getBeginLoc ();
4498
4494
}
4499
4495
4500
4496
SourceLocation getEndLoc () const LLVM_READONLY {
4501
- return getTemporary ()->getEndLoc ();
4497
+ return getSubExpr ()->getEndLoc ();
4502
4498
}
4503
4499
4504
4500
static bool classof (const Stmt *T) {
@@ -4507,20 +4503,18 @@ class MaterializeTemporaryExpr : public Expr {
4507
4503
4508
4504
// Iterators
4509
4505
child_range children () {
4510
- if (State.is <Stmt *>())
4511
- return child_range (State.getAddrOfPtr1 (), State.getAddrOfPtr1 () + 1 );
4512
-
4513
- auto ES = State.get <ExtraState *>();
4514
- return child_range (&ES->Temporary , &ES->Temporary + 1 );
4506
+ return State.is <Stmt *>()
4507
+ ? child_range (State.getAddrOfPtr1 (), State.getAddrOfPtr1 () + 1 )
4508
+ : State.get <LifetimeExtendedTemporaryDecl *>()->childrenExpr ();
4515
4509
}
4516
4510
4517
4511
const_child_range children () const {
4518
- if ( State.is <Stmt *>() )
4519
- return const_child_range (State.getAddrOfPtr1 (),
4520
- State.getAddrOfPtr1 () + 1 );
4521
-
4522
- auto ES = State.get <ExtraState *>();
4523
- return const_child_range (&ES-> Temporary , &ES-> Temporary + 1 );
4512
+ return State.is <Stmt *>()
4513
+ ? const_child_range (State.getAddrOfPtr1 (),
4514
+ State.getAddrOfPtr1 () + 1 )
4515
+ : const_cast < const LifetimeExtendedTemporaryDecl *>(
4516
+ State.get <LifetimeExtendedTemporaryDecl *>())
4517
+ -> childrenExpr ( );
4524
4518
}
4525
4519
};
4526
4520
0 commit comments