Coverage Report

Created: 2020-02-15 09:57

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/DeclOpenMP.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
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
/// \file
9
/// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
10
/// classes.
11
///
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/AST/ASTContext.h"
15
#include "clang/AST/Decl.h"
16
#include "clang/AST/DeclBase.h"
17
#include "clang/AST/DeclOpenMP.h"
18
#include "clang/AST/Expr.h"
19
20
using namespace clang;
21
22
//===----------------------------------------------------------------------===//
23
// OMPThreadPrivateDecl Implementation.
24
//===----------------------------------------------------------------------===//
25
26
0
void OMPThreadPrivateDecl::anchor() { }
27
28
OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
29
                                                   DeclContext *DC,
30
                                                   SourceLocation L,
31
2.07k
                                                   ArrayRef<Expr *> VL) {
32
2.07k
  OMPThreadPrivateDecl *D =
33
2.07k
      new (C, DC, additionalSizeToAlloc<Expr *>(VL.size()))
34
2.07k
          OMPThreadPrivateDecl(OMPThreadPrivate, DC, L);
35
2.07k
  D->NumVars = VL.size();
36
2.07k
  D->setVars(VL);
37
2.07k
  return D;
38
2.07k
}
39
40
OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
41
                                                               unsigned ID,
42
221
                                                               unsigned N) {
43
221
  OMPThreadPrivateDecl *D = new (C, ID, additionalSizeToAlloc<Expr *>(N))
44
221
      OMPThreadPrivateDecl(OMPThreadPrivate, nullptr, SourceLocation());
45
221
  D->NumVars = N;
46
221
  return D;
47
221
}
48
49
2.29k
void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
50
2.29k
  assert(VL.size() == NumVars &&
51
2.29k
         "Number of variables is not the same as the preallocated buffer");
52
2.29k
  std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
53
2.29k
}
54
55
//===----------------------------------------------------------------------===//
56
// OMPAllocateDecl Implementation.
57
//===----------------------------------------------------------------------===//
58
59
0
void OMPAllocateDecl::anchor() { }
60
61
OMPAllocateDecl *OMPAllocateDecl::Create(ASTContext &C, DeclContext *DC,
62
                                         SourceLocation L, ArrayRef<Expr *> VL,
63
486
                                         ArrayRef<OMPClause *> CL) {
64
486
  OMPAllocateDecl *D = new (
65
486
      C, DC, additionalSizeToAlloc<Expr *, OMPClause *>(VL.size(), CL.size()))
66
486
      OMPAllocateDecl(OMPAllocate, DC, L);
67
486
  D->NumVars = VL.size();
68
486
  D->setVars(VL);
69
486
  D->NumClauses = CL.size();
70
486
  D->setClauses(CL);
71
486
  return D;
72
486
}
73
74
OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C, unsigned ID,
75
                                                     unsigned NVars,
76
119
                                                     unsigned NClauses) {
77
119
  OMPAllocateDecl *D =
78
119
      new (C, ID, additionalSizeToAlloc<Expr *, OMPClause *>(NVars, NClauses))
79
119
          OMPAllocateDecl(OMPAllocate, nullptr, SourceLocation());
80
119
  D->NumVars = NVars;
81
119
  D->NumClauses = NClauses;
82
119
  return D;
83
119
}
84
85
605
void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {
86
605
  assert(VL.size() == NumVars &&
87
605
         "Number of variables is not the same as the preallocated buffer");
88
605
  std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
89
605
}
90
91
605
void OMPAllocateDecl::setClauses(ArrayRef<OMPClause *> CL) {
92
605
  assert(CL.size() == NumClauses &&
93
605
         "Number of variables is not the same as the preallocated buffer");
94
605
  std::uninitialized_copy(CL.begin(), CL.end(),
95
605
                          getTrailingObjects<OMPClause *>());
96
605
}
97
98
//===----------------------------------------------------------------------===//
99
// OMPRequiresDecl Implementation.
100
//===----------------------------------------------------------------------===//
101
102
0
void OMPRequiresDecl::anchor() {}
103
104
OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
105
                                         SourceLocation L,
106
71
                                         ArrayRef<OMPClause *> CL) {
107
71
  OMPRequiresDecl *D =
108
71
      new (C, DC, additionalSizeToAlloc<OMPClause *>(CL.size()))
109
71
      OMPRequiresDecl(OMPRequires, DC, L);
110
71
  D->NumClauses = CL.size();
111
71
  D->setClauses(CL);
112
71
  return D;
113
71
}
114
115
OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, unsigned ID,
116
20
                                                     unsigned N) {
117
20
  OMPRequiresDecl *D = new (C, ID, additionalSizeToAlloc<OMPClause *>(N))
118
20
      OMPRequiresDecl(OMPRequires, nullptr, SourceLocation());
119
20
  D->NumClauses = N;
120
20
  return D;
121
20
}
122
123
91
void OMPRequiresDecl::setClauses(ArrayRef<OMPClause *> CL) {
124
91
  assert(CL.size() == NumClauses &&
125
91
         "Number of clauses is not the same as the preallocated buffer");
126
91
  std::uninitialized_copy(CL.begin(), CL.end(),
127
91
                          getTrailingObjects<OMPClause *>());
128
91
}
129
130
//===----------------------------------------------------------------------===//
131
// OMPDeclareReductionDecl Implementation.
132
//===----------------------------------------------------------------------===//
133
134
OMPDeclareReductionDecl::OMPDeclareReductionDecl(
135
    Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
136
    QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
137
    : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
138
822
      PrevDeclInScope(PrevDeclInScope) {
139
822
  setInitializer(nullptr, CallInit);
140
822
}
141
142
0
void OMPDeclareReductionDecl::anchor() {}
143
144
OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
145
    ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
146
710
    QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
147
710
  return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
148
710
                                             T, PrevDeclInScope);
