Skip to content

[NFC][Support] Add llvm::uninitialized_copy #138174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jurahul
Copy link
Contributor

@jurahul jurahul commented May 1, 2025

Add llvm::uninitialized_copy that accepts a range instead of start/end iterator for the source of the copy.

@jurahul jurahul force-pushed the llvm_uninitialized_copy branch 5 times, most recently from 705699c to 7fde96d Compare May 2, 2025 12:33
@jurahul jurahul marked this pull request as ready for review May 2, 2025 15:00
@jurahul jurahul requested review from JDevlieghere and nikic as code owners May 2, 2025 15:00
@llvmbot llvmbot added clang Clang issues not falling into any other category lldb backend:AMDGPU clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:as-a-library libclang and C++ API mlir:core MLIR Core Infrastructure tablegen debuginfo mlir:affine mlir llvm:support mlir:ods llvm:ir objectyaml llvm:analysis llvm:transforms llvm:adt labels May 2, 2025
@llvmbot
Copy link
Member

llvmbot commented May 2, 2025

@llvm/pr-subscribers-llvm-support
@llvm/pr-subscribers-llvm-adt
@llvm/pr-subscribers-llvm-ir
@llvm/pr-subscribers-llvm-analysis
@llvm/pr-subscribers-mlir-affine
@llvm/pr-subscribers-mlir-ods
@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-backend-amdgpu

Author: Rahul Joshi (jurahul)

Changes

Add llvm::uninitialized_copy that accepts a range instead of start/end iterator for the source of the copy.


Patch is 64.57 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/138174.diff

37 Files Affected:

  • (modified) clang/include/clang/AST/DeclCXX.h (+2-4)
  • (modified) clang/include/clang/AST/DeclOpenACC.h (+5-4)
  • (modified) clang/include/clang/AST/ExprCXX.h (+3-3)
  • (modified) clang/include/clang/AST/OpenACCClause.h (+26-46)
  • (modified) clang/include/clang/AST/StmtOpenACC.h (+26-28)
  • (modified) clang/include/clang/Sema/ParsedTemplate.h (+2-2)
  • (modified) clang/lib/AST/Decl.cpp (+2-4)
  • (modified) clang/lib/AST/DeclObjC.cpp (+2-2)
  • (modified) clang/lib/AST/DeclTemplate.cpp (+4-7)
  • (modified) clang/lib/AST/Expr.cpp (+4-4)
  • (modified) clang/lib/AST/ExprCXX.cpp (+8-8)
  • (modified) clang/lib/AST/OpenACCClause.cpp (+5-8)
  • (modified) clang/lib/AST/StmtOpenACC.cpp (+2-2)
  • (modified) clang/lib/AST/Type.cpp (+3-5)
  • (modified) clang/tools/libclang/CXIndexDataConsumer.cpp (+2-1)
  • (modified) lldb/source/Utility/Checksum.cpp (+2-2)
  • (modified) llvm/include/llvm/ADT/ArrayRef.h (+1-1)
  • (modified) llvm/include/llvm/ADT/STLExtras.h (+5)
  • (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+5-5)
  • (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+1-2)
  • (modified) llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp (+2-2)
  • (modified) llvm/lib/DebugInfo/MSF/MSFBuilder.cpp (+2-4)
  • (modified) llvm/lib/IR/AttributeImpl.h (+1-1)
  • (modified) llvm/lib/ObjectYAML/MinidumpEmitter.cpp (+1-1)
  • (modified) llvm/lib/Support/FoldingSet.cpp (+2-2)
  • (modified) llvm/lib/TableGen/Record.cpp (+8-15)
  • (modified) llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp (+1-1)
  • (modified) llvm/lib/Transforms/IPO/LowerTypeTests.cpp (+3-4)
  • (modified) llvm/unittests/Support/TrailingObjectsTest.cpp (+10-9)
  • (modified) mlir/include/mlir/IR/BuiltinAttributes.td (+1-1)
  • (modified) mlir/include/mlir/Support/StorageUniquer.h (+2-2)
  • (modified) mlir/lib/Dialect/Affine/Analysis/NestedMatcher.cpp (+2-2)
  • (modified) mlir/lib/IR/AffineMapDetail.h (+1-2)
  • (modified) mlir/lib/IR/Location.cpp (+4-4)
  • (modified) mlir/lib/IR/MLIRContext.cpp (+1-1)
  • (modified) mlir/lib/IR/TypeDetail.h (+1-2)
  • (modified) mlir/lib/Tools/PDLL/AST/Nodes.cpp (+14-28)
diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h
index dd325815ee28d..20720115bf6c3 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -3861,8 +3861,7 @@ class UsingPackDecl final
                   InstantiatedFrom ? InstantiatedFrom->getDeclName()
                                    : DeclarationName()),
         InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) {
-    std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(),
-                            getTrailingObjects<NamedDecl *>());
+    llvm::uninitialized_copy(UsingDecls, getTrailingObjects<NamedDecl *>());
   }
 
   void anchor() override;
@@ -4233,8 +4232,7 @@ class DecompositionDecl final
       : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo,
                 SC),
         NumBindings(Bindings.size()) {
-    std::uninitialized_copy(Bindings.begin(), Bindings.end(),
-                            getTrailingObjects<BindingDecl *>());
+    llvm::uninitialized_copy(Bindings, getTrailingObjects<BindingDecl *>());
     for (auto *B : Bindings) {
       B->setDecomposedDecl(this);
       if (B->isParameterPack() && B->getBinding()) {
diff --git a/clang/include/clang/AST/DeclOpenACC.h b/clang/include/clang/AST/DeclOpenACC.h
index 8c612fbf1ec07..905d9bf636ea1 100644
--- a/clang/include/clang/AST/DeclOpenACC.h
+++ b/clang/include/clang/AST/DeclOpenACC.h
@@ -18,6 +18,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/OpenACCClause.h"
 #include "clang/Basic/OpenACCKinds.h"
+#include "llvm/ADT/STLExtras.h"
 
 namespace clang {
 
@@ -85,8 +86,8 @@ class OpenACCDeclareDecl final
       : OpenACCConstructDecl(OpenACCDeclare, DC, OpenACCDirectiveKind::Declare,
                              StartLoc, DirLoc, EndLoc) {
     // Initialize the trailing storage.
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
 
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
@@ -136,8 +137,8 @@ class OpenACCRoutineDecl final
     assert(LParenLoc.isValid() &&
            "Cannot represent implicit name with this declaration");
     // Initialize the trailing storage.
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
   }
diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h
index 844f6dd90ae1d..15d94a8765dd6 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -41,6 +41,7 @@
 #include "clang/Basic/TypeTraits.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Casting.h"
@@ -4417,7 +4418,7 @@ class SizeOfPackExpr final
     assert((!Length || PartialArgs.empty()) &&
            "have partial args for non-dependent sizeof... expression");
     auto *Args = getTrailingObjects<TemplateArgument>();
-    std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args);
+    llvm::uninitialized_copy(PartialArgs, Args);
     setDependence(Length ? ExprDependence::None
                          : ExprDependence::ValueInstantiation);
   }
@@ -4522,8 +4523,7 @@ class PackIndexingExpr final
         FullySubstituted(FullySubstituted) {
 
     auto *Exprs = getTrailingObjects<Expr *>();
-    std::uninitialized_copy(SubstitutedExprs.begin(), SubstitutedExprs.end(),
-                            Exprs);
+    llvm::uninitialized_copy(SubstitutedExprs, Exprs);
 
     setDependence(computeDependence(this));
     if (!isInstantiationDependent())
diff --git a/clang/include/clang/AST/OpenACCClause.h b/clang/include/clang/AST/OpenACCClause.h
index 449bcb71f9f32..65377b91f83d3 100644
--- a/clang/include/clang/AST/OpenACCClause.h
+++ b/clang/include/clang/AST/OpenACCClause.h
@@ -13,9 +13,11 @@
 
 #ifndef LLVM_CLANG_AST_OPENACCCLAUSE_H
 #define LLVM_CLANG_AST_OPENACCCLAUSE_H
+
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/StmtIterator.h"
 #include "clang/Basic/OpenACCKinds.h"
+#include "llvm/ADT/STLExtras.h"
 
 #include <utility>
 #include <variant>
@@ -291,8 +293,7 @@ class OpenACCDeviceTypeClause final
            "Only a single asterisk version is permitted, and must be the "
            "only one");
 
-    std::uninitialized_copy(Archs.begin(), Archs.end(),
-                            getTrailingObjects<DeviceTypeArgument>());
+    llvm::uninitialized_copy(Archs, getTrailingObjects<DeviceTypeArgument>());
   }
 
 public:
@@ -537,10 +538,9 @@ class OpenACCWaitClause final
         QueuesLoc(QueuesLoc) {
     // The first element of the trailing storage is always the devnum expr,
     // whether it is used or not.
-    std::uninitialized_copy(&DevNumExpr, &DevNumExpr + 1,
-                            getTrailingObjects<Expr *>());
-    std::uninitialized_copy(QueueIdExprs.begin(), QueueIdExprs.end(),
-                            getTrailingObjects<Expr *>() + 1);
+    auto *Exprs = getTrailingObjects<Expr *>();
+    llvm::uninitialized_copy(ArrayRef(DevNumExpr), Exprs);
+    llvm::uninitialized_copy(QueueIdExprs, Exprs + 1);
     setExprs(
         MutableArrayRef(getTrailingObjects<Expr *>(), QueueIdExprs.size() + 1));
   }
@@ -579,8 +579,7 @@ class OpenACCNumGangsClause final
                         ArrayRef<Expr *> IntExprs, SourceLocation EndLoc)
       : OpenACCClauseWithExprs(OpenACCClauseKind::NumGangs, BeginLoc, LParenLoc,
                                EndLoc) {
-    std::uninitialized_copy(IntExprs.begin(), IntExprs.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(IntExprs, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), IntExprs.size()));
   }
 
