@@ -2051,6 +2051,27 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
20512051 return false ;
20522052 }
20532053
2054+ bool hasVirtualInheritance (const CXXRecordDecl *RD, ParmVarDecl *PD) {
2055+ if (RD->getNumBases () > 0 ) {
2056+ for (const auto &Base : RD->bases ()) {
2057+ QualType BaseType = Base.getType ();
2058+ if (const CXXRecordDecl *BaseDecl = BaseType->getAsCXXRecordDecl ();
2059+ BaseDecl) {
2060+ if (Base.isVirtual ()) {
2061+ const FunctionDecl *FD =
2062+ dyn_cast<FunctionDecl>(PD->getDeclContext ());
2063+ SemaSYCLRef.SemaRef .Diag (FD->getLocation (),
2064+ diag::err_free_function_virtual_arg)
2065+ << RD->getNameAsString () << Base.getType ().getAsString ();
2066+ return true ;
2067+ } else if (BaseDecl->getNumBases () > 0 )
2068+ hasVirtualInheritance (BaseDecl, PD);
2069+ }
2070+ }
2071+ }
2072+ return false ;
2073+ }
2074+
20542075public:
20552076 SyclKernelFieldChecker (SemaSYCL &S)
20562077 : SyclKernelFieldHandler(S), Diag(S.getASTContext().getDiagnostics()) {}
@@ -2089,24 +2110,6 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
20892110 return isValid ();
20902111 }
20912112 CXXRecordDecl *RD = ParamTy->getAsCXXRecordDecl ();
2092- // Free functions do not support for virtual inheritance.
2093- if (RD->getNumBases () > 0 ) {
2094- for (const auto &Base : RD->bases ()) {
2095- QualType BaseType = Base.getType ();
2096- const CXXRecordDecl *BaseDecl = BaseType->getAsCXXRecordDecl ();
2097- if (BaseDecl) {
2098- if (Base.isVirtual ()) {
2099- const FunctionDecl *FD =
2100- dyn_cast<FunctionDecl>(PD->getDeclContext ());
2101- SemaSYCLRef.SemaRef .Diag (FD->getLocation (),
2102- diag::err_free_function_virtual_arg)
2103- << RD->getNameAsString () << Base.getType ().getAsString ();
2104- IsInvalid = true ;
2105- } else if (BaseDecl->getNumBases () > 0 )
2106- handleStructType (PD, BaseType);
2107- }
2108- }
2109- }
21102113 // For free functions all struct/class kernel arguments are forward declared
21112114 // in integration header, that adds additional restrictions for kernel
21122115 // arguments.
@@ -2121,6 +2124,9 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
21212124 << ParamTy;
21222125 IsInvalid = true ;
21232126 }
2127+ // Free functions do not support for virtual inheritance.
2128+ if (hasVirtualInheritance (RD, PD))
2129+ IsInvalid = true ;
21242130 return isValid ();
21252131 }
21262132
0 commit comments