Coverage Report

Created: 2021-08-24 07:12

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Sema/SemaSYCL.cpp
Line
Count
Source (jump to first uncovered line)
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
102
                                                       unsigned DiagID) {
23
102
  assert(getLangOpts().SYCLIsDevice &&
24
102
         "Should only be called during SYCL compilation");
25
0
  FunctionDecl *FD = dyn_cast<FunctionDecl>(getCurLexicalContext());
26
102
  SemaDiagnosticBuilder::Kind DiagKind = [this, FD] {
27
102
    if (!FD)
28
24
      return SemaDiagnosticBuilder::K_Nop;
29
78
    if (getEmissionStatus(FD) == Sema::FunctionEmissionStatus::Emitted)
30
0
      return SemaDiagnosticBuilder::K_ImmediateWithCallStack;
31
78
    return SemaDiagnosticBuilder::K_Deferred;
32
78
  }();
33
102
  return SemaDiagnosticBuilder(DiagKind, Loc, DiagID, FD, *this);
34
102
}
35
36
866
bool Sema::checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee) {
37
866
  assert(getLangOpts().SYCLIsDevice &&
38
866
         "Should only be called during SYCL compilation");
39
0
  assert(Callee && "Callee may not be null.");
40
41
  // Errors in unevaluated context don't need to be generated,
42
  // so we can safely skip them.
43
866
  if (isUnevaluatedContext() || 
isConstantEvaluated()863
)
44
5
    return true;
45
46
861
  SemaDiagnosticBuilder::Kind DiagKind = SemaDiagnosticBuilder::K_Nop;
47
48
861
  return DiagKind != SemaDiagnosticBuilder::K_Immediate &&
49
861
         DiagKind != SemaDiagnosticBuilder::K_ImmediateWithCallStack;
50
866
}
51
52
// The SYCL kernel's 'object type' used for diagnostics and naming/mangling is
53
// the first parameter to a sycl_kernel labeled function template. In SYCL1.2.1,
54
// this was passed by value, and in SYCL2020, it is passed by reference.
55
46
static QualType GetSYCLKernelObjectType(const FunctionDecl *KernelCaller) {
56
46
  assert(KernelCaller->getNumParams() > 0 && "Insufficient kernel parameters");
57
0
  QualType KernelParamTy = KernelCaller->getParamDecl(0)->getType();
58
59
  // SYCL 2020 kernels are passed by reference.
60
46
  if (KernelParamTy->isReferenceType())
61
1
    return KernelParamTy->getPointeeType();
62
63
  // SYCL 1.2.1
64
45
  return KernelParamTy;
65
46
}
66
67
46
void Sema::AddSYCLKernelLambda(const FunctionDecl *FD) {
68
46
  auto MangleCallback = [](ASTContext &Ctx,
69
52
                           const NamedDecl *ND) -> llvm::Optional<unsigned> {
70
52
    if (const auto *RD = dyn_cast<CXXRecordDecl>(ND))
71
52
      Ctx.AddSYCLKernelNamingDecl(RD);
72
    // We always want to go into the lambda mangling (skipping the unnamed
73
    // struct version), so make sure we return a value here.
74
52
    return 1;
75
52
  };
76
77
46
  QualType Ty = GetSYCLKernelObjectType(FD);
78
46
  std::unique_ptr<MangleContext> Ctx{ItaniumMangleContext::create(
79
46
      Context, Context.getDiagnostics(), MangleCallback)};
80
46
  llvm::raw_null_ostream Out;
81
46
  Ctx->mangleTypeName(Ty, Out);
82
46
}