@@ -1445,6 +1445,7 @@ namespace {
14451445 LLVM_PREFERRED_TYPE (TypeAwareAllocationMode)
14461446 unsigned PassTypeToPlacementDelete : 1 ;
14471447 const FunctionDecl *OperatorDelete;
1448+ RValueTy TypeIdentity;
14481449 ValueTy Ptr;
14491450 ValueTy AllocSize;
14501451 CharUnits AllocAlign;
@@ -1459,15 +1460,15 @@ namespace {
14591460 }
14601461
14611462 CallDeleteDuringNew (size_t NumPlacementArgs,
1462- const FunctionDecl *OperatorDelete, ValueTy Ptr,
1463- ValueTy AllocSize,
1463+ const FunctionDecl *OperatorDelete,
1464+ RValueTy TypeIdentity, ValueTy Ptr, ValueTy AllocSize,
14641465 const ImplicitAllocationParameters &IAP,
14651466 CharUnits AllocAlign)
14661467 : NumPlacementArgs(NumPlacementArgs),
14671468 PassAlignmentToPlacementDelete (
14681469 isAlignedAllocation (IAP.PassAlignment)),
1469- OperatorDelete(OperatorDelete), Ptr(Ptr ), AllocSize(AllocSize ),
1470- AllocAlign(AllocAlign) {}
1470+ OperatorDelete(OperatorDelete), TypeIdentity(TypeIdentity ), Ptr(Ptr ),
1471+ AllocSize(AllocSize), AllocAlign(AllocAlign) {}
14711472
14721473 void setPlacementArg (unsigned I, RValueTy Arg, QualType Type) {
14731474 assert (I < NumPlacementArgs && " index out of range" );
@@ -1484,10 +1485,7 @@ namespace {
14841485 TypeAwareDeallocation = TypeAwareAllocationMode::Yes;
14851486 QualType SpecializedTypeIdentity = FPT->getParamType (0 );
14861487 ++FirstNonTypeArg;
1487- CXXScalarValueInitExpr TypeIdentityParam (SpecializedTypeIdentity,
1488- nullptr , SourceLocation ());
1489- DeleteArgs.add (CGF.EmitAnyExprToTemp (&TypeIdentityParam),
1490- SpecializedTypeIdentity);
1488+ DeleteArgs.add (Traits::get (CGF, TypeIdentity), SpecializedTypeIdentity);
14911489 }
14921490 // The first non type tag argument is always a void* (or C* for a
14931491 // destroying operator delete for class type C).
@@ -1501,6 +1499,7 @@ namespace {
15011499 Params.Alignment =
15021500 alignedAllocationModeFromBool (PassAlignmentToPlacementDelete);
15031501 Params.TypeAwareDelete = TypeAwareDeallocation;
1502+ Params.Size = isTypeAwareAllocation (Params.TypeAwareDelete );
15041503 } else {
15051504 // For a non-placement new-expression, 'operator delete' can take a
15061505 // size and/or an alignment if it has the right parameters.
@@ -1538,11 +1537,9 @@ namespace {
15381537
15391538// / Enter a cleanup to call 'operator delete' if the initializer in a
15401539// / new-expression throws.
1541- static void EnterNewDeleteCleanup (CodeGenFunction &CGF,
1542- const CXXNewExpr *E,
1543- Address NewPtr,
1544- llvm::Value *AllocSize,
1545- CharUnits AllocAlign,
1540+ static void EnterNewDeleteCleanup (CodeGenFunction &CGF, const CXXNewExpr *E,
1541+ RValue TypeIdentity, Address NewPtr,
1542+ llvm::Value *AllocSize, CharUnits AllocAlign,
15461543 const CallArgList &NewArgs) {
15471544 unsigned NumNonPlacementArgs = E->getNumImplicitArgs ();
15481545
@@ -1560,7 +1557,7 @@ static void EnterNewDeleteCleanup(CodeGenFunction &CGF,
15601557
15611558 DirectCleanup *Cleanup = CGF.EHStack .pushCleanupWithExtra <DirectCleanup>(
15621559 EHCleanup, E->getNumPlacementArgs (), E->getOperatorDelete (),
1563- NewPtr.emitRawPointer (CGF), AllocSize,
1560+ TypeIdentity, NewPtr.emitRawPointer (CGF), AllocSize,
15641561 E->implicitAllocationParameters (), AllocAlign);
15651562 for (unsigned I = 0 , N = E->getNumPlacementArgs (); I != N; ++I) {
15661563 auto &Arg = NewArgs[I + NumNonPlacementArgs];
@@ -1575,7 +1572,8 @@ static void EnterNewDeleteCleanup(CodeGenFunction &CGF,
15751572 DominatingValue<RValue>::save (CGF, RValue::get (NewPtr, CGF));
15761573 DominatingValue<RValue>::saved_type SavedAllocSize =
15771574 DominatingValue<RValue>::save (CGF, RValue::get (AllocSize));
1578-
1575+ DominatingValue<RValue>::saved_type SavedTypeIdentity =
1576+ DominatingValue<RValue>::save (CGF, TypeIdentity);
15791577 struct ConditionalCleanupTraits {
15801578 typedef DominatingValue<RValue>::saved_type ValueTy;
15811579 typedef DominatingValue<RValue>::saved_type RValueTy;
@@ -1588,8 +1586,8 @@ static void EnterNewDeleteCleanup(CodeGenFunction &CGF,
15881586 ConditionalCleanup *Cleanup =
15891587 CGF.EHStack .pushCleanupWithExtra <ConditionalCleanup>(
15901588 EHCleanup, E->getNumPlacementArgs (), E->getOperatorDelete (),
1591- SavedNewPtr, SavedAllocSize, E-> implicitAllocationParameters () ,
1592- AllocAlign);
1589+ SavedTypeIdentity, SavedNewPtr, SavedAllocSize ,
1590+ E-> implicitAllocationParameters (), AllocAlign);
15931591 for (unsigned I = 0 , N = E->getNumPlacementArgs (); I != N; ++I) {
15941592 auto &Arg = NewArgs[I + NumNonPlacementArgs];
15951593 Cleanup->setPlacementArg (
@@ -1636,6 +1634,7 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
16361634 // operator, just "inline" it directly.
16371635 Address allocation = Address::invalid ();
16381636 CallArgList allocatorArgs;
1637+ RValue TypeIdentityArg;
16391638 if (allocator->isReservedGlobalPlacementOperator ()) {
16401639 assert (E->getNumPlacementArgs () == 1 );
16411640 const Expr *arg = *E->placement_arguments ().begin ();
@@ -1666,8 +1665,8 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
16661665 QualType SpecializedTypeIdentity = allocatorType->getParamType (0 );
16671666 CXXScalarValueInitExpr TypeIdentityParam (SpecializedTypeIdentity, nullptr ,
16681667 SourceLocation ());
1669- allocatorArgs. add ( EmitAnyExprToTemp (&TypeIdentityParam),
1670- SpecializedTypeIdentity);
1668+ TypeIdentityArg = EmitAnyExprToTemp (&TypeIdentityParam);
1669+ allocatorArgs. add (TypeIdentityArg, SpecializedTypeIdentity);
16711670 ++ParamsToSkip;
16721671 ++IndexOfAlignArg;
16731672 }
@@ -1762,8 +1761,8 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
17621761 llvm::Instruction *cleanupDominator = nullptr ;
17631762 if (E->getOperatorDelete () &&
17641763 !E->getOperatorDelete ()->isReservedGlobalPlacementOperator ()) {
1765- EnterNewDeleteCleanup (*this , E, allocation, allocSize, allocAlign ,
1766- allocatorArgs);
1764+ EnterNewDeleteCleanup (*this , E, TypeIdentityArg, allocation, allocSize ,
1765+ allocAlign, allocatorArgs);
17671766 operatorDeleteCleanup = EHStack.stable_begin ();
17681767 cleanupDominator = Builder.CreateUnreachable ();
17691768 }
0 commit comments