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