Bug Summary

File:build-llvm/tools/clang/include/clang/AST/Attrs.inc
Warning:line 4112, column 5
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name SemaTemplateInstantiate.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-9/lib/clang/9.0.0 -D CLANG_VENDOR="Debian " -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/lib/Sema -I /build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema -I /build/llvm-toolchain-snapshot-9~svn362543/tools/clang/include -I /build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-9~svn362543/build-llvm/include -I /build/llvm-toolchain-snapshot-9~svn362543/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/9.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-9/lib/clang/9.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/lib/Sema -fdebug-prefix-map=/build/llvm-toolchain-snapshot-9~svn362543=. -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -stack-protector 2 -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2019-06-05-060531-1271-1 -x c++ /build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp -faddrsig

/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp

1//===------- SemaTemplateInstantiate.cpp - C++ Template Instantiation ------===/
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 file implements C++ template instantiation.
9//
10//===----------------------------------------------------------------------===/
11
12#include "clang/Sema/SemaInternal.h"
13#include "TreeTransform.h"
14#include "clang/AST/ASTConsumer.h"
15#include "clang/AST/ASTContext.h"
16#include "clang/AST/ASTLambda.h"
17#include "clang/AST/ASTMutationListener.h"
18#include "clang/AST/DeclTemplate.h"
19#include "clang/AST/Expr.h"
20#include "clang/AST/PrettyDeclStackTrace.h"
21#include "clang/Basic/LangOptions.h"
22#include "clang/Sema/DeclSpec.h"
23#include "clang/Sema/Initialization.h"
24#include "clang/Sema/Lookup.h"
25#include "clang/Sema/Template.h"
26#include "clang/Sema/TemplateDeduction.h"
27#include "clang/Sema/TemplateInstCallback.h"
28#include "llvm/Support/TimeProfiler.h"
29
30using namespace clang;
31using namespace sema;
32
33//===----------------------------------------------------------------------===/
34// Template Instantiation Support
35//===----------------------------------------------------------------------===/
36
37/// Retrieve the template argument list(s) that should be used to
38/// instantiate the definition of the given declaration.
39///
40/// \param D the declaration for which we are computing template instantiation
41/// arguments.
42///
43/// \param Innermost if non-NULL, the innermost template argument list.
44///
45/// \param RelativeToPrimary true if we should get the template
46/// arguments relative to the primary template, even when we're
47/// dealing with a specialization. This is only relevant for function
48/// template specializations.
49///
50/// \param Pattern If non-NULL, indicates the pattern from which we will be
51/// instantiating the definition of the given declaration, \p D. This is
52/// used to determine the proper set of template instantiation arguments for
53/// friend function template specializations.
54MultiLevelTemplateArgumentList
55Sema::getTemplateInstantiationArgs(NamedDecl *D,
56 const TemplateArgumentList *Innermost,
57 bool RelativeToPrimary,
58 const FunctionDecl *Pattern) {
59 // Accumulate the set of template argument lists in this structure.
60 MultiLevelTemplateArgumentList Result;
61
62 if (Innermost)
63 Result.addOuterTemplateArguments(Innermost);
64
65 DeclContext *Ctx = dyn_cast<DeclContext>(D);
66 if (!Ctx) {
67 Ctx = D->getDeclContext();
68
69 // Add template arguments from a variable template instantiation. For a
70 // class-scope explicit specialization, there are no template arguments
71 // at this level, but there may be enclosing template arguments.
72 VarTemplateSpecializationDecl *Spec =
73 dyn_cast<VarTemplateSpecializationDecl>(D);
74 if (Spec && !Spec->isClassScopeExplicitSpecialization()) {
75 // We're done when we hit an explicit specialization.
76 if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization &&
77 !isa<VarTemplatePartialSpecializationDecl>(Spec))
78 return Result;
79
80 Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs());
81
82 // If this variable template specialization was instantiated from a
83 // specialized member that is a variable template, we're done.
84 assert(Spec->getSpecializedTemplate() && "No variable template?")((Spec->getSpecializedTemplate() && "No variable template?"
) ? static_cast<void> (0) : __assert_fail ("Spec->getSpecializedTemplate() && \"No variable template?\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 84, __PRETTY_FUNCTION__))
;
85 llvm::PointerUnion<VarTemplateDecl*,
86 VarTemplatePartialSpecializationDecl*> Specialized
87 = Spec->getSpecializedTemplateOrPartial();
88 if (VarTemplatePartialSpecializationDecl *Partial =
89 Specialized.dyn_cast<VarTemplatePartialSpecializationDecl *>()) {
90 if (Partial->isMemberSpecialization())
91 return Result;
92 } else {
93 VarTemplateDecl *Tmpl = Specialized.get<VarTemplateDecl *>();
94 if (Tmpl->isMemberSpecialization())
95 return Result;
96 }
97 }
98
99 // If we have a template template parameter with translation unit context,
100 // then we're performing substitution into a default template argument of
101 // this template template parameter before we've constructed the template
102 // that will own this template template parameter. In this case, we
103 // use empty template parameter lists for all of the outer templates
104 // to avoid performing any substitutions.
105 if (Ctx->isTranslationUnit()) {
106 if (TemplateTemplateParmDecl *TTP
107 = dyn_cast<TemplateTemplateParmDecl>(D)) {
108 for (unsigned I = 0, N = TTP->getDepth() + 1; I != N; ++I)
109 Result.addOuterTemplateArguments(None);
110 return Result;
111 }
112 }
113 }
114
115 while (!Ctx->isFileContext()) {
116 // Add template arguments from a class template instantiation.
117 ClassTemplateSpecializationDecl *Spec
118 = dyn_cast<ClassTemplateSpecializationDecl>(Ctx);
119 if (Spec && !Spec->isClassScopeExplicitSpecialization()) {
120 // We're done when we hit an explicit specialization.
121 if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization &&
122 !isa<ClassTemplatePartialSpecializationDecl>(Spec))
123 break;
124
125 Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs());
126
127 // If this class template specialization was instantiated from a
128 // specialized member that is a class template, we're done.
129 assert(Spec->getSpecializedTemplate() && "No class template?")((Spec->getSpecializedTemplate() && "No class template?"
) ? static_cast<void> (0) : __assert_fail ("Spec->getSpecializedTemplate() && \"No class template?\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 129, __PRETTY_FUNCTION__))
;
130 if (Spec->getSpecializedTemplate()->isMemberSpecialization())
131 break;
132 }
133 // Add template arguments from a function template specialization.
134 else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) {
135 if (!RelativeToPrimary &&
136 Function->getTemplateSpecializationKindForInstantiation() ==
137 TSK_ExplicitSpecialization)
138 break;
139
140 if (const TemplateArgumentList *TemplateArgs
141 = Function->getTemplateSpecializationArgs()) {
142 // Add the template arguments for this specialization.
143 Result.addOuterTemplateArguments(TemplateArgs);
144
145 // If this function was instantiated from a specialized member that is
146 // a function template, we're done.
147 assert(Function->getPrimaryTemplate() && "No function template?")((Function->getPrimaryTemplate() && "No function template?"
) ? static_cast<void> (0) : __assert_fail ("Function->getPrimaryTemplate() && \"No function template?\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 147, __PRETTY_FUNCTION__))
;
148 if (Function->getPrimaryTemplate()->isMemberSpecialization())
149 break;
150
151 // If this function is a generic lambda specialization, we are done.
152 if (isGenericLambdaCallOperatorSpecialization(Function))
153 break;
154
155 } else if (FunctionTemplateDecl *FunTmpl
156 = Function->getDescribedFunctionTemplate()) {
157 // Add the "injected" template arguments.
158 Result.addOuterTemplateArguments(FunTmpl->getInjectedTemplateArgs());
159 }
160
161 // If this is a friend declaration and it declares an entity at
162 // namespace scope, take arguments from its lexical parent
163 // instead of its semantic parent, unless of course the pattern we're
164 // instantiating actually comes from the file's context!
165 if (Function->getFriendObjectKind() &&
166 Function->getDeclContext()->isFileContext() &&
167 (!Pattern || !Pattern->getLexicalDeclContext()->isFileContext())) {
168 Ctx = Function->getLexicalDeclContext();
169 RelativeToPrimary = false;
170 continue;
171 }
172 } else if (CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Ctx)) {
173 if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) {
174 QualType T = ClassTemplate->getInjectedClassNameSpecialization();
175 const TemplateSpecializationType *TST =
176 cast<TemplateSpecializationType>(Context.getCanonicalType(T));
177 Result.addOuterTemplateArguments(
178 llvm::makeArrayRef(TST->getArgs(), TST->getNumArgs()));
179 if (ClassTemplate->isMemberSpecialization())
180 break;
181 }
182 }
183
184 Ctx = Ctx->getParent();
185 RelativeToPrimary = false;
186 }
187
188 return Result;
189}
190
191bool Sema::CodeSynthesisContext::isInstantiationRecord() const {
192 switch (Kind) {
193 case TemplateInstantiation:
194 case ExceptionSpecInstantiation:
195 case DefaultTemplateArgumentInstantiation:
196 case DefaultFunctionArgumentInstantiation:
197 case ExplicitTemplateArgumentSubstitution:
198 case DeducedTemplateArgumentSubstitution:
199 case PriorTemplateArgumentSubstitution:
200 return true;
201
202 case DefaultTemplateArgumentChecking:
203 case DeclaringSpecialMember:
204 case DefiningSynthesizedFunction:
205 case ExceptionSpecEvaluation:
206 return false;
207
208 // This function should never be called when Kind's value is Memoization.
209 case Memoization:
210 break;
211 }
212
213 llvm_unreachable("Invalid SynthesisKind!")::llvm::llvm_unreachable_internal("Invalid SynthesisKind!", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 213)
;
214}
215
216Sema::InstantiatingTemplate::InstantiatingTemplate(
217 Sema &SemaRef, CodeSynthesisContext::SynthesisKind Kind,
218 SourceLocation PointOfInstantiation, SourceRange InstantiationRange,
219 Decl *Entity, NamedDecl *Template, ArrayRef<TemplateArgument> TemplateArgs,
220 sema::TemplateDeductionInfo *DeductionInfo)
221 : SemaRef(SemaRef) {
222 // Don't allow further instantiation if a fatal error and an uncompilable
223 // error have occurred. Any diagnostics we might have raised will not be
224 // visible, and we do not need to construct a correct AST.
225 if (SemaRef.Diags.hasFatalErrorOccurred() &&
226 SemaRef.Diags.hasUncompilableErrorOccurred()) {
227 Invalid = true;
228 return;
229 }
230 Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange);
231 if (!Invalid) {
232 CodeSynthesisContext Inst;
233 Inst.Kind = Kind;
234 Inst.PointOfInstantiation = PointOfInstantiation;
235 Inst.Entity = Entity;
236 Inst.Template = Template;
237 Inst.TemplateArgs = TemplateArgs.data();
238 Inst.NumTemplateArgs = TemplateArgs.size();
239 Inst.DeductionInfo = DeductionInfo;
240 Inst.InstantiationRange = InstantiationRange;
241 SemaRef.pushCodeSynthesisContext(Inst);
242
243 AlreadyInstantiating =
244 !SemaRef.InstantiatingSpecializations
245 .insert(std::make_pair(Inst.Entity->getCanonicalDecl(), Inst.Kind))
246 .second;
247 atTemplateBegin(SemaRef.TemplateInstCallbacks, SemaRef, Inst);
248 }
249}
250
251Sema::InstantiatingTemplate::InstantiatingTemplate(
252 Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity,
253 SourceRange InstantiationRange)
254 : InstantiatingTemplate(SemaRef,
255 CodeSynthesisContext::TemplateInstantiation,
256 PointOfInstantiation, InstantiationRange, Entity) {}
257
258Sema::InstantiatingTemplate::InstantiatingTemplate(
259 Sema &SemaRef, SourceLocation PointOfInstantiation, FunctionDecl *Entity,
260 ExceptionSpecification, SourceRange InstantiationRange)
261 : InstantiatingTemplate(
262 SemaRef, CodeSynthesisContext::ExceptionSpecInstantiation,
263 PointOfInstantiation, InstantiationRange, Entity) {}
264
265Sema::InstantiatingTemplate::InstantiatingTemplate(
266 Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateParameter Param,
267 TemplateDecl *Template, ArrayRef<TemplateArgument> TemplateArgs,
268 SourceRange InstantiationRange)
269 : InstantiatingTemplate(
270 SemaRef,
271 CodeSynthesisContext::DefaultTemplateArgumentInstantiation,
272 PointOfInstantiation, InstantiationRange, getAsNamedDecl(Param),
273 Template, TemplateArgs) {}
274
275Sema::InstantiatingTemplate::InstantiatingTemplate(
276 Sema &SemaRef, SourceLocation PointOfInstantiation,
277 FunctionTemplateDecl *FunctionTemplate,
278 ArrayRef<TemplateArgument> TemplateArgs,
279 CodeSynthesisContext::SynthesisKind Kind,
280 sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
281 : InstantiatingTemplate(SemaRef, Kind, PointOfInstantiation,
282 InstantiationRange, FunctionTemplate, nullptr,
283 TemplateArgs, &DeductionInfo) {
284 assert(((Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution
|| Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution
) ? static_cast<void> (0) : __assert_fail ("Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution"
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 286, __PRETTY_FUNCTION__))
285 Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution ||((Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution
|| Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution
) ? static_cast<void> (0) : __assert_fail ("Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution"
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 286, __PRETTY_FUNCTION__))
286 Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution)((Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution
|| Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution
) ? static_cast<void> (0) : __assert_fail ("Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution"
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 286, __PRETTY_FUNCTION__))
;
287}
288
289Sema::InstantiatingTemplate::InstantiatingTemplate(
290 Sema &SemaRef, SourceLocation PointOfInstantiation,
291 TemplateDecl *Template,
292 ArrayRef<TemplateArgument> TemplateArgs,
293 sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
294 : InstantiatingTemplate(
295 SemaRef,
296 CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
297 PointOfInstantiation, InstantiationRange, Template, nullptr,
298 TemplateArgs, &DeductionInfo) {}
299
300Sema::InstantiatingTemplate::InstantiatingTemplate(
301 Sema &SemaRef, SourceLocation PointOfInstantiation,
302 ClassTemplatePartialSpecializationDecl *PartialSpec,
303 ArrayRef<TemplateArgument> TemplateArgs,
304 sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
305 : InstantiatingTemplate(
306 SemaRef,
307 CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
308 PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
309 TemplateArgs, &DeductionInfo) {}
310
311Sema::InstantiatingTemplate::InstantiatingTemplate(
312 Sema &SemaRef, SourceLocation PointOfInstantiation,
313 VarTemplatePartialSpecializationDecl *PartialSpec,
314 ArrayRef<TemplateArgument> TemplateArgs,
315 sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange)
316 : InstantiatingTemplate(
317 SemaRef,
318 CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
319 PointOfInstantiation, InstantiationRange, PartialSpec, nullptr,
320 TemplateArgs, &DeductionInfo) {}
321
322Sema::InstantiatingTemplate::InstantiatingTemplate(
323 Sema &SemaRef, SourceLocation PointOfInstantiation, ParmVarDecl *Param,
324 ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange)
325 : InstantiatingTemplate(
326 SemaRef,
327 CodeSynthesisContext::DefaultFunctionArgumentInstantiation,
328 PointOfInstantiation, InstantiationRange, Param, nullptr,
329 TemplateArgs) {}
330
331Sema::InstantiatingTemplate::InstantiatingTemplate(
332 Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template,
333 NonTypeTemplateParmDecl *Param, ArrayRef<TemplateArgument> TemplateArgs,
334 SourceRange InstantiationRange)
335 : InstantiatingTemplate(
336 SemaRef,
337 CodeSynthesisContext::PriorTemplateArgumentSubstitution,
338 PointOfInstantiation, InstantiationRange, Param, Template,
339 TemplateArgs) {}
340
341Sema::InstantiatingTemplate::InstantiatingTemplate(
342 Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template,
343 TemplateTemplateParmDecl *Param, ArrayRef<TemplateArgument> TemplateArgs,
344 SourceRange InstantiationRange)
345 : InstantiatingTemplate(
346 SemaRef,
347 CodeSynthesisContext::PriorTemplateArgumentSubstitution,
348 PointOfInstantiation, InstantiationRange, Param, Template,
349 TemplateArgs) {}
350
351Sema::InstantiatingTemplate::InstantiatingTemplate(
352 Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateDecl *Template,
353 NamedDecl *Param, ArrayRef<TemplateArgument> TemplateArgs,
354 SourceRange InstantiationRange)
355 : InstantiatingTemplate(
356 SemaRef, CodeSynthesisContext::DefaultTemplateArgumentChecking,
357 PointOfInstantiation, InstantiationRange, Param, Template,
358 TemplateArgs) {}
359
360void Sema::pushCodeSynthesisContext(CodeSynthesisContext Ctx) {
361 Ctx.SavedInNonInstantiationSFINAEContext = InNonInstantiationSFINAEContext;
362 InNonInstantiationSFINAEContext = false;
363
364 CodeSynthesisContexts.push_back(Ctx);
365
366 if (!Ctx.isInstantiationRecord())
367 ++NonInstantiationEntries;
368}
369
370void Sema::popCodeSynthesisContext() {
371 auto &Active = CodeSynthesisContexts.back();
372 if (!Active.isInstantiationRecord()) {
373 assert(NonInstantiationEntries > 0)((NonInstantiationEntries > 0) ? static_cast<void> (
0) : __assert_fail ("NonInstantiationEntries > 0", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 373, __PRETTY_FUNCTION__))
;
374 --NonInstantiationEntries;
375 }
376
377 InNonInstantiationSFINAEContext = Active.SavedInNonInstantiationSFINAEContext;
378
379 // Name lookup no longer looks in this template's defining module.
380 assert(CodeSynthesisContexts.size() >=((CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules
.size() && "forgot to remove a lookup module for a template instantiation"
) ? static_cast<void> (0) : __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 382, __PRETTY_FUNCTION__))
381 CodeSynthesisContextLookupModules.size() &&((CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules
.size() && "forgot to remove a lookup module for a template instantiation"
) ? static_cast<void> (0) : __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 382, __PRETTY_FUNCTION__))
382 "forgot to remove a lookup module for a template instantiation")((CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules
.size() && "forgot to remove a lookup module for a template instantiation"
) ? static_cast<void> (0) : __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 382, __PRETTY_FUNCTION__))
;
383 if (CodeSynthesisContexts.size() ==
384 CodeSynthesisContextLookupModules.size()) {
385 if (Module *M = CodeSynthesisContextLookupModules.back())
386 LookupModulesCache.erase(M);
387 CodeSynthesisContextLookupModules.pop_back();
388 }
389
390 // If we've left the code synthesis context for the current context stack,
391 // stop remembering that we've emitted that stack.
392 if (CodeSynthesisContexts.size() ==
393 LastEmittedCodeSynthesisContextDepth)
394 LastEmittedCodeSynthesisContextDepth = 0;
395
396 CodeSynthesisContexts.pop_back();
397}
398
399void Sema::InstantiatingTemplate::Clear() {
400 if (!Invalid) {
401 if (!AlreadyInstantiating) {
402 auto &Active = SemaRef.CodeSynthesisContexts.back();
403 SemaRef.InstantiatingSpecializations.erase(
404 std::make_pair(Active.Entity, Active.Kind));
405 }
406
407 atTemplateEnd(SemaRef.TemplateInstCallbacks, SemaRef,
408 SemaRef.CodeSynthesisContexts.back());
409
410 SemaRef.popCodeSynthesisContext();
411 Invalid = true;
412 }
413}
414
415bool Sema::InstantiatingTemplate::CheckInstantiationDepth(
416 SourceLocation PointOfInstantiation,
417 SourceRange InstantiationRange) {
418 assert(SemaRef.NonInstantiationEntries <=((SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts
.size()) ? static_cast<void> (0) : __assert_fail ("SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts.size()"
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 419, __PRETTY_FUNCTION__))
419 SemaRef.CodeSynthesisContexts.size())((SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts
.size()) ? static_cast<void> (0) : __assert_fail ("SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts.size()"
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 419, __PRETTY_FUNCTION__))
;
420 if ((SemaRef.CodeSynthesisContexts.size() -
421 SemaRef.NonInstantiationEntries)
422 <= SemaRef.getLangOpts().InstantiationDepth)
423 return false;
424
425 SemaRef.Diag(PointOfInstantiation,
426 diag::err_template_recursion_depth_exceeded)
427 << SemaRef.getLangOpts().InstantiationDepth
428 << InstantiationRange;
429 SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth)
430 << SemaRef.getLangOpts().InstantiationDepth;
431 return true;
432}
433
434/// Prints the current instantiation stack through a series of
435/// notes.
436void Sema::PrintInstantiationStack() {
437 // Determine which template instantiations to skip, if any.
438 unsigned SkipStart = CodeSynthesisContexts.size(), SkipEnd = SkipStart;
439 unsigned Limit = Diags.getTemplateBacktraceLimit();
440 if (Limit && Limit < CodeSynthesisContexts.size()) {
441 SkipStart = Limit / 2 + Limit % 2;
442 SkipEnd = CodeSynthesisContexts.size() - Limit / 2;
443 }
444
445 // FIXME: In all of these cases, we need to show the template arguments
446 unsigned InstantiationIdx = 0;
447 for (SmallVectorImpl<CodeSynthesisContext>::reverse_iterator
448 Active = CodeSynthesisContexts.rbegin(),
449 ActiveEnd = CodeSynthesisContexts.rend();
450 Active != ActiveEnd;
451 ++Active, ++InstantiationIdx) {
452 // Skip this instantiation?
453 if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) {
454 if (InstantiationIdx == SkipStart) {
455 // Note that we're skipping instantiations.
456 Diags.Report(Active->PointOfInstantiation,
457 diag::note_instantiation_contexts_suppressed)
458 << unsigned(CodeSynthesisContexts.size() - Limit);
459 }
460 continue;
461 }
462
463 switch (Active->Kind) {
464 case CodeSynthesisContext::TemplateInstantiation: {
465 Decl *D = Active->Entity;
466 if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) {
467 unsigned DiagID = diag::note_template_member_class_here;
468 if (isa<ClassTemplateSpecializationDecl>(Record))
469 DiagID = diag::note_template_class_instantiation_here;
470 Diags.Report(Active->PointOfInstantiation, DiagID)
471 << Record << Active->InstantiationRange;
472 } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
473 unsigned DiagID;
474 if (Function->getPrimaryTemplate())
475 DiagID = diag::note_function_template_spec_here;
476 else
477 DiagID = diag::note_template_member_function_here;
478 Diags.Report(Active->PointOfInstantiation, DiagID)
479 << Function
480 << Active->InstantiationRange;
481 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
482 Diags.Report(Active->PointOfInstantiation,
483 VD->isStaticDataMember()?
484 diag::note_template_static_data_member_def_here
485 : diag::note_template_variable_def_here)
486 << VD
487 << Active->InstantiationRange;
488 } else if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
489 Diags.Report(Active->PointOfInstantiation,
490 diag::note_template_enum_def_here)
491 << ED
492 << Active->InstantiationRange;
493 } else if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
494 Diags.Report(Active->PointOfInstantiation,
495 diag::note_template_nsdmi_here)
496 << FD << Active->InstantiationRange;
497 } else {
498 Diags.Report(Active->PointOfInstantiation,
499 diag::note_template_type_alias_instantiation_here)
500 << cast<TypeAliasTemplateDecl>(D)
501 << Active->InstantiationRange;
502 }
503 break;
504 }
505
506 case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: {
507 TemplateDecl *Template = cast<TemplateDecl>(Active->Template);
508 SmallVector<char, 128> TemplateArgsStr;
509 llvm::raw_svector_ostream OS(TemplateArgsStr);
510 Template->printName(OS);
511 printTemplateArgumentList(OS, Active->template_arguments(),
512 getPrintingPolicy());
513 Diags.Report(Active->PointOfInstantiation,
514 diag::note_default_arg_instantiation_here)
515 << OS.str()
516 << Active->InstantiationRange;
517 break;
518 }
519
520 case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution: {
521 FunctionTemplateDecl *FnTmpl = cast<FunctionTemplateDecl>(Active->Entity);
522 Diags.Report(Active->PointOfInstantiation,
523 diag::note_explicit_template_arg_substitution_here)
524 << FnTmpl
525 << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(),
526 Active->TemplateArgs,
527 Active->NumTemplateArgs)
528 << Active->InstantiationRange;
529 break;
530 }
531
532 case CodeSynthesisContext::DeducedTemplateArgumentSubstitution: {
533 if (FunctionTemplateDecl *FnTmpl =
534 dyn_cast<FunctionTemplateDecl>(Active->Entity)) {
535 Diags.Report(Active->PointOfInstantiation,
536 diag::note_function_template_deduction_instantiation_here)
537 << FnTmpl
538 << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(),
539 Active->TemplateArgs,
540 Active->NumTemplateArgs)
541 << Active->InstantiationRange;
542 } else {
543 bool IsVar = isa<VarTemplateDecl>(Active->Entity) ||
544 isa<VarTemplateSpecializationDecl>(Active->Entity);
545 bool IsTemplate = false;
546 TemplateParameterList *Params;
547 if (auto *D = dyn_cast<TemplateDecl>(Active->Entity)) {
548 IsTemplate = true;
549 Params = D->getTemplateParameters();
550 } else if (auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>(
551 Active->Entity)) {
552 Params = D->getTemplateParameters();
553 } else if (auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>(
554 Active->Entity)) {
555 Params = D->getTemplateParameters();
556 } else {
557 llvm_unreachable("unexpected template kind")::llvm::llvm_unreachable_internal("unexpected template kind",
"/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 557)
;
558 }
559
560 Diags.Report(Active->PointOfInstantiation,
561 diag::note_deduced_template_arg_substitution_here)
562 << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity)
563 << getTemplateArgumentBindingsText(Params, Active->TemplateArgs,
564 Active->NumTemplateArgs)
565 << Active->InstantiationRange;
566 }
567 break;
568 }
569
570 case CodeSynthesisContext::DefaultFunctionArgumentInstantiation: {
571 ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity);
572 FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext());
573
574 SmallVector<char, 128> TemplateArgsStr;
575 llvm::raw_svector_ostream OS(TemplateArgsStr);
576 FD->printName(OS);
577 printTemplateArgumentList(OS, Active->template_arguments(),
578 getPrintingPolicy());
579 Diags.Report(Active->PointOfInstantiation,
580 diag::note_default_function_arg_instantiation_here)
581 << OS.str()
582 << Active->InstantiationRange;
583 break;
584 }
585
586 case CodeSynthesisContext::PriorTemplateArgumentSubstitution: {
587 NamedDecl *Parm = cast<NamedDecl>(Active->Entity);
588 std::string Name;
589 if (!Parm->getName().empty())
590 Name = std::string(" '") + Parm->getName().str() + "'";
591
592 TemplateParameterList *TemplateParams = nullptr;
593 if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
594 TemplateParams = Template->getTemplateParameters();
595 else
596 TemplateParams =
597 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
598 ->getTemplateParameters();
599 Diags.Report(Active->PointOfInstantiation,
600 diag::note_prior_template_arg_substitution)
601 << isa<TemplateTemplateParmDecl>(Parm)
602 << Name
603 << getTemplateArgumentBindingsText(TemplateParams,
604 Active->TemplateArgs,
605 Active->NumTemplateArgs)
606 << Active->InstantiationRange;
607 break;
608 }
609
610 case CodeSynthesisContext::DefaultTemplateArgumentChecking: {
611 TemplateParameterList *TemplateParams = nullptr;
612 if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template))
613 TemplateParams = Template->getTemplateParameters();
614 else
615 TemplateParams =
616 cast<ClassTemplatePartialSpecializationDecl>(Active->Template)
617 ->getTemplateParameters();
618
619 Diags.Report(Active->PointOfInstantiation,
620 diag::note_template_default_arg_checking)
621 << getTemplateArgumentBindingsText(TemplateParams,
622 Active->TemplateArgs,
623 Active->NumTemplateArgs)
624 << Active->InstantiationRange;
625 break;
626 }
627
628 case CodeSynthesisContext::ExceptionSpecEvaluation:
629 Diags.Report(Active->PointOfInstantiation,
630 diag::note_evaluating_exception_spec_here)
631 << cast<FunctionDecl>(Active->Entity);
632 break;
633
634 case CodeSynthesisContext::ExceptionSpecInstantiation:
635 Diags.Report(Active->PointOfInstantiation,
636 diag::note_template_exception_spec_instantiation_here)
637 << cast<FunctionDecl>(Active->Entity)
638 << Active->InstantiationRange;
639 break;
640
641 case CodeSynthesisContext::DeclaringSpecialMember:
642 Diags.Report(Active->PointOfInstantiation,
643 diag::note_in_declaration_of_implicit_special_member)
644 << cast<CXXRecordDecl>(Active->Entity) << Active->SpecialMember;
645 break;
646
647 case CodeSynthesisContext::DefiningSynthesizedFunction: {
648 // FIXME: For synthesized members other than special members, produce a note.
649 auto *MD = dyn_cast<CXXMethodDecl>(Active->Entity);
650 auto CSM = MD ? getSpecialMember(MD) : CXXInvalid;
651 if (CSM != CXXInvalid) {
652 Diags.Report(Active->PointOfInstantiation,
653 diag::note_member_synthesized_at)
654 << CSM << Context.getTagDeclType(MD->getParent());
655 }
656 break;
657 }
658
659 case CodeSynthesisContext::Memoization:
660 break;
661 }
662 }
663}
664
665Optional<TemplateDeductionInfo *> Sema::isSFINAEContext() const {
666 if (InNonInstantiationSFINAEContext)
667 return Optional<TemplateDeductionInfo *>(nullptr);
668
669 for (SmallVectorImpl<CodeSynthesisContext>::const_reverse_iterator
670 Active = CodeSynthesisContexts.rbegin(),
671 ActiveEnd = CodeSynthesisContexts.rend();
672 Active != ActiveEnd;
673 ++Active)
674 {
675 switch (Active->Kind) {
676 case CodeSynthesisContext::TemplateInstantiation:
677 // An instantiation of an alias template may or may not be a SFINAE
678 // context, depending on what else is on the stack.
679 if (isa<TypeAliasTemplateDecl>(Active->Entity))
680 break;
681 LLVM_FALLTHROUGH[[clang::fallthrough]];
682 case CodeSynthesisContext::DefaultFunctionArgumentInstantiation:
683 case CodeSynthesisContext::ExceptionSpecInstantiation:
684 // This is a template instantiation, so there is no SFINAE.
685 return None;
686
687 case CodeSynthesisContext::DefaultTemplateArgumentInstantiation:
688 case CodeSynthesisContext::PriorTemplateArgumentSubstitution:
689 case CodeSynthesisContext::DefaultTemplateArgumentChecking:
690 // A default template argument instantiation and substitution into
691 // template parameters with arguments for prior parameters may or may
692 // not be a SFINAE context; look further up the stack.
693 break;
694
695 case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution:
696 case CodeSynthesisContext::DeducedTemplateArgumentSubstitution:
697 // We're either substitution explicitly-specified template arguments
698 // or deduced template arguments, so SFINAE applies.
699 assert(Active->DeductionInfo && "Missing deduction info pointer")((Active->DeductionInfo && "Missing deduction info pointer"
) ? static_cast<void> (0) : __assert_fail ("Active->DeductionInfo && \"Missing deduction info pointer\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 699, __PRETTY_FUNCTION__))
;
700 return Active->DeductionInfo;
701
702 case CodeSynthesisContext::DeclaringSpecialMember:
703 case CodeSynthesisContext::DefiningSynthesizedFunction:
704 // This happens in a context unrelated to template instantiation, so
705 // there is no SFINAE.
706 return None;
707
708 case CodeSynthesisContext::ExceptionSpecEvaluation:
709 // FIXME: This should not be treated as a SFINAE context, because
710 // we will cache an incorrect exception specification. However, clang
711 // bootstrap relies this! See PR31692.
712 break;
713
714 case CodeSynthesisContext::Memoization:
715 break;
716 }
717
718 // The inner context was transparent for SFINAE. If it occurred within a
719 // non-instantiation SFINAE context, then SFINAE applies.
720 if (Active->SavedInNonInstantiationSFINAEContext)
721 return Optional<TemplateDeductionInfo *>(nullptr);
722 }
723
724 return None;
725}
726
727//===----------------------------------------------------------------------===/
728// Template Instantiation for Types
729//===----------------------------------------------------------------------===/
730namespace {
731 class TemplateInstantiator : public TreeTransform<TemplateInstantiator> {
732 const MultiLevelTemplateArgumentList &TemplateArgs;
733 SourceLocation Loc;
734 DeclarationName Entity;
735
736 public:
737 typedef TreeTransform<TemplateInstantiator> inherited;
738
739 TemplateInstantiator(Sema &SemaRef,
740 const MultiLevelTemplateArgumentList &TemplateArgs,
741 SourceLocation Loc,
742 DeclarationName Entity)
743 : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc),
744 Entity(Entity) { }
745
746 /// Determine whether the given type \p T has already been
747 /// transformed.
748 ///
749 /// For the purposes of template instantiation, a type has already been
750 /// transformed if it is NULL or if it is not dependent.
751 bool AlreadyTransformed(QualType T);
752
753 /// Returns the location of the entity being instantiated, if known.
754 SourceLocation getBaseLocation() { return Loc; }
755
756 /// Returns the name of the entity being instantiated, if any.
757 DeclarationName getBaseEntity() { return Entity; }
758
759 /// Sets the "base" location and entity when that
760 /// information is known based on another transformation.
761 void setBase(SourceLocation Loc, DeclarationName Entity) {
762 this->Loc = Loc;
763 this->Entity = Entity;
764 }
765
766 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
767 SourceRange PatternRange,
768 ArrayRef<UnexpandedParameterPack> Unexpanded,
769 bool &ShouldExpand, bool &RetainExpansion,
770 Optional<unsigned> &NumExpansions) {
771 return getSema().CheckParameterPacksForExpansion(EllipsisLoc,
772 PatternRange, Unexpanded,
773 TemplateArgs,
774 ShouldExpand,
775 RetainExpansion,
776 NumExpansions);
777 }
778
779 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) {
780 SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Pack);
781 }
782
783 TemplateArgument ForgetPartiallySubstitutedPack() {
784 TemplateArgument Result;
785 if (NamedDecl *PartialPack
786 = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){
787 MultiLevelTemplateArgumentList &TemplateArgs
788 = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs);
789 unsigned Depth, Index;
790 std::tie(Depth, Index) = getDepthAndIndex(PartialPack);
791 if (TemplateArgs.hasTemplateArgument(Depth, Index)) {
792 Result = TemplateArgs(Depth, Index);
793 TemplateArgs.setArgument(Depth, Index, TemplateArgument());
794 }
795 }
796
797 return Result;
798 }
799
800 void RememberPartiallySubstitutedPack(TemplateArgument Arg) {
801 if (Arg.isNull())
802 return;
803
804 if (NamedDecl *PartialPack
805 = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){
806 MultiLevelTemplateArgumentList &TemplateArgs
807 = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs);
808 unsigned Depth, Index;
809 std::tie(Depth, Index) = getDepthAndIndex(PartialPack);
810 TemplateArgs.setArgument(Depth, Index, Arg);
811 }
812 }
813
814 /// Transform the given declaration by instantiating a reference to
815 /// this declaration.
816 Decl *TransformDecl(SourceLocation Loc, Decl *D);
817
818 void transformAttrs(Decl *Old, Decl *New) {
819 SemaRef.InstantiateAttrs(TemplateArgs, Old, New);
820 }
821
822 void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) {
823 if (Old->isParameterPack()) {
824 SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Old);
825 for (auto *New : NewDecls)
826 SemaRef.CurrentInstantiationScope->InstantiatedLocalPackArg(
827 Old, cast<VarDecl>(New));
828 return;
829 }
830
831 assert(NewDecls.size() == 1 &&((NewDecls.size() == 1 && "should only have multiple expansions for a pack"
) ? static_cast<void> (0) : __assert_fail ("NewDecls.size() == 1 && \"should only have multiple expansions for a pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 832, __PRETTY_FUNCTION__))
832 "should only have multiple expansions for a pack")((NewDecls.size() == 1 && "should only have multiple expansions for a pack"
) ? static_cast<void> (0) : __assert_fail ("NewDecls.size() == 1 && \"should only have multiple expansions for a pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 832, __PRETTY_FUNCTION__))
;
833 Decl *New = NewDecls.front();
834
835 // If we've instantiated the call operator of a lambda or the call
836 // operator template of a generic lambda, update the "instantiation of"
837 // information.
838 auto *NewMD = dyn_cast<CXXMethodDecl>(New);
839 if (NewMD && isLambdaCallOperator(NewMD)) {
840 auto *OldMD = dyn_cast<CXXMethodDecl>(Old);
841 if (auto *NewTD = NewMD->getDescribedFunctionTemplate())
842 NewTD->setInstantiatedFromMemberTemplate(
843 OldMD->getDescribedFunctionTemplate());
844 else
845 NewMD->setInstantiationOfMemberFunction(OldMD,
846 TSK_ImplicitInstantiation);
847 }
848
849 SemaRef.CurrentInstantiationScope->InstantiatedLocal(Old, New);
850
851 // We recreated a local declaration, but not by instantiating it. There
852 // may be pending dependent diagnostics to produce.
853 if (auto *DC = dyn_cast<DeclContext>(Old))
854 SemaRef.PerformDependentDiagnostics(DC, TemplateArgs);
855 }
856
857 /// Transform the definition of the given declaration by
858 /// instantiating it.
859 Decl *TransformDefinition(SourceLocation Loc, Decl *D);
860
861 /// Transform the first qualifier within a scope by instantiating the
862 /// declaration.
863 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc);
864
865 /// Rebuild the exception declaration and register the declaration
866 /// as an instantiated local.
867 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
868 TypeSourceInfo *Declarator,
869 SourceLocation StartLoc,
870 SourceLocation NameLoc,
871 IdentifierInfo *Name);
872
873 /// Rebuild the Objective-C exception declaration and register the
874 /// declaration as an instantiated local.
875 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
876 TypeSourceInfo *TSInfo, QualType T);
877
878 /// Check for tag mismatches when instantiating an
879 /// elaborated type.
880 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
881 ElaboratedTypeKeyword Keyword,
882 NestedNameSpecifierLoc QualifierLoc,
883 QualType T);
884
885 TemplateName
886 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
887 SourceLocation NameLoc,
888 QualType ObjectType = QualType(),
889 NamedDecl *FirstQualifierInScope = nullptr,
890 bool AllowInjectedClassName = false);
891
892 const LoopHintAttr *TransformLoopHintAttr(const LoopHintAttr *LH);
893
894 ExprResult TransformPredefinedExpr(PredefinedExpr *E);
895 ExprResult TransformDeclRefExpr(DeclRefExpr *E);
896 ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E);
897
898 ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E,
899 NonTypeTemplateParmDecl *D);
900 ExprResult TransformSubstNonTypeTemplateParmPackExpr(
901 SubstNonTypeTemplateParmPackExpr *E);
902
903 /// Rebuild a DeclRefExpr for a VarDecl reference.
904 ExprResult RebuildVarDeclRefExpr(VarDecl *PD, SourceLocation Loc);
905
906 /// Transform a reference to a function or init-capture parameter pack.
907 ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, VarDecl *PD);
908
909 /// Transform a FunctionParmPackExpr which was built when we couldn't
910 /// expand a function parameter pack reference which refers to an expanded
911 /// pack.
912 ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E);
913
914 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
915 FunctionProtoTypeLoc TL) {
916 // Call the base version; it will forward to our overridden version below.
917 return inherited::TransformFunctionProtoType(TLB, TL);
918 }
919
920 template<typename Fn>
921 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
922 FunctionProtoTypeLoc TL,
923 CXXRecordDecl *ThisContext,
924 Qualifiers ThisTypeQuals,
925 Fn TransformExceptionSpec);
926
927 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
928 int indexAdjustment,
929 Optional<unsigned> NumExpansions,
930 bool ExpectParameterPack);
931
932 /// Transforms a template type parameter type by performing
933 /// substitution of the corresponding template type argument.
934 QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB,
935 TemplateTypeParmTypeLoc TL);
936
937 /// Transforms an already-substituted template type parameter pack
938 /// into either itself (if we aren't substituting into its pack expansion)
939 /// or the appropriate substituted argument.
940 QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB,
941 SubstTemplateTypeParmPackTypeLoc TL);
942
943 ExprResult TransformLambdaExpr(LambdaExpr *E) {
944 LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
945 return TreeTransform<TemplateInstantiator>::TransformLambdaExpr(E);
946 }
947
948 TemplateParameterList *TransformTemplateParameterList(
949 TemplateParameterList *OrigTPL) {
950 if (!OrigTPL || !OrigTPL->size()) return OrigTPL;
951
952 DeclContext *Owner = OrigTPL->getParam(0)->getDeclContext();
953 TemplateDeclInstantiator DeclInstantiator(getSema(),
954 /* DeclContext *Owner */ Owner, TemplateArgs);
955 return DeclInstantiator.SubstTemplateParams(OrigTPL);
956 }
957 private:
958 ExprResult transformNonTypeTemplateParmRef(NonTypeTemplateParmDecl *parm,
959 SourceLocation loc,
960 TemplateArgument arg);
961 };
962}
963
964bool TemplateInstantiator::AlreadyTransformed(QualType T) {
965 if (T.isNull())
966 return true;
967
968 if (T->isInstantiationDependentType() || T->isVariablyModifiedType())
969 return false;
970
971 getSema().MarkDeclarationsReferencedInType(Loc, T);
972 return true;
973}
974
975static TemplateArgument
976getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg) {
977 assert(S.ArgumentPackSubstitutionIndex >= 0)((S.ArgumentPackSubstitutionIndex >= 0) ? static_cast<void
> (0) : __assert_fail ("S.ArgumentPackSubstitutionIndex >= 0"
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 977, __PRETTY_FUNCTION__))
;
978 assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size())((S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size()) ?
static_cast<void> (0) : __assert_fail ("S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size()"
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 978, __PRETTY_FUNCTION__))
;
979 Arg = Arg.pack_begin()[S.ArgumentPackSubstitutionIndex];
980 if (Arg.isPackExpansion())
981 Arg = Arg.getPackExpansionPattern();
982 return Arg;
983}
984
985Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
986 if (!D)
987 return nullptr;
988
989 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) {
990 if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
991 // If the corresponding template argument is NULL or non-existent, it's
992 // because we are performing instantiation from explicitly-specified
993 // template arguments in a function template, but there were some
994 // arguments left unspecified.
995 if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
996 TTP->getPosition()))
997 return D;
998
999 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1000
1001 if (TTP->isParameterPack()) {
1002 assert(Arg.getKind() == TemplateArgument::Pack &&((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack"
) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1003, __PRETTY_FUNCTION__))
1003 "Missing argument pack")((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack"
) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1003, __PRETTY_FUNCTION__))
;
1004 Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1005 }
1006
1007 TemplateName Template = Arg.getAsTemplate().getNameToSubstitute();
1008 assert(!Template.isNull() && Template.getAsTemplateDecl() &&((!Template.isNull() && Template.getAsTemplateDecl() &&
"Wrong kind of template template argument") ? static_cast<
void> (0) : __assert_fail ("!Template.isNull() && Template.getAsTemplateDecl() && \"Wrong kind of template template argument\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1009, __PRETTY_FUNCTION__))
1009 "Wrong kind of template template argument")((!Template.isNull() && Template.getAsTemplateDecl() &&
"Wrong kind of template template argument") ? static_cast<
void> (0) : __assert_fail ("!Template.isNull() && Template.getAsTemplateDecl() && \"Wrong kind of template template argument\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1009, __PRETTY_FUNCTION__))
;
1010 return Template.getAsTemplateDecl();
1011 }
1012
1013 // Fall through to find the instantiated declaration for this template
1014 // template parameter.
1015 }
1016
1017 return SemaRef.FindInstantiatedDecl(Loc, cast<NamedDecl>(D), TemplateArgs);
1018}
1019
1020Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) {
1021 Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs);
1022 if (!Inst)
1023 return nullptr;
1024
1025 getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst);
1026 return Inst;
1027}
1028
1029NamedDecl *
1030TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D,
1031 SourceLocation Loc) {
1032 // If the first part of the nested-name-specifier was a template type
1033 // parameter, instantiate that type parameter down to a tag type.
1034 if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) {
1035 const TemplateTypeParmType *TTP
1036 = cast<TemplateTypeParmType>(getSema().Context.getTypeDeclType(TTPD));
1037
1038 if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
1039 // FIXME: This needs testing w/ member access expressions.
1040 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex());
1041
1042 if (TTP->isParameterPack()) {
1043 assert(Arg.getKind() == TemplateArgument::Pack &&((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack"
) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1044, __PRETTY_FUNCTION__))
1044 "Missing argument pack")((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack"
) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1044, __PRETTY_FUNCTION__))
;
1045
1046 if (getSema().ArgumentPackSubstitutionIndex == -1)
1047 return nullptr;
1048
1049 Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1050 }
1051
1052 QualType T = Arg.getAsType();
1053 if (T.isNull())
1054 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1055
1056 if (const TagType *Tag = T->getAs<TagType>())
1057 return Tag->getDecl();
1058
1059 // The resulting type is not a tag; complain.
1060 getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) << T;
1061 return nullptr;
1062 }
1063 }
1064
1065 return cast_or_null<NamedDecl>(TransformDecl(Loc, D));
1066}
1067
1068VarDecl *
1069TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl,
1070 TypeSourceInfo *Declarator,
1071 SourceLocation StartLoc,
1072 SourceLocation NameLoc,
1073 IdentifierInfo *Name) {
1074 VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator,
1075 StartLoc, NameLoc, Name);
1076 if (Var)
1077 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1078 return Var;
1079}
1080
1081VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1082 TypeSourceInfo *TSInfo,
1083 QualType T) {
1084 VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo, T);
1085 if (Var)
1086 getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var);
1087 return Var;
1088}
1089
1090QualType
1091TemplateInstantiator::RebuildElaboratedType(SourceLocation KeywordLoc,
1092 ElaboratedTypeKeyword Keyword,
1093 NestedNameSpecifierLoc QualifierLoc,
1094 QualType T) {
1095 if (const TagType *TT = T->getAs<TagType>()) {
1096 TagDecl* TD = TT->getDecl();
1097
1098 SourceLocation TagLocation = KeywordLoc;
1099
1100 IdentifierInfo *Id = TD->getIdentifier();
1101
1102 // TODO: should we even warn on struct/class mismatches for this? Seems
1103 // like it's likely to produce a lot of spurious errors.
1104 if (Id && Keyword != ETK_None && Keyword != ETK_Typename) {
1105 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1106 if (!SemaRef.isAcceptableTagRedeclaration(TD, Kind, /*isDefinition*/false,
1107 TagLocation, Id)) {
1108 SemaRef.Diag(TagLocation, diag::err_use_with_wrong_tag)
1109 << Id
1110 << FixItHint::CreateReplacement(SourceRange(TagLocation),
1111 TD->getKindName());
1112 SemaRef.Diag(TD->getLocation(), diag::note_previous_use);
1113 }
1114 }
1115 }
1116
1117 return TreeTransform<TemplateInstantiator>::RebuildElaboratedType(KeywordLoc,
1118 Keyword,
1119 QualifierLoc,
1120 T);
1121}
1122
1123TemplateName TemplateInstantiator::TransformTemplateName(
1124 CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc,
1125 QualType ObjectType, NamedDecl *FirstQualifierInScope,
1126 bool AllowInjectedClassName) {
1127 if (TemplateTemplateParmDecl *TTP
1128 = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) {
1129 if (TTP->getDepth() < TemplateArgs.getNumLevels()) {
1130 // If the corresponding template argument is NULL or non-existent, it's
1131 // because we are performing instantiation from explicitly-specified
1132 // template arguments in a function template, but there were some
1133 // arguments left unspecified.
1134 if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(),
1135 TTP->getPosition()))
1136 return Name;
1137
1138 TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition());
1139
1140 if (TTP->isParameterPack()) {
1141 assert(Arg.getKind() == TemplateArgument::Pack &&((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack"
) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1142, __PRETTY_FUNCTION__))
1142 "Missing argument pack")((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack"
) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1142, __PRETTY_FUNCTION__))
;
1143
1144 if (getSema().ArgumentPackSubstitutionIndex == -1) {
1145 // We have the template argument pack to substitute, but we're not
1146 // actually expanding the enclosing pack expansion yet. So, just
1147 // keep the entire argument pack.
1148 return getSema().Context.getSubstTemplateTemplateParmPack(TTP, Arg);
1149 }
1150
1151 Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1152 }
1153
1154 TemplateName Template = Arg.getAsTemplate().getNameToSubstitute();
1155 assert(!Template.isNull() && "Null template template argument")((!Template.isNull() && "Null template template argument"
) ? static_cast<void> (0) : __assert_fail ("!Template.isNull() && \"Null template template argument\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1155, __PRETTY_FUNCTION__))
;
1156 assert(!Template.getAsQualifiedTemplateName() &&((!Template.getAsQualifiedTemplateName() && "template decl to substitute is qualified?"
) ? static_cast<void> (0) : __assert_fail ("!Template.getAsQualifiedTemplateName() && \"template decl to substitute is qualified?\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1157, __PRETTY_FUNCTION__))
1157 "template decl to substitute is qualified?")((!Template.getAsQualifiedTemplateName() && "template decl to substitute is qualified?"
) ? static_cast<void> (0) : __assert_fail ("!Template.getAsQualifiedTemplateName() && \"template decl to substitute is qualified?\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1157, __PRETTY_FUNCTION__))
;
1158
1159 Template = getSema().Context.getSubstTemplateTemplateParm(TTP, Template);
1160 return Template;
1161 }
1162 }
1163
1164 if (SubstTemplateTemplateParmPackStorage *SubstPack
1165 = Name.getAsSubstTemplateTemplateParmPack()) {
1166 if (getSema().ArgumentPackSubstitutionIndex == -1)
1167 return Name;
1168
1169 TemplateArgument Arg = SubstPack->getArgumentPack();
1170 Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1171 return Arg.getAsTemplate().getNameToSubstitute();
1172 }
1173
1174 return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType,
1175 FirstQualifierInScope,
1176 AllowInjectedClassName);
1177}
1178
1179ExprResult
1180TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) {
1181 if (!E->isTypeDependent())
1182 return E;
1183
1184 return getSema().BuildPredefinedExpr(E->getLocation(), E->getIdentKind());
1185}
1186
1187ExprResult
1188TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
1189 NonTypeTemplateParmDecl *NTTP) {
1190 // If the corresponding template argument is NULL or non-existent, it's
1191 // because we are performing instantiation from explicitly-specified
1192 // template arguments in a function template, but there were some
1193 // arguments left unspecified.
1194 if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(),
1195 NTTP->getPosition()))
1196 return E;
1197
1198 TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), NTTP->getPosition());
1199
1200 if (TemplateArgs.getNumLevels() != TemplateArgs.getNumSubstitutedLevels()) {
1201 // We're performing a partial substitution, so the substituted argument
1202 // could be dependent. As a result we can't create a SubstNonType*Expr
1203 // node now, since that represents a fully-substituted argument.
1204 // FIXME: We should have some AST representation for this.
1205 if (Arg.getKind() == TemplateArgument::Pack) {
1206 // FIXME: This won't work for alias templates.
1207 assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&((Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion
() && "unexpected pack arguments in partial substitution"
) ? static_cast<void> (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in partial substitution\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1208, __PRETTY_FUNCTION__))
1208 "unexpected pack arguments in partial substitution")((Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion
() && "unexpected pack arguments in partial substitution"
) ? static_cast<void> (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in partial substitution\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1208, __PRETTY_FUNCTION__))
;
1209 Arg = Arg.pack_begin()->getPackExpansionPattern();
1210 }
1211 assert(Arg.getKind() == TemplateArgument::Expression &&((Arg.getKind() == TemplateArgument::Expression && "unexpected nontype template argument kind in partial substitution"
) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Expression && \"unexpected nontype template argument kind in partial substitution\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1212, __PRETTY_FUNCTION__))
1212 "unexpected nontype template argument kind in partial substitution")((Arg.getKind() == TemplateArgument::Expression && "unexpected nontype template argument kind in partial substitution"
) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Expression && \"unexpected nontype template argument kind in partial substitution\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1212, __PRETTY_FUNCTION__))
;
1213 return Arg.getAsExpr();
1214 }
1215
1216 if (NTTP->isParameterPack()) {
1217 assert(Arg.getKind() == TemplateArgument::Pack &&((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack"
) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1218, __PRETTY_FUNCTION__))
1218 "Missing argument pack")((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack"
) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1218, __PRETTY_FUNCTION__))
;
1219
1220 if (getSema().ArgumentPackSubstitutionIndex == -1) {
1221 // We have an argument pack, but we can't select a particular argument
1222 // out of it yet. Therefore, we'll build an expression to hold on to that
1223 // argument pack.
1224 QualType TargetType = SemaRef.SubstType(NTTP->getType(), TemplateArgs,
1225 E->getLocation(),
1226 NTTP->getDeclName());
1227 if (TargetType.isNull())
1228 return ExprError();
1229
1230 return new (SemaRef.Context) SubstNonTypeTemplateParmPackExpr(
1231 TargetType.getNonLValueExprType(SemaRef.Context),
1232 TargetType->isReferenceType() ? VK_LValue : VK_RValue, NTTP,
1233 E->getLocation(), Arg);
1234 }
1235
1236 Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1237 }
1238
1239 return transformNonTypeTemplateParmRef(NTTP, E->getLocation(), Arg);
1240}
1241
1242const LoopHintAttr *
1243TemplateInstantiator::TransformLoopHintAttr(const LoopHintAttr *LH) {
1244 Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get();
1245
1246 if (TransformedExpr == LH->getValue())
1
Assuming the condition is false
2
Taking false branch
1247 return LH;
1248
1249 // Generate error if there is a problem with the value.
1250 if (getSema().CheckLoopHintExpr(TransformedExpr, LH->getLocation()))
3
Assuming the condition is false
4
Taking false branch
1251 return LH;
1252
1253 // Create new LoopHintValueAttr with integral expression in place of the
1254 // non-type template parameter.
1255 return LoopHintAttr::CreateImplicit(
5
Calling 'LoopHintAttr::CreateImplicit'
1256 getSema().Context, LH->getSemanticSpelling(), LH->getOption(),
1257 LH->getState(), TransformedExpr, LH->getRange());
1258}
1259
1260ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef(
1261 NonTypeTemplateParmDecl *parm,
1262 SourceLocation loc,
1263 TemplateArgument arg) {
1264 ExprResult result;
1265 QualType type;
1266
1267 // The template argument itself might be an expression, in which
1268 // case we just return that expression.
1269 if (arg.getKind() == TemplateArgument::Expression) {
1270 Expr *argExpr = arg.getAsExpr();
1271 result = argExpr;
1272 type = argExpr->getType();
1273
1274 } else if (arg.getKind() == TemplateArgument::Declaration ||
1275 arg.getKind() == TemplateArgument::NullPtr) {
1276 ValueDecl *VD;
1277 if (arg.getKind() == TemplateArgument::Declaration) {
1278 VD = arg.getAsDecl();
1279
1280 // Find the instantiation of the template argument. This is
1281 // required for nested templates.
1282 VD = cast_or_null<ValueDecl>(
1283 getSema().FindInstantiatedDecl(loc, VD, TemplateArgs));
1284 if (!VD)
1285 return ExprError();
1286 } else {
1287 // Propagate NULL template argument.
1288 VD = nullptr;
1289 }
1290
1291 // Derive the type we want the substituted decl to have. This had
1292 // better be non-dependent, or these checks will have serious problems.
1293 if (parm->isExpandedParameterPack()) {
1294 type = parm->getExpansionType(SemaRef.ArgumentPackSubstitutionIndex);
1295 } else if (parm->isParameterPack() &&
1296 isa<PackExpansionType>(parm->getType())) {
1297 type = SemaRef.SubstType(
1298 cast<PackExpansionType>(parm->getType())->getPattern(),
1299 TemplateArgs, loc, parm->getDeclName());
1300 } else {
1301 type = SemaRef.SubstType(VD ? arg.getParamTypeForDecl() : arg.getNullPtrType(),
1302 TemplateArgs, loc, parm->getDeclName());
1303 }
1304 assert(!type.isNull() && "type substitution failed for param type")((!type.isNull() && "type substitution failed for param type"
) ? static_cast<void> (0) : __assert_fail ("!type.isNull() && \"type substitution failed for param type\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1304, __PRETTY_FUNCTION__))
;
1305 assert(!type->isDependentType() && "param type still dependent")((!type->isDependentType() && "param type still dependent"
) ? static_cast<void> (0) : __assert_fail ("!type->isDependentType() && \"param type still dependent\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1305, __PRETTY_FUNCTION__))
;
1306 result = SemaRef.BuildExpressionFromDeclTemplateArgument(arg, type, loc);
1307
1308 if (!result.isInvalid()) type = result.get()->getType();
1309 } else {
1310 result = SemaRef.BuildExpressionFromIntegralTemplateArgument(arg, loc);
1311
1312 // Note that this type can be different from the type of 'result',
1313 // e.g. if it's an enum type.
1314 type = arg.getIntegralType();
1315 }
1316 if (result.isInvalid()) return ExprError();
1317
1318 Expr *resultExpr = result.get();
1319 return new (SemaRef.Context) SubstNonTypeTemplateParmExpr(
1320 type, resultExpr->getValueKind(), loc, parm, resultExpr);
1321}
1322
1323ExprResult
1324TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr(
1325 SubstNonTypeTemplateParmPackExpr *E) {
1326 if (getSema().ArgumentPackSubstitutionIndex == -1) {
1327 // We aren't expanding the parameter pack, so just return ourselves.
1328 return E;
1329 }
1330
1331 TemplateArgument Arg = E->getArgumentPack();
1332 Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1333 return transformNonTypeTemplateParmRef(E->getParameterPack(),
1334 E->getParameterPackLocation(),
1335 Arg);
1336}
1337
1338ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(VarDecl *PD,
1339 SourceLocation Loc) {
1340 DeclarationNameInfo NameInfo(PD->getDeclName(), Loc);
1341 return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD);
1342}
1343
1344ExprResult
1345TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
1346 if (getSema().ArgumentPackSubstitutionIndex != -1) {
1347 // We can expand this parameter pack now.
1348 VarDecl *D = E->getExpansion(getSema().ArgumentPackSubstitutionIndex);
1349 VarDecl *VD = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), D));
1350 if (!VD)
1351 return ExprError();
1352 return RebuildVarDeclRefExpr(VD, E->getExprLoc());
1353 }
1354
1355 QualType T = TransformType(E->getType());
1356 if (T.isNull())
1357 return ExprError();
1358
1359 // Transform each of the parameter expansions into the corresponding
1360 // parameters in the instantiation of the function decl.
1361 SmallVector<VarDecl *, 8> Vars;
1362 Vars.reserve(E->getNumExpansions());
1363 for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end();
1364 I != End; ++I) {
1365 VarDecl *D = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), *I));
1366 if (!D)
1367 return ExprError();
1368 Vars.push_back(D);
1369 }
1370
1371 auto *PackExpr =
1372 FunctionParmPackExpr::Create(getSema().Context, T, E->getParameterPack(),
1373 E->getParameterPackLocation(), Vars);
1374 getSema().MarkFunctionParmPackReferenced(PackExpr);
1375 return PackExpr;
1376}
1377
1378ExprResult
1379TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E,
1380 VarDecl *PD) {
1381 typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
1382 llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found
1383 = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
1384 assert(Found && "no instantiation for parameter pack")((Found && "no instantiation for parameter pack") ? static_cast
<void> (0) : __assert_fail ("Found && \"no instantiation for parameter pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1384, __PRETTY_FUNCTION__))
;
1385
1386 Decl *TransformedDecl;
1387 if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) {
1388 // If this is a reference to a function parameter pack which we can
1389 // substitute but can't yet expand, build a FunctionParmPackExpr for it.
1390 if (getSema().ArgumentPackSubstitutionIndex == -1) {
1391 QualType T = TransformType(E->getType());
1392 if (T.isNull())
1393 return ExprError();
1394 auto *PackExpr = FunctionParmPackExpr::Create(getSema().Context, T, PD,
1395 E->getExprLoc(), *Pack);
1396 getSema().MarkFunctionParmPackReferenced(PackExpr);
1397 return PackExpr;
1398 }
1399
1400 TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex];
1401 } else {
1402 TransformedDecl = Found->get<Decl*>();
1403 }
1404
1405 // We have either an unexpanded pack or a specific expansion.
1406 return RebuildVarDeclRefExpr(cast<VarDecl>(TransformedDecl), E->getExprLoc());
1407}
1408
1409ExprResult
1410TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
1411 NamedDecl *D = E->getDecl();
1412
1413 // Handle references to non-type template parameters and non-type template
1414 // parameter packs.
1415 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) {
1416 if (NTTP->getDepth() < TemplateArgs.getNumLevels())
1417 return TransformTemplateParmRefExpr(E, NTTP);
1418
1419 // We have a non-type template parameter that isn't fully substituted;
1420 // FindInstantiatedDecl will find it in the local instantiation scope.
1421 }
1422
1423 // Handle references to function parameter packs.
1424 if (VarDecl *PD = dyn_cast<VarDecl>(D))
1425 if (PD->isParameterPack())
1426 return TransformFunctionParmPackRefExpr(E, PD);
1427
1428 return TreeTransform<TemplateInstantiator>::TransformDeclRefExpr(E);
1429}
1430
1431ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(
1432 CXXDefaultArgExpr *E) {
1433 assert(!cast<FunctionDecl>(E->getParam()->getDeclContext())->((!cast<FunctionDecl>(E->getParam()->getDeclContext
())-> getDescribedFunctionTemplate() && "Default arg expressions are never formed in dependent cases."
) ? static_cast<void> (0) : __assert_fail ("!cast<FunctionDecl>(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1435, __PRETTY_FUNCTION__))
1434 getDescribedFunctionTemplate() &&((!cast<FunctionDecl>(E->getParam()->getDeclContext
())-> getDescribedFunctionTemplate() && "Default arg expressions are never formed in dependent cases."
) ? static_cast<void> (0) : __assert_fail ("!cast<FunctionDecl>(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1435, __PRETTY_FUNCTION__))
1435 "Default arg expressions are never formed in dependent cases.")((!cast<FunctionDecl>(E->getParam()->getDeclContext
())-> getDescribedFunctionTemplate() && "Default arg expressions are never formed in dependent cases."
) ? static_cast<void> (0) : __assert_fail ("!cast<FunctionDecl>(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1435, __PRETTY_FUNCTION__))
;
1436 return SemaRef.BuildCXXDefaultArgExpr(E->getUsedLocation(),
1437 cast<FunctionDecl>(E->getParam()->getDeclContext()),
1438 E->getParam());
1439}
1440
1441template<typename Fn>
1442QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB,
1443 FunctionProtoTypeLoc TL,
1444 CXXRecordDecl *ThisContext,
1445 Qualifiers ThisTypeQuals,
1446 Fn TransformExceptionSpec) {
1447 // We need a local instantiation scope for this function prototype.
1448 LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
1449 return inherited::TransformFunctionProtoType(
1450 TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec);
1451}
1452
1453ParmVarDecl *
1454TemplateInstantiator::TransformFunctionTypeParam(ParmVarDecl *OldParm,
1455 int indexAdjustment,
1456 Optional<unsigned> NumExpansions,
1457 bool ExpectParameterPack) {
1458 return SemaRef.SubstParmVarDecl(OldParm, TemplateArgs, indexAdjustment,
1459 NumExpansions, ExpectParameterPack);
1460}
1461
1462QualType
1463TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
1464 TemplateTypeParmTypeLoc TL) {
1465 const TemplateTypeParmType *T = TL.getTypePtr();
1466 if (T->getDepth() < TemplateArgs.getNumLevels()) {
1467 // Replace the template type parameter with its corresponding
1468 // template argument.
1469
1470 // If the corresponding template argument is NULL or doesn't exist, it's
1471 // because we are performing instantiation from explicitly-specified
1472 // template arguments in a function template class, but there were some
1473 // arguments left unspecified.
1474 if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) {
1475 TemplateTypeParmTypeLoc NewTL
1476 = TLB.push<TemplateTypeParmTypeLoc>(TL.getType());
1477 NewTL.setNameLoc(TL.getNameLoc());
1478 return TL.getType();
1479 }
1480
1481 TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex());
1482
1483 if (T->isParameterPack()) {
1484 assert(Arg.getKind() == TemplateArgument::Pack &&((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack"
) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1485, __PRETTY_FUNCTION__))
1485 "Missing argument pack")((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack"
) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1485, __PRETTY_FUNCTION__))
;
1486
1487 if (getSema().ArgumentPackSubstitutionIndex == -1) {
1488 // We have the template argument pack, but we're not expanding the
1489 // enclosing pack expansion yet. Just save the template argument
1490 // pack for later substitution.
1491 QualType Result
1492 = getSema().Context.getSubstTemplateTypeParmPackType(T, Arg);
1493 SubstTemplateTypeParmPackTypeLoc NewTL
1494 = TLB.push<SubstTemplateTypeParmPackTypeLoc>(Result);
1495 NewTL.setNameLoc(TL.getNameLoc());
1496 return Result;
1497 }
1498
1499 Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1500 }
1501
1502 assert(Arg.getKind() == TemplateArgument::Type &&((Arg.getKind() == TemplateArgument::Type && "Template argument kind mismatch"
) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Type && \"Template argument kind mismatch\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1503, __PRETTY_FUNCTION__))
1503 "Template argument kind mismatch")((Arg.getKind() == TemplateArgument::Type && "Template argument kind mismatch"
) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Type && \"Template argument kind mismatch\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1503, __PRETTY_FUNCTION__))
;
1504
1505 QualType Replacement = Arg.getAsType();
1506
1507 // TODO: only do this uniquing once, at the start of instantiation.
1508 QualType Result
1509 = getSema().Context.getSubstTemplateTypeParmType(T, Replacement);
1510 SubstTemplateTypeParmTypeLoc NewTL
1511 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
1512 NewTL.setNameLoc(TL.getNameLoc());
1513 return Result;
1514 }
1515
1516 // The template type parameter comes from an inner template (e.g.,
1517 // the template parameter list of a member template inside the
1518 // template we are instantiating). Create a new template type
1519 // parameter with the template "level" reduced by one.
1520 TemplateTypeParmDecl *NewTTPDecl = nullptr;
1521 if (TemplateTypeParmDecl *OldTTPDecl = T->getDecl())
1522 NewTTPDecl = cast_or_null<TemplateTypeParmDecl>(
1523 TransformDecl(TL.getNameLoc(), OldTTPDecl));
1524
1525 QualType Result = getSema().Context.getTemplateTypeParmType(
1526 T->getDepth() - TemplateArgs.getNumSubstitutedLevels(), T->getIndex(),
1527 T->isParameterPack(), NewTTPDecl);
1528 TemplateTypeParmTypeLoc NewTL = TLB.push<TemplateTypeParmTypeLoc>(Result);
1529 NewTL.setNameLoc(TL.getNameLoc());
1530 return Result;
1531}
1532
1533QualType
1534TemplateInstantiator::TransformSubstTemplateTypeParmPackType(
1535 TypeLocBuilder &TLB,
1536 SubstTemplateTypeParmPackTypeLoc TL) {
1537 if (getSema().ArgumentPackSubstitutionIndex == -1) {
1538 // We aren't expanding the parameter pack, so just return ourselves.
1539 SubstTemplateTypeParmPackTypeLoc NewTL
1540 = TLB.push<SubstTemplateTypeParmPackTypeLoc>(TL.getType());
1541 NewTL.setNameLoc(TL.getNameLoc());
1542 return TL.getType();
1543 }
1544
1545 TemplateArgument Arg = TL.getTypePtr()->getArgumentPack();
1546 Arg = getPackSubstitutedTemplateArgument(getSema(), Arg);
1547 QualType Result = Arg.getAsType();
1548
1549 Result = getSema().Context.getSubstTemplateTypeParmType(
1550 TL.getTypePtr()->getReplacedParameter(),
1551 Result);
1552 SubstTemplateTypeParmTypeLoc NewTL
1553 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
1554 NewTL.setNameLoc(TL.getNameLoc());
1555 return Result;
1556}
1557
1558/// Perform substitution on the type T with a given set of template
1559/// arguments.
1560///
1561/// This routine substitutes the given template arguments into the
1562/// type T and produces the instantiated type.
1563///
1564/// \param T the type into which the template arguments will be
1565/// substituted. If this type is not dependent, it will be returned
1566/// immediately.
1567///
1568/// \param Args the template arguments that will be
1569/// substituted for the top-level template parameters within T.
1570///
1571/// \param Loc the location in the source code where this substitution
1572/// is being performed. It will typically be the location of the
1573/// declarator (if we're instantiating the type of some declaration)
1574/// or the location of the type in the source code (if, e.g., we're
1575/// instantiating the type of a cast expression).
1576///
1577/// \param Entity the name of the entity associated with a declaration
1578/// being instantiated (if any). May be empty to indicate that there
1579/// is no such entity (if, e.g., this is a type that occurs as part of
1580/// a cast expression) or that the entity has no name (e.g., an
1581/// unnamed function parameter).
1582///
1583/// \param AllowDeducedTST Whether a DeducedTemplateSpecializationType is
1584/// acceptable as the top level type of the result.
1585///
1586/// \returns If the instantiation succeeds, the instantiated
1587/// type. Otherwise, produces diagnostics and returns a NULL type.
1588TypeSourceInfo *Sema::SubstType(TypeSourceInfo *T,
1589 const MultiLevelTemplateArgumentList &Args,
1590 SourceLocation Loc,
1591 DeclarationName Entity,
1592 bool AllowDeducedTST) {
1593 assert(!CodeSynthesisContexts.empty() &&((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1595, __PRETTY_FUNCTION__))
1594 "Cannot perform an instantiation without some context on the "((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1595, __PRETTY_FUNCTION__))
1595 "instantiation stack")((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1595, __PRETTY_FUNCTION__))
;
1596
1597 if (!T->getType()->isInstantiationDependentType() &&
1598 !T->getType()->isVariablyModifiedType())
1599 return T;
1600
1601 TemplateInstantiator Instantiator(*this, Args, Loc, Entity);
1602 return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(T)
1603 : Instantiator.TransformType(T);
1604}
1605
1606TypeSourceInfo *Sema::SubstType(TypeLoc TL,
1607 const MultiLevelTemplateArgumentList &Args,
1608 SourceLocation Loc,
1609 DeclarationName Entity) {
1610 assert(!CodeSynthesisContexts.empty() &&((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1612, __PRETTY_FUNCTION__))
1611 "Cannot perform an instantiation without some context on the "((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1612, __PRETTY_FUNCTION__))
1612 "instantiation stack")((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1612, __PRETTY_FUNCTION__))
;
1613
1614 if (TL.getType().isNull())
1615 return nullptr;
1616
1617 if (!TL.getType()->isInstantiationDependentType() &&
1618 !TL.getType()->isVariablyModifiedType()) {
1619 // FIXME: Make a copy of the TypeLoc data here, so that we can
1620 // return a new TypeSourceInfo. Inefficient!
1621 TypeLocBuilder TLB;
1622 TLB.pushFullCopy(TL);
1623 return TLB.getTypeSourceInfo(Context, TL.getType());
1624 }
1625
1626 TemplateInstantiator Instantiator(*this, Args, Loc, Entity);
1627 TypeLocBuilder TLB;
1628 TLB.reserve(TL.getFullDataSize());
1629 QualType Result = Instantiator.TransformType(TLB, TL);
1630 if (Result.isNull())
1631 return nullptr;
1632
1633 return TLB.getTypeSourceInfo(Context, Result);
1634}
1635
1636/// Deprecated form of the above.
1637QualType Sema::SubstType(QualType T,
1638 const MultiLevelTemplateArgumentList &TemplateArgs,
1639 SourceLocation Loc, DeclarationName Entity) {
1640 assert(!CodeSynthesisContexts.empty() &&((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1642, __PRETTY_FUNCTION__))
1641 "Cannot perform an instantiation without some context on the "((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1642, __PRETTY_FUNCTION__))
1642 "instantiation stack")((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1642, __PRETTY_FUNCTION__))
;
1643
1644 // If T is not a dependent type or a variably-modified type, there
1645 // is nothing to do.
1646 if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType())
1647 return T;
1648
1649 TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
1650 return Instantiator.TransformType(T);
1651}
1652
1653static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) {
1654 if (T->getType()->isInstantiationDependentType() ||
1655 T->getType()->isVariablyModifiedType())
1656 return true;
1657
1658 TypeLoc TL = T->getTypeLoc().IgnoreParens();
1659 if (!TL.getAs<FunctionProtoTypeLoc>())
1660 return false;
1661
1662 FunctionProtoTypeLoc FP = TL.castAs<FunctionProtoTypeLoc>();
1663 for (ParmVarDecl *P : FP.getParams()) {
1664 // This must be synthesized from a typedef.
1665 if (!P) continue;
1666
1667 // If there are any parameters, a new TypeSourceInfo that refers to the
1668 // instantiated parameters must be built.
1669 return true;
1670 }
1671
1672 return false;
1673}
1674
1675/// A form of SubstType intended specifically for instantiating the
1676/// type of a FunctionDecl. Its purpose is solely to force the
1677/// instantiation of default-argument expressions and to avoid
1678/// instantiating an exception-specification.
1679TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T,
1680 const MultiLevelTemplateArgumentList &Args,
1681 SourceLocation Loc,
1682 DeclarationName Entity,
1683 CXXRecordDecl *ThisContext,
1684 Qualifiers ThisTypeQuals) {
1685 assert(!CodeSynthesisContexts.empty() &&((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1687, __PRETTY_FUNCTION__))
1686 "Cannot perform an instantiation without some context on the "((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1687, __PRETTY_FUNCTION__))
1687 "instantiation stack")((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1687, __PRETTY_FUNCTION__))
;
1688
1689 if (!NeedsInstantiationAsFunctionType(T))
1690 return T;
1691
1692 TemplateInstantiator Instantiator(*this, Args, Loc, Entity);
1693
1694 TypeLocBuilder TLB;
1695
1696 TypeLoc TL = T->getTypeLoc();
1697 TLB.reserve(TL.getFullDataSize());
1698
1699 QualType Result;
1700
1701 if (FunctionProtoTypeLoc Proto =
1702 TL.IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
1703 // Instantiate the type, other than its exception specification. The
1704 // exception specification is instantiated in InitFunctionInstantiation
1705 // once we've built the FunctionDecl.
1706 // FIXME: Set the exception specification to EST_Uninstantiated here,
1707 // instead of rebuilding the function type again later.
1708 Result = Instantiator.TransformFunctionProtoType(
1709 TLB, Proto, ThisContext, ThisTypeQuals,
1710 [](FunctionProtoType::ExceptionSpecInfo &ESI,
1711 bool &Changed) { return false; });
1712 } else {
1713 Result = Instantiator.TransformType(TLB, TL);
1714 }
1715 if (Result.isNull())
1716 return nullptr;
1717
1718 return TLB.getTypeSourceInfo(Context, Result);
1719}
1720
1721bool Sema::SubstExceptionSpec(SourceLocation Loc,
1722 FunctionProtoType::ExceptionSpecInfo &ESI,
1723 SmallVectorImpl<QualType> &ExceptionStorage,
1724 const MultiLevelTemplateArgumentList &Args) {
1725 assert(ESI.Type != EST_Uninstantiated)((ESI.Type != EST_Uninstantiated) ? static_cast<void> (
0) : __assert_fail ("ESI.Type != EST_Uninstantiated", "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1725, __PRETTY_FUNCTION__))
;
1726
1727 bool Changed = false;
1728 TemplateInstantiator Instantiator(*this, Args, Loc, DeclarationName());
1729 return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage,
1730 Changed);
1731}
1732
1733void Sema::SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto,
1734 const MultiLevelTemplateArgumentList &Args) {
1735 FunctionProtoType::ExceptionSpecInfo ESI =
1736 Proto->getExtProtoInfo().ExceptionSpec;
1737
1738 SmallVector<QualType, 4> ExceptionStorage;
1739 if (SubstExceptionSpec(New->getTypeSourceInfo()->getTypeLoc().getEndLoc(),
1740 ESI, ExceptionStorage, Args))
1741 // On error, recover by dropping the exception specification.
1742 ESI.Type = EST_None;
1743
1744 UpdateExceptionSpec(New, ESI);
1745}
1746
1747ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
1748 const MultiLevelTemplateArgumentList &TemplateArgs,
1749 int indexAdjustment,
1750 Optional<unsigned> NumExpansions,
1751 bool ExpectParameterPack) {
1752 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
1753 TypeSourceInfo *NewDI = nullptr;
1754
1755 TypeLoc OldTL = OldDI->getTypeLoc();
1756 if (PackExpansionTypeLoc ExpansionTL = OldTL.getAs<PackExpansionTypeLoc>()) {
1757
1758 // We have a function parameter pack. Substitute into the pattern of the
1759 // expansion.
1760 NewDI = SubstType(ExpansionTL.getPatternLoc(), TemplateArgs,
1761 OldParm->getLocation(), OldParm->getDeclName());
1762 if (!NewDI)
1763 return nullptr;
1764
1765 if (NewDI->getType()->containsUnexpandedParameterPack()) {
1766 // We still have unexpanded parameter packs, which means that
1767 // our function parameter is still a function parameter pack.
1768 // Therefore, make its type a pack expansion type.
1769 NewDI = CheckPackExpansion(NewDI, ExpansionTL.getEllipsisLoc(),
1770 NumExpansions);
1771 } else if (ExpectParameterPack) {
1772 // We expected to get a parameter pack but didn't (because the type
1773 // itself is not a pack expansion type), so complain. This can occur when
1774 // the substitution goes through an alias template that "loses" the
1775 // pack expansion.
1776 Diag(OldParm->getLocation(),
1777 diag::err_function_parameter_pack_without_parameter_packs)
1778 << NewDI->getType();
1779 return nullptr;
1780 }
1781 } else {
1782 NewDI = SubstType(OldDI, TemplateArgs, OldParm->getLocation(),
1783 OldParm->getDeclName());
1784 }
1785
1786 if (!NewDI)
1787 return nullptr;
1788
1789 if (NewDI->getType()->isVoidType()) {
1790 Diag(OldParm->getLocation(), diag::err_param_with_void_type);
1791 return nullptr;
1792 }
1793
1794 ParmVarDecl *NewParm = CheckParameter(Context.getTranslationUnitDecl(),
1795 OldParm->getInnerLocStart(),
1796 OldParm->getLocation(),
1797 OldParm->getIdentifier(),
1798 NewDI->getType(), NewDI,
1799 OldParm->getStorageClass());
1800 if (!NewParm)
1801 return nullptr;
1802
1803 // Mark the (new) default argument as uninstantiated (if any).
1804 if (OldParm->hasUninstantiatedDefaultArg()) {
1805 Expr *Arg = OldParm->getUninstantiatedDefaultArg();
1806 NewParm->setUninstantiatedDefaultArg(Arg);
1807 } else if (OldParm->hasUnparsedDefaultArg()) {
1808 NewParm->setUnparsedDefaultArg();
1809 UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm);
1810 } else if (Expr *Arg = OldParm->getDefaultArg()) {
1811 FunctionDecl *OwningFunc = cast<FunctionDecl>(OldParm->getDeclContext());
1812 if (OwningFunc->isLexicallyWithinFunctionOrMethod()) {
1813 // Instantiate default arguments for methods of local classes (DR1484)
1814 // and non-defining declarations.
1815 Sema::ContextRAII SavedContext(*this, OwningFunc);
1816 LocalInstantiationScope Local(*this, true);
1817 ExprResult NewArg = SubstExpr(Arg, TemplateArgs);
1818 if (NewArg.isUsable()) {
1819 // It would be nice if we still had this.
1820 SourceLocation EqualLoc = NewArg.get()->getBeginLoc();
1821 SetParamDefaultArgument(NewParm, NewArg.get(), EqualLoc);
1822 }
1823 } else {
1824 // FIXME: if we non-lazily instantiated non-dependent default args for
1825 // non-dependent parameter types we could remove a bunch of duplicate
1826 // conversion warnings for such arguments.
1827 NewParm->setUninstantiatedDefaultArg(Arg);
1828 }
1829 }
1830
1831 NewParm->setHasInheritedDefaultArg(OldParm->hasInheritedDefaultArg());
1832
1833 if (OldParm->isParameterPack() && !NewParm->isParameterPack()) {
1834 // Add the new parameter to the instantiated parameter pack.
1835 CurrentInstantiationScope->InstantiatedLocalPackArg(OldParm, NewParm);
1836 } else {
1837 // Introduce an Old -> New mapping
1838 CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm);
1839 }
1840
1841 // FIXME: OldParm may come from a FunctionProtoType, in which case CurContext
1842 // can be anything, is this right ?
1843 NewParm->setDeclContext(CurContext);
1844
1845 NewParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
1846 OldParm->getFunctionScopeIndex() + indexAdjustment);
1847
1848 InstantiateAttrs(TemplateArgs, OldParm, NewParm);
1849
1850 return NewParm;
1851}
1852
1853/// Substitute the given template arguments into the given set of
1854/// parameters, producing the set of parameter types that would be generated
1855/// from such a substitution.
1856bool Sema::SubstParmTypes(
1857 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
1858 const FunctionProtoType::ExtParameterInfo *ExtParamInfos,
1859 const MultiLevelTemplateArgumentList &TemplateArgs,
1860 SmallVectorImpl<QualType> &ParamTypes,
1861 SmallVectorImpl<ParmVarDecl *> *OutParams,
1862 ExtParameterInfoBuilder &ParamInfos) {
1863 assert(!CodeSynthesisContexts.empty() &&((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1865, __PRETTY_FUNCTION__))
1864 "Cannot perform an instantiation without some context on the "((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1865, __PRETTY_FUNCTION__))
1865 "instantiation stack")((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the "
"instantiation stack") ? static_cast<void> (0) : __assert_fail
("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 1865, __PRETTY_FUNCTION__))
;
1866
1867 TemplateInstantiator Instantiator(*this, TemplateArgs, Loc,
1868 DeclarationName());
1869 return Instantiator.TransformFunctionTypeParams(
1870 Loc, Params, nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos);
1871}
1872
1873/// Perform substitution on the base class specifiers of the
1874/// given class template specialization.
1875///
1876/// Produces a diagnostic and returns true on error, returns false and
1877/// attaches the instantiated base classes to the class template
1878/// specialization if successful.
1879bool
1880Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation,
1881 CXXRecordDecl *Pattern,
1882 const MultiLevelTemplateArgumentList &TemplateArgs) {
1883 bool Invalid = false;
1884 SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases;
1885 for (const auto &Base : Pattern->bases()) {
1886 if (!Base.getType()->isDependentType()) {
1887 if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl()) {
1888 if (RD->isInvalidDecl())
1889 Instantiation->setInvalidDecl();
1890 }
1891 InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(Base));
1892 continue;
1893 }
1894
1895 SourceLocation EllipsisLoc;
1896 TypeSourceInfo *BaseTypeLoc;
1897 if (Base.isPackExpansion()) {
1898 // This is a pack expansion. See whether we should expand it now, or
1899 // wait until later.
1900 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
1901 collectUnexpandedParameterPacks(Base.getTypeSourceInfo()->getTypeLoc(),
1902 Unexpanded);
1903 bool ShouldExpand = false;
1904 bool RetainExpansion = false;
1905 Optional<unsigned> NumExpansions;
1906 if (CheckParameterPacksForExpansion(Base.getEllipsisLoc(),
1907 Base.getSourceRange(),
1908 Unexpanded,
1909 TemplateArgs, ShouldExpand,
1910 RetainExpansion,
1911 NumExpansions)) {
1912 Invalid = true;
1913 continue;
1914 }
1915
1916 // If we should expand this pack expansion now, do so.
1917 if (ShouldExpand) {
1918 for (unsigned I = 0; I != *NumExpansions; ++I) {
1919 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I);
1920
1921 TypeSourceInfo *BaseTypeLoc = SubstType(Base.getTypeSourceInfo(),
1922 TemplateArgs,
1923 Base.getSourceRange().getBegin(),
1924 DeclarationName());
1925 if (!BaseTypeLoc) {
1926 Invalid = true;
1927 continue;
1928 }
1929
1930 if (CXXBaseSpecifier *InstantiatedBase
1931 = CheckBaseSpecifier(Instantiation,
1932 Base.getSourceRange(),
1933 Base.isVirtual(),
1934 Base.getAccessSpecifierAsWritten(),
1935 BaseTypeLoc,
1936 SourceLocation()))
1937 InstantiatedBases.push_back(InstantiatedBase);
1938 else
1939 Invalid = true;
1940 }
1941
1942 continue;
1943 }
1944
1945 // The resulting base specifier will (still) be a pack expansion.
1946 EllipsisLoc = Base.getEllipsisLoc();
1947 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1);
1948 BaseTypeLoc = SubstType(Base.getTypeSourceInfo(),
1949 TemplateArgs,
1950 Base.getSourceRange().getBegin(),
1951 DeclarationName());
1952 } else {
1953 BaseTypeLoc = SubstType(Base.getTypeSourceInfo(),
1954 TemplateArgs,
1955 Base.getSourceRange().getBegin(),
1956 DeclarationName());
1957 }
1958
1959 if (!BaseTypeLoc) {
1960 Invalid = true;
1961 continue;
1962 }
1963
1964 if (CXXBaseSpecifier *InstantiatedBase
1965 = CheckBaseSpecifier(Instantiation,
1966 Base.getSourceRange(),
1967 Base.isVirtual(),
1968 Base.getAccessSpecifierAsWritten(),
1969 BaseTypeLoc,
1970 EllipsisLoc))
1971 InstantiatedBases.push_back(InstantiatedBase);
1972 else
1973 Invalid = true;
1974 }
1975
1976 if (!Invalid && AttachBaseSpecifiers(Instantiation, InstantiatedBases))
1977 Invalid = true;
1978
1979 return Invalid;
1980}
1981
1982// Defined via #include from SemaTemplateInstantiateDecl.cpp
1983namespace clang {
1984 namespace sema {
1985 Attr *instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S,
1986 const MultiLevelTemplateArgumentList &TemplateArgs);
1987 Attr *instantiateTemplateAttributeForDecl(
1988 const Attr *At, ASTContext &C, Sema &S,
1989 const MultiLevelTemplateArgumentList &TemplateArgs);
1990 }
1991}
1992
1993/// Instantiate the definition of a class from a given pattern.
1994///
1995/// \param PointOfInstantiation The point of instantiation within the
1996/// source code.
1997///
1998/// \param Instantiation is the declaration whose definition is being
1999/// instantiated. This will be either a class template specialization
2000/// or a member class of a class template specialization.
2001///
2002/// \param Pattern is the pattern from which the instantiation
2003/// occurs. This will be either the declaration of a class template or
2004/// the declaration of a member class of a class template.
2005///
2006/// \param TemplateArgs The template arguments to be substituted into
2007/// the pattern.
2008///
2009/// \param TSK the kind of implicit or explicit instantiation to perform.
2010///
2011/// \param Complain whether to complain if the class cannot be instantiated due
2012/// to the lack of a definition.
2013///
2014/// \returns true if an error occurred, false otherwise.
2015bool
2016Sema::InstantiateClass(SourceLocation PointOfInstantiation,
2017 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
2018 const MultiLevelTemplateArgumentList &TemplateArgs,
2019 TemplateSpecializationKind TSK,
2020 bool Complain) {
2021 CXXRecordDecl *PatternDef
2022 = cast_or_null<CXXRecordDecl>(Pattern->getDefinition());
2023 if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation,
2024 Instantiation->getInstantiatedFromMemberClass(),
2025 Pattern, PatternDef, TSK, Complain))
2026 return true;
2027
2028 llvm::TimeTraceScope TimeScope("InstantiateClass", [&]() {
2029 std::string Name;
2030 llvm::raw_string_ostream OS(Name);
2031 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
2032 /*Qualified=*/true);
2033 return Name;
2034 });
2035
2036 Pattern = PatternDef;
2037
2038 // Record the point of instantiation.
2039 if (MemberSpecializationInfo *MSInfo
2040 = Instantiation->getMemberSpecializationInfo()) {
2041 MSInfo->setTemplateSpecializationKind(TSK);
2042 MSInfo->setPointOfInstantiation(PointOfInstantiation);
2043 } else if (ClassTemplateSpecializationDecl *Spec
2044 = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) {
2045 Spec->setTemplateSpecializationKind(TSK);
2046 Spec->setPointOfInstantiation(PointOfInstantiation);
2047 }
2048
2049 InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
2050 if (Inst.isInvalid())
2051 return true;
2052 assert(!Inst.isAlreadyInstantiating() && "should have been caught by caller")((!Inst.isAlreadyInstantiating() && "should have been caught by caller"
) ? static_cast<void> (0) : __assert_fail ("!Inst.isAlreadyInstantiating() && \"should have been caught by caller\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2052, __PRETTY_FUNCTION__))
;
2053 PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
2054 "instantiating class definition");
2055
2056 // Enter the scope of this instantiation. We don't use
2057 // PushDeclContext because we don't have a scope.
2058 ContextRAII SavedContext(*this, Instantiation);
2059 EnterExpressionEvaluationContext EvalContext(
2060 *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
2061
2062 // If this is an instantiation of a local class, merge this local
2063 // instantiation scope with the enclosing scope. Otherwise, every
2064 // instantiation of a class has its own local instantiation scope.
2065 bool MergeWithParentScope = !Instantiation->isDefinedOutsideFunctionOrMethod();
2066 LocalInstantiationScope Scope(*this, MergeWithParentScope);
2067
2068 // Some class state isn't processed immediately but delayed till class
2069 // instantiation completes. We may not be ready to handle any delayed state
2070 // already on the stack as it might correspond to a different class, so save
2071 // it now and put it back later.
2072 SavePendingParsedClassStateRAII SavedPendingParsedClassState(*this);
2073
2074 // Pull attributes from the pattern onto the instantiation.
2075 InstantiateAttrs(TemplateArgs, Pattern, Instantiation);
2076
2077 // Start the definition of this instantiation.
2078 Instantiation->startDefinition();
2079
2080 // The instantiation is visible here, even if it was first declared in an
2081 // unimported module.
2082 Instantiation->setVisibleDespiteOwningModule();
2083
2084 // FIXME: This loses the as-written tag kind for an explicit instantiation.
2085 Instantiation->setTagKind(Pattern->getTagKind());
2086
2087 // Do substitution on the base class specifiers.
2088 if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs))
2089 Instantiation->setInvalidDecl();
2090
2091 TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs);
2092 SmallVector<Decl*, 4> Fields;
2093 // Delay instantiation of late parsed attributes.
2094 LateInstantiatedAttrVec LateAttrs;
2095 Instantiator.enableLateAttributeInstantiation(&LateAttrs);
2096
2097 bool MightHaveConstexprVirtualFunctions = false;
2098 for (auto *Member : Pattern->decls()) {
2099 // Don't instantiate members not belonging in this semantic context.
2100 // e.g. for:
2101 // @code
2102 // template <int i> class A {
2103 // class B *g;
2104 // };
2105 // @endcode
2106 // 'class B' has the template as lexical context but semantically it is
2107 // introduced in namespace scope.
2108 if (Member->getDeclContext() != Pattern)
2109 continue;
2110
2111 // BlockDecls can appear in a default-member-initializer. They must be the
2112 // child of a BlockExpr, so we only know how to instantiate them from there.
2113 if (isa<BlockDecl>(Member))
2114 continue;
2115
2116 if (Member->isInvalidDecl()) {
2117 Instantiation->setInvalidDecl();
2118 continue;
2119 }
2120
2121 Decl *NewMember = Instantiator.Visit(Member);
2122 if (NewMember) {
2123 if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) {
2124 Fields.push_back(Field);
2125 } else if (EnumDecl *Enum = dyn_cast<EnumDecl>(NewMember)) {
2126 // C++11 [temp.inst]p1: The implicit instantiation of a class template
2127 // specialization causes the implicit instantiation of the definitions
2128 // of unscoped member enumerations.
2129 // Record a point of instantiation for this implicit instantiation.
2130 if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() &&
2131 Enum->isCompleteDefinition()) {
2132 MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo();
2133 assert(MSInfo && "no spec info for member enum specialization")((MSInfo && "no spec info for member enum specialization"
) ? static_cast<void> (0) : __assert_fail ("MSInfo && \"no spec info for member enum specialization\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2133, __PRETTY_FUNCTION__))
;
2134 MSInfo->setTemplateSpecializationKind(TSK_ImplicitInstantiation);
2135 MSInfo->setPointOfInstantiation(PointOfInstantiation);
2136 }
2137 } else if (StaticAssertDecl *SA = dyn_cast<StaticAssertDecl>(NewMember)) {
2138 if (SA->isFailed()) {
2139 // A static_assert failed. Bail out; instantiating this
2140 // class is probably not meaningful.
2141 Instantiation->setInvalidDecl();
2142 break;
2143 }
2144 } else if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) {
2145 if (MD->isConstexpr() && !MD->getFriendObjectKind() &&
2146 (MD->isVirtualAsWritten() || Instantiation->getNumBases()))
2147 MightHaveConstexprVirtualFunctions = true;
2148 }
2149
2150 if (NewMember->isInvalidDecl())
2151 Instantiation->setInvalidDecl();
2152 } else {
2153 // FIXME: Eventually, a NULL return will mean that one of the
2154 // instantiations was a semantic disaster, and we'll want to mark the
2155 // declaration invalid.
2156 // For now, we expect to skip some members that we can't yet handle.
2157 }
2158 }
2159
2160 // Finish checking fields.
2161 ActOnFields(nullptr, Instantiation->getLocation(), Instantiation, Fields,
2162 SourceLocation(), SourceLocation(), ParsedAttributesView());
2163 CheckCompletedCXXClass(Instantiation);
2164
2165 // Default arguments are parsed, if not instantiated. We can go instantiate
2166 // default arg exprs for default constructors if necessary now.
2167 ActOnFinishCXXNonNestedClass(Instantiation);
2168
2169 // Instantiate late parsed attributes, and attach them to their decls.
2170 // See Sema::InstantiateAttrs
2171 for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
2172 E = LateAttrs.end(); I != E; ++I) {
2173 assert(CurrentInstantiationScope == Instantiator.getStartingScope())((CurrentInstantiationScope == Instantiator.getStartingScope(
)) ? static_cast<void> (0) : __assert_fail ("CurrentInstantiationScope == Instantiator.getStartingScope()"
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2173, __PRETTY_FUNCTION__))
;
2174 CurrentInstantiationScope = I->Scope;
2175
2176 // Allow 'this' within late-parsed attributes.
2177 NamedDecl *ND = dyn_cast<NamedDecl>(I->NewDecl);
2178 CXXRecordDecl *ThisContext =
2179 dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext());
2180 CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(),
2181 ND && ND->isCXXInstanceMember());
2182
2183 Attr *NewAttr =
2184 instantiateTemplateAttribute(I->TmplAttr, Context, *this, TemplateArgs);
2185 I->NewDecl->addAttr(NewAttr);
2186 LocalInstantiationScope::deleteScopes(I->Scope,
2187 Instantiator.getStartingScope());
2188 }
2189 Instantiator.disableLateAttributeInstantiation();
2190 LateAttrs.clear();
2191
2192 ActOnFinishDelayedMemberInitializers(Instantiation);
2193
2194 // FIXME: We should do something similar for explicit instantiations so they
2195 // end up in the right module.
2196 if (TSK == TSK_ImplicitInstantiation) {
2197 Instantiation->setLocation(Pattern->getLocation());
2198 Instantiation->setLocStart(Pattern->getInnerLocStart());
2199 Instantiation->setBraceRange(Pattern->getBraceRange());
2200 }
2201
2202 if (!Instantiation->isInvalidDecl()) {
2203 // Perform any dependent diagnostics from the pattern.
2204 PerformDependentDiagnostics(Pattern, TemplateArgs);
2205
2206 // Instantiate any out-of-line class template partial
2207 // specializations now.
2208 for (TemplateDeclInstantiator::delayed_partial_spec_iterator
2209 P = Instantiator.delayed_partial_spec_begin(),
2210 PEnd = Instantiator.delayed_partial_spec_end();
2211 P != PEnd; ++P) {
2212 if (!Instantiator.InstantiateClassTemplatePartialSpecialization(
2213 P->first, P->second)) {
2214 Instantiation->setInvalidDecl();
2215 break;
2216 }
2217 }
2218
2219 // Instantiate any out-of-line variable template partial
2220 // specializations now.
2221 for (TemplateDeclInstantiator::delayed_var_partial_spec_iterator
2222 P = Instantiator.delayed_var_partial_spec_begin(),
2223 PEnd = Instantiator.delayed_var_partial_spec_end();
2224 P != PEnd; ++P) {
2225 if (!Instantiator.InstantiateVarTemplatePartialSpecialization(
2226 P->first, P->second)) {
2227 Instantiation->setInvalidDecl();
2228 break;
2229 }
2230 }
2231 }
2232
2233 // Exit the scope of this instantiation.
2234 SavedContext.pop();
2235
2236 if (!Instantiation->isInvalidDecl()) {
2237 Consumer.HandleTagDeclDefinition(Instantiation);
2238
2239 // Always emit the vtable for an explicit instantiation definition
2240 // of a polymorphic class template specialization. Otherwise, eagerly
2241 // instantiate only constexpr virtual functions in preparation for their use
2242 // in constant evaluation.
2243 if (TSK == TSK_ExplicitInstantiationDefinition)
2244 MarkVTableUsed(PointOfInstantiation, Instantiation, true);
2245 else if (MightHaveConstexprVirtualFunctions)
2246 MarkVirtualMembersReferenced(PointOfInstantiation, Instantiation,
2247 /*ConstexprOnly*/ true);
2248 }
2249
2250 return Instantiation->isInvalidDecl();
2251}
2252
2253/// Instantiate the definition of an enum from a given pattern.
2254///
2255/// \param PointOfInstantiation The point of instantiation within the
2256/// source code.
2257/// \param Instantiation is the declaration whose definition is being
2258/// instantiated. This will be a member enumeration of a class
2259/// temploid specialization, or a local enumeration within a
2260/// function temploid specialization.
2261/// \param Pattern The templated declaration from which the instantiation
2262/// occurs.
2263/// \param TemplateArgs The template arguments to be substituted into
2264/// the pattern.
2265/// \param TSK The kind of implicit or explicit instantiation to perform.
2266///
2267/// \return \c true if an error occurred, \c false otherwise.
2268bool Sema::InstantiateEnum(SourceLocation PointOfInstantiation,
2269 EnumDecl *Instantiation, EnumDecl *Pattern,
2270 const MultiLevelTemplateArgumentList &TemplateArgs,
2271 TemplateSpecializationKind TSK) {
2272 EnumDecl *PatternDef = Pattern->getDefinition();
2273 if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation,
2274 Instantiation->getInstantiatedFromMemberEnum(),
2275 Pattern, PatternDef, TSK,/*Complain*/true))
2276 return true;
2277 Pattern = PatternDef;
2278
2279 // Record the point of instantiation.
2280 if (MemberSpecializationInfo *MSInfo
2281 = Instantiation->getMemberSpecializationInfo()) {
2282 MSInfo->setTemplateSpecializationKind(TSK);
2283 MSInfo->setPointOfInstantiation(PointOfInstantiation);
2284 }
2285
2286 InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
2287 if (Inst.isInvalid())
2288 return true;
2289 if (Inst.isAlreadyInstantiating())
2290 return false;
2291 PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
2292 "instantiating enum definition");
2293
2294 // The instantiation is visible here, even if it was first declared in an
2295 // unimported module.
2296 Instantiation->setVisibleDespiteOwningModule();
2297
2298 // Enter the scope of this instantiation. We don't use
2299 // PushDeclContext because we don't have a scope.
2300 ContextRAII SavedContext(*this, Instantiation);
2301 EnterExpressionEvaluationContext EvalContext(
2302 *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
2303
2304 LocalInstantiationScope Scope(*this, /*MergeWithParentScope*/true);
2305
2306 // Pull attributes from the pattern onto the instantiation.
2307 InstantiateAttrs(TemplateArgs, Pattern, Instantiation);
2308
2309 TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs);
2310 Instantiator.InstantiateEnumDefinition(Instantiation, Pattern);
2311
2312 // Exit the scope of this instantiation.
2313 SavedContext.pop();
2314
2315 return Instantiation->isInvalidDecl();
2316}
2317
2318
2319/// Instantiate the definition of a field from the given pattern.
2320///
2321/// \param PointOfInstantiation The point of instantiation within the
2322/// source code.
2323/// \param Instantiation is the declaration whose definition is being
2324/// instantiated. This will be a class of a class temploid
2325/// specialization, or a local enumeration within a function temploid
2326/// specialization.
2327/// \param Pattern The templated declaration from which the instantiation
2328/// occurs.
2329/// \param TemplateArgs The template arguments to be substituted into
2330/// the pattern.
2331///
2332/// \return \c true if an error occurred, \c false otherwise.
2333bool Sema::InstantiateInClassInitializer(
2334 SourceLocation PointOfInstantiation, FieldDecl *Instantiation,
2335 FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs) {
2336 // If there is no initializer, we don't need to do anything.
2337 if (!Pattern->hasInClassInitializer())
2338 return false;
2339
2340 assert(Instantiation->getInClassInitStyle() ==((Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle
() && "pattern and instantiation disagree about init style"
) ? static_cast<void> (0) : __assert_fail ("Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle() && \"pattern and instantiation disagree about init style\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2342, __PRETTY_FUNCTION__))
2341 Pattern->getInClassInitStyle() &&((Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle
() && "pattern and instantiation disagree about init style"
) ? static_cast<void> (0) : __assert_fail ("Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle() && \"pattern and instantiation disagree about init style\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2342, __PRETTY_FUNCTION__))
2342 "pattern and instantiation disagree about init style")((Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle
() && "pattern and instantiation disagree about init style"
) ? static_cast<void> (0) : __assert_fail ("Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle() && \"pattern and instantiation disagree about init style\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2342, __PRETTY_FUNCTION__))
;
2343
2344 // Error out if we haven't parsed the initializer of the pattern yet because
2345 // we are waiting for the closing brace of the outer class.
2346 Expr *OldInit = Pattern->getInClassInitializer();
2347 if (!OldInit) {
2348 RecordDecl *PatternRD = Pattern->getParent();
2349 RecordDecl *OutermostClass = PatternRD->getOuterLexicalRecordContext();
2350 Diag(PointOfInstantiation,
2351 diag::err_in_class_initializer_not_yet_parsed)
2352 << OutermostClass << Pattern;
2353 Diag(Pattern->getEndLoc(), diag::note_in_class_initializer_not_yet_parsed);
2354 Instantiation->setInvalidDecl();
2355 return true;
2356 }
2357
2358 InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation);
2359 if (Inst.isInvalid())
2360 return true;
2361 if (Inst.isAlreadyInstantiating()) {
2362 // Error out if we hit an instantiation cycle for this initializer.
2363 Diag(PointOfInstantiation, diag::err_in_class_initializer_cycle)
2364 << Instantiation;
2365 return true;
2366 }
2367 PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(),
2368 "instantiating default member init");
2369
2370 // Enter the scope of this instantiation. We don't use PushDeclContext because
2371 // we don't have a scope.
2372 ContextRAII SavedContext(*this, Instantiation->getParent());
2373 EnterExpressionEvaluationContext EvalContext(
2374 *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
2375
2376 LocalInstantiationScope Scope(*this, true);
2377
2378 // Instantiate the initializer.
2379 ActOnStartCXXInClassMemberInitializer();
2380 CXXThisScopeRAII ThisScope(*this, Instantiation->getParent(), Qualifiers());
2381
2382 ExprResult NewInit = SubstInitializer(OldInit, TemplateArgs,
2383 /*CXXDirectInit=*/false);
2384 Expr *Init = NewInit.get();
2385 assert((!Init || !isa<ParenListExpr>(Init)) && "call-style init in class")(((!Init || !isa<ParenListExpr>(Init)) && "call-style init in class"
) ? static_cast<void> (0) : __assert_fail ("(!Init || !isa<ParenListExpr>(Init)) && \"call-style init in class\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2385, __PRETTY_FUNCTION__))
;
2386 ActOnFinishCXXInClassMemberInitializer(
2387 Instantiation, Init ? Init->getBeginLoc() : SourceLocation(), Init);
2388
2389 if (auto *L = getASTMutationListener())
2390 L->DefaultMemberInitializerInstantiated(Instantiation);
2391
2392 // Return true if the in-class initializer is still missing.
2393 return !Instantiation->getInClassInitializer();
2394}
2395
2396namespace {
2397 /// A partial specialization whose template arguments have matched
2398 /// a given template-id.
2399 struct PartialSpecMatchResult {
2400 ClassTemplatePartialSpecializationDecl *Partial;
2401 TemplateArgumentList *Args;
2402 };
2403}
2404
2405bool Sema::usesPartialOrExplicitSpecialization(
2406 SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec) {
2407 if (ClassTemplateSpec->getTemplateSpecializationKind() ==
2408 TSK_ExplicitSpecialization)
2409 return true;
2410
2411 SmallVector<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs;
2412 ClassTemplateSpec->getSpecializedTemplate()
2413 ->getPartialSpecializations(PartialSpecs);
2414 for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
2415 TemplateDeductionInfo Info(Loc);
2416 if (!DeduceTemplateArguments(PartialSpecs[I],
2417 ClassTemplateSpec->getTemplateArgs(), Info))
2418 return true;
2419 }
2420
2421 return false;
2422}
2423
2424/// Get the instantiation pattern to use to instantiate the definition of a
2425/// given ClassTemplateSpecializationDecl (either the pattern of the primary
2426/// template or of a partial specialization).
2427static CXXRecordDecl *
2428getPatternForClassTemplateSpecialization(
2429 Sema &S, SourceLocation PointOfInstantiation,
2430 ClassTemplateSpecializationDecl *ClassTemplateSpec,
2431 TemplateSpecializationKind TSK, bool Complain) {
2432 Sema::InstantiatingTemplate Inst(S, PointOfInstantiation, ClassTemplateSpec);
2433 if (Inst.isInvalid() || Inst.isAlreadyInstantiating())
2434 return nullptr;
2435
2436 llvm::PointerUnion<ClassTemplateDecl *,
2437 ClassTemplatePartialSpecializationDecl *>
2438 Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial();
2439 if (!Specialized.is<ClassTemplatePartialSpecializationDecl *>()) {
2440 // Find best matching specialization.
2441 ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
2442
2443 // C++ [temp.class.spec.match]p1:
2444 // When a class template is used in a context that requires an
2445 // instantiation of the class, it is necessary to determine
2446 // whether the instantiation is to be generated using the primary
2447 // template or one of the partial specializations. This is done by
2448 // matching the template arguments of the class template
2449 // specialization with the template argument lists of the partial
2450 // specializations.
2451 typedef PartialSpecMatchResult MatchResult;
2452 SmallVector<MatchResult, 4> Matched;
2453 SmallVector<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs;
2454 Template->getPartialSpecializations(PartialSpecs);
2455 TemplateSpecCandidateSet FailedCandidates(PointOfInstantiation);
2456 for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) {
2457 ClassTemplatePartialSpecializationDecl *Partial = PartialSpecs[I];
2458 TemplateDeductionInfo Info(FailedCandidates.getLocation());
2459 if (Sema::TemplateDeductionResult Result = S.DeduceTemplateArguments(
2460 Partial, ClassTemplateSpec->getTemplateArgs(), Info)) {
2461 // Store the failed-deduction information for use in diagnostics, later.
2462 // TODO: Actually use the failed-deduction info?
2463 FailedCandidates.addCandidate().set(
2464 DeclAccessPair::make(Template, AS_public), Partial,
2465 MakeDeductionFailureInfo(S.Context, Result, Info));
2466 (void)Result;
2467 } else {
2468 Matched.push_back(PartialSpecMatchResult());
2469 Matched.back().Partial = Partial;
2470 Matched.back().Args = Info.take();
2471 }
2472 }
2473
2474 // If we're dealing with a member template where the template parameters
2475 // have been instantiated, this provides the original template parameters
2476 // from which the member template's parameters were instantiated.
2477
2478 if (Matched.size() >= 1) {
2479 SmallVectorImpl<MatchResult>::iterator Best = Matched.begin();
2480 if (Matched.size() == 1) {
2481 // -- If exactly one matching specialization is found, the
2482 // instantiation is generated from that specialization.
2483 // We don't need to do anything for this.
2484 } else {
2485 // -- If more than one matching specialization is found, the
2486 // partial order rules (14.5.4.2) are used to determine
2487 // whether one of the specializations is more specialized
2488 // than the others. If none of the specializations is more
2489 // specialized than all of the other matching
2490 // specializations, then the use of the class template is
2491 // ambiguous and the program is ill-formed.
2492 for (SmallVectorImpl<MatchResult>::iterator P = Best + 1,
2493 PEnd = Matched.end();
2494 P != PEnd; ++P) {
2495 if (S.getMoreSpecializedPartialSpecialization(
2496 P->Partial, Best->Partial, PointOfInstantiation) ==
2497 P->Partial)
2498 Best = P;
2499 }
2500
2501 // Determine if the best partial specialization is more specialized than
2502 // the others.
2503 bool Ambiguous = false;
2504 for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(),
2505 PEnd = Matched.end();
2506 P != PEnd; ++P) {
2507 if (P != Best && S.getMoreSpecializedPartialSpecialization(
2508 P->Partial, Best->Partial,
2509 PointOfInstantiation) != Best->Partial) {
2510 Ambiguous = true;
2511 break;
2512 }
2513 }
2514
2515 if (Ambiguous) {
2516 // Partial ordering did not produce a clear winner. Complain.
2517 Inst.Clear();
2518 ClassTemplateSpec->setInvalidDecl();
2519 S.Diag(PointOfInstantiation,
2520 diag::err_partial_spec_ordering_ambiguous)
2521 << ClassTemplateSpec;
2522
2523 // Print the matching partial specializations.
2524 for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(),
2525 PEnd = Matched.end();
2526 P != PEnd; ++P)
2527 S.Diag(P->Partial->getLocation(), diag::note_partial_spec_match)
2528 << S.getTemplateArgumentBindingsText(
2529 P->Partial->getTemplateParameters(), *P->Args);
2530
2531 return nullptr;
2532 }
2533 }
2534
2535 ClassTemplateSpec->setInstantiationOf(Best->Partial, Best->Args);
2536 } else {
2537 // -- If no matches are found, the instantiation is generated
2538 // from the primary template.
2539 }
2540 }
2541
2542 CXXRecordDecl *Pattern = nullptr;
2543 Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial();
2544 if (auto *PartialSpec =
2545 Specialized.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) {
2546 // Instantiate using the best class template partial specialization.
2547 while (PartialSpec->getInstantiatedFromMember()) {
2548 // If we've found an explicit specialization of this class template,
2549 // stop here and use that as the pattern.
2550 if (PartialSpec->isMemberSpecialization())
2551 break;
2552
2553 PartialSpec = PartialSpec->getInstantiatedFromMember();
2554 }
2555 Pattern = PartialSpec;
2556 } else {
2557 ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate();
2558 while (Template->getInstantiatedFromMemberTemplate()) {
2559 // If we've found an explicit specialization of this class template,
2560 // stop here and use that as the pattern.
2561 if (Template->isMemberSpecialization())
2562 break;
2563
2564 Template = Template->getInstantiatedFromMemberTemplate();
2565 }
2566 Pattern = Template->getTemplatedDecl();
2567 }
2568
2569 return Pattern;
2570}
2571
2572bool Sema::InstantiateClassTemplateSpecialization(
2573 SourceLocation PointOfInstantiation,
2574 ClassTemplateSpecializationDecl *ClassTemplateSpec,
2575 TemplateSpecializationKind TSK, bool Complain) {
2576 // Perform the actual instantiation on the canonical declaration.
2577 ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>(
2578 ClassTemplateSpec->getCanonicalDecl());
2579 if (ClassTemplateSpec->isInvalidDecl())
2580 return true;
2581
2582 CXXRecordDecl *Pattern = getPatternForClassTemplateSpecialization(
2583 *this, PointOfInstantiation, ClassTemplateSpec, TSK, Complain);
2584 if (!Pattern)
2585 return true;
2586
2587 return InstantiateClass(PointOfInstantiation, ClassTemplateSpec, Pattern,
2588 getTemplateInstantiationArgs(ClassTemplateSpec), TSK,
2589 Complain);
2590}
2591
2592/// Instantiates the definitions of all of the member
2593/// of the given class, which is an instantiation of a class template
2594/// or a member class of a template.
2595void
2596Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation,
2597 CXXRecordDecl *Instantiation,
2598 const MultiLevelTemplateArgumentList &TemplateArgs,
2599 TemplateSpecializationKind TSK) {
2600 // FIXME: We need to notify the ASTMutationListener that we did all of these
2601 // things, in case we have an explicit instantiation definition in a PCM, a
2602 // module, or preamble, and the declaration is in an imported AST.
2603 assert((((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration
|| (TSK == TSK_ImplicitInstantiation && Instantiation
->isLocalClass())) && "Unexpected template specialization kind!"
) ? static_cast<void> (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2607, __PRETTY_FUNCTION__))
2604 (TSK == TSK_ExplicitInstantiationDefinition ||(((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration
|| (TSK == TSK_ImplicitInstantiation && Instantiation
->isLocalClass())) && "Unexpected template specialization kind!"
) ? static_cast<void> (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2607, __PRETTY_FUNCTION__))
2605 TSK == TSK_ExplicitInstantiationDeclaration ||(((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration
|| (TSK == TSK_ImplicitInstantiation && Instantiation
->isLocalClass())) && "Unexpected template specialization kind!"
) ? static_cast<void> (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2607, __PRETTY_FUNCTION__))
2606 (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) &&(((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration
|| (TSK == TSK_ImplicitInstantiation && Instantiation
->isLocalClass())) && "Unexpected template specialization kind!"
) ? static_cast<void> (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2607, __PRETTY_FUNCTION__))
2607 "Unexpected template specialization kind!")(((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration
|| (TSK == TSK_ImplicitInstantiation && Instantiation
->isLocalClass())) && "Unexpected template specialization kind!"
) ? static_cast<void> (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2607, __PRETTY_FUNCTION__))
;
2608 for (auto *D : Instantiation->decls()) {
2609 bool SuppressNew = false;
2610 if (auto *Function = dyn_cast<FunctionDecl>(D)) {
2611 if (FunctionDecl *Pattern =
2612 Function->getInstantiatedFromMemberFunction()) {
2613
2614 if (Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
2615 continue;
2616
2617 MemberSpecializationInfo *MSInfo =
2618 Function->getMemberSpecializationInfo();
2619 assert(MSInfo && "No member specialization information?")((MSInfo && "No member specialization information?") ?
static_cast<void> (0) : __assert_fail ("MSInfo && \"No member specialization information?\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2619, __PRETTY_FUNCTION__))
;
2620 if (MSInfo->getTemplateSpecializationKind()
2621 == TSK_ExplicitSpecialization)
2622 continue;
2623
2624 if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK,
2625 Function,
2626 MSInfo->getTemplateSpecializationKind(),
2627 MSInfo->getPointOfInstantiation(),
2628 SuppressNew) ||
2629 SuppressNew)
2630 continue;
2631
2632 // C++11 [temp.explicit]p8:
2633 // An explicit instantiation definition that names a class template
2634 // specialization explicitly instantiates the class template
2635 // specialization and is only an explicit instantiation definition
2636 // of members whose definition is visible at the point of
2637 // instantiation.
2638 if (TSK == TSK_ExplicitInstantiationDefinition && !Pattern->isDefined())
2639 continue;
2640
2641 Function->setTemplateSpecializationKind(TSK, PointOfInstantiation);
2642
2643 if (Function->isDefined()) {
2644 // Let the ASTConsumer know that this function has been explicitly
2645 // instantiated now, and its linkage might have changed.
2646 Consumer.HandleTopLevelDecl(DeclGroupRef(Function));
2647 } else if (TSK == TSK_ExplicitInstantiationDefinition) {
2648 InstantiateFunctionDefinition(PointOfInstantiation, Function);
2649 } else if (TSK == TSK_ImplicitInstantiation) {
2650 PendingLocalImplicitInstantiations.push_back(
2651 std::make_pair(Function, PointOfInstantiation));
2652 }
2653 }
2654 } else if (auto *Var = dyn_cast<VarDecl>(D)) {
2655 if (isa<VarTemplateSpecializationDecl>(Var))
2656 continue;
2657
2658 if (Var->isStaticDataMember()) {
2659 if (Var->hasAttr<ExcludeFromExplicitInstantiationAttr>())
2660 continue;
2661
2662 MemberSpecializationInfo *MSInfo = Var->getMemberSpecializationInfo();
2663 assert(MSInfo && "No member specialization information?")((MSInfo && "No member specialization information?") ?
static_cast<void> (0) : __assert_fail ("MSInfo && \"No member specialization information?\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2663, __PRETTY_FUNCTION__))
;
2664 if (MSInfo->getTemplateSpecializationKind()
2665 == TSK_ExplicitSpecialization)
2666 continue;
2667
2668 if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK,
2669 Var,
2670 MSInfo->getTemplateSpecializationKind(),
2671 MSInfo->getPointOfInstantiation(),
2672 SuppressNew) ||
2673 SuppressNew)
2674 continue;
2675
2676 if (TSK == TSK_ExplicitInstantiationDefinition) {
2677 // C++0x [temp.explicit]p8:
2678 // An explicit instantiation definition that names a class template
2679 // specialization explicitly instantiates the class template
2680 // specialization and is only an explicit instantiation definition
2681 // of members whose definition is visible at the point of
2682 // instantiation.
2683 if (!Var->getInstantiatedFromStaticDataMember()->getDefinition())
2684 continue;
2685
2686 Var->setTemplateSpecializationKind(TSK, PointOfInstantiation);
2687 InstantiateVariableDefinition(PointOfInstantiation, Var);
2688 } else {
2689 Var->setTemplateSpecializationKind(TSK, PointOfInstantiation);
2690 }
2691 }
2692 } else if (auto *Record = dyn_cast<CXXRecordDecl>(D)) {
2693 if (Record->hasAttr<ExcludeFromExplicitInstantiationAttr>())
2694 continue;
2695
2696 // Always skip the injected-class-name, along with any
2697 // redeclarations of nested classes, since both would cause us
2698 // to try to instantiate the members of a class twice.
2699 // Skip closure types; they'll get instantiated when we instantiate
2700 // the corresponding lambda-expression.
2701 if (Record->isInjectedClassName() || Record->getPreviousDecl() ||
2702 Record->isLambda())
2703 continue;
2704
2705 MemberSpecializationInfo *MSInfo = Record->getMemberSpecializationInfo();
2706 assert(MSInfo && "No member specialization information?")((MSInfo && "No member specialization information?") ?
static_cast<void> (0) : __assert_fail ("MSInfo && \"No member specialization information?\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2706, __PRETTY_FUNCTION__))
;
2707
2708 if (MSInfo->getTemplateSpecializationKind()
2709 == TSK_ExplicitSpecialization)
2710 continue;
2711
2712 if (Context.getTargetInfo().getTriple().isOSWindows() &&
2713 TSK == TSK_ExplicitInstantiationDeclaration) {
2714 // On Windows, explicit instantiation decl of the outer class doesn't
2715 // affect the inner class. Typically extern template declarations are
2716 // used in combination with dll import/export annotations, but those
2717 // are not propagated from the outer class templates to inner classes.
2718 // Therefore, do not instantiate inner classes on this platform, so
2719 // that users don't end up with undefined symbols during linking.
2720 continue;
2721 }
2722
2723 if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK,
2724 Record,
2725 MSInfo->getTemplateSpecializationKind(),
2726 MSInfo->getPointOfInstantiation(),
2727 SuppressNew) ||
2728 SuppressNew)
2729 continue;
2730
2731 CXXRecordDecl *Pattern = Record->getInstantiatedFromMemberClass();
2732 assert(Pattern && "Missing instantiated-from-template information")((Pattern && "Missing instantiated-from-template information"
) ? static_cast<void> (0) : __assert_fail ("Pattern && \"Missing instantiated-from-template information\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2732, __PRETTY_FUNCTION__))
;
2733
2734 if (!Record->getDefinition()) {
2735 if (!Pattern->getDefinition()) {
2736 // C++0x [temp.explicit]p8:
2737 // An explicit instantiation definition that names a class template
2738 // specialization explicitly instantiates the class template
2739 // specialization and is only an explicit instantiation definition
2740 // of members whose definition is visible at the point of
2741 // instantiation.
2742 if (TSK == TSK_ExplicitInstantiationDeclaration) {
2743 MSInfo->setTemplateSpecializationKind(TSK);
2744 MSInfo->setPointOfInstantiation(PointOfInstantiation);
2745 }
2746
2747 continue;
2748 }
2749
2750 InstantiateClass(PointOfInstantiation, Record, Pattern,
2751 TemplateArgs,
2752 TSK);
2753 } else {
2754 if (TSK == TSK_ExplicitInstantiationDefinition &&
2755 Record->getTemplateSpecializationKind() ==
2756 TSK_ExplicitInstantiationDeclaration) {
2757 Record->setTemplateSpecializationKind(TSK);
2758 MarkVTableUsed(PointOfInstantiation, Record, true);
2759 }
2760 }
2761
2762 Pattern = cast_or_null<CXXRecordDecl>(Record->getDefinition());
2763 if (Pattern)
2764 InstantiateClassMembers(PointOfInstantiation, Pattern, TemplateArgs,
2765 TSK);
2766 } else if (auto *Enum = dyn_cast<EnumDecl>(D)) {
2767 MemberSpecializationInfo *MSInfo = Enum->getMemberSpecializationInfo();
2768 assert(MSInfo && "No member specialization information?")((MSInfo && "No member specialization information?") ?
static_cast<void> (0) : __assert_fail ("MSInfo && \"No member specialization information?\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2768, __PRETTY_FUNCTION__))
;
2769
2770 if (MSInfo->getTemplateSpecializationKind()
2771 == TSK_ExplicitSpecialization)
2772 continue;
2773
2774 if (CheckSpecializationInstantiationRedecl(
2775 PointOfInstantiation, TSK, Enum,
2776 MSInfo->getTemplateSpecializationKind(),
2777 MSInfo->getPointOfInstantiation(), SuppressNew) ||
2778 SuppressNew)
2779 continue;
2780
2781 if (Enum->getDefinition())
2782 continue;
2783
2784 EnumDecl *Pattern = Enum->getTemplateInstantiationPattern();
2785 assert(Pattern && "Missing instantiated-from-template information")((Pattern && "Missing instantiated-from-template information"
) ? static_cast<void> (0) : __assert_fail ("Pattern && \"Missing instantiated-from-template information\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2785, __PRETTY_FUNCTION__))
;
2786
2787 if (TSK == TSK_ExplicitInstantiationDefinition) {
2788 if (!Pattern->getDefinition())
2789 continue;
2790
2791 InstantiateEnum(PointOfInstantiation, Enum, Pattern, TemplateArgs, TSK);
2792 } else {
2793 MSInfo->setTemplateSpecializationKind(TSK);
2794 MSInfo->setPointOfInstantiation(PointOfInstantiation);
2795 }
2796 } else if (auto *Field = dyn_cast<FieldDecl>(D)) {
2797 // No need to instantiate in-class initializers during explicit
2798 // instantiation.
2799 if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) {
2800 CXXRecordDecl *ClassPattern =
2801 Instantiation->getTemplateInstantiationPattern();
2802 DeclContext::lookup_result Lookup =
2803 ClassPattern->lookup(Field->getDeclName());
2804 FieldDecl *Pattern = cast<FieldDecl>(Lookup.front());
2805 InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern,
2806 TemplateArgs);
2807 }
2808 }
2809 }
2810}
2811
2812/// Instantiate the definitions of all of the members of the
2813/// given class template specialization, which was named as part of an
2814/// explicit instantiation.
2815void
2816Sema::InstantiateClassTemplateSpecializationMembers(
2817 SourceLocation PointOfInstantiation,
2818 ClassTemplateSpecializationDecl *ClassTemplateSpec,
2819 TemplateSpecializationKind TSK) {
2820 // C++0x [temp.explicit]p7:
2821 // An explicit instantiation that names a class template
2822 // specialization is an explicit instantion of the same kind
2823 // (declaration or definition) of each of its members (not
2824 // including members inherited from base classes) that has not
2825 // been previously explicitly specialized in the translation unit
2826 // containing the explicit instantiation, except as described
2827 // below.
2828 InstantiateClassMembers(PointOfInstantiation, ClassTemplateSpec,
2829 getTemplateInstantiationArgs(ClassTemplateSpec),
2830 TSK);
2831}
2832
2833StmtResult
2834Sema::SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs) {
2835 if (!S)
2836 return S;
2837
2838 TemplateInstantiator Instantiator(*this, TemplateArgs,
2839 SourceLocation(),
2840 DeclarationName());
2841 return Instantiator.TransformStmt(S);
2842}
2843
2844ExprResult
2845Sema::SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs) {
2846 if (!E)
2847 return E;
2848
2849 TemplateInstantiator Instantiator(*this, TemplateArgs,
2850 SourceLocation(),
2851 DeclarationName());
2852 return Instantiator.TransformExpr(E);
2853}
2854
2855ExprResult Sema::SubstInitializer(Expr *Init,
2856 const MultiLevelTemplateArgumentList &TemplateArgs,
2857 bool CXXDirectInit) {
2858 TemplateInstantiator Instantiator(*this, TemplateArgs,
2859 SourceLocation(),
2860 DeclarationName());
2861 return Instantiator.TransformInitializer(Init, CXXDirectInit);
2862}
2863
2864bool Sema::SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall,
2865 const MultiLevelTemplateArgumentList &TemplateArgs,
2866 SmallVectorImpl<Expr *> &Outputs) {
2867 if (Exprs.empty())
2868 return false;
2869
2870 TemplateInstantiator Instantiator(*this, TemplateArgs,
2871 SourceLocation(),
2872 DeclarationName());
2873 return Instantiator.TransformExprs(Exprs.data(), Exprs.size(),
2874 IsCall, Outputs);
2875}
2876
2877NestedNameSpecifierLoc
2878Sema::SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
2879 const MultiLevelTemplateArgumentList &TemplateArgs) {
2880 if (!NNS)
2881 return NestedNameSpecifierLoc();
2882
2883 TemplateInstantiator Instantiator(*this, TemplateArgs, NNS.getBeginLoc(),
2884 DeclarationName());
2885 return Instantiator.TransformNestedNameSpecifierLoc(NNS);
2886}
2887
2888/// Do template substitution on declaration name info.
2889DeclarationNameInfo
2890Sema::SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo,
2891 const MultiLevelTemplateArgumentList &TemplateArgs) {
2892 TemplateInstantiator Instantiator(*this, TemplateArgs, NameInfo.getLoc(),
2893 NameInfo.getName());
2894 return Instantiator.TransformDeclarationNameInfo(NameInfo);
2895}
2896
2897TemplateName
2898Sema::SubstTemplateName(NestedNameSpecifierLoc QualifierLoc,
2899 TemplateName Name, SourceLocation Loc,
2900 const MultiLevelTemplateArgumentList &TemplateArgs) {
2901 TemplateInstantiator Instantiator(*this, TemplateArgs, Loc,
2902 DeclarationName());
2903 CXXScopeSpec SS;
2904 SS.Adopt(QualifierLoc);
2905 return Instantiator.TransformTemplateName(SS, Name, Loc);
2906}
2907
2908bool Sema::Subst(const TemplateArgumentLoc *Args, unsigned NumArgs,
2909 TemplateArgumentListInfo &Result,
2910 const MultiLevelTemplateArgumentList &TemplateArgs) {
2911 TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(),
2912 DeclarationName());
2913
2914 return Instantiator.TransformTemplateArguments(Args, NumArgs, Result);
2915}
2916
2917static const Decl *getCanonicalParmVarDecl(const Decl *D) {
2918 // When storing ParmVarDecls in the local instantiation scope, we always
2919 // want to use the ParmVarDecl from the canonical function declaration,
2920 // since the map is then valid for any redeclaration or definition of that
2921 // function.
2922 if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) {
2923 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
2924 unsigned i = PV->getFunctionScopeIndex();
2925 // This parameter might be from a freestanding function type within the
2926 // function and isn't necessarily referring to one of FD's parameters.
2927 if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
2928 return FD->getCanonicalDecl()->getParamDecl(i);
2929 }
2930 }
2931 return D;
2932}
2933
2934
2935llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> *
2936LocalInstantiationScope::findInstantiationOf(const Decl *D) {
2937 D = getCanonicalParmVarDecl(D);
2938 for (LocalInstantiationScope *Current = this; Current;
2939 Current = Current->Outer) {
2940
2941 // Check if we found something within this scope.
2942 const Decl *CheckD = D;
2943 do {
2944 LocalDeclsMap::iterator Found = Current->LocalDecls.find(CheckD);
2945 if (Found != Current->LocalDecls.end())
2946 return &Found->second;
2947
2948 // If this is a tag declaration, it's possible that we need to look for
2949 // a previous declaration.
2950 if (const TagDecl *Tag = dyn_cast<TagDecl>(CheckD))
2951 CheckD = Tag->getPreviousDecl();
2952 else
2953 CheckD = nullptr;
2954 } while (CheckD);
2955
2956 // If we aren't combined with our outer scope, we're done.
2957 if (!Current->CombineWithOuterScope)
2958 break;
2959 }
2960
2961 // If we're performing a partial substitution during template argument
2962 // deduction, we may not have values for template parameters yet.
2963 if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
2964 isa<TemplateTemplateParmDecl>(D))
2965 return nullptr;
2966
2967 // Local types referenced prior to definition may require instantiation.
2968 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D))
2969 if (RD->isLocalClass())
2970 return nullptr;
2971
2972 // Enumeration types referenced prior to definition may appear as a result of
2973 // error recovery.
2974 if (isa<EnumDecl>(D))
2975 return nullptr;
2976
2977 // If we didn't find the decl, then we either have a sema bug, or we have a
2978 // forward reference to a label declaration. Return null to indicate that
2979 // we have an uninstantiated label.
2980 assert(isa<LabelDecl>(D) && "declaration not instantiated in this scope")((isa<LabelDecl>(D) && "declaration not instantiated in this scope"
) ? static_cast<void> (0) : __assert_fail ("isa<LabelDecl>(D) && \"declaration not instantiated in this scope\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2980, __PRETTY_FUNCTION__))
;
2981 return nullptr;
2982}
2983
2984void LocalInstantiationScope::InstantiatedLocal(const Decl *D, Decl *Inst) {
2985 D = getCanonicalParmVarDecl(D);
2986 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
2987 if (Stored.isNull()) {
2988#ifndef NDEBUG
2989 // It should not be present in any surrounding scope either.
2990 LocalInstantiationScope *Current = this;
2991 while (Current->CombineWithOuterScope && Current->Outer) {
2992 Current = Current->Outer;
2993 assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&((Current->LocalDecls.find(D) == Current->LocalDecls.end
() && "Instantiated local in inner and outer scopes")
? static_cast<void> (0) : __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Instantiated local in inner and outer scopes\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2994, __PRETTY_FUNCTION__))
2994 "Instantiated local in inner and outer scopes")((Current->LocalDecls.find(D) == Current->LocalDecls.end
() && "Instantiated local in inner and outer scopes")
? static_cast<void> (0) : __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Instantiated local in inner and outer scopes\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 2994, __PRETTY_FUNCTION__))
;
2995 }
2996#endif
2997 Stored = Inst;
2998 } else if (DeclArgumentPack *Pack = Stored.dyn_cast<DeclArgumentPack *>()) {
2999 Pack->push_back(cast<VarDecl>(Inst));
3000 } else {
3001 assert(Stored.get<Decl *>() == Inst && "Already instantiated this local")((Stored.get<Decl *>() == Inst && "Already instantiated this local"
) ? static_cast<void> (0) : __assert_fail ("Stored.get<Decl *>() == Inst && \"Already instantiated this local\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 3001, __PRETTY_FUNCTION__))
;
3002 }
3003}
3004
3005void LocalInstantiationScope::InstantiatedLocalPackArg(const Decl *D,
3006 VarDecl *Inst) {
3007 D = getCanonicalParmVarDecl(D);
3008 DeclArgumentPack *Pack = LocalDecls[D].get<DeclArgumentPack *>();
3009 Pack->push_back(Inst);
3010}
3011
3012void LocalInstantiationScope::MakeInstantiatedLocalArgPack(const Decl *D) {
3013#ifndef NDEBUG
3014 // This should be the first time we've been told about this decl.
3015 for (LocalInstantiationScope *Current = this;
3016 Current && Current->CombineWithOuterScope; Current = Current->Outer)
3017 assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&((Current->LocalDecls.find(D) == Current->LocalDecls.end
() && "Creating local pack after instantiation of local"
) ? static_cast<void> (0) : __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Creating local pack after instantiation of local\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 3018, __PRETTY_FUNCTION__))
3018 "Creating local pack after instantiation of local")((Current->LocalDecls.find(D) == Current->LocalDecls.end
() && "Creating local pack after instantiation of local"
) ? static_cast<void> (0) : __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Creating local pack after instantiation of local\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 3018, __PRETTY_FUNCTION__))
;
3019#endif
3020
3021 D = getCanonicalParmVarDecl(D);
3022 llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D];
3023 DeclArgumentPack *Pack = new DeclArgumentPack;
3024 Stored = Pack;
3025 ArgumentPacks.push_back(Pack);
3026}
3027
3028void LocalInstantiationScope::SetPartiallySubstitutedPack(NamedDecl *Pack,
3029 const TemplateArgument *ExplicitArgs,
3030 unsigned NumExplicitArgs) {
3031 assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&(((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack
) && "Already have a partially-substituted pack") ? static_cast
<void> (0) : __assert_fail ("(!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) && \"Already have a partially-substituted pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 3032, __PRETTY_FUNCTION__))
3032 "Already have a partially-substituted pack")(((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack
) && "Already have a partially-substituted pack") ? static_cast
<void> (0) : __assert_fail ("(!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) && \"Already have a partially-substituted pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 3032, __PRETTY_FUNCTION__))
;
3033 assert((!PartiallySubstitutedPack(((!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack
== NumExplicitArgs) && "Wrong number of arguments in partially-substituted pack"
) ? static_cast<void> (0) : __assert_fail ("(!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && \"Wrong number of arguments in partially-substituted pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 3035, __PRETTY_FUNCTION__))
3034 || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&(((!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack
== NumExplicitArgs) && "Wrong number of arguments in partially-substituted pack"
) ? static_cast<void> (0) : __assert_fail ("(!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && \"Wrong number of arguments in partially-substituted pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 3035, __PRETTY_FUNCTION__))
3035 "Wrong number of arguments in partially-substituted pack")(((!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack
== NumExplicitArgs) && "Wrong number of arguments in partially-substituted pack"
) ? static_cast<void> (0) : __assert_fail ("(!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && \"Wrong number of arguments in partially-substituted pack\""
, "/build/llvm-toolchain-snapshot-9~svn362543/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp"
, 3035, __PRETTY_FUNCTION__))
;
3036 PartiallySubstitutedPack = Pack;
3037 ArgsInPartiallySubstitutedPack = ExplicitArgs;
3038 NumArgsInPartiallySubstitutedPack = NumExplicitArgs;
3039}
3040
3041NamedDecl *LocalInstantiationScope::getPartiallySubstitutedPack(
3042 const TemplateArgument **ExplicitArgs,
3043 unsigned *NumExplicitArgs) const {
3044 if (ExplicitArgs)
3045 *ExplicitArgs = nullptr;
3046 if (NumExplicitArgs)
3047 *NumExplicitArgs = 0;
3048
3049 for (const LocalInstantiationScope *Current = this; Current;
3050 Current = Current->Outer) {
3051 if (Current->PartiallySubstitutedPack) {
3052 if (ExplicitArgs)
3053 *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack;
3054 if (NumExplicitArgs)
3055 *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack;
3056
3057 return Current->PartiallySubstitutedPack;
3058 }
3059
3060 if (!Current->CombineWithOuterScope)
3061 break;
3062 }
3063
3064 return nullptr;
3065}

/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc

1/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2|* *|
3|* Attribute classes' definitions *|
4|* *|
5|* Automatically generated file, do not edit! *|
6|* *|
7\*===----------------------------------------------------------------------===*/
8
9#ifndef LLVM_CLANG_ATTR_CLASSES_INC
10#define LLVM_CLANG_ATTR_CLASSES_INC
11
12class AArch64VectorPcsAttr : public InheritableAttr {
13public:
14 static AArch64VectorPcsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
15 auto *A = new (Ctx) AArch64VectorPcsAttr(Loc, Ctx, 0);
16 A->setImplicit(true);
17 return A;
18 }
19
20 AArch64VectorPcsAttr(SourceRange R, ASTContext &Ctx
21 , unsigned SI
22 )
23 : InheritableAttr(attr::AArch64VectorPcs, R, SI, false, false)
24 {
25 }
26
27 AArch64VectorPcsAttr *clone(ASTContext &C) const;
28 void printPretty(raw_ostream &OS,
29 const PrintingPolicy &Policy) const;
30 const char *getSpelling() const;
31
32
33 static bool classof(const Attr *A) { return A->getKind() == attr::AArch64VectorPcs; }
34};
35
36class AMDGPUFlatWorkGroupSizeAttr : public InheritableAttr {
37Expr * min;
38
39Expr * max;
40
41public:
42 static AMDGPUFlatWorkGroupSizeAttr *CreateImplicit(ASTContext &Ctx, Expr * Min, Expr * Max, SourceRange Loc = SourceRange()) {
43 auto *A = new (Ctx) AMDGPUFlatWorkGroupSizeAttr(Loc, Ctx, Min, Max, 0);
44 A->setImplicit(true);
45 return A;
46 }
47
48 AMDGPUFlatWorkGroupSizeAttr(SourceRange R, ASTContext &Ctx
49 , Expr * Min
50 , Expr * Max
51 , unsigned SI
52 )
53 : InheritableAttr(attr::AMDGPUFlatWorkGroupSize, R, SI, false, false)
54 , min(Min)
55 , max(Max)
56 {
57 }
58
59 AMDGPUFlatWorkGroupSizeAttr *clone(ASTContext &C) const;
60 void printPretty(raw_ostream &OS,
61 const PrintingPolicy &Policy) const;
62 const char *getSpelling() const;
63 Expr * getMin() const {
64 return min;
65 }
66
67 Expr * getMax() const {
68 return max;
69 }
70
71
72
73 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUFlatWorkGroupSize; }
74};
75
76class AMDGPUNumSGPRAttr : public InheritableAttr {
77unsigned numSGPR;
78
79public:
80 static AMDGPUNumSGPRAttr *CreateImplicit(ASTContext &Ctx, unsigned NumSGPR, SourceRange Loc = SourceRange()) {
81 auto *A = new (Ctx) AMDGPUNumSGPRAttr(Loc, Ctx, NumSGPR, 0);
82 A->setImplicit(true);
83 return A;
84 }
85
86 AMDGPUNumSGPRAttr(SourceRange R, ASTContext &Ctx
87 , unsigned NumSGPR
88 , unsigned SI
89 )
90 : InheritableAttr(attr::AMDGPUNumSGPR, R, SI, false, false)
91 , numSGPR(NumSGPR)
92 {
93 }
94
95 AMDGPUNumSGPRAttr *clone(ASTContext &C) const;
96 void printPretty(raw_ostream &OS,
97 const PrintingPolicy &Policy) const;
98 const char *getSpelling() const;
99 unsigned getNumSGPR() const {
100 return numSGPR;
101 }
102
103
104
105 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUNumSGPR; }
106};
107
108class AMDGPUNumVGPRAttr : public InheritableAttr {
109unsigned numVGPR;
110
111public:
112 static AMDGPUNumVGPRAttr *CreateImplicit(ASTContext &Ctx, unsigned NumVGPR, SourceRange Loc = SourceRange()) {
113 auto *A = new (Ctx) AMDGPUNumVGPRAttr(Loc, Ctx, NumVGPR, 0);
114 A->setImplicit(true);
115 return A;
116 }
117
118 AMDGPUNumVGPRAttr(SourceRange R, ASTContext &Ctx
119 , unsigned NumVGPR
120 , unsigned SI
121 )
122 : InheritableAttr(attr::AMDGPUNumVGPR, R, SI, false, false)
123 , numVGPR(NumVGPR)
124 {
125 }
126
127 AMDGPUNumVGPRAttr *clone(ASTContext &C) const;
128 void printPretty(raw_ostream &OS,
129 const PrintingPolicy &Policy) const;
130 const char *getSpelling() const;
131 unsigned getNumVGPR() const {
132 return numVGPR;
133 }
134
135
136
137 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUNumVGPR; }
138};
139
140class AMDGPUWavesPerEUAttr : public InheritableAttr {
141Expr * min;
142
143Expr * max;
144
145public:
146 static AMDGPUWavesPerEUAttr *CreateImplicit(ASTContext &Ctx, Expr * Min, Expr * Max, SourceRange Loc = SourceRange()) {
147 auto *A = new (Ctx) AMDGPUWavesPerEUAttr(Loc, Ctx, Min, Max, 0);
148 A->setImplicit(true);
149 return A;
150 }
151
152 AMDGPUWavesPerEUAttr(SourceRange R, ASTContext &Ctx
153 , Expr * Min
154 , Expr * Max
155 , unsigned SI
156 )
157 : InheritableAttr(attr::AMDGPUWavesPerEU, R, SI, false, false)
158 , min(Min)
159 , max(Max)
160 {
161 }
162
163 AMDGPUWavesPerEUAttr(SourceRange R, ASTContext &Ctx
164 , Expr * Min
165 , unsigned SI
166 )
167 : InheritableAttr(attr::AMDGPUWavesPerEU, R, SI, false, false)
168 , min(Min)
169 , max()
170 {
171 }
172
173 AMDGPUWavesPerEUAttr *clone(ASTContext &C) const;
174 void printPretty(raw_ostream &OS,
175 const PrintingPolicy &Policy) const;
176 const char *getSpelling() const;
177 Expr * getMin() const {
178 return min;
179 }
180
181 Expr * getMax() const {
182 return max;
183 }
184
185
186
187 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUWavesPerEU; }
188};
189
190class ARMInterruptAttr : public InheritableAttr {
191public:
192 enum InterruptType {
193 IRQ,
194 FIQ,
195 SWI,
196 ABORT,
197 UNDEF,
198 Generic
199 };
200private:
201 InterruptType interrupt;
202
203public:
204 static ARMInterruptAttr *CreateImplicit(ASTContext &Ctx, InterruptType Interrupt, SourceRange Loc = SourceRange()) {
205 auto *A = new (Ctx) ARMInterruptAttr(Loc, Ctx, Interrupt, 0);
206 A->setImplicit(true);
207 return A;
208 }
209
210 ARMInterruptAttr(SourceRange R, ASTContext &Ctx
211 , InterruptType Interrupt
212 , unsigned SI
213 )
214 : InheritableAttr(attr::ARMInterrupt, R, SI, false, false)
215 , interrupt(Interrupt)
216 {
217 }
218
219 ARMInterruptAttr(SourceRange R, ASTContext &Ctx
220 , unsigned SI
221 )
222 : InheritableAttr(attr::ARMInterrupt, R, SI, false, false)
223 , interrupt(InterruptType(0))
224 {
225 }
226
227 ARMInterruptAttr *clone(ASTContext &C) const;
228 void printPretty(raw_ostream &OS,
229 const PrintingPolicy &Policy) const;
230 const char *getSpelling() const;
231 InterruptType getInterrupt() const {
232 return interrupt;
233 }
234
235 static bool ConvertStrToInterruptType(StringRef Val, InterruptType &Out) {
236 Optional<InterruptType> R = llvm::StringSwitch<Optional<InterruptType>>(Val)
237 .Case("IRQ", ARMInterruptAttr::IRQ)
238 .Case("FIQ", ARMInterruptAttr::FIQ)
239 .Case("SWI", ARMInterruptAttr::SWI)
240 .Case("ABORT", ARMInterruptAttr::ABORT)
241 .Case("UNDEF", ARMInterruptAttr::UNDEF)
242 .Case("", ARMInterruptAttr::Generic)
243 .Default(Optional<InterruptType>());
244 if (R) {
245 Out = *R;
246 return true;
247 }
248 return false;
249 }
250
251 static const char *ConvertInterruptTypeToStr(InterruptType Val) {
252 switch(Val) {
253 case ARMInterruptAttr::IRQ: return "IRQ";
254 case ARMInterruptAttr::FIQ: return "FIQ";
255 case ARMInterruptAttr::SWI: return "SWI";
256 case ARMInterruptAttr::ABORT: return "ABORT";
257 case ARMInterruptAttr::UNDEF: return "UNDEF";
258 case ARMInterruptAttr::Generic: return "";
259 }
260 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 260)
;
261 }
262
263
264 static bool classof(const Attr *A) { return A->getKind() == attr::ARMInterrupt; }
265};
266
267class AVRInterruptAttr : public InheritableAttr {
268public:
269 static AVRInterruptAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
270 auto *A = new (Ctx) AVRInterruptAttr(Loc, Ctx, 0);
271 A->setImplicit(true);
272 return A;
273 }
274
275 AVRInterruptAttr(SourceRange R, ASTContext &Ctx
276 , unsigned SI
277 )
278 : InheritableAttr(attr::AVRInterrupt, R, SI, false, false)
279 {
280 }
281
282 AVRInterruptAttr *clone(ASTContext &C) const;
283 void printPretty(raw_ostream &OS,
284 const PrintingPolicy &Policy) const;
285 const char *getSpelling() const;
286
287
288 static bool classof(const Attr *A) { return A->getKind() == attr::AVRInterrupt; }
289};
290
291class AVRSignalAttr : public InheritableAttr {
292public:
293 static AVRSignalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
294 auto *A = new (Ctx) AVRSignalAttr(Loc, Ctx, 0);
295 A->setImplicit(true);
296 return A;
297 }
298
299 AVRSignalAttr(SourceRange R, ASTContext &Ctx
300 , unsigned SI
301 )
302 : InheritableAttr(attr::AVRSignal, R, SI, false, false)
303 {
304 }
305
306 AVRSignalAttr *clone(ASTContext &C) const;
307 void printPretty(raw_ostream &OS,
308 const PrintingPolicy &Policy) const;
309 const char *getSpelling() const;
310
311
312 static bool classof(const Attr *A) { return A->getKind() == attr::AVRSignal; }
313};
314
315class AbiTagAttr : public Attr {
316 unsigned tags_Size;
317 StringRef *tags_;
318
319public:
320 static AbiTagAttr *CreateImplicit(ASTContext &Ctx, StringRef *Tags, unsigned TagsSize, SourceRange Loc = SourceRange()) {
321 auto *A = new (Ctx) AbiTagAttr(Loc, Ctx, Tags, TagsSize, 0);
322 A->setImplicit(true);
323 return A;
324 }
325
326 AbiTagAttr(SourceRange R, ASTContext &Ctx
327 , StringRef *Tags, unsigned TagsSize
328 , unsigned SI
329 )
330 : Attr(attr::AbiTag, R, SI, false)
331 , tags_Size(TagsSize), tags_(new (Ctx, 16) StringRef[tags_Size])
332 {
333 for (size_t I = 0, E = tags_Size; I != E;
334 ++I) {
335 StringRef Ref = Tags[I];
336 if (!Ref.empty()) {
337 char *Mem = new (Ctx, 1) char[Ref.size()];
338 std::memcpy(Mem, Ref.data(), Ref.size());
339 tags_[I] = StringRef(Mem, Ref.size());
340 }
341 }
342 }
343
344 AbiTagAttr(SourceRange R, ASTContext &Ctx
345 , unsigned SI
346 )
347 : Attr(attr::AbiTag, R, SI, false)
348 , tags_Size(0), tags_(nullptr)
349 {
350 }
351
352 AbiTagAttr *clone(ASTContext &C) const;
353 void printPretty(raw_ostream &OS,
354 const PrintingPolicy &Policy) const;
355 const char *getSpelling() const;
356 typedef StringRef* tags_iterator;
357 tags_iterator tags_begin() const { return tags_; }
358 tags_iterator tags_end() const { return tags_ + tags_Size; }
359 unsigned tags_size() const { return tags_Size; }
360 llvm::iterator_range<tags_iterator> tags() const { return llvm::make_range(tags_begin(), tags_end()); }
361
362
363
364
365 static bool classof(const Attr *A) { return A->getKind() == attr::AbiTag; }
366};
367
368class AcquireCapabilityAttr : public InheritableAttr {
369 unsigned args_Size;
370 Expr * *args_;
371
372public:
373 enum Spelling {
374 GNU_acquire_capability = 0,
375 CXX11_clang_acquire_capability = 1,
376 GNU_acquire_shared_capability = 2,
377 CXX11_clang_acquire_shared_capability = 3,
378 GNU_exclusive_lock_function = 4,
379 GNU_shared_lock_function = 5
380 };
381
382 static AcquireCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
383 auto *A = new (Ctx) AcquireCapabilityAttr(Loc, Ctx, Args, ArgsSize, S);
384 A->setImplicit(true);
385 return A;
386 }
387
388 AcquireCapabilityAttr(SourceRange R, ASTContext &Ctx
389 , Expr * *Args, unsigned ArgsSize
390 , unsigned SI
391 )
392 : InheritableAttr(attr::AcquireCapability, R, SI, true, true)
393 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
394 {
395 std::copy(Args, Args + args_Size, args_);
396 }
397
398 AcquireCapabilityAttr(SourceRange R, ASTContext &Ctx
399 , unsigned SI
400 )
401 : InheritableAttr(attr::AcquireCapability, R, SI, true, true)
402 , args_Size(0), args_(nullptr)
403 {
404 }
405
406 AcquireCapabilityAttr *clone(ASTContext &C) const;
407 void printPretty(raw_ostream &OS,
408 const PrintingPolicy &Policy) const;
409 const char *getSpelling() const;
410 Spelling getSemanticSpelling() const {
411 switch (SpellingListIndex) {
412 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 412)
;
413 case 0: return GNU_acquire_capability;
414 case 1: return CXX11_clang_acquire_capability;
415 case 2: return GNU_acquire_shared_capability;
416 case 3: return CXX11_clang_acquire_shared_capability;
417 case 4: return GNU_exclusive_lock_function;
418 case 5: return GNU_shared_lock_function;
419 }
420 }
421 bool isShared() const { return SpellingListIndex == 2 ||
422 SpellingListIndex == 3 ||
423 SpellingListIndex == 5; }
424 typedef Expr ** args_iterator;
425 args_iterator args_begin() const { return args_; }
426 args_iterator args_end() const { return args_ + args_Size; }
427 unsigned args_size() const { return args_Size; }
428 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
429
430
431
432
433 static bool classof(const Attr *A) { return A->getKind() == attr::AcquireCapability; }
434};
435
436class AcquiredAfterAttr : public InheritableAttr {
437 unsigned args_Size;
438 Expr * *args_;
439
440public:
441 static AcquiredAfterAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
442 auto *A = new (Ctx) AcquiredAfterAttr(Loc, Ctx, Args, ArgsSize, 0);
443 A->setImplicit(true);
444 return A;
445 }
446
447 AcquiredAfterAttr(SourceRange R, ASTContext &Ctx
448 , Expr * *Args, unsigned ArgsSize
449 , unsigned SI
450 )
451 : InheritableAttr(attr::AcquiredAfter, R, SI, true, true)
452 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
453 {
454 std::copy(Args, Args + args_Size, args_);
455 }
456
457 AcquiredAfterAttr(SourceRange R, ASTContext &Ctx
458 , unsigned SI
459 )
460 : InheritableAttr(attr::AcquiredAfter, R, SI, true, true)
461 , args_Size(0), args_(nullptr)
462 {
463 }
464
465 AcquiredAfterAttr *clone(ASTContext &C) const;
466 void printPretty(raw_ostream &OS,
467 const PrintingPolicy &Policy) const;
468 const char *getSpelling() const;
469 typedef Expr ** args_iterator;
470 args_iterator args_begin() const { return args_; }
471 args_iterator args_end() const { return args_ + args_Size; }
472 unsigned args_size() const { return args_Size; }
473 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
474
475
476
477
478 static bool classof(const Attr *A) { return A->getKind() == attr::AcquiredAfter; }
479};
480
481class AcquiredBeforeAttr : public InheritableAttr {
482 unsigned args_Size;
483 Expr * *args_;
484
485public:
486 static AcquiredBeforeAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
487 auto *A = new (Ctx) AcquiredBeforeAttr(Loc, Ctx, Args, ArgsSize, 0);
488 A->setImplicit(true);
489 return A;
490 }
491
492 AcquiredBeforeAttr(SourceRange R, ASTContext &Ctx
493 , Expr * *Args, unsigned ArgsSize
494 , unsigned SI
495 )
496 : InheritableAttr(attr::AcquiredBefore, R, SI, true, true)
497 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
498 {
499 std::copy(Args, Args + args_Size, args_);
500 }
501
502 AcquiredBeforeAttr(SourceRange R, ASTContext &Ctx
503 , unsigned SI
504 )
505 : InheritableAttr(attr::AcquiredBefore, R, SI, true, true)
506 , args_Size(0), args_(nullptr)
507 {
508 }
509
510 AcquiredBeforeAttr *clone(ASTContext &C) const;
511 void printPretty(raw_ostream &OS,
512 const PrintingPolicy &Policy) const;
513 const char *getSpelling() const;
514 typedef Expr ** args_iterator;
515 args_iterator args_begin() const { return args_; }
516 args_iterator args_end() const { return args_ + args_Size; }
517 unsigned args_size() const { return args_Size; }
518 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
519
520
521
522
523 static bool classof(const Attr *A) { return A->getKind() == attr::AcquiredBefore; }
524};
525
526class AddressSpaceAttr : public TypeAttr {
527int addressSpace;
528
529public:
530 static AddressSpaceAttr *CreateImplicit(ASTContext &Ctx, int AddressSpace, SourceRange Loc = SourceRange()) {
531 auto *A = new (Ctx) AddressSpaceAttr(Loc, Ctx, AddressSpace, 0);
532 A->setImplicit(true);
533 return A;
534 }
535
536 AddressSpaceAttr(SourceRange R, ASTContext &Ctx
537 , int AddressSpace
538 , unsigned SI
539 )
540 : TypeAttr(attr::AddressSpace, R, SI, false)
541 , addressSpace(AddressSpace)
542 {
543 }
544
545 AddressSpaceAttr *clone(ASTContext &C) const;
546 void printPretty(raw_ostream &OS,
547 const PrintingPolicy &Policy) const;
548 const char *getSpelling() const;
549 int getAddressSpace() const {
550 return addressSpace;
551 }
552
553
554
555 static bool classof(const Attr *A) { return A->getKind() == attr::AddressSpace; }
556};
557
558class AliasAttr : public Attr {
559unsigned aliaseeLength;
560char *aliasee;
561
562public:
563 static AliasAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Aliasee, SourceRange Loc = SourceRange()) {
564 auto *A = new (Ctx) AliasAttr(Loc, Ctx, Aliasee, 0);
565 A->setImplicit(true);
566 return A;
567 }
568
569 AliasAttr(SourceRange R, ASTContext &Ctx
570 , llvm::StringRef Aliasee
571 , unsigned SI
572 )
573 : Attr(attr::Alias, R, SI, false)
574 , aliaseeLength(Aliasee.size()),aliasee(new (Ctx, 1) char[aliaseeLength])
575 {
576 if (!Aliasee.empty())
577 std::memcpy(aliasee, Aliasee.data(), aliaseeLength);
578 }
579
580 AliasAttr *clone(ASTContext &C) const;
581 void printPretty(raw_ostream &OS,
582 const PrintingPolicy &Policy) const;
583 const char *getSpelling() const;
584 llvm::StringRef getAliasee() const {
585 return llvm::StringRef(aliasee, aliaseeLength);
586 }
587 unsigned getAliaseeLength() const {
588 return aliaseeLength;
589 }
590 void setAliasee(ASTContext &C, llvm::StringRef S) {
591 aliaseeLength = S.size();
592 this->aliasee = new (C, 1) char [aliaseeLength];
593 if (!S.empty())
594 std::memcpy(this->aliasee, S.data(), aliaseeLength);
595 }
596
597
598
599 static bool classof(const Attr *A) { return A->getKind() == attr::Alias; }
600};
601
602class AlignMac68kAttr : public InheritableAttr {
603public:
604 static AlignMac68kAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
605 auto *A = new (Ctx) AlignMac68kAttr(Loc, Ctx, 0);
606 A->setImplicit(true);
607 return A;
608 }
609
610 AlignMac68kAttr(SourceRange R, ASTContext &Ctx
611 , unsigned SI
612 )
613 : InheritableAttr(attr::AlignMac68k, R, SI, false, false)
614 {
615 }
616
617 AlignMac68kAttr *clone(ASTContext &C) const;
618 void printPretty(raw_ostream &OS,
619 const PrintingPolicy &Policy) const;
620 const char *getSpelling() const;
621
622
623 static bool classof(const Attr *A) { return A->getKind() == attr::AlignMac68k; }
624};
625
626class AlignValueAttr : public Attr {
627Expr * alignment;
628
629public:
630 static AlignValueAttr *CreateImplicit(ASTContext &Ctx, Expr * Alignment, SourceRange Loc = SourceRange()) {
631 auto *A = new (Ctx) AlignValueAttr(Loc, Ctx, Alignment, 0);
632 A->setImplicit(true);
633 return A;
634 }
635
636 AlignValueAttr(SourceRange R, ASTContext &Ctx
637 , Expr * Alignment
638 , unsigned SI
639 )
640 : Attr(attr::AlignValue, R, SI, false)
641 , alignment(Alignment)
642 {
643 }
644
645 AlignValueAttr *clone(ASTContext &C) const;
646 void printPretty(raw_ostream &OS,
647 const PrintingPolicy &Policy) const;
648 const char *getSpelling() const;
649 Expr * getAlignment() const {
650 return alignment;
651 }
652
653
654
655 static bool classof(const Attr *A) { return A->getKind() == attr::AlignValue; }
656};
657
658class AlignedAttr : public InheritableAttr {
659bool isalignmentExpr;
660union {
661Expr *alignmentExpr;
662TypeSourceInfo *alignmentType;
663};
664
665public:
666 enum Spelling {
667 GNU_aligned = 0,
668 CXX11_gnu_aligned = 1,
669 Declspec_align = 2,
670 Keyword_alignas = 3,
671 Keyword_Alignas = 4
672 };
673
674 static AlignedAttr *CreateImplicit(ASTContext &Ctx, Spelling S, bool IsAlignmentExpr, void *Alignment, SourceRange Loc = SourceRange()) {
675 auto *A = new (Ctx) AlignedAttr(Loc, Ctx, IsAlignmentExpr, Alignment, S);
676 A->setImplicit(true);
677 return A;
678 }
679
680 AlignedAttr(SourceRange R, ASTContext &Ctx
681 , bool IsAlignmentExpr, void *Alignment
682 , unsigned SI
683 )
684 : InheritableAttr(attr::Aligned, R, SI, false, false)
685 , isalignmentExpr(IsAlignmentExpr)
686 {
687 if (isalignmentExpr)
688 alignmentExpr = reinterpret_cast<Expr *>(Alignment);
689 else
690 alignmentType = reinterpret_cast<TypeSourceInfo *>(Alignment);
691 }
692
693 AlignedAttr(SourceRange R, ASTContext &Ctx
694 , unsigned SI
695 )
696 : InheritableAttr(attr::Aligned, R, SI, false, false)
697 , isalignmentExpr(false)
698 {
699 }
700
701 AlignedAttr *clone(ASTContext &C) const;
702 void printPretty(raw_ostream &OS,
703 const PrintingPolicy &Policy) const;
704 const char *getSpelling() const;
705 Spelling getSemanticSpelling() const {
706 switch (SpellingListIndex) {
707 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 707)
;
708 case 0: return GNU_aligned;
709 case 1: return CXX11_gnu_aligned;
710 case 2: return Declspec_align;
711 case 3: return Keyword_alignas;
712 case 4: return Keyword_Alignas;
713 }
714 }
715 bool isGNU() const { return SpellingListIndex == 0 ||
716 SpellingListIndex == 1; }
717 bool isC11() const { return SpellingListIndex == 4; }
718 bool isAlignas() const { return SpellingListIndex == 3 ||
719 SpellingListIndex == 4; }
720 bool isDeclspec() const { return SpellingListIndex == 2; }
721 bool isAlignmentDependent() const;
722 unsigned getAlignment(ASTContext &Ctx) const;
723 bool isAlignmentExpr() const {
724 return isalignmentExpr;
725 }
726 Expr *getAlignmentExpr() const {
727 assert(isalignmentExpr)((isalignmentExpr) ? static_cast<void> (0) : __assert_fail
("isalignmentExpr", "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 727, __PRETTY_FUNCTION__))
;
728 return alignmentExpr;
729 }
730 TypeSourceInfo *getAlignmentType() const {
731 assert(!isalignmentExpr)((!isalignmentExpr) ? static_cast<void> (0) : __assert_fail
("!isalignmentExpr", "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 731, __PRETTY_FUNCTION__))
;
732 return alignmentType;
733 }
734
735
736
737 static bool classof(const Attr *A) { return A->getKind() == attr::Aligned; }
738};
739
740class AllocAlignAttr : public InheritableAttr {
741ParamIdx paramIndex;
742
743public:
744 static AllocAlignAttr *CreateImplicit(ASTContext &Ctx, ParamIdx ParamIndex, SourceRange Loc = SourceRange()) {
745 auto *A = new (Ctx) AllocAlignAttr(Loc, Ctx, ParamIndex, 0);
746 A->setImplicit(true);
747 return A;
748 }
749
750 AllocAlignAttr(SourceRange R, ASTContext &Ctx
751 , ParamIdx ParamIndex
752 , unsigned SI
753 )
754 : InheritableAttr(attr::AllocAlign, R, SI, false, false)
755 , paramIndex(ParamIndex)
756 {
757 }
758
759 AllocAlignAttr *clone(ASTContext &C) const;
760 void printPretty(raw_ostream &OS,
761 const PrintingPolicy &Policy) const;
762 const char *getSpelling() const;
763 ParamIdx getParamIndex() const {
764 return paramIndex;
765 }
766
767
768
769 static bool classof(const Attr *A) { return A->getKind() == attr::AllocAlign; }
770};
771
772class AllocSizeAttr : public InheritableAttr {
773ParamIdx elemSizeParam;
774
775ParamIdx numElemsParam;
776
777public:
778 static AllocSizeAttr *CreateImplicit(ASTContext &Ctx, ParamIdx ElemSizeParam, ParamIdx NumElemsParam, SourceRange Loc = SourceRange()) {
779 auto *A = new (Ctx) AllocSizeAttr(Loc, Ctx, ElemSizeParam, NumElemsParam, 0);
780 A->setImplicit(true);
781 return A;
782 }
783
784 AllocSizeAttr(SourceRange R, ASTContext &Ctx
785 , ParamIdx ElemSizeParam
786 , ParamIdx NumElemsParam
787 , unsigned SI
788 )
789 : InheritableAttr(attr::AllocSize, R, SI, false, false)
790 , elemSizeParam(ElemSizeParam)
791 , numElemsParam(NumElemsParam)
792 {
793 }
794
795 AllocSizeAttr(SourceRange R, ASTContext &Ctx
796 , ParamIdx ElemSizeParam
797 , unsigned SI
798 )
799 : InheritableAttr(attr::AllocSize, R, SI, false, false)
800 , elemSizeParam(ElemSizeParam)
801 , numElemsParam()
802 {
803 }
804
805 AllocSizeAttr *clone(ASTContext &C) const;
806 void printPretty(raw_ostream &OS,
807 const PrintingPolicy &Policy) const;
808 const char *getSpelling() const;
809 ParamIdx getElemSizeParam() const {
810 return elemSizeParam;
811 }
812
813 ParamIdx getNumElemsParam() const {
814 return numElemsParam;
815 }
816
817
818
819 static bool classof(const Attr *A) { return A->getKind() == attr::AllocSize; }
820};
821
822class AlwaysDestroyAttr : public InheritableAttr {
823public:
824 static AlwaysDestroyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
825 auto *A = new (Ctx) AlwaysDestroyAttr(Loc, Ctx, 0);
826 A->setImplicit(true);
827 return A;
828 }
829
830 AlwaysDestroyAttr(SourceRange R, ASTContext &Ctx
831 , unsigned SI
832 )
833 : InheritableAttr(attr::AlwaysDestroy, R, SI, false, false)
834 {
835 }
836
837 AlwaysDestroyAttr *clone(ASTContext &C) const;
838 void printPretty(raw_ostream &OS,
839 const PrintingPolicy &Policy) const;
840 const char *getSpelling() const;
841
842
843 static bool classof(const Attr *A) { return A->getKind() == attr::AlwaysDestroy; }
844};
845
846class AlwaysInlineAttr : public InheritableAttr {
847public:
848 enum Spelling {
849 GNU_always_inline = 0,
850 CXX11_gnu_always_inline = 1,
851 Keyword_forceinline = 2
852 };
853
854 static AlwaysInlineAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
855 auto *A = new (Ctx) AlwaysInlineAttr(Loc, Ctx, S);
856 A->setImplicit(true);
857 return A;
858 }
859
860 AlwaysInlineAttr(SourceRange R, ASTContext &Ctx
861 , unsigned SI
862 )
863 : InheritableAttr(attr::AlwaysInline, R, SI, false, false)
864 {
865 }
866
867 AlwaysInlineAttr *clone(ASTContext &C) const;
868 void printPretty(raw_ostream &OS,
869 const PrintingPolicy &Policy) const;
870 const char *getSpelling() const;
871 Spelling getSemanticSpelling() const {
872 switch (SpellingListIndex) {
873 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 873)
;
874 case 0: return GNU_always_inline;
875 case 1: return CXX11_gnu_always_inline;
876 case 2: return Keyword_forceinline;
877 }
878 }
879
880
881 static bool classof(const Attr *A) { return A->getKind() == attr::AlwaysInline; }
882};
883
884class AnalyzerNoReturnAttr : public InheritableAttr {
885public:
886 static AnalyzerNoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
887 auto *A = new (Ctx) AnalyzerNoReturnAttr(Loc, Ctx, 0);
888 A->setImplicit(true);
889 return A;
890 }
891
892 AnalyzerNoReturnAttr(SourceRange R, ASTContext &Ctx
893 , unsigned SI
894 )
895 : InheritableAttr(attr::AnalyzerNoReturn, R, SI, false, false)
896 {
897 }
898
899 AnalyzerNoReturnAttr *clone(ASTContext &C) const;
900 void printPretty(raw_ostream &OS,
901 const PrintingPolicy &Policy) const;
902 const char *getSpelling() const;
903
904
905 static bool classof(const Attr *A) { return A->getKind() == attr::AnalyzerNoReturn; }
906};
907
908class AnnotateAttr : public InheritableParamAttr {
909unsigned annotationLength;
910char *annotation;
911
912public:
913 static AnnotateAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Annotation, SourceRange Loc = SourceRange()) {
914 auto *A = new (Ctx) AnnotateAttr(Loc, Ctx, Annotation, 0);
915 A->setImplicit(true);
916 return A;
917 }
918
919 AnnotateAttr(SourceRange R, ASTContext &Ctx
920 , llvm::StringRef Annotation
921 , unsigned SI
922 )
923 : InheritableParamAttr(attr::Annotate, R, SI, false, false)
924 , annotationLength(Annotation.size()),annotation(new (Ctx, 1) char[annotationLength])
925 {
926 if (!Annotation.empty())
927 std::memcpy(annotation, Annotation.data(), annotationLength);
928 }
929
930 AnnotateAttr *clone(ASTContext &C) const;
931 void printPretty(raw_ostream &OS,
932 const PrintingPolicy &Policy) const;
933 const char *getSpelling() const;
934 llvm::StringRef getAnnotation() const {
935 return llvm::StringRef(annotation, annotationLength);
936 }
937 unsigned getAnnotationLength() const {
938 return annotationLength;
939 }
940 void setAnnotation(ASTContext &C, llvm::StringRef S) {
941 annotationLength = S.size();
942 this->annotation = new (C, 1) char [annotationLength];
943 if (!S.empty())
944 std::memcpy(this->annotation, S.data(), annotationLength);
945 }
946
947
948
949 static bool classof(const Attr *A) { return A->getKind() == attr::Annotate; }
950};
951
952class AnyX86InterruptAttr : public InheritableAttr {
953public:
954 static AnyX86InterruptAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
955 auto *A = new (Ctx) AnyX86InterruptAttr(Loc, Ctx, 0);
956 A->setImplicit(true);
957 return A;
958 }
959
960 AnyX86InterruptAttr(SourceRange R, ASTContext &Ctx
961 , unsigned SI
962 )
963 : InheritableAttr(attr::AnyX86Interrupt, R, SI, false, false)
964 {
965 }
966
967 AnyX86InterruptAttr *clone(ASTContext &C) const;
968 void printPretty(raw_ostream &OS,
969 const PrintingPolicy &Policy) const;
970 const char *getSpelling() const;
971
972
973 static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86Interrupt; }
974};
975
976class AnyX86NoCallerSavedRegistersAttr : public InheritableAttr {
977public:
978 static AnyX86NoCallerSavedRegistersAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
979 auto *A = new (Ctx) AnyX86NoCallerSavedRegistersAttr(Loc, Ctx, 0);
980 A->setImplicit(true);
981 return A;
982 }
983
984 AnyX86NoCallerSavedRegistersAttr(SourceRange R, ASTContext &Ctx
985 , unsigned SI
986 )
987 : InheritableAttr(attr::AnyX86NoCallerSavedRegisters, R, SI, false, false)
988 {
989 }
990
991 AnyX86NoCallerSavedRegistersAttr *clone(ASTContext &C) const;
992 void printPretty(raw_ostream &OS,
993 const PrintingPolicy &Policy) const;
994 const char *getSpelling() const;
995
996
997 static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86NoCallerSavedRegisters; }
998};
999
1000class AnyX86NoCfCheckAttr : public InheritableAttr {
1001public:
1002 static AnyX86NoCfCheckAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1003 auto *A = new (Ctx) AnyX86NoCfCheckAttr(Loc, Ctx, 0);
1004 A->setImplicit(true);
1005 return A;
1006 }
1007
1008 AnyX86NoCfCheckAttr(SourceRange R, ASTContext &Ctx
1009 , unsigned SI
1010 )
1011 : InheritableAttr(attr::AnyX86NoCfCheck, R, SI, false, false)
1012 {
1013 }
1014
1015 AnyX86NoCfCheckAttr *clone(ASTContext &C) const;
1016 void printPretty(raw_ostream &OS,
1017 const PrintingPolicy &Policy) const;
1018 const char *getSpelling() const;
1019
1020
1021 static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86NoCfCheck; }
1022};
1023
1024class ArcWeakrefUnavailableAttr : public InheritableAttr {
1025public:
1026 static ArcWeakrefUnavailableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1027 auto *A = new (Ctx) ArcWeakrefUnavailableAttr(Loc, Ctx, 0);
1028 A->setImplicit(true);
1029 return A;
1030 }
1031
1032 ArcWeakrefUnavailableAttr(SourceRange R, ASTContext &Ctx
1033 , unsigned SI
1034 )
1035 : InheritableAttr(attr::ArcWeakrefUnavailable, R, SI, false, false)
1036 {
1037 }
1038
1039 ArcWeakrefUnavailableAttr *clone(ASTContext &C) const;
1040 void printPretty(raw_ostream &OS,
1041 const PrintingPolicy &Policy) const;
1042 const char *getSpelling() const;
1043
1044
1045 static bool classof(const Attr *A) { return A->getKind() == attr::ArcWeakrefUnavailable; }
1046};
1047
1048class ArgumentWithTypeTagAttr : public InheritableAttr {
1049IdentifierInfo * argumentKind;
1050
1051ParamIdx argumentIdx;
1052
1053ParamIdx typeTagIdx;
1054
1055bool isPointer;
1056
1057public:
1058 enum Spelling {
1059 GNU_argument_with_type_tag = 0,
1060 CXX11_clang_argument_with_type_tag = 1,
1061 C2x_clang_argument_with_type_tag = 2,
1062 GNU_pointer_with_type_tag = 3,
1063 CXX11_clang_pointer_with_type_tag = 4,
1064 C2x_clang_pointer_with_type_tag = 5
1065 };
1066
1067 static ArgumentWithTypeTagAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * ArgumentKind, ParamIdx ArgumentIdx, ParamIdx TypeTagIdx, bool IsPointer, SourceRange Loc = SourceRange()) {
1068 auto *A = new (Ctx) ArgumentWithTypeTagAttr(Loc, Ctx, ArgumentKind, ArgumentIdx, TypeTagIdx, IsPointer, S);
1069 A->setImplicit(true);
1070 return A;
1071 }
1072
1073 static ArgumentWithTypeTagAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * ArgumentKind, ParamIdx ArgumentIdx, ParamIdx TypeTagIdx, SourceRange Loc = SourceRange()) {
1074 auto *A = new (Ctx) ArgumentWithTypeTagAttr(Loc, Ctx, ArgumentKind, ArgumentIdx, TypeTagIdx, S);
1075 A->setImplicit(true);
1076 return A;
1077 }
1078
1079 ArgumentWithTypeTagAttr(SourceRange R, ASTContext &Ctx
1080 , IdentifierInfo * ArgumentKind
1081 , ParamIdx ArgumentIdx
1082 , ParamIdx TypeTagIdx
1083 , bool IsPointer
1084 , unsigned SI
1085 )
1086 : InheritableAttr(attr::ArgumentWithTypeTag, R, SI, false, false)
1087 , argumentKind(ArgumentKind)
1088 , argumentIdx(ArgumentIdx)
1089 , typeTagIdx(TypeTagIdx)
1090 , isPointer(IsPointer)
1091 {
1092 }
1093
1094 ArgumentWithTypeTagAttr(SourceRange R, ASTContext &Ctx
1095 , IdentifierInfo * ArgumentKind
1096 , ParamIdx ArgumentIdx
1097 , ParamIdx TypeTagIdx
1098 , unsigned SI
1099 )
1100 : InheritableAttr(attr::ArgumentWithTypeTag, R, SI, false, false)
1101 , argumentKind(ArgumentKind)
1102 , argumentIdx(ArgumentIdx)
1103 , typeTagIdx(TypeTagIdx)
1104 , isPointer()
1105 {
1106 }
1107
1108 ArgumentWithTypeTagAttr *clone(ASTContext &C) const;
1109 void printPretty(raw_ostream &OS,
1110 const PrintingPolicy &Policy) const;
1111 const char *getSpelling() const;
1112 Spelling getSemanticSpelling() const {
1113 switch (SpellingListIndex) {
1114 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 1114)
;
1115 case 0: return GNU_argument_with_type_tag;
1116 case 1: return CXX11_clang_argument_with_type_tag;
1117 case 2: return C2x_clang_argument_with_type_tag;
1118 case 3: return GNU_pointer_with_type_tag;
1119 case 4: return CXX11_clang_pointer_with_type_tag;
1120 case 5: return C2x_clang_pointer_with_type_tag;
1121 }
1122 }
1123 IdentifierInfo * getArgumentKind() const {
1124 return argumentKind;
1125 }
1126
1127 ParamIdx getArgumentIdx() const {
1128 return argumentIdx;
1129 }
1130
1131 ParamIdx getTypeTagIdx() const {
1132 return typeTagIdx;
1133 }
1134
1135 bool getIsPointer() const {
1136 return isPointer;
1137 }
1138
1139
1140
1141 static bool classof(const Attr *A) { return A->getKind() == attr::ArgumentWithTypeTag; }
1142};
1143
1144class ArtificialAttr : public InheritableAttr {
1145public:
1146 static ArtificialAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1147 auto *A = new (Ctx) ArtificialAttr(Loc, Ctx, 0);
1148 A->setImplicit(true);
1149 return A;
1150 }
1151
1152 ArtificialAttr(SourceRange R, ASTContext &Ctx
1153 , unsigned SI
1154 )
1155 : InheritableAttr(attr::Artificial, R, SI, false, false)
1156 {
1157 }
1158
1159 ArtificialAttr *clone(ASTContext &C) const;
1160 void printPretty(raw_ostream &OS,
1161 const PrintingPolicy &Policy) const;
1162 const char *getSpelling() const;
1163
1164
1165 static bool classof(const Attr *A) { return A->getKind() == attr::Artificial; }
1166};
1167
1168class AsmLabelAttr : public InheritableAttr {
1169unsigned labelLength;
1170char *label;
1171
1172public:
1173 static AsmLabelAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Label, SourceRange Loc = SourceRange()) {
1174 auto *A = new (Ctx) AsmLabelAttr(Loc, Ctx, Label, 0);
1175 A->setImplicit(true);
1176 return A;
1177 }
1178
1179 AsmLabelAttr(SourceRange R, ASTContext &Ctx
1180 , llvm::StringRef Label
1181 , unsigned SI
1182 )
1183 : InheritableAttr(attr::AsmLabel, R, SI, false, false)
1184 , labelLength(Label.size()),label(new (Ctx, 1) char[labelLength])
1185 {
1186 if (!Label.empty())
1187 std::memcpy(label, Label.data(), labelLength);
1188 }
1189
1190 AsmLabelAttr *clone(ASTContext &C) const;
1191 void printPretty(raw_ostream &OS,
1192 const PrintingPolicy &Policy) const;
1193 const char *getSpelling() const;
1194 llvm::StringRef getLabel() const {
1195 return llvm::StringRef(label, labelLength);
1196 }
1197 unsigned getLabelLength() const {
1198 return labelLength;
1199 }
1200 void setLabel(ASTContext &C, llvm::StringRef S) {
1201 labelLength = S.size();
1202 this->label = new (C, 1) char [labelLength];
1203 if (!S.empty())
1204 std::memcpy(this->label, S.data(), labelLength);
1205 }
1206
1207
1208
1209 static bool classof(const Attr *A) { return A->getKind() == attr::AsmLabel; }
1210};
1211
1212class AssertCapabilityAttr : public InheritableAttr {
1213 unsigned args_Size;
1214 Expr * *args_;
1215
1216public:
1217 enum Spelling {
1218 GNU_assert_capability = 0,
1219 CXX11_clang_assert_capability = 1,
1220 GNU_assert_shared_capability = 2,
1221 CXX11_clang_assert_shared_capability = 3
1222 };
1223
1224 static AssertCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
1225 auto *A = new (Ctx) AssertCapabilityAttr(Loc, Ctx, Args, ArgsSize, S);
1226 A->setImplicit(true);
1227 return A;
1228 }
1229
1230 AssertCapabilityAttr(SourceRange R, ASTContext &Ctx
1231 , Expr * *Args, unsigned ArgsSize
1232 , unsigned SI
1233 )
1234 : InheritableAttr(attr::AssertCapability, R, SI, true, true)
1235 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
1236 {
1237 std::copy(Args, Args + args_Size, args_);
1238 }
1239
1240 AssertCapabilityAttr(SourceRange R, ASTContext &Ctx
1241 , unsigned SI
1242 )
1243 : InheritableAttr(attr::AssertCapability, R, SI, true, true)
1244 , args_Size(0), args_(nullptr)
1245 {
1246 }
1247
1248 AssertCapabilityAttr *clone(ASTContext &C) const;
1249 void printPretty(raw_ostream &OS,
1250 const PrintingPolicy &Policy) const;
1251 const char *getSpelling() const;
1252 Spelling getSemanticSpelling() const {
1253 switch (SpellingListIndex) {
1254 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 1254)
;
1255 case 0: return GNU_assert_capability;
1256 case 1: return CXX11_clang_assert_capability;
1257 case 2: return GNU_assert_shared_capability;
1258 case 3: return CXX11_clang_assert_shared_capability;
1259 }
1260 }
1261 bool isShared() const { return SpellingListIndex == 2 ||
1262 SpellingListIndex == 3; }
1263 typedef Expr ** args_iterator;
1264 args_iterator args_begin() const { return args_; }
1265 args_iterator args_end() const { return args_ + args_Size; }
1266 unsigned args_size() const { return args_Size; }
1267 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
1268
1269
1270
1271
1272 static bool classof(const Attr *A) { return A->getKind() == attr::AssertCapability; }
1273};
1274
1275class AssertExclusiveLockAttr : public InheritableAttr {
1276 unsigned args_Size;
1277 Expr * *args_;
1278
1279public:
1280 static AssertExclusiveLockAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
1281 auto *A = new (Ctx) AssertExclusiveLockAttr(Loc, Ctx, Args, ArgsSize, 0);
1282 A->setImplicit(true);
1283 return A;
1284 }
1285
1286 AssertExclusiveLockAttr(SourceRange R, ASTContext &Ctx
1287 , Expr * *Args, unsigned ArgsSize
1288 , unsigned SI
1289 )
1290 : InheritableAttr(attr::AssertExclusiveLock, R, SI, true, true)
1291 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
1292 {
1293 std::copy(Args, Args + args_Size, args_);
1294 }
1295
1296 AssertExclusiveLockAttr(SourceRange R, ASTContext &Ctx
1297 , unsigned SI
1298 )
1299 : InheritableAttr(attr::AssertExclusiveLock, R, SI, true, true)
1300 , args_Size(0), args_(nullptr)
1301 {
1302 }
1303
1304 AssertExclusiveLockAttr *clone(ASTContext &C) const;
1305 void printPretty(raw_ostream &OS,
1306 const PrintingPolicy &Policy) const;
1307 const char *getSpelling() const;
1308 typedef Expr ** args_iterator;
1309 args_iterator args_begin() const { return args_; }
1310 args_iterator args_end() const { return args_ + args_Size; }
1311 unsigned args_size() const { return args_Size; }
1312 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
1313
1314
1315
1316
1317 static bool classof(const Attr *A) { return A->getKind() == attr::AssertExclusiveLock; }
1318};
1319
1320class AssertSharedLockAttr : public InheritableAttr {
1321 unsigned args_Size;
1322 Expr * *args_;
1323
1324public:
1325 static AssertSharedLockAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
1326 auto *A = new (Ctx) AssertSharedLockAttr(Loc, Ctx, Args, ArgsSize, 0);
1327 A->setImplicit(true);
1328 return A;
1329 }
1330
1331 AssertSharedLockAttr(SourceRange R, ASTContext &Ctx
1332 , Expr * *Args, unsigned ArgsSize
1333 , unsigned SI
1334 )
1335 : InheritableAttr(attr::AssertSharedLock, R, SI, true, true)
1336 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
1337 {
1338 std::copy(Args, Args + args_Size, args_);
1339 }
1340
1341 AssertSharedLockAttr(SourceRange R, ASTContext &Ctx
1342 , unsigned SI
1343 )
1344 : InheritableAttr(attr::AssertSharedLock, R, SI, true, true)
1345 , args_Size(0), args_(nullptr)
1346 {
1347 }
1348
1349 AssertSharedLockAttr *clone(ASTContext &C) const;
1350 void printPretty(raw_ostream &OS,
1351 const PrintingPolicy &Policy) const;
1352 const char *getSpelling() const;
1353 typedef Expr ** args_iterator;
1354 args_iterator args_begin() const { return args_; }
1355 args_iterator args_end() const { return args_ + args_Size; }
1356 unsigned args_size() const { return args_Size; }
1357 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
1358
1359
1360
1361
1362 static bool classof(const Attr *A) { return A->getKind() == attr::AssertSharedLock; }
1363};
1364
1365class AssumeAlignedAttr : public InheritableAttr {
1366Expr * alignment;
1367
1368Expr * offset;
1369
1370public:
1371 static AssumeAlignedAttr *CreateImplicit(ASTContext &Ctx, Expr * Alignment, Expr * Offset, SourceRange Loc = SourceRange()) {
1372 auto *A = new (Ctx) AssumeAlignedAttr(Loc, Ctx, Alignment, Offset, 0);
1373 A->setImplicit(true);
1374 return A;
1375 }
1376
1377 AssumeAlignedAttr(SourceRange R, ASTContext &Ctx
1378 , Expr * Alignment
1379 , Expr * Offset
1380 , unsigned SI
1381 )
1382 : InheritableAttr(attr::AssumeAligned, R, SI, false, false)
1383 , alignment(Alignment)
1384 , offset(Offset)
1385 {
1386 }
1387
1388 AssumeAlignedAttr(SourceRange R, ASTContext &Ctx
1389 , Expr * Alignment
1390 , unsigned SI
1391 )
1392 : InheritableAttr(attr::AssumeAligned, R, SI, false, false)
1393 , alignment(Alignment)
1394 , offset()
1395 {
1396 }
1397
1398 AssumeAlignedAttr *clone(ASTContext &C) const;
1399 void printPretty(raw_ostream &OS,
1400 const PrintingPolicy &Policy) const;
1401 const char *getSpelling() const;
1402 Expr * getAlignment() const {
1403 return alignment;
1404 }
1405
1406 Expr * getOffset() const {
1407 return offset;
1408 }
1409
1410
1411
1412 static bool classof(const Attr *A) { return A->getKind() == attr::AssumeAligned; }
1413};
1414
1415class AvailabilityAttr : public InheritableAttr {
1416IdentifierInfo * platform;
1417
1418VersionTuple introduced;
1419
1420
1421VersionTuple deprecated;
1422
1423
1424VersionTuple obsoleted;
1425
1426
1427bool unavailable;
1428
1429unsigned messageLength;
1430char *message;
1431
1432bool strict;
1433
1434unsigned replacementLength;
1435char *replacement;
1436
1437int priority;
1438
1439public:
1440 static AvailabilityAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Platform, VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, bool Unavailable, llvm::StringRef Message, bool Strict, llvm::StringRef Replacement, int Priority, SourceRange Loc = SourceRange()) {
1441 auto *A = new (Ctx) AvailabilityAttr(Loc, Ctx, Platform, Introduced, Deprecated, Obsoleted, Unavailable, Message, Strict, Replacement, Priority, 0);
1442 A->setImplicit(true);
1443 return A;
1444 }
1445
1446 AvailabilityAttr(SourceRange R, ASTContext &Ctx
1447 , IdentifierInfo * Platform
1448 , VersionTuple Introduced
1449 , VersionTuple Deprecated
1450 , VersionTuple Obsoleted
1451 , bool Unavailable
1452 , llvm::StringRef Message
1453 , bool Strict
1454 , llvm::StringRef Replacement
1455 , int Priority
1456 , unsigned SI
1457 )
1458 : InheritableAttr(attr::Availability, R, SI, false, true)
1459 , platform(Platform)
1460 , introduced(Introduced)
1461 , deprecated(Deprecated)
1462 , obsoleted(Obsoleted)
1463 , unavailable(Unavailable)
1464 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
1465 , strict(Strict)
1466 , replacementLength(Replacement.size()),replacement(new (Ctx, 1) char[replacementLength])
1467 , priority(Priority)
1468 {
1469 if (!Message.empty())
1470 std::memcpy(message, Message.data(), messageLength);
1471 if (!Replacement.empty())
1472 std::memcpy(replacement, Replacement.data(), replacementLength);
1473 }
1474
1475 AvailabilityAttr *clone(ASTContext &C) const;
1476 void printPretty(raw_ostream &OS,
1477 const PrintingPolicy &Policy) const;
1478 const char *getSpelling() const;
1479 IdentifierInfo * getPlatform() const {
1480 return platform;
1481 }
1482
1483 VersionTuple getIntroduced() const {
1484 return introduced;
1485 }
1486 void setIntroduced(ASTContext &C, VersionTuple V) {
1487 introduced = V;
1488 }
1489
1490 VersionTuple getDeprecated() const {
1491 return deprecated;
1492 }
1493 void setDeprecated(ASTContext &C, VersionTuple V) {
1494 deprecated = V;
1495 }
1496
1497 VersionTuple getObsoleted() const {
1498 return obsoleted;
1499 }
1500 void setObsoleted(ASTContext &C, VersionTuple V) {
1501 obsoleted = V;
1502 }
1503
1504 bool getUnavailable() const {
1505 return unavailable;
1506 }
1507
1508 llvm::StringRef getMessage() const {
1509 return llvm::StringRef(message, messageLength);
1510 }
1511 unsigned getMessageLength() const {
1512 return messageLength;
1513 }
1514 void setMessage(ASTContext &C, llvm::StringRef S) {
1515 messageLength = S.size();
1516 this->message = new (C, 1) char [messageLength];
1517 if (!S.empty())
1518 std::memcpy(this->message, S.data(), messageLength);
1519 }
1520
1521 bool getStrict() const {
1522 return strict;
1523 }
1524
1525 llvm::StringRef getReplacement() const {
1526 return llvm::StringRef(replacement, replacementLength);
1527 }
1528 unsigned getReplacementLength() const {
1529 return replacementLength;
1530 }
1531 void setReplacement(ASTContext &C, llvm::StringRef S) {
1532 replacementLength = S.size();
1533 this->replacement = new (C, 1) char [replacementLength];
1534 if (!S.empty())
1535 std::memcpy(this->replacement, S.data(), replacementLength);
1536 }
1537
1538 int getPriority() const {
1539 return priority;
1540 }
1541
1542static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
1543 return llvm::StringSwitch<llvm::StringRef>(Platform)
1544 .Case("android", "Android")
1545 .Case("ios", "iOS")
1546 .Case("macos", "macOS")
1547 .Case("tvos", "tvOS")
1548 .Case("watchos", "watchOS")
1549 .Case("ios_app_extension", "iOS (App Extension)")
1550 .Case("macos_app_extension", "macOS (App Extension)")
1551 .Case("tvos_app_extension", "tvOS (App Extension)")
1552 .Case("watchos_app_extension", "watchOS (App Extension)")
1553 .Case("swift", "Swift")
1554 .Default(llvm::StringRef());
1555}
1556static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) {
1557 return llvm::StringSwitch<llvm::StringRef>(Platform)
1558 .Case("ios", "iOS")
1559 .Case("macos", "macOS")
1560 .Case("tvos", "tvOS")
1561 .Case("watchos", "watchOS")
1562 .Case("ios_app_extension", "iOSApplicationExtension")
1563 .Case("macos_app_extension", "macOSApplicationExtension")
1564 .Case("tvos_app_extension", "tvOSApplicationExtension")
1565 .Case("watchos_app_extension", "watchOSApplicationExtension")
1566 .Default(Platform);
1567}
1568static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
1569 return llvm::StringSwitch<llvm::StringRef>(Platform)
1570 .Case("iOS", "ios")
1571 .Case("macOS", "macos")
1572 .Case("tvOS", "tvos")
1573 .Case("watchOS", "watchos")
1574 .Case("iOSApplicationExtension", "ios_app_extension")
1575 .Case("macOSApplicationExtension", "macos_app_extension")
1576 .Case("tvOSApplicationExtension", "tvos_app_extension")
1577 .Case("watchOSApplicationExtension", "watchos_app_extension")
1578 .Default(Platform);
1579}
1580
1581 static bool classof(const Attr *A) { return A->getKind() == attr::Availability; }
1582};
1583
1584class BlocksAttr : public InheritableAttr {
1585public:
1586 enum BlockType {
1587 ByRef
1588 };
1589private:
1590 BlockType type;
1591
1592public:
1593 static BlocksAttr *CreateImplicit(ASTContext &Ctx, BlockType Type, SourceRange Loc = SourceRange()) {
1594 auto *A = new (Ctx) BlocksAttr(Loc, Ctx, Type, 0);
1595 A->setImplicit(true);
1596 return A;
1597 }
1598
1599 BlocksAttr(SourceRange R, ASTContext &Ctx
1600 , BlockType Type
1601 , unsigned SI
1602 )
1603 : InheritableAttr(attr::Blocks, R, SI, false, false)
1604 , type(Type)
1605 {
1606 }
1607
1608 BlocksAttr *clone(ASTContext &C) const;
1609 void printPretty(raw_ostream &OS,
1610 const PrintingPolicy &Policy) const;
1611 const char *getSpelling() const;
1612 BlockType getType() const {
1613 return type;
1614 }
1615
1616 static bool ConvertStrToBlockType(StringRef Val, BlockType &Out) {
1617 Optional<BlockType> R = llvm::StringSwitch<Optional<BlockType>>(Val)
1618 .Case("byref", BlocksAttr::ByRef)
1619 .Default(Optional<BlockType>());
1620 if (R) {
1621 Out = *R;
1622 return true;
1623 }
1624 return false;
1625 }
1626
1627 static const char *ConvertBlockTypeToStr(BlockType Val) {
1628 switch(Val) {
1629 case BlocksAttr::ByRef: return "byref";
1630 }
1631 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 1631)
;
1632 }
1633
1634
1635 static bool classof(const Attr *A) { return A->getKind() == attr::Blocks; }
1636};
1637
1638class C11NoReturnAttr : public InheritableAttr {
1639public:
1640 static C11NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1641 auto *A = new (Ctx) C11NoReturnAttr(Loc, Ctx, 0);
1642 A->setImplicit(true);
1643 return A;
1644 }
1645
1646 C11NoReturnAttr(SourceRange R, ASTContext &Ctx
1647 , unsigned SI
1648 )
1649 : InheritableAttr(attr::C11NoReturn, R, SI, false, false)
1650 {
1651 }
1652
1653 C11NoReturnAttr *clone(ASTContext &C) const;
1654 void printPretty(raw_ostream &OS,
1655 const PrintingPolicy &Policy) const;
1656 const char *getSpelling() const;
1657
1658
1659 static bool classof(const Attr *A) { return A->getKind() == attr::C11NoReturn; }
1660};
1661
1662class CDeclAttr : public InheritableAttr {
1663public:
1664 static CDeclAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1665 auto *A = new (Ctx) CDeclAttr(Loc, Ctx, 0);
1666 A->setImplicit(true);
1667 return A;
1668 }
1669
1670 CDeclAttr(SourceRange R, ASTContext &Ctx
1671 , unsigned SI
1672 )
1673 : InheritableAttr(attr::CDecl, R, SI, false, false)
1674 {
1675 }
1676
1677 CDeclAttr *clone(ASTContext &C) const;
1678 void printPretty(raw_ostream &OS,
1679 const PrintingPolicy &Policy) const;
1680 const char *getSpelling() const;
1681
1682
1683 static bool classof(const Attr *A) { return A->getKind() == attr::CDecl; }
1684};
1685
1686class CFAuditedTransferAttr : public InheritableAttr {
1687public:
1688 static CFAuditedTransferAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1689 auto *A = new (Ctx) CFAuditedTransferAttr(Loc, Ctx, 0);
1690 A->setImplicit(true);
1691 return A;
1692 }
1693
1694 CFAuditedTransferAttr(SourceRange R, ASTContext &Ctx
1695 , unsigned SI
1696 )
1697 : InheritableAttr(attr::CFAuditedTransfer, R, SI, false, false)
1698 {
1699 }
1700
1701 CFAuditedTransferAttr *clone(ASTContext &C) const;
1702 void printPretty(raw_ostream &OS,
1703 const PrintingPolicy &Policy) const;
1704 const char *getSpelling() const;
1705
1706
1707 static bool classof(const Attr *A) { return A->getKind() == attr::CFAuditedTransfer; }
1708};
1709
1710class CFConsumedAttr : public InheritableParamAttr {
1711public:
1712 static CFConsumedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1713 auto *A = new (Ctx) CFConsumedAttr(Loc, Ctx, 0);
1714 A->setImplicit(true);
1715 return A;
1716 }
1717
1718 CFConsumedAttr(SourceRange R, ASTContext &Ctx
1719 , unsigned SI
1720 )
1721 : InheritableParamAttr(attr::CFConsumed, R, SI, false, false)
1722 {
1723 }
1724
1725 CFConsumedAttr *clone(ASTContext &C) const;
1726 void printPretty(raw_ostream &OS,
1727 const PrintingPolicy &Policy) const;
1728 const char *getSpelling() const;
1729
1730
1731 static bool classof(const Attr *A) { return A->getKind() == attr::CFConsumed; }
1732};
1733
1734class CFReturnsNotRetainedAttr : public InheritableAttr {
1735public:
1736 static CFReturnsNotRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1737 auto *A = new (Ctx) CFReturnsNotRetainedAttr(Loc, Ctx, 0);
1738 A->setImplicit(true);
1739 return A;
1740 }
1741
1742 CFReturnsNotRetainedAttr(SourceRange R, ASTContext &Ctx
1743 , unsigned SI
1744 )
1745 : InheritableAttr(attr::CFReturnsNotRetained, R, SI, false, false)
1746 {
1747 }
1748
1749 CFReturnsNotRetainedAttr *clone(ASTContext &C) const;
1750 void printPretty(raw_ostream &OS,
1751 const PrintingPolicy &Policy) const;
1752 const char *getSpelling() const;
1753
1754
1755 static bool classof(const Attr *A) { return A->getKind() == attr::CFReturnsNotRetained; }
1756};
1757
1758class CFReturnsRetainedAttr : public InheritableAttr {
1759public:
1760 static CFReturnsRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1761 auto *A = new (Ctx) CFReturnsRetainedAttr(Loc, Ctx, 0);
1762 A->setImplicit(true);
1763 return A;
1764 }
1765
1766 CFReturnsRetainedAttr(SourceRange R, ASTContext &Ctx
1767 , unsigned SI
1768 )
1769 : InheritableAttr(attr::CFReturnsRetained, R, SI, false, false)
1770 {
1771 }
1772
1773 CFReturnsRetainedAttr *clone(ASTContext &C) const;
1774 void printPretty(raw_ostream &OS,
1775 const PrintingPolicy &Policy) const;
1776 const char *getSpelling() const;
1777
1778
1779 static bool classof(const Attr *A) { return A->getKind() == attr::CFReturnsRetained; }
1780};
1781
1782class CFUnknownTransferAttr : public InheritableAttr {
1783public:
1784 static CFUnknownTransferAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1785 auto *A = new (Ctx) CFUnknownTransferAttr(Loc, Ctx, 0);
1786 A->setImplicit(true);
1787 return A;
1788 }
1789
1790 CFUnknownTransferAttr(SourceRange R, ASTContext &Ctx
1791 , unsigned SI
1792 )
1793 : InheritableAttr(attr::CFUnknownTransfer, R, SI, false, false)
1794 {
1795 }
1796
1797 CFUnknownTransferAttr *clone(ASTContext &C) const;
1798 void printPretty(raw_ostream &OS,
1799 const PrintingPolicy &Policy) const;
1800 const char *getSpelling() const;
1801
1802
1803 static bool classof(const Attr *A) { return A->getKind() == attr::CFUnknownTransfer; }
1804};
1805
1806class CPUDispatchAttr : public InheritableAttr {
1807 unsigned cpus_Size;
1808 IdentifierInfo * *cpus_;
1809
1810public:
1811 static CPUDispatchAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * *Cpus, unsigned CpusSize, SourceRange Loc = SourceRange()) {
1812 auto *A = new (Ctx) CPUDispatchAttr(Loc, Ctx, Cpus, CpusSize, 0);
1813 A->setImplicit(true);
1814 return A;
1815 }
1816
1817 CPUDispatchAttr(SourceRange R, ASTContext &Ctx
1818 , IdentifierInfo * *Cpus, unsigned CpusSize
1819 , unsigned SI
1820 )
1821 : InheritableAttr(attr::CPUDispatch, R, SI, false, false)
1822 , cpus_Size(CpusSize), cpus_(new (Ctx, 16) IdentifierInfo *[cpus_Size])
1823 {
1824 std::copy(Cpus, Cpus + cpus_Size, cpus_);
1825 }
1826
1827 CPUDispatchAttr(SourceRange R, ASTContext &Ctx
1828 , unsigned SI
1829 )
1830 : InheritableAttr(attr::CPUDispatch, R, SI, false, false)
1831 , cpus_Size(0), cpus_(nullptr)
1832 {
1833 }
1834
1835 CPUDispatchAttr *clone(ASTContext &C) const;
1836 void printPretty(raw_ostream &OS,
1837 const PrintingPolicy &Policy) const;
1838 const char *getSpelling() const;
1839 typedef IdentifierInfo ** cpus_iterator;
1840 cpus_iterator cpus_begin() const { return cpus_; }
1841 cpus_iterator cpus_end() const { return cpus_ + cpus_Size; }
1842 unsigned cpus_size() const { return cpus_Size; }
1843 llvm::iterator_range<cpus_iterator> cpus() const { return llvm::make_range(cpus_begin(), cpus_end()); }
1844
1845
1846
1847
1848 static bool classof(const Attr *A) { return A->getKind() == attr::CPUDispatch; }
1849};
1850
1851class CPUSpecificAttr : public InheritableAttr {
1852 unsigned cpus_Size;
1853 IdentifierInfo * *cpus_;
1854
1855public:
1856 static CPUSpecificAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * *Cpus, unsigned CpusSize, SourceRange Loc = SourceRange()) {
1857 auto *A = new (Ctx) CPUSpecificAttr(Loc, Ctx, Cpus, CpusSize, 0);
1858 A->setImplicit(true);
1859 return A;
1860 }
1861
1862 CPUSpecificAttr(SourceRange R, ASTContext &Ctx
1863 , IdentifierInfo * *Cpus, unsigned CpusSize
1864 , unsigned SI
1865 )
1866 : InheritableAttr(attr::CPUSpecific, R, SI, false, false)
1867 , cpus_Size(CpusSize), cpus_(new (Ctx, 16) IdentifierInfo *[cpus_Size])
1868 {
1869 std::copy(Cpus, Cpus + cpus_Size, cpus_);
1870 }
1871
1872 CPUSpecificAttr(SourceRange R, ASTContext &Ctx
1873 , unsigned SI
1874 )
1875 : InheritableAttr(attr::CPUSpecific, R, SI, false, false)
1876 , cpus_Size(0), cpus_(nullptr)
1877 {
1878 }
1879
1880 CPUSpecificAttr *clone(ASTContext &C) const;
1881 void printPretty(raw_ostream &OS,
1882 const PrintingPolicy &Policy) const;
1883 const char *getSpelling() const;
1884 typedef IdentifierInfo ** cpus_iterator;
1885 cpus_iterator cpus_begin() const { return cpus_; }
1886 cpus_iterator cpus_end() const { return cpus_ + cpus_Size; }
1887 unsigned cpus_size() const { return cpus_Size; }
1888 llvm::iterator_range<cpus_iterator> cpus() const { return llvm::make_range(cpus_begin(), cpus_end()); }
1889
1890
1891
1892 IdentifierInfo *getCPUName(unsigned Index) const {
1893 return *(cpus_begin() + Index);
1894 }
1895
1896
1897 static bool classof(const Attr *A) { return A->getKind() == attr::CPUSpecific; }
1898};
1899
1900class CUDAConstantAttr : public InheritableAttr {
1901public:
1902 static CUDAConstantAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1903 auto *A = new (Ctx) CUDAConstantAttr(Loc, Ctx, 0);
1904 A->setImplicit(true);
1905 return A;
1906 }
1907
1908 CUDAConstantAttr(SourceRange R, ASTContext &Ctx
1909 , unsigned SI
1910 )
1911 : InheritableAttr(attr::CUDAConstant, R, SI, false, false)
1912 {
1913 }
1914
1915 CUDAConstantAttr *clone(ASTContext &C) const;
1916 void printPretty(raw_ostream &OS,
1917 const PrintingPolicy &Policy) const;
1918 const char *getSpelling() const;
1919
1920
1921 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAConstant; }
1922};
1923
1924class CUDADeviceAttr : public InheritableAttr {
1925public:
1926 static CUDADeviceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1927 auto *A = new (Ctx) CUDADeviceAttr(Loc, Ctx, 0);
1928 A->setImplicit(true);
1929 return A;
1930 }
1931
1932 CUDADeviceAttr(SourceRange R, ASTContext &Ctx
1933 , unsigned SI
1934 )
1935 : InheritableAttr(attr::CUDADevice, R, SI, false, false)
1936 {
1937 }
1938
1939 CUDADeviceAttr *clone(ASTContext &C) const;
1940 void printPretty(raw_ostream &OS,
1941 const PrintingPolicy &Policy) const;
1942 const char *getSpelling() const;
1943
1944
1945 static bool classof(const Attr *A) { return A->getKind() == attr::CUDADevice; }
1946};
1947
1948class CUDAGlobalAttr : public InheritableAttr {
1949public:
1950 static CUDAGlobalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1951 auto *A = new (Ctx) CUDAGlobalAttr(Loc, Ctx, 0);
1952 A->setImplicit(true);
1953 return A;
1954 }
1955
1956 CUDAGlobalAttr(SourceRange R, ASTContext &Ctx
1957 , unsigned SI
1958 )
1959 : InheritableAttr(attr::CUDAGlobal, R, SI, false, false)
1960 {
1961 }
1962
1963 CUDAGlobalAttr *clone(ASTContext &C) const;
1964 void printPretty(raw_ostream &OS,
1965 const PrintingPolicy &Policy) const;
1966 const char *getSpelling() const;
1967
1968
1969 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAGlobal; }
1970};
1971
1972class CUDAHostAttr : public InheritableAttr {
1973public:
1974 static CUDAHostAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1975 auto *A = new (Ctx) CUDAHostAttr(Loc, Ctx, 0);
1976 A->setImplicit(true);
1977 return A;
1978 }
1979
1980 CUDAHostAttr(SourceRange R, ASTContext &Ctx
1981 , unsigned SI
1982 )
1983 : InheritableAttr(attr::CUDAHost, R, SI, false, false)
1984 {
1985 }
1986
1987 CUDAHostAttr *clone(ASTContext &C) const;
1988 void printPretty(raw_ostream &OS,
1989 const PrintingPolicy &Policy) const;
1990 const char *getSpelling() const;
1991
1992
1993 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAHost; }
1994};
1995
1996class CUDAInvalidTargetAttr : public InheritableAttr {
1997public:
1998 static CUDAInvalidTargetAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1999 auto *A = new (Ctx) CUDAInvalidTargetAttr(Loc, Ctx, 0);
2000 A->setImplicit(true);
2001 return A;
2002 }
2003
2004 CUDAInvalidTargetAttr(SourceRange R, ASTContext &Ctx
2005 , unsigned SI
2006 )
2007 : InheritableAttr(attr::CUDAInvalidTarget, R, SI, false, false)
2008 {
2009 }
2010
2011 CUDAInvalidTargetAttr *clone(ASTContext &C) const;
2012 void printPretty(raw_ostream &OS,
2013 const PrintingPolicy &Policy) const;
2014 const char *getSpelling() const;
2015
2016
2017 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAInvalidTarget; }
2018};
2019
2020class CUDALaunchBoundsAttr : public InheritableAttr {
2021Expr * maxThreads;
2022
2023Expr * minBlocks;
2024
2025public:
2026 static CUDALaunchBoundsAttr *CreateImplicit(ASTContext &Ctx, Expr * MaxThreads, Expr * MinBlocks, SourceRange Loc = SourceRange()) {
2027 auto *A = new (Ctx) CUDALaunchBoundsAttr(Loc, Ctx, MaxThreads, MinBlocks, 0);
2028 A->setImplicit(true);
2029 return A;
2030 }
2031
2032 CUDALaunchBoundsAttr(SourceRange R, ASTContext &Ctx
2033 , Expr * MaxThreads
2034 , Expr * MinBlocks
2035 , unsigned SI
2036 )
2037 : InheritableAttr(attr::CUDALaunchBounds, R, SI, false, false)
2038 , maxThreads(MaxThreads)
2039 , minBlocks(MinBlocks)
2040 {
2041 }
2042
2043 CUDALaunchBoundsAttr(SourceRange R, ASTContext &Ctx
2044 , Expr * MaxThreads
2045 , unsigned SI
2046 )
2047 : InheritableAttr(attr::CUDALaunchBounds, R, SI, false, false)
2048 , maxThreads(MaxThreads)
2049 , minBlocks()
2050 {
2051 }
2052
2053 CUDALaunchBoundsAttr *clone(ASTContext &C) const;
2054 void printPretty(raw_ostream &OS,
2055 const PrintingPolicy &Policy) const;
2056 const char *getSpelling() const;
2057 Expr * getMaxThreads() const {
2058 return maxThreads;
2059 }
2060
2061 Expr * getMinBlocks() const {
2062 return minBlocks;
2063 }
2064
2065
2066
2067 static bool classof(const Attr *A) { return A->getKind() == attr::CUDALaunchBounds; }
2068};
2069
2070class CUDASharedAttr : public InheritableAttr {
2071public:
2072 static CUDASharedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2073 auto *A = new (Ctx) CUDASharedAttr(Loc, Ctx, 0);
2074 A->setImplicit(true);
2075 return A;
2076 }
2077
2078 CUDASharedAttr(SourceRange R, ASTContext &Ctx
2079 , unsigned SI
2080 )
2081 : InheritableAttr(attr::CUDAShared, R, SI, false, false)
2082 {
2083 }
2084
2085 CUDASharedAttr *clone(ASTContext &C) const;
2086 void printPretty(raw_ostream &OS,
2087 const PrintingPolicy &Policy) const;
2088 const char *getSpelling() const;
2089
2090
2091 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAShared; }
2092};
2093
2094class CXX11NoReturnAttr : public InheritableAttr {
2095public:
2096 static CXX11NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2097 auto *A = new (Ctx) CXX11NoReturnAttr(Loc, Ctx, 0);
2098 A->setImplicit(true);
2099 return A;
2100 }
2101
2102 CXX11NoReturnAttr(SourceRange R, ASTContext &Ctx
2103 , unsigned SI
2104 )
2105 : InheritableAttr(attr::CXX11NoReturn, R, SI, false, false)
2106 {
2107 }
2108
2109 CXX11NoReturnAttr *clone(ASTContext &C) const;
2110 void printPretty(raw_ostream &OS,
2111 const PrintingPolicy &Policy) const;
2112 const char *getSpelling() const;
2113
2114
2115 static bool classof(const Attr *A) { return A->getKind() == attr::CXX11NoReturn; }
2116};
2117
2118class CallableWhenAttr : public InheritableAttr {
2119public:
2120 enum ConsumedState {
2121 Unknown,
2122 Consumed,
2123 Unconsumed
2124 };
2125private:
2126 unsigned callableStates_Size;
2127 ConsumedState *callableStates_;
2128
2129public:
2130 static CallableWhenAttr *CreateImplicit(ASTContext &Ctx, ConsumedState *CallableStates, unsigned CallableStatesSize, SourceRange Loc = SourceRange()) {
2131 auto *A = new (Ctx) CallableWhenAttr(Loc, Ctx, CallableStates, CallableStatesSize, 0);
2132 A->setImplicit(true);
2133 return A;
2134 }
2135
2136 CallableWhenAttr(SourceRange R, ASTContext &Ctx
2137 , ConsumedState *CallableStates, unsigned CallableStatesSize
2138 , unsigned SI
2139 )
2140 : InheritableAttr(attr::CallableWhen, R, SI, false, false)
2141 , callableStates_Size(CallableStatesSize), callableStates_(new (Ctx, 16) ConsumedState[callableStates_Size])
2142 {
2143 std::copy(CallableStates, CallableStates + callableStates_Size, callableStates_);
2144 }
2145
2146 CallableWhenAttr(SourceRange R, ASTContext &Ctx
2147 , unsigned SI
2148 )
2149 : InheritableAttr(attr::CallableWhen, R, SI, false, false)
2150 , callableStates_Size(0), callableStates_(nullptr)
2151 {
2152 }
2153
2154 CallableWhenAttr *clone(ASTContext &C) const;
2155 void printPretty(raw_ostream &OS,
2156 const PrintingPolicy &Policy) const;
2157 const char *getSpelling() const;
2158 typedef ConsumedState* callableStates_iterator;
2159 callableStates_iterator callableStates_begin() const { return callableStates_; }
2160 callableStates_iterator callableStates_end() const { return callableStates_ + callableStates_Size; }
2161 unsigned callableStates_size() const { return callableStates_Size; }
2162 llvm::iterator_range<callableStates_iterator> callableStates() const { return llvm::make_range(callableStates_begin(), callableStates_end()); }
2163
2164
2165 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
2166 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
2167 .Case("unknown", CallableWhenAttr::Unknown)
2168 .Case("consumed", CallableWhenAttr::Consumed)
2169 .Case("unconsumed", CallableWhenAttr::Unconsumed)
2170 .Default(Optional<ConsumedState>());
2171 if (R) {
2172 Out = *R;
2173 return true;
2174 }
2175 return false;
2176 }
2177
2178 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
2179 switch(Val) {
2180 case CallableWhenAttr::Unknown: return "unknown";
2181 case CallableWhenAttr::Consumed: return "consumed";
2182 case CallableWhenAttr::Unconsumed: return "unconsumed";
2183 }
2184 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2184)
;
2185 }
2186
2187
2188 static bool classof(const Attr *A) { return A->getKind() == attr::CallableWhen; }
2189};
2190
2191class CallbackAttr : public InheritableAttr {
2192 unsigned encoding_Size;
2193 int *encoding_;
2194
2195public:
2196 static CallbackAttr *CreateImplicit(ASTContext &Ctx, int *Encoding, unsigned EncodingSize, SourceRange Loc = SourceRange()) {
2197 auto *A = new (Ctx) CallbackAttr(Loc, Ctx, Encoding, EncodingSize, 0);
2198 A->setImplicit(true);
2199 return A;
2200 }
2201
2202 CallbackAttr(SourceRange R, ASTContext &Ctx
2203 , int *Encoding, unsigned EncodingSize
2204 , unsigned SI
2205 )
2206 : InheritableAttr(attr::Callback, R, SI, false, false)
2207 , encoding_Size(EncodingSize), encoding_(new (Ctx, 16) int[encoding_Size])
2208 {
2209 std::copy(Encoding, Encoding + encoding_Size, encoding_);
2210 }
2211
2212 CallbackAttr(SourceRange R, ASTContext &Ctx
2213 , unsigned SI
2214 )
2215 : InheritableAttr(attr::Callback, R, SI, false, false)
2216 , encoding_Size(0), encoding_(nullptr)
2217 {
2218 }
2219
2220 CallbackAttr *clone(ASTContext &C) const;
2221 void printPretty(raw_ostream &OS,
2222 const PrintingPolicy &Policy) const;
2223 const char *getSpelling() const;
2224 typedef int* encoding_iterator;
2225 encoding_iterator encoding_begin() const { return encoding_; }
2226 encoding_iterator encoding_end() const { return encoding_ + encoding_Size; }
2227 unsigned encoding_size() const { return encoding_Size; }
2228 llvm::iterator_range<encoding_iterator> encoding() const { return llvm::make_range(encoding_begin(), encoding_end()); }
2229
2230
2231
2232
2233 static bool classof(const Attr *A) { return A->getKind() == attr::Callback; }
2234};
2235
2236class CapabilityAttr : public InheritableAttr {
2237unsigned nameLength;
2238char *name;
2239
2240public:
2241 enum Spelling {
2242 GNU_capability = 0,
2243 CXX11_clang_capability = 1,
2244 GNU_shared_capability = 2,
2245 CXX11_clang_shared_capability = 3
2246 };
2247
2248 static CapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
2249 auto *A = new (Ctx) CapabilityAttr(Loc, Ctx, Name, S);
2250 A->setImplicit(true);
2251 return A;
2252 }
2253
2254 CapabilityAttr(SourceRange R, ASTContext &Ctx
2255 , llvm::StringRef Name
2256 , unsigned SI
2257 )
2258 : InheritableAttr(attr::Capability, R, SI, false, false)
2259 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
2260 {
2261 if (!Name.empty())
2262 std::memcpy(name, Name.data(), nameLength);
2263 }
2264
2265 CapabilityAttr *clone(ASTContext &C) const;
2266 void printPretty(raw_ostream &OS,
2267 const PrintingPolicy &Policy) const;
2268 const char *getSpelling() const;
2269 Spelling getSemanticSpelling() const {
2270 switch (SpellingListIndex) {
2271 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2271)
;
2272 case 0: return GNU_capability;
2273 case 1: return CXX11_clang_capability;
2274 case 2: return GNU_shared_capability;
2275 case 3: return CXX11_clang_shared_capability;
2276 }
2277 }
2278 bool isShared() const { return SpellingListIndex == 2 ||
2279 SpellingListIndex == 3; }
2280 llvm::StringRef getName() const {
2281 return llvm::StringRef(name, nameLength);
2282 }
2283 unsigned getNameLength() const {
2284 return nameLength;
2285 }
2286 void setName(ASTContext &C, llvm::StringRef S) {
2287 nameLength = S.size();
2288 this->name = new (C, 1) char [nameLength];
2289 if (!S.empty())
2290 std::memcpy(this->name, S.data(), nameLength);
2291 }
2292
2293
2294 bool isMutex() const { return getName().equals_lower("mutex"); }
2295 bool isRole() const { return getName().equals_lower("role"); }
2296
2297
2298 static bool classof(const Attr *A) { return A->getKind() == attr::Capability; }
2299};
2300
2301class CapturedRecordAttr : public InheritableAttr {
2302public:
2303 static CapturedRecordAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2304 auto *A = new (Ctx) CapturedRecordAttr(Loc, Ctx, 0);
2305 A->setImplicit(true);
2306 return A;
2307 }
2308
2309 CapturedRecordAttr(SourceRange R, ASTContext &Ctx
2310 , unsigned SI
2311 )
2312 : InheritableAttr(attr::CapturedRecord, R, SI, false, false)
2313 {
2314 }
2315
2316 CapturedRecordAttr *clone(ASTContext &C) const;
2317 void printPretty(raw_ostream &OS,
2318 const PrintingPolicy &Policy) const;
2319 const char *getSpelling() const;
2320
2321
2322 static bool classof(const Attr *A) { return A->getKind() == attr::CapturedRecord; }
2323};
2324
2325class CarriesDependencyAttr : public InheritableParamAttr {
2326public:
2327 static CarriesDependencyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2328 auto *A = new (Ctx) CarriesDependencyAttr(Loc, Ctx, 0);
2329 A->setImplicit(true);
2330 return A;
2331 }
2332
2333 CarriesDependencyAttr(SourceRange R, ASTContext &Ctx
2334 , unsigned SI
2335 )
2336 : InheritableParamAttr(attr::CarriesDependency, R, SI, false, false)
2337 {
2338 }
2339
2340 CarriesDependencyAttr *clone(ASTContext &C) const;
2341 void printPretty(raw_ostream &OS,
2342 const PrintingPolicy &Policy) const;
2343 const char *getSpelling() const;
2344
2345
2346 static bool classof(const Attr *A) { return A->getKind() == attr::CarriesDependency; }
2347};
2348
2349class CleanupAttr : public InheritableAttr {
2350FunctionDecl * functionDecl;
2351
2352public:
2353 static CleanupAttr *CreateImplicit(ASTContext &Ctx, FunctionDecl * FunctionDecl, SourceRange Loc = SourceRange()) {
2354 auto *A = new (Ctx) CleanupAttr(Loc, Ctx, FunctionDecl, 0);
2355 A->setImplicit(true);
2356 return A;
2357 }
2358
2359 CleanupAttr(SourceRange R, ASTContext &Ctx
2360 , FunctionDecl * FunctionDecl
2361 , unsigned SI
2362 )
2363 : InheritableAttr(attr::Cleanup, R, SI, false, false)
2364 , functionDecl(FunctionDecl)
2365 {
2366 }
2367
2368 CleanupAttr *clone(ASTContext &C) const;
2369 void printPretty(raw_ostream &OS,
2370 const PrintingPolicy &Policy) const;
2371 const char *getSpelling() const;
2372 FunctionDecl * getFunctionDecl() const {
2373 return functionDecl;
2374 }
2375
2376
2377
2378 static bool classof(const Attr *A) { return A->getKind() == attr::Cleanup; }
2379};
2380
2381class CodeSegAttr : public InheritableAttr {
2382unsigned nameLength;
2383char *name;
2384
2385public:
2386 static CodeSegAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
2387 auto *A = new (Ctx) CodeSegAttr(Loc, Ctx, Name, 0);
2388 A->setImplicit(true);
2389 return A;
2390 }
2391
2392 CodeSegAttr(SourceRange R, ASTContext &Ctx
2393 , llvm::StringRef Name
2394 , unsigned SI
2395 )
2396 : InheritableAttr(attr::CodeSeg, R, SI, false, false)
2397 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
2398 {
2399 if (!Name.empty())
2400 std::memcpy(name, Name.data(), nameLength);
2401 }
2402
2403 CodeSegAttr *clone(ASTContext &C) const;
2404 void printPretty(raw_ostream &OS,
2405 const PrintingPolicy &Policy) const;
2406 const char *getSpelling() const;
2407 llvm::StringRef getName() const {
2408 return llvm::StringRef(name, nameLength);
2409 }
2410 unsigned getNameLength() const {
2411 return nameLength;
2412 }
2413 void setName(ASTContext &C, llvm::StringRef S) {
2414 nameLength = S.size();
2415 this->name = new (C, 1) char [nameLength];
2416 if (!S.empty())
2417 std::memcpy(this->name, S.data(), nameLength);
2418 }
2419
2420
2421
2422 static bool classof(const Attr *A) { return A->getKind() == attr::CodeSeg; }
2423};
2424
2425class ColdAttr : public InheritableAttr {
2426public:
2427 static ColdAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2428 auto *A = new (Ctx) ColdAttr(Loc, Ctx, 0);
2429 A->setImplicit(true);
2430 return A;
2431 }
2432
2433 ColdAttr(SourceRange R, ASTContext &Ctx
2434 , unsigned SI
2435 )
2436 : InheritableAttr(attr::Cold, R, SI, false, false)
2437 {
2438 }
2439
2440 ColdAttr *clone(ASTContext &C) const;
2441 void printPretty(raw_ostream &OS,
2442 const PrintingPolicy &Policy) const;
2443 const char *getSpelling() const;
2444
2445
2446 static bool classof(const Attr *A) { return A->getKind() == attr::Cold; }
2447};
2448
2449class CommonAttr : public InheritableAttr {
2450public:
2451 static CommonAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2452 auto *A = new (Ctx) CommonAttr(Loc, Ctx, 0);
2453 A->setImplicit(true);
2454 return A;
2455 }
2456
2457 CommonAttr(SourceRange R, ASTContext &Ctx
2458 , unsigned SI
2459 )
2460 : InheritableAttr(attr::Common, R, SI, false, false)
2461 {
2462 }
2463
2464 CommonAttr *clone(ASTContext &C) const;
2465 void printPretty(raw_ostream &OS,
2466 const PrintingPolicy &Policy) const;
2467 const char *getSpelling() const;
2468
2469
2470 static bool classof(const Attr *A) { return A->getKind() == attr::Common; }
2471};
2472
2473class ConstAttr : public InheritableAttr {
2474public:
2475 static ConstAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2476 auto *A = new (Ctx) ConstAttr(Loc, Ctx, 0);
2477 A->setImplicit(true);
2478 return A;
2479 }
2480
2481 ConstAttr(SourceRange R, ASTContext &Ctx
2482 , unsigned SI
2483 )
2484 : InheritableAttr(attr::Const, R, SI, false, false)
2485 {
2486 }
2487
2488 ConstAttr *clone(ASTContext &C) const;
2489 void printPretty(raw_ostream &OS,
2490 const PrintingPolicy &Policy) const;
2491 const char *getSpelling() const;
2492
2493
2494 static bool classof(const Attr *A) { return A->getKind() == attr::Const; }
2495};
2496
2497class ConstructorAttr : public InheritableAttr {
2498int priority;
2499
2500public:
2501 static ConstructorAttr *CreateImplicit(ASTContext &Ctx, int Priority, SourceRange Loc = SourceRange()) {
2502 auto *A = new (Ctx) ConstructorAttr(Loc, Ctx, Priority, 0);
2503 A->setImplicit(true);
2504 return A;
2505 }
2506
2507 ConstructorAttr(SourceRange R, ASTContext &Ctx
2508 , int Priority
2509 , unsigned SI
2510 )
2511 : InheritableAttr(attr::Constructor, R, SI, false, false)
2512 , priority(Priority)
2513 {
2514 }
2515
2516 ConstructorAttr(SourceRange R, ASTContext &Ctx
2517 , unsigned SI
2518 )
2519 : InheritableAttr(attr::Constructor, R, SI, false, false)
2520 , priority()
2521 {
2522 }
2523
2524 ConstructorAttr *clone(ASTContext &C) const;
2525 void printPretty(raw_ostream &OS,
2526 const PrintingPolicy &Policy) const;
2527 const char *getSpelling() const;
2528 int getPriority() const {
2529 return priority;
2530 }
2531
2532 static const int DefaultPriority = 65535;
2533
2534
2535
2536 static bool classof(const Attr *A) { return A->getKind() == attr::Constructor; }
2537};
2538
2539class ConsumableAttr : public InheritableAttr {
2540public:
2541 enum ConsumedState {
2542 Unknown,
2543 Consumed,
2544 Unconsumed
2545 };
2546private:
2547 ConsumedState defaultState;
2548
2549public:
2550 static ConsumableAttr *CreateImplicit(ASTContext &Ctx, ConsumedState DefaultState, SourceRange Loc = SourceRange()) {
2551 auto *A = new (Ctx) ConsumableAttr(Loc, Ctx, DefaultState, 0);
2552 A->setImplicit(true);
2553 return A;
2554 }
2555
2556 ConsumableAttr(SourceRange R, ASTContext &Ctx
2557 , ConsumedState DefaultState
2558 , unsigned SI
2559 )
2560 : InheritableAttr(attr::Consumable, R, SI, false, false)
2561 , defaultState(DefaultState)
2562 {
2563 }
2564
2565 ConsumableAttr *clone(ASTContext &C) const;
2566 void printPretty(raw_ostream &OS,
2567 const PrintingPolicy &Policy) const;
2568 const char *getSpelling() const;
2569 ConsumedState getDefaultState() const {
2570 return defaultState;
2571 }
2572
2573 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
2574 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
2575 .Case("unknown", ConsumableAttr::Unknown)
2576 .Case("consumed", ConsumableAttr::Consumed)
2577 .Case("unconsumed", ConsumableAttr::Unconsumed)
2578 .Default(Optional<ConsumedState>());
2579 if (R) {
2580 Out = *R;
2581 return true;
2582 }
2583 return false;
2584 }
2585
2586 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
2587 switch(Val) {
2588 case ConsumableAttr::Unknown: return "unknown";
2589 case ConsumableAttr::Consumed: return "consumed";
2590 case ConsumableAttr::Unconsumed: return "unconsumed";
2591 }
2592 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-9~svn362543/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2592)
;
2593 }
2594
2595
2596 static bool classof(const Attr *A) { return A->getKind() == attr::Consumable; }
2597};
2598
2599class ConsumableAutoCastAttr : public InheritableAttr {
2600public:
2601 static ConsumableAutoCastAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2602 auto *A = new (Ctx) ConsumableAutoCastAttr(Loc, Ctx, 0);
2603 A->setImplicit(true);
2604 return A;
2605 }
2606
2607 ConsumableAutoCastAttr(SourceRange R, ASTContext &Ctx
2608 , unsigned SI
2609 )
2610 : InheritableAttr(attr::ConsumableAutoCast, R, SI, false, false)
2611 {
2612 }
2613
2614 ConsumableAutoCastAttr *clone(ASTContext &C) const;
2615 void printPretty(raw_ostream &OS,
2616 const PrintingPolicy &Policy) const;
2617 const char *getSpelling() const;
2618
2619
2620 static bool classof(const Attr *A) { return A->getKind() == attr::ConsumableAutoCast; }
2621};
2622
2623class ConsumableSetOnReadAttr : public InheritableAttr {
2624public:
2625 static ConsumableSetOnReadAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2626 auto *A = new (Ctx) ConsumableSetOnReadAttr(Loc, Ctx, 0);
2627 A->setImplicit(true);
2628 return A;
2629 }
2630
2631 ConsumableSetOnReadAttr(SourceRange R, ASTContext &Ctx
2632 , unsigned SI
2633 )
2634 : InheritableAttr(attr::ConsumableSetOnRead, R, SI, false, false)
2635 {
2636 }
2637
2638 ConsumableSetOnReadAttr *clone(ASTContext &C) const;
2639 void printPretty(raw_ostream &OS,
2640 const PrintingPolicy &Policy) const;
2641 const char *getSpelling() const;
2642
2643
2644 static bool classof(const Attr *A) { return A->getKind() == attr::ConsumableSetOnRead; }
2645};
2646
2647class ConvergentAttr : public InheritableAttr {
2648public:
2649 static ConvergentAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2650 auto *A = new (Ctx) ConvergentAttr(Loc, Ctx, 0);
2651 A->setImplicit(true);
2652 return A;
2653 }
2654
2655 ConvergentAttr(SourceRange R, ASTContext &Ctx
2656 , unsigned SI
2657 )
2658 : InheritableAttr(attr::Convergent, R, SI, false, false)
2659 {
2660 }
2661
2662 ConvergentAttr *clone(ASTContext &C) const;
2663 void printPretty(raw_ostream &OS,
2664 const PrintingPolicy &Policy) const;
2665 const char *getSpelling() const;
2666
2667
2668 static bool classof(const Attr *A) { return A->getKind() == attr::Convergent; }
2669};
2670
2671class DLLExportAttr : public InheritableAttr {
2672public:
2673 static DLLExportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2674 auto *A = new (Ctx) DLLExportAttr(Loc, Ctx, 0);
2675 A->setImplicit(true);
2676 return A;
2677 }
2678
2679 DLLExportAttr(SourceRange R, ASTContext &Ctx
2680 , unsigned SI
2681 )
2682 : InheritableAttr(attr::DLLExport, R, SI, false, false)
2683 {
2684 }
2685
2686 DLLExportAttr *clone(ASTContext &C) const;
2687 void printPretty(raw_ostream &OS,
2688 const PrintingPolicy &Policy) const;
2689 const char *getSpelling() const;
2690
2691
2692 static bool classof(const Attr *A) { return A->getKind() == attr::DLLExport; }
2693};
2694
2695class DLLExportStaticLocalAttr : public InheritableAttr {
2696public:
2697 static DLLExportStaticLocalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2698 auto *A = new (Ctx) DLLExportStaticLocalAttr(Loc, Ctx, 0);
2699 A->setImplicit(true);
2700 return A;
2701 }
2702
2703 DLLExportStaticLocalAttr(SourceRange R, ASTContext &Ctx
2704 , unsigned SI
2705 )
2706 : InheritableAttr(attr::DLLExportStaticLocal, R, SI, false, false)
2707 {
2708 }
2709
2710 DLLExportStaticLocalAttr *clone(ASTContext &C) const;
2711 void printPretty(raw_ostream &OS,
2712 const PrintingPolicy &Policy) const;
2713 const char *getSpelling() const;
2714
2715
2716 static bool classof(const Attr *A) { return A->getKind() == attr::DLLExportStaticLocal; }
2717};
2718
2719class DLLImportAttr : public InheritableAttr {
2720public:
2721 static DLLImportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2722 auto *A = new (Ctx) DLLImportAttr(Loc, Ctx, 0);
2723 A->setImplicit(true);
2724 return A;
2725 }
2726
2727 DLLImportAttr(SourceRange R, ASTContext &Ctx
2728 , unsigned SI
2729 )
2730 : InheritableAttr(attr::DLLImport, R, SI, false, false)
2731 {
2732 }
2733
2734 DLLImportAttr *clone(ASTContext &C) const;
2735 void printPretty(raw_ostream &OS,
2736 const PrintingPolicy &Policy) const;
2737 const char *getSpelling() const;
2738
2739private:
2740 bool PropagatedToBaseTemplate = false;
2741
2742public:
2743 void setPropagatedToBaseTemplate() { PropagatedToBaseTemplate = true; }
2744 bool wasPropagatedToBaseTemplate() { return PropagatedToBaseTemplate; }
2745
2746
2747 static bool classof(const Attr *A) { return A->getKind() == attr::DLLImport; }
2748};
2749
2750class DLLImportStaticLocalAttr : public InheritableAttr {
2751public:
2752 static DLLImportStaticLocalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2753 auto *A = new (Ctx) DLLImportStaticLocalAttr(Loc, Ctx, 0);
2754 A->setImplicit(true);
2755 return A;
2756 }
2757
2758 DLLImportStaticLocalAttr(SourceRange R, ASTContext &Ctx
2759 , unsigned SI
2760 )
2761 : InheritableAttr(attr::DLLImportStaticLocal, R, SI, false, false)
2762 {
2763 }
2764
2765 DLLImportStaticLocalAttr *clone(ASTContext &C) const;
2766 void printPretty(raw_ostream &OS,
2767 const PrintingPolicy &Policy) const;
2768 const char *getSpelling() const;
2769
2770
2771 static bool classof(const Attr *A) { return A->getKind() == attr::DLLImportStaticLocal; }
2772};
2773
2774class DeprecatedAttr : public InheritableAttr {
2775unsigned messageLength;
2776char *message;
2777
2778unsigned replacementLength;
2779char *replacement;
2780
2781public:
2782 static DeprecatedAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Message, llvm::StringRef Replacement, SourceRange Loc = SourceRange()) {
2783 auto *A = new (Ctx) DeprecatedAttr(Loc, Ctx, Message, Replacement, 0);
2784 A->setImplicit(true);
2785 return A;
2786 }
2787
2788 DeprecatedAttr(SourceRange R, ASTContext &Ctx
2789 , llvm::StringRef Message
2790 , llvm::StringRef Replacement
2791 , unsigned SI
2792 )
2793 : InheritableAttr(attr::Deprecated, R, SI, false, false)
2794 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
2795 , replacementLength(Replacement.size()),replacement(new (Ctx, 1) char[replacementLength])
2796 {
2797 if (!Message.empty())
2798 std::memcpy(message, Message.data(), messageLength);
2799 if (!Replacement.empty())
2800 std::memcpy(replacement, Replacement.data(), replacementLength);
2801 }
2802
2803 DeprecatedAttr(SourceRange R, ASTContext &Ctx
2804 , unsigned SI
2805 )
2806 : InheritableAttr(attr::Deprecated, R, SI, false, false)
2807 , messageLength(0),message(nullptr)
2808 , replacementLength(0),replacement(nullptr)
2809 {
2810 }
2811
2812 DeprecatedAttr *clone(ASTContext &C) const;
2813 void printPretty(raw_ostream &OS,
2814 const PrintingPolicy &Policy) const;
2815 const char *getSpelling() const;
2816 llvm::StringRef getMessage() const {
2817 return llvm::StringRef(message, messageLength);
2818 }
2819 unsigned getMessageLength() const {
2820 return messageLength;
2821 }
2822 void setMessage(ASTContext &C, llvm::StringRef S) {
2823 messageLength = S.size();
2824 this->message = new (C, 1) char [messageLength];
2825 if (!S.empty())
2826 std::memcpy(this->message, S.data(), messageLength);
2827 }
2828
2829 llvm::StringRef getReplacement() const {
2830 return llvm::StringRef(replacement, replacementLength);
2831 }
2832 unsigned getReplacementLength() const {
2833 return replacementLength;
2834 }
2835 void setReplacement(ASTContext &C, llvm::StringRef S) {
2836 replacementLength = S.size();
2837 this->replacement = new (C, 1) char [replacementLength];
2838 if (!S.empty())
2839 std::memcpy(this->replacement, S.data(), replacementLength);
2840 }
2841
2842
2843
2844 static bool classof(const Attr *A) { return A->getKind() == attr::Deprecated; }
2845};
2846
2847class DestructorAttr : public InheritableAttr {
2848int priority;
2849
2850public:
2851 static DestructorAttr *CreateImplicit(ASTContext &Ctx, int Priority, SourceRange Loc = SourceRange()) {
2852 auto *A = new (Ctx) DestructorAttr(Loc, Ctx, Priority, 0);
2853 A->setImplicit(true);
2854 return A;
2855 }
2856
2857 DestructorAttr(SourceRange R, ASTContext &Ctx
2858 , int Priority
2859 , unsigned SI
2860 )
2861 : InheritableAttr(attr::Destructor, R, SI, false, false)
2862 , priority(Priority)
2863 {
2864 }
2865
2866 DestructorAttr(SourceRange R, ASTContext &Ctx
2867 , unsigned SI
2868 )
2869 : InheritableAttr(attr::Destructor, R, SI, false, false)
2870 , priority()
2871 {
2872 }
2873
2874 DestructorAttr *clone(ASTContext &C) const;
2875 void printPretty(raw_ostream &OS,
2876 const PrintingPolicy &Policy) const;
2877 const char *getSpelling() const;
2878 int getPriority() const {
2879 return priority;
2880 }
2881
2882 static const int DefaultPriority = 65535;
2883
2884
2885
2886 static bool classof(const Attr *A) { return A->getKind() == attr::Destructor; }
2887};
2888
2889class DiagnoseIfAttr : public InheritableAttr {
2890Expr * cond;
2891
2892unsigned messageLength;
2893char *message;
2894
2895public:
2896 enum DiagnosticType {
2897 DT_Error,
2898 DT_Warning
2899 };
2900private:
2901 DiagnosticType diagnosticType;
2902
2903bool argDependent;
2904
2905NamedDecl * parent;
2906
2907public:
2908 static DiagnoseIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, DiagnosticType DiagnosticType, bool ArgDependent, NamedDecl * Parent, SourceRange Loc = SourceRange()) {
2909 auto *A = new (Ctx) DiagnoseIfAttr(Loc, Ctx, Cond, Message, DiagnosticType, ArgDependent, Parent, 0);
2910 A->setImplicit(true);
2911 return A;
2912 }
2913
2914 static DiagnoseIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, DiagnosticType DiagnosticType, SourceRange Loc = SourceRange()) {
2915 auto *A = new (Ctx) DiagnoseIfAttr(Loc, Ctx, Cond, Message, DiagnosticType, 0);
2916 A->setImplicit(true);
2917 return A;
2918 }
2919
2920 DiagnoseIfAttr(SourceRange R, ASTContext &Ctx
2921 , Expr * Cond
2922 , llvm::StringRef Message
2923 , DiagnosticType DiagnosticType
2924 , bool ArgDependent
2925 , NamedDecl * Parent
2926 , unsigned SI
2927 )
2928 : InheritableAttr(attr::DiagnoseIf, R, SI, true, true)
2929 , cond(Cond)
2930 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
2931 , diagnosticType(DiagnosticType)
2932 , argDependent(ArgDependent)
2933 , parent(Parent)
2934 {
2935 if (!Message.empty())
2936 std::memcpy(message, Message.data(), messageLength);
2937 }
2938
2939 DiagnoseIfAttr(SourceRange R, ASTContext &Ctx
2940 , Expr * Cond
2941 , llvm::StringRef Message
2942 , DiagnosticType DiagnosticType
2943 , unsigned SI
2944 )
2945 : InheritableAttr(attr::DiagnoseIf, R, SI, true, true)
2946 , cond(Cond)
2947 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
2948 , diagnosticType(DiagnosticType)
2949 , argDependent()
2950 , parent()
2951 {
2952 if (!Message.empty())
2953 std::memcpy(message, Message.data(), messageLength);
2954 }
2955
2956 DiagnoseIfAttr *clone(ASTContext &C) const;
2957 void printPretty(raw_ostream &OS,
2958 const PrintingPolicy &Policy) const;
2959 const char *getSpelling() const;
2960 Expr * getCond() const {
2961 return cond;
2962 }
2963
2964 llvm::StringRef getMessage() const {
2965 return llvm::StringRef(message, messageLength);
2966 }
2967 unsigned getMessageLength() const {
2968 return messageLength;
2969 }
2970 void setMessage(ASTContext &C, llvm::StringRef S) {
2971 messageLength = S.size();
2972 this->message = new (C, 1) char [messageLength];
2973