clang  14.0.0git
SemaSYCL.cpp
Go to the documentation of this file.
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/AST/Mangle.h"
12 #include "clang/Sema/Sema.h"
14 
15 using namespace clang;
16 
17 // -----------------------------------------------------------------------------
18 // SYCL device specific diagnostics implementation
19 // -----------------------------------------------------------------------------
20 
22  unsigned DiagID) {
23  assert(getLangOpts().SYCLIsDevice &&
24  "Should only be called during SYCL compilation");
25  FunctionDecl *FD = dyn_cast<FunctionDecl>(getCurLexicalContext());
26  SemaDiagnosticBuilder::Kind DiagKind = [this, FD] {
27  if (!FD)
32  }();
33  return SemaDiagnosticBuilder(DiagKind, Loc, DiagID, FD, *this);
34 }
35 
37  assert(getLangOpts().SYCLIsDevice &&
38  "Should only be called during SYCL compilation");
39  assert(Callee && "Callee may not be null.");
40 
41  // Errors in an unevaluated context don't need to be generated,
42  // so we can safely skip them.
44  return true;
45 
47 
48  return DiagKind != SemaDiagnosticBuilder::K_Immediate &&
50 }
clang::Sema::SemaDiagnosticBuilder::Kind
Kind
Definition: Sema.h:1684
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::Sema::isUnevaluatedContext
bool isUnevaluatedContext() const
Determines whether we are currently in a context that is not evaluated as per C++ [expr] p5.
Definition: Sema.h:9129
clang::Sema::getLangOpts
const LangOptions & getLangOpts() const
Definition: Sema.h:1569
clang::Sema::getCurLexicalContext
DeclContext * getCurLexicalContext() const
Definition: Sema.h:12915
clang::Sema::SemaDiagnosticBuilder::K_Nop
@ K_Nop
Emit no diagnostics.
Definition: Sema.h:1686
clang::Sema::SemaDiagnosticBuilder::K_Immediate
@ K_Immediate
Emit the diagnostic immediately (i.e., behave like Sema::Diag()).
Definition: Sema.h:1688
Sema.h
clang::Sema::SemaDiagnosticBuilder::K_Deferred
@ K_Deferred
Create a deferred diagnostic, which is emitted only if the function it's attached to is codegen'ed.
Definition: Sema.h:1696
clang::Sema::SYCLDiagIfDeviceCode
SemaDiagnosticBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, unsigned DiagID)
Creates a SemaDiagnosticBuilder that emits the diagnostic if the current context is "used as device c...
Definition: SemaSYCL.cpp:21
SemaDiagnostic.h
clang::Sema::SemaDiagnosticBuilder::K_ImmediateWithCallStack
@ K_ImmediateWithCallStack
Emit the diagnostic immediately, and, if it's a warning or error, also emit a call stack showing how ...
Definition: Sema.h:1692
clang::Sema::isConstantEvaluated
bool isConstantEvaluated()
Definition: Sema.h:1030
clang::Sema::SemaDiagnosticBuilder
A generic diagnostic builder for errors which may or may not be deferred.
Definition: Sema.h:1682
clang::Sema::getEmissionStatus
FunctionEmissionStatus getEmissionStatus(FunctionDecl *Decl, bool Final=false)
Definition: SemaDecl.cpp:18557
clang::Sema::FunctionEmissionStatus::Emitted
@ Emitted
clang
Definition: CalledOnceCheck.h:17
Mangle.h
clang::Sema::checkSYCLDeviceFunction
bool checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee)
Check whether we're allowed to call Callee from the current context.
Definition: SemaSYCL.cpp:36
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1856