Bug Summary

File:tools/clang/lib/Sema/SemaTemplateInstantiate.cpp
Warning:line 3707, 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-eagerly-assume -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 -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-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/lib/Sema -I /build/llvm-toolchain-snapshot-7~svn326246/tools/clang/lib/Sema -I /build/llvm-toolchain-snapshot-7~svn326246/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn326246/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn326246/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.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-7~svn326246/build-llvm/tools/clang/lib/Sema -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-02-28-041547-14988-1 -x c++ /build/llvm-toolchain-snapshot-7~svn326246/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp

/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp

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

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