@@ -609,8 +608,7 @@ class OpenACCTileClause final
                     ArrayRef<Expr *> SizeExprs, SourceLocation EndLoc)
       : OpenACCClauseWithExprs(OpenACCClauseKind::Tile, BeginLoc, LParenLoc,
                                EndLoc) {
-    std::uninitialized_copy(SizeExprs.begin(), SizeExprs.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(SizeExprs, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), SizeExprs.size()));
   }
 
@@ -848,8 +846,7 @@ class OpenACCPrivateClause final
                        ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Private, BeginLoc,
                                  LParenLoc, EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -871,8 +868,7 @@ class OpenACCFirstPrivateClause final
                             ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::FirstPrivate, BeginLoc,
                                  LParenLoc, EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -894,8 +890,7 @@ class OpenACCDevicePtrClause final
                          ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::DevicePtr, BeginLoc,
                                  LParenLoc, EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -917,8 +912,7 @@ class OpenACCAttachClause final
                       ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Attach, BeginLoc, LParenLoc,
                                  EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -940,8 +934,7 @@ class OpenACCDetachClause final
                       ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Detach, BeginLoc, LParenLoc,
                                  EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -963,8 +956,7 @@ class OpenACCDeleteClause final
                       ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Delete, BeginLoc, LParenLoc,
                                  EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -986,8 +978,7 @@ class OpenACCUseDeviceClause final
                          ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::UseDevice, BeginLoc,
                                  LParenLoc, EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1009,8 +1000,7 @@ class OpenACCNoCreateClause final
                         ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::NoCreate, BeginLoc,
                                  LParenLoc, EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1032,8 +1022,7 @@ class OpenACCPresentClause final
                        ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Present, BeginLoc,
                                  LParenLoc, EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1054,8 +1043,7 @@ class OpenACCHostClause final
                     ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Host, BeginLoc, LParenLoc,
                                  EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1078,8 +1066,7 @@ class OpenACCDeviceClause final
                       ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Device, BeginLoc, LParenLoc,
                                  EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1107,8 +1094,7 @@ class OpenACCCopyClause final
             Spelling == OpenACCClauseKind::PCopy ||
             Spelling == OpenACCClauseKind::PresentOrCopy) &&
            "Invalid clause kind for copy-clause");
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1142,8 +1128,7 @@ class OpenACCCopyInClause final
             Spelling == OpenACCClauseKind::PCopyIn ||
             Spelling == OpenACCClauseKind::PresentOrCopyIn) &&
            "Invalid clause kind for copyin-clause");
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1176,8 +1161,7 @@ class OpenACCCopyOutClause final
             Spelling == OpenACCClauseKind::PCopyOut ||
             Spelling == OpenACCClauseKind::PresentOrCopyOut) &&
            "Invalid clause kind for copyout-clause");
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1210,8 +1194,7 @@ class OpenACCCreateClause final
             Spelling == OpenACCClauseKind::PCreate ||
             Spelling == OpenACCClauseKind::PresentOrCreate) &&
            "Invalid clause kind for create-clause");
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1241,8 +1224,7 @@ class OpenACCReductionClause final
       : OpenACCClauseWithVarList(OpenACCClauseKind::Reduction, BeginLoc,
                                  LParenLoc, EndLoc),
         Op(Operator) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1268,8 +1250,7 @@ class OpenACCLinkClause final
                     ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Link, BeginLoc, LParenLoc,
                                  EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1293,8 +1274,7 @@ class OpenACCDeviceResidentClause final
                               ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::DeviceResident, BeginLoc,
                                  LParenLoc, EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
