================
@@ -665,6 +666,101 @@ OutlinedFunctionDecl 
*BuildSYCLKernelEntryPointOutline(Sema &SemaRef,
   return OFD;
 }
 
+class KernelArgsChecker : public SubobjectVisitor<KernelArgsChecker> {
+  SemaSYCL &SemaSYCLRef;
+  bool IsValid = true;
+  using ObjectAccess =
+      llvm::PointerUnion<ParmVarDecl *, CXXBaseSpecifier *, FieldDecl *>;
+  SmallVector<ObjectAccess, 4> ObjectAccessPath;
+
+  void emitObjectAccessPathNotes() {
+    for (auto Parent : ObjectAccessPath) {
+      if (auto *FD = Parent.dyn_cast<FieldDecl *>()) {
+        SemaSYCLRef.Diag(FD->getParent()->getLocation(),
+                         diag::note_within_field_of_type)
+            << FD->getParent();
+      } else if (auto *BS = Parent.dyn_cast<CXXBaseSpecifier *>()) {
+        CXXRecordDecl *RD = BS->getType()->getAsCXXRecordDecl();
+        assert(RD);
+        SemaSYCLRef.Diag(BS->getBeginLoc(), diag::note_within_base_of_type)
+            << RD;
+      } else {
+        // Nothing to emit for ParmVarDecl since its location just points to
+        // skep-attributed function template.
+        assert(isa<ParmVarDecl *>(Parent));
+      }
+    }
+  }
+
+public:
+  KernelArgsChecker(SemaSYCL &SR, SourceLocation Loc)
+      : SubobjectVisitor<KernelArgsChecker>(SR.getASTContext()),
+        SemaSYCLRef(SR) {}
+
+  void checkParameter(ParmVarDecl *PVD) {
+    ObjectAccessPath.push_back(PVD);
+    // Check the immediate type of the parameter.
+    if (checkType(PVD->getType())) {
+      // If type checking wasn't short circuited, visit subobjects to check
+      // them.
+      visit(PVD->getType());
+    }
+    ObjectAccessPath.pop_back();
+    // We either visited everything or we stopped visiting due to invalid 
kernel
+    // argument type.
----------------
tahonermann wrote:

Oh! That's my mistake; I gave you a bad implementation of `traverseRecord()`. I 
added a comment to suggest a change to it. We should be able to assert that 
`ObjectAccessPath` is empty after the pop of `PVD`.

```suggestion
  assert(ObjectAccessPath.empty());
```

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