@@ -395,27 +395,9 @@ static void collectSYCLAttributes(Sema &S, FunctionDecl *FD,
395
395
}
396
396
397
397
class DiagDeviceFunction : public RecursiveASTVisitor <DiagDeviceFunction> {
398
- // Used to keep track of the constexpr depth, so we know whether to skip
399
- // diagnostics.
400
- unsigned ConstexprDepth = 0 ;
401
398
Sema &SemaRef;
402
399
const llvm::SmallPtrSetImpl<const FunctionDecl *> &RecursiveFuncs;
403
400
404
- struct ConstexprDepthRAII {
405
- DiagDeviceFunction &DDF;
406
- bool Increment;
407
-
408
- ConstexprDepthRAII (DiagDeviceFunction &DDF, bool Increment = true )
409
- : DDF(DDF), Increment(Increment) {
410
- if (Increment)
411
- ++DDF.ConstexprDepth ;
412
- }
413
- ~ConstexprDepthRAII () {
414
- if (Increment)
415
- --DDF.ConstexprDepth ;
416
- }
417
- };
418
-
419
401
public:
420
402
DiagDeviceFunction (
421
403
Sema &S,
@@ -433,7 +415,7 @@ class DiagDeviceFunction : public RecursiveASTVisitor<DiagDeviceFunction> {
433
415
// instantiation as template functions. It means that
434
416
// all functions used by kernel have already been parsed and have
435
417
// definitions.
436
- if (RecursiveFuncs.count (Callee) && !ConstexprDepth ) {
418
+ if (RecursiveFuncs.count (Callee)) {
437
419
SemaRef.Diag (e->getExprLoc (), diag::err_sycl_restrict)
438
420
<< Sema::KernelCallRecursiveFunction;
439
421
SemaRef.Diag (Callee->getSourceRange ().getBegin (),
@@ -486,45 +468,41 @@ class DiagDeviceFunction : public RecursiveASTVisitor<DiagDeviceFunction> {
486
468
487
469
// Skip checking rules on variables initialized during constant evaluation.
488
470
bool TraverseVarDecl (VarDecl *VD) {
489
- ConstexprDepthRAII R (*this , VD->isConstexpr ());
471
+ if (VD->isConstexpr ())
472
+ return true ;
490
473
return RecursiveASTVisitor::TraverseVarDecl (VD);
491
474
}
492
475
493
476
// Skip checking rules on template arguments, since these are constant
494
477
// expressions.
495
478
bool TraverseTemplateArgumentLoc (const TemplateArgumentLoc &ArgLoc) {
496
- ConstexprDepthRAII R (*this );
497
- return RecursiveASTVisitor::TraverseTemplateArgumentLoc (ArgLoc);
479
+ return true ;
498
480
}
499
481
500
482
// Skip checking the static assert, both components are required to be
501
483
// constant expressions.
502
- bool TraverseStaticAssertDecl (StaticAssertDecl *D) {
503
- ConstexprDepthRAII R (*this );
504
- return RecursiveASTVisitor::TraverseStaticAssertDecl (D);
505
- }
484
+ bool TraverseStaticAssertDecl (StaticAssertDecl *D) { return true ; }
506
485
507
486
// Make sure we skip the condition of the case, since that is a constant
508
487
// expression.
509
488
bool TraverseCaseStmt (CaseStmt *S) {
510
- {
511
- ConstexprDepthRAII R (*this );
512
- if (!TraverseStmt (S->getLHS ()))
513
- return false ;
514
- if (!TraverseStmt (S->getRHS ()))
515
- return false ;
516
- }
517
489
return TraverseStmt (S->getSubStmt ());
518
490
}
519
491
520
492
// Skip checking the size expr, since a constant array type loc's size expr is
521
493
// a constant expression.
522
494
bool TraverseConstantArrayTypeLoc (const ConstantArrayTypeLoc &ArrLoc) {
523
- if (! TraverseTypeLoc (ArrLoc. getElementLoc ()))
524
- return false ;
495
+ return true ;
496
+ }
525
497
526
- ConstexprDepthRAII R (*this );
527
- return TraverseStmt (ArrLoc.getSizeExpr ());
498
+ bool TraverseIfStmt (IfStmt *S) {
499
+ if (llvm::Optional<Stmt *> ActiveStmt =
500
+ S->getNondiscardedCase (SemaRef.Context )) {
501
+ if (*ActiveStmt)
502
+ return TraverseStmt (*ActiveStmt);
503
+ return true ;
504
+ }
505
+ return RecursiveASTVisitor::TraverseIfStmt (S);
528
506
}
529
507
};
530
508
0 commit comments