diff --git a/clang/include/clang/AST/StmtOpenACC.h b/clang/include/clang/AST/StmtOpenACC.h
index 39c4c81844911..9aae91372e264 100644
--- a/clang/include/clang/AST/StmtOpenACC.h
+++ b/clang/include/clang/AST/StmtOpenACC.h
@@ -17,6 +17,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/Basic/OpenACCKinds.h"
 #include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/STLExtras.h"
 #include <memory>
 
 namespace clang {
@@ -159,8 +160,8 @@ class OpenACCComputeConstruct final
            "represented by this type");
 
     // Initialize the trailing storage.
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
 
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
@@ -272,8 +273,8 @@ class OpenACCCombinedConstruct final
            "Only parallel loop, serial loop, and kernels loop constructs "
            "should be represented by this type");
 
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
   }
@@ -322,8 +323,8 @@ class OpenACCDataConstruct final
       : OpenACCAssociatedStmtConstruct(OpenACCDataConstructClass,
                                        OpenACCDirectiveKind::Data, Start,
                                        DirectiveLoc, End, StructuredBlock) {
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
   }
@@ -368,8 +369,8 @@ class OpenACCEnterDataConstruct final
       : OpenACCConstructStmt(OpenACCEnterDataConstructClass,
                              OpenACCDirectiveKind::EnterData, Start,
                              DirectiveLoc, End) {
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
   }
@@ -406,8 +407,8 @@ class OpenACCExitDataConstruct final
       : OpenACCConstructStmt(OpenACCExitDataConstructClass,
                              OpenACCDirectiveKind::ExitData, Start,
                              DirectiveLoc, End) {
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
   }
@@ -447,8 +448,8 @@ class OpenACCHostDataConstruct final
       : OpenACCAssociatedStmtConstruct(OpenACCHostDataConstructClass,
                                        OpenACCDirectiveKind::HostData, Start,
                                        DirectiveLoc, End, StructuredBlock) {
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
   }
@@ -525,11 +526,8 @@ class OpenACCWaitConstruct final
            "NumExprs should always be >= 1 because the '...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented May 2, 2025

@llvm/pr-subscribers-mlir-core

Author: Rahul Joshi (jurahul)

Changes

Add llvm::uninitialized_copy that accepts a range instead of start/end iterator for the source of the copy.


Patch is 64.57 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/138174.diff

