xref: /freebsd/contrib/llvm-project/clang/lib/Sema/SemaSYCL.cpp (revision 6be3386466ab79a84b48429ae66244f21526d3df)
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::DeviceDiagBuilder 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   DeviceDiagBuilder::Kind DiagKind = [this, FD] {
26     if (!FD)
27       return DeviceDiagBuilder::K_Nop;
28     if (getEmissionStatus(FD) == Sema::FunctionEmissionStatus::Emitted)
29       return DeviceDiagBuilder::K_ImmediateWithCallStack;
30     return DeviceDiagBuilder::K_Deferred;
31   }();
32   return DeviceDiagBuilder(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   DeviceDiagBuilder::Kind DiagKind = DeviceDiagBuilder::K_Nop;
46 
47   return DiagKind != DeviceDiagBuilder::K_Immediate &&
48          DiagKind != DeviceDiagBuilder::K_ImmediateWithCallStack;
49 }
50