Skip to content

Commit 99e6ef3

Browse files
authored
[clang][NFC] Add missing placement-new after Allocate() calls (#68382)
While working on #68377 inspecting `Allocate()` calls, I found out that there are couple of places where we forget to use placement-new to create objects in the allocated memory.
1 parent 46518a1 commit 99e6ef3

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

clang/lib/AST/DeclCXX.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,8 @@ void CXXRecordDecl::setCaptures(ASTContext &Context,
14841484
if (Captures[I].isExplicit())
14851485
++Data.NumExplicitCaptures;
14861486

1487-
*ToCapture++ = Captures[I];
1487+
new (ToCapture) LambdaCapture(Captures[I]);
1488+
ToCapture++;
14881489
}
14891490

14901491
if (!lambdaIsDefaultConstructibleAndAssignable())

clang/lib/AST/DeclObjC.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,8 @@ void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C,
931931
unsigned Size = sizeof(ParmVarDecl *) * NumParams +
932932
sizeof(SourceLocation) * SelLocs.size();
933933
ParamsAndSelLocs = C.Allocate(Size);
934-
std::copy(Params.begin(), Params.end(), getParams());
935-
std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs());
934+
std::uninitialized_copy(Params.begin(), Params.end(), getParams());
935+
std::uninitialized_copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs());
936936
}
937937

938938
void ObjCMethodDecl::getSelectorLocs(

clang/lib/Serialization/ASTReaderDecl.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -2002,13 +2002,16 @@ void ASTDeclReader::ReadCXXDefinitionData(
20022002
case LCK_StarThis:
20032003
case LCK_This:
20042004
case LCK_VLAType:
2005-
*ToCapture++ = Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation());
2005+
new (ToCapture)
2006+
Capture(Loc, IsImplicit, Kind, nullptr, SourceLocation());
2007+
ToCapture++;
20062008
break;
20072009
case LCK_ByCopy:
20082010
case LCK_ByRef:
20092011
auto *Var = readDeclAs<VarDecl>();
20102012
SourceLocation EllipsisLoc = readSourceLocation();
2011-
*ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc);
2013+
new (ToCapture) Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc);
2014+
ToCapture++;
20122015
break;
20132016
}
20142017
}

0 commit comments

Comments
 (0)