37 Files Affected:

  • (modified) clang/include/clang/AST/DeclCXX.h (+2-4)
  • (modified) clang/include/clang/AST/DeclOpenACC.h (+5-4)
  • (modified) clang/include/clang/AST/ExprCXX.h (+3-3)
  • (modified) clang/include/clang/AST/OpenACCClause.h (+26-46)
  • (modified) clang/include/clang/AST/StmtOpenACC.h (+26-28)
  • (modified) clang/include/clang/Sema/ParsedTemplate.h (+2-2)
  • (modified) clang/lib/AST/Decl.cpp (+2-4)
  • (modified) clang/lib/AST/DeclObjC.cpp (+2-2)
  • (modified) clang/lib/AST/DeclTemplate.cpp (+4-7)
  • (modified) clang/lib/AST/Expr.cpp (+4-4)
  • (modified) clang/lib/AST/ExprCXX.cpp (+8-8)
  • (modified) clang/lib/AST/OpenACCClause.cpp (+5-8)
  • (modified) clang/lib/AST/StmtOpenACC.cpp (+2-2)
  • (modified) clang/lib/AST/Type.cpp (+3-5)
  • (modified) clang/tools/libclang/CXIndexDataConsumer.cpp (+2-1)
  • (modified) lldb/source/Utility/Checksum.cpp (+2-2)
  • (modified) llvm/include/llvm/ADT/ArrayRef.h (+1-1)
  • (modified) llvm/include/llvm/ADT/STLExtras.h (+5)
  • (modified) llvm/lib/Analysis/ScalarEvolution.cpp (+5-5)
  • (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+1-2)
  • (modified) llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp (+2-2)
  • (modified) llvm/lib/DebugInfo/MSF/MSFBuilder.cpp (+2-4)
  • (modified) llvm/lib/IR/AttributeImpl.h (+1-1)
  • (modified) llvm/lib/ObjectYAML/MinidumpEmitter.cpp (+1-1)
  • (modified) llvm/lib/Support/FoldingSet.cpp (+2-2)
  • (modified) llvm/lib/TableGen/Record.cpp (+8-15)
  • (modified) llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp (+1-1)
  • (modified) llvm/lib/Transforms/IPO/LowerTypeTests.cpp (+3-4)
  • (modified) llvm/unittests/Support/TrailingObjectsTest.cpp (+10-9)
  • (modified) mlir/include/mlir/IR/BuiltinAttributes.td (+1-1)
  • (modified) mlir/include/mlir/Support/StorageUniquer.h (+2-2)
  • (modified) mlir/lib/Dialect/Affine/Analysis/NestedMatcher.cpp (+2-2)
  • (modified) mlir/lib/IR/AffineMapDetail.h (+1-2)
  • (modified) mlir/lib/IR/Location.cpp (+4-4)
  • (modified) mlir/lib/IR/MLIRContext.cpp (+1-1)
  • (modified) mlir/lib/IR/TypeDetail.h (+1-2)
  • (modified) mlir/lib/Tools/PDLL/AST/Nodes.cpp (+14-28)
diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h
index dd325815ee28d..20720115bf6c3 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -3861,8 +3861,7 @@ class UsingPackDecl final
                   InstantiatedFrom ? InstantiatedFrom->getDeclName()
                                    : DeclarationName()),
         InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) {
-    std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(),
-                            getTrailingObjects<NamedDecl *>());
+    llvm::uninitialized_copy(UsingDecls, getTrailingObjects<NamedDecl *>());
   }
 
   void anchor() override;
@@ -4233,8 +4232,7 @@ class DecompositionDecl final
       : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo,
                 SC),
         NumBindings(Bindings.size()) {
-    std::uninitialized_copy(Bindings.begin(), Bindings.end(),
-                            getTrailingObjects<BindingDecl *>());
+    llvm::uninitialized_copy(Bindings, getTrailingObjects<BindingDecl *>());
     for (auto *B : Bindings) {
       B->setDecomposedDecl(this);
       if (B->isParameterPack() && B->getBinding()) {
diff --git a/clang/include/clang/AST/DeclOpenACC.h b/clang/include/clang/AST/DeclOpenACC.h
index 8c612fbf1ec07..905d9bf636ea1 100644
--- a/clang/include/clang/AST/DeclOpenACC.h
+++ b/clang/include/clang/AST/DeclOpenACC.h
@@ -18,6 +18,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/OpenACCClause.h"
 #include "clang/Basic/OpenACCKinds.h"
+#include "llvm/ADT/STLExtras.h"
 
 namespace clang {
 
@@ -85,8 +86,8 @@ class OpenACCDeclareDecl final
       : OpenACCConstructDecl(OpenACCDeclare, DC, OpenACCDirectiveKind::Declare,
                              StartLoc, DirLoc, EndLoc) {
     // Initialize the trailing storage.
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
 
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
@@ -136,8 +137,8 @@ class OpenACCRoutineDecl final
     assert(LParenLoc.isValid() &&
            "Cannot represent implicit name with this declaration");
     // Initialize the trailing storage.
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
   }
diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h
index 844f6dd90ae1d..15d94a8765dd6 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -41,6 +41,7 @@
 #include "clang/Basic/TypeTraits.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Casting.h"
@@ -4417,7 +4418,7 @@ class SizeOfPackExpr final
     assert((!Length || PartialArgs.empty()) &&
            "have partial args for non-dependent sizeof... expression");
     auto *Args = getTrailingObjects<TemplateArgument>();
-    std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args);
+    llvm::uninitialized_copy(PartialArgs, Args);
     setDependence(Length ? ExprDependence::None
                          : ExprDependence::ValueInstantiation);
   }
@@ -4522,8 +4523,7 @@ class PackIndexingExpr final
         FullySubstituted(FullySubstituted) {
 
     auto *Exprs = getTrailingObjects<Expr *>();
-    std::uninitialized_copy(SubstitutedExprs.begin(), SubstitutedExprs.end(),
-                            Exprs);
+    llvm::uninitialized_copy(SubstitutedExprs, Exprs);
 
     setDependence(computeDependence(this));
     if (!isInstantiationDependent())
diff --git a/clang/include/clang/AST/OpenACCClause.h b/clang/include/clang/AST/OpenACCClause.h
index 449bcb71f9f32..65377b91f83d3 100644
--- a/clang/include/clang/AST/OpenACCClause.h
+++ b/clang/include/clang/AST/OpenACCClause.h
@@ -13,9 +13,11 @@
 
 #ifndef LLVM_CLANG_AST_OPENACCCLAUSE_H
 #define LLVM_CLANG_AST_OPENACCCLAUSE_H
+
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/StmtIterator.h"
 #include "clang/Basic/OpenACCKinds.h"
+#include "llvm/ADT/STLExtras.h"
 
 #include <utility>
 #include <variant>
@@ -291,8 +293,7 @@ class OpenACCDeviceTypeClause final
            "Only a single asterisk version is permitted, and must be the "
            "only one");
 
-    std::uninitialized_copy(Archs.begin(), Archs.end(),
-                            getTrailingObjects<DeviceTypeArgument>());
+    llvm::uninitialized_copy(Archs, getTrailingObjects<DeviceTypeArgument>());
   }
 
 public:
@@ -537,10 +538,9 @@ class OpenACCWaitClause final
         QueuesLoc(QueuesLoc) {
     // The first element of the trailing storage is always the devnum expr,
     // whether it is used or not.
-    std::uninitialized_copy(&DevNumExpr, &DevNumExpr + 1,
-                            getTrailingObjects<Expr *>());
-    std::uninitialized_copy(QueueIdExprs.begin(), QueueIdExprs.end(),
-                            getTrailingObjects<Expr *>() + 1);
+    auto *Exprs = getTrailingObjects<Expr *>();
+    llvm::uninitialized_copy(ArrayRef(DevNumExpr), Exprs);
+    llvm::uninitialized_copy(QueueIdExprs, Exprs + 1);
     setExprs(
         MutableArrayRef(getTrailingObjects<Expr *>(), QueueIdExprs.size() + 1));
   }
@@ -579,8 +579,7 @@ class OpenACCNumGangsClause final
                         ArrayRef<Expr *> IntExprs, SourceLocation EndLoc)
       : OpenACCClauseWithExprs(OpenACCClauseKind::NumGangs, BeginLoc, LParenLoc,
                                EndLoc) {
-    std::uninitialized_copy(IntExprs.begin(), IntExprs.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(IntExprs, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), IntExprs.size()));
   }
 
