File: | clang/lib/Sema/TreeTransform.h |
Warning: | line 5617, column 24 Forming reference to null pointer |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===------- SemaTemplateInstantiate.cpp - C++ Template Instantiation ------===/ | |||
2 | // | |||
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |||
4 | // See https://llvm.org/LICENSE.txt for license information. | |||
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |||
6 | //===----------------------------------------------------------------------===/ | |||
7 | // | |||
8 | // This file implements C++ template instantiation. | |||
9 | // | |||
10 | //===----------------------------------------------------------------------===/ | |||
11 | ||||
12 | #include "TreeTransform.h" | |||
13 | #include "clang/AST/ASTConsumer.h" | |||
14 | #include "clang/AST/ASTContext.h" | |||
15 | #include "clang/AST/ASTLambda.h" | |||
16 | #include "clang/AST/ASTMutationListener.h" | |||
17 | #include "clang/AST/DeclTemplate.h" | |||
18 | #include "clang/AST/Expr.h" | |||
19 | #include "clang/AST/PrettyDeclStackTrace.h" | |||
20 | #include "clang/AST/TypeVisitor.h" | |||
21 | #include "clang/Basic/LangOptions.h" | |||
22 | #include "clang/Basic/Stack.h" | |||
23 | #include "clang/Basic/TargetInfo.h" | |||
24 | #include "clang/Sema/DeclSpec.h" | |||
25 | #include "clang/Sema/Initialization.h" | |||
26 | #include "clang/Sema/Lookup.h" | |||
27 | #include "clang/Sema/SemaConcept.h" | |||
28 | #include "clang/Sema/SemaInternal.h" | |||
29 | #include "clang/Sema/Template.h" | |||
30 | #include "clang/Sema/TemplateDeduction.h" | |||
31 | #include "clang/Sema/TemplateInstCallback.h" | |||
32 | #include "llvm/Support/TimeProfiler.h" | |||
33 | ||||
34 | using namespace clang; | |||
35 | using namespace sema; | |||
36 | ||||
37 | //===----------------------------------------------------------------------===/ | |||
38 | // Template Instantiation Support | |||
39 | //===----------------------------------------------------------------------===/ | |||
40 | ||||
41 | /// Retrieve the template argument list(s) that should be used to | |||
42 | /// instantiate the definition of the given declaration. | |||
43 | /// | |||
44 | /// \param D the declaration for which we are computing template instantiation | |||
45 | /// arguments. | |||
46 | /// | |||
47 | /// \param Innermost if non-NULL, the innermost template argument list. | |||
48 | /// | |||
49 | /// \param RelativeToPrimary true if we should get the template | |||
50 | /// arguments relative to the primary template, even when we're | |||
51 | /// dealing with a specialization. This is only relevant for function | |||
52 | /// template specializations. | |||
53 | /// | |||
54 | /// \param Pattern If non-NULL, indicates the pattern from which we will be | |||
55 | /// instantiating the definition of the given declaration, \p D. This is | |||
56 | /// used to determine the proper set of template instantiation arguments for | |||
57 | /// friend function template specializations. | |||
58 | MultiLevelTemplateArgumentList | |||
59 | Sema::getTemplateInstantiationArgs(NamedDecl *D, | |||
60 | const TemplateArgumentList *Innermost, | |||
61 | bool RelativeToPrimary, | |||
62 | const FunctionDecl *Pattern) { | |||
63 | // Accumulate the set of template argument lists in this structure. | |||
64 | MultiLevelTemplateArgumentList Result; | |||
65 | ||||
66 | if (Innermost) | |||
67 | Result.addOuterTemplateArguments(Innermost); | |||
68 | ||||
69 | DeclContext *Ctx = dyn_cast<DeclContext>(D); | |||
70 | if (!Ctx) { | |||
71 | Ctx = D->getDeclContext(); | |||
72 | ||||
73 | // Add template arguments from a variable template instantiation. For a | |||
74 | // class-scope explicit specialization, there are no template arguments | |||
75 | // at this level, but there may be enclosing template arguments. | |||
76 | VarTemplateSpecializationDecl *Spec = | |||
77 | dyn_cast<VarTemplateSpecializationDecl>(D); | |||
78 | if (Spec && !Spec->isClassScopeExplicitSpecialization()) { | |||
79 | // We're done when we hit an explicit specialization. | |||
80 | if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization && | |||
81 | !isa<VarTemplatePartialSpecializationDecl>(Spec)) | |||
82 | return Result; | |||
83 | ||||
84 | Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); | |||
85 | ||||
86 | // If this variable template specialization was instantiated from a | |||
87 | // specialized member that is a variable template, we're done. | |||
88 | assert(Spec->getSpecializedTemplate() && "No variable template?")((Spec->getSpecializedTemplate() && "No variable template?" ) ? static_cast<void> (0) : __assert_fail ("Spec->getSpecializedTemplate() && \"No variable template?\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 88, __PRETTY_FUNCTION__)); | |||
89 | llvm::PointerUnion<VarTemplateDecl*, | |||
90 | VarTemplatePartialSpecializationDecl*> Specialized | |||
91 | = Spec->getSpecializedTemplateOrPartial(); | |||
92 | if (VarTemplatePartialSpecializationDecl *Partial = | |||
93 | Specialized.dyn_cast<VarTemplatePartialSpecializationDecl *>()) { | |||
94 | if (Partial->isMemberSpecialization()) | |||
95 | return Result; | |||
96 | } else { | |||
97 | VarTemplateDecl *Tmpl = Specialized.get<VarTemplateDecl *>(); | |||
98 | if (Tmpl->isMemberSpecialization()) | |||
99 | return Result; | |||
100 | } | |||
101 | } | |||
102 | ||||
103 | // If we have a template template parameter with translation unit context, | |||
104 | // then we're performing substitution into a default template argument of | |||
105 | // this template template parameter before we've constructed the template | |||
106 | // that will own this template template parameter. In this case, we | |||
107 | // use empty template parameter lists for all of the outer templates | |||
108 | // to avoid performing any substitutions. | |||
109 | if (Ctx->isTranslationUnit()) { | |||
110 | if (TemplateTemplateParmDecl *TTP | |||
111 | = dyn_cast<TemplateTemplateParmDecl>(D)) { | |||
112 | for (unsigned I = 0, N = TTP->getDepth() + 1; I != N; ++I) | |||
113 | Result.addOuterTemplateArguments(None); | |||
114 | return Result; | |||
115 | } | |||
116 | } | |||
117 | } | |||
118 | ||||
119 | while (!Ctx->isFileContext()) { | |||
120 | // Add template arguments from a class template instantiation. | |||
121 | ClassTemplateSpecializationDecl *Spec | |||
122 | = dyn_cast<ClassTemplateSpecializationDecl>(Ctx); | |||
123 | if (Spec && !Spec->isClassScopeExplicitSpecialization()) { | |||
124 | // We're done when we hit an explicit specialization. | |||
125 | if (Spec->getSpecializationKind() == TSK_ExplicitSpecialization && | |||
126 | !isa<ClassTemplatePartialSpecializationDecl>(Spec)) | |||
127 | break; | |||
128 | ||||
129 | Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs()); | |||
130 | ||||
131 | // If this class template specialization was instantiated from a | |||
132 | // specialized member that is a class template, we're done. | |||
133 | assert(Spec->getSpecializedTemplate() && "No class template?")((Spec->getSpecializedTemplate() && "No class template?" ) ? static_cast<void> (0) : __assert_fail ("Spec->getSpecializedTemplate() && \"No class template?\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 133, __PRETTY_FUNCTION__)); | |||
134 | if (Spec->getSpecializedTemplate()->isMemberSpecialization()) | |||
135 | break; | |||
136 | } | |||
137 | // Add template arguments from a function template specialization. | |||
138 | else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) { | |||
139 | if (!RelativeToPrimary && | |||
140 | Function->getTemplateSpecializationKindForInstantiation() == | |||
141 | TSK_ExplicitSpecialization) | |||
142 | break; | |||
143 | ||||
144 | if (!RelativeToPrimary && Function->getTemplateSpecializationKind() == | |||
145 | TSK_ExplicitSpecialization) { | |||
146 | // This is an implicit instantiation of an explicit specialization. We | |||
147 | // don't get any template arguments from this function but might get | |||
148 | // some from an enclosing template. | |||
149 | } else if (const TemplateArgumentList *TemplateArgs | |||
150 | = Function->getTemplateSpecializationArgs()) { | |||
151 | // Add the template arguments for this specialization. | |||
152 | Result.addOuterTemplateArguments(TemplateArgs); | |||
153 | ||||
154 | // If this function was instantiated from a specialized member that is | |||
155 | // a function template, we're done. | |||
156 | assert(Function->getPrimaryTemplate() && "No function template?")((Function->getPrimaryTemplate() && "No function template?" ) ? static_cast<void> (0) : __assert_fail ("Function->getPrimaryTemplate() && \"No function template?\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 156, __PRETTY_FUNCTION__)); | |||
157 | if (Function->getPrimaryTemplate()->isMemberSpecialization()) | |||
158 | break; | |||
159 | ||||
160 | // If this function is a generic lambda specialization, we are done. | |||
161 | if (isGenericLambdaCallOperatorOrStaticInvokerSpecialization(Function)) | |||
162 | break; | |||
163 | ||||
164 | } else if (FunctionTemplateDecl *FunTmpl | |||
165 | = Function->getDescribedFunctionTemplate()) { | |||
166 | // Add the "injected" template arguments. | |||
167 | Result.addOuterTemplateArguments(FunTmpl->getInjectedTemplateArgs()); | |||
168 | } | |||
169 | ||||
170 | // If this is a friend declaration and it declares an entity at | |||
171 | // namespace scope, take arguments from its lexical parent | |||
172 | // instead of its semantic parent, unless of course the pattern we're | |||
173 | // instantiating actually comes from the file's context! | |||
174 | if (Function->getFriendObjectKind() && | |||
175 | Function->getDeclContext()->isFileContext() && | |||
176 | (!Pattern || !Pattern->getLexicalDeclContext()->isFileContext())) { | |||
177 | Ctx = Function->getLexicalDeclContext(); | |||
178 | RelativeToPrimary = false; | |||
179 | continue; | |||
180 | } | |||
181 | } else if (CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Ctx)) { | |||
182 | if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) { | |||
183 | QualType T = ClassTemplate->getInjectedClassNameSpecialization(); | |||
184 | const TemplateSpecializationType *TST = | |||
185 | cast<TemplateSpecializationType>(Context.getCanonicalType(T)); | |||
186 | Result.addOuterTemplateArguments( | |||
187 | llvm::makeArrayRef(TST->getArgs(), TST->getNumArgs())); | |||
188 | if (ClassTemplate->isMemberSpecialization()) | |||
189 | break; | |||
190 | } | |||
191 | } | |||
192 | ||||
193 | Ctx = Ctx->getParent(); | |||
194 | RelativeToPrimary = false; | |||
195 | } | |||
196 | ||||
197 | return Result; | |||
198 | } | |||
199 | ||||
200 | bool Sema::CodeSynthesisContext::isInstantiationRecord() const { | |||
201 | switch (Kind) { | |||
202 | case TemplateInstantiation: | |||
203 | case ExceptionSpecInstantiation: | |||
204 | case DefaultTemplateArgumentInstantiation: | |||
205 | case DefaultFunctionArgumentInstantiation: | |||
206 | case ExplicitTemplateArgumentSubstitution: | |||
207 | case DeducedTemplateArgumentSubstitution: | |||
208 | case PriorTemplateArgumentSubstitution: | |||
209 | case ConstraintsCheck: | |||
210 | case NestedRequirementConstraintsCheck: | |||
211 | return true; | |||
212 | ||||
213 | case RequirementInstantiation: | |||
214 | case DefaultTemplateArgumentChecking: | |||
215 | case DeclaringSpecialMember: | |||
216 | case DeclaringImplicitEqualityComparison: | |||
217 | case DefiningSynthesizedFunction: | |||
218 | case ExceptionSpecEvaluation: | |||
219 | case ConstraintSubstitution: | |||
220 | case ParameterMappingSubstitution: | |||
221 | case ConstraintNormalization: | |||
222 | case RewritingOperatorAsSpaceship: | |||
223 | case InitializingStructuredBinding: | |||
224 | case MarkingClassDllexported: | |||
225 | return false; | |||
226 | ||||
227 | // This function should never be called when Kind's value is Memoization. | |||
228 | case Memoization: | |||
229 | break; | |||
230 | } | |||
231 | ||||
232 | llvm_unreachable("Invalid SynthesisKind!")::llvm::llvm_unreachable_internal("Invalid SynthesisKind!", "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 232); | |||
233 | } | |||
234 | ||||
235 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
236 | Sema &SemaRef, CodeSynthesisContext::SynthesisKind Kind, | |||
237 | SourceLocation PointOfInstantiation, SourceRange InstantiationRange, | |||
238 | Decl *Entity, NamedDecl *Template, ArrayRef<TemplateArgument> TemplateArgs, | |||
239 | sema::TemplateDeductionInfo *DeductionInfo) | |||
240 | : SemaRef(SemaRef) { | |||
241 | // Don't allow further instantiation if a fatal error and an uncompilable | |||
242 | // error have occurred. Any diagnostics we might have raised will not be | |||
243 | // visible, and we do not need to construct a correct AST. | |||
244 | if (SemaRef.Diags.hasFatalErrorOccurred() && | |||
245 | SemaRef.hasUncompilableErrorOccurred()) { | |||
246 | Invalid = true; | |||
247 | return; | |||
248 | } | |||
249 | Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange); | |||
250 | if (!Invalid) { | |||
251 | CodeSynthesisContext Inst; | |||
252 | Inst.Kind = Kind; | |||
253 | Inst.PointOfInstantiation = PointOfInstantiation; | |||
254 | Inst.Entity = Entity; | |||
255 | Inst.Template = Template; | |||
256 | Inst.TemplateArgs = TemplateArgs.data(); | |||
257 | Inst.NumTemplateArgs = TemplateArgs.size(); | |||
258 | Inst.DeductionInfo = DeductionInfo; | |||
259 | Inst.InstantiationRange = InstantiationRange; | |||
260 | SemaRef.pushCodeSynthesisContext(Inst); | |||
261 | ||||
262 | AlreadyInstantiating = !Inst.Entity ? false : | |||
263 | !SemaRef.InstantiatingSpecializations | |||
264 | .insert({Inst.Entity->getCanonicalDecl(), Inst.Kind}) | |||
265 | .second; | |||
266 | atTemplateBegin(SemaRef.TemplateInstCallbacks, SemaRef, Inst); | |||
267 | } | |||
268 | } | |||
269 | ||||
270 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
271 | Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity, | |||
272 | SourceRange InstantiationRange) | |||
273 | : InstantiatingTemplate(SemaRef, | |||
274 | CodeSynthesisContext::TemplateInstantiation, | |||
275 | PointOfInstantiation, InstantiationRange, Entity) {} | |||
276 | ||||
277 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
278 | Sema &SemaRef, SourceLocation PointOfInstantiation, FunctionDecl *Entity, | |||
279 | ExceptionSpecification, SourceRange InstantiationRange) | |||
280 | : InstantiatingTemplate( | |||
281 | SemaRef, CodeSynthesisContext::ExceptionSpecInstantiation, | |||
282 | PointOfInstantiation, InstantiationRange, Entity) {} | |||
283 | ||||
284 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
285 | Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateParameter Param, | |||
286 | TemplateDecl *Template, ArrayRef<TemplateArgument> TemplateArgs, | |||
287 | SourceRange InstantiationRange) | |||
288 | : InstantiatingTemplate( | |||
289 | SemaRef, | |||
290 | CodeSynthesisContext::DefaultTemplateArgumentInstantiation, | |||
291 | PointOfInstantiation, InstantiationRange, getAsNamedDecl(Param), | |||
292 | Template, TemplateArgs) {} | |||
293 | ||||
294 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
295 | Sema &SemaRef, SourceLocation PointOfInstantiation, | |||
296 | FunctionTemplateDecl *FunctionTemplate, | |||
297 | ArrayRef<TemplateArgument> TemplateArgs, | |||
298 | CodeSynthesisContext::SynthesisKind Kind, | |||
299 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | |||
300 | : InstantiatingTemplate(SemaRef, Kind, PointOfInstantiation, | |||
301 | InstantiationRange, FunctionTemplate, nullptr, | |||
302 | TemplateArgs, &DeductionInfo) { | |||
303 | assert(((Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution ) ? static_cast<void> (0) : __assert_fail ("Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 305, __PRETTY_FUNCTION__)) | |||
304 | Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution ||((Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution ) ? static_cast<void> (0) : __assert_fail ("Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 305, __PRETTY_FUNCTION__)) | |||
305 | Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution)((Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution ) ? static_cast<void> (0) : __assert_fail ("Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 305, __PRETTY_FUNCTION__)); | |||
306 | } | |||
307 | ||||
308 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
309 | Sema &SemaRef, SourceLocation PointOfInstantiation, | |||
310 | TemplateDecl *Template, | |||
311 | ArrayRef<TemplateArgument> TemplateArgs, | |||
312 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | |||
313 | : InstantiatingTemplate( | |||
314 | SemaRef, | |||
315 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | |||
316 | PointOfInstantiation, InstantiationRange, Template, nullptr, | |||
317 | TemplateArgs, &DeductionInfo) {} | |||
318 | ||||
319 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
320 | Sema &SemaRef, SourceLocation PointOfInstantiation, | |||
321 | ClassTemplatePartialSpecializationDecl *PartialSpec, | |||
322 | ArrayRef<TemplateArgument> TemplateArgs, | |||
323 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | |||
324 | : InstantiatingTemplate( | |||
325 | SemaRef, | |||
326 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | |||
327 | PointOfInstantiation, InstantiationRange, PartialSpec, nullptr, | |||
328 | TemplateArgs, &DeductionInfo) {} | |||
329 | ||||
330 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
331 | Sema &SemaRef, SourceLocation PointOfInstantiation, | |||
332 | VarTemplatePartialSpecializationDecl *PartialSpec, | |||
333 | ArrayRef<TemplateArgument> TemplateArgs, | |||
334 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | |||
335 | : InstantiatingTemplate( | |||
336 | SemaRef, | |||
337 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | |||
338 | PointOfInstantiation, InstantiationRange, PartialSpec, nullptr, | |||
339 | TemplateArgs, &DeductionInfo) {} | |||
340 | ||||
341 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
342 | Sema &SemaRef, SourceLocation PointOfInstantiation, ParmVarDecl *Param, | |||
343 | ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange) | |||
344 | : InstantiatingTemplate( | |||
345 | SemaRef, | |||
346 | CodeSynthesisContext::DefaultFunctionArgumentInstantiation, | |||
347 | PointOfInstantiation, InstantiationRange, Param, nullptr, | |||
348 | TemplateArgs) {} | |||
349 | ||||
350 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
351 | Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template, | |||
352 | NonTypeTemplateParmDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | |||
353 | SourceRange InstantiationRange) | |||
354 | : InstantiatingTemplate( | |||
355 | SemaRef, | |||
356 | CodeSynthesisContext::PriorTemplateArgumentSubstitution, | |||
357 | PointOfInstantiation, InstantiationRange, Param, Template, | |||
358 | TemplateArgs) {} | |||
359 | ||||
360 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
361 | Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template, | |||
362 | TemplateTemplateParmDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | |||
363 | SourceRange InstantiationRange) | |||
364 | : InstantiatingTemplate( | |||
365 | SemaRef, | |||
366 | CodeSynthesisContext::PriorTemplateArgumentSubstitution, | |||
367 | PointOfInstantiation, InstantiationRange, Param, Template, | |||
368 | TemplateArgs) {} | |||
369 | ||||
370 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
371 | Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateDecl *Template, | |||
372 | NamedDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | |||
373 | SourceRange InstantiationRange) | |||
374 | : InstantiatingTemplate( | |||
375 | SemaRef, CodeSynthesisContext::DefaultTemplateArgumentChecking, | |||
376 | PointOfInstantiation, InstantiationRange, Param, Template, | |||
377 | TemplateArgs) {} | |||
378 | ||||
379 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
380 | Sema &SemaRef, SourceLocation PointOfInstantiation, | |||
381 | concepts::Requirement *Req, sema::TemplateDeductionInfo &DeductionInfo, | |||
382 | SourceRange InstantiationRange) | |||
383 | : InstantiatingTemplate( | |||
384 | SemaRef, CodeSynthesisContext::RequirementInstantiation, | |||
385 | PointOfInstantiation, InstantiationRange, /*Entity=*/nullptr, | |||
386 | /*Template=*/nullptr, /*TemplateArgs=*/None, &DeductionInfo) {} | |||
387 | ||||
388 | ||||
389 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
390 | Sema &SemaRef, SourceLocation PointOfInstantiation, | |||
391 | concepts::NestedRequirement *Req, ConstraintsCheck, | |||
392 | SourceRange InstantiationRange) | |||
393 | : InstantiatingTemplate( | |||
394 | SemaRef, CodeSynthesisContext::NestedRequirementConstraintsCheck, | |||
395 | PointOfInstantiation, InstantiationRange, /*Entity=*/nullptr, | |||
396 | /*Template=*/nullptr, /*TemplateArgs=*/None) {} | |||
397 | ||||
398 | ||||
399 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
400 | Sema &SemaRef, SourceLocation PointOfInstantiation, | |||
401 | ConstraintsCheck, NamedDecl *Template, | |||
402 | ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange) | |||
403 | : InstantiatingTemplate( | |||
404 | SemaRef, CodeSynthesisContext::ConstraintsCheck, | |||
405 | PointOfInstantiation, InstantiationRange, Template, nullptr, | |||
406 | TemplateArgs) {} | |||
407 | ||||
408 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
409 | Sema &SemaRef, SourceLocation PointOfInstantiation, | |||
410 | ConstraintSubstitution, NamedDecl *Template, | |||
411 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | |||
412 | : InstantiatingTemplate( | |||
413 | SemaRef, CodeSynthesisContext::ConstraintSubstitution, | |||
414 | PointOfInstantiation, InstantiationRange, Template, nullptr, | |||
415 | {}, &DeductionInfo) {} | |||
416 | ||||
417 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
418 | Sema &SemaRef, SourceLocation PointOfInstantiation, | |||
419 | ConstraintNormalization, NamedDecl *Template, | |||
420 | SourceRange InstantiationRange) | |||
421 | : InstantiatingTemplate( | |||
422 | SemaRef, CodeSynthesisContext::ConstraintNormalization, | |||
423 | PointOfInstantiation, InstantiationRange, Template) {} | |||
424 | ||||
425 | Sema::InstantiatingTemplate::InstantiatingTemplate( | |||
426 | Sema &SemaRef, SourceLocation PointOfInstantiation, | |||
427 | ParameterMappingSubstitution, NamedDecl *Template, | |||
428 | SourceRange InstantiationRange) | |||
429 | : InstantiatingTemplate( | |||
430 | SemaRef, CodeSynthesisContext::ParameterMappingSubstitution, | |||
431 | PointOfInstantiation, InstantiationRange, Template) {} | |||
432 | ||||
433 | void Sema::pushCodeSynthesisContext(CodeSynthesisContext Ctx) { | |||
434 | Ctx.SavedInNonInstantiationSFINAEContext = InNonInstantiationSFINAEContext; | |||
435 | InNonInstantiationSFINAEContext = false; | |||
436 | ||||
437 | CodeSynthesisContexts.push_back(Ctx); | |||
438 | ||||
439 | if (!Ctx.isInstantiationRecord()) | |||
440 | ++NonInstantiationEntries; | |||
441 | ||||
442 | // Check to see if we're low on stack space. We can't do anything about this | |||
443 | // from here, but we can at least warn the user. | |||
444 | if (isStackNearlyExhausted()) | |||
445 | warnStackExhausted(Ctx.PointOfInstantiation); | |||
446 | } | |||
447 | ||||
448 | void Sema::popCodeSynthesisContext() { | |||
449 | auto &Active = CodeSynthesisContexts.back(); | |||
450 | if (!Active.isInstantiationRecord()) { | |||
451 | assert(NonInstantiationEntries > 0)((NonInstantiationEntries > 0) ? static_cast<void> ( 0) : __assert_fail ("NonInstantiationEntries > 0", "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 451, __PRETTY_FUNCTION__)); | |||
452 | --NonInstantiationEntries; | |||
453 | } | |||
454 | ||||
455 | InNonInstantiationSFINAEContext = Active.SavedInNonInstantiationSFINAEContext; | |||
456 | ||||
457 | // Name lookup no longer looks in this template's defining module. | |||
458 | assert(CodeSynthesisContexts.size() >=((CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules .size() && "forgot to remove a lookup module for a template instantiation" ) ? static_cast<void> (0) : __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 460, __PRETTY_FUNCTION__)) | |||
459 | CodeSynthesisContextLookupModules.size() &&((CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules .size() && "forgot to remove a lookup module for a template instantiation" ) ? static_cast<void> (0) : __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 460, __PRETTY_FUNCTION__)) | |||
460 | "forgot to remove a lookup module for a template instantiation")((CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules .size() && "forgot to remove a lookup module for a template instantiation" ) ? static_cast<void> (0) : __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 460, __PRETTY_FUNCTION__)); | |||
461 | if (CodeSynthesisContexts.size() == | |||
462 | CodeSynthesisContextLookupModules.size()) { | |||
463 | if (Module *M = CodeSynthesisContextLookupModules.back()) | |||
464 | LookupModulesCache.erase(M); | |||
465 | CodeSynthesisContextLookupModules.pop_back(); | |||
466 | } | |||
467 | ||||
468 | // If we've left the code synthesis context for the current context stack, | |||
469 | // stop remembering that we've emitted that stack. | |||
470 | if (CodeSynthesisContexts.size() == | |||
471 | LastEmittedCodeSynthesisContextDepth) | |||
472 | LastEmittedCodeSynthesisContextDepth = 0; | |||
473 | ||||
474 | CodeSynthesisContexts.pop_back(); | |||
475 | } | |||
476 | ||||
477 | void Sema::InstantiatingTemplate::Clear() { | |||
478 | if (!Invalid) { | |||
479 | if (!AlreadyInstantiating) { | |||
480 | auto &Active = SemaRef.CodeSynthesisContexts.back(); | |||
481 | if (Active.Entity) | |||
482 | SemaRef.InstantiatingSpecializations.erase( | |||
483 | {Active.Entity->getCanonicalDecl(), Active.Kind}); | |||
484 | } | |||
485 | ||||
486 | atTemplateEnd(SemaRef.TemplateInstCallbacks, SemaRef, | |||
487 | SemaRef.CodeSynthesisContexts.back()); | |||
488 | ||||
489 | SemaRef.popCodeSynthesisContext(); | |||
490 | Invalid = true; | |||
491 | } | |||
492 | } | |||
493 | ||||
494 | bool Sema::InstantiatingTemplate::CheckInstantiationDepth( | |||
495 | SourceLocation PointOfInstantiation, | |||
496 | SourceRange InstantiationRange) { | |||
497 | assert(SemaRef.NonInstantiationEntries <=((SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts .size()) ? static_cast<void> (0) : __assert_fail ("SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts.size()" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 498, __PRETTY_FUNCTION__)) | |||
498 | SemaRef.CodeSynthesisContexts.size())((SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts .size()) ? static_cast<void> (0) : __assert_fail ("SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts.size()" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 498, __PRETTY_FUNCTION__)); | |||
499 | if ((SemaRef.CodeSynthesisContexts.size() - | |||
500 | SemaRef.NonInstantiationEntries) | |||
501 | <= SemaRef.getLangOpts().InstantiationDepth) | |||
502 | return false; | |||
503 | ||||
504 | SemaRef.Diag(PointOfInstantiation, | |||
505 | diag::err_template_recursion_depth_exceeded) | |||
506 | << SemaRef.getLangOpts().InstantiationDepth | |||
507 | << InstantiationRange; | |||
508 | SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth) | |||
509 | << SemaRef.getLangOpts().InstantiationDepth; | |||
510 | return true; | |||
511 | } | |||
512 | ||||
513 | /// Prints the current instantiation stack through a series of | |||
514 | /// notes. | |||
515 | void Sema::PrintInstantiationStack() { | |||
516 | // Determine which template instantiations to skip, if any. | |||
517 | unsigned SkipStart = CodeSynthesisContexts.size(), SkipEnd = SkipStart; | |||
518 | unsigned Limit = Diags.getTemplateBacktraceLimit(); | |||
519 | if (Limit && Limit < CodeSynthesisContexts.size()) { | |||
520 | SkipStart = Limit / 2 + Limit % 2; | |||
521 | SkipEnd = CodeSynthesisContexts.size() - Limit / 2; | |||
522 | } | |||
523 | ||||
524 | // FIXME: In all of these cases, we need to show the template arguments | |||
525 | unsigned InstantiationIdx = 0; | |||
526 | for (SmallVectorImpl<CodeSynthesisContext>::reverse_iterator | |||
527 | Active = CodeSynthesisContexts.rbegin(), | |||
528 | ActiveEnd = CodeSynthesisContexts.rend(); | |||
529 | Active != ActiveEnd; | |||
530 | ++Active, ++InstantiationIdx) { | |||
531 | // Skip this instantiation? | |||
532 | if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) { | |||
533 | if (InstantiationIdx == SkipStart) { | |||
534 | // Note that we're skipping instantiations. | |||
535 | Diags.Report(Active->PointOfInstantiation, | |||
536 | diag::note_instantiation_contexts_suppressed) | |||
537 | << unsigned(CodeSynthesisContexts.size() - Limit); | |||
538 | } | |||
539 | continue; | |||
540 | } | |||
541 | ||||
542 | switch (Active->Kind) { | |||
543 | case CodeSynthesisContext::TemplateInstantiation: { | |||
544 | Decl *D = Active->Entity; | |||
545 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) { | |||
546 | unsigned DiagID = diag::note_template_member_class_here; | |||
547 | if (isa<ClassTemplateSpecializationDecl>(Record)) | |||
548 | DiagID = diag::note_template_class_instantiation_here; | |||
549 | Diags.Report(Active->PointOfInstantiation, DiagID) | |||
550 | << Record << Active->InstantiationRange; | |||
551 | } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { | |||
552 | unsigned DiagID; | |||
553 | if (Function->getPrimaryTemplate()) | |||
554 | DiagID = diag::note_function_template_spec_here; | |||
555 | else | |||
556 | DiagID = diag::note_template_member_function_here; | |||
557 | Diags.Report(Active->PointOfInstantiation, DiagID) | |||
558 | << Function | |||
559 | << Active->InstantiationRange; | |||
560 | } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) { | |||
561 | Diags.Report(Active->PointOfInstantiation, | |||
562 | VD->isStaticDataMember()? | |||
563 | diag::note_template_static_data_member_def_here | |||
564 | : diag::note_template_variable_def_here) | |||
565 | << VD | |||
566 | << Active->InstantiationRange; | |||
567 | } else if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) { | |||
568 | Diags.Report(Active->PointOfInstantiation, | |||
569 | diag::note_template_enum_def_here) | |||
570 | << ED | |||
571 | << Active->InstantiationRange; | |||
572 | } else if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) { | |||
573 | Diags.Report(Active->PointOfInstantiation, | |||
574 | diag::note_template_nsdmi_here) | |||
575 | << FD << Active->InstantiationRange; | |||
576 | } else { | |||
577 | Diags.Report(Active->PointOfInstantiation, | |||
578 | diag::note_template_type_alias_instantiation_here) | |||
579 | << cast<TypeAliasTemplateDecl>(D) | |||
580 | << Active->InstantiationRange; | |||
581 | } | |||
582 | break; | |||
583 | } | |||
584 | ||||
585 | case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: { | |||
586 | TemplateDecl *Template = cast<TemplateDecl>(Active->Template); | |||
587 | SmallString<128> TemplateArgsStr; | |||
588 | llvm::raw_svector_ostream OS(TemplateArgsStr); | |||
589 | Template->printName(OS); | |||
590 | printTemplateArgumentList(OS, Active->template_arguments(), | |||
591 | getPrintingPolicy()); | |||
592 | Diags.Report(Active->PointOfInstantiation, | |||
593 | diag::note_default_arg_instantiation_here) | |||
594 | << OS.str() | |||
595 | << Active->InstantiationRange; | |||
596 | break; | |||
597 | } | |||
598 | ||||
599 | case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution: { | |||
600 | FunctionTemplateDecl *FnTmpl = cast<FunctionTemplateDecl>(Active->Entity); | |||
601 | Diags.Report(Active->PointOfInstantiation, | |||
602 | diag::note_explicit_template_arg_substitution_here) | |||
603 | << FnTmpl | |||
604 | << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(), | |||
605 | Active->TemplateArgs, | |||
606 | Active->NumTemplateArgs) | |||
607 | << Active->InstantiationRange; | |||
608 | break; | |||
609 | } | |||
610 | ||||
611 | case CodeSynthesisContext::DeducedTemplateArgumentSubstitution: { | |||
612 | if (FunctionTemplateDecl *FnTmpl = | |||
613 | dyn_cast<FunctionTemplateDecl>(Active->Entity)) { | |||
614 | Diags.Report(Active->PointOfInstantiation, | |||
615 | diag::note_function_template_deduction_instantiation_here) | |||
616 | << FnTmpl | |||
617 | << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(), | |||
618 | Active->TemplateArgs, | |||
619 | Active->NumTemplateArgs) | |||
620 | << Active->InstantiationRange; | |||
621 | } else { | |||
622 | bool IsVar = isa<VarTemplateDecl>(Active->Entity) || | |||
623 | isa<VarTemplateSpecializationDecl>(Active->Entity); | |||
624 | bool IsTemplate = false; | |||
625 | TemplateParameterList *Params; | |||
626 | if (auto *D = dyn_cast<TemplateDecl>(Active->Entity)) { | |||
627 | IsTemplate = true; | |||
628 | Params = D->getTemplateParameters(); | |||
629 | } else if (auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>( | |||
630 | Active->Entity)) { | |||
631 | Params = D->getTemplateParameters(); | |||
632 | } else if (auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>( | |||
633 | Active->Entity)) { | |||
634 | Params = D->getTemplateParameters(); | |||
635 | } else { | |||
636 | llvm_unreachable("unexpected template kind")::llvm::llvm_unreachable_internal("unexpected template kind", "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 636); | |||
637 | } | |||
638 | ||||
639 | Diags.Report(Active->PointOfInstantiation, | |||
640 | diag::note_deduced_template_arg_substitution_here) | |||
641 | << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity) | |||
642 | << getTemplateArgumentBindingsText(Params, Active->TemplateArgs, | |||
643 | Active->NumTemplateArgs) | |||
644 | << Active->InstantiationRange; | |||
645 | } | |||
646 | break; | |||
647 | } | |||
648 | ||||
649 | case CodeSynthesisContext::DefaultFunctionArgumentInstantiation: { | |||
650 | ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity); | |||
651 | FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext()); | |||
652 | ||||
653 | SmallString<128> TemplateArgsStr; | |||
654 | llvm::raw_svector_ostream OS(TemplateArgsStr); | |||
655 | FD->printName(OS); | |||
656 | printTemplateArgumentList(OS, Active->template_arguments(), | |||
657 | getPrintingPolicy()); | |||
658 | Diags.Report(Active->PointOfInstantiation, | |||
659 | diag::note_default_function_arg_instantiation_here) | |||
660 | << OS.str() | |||
661 | << Active->InstantiationRange; | |||
662 | break; | |||
663 | } | |||
664 | ||||
665 | case CodeSynthesisContext::PriorTemplateArgumentSubstitution: { | |||
666 | NamedDecl *Parm = cast<NamedDecl>(Active->Entity); | |||
667 | std::string Name; | |||
668 | if (!Parm->getName().empty()) | |||
669 | Name = std::string(" '") + Parm->getName().str() + "'"; | |||
670 | ||||
671 | TemplateParameterList *TemplateParams = nullptr; | |||
672 | if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template)) | |||
673 | TemplateParams = Template->getTemplateParameters(); | |||
674 | else | |||
675 | TemplateParams = | |||
676 | cast<ClassTemplatePartialSpecializationDecl>(Active->Template) | |||
677 | ->getTemplateParameters(); | |||
678 | Diags.Report(Active->PointOfInstantiation, | |||
679 | diag::note_prior_template_arg_substitution) | |||
680 | << isa<TemplateTemplateParmDecl>(Parm) | |||
681 | << Name | |||
682 | << getTemplateArgumentBindingsText(TemplateParams, | |||
683 | Active->TemplateArgs, | |||
684 | Active->NumTemplateArgs) | |||
685 | << Active->InstantiationRange; | |||
686 | break; | |||
687 | } | |||
688 | ||||
689 | case CodeSynthesisContext::DefaultTemplateArgumentChecking: { | |||
690 | TemplateParameterList *TemplateParams = nullptr; | |||
691 | if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template)) | |||
692 | TemplateParams = Template->getTemplateParameters(); | |||
693 | else | |||
694 | TemplateParams = | |||
695 | cast<ClassTemplatePartialSpecializationDecl>(Active->Template) | |||
696 | ->getTemplateParameters(); | |||
697 | ||||
698 | Diags.Report(Active->PointOfInstantiation, | |||
699 | diag::note_template_default_arg_checking) | |||
700 | << getTemplateArgumentBindingsText(TemplateParams, | |||
701 | Active->TemplateArgs, | |||
702 | Active->NumTemplateArgs) | |||
703 | << Active->InstantiationRange; | |||
704 | break; | |||
705 | } | |||
706 | ||||
707 | case CodeSynthesisContext::ExceptionSpecEvaluation: | |||
708 | Diags.Report(Active->PointOfInstantiation, | |||
709 | diag::note_evaluating_exception_spec_here) | |||
710 | << cast<FunctionDecl>(Active->Entity); | |||
711 | break; | |||
712 | ||||
713 | case CodeSynthesisContext::ExceptionSpecInstantiation: | |||
714 | Diags.Report(Active->PointOfInstantiation, | |||
715 | diag::note_template_exception_spec_instantiation_here) | |||
716 | << cast<FunctionDecl>(Active->Entity) | |||
717 | << Active->InstantiationRange; | |||
718 | break; | |||
719 | ||||
720 | case CodeSynthesisContext::RequirementInstantiation: | |||
721 | Diags.Report(Active->PointOfInstantiation, | |||
722 | diag::note_template_requirement_instantiation_here) | |||
723 | << Active->InstantiationRange; | |||
724 | break; | |||
725 | ||||
726 | case CodeSynthesisContext::NestedRequirementConstraintsCheck: | |||
727 | Diags.Report(Active->PointOfInstantiation, | |||
728 | diag::note_nested_requirement_here) | |||
729 | << Active->InstantiationRange; | |||
730 | break; | |||
731 | ||||
732 | case CodeSynthesisContext::DeclaringSpecialMember: | |||
733 | Diags.Report(Active->PointOfInstantiation, | |||
734 | diag::note_in_declaration_of_implicit_special_member) | |||
735 | << cast<CXXRecordDecl>(Active->Entity) << Active->SpecialMember; | |||
736 | break; | |||
737 | ||||
738 | case CodeSynthesisContext::DeclaringImplicitEqualityComparison: | |||
739 | Diags.Report(Active->Entity->getLocation(), | |||
740 | diag::note_in_declaration_of_implicit_equality_comparison); | |||
741 | break; | |||
742 | ||||
743 | case CodeSynthesisContext::DefiningSynthesizedFunction: { | |||
744 | // FIXME: For synthesized functions that are not defaulted, | |||
745 | // produce a note. | |||
746 | auto *FD = dyn_cast<FunctionDecl>(Active->Entity); | |||
747 | DefaultedFunctionKind DFK = | |||
748 | FD ? getDefaultedFunctionKind(FD) : DefaultedFunctionKind(); | |||
749 | if (DFK.isSpecialMember()) { | |||
750 | auto *MD = cast<CXXMethodDecl>(FD); | |||
751 | Diags.Report(Active->PointOfInstantiation, | |||
752 | diag::note_member_synthesized_at) | |||
753 | << MD->isExplicitlyDefaulted() << DFK.asSpecialMember() | |||
754 | << Context.getTagDeclType(MD->getParent()); | |||
755 | } else if (DFK.isComparison()) { | |||
756 | Diags.Report(Active->PointOfInstantiation, | |||
757 | diag::note_comparison_synthesized_at) | |||
758 | << (int)DFK.asComparison() | |||
759 | << Context.getTagDeclType( | |||
760 | cast<CXXRecordDecl>(FD->getLexicalDeclContext())); | |||
761 | } | |||
762 | break; | |||
763 | } | |||
764 | ||||
765 | case CodeSynthesisContext::RewritingOperatorAsSpaceship: | |||
766 | Diags.Report(Active->Entity->getLocation(), | |||
767 | diag::note_rewriting_operator_as_spaceship); | |||
768 | break; | |||
769 | ||||
770 | case CodeSynthesisContext::InitializingStructuredBinding: | |||
771 | Diags.Report(Active->PointOfInstantiation, | |||
772 | diag::note_in_binding_decl_init) | |||
773 | << cast<BindingDecl>(Active->Entity); | |||
774 | break; | |||
775 | ||||
776 | case CodeSynthesisContext::MarkingClassDllexported: | |||
777 | Diags.Report(Active->PointOfInstantiation, | |||
778 | diag::note_due_to_dllexported_class) | |||
779 | << cast<CXXRecordDecl>(Active->Entity) << !getLangOpts().CPlusPlus11; | |||
780 | break; | |||
781 | ||||
782 | case CodeSynthesisContext::Memoization: | |||
783 | break; | |||
784 | ||||
785 | case CodeSynthesisContext::ConstraintsCheck: { | |||
786 | unsigned DiagID = 0; | |||
787 | if (!Active->Entity) { | |||
788 | Diags.Report(Active->PointOfInstantiation, | |||
789 | diag::note_nested_requirement_here) | |||
790 | << Active->InstantiationRange; | |||
791 | break; | |||
792 | } | |||
793 | if (isa<ConceptDecl>(Active->Entity)) | |||
794 | DiagID = diag::note_concept_specialization_here; | |||
795 | else if (isa<TemplateDecl>(Active->Entity)) | |||
796 | DiagID = diag::note_checking_constraints_for_template_id_here; | |||
797 | else if (isa<VarTemplatePartialSpecializationDecl>(Active->Entity)) | |||
798 | DiagID = diag::note_checking_constraints_for_var_spec_id_here; | |||
799 | else if (isa<ClassTemplatePartialSpecializationDecl>(Active->Entity)) | |||
800 | DiagID = diag::note_checking_constraints_for_class_spec_id_here; | |||
801 | else { | |||
802 | assert(isa<FunctionDecl>(Active->Entity))((isa<FunctionDecl>(Active->Entity)) ? static_cast< void> (0) : __assert_fail ("isa<FunctionDecl>(Active->Entity)" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 802, __PRETTY_FUNCTION__)); | |||
803 | DiagID = diag::note_checking_constraints_for_function_here; | |||
804 | } | |||
805 | SmallString<128> TemplateArgsStr; | |||
806 | llvm::raw_svector_ostream OS(TemplateArgsStr); | |||
807 | cast<NamedDecl>(Active->Entity)->printName(OS); | |||
808 | if (!isa<FunctionDecl>(Active->Entity)) | |||
809 | printTemplateArgumentList(OS, Active->template_arguments(), | |||
810 | getPrintingPolicy()); | |||
811 | Diags.Report(Active->PointOfInstantiation, DiagID) << OS.str() | |||
812 | << Active->InstantiationRange; | |||
813 | break; | |||
814 | } | |||
815 | case CodeSynthesisContext::ConstraintSubstitution: | |||
816 | Diags.Report(Active->PointOfInstantiation, | |||
817 | diag::note_constraint_substitution_here) | |||
818 | << Active->InstantiationRange; | |||
819 | break; | |||
820 | case CodeSynthesisContext::ConstraintNormalization: | |||
821 | Diags.Report(Active->PointOfInstantiation, | |||
822 | diag::note_constraint_normalization_here) | |||
823 | << cast<NamedDecl>(Active->Entity)->getName() | |||
824 | << Active->InstantiationRange; | |||
825 | break; | |||
826 | case CodeSynthesisContext::ParameterMappingSubstitution: | |||
827 | Diags.Report(Active->PointOfInstantiation, | |||
828 | diag::note_parameter_mapping_substitution_here) | |||
829 | << Active->InstantiationRange; | |||
830 | break; | |||
831 | } | |||
832 | } | |||
833 | } | |||
834 | ||||
835 | Optional<TemplateDeductionInfo *> Sema::isSFINAEContext() const { | |||
836 | if (InNonInstantiationSFINAEContext) | |||
837 | return Optional<TemplateDeductionInfo *>(nullptr); | |||
838 | ||||
839 | for (SmallVectorImpl<CodeSynthesisContext>::const_reverse_iterator | |||
840 | Active = CodeSynthesisContexts.rbegin(), | |||
841 | ActiveEnd = CodeSynthesisContexts.rend(); | |||
842 | Active != ActiveEnd; | |||
843 | ++Active) | |||
844 | { | |||
845 | switch (Active->Kind) { | |||
846 | case CodeSynthesisContext::TemplateInstantiation: | |||
847 | // An instantiation of an alias template may or may not be a SFINAE | |||
848 | // context, depending on what else is on the stack. | |||
849 | if (isa<TypeAliasTemplateDecl>(Active->Entity)) | |||
850 | break; | |||
851 | LLVM_FALLTHROUGH[[gnu::fallthrough]]; | |||
852 | case CodeSynthesisContext::DefaultFunctionArgumentInstantiation: | |||
853 | case CodeSynthesisContext::ExceptionSpecInstantiation: | |||
854 | case CodeSynthesisContext::ConstraintsCheck: | |||
855 | case CodeSynthesisContext::ParameterMappingSubstitution: | |||
856 | case CodeSynthesisContext::ConstraintNormalization: | |||
857 | case CodeSynthesisContext::NestedRequirementConstraintsCheck: | |||
858 | // This is a template instantiation, so there is no SFINAE. | |||
859 | return None; | |||
860 | ||||
861 | case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: | |||
862 | case CodeSynthesisContext::PriorTemplateArgumentSubstitution: | |||
863 | case CodeSynthesisContext::DefaultTemplateArgumentChecking: | |||
864 | case CodeSynthesisContext::RewritingOperatorAsSpaceship: | |||
865 | // A default template argument instantiation and substitution into | |||
866 | // template parameters with arguments for prior parameters may or may | |||
867 | // not be a SFINAE context; look further up the stack. | |||
868 | break; | |||
869 | ||||
870 | case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution: | |||
871 | case CodeSynthesisContext::DeducedTemplateArgumentSubstitution: | |||
872 | case CodeSynthesisContext::ConstraintSubstitution: | |||
873 | case CodeSynthesisContext::RequirementInstantiation: | |||
874 | // We're either substituting explicitly-specified template arguments, | |||
875 | // deduced template arguments, a constraint expression or a requirement | |||
876 | // in a requires expression, so SFINAE applies. | |||
877 | assert(Active->DeductionInfo && "Missing deduction info pointer")((Active->DeductionInfo && "Missing deduction info pointer" ) ? static_cast<void> (0) : __assert_fail ("Active->DeductionInfo && \"Missing deduction info pointer\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 877, __PRETTY_FUNCTION__)); | |||
878 | return Active->DeductionInfo; | |||
879 | ||||
880 | case CodeSynthesisContext::DeclaringSpecialMember: | |||
881 | case CodeSynthesisContext::DeclaringImplicitEqualityComparison: | |||
882 | case CodeSynthesisContext::DefiningSynthesizedFunction: | |||
883 | case CodeSynthesisContext::InitializingStructuredBinding: | |||
884 | case CodeSynthesisContext::MarkingClassDllexported: | |||
885 | // This happens in a context unrelated to template instantiation, so | |||
886 | // there is no SFINAE. | |||
887 | return None; | |||
888 | ||||
889 | case CodeSynthesisContext::ExceptionSpecEvaluation: | |||
890 | // FIXME: This should not be treated as a SFINAE context, because | |||
891 | // we will cache an incorrect exception specification. However, clang | |||
892 | // bootstrap relies this! See PR31692. | |||
893 | break; | |||
894 | ||||
895 | case CodeSynthesisContext::Memoization: | |||
896 | break; | |||
897 | } | |||
898 | ||||
899 | // The inner context was transparent for SFINAE. If it occurred within a | |||
900 | // non-instantiation SFINAE context, then SFINAE applies. | |||
901 | if (Active->SavedInNonInstantiationSFINAEContext) | |||
902 | return Optional<TemplateDeductionInfo *>(nullptr); | |||
903 | } | |||
904 | ||||
905 | return None; | |||
906 | } | |||
907 | ||||
908 | //===----------------------------------------------------------------------===/ | |||
909 | // Template Instantiation for Types | |||
910 | //===----------------------------------------------------------------------===/ | |||
911 | namespace { | |||
912 | class TemplateInstantiator : public TreeTransform<TemplateInstantiator> { | |||
913 | const MultiLevelTemplateArgumentList &TemplateArgs; | |||
914 | SourceLocation Loc; | |||
915 | DeclarationName Entity; | |||
916 | ||||
917 | public: | |||
918 | typedef TreeTransform<TemplateInstantiator> inherited; | |||
919 | ||||
920 | TemplateInstantiator(Sema &SemaRef, | |||
921 | const MultiLevelTemplateArgumentList &TemplateArgs, | |||
922 | SourceLocation Loc, | |||
923 | DeclarationName Entity) | |||
924 | : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc), | |||
925 | Entity(Entity) { } | |||
926 | ||||
927 | /// Determine whether the given type \p T has already been | |||
928 | /// transformed. | |||
929 | /// | |||
930 | /// For the purposes of template instantiation, a type has already been | |||
931 | /// transformed if it is NULL or if it is not dependent. | |||
932 | bool AlreadyTransformed(QualType T); | |||
933 | ||||
934 | /// Returns the location of the entity being instantiated, if known. | |||
935 | SourceLocation getBaseLocation() { return Loc; } | |||
936 | ||||
937 | /// Returns the name of the entity being instantiated, if any. | |||
938 | DeclarationName getBaseEntity() { return Entity; } | |||
939 | ||||
940 | /// Sets the "base" location and entity when that | |||
941 | /// information is known based on another transformation. | |||
942 | void setBase(SourceLocation Loc, DeclarationName Entity) { | |||
943 | this->Loc = Loc; | |||
944 | this->Entity = Entity; | |||
945 | } | |||
946 | ||||
947 | unsigned TransformTemplateDepth(unsigned Depth) { | |||
948 | return TemplateArgs.getNewDepth(Depth); | |||
949 | } | |||
950 | ||||
951 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, | |||
952 | SourceRange PatternRange, | |||
953 | ArrayRef<UnexpandedParameterPack> Unexpanded, | |||
954 | bool &ShouldExpand, bool &RetainExpansion, | |||
955 | Optional<unsigned> &NumExpansions) { | |||
956 | return getSema().CheckParameterPacksForExpansion(EllipsisLoc, | |||
957 | PatternRange, Unexpanded, | |||
958 | TemplateArgs, | |||
959 | ShouldExpand, | |||
960 | RetainExpansion, | |||
961 | NumExpansions); | |||
962 | } | |||
963 | ||||
964 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { | |||
965 | SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Pack); | |||
966 | } | |||
967 | ||||
968 | TemplateArgument ForgetPartiallySubstitutedPack() { | |||
969 | TemplateArgument Result; | |||
970 | if (NamedDecl *PartialPack | |||
971 | = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){ | |||
972 | MultiLevelTemplateArgumentList &TemplateArgs | |||
973 | = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs); | |||
974 | unsigned Depth, Index; | |||
975 | std::tie(Depth, Index) = getDepthAndIndex(PartialPack); | |||
976 | if (TemplateArgs.hasTemplateArgument(Depth, Index)) { | |||
977 | Result = TemplateArgs(Depth, Index); | |||
978 | TemplateArgs.setArgument(Depth, Index, TemplateArgument()); | |||
979 | } | |||
980 | } | |||
981 | ||||
982 | return Result; | |||
983 | } | |||
984 | ||||
985 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { | |||
986 | if (Arg.isNull()) | |||
987 | return; | |||
988 | ||||
989 | if (NamedDecl *PartialPack | |||
990 | = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){ | |||
991 | MultiLevelTemplateArgumentList &TemplateArgs | |||
992 | = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs); | |||
993 | unsigned Depth, Index; | |||
994 | std::tie(Depth, Index) = getDepthAndIndex(PartialPack); | |||
995 | TemplateArgs.setArgument(Depth, Index, Arg); | |||
996 | } | |||
997 | } | |||
998 | ||||
999 | /// Transform the given declaration by instantiating a reference to | |||
1000 | /// this declaration. | |||
1001 | Decl *TransformDecl(SourceLocation Loc, Decl *D); | |||
1002 | ||||
1003 | void transformAttrs(Decl *Old, Decl *New) { | |||
1004 | SemaRef.InstantiateAttrs(TemplateArgs, Old, New); | |||
1005 | } | |||
1006 | ||||
1007 | void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) { | |||
1008 | if (Old->isParameterPack()) { | |||
1009 | SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Old); | |||
1010 | for (auto *New : NewDecls) | |||
1011 | SemaRef.CurrentInstantiationScope->InstantiatedLocalPackArg( | |||
1012 | Old, cast<VarDecl>(New)); | |||
1013 | return; | |||
1014 | } | |||
1015 | ||||
1016 | assert(NewDecls.size() == 1 &&((NewDecls.size() == 1 && "should only have multiple expansions for a pack" ) ? static_cast<void> (0) : __assert_fail ("NewDecls.size() == 1 && \"should only have multiple expansions for a pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1017, __PRETTY_FUNCTION__)) | |||
1017 | "should only have multiple expansions for a pack")((NewDecls.size() == 1 && "should only have multiple expansions for a pack" ) ? static_cast<void> (0) : __assert_fail ("NewDecls.size() == 1 && \"should only have multiple expansions for a pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1017, __PRETTY_FUNCTION__)); | |||
1018 | Decl *New = NewDecls.front(); | |||
1019 | ||||
1020 | // If we've instantiated the call operator of a lambda or the call | |||
1021 | // operator template of a generic lambda, update the "instantiation of" | |||
1022 | // information. | |||
1023 | auto *NewMD = dyn_cast<CXXMethodDecl>(New); | |||
1024 | if (NewMD && isLambdaCallOperator(NewMD)) { | |||
1025 | auto *OldMD = dyn_cast<CXXMethodDecl>(Old); | |||
1026 | if (auto *NewTD = NewMD->getDescribedFunctionTemplate()) | |||
1027 | NewTD->setInstantiatedFromMemberTemplate( | |||
1028 | OldMD->getDescribedFunctionTemplate()); | |||
1029 | else | |||
1030 | NewMD->setInstantiationOfMemberFunction(OldMD, | |||
1031 | TSK_ImplicitInstantiation); | |||
1032 | } | |||
1033 | ||||
1034 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(Old, New); | |||
1035 | ||||
1036 | // We recreated a local declaration, but not by instantiating it. There | |||
1037 | // may be pending dependent diagnostics to produce. | |||
1038 | if (auto *DC = dyn_cast<DeclContext>(Old)) | |||
1039 | SemaRef.PerformDependentDiagnostics(DC, TemplateArgs); | |||
1040 | } | |||
1041 | ||||
1042 | /// Transform the definition of the given declaration by | |||
1043 | /// instantiating it. | |||
1044 | Decl *TransformDefinition(SourceLocation Loc, Decl *D); | |||
1045 | ||||
1046 | /// Transform the first qualifier within a scope by instantiating the | |||
1047 | /// declaration. | |||
1048 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc); | |||
1049 | ||||
1050 | /// Rebuild the exception declaration and register the declaration | |||
1051 | /// as an instantiated local. | |||
1052 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, | |||
1053 | TypeSourceInfo *Declarator, | |||
1054 | SourceLocation StartLoc, | |||
1055 | SourceLocation NameLoc, | |||
1056 | IdentifierInfo *Name); | |||
1057 | ||||
1058 | /// Rebuild the Objective-C exception declaration and register the | |||
1059 | /// declaration as an instantiated local. | |||
1060 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, | |||
1061 | TypeSourceInfo *TSInfo, QualType T); | |||
1062 | ||||
1063 | /// Check for tag mismatches when instantiating an | |||
1064 | /// elaborated type. | |||
1065 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, | |||
1066 | ElaboratedTypeKeyword Keyword, | |||
1067 | NestedNameSpecifierLoc QualifierLoc, | |||
1068 | QualType T); | |||
1069 | ||||
1070 | TemplateName | |||
1071 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, | |||
1072 | SourceLocation NameLoc, | |||
1073 | QualType ObjectType = QualType(), | |||
1074 | NamedDecl *FirstQualifierInScope = nullptr, | |||
1075 | bool AllowInjectedClassName = false); | |||
1076 | ||||
1077 | const LoopHintAttr *TransformLoopHintAttr(const LoopHintAttr *LH); | |||
1078 | ||||
1079 | ExprResult TransformPredefinedExpr(PredefinedExpr *E); | |||
1080 | ExprResult TransformDeclRefExpr(DeclRefExpr *E); | |||
1081 | ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E); | |||
1082 | ||||
1083 | ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E, | |||
1084 | NonTypeTemplateParmDecl *D); | |||
1085 | ExprResult TransformSubstNonTypeTemplateParmPackExpr( | |||
1086 | SubstNonTypeTemplateParmPackExpr *E); | |||
1087 | ExprResult TransformSubstNonTypeTemplateParmExpr( | |||
1088 | SubstNonTypeTemplateParmExpr *E); | |||
1089 | ||||
1090 | /// Rebuild a DeclRefExpr for a VarDecl reference. | |||
1091 | ExprResult RebuildVarDeclRefExpr(VarDecl *PD, SourceLocation Loc); | |||
1092 | ||||
1093 | /// Transform a reference to a function or init-capture parameter pack. | |||
1094 | ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, VarDecl *PD); | |||
1095 | ||||
1096 | /// Transform a FunctionParmPackExpr which was built when we couldn't | |||
1097 | /// expand a function parameter pack reference which refers to an expanded | |||
1098 | /// pack. | |||
1099 | ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E); | |||
1100 | ||||
1101 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, | |||
1102 | FunctionProtoTypeLoc TL) { | |||
1103 | // Call the base version; it will forward to our overridden version below. | |||
1104 | return inherited::TransformFunctionProtoType(TLB, TL); | |||
1105 | } | |||
1106 | ||||
1107 | template<typename Fn> | |||
1108 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, | |||
1109 | FunctionProtoTypeLoc TL, | |||
1110 | CXXRecordDecl *ThisContext, | |||
1111 | Qualifiers ThisTypeQuals, | |||
1112 | Fn TransformExceptionSpec); | |||
1113 | ||||
1114 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, | |||
1115 | int indexAdjustment, | |||
1116 | Optional<unsigned> NumExpansions, | |||
1117 | bool ExpectParameterPack); | |||
1118 | ||||
1119 | /// Transforms a template type parameter type by performing | |||
1120 | /// substitution of the corresponding template type argument. | |||
1121 | QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, | |||
1122 | TemplateTypeParmTypeLoc TL); | |||
1123 | ||||
1124 | /// Transforms an already-substituted template type parameter pack | |||
1125 | /// into either itself (if we aren't substituting into its pack expansion) | |||
1126 | /// or the appropriate substituted argument. | |||
1127 | QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB, | |||
1128 | SubstTemplateTypeParmPackTypeLoc TL); | |||
1129 | ||||
1130 | ExprResult TransformLambdaExpr(LambdaExpr *E) { | |||
1131 | LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); | |||
1132 | return TreeTransform<TemplateInstantiator>::TransformLambdaExpr(E); | |||
1133 | } | |||
1134 | ||||
1135 | ExprResult TransformRequiresExpr(RequiresExpr *E) { | |||
1136 | LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); | |||
1137 | return TreeTransform<TemplateInstantiator>::TransformRequiresExpr(E); | |||
| ||||
1138 | } | |||
1139 | ||||
1140 | bool TransformRequiresExprRequirements( | |||
1141 | ArrayRef<concepts::Requirement *> Reqs, | |||
1142 | SmallVectorImpl<concepts::Requirement *> &Transformed) { | |||
1143 | bool SatisfactionDetermined = false; | |||
1144 | for (concepts::Requirement *Req : Reqs) { | |||
1145 | concepts::Requirement *TransReq = nullptr; | |||
1146 | if (!SatisfactionDetermined) { | |||
1147 | if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) | |||
1148 | TransReq = TransformTypeRequirement(TypeReq); | |||
1149 | else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) | |||
1150 | TransReq = TransformExprRequirement(ExprReq); | |||
1151 | else | |||
1152 | TransReq = TransformNestedRequirement( | |||
1153 | cast<concepts::NestedRequirement>(Req)); | |||
1154 | if (!TransReq) | |||
1155 | return true; | |||
1156 | if (!TransReq->isDependent() && !TransReq->isSatisfied()) | |||
1157 | // [expr.prim.req]p6 | |||
1158 | // [...] The substitution and semantic constraint checking | |||
1159 | // proceeds in lexical order and stops when a condition that | |||
1160 | // determines the result of the requires-expression is | |||
1161 | // encountered. [..] | |||
1162 | SatisfactionDetermined = true; | |||
1163 | } else | |||
1164 | TransReq = Req; | |||
1165 | Transformed.push_back(TransReq); | |||
1166 | } | |||
1167 | return false; | |||
1168 | } | |||
1169 | ||||
1170 | TemplateParameterList *TransformTemplateParameterList( | |||
1171 | TemplateParameterList *OrigTPL) { | |||
1172 | if (!OrigTPL || !OrigTPL->size()) return OrigTPL; | |||
1173 | ||||
1174 | DeclContext *Owner = OrigTPL->getParam(0)->getDeclContext(); | |||
1175 | TemplateDeclInstantiator DeclInstantiator(getSema(), | |||
1176 | /* DeclContext *Owner */ Owner, TemplateArgs); | |||
1177 | return DeclInstantiator.SubstTemplateParams(OrigTPL); | |||
1178 | } | |||
1179 | ||||
1180 | concepts::TypeRequirement * | |||
1181 | TransformTypeRequirement(concepts::TypeRequirement *Req); | |||
1182 | concepts::ExprRequirement * | |||
1183 | TransformExprRequirement(concepts::ExprRequirement *Req); | |||
1184 | concepts::NestedRequirement * | |||
1185 | TransformNestedRequirement(concepts::NestedRequirement *Req); | |||
1186 | ||||
1187 | private: | |||
1188 | ExprResult transformNonTypeTemplateParmRef(NonTypeTemplateParmDecl *parm, | |||
1189 | SourceLocation loc, | |||
1190 | TemplateArgument arg); | |||
1191 | }; | |||
1192 | } | |||
1193 | ||||
1194 | bool TemplateInstantiator::AlreadyTransformed(QualType T) { | |||
1195 | if (T.isNull()) | |||
1196 | return true; | |||
1197 | ||||
1198 | if (T->isInstantiationDependentType() || T->isVariablyModifiedType()) | |||
1199 | return false; | |||
1200 | ||||
1201 | getSema().MarkDeclarationsReferencedInType(Loc, T); | |||
1202 | return true; | |||
1203 | } | |||
1204 | ||||
1205 | static TemplateArgument | |||
1206 | getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg) { | |||
1207 | assert(S.ArgumentPackSubstitutionIndex >= 0)((S.ArgumentPackSubstitutionIndex >= 0) ? static_cast<void > (0) : __assert_fail ("S.ArgumentPackSubstitutionIndex >= 0" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1207, __PRETTY_FUNCTION__)); | |||
1208 | assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size())((S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size()) ? static_cast<void> (0) : __assert_fail ("S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size()" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1208, __PRETTY_FUNCTION__)); | |||
1209 | Arg = Arg.pack_begin()[S.ArgumentPackSubstitutionIndex]; | |||
1210 | if (Arg.isPackExpansion()) | |||
1211 | Arg = Arg.getPackExpansionPattern(); | |||
1212 | return Arg; | |||
1213 | } | |||
1214 | ||||
1215 | Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) { | |||
1216 | if (!D) | |||
1217 | return nullptr; | |||
1218 | ||||
1219 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) { | |||
1220 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | |||
1221 | // If the corresponding template argument is NULL or non-existent, it's | |||
1222 | // because we are performing instantiation from explicitly-specified | |||
1223 | // template arguments in a function template, but there were some | |||
1224 | // arguments left unspecified. | |||
1225 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), | |||
1226 | TTP->getPosition())) | |||
1227 | return D; | |||
1228 | ||||
1229 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition()); | |||
1230 | ||||
1231 | if (TTP->isParameterPack()) { | |||
1232 | assert(Arg.getKind() == TemplateArgument::Pack &&((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1233, __PRETTY_FUNCTION__)) | |||
1233 | "Missing argument pack")((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1233, __PRETTY_FUNCTION__)); | |||
1234 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | |||
1235 | } | |||
1236 | ||||
1237 | TemplateName Template = Arg.getAsTemplate().getNameToSubstitute(); | |||
1238 | assert(!Template.isNull() && Template.getAsTemplateDecl() &&((!Template.isNull() && Template.getAsTemplateDecl() && "Wrong kind of template template argument") ? static_cast< void> (0) : __assert_fail ("!Template.isNull() && Template.getAsTemplateDecl() && \"Wrong kind of template template argument\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1239, __PRETTY_FUNCTION__)) | |||
1239 | "Wrong kind of template template argument")((!Template.isNull() && Template.getAsTemplateDecl() && "Wrong kind of template template argument") ? static_cast< void> (0) : __assert_fail ("!Template.isNull() && Template.getAsTemplateDecl() && \"Wrong kind of template template argument\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1239, __PRETTY_FUNCTION__)); | |||
1240 | return Template.getAsTemplateDecl(); | |||
1241 | } | |||
1242 | ||||
1243 | // Fall through to find the instantiated declaration for this template | |||
1244 | // template parameter. | |||
1245 | } | |||
1246 | ||||
1247 | return SemaRef.FindInstantiatedDecl(Loc, cast<NamedDecl>(D), TemplateArgs); | |||
1248 | } | |||
1249 | ||||
1250 | Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) { | |||
1251 | Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs); | |||
1252 | if (!Inst) | |||
1253 | return nullptr; | |||
1254 | ||||
1255 | getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst); | |||
1256 | return Inst; | |||
1257 | } | |||
1258 | ||||
1259 | NamedDecl * | |||
1260 | TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D, | |||
1261 | SourceLocation Loc) { | |||
1262 | // If the first part of the nested-name-specifier was a template type | |||
1263 | // parameter, instantiate that type parameter down to a tag type. | |||
1264 | if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) { | |||
1265 | const TemplateTypeParmType *TTP | |||
1266 | = cast<TemplateTypeParmType>(getSema().Context.getTypeDeclType(TTPD)); | |||
1267 | ||||
1268 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | |||
1269 | // FIXME: This needs testing w/ member access expressions. | |||
1270 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex()); | |||
1271 | ||||
1272 | if (TTP->isParameterPack()) { | |||
1273 | assert(Arg.getKind() == TemplateArgument::Pack &&((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1274, __PRETTY_FUNCTION__)) | |||
1274 | "Missing argument pack")((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1274, __PRETTY_FUNCTION__)); | |||
1275 | ||||
1276 | if (getSema().ArgumentPackSubstitutionIndex == -1) | |||
1277 | return nullptr; | |||
1278 | ||||
1279 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | |||
1280 | } | |||
1281 | ||||
1282 | QualType T = Arg.getAsType(); | |||
1283 | if (T.isNull()) | |||
1284 | return cast_or_null<NamedDecl>(TransformDecl(Loc, D)); | |||
1285 | ||||
1286 | if (const TagType *Tag = T->getAs<TagType>()) | |||
1287 | return Tag->getDecl(); | |||
1288 | ||||
1289 | // The resulting type is not a tag; complain. | |||
1290 | getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) << T; | |||
1291 | return nullptr; | |||
1292 | } | |||
1293 | } | |||
1294 | ||||
1295 | return cast_or_null<NamedDecl>(TransformDecl(Loc, D)); | |||
1296 | } | |||
1297 | ||||
1298 | VarDecl * | |||
1299 | TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl, | |||
1300 | TypeSourceInfo *Declarator, | |||
1301 | SourceLocation StartLoc, | |||
1302 | SourceLocation NameLoc, | |||
1303 | IdentifierInfo *Name) { | |||
1304 | VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator, | |||
1305 | StartLoc, NameLoc, Name); | |||
1306 | if (Var) | |||
1307 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); | |||
1308 | return Var; | |||
1309 | } | |||
1310 | ||||
1311 | VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, | |||
1312 | TypeSourceInfo *TSInfo, | |||
1313 | QualType T) { | |||
1314 | VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo, T); | |||
1315 | if (Var) | |||
1316 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); | |||
1317 | return Var; | |||
1318 | } | |||
1319 | ||||
1320 | QualType | |||
1321 | TemplateInstantiator::RebuildElaboratedType(SourceLocation KeywordLoc, | |||
1322 | ElaboratedTypeKeyword Keyword, | |||
1323 | NestedNameSpecifierLoc QualifierLoc, | |||
1324 | QualType T) { | |||
1325 | if (const TagType *TT = T->getAs<TagType>()) { | |||
1326 | TagDecl* TD = TT->getDecl(); | |||
1327 | ||||
1328 | SourceLocation TagLocation = KeywordLoc; | |||
1329 | ||||
1330 | IdentifierInfo *Id = TD->getIdentifier(); | |||
1331 | ||||
1332 | // TODO: should we even warn on struct/class mismatches for this? Seems | |||
1333 | // like it's likely to produce a lot of spurious errors. | |||
1334 | if (Id && Keyword != ETK_None && Keyword != ETK_Typename) { | |||
1335 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); | |||
1336 | if (!SemaRef.isAcceptableTagRedeclaration(TD, Kind, /*isDefinition*/false, | |||
1337 | TagLocation, Id)) { | |||
1338 | SemaRef.Diag(TagLocation, diag::err_use_with_wrong_tag) | |||
1339 | << Id | |||
1340 | << FixItHint::CreateReplacement(SourceRange(TagLocation), | |||
1341 | TD->getKindName()); | |||
1342 | SemaRef.Diag(TD->getLocation(), diag::note_previous_use); | |||
1343 | } | |||
1344 | } | |||
1345 | } | |||
1346 | ||||
1347 | return TreeTransform<TemplateInstantiator>::RebuildElaboratedType(KeywordLoc, | |||
1348 | Keyword, | |||
1349 | QualifierLoc, | |||
1350 | T); | |||
1351 | } | |||
1352 | ||||
1353 | TemplateName TemplateInstantiator::TransformTemplateName( | |||
1354 | CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc, | |||
1355 | QualType ObjectType, NamedDecl *FirstQualifierInScope, | |||
1356 | bool AllowInjectedClassName) { | |||
1357 | if (TemplateTemplateParmDecl *TTP | |||
1358 | = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) { | |||
1359 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | |||
1360 | // If the corresponding template argument is NULL or non-existent, it's | |||
1361 | // because we are performing instantiation from explicitly-specified | |||
1362 | // template arguments in a function template, but there were some | |||
1363 | // arguments left unspecified. | |||
1364 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), | |||
1365 | TTP->getPosition())) | |||
1366 | return Name; | |||
1367 | ||||
1368 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition()); | |||
1369 | ||||
1370 | if (TemplateArgs.isRewrite()) { | |||
1371 | // We're rewriting the template parameter as a reference to another | |||
1372 | // template parameter. | |||
1373 | if (Arg.getKind() == TemplateArgument::Pack) { | |||
1374 | assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&((Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion () && "unexpected pack arguments in template rewrite" ) ? static_cast<void> (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1375, __PRETTY_FUNCTION__)) | |||
1375 | "unexpected pack arguments in template rewrite")((Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion () && "unexpected pack arguments in template rewrite" ) ? static_cast<void> (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1375, __PRETTY_FUNCTION__)); | |||
1376 | Arg = Arg.pack_begin()->getPackExpansionPattern(); | |||
1377 | } | |||
1378 | assert(Arg.getKind() == TemplateArgument::Template &&((Arg.getKind() == TemplateArgument::Template && "unexpected nontype template argument kind in template rewrite" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Template && \"unexpected nontype template argument kind in template rewrite\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1379, __PRETTY_FUNCTION__)) | |||
1379 | "unexpected nontype template argument kind in template rewrite")((Arg.getKind() == TemplateArgument::Template && "unexpected nontype template argument kind in template rewrite" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Template && \"unexpected nontype template argument kind in template rewrite\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1379, __PRETTY_FUNCTION__)); | |||
1380 | return Arg.getAsTemplate(); | |||
1381 | } | |||
1382 | ||||
1383 | if (TTP->isParameterPack()) { | |||
1384 | assert(Arg.getKind() == TemplateArgument::Pack &&((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1385, __PRETTY_FUNCTION__)) | |||
1385 | "Missing argument pack")((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1385, __PRETTY_FUNCTION__)); | |||
1386 | ||||
1387 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | |||
1388 | // We have the template argument pack to substitute, but we're not | |||
1389 | // actually expanding the enclosing pack expansion yet. So, just | |||
1390 | // keep the entire argument pack. | |||
1391 | return getSema().Context.getSubstTemplateTemplateParmPack(TTP, Arg); | |||
1392 | } | |||
1393 | ||||
1394 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | |||
1395 | } | |||
1396 | ||||
1397 | TemplateName Template = Arg.getAsTemplate().getNameToSubstitute(); | |||
1398 | assert(!Template.isNull() && "Null template template argument")((!Template.isNull() && "Null template template argument" ) ? static_cast<void> (0) : __assert_fail ("!Template.isNull() && \"Null template template argument\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1398, __PRETTY_FUNCTION__)); | |||
1399 | assert(!Template.getAsQualifiedTemplateName() &&((!Template.getAsQualifiedTemplateName() && "template decl to substitute is qualified?" ) ? static_cast<void> (0) : __assert_fail ("!Template.getAsQualifiedTemplateName() && \"template decl to substitute is qualified?\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1400, __PRETTY_FUNCTION__)) | |||
1400 | "template decl to substitute is qualified?")((!Template.getAsQualifiedTemplateName() && "template decl to substitute is qualified?" ) ? static_cast<void> (0) : __assert_fail ("!Template.getAsQualifiedTemplateName() && \"template decl to substitute is qualified?\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1400, __PRETTY_FUNCTION__)); | |||
1401 | ||||
1402 | Template = getSema().Context.getSubstTemplateTemplateParm(TTP, Template); | |||
1403 | return Template; | |||
1404 | } | |||
1405 | } | |||
1406 | ||||
1407 | if (SubstTemplateTemplateParmPackStorage *SubstPack | |||
1408 | = Name.getAsSubstTemplateTemplateParmPack()) { | |||
1409 | if (getSema().ArgumentPackSubstitutionIndex == -1) | |||
1410 | return Name; | |||
1411 | ||||
1412 | TemplateArgument Arg = SubstPack->getArgumentPack(); | |||
1413 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | |||
1414 | return Arg.getAsTemplate().getNameToSubstitute(); | |||
1415 | } | |||
1416 | ||||
1417 | return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType, | |||
1418 | FirstQualifierInScope, | |||
1419 | AllowInjectedClassName); | |||
1420 | } | |||
1421 | ||||
1422 | ExprResult | |||
1423 | TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) { | |||
1424 | if (!E->isTypeDependent()) | |||
1425 | return E; | |||
1426 | ||||
1427 | return getSema().BuildPredefinedExpr(E->getLocation(), E->getIdentKind()); | |||
1428 | } | |||
1429 | ||||
1430 | ExprResult | |||
1431 | TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E, | |||
1432 | NonTypeTemplateParmDecl *NTTP) { | |||
1433 | // If the corresponding template argument is NULL or non-existent, it's | |||
1434 | // because we are performing instantiation from explicitly-specified | |||
1435 | // template arguments in a function template, but there were some | |||
1436 | // arguments left unspecified. | |||
1437 | if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(), | |||
1438 | NTTP->getPosition())) | |||
1439 | return E; | |||
1440 | ||||
1441 | TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), NTTP->getPosition()); | |||
1442 | ||||
1443 | if (TemplateArgs.isRewrite()) { | |||
1444 | // We're rewriting the template parameter as a reference to another | |||
1445 | // template parameter. | |||
1446 | if (Arg.getKind() == TemplateArgument::Pack) { | |||
1447 | assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&((Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion () && "unexpected pack arguments in template rewrite" ) ? static_cast<void> (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1448, __PRETTY_FUNCTION__)) | |||
1448 | "unexpected pack arguments in template rewrite")((Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion () && "unexpected pack arguments in template rewrite" ) ? static_cast<void> (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1448, __PRETTY_FUNCTION__)); | |||
1449 | Arg = Arg.pack_begin()->getPackExpansionPattern(); | |||
1450 | } | |||
1451 | assert(Arg.getKind() == TemplateArgument::Expression &&((Arg.getKind() == TemplateArgument::Expression && "unexpected nontype template argument kind in template rewrite" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Expression && \"unexpected nontype template argument kind in template rewrite\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1452, __PRETTY_FUNCTION__)) | |||
1452 | "unexpected nontype template argument kind in template rewrite")((Arg.getKind() == TemplateArgument::Expression && "unexpected nontype template argument kind in template rewrite" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Expression && \"unexpected nontype template argument kind in template rewrite\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1452, __PRETTY_FUNCTION__)); | |||
1453 | // FIXME: This can lead to the same subexpression appearing multiple times | |||
1454 | // in a complete expression. | |||
1455 | return Arg.getAsExpr(); | |||
1456 | } | |||
1457 | ||||
1458 | if (NTTP->isParameterPack()) { | |||
1459 | assert(Arg.getKind() == TemplateArgument::Pack &&((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1460, __PRETTY_FUNCTION__)) | |||
1460 | "Missing argument pack")((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1460, __PRETTY_FUNCTION__)); | |||
1461 | ||||
1462 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | |||
1463 | // We have an argument pack, but we can't select a particular argument | |||
1464 | // out of it yet. Therefore, we'll build an expression to hold on to that | |||
1465 | // argument pack. | |||
1466 | QualType TargetType = SemaRef.SubstType(NTTP->getType(), TemplateArgs, | |||
1467 | E->getLocation(), | |||
1468 | NTTP->getDeclName()); | |||
1469 | if (TargetType.isNull()) | |||
1470 | return ExprError(); | |||
1471 | ||||
1472 | QualType ExprType = TargetType.getNonLValueExprType(SemaRef.Context); | |||
1473 | if (TargetType->isRecordType()) | |||
1474 | ExprType.addConst(); | |||
1475 | ||||
1476 | return new (SemaRef.Context) SubstNonTypeTemplateParmPackExpr( | |||
1477 | ExprType, TargetType->isReferenceType() ? VK_LValue : VK_RValue, NTTP, | |||
1478 | E->getLocation(), Arg); | |||
1479 | } | |||
1480 | ||||
1481 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | |||
1482 | } | |||
1483 | ||||
1484 | return transformNonTypeTemplateParmRef(NTTP, E->getLocation(), Arg); | |||
1485 | } | |||
1486 | ||||
1487 | const LoopHintAttr * | |||
1488 | TemplateInstantiator::TransformLoopHintAttr(const LoopHintAttr *LH) { | |||
1489 | Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get(); | |||
1490 | ||||
1491 | if (TransformedExpr == LH->getValue()) | |||
1492 | return LH; | |||
1493 | ||||
1494 | // Generate error if there is a problem with the value. | |||
1495 | if (getSema().CheckLoopHintExpr(TransformedExpr, LH->getLocation())) | |||
1496 | return LH; | |||
1497 | ||||
1498 | // Create new LoopHintValueAttr with integral expression in place of the | |||
1499 | // non-type template parameter. | |||
1500 | return LoopHintAttr::CreateImplicit(getSema().Context, LH->getOption(), | |||
1501 | LH->getState(), TransformedExpr, *LH); | |||
1502 | } | |||
1503 | ||||
1504 | ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef( | |||
1505 | NonTypeTemplateParmDecl *parm, | |||
1506 | SourceLocation loc, | |||
1507 | TemplateArgument arg) { | |||
1508 | ExprResult result; | |||
1509 | ||||
1510 | // Determine the substituted parameter type. We can usually infer this from | |||
1511 | // the template argument, but not always. | |||
1512 | auto SubstParamType = [&] { | |||
1513 | QualType T; | |||
1514 | if (parm->isExpandedParameterPack()) | |||
1515 | T = parm->getExpansionType(SemaRef.ArgumentPackSubstitutionIndex); | |||
1516 | else | |||
1517 | T = parm->getType(); | |||
1518 | if (parm->isParameterPack() && isa<PackExpansionType>(T)) | |||
1519 | T = cast<PackExpansionType>(T)->getPattern(); | |||
1520 | return SemaRef.SubstType(T, TemplateArgs, loc, parm->getDeclName()); | |||
1521 | }; | |||
1522 | ||||
1523 | bool refParam = false; | |||
1524 | ||||
1525 | // The template argument itself might be an expression, in which case we just | |||
1526 | // return that expression. This happens when substituting into an alias | |||
1527 | // template. | |||
1528 | if (arg.getKind() == TemplateArgument::Expression) { | |||
1529 | Expr *argExpr = arg.getAsExpr(); | |||
1530 | result = argExpr; | |||
1531 | if (argExpr->isLValue()) { | |||
1532 | if (argExpr->getType()->isRecordType()) { | |||
1533 | // Check whether the parameter was actually a reference. | |||
1534 | QualType paramType = SubstParamType(); | |||
1535 | if (paramType.isNull()) | |||
1536 | return ExprError(); | |||
1537 | refParam = paramType->isReferenceType(); | |||
1538 | } else { | |||
1539 | refParam = true; | |||
1540 | } | |||
1541 | } | |||
1542 | } else if (arg.getKind() == TemplateArgument::Declaration || | |||
1543 | arg.getKind() == TemplateArgument::NullPtr) { | |||
1544 | ValueDecl *VD; | |||
1545 | if (arg.getKind() == TemplateArgument::Declaration) { | |||
1546 | VD = arg.getAsDecl(); | |||
1547 | ||||
1548 | // Find the instantiation of the template argument. This is | |||
1549 | // required for nested templates. | |||
1550 | VD = cast_or_null<ValueDecl>( | |||
1551 | getSema().FindInstantiatedDecl(loc, VD, TemplateArgs)); | |||
1552 | if (!VD) | |||
1553 | return ExprError(); | |||
1554 | } else { | |||
1555 | // Propagate NULL template argument. | |||
1556 | VD = nullptr; | |||
1557 | } | |||
1558 | ||||
1559 | QualType paramType = VD ? arg.getParamTypeForDecl() : arg.getNullPtrType(); | |||
1560 | assert(!paramType.isNull() && "type substitution failed for param type")((!paramType.isNull() && "type substitution failed for param type" ) ? static_cast<void> (0) : __assert_fail ("!paramType.isNull() && \"type substitution failed for param type\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1560, __PRETTY_FUNCTION__)); | |||
1561 | assert(!paramType->isDependentType() && "param type still dependent")((!paramType->isDependentType() && "param type still dependent" ) ? static_cast<void> (0) : __assert_fail ("!paramType->isDependentType() && \"param type still dependent\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1561, __PRETTY_FUNCTION__)); | |||
1562 | result = SemaRef.BuildExpressionFromDeclTemplateArgument(arg, paramType, loc); | |||
1563 | refParam = paramType->isReferenceType(); | |||
1564 | } else { | |||
1565 | result = SemaRef.BuildExpressionFromIntegralTemplateArgument(arg, loc); | |||
1566 | assert(result.isInvalid() ||((result.isInvalid() || SemaRef.Context.hasSameType(result.get ()->getType(), arg.getIntegralType())) ? static_cast<void > (0) : __assert_fail ("result.isInvalid() || SemaRef.Context.hasSameType(result.get()->getType(), arg.getIntegralType())" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1568, __PRETTY_FUNCTION__)) | |||
1567 | SemaRef.Context.hasSameType(result.get()->getType(),((result.isInvalid() || SemaRef.Context.hasSameType(result.get ()->getType(), arg.getIntegralType())) ? static_cast<void > (0) : __assert_fail ("result.isInvalid() || SemaRef.Context.hasSameType(result.get()->getType(), arg.getIntegralType())" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1568, __PRETTY_FUNCTION__)) | |||
1568 | arg.getIntegralType()))((result.isInvalid() || SemaRef.Context.hasSameType(result.get ()->getType(), arg.getIntegralType())) ? static_cast<void > (0) : __assert_fail ("result.isInvalid() || SemaRef.Context.hasSameType(result.get()->getType(), arg.getIntegralType())" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1568, __PRETTY_FUNCTION__)); | |||
1569 | } | |||
1570 | ||||
1571 | if (result.isInvalid()) | |||
1572 | return ExprError(); | |||
1573 | ||||
1574 | Expr *resultExpr = result.get(); | |||
1575 | return new (SemaRef.Context) SubstNonTypeTemplateParmExpr( | |||
1576 | resultExpr->getType(), resultExpr->getValueKind(), loc, parm, refParam, | |||
1577 | resultExpr); | |||
1578 | } | |||
1579 | ||||
1580 | ExprResult | |||
1581 | TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr( | |||
1582 | SubstNonTypeTemplateParmPackExpr *E) { | |||
1583 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | |||
1584 | // We aren't expanding the parameter pack, so just return ourselves. | |||
1585 | return E; | |||
1586 | } | |||
1587 | ||||
1588 | TemplateArgument Arg = E->getArgumentPack(); | |||
1589 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | |||
1590 | return transformNonTypeTemplateParmRef(E->getParameterPack(), | |||
1591 | E->getParameterPackLocation(), | |||
1592 | Arg); | |||
1593 | } | |||
1594 | ||||
1595 | ExprResult | |||
1596 | TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr( | |||
1597 | SubstNonTypeTemplateParmExpr *E) { | |||
1598 | ExprResult SubstReplacement = TransformExpr(E->getReplacement()); | |||
1599 | if (SubstReplacement.isInvalid()) | |||
1600 | return true; | |||
1601 | QualType SubstType = TransformType(E->getParameterType(getSema().Context)); | |||
1602 | if (SubstType.isNull()) | |||
1603 | return true; | |||
1604 | // The type may have been previously dependent and not now, which means we | |||
1605 | // might have to implicit cast the argument to the new type, for example: | |||
1606 | // template<auto T, decltype(T) U> | |||
1607 | // concept C = sizeof(U) == 4; | |||
1608 | // void foo() requires C<2, 'a'> { } | |||
1609 | // When normalizing foo(), we first form the normalized constraints of C: | |||
1610 | // AtomicExpr(sizeof(U) == 4, | |||
1611 | // U=SubstNonTypeTemplateParmExpr(Param=U, | |||
1612 | // Expr=DeclRef(U), | |||
1613 | // Type=decltype(T))) | |||
1614 | // Then we substitute T = 2, U = 'a' into the parameter mapping, and need to | |||
1615 | // produce: | |||
1616 | // AtomicExpr(sizeof(U) == 4, | |||
1617 | // U=SubstNonTypeTemplateParmExpr(Param=U, | |||
1618 | // Expr=ImpCast( | |||
1619 | // decltype(2), | |||
1620 | // SubstNTTPE(Param=U, Expr='a', | |||
1621 | // Type=char)), | |||
1622 | // Type=decltype(2))) | |||
1623 | // The call to CheckTemplateArgument here produces the ImpCast. | |||
1624 | TemplateArgument Converted; | |||
1625 | if (SemaRef.CheckTemplateArgument(E->getParameter(), SubstType, | |||
1626 | SubstReplacement.get(), | |||
1627 | Converted).isInvalid()) | |||
1628 | return true; | |||
1629 | return transformNonTypeTemplateParmRef(E->getParameter(), | |||
1630 | E->getExprLoc(), Converted); | |||
1631 | } | |||
1632 | ||||
1633 | ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(VarDecl *PD, | |||
1634 | SourceLocation Loc) { | |||
1635 | DeclarationNameInfo NameInfo(PD->getDeclName(), Loc); | |||
1636 | return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD); | |||
1637 | } | |||
1638 | ||||
1639 | ExprResult | |||
1640 | TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { | |||
1641 | if (getSema().ArgumentPackSubstitutionIndex != -1) { | |||
1642 | // We can expand this parameter pack now. | |||
1643 | VarDecl *D = E->getExpansion(getSema().ArgumentPackSubstitutionIndex); | |||
1644 | VarDecl *VD = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), D)); | |||
1645 | if (!VD) | |||
1646 | return ExprError(); | |||
1647 | return RebuildVarDeclRefExpr(VD, E->getExprLoc()); | |||
1648 | } | |||
1649 | ||||
1650 | QualType T = TransformType(E->getType()); | |||
1651 | if (T.isNull()) | |||
1652 | return ExprError(); | |||
1653 | ||||
1654 | // Transform each of the parameter expansions into the corresponding | |||
1655 | // parameters in the instantiation of the function decl. | |||
1656 | SmallVector<VarDecl *, 8> Vars; | |||
1657 | Vars.reserve(E->getNumExpansions()); | |||
1658 | for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end(); | |||
1659 | I != End; ++I) { | |||
1660 | VarDecl *D = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), *I)); | |||
1661 | if (!D) | |||
1662 | return ExprError(); | |||
1663 | Vars.push_back(D); | |||
1664 | } | |||
1665 | ||||
1666 | auto *PackExpr = | |||
1667 | FunctionParmPackExpr::Create(getSema().Context, T, E->getParameterPack(), | |||
1668 | E->getParameterPackLocation(), Vars); | |||
1669 | getSema().MarkFunctionParmPackReferenced(PackExpr); | |||
1670 | return PackExpr; | |||
1671 | } | |||
1672 | ||||
1673 | ExprResult | |||
1674 | TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E, | |||
1675 | VarDecl *PD) { | |||
1676 | typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack; | |||
1677 | llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found | |||
1678 | = getSema().CurrentInstantiationScope->findInstantiationOf(PD); | |||
1679 | assert(Found && "no instantiation for parameter pack")((Found && "no instantiation for parameter pack") ? static_cast <void> (0) : __assert_fail ("Found && \"no instantiation for parameter pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1679, __PRETTY_FUNCTION__)); | |||
1680 | ||||
1681 | Decl *TransformedDecl; | |||
1682 | if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) { | |||
1683 | // If this is a reference to a function parameter pack which we can | |||
1684 | // substitute but can't yet expand, build a FunctionParmPackExpr for it. | |||
1685 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | |||
1686 | QualType T = TransformType(E->getType()); | |||
1687 | if (T.isNull()) | |||
1688 | return ExprError(); | |||
1689 | auto *PackExpr = FunctionParmPackExpr::Create(getSema().Context, T, PD, | |||
1690 | E->getExprLoc(), *Pack); | |||
1691 | getSema().MarkFunctionParmPackReferenced(PackExpr); | |||
1692 | return PackExpr; | |||
1693 | } | |||
1694 | ||||
1695 | TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex]; | |||
1696 | } else { | |||
1697 | TransformedDecl = Found->get<Decl*>(); | |||
1698 | } | |||
1699 | ||||
1700 | // We have either an unexpanded pack or a specific expansion. | |||
1701 | return RebuildVarDeclRefExpr(cast<VarDecl>(TransformedDecl), E->getExprLoc()); | |||
1702 | } | |||
1703 | ||||
1704 | ExprResult | |||
1705 | TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) { | |||
1706 | NamedDecl *D = E->getDecl(); | |||
1707 | ||||
1708 | // Handle references to non-type template parameters and non-type template | |||
1709 | // parameter packs. | |||
1710 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { | |||
1711 | if (NTTP->getDepth() < TemplateArgs.getNumLevels()) | |||
1712 | return TransformTemplateParmRefExpr(E, NTTP); | |||
1713 | ||||
1714 | // We have a non-type template parameter that isn't fully substituted; | |||
1715 | // FindInstantiatedDecl will find it in the local instantiation scope. | |||
1716 | } | |||
1717 | ||||
1718 | // Handle references to function parameter packs. | |||
1719 | if (VarDecl *PD = dyn_cast<VarDecl>(D)) | |||
1720 | if (PD->isParameterPack()) | |||
1721 | return TransformFunctionParmPackRefExpr(E, PD); | |||
1722 | ||||
1723 | return TreeTransform<TemplateInstantiator>::TransformDeclRefExpr(E); | |||
1724 | } | |||
1725 | ||||
1726 | ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr( | |||
1727 | CXXDefaultArgExpr *E) { | |||
1728 | assert(!cast<FunctionDecl>(E->getParam()->getDeclContext())->((!cast<FunctionDecl>(E->getParam()->getDeclContext ())-> getDescribedFunctionTemplate() && "Default arg expressions are never formed in dependent cases." ) ? static_cast<void> (0) : __assert_fail ("!cast<FunctionDecl>(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1730, __PRETTY_FUNCTION__)) | |||
1729 | getDescribedFunctionTemplate() &&((!cast<FunctionDecl>(E->getParam()->getDeclContext ())-> getDescribedFunctionTemplate() && "Default arg expressions are never formed in dependent cases." ) ? static_cast<void> (0) : __assert_fail ("!cast<FunctionDecl>(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1730, __PRETTY_FUNCTION__)) | |||
1730 | "Default arg expressions are never formed in dependent cases.")((!cast<FunctionDecl>(E->getParam()->getDeclContext ())-> getDescribedFunctionTemplate() && "Default arg expressions are never formed in dependent cases." ) ? static_cast<void> (0) : __assert_fail ("!cast<FunctionDecl>(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1730, __PRETTY_FUNCTION__)); | |||
1731 | return SemaRef.BuildCXXDefaultArgExpr(E->getUsedLocation(), | |||
1732 | cast<FunctionDecl>(E->getParam()->getDeclContext()), | |||
1733 | E->getParam()); | |||
1734 | } | |||
1735 | ||||
1736 | template<typename Fn> | |||
1737 | QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB, | |||
1738 | FunctionProtoTypeLoc TL, | |||
1739 | CXXRecordDecl *ThisContext, | |||
1740 | Qualifiers ThisTypeQuals, | |||
1741 | Fn TransformExceptionSpec) { | |||
1742 | // We need a local instantiation scope for this function prototype. | |||
1743 | LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); | |||
1744 | return inherited::TransformFunctionProtoType( | |||
1745 | TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec); | |||
1746 | } | |||
1747 | ||||
1748 | ParmVarDecl * | |||
1749 | TemplateInstantiator::TransformFunctionTypeParam(ParmVarDecl *OldParm, | |||
1750 | int indexAdjustment, | |||
1751 | Optional<unsigned> NumExpansions, | |||
1752 | bool ExpectParameterPack) { | |||
1753 | auto NewParm = | |||
1754 | SemaRef.SubstParmVarDecl(OldParm, TemplateArgs, indexAdjustment, | |||
1755 | NumExpansions, ExpectParameterPack); | |||
1756 | if (NewParm && SemaRef.getLangOpts().OpenCL) | |||
1757 | SemaRef.deduceOpenCLAddressSpace(NewParm); | |||
1758 | return NewParm; | |||
1759 | } | |||
1760 | ||||
1761 | QualType | |||
1762 | TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB, | |||
1763 | TemplateTypeParmTypeLoc TL) { | |||
1764 | const TemplateTypeParmType *T = TL.getTypePtr(); | |||
1765 | if (T->getDepth() < TemplateArgs.getNumLevels()) { | |||
1766 | // Replace the template type parameter with its corresponding | |||
1767 | // template argument. | |||
1768 | ||||
1769 | // If the corresponding template argument is NULL or doesn't exist, it's | |||
1770 | // because we are performing instantiation from explicitly-specified | |||
1771 | // template arguments in a function template class, but there were some | |||
1772 | // arguments left unspecified. | |||
1773 | if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) { | |||
1774 | TemplateTypeParmTypeLoc NewTL | |||
1775 | = TLB.push<TemplateTypeParmTypeLoc>(TL.getType()); | |||
1776 | NewTL.setNameLoc(TL.getNameLoc()); | |||
1777 | return TL.getType(); | |||
1778 | } | |||
1779 | ||||
1780 | TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex()); | |||
1781 | ||||
1782 | if (TemplateArgs.isRewrite()) { | |||
1783 | // We're rewriting the template parameter as a reference to another | |||
1784 | // template parameter. | |||
1785 | if (Arg.getKind() == TemplateArgument::Pack) { | |||
1786 | assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&((Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion () && "unexpected pack arguments in template rewrite" ) ? static_cast<void> (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1787, __PRETTY_FUNCTION__)) | |||
1787 | "unexpected pack arguments in template rewrite")((Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion () && "unexpected pack arguments in template rewrite" ) ? static_cast<void> (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1787, __PRETTY_FUNCTION__)); | |||
1788 | Arg = Arg.pack_begin()->getPackExpansionPattern(); | |||
1789 | } | |||
1790 | assert(Arg.getKind() == TemplateArgument::Type &&((Arg.getKind() == TemplateArgument::Type && "unexpected nontype template argument kind in template rewrite" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Type && \"unexpected nontype template argument kind in template rewrite\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1791, __PRETTY_FUNCTION__)) | |||
1791 | "unexpected nontype template argument kind in template rewrite")((Arg.getKind() == TemplateArgument::Type && "unexpected nontype template argument kind in template rewrite" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Type && \"unexpected nontype template argument kind in template rewrite\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1791, __PRETTY_FUNCTION__)); | |||
1792 | QualType NewT = Arg.getAsType(); | |||
1793 | assert(isa<TemplateTypeParmType>(NewT) &&((isa<TemplateTypeParmType>(NewT) && "type parm not rewritten to type parm" ) ? static_cast<void> (0) : __assert_fail ("isa<TemplateTypeParmType>(NewT) && \"type parm not rewritten to type parm\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1794, __PRETTY_FUNCTION__)) | |||
1794 | "type parm not rewritten to type parm")((isa<TemplateTypeParmType>(NewT) && "type parm not rewritten to type parm" ) ? static_cast<void> (0) : __assert_fail ("isa<TemplateTypeParmType>(NewT) && \"type parm not rewritten to type parm\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1794, __PRETTY_FUNCTION__)); | |||
1795 | auto NewTL = TLB.push<TemplateTypeParmTypeLoc>(NewT); | |||
1796 | NewTL.setNameLoc(TL.getNameLoc()); | |||
1797 | return NewT; | |||
1798 | } | |||
1799 | ||||
1800 | if (T->isParameterPack()) { | |||
1801 | assert(Arg.getKind() == TemplateArgument::Pack &&((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1802, __PRETTY_FUNCTION__)) | |||
1802 | "Missing argument pack")((Arg.getKind() == TemplateArgument::Pack && "Missing argument pack" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1802, __PRETTY_FUNCTION__)); | |||
1803 | ||||
1804 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | |||
1805 | // We have the template argument pack, but we're not expanding the | |||
1806 | // enclosing pack expansion yet. Just save the template argument | |||
1807 | // pack for later substitution. | |||
1808 | QualType Result | |||
1809 | = getSema().Context.getSubstTemplateTypeParmPackType(T, Arg); | |||
1810 | SubstTemplateTypeParmPackTypeLoc NewTL | |||
1811 | = TLB.push<SubstTemplateTypeParmPackTypeLoc>(Result); | |||
1812 | NewTL.setNameLoc(TL.getNameLoc()); | |||
1813 | return Result; | |||
1814 | } | |||
1815 | ||||
1816 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | |||
1817 | } | |||
1818 | ||||
1819 | assert(Arg.getKind() == TemplateArgument::Type &&((Arg.getKind() == TemplateArgument::Type && "Template argument kind mismatch" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Type && \"Template argument kind mismatch\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1820, __PRETTY_FUNCTION__)) | |||
1820 | "Template argument kind mismatch")((Arg.getKind() == TemplateArgument::Type && "Template argument kind mismatch" ) ? static_cast<void> (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Type && \"Template argument kind mismatch\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1820, __PRETTY_FUNCTION__)); | |||
1821 | ||||
1822 | QualType Replacement = Arg.getAsType(); | |||
1823 | ||||
1824 | // TODO: only do this uniquing once, at the start of instantiation. | |||
1825 | QualType Result | |||
1826 | = getSema().Context.getSubstTemplateTypeParmType(T, Replacement); | |||
1827 | SubstTemplateTypeParmTypeLoc NewTL | |||
1828 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); | |||
1829 | NewTL.setNameLoc(TL.getNameLoc()); | |||
1830 | return Result; | |||
1831 | } | |||
1832 | ||||
1833 | // The template type parameter comes from an inner template (e.g., | |||
1834 | // the template parameter list of a member template inside the | |||
1835 | // template we are instantiating). Create a new template type | |||
1836 | // parameter with the template "level" reduced by one. | |||
1837 | TemplateTypeParmDecl *NewTTPDecl = nullptr; | |||
1838 | if (TemplateTypeParmDecl *OldTTPDecl = T->getDecl()) | |||
1839 | NewTTPDecl = cast_or_null<TemplateTypeParmDecl>( | |||
1840 | TransformDecl(TL.getNameLoc(), OldTTPDecl)); | |||
1841 | ||||
1842 | QualType Result = getSema().Context.getTemplateTypeParmType( | |||
1843 | T->getDepth() - TemplateArgs.getNumSubstitutedLevels(), T->getIndex(), | |||
1844 | T->isParameterPack(), NewTTPDecl); | |||
1845 | TemplateTypeParmTypeLoc NewTL = TLB.push<TemplateTypeParmTypeLoc>(Result); | |||
1846 | NewTL.setNameLoc(TL.getNameLoc()); | |||
1847 | return Result; | |||
1848 | } | |||
1849 | ||||
1850 | QualType | |||
1851 | TemplateInstantiator::TransformSubstTemplateTypeParmPackType( | |||
1852 | TypeLocBuilder &TLB, | |||
1853 | SubstTemplateTypeParmPackTypeLoc TL) { | |||
1854 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | |||
1855 | // We aren't expanding the parameter pack, so just return ourselves. | |||
1856 | SubstTemplateTypeParmPackTypeLoc NewTL | |||
1857 | = TLB.push<SubstTemplateTypeParmPackTypeLoc>(TL.getType()); | |||
1858 | NewTL.setNameLoc(TL.getNameLoc()); | |||
1859 | return TL.getType(); | |||
1860 | } | |||
1861 | ||||
1862 | TemplateArgument Arg = TL.getTypePtr()->getArgumentPack(); | |||
1863 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | |||
1864 | QualType Result = Arg.getAsType(); | |||
1865 | ||||
1866 | Result = getSema().Context.getSubstTemplateTypeParmType( | |||
1867 | TL.getTypePtr()->getReplacedParameter(), | |||
1868 | Result); | |||
1869 | SubstTemplateTypeParmTypeLoc NewTL | |||
1870 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); | |||
1871 | NewTL.setNameLoc(TL.getNameLoc()); | |||
1872 | return Result; | |||
1873 | } | |||
1874 | ||||
1875 | template<typename EntityPrinter> | |||
1876 | static concepts::Requirement::SubstitutionDiagnostic * | |||
1877 | createSubstDiag(Sema &S, TemplateDeductionInfo &Info, EntityPrinter Printer) { | |||
1878 | SmallString<128> Message; | |||
1879 | SourceLocation ErrorLoc; | |||
1880 | if (Info.hasSFINAEDiagnostic()) { | |||
1881 | PartialDiagnosticAt PDA(SourceLocation(), | |||
1882 | PartialDiagnostic::NullDiagnostic{}); | |||
1883 | Info.takeSFINAEDiagnostic(PDA); | |||
1884 | PDA.second.EmitToString(S.getDiagnostics(), Message); | |||
1885 | ErrorLoc = PDA.first; | |||
1886 | } else { | |||
1887 | ErrorLoc = Info.getLocation(); | |||
1888 | } | |||
1889 | char *MessageBuf = new (S.Context) char[Message.size()]; | |||
1890 | std::copy(Message.begin(), Message.end(), MessageBuf); | |||
1891 | SmallString<128> Entity; | |||
1892 | llvm::raw_svector_ostream OS(Entity); | |||
1893 | Printer(OS); | |||
1894 | char *EntityBuf = new (S.Context) char[Entity.size()]; | |||
1895 | std::copy(Entity.begin(), Entity.end(), EntityBuf); | |||
1896 | return new (S.Context) concepts::Requirement::SubstitutionDiagnostic{ | |||
1897 | StringRef(EntityBuf, Entity.size()), ErrorLoc, | |||
1898 | StringRef(MessageBuf, Message.size())}; | |||
1899 | } | |||
1900 | ||||
1901 | concepts::TypeRequirement * | |||
1902 | TemplateInstantiator::TransformTypeRequirement(concepts::TypeRequirement *Req) { | |||
1903 | if (!Req->isDependent() && !AlwaysRebuild()) | |||
1904 | return Req; | |||
1905 | if (Req->isSubstitutionFailure()) { | |||
1906 | if (AlwaysRebuild()) | |||
1907 | return RebuildTypeRequirement( | |||
1908 | Req->getSubstitutionDiagnostic()); | |||
1909 | return Req; | |||
1910 | } | |||
1911 | ||||
1912 | Sema::SFINAETrap Trap(SemaRef); | |||
1913 | TemplateDeductionInfo Info(Req->getType()->getTypeLoc().getBeginLoc()); | |||
1914 | Sema::InstantiatingTemplate TypeInst(SemaRef, | |||
1915 | Req->getType()->getTypeLoc().getBeginLoc(), Req, Info, | |||
1916 | Req->getType()->getTypeLoc().getSourceRange()); | |||
1917 | if (TypeInst.isInvalid()) | |||
1918 | return nullptr; | |||
1919 | TypeSourceInfo *TransType = TransformType(Req->getType()); | |||
1920 | if (!TransType || Trap.hasErrorOccurred()) | |||
1921 | return RebuildTypeRequirement(createSubstDiag(SemaRef, Info, | |||
1922 | [&] (llvm::raw_ostream& OS) { | |||
1923 | Req->getType()->getType().print(OS, SemaRef.getPrintingPolicy()); | |||
1924 | })); | |||
1925 | return RebuildTypeRequirement(TransType); | |||
1926 | } | |||
1927 | ||||
1928 | concepts::ExprRequirement * | |||
1929 | TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) { | |||
1930 | if (!Req->isDependent() && !AlwaysRebuild()) | |||
1931 | return Req; | |||
1932 | ||||
1933 | Sema::SFINAETrap Trap(SemaRef); | |||
1934 | TemplateDeductionInfo Info(Req->getExpr()->getBeginLoc()); | |||
1935 | ||||
1936 | llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> | |||
1937 | TransExpr; | |||
1938 | if (Req->isExprSubstitutionFailure()) | |||
1939 | TransExpr = Req->getExprSubstitutionDiagnostic(); | |||
1940 | else { | |||
1941 | Sema::InstantiatingTemplate ExprInst(SemaRef, Req->getExpr()->getBeginLoc(), | |||
1942 | Req, Info, | |||
1943 | Req->getExpr()->getSourceRange()); | |||
1944 | if (ExprInst.isInvalid()) | |||
1945 | return nullptr; | |||
1946 | ExprResult TransExprRes = TransformExpr(Req->getExpr()); | |||
1947 | if (TransExprRes.isInvalid() || Trap.hasErrorOccurred()) | |||
1948 | TransExpr = createSubstDiag(SemaRef, Info, | |||
1949 | [&] (llvm::raw_ostream& OS) { | |||
1950 | Req->getExpr()->printPretty(OS, nullptr, | |||
1951 | SemaRef.getPrintingPolicy()); | |||
1952 | }); | |||
1953 | else | |||
1954 | TransExpr = TransExprRes.get(); | |||
1955 | } | |||
1956 | ||||
1957 | llvm::Optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq; | |||
1958 | const auto &RetReq = Req->getReturnTypeRequirement(); | |||
1959 | if (RetReq.isEmpty()) | |||
1960 | TransRetReq.emplace(); | |||
1961 | else if (RetReq.isSubstitutionFailure()) | |||
1962 | TransRetReq.emplace(RetReq.getSubstitutionDiagnostic()); | |||
1963 | else if (RetReq.isTypeConstraint()) { | |||
1964 | TemplateParameterList *OrigTPL = | |||
1965 | RetReq.getTypeConstraintTemplateParameterList(); | |||
1966 | Sema::InstantiatingTemplate TPLInst(SemaRef, OrigTPL->getTemplateLoc(), | |||
1967 | Req, Info, OrigTPL->getSourceRange()); | |||
1968 | if (TPLInst.isInvalid()) | |||
1969 | return nullptr; | |||
1970 | TemplateParameterList *TPL = | |||
1971 | TransformTemplateParameterList(OrigTPL); | |||
1972 | if (!TPL) | |||
1973 | TransRetReq.emplace(createSubstDiag(SemaRef, Info, | |||
1974 | [&] (llvm::raw_ostream& OS) { | |||
1975 | RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint() | |||
1976 | ->printPretty(OS, nullptr, SemaRef.getPrintingPolicy()); | |||
1977 | })); | |||
1978 | else { | |||
1979 | TPLInst.Clear(); | |||
1980 | TransRetReq.emplace(TPL); | |||
1981 | } | |||
1982 | } | |||
1983 | assert(TransRetReq.hasValue() &&((TransRetReq.hasValue() && "All code paths leading here must set TransRetReq" ) ? static_cast<void> (0) : __assert_fail ("TransRetReq.hasValue() && \"All code paths leading here must set TransRetReq\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1984, __PRETTY_FUNCTION__)) | |||
1984 | "All code paths leading here must set TransRetReq")((TransRetReq.hasValue() && "All code paths leading here must set TransRetReq" ) ? static_cast<void> (0) : __assert_fail ("TransRetReq.hasValue() && \"All code paths leading here must set TransRetReq\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1984, __PRETTY_FUNCTION__)); | |||
1985 | if (Expr *E = TransExpr.dyn_cast<Expr *>()) | |||
1986 | return RebuildExprRequirement(E, Req->isSimple(), Req->getNoexceptLoc(), | |||
1987 | std::move(*TransRetReq)); | |||
1988 | return RebuildExprRequirement( | |||
1989 | TransExpr.get<concepts::Requirement::SubstitutionDiagnostic *>(), | |||
1990 | Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq)); | |||
1991 | } | |||
1992 | ||||
1993 | concepts::NestedRequirement * | |||
1994 | TemplateInstantiator::TransformNestedRequirement( | |||
1995 | concepts::NestedRequirement *Req) { | |||
1996 | if (!Req->isDependent() && !AlwaysRebuild()) | |||
1997 | return Req; | |||
1998 | if (Req->isSubstitutionFailure()) { | |||
1999 | if (AlwaysRebuild()) | |||
2000 | return RebuildNestedRequirement( | |||
2001 | Req->getSubstitutionDiagnostic()); | |||
2002 | return Req; | |||
2003 | } | |||
2004 | Sema::InstantiatingTemplate ReqInst(SemaRef, | |||
2005 | Req->getConstraintExpr()->getBeginLoc(), Req, | |||
2006 | Sema::InstantiatingTemplate::ConstraintsCheck{}, | |||
2007 | Req->getConstraintExpr()->getSourceRange()); | |||
2008 | ||||
2009 | ExprResult TransConstraint; | |||
2010 | TemplateDeductionInfo Info(Req->getConstraintExpr()->getBeginLoc()); | |||
2011 | { | |||
2012 | EnterExpressionEvaluationContext ContextRAII( | |||
2013 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); | |||
2014 | Sema::SFINAETrap Trap(SemaRef); | |||
2015 | Sema::InstantiatingTemplate ConstrInst(SemaRef, | |||
2016 | Req->getConstraintExpr()->getBeginLoc(), Req, Info, | |||
2017 | Req->getConstraintExpr()->getSourceRange()); | |||
2018 | if (ConstrInst.isInvalid()) | |||
2019 | return nullptr; | |||
2020 | TransConstraint = TransformExpr(Req->getConstraintExpr()); | |||
2021 | if (TransConstraint.isInvalid() || Trap.hasErrorOccurred()) | |||
2022 | return RebuildNestedRequirement(createSubstDiag(SemaRef, Info, | |||
2023 | [&] (llvm::raw_ostream& OS) { | |||
2024 | Req->getConstraintExpr()->printPretty(OS, nullptr, | |||
2025 | SemaRef.getPrintingPolicy()); | |||
2026 | })); | |||
2027 | } | |||
2028 | return RebuildNestedRequirement(TransConstraint.get()); | |||
2029 | } | |||
2030 | ||||
2031 | ||||
2032 | /// Perform substitution on the type T with a given set of template | |||
2033 | /// arguments. | |||
2034 | /// | |||
2035 | /// This routine substitutes the given template arguments into the | |||
2036 | /// type T and produces the instantiated type. | |||
2037 | /// | |||
2038 | /// \param T the type into which the template arguments will be | |||
2039 | /// substituted. If this type is not dependent, it will be returned | |||
2040 | /// immediately. | |||
2041 | /// | |||
2042 | /// \param Args the template arguments that will be | |||
2043 | /// substituted for the top-level template parameters within T. | |||
2044 | /// | |||
2045 | /// \param Loc the location in the source code where this substitution | |||
2046 | /// is being performed. It will typically be the location of the | |||
2047 | /// declarator (if we're instantiating the type of some declaration) | |||
2048 | /// or the location of the type in the source code (if, e.g., we're | |||
2049 | /// instantiating the type of a cast expression). | |||
2050 | /// | |||
2051 | /// \param Entity the name of the entity associated with a declaration | |||
2052 | /// being instantiated (if any). May be empty to indicate that there | |||
2053 | /// is no such entity (if, e.g., this is a type that occurs as part of | |||
2054 | /// a cast expression) or that the entity has no name (e.g., an | |||
2055 | /// unnamed function parameter). | |||
2056 | /// | |||
2057 | /// \param AllowDeducedTST Whether a DeducedTemplateSpecializationType is | |||
2058 | /// acceptable as the top level type of the result. | |||
2059 | /// | |||
2060 | /// \returns If the instantiation succeeds, the instantiated | |||
2061 | /// type. Otherwise, produces diagnostics and returns a NULL type. | |||
2062 | TypeSourceInfo *Sema::SubstType(TypeSourceInfo *T, | |||
2063 | const MultiLevelTemplateArgumentList &Args, | |||
2064 | SourceLocation Loc, | |||
2065 | DeclarationName Entity, | |||
2066 | bool AllowDeducedTST) { | |||
2067 | assert(!CodeSynthesisContexts.empty() &&((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2069, __PRETTY_FUNCTION__)) | |||
2068 | "Cannot perform an instantiation without some context on the "((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2069, __PRETTY_FUNCTION__)) | |||
2069 | "instantiation stack")((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2069, __PRETTY_FUNCTION__)); | |||
2070 | ||||
2071 | if (!T->getType()->isInstantiationDependentType() && | |||
2072 | !T->getType()->isVariablyModifiedType()) | |||
2073 | return T; | |||
2074 | ||||
2075 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | |||
2076 | return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(T) | |||
2077 | : Instantiator.TransformType(T); | |||
2078 | } | |||
2079 | ||||
2080 | TypeSourceInfo *Sema::SubstType(TypeLoc TL, | |||
2081 | const MultiLevelTemplateArgumentList &Args, | |||
2082 | SourceLocation Loc, | |||
2083 | DeclarationName Entity) { | |||
2084 | assert(!CodeSynthesisContexts.empty() &&((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2086, __PRETTY_FUNCTION__)) | |||
2085 | "Cannot perform an instantiation without some context on the "((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2086, __PRETTY_FUNCTION__)) | |||
2086 | "instantiation stack")((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2086, __PRETTY_FUNCTION__)); | |||
2087 | ||||
2088 | if (TL.getType().isNull()) | |||
2089 | return nullptr; | |||
2090 | ||||
2091 | if (!TL.getType()->isInstantiationDependentType() && | |||
2092 | !TL.getType()->isVariablyModifiedType()) { | |||
2093 | // FIXME: Make a copy of the TypeLoc data here, so that we can | |||
2094 | // return a new TypeSourceInfo. Inefficient! | |||
2095 | TypeLocBuilder TLB; | |||
2096 | TLB.pushFullCopy(TL); | |||
2097 | return TLB.getTypeSourceInfo(Context, TL.getType()); | |||
2098 | } | |||
2099 | ||||
2100 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | |||
2101 | TypeLocBuilder TLB; | |||
2102 | TLB.reserve(TL.getFullDataSize()); | |||
2103 | QualType Result = Instantiator.TransformType(TLB, TL); | |||
2104 | if (Result.isNull()) | |||
2105 | return nullptr; | |||
2106 | ||||
2107 | return TLB.getTypeSourceInfo(Context, Result); | |||
2108 | } | |||
2109 | ||||
2110 | /// Deprecated form of the above. | |||
2111 | QualType Sema::SubstType(QualType T, | |||
2112 | const MultiLevelTemplateArgumentList &TemplateArgs, | |||
2113 | SourceLocation Loc, DeclarationName Entity) { | |||
2114 | assert(!CodeSynthesisContexts.empty() &&((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2116, __PRETTY_FUNCTION__)) | |||
2115 | "Cannot perform an instantiation without some context on the "((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2116, __PRETTY_FUNCTION__)) | |||
2116 | "instantiation stack")((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2116, __PRETTY_FUNCTION__)); | |||
2117 | ||||
2118 | // If T is not a dependent type or a variably-modified type, there | |||
2119 | // is nothing to do. | |||
2120 | if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType()) | |||
2121 | return T; | |||
2122 | ||||
2123 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity); | |||
2124 | return Instantiator.TransformType(T); | |||
2125 | } | |||
2126 | ||||
2127 | static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) { | |||
2128 | if (T->getType()->isInstantiationDependentType() || | |||
2129 | T->getType()->isVariablyModifiedType()) | |||
2130 | return true; | |||
2131 | ||||
2132 | TypeLoc TL = T->getTypeLoc().IgnoreParens(); | |||
2133 | if (!TL.getAs<FunctionProtoTypeLoc>()) | |||
2134 | return false; | |||
2135 | ||||
2136 | FunctionProtoTypeLoc FP = TL.castAs<FunctionProtoTypeLoc>(); | |||
2137 | for (ParmVarDecl *P : FP.getParams()) { | |||
2138 | // This must be synthesized from a typedef. | |||
2139 | if (!P) continue; | |||
2140 | ||||
2141 | // If there are any parameters, a new TypeSourceInfo that refers to the | |||
2142 | // instantiated parameters must be built. | |||
2143 | return true; | |||
2144 | } | |||
2145 | ||||
2146 | return false; | |||
2147 | } | |||
2148 | ||||
2149 | /// A form of SubstType intended specifically for instantiating the | |||
2150 | /// type of a FunctionDecl. Its purpose is solely to force the | |||
2151 | /// instantiation of default-argument expressions and to avoid | |||
2152 | /// instantiating an exception-specification. | |||
2153 | TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T, | |||
2154 | const MultiLevelTemplateArgumentList &Args, | |||
2155 | SourceLocation Loc, | |||
2156 | DeclarationName Entity, | |||
2157 | CXXRecordDecl *ThisContext, | |||
2158 | Qualifiers ThisTypeQuals) { | |||
2159 | assert(!CodeSynthesisContexts.empty() &&((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2161, __PRETTY_FUNCTION__)) | |||
2160 | "Cannot perform an instantiation without some context on the "((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2161, __PRETTY_FUNCTION__)) | |||
2161 | "instantiation stack")((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2161, __PRETTY_FUNCTION__)); | |||
2162 | ||||
2163 | if (!NeedsInstantiationAsFunctionType(T)) | |||
2164 | return T; | |||
2165 | ||||
2166 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | |||
2167 | ||||
2168 | TypeLocBuilder TLB; | |||
2169 | ||||
2170 | TypeLoc TL = T->getTypeLoc(); | |||
2171 | TLB.reserve(TL.getFullDataSize()); | |||
2172 | ||||
2173 | QualType Result; | |||
2174 | ||||
2175 | if (FunctionProtoTypeLoc Proto = | |||
2176 | TL.IgnoreParens().getAs<FunctionProtoTypeLoc>()) { | |||
2177 | // Instantiate the type, other than its exception specification. The | |||
2178 | // exception specification is instantiated in InitFunctionInstantiation | |||
2179 | // once we've built the FunctionDecl. | |||
2180 | // FIXME: Set the exception specification to EST_Uninstantiated here, | |||
2181 | // instead of rebuilding the function type again later. | |||
2182 | Result = Instantiator.TransformFunctionProtoType( | |||
2183 | TLB, Proto, ThisContext, ThisTypeQuals, | |||
2184 | [](FunctionProtoType::ExceptionSpecInfo &ESI, | |||
2185 | bool &Changed) { return false; }); | |||
2186 | } else { | |||
2187 | Result = Instantiator.TransformType(TLB, TL); | |||
2188 | } | |||
2189 | if (Result.isNull()) | |||
2190 | return nullptr; | |||
2191 | ||||
2192 | return TLB.getTypeSourceInfo(Context, Result); | |||
2193 | } | |||
2194 | ||||
2195 | bool Sema::SubstExceptionSpec(SourceLocation Loc, | |||
2196 | FunctionProtoType::ExceptionSpecInfo &ESI, | |||
2197 | SmallVectorImpl<QualType> &ExceptionStorage, | |||
2198 | const MultiLevelTemplateArgumentList &Args) { | |||
2199 | assert(ESI.Type != EST_Uninstantiated)((ESI.Type != EST_Uninstantiated) ? static_cast<void> ( 0) : __assert_fail ("ESI.Type != EST_Uninstantiated", "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2199, __PRETTY_FUNCTION__)); | |||
2200 | ||||
2201 | bool Changed = false; | |||
2202 | TemplateInstantiator Instantiator(*this, Args, Loc, DeclarationName()); | |||
2203 | return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage, | |||
2204 | Changed); | |||
2205 | } | |||
2206 | ||||
2207 | void Sema::SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, | |||
2208 | const MultiLevelTemplateArgumentList &Args) { | |||
2209 | FunctionProtoType::ExceptionSpecInfo ESI = | |||
2210 | Proto->getExtProtoInfo().ExceptionSpec; | |||
2211 | ||||
2212 | SmallVector<QualType, 4> ExceptionStorage; | |||
2213 | if (SubstExceptionSpec(New->getTypeSourceInfo()->getTypeLoc().getEndLoc(), | |||
2214 | ESI, ExceptionStorage, Args)) | |||
2215 | // On error, recover by dropping the exception specification. | |||
2216 | ESI.Type = EST_None; | |||
2217 | ||||
2218 | UpdateExceptionSpec(New, ESI); | |||
2219 | } | |||
2220 | ||||
2221 | namespace { | |||
2222 | ||||
2223 | struct GetContainedInventedTypeParmVisitor : | |||
2224 | public TypeVisitor<GetContainedInventedTypeParmVisitor, | |||
2225 | TemplateTypeParmDecl *> { | |||
2226 | using TypeVisitor<GetContainedInventedTypeParmVisitor, | |||
2227 | TemplateTypeParmDecl *>::Visit; | |||
2228 | ||||
2229 | TemplateTypeParmDecl *Visit(QualType T) { | |||
2230 | if (T.isNull()) | |||
2231 | return nullptr; | |||
2232 | return Visit(T.getTypePtr()); | |||
2233 | } | |||
2234 | // The deduced type itself. | |||
2235 | TemplateTypeParmDecl *VisitTemplateTypeParmType( | |||
2236 | const TemplateTypeParmType *T) { | |||
2237 | if (!T->getDecl() || !T->getDecl()->isImplicit()) | |||
2238 | return nullptr; | |||
2239 | return T->getDecl(); | |||
2240 | } | |||
2241 | ||||
2242 | // Only these types can contain 'auto' types, and subsequently be replaced | |||
2243 | // by references to invented parameters. | |||
2244 | ||||
2245 | TemplateTypeParmDecl *VisitElaboratedType(const ElaboratedType *T) { | |||
2246 | return Visit(T->getNamedType()); | |||
2247 | } | |||
2248 | ||||
2249 | TemplateTypeParmDecl *VisitPointerType(const PointerType *T) { | |||
2250 | return Visit(T->getPointeeType()); | |||
2251 | } | |||
2252 | ||||
2253 | TemplateTypeParmDecl *VisitBlockPointerType(const BlockPointerType *T) { | |||
2254 | return Visit(T->getPointeeType()); | |||
2255 | } | |||
2256 | ||||
2257 | TemplateTypeParmDecl *VisitReferenceType(const ReferenceType *T) { | |||
2258 | return Visit(T->getPointeeTypeAsWritten()); | |||
2259 | } | |||
2260 | ||||
2261 | TemplateTypeParmDecl *VisitMemberPointerType(const MemberPointerType *T) { | |||
2262 | return Visit(T->getPointeeType()); | |||
2263 | } | |||
2264 | ||||
2265 | TemplateTypeParmDecl *VisitArrayType(const ArrayType *T) { | |||
2266 | return Visit(T->getElementType()); | |||
2267 | } | |||
2268 | ||||
2269 | TemplateTypeParmDecl *VisitDependentSizedExtVectorType( | |||
2270 | const DependentSizedExtVectorType *T) { | |||
2271 | return Visit(T->getElementType()); | |||
2272 | } | |||
2273 | ||||
2274 | TemplateTypeParmDecl *VisitVectorType(const VectorType *T) { | |||
2275 | return Visit(T->getElementType()); | |||
2276 | } | |||
2277 | ||||
2278 | TemplateTypeParmDecl *VisitFunctionProtoType(const FunctionProtoType *T) { | |||
2279 | return VisitFunctionType(T); | |||
2280 | } | |||
2281 | ||||
2282 | TemplateTypeParmDecl *VisitFunctionType(const FunctionType *T) { | |||
2283 | return Visit(T->getReturnType()); | |||
2284 | } | |||
2285 | ||||
2286 | TemplateTypeParmDecl *VisitParenType(const ParenType *T) { | |||
2287 | return Visit(T->getInnerType()); | |||
2288 | } | |||
2289 | ||||
2290 | TemplateTypeParmDecl *VisitAttributedType(const AttributedType *T) { | |||
2291 | return Visit(T->getModifiedType()); | |||
2292 | } | |||
2293 | ||||
2294 | TemplateTypeParmDecl *VisitMacroQualifiedType(const MacroQualifiedType *T) { | |||
2295 | return Visit(T->getUnderlyingType()); | |||
2296 | } | |||
2297 | ||||
2298 | TemplateTypeParmDecl *VisitAdjustedType(const AdjustedType *T) { | |||
2299 | return Visit(T->getOriginalType()); | |||
2300 | } | |||
2301 | ||||
2302 | TemplateTypeParmDecl *VisitPackExpansionType(const PackExpansionType *T) { | |||
2303 | return Visit(T->getPattern()); | |||
2304 | } | |||
2305 | }; | |||
2306 | ||||
2307 | } // namespace | |||
2308 | ||||
2309 | ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm, | |||
2310 | const MultiLevelTemplateArgumentList &TemplateArgs, | |||
2311 | int indexAdjustment, | |||
2312 | Optional<unsigned> NumExpansions, | |||
2313 | bool ExpectParameterPack) { | |||
2314 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); | |||
2315 | TypeSourceInfo *NewDI = nullptr; | |||
2316 | ||||
2317 | TypeLoc OldTL = OldDI->getTypeLoc(); | |||
2318 | if (PackExpansionTypeLoc ExpansionTL = OldTL.getAs<PackExpansionTypeLoc>()) { | |||
2319 | ||||
2320 | // We have a function parameter pack. Substitute into the pattern of the | |||
2321 | // expansion. | |||
2322 | NewDI = SubstType(ExpansionTL.getPatternLoc(), TemplateArgs, | |||
2323 | OldParm->getLocation(), OldParm->getDeclName()); | |||
2324 | if (!NewDI) | |||
2325 | return nullptr; | |||
2326 | ||||
2327 | if (NewDI->getType()->containsUnexpandedParameterPack()) { | |||
2328 | // We still have unexpanded parameter packs, which means that | |||
2329 | // our function parameter is still a function parameter pack. | |||
2330 | // Therefore, make its type a pack expansion type. | |||
2331 | NewDI = CheckPackExpansion(NewDI, ExpansionTL.getEllipsisLoc(), | |||
2332 | NumExpansions); | |||
2333 | } else if (ExpectParameterPack) { | |||
2334 | // We expected to get a parameter pack but didn't (because the type | |||
2335 | // itself is not a pack expansion type), so complain. This can occur when | |||
2336 | // the substitution goes through an alias template that "loses" the | |||
2337 | // pack expansion. | |||
2338 | Diag(OldParm->getLocation(), | |||
2339 | diag::err_function_parameter_pack_without_parameter_packs) | |||
2340 | << NewDI->getType(); | |||
2341 | return nullptr; | |||
2342 | } | |||
2343 | } else { | |||
2344 | NewDI = SubstType(OldDI, TemplateArgs, OldParm->getLocation(), | |||
2345 | OldParm->getDeclName()); | |||
2346 | } | |||
2347 | ||||
2348 | if (!NewDI) | |||
2349 | return nullptr; | |||
2350 | ||||
2351 | if (NewDI->getType()->isVoidType()) { | |||
2352 | Diag(OldParm->getLocation(), diag::err_param_with_void_type); | |||
2353 | return nullptr; | |||
2354 | } | |||
2355 | ||||
2356 | // In abbreviated templates, TemplateTypeParmDecls with possible | |||
2357 | // TypeConstraints are created when the parameter list is originally parsed. | |||
2358 | // The TypeConstraints can therefore reference other functions parameters in | |||
2359 | // the abbreviated function template, which is why we must instantiate them | |||
2360 | // here, when the instantiated versions of those referenced parameters are in | |||
2361 | // scope. | |||
2362 | if (TemplateTypeParmDecl *TTP = | |||
2363 | GetContainedInventedTypeParmVisitor().Visit(OldDI->getType())) { | |||
2364 | if (const TypeConstraint *TC = TTP->getTypeConstraint()) { | |||
2365 | auto *Inst = cast_or_null<TemplateTypeParmDecl>( | |||
2366 | FindInstantiatedDecl(TTP->getLocation(), TTP, TemplateArgs)); | |||
2367 | // We will first get here when instantiating the abbreviated function | |||
2368 | // template's described function, but we might also get here later. | |||
2369 | // Make sure we do not instantiate the TypeConstraint more than once. | |||
2370 | if (Inst && !Inst->getTypeConstraint()) { | |||
2371 | // TODO: Concepts: do not instantiate the constraint (delayed constraint | |||
2372 | // substitution) | |||
2373 | const ASTTemplateArgumentListInfo *TemplArgInfo | |||
2374 | = TC->getTemplateArgsAsWritten(); | |||
2375 | TemplateArgumentListInfo InstArgs; | |||
2376 | ||||
2377 | if (TemplArgInfo) { | |||
2378 | InstArgs.setLAngleLoc(TemplArgInfo->LAngleLoc); | |||
2379 | InstArgs.setRAngleLoc(TemplArgInfo->RAngleLoc); | |||
2380 | if (Subst(TemplArgInfo->getTemplateArgs(), | |||
2381 | TemplArgInfo->NumTemplateArgs, InstArgs, TemplateArgs)) | |||
2382 | return nullptr; | |||
2383 | } | |||
2384 | if (AttachTypeConstraint( | |||
2385 | TC->getNestedNameSpecifierLoc(), TC->getConceptNameInfo(), | |||
2386 | TC->getNamedConcept(), &InstArgs, Inst, | |||
2387 | TTP->isParameterPack() | |||
2388 | ? cast<CXXFoldExpr>(TC->getImmediatelyDeclaredConstraint()) | |||
2389 | ->getEllipsisLoc() | |||
2390 | : SourceLocation())) | |||
2391 | return nullptr; | |||
2392 | } | |||
2393 | } | |||
2394 | } | |||
2395 | ||||
2396 | ParmVarDecl *NewParm = CheckParameter(Context.getTranslationUnitDecl(), | |||
2397 | OldParm->getInnerLocStart(), | |||
2398 | OldParm->getLocation(), | |||
2399 | OldParm->getIdentifier(), | |||
2400 | NewDI->getType(), NewDI, | |||
2401 | OldParm->getStorageClass()); | |||
2402 | if (!NewParm) | |||
2403 | return nullptr; | |||
2404 | ||||
2405 | // Mark the (new) default argument as uninstantiated (if any). | |||
2406 | if (OldParm->hasUninstantiatedDefaultArg()) { | |||
2407 | Expr *Arg = OldParm->getUninstantiatedDefaultArg(); | |||
2408 | NewParm->setUninstantiatedDefaultArg(Arg); | |||
2409 | } else if (OldParm->hasUnparsedDefaultArg()) { | |||
2410 | NewParm->setUnparsedDefaultArg(); | |||
2411 | UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm); | |||
2412 | } else if (Expr *Arg = OldParm->getDefaultArg()) { | |||
2413 | FunctionDecl *OwningFunc = cast<FunctionDecl>(OldParm->getDeclContext()); | |||
2414 | if (OwningFunc->isInLocalScopeForInstantiation()) { | |||
2415 | // Instantiate default arguments for methods of local classes (DR1484) | |||
2416 | // and non-defining declarations. | |||
2417 | Sema::ContextRAII SavedContext(*this, OwningFunc); | |||
2418 | LocalInstantiationScope Local(*this, true); | |||
2419 | ExprResult NewArg = SubstExpr(Arg, TemplateArgs); | |||
2420 | if (NewArg.isUsable()) { | |||
2421 | // It would be nice if we still had this. | |||
2422 | SourceLocation EqualLoc = NewArg.get()->getBeginLoc(); | |||
2423 | ExprResult Result = | |||
2424 | ConvertParamDefaultArgument(NewParm, NewArg.get(), EqualLoc); | |||
2425 | if (Result.isInvalid()) | |||
2426 | return nullptr; | |||
2427 | ||||
2428 | SetParamDefaultArgument(NewParm, Result.getAs<Expr>(), EqualLoc); | |||
2429 | } | |||
2430 | } else { | |||
2431 | // FIXME: if we non-lazily instantiated non-dependent default args for | |||
2432 | // non-dependent parameter types we could remove a bunch of duplicate | |||
2433 | // conversion warnings for such arguments. | |||
2434 | NewParm->setUninstantiatedDefaultArg(Arg); | |||
2435 | } | |||
2436 | } | |||
2437 | ||||
2438 | NewParm->setHasInheritedDefaultArg(OldParm->hasInheritedDefaultArg()); | |||
2439 | ||||
2440 | if (OldParm->isParameterPack() && !NewParm->isParameterPack()) { | |||
2441 | // Add the new parameter to the instantiated parameter pack. | |||
2442 | CurrentInstantiationScope->InstantiatedLocalPackArg(OldParm, NewParm); | |||
2443 | } else { | |||
2444 | // Introduce an Old -> New mapping | |||
2445 | CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm); | |||
2446 | } | |||
2447 | ||||
2448 | // FIXME: OldParm may come from a FunctionProtoType, in which case CurContext | |||
2449 | // can be anything, is this right ? | |||
2450 | NewParm->setDeclContext(CurContext); | |||
2451 | ||||
2452 | NewParm->setScopeInfo(OldParm->getFunctionScopeDepth(), | |||
2453 | OldParm->getFunctionScopeIndex() + indexAdjustment); | |||
2454 | ||||
2455 | InstantiateAttrs(TemplateArgs, OldParm, NewParm); | |||
2456 | ||||
2457 | return NewParm; | |||
2458 | } | |||
2459 | ||||
2460 | /// Substitute the given template arguments into the given set of | |||
2461 | /// parameters, producing the set of parameter types that would be generated | |||
2462 | /// from such a substitution. | |||
2463 | bool Sema::SubstParmTypes( | |||
2464 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, | |||
2465 | const FunctionProtoType::ExtParameterInfo *ExtParamInfos, | |||
2466 | const MultiLevelTemplateArgumentList &TemplateArgs, | |||
2467 | SmallVectorImpl<QualType> &ParamTypes, | |||
2468 | SmallVectorImpl<ParmVarDecl *> *OutParams, | |||
2469 | ExtParameterInfoBuilder &ParamInfos) { | |||
2470 | assert(!CodeSynthesisContexts.empty() &&((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2472, __PRETTY_FUNCTION__)) | |||
2471 | "Cannot perform an instantiation without some context on the "((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2472, __PRETTY_FUNCTION__)) | |||
2472 | "instantiation stack")((!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? static_cast<void> (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2472, __PRETTY_FUNCTION__)); | |||
2473 | ||||
2474 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, | |||
2475 | DeclarationName()); | |||
2476 | return Instantiator.TransformFunctionTypeParams( | |||
2477 | Loc, Params, nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos); | |||
2478 | } | |||
2479 | ||||
2480 | /// Perform substitution on the base class specifiers of the | |||
2481 | /// given class template specialization. | |||
2482 | /// | |||
2483 | /// Produces a diagnostic and returns true on error, returns false and | |||
2484 | /// attaches the instantiated base classes to the class template | |||
2485 | /// specialization if successful. | |||
2486 | bool | |||
2487 | Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, | |||
2488 | CXXRecordDecl *Pattern, | |||
2489 | const MultiLevelTemplateArgumentList &TemplateArgs) { | |||
2490 | bool Invalid = false; | |||
2491 | SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases; | |||
2492 | for (const auto &Base : Pattern->bases()) { | |||
2493 | if (!Base.getType()->isDependentType()) { | |||
2494 | if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl()) { | |||
2495 | if (RD->isInvalidDecl()) | |||
2496 | Instantiation->setInvalidDecl(); | |||
2497 | } | |||
2498 | InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(Base)); | |||
2499 | continue; | |||
2500 | } | |||
2501 | ||||
2502 | SourceLocation EllipsisLoc; | |||
2503 | TypeSourceInfo *BaseTypeLoc; | |||
2504 | if (Base.isPackExpansion()) { | |||
2505 | // This is a pack expansion. See whether we should expand it now, or | |||
2506 | // wait until later. | |||
2507 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; | |||
2508 | collectUnexpandedParameterPacks(Base.getTypeSourceInfo()->getTypeLoc(), | |||
2509 | Unexpanded); | |||
2510 | bool ShouldExpand = false; | |||
2511 | bool RetainExpansion = false; | |||
2512 | Optional<unsigned> NumExpansions; | |||
2513 | if (CheckParameterPacksForExpansion(Base.getEllipsisLoc(), | |||
2514 | Base.getSourceRange(), | |||
2515 | Unexpanded, | |||
2516 | TemplateArgs, ShouldExpand, | |||
2517 | RetainExpansion, | |||
2518 | NumExpansions)) { | |||
2519 | Invalid = true; | |||
2520 | continue; | |||
2521 | } | |||
2522 | ||||
2523 | // If we should expand this pack expansion now, do so. | |||
2524 | if (ShouldExpand) { | |||
2525 | for (unsigned I = 0; I != *NumExpansions; ++I) { | |||
2526 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I); | |||
2527 | ||||
2528 | TypeSourceInfo *BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | |||
2529 | TemplateArgs, | |||
2530 | Base.getSourceRange().getBegin(), | |||
2531 | DeclarationName()); | |||
2532 | if (!BaseTypeLoc) { | |||
2533 | Invalid = true; | |||
2534 | continue; | |||
2535 | } | |||
2536 | ||||
2537 | if (CXXBaseSpecifier *InstantiatedBase | |||
2538 | = CheckBaseSpecifier(Instantiation, | |||
2539 | Base.getSourceRange(), | |||
2540 | Base.isVirtual(), | |||
2541 | Base.getAccessSpecifierAsWritten(), | |||
2542 | BaseTypeLoc, | |||
2543 | SourceLocation())) | |||
2544 | InstantiatedBases.push_back(InstantiatedBase); | |||
2545 | else | |||
2546 | Invalid = true; | |||
2547 | } | |||
2548 | ||||
2549 | continue; | |||
2550 | } | |||
2551 | ||||
2552 | // The resulting base specifier will (still) be a pack expansion. | |||
2553 | EllipsisLoc = Base.getEllipsisLoc(); | |||
2554 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1); | |||
2555 | BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | |||
2556 | TemplateArgs, | |||
2557 | Base.getSourceRange().getBegin(), | |||
2558 | DeclarationName()); | |||
2559 | } else { | |||
2560 | BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | |||
2561 | TemplateArgs, | |||
2562 | Base.getSourceRange().getBegin(), | |||
2563 | DeclarationName()); | |||
2564 | } | |||
2565 | ||||
2566 | if (!BaseTypeLoc) { | |||
2567 | Invalid = true; | |||
2568 | continue; | |||
2569 | } | |||
2570 | ||||
2571 | if (CXXBaseSpecifier *InstantiatedBase | |||
2572 | = CheckBaseSpecifier(Instantiation, | |||
2573 | Base.getSourceRange(), | |||
2574 | Base.isVirtual(), | |||
2575 | Base.getAccessSpecifierAsWritten(), | |||
2576 | BaseTypeLoc, | |||
2577 | EllipsisLoc)) | |||
2578 | InstantiatedBases.push_back(InstantiatedBase); | |||
2579 | else | |||
2580 | Invalid = true; | |||
2581 | } | |||
2582 | ||||
2583 | if (!Invalid && AttachBaseSpecifiers(Instantiation, InstantiatedBases)) | |||
2584 | Invalid = true; | |||
2585 | ||||
2586 | return Invalid; | |||
2587 | } | |||
2588 | ||||
2589 | // Defined via #include from SemaTemplateInstantiateDecl.cpp | |||
2590 | namespace clang { | |||
2591 | namespace sema { | |||
2592 | Attr *instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S, | |||
2593 | const MultiLevelTemplateArgumentList &TemplateArgs); | |||
2594 | Attr *instantiateTemplateAttributeForDecl( | |||
2595 | const Attr *At, ASTContext &C, Sema &S, | |||
2596 | const MultiLevelTemplateArgumentList &TemplateArgs); | |||
2597 | } | |||
2598 | } | |||
2599 | ||||
2600 | /// Instantiate the definition of a class from a given pattern. | |||
2601 | /// | |||
2602 | /// \param PointOfInstantiation The point of instantiation within the | |||
2603 | /// source code. | |||
2604 | /// | |||
2605 | /// \param Instantiation is the declaration whose definition is being | |||
2606 | /// instantiated. This will be either a class template specialization | |||
2607 | /// or a member class of a class template specialization. | |||
2608 | /// | |||
2609 | /// \param Pattern is the pattern from which the instantiation | |||
2610 | /// occurs. This will be either the declaration of a class template or | |||
2611 | /// the declaration of a member class of a class template. | |||
2612 | /// | |||
2613 | /// \param TemplateArgs The template arguments to be substituted into | |||
2614 | /// the pattern. | |||
2615 | /// | |||
2616 | /// \param TSK the kind of implicit or explicit instantiation to perform. | |||
2617 | /// | |||
2618 | /// \param Complain whether to complain if the class cannot be instantiated due | |||
2619 | /// to the lack of a definition. | |||
2620 | /// | |||
2621 | /// \returns true if an error occurred, false otherwise. | |||
2622 | bool | |||
2623 | Sema::InstantiateClass(SourceLocation PointOfInstantiation, | |||
2624 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, | |||
2625 | const MultiLevelTemplateArgumentList &TemplateArgs, | |||
2626 | TemplateSpecializationKind TSK, | |||
2627 | bool Complain) { | |||
2628 | CXXRecordDecl *PatternDef | |||
2629 | = cast_or_null<CXXRecordDecl>(Pattern->getDefinition()); | |||
2630 | if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation, | |||
2631 | Instantiation->getInstantiatedFromMemberClass(), | |||
2632 | Pattern, PatternDef, TSK, Complain)) | |||
2633 | return true; | |||
2634 | ||||
2635 | llvm::TimeTraceScope TimeScope("InstantiateClass", [&]() { | |||
2636 | std::string Name; | |||
2637 | llvm::raw_string_ostream OS(Name); | |||
2638 | Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(), | |||
2639 | /*Qualified=*/true); | |||
2640 | return Name; | |||
2641 | }); | |||
2642 | ||||
2643 | Pattern = PatternDef; | |||
2644 | ||||
2645 | // Record the point of instantiation. | |||
2646 | if (MemberSpecializationInfo *MSInfo | |||
2647 | = Instantiation->getMemberSpecializationInfo()) { | |||
2648 | MSInfo->setTemplateSpecializationKind(TSK); | |||
2649 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | |||
2650 | } else if (ClassTemplateSpecializationDecl *Spec | |||
2651 | = dyn_cast<ClassTemplateSpecializationDecl>(Instantiation)) { | |||
2652 | Spec->setTemplateSpecializationKind(TSK); | |||
2653 | Spec->setPointOfInstantiation(PointOfInstantiation); | |||
2654 | } | |||
2655 | ||||
2656 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); | |||
2657 | if (Inst.isInvalid()) | |||
2658 | return true; | |||
2659 | assert(!Inst.isAlreadyInstantiating() && "should have been caught by caller")((!Inst.isAlreadyInstantiating() && "should have been caught by caller" ) ? static_cast<void> (0) : __assert_fail ("!Inst.isAlreadyInstantiating() && \"should have been caught by caller\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2659, __PRETTY_FUNCTION__)); | |||
2660 | PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(), | |||
2661 | "instantiating class definition"); | |||
2662 | ||||
2663 | // Enter the scope of this instantiation. We don't use | |||
2664 | // PushDeclContext because we don't have a scope. | |||
2665 | ContextRAII SavedContext(*this, Instantiation); | |||
2666 | EnterExpressionEvaluationContext EvalContext( | |||
2667 | *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); | |||
2668 | ||||
2669 | // If this is an instantiation of a local class, merge this local | |||
2670 | // instantiation scope with the enclosing scope. Otherwise, every | |||
2671 | // instantiation of a class has its own local instantiation scope. | |||
2672 | bool MergeWithParentScope = !Instantiation->isDefinedOutsideFunctionOrMethod(); | |||
2673 | LocalInstantiationScope Scope(*this, MergeWithParentScope); | |||
2674 | ||||
2675 | // Some class state isn't processed immediately but delayed till class | |||
2676 | // instantiation completes. We may not be ready to handle any delayed state | |||
2677 | // already on the stack as it might correspond to a different class, so save | |||
2678 | // it now and put it back later. | |||
2679 | SavePendingParsedClassStateRAII SavedPendingParsedClassState(*this); | |||
2680 | ||||
2681 | // Pull attributes from the pattern onto the instantiation. | |||
2682 | InstantiateAttrs(TemplateArgs, Pattern, Instantiation); | |||
2683 | ||||
2684 | // Start the definition of this instantiation. | |||
2685 | Instantiation->startDefinition(); | |||
2686 | ||||
2687 | // The instantiation is visible here, even if it was first declared in an | |||
2688 | // unimported module. | |||
2689 | Instantiation->setVisibleDespiteOwningModule(); | |||
2690 | ||||
2691 | // FIXME: This loses the as-written tag kind for an explicit instantiation. | |||
2692 | Instantiation->setTagKind(Pattern->getTagKind()); | |||
2693 | ||||
2694 | // Do substitution on the base class specifiers. | |||
2695 | if (SubstBaseSpecifiers(Instantiation, Pattern, TemplateArgs)) | |||
2696 | Instantiation->setInvalidDecl(); | |||
2697 | ||||
2698 | TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs); | |||
2699 | SmallVector<Decl*, 4> Fields; | |||
2700 | // Delay instantiation of late parsed attributes. | |||
2701 | LateInstantiatedAttrVec LateAttrs; | |||
2702 | Instantiator.enableLateAttributeInstantiation(&LateAttrs); | |||
2703 | ||||
2704 | bool MightHaveConstexprVirtualFunctions = false; | |||
2705 | for (auto *Member : Pattern->decls()) { | |||
2706 | // Don't instantiate members not belonging in this semantic context. | |||
2707 | // e.g. for: | |||
2708 | // @code | |||
2709 | // template <int i> class A { | |||
2710 | // class B *g; | |||
2711 | // }; | |||
2712 | // @endcode | |||
2713 | // 'class B' has the template as lexical context but semantically it is | |||
2714 | // introduced in namespace scope. | |||
2715 | if (Member->getDeclContext() != Pattern) | |||
2716 | continue; | |||
2717 | ||||
2718 | // BlockDecls can appear in a default-member-initializer. They must be the | |||
2719 | // child of a BlockExpr, so we only know how to instantiate them from there. | |||
2720 | // Similarly, lambda closure types are recreated when instantiating the | |||
2721 | // corresponding LambdaExpr. | |||
2722 | if (isa<BlockDecl>(Member) || | |||
2723 | (isa<CXXRecordDecl>(Member) && cast<CXXRecordDecl>(Member)->isLambda())) | |||
2724 | continue; | |||
2725 | ||||
2726 | if (Member->isInvalidDecl()) { | |||
2727 | Instantiation->setInvalidDecl(); | |||
2728 | continue; | |||
2729 | } | |||
2730 | ||||
2731 | Decl *NewMember = Instantiator.Visit(Member); | |||
2732 | if (NewMember) { | |||
2733 | if (FieldDecl *Field = dyn_cast<FieldDecl>(NewMember)) { | |||
2734 | Fields.push_back(Field); | |||
2735 | } else if (EnumDecl *Enum = dyn_cast<EnumDecl>(NewMember)) { | |||
2736 | // C++11 [temp.inst]p1: The implicit instantiation of a class template | |||
2737 | // specialization causes the implicit instantiation of the definitions | |||
2738 | // of unscoped member enumerations. | |||
2739 | // Record a point of instantiation for this implicit instantiation. | |||
2740 | if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() && | |||
2741 | Enum->isCompleteDefinition()) { | |||
2742 | MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo(); | |||
2743 | assert(MSInfo && "no spec info for member enum specialization")((MSInfo && "no spec info for member enum specialization" ) ? static_cast<void> (0) : __assert_fail ("MSInfo && \"no spec info for member enum specialization\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2743, __PRETTY_FUNCTION__)); | |||
2744 | MSInfo->setTemplateSpecializationKind(TSK_ImplicitInstantiation); | |||
2745 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | |||
2746 | } | |||
2747 | } else if (StaticAssertDecl *SA = dyn_cast<StaticAssertDecl>(NewMember)) { | |||
2748 | if (SA->isFailed()) { | |||
2749 | // A static_assert failed. Bail out; instantiating this | |||
2750 | // class is probably not meaningful. | |||
2751 | Instantiation->setInvalidDecl(); | |||
2752 | break; | |||
2753 | } | |||
2754 | } else if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewMember)) { | |||
2755 | if (MD->isConstexpr() && !MD->getFriendObjectKind() && | |||
2756 | (MD->isVirtualAsWritten() || Instantiation->getNumBases())) | |||
2757 | MightHaveConstexprVirtualFunctions = true; | |||
2758 | } | |||
2759 | ||||
2760 | if (NewMember->isInvalidDecl()) | |||
2761 | Instantiation->setInvalidDecl(); | |||
2762 | } else { | |||
2763 | // FIXME: Eventually, a NULL return will mean that one of the | |||
2764 | // instantiations was a semantic disaster, and we'll want to mark the | |||
2765 | // declaration invalid. | |||
2766 | // For now, we expect to skip some members that we can't yet handle. | |||
2767 | } | |||
2768 | } | |||
2769 | ||||
2770 | // Finish checking fields. | |||
2771 | ActOnFields(nullptr, Instantiation->getLocation(), Instantiation, Fields, | |||
2772 | SourceLocation(), SourceLocation(), ParsedAttributesView()); | |||
2773 | CheckCompletedCXXClass(nullptr, Instantiation); | |||
2774 | ||||
2775 | // Default arguments are parsed, if not instantiated. We can go instantiate | |||
2776 | // default arg exprs for default constructors if necessary now. Unless we're | |||
2777 | // parsing a class, in which case wait until that's finished. | |||
2778 | if (ParsingClassDepth == 0) | |||
2779 | ActOnFinishCXXNonNestedClass(); | |||
2780 | ||||
2781 | // Instantiate late parsed attributes, and attach them to their decls. | |||
2782 | // See Sema::InstantiateAttrs | |||
2783 | for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(), | |||
2784 | E = LateAttrs.end(); I != E; ++I) { | |||
2785 | assert(CurrentInstantiationScope == Instantiator.getStartingScope())((CurrentInstantiationScope == Instantiator.getStartingScope( )) ? static_cast<void> (0) : __assert_fail ("CurrentInstantiationScope == Instantiator.getStartingScope()" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2785, __PRETTY_FUNCTION__)); | |||
2786 | CurrentInstantiationScope = I->Scope; | |||
2787 | ||||
2788 | // Allow 'this' within late-parsed attributes. | |||
2789 | NamedDecl *ND = dyn_cast<NamedDecl>(I->NewDecl); | |||
2790 | CXXRecordDecl *ThisContext = | |||
2791 | dyn_cast_or_null<CXXRecordDecl>(ND->getDeclContext()); | |||
2792 | CXXThisScopeRAII ThisScope(*this, ThisContext, Qualifiers(), | |||
2793 | ND && ND->isCXXInstanceMember()); | |||
2794 | ||||
2795 | Attr *NewAttr = | |||
2796 | instantiateTemplateAttribute(I->TmplAttr, Context, *this, TemplateArgs); | |||
2797 | I->NewDecl->addAttr(NewAttr); | |||
2798 | LocalInstantiationScope::deleteScopes(I->Scope, | |||
2799 | Instantiator.getStartingScope()); | |||
2800 | } | |||
2801 | Instantiator.disableLateAttributeInstantiation(); | |||
2802 | LateAttrs.clear(); | |||
2803 | ||||
2804 | ActOnFinishDelayedMemberInitializers(Instantiation); | |||
2805 | ||||
2806 | // FIXME: We should do something similar for explicit instantiations so they | |||
2807 | // end up in the right module. | |||
2808 | if (TSK == TSK_ImplicitInstantiation) { | |||
2809 | Instantiation->setLocation(Pattern->getLocation()); | |||
2810 | Instantiation->setLocStart(Pattern->getInnerLocStart()); | |||
2811 | Instantiation->setBraceRange(Pattern->getBraceRange()); | |||
2812 | } | |||
2813 | ||||
2814 | if (!Instantiation->isInvalidDecl()) { | |||
2815 | // Perform any dependent diagnostics from the pattern. | |||
2816 | PerformDependentDiagnostics(Pattern, TemplateArgs); | |||
2817 | ||||
2818 | // Instantiate any out-of-line class template partial | |||
2819 | // specializations now. | |||
2820 | for (TemplateDeclInstantiator::delayed_partial_spec_iterator | |||
2821 | P = Instantiator.delayed_partial_spec_begin(), | |||
2822 | PEnd = Instantiator.delayed_partial_spec_end(); | |||
2823 | P != PEnd; ++P) { | |||
2824 | if (!Instantiator.InstantiateClassTemplatePartialSpecialization( | |||
2825 | P->first, P->second)) { | |||
2826 | Instantiation->setInvalidDecl(); | |||
2827 | break; | |||
2828 | } | |||
2829 | } | |||
2830 | ||||
2831 | // Instantiate any out-of-line variable template partial | |||
2832 | // specializations now. | |||
2833 | for (TemplateDeclInstantiator::delayed_var_partial_spec_iterator | |||
2834 | P = Instantiator.delayed_var_partial_spec_begin(), | |||
2835 | PEnd = Instantiator.delayed_var_partial_spec_end(); | |||
2836 | P != PEnd; ++P) { | |||
2837 | if (!Instantiator.InstantiateVarTemplatePartialSpecialization( | |||
2838 | P->first, P->second)) { | |||
2839 | Instantiation->setInvalidDecl(); | |||
2840 | break; | |||
2841 | } | |||
2842 | } | |||
2843 | } | |||
2844 | ||||
2845 | // Exit the scope of this instantiation. | |||
2846 | SavedContext.pop(); | |||
2847 | ||||
2848 | if (!Instantiation->isInvalidDecl()) { | |||
2849 | // Always emit the vtable for an explicit instantiation definition | |||
2850 | // of a polymorphic class template specialization. Otherwise, eagerly | |||
2851 | // instantiate only constexpr virtual functions in preparation for their use | |||
2852 | // in constant evaluation. | |||
2853 | if (TSK == TSK_ExplicitInstantiationDefinition) | |||
2854 | MarkVTableUsed(PointOfInstantiation, Instantiation, true); | |||
2855 | else if (MightHaveConstexprVirtualFunctions) | |||
2856 | MarkVirtualMembersReferenced(PointOfInstantiation, Instantiation, | |||
2857 | /*ConstexprOnly*/ true); | |||
2858 | } | |||
2859 | ||||
2860 | Consumer.HandleTagDeclDefinition(Instantiation); | |||
2861 | ||||
2862 | return Instantiation->isInvalidDecl(); | |||
2863 | } | |||
2864 | ||||
2865 | /// Instantiate the definition of an enum from a given pattern. | |||
2866 | /// | |||
2867 | /// \param PointOfInstantiation The point of instantiation within the | |||
2868 | /// source code. | |||
2869 | /// \param Instantiation is the declaration whose definition is being | |||
2870 | /// instantiated. This will be a member enumeration of a class | |||
2871 | /// temploid specialization, or a local enumeration within a | |||
2872 | /// function temploid specialization. | |||
2873 | /// \param Pattern The templated declaration from which the instantiation | |||
2874 | /// occurs. | |||
2875 | /// \param TemplateArgs The template arguments to be substituted into | |||
2876 | /// the pattern. | |||
2877 | /// \param TSK The kind of implicit or explicit instantiation to perform. | |||
2878 | /// | |||
2879 | /// \return \c true if an error occurred, \c false otherwise. | |||
2880 | bool Sema::InstantiateEnum(SourceLocation PointOfInstantiation, | |||
2881 | EnumDecl *Instantiation, EnumDecl *Pattern, | |||
2882 | const MultiLevelTemplateArgumentList &TemplateArgs, | |||
2883 | TemplateSpecializationKind TSK) { | |||
2884 | EnumDecl *PatternDef = Pattern->getDefinition(); | |||
2885 | if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation, | |||
2886 | Instantiation->getInstantiatedFromMemberEnum(), | |||
2887 | Pattern, PatternDef, TSK,/*Complain*/true)) | |||
2888 | return true; | |||
2889 | Pattern = PatternDef; | |||
2890 | ||||
2891 | // Record the point of instantiation. | |||
2892 | if (MemberSpecializationInfo *MSInfo | |||
2893 | = Instantiation->getMemberSpecializationInfo()) { | |||
2894 | MSInfo->setTemplateSpecializationKind(TSK); | |||
2895 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | |||
2896 | } | |||
2897 | ||||
2898 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); | |||
2899 | if (Inst.isInvalid()) | |||
2900 | return true; | |||
2901 | if (Inst.isAlreadyInstantiating()) | |||
2902 | return false; | |||
2903 | PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(), | |||
2904 | "instantiating enum definition"); | |||
2905 | ||||
2906 | // The instantiation is visible here, even if it was first declared in an | |||
2907 | // unimported module. | |||
2908 | Instantiation->setVisibleDespiteOwningModule(); | |||
2909 | ||||
2910 | // Enter the scope of this instantiation. We don't use | |||
2911 | // PushDeclContext because we don't have a scope. | |||
2912 | ContextRAII SavedContext(*this, Instantiation); | |||
2913 | EnterExpressionEvaluationContext EvalContext( | |||
2914 | *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); | |||
2915 | ||||
2916 | LocalInstantiationScope Scope(*this, /*MergeWithParentScope*/true); | |||
2917 | ||||
2918 | // Pull attributes from the pattern onto the instantiation. | |||
2919 | InstantiateAttrs(TemplateArgs, Pattern, Instantiation); | |||
2920 | ||||
2921 | TemplateDeclInstantiator Instantiator(*this, Instantiation, TemplateArgs); | |||
2922 | Instantiator.InstantiateEnumDefinition(Instantiation, Pattern); | |||
2923 | ||||
2924 | // Exit the scope of this instantiation. | |||
2925 | SavedContext.pop(); | |||
2926 | ||||
2927 | return Instantiation->isInvalidDecl(); | |||
2928 | } | |||
2929 | ||||
2930 | ||||
2931 | /// Instantiate the definition of a field from the given pattern. | |||
2932 | /// | |||
2933 | /// \param PointOfInstantiation The point of instantiation within the | |||
2934 | /// source code. | |||
2935 | /// \param Instantiation is the declaration whose definition is being | |||
2936 | /// instantiated. This will be a class of a class temploid | |||
2937 | /// specialization, or a local enumeration within a function temploid | |||
2938 | /// specialization. | |||
2939 | /// \param Pattern The templated declaration from which the instantiation | |||
2940 | /// occurs. | |||
2941 | /// \param TemplateArgs The template arguments to be substituted into | |||
2942 | /// the pattern. | |||
2943 | /// | |||
2944 | /// \return \c true if an error occurred, \c false otherwise. | |||
2945 | bool Sema::InstantiateInClassInitializer( | |||
2946 | SourceLocation PointOfInstantiation, FieldDecl *Instantiation, | |||
2947 | FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs) { | |||
2948 | // If there is no initializer, we don't need to do anything. | |||
2949 | if (!Pattern->hasInClassInitializer()) | |||
2950 | return false; | |||
2951 | ||||
2952 | assert(Instantiation->getInClassInitStyle() ==((Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle () && "pattern and instantiation disagree about init style" ) ? static_cast<void> (0) : __assert_fail ("Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle() && \"pattern and instantiation disagree about init style\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2954, __PRETTY_FUNCTION__)) | |||
2953 | Pattern->getInClassInitStyle() &&((Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle () && "pattern and instantiation disagree about init style" ) ? static_cast<void> (0) : __assert_fail ("Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle() && \"pattern and instantiation disagree about init style\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2954, __PRETTY_FUNCTION__)) | |||
2954 | "pattern and instantiation disagree about init style")((Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle () && "pattern and instantiation disagree about init style" ) ? static_cast<void> (0) : __assert_fail ("Instantiation->getInClassInitStyle() == Pattern->getInClassInitStyle() && \"pattern and instantiation disagree about init style\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2954, __PRETTY_FUNCTION__)); | |||
2955 | ||||
2956 | // Error out if we haven't parsed the initializer of the pattern yet because | |||
2957 | // we are waiting for the closing brace of the outer class. | |||
2958 | Expr *OldInit = Pattern->getInClassInitializer(); | |||
2959 | if (!OldInit) { | |||
2960 | RecordDecl *PatternRD = Pattern->getParent(); | |||
2961 | RecordDecl *OutermostClass = PatternRD->getOuterLexicalRecordContext(); | |||
2962 | Diag(PointOfInstantiation, | |||
2963 | diag::err_default_member_initializer_not_yet_parsed) | |||
2964 | << OutermostClass << Pattern; | |||
2965 | Diag(Pattern->getEndLoc(), | |||
2966 | diag::note_default_member_initializer_not_yet_parsed); | |||
2967 | Instantiation->setInvalidDecl(); | |||
2968 | return true; | |||
2969 | } | |||
2970 | ||||
2971 | InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); | |||
2972 | if (Inst.isInvalid()) | |||
2973 | return true; | |||
2974 | if (Inst.isAlreadyInstantiating()) { | |||
2975 | // Error out if we hit an instantiation cycle for this initializer. | |||
2976 | Diag(PointOfInstantiation, diag::err_default_member_initializer_cycle) | |||
2977 | << Instantiation; | |||
2978 | return true; | |||
2979 | } | |||
2980 | PrettyDeclStackTraceEntry CrashInfo(Context, Instantiation, SourceLocation(), | |||
2981 | "instantiating default member init"); | |||
2982 | ||||
2983 | // Enter the scope of this instantiation. We don't use PushDeclContext because | |||
2984 | // we don't have a scope. | |||
2985 | ContextRAII SavedContext(*this, Instantiation->getParent()); | |||
2986 | EnterExpressionEvaluationContext EvalContext( | |||
2987 | *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); | |||
2988 | ||||
2989 | LocalInstantiationScope Scope(*this, true); | |||
2990 | ||||
2991 | // Instantiate the initializer. | |||
2992 | ActOnStartCXXInClassMemberInitializer(); | |||
2993 | CXXThisScopeRAII ThisScope(*this, Instantiation->getParent(), Qualifiers()); | |||
2994 | ||||
2995 | ExprResult NewInit = SubstInitializer(OldInit, TemplateArgs, | |||
2996 | /*CXXDirectInit=*/false); | |||
2997 | Expr *Init = NewInit.get(); | |||
2998 | assert((!Init || !isa<ParenListExpr>(Init)) && "call-style init in class")(((!Init || !isa<ParenListExpr>(Init)) && "call-style init in class" ) ? static_cast<void> (0) : __assert_fail ("(!Init || !isa<ParenListExpr>(Init)) && \"call-style init in class\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2998, __PRETTY_FUNCTION__)); | |||
2999 | ActOnFinishCXXInClassMemberInitializer( | |||
3000 | Instantiation, Init ? Init->getBeginLoc() : SourceLocation(), Init); | |||
3001 | ||||
3002 | if (auto *L = getASTMutationListener()) | |||
3003 | L->DefaultMemberInitializerInstantiated(Instantiation); | |||
3004 | ||||
3005 | // Return true if the in-class initializer is still missing. | |||
3006 | return !Instantiation->getInClassInitializer(); | |||
3007 | } | |||
3008 | ||||
3009 | namespace { | |||
3010 | /// A partial specialization whose template arguments have matched | |||
3011 | /// a given template-id. | |||
3012 | struct PartialSpecMatchResult { | |||
3013 | ClassTemplatePartialSpecializationDecl *Partial; | |||
3014 | TemplateArgumentList *Args; | |||
3015 | }; | |||
3016 | } | |||
3017 | ||||
3018 | bool Sema::usesPartialOrExplicitSpecialization( | |||
3019 | SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec) { | |||
3020 | if (ClassTemplateSpec->getTemplateSpecializationKind() == | |||
3021 | TSK_ExplicitSpecialization) | |||
3022 | return true; | |||
3023 | ||||
3024 | SmallVector<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs; | |||
3025 | ClassTemplateSpec->getSpecializedTemplate() | |||
3026 | ->getPartialSpecializations(PartialSpecs); | |||
3027 | for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) { | |||
3028 | TemplateDeductionInfo Info(Loc); | |||
3029 | if (!DeduceTemplateArguments(PartialSpecs[I], | |||
3030 | ClassTemplateSpec->getTemplateArgs(), Info)) | |||
3031 | return true; | |||
3032 | } | |||
3033 | ||||
3034 | return false; | |||
3035 | } | |||
3036 | ||||
3037 | /// Get the instantiation pattern to use to instantiate the definition of a | |||
3038 | /// given ClassTemplateSpecializationDecl (either the pattern of the primary | |||
3039 | /// template or of a partial specialization). | |||
3040 | static ActionResult<CXXRecordDecl *> | |||
3041 | getPatternForClassTemplateSpecialization( | |||
3042 | Sema &S, SourceLocation PointOfInstantiation, | |||
3043 | ClassTemplateSpecializationDecl *ClassTemplateSpec, | |||
3044 | TemplateSpecializationKind TSK) { | |||
3045 | Sema::InstantiatingTemplate Inst(S, PointOfInstantiation, ClassTemplateSpec); | |||
3046 | if (Inst.isInvalid()) | |||
3047 | return {/*Invalid=*/true}; | |||
3048 | if (Inst.isAlreadyInstantiating()) | |||
3049 | return {/*Invalid=*/false}; | |||
3050 | ||||
3051 | llvm::PointerUnion<ClassTemplateDecl *, | |||
3052 | ClassTemplatePartialSpecializationDecl *> | |||
3053 | Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial(); | |||
3054 | if (!Specialized.is<ClassTemplatePartialSpecializationDecl *>()) { | |||
3055 | // Find best matching specialization. | |||
3056 | ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); | |||
3057 | ||||
3058 | // C++ [temp.class.spec.match]p1: | |||
3059 | // When a class template is used in a context that requires an | |||
3060 | // instantiation of the class, it is necessary to determine | |||
3061 | // whether the instantiation is to be generated using the primary | |||
3062 | // template or one of the partial specializations. This is done by | |||
3063 | // matching the template arguments of the class template | |||
3064 | // specialization with the template argument lists of the partial | |||
3065 | // specializations. | |||
3066 | typedef PartialSpecMatchResult MatchResult; | |||
3067 | SmallVector<MatchResult, 4> Matched; | |||
3068 | SmallVector<ClassTemplatePartialSpecializationDecl *, 4> PartialSpecs; | |||
3069 | Template->getPartialSpecializations(PartialSpecs); | |||
3070 | TemplateSpecCandidateSet FailedCandidates(PointOfInstantiation); | |||
3071 | for (unsigned I = 0, N = PartialSpecs.size(); I != N; ++I) { | |||
3072 | ClassTemplatePartialSpecializationDecl *Partial = PartialSpecs[I]; | |||
3073 | TemplateDeductionInfo Info(FailedCandidates.getLocation()); | |||
3074 | if (Sema::TemplateDeductionResult Result = S.DeduceTemplateArguments( | |||
3075 | Partial, ClassTemplateSpec->getTemplateArgs(), Info)) { | |||
3076 | // Store the failed-deduction information for use in diagnostics, later. | |||
3077 | // TODO: Actually use the failed-deduction info? | |||
3078 | FailedCandidates.addCandidate().set( | |||
3079 | DeclAccessPair::make(Template, AS_public), Partial, | |||
3080 | MakeDeductionFailureInfo(S.Context, Result, Info)); | |||
3081 | (void)Result; | |||
3082 | } else { | |||
3083 | Matched.push_back(PartialSpecMatchResult()); | |||
3084 | Matched.back().Partial = Partial; | |||
3085 | Matched.back().Args = Info.take(); | |||
3086 | } | |||
3087 | } | |||
3088 | ||||
3089 | // If we're dealing with a member template where the template parameters | |||
3090 | // have been instantiated, this provides the original template parameters | |||
3091 | // from which the member template's parameters were instantiated. | |||
3092 | ||||
3093 | if (Matched.size() >= 1) { | |||
3094 | SmallVectorImpl<MatchResult>::iterator Best = Matched.begin(); | |||
3095 | if (Matched.size() == 1) { | |||
3096 | // -- If exactly one matching specialization is found, the | |||
3097 | // instantiation is generated from that specialization. | |||
3098 | // We don't need to do anything for this. | |||
3099 | } else { | |||
3100 | // -- If more than one matching specialization is found, the | |||
3101 | // partial order rules (14.5.4.2) are used to determine | |||
3102 | // whether one of the specializations is more specialized | |||
3103 | // than the others. If none of the specializations is more | |||
3104 | // specialized than all of the other matching | |||
3105 | // specializations, then the use of the class template is | |||
3106 | // ambiguous and the program is ill-formed. | |||
3107 | for (SmallVectorImpl<MatchResult>::iterator P = Best + 1, | |||
3108 | PEnd = Matched.end(); | |||
3109 | P != PEnd; ++P) { | |||
3110 | if (S.getMoreSpecializedPartialSpecialization( | |||
3111 | P->Partial, Best->Partial, PointOfInstantiation) == | |||
3112 | P->Partial) | |||
3113 | Best = P; | |||
3114 | } | |||
3115 | ||||
3116 | // Determine if the best partial specialization is more specialized than | |||
3117 | // the others. | |||
3118 | bool Ambiguous = false; | |||
3119 | for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(), | |||
3120 | PEnd = Matched.end(); | |||
3121 | P != PEnd; ++P) { | |||
3122 | if (P != Best && S.getMoreSpecializedPartialSpecialization( | |||
3123 | P->Partial, Best->Partial, | |||
3124 | PointOfInstantiation) != Best->Partial) { | |||
3125 | Ambiguous = true; | |||
3126 | break; | |||
3127 | } | |||
3128 | } | |||
3129 | ||||
3130 | if (Ambiguous) { | |||
3131 | // Partial ordering did not produce a clear winner. Complain. | |||
3132 | Inst.Clear(); | |||
3133 | ClassTemplateSpec->setInvalidDecl(); | |||
3134 | S.Diag(PointOfInstantiation, | |||
3135 | diag::err_partial_spec_ordering_ambiguous) | |||
3136 | << ClassTemplateSpec; | |||
3137 | ||||
3138 | // Print the matching partial specializations. | |||
3139 | for (SmallVectorImpl<MatchResult>::iterator P = Matched.begin(), | |||
3140 | PEnd = Matched.end(); | |||
3141 | P != PEnd; ++P) | |||
3142 | S.Diag(P->Partial->getLocation(), diag::note_partial_spec_match) | |||
3143 | << S.getTemplateArgumentBindingsText( | |||
3144 | P->Partial->getTemplateParameters(), *P->Args); | |||
3145 | ||||
3146 | return {/*Invalid=*/true}; | |||
3147 | } | |||
3148 | } | |||
3149 | ||||
3150 | ClassTemplateSpec->setInstantiationOf(Best->Partial, Best->Args); | |||
3151 | } else { | |||
3152 | // -- If no matches are found, the instantiation is generated | |||
3153 | // from the primary template. | |||
3154 | } | |||
3155 | } | |||
3156 | ||||
3157 | CXXRecordDecl *Pattern = nullptr; | |||
3158 | Specialized = ClassTemplateSpec->getSpecializedTemplateOrPartial(); | |||
3159 | if (auto *PartialSpec = | |||
3160 | Specialized.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) { | |||
3161 | // Instantiate using the best class template partial specialization. | |||
3162 | while (PartialSpec->getInstantiatedFromMember()) { | |||
3163 | // If we've found an explicit specialization of this class template, | |||
3164 | // stop here and use that as the pattern. | |||
3165 | if (PartialSpec->isMemberSpecialization()) | |||
3166 | break; | |||
3167 | ||||
3168 | PartialSpec = PartialSpec->getInstantiatedFromMember(); | |||
3169 | } | |||
3170 | Pattern = PartialSpec; | |||
3171 | } else { | |||
3172 | ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); | |||
3173 | while (Template->getInstantiatedFromMemberTemplate()) { | |||
3174 | // If we've found an explicit specialization of this class template, | |||
3175 | // stop here and use that as the pattern. | |||
3176 | if (Template->isMemberSpecialization()) | |||
3177 | break; | |||
3178 | ||||
3179 | Template = Template->getInstantiatedFromMemberTemplate(); | |||
3180 | } | |||
3181 | Pattern = Template->getTemplatedDecl(); | |||
3182 | } | |||
3183 | ||||
3184 | return Pattern; | |||
3185 | } | |||
3186 | ||||
3187 | bool Sema::InstantiateClassTemplateSpecialization( | |||
3188 | SourceLocation PointOfInstantiation, | |||
3189 | ClassTemplateSpecializationDecl *ClassTemplateSpec, | |||
3190 | TemplateSpecializationKind TSK, bool Complain) { | |||
3191 | // Perform the actual instantiation on the canonical declaration. | |||
3192 | ClassTemplateSpec = cast<ClassTemplateSpecializationDecl>( | |||
3193 | ClassTemplateSpec->getCanonicalDecl()); | |||
3194 | if (ClassTemplateSpec->isInvalidDecl()) | |||
3195 | return true; | |||
3196 | ||||
3197 | ActionResult<CXXRecordDecl *> Pattern = | |||
3198 | getPatternForClassTemplateSpecialization(*this, PointOfInstantiation, | |||
3199 | ClassTemplateSpec, TSK); | |||
3200 | if (!Pattern.isUsable()) | |||
3201 | return Pattern.isInvalid(); | |||
3202 | ||||
3203 | return InstantiateClass( | |||
3204 | PointOfInstantiation, ClassTemplateSpec, Pattern.get(), | |||
3205 | getTemplateInstantiationArgs(ClassTemplateSpec), TSK, Complain); | |||
3206 | } | |||
3207 | ||||
3208 | /// Instantiates the definitions of all of the member | |||
3209 | /// of the given class, which is an instantiation of a class template | |||
3210 | /// or a member class of a template. | |||
3211 | void | |||
3212 | Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, | |||
3213 | CXXRecordDecl *Instantiation, | |||
3214 | const MultiLevelTemplateArgumentList &TemplateArgs, | |||
3215 | TemplateSpecializationKind TSK) { | |||
3216 | // FIXME: We need to notify the ASTMutationListener that we did all of these | |||
3217 | // things, in case we have an explicit instantiation definition in a PCM, a | |||
3218 | // module, or preamble, and the declaration is in an imported AST. | |||
3219 | assert((((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation ->isLocalClass())) && "Unexpected template specialization kind!" ) ? static_cast<void> (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3223, __PRETTY_FUNCTION__)) | |||
3220 | (TSK == TSK_ExplicitInstantiationDefinition ||(((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation ->isLocalClass())) && "Unexpected template specialization kind!" ) ? static_cast<void> (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3223, __PRETTY_FUNCTION__)) | |||
3221 | TSK == TSK_ExplicitInstantiationDeclaration ||(((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation ->isLocalClass())) && "Unexpected template specialization kind!" ) ? static_cast<void> (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3223, __PRETTY_FUNCTION__)) | |||
3222 | (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) &&(((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation ->isLocalClass())) && "Unexpected template specialization kind!" ) ? static_cast<void> (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3223, __PRETTY_FUNCTION__)) | |||
3223 | "Unexpected template specialization kind!")(((TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation ->isLocalClass())) && "Unexpected template specialization kind!" ) ? static_cast<void> (0) : __assert_fail ("(TSK == TSK_ExplicitInstantiationDefinition || TSK == TSK_ExplicitInstantiationDeclaration || (TSK == TSK_ImplicitInstantiation && Instantiation->isLocalClass())) && \"Unexpected template specialization kind!\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3223, __PRETTY_FUNCTION__)); | |||
3224 | for (auto *D : Instantiation->decls()) { | |||
3225 | bool SuppressNew = false; | |||
3226 | if (auto *Function = dyn_cast<FunctionDecl>(D)) { | |||
3227 | if (FunctionDecl *Pattern = | |||
3228 | Function->getInstantiatedFromMemberFunction()) { | |||
3229 | ||||
3230 | if (Function->hasAttr<ExcludeFromExplicitInstantiationAttr>()) | |||
3231 | continue; | |||
3232 | ||||
3233 | MemberSpecializationInfo *MSInfo = | |||
3234 | Function->getMemberSpecializationInfo(); | |||
3235 | assert(MSInfo && "No member specialization information?")((MSInfo && "No member specialization information?") ? static_cast<void> (0) : __assert_fail ("MSInfo && \"No member specialization information?\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3235, __PRETTY_FUNCTION__)); | |||
3236 | if (MSInfo->getTemplateSpecializationKind() | |||
3237 | == TSK_ExplicitSpecialization) | |||
3238 | continue; | |||
3239 | ||||
3240 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, | |||
3241 | Function, | |||
3242 | MSInfo->getTemplateSpecializationKind(), | |||
3243 | MSInfo->getPointOfInstantiation(), | |||
3244 | SuppressNew) || | |||
3245 | SuppressNew) | |||
3246 | continue; | |||
3247 | ||||
3248 | // C++11 [temp.explicit]p8: | |||
3249 | // An explicit instantiation definition that names a class template | |||
3250 | // specialization explicitly instantiates the class template | |||
3251 | // specialization and is only an explicit instantiation definition | |||
3252 | // of members whose definition is visible at the point of | |||
3253 | // instantiation. | |||
3254 | if (TSK == TSK_ExplicitInstantiationDefinition && !Pattern->isDefined()) | |||
3255 | continue; | |||
3256 | ||||
3257 | Function->setTemplateSpecializationKind(TSK, PointOfInstantiation); | |||
3258 | ||||
3259 | if (Function->isDefined()) { | |||
3260 | // Let the ASTConsumer know that this function has been explicitly | |||
3261 | // instantiated now, and its linkage might have changed. | |||
3262 | Consumer.HandleTopLevelDecl(DeclGroupRef(Function)); | |||
3263 | } else if (TSK == TSK_ExplicitInstantiationDefinition) { | |||
3264 | InstantiateFunctionDefinition(PointOfInstantiation, Function); | |||
3265 | } else if (TSK == TSK_ImplicitInstantiation) { | |||
3266 | PendingLocalImplicitInstantiations.push_back( | |||
3267 | std::make_pair(Function, PointOfInstantiation)); | |||
3268 | } | |||
3269 | } | |||
3270 | } else if (auto *Var = dyn_cast<VarDecl>(D)) { | |||
3271 | if (isa<VarTemplateSpecializationDecl>(Var)) | |||
3272 | continue; | |||
3273 | ||||
3274 | if (Var->isStaticDataMember()) { | |||
3275 | if (Var->hasAttr<ExcludeFromExplicitInstantiationAttr>()) | |||
3276 | continue; | |||
3277 | ||||
3278 | MemberSpecializationInfo *MSInfo = Var->getMemberSpecializationInfo(); | |||
3279 | assert(MSInfo && "No member specialization information?")((MSInfo && "No member specialization information?") ? static_cast<void> (0) : __assert_fail ("MSInfo && \"No member specialization information?\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3279, __PRETTY_FUNCTION__)); | |||
3280 | if (MSInfo->getTemplateSpecializationKind() | |||
3281 | == TSK_ExplicitSpecialization) | |||
3282 | continue; | |||
3283 | ||||
3284 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, | |||
3285 | Var, | |||
3286 | MSInfo->getTemplateSpecializationKind(), | |||
3287 | MSInfo->getPointOfInstantiation(), | |||
3288 | SuppressNew) || | |||
3289 | SuppressNew) | |||
3290 | continue; | |||
3291 | ||||
3292 | if (TSK == TSK_ExplicitInstantiationDefinition) { | |||
3293 | // C++0x [temp.explicit]p8: | |||
3294 | // An explicit instantiation definition that names a class template | |||
3295 | // specialization explicitly instantiates the class template | |||
3296 | // specialization and is only an explicit instantiation definition | |||
3297 | // of members whose definition is visible at the point of | |||
3298 | // instantiation. | |||
3299 | if (!Var->getInstantiatedFromStaticDataMember()->getDefinition()) | |||
3300 | continue; | |||
3301 | ||||
3302 | Var->setTemplateSpecializationKind(TSK, PointOfInstantiation); | |||
3303 | InstantiateVariableDefinition(PointOfInstantiation, Var); | |||
3304 | } else { | |||
3305 | Var->setTemplateSpecializationKind(TSK, PointOfInstantiation); | |||
3306 | } | |||
3307 | } | |||
3308 | } else if (auto *Record = dyn_cast<CXXRecordDecl>(D)) { | |||
3309 | if (Record->hasAttr<ExcludeFromExplicitInstantiationAttr>()) | |||
3310 | continue; | |||
3311 | ||||
3312 | // Always skip the injected-class-name, along with any | |||
3313 | // redeclarations of nested classes, since both would cause us | |||
3314 | // to try to instantiate the members of a class twice. | |||
3315 | // Skip closure types; they'll get instantiated when we instantiate | |||
3316 | // the corresponding lambda-expression. | |||
3317 | if (Record->isInjectedClassName() || Record->getPreviousDecl() || | |||
3318 | Record->isLambda()) | |||
3319 | continue; | |||
3320 | ||||
3321 | MemberSpecializationInfo *MSInfo = Record->getMemberSpecializationInfo(); | |||
3322 | assert(MSInfo && "No member specialization information?")((MSInfo && "No member specialization information?") ? static_cast<void> (0) : __assert_fail ("MSInfo && \"No member specialization information?\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3322, __PRETTY_FUNCTION__)); | |||
3323 | ||||
3324 | if (MSInfo->getTemplateSpecializationKind() | |||
3325 | == TSK_ExplicitSpecialization) | |||
3326 | continue; | |||
3327 | ||||
3328 | if (Context.getTargetInfo().getTriple().isOSWindows() && | |||
3329 | TSK == TSK_ExplicitInstantiationDeclaration) { | |||
3330 | // On Windows, explicit instantiation decl of the outer class doesn't | |||
3331 | // affect the inner class. Typically extern template declarations are | |||
3332 | // used in combination with dll import/export annotations, but those | |||
3333 | // are not propagated from the outer class templates to inner classes. | |||
3334 | // Therefore, do not instantiate inner classes on this platform, so | |||
3335 | // that users don't end up with undefined symbols during linking. | |||
3336 | continue; | |||
3337 | } | |||
3338 | ||||
3339 | if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, | |||
3340 | Record, | |||
3341 | MSInfo->getTemplateSpecializationKind(), | |||
3342 | MSInfo->getPointOfInstantiation(), | |||
3343 | SuppressNew) || | |||
3344 | SuppressNew) | |||
3345 | continue; | |||
3346 | ||||
3347 | CXXRecordDecl *Pattern = Record->getInstantiatedFromMemberClass(); | |||
3348 | assert(Pattern && "Missing instantiated-from-template information")((Pattern && "Missing instantiated-from-template information" ) ? static_cast<void> (0) : __assert_fail ("Pattern && \"Missing instantiated-from-template information\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3348, __PRETTY_FUNCTION__)); | |||
3349 | ||||
3350 | if (!Record->getDefinition()) { | |||
3351 | if (!Pattern->getDefinition()) { | |||
3352 | // C++0x [temp.explicit]p8: | |||
3353 | // An explicit instantiation definition that names a class template | |||
3354 | // specialization explicitly instantiates the class template | |||
3355 | // specialization and is only an explicit instantiation definition | |||
3356 | // of members whose definition is visible at the point of | |||
3357 | // instantiation. | |||
3358 | if (TSK == TSK_ExplicitInstantiationDeclaration) { | |||
3359 | MSInfo->setTemplateSpecializationKind(TSK); | |||
3360 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | |||
3361 | } | |||
3362 | ||||
3363 | continue; | |||
3364 | } | |||
3365 | ||||
3366 | InstantiateClass(PointOfInstantiation, Record, Pattern, | |||
3367 | TemplateArgs, | |||
3368 | TSK); | |||
3369 | } else { | |||
3370 | if (TSK == TSK_ExplicitInstantiationDefinition && | |||
3371 | Record->getTemplateSpecializationKind() == | |||
3372 | TSK_ExplicitInstantiationDeclaration) { | |||
3373 | Record->setTemplateSpecializationKind(TSK); | |||
3374 | MarkVTableUsed(PointOfInstantiation, Record, true); | |||
3375 | } | |||
3376 | } | |||
3377 | ||||
3378 | Pattern = cast_or_null<CXXRecordDecl>(Record->getDefinition()); | |||
3379 | if (Pattern) | |||
3380 | InstantiateClassMembers(PointOfInstantiation, Pattern, TemplateArgs, | |||
3381 | TSK); | |||
3382 | } else if (auto *Enum = dyn_cast<EnumDecl>(D)) { | |||
3383 | MemberSpecializationInfo *MSInfo = Enum->getMemberSpecializationInfo(); | |||
3384 | assert(MSInfo && "No member specialization information?")((MSInfo && "No member specialization information?") ? static_cast<void> (0) : __assert_fail ("MSInfo && \"No member specialization information?\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3384, __PRETTY_FUNCTION__)); | |||
3385 | ||||
3386 | if (MSInfo->getTemplateSpecializationKind() | |||
3387 | == TSK_ExplicitSpecialization) | |||
3388 | continue; | |||
3389 | ||||
3390 | if (CheckSpecializationInstantiationRedecl( | |||
3391 | PointOfInstantiation, TSK, Enum, | |||
3392 | MSInfo->getTemplateSpecializationKind(), | |||
3393 | MSInfo->getPointOfInstantiation(), SuppressNew) || | |||
3394 | SuppressNew) | |||
3395 | continue; | |||
3396 | ||||
3397 | if (Enum->getDefinition()) | |||
3398 | continue; | |||
3399 | ||||
3400 | EnumDecl *Pattern = Enum->getTemplateInstantiationPattern(); | |||
3401 | assert(Pattern && "Missing instantiated-from-template information")((Pattern && "Missing instantiated-from-template information" ) ? static_cast<void> (0) : __assert_fail ("Pattern && \"Missing instantiated-from-template information\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3401, __PRETTY_FUNCTION__)); | |||
3402 | ||||
3403 | if (TSK == TSK_ExplicitInstantiationDefinition) { | |||
3404 | if (!Pattern->getDefinition()) | |||
3405 | continue; | |||
3406 | ||||
3407 | InstantiateEnum(PointOfInstantiation, Enum, Pattern, TemplateArgs, TSK); | |||
3408 | } else { | |||
3409 | MSInfo->setTemplateSpecializationKind(TSK); | |||
3410 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | |||
3411 | } | |||
3412 | } else if (auto *Field = dyn_cast<FieldDecl>(D)) { | |||
3413 | // No need to instantiate in-class initializers during explicit | |||
3414 | // instantiation. | |||
3415 | if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) { | |||
3416 | CXXRecordDecl *ClassPattern = | |||
3417 | Instantiation->getTemplateInstantiationPattern(); | |||
3418 | DeclContext::lookup_result Lookup = | |||
3419 | ClassPattern->lookup(Field->getDeclName()); | |||
3420 | FieldDecl *Pattern = cast<FieldDecl>(Lookup.front()); | |||
3421 | InstantiateInClassInitializer(PointOfInstantiation, Field, Pattern, | |||
3422 | TemplateArgs); | |||
3423 | } | |||
3424 | } | |||
3425 | } | |||
3426 | } | |||
3427 | ||||
3428 | /// Instantiate the definitions of all of the members of the | |||
3429 | /// given class template specialization, which was named as part of an | |||
3430 | /// explicit instantiation. | |||
3431 | void | |||
3432 | Sema::InstantiateClassTemplateSpecializationMembers( | |||
3433 | SourceLocation PointOfInstantiation, | |||
3434 | ClassTemplateSpecializationDecl *ClassTemplateSpec, | |||
3435 | TemplateSpecializationKind TSK) { | |||
3436 | // C++0x [temp.explicit]p7: | |||
3437 | // An explicit instantiation that names a class template | |||
3438 | // specialization is an explicit instantion of the same kind | |||
3439 | // (declaration or definition) of each of its members (not | |||
3440 | // including members inherited from base classes) that has not | |||
3441 | // been previously explicitly specialized in the translation unit | |||
3442 | // containing the explicit instantiation, except as described | |||
3443 | // below. | |||
3444 | InstantiateClassMembers(PointOfInstantiation, ClassTemplateSpec, | |||
3445 | getTemplateInstantiationArgs(ClassTemplateSpec), | |||
3446 | TSK); | |||
3447 | } | |||
3448 | ||||
3449 | StmtResult | |||
3450 | Sema::SubstStmt(Stmt *S, const MultiLevelTemplateArgumentList &TemplateArgs) { | |||
3451 | if (!S) | |||
3452 | return S; | |||
3453 | ||||
3454 | TemplateInstantiator Instantiator(*this, TemplateArgs, | |||
3455 | SourceLocation(), | |||
3456 | DeclarationName()); | |||
3457 | return Instantiator.TransformStmt(S); | |||
3458 | } | |||
3459 | ||||
3460 | bool Sema::SubstTemplateArguments( | |||
3461 | ArrayRef<TemplateArgumentLoc> Args, | |||
3462 | const MultiLevelTemplateArgumentList &TemplateArgs, | |||
3463 | TemplateArgumentListInfo &Out) { | |||
3464 | TemplateInstantiator Instantiator(*this, TemplateArgs, | |||
3465 | SourceLocation(), | |||
3466 | DeclarationName()); | |||
3467 | return Instantiator.TransformTemplateArguments(Args.begin(), Args.end(), | |||
3468 | Out); | |||
3469 | } | |||
3470 | ||||
3471 | ExprResult | |||
3472 | Sema::SubstExpr(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs) { | |||
3473 | if (!E) | |||
3474 | return E; | |||
3475 | ||||
3476 | TemplateInstantiator Instantiator(*this, TemplateArgs, | |||
3477 | SourceLocation(), | |||
3478 | DeclarationName()); | |||
3479 | return Instantiator.TransformExpr(E); | |||
3480 | } | |||
3481 | ||||
3482 | ExprResult Sema::SubstInitializer(Expr *Init, | |||
3483 | const MultiLevelTemplateArgumentList &TemplateArgs, | |||
3484 | bool CXXDirectInit) { | |||
3485 | TemplateInstantiator Instantiator(*this, TemplateArgs, | |||
3486 | SourceLocation(), | |||
3487 | DeclarationName()); | |||
3488 | return Instantiator.TransformInitializer(Init, CXXDirectInit); | |||
3489 | } | |||
3490 | ||||
3491 | bool Sema::SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall, | |||
3492 | const MultiLevelTemplateArgumentList &TemplateArgs, | |||
3493 | SmallVectorImpl<Expr *> &Outputs) { | |||
3494 | if (Exprs.empty()) | |||
3495 | return false; | |||
3496 | ||||
3497 | TemplateInstantiator Instantiator(*this, TemplateArgs, | |||
3498 | SourceLocation(), | |||
3499 | DeclarationName()); | |||
3500 | return Instantiator.TransformExprs(Exprs.data(), Exprs.size(), | |||
3501 | IsCall, Outputs); | |||
3502 | } | |||
3503 | ||||
3504 | NestedNameSpecifierLoc | |||
3505 | Sema::SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, | |||
3506 | const MultiLevelTemplateArgumentList &TemplateArgs) { | |||
3507 | if (!NNS) | |||
3508 | return NestedNameSpecifierLoc(); | |||
3509 | ||||
3510 | TemplateInstantiator Instantiator(*this, TemplateArgs, NNS.getBeginLoc(), | |||
3511 | DeclarationName()); | |||
3512 | return Instantiator.TransformNestedNameSpecifierLoc(NNS); | |||
3513 | } | |||
3514 | ||||
3515 | /// Do template substitution on declaration name info. | |||
3516 | DeclarationNameInfo | |||
3517 | Sema::SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, | |||
3518 | const MultiLevelTemplateArgumentList &TemplateArgs) { | |||
3519 | TemplateInstantiator Instantiator(*this, TemplateArgs, NameInfo.getLoc(), | |||
3520 | NameInfo.getName()); | |||
3521 | return Instantiator.TransformDeclarationNameInfo(NameInfo); | |||
3522 | } | |||
3523 | ||||
3524 | TemplateName | |||
3525 | Sema::SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, | |||
3526 | TemplateName Name, SourceLocation Loc, | |||
3527 | const MultiLevelTemplateArgumentList &TemplateArgs) { | |||
3528 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, | |||
3529 | DeclarationName()); | |||
3530 | CXXScopeSpec SS; | |||
3531 | SS.Adopt(QualifierLoc); | |||
3532 | return Instantiator.TransformTemplateName(SS, Name, Loc); | |||
3533 | } | |||
3534 | ||||
3535 | bool Sema::Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, | |||
3536 | TemplateArgumentListInfo &Result, | |||
3537 | const MultiLevelTemplateArgumentList &TemplateArgs) { | |||
3538 | TemplateInstantiator Instantiator(*this, TemplateArgs, SourceLocation(), | |||
3539 | DeclarationName()); | |||
3540 | ||||
3541 | return Instantiator.TransformTemplateArguments(Args, NumArgs, Result); | |||
3542 | } | |||
3543 | ||||
3544 | static const Decl *getCanonicalParmVarDecl(const Decl *D) { | |||
3545 | // When storing ParmVarDecls in the local instantiation scope, we always | |||
3546 | // want to use the ParmVarDecl from the canonical function declaration, | |||
3547 | // since the map is then valid for any redeclaration or definition of that | |||
3548 | // function. | |||
3549 | if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(D)) { | |||
3550 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) { | |||
3551 | unsigned i = PV->getFunctionScopeIndex(); | |||
3552 | // This parameter might be from a freestanding function type within the | |||
3553 | // function and isn't necessarily referring to one of FD's parameters. | |||
3554 | if (i < FD->getNumParams() && FD->getParamDecl(i) == PV) | |||
3555 | return FD->getCanonicalDecl()->getParamDecl(i); | |||
3556 | } | |||
3557 | } | |||
3558 | return D; | |||
3559 | } | |||
3560 | ||||
3561 | ||||
3562 | llvm::PointerUnion<Decl *, LocalInstantiationScope::DeclArgumentPack *> * | |||
3563 | LocalInstantiationScope::findInstantiationOf(const Decl *D) { | |||
3564 | D = getCanonicalParmVarDecl(D); | |||
3565 | for (LocalInstantiationScope *Current = this; Current; | |||
3566 | Current = Current->Outer) { | |||
3567 | ||||
3568 | // Check if we found something within this scope. | |||
3569 | const Decl *CheckD = D; | |||
3570 | do { | |||
3571 | LocalDeclsMap::iterator Found = Current->LocalDecls.find(CheckD); | |||
3572 | if (Found != Current->LocalDecls.end()) | |||
3573 | return &Found->second; | |||
3574 | ||||
3575 | // If this is a tag declaration, it's possible that we need to look for | |||
3576 | // a previous declaration. | |||
3577 | if (const TagDecl *Tag = dyn_cast<TagDecl>(CheckD)) | |||
3578 | CheckD = Tag->getPreviousDecl(); | |||
3579 | else | |||
3580 | CheckD = nullptr; | |||
3581 | } while (CheckD); | |||
3582 | ||||
3583 | // If we aren't combined with our outer scope, we're done. | |||
3584 | if (!Current->CombineWithOuterScope) | |||
3585 | break; | |||
3586 | } | |||
3587 | ||||
3588 | // If we're performing a partial substitution during template argument | |||
3589 | // deduction, we may not have values for template parameters yet. | |||
3590 | if (isa<NonTypeTemplateParmDecl>(D) || isa<TemplateTypeParmDecl>(D) || | |||
3591 | isa<TemplateTemplateParmDecl>(D)) | |||
3592 | return nullptr; | |||
3593 | ||||
3594 | // Local types referenced prior to definition may require instantiation. | |||
3595 | if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) | |||
3596 | if (RD->isLocalClass()) | |||
3597 | return nullptr; | |||
3598 | ||||
3599 | // Enumeration types referenced prior to definition may appear as a result of | |||
3600 | // error recovery. | |||
3601 | if (isa<EnumDecl>(D)) | |||
3602 | return nullptr; | |||
3603 | ||||
3604 | // Materialized typedefs/type alias for implicit deduction guides may require | |||
3605 | // instantiation. | |||
3606 | if (isa<TypedefNameDecl>(D) && | |||
3607 | isa<CXXDeductionGuideDecl>(D->getDeclContext())) | |||
3608 | return nullptr; | |||
3609 | ||||
3610 | // If we didn't find the decl, then we either have a sema bug, or we have a | |||
3611 | // forward reference to a label declaration. Return null to indicate that | |||
3612 | // we have an uninstantiated label. | |||
3613 | assert(isa<LabelDecl>(D) && "declaration not instantiated in this scope")((isa<LabelDecl>(D) && "declaration not instantiated in this scope" ) ? static_cast<void> (0) : __assert_fail ("isa<LabelDecl>(D) && \"declaration not instantiated in this scope\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3613, __PRETTY_FUNCTION__)); | |||
3614 | return nullptr; | |||
3615 | } | |||
3616 | ||||
3617 | void LocalInstantiationScope::InstantiatedLocal(const Decl *D, Decl *Inst) { | |||
3618 | D = getCanonicalParmVarDecl(D); | |||
3619 | llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D]; | |||
3620 | if (Stored.isNull()) { | |||
3621 | #ifndef NDEBUG | |||
3622 | // It should not be present in any surrounding scope either. | |||
3623 | LocalInstantiationScope *Current = this; | |||
3624 | while (Current->CombineWithOuterScope && Current->Outer) { | |||
3625 | Current = Current->Outer; | |||
3626 | assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&((Current->LocalDecls.find(D) == Current->LocalDecls.end () && "Instantiated local in inner and outer scopes") ? static_cast<void> (0) : __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Instantiated local in inner and outer scopes\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3627, __PRETTY_FUNCTION__)) | |||
3627 | "Instantiated local in inner and outer scopes")((Current->LocalDecls.find(D) == Current->LocalDecls.end () && "Instantiated local in inner and outer scopes") ? static_cast<void> (0) : __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Instantiated local in inner and outer scopes\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3627, __PRETTY_FUNCTION__)); | |||
3628 | } | |||
3629 | #endif | |||
3630 | Stored = Inst; | |||
3631 | } else if (DeclArgumentPack *Pack = Stored.dyn_cast<DeclArgumentPack *>()) { | |||
3632 | Pack->push_back(cast<VarDecl>(Inst)); | |||
3633 | } else { | |||
3634 | assert(Stored.get<Decl *>() == Inst && "Already instantiated this local")((Stored.get<Decl *>() == Inst && "Already instantiated this local" ) ? static_cast<void> (0) : __assert_fail ("Stored.get<Decl *>() == Inst && \"Already instantiated this local\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3634, __PRETTY_FUNCTION__)); | |||
3635 | } | |||
3636 | } | |||
3637 | ||||
3638 | void LocalInstantiationScope::InstantiatedLocalPackArg(const Decl *D, | |||
3639 | VarDecl *Inst) { | |||
3640 | D = getCanonicalParmVarDecl(D); | |||
3641 | DeclArgumentPack *Pack = LocalDecls[D].get<DeclArgumentPack *>(); | |||
3642 | Pack->push_back(Inst); | |||
3643 | } | |||
3644 | ||||
3645 | void LocalInstantiationScope::MakeInstantiatedLocalArgPack(const Decl *D) { | |||
3646 | #ifndef NDEBUG | |||
3647 | // This should be the first time we've been told about this decl. | |||
3648 | for (LocalInstantiationScope *Current = this; | |||
3649 | Current && Current->CombineWithOuterScope; Current = Current->Outer) | |||
3650 | assert(Current->LocalDecls.find(D) == Current->LocalDecls.end() &&((Current->LocalDecls.find(D) == Current->LocalDecls.end () && "Creating local pack after instantiation of local" ) ? static_cast<void> (0) : __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Creating local pack after instantiation of local\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3651, __PRETTY_FUNCTION__)) | |||
3651 | "Creating local pack after instantiation of local")((Current->LocalDecls.find(D) == Current->LocalDecls.end () && "Creating local pack after instantiation of local" ) ? static_cast<void> (0) : __assert_fail ("Current->LocalDecls.find(D) == Current->LocalDecls.end() && \"Creating local pack after instantiation of local\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3651, __PRETTY_FUNCTION__)); | |||
3652 | #endif | |||
3653 | ||||
3654 | D = getCanonicalParmVarDecl(D); | |||
3655 | llvm::PointerUnion<Decl *, DeclArgumentPack *> &Stored = LocalDecls[D]; | |||
3656 | DeclArgumentPack *Pack = new DeclArgumentPack; | |||
3657 | Stored = Pack; | |||
3658 | ArgumentPacks.push_back(Pack); | |||
3659 | } | |||
3660 | ||||
3661 | bool LocalInstantiationScope::isLocalPackExpansion(const Decl *D) { | |||
3662 | for (DeclArgumentPack *Pack : ArgumentPacks) | |||
3663 | if (std::find(Pack->begin(), Pack->end(), D) != Pack->end()) | |||
3664 | return true; | |||
3665 | return false; | |||
3666 | } | |||
3667 | ||||
3668 | void LocalInstantiationScope::SetPartiallySubstitutedPack(NamedDecl *Pack, | |||
3669 | const TemplateArgument *ExplicitArgs, | |||
3670 | unsigned NumExplicitArgs) { | |||
3671 | assert((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) &&(((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack ) && "Already have a partially-substituted pack") ? static_cast <void> (0) : __assert_fail ("(!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) && \"Already have a partially-substituted pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3672, __PRETTY_FUNCTION__)) | |||
3672 | "Already have a partially-substituted pack")(((!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack ) && "Already have a partially-substituted pack") ? static_cast <void> (0) : __assert_fail ("(!PartiallySubstitutedPack || PartiallySubstitutedPack == Pack) && \"Already have a partially-substituted pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3672, __PRETTY_FUNCTION__)); | |||
3673 | assert((!PartiallySubstitutedPack(((!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && "Wrong number of arguments in partially-substituted pack" ) ? static_cast<void> (0) : __assert_fail ("(!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && \"Wrong number of arguments in partially-substituted pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3675, __PRETTY_FUNCTION__)) | |||
3674 | || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) &&(((!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && "Wrong number of arguments in partially-substituted pack" ) ? static_cast<void> (0) : __assert_fail ("(!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && \"Wrong number of arguments in partially-substituted pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3675, __PRETTY_FUNCTION__)) | |||
3675 | "Wrong number of arguments in partially-substituted pack")(((!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && "Wrong number of arguments in partially-substituted pack" ) ? static_cast<void> (0) : __assert_fail ("(!PartiallySubstitutedPack || NumArgsInPartiallySubstitutedPack == NumExplicitArgs) && \"Wrong number of arguments in partially-substituted pack\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 3675, __PRETTY_FUNCTION__)); | |||
3676 | PartiallySubstitutedPack = Pack; | |||
3677 | ArgsInPartiallySubstitutedPack = ExplicitArgs; | |||
3678 | NumArgsInPartiallySubstitutedPack = NumExplicitArgs; | |||
3679 | } | |||
3680 | ||||
3681 | NamedDecl *LocalInstantiationScope::getPartiallySubstitutedPack( | |||
3682 | const TemplateArgument **ExplicitArgs, | |||
3683 | unsigned *NumExplicitArgs) const { | |||
3684 | if (ExplicitArgs) | |||
3685 | *ExplicitArgs = nullptr; | |||
3686 | if (NumExplicitArgs) | |||
3687 | *NumExplicitArgs = 0; | |||
3688 | ||||
3689 | for (const LocalInstantiationScope *Current = this; Current; | |||
3690 | Current = Current->Outer) { | |||
3691 | if (Current->PartiallySubstitutedPack) { | |||
3692 | if (ExplicitArgs) | |||
3693 | *ExplicitArgs = Current->ArgsInPartiallySubstitutedPack; | |||
3694 | if (NumExplicitArgs) | |||
3695 | *NumExplicitArgs = Current->NumArgsInPartiallySubstitutedPack; | |||
3696 | ||||
3697 | return Current->PartiallySubstitutedPack; | |||
3698 | } | |||
3699 | ||||
3700 | if (!Current->CombineWithOuterScope) | |||
3701 | break; | |||
3702 | } | |||
3703 | ||||
3704 | return nullptr; | |||
3705 | } |
1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | //===----------------------------------------------------------------------===// |
7 | // |
8 | // This file implements a semantic tree transformation that takes a given |
9 | // AST and rebuilds it, possibly transforming some nodes in the process. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
14 | #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
15 | |
16 | #include "CoroutineStmtBuilder.h" |
17 | #include "TypeLocBuilder.h" |
18 | #include "clang/AST/Decl.h" |
19 | #include "clang/AST/DeclObjC.h" |
20 | #include "clang/AST/DeclTemplate.h" |
21 | #include "clang/AST/Expr.h" |
22 | #include "clang/AST/ExprConcepts.h" |
23 | #include "clang/AST/ExprCXX.h" |
24 | #include "clang/AST/ExprObjC.h" |
25 | #include "clang/AST/ExprOpenMP.h" |
26 | #include "clang/AST/OpenMPClause.h" |
27 | #include "clang/AST/Stmt.h" |
28 | #include "clang/AST/StmtCXX.h" |
29 | #include "clang/AST/StmtObjC.h" |
30 | #include "clang/AST/StmtOpenMP.h" |
31 | #include "clang/Basic/DiagnosticParse.h" |
32 | #include "clang/Basic/OpenMPKinds.h" |
33 | #include "clang/Sema/Designator.h" |
34 | #include "clang/Sema/Lookup.h" |
35 | #include "clang/Sema/Ownership.h" |
36 | #include "clang/Sema/ParsedTemplate.h" |
37 | #include "clang/Sema/ScopeInfo.h" |
38 | #include "clang/Sema/SemaDiagnostic.h" |
39 | #include "clang/Sema/SemaInternal.h" |
40 | #include "llvm/ADT/ArrayRef.h" |
41 | #include "llvm/Support/ErrorHandling.h" |
42 | #include <algorithm> |
43 | |
44 | using namespace llvm::omp; |
45 | |
46 | namespace clang { |
47 | using namespace sema; |
48 | |
49 | /// A semantic tree transformation that allows one to transform one |
50 | /// abstract syntax tree into another. |
51 | /// |
52 | /// A new tree transformation is defined by creating a new subclass \c X of |
53 | /// \c TreeTransform<X> and then overriding certain operations to provide |
54 | /// behavior specific to that transformation. For example, template |
55 | /// instantiation is implemented as a tree transformation where the |
56 | /// transformation of TemplateTypeParmType nodes involves substituting the |
57 | /// template arguments for their corresponding template parameters; a similar |
58 | /// transformation is performed for non-type template parameters and |
59 | /// template template parameters. |
60 | /// |
61 | /// This tree-transformation template uses static polymorphism to allow |
62 | /// subclasses to customize any of its operations. Thus, a subclass can |
63 | /// override any of the transformation or rebuild operators by providing an |
64 | /// operation with the same signature as the default implementation. The |
65 | /// overriding function should not be virtual. |
66 | /// |
67 | /// Semantic tree transformations are split into two stages, either of which |
68 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
69 | /// or the parts of an AST node using the various transformation functions, |
70 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
71 | /// node of the appropriate kind from the pieces. The default transformation |
72 | /// routines recursively transform the operands to composite AST nodes (e.g., |
73 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
74 | /// were changed by the transformation, invokes the rebuild operation to create |
75 | /// a new AST node. |
76 | /// |
77 | /// Subclasses can customize the transformation at various levels. The |
78 | /// most coarse-grained transformations involve replacing TransformType(), |
79 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
80 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
81 | /// new implementations. |
82 | /// |
83 | /// For more fine-grained transformations, subclasses can replace any of the |
84 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
85 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
86 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
87 | /// to substitute template arguments for their corresponding template |
88 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
89 | /// functions to control how AST nodes are rebuilt when their operands change. |
90 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
91 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
92 | /// be able to use more efficient rebuild steps. |
93 | /// |
94 | /// There are a handful of other functions that can be overridden, allowing one |
95 | /// to avoid traversing nodes that don't need any transformation |
96 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
97 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
98 | /// default locations and entity names used for type-checking |
99 | /// (\c getBaseLocation(), \c getBaseEntity()). |
100 | template<typename Derived> |
101 | class TreeTransform { |
102 | /// Private RAII object that helps us forget and then re-remember |
103 | /// the template argument corresponding to a partially-substituted parameter |
104 | /// pack. |
105 | class ForgetPartiallySubstitutedPackRAII { |
106 | Derived &Self; |
107 | TemplateArgument Old; |
108 | |
109 | public: |
110 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
111 | Old = Self.ForgetPartiallySubstitutedPack(); |
112 | } |
113 | |
114 | ~ForgetPartiallySubstitutedPackRAII() { |
115 | Self.RememberPartiallySubstitutedPack(Old); |
116 | } |
117 | }; |
118 | |
119 | protected: |
120 | Sema &SemaRef; |
121 | |
122 | /// The set of local declarations that have been transformed, for |
123 | /// cases where we are forced to build new declarations within the transformer |
124 | /// rather than in the subclass (e.g., lambda closure types). |
125 | llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls; |
126 | |
127 | public: |
128 | /// Initializes a new tree transformer. |
129 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
130 | |
131 | /// Retrieves a reference to the derived class. |
132 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
133 | |
134 | /// Retrieves a reference to the derived class. |
135 | const Derived &getDerived() const { |
136 | return static_cast<const Derived&>(*this); |
137 | } |
138 | |
139 | static inline ExprResult Owned(Expr *E) { return E; } |
140 | static inline StmtResult Owned(Stmt *S) { return S; } |
141 | |
142 | /// Retrieves a reference to the semantic analysis object used for |
143 | /// this tree transform. |
144 | Sema &getSema() const { return SemaRef; } |
145 | |
146 | /// Whether the transformation should always rebuild AST nodes, even |
147 | /// if none of the children have changed. |
148 | /// |
149 | /// Subclasses may override this function to specify when the transformation |
150 | /// should rebuild all AST nodes. |
151 | /// |
152 | /// We must always rebuild all AST nodes when performing variadic template |
153 | /// pack expansion, in order to avoid violating the AST invariant that each |
154 | /// statement node appears at most once in its containing declaration. |
155 | bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; } |
156 | |
157 | /// Whether the transformation is forming an expression or statement that |
158 | /// replaces the original. In this case, we'll reuse mangling numbers from |
159 | /// existing lambdas. |
160 | bool ReplacingOriginal() { return false; } |
161 | |
162 | /// Wether CXXConstructExpr can be skipped when they are implicit. |
163 | /// They will be reconstructed when used if needed. |
164 | /// This is usefull when the user that cause rebuilding of the |
165 | /// CXXConstructExpr is outside of the expression at which the TreeTransform |
166 | /// started. |
167 | bool AllowSkippingCXXConstructExpr() { return true; } |
168 | |
169 | /// Returns the location of the entity being transformed, if that |
170 | /// information was not available elsewhere in the AST. |
171 | /// |
172 | /// By default, returns no source-location information. Subclasses can |
173 | /// provide an alternative implementation that provides better location |
174 | /// information. |
175 | SourceLocation getBaseLocation() { return SourceLocation(); } |
176 | |
177 | /// Returns the name of the entity being transformed, if that |
178 | /// information was not available elsewhere in the AST. |
179 | /// |
180 | /// By default, returns an empty name. Subclasses can provide an alternative |
181 | /// implementation with a more precise name. |
182 | DeclarationName getBaseEntity() { return DeclarationName(); } |
183 | |
184 | /// Sets the "base" location and entity when that |
185 | /// information is known based on another transformation. |
186 | /// |
187 | /// By default, the source location and entity are ignored. Subclasses can |
188 | /// override this function to provide a customized implementation. |
189 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
190 | |
191 | /// RAII object that temporarily sets the base location and entity |
192 | /// used for reporting diagnostics in types. |
193 | class TemporaryBase { |
194 | TreeTransform &Self; |
195 | SourceLocation OldLocation; |
196 | DeclarationName OldEntity; |
197 | |
198 | public: |
199 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
200 | DeclarationName Entity) : Self(Self) { |
201 | OldLocation = Self.getDerived().getBaseLocation(); |
202 | OldEntity = Self.getDerived().getBaseEntity(); |
203 | |
204 | if (Location.isValid()) |
205 | Self.getDerived().setBase(Location, Entity); |
206 | } |
207 | |
208 | ~TemporaryBase() { |
209 | Self.getDerived().setBase(OldLocation, OldEntity); |
210 | } |
211 | }; |
212 | |
213 | /// Determine whether the given type \p T has already been |
214 | /// transformed. |
215 | /// |
216 | /// Subclasses can provide an alternative implementation of this routine |
217 | /// to short-circuit evaluation when it is known that a given type will |
218 | /// not change. For example, template instantiation need not traverse |
219 | /// non-dependent types. |
220 | bool AlreadyTransformed(QualType T) { |
221 | return T.isNull(); |
222 | } |
223 | |
224 | /// Transform a template parameter depth level. |
225 | /// |
226 | /// During a transformation that transforms template parameters, this maps |
227 | /// an old template parameter depth to a new depth. |
228 | unsigned TransformTemplateDepth(unsigned Depth) { |
229 | return Depth; |
230 | } |
231 | |
232 | /// Determine whether the given call argument should be dropped, e.g., |
233 | /// because it is a default argument. |
234 | /// |
235 | /// Subclasses can provide an alternative implementation of this routine to |
236 | /// determine which kinds of call arguments get dropped. By default, |
237 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
238 | bool DropCallArgument(Expr *E) { |
239 | return E->isDefaultArgument(); |
240 | } |
241 | |
242 | /// Determine whether we should expand a pack expansion with the |
243 | /// given set of parameter packs into separate arguments by repeatedly |
244 | /// transforming the pattern. |
245 | /// |
246 | /// By default, the transformer never tries to expand pack expansions. |
247 | /// Subclasses can override this routine to provide different behavior. |
248 | /// |
249 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
250 | /// pack expansion. |
251 | /// |
252 | /// \param PatternRange The source range that covers the entire pattern of |
253 | /// the pack expansion. |
254 | /// |
255 | /// \param Unexpanded The set of unexpanded parameter packs within the |
256 | /// pattern. |
257 | /// |
258 | /// \param ShouldExpand Will be set to \c true if the transformer should |
259 | /// expand the corresponding pack expansions into separate arguments. When |
260 | /// set, \c NumExpansions must also be set. |
261 | /// |
262 | /// \param RetainExpansion Whether the caller should add an unexpanded |
263 | /// pack expansion after all of the expanded arguments. This is used |
264 | /// when extending explicitly-specified template argument packs per |
265 | /// C++0x [temp.arg.explicit]p9. |
266 | /// |
267 | /// \param NumExpansions The number of separate arguments that will be in |
268 | /// the expanded form of the corresponding pack expansion. This is both an |
269 | /// input and an output parameter, which can be set by the caller if the |
270 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
271 | /// and will be set by the callee when the number of expansions is known. |
272 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
273 | /// set this value in other cases. |
274 | /// |
275 | /// \returns true if an error occurred (e.g., because the parameter packs |
276 | /// are to be instantiated with arguments of different lengths), false |
277 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
278 | /// must be set. |
279 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
280 | SourceRange PatternRange, |
281 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
282 | bool &ShouldExpand, |
283 | bool &RetainExpansion, |
284 | Optional<unsigned> &NumExpansions) { |
285 | ShouldExpand = false; |
286 | return false; |
287 | } |
288 | |
289 | /// "Forget" about the partially-substituted pack template argument, |
290 | /// when performing an instantiation that must preserve the parameter pack |
291 | /// use. |
292 | /// |
293 | /// This routine is meant to be overridden by the template instantiator. |
294 | TemplateArgument ForgetPartiallySubstitutedPack() { |
295 | return TemplateArgument(); |
296 | } |
297 | |
298 | /// "Remember" the partially-substituted pack template argument |
299 | /// after performing an instantiation that must preserve the parameter pack |
300 | /// use. |
301 | /// |
302 | /// This routine is meant to be overridden by the template instantiator. |
303 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
304 | |
305 | /// Note to the derived class when a function parameter pack is |
306 | /// being expanded. |
307 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
308 | |
309 | /// Transforms the given type into another type. |
310 | /// |
311 | /// By default, this routine transforms a type by creating a |
312 | /// TypeSourceInfo for it and delegating to the appropriate |
313 | /// function. This is expensive, but we don't mind, because |
314 | /// this method is deprecated anyway; all users should be |
315 | /// switched to storing TypeSourceInfos. |
316 | /// |
317 | /// \returns the transformed type. |
318 | QualType TransformType(QualType T); |
319 | |
320 | /// Transforms the given type-with-location into a new |
321 | /// type-with-location. |
322 | /// |
323 | /// By default, this routine transforms a type by delegating to the |
324 | /// appropriate TransformXXXType to build a new type. Subclasses |
325 | /// may override this function (to take over all type |
326 | /// transformations) or some set of the TransformXXXType functions |
327 | /// to alter the transformation. |
328 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
329 | |
330 | /// Transform the given type-with-location into a new |
331 | /// type, collecting location information in the given builder |
332 | /// as necessary. |
333 | /// |
334 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
335 | |
336 | /// Transform a type that is permitted to produce a |
337 | /// DeducedTemplateSpecializationType. |
338 | /// |
339 | /// This is used in the (relatively rare) contexts where it is acceptable |
340 | /// for transformation to produce a class template type with deduced |
341 | /// template arguments. |
342 | /// @{ |
343 | QualType TransformTypeWithDeducedTST(QualType T); |
344 | TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI); |
345 | /// @} |
346 | |
347 | /// The reason why the value of a statement is not discarded, if any. |
348 | enum StmtDiscardKind { |
349 | SDK_Discarded, |
350 | SDK_NotDiscarded, |
351 | SDK_StmtExprResult, |
352 | }; |
353 | |
354 | /// Transform the given statement. |
355 | /// |
356 | /// By default, this routine transforms a statement by delegating to the |
357 | /// appropriate TransformXXXStmt function to transform a specific kind of |
358 | /// statement or the TransformExpr() function to transform an expression. |
359 | /// Subclasses may override this function to transform statements using some |
360 | /// other mechanism. |
361 | /// |
362 | /// \returns the transformed statement. |
363 | StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK = SDK_Discarded); |
364 | |
365 | /// Transform the given statement. |
366 | /// |
367 | /// By default, this routine transforms a statement by delegating to the |
368 | /// appropriate TransformOMPXXXClause function to transform a specific kind |
369 | /// of clause. Subclasses may override this function to transform statements |
370 | /// using some other mechanism. |
371 | /// |
372 | /// \returns the transformed OpenMP clause. |
373 | OMPClause *TransformOMPClause(OMPClause *S); |
374 | |
375 | /// Transform the given attribute. |
376 | /// |
377 | /// By default, this routine transforms a statement by delegating to the |
378 | /// appropriate TransformXXXAttr function to transform a specific kind |
379 | /// of attribute. Subclasses may override this function to transform |
380 | /// attributed statements using some other mechanism. |
381 | /// |
382 | /// \returns the transformed attribute |
383 | const Attr *TransformAttr(const Attr *S); |
384 | |
385 | /// Transform the specified attribute. |
386 | /// |
387 | /// Subclasses should override the transformation of attributes with a pragma |
388 | /// spelling to transform expressions stored within the attribute. |
389 | /// |
390 | /// \returns the transformed attribute. |
391 | #define ATTR(X) |
392 | #define PRAGMA_SPELLING_ATTR(X) \ |
393 | const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; } |
394 | #include "clang/Basic/AttrList.inc" |
395 | |
396 | /// Transform the given expression. |
397 | /// |
398 | /// By default, this routine transforms an expression by delegating to the |
399 | /// appropriate TransformXXXExpr function to build a new expression. |
400 | /// Subclasses may override this function to transform expressions using some |
401 | /// other mechanism. |
402 | /// |
403 | /// \returns the transformed expression. |
404 | ExprResult TransformExpr(Expr *E); |
405 | |
406 | /// Transform the given initializer. |
407 | /// |
408 | /// By default, this routine transforms an initializer by stripping off the |
409 | /// semantic nodes added by initialization, then passing the result to |
410 | /// TransformExpr or TransformExprs. |
411 | /// |
412 | /// \returns the transformed initializer. |
413 | ExprResult TransformInitializer(Expr *Init, bool NotCopyInit); |
414 | |
415 | /// Transform the given list of expressions. |
416 | /// |
417 | /// This routine transforms a list of expressions by invoking |
418 | /// \c TransformExpr() for each subexpression. However, it also provides |
419 | /// support for variadic templates by expanding any pack expansions (if the |
420 | /// derived class permits such expansion) along the way. When pack expansions |
421 | /// are present, the number of outputs may not equal the number of inputs. |
422 | /// |
423 | /// \param Inputs The set of expressions to be transformed. |
424 | /// |
425 | /// \param NumInputs The number of expressions in \c Inputs. |
426 | /// |
427 | /// \param IsCall If \c true, then this transform is being performed on |
428 | /// function-call arguments, and any arguments that should be dropped, will |
429 | /// be. |
430 | /// |
431 | /// \param Outputs The transformed input expressions will be added to this |
432 | /// vector. |
433 | /// |
434 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
435 | /// due to transformation. |
436 | /// |
437 | /// \returns true if an error occurred, false otherwise. |
438 | bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall, |
439 | SmallVectorImpl<Expr *> &Outputs, |
440 | bool *ArgChanged = nullptr); |
441 | |
442 | /// Transform the given declaration, which is referenced from a type |
443 | /// or expression. |
444 | /// |
445 | /// By default, acts as the identity function on declarations, unless the |
446 | /// transformer has had to transform the declaration itself. Subclasses |
447 | /// may override this function to provide alternate behavior. |
448 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
449 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
450 | = TransformedLocalDecls.find(D); |
451 | if (Known != TransformedLocalDecls.end()) |
452 | return Known->second; |
453 | |
454 | return D; |
455 | } |
456 | |
457 | /// Transform the specified condition. |
458 | /// |
459 | /// By default, this transforms the variable and expression and rebuilds |
460 | /// the condition. |
461 | Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, |
462 | Expr *Expr, |
463 | Sema::ConditionKind Kind); |
464 | |
465 | /// Transform the attributes associated with the given declaration and |
466 | /// place them on the new declaration. |
467 | /// |
468 | /// By default, this operation does nothing. Subclasses may override this |
469 | /// behavior to transform attributes. |
470 | void transformAttrs(Decl *Old, Decl *New) { } |
471 | |
472 | /// Note that a local declaration has been transformed by this |
473 | /// transformer. |
474 | /// |
475 | /// Local declarations are typically transformed via a call to |
476 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
477 | /// the transformer itself has to transform the declarations. This routine |
478 | /// can be overridden by a subclass that keeps track of such mappings. |
479 | void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> New) { |
480 | assert(New.size() == 1 &&((New.size() == 1 && "must override transformedLocalDecl if performing pack expansion" ) ? static_cast<void> (0) : __assert_fail ("New.size() == 1 && \"must override transformedLocalDecl if performing pack expansion\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/TreeTransform.h" , 481, __PRETTY_FUNCTION__)) |
481 | "must override transformedLocalDecl if performing pack expansion")((New.size() == 1 && "must override transformedLocalDecl if performing pack expansion" ) ? static_cast<void> (0) : __assert_fail ("New.size() == 1 && \"must override transformedLocalDecl if performing pack expansion\"" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/TreeTransform.h" , 481, __PRETTY_FUNCTION__)); |
482 | TransformedLocalDecls[Old] = New.front(); |
483 | } |
484 | |
485 | /// Transform the definition of the given declaration. |
486 | /// |
487 | /// By default, invokes TransformDecl() to transform the declaration. |
488 | /// Subclasses may override this function to provide alternate behavior. |
489 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
490 | return getDerived().TransformDecl(Loc, D); |
491 | } |
492 | |
493 | /// Transform the given declaration, which was the first part of a |
494 | /// nested-name-specifier in a member access expression. |
495 | /// |
496 | /// This specific declaration transformation only applies to the first |
497 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
498 | /// the \c T in \c x->T::member |
499 | /// |
500 | /// By default, invokes TransformDecl() to transform the declaration. |
501 | /// Subclasses may override this function to provide alternate behavior. |
502 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
503 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
504 | } |
505 | |
506 | /// Transform the set of declarations in an OverloadExpr. |
507 | bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, |
508 | LookupResult &R); |
509 | |
510 | /// Transform the given nested-name-specifier with source-location |
511 | /// information. |
512 | /// |
513 | /// By default, transforms all of the types and declarations within the |
514 | /// nested-name-specifier. Subclasses may override this function to provide |
515 | /// alternate behavior. |
516 | NestedNameSpecifierLoc |
517 | TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
518 | QualType ObjectType = QualType(), |
519 | NamedDecl *FirstQualifierInScope = nullptr); |
520 | |
521 | /// Transform the given declaration name. |
522 | /// |
523 | /// By default, transforms the types of conversion function, constructor, |
524 | /// and destructor names and then (if needed) rebuilds the declaration name. |
525 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
526 | /// override this function to provide alternate behavior. |
527 | DeclarationNameInfo |
528 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
529 | |
530 | bool TransformRequiresExprRequirements(ArrayRef<concepts::Requirement *> Reqs, |
531 | llvm::SmallVectorImpl<concepts::Requirement *> &Transformed); |
532 | concepts::TypeRequirement * |
533 | TransformTypeRequirement(concepts::TypeRequirement *Req); |
534 | concepts::ExprRequirement * |
535 | TransformExprRequirement(concepts::ExprRequirement *Req); |
536 | concepts::NestedRequirement * |
537 | TransformNestedRequirement(concepts::NestedRequirement *Req); |
538 | |
539 | /// Transform the given template name. |
540 | /// |
541 | /// \param SS The nested-name-specifier that qualifies the template |
542 | /// name. This nested-name-specifier must already have been transformed. |
543 | /// |
544 | /// \param Name The template name to transform. |
545 | /// |
546 | /// \param NameLoc The source location of the template name. |
547 | /// |
548 | /// \param ObjectType If we're translating a template name within a member |
549 | /// access expression, this is the type of the object whose member template |
550 | /// is being referenced. |
551 | /// |
552 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
553 | /// also refers to a name within the current (lexical) scope, this is the |
554 | /// declaration it refers to. |
555 | /// |
556 | /// By default, transforms the template name by transforming the declarations |
557 | /// and nested-name-specifiers that occur within the template name. |
558 | /// Subclasses may override this function to provide alternate behavior. |
559 | TemplateName |
560 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, |
561 | SourceLocation NameLoc, |
562 | QualType ObjectType = QualType(), |
563 | NamedDecl *FirstQualifierInScope = nullptr, |
564 | bool AllowInjectedClassName = false); |
565 | |
566 | /// Transform the given template argument. |
567 | /// |
568 | /// By default, this operation transforms the type, expression, or |
569 | /// declaration stored within the template argument and constructs a |
570 | /// new template argument from the transformed result. Subclasses may |
571 | /// override this function to provide alternate behavior. |
572 | /// |
573 | /// Returns true if there was an error. |
574 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
575 | TemplateArgumentLoc &Output, |
576 | bool Uneval = false); |
577 | |
578 | /// Transform the given set of template arguments. |
579 | /// |
580 | /// By default, this operation transforms all of the template arguments |
581 | /// in the input set using \c TransformTemplateArgument(), and appends |
582 | /// the transformed arguments to the output list. |
583 | /// |
584 | /// Note that this overload of \c TransformTemplateArguments() is merely |
585 | /// a convenience function. Subclasses that wish to override this behavior |
586 | /// should override the iterator-based member template version. |
587 | /// |
588 | /// \param Inputs The set of template arguments to be transformed. |
589 | /// |
590 | /// \param NumInputs The number of template arguments in \p Inputs. |
591 | /// |
592 | /// \param Outputs The set of transformed template arguments output by this |
593 | /// routine. |
594 | /// |
595 | /// Returns true if an error occurred. |
596 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
597 | unsigned NumInputs, |
598 | TemplateArgumentListInfo &Outputs, |
599 | bool Uneval = false) { |
600 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs, |
601 | Uneval); |
602 | } |
603 | |
604 | /// Transform the given set of template arguments. |
605 | /// |
606 | /// By default, this operation transforms all of the template arguments |
607 | /// in the input set using \c TransformTemplateArgument(), and appends |
608 | /// the transformed arguments to the output list. |
609 | /// |
610 | /// \param First An iterator to the first template argument. |
611 | /// |
612 | /// \param Last An iterator one step past the last template argument. |
613 | /// |
614 | /// \param Outputs The set of transformed template arguments output by this |
615 | /// routine. |
616 | /// |
617 | /// Returns true if an error occurred. |
618 | template<typename InputIterator> |
619 | bool TransformTemplateArguments(InputIterator First, |
620 | InputIterator Last, |
621 | TemplateArgumentListInfo &Outputs, |
622 | bool Uneval = false); |
623 | |
624 | /// Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
625 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
626 | TemplateArgumentLoc &ArgLoc); |
627 | |
628 | /// Fakes up a TypeSourceInfo for a type. |
629 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
630 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
631 | getDerived().getBaseLocation()); |
632 | } |
633 | |
634 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
635 | #define TYPELOC(CLASS, PARENT) \ |
636 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
637 | #include "clang/AST/TypeLocNodes.def" |
638 | |
639 | template<typename Fn> |
640 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
641 | FunctionProtoTypeLoc TL, |
642 | CXXRecordDecl *ThisContext, |
643 | Qualifiers ThisTypeQuals, |
644 | Fn TransformExceptionSpec); |
645 | |
646 | bool TransformExceptionSpec(SourceLocation Loc, |
647 | FunctionProtoType::ExceptionSpecInfo &ESI, |
648 | SmallVectorImpl<QualType> &Exceptions, |
649 | bool &Changed); |
650 | |
651 | StmtResult TransformSEHHandler(Stmt *Handler); |
652 | |
653 | QualType |
654 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
655 | TemplateSpecializationTypeLoc TL, |
656 | TemplateName Template); |
657 | |
658 | QualType |
659 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
660 | DependentTemplateSpecializationTypeLoc TL, |
661 | TemplateName Template, |
662 | CXXScopeSpec &SS); |
663 | |
664 | QualType TransformDependentTemplateSpecializationType( |
665 | TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, |
666 | NestedNameSpecifierLoc QualifierLoc); |
667 | |
668 | /// Transforms the parameters of a function type into the |
669 | /// given vectors. |
670 | /// |
671 | /// The result vectors should be kept in sync; null entries in the |
672 | /// variables vector are acceptable. |
673 | /// |
674 | /// Return true on error. |
675 | bool TransformFunctionTypeParams( |
676 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
677 | const QualType *ParamTypes, |
678 | const FunctionProtoType::ExtParameterInfo *ParamInfos, |
679 | SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars, |
680 | Sema::ExtParameterInfoBuilder &PInfos); |
681 | |
682 | /// Transforms a single function-type parameter. Return null |
683 | /// on error. |
684 | /// |
685 | /// \param indexAdjustment - A number to add to the parameter's |
686 | /// scope index; can be negative |
687 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
688 | int indexAdjustment, |
689 | Optional<unsigned> NumExpansions, |
690 | bool ExpectParameterPack); |
691 | |
692 | /// Transform the body of a lambda-expression. |
693 | StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body); |
694 | /// Alternative implementation of TransformLambdaBody that skips transforming |
695 | /// the body. |
696 | StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body); |
697 | |
698 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
699 | |
700 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
701 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
702 | |
703 | TemplateParameterList *TransformTemplateParameterList( |
704 | TemplateParameterList *TPL) { |
705 | return TPL; |
706 | } |
707 | |
708 | ExprResult TransformAddressOfOperand(Expr *E); |
709 | |
710 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
711 | bool IsAddressOfOperand, |
712 | TypeSourceInfo **RecoveryTSI); |
713 | |
714 | ExprResult TransformParenDependentScopeDeclRefExpr( |
715 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, |
716 | TypeSourceInfo **RecoveryTSI); |
717 | |
718 | StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S); |
719 | |
720 | // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous |
721 | // amount of stack usage with clang. |
722 | #define STMT(Node, Parent) \ |
723 | LLVM_ATTRIBUTE_NOINLINE__attribute__((noinline)) \ |
724 | StmtResult Transform##Node(Node *S); |
725 | #define VALUESTMT(Node, Parent) \ |
726 | LLVM_ATTRIBUTE_NOINLINE__attribute__((noinline)) \ |
727 | StmtResult Transform##Node(Node *S, StmtDiscardKind SDK); |
728 | #define EXPR(Node, Parent) \ |
729 | LLVM_ATTRIBUTE_NOINLINE__attribute__((noinline)) \ |
730 | ExprResult Transform##Node(Node *E); |
731 | #define ABSTRACT_STMT(Stmt) |
732 | #include "clang/AST/StmtNodes.inc" |
733 | |
734 | #define GEN_CLANG_CLAUSE_CLASS |
735 | #define CLAUSE_CLASS(Enum, Str, Class) \ |
736 | LLVM_ATTRIBUTE_NOINLINE__attribute__((noinline)) \ |
737 | OMPClause *Transform##Class(Class *S); |
738 | #include "llvm/Frontend/OpenMP/OMP.inc" |
739 | |
740 | /// Build a new qualified type given its unqualified type and type location. |
741 | /// |
742 | /// By default, this routine adds type qualifiers only to types that can |
743 | /// have qualifiers, and silently suppresses those qualifiers that are not |
744 | /// permitted. Subclasses may override this routine to provide different |
745 | /// behavior. |
746 | QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL); |
747 | |
748 | /// Build a new pointer type given its pointee type. |
749 | /// |
750 | /// By default, performs semantic analysis when building the pointer type. |
751 | /// Subclasses may override this routine to provide different behavior. |
752 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
753 | |
754 | /// Build a new block pointer type given its pointee type. |
755 | /// |
756 | /// By default, performs semantic analysis when building the block pointer |
757 | /// type. Subclasses may override this routine to provide different behavior. |
758 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
759 | |
760 | /// Build a new reference type given the type it references. |
761 | /// |
762 | /// By default, performs semantic analysis when building the |
763 | /// reference type. Subclasses may override this routine to provide |
764 | /// different behavior. |
765 | /// |
766 | /// \param LValue whether the type was written with an lvalue sigil |
767 | /// or an rvalue sigil. |
768 | QualType RebuildReferenceType(QualType ReferentType, |
769 | bool LValue, |
770 | SourceLocation Sigil); |
771 | |
772 | /// Build a new member pointer type given the pointee type and the |
773 | /// class type it refers into. |
774 | /// |
775 | /// By default, performs semantic analysis when building the member pointer |
776 | /// type. Subclasses may override this routine to provide different behavior. |
777 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
778 | SourceLocation Sigil); |
779 | |
780 | QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, |
781 | SourceLocation ProtocolLAngleLoc, |
782 | ArrayRef<ObjCProtocolDecl *> Protocols, |
783 | ArrayRef<SourceLocation> ProtocolLocs, |
784 | SourceLocation ProtocolRAngleLoc); |
785 | |
786 | /// Build an Objective-C object type. |
787 | /// |
788 | /// By default, performs semantic analysis when building the object type. |
789 | /// Subclasses may override this routine to provide different behavior. |
790 | QualType RebuildObjCObjectType(QualType BaseType, |
791 | SourceLocation Loc, |
792 | SourceLocation TypeArgsLAngleLoc, |
793 | ArrayRef<TypeSourceInfo *> TypeArgs, |
794 | SourceLocation TypeArgsRAngleLoc, |
795 | SourceLocation ProtocolLAngleLoc, |
796 | ArrayRef<ObjCProtocolDecl *> Protocols, |
797 | ArrayRef<SourceLocation> ProtocolLocs, |
798 | SourceLocation ProtocolRAngleLoc); |
799 | |
800 | /// Build a new Objective-C object pointer type given the pointee type. |
801 | /// |
802 | /// By default, directly builds the pointer type, with no additional semantic |
803 | /// analysis. |
804 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
805 | SourceLocation Star); |
806 | |
807 | /// Build a new array type given the element type, size |
808 | /// modifier, size of the array (if known), size expression, and index type |
809 | /// qualifiers. |
810 | /// |
811 | /// By default, performs semantic analysis when building the array type. |
812 | /// Subclasses may override this routine to provide different behavior. |
813 | /// Also by default, all of the other Rebuild*Array |
814 | QualType RebuildArrayType(QualType ElementType, |
815 | ArrayType::ArraySizeModifier SizeMod, |
816 | const llvm::APInt *Size, |
817 | Expr *SizeExpr, |
818 | unsigned IndexTypeQuals, |
819 | SourceRange BracketsRange); |
820 | |
821 | /// Build a new constant array type given the element type, size |
822 | /// modifier, (known) size of the array, and index type qualifiers. |
823 | /// |
824 | /// By default, performs semantic analysis when building the array type. |
825 | /// Subclasses may override this routine to provide different behavior. |
826 | QualType RebuildConstantArrayType(QualType ElementType, |
827 | ArrayType::ArraySizeModifier SizeMod, |
828 | const llvm::APInt &Size, |
829 | Expr *SizeExpr, |
830 | unsigned IndexTypeQuals, |
831 | SourceRange BracketsRange); |
832 | |
833 | /// Build a new incomplete array type given the element type, size |
834 | /// modifier, and index type qualifiers. |
835 | /// |
836 | /// By default, performs semantic analysis when building the array type. |
837 | /// Subclasses may override this routine to provide different behavior. |
838 | QualType RebuildIncompleteArrayType(QualType ElementType, |
839 | ArrayType::ArraySizeModifier SizeMod, |
840 | unsigned IndexTypeQuals, |
841 | SourceRange BracketsRange); |
842 | |
843 | /// Build a new variable-length array type given the element type, |
844 | /// size modifier, size expression, and index type qualifiers. |
845 | /// |
846 | /// By default, performs semantic analysis when building the array type. |
847 | /// Subclasses may override this routine to provide different behavior. |
848 | QualType RebuildVariableArrayType(QualType ElementType, |
849 | ArrayType::ArraySizeModifier SizeMod, |
850 | Expr *SizeExpr, |
851 | unsigned IndexTypeQuals, |
852 | SourceRange BracketsRange); |
853 | |
854 | /// Build a new dependent-sized array type given the element type, |
855 | /// size modifier, size expression, and index type qualifiers. |
856 | /// |
857 | /// By default, performs semantic analysis when building the array type. |
858 | /// Subclasses may override this routine to provide different behavior. |
859 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
860 | ArrayType::ArraySizeModifier SizeMod, |
861 | Expr *SizeExpr, |
862 | unsigned IndexTypeQuals, |
863 | SourceRange BracketsRange); |
864 | |
865 | /// Build a new vector type given the element type and |
866 | /// number of elements. |
867 | /// |
868 | /// By default, performs semantic analysis when building the vector type. |
869 | /// Subclasses may override this routine to provide different behavior. |
870 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
871 | VectorType::VectorKind VecKind); |
872 | |
873 | /// Build a new potentially dependently-sized extended vector type |
874 | /// given the element type and number of elements. |
875 | /// |
876 | /// By default, performs semantic analysis when building the vector type. |
877 | /// Subclasses may override this routine to provide different behavior. |
878 | QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr, |
879 | SourceLocation AttributeLoc, |
880 | VectorType::VectorKind); |
881 | |
882 | /// Build a new extended vector type given the element type and |
883 | /// number of elements. |
884 | /// |
885 | /// By default, performs semantic analysis when building the vector type. |
886 | /// Subclasses may override this routine to provide different behavior. |
887 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
888 | SourceLocation AttributeLoc); |
889 | |
890 | /// Build a new potentially dependently-sized extended vector type |
891 | /// given the element type and number of elements. |
892 | /// |
893 | /// By default, performs semantic analysis when building the vector type. |
894 | /// Subclasses may override this routine to provide different behavior. |
895 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
896 | Expr *SizeExpr, |
897 | SourceLocation AttributeLoc); |
898 | |
899 | /// Build a new matrix type given the element type and dimensions. |
900 | QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows, |
901 | unsigned NumColumns); |
902 | |
903 | /// Build a new matrix type given the type and dependently-defined |
904 | /// dimensions. |
905 | QualType RebuildDependentSizedMatrixType(QualType ElementType, Expr *RowExpr, |
906 | Expr *ColumnExpr, |
907 | SourceLocation AttributeLoc); |
908 | |
909 | /// Build a new DependentAddressSpaceType or return the pointee |
910 | /// type variable with the correct address space (retrieved from |
911 | /// AddrSpaceExpr) applied to it. The former will be returned in cases |
912 | /// where the address space remains dependent. |
913 | /// |
914 | /// By default, performs semantic analysis when building the type with address |
915 | /// space applied. Subclasses may override this routine to provide different |
916 | /// behavior. |
917 | QualType RebuildDependentAddressSpaceType(QualType PointeeType, |
918 | Expr *AddrSpaceExpr, |
919 | SourceLocation AttributeLoc); |
920 | |
921 | /// Build a new function type. |
922 | /// |
923 | /// By default, performs semantic analysis when building the function type. |
924 | /// Subclasses may override this routine to provide different behavior. |
925 | QualType RebuildFunctionProtoType(QualType T, |
926 | MutableArrayRef<QualType> ParamTypes, |
927 | const FunctionProtoType::ExtProtoInfo &EPI); |
928 | |
929 | /// Build a new unprototyped function type. |
930 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
931 | |
932 | /// Rebuild an unresolved typename type, given the decl that |
933 | /// the UnresolvedUsingTypenameDecl was transformed to. |
934 | QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D); |
935 | |
936 | /// Build a new typedef type. |
937 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
938 | return SemaRef.Context.getTypeDeclType(Typedef); |
939 | } |
940 | |
941 | /// Build a new MacroDefined type. |
942 | QualType RebuildMacroQualifiedType(QualType T, |
943 | const IdentifierInfo *MacroII) { |
944 | return SemaRef.Context.getMacroQualifiedType(T, MacroII); |
945 | } |
946 | |
947 | /// Build a new class/struct/union type. |
948 | QualType RebuildRecordType(RecordDecl *Record) { |
949 | return SemaRef.Context.getTypeDeclType(Record); |
950 | } |
951 | |
952 | /// Build a new Enum type. |
953 | QualType RebuildEnumType(EnumDecl *Enum) { |
954 | return SemaRef.Context.getTypeDeclType(Enum); |
955 | } |
956 | |
957 | /// Build a new typeof(expr) type. |
958 | /// |
959 | /// By default, performs semantic analysis when building the typeof type. |
960 | /// Subclasses may override this routine to provide different behavior. |
961 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
962 | |
963 | /// Build a new typeof(type) type. |
964 | /// |
965 | /// By default, builds a new TypeOfType with the given underlying type. |
966 | QualType RebuildTypeOfType(QualType Underlying); |
967 | |
968 | /// Build a new unary transform type. |
969 | QualType RebuildUnaryTransformType(QualType BaseType, |
970 | UnaryTransformType::UTTKind UKind, |
971 | SourceLocation Loc); |
972 | |
973 | /// Build a new C++11 decltype type. |
974 | /// |
975 | /// By default, performs semantic analysis when building the decltype type. |
976 | /// Subclasses may override this routine to provide different behavior. |
977 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
978 | |
979 | /// Build a new C++11 auto type. |
980 | /// |
981 | /// By default, builds a new AutoType with the given deduced type. |
982 | QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword, |
983 | ConceptDecl *TypeConstraintConcept, |
984 | ArrayRef<TemplateArgument> TypeConstraintArgs) { |
985 | // Note, IsDependent is always false here: we implicitly convert an 'auto' |
986 | // which has been deduced to a dependent type into an undeduced 'auto', so |
987 | // that we'll retry deduction after the transformation. |
988 | return SemaRef.Context.getAutoType(Deduced, Keyword, |
989 | /*IsDependent*/ false, /*IsPack=*/false, |
990 | TypeConstraintConcept, |
991 | TypeConstraintArgs); |
992 | } |
993 | |
994 | /// By default, builds a new DeducedTemplateSpecializationType with the given |
995 | /// deduced type. |
996 | QualType RebuildDeducedTemplateSpecializationType(TemplateName Template, |
997 | QualType Deduced) { |
998 | return SemaRef.Context.getDeducedTemplateSpecializationType( |
999 | Template, Deduced, /*IsDependent*/ false); |
1000 | } |
1001 | |
1002 | /// Build a new template specialization type. |
1003 | /// |
1004 | /// By default, performs semantic analysis when building the template |
1005 | /// specialization type. Subclasses may override this routine to provide |
1006 | /// different behavior. |
1007 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
1008 | SourceLocation TemplateLoc, |
1009 | TemplateArgumentListInfo &Args); |
1010 | |
1011 | /// Build a new parenthesized type. |
1012 | /// |
1013 | /// By default, builds a new ParenType type from the inner type. |
1014 | /// Subclasses may override this routine to provide different behavior. |
1015 | QualType RebuildParenType(QualType InnerType) { |
1016 | return SemaRef.BuildParenType(InnerType); |
1017 | } |
1018 | |
1019 | /// Build a new qualified name type. |
1020 | /// |
1021 | /// By default, builds a new ElaboratedType type from the keyword, |
1022 | /// the nested-name-specifier and the named type. |
1023 | /// Subclasses may override this routine to provide different behavior. |
1024 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
1025 | ElaboratedTypeKeyword Keyword, |
1026 | NestedNameSpecifierLoc QualifierLoc, |
1027 | QualType Named) { |
1028 | return SemaRef.Context.getElaboratedType(Keyword, |
1029 | QualifierLoc.getNestedNameSpecifier(), |
1030 | Named); |
1031 | } |
1032 | |
1033 | /// Build a new typename type that refers to a template-id. |
1034 | /// |
1035 | /// By default, builds a new DependentNameType type from the |
1036 | /// nested-name-specifier and the given type. Subclasses may override |
1037 | /// this routine to provide different behavior. |
1038 | QualType RebuildDependentTemplateSpecializationType( |
1039 | ElaboratedTypeKeyword Keyword, |
1040 | NestedNameSpecifierLoc QualifierLoc, |
1041 | SourceLocation TemplateKWLoc, |
1042 | const IdentifierInfo *Name, |
1043 | SourceLocation NameLoc, |
1044 | TemplateArgumentListInfo &Args, |
1045 | bool AllowInjectedClassName) { |
1046 | // Rebuild the template name. |
1047 | // TODO: avoid TemplateName abstraction |
1048 | CXXScopeSpec SS; |
1049 | SS.Adopt(QualifierLoc); |
1050 | TemplateName InstName = getDerived().RebuildTemplateName( |
1051 | SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr, |
1052 | AllowInjectedClassName); |
1053 | |
1054 | if (InstName.isNull()) |
1055 | return QualType(); |
1056 | |
1057 | // If it's still dependent, make a dependent specialization. |
1058 | if (InstName.getAsDependentTemplateName()) |
1059 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
1060 | QualifierLoc.getNestedNameSpecifier(), |
1061 | Name, |
1062 | Args); |
1063 | |
1064 | // Otherwise, make an elaborated type wrapping a non-dependent |
1065 | // specialization. |
1066 | QualType T = |
1067 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
1068 | if (T.isNull()) return QualType(); |
1069 | |
1070 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr) |
1071 | return T; |
1072 | |
1073 | return SemaRef.Context.getElaboratedType(Keyword, |
1074 | QualifierLoc.getNestedNameSpecifier(), |
1075 | T); |
1076 | } |
1077 | |
1078 | /// Build a new typename type that refers to an identifier. |
1079 | /// |
1080 | /// By default, performs semantic analysis when building the typename type |
1081 | /// (or elaborated type). Subclasses may override this routine to provide |
1082 | /// different behavior. |
1083 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
1084 | SourceLocation KeywordLoc, |
1085 | NestedNameSpecifierLoc QualifierLoc, |
1086 | const IdentifierInfo *Id, |
1087 | SourceLocation IdLoc, |
1088 | bool DeducedTSTContext) { |
1089 | CXXScopeSpec SS; |
1090 | SS.Adopt(QualifierLoc); |
1091 | |
1092 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
1093 | // If the name is still dependent, just build a new dependent name type. |
1094 | if (!SemaRef.computeDeclContext(SS)) |
1095 | return SemaRef.Context.getDependentNameType(Keyword, |
1096 | QualifierLoc.getNestedNameSpecifier(), |
1097 | Id); |
1098 | } |
1099 | |
1100 | if (Keyword == ETK_None || Keyword == ETK_Typename) { |
1101 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
1102 | *Id, IdLoc, DeducedTSTContext); |
1103 | } |
1104 | |
1105 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
1106 | |
1107 | // We had a dependent elaborated-type-specifier that has been transformed |
1108 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
1109 | // referring to. |
1110 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
1111 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
1112 | if (!DC) |
1113 | return QualType(); |
1114 | |
1115 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
1116 | return QualType(); |
1117 | |
1118 | TagDecl *Tag = nullptr; |
1119 | SemaRef.LookupQualifiedName(Result, DC); |
1120 | switch (Result.getResultKind()) { |
1121 | case LookupResult::NotFound: |
1122 | case LookupResult::NotFoundInCurrentInstantiation: |
1123 | break; |
1124 | |
1125 | case LookupResult::Found: |
1126 | Tag = Result.getAsSingle<TagDecl>(); |
1127 | break; |
1128 | |
1129 | case LookupResult::FoundOverloaded: |
1130 | case LookupResult::FoundUnresolvedValue: |
1131 | llvm_unreachable("Tag lookup cannot find non-tags")::llvm::llvm_unreachable_internal("Tag lookup cannot find non-tags" , "/build/llvm-toolchain-snapshot-12~++20210115100614+a14c36fe27f5/clang/lib/Sema/TreeTransform.h" , 1131); |
1132 | |
1133 | case LookupResult::Ambiguous: |
1134 | // Let the LookupResult structure handle ambiguities. |
1135 | return QualType(); |
1136 | } |
1137 | |
1138 | if (!Tag) { |
1139 | // Check where the name exists but isn't a tag type and use that to emit |
1140 | // better diagnostics. |
1141 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
1142 | SemaRef.LookupQualifiedName(Result, DC); |
1143 | switch (Result.getResultKind()) { |
1144 | case LookupResult::Found: |
1145 | case LookupResult::FoundOverloaded: |
1146 | case LookupResult::FoundUnresolvedValue: { |
1147 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
1148 | Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind); |
1149 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl |
1150 | << NTK << Kind; |
1151 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
1152 | break; |
1153 | } |
1154 | default: |
1155 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
1156 | << Kind << Id << DC << QualifierLoc.getSourceRange(); |
1157 | break; |
1158 | } |
1159 | return QualType(); |
1160 | } |
1161 | |
1162 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
1163 | IdLoc, Id)) { |
1164 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
1165 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
1166 | return QualType(); |
1167 | } |
1168 | |
1169 | // Build the elaborated-type-specifier type. |
1170 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
1171 | return SemaRef.Context.getElaboratedType(Keyword, |
1172 | QualifierLoc.getNestedNameSpecifier(), |
1173 | T); |
1174 | } |
1175 | |
1176 | /// Build a new pack expansion type. |
1177 | /// |
1178 | /// By default, builds a new PackExpansionType type from the given pattern. |
1179 | /// Subclasses may override this routine to provide different behavior. |
1180 | QualType RebuildPackExpansionType(QualType Pattern, |
1181 | SourceRange PatternRange, |
1182 | SourceLocation EllipsisLoc, |
1183 | Optional<unsigned> NumExpansions) { |
1184 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
1185 | NumExpansions); |
1186 | } |
1187 | |
1188 | /// Build a new atomic type given its value type. |
1189 | /// |
1190 | /// By default, performs semantic analysis when building the atomic type. |
1191 | /// Subclasses may override this routine to provide different behavior. |
1192 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
1193 | |
1194 | /// Build a new pipe type given its value type. |
1195 | QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc, |
1196 | bool isReadPipe); |
1197 | |
1198 | /// Build an extended int given its value type. |
1199 | QualType RebuildExtIntType(bool IsUnsigned, unsigned NumBits, |
1200 | SourceLocation Loc); |
1201 | |
1202 | /// Build a dependent extended int given its value type. |
1203 | QualType RebuildDependentExtIntType(bool IsUnsigned, Expr *NumBitsExpr, |
1204 | SourceLocation Loc); |
1205 | |
1206 | /// Build a new template name given a nested name specifier, a flag |
1207 | /// indicating whether the "template" keyword was provided, and the template |
1208 | /// that the template name refers to. |
1209 | /// |
1210 | /// By default, builds the new template name directly. Subclasses may override |
1211 | /// this routine to provide different behavior. |
1212 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
1213 | bool TemplateKW, |
1214 | TemplateDecl *Template); |
1215 | |
1216 | /// Build a new template name given a nested name specifier and the |
1217 | /// name that is referred to as a template. |
1218 | /// |
1219 | /// By default, performs semantic analysis to determine whether the name can |
1220 | /// be resolved to a specific template, then builds the appropriate kind of |
1221 | /// template name. Subclasses may override this routine to provide different |
1222 | /// behavior. |
1223 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
1224 | SourceLocation TemplateKWLoc, |
1225 | const IdentifierInfo &Name, |
1226 | SourceLocation NameLoc, QualType ObjectType, |
1227 | NamedDecl *FirstQualifierInScope, |
1228 | bool AllowInjectedClassName); |
1229 | |
1230 | /// Build a new template name given a nested name specifier and the |
1231 | /// overloaded operator name that is referred to as a template. |
1232 | /// |
1233 | /// By default, performs semantic analysis to determine whether the name can |
1234 | /// be resolved to a specific template, then builds the appropriate kind of |
1235 | /// template name. Subclasses may override this routine to provide different |
1236 | /// behavior. |
1237 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
1238 | SourceLocation TemplateKWLoc, |
1239 | OverloadedOperatorKind Operator, |
1240 | SourceLocation NameLoc, QualType ObjectType, |
1241 | bool AllowInjectedClassName); |
1242 | |
1243 | /// Build a new template name given a template template parameter pack |
1244 | /// and the |
1245 | /// |
1246 | /// By default, performs semantic analysis to determine whether the name can |
1247 | /// be resolved to a specific template, then builds the appropriate kind of |
1248 | /// template name. Subclasses may override this routine to provide different |
1249 | /// behavior. |
1250 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
1251 | const TemplateArgument &ArgPack) { |
1252 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
1253 | } |
1254 | |
1255 | /// Build a new compound statement. |
1256 | /// |
1257 | /// By default, performs semantic analysis to build the new statement. |
1258 | /// Subclasses may override this routine to provide different behavior. |
1259 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
1260 | MultiStmtArg Statements, |
1261 | SourceLocation RBraceLoc, |
1262 | bool IsStmtExpr) { |
1263 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
1264 | IsStmtExpr); |
1265 | } |
1266 | |
1267 | /// Build a new case statement. |
1268 | /// |
1269 | /// By default, performs semantic analysis to build the new statement. |
1270 | /// Subclasses may override this routine to provide different behavior. |
1271 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
1272 | Expr *LHS, |
1273 | SourceLocation EllipsisLoc, |
1274 | Expr *RHS, |
1275 | SourceLocation ColonLoc) { |
1276 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
1277 | ColonLoc); |
1278 | } |
1279 | |
1280 | /// Attach the body to a new case statement. |
1281 | /// |
1282 | /// By default, performs semantic analysis to build the new statement. |
1283 | /// Subclasses may override this routine to provide different behavior. |
1284 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
1285 | getSema().ActOnCaseStmtBody(S, Body); |
1286 | return S; |
1287 | } |
1288 | |
1289 | /// Build a new default statement. |
1290 | /// |
1291 | /// By default, performs semantic analysis to build the new statement. |
1292 | /// Subclasses may override this routine to provide different behavior. |
1293 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
1294 | SourceLocation ColonLoc, |
1295 | Stmt *SubStmt) { |
1296 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
1297 | /*CurScope=*/nullptr); |
1298 | } |
1299 | |
1300 | /// Build a new label statement. |
1301 | /// |
1302 | /// By default, performs semantic analysis to build the new statement. |
1303 | /// Subclasses may override this routine to provide different behavior. |
1304 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
1305 | SourceLocation ColonLoc, Stmt *SubStmt) { |
1306 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
1307 | } |
1308 | |
1309 | /// Build a new attributed statement. |
1310 | /// |
1311 | /// By default, performs semantic analysis to build the new statement. |
1312 | /// Subclasses may override this routine to provide different behavior. |
1313 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
1314 | ArrayRef<const Attr*> Attrs, |
1315 | Stmt *SubStmt) { |
1316 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
1317 | } |
1318 | |
1319 | /// Build a new "if" statement. |
1320 | /// |
1321 | /// By default, performs semantic analysis to build the new statement. |
1322 | /// Subclasses may override this routine to provide different behavior. |
1323 | StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr, |
1324 | SourceLocation LParenLoc, Sema::ConditionResult Cond, |
1325 | SourceLocation RParenLoc, Stmt *Init, Stmt *Then, |
1326 | SourceLocation ElseLoc, Stmt *Else) { |
1327 | return getSema().ActOnIfStmt(IfLoc, IsConstexpr, LParenLoc, Init, Cond, |
1328 | RParenLoc, Then, ElseLoc, Else); |
1329 | } |
1330 | |
1331 | /// Start building a new switch statement. |
1332 | /// |
1333 | /// By default, performs semantic analysis to build the new statement. |
1334 | /// Subclasses may override this routine to provide different behavior. |
1335 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
1336 | SourceLocation LParenLoc, Stmt *Init, |
1337 | Sema::ConditionResult Cond, |
1338 | SourceLocation RParenLoc) { |
1339 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond, |
1340 | RParenLoc); |
1341 | } |
1342 | |
1343 | /// Attach the body to the switch statement. |
1344 | /// |
1345 | /// By default, performs semantic analysis to build the new statement. |
1346 | /// Subclasses may override this routine to provide different behavior. |
1347 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
1348 | Stmt *Switch, Stmt *Body) { |
1349 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
1350 | } |
1351 | |
1352 | /// Build a new while statement. |
1353 | /// |
1354 | /// By default, performs semantic analysis to build the new statement. |
1355 | /// Subclasses may override this routine to provide different behavior. |
1356 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, |
1357 | Sema::ConditionResult Cond, |
1358 | SourceLocation RParenLoc, Stmt *Body) { |
1359 | return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body); |
1360 | } |
1361 | |
1362 | /// Build a new do-while statement. |
1363 | /// |
1364 | /// By default, performs semantic analysis to build the new statement. |
1365 | /// Subclasses may override this routine to provide different behavior. |
1366 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
1367 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
1368 | Expr *Cond, SourceLocation RParenLoc) { |
1369 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
1370 | Cond, RParenLoc); |
1371 | } |
1372 | |
1373 | /// Build a new for statement. |
1374 | /// |
1375 | /// By default, performs semantic analysis to build the new statement. |
1376 | /// Subclasses may override this routine to provide different behavior. |
1377 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
1378 | Stmt *Init, Sema::ConditionResult Cond, |
1379 | Sema::FullExprArg Inc, SourceLocation RParenLoc, |
1380 | Stmt *Body) { |
1381 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
1382 | Inc, RParenLoc, Body); |
1383 | } |
1384 | |
1385 | /// Build a new goto statement. |
1386 | /// |
1387 | /// By default, performs semantic analysis to build the new statement. |
1388 | /// Subclasses may override this routine to provide different behavior. |
1389 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
1390 | LabelDecl *Label) { |
1391 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
1392 | } |
1393 | |
1394 | /// Build a new indirect goto statement. |
1395 | /// |
1396 | /// By default, performs semantic analysis to build the new statement. |
1397 | /// Subclasses may override this routine to provide different behavior. |
1398 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
1399 | SourceLocation StarLoc, |
1400 | Expr *Target) { |
1401 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
1402 | } |
1403 | |
1404 | /// Build a new return statement. |
1405 | /// |
1406 | /// By default, performs semantic analysis to build the new statement. |
1407 | /// Subclasses may override this routine to provide different behavior. |
1408 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
1409 | return getSema().BuildReturnStmt(ReturnLoc, Result); |
1410 | } |
1411 | |
1412 | /// Build a new declaration statement. |
1413 | /// |
1414 | /// By default, performs semantic analysis to build the new statement. |
1415 | /// Subclasses may override this routine to provide different behavior. |
1416 | StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls, |
1417 | SourceLocation StartLoc, SourceLocation EndLoc) { |
1418 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); |
1419 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
1420 | } |
1421 | |
1422 | /// Build a new inline asm statement. |
1423 | /// |
1424 | /// By default, performs semantic analysis to build the new statement. |
1425 | /// Subclasses may override this routine to provide different behavior. |
1426 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
1427 | bool IsVolatile, unsigned NumOutputs, |
1428 | unsigned NumInputs, IdentifierInfo **Names, |
1429 | MultiExprArg Constraints, MultiExprArg Exprs, |
1430 | Expr *AsmString, MultiExprArg Clobbers, |
1431 | unsigned NumLabels, |
1432 | SourceLocation RParenLoc) { |
1433 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
1434 | NumInputs, Names, Constraints, Exprs, |
1435 | AsmString, Clobbers, NumLabels, RParenLoc); |
1436 | } |
1437 | |
1438 | /// Build a new MS style inline asm statement. |
1439 | /// |
1440 | /// By default, performs semantic analysis to build the new statement. |
1441 | /// Subclasses may override this routine to provide different behavior. |
1442 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
1443 | ArrayRef<Token> AsmToks, |
1444 | StringRef AsmString, |
1445 | unsigned NumOutputs, unsigned NumInputs, |
1446 | ArrayRef<StringRef> Constraints, |
1447 | ArrayRef<StringRef> Clobbers, |
1448 | ArrayRef<Expr*> Exprs, |
1449 | SourceLocation EndLoc) { |
1450 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, |
1451 | NumOutputs, NumInputs, |
1452 | Constraints, Clobbers, Exprs, EndLoc); |
1453 | } |
1454 | |
1455 | /// Build a new co_return statement. |
1456 | /// |
1457 | /// By default, performs semantic analysis to build the new statement. |
1458 | /// Subclasses may override this routine to provide different behavior. |
1459 | StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result, |
1460 | bool IsImplicit) { |
1461 | return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit); |
1462 | } |
1463 | |
1464 | /// Build a new co_await expression. |
1465 | /// |
1466 | /// By default, performs semantic analysis to build the new expression. |
1467 | /// Subclasses may override this routine to provide different behavior. |
1468 | ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result, |
1469 | bool IsImplicit) { |
1470 | return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit); |
1471 | } |
1472 | |
1473 | /// Build a new co_await expression. |
1474 | /// |
1475 | /// By default, performs semantic analysis to build the new expression. |
1476 | /// Subclasses may override this routine to provide different behavior. |
1477 | ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc, |
1478 | Expr *Result, |
1479 | UnresolvedLookupExpr *Lookup) { |
1480 | return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup); |
1481 | } |
1482 | |
1483 | /// Build a new co_yield expression. |
1484 | /// |
1485 | /// By default, performs semantic analysis to build the new expression. |
1486 | /// Subclasses may override this routine to provide different behavior. |
1487 | ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) { |
1488 | return getSema().BuildCoyieldExpr(CoyieldLoc, Result); |
1489 | } |
1490 | |
1491 | StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) { |
1492 | return getSema().BuildCoroutineBodyStmt(Args); |
1493 | } |
1494 | |
1495 | /// Build a new Objective-C \@try statement. |
1496 | /// |
1497 | /// By default, performs semantic analysis to build the new statement. |
1498 | /// Subclasses may override this routine to provide different behavior. |
1499 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
1500 | Stmt *TryBody, |
1501 | MultiStmtArg CatchStmts, |
1502 | Stmt *Finally) { |
1503 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
1504 | Finally); |
1505 | } |
1506 | |
1507 | /// Rebuild an Objective-C exception declaration. |
1508 | /// |
1509 | /// By default, performs semantic analysis to build the new declaration. |
1510 | /// Subclasses may override this routine to provide different behavior. |
1511 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
1512 | TypeSourceInfo *TInfo, QualType T) { |
1513 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
1514 | ExceptionDecl->getInnerLocStart(), |
1515 | ExceptionDecl->getLocation(), |
1516 | ExceptionDecl->getIdentifier()); |
1517 | } |
1518 | |
1519 | /// Build a new Objective-C \@catch statement. |
1520 | /// |
1521 | /// By default, performs semantic analysis to build the new statement. |
1522 | /// Subclasses may override this routine to provide different behavior. |
1523 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
1524 | SourceLocation RParenLoc, |
1525 | VarDecl *Var, |
1526 | Stmt *Body) { |
1527 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
1528 | Var, Body); |
1529 | } |
1530 | |
1531 | /// Build a new Objective-C \@finally statement. |
1532 | /// |
1533 | /// By default, performs semantic analysis to build the new statement. |
1534 | /// Subclasses may override this routine to provide different behavior. |
1535 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
1536 | Stmt *Body) { |
1537 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
1538 | } |
1539 | |
1540 | /// Build a new Objective-C \@throw statement. |
1541 | /// |
1542 | /// By default, performs semantic analysis to build the new statement. |
1543 | /// Subclasses may override this routine to provide different behavior. |
1544 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
1545 | Expr *Operand) { |
1546 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
1547 | } |
1548 | |
1549 | /// Build a new OpenMP executable directive. |
1550 | /// |
1551 | /// By default, performs semantic analysis to build the new statement. |
1552 | /// Subclasses may override this routine to provide different behavior. |
1553 | StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, |
1554 | DeclarationNameInfo DirName, |
1555 | OpenMPDirectiveKind CancelRegion, |
1556 | ArrayRef<OMPClause *> Clauses, |
1557 | Stmt *AStmt, SourceLocation StartLoc, |
1558 | SourceLocation EndLoc) { |
1559 | return getSema().ActOnOpenMPExecutableDirective( |
1560 | Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc); |
1561 | } |
1562 | |
1563 | /// Build a new OpenMP 'if' clause. |
1564 | /// |
1565 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1566 | /// Subclasses may override this routine to provide different behavior. |
1567 | OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, |
1568 | Expr *Condition, SourceLocation StartLoc, |
1569 | SourceLocation LParenLoc, |
1570 | SourceLocation NameModifierLoc, |
1571 | SourceLocation ColonLoc, |
1572 | SourceLocation EndLoc) { |
1573 | return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc, |
1574 | LParenLoc, NameModifierLoc, ColonLoc, |
1575 | EndLoc); |
1576 | } |
1577 | |
1578 | /// Build a new OpenMP 'final' clause. |
1579 | /// |
1580 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1581 | /// Subclasses may override this routine to provide different behavior. |
1582 | OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
1583 | SourceLocation LParenLoc, |
1584 | SourceLocation EndLoc) { |
1585 | return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc, |
1586 | EndLoc); |
1587 | } |
1588 | |
1589 | /// Build a new OpenMP 'num_threads' clause. |
1590 | /// |
1591 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1592 | /// Subclasses may override this routine to provide different behavior. |
1593 | OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads, |
1594 | SourceLocation StartLoc, |
1595 | SourceLocation LParenLoc, |
1596 | SourceLocation EndLoc) { |
1597 | return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc, |
1598 | LParenLoc, EndLoc); |
1599 | } |
1600 | |
1601 | /// Build a new OpenMP 'safelen' clause. |
1602 | /// |
1603 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1604 | /// Subclasses may override this routine to provide different behavior. |
1605 | OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
1606 | SourceLocation LParenLoc, |
1607 | SourceLocation EndLoc) { |
1608 | return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc); |
1609 | } |
1610 | |
1611 | /// Build a new OpenMP 'simdlen' clause. |
1612 | /// |
1613 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1614 | /// Subclasses may override this routine to provide different behavior. |
1615 | OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
1616 | SourceLocation LParenLoc, |
1617 | SourceLocation EndLoc) { |
1618 | return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc); |
1619 | } |
1620 | |
1621 | /// Build a new OpenMP 'allocator' clause. |
1622 | /// |
1623 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1624 | /// Subclasses may override this routine to provide different behavior. |
1625 | OMPClause *RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc, |
1626 | SourceLocation LParenLoc, |
1627 | SourceLocation EndLoc) { |
1628 | return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc); |
1629 | } |
1630 | |
1631 | /// Build a new OpenMP 'collapse' clause. |
1632 | /// |
1633 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1634 | /// Subclasses may override this routine to provide different behavior. |
1635 | OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, |
1636 | SourceLocation LParenLoc, |
1637 | SourceLocation EndLoc) { |
1638 | return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc, |
1639 | EndLoc); |
1640 | } |
1641 | |
1642 | /// Build a new OpenMP 'default' clause. |
1643 | /// |
1644 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1645 | /// Subclasses may override this routine to provide different behavior. |
1646 | OMPClause *RebuildOMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc, |
1647 | SourceLocation StartLoc, |
1648 | SourceLocation LParenLoc, |
1649 | SourceLocation EndLoc) { |
1650 | return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, |
1651 | StartLoc, LParenLoc, EndLoc); |
1652 | } |
1653 | |
1654 | /// Build a new OpenMP 'proc_bind' clause. |
1655 | /// |
1656 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1657 | /// Subclasses may override this routine to provide different behavior. |
1658 | OMPClause *RebuildOMPProcBindClause(ProcBindKind Kind, |
1659 | SourceLocation KindKwLoc, |
1660 | SourceLocation StartLoc, |
1661 | SourceLocation LParenLoc, |
1662 | SourceLocation EndLoc) { |
1663 | return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc, |
1664 | StartLoc, LParenLoc, EndLoc); |
1665 | } |
1666 | |
1667 | /// Build a new OpenMP 'schedule' clause. |
1668 | /// |
1669 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1670 | /// Subclasses may override this routine to provide different behavior. |
1671 | OMPClause *RebuildOMPScheduleClause( |
1672 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
1673 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
1674 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
1675 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
1676 | return getSema().ActOnOpenMPScheduleClause( |
1677 | M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc, |
1678 | CommaLoc, EndLoc); |
1679 | } |
1680 | |
1681 | /// Build a new OpenMP 'ordered' clause. |
1682 | /// |
1683 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1684 | /// Subclasses may override this routine to provide different behavior. |
1685 | OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc, |
1686 | SourceLocation EndLoc, |
1687 | SourceLocation LParenLoc, Expr *Num) { |
1688 | return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num); |
1689 | } |
1690 | |
1691 | /// Build a new OpenMP 'private' clause. |
1692 | /// |
1693 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1694 | /// Subclasses may override this routine to provide different behavior. |
1695 | OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, |
1696 | SourceLocation StartLoc, |
1697 | SourceLocation LParenLoc, |
1698 | SourceLocation EndLoc) { |
1699 | return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, |
1700 | EndLoc); |
1701 | } |
1702 | |
1703 | /// Build a new OpenMP 'firstprivate' clause. |
1704 | /// |
1705 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1706 | /// Subclasses may override this routine to provide different behavior. |
1707 | OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList, |
1708 | SourceLocation StartLoc, |
1709 | SourceLocation LParenLoc, |
1710 | SourceLocation EndLoc) { |
1711 | return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, |
1712 | EndLoc); |
1713 | } |
1714 | |
1715 | /// Build a new OpenMP 'lastprivate' clause. |
1716 | /// |
1717 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1718 | /// Subclasses may override this routine to provide different behavior. |
1719 | OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList, |
1720 | OpenMPLastprivateModifier LPKind, |
1721 | SourceLocation LPKindLoc, |
1722 | SourceLocation ColonLoc, |
1723 | SourceLocation StartLoc, |
1724 | SourceLocation LParenLoc, |
1725 | SourceLocation EndLoc) { |
1726 | return getSema().ActOnOpenMPLastprivateClause( |
1727 | VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc); |
1728 | } |
1729 | |
1730 | /// Build a new OpenMP 'shared' clause. |
1731 | /// |
1732 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1733 | /// Subclasses may override this routine to provide different behavior. |
1734 | OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList, |
1735 | SourceLocation StartLoc, |
1736 | SourceLocation LParenLoc, |
1737 | SourceLocation EndLoc) { |
1738 | return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, |
1739 | EndLoc); |
1740 | } |
1741 | |
1742 | /// Build a new OpenMP 'reduction' clause. |
1743 | /// |
1744 | /// By default, performs semantic analysis to build the new statement. |
1745 | /// Subclasses may override this routine to provide different behavior. |
1746 | OMPClause *RebuildOMPReductionClause( |
1747 | ArrayRef<Expr *> VarList, OpenMPReductionClauseModifier Modifier, |
1748 | SourceLocation StartLoc, SourceLocation LParenLoc, |
1749 | SourceLocation ModifierLoc, SourceLocation ColonLoc, |
1750 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
1751 | const DeclarationNameInfo &ReductionId, |
1752 | ArrayRef<Expr *> UnresolvedReductions) { |
1753 | return getSema().ActOnOpenMPReductionClause( |
1754 | VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc, |
1755 | ReductionIdScopeSpec, ReductionId, UnresolvedReductions); |
1756 | } |
1757 | |
1758 | /// Build a new OpenMP 'task_reduction' clause. |
1759 | /// |
1760 | /// By default, performs semantic analysis to build the new statement. |
1761 | /// Subclasses may override this routine to provide different behavior. |
1762 | OMPClause *RebuildOMPTaskReductionClause( |
1763 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
1764 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
1765 | CXXScopeSpec &ReductionIdScopeSpec, |
1766 | const DeclarationNameInfo &ReductionId, |
1767 | ArrayRef<Expr *> UnresolvedReductions) { |
1768 | return getSema().ActOnOpenMPTaskReductionClause( |
1769 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
1770 | ReductionId, UnresolvedReductions); |
1771 | } |
1772 | |
1773 | /// Build a new OpenMP 'in_reduction' clause. |
1774 | /// |
1775 | /// By default, performs semantic analysis to build the new statement. |
1776 | /// Subclasses may override this routine to provide different behavior. |
1777 | OMPClause * |
1778 | RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
1779 | SourceLocation LParenLoc, SourceLocation ColonLoc, |
1780 | SourceLocation EndLoc, |
1781 | CXXScopeSpec &ReductionIdScopeSpec, |
1782 | const DeclarationNameInfo &ReductionId, |
1783 | ArrayRef<Expr *> UnresolvedReductions) { |
1784 | return getSema().ActOnOpenMPInReductionClause( |
1785 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
1786 | ReductionId, UnresolvedReductions); |
1787 | } |
1788 | |
1789 | /// Build a new OpenMP 'linear' clause. |
1790 | /// |
1791 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1792 | /// Subclasses may override this routine to provide different behavior. |
1793 | OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
1794 | SourceLocation StartLoc, |
1795 | SourceLocation LParenLoc, |
1796 | OpenMPLinearClauseKind Modifier, |
1797 | SourceLocation ModifierLoc, |
1798 | SourceLocation ColonLoc, |
1799 | SourceLocation EndLoc) { |
1800 | return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc, |
1801 | Modifier, ModifierLoc, ColonLoc, |
1802 | EndLoc); |
1803 | } |
1804 | |
1805 | /// Build a new OpenMP 'aligned' clause. |
1806 | /// |
1807 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1808 | /// Subclasses may override this routine to provide different behavior. |
1809 | OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment, |
1810 | SourceLocation StartLoc, |
1811 | SourceLocation LParenLoc, |
1812 | SourceLocation ColonLoc, |
1813 | SourceLocation EndLoc) { |
1814 | return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc, |
1815 | LParenLoc, ColonLoc, EndLoc); |
1816 | } |
1817 | |
1818 | /// Build a new OpenMP 'copyin' clause. |
1819 | /// |
1820 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1821 | /// Subclasses may override this routine to provide different behavior. |
1822 | OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList, |
1823 | SourceLocation StartLoc, |
1824 | SourceLocation LParenLoc, |
1825 | SourceLocation EndLoc) { |
1826 | return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, |
1827 | EndLoc); |
1828 | } |
1829 | |
1830 | /// Build a new OpenMP 'copyprivate' clause. |
1831 | /// |
1832 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1833 | /// Subclasses may override this routine to provide different behavior. |
1834 | OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList, |
1835 | SourceLocation StartLoc, |
1836 | SourceLocation LParenLoc, |
1837 | SourceLocation EndLoc) { |
1838 | return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, |
1839 | EndLoc); |
1840 | } |
1841 | |
1842 | /// Build a new OpenMP 'flush' pseudo clause. |
1843 | /// |
1844 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1845 | /// Subclasses may override this routine to provide different behavior. |
1846 | OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList, |
1847 | SourceLocation StartLoc, |
1848 | SourceLocation LParenLoc, |
1849 | SourceLocation EndLoc) { |
1850 | return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, |
1851 | EndLoc); |
1852 | } |
1853 | |
1854 | /// Build a new OpenMP 'depobj' pseudo clause. |
1855 | /// |
1856 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1857 | /// Subclasses may override this routine to provide different behavior. |
1858 | OMPClause *RebuildOMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, |
1859 | SourceLocation LParenLoc, |
1860 | SourceLocation EndLoc) { |
1861 | return getSema().ActOnOpenMPDepobjClause(Depobj, StartLoc, LParenLoc, |
1862 | EndLoc); |
1863 | } |
1864 | |
1865 | /// Build a new OpenMP 'depend' pseudo clause. |
1866 | /// |
1867 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1868 | /// Subclasses may override this routine to provide different behavior. |
1869 | OMPClause * |
1870 | RebuildOMPDependClause(Expr *DepModifier, OpenMPDependClauseKind DepKind, |
1871 | SourceLocation DepLoc, SourceLocation ColonLoc, |
1872 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
1873 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
1874 | return getSema().ActOnOpenMPDependClause(DepModifier, DepKind, DepLoc, |
1875 | ColonLoc, VarList, StartLoc, |
1876 | LParenLoc, EndLoc); |
1877 | } |
1878 | |
1879 | /// Build a new OpenMP 'device' clause. |
1880 | /// |
1881 | /// By default, performs semantic analysis to build the new statement. |
1882 | /// Subclasses may override this routine to provide different behavior. |
1883 | OMPClause *RebuildOMPDeviceClause(OpenMPDeviceClauseModifier Modifier, |
1884 | Expr *Device, SourceLocation StartLoc, |
1885 | SourceLocation LParenLoc, |
1886 | SourceLocation ModifierLoc, |
1887 | SourceLocation EndLoc) { |
1888 | return getSema().ActOnOpenMPDeviceClause(Modifier, Device, StartLoc, |
1889 | LParenLoc, ModifierLoc, EndLoc); |
1890 | } |
1891 | |
1892 | /// Build a new OpenMP 'map' clause. |
1893 | /// |
1894 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1895 | /// Subclasses may override this routine to provide different behavior. |
1896 | OMPClause *RebuildOMPMapClause( |
1897 | ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
1898 | ArrayRef<SourceLocation> MapTypeModifiersLoc, |
1899 | CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId, |
1900 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
1901 | SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
1902 | const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) { |
1903 | return getSema().ActOnOpenMPMapClause(MapTypeModifiers, MapTypeModifiersLoc, |
1904 | MapperIdScopeSpec, MapperId, MapType, |
1905 | IsMapTypeImplicit, MapLoc, ColonLoc, |
1906 | VarList, Locs, UnresolvedMappers); |
1907 | } |
1908 | |
1909 | /// Build a new OpenMP 'allocate' clause. |
1910 | /// |
1911 | /// By default, performs semantic analysis to build the new OpenMP clause. |
1912 | /// Subclasses may override this routine to provide different behavior. |
1913 | OMPClause *RebuildOMPAllocateClause(Expr *Allocate, ArrayRef<Expr *> VarList, |
1914 | SourceLocation StartLoc, |
1915 | SourceLocation LParenLoc, |
1916 | SourceLocation ColonLoc, |
1917 | SourceLocation EndLoc) { |
1918 | return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc, |
1919 | LParenLoc, ColonLoc, EndLoc); |
1920 | } |
1921 | |
1922 | /// Build a new OpenMP 'num_teams' clause. |
1923 | /// |
1924 | /// By default, performs semantic analysis to build the new statement. |
1925 | /// Subclasses may override this routine to provide different behavior. |
1926 | OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, |
1927 | SourceLocation LParenLoc, |
1928 | SourceLocation EndLoc) { |
1929 | return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc, |
1930 | EndLoc); |
1931 | } |
1932 | |
1933 | /// Build a new OpenMP 'thread_limit' clause. |
1934 | /// |
1935 | /// By default, performs semantic analysis to build the new statement. |
1936 | /// Subclasses may override this routine to provide different behavior. |
1937 | OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit, |
1938 | SourceLocation StartLoc, |
1939 | SourceLocation LParenLoc, |
1940 | SourceLocation EndLoc) { |
1941 | return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc, |
1942 | LParenLoc, EndLoc); |
1943 | } |
1944 | |
1945 | /// Build a new OpenMP 'priority' clause. |
1946 | /// |
1947 | /// By default, performs semantic analysis to build the new statement. |
1948 | /// Subclasses may override this routine to provide different behavior. |
1949 | OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, |
1950 | SourceLocation LParenLoc, |
1951 | SourceLocation EndLoc) { |
1952 | return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc, |
1953 | EndLoc); |
1954 | } |
1955 | |
1956 | /// Build a new OpenMP 'grainsize' clause. |
1957 | /// |
1958 | /// By default, performs semantic analysis to build the new statement. |
1959 | /// Subclasses may override this routine to provide different behavior. |
1960 | OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc, |
1961 | SourceLocation LParenLoc, |
1962 | SourceLocation EndLoc) { |
1963 | return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc, |
1964 | EndLoc); |
1965 | } |
1966 | |
1967 | /// Build a new OpenMP 'num_tasks' clause. |
1968 | /// |
1969 | /// By default, performs semantic analysis to build the new statement. |
1970 | /// Subclasses may override this routine to provide different behavior. |
1971 | OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc, |
1972 | SourceLocation LParenLoc, |
1973 | SourceLocation EndLoc) { |
1974 | return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc, |
1975 | EndLoc); |
1976 | } |
1977 | |
1978 | /// Build a new OpenMP 'hint' clause. |
1979 | /// |
1980 | /// By default, performs semantic analysis to build the new statement. |
1981 | /// Subclasses may override this routine to provide different behavior. |
1982 | OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, |
1983 | SourceLocation LParenLoc, |
1984 | SourceLocation EndLoc) { |
1985 | return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc); |
1986 | } |
1987 | |
1988 | /// Build a new OpenMP 'detach' clause. |
1989 | /// |
1990 | /// By default, performs semantic analysis to build the new statement. |
1991 | /// Subclasses may override this routine to provide different behavior. |
1992 | OMPClause *RebuildOMPDetachClause(Expr *Evt, SourceLocation StartLoc, |
1993 | SourceLocation LParenLoc, |
1994 | SourceLocation EndLoc) { |
1995 | return getSema().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc, EndLoc); |
1996 | } |
1997 | |
1998 | /// Build a new OpenMP 'dist_schedule' clause. |
1999 | /// |
2000 | /// By default, performs semantic analysis to build the new OpenMP clause. |
2001 | /// Subclasses may override this routine to provide different behavior. |
2002 | OMPClause * |
2003 | RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, |
2004 | Expr *ChunkSize, SourceLocation StartLoc, |
2005 | SourceLocation LParenLoc, SourceLocation KindLoc, |
2006 | SourceLocation CommaLoc, SourceLocation EndLoc) { |
2007 | return getSema().ActOnOpenMPDistScheduleClause( |
2008 | Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc); |
2009 | } |
2010 | |
2011 | /// Build a new OpenMP 'to' clause. |
2012 | /// |
2013 | /// By default, performs semantic analysis to build the new statement. |
2014 | /// Subclasses may override this routine to provide different behavior. |
2015 | OMPClause * |
2016 | RebuildOMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
2017 | ArrayRef<SourceLocation> MotionModifiersLoc, |
2018 | CXXScopeSpec &MapperIdScopeSpec, |
2019 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
2020 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
2021 | ArrayRef<Expr *> UnresolvedMappers) { |
2022 | return getSema().ActOnOpenMPToClause(MotionModifiers, MotionModifiersLoc, |
2023 | MapperIdScopeSpec, MapperId, ColonLoc, |
2024 | VarList, Locs, UnresolvedMappers); |
2025 | } |
2026 | |
2027 | /// Build a new OpenMP 'from' clause. |
2028 | /// |
2029 | /// By default, performs semantic analysis to build the new statement. |
2030 | /// Subclasses may override this routine to provide different behavior. |
2031 | OMPClause * |
2032 | RebuildOMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
2033 | ArrayRef<SourceLocation> MotionModifiersLoc, |
2034 | CXXScopeSpec &MapperIdScopeSpec, |
2035 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
2036 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
2037 | ArrayRef<Expr *> UnresolvedMappers) { |
2038 | return getSema().ActOnOpenMPFromClause( |
2039 | MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId, |
2040 | ColonLoc, VarList, Locs, UnresolvedMappers); |
2041 | } |
2042 | |
2043 | /// Build a new OpenMP 'use_device_ptr' clause. |
2044 | /// |
2045 | /// By default, performs semantic analysis to build the new OpenMP clause. |
2046 | /// Subclasses may override this routine to provide different behavior. |
2047 | OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
2048 | const OMPVarListLocTy &Locs) { |
2049 | return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs); |
2050 | } |
2051 | |
2052 | /// Build a new OpenMP 'use_device_addr' clause. |
2053 | /// |
2054 | /// By default, performs semantic analysis to build the new OpenMP clause. |
2055 | /// Subclasses may override this routine to provide different behavior. |
2056 | OMPClause *RebuildOMPUseDeviceAddrClause(ArrayRef<Expr *> VarList, |
2057 | const OMPVarListLocTy &Locs) { |
2058 | return getSema().ActOnOpenMPUseDeviceAddrClause(VarList, Locs); |
2059 | } |
2060 | |
2061 | /// Build a new OpenMP 'is_device_ptr' clause. |
2062 | /// |
2063 | /// By default, performs semantic analysis to build the new OpenMP clause. |
2064 | /// Subclasses may override this routine to provide different behavior. |
2065 | OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
2066 | const OMPVarListLocTy &Locs) { |
2067 | return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs); |
2068 | } |
2069 | |
2070 | /// Build a new OpenMP 'defaultmap' clause. |
2071 | /// |
2072 | /// By default, performs semantic analysis to build the new OpenMP clause. |
2073 | /// Subclasses may override this routine to provide different behavior. |
2074 | OMPClause *RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, |
2075 | OpenMPDefaultmapClauseKind Kind, |
2076 | SourceLocation StartLoc, |
2077 | SourceLocation LParenLoc, |
2078 | SourceLocation MLoc, |
2079 | SourceLocation KindLoc, |
2080 | SourceLocation EndLoc) { |
2081 | return getSema().ActOnOpenMPDefaultmapClause(M, Kind, StartLoc, LParenLoc, |
2082 | MLoc, KindLoc, EndLoc); |
2083 | } |
2084 | |
2085 | /// Build a new OpenMP 'nontemporal' clause. |
2086 | /// |
2087 | /// By default, performs semantic analysis to build the new OpenMP clause. |
2088 | /// Subclasses may override this routine to provide different behavior. |
2089 | OMPClause *RebuildOMPNontemporalClause(ArrayRef<Expr *> VarList, |
2090 | SourceLocation StartLoc, |
2091 | SourceLocation LParenLoc, |
2092 | SourceLocation EndLoc) { |
2093 | return getSema().ActOnOpenMPNontemporalClause(VarList, StartLoc, LParenLoc, |
2094 | EndLoc); |
2095 | } |
2096 | |
2097 | /// Build a new OpenMP 'inclusive' clause. |
2098 | /// |
2099 | /// By default, performs semantic analysis to build the new OpenMP clause. |
2100 | /// Subclasses may override this routine to provide different behavior. |
2101 | OMPClause *RebuildOMPInclusiveClause(ArrayRef<Expr *> VarList, |
2102 | SourceLocation StartLoc, |
2103 | SourceLocation LParenLoc, |
2104 | SourceLocation EndLoc) { |
2105 | return getSema().ActOnOpenMPInclusiveClause(VarList, StartLoc, LParenLoc, |
2106 | EndLoc); |
2107 | } |
2108 | |
2109 | /// Build a new OpenMP 'exclusive' clause. |
2110 | /// |
2111 | /// By default, performs semantic analysis to build the new OpenMP clause. |
2112 | /// Subclasses may override this routine to provide different behavior. |
2113 | OMPClause *RebuildOMPExclusiveClause(ArrayRef<Expr *> VarList, |
2114 | SourceLocation StartLoc, |
2115 | SourceLocation LParenLoc, |
2116 | SourceLocation EndLoc) { |
2117 | return getSema().ActOnOpenMPExclusiveClause(VarList, StartLoc, LParenLoc, |
2118 | EndLoc); |
2119 | } |
2120 | |
2121 | /// Build a new OpenMP 'uses_allocators' clause. |
2122 | /// |
2123 | /// By default, performs semantic analysis to build the new OpenMP clause. |
2124 | /// Subclasses may override this routine to provide different behavior. |
2125 | OMPClause *RebuildOMPUsesAllocatorsClause( |
2126 | ArrayRef<Sema::UsesAllocatorsData> Data, SourceLocation StartLoc, |
2127 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
2128 | return getSema().ActOnOpenMPUsesAllocatorClause(StartLoc, LParenLoc, EndLoc, |
2129 | Data); |
2130 | } |
2131 | |
2132 | /// Build a new OpenMP 'affinity' clause. |
2133 | /// |
2134 | /// By default, performs semantic analysis to build the new OpenMP clause. |
2135 | /// Subclasses may override this routine to provide different behavior. |
2136 | OMPClause *RebuildOMPAffinityClause(SourceLocation StartLoc, |
2137 | SourceLocation LParenLoc, |
2138 | SourceLocation ColonLoc, |
2139 | SourceLocation EndLoc, Expr *Modifier, |
2140 | ArrayRef<Expr *> Locators) { |
2141 | return getSema().ActOnOpenMPAffinityClause(StartLoc, LParenLoc, ColonLoc, |
2142 | EndLoc, Modifier, Locators); |
2143 | } |
2144 | |
2145 | /// Build a new OpenMP 'order' clause. |
2146 | /// |
2147 | /// By default, performs semantic analysis to build the new OpenMP clause. |
2148 | /// Subclasses may override this routine to provide different behavior. |
2149 | OMPClause *RebuildOMPOrderClause(OpenMPOrderClauseKind Kind, |
2150 | SourceLocation KindKwLoc, |
2151 | SourceLocation StartLoc, |
2152 | SourceLocation LParenLoc, |
2153 | SourceLocation EndLoc) { |
2154 | return getSema().ActOnOpenMPOrderClause(Kind, KindKwLoc, StartLoc, |
2155 | LParenLoc, EndLoc); |
2156 | } |
2157 | |
2158 | /// Rebuild the operand to an Objective-C \@synchronized statement. |
2159 | /// |
2160 | /// By default, performs semantic analysis to build the new statement. |
2161 | /// Subclasses may override this routine to provide different behavior. |
2162 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
2163 | Expr *object) { |
2164 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
2165 | } |
2166 | |
2167 | /// Build a new Objective-C \@synchronized statement. |
2168 | /// |
2169 | /// By default, performs semantic analysis to build the new statement. |
2170 | /// Subclasses may override this routine to provide different behavior. |
2171 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |