[clang] [OpenACC][NFC] Add OpenACC Clause AST Nodes/infrastructure (PR #87675)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 5 06:47:58 PDT 2024


================
@@ -101,24 +113,45 @@ class OpenACCAssociatedStmtConstruct : public OpenACCConstructStmt {
 /// those three, as they are semantically identical, and have only minor
 /// differences in the permitted list of clauses, which can be differentiated by
 /// the 'Kind'.
-class OpenACCComputeConstruct : public OpenACCAssociatedStmtConstruct {
+class OpenACCComputeConstruct final
+    : public OpenACCAssociatedStmtConstruct,
+      public llvm::TrailingObjects<OpenACCComputeConstruct,
+                                   const OpenACCClause *> {
   friend class ASTStmtWriter;
   friend class ASTStmtReader;
   friend class ASTContext;
-  OpenACCComputeConstruct()
-      : OpenACCAssociatedStmtConstruct(
-            OpenACCComputeConstructClass, OpenACCDirectiveKind::Invalid,
-            SourceLocation{}, SourceLocation{}, /*AssociatedStmt=*/nullptr) {}
+  OpenACCComputeConstruct(unsigned NumClauses)
+      : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
+                                       OpenACCDirectiveKind::Invalid,
+                                       SourceLocation{}, SourceLocation{},
+                                       /*AssociatedStmt=*/nullptr) {
+    // We cannot send the TrailingObjects storage to the base class (which holds
+    // a reference to the data) until it is constructed, so we have to set it
+    // separately here.
+    memset(getTrailingObjects<const OpenACCClause *>(), 0,
+           NumClauses * sizeof(const OpenACCClause *));
----------------
erichkeane wrote:

Ah!  That DOES seem like it is useful in the other init here.  Perhaps `std::uninitialized_value_construct` is useful for the memcpy.  Patch incoming :) 

https://github.com/llvm/llvm-project/pull/87675


More information about the cfe-commits mailing list