@@ -609,8 +608,7 @@ class OpenACCTileClause final
                     ArrayRef<Expr *> SizeExprs, SourceLocation EndLoc)
       : OpenACCClauseWithExprs(OpenACCClauseKind::Tile, BeginLoc, LParenLoc,
                                EndLoc) {
-    std::uninitialized_copy(SizeExprs.begin(), SizeExprs.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(SizeExprs, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), SizeExprs.size()));
   }
 
@@ -848,8 +846,7 @@ class OpenACCPrivateClause final
                        ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Private, BeginLoc,
                                  LParenLoc, EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -871,8 +868,7 @@ class OpenACCFirstPrivateClause final
                             ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::FirstPrivate, BeginLoc,
                                  LParenLoc, EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -894,8 +890,7 @@ class OpenACCDevicePtrClause final
                          ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::DevicePtr, BeginLoc,
                                  LParenLoc, EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -917,8 +912,7 @@ class OpenACCAttachClause final
                       ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Attach, BeginLoc, LParenLoc,
                                  EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -940,8 +934,7 @@ class OpenACCDetachClause final
                       ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Detach, BeginLoc, LParenLoc,
                                  EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -963,8 +956,7 @@ class OpenACCDeleteClause final
                       ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Delete, BeginLoc, LParenLoc,
                                  EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -986,8 +978,7 @@ class OpenACCUseDeviceClause final
                          ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::UseDevice, BeginLoc,
                                  LParenLoc, EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1009,8 +1000,7 @@ class OpenACCNoCreateClause final
                         ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::NoCreate, BeginLoc,
                                  LParenLoc, EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1032,8 +1022,7 @@ class OpenACCPresentClause final
                        ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Present, BeginLoc,
                                  LParenLoc, EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1054,8 +1043,7 @@ class OpenACCHostClause final
                     ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Host, BeginLoc, LParenLoc,
                                  EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1078,8 +1066,7 @@ class OpenACCDeviceClause final
                       ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Device, BeginLoc, LParenLoc,
                                  EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1107,8 +1094,7 @@ class OpenACCCopyClause final
             Spelling == OpenACCClauseKind::PCopy ||
             Spelling == OpenACCClauseKind::PresentOrCopy) &&
            "Invalid clause kind for copy-clause");
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1142,8 +1128,7 @@ class OpenACCCopyInClause final
             Spelling == OpenACCClauseKind::PCopyIn ||
             Spelling == OpenACCClauseKind::PresentOrCopyIn) &&
            "Invalid clause kind for copyin-clause");
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1176,8 +1161,7 @@ class OpenACCCopyOutClause final
             Spelling == OpenACCClauseKind::PCopyOut ||
             Spelling == OpenACCClauseKind::PresentOrCopyOut) &&
            "Invalid clause kind for copyout-clause");
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1210,8 +1194,7 @@ class OpenACCCreateClause final
             Spelling == OpenACCClauseKind::PCreate ||
             Spelling == OpenACCClauseKind::PresentOrCreate) &&
            "Invalid clause kind for create-clause");
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1241,8 +1224,7 @@ class OpenACCReductionClause final
       : OpenACCClauseWithVarList(OpenACCClauseKind::Reduction, BeginLoc,
                                  LParenLoc, EndLoc),
         Op(Operator) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1268,8 +1250,7 @@ class OpenACCLinkClause final
                     ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::Link, BeginLoc, LParenLoc,
                                  EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
@@ -1293,8 +1274,7 @@ class OpenACCDeviceResidentClause final
                               ArrayRef<Expr *> VarList, SourceLocation EndLoc)
       : OpenACCClauseWithVarList(OpenACCClauseKind::DeviceResident, BeginLoc,
                                  LParenLoc, EndLoc) {
-    std::uninitialized_copy(VarList.begin(), VarList.end(),
-                            getTrailingObjects<Expr *>());
+    llvm::uninitialized_copy(VarList, getTrailingObjects<Expr *>());
     setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
   }
 
