[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:57:39 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:

I think there is value in setting this to '0', but I've used your suggestion in another way.  I don't think 'setClauseList' can do the copy (as it is just initializing the ArrayRef to the pointer+size pair), but I'm also going to use `std::uninitialized_copy` for the setting of the trailing storage.  

The 'serialization' means the clause `MutableArrayRef` needs to be set in the 'create empty' case.  Let me know what you think about the next version of this patch (more suggestions appreciated!).

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


More information about the cfe-commits mailing list