Skip to content

Commit ed75e55

Browse files
authored
[NFC][Clang][AST] Adopt llvm::copy in Clang AST (llvm#145192)
1 parent f40909f commit ed75e55

File tree

13 files changed

+73
-90
lines changed

13 files changed

+73
-90
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
814814

815815
llvm::StringRef backupStr(llvm::StringRef S) const {
816816
char *Buf = new (*this) char[S.size()];
817-
std::copy(S.begin(), S.end(), Buf);
817+
llvm::copy(S, Buf);
818818
return llvm::StringRef(Buf, S.size());
819819
}
820820

clang/include/clang/AST/OpenMPClause.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ template <class T> class OMPDirectiveListClause : public OMPClause {
387387
assert(
388388
DK.size() == NumKinds &&
389389
"Number of directive kinds is not the same as the preallocated buffer");
390-
std::copy(DK.begin(), DK.end(), getDirectiveKinds().begin());
390+
llvm::copy(DK, getDirectiveKinds().begin());
391391
}
392392

393393
SourceLocation getLParenLoc() { return LParenLoc; }
@@ -5917,7 +5917,7 @@ class OMPMappableExprListClause : public OMPVarListClause<T>,
59175917
void setUniqueDecls(ArrayRef<ValueDecl *> UDs) {
59185918
assert(UDs.size() == NumUniqueDeclarations &&
59195919
"Unexpected amount of unique declarations.");
5920-
std::copy(UDs.begin(), UDs.end(), getUniqueDeclsRef().begin());
5920+
llvm::copy(UDs, getUniqueDeclsRef().begin());
59215921
}
59225922

59235923
/// Get the number of lists per declaration that are in the trailing
@@ -5939,7 +5939,7 @@ class OMPMappableExprListClause : public OMPVarListClause<T>,
59395939
void setDeclNumLists(ArrayRef<unsigned> DNLs) {
59405940
assert(DNLs.size() == NumUniqueDeclarations &&
59415941
"Unexpected amount of list numbers.");
5942-
std::copy(DNLs.begin(), DNLs.end(), getDeclNumListsRef().begin());
5942+
llvm::copy(DNLs, getDeclNumListsRef().begin());
59435943
}
59445944

59455945
/// Get the cumulative component lists sizes that are in the trailing
@@ -5965,7 +5965,7 @@ class OMPMappableExprListClause : public OMPVarListClause<T>,
59655965
void setComponentListSizes(ArrayRef<unsigned> CLSs) {
59665966
assert(CLSs.size() == NumComponentLists &&
59675967
"Unexpected amount of component lists.");
5968-
std::copy(CLSs.begin(), CLSs.end(), getComponentListSizesRef().begin());
5968+
llvm::copy(CLSs, getComponentListSizesRef().begin());
59695969
}
59705970

59715971
/// Get the components that are in the trailing objects of the class.
@@ -5989,7 +5989,7 @@ class OMPMappableExprListClause : public OMPVarListClause<T>,
59895989
"Unexpected amount of component lists.");
59905990
assert(CLSs.size() == NumComponentLists &&
59915991
"Unexpected amount of list sizes.");
5992-
std::copy(Components.begin(), Components.end(), getComponentsRef().begin());
5992+
llvm::copy(Components, getComponentsRef().begin());
59935993
}
59945994

59955995
/// Fill the clause information from the list of declarations and
@@ -6063,7 +6063,7 @@ class OMPMappableExprListClause : public OMPVarListClause<T>,
60636063
++CLSI;
60646064

60656065
// Append components after the current components iterator.
6066-
CI = std::copy(C.begin(), C.end(), CI);
6066+
CI = llvm::copy(C, CI);
60676067
}
60686068
}
60696069
}
@@ -6107,7 +6107,7 @@ class OMPMappableExprListClause : public OMPVarListClause<T>,
61076107
"Unexpected number of user-defined mappers.");
61086108
assert(SupportsMapper &&
61096109
"Must be a clause that is possible to have user-defined mappers");
6110-
std::copy(DMDs.begin(), DMDs.end(), getUDMapperRefs().begin());
6110+
llvm::copy(DMDs, getUDMapperRefs().begin());
61116111
}
61126112

61136113
public:

clang/include/clang/AST/Stmt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2214,7 +2214,7 @@ class AttributedStmt final
22142214
: ValueStmt(AttributedStmtClass), SubStmt(SubStmt) {
22152215
AttributedStmtBits.NumAttrs = Attrs.size();
22162216
AttributedStmtBits.AttrLoc = Loc;
2217-
std::copy(Attrs.begin(), Attrs.end(), getAttrArrayPtr());
2217+
llvm::copy(Attrs, getAttrArrayPtr());
22182218
}
22192219

22202220
explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)