diff --git a/clang/include/clang/AST/StmtOpenACC.h b/clang/include/clang/AST/StmtOpenACC.h
index 39c4c81844911..9aae91372e264 100644
--- a/clang/include/clang/AST/StmtOpenACC.h
+++ b/clang/include/clang/AST/StmtOpenACC.h
@@ -17,6 +17,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/Basic/OpenACCKinds.h"
 #include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/STLExtras.h"
 #include <memory>
 
 namespace clang {
@@ -159,8 +160,8 @@ class OpenACCComputeConstruct final
            "represented by this type");
 
     // Initialize the trailing storage.
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
 
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
@@ -272,8 +273,8 @@ class OpenACCCombinedConstruct final
            "Only parallel loop, serial loop, and kernels loop constructs "
            "should be represented by this type");
 
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
   }
@@ -322,8 +323,8 @@ class OpenACCDataConstruct final
       : OpenACCAssociatedStmtConstruct(OpenACCDataConstructClass,
                                        OpenACCDirectiveKind::Data, Start,
                                        DirectiveLoc, End, StructuredBlock) {
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
   }
@@ -368,8 +369,8 @@ class OpenACCEnterDataConstruct final
       : OpenACCConstructStmt(OpenACCEnterDataConstructClass,
                              OpenACCDirectiveKind::EnterData, Start,
                              DirectiveLoc, End) {
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
   }
@@ -406,8 +407,8 @@ class OpenACCExitDataConstruct final
       : OpenACCConstructStmt(OpenACCExitDataConstructClass,
                              OpenACCDirectiveKind::ExitData, Start,
                              DirectiveLoc, End) {
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
   }
@@ -447,8 +448,8 @@ class OpenACCHostDataConstruct final
       : OpenACCAssociatedStmtConstruct(OpenACCHostDataConstructClass,
                                        OpenACCDirectiveKind::HostData, Start,
                                        DirectiveLoc, End, StructuredBlock) {
-    std::uninitialized_copy(Clauses.begin(), Clauses.end(),
-                            getTrailingObjects<const OpenACCClause *>());
+    llvm::uninitialized_copy(Clauses,
+                             getTrailingObjects<const OpenACCClause *>());
     setClauseList(MutableArrayRef(getTrailingObjects<const OpenACCClause *>(),
                                   Clauses.size()));
   }
@@ -525,11 +526,8 @@ class OpenACCWaitConstruct final
            "NumExprs should always be >= 1 because the '...
[truncated]

@jurahul jurahul requested review from jpienaar and removed request for JDevlieghere May 2, 2025 15:01
@jurahul jurahul requested a review from erichkeane May 2, 2025 15:01
Copy link
Collaborator

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks right, but I'd like someone else to go through to make sure it is right everywhere.

Also, the md5 change looks... odd and counts a lot on the internal representation of md5, so I'm not sure about that one, but at least it is right NOW (Since MD5 inherits from std::array).

@jurahul
Copy link
Contributor Author

jurahul commented May 2, 2025

This looks right, but I'd like someone else to go through to make sure it is right everywhere.

Also, the md5 change looks... odd and counts a lot on the internal representation of md5, so I'm not sure about that one, but at least it is right NOW (Since MD5 inherits from std::array).

For reference, this change is in lldb/source/Utility/Checksum.cpp in the PR. Right, if something changes there the static_assert that I added will fail, so in that sense it won't go unnoticed and cause subtle runtime issues.

@jurahul jurahul force-pushed the llvm_uninitialized_copy branch from 7fde96d to 7c67ef6 Compare May 2, 2025 17:45
@jurahul jurahul requested a review from s-barannikov May 2, 2025 17:53
Add `llvm::uninitialized_copy` that accepts a range instead of two
iterators for the source of the copy and adopt it.
@jurahul jurahul force-pushed the llvm_uninitialized_copy branch from 7c67ef6 to 46542ce Compare May 2, 2025 19:22
@jurahul jurahul requested a review from s-barannikov May 2, 2025 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU clang:as-a-library libclang and C++ API clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category debuginfo lldb llvm:adt llvm:analysis llvm:ir llvm:support llvm:transforms mlir:affine mlir:core MLIR Core Infrastructure mlir:ods mlir objectyaml tablegen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants