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" 13 #include "clang/Sema/SemaDiagnostic.h" 14 15 using namespace clang; 16 17 // ----------------------------------------------------------------------------- 18 // SYCL device specific diagnostics implementation 19 // ----------------------------------------------------------------------------- 20 21 Sema::SemaDiagnosticBuilder Sema::SYCLDiagIfDeviceCode(SourceLocation Loc, 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) 28 return SemaDiagnosticBuilder::K_Nop; 29 if (getEmissionStatus(FD) == Sema::FunctionEmissionStatus::Emitted) 30 return SemaDiagnosticBuilder::K_ImmediateWithCallStack; 31 return SemaDiagnosticBuilder::K_Deferred; 32 }(); 33 return SemaDiagnosticBuilder(DiagKind, Loc, DiagID, FD, *this); 34 } 35 36 bool Sema::checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee) { 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. 43 if (isUnevaluatedContext() || isConstantEvaluated()) 44 return true; 45 46 SemaDiagnosticBuilder::Kind DiagKind = SemaDiagnosticBuilder::K_Nop; 47 48 return DiagKind != SemaDiagnosticBuilder::K_Immediate && 49 DiagKind != SemaDiagnosticBuilder::K_ImmediateWithCallStack; 50 } 51