[clang] [clang][SYCL] Diagnose reference kernel parameters (PR #192957)
Mariya Podchishchaeva via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 29 04:06:30 PDT 2026
================
@@ -0,0 +1,134 @@
+//===- unittests/AST/SubobjectVisitorTest.cpp - Subobject Visitor tests --===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/AST/SubobjectVisitor.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+#include <string>
+#include <vector>
+
+using namespace clang;
+using namespace clang::ast_matchers;
+using namespace clang::tooling;
+
+namespace {
+
+// Helper class to record visited subobjects
+class RecordingVisitor : public SubobjectVisitor<RecordingVisitor> {
+public:
+ std::vector<std::string> VisitedBases;
+ std::vector<std::string> VisitedFields;
+
+ RecordingVisitor(ASTContext &Ctx) : SubobjectVisitor<RecordingVisitor>(Ctx) {}
+
+ bool visitBaseSpecifierPre(CXXBaseSpecifier *BS) {
+ std::string Name = BS->getType()->getAsCXXRecordDecl()->getNameAsString();
+ VisitedBases.push_back(Name);
+ return true;
+ }
+
+ bool visitFieldDeclPre(FieldDecl *FD) {
+ std::string Name = FD->getNameAsString();
+ VisitedFields.push_back(Name);
+ return true;
+ }
+
+};
+
+// Helper function to get a CXXRecordDecl by name
+const CXXRecordDecl *getCXXRecordDecl(ASTUnit *AST, const std::string &Name) {
+ auto Result = match(cxxRecordDecl(hasName(Name)).bind("record"),
+ AST->getASTContext());
+ if (Result.empty())
+ return nullptr;
+ return Result[0].getNodeAs<CXXRecordDecl>("record");
+}
+
+TEST(SubobjectVisitorTest, Basic) {
+ auto AST = buildASTFromCode(R"cpp(
+ struct Base {
+ int BaseF;
+ };
+ struct Inner {
+ int InnerF;
+ };
+ struct S : public Base {
+ int MemberF;
+ Inner StructF;
+ };
+ )cpp");
+ ASSERT_TRUE(AST.get());
+
+ const CXXRecordDecl *RD = getCXXRecordDecl(AST.get(), "S");
+ ASSERT_TRUE(RD);
+
+ RecordingVisitor Visitor(AST->getASTContext());
+ Visitor.visit(AST->getASTContext().getTagType(ElaboratedTypeKeyword::None,
+ std::nullopt, RD, false));
----------------
Fznamznon wrote:
That won't work because `TagDecl::getTypeForDecl()` has been deleted. https://clang.llvm.org/doxygen/classclang_1_1TagDecl.html#ae89281032c91af9f4ec5672220ca4798
https://github.com/llvm/llvm-project/pull/192957
More information about the cfe-commits
mailing list