1 //===- SemaSYCL.cpp - Semantic Analysis for SYCL constructs ---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 // This implements Semantic Analysis for SYCL constructs.
9 //===----------------------------------------------------------------------===//
10 
11 #include "clang/Sema/Sema.h"
12 #include "clang/Sema/SemaDiagnostic.h"
13 
14 using namespace clang;
15 
16 // -----------------------------------------------------------------------------
17 // SYCL device specific diagnostics implementation
18 // -----------------------------------------------------------------------------
19 
20 Sema::SemaDiagnosticBuilder Sema::SYCLDiagIfDeviceCode(SourceLocation Loc,
21                                                        unsigned DiagID) {
22   assert(getLangOpts().SYCLIsDevice &&
23          "Should only be called during SYCL compilation");
24   FunctionDecl *FD = dyn_cast<FunctionDecl>(getCurLexicalContext());
25   SemaDiagnosticBuilder::Kind DiagKind = [this, FD] {
26     if (!FD)
27       return SemaDiagnosticBuilder::K_Nop;
28     if (getEmissionStatus(FD) == Sema::FunctionEmissionStatus::Emitted)
29       return SemaDiagnosticBuilder::K_ImmediateWithCallStack;
30     return SemaDiagnosticBuilder::K_Deferred;
31   }();
32   return SemaDiagnosticBuilder(DiagKind, Loc, DiagID, FD, *this);
33 }
34 
35 bool Sema::checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee) {
36   assert(getLangOpts().SYCLIsDevice &&
37          "Should only be called during SYCL compilation");
38   assert(Callee && "Callee may not be null.");
39 
40   // Errors in unevaluated context don't need to be generated,
41   // so we can safely skip them.
42   if (isUnevaluatedContext() || isConstantEvaluated())
43     return true;
44 
45   SemaDiagnosticBuilder::Kind DiagKind = SemaDiagnosticBuilder::K_Nop;
46 
47   return DiagKind != SemaDiagnosticBuilder::K_Immediate &&
48          DiagKind != SemaDiagnosticBuilder::K_ImmediateWithCallStack;
49 }
50