================
@@ -0,0 +1,105 @@
+//===---------- SubobjectVisitor.h - Subobject Visitor ----------*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines the SubobjectVisitor interface, which recursively
+//  traverses subobjects within a type.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_SUBOBJECTVISITOR_H
+#define LLVM_CLANG_AST_SUBOBJECTVISITOR_H
+
+#include "clang/AST/Type.h"
+
+namespace clang {
+
+/// Given a type, subobject visitors visit all subobjects of the type in depth
+/// first order. Both pre-order and post-order visitation are performed so that
+/// derived classes can maintain an access path to the visited elements.
+/// Subobjects include all base classes and non-static data members, including
+/// those that are not subobjects according to the C++standard like data
+/// members with a reference type. Virtual base classes are visited each time
+/// they appear in a class hierarchy despite there being only one actual
+/// subobject present in an object of a most derived type. Array elements are
+/// not individually visited; only their containing array is.
+template <template <typename> class Ptr, typename Derived>
+class SubobjectVisitorBase {
+  ASTContext &Ctx;
+  template <typename Class> using ptr_t = typename Ptr<Class>::type;
+
+public:
+  SubobjectVisitorBase(ASTContext &Ctx) : Ctx(Ctx) {}
+
+  /// Return a reference to the derived class.
+  Derived &getDerived() { return *static_cast<Derived *>(this); }
+
+  void visit(QualType QT) {
+    // If the type is an array, visit its element type. Separate traversal of
+    // arrays is not needed because the array will be encountered as a
+    // FieldDecl.
+
+    if (QT->isArrayType()) {
+      QualType ElTy =
+          cast<ConstantArrayType>(Ctx.getAsArrayType(QT))->getElementType();
----------------
tahonermann wrote:

We will need to implement a diagnostic to reject types with flexible data 
members at some point. DPC++ implements such a diagnostic. 
https://godbolt.org/z/7KoqznvMK. I think that can be done in a later PR though.

@Fznamznon, I'm not sure what happens when a `[[sycl_kernel_entry_point]]` 
attributed function has a parameter of reference to array type when the 
reference is dropped to produce the kernel entry point function. Do we get an 
implicit array-to-pointer decay? Or do we produce a kernel entry point function 
that somehow expects an array to be passed as a prvalue? We probably should 
diagnose such cases. A test for a variably modified type could be reasonable 
too. https://godbolt.org/z/v4P8Kn7xT.

https://github.com/llvm/llvm-project/pull/192957
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to