149
710
}
150
151
OMPDeclareReductionDecl *
152
112
OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
153
112
  return new (C, ID) OMPDeclareReductionDecl(
154
112
      OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
155
112
      QualType(), /*PrevDeclInScope=*/nullptr);
156
112
}
157
158
302
OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
159
302
  return cast_or_null<OMPDeclareReductionDecl>(
160
302
      PrevDeclInScope.get(getASTContext().getExternalSource()));
161
302
}
162
const OMPDeclareReductionDecl *
163
0
OMPDeclareReductionDecl::getPrevDeclInScope() const {
164
0
  return cast_or_null<OMPDeclareReductionDecl>(
165
0
      PrevDeclInScope.get(getASTContext().getExternalSource()));
166
0
}
167
168
//===----------------------------------------------------------------------===//
169
// OMPDeclareMapperDecl Implementation.
170
//===----------------------------------------------------------------------===//
171
172
0
void OMPDeclareMapperDecl::anchor() {}
173
174
OMPDeclareMapperDecl *
175
OMPDeclareMapperDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
176
                             DeclarationName Name, QualType T,
177
                             DeclarationName VarName,
178
238
                             OMPDeclareMapperDecl *PrevDeclInScope) {
179
238
  return new (C, DC) OMPDeclareMapperDecl(OMPDeclareMapper, DC, L, Name, T,
180
238
                                          VarName, PrevDeclInScope);
181
238
}
182
183
OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C,
184
                                                               unsigned ID,
185
46
                                                               unsigned N) {
186
46
  auto *D = new (C, ID)
187
46
      OMPDeclareMapperDecl(OMPDeclareMapper, /*DC=*/nullptr, SourceLocation(),
188
46
                           DeclarationName(), QualType(), DeclarationName(),
189
46
                           /*PrevDeclInScope=*/nullptr);
190
46
  if (N) {
191
46
    auto **ClauseStorage = C.Allocate<OMPClause *>(N);
192
46
    D->Clauses = llvm::makeMutableArrayRef<OMPClause *>(ClauseStorage, N);
193
46
  }
194
46
  return D;
195
46
}
196
197
/// Creates an array of clauses to this mapper declaration and intializes
198
/// them. The space used to store clause pointers is dynamically allocated,
199
/// because we do not know the number of clauses when creating
200
/// OMPDeclareMapperDecl
201
void OMPDeclareMapperDecl::CreateClauses(ASTContext &C,
202
238
                                         ArrayRef<OMPClause *> CL) {
203
238
  assert(Clauses.empty() && "Number of clauses should be 0 on initialization");
204
238
  size_t NumClauses = CL.size();
205
238
  if (NumClauses) {
206
222
    auto **ClauseStorage = C.Allocate<OMPClause *>(NumClauses);
207
222
    Clauses = llvm::makeMutableArrayRef<OMPClause *>(ClauseStorage, NumClauses);
208
222
    setClauses(CL);
209
222
  }
210
238
}
211
212
268
void OMPDeclareMapperDecl::setClauses(ArrayRef<OMPClause *> CL) {
213
268
  assert(CL.size() == Clauses.size() &&
214
268
         "Number of clauses is not the same as the preallocated buffer");
215
268
  std::uninitialized_copy(CL.begin(), CL.end(), Clauses.data());
216
268
}
217
218
98
OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() {
219
98
  return cast_or_null<OMPDeclareMapperDecl>(
220
98
      PrevDeclInScope.get(getASTContext().getExternalSource()));
221
98
}
222
223
0
const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const {
224
0
  return cast_or_null<OMPDeclareMapperDecl>(
225
0
      PrevDeclInScope.get(getASTContext().getExternalSource()));
226
0
}
227
228
//===----------------------------------------------------------------------===//
229
// OMPCapturedExprDecl Implementation.
230
//===----------------------------------------------------------------------===//
231
232
0
void OMPCapturedExprDecl::anchor() {}
233
234
OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
235
                                                 IdentifierInfo *Id, QualType T,
236
53.2k
                                                 SourceLocation StartLoc) {
237
53.2k
  return new (C, DC) OMPCapturedExprDecl(
238
53.2k
      C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
239
53.2k
}
240
241
OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
242
3.48k
                                                             unsigned ID) {
243
3.48k
  return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
244
3.48k
                                         /*TInfo=*/nullptr, SourceLocation());
245
3.48k
}
246
247
96
SourceRange OMPCapturedExprDecl::getSourceRange() const {
248
96
  assert(hasInit());
249
96
  return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
250
96
}