@@ -236,6 +236,10 @@ static void checkSYCLVarType(Sema &S, QualType Ty, SourceRange Loc,
236
236
emitDeferredDiagnosticAndNote (S, Loc, diag::err_typecheck_zero_array_size,
237
237
UsedAtLoc);
238
238
239
+ // variable length arrays
240
+ if (Ty->isVariableArrayType ())
241
+ emitDeferredDiagnosticAndNote (S, Loc, diag::err_vla_unsupported, UsedAtLoc);
242
+
239
243
// Sub-reference array or pointer, then proceed with that type.
240
244
while (Ty->isAnyPointerType () || Ty->isArrayType ())
241
245
Ty = QualType{Ty->getPointeeOrArrayElementType (), 0 };
@@ -284,9 +288,6 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
284
288
: RecursiveASTVisitor<MarkDeviceFunction>(), SemaRef(S) {}
285
289
286
290
bool VisitCallExpr (CallExpr *e) {
287
- for (const auto &Arg : e->arguments ())
288
- CheckSYCLType (Arg->getType (), Arg->getSourceRange ());
289
-
290
291
if (FunctionDecl *Callee = e->getDirectCallee ()) {
291
292
Callee = Callee->getCanonicalDecl ();
292
293
assert (Callee && " Device function canonical decl must be available" );
@@ -308,8 +309,6 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
308
309
SemaRef.Diag (e->getExprLoc (), diag::err_sycl_restrict)
309
310
<< Sema::KernelCallVirtualFunction;
310
311
311
- CheckSYCLType (Callee->getReturnType (), Callee->getSourceRange ());
312
-
313
312
if (auto const *FD = dyn_cast<FunctionDecl>(Callee)) {
314
313
// FIXME: We need check all target specified attributes for error if
315
314
// that function with attribute can not be called from sycl kernel. The
@@ -338,12 +337,6 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
338
337
return true ;
339
338
}
340
339
341
- bool VisitCXXConstructExpr (CXXConstructExpr *E) {
342
- for (const auto &Arg : E->arguments ())
343
- CheckSYCLType (Arg->getType (), Arg->getSourceRange ());
344
- return true ;
345
- }
346
-
347
340
bool VisitCXXTypeidExpr (CXXTypeidExpr *E) {
348
341
SemaRef.Diag (E->getExprLoc (), diag::err_sycl_restrict) << Sema::KernelRTTI;
349
342
return true ;
@@ -354,35 +347,6 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
354
347
return true ;
355
348
}
356
349
357
- bool VisitTypedefNameDecl (TypedefNameDecl *TD) {
358
- CheckSYCLType (TD->getUnderlyingType (), TD->getLocation ());
359
- return true ;
360
- }
361
-
362
- bool VisitRecordDecl (RecordDecl *RD) {
363
- CheckSYCLType (QualType{RD->getTypeForDecl (), 0 }, RD->getLocation ());
364
- return true ;
365
- }
366
-
367
- bool VisitParmVarDecl (VarDecl *VD) {
368
- CheckSYCLType (VD->getType (), VD->getLocation ());
369
- return true ;
370
- }
371
-
372
- bool VisitVarDecl (VarDecl *VD) {
373
- CheckSYCLType (VD->getType (), VD->getLocation ());
374
- return true ;
375
- }
376
-
377
- bool VisitDeclRefExpr (DeclRefExpr *E) {
378
- Decl *D = E->getDecl ();
379
- if (SemaRef.isKnownGoodSYCLDecl (D))
380
- return true ;
381
-
382
- CheckSYCLType (E->getType (), E->getSourceRange ());
383
- return true ;
384
- }
385
-
386
350
// The call graph for this translation unit.
387
351
CallGraph SYCLCG;
388
352
// The set of functions called by a kernel function.
@@ -506,64 +470,6 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
506
470
}
507
471
508
472
private:
509
- bool CheckSYCLType (QualType Ty, SourceRange Loc) {
510
- llvm::DenseSet<QualType> visited;
511
- return CheckSYCLType (Ty, Loc, visited);
512
- }
513
-
514
- bool CheckSYCLType (QualType Ty, SourceRange Loc,
515
- llvm::DenseSet<QualType> &Visited) {
516
- if (Ty->isVariableArrayType ()) {
517
- SemaRef.Diag (Loc.getBegin (), diag::err_vla_unsupported);
518
- return false ;
519
- }
520
-
521
- while (Ty->isAnyPointerType () || Ty->isArrayType ())
522
- Ty = QualType{Ty->getPointeeOrArrayElementType (), 0 };
523
-
524
- // Pointers complicate recursion. Add this type to Visited.
525
- // If already there, bail out.
526
- if (!Visited.insert (Ty).second )
527
- return true ;
528
-
529
- if (const auto *ATy = dyn_cast<AttributedType>(Ty))
530
- return CheckSYCLType (ATy->getModifiedType (), Loc, Visited);
531
-
532
- if (const auto *CRD = Ty->getAsCXXRecordDecl ()) {
533
- // If the class is a forward declaration - skip it, because otherwise we
534
- // would query property of class with no definition, which results in
535
- // clang crash.
536
- if (!CRD->hasDefinition ())
537
- return true ;
538
-
539
- for (const auto &Field : CRD->fields ()) {
540
- if (!CheckSYCLType (Field->getType (), Field->getSourceRange (),
541
- Visited)) {
542
- if (SemaRef.getLangOpts ().SYCLIsDevice )
543
- SemaRef.Diag (Loc.getBegin (), diag::note_sycl_used_here);
544
- return false ;
545
- }
546
- }
547
- } else if (const auto *RD = Ty->getAsRecordDecl ()) {
548
- for (const auto &Field : RD->fields ()) {
549
- if (!CheckSYCLType (Field->getType (), Field->getSourceRange (),
550
- Visited)) {
551
- if (SemaRef.getLangOpts ().SYCLIsDevice )
552
- SemaRef.Diag (Loc.getBegin (), diag::note_sycl_used_here);
553
- return false ;
554
- }
555
- }
556
- } else if (const auto *FPTy = dyn_cast<FunctionProtoType>(Ty)) {
557
- for (const auto &ParamTy : FPTy->param_types ())
558
- if (!CheckSYCLType (ParamTy, Loc, Visited))
559
- return false ;
560
- return CheckSYCLType (FPTy->getReturnType (), Loc, Visited);
561
- } else if (const auto *FTy = dyn_cast<FunctionType>(Ty)) {
562
- return CheckSYCLType (FTy->getReturnType (), Loc, Visited);
563
- }
564
- return true ;
565
- }
566
-
567
473
Sema &SemaRef;
568
474
};
569
475
0 commit comments