clang/lib/AST/ASTImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4123,7 +4123,7 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
41234123
return std::move(Err);
41244124
auto **Memory =
41254125
new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4126-
std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
4126+
llvm::copy(CtorInitializers, Memory);
41274127
auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
41284128
ToCtor->setCtorInitializers(Memory);
41294129
ToCtor->setNumCtorInitializers(NumInitializers);

clang/lib/AST/Decl.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,7 @@ void QualifierInfo::setTemplateParameterListsInfo(
21102110
if (!TPLists.empty()) {
21112111
TemplParamLists = new (Context) TemplateParameterList *[TPLists.size()];
21122112
NumTemplParamLists = TPLists.size();
2113-
std::copy(TPLists.begin(), TPLists.end(), TemplParamLists);
2113+
llvm::copy(TPLists, TemplParamLists);
21142114
}
21152115
}
21162116

@@ -3753,7 +3753,7 @@ void FunctionDecl::setParams(ASTContext &C,
37533753
// Zero params -> null pointer.
37543754
if (!NewParamInfo.empty()) {
37553755
ParamInfo = new (C) ParmVarDecl*[NewParamInfo.size()];
3756-
std::copy(NewParamInfo.begin(), NewParamInfo.end(), ParamInfo);
3756+
llvm::copy(NewParamInfo, ParamInfo);
37573757
}
37583758
}
37593759

@@ -5322,7 +5322,7 @@ void BlockDecl::setParams(ArrayRef<ParmVarDecl *> NewParamInfo) {
53225322
if (!NewParamInfo.empty()) {
53235323
NumParams = NewParamInfo.size();
53245324
ParamInfo = new (getASTContext()) ParmVarDecl*[NewParamInfo.size()];
5325-
std::copy(NewParamInfo.begin(), NewParamInfo.end(), ParamInfo);
5325+
llvm::copy(NewParamInfo, ParamInfo);
53265326
}
53275327
}
53285328

@@ -5379,7 +5379,7 @@ PragmaCommentDecl *PragmaCommentDecl::Create(const ASTContext &C,
53795379
PragmaCommentDecl *PCD =
53805380
new (C, DC, additionalSizeToAlloc<char>(Arg.size() + 1))
53815381
PragmaCommentDecl(DC, CommentLoc, CommentKind);
5382-
memcpy(PCD->getTrailingObjects(), Arg.data(), Arg.size());
5382+
llvm::copy(Arg, PCD->getTrailingObjects());
53835383
PCD->getTrailingObjects()[Arg.size()] = '\0';
53845384
return PCD;
53855385
}
@@ -5401,9 +5401,9 @@ PragmaDetectMismatchDecl::Create(const ASTContext &C, TranslationUnitDecl *DC,
54015401
PragmaDetectMismatchDecl *PDMD =
54025402
new (C, DC, additionalSizeToAlloc<char>(ValueStart + Value.size() + 1))
54035403
PragmaDetectMismatchDecl(DC, Loc, ValueStart);
5404-
memcpy(PDMD->getTrailingObjects(), Name.data(), Name.size());
5404+
llvm::copy(Name, PDMD->getTrailingObjects());
54055405
PDMD->getTrailingObjects()[Name.size()] = '\0';
5406-
memcpy(PDMD->getTrailingObjects() + ValueStart, Value.data(), Value.size());
5406+
llvm::copy(Value, PDMD->getTrailingObjects() + ValueStart);
54075407
PDMD->getTrailingObjects()[ValueStart + Value.size()] = '\0';
54085408
return PDMD;
54095409
}
@@ -5443,9 +5443,9 @@ LabelDecl *LabelDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
54435443

54445444
void LabelDecl::setMSAsmLabel(StringRef Name) {
54455445
char *Buffer = new (getASTContext(), 1) char[Name.size() + 1];
5446-
memcpy(Buffer, Name.data(), Name.size());
5447-
Buffer[Name.size()] = '\0';
5448-
MSAsmName = Buffer;
5446+
llvm::copy(Name, Buffer);
5447+
Buffer[Name.size()] = '\0';
5448+
MSAsmName = Buffer;
54495449
}
54505450

54515451
void ValueDecl::anchor() {}
@@ -5828,7 +5828,7 @@ void HLSLBufferDecl::setDefaultBufferDecls(ArrayRef<Decl *> Decls) {
58285828

58295829
// allocate array for default decls with ASTContext allocator
58305830
Decl **DeclsArray = new (getASTContext()) Decl *[Decls.size()];
5831-
std::copy(Decls.begin(), Decls.end(), DeclsArray);
5831+
llvm::copy(Decls, DeclsArray);
58325832
DefaultBufferDecls = ArrayRef<Decl *>(DeclsArray, Decls.size());
58335833
}
58345834

@@ -5869,8 +5869,7 @@ HLSLRootSignatureDecl *HLSLRootSignatureDecl::Create(
58695869
RootElements.size()))
58705870
HLSLRootSignatureDecl(DC, Loc, ID, RootElements.size());
58715871
auto *StoredElems = RSDecl->getElems();
5872-
std::uninitialized_copy(RootElements.begin(), RootElements.end(),
5873-
StoredElems);
5872+
llvm::uninitialized_copy(RootElements, StoredElems);
58745873
return RSDecl;
58755874
}
58765875

clang/lib/AST/DeclObjC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ ObjCTypeParamList::ObjCTypeParamList(SourceLocation lAngleLoc,
15121512
ArrayRef<ObjCTypeParamDecl *> typeParams,
15131513
SourceLocation rAngleLoc)
15141514
: Brackets(lAngleLoc, rAngleLoc), NumParams(typeParams.size()) {
1515-
std::copy(typeParams.begin(), typeParams.end(), begin());
1515+
llvm::copy(typeParams, begin());
15161516
}
15171517

15181518
ObjCTypeParamList *ObjCTypeParamList::create(

clang/lib/AST/ExprCXX.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,8 @@ CXXNewExpr::CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
261261
getTrailingObjects<Stmt *>()[arraySizeOffset()] = *ArraySize;
262262
if (Initializer)
263263
getTrailingObjects<Stmt *>()[initExprOffset()] = Initializer;
264-
for (unsigned I = 0; I != PlacementArgs.size(); ++I)
265-
getTrailingObjects<Stmt *>()[placementNewArgsOffset() + I] =
266-
PlacementArgs[I];
264+
llvm::copy(PlacementArgs,
265+
getTrailingObjects<Stmt *>() + placementNewArgsOffset());
267266
if (IsParenTypeId)
268267
getTrailingObjects<SourceRange>()[0] = TypeIdParens;
269268

@@ -1208,10 +1207,8 @@ CXXConstructExpr::CXXConstructExpr(
12081207
CXXConstructExprBits.Loc = Loc;
12091208

12101209
Stmt **TrailingArgs = getTrailingArgs();
1211-
for (unsigned I = 0, N = Args.size(); I != N; ++I) {
1212-
assert(Args[I] && "NULL argument in CXXConstructExpr!");
1213-
TrailingArgs[I] = Args[I];
1214-
}
1210+
llvm::copy(Args, TrailingArgs);
1211+
assert(llvm::all_of(Args, [](const Stmt *Arg) { return Arg != nullptr; }));
12151212

12161213
// CXXTemporaryObjectExpr does this itself after setting its TypeSourceInfo.
12171214
if (SC == CXXConstructExprClass)
@@ -1472,8 +1469,7 @@ CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(
14721469
RParenLoc(RParenLoc) {
14731470
CXXUnresolvedConstructExprBits.NumArgs = Args.size();
14741471
auto **StoredArgs = getTrailingObjects();
1475-
for (unsigned I = 0; I != Args.size(); ++I)
1476-
StoredArgs[I] = Args[I];
1472+
llvm::copy(Args, StoredArgs);
14771473
setDependence(computeDependence(this));
14781474
}
14791475

@@ -1885,8 +1881,7 @@ TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
18851881
assert(Args.size() == TypeTraitExprBits.NumArgs &&
18861882
"TypeTraitExprBits.NumArgs overflow!");
18871883
auto **ToArgs = getTrailingObjects<TypeSourceInfo *>();
1888-
for (unsigned I = 0, N = Args.size(); I != N; ++I)
1889-
ToArgs[I] = Args[I];
1884+
llvm::copy(Args, ToArgs);
18901885

18911886
setDependence(computeDependence(this));
18921887

clang/lib/AST/ExprConcepts.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,8 @@ RequiresExpr::RequiresExpr(ASTContext &C, SourceLocation RequiresKWLoc,
144144
if (RequirementContainsError(R))
145145
setDependence(getDependence() | ExprDependence::Error);
146146
}
147-
std::copy(LocalParameters.begin(), LocalParameters.end(),
148-
getTrailingObjects<ParmVarDecl *>());
149-
std::copy(Requirements.begin(), Requirements.end(),
150-
getTrailingObjects<concepts::Requirement *>());
147+
llvm::copy(LocalParameters, getTrailingObjects<ParmVarDecl *>());
148+
llvm::copy(Requirements, getTrailingObjects<concepts::Requirement *>());
151149
RequiresExprBits.IsSatisfied |= Dependent;
152150
// FIXME: move the computing dependency logic to ComputeDependence.h
153151
if (ContainsUnexpandedParameterPack)

clang/lib/AST/ExprObjC.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,8 @@ void ObjCMessageExpr::initArgsAndSelLocs(ArrayRef<Expr *> Args,
163163
MyArgs[I] = Args[I];
164164

165165
SelLocsKind = SelLocsK;
166-
if (!isImplicit()) {
167-
if (SelLocsK == SelLoc_NonStandard)
168-
std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs());
169-
}
166+
if (!isImplicit() && SelLocsK == SelLoc_NonStandard)
167+
llvm::copy(SelLocs, getStoredSelLocs());
170168
}
171169

172170
ObjCMessageExpr *

0 commit comments

Comments
 (0)