[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:41:16 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:

Do you mean https://en.cppreference.com/w/cpp/memory/uninitialized_default_construct ?  Or is there something else you mean?

`std::uninitialized_default_construct` unfortunately 'default constructs', which means I get indeterminate values instead of nullptr.

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


More information about the cfe-commits mailing list