File: | clang/lib/Sema/SemaTemplateInstantiate.cpp |
Warning: | line 2803, column 41 Called C++ object pointer is null |
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~++20200927111121+5811d723998/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~++20200927111121+5811d723998/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 (const TemplateArgumentList *TemplateArgs | ||||
145 | = Function->getTemplateSpecializationArgs()) { | ||||
146 | // Add the template arguments for this specialization. | ||||
147 | Result.addOuterTemplateArguments(TemplateArgs); | ||||
148 | |||||
149 | // If this function was instantiated from a specialized member that is | ||||
150 | // a function template, we're done. | ||||
151 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 151, __PRETTY_FUNCTION__)); | ||||
152 | if (Function->getPrimaryTemplate()->isMemberSpecialization()) | ||||
153 | break; | ||||
154 | |||||
155 | // If this function is a generic lambda specialization, we are done. | ||||
156 | if (isGenericLambdaCallOperatorOrStaticInvokerSpecialization(Function)) | ||||
157 | break; | ||||
158 | |||||
159 | } else if (FunctionTemplateDecl *FunTmpl | ||||
160 | = Function->getDescribedFunctionTemplate()) { | ||||
161 | // Add the "injected" template arguments. | ||||
162 | Result.addOuterTemplateArguments(FunTmpl->getInjectedTemplateArgs()); | ||||
163 | } | ||||
164 | |||||
165 | // If this is a friend declaration and it declares an entity at | ||||
166 | // namespace scope, take arguments from its lexical parent | ||||
167 | // instead of its semantic parent, unless of course the pattern we're | ||||
168 | // instantiating actually comes from the file's context! | ||||
169 | if (Function->getFriendObjectKind() && | ||||
170 | Function->getDeclContext()->isFileContext() && | ||||
171 | (!Pattern || !Pattern->getLexicalDeclContext()->isFileContext())) { | ||||
172 | Ctx = Function->getLexicalDeclContext(); | ||||
173 | RelativeToPrimary = false; | ||||
174 | continue; | ||||
175 | } | ||||
176 | } else if (CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Ctx)) { | ||||
177 | if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) { | ||||
178 | QualType T = ClassTemplate->getInjectedClassNameSpecialization(); | ||||
179 | const TemplateSpecializationType *TST = | ||||
180 | cast<TemplateSpecializationType>(Context.getCanonicalType(T)); | ||||
181 | Result.addOuterTemplateArguments( | ||||
182 | llvm::makeArrayRef(TST->getArgs(), TST->getNumArgs())); | ||||
183 | if (ClassTemplate->isMemberSpecialization()) | ||||
184 | break; | ||||
185 | } | ||||
186 | } | ||||
187 | |||||
188 | Ctx = Ctx->getParent(); | ||||
189 | RelativeToPrimary = false; | ||||
190 | } | ||||
191 | |||||
192 | return Result; | ||||
193 | } | ||||
194 | |||||
195 | bool Sema::CodeSynthesisContext::isInstantiationRecord() const { | ||||
196 | switch (Kind) { | ||||
197 | case TemplateInstantiation: | ||||
198 | case ExceptionSpecInstantiation: | ||||
199 | case DefaultTemplateArgumentInstantiation: | ||||
200 | case DefaultFunctionArgumentInstantiation: | ||||
201 | case ExplicitTemplateArgumentSubstitution: | ||||
202 | case DeducedTemplateArgumentSubstitution: | ||||
203 | case PriorTemplateArgumentSubstitution: | ||||
204 | case ConstraintsCheck: | ||||
205 | case NestedRequirementConstraintsCheck: | ||||
206 | return true; | ||||
207 | |||||
208 | case RequirementInstantiation: | ||||
209 | case DefaultTemplateArgumentChecking: | ||||
210 | case DeclaringSpecialMember: | ||||
211 | case DeclaringImplicitEqualityComparison: | ||||
212 | case DefiningSynthesizedFunction: | ||||
213 | case ExceptionSpecEvaluation: | ||||
214 | case ConstraintSubstitution: | ||||
215 | case ParameterMappingSubstitution: | ||||
216 | case ConstraintNormalization: | ||||
217 | case RewritingOperatorAsSpaceship: | ||||
218 | case InitializingStructuredBinding: | ||||
219 | case MarkingClassDllexported: | ||||
220 | return false; | ||||
221 | |||||
222 | // This function should never be called when Kind's value is Memoization. | ||||
223 | case Memoization: | ||||
224 | break; | ||||
225 | } | ||||
226 | |||||
227 | llvm_unreachable("Invalid SynthesisKind!")::llvm::llvm_unreachable_internal("Invalid SynthesisKind!", "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 227); | ||||
228 | } | ||||
229 | |||||
230 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
231 | Sema &SemaRef, CodeSynthesisContext::SynthesisKind Kind, | ||||
232 | SourceLocation PointOfInstantiation, SourceRange InstantiationRange, | ||||
233 | Decl *Entity, NamedDecl *Template, ArrayRef<TemplateArgument> TemplateArgs, | ||||
234 | sema::TemplateDeductionInfo *DeductionInfo) | ||||
235 | : SemaRef(SemaRef) { | ||||
236 | // Don't allow further instantiation if a fatal error and an uncompilable | ||||
237 | // error have occurred. Any diagnostics we might have raised will not be | ||||
238 | // visible, and we do not need to construct a correct AST. | ||||
239 | if (SemaRef.Diags.hasFatalErrorOccurred() && | ||||
240 | SemaRef.Diags.hasUncompilableErrorOccurred()) { | ||||
241 | Invalid = true; | ||||
242 | return; | ||||
243 | } | ||||
244 | Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange); | ||||
245 | if (!Invalid
| ||||
246 | CodeSynthesisContext Inst; | ||||
247 | Inst.Kind = Kind; | ||||
248 | Inst.PointOfInstantiation = PointOfInstantiation; | ||||
249 | Inst.Entity = Entity; | ||||
250 | Inst.Template = Template; | ||||
251 | Inst.TemplateArgs = TemplateArgs.data(); | ||||
252 | Inst.NumTemplateArgs = TemplateArgs.size(); | ||||
253 | Inst.DeductionInfo = DeductionInfo; | ||||
254 | Inst.InstantiationRange = InstantiationRange; | ||||
255 | SemaRef.pushCodeSynthesisContext(Inst); | ||||
256 | |||||
257 | AlreadyInstantiating = !Inst.Entity
| ||||
258 | !SemaRef.InstantiatingSpecializations | ||||
259 | .insert(std::make_pair(Inst.Entity->getCanonicalDecl(), Inst.Kind)) | ||||
260 | .second; | ||||
261 | atTemplateBegin(SemaRef.TemplateInstCallbacks, SemaRef, Inst); | ||||
262 | } | ||||
263 | } | ||||
264 | |||||
265 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
266 | Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity, | ||||
267 | SourceRange InstantiationRange) | ||||
268 | : InstantiatingTemplate(SemaRef, | ||||
269 | CodeSynthesisContext::TemplateInstantiation, | ||||
270 | PointOfInstantiation, InstantiationRange, Entity) {} | ||||
271 | |||||
272 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
273 | Sema &SemaRef, SourceLocation PointOfInstantiation, FunctionDecl *Entity, | ||||
274 | ExceptionSpecification, SourceRange InstantiationRange) | ||||
275 | : InstantiatingTemplate( | ||||
276 | SemaRef, CodeSynthesisContext::ExceptionSpecInstantiation, | ||||
277 | PointOfInstantiation, InstantiationRange, Entity) {} | ||||
278 | |||||
279 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
280 | Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateParameter Param, | ||||
281 | TemplateDecl *Template, ArrayRef<TemplateArgument> TemplateArgs, | ||||
282 | SourceRange InstantiationRange) | ||||
283 | : InstantiatingTemplate( | ||||
284 | SemaRef, | ||||
285 | CodeSynthesisContext::DefaultTemplateArgumentInstantiation, | ||||
286 | PointOfInstantiation, InstantiationRange, getAsNamedDecl(Param), | ||||
287 | Template, TemplateArgs) {} | ||||
288 | |||||
289 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
290 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
291 | FunctionTemplateDecl *FunctionTemplate, | ||||
292 | ArrayRef<TemplateArgument> TemplateArgs, | ||||
293 | CodeSynthesisContext::SynthesisKind Kind, | ||||
294 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||
295 | : InstantiatingTemplate(SemaRef, Kind, PointOfInstantiation, | ||||
296 | InstantiationRange, FunctionTemplate, nullptr, | ||||
297 | TemplateArgs, &DeductionInfo) { | ||||
298 | assert(((Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution ) ? static_cast<void> (0) : __assert_fail ("Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 300, __PRETTY_FUNCTION__)) | ||||
299 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 300, __PRETTY_FUNCTION__)) | ||||
300 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 300, __PRETTY_FUNCTION__)); | ||||
301 | } | ||||
302 | |||||
303 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
304 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
305 | TemplateDecl *Template, | ||||
306 | ArrayRef<TemplateArgument> TemplateArgs, | ||||
307 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||
308 | : InstantiatingTemplate( | ||||
309 | SemaRef, | ||||
310 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | ||||
311 | PointOfInstantiation, InstantiationRange, Template, nullptr, | ||||
312 | TemplateArgs, &DeductionInfo) {} | ||||
313 | |||||
314 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
315 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
316 | ClassTemplatePartialSpecializationDecl *PartialSpec, | ||||
317 | ArrayRef<TemplateArgument> TemplateArgs, | ||||
318 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||
319 | : InstantiatingTemplate( | ||||
320 | SemaRef, | ||||
321 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | ||||
322 | PointOfInstantiation, InstantiationRange, PartialSpec, nullptr, | ||||
323 | TemplateArgs, &DeductionInfo) {} | ||||
324 | |||||
325 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
326 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
327 | VarTemplatePartialSpecializationDecl *PartialSpec, | ||||
328 | ArrayRef<TemplateArgument> TemplateArgs, | ||||
329 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||
330 | : InstantiatingTemplate( | ||||
331 | SemaRef, | ||||
332 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | ||||
333 | PointOfInstantiation, InstantiationRange, PartialSpec, nullptr, | ||||
334 | TemplateArgs, &DeductionInfo) {} | ||||
335 | |||||
336 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
337 | Sema &SemaRef, SourceLocation PointOfInstantiation, ParmVarDecl *Param, | ||||
338 | ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange) | ||||
339 | : InstantiatingTemplate( | ||||
340 | SemaRef, | ||||
341 | CodeSynthesisContext::DefaultFunctionArgumentInstantiation, | ||||
342 | PointOfInstantiation, InstantiationRange, Param, nullptr, | ||||
343 | TemplateArgs) {} | ||||
344 | |||||
345 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
346 | Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template, | ||||
347 | NonTypeTemplateParmDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | ||||
348 | SourceRange InstantiationRange) | ||||
349 | : InstantiatingTemplate( | ||||
350 | SemaRef, | ||||
351 | CodeSynthesisContext::PriorTemplateArgumentSubstitution, | ||||
352 | PointOfInstantiation, InstantiationRange, Param, Template, | ||||
353 | TemplateArgs) {} | ||||
354 | |||||
355 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
356 | Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template, | ||||
357 | TemplateTemplateParmDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | ||||
358 | SourceRange InstantiationRange) | ||||
359 | : InstantiatingTemplate( | ||||
360 | SemaRef, | ||||
361 | CodeSynthesisContext::PriorTemplateArgumentSubstitution, | ||||
362 | PointOfInstantiation, InstantiationRange, Param, Template, | ||||
363 | TemplateArgs) {} | ||||
364 | |||||
365 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
366 | Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateDecl *Template, | ||||
367 | NamedDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | ||||
368 | SourceRange InstantiationRange) | ||||
369 | : InstantiatingTemplate( | ||||
370 | SemaRef, CodeSynthesisContext::DefaultTemplateArgumentChecking, | ||||
371 | PointOfInstantiation, InstantiationRange, Param, Template, | ||||
372 | TemplateArgs) {} | ||||
373 | |||||
374 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
375 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
376 | concepts::Requirement *Req, sema::TemplateDeductionInfo &DeductionInfo, | ||||
377 | SourceRange InstantiationRange) | ||||
378 | : InstantiatingTemplate( | ||||
379 | SemaRef, CodeSynthesisContext::RequirementInstantiation, | ||||
380 | PointOfInstantiation, InstantiationRange, /*Entity=*/nullptr, | ||||
381 | /*Template=*/nullptr, /*TemplateArgs=*/None, &DeductionInfo) {} | ||||
382 | |||||
383 | |||||
384 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
385 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
386 | concepts::NestedRequirement *Req, ConstraintsCheck, | ||||
387 | SourceRange InstantiationRange) | ||||
388 | : InstantiatingTemplate( | ||||
389 | SemaRef, CodeSynthesisContext::NestedRequirementConstraintsCheck, | ||||
390 | PointOfInstantiation, InstantiationRange, /*Entity=*/nullptr, | ||||
391 | /*Template=*/nullptr, /*TemplateArgs=*/None) {} | ||||
392 | |||||
393 | |||||
394 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
395 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
396 | ConstraintsCheck, NamedDecl *Template, | ||||
397 | ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange) | ||||
398 | : InstantiatingTemplate( | ||||
399 | SemaRef, CodeSynthesisContext::ConstraintsCheck, | ||||
400 | PointOfInstantiation, InstantiationRange, Template, nullptr, | ||||
401 | TemplateArgs) {} | ||||
402 | |||||
403 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
404 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
405 | ConstraintSubstitution, NamedDecl *Template, | ||||
406 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||
407 | : InstantiatingTemplate( | ||||
408 | SemaRef, CodeSynthesisContext::ConstraintSubstitution, | ||||
409 | PointOfInstantiation, InstantiationRange, Template, nullptr, | ||||
410 | {}, &DeductionInfo) {} | ||||
411 | |||||
412 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
413 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
414 | ConstraintNormalization, NamedDecl *Template, | ||||
415 | SourceRange InstantiationRange) | ||||
416 | : InstantiatingTemplate( | ||||
417 | SemaRef, CodeSynthesisContext::ConstraintNormalization, | ||||
418 | PointOfInstantiation, InstantiationRange, Template) {} | ||||
419 | |||||
420 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
421 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
422 | ParameterMappingSubstitution, NamedDecl *Template, | ||||
423 | SourceRange InstantiationRange) | ||||
424 | : InstantiatingTemplate( | ||||
425 | SemaRef, CodeSynthesisContext::ParameterMappingSubstitution, | ||||
426 | PointOfInstantiation, InstantiationRange, Template) {} | ||||
427 | |||||
428 | void Sema::pushCodeSynthesisContext(CodeSynthesisContext Ctx) { | ||||
429 | Ctx.SavedInNonInstantiationSFINAEContext = InNonInstantiationSFINAEContext; | ||||
430 | InNonInstantiationSFINAEContext = false; | ||||
431 | |||||
432 | CodeSynthesisContexts.push_back(Ctx); | ||||
433 | |||||
434 | if (!Ctx.isInstantiationRecord()) | ||||
435 | ++NonInstantiationEntries; | ||||
436 | |||||
437 | // Check to see if we're low on stack space. We can't do anything about this | ||||
438 | // from here, but we can at least warn the user. | ||||
439 | if (isStackNearlyExhausted()) | ||||
440 | warnStackExhausted(Ctx.PointOfInstantiation); | ||||
441 | } | ||||
442 | |||||
443 | void Sema::popCodeSynthesisContext() { | ||||
444 | auto &Active = CodeSynthesisContexts.back(); | ||||
445 | if (!Active.isInstantiationRecord()) { | ||||
446 | assert(NonInstantiationEntries > 0)((NonInstantiationEntries > 0) ? static_cast<void> ( 0) : __assert_fail ("NonInstantiationEntries > 0", "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 446, __PRETTY_FUNCTION__)); | ||||
447 | --NonInstantiationEntries; | ||||
448 | } | ||||
449 | |||||
450 | InNonInstantiationSFINAEContext = Active.SavedInNonInstantiationSFINAEContext; | ||||
451 | |||||
452 | // Name lookup no longer looks in this template's defining module. | ||||
453 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 455, __PRETTY_FUNCTION__)) | ||||
454 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 455, __PRETTY_FUNCTION__)) | ||||
455 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 455, __PRETTY_FUNCTION__)); | ||||
456 | if (CodeSynthesisContexts.size() == | ||||
457 | CodeSynthesisContextLookupModules.size()) { | ||||
458 | if (Module *M = CodeSynthesisContextLookupModules.back()) | ||||
459 | LookupModulesCache.erase(M); | ||||
460 | CodeSynthesisContextLookupModules.pop_back(); | ||||
461 | } | ||||
462 | |||||
463 | // If we've left the code synthesis context for the current context stack, | ||||
464 | // stop remembering that we've emitted that stack. | ||||
465 | if (CodeSynthesisContexts.size() == | ||||
466 | LastEmittedCodeSynthesisContextDepth) | ||||
467 | LastEmittedCodeSynthesisContextDepth = 0; | ||||
468 | |||||
469 | CodeSynthesisContexts.pop_back(); | ||||
470 | } | ||||
471 | |||||
472 | void Sema::InstantiatingTemplate::Clear() { | ||||
473 | if (!Invalid) { | ||||
474 | if (!AlreadyInstantiating) { | ||||
475 | auto &Active = SemaRef.CodeSynthesisContexts.back(); | ||||
476 | if (Active.Entity) | ||||
477 | SemaRef.InstantiatingSpecializations.erase( | ||||
478 | std::make_pair(Active.Entity, Active.Kind)); | ||||
479 | } | ||||
480 | |||||
481 | atTemplateEnd(SemaRef.TemplateInstCallbacks, SemaRef, | ||||
482 | SemaRef.CodeSynthesisContexts.back()); | ||||
483 | |||||
484 | SemaRef.popCodeSynthesisContext(); | ||||
485 | Invalid = true; | ||||
486 | } | ||||
487 | } | ||||
488 | |||||
489 | bool Sema::InstantiatingTemplate::CheckInstantiationDepth( | ||||
490 | SourceLocation PointOfInstantiation, | ||||
491 | SourceRange InstantiationRange) { | ||||
492 | assert(SemaRef.NonInstantiationEntries <=((SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts .size()) ? static_cast<void> (0) : __assert_fail ("SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts.size()" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 493, __PRETTY_FUNCTION__)) | ||||
493 | SemaRef.CodeSynthesisContexts.size())((SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts .size()) ? static_cast<void> (0) : __assert_fail ("SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts.size()" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 493, __PRETTY_FUNCTION__)); | ||||
494 | if ((SemaRef.CodeSynthesisContexts.size() - | ||||
495 | SemaRef.NonInstantiationEntries) | ||||
496 | <= SemaRef.getLangOpts().InstantiationDepth) | ||||
497 | return false; | ||||
498 | |||||
499 | SemaRef.Diag(PointOfInstantiation, | ||||
500 | diag::err_template_recursion_depth_exceeded) | ||||
501 | << SemaRef.getLangOpts().InstantiationDepth | ||||
502 | << InstantiationRange; | ||||
503 | SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth) | ||||
504 | << SemaRef.getLangOpts().InstantiationDepth; | ||||
505 | return true; | ||||
506 | } | ||||
507 | |||||
508 | /// Prints the current instantiation stack through a series of | ||||
509 | /// notes. | ||||
510 | void Sema::PrintInstantiationStack() { | ||||
511 | // Determine which template instantiations to skip, if any. | ||||
512 | unsigned SkipStart = CodeSynthesisContexts.size(), SkipEnd = SkipStart; | ||||
513 | unsigned Limit = Diags.getTemplateBacktraceLimit(); | ||||
514 | if (Limit && Limit < CodeSynthesisContexts.size()) { | ||||
515 | SkipStart = Limit / 2 + Limit % 2; | ||||
516 | SkipEnd = CodeSynthesisContexts.size() - Limit / 2; | ||||
517 | } | ||||
518 | |||||
519 | // FIXME: In all of these cases, we need to show the template arguments | ||||
520 | unsigned InstantiationIdx = 0; | ||||
521 | for (SmallVectorImpl<CodeSynthesisContext>::reverse_iterator | ||||
522 | Active = CodeSynthesisContexts.rbegin(), | ||||
523 | ActiveEnd = CodeSynthesisContexts.rend(); | ||||
524 | Active != ActiveEnd; | ||||
525 | ++Active, ++InstantiationIdx) { | ||||
526 | // Skip this instantiation? | ||||
527 | if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) { | ||||
528 | if (InstantiationIdx == SkipStart) { | ||||
529 | // Note that we're skipping instantiations. | ||||
530 | Diags.Report(Active->PointOfInstantiation, | ||||
531 | diag::note_instantiation_contexts_suppressed) | ||||
532 | << unsigned(CodeSynthesisContexts.size() - Limit); | ||||
533 | } | ||||
534 | continue; | ||||
535 | } | ||||
536 | |||||
537 | switch (Active->Kind) { | ||||
538 | case CodeSynthesisContext::TemplateInstantiation: { | ||||
539 | Decl *D = Active->Entity; | ||||
540 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) { | ||||
541 | unsigned DiagID = diag::note_template_member_class_here; | ||||
542 | if (isa<ClassTemplateSpecializationDecl>(Record)) | ||||
543 | DiagID = diag::note_template_class_instantiation_here; | ||||
544 | Diags.Report(Active->PointOfInstantiation, DiagID) | ||||
545 | << Record << Active->InstantiationRange; | ||||
546 | } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { | ||||
547 | unsigned DiagID; | ||||
548 | if (Function->getPrimaryTemplate()) | ||||
549 | DiagID = diag::note_function_template_spec_here; | ||||
550 | else | ||||
551 | DiagID = diag::note_template_member_function_here; | ||||
552 | Diags.Report(Active->PointOfInstantiation, DiagID) | ||||
553 | << Function | ||||
554 | << Active->InstantiationRange; | ||||
555 | } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) { | ||||
556 | Diags.Report(Active->PointOfInstantiation, | ||||
557 | VD->isStaticDataMember()? | ||||
558 | diag::note_template_static_data_member_def_here | ||||
559 | : diag::note_template_variable_def_here) | ||||
560 | << VD | ||||
561 | << Active->InstantiationRange; | ||||
562 | } else if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) { | ||||
563 | Diags.Report(Active->PointOfInstantiation, | ||||
564 | diag::note_template_enum_def_here) | ||||
565 | << ED | ||||
566 | << Active->InstantiationRange; | ||||
567 | } else if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) { | ||||
568 | Diags.Report(Active->PointOfInstantiation, | ||||
569 | diag::note_template_nsdmi_here) | ||||
570 | << FD << Active->InstantiationRange; | ||||
571 | } else { | ||||
572 | Diags.Report(Active->PointOfInstantiation, | ||||
573 | diag::note_template_type_alias_instantiation_here) | ||||
574 | << cast<TypeAliasTemplateDecl>(D) | ||||
575 | << Active->InstantiationRange; | ||||
576 | } | ||||
577 | break; | ||||
578 | } | ||||
579 | |||||
580 | case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: { | ||||
581 | TemplateDecl *Template = cast<TemplateDecl>(Active->Template); | ||||
582 | SmallVector<char, 128> TemplateArgsStr; | ||||
583 | llvm::raw_svector_ostream OS(TemplateArgsStr); | ||||
584 | Template->printName(OS); | ||||
585 | printTemplateArgumentList(OS, Active->template_arguments(), | ||||
586 | getPrintingPolicy()); | ||||
587 | Diags.Report(Active->PointOfInstantiation, | ||||
588 | diag::note_default_arg_instantiation_here) | ||||
589 | << OS.str() | ||||
590 | << Active->InstantiationRange; | ||||
591 | break; | ||||
592 | } | ||||
593 | |||||
594 | case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution: { | ||||
595 | FunctionTemplateDecl *FnTmpl = cast<FunctionTemplateDecl>(Active->Entity); | ||||
596 | Diags.Report(Active->PointOfInstantiation, | ||||
597 | diag::note_explicit_template_arg_substitution_here) | ||||
598 | << FnTmpl | ||||
599 | << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(), | ||||
600 | Active->TemplateArgs, | ||||
601 | Active->NumTemplateArgs) | ||||
602 | << Active->InstantiationRange; | ||||
603 | break; | ||||
604 | } | ||||
605 | |||||
606 | case CodeSynthesisContext::DeducedTemplateArgumentSubstitution: { | ||||
607 | if (FunctionTemplateDecl *FnTmpl = | ||||
608 | dyn_cast<FunctionTemplateDecl>(Active->Entity)) { | ||||
609 | Diags.Report(Active->PointOfInstantiation, | ||||
610 | diag::note_function_template_deduction_instantiation_here) | ||||
611 | << FnTmpl | ||||
612 | << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(), | ||||
613 | Active->TemplateArgs, | ||||
614 | Active->NumTemplateArgs) | ||||
615 | << Active->InstantiationRange; | ||||
616 | } else { | ||||
617 | bool IsVar = isa<VarTemplateDecl>(Active->Entity) || | ||||
618 | isa<VarTemplateSpecializationDecl>(Active->Entity); | ||||
619 | bool IsTemplate = false; | ||||
620 | TemplateParameterList *Params; | ||||
621 | if (auto *D = dyn_cast<TemplateDecl>(Active->Entity)) { | ||||
622 | IsTemplate = true; | ||||
623 | Params = D->getTemplateParameters(); | ||||
624 | } else if (auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>( | ||||
625 | Active->Entity)) { | ||||
626 | Params = D->getTemplateParameters(); | ||||
627 | } else if (auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>( | ||||
628 | Active->Entity)) { | ||||
629 | Params = D->getTemplateParameters(); | ||||
630 | } else { | ||||
631 | llvm_unreachable("unexpected template kind")::llvm::llvm_unreachable_internal("unexpected template kind", "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 631); | ||||
632 | } | ||||
633 | |||||
634 | Diags.Report(Active->PointOfInstantiation, | ||||
635 | diag::note_deduced_template_arg_substitution_here) | ||||
636 | << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity) | ||||
637 | << getTemplateArgumentBindingsText(Params, Active->TemplateArgs, | ||||
638 | Active->NumTemplateArgs) | ||||
639 | << Active->InstantiationRange; | ||||
640 | } | ||||
641 | break; | ||||
642 | } | ||||
643 | |||||
644 | case CodeSynthesisContext::DefaultFunctionArgumentInstantiation: { | ||||
645 | ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity); | ||||
646 | FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext()); | ||||
647 | |||||
648 | SmallVector<char, 128> TemplateArgsStr; | ||||
649 | llvm::raw_svector_ostream OS(TemplateArgsStr); | ||||
650 | FD->printName(OS); | ||||
651 | printTemplateArgumentList(OS, Active->template_arguments(), | ||||
652 | getPrintingPolicy()); | ||||
653 | Diags.Report(Active->PointOfInstantiation, | ||||
654 | diag::note_default_function_arg_instantiation_here) | ||||
655 | << OS.str() | ||||
656 | << Active->InstantiationRange; | ||||
657 | break; | ||||
658 | } | ||||
659 | |||||
660 | case CodeSynthesisContext::PriorTemplateArgumentSubstitution: { | ||||
661 | NamedDecl *Parm = cast<NamedDecl>(Active->Entity); | ||||
662 | std::string Name; | ||||
663 | if (!Parm->getName().empty()) | ||||
664 | Name = std::string(" '") + Parm->getName().str() + "'"; | ||||
665 | |||||
666 | TemplateParameterList *TemplateParams = nullptr; | ||||
667 | if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template)) | ||||
668 | TemplateParams = Template->getTemplateParameters(); | ||||
669 | else | ||||
670 | TemplateParams = | ||||
671 | cast<ClassTemplatePartialSpecializationDecl>(Active->Template) | ||||
672 | ->getTemplateParameters(); | ||||
673 | Diags.Report(Active->PointOfInstantiation, | ||||
674 | diag::note_prior_template_arg_substitution) | ||||
675 | << isa<TemplateTemplateParmDecl>(Parm) | ||||
676 | << Name | ||||
677 | << getTemplateArgumentBindingsText(TemplateParams, | ||||
678 | Active->TemplateArgs, | ||||
679 | Active->NumTemplateArgs) | ||||
680 | << Active->InstantiationRange; | ||||
681 | break; | ||||
682 | } | ||||
683 | |||||
684 | case CodeSynthesisContext::DefaultTemplateArgumentChecking: { | ||||
685 | TemplateParameterList *TemplateParams = nullptr; | ||||
686 | if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template)) | ||||
687 | TemplateParams = Template->getTemplateParameters(); | ||||
688 | else | ||||
689 | TemplateParams = | ||||
690 | cast<ClassTemplatePartialSpecializationDecl>(Active->Template) | ||||
691 | ->getTemplateParameters(); | ||||
692 | |||||
693 | Diags.Report(Active->PointOfInstantiation, | ||||
694 | diag::note_template_default_arg_checking) | ||||
695 | << getTemplateArgumentBindingsText(TemplateParams, | ||||
696 | Active->TemplateArgs, | ||||
697 | Active->NumTemplateArgs) | ||||
698 | << Active->InstantiationRange; | ||||
699 | break; | ||||
700 | } | ||||
701 | |||||
702 | case CodeSynthesisContext::ExceptionSpecEvaluation: | ||||
703 | Diags.Report(Active->PointOfInstantiation, | ||||
704 | diag::note_evaluating_exception_spec_here) | ||||
705 | << cast<FunctionDecl>(Active->Entity); | ||||
706 | break; | ||||
707 | |||||
708 | case CodeSynthesisContext::ExceptionSpecInstantiation: | ||||
709 | Diags.Report(Active->PointOfInstantiation, | ||||
710 | diag::note_template_exception_spec_instantiation_here) | ||||
711 | << cast<FunctionDecl>(Active->Entity) | ||||
712 | << Active->InstantiationRange; | ||||
713 | break; | ||||
714 | |||||
715 | case CodeSynthesisContext::RequirementInstantiation: | ||||
716 | Diags.Report(Active->PointOfInstantiation, | ||||
717 | diag::note_template_requirement_instantiation_here) | ||||
718 | << Active->InstantiationRange; | ||||
719 | break; | ||||
720 | |||||
721 | case CodeSynthesisContext::NestedRequirementConstraintsCheck: | ||||
722 | Diags.Report(Active->PointOfInstantiation, | ||||
723 | diag::note_nested_requirement_here) | ||||
724 | << Active->InstantiationRange; | ||||
725 | break; | ||||
726 | |||||
727 | case CodeSynthesisContext::DeclaringSpecialMember: | ||||
728 | Diags.Report(Active->PointOfInstantiation, | ||||
729 | diag::note_in_declaration_of_implicit_special_member) | ||||
730 | << cast<CXXRecordDecl>(Active->Entity) << Active->SpecialMember; | ||||
731 | break; | ||||
732 | |||||
733 | case CodeSynthesisContext::DeclaringImplicitEqualityComparison: | ||||
734 | Diags.Report(Active->Entity->getLocation(), | ||||
735 | diag::note_in_declaration_of_implicit_equality_comparison); | ||||
736 | break; | ||||
737 | |||||
738 | case CodeSynthesisContext::DefiningSynthesizedFunction: { | ||||
739 | // FIXME: For synthesized functions that are not defaulted, | ||||
740 | // produce a note. | ||||
741 | auto *FD = dyn_cast<FunctionDecl>(Active->Entity); | ||||
742 | DefaultedFunctionKind DFK = | ||||
743 | FD ? getDefaultedFunctionKind(FD) : DefaultedFunctionKind(); | ||||
744 | if (DFK.isSpecialMember()) { | ||||
745 | auto *MD = cast<CXXMethodDecl>(FD); | ||||
746 | Diags.Report(Active->PointOfInstantiation, | ||||
747 | diag::note_member_synthesized_at) | ||||
748 | << MD->isExplicitlyDefaulted() << DFK.asSpecialMember() | ||||
749 | << Context.getTagDeclType(MD->getParent()); | ||||
750 | } else if (DFK.isComparison()) { | ||||
751 | Diags.Report(Active->PointOfInstantiation, | ||||
752 | diag::note_comparison_synthesized_at) | ||||
753 | << (int)DFK.asComparison() | ||||
754 | << Context.getTagDeclType( | ||||
755 | cast<CXXRecordDecl>(FD->getLexicalDeclContext())); | ||||
756 | } | ||||
757 | break; | ||||
758 | } | ||||
759 | |||||
760 | case CodeSynthesisContext::RewritingOperatorAsSpaceship: | ||||
761 | Diags.Report(Active->Entity->getLocation(), | ||||
762 | diag::note_rewriting_operator_as_spaceship); | ||||
763 | break; | ||||
764 | |||||
765 | case CodeSynthesisContext::InitializingStructuredBinding: | ||||
766 | Diags.Report(Active->PointOfInstantiation, | ||||
767 | diag::note_in_binding_decl_init) | ||||
768 | << cast<BindingDecl>(Active->Entity); | ||||
769 | break; | ||||
770 | |||||
771 | case CodeSynthesisContext::MarkingClassDllexported: | ||||
772 | Diags.Report(Active->PointOfInstantiation, | ||||
773 | diag::note_due_to_dllexported_class) | ||||
774 | << cast<CXXRecordDecl>(Active->Entity) << !getLangOpts().CPlusPlus11; | ||||
775 | break; | ||||
776 | |||||
777 | case CodeSynthesisContext::Memoization: | ||||
778 | break; | ||||
779 | |||||
780 | case CodeSynthesisContext::ConstraintsCheck: { | ||||
781 | unsigned DiagID = 0; | ||||
782 | if (!Active->Entity) { | ||||
783 | Diags.Report(Active->PointOfInstantiation, | ||||
784 | diag::note_nested_requirement_here) | ||||
785 | << Active->InstantiationRange; | ||||
786 | break; | ||||
787 | } | ||||
788 | if (isa<ConceptDecl>(Active->Entity)) | ||||
789 | DiagID = diag::note_concept_specialization_here; | ||||
790 | else if (isa<TemplateDecl>(Active->Entity)) | ||||
791 | DiagID = diag::note_checking_constraints_for_template_id_here; | ||||
792 | else if (isa<VarTemplatePartialSpecializationDecl>(Active->Entity)) | ||||
793 | DiagID = diag::note_checking_constraints_for_var_spec_id_here; | ||||
794 | else if (isa<ClassTemplatePartialSpecializationDecl>(Active->Entity)) | ||||
795 | DiagID = diag::note_checking_constraints_for_class_spec_id_here; | ||||
796 | else { | ||||
797 | assert(isa<FunctionDecl>(Active->Entity))((isa<FunctionDecl>(Active->Entity)) ? static_cast< void> (0) : __assert_fail ("isa<FunctionDecl>(Active->Entity)" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 797, __PRETTY_FUNCTION__)); | ||||
798 | DiagID = diag::note_checking_constraints_for_function_here; | ||||
799 | } | ||||
800 | SmallVector<char, 128> TemplateArgsStr; | ||||
801 | llvm::raw_svector_ostream OS(TemplateArgsStr); | ||||
802 | cast<NamedDecl>(Active->Entity)->printName(OS); | ||||
803 | if (!isa<FunctionDecl>(Active->Entity)) | ||||
804 | printTemplateArgumentList(OS, Active->template_arguments(), | ||||
805 | getPrintingPolicy()); | ||||
806 | Diags.Report(Active->PointOfInstantiation, DiagID) << OS.str() | ||||
807 | << Active->InstantiationRange; | ||||
808 | break; | ||||
809 | } | ||||
810 | case CodeSynthesisContext::ConstraintSubstitution: | ||||
811 | Diags.Report(Active->PointOfInstantiation, | ||||
812 | diag::note_constraint_substitution_here) | ||||
813 | << Active->InstantiationRange; | ||||
814 | break; | ||||
815 | case CodeSynthesisContext::ConstraintNormalization: | ||||
816 | Diags.Report(Active->PointOfInstantiation, | ||||
817 | diag::note_constraint_normalization_here) | ||||
818 | << cast<NamedDecl>(Active->Entity)->getName() | ||||
819 | << Active->InstantiationRange; | ||||
820 | break; | ||||
821 | case CodeSynthesisContext::ParameterMappingSubstitution: | ||||
822 | Diags.Report(Active->PointOfInstantiation, | ||||
823 | diag::note_parameter_mapping_substitution_here) | ||||
824 | << Active->InstantiationRange; | ||||
825 | break; | ||||
826 | } | ||||
827 | } | ||||
828 | } | ||||
829 | |||||
830 | Optional<TemplateDeductionInfo *> Sema::isSFINAEContext() const { | ||||
831 | if (InNonInstantiationSFINAEContext) | ||||
832 | return Optional<TemplateDeductionInfo *>(nullptr); | ||||
833 | |||||
834 | for (SmallVectorImpl<CodeSynthesisContext>::const_reverse_iterator | ||||
835 | Active = CodeSynthesisContexts.rbegin(), | ||||
836 | ActiveEnd = CodeSynthesisContexts.rend(); | ||||
837 | Active != ActiveEnd; | ||||
838 | ++Active) | ||||
839 | { | ||||
840 | switch (Active->Kind) { | ||||
841 | case CodeSynthesisContext::TemplateInstantiation: | ||||
842 | // An instantiation of an alias template may or may not be a SFINAE | ||||
843 | // context, depending on what else is on the stack. | ||||
844 | if (isa<TypeAliasTemplateDecl>(Active->Entity)) | ||||
845 | break; | ||||
846 | LLVM_FALLTHROUGH[[gnu::fallthrough]]; | ||||
847 | case CodeSynthesisContext::DefaultFunctionArgumentInstantiation: | ||||
848 | case CodeSynthesisContext::ExceptionSpecInstantiation: | ||||
849 | case CodeSynthesisContext::ConstraintsCheck: | ||||
850 | case CodeSynthesisContext::ParameterMappingSubstitution: | ||||
851 | case CodeSynthesisContext::ConstraintNormalization: | ||||
852 | case CodeSynthesisContext::NestedRequirementConstraintsCheck: | ||||
853 | // This is a template instantiation, so there is no SFINAE. | ||||
854 | return None; | ||||
855 | |||||
856 | case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: | ||||
857 | case CodeSynthesisContext::PriorTemplateArgumentSubstitution: | ||||
858 | case CodeSynthesisContext::DefaultTemplateArgumentChecking: | ||||
859 | // A default template argument instantiation and substitution into | ||||
860 | // template parameters with arguments for prior parameters may or may | ||||
861 | // not be a SFINAE context; look further up the stack. | ||||
862 | break; | ||||
863 | |||||
864 | case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution: | ||||
865 | case CodeSynthesisContext::DeducedTemplateArgumentSubstitution: | ||||
866 | case CodeSynthesisContext::ConstraintSubstitution: | ||||
867 | case CodeSynthesisContext::RequirementInstantiation: | ||||
868 | // We're either substituting explicitly-specified template arguments, | ||||
869 | // deduced template arguments, a constraint expression or a requirement | ||||
870 | // in a requires expression, so SFINAE applies. | ||||
871 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 871, __PRETTY_FUNCTION__)); | ||||
872 | return Active->DeductionInfo; | ||||
873 | |||||
874 | case CodeSynthesisContext::DeclaringSpecialMember: | ||||
875 | case CodeSynthesisContext::DeclaringImplicitEqualityComparison: | ||||
876 | case CodeSynthesisContext::DefiningSynthesizedFunction: | ||||
877 | case CodeSynthesisContext::RewritingOperatorAsSpaceship: | ||||
878 | case CodeSynthesisContext::InitializingStructuredBinding: | ||||
879 | case CodeSynthesisContext::MarkingClassDllexported: | ||||
880 | // This happens in a context unrelated to template instantiation, so | ||||
881 | // there is no SFINAE. | ||||
882 | return None; | ||||
883 | |||||
884 | case CodeSynthesisContext::ExceptionSpecEvaluation: | ||||
885 | // FIXME: This should not be treated as a SFINAE context, because | ||||
886 | // we will cache an incorrect exception specification. However, clang | ||||
887 | // bootstrap relies this! See PR31692. | ||||
888 | break; | ||||
889 | |||||
890 | case CodeSynthesisContext::Memoization: | ||||
891 | break; | ||||
892 | } | ||||
893 | |||||
894 | // The inner context was transparent for SFINAE. If it occurred within a | ||||
895 | // non-instantiation SFINAE context, then SFINAE applies. | ||||
896 | if (Active->SavedInNonInstantiationSFINAEContext) | ||||
897 | return Optional<TemplateDeductionInfo *>(nullptr); | ||||
898 | } | ||||
899 | |||||
900 | return None; | ||||
901 | } | ||||
902 | |||||
903 | //===----------------------------------------------------------------------===/ | ||||
904 | // Template Instantiation for Types | ||||
905 | //===----------------------------------------------------------------------===/ | ||||
906 | namespace { | ||||
907 | class TemplateInstantiator : public TreeTransform<TemplateInstantiator> { | ||||
908 | const MultiLevelTemplateArgumentList &TemplateArgs; | ||||
909 | SourceLocation Loc; | ||||
910 | DeclarationName Entity; | ||||
911 | |||||
912 | public: | ||||
913 | typedef TreeTransform<TemplateInstantiator> inherited; | ||||
914 | |||||
915 | TemplateInstantiator(Sema &SemaRef, | ||||
916 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||
917 | SourceLocation Loc, | ||||
918 | DeclarationName Entity) | ||||
919 | : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc), | ||||
920 | Entity(Entity) { } | ||||
921 | |||||
922 | /// Determine whether the given type \p T has already been | ||||
923 | /// transformed. | ||||
924 | /// | ||||
925 | /// For the purposes of template instantiation, a type has already been | ||||
926 | /// transformed if it is NULL or if it is not dependent. | ||||
927 | bool AlreadyTransformed(QualType T); | ||||
928 | |||||
929 | /// Returns the location of the entity being instantiated, if known. | ||||
930 | SourceLocation getBaseLocation() { return Loc; } | ||||
931 | |||||
932 | /// Returns the name of the entity being instantiated, if any. | ||||
933 | DeclarationName getBaseEntity() { return Entity; } | ||||
934 | |||||
935 | /// Sets the "base" location and entity when that | ||||
936 | /// information is known based on another transformation. | ||||
937 | void setBase(SourceLocation Loc, DeclarationName Entity) { | ||||
938 | this->Loc = Loc; | ||||
939 | this->Entity = Entity; | ||||
940 | } | ||||
941 | |||||
942 | unsigned TransformTemplateDepth(unsigned Depth) { | ||||
943 | return TemplateArgs.getNewDepth(Depth); | ||||
944 | } | ||||
945 | |||||
946 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, | ||||
947 | SourceRange PatternRange, | ||||
948 | ArrayRef<UnexpandedParameterPack> Unexpanded, | ||||
949 | bool &ShouldExpand, bool &RetainExpansion, | ||||
950 | Optional<unsigned> &NumExpansions) { | ||||
951 | return getSema().CheckParameterPacksForExpansion(EllipsisLoc, | ||||
952 | PatternRange, Unexpanded, | ||||
953 | TemplateArgs, | ||||
954 | ShouldExpand, | ||||
955 | RetainExpansion, | ||||
956 | NumExpansions); | ||||
957 | } | ||||
958 | |||||
959 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { | ||||
960 | SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Pack); | ||||
961 | } | ||||
962 | |||||
963 | TemplateArgument ForgetPartiallySubstitutedPack() { | ||||
964 | TemplateArgument Result; | ||||
965 | if (NamedDecl *PartialPack | ||||
966 | = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){ | ||||
967 | MultiLevelTemplateArgumentList &TemplateArgs | ||||
968 | = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs); | ||||
969 | unsigned Depth, Index; | ||||
970 | std::tie(Depth, Index) = getDepthAndIndex(PartialPack); | ||||
971 | if (TemplateArgs.hasTemplateArgument(Depth, Index)) { | ||||
972 | Result = TemplateArgs(Depth, Index); | ||||
973 | TemplateArgs.setArgument(Depth, Index, TemplateArgument()); | ||||
974 | } | ||||
975 | } | ||||
976 | |||||
977 | return Result; | ||||
978 | } | ||||
979 | |||||
980 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { | ||||
981 | if (Arg.isNull()) | ||||
982 | return; | ||||
983 | |||||
984 | if (NamedDecl *PartialPack | ||||
985 | = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){ | ||||
986 | MultiLevelTemplateArgumentList &TemplateArgs | ||||
987 | = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs); | ||||
988 | unsigned Depth, Index; | ||||
989 | std::tie(Depth, Index) = getDepthAndIndex(PartialPack); | ||||
990 | TemplateArgs.setArgument(Depth, Index, Arg); | ||||
991 | } | ||||
992 | } | ||||
993 | |||||
994 | /// Transform the given declaration by instantiating a reference to | ||||
995 | /// this declaration. | ||||
996 | Decl *TransformDecl(SourceLocation Loc, Decl *D); | ||||
997 | |||||
998 | void transformAttrs(Decl *Old, Decl *New) { | ||||
999 | SemaRef.InstantiateAttrs(TemplateArgs, Old, New); | ||||
1000 | } | ||||
1001 | |||||
1002 | void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) { | ||||
1003 | if (Old->isParameterPack()) { | ||||
1004 | SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Old); | ||||
1005 | for (auto *New : NewDecls) | ||||
1006 | SemaRef.CurrentInstantiationScope->InstantiatedLocalPackArg( | ||||
1007 | Old, cast<VarDecl>(New)); | ||||
1008 | return; | ||||
1009 | } | ||||
1010 | |||||
1011 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1012, __PRETTY_FUNCTION__)) | ||||
1012 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1012, __PRETTY_FUNCTION__)); | ||||
1013 | Decl *New = NewDecls.front(); | ||||
1014 | |||||
1015 | // If we've instantiated the call operator of a lambda or the call | ||||
1016 | // operator template of a generic lambda, update the "instantiation of" | ||||
1017 | // information. | ||||
1018 | auto *NewMD = dyn_cast<CXXMethodDecl>(New); | ||||
1019 | if (NewMD && isLambdaCallOperator(NewMD)) { | ||||
1020 | auto *OldMD = dyn_cast<CXXMethodDecl>(Old); | ||||
1021 | if (auto *NewTD = NewMD->getDescribedFunctionTemplate()) | ||||
1022 | NewTD->setInstantiatedFromMemberTemplate( | ||||
1023 | OldMD->getDescribedFunctionTemplate()); | ||||
1024 | else | ||||
1025 | NewMD->setInstantiationOfMemberFunction(OldMD, | ||||
1026 | TSK_ImplicitInstantiation); | ||||
1027 | } | ||||
1028 | |||||
1029 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(Old, New); | ||||
1030 | |||||
1031 | // We recreated a local declaration, but not by instantiating it. There | ||||
1032 | // may be pending dependent diagnostics to produce. | ||||
1033 | if (auto *DC = dyn_cast<DeclContext>(Old)) | ||||
1034 | SemaRef.PerformDependentDiagnostics(DC, TemplateArgs); | ||||
1035 | } | ||||
1036 | |||||
1037 | /// Transform the definition of the given declaration by | ||||
1038 | /// instantiating it. | ||||
1039 | Decl *TransformDefinition(SourceLocation Loc, Decl *D); | ||||
1040 | |||||
1041 | /// Transform the first qualifier within a scope by instantiating the | ||||
1042 | /// declaration. | ||||
1043 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc); | ||||
1044 | |||||
1045 | /// Rebuild the exception declaration and register the declaration | ||||
1046 | /// as an instantiated local. | ||||
1047 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, | ||||
1048 | TypeSourceInfo *Declarator, | ||||
1049 | SourceLocation StartLoc, | ||||
1050 | SourceLocation NameLoc, | ||||
1051 | IdentifierInfo *Name); | ||||
1052 | |||||
1053 | /// Rebuild the Objective-C exception declaration and register the | ||||
1054 | /// declaration as an instantiated local. | ||||
1055 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, | ||||
1056 | TypeSourceInfo *TSInfo, QualType T); | ||||
1057 | |||||
1058 | /// Check for tag mismatches when instantiating an | ||||
1059 | /// elaborated type. | ||||
1060 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, | ||||
1061 | ElaboratedTypeKeyword Keyword, | ||||
1062 | NestedNameSpecifierLoc QualifierLoc, | ||||
1063 | QualType T); | ||||
1064 | |||||
1065 | TemplateName | ||||
1066 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, | ||||
1067 | SourceLocation NameLoc, | ||||
1068 | QualType ObjectType = QualType(), | ||||
1069 | NamedDecl *FirstQualifierInScope = nullptr, | ||||
1070 | bool AllowInjectedClassName = false); | ||||
1071 | |||||
1072 | const LoopHintAttr *TransformLoopHintAttr(const LoopHintAttr *LH); | ||||
1073 | |||||
1074 | ExprResult TransformPredefinedExpr(PredefinedExpr *E); | ||||
1075 | ExprResult TransformDeclRefExpr(DeclRefExpr *E); | ||||
1076 | ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E); | ||||
1077 | |||||
1078 | ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E, | ||||
1079 | NonTypeTemplateParmDecl *D); | ||||
1080 | ExprResult TransformSubstNonTypeTemplateParmPackExpr( | ||||
1081 | SubstNonTypeTemplateParmPackExpr *E); | ||||
1082 | ExprResult TransformSubstNonTypeTemplateParmExpr( | ||||
1083 | SubstNonTypeTemplateParmExpr *E); | ||||
1084 | |||||
1085 | /// Rebuild a DeclRefExpr for a VarDecl reference. | ||||
1086 | ExprResult RebuildVarDeclRefExpr(VarDecl *PD, SourceLocation Loc); | ||||
1087 | |||||
1088 | /// Transform a reference to a function or init-capture parameter pack. | ||||
1089 | ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, VarDecl *PD); | ||||
1090 | |||||
1091 | /// Transform a FunctionParmPackExpr which was built when we couldn't | ||||
1092 | /// expand a function parameter pack reference which refers to an expanded | ||||
1093 | /// pack. | ||||
1094 | ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E); | ||||
1095 | |||||
1096 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, | ||||
1097 | FunctionProtoTypeLoc TL) { | ||||
1098 | // Call the base version; it will forward to our overridden version below. | ||||
1099 | return inherited::TransformFunctionProtoType(TLB, TL); | ||||
1100 | } | ||||
1101 | |||||
1102 | template<typename Fn> | ||||
1103 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, | ||||
1104 | FunctionProtoTypeLoc TL, | ||||
1105 | CXXRecordDecl *ThisContext, | ||||
1106 | Qualifiers ThisTypeQuals, | ||||
1107 | Fn TransformExceptionSpec); | ||||
1108 | |||||
1109 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, | ||||
1110 | int indexAdjustment, | ||||
1111 | Optional<unsigned> NumExpansions, | ||||
1112 | bool ExpectParameterPack); | ||||
1113 | |||||
1114 | /// Transforms a template type parameter type by performing | ||||
1115 | /// substitution of the corresponding template type argument. | ||||
1116 | QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, | ||||
1117 | TemplateTypeParmTypeLoc TL); | ||||
1118 | |||||
1119 | /// Transforms an already-substituted template type parameter pack | ||||
1120 | /// into either itself (if we aren't substituting into its pack expansion) | ||||
1121 | /// or the appropriate substituted argument. | ||||
1122 | QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB, | ||||
1123 | SubstTemplateTypeParmPackTypeLoc TL); | ||||
1124 | |||||
1125 | ExprResult TransformLambdaExpr(LambdaExpr *E) { | ||||
1126 | LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); | ||||
1127 | return TreeTransform<TemplateInstantiator>::TransformLambdaExpr(E); | ||||
1128 | } | ||||
1129 | |||||
1130 | ExprResult TransformRequiresExpr(RequiresExpr *E) { | ||||
1131 | LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); | ||||
1132 | return TreeTransform<TemplateInstantiator>::TransformRequiresExpr(E); | ||||
1133 | } | ||||
1134 | |||||
1135 | bool TransformRequiresExprRequirements( | ||||
1136 | ArrayRef<concepts::Requirement *> Reqs, | ||||
1137 | SmallVectorImpl<concepts::Requirement *> &Transformed) { | ||||
1138 | bool SatisfactionDetermined = false; | ||||
1139 | for (concepts::Requirement *Req : Reqs) { | ||||
1140 | concepts::Requirement *TransReq = nullptr; | ||||
1141 | if (!SatisfactionDetermined) { | ||||
1142 | if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) | ||||
1143 | TransReq = TransformTypeRequirement(TypeReq); | ||||
1144 | else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) | ||||
1145 | TransReq = TransformExprRequirement(ExprReq); | ||||
1146 | else | ||||
1147 | TransReq = TransformNestedRequirement( | ||||
1148 | cast<concepts::NestedRequirement>(Req)); | ||||
1149 | if (!TransReq) | ||||
1150 | return true; | ||||
1151 | if (!TransReq->isDependent() && !TransReq->isSatisfied()) | ||||
1152 | // [expr.prim.req]p6 | ||||
1153 | // [...] The substitution and semantic constraint checking | ||||
1154 | // proceeds in lexical order and stops when a condition that | ||||
1155 | // determines the result of the requires-expression is | ||||
1156 | // encountered. [..] | ||||
1157 | SatisfactionDetermined = true; | ||||
1158 | } else | ||||
1159 | TransReq = Req; | ||||
1160 | Transformed.push_back(TransReq); | ||||
1161 | } | ||||
1162 | return false; | ||||
1163 | } | ||||
1164 | |||||
1165 | TemplateParameterList *TransformTemplateParameterList( | ||||
1166 | TemplateParameterList *OrigTPL) { | ||||
1167 | if (!OrigTPL || !OrigTPL->size()) return OrigTPL; | ||||
1168 | |||||
1169 | DeclContext *Owner = OrigTPL->getParam(0)->getDeclContext(); | ||||
1170 | TemplateDeclInstantiator DeclInstantiator(getSema(), | ||||
1171 | /* DeclContext *Owner */ Owner, TemplateArgs); | ||||
1172 | return DeclInstantiator.SubstTemplateParams(OrigTPL); | ||||
1173 | } | ||||
1174 | |||||
1175 | concepts::TypeRequirement * | ||||
1176 | TransformTypeRequirement(concepts::TypeRequirement *Req); | ||||
1177 | concepts::ExprRequirement * | ||||
1178 | TransformExprRequirement(concepts::ExprRequirement *Req); | ||||
1179 | concepts::NestedRequirement * | ||||
1180 | TransformNestedRequirement(concepts::NestedRequirement *Req); | ||||
1181 | |||||
1182 | private: | ||||
1183 | ExprResult transformNonTypeTemplateParmRef(NonTypeTemplateParmDecl *parm, | ||||
1184 | SourceLocation loc, | ||||
1185 | TemplateArgument arg); | ||||
1186 | }; | ||||
1187 | } | ||||
1188 | |||||
1189 | bool TemplateInstantiator::AlreadyTransformed(QualType T) { | ||||
1190 | if (T.isNull()) | ||||
1191 | return true; | ||||
1192 | |||||
1193 | if (T->isInstantiationDependentType() || T->isVariablyModifiedType()) | ||||
1194 | return false; | ||||
1195 | |||||
1196 | getSema().MarkDeclarationsReferencedInType(Loc, T); | ||||
1197 | return true; | ||||
1198 | } | ||||
1199 | |||||
1200 | static TemplateArgument | ||||
1201 | getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg) { | ||||
1202 | assert(S.ArgumentPackSubstitutionIndex >= 0)((S.ArgumentPackSubstitutionIndex >= 0) ? static_cast<void > (0) : __assert_fail ("S.ArgumentPackSubstitutionIndex >= 0" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1202, __PRETTY_FUNCTION__)); | ||||
1203 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1203, __PRETTY_FUNCTION__)); | ||||
1204 | Arg = Arg.pack_begin()[S.ArgumentPackSubstitutionIndex]; | ||||
1205 | if (Arg.isPackExpansion()) | ||||
1206 | Arg = Arg.getPackExpansionPattern(); | ||||
1207 | return Arg; | ||||
1208 | } | ||||
1209 | |||||
1210 | Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) { | ||||
1211 | if (!D) | ||||
1212 | return nullptr; | ||||
1213 | |||||
1214 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) { | ||||
1215 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | ||||
1216 | // If the corresponding template argument is NULL or non-existent, it's | ||||
1217 | // because we are performing instantiation from explicitly-specified | ||||
1218 | // template arguments in a function template, but there were some | ||||
1219 | // arguments left unspecified. | ||||
1220 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), | ||||
1221 | TTP->getPosition())) | ||||
1222 | return D; | ||||
1223 | |||||
1224 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition()); | ||||
1225 | |||||
1226 | if (TTP->isParameterPack()) { | ||||
1227 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1228, __PRETTY_FUNCTION__)) | ||||
1228 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1228, __PRETTY_FUNCTION__)); | ||||
1229 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1230 | } | ||||
1231 | |||||
1232 | TemplateName Template = Arg.getAsTemplate().getNameToSubstitute(); | ||||
1233 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1234, __PRETTY_FUNCTION__)) | ||||
1234 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1234, __PRETTY_FUNCTION__)); | ||||
1235 | return Template.getAsTemplateDecl(); | ||||
1236 | } | ||||
1237 | |||||
1238 | // Fall through to find the instantiated declaration for this template | ||||
1239 | // template parameter. | ||||
1240 | } | ||||
1241 | |||||
1242 | return SemaRef.FindInstantiatedDecl(Loc, cast<NamedDecl>(D), TemplateArgs); | ||||
1243 | } | ||||
1244 | |||||
1245 | Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) { | ||||
1246 | Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs); | ||||
1247 | if (!Inst) | ||||
1248 | return nullptr; | ||||
1249 | |||||
1250 | getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst); | ||||
1251 | return Inst; | ||||
1252 | } | ||||
1253 | |||||
1254 | NamedDecl * | ||||
1255 | TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D, | ||||
1256 | SourceLocation Loc) { | ||||
1257 | // If the first part of the nested-name-specifier was a template type | ||||
1258 | // parameter, instantiate that type parameter down to a tag type. | ||||
1259 | if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) { | ||||
1260 | const TemplateTypeParmType *TTP | ||||
1261 | = cast<TemplateTypeParmType>(getSema().Context.getTypeDeclType(TTPD)); | ||||
1262 | |||||
1263 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | ||||
1264 | // FIXME: This needs testing w/ member access expressions. | ||||
1265 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex()); | ||||
1266 | |||||
1267 | if (TTP->isParameterPack()) { | ||||
1268 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1269, __PRETTY_FUNCTION__)) | ||||
1269 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1269, __PRETTY_FUNCTION__)); | ||||
1270 | |||||
1271 | if (getSema().ArgumentPackSubstitutionIndex == -1) | ||||
1272 | return nullptr; | ||||
1273 | |||||
1274 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1275 | } | ||||
1276 | |||||
1277 | QualType T = Arg.getAsType(); | ||||
1278 | if (T.isNull()) | ||||
1279 | return cast_or_null<NamedDecl>(TransformDecl(Loc, D)); | ||||
1280 | |||||
1281 | if (const TagType *Tag = T->getAs<TagType>()) | ||||
1282 | return Tag->getDecl(); | ||||
1283 | |||||
1284 | // The resulting type is not a tag; complain. | ||||
1285 | getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) << T; | ||||
1286 | return nullptr; | ||||
1287 | } | ||||
1288 | } | ||||
1289 | |||||
1290 | return cast_or_null<NamedDecl>(TransformDecl(Loc, D)); | ||||
1291 | } | ||||
1292 | |||||
1293 | VarDecl * | ||||
1294 | TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl, | ||||
1295 | TypeSourceInfo *Declarator, | ||||
1296 | SourceLocation StartLoc, | ||||
1297 | SourceLocation NameLoc, | ||||
1298 | IdentifierInfo *Name) { | ||||
1299 | VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator, | ||||
1300 | StartLoc, NameLoc, Name); | ||||
1301 | if (Var) | ||||
1302 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); | ||||
1303 | return Var; | ||||
1304 | } | ||||
1305 | |||||
1306 | VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, | ||||
1307 | TypeSourceInfo *TSInfo, | ||||
1308 | QualType T) { | ||||
1309 | VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo, T); | ||||
1310 | if (Var) | ||||
1311 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); | ||||
1312 | return Var; | ||||
1313 | } | ||||
1314 | |||||
1315 | QualType | ||||
1316 | TemplateInstantiator::RebuildElaboratedType(SourceLocation KeywordLoc, | ||||
1317 | ElaboratedTypeKeyword Keyword, | ||||
1318 | NestedNameSpecifierLoc QualifierLoc, | ||||
1319 | QualType T) { | ||||
1320 | if (const TagType *TT = T->getAs<TagType>()) { | ||||
1321 | TagDecl* TD = TT->getDecl(); | ||||
1322 | |||||
1323 | SourceLocation TagLocation = KeywordLoc; | ||||
1324 | |||||
1325 | IdentifierInfo *Id = TD->getIdentifier(); | ||||
1326 | |||||
1327 | // TODO: should we even warn on struct/class mismatches for this? Seems | ||||
1328 | // like it's likely to produce a lot of spurious errors. | ||||
1329 | if (Id && Keyword != ETK_None && Keyword != ETK_Typename) { | ||||
1330 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); | ||||
1331 | if (!SemaRef.isAcceptableTagRedeclaration(TD, Kind, /*isDefinition*/false, | ||||
1332 | TagLocation, Id)) { | ||||
1333 | SemaRef.Diag(TagLocation, diag::err_use_with_wrong_tag) | ||||
1334 | << Id | ||||
1335 | << FixItHint::CreateReplacement(SourceRange(TagLocation), | ||||
1336 | TD->getKindName()); | ||||
1337 | SemaRef.Diag(TD->getLocation(), diag::note_previous_use); | ||||
1338 | } | ||||
1339 | } | ||||
1340 | } | ||||
1341 | |||||
1342 | return TreeTransform<TemplateInstantiator>::RebuildElaboratedType(KeywordLoc, | ||||
1343 | Keyword, | ||||
1344 | QualifierLoc, | ||||
1345 | T); | ||||
1346 | } | ||||
1347 | |||||
1348 | TemplateName TemplateInstantiator::TransformTemplateName( | ||||
1349 | CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc, | ||||
1350 | QualType ObjectType, NamedDecl *FirstQualifierInScope, | ||||
1351 | bool AllowInjectedClassName) { | ||||
1352 | if (TemplateTemplateParmDecl *TTP | ||||
1353 | = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) { | ||||
1354 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | ||||
1355 | // If the corresponding template argument is NULL or non-existent, it's | ||||
1356 | // because we are performing instantiation from explicitly-specified | ||||
1357 | // template arguments in a function template, but there were some | ||||
1358 | // arguments left unspecified. | ||||
1359 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), | ||||
1360 | TTP->getPosition())) | ||||
1361 | return Name; | ||||
1362 | |||||
1363 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition()); | ||||
1364 | |||||
1365 | if (TemplateArgs.isRewrite()) { | ||||
1366 | // We're rewriting the template parameter as a reference to another | ||||
1367 | // template parameter. | ||||
1368 | if (Arg.getKind() == TemplateArgument::Pack) { | ||||
1369 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1370, __PRETTY_FUNCTION__)) | ||||
1370 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1370, __PRETTY_FUNCTION__)); | ||||
1371 | Arg = Arg.pack_begin()->getPackExpansionPattern(); | ||||
1372 | } | ||||
1373 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1374, __PRETTY_FUNCTION__)) | ||||
1374 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1374, __PRETTY_FUNCTION__)); | ||||
1375 | return Arg.getAsTemplate(); | ||||
1376 | } | ||||
1377 | |||||
1378 | if (TTP->isParameterPack()) { | ||||
1379 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1380, __PRETTY_FUNCTION__)) | ||||
1380 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1380, __PRETTY_FUNCTION__)); | ||||
1381 | |||||
1382 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||
1383 | // We have the template argument pack to substitute, but we're not | ||||
1384 | // actually expanding the enclosing pack expansion yet. So, just | ||||
1385 | // keep the entire argument pack. | ||||
1386 | return getSema().Context.getSubstTemplateTemplateParmPack(TTP, Arg); | ||||
1387 | } | ||||
1388 | |||||
1389 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1390 | } | ||||
1391 | |||||
1392 | TemplateName Template = Arg.getAsTemplate().getNameToSubstitute(); | ||||
1393 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1393, __PRETTY_FUNCTION__)); | ||||
1394 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1395, __PRETTY_FUNCTION__)) | ||||
1395 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1395, __PRETTY_FUNCTION__)); | ||||
1396 | |||||
1397 | Template = getSema().Context.getSubstTemplateTemplateParm(TTP, Template); | ||||
1398 | return Template; | ||||
1399 | } | ||||
1400 | } | ||||
1401 | |||||
1402 | if (SubstTemplateTemplateParmPackStorage *SubstPack | ||||
1403 | = Name.getAsSubstTemplateTemplateParmPack()) { | ||||
1404 | if (getSema().ArgumentPackSubstitutionIndex == -1) | ||||
1405 | return Name; | ||||
1406 | |||||
1407 | TemplateArgument Arg = SubstPack->getArgumentPack(); | ||||
1408 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1409 | return Arg.getAsTemplate().getNameToSubstitute(); | ||||
1410 | } | ||||
1411 | |||||
1412 | return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType, | ||||
1413 | FirstQualifierInScope, | ||||
1414 | AllowInjectedClassName); | ||||
1415 | } | ||||
1416 | |||||
1417 | static ExprResult TransformUniqueStableName(TemplateInstantiator &TI, | ||||
1418 | PredefinedExpr *E) { | ||||
1419 | if (E->getIdentKind() == PredefinedExpr::UniqueStableNameType) { | ||||
1420 | TypeSourceInfo *Info = | ||||
1421 | TI.getDerived().TransformType(E->getTypeSourceInfo()); | ||||
1422 | |||||
1423 | if (!Info) | ||||
1424 | return ExprError(); | ||||
1425 | |||||
1426 | if (!TI.getDerived().AlwaysRebuild() && Info == E->getTypeSourceInfo()) | ||||
1427 | return E; | ||||
1428 | |||||
1429 | return TI.getSema().BuildUniqueStableName(E->getLocation(), Info); | ||||
1430 | } | ||||
1431 | |||||
1432 | if (E->getIdentKind() == PredefinedExpr::UniqueStableNameExpr) { | ||||
1433 | EnterExpressionEvaluationContext Unevaluated( | ||||
1434 | TI.getSema(), Sema::ExpressionEvaluationContext::Unevaluated); | ||||
1435 | ExprResult SubExpr = TI.getDerived().TransformExpr(E->getExpr()); | ||||
1436 | |||||
1437 | if (SubExpr.isInvalid()) | ||||
1438 | return ExprError(); | ||||
1439 | |||||
1440 | if (!TI.getDerived().AlwaysRebuild() && SubExpr.get() == E->getExpr()) | ||||
1441 | return E; | ||||
1442 | |||||
1443 | return TI.getSema().BuildUniqueStableName(E->getLocation(), SubExpr.get()); | ||||
1444 | } | ||||
1445 | |||||
1446 | llvm_unreachable("Only valid for UniqueStableNameType/Expr")::llvm::llvm_unreachable_internal("Only valid for UniqueStableNameType/Expr" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1446); | ||||
1447 | } | ||||
1448 | |||||
1449 | ExprResult | ||||
1450 | TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) { | ||||
1451 | if (!E->isTypeDependent()) | ||||
1452 | return E; | ||||
1453 | |||||
1454 | if (E->getIdentKind() == PredefinedExpr::UniqueStableNameType || | ||||
1455 | E->getIdentKind() == PredefinedExpr::UniqueStableNameExpr) | ||||
1456 | return TransformUniqueStableName(*this, E); | ||||
1457 | |||||
1458 | return getSema().BuildPredefinedExpr(E->getLocation(), E->getIdentKind()); | ||||
1459 | } | ||||
1460 | |||||
1461 | ExprResult | ||||
1462 | TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E, | ||||
1463 | NonTypeTemplateParmDecl *NTTP) { | ||||
1464 | // If the corresponding template argument is NULL or non-existent, it's | ||||
1465 | // because we are performing instantiation from explicitly-specified | ||||
1466 | // template arguments in a function template, but there were some | ||||
1467 | // arguments left unspecified. | ||||
1468 | if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(), | ||||
1469 | NTTP->getPosition())) | ||||
1470 | return E; | ||||
1471 | |||||
1472 | TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), NTTP->getPosition()); | ||||
1473 | |||||
1474 | if (TemplateArgs.isRewrite()) { | ||||
1475 | // We're rewriting the template parameter as a reference to another | ||||
1476 | // template parameter. | ||||
1477 | if (Arg.getKind() == TemplateArgument::Pack) { | ||||
1478 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1479, __PRETTY_FUNCTION__)) | ||||
1479 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1479, __PRETTY_FUNCTION__)); | ||||
1480 | Arg = Arg.pack_begin()->getPackExpansionPattern(); | ||||
1481 | } | ||||
1482 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1483, __PRETTY_FUNCTION__)) | ||||
1483 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1483, __PRETTY_FUNCTION__)); | ||||
1484 | // FIXME: This can lead to the same subexpression appearing multiple times | ||||
1485 | // in a complete expression. | ||||
1486 | return Arg.getAsExpr(); | ||||
1487 | } | ||||
1488 | |||||
1489 | if (NTTP->isParameterPack()) { | ||||
1490 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1491, __PRETTY_FUNCTION__)) | ||||
1491 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1491, __PRETTY_FUNCTION__)); | ||||
1492 | |||||
1493 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||
1494 | // We have an argument pack, but we can't select a particular argument | ||||
1495 | // out of it yet. Therefore, we'll build an expression to hold on to that | ||||
1496 | // argument pack. | ||||
1497 | QualType TargetType = SemaRef.SubstType(NTTP->getType(), TemplateArgs, | ||||
1498 | E->getLocation(), | ||||
1499 | NTTP->getDeclName()); | ||||
1500 | if (TargetType.isNull()) | ||||
1501 | return ExprError(); | ||||
1502 | |||||
1503 | return new (SemaRef.Context) SubstNonTypeTemplateParmPackExpr( | ||||
1504 | TargetType.getNonLValueExprType(SemaRef.Context), | ||||
1505 | TargetType->isReferenceType() ? VK_LValue : VK_RValue, NTTP, | ||||
1506 | E->getLocation(), Arg); | ||||
1507 | } | ||||
1508 | |||||
1509 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1510 | } | ||||
1511 | |||||
1512 | return transformNonTypeTemplateParmRef(NTTP, E->getLocation(), Arg); | ||||
1513 | } | ||||
1514 | |||||
1515 | const LoopHintAttr * | ||||
1516 | TemplateInstantiator::TransformLoopHintAttr(const LoopHintAttr *LH) { | ||||
1517 | Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get(); | ||||
1518 | |||||
1519 | if (TransformedExpr == LH->getValue()) | ||||
1520 | return LH; | ||||
1521 | |||||
1522 | // Generate error if there is a problem with the value. | ||||
1523 | if (getSema().CheckLoopHintExpr(TransformedExpr, LH->getLocation())) | ||||
1524 | return LH; | ||||
1525 | |||||
1526 | // Create new LoopHintValueAttr with integral expression in place of the | ||||
1527 | // non-type template parameter. | ||||
1528 | return LoopHintAttr::CreateImplicit(getSema().Context, LH->getOption(), | ||||
1529 | LH->getState(), TransformedExpr, *LH); | ||||
1530 | } | ||||
1531 | |||||
1532 | ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef( | ||||
1533 | NonTypeTemplateParmDecl *parm, | ||||
1534 | SourceLocation loc, | ||||
1535 | TemplateArgument arg) { | ||||
1536 | ExprResult result; | ||||
1537 | QualType type; | ||||
1538 | |||||
1539 | // The template argument itself might be an expression, in which | ||||
1540 | // case we just return that expression. | ||||
1541 | if (arg.getKind() == TemplateArgument::Expression) { | ||||
1542 | Expr *argExpr = arg.getAsExpr(); | ||||
1543 | result = argExpr; | ||||
1544 | type = argExpr->getType(); | ||||
1545 | |||||
1546 | } else if (arg.getKind() == TemplateArgument::Declaration || | ||||
1547 | arg.getKind() == TemplateArgument::NullPtr) { | ||||
1548 | ValueDecl *VD; | ||||
1549 | if (arg.getKind() == TemplateArgument::Declaration) { | ||||
1550 | VD = arg.getAsDecl(); | ||||
1551 | |||||
1552 | // Find the instantiation of the template argument. This is | ||||
1553 | // required for nested templates. | ||||
1554 | VD = cast_or_null<ValueDecl>( | ||||
1555 | getSema().FindInstantiatedDecl(loc, VD, TemplateArgs)); | ||||
1556 | if (!VD) | ||||
1557 | return ExprError(); | ||||
1558 | } else { | ||||
1559 | // Propagate NULL template argument. | ||||
1560 | VD = nullptr; | ||||
1561 | } | ||||
1562 | |||||
1563 | // Derive the type we want the substituted decl to have. This had | ||||
1564 | // better be non-dependent, or these checks will have serious problems. | ||||
1565 | if (parm->isExpandedParameterPack()) { | ||||
1566 | type = parm->getExpansionType(SemaRef.ArgumentPackSubstitutionIndex); | ||||
1567 | } else if (parm->isParameterPack() && | ||||
1568 | isa<PackExpansionType>(parm->getType())) { | ||||
1569 | type = SemaRef.SubstType( | ||||
1570 | cast<PackExpansionType>(parm->getType())->getPattern(), | ||||
1571 | TemplateArgs, loc, parm->getDeclName()); | ||||
1572 | } else { | ||||
1573 | type = SemaRef.SubstType(VD ? arg.getParamTypeForDecl() : arg.getNullPtrType(), | ||||
1574 | TemplateArgs, loc, parm->getDeclName()); | ||||
1575 | } | ||||
1576 | assert(!type.isNull() && "type substitution failed for param type")((!type.isNull() && "type substitution failed for param type" ) ? static_cast<void> (0) : __assert_fail ("!type.isNull() && \"type substitution failed for param type\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1576, __PRETTY_FUNCTION__)); | ||||
1577 | assert(!type->isDependentType() && "param type still dependent")((!type->isDependentType() && "param type still dependent" ) ? static_cast<void> (0) : __assert_fail ("!type->isDependentType() && \"param type still dependent\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1577, __PRETTY_FUNCTION__)); | ||||
1578 | result = SemaRef.BuildExpressionFromDeclTemplateArgument(arg, type, loc); | ||||
1579 | |||||
1580 | if (!result.isInvalid()) type = result.get()->getType(); | ||||
1581 | } else { | ||||
1582 | result = SemaRef.BuildExpressionFromIntegralTemplateArgument(arg, loc); | ||||
1583 | |||||
1584 | // Note that this type can be different from the type of 'result', | ||||
1585 | // e.g. if it's an enum type. | ||||
1586 | type = arg.getIntegralType(); | ||||
1587 | } | ||||
1588 | if (result.isInvalid()) return ExprError(); | ||||
1589 | |||||
1590 | Expr *resultExpr = result.get(); | ||||
1591 | return new (SemaRef.Context) SubstNonTypeTemplateParmExpr( | ||||
1592 | type, resultExpr->getValueKind(), loc, parm, resultExpr); | ||||
1593 | } | ||||
1594 | |||||
1595 | ExprResult | ||||
1596 | TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr( | ||||
1597 | SubstNonTypeTemplateParmPackExpr *E) { | ||||
1598 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||
1599 | // We aren't expanding the parameter pack, so just return ourselves. | ||||
1600 | return E; | ||||
1601 | } | ||||
1602 | |||||
1603 | TemplateArgument Arg = E->getArgumentPack(); | ||||
1604 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1605 | return transformNonTypeTemplateParmRef(E->getParameterPack(), | ||||
1606 | E->getParameterPackLocation(), | ||||
1607 | Arg); | ||||
1608 | } | ||||
1609 | |||||
1610 | ExprResult | ||||
1611 | TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr( | ||||
1612 | SubstNonTypeTemplateParmExpr *E) { | ||||
1613 | ExprResult SubstReplacement = TransformExpr(E->getReplacement()); | ||||
1614 | if (SubstReplacement.isInvalid()) | ||||
1615 | return true; | ||||
1616 | QualType SubstType = TransformType(E->getType()); | ||||
1617 | if (SubstType.isNull()) | ||||
1618 | return true; | ||||
1619 | // The type may have been previously dependent and not now, which means we | ||||
1620 | // might have to implicit cast the argument to the new type, for example: | ||||
1621 | // template<auto T, decltype(T) U> | ||||
1622 | // concept C = sizeof(U) == 4; | ||||
1623 | // void foo() requires C<2, 'a'> { } | ||||
1624 | // When normalizing foo(), we first form the normalized constraints of C: | ||||
1625 | // AtomicExpr(sizeof(U) == 4, | ||||
1626 | // U=SubstNonTypeTemplateParmExpr(Param=U, | ||||
1627 | // Expr=DeclRef(U), | ||||
1628 | // Type=decltype(T))) | ||||
1629 | // Then we substitute T = 2, U = 'a' into the parameter mapping, and need to | ||||
1630 | // produce: | ||||
1631 | // AtomicExpr(sizeof(U) == 4, | ||||
1632 | // U=SubstNonTypeTemplateParmExpr(Param=U, | ||||
1633 | // Expr=ImpCast( | ||||
1634 | // decltype(2), | ||||
1635 | // SubstNTTPE(Param=U, Expr='a', | ||||
1636 | // Type=char)), | ||||
1637 | // Type=decltype(2))) | ||||
1638 | // The call to CheckTemplateArgument here produces the ImpCast. | ||||
1639 | TemplateArgument Converted; | ||||
1640 | if (SemaRef.CheckTemplateArgument(E->getParameter(), SubstType, | ||||
1641 | SubstReplacement.get(), | ||||
1642 | Converted).isInvalid()) | ||||
1643 | return true; | ||||
1644 | return transformNonTypeTemplateParmRef(E->getParameter(), | ||||
1645 | E->getExprLoc(), Converted); | ||||
1646 | } | ||||
1647 | |||||
1648 | ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(VarDecl *PD, | ||||
1649 | SourceLocation Loc) { | ||||
1650 | DeclarationNameInfo NameInfo(PD->getDeclName(), Loc); | ||||
1651 | return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD); | ||||
1652 | } | ||||
1653 | |||||
1654 | ExprResult | ||||
1655 | TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { | ||||
1656 | if (getSema().ArgumentPackSubstitutionIndex != -1) { | ||||
1657 | // We can expand this parameter pack now. | ||||
1658 | VarDecl *D = E->getExpansion(getSema().ArgumentPackSubstitutionIndex); | ||||
1659 | VarDecl *VD = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), D)); | ||||
1660 | if (!VD) | ||||
1661 | return ExprError(); | ||||
1662 | return RebuildVarDeclRefExpr(VD, E->getExprLoc()); | ||||
1663 | } | ||||
1664 | |||||
1665 | QualType T = TransformType(E->getType()); | ||||
1666 | if (T.isNull()) | ||||
1667 | return ExprError(); | ||||
1668 | |||||
1669 | // Transform each of the parameter expansions into the corresponding | ||||
1670 | // parameters in the instantiation of the function decl. | ||||
1671 | SmallVector<VarDecl *, 8> Vars; | ||||
1672 | Vars.reserve(E->getNumExpansions()); | ||||
1673 | for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end(); | ||||
1674 | I != End; ++I) { | ||||
1675 | VarDecl *D = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), *I)); | ||||
1676 | if (!D) | ||||
1677 | return ExprError(); | ||||
1678 | Vars.push_back(D); | ||||
1679 | } | ||||
1680 | |||||
1681 | auto *PackExpr = | ||||
1682 | FunctionParmPackExpr::Create(getSema().Context, T, E->getParameterPack(), | ||||
1683 | E->getParameterPackLocation(), Vars); | ||||
1684 | getSema().MarkFunctionParmPackReferenced(PackExpr); | ||||
1685 | return PackExpr; | ||||
1686 | } | ||||
1687 | |||||
1688 | ExprResult | ||||
1689 | TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E, | ||||
1690 | VarDecl *PD) { | ||||
1691 | typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack; | ||||
1692 | llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found | ||||
1693 | = getSema().CurrentInstantiationScope->findInstantiationOf(PD); | ||||
1694 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1694, __PRETTY_FUNCTION__)); | ||||
1695 | |||||
1696 | Decl *TransformedDecl; | ||||
1697 | if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) { | ||||
1698 | // If this is a reference to a function parameter pack which we can | ||||
1699 | // substitute but can't yet expand, build a FunctionParmPackExpr for it. | ||||
1700 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||
1701 | QualType T = TransformType(E->getType()); | ||||
1702 | if (T.isNull()) | ||||
1703 | return ExprError(); | ||||
1704 | auto *PackExpr = FunctionParmPackExpr::Create(getSema().Context, T, PD, | ||||
1705 | E->getExprLoc(), *Pack); | ||||
1706 | getSema().MarkFunctionParmPackReferenced(PackExpr); | ||||
1707 | return PackExpr; | ||||
1708 | } | ||||
1709 | |||||
1710 | TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex]; | ||||
1711 | } else { | ||||
1712 | TransformedDecl = Found->get<Decl*>(); | ||||
1713 | } | ||||
1714 | |||||
1715 | // We have either an unexpanded pack or a specific expansion. | ||||
1716 | return RebuildVarDeclRefExpr(cast<VarDecl>(TransformedDecl), E->getExprLoc()); | ||||
1717 | } | ||||
1718 | |||||
1719 | ExprResult | ||||
1720 | TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) { | ||||
1721 | NamedDecl *D = E->getDecl(); | ||||
1722 | |||||
1723 | // Handle references to non-type template parameters and non-type template | ||||
1724 | // parameter packs. | ||||
1725 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { | ||||
1726 | if (NTTP->getDepth() < TemplateArgs.getNumLevels()) | ||||
1727 | return TransformTemplateParmRefExpr(E, NTTP); | ||||
1728 | |||||
1729 | // We have a non-type template parameter that isn't fully substituted; | ||||
1730 | // FindInstantiatedDecl will find it in the local instantiation scope. | ||||
1731 | } | ||||
1732 | |||||
1733 | // Handle references to function parameter packs. | ||||
1734 | if (VarDecl *PD = dyn_cast<VarDecl>(D)) | ||||
1735 | if (PD->isParameterPack()) | ||||
1736 | return TransformFunctionParmPackRefExpr(E, PD); | ||||
1737 | |||||
1738 | return TreeTransform<TemplateInstantiator>::TransformDeclRefExpr(E); | ||||
1739 | } | ||||
1740 | |||||
1741 | ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr( | ||||
1742 | CXXDefaultArgExpr *E) { | ||||
1743 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1745, __PRETTY_FUNCTION__)) | ||||
1744 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1745, __PRETTY_FUNCTION__)) | ||||
1745 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1745, __PRETTY_FUNCTION__)); | ||||
1746 | return SemaRef.BuildCXXDefaultArgExpr(E->getUsedLocation(), | ||||
1747 | cast<FunctionDecl>(E->getParam()->getDeclContext()), | ||||
1748 | E->getParam()); | ||||
1749 | } | ||||
1750 | |||||
1751 | template<typename Fn> | ||||
1752 | QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB, | ||||
1753 | FunctionProtoTypeLoc TL, | ||||
1754 | CXXRecordDecl *ThisContext, | ||||
1755 | Qualifiers ThisTypeQuals, | ||||
1756 | Fn TransformExceptionSpec) { | ||||
1757 | // We need a local instantiation scope for this function prototype. | ||||
1758 | LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); | ||||
1759 | return inherited::TransformFunctionProtoType( | ||||
1760 | TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec); | ||||
1761 | } | ||||
1762 | |||||
1763 | ParmVarDecl * | ||||
1764 | TemplateInstantiator::TransformFunctionTypeParam(ParmVarDecl *OldParm, | ||||
1765 | int indexAdjustment, | ||||
1766 | Optional<unsigned> NumExpansions, | ||||
1767 | bool ExpectParameterPack) { | ||||
1768 | auto NewParm = | ||||
1769 | SemaRef.SubstParmVarDecl(OldParm, TemplateArgs, indexAdjustment, | ||||
1770 | NumExpansions, ExpectParameterPack); | ||||
1771 | if (NewParm && SemaRef.getLangOpts().OpenCL) | ||||
1772 | SemaRef.deduceOpenCLAddressSpace(NewParm); | ||||
1773 | return NewParm; | ||||
1774 | } | ||||
1775 | |||||
1776 | QualType | ||||
1777 | TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB, | ||||
1778 | TemplateTypeParmTypeLoc TL) { | ||||
1779 | const TemplateTypeParmType *T = TL.getTypePtr(); | ||||
1780 | if (T->getDepth() < TemplateArgs.getNumLevels()) { | ||||
1781 | // Replace the template type parameter with its corresponding | ||||
1782 | // template argument. | ||||
1783 | |||||
1784 | // If the corresponding template argument is NULL or doesn't exist, it's | ||||
1785 | // because we are performing instantiation from explicitly-specified | ||||
1786 | // template arguments in a function template class, but there were some | ||||
1787 | // arguments left unspecified. | ||||
1788 | if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) { | ||||
1789 | TemplateTypeParmTypeLoc NewTL | ||||
1790 | = TLB.push<TemplateTypeParmTypeLoc>(TL.getType()); | ||||
1791 | NewTL.setNameLoc(TL.getNameLoc()); | ||||
1792 | return TL.getType(); | ||||
1793 | } | ||||
1794 | |||||
1795 | TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex()); | ||||
1796 | |||||
1797 | if (TemplateArgs.isRewrite()) { | ||||
1798 | // We're rewriting the template parameter as a reference to another | ||||
1799 | // template parameter. | ||||
1800 | if (Arg.getKind() == TemplateArgument::Pack) { | ||||
1801 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1802, __PRETTY_FUNCTION__)) | ||||
1802 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1802, __PRETTY_FUNCTION__)); | ||||
1803 | Arg = Arg.pack_begin()->getPackExpansionPattern(); | ||||
1804 | } | ||||
1805 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1806, __PRETTY_FUNCTION__)) | ||||
1806 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1806, __PRETTY_FUNCTION__)); | ||||
1807 | QualType NewT = Arg.getAsType(); | ||||
1808 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1809, __PRETTY_FUNCTION__)) | ||||
1809 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1809, __PRETTY_FUNCTION__)); | ||||
1810 | auto NewTL = TLB.push<TemplateTypeParmTypeLoc>(NewT); | ||||
1811 | NewTL.setNameLoc(TL.getNameLoc()); | ||||
1812 | return NewT; | ||||
1813 | } | ||||
1814 | |||||
1815 | if (T->isParameterPack()) { | ||||
1816 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1817, __PRETTY_FUNCTION__)) | ||||
1817 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1817, __PRETTY_FUNCTION__)); | ||||
1818 | |||||
1819 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||
1820 | // We have the template argument pack, but we're not expanding the | ||||
1821 | // enclosing pack expansion yet. Just save the template argument | ||||
1822 | // pack for later substitution. | ||||
1823 | QualType Result | ||||
1824 | = getSema().Context.getSubstTemplateTypeParmPackType(T, Arg); | ||||
1825 | SubstTemplateTypeParmPackTypeLoc NewTL | ||||
1826 | = TLB.push<SubstTemplateTypeParmPackTypeLoc>(Result); | ||||
1827 | NewTL.setNameLoc(TL.getNameLoc()); | ||||
1828 | return Result; | ||||
1829 | } | ||||
1830 | |||||
1831 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1832 | } | ||||
1833 | |||||
1834 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1835, __PRETTY_FUNCTION__)) | ||||
1835 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1835, __PRETTY_FUNCTION__)); | ||||
1836 | |||||
1837 | QualType Replacement = Arg.getAsType(); | ||||
1838 | |||||
1839 | // TODO: only do this uniquing once, at the start of instantiation. | ||||
1840 | QualType Result | ||||
1841 | = getSema().Context.getSubstTemplateTypeParmType(T, Replacement); | ||||
1842 | SubstTemplateTypeParmTypeLoc NewTL | ||||
1843 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); | ||||
1844 | NewTL.setNameLoc(TL.getNameLoc()); | ||||
1845 | return Result; | ||||
1846 | } | ||||
1847 | |||||
1848 | // The template type parameter comes from an inner template (e.g., | ||||
1849 | // the template parameter list of a member template inside the | ||||
1850 | // template we are instantiating). Create a new template type | ||||
1851 | // parameter with the template "level" reduced by one. | ||||
1852 | TemplateTypeParmDecl *NewTTPDecl = nullptr; | ||||
1853 | if (TemplateTypeParmDecl *OldTTPDecl = T->getDecl()) | ||||
1854 | NewTTPDecl = cast_or_null<TemplateTypeParmDecl>( | ||||
1855 | TransformDecl(TL.getNameLoc(), OldTTPDecl)); | ||||
1856 | |||||
1857 | QualType Result = getSema().Context.getTemplateTypeParmType( | ||||
1858 | T->getDepth() - TemplateArgs.getNumSubstitutedLevels(), T->getIndex(), | ||||
1859 | T->isParameterPack(), NewTTPDecl); | ||||
1860 | TemplateTypeParmTypeLoc NewTL = TLB.push<TemplateTypeParmTypeLoc>(Result); | ||||
1861 | NewTL.setNameLoc(TL.getNameLoc()); | ||||
1862 | return Result; | ||||
1863 | } | ||||
1864 | |||||
1865 | QualType | ||||
1866 | TemplateInstantiator::TransformSubstTemplateTypeParmPackType( | ||||
1867 | TypeLocBuilder &TLB, | ||||
1868 | SubstTemplateTypeParmPackTypeLoc TL) { | ||||
1869 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||
1870 | // We aren't expanding the parameter pack, so just return ourselves. | ||||
1871 | SubstTemplateTypeParmPackTypeLoc NewTL | ||||
1872 | = TLB.push<SubstTemplateTypeParmPackTypeLoc>(TL.getType()); | ||||
1873 | NewTL.setNameLoc(TL.getNameLoc()); | ||||
1874 | return TL.getType(); | ||||
1875 | } | ||||
1876 | |||||
1877 | TemplateArgument Arg = TL.getTypePtr()->getArgumentPack(); | ||||
1878 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1879 | QualType Result = Arg.getAsType(); | ||||
1880 | |||||
1881 | Result = getSema().Context.getSubstTemplateTypeParmType( | ||||
1882 | TL.getTypePtr()->getReplacedParameter(), | ||||
1883 | Result); | ||||
1884 | SubstTemplateTypeParmTypeLoc NewTL | ||||
1885 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); | ||||
1886 | NewTL.setNameLoc(TL.getNameLoc()); | ||||
1887 | return Result; | ||||
1888 | } | ||||
1889 | |||||
1890 | template<typename EntityPrinter> | ||||
1891 | static concepts::Requirement::SubstitutionDiagnostic * | ||||
1892 | createSubstDiag(Sema &S, TemplateDeductionInfo &Info, EntityPrinter Printer) { | ||||
1893 | SmallString<128> Message; | ||||
1894 | SourceLocation ErrorLoc; | ||||
1895 | if (Info.hasSFINAEDiagnostic()) { | ||||
1896 | PartialDiagnosticAt PDA(SourceLocation(), | ||||
1897 | PartialDiagnostic::NullDiagnostic{}); | ||||
1898 | Info.takeSFINAEDiagnostic(PDA); | ||||
1899 | PDA.second.EmitToString(S.getDiagnostics(), Message); | ||||
1900 | ErrorLoc = PDA.first; | ||||
1901 | } else { | ||||
1902 | ErrorLoc = Info.getLocation(); | ||||
1903 | } | ||||
1904 | char *MessageBuf = new (S.Context) char[Message.size()]; | ||||
1905 | std::copy(Message.begin(), Message.end(), MessageBuf); | ||||
1906 | SmallString<128> Entity; | ||||
1907 | llvm::raw_svector_ostream OS(Entity); | ||||
1908 | Printer(OS); | ||||
1909 | char *EntityBuf = new (S.Context) char[Entity.size()]; | ||||
1910 | std::copy(Entity.begin(), Entity.end(), EntityBuf); | ||||
1911 | return new (S.Context) concepts::Requirement::SubstitutionDiagnostic{ | ||||
1912 | StringRef(EntityBuf, Entity.size()), ErrorLoc, | ||||
1913 | StringRef(MessageBuf, Message.size())}; | ||||
1914 | } | ||||
1915 | |||||
1916 | concepts::TypeRequirement * | ||||
1917 | TemplateInstantiator::TransformTypeRequirement(concepts::TypeRequirement *Req) { | ||||
1918 | if (!Req->isDependent() && !AlwaysRebuild()) | ||||
1919 | return Req; | ||||
1920 | if (Req->isSubstitutionFailure()) { | ||||
1921 | if (AlwaysRebuild()) | ||||
1922 | return RebuildTypeRequirement( | ||||
1923 | Req->getSubstitutionDiagnostic()); | ||||
1924 | return Req; | ||||
1925 | } | ||||
1926 | |||||
1927 | Sema::SFINAETrap Trap(SemaRef); | ||||
1928 | TemplateDeductionInfo Info(Req->getType()->getTypeLoc().getBeginLoc()); | ||||
1929 | Sema::InstantiatingTemplate TypeInst(SemaRef, | ||||
1930 | Req->getType()->getTypeLoc().getBeginLoc(), Req, Info, | ||||
1931 | Req->getType()->getTypeLoc().getSourceRange()); | ||||
1932 | if (TypeInst.isInvalid()) | ||||
1933 | return nullptr; | ||||
1934 | TypeSourceInfo *TransType = TransformType(Req->getType()); | ||||
1935 | if (!TransType || Trap.hasErrorOccurred()) | ||||
1936 | return RebuildTypeRequirement(createSubstDiag(SemaRef, Info, | ||||
1937 | [&] (llvm::raw_ostream& OS) { | ||||
1938 | Req->getType()->getType().print(OS, SemaRef.getPrintingPolicy()); | ||||
1939 | })); | ||||
1940 | return RebuildTypeRequirement(TransType); | ||||
1941 | } | ||||
1942 | |||||
1943 | concepts::ExprRequirement * | ||||
1944 | TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) { | ||||
1945 | if (!Req->isDependent() && !AlwaysRebuild()) | ||||
1946 | return Req; | ||||
1947 | |||||
1948 | Sema::SFINAETrap Trap(SemaRef); | ||||
1949 | TemplateDeductionInfo Info(Req->getExpr()->getBeginLoc()); | ||||
1950 | |||||
1951 | llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> | ||||
1952 | TransExpr; | ||||
1953 | if (Req->isExprSubstitutionFailure()) | ||||
1954 | TransExpr = Req->getExprSubstitutionDiagnostic(); | ||||
1955 | else { | ||||
1956 | Sema::InstantiatingTemplate ExprInst(SemaRef, Req->getExpr()->getBeginLoc(), | ||||
1957 | Req, Info, | ||||
1958 | Req->getExpr()->getSourceRange()); | ||||
1959 | if (ExprInst.isInvalid()) | ||||
1960 | return nullptr; | ||||
1961 | ExprResult TransExprRes = TransformExpr(Req->getExpr()); | ||||
1962 | if (TransExprRes.isInvalid() || Trap.hasErrorOccurred()) | ||||
1963 | TransExpr = createSubstDiag(SemaRef, Info, | ||||
1964 | [&] (llvm::raw_ostream& OS) { | ||||
1965 | Req->getExpr()->printPretty(OS, nullptr, | ||||
1966 | SemaRef.getPrintingPolicy()); | ||||
1967 | }); | ||||
1968 | else | ||||
1969 | TransExpr = TransExprRes.get(); | ||||
1970 | } | ||||
1971 | |||||
1972 | llvm::Optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq; | ||||
1973 | const auto &RetReq = Req->getReturnTypeRequirement(); | ||||
1974 | if (RetReq.isEmpty()) | ||||
1975 | TransRetReq.emplace(); | ||||
1976 | else if (RetReq.isSubstitutionFailure()) | ||||
1977 | TransRetReq.emplace(RetReq.getSubstitutionDiagnostic()); | ||||
1978 | else if (RetReq.isTypeConstraint()) { | ||||
1979 | TemplateParameterList *OrigTPL = | ||||
1980 | RetReq.getTypeConstraintTemplateParameterList(); | ||||
1981 | Sema::InstantiatingTemplate TPLInst(SemaRef, OrigTPL->getTemplateLoc(), | ||||
1982 | Req, Info, OrigTPL->getSourceRange()); | ||||
1983 | if (TPLInst.isInvalid()) | ||||
1984 | return nullptr; | ||||
1985 | TemplateParameterList *TPL = | ||||
1986 | TransformTemplateParameterList(OrigTPL); | ||||
1987 | if (!TPL) | ||||
1988 | TransRetReq.emplace(createSubstDiag(SemaRef, Info, | ||||
1989 | [&] (llvm::raw_ostream& OS) { | ||||
1990 | RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint() | ||||
1991 | ->printPretty(OS, nullptr, SemaRef.getPrintingPolicy()); | ||||
1992 | })); | ||||
1993 | else { | ||||
1994 | TPLInst.Clear(); | ||||
1995 | TransRetReq.emplace(TPL); | ||||
1996 | } | ||||
1997 | } | ||||
1998 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1999, __PRETTY_FUNCTION__)) | ||||
1999 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 1999, __PRETTY_FUNCTION__)); | ||||
2000 | if (Expr *E = TransExpr.dyn_cast<Expr *>()) | ||||
2001 | return RebuildExprRequirement(E, Req->isSimple(), Req->getNoexceptLoc(), | ||||
2002 | std::move(*TransRetReq)); | ||||
2003 | return RebuildExprRequirement( | ||||
2004 | TransExpr.get<concepts::Requirement::SubstitutionDiagnostic *>(), | ||||
2005 | Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq)); | ||||
2006 | } | ||||
2007 | |||||
2008 | concepts::NestedRequirement * | ||||
2009 | TemplateInstantiator::TransformNestedRequirement( | ||||
2010 | concepts::NestedRequirement *Req) { | ||||
2011 | if (!Req->isDependent() && !AlwaysRebuild()) | ||||
2012 | return Req; | ||||
2013 | if (Req->isSubstitutionFailure()) { | ||||
2014 | if (AlwaysRebuild()) | ||||
2015 | return RebuildNestedRequirement( | ||||
2016 | Req->getSubstitutionDiagnostic()); | ||||
2017 | return Req; | ||||
2018 | } | ||||
2019 | Sema::InstantiatingTemplate ReqInst(SemaRef, | ||||
2020 | Req->getConstraintExpr()->getBeginLoc(), Req, | ||||
2021 | Sema::InstantiatingTemplate::ConstraintsCheck{}, | ||||
2022 | Req->getConstraintExpr()->getSourceRange()); | ||||
2023 | |||||
2024 | ExprResult TransConstraint; | ||||
2025 | TemplateDeductionInfo Info(Req->getConstraintExpr()->getBeginLoc()); | ||||
2026 | { | ||||
2027 | EnterExpressionEvaluationContext ContextRAII( | ||||
2028 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); | ||||
2029 | Sema::SFINAETrap Trap(SemaRef); | ||||
2030 | Sema::InstantiatingTemplate ConstrInst(SemaRef, | ||||
2031 | Req->getConstraintExpr()->getBeginLoc(), Req, Info, | ||||
2032 | Req->getConstraintExpr()->getSourceRange()); | ||||
2033 | if (ConstrInst.isInvalid()) | ||||
2034 | return nullptr; | ||||
2035 | TransConstraint = TransformExpr(Req->getConstraintExpr()); | ||||
2036 | if (TransConstraint.isInvalid() || Trap.hasErrorOccurred()) | ||||
2037 | return RebuildNestedRequirement(createSubstDiag(SemaRef, Info, | ||||
2038 | [&] (llvm::raw_ostream& OS) { | ||||
2039 | Req->getConstraintExpr()->printPretty(OS, nullptr, | ||||
2040 | SemaRef.getPrintingPolicy()); | ||||
2041 | })); | ||||
2042 | } | ||||
2043 | return RebuildNestedRequirement(TransConstraint.get()); | ||||
2044 | } | ||||
2045 | |||||
2046 | |||||
2047 | /// Perform substitution on the type T with a given set of template | ||||
2048 | /// arguments. | ||||
2049 | /// | ||||
2050 | /// This routine substitutes the given template arguments into the | ||||
2051 | /// type T and produces the instantiated type. | ||||
2052 | /// | ||||
2053 | /// \param T the type into which the template arguments will be | ||||
2054 | /// substituted. If this type is not dependent, it will be returned | ||||
2055 | /// immediately. | ||||
2056 | /// | ||||
2057 | /// \param Args the template arguments that will be | ||||
2058 | /// substituted for the top-level template parameters within T. | ||||
2059 | /// | ||||
2060 | /// \param Loc the location in the source code where this substitution | ||||
2061 | /// is being performed. It will typically be the location of the | ||||
2062 | /// declarator (if we're instantiating the type of some declaration) | ||||
2063 | /// or the location of the type in the source code (if, e.g., we're | ||||
2064 | /// instantiating the type of a cast expression). | ||||
2065 | /// | ||||
2066 | /// \param Entity the name of the entity associated with a declaration | ||||
2067 | /// being instantiated (if any). May be empty to indicate that there | ||||
2068 | /// is no such entity (if, e.g., this is a type that occurs as part of | ||||
2069 | /// a cast expression) or that the entity has no name (e.g., an | ||||
2070 | /// unnamed function parameter). | ||||
2071 | /// | ||||
2072 | /// \param AllowDeducedTST Whether a DeducedTemplateSpecializationType is | ||||
2073 | /// acceptable as the top level type of the result. | ||||
2074 | /// | ||||
2075 | /// \returns If the instantiation succeeds, the instantiated | ||||
2076 | /// type. Otherwise, produces diagnostics and returns a NULL type. | ||||
2077 | TypeSourceInfo *Sema::SubstType(TypeSourceInfo *T, | ||||
2078 | const MultiLevelTemplateArgumentList &Args, | ||||
2079 | SourceLocation Loc, | ||||
2080 | DeclarationName Entity, | ||||
2081 | bool AllowDeducedTST) { | ||||
2082 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2084, __PRETTY_FUNCTION__)) | ||||
2083 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2084, __PRETTY_FUNCTION__)) | ||||
2084 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2084, __PRETTY_FUNCTION__)); | ||||
2085 | |||||
2086 | if (!T->getType()->isInstantiationDependentType() && | ||||
2087 | !T->getType()->isVariablyModifiedType()) | ||||
2088 | return T; | ||||
2089 | |||||
2090 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | ||||
2091 | return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(T) | ||||
2092 | : Instantiator.TransformType(T); | ||||
2093 | } | ||||
2094 | |||||
2095 | TypeSourceInfo *Sema::SubstType(TypeLoc TL, | ||||
2096 | const MultiLevelTemplateArgumentList &Args, | ||||
2097 | SourceLocation Loc, | ||||
2098 | DeclarationName Entity) { | ||||
2099 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2101, __PRETTY_FUNCTION__)) | ||||
2100 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2101, __PRETTY_FUNCTION__)) | ||||
2101 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2101, __PRETTY_FUNCTION__)); | ||||
2102 | |||||
2103 | if (TL.getType().isNull()) | ||||
2104 | return nullptr; | ||||
2105 | |||||
2106 | if (!TL.getType()->isInstantiationDependentType() && | ||||
2107 | !TL.getType()->isVariablyModifiedType()) { | ||||
2108 | // FIXME: Make a copy of the TypeLoc data here, so that we can | ||||
2109 | // return a new TypeSourceInfo. Inefficient! | ||||
2110 | TypeLocBuilder TLB; | ||||
2111 | TLB.pushFullCopy(TL); | ||||
2112 | return TLB.getTypeSourceInfo(Context, TL.getType()); | ||||
2113 | } | ||||
2114 | |||||
2115 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | ||||
2116 | TypeLocBuilder TLB; | ||||
2117 | TLB.reserve(TL.getFullDataSize()); | ||||
2118 | QualType Result = Instantiator.TransformType(TLB, TL); | ||||
2119 | if (Result.isNull()) | ||||
2120 | return nullptr; | ||||
2121 | |||||
2122 | return TLB.getTypeSourceInfo(Context, Result); | ||||
2123 | } | ||||
2124 | |||||
2125 | /// Deprecated form of the above. | ||||
2126 | QualType Sema::SubstType(QualType T, | ||||
2127 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||
2128 | SourceLocation Loc, DeclarationName Entity) { | ||||
2129 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2131, __PRETTY_FUNCTION__)) | ||||
2130 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2131, __PRETTY_FUNCTION__)) | ||||
2131 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2131, __PRETTY_FUNCTION__)); | ||||
2132 | |||||
2133 | // If T is not a dependent type or a variably-modified type, there | ||||
2134 | // is nothing to do. | ||||
2135 | if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType()) | ||||
2136 | return T; | ||||
2137 | |||||
2138 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity); | ||||
2139 | return Instantiator.TransformType(T); | ||||
2140 | } | ||||
2141 | |||||
2142 | static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) { | ||||
2143 | if (T->getType()->isInstantiationDependentType() || | ||||
2144 | T->getType()->isVariablyModifiedType()) | ||||
2145 | return true; | ||||
2146 | |||||
2147 | TypeLoc TL = T->getTypeLoc().IgnoreParens(); | ||||
2148 | if (!TL.getAs<FunctionProtoTypeLoc>()) | ||||
2149 | return false; | ||||
2150 | |||||
2151 | FunctionProtoTypeLoc FP = TL.castAs<FunctionProtoTypeLoc>(); | ||||
2152 | for (ParmVarDecl *P : FP.getParams()) { | ||||
2153 | // This must be synthesized from a typedef. | ||||
2154 | if (!P) continue; | ||||
2155 | |||||
2156 | // If there are any parameters, a new TypeSourceInfo that refers to the | ||||
2157 | // instantiated parameters must be built. | ||||
2158 | return true; | ||||
2159 | } | ||||
2160 | |||||
2161 | return false; | ||||
2162 | } | ||||
2163 | |||||
2164 | /// A form of SubstType intended specifically for instantiating the | ||||
2165 | /// type of a FunctionDecl. Its purpose is solely to force the | ||||
2166 | /// instantiation of default-argument expressions and to avoid | ||||
2167 | /// instantiating an exception-specification. | ||||
2168 | TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T, | ||||
2169 | const MultiLevelTemplateArgumentList &Args, | ||||
2170 | SourceLocation Loc, | ||||
2171 | DeclarationName Entity, | ||||
2172 | CXXRecordDecl *ThisContext, | ||||
2173 | Qualifiers ThisTypeQuals) { | ||||
2174 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2176, __PRETTY_FUNCTION__)) | ||||
2175 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2176, __PRETTY_FUNCTION__)) | ||||
2176 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2176, __PRETTY_FUNCTION__)); | ||||
2177 | |||||
2178 | if (!NeedsInstantiationAsFunctionType(T)) | ||||
2179 | return T; | ||||
2180 | |||||
2181 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | ||||
2182 | |||||
2183 | TypeLocBuilder TLB; | ||||
2184 | |||||
2185 | TypeLoc TL = T->getTypeLoc(); | ||||
2186 | TLB.reserve(TL.getFullDataSize()); | ||||
2187 | |||||
2188 | QualType Result; | ||||
2189 | |||||
2190 | if (FunctionProtoTypeLoc Proto = | ||||
2191 | TL.IgnoreParens().getAs<FunctionProtoTypeLoc>()) { | ||||
2192 | // Instantiate the type, other than its exception specification. The | ||||
2193 | // exception specification is instantiated in InitFunctionInstantiation | ||||
2194 | // once we've built the FunctionDecl. | ||||
2195 | // FIXME: Set the exception specification to EST_Uninstantiated here, | ||||
2196 | // instead of rebuilding the function type again later. | ||||
2197 | Result = Instantiator.TransformFunctionProtoType( | ||||
2198 | TLB, Proto, ThisContext, ThisTypeQuals, | ||||
2199 | [](FunctionProtoType::ExceptionSpecInfo &ESI, | ||||
2200 | bool &Changed) { return false; }); | ||||
2201 | } else { | ||||
2202 | Result = Instantiator.TransformType(TLB, TL); | ||||
2203 | } | ||||
2204 | if (Result.isNull()) | ||||
2205 | return nullptr; | ||||
2206 | |||||
2207 | return TLB.getTypeSourceInfo(Context, Result); | ||||
2208 | } | ||||
2209 | |||||
2210 | bool Sema::SubstExceptionSpec(SourceLocation Loc, | ||||
2211 | FunctionProtoType::ExceptionSpecInfo &ESI, | ||||
2212 | SmallVectorImpl<QualType> &ExceptionStorage, | ||||
2213 | const MultiLevelTemplateArgumentList &Args) { | ||||
2214 | assert(ESI.Type != EST_Uninstantiated)((ESI.Type != EST_Uninstantiated) ? static_cast<void> ( 0) : __assert_fail ("ESI.Type != EST_Uninstantiated", "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2214, __PRETTY_FUNCTION__)); | ||||
2215 | |||||
2216 | bool Changed = false; | ||||
2217 | TemplateInstantiator Instantiator(*this, Args, Loc, DeclarationName()); | ||||
2218 | return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage, | ||||
2219 | Changed); | ||||
2220 | } | ||||
2221 | |||||
2222 | void Sema::SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, | ||||
2223 | const MultiLevelTemplateArgumentList &Args) { | ||||
2224 | FunctionProtoType::ExceptionSpecInfo ESI = | ||||
2225 | Proto->getExtProtoInfo().ExceptionSpec; | ||||
2226 | |||||
2227 | SmallVector<QualType, 4> ExceptionStorage; | ||||
2228 | if (SubstExceptionSpec(New->getTypeSourceInfo()->getTypeLoc().getEndLoc(), | ||||
2229 | ESI, ExceptionStorage, Args)) | ||||
2230 | // On error, recover by dropping the exception specification. | ||||
2231 | ESI.Type = EST_None; | ||||
2232 | |||||
2233 | UpdateExceptionSpec(New, ESI); | ||||
2234 | } | ||||
2235 | |||||
2236 | namespace { | ||||
2237 | |||||
2238 | struct GetContainedInventedTypeParmVisitor : | ||||
2239 | public TypeVisitor<GetContainedInventedTypeParmVisitor, | ||||
2240 | TemplateTypeParmDecl *> { | ||||
2241 | using TypeVisitor<GetContainedInventedTypeParmVisitor, | ||||
2242 | TemplateTypeParmDecl *>::Visit; | ||||
2243 | |||||
2244 | TemplateTypeParmDecl *Visit(QualType T) { | ||||
2245 | if (T.isNull()) | ||||
2246 | return nullptr; | ||||
2247 | return Visit(T.getTypePtr()); | ||||
2248 | } | ||||
2249 | // The deduced type itself. | ||||
2250 | TemplateTypeParmDecl *VisitTemplateTypeParmType( | ||||
2251 | const TemplateTypeParmType *T) { | ||||
2252 | if (!T->getDecl() || !T->getDecl()->isImplicit()) | ||||
2253 | return nullptr; | ||||
2254 | return T->getDecl(); | ||||
2255 | } | ||||
2256 | |||||
2257 | // Only these types can contain 'auto' types, and subsequently be replaced | ||||
2258 | // by references to invented parameters. | ||||
2259 | |||||
2260 | TemplateTypeParmDecl *VisitElaboratedType(const ElaboratedType *T) { | ||||
2261 | return Visit(T->getNamedType()); | ||||
2262 | } | ||||
2263 | |||||
2264 | TemplateTypeParmDecl *VisitPointerType(const PointerType *T) { | ||||
2265 | return Visit(T->getPointeeType()); | ||||
2266 | } | ||||
2267 | |||||
2268 | TemplateTypeParmDecl *VisitBlockPointerType(const BlockPointerType *T) { | ||||
2269 | return Visit(T->getPointeeType()); | ||||
2270 | } | ||||
2271 | |||||
2272 | TemplateTypeParmDecl *VisitReferenceType(const ReferenceType *T) { | ||||
2273 | return Visit(T->getPointeeTypeAsWritten()); | ||||
2274 | } | ||||
2275 | |||||
2276 | TemplateTypeParmDecl *VisitMemberPointerType(const MemberPointerType *T) { | ||||
2277 | return Visit(T->getPointeeType()); | ||||
2278 | } | ||||
2279 | |||||
2280 | TemplateTypeParmDecl *VisitArrayType(const ArrayType *T) { | ||||
2281 | return Visit(T->getElementType()); | ||||
2282 | } | ||||
2283 | |||||
2284 | TemplateTypeParmDecl *VisitDependentSizedExtVectorType( | ||||
2285 | const DependentSizedExtVectorType *T) { | ||||
2286 | return Visit(T->getElementType()); | ||||
2287 | } | ||||
2288 | |||||
2289 | TemplateTypeParmDecl *VisitVectorType(const VectorType *T) { | ||||
2290 | return Visit(T->getElementType()); | ||||
2291 | } | ||||
2292 | |||||
2293 | TemplateTypeParmDecl *VisitFunctionProtoType(const FunctionProtoType *T) { | ||||
2294 | return VisitFunctionType(T); | ||||
2295 | } | ||||
2296 | |||||
2297 | TemplateTypeParmDecl *VisitFunctionType(const FunctionType *T) { | ||||
2298 | return Visit(T->getReturnType()); | ||||
2299 | } | ||||
2300 | |||||
2301 | TemplateTypeParmDecl *VisitParenType(const ParenType *T) { | ||||
2302 | return Visit(T->getInnerType()); | ||||
2303 | } | ||||
2304 | |||||
2305 | TemplateTypeParmDecl *VisitAttributedType(const AttributedType *T) { | ||||
2306 | return Visit(T->getModifiedType()); | ||||
2307 | } | ||||
2308 | |||||
2309 | TemplateTypeParmDecl *VisitMacroQualifiedType(const MacroQualifiedType *T) { | ||||
2310 | return Visit(T->getUnderlyingType()); | ||||
2311 | } | ||||
2312 | |||||
2313 | TemplateTypeParmDecl *VisitAdjustedType(const AdjustedType *T) { | ||||
2314 | return Visit(T->getOriginalType()); | ||||
2315 | } | ||||
2316 | |||||
2317 | TemplateTypeParmDecl *VisitPackExpansionType(const PackExpansionType *T) { | ||||
2318 | return Visit(T->getPattern()); | ||||
2319 | } | ||||
2320 | }; | ||||
2321 | |||||
2322 | } // namespace | ||||
2323 | |||||
2324 | ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm, | ||||
2325 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||
2326 | int indexAdjustment, | ||||
2327 | Optional<unsigned> NumExpansions, | ||||
2328 | bool ExpectParameterPack) { | ||||
2329 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); | ||||
2330 | TypeSourceInfo *NewDI = nullptr; | ||||
2331 | |||||
2332 | TypeLoc OldTL = OldDI->getTypeLoc(); | ||||
2333 | if (PackExpansionTypeLoc ExpansionTL = OldTL.getAs<PackExpansionTypeLoc>()) { | ||||
2334 | |||||
2335 | // We have a function parameter pack. Substitute into the pattern of the | ||||
2336 | // expansion. | ||||
2337 | NewDI = SubstType(ExpansionTL.getPatternLoc(), TemplateArgs, | ||||
2338 | OldParm->getLocation(), OldParm->getDeclName()); | ||||
2339 | if (!NewDI) | ||||
2340 | return nullptr; | ||||
2341 | |||||
2342 | if (NewDI->getType()->containsUnexpandedParameterPack()) { | ||||
2343 | // We still have unexpanded parameter packs, which means that | ||||
2344 | // our function parameter is still a function parameter pack. | ||||
2345 | // Therefore, make its type a pack expansion type. | ||||
2346 | NewDI = CheckPackExpansion(NewDI, ExpansionTL.getEllipsisLoc(), | ||||
2347 | NumExpansions); | ||||
2348 | } else if (ExpectParameterPack) { | ||||
2349 | // We expected to get a parameter pack but didn't (because the type | ||||
2350 | // itself is not a pack expansion type), so complain. This can occur when | ||||
2351 | // the substitution goes through an alias template that "loses" the | ||||
2352 | // pack expansion. | ||||
2353 | Diag(OldParm->getLocation(), | ||||
2354 | diag::err_function_parameter_pack_without_parameter_packs) | ||||
2355 | << NewDI->getType(); | ||||
2356 | return nullptr; | ||||
2357 | } | ||||
2358 | } else { | ||||
2359 | NewDI = SubstType(OldDI, TemplateArgs, OldParm->getLocation(), | ||||
2360 | OldParm->getDeclName()); | ||||
2361 | } | ||||
2362 | |||||
2363 | if (!NewDI) | ||||
2364 | return nullptr; | ||||
2365 | |||||
2366 | if (NewDI->getType()->isVoidType()) { | ||||
2367 | Diag(OldParm->getLocation(), diag::err_param_with_void_type); | ||||
2368 | return nullptr; | ||||
2369 | } | ||||
2370 | |||||
2371 | // In abbreviated templates, TemplateTypeParmDecls with possible | ||||
2372 | // TypeConstraints are created when the parameter list is originally parsed. | ||||
2373 | // The TypeConstraints can therefore reference other functions parameters in | ||||
2374 | // the abbreviated function template, which is why we must instantiate them | ||||
2375 | // here, when the instantiated versions of those referenced parameters are in | ||||
2376 | // scope. | ||||
2377 | if (TemplateTypeParmDecl *TTP = | ||||
2378 | GetContainedInventedTypeParmVisitor().Visit(OldDI->getType())) { | ||||
2379 | if (const TypeConstraint *TC = TTP->getTypeConstraint()) { | ||||
2380 | auto *Inst = cast_or_null<TemplateTypeParmDecl>( | ||||
2381 | FindInstantiatedDecl(TTP->getLocation(), TTP, TemplateArgs)); | ||||
2382 | // We will first get here when instantiating the abbreviated function | ||||
2383 | // template's described function, but we might also get here later. | ||||
2384 | // Make sure we do not instantiate the TypeConstraint more than once. | ||||
2385 | if (Inst && !Inst->getTypeConstraint()) { | ||||
2386 | // TODO: Concepts: do not instantiate the constraint (delayed constraint | ||||
2387 | // substitution) | ||||
2388 | const ASTTemplateArgumentListInfo *TemplArgInfo | ||||
2389 | = TC->getTemplateArgsAsWritten(); | ||||
2390 | TemplateArgumentListInfo InstArgs; | ||||
2391 | |||||
2392 | if (TemplArgInfo) { | ||||
2393 | InstArgs.setLAngleLoc(TemplArgInfo->LAngleLoc); | ||||
2394 | InstArgs.setRAngleLoc(TemplArgInfo->RAngleLoc); | ||||
2395 | if (Subst(TemplArgInfo->getTemplateArgs(), | ||||
2396 | TemplArgInfo->NumTemplateArgs, InstArgs, TemplateArgs)) | ||||
2397 | return nullptr; | ||||
2398 | } | ||||
2399 | if (AttachTypeConstraint( | ||||
2400 | TC->getNestedNameSpecifierLoc(), TC->getConceptNameInfo(), | ||||
2401 | TC->getNamedConcept(), &InstArgs, Inst, | ||||
2402 | TTP->isParameterPack() | ||||
2403 | ? cast<CXXFoldExpr>(TC->getImmediatelyDeclaredConstraint()) | ||||
2404 | ->getEllipsisLoc() | ||||
2405 | : SourceLocation())) | ||||
2406 | return nullptr; | ||||
2407 | } | ||||
2408 | } | ||||
2409 | } | ||||
2410 | |||||
2411 | ParmVarDecl *NewParm = CheckParameter(Context.getTranslationUnitDecl(), | ||||
2412 | OldParm->getInnerLocStart(), | ||||
2413 | OldParm->getLocation(), | ||||
2414 | OldParm->getIdentifier(), | ||||
2415 | NewDI->getType(), NewDI, | ||||
2416 | OldParm->getStorageClass()); | ||||
2417 | if (!NewParm) | ||||
2418 | return nullptr; | ||||
2419 | |||||
2420 | // Mark the (new) default argument as uninstantiated (if any). | ||||
2421 | if (OldParm->hasUninstantiatedDefaultArg()) { | ||||
2422 | Expr *Arg = OldParm->getUninstantiatedDefaultArg(); | ||||
2423 | NewParm->setUninstantiatedDefaultArg(Arg); | ||||
2424 | } else if (OldParm->hasUnparsedDefaultArg()) { | ||||
2425 | NewParm->setUnparsedDefaultArg(); | ||||
2426 | UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm); | ||||
2427 | } else if (Expr *Arg = OldParm->getDefaultArg()) { | ||||
2428 | FunctionDecl *OwningFunc = cast<FunctionDecl>(OldParm->getDeclContext()); | ||||
2429 | if (OwningFunc->isInLocalScopeForInstantiation()) { | ||||
2430 | // Instantiate default arguments for methods of local classes (DR1484) | ||||
2431 | // and non-defining declarations. | ||||
2432 | Sema::ContextRAII SavedContext(*this, OwningFunc); | ||||
2433 | LocalInstantiationScope Local(*this, true); | ||||
2434 | ExprResult NewArg = SubstExpr(Arg, TemplateArgs); | ||||
2435 | if (NewArg.isUsable()) { | ||||
2436 | // It would be nice if we still had this. | ||||
2437 | SourceLocation EqualLoc = NewArg.get()->getBeginLoc(); | ||||
2438 | ExprResult Result = | ||||
2439 | ConvertParamDefaultArgument(NewParm, NewArg.get(), EqualLoc); | ||||
2440 | if (Result.isInvalid()) | ||||
2441 | return nullptr; | ||||
2442 | |||||
2443 | SetParamDefaultArgument(NewParm, Result.getAs<Expr>(), EqualLoc); | ||||
2444 | } | ||||
2445 | } else { | ||||
2446 | // FIXME: if we non-lazily instantiated non-dependent default args for | ||||
2447 | // non-dependent parameter types we could remove a bunch of duplicate | ||||
2448 | // conversion warnings for such arguments. | ||||
2449 | NewParm->setUninstantiatedDefaultArg(Arg); | ||||
2450 | } | ||||
2451 | } | ||||
2452 | |||||
2453 | NewParm->setHasInheritedDefaultArg(OldParm->hasInheritedDefaultArg()); | ||||
2454 | |||||
2455 | if (OldParm->isParameterPack() && !NewParm->isParameterPack()) { | ||||
2456 | // Add the new parameter to the instantiated parameter pack. | ||||
2457 | CurrentInstantiationScope->InstantiatedLocalPackArg(OldParm, NewParm); | ||||
2458 | } else { | ||||
2459 | // Introduce an Old -> New mapping | ||||
2460 | CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm); | ||||
2461 | } | ||||
2462 | |||||
2463 | // FIXME: OldParm may come from a FunctionProtoType, in which case CurContext | ||||
2464 | // can be anything, is this right ? | ||||
2465 | NewParm->setDeclContext(CurContext); | ||||
2466 | |||||
2467 | NewParm->setScopeInfo(OldParm->getFunctionScopeDepth(), | ||||
2468 | OldParm->getFunctionScopeIndex() + indexAdjustment); | ||||
2469 | |||||
2470 | InstantiateAttrs(TemplateArgs, OldParm, NewParm); | ||||
2471 | |||||
2472 | return NewParm; | ||||
2473 | } | ||||
2474 | |||||
2475 | /// Substitute the given template arguments into the given set of | ||||
2476 | /// parameters, producing the set of parameter types that would be generated | ||||
2477 | /// from such a substitution. | ||||
2478 | bool Sema::SubstParmTypes( | ||||
2479 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, | ||||
2480 | const FunctionProtoType::ExtParameterInfo *ExtParamInfos, | ||||
2481 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||
2482 | SmallVectorImpl<QualType> &ParamTypes, | ||||
2483 | SmallVectorImpl<ParmVarDecl *> *OutParams, | ||||
2484 | ExtParameterInfoBuilder &ParamInfos) { | ||||
2485 | 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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2487, __PRETTY_FUNCTION__)) | ||||
2486 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2487, __PRETTY_FUNCTION__)) | ||||
2487 | "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~++20200927111121+5811d723998/clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2487, __PRETTY_FUNCTION__)); | ||||
2488 | |||||
2489 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, | ||||
2490 | DeclarationName()); | ||||
2491 | return Instantiator.TransformFunctionTypeParams( | ||||
2492 | Loc, Params, nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos); | ||||
2493 | } | ||||
2494 | |||||
2495 | /// Perform substitution on the base class specifiers of the | ||||
2496 | /// given class template specialization. | ||||
2497 | /// | ||||
2498 | /// Produces a diagnostic and returns true on error, returns false and | ||||
2499 | /// attaches the instantiated base classes to the class template | ||||
2500 | /// specialization if successful. | ||||
2501 | bool | ||||
2502 | Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, | ||||
2503 | CXXRecordDecl *Pattern, | ||||
2504 | const MultiLevelTemplateArgumentList &TemplateArgs) { | ||||
2505 | bool Invalid = false; | ||||
2506 | SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases; | ||||
2507 | for (const auto &Base : Pattern->bases()) { | ||||
2508 | if (!Base.getType()->isDependentType()) { | ||||
2509 | if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl()) { | ||||
2510 | if (RD->isInvalidDecl()) | ||||
2511 | Instantiation->setInvalidDecl(); | ||||
2512 | } | ||||
2513 | InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(Base)); | ||||
2514 | continue; | ||||
2515 | } | ||||
2516 | |||||
2517 | SourceLocation EllipsisLoc; | ||||
2518 | TypeSourceInfo *BaseTypeLoc; | ||||
2519 | if (Base.isPackExpansion()) { | ||||
2520 | // This is a pack expansion. See whether we should expand it now, or | ||||
2521 | // wait until later. | ||||
2522 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; | ||||
2523 | collectUnexpandedParameterPacks(Base.getTypeSourceInfo()->getTypeLoc(), | ||||
2524 | Unexpanded); | ||||
2525 | bool ShouldExpand = false; | ||||
2526 | bool RetainExpansion = false; | ||||
2527 | Optional<unsigned> NumExpansions; | ||||
2528 | if (CheckParameterPacksForExpansion(Base.getEllipsisLoc(), | ||||
2529 | Base.getSourceRange(), | ||||
2530 | Unexpanded, | ||||
2531 | TemplateArgs, ShouldExpand, | ||||
2532 | RetainExpansion, | ||||
2533 | NumExpansions)) { | ||||
2534 | Invalid = true; | ||||
2535 | continue; | ||||
2536 | } | ||||
2537 | |||||
2538 | // If we should expand this pack expansion now, do so. | ||||
2539 | if (ShouldExpand) { | ||||
2540 | for (unsigned I = 0; I != *NumExpansions; ++I) { | ||||
2541 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I); | ||||
2542 | |||||
2543 | TypeSourceInfo *BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | ||||
2544 | TemplateArgs, | ||||
2545 | Base.getSourceRange().getBegin(), | ||||
2546 | DeclarationName()); | ||||
2547 | if (!BaseTypeLoc) { | ||||
2548 | Invalid = true; | ||||
2549 | continue; | ||||
2550 | } | ||||
2551 | |||||
2552 | if (CXXBaseSpecifier *InstantiatedBase | ||||
2553 | = CheckBaseSpecifier(Instantiation, | ||||
2554 | Base.getSourceRange(), | ||||
2555 | Base.isVirtual(), | ||||
2556 | Base.getAccessSpecifierAsWritten(), | ||||
2557 | BaseTypeLoc, | ||||
2558 | SourceLocation())) | ||||
2559 | InstantiatedBases.push_back(InstantiatedBase); | ||||
2560 | else | ||||
2561 | Invalid = true; | ||||
2562 | } | ||||
2563 | |||||
2564 | continue; | ||||
2565 | } | ||||
2566 | |||||
2567 | // The resulting base specifier will (still) be a pack expansion. | ||||
2568 | EllipsisLoc = Base.getEllipsisLoc(); | ||||
2569 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1); | ||||
2570 | BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | ||||
2571 | TemplateArgs, | ||||
2572 | Base.getSourceRange().getBegin(), | ||||
2573 | DeclarationName()); | ||||
2574 | } else { | ||||
2575 | BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | ||||
2576 | TemplateArgs, | ||||
2577 | Base.getSourceRange().getBegin(), | ||||
2578 | DeclarationName()); | ||||
2579 | } | ||||
2580 | |||||
2581 | if (!BaseTypeLoc) { | ||||
2582 | Invalid = true; | ||||
2583 | continue; | ||||
2584 | } | ||||
2585 | |||||
2586 | if (CXXBaseSpecifier *InstantiatedBase | ||||
2587 | = CheckBaseSpecifier(Instantiation, | ||||
2588 | Base.getSourceRange(), | ||||
2589 | Base.isVirtual(), | ||||
2590 | Base.getAccessSpecifierAsWritten(), | ||||
2591 | BaseTypeLoc, | ||||
2592 | EllipsisLoc)) | ||||
2593 | InstantiatedBases.push_back(InstantiatedBase); | ||||
2594 | else | ||||
2595 | Invalid = true; | ||||
2596 | } | ||||
2597 | |||||
2598 | if (!Invalid && AttachBaseSpecifiers(Instantiation, InstantiatedBases)) | ||||
2599 | Invalid = true; | ||||
2600 | |||||
2601 | return Invalid; | ||||
2602 | } | ||||
2603 | |||||
2604 | // Defined via #include from SemaTemplateInstantiateDecl.cpp | ||||
2605 | namespace clang { | ||||
2606 | namespace sema { | ||||
2607 | Attr *instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S, | ||||
2608 | const MultiLevelTemplateArgumentList &TemplateArgs); | ||||
2609 | Attr *instantiateTemplateAttributeForDecl( | ||||
2610 | const Attr *At, ASTContext &C, Sema &S, | ||||
2611 | const MultiLevelTemplateArgumentList &TemplateArgs); | ||||
2612 | } | ||||
2613 | } | ||||
2614 | |||||
2615 | /// Instantiate the definition of a class from a given pattern. | ||||
2616 | /// | ||||
2617 | /// \param PointOfInstantiation The point of instantiation within the | ||||
2618 | /// source code. | ||||
2619 | /// | ||||
2620 | /// \param Instantiation is the declaration whose definition is being | ||||
2621 | /// instantiated. This will be either a class template specialization | ||||
2622 | /// or a member class of a class template specialization. | ||||
2623 | /// | ||||
2624 | /// \param Pattern is the pattern from which the instantiation | ||||
2625 | /// occurs. This will be either the declaration of a class template or | ||||
2626 | /// the declaration of a member class of a class template. | ||||
2627 | /// | ||||
2628 | /// \param TemplateArgs The template arguments to be substituted into | ||||
2629 | /// the pattern. | ||||
2630 | /// | ||||
2631 | /// \param TSK the kind of implicit or explicit instantiation to perform. | ||||
2632 | /// | ||||
2633 | /// \param Complain whether to complain if the class cannot be instantiated due | ||||
2634 | /// to the lack of a definition. | ||||
2635 | /// | ||||
2636 | /// \returns true if an error occurred, false otherwise. | ||||
2637 | bool | ||||
2638 | Sema::InstantiateClass(SourceLocation PointOfInstantiation, | ||||
2639 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, | ||||
2640 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||
2641 | TemplateSpecializationKind TSK, | ||||
2642 | bool Complain) { | ||||
2643 | CXXRecordDecl *PatternDef | ||||
2644 | = cast_or_null<CXXRecordDecl>(Pattern->getDefinition()); | ||||
2645 | if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation, | ||||
2646 | Instantiation->getInstantiatedFromMemberClass(), | ||||
2647 | Pattern, PatternDef, TSK, Complain)) | ||||
2648 | return true; | ||||
2649 | |||||
2650 | llvm::TimeTraceScope TimeScope("InstantiateClass", [&]() { | ||||
2651 | std::string Name; | ||||
2652 | llvm::raw_string_ostream OS(Name); | ||||
2653 | Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(), | ||||
2654 | /*Qualified=*/true); | ||||
2655 | return Name; | ||||
2656 | }); | ||||
2657 | |||||
2658 | Pattern = PatternDef; | ||||
2659 | |||||
2660 | // Record the point of instantiation. | ||||
2661 | if (MemberSpecializationInfo *MSInfo | ||||
2662 | = Instantiation->getMemberSpecializationInfo()) { | ||||
2663 | MSInfo->setTemplateSpecializationKind(TSK); | ||||
2664 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | ||||
2665 | } else if (ClassTemplateSpecializationDecl *Spec
|
32.1 | 'Spec' is null |
63 | Called C++ object pointer is null |
1 | Assuming 'TSK' is not equal to TSK_ExplicitInstantiationDefinition |
5.1 | 'Function' is null |
5.1 | 'Function' is null |
7.1 | 'Var' is null |
7.1 | 'Var' is null |
9.1 | 'Record' is non-null |
9.1 | 'Record' is non-null |
1 | //===--- Sema.h - Semantic Analysis & AST Building --------------*- 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 | // |
9 | // This file defines the Sema class, which performs semantic analysis and |
10 | // builds ASTs. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef LLVM_CLANG_SEMA_SEMA_H |
15 | #define LLVM_CLANG_SEMA_SEMA_H |
16 | |
17 | #include "clang/AST/ASTConcept.h" |
18 | #include "clang/AST/ASTFwd.h" |
19 | #include "clang/AST/Attr.h" |
20 | #include "clang/AST/Availability.h" |
21 | #include "clang/AST/ComparisonCategories.h" |
22 | #include "clang/AST/DeclTemplate.h" |
23 | #include "clang/AST/DeclarationName.h" |
24 | #include "clang/AST/Expr.h" |
25 | #include "clang/AST/ExprCXX.h" |
26 | #include "clang/AST/ExprConcepts.h" |
27 | #include "clang/AST/ExprObjC.h" |
28 | #include "clang/AST/ExprOpenMP.h" |
29 | #include "clang/AST/ExternalASTSource.h" |
30 | #include "clang/AST/LocInfoType.h" |
31 | #include "clang/AST/MangleNumberingContext.h" |
32 | #include "clang/AST/NSAPI.h" |
33 | #include "clang/AST/PrettyPrinter.h" |
34 | #include "clang/AST/StmtCXX.h" |
35 | #include "clang/AST/TypeLoc.h" |
36 | #include "clang/AST/TypeOrdering.h" |
37 | #include "clang/Basic/BitmaskEnum.h" |
38 | #include "clang/Basic/ExpressionTraits.h" |
39 | #include "clang/Basic/Module.h" |
40 | #include "clang/Basic/OpenCLOptions.h" |
41 | #include "clang/Basic/OpenMPKinds.h" |
42 | #include "clang/Basic/PragmaKinds.h" |
43 | #include "clang/Basic/Specifiers.h" |
44 | #include "clang/Basic/TemplateKinds.h" |
45 | #include "clang/Basic/TypeTraits.h" |
46 | #include "clang/Sema/AnalysisBasedWarnings.h" |
47 | #include "clang/Sema/CleanupInfo.h" |
48 | #include "clang/Sema/DeclSpec.h" |
49 | #include "clang/Sema/ExternalSemaSource.h" |
50 | #include "clang/Sema/IdentifierResolver.h" |
51 | #include "clang/Sema/ObjCMethodList.h" |
52 | #include "clang/Sema/Ownership.h" |
53 | #include "clang/Sema/Scope.h" |
54 | #include "clang/Sema/SemaConcept.h" |
55 | #include "clang/Sema/TypoCorrection.h" |
56 | #include "clang/Sema/Weak.h" |
57 | #include "llvm/ADT/ArrayRef.h" |
58 | #include "llvm/ADT/Optional.h" |
59 | #include "llvm/ADT/SetVector.h" |
60 | #include "llvm/ADT/SmallBitVector.h" |
61 | #include "llvm/ADT/SmallSet.h" |
62 | #include "llvm/ADT/SmallPtrSet.h" |
63 | #include "llvm/ADT/SmallVector.h" |
64 | #include "llvm/ADT/TinyPtrVector.h" |
65 | #include "llvm/Frontend/OpenMP/OMPConstants.h" |
66 | #include <deque> |
67 | #include <memory> |
68 | #include <string> |
69 | #include <tuple> |
70 | #include <vector> |
71 | |
72 | namespace llvm { |
73 | class APSInt; |
74 | template <typename ValueT> struct DenseMapInfo; |
75 | template <typename ValueT, typename ValueInfoT> class DenseSet; |
76 | class SmallBitVector; |
77 | struct InlineAsmIdentifierInfo; |
78 | } |
79 | |
80 | namespace clang { |
81 | class ADLResult; |
82 | class ASTConsumer; |
83 | class ASTContext; |
84 | class ASTMutationListener; |
85 | class ASTReader; |
86 | class ASTWriter; |
87 | class ArrayType; |
88 | class ParsedAttr; |
89 | class BindingDecl; |
90 | class BlockDecl; |
91 | class CapturedDecl; |
92 | class CXXBasePath; |
93 | class CXXBasePaths; |
94 | class CXXBindTemporaryExpr; |
95 | typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; |
96 | class CXXConstructorDecl; |
97 | class CXXConversionDecl; |
98 | class CXXDeleteExpr; |
99 | class CXXDestructorDecl; |
100 | class CXXFieldCollector; |
101 | class CXXMemberCallExpr; |
102 | class CXXMethodDecl; |
103 | class CXXScopeSpec; |
104 | class CXXTemporary; |
105 | class CXXTryStmt; |
106 | class CallExpr; |
107 | class ClassTemplateDecl; |
108 | class ClassTemplatePartialSpecializationDecl; |
109 | class ClassTemplateSpecializationDecl; |
110 | class VarTemplatePartialSpecializationDecl; |
111 | class CodeCompleteConsumer; |
112 | class CodeCompletionAllocator; |
113 | class CodeCompletionTUInfo; |
114 | class CodeCompletionResult; |
115 | class CoroutineBodyStmt; |
116 | class Decl; |
117 | class DeclAccessPair; |
118 | class DeclContext; |
119 | class DeclRefExpr; |
120 | class DeclaratorDecl; |
121 | class DeducedTemplateArgument; |
122 | class DependentDiagnostic; |
123 | class DesignatedInitExpr; |
124 | class Designation; |
125 | class EnableIfAttr; |
126 | class EnumConstantDecl; |
127 | class Expr; |
128 | class ExtVectorType; |
129 | class FormatAttr; |
130 | class FriendDecl; |
131 | class FunctionDecl; |
132 | class FunctionProtoType; |
133 | class FunctionTemplateDecl; |
134 | class ImplicitConversionSequence; |
135 | typedef MutableArrayRef<ImplicitConversionSequence> ConversionSequenceList; |
136 | class InitListExpr; |
137 | class InitializationKind; |
138 | class InitializationSequence; |
139 | class InitializedEntity; |
140 | class IntegerLiteral; |
141 | class LabelStmt; |
142 | class LambdaExpr; |
143 | class LangOptions; |
144 | class LocalInstantiationScope; |
145 | class LookupResult; |
146 | class MacroInfo; |
147 | typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> ModuleIdPath; |
148 | class ModuleLoader; |
149 | class MultiLevelTemplateArgumentList; |
150 | class NamedDecl; |
151 | class ObjCCategoryDecl; |
152 | class ObjCCategoryImplDecl; |
153 | class ObjCCompatibleAliasDecl; |
154 | class ObjCContainerDecl; |
155 | class ObjCImplDecl; |
156 | class ObjCImplementationDecl; |
157 | class ObjCInterfaceDecl; |
158 | class ObjCIvarDecl; |
159 | template <class T> class ObjCList; |
160 | class ObjCMessageExpr; |
161 | class ObjCMethodDecl; |
162 | class ObjCPropertyDecl; |
163 | class ObjCProtocolDecl; |
164 | class OMPThreadPrivateDecl; |
165 | class OMPRequiresDecl; |
166 | class OMPDeclareReductionDecl; |
167 | class OMPDeclareSimdDecl; |
168 | class OMPClause; |
169 | struct OMPVarListLocTy; |
170 | struct OverloadCandidate; |
171 | enum class OverloadCandidateParamOrder : char; |
172 | enum OverloadCandidateRewriteKind : unsigned; |
173 | class OverloadCandidateSet; |
174 | class OverloadExpr; |
175 | class ParenListExpr; |
176 | class ParmVarDecl; |
177 | class Preprocessor; |
178 | class PseudoDestructorTypeStorage; |
179 | class PseudoObjectExpr; |
180 | class QualType; |
181 | class StandardConversionSequence; |
182 | class Stmt; |
183 | class StringLiteral; |
184 | class SwitchStmt; |
185 | class TemplateArgument; |
186 | class TemplateArgumentList; |
187 | class TemplateArgumentLoc; |
188 | class TemplateDecl; |
189 | class TemplateInstantiationCallback; |
190 | class TemplateParameterList; |
191 | class TemplatePartialOrderingContext; |
192 | class TemplateTemplateParmDecl; |
193 | class Token; |
194 | class TypeAliasDecl; |
195 | class TypedefDecl; |
196 | class TypedefNameDecl; |
197 | class TypeLoc; |
198 | class TypoCorrectionConsumer; |
199 | class UnqualifiedId; |
200 | class UnresolvedLookupExpr; |
201 | class UnresolvedMemberExpr; |
202 | class UnresolvedSetImpl; |
203 | class UnresolvedSetIterator; |
204 | class UsingDecl; |
205 | class UsingShadowDecl; |
206 | class ValueDecl; |
207 | class VarDecl; |
208 | class VarTemplateSpecializationDecl; |
209 | class VisibilityAttr; |
210 | class VisibleDeclConsumer; |
211 | class IndirectFieldDecl; |
212 | struct DeductionFailureInfo; |
213 | class TemplateSpecCandidateSet; |
214 | |
215 | namespace sema { |
216 | class AccessedEntity; |
217 | class BlockScopeInfo; |
218 | class Capture; |
219 | class CapturedRegionScopeInfo; |
220 | class CapturingScopeInfo; |
221 | class CompoundScopeInfo; |
222 | class DelayedDiagnostic; |
223 | class DelayedDiagnosticPool; |
224 | class FunctionScopeInfo; |
225 | class LambdaScopeInfo; |
226 | class PossiblyUnreachableDiag; |
227 | class SemaPPCallbacks; |
228 | class TemplateDeductionInfo; |
229 | } |
230 | |
231 | namespace threadSafety { |
232 | class BeforeSet; |
233 | void threadSafetyCleanup(BeforeSet* Cache); |
234 | } |
235 | |
236 | // FIXME: No way to easily map from TemplateTypeParmTypes to |
237 | // TemplateTypeParmDecls, so we have this horrible PointerUnion. |
238 | typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>, |
239 | SourceLocation> UnexpandedParameterPack; |
240 | |
241 | /// Describes whether we've seen any nullability information for the given |
242 | /// file. |
243 | struct FileNullability { |
244 | /// The first pointer declarator (of any pointer kind) in the file that does |
245 | /// not have a corresponding nullability annotation. |
246 | SourceLocation PointerLoc; |
247 | |
248 | /// The end location for the first pointer declarator in the file. Used for |
249 | /// placing fix-its. |
250 | SourceLocation PointerEndLoc; |
251 | |
252 | /// Which kind of pointer declarator we saw. |
253 | uint8_t PointerKind; |
254 | |
255 | /// Whether we saw any type nullability annotations in the given file. |
256 | bool SawTypeNullability = false; |
257 | }; |
258 | |
259 | /// A mapping from file IDs to a record of whether we've seen nullability |
260 | /// information in that file. |
261 | class FileNullabilityMap { |
262 | /// A mapping from file IDs to the nullability information for each file ID. |
263 | llvm::DenseMap<FileID, FileNullability> Map; |
264 | |
265 | /// A single-element cache based on the file ID. |
266 | struct { |
267 | FileID File; |
268 | FileNullability Nullability; |
269 | } Cache; |
270 | |
271 | public: |
272 | FileNullability &operator[](FileID file) { |
273 | // Check the single-element cache. |
274 | if (file == Cache.File) |
275 | return Cache.Nullability; |
276 | |
277 | // It's not in the single-element cache; flush the cache if we have one. |
278 | if (!Cache.File.isInvalid()) { |
279 | Map[Cache.File] = Cache.Nullability; |
280 | } |
281 | |
282 | // Pull this entry into the cache. |
283 | Cache.File = file; |
284 | Cache.Nullability = Map[file]; |
285 | return Cache.Nullability; |
286 | } |
287 | }; |
288 | |
289 | /// Keeps track of expected type during expression parsing. The type is tied to |
290 | /// a particular token, all functions that update or consume the type take a |
291 | /// start location of the token they are looking at as a parameter. This allows |
292 | /// to avoid updating the type on hot paths in the parser. |
293 | class PreferredTypeBuilder { |
294 | public: |
295 | PreferredTypeBuilder() = default; |
296 | explicit PreferredTypeBuilder(QualType Type) : Type(Type) {} |
297 | |
298 | void enterCondition(Sema &S, SourceLocation Tok); |
299 | void enterReturn(Sema &S, SourceLocation Tok); |
300 | void enterVariableInit(SourceLocation Tok, Decl *D); |
301 | /// Computing a type for the function argument may require running |
302 | /// overloading, so we postpone its computation until it is actually needed. |
303 | /// |
304 | /// Clients should be very careful when using this funciton, as it stores a |
305 | /// function_ref, clients should make sure all calls to get() with the same |
306 | /// location happen while function_ref is alive. |
307 | void enterFunctionArgument(SourceLocation Tok, |
308 | llvm::function_ref<QualType()> ComputeType); |
309 | |
310 | void enterParenExpr(SourceLocation Tok, SourceLocation LParLoc); |
311 | void enterUnary(Sema &S, SourceLocation Tok, tok::TokenKind OpKind, |
312 | SourceLocation OpLoc); |
313 | void enterBinary(Sema &S, SourceLocation Tok, Expr *LHS, tok::TokenKind Op); |
314 | void enterMemAccess(Sema &S, SourceLocation Tok, Expr *Base); |
315 | void enterSubscript(Sema &S, SourceLocation Tok, Expr *LHS); |
316 | /// Handles all type casts, including C-style cast, C++ casts, etc. |
317 | void enterTypeCast(SourceLocation Tok, QualType CastType); |
318 | |
319 | QualType get(SourceLocation Tok) const { |
320 | if (Tok != ExpectedLoc) |
321 | return QualType(); |
322 | if (!Type.isNull()) |
323 | return Type; |
324 | if (ComputeType) |
325 | return ComputeType(); |
326 | return QualType(); |
327 | } |
328 | |
329 | private: |
330 | /// Start position of a token for which we store expected type. |
331 | SourceLocation ExpectedLoc; |
332 | /// Expected type for a token starting at ExpectedLoc. |
333 | QualType Type; |
334 | /// A function to compute expected type at ExpectedLoc. It is only considered |
335 | /// if Type is null. |
336 | llvm::function_ref<QualType()> ComputeType; |
337 | }; |
338 | |
339 | /// Sema - This implements semantic analysis and AST building for C. |
340 | class Sema final { |
341 | Sema(const Sema &) = delete; |
342 | void operator=(const Sema &) = delete; |
343 | |
344 | /// A key method to reduce duplicate debug info from Sema. |
345 | virtual void anchor(); |
346 | |
347 | ///Source of additional semantic information. |
348 | ExternalSemaSource *ExternalSource; |
349 | |
350 | ///Whether Sema has generated a multiplexer and has to delete it. |
351 | bool isMultiplexExternalSource; |
352 | |
353 | static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD); |
354 | |
355 | bool isVisibleSlow(const NamedDecl *D); |
356 | |
357 | /// Determine whether two declarations should be linked together, given that |
358 | /// the old declaration might not be visible and the new declaration might |
359 | /// not have external linkage. |
360 | bool shouldLinkPossiblyHiddenDecl(const NamedDecl *Old, |
361 | const NamedDecl *New) { |
362 | if (isVisible(Old)) |
363 | return true; |
364 | // See comment in below overload for why it's safe to compute the linkage |
365 | // of the new declaration here. |
366 | if (New->isExternallyDeclarable()) { |
367 | assert(Old->isExternallyDeclarable() &&((Old->isExternallyDeclarable() && "should not have found a non-externally-declarable previous decl" ) ? static_cast<void> (0) : __assert_fail ("Old->isExternallyDeclarable() && \"should not have found a non-externally-declarable previous decl\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 368, __PRETTY_FUNCTION__)) |
368 | "should not have found a non-externally-declarable previous decl")((Old->isExternallyDeclarable() && "should not have found a non-externally-declarable previous decl" ) ? static_cast<void> (0) : __assert_fail ("Old->isExternallyDeclarable() && \"should not have found a non-externally-declarable previous decl\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 368, __PRETTY_FUNCTION__)); |
369 | return true; |
370 | } |
371 | return false; |
372 | } |
373 | bool shouldLinkPossiblyHiddenDecl(LookupResult &Old, const NamedDecl *New); |
374 | |
375 | void setupImplicitSpecialMemberType(CXXMethodDecl *SpecialMem, |
376 | QualType ResultTy, |
377 | ArrayRef<QualType> Args); |
378 | |
379 | public: |
380 | /// The maximum alignment, same as in llvm::Value. We duplicate them here |
381 | /// because that allows us not to duplicate the constants in clang code, |
382 | /// which we must to since we can't directly use the llvm constants. |
383 | /// The value is verified against llvm here: lib/CodeGen/CGDecl.cpp |
384 | /// |
385 | /// This is the greatest alignment value supported by load, store, and alloca |
386 | /// instructions, and global values. |
387 | static const unsigned MaxAlignmentExponent = 29; |
388 | static const unsigned MaximumAlignment = 1u << MaxAlignmentExponent; |
389 | |
390 | typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; |
391 | typedef OpaquePtr<TemplateName> TemplateTy; |
392 | typedef OpaquePtr<QualType> TypeTy; |
393 | |
394 | OpenCLOptions OpenCLFeatures; |
395 | FPOptions CurFPFeatures; |
396 | |
397 | const LangOptions &LangOpts; |
398 | Preprocessor &PP; |
399 | ASTContext &Context; |
400 | ASTConsumer &Consumer; |
401 | DiagnosticsEngine &Diags; |
402 | SourceManager &SourceMgr; |
403 | |
404 | /// Flag indicating whether or not to collect detailed statistics. |
405 | bool CollectStats; |
406 | |
407 | /// Code-completion consumer. |
408 | CodeCompleteConsumer *CodeCompleter; |
409 | |
410 | /// CurContext - This is the current declaration context of parsing. |
411 | DeclContext *CurContext; |
412 | |
413 | /// Generally null except when we temporarily switch decl contexts, |
414 | /// like in \see ActOnObjCTemporaryExitContainerContext. |
415 | DeclContext *OriginalLexicalContext; |
416 | |
417 | /// VAListTagName - The declaration name corresponding to __va_list_tag. |
418 | /// This is used as part of a hack to omit that class from ADL results. |
419 | DeclarationName VAListTagName; |
420 | |
421 | bool MSStructPragmaOn; // True when \#pragma ms_struct on |
422 | |
423 | /// Controls member pointer representation format under the MS ABI. |
424 | LangOptions::PragmaMSPointersToMembersKind |
425 | MSPointerToMemberRepresentationMethod; |
426 | |
427 | /// Stack of active SEH __finally scopes. Can be empty. |
428 | SmallVector<Scope*, 2> CurrentSEHFinally; |
429 | |
430 | /// Source location for newly created implicit MSInheritanceAttrs |
431 | SourceLocation ImplicitMSInheritanceAttrLoc; |
432 | |
433 | /// Holds TypoExprs that are created from `createDelayedTypo`. This is used by |
434 | /// `TransformTypos` in order to keep track of any TypoExprs that are created |
435 | /// recursively during typo correction and wipe them away if the correction |
436 | /// fails. |
437 | llvm::SmallVector<TypoExpr *, 2> TypoExprs; |
438 | |
439 | /// pragma clang section kind |
440 | enum PragmaClangSectionKind { |
441 | PCSK_Invalid = 0, |
442 | PCSK_BSS = 1, |
443 | PCSK_Data = 2, |
444 | PCSK_Rodata = 3, |
445 | PCSK_Text = 4, |
446 | PCSK_Relro = 5 |
447 | }; |
448 | |
449 | enum PragmaClangSectionAction { |
450 | PCSA_Set = 0, |
451 | PCSA_Clear = 1 |
452 | }; |
453 | |
454 | struct PragmaClangSection { |
455 | std::string SectionName; |
456 | bool Valid = false; |
457 | SourceLocation PragmaLocation; |
458 | |
459 | void Act(SourceLocation PragmaLocation, |
460 | PragmaClangSectionAction Action, |
461 | StringLiteral* Name); |
462 | }; |
463 | |
464 | PragmaClangSection PragmaClangBSSSection; |
465 | PragmaClangSection PragmaClangDataSection; |
466 | PragmaClangSection PragmaClangRodataSection; |
467 | PragmaClangSection PragmaClangRelroSection; |
468 | PragmaClangSection PragmaClangTextSection; |
469 | |
470 | enum PragmaMsStackAction { |
471 | PSK_Reset = 0x0, // #pragma () |
472 | PSK_Set = 0x1, // #pragma (value) |
473 | PSK_Push = 0x2, // #pragma (push[, id]) |
474 | PSK_Pop = 0x4, // #pragma (pop[, id]) |
475 | PSK_Show = 0x8, // #pragma (show) -- only for "pack"! |
476 | PSK_Push_Set = PSK_Push | PSK_Set, // #pragma (push[, id], value) |
477 | PSK_Pop_Set = PSK_Pop | PSK_Set, // #pragma (pop[, id], value) |
478 | }; |
479 | |
480 | template<typename ValueType> |
481 | struct PragmaStack { |
482 | struct Slot { |
483 | llvm::StringRef StackSlotLabel; |
484 | ValueType Value; |
485 | SourceLocation PragmaLocation; |
486 | SourceLocation PragmaPushLocation; |
487 | Slot(llvm::StringRef StackSlotLabel, ValueType Value, |
488 | SourceLocation PragmaLocation, SourceLocation PragmaPushLocation) |
489 | : StackSlotLabel(StackSlotLabel), Value(Value), |
490 | PragmaLocation(PragmaLocation), |
491 | PragmaPushLocation(PragmaPushLocation) {} |
492 | }; |
493 | |
494 | void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, |
495 | llvm::StringRef StackSlotLabel, ValueType Value) { |
496 | if (Action == PSK_Reset) { |
497 | CurrentValue = DefaultValue; |
498 | CurrentPragmaLocation = PragmaLocation; |
499 | return; |
500 | } |
501 | if (Action & PSK_Push) |
502 | Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation, |
503 | PragmaLocation); |
504 | else if (Action & PSK_Pop) { |
505 | if (!StackSlotLabel.empty()) { |
506 | // If we've got a label, try to find it and jump there. |
507 | auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) { |
508 | return x.StackSlotLabel == StackSlotLabel; |
509 | }); |
510 | // If we found the label so pop from there. |
511 | if (I != Stack.rend()) { |
512 | CurrentValue = I->Value; |
513 | CurrentPragmaLocation = I->PragmaLocation; |
514 | Stack.erase(std::prev(I.base()), Stack.end()); |
515 | } |
516 | } else if (!Stack.empty()) { |
517 | // We do not have a label, just pop the last entry. |
518 | CurrentValue = Stack.back().Value; |
519 | CurrentPragmaLocation = Stack.back().PragmaLocation; |
520 | Stack.pop_back(); |
521 | } |
522 | } |
523 | if (Action & PSK_Set) { |
524 | CurrentValue = Value; |
525 | CurrentPragmaLocation = PragmaLocation; |
526 | } |
527 | } |
528 | |
529 | // MSVC seems to add artificial slots to #pragma stacks on entering a C++ |
530 | // method body to restore the stacks on exit, so it works like this: |
531 | // |
532 | // struct S { |
533 | // #pragma <name>(push, InternalPragmaSlot, <current_pragma_value>) |
534 | // void Method {} |
535 | // #pragma <name>(pop, InternalPragmaSlot) |
536 | // }; |
537 | // |
538 | // It works even with #pragma vtordisp, although MSVC doesn't support |
539 | // #pragma vtordisp(push [, id], n) |
540 | // syntax. |
541 | // |
542 | // Push / pop a named sentinel slot. |
543 | void SentinelAction(PragmaMsStackAction Action, StringRef Label) { |
544 | assert((Action == PSK_Push || Action == PSK_Pop) &&(((Action == PSK_Push || Action == PSK_Pop) && "Can only push / pop #pragma stack sentinels!" ) ? static_cast<void> (0) : __assert_fail ("(Action == PSK_Push || Action == PSK_Pop) && \"Can only push / pop #pragma stack sentinels!\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 545, __PRETTY_FUNCTION__)) |
545 | "Can only push / pop #pragma stack sentinels!")(((Action == PSK_Push || Action == PSK_Pop) && "Can only push / pop #pragma stack sentinels!" ) ? static_cast<void> (0) : __assert_fail ("(Action == PSK_Push || Action == PSK_Pop) && \"Can only push / pop #pragma stack sentinels!\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 545, __PRETTY_FUNCTION__)); |
546 | Act(CurrentPragmaLocation, Action, Label, CurrentValue); |
547 | } |
548 | |
549 | // Constructors. |
550 | explicit PragmaStack(const ValueType &Default) |
551 | : DefaultValue(Default), CurrentValue(Default) {} |
552 | |
553 | bool hasValue() const { return CurrentValue != DefaultValue; } |
554 | |
555 | SmallVector<Slot, 2> Stack; |
556 | ValueType DefaultValue; // Value used for PSK_Reset action. |
557 | ValueType CurrentValue; |
558 | SourceLocation CurrentPragmaLocation; |
559 | }; |
560 | // FIXME: We should serialize / deserialize these if they occur in a PCH (but |
561 | // we shouldn't do so if they're in a module). |
562 | |
563 | /// Whether to insert vtordisps prior to virtual bases in the Microsoft |
564 | /// C++ ABI. Possible values are 0, 1, and 2, which mean: |
565 | /// |
566 | /// 0: Suppress all vtordisps |
567 | /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial |
568 | /// structors |
569 | /// 2: Always insert vtordisps to support RTTI on partially constructed |
570 | /// objects |
571 | PragmaStack<MSVtorDispMode> VtorDispStack; |
572 | // #pragma pack. |
573 | // Sentinel to represent when the stack is set to mac68k alignment. |
574 | static const unsigned kMac68kAlignmentSentinel = ~0U; |
575 | PragmaStack<unsigned> PackStack; |
576 | // The current #pragma pack values and locations at each #include. |
577 | struct PackIncludeState { |
578 | unsigned CurrentValue; |
579 | SourceLocation CurrentPragmaLocation; |
580 | bool HasNonDefaultValue, ShouldWarnOnInclude; |
581 | }; |
582 | SmallVector<PackIncludeState, 8> PackIncludeStack; |
583 | // Segment #pragmas. |
584 | PragmaStack<StringLiteral *> DataSegStack; |
585 | PragmaStack<StringLiteral *> BSSSegStack; |
586 | PragmaStack<StringLiteral *> ConstSegStack; |
587 | PragmaStack<StringLiteral *> CodeSegStack; |
588 | |
589 | // This stack tracks the current state of Sema.CurFPFeatures. |
590 | PragmaStack<FPOptionsOverride> FpPragmaStack; |
591 | FPOptionsOverride CurFPFeatureOverrides() { |
592 | FPOptionsOverride result; |
593 | if (!FpPragmaStack.hasValue()) { |
594 | result = FPOptionsOverride(); |
595 | } else { |
596 | result = FpPragmaStack.CurrentValue; |
597 | } |
598 | return result; |
599 | } |
600 | |
601 | // RAII object to push / pop sentinel slots for all MS #pragma stacks. |
602 | // Actions should be performed only if we enter / exit a C++ method body. |
603 | class PragmaStackSentinelRAII { |
604 | public: |
605 | PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct); |
606 | ~PragmaStackSentinelRAII(); |
607 | |
608 | private: |
609 | Sema &S; |
610 | StringRef SlotLabel; |
611 | bool ShouldAct; |
612 | }; |
613 | |
614 | /// A mapping that describes the nullability we've seen in each header file. |
615 | FileNullabilityMap NullabilityMap; |
616 | |
617 | /// Last section used with #pragma init_seg. |
618 | StringLiteral *CurInitSeg; |
619 | SourceLocation CurInitSegLoc; |
620 | |
621 | /// VisContext - Manages the stack for \#pragma GCC visibility. |
622 | void *VisContext; // Really a "PragmaVisStack*" |
623 | |
624 | /// This an attribute introduced by \#pragma clang attribute. |
625 | struct PragmaAttributeEntry { |
626 | SourceLocation Loc; |
627 | ParsedAttr *Attribute; |
628 | SmallVector<attr::SubjectMatchRule, 4> MatchRules; |
629 | bool IsUsed; |
630 | }; |
631 | |
632 | /// A push'd group of PragmaAttributeEntries. |
633 | struct PragmaAttributeGroup { |
634 | /// The location of the push attribute. |
635 | SourceLocation Loc; |
636 | /// The namespace of this push group. |
637 | const IdentifierInfo *Namespace; |
638 | SmallVector<PragmaAttributeEntry, 2> Entries; |
639 | }; |
640 | |
641 | SmallVector<PragmaAttributeGroup, 2> PragmaAttributeStack; |
642 | |
643 | /// The declaration that is currently receiving an attribute from the |
644 | /// #pragma attribute stack. |
645 | const Decl *PragmaAttributeCurrentTargetDecl; |
646 | |
647 | /// This represents the last location of a "#pragma clang optimize off" |
648 | /// directive if such a directive has not been closed by an "on" yet. If |
649 | /// optimizations are currently "on", this is set to an invalid location. |
650 | SourceLocation OptimizeOffPragmaLocation; |
651 | |
652 | /// Flag indicating if Sema is building a recovery call expression. |
653 | /// |
654 | /// This flag is used to avoid building recovery call expressions |
655 | /// if Sema is already doing so, which would cause infinite recursions. |
656 | bool IsBuildingRecoveryCallExpr; |
657 | |
658 | /// Used to control the generation of ExprWithCleanups. |
659 | CleanupInfo Cleanup; |
660 | |
661 | /// ExprCleanupObjects - This is the stack of objects requiring |
662 | /// cleanup that are created by the current full expression. |
663 | SmallVector<ExprWithCleanups::CleanupObject, 8> ExprCleanupObjects; |
664 | |
665 | /// Store a set of either DeclRefExprs or MemberExprs that contain a reference |
666 | /// to a variable (constant) that may or may not be odr-used in this Expr, and |
667 | /// we won't know until all lvalue-to-rvalue and discarded value conversions |
668 | /// have been applied to all subexpressions of the enclosing full expression. |
669 | /// This is cleared at the end of each full expression. |
670 | using MaybeODRUseExprSet = llvm::SetVector<Expr *, SmallVector<Expr *, 4>, |
671 | llvm::SmallPtrSet<Expr *, 4>>; |
672 | MaybeODRUseExprSet MaybeODRUseExprs; |
673 | |
674 | std::unique_ptr<sema::FunctionScopeInfo> CachedFunctionScope; |
675 | |
676 | /// Stack containing information about each of the nested |
677 | /// function, block, and method scopes that are currently active. |
678 | SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes; |
679 | |
680 | /// The index of the first FunctionScope that corresponds to the current |
681 | /// context. |
682 | unsigned FunctionScopesStart = 0; |
683 | |
684 | ArrayRef<sema::FunctionScopeInfo*> getFunctionScopes() const { |
685 | return llvm::makeArrayRef(FunctionScopes.begin() + FunctionScopesStart, |
686 | FunctionScopes.end()); |
687 | } |
688 | |
689 | /// Stack containing information needed when in C++2a an 'auto' is encountered |
690 | /// in a function declaration parameter type specifier in order to invent a |
691 | /// corresponding template parameter in the enclosing abbreviated function |
692 | /// template. This information is also present in LambdaScopeInfo, stored in |
693 | /// the FunctionScopes stack. |
694 | SmallVector<InventedTemplateParameterInfo, 4> InventedParameterInfos; |
695 | |
696 | /// The index of the first InventedParameterInfo that refers to the current |
697 | /// context. |
698 | unsigned InventedParameterInfosStart = 0; |
699 | |
700 | ArrayRef<InventedTemplateParameterInfo> getInventedParameterInfos() const { |
701 | return llvm::makeArrayRef(InventedParameterInfos.begin() + |
702 | InventedParameterInfosStart, |
703 | InventedParameterInfos.end()); |
704 | } |
705 | |
706 | typedef LazyVector<TypedefNameDecl *, ExternalSemaSource, |
707 | &ExternalSemaSource::ReadExtVectorDecls, 2, 2> |
708 | ExtVectorDeclsType; |
709 | |
710 | /// ExtVectorDecls - This is a list all the extended vector types. This allows |
711 | /// us to associate a raw vector type with one of the ext_vector type names. |
712 | /// This is only necessary for issuing pretty diagnostics. |
713 | ExtVectorDeclsType ExtVectorDecls; |
714 | |
715 | /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. |
716 | std::unique_ptr<CXXFieldCollector> FieldCollector; |
717 | |
718 | typedef llvm::SmallSetVector<NamedDecl *, 16> NamedDeclSetType; |
719 | |
720 | /// Set containing all declared private fields that are not used. |
721 | NamedDeclSetType UnusedPrivateFields; |
722 | |
723 | /// Set containing all typedefs that are likely unused. |
724 | llvm::SmallSetVector<const TypedefNameDecl *, 4> |
725 | UnusedLocalTypedefNameCandidates; |
726 | |
727 | /// Delete-expressions to be analyzed at the end of translation unit |
728 | /// |
729 | /// This list contains class members, and locations of delete-expressions |
730 | /// that could not be proven as to whether they mismatch with new-expression |
731 | /// used in initializer of the field. |
732 | typedef std::pair<SourceLocation, bool> DeleteExprLoc; |
733 | typedef llvm::SmallVector<DeleteExprLoc, 4> DeleteLocs; |
734 | llvm::MapVector<FieldDecl *, DeleteLocs> DeleteExprs; |
735 | |
736 | typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy; |
737 | |
738 | /// PureVirtualClassDiagSet - a set of class declarations which we have |
739 | /// emitted a list of pure virtual functions. Used to prevent emitting the |
740 | /// same list more than once. |
741 | std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet; |
742 | |
743 | /// ParsingInitForAutoVars - a set of declarations with auto types for which |
744 | /// we are currently parsing the initializer. |
745 | llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars; |
746 | |
747 | /// Look for a locally scoped extern "C" declaration by the given name. |
748 | NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name); |
749 | |
750 | typedef LazyVector<VarDecl *, ExternalSemaSource, |
751 | &ExternalSemaSource::ReadTentativeDefinitions, 2, 2> |
752 | TentativeDefinitionsType; |
753 | |
754 | /// All the tentative definitions encountered in the TU. |
755 | TentativeDefinitionsType TentativeDefinitions; |
756 | |
757 | /// All the external declarations encoutered and used in the TU. |
758 | SmallVector<VarDecl *, 4> ExternalDeclarations; |
759 | |
760 | typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource, |
761 | &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2> |
762 | UnusedFileScopedDeclsType; |
763 | |
764 | /// The set of file scoped decls seen so far that have not been used |
765 | /// and must warn if not used. Only contains the first declaration. |
766 | UnusedFileScopedDeclsType UnusedFileScopedDecls; |
767 | |
768 | typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource, |
769 | &ExternalSemaSource::ReadDelegatingConstructors, 2, 2> |
770 | DelegatingCtorDeclsType; |
771 | |
772 | /// All the delegating constructors seen so far in the file, used for |
773 | /// cycle detection at the end of the TU. |
774 | DelegatingCtorDeclsType DelegatingCtorDecls; |
775 | |
776 | /// All the overriding functions seen during a class definition |
777 | /// that had their exception spec checks delayed, plus the overridden |
778 | /// function. |
779 | SmallVector<std::pair<const CXXMethodDecl*, const CXXMethodDecl*>, 2> |
780 | DelayedOverridingExceptionSpecChecks; |
781 | |
782 | /// All the function redeclarations seen during a class definition that had |
783 | /// their exception spec checks delayed, plus the prior declaration they |
784 | /// should be checked against. Except during error recovery, the new decl |
785 | /// should always be a friend declaration, as that's the only valid way to |
786 | /// redeclare a special member before its class is complete. |
787 | SmallVector<std::pair<FunctionDecl*, FunctionDecl*>, 2> |
788 | DelayedEquivalentExceptionSpecChecks; |
789 | |
790 | typedef llvm::MapVector<const FunctionDecl *, |
791 | std::unique_ptr<LateParsedTemplate>> |
792 | LateParsedTemplateMapT; |
793 | LateParsedTemplateMapT LateParsedTemplateMap; |
794 | |
795 | /// Callback to the parser to parse templated functions when needed. |
796 | typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT); |
797 | typedef void LateTemplateParserCleanupCB(void *P); |
798 | LateTemplateParserCB *LateTemplateParser; |
799 | LateTemplateParserCleanupCB *LateTemplateParserCleanup; |
800 | void *OpaqueParser; |
801 | |
802 | void SetLateTemplateParser(LateTemplateParserCB *LTP, |
803 | LateTemplateParserCleanupCB *LTPCleanup, |
804 | void *P) { |
805 | LateTemplateParser = LTP; |
806 | LateTemplateParserCleanup = LTPCleanup; |
807 | OpaqueParser = P; |
808 | } |
809 | |
810 | class DelayedDiagnostics; |
811 | |
812 | class DelayedDiagnosticsState { |
813 | sema::DelayedDiagnosticPool *SavedPool; |
814 | friend class Sema::DelayedDiagnostics; |
815 | }; |
816 | typedef DelayedDiagnosticsState ParsingDeclState; |
817 | typedef DelayedDiagnosticsState ProcessingContextState; |
818 | |
819 | /// A class which encapsulates the logic for delaying diagnostics |
820 | /// during parsing and other processing. |
821 | class DelayedDiagnostics { |
822 | /// The current pool of diagnostics into which delayed |
823 | /// diagnostics should go. |
824 | sema::DelayedDiagnosticPool *CurPool; |
825 | |
826 | public: |
827 | DelayedDiagnostics() : CurPool(nullptr) {} |
828 | |
829 | /// Adds a delayed diagnostic. |
830 | void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h |
831 | |
832 | /// Determines whether diagnostics should be delayed. |
833 | bool shouldDelayDiagnostics() { return CurPool != nullptr; } |
834 | |
835 | /// Returns the current delayed-diagnostics pool. |
836 | sema::DelayedDiagnosticPool *getCurrentPool() const { |
837 | return CurPool; |
838 | } |
839 | |
840 | /// Enter a new scope. Access and deprecation diagnostics will be |
841 | /// collected in this pool. |
842 | DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) { |
843 | DelayedDiagnosticsState state; |
844 | state.SavedPool = CurPool; |
845 | CurPool = &pool; |
846 | return state; |
847 | } |
848 | |
849 | /// Leave a delayed-diagnostic state that was previously pushed. |
850 | /// Do not emit any of the diagnostics. This is performed as part |
851 | /// of the bookkeeping of popping a pool "properly". |
852 | void popWithoutEmitting(DelayedDiagnosticsState state) { |
853 | CurPool = state.SavedPool; |
854 | } |
855 | |
856 | /// Enter a new scope where access and deprecation diagnostics are |
857 | /// not delayed. |
858 | DelayedDiagnosticsState pushUndelayed() { |
859 | DelayedDiagnosticsState state; |
860 | state.SavedPool = CurPool; |
861 | CurPool = nullptr; |
862 | return state; |
863 | } |
864 | |
865 | /// Undo a previous pushUndelayed(). |
866 | void popUndelayed(DelayedDiagnosticsState state) { |
867 | assert(CurPool == nullptr)((CurPool == nullptr) ? static_cast<void> (0) : __assert_fail ("CurPool == nullptr", "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 867, __PRETTY_FUNCTION__)); |
868 | CurPool = state.SavedPool; |
869 | } |
870 | } DelayedDiagnostics; |
871 | |
872 | /// A RAII object to temporarily push a declaration context. |
873 | class ContextRAII { |
874 | private: |
875 | Sema &S; |
876 | DeclContext *SavedContext; |
877 | ProcessingContextState SavedContextState; |
878 | QualType SavedCXXThisTypeOverride; |
879 | unsigned SavedFunctionScopesStart; |
880 | unsigned SavedInventedParameterInfosStart; |
881 | |
882 | public: |
883 | ContextRAII(Sema &S, DeclContext *ContextToPush, bool NewThisContext = true) |
884 | : S(S), SavedContext(S.CurContext), |
885 | SavedContextState(S.DelayedDiagnostics.pushUndelayed()), |
886 | SavedCXXThisTypeOverride(S.CXXThisTypeOverride), |
887 | SavedFunctionScopesStart(S.FunctionScopesStart), |
888 | SavedInventedParameterInfosStart(S.InventedParameterInfosStart) |
889 | { |
890 | assert(ContextToPush && "pushing null context")((ContextToPush && "pushing null context") ? static_cast <void> (0) : __assert_fail ("ContextToPush && \"pushing null context\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 890, __PRETTY_FUNCTION__)); |
891 | S.CurContext = ContextToPush; |
892 | if (NewThisContext) |
893 | S.CXXThisTypeOverride = QualType(); |
894 | // Any saved FunctionScopes do not refer to this context. |
895 | S.FunctionScopesStart = S.FunctionScopes.size(); |
896 | S.InventedParameterInfosStart = S.InventedParameterInfos.size(); |
897 | } |
898 | |
899 | void pop() { |
900 | if (!SavedContext) return; |
901 | S.CurContext = SavedContext; |
902 | S.DelayedDiagnostics.popUndelayed(SavedContextState); |
903 | S.CXXThisTypeOverride = SavedCXXThisTypeOverride; |
904 | S.FunctionScopesStart = SavedFunctionScopesStart; |
905 | S.InventedParameterInfosStart = SavedInventedParameterInfosStart; |
906 | SavedContext = nullptr; |
907 | } |
908 | |
909 | ~ContextRAII() { |
910 | pop(); |
911 | } |
912 | }; |
913 | |
914 | /// Whether the AST is currently being rebuilt to correct immediate |
915 | /// invocations. Immediate invocation candidates and references to consteval |
916 | /// functions aren't tracked when this is set. |
917 | bool RebuildingImmediateInvocation = false; |
918 | |
919 | /// Used to change context to isConstantEvaluated without pushing a heavy |
920 | /// ExpressionEvaluationContextRecord object. |
921 | bool isConstantEvaluatedOverride; |
922 | |
923 | bool isConstantEvaluated() { |
924 | return ExprEvalContexts.back().isConstantEvaluated() || |
925 | isConstantEvaluatedOverride; |
926 | } |
927 | |
928 | /// RAII object to handle the state changes required to synthesize |
929 | /// a function body. |
930 | class SynthesizedFunctionScope { |
931 | Sema &S; |
932 | Sema::ContextRAII SavedContext; |
933 | bool PushedCodeSynthesisContext = false; |
934 | |
935 | public: |
936 | SynthesizedFunctionScope(Sema &S, DeclContext *DC) |
937 | : S(S), SavedContext(S, DC) { |
938 | S.PushFunctionScope(); |
939 | S.PushExpressionEvaluationContext( |
940 | Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
941 | if (auto *FD = dyn_cast<FunctionDecl>(DC)) |
942 | FD->setWillHaveBody(true); |
943 | else |
944 | assert(isa<ObjCMethodDecl>(DC))((isa<ObjCMethodDecl>(DC)) ? static_cast<void> (0 ) : __assert_fail ("isa<ObjCMethodDecl>(DC)", "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 944, __PRETTY_FUNCTION__)); |
945 | } |
946 | |
947 | void addContextNote(SourceLocation UseLoc) { |
948 | assert(!PushedCodeSynthesisContext)((!PushedCodeSynthesisContext) ? static_cast<void> (0) : __assert_fail ("!PushedCodeSynthesisContext", "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 948, __PRETTY_FUNCTION__)); |
949 | |
950 | Sema::CodeSynthesisContext Ctx; |
951 | Ctx.Kind = Sema::CodeSynthesisContext::DefiningSynthesizedFunction; |
952 | Ctx.PointOfInstantiation = UseLoc; |
953 | Ctx.Entity = cast<Decl>(S.CurContext); |
954 | S.pushCodeSynthesisContext(Ctx); |
955 | |
956 | PushedCodeSynthesisContext = true; |
957 | } |
958 | |
959 | ~SynthesizedFunctionScope() { |
960 | if (PushedCodeSynthesisContext) |
961 | S.popCodeSynthesisContext(); |
962 | if (auto *FD = dyn_cast<FunctionDecl>(S.CurContext)) |
963 | FD->setWillHaveBody(false); |
964 | S.PopExpressionEvaluationContext(); |
965 | S.PopFunctionScopeInfo(); |
966 | } |
967 | }; |
968 | |
969 | /// WeakUndeclaredIdentifiers - Identifiers contained in |
970 | /// \#pragma weak before declared. rare. may alias another |
971 | /// identifier, declared or undeclared |
972 | llvm::MapVector<IdentifierInfo *, WeakInfo> WeakUndeclaredIdentifiers; |
973 | |
974 | /// ExtnameUndeclaredIdentifiers - Identifiers contained in |
975 | /// \#pragma redefine_extname before declared. Used in Solaris system headers |
976 | /// to define functions that occur in multiple standards to call the version |
977 | /// in the currently selected standard. |
978 | llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers; |
979 | |
980 | |
981 | /// Load weak undeclared identifiers from the external source. |
982 | void LoadExternalWeakUndeclaredIdentifiers(); |
983 | |
984 | /// WeakTopLevelDecl - Translation-unit scoped declarations generated by |
985 | /// \#pragma weak during processing of other Decls. |
986 | /// I couldn't figure out a clean way to generate these in-line, so |
987 | /// we store them here and handle separately -- which is a hack. |
988 | /// It would be best to refactor this. |
989 | SmallVector<Decl*,2> WeakTopLevelDecl; |
990 | |
991 | IdentifierResolver IdResolver; |
992 | |
993 | /// Translation Unit Scope - useful to Objective-C actions that need |
994 | /// to lookup file scope declarations in the "ordinary" C decl namespace. |
995 | /// For example, user-defined classes, built-in "id" type, etc. |
996 | Scope *TUScope; |
997 | |
998 | /// The C++ "std" namespace, where the standard library resides. |
999 | LazyDeclPtr StdNamespace; |
1000 | |
1001 | /// The C++ "std::bad_alloc" class, which is defined by the C++ |
1002 | /// standard library. |
1003 | LazyDeclPtr StdBadAlloc; |
1004 | |
1005 | /// The C++ "std::align_val_t" enum class, which is defined by the C++ |
1006 | /// standard library. |
1007 | LazyDeclPtr StdAlignValT; |
1008 | |
1009 | /// The C++ "std::experimental" namespace, where the experimental parts |
1010 | /// of the standard library resides. |
1011 | NamespaceDecl *StdExperimentalNamespaceCache; |
1012 | |
1013 | /// The C++ "std::initializer_list" template, which is defined in |
1014 | /// \<initializer_list>. |
1015 | ClassTemplateDecl *StdInitializerList; |
1016 | |
1017 | /// The C++ "std::coroutine_traits" template, which is defined in |
1018 | /// \<coroutine_traits> |
1019 | ClassTemplateDecl *StdCoroutineTraitsCache; |
1020 | |
1021 | /// The C++ "type_info" declaration, which is defined in \<typeinfo>. |
1022 | RecordDecl *CXXTypeInfoDecl; |
1023 | |
1024 | /// The MSVC "_GUID" struct, which is defined in MSVC header files. |
1025 | RecordDecl *MSVCGuidDecl; |
1026 | |
1027 | /// Caches identifiers/selectors for NSFoundation APIs. |
1028 | std::unique_ptr<NSAPI> NSAPIObj; |
1029 | |
1030 | /// The declaration of the Objective-C NSNumber class. |
1031 | ObjCInterfaceDecl *NSNumberDecl; |
1032 | |
1033 | /// The declaration of the Objective-C NSValue class. |
1034 | ObjCInterfaceDecl *NSValueDecl; |
1035 | |
1036 | /// Pointer to NSNumber type (NSNumber *). |
1037 | QualType NSNumberPointer; |
1038 | |
1039 | /// Pointer to NSValue type (NSValue *). |
1040 | QualType NSValuePointer; |
1041 | |
1042 | /// The Objective-C NSNumber methods used to create NSNumber literals. |
1043 | ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]; |
1044 | |
1045 | /// The declaration of the Objective-C NSString class. |
1046 | ObjCInterfaceDecl *NSStringDecl; |
1047 | |
1048 | /// Pointer to NSString type (NSString *). |
1049 | QualType NSStringPointer; |
1050 | |
1051 | /// The declaration of the stringWithUTF8String: method. |
1052 | ObjCMethodDecl *StringWithUTF8StringMethod; |
1053 | |
1054 | /// The declaration of the valueWithBytes:objCType: method. |
1055 | ObjCMethodDecl *ValueWithBytesObjCTypeMethod; |
1056 | |
1057 | /// The declaration of the Objective-C NSArray class. |
1058 | ObjCInterfaceDecl *NSArrayDecl; |
1059 | |
1060 | /// The declaration of the arrayWithObjects:count: method. |
1061 | ObjCMethodDecl *ArrayWithObjectsMethod; |
1062 | |
1063 | /// The declaration of the Objective-C NSDictionary class. |
1064 | ObjCInterfaceDecl *NSDictionaryDecl; |
1065 | |
1066 | /// The declaration of the dictionaryWithObjects:forKeys:count: method. |
1067 | ObjCMethodDecl *DictionaryWithObjectsMethod; |
1068 | |
1069 | /// id<NSCopying> type. |
1070 | QualType QIDNSCopying; |
1071 | |
1072 | /// will hold 'respondsToSelector:' |
1073 | Selector RespondsToSelectorSel; |
1074 | |
1075 | /// A flag to remember whether the implicit forms of operator new and delete |
1076 | /// have been declared. |
1077 | bool GlobalNewDeleteDeclared; |
1078 | |
1079 | /// A flag to indicate that we're in a context that permits abstract |
1080 | /// references to fields. This is really a |
1081 | bool AllowAbstractFieldReference; |
1082 | |
1083 | /// Describes how the expressions currently being parsed are |
1084 | /// evaluated at run-time, if at all. |
1085 | enum class ExpressionEvaluationContext { |
1086 | /// The current expression and its subexpressions occur within an |
1087 | /// unevaluated operand (C++11 [expr]p7), such as the subexpression of |
1088 | /// \c sizeof, where the type of the expression may be significant but |
1089 | /// no code will be generated to evaluate the value of the expression at |
1090 | /// run time. |
1091 | Unevaluated, |
1092 | |
1093 | /// The current expression occurs within a braced-init-list within |
1094 | /// an unevaluated operand. This is mostly like a regular unevaluated |
1095 | /// context, except that we still instantiate constexpr functions that are |
1096 | /// referenced here so that we can perform narrowing checks correctly. |
1097 | UnevaluatedList, |
1098 | |
1099 | /// The current expression occurs within a discarded statement. |
1100 | /// This behaves largely similarly to an unevaluated operand in preventing |
1101 | /// definitions from being required, but not in other ways. |
1102 | DiscardedStatement, |
1103 | |
1104 | /// The current expression occurs within an unevaluated |
1105 | /// operand that unconditionally permits abstract references to |
1106 | /// fields, such as a SIZE operator in MS-style inline assembly. |
1107 | UnevaluatedAbstract, |
1108 | |
1109 | /// The current context is "potentially evaluated" in C++11 terms, |
1110 | /// but the expression is evaluated at compile-time (like the values of |
1111 | /// cases in a switch statement). |
1112 | ConstantEvaluated, |
1113 | |
1114 | /// The current expression is potentially evaluated at run time, |
1115 | /// which means that code may be generated to evaluate the value of the |
1116 | /// expression at run time. |
1117 | PotentiallyEvaluated, |
1118 | |
1119 | /// The current expression is potentially evaluated, but any |
1120 | /// declarations referenced inside that expression are only used if |
1121 | /// in fact the current expression is used. |
1122 | /// |
1123 | /// This value is used when parsing default function arguments, for which |
1124 | /// we would like to provide diagnostics (e.g., passing non-POD arguments |
1125 | /// through varargs) but do not want to mark declarations as "referenced" |
1126 | /// until the default argument is used. |
1127 | PotentiallyEvaluatedIfUsed |
1128 | }; |
1129 | |
1130 | using ImmediateInvocationCandidate = llvm::PointerIntPair<ConstantExpr *, 1>; |
1131 | |
1132 | /// Data structure used to record current or nested |
1133 | /// expression evaluation contexts. |
1134 | struct ExpressionEvaluationContextRecord { |
1135 | /// The expression evaluation context. |
1136 | ExpressionEvaluationContext Context; |
1137 | |
1138 | /// Whether the enclosing context needed a cleanup. |
1139 | CleanupInfo ParentCleanup; |
1140 | |
1141 | /// Whether we are in a decltype expression. |
1142 | bool IsDecltype; |
1143 | |
1144 | /// The number of active cleanup objects when we entered |
1145 | /// this expression evaluation context. |
1146 | unsigned NumCleanupObjects; |
1147 | |
1148 | /// The number of typos encountered during this expression evaluation |
1149 | /// context (i.e. the number of TypoExprs created). |
1150 | unsigned NumTypos; |
1151 | |
1152 | MaybeODRUseExprSet SavedMaybeODRUseExprs; |
1153 | |
1154 | /// The lambdas that are present within this context, if it |
1155 | /// is indeed an unevaluated context. |
1156 | SmallVector<LambdaExpr *, 2> Lambdas; |
1157 | |
1158 | /// The declaration that provides context for lambda expressions |
1159 | /// and block literals if the normal declaration context does not |
1160 | /// suffice, e.g., in a default function argument. |
1161 | Decl *ManglingContextDecl; |
1162 | |
1163 | /// If we are processing a decltype type, a set of call expressions |
1164 | /// for which we have deferred checking the completeness of the return type. |
1165 | SmallVector<CallExpr *, 8> DelayedDecltypeCalls; |
1166 | |
1167 | /// If we are processing a decltype type, a set of temporary binding |
1168 | /// expressions for which we have deferred checking the destructor. |
1169 | SmallVector<CXXBindTemporaryExpr *, 8> DelayedDecltypeBinds; |
1170 | |
1171 | llvm::SmallPtrSet<const Expr *, 8> PossibleDerefs; |
1172 | |
1173 | /// Expressions appearing as the LHS of a volatile assignment in this |
1174 | /// context. We produce a warning for these when popping the context if |
1175 | /// they are not discarded-value expressions nor unevaluated operands. |
1176 | SmallVector<Expr*, 2> VolatileAssignmentLHSs; |
1177 | |
1178 | /// Set of candidates for starting an immediate invocation. |
1179 | llvm::SmallVector<ImmediateInvocationCandidate, 4> ImmediateInvocationCandidates; |
1180 | |
1181 | /// Set of DeclRefExprs referencing a consteval function when used in a |
1182 | /// context not already known to be immediately invoked. |
1183 | llvm::SmallPtrSet<DeclRefExpr *, 4> ReferenceToConsteval; |
1184 | |
1185 | /// \brief Describes whether we are in an expression constext which we have |
1186 | /// to handle differently. |
1187 | enum ExpressionKind { |
1188 | EK_Decltype, EK_TemplateArgument, EK_Other |
1189 | } ExprContext; |
1190 | |
1191 | ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context, |
1192 | unsigned NumCleanupObjects, |
1193 | CleanupInfo ParentCleanup, |
1194 | Decl *ManglingContextDecl, |
1195 | ExpressionKind ExprContext) |
1196 | : Context(Context), ParentCleanup(ParentCleanup), |
1197 | NumCleanupObjects(NumCleanupObjects), NumTypos(0), |
1198 | ManglingContextDecl(ManglingContextDecl), ExprContext(ExprContext) {} |
1199 | |
1200 | bool isUnevaluated() const { |
1201 | return Context == ExpressionEvaluationContext::Unevaluated || |
1202 | Context == ExpressionEvaluationContext::UnevaluatedAbstract || |
1203 | Context == ExpressionEvaluationContext::UnevaluatedList; |
1204 | } |
1205 | bool isConstantEvaluated() const { |
1206 | return Context == ExpressionEvaluationContext::ConstantEvaluated; |
1207 | } |
1208 | }; |
1209 | |
1210 | /// A stack of expression evaluation contexts. |
1211 | SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts; |
1212 | |
1213 | /// Emit a warning for all pending noderef expressions that we recorded. |
1214 | void WarnOnPendingNoDerefs(ExpressionEvaluationContextRecord &Rec); |
1215 | |
1216 | /// Compute the mangling number context for a lambda expression or |
1217 | /// block literal. Also return the extra mangling decl if any. |
1218 | /// |
1219 | /// \param DC - The DeclContext containing the lambda expression or |
1220 | /// block literal. |
1221 | std::tuple<MangleNumberingContext *, Decl *> |
1222 | getCurrentMangleNumberContext(const DeclContext *DC); |
1223 | |
1224 | |
1225 | /// SpecialMemberOverloadResult - The overloading result for a special member |
1226 | /// function. |
1227 | /// |
1228 | /// This is basically a wrapper around PointerIntPair. The lowest bits of the |
1229 | /// integer are used to determine whether overload resolution succeeded. |
1230 | class SpecialMemberOverloadResult { |
1231 | public: |
1232 | enum Kind { |
1233 | NoMemberOrDeleted, |
1234 | Ambiguous, |
1235 | Success |
1236 | }; |
1237 | |
1238 | private: |
1239 | llvm::PointerIntPair<CXXMethodDecl*, 2> Pair; |
1240 | |
1241 | public: |
1242 | SpecialMemberOverloadResult() : Pair() {} |
1243 | SpecialMemberOverloadResult(CXXMethodDecl *MD) |
1244 | : Pair(MD, MD->isDeleted() ? NoMemberOrDeleted : Success) {} |
1245 | |
1246 | CXXMethodDecl *getMethod() const { return Pair.getPointer(); } |
1247 | void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); } |
1248 | |
1249 | Kind getKind() const { return static_cast<Kind>(Pair.getInt()); } |
1250 | void setKind(Kind K) { Pair.setInt(K); } |
1251 | }; |
1252 | |
1253 | class SpecialMemberOverloadResultEntry |
1254 | : public llvm::FastFoldingSetNode, |
1255 | public SpecialMemberOverloadResult { |
1256 | public: |
1257 | SpecialMemberOverloadResultEntry(const llvm::FoldingSetNodeID &ID) |
1258 | : FastFoldingSetNode(ID) |
1259 | {} |
1260 | }; |
1261 | |
1262 | /// A cache of special member function overload resolution results |
1263 | /// for C++ records. |
1264 | llvm::FoldingSet<SpecialMemberOverloadResultEntry> SpecialMemberCache; |
1265 | |
1266 | /// A cache of the flags available in enumerations with the flag_bits |
1267 | /// attribute. |
1268 | mutable llvm::DenseMap<const EnumDecl*, llvm::APInt> FlagBitsCache; |
1269 | |
1270 | /// The kind of translation unit we are processing. |
1271 | /// |
1272 | /// When we're processing a complete translation unit, Sema will perform |
1273 | /// end-of-translation-unit semantic tasks (such as creating |
1274 | /// initializers for tentative definitions in C) once parsing has |
1275 | /// completed. Modules and precompiled headers perform different kinds of |
1276 | /// checks. |
1277 | TranslationUnitKind TUKind; |
1278 | |
1279 | llvm::BumpPtrAllocator BumpAlloc; |
1280 | |
1281 | /// The number of SFINAE diagnostics that have been trapped. |
1282 | unsigned NumSFINAEErrors; |
1283 | |
1284 | typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>> |
1285 | UnparsedDefaultArgInstantiationsMap; |
1286 | |
1287 | /// A mapping from parameters with unparsed default arguments to the |
1288 | /// set of instantiations of each parameter. |
1289 | /// |
1290 | /// This mapping is a temporary data structure used when parsing |
1291 | /// nested class templates or nested classes of class templates, |
1292 | /// where we might end up instantiating an inner class before the |
1293 | /// default arguments of its methods have been parsed. |
1294 | UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations; |
1295 | |
1296 | // Contains the locations of the beginning of unparsed default |
1297 | // argument locations. |
1298 | llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs; |
1299 | |
1300 | /// UndefinedInternals - all the used, undefined objects which require a |
1301 | /// definition in this translation unit. |
1302 | llvm::MapVector<NamedDecl *, SourceLocation> UndefinedButUsed; |
1303 | |
1304 | /// Determine if VD, which must be a variable or function, is an external |
1305 | /// symbol that nonetheless can't be referenced from outside this translation |
1306 | /// unit because its type has no linkage and it's not extern "C". |
1307 | bool isExternalWithNoLinkageType(ValueDecl *VD); |
1308 | |
1309 | /// Obtain a sorted list of functions that are undefined but ODR-used. |
1310 | void getUndefinedButUsed( |
1311 | SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined); |
1312 | |
1313 | /// Retrieves list of suspicious delete-expressions that will be checked at |
1314 | /// the end of translation unit. |
1315 | const llvm::MapVector<FieldDecl *, DeleteLocs> & |
1316 | getMismatchingDeleteExpressions() const; |
1317 | |
1318 | typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods; |
1319 | typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool; |
1320 | |
1321 | /// Method Pool - allows efficient lookup when typechecking messages to "id". |
1322 | /// We need to maintain a list, since selectors can have differing signatures |
1323 | /// across classes. In Cocoa, this happens to be extremely uncommon (only 1% |
1324 | /// of selectors are "overloaded"). |
1325 | /// At the head of the list it is recorded whether there were 0, 1, or >= 2 |
1326 | /// methods inside categories with a particular selector. |
1327 | GlobalMethodPool MethodPool; |
1328 | |
1329 | /// Method selectors used in a \@selector expression. Used for implementation |
1330 | /// of -Wselector. |
1331 | llvm::MapVector<Selector, SourceLocation> ReferencedSelectors; |
1332 | |
1333 | /// List of SourceLocations where 'self' is implicitly retained inside a |
1334 | /// block. |
1335 | llvm::SmallVector<std::pair<SourceLocation, const BlockDecl *>, 1> |
1336 | ImplicitlyRetainedSelfLocs; |
1337 | |
1338 | /// Kinds of C++ special members. |
1339 | enum CXXSpecialMember { |
1340 | CXXDefaultConstructor, |
1341 | CXXCopyConstructor, |
1342 | CXXMoveConstructor, |
1343 | CXXCopyAssignment, |
1344 | CXXMoveAssignment, |
1345 | CXXDestructor, |
1346 | CXXInvalid |
1347 | }; |
1348 | |
1349 | typedef llvm::PointerIntPair<CXXRecordDecl *, 3, CXXSpecialMember> |
1350 | SpecialMemberDecl; |
1351 | |
1352 | /// The C++ special members which we are currently in the process of |
1353 | /// declaring. If this process recursively triggers the declaration of the |
1354 | /// same special member, we should act as if it is not yet declared. |
1355 | llvm::SmallPtrSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared; |
1356 | |
1357 | /// Kinds of defaulted comparison operator functions. |
1358 | enum class DefaultedComparisonKind : unsigned char { |
1359 | /// This is not a defaultable comparison operator. |
1360 | None, |
1361 | /// This is an operator== that should be implemented as a series of |
1362 | /// subobject comparisons. |
1363 | Equal, |
1364 | /// This is an operator<=> that should be implemented as a series of |
1365 | /// subobject comparisons. |
1366 | ThreeWay, |
1367 | /// This is an operator!= that should be implemented as a rewrite in terms |
1368 | /// of a == comparison. |
1369 | NotEqual, |
1370 | /// This is an <, <=, >, or >= that should be implemented as a rewrite in |
1371 | /// terms of a <=> comparison. |
1372 | Relational, |
1373 | }; |
1374 | |
1375 | /// The function definitions which were renamed as part of typo-correction |
1376 | /// to match their respective declarations. We want to keep track of them |
1377 | /// to ensure that we don't emit a "redefinition" error if we encounter a |
1378 | /// correctly named definition after the renamed definition. |
1379 | llvm::SmallPtrSet<const NamedDecl *, 4> TypoCorrectedFunctionDefinitions; |
1380 | |
1381 | /// Stack of types that correspond to the parameter entities that are |
1382 | /// currently being copy-initialized. Can be empty. |
1383 | llvm::SmallVector<QualType, 4> CurrentParameterCopyTypes; |
1384 | |
1385 | void ReadMethodPool(Selector Sel); |
1386 | void updateOutOfDateSelector(Selector Sel); |
1387 | |
1388 | /// Private Helper predicate to check for 'self'. |
1389 | bool isSelfExpr(Expr *RExpr); |
1390 | bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method); |
1391 | |
1392 | /// Cause the active diagnostic on the DiagosticsEngine to be |
1393 | /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and |
1394 | /// should not be used elsewhere. |
1395 | void EmitCurrentDiagnostic(unsigned DiagID); |
1396 | |
1397 | /// Records and restores the CurFPFeatures state on entry/exit of compound |
1398 | /// statements. |
1399 | class FPFeaturesStateRAII { |
1400 | public: |
1401 | FPFeaturesStateRAII(Sema &S) : S(S), OldFPFeaturesState(S.CurFPFeatures) { |
1402 | OldOverrides = S.FpPragmaStack.CurrentValue; |
1403 | } |
1404 | ~FPFeaturesStateRAII() { |
1405 | S.CurFPFeatures = OldFPFeaturesState; |
1406 | S.FpPragmaStack.CurrentValue = OldOverrides; |
1407 | } |
1408 | FPOptionsOverride getOverrides() { return OldOverrides; } |
1409 | |
1410 | private: |
1411 | Sema& S; |
1412 | FPOptions OldFPFeaturesState; |
1413 | FPOptionsOverride OldOverrides; |
1414 | }; |
1415 | |
1416 | void addImplicitTypedef(StringRef Name, QualType T); |
1417 | |
1418 | bool WarnedStackExhausted = false; |
1419 | |
1420 | public: |
1421 | Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, |
1422 | TranslationUnitKind TUKind = TU_Complete, |
1423 | CodeCompleteConsumer *CompletionConsumer = nullptr); |
1424 | ~Sema(); |
1425 | |
1426 | /// Perform initialization that occurs after the parser has been |
1427 | /// initialized but before it parses anything. |
1428 | void Initialize(); |
1429 | |
1430 | const LangOptions &getLangOpts() const { return LangOpts; } |
1431 | OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; } |
1432 | FPOptions &getCurFPFeatures() { return CurFPFeatures; } |
1433 | |
1434 | DiagnosticsEngine &getDiagnostics() const { return Diags; } |
1435 | SourceManager &getSourceManager() const { return SourceMgr; } |
1436 | Preprocessor &getPreprocessor() const { return PP; } |
1437 | ASTContext &getASTContext() const { return Context; } |
1438 | ASTConsumer &getASTConsumer() const { return Consumer; } |
1439 | ASTMutationListener *getASTMutationListener() const; |
1440 | ExternalSemaSource* getExternalSource() const { return ExternalSource; } |
1441 | |
1442 | ///Registers an external source. If an external source already exists, |
1443 | /// creates a multiplex external source and appends to it. |
1444 | /// |
1445 | ///\param[in] E - A non-null external sema source. |
1446 | /// |
1447 | void addExternalSource(ExternalSemaSource *E); |
1448 | |
1449 | void PrintStats() const; |
1450 | |
1451 | /// Warn that the stack is nearly exhausted. |
1452 | void warnStackExhausted(SourceLocation Loc); |
1453 | |
1454 | /// Run some code with "sufficient" stack space. (Currently, at least 256K is |
1455 | /// guaranteed). Produces a warning if we're low on stack space and allocates |
1456 | /// more in that case. Use this in code that may recurse deeply (for example, |
1457 | /// in template instantiation) to avoid stack overflow. |
1458 | void runWithSufficientStackSpace(SourceLocation Loc, |
1459 | llvm::function_ref<void()> Fn); |
1460 | |
1461 | /// Helper class that creates diagnostics with optional |
1462 | /// template instantiation stacks. |
1463 | /// |
1464 | /// This class provides a wrapper around the basic DiagnosticBuilder |
1465 | /// class that emits diagnostics. SemaDiagnosticBuilder is |
1466 | /// responsible for emitting the diagnostic (as DiagnosticBuilder |
1467 | /// does) and, if the diagnostic comes from inside a template |
1468 | /// instantiation, printing the template instantiation stack as |
1469 | /// well. |
1470 | class SemaDiagnosticBuilder : public DiagnosticBuilder { |
1471 | Sema &SemaRef; |
1472 | unsigned DiagID; |
1473 | |
1474 | public: |
1475 | SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID) |
1476 | : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { } |
1477 | |
1478 | // This is a cunning lie. DiagnosticBuilder actually performs move |
1479 | // construction in its copy constructor (but due to varied uses, it's not |
1480 | // possible to conveniently express this as actual move construction). So |
1481 | // the default copy ctor here is fine, because the base class disables the |
1482 | // source anyway, so the user-defined ~SemaDiagnosticBuilder is a safe no-op |
1483 | // in that case anwyay. |
1484 | SemaDiagnosticBuilder(const SemaDiagnosticBuilder&) = default; |
1485 | |
1486 | ~SemaDiagnosticBuilder() { |
1487 | // If we aren't active, there is nothing to do. |
1488 | if (!isActive()) return; |
1489 | |
1490 | // Otherwise, we need to emit the diagnostic. First flush the underlying |
1491 | // DiagnosticBuilder data, and clear the diagnostic builder itself so it |
1492 | // won't emit the diagnostic in its own destructor. |
1493 | // |
1494 | // This seems wasteful, in that as written the DiagnosticBuilder dtor will |
1495 | // do its own needless checks to see if the diagnostic needs to be |
1496 | // emitted. However, because we take care to ensure that the builder |
1497 | // objects never escape, a sufficiently smart compiler will be able to |
1498 | // eliminate that code. |
1499 | FlushCounts(); |
1500 | Clear(); |
1501 | |
1502 | // Dispatch to Sema to emit the diagnostic. |
1503 | SemaRef.EmitCurrentDiagnostic(DiagID); |
1504 | } |
1505 | |
1506 | /// Teach operator<< to produce an object of the correct type. |
1507 | template<typename T> |
1508 | friend const SemaDiagnosticBuilder &operator<<( |
1509 | const SemaDiagnosticBuilder &Diag, const T &Value) { |
1510 | const DiagnosticBuilder &BaseDiag = Diag; |
1511 | BaseDiag << Value; |
1512 | return Diag; |
1513 | } |
1514 | }; |
1515 | |
1516 | /// Emit a diagnostic. |
1517 | SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) { |
1518 | DiagnosticBuilder DB = Diags.Report(Loc, DiagID); |
1519 | return SemaDiagnosticBuilder(DB, *this, DiagID); |
1520 | } |
1521 | |
1522 | /// Emit a partial diagnostic. |
1523 | SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD); |
1524 | |
1525 | /// Build a partial diagnostic. |
1526 | PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h |
1527 | |
1528 | bool findMacroSpelling(SourceLocation &loc, StringRef name); |
1529 | |
1530 | /// Get a string to suggest for zero-initialization of a type. |
1531 | std::string |
1532 | getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const; |
1533 | std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const; |
1534 | |
1535 | /// Calls \c Lexer::getLocForEndOfToken() |
1536 | SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0); |
1537 | |
1538 | /// Retrieve the module loader associated with the preprocessor. |
1539 | ModuleLoader &getModuleLoader() const; |
1540 | |
1541 | /// Invent a new identifier for parameters of abbreviated templates. |
1542 | IdentifierInfo * |
1543 | InventAbbreviatedTemplateParameterTypeName(IdentifierInfo *ParamName, |
1544 | unsigned Index); |
1545 | |
1546 | void emitAndClearUnusedLocalTypedefWarnings(); |
1547 | |
1548 | private: |
1549 | /// Function or variable declarations to be checked for whether the deferred |
1550 | /// diagnostics should be emitted. |
1551 | SmallVector<Decl *, 4> DeclsToCheckForDeferredDiags; |
1552 | |
1553 | public: |
1554 | // Emit all deferred diagnostics. |
1555 | void emitDeferredDiags(); |
1556 | |
1557 | enum TUFragmentKind { |
1558 | /// The global module fragment, between 'module;' and a module-declaration. |
1559 | Global, |
1560 | /// A normal translation unit fragment. For a non-module unit, this is the |
1561 | /// entire translation unit. Otherwise, it runs from the module-declaration |
1562 | /// to the private-module-fragment (if any) or the end of the TU (if not). |
1563 | Normal, |
1564 | /// The private module fragment, between 'module :private;' and the end of |
1565 | /// the translation unit. |
1566 | Private |
1567 | }; |
1568 | |
1569 | void ActOnStartOfTranslationUnit(); |
1570 | void ActOnEndOfTranslationUnit(); |
1571 | void ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind); |
1572 | |
1573 | void CheckDelegatingCtorCycles(); |
1574 | |
1575 | Scope *getScopeForContext(DeclContext *Ctx); |
1576 | |
1577 | void PushFunctionScope(); |
1578 | void PushBlockScope(Scope *BlockScope, BlockDecl *Block); |
1579 | sema::LambdaScopeInfo *PushLambdaScope(); |
1580 | |
1581 | /// This is used to inform Sema what the current TemplateParameterDepth |
1582 | /// is during Parsing. Currently it is used to pass on the depth |
1583 | /// when parsing generic lambda 'auto' parameters. |
1584 | void RecordParsingTemplateParameterDepth(unsigned Depth); |
1585 | |
1586 | void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD, |
1587 | RecordDecl *RD, CapturedRegionKind K, |
1588 | unsigned OpenMPCaptureLevel = 0); |
1589 | |
1590 | /// Custom deleter to allow FunctionScopeInfos to be kept alive for a short |
1591 | /// time after they've been popped. |
1592 | class PoppedFunctionScopeDeleter { |
1593 | Sema *Self; |
1594 | |
1595 | public: |
1596 | explicit PoppedFunctionScopeDeleter(Sema *Self) : Self(Self) {} |
1597 | void operator()(sema::FunctionScopeInfo *Scope) const; |
1598 | }; |
1599 | |
1600 | using PoppedFunctionScopePtr = |
1601 | std::unique_ptr<sema::FunctionScopeInfo, PoppedFunctionScopeDeleter>; |
1602 | |
1603 | PoppedFunctionScopePtr |
1604 | PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr, |
1605 | const Decl *D = nullptr, |
1606 | QualType BlockType = QualType()); |
1607 | |
1608 | sema::FunctionScopeInfo *getCurFunction() const { |
1609 | return FunctionScopes.empty() ? nullptr : FunctionScopes.back(); |
1610 | } |
1611 | |
1612 | sema::FunctionScopeInfo *getEnclosingFunction() const; |
1613 | |
1614 | void setFunctionHasBranchIntoScope(); |
1615 | void setFunctionHasBranchProtectedScope(); |
1616 | void setFunctionHasIndirectGoto(); |
1617 | |
1618 | void PushCompoundScope(bool IsStmtExpr); |
1619 | void PopCompoundScope(); |
1620 | |
1621 | sema::CompoundScopeInfo &getCurCompoundScope() const; |
1622 | |
1623 | bool hasAnyUnrecoverableErrorsInThisFunction() const; |
1624 | |
1625 | /// Retrieve the current block, if any. |
1626 | sema::BlockScopeInfo *getCurBlock(); |
1627 | |
1628 | /// Get the innermost lambda enclosing the current location, if any. This |
1629 | /// looks through intervening non-lambda scopes such as local functions and |
1630 | /// blocks. |
1631 | sema::LambdaScopeInfo *getEnclosingLambda() const; |
1632 | |
1633 | /// Retrieve the current lambda scope info, if any. |
1634 | /// \param IgnoreNonLambdaCapturingScope true if should find the top-most |
1635 | /// lambda scope info ignoring all inner capturing scopes that are not |
1636 | /// lambda scopes. |
1637 | sema::LambdaScopeInfo * |
1638 | getCurLambda(bool IgnoreNonLambdaCapturingScope = false); |
1639 | |
1640 | /// Retrieve the current generic lambda info, if any. |
1641 | sema::LambdaScopeInfo *getCurGenericLambda(); |
1642 | |
1643 | /// Retrieve the current captured region, if any. |
1644 | sema::CapturedRegionScopeInfo *getCurCapturedRegion(); |
1645 | |
1646 | /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls |
1647 | SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; } |
1648 | |
1649 | /// Called before parsing a function declarator belonging to a function |
1650 | /// declaration. |
1651 | void ActOnStartFunctionDeclarationDeclarator(Declarator &D, |
1652 | unsigned TemplateParameterDepth); |
1653 | |
1654 | /// Called after parsing a function declarator belonging to a function |
1655 | /// declaration. |
1656 | void ActOnFinishFunctionDeclarationDeclarator(Declarator &D); |
1657 | |
1658 | void ActOnComment(SourceRange Comment); |
1659 | |
1660 | //===--------------------------------------------------------------------===// |
1661 | // Type Analysis / Processing: SemaType.cpp. |
1662 | // |
1663 | |
1664 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, |
1665 | const DeclSpec *DS = nullptr); |
1666 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA, |
1667 | const DeclSpec *DS = nullptr); |
1668 | QualType BuildPointerType(QualType T, |
1669 | SourceLocation Loc, DeclarationName Entity); |
1670 | QualType BuildReferenceType(QualType T, bool LValueRef, |
1671 | SourceLocation Loc, DeclarationName Entity); |
1672 | QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, |
1673 | Expr *ArraySize, unsigned Quals, |
1674 | SourceRange Brackets, DeclarationName Entity); |
1675 | QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc); |
1676 | QualType BuildExtVectorType(QualType T, Expr *ArraySize, |
1677 | SourceLocation AttrLoc); |
1678 | QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, |
1679 | SourceLocation AttrLoc); |
1680 | |
1681 | QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace, |
1682 | SourceLocation AttrLoc); |
1683 | |
1684 | /// Same as above, but constructs the AddressSpace index if not provided. |
1685 | QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace, |
1686 | SourceLocation AttrLoc); |
1687 | |
1688 | bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc); |
1689 | |
1690 | bool CheckFunctionReturnType(QualType T, SourceLocation Loc); |
1691 | |
1692 | /// Build a function type. |
1693 | /// |
1694 | /// This routine checks the function type according to C++ rules and |
1695 | /// under the assumption that the result type and parameter types have |
1696 | /// just been instantiated from a template. It therefore duplicates |
1697 | /// some of the behavior of GetTypeForDeclarator, but in a much |
1698 | /// simpler form that is only suitable for this narrow use case. |
1699 | /// |
1700 | /// \param T The return type of the function. |
1701 | /// |
1702 | /// \param ParamTypes The parameter types of the function. This array |
1703 | /// will be modified to account for adjustments to the types of the |
1704 | /// function parameters. |
1705 | /// |
1706 | /// \param Loc The location of the entity whose type involves this |
1707 | /// function type or, if there is no such entity, the location of the |
1708 | /// type that will have function type. |
1709 | /// |
1710 | /// \param Entity The name of the entity that involves the function |
1711 | /// type, if known. |
1712 | /// |
1713 | /// \param EPI Extra information about the function type. Usually this will |
1714 | /// be taken from an existing function with the same prototype. |
1715 | /// |
1716 | /// \returns A suitable function type, if there are no errors. The |
1717 | /// unqualified type will always be a FunctionProtoType. |
1718 | /// Otherwise, returns a NULL type. |
1719 | QualType BuildFunctionType(QualType T, |
1720 | MutableArrayRef<QualType> ParamTypes, |
1721 | SourceLocation Loc, DeclarationName Entity, |
1722 | const FunctionProtoType::ExtProtoInfo &EPI); |
1723 | |
1724 | QualType BuildMemberPointerType(QualType T, QualType Class, |
1725 | SourceLocation Loc, |
1726 | DeclarationName Entity); |
1727 | QualType BuildBlockPointerType(QualType T, |
1728 | SourceLocation Loc, DeclarationName Entity); |
1729 | QualType BuildParenType(QualType T); |
1730 | QualType BuildAtomicType(QualType T, SourceLocation Loc); |
1731 | QualType BuildReadPipeType(QualType T, |
1732 | SourceLocation Loc); |
1733 | QualType BuildWritePipeType(QualType T, |
1734 | SourceLocation Loc); |
1735 | QualType BuildExtIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc); |
1736 | |
1737 | TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S); |
1738 | TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy); |
1739 | |
1740 | /// Package the given type and TSI into a ParsedType. |
1741 | ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo); |
1742 | DeclarationNameInfo GetNameForDeclarator(Declarator &D); |
1743 | DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name); |
1744 | static QualType GetTypeFromParser(ParsedType Ty, |
1745 | TypeSourceInfo **TInfo = nullptr); |
1746 | CanThrowResult canThrow(const Stmt *E); |
1747 | /// Determine whether the callee of a particular function call can throw. |
1748 | /// E, D and Loc are all optional. |
1749 | static CanThrowResult canCalleeThrow(Sema &S, const Expr *E, const Decl *D, |
1750 | SourceLocation Loc = SourceLocation()); |
1751 | const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc, |
1752 | const FunctionProtoType *FPT); |
1753 | void UpdateExceptionSpec(FunctionDecl *FD, |
1754 | const FunctionProtoType::ExceptionSpecInfo &ESI); |
1755 | bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range); |
1756 | bool CheckDistantExceptionSpec(QualType T); |
1757 | bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New); |
1758 | bool CheckEquivalentExceptionSpec( |
1759 | const FunctionProtoType *Old, SourceLocation OldLoc, |
1760 | const FunctionProtoType *New, SourceLocation NewLoc); |
1761 | bool CheckEquivalentExceptionSpec( |
1762 | const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, |
1763 | const FunctionProtoType *Old, SourceLocation OldLoc, |
1764 | const FunctionProtoType *New, SourceLocation NewLoc); |
1765 | bool handlerCanCatch(QualType HandlerType, QualType ExceptionType); |
1766 | bool CheckExceptionSpecSubset(const PartialDiagnostic &DiagID, |
1767 | const PartialDiagnostic &NestedDiagID, |
1768 | const PartialDiagnostic &NoteID, |
1769 | const PartialDiagnostic &NoThrowDiagID, |
1770 | const FunctionProtoType *Superset, |
1771 | SourceLocation SuperLoc, |
1772 | const FunctionProtoType *Subset, |
1773 | SourceLocation SubLoc); |
1774 | bool CheckParamExceptionSpec(const PartialDiagnostic &NestedDiagID, |
1775 | const PartialDiagnostic &NoteID, |
1776 | const FunctionProtoType *Target, |
1777 | SourceLocation TargetLoc, |
1778 | const FunctionProtoType *Source, |
1779 | SourceLocation SourceLoc); |
1780 | |
1781 | TypeResult ActOnTypeName(Scope *S, Declarator &D); |
1782 | |
1783 | /// The parser has parsed the context-sensitive type 'instancetype' |
1784 | /// in an Objective-C message declaration. Return the appropriate type. |
1785 | ParsedType ActOnObjCInstanceType(SourceLocation Loc); |
1786 | |
1787 | /// Abstract class used to diagnose incomplete types. |
1788 | struct TypeDiagnoser { |
1789 | TypeDiagnoser() {} |
1790 | |
1791 | virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0; |
1792 | virtual ~TypeDiagnoser() {} |
1793 | }; |
1794 | |
1795 | static int getPrintable(int I) { return I; } |
1796 | static unsigned getPrintable(unsigned I) { return I; } |
1797 | static bool getPrintable(bool B) { return B; } |
1798 | static const char * getPrintable(const char *S) { return S; } |
1799 | static StringRef getPrintable(StringRef S) { return S; } |
1800 | static const std::string &getPrintable(const std::string &S) { return S; } |
1801 | static const IdentifierInfo *getPrintable(const IdentifierInfo *II) { |
1802 | return II; |
1803 | } |
1804 | static DeclarationName getPrintable(DeclarationName N) { return N; } |
1805 | static QualType getPrintable(QualType T) { return T; } |
1806 | static SourceRange getPrintable(SourceRange R) { return R; } |
1807 | static SourceRange getPrintable(SourceLocation L) { return L; } |
1808 | static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); } |
1809 | static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();} |
1810 | |
1811 | template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser { |
1812 | protected: |
1813 | unsigned DiagID; |
1814 | std::tuple<const Ts &...> Args; |
1815 | |
1816 | template <std::size_t... Is> |
1817 | void emit(const SemaDiagnosticBuilder &DB, |
1818 | std::index_sequence<Is...>) const { |
1819 | // Apply all tuple elements to the builder in order. |
1820 | bool Dummy[] = {false, (DB << getPrintable(std::get<Is>(Args)))...}; |
1821 | (void)Dummy; |
1822 | } |
1823 | |
1824 | public: |
1825 | BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args) |
1826 | : TypeDiagnoser(), DiagID(DiagID), Args(Args...) { |
1827 | assert(DiagID != 0 && "no diagnostic for type diagnoser")((DiagID != 0 && "no diagnostic for type diagnoser") ? static_cast<void> (0) : __assert_fail ("DiagID != 0 && \"no diagnostic for type diagnoser\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 1827, __PRETTY_FUNCTION__)); |
1828 | } |
1829 | |
1830 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
1831 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID); |
1832 | emit(DB, std::index_sequence_for<Ts...>()); |
1833 | DB << T; |
1834 | } |
1835 | }; |
1836 | |
1837 | /// Do a check to make sure \p Name looks like a legal argument for the |
1838 | /// swift_name attribute applied to decl \p D. Raise a diagnostic if the name |
1839 | /// is invalid for the given declaration. |
1840 | /// |
1841 | /// \p AL is used to provide caret diagnostics in case of a malformed name. |
1842 | /// |
1843 | /// \returns true if the name is a valid swift name for \p D, false otherwise. |
1844 | bool DiagnoseSwiftName(Decl *D, StringRef Name, SourceLocation Loc, |
1845 | const ParsedAttr &AL); |
1846 | |
1847 | /// A derivative of BoundTypeDiagnoser for which the diagnostic's type |
1848 | /// parameter is preceded by a 0/1 enum that is 1 if the type is sizeless. |
1849 | /// For example, a diagnostic with no other parameters would generally have |
1850 | /// the form "...%select{incomplete|sizeless}0 type %1...". |
1851 | template <typename... Ts> |
1852 | class SizelessTypeDiagnoser : public BoundTypeDiagnoser<Ts...> { |
1853 | public: |
1854 | SizelessTypeDiagnoser(unsigned DiagID, const Ts &... Args) |
1855 | : BoundTypeDiagnoser<Ts...>(DiagID, Args...) {} |
1856 | |
1857 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
1858 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, this->DiagID); |
1859 | this->emit(DB, std::index_sequence_for<Ts...>()); |
1860 | DB << T->isSizelessType() << T; |
1861 | } |
1862 | }; |
1863 | |
1864 | enum class CompleteTypeKind { |
1865 | /// Apply the normal rules for complete types. In particular, |
1866 | /// treat all sizeless types as incomplete. |
1867 | Normal, |
1868 | |
1869 | /// Relax the normal rules for complete types so that they include |
1870 | /// sizeless built-in types. |
1871 | AcceptSizeless, |
1872 | |
1873 | // FIXME: Eventually we should flip the default to Normal and opt in |
1874 | // to AcceptSizeless rather than opt out of it. |
1875 | Default = AcceptSizeless |
1876 | }; |
1877 | |
1878 | private: |
1879 | /// Methods for marking which expressions involve dereferencing a pointer |
1880 | /// marked with the 'noderef' attribute. Expressions are checked bottom up as |
1881 | /// they are parsed, meaning that a noderef pointer may not be accessed. For |
1882 | /// example, in `&*p` where `p` is a noderef pointer, we will first parse the |
1883 | /// `*p`, but need to check that `address of` is called on it. This requires |
1884 | /// keeping a container of all pending expressions and checking if the address |
1885 | /// of them are eventually taken. |
1886 | void CheckSubscriptAccessOfNoDeref(const ArraySubscriptExpr *E); |
1887 | void CheckAddressOfNoDeref(const Expr *E); |
1888 | void CheckMemberAccessOfNoDeref(const MemberExpr *E); |
1889 | |
1890 | bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T, |
1891 | CompleteTypeKind Kind, TypeDiagnoser *Diagnoser); |
1892 | |
1893 | struct ModuleScope { |
1894 | SourceLocation BeginLoc; |
1895 | clang::Module *Module = nullptr; |
1896 | bool ModuleInterface = false; |
1897 | bool ImplicitGlobalModuleFragment = false; |
1898 | VisibleModuleSet OuterVisibleModules; |
1899 | }; |
1900 | /// The modules we're currently parsing. |
1901 | llvm::SmallVector<ModuleScope, 16> ModuleScopes; |
1902 | |
1903 | /// Namespace definitions that we will export when they finish. |
1904 | llvm::SmallPtrSet<const NamespaceDecl*, 8> DeferredExportedNamespaces; |
1905 | |
1906 | /// Get the module whose scope we are currently within. |
1907 | Module *getCurrentModule() const { |
1908 | return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module; |
1909 | } |
1910 | |
1911 | VisibleModuleSet VisibleModules; |
1912 | |
1913 | public: |
1914 | /// Get the module owning an entity. |
1915 | Module *getOwningModule(const Decl *Entity) { |
1916 | return Entity->getOwningModule(); |
1917 | } |
1918 | |
1919 | /// Make a merged definition of an existing hidden definition \p ND |
1920 | /// visible at the specified location. |
1921 | void makeMergedDefinitionVisible(NamedDecl *ND); |
1922 | |
1923 | bool isModuleVisible(const Module *M, bool ModulePrivate = false); |
1924 | |
1925 | // When loading a non-modular PCH files, this is used to restore module |
1926 | // visibility. |
1927 | void makeModuleVisible(Module *Mod, SourceLocation ImportLoc) { |
1928 | VisibleModules.setVisible(Mod, ImportLoc); |
1929 | } |
1930 | |
1931 | /// Determine whether a declaration is visible to name lookup. |
1932 | bool isVisible(const NamedDecl *D) { |
1933 | return D->isUnconditionallyVisible() || isVisibleSlow(D); |
1934 | } |
1935 | |
1936 | /// Determine whether any declaration of an entity is visible. |
1937 | bool |
1938 | hasVisibleDeclaration(const NamedDecl *D, |
1939 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
1940 | return isVisible(D) || hasVisibleDeclarationSlow(D, Modules); |
1941 | } |
1942 | bool hasVisibleDeclarationSlow(const NamedDecl *D, |
1943 | llvm::SmallVectorImpl<Module *> *Modules); |
1944 | |
1945 | bool hasVisibleMergedDefinition(NamedDecl *Def); |
1946 | bool hasMergedDefinitionInCurrentModule(NamedDecl *Def); |
1947 | |
1948 | /// Determine if \p D and \p Suggested have a structurally compatible |
1949 | /// layout as described in C11 6.2.7/1. |
1950 | bool hasStructuralCompatLayout(Decl *D, Decl *Suggested); |
1951 | |
1952 | /// Determine if \p D has a visible definition. If not, suggest a declaration |
1953 | /// that should be made visible to expose the definition. |
1954 | bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, |
1955 | bool OnlyNeedComplete = false); |
1956 | bool hasVisibleDefinition(const NamedDecl *D) { |
1957 | NamedDecl *Hidden; |
1958 | return hasVisibleDefinition(const_cast<NamedDecl*>(D), &Hidden); |
1959 | } |
1960 | |
1961 | /// Determine if the template parameter \p D has a visible default argument. |
1962 | bool |
1963 | hasVisibleDefaultArgument(const NamedDecl *D, |
1964 | llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
1965 | |
1966 | /// Determine if there is a visible declaration of \p D that is an explicit |
1967 | /// specialization declaration for a specialization of a template. (For a |
1968 | /// member specialization, use hasVisibleMemberSpecialization.) |
1969 | bool hasVisibleExplicitSpecialization( |
1970 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
1971 | |
1972 | /// Determine if there is a visible declaration of \p D that is a member |
1973 | /// specialization declaration (as opposed to an instantiated declaration). |
1974 | bool hasVisibleMemberSpecialization( |
1975 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
1976 | |
1977 | /// Determine if \p A and \p B are equivalent internal linkage declarations |
1978 | /// from different modules, and thus an ambiguity error can be downgraded to |
1979 | /// an extension warning. |
1980 | bool isEquivalentInternalLinkageDeclaration(const NamedDecl *A, |
1981 | const NamedDecl *B); |
1982 | void diagnoseEquivalentInternalLinkageDeclarations( |
1983 | SourceLocation Loc, const NamedDecl *D, |
1984 | ArrayRef<const NamedDecl *> Equiv); |
1985 | |
1986 | bool isUsualDeallocationFunction(const CXXMethodDecl *FD); |
1987 | |
1988 | bool isCompleteType(SourceLocation Loc, QualType T, |
1989 | CompleteTypeKind Kind = CompleteTypeKind::Default) { |
1990 | return !RequireCompleteTypeImpl(Loc, T, Kind, nullptr); |
1991 | } |
1992 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
1993 | CompleteTypeKind Kind, TypeDiagnoser &Diagnoser); |
1994 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
1995 | CompleteTypeKind Kind, unsigned DiagID); |
1996 | |
1997 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
1998 | TypeDiagnoser &Diagnoser) { |
1999 | return RequireCompleteType(Loc, T, CompleteTypeKind::Default, Diagnoser); |
2000 | } |
2001 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID) { |
2002 | return RequireCompleteType(Loc, T, CompleteTypeKind::Default, DiagID); |
2003 | } |
2004 | |
2005 | template <typename... Ts> |
2006 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID, |
2007 | const Ts &...Args) { |
2008 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2009 | return RequireCompleteType(Loc, T, Diagnoser); |
2010 | } |
2011 | |
2012 | template <typename... Ts> |
2013 | bool RequireCompleteSizedType(SourceLocation Loc, QualType T, unsigned DiagID, |
2014 | const Ts &... Args) { |
2015 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2016 | return RequireCompleteType(Loc, T, CompleteTypeKind::Normal, Diagnoser); |
2017 | } |
2018 | |
2019 | void completeExprArrayBound(Expr *E); |
2020 | bool RequireCompleteExprType(Expr *E, CompleteTypeKind Kind, |
2021 | TypeDiagnoser &Diagnoser); |
2022 | bool RequireCompleteExprType(Expr *E, unsigned DiagID); |
2023 | |
2024 | template <typename... Ts> |
2025 | bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) { |
2026 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2027 | return RequireCompleteExprType(E, CompleteTypeKind::Default, Diagnoser); |
2028 | } |
2029 | |
2030 | template <typename... Ts> |
2031 | bool RequireCompleteSizedExprType(Expr *E, unsigned DiagID, |
2032 | const Ts &... Args) { |
2033 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2034 | return RequireCompleteExprType(E, CompleteTypeKind::Normal, Diagnoser); |
2035 | } |
2036 | |
2037 | bool RequireLiteralType(SourceLocation Loc, QualType T, |
2038 | TypeDiagnoser &Diagnoser); |
2039 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID); |
2040 | |
2041 | template <typename... Ts> |
2042 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID, |
2043 | const Ts &...Args) { |
2044 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2045 | return RequireLiteralType(Loc, T, Diagnoser); |
2046 | } |
2047 | |
2048 | QualType getElaboratedType(ElaboratedTypeKeyword Keyword, |
2049 | const CXXScopeSpec &SS, QualType T, |
2050 | TagDecl *OwnedTagDecl = nullptr); |
2051 | |
2052 | QualType BuildTypeofExprType(Expr *E, SourceLocation Loc); |
2053 | /// If AsUnevaluated is false, E is treated as though it were an evaluated |
2054 | /// context, such as when building a type for decltype(auto). |
2055 | QualType BuildDecltypeType(Expr *E, SourceLocation Loc, |
2056 | bool AsUnevaluated = true); |
2057 | QualType BuildUnaryTransformType(QualType BaseType, |
2058 | UnaryTransformType::UTTKind UKind, |
2059 | SourceLocation Loc); |
2060 | |
2061 | //===--------------------------------------------------------------------===// |
2062 | // Symbol table / Decl tracking callbacks: SemaDecl.cpp. |
2063 | // |
2064 | |
2065 | struct SkipBodyInfo { |
2066 | SkipBodyInfo() |
2067 | : ShouldSkip(false), CheckSameAsPrevious(false), Previous(nullptr), |
2068 | New(nullptr) {} |
2069 | bool ShouldSkip; |
2070 | bool CheckSameAsPrevious; |
2071 | NamedDecl *Previous; |
2072 | NamedDecl *New; |
2073 | }; |
2074 | |
2075 | DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr); |
2076 | |
2077 | void DiagnoseUseOfUnimplementedSelectors(); |
2078 | |
2079 | bool isSimpleTypeSpecifier(tok::TokenKind Kind) const; |
2080 | |
2081 | ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, |
2082 | Scope *S, CXXScopeSpec *SS = nullptr, |
2083 | bool isClassName = false, bool HasTrailingDot = false, |
2084 | ParsedType ObjectType = nullptr, |
2085 | bool IsCtorOrDtorName = false, |
2086 | bool WantNontrivialTypeSourceInfo = false, |
2087 | bool IsClassTemplateDeductionContext = true, |
2088 | IdentifierInfo **CorrectedII = nullptr); |
2089 | TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S); |
2090 | bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S); |
2091 | void DiagnoseUnknownTypeName(IdentifierInfo *&II, |
2092 | SourceLocation IILoc, |
2093 | Scope *S, |
2094 | CXXScopeSpec *SS, |
2095 | ParsedType &SuggestedType, |
2096 | bool IsTemplateName = false); |
2097 | |
2098 | /// Attempt to behave like MSVC in situations where lookup of an unqualified |
2099 | /// type name has failed in a dependent context. In these situations, we |
2100 | /// automatically form a DependentTypeName that will retry lookup in a related |
2101 | /// scope during instantiation. |
2102 | ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II, |
2103 | SourceLocation NameLoc, |
2104 | bool IsTemplateTypeArg); |
2105 | |
2106 | /// Describes the result of the name lookup and resolution performed |
2107 | /// by \c ClassifyName(). |
2108 | enum NameClassificationKind { |
2109 | /// This name is not a type or template in this context, but might be |
2110 | /// something else. |
2111 | NC_Unknown, |
2112 | /// Classification failed; an error has been produced. |
2113 | NC_Error, |
2114 | /// The name has been typo-corrected to a keyword. |
2115 | NC_Keyword, |
2116 | /// The name was classified as a type. |
2117 | NC_Type, |
2118 | /// The name was classified as a specific non-type, non-template |
2119 | /// declaration. ActOnNameClassifiedAsNonType should be called to |
2120 | /// convert the declaration to an expression. |
2121 | NC_NonType, |
2122 | /// The name was classified as an ADL-only function name. |
2123 | /// ActOnNameClassifiedAsUndeclaredNonType should be called to convert the |
2124 | /// result to an expression. |
2125 | NC_UndeclaredNonType, |
2126 | /// The name denotes a member of a dependent type that could not be |
2127 | /// resolved. ActOnNameClassifiedAsDependentNonType should be called to |
2128 | /// convert the result to an expression. |
2129 | NC_DependentNonType, |
2130 | /// The name was classified as an overload set, and an expression |
2131 | /// representing that overload set has been formed. |
2132 | /// ActOnNameClassifiedAsOverloadSet should be called to form a suitable |
2133 | /// expression referencing the overload set. |
2134 | NC_OverloadSet, |
2135 | /// The name was classified as a template whose specializations are types. |
2136 | NC_TypeTemplate, |
2137 | /// The name was classified as a variable template name. |
2138 | NC_VarTemplate, |
2139 | /// The name was classified as a function template name. |
2140 | NC_FunctionTemplate, |
2141 | /// The name was classified as an ADL-only function template name. |
2142 | NC_UndeclaredTemplate, |
2143 | /// The name was classified as a concept name. |
2144 | NC_Concept, |
2145 | }; |
2146 | |
2147 | class NameClassification { |
2148 | NameClassificationKind Kind; |
2149 | union { |
2150 | ExprResult Expr; |
2151 | NamedDecl *NonTypeDecl; |
2152 | TemplateName Template; |
2153 | ParsedType Type; |
2154 | }; |
2155 | |
2156 | explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {} |
2157 | |
2158 | public: |
2159 | NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {} |
2160 | |
2161 | NameClassification(const IdentifierInfo *Keyword) : Kind(NC_Keyword) {} |
2162 | |
2163 | static NameClassification Error() { |
2164 | return NameClassification(NC_Error); |
2165 | } |
2166 | |
2167 | static NameClassification Unknown() { |
2168 | return NameClassification(NC_Unknown); |
2169 | } |
2170 | |
2171 | static NameClassification OverloadSet(ExprResult E) { |
2172 | NameClassification Result(NC_OverloadSet); |
2173 | Result.Expr = E; |
2174 | return Result; |
2175 | } |
2176 | |
2177 | static NameClassification NonType(NamedDecl *D) { |
2178 | NameClassification Result(NC_NonType); |
2179 | Result.NonTypeDecl = D; |
2180 | return Result; |
2181 | } |
2182 | |
2183 | static NameClassification UndeclaredNonType() { |
2184 | return NameClassification(NC_UndeclaredNonType); |
2185 | } |
2186 | |
2187 | static NameClassification DependentNonType() { |
2188 | return NameClassification(NC_DependentNonType); |
2189 | } |
2190 | |
2191 | static NameClassification TypeTemplate(TemplateName Name) { |
2192 | NameClassification Result(NC_TypeTemplate); |
2193 | Result.Template = Name; |
2194 | return Result; |
2195 | } |
2196 | |
2197 | static NameClassification VarTemplate(TemplateName Name) { |
2198 | NameClassification Result(NC_VarTemplate); |
2199 | Result.Template = Name; |
2200 | return Result; |
2201 | } |
2202 | |
2203 | static NameClassification FunctionTemplate(TemplateName Name) { |
2204 | NameClassification Result(NC_FunctionTemplate); |
2205 | Result.Template = Name; |
2206 | return Result; |
2207 | } |
2208 | |
2209 | static NameClassification Concept(TemplateName Name) { |
2210 | NameClassification Result(NC_Concept); |
2211 | Result.Template = Name; |
2212 | return Result; |
2213 | } |
2214 | |
2215 | static NameClassification UndeclaredTemplate(TemplateName Name) { |
2216 | NameClassification Result(NC_UndeclaredTemplate); |
2217 | Result.Template = Name; |
2218 | return Result; |
2219 | } |
2220 | |
2221 | NameClassificationKind getKind() const { return Kind; } |
2222 | |
2223 | ExprResult getExpression() const { |
2224 | assert(Kind == NC_OverloadSet)((Kind == NC_OverloadSet) ? static_cast<void> (0) : __assert_fail ("Kind == NC_OverloadSet", "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 2224, __PRETTY_FUNCTION__)); |
2225 | return Expr; |
2226 | } |
2227 | |
2228 | ParsedType getType() const { |
2229 | assert(Kind == NC_Type)((Kind == NC_Type) ? static_cast<void> (0) : __assert_fail ("Kind == NC_Type", "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 2229, __PRETTY_FUNCTION__)); |
2230 | return Type; |
2231 | } |
2232 | |
2233 | NamedDecl *getNonTypeDecl() const { |
2234 | assert(Kind == NC_NonType)((Kind == NC_NonType) ? static_cast<void> (0) : __assert_fail ("Kind == NC_NonType", "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 2234, __PRETTY_FUNCTION__)); |
2235 | return NonTypeDecl; |
2236 | } |
2237 | |
2238 | TemplateName getTemplateName() const { |
2239 | assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate ||((Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate ) ? static_cast<void> (0) : __assert_fail ("Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 2241, __PRETTY_FUNCTION__)) |
2240 | Kind == NC_VarTemplate || Kind == NC_Concept ||((Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate ) ? static_cast<void> (0) : __assert_fail ("Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 2241, __PRETTY_FUNCTION__)) |
2241 | Kind == NC_UndeclaredTemplate)((Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate ) ? static_cast<void> (0) : __assert_fail ("Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 2241, __PRETTY_FUNCTION__)); |
2242 | return Template; |
2243 | } |
2244 | |
2245 | TemplateNameKind getTemplateNameKind() const { |
2246 | switch (Kind) { |
2247 | case NC_TypeTemplate: |
2248 | return TNK_Type_template; |
2249 | case NC_FunctionTemplate: |
2250 | return TNK_Function_template; |
2251 | case NC_VarTemplate: |
2252 | return TNK_Var_template; |
2253 | case NC_Concept: |
2254 | return TNK_Concept_template; |
2255 | case NC_UndeclaredTemplate: |
2256 | return TNK_Undeclared_template; |
2257 | default: |
2258 | llvm_unreachable("unsupported name classification.")::llvm::llvm_unreachable_internal("unsupported name classification." , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 2258); |
2259 | } |
2260 | } |
2261 | }; |
2262 | |
2263 | /// Perform name lookup on the given name, classifying it based on |
2264 | /// the results of name lookup and the following token. |
2265 | /// |
2266 | /// This routine is used by the parser to resolve identifiers and help direct |
2267 | /// parsing. When the identifier cannot be found, this routine will attempt |
2268 | /// to correct the typo and classify based on the resulting name. |
2269 | /// |
2270 | /// \param S The scope in which we're performing name lookup. |
2271 | /// |
2272 | /// \param SS The nested-name-specifier that precedes the name. |
2273 | /// |
2274 | /// \param Name The identifier. If typo correction finds an alternative name, |
2275 | /// this pointer parameter will be updated accordingly. |
2276 | /// |
2277 | /// \param NameLoc The location of the identifier. |
2278 | /// |
2279 | /// \param NextToken The token following the identifier. Used to help |
2280 | /// disambiguate the name. |
2281 | /// |
2282 | /// \param CCC The correction callback, if typo correction is desired. |
2283 | NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS, |
2284 | IdentifierInfo *&Name, SourceLocation NameLoc, |
2285 | const Token &NextToken, |
2286 | CorrectionCandidateCallback *CCC = nullptr); |
2287 | |
2288 | /// Act on the result of classifying a name as an undeclared (ADL-only) |
2289 | /// non-type declaration. |
2290 | ExprResult ActOnNameClassifiedAsUndeclaredNonType(IdentifierInfo *Name, |
2291 | SourceLocation NameLoc); |
2292 | /// Act on the result of classifying a name as an undeclared member of a |
2293 | /// dependent base class. |
2294 | ExprResult ActOnNameClassifiedAsDependentNonType(const CXXScopeSpec &SS, |
2295 | IdentifierInfo *Name, |
2296 | SourceLocation NameLoc, |
2297 | bool IsAddressOfOperand); |
2298 | /// Act on the result of classifying a name as a specific non-type |
2299 | /// declaration. |
2300 | ExprResult ActOnNameClassifiedAsNonType(Scope *S, const CXXScopeSpec &SS, |
2301 | NamedDecl *Found, |
2302 | SourceLocation NameLoc, |
2303 | const Token &NextToken); |
2304 | /// Act on the result of classifying a name as an overload set. |
2305 | ExprResult ActOnNameClassifiedAsOverloadSet(Scope *S, Expr *OverloadSet); |
2306 | |
2307 | /// Describes the detailed kind of a template name. Used in diagnostics. |
2308 | enum class TemplateNameKindForDiagnostics { |
2309 | ClassTemplate, |
2310 | FunctionTemplate, |
2311 | VarTemplate, |
2312 | AliasTemplate, |
2313 | TemplateTemplateParam, |
2314 | Concept, |
2315 | DependentTemplate |
2316 | }; |
2317 | TemplateNameKindForDiagnostics |
2318 | getTemplateNameKindForDiagnostics(TemplateName Name); |
2319 | |
2320 | /// Determine whether it's plausible that E was intended to be a |
2321 | /// template-name. |
2322 | bool mightBeIntendedToBeTemplateName(ExprResult E, bool &Dependent) { |
2323 | if (!getLangOpts().CPlusPlus || E.isInvalid()) |
2324 | return false; |
2325 | Dependent = false; |
2326 | if (auto *DRE = dyn_cast<DeclRefExpr>(E.get())) |
2327 | return !DRE->hasExplicitTemplateArgs(); |
2328 | if (auto *ME = dyn_cast<MemberExpr>(E.get())) |
2329 | return !ME->hasExplicitTemplateArgs(); |
2330 | Dependent = true; |
2331 | if (auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(E.get())) |
2332 | return !DSDRE->hasExplicitTemplateArgs(); |
2333 | if (auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(E.get())) |
2334 | return !DSME->hasExplicitTemplateArgs(); |
2335 | // Any additional cases recognized here should also be handled by |
2336 | // diagnoseExprIntendedAsTemplateName. |
2337 | return false; |
2338 | } |
2339 | void diagnoseExprIntendedAsTemplateName(Scope *S, ExprResult TemplateName, |
2340 | SourceLocation Less, |
2341 | SourceLocation Greater); |
2342 | |
2343 | Decl *ActOnDeclarator(Scope *S, Declarator &D); |
2344 | |
2345 | NamedDecl *HandleDeclarator(Scope *S, Declarator &D, |
2346 | MultiTemplateParamsArg TemplateParameterLists); |
2347 | void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S); |
2348 | bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info); |
2349 | bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, |
2350 | DeclarationName Name, SourceLocation Loc, |
2351 | bool IsTemplateId); |
2352 | void |
2353 | diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals, |
2354 | SourceLocation FallbackLoc, |
2355 | SourceLocation ConstQualLoc = SourceLocation(), |
2356 | SourceLocation VolatileQualLoc = SourceLocation(), |
2357 | SourceLocation RestrictQualLoc = SourceLocation(), |
2358 | SourceLocation AtomicQualLoc = SourceLocation(), |
2359 | SourceLocation UnalignedQualLoc = SourceLocation()); |
2360 | |
2361 | static bool adjustContextForLocalExternDecl(DeclContext *&DC); |
2362 | void DiagnoseFunctionSpecifiers(const DeclSpec &DS); |
2363 | NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D, |
2364 | const LookupResult &R); |
2365 | NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult &R); |
2366 | void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl, |
2367 | const LookupResult &R); |
2368 | void CheckShadow(Scope *S, VarDecl *D); |
2369 | |
2370 | /// Warn if 'E', which is an expression that is about to be modified, refers |
2371 | /// to a shadowing declaration. |
2372 | void CheckShadowingDeclModification(Expr *E, SourceLocation Loc); |
2373 | |
2374 | void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI); |
2375 | |
2376 | private: |
2377 | /// Map of current shadowing declarations to shadowed declarations. Warn if |
2378 | /// it looks like the user is trying to modify the shadowing declaration. |
2379 | llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls; |
2380 | |
2381 | public: |
2382 | void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); |
2383 | void handleTagNumbering(const TagDecl *Tag, Scope *TagScope); |
2384 | void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec, |
2385 | TypedefNameDecl *NewTD); |
2386 | void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D); |
2387 | NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
2388 | TypeSourceInfo *TInfo, |
2389 | LookupResult &Previous); |
2390 | NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D, |
2391 | LookupResult &Previous, bool &Redeclaration); |
2392 | NamedDecl *ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, |
2393 | TypeSourceInfo *TInfo, |
2394 | LookupResult &Previous, |
2395 | MultiTemplateParamsArg TemplateParamLists, |
2396 | bool &AddToScope, |
2397 | ArrayRef<BindingDecl *> Bindings = None); |
2398 | NamedDecl * |
2399 | ActOnDecompositionDeclarator(Scope *S, Declarator &D, |
2400 | MultiTemplateParamsArg TemplateParamLists); |
2401 | // Returns true if the variable declaration is a redeclaration |
2402 | bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous); |
2403 | void CheckVariableDeclarationType(VarDecl *NewVD); |
2404 | bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit, |
2405 | Expr *Init); |
2406 | void CheckCompleteVariableDeclaration(VarDecl *VD); |
2407 | void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD); |
2408 | void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D); |
2409 | |
2410 | NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
2411 | TypeSourceInfo *TInfo, |
2412 | LookupResult &Previous, |
2413 | MultiTemplateParamsArg TemplateParamLists, |
2414 | bool &AddToScope); |
2415 | bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); |
2416 | |
2417 | enum class CheckConstexprKind { |
2418 | /// Diagnose issues that are non-constant or that are extensions. |
2419 | Diagnose, |
2420 | /// Identify whether this function satisfies the formal rules for constexpr |
2421 | /// functions in the current lanugage mode (with no extensions). |
2422 | CheckValid |
2423 | }; |
2424 | |
2425 | bool CheckConstexprFunctionDefinition(const FunctionDecl *FD, |
2426 | CheckConstexprKind Kind); |
2427 | |
2428 | void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD); |
2429 | void FindHiddenVirtualMethods(CXXMethodDecl *MD, |
2430 | SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods); |
2431 | void NoteHiddenVirtualMethods(CXXMethodDecl *MD, |
2432 | SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods); |
2433 | // Returns true if the function declaration is a redeclaration |
2434 | bool CheckFunctionDeclaration(Scope *S, |
2435 | FunctionDecl *NewFD, LookupResult &Previous, |
2436 | bool IsMemberSpecialization); |
2437 | bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl); |
2438 | bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD, |
2439 | QualType NewT, QualType OldT); |
2440 | void CheckMain(FunctionDecl *FD, const DeclSpec &D); |
2441 | void CheckMSVCRTEntryPoint(FunctionDecl *FD); |
2442 | Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, |
2443 | bool IsDefinition); |
2444 | void CheckFunctionOrTemplateParamDeclarator(Scope *S, Declarator &D); |
2445 | Decl *ActOnParamDeclarator(Scope *S, Declarator &D); |
2446 | ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, |
2447 | SourceLocation Loc, |
2448 | QualType T); |
2449 | ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc, |
2450 | SourceLocation NameLoc, IdentifierInfo *Name, |
2451 | QualType T, TypeSourceInfo *TSInfo, |
2452 | StorageClass SC); |
2453 | void ActOnParamDefaultArgument(Decl *param, |
2454 | SourceLocation EqualLoc, |
2455 | Expr *defarg); |
2456 | void ActOnParamUnparsedDefaultArgument(Decl *param, SourceLocation EqualLoc, |
2457 | SourceLocation ArgLoc); |
2458 | void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc); |
2459 | ExprResult ConvertParamDefaultArgument(const ParmVarDecl *Param, |
2460 | Expr *DefaultArg, |
2461 | SourceLocation EqualLoc); |
2462 | void SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
2463 | SourceLocation EqualLoc); |
2464 | |
2465 | // Contexts where using non-trivial C union types can be disallowed. This is |
2466 | // passed to err_non_trivial_c_union_in_invalid_context. |
2467 | enum NonTrivialCUnionContext { |
2468 | // Function parameter. |
2469 | NTCUC_FunctionParam, |
2470 | // Function return. |
2471 | NTCUC_FunctionReturn, |
2472 | // Default-initialized object. |
2473 | NTCUC_DefaultInitializedObject, |
2474 | // Variable with automatic storage duration. |
2475 | NTCUC_AutoVar, |
2476 | // Initializer expression that might copy from another object. |
2477 | NTCUC_CopyInit, |
2478 | // Assignment. |
2479 | NTCUC_Assignment, |
2480 | // Compound literal. |
2481 | NTCUC_CompoundLiteral, |
2482 | // Block capture. |
2483 | NTCUC_BlockCapture, |
2484 | // lvalue-to-rvalue conversion of volatile type. |
2485 | NTCUC_LValueToRValueVolatile, |
2486 | }; |
2487 | |
2488 | /// Emit diagnostics if the initializer or any of its explicit or |
2489 | /// implicitly-generated subexpressions require copying or |
2490 | /// default-initializing a type that is or contains a C union type that is |
2491 | /// non-trivial to copy or default-initialize. |
2492 | void checkNonTrivialCUnionInInitializer(const Expr *Init, SourceLocation Loc); |
2493 | |
2494 | // These flags are passed to checkNonTrivialCUnion. |
2495 | enum NonTrivialCUnionKind { |
2496 | NTCUK_Init = 0x1, |
2497 | NTCUK_Destruct = 0x2, |
2498 | NTCUK_Copy = 0x4, |
2499 | }; |
2500 | |
2501 | /// Emit diagnostics if a non-trivial C union type or a struct that contains |
2502 | /// a non-trivial C union is used in an invalid context. |
2503 | void checkNonTrivialCUnion(QualType QT, SourceLocation Loc, |
2504 | NonTrivialCUnionContext UseContext, |
2505 | unsigned NonTrivialKind); |
2506 | |
2507 | void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit); |
2508 | void ActOnUninitializedDecl(Decl *dcl); |
2509 | void ActOnInitializerError(Decl *Dcl); |
2510 | |
2511 | void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc); |
2512 | void ActOnCXXForRangeDecl(Decl *D); |
2513 | StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, |
2514 | IdentifierInfo *Ident, |
2515 | ParsedAttributes &Attrs, |
2516 | SourceLocation AttrEnd); |
2517 | void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc); |
2518 | void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc); |
2519 | void CheckStaticLocalForDllExport(VarDecl *VD); |
2520 | void FinalizeDeclaration(Decl *D); |
2521 | DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, |
2522 | ArrayRef<Decl *> Group); |
2523 | DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group); |
2524 | |
2525 | /// Should be called on all declarations that might have attached |
2526 | /// documentation comments. |
2527 | void ActOnDocumentableDecl(Decl *D); |
2528 | void ActOnDocumentableDecls(ArrayRef<Decl *> Group); |
2529 | |
2530 | void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, |
2531 | SourceLocation LocAfterDecls); |
2532 | void CheckForFunctionRedefinition( |
2533 | FunctionDecl *FD, const FunctionDecl *EffectiveDefinition = nullptr, |
2534 | SkipBodyInfo *SkipBody = nullptr); |
2535 | Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D, |
2536 | MultiTemplateParamsArg TemplateParamLists, |
2537 | SkipBodyInfo *SkipBody = nullptr); |
2538 | Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D, |
2539 | SkipBodyInfo *SkipBody = nullptr); |
2540 | void ActOnStartTrailingRequiresClause(Scope *S, Declarator &D); |
2541 | ExprResult ActOnFinishTrailingRequiresClause(ExprResult ConstraintExpr); |
2542 | void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); |
2543 | bool isObjCMethodDecl(Decl *D) { |
2544 | return D && isa<ObjCMethodDecl>(D); |
2545 | } |
2546 | |
2547 | /// Determine whether we can delay parsing the body of a function or |
2548 | /// function template until it is used, assuming we don't care about emitting |
2549 | /// code for that function. |
2550 | /// |
2551 | /// This will be \c false if we may need the body of the function in the |
2552 | /// middle of parsing an expression (where it's impractical to switch to |
2553 | /// parsing a different function), for instance, if it's constexpr in C++11 |
2554 | /// or has an 'auto' return type in C++14. These cases are essentially bugs. |
2555 | bool canDelayFunctionBody(const Declarator &D); |
2556 | |
2557 | /// Determine whether we can skip parsing the body of a function |
2558 | /// definition, assuming we don't care about analyzing its body or emitting |
2559 | /// code for that function. |
2560 | /// |
2561 | /// This will be \c false only if we may need the body of the function in |
2562 | /// order to parse the rest of the program (for instance, if it is |
2563 | /// \c constexpr in C++11 or has an 'auto' return type in C++14). |
2564 | bool canSkipFunctionBody(Decl *D); |
2565 | |
2566 | void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope); |
2567 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body); |
2568 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation); |
2569 | Decl *ActOnSkippedFunctionBody(Decl *Decl); |
2570 | void ActOnFinishInlineFunctionDef(FunctionDecl *D); |
2571 | |
2572 | /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an |
2573 | /// attribute for which parsing is delayed. |
2574 | void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs); |
2575 | |
2576 | /// Diagnose any unused parameters in the given sequence of |
2577 | /// ParmVarDecl pointers. |
2578 | void DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters); |
2579 | |
2580 | /// Diagnose whether the size of parameters or return value of a |
2581 | /// function or obj-c method definition is pass-by-value and larger than a |
2582 | /// specified threshold. |
2583 | void |
2584 | DiagnoseSizeOfParametersAndReturnValue(ArrayRef<ParmVarDecl *> Parameters, |
2585 | QualType ReturnTy, NamedDecl *D); |
2586 | |
2587 | void DiagnoseInvalidJumps(Stmt *Body); |
2588 | Decl *ActOnFileScopeAsmDecl(Expr *expr, |
2589 | SourceLocation AsmLoc, |
2590 | SourceLocation RParenLoc); |
2591 | |
2592 | /// Handle a C++11 empty-declaration and attribute-declaration. |
2593 | Decl *ActOnEmptyDeclaration(Scope *S, const ParsedAttributesView &AttrList, |
2594 | SourceLocation SemiLoc); |
2595 | |
2596 | enum class ModuleDeclKind { |
2597 | Interface, ///< 'export module X;' |
2598 | Implementation, ///< 'module X;' |
2599 | }; |
2600 | |
2601 | /// The parser has processed a module-declaration that begins the definition |
2602 | /// of a module interface or implementation. |
2603 | DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc, |
2604 | SourceLocation ModuleLoc, ModuleDeclKind MDK, |
2605 | ModuleIdPath Path, bool IsFirstDecl); |
2606 | |
2607 | /// The parser has processed a global-module-fragment declaration that begins |
2608 | /// the definition of the global module fragment of the current module unit. |
2609 | /// \param ModuleLoc The location of the 'module' keyword. |
2610 | DeclGroupPtrTy ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc); |
2611 | |
2612 | /// The parser has processed a private-module-fragment declaration that begins |
2613 | /// the definition of the private module fragment of the current module unit. |
2614 | /// \param ModuleLoc The location of the 'module' keyword. |
2615 | /// \param PrivateLoc The location of the 'private' keyword. |
2616 | DeclGroupPtrTy ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc, |
2617 | SourceLocation PrivateLoc); |
2618 | |
2619 | /// The parser has processed a module import declaration. |
2620 | /// |
2621 | /// \param StartLoc The location of the first token in the declaration. This |
2622 | /// could be the location of an '@', 'export', or 'import'. |
2623 | /// \param ExportLoc The location of the 'export' keyword, if any. |
2624 | /// \param ImportLoc The location of the 'import' keyword. |
2625 | /// \param Path The module access path. |
2626 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
2627 | SourceLocation ExportLoc, |
2628 | SourceLocation ImportLoc, ModuleIdPath Path); |
2629 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
2630 | SourceLocation ExportLoc, |
2631 | SourceLocation ImportLoc, Module *M, |
2632 | ModuleIdPath Path = {}); |
2633 | |
2634 | /// The parser has processed a module import translated from a |
2635 | /// #include or similar preprocessing directive. |
2636 | void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
2637 | void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
2638 | |
2639 | /// The parsed has entered a submodule. |
2640 | void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod); |
2641 | /// The parser has left a submodule. |
2642 | void ActOnModuleEnd(SourceLocation DirectiveLoc, Module *Mod); |
2643 | |
2644 | /// Create an implicit import of the given module at the given |
2645 | /// source location, for error recovery, if possible. |
2646 | /// |
2647 | /// This routine is typically used when an entity found by name lookup |
2648 | /// is actually hidden within a module that we know about but the user |
2649 | /// has forgotten to import. |
2650 | void createImplicitModuleImportForErrorRecovery(SourceLocation Loc, |
2651 | Module *Mod); |
2652 | |
2653 | /// Kinds of missing import. Note, the values of these enumerators correspond |
2654 | /// to %select values in diagnostics. |
2655 | enum class MissingImportKind { |
2656 | Declaration, |
2657 | Definition, |
2658 | DefaultArgument, |
2659 | ExplicitSpecialization, |
2660 | PartialSpecialization |
2661 | }; |
2662 | |
2663 | /// Diagnose that the specified declaration needs to be visible but |
2664 | /// isn't, and suggest a module import that would resolve the problem. |
2665 | void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl, |
2666 | MissingImportKind MIK, bool Recover = true); |
2667 | void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl, |
2668 | SourceLocation DeclLoc, ArrayRef<Module *> Modules, |
2669 | MissingImportKind MIK, bool Recover); |
2670 | |
2671 | Decl *ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, |
2672 | SourceLocation LBraceLoc); |
2673 | Decl *ActOnFinishExportDecl(Scope *S, Decl *ExportDecl, |
2674 | SourceLocation RBraceLoc); |
2675 | |
2676 | /// We've found a use of a templated declaration that would trigger an |
2677 | /// implicit instantiation. Check that any relevant explicit specializations |
2678 | /// and partial specializations are visible, and diagnose if not. |
2679 | void checkSpecializationVisibility(SourceLocation Loc, NamedDecl *Spec); |
2680 | |
2681 | /// We've found a use of a template specialization that would select a |
2682 | /// partial specialization. Check that the partial specialization is visible, |
2683 | /// and diagnose if not. |
2684 | void checkPartialSpecializationVisibility(SourceLocation Loc, |
2685 | NamedDecl *Spec); |
2686 | |
2687 | /// Retrieve a suitable printing policy for diagnostics. |
2688 | PrintingPolicy getPrintingPolicy() const { |
2689 | return getPrintingPolicy(Context, PP); |
2690 | } |
2691 | |
2692 | /// Retrieve a suitable printing policy for diagnostics. |
2693 | static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx, |
2694 | const Preprocessor &PP); |
2695 | |
2696 | /// Scope actions. |
2697 | void ActOnPopScope(SourceLocation Loc, Scope *S); |
2698 | void ActOnTranslationUnitScope(Scope *S); |
2699 | |
2700 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
2701 | RecordDecl *&AnonRecord); |
2702 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
2703 | MultiTemplateParamsArg TemplateParams, |
2704 | bool IsExplicitInstantiation, |
2705 | RecordDecl *&AnonRecord); |
2706 | |
2707 | Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, |
2708 | AccessSpecifier AS, |
2709 | RecordDecl *Record, |
2710 | const PrintingPolicy &Policy); |
2711 | |
2712 | Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, |
2713 | RecordDecl *Record); |
2714 | |
2715 | /// Common ways to introduce type names without a tag for use in diagnostics. |
2716 | /// Keep in sync with err_tag_reference_non_tag. |
2717 | enum NonTagKind { |
2718 | NTK_NonStruct, |
2719 | NTK_NonClass, |
2720 | NTK_NonUnion, |
2721 | NTK_NonEnum, |
2722 | NTK_Typedef, |
2723 | NTK_TypeAlias, |
2724 | NTK_Template, |
2725 | NTK_TypeAliasTemplate, |
2726 | NTK_TemplateTemplateArgument, |
2727 | }; |
2728 | |
2729 | /// Given a non-tag type declaration, returns an enum useful for indicating |
2730 | /// what kind of non-tag type this is. |
2731 | NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK); |
2732 | |
2733 | bool isAcceptableTagRedeclaration(const TagDecl *Previous, |
2734 | TagTypeKind NewTag, bool isDefinition, |
2735 | SourceLocation NewTagLoc, |
2736 | const IdentifierInfo *Name); |
2737 | |
2738 | enum TagUseKind { |
2739 | TUK_Reference, // Reference to a tag: 'struct foo *X;' |
2740 | TUK_Declaration, // Fwd decl of a tag: 'struct foo;' |
2741 | TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;' |
2742 | TUK_Friend // Friend declaration: 'friend struct foo;' |
2743 | }; |
2744 | |
2745 | Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, |
2746 | SourceLocation KWLoc, CXXScopeSpec &SS, IdentifierInfo *Name, |
2747 | SourceLocation NameLoc, const ParsedAttributesView &Attr, |
2748 | AccessSpecifier AS, SourceLocation ModulePrivateLoc, |
2749 | MultiTemplateParamsArg TemplateParameterLists, bool &OwnedDecl, |
2750 | bool &IsDependent, SourceLocation ScopedEnumKWLoc, |
2751 | bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, |
2752 | bool IsTypeSpecifier, bool IsTemplateParamOrArg, |
2753 | SkipBodyInfo *SkipBody = nullptr); |
2754 | |
2755 | Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, |
2756 | unsigned TagSpec, SourceLocation TagLoc, |
2757 | CXXScopeSpec &SS, IdentifierInfo *Name, |
2758 | SourceLocation NameLoc, |
2759 | const ParsedAttributesView &Attr, |
2760 | MultiTemplateParamsArg TempParamLists); |
2761 | |
2762 | TypeResult ActOnDependentTag(Scope *S, |
2763 | unsigned TagSpec, |
2764 | TagUseKind TUK, |
2765 | const CXXScopeSpec &SS, |
2766 | IdentifierInfo *Name, |
2767 | SourceLocation TagLoc, |
2768 | SourceLocation NameLoc); |
2769 | |
2770 | void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, |
2771 | IdentifierInfo *ClassName, |
2772 | SmallVectorImpl<Decl *> &Decls); |
2773 | Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, |
2774 | Declarator &D, Expr *BitfieldWidth); |
2775 | |
2776 | FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, |
2777 | Declarator &D, Expr *BitfieldWidth, |
2778 | InClassInitStyle InitStyle, |
2779 | AccessSpecifier AS); |
2780 | MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD, |
2781 | SourceLocation DeclStart, Declarator &D, |
2782 | Expr *BitfieldWidth, |
2783 | InClassInitStyle InitStyle, |
2784 | AccessSpecifier AS, |
2785 | const ParsedAttr &MSPropertyAttr); |
2786 | |
2787 | FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, |
2788 | TypeSourceInfo *TInfo, |
2789 | RecordDecl *Record, SourceLocation Loc, |
2790 | bool Mutable, Expr *BitfieldWidth, |
2791 | InClassInitStyle InitStyle, |
2792 | SourceLocation TSSL, |
2793 | AccessSpecifier AS, NamedDecl *PrevDecl, |
2794 | Declarator *D = nullptr); |
2795 | |
2796 | bool CheckNontrivialField(FieldDecl *FD); |
2797 | void DiagnoseNontrivial(const CXXRecordDecl *Record, CXXSpecialMember CSM); |
2798 | |
2799 | enum TrivialABIHandling { |
2800 | /// The triviality of a method unaffected by "trivial_abi". |
2801 | TAH_IgnoreTrivialABI, |
2802 | |
2803 | /// The triviality of a method affected by "trivial_abi". |
2804 | TAH_ConsiderTrivialABI |
2805 | }; |
2806 | |
2807 | bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM, |
2808 | TrivialABIHandling TAH = TAH_IgnoreTrivialABI, |
2809 | bool Diagnose = false); |
2810 | |
2811 | /// For a defaulted function, the kind of defaulted function that it is. |
2812 | class DefaultedFunctionKind { |
2813 | CXXSpecialMember SpecialMember : 8; |
2814 | DefaultedComparisonKind Comparison : 8; |
2815 | |
2816 | public: |
2817 | DefaultedFunctionKind() |
2818 | : SpecialMember(CXXInvalid), Comparison(DefaultedComparisonKind::None) { |
2819 | } |
2820 | DefaultedFunctionKind(CXXSpecialMember CSM) |
2821 | : SpecialMember(CSM), Comparison(DefaultedComparisonKind::None) {} |
2822 | DefaultedFunctionKind(DefaultedComparisonKind Comp) |
2823 | : SpecialMember(CXXInvalid), Comparison(Comp) {} |
2824 | |
2825 | bool isSpecialMember() const { return SpecialMember != CXXInvalid; } |
2826 | bool isComparison() const { |
2827 | return Comparison != DefaultedComparisonKind::None; |
2828 | } |
2829 | |
2830 | explicit operator bool() const { |
2831 | return isSpecialMember() || isComparison(); |
2832 | } |
2833 | |
2834 | CXXSpecialMember asSpecialMember() const { return SpecialMember; } |
2835 | DefaultedComparisonKind asComparison() const { return Comparison; } |
2836 | |
2837 | /// Get the index of this function kind for use in diagnostics. |
2838 | unsigned getDiagnosticIndex() const { |
2839 | static_assert(CXXInvalid > CXXDestructor, |
2840 | "invalid should have highest index"); |
2841 | static_assert((unsigned)DefaultedComparisonKind::None == 0, |
2842 | "none should be equal to zero"); |
2843 | return SpecialMember + (unsigned)Comparison; |
2844 | } |
2845 | }; |
2846 | |
2847 | DefaultedFunctionKind getDefaultedFunctionKind(const FunctionDecl *FD); |
2848 | |
2849 | CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD) { |
2850 | return getDefaultedFunctionKind(MD).asSpecialMember(); |
2851 | } |
2852 | DefaultedComparisonKind getDefaultedComparisonKind(const FunctionDecl *FD) { |
2853 | return getDefaultedFunctionKind(FD).asComparison(); |
2854 | } |
2855 | |
2856 | void ActOnLastBitfield(SourceLocation DeclStart, |
2857 | SmallVectorImpl<Decl *> &AllIvarDecls); |
2858 | Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, |
2859 | Declarator &D, Expr *BitfieldWidth, |
2860 | tok::ObjCKeywordKind visibility); |
2861 | |
2862 | // This is used for both record definitions and ObjC interface declarations. |
2863 | void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, |
2864 | ArrayRef<Decl *> Fields, SourceLocation LBrac, |
2865 | SourceLocation RBrac, const ParsedAttributesView &AttrList); |
2866 | |
2867 | /// ActOnTagStartDefinition - Invoked when we have entered the |
2868 | /// scope of a tag's definition (e.g., for an enumeration, class, |
2869 | /// struct, or union). |
2870 | void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); |
2871 | |
2872 | /// Perform ODR-like check for C/ObjC when merging tag types from modules. |
2873 | /// Differently from C++, actually parse the body and reject / error out |
2874 | /// in case of a structural mismatch. |
2875 | bool ActOnDuplicateDefinition(DeclSpec &DS, Decl *Prev, |
2876 | SkipBodyInfo &SkipBody); |
2877 | |
2878 | typedef void *SkippedDefinitionContext; |
2879 | |
2880 | /// Invoked when we enter a tag definition that we're skipping. |
2881 | SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD); |
2882 | |
2883 | Decl *ActOnObjCContainerStartDefinition(Decl *IDecl); |
2884 | |
2885 | /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a |
2886 | /// C++ record definition's base-specifiers clause and are starting its |
2887 | /// member declarations. |
2888 | void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, |
2889 | SourceLocation FinalLoc, |
2890 | bool IsFinalSpelledSealed, |
2891 | SourceLocation LBraceLoc); |
2892 | |
2893 | /// ActOnTagFinishDefinition - Invoked once we have finished parsing |
2894 | /// the definition of a tag (enumeration, class, struct, or union). |
2895 | void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, |
2896 | SourceRange BraceRange); |
2897 | |
2898 | void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context); |
2899 | |
2900 | void ActOnObjCContainerFinishDefinition(); |
2901 | |
2902 | /// Invoked when we must temporarily exit the objective-c container |
2903 | /// scope for parsing/looking-up C constructs. |
2904 | /// |
2905 | /// Must be followed by a call to \see ActOnObjCReenterContainerContext |
2906 | void ActOnObjCTemporaryExitContainerContext(DeclContext *DC); |
2907 | void ActOnObjCReenterContainerContext(DeclContext *DC); |
2908 | |
2909 | /// ActOnTagDefinitionError - Invoked when there was an unrecoverable |
2910 | /// error parsing the definition of a tag. |
2911 | void ActOnTagDefinitionError(Scope *S, Decl *TagDecl); |
2912 | |
2913 | EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, |
2914 | EnumConstantDecl *LastEnumConst, |
2915 | SourceLocation IdLoc, |
2916 | IdentifierInfo *Id, |
2917 | Expr *val); |
2918 | bool CheckEnumUnderlyingType(TypeSourceInfo *TI); |
2919 | bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, |
2920 | QualType EnumUnderlyingTy, bool IsFixed, |
2921 | const EnumDecl *Prev); |
2922 | |
2923 | /// Determine whether the body of an anonymous enumeration should be skipped. |
2924 | /// \param II The name of the first enumerator. |
2925 | SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, |
2926 | SourceLocation IILoc); |
2927 | |
2928 | Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, |
2929 | SourceLocation IdLoc, IdentifierInfo *Id, |
2930 | const ParsedAttributesView &Attrs, |
2931 | SourceLocation EqualLoc, Expr *Val); |
2932 | void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, |
2933 | Decl *EnumDecl, ArrayRef<Decl *> Elements, Scope *S, |
2934 | const ParsedAttributesView &Attr); |
2935 | |
2936 | /// Set the current declaration context until it gets popped. |
2937 | void PushDeclContext(Scope *S, DeclContext *DC); |
2938 | void PopDeclContext(); |
2939 | |
2940 | /// EnterDeclaratorContext - Used when we must lookup names in the context |
2941 | /// of a declarator's nested name specifier. |
2942 | void EnterDeclaratorContext(Scope *S, DeclContext *DC); |
2943 | void ExitDeclaratorContext(Scope *S); |
2944 | |
2945 | /// Enter a template parameter scope, after it's been associated with a particular |
2946 | /// DeclContext. Causes lookup within the scope to chain through enclosing contexts |
2947 | /// in the correct order. |
2948 | void EnterTemplatedContext(Scope *S, DeclContext *DC); |
2949 | |
2950 | /// Push the parameters of D, which must be a function, into scope. |
2951 | void ActOnReenterFunctionContext(Scope* S, Decl* D); |
2952 | void ActOnExitFunctionContext(); |
2953 | |
2954 | DeclContext *getFunctionLevelDeclContext(); |
2955 | |
2956 | /// getCurFunctionDecl - If inside of a function body, this returns a pointer |
2957 | /// to the function decl for the function being parsed. If we're currently |
2958 | /// in a 'block', this returns the containing context. |
2959 | FunctionDecl *getCurFunctionDecl(); |
2960 | |
2961 | /// getCurMethodDecl - If inside of a method body, this returns a pointer to |
2962 | /// the method decl for the method being parsed. If we're currently |
2963 | /// in a 'block', this returns the containing context. |
2964 | ObjCMethodDecl *getCurMethodDecl(); |
2965 | |
2966 | /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method |
2967 | /// or C function we're in, otherwise return null. If we're currently |
2968 | /// in a 'block', this returns the containing context. |
2969 | NamedDecl *getCurFunctionOrMethodDecl(); |
2970 | |
2971 | /// Add this decl to the scope shadowed decl chains. |
2972 | void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true); |
2973 | |
2974 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
2975 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
2976 | /// true if 'D' belongs to the given declaration context. |
2977 | /// |
2978 | /// \param AllowInlineNamespace If \c true, allow the declaration to be in the |
2979 | /// enclosing namespace set of the context, rather than contained |
2980 | /// directly within it. |
2981 | bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr, |
2982 | bool AllowInlineNamespace = false); |
2983 | |
2984 | /// Finds the scope corresponding to the given decl context, if it |
2985 | /// happens to be an enclosing scope. Otherwise return NULL. |
2986 | static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC); |
2987 | |
2988 | /// Subroutines of ActOnDeclarator(). |
2989 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, |
2990 | TypeSourceInfo *TInfo); |
2991 | bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New); |
2992 | |
2993 | /// Describes the kind of merge to perform for availability |
2994 | /// attributes (including "deprecated", "unavailable", and "availability"). |
2995 | enum AvailabilityMergeKind { |
2996 | /// Don't merge availability attributes at all. |
2997 | AMK_None, |
2998 | /// Merge availability attributes for a redeclaration, which requires |
2999 | /// an exact match. |
3000 | AMK_Redeclaration, |
3001 | /// Merge availability attributes for an override, which requires |
3002 | /// an exact match or a weakening of constraints. |
3003 | AMK_Override, |
3004 | /// Merge availability attributes for an implementation of |
3005 | /// a protocol requirement. |
3006 | AMK_ProtocolImplementation, |
3007 | }; |
3008 | |
3009 | /// Describes the kind of priority given to an availability attribute. |
3010 | /// |
3011 | /// The sum of priorities deteremines the final priority of the attribute. |
3012 | /// The final priority determines how the attribute will be merged. |
3013 | /// An attribute with a lower priority will always remove higher priority |
3014 | /// attributes for the specified platform when it is being applied. An |
3015 | /// attribute with a higher priority will not be applied if the declaration |
3016 | /// already has an availability attribute with a lower priority for the |
3017 | /// specified platform. The final prirority values are not expected to match |
3018 | /// the values in this enumeration, but instead should be treated as a plain |
3019 | /// integer value. This enumeration just names the priority weights that are |
3020 | /// used to calculate that final vaue. |
3021 | enum AvailabilityPriority : int { |
3022 | /// The availability attribute was specified explicitly next to the |
3023 | /// declaration. |
3024 | AP_Explicit = 0, |
3025 | |
3026 | /// The availability attribute was applied using '#pragma clang attribute'. |
3027 | AP_PragmaClangAttribute = 1, |
3028 | |
3029 | /// The availability attribute for a specific platform was inferred from |
3030 | /// an availability attribute for another platform. |
3031 | AP_InferredFromOtherPlatform = 2 |
3032 | }; |
3033 | |
3034 | /// Attribute merging methods. Return true if a new attribute was added. |
3035 | AvailabilityAttr * |
3036 | mergeAvailabilityAttr(NamedDecl *D, const AttributeCommonInfo &CI, |
3037 | IdentifierInfo *Platform, bool Implicit, |
3038 | VersionTuple Introduced, VersionTuple Deprecated, |
3039 | VersionTuple Obsoleted, bool IsUnavailable, |
3040 | StringRef Message, bool IsStrict, StringRef Replacement, |
3041 | AvailabilityMergeKind AMK, int Priority); |
3042 | TypeVisibilityAttr * |
3043 | mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
3044 | TypeVisibilityAttr::VisibilityType Vis); |
3045 | VisibilityAttr *mergeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
3046 | VisibilityAttr::VisibilityType Vis); |
3047 | UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI, |
3048 | StringRef UuidAsWritten, MSGuidDecl *GuidDecl); |
3049 | DLLImportAttr *mergeDLLImportAttr(Decl *D, const AttributeCommonInfo &CI); |
3050 | DLLExportAttr *mergeDLLExportAttr(Decl *D, const AttributeCommonInfo &CI); |
3051 | MSInheritanceAttr *mergeMSInheritanceAttr(Decl *D, |
3052 | const AttributeCommonInfo &CI, |
3053 | bool BestCase, |
3054 | MSInheritanceModel Model); |
3055 | FormatAttr *mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI, |
3056 | IdentifierInfo *Format, int FormatIdx, |
3057 | int FirstArg); |
3058 | SectionAttr *mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI, |
3059 | StringRef Name); |
3060 | CodeSegAttr *mergeCodeSegAttr(Decl *D, const AttributeCommonInfo &CI, |
3061 | StringRef Name); |
3062 | AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, |
3063 | const AttributeCommonInfo &CI, |
3064 | const IdentifierInfo *Ident); |
3065 | MinSizeAttr *mergeMinSizeAttr(Decl *D, const AttributeCommonInfo &CI); |
3066 | NoSpeculativeLoadHardeningAttr * |
3067 | mergeNoSpeculativeLoadHardeningAttr(Decl *D, |
3068 | const NoSpeculativeLoadHardeningAttr &AL); |
3069 | SpeculativeLoadHardeningAttr * |
3070 | mergeSpeculativeLoadHardeningAttr(Decl *D, |
3071 | const SpeculativeLoadHardeningAttr &AL); |
3072 | SwiftNameAttr *mergeSwiftNameAttr(Decl *D, const SwiftNameAttr &SNA, |
3073 | StringRef Name); |
3074 | OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, |
3075 | const AttributeCommonInfo &CI); |
3076 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL); |
3077 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, |
3078 | const InternalLinkageAttr &AL); |
3079 | CommonAttr *mergeCommonAttr(Decl *D, const ParsedAttr &AL); |
3080 | CommonAttr *mergeCommonAttr(Decl *D, const CommonAttr &AL); |
3081 | WebAssemblyImportNameAttr *mergeImportNameAttr( |
3082 | Decl *D, const WebAssemblyImportNameAttr &AL); |
3083 | WebAssemblyImportModuleAttr *mergeImportModuleAttr( |
3084 | Decl *D, const WebAssemblyImportModuleAttr &AL); |
3085 | |
3086 | void mergeDeclAttributes(NamedDecl *New, Decl *Old, |
3087 | AvailabilityMergeKind AMK = AMK_Redeclaration); |
3088 | void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, |
3089 | LookupResult &OldDecls); |
3090 | bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S, |
3091 | bool MergeTypeWithOld); |
3092 | bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, |
3093 | Scope *S, bool MergeTypeWithOld); |
3094 | void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old); |
3095 | void MergeVarDecl(VarDecl *New, LookupResult &Previous); |
3096 | void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld); |
3097 | void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old); |
3098 | bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn); |
3099 | void notePreviousDefinition(const NamedDecl *Old, SourceLocation New); |
3100 | bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S); |
3101 | |
3102 | // AssignmentAction - This is used by all the assignment diagnostic functions |
3103 | // to represent what is actually causing the operation |
3104 | enum AssignmentAction { |
3105 | AA_Assigning, |
3106 | AA_Passing, |
3107 | AA_Returning, |
3108 | AA_Converting, |
3109 | AA_Initializing, |
3110 | AA_Sending, |
3111 | AA_Casting, |
3112 | AA_Passing_CFAudited |
3113 | }; |
3114 | |
3115 | /// C++ Overloading. |
3116 | enum OverloadKind { |
3117 | /// This is a legitimate overload: the existing declarations are |
3118 | /// functions or function templates with different signatures. |
3119 | Ovl_Overload, |
3120 | |
3121 | /// This is not an overload because the signature exactly matches |
3122 | /// an existing declaration. |
3123 | Ovl_Match, |
3124 | |
3125 | /// This is not an overload because the lookup results contain a |
3126 | /// non-function. |
3127 | Ovl_NonFunction |
3128 | }; |
3129 | OverloadKind CheckOverload(Scope *S, |
3130 | FunctionDecl *New, |
3131 | const LookupResult &OldDecls, |
3132 | NamedDecl *&OldDecl, |
3133 | bool IsForUsingDecl); |
3134 | bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl, |
3135 | bool ConsiderCudaAttrs = true, |
3136 | bool ConsiderRequiresClauses = true); |
3137 | |
3138 | enum class AllowedExplicit { |
3139 | /// Allow no explicit functions to be used. |
3140 | None, |
3141 | /// Allow explicit conversion functions but not explicit constructors. |
3142 | Conversions, |
3143 | /// Allow both explicit conversion functions and explicit constructors. |
3144 | All |
3145 | }; |
3146 | |
3147 | ImplicitConversionSequence |
3148 | TryImplicitConversion(Expr *From, QualType ToType, |
3149 | bool SuppressUserConversions, |
3150 | AllowedExplicit AllowExplicit, |
3151 | bool InOverloadResolution, |
3152 | bool CStyle, |
3153 | bool AllowObjCWritebackConversion); |
3154 | |
3155 | bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); |
3156 | bool IsFloatingPointPromotion(QualType FromType, QualType ToType); |
3157 | bool IsComplexPromotion(QualType FromType, QualType ToType); |
3158 | bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, |
3159 | bool InOverloadResolution, |
3160 | QualType& ConvertedType, bool &IncompatibleObjC); |
3161 | bool isObjCPointerConversion(QualType FromType, QualType ToType, |
3162 | QualType& ConvertedType, bool &IncompatibleObjC); |
3163 | bool isObjCWritebackConversion(QualType FromType, QualType ToType, |
3164 | QualType &ConvertedType); |
3165 | bool IsBlockPointerConversion(QualType FromType, QualType ToType, |
3166 | QualType& ConvertedType); |
3167 | bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType, |
3168 | const FunctionProtoType *NewType, |
3169 | unsigned *ArgPos = nullptr); |
3170 | void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, |
3171 | QualType FromType, QualType ToType); |
3172 | |
3173 | void maybeExtendBlockObject(ExprResult &E); |
3174 | CastKind PrepareCastToObjCObjectPointer(ExprResult &E); |
3175 | bool CheckPointerConversion(Expr *From, QualType ToType, |
3176 | CastKind &Kind, |
3177 | CXXCastPath& BasePath, |
3178 | bool IgnoreBaseAccess, |
3179 | bool Diagnose = true); |
3180 | bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, |
3181 | bool InOverloadResolution, |
3182 | QualType &ConvertedType); |
3183 | bool CheckMemberPointerConversion(Expr *From, QualType ToType, |
3184 | CastKind &Kind, |
3185 | CXXCastPath &BasePath, |
3186 | bool IgnoreBaseAccess); |
3187 | bool IsQualificationConversion(QualType FromType, QualType ToType, |
3188 | bool CStyle, bool &ObjCLifetimeConversion); |
3189 | bool IsFunctionConversion(QualType FromType, QualType ToType, |
3190 | QualType &ResultTy); |
3191 | bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); |
3192 | bool isSameOrCompatibleFunctionType(CanQualType Param, CanQualType Arg); |
3193 | |
3194 | ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity, |
3195 | const VarDecl *NRVOCandidate, |
3196 | QualType ResultType, |
3197 | Expr *Value, |
3198 | bool AllowNRVO = true); |
3199 | |
3200 | bool CanPerformAggregateInitializationForOverloadResolution( |
3201 | const InitializedEntity &Entity, InitListExpr *From); |
3202 | |
3203 | bool CanPerformCopyInitialization(const InitializedEntity &Entity, |
3204 | ExprResult Init); |
3205 | ExprResult PerformCopyInitialization(const InitializedEntity &Entity, |
3206 | SourceLocation EqualLoc, |
3207 | ExprResult Init, |
3208 | bool TopLevelOfInitList = false, |
3209 | bool AllowExplicit = false); |
3210 | ExprResult PerformObjectArgumentInitialization(Expr *From, |
3211 | NestedNameSpecifier *Qualifier, |
3212 | NamedDecl *FoundDecl, |
3213 | CXXMethodDecl *Method); |
3214 | |
3215 | /// Check that the lifetime of the initializer (and its subobjects) is |
3216 | /// sufficient for initializing the entity, and perform lifetime extension |
3217 | /// (when permitted) if not. |
3218 | void checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init); |
3219 | |
3220 | ExprResult PerformContextuallyConvertToBool(Expr *From); |
3221 | ExprResult PerformContextuallyConvertToObjCPointer(Expr *From); |
3222 | |
3223 | /// Contexts in which a converted constant expression is required. |
3224 | enum CCEKind { |
3225 | CCEK_CaseValue, ///< Expression in a case label. |
3226 | CCEK_Enumerator, ///< Enumerator value with fixed underlying type. |
3227 | CCEK_TemplateArg, ///< Value of a non-type template parameter. |
3228 | CCEK_ArrayBound, ///< Array bound in array declarator or new-expression. |
3229 | CCEK_ConstexprIf, ///< Condition in a constexpr if statement. |
3230 | CCEK_ExplicitBool ///< Condition in an explicit(bool) specifier. |
3231 | }; |
3232 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
3233 | llvm::APSInt &Value, CCEKind CCE); |
3234 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
3235 | APValue &Value, CCEKind CCE); |
3236 | |
3237 | /// Abstract base class used to perform a contextual implicit |
3238 | /// conversion from an expression to any type passing a filter. |
3239 | class ContextualImplicitConverter { |
3240 | public: |
3241 | bool Suppress; |
3242 | bool SuppressConversion; |
3243 | |
3244 | ContextualImplicitConverter(bool Suppress = false, |
3245 | bool SuppressConversion = false) |
3246 | : Suppress(Suppress), SuppressConversion(SuppressConversion) {} |
3247 | |
3248 | /// Determine whether the specified type is a valid destination type |
3249 | /// for this conversion. |
3250 | virtual bool match(QualType T) = 0; |
3251 | |
3252 | /// Emits a diagnostic complaining that the expression does not have |
3253 | /// integral or enumeration type. |
3254 | virtual SemaDiagnosticBuilder |
3255 | diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) = 0; |
3256 | |
3257 | /// Emits a diagnostic when the expression has incomplete class type. |
3258 | virtual SemaDiagnosticBuilder |
3259 | diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0; |
3260 | |
3261 | /// Emits a diagnostic when the only matching conversion function |
3262 | /// is explicit. |
3263 | virtual SemaDiagnosticBuilder diagnoseExplicitConv( |
3264 | Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0; |
3265 | |
3266 | /// Emits a note for the explicit conversion function. |
3267 | virtual SemaDiagnosticBuilder |
3268 | noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
3269 | |
3270 | /// Emits a diagnostic when there are multiple possible conversion |
3271 | /// functions. |
3272 | virtual SemaDiagnosticBuilder |
3273 | diagnoseAmbiguous(Sema &S, SourceLocation Loc, QualType T) = 0; |
3274 | |
3275 | /// Emits a note for one of the candidate conversions. |
3276 | virtual SemaDiagnosticBuilder |
3277 | noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
3278 | |
3279 | /// Emits a diagnostic when we picked a conversion function |
3280 | /// (for cases when we are not allowed to pick a conversion function). |
3281 | virtual SemaDiagnosticBuilder diagnoseConversion( |
3282 | Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0; |
3283 | |
3284 | virtual ~ContextualImplicitConverter() {} |
3285 | }; |
3286 | |
3287 | class ICEConvertDiagnoser : public ContextualImplicitConverter { |
3288 | bool AllowScopedEnumerations; |
3289 | |
3290 | public: |
3291 | ICEConvertDiagnoser(bool AllowScopedEnumerations, |
3292 | bool Suppress, bool SuppressConversion) |
3293 | : ContextualImplicitConverter(Suppress, SuppressConversion), |
3294 | AllowScopedEnumerations(AllowScopedEnumerations) {} |
3295 | |
3296 | /// Match an integral or (possibly scoped) enumeration type. |
3297 | bool match(QualType T) override; |
3298 | |
3299 | SemaDiagnosticBuilder |
3300 | diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) override { |
3301 | return diagnoseNotInt(S, Loc, T); |
3302 | } |
3303 | |
3304 | /// Emits a diagnostic complaining that the expression does not have |
3305 | /// integral or enumeration type. |
3306 | virtual SemaDiagnosticBuilder |
3307 | diagnoseNotInt(Sema &S, SourceLocation Loc, QualType T) = 0; |
3308 | }; |
3309 | |
3310 | /// Perform a contextual implicit conversion. |
3311 | ExprResult PerformContextualImplicitConversion( |
3312 | SourceLocation Loc, Expr *FromE, ContextualImplicitConverter &Converter); |
3313 | |
3314 | |
3315 | enum ObjCSubscriptKind { |
3316 | OS_Array, |
3317 | OS_Dictionary, |
3318 | OS_Error |
3319 | }; |
3320 | ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE); |
3321 | |
3322 | // Note that LK_String is intentionally after the other literals, as |
3323 | // this is used for diagnostics logic. |
3324 | enum ObjCLiteralKind { |
3325 | LK_Array, |
3326 | LK_Dictionary, |
3327 | LK_Numeric, |
3328 | LK_Boxed, |
3329 | LK_String, |
3330 | LK_Block, |
3331 | LK_None |
3332 | }; |
3333 | ObjCLiteralKind CheckLiteralKind(Expr *FromE); |
3334 | |
3335 | ExprResult PerformObjectMemberConversion(Expr *From, |
3336 | NestedNameSpecifier *Qualifier, |
3337 | NamedDecl *FoundDecl, |
3338 | NamedDecl *Member); |
3339 | |
3340 | // Members have to be NamespaceDecl* or TranslationUnitDecl*. |
3341 | // TODO: make this is a typesafe union. |
3342 | typedef llvm::SmallSetVector<DeclContext *, 16> AssociatedNamespaceSet; |
3343 | typedef llvm::SmallSetVector<CXXRecordDecl *, 16> AssociatedClassSet; |
3344 | |
3345 | using ADLCallKind = CallExpr::ADLCallKind; |
3346 | |
3347 | void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl, |
3348 | ArrayRef<Expr *> Args, |
3349 | OverloadCandidateSet &CandidateSet, |
3350 | bool SuppressUserConversions = false, |
3351 | bool PartialOverloading = false, |
3352 | bool AllowExplicit = true, |
3353 | bool AllowExplicitConversion = false, |
3354 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
3355 | ConversionSequenceList EarlyConversions = None, |
3356 | OverloadCandidateParamOrder PO = {}); |
3357 | void AddFunctionCandidates(const UnresolvedSetImpl &Functions, |
3358 | ArrayRef<Expr *> Args, |
3359 | OverloadCandidateSet &CandidateSet, |
3360 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
3361 | bool SuppressUserConversions = false, |
3362 | bool PartialOverloading = false, |
3363 | bool FirstArgumentIsBase = false); |
3364 | void AddMethodCandidate(DeclAccessPair FoundDecl, |
3365 | QualType ObjectType, |
3366 | Expr::Classification ObjectClassification, |
3367 | ArrayRef<Expr *> Args, |
3368 | OverloadCandidateSet& CandidateSet, |
3369 | bool SuppressUserConversion = false, |
3370 | OverloadCandidateParamOrder PO = {}); |
3371 | void AddMethodCandidate(CXXMethodDecl *Method, |
3372 | DeclAccessPair FoundDecl, |
3373 | CXXRecordDecl *ActingContext, QualType ObjectType, |
3374 | Expr::Classification ObjectClassification, |
3375 | ArrayRef<Expr *> Args, |
3376 | OverloadCandidateSet& CandidateSet, |
3377 | bool SuppressUserConversions = false, |
3378 | bool PartialOverloading = false, |
3379 | ConversionSequenceList EarlyConversions = None, |
3380 | OverloadCandidateParamOrder PO = {}); |
3381 | void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, |
3382 | DeclAccessPair FoundDecl, |
3383 | CXXRecordDecl *ActingContext, |
3384 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
3385 | QualType ObjectType, |
3386 | Expr::Classification ObjectClassification, |
3387 | ArrayRef<Expr *> Args, |
3388 | OverloadCandidateSet& CandidateSet, |
3389 | bool SuppressUserConversions = false, |
3390 | bool PartialOverloading = false, |
3391 | OverloadCandidateParamOrder PO = {}); |
3392 | void AddTemplateOverloadCandidate( |
3393 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
3394 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
3395 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
3396 | bool PartialOverloading = false, bool AllowExplicit = true, |
3397 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
3398 | OverloadCandidateParamOrder PO = {}); |
3399 | bool CheckNonDependentConversions( |
3400 | FunctionTemplateDecl *FunctionTemplate, ArrayRef<QualType> ParamTypes, |
3401 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, |
3402 | ConversionSequenceList &Conversions, bool SuppressUserConversions, |
3403 | CXXRecordDecl *ActingContext = nullptr, QualType ObjectType = QualType(), |
3404 | Expr::Classification ObjectClassification = {}, |
3405 | OverloadCandidateParamOrder PO = {}); |
3406 | void AddConversionCandidate( |
3407 | CXXConversionDecl *Conversion, DeclAccessPair FoundDecl, |
3408 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
3409 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
3410 | bool AllowExplicit, bool AllowResultConversion = true); |
3411 | void AddTemplateConversionCandidate( |
3412 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
3413 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
3414 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
3415 | bool AllowExplicit, bool AllowResultConversion = true); |
3416 | void AddSurrogateCandidate(CXXConversionDecl *Conversion, |
3417 | DeclAccessPair FoundDecl, |
3418 | CXXRecordDecl *ActingContext, |
3419 | const FunctionProtoType *Proto, |
3420 | Expr *Object, ArrayRef<Expr *> Args, |
3421 | OverloadCandidateSet& CandidateSet); |
3422 | void AddNonMemberOperatorCandidates( |
3423 | const UnresolvedSetImpl &Functions, ArrayRef<Expr *> Args, |
3424 | OverloadCandidateSet &CandidateSet, |
3425 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
3426 | void AddMemberOperatorCandidates(OverloadedOperatorKind Op, |
3427 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
3428 | OverloadCandidateSet &CandidateSet, |
3429 | OverloadCandidateParamOrder PO = {}); |
3430 | void AddBuiltinCandidate(QualType *ParamTys, ArrayRef<Expr *> Args, |
3431 | OverloadCandidateSet& CandidateSet, |
3432 | bool IsAssignmentOperator = false, |
3433 | unsigned NumContextualBoolArguments = 0); |
3434 | void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, |
3435 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
3436 | OverloadCandidateSet& CandidateSet); |
3437 | void AddArgumentDependentLookupCandidates(DeclarationName Name, |
3438 | SourceLocation Loc, |
3439 | ArrayRef<Expr *> Args, |
3440 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
3441 | OverloadCandidateSet& CandidateSet, |
3442 | bool PartialOverloading = false); |
3443 | |
3444 | // Emit as a 'note' the specific overload candidate |
3445 | void NoteOverloadCandidate( |
3446 | NamedDecl *Found, FunctionDecl *Fn, |
3447 | OverloadCandidateRewriteKind RewriteKind = OverloadCandidateRewriteKind(), |
3448 | QualType DestType = QualType(), bool TakingAddress = false); |
3449 | |
3450 | // Emit as a series of 'note's all template and non-templates identified by |
3451 | // the expression Expr |
3452 | void NoteAllOverloadCandidates(Expr *E, QualType DestType = QualType(), |
3453 | bool TakingAddress = false); |
3454 | |
3455 | /// Check the enable_if expressions on the given function. Returns the first |
3456 | /// failing attribute, or NULL if they were all successful. |
3457 | EnableIfAttr *CheckEnableIf(FunctionDecl *Function, SourceLocation CallLoc, |
3458 | ArrayRef<Expr *> Args, |
3459 | bool MissingImplicitThis = false); |
3460 | |
3461 | /// Find the failed Boolean condition within a given Boolean |
3462 | /// constant expression, and describe it with a string. |
3463 | std::pair<Expr *, std::string> findFailedBooleanCondition(Expr *Cond); |
3464 | |
3465 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
3466 | /// non-ArgDependent DiagnoseIfAttrs. |
3467 | /// |
3468 | /// Argument-dependent diagnose_if attributes should be checked each time a |
3469 | /// function is used as a direct callee of a function call. |
3470 | /// |
3471 | /// Returns true if any errors were emitted. |
3472 | bool diagnoseArgDependentDiagnoseIfAttrs(const FunctionDecl *Function, |
3473 | const Expr *ThisArg, |
3474 | ArrayRef<const Expr *> Args, |
3475 | SourceLocation Loc); |
3476 | |
3477 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
3478 | /// ArgDependent DiagnoseIfAttrs. |
3479 | /// |
3480 | /// Argument-independent diagnose_if attributes should be checked on every use |
3481 | /// of a function. |
3482 | /// |
3483 | /// Returns true if any errors were emitted. |
3484 | bool diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND, |
3485 | SourceLocation Loc); |
3486 | |
3487 | /// Returns whether the given function's address can be taken or not, |
3488 | /// optionally emitting a diagnostic if the address can't be taken. |
3489 | /// |
3490 | /// Returns false if taking the address of the function is illegal. |
3491 | bool checkAddressOfFunctionIsAvailable(const FunctionDecl *Function, |
3492 | bool Complain = false, |
3493 | SourceLocation Loc = SourceLocation()); |
3494 | |
3495 | // [PossiblyAFunctionType] --> [Return] |
3496 | // NonFunctionType --> NonFunctionType |
3497 | // R (A) --> R(A) |
3498 | // R (*)(A) --> R (A) |
3499 | // R (&)(A) --> R (A) |
3500 | // R (S::*)(A) --> R (A) |
3501 | QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType); |
3502 | |
3503 | FunctionDecl * |
3504 | ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, |
3505 | QualType TargetType, |
3506 | bool Complain, |
3507 | DeclAccessPair &Found, |
3508 | bool *pHadMultipleCandidates = nullptr); |
3509 | |
3510 | FunctionDecl * |
3511 | resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &FoundResult); |
3512 | |
3513 | bool resolveAndFixAddressOfSingleOverloadCandidate( |
3514 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false); |
3515 | |
3516 | FunctionDecl * |
3517 | ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, |
3518 | bool Complain = false, |
3519 | DeclAccessPair *Found = nullptr); |
3520 | |
3521 | bool ResolveAndFixSingleFunctionTemplateSpecialization( |
3522 | ExprResult &SrcExpr, |
3523 | bool DoFunctionPointerConverion = false, |
3524 | bool Complain = false, |
3525 | SourceRange OpRangeForComplaining = SourceRange(), |
3526 | QualType DestTypeForComplaining = QualType(), |
3527 | unsigned DiagIDForComplaining = 0); |
3528 | |
3529 | |
3530 | Expr *FixOverloadedFunctionReference(Expr *E, |
3531 | DeclAccessPair FoundDecl, |
3532 | FunctionDecl *Fn); |
3533 | ExprResult FixOverloadedFunctionReference(ExprResult, |
3534 | DeclAccessPair FoundDecl, |
3535 | FunctionDecl *Fn); |
3536 | |
3537 | void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, |
3538 | ArrayRef<Expr *> Args, |
3539 | OverloadCandidateSet &CandidateSet, |
3540 | bool PartialOverloading = false); |
3541 | |
3542 | // An enum used to represent the different possible results of building a |
3543 | // range-based for loop. |
3544 | enum ForRangeStatus { |
3545 | FRS_Success, |
3546 | FRS_NoViableFunction, |
3547 | FRS_DiagnosticIssued |
3548 | }; |
3549 | |
3550 | ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc, |
3551 | SourceLocation RangeLoc, |
3552 | const DeclarationNameInfo &NameInfo, |
3553 | LookupResult &MemberLookup, |
3554 | OverloadCandidateSet *CandidateSet, |
3555 | Expr *Range, ExprResult *CallExpr); |
3556 | |
3557 | ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn, |
3558 | UnresolvedLookupExpr *ULE, |
3559 | SourceLocation LParenLoc, |
3560 | MultiExprArg Args, |
3561 | SourceLocation RParenLoc, |
3562 | Expr *ExecConfig, |
3563 | bool AllowTypoCorrection=true, |
3564 | bool CalleesAddressIsTaken=false); |
3565 | |
3566 | bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, |
3567 | MultiExprArg Args, SourceLocation RParenLoc, |
3568 | OverloadCandidateSet *CandidateSet, |
3569 | ExprResult *Result); |
3570 | |
3571 | ExprResult CreateUnresolvedLookupExpr(CXXRecordDecl *NamingClass, |
3572 | NestedNameSpecifierLoc NNSLoc, |
3573 | DeclarationNameInfo DNI, |
3574 | const UnresolvedSetImpl &Fns, |
3575 | bool PerformADL = true); |
3576 | |
3577 | ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, |
3578 | UnaryOperatorKind Opc, |
3579 | const UnresolvedSetImpl &Fns, |
3580 | Expr *input, bool RequiresADL = true); |
3581 | |
3582 | void LookupOverloadedBinOp(OverloadCandidateSet &CandidateSet, |
3583 | OverloadedOperatorKind Op, |
3584 | const UnresolvedSetImpl &Fns, |
3585 | ArrayRef<Expr *> Args, bool RequiresADL = true); |
3586 | ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, |
3587 | BinaryOperatorKind Opc, |
3588 | const UnresolvedSetImpl &Fns, |
3589 | Expr *LHS, Expr *RHS, |
3590 | bool RequiresADL = true, |
3591 | bool AllowRewrittenCandidates = true, |
3592 | FunctionDecl *DefaultedFn = nullptr); |
3593 | ExprResult BuildSynthesizedThreeWayComparison(SourceLocation OpLoc, |
3594 | const UnresolvedSetImpl &Fns, |
3595 | Expr *LHS, Expr *RHS, |
3596 | FunctionDecl *DefaultedFn); |
3597 | |
3598 | ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, |
3599 | SourceLocation RLoc, |
3600 | Expr *Base,Expr *Idx); |
3601 | |
3602 | ExprResult |
3603 | BuildCallToMemberFunction(Scope *S, Expr *MemExpr, |
3604 | SourceLocation LParenLoc, |
3605 | MultiExprArg Args, |
3606 | SourceLocation RParenLoc); |
3607 | ExprResult |
3608 | BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, |
3609 | MultiExprArg Args, |
3610 | SourceLocation RParenLoc); |
3611 | |
3612 | ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, |
3613 | SourceLocation OpLoc, |
3614 | bool *NoArrowOperatorFound = nullptr); |
3615 | |
3616 | /// CheckCallReturnType - Checks that a call expression's return type is |
3617 | /// complete. Returns true on failure. The location passed in is the location |
3618 | /// that best represents the call. |
3619 | bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, |
3620 | CallExpr *CE, FunctionDecl *FD); |
3621 | |
3622 | /// Helpers for dealing with blocks and functions. |
3623 | bool CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters, |
3624 | bool CheckParameterNames); |
3625 | void CheckCXXDefaultArguments(FunctionDecl *FD); |
3626 | void CheckExtraCXXDefaultArguments(Declarator &D); |
3627 | Scope *getNonFieldDeclScope(Scope *S); |
3628 | |
3629 | /// \name Name lookup |
3630 | /// |
3631 | /// These routines provide name lookup that is used during semantic |
3632 | /// analysis to resolve the various kinds of names (identifiers, |
3633 | /// overloaded operator names, constructor names, etc.) into zero or |
3634 | /// more declarations within a particular scope. The major entry |
3635 | /// points are LookupName, which performs unqualified name lookup, |
3636 | /// and LookupQualifiedName, which performs qualified name lookup. |
3637 | /// |
3638 | /// All name lookup is performed based on some specific criteria, |
3639 | /// which specify what names will be visible to name lookup and how |
3640 | /// far name lookup should work. These criteria are important both |
3641 | /// for capturing language semantics (certain lookups will ignore |
3642 | /// certain names, for example) and for performance, since name |
3643 | /// lookup is often a bottleneck in the compilation of C++. Name |
3644 | /// lookup criteria is specified via the LookupCriteria enumeration. |
3645 | /// |
3646 | /// The results of name lookup can vary based on the kind of name |
3647 | /// lookup performed, the current language, and the translation |
3648 | /// unit. In C, for example, name lookup will either return nothing |
3649 | /// (no entity found) or a single declaration. In C++, name lookup |
3650 | /// can additionally refer to a set of overloaded functions or |
3651 | /// result in an ambiguity. All of the possible results of name |
3652 | /// lookup are captured by the LookupResult class, which provides |
3653 | /// the ability to distinguish among them. |
3654 | //@{ |
3655 | |
3656 | /// Describes the kind of name lookup to perform. |
3657 | enum LookupNameKind { |
3658 | /// Ordinary name lookup, which finds ordinary names (functions, |
3659 | /// variables, typedefs, etc.) in C and most kinds of names |
3660 | /// (functions, variables, members, types, etc.) in C++. |
3661 | LookupOrdinaryName = 0, |
3662 | /// Tag name lookup, which finds the names of enums, classes, |
3663 | /// structs, and unions. |
3664 | LookupTagName, |
3665 | /// Label name lookup. |
3666 | LookupLabel, |
3667 | /// Member name lookup, which finds the names of |
3668 | /// class/struct/union members. |
3669 | LookupMemberName, |
3670 | /// Look up of an operator name (e.g., operator+) for use with |
3671 | /// operator overloading. This lookup is similar to ordinary name |
3672 | /// lookup, but will ignore any declarations that are class members. |
3673 | LookupOperatorName, |
3674 | /// Look up a name following ~ in a destructor name. This is an ordinary |
3675 | /// lookup, but prefers tags to typedefs. |
3676 | LookupDestructorName, |
3677 | /// Look up of a name that precedes the '::' scope resolution |
3678 | /// operator in C++. This lookup completely ignores operator, object, |
3679 | /// function, and enumerator names (C++ [basic.lookup.qual]p1). |
3680 | LookupNestedNameSpecifierName, |
3681 | /// Look up a namespace name within a C++ using directive or |
3682 | /// namespace alias definition, ignoring non-namespace names (C++ |
3683 | /// [basic.lookup.udir]p1). |
3684 | LookupNamespaceName, |
3685 | /// Look up all declarations in a scope with the given name, |
3686 | /// including resolved using declarations. This is appropriate |
3687 | /// for checking redeclarations for a using declaration. |
3688 | LookupUsingDeclName, |
3689 | /// Look up an ordinary name that is going to be redeclared as a |
3690 | /// name with linkage. This lookup ignores any declarations that |
3691 | /// are outside of the current scope unless they have linkage. See |
3692 | /// C99 6.2.2p4-5 and C++ [basic.link]p6. |
3693 | LookupRedeclarationWithLinkage, |
3694 | /// Look up a friend of a local class. This lookup does not look |
3695 | /// outside the innermost non-class scope. See C++11 [class.friend]p11. |
3696 | LookupLocalFriendName, |
3697 | /// Look up the name of an Objective-C protocol. |
3698 | LookupObjCProtocolName, |
3699 | /// Look up implicit 'self' parameter of an objective-c method. |
3700 | LookupObjCImplicitSelfParam, |
3701 | /// Look up the name of an OpenMP user-defined reduction operation. |
3702 | LookupOMPReductionName, |
3703 | /// Look up the name of an OpenMP user-defined mapper. |
3704 | LookupOMPMapperName, |
3705 | /// Look up any declaration with any name. |
3706 | LookupAnyName |
3707 | }; |
3708 | |
3709 | /// Specifies whether (or how) name lookup is being performed for a |
3710 | /// redeclaration (vs. a reference). |
3711 | enum RedeclarationKind { |
3712 | /// The lookup is a reference to this name that is not for the |
3713 | /// purpose of redeclaring the name. |
3714 | NotForRedeclaration = 0, |
3715 | /// The lookup results will be used for redeclaration of a name, |
3716 | /// if an entity by that name already exists and is visible. |
3717 | ForVisibleRedeclaration, |
3718 | /// The lookup results will be used for redeclaration of a name |
3719 | /// with external linkage; non-visible lookup results with external linkage |
3720 | /// may also be found. |
3721 | ForExternalRedeclaration |
3722 | }; |
3723 | |
3724 | RedeclarationKind forRedeclarationInCurContext() { |
3725 | // A declaration with an owning module for linkage can never link against |
3726 | // anything that is not visible. We don't need to check linkage here; if |
3727 | // the context has internal linkage, redeclaration lookup won't find things |
3728 | // from other TUs, and we can't safely compute linkage yet in general. |
3729 | if (cast<Decl>(CurContext) |
3730 | ->getOwningModuleForLinkage(/*IgnoreLinkage*/true)) |
3731 | return ForVisibleRedeclaration; |
3732 | return ForExternalRedeclaration; |
3733 | } |
3734 | |
3735 | /// The possible outcomes of name lookup for a literal operator. |
3736 | enum LiteralOperatorLookupResult { |
3737 | /// The lookup resulted in an error. |
3738 | LOLR_Error, |
3739 | /// The lookup found no match but no diagnostic was issued. |
3740 | LOLR_ErrorNoDiagnostic, |
3741 | /// The lookup found a single 'cooked' literal operator, which |
3742 | /// expects a normal literal to be built and passed to it. |
3743 | LOLR_Cooked, |
3744 | /// The lookup found a single 'raw' literal operator, which expects |
3745 | /// a string literal containing the spelling of the literal token. |
3746 | LOLR_Raw, |
3747 | /// The lookup found an overload set of literal operator templates, |
3748 | /// which expect the characters of the spelling of the literal token to be |
3749 | /// passed as a non-type template argument pack. |
3750 | LOLR_Template, |
3751 | /// The lookup found an overload set of literal operator templates, |
3752 | /// which expect the character type and characters of the spelling of the |
3753 | /// string literal token to be passed as template arguments. |
3754 | LOLR_StringTemplate |
3755 | }; |
3756 | |
3757 | SpecialMemberOverloadResult LookupSpecialMember(CXXRecordDecl *D, |
3758 | CXXSpecialMember SM, |
3759 | bool ConstArg, |
3760 | bool VolatileArg, |
3761 | bool RValueThis, |
3762 | bool ConstThis, |
3763 | bool VolatileThis); |
3764 | |
3765 | typedef std::function<void(const TypoCorrection &)> TypoDiagnosticGenerator; |
3766 | typedef std::function<ExprResult(Sema &, TypoExpr *, TypoCorrection)> |
3767 | TypoRecoveryCallback; |
3768 | |
3769 | private: |
3770 | bool CppLookupName(LookupResult &R, Scope *S); |
3771 | |
3772 | struct TypoExprState { |
3773 | std::unique_ptr<TypoCorrectionConsumer> Consumer; |
3774 | TypoDiagnosticGenerator DiagHandler; |
3775 | TypoRecoveryCallback RecoveryHandler; |
3776 | TypoExprState(); |
3777 | TypoExprState(TypoExprState &&other) noexcept; |
3778 | TypoExprState &operator=(TypoExprState &&other) noexcept; |
3779 | }; |
3780 | |
3781 | /// The set of unhandled TypoExprs and their associated state. |
3782 | llvm::MapVector<TypoExpr *, TypoExprState> DelayedTypos; |
3783 | |
3784 | /// Creates a new TypoExpr AST node. |
3785 | TypoExpr *createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC, |
3786 | TypoDiagnosticGenerator TDG, |
3787 | TypoRecoveryCallback TRC, SourceLocation TypoLoc); |
3788 | |
3789 | // The set of known/encountered (unique, canonicalized) NamespaceDecls. |
3790 | // |
3791 | // The boolean value will be true to indicate that the namespace was loaded |
3792 | // from an AST/PCH file, or false otherwise. |
3793 | llvm::MapVector<NamespaceDecl*, bool> KnownNamespaces; |
3794 | |
3795 | /// Whether we have already loaded known namespaces from an extenal |
3796 | /// source. |
3797 | bool LoadedExternalKnownNamespaces; |
3798 | |
3799 | /// Helper for CorrectTypo and CorrectTypoDelayed used to create and |
3800 | /// populate a new TypoCorrectionConsumer. Returns nullptr if typo correction |
3801 | /// should be skipped entirely. |
3802 | std::unique_ptr<TypoCorrectionConsumer> |
3803 | makeTypoCorrectionConsumer(const DeclarationNameInfo &Typo, |
3804 | Sema::LookupNameKind LookupKind, Scope *S, |
3805 | CXXScopeSpec *SS, |
3806 | CorrectionCandidateCallback &CCC, |
3807 | DeclContext *MemberContext, bool EnteringContext, |
3808 | const ObjCObjectPointerType *OPT, |
3809 | bool ErrorRecovery); |
3810 | |
3811 | public: |
3812 | const TypoExprState &getTypoExprState(TypoExpr *TE) const; |
3813 | |
3814 | /// Clears the state of the given TypoExpr. |
3815 | void clearDelayedTypo(TypoExpr *TE); |
3816 | |
3817 | /// Look up a name, looking for a single declaration. Return |
3818 | /// null if the results were absent, ambiguous, or overloaded. |
3819 | /// |
3820 | /// It is preferable to use the elaborated form and explicitly handle |
3821 | /// ambiguity and overloaded. |
3822 | NamedDecl *LookupSingleName(Scope *S, DeclarationName Name, |
3823 | SourceLocation Loc, |
3824 | LookupNameKind NameKind, |
3825 | RedeclarationKind Redecl |
3826 | = NotForRedeclaration); |
3827 | bool LookupBuiltin(LookupResult &R); |
3828 | void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID); |
3829 | bool LookupName(LookupResult &R, Scope *S, |
3830 | bool AllowBuiltinCreation = false); |
3831 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
3832 | bool InUnqualifiedLookup = false); |
3833 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
3834 | CXXScopeSpec &SS); |
3835 | bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, |
3836 | bool AllowBuiltinCreation = false, |
3837 | bool EnteringContext = false); |
3838 | ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, |
3839 | RedeclarationKind Redecl |
3840 | = NotForRedeclaration); |
3841 | bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class); |
3842 | |
3843 | void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, |
3844 | UnresolvedSetImpl &Functions); |
3845 | |
3846 | LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, |
3847 | SourceLocation GnuLabelLoc = SourceLocation()); |
3848 | |
3849 | DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); |
3850 | CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class); |
3851 | CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class, |
3852 | unsigned Quals); |
3853 | CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, |
3854 | bool RValueThis, unsigned ThisQuals); |
3855 | CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class, |
3856 | unsigned Quals); |
3857 | CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals, |
3858 | bool RValueThis, unsigned ThisQuals); |
3859 | CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); |
3860 | |
3861 | bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id); |
3862 | LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R, |
3863 | ArrayRef<QualType> ArgTys, |
3864 | bool AllowRaw, |
3865 | bool AllowTemplate, |
3866 | bool AllowStringTemplate, |
3867 | bool DiagnoseMissing); |
3868 | bool isKnownName(StringRef name); |
3869 | |
3870 | /// Status of the function emission on the CUDA/HIP/OpenMP host/device attrs. |
3871 | enum class FunctionEmissionStatus { |
3872 | Emitted, |
3873 | CUDADiscarded, // Discarded due to CUDA/HIP hostness |
3874 | OMPDiscarded, // Discarded due to OpenMP hostness |
3875 | TemplateDiscarded, // Discarded due to uninstantiated templates |
3876 | Unknown, |
3877 | }; |
3878 | FunctionEmissionStatus getEmissionStatus(FunctionDecl *Decl, |
3879 | bool Final = false); |
3880 | |
3881 | // Whether the callee should be ignored in CUDA/HIP/OpenMP host/device check. |
3882 | bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee); |
3883 | |
3884 | void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc, |
3885 | ArrayRef<Expr *> Args, ADLResult &Functions); |
3886 | |
3887 | void LookupVisibleDecls(Scope *S, LookupNameKind Kind, |
3888 | VisibleDeclConsumer &Consumer, |
3889 | bool IncludeGlobalScope = true, |
3890 | bool LoadExternal = true); |
3891 | void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, |
3892 | VisibleDeclConsumer &Consumer, |
3893 | bool IncludeGlobalScope = true, |
3894 | bool IncludeDependentBases = false, |
3895 | bool LoadExternal = true); |
3896 | |
3897 | enum CorrectTypoKind { |
3898 | CTK_NonError, // CorrectTypo used in a non error recovery situation. |
3899 | CTK_ErrorRecovery // CorrectTypo used in normal error recovery. |
3900 | }; |
3901 | |
3902 | TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, |
3903 | Sema::LookupNameKind LookupKind, |
3904 | Scope *S, CXXScopeSpec *SS, |
3905 | CorrectionCandidateCallback &CCC, |
3906 | CorrectTypoKind Mode, |
3907 | DeclContext *MemberContext = nullptr, |
3908 | bool EnteringContext = false, |
3909 | const ObjCObjectPointerType *OPT = nullptr, |
3910 | bool RecordFailure = true); |
3911 | |
3912 | TypoExpr *CorrectTypoDelayed(const DeclarationNameInfo &Typo, |
3913 | Sema::LookupNameKind LookupKind, Scope *S, |
3914 | CXXScopeSpec *SS, |
3915 | CorrectionCandidateCallback &CCC, |
3916 | TypoDiagnosticGenerator TDG, |
3917 | TypoRecoveryCallback TRC, CorrectTypoKind Mode, |
3918 | DeclContext *MemberContext = nullptr, |
3919 | bool EnteringContext = false, |
3920 | const ObjCObjectPointerType *OPT = nullptr); |
3921 | |
3922 | /// Process any TypoExprs in the given Expr and its children, |
3923 | /// generating diagnostics as appropriate and returning a new Expr if there |
3924 | /// were typos that were all successfully corrected and ExprError if one or |
3925 | /// more typos could not be corrected. |
3926 | /// |
3927 | /// \param E The Expr to check for TypoExprs. |
3928 | /// |
3929 | /// \param InitDecl A VarDecl to avoid because the Expr being corrected is its |
3930 | /// initializer. |
3931 | /// |
3932 | /// \param RecoverUncorrectedTypos If true, when typo correction fails, it |
3933 | /// will rebuild the given Expr with all TypoExprs degraded to RecoveryExprs. |
3934 | /// |
3935 | /// \param Filter A function applied to a newly rebuilt Expr to determine if |
3936 | /// it is an acceptable/usable result from a single combination of typo |
3937 | /// corrections. As long as the filter returns ExprError, different |
3938 | /// combinations of corrections will be tried until all are exhausted. |
3939 | ExprResult CorrectDelayedTyposInExpr( |
3940 | Expr *E, VarDecl *InitDecl = nullptr, |
3941 | bool RecoverUncorrectedTypos = false, |
3942 | llvm::function_ref<ExprResult(Expr *)> Filter = |
3943 | [](Expr *E) -> ExprResult { return E; }); |
3944 | |
3945 | ExprResult CorrectDelayedTyposInExpr( |
3946 | ExprResult ER, VarDecl *InitDecl = nullptr, |
3947 | bool RecoverUncorrectedTypos = false, |
3948 | llvm::function_ref<ExprResult(Expr *)> Filter = |
3949 | [](Expr *E) -> ExprResult { return E; }) { |
3950 | return ER.isInvalid() |
3951 | ? ER |
3952 | : CorrectDelayedTyposInExpr(ER.get(), InitDecl, |
3953 | RecoverUncorrectedTypos, Filter); |
3954 | } |
3955 | |
3956 | void diagnoseTypo(const TypoCorrection &Correction, |
3957 | const PartialDiagnostic &TypoDiag, |
3958 | bool ErrorRecovery = true); |
3959 | |
3960 | void diagnoseTypo(const TypoCorrection &Correction, |
3961 | const PartialDiagnostic &TypoDiag, |
3962 | const PartialDiagnostic &PrevNote, |
3963 | bool ErrorRecovery = true); |
3964 | |
3965 | void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F); |
3966 | |
3967 | void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc, |
3968 | ArrayRef<Expr *> Args, |
3969 | AssociatedNamespaceSet &AssociatedNamespaces, |
3970 | AssociatedClassSet &AssociatedClasses); |
3971 | |
3972 | void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, |
3973 | bool ConsiderLinkage, bool AllowInlineNamespace); |
3974 | |
3975 | bool CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old); |
3976 | |
3977 | void DiagnoseAmbiguousLookup(LookupResult &Result); |
3978 | //@} |
3979 | |
3980 | /// Attempts to produce a RecoveryExpr after some AST node cannot be created. |
3981 | ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, |
3982 | ArrayRef<Expr *> SubExprs, |
3983 | QualType T = QualType()); |
3984 | |
3985 | ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id, |
3986 | SourceLocation IdLoc, |
3987 | bool TypoCorrection = false); |
3988 | FunctionDecl *CreateBuiltin(IdentifierInfo *II, QualType Type, unsigned ID, |
3989 | SourceLocation Loc); |
3990 | NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, |
3991 | Scope *S, bool ForRedeclaration, |
3992 | SourceLocation Loc); |
3993 | NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
3994 | Scope *S); |
3995 | void AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction( |
3996 | FunctionDecl *FD); |
3997 | void AddKnownFunctionAttributes(FunctionDecl *FD); |
3998 | |
3999 | // More parsing and symbol table subroutines. |
4000 | |
4001 | void ProcessPragmaWeak(Scope *S, Decl *D); |
4002 | // Decl attributes - this routine is the top level dispatcher. |
4003 | void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD); |
4004 | // Helper for delayed processing of attributes. |
4005 | void ProcessDeclAttributeDelayed(Decl *D, |
4006 | const ParsedAttributesView &AttrList); |
4007 | void ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AL, |
4008 | bool IncludeCXX11Attributes = true); |
4009 | bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, |
4010 | const ParsedAttributesView &AttrList); |
4011 | |
4012 | void checkUnusedDeclAttributes(Declarator &D); |
4013 | |
4014 | /// Determine if type T is a valid subject for a nonnull and similar |
4015 | /// attributes. By default, we look through references (the behavior used by |
4016 | /// nonnull), but if the second parameter is true, then we treat a reference |
4017 | /// type as valid. |
4018 | bool isValidPointerAttrType(QualType T, bool RefOkay = false); |
4019 | |
4020 | bool CheckRegparmAttr(const ParsedAttr &attr, unsigned &value); |
4021 | bool CheckCallingConvAttr(const ParsedAttr &attr, CallingConv &CC, |
4022 | const FunctionDecl *FD = nullptr); |
4023 | bool CheckAttrTarget(const ParsedAttr &CurrAttr); |
4024 | bool CheckAttrNoArgs(const ParsedAttr &CurrAttr); |
4025 | bool checkStringLiteralArgumentAttr(const ParsedAttr &Attr, unsigned ArgNum, |
4026 | StringRef &Str, |
4027 | SourceLocation *ArgLocation = nullptr); |
4028 | bool checkSectionName(SourceLocation LiteralLoc, StringRef Str); |
4029 | bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str); |
4030 | bool checkMSInheritanceAttrOnDefinition( |
4031 | CXXRecordDecl *RD, SourceRange Range, bool BestCase, |
4032 | MSInheritanceModel SemanticSpelling); |
4033 | |
4034 | void CheckAlignasUnderalignment(Decl *D); |
4035 | |
4036 | /// Adjust the calling convention of a method to be the ABI default if it |
4037 | /// wasn't specified explicitly. This handles method types formed from |
4038 | /// function type typedefs and typename template arguments. |
4039 | void adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor, |
4040 | SourceLocation Loc); |
4041 | |
4042 | // Check if there is an explicit attribute, but only look through parens. |
4043 | // The intent is to look for an attribute on the current declarator, but not |
4044 | // one that came from a typedef. |
4045 | bool hasExplicitCallingConv(QualType T); |
4046 | |
4047 | /// Get the outermost AttributedType node that sets a calling convention. |
4048 | /// Valid types should not have multiple attributes with different CCs. |
4049 | const AttributedType *getCallingConvAttributedType(QualType T) const; |
4050 | |
4051 | /// Stmt attributes - this routine is the top level dispatcher. |
4052 | StmtResult ProcessStmtAttributes(Stmt *Stmt, |
4053 | const ParsedAttributesView &Attrs, |
4054 | SourceRange Range); |
4055 | |
4056 | void WarnConflictingTypedMethods(ObjCMethodDecl *Method, |
4057 | ObjCMethodDecl *MethodDecl, |
4058 | bool IsProtocolMethodDecl); |
4059 | |
4060 | void CheckConflictingOverridingMethod(ObjCMethodDecl *Method, |
4061 | ObjCMethodDecl *Overridden, |
4062 | bool IsProtocolMethodDecl); |
4063 | |
4064 | /// WarnExactTypedMethods - This routine issues a warning if method |
4065 | /// implementation declaration matches exactly that of its declaration. |
4066 | void WarnExactTypedMethods(ObjCMethodDecl *Method, |
4067 | ObjCMethodDecl *MethodDecl, |
4068 | bool IsProtocolMethodDecl); |
4069 | |
4070 | typedef llvm::SmallPtrSet<Selector, 8> SelectorSet; |
4071 | |
4072 | /// CheckImplementationIvars - This routine checks if the instance variables |
4073 | /// listed in the implelementation match those listed in the interface. |
4074 | void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, |
4075 | ObjCIvarDecl **Fields, unsigned nIvars, |
4076 | SourceLocation Loc); |
4077 | |
4078 | /// ImplMethodsVsClassMethods - This is main routine to warn if any method |
4079 | /// remains unimplemented in the class or category \@implementation. |
4080 | void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, |
4081 | ObjCContainerDecl* IDecl, |
4082 | bool IncompleteImpl = false); |
4083 | |
4084 | /// DiagnoseUnimplementedProperties - This routine warns on those properties |
4085 | /// which must be implemented by this implementation. |
4086 | void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, |
4087 | ObjCContainerDecl *CDecl, |
4088 | bool SynthesizeProperties); |
4089 | |
4090 | /// Diagnose any null-resettable synthesized setters. |
4091 | void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl); |
4092 | |
4093 | /// DefaultSynthesizeProperties - This routine default synthesizes all |
4094 | /// properties which must be synthesized in the class's \@implementation. |
4095 | void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, |
4096 | ObjCInterfaceDecl *IDecl, |
4097 | SourceLocation AtEnd); |
4098 | void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd); |
4099 | |
4100 | /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is |
4101 | /// an ivar synthesized for 'Method' and 'Method' is a property accessor |
4102 | /// declared in class 'IFace'. |
4103 | bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace, |
4104 | ObjCMethodDecl *Method, ObjCIvarDecl *IV); |
4105 | |
4106 | /// DiagnoseUnusedBackingIvarInAccessor - Issue an 'unused' warning if ivar which |
4107 | /// backs the property is not used in the property's accessor. |
4108 | void DiagnoseUnusedBackingIvarInAccessor(Scope *S, |
4109 | const ObjCImplementationDecl *ImplD); |
4110 | |
4111 | /// GetIvarBackingPropertyAccessor - If method is a property setter/getter and |
4112 | /// it property has a backing ivar, returns this ivar; otherwise, returns NULL. |
4113 | /// It also returns ivar's property on success. |
4114 | ObjCIvarDecl *GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method, |
4115 | const ObjCPropertyDecl *&PDecl) const; |
4116 | |
4117 | /// Called by ActOnProperty to handle \@property declarations in |
4118 | /// class extensions. |
4119 | ObjCPropertyDecl *HandlePropertyInClassExtension(Scope *S, |
4120 | SourceLocation AtLoc, |
4121 | SourceLocation LParenLoc, |
4122 | FieldDeclarator &FD, |
4123 | Selector GetterSel, |
4124 | SourceLocation GetterNameLoc, |
4125 | Selector SetterSel, |
4126 | SourceLocation SetterNameLoc, |
4127 | const bool isReadWrite, |
4128 | unsigned &Attributes, |
4129 | const unsigned AttributesAsWritten, |
4130 | QualType T, |
4131 | TypeSourceInfo *TSI, |
4132 | tok::ObjCKeywordKind MethodImplKind); |
4133 | |
4134 | /// Called by ActOnProperty and HandlePropertyInClassExtension to |
4135 | /// handle creating the ObjcPropertyDecl for a category or \@interface. |
4136 | ObjCPropertyDecl *CreatePropertyDecl(Scope *S, |
4137 | ObjCContainerDecl *CDecl, |
4138 | SourceLocation AtLoc, |
4139 | SourceLocation LParenLoc, |
4140 | FieldDeclarator &FD, |
4141 | Selector GetterSel, |
4142 | SourceLocation GetterNameLoc, |
4143 | Selector SetterSel, |
4144 | SourceLocation SetterNameLoc, |
4145 | const bool isReadWrite, |
4146 | const unsigned Attributes, |
4147 | const unsigned AttributesAsWritten, |
4148 | QualType T, |
4149 | TypeSourceInfo *TSI, |
4150 | tok::ObjCKeywordKind MethodImplKind, |
4151 | DeclContext *lexicalDC = nullptr); |
4152 | |
4153 | /// AtomicPropertySetterGetterRules - This routine enforces the rule (via |
4154 | /// warning) when atomic property has one but not the other user-declared |
4155 | /// setter or getter. |
4156 | void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl, |
4157 | ObjCInterfaceDecl* IDecl); |
4158 | |
4159 | void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D); |
4160 | |
4161 | void DiagnoseMissingDesignatedInitOverrides( |
4162 | const ObjCImplementationDecl *ImplD, |
4163 | const ObjCInterfaceDecl *IFD); |
4164 | |
4165 | void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); |
4166 | |
4167 | enum MethodMatchStrategy { |
4168 | MMS_loose, |
4169 | MMS_strict |
4170 | }; |
4171 | |
4172 | /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns |
4173 | /// true, or false, accordingly. |
4174 | bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, |
4175 | const ObjCMethodDecl *PrevMethod, |
4176 | MethodMatchStrategy strategy = MMS_strict); |
4177 | |
4178 | /// MatchAllMethodDeclarations - Check methods declaraed in interface or |
4179 | /// or protocol against those declared in their implementations. |
4180 | void MatchAllMethodDeclarations(const SelectorSet &InsMap, |
4181 | const SelectorSet &ClsMap, |
4182 | SelectorSet &InsMapSeen, |
4183 | SelectorSet &ClsMapSeen, |
4184 | ObjCImplDecl* IMPDecl, |
4185 | ObjCContainerDecl* IDecl, |
4186 | bool &IncompleteImpl, |
4187 | bool ImmediateClass, |
4188 | bool WarnCategoryMethodImpl=false); |
4189 | |
4190 | /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in |
4191 | /// category matches with those implemented in its primary class and |
4192 | /// warns each time an exact match is found. |
4193 | void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP); |
4194 | |
4195 | /// Add the given method to the list of globally-known methods. |
4196 | void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method); |
4197 | |
4198 | /// Returns default addr space for method qualifiers. |
4199 | LangAS getDefaultCXXMethodAddrSpace() const; |
4200 | |
4201 | private: |
4202 | /// AddMethodToGlobalPool - Add an instance or factory method to the global |
4203 | /// pool. See descriptoin of AddInstanceMethodToGlobalPool. |
4204 | void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); |
4205 | |
4206 | /// LookupMethodInGlobalPool - Returns the instance or factory method and |
4207 | /// optionally warns if there are multiple signatures. |
4208 | ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, |
4209 | bool receiverIdOrClass, |
4210 | bool instance); |
4211 | |
4212 | public: |
4213 | /// - Returns instance or factory methods in global method pool for |
4214 | /// given selector. It checks the desired kind first, if none is found, and |
4215 | /// parameter checkTheOther is set, it then checks the other kind. If no such |
4216 | /// method or only one method is found, function returns false; otherwise, it |
4217 | /// returns true. |
4218 | bool |
4219 | CollectMultipleMethodsInGlobalPool(Selector Sel, |
4220 | SmallVectorImpl<ObjCMethodDecl*>& Methods, |
4221 | bool InstanceFirst, bool CheckTheOther, |
4222 | const ObjCObjectType *TypeBound = nullptr); |
4223 | |
4224 | bool |
4225 | AreMultipleMethodsInGlobalPool(Selector Sel, ObjCMethodDecl *BestMethod, |
4226 | SourceRange R, bool receiverIdOrClass, |
4227 | SmallVectorImpl<ObjCMethodDecl*>& Methods); |
4228 | |
4229 | void |
4230 | DiagnoseMultipleMethodInGlobalPool(SmallVectorImpl<ObjCMethodDecl*> &Methods, |
4231 | Selector Sel, SourceRange R, |
4232 | bool receiverIdOrClass); |
4233 | |
4234 | private: |
4235 | /// - Returns a selector which best matches given argument list or |
4236 | /// nullptr if none could be found |
4237 | ObjCMethodDecl *SelectBestMethod(Selector Sel, MultiExprArg Args, |
4238 | bool IsInstance, |
4239 | SmallVectorImpl<ObjCMethodDecl*>& Methods); |
4240 | |
4241 | |
4242 | /// Record the typo correction failure and return an empty correction. |
4243 | TypoCorrection FailedCorrection(IdentifierInfo *Typo, SourceLocation TypoLoc, |
4244 | bool RecordFailure = true) { |
4245 | if (RecordFailure) |
4246 | TypoCorrectionFailures[Typo].insert(TypoLoc); |
4247 | return TypoCorrection(); |
4248 | } |
4249 | |
4250 | public: |
4251 | /// AddInstanceMethodToGlobalPool - All instance methods in a translation |
4252 | /// unit are added to a global pool. This allows us to efficiently associate |
4253 | /// a selector with a method declaraation for purposes of typechecking |
4254 | /// messages sent to "id" (where the class of the object is unknown). |
4255 | void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { |
4256 | AddMethodToGlobalPool(Method, impl, /*instance*/true); |
4257 | } |
4258 | |
4259 | /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. |
4260 | void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { |
4261 | AddMethodToGlobalPool(Method, impl, /*instance*/false); |
4262 | } |
4263 | |
4264 | /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global |
4265 | /// pool. |
4266 | void AddAnyMethodToGlobalPool(Decl *D); |
4267 | |
4268 | /// LookupInstanceMethodInGlobalPool - Returns the method and warns if |
4269 | /// there are multiple signatures. |
4270 | ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, |
4271 | bool receiverIdOrClass=false) { |
4272 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
4273 | /*instance*/true); |
4274 | } |
4275 | |
4276 | /// LookupFactoryMethodInGlobalPool - Returns the method and warns if |
4277 | /// there are multiple signatures. |
4278 | ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, |
4279 | bool receiverIdOrClass=false) { |
4280 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
4281 | /*instance*/false); |
4282 | } |
4283 | |
4284 | const ObjCMethodDecl *SelectorsForTypoCorrection(Selector Sel, |
4285 | QualType ObjectType=QualType()); |
4286 | /// LookupImplementedMethodInGlobalPool - Returns the method which has an |
4287 | /// implementation. |
4288 | ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); |
4289 | |
4290 | /// CollectIvarsToConstructOrDestruct - Collect those ivars which require |
4291 | /// initialization. |
4292 | void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, |
4293 | SmallVectorImpl<ObjCIvarDecl*> &Ivars); |
4294 | |
4295 | //===--------------------------------------------------------------------===// |
4296 | // Statement Parsing Callbacks: SemaStmt.cpp. |
4297 | public: |
4298 | class FullExprArg { |
4299 | public: |
4300 | FullExprArg() : E(nullptr) { } |
4301 | FullExprArg(Sema &actions) : E(nullptr) { } |
4302 | |
4303 | ExprResult release() { |
4304 | return E; |
4305 | } |
4306 | |
4307 | Expr *get() const { return E; } |
4308 | |
4309 | Expr *operator->() { |
4310 | return E; |
4311 | } |
4312 | |
4313 | private: |
4314 | // FIXME: No need to make the entire Sema class a friend when it's just |
4315 | // Sema::MakeFullExpr that needs access to the constructor below. |
4316 | friend class Sema; |
4317 | |
4318 | explicit FullExprArg(Expr *expr) : E(expr) {} |
4319 | |
4320 | Expr *E; |
4321 | }; |
4322 | |
4323 | FullExprArg MakeFullExpr(Expr *Arg) { |
4324 | return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation()); |
4325 | } |
4326 | FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) { |
4327 | return FullExprArg( |
4328 | ActOnFinishFullExpr(Arg, CC, /*DiscardedValue*/ false).get()); |
4329 | } |
4330 | FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) { |
4331 | ExprResult FE = |
4332 | ActOnFinishFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation(), |
4333 | /*DiscardedValue*/ true); |
4334 | return FullExprArg(FE.get()); |
4335 | } |
4336 | |
4337 | StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue = true); |
4338 | StmtResult ActOnExprStmtError(); |
4339 | |
4340 | StmtResult ActOnNullStmt(SourceLocation SemiLoc, |
4341 | bool HasLeadingEmptyMacro = false); |
4342 | |
4343 | void ActOnStartOfCompoundStmt(bool IsStmtExpr); |
4344 | void ActOnFinishOfCompoundStmt(); |
4345 | StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
4346 | ArrayRef<Stmt *> Elts, bool isStmtExpr); |
4347 | |
4348 | /// A RAII object to enter scope of a compound statement. |
4349 | class CompoundScopeRAII { |
4350 | public: |
4351 | CompoundScopeRAII(Sema &S, bool IsStmtExpr = false) : S(S) { |
4352 | S.ActOnStartOfCompoundStmt(IsStmtExpr); |
4353 | } |
4354 | |
4355 | ~CompoundScopeRAII() { |
4356 | S.ActOnFinishOfCompoundStmt(); |
4357 | } |
4358 | |
4359 | private: |
4360 | Sema &S; |
4361 | }; |
4362 | |
4363 | /// An RAII helper that pops function a function scope on exit. |
4364 | struct FunctionScopeRAII { |
4365 | Sema &S; |
4366 | bool Active; |
4367 | FunctionScopeRAII(Sema &S) : S(S), Active(true) {} |
4368 | ~FunctionScopeRAII() { |
4369 | if (Active) |
4370 | S.PopFunctionScopeInfo(); |
4371 | } |
4372 | void disable() { Active = false; } |
4373 | }; |
4374 | |
4375 | StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, |
4376 | SourceLocation StartLoc, |
4377 | SourceLocation EndLoc); |
4378 | void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); |
4379 | StmtResult ActOnForEachLValueExpr(Expr *E); |
4380 | ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val); |
4381 | StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, |
4382 | SourceLocation DotDotDotLoc, ExprResult RHS, |
4383 | SourceLocation ColonLoc); |
4384 | void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); |
4385 | |
4386 | StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, |
4387 | SourceLocation ColonLoc, |
4388 | Stmt *SubStmt, Scope *CurScope); |
4389 | StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, |
4390 | SourceLocation ColonLoc, Stmt *SubStmt); |
4391 | |
4392 | StmtResult ActOnAttributedStmt(SourceLocation AttrLoc, |
4393 | ArrayRef<const Attr*> Attrs, |
4394 | Stmt *SubStmt); |
4395 | |
4396 | class ConditionResult; |
4397 | StmtResult ActOnIfStmt(SourceLocation IfLoc, bool IsConstexpr, |
4398 | SourceLocation LParenLoc, Stmt *InitStmt, |
4399 | ConditionResult Cond, SourceLocation RParenLoc, |
4400 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
4401 | StmtResult BuildIfStmt(SourceLocation IfLoc, bool IsConstexpr, |
4402 | SourceLocation LParenLoc, Stmt *InitStmt, |
4403 | ConditionResult Cond, SourceLocation RParenLoc, |
4404 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
4405 | StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, |
4406 | SourceLocation LParenLoc, Stmt *InitStmt, |
4407 | ConditionResult Cond, |
4408 | SourceLocation RParenLoc); |
4409 | StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, |
4410 | Stmt *Switch, Stmt *Body); |
4411 | StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, |
4412 | ConditionResult Cond, SourceLocation RParenLoc, |
4413 | Stmt *Body); |
4414 | StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, |
4415 | SourceLocation WhileLoc, SourceLocation CondLParen, |
4416 | Expr *Cond, SourceLocation CondRParen); |
4417 | |
4418 | StmtResult ActOnForStmt(SourceLocation ForLoc, |
4419 | SourceLocation LParenLoc, |
4420 | Stmt *First, |
4421 | ConditionResult Second, |
4422 | FullExprArg Third, |
4423 | SourceLocation RParenLoc, |
4424 | Stmt *Body); |
4425 | ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, |
4426 | Expr *collection); |
4427 | StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, |
4428 | Stmt *First, Expr *collection, |
4429 | SourceLocation RParenLoc); |
4430 | StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body); |
4431 | |
4432 | enum BuildForRangeKind { |
4433 | /// Initial building of a for-range statement. |
4434 | BFRK_Build, |
4435 | /// Instantiation or recovery rebuild of a for-range statement. Don't |
4436 | /// attempt any typo-correction. |
4437 | BFRK_Rebuild, |
4438 | /// Determining whether a for-range statement could be built. Avoid any |
4439 | /// unnecessary or irreversible actions. |
4440 | BFRK_Check |
4441 | }; |
4442 | |
4443 | StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc, |
4444 | SourceLocation CoawaitLoc, |
4445 | Stmt *InitStmt, |
4446 | Stmt *LoopVar, |
4447 | SourceLocation ColonLoc, Expr *Collection, |
4448 | SourceLocation RParenLoc, |
4449 | BuildForRangeKind Kind); |
4450 | StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, |
4451 | SourceLocation CoawaitLoc, |
4452 | Stmt *InitStmt, |
4453 | SourceLocation ColonLoc, |
4454 | Stmt *RangeDecl, Stmt *Begin, Stmt *End, |
4455 | Expr *Cond, Expr *Inc, |
4456 | Stmt *LoopVarDecl, |
4457 | SourceLocation RParenLoc, |
4458 | BuildForRangeKind Kind); |
4459 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body); |
4460 | |
4461 | StmtResult ActOnGotoStmt(SourceLocation GotoLoc, |
4462 | SourceLocation LabelLoc, |
4463 | LabelDecl *TheDecl); |
4464 | StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, |
4465 | SourceLocation StarLoc, |
4466 | Expr *DestExp); |
4467 | StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope); |
4468 | StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope); |
4469 | |
4470 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
4471 | CapturedRegionKind Kind, unsigned NumParams); |
4472 | typedef std::pair<StringRef, QualType> CapturedParamNameType; |
4473 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
4474 | CapturedRegionKind Kind, |
4475 | ArrayRef<CapturedParamNameType> Params, |
4476 | unsigned OpenMPCaptureLevel = 0); |
4477 | StmtResult ActOnCapturedRegionEnd(Stmt *S); |
4478 | void ActOnCapturedRegionError(); |
4479 | RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD, |
4480 | SourceLocation Loc, |
4481 | unsigned NumParams); |
4482 | |
4483 | enum CopyElisionSemanticsKind { |
4484 | CES_Strict = 0, |
4485 | CES_AllowParameters = 1, |
4486 | CES_AllowDifferentTypes = 2, |
4487 | CES_AllowExceptionVariables = 4, |
4488 | CES_FormerDefault = (CES_AllowParameters), |
4489 | CES_Default = (CES_AllowParameters | CES_AllowDifferentTypes), |
4490 | CES_AsIfByStdMove = (CES_AllowParameters | CES_AllowDifferentTypes | |
4491 | CES_AllowExceptionVariables), |
4492 | }; |
4493 | |
4494 | VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E, |
4495 | CopyElisionSemanticsKind CESK); |
4496 | bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD, |
4497 | CopyElisionSemanticsKind CESK); |
4498 | |
4499 | StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
4500 | Scope *CurScope); |
4501 | StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); |
4502 | StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); |
4503 | |
4504 | StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
4505 | bool IsVolatile, unsigned NumOutputs, |
4506 | unsigned NumInputs, IdentifierInfo **Names, |
4507 | MultiExprArg Constraints, MultiExprArg Exprs, |
4508 | Expr *AsmString, MultiExprArg Clobbers, |
4509 | unsigned NumLabels, |
4510 | SourceLocation RParenLoc); |
4511 | |
4512 | void FillInlineAsmIdentifierInfo(Expr *Res, |
4513 | llvm::InlineAsmIdentifierInfo &Info); |
4514 | ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS, |
4515 | SourceLocation TemplateKWLoc, |
4516 | UnqualifiedId &Id, |
4517 | bool IsUnevaluatedContext); |
4518 | bool LookupInlineAsmField(StringRef Base, StringRef Member, |
4519 | unsigned &Offset, SourceLocation AsmLoc); |
4520 | ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member, |
4521 | SourceLocation AsmLoc); |
4522 | StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
4523 | ArrayRef<Token> AsmToks, |
4524 | StringRef AsmString, |
4525 | unsigned NumOutputs, unsigned NumInputs, |
4526 | ArrayRef<StringRef> Constraints, |
4527 | ArrayRef<StringRef> Clobbers, |
4528 | ArrayRef<Expr*> Exprs, |
4529 | SourceLocation EndLoc); |
4530 | LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName, |
4531 | SourceLocation Location, |
4532 | bool AlwaysCreate); |
4533 | |
4534 | VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, |
4535 | SourceLocation StartLoc, |
4536 | SourceLocation IdLoc, IdentifierInfo *Id, |
4537 | bool Invalid = false); |
4538 | |
4539 | Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); |
4540 | |
4541 | StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, |
4542 | Decl *Parm, Stmt *Body); |
4543 | |
4544 | StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); |
4545 | |
4546 | StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, |
4547 | MultiStmtArg Catch, Stmt *Finally); |
4548 | |
4549 | StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); |
4550 | StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, |
4551 | Scope *CurScope); |
4552 | ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, |
4553 | Expr *operand); |
4554 | StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, |
4555 | Expr *SynchExpr, |
4556 | Stmt *SynchBody); |
4557 | |
4558 | StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body); |
4559 | |
4560 | VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, |
4561 | SourceLocation StartLoc, |
4562 | SourceLocation IdLoc, |
4563 | IdentifierInfo *Id); |
4564 | |
4565 | Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); |
4566 | |
4567 | StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, |
4568 | Decl *ExDecl, Stmt *HandlerBlock); |
4569 | StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, |
4570 | ArrayRef<Stmt *> Handlers); |
4571 | |
4572 | StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ? |
4573 | SourceLocation TryLoc, Stmt *TryBlock, |
4574 | Stmt *Handler); |
4575 | StmtResult ActOnSEHExceptBlock(SourceLocation Loc, |
4576 | Expr *FilterExpr, |
4577 | Stmt *Block); |
4578 | void ActOnStartSEHFinallyBlock(); |
4579 | void ActOnAbortSEHFinallyBlock(); |
4580 | StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block); |
4581 | StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope); |
4582 | |
4583 | void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); |
4584 | |
4585 | bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; |
4586 | |
4587 | /// If it's a file scoped decl that must warn if not used, keep track |
4588 | /// of it. |
4589 | void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); |
4590 | |
4591 | /// DiagnoseUnusedExprResult - If the statement passed in is an expression |
4592 | /// whose result is unused, warn. |
4593 | void DiagnoseUnusedExprResult(const Stmt *S); |
4594 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D); |
4595 | void DiagnoseUnusedDecl(const NamedDecl *ND); |
4596 | |
4597 | /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null |
4598 | /// statement as a \p Body, and it is located on the same line. |
4599 | /// |
4600 | /// This helps prevent bugs due to typos, such as: |
4601 | /// if (condition); |
4602 | /// do_stuff(); |
4603 | void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, |
4604 | const Stmt *Body, |
4605 | unsigned DiagID); |
4606 | |
4607 | /// Warn if a for/while loop statement \p S, which is followed by |
4608 | /// \p PossibleBody, has a suspicious null statement as a body. |
4609 | void DiagnoseEmptyLoopBody(const Stmt *S, |
4610 | const Stmt *PossibleBody); |
4611 | |
4612 | /// Warn if a value is moved to itself. |
4613 | void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr, |
4614 | SourceLocation OpLoc); |
4615 | |
4616 | /// Warn if we're implicitly casting from a _Nullable pointer type to a |
4617 | /// _Nonnull one. |
4618 | void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType, |
4619 | SourceLocation Loc); |
4620 | |
4621 | /// Warn when implicitly casting 0 to nullptr. |
4622 | void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E); |
4623 | |
4624 | ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) { |
4625 | return DelayedDiagnostics.push(pool); |
4626 | } |
4627 | void PopParsingDeclaration(ParsingDeclState state, Decl *decl); |
4628 | |
4629 | typedef ProcessingContextState ParsingClassState; |
4630 | ParsingClassState PushParsingClass() { |
4631 | ParsingClassDepth++; |
4632 | return DelayedDiagnostics.pushUndelayed(); |
4633 | } |
4634 | void PopParsingClass(ParsingClassState state) { |
4635 | ParsingClassDepth--; |
4636 | DelayedDiagnostics.popUndelayed(state); |
4637 | } |
4638 | |
4639 | void redelayDiagnostics(sema::DelayedDiagnosticPool &pool); |
4640 | |
4641 | void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
4642 | const ObjCInterfaceDecl *UnknownObjCClass, |
4643 | bool ObjCPropertyAccess, |
4644 | bool AvoidPartialAvailabilityChecks = false, |
4645 | ObjCInterfaceDecl *ClassReceiver = nullptr); |
4646 | |
4647 | bool makeUnavailableInSystemHeader(SourceLocation loc, |
4648 | UnavailableAttr::ImplicitReason reason); |
4649 | |
4650 | /// Issue any -Wunguarded-availability warnings in \c FD |
4651 | void DiagnoseUnguardedAvailabilityViolations(Decl *FD); |
4652 | |
4653 | void handleDelayedAvailabilityCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
4654 | |
4655 | //===--------------------------------------------------------------------===// |
4656 | // Expression Parsing Callbacks: SemaExpr.cpp. |
4657 | |
4658 | bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid); |
4659 | bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
4660 | const ObjCInterfaceDecl *UnknownObjCClass = nullptr, |
4661 | bool ObjCPropertyAccess = false, |
4662 | bool AvoidPartialAvailabilityChecks = false, |
4663 | ObjCInterfaceDecl *ClassReciever = nullptr); |
4664 | void NoteDeletedFunction(FunctionDecl *FD); |
4665 | void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD); |
4666 | bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, |
4667 | ObjCMethodDecl *Getter, |
4668 | SourceLocation Loc); |
4669 | void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, |
4670 | ArrayRef<Expr *> Args); |
4671 | |
4672 | void PushExpressionEvaluationContext( |
4673 | ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl = nullptr, |
4674 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
4675 | ExpressionEvaluationContextRecord::EK_Other); |
4676 | enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl }; |
4677 | void PushExpressionEvaluationContext( |
4678 | ExpressionEvaluationContext NewContext, ReuseLambdaContextDecl_t, |
4679 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
4680 | ExpressionEvaluationContextRecord::EK_Other); |
4681 | void PopExpressionEvaluationContext(); |
4682 | |
4683 | void DiscardCleanupsInEvaluationContext(); |
4684 | |
4685 | ExprResult TransformToPotentiallyEvaluated(Expr *E); |
4686 | ExprResult HandleExprEvaluationContextForTypeof(Expr *E); |
4687 | |
4688 | ExprResult CheckUnevaluatedOperand(Expr *E); |
4689 | void CheckUnusedVolatileAssignment(Expr *E); |
4690 | |
4691 | ExprResult ActOnConstantExpression(ExprResult Res); |
4692 | |
4693 | // Functions for marking a declaration referenced. These functions also |
4694 | // contain the relevant logic for marking if a reference to a function or |
4695 | // variable is an odr-use (in the C++11 sense). There are separate variants |
4696 | // for expressions referring to a decl; these exist because odr-use marking |
4697 | // needs to be delayed for some constant variables when we build one of the |
4698 | // named expressions. |
4699 | // |
4700 | // MightBeOdrUse indicates whether the use could possibly be an odr-use, and |
4701 | // should usually be true. This only needs to be set to false if the lack of |
4702 | // odr-use cannot be determined from the current context (for instance, |
4703 | // because the name denotes a virtual function and was written without an |
4704 | // explicit nested-name-specifier). |
4705 | void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse); |
4706 | void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, |
4707 | bool MightBeOdrUse = true); |
4708 | void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var); |
4709 | void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base = nullptr); |
4710 | void MarkMemberReferenced(MemberExpr *E); |
4711 | void MarkFunctionParmPackReferenced(FunctionParmPackExpr *E); |
4712 | void MarkCaptureUsedInEnclosingContext(VarDecl *Capture, SourceLocation Loc, |
4713 | unsigned CapturingScopeIndex); |
4714 | |
4715 | ExprResult CheckLValueToRValueConversionOperand(Expr *E); |
4716 | void CleanupVarDeclMarking(); |
4717 | |
4718 | enum TryCaptureKind { |
4719 | TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef |
4720 | }; |
4721 | |
4722 | /// Try to capture the given variable. |
4723 | /// |
4724 | /// \param Var The variable to capture. |
4725 | /// |
4726 | /// \param Loc The location at which the capture occurs. |
4727 | /// |
4728 | /// \param Kind The kind of capture, which may be implicit (for either a |
4729 | /// block or a lambda), or explicit by-value or by-reference (for a lambda). |
4730 | /// |
4731 | /// \param EllipsisLoc The location of the ellipsis, if one is provided in |
4732 | /// an explicit lambda capture. |
4733 | /// |
4734 | /// \param BuildAndDiagnose Whether we are actually supposed to add the |
4735 | /// captures or diagnose errors. If false, this routine merely check whether |
4736 | /// the capture can occur without performing the capture itself or complaining |
4737 | /// if the variable cannot be captured. |
4738 | /// |
4739 | /// \param CaptureType Will be set to the type of the field used to capture |
4740 | /// this variable in the innermost block or lambda. Only valid when the |
4741 | /// variable can be captured. |
4742 | /// |
4743 | /// \param DeclRefType Will be set to the type of a reference to the capture |
4744 | /// from within the current scope. Only valid when the variable can be |
4745 | /// captured. |
4746 | /// |
4747 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
4748 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
4749 | /// This is useful when enclosing lambdas must speculatively capture |
4750 | /// variables that may or may not be used in certain specializations of |
4751 | /// a nested generic lambda. |
4752 | /// |
4753 | /// \returns true if an error occurred (i.e., the variable cannot be |
4754 | /// captured) and false if the capture succeeded. |
4755 | bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind, |
4756 | SourceLocation EllipsisLoc, bool BuildAndDiagnose, |
4757 | QualType &CaptureType, |
4758 | QualType &DeclRefType, |
4759 | const unsigned *const FunctionScopeIndexToStopAt); |
4760 | |
4761 | /// Try to capture the given variable. |
4762 | bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, |
4763 | TryCaptureKind Kind = TryCapture_Implicit, |
4764 | SourceLocation EllipsisLoc = SourceLocation()); |
4765 | |
4766 | /// Checks if the variable must be captured. |
4767 | bool NeedToCaptureVariable(VarDecl *Var, SourceLocation Loc); |
4768 | |
4769 | /// Given a variable, determine the type that a reference to that |
4770 | /// variable will have in the given scope. |
4771 | QualType getCapturedDeclRefType(VarDecl *Var, SourceLocation Loc); |
4772 | |
4773 | /// Mark all of the declarations referenced within a particular AST node as |
4774 | /// referenced. Used when template instantiation instantiates a non-dependent |
4775 | /// type -- entities referenced by the type are now referenced. |
4776 | void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); |
4777 | void MarkDeclarationsReferencedInExpr(Expr *E, |
4778 | bool SkipLocalVariables = false); |
4779 | |
4780 | /// Try to recover by turning the given expression into a |
4781 | /// call. Returns true if recovery was attempted or an error was |
4782 | /// emitted; this may also leave the ExprResult invalid. |
4783 | bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, |
4784 | bool ForceComplain = false, |
4785 | bool (*IsPlausibleResult)(QualType) = nullptr); |
4786 | |
4787 | /// Figure out if an expression could be turned into a call. |
4788 | bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy, |
4789 | UnresolvedSetImpl &NonTemplateOverloads); |
4790 | |
4791 | /// Try to convert an expression \p E to type \p Ty. Returns the result of the |
4792 | /// conversion. |
4793 | ExprResult tryConvertExprToType(Expr *E, QualType Ty); |
4794 | |
4795 | /// Conditionally issue a diagnostic based on the current |
4796 | /// evaluation context. |
4797 | /// |
4798 | /// \param Statement If Statement is non-null, delay reporting the |
4799 | /// diagnostic until the function body is parsed, and then do a basic |
4800 | /// reachability analysis to determine if the statement is reachable. |
4801 | /// If it is unreachable, the diagnostic will not be emitted. |
4802 | bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, |
4803 | const PartialDiagnostic &PD); |
4804 | /// Similar, but diagnostic is only produced if all the specified statements |
4805 | /// are reachable. |
4806 | bool DiagRuntimeBehavior(SourceLocation Loc, ArrayRef<const Stmt*> Stmts, |
4807 | const PartialDiagnostic &PD); |
4808 | |
4809 | // Primary Expressions. |
4810 | SourceRange getExprRange(Expr *E) const; |
4811 | |
4812 | ExprResult ActOnIdExpression( |
4813 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
4814 | UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand, |
4815 | CorrectionCandidateCallback *CCC = nullptr, |
4816 | bool IsInlineAsmIdentifier = false, Token *KeywordReplacement = nullptr); |
4817 | |
4818 | void DecomposeUnqualifiedId(const UnqualifiedId &Id, |
4819 | TemplateArgumentListInfo &Buffer, |
4820 | DeclarationNameInfo &NameInfo, |
4821 | const TemplateArgumentListInfo *&TemplateArgs); |
4822 | |
4823 | bool |
4824 | DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, |
4825 | CorrectionCandidateCallback &CCC, |
4826 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
4827 | ArrayRef<Expr *> Args = None, TypoExpr **Out = nullptr); |
4828 | |
4829 | DeclResult LookupIvarInObjCMethod(LookupResult &Lookup, Scope *S, |
4830 | IdentifierInfo *II); |
4831 | ExprResult BuildIvarRefExpr(Scope *S, SourceLocation Loc, ObjCIvarDecl *IV); |
4832 | |
4833 | ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S, |
4834 | IdentifierInfo *II, |
4835 | bool AllowBuiltinCreation=false); |
4836 | |
4837 | ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, |
4838 | SourceLocation TemplateKWLoc, |
4839 | const DeclarationNameInfo &NameInfo, |
4840 | bool isAddressOfOperand, |
4841 | const TemplateArgumentListInfo *TemplateArgs); |
4842 | |
4843 | /// If \p D cannot be odr-used in the current expression evaluation context, |
4844 | /// return a reason explaining why. Otherwise, return NOUR_None. |
4845 | NonOdrUseReason getNonOdrUseReasonInCurrentContext(ValueDecl *D); |
4846 | |
4847 | DeclRefExpr *BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
4848 | SourceLocation Loc, |
4849 | const CXXScopeSpec *SS = nullptr); |
4850 | DeclRefExpr * |
4851 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
4852 | const DeclarationNameInfo &NameInfo, |
4853 | const CXXScopeSpec *SS = nullptr, |
4854 | NamedDecl *FoundD = nullptr, |
4855 | SourceLocation TemplateKWLoc = SourceLocation(), |
4856 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
4857 | DeclRefExpr * |
4858 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
4859 | const DeclarationNameInfo &NameInfo, |
4860 | NestedNameSpecifierLoc NNS, |
4861 | NamedDecl *FoundD = nullptr, |
4862 | SourceLocation TemplateKWLoc = SourceLocation(), |
4863 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
4864 | |
4865 | ExprResult |
4866 | BuildAnonymousStructUnionMemberReference( |
4867 | const CXXScopeSpec &SS, |
4868 | SourceLocation nameLoc, |
4869 | IndirectFieldDecl *indirectField, |
4870 | DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_none), |
4871 | Expr *baseObjectExpr = nullptr, |
4872 | SourceLocation opLoc = SourceLocation()); |
4873 | |
4874 | ExprResult BuildPossibleImplicitMemberExpr( |
4875 | const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, |
4876 | const TemplateArgumentListInfo *TemplateArgs, const Scope *S, |
4877 | UnresolvedLookupExpr *AsULE = nullptr); |
4878 | ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, |
4879 | SourceLocation TemplateKWLoc, |
4880 | LookupResult &R, |
4881 | const TemplateArgumentListInfo *TemplateArgs, |
4882 | bool IsDefiniteInstance, |
4883 | const Scope *S); |
4884 | bool UseArgumentDependentLookup(const CXXScopeSpec &SS, |
4885 | const LookupResult &R, |
4886 | bool HasTrailingLParen); |
4887 | |
4888 | ExprResult |
4889 | BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, |
4890 | const DeclarationNameInfo &NameInfo, |
4891 | bool IsAddressOfOperand, const Scope *S, |
4892 | TypeSourceInfo **RecoveryTSI = nullptr); |
4893 | |
4894 | ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS, |
4895 | SourceLocation TemplateKWLoc, |
4896 | const DeclarationNameInfo &NameInfo, |
4897 | const TemplateArgumentListInfo *TemplateArgs); |
4898 | |
4899 | ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, |
4900 | LookupResult &R, |
4901 | bool NeedsADL, |
4902 | bool AcceptInvalidDecl = false); |
4903 | ExprResult BuildDeclarationNameExpr( |
4904 | const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D, |
4905 | NamedDecl *FoundD = nullptr, |
4906 | const TemplateArgumentListInfo *TemplateArgs = nullptr, |
4907 | bool AcceptInvalidDecl = false); |
4908 | |
4909 | ExprResult BuildLiteralOperatorCall(LookupResult &R, |
4910 | DeclarationNameInfo &SuffixInfo, |
4911 | ArrayRef<Expr *> Args, |
4912 | SourceLocation LitEndLoc, |
4913 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
4914 | |
4915 | ExprResult BuildPredefinedExpr(SourceLocation Loc, |
4916 | PredefinedExpr::IdentKind IK); |
4917 | ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); |
4918 | ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val); |
4919 | |
4920 | ExprResult BuildUniqueStableName(SourceLocation Loc, TypeSourceInfo *Operand); |
4921 | ExprResult BuildUniqueStableName(SourceLocation Loc, Expr *E); |
4922 | ExprResult ActOnUniqueStableNameExpr(SourceLocation OpLoc, |
4923 | SourceLocation LParen, |
4924 | SourceLocation RParen, ParsedType Ty); |
4925 | ExprResult ActOnUniqueStableNameExpr(SourceLocation OpLoc, |
4926 | SourceLocation LParen, |
4927 | SourceLocation RParen, Expr *E); |
4928 | |
4929 | bool CheckLoopHintExpr(Expr *E, SourceLocation Loc); |
4930 | |
4931 | ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr); |
4932 | ExprResult ActOnCharacterConstant(const Token &Tok, |
4933 | Scope *UDLScope = nullptr); |
4934 | ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E); |
4935 | ExprResult ActOnParenListExpr(SourceLocation L, |
4936 | SourceLocation R, |
4937 | MultiExprArg Val); |
4938 | |
4939 | /// ActOnStringLiteral - The specified tokens were lexed as pasted string |
4940 | /// fragments (e.g. "foo" "bar" L"baz"). |
4941 | ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks, |
4942 | Scope *UDLScope = nullptr); |
4943 | |
4944 | ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, |
4945 | SourceLocation DefaultLoc, |
4946 | SourceLocation RParenLoc, |
4947 | Expr *ControllingExpr, |
4948 | ArrayRef<ParsedType> ArgTypes, |
4949 | ArrayRef<Expr *> ArgExprs); |
4950 | ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, |
4951 | SourceLocation DefaultLoc, |
4952 | SourceLocation RParenLoc, |
4953 | Expr *ControllingExpr, |
4954 | ArrayRef<TypeSourceInfo *> Types, |
4955 | ArrayRef<Expr *> Exprs); |
4956 | |
4957 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
4958 | ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, |
4959 | Expr *InputExpr); |
4960 | ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, |
4961 | UnaryOperatorKind Opc, Expr *Input); |
4962 | ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, |
4963 | tok::TokenKind Op, Expr *Input); |
4964 | |
4965 | bool isQualifiedMemberAccess(Expr *E); |
4966 | QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc); |
4967 | |
4968 | ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, |
4969 | SourceLocation OpLoc, |
4970 | UnaryExprOrTypeTrait ExprKind, |
4971 | SourceRange R); |
4972 | ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, |
4973 | UnaryExprOrTypeTrait ExprKind); |
4974 | ExprResult |
4975 | ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, |
4976 | UnaryExprOrTypeTrait ExprKind, |
4977 | bool IsType, void *TyOrEx, |
4978 | SourceRange ArgRange); |
4979 | |
4980 | ExprResult CheckPlaceholderExpr(Expr *E); |
4981 | bool CheckVecStepExpr(Expr *E); |
4982 | |
4983 | bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind); |
4984 | bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc, |
4985 | SourceRange ExprRange, |
4986 | UnaryExprOrTypeTrait ExprKind); |
4987 | ExprResult ActOnSizeofParameterPackExpr(Scope *S, |
4988 | SourceLocation OpLoc, |
4989 | IdentifierInfo &Name, |
4990 | SourceLocation NameLoc, |
4991 | SourceLocation RParenLoc); |
4992 | ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, |
4993 | tok::TokenKind Kind, Expr *Input); |
4994 | |
4995 | ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, |
4996 | Expr *Idx, SourceLocation RLoc); |
4997 | ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, |
4998 | Expr *Idx, SourceLocation RLoc); |
4999 | |
5000 | ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, |
5001 | Expr *ColumnIdx, |
5002 | SourceLocation RBLoc); |
5003 | |
5004 | ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, |
5005 | Expr *LowerBound, |
5006 | SourceLocation ColonLocFirst, |
5007 | SourceLocation ColonLocSecond, |
5008 | Expr *Length, Expr *Stride, |
5009 | SourceLocation RBLoc); |
5010 | ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, |
5011 | SourceLocation RParenLoc, |
5012 | ArrayRef<Expr *> Dims, |
5013 | ArrayRef<SourceRange> Brackets); |
5014 | |
5015 | /// Data structure for iterator expression. |
5016 | struct OMPIteratorData { |
5017 | IdentifierInfo *DeclIdent = nullptr; |
5018 | SourceLocation DeclIdentLoc; |
5019 | ParsedType Type; |
5020 | OMPIteratorExpr::IteratorRange Range; |
5021 | SourceLocation AssignLoc; |
5022 | SourceLocation ColonLoc; |
5023 | SourceLocation SecColonLoc; |
5024 | }; |
5025 | |
5026 | ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc, |
5027 | SourceLocation LLoc, SourceLocation RLoc, |
5028 | ArrayRef<OMPIteratorData> Data); |
5029 | |
5030 | // This struct is for use by ActOnMemberAccess to allow |
5031 | // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after |
5032 | // changing the access operator from a '.' to a '->' (to see if that is the |
5033 | // change needed to fix an error about an unknown member, e.g. when the class |
5034 | // defines a custom operator->). |
5035 | struct ActOnMemberAccessExtraArgs { |
5036 | Scope *S; |
5037 | UnqualifiedId &Id; |
5038 | Decl *ObjCImpDecl; |
5039 | }; |
5040 | |
5041 | ExprResult BuildMemberReferenceExpr( |
5042 | Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, |
5043 | CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
5044 | NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, |
5045 | const TemplateArgumentListInfo *TemplateArgs, |
5046 | const Scope *S, |
5047 | ActOnMemberAccessExtraArgs *ExtraArgs = nullptr); |
5048 | |
5049 | ExprResult |
5050 | BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, |
5051 | bool IsArrow, const CXXScopeSpec &SS, |
5052 | SourceLocation TemplateKWLoc, |
5053 | NamedDecl *FirstQualifierInScope, LookupResult &R, |
5054 | const TemplateArgumentListInfo *TemplateArgs, |
5055 | const Scope *S, |
5056 | bool SuppressQualifierCheck = false, |
5057 | ActOnMemberAccessExtraArgs *ExtraArgs = nullptr); |
5058 | |
5059 | ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, |
5060 | SourceLocation OpLoc, |
5061 | const CXXScopeSpec &SS, FieldDecl *Field, |
5062 | DeclAccessPair FoundDecl, |
5063 | const DeclarationNameInfo &MemberNameInfo); |
5064 | |
5065 | ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow); |
5066 | |
5067 | bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, |
5068 | const CXXScopeSpec &SS, |
5069 | const LookupResult &R); |
5070 | |
5071 | ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, |
5072 | bool IsArrow, SourceLocation OpLoc, |
5073 | const CXXScopeSpec &SS, |
5074 | SourceLocation TemplateKWLoc, |
5075 | NamedDecl *FirstQualifierInScope, |
5076 | const DeclarationNameInfo &NameInfo, |
5077 | const TemplateArgumentListInfo *TemplateArgs); |
5078 | |
5079 | ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, |
5080 | SourceLocation OpLoc, |
5081 | tok::TokenKind OpKind, |
5082 | CXXScopeSpec &SS, |
5083 | SourceLocation TemplateKWLoc, |
5084 | UnqualifiedId &Member, |
5085 | Decl *ObjCImpDecl); |
5086 | |
5087 | MemberExpr * |
5088 | BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc, |
5089 | const CXXScopeSpec *SS, SourceLocation TemplateKWLoc, |
5090 | ValueDecl *Member, DeclAccessPair FoundDecl, |
5091 | bool HadMultipleCandidates, |
5092 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, |
5093 | ExprValueKind VK, ExprObjectKind OK, |
5094 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
5095 | MemberExpr * |
5096 | BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc, |
5097 | NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, |
5098 | ValueDecl *Member, DeclAccessPair FoundDecl, |
5099 | bool HadMultipleCandidates, |
5100 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, |
5101 | ExprValueKind VK, ExprObjectKind OK, |
5102 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
5103 | |
5104 | void ActOnDefaultCtorInitializers(Decl *CDtorDecl); |
5105 | bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, |
5106 | FunctionDecl *FDecl, |
5107 | const FunctionProtoType *Proto, |
5108 | ArrayRef<Expr *> Args, |
5109 | SourceLocation RParenLoc, |
5110 | bool ExecConfig = false); |
5111 | void CheckStaticArrayArgument(SourceLocation CallLoc, |
5112 | ParmVarDecl *Param, |
5113 | const Expr *ArgExpr); |
5114 | |
5115 | /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. |
5116 | /// This provides the location of the left/right parens and a list of comma |
5117 | /// locations. |
5118 | ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
5119 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
5120 | Expr *ExecConfig = nullptr); |
5121 | ExprResult BuildCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
5122 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
5123 | Expr *ExecConfig = nullptr, |
5124 | bool IsExecConfig = false); |
5125 | enum class AtomicArgumentOrder { API, AST }; |
5126 | ExprResult |
5127 | BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, |
5128 | SourceLocation RParenLoc, MultiExprArg Args, |
5129 | AtomicExpr::AtomicOp Op, |
5130 | AtomicArgumentOrder ArgOrder = AtomicArgumentOrder::API); |
5131 | ExprResult |
5132 | BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, SourceLocation LParenLoc, |
5133 | ArrayRef<Expr *> Arg, SourceLocation RParenLoc, |
5134 | Expr *Config = nullptr, bool IsExecConfig = false, |
5135 | ADLCallKind UsesADL = ADLCallKind::NotADL); |
5136 | |
5137 | ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, |
5138 | MultiExprArg ExecConfig, |
5139 | SourceLocation GGGLoc); |
5140 | |
5141 | ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, |
5142 | Declarator &D, ParsedType &Ty, |
5143 | SourceLocation RParenLoc, Expr *CastExpr); |
5144 | ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, |
5145 | TypeSourceInfo *Ty, |
5146 | SourceLocation RParenLoc, |
5147 | Expr *Op); |
5148 | CastKind PrepareScalarCast(ExprResult &src, QualType destType); |
5149 | |
5150 | /// Build an altivec or OpenCL literal. |
5151 | ExprResult BuildVectorLiteral(SourceLocation LParenLoc, |
5152 | SourceLocation RParenLoc, Expr *E, |
5153 | TypeSourceInfo *TInfo); |
5154 | |
5155 | ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); |
5156 | |
5157 | ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, |
5158 | ParsedType Ty, |
5159 | SourceLocation RParenLoc, |
5160 | Expr *InitExpr); |
5161 | |
5162 | ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, |
5163 | TypeSourceInfo *TInfo, |
5164 | SourceLocation RParenLoc, |
5165 | Expr *LiteralExpr); |
5166 | |
5167 | ExprResult ActOnInitList(SourceLocation LBraceLoc, |
5168 | MultiExprArg InitArgList, |
5169 | SourceLocation RBraceLoc); |
5170 | |
5171 | ExprResult BuildInitList(SourceLocation LBraceLoc, |
5172 | MultiExprArg InitArgList, |
5173 | SourceLocation RBraceLoc); |
5174 | |
5175 | ExprResult ActOnDesignatedInitializer(Designation &Desig, |
5176 | SourceLocation EqualOrColonLoc, |
5177 | bool GNUSyntax, |
5178 | ExprResult Init); |
5179 | |
5180 | private: |
5181 | static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind); |
5182 | |
5183 | public: |
5184 | ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, |
5185 | tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr); |
5186 | ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, |
5187 | BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr); |
5188 | ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, |
5189 | Expr *LHSExpr, Expr *RHSExpr); |
5190 | void LookupBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, |
5191 | UnresolvedSetImpl &Functions); |
5192 | |
5193 | void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc); |
5194 | |
5195 | /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
5196 | /// in the case of a the GNU conditional expr extension. |
5197 | ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, |
5198 | SourceLocation ColonLoc, |
5199 | Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr); |
5200 | |
5201 | /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". |
5202 | ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, |
5203 | LabelDecl *TheDecl); |
5204 | |
5205 | void ActOnStartStmtExpr(); |
5206 | ExprResult ActOnStmtExpr(Scope *S, SourceLocation LPLoc, Stmt *SubStmt, |
5207 | SourceLocation RPLoc); |
5208 | ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, |
5209 | SourceLocation RPLoc, unsigned TemplateDepth); |
5210 | // Handle the final expression in a statement expression. |
5211 | ExprResult ActOnStmtExprResult(ExprResult E); |
5212 | void ActOnStmtExprError(); |
5213 | |
5214 | // __builtin_offsetof(type, identifier(.identifier|[expr])*) |
5215 | struct OffsetOfComponent { |
5216 | SourceLocation LocStart, LocEnd; |
5217 | bool isBrackets; // true if [expr], false if .ident |
5218 | union { |
5219 | IdentifierInfo *IdentInfo; |
5220 | Expr *E; |
5221 | } U; |
5222 | }; |
5223 | |
5224 | /// __builtin_offsetof(type, a.b[123][456].c) |
5225 | ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, |
5226 | TypeSourceInfo *TInfo, |
5227 | ArrayRef<OffsetOfComponent> Components, |
5228 | SourceLocation RParenLoc); |
5229 | ExprResult ActOnBuiltinOffsetOf(Scope *S, |
5230 | SourceLocation BuiltinLoc, |
5231 | SourceLocation TypeLoc, |
5232 | ParsedType ParsedArgTy, |
5233 | ArrayRef<OffsetOfComponent> Components, |
5234 | SourceLocation RParenLoc); |
5235 | |
5236 | // __builtin_choose_expr(constExpr, expr1, expr2) |
5237 | ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, |
5238 | Expr *CondExpr, Expr *LHSExpr, |
5239 | Expr *RHSExpr, SourceLocation RPLoc); |
5240 | |
5241 | // __builtin_va_arg(expr, type) |
5242 | ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, |
5243 | SourceLocation RPLoc); |
5244 | ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, |
5245 | TypeSourceInfo *TInfo, SourceLocation RPLoc); |
5246 | |
5247 | // __builtin_LINE(), __builtin_FUNCTION(), __builtin_FILE(), |
5248 | // __builtin_COLUMN() |
5249 | ExprResult ActOnSourceLocExpr(SourceLocExpr::IdentKind Kind, |
5250 | SourceLocation BuiltinLoc, |
5251 | SourceLocation RPLoc); |
5252 | |
5253 | // Build a potentially resolved SourceLocExpr. |
5254 | ExprResult BuildSourceLocExpr(SourceLocExpr::IdentKind Kind, |
5255 | SourceLocation BuiltinLoc, SourceLocation RPLoc, |
5256 | DeclContext *ParentContext); |
5257 | |
5258 | // __null |
5259 | ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); |
5260 | |
5261 | bool CheckCaseExpression(Expr *E); |
5262 | |
5263 | /// Describes the result of an "if-exists" condition check. |
5264 | enum IfExistsResult { |
5265 | /// The symbol exists. |
5266 | IER_Exists, |
5267 | |
5268 | /// The symbol does not exist. |
5269 | IER_DoesNotExist, |
5270 | |
5271 | /// The name is a dependent name, so the results will differ |
5272 | /// from one instantiation to the next. |
5273 | IER_Dependent, |
5274 | |
5275 | /// An error occurred. |
5276 | IER_Error |
5277 | }; |
5278 | |
5279 | IfExistsResult |
5280 | CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, |
5281 | const DeclarationNameInfo &TargetNameInfo); |
5282 | |
5283 | IfExistsResult |
5284 | CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc, |
5285 | bool IsIfExists, CXXScopeSpec &SS, |
5286 | UnqualifiedId &Name); |
5287 | |
5288 | StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
5289 | bool IsIfExists, |
5290 | NestedNameSpecifierLoc QualifierLoc, |
5291 | DeclarationNameInfo NameInfo, |
5292 | Stmt *Nested); |
5293 | StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, |
5294 | bool IsIfExists, |
5295 | CXXScopeSpec &SS, UnqualifiedId &Name, |
5296 | Stmt *Nested); |
5297 | |
5298 | //===------------------------- "Block" Extension ------------------------===// |
5299 | |
5300 | /// ActOnBlockStart - This callback is invoked when a block literal is |
5301 | /// started. |
5302 | void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); |
5303 | |
5304 | /// ActOnBlockArguments - This callback allows processing of block arguments. |
5305 | /// If there are no arguments, this is still invoked. |
5306 | void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, |
5307 | Scope *CurScope); |
5308 | |
5309 | /// ActOnBlockError - If there is an error parsing a block, this callback |
5310 | /// is invoked to pop the information about the block from the action impl. |
5311 | void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); |
5312 | |
5313 | /// ActOnBlockStmtExpr - This is called when the body of a block statement |
5314 | /// literal was successfully completed. ^(int x){...} |
5315 | ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, |
5316 | Scope *CurScope); |
5317 | |
5318 | //===---------------------------- Clang Extensions ----------------------===// |
5319 | |
5320 | /// __builtin_convertvector(...) |
5321 | ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy, |
5322 | SourceLocation BuiltinLoc, |
5323 | SourceLocation RParenLoc); |
5324 | |
5325 | //===---------------------------- OpenCL Features -----------------------===// |
5326 | |
5327 | /// __builtin_astype(...) |
5328 | ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, |
5329 | SourceLocation BuiltinLoc, |
5330 | SourceLocation RParenLoc); |
5331 | |
5332 | //===---------------------------- C++ Features --------------------------===// |
5333 | |
5334 | // Act on C++ namespaces |
5335 | Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, |
5336 | SourceLocation NamespaceLoc, |
5337 | SourceLocation IdentLoc, IdentifierInfo *Ident, |
5338 | SourceLocation LBrace, |
5339 | const ParsedAttributesView &AttrList, |
5340 | UsingDirectiveDecl *&UsingDecl); |
5341 | void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); |
5342 | |
5343 | NamespaceDecl *getStdNamespace() const; |
5344 | NamespaceDecl *getOrCreateStdNamespace(); |
5345 | |
5346 | NamespaceDecl *lookupStdExperimentalNamespace(); |
5347 | |
5348 | CXXRecordDecl *getStdBadAlloc() const; |
5349 | EnumDecl *getStdAlignValT() const; |
5350 | |
5351 | private: |
5352 | // A cache representing if we've fully checked the various comparison category |
5353 | // types stored in ASTContext. The bit-index corresponds to the integer value |
5354 | // of a ComparisonCategoryType enumerator. |
5355 | llvm::SmallBitVector FullyCheckedComparisonCategories; |
5356 | |
5357 | ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl, |
5358 | CXXScopeSpec &SS, |
5359 | ParsedType TemplateTypeTy, |
5360 | IdentifierInfo *MemberOrBase); |
5361 | |
5362 | public: |
5363 | enum class ComparisonCategoryUsage { |
5364 | /// The '<=>' operator was used in an expression and a builtin operator |
5365 | /// was selected. |
5366 | OperatorInExpression, |
5367 | /// A defaulted 'operator<=>' needed the comparison category. This |
5368 | /// typically only applies to 'std::strong_ordering', due to the implicit |
5369 | /// fallback return value. |
5370 | DefaultedOperator, |
5371 | }; |
5372 | |
5373 | /// Lookup the specified comparison category types in the standard |
5374 | /// library, an check the VarDecls possibly returned by the operator<=> |
5375 | /// builtins for that type. |
5376 | /// |
5377 | /// \return The type of the comparison category type corresponding to the |
5378 | /// specified Kind, or a null type if an error occurs |
5379 | QualType CheckComparisonCategoryType(ComparisonCategoryType Kind, |
5380 | SourceLocation Loc, |
5381 | ComparisonCategoryUsage Usage); |
5382 | |
5383 | /// Tests whether Ty is an instance of std::initializer_list and, if |
5384 | /// it is and Element is not NULL, assigns the element type to Element. |
5385 | bool isStdInitializerList(QualType Ty, QualType *Element); |
5386 | |
5387 | /// Looks for the std::initializer_list template and instantiates it |
5388 | /// with Element, or emits an error if it's not found. |
5389 | /// |
5390 | /// \returns The instantiated template, or null on error. |
5391 | QualType BuildStdInitializerList(QualType Element, SourceLocation Loc); |
5392 | |
5393 | /// Determine whether Ctor is an initializer-list constructor, as |
5394 | /// defined in [dcl.init.list]p2. |
5395 | bool isInitListConstructor(const FunctionDecl *Ctor); |
5396 | |
5397 | Decl *ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc, |
5398 | SourceLocation NamespcLoc, CXXScopeSpec &SS, |
5399 | SourceLocation IdentLoc, |
5400 | IdentifierInfo *NamespcName, |
5401 | const ParsedAttributesView &AttrList); |
5402 | |
5403 | void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); |
5404 | |
5405 | Decl *ActOnNamespaceAliasDef(Scope *CurScope, |
5406 | SourceLocation NamespaceLoc, |
5407 | SourceLocation AliasLoc, |
5408 | IdentifierInfo *Alias, |
5409 | CXXScopeSpec &SS, |
5410 | SourceLocation IdentLoc, |
5411 | IdentifierInfo *Ident); |
5412 | |
5413 | void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); |
5414 | bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target, |
5415 | const LookupResult &PreviousDecls, |
5416 | UsingShadowDecl *&PrevShadow); |
5417 | UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD, |
5418 | NamedDecl *Target, |
5419 | UsingShadowDecl *PrevDecl); |
5420 | |
5421 | bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, |
5422 | bool HasTypenameKeyword, |
5423 | const CXXScopeSpec &SS, |
5424 | SourceLocation NameLoc, |
5425 | const LookupResult &Previous); |
5426 | bool CheckUsingDeclQualifier(SourceLocation UsingLoc, |
5427 | bool HasTypename, |
5428 | const CXXScopeSpec &SS, |
5429 | const DeclarationNameInfo &NameInfo, |
5430 | SourceLocation NameLoc); |
5431 | |
5432 | NamedDecl *BuildUsingDeclaration( |
5433 | Scope *S, AccessSpecifier AS, SourceLocation UsingLoc, |
5434 | bool HasTypenameKeyword, SourceLocation TypenameLoc, CXXScopeSpec &SS, |
5435 | DeclarationNameInfo NameInfo, SourceLocation EllipsisLoc, |
5436 | const ParsedAttributesView &AttrList, bool IsInstantiation); |
5437 | NamedDecl *BuildUsingPackDecl(NamedDecl *InstantiatedFrom, |
5438 | ArrayRef<NamedDecl *> Expansions); |
5439 | |
5440 | bool CheckInheritingConstructorUsingDecl(UsingDecl *UD); |
5441 | |
5442 | /// Given a derived-class using shadow declaration for a constructor and the |
5443 | /// correspnding base class constructor, find or create the implicit |
5444 | /// synthesized derived class constructor to use for this initialization. |
5445 | CXXConstructorDecl * |
5446 | findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor, |
5447 | ConstructorUsingShadowDecl *DerivedShadow); |
5448 | |
5449 | Decl *ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS, |
5450 | SourceLocation UsingLoc, |
5451 | SourceLocation TypenameLoc, CXXScopeSpec &SS, |
5452 | UnqualifiedId &Name, SourceLocation EllipsisLoc, |
5453 | const ParsedAttributesView &AttrList); |
5454 | Decl *ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS, |
5455 | MultiTemplateParamsArg TemplateParams, |
5456 | SourceLocation UsingLoc, UnqualifiedId &Name, |
5457 | const ParsedAttributesView &AttrList, |
5458 | TypeResult Type, Decl *DeclFromDeclSpec); |
5459 | |
5460 | /// BuildCXXConstructExpr - Creates a complete call to a constructor, |
5461 | /// including handling of its default argument expressions. |
5462 | /// |
5463 | /// \param ConstructKind - a CXXConstructExpr::ConstructionKind |
5464 | ExprResult |
5465 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
5466 | NamedDecl *FoundDecl, |
5467 | CXXConstructorDecl *Constructor, MultiExprArg Exprs, |
5468 | bool HadMultipleCandidates, bool IsListInitialization, |
5469 | bool IsStdInitListInitialization, |
5470 | bool RequiresZeroInit, unsigned ConstructKind, |
5471 | SourceRange ParenRange); |
5472 | |
5473 | /// Build a CXXConstructExpr whose constructor has already been resolved if |
5474 | /// it denotes an inherited constructor. |
5475 | ExprResult |
5476 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
5477 | CXXConstructorDecl *Constructor, bool Elidable, |
5478 | MultiExprArg Exprs, |
5479 | bool HadMultipleCandidates, bool IsListInitialization, |
5480 | bool IsStdInitListInitialization, |
5481 | bool RequiresZeroInit, unsigned ConstructKind, |
5482 | SourceRange ParenRange); |
5483 | |
5484 | // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if |
5485 | // the constructor can be elidable? |
5486 | ExprResult |
5487 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
5488 | NamedDecl *FoundDecl, |
5489 | CXXConstructorDecl *Constructor, bool Elidable, |
5490 | MultiExprArg Exprs, bool HadMultipleCandidates, |
5491 | bool IsListInitialization, |
5492 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
5493 | unsigned ConstructKind, SourceRange ParenRange); |
5494 | |
5495 | ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field); |
5496 | |
5497 | |
5498 | /// Instantiate or parse a C++ default argument expression as necessary. |
5499 | /// Return true on error. |
5500 | bool CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
5501 | ParmVarDecl *Param); |
5502 | |
5503 | /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating |
5504 | /// the default expr if needed. |
5505 | ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, |
5506 | FunctionDecl *FD, |
5507 | ParmVarDecl *Param); |
5508 | |
5509 | /// FinalizeVarWithDestructor - Prepare for calling destructor on the |
5510 | /// constructed variable. |
5511 | void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); |
5512 | |
5513 | /// Helper class that collects exception specifications for |
5514 | /// implicitly-declared special member functions. |
5515 | class ImplicitExceptionSpecification { |
5516 | // Pointer to allow copying |
5517 | Sema *Self; |
5518 | // We order exception specifications thus: |
5519 | // noexcept is the most restrictive, but is only used in C++11. |
5520 | // throw() comes next. |
5521 | // Then a throw(collected exceptions) |
5522 | // Finally no specification, which is expressed as noexcept(false). |
5523 | // throw(...) is used instead if any called function uses it. |
5524 | ExceptionSpecificationType ComputedEST; |
5525 | llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; |
5526 | SmallVector<QualType, 4> Exceptions; |
5527 | |
5528 | void ClearExceptions() { |
5529 | ExceptionsSeen.clear(); |
5530 | Exceptions.clear(); |
5531 | } |
5532 | |
5533 | public: |
5534 | explicit ImplicitExceptionSpecification(Sema &Self) |
5535 | : Self(&Self), ComputedEST(EST_BasicNoexcept) { |
5536 | if (!Self.getLangOpts().CPlusPlus11) |
5537 | ComputedEST = EST_DynamicNone; |
5538 | } |
5539 | |
5540 | /// Get the computed exception specification type. |
5541 | ExceptionSpecificationType getExceptionSpecType() const { |
5542 | assert(!isComputedNoexcept(ComputedEST) &&((!isComputedNoexcept(ComputedEST) && "noexcept(expr) should not be a possible result" ) ? static_cast<void> (0) : __assert_fail ("!isComputedNoexcept(ComputedEST) && \"noexcept(expr) should not be a possible result\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 5543, __PRETTY_FUNCTION__)) |
5543 | "noexcept(expr) should not be a possible result")((!isComputedNoexcept(ComputedEST) && "noexcept(expr) should not be a possible result" ) ? static_cast<void> (0) : __assert_fail ("!isComputedNoexcept(ComputedEST) && \"noexcept(expr) should not be a possible result\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 5543, __PRETTY_FUNCTION__)); |
5544 | return ComputedEST; |
5545 | } |
5546 | |
5547 | /// The number of exceptions in the exception specification. |
5548 | unsigned size() const { return Exceptions.size(); } |
5549 | |
5550 | /// The set of exceptions in the exception specification. |
5551 | const QualType *data() const { return Exceptions.data(); } |
5552 | |
5553 | /// Integrate another called method into the collected data. |
5554 | void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method); |
5555 | |
5556 | /// Integrate an invoked expression into the collected data. |
5557 | void CalledExpr(Expr *E) { CalledStmt(E); } |
5558 | |
5559 | /// Integrate an invoked statement into the collected data. |
5560 | void CalledStmt(Stmt *S); |
5561 | |
5562 | /// Overwrite an EPI's exception specification with this |
5563 | /// computed exception specification. |
5564 | FunctionProtoType::ExceptionSpecInfo getExceptionSpec() const { |
5565 | FunctionProtoType::ExceptionSpecInfo ESI; |
5566 | ESI.Type = getExceptionSpecType(); |
5567 | if (ESI.Type == EST_Dynamic) { |
5568 | ESI.Exceptions = Exceptions; |
5569 | } else if (ESI.Type == EST_None) { |
5570 | /// C++11 [except.spec]p14: |
5571 | /// The exception-specification is noexcept(false) if the set of |
5572 | /// potential exceptions of the special member function contains "any" |
5573 | ESI.Type = EST_NoexceptFalse; |
5574 | ESI.NoexceptExpr = Self->ActOnCXXBoolLiteral(SourceLocation(), |
5575 | tok::kw_false).get(); |
5576 | } |
5577 | return ESI; |
5578 | } |
5579 | }; |
5580 | |
5581 | /// Determine what sort of exception specification a defaulted |
5582 | /// copy constructor of a class will have. |
5583 | ImplicitExceptionSpecification |
5584 | ComputeDefaultedDefaultCtorExceptionSpec(SourceLocation Loc, |
5585 | CXXMethodDecl *MD); |
5586 | |
5587 | /// Determine what sort of exception specification a defaulted |
5588 | /// default constructor of a class will have, and whether the parameter |
5589 | /// will be const. |
5590 | ImplicitExceptionSpecification |
5591 | ComputeDefaultedCopyCtorExceptionSpec(CXXMethodDecl *MD); |
5592 | |
5593 | /// Determine what sort of exception specification a defaulted |
5594 | /// copy assignment operator of a class will have, and whether the |
5595 | /// parameter will be const. |
5596 | ImplicitExceptionSpecification |
5597 | ComputeDefaultedCopyAssignmentExceptionSpec(CXXMethodDecl *MD); |
5598 | |
5599 | /// Determine what sort of exception specification a defaulted move |
5600 | /// constructor of a class will have. |
5601 | ImplicitExceptionSpecification |
5602 | ComputeDefaultedMoveCtorExceptionSpec(CXXMethodDecl *MD); |
5603 | |
5604 | /// Determine what sort of exception specification a defaulted move |
5605 | /// assignment operator of a class will have. |
5606 | ImplicitExceptionSpecification |
5607 | ComputeDefaultedMoveAssignmentExceptionSpec(CXXMethodDecl *MD); |
5608 | |
5609 | /// Determine what sort of exception specification a defaulted |
5610 | /// destructor of a class will have. |
5611 | ImplicitExceptionSpecification |
5612 | ComputeDefaultedDtorExceptionSpec(CXXMethodDecl *MD); |
5613 | |
5614 | /// Determine what sort of exception specification an inheriting |
5615 | /// constructor of a class will have. |
5616 | ImplicitExceptionSpecification |
5617 | ComputeInheritingCtorExceptionSpec(SourceLocation Loc, |
5618 | CXXConstructorDecl *CD); |
5619 | |
5620 | /// Evaluate the implicit exception specification for a defaulted |
5621 | /// special member function. |
5622 | void EvaluateImplicitExceptionSpec(SourceLocation Loc, FunctionDecl *FD); |
5623 | |
5624 | /// Check the given noexcept-specifier, convert its expression, and compute |
5625 | /// the appropriate ExceptionSpecificationType. |
5626 | ExprResult ActOnNoexceptSpec(SourceLocation NoexceptLoc, Expr *NoexceptExpr, |
5627 | ExceptionSpecificationType &EST); |
5628 | |
5629 | /// Check the given exception-specification and update the |
5630 | /// exception specification information with the results. |
5631 | void checkExceptionSpecification(bool IsTopLevel, |
5632 | ExceptionSpecificationType EST, |
5633 | ArrayRef<ParsedType> DynamicExceptions, |
5634 | ArrayRef<SourceRange> DynamicExceptionRanges, |
5635 | Expr *NoexceptExpr, |
5636 | SmallVectorImpl<QualType> &Exceptions, |
5637 | FunctionProtoType::ExceptionSpecInfo &ESI); |
5638 | |
5639 | /// Determine if we're in a case where we need to (incorrectly) eagerly |
5640 | /// parse an exception specification to work around a libstdc++ bug. |
5641 | bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D); |
5642 | |
5643 | /// Add an exception-specification to the given member function |
5644 | /// (or member function template). The exception-specification was parsed |
5645 | /// after the method itself was declared. |
5646 | void actOnDelayedExceptionSpecification(Decl *Method, |
5647 | ExceptionSpecificationType EST, |
5648 | SourceRange SpecificationRange, |
5649 | ArrayRef<ParsedType> DynamicExceptions, |
5650 | ArrayRef<SourceRange> DynamicExceptionRanges, |
5651 | Expr *NoexceptExpr); |
5652 | |
5653 | class InheritedConstructorInfo; |
5654 | |
5655 | /// Determine if a special member function should have a deleted |
5656 | /// definition when it is defaulted. |
5657 | bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM, |
5658 | InheritedConstructorInfo *ICI = nullptr, |
5659 | bool Diagnose = false); |
5660 | |
5661 | /// Produce notes explaining why a defaulted function was defined as deleted. |
5662 | void DiagnoseDeletedDefaultedFunction(FunctionDecl *FD); |
5663 | |
5664 | /// Declare the implicit default constructor for the given class. |
5665 | /// |
5666 | /// \param ClassDecl The class declaration into which the implicit |
5667 | /// default constructor will be added. |
5668 | /// |
5669 | /// \returns The implicitly-declared default constructor. |
5670 | CXXConstructorDecl *DeclareImplicitDefaultConstructor( |
5671 | CXXRecordDecl *ClassDecl); |
5672 | |
5673 | /// DefineImplicitDefaultConstructor - Checks for feasibility of |
5674 | /// defining this constructor as the default constructor. |
5675 | void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, |
5676 | CXXConstructorDecl *Constructor); |
5677 | |
5678 | /// Declare the implicit destructor for the given class. |
5679 | /// |
5680 | /// \param ClassDecl The class declaration into which the implicit |
5681 | /// destructor will be added. |
5682 | /// |
5683 | /// \returns The implicitly-declared destructor. |
5684 | CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); |
5685 | |
5686 | /// DefineImplicitDestructor - Checks for feasibility of |
5687 | /// defining this destructor as the default destructor. |
5688 | void DefineImplicitDestructor(SourceLocation CurrentLocation, |
5689 | CXXDestructorDecl *Destructor); |
5690 | |
5691 | /// Build an exception spec for destructors that don't have one. |
5692 | /// |
5693 | /// C++11 says that user-defined destructors with no exception spec get one |
5694 | /// that looks as if the destructor was implicitly declared. |
5695 | void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor); |
5696 | |
5697 | /// Define the specified inheriting constructor. |
5698 | void DefineInheritingConstructor(SourceLocation UseLoc, |
5699 | CXXConstructorDecl *Constructor); |
5700 | |
5701 | /// Declare the implicit copy constructor for the given class. |
5702 | /// |
5703 | /// \param ClassDecl The class declaration into which the implicit |
5704 | /// copy constructor will be added. |
5705 | /// |
5706 | /// \returns The implicitly-declared copy constructor. |
5707 | CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); |
5708 | |
5709 | /// DefineImplicitCopyConstructor - Checks for feasibility of |
5710 | /// defining this constructor as the copy constructor. |
5711 | void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, |
5712 | CXXConstructorDecl *Constructor); |
5713 | |
5714 | /// Declare the implicit move constructor for the given class. |
5715 | /// |
5716 | /// \param ClassDecl The Class declaration into which the implicit |
5717 | /// move constructor will be added. |
5718 | /// |
5719 | /// \returns The implicitly-declared move constructor, or NULL if it wasn't |
5720 | /// declared. |
5721 | CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl); |
5722 | |
5723 | /// DefineImplicitMoveConstructor - Checks for feasibility of |
5724 | /// defining this constructor as the move constructor. |
5725 | void DefineImplicitMoveConstructor(SourceLocation CurrentLocation, |
5726 | CXXConstructorDecl *Constructor); |
5727 | |
5728 | /// Declare the implicit copy assignment operator for the given class. |
5729 | /// |
5730 | /// \param ClassDecl The class declaration into which the implicit |
5731 | /// copy assignment operator will be added. |
5732 | /// |
5733 | /// \returns The implicitly-declared copy assignment operator. |
5734 | CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); |
5735 | |
5736 | /// Defines an implicitly-declared copy assignment operator. |
5737 | void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, |
5738 | CXXMethodDecl *MethodDecl); |
5739 | |
5740 | /// Declare the implicit move assignment operator for the given class. |
5741 | /// |
5742 | /// \param ClassDecl The Class declaration into which the implicit |
5743 | /// move assignment operator will be added. |
5744 | /// |
5745 | /// \returns The implicitly-declared move assignment operator, or NULL if it |
5746 | /// wasn't declared. |
5747 | CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl); |
5748 | |
5749 | /// Defines an implicitly-declared move assignment operator. |
5750 | void DefineImplicitMoveAssignment(SourceLocation CurrentLocation, |
5751 | CXXMethodDecl *MethodDecl); |
5752 | |
5753 | /// Force the declaration of any implicitly-declared members of this |
5754 | /// class. |
5755 | void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); |
5756 | |
5757 | /// Check a completed declaration of an implicit special member. |
5758 | void CheckImplicitSpecialMemberDeclaration(Scope *S, FunctionDecl *FD); |
5759 | |
5760 | /// Determine whether the given function is an implicitly-deleted |
5761 | /// special member function. |
5762 | bool isImplicitlyDeleted(FunctionDecl *FD); |
5763 | |
5764 | /// Check whether 'this' shows up in the type of a static member |
5765 | /// function after the (naturally empty) cv-qualifier-seq would be. |
5766 | /// |
5767 | /// \returns true if an error occurred. |
5768 | bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method); |
5769 | |
5770 | /// Whether this' shows up in the exception specification of a static |
5771 | /// member function. |
5772 | bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method); |
5773 | |
5774 | /// Check whether 'this' shows up in the attributes of the given |
5775 | /// static member function. |
5776 | /// |
5777 | /// \returns true if an error occurred. |
5778 | bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method); |
5779 | |
5780 | /// MaybeBindToTemporary - If the passed in expression has a record type with |
5781 | /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise |
5782 | /// it simply returns the passed in expression. |
5783 | ExprResult MaybeBindToTemporary(Expr *E); |
5784 | |
5785 | /// Wrap the expression in a ConstantExpr if it is a potential immediate |
5786 | /// invocation. |
5787 | ExprResult CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl); |
5788 | |
5789 | bool CompleteConstructorCall(CXXConstructorDecl *Constructor, |
5790 | MultiExprArg ArgsPtr, |
5791 | SourceLocation Loc, |
5792 | SmallVectorImpl<Expr*> &ConvertedArgs, |
5793 | bool AllowExplicit = false, |
5794 | bool IsListInitialization = false); |
5795 | |
5796 | ParsedType getInheritingConstructorName(CXXScopeSpec &SS, |
5797 | SourceLocation NameLoc, |
5798 | IdentifierInfo &Name); |
5799 | |
5800 | ParsedType getConstructorName(IdentifierInfo &II, SourceLocation NameLoc, |
5801 | Scope *S, CXXScopeSpec &SS, |
5802 | bool EnteringContext); |
5803 | ParsedType getDestructorName(SourceLocation TildeLoc, |
5804 | IdentifierInfo &II, SourceLocation NameLoc, |
5805 | Scope *S, CXXScopeSpec &SS, |
5806 | ParsedType ObjectType, |
5807 | bool EnteringContext); |
5808 | |
5809 | ParsedType getDestructorTypeForDecltype(const DeclSpec &DS, |
5810 | ParsedType ObjectType); |
5811 | |
5812 | // Checks that reinterpret casts don't have undefined behavior. |
5813 | void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, |
5814 | bool IsDereference, SourceRange Range); |
5815 | |
5816 | /// ActOnCXXNamedCast - Parse |
5817 | /// {dynamic,static,reinterpret,const,addrspace}_cast's. |
5818 | ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, |
5819 | tok::TokenKind Kind, |
5820 | SourceLocation LAngleBracketLoc, |
5821 | Declarator &D, |
5822 | SourceLocation RAngleBracketLoc, |
5823 | SourceLocation LParenLoc, |
5824 | Expr *E, |
5825 | SourceLocation RParenLoc); |
5826 | |
5827 | ExprResult BuildCXXNamedCast(SourceLocation OpLoc, |
5828 | tok::TokenKind Kind, |
5829 | TypeSourceInfo *Ty, |
5830 | Expr *E, |
5831 | SourceRange AngleBrackets, |
5832 | SourceRange Parens); |
5833 | |
5834 | ExprResult ActOnBuiltinBitCastExpr(SourceLocation KWLoc, Declarator &Dcl, |
5835 | ExprResult Operand, |
5836 | SourceLocation RParenLoc); |
5837 | |
5838 | ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, |
5839 | Expr *Operand, SourceLocation RParenLoc); |
5840 | |
5841 | ExprResult BuildCXXTypeId(QualType TypeInfoType, |
5842 | SourceLocation TypeidLoc, |
5843 | TypeSourceInfo *Operand, |
5844 | SourceLocation RParenLoc); |
5845 | ExprResult BuildCXXTypeId(QualType TypeInfoType, |
5846 | SourceLocation TypeidLoc, |
5847 | Expr *Operand, |
5848 | SourceLocation RParenLoc); |
5849 | |
5850 | /// ActOnCXXTypeid - Parse typeid( something ). |
5851 | ExprResult ActOnCXXTypeid(SourceLocation OpLoc, |
5852 | SourceLocation LParenLoc, bool isType, |
5853 | void *TyOrExpr, |
5854 | SourceLocation RParenLoc); |
5855 | |
5856 | ExprResult BuildCXXUuidof(QualType TypeInfoType, |
5857 | SourceLocation TypeidLoc, |
5858 | TypeSourceInfo *Operand, |
5859 | SourceLocation RParenLoc); |
5860 | ExprResult BuildCXXUuidof(QualType TypeInfoType, |
5861 | SourceLocation TypeidLoc, |
5862 | Expr *Operand, |
5863 | SourceLocation RParenLoc); |
5864 | |
5865 | /// ActOnCXXUuidof - Parse __uuidof( something ). |
5866 | ExprResult ActOnCXXUuidof(SourceLocation OpLoc, |
5867 | SourceLocation LParenLoc, bool isType, |
5868 | void *TyOrExpr, |
5869 | SourceLocation RParenLoc); |
5870 | |
5871 | /// Handle a C++1z fold-expression: ( expr op ... op expr ). |
5872 | ExprResult ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS, |
5873 | tok::TokenKind Operator, |
5874 | SourceLocation EllipsisLoc, Expr *RHS, |
5875 | SourceLocation RParenLoc); |
5876 | ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, |
5877 | SourceLocation LParenLoc, Expr *LHS, |
5878 | BinaryOperatorKind Operator, |
5879 | SourceLocation EllipsisLoc, Expr *RHS, |
5880 | SourceLocation RParenLoc, |
5881 | Optional<unsigned> NumExpansions); |
5882 | ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
5883 | BinaryOperatorKind Operator); |
5884 | |
5885 | //// ActOnCXXThis - Parse 'this' pointer. |
5886 | ExprResult ActOnCXXThis(SourceLocation loc); |
5887 | |
5888 | /// Build a CXXThisExpr and mark it referenced in the current context. |
5889 | Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit); |
5890 | void MarkThisReferenced(CXXThisExpr *This); |
5891 | |
5892 | /// Try to retrieve the type of the 'this' pointer. |
5893 | /// |
5894 | /// \returns The type of 'this', if possible. Otherwise, returns a NULL type. |
5895 | QualType getCurrentThisType(); |
5896 | |
5897 | /// When non-NULL, the C++ 'this' expression is allowed despite the |
5898 | /// current context not being a non-static member function. In such cases, |
5899 | /// this provides the type used for 'this'. |
5900 | QualType CXXThisTypeOverride; |
5901 | |
5902 | /// RAII object used to temporarily allow the C++ 'this' expression |
5903 | /// to be used, with the given qualifiers on the current class type. |
5904 | class CXXThisScopeRAII { |
5905 | Sema &S; |
5906 | QualType OldCXXThisTypeOverride; |
5907 | bool Enabled; |
5908 | |
5909 | public: |
5910 | /// Introduce a new scope where 'this' may be allowed (when enabled), |
5911 | /// using the given declaration (which is either a class template or a |
5912 | /// class) along with the given qualifiers. |
5913 | /// along with the qualifiers placed on '*this'. |
5914 | CXXThisScopeRAII(Sema &S, Decl *ContextDecl, Qualifiers CXXThisTypeQuals, |
5915 | bool Enabled = true); |
5916 | |
5917 | ~CXXThisScopeRAII(); |
5918 | }; |
5919 | |
5920 | /// Make sure the value of 'this' is actually available in the current |
5921 | /// context, if it is a potentially evaluated context. |
5922 | /// |
5923 | /// \param Loc The location at which the capture of 'this' occurs. |
5924 | /// |
5925 | /// \param Explicit Whether 'this' is explicitly captured in a lambda |
5926 | /// capture list. |
5927 | /// |
5928 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
5929 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
5930 | /// This is useful when enclosing lambdas must speculatively capture |
5931 | /// 'this' that may or may not be used in certain specializations of |
5932 | /// a nested generic lambda (depending on whether the name resolves to |
5933 | /// a non-static member function or a static function). |
5934 | /// \return returns 'true' if failed, 'false' if success. |
5935 | bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false, |
5936 | bool BuildAndDiagnose = true, |
5937 | const unsigned *const FunctionScopeIndexToStopAt = nullptr, |
5938 | bool ByCopy = false); |
5939 | |
5940 | /// Determine whether the given type is the type of *this that is used |
5941 | /// outside of the body of a member function for a type that is currently |
5942 | /// being defined. |
5943 | bool isThisOutsideMemberFunctionBody(QualType BaseType); |
5944 | |
5945 | /// ActOnCXXBoolLiteral - Parse {true,false} literals. |
5946 | ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
5947 | |
5948 | |
5949 | /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals. |
5950 | ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
5951 | |
5952 | ExprResult |
5953 | ActOnObjCAvailabilityCheckExpr(llvm::ArrayRef<AvailabilitySpec> AvailSpecs, |
5954 | SourceLocation AtLoc, SourceLocation RParen); |
5955 | |
5956 | /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. |
5957 | ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); |
5958 | |
5959 | //// ActOnCXXThrow - Parse throw expressions. |
5960 | ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); |
5961 | ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, |
5962 | bool IsThrownVarInScope); |
5963 | bool CheckCXXThrowOperand(SourceLocation ThrowLoc, QualType ThrowTy, Expr *E); |
5964 | |
5965 | /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. |
5966 | /// Can be interpreted either as function-style casting ("int(x)") |
5967 | /// or class type construction ("ClassType(x,y,z)") |
5968 | /// or creation of a value-initialized type ("int()"). |
5969 | ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, |
5970 | SourceLocation LParenOrBraceLoc, |
5971 | MultiExprArg Exprs, |
5972 | SourceLocation RParenOrBraceLoc, |
5973 | bool ListInitialization); |
5974 | |
5975 | ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, |
5976 | SourceLocation LParenLoc, |
5977 | MultiExprArg Exprs, |
5978 | SourceLocation RParenLoc, |
5979 | bool ListInitialization); |
5980 | |
5981 | /// ActOnCXXNew - Parsed a C++ 'new' expression. |
5982 | ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, |
5983 | SourceLocation PlacementLParen, |
5984 | MultiExprArg PlacementArgs, |
5985 | SourceLocation PlacementRParen, |
5986 | SourceRange TypeIdParens, Declarator &D, |
5987 | Expr *Initializer); |
5988 | ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal, |
5989 | SourceLocation PlacementLParen, |
5990 | MultiExprArg PlacementArgs, |
5991 | SourceLocation PlacementRParen, |
5992 | SourceRange TypeIdParens, |
5993 | QualType AllocType, |
5994 | TypeSourceInfo *AllocTypeInfo, |
5995 | Optional<Expr *> ArraySize, |
5996 | SourceRange DirectInitRange, |
5997 | Expr *Initializer); |
5998 | |
5999 | /// Determine whether \p FD is an aligned allocation or deallocation |
6000 | /// function that is unavailable. |
6001 | bool isUnavailableAlignedAllocationFunction(const FunctionDecl &FD) const; |
6002 | |
6003 | /// Produce diagnostics if \p FD is an aligned allocation or deallocation |
6004 | /// function that is unavailable. |
6005 | void diagnoseUnavailableAlignedAllocation(const FunctionDecl &FD, |
6006 | SourceLocation Loc); |
6007 | |
6008 | bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, |
6009 | SourceRange R); |
6010 | |
6011 | /// The scope in which to find allocation functions. |
6012 | enum AllocationFunctionScope { |
6013 | /// Only look for allocation functions in the global scope. |
6014 | AFS_Global, |
6015 | /// Only look for allocation functions in the scope of the |
6016 | /// allocated class. |
6017 | AFS_Class, |
6018 | /// Look for allocation functions in both the global scope |
6019 | /// and in the scope of the allocated class. |
6020 | AFS_Both |
6021 | }; |
6022 | |
6023 | /// Finds the overloads of operator new and delete that are appropriate |
6024 | /// for the allocation. |
6025 | bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, |
6026 | AllocationFunctionScope NewScope, |
6027 | AllocationFunctionScope DeleteScope, |
6028 | QualType AllocType, bool IsArray, |
6029 | bool &PassAlignment, MultiExprArg PlaceArgs, |
6030 | FunctionDecl *&OperatorNew, |
6031 | FunctionDecl *&OperatorDelete, |
6032 | bool Diagnose = true); |
6033 | void DeclareGlobalNewDelete(); |
6034 | void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, |
6035 | ArrayRef<QualType> Params); |
6036 | |
6037 | bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, |
6038 | DeclarationName Name, FunctionDecl* &Operator, |
6039 | bool Diagnose = true); |
6040 | FunctionDecl *FindUsualDeallocationFunction(SourceLocation StartLoc, |
6041 | bool CanProvideSize, |
6042 | bool Overaligned, |
6043 | DeclarationName Name); |
6044 | FunctionDecl *FindDeallocationFunctionForDestructor(SourceLocation StartLoc, |
6045 | CXXRecordDecl *RD); |
6046 | |
6047 | /// ActOnCXXDelete - Parsed a C++ 'delete' expression |
6048 | ExprResult ActOnCXXDelete(SourceLocation StartLoc, |
6049 | bool UseGlobal, bool ArrayForm, |
6050 | Expr *Operand); |
6051 | void CheckVirtualDtorCall(CXXDestructorDecl *dtor, SourceLocation Loc, |
6052 | bool IsDelete, bool CallCanBeVirtual, |
6053 | bool WarnOnNonAbstractTypes, |
6054 | SourceLocation DtorLoc); |
6055 | |
6056 | ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, |
6057 | Expr *Operand, SourceLocation RParen); |
6058 | ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, |
6059 | SourceLocation RParen); |
6060 | |
6061 | /// Parsed one of the type trait support pseudo-functions. |
6062 | ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
6063 | ArrayRef<ParsedType> Args, |
6064 | SourceLocation RParenLoc); |
6065 | ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
6066 | ArrayRef<TypeSourceInfo *> Args, |
6067 | SourceLocation RParenLoc); |
6068 | |
6069 | /// ActOnArrayTypeTrait - Parsed one of the binary type trait support |
6070 | /// pseudo-functions. |
6071 | ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, |
6072 | SourceLocation KWLoc, |
6073 | ParsedType LhsTy, |
6074 | Expr *DimExpr, |
6075 | SourceLocation RParen); |
6076 | |
6077 | ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, |
6078 | SourceLocation KWLoc, |
6079 | TypeSourceInfo *TSInfo, |
6080 | Expr *DimExpr, |
6081 | SourceLocation RParen); |
6082 | |
6083 | /// ActOnExpressionTrait - Parsed one of the unary type trait support |
6084 | /// pseudo-functions. |
6085 | ExprResult ActOnExpressionTrait(ExpressionTrait OET, |
6086 | SourceLocation KWLoc, |
6087 | Expr *Queried, |
6088 | SourceLocation RParen); |
6089 | |
6090 | ExprResult BuildExpressionTrait(ExpressionTrait OET, |
6091 | SourceLocation KWLoc, |
6092 | Expr *Queried, |
6093 | SourceLocation RParen); |
6094 | |
6095 | ExprResult ActOnStartCXXMemberReference(Scope *S, |
6096 | Expr *Base, |
6097 | SourceLocation OpLoc, |
6098 | tok::TokenKind OpKind, |
6099 | ParsedType &ObjectType, |
6100 | bool &MayBePseudoDestructor); |
6101 | |
6102 | ExprResult BuildPseudoDestructorExpr(Expr *Base, |
6103 | SourceLocation OpLoc, |
6104 | tok::TokenKind OpKind, |
6105 | const CXXScopeSpec &SS, |
6106 | TypeSourceInfo *ScopeType, |
6107 | SourceLocation CCLoc, |
6108 | SourceLocation TildeLoc, |
6109 | PseudoDestructorTypeStorage DestroyedType); |
6110 | |
6111 | ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, |
6112 | SourceLocation OpLoc, |
6113 | tok::TokenKind OpKind, |
6114 | CXXScopeSpec &SS, |
6115 | UnqualifiedId &FirstTypeName, |
6116 | SourceLocation CCLoc, |
6117 | SourceLocation TildeLoc, |
6118 | UnqualifiedId &SecondTypeName); |
6119 | |
6120 | ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, |
6121 | SourceLocation OpLoc, |
6122 | tok::TokenKind OpKind, |
6123 | SourceLocation TildeLoc, |
6124 | const DeclSpec& DS); |
6125 | |
6126 | /// MaybeCreateExprWithCleanups - If the current full-expression |
6127 | /// requires any cleanups, surround it with a ExprWithCleanups node. |
6128 | /// Otherwise, just returns the passed-in expression. |
6129 | Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); |
6130 | Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); |
6131 | ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); |
6132 | |
6133 | MaterializeTemporaryExpr * |
6134 | CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, |
6135 | bool BoundToLvalueReference); |
6136 | |
6137 | ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue) { |
6138 | return ActOnFinishFullExpr( |
6139 | Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue); |
6140 | } |
6141 | ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC, |
6142 | bool DiscardedValue, bool IsConstexpr = false); |
6143 | StmtResult ActOnFinishFullStmt(Stmt *Stmt); |
6144 | |
6145 | // Marks SS invalid if it represents an incomplete type. |
6146 | bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); |
6147 | |
6148 | DeclContext *computeDeclContext(QualType T); |
6149 | DeclContext *computeDeclContext(const CXXScopeSpec &SS, |
6150 | bool EnteringContext = false); |
6151 | bool isDependentScopeSpecifier(const CXXScopeSpec &SS); |
6152 | CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); |
6153 | |
6154 | /// The parser has parsed a global nested-name-specifier '::'. |
6155 | /// |
6156 | /// \param CCLoc The location of the '::'. |
6157 | /// |
6158 | /// \param SS The nested-name-specifier, which will be updated in-place |
6159 | /// to reflect the parsed nested-name-specifier. |
6160 | /// |
6161 | /// \returns true if an error occurred, false otherwise. |
6162 | bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS); |
6163 | |
6164 | /// The parser has parsed a '__super' nested-name-specifier. |
6165 | /// |
6166 | /// \param SuperLoc The location of the '__super' keyword. |
6167 | /// |
6168 | /// \param ColonColonLoc The location of the '::'. |
6169 | /// |
6170 | /// \param SS The nested-name-specifier, which will be updated in-place |
6171 | /// to reflect the parsed nested-name-specifier. |
6172 | /// |
6173 | /// \returns true if an error occurred, false otherwise. |
6174 | bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc, |
6175 | SourceLocation ColonColonLoc, CXXScopeSpec &SS); |
6176 | |
6177 | bool isAcceptableNestedNameSpecifier(const NamedDecl *SD, |
6178 | bool *CanCorrect = nullptr); |
6179 | NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); |
6180 | |
6181 | /// Keeps information about an identifier in a nested-name-spec. |
6182 | /// |
6183 | struct NestedNameSpecInfo { |
6184 | /// The type of the object, if we're parsing nested-name-specifier in |
6185 | /// a member access expression. |
6186 | ParsedType ObjectType; |
6187 | |
6188 | /// The identifier preceding the '::'. |
6189 | IdentifierInfo *Identifier; |
6190 | |
6191 | /// The location of the identifier. |
6192 | SourceLocation IdentifierLoc; |
6193 | |
6194 | /// The location of the '::'. |
6195 | SourceLocation CCLoc; |
6196 | |
6197 | /// Creates info object for the most typical case. |
6198 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
6199 | SourceLocation ColonColonLoc, ParsedType ObjectType = ParsedType()) |
6200 | : ObjectType(ObjectType), Identifier(II), IdentifierLoc(IdLoc), |
6201 | CCLoc(ColonColonLoc) { |
6202 | } |
6203 | |
6204 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
6205 | SourceLocation ColonColonLoc, QualType ObjectType) |
6206 | : ObjectType(ParsedType::make(ObjectType)), Identifier(II), |
6207 | IdentifierLoc(IdLoc), CCLoc(ColonColonLoc) { |
6208 | } |
6209 | }; |
6210 | |
6211 | bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, |
6212 | NestedNameSpecInfo &IdInfo); |
6213 | |
6214 | bool BuildCXXNestedNameSpecifier(Scope *S, |
6215 | NestedNameSpecInfo &IdInfo, |
6216 | bool EnteringContext, |
6217 | CXXScopeSpec &SS, |
6218 | NamedDecl *ScopeLookupResult, |
6219 | bool ErrorRecoveryLookup, |
6220 | bool *IsCorrectedToColon = nullptr, |
6221 | bool OnlyNamespace = false); |
6222 | |
6223 | /// The parser has parsed a nested-name-specifier 'identifier::'. |
6224 | /// |
6225 | /// \param S The scope in which this nested-name-specifier occurs. |
6226 | /// |
6227 | /// \param IdInfo Parser information about an identifier in the |
6228 | /// nested-name-spec. |
6229 | /// |
6230 | /// \param EnteringContext Whether we're entering the context nominated by |
6231 | /// this nested-name-specifier. |
6232 | /// |
6233 | /// \param SS The nested-name-specifier, which is both an input |
6234 | /// parameter (the nested-name-specifier before this type) and an |
6235 | /// output parameter (containing the full nested-name-specifier, |
6236 | /// including this new type). |
6237 | /// |
6238 | /// \param ErrorRecoveryLookup If true, then this method is called to improve |
6239 | /// error recovery. In this case do not emit error message. |
6240 | /// |
6241 | /// \param IsCorrectedToColon If not null, suggestions to replace '::' -> ':' |
6242 | /// are allowed. The bool value pointed by this parameter is set to 'true' |
6243 | /// if the identifier is treated as if it was followed by ':', not '::'. |
6244 | /// |
6245 | /// \param OnlyNamespace If true, only considers namespaces in lookup. |
6246 | /// |
6247 | /// \returns true if an error occurred, false otherwise. |
6248 | bool ActOnCXXNestedNameSpecifier(Scope *S, |
6249 | NestedNameSpecInfo &IdInfo, |
6250 | bool EnteringContext, |
6251 | CXXScopeSpec &SS, |
6252 | bool ErrorRecoveryLookup = false, |
6253 | bool *IsCorrectedToColon = nullptr, |
6254 | bool OnlyNamespace = false); |
6255 | |
6256 | ExprResult ActOnDecltypeExpression(Expr *E); |
6257 | |
6258 | bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, |
6259 | const DeclSpec &DS, |
6260 | SourceLocation ColonColonLoc); |
6261 | |
6262 | bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, |
6263 | NestedNameSpecInfo &IdInfo, |
6264 | bool EnteringContext); |
6265 | |
6266 | /// The parser has parsed a nested-name-specifier |
6267 | /// 'template[opt] template-name < template-args >::'. |
6268 | /// |
6269 | /// \param S The scope in which this nested-name-specifier occurs. |
6270 | /// |
6271 | /// \param SS The nested-name-specifier, which is both an input |
6272 | /// parameter (the nested-name-specifier before this type) and an |
6273 | /// output parameter (containing the full nested-name-specifier, |
6274 | /// including this new type). |
6275 | /// |
6276 | /// \param TemplateKWLoc the location of the 'template' keyword, if any. |
6277 | /// \param TemplateName the template name. |
6278 | /// \param TemplateNameLoc The location of the template name. |
6279 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
6280 | /// \param TemplateArgs The template arguments. |
6281 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
6282 | /// \param CCLoc The location of the '::'. |
6283 | /// |
6284 | /// \param EnteringContext Whether we're entering the context of the |
6285 | /// nested-name-specifier. |
6286 | /// |
6287 | /// |
6288 | /// \returns true if an error occurred, false otherwise. |
6289 | bool ActOnCXXNestedNameSpecifier(Scope *S, |
6290 | CXXScopeSpec &SS, |
6291 | SourceLocation TemplateKWLoc, |
6292 | TemplateTy TemplateName, |
6293 | SourceLocation TemplateNameLoc, |
6294 | SourceLocation LAngleLoc, |
6295 | ASTTemplateArgsPtr TemplateArgs, |
6296 | SourceLocation RAngleLoc, |
6297 | SourceLocation CCLoc, |
6298 | bool EnteringContext); |
6299 | |
6300 | /// Given a C++ nested-name-specifier, produce an annotation value |
6301 | /// that the parser can use later to reconstruct the given |
6302 | /// nested-name-specifier. |
6303 | /// |
6304 | /// \param SS A nested-name-specifier. |
6305 | /// |
6306 | /// \returns A pointer containing all of the information in the |
6307 | /// nested-name-specifier \p SS. |
6308 | void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); |
6309 | |
6310 | /// Given an annotation pointer for a nested-name-specifier, restore |
6311 | /// the nested-name-specifier structure. |
6312 | /// |
6313 | /// \param Annotation The annotation pointer, produced by |
6314 | /// \c SaveNestedNameSpecifierAnnotation(). |
6315 | /// |
6316 | /// \param AnnotationRange The source range corresponding to the annotation. |
6317 | /// |
6318 | /// \param SS The nested-name-specifier that will be updated with the contents |
6319 | /// of the annotation pointer. |
6320 | void RestoreNestedNameSpecifierAnnotation(void *Annotation, |
6321 | SourceRange AnnotationRange, |
6322 | CXXScopeSpec &SS); |
6323 | |
6324 | bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
6325 | |
6326 | /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global |
6327 | /// scope or nested-name-specifier) is parsed, part of a declarator-id. |
6328 | /// After this method is called, according to [C++ 3.4.3p3], names should be |
6329 | /// looked up in the declarator-id's scope, until the declarator is parsed and |
6330 | /// ActOnCXXExitDeclaratorScope is called. |
6331 | /// The 'SS' should be a non-empty valid CXXScopeSpec. |
6332 | bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); |
6333 | |
6334 | /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously |
6335 | /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same |
6336 | /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. |
6337 | /// Used to indicate that names should revert to being looked up in the |
6338 | /// defining scope. |
6339 | void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
6340 | |
6341 | /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an |
6342 | /// initializer for the declaration 'Dcl'. |
6343 | /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a |
6344 | /// static data member of class X, names should be looked up in the scope of |
6345 | /// class X. |
6346 | void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); |
6347 | |
6348 | /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an |
6349 | /// initializer for the declaration 'Dcl'. |
6350 | void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); |
6351 | |
6352 | /// Create a new lambda closure type. |
6353 | CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange, |
6354 | TypeSourceInfo *Info, |
6355 | bool KnownDependent, |
6356 | LambdaCaptureDefault CaptureDefault); |
6357 | |
6358 | /// Start the definition of a lambda expression. |
6359 | CXXMethodDecl *startLambdaDefinition(CXXRecordDecl *Class, |
6360 | SourceRange IntroducerRange, |
6361 | TypeSourceInfo *MethodType, |
6362 | SourceLocation EndLoc, |
6363 | ArrayRef<ParmVarDecl *> Params, |
6364 | ConstexprSpecKind ConstexprKind, |
6365 | Expr *TrailingRequiresClause); |
6366 | |
6367 | /// Number lambda for linkage purposes if necessary. |
6368 | void handleLambdaNumbering( |
6369 | CXXRecordDecl *Class, CXXMethodDecl *Method, |
6370 | Optional<std::tuple<unsigned, bool, Decl *>> Mangling = None); |
6371 | |
6372 | /// Endow the lambda scope info with the relevant properties. |
6373 | void buildLambdaScope(sema::LambdaScopeInfo *LSI, |
6374 | CXXMethodDecl *CallOperator, |
6375 | SourceRange IntroducerRange, |
6376 | LambdaCaptureDefault CaptureDefault, |
6377 | SourceLocation CaptureDefaultLoc, |
6378 | bool ExplicitParams, |
6379 | bool ExplicitResultType, |
6380 | bool Mutable); |
6381 | |
6382 | /// Perform initialization analysis of the init-capture and perform |
6383 | /// any implicit conversions such as an lvalue-to-rvalue conversion if |
6384 | /// not being used to initialize a reference. |
6385 | ParsedType actOnLambdaInitCaptureInitialization( |
6386 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
6387 | IdentifierInfo *Id, LambdaCaptureInitKind InitKind, Expr *&Init) { |
6388 | return ParsedType::make(buildLambdaInitCaptureInitialization( |
6389 | Loc, ByRef, EllipsisLoc, None, Id, |
6390 | InitKind != LambdaCaptureInitKind::CopyInit, Init)); |
6391 | } |
6392 | QualType buildLambdaInitCaptureInitialization( |
6393 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
6394 | Optional<unsigned> NumExpansions, IdentifierInfo *Id, bool DirectInit, |
6395 | Expr *&Init); |
6396 | |
6397 | /// Create a dummy variable within the declcontext of the lambda's |
6398 | /// call operator, for name lookup purposes for a lambda init capture. |
6399 | /// |
6400 | /// CodeGen handles emission of lambda captures, ignoring these dummy |
6401 | /// variables appropriately. |
6402 | VarDecl *createLambdaInitCaptureVarDecl(SourceLocation Loc, |
6403 | QualType InitCaptureType, |
6404 | SourceLocation EllipsisLoc, |
6405 | IdentifierInfo *Id, |
6406 | unsigned InitStyle, Expr *Init); |
6407 | |
6408 | /// Add an init-capture to a lambda scope. |
6409 | void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var); |
6410 | |
6411 | /// Note that we have finished the explicit captures for the |
6412 | /// given lambda. |
6413 | void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI); |
6414 | |
6415 | /// \brief This is called after parsing the explicit template parameter list |
6416 | /// on a lambda (if it exists) in C++2a. |
6417 | void ActOnLambdaExplicitTemplateParameterList(SourceLocation LAngleLoc, |
6418 | ArrayRef<NamedDecl *> TParams, |
6419 | SourceLocation RAngleLoc); |
6420 | |
6421 | /// Introduce the lambda parameters into scope. |
6422 | void addLambdaParameters( |
6423 | ArrayRef<LambdaIntroducer::LambdaCapture> Captures, |
6424 | CXXMethodDecl *CallOperator, Scope *CurScope); |
6425 | |
6426 | /// Deduce a block or lambda's return type based on the return |
6427 | /// statements present in the body. |
6428 | void deduceClosureReturnType(sema::CapturingScopeInfo &CSI); |
6429 | |
6430 | /// ActOnStartOfLambdaDefinition - This is called just before we start |
6431 | /// parsing the body of a lambda; it analyzes the explicit captures and |
6432 | /// arguments, and sets up various data-structures for the body of the |
6433 | /// lambda. |
6434 | void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, |
6435 | Declarator &ParamInfo, Scope *CurScope); |
6436 | |
6437 | /// ActOnLambdaError - If there is an error parsing a lambda, this callback |
6438 | /// is invoked to pop the information about the lambda. |
6439 | void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, |
6440 | bool IsInstantiation = false); |
6441 | |
6442 | /// ActOnLambdaExpr - This is called when the body of a lambda expression |
6443 | /// was successfully completed. |
6444 | ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, |
6445 | Scope *CurScope); |
6446 | |
6447 | /// Does copying/destroying the captured variable have side effects? |
6448 | bool CaptureHasSideEffects(const sema::Capture &From); |
6449 | |
6450 | /// Diagnose if an explicit lambda capture is unused. Returns true if a |
6451 | /// diagnostic is emitted. |
6452 | bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange, |
6453 | const sema::Capture &From); |
6454 | |
6455 | /// Build a FieldDecl suitable to hold the given capture. |
6456 | FieldDecl *BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture); |
6457 | |
6458 | /// Initialize the given capture with a suitable expression. |
6459 | ExprResult BuildCaptureInit(const sema::Capture &Capture, |
6460 | SourceLocation ImplicitCaptureLoc, |
6461 | bool IsOpenMPMapping = false); |
6462 | |
6463 | /// Complete a lambda-expression having processed and attached the |
6464 | /// lambda body. |
6465 | ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, |
6466 | sema::LambdaScopeInfo *LSI); |
6467 | |
6468 | /// Get the return type to use for a lambda's conversion function(s) to |
6469 | /// function pointer type, given the type of the call operator. |
6470 | QualType |
6471 | getLambdaConversionFunctionResultType(const FunctionProtoType *CallOpType); |
6472 | |
6473 | /// Define the "body" of the conversion from a lambda object to a |
6474 | /// function pointer. |
6475 | /// |
6476 | /// This routine doesn't actually define a sensible body; rather, it fills |
6477 | /// in the initialization expression needed to copy the lambda object into |
6478 | /// the block, and IR generation actually generates the real body of the |
6479 | /// block pointer conversion. |
6480 | void DefineImplicitLambdaToFunctionPointerConversion( |
6481 | SourceLocation CurrentLoc, CXXConversionDecl *Conv); |
6482 | |
6483 | /// Define the "body" of the conversion from a lambda object to a |
6484 | /// block pointer. |
6485 | /// |
6486 | /// This routine doesn't actually define a sensible body; rather, it fills |
6487 | /// in the initialization expression needed to copy the lambda object into |
6488 | /// the block, and IR generation actually generates the real body of the |
6489 | /// block pointer conversion. |
6490 | void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc, |
6491 | CXXConversionDecl *Conv); |
6492 | |
6493 | ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, |
6494 | SourceLocation ConvLocation, |
6495 | CXXConversionDecl *Conv, |
6496 | Expr *Src); |
6497 | |
6498 | /// Check whether the given expression is a valid constraint expression. |
6499 | /// A diagnostic is emitted if it is not, false is returned, and |
6500 | /// PossibleNonPrimary will be set to true if the failure might be due to a |
6501 | /// non-primary expression being used as an atomic constraint. |
6502 | bool CheckConstraintExpression(const Expr *CE, Token NextToken = Token(), |
6503 | bool *PossibleNonPrimary = nullptr, |
6504 | bool IsTrailingRequiresClause = false); |
6505 | |
6506 | private: |
6507 | /// Caches pairs of template-like decls whose associated constraints were |
6508 | /// checked for subsumption and whether or not the first's constraints did in |
6509 | /// fact subsume the second's. |
6510 | llvm::DenseMap<std::pair<NamedDecl *, NamedDecl *>, bool> SubsumptionCache; |
6511 | /// Caches the normalized associated constraints of declarations (concepts or |
6512 | /// constrained declarations). If an error occurred while normalizing the |
6513 | /// associated constraints of the template or concept, nullptr will be cached |
6514 | /// here. |
6515 | llvm::DenseMap<NamedDecl *, NormalizedConstraint *> |
6516 | NormalizationCache; |
6517 | |
6518 | llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &> |
6519 | SatisfactionCache; |
6520 | |
6521 | public: |
6522 | const NormalizedConstraint * |
6523 | getNormalizedAssociatedConstraints( |
6524 | NamedDecl *ConstrainedDecl, ArrayRef<const Expr *> AssociatedConstraints); |
6525 | |
6526 | /// \brief Check whether the given declaration's associated constraints are |
6527 | /// at least as constrained than another declaration's according to the |
6528 | /// partial ordering of constraints. |
6529 | /// |
6530 | /// \param Result If no error occurred, receives the result of true if D1 is |
6531 | /// at least constrained than D2, and false otherwise. |
6532 | /// |
6533 | /// \returns true if an error occurred, false otherwise. |
6534 | bool IsAtLeastAsConstrained(NamedDecl *D1, ArrayRef<const Expr *> AC1, |
6535 | NamedDecl *D2, ArrayRef<const Expr *> AC2, |
6536 | bool &Result); |
6537 | |
6538 | /// If D1 was not at least as constrained as D2, but would've been if a pair |
6539 | /// of atomic constraints involved had been declared in a concept and not |
6540 | /// repeated in two separate places in code. |
6541 | /// \returns true if such a diagnostic was emitted, false otherwise. |
6542 | bool MaybeEmitAmbiguousAtomicConstraintsDiagnostic(NamedDecl *D1, |
6543 | ArrayRef<const Expr *> AC1, NamedDecl *D2, ArrayRef<const Expr *> AC2); |
6544 | |
6545 | /// \brief Check whether the given list of constraint expressions are |
6546 | /// satisfied (as if in a 'conjunction') given template arguments. |
6547 | /// \param Template the template-like entity that triggered the constraints |
6548 | /// check (either a concept or a constrained entity). |
6549 | /// \param ConstraintExprs a list of constraint expressions, treated as if |
6550 | /// they were 'AND'ed together. |
6551 | /// \param TemplateArgs the list of template arguments to substitute into the |
6552 | /// constraint expression. |
6553 | /// \param TemplateIDRange The source range of the template id that |
6554 | /// caused the constraints check. |
6555 | /// \param Satisfaction if true is returned, will contain details of the |
6556 | /// satisfaction, with enough information to diagnose an unsatisfied |
6557 | /// expression. |
6558 | /// \returns true if an error occurred and satisfaction could not be checked, |
6559 | /// false otherwise. |
6560 | bool CheckConstraintSatisfaction( |
6561 | const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs, |
6562 | ArrayRef<TemplateArgument> TemplateArgs, |
6563 | SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction); |
6564 | |
6565 | /// \brief Check whether the given non-dependent constraint expression is |
6566 | /// satisfied. Returns false and updates Satisfaction with the satisfaction |
6567 | /// verdict if successful, emits a diagnostic and returns true if an error |
6568 | /// occured and satisfaction could not be determined. |
6569 | /// |
6570 | /// \returns true if an error occurred, false otherwise. |
6571 | bool CheckConstraintSatisfaction(const Expr *ConstraintExpr, |
6572 | ConstraintSatisfaction &Satisfaction); |
6573 | |
6574 | /// Check whether the given function decl's trailing requires clause is |
6575 | /// satisfied, if any. Returns false and updates Satisfaction with the |
6576 | /// satisfaction verdict if successful, emits a diagnostic and returns true if |
6577 | /// an error occured and satisfaction could not be determined. |
6578 | /// |
6579 | /// \returns true if an error occurred, false otherwise. |
6580 | bool CheckFunctionConstraints(const FunctionDecl *FD, |
6581 | ConstraintSatisfaction &Satisfaction, |
6582 | SourceLocation UsageLoc = SourceLocation()); |
6583 | |
6584 | |
6585 | /// \brief Ensure that the given template arguments satisfy the constraints |
6586 | /// associated with the given template, emitting a diagnostic if they do not. |
6587 | /// |
6588 | /// \param Template The template to which the template arguments are being |
6589 | /// provided. |
6590 | /// |
6591 | /// \param TemplateArgs The converted, canonicalized template arguments. |
6592 | /// |
6593 | /// \param TemplateIDRange The source range of the template id that |
6594 | /// caused the constraints check. |
6595 | /// |
6596 | /// \returns true if the constrains are not satisfied or could not be checked |
6597 | /// for satisfaction, false if the constraints are satisfied. |
6598 | bool EnsureTemplateArgumentListConstraints(TemplateDecl *Template, |
6599 | ArrayRef<TemplateArgument> TemplateArgs, |
6600 | SourceRange TemplateIDRange); |
6601 | |
6602 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
6603 | /// unsatisfied. |
6604 | /// \param First whether this is the first time an unsatisfied constraint is |
6605 | /// diagnosed for this error. |
6606 | void |
6607 | DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction &Satisfaction, |
6608 | bool First = true); |
6609 | |
6610 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
6611 | /// unsatisfied. |
6612 | void |
6613 | DiagnoseUnsatisfiedConstraint(const ASTConstraintSatisfaction &Satisfaction, |
6614 | bool First = true); |
6615 | |
6616 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
6617 | /// unsatisfied because it was ill-formed. |
6618 | void DiagnoseUnsatisfiedIllFormedConstraint(SourceLocation DiagnosticLocation, |
6619 | StringRef Diagnostic); |
6620 | |
6621 | void DiagnoseRedeclarationConstraintMismatch(SourceLocation Old, |
6622 | SourceLocation New); |
6623 | |
6624 | // ParseObjCStringLiteral - Parse Objective-C string literals. |
6625 | ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, |
6626 | ArrayRef<Expr *> Strings); |
6627 | |
6628 | ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S); |
6629 | |
6630 | /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the |
6631 | /// numeric literal expression. Type of the expression will be "NSNumber *" |
6632 | /// or "id" if NSNumber is unavailable. |
6633 | ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number); |
6634 | ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc, |
6635 | bool Value); |
6636 | ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements); |
6637 | |
6638 | /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the |
6639 | /// '@' prefixed parenthesized expression. The type of the expression will |
6640 | /// either be "NSNumber *", "NSString *" or "NSValue *" depending on the type |
6641 | /// of ValueType, which is allowed to be a built-in numeric type, "char *", |
6642 | /// "const char *" or C structure with attribute 'objc_boxable'. |
6643 | ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr); |
6644 | |
6645 | ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, |
6646 | Expr *IndexExpr, |
6647 | ObjCMethodDecl *getterMethod, |
6648 | ObjCMethodDecl *setterMethod); |
6649 | |
6650 | ExprResult BuildObjCDictionaryLiteral(SourceRange SR, |
6651 | MutableArrayRef<ObjCDictionaryElement> Elements); |
6652 | |
6653 | ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, |
6654 | TypeSourceInfo *EncodedTypeInfo, |
6655 | SourceLocation RParenLoc); |
6656 | ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, |
6657 | CXXConversionDecl *Method, |
6658 | bool HadMultipleCandidates); |
6659 | |
6660 | ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, |
6661 | SourceLocation EncodeLoc, |
6662 | SourceLocation LParenLoc, |
6663 | ParsedType Ty, |
6664 | SourceLocation RParenLoc); |
6665 | |
6666 | /// ParseObjCSelectorExpression - Build selector expression for \@selector |
6667 | ExprResult ParseObjCSelectorExpression(Selector Sel, |
6668 | SourceLocation AtLoc, |
6669 | SourceLocation SelLoc, |
6670 | SourceLocation LParenLoc, |
6671 | SourceLocation RParenLoc, |
6672 | bool WarnMultipleSelectors); |
6673 | |
6674 | /// ParseObjCProtocolExpression - Build protocol expression for \@protocol |
6675 | ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, |
6676 | SourceLocation AtLoc, |
6677 | SourceLocation ProtoLoc, |
6678 | SourceLocation LParenLoc, |
6679 | SourceLocation ProtoIdLoc, |
6680 | SourceLocation RParenLoc); |
6681 | |
6682 | //===--------------------------------------------------------------------===// |
6683 | // C++ Declarations |
6684 | // |
6685 | Decl *ActOnStartLinkageSpecification(Scope *S, |
6686 | SourceLocation ExternLoc, |
6687 | Expr *LangStr, |
6688 | SourceLocation LBraceLoc); |
6689 | Decl *ActOnFinishLinkageSpecification(Scope *S, |
6690 | Decl *LinkageSpec, |
6691 | SourceLocation RBraceLoc); |
6692 | |
6693 | |
6694 | //===--------------------------------------------------------------------===// |
6695 | // C++ Classes |
6696 | // |
6697 | CXXRecordDecl *getCurrentClass(Scope *S, const CXXScopeSpec *SS); |
6698 | bool isCurrentClassName(const IdentifierInfo &II, Scope *S, |
6699 | const CXXScopeSpec *SS = nullptr); |
6700 | bool isCurrentClassNameTypo(IdentifierInfo *&II, const CXXScopeSpec *SS); |
6701 | |
6702 | bool ActOnAccessSpecifier(AccessSpecifier Access, SourceLocation ASLoc, |
6703 | SourceLocation ColonLoc, |
6704 | const ParsedAttributesView &Attrs); |
6705 | |
6706 | NamedDecl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, |
6707 | Declarator &D, |
6708 | MultiTemplateParamsArg TemplateParameterLists, |
6709 | Expr *BitfieldWidth, const VirtSpecifiers &VS, |
6710 | InClassInitStyle InitStyle); |
6711 | |
6712 | void ActOnStartCXXInClassMemberInitializer(); |
6713 | void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl, |
6714 | SourceLocation EqualLoc, |
6715 | Expr *Init); |
6716 | |
6717 | MemInitResult ActOnMemInitializer(Decl *ConstructorD, |
6718 | Scope *S, |
6719 | CXXScopeSpec &SS, |
6720 | IdentifierInfo *MemberOrBase, |
6721 | ParsedType TemplateTypeTy, |
6722 | const DeclSpec &DS, |
6723 | SourceLocation IdLoc, |
6724 | SourceLocation LParenLoc, |
6725 | ArrayRef<Expr *> Args, |
6726 | SourceLocation RParenLoc, |
6727 | SourceLocation EllipsisLoc); |
6728 | |
6729 | MemInitResult ActOnMemInitializer(Decl *ConstructorD, |
6730 | Scope *S, |
6731 | CXXScopeSpec &SS, |
6732 | IdentifierInfo *MemberOrBase, |
6733 | ParsedType TemplateTypeTy, |
6734 | const DeclSpec &DS, |
6735 | SourceLocation IdLoc, |
6736 | Expr *InitList, |
6737 | SourceLocation EllipsisLoc); |
6738 | |
6739 | MemInitResult BuildMemInitializer(Decl *ConstructorD, |
6740 | Scope *S, |
6741 | CXXScopeSpec &SS, |
6742 | IdentifierInfo *MemberOrBase, |
6743 | ParsedType TemplateTypeTy, |
6744 | const DeclSpec &DS, |
6745 | SourceLocation IdLoc, |
6746 | Expr *Init, |
6747 | SourceLocation EllipsisLoc); |
6748 | |
6749 | MemInitResult BuildMemberInitializer(ValueDecl *Member, |
6750 | Expr *Init, |
6751 | SourceLocation IdLoc); |
6752 | |
6753 | MemInitResult BuildBaseInitializer(QualType BaseType, |
6754 | TypeSourceInfo *BaseTInfo, |
6755 | Expr *Init, |
6756 | CXXRecordDecl *ClassDecl, |
6757 | SourceLocation EllipsisLoc); |
6758 | |
6759 | MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, |
6760 | Expr *Init, |
6761 | CXXRecordDecl *ClassDecl); |
6762 | |
6763 | bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, |
6764 | CXXCtorInitializer *Initializer); |
6765 | |
6766 | bool SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors, |
6767 | ArrayRef<CXXCtorInitializer *> Initializers = None); |
6768 | |
6769 | void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); |
6770 | |
6771 | |
6772 | /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, |
6773 | /// mark all the non-trivial destructors of its members and bases as |
6774 | /// referenced. |
6775 | void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, |
6776 | CXXRecordDecl *Record); |
6777 | |
6778 | /// Mark destructors of virtual bases of this class referenced. In the Itanium |
6779 | /// C++ ABI, this is done when emitting a destructor for any non-abstract |
6780 | /// class. In the Microsoft C++ ABI, this is done any time a class's |
6781 | /// destructor is referenced. |
6782 | void MarkVirtualBaseDestructorsReferenced( |
6783 | SourceLocation Location, CXXRecordDecl *ClassDecl, |
6784 | llvm::SmallPtrSetImpl<const RecordType *> *DirectVirtualBases = nullptr); |
6785 | |
6786 | /// Do semantic checks to allow the complete destructor variant to be emitted |
6787 | /// when the destructor is defined in another translation unit. In the Itanium |
6788 | /// C++ ABI, destructor variants are emitted together. In the MS C++ ABI, they |
6789 | /// can be emitted in separate TUs. To emit the complete variant, run a subset |
6790 | /// of the checks performed when emitting a regular destructor. |
6791 | void CheckCompleteDestructorVariant(SourceLocation CurrentLocation, |
6792 | CXXDestructorDecl *Dtor); |
6793 | |
6794 | /// The list of classes whose vtables have been used within |
6795 | /// this translation unit, and the source locations at which the |
6796 | /// first use occurred. |
6797 | typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse; |
6798 | |
6799 | /// The list of vtables that are required but have not yet been |
6800 | /// materialized. |
6801 | SmallVector<VTableUse, 16> VTableUses; |
6802 | |
6803 | /// The set of classes whose vtables have been used within |
6804 | /// this translation unit, and a bit that will be true if the vtable is |
6805 | /// required to be emitted (otherwise, it should be emitted only if needed |
6806 | /// by code generation). |
6807 | llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; |
6808 | |
6809 | /// Load any externally-stored vtable uses. |
6810 | void LoadExternalVTableUses(); |
6811 | |
6812 | /// Note that the vtable for the given class was used at the |
6813 | /// given location. |
6814 | void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, |
6815 | bool DefinitionRequired = false); |
6816 | |
6817 | /// Mark the exception specifications of all virtual member functions |
6818 | /// in the given class as needed. |
6819 | void MarkVirtualMemberExceptionSpecsNeeded(SourceLocation Loc, |
6820 | const CXXRecordDecl *RD); |
6821 | |
6822 | /// MarkVirtualMembersReferenced - Will mark all members of the given |
6823 | /// CXXRecordDecl referenced. |
6824 | void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD, |
6825 | bool ConstexprOnly = false); |
6826 | |
6827 | /// Define all of the vtables that have been used in this |
6828 | /// translation unit and reference any virtual members used by those |
6829 | /// vtables. |
6830 | /// |
6831 | /// \returns true if any work was done, false otherwise. |
6832 | bool DefineUsedVTables(); |
6833 | |
6834 | void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); |
6835 | |
6836 | void ActOnMemInitializers(Decl *ConstructorDecl, |
6837 | SourceLocation ColonLoc, |
6838 | ArrayRef<CXXCtorInitializer*> MemInits, |
6839 | bool AnyErrors); |
6840 | |
6841 | /// Check class-level dllimport/dllexport attribute. The caller must |
6842 | /// ensure that referenceDLLExportedClassMethods is called some point later |
6843 | /// when all outer classes of Class are complete. |
6844 | void checkClassLevelDLLAttribute(CXXRecordDecl *Class); |
6845 | void checkClassLevelCodeSegAttribute(CXXRecordDecl *Class); |
6846 | |
6847 | void referenceDLLExportedClassMethods(); |
6848 | |
6849 | void propagateDLLAttrToBaseClassTemplate( |
6850 | CXXRecordDecl *Class, Attr *ClassAttr, |
6851 | ClassTemplateSpecializationDecl *BaseTemplateSpec, |
6852 | SourceLocation BaseLoc); |
6853 | |
6854 | /// Add gsl::Pointer attribute to std::container::iterator |
6855 | /// \param ND The declaration that introduces the name |
6856 | /// std::container::iterator. \param UnderlyingRecord The record named by ND. |
6857 | void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord); |
6858 | |
6859 | /// Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types. |
6860 | void inferGslOwnerPointerAttribute(CXXRecordDecl *Record); |
6861 | |
6862 | /// Add [[gsl::Pointer]] attributes for std:: types. |
6863 | void inferGslPointerAttribute(TypedefNameDecl *TD); |
6864 | |
6865 | void CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record); |
6866 | |
6867 | /// Check that the C++ class annoated with "trivial_abi" satisfies all the |
6868 | /// conditions that are needed for the attribute to have an effect. |
6869 | void checkIllFormedTrivialABIStruct(CXXRecordDecl &RD); |
6870 | |
6871 | void ActOnFinishCXXMemberSpecification(Scope *S, SourceLocation RLoc, |
6872 | Decl *TagDecl, SourceLocation LBrac, |
6873 | SourceLocation RBrac, |
6874 | const ParsedAttributesView &AttrList); |
6875 | void ActOnFinishCXXMemberDecls(); |
6876 | void ActOnFinishCXXNonNestedClass(); |
6877 | |
6878 | void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param); |
6879 | unsigned ActOnReenterTemplateScope(Decl *Template, |
6880 | llvm::function_ref<Scope *()> EnterScope); |
6881 | void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); |
6882 | void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
6883 | void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); |
6884 | void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); |
6885 | void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
6886 | void ActOnFinishDelayedMemberInitializers(Decl *Record); |
6887 | void MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD, |
6888 | CachedTokens &Toks); |
6889 | void UnmarkAsLateParsedTemplate(FunctionDecl *FD); |
6890 | bool IsInsideALocalClassWithinATemplateFunction(); |
6891 | |
6892 | Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
6893 | Expr *AssertExpr, |
6894 | Expr *AssertMessageExpr, |
6895 | SourceLocation RParenLoc); |
6896 | Decl *BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
6897 | Expr *AssertExpr, |
6898 | StringLiteral *AssertMessageExpr, |
6899 | SourceLocation RParenLoc, |
6900 | bool Failed); |
6901 | |
6902 | FriendDecl *CheckFriendTypeDecl(SourceLocation LocStart, |
6903 | SourceLocation FriendLoc, |
6904 | TypeSourceInfo *TSInfo); |
6905 | Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, |
6906 | MultiTemplateParamsArg TemplateParams); |
6907 | NamedDecl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, |
6908 | MultiTemplateParamsArg TemplateParams); |
6909 | |
6910 | QualType CheckConstructorDeclarator(Declarator &D, QualType R, |
6911 | StorageClass& SC); |
6912 | void CheckConstructor(CXXConstructorDecl *Constructor); |
6913 | QualType CheckDestructorDeclarator(Declarator &D, QualType R, |
6914 | StorageClass& SC); |
6915 | bool CheckDestructor(CXXDestructorDecl *Destructor); |
6916 | void CheckConversionDeclarator(Declarator &D, QualType &R, |
6917 | StorageClass& SC); |
6918 | Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); |
6919 | void CheckDeductionGuideDeclarator(Declarator &D, QualType &R, |
6920 | StorageClass &SC); |
6921 | void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD); |
6922 | |
6923 | void CheckExplicitlyDefaultedFunction(Scope *S, FunctionDecl *MD); |
6924 | |
6925 | bool CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD, |
6926 | CXXSpecialMember CSM); |
6927 | void CheckDelayedMemberExceptionSpecs(); |
6928 | |
6929 | bool CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *MD, |
6930 | DefaultedComparisonKind DCK); |
6931 | void DeclareImplicitEqualityComparison(CXXRecordDecl *RD, |
6932 | FunctionDecl *Spaceship); |
6933 | void DefineDefaultedComparison(SourceLocation Loc, FunctionDecl *FD, |
6934 | DefaultedComparisonKind DCK); |
6935 | |
6936 | //===--------------------------------------------------------------------===// |
6937 | // C++ Derived Classes |
6938 | // |
6939 | |
6940 | /// ActOnBaseSpecifier - Parsed a base specifier |
6941 | CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, |
6942 | SourceRange SpecifierRange, |
6943 | bool Virtual, AccessSpecifier Access, |
6944 | TypeSourceInfo *TInfo, |
6945 | SourceLocation EllipsisLoc); |
6946 | |
6947 | BaseResult ActOnBaseSpecifier(Decl *classdecl, |
6948 | SourceRange SpecifierRange, |
6949 | ParsedAttributes &Attrs, |
6950 | bool Virtual, AccessSpecifier Access, |
6951 | ParsedType basetype, |
6952 | SourceLocation BaseLoc, |
6953 | SourceLocation EllipsisLoc); |
6954 | |
6955 | bool AttachBaseSpecifiers(CXXRecordDecl *Class, |
6956 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
6957 | void ActOnBaseSpecifiers(Decl *ClassDecl, |
6958 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
6959 | |
6960 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base); |
6961 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base, |
6962 | CXXBasePaths &Paths); |
6963 | |
6964 | // FIXME: I don't like this name. |
6965 | void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); |
6966 | |
6967 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
6968 | SourceLocation Loc, SourceRange Range, |
6969 | CXXCastPath *BasePath = nullptr, |
6970 | bool IgnoreAccess = false); |
6971 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
6972 | unsigned InaccessibleBaseID, |
6973 | unsigned AmbiguousBaseConvID, |
6974 | SourceLocation Loc, SourceRange Range, |
6975 | DeclarationName Name, |
6976 | CXXCastPath *BasePath, |
6977 | bool IgnoreAccess = false); |
6978 | |
6979 | std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); |
6980 | |
6981 | bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New, |
6982 | const CXXMethodDecl *Old); |
6983 | |
6984 | /// CheckOverridingFunctionReturnType - Checks whether the return types are |
6985 | /// covariant, according to C++ [class.virtual]p5. |
6986 | bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, |
6987 | const CXXMethodDecl *Old); |
6988 | |
6989 | /// CheckOverridingFunctionExceptionSpec - Checks whether the exception |
6990 | /// spec is a subset of base spec. |
6991 | bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, |
6992 | const CXXMethodDecl *Old); |
6993 | |
6994 | bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); |
6995 | |
6996 | /// CheckOverrideControl - Check C++11 override control semantics. |
6997 | void CheckOverrideControl(NamedDecl *D); |
6998 | |
6999 | /// DiagnoseAbsenceOfOverrideControl - Diagnose if 'override' keyword was |
7000 | /// not used in the declaration of an overriding method. |
7001 | void DiagnoseAbsenceOfOverrideControl(NamedDecl *D, bool Inconsistent); |
7002 | |
7003 | /// CheckForFunctionMarkedFinal - Checks whether a virtual member function |
7004 | /// overrides a virtual member function marked 'final', according to |
7005 | /// C++11 [class.virtual]p4. |
7006 | bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, |
7007 | const CXXMethodDecl *Old); |
7008 | |
7009 | |
7010 | //===--------------------------------------------------------------------===// |
7011 | // C++ Access Control |
7012 | // |
7013 | |
7014 | enum AccessResult { |
7015 | AR_accessible, |
7016 | AR_inaccessible, |
7017 | AR_dependent, |
7018 | AR_delayed |
7019 | }; |
7020 | |
7021 | bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, |
7022 | NamedDecl *PrevMemberDecl, |
7023 | AccessSpecifier LexicalAS); |
7024 | |
7025 | AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, |
7026 | DeclAccessPair FoundDecl); |
7027 | AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, |
7028 | DeclAccessPair FoundDecl); |
7029 | AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, |
7030 | SourceRange PlacementRange, |
7031 | CXXRecordDecl *NamingClass, |
7032 | DeclAccessPair FoundDecl, |
7033 | bool Diagnose = true); |
7034 | AccessResult CheckConstructorAccess(SourceLocation Loc, |
7035 | CXXConstructorDecl *D, |
7036 | DeclAccessPair FoundDecl, |
7037 | const InitializedEntity &Entity, |
7038 | bool IsCopyBindingRefToTemp = false); |
7039 | AccessResult CheckConstructorAccess(SourceLocation Loc, |
7040 | CXXConstructorDecl *D, |
7041 | DeclAccessPair FoundDecl, |
7042 | const InitializedEntity &Entity, |
7043 | const PartialDiagnostic &PDiag); |
7044 | AccessResult CheckDestructorAccess(SourceLocation Loc, |
7045 | CXXDestructorDecl *Dtor, |
7046 | const PartialDiagnostic &PDiag, |
7047 | QualType objectType = QualType()); |
7048 | AccessResult CheckFriendAccess(NamedDecl *D); |
7049 | AccessResult CheckMemberAccess(SourceLocation UseLoc, |
7050 | CXXRecordDecl *NamingClass, |
7051 | DeclAccessPair Found); |
7052 | AccessResult |
7053 | CheckStructuredBindingMemberAccess(SourceLocation UseLoc, |
7054 | CXXRecordDecl *DecomposedClass, |
7055 | DeclAccessPair Field); |
7056 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, |
7057 | Expr *ObjectExpr, |
7058 | Expr *ArgExpr, |
7059 | DeclAccessPair FoundDecl); |
7060 | AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, |
7061 | DeclAccessPair FoundDecl); |
7062 | AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, |
7063 | QualType Base, QualType Derived, |
7064 | const CXXBasePath &Path, |
7065 | unsigned DiagID, |
7066 | bool ForceCheck = false, |
7067 | bool ForceUnprivileged = false); |
7068 | void CheckLookupAccess(const LookupResult &R); |
7069 | bool IsSimplyAccessible(NamedDecl *Decl, CXXRecordDecl *NamingClass, |
7070 | QualType BaseType); |
7071 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
7072 | DeclAccessPair Found, QualType ObjectType, |
7073 | SourceLocation Loc, |
7074 | const PartialDiagnostic &Diag); |
7075 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
7076 | DeclAccessPair Found, |
7077 | QualType ObjectType) { |
7078 | return isMemberAccessibleForDeletion(NamingClass, Found, ObjectType, |
7079 | SourceLocation(), PDiag()); |
7080 | } |
7081 | |
7082 | void HandleDependentAccessCheck(const DependentDiagnostic &DD, |
7083 | const MultiLevelTemplateArgumentList &TemplateArgs); |
7084 | void PerformDependentDiagnostics(const DeclContext *Pattern, |
7085 | const MultiLevelTemplateArgumentList &TemplateArgs); |
7086 | |
7087 | void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
7088 | |
7089 | /// When true, access checking violations are treated as SFINAE |
7090 | /// failures rather than hard errors. |
7091 | bool AccessCheckingSFINAE; |
7092 | |
7093 | enum AbstractDiagSelID { |
7094 | AbstractNone = -1, |
7095 | AbstractReturnType, |
7096 | AbstractParamType, |
7097 | AbstractVariableType, |
7098 | AbstractFieldType, |
7099 | AbstractIvarType, |
7100 | AbstractSynthesizedIvarType, |
7101 | AbstractArrayType |
7102 | }; |
7103 | |
7104 | bool isAbstractType(SourceLocation Loc, QualType T); |
7105 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, |
7106 | TypeDiagnoser &Diagnoser); |
7107 | template <typename... Ts> |
7108 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, |
7109 | const Ts &...Args) { |
7110 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
7111 | return RequireNonAbstractType(Loc, T, Diagnoser); |
7112 | } |
7113 | |
7114 | void DiagnoseAbstractType(const CXXRecordDecl *RD); |
7115 | |
7116 | //===--------------------------------------------------------------------===// |
7117 | // C++ Overloaded Operators [C++ 13.5] |
7118 | // |
7119 | |
7120 | bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); |
7121 | |
7122 | bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); |
7123 | |
7124 | //===--------------------------------------------------------------------===// |
7125 | // C++ Templates [C++ 14] |
7126 | // |
7127 | void FilterAcceptableTemplateNames(LookupResult &R, |
7128 | bool AllowFunctionTemplates = true, |
7129 | bool AllowDependent = true); |
7130 | bool hasAnyAcceptableTemplateNames(LookupResult &R, |
7131 | bool AllowFunctionTemplates = true, |
7132 | bool AllowDependent = true, |
7133 | bool AllowNonTemplateFunctions = false); |
7134 | /// Try to interpret the lookup result D as a template-name. |
7135 | /// |
7136 | /// \param D A declaration found by name lookup. |
7137 | /// \param AllowFunctionTemplates Whether function templates should be |
7138 | /// considered valid results. |
7139 | /// \param AllowDependent Whether unresolved using declarations (that might |
7140 | /// name templates) should be considered valid results. |
7141 | NamedDecl *getAsTemplateNameDecl(NamedDecl *D, |
7142 | bool AllowFunctionTemplates = true, |
7143 | bool AllowDependent = true); |
7144 | |
7145 | enum TemplateNameIsRequiredTag { TemplateNameIsRequired }; |
7146 | /// Whether and why a template name is required in this lookup. |
7147 | class RequiredTemplateKind { |
7148 | public: |
7149 | /// Template name is required if TemplateKWLoc is valid. |
7150 | RequiredTemplateKind(SourceLocation TemplateKWLoc = SourceLocation()) |
7151 | : TemplateKW(TemplateKWLoc) {} |
7152 | /// Template name is unconditionally required. |
7153 | RequiredTemplateKind(TemplateNameIsRequiredTag) : TemplateKW() {} |
7154 | |
7155 | SourceLocation getTemplateKeywordLoc() const { |
7156 | return TemplateKW.getValueOr(SourceLocation()); |
7157 | } |
7158 | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } |
7159 | bool isRequired() const { return TemplateKW != SourceLocation(); } |
7160 | explicit operator bool() const { return isRequired(); } |
7161 | |
7162 | private: |
7163 | llvm::Optional<SourceLocation> TemplateKW; |
7164 | }; |
7165 | |
7166 | enum class AssumedTemplateKind { |
7167 | /// This is not assumed to be a template name. |
7168 | None, |
7169 | /// This is assumed to be a template name because lookup found nothing. |
7170 | FoundNothing, |
7171 | /// This is assumed to be a template name because lookup found one or more |
7172 | /// functions (but no function templates). |
7173 | FoundFunctions, |
7174 | }; |
7175 | bool LookupTemplateName( |
7176 | LookupResult &R, Scope *S, CXXScopeSpec &SS, QualType ObjectType, |
7177 | bool EnteringContext, bool &MemberOfUnknownSpecialization, |
7178 | RequiredTemplateKind RequiredTemplate = SourceLocation(), |
7179 | AssumedTemplateKind *ATK = nullptr, bool AllowTypoCorrection = true); |
7180 | |
7181 | TemplateNameKind isTemplateName(Scope *S, |
7182 | CXXScopeSpec &SS, |
7183 | bool hasTemplateKeyword, |
7184 | const UnqualifiedId &Name, |
7185 | ParsedType ObjectType, |
7186 | bool EnteringContext, |
7187 | TemplateTy &Template, |
7188 | bool &MemberOfUnknownSpecialization, |
7189 | bool Disambiguation = false); |
7190 | |
7191 | /// Try to resolve an undeclared template name as a type template. |
7192 | /// |
7193 | /// Sets II to the identifier corresponding to the template name, and updates |
7194 | /// Name to a corresponding (typo-corrected) type template name and TNK to |
7195 | /// the corresponding kind, if possible. |
7196 | void ActOnUndeclaredTypeTemplateName(Scope *S, TemplateTy &Name, |
7197 | TemplateNameKind &TNK, |
7198 | SourceLocation NameLoc, |
7199 | IdentifierInfo *&II); |
7200 | |
7201 | bool resolveAssumedTemplateNameAsType(Scope *S, TemplateName &Name, |
7202 | SourceLocation NameLoc, |
7203 | bool Diagnose = true); |
7204 | |
7205 | /// Determine whether a particular identifier might be the name in a C++1z |
7206 | /// deduction-guide declaration. |
7207 | bool isDeductionGuideName(Scope *S, const IdentifierInfo &Name, |
7208 | SourceLocation NameLoc, |
7209 | ParsedTemplateTy *Template = nullptr); |
7210 | |
7211 | bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, |
7212 | SourceLocation IILoc, |
7213 | Scope *S, |
7214 | const CXXScopeSpec *SS, |
7215 | TemplateTy &SuggestedTemplate, |
7216 | TemplateNameKind &SuggestedKind); |
7217 | |
7218 | bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation, |
7219 | NamedDecl *Instantiation, |
7220 | bool InstantiatedFromMember, |
7221 | const NamedDecl *Pattern, |
7222 | const NamedDecl *PatternDef, |
7223 | TemplateSpecializationKind TSK, |
7224 | bool Complain = true); |
7225 | |
7226 | void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); |
7227 | TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); |
7228 | |
7229 | NamedDecl *ActOnTypeParameter(Scope *S, bool Typename, |
7230 | SourceLocation EllipsisLoc, |
7231 | SourceLocation KeyLoc, |
7232 | IdentifierInfo *ParamName, |
7233 | SourceLocation ParamNameLoc, |
7234 | unsigned Depth, unsigned Position, |
7235 | SourceLocation EqualLoc, |
7236 | ParsedType DefaultArg, bool HasTypeConstraint); |
7237 | |
7238 | bool ActOnTypeConstraint(const CXXScopeSpec &SS, |
7239 | TemplateIdAnnotation *TypeConstraint, |
7240 | TemplateTypeParmDecl *ConstrainedParameter, |
7241 | SourceLocation EllipsisLoc); |
7242 | |
7243 | bool AttachTypeConstraint(NestedNameSpecifierLoc NS, |
7244 | DeclarationNameInfo NameInfo, |
7245 | ConceptDecl *NamedConcept, |
7246 | const TemplateArgumentListInfo *TemplateArgs, |
7247 | TemplateTypeParmDecl *ConstrainedParameter, |
7248 | SourceLocation EllipsisLoc); |
7249 | |
7250 | bool AttachTypeConstraint(AutoTypeLoc TL, |
7251 | NonTypeTemplateParmDecl *ConstrainedParameter, |
7252 | SourceLocation EllipsisLoc); |
7253 | |
7254 | bool RequireStructuralType(QualType T, SourceLocation Loc); |
7255 | |
7256 | QualType CheckNonTypeTemplateParameterType(TypeSourceInfo *&TSI, |
7257 | SourceLocation Loc); |
7258 | QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); |
7259 | |
7260 | NamedDecl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, |
7261 | unsigned Depth, |
7262 | unsigned Position, |
7263 | SourceLocation EqualLoc, |
7264 | Expr *DefaultArg); |
7265 | NamedDecl *ActOnTemplateTemplateParameter(Scope *S, |
7266 | SourceLocation TmpLoc, |
7267 | TemplateParameterList *Params, |
7268 | SourceLocation EllipsisLoc, |
7269 | IdentifierInfo *ParamName, |
7270 | SourceLocation ParamNameLoc, |
7271 | unsigned Depth, |
7272 | unsigned Position, |
7273 | SourceLocation EqualLoc, |
7274 | ParsedTemplateArgument DefaultArg); |
7275 | |
7276 | TemplateParameterList * |
7277 | ActOnTemplateParameterList(unsigned Depth, |
7278 | SourceLocation ExportLoc, |
7279 | SourceLocation TemplateLoc, |
7280 | SourceLocation LAngleLoc, |
7281 | ArrayRef<NamedDecl *> Params, |
7282 | SourceLocation RAngleLoc, |
7283 | Expr *RequiresClause); |
7284 | |
7285 | /// The context in which we are checking a template parameter list. |
7286 | enum TemplateParamListContext { |
7287 | TPC_ClassTemplate, |
7288 | TPC_VarTemplate, |
7289 | TPC_FunctionTemplate, |
7290 | TPC_ClassTemplateMember, |
7291 | TPC_FriendClassTemplate, |
7292 | TPC_FriendFunctionTemplate, |
7293 | TPC_FriendFunctionTemplateDefinition, |
7294 | TPC_TypeAliasTemplate |
7295 | }; |
7296 | |
7297 | bool CheckTemplateParameterList(TemplateParameterList *NewParams, |
7298 | TemplateParameterList *OldParams, |
7299 | TemplateParamListContext TPC, |
7300 | SkipBodyInfo *SkipBody = nullptr); |
7301 | TemplateParameterList *MatchTemplateParametersToScopeSpecifier( |
7302 | SourceLocation DeclStartLoc, SourceLocation DeclLoc, |
7303 | const CXXScopeSpec &SS, TemplateIdAnnotation *TemplateId, |
7304 | ArrayRef<TemplateParameterList *> ParamLists, |
7305 | bool IsFriend, bool &IsMemberSpecialization, bool &Invalid, |
7306 | bool SuppressDiagnostic = false); |
7307 | |
7308 | DeclResult CheckClassTemplate( |
7309 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
7310 | CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, |
7311 | const ParsedAttributesView &Attr, TemplateParameterList *TemplateParams, |
7312 | AccessSpecifier AS, SourceLocation ModulePrivateLoc, |
7313 | SourceLocation FriendLoc, unsigned NumOuterTemplateParamLists, |
7314 | TemplateParameterList **OuterTemplateParamLists, |
7315 | SkipBodyInfo *SkipBody = nullptr); |
7316 | |
7317 | TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, |
7318 | QualType NTTPType, |
7319 | SourceLocation Loc); |
7320 | |
7321 | /// Get a template argument mapping the given template parameter to itself, |
7322 | /// e.g. for X in \c template<int X>, this would return an expression template |
7323 | /// argument referencing X. |
7324 | TemplateArgumentLoc getIdentityTemplateArgumentLoc(NamedDecl *Param, |
7325 | SourceLocation Location); |
7326 | |
7327 | void translateTemplateArguments(const ASTTemplateArgsPtr &In, |
7328 | TemplateArgumentListInfo &Out); |
7329 | |
7330 | ParsedTemplateArgument ActOnTemplateTypeArgument(TypeResult ParsedType); |
7331 | |
7332 | void NoteAllFoundTemplates(TemplateName Name); |
7333 | |
7334 | QualType CheckTemplateIdType(TemplateName Template, |
7335 | SourceLocation TemplateLoc, |
7336 | TemplateArgumentListInfo &TemplateArgs); |
7337 | |
7338 | TypeResult |
7339 | ActOnTemplateIdType(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
7340 | TemplateTy Template, IdentifierInfo *TemplateII, |
7341 | SourceLocation TemplateIILoc, SourceLocation LAngleLoc, |
7342 | ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, |
7343 | bool IsCtorOrDtorName = false, bool IsClassName = false); |
7344 | |
7345 | /// Parsed an elaborated-type-specifier that refers to a template-id, |
7346 | /// such as \c class T::template apply<U>. |
7347 | TypeResult ActOnTagTemplateIdType(TagUseKind TUK, |
7348 | TypeSpecifierType TagSpec, |
7349 | SourceLocation TagLoc, |
7350 | CXXScopeSpec &SS, |
7351 | SourceLocation TemplateKWLoc, |
7352 | TemplateTy TemplateD, |
7353 | SourceLocation TemplateLoc, |
7354 | SourceLocation LAngleLoc, |
7355 | ASTTemplateArgsPtr TemplateArgsIn, |
7356 | SourceLocation RAngleLoc); |
7357 | |
7358 | DeclResult ActOnVarTemplateSpecialization( |
7359 | Scope *S, Declarator &D, TypeSourceInfo *DI, |
7360 | SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams, |
7361 | StorageClass SC, bool IsPartialSpecialization); |
7362 | |
7363 | /// Get the specialization of the given variable template corresponding to |
7364 | /// the specified argument list, or a null-but-valid result if the arguments |
7365 | /// are dependent. |
7366 | DeclResult CheckVarTemplateId(VarTemplateDecl *Template, |
7367 | SourceLocation TemplateLoc, |
7368 | SourceLocation TemplateNameLoc, |
7369 | const TemplateArgumentListInfo &TemplateArgs); |
7370 | |
7371 | /// Form a reference to the specialization of the given variable template |
7372 | /// corresponding to the specified argument list, or a null-but-valid result |
7373 | /// if the arguments are dependent. |
7374 | ExprResult CheckVarTemplateId(const CXXScopeSpec &SS, |
7375 | const DeclarationNameInfo &NameInfo, |
7376 | VarTemplateDecl *Template, |
7377 | SourceLocation TemplateLoc, |
7378 | const TemplateArgumentListInfo *TemplateArgs); |
7379 | |
7380 | ExprResult |
7381 | CheckConceptTemplateId(const CXXScopeSpec &SS, |
7382 | SourceLocation TemplateKWLoc, |
7383 | const DeclarationNameInfo &ConceptNameInfo, |
7384 | NamedDecl *FoundDecl, ConceptDecl *NamedConcept, |
7385 | const TemplateArgumentListInfo *TemplateArgs); |
7386 | |
7387 | void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc); |
7388 | |
7389 | ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, |
7390 | SourceLocation TemplateKWLoc, |
7391 | LookupResult &R, |
7392 | bool RequiresADL, |
7393 | const TemplateArgumentListInfo *TemplateArgs); |
7394 | |
7395 | ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, |
7396 | SourceLocation TemplateKWLoc, |
7397 | const DeclarationNameInfo &NameInfo, |
7398 | const TemplateArgumentListInfo *TemplateArgs); |
7399 | |
7400 | TemplateNameKind ActOnTemplateName( |
7401 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
7402 | const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, |
7403 | TemplateTy &Template, bool AllowInjectedClassName = false); |
7404 | |
7405 | DeclResult ActOnClassTemplateSpecialization( |
7406 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
7407 | SourceLocation ModulePrivateLoc, CXXScopeSpec &SS, |
7408 | TemplateIdAnnotation &TemplateId, const ParsedAttributesView &Attr, |
7409 | MultiTemplateParamsArg TemplateParameterLists, |
7410 | SkipBodyInfo *SkipBody = nullptr); |
7411 | |
7412 | bool CheckTemplatePartialSpecializationArgs(SourceLocation Loc, |
7413 | TemplateDecl *PrimaryTemplate, |
7414 | unsigned NumExplicitArgs, |
7415 | ArrayRef<TemplateArgument> Args); |
7416 | void CheckTemplatePartialSpecialization( |
7417 | ClassTemplatePartialSpecializationDecl *Partial); |
7418 | void CheckTemplatePartialSpecialization( |
7419 | VarTemplatePartialSpecializationDecl *Partial); |
7420 | |
7421 | Decl *ActOnTemplateDeclarator(Scope *S, |
7422 | MultiTemplateParamsArg TemplateParameterLists, |
7423 | Declarator &D); |
7424 | |
7425 | bool |
7426 | CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, |
7427 | TemplateSpecializationKind NewTSK, |
7428 | NamedDecl *PrevDecl, |
7429 | TemplateSpecializationKind PrevTSK, |
7430 | SourceLocation PrevPtOfInstantiation, |
7431 | bool &SuppressNew); |
7432 | |
7433 | bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, |
7434 | const TemplateArgumentListInfo &ExplicitTemplateArgs, |
7435 | LookupResult &Previous); |
7436 | |
7437 | bool CheckFunctionTemplateSpecialization( |
7438 | FunctionDecl *FD, TemplateArgumentListInfo *ExplicitTemplateArgs, |
7439 | LookupResult &Previous, bool QualifiedFriend = false); |
7440 | bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
7441 | void CompleteMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
7442 | |
7443 | DeclResult ActOnExplicitInstantiation( |
7444 | Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc, |
7445 | unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS, |
7446 | TemplateTy Template, SourceLocation TemplateNameLoc, |
7447 | SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, |
7448 | SourceLocation RAngleLoc, const ParsedAttributesView &Attr); |
7449 | |
7450 | DeclResult ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, |
7451 | SourceLocation TemplateLoc, |
7452 | unsigned TagSpec, SourceLocation KWLoc, |
7453 | CXXScopeSpec &SS, IdentifierInfo *Name, |
7454 | SourceLocation NameLoc, |
7455 | const ParsedAttributesView &Attr); |
7456 | |
7457 | DeclResult ActOnExplicitInstantiation(Scope *S, |
7458 | SourceLocation ExternLoc, |
7459 | SourceLocation TemplateLoc, |
7460 | Declarator &D); |
7461 | |
7462 | TemplateArgumentLoc |
7463 | SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, |
7464 | SourceLocation TemplateLoc, |
7465 | SourceLocation RAngleLoc, |
7466 | Decl *Param, |
7467 | SmallVectorImpl<TemplateArgument> |
7468 | &Converted, |
7469 | bool &HasDefaultArg); |
7470 | |
7471 | /// Specifies the context in which a particular template |
7472 | /// argument is being checked. |
7473 | enum CheckTemplateArgumentKind { |
7474 | /// The template argument was specified in the code or was |
7475 | /// instantiated with some deduced template arguments. |
7476 | CTAK_Specified, |
7477 | |
7478 | /// The template argument was deduced via template argument |
7479 | /// deduction. |
7480 | CTAK_Deduced, |
7481 | |
7482 | /// The template argument was deduced from an array bound |
7483 | /// via template argument deduction. |
7484 | CTAK_DeducedFromArrayBound |
7485 | }; |
7486 | |
7487 | bool CheckTemplateArgument(NamedDecl *Param, |
7488 | TemplateArgumentLoc &Arg, |
7489 | NamedDecl *Template, |
7490 | SourceLocation TemplateLoc, |
7491 | SourceLocation RAngleLoc, |
7492 | unsigned ArgumentPackIndex, |
7493 | SmallVectorImpl<TemplateArgument> &Converted, |
7494 | CheckTemplateArgumentKind CTAK = CTAK_Specified); |
7495 | |
7496 | /// Check that the given template arguments can be be provided to |
7497 | /// the given template, converting the arguments along the way. |
7498 | /// |
7499 | /// \param Template The template to which the template arguments are being |
7500 | /// provided. |
7501 | /// |
7502 | /// \param TemplateLoc The location of the template name in the source. |
7503 | /// |
7504 | /// \param TemplateArgs The list of template arguments. If the template is |
7505 | /// a template template parameter, this function may extend the set of |
7506 | /// template arguments to also include substituted, defaulted template |
7507 | /// arguments. |
7508 | /// |
7509 | /// \param PartialTemplateArgs True if the list of template arguments is |
7510 | /// intentionally partial, e.g., because we're checking just the initial |
7511 | /// set of template arguments. |
7512 | /// |
7513 | /// \param Converted Will receive the converted, canonicalized template |
7514 | /// arguments. |
7515 | /// |
7516 | /// \param UpdateArgsWithConversions If \c true, update \p TemplateArgs to |
7517 | /// contain the converted forms of the template arguments as written. |
7518 | /// Otherwise, \p TemplateArgs will not be modified. |
7519 | /// |
7520 | /// \param ConstraintsNotSatisfied If provided, and an error occured, will |
7521 | /// receive true if the cause for the error is the associated constraints of |
7522 | /// the template not being satisfied by the template arguments. |
7523 | /// |
7524 | /// \returns true if an error occurred, false otherwise. |
7525 | bool CheckTemplateArgumentList(TemplateDecl *Template, |
7526 | SourceLocation TemplateLoc, |
7527 | TemplateArgumentListInfo &TemplateArgs, |
7528 | bool PartialTemplateArgs, |
7529 | SmallVectorImpl<TemplateArgument> &Converted, |
7530 | bool UpdateArgsWithConversions = true, |
7531 | bool *ConstraintsNotSatisfied = nullptr); |
7532 | |
7533 | bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, |
7534 | TemplateArgumentLoc &Arg, |
7535 | SmallVectorImpl<TemplateArgument> &Converted); |
7536 | |
7537 | bool CheckTemplateArgument(TemplateTypeParmDecl *Param, |
7538 | TypeSourceInfo *Arg); |
7539 | ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, |
7540 | QualType InstantiatedParamType, Expr *Arg, |
7541 | TemplateArgument &Converted, |
7542 | CheckTemplateArgumentKind CTAK = CTAK_Specified); |
7543 | bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, |
7544 | TemplateParameterList *Params, |
7545 | TemplateArgumentLoc &Arg); |
7546 | |
7547 | ExprResult |
7548 | BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, |
7549 | QualType ParamType, |
7550 | SourceLocation Loc); |
7551 | ExprResult |
7552 | BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, |
7553 | SourceLocation Loc); |
7554 | |
7555 | /// Enumeration describing how template parameter lists are compared |
7556 | /// for equality. |
7557 | enum TemplateParameterListEqualKind { |
7558 | /// We are matching the template parameter lists of two templates |
7559 | /// that might be redeclarations. |
7560 | /// |
7561 | /// \code |
7562 | /// template<typename T> struct X; |
7563 | /// template<typename T> struct X; |
7564 | /// \endcode |
7565 | TPL_TemplateMatch, |
7566 | |
7567 | /// We are matching the template parameter lists of two template |
7568 | /// template parameters as part of matching the template parameter lists |
7569 | /// of two templates that might be redeclarations. |
7570 | /// |
7571 | /// \code |
7572 | /// template<template<int I> class TT> struct X; |
7573 | /// template<template<int Value> class Other> struct X; |
7574 | /// \endcode |
7575 | TPL_TemplateTemplateParmMatch, |
7576 | |
7577 | /// We are matching the template parameter lists of a template |
7578 | /// template argument against the template parameter lists of a template |
7579 | /// template parameter. |
7580 | /// |
7581 | /// \code |
7582 | /// template<template<int Value> class Metafun> struct X; |
7583 | /// template<int Value> struct integer_c; |
7584 | /// X<integer_c> xic; |
7585 | /// \endcode |
7586 | TPL_TemplateTemplateArgumentMatch |
7587 | }; |
7588 | |
7589 | bool TemplateParameterListsAreEqual(TemplateParameterList *New, |
7590 | TemplateParameterList *Old, |
7591 | bool Complain, |
7592 | TemplateParameterListEqualKind Kind, |
7593 | SourceLocation TemplateArgLoc |
7594 | = SourceLocation()); |
7595 | |
7596 | bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); |
7597 | |
7598 | /// Called when the parser has parsed a C++ typename |
7599 | /// specifier, e.g., "typename T::type". |
7600 | /// |
7601 | /// \param S The scope in which this typename type occurs. |
7602 | /// \param TypenameLoc the location of the 'typename' keyword |
7603 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
7604 | /// \param II the identifier we're retrieving (e.g., 'type' in the example). |
7605 | /// \param IdLoc the location of the identifier. |
7606 | TypeResult |
7607 | ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, |
7608 | const CXXScopeSpec &SS, const IdentifierInfo &II, |
7609 | SourceLocation IdLoc); |
7610 | |
7611 | /// Called when the parser has parsed a C++ typename |
7612 | /// specifier that ends in a template-id, e.g., |
7613 | /// "typename MetaFun::template apply<T1, T2>". |
7614 | /// |
7615 | /// \param S The scope in which this typename type occurs. |
7616 | /// \param TypenameLoc the location of the 'typename' keyword |
7617 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
7618 | /// \param TemplateLoc the location of the 'template' keyword, if any. |
7619 | /// \param TemplateName The template name. |
7620 | /// \param TemplateII The identifier used to name the template. |
7621 | /// \param TemplateIILoc The location of the template name. |
7622 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
7623 | /// \param TemplateArgs The template arguments. |
7624 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
7625 | TypeResult |
7626 | ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, |
7627 | const CXXScopeSpec &SS, |
7628 | SourceLocation TemplateLoc, |
7629 | TemplateTy TemplateName, |
7630 | IdentifierInfo *TemplateII, |
7631 | SourceLocation TemplateIILoc, |
7632 | SourceLocation LAngleLoc, |
7633 | ASTTemplateArgsPtr TemplateArgs, |
7634 | SourceLocation RAngleLoc); |
7635 | |
7636 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
7637 | SourceLocation KeywordLoc, |
7638 | NestedNameSpecifierLoc QualifierLoc, |
7639 | const IdentifierInfo &II, |
7640 | SourceLocation IILoc, |
7641 | TypeSourceInfo **TSI, |
7642 | bool DeducedTSTContext); |
7643 | |
7644 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
7645 | SourceLocation KeywordLoc, |
7646 | NestedNameSpecifierLoc QualifierLoc, |
7647 | const IdentifierInfo &II, |
7648 | SourceLocation IILoc, |
7649 | bool DeducedTSTContext = true); |
7650 | |
7651 | |
7652 | TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, |
7653 | SourceLocation Loc, |
7654 | DeclarationName Name); |
7655 | bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); |
7656 | |
7657 | ExprResult RebuildExprInCurrentInstantiation(Expr *E); |
7658 | bool RebuildTemplateParamsInCurrentInstantiation( |
7659 | TemplateParameterList *Params); |
7660 | |
7661 | std::string |
7662 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
7663 | const TemplateArgumentList &Args); |
7664 | |
7665 | std::string |
7666 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
7667 | const TemplateArgument *Args, |
7668 | unsigned NumArgs); |
7669 | |
7670 | //===--------------------------------------------------------------------===// |
7671 | // C++ Concepts |
7672 | //===--------------------------------------------------------------------===// |
7673 | Decl *ActOnConceptDefinition( |
7674 | Scope *S, MultiTemplateParamsArg TemplateParameterLists, |
7675 | IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr); |
7676 | |
7677 | RequiresExprBodyDecl * |
7678 | ActOnStartRequiresExpr(SourceLocation RequiresKWLoc, |
7679 | ArrayRef<ParmVarDecl *> LocalParameters, |
7680 | Scope *BodyScope); |
7681 | void ActOnFinishRequiresExpr(); |
7682 | concepts::Requirement *ActOnSimpleRequirement(Expr *E); |
7683 | concepts::Requirement *ActOnTypeRequirement( |
7684 | SourceLocation TypenameKWLoc, CXXScopeSpec &SS, SourceLocation NameLoc, |
7685 | IdentifierInfo *TypeName, TemplateIdAnnotation *TemplateId); |
7686 | concepts::Requirement *ActOnCompoundRequirement(Expr *E, |
7687 | SourceLocation NoexceptLoc); |
7688 | concepts::Requirement * |
7689 | ActOnCompoundRequirement( |
7690 | Expr *E, SourceLocation NoexceptLoc, CXXScopeSpec &SS, |
7691 | TemplateIdAnnotation *TypeConstraint, unsigned Depth); |
7692 | concepts::Requirement *ActOnNestedRequirement(Expr *Constraint); |
7693 | concepts::ExprRequirement * |
7694 | BuildExprRequirement( |
7695 | Expr *E, bool IsSatisfied, SourceLocation NoexceptLoc, |
7696 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
7697 | concepts::ExprRequirement * |
7698 | BuildExprRequirement( |
7699 | concepts::Requirement::SubstitutionDiagnostic *ExprSubstDiag, |
7700 | bool IsSatisfied, SourceLocation NoexceptLoc, |
7701 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
7702 | concepts::TypeRequirement *BuildTypeRequirement(TypeSourceInfo *Type); |
7703 | concepts::TypeRequirement * |
7704 | BuildTypeRequirement( |
7705 | concepts::Requirement::SubstitutionDiagnostic *SubstDiag); |
7706 | concepts::NestedRequirement *BuildNestedRequirement(Expr *E); |
7707 | concepts::NestedRequirement * |
7708 | BuildNestedRequirement( |
7709 | concepts::Requirement::SubstitutionDiagnostic *SubstDiag); |
7710 | ExprResult ActOnRequiresExpr(SourceLocation RequiresKWLoc, |
7711 | RequiresExprBodyDecl *Body, |
7712 | ArrayRef<ParmVarDecl *> LocalParameters, |
7713 | ArrayRef<concepts::Requirement *> Requirements, |
7714 | SourceLocation ClosingBraceLoc); |
7715 | |
7716 | //===--------------------------------------------------------------------===// |
7717 | // C++ Variadic Templates (C++0x [temp.variadic]) |
7718 | //===--------------------------------------------------------------------===// |
7719 | |
7720 | /// Determine whether an unexpanded parameter pack might be permitted in this |
7721 | /// location. Useful for error recovery. |
7722 | bool isUnexpandedParameterPackPermitted(); |
7723 | |
7724 | /// The context in which an unexpanded parameter pack is |
7725 | /// being diagnosed. |
7726 | /// |
7727 | /// Note that the values of this enumeration line up with the first |
7728 | /// argument to the \c err_unexpanded_parameter_pack diagnostic. |
7729 | enum UnexpandedParameterPackContext { |
7730 | /// An arbitrary expression. |
7731 | UPPC_Expression = 0, |
7732 | |
7733 | /// The base type of a class type. |
7734 | UPPC_BaseType, |
7735 | |
7736 | /// The type of an arbitrary declaration. |
7737 | UPPC_DeclarationType, |
7738 | |
7739 | /// The type of a data member. |
7740 | UPPC_DataMemberType, |
7741 | |
7742 | /// The size of a bit-field. |
7743 | UPPC_BitFieldWidth, |
7744 | |
7745 | /// The expression in a static assertion. |
7746 | UPPC_StaticAssertExpression, |
7747 | |
7748 | /// The fixed underlying type of an enumeration. |
7749 | UPPC_FixedUnderlyingType, |
7750 | |
7751 | /// The enumerator value. |
7752 | UPPC_EnumeratorValue, |
7753 | |
7754 | /// A using declaration. |
7755 | UPPC_UsingDeclaration, |
7756 | |
7757 | /// A friend declaration. |
7758 | UPPC_FriendDeclaration, |
7759 | |
7760 | /// A declaration qualifier. |
7761 | UPPC_DeclarationQualifier, |
7762 | |
7763 | /// An initializer. |
7764 | UPPC_Initializer, |
7765 | |
7766 | /// A default argument. |
7767 | UPPC_DefaultArgument, |
7768 | |
7769 | /// The type of a non-type template parameter. |
7770 | UPPC_NonTypeTemplateParameterType, |
7771 | |
7772 | /// The type of an exception. |
7773 | UPPC_ExceptionType, |
7774 | |
7775 | /// Partial specialization. |
7776 | UPPC_PartialSpecialization, |
7777 | |
7778 | /// Microsoft __if_exists. |
7779 | UPPC_IfExists, |
7780 | |
7781 | /// Microsoft __if_not_exists. |
7782 | UPPC_IfNotExists, |
7783 | |
7784 | /// Lambda expression. |
7785 | UPPC_Lambda, |
7786 | |
7787 | /// Block expression. |
7788 | UPPC_Block, |
7789 | |
7790 | /// A type constraint. |
7791 | UPPC_TypeConstraint, |
7792 | |
7793 | // A requirement in a requires-expression. |
7794 | UPPC_Requirement, |
7795 | }; |
7796 | |
7797 | /// Diagnose unexpanded parameter packs. |
7798 | /// |
7799 | /// \param Loc The location at which we should emit the diagnostic. |
7800 | /// |
7801 | /// \param UPPC The context in which we are diagnosing unexpanded |
7802 | /// parameter packs. |
7803 | /// |
7804 | /// \param Unexpanded the set of unexpanded parameter packs. |
7805 | /// |
7806 | /// \returns true if an error occurred, false otherwise. |
7807 | bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc, |
7808 | UnexpandedParameterPackContext UPPC, |
7809 | ArrayRef<UnexpandedParameterPack> Unexpanded); |
7810 | |
7811 | /// If the given type contains an unexpanded parameter pack, |
7812 | /// diagnose the error. |
7813 | /// |
7814 | /// \param Loc The source location where a diagnostc should be emitted. |
7815 | /// |
7816 | /// \param T The type that is being checked for unexpanded parameter |
7817 | /// packs. |
7818 | /// |
7819 | /// \returns true if an error occurred, false otherwise. |
7820 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, |
7821 | UnexpandedParameterPackContext UPPC); |
7822 | |
7823 | /// If the given expression contains an unexpanded parameter |
7824 | /// pack, diagnose the error. |
7825 | /// |
7826 | /// \param E The expression that is being checked for unexpanded |
7827 | /// parameter packs. |
7828 | /// |
7829 | /// \returns true if an error occurred, false otherwise. |
7830 | bool DiagnoseUnexpandedParameterPack(Expr *E, |
7831 | UnexpandedParameterPackContext UPPC = UPPC_Expression); |
7832 | |
7833 | /// If the given requirees-expression contains an unexpanded reference to one |
7834 | /// of its own parameter packs, diagnose the error. |
7835 | /// |
7836 | /// \param RE The requiress-expression that is being checked for unexpanded |
7837 | /// parameter packs. |
7838 | /// |
7839 | /// \returns true if an error occurred, false otherwise. |
7840 | bool DiagnoseUnexpandedParameterPackInRequiresExpr(RequiresExpr *RE); |
7841 | |
7842 | /// If the given nested-name-specifier contains an unexpanded |
7843 | /// parameter pack, diagnose the error. |
7844 | /// |
7845 | /// \param SS The nested-name-specifier that is being checked for |
7846 | /// unexpanded parameter packs. |
7847 | /// |
7848 | /// \returns true if an error occurred, false otherwise. |
7849 | bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, |
7850 | UnexpandedParameterPackContext UPPC); |
7851 | |
7852 | /// If the given name contains an unexpanded parameter pack, |
7853 | /// diagnose the error. |
7854 | /// |
7855 | /// \param NameInfo The name (with source location information) that |
7856 | /// is being checked for unexpanded parameter packs. |
7857 | /// |
7858 | /// \returns true if an error occurred, false otherwise. |
7859 | bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, |
7860 | UnexpandedParameterPackContext UPPC); |
7861 | |
7862 | /// If the given template name contains an unexpanded parameter pack, |
7863 | /// diagnose the error. |
7864 | /// |
7865 | /// \param Loc The location of the template name. |
7866 | /// |
7867 | /// \param Template The template name that is being checked for unexpanded |
7868 | /// parameter packs. |
7869 | /// |
7870 | /// \returns true if an error occurred, false otherwise. |
7871 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, |
7872 | TemplateName Template, |
7873 | UnexpandedParameterPackContext UPPC); |
7874 | |
7875 | /// If the given template argument contains an unexpanded parameter |
7876 | /// pack, diagnose the error. |
7877 | /// |
7878 | /// \param Arg The template argument that is being checked for unexpanded |
7879 | /// parameter packs. |
7880 | /// |
7881 | /// \returns true if an error occurred, false otherwise. |
7882 | bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, |
7883 | UnexpandedParameterPackContext UPPC); |
7884 | |
7885 | /// Collect the set of unexpanded parameter packs within the given |
7886 | /// template argument. |
7887 | /// |
7888 | /// \param Arg The template argument that will be traversed to find |
7889 | /// unexpanded parameter packs. |
7890 | void collectUnexpandedParameterPacks(TemplateArgument Arg, |
7891 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
7892 | |
7893 | /// Collect the set of unexpanded parameter packs within the given |
7894 | /// template argument. |
7895 | /// |
7896 | /// \param Arg The template argument that will be traversed to find |
7897 | /// unexpanded parameter packs. |
7898 | void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, |
7899 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
7900 | |
7901 | /// Collect the set of unexpanded parameter packs within the given |
7902 | /// type. |
7903 | /// |
7904 | /// \param T The type that will be traversed to find |
7905 | /// unexpanded parameter packs. |
7906 | void collectUnexpandedParameterPacks(QualType T, |
7907 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
7908 | |
7909 | /// Collect the set of unexpanded parameter packs within the given |
7910 | /// type. |
7911 | /// |
7912 | /// \param TL The type that will be traversed to find |
7913 | /// unexpanded parameter packs. |
7914 | void collectUnexpandedParameterPacks(TypeLoc TL, |
7915 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
7916 | |
7917 | /// Collect the set of unexpanded parameter packs within the given |
7918 | /// nested-name-specifier. |
7919 | /// |
7920 | /// \param NNS The nested-name-specifier that will be traversed to find |
7921 | /// unexpanded parameter packs. |
7922 | void collectUnexpandedParameterPacks(NestedNameSpecifierLoc NNS, |
7923 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
7924 | |
7925 | /// Collect the set of unexpanded parameter packs within the given |
7926 | /// name. |
7927 | /// |
7928 | /// \param NameInfo The name that will be traversed to find |
7929 | /// unexpanded parameter packs. |
7930 | void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo, |
7931 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
7932 | |
7933 | /// Invoked when parsing a template argument followed by an |
7934 | /// ellipsis, which creates a pack expansion. |
7935 | /// |
7936 | /// \param Arg The template argument preceding the ellipsis, which |
7937 | /// may already be invalid. |
7938 | /// |
7939 | /// \param EllipsisLoc The location of the ellipsis. |
7940 | ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, |
7941 | SourceLocation EllipsisLoc); |
7942 | |
7943 | /// Invoked when parsing a type followed by an ellipsis, which |
7944 | /// creates a pack expansion. |
7945 | /// |
7946 | /// \param Type The type preceding the ellipsis, which will become |
7947 | /// the pattern of the pack expansion. |
7948 | /// |
7949 | /// \param EllipsisLoc The location of the ellipsis. |
7950 | TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); |
7951 | |
7952 | /// Construct a pack expansion type from the pattern of the pack |
7953 | /// expansion. |
7954 | TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, |
7955 | SourceLocation EllipsisLoc, |
7956 | Optional<unsigned> NumExpansions); |
7957 | |
7958 | /// Construct a pack expansion type from the pattern of the pack |
7959 | /// expansion. |
7960 | QualType CheckPackExpansion(QualType Pattern, |
7961 | SourceRange PatternRange, |
7962 | SourceLocation EllipsisLoc, |
7963 | Optional<unsigned> NumExpansions); |
7964 | |
7965 | /// Invoked when parsing an expression followed by an ellipsis, which |
7966 | /// creates a pack expansion. |
7967 | /// |
7968 | /// \param Pattern The expression preceding the ellipsis, which will become |
7969 | /// the pattern of the pack expansion. |
7970 | /// |
7971 | /// \param EllipsisLoc The location of the ellipsis. |
7972 | ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); |
7973 | |
7974 | /// Invoked when parsing an expression followed by an ellipsis, which |
7975 | /// creates a pack expansion. |
7976 | /// |
7977 | /// \param Pattern The expression preceding the ellipsis, which will become |
7978 | /// the pattern of the pack expansion. |
7979 | /// |
7980 | /// \param EllipsisLoc The location of the ellipsis. |
7981 | ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
7982 | Optional<unsigned> NumExpansions); |
7983 | |
7984 | /// Determine whether we could expand a pack expansion with the |
7985 | /// given set of parameter packs into separate arguments by repeatedly |
7986 | /// transforming the pattern. |
7987 | /// |
7988 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
7989 | /// pack expansion. |
7990 | /// |
7991 | /// \param PatternRange The source range that covers the entire pattern of |
7992 | /// the pack expansion. |
7993 | /// |
7994 | /// \param Unexpanded The set of unexpanded parameter packs within the |
7995 | /// pattern. |
7996 | /// |
7997 | /// \param ShouldExpand Will be set to \c true if the transformer should |
7998 | /// expand the corresponding pack expansions into separate arguments. When |
7999 | /// set, \c NumExpansions must also be set. |
8000 | /// |
8001 | /// \param RetainExpansion Whether the caller should add an unexpanded |
8002 | /// pack expansion after all of the expanded arguments. This is used |
8003 | /// when extending explicitly-specified template argument packs per |
8004 | /// C++0x [temp.arg.explicit]p9. |
8005 | /// |
8006 | /// \param NumExpansions The number of separate arguments that will be in |
8007 | /// the expanded form of the corresponding pack expansion. This is both an |
8008 | /// input and an output parameter, which can be set by the caller if the |
8009 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
8010 | /// and will be set by the callee when the number of expansions is known. |
8011 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
8012 | /// set this value in other cases. |
8013 | /// |
8014 | /// \returns true if an error occurred (e.g., because the parameter packs |
8015 | /// are to be instantiated with arguments of different lengths), false |
8016 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
8017 | /// must be set. |
8018 | bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, |
8019 | SourceRange PatternRange, |
8020 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
8021 | const MultiLevelTemplateArgumentList &TemplateArgs, |
8022 | bool &ShouldExpand, |
8023 | bool &RetainExpansion, |
8024 | Optional<unsigned> &NumExpansions); |
8025 | |
8026 | /// Determine the number of arguments in the given pack expansion |
8027 | /// type. |
8028 | /// |
8029 | /// This routine assumes that the number of arguments in the expansion is |
8030 | /// consistent across all of the unexpanded parameter packs in its pattern. |
8031 | /// |
8032 | /// Returns an empty Optional if the type can't be expanded. |
8033 | Optional<unsigned> getNumArgumentsInExpansion(QualType T, |
8034 | const MultiLevelTemplateArgumentList &TemplateArgs); |
8035 | |
8036 | /// Determine whether the given declarator contains any unexpanded |
8037 | /// parameter packs. |
8038 | /// |
8039 | /// This routine is used by the parser to disambiguate function declarators |
8040 | /// with an ellipsis prior to the ')', e.g., |
8041 | /// |
8042 | /// \code |
8043 | /// void f(T...); |
8044 | /// \endcode |
8045 | /// |
8046 | /// To determine whether we have an (unnamed) function parameter pack or |
8047 | /// a variadic function. |
8048 | /// |
8049 | /// \returns true if the declarator contains any unexpanded parameter packs, |
8050 | /// false otherwise. |
8051 | bool containsUnexpandedParameterPacks(Declarator &D); |
8052 | |
8053 | /// Returns the pattern of the pack expansion for a template argument. |
8054 | /// |
8055 | /// \param OrigLoc The template argument to expand. |
8056 | /// |
8057 | /// \param Ellipsis Will be set to the location of the ellipsis. |
8058 | /// |
8059 | /// \param NumExpansions Will be set to the number of expansions that will |
8060 | /// be generated from this pack expansion, if known a priori. |
8061 | TemplateArgumentLoc getTemplateArgumentPackExpansionPattern( |
8062 | TemplateArgumentLoc OrigLoc, |
8063 | SourceLocation &Ellipsis, |
8064 | Optional<unsigned> &NumExpansions) const; |
8065 | |
8066 | /// Given a template argument that contains an unexpanded parameter pack, but |
8067 | /// which has already been substituted, attempt to determine the number of |
8068 | /// elements that will be produced once this argument is fully-expanded. |
8069 | /// |
8070 | /// This is intended for use when transforming 'sizeof...(Arg)' in order to |
8071 | /// avoid actually expanding the pack where possible. |
8072 | Optional<unsigned> getFullyPackExpandedSize(TemplateArgument Arg); |
8073 | |
8074 | //===--------------------------------------------------------------------===// |
8075 | // C++ Template Argument Deduction (C++ [temp.deduct]) |
8076 | //===--------------------------------------------------------------------===// |
8077 | |
8078 | /// Adjust the type \p ArgFunctionType to match the calling convention, |
8079 | /// noreturn, and optionally the exception specification of \p FunctionType. |
8080 | /// Deduction often wants to ignore these properties when matching function |
8081 | /// types. |
8082 | QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType, |
8083 | bool AdjustExceptionSpec = false); |
8084 | |
8085 | /// Describes the result of template argument deduction. |
8086 | /// |
8087 | /// The TemplateDeductionResult enumeration describes the result of |
8088 | /// template argument deduction, as returned from |
8089 | /// DeduceTemplateArguments(). The separate TemplateDeductionInfo |
8090 | /// structure provides additional information about the results of |
8091 | /// template argument deduction, e.g., the deduced template argument |
8092 | /// list (if successful) or the specific template parameters or |
8093 | /// deduced arguments that were involved in the failure. |
8094 | enum TemplateDeductionResult { |
8095 | /// Template argument deduction was successful. |
8096 | TDK_Success = 0, |
8097 | /// The declaration was invalid; do nothing. |
8098 | TDK_Invalid, |
8099 | /// Template argument deduction exceeded the maximum template |
8100 | /// instantiation depth (which has already been diagnosed). |
8101 | TDK_InstantiationDepth, |
8102 | /// Template argument deduction did not deduce a value |
8103 | /// for every template parameter. |
8104 | TDK_Incomplete, |
8105 | /// Template argument deduction did not deduce a value for every |
8106 | /// expansion of an expanded template parameter pack. |
8107 | TDK_IncompletePack, |
8108 | /// Template argument deduction produced inconsistent |
8109 | /// deduced values for the given template parameter. |
8110 | TDK_Inconsistent, |
8111 | /// Template argument deduction failed due to inconsistent |
8112 | /// cv-qualifiers on a template parameter type that would |
8113 | /// otherwise be deduced, e.g., we tried to deduce T in "const T" |
8114 | /// but were given a non-const "X". |
8115 | TDK_Underqualified, |
8116 | /// Substitution of the deduced template argument values |
8117 | /// resulted in an error. |
8118 | TDK_SubstitutionFailure, |
8119 | /// After substituting deduced template arguments, a dependent |
8120 | /// parameter type did not match the corresponding argument. |
8121 | TDK_DeducedMismatch, |
8122 | /// After substituting deduced template arguments, an element of |
8123 | /// a dependent parameter type did not match the corresponding element |
8124 | /// of the corresponding argument (when deducing from an initializer list). |
8125 | TDK_DeducedMismatchNested, |
8126 | /// A non-depnedent component of the parameter did not match the |
8127 | /// corresponding component of the argument. |
8128 | TDK_NonDeducedMismatch, |
8129 | /// When performing template argument deduction for a function |
8130 | /// template, there were too many call arguments. |
8131 | TDK_TooManyArguments, |
8132 | /// When performing template argument deduction for a function |
8133 | /// template, there were too few call arguments. |
8134 | TDK_TooFewArguments, |
8135 | /// The explicitly-specified template arguments were not valid |
8136 | /// template arguments for the given template. |
8137 | TDK_InvalidExplicitArguments, |
8138 | /// Checking non-dependent argument conversions failed. |
8139 | TDK_NonDependentConversionFailure, |
8140 | /// The deduced arguments did not satisfy the constraints associated |
8141 | /// with the template. |
8142 | TDK_ConstraintsNotSatisfied, |
8143 | /// Deduction failed; that's all we know. |
8144 | TDK_MiscellaneousDeductionFailure, |
8145 | /// CUDA Target attributes do not match. |
8146 | TDK_CUDATargetMismatch |
8147 | }; |
8148 | |
8149 | TemplateDeductionResult |
8150 | DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, |
8151 | const TemplateArgumentList &TemplateArgs, |
8152 | sema::TemplateDeductionInfo &Info); |
8153 | |
8154 | TemplateDeductionResult |
8155 | DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, |
8156 | const TemplateArgumentList &TemplateArgs, |
8157 | sema::TemplateDeductionInfo &Info); |
8158 | |
8159 | TemplateDeductionResult SubstituteExplicitTemplateArguments( |
8160 | FunctionTemplateDecl *FunctionTemplate, |
8161 | TemplateArgumentListInfo &ExplicitTemplateArgs, |
8162 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
8163 | SmallVectorImpl<QualType> &ParamTypes, QualType *FunctionType, |
8164 | sema::TemplateDeductionInfo &Info); |
8165 | |
8166 | /// brief A function argument from which we performed template argument |
8167 | // deduction for a call. |
8168 | struct OriginalCallArg { |
8169 | OriginalCallArg(QualType OriginalParamType, bool DecomposedParam, |
8170 | unsigned ArgIdx, QualType OriginalArgType) |
8171 | : OriginalParamType(OriginalParamType), |
8172 | DecomposedParam(DecomposedParam), ArgIdx(ArgIdx), |
8173 | OriginalArgType(OriginalArgType) {} |
8174 | |
8175 | QualType OriginalParamType; |
8176 | bool DecomposedParam; |
8177 | unsigned ArgIdx; |
8178 | QualType OriginalArgType; |
8179 | }; |
8180 | |
8181 | TemplateDeductionResult FinishTemplateArgumentDeduction( |
8182 | FunctionTemplateDecl *FunctionTemplate, |
8183 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
8184 | unsigned NumExplicitlySpecified, FunctionDecl *&Specialization, |
8185 | sema::TemplateDeductionInfo &Info, |
8186 | SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = nullptr, |
8187 | bool PartialOverloading = false, |
8188 | llvm::function_ref<bool()> CheckNonDependent = []{ return false; }); |
8189 | |
8190 | TemplateDeductionResult DeduceTemplateArguments( |
8191 | FunctionTemplateDecl *FunctionTemplate, |
8192 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
8193 | FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, |
8194 | bool PartialOverloading, |
8195 | llvm::function_ref<bool(ArrayRef<QualType>)> CheckNonDependent); |
8196 | |
8197 | TemplateDeductionResult |
8198 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
8199 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
8200 | QualType ArgFunctionType, |
8201 | FunctionDecl *&Specialization, |
8202 | sema::TemplateDeductionInfo &Info, |
8203 | bool IsAddressOfFunction = false); |
8204 | |
8205 | TemplateDeductionResult |
8206 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
8207 | QualType ToType, |
8208 | CXXConversionDecl *&Specialization, |
8209 | sema::TemplateDeductionInfo &Info); |
8210 | |
8211 | TemplateDeductionResult |
8212 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
8213 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
8214 | FunctionDecl *&Specialization, |
8215 | sema::TemplateDeductionInfo &Info, |
8216 | bool IsAddressOfFunction = false); |
8217 | |
8218 | /// Substitute Replacement for \p auto in \p TypeWithAuto |
8219 | QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement); |
8220 | /// Substitute Replacement for auto in TypeWithAuto |
8221 | TypeSourceInfo* SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
8222 | QualType Replacement); |
8223 | /// Completely replace the \c auto in \p TypeWithAuto by |
8224 | /// \p Replacement. This does not retain any \c auto type sugar. |
8225 | QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement); |
8226 | TypeSourceInfo *ReplaceAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
8227 | QualType Replacement); |
8228 | |
8229 | /// Result type of DeduceAutoType. |
8230 | enum DeduceAutoResult { |
8231 | DAR_Succeeded, |
8232 | DAR_Failed, |
8233 | DAR_FailedAlreadyDiagnosed |
8234 | }; |
8235 | |
8236 | DeduceAutoResult |
8237 | DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer, QualType &Result, |
8238 | Optional<unsigned> DependentDeductionDepth = None, |
8239 | bool IgnoreConstraints = false); |
8240 | DeduceAutoResult |
8241 | DeduceAutoType(TypeLoc AutoTypeLoc, Expr *&Initializer, QualType &Result, |
8242 | Optional<unsigned> DependentDeductionDepth = None, |
8243 | bool IgnoreConstraints = false); |
8244 | void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init); |
8245 | bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc, |
8246 | bool Diagnose = true); |
8247 | |
8248 | /// Declare implicit deduction guides for a class template if we've |
8249 | /// not already done so. |
8250 | void DeclareImplicitDeductionGuides(TemplateDecl *Template, |
8251 | SourceLocation Loc); |
8252 | |
8253 | QualType DeduceTemplateSpecializationFromInitializer( |
8254 | TypeSourceInfo *TInfo, const InitializedEntity &Entity, |
8255 | const InitializationKind &Kind, MultiExprArg Init); |
8256 | |
8257 | QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name, |
8258 | QualType Type, TypeSourceInfo *TSI, |
8259 | SourceRange Range, bool DirectInit, |
8260 | Expr *Init); |
8261 | |
8262 | TypeLoc getReturnTypeLoc(FunctionDecl *FD) const; |
8263 | |
8264 | bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD, |
8265 | SourceLocation ReturnLoc, |
8266 | Expr *&RetExpr, AutoType *AT); |
8267 | |
8268 | FunctionTemplateDecl *getMoreSpecializedTemplate( |
8269 | FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc, |
8270 | TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1, |
8271 | unsigned NumCallArguments2, bool Reversed = false); |
8272 | UnresolvedSetIterator |
8273 | getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd, |
8274 | TemplateSpecCandidateSet &FailedCandidates, |
8275 | SourceLocation Loc, |
8276 | const PartialDiagnostic &NoneDiag, |
8277 | const PartialDiagnostic &AmbigDiag, |
8278 | const PartialDiagnostic &CandidateDiag, |
8279 | bool Complain = true, QualType TargetType = QualType()); |
8280 | |
8281 | ClassTemplatePartialSpecializationDecl * |
8282 | getMoreSpecializedPartialSpecialization( |
8283 | ClassTemplatePartialSpecializationDecl *PS1, |
8284 | ClassTemplatePartialSpecializationDecl *PS2, |
8285 | SourceLocation Loc); |
8286 | |
8287 | bool isMoreSpecializedThanPrimary(ClassTemplatePartialSpecializationDecl *T, |
8288 | sema::TemplateDeductionInfo &Info); |
8289 | |
8290 | VarTemplatePartialSpecializationDecl *getMoreSpecializedPartialSpecialization( |
8291 | VarTemplatePartialSpecializationDecl *PS1, |
8292 | VarTemplatePartialSpecializationDecl *PS2, SourceLocation Loc); |
8293 | |
8294 | bool isMoreSpecializedThanPrimary(VarTemplatePartialSpecializationDecl *T, |
8295 | sema::TemplateDeductionInfo &Info); |
8296 | |
8297 | bool isTemplateTemplateParameterAtLeastAsSpecializedAs( |
8298 | TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc); |
8299 | |
8300 | void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced, |
8301 | unsigned Depth, llvm::SmallBitVector &Used); |
8302 | |
8303 | void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, |
8304 | bool OnlyDeduced, |
8305 | unsigned Depth, |
8306 | llvm::SmallBitVector &Used); |
8307 | void MarkDeducedTemplateParameters( |
8308 | const FunctionTemplateDecl *FunctionTemplate, |
8309 | llvm::SmallBitVector &Deduced) { |
8310 | return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced); |
8311 | } |
8312 | static void MarkDeducedTemplateParameters(ASTContext &Ctx, |
8313 | const FunctionTemplateDecl *FunctionTemplate, |
8314 | llvm::SmallBitVector &Deduced); |
8315 | |
8316 | //===--------------------------------------------------------------------===// |
8317 | // C++ Template Instantiation |
8318 | // |
8319 | |
8320 | MultiLevelTemplateArgumentList |
8321 | getTemplateInstantiationArgs(NamedDecl *D, |
8322 | const TemplateArgumentList *Innermost = nullptr, |
8323 | bool RelativeToPrimary = false, |
8324 | const FunctionDecl *Pattern = nullptr); |
8325 | |
8326 | /// A context in which code is being synthesized (where a source location |
8327 | /// alone is not sufficient to identify the context). This covers template |
8328 | /// instantiation and various forms of implicitly-generated functions. |
8329 | struct CodeSynthesisContext { |
8330 | /// The kind of template instantiation we are performing |
8331 | enum SynthesisKind { |
8332 | /// We are instantiating a template declaration. The entity is |
8333 | /// the declaration we're instantiating (e.g., a CXXRecordDecl). |
8334 | TemplateInstantiation, |
8335 | |
8336 | /// We are instantiating a default argument for a template |
8337 | /// parameter. The Entity is the template parameter whose argument is |
8338 | /// being instantiated, the Template is the template, and the |
8339 | /// TemplateArgs/NumTemplateArguments provide the template arguments as |
8340 | /// specified. |
8341 | DefaultTemplateArgumentInstantiation, |
8342 | |
8343 | /// We are instantiating a default argument for a function. |
8344 | /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs |
8345 | /// provides the template arguments as specified. |
8346 | DefaultFunctionArgumentInstantiation, |
8347 | |
8348 | /// We are substituting explicit template arguments provided for |
8349 | /// a function template. The entity is a FunctionTemplateDecl. |
8350 | ExplicitTemplateArgumentSubstitution, |
8351 | |
8352 | /// We are substituting template argument determined as part of |
8353 | /// template argument deduction for either a class template |
8354 | /// partial specialization or a function template. The |
8355 | /// Entity is either a {Class|Var}TemplatePartialSpecializationDecl or |
8356 | /// a TemplateDecl. |
8357 | DeducedTemplateArgumentSubstitution, |
8358 | |
8359 | /// We are substituting prior template arguments into a new |
8360 | /// template parameter. The template parameter itself is either a |
8361 | /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. |
8362 | PriorTemplateArgumentSubstitution, |
8363 | |
8364 | /// We are checking the validity of a default template argument that |
8365 | /// has been used when naming a template-id. |
8366 | DefaultTemplateArgumentChecking, |
8367 | |
8368 | /// We are computing the exception specification for a defaulted special |
8369 | /// member function. |
8370 | ExceptionSpecEvaluation, |
8371 | |
8372 | /// We are instantiating the exception specification for a function |
8373 | /// template which was deferred until it was needed. |
8374 | ExceptionSpecInstantiation, |
8375 | |
8376 | /// We are instantiating a requirement of a requires expression. |
8377 | RequirementInstantiation, |
8378 | |
8379 | /// We are checking the satisfaction of a nested requirement of a requires |
8380 | /// expression. |
8381 | NestedRequirementConstraintsCheck, |
8382 | |
8383 | /// We are declaring an implicit special member function. |
8384 | DeclaringSpecialMember, |
8385 | |
8386 | /// We are declaring an implicit 'operator==' for a defaulted |
8387 | /// 'operator<=>'. |
8388 | DeclaringImplicitEqualityComparison, |
8389 | |
8390 | /// We are defining a synthesized function (such as a defaulted special |
8391 | /// member). |
8392 | DefiningSynthesizedFunction, |
8393 | |
8394 | // We are checking the constraints associated with a constrained entity or |
8395 | // the constraint expression of a concept. This includes the checks that |
8396 | // atomic constraints have the type 'bool' and that they can be constant |
8397 | // evaluated. |
8398 | ConstraintsCheck, |
8399 | |
8400 | // We are substituting template arguments into a constraint expression. |
8401 | ConstraintSubstitution, |
8402 | |
8403 | // We are normalizing a constraint expression. |
8404 | ConstraintNormalization, |
8405 | |
8406 | // We are substituting into the parameter mapping of an atomic constraint |
8407 | // during normalization. |
8408 | ParameterMappingSubstitution, |
8409 | |
8410 | /// We are rewriting a comparison operator in terms of an operator<=>. |
8411 | RewritingOperatorAsSpaceship, |
8412 | |
8413 | /// We are initializing a structured binding. |
8414 | InitializingStructuredBinding, |
8415 | |
8416 | /// We are marking a class as __dllexport. |
8417 | MarkingClassDllexported, |
8418 | |
8419 | /// Added for Template instantiation observation. |
8420 | /// Memoization means we are _not_ instantiating a template because |
8421 | /// it is already instantiated (but we entered a context where we |
8422 | /// would have had to if it was not already instantiated). |
8423 | Memoization |
8424 | } Kind; |
8425 | |
8426 | /// Was the enclosing context a non-instantiation SFINAE context? |
8427 | bool SavedInNonInstantiationSFINAEContext; |
8428 | |
8429 | /// The point of instantiation or synthesis within the source code. |
8430 | SourceLocation PointOfInstantiation; |
8431 | |
8432 | /// The entity that is being synthesized. |
8433 | Decl *Entity; |
8434 | |
8435 | /// The template (or partial specialization) in which we are |
8436 | /// performing the instantiation, for substitutions of prior template |
8437 | /// arguments. |
8438 | NamedDecl *Template; |
8439 | |
8440 | /// The list of template arguments we are substituting, if they |
8441 | /// are not part of the entity. |
8442 | const TemplateArgument *TemplateArgs; |
8443 | |
8444 | // FIXME: Wrap this union around more members, or perhaps store the |
8445 | // kind-specific members in the RAII object owning the context. |
8446 | union { |
8447 | /// The number of template arguments in TemplateArgs. |
8448 | unsigned NumTemplateArgs; |
8449 | |
8450 | /// The special member being declared or defined. |
8451 | CXXSpecialMember SpecialMember; |
8452 | }; |
8453 | |
8454 | ArrayRef<TemplateArgument> template_arguments() const { |
8455 | assert(Kind != DeclaringSpecialMember)((Kind != DeclaringSpecialMember) ? static_cast<void> ( 0) : __assert_fail ("Kind != DeclaringSpecialMember", "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 8455, __PRETTY_FUNCTION__)); |
8456 | return {TemplateArgs, NumTemplateArgs}; |
8457 | } |
8458 | |
8459 | /// The template deduction info object associated with the |
8460 | /// substitution or checking of explicit or deduced template arguments. |
8461 | sema::TemplateDeductionInfo *DeductionInfo; |
8462 | |
8463 | /// The source range that covers the construct that cause |
8464 | /// the instantiation, e.g., the template-id that causes a class |
8465 | /// template instantiation. |
8466 | SourceRange InstantiationRange; |
8467 | |
8468 | CodeSynthesisContext() |
8469 | : Kind(TemplateInstantiation), |
8470 | SavedInNonInstantiationSFINAEContext(false), Entity(nullptr), |
8471 | Template(nullptr), TemplateArgs(nullptr), NumTemplateArgs(0), |
8472 | DeductionInfo(nullptr) {} |
8473 | |
8474 | /// Determines whether this template is an actual instantiation |
8475 | /// that should be counted toward the maximum instantiation depth. |
8476 | bool isInstantiationRecord() const; |
8477 | }; |
8478 | |
8479 | /// List of active code synthesis contexts. |
8480 | /// |
8481 | /// This vector is treated as a stack. As synthesis of one entity requires |
8482 | /// synthesis of another, additional contexts are pushed onto the stack. |
8483 | SmallVector<CodeSynthesisContext, 16> CodeSynthesisContexts; |
8484 | |
8485 | /// Specializations whose definitions are currently being instantiated. |
8486 | llvm::DenseSet<std::pair<Decl *, unsigned>> InstantiatingSpecializations; |
8487 | |
8488 | /// Non-dependent types used in templates that have already been instantiated |
8489 | /// by some template instantiation. |
8490 | llvm::DenseSet<QualType> InstantiatedNonDependentTypes; |
8491 | |
8492 | /// Extra modules inspected when performing a lookup during a template |
8493 | /// instantiation. Computed lazily. |
8494 | SmallVector<Module*, 16> CodeSynthesisContextLookupModules; |
8495 | |
8496 | /// Cache of additional modules that should be used for name lookup |
8497 | /// within the current template instantiation. Computed lazily; use |
8498 | /// getLookupModules() to get a complete set. |
8499 | llvm::DenseSet<Module*> LookupModulesCache; |
8500 | |
8501 | /// Get the set of additional modules that should be checked during |
8502 | /// name lookup. A module and its imports become visible when instanting a |
8503 | /// template defined within it. |
8504 | llvm::DenseSet<Module*> &getLookupModules(); |
8505 | |
8506 | /// Map from the most recent declaration of a namespace to the most |
8507 | /// recent visible declaration of that namespace. |
8508 | llvm::DenseMap<NamedDecl*, NamedDecl*> VisibleNamespaceCache; |
8509 | |
8510 | /// Whether we are in a SFINAE context that is not associated with |
8511 | /// template instantiation. |
8512 | /// |
8513 | /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside |
8514 | /// of a template instantiation or template argument deduction. |
8515 | bool InNonInstantiationSFINAEContext; |
8516 | |
8517 | /// The number of \p CodeSynthesisContexts that are not template |
8518 | /// instantiations and, therefore, should not be counted as part of the |
8519 | /// instantiation depth. |
8520 | /// |
8521 | /// When the instantiation depth reaches the user-configurable limit |
8522 | /// \p LangOptions::InstantiationDepth we will abort instantiation. |
8523 | // FIXME: Should we have a similar limit for other forms of synthesis? |
8524 | unsigned NonInstantiationEntries; |
8525 | |
8526 | /// The depth of the context stack at the point when the most recent |
8527 | /// error or warning was produced. |
8528 | /// |
8529 | /// This value is used to suppress printing of redundant context stacks |
8530 | /// when there are multiple errors or warnings in the same instantiation. |
8531 | // FIXME: Does this belong in Sema? It's tough to implement it anywhere else. |
8532 | unsigned LastEmittedCodeSynthesisContextDepth = 0; |
8533 | |
8534 | /// The template instantiation callbacks to trace or track |
8535 | /// instantiations (objects can be chained). |
8536 | /// |
8537 | /// This callbacks is used to print, trace or track template |
8538 | /// instantiations as they are being constructed. |
8539 | std::vector<std::unique_ptr<TemplateInstantiationCallback>> |
8540 | TemplateInstCallbacks; |
8541 | |
8542 | /// The current index into pack expansion arguments that will be |
8543 | /// used for substitution of parameter packs. |
8544 | /// |
8545 | /// The pack expansion index will be -1 to indicate that parameter packs |
8546 | /// should be instantiated as themselves. Otherwise, the index specifies |
8547 | /// which argument within the parameter pack will be used for substitution. |
8548 | int ArgumentPackSubstitutionIndex; |
8549 | |
8550 | /// RAII object used to change the argument pack substitution index |
8551 | /// within a \c Sema object. |
8552 | /// |
8553 | /// See \c ArgumentPackSubstitutionIndex for more information. |
8554 | class ArgumentPackSubstitutionIndexRAII { |
8555 | Sema &Self; |
8556 | int OldSubstitutionIndex; |
8557 | |
8558 | public: |
8559 | ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) |
8560 | : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { |
8561 | Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; |
8562 | } |
8563 | |
8564 | ~ArgumentPackSubstitutionIndexRAII() { |
8565 | Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; |
8566 | } |
8567 | }; |
8568 | |
8569 | friend class ArgumentPackSubstitutionRAII; |
8570 | |
8571 | /// For each declaration that involved template argument deduction, the |
8572 | /// set of diagnostics that were suppressed during that template argument |
8573 | /// deduction. |
8574 | /// |
8575 | /// FIXME: Serialize this structure to the AST file. |
8576 | typedef llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> > |
8577 | SuppressedDiagnosticsMap; |
8578 | SuppressedDiagnosticsMap SuppressedDiagnostics; |
8579 | |
8580 | /// A stack object to be created when performing template |
8581 | /// instantiation. |
8582 | /// |
8583 | /// Construction of an object of type \c InstantiatingTemplate |
8584 | /// pushes the current instantiation onto the stack of active |
8585 | /// instantiations. If the size of this stack exceeds the maximum |
8586 | /// number of recursive template instantiations, construction |
8587 | /// produces an error and evaluates true. |
8588 | /// |
8589 | /// Destruction of this object will pop the named instantiation off |
8590 | /// the stack. |
8591 | struct InstantiatingTemplate { |
8592 | /// Note that we are instantiating a class template, |
8593 | /// function template, variable template, alias template, |
8594 | /// or a member thereof. |
8595 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8596 | Decl *Entity, |
8597 | SourceRange InstantiationRange = SourceRange()); |
8598 | |
8599 | struct ExceptionSpecification {}; |
8600 | /// Note that we are instantiating an exception specification |
8601 | /// of a function template. |
8602 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8603 | FunctionDecl *Entity, ExceptionSpecification, |
8604 | SourceRange InstantiationRange = SourceRange()); |
8605 | |
8606 | /// Note that we are instantiating a default argument in a |
8607 | /// template-id. |
8608 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8609 | TemplateParameter Param, TemplateDecl *Template, |
8610 | ArrayRef<TemplateArgument> TemplateArgs, |
8611 | SourceRange InstantiationRange = SourceRange()); |
8612 | |
8613 | /// Note that we are substituting either explicitly-specified or |
8614 | /// deduced template arguments during function template argument deduction. |
8615 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8616 | FunctionTemplateDecl *FunctionTemplate, |
8617 | ArrayRef<TemplateArgument> TemplateArgs, |
8618 | CodeSynthesisContext::SynthesisKind Kind, |
8619 | sema::TemplateDeductionInfo &DeductionInfo, |
8620 | SourceRange InstantiationRange = SourceRange()); |
8621 | |
8622 | /// Note that we are instantiating as part of template |
8623 | /// argument deduction for a class template declaration. |
8624 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8625 | TemplateDecl *Template, |
8626 | ArrayRef<TemplateArgument> TemplateArgs, |
8627 | sema::TemplateDeductionInfo &DeductionInfo, |
8628 | SourceRange InstantiationRange = SourceRange()); |
8629 | |
8630 | /// Note that we are instantiating as part of template |
8631 | /// argument deduction for a class template partial |
8632 | /// specialization. |
8633 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8634 | ClassTemplatePartialSpecializationDecl *PartialSpec, |
8635 | ArrayRef<TemplateArgument> TemplateArgs, |
8636 | sema::TemplateDeductionInfo &DeductionInfo, |
8637 | SourceRange InstantiationRange = SourceRange()); |
8638 | |
8639 | /// Note that we are instantiating as part of template |
8640 | /// argument deduction for a variable template partial |
8641 | /// specialization. |
8642 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8643 | VarTemplatePartialSpecializationDecl *PartialSpec, |
8644 | ArrayRef<TemplateArgument> TemplateArgs, |
8645 | sema::TemplateDeductionInfo &DeductionInfo, |
8646 | SourceRange InstantiationRange = SourceRange()); |
8647 | |
8648 | /// Note that we are instantiating a default argument for a function |
8649 | /// parameter. |
8650 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8651 | ParmVarDecl *Param, |
8652 | ArrayRef<TemplateArgument> TemplateArgs, |
8653 | SourceRange InstantiationRange = SourceRange()); |
8654 | |
8655 | /// Note that we are substituting prior template arguments into a |
8656 | /// non-type parameter. |
8657 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8658 | NamedDecl *Template, |
8659 | NonTypeTemplateParmDecl *Param, |
8660 | ArrayRef<TemplateArgument> TemplateArgs, |
8661 | SourceRange InstantiationRange); |
8662 | |
8663 | /// Note that we are substituting prior template arguments into a |
8664 | /// template template parameter. |
8665 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8666 | NamedDecl *Template, |
8667 | TemplateTemplateParmDecl *Param, |
8668 | ArrayRef<TemplateArgument> TemplateArgs, |
8669 | SourceRange InstantiationRange); |
8670 | |
8671 | /// Note that we are checking the default template argument |
8672 | /// against the template parameter for a given template-id. |
8673 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8674 | TemplateDecl *Template, |
8675 | NamedDecl *Param, |
8676 | ArrayRef<TemplateArgument> TemplateArgs, |
8677 | SourceRange InstantiationRange); |
8678 | |
8679 | struct ConstraintsCheck {}; |
8680 | /// \brief Note that we are checking the constraints associated with some |
8681 | /// constrained entity (a concept declaration or a template with associated |
8682 | /// constraints). |
8683 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8684 | ConstraintsCheck, NamedDecl *Template, |
8685 | ArrayRef<TemplateArgument> TemplateArgs, |
8686 | SourceRange InstantiationRange); |
8687 | |
8688 | struct ConstraintSubstitution {}; |
8689 | /// \brief Note that we are checking a constraint expression associated |
8690 | /// with a template declaration or as part of the satisfaction check of a |
8691 | /// concept. |
8692 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8693 | ConstraintSubstitution, NamedDecl *Template, |
8694 | sema::TemplateDeductionInfo &DeductionInfo, |
8695 | SourceRange InstantiationRange); |
8696 | |
8697 | struct ConstraintNormalization {}; |
8698 | /// \brief Note that we are normalizing a constraint expression. |
8699 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8700 | ConstraintNormalization, NamedDecl *Template, |
8701 | SourceRange InstantiationRange); |
8702 | |
8703 | struct ParameterMappingSubstitution {}; |
8704 | /// \brief Note that we are subtituting into the parameter mapping of an |
8705 | /// atomic constraint during constraint normalization. |
8706 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8707 | ParameterMappingSubstitution, NamedDecl *Template, |
8708 | SourceRange InstantiationRange); |
8709 | |
8710 | /// \brief Note that we are substituting template arguments into a part of |
8711 | /// a requirement of a requires expression. |
8712 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8713 | concepts::Requirement *Req, |
8714 | sema::TemplateDeductionInfo &DeductionInfo, |
8715 | SourceRange InstantiationRange = SourceRange()); |
8716 | |
8717 | /// \brief Note that we are checking the satisfaction of the constraint |
8718 | /// expression inside of a nested requirement. |
8719 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8720 | concepts::NestedRequirement *Req, ConstraintsCheck, |
8721 | SourceRange InstantiationRange = SourceRange()); |
8722 | |
8723 | /// Note that we have finished instantiating this template. |
8724 | void Clear(); |
8725 | |
8726 | ~InstantiatingTemplate() { Clear(); } |
8727 | |
8728 | /// Determines whether we have exceeded the maximum |
8729 | /// recursive template instantiations. |
8730 | bool isInvalid() const { return Invalid; } |
8731 | |
8732 | /// Determine whether we are already instantiating this |
8733 | /// specialization in some surrounding active instantiation. |
8734 | bool isAlreadyInstantiating() const { return AlreadyInstantiating; } |
8735 | |
8736 | private: |
8737 | Sema &SemaRef; |
8738 | bool Invalid; |
8739 | bool AlreadyInstantiating; |
8740 | bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, |
8741 | SourceRange InstantiationRange); |
8742 | |
8743 | InstantiatingTemplate( |
8744 | Sema &SemaRef, CodeSynthesisContext::SynthesisKind Kind, |
8745 | SourceLocation PointOfInstantiation, SourceRange InstantiationRange, |
8746 | Decl *Entity, NamedDecl *Template = nullptr, |
8747 | ArrayRef<TemplateArgument> TemplateArgs = None, |
8748 | sema::TemplateDeductionInfo *DeductionInfo = nullptr); |
8749 | |
8750 | InstantiatingTemplate(const InstantiatingTemplate&) = delete; |
8751 | |
8752 | InstantiatingTemplate& |
8753 | operator=(const InstantiatingTemplate&) = delete; |
8754 | }; |
8755 | |
8756 | void pushCodeSynthesisContext(CodeSynthesisContext Ctx); |
8757 | void popCodeSynthesisContext(); |
8758 | |
8759 | /// Determine whether we are currently performing template instantiation. |
8760 | bool inTemplateInstantiation() const { |
8761 | return CodeSynthesisContexts.size() > NonInstantiationEntries; |
8762 | } |
8763 | |
8764 | void PrintContextStack() { |
8765 | if (!CodeSynthesisContexts.empty() && |
8766 | CodeSynthesisContexts.size() != LastEmittedCodeSynthesisContextDepth) { |
8767 | PrintInstantiationStack(); |
8768 | LastEmittedCodeSynthesisContextDepth = CodeSynthesisContexts.size(); |
8769 | } |
8770 | if (PragmaAttributeCurrentTargetDecl) |
8771 | PrintPragmaAttributeInstantiationPoint(); |
8772 | } |
8773 | void PrintInstantiationStack(); |
8774 | |
8775 | void PrintPragmaAttributeInstantiationPoint(); |
8776 | |
8777 | /// Determines whether we are currently in a context where |
8778 | /// template argument substitution failures are not considered |
8779 | /// errors. |
8780 | /// |
8781 | /// \returns An empty \c Optional if we're not in a SFINAE context. |
8782 | /// Otherwise, contains a pointer that, if non-NULL, contains the nearest |
8783 | /// template-deduction context object, which can be used to capture |
8784 | /// diagnostics that will be suppressed. |
8785 | Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; |
8786 | |
8787 | /// Determines whether we are currently in a context that |
8788 | /// is not evaluated as per C++ [expr] p5. |
8789 | bool isUnevaluatedContext() const { |
8790 | assert(!ExprEvalContexts.empty() &&((!ExprEvalContexts.empty() && "Must be in an expression evaluation context" ) ? static_cast<void> (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 8791, __PRETTY_FUNCTION__)) |
8791 | "Must be in an expression evaluation context")((!ExprEvalContexts.empty() && "Must be in an expression evaluation context" ) ? static_cast<void> (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 8791, __PRETTY_FUNCTION__)); |
8792 | return ExprEvalContexts.back().isUnevaluated(); |
8793 | } |
8794 | |
8795 | /// RAII class used to determine whether SFINAE has |
8796 | /// trapped any errors that occur during template argument |
8797 | /// deduction. |
8798 | class SFINAETrap { |
8799 | Sema &SemaRef; |
8800 | unsigned PrevSFINAEErrors; |
8801 | bool PrevInNonInstantiationSFINAEContext; |
8802 | bool PrevAccessCheckingSFINAE; |
8803 | bool PrevLastDiagnosticIgnored; |
8804 | |
8805 | public: |
8806 | explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) |
8807 | : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), |
8808 | PrevInNonInstantiationSFINAEContext( |
8809 | SemaRef.InNonInstantiationSFINAEContext), |
8810 | PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE), |
8811 | PrevLastDiagnosticIgnored( |
8812 | SemaRef.getDiagnostics().isLastDiagnosticIgnored()) |
8813 | { |
8814 | if (!SemaRef.isSFINAEContext()) |
8815 | SemaRef.InNonInstantiationSFINAEContext = true; |
8816 | SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; |
8817 | } |
8818 | |
8819 | ~SFINAETrap() { |
8820 | SemaRef.NumSFINAEErrors = PrevSFINAEErrors; |
8821 | SemaRef.InNonInstantiationSFINAEContext |
8822 | = PrevInNonInstantiationSFINAEContext; |
8823 | SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; |
8824 | SemaRef.getDiagnostics().setLastDiagnosticIgnored( |
8825 | PrevLastDiagnosticIgnored); |
8826 | } |
8827 | |
8828 | /// Determine whether any SFINAE errors have been trapped. |
8829 | bool hasErrorOccurred() const { |
8830 | return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; |
8831 | } |
8832 | }; |
8833 | |
8834 | /// RAII class used to indicate that we are performing provisional |
8835 | /// semantic analysis to determine the validity of a construct, so |
8836 | /// typo-correction and diagnostics in the immediate context (not within |
8837 | /// implicitly-instantiated templates) should be suppressed. |
8838 | class TentativeAnalysisScope { |
8839 | Sema &SemaRef; |
8840 | // FIXME: Using a SFINAETrap for this is a hack. |
8841 | SFINAETrap Trap; |
8842 | bool PrevDisableTypoCorrection; |
8843 | public: |
8844 | explicit TentativeAnalysisScope(Sema &SemaRef) |
8845 | : SemaRef(SemaRef), Trap(SemaRef, true), |
8846 | PrevDisableTypoCorrection(SemaRef.DisableTypoCorrection) { |
8847 | SemaRef.DisableTypoCorrection = true; |
8848 | } |
8849 | ~TentativeAnalysisScope() { |
8850 | SemaRef.DisableTypoCorrection = PrevDisableTypoCorrection; |
8851 | } |
8852 | }; |
8853 | |
8854 | /// The current instantiation scope used to store local |
8855 | /// variables. |
8856 | LocalInstantiationScope *CurrentInstantiationScope; |
8857 | |
8858 | /// Tracks whether we are in a context where typo correction is |
8859 | /// disabled. |
8860 | bool DisableTypoCorrection; |
8861 | |
8862 | /// The number of typos corrected by CorrectTypo. |
8863 | unsigned TyposCorrected; |
8864 | |
8865 | typedef llvm::SmallSet<SourceLocation, 2> SrcLocSet; |
8866 | typedef llvm::DenseMap<IdentifierInfo *, SrcLocSet> IdentifierSourceLocations; |
8867 | |
8868 | /// A cache containing identifiers for which typo correction failed and |
8869 | /// their locations, so that repeated attempts to correct an identifier in a |
8870 | /// given location are ignored if typo correction already failed for it. |
8871 | IdentifierSourceLocations TypoCorrectionFailures; |
8872 | |
8873 | /// Worker object for performing CFG-based warnings. |
8874 | sema::AnalysisBasedWarnings AnalysisWarnings; |
8875 | threadSafety::BeforeSet *ThreadSafetyDeclCache; |
8876 | |
8877 | /// An entity for which implicit template instantiation is required. |
8878 | /// |
8879 | /// The source location associated with the declaration is the first place in |
8880 | /// the source code where the declaration was "used". It is not necessarily |
8881 | /// the point of instantiation (which will be either before or after the |
8882 | /// namespace-scope declaration that triggered this implicit instantiation), |
8883 | /// However, it is the location that diagnostics should generally refer to, |
8884 | /// because users will need to know what code triggered the instantiation. |
8885 | typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; |
8886 | |
8887 | /// The queue of implicit template instantiations that are required |
8888 | /// but have not yet been performed. |
8889 | std::deque<PendingImplicitInstantiation> PendingInstantiations; |
8890 | |
8891 | /// Queue of implicit template instantiations that cannot be performed |
8892 | /// eagerly. |
8893 | SmallVector<PendingImplicitInstantiation, 1> LateParsedInstantiations; |
8894 | |
8895 | class GlobalEagerInstantiationScope { |
8896 | public: |
8897 | GlobalEagerInstantiationScope(Sema &S, bool Enabled) |
8898 | : S(S), Enabled(Enabled) { |
8899 | if (!Enabled) return; |
8900 | |
8901 | SavedPendingInstantiations.swap(S.PendingInstantiations); |
8902 | SavedVTableUses.swap(S.VTableUses); |
8903 | } |
8904 | |
8905 | void perform() { |
8906 | if (Enabled) { |
8907 | S.DefineUsedVTables(); |
8908 | S.PerformPendingInstantiations(); |
8909 | } |
8910 | } |
8911 | |
8912 | ~GlobalEagerInstantiationScope() { |
8913 | if (!Enabled) return; |
8914 | |
8915 | // Restore the set of pending vtables. |
8916 | assert(S.VTableUses.empty() &&((S.VTableUses.empty() && "VTableUses should be empty before it is discarded." ) ? static_cast<void> (0) : __assert_fail ("S.VTableUses.empty() && \"VTableUses should be empty before it is discarded.\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 8917, __PRETTY_FUNCTION__)) |
8917 | "VTableUses should be empty before it is discarded.")((S.VTableUses.empty() && "VTableUses should be empty before it is discarded." ) ? static_cast<void> (0) : __assert_fail ("S.VTableUses.empty() && \"VTableUses should be empty before it is discarded.\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 8917, __PRETTY_FUNCTION__)); |
8918 | S.VTableUses.swap(SavedVTableUses); |
8919 | |
8920 | // Restore the set of pending implicit instantiations. |
8921 | if (S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) { |
8922 | assert(S.PendingInstantiations.empty() &&((S.PendingInstantiations.empty() && "PendingInstantiations should be empty before it is discarded." ) ? static_cast<void> (0) : __assert_fail ("S.PendingInstantiations.empty() && \"PendingInstantiations should be empty before it is discarded.\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 8923, __PRETTY_FUNCTION__)) |
8923 | "PendingInstantiations should be empty before it is discarded.")((S.PendingInstantiations.empty() && "PendingInstantiations should be empty before it is discarded." ) ? static_cast<void> (0) : __assert_fail ("S.PendingInstantiations.empty() && \"PendingInstantiations should be empty before it is discarded.\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 8923, __PRETTY_FUNCTION__)); |
8924 | S.PendingInstantiations.swap(SavedPendingInstantiations); |
8925 | } else { |
8926 | // Template instantiations in the PCH may be delayed until the TU. |
8927 | S.PendingInstantiations.swap(SavedPendingInstantiations); |
8928 | S.PendingInstantiations.insert(S.PendingInstantiations.end(), |
8929 | SavedPendingInstantiations.begin(), |
8930 | SavedPendingInstantiations.end()); |
8931 | } |
8932 | } |
8933 | |
8934 | private: |
8935 | Sema &S; |
8936 | SmallVector<VTableUse, 16> SavedVTableUses; |
8937 | std::deque<PendingImplicitInstantiation> SavedPendingInstantiations; |
8938 | bool Enabled; |
8939 | }; |
8940 | |
8941 | /// The queue of implicit template instantiations that are required |
8942 | /// and must be performed within the current local scope. |
8943 | /// |
8944 | /// This queue is only used for member functions of local classes in |
8945 | /// templates, which must be instantiated in the same scope as their |
8946 | /// enclosing function, so that they can reference function-local |
8947 | /// types, static variables, enumerators, etc. |
8948 | std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; |
8949 | |
8950 | class LocalEagerInstantiationScope { |
8951 | public: |
8952 | LocalEagerInstantiationScope(Sema &S) : S(S) { |
8953 | SavedPendingLocalImplicitInstantiations.swap( |
8954 | S.PendingLocalImplicitInstantiations); |
8955 | } |
8956 | |
8957 | void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/true); } |
8958 | |
8959 | ~LocalEagerInstantiationScope() { |
8960 | assert(S.PendingLocalImplicitInstantiations.empty() &&((S.PendingLocalImplicitInstantiations.empty() && "there shouldn't be any pending local implicit instantiations" ) ? static_cast<void> (0) : __assert_fail ("S.PendingLocalImplicitInstantiations.empty() && \"there shouldn't be any pending local implicit instantiations\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 8961, __PRETTY_FUNCTION__)) |
8961 | "there shouldn't be any pending local implicit instantiations")((S.PendingLocalImplicitInstantiations.empty() && "there shouldn't be any pending local implicit instantiations" ) ? static_cast<void> (0) : __assert_fail ("S.PendingLocalImplicitInstantiations.empty() && \"there shouldn't be any pending local implicit instantiations\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 8961, __PRETTY_FUNCTION__)); |
8962 | SavedPendingLocalImplicitInstantiations.swap( |
8963 | S.PendingLocalImplicitInstantiations); |
8964 | } |
8965 | |
8966 | private: |
8967 | Sema &S; |
8968 | std::deque<PendingImplicitInstantiation> |
8969 | SavedPendingLocalImplicitInstantiations; |
8970 | }; |
8971 | |
8972 | /// A helper class for building up ExtParameterInfos. |
8973 | class ExtParameterInfoBuilder { |
8974 | SmallVector<FunctionProtoType::ExtParameterInfo, 16> Infos; |
8975 | bool HasInteresting = false; |
8976 | |
8977 | public: |
8978 | /// Set the ExtParameterInfo for the parameter at the given index, |
8979 | /// |
8980 | void set(unsigned index, FunctionProtoType::ExtParameterInfo info) { |
8981 | assert(Infos.size() <= index)((Infos.size() <= index) ? static_cast<void> (0) : __assert_fail ("Infos.size() <= index", "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 8981, __PRETTY_FUNCTION__)); |
8982 | Infos.resize(index); |
8983 | Infos.push_back(info); |
8984 | |
8985 | if (!HasInteresting) |
8986 | HasInteresting = (info != FunctionProtoType::ExtParameterInfo()); |
8987 | } |
8988 | |
8989 | /// Return a pointer (suitable for setting in an ExtProtoInfo) to the |
8990 | /// ExtParameterInfo array we've built up. |
8991 | const FunctionProtoType::ExtParameterInfo * |
8992 | getPointerOrNull(unsigned numParams) { |
8993 | if (!HasInteresting) return nullptr; |
8994 | Infos.resize(numParams); |
8995 | return Infos.data(); |
8996 | } |
8997 | }; |
8998 | |
8999 | void PerformPendingInstantiations(bool LocalOnly = false); |
9000 | |
9001 | TypeSourceInfo *SubstType(TypeSourceInfo *T, |
9002 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9003 | SourceLocation Loc, DeclarationName Entity, |
9004 | bool AllowDeducedTST = false); |
9005 | |
9006 | QualType SubstType(QualType T, |
9007 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9008 | SourceLocation Loc, DeclarationName Entity); |
9009 | |
9010 | TypeSourceInfo *SubstType(TypeLoc TL, |
9011 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9012 | SourceLocation Loc, DeclarationName Entity); |
9013 | |
9014 | TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T, |
9015 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9016 | SourceLocation Loc, |
9017 | DeclarationName Entity, |
9018 | CXXRecordDecl *ThisContext, |
9019 | Qualifiers ThisTypeQuals); |
9020 | void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, |
9021 | const MultiLevelTemplateArgumentList &Args); |
9022 | bool SubstExceptionSpec(SourceLocation Loc, |
9023 | FunctionProtoType::ExceptionSpecInfo &ESI, |
9024 | SmallVectorImpl<QualType> &ExceptionStorage, |
9025 | const MultiLevelTemplateArgumentList &Args); |
9026 | ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D, |
9027 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9028 | int indexAdjustment, |
9029 | Optional<unsigned> NumExpansions, |
9030 | bool ExpectParameterPack); |
9031 | bool SubstParmTypes(SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
9032 | const FunctionProtoType::ExtParameterInfo *ExtParamInfos, |
9033 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9034 | SmallVectorImpl<QualType> &ParamTypes, |
9035 | SmallVectorImpl<ParmVarDecl *> *OutParams, |
9036 | ExtParameterInfoBuilder &ParamInfos); |
9037 | ExprResult SubstExpr(Expr *E, |
9038 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9039 | |
9040 | /// Substitute the given template arguments into a list of |
9041 | /// expressions, expanding pack expansions if required. |
9042 | /// |
9043 | /// \param Exprs The list of expressions to substitute into. |
9044 | /// |
9045 | /// \param IsCall Whether this is some form of call, in which case |
9046 | /// default arguments will be dropped. |
9047 | /// |
9048 | /// \param TemplateArgs The set of template arguments to substitute. |
9049 | /// |
9050 | /// \param Outputs Will receive all of the substituted arguments. |
9051 | /// |
9052 | /// \returns true if an error occurred, false otherwise. |
9053 | bool SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall, |
9054 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9055 | SmallVectorImpl<Expr *> &Outputs); |
9056 | |
9057 | StmtResult SubstStmt(Stmt *S, |
9058 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9059 | |
9060 | TemplateParameterList * |
9061 | SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner, |
9062 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9063 | |
9064 | bool |
9065 | SubstTemplateArguments(ArrayRef<TemplateArgumentLoc> Args, |
9066 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9067 | TemplateArgumentListInfo &Outputs); |
9068 | |
9069 | |
9070 | Decl *SubstDecl(Decl *D, DeclContext *Owner, |
9071 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9072 | |
9073 | /// Substitute the name and return type of a defaulted 'operator<=>' to form |
9074 | /// an implicit 'operator=='. |
9075 | FunctionDecl *SubstSpaceshipAsEqualEqual(CXXRecordDecl *RD, |
9076 | FunctionDecl *Spaceship); |
9077 | |
9078 | ExprResult SubstInitializer(Expr *E, |
9079 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9080 | bool CXXDirectInit); |
9081 | |
9082 | bool |
9083 | SubstBaseSpecifiers(CXXRecordDecl *Instantiation, |
9084 | CXXRecordDecl *Pattern, |
9085 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9086 | |
9087 | bool |
9088 | InstantiateClass(SourceLocation PointOfInstantiation, |
9089 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
9090 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9091 | TemplateSpecializationKind TSK, |
9092 | bool Complain = true); |
9093 | |
9094 | bool InstantiateEnum(SourceLocation PointOfInstantiation, |
9095 | EnumDecl *Instantiation, EnumDecl *Pattern, |
9096 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9097 | TemplateSpecializationKind TSK); |
9098 | |
9099 | bool InstantiateInClassInitializer( |
9100 | SourceLocation PointOfInstantiation, FieldDecl *Instantiation, |
9101 | FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs); |
9102 | |
9103 | struct LateInstantiatedAttribute { |
9104 | const Attr *TmplAttr; |
9105 | LocalInstantiationScope *Scope; |
9106 | Decl *NewDecl; |
9107 | |
9108 | LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S, |
9109 | Decl *D) |
9110 | : TmplAttr(A), Scope(S), NewDecl(D) |
9111 | { } |
9112 | }; |
9113 | typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec; |
9114 | |
9115 | void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, |
9116 | const Decl *Pattern, Decl *Inst, |
9117 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
9118 | LocalInstantiationScope *OuterMostScope = nullptr); |
9119 | |
9120 | void |
9121 | InstantiateAttrsForDecl(const MultiLevelTemplateArgumentList &TemplateArgs, |
9122 | const Decl *Pattern, Decl *Inst, |
9123 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
9124 | LocalInstantiationScope *OuterMostScope = nullptr); |
9125 | |
9126 | bool usesPartialOrExplicitSpecialization( |
9127 | SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec); |
9128 | |
9129 | bool |
9130 | InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, |
9131 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
9132 | TemplateSpecializationKind TSK, |
9133 | bool Complain = true); |
9134 | |
9135 | void InstantiateClassMembers(SourceLocation PointOfInstantiation, |
9136 | CXXRecordDecl *Instantiation, |
9137 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9138 | TemplateSpecializationKind TSK); |
9139 | |
9140 | void InstantiateClassTemplateSpecializationMembers( |
9141 | SourceLocation PointOfInstantiation, |
9142 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
9143 | TemplateSpecializationKind TSK); |
9144 | |
9145 | NestedNameSpecifierLoc |
9146 | SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
9147 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9148 | |
9149 | DeclarationNameInfo |
9150 | SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
9151 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9152 | TemplateName |
9153 | SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, |
9154 | SourceLocation Loc, |
9155 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9156 | bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs, |
9157 | TemplateArgumentListInfo &Result, |
9158 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9159 | |
9160 | bool InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD, |
9161 | ParmVarDecl *Param); |
9162 | void InstantiateExceptionSpec(SourceLocation PointOfInstantiation, |
9163 | FunctionDecl *Function); |
9164 | bool CheckInstantiatedFunctionTemplateConstraints( |
9165 | SourceLocation PointOfInstantiation, FunctionDecl *Decl, |
9166 | ArrayRef<TemplateArgument> TemplateArgs, |
9167 | ConstraintSatisfaction &Satisfaction); |
9168 | FunctionDecl *InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD, |
9169 | const TemplateArgumentList *Args, |
9170 | SourceLocation Loc); |
9171 | void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, |
9172 | FunctionDecl *Function, |
9173 | bool Recursive = false, |
9174 | bool DefinitionRequired = false, |
9175 | bool AtEndOfTU = false); |
9176 | VarTemplateSpecializationDecl *BuildVarTemplateInstantiation( |
9177 | VarTemplateDecl *VarTemplate, VarDecl *FromVar, |
9178 | const TemplateArgumentList &TemplateArgList, |
9179 | const TemplateArgumentListInfo &TemplateArgsInfo, |
9180 | SmallVectorImpl<TemplateArgument> &Converted, |
9181 | SourceLocation PointOfInstantiation, void *InsertPos, |
9182 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
9183 | LocalInstantiationScope *StartingScope = nullptr); |
9184 | VarTemplateSpecializationDecl *CompleteVarTemplateSpecializationDecl( |
9185 | VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl, |
9186 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9187 | void |
9188 | BuildVariableInstantiation(VarDecl *NewVar, VarDecl *OldVar, |
9189 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9190 | LateInstantiatedAttrVec *LateAttrs, |
9191 | DeclContext *Owner, |
9192 | LocalInstantiationScope *StartingScope, |
9193 | bool InstantiatingVarTemplate = false, |
9194 | VarTemplateSpecializationDecl *PrevVTSD = nullptr); |
9195 | |
9196 | void InstantiateVariableInitializer( |
9197 | VarDecl *Var, VarDecl *OldVar, |
9198 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9199 | void InstantiateVariableDefinition(SourceLocation PointOfInstantiation, |
9200 | VarDecl *Var, bool Recursive = false, |
9201 | bool DefinitionRequired = false, |
9202 | bool AtEndOfTU = false); |
9203 | |
9204 | void InstantiateMemInitializers(CXXConstructorDecl *New, |
9205 | const CXXConstructorDecl *Tmpl, |
9206 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9207 | |
9208 | NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, |
9209 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9210 | bool FindingInstantiatedContext = false); |
9211 | DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, |
9212 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9213 | |
9214 | // Objective-C declarations. |
9215 | enum ObjCContainerKind { |
9216 | OCK_None = -1, |
9217 | OCK_Interface = 0, |
9218 | OCK_Protocol, |
9219 | OCK_Category, |
9220 | OCK_ClassExtension, |
9221 | OCK_Implementation, |
9222 | OCK_CategoryImplementation |
9223 | }; |
9224 | ObjCContainerKind getObjCContainerKind() const; |
9225 | |
9226 | DeclResult actOnObjCTypeParam(Scope *S, |
9227 | ObjCTypeParamVariance variance, |
9228 | SourceLocation varianceLoc, |
9229 | unsigned index, |
9230 | IdentifierInfo *paramName, |
9231 | SourceLocation paramLoc, |
9232 | SourceLocation colonLoc, |
9233 | ParsedType typeBound); |
9234 | |
9235 | ObjCTypeParamList *actOnObjCTypeParamList(Scope *S, SourceLocation lAngleLoc, |
9236 | ArrayRef<Decl *> typeParams, |
9237 | SourceLocation rAngleLoc); |
9238 | void popObjCTypeParamList(Scope *S, ObjCTypeParamList *typeParamList); |
9239 | |
9240 | Decl *ActOnStartClassInterface( |
9241 | Scope *S, SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, |
9242 | SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, |
9243 | IdentifierInfo *SuperName, SourceLocation SuperLoc, |
9244 | ArrayRef<ParsedType> SuperTypeArgs, SourceRange SuperTypeArgsRange, |
9245 | Decl *const *ProtoRefs, unsigned NumProtoRefs, |
9246 | const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, |
9247 | const ParsedAttributesView &AttrList); |
9248 | |
9249 | void ActOnSuperClassOfClassInterface(Scope *S, |
9250 | SourceLocation AtInterfaceLoc, |
9251 | ObjCInterfaceDecl *IDecl, |
9252 | IdentifierInfo *ClassName, |
9253 | SourceLocation ClassLoc, |
9254 | IdentifierInfo *SuperName, |
9255 | SourceLocation SuperLoc, |
9256 | ArrayRef<ParsedType> SuperTypeArgs, |
9257 | SourceRange SuperTypeArgsRange); |
9258 | |
9259 | void ActOnTypedefedProtocols(SmallVectorImpl<Decl *> &ProtocolRefs, |
9260 | SmallVectorImpl<SourceLocation> &ProtocolLocs, |
9261 | IdentifierInfo *SuperName, |
9262 | SourceLocation SuperLoc); |
9263 | |
9264 | Decl *ActOnCompatibilityAlias( |
9265 | SourceLocation AtCompatibilityAliasLoc, |
9266 | IdentifierInfo *AliasName, SourceLocation AliasLocation, |
9267 | IdentifierInfo *ClassName, SourceLocation ClassLocation); |
9268 | |
9269 | bool CheckForwardProtocolDeclarationForCircularDependency( |
9270 | IdentifierInfo *PName, |
9271 | SourceLocation &PLoc, SourceLocation PrevLoc, |
9272 | const ObjCList<ObjCProtocolDecl> &PList); |
9273 | |
9274 | Decl *ActOnStartProtocolInterface( |
9275 | SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName, |
9276 | SourceLocation ProtocolLoc, Decl *const *ProtoRefNames, |
9277 | unsigned NumProtoRefs, const SourceLocation *ProtoLocs, |
9278 | SourceLocation EndProtoLoc, const ParsedAttributesView &AttrList); |
9279 | |
9280 | Decl *ActOnStartCategoryInterface( |
9281 | SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, |
9282 | SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, |
9283 | IdentifierInfo *CategoryName, SourceLocation CategoryLoc, |
9284 | Decl *const *ProtoRefs, unsigned NumProtoRefs, |
9285 | const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, |
9286 | const ParsedAttributesView &AttrList); |
9287 | |
9288 | Decl *ActOnStartClassImplementation(SourceLocation AtClassImplLoc, |
9289 | IdentifierInfo *ClassName, |
9290 | SourceLocation ClassLoc, |
9291 | IdentifierInfo *SuperClassname, |
9292 | SourceLocation SuperClassLoc, |
9293 | const ParsedAttributesView &AttrList); |
9294 | |
9295 | Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc, |
9296 | IdentifierInfo *ClassName, |
9297 | SourceLocation ClassLoc, |
9298 | IdentifierInfo *CatName, |
9299 | SourceLocation CatLoc, |
9300 | const ParsedAttributesView &AttrList); |
9301 | |
9302 | DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, |
9303 | ArrayRef<Decl *> Decls); |
9304 | |
9305 | DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, |
9306 | IdentifierInfo **IdentList, |
9307 | SourceLocation *IdentLocs, |
9308 | ArrayRef<ObjCTypeParamList *> TypeParamLists, |
9309 | unsigned NumElts); |
9310 | |
9311 | DeclGroupPtrTy |
9312 | ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, |
9313 | ArrayRef<IdentifierLocPair> IdentList, |
9314 | const ParsedAttributesView &attrList); |
9315 | |
9316 | void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer, |
9317 | ArrayRef<IdentifierLocPair> ProtocolId, |
9318 | SmallVectorImpl<Decl *> &Protocols); |
9319 | |
9320 | void DiagnoseTypeArgsAndProtocols(IdentifierInfo *ProtocolId, |
9321 | SourceLocation ProtocolLoc, |
9322 | IdentifierInfo *TypeArgId, |
9323 | SourceLocation TypeArgLoc, |
9324 | bool SelectProtocolFirst = false); |
9325 | |
9326 | /// Given a list of identifiers (and their locations), resolve the |
9327 | /// names to either Objective-C protocol qualifiers or type |
9328 | /// arguments, as appropriate. |
9329 | void actOnObjCTypeArgsOrProtocolQualifiers( |
9330 | Scope *S, |
9331 | ParsedType baseType, |
9332 | SourceLocation lAngleLoc, |
9333 | ArrayRef<IdentifierInfo *> identifiers, |
9334 | ArrayRef<SourceLocation> identifierLocs, |
9335 | SourceLocation rAngleLoc, |
9336 | SourceLocation &typeArgsLAngleLoc, |
9337 | SmallVectorImpl<ParsedType> &typeArgs, |
9338 | SourceLocation &typeArgsRAngleLoc, |
9339 | SourceLocation &protocolLAngleLoc, |
9340 | SmallVectorImpl<Decl *> &protocols, |
9341 | SourceLocation &protocolRAngleLoc, |
9342 | bool warnOnIncompleteProtocols); |
9343 | |
9344 | /// Build a an Objective-C protocol-qualified 'id' type where no |
9345 | /// base type was specified. |
9346 | TypeResult actOnObjCProtocolQualifierType( |
9347 | SourceLocation lAngleLoc, |
9348 | ArrayRef<Decl *> protocols, |
9349 | ArrayRef<SourceLocation> protocolLocs, |
9350 | SourceLocation rAngleLoc); |
9351 | |
9352 | /// Build a specialized and/or protocol-qualified Objective-C type. |
9353 | TypeResult actOnObjCTypeArgsAndProtocolQualifiers( |
9354 | Scope *S, |
9355 | SourceLocation Loc, |
9356 | ParsedType BaseType, |
9357 | SourceLocation TypeArgsLAngleLoc, |
9358 | ArrayRef<ParsedType> TypeArgs, |
9359 | SourceLocation TypeArgsRAngleLoc, |
9360 | SourceLocation ProtocolLAngleLoc, |
9361 | ArrayRef<Decl *> Protocols, |
9362 | ArrayRef<SourceLocation> ProtocolLocs, |
9363 | SourceLocation ProtocolRAngleLoc); |
9364 | |
9365 | /// Build an Objective-C type parameter type. |
9366 | QualType BuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, |
9367 | SourceLocation ProtocolLAngleLoc, |
9368 | ArrayRef<ObjCProtocolDecl *> Protocols, |
9369 | ArrayRef<SourceLocation> ProtocolLocs, |
9370 | SourceLocation ProtocolRAngleLoc, |
9371 | bool FailOnError = false); |
9372 | |
9373 | /// Build an Objective-C object pointer type. |
9374 | QualType BuildObjCObjectType(QualType BaseType, |
9375 | SourceLocation Loc, |
9376 | SourceLocation TypeArgsLAngleLoc, |
9377 | ArrayRef<TypeSourceInfo *> TypeArgs, |
9378 | SourceLocation TypeArgsRAngleLoc, |
9379 | SourceLocation ProtocolLAngleLoc, |
9380 | ArrayRef<ObjCProtocolDecl *> Protocols, |
9381 | ArrayRef<SourceLocation> ProtocolLocs, |
9382 | SourceLocation ProtocolRAngleLoc, |
9383 | bool FailOnError = false); |
9384 | |
9385 | /// Ensure attributes are consistent with type. |
9386 | /// \param [in, out] Attributes The attributes to check; they will |
9387 | /// be modified to be consistent with \p PropertyTy. |
9388 | void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, |
9389 | SourceLocation Loc, |
9390 | unsigned &Attributes, |
9391 | bool propertyInPrimaryClass); |
9392 | |
9393 | /// Process the specified property declaration and create decls for the |
9394 | /// setters and getters as needed. |
9395 | /// \param property The property declaration being processed |
9396 | void ProcessPropertyDecl(ObjCPropertyDecl *property); |
9397 | |
9398 | |
9399 | void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, |
9400 | ObjCPropertyDecl *SuperProperty, |
9401 | const IdentifierInfo *Name, |
9402 | bool OverridingProtocolProperty); |
9403 | |
9404 | void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, |
9405 | ObjCInterfaceDecl *ID); |
9406 | |
9407 | Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd, |
9408 | ArrayRef<Decl *> allMethods = None, |
9409 | ArrayRef<DeclGroupPtrTy> allTUVars = None); |
9410 | |
9411 | Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, |
9412 | SourceLocation LParenLoc, |
9413 | FieldDeclarator &FD, ObjCDeclSpec &ODS, |
9414 | Selector GetterSel, Selector SetterSel, |
9415 | tok::ObjCKeywordKind MethodImplKind, |
9416 | DeclContext *lexicalDC = nullptr); |
9417 | |
9418 | Decl *ActOnPropertyImplDecl(Scope *S, |
9419 | SourceLocation AtLoc, |
9420 | SourceLocation PropertyLoc, |
9421 | bool ImplKind, |
9422 | IdentifierInfo *PropertyId, |
9423 | IdentifierInfo *PropertyIvar, |
9424 | SourceLocation PropertyIvarLoc, |
9425 | ObjCPropertyQueryKind QueryKind); |
9426 | |
9427 | enum ObjCSpecialMethodKind { |
9428 | OSMK_None, |
9429 | OSMK_Alloc, |
9430 | OSMK_New, |
9431 | OSMK_Copy, |
9432 | OSMK_RetainingInit, |
9433 | OSMK_NonRetainingInit |
9434 | }; |
9435 | |
9436 | struct ObjCArgInfo { |
9437 | IdentifierInfo *Name; |
9438 | SourceLocation NameLoc; |
9439 | // The Type is null if no type was specified, and the DeclSpec is invalid |
9440 | // in this case. |
9441 | ParsedType Type; |
9442 | ObjCDeclSpec DeclSpec; |
9443 | |
9444 | /// ArgAttrs - Attribute list for this argument. |
9445 | ParsedAttributesView ArgAttrs; |
9446 | }; |
9447 | |
9448 | Decl *ActOnMethodDeclaration( |
9449 | Scope *S, |
9450 | SourceLocation BeginLoc, // location of the + or -. |
9451 | SourceLocation EndLoc, // location of the ; or {. |
9452 | tok::TokenKind MethodType, ObjCDeclSpec &ReturnQT, ParsedType ReturnType, |
9453 | ArrayRef<SourceLocation> SelectorLocs, Selector Sel, |
9454 | // optional arguments. The number of types/arguments is obtained |
9455 | // from the Sel.getNumArgs(). |
9456 | ObjCArgInfo *ArgInfo, DeclaratorChunk::ParamInfo *CParamInfo, |
9457 | unsigned CNumArgs, // c-style args |
9458 | const ParsedAttributesView &AttrList, tok::ObjCKeywordKind MethodImplKind, |
9459 | bool isVariadic, bool MethodDefinition); |
9460 | |
9461 | ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, |
9462 | const ObjCObjectPointerType *OPT, |
9463 | bool IsInstance); |
9464 | ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty, |
9465 | bool IsInstance); |
9466 | |
9467 | bool CheckARCMethodDecl(ObjCMethodDecl *method); |
9468 | bool inferObjCARCLifetime(ValueDecl *decl); |
9469 | |
9470 | void deduceOpenCLAddressSpace(ValueDecl *decl); |
9471 | |
9472 | ExprResult |
9473 | HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, |
9474 | Expr *BaseExpr, |
9475 | SourceLocation OpLoc, |
9476 | DeclarationName MemberName, |
9477 | SourceLocation MemberLoc, |
9478 | SourceLocation SuperLoc, QualType SuperType, |
9479 | bool Super); |
9480 | |
9481 | ExprResult |
9482 | ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, |
9483 | IdentifierInfo &propertyName, |
9484 | SourceLocation receiverNameLoc, |
9485 | SourceLocation propertyNameLoc); |
9486 | |
9487 | ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc); |
9488 | |
9489 | /// Describes the kind of message expression indicated by a message |
9490 | /// send that starts with an identifier. |
9491 | enum ObjCMessageKind { |
9492 | /// The message is sent to 'super'. |
9493 | ObjCSuperMessage, |
9494 | /// The message is an instance message. |
9495 | ObjCInstanceMessage, |
9496 | /// The message is a class message, and the identifier is a type |
9497 | /// name. |
9498 | ObjCClassMessage |
9499 | }; |
9500 | |
9501 | ObjCMessageKind getObjCMessageKind(Scope *S, |
9502 | IdentifierInfo *Name, |
9503 | SourceLocation NameLoc, |
9504 | bool IsSuper, |
9505 | bool HasTrailingDot, |
9506 | ParsedType &ReceiverType); |
9507 | |
9508 | ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, |
9509 | Selector Sel, |
9510 | SourceLocation LBracLoc, |
9511 | ArrayRef<SourceLocation> SelectorLocs, |
9512 | SourceLocation RBracLoc, |
9513 | MultiExprArg Args); |
9514 | |
9515 | ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, |
9516 | QualType ReceiverType, |
9517 | SourceLocation SuperLoc, |
9518 | Selector Sel, |
9519 | ObjCMethodDecl *Method, |
9520 | SourceLocation LBracLoc, |
9521 | ArrayRef<SourceLocation> SelectorLocs, |
9522 | SourceLocation RBracLoc, |
9523 | MultiExprArg Args, |
9524 | bool isImplicit = false); |
9525 | |
9526 | ExprResult BuildClassMessageImplicit(QualType ReceiverType, |
9527 | bool isSuperReceiver, |
9528 | SourceLocation Loc, |
9529 | Selector Sel, |
9530 | ObjCMethodDecl *Method, |
9531 | MultiExprArg Args); |
9532 | |
9533 | ExprResult ActOnClassMessage(Scope *S, |
9534 | ParsedType Receiver, |
9535 | Selector Sel, |
9536 | SourceLocation LBracLoc, |
9537 | ArrayRef<SourceLocation> SelectorLocs, |
9538 | SourceLocation RBracLoc, |
9539 | MultiExprArg Args); |
9540 | |
9541 | ExprResult BuildInstanceMessage(Expr *Receiver, |
9542 | QualType ReceiverType, |
9543 | SourceLocation SuperLoc, |
9544 | Selector Sel, |
9545 | ObjCMethodDecl *Method, |
9546 | SourceLocation LBracLoc, |
9547 | ArrayRef<SourceLocation> SelectorLocs, |
9548 | SourceLocation RBracLoc, |
9549 | MultiExprArg Args, |
9550 | bool isImplicit = false); |
9551 | |
9552 | ExprResult BuildInstanceMessageImplicit(Expr *Receiver, |
9553 | QualType ReceiverType, |
9554 | SourceLocation Loc, |
9555 | Selector Sel, |
9556 | ObjCMethodDecl *Method, |
9557 | MultiExprArg Args); |
9558 | |
9559 | ExprResult ActOnInstanceMessage(Scope *S, |
9560 | Expr *Receiver, |
9561 | Selector Sel, |
9562 | SourceLocation LBracLoc, |
9563 | ArrayRef<SourceLocation> SelectorLocs, |
9564 | SourceLocation RBracLoc, |
9565 | MultiExprArg Args); |
9566 | |
9567 | ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, |
9568 | ObjCBridgeCastKind Kind, |
9569 | SourceLocation BridgeKeywordLoc, |
9570 | TypeSourceInfo *TSInfo, |
9571 | Expr *SubExpr); |
9572 | |
9573 | ExprResult ActOnObjCBridgedCast(Scope *S, |
9574 | SourceLocation LParenLoc, |
9575 | ObjCBridgeCastKind Kind, |
9576 | SourceLocation BridgeKeywordLoc, |
9577 | ParsedType Type, |
9578 | SourceLocation RParenLoc, |
9579 | Expr *SubExpr); |
9580 | |
9581 | void CheckTollFreeBridgeCast(QualType castType, Expr *castExpr); |
9582 | |
9583 | void CheckObjCBridgeRelatedCast(QualType castType, Expr *castExpr); |
9584 | |
9585 | bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr, |
9586 | CastKind &Kind); |
9587 | |
9588 | bool checkObjCBridgeRelatedComponents(SourceLocation Loc, |
9589 | QualType DestType, QualType SrcType, |
9590 | ObjCInterfaceDecl *&RelatedClass, |
9591 | ObjCMethodDecl *&ClassMethod, |
9592 | ObjCMethodDecl *&InstanceMethod, |
9593 | TypedefNameDecl *&TDNDecl, |
9594 | bool CfToNs, bool Diagnose = true); |
9595 | |
9596 | bool CheckObjCBridgeRelatedConversions(SourceLocation Loc, |
9597 | QualType DestType, QualType SrcType, |
9598 | Expr *&SrcExpr, bool Diagnose = true); |
9599 | |
9600 | bool CheckConversionToObjCLiteral(QualType DstType, Expr *&SrcExpr, |
9601 | bool Diagnose = true); |
9602 | |
9603 | bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); |
9604 | |
9605 | /// Check whether the given new method is a valid override of the |
9606 | /// given overridden method, and set any properties that should be inherited. |
9607 | void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, |
9608 | const ObjCMethodDecl *Overridden); |
9609 | |
9610 | /// Describes the compatibility of a result type with its method. |
9611 | enum ResultTypeCompatibilityKind { |
9612 | RTC_Compatible, |
9613 | RTC_Incompatible, |
9614 | RTC_Unknown |
9615 | }; |
9616 | |
9617 | void CheckObjCMethodDirectOverrides(ObjCMethodDecl *method, |
9618 | ObjCMethodDecl *overridden); |
9619 | |
9620 | void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod, |
9621 | ObjCInterfaceDecl *CurrentClass, |
9622 | ResultTypeCompatibilityKind RTC); |
9623 | |
9624 | enum PragmaOptionsAlignKind { |
9625 | POAK_Native, // #pragma options align=native |
9626 | POAK_Natural, // #pragma options align=natural |
9627 | POAK_Packed, // #pragma options align=packed |
9628 | POAK_Power, // #pragma options align=power |
9629 | POAK_Mac68k, // #pragma options align=mac68k |
9630 | POAK_Reset // #pragma options align=reset |
9631 | }; |
9632 | |
9633 | /// ActOnPragmaClangSection - Called on well formed \#pragma clang section |
9634 | void ActOnPragmaClangSection(SourceLocation PragmaLoc, |
9635 | PragmaClangSectionAction Action, |
9636 | PragmaClangSectionKind SecKind, StringRef SecName); |
9637 | |
9638 | /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align. |
9639 | void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, |
9640 | SourceLocation PragmaLoc); |
9641 | |
9642 | /// ActOnPragmaPack - Called on well formed \#pragma pack(...). |
9643 | void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, |
9644 | StringRef SlotLabel, Expr *Alignment); |
9645 | |
9646 | enum class PragmaPackDiagnoseKind { |
9647 | NonDefaultStateAtInclude, |
9648 | ChangedStateAtExit |
9649 | }; |
9650 | |
9651 | void DiagnoseNonDefaultPragmaPack(PragmaPackDiagnoseKind Kind, |
9652 | SourceLocation IncludeLoc); |
9653 | void DiagnoseUnterminatedPragmaPack(); |
9654 | |
9655 | /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off]. |
9656 | void ActOnPragmaMSStruct(PragmaMSStructKind Kind); |
9657 | |
9658 | /// ActOnPragmaMSComment - Called on well formed |
9659 | /// \#pragma comment(kind, "arg"). |
9660 | void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind, |
9661 | StringRef Arg); |
9662 | |
9663 | /// ActOnPragmaMSPointersToMembers - called on well formed \#pragma |
9664 | /// pointers_to_members(representation method[, general purpose |
9665 | /// representation]). |
9666 | void ActOnPragmaMSPointersToMembers( |
9667 | LangOptions::PragmaMSPointersToMembersKind Kind, |
9668 | SourceLocation PragmaLoc); |
9669 | |
9670 | /// Called on well formed \#pragma vtordisp(). |
9671 | void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, |
9672 | SourceLocation PragmaLoc, |
9673 | MSVtorDispMode Value); |
9674 | |
9675 | enum PragmaSectionKind { |
9676 | PSK_DataSeg, |
9677 | PSK_BSSSeg, |
9678 | PSK_ConstSeg, |
9679 | PSK_CodeSeg, |
9680 | }; |
9681 | |
9682 | bool UnifySection(StringRef SectionName, |
9683 | int SectionFlags, |
9684 | DeclaratorDecl *TheDecl); |
9685 | bool UnifySection(StringRef SectionName, |
9686 | int SectionFlags, |
9687 | SourceLocation PragmaSectionLocation); |
9688 | |
9689 | /// Called on well formed \#pragma bss_seg/data_seg/const_seg/code_seg. |
9690 | void ActOnPragmaMSSeg(SourceLocation PragmaLocation, |
9691 | PragmaMsStackAction Action, |
9692 | llvm::StringRef StackSlotLabel, |
9693 | StringLiteral *SegmentName, |
9694 | llvm::StringRef PragmaName); |
9695 | |
9696 | /// Called on well formed \#pragma section(). |
9697 | void ActOnPragmaMSSection(SourceLocation PragmaLocation, |
9698 | int SectionFlags, StringLiteral *SegmentName); |
9699 | |
9700 | /// Called on well-formed \#pragma init_seg(). |
9701 | void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, |
9702 | StringLiteral *SegmentName); |
9703 | |
9704 | /// Called on #pragma clang __debug dump II |
9705 | void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II); |
9706 | |
9707 | /// ActOnPragmaDetectMismatch - Call on well-formed \#pragma detect_mismatch |
9708 | void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, |
9709 | StringRef Value); |
9710 | |
9711 | /// Are precise floating point semantics currently enabled? |
9712 | bool isPreciseFPEnabled() { |
9713 | return !CurFPFeatures.getAllowFPReassociate() && |
9714 | !CurFPFeatures.getNoSignedZero() && |
9715 | !CurFPFeatures.getAllowReciprocal() && |
9716 | !CurFPFeatures.getAllowApproxFunc(); |
9717 | } |
9718 | |
9719 | /// ActOnPragmaFloatControl - Call on well-formed \#pragma float_control |
9720 | void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, |
9721 | PragmaFloatControlKind Value); |
9722 | |
9723 | /// ActOnPragmaUnused - Called on well-formed '\#pragma unused'. |
9724 | void ActOnPragmaUnused(const Token &Identifier, |
9725 | Scope *curScope, |
9726 | SourceLocation PragmaLoc); |
9727 | |
9728 | /// ActOnPragmaVisibility - Called on well formed \#pragma GCC visibility... . |
9729 | void ActOnPragmaVisibility(const IdentifierInfo* VisType, |
9730 | SourceLocation PragmaLoc); |
9731 | |
9732 | NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II, |
9733 | SourceLocation Loc); |
9734 | void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W); |
9735 | |
9736 | /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident. |
9737 | void ActOnPragmaWeakID(IdentifierInfo* WeakName, |
9738 | SourceLocation PragmaLoc, |
9739 | SourceLocation WeakNameLoc); |
9740 | |
9741 | /// ActOnPragmaRedefineExtname - Called on well formed |
9742 | /// \#pragma redefine_extname oldname newname. |
9743 | void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName, |
9744 | IdentifierInfo* AliasName, |
9745 | SourceLocation PragmaLoc, |
9746 | SourceLocation WeakNameLoc, |
9747 | SourceLocation AliasNameLoc); |
9748 | |
9749 | /// ActOnPragmaWeakAlias - Called on well formed \#pragma weak ident = ident. |
9750 | void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, |
9751 | IdentifierInfo* AliasName, |
9752 | SourceLocation PragmaLoc, |
9753 | SourceLocation WeakNameLoc, |
9754 | SourceLocation AliasNameLoc); |
9755 | |
9756 | /// ActOnPragmaFPContract - Called on well formed |
9757 | /// \#pragma {STDC,OPENCL} FP_CONTRACT and |
9758 | /// \#pragma clang fp contract |
9759 | void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC); |
9760 | |
9761 | /// Called on well formed |
9762 | /// \#pragma clang fp reassociate |
9763 | void ActOnPragmaFPReassociate(SourceLocation Loc, bool IsEnabled); |
9764 | |
9765 | /// ActOnPragmaFenvAccess - Called on well formed |
9766 | /// \#pragma STDC FENV_ACCESS |
9767 | void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled); |
9768 | |
9769 | /// Called to set constant rounding mode for floating point operations. |
9770 | void setRoundingMode(SourceLocation Loc, llvm::RoundingMode); |
9771 | |
9772 | /// Called to set exception behavior for floating point operations. |
9773 | void setExceptionMode(SourceLocation Loc, LangOptions::FPExceptionModeKind); |
9774 | |
9775 | /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to |
9776 | /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'. |
9777 | void AddAlignmentAttributesForRecord(RecordDecl *RD); |
9778 | |
9779 | /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. |
9780 | void AddMsStructLayoutForRecord(RecordDecl *RD); |
9781 | |
9782 | /// FreePackedContext - Deallocate and null out PackContext. |
9783 | void FreePackedContext(); |
9784 | |
9785 | /// PushNamespaceVisibilityAttr - Note that we've entered a |
9786 | /// namespace with a visibility attribute. |
9787 | void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, |
9788 | SourceLocation Loc); |
9789 | |
9790 | /// AddPushedVisibilityAttribute - If '\#pragma GCC visibility' was used, |
9791 | /// add an appropriate visibility attribute. |
9792 | void AddPushedVisibilityAttribute(Decl *RD); |
9793 | |
9794 | /// PopPragmaVisibility - Pop the top element of the visibility stack; used |
9795 | /// for '\#pragma GCC visibility' and visibility attributes on namespaces. |
9796 | void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc); |
9797 | |
9798 | /// FreeVisContext - Deallocate and null out VisContext. |
9799 | void FreeVisContext(); |
9800 | |
9801 | /// AddCFAuditedAttribute - Check whether we're currently within |
9802 | /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding |
9803 | /// the appropriate attribute. |
9804 | void AddCFAuditedAttribute(Decl *D); |
9805 | |
9806 | void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, |
9807 | SourceLocation PragmaLoc, |
9808 | attr::ParsedSubjectMatchRuleSet Rules); |
9809 | void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, |
9810 | const IdentifierInfo *Namespace); |
9811 | |
9812 | /// Called on well-formed '\#pragma clang attribute pop'. |
9813 | void ActOnPragmaAttributePop(SourceLocation PragmaLoc, |
9814 | const IdentifierInfo *Namespace); |
9815 | |
9816 | /// Adds the attributes that have been specified using the |
9817 | /// '\#pragma clang attribute push' directives to the given declaration. |
9818 | void AddPragmaAttributes(Scope *S, Decl *D); |
9819 | |
9820 | void DiagnoseUnterminatedPragmaAttribute(); |
9821 | |
9822 | /// Called on well formed \#pragma clang optimize. |
9823 | void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc); |
9824 | |
9825 | /// Get the location for the currently active "\#pragma clang optimize |
9826 | /// off". If this location is invalid, then the state of the pragma is "on". |
9827 | SourceLocation getOptimizeOffPragmaLocation() const { |
9828 | return OptimizeOffPragmaLocation; |
9829 | } |
9830 | |
9831 | /// Only called on function definitions; if there is a pragma in scope |
9832 | /// with the effect of a range-based optnone, consider marking the function |
9833 | /// with attribute optnone. |
9834 | void AddRangeBasedOptnone(FunctionDecl *FD); |
9835 | |
9836 | /// Adds the 'optnone' attribute to the function declaration if there |
9837 | /// are no conflicts; Loc represents the location causing the 'optnone' |
9838 | /// attribute to be added (usually because of a pragma). |
9839 | void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc); |
9840 | |
9841 | /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. |
9842 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
9843 | bool IsPackExpansion); |
9844 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, TypeSourceInfo *T, |
9845 | bool IsPackExpansion); |
9846 | |
9847 | /// AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular |
9848 | /// declaration. |
9849 | void AddAssumeAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
9850 | Expr *OE); |
9851 | |
9852 | /// AddAllocAlignAttr - Adds an alloc_align attribute to a particular |
9853 | /// declaration. |
9854 | void AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI, |
9855 | Expr *ParamExpr); |
9856 | |
9857 | /// AddAlignValueAttr - Adds an align_value attribute to a particular |
9858 | /// declaration. |
9859 | void AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E); |
9860 | |
9861 | /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular |
9862 | /// declaration. |
9863 | void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI, |
9864 | Expr *MaxThreads, Expr *MinBlocks); |
9865 | |
9866 | /// AddModeAttr - Adds a mode attribute to a particular declaration. |
9867 | void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Name, |
9868 | bool InInstantiation = false); |
9869 | |
9870 | void AddParameterABIAttr(Decl *D, const AttributeCommonInfo &CI, |
9871 | ParameterABI ABI); |
9872 | |
9873 | enum class RetainOwnershipKind {NS, CF, OS}; |
9874 | void AddXConsumedAttr(Decl *D, const AttributeCommonInfo &CI, |
9875 | RetainOwnershipKind K, bool IsTemplateInstantiation); |
9876 | |
9877 | /// addAMDGPUFlatWorkGroupSizeAttr - Adds an amdgpu_flat_work_group_size |
9878 | /// attribute to a particular declaration. |
9879 | void addAMDGPUFlatWorkGroupSizeAttr(Decl *D, const AttributeCommonInfo &CI, |
9880 | Expr *Min, Expr *Max); |
9881 | |
9882 | /// addAMDGPUWavePersEUAttr - Adds an amdgpu_waves_per_eu attribute to a |
9883 | /// particular declaration. |
9884 | void addAMDGPUWavesPerEUAttr(Decl *D, const AttributeCommonInfo &CI, |
9885 | Expr *Min, Expr *Max); |
9886 | |
9887 | bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type); |
9888 | |
9889 | //===--------------------------------------------------------------------===// |
9890 | // C++ Coroutines TS |
9891 | // |
9892 | bool ActOnCoroutineBodyStart(Scope *S, SourceLocation KwLoc, |
9893 | StringRef Keyword); |
9894 | ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
9895 | ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
9896 | StmtResult ActOnCoreturnStmt(Scope *S, SourceLocation KwLoc, Expr *E); |
9897 | |
9898 | ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *E, |
9899 | bool IsImplicit = false); |
9900 | ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *E, |
9901 | UnresolvedLookupExpr* Lookup); |
9902 | ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E); |
9903 | StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E, |
9904 | bool IsImplicit = false); |
9905 | StmtResult BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs); |
9906 | bool buildCoroutineParameterMoves(SourceLocation Loc); |
9907 | VarDecl *buildCoroutinePromise(SourceLocation Loc); |
9908 | void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body); |
9909 | ClassTemplateDecl *lookupCoroutineTraits(SourceLocation KwLoc, |
9910 | SourceLocation FuncLoc); |
9911 | /// Check that the expression co_await promise.final_suspend() shall not be |
9912 | /// potentially-throwing. |
9913 | bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend); |
9914 | |
9915 | //===--------------------------------------------------------------------===// |
9916 | // OpenCL extensions. |
9917 | // |
9918 | private: |
9919 | std::string CurrOpenCLExtension; |
9920 | /// Extensions required by an OpenCL type. |
9921 | llvm::DenseMap<const Type*, std::set<std::string>> OpenCLTypeExtMap; |
9922 | /// Extensions required by an OpenCL declaration. |
9923 | llvm::DenseMap<const Decl*, std::set<std::string>> OpenCLDeclExtMap; |
9924 | public: |
9925 | llvm::StringRef getCurrentOpenCLExtension() const { |
9926 | return CurrOpenCLExtension; |
9927 | } |
9928 | |
9929 | /// Check if a function declaration \p FD associates with any |
9930 | /// extensions present in OpenCLDeclExtMap and if so return the |
9931 | /// extension(s) name(s). |
9932 | std::string getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD); |
9933 | |
9934 | /// Check if a function type \p FT associates with any |
9935 | /// extensions present in OpenCLTypeExtMap and if so return the |
9936 | /// extension(s) name(s). |
9937 | std::string getOpenCLExtensionsFromTypeExtMap(FunctionType *FT); |
9938 | |
9939 | /// Find an extension in an appropriate extension map and return its name |
9940 | template<typename T, typename MapT> |
9941 | std::string getOpenCLExtensionsFromExtMap(T* FT, MapT &Map); |
9942 | |
9943 | void setCurrentOpenCLExtension(llvm::StringRef Ext) { |
9944 | CurrOpenCLExtension = std::string(Ext); |
9945 | } |
9946 | |
9947 | /// Set OpenCL extensions for a type which can only be used when these |
9948 | /// OpenCL extensions are enabled. If \p Exts is empty, do nothing. |
9949 | /// \param Exts A space separated list of OpenCL extensions. |
9950 | void setOpenCLExtensionForType(QualType T, llvm::StringRef Exts); |
9951 | |
9952 | /// Set OpenCL extensions for a declaration which can only be |
9953 | /// used when these OpenCL extensions are enabled. If \p Exts is empty, do |
9954 | /// nothing. |
9955 | /// \param Exts A space separated list of OpenCL extensions. |
9956 | void setOpenCLExtensionForDecl(Decl *FD, llvm::StringRef Exts); |
9957 | |
9958 | /// Set current OpenCL extensions for a type which can only be used |
9959 | /// when these OpenCL extensions are enabled. If current OpenCL extension is |
9960 | /// empty, do nothing. |
9961 | void setCurrentOpenCLExtensionForType(QualType T); |
9962 | |
9963 | /// Set current OpenCL extensions for a declaration which |
9964 | /// can only be used when these OpenCL extensions are enabled. If current |
9965 | /// OpenCL extension is empty, do nothing. |
9966 | void setCurrentOpenCLExtensionForDecl(Decl *FD); |
9967 | |
9968 | bool isOpenCLDisabledDecl(Decl *FD); |
9969 | |
9970 | /// Check if type \p T corresponding to declaration specifier \p DS |
9971 | /// is disabled due to required OpenCL extensions being disabled. If so, |
9972 | /// emit diagnostics. |
9973 | /// \return true if type is disabled. |
9974 | bool checkOpenCLDisabledTypeDeclSpec(const DeclSpec &DS, QualType T); |
9975 | |
9976 | /// Check if declaration \p D used by expression \p E |
9977 | /// is disabled due to required OpenCL extensions being disabled. If so, |
9978 | /// emit diagnostics. |
9979 | /// \return true if type is disabled. |
9980 | bool checkOpenCLDisabledDecl(const NamedDecl &D, const Expr &E); |
9981 | |
9982 | //===--------------------------------------------------------------------===// |
9983 | // OpenMP directives and clauses. |
9984 | // |
9985 | private: |
9986 | void *VarDataSharingAttributesStack; |
9987 | /// Number of nested '#pragma omp declare target' directives. |
9988 | SmallVector<SourceLocation, 4> DeclareTargetNesting; |
9989 | /// Initialization of data-sharing attributes stack. |
9990 | void InitDataSharingAttributesStack(); |
9991 | void DestroyDataSharingAttributesStack(); |
9992 | ExprResult |
9993 | VerifyPositiveIntegerConstantInClause(Expr *Op, OpenMPClauseKind CKind, |
9994 | bool StrictlyPositive = true); |
9995 | /// Returns OpenMP nesting level for current directive. |
9996 | unsigned getOpenMPNestingLevel() const; |
9997 | |
9998 | /// Adjusts the function scopes index for the target-based regions. |
9999 | void adjustOpenMPTargetScopeIndex(unsigned &FunctionScopesIndex, |
10000 | unsigned Level) const; |
10001 | |
10002 | /// Returns the number of scopes associated with the construct on the given |
10003 | /// OpenMP level. |
10004 | int getNumberOfConstructScopes(unsigned Level) const; |
10005 | |
10006 | /// Push new OpenMP function region for non-capturing function. |
10007 | void pushOpenMPFunctionRegion(); |
10008 | |
10009 | /// Pop OpenMP function region for non-capturing function. |
10010 | void popOpenMPFunctionRegion(const sema::FunctionScopeInfo *OldFSI); |
10011 | |
10012 | /// Checks if a type or a declaration is disabled due to the owning extension |
10013 | /// being disabled, and emits diagnostic messages if it is disabled. |
10014 | /// \param D type or declaration to be checked. |
10015 | /// \param DiagLoc source location for the diagnostic message. |
10016 | /// \param DiagInfo information to be emitted for the diagnostic message. |
10017 | /// \param SrcRange source range of the declaration. |
10018 | /// \param Map maps type or declaration to the extensions. |
10019 | /// \param Selector selects diagnostic message: 0 for type and 1 for |
10020 | /// declaration. |
10021 | /// \return true if the type or declaration is disabled. |
10022 | template <typename T, typename DiagLocT, typename DiagInfoT, typename MapT> |
10023 | bool checkOpenCLDisabledTypeOrDecl(T D, DiagLocT DiagLoc, DiagInfoT DiagInfo, |
10024 | MapT &Map, unsigned Selector = 0, |
10025 | SourceRange SrcRange = SourceRange()); |
10026 | |
10027 | /// Helper to keep information about the current `omp begin/end declare |
10028 | /// variant` nesting. |
10029 | struct OMPDeclareVariantScope { |
10030 | /// The associated OpenMP context selector. |
10031 | OMPTraitInfo *TI; |
10032 | |
10033 | /// The associated OpenMP context selector mangling. |
10034 | std::string NameSuffix; |
10035 | |
10036 | OMPDeclareVariantScope(OMPTraitInfo &TI); |
10037 | }; |
10038 | |
10039 | /// Return the OMPTraitInfo for the surrounding scope, if any. |
10040 | OMPTraitInfo *getOMPTraitInfoForSurroundingScope() { |
10041 | return OMPDeclareVariantScopes.empty() ? nullptr |
10042 | : OMPDeclareVariantScopes.back().TI; |
10043 | } |
10044 | |
10045 | /// The current `omp begin/end declare variant` scopes. |
10046 | SmallVector<OMPDeclareVariantScope, 4> OMPDeclareVariantScopes; |
10047 | |
10048 | /// The declarator \p D defines a function in the scope \p S which is nested |
10049 | /// in an `omp begin/end declare variant` scope. In this method we create a |
10050 | /// declaration for \p D and rename \p D according to the OpenMP context |
10051 | /// selector of the surrounding scope. Return all base functions in \p Bases. |
10052 | void ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope( |
10053 | Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists, |
10054 | SmallVectorImpl<FunctionDecl *> &Bases); |
10055 | |
10056 | /// Register \p D as specialization of all base functions in \p Bases in the |
10057 | /// current `omp begin/end declare variant` scope. |
10058 | void ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope( |
10059 | Decl *D, SmallVectorImpl<FunctionDecl *> &Bases); |
10060 | |
10061 | public: |
10062 | |
10063 | /// Can we exit a scope at the moment. |
10064 | bool isInOpenMPDeclareVariantScope() { |
10065 | return !OMPDeclareVariantScopes.empty(); |
10066 | } |
10067 | |
10068 | /// Given the potential call expression \p Call, determine if there is a |
10069 | /// specialization via the OpenMP declare variant mechanism available. If |
10070 | /// there is, return the specialized call expression, otherwise return the |
10071 | /// original \p Call. |
10072 | ExprResult ActOnOpenMPCall(ExprResult Call, Scope *Scope, |
10073 | SourceLocation LParenLoc, MultiExprArg ArgExprs, |
10074 | SourceLocation RParenLoc, Expr *ExecConfig); |
10075 | |
10076 | /// Handle a `omp begin declare variant`. |
10077 | void ActOnOpenMPBeginDeclareVariant(SourceLocation Loc, OMPTraitInfo &TI); |
10078 | |
10079 | /// Handle a `omp end declare variant`. |
10080 | void ActOnOpenMPEndDeclareVariant(); |
10081 | |
10082 | /// Checks if the variant/multiversion functions are compatible. |
10083 | bool areMultiversionVariantFunctionsCompatible( |
10084 | const FunctionDecl *OldFD, const FunctionDecl *NewFD, |
10085 | const PartialDiagnostic &NoProtoDiagID, |
10086 | const PartialDiagnosticAt &NoteCausedDiagIDAt, |
10087 | const PartialDiagnosticAt &NoSupportDiagIDAt, |
10088 | const PartialDiagnosticAt &DiffDiagIDAt, bool TemplatesSupported, |
10089 | bool ConstexprSupported, bool CLinkageMayDiffer); |
10090 | |
10091 | /// Function tries to capture lambda's captured variables in the OpenMP region |
10092 | /// before the original lambda is captured. |
10093 | void tryCaptureOpenMPLambdas(ValueDecl *V); |
10094 | |
10095 | /// Return true if the provided declaration \a VD should be captured by |
10096 | /// reference. |
10097 | /// \param Level Relative level of nested OpenMP construct for that the check |
10098 | /// is performed. |
10099 | /// \param OpenMPCaptureLevel Capture level within an OpenMP construct. |
10100 | bool isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level, |
10101 | unsigned OpenMPCaptureLevel) const; |
10102 | |
10103 | /// Check if the specified variable is used in one of the private |
10104 | /// clauses (private, firstprivate, lastprivate, reduction etc.) in OpenMP |
10105 | /// constructs. |
10106 | VarDecl *isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo = false, |
10107 | unsigned StopAt = 0); |
10108 | ExprResult getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
10109 | ExprObjectKind OK, SourceLocation Loc); |
10110 | |
10111 | /// If the current region is a loop-based region, mark the start of the loop |
10112 | /// construct. |
10113 | void startOpenMPLoop(); |
10114 | |
10115 | /// If the current region is a range loop-based region, mark the start of the |
10116 | /// loop construct. |
10117 | void startOpenMPCXXRangeFor(); |
10118 | |
10119 | /// Check if the specified variable is used in 'private' clause. |
10120 | /// \param Level Relative level of nested OpenMP construct for that the check |
10121 | /// is performed. |
10122 | OpenMPClauseKind isOpenMPPrivateDecl(ValueDecl *D, unsigned Level, |
10123 | unsigned CapLevel) const; |
10124 | |
10125 | /// Sets OpenMP capture kind (OMPC_private, OMPC_firstprivate, OMPC_map etc.) |
10126 | /// for \p FD based on DSA for the provided corresponding captured declaration |
10127 | /// \p D. |
10128 | void setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, unsigned Level); |
10129 | |
10130 | /// Check if the specified variable is captured by 'target' directive. |
10131 | /// \param Level Relative level of nested OpenMP construct for that the check |
10132 | /// is performed. |
10133 | bool isOpenMPTargetCapturedDecl(const ValueDecl *D, unsigned Level, |
10134 | unsigned CaptureLevel) const; |
10135 | |
10136 | /// Check if the specified global variable must be captured by outer capture |
10137 | /// regions. |
10138 | /// \param Level Relative level of nested OpenMP construct for that |
10139 | /// the check is performed. |
10140 | bool isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level, |
10141 | unsigned CaptureLevel) const; |
10142 | |
10143 | ExprResult PerformOpenMPImplicitIntegerConversion(SourceLocation OpLoc, |
10144 | Expr *Op); |
10145 | /// Called on start of new data sharing attribute block. |
10146 | void StartOpenMPDSABlock(OpenMPDirectiveKind K, |
10147 | const DeclarationNameInfo &DirName, Scope *CurScope, |
10148 | SourceLocation Loc); |
10149 | /// Start analysis of clauses. |
10150 | void StartOpenMPClause(OpenMPClauseKind K); |
10151 | /// End analysis of clauses. |
10152 | void EndOpenMPClause(); |
10153 | /// Called on end of data sharing attribute block. |
10154 | void EndOpenMPDSABlock(Stmt *CurDirective); |
10155 | |
10156 | /// Check if the current region is an OpenMP loop region and if it is, |
10157 | /// mark loop control variable, used in \p Init for loop initialization, as |
10158 | /// private by default. |
10159 | /// \param Init First part of the for loop. |
10160 | void ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init); |
10161 | |
10162 | // OpenMP directives and clauses. |
10163 | /// Called on correct id-expression from the '#pragma omp |
10164 | /// threadprivate'. |
10165 | ExprResult ActOnOpenMPIdExpression(Scope *CurScope, CXXScopeSpec &ScopeSpec, |
10166 | const DeclarationNameInfo &Id, |
10167 | OpenMPDirectiveKind Kind); |
10168 | /// Called on well-formed '#pragma omp threadprivate'. |
10169 | DeclGroupPtrTy ActOnOpenMPThreadprivateDirective( |
10170 | SourceLocation Loc, |
10171 | ArrayRef<Expr *> VarList); |
10172 | /// Builds a new OpenMPThreadPrivateDecl and checks its correctness. |
10173 | OMPThreadPrivateDecl *CheckOMPThreadPrivateDecl(SourceLocation Loc, |
10174 | ArrayRef<Expr *> VarList); |
10175 | /// Called on well-formed '#pragma omp allocate'. |
10176 | DeclGroupPtrTy ActOnOpenMPAllocateDirective(SourceLocation Loc, |
10177 | ArrayRef<Expr *> VarList, |
10178 | ArrayRef<OMPClause *> Clauses, |
10179 | DeclContext *Owner = nullptr); |
10180 | /// Called on well-formed '#pragma omp requires'. |
10181 | DeclGroupPtrTy ActOnOpenMPRequiresDirective(SourceLocation Loc, |
10182 | ArrayRef<OMPClause *> ClauseList); |
10183 | /// Check restrictions on Requires directive |
10184 | OMPRequiresDecl *CheckOMPRequiresDecl(SourceLocation Loc, |
10185 | ArrayRef<OMPClause *> Clauses); |
10186 | /// Check if the specified type is allowed to be used in 'omp declare |
10187 | /// reduction' construct. |
10188 | QualType ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
10189 | TypeResult ParsedType); |
10190 | /// Called on start of '#pragma omp declare reduction'. |
10191 | DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveStart( |
10192 | Scope *S, DeclContext *DC, DeclarationName Name, |
10193 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
10194 | AccessSpecifier AS, Decl *PrevDeclInScope = nullptr); |
10195 | /// Initialize declare reduction construct initializer. |
10196 | void ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D); |
10197 | /// Finish current declare reduction construct initializer. |
10198 | void ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner); |
10199 | /// Initialize declare reduction construct initializer. |
10200 | /// \return omp_priv variable. |
10201 | VarDecl *ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D); |
10202 | /// Finish current declare reduction construct initializer. |
10203 | void ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, Expr *Initializer, |
10204 | VarDecl *OmpPrivParm); |
10205 | /// Called at the end of '#pragma omp declare reduction'. |
10206 | DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveEnd( |
10207 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid); |
10208 | |
10209 | /// Check variable declaration in 'omp declare mapper' construct. |
10210 | TypeResult ActOnOpenMPDeclareMapperVarDecl(Scope *S, Declarator &D); |
10211 | /// Check if the specified type is allowed to be used in 'omp declare |
10212 | /// mapper' construct. |
10213 | QualType ActOnOpenMPDeclareMapperType(SourceLocation TyLoc, |
10214 | TypeResult ParsedType); |
10215 | /// Called on start of '#pragma omp declare mapper'. |
10216 | DeclGroupPtrTy ActOnOpenMPDeclareMapperDirective( |
10217 | Scope *S, DeclContext *DC, DeclarationName Name, QualType MapperType, |
10218 | SourceLocation StartLoc, DeclarationName VN, AccessSpecifier AS, |
10219 | Expr *MapperVarRef, ArrayRef<OMPClause *> Clauses, |
10220 | Decl *PrevDeclInScope = nullptr); |
10221 | /// Build the mapper variable of '#pragma omp declare mapper'. |
10222 | ExprResult ActOnOpenMPDeclareMapperDirectiveVarDecl(Scope *S, |
10223 | QualType MapperType, |
10224 | SourceLocation StartLoc, |
10225 | DeclarationName VN); |
10226 | bool isOpenMPDeclareMapperVarDeclAllowed(const VarDecl *VD) const; |
10227 | const ValueDecl *getOpenMPDeclareMapperVarName() const; |
10228 | |
10229 | /// Called on the start of target region i.e. '#pragma omp declare target'. |
10230 | bool ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc); |
10231 | /// Called at the end of target region i.e. '#pragme omp end declare target'. |
10232 | void ActOnFinishOpenMPDeclareTargetDirective(); |
10233 | /// Searches for the provided declaration name for OpenMP declare target |
10234 | /// directive. |
10235 | NamedDecl * |
10236 | lookupOpenMPDeclareTargetName(Scope *CurScope, CXXScopeSpec &ScopeSpec, |
10237 | const DeclarationNameInfo &Id, |
10238 | NamedDeclSetType &SameDirectiveDecls); |
10239 | /// Called on correct id-expression from the '#pragma omp declare target'. |
10240 | void ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc, |
10241 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
10242 | OMPDeclareTargetDeclAttr::DevTypeTy DT); |
10243 | /// Check declaration inside target region. |
10244 | void |
10245 | checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, |
10246 | SourceLocation IdLoc = SourceLocation()); |
10247 | /// Finishes analysis of the deferred functions calls that may be declared as |
10248 | /// host/nohost during device/host compilation. |
10249 | void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller, |
10250 | const FunctionDecl *Callee, |
10251 | SourceLocation Loc); |
10252 | /// Return true inside OpenMP declare target region. |
10253 | bool isInOpenMPDeclareTargetContext() const { |
10254 | return !DeclareTargetNesting.empty(); |
10255 | } |
10256 | /// Return true inside OpenMP target region. |
10257 | bool isInOpenMPTargetExecutionDirective() const; |
10258 | |
10259 | /// Return the number of captured regions created for an OpenMP directive. |
10260 | static int getOpenMPCaptureLevels(OpenMPDirectiveKind Kind); |
10261 | |
10262 | /// Initialization of captured region for OpenMP region. |
10263 | void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope); |
10264 | /// End of OpenMP region. |
10265 | /// |
10266 | /// \param S Statement associated with the current OpenMP region. |
10267 | /// \param Clauses List of clauses for the current OpenMP region. |
10268 | /// |
10269 | /// \returns Statement for finished OpenMP region. |
10270 | StmtResult ActOnOpenMPRegionEnd(StmtResult S, ArrayRef<OMPClause *> Clauses); |
10271 | StmtResult ActOnOpenMPExecutableDirective( |
10272 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
10273 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
10274 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc); |
10275 | /// Called on well-formed '\#pragma omp parallel' after parsing |
10276 | /// of the associated statement. |
10277 | StmtResult ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
10278 | Stmt *AStmt, |
10279 | SourceLocation StartLoc, |
10280 | SourceLocation EndLoc); |
10281 | using VarsWithInheritedDSAType = |
10282 | llvm::SmallDenseMap<const ValueDecl *, const Expr *, 4>; |
10283 | /// Called on well-formed '\#pragma omp simd' after parsing |
10284 | /// of the associated statement. |
10285 | StmtResult |
10286 | ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
10287 | SourceLocation StartLoc, SourceLocation EndLoc, |
10288 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10289 | /// Called on well-formed '\#pragma omp for' after parsing |
10290 | /// of the associated statement. |
10291 | StmtResult |
10292 | ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
10293 | SourceLocation StartLoc, SourceLocation EndLoc, |
10294 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10295 | /// Called on well-formed '\#pragma omp for simd' after parsing |
10296 | /// of the associated statement. |
10297 | StmtResult |
10298 | ActOnOpenMPForSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
10299 | SourceLocation StartLoc, SourceLocation EndLoc, |
10300 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10301 | /// Called on well-formed '\#pragma omp sections' after parsing |
10302 | /// of the associated statement. |
10303 | StmtResult ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
10304 | Stmt *AStmt, SourceLocation StartLoc, |
10305 | SourceLocation EndLoc); |
10306 | /// Called on well-formed '\#pragma omp section' after parsing of the |
10307 | /// associated statement. |
10308 | StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc, |
10309 | SourceLocation EndLoc); |
10310 | /// Called on well-formed '\#pragma omp single' after parsing of the |
10311 | /// associated statement. |
10312 | StmtResult ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
10313 | Stmt *AStmt, SourceLocation StartLoc, |
10314 | SourceLocation EndLoc); |
10315 | /// Called on well-formed '\#pragma omp master' after parsing of the |
10316 | /// associated statement. |
10317 | StmtResult ActOnOpenMPMasterDirective(Stmt *AStmt, SourceLocation StartLoc, |
10318 | SourceLocation EndLoc); |
10319 | /// Called on well-formed '\#pragma omp critical' after parsing of the |
10320 | /// associated statement. |
10321 | StmtResult ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
10322 | ArrayRef<OMPClause *> Clauses, |
10323 | Stmt *AStmt, SourceLocation StartLoc, |
10324 | SourceLocation EndLoc); |
10325 | /// Called on well-formed '\#pragma omp parallel for' after parsing |
10326 | /// of the associated statement. |
10327 | StmtResult ActOnOpenMPParallelForDirective( |
10328 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10329 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10330 | /// Called on well-formed '\#pragma omp parallel for simd' after |
10331 | /// parsing of the associated statement. |
10332 | StmtResult ActOnOpenMPParallelForSimdDirective( |
10333 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10334 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10335 | /// Called on well-formed '\#pragma omp parallel master' after |
10336 | /// parsing of the associated statement. |
10337 | StmtResult ActOnOpenMPParallelMasterDirective(ArrayRef<OMPClause *> Clauses, |
10338 | Stmt *AStmt, |
10339 | SourceLocation StartLoc, |
10340 | SourceLocation EndLoc); |
10341 | /// Called on well-formed '\#pragma omp parallel sections' after |
10342 | /// parsing of the associated statement. |
10343 | StmtResult ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
10344 | Stmt *AStmt, |
10345 | SourceLocation StartLoc, |
10346 | SourceLocation EndLoc); |
10347 | /// Called on well-formed '\#pragma omp task' after parsing of the |
10348 | /// associated statement. |
10349 | StmtResult ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
10350 | Stmt *AStmt, SourceLocation StartLoc, |
10351 | SourceLocation EndLoc); |
10352 | /// Called on well-formed '\#pragma omp taskyield'. |
10353 | StmtResult ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
10354 | SourceLocation EndLoc); |
10355 | /// Called on well-formed '\#pragma omp barrier'. |
10356 | StmtResult ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
10357 | SourceLocation EndLoc); |
10358 | /// Called on well-formed '\#pragma omp taskwait'. |
10359 | StmtResult ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
10360 | SourceLocation EndLoc); |
10361 | /// Called on well-formed '\#pragma omp taskgroup'. |
10362 | StmtResult ActOnOpenMPTaskgroupDirective(ArrayRef<OMPClause *> Clauses, |
10363 | Stmt *AStmt, SourceLocation StartLoc, |
10364 | SourceLocation EndLoc); |
10365 | /// Called on well-formed '\#pragma omp flush'. |
10366 | StmtResult ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
10367 | SourceLocation StartLoc, |
10368 | SourceLocation EndLoc); |
10369 | /// Called on well-formed '\#pragma omp depobj'. |
10370 | StmtResult ActOnOpenMPDepobjDirective(ArrayRef<OMPClause *> Clauses, |
10371 | SourceLocation StartLoc, |
10372 | SourceLocation EndLoc); |
10373 | /// Called on well-formed '\#pragma omp scan'. |
10374 | StmtResult ActOnOpenMPScanDirective(ArrayRef<OMPClause *> Clauses, |
10375 | SourceLocation StartLoc, |
10376 | SourceLocation EndLoc); |
10377 | /// Called on well-formed '\#pragma omp ordered' after parsing of the |
10378 | /// associated statement. |
10379 | StmtResult ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
10380 | Stmt *AStmt, SourceLocation StartLoc, |
10381 | SourceLocation EndLoc); |
10382 | /// Called on well-formed '\#pragma omp atomic' after parsing of the |
10383 | /// associated statement. |
10384 | StmtResult ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
10385 | Stmt *AStmt, SourceLocation StartLoc, |
10386 | SourceLocation EndLoc); |
10387 | /// Called on well-formed '\#pragma omp target' after parsing of the |
10388 | /// associated statement. |
10389 | StmtResult ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
10390 | Stmt *AStmt, SourceLocation StartLoc, |
10391 | SourceLocation EndLoc); |
10392 | /// Called on well-formed '\#pragma omp target data' after parsing of |
10393 | /// the associated statement. |
10394 | StmtResult ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
10395 | Stmt *AStmt, SourceLocation StartLoc, |
10396 | SourceLocation EndLoc); |
10397 | /// Called on well-formed '\#pragma omp target enter data' after |
10398 | /// parsing of the associated statement. |
10399 | StmtResult ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
10400 | SourceLocation StartLoc, |
10401 | SourceLocation EndLoc, |
10402 | Stmt *AStmt); |
10403 | /// Called on well-formed '\#pragma omp target exit data' after |
10404 | /// parsing of the associated statement. |
10405 | StmtResult ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
10406 | SourceLocation StartLoc, |
10407 | SourceLocation EndLoc, |
10408 | Stmt *AStmt); |
10409 | /// Called on well-formed '\#pragma omp target parallel' after |
10410 | /// parsing of the associated statement. |
10411 | StmtResult ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
10412 | Stmt *AStmt, |
10413 | SourceLocation StartLoc, |
10414 | SourceLocation EndLoc); |
10415 | /// Called on well-formed '\#pragma omp target parallel for' after |
10416 | /// parsing of the associated statement. |
10417 | StmtResult ActOnOpenMPTargetParallelForDirective( |
10418 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10419 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10420 | /// Called on well-formed '\#pragma omp teams' after parsing of the |
10421 | /// associated statement. |
10422 | StmtResult ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
10423 | Stmt *AStmt, SourceLocation StartLoc, |
10424 | SourceLocation EndLoc); |
10425 | /// Called on well-formed '\#pragma omp cancellation point'. |
10426 | StmtResult |
10427 | ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
10428 | SourceLocation EndLoc, |
10429 | OpenMPDirectiveKind CancelRegion); |
10430 | /// Called on well-formed '\#pragma omp cancel'. |
10431 | StmtResult ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
10432 | SourceLocation StartLoc, |
10433 | SourceLocation EndLoc, |
10434 | OpenMPDirectiveKind CancelRegion); |
10435 | /// Called on well-formed '\#pragma omp taskloop' after parsing of the |
10436 | /// associated statement. |
10437 | StmtResult |
10438 | ActOnOpenMPTaskLoopDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
10439 | SourceLocation StartLoc, SourceLocation EndLoc, |
10440 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10441 | /// Called on well-formed '\#pragma omp taskloop simd' after parsing of |
10442 | /// the associated statement. |
10443 | StmtResult ActOnOpenMPTaskLoopSimdDirective( |
10444 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10445 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10446 | /// Called on well-formed '\#pragma omp master taskloop' after parsing of the |
10447 | /// associated statement. |
10448 | StmtResult ActOnOpenMPMasterTaskLoopDirective( |
10449 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10450 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10451 | /// Called on well-formed '\#pragma omp master taskloop simd' after parsing of |
10452 | /// the associated statement. |
10453 | StmtResult ActOnOpenMPMasterTaskLoopSimdDirective( |
10454 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10455 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10456 | /// Called on well-formed '\#pragma omp parallel master taskloop' after |
10457 | /// parsing of the associated statement. |
10458 | StmtResult ActOnOpenMPParallelMasterTaskLoopDirective( |
10459 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10460 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10461 | /// Called on well-formed '\#pragma omp parallel master taskloop simd' after |
10462 | /// parsing of the associated statement. |
10463 | StmtResult ActOnOpenMPParallelMasterTaskLoopSimdDirective( |
10464 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10465 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10466 | /// Called on well-formed '\#pragma omp distribute' after parsing |
10467 | /// of the associated statement. |
10468 | StmtResult |
10469 | ActOnOpenMPDistributeDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
10470 | SourceLocation StartLoc, SourceLocation EndLoc, |
10471 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10472 | /// Called on well-formed '\#pragma omp target update'. |
10473 | StmtResult ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
10474 | SourceLocation StartLoc, |
10475 | SourceLocation EndLoc, |
10476 | Stmt *AStmt); |
10477 | /// Called on well-formed '\#pragma omp distribute parallel for' after |
10478 | /// parsing of the associated statement. |
10479 | StmtResult ActOnOpenMPDistributeParallelForDirective( |
10480 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10481 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10482 | /// Called on well-formed '\#pragma omp distribute parallel for simd' |
10483 | /// after parsing of the associated statement. |
10484 | StmtResult ActOnOpenMPDistributeParallelForSimdDirective( |
10485 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10486 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10487 | /// Called on well-formed '\#pragma omp distribute simd' after |
10488 | /// parsing of the associated statement. |
10489 | StmtResult ActOnOpenMPDistributeSimdDirective( |
10490 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10491 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10492 | /// Called on well-formed '\#pragma omp target parallel for simd' after |
10493 | /// parsing of the associated statement. |
10494 | StmtResult ActOnOpenMPTargetParallelForSimdDirective( |
10495 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10496 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10497 | /// Called on well-formed '\#pragma omp target simd' after parsing of |
10498 | /// the associated statement. |
10499 | StmtResult |
10500 | ActOnOpenMPTargetSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
10501 | SourceLocation StartLoc, SourceLocation EndLoc, |
10502 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10503 | /// Called on well-formed '\#pragma omp teams distribute' after parsing of |
10504 | /// the associated statement. |
10505 | StmtResult ActOnOpenMPTeamsDistributeDirective( |
10506 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10507 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10508 | /// Called on well-formed '\#pragma omp teams distribute simd' after parsing |
10509 | /// of the associated statement. |
10510 | StmtResult ActOnOpenMPTeamsDistributeSimdDirective( |
10511 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10512 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10513 | /// Called on well-formed '\#pragma omp teams distribute parallel for simd' |
10514 | /// after parsing of the associated statement. |
10515 | StmtResult ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
10516 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10517 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10518 | /// Called on well-formed '\#pragma omp teams distribute parallel for' |
10519 | /// after parsing of the associated statement. |
10520 | StmtResult ActOnOpenMPTeamsDistributeParallelForDirective( |
10521 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10522 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10523 | /// Called on well-formed '\#pragma omp target teams' after parsing of the |
10524 | /// associated statement. |
10525 | StmtResult ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses, |
10526 | Stmt *AStmt, |
10527 | SourceLocation StartLoc, |
10528 | SourceLocation EndLoc); |
10529 | /// Called on well-formed '\#pragma omp target teams distribute' after parsing |
10530 | /// of the associated statement. |
10531 | StmtResult ActOnOpenMPTargetTeamsDistributeDirective( |
10532 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10533 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10534 | /// Called on well-formed '\#pragma omp target teams distribute parallel for' |
10535 | /// after parsing of the associated statement. |
10536 | StmtResult ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
10537 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10538 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10539 | /// Called on well-formed '\#pragma omp target teams distribute parallel for |
10540 | /// simd' after parsing of the associated statement. |
10541 | StmtResult ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
10542 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10543 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10544 | /// Called on well-formed '\#pragma omp target teams distribute simd' after |
10545 | /// parsing of the associated statement. |
10546 | StmtResult ActOnOpenMPTargetTeamsDistributeSimdDirective( |
10547 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10548 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10549 | |
10550 | /// Checks correctness of linear modifiers. |
10551 | bool CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
10552 | SourceLocation LinLoc); |
10553 | /// Checks that the specified declaration matches requirements for the linear |
10554 | /// decls. |
10555 | bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc, |
10556 | OpenMPLinearClauseKind LinKind, QualType Type, |
10557 | bool IsDeclareSimd = false); |
10558 | |
10559 | /// Called on well-formed '\#pragma omp declare simd' after parsing of |
10560 | /// the associated method/function. |
10561 | DeclGroupPtrTy ActOnOpenMPDeclareSimdDirective( |
10562 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, |
10563 | Expr *Simdlen, ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
10564 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
10565 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR); |
10566 | |
10567 | /// Checks '\#pragma omp declare variant' variant function and original |
10568 | /// functions after parsing of the associated method/function. |
10569 | /// \param DG Function declaration to which declare variant directive is |
10570 | /// applied to. |
10571 | /// \param VariantRef Expression that references the variant function, which |
10572 | /// must be used instead of the original one, specified in \p DG. |
10573 | /// \param TI The trait info object representing the match clause. |
10574 | /// \returns None, if the function/variant function are not compatible with |
10575 | /// the pragma, pair of original function/variant ref expression otherwise. |
10576 | Optional<std::pair<FunctionDecl *, Expr *>> |
10577 | checkOpenMPDeclareVariantFunction(DeclGroupPtrTy DG, Expr *VariantRef, |
10578 | OMPTraitInfo &TI, SourceRange SR); |
10579 | |
10580 | /// Called on well-formed '\#pragma omp declare variant' after parsing of |
10581 | /// the associated method/function. |
10582 | /// \param FD Function declaration to which declare variant directive is |
10583 | /// applied to. |
10584 | /// \param VariantRef Expression that references the variant function, which |
10585 | /// must be used instead of the original one, specified in \p DG. |
10586 | /// \param TI The context traits associated with the function variant. |
10587 | void ActOnOpenMPDeclareVariantDirective(FunctionDecl *FD, Expr *VariantRef, |
10588 | OMPTraitInfo &TI, SourceRange SR); |
10589 | |
10590 | OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, |
10591 | Expr *Expr, |
10592 | SourceLocation StartLoc, |
10593 | SourceLocation LParenLoc, |
10594 | SourceLocation EndLoc); |
10595 | /// Called on well-formed 'allocator' clause. |
10596 | OMPClause *ActOnOpenMPAllocatorClause(Expr *Allocator, |
10597 | SourceLocation StartLoc, |
10598 | SourceLocation LParenLoc, |
10599 | SourceLocation EndLoc); |
10600 | /// Called on well-formed 'if' clause. |
10601 | OMPClause *ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
10602 | Expr *Condition, SourceLocation StartLoc, |
10603 | SourceLocation LParenLoc, |
10604 | SourceLocation NameModifierLoc, |
10605 | SourceLocation ColonLoc, |
10606 | SourceLocation EndLoc); |
10607 | /// Called on well-formed 'final' clause. |
10608 | OMPClause *ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
10609 | SourceLocation LParenLoc, |
10610 | SourceLocation EndLoc); |
10611 | /// Called on well-formed 'num_threads' clause. |
10612 | OMPClause *ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
10613 | SourceLocation StartLoc, |
10614 | SourceLocation LParenLoc, |
10615 | SourceLocation EndLoc); |
10616 | /// Called on well-formed 'safelen' clause. |
10617 | OMPClause *ActOnOpenMPSafelenClause(Expr *Length, |
10618 | SourceLocation StartLoc, |
10619 | SourceLocation LParenLoc, |
10620 | SourceLocation EndLoc); |
10621 | /// Called on well-formed 'simdlen' clause. |
10622 | OMPClause *ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc, |
10623 | SourceLocation LParenLoc, |
10624 | SourceLocation EndLoc); |
10625 | /// Called on well-formed 'collapse' clause. |
10626 | OMPClause *ActOnOpenMPCollapseClause(Expr *NumForLoops, |
10627 | SourceLocation StartLoc, |
10628 | SourceLocation LParenLoc, |
10629 | SourceLocation EndLoc); |
10630 | /// Called on well-formed 'ordered' clause. |
10631 | OMPClause * |
10632 | ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, |
10633 | SourceLocation LParenLoc = SourceLocation(), |
10634 | Expr *NumForLoops = nullptr); |
10635 | /// Called on well-formed 'grainsize' clause. |
10636 | OMPClause *ActOnOpenMPGrainsizeClause(Expr *Size, SourceLocation StartLoc, |
10637 | SourceLocation LParenLoc, |
10638 | SourceLocation EndLoc); |
10639 | /// Called on well-formed 'num_tasks' clause. |
10640 | OMPClause *ActOnOpenMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc, |
10641 | SourceLocation LParenLoc, |
10642 | SourceLocation EndLoc); |
10643 | /// Called on well-formed 'hint' clause. |
10644 | OMPClause *ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
10645 | SourceLocation LParenLoc, |
10646 | SourceLocation EndLoc); |
10647 | /// Called on well-formed 'detach' clause. |
10648 | OMPClause *ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc, |
10649 | SourceLocation LParenLoc, |
10650 | SourceLocation EndLoc); |
10651 | |
10652 | OMPClause *ActOnOpenMPSimpleClause(OpenMPClauseKind Kind, |
10653 | unsigned Argument, |
10654 | SourceLocation ArgumentLoc, |
10655 | SourceLocation StartLoc, |
10656 | SourceLocation LParenLoc, |
10657 | SourceLocation EndLoc); |
10658 | /// Called on well-formed 'default' clause. |
10659 | OMPClause *ActOnOpenMPDefaultClause(llvm::omp::DefaultKind Kind, |
10660 | SourceLocation KindLoc, |
10661 | SourceLocation StartLoc, |
10662 | SourceLocation LParenLoc, |
10663 | SourceLocation EndLoc); |
10664 | /// Called on well-formed 'proc_bind' clause. |
10665 | OMPClause *ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind, |
10666 | SourceLocation KindLoc, |
10667 | SourceLocation StartLoc, |
10668 | SourceLocation LParenLoc, |
10669 | SourceLocation EndLoc); |
10670 | /// Called on well-formed 'order' clause. |
10671 | OMPClause *ActOnOpenMPOrderClause(OpenMPOrderClauseKind Kind, |
10672 | SourceLocation KindLoc, |
10673 | SourceLocation StartLoc, |
10674 | SourceLocation LParenLoc, |
10675 | SourceLocation EndLoc); |
10676 | /// Called on well-formed 'update' clause. |
10677 | OMPClause *ActOnOpenMPUpdateClause(OpenMPDependClauseKind Kind, |
10678 | SourceLocation KindLoc, |
10679 | SourceLocation StartLoc, |
10680 | SourceLocation LParenLoc, |
10681 | SourceLocation EndLoc); |
10682 | |
10683 | OMPClause *ActOnOpenMPSingleExprWithArgClause( |
10684 | OpenMPClauseKind Kind, ArrayRef<unsigned> Arguments, Expr *Expr, |
10685 | SourceLocation StartLoc, SourceLocation LParenLoc, |
10686 | ArrayRef<SourceLocation> ArgumentsLoc, SourceLocation DelimLoc, |
10687 | SourceLocation EndLoc); |
10688 | /// Called on well-formed 'schedule' clause. |
10689 | OMPClause *ActOnOpenMPScheduleClause( |
10690 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
10691 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
10692 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
10693 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc); |
10694 | |
10695 | OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc, |
10696 | SourceLocation EndLoc); |
10697 | /// Called on well-formed 'nowait' clause. |
10698 | OMPClause *ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
10699 | SourceLocation EndLoc); |
10700 | /// Called on well-formed 'untied' clause. |
10701 | OMPClause *ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
10702 | SourceLocation EndLoc); |
10703 | /// Called on well-formed 'mergeable' clause. |
10704 | OMPClause *ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
10705 | SourceLocation EndLoc); |
10706 | /// Called on well-formed 'read' clause. |
10707 | OMPClause *ActOnOpenMPReadClause(SourceLocation StartLoc, |
10708 | SourceLocation EndLoc); |
10709 | /// Called on well-formed 'write' clause. |
10710 | OMPClause *ActOnOpenMPWriteClause(SourceLocation StartLoc, |
10711 | SourceLocation EndLoc); |
10712 | /// Called on well-formed 'update' clause. |
10713 | OMPClause *ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
10714 | SourceLocation EndLoc); |
10715 | /// Called on well-formed 'capture' clause. |
10716 | OMPClause *ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
10717 | SourceLocation EndLoc); |
10718 | /// Called on well-formed 'seq_cst' clause. |
10719 | OMPClause *ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
10720 | SourceLocation EndLoc); |
10721 | /// Called on well-formed 'acq_rel' clause. |
10722 | OMPClause *ActOnOpenMPAcqRelClause(SourceLocation StartLoc, |
10723 | SourceLocation EndLoc); |
10724 | /// Called on well-formed 'acquire' clause. |
10725 | OMPClause *ActOnOpenMPAcquireClause(SourceLocation StartLoc, |
10726 | SourceLocation EndLoc); |
10727 | /// Called on well-formed 'release' clause. |
10728 | OMPClause *ActOnOpenMPReleaseClause(SourceLocation StartLoc, |
10729 | SourceLocation EndLoc); |
10730 | /// Called on well-formed 'relaxed' clause. |
10731 | OMPClause *ActOnOpenMPRelaxedClause(SourceLocation StartLoc, |
10732 | SourceLocation EndLoc); |
10733 | /// Called on well-formed 'destroy' clause. |
10734 | OMPClause *ActOnOpenMPDestroyClause(SourceLocation StartLoc, |
10735 | SourceLocation EndLoc); |
10736 | /// Called on well-formed 'threads' clause. |
10737 | OMPClause *ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
10738 | SourceLocation EndLoc); |
10739 | /// Called on well-formed 'simd' clause. |
10740 | OMPClause *ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
10741 | SourceLocation EndLoc); |
10742 | /// Called on well-formed 'nogroup' clause. |
10743 | OMPClause *ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
10744 | SourceLocation EndLoc); |
10745 | /// Called on well-formed 'unified_address' clause. |
10746 | OMPClause *ActOnOpenMPUnifiedAddressClause(SourceLocation StartLoc, |
10747 | SourceLocation EndLoc); |
10748 | |
10749 | /// Called on well-formed 'unified_address' clause. |
10750 | OMPClause *ActOnOpenMPUnifiedSharedMemoryClause(SourceLocation StartLoc, |
10751 | SourceLocation EndLoc); |
10752 | |
10753 | /// Called on well-formed 'reverse_offload' clause. |
10754 | OMPClause *ActOnOpenMPReverseOffloadClause(SourceLocation StartLoc, |
10755 | SourceLocation EndLoc); |
10756 | |
10757 | /// Called on well-formed 'dynamic_allocators' clause. |
10758 | OMPClause *ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc, |
10759 | SourceLocation EndLoc); |
10760 | |
10761 | /// Called on well-formed 'atomic_default_mem_order' clause. |
10762 | OMPClause *ActOnOpenMPAtomicDefaultMemOrderClause( |
10763 | OpenMPAtomicDefaultMemOrderClauseKind Kind, SourceLocation KindLoc, |
10764 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); |
10765 | |
10766 | OMPClause *ActOnOpenMPVarListClause( |
10767 | OpenMPClauseKind Kind, ArrayRef<Expr *> Vars, Expr *DepModOrTailExpr, |
10768 | const OMPVarListLocTy &Locs, SourceLocation ColonLoc, |
10769 | CXXScopeSpec &ReductionOrMapperIdScopeSpec, |
10770 | DeclarationNameInfo &ReductionOrMapperId, int ExtraModifier, |
10771 | ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
10772 | ArrayRef<SourceLocation> MapTypeModifiersLoc, bool IsMapTypeImplicit, |
10773 | SourceLocation ExtraModifierLoc, |
10774 | ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
10775 | ArrayRef<SourceLocation> MotionModifiersLoc); |
10776 | /// Called on well-formed 'inclusive' clause. |
10777 | OMPClause *ActOnOpenMPInclusiveClause(ArrayRef<Expr *> VarList, |
10778 | SourceLocation StartLoc, |
10779 | SourceLocation LParenLoc, |
10780 | SourceLocation EndLoc); |
10781 | /// Called on well-formed 'exclusive' clause. |
10782 | OMPClause *ActOnOpenMPExclusiveClause(ArrayRef<Expr *> VarList, |
10783 | SourceLocation StartLoc, |
10784 | SourceLocation LParenLoc, |
10785 | SourceLocation EndLoc); |
10786 | /// Called on well-formed 'allocate' clause. |
10787 | OMPClause * |
10788 | ActOnOpenMPAllocateClause(Expr *Allocator, ArrayRef<Expr *> VarList, |
10789 | SourceLocation StartLoc, SourceLocation ColonLoc, |
10790 | SourceLocation LParenLoc, SourceLocation EndLoc); |
10791 | /// Called on well-formed 'private' clause. |
10792 | OMPClause *ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
10793 | SourceLocation StartLoc, |
10794 | SourceLocation LParenLoc, |
10795 | SourceLocation EndLoc); |
10796 | /// Called on well-formed 'firstprivate' clause. |
10797 | OMPClause *ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
10798 | SourceLocation StartLoc, |
10799 | SourceLocation LParenLoc, |
10800 | SourceLocation EndLoc); |
10801 | /// Called on well-formed 'lastprivate' clause. |
10802 | OMPClause *ActOnOpenMPLastprivateClause( |
10803 | ArrayRef<Expr *> VarList, OpenMPLastprivateModifier LPKind, |
10804 | SourceLocation LPKindLoc, SourceLocation ColonLoc, |
10805 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); |
10806 | /// Called on well-formed 'shared' clause. |
10807 | OMPClause *ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
10808 | SourceLocation StartLoc, |
10809 | SourceLocation LParenLoc, |
10810 | SourceLocation EndLoc); |
10811 | /// Called on well-formed 'reduction' clause. |
10812 | OMPClause *ActOnOpenMPReductionClause( |
10813 | ArrayRef<Expr *> VarList, OpenMPReductionClauseModifier Modifier, |
10814 | SourceLocation StartLoc, SourceLocation LParenLoc, |
10815 | SourceLocation ModifierLoc, SourceLocation ColonLoc, |
10816 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
10817 | const DeclarationNameInfo &ReductionId, |
10818 | ArrayRef<Expr *> UnresolvedReductions = llvm::None); |
10819 | /// Called on well-formed 'task_reduction' clause. |
10820 | OMPClause *ActOnOpenMPTaskReductionClause( |
10821 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
10822 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
10823 | CXXScopeSpec &ReductionIdScopeSpec, |
10824 | const DeclarationNameInfo &ReductionId, |
10825 | ArrayRef<Expr *> UnresolvedReductions = llvm::None); |
10826 | /// Called on well-formed 'in_reduction' clause. |
10827 | OMPClause *ActOnOpenMPInReductionClause( |
10828 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
10829 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
10830 | CXXScopeSpec &ReductionIdScopeSpec, |
10831 | const DeclarationNameInfo &ReductionId, |
10832 | ArrayRef<Expr *> UnresolvedReductions = llvm::None); |
10833 | /// Called on well-formed 'linear' clause. |
10834 | OMPClause * |
10835 | ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
10836 | SourceLocation StartLoc, SourceLocation LParenLoc, |
10837 | OpenMPLinearClauseKind LinKind, SourceLocation LinLoc, |
10838 | SourceLocation ColonLoc, SourceLocation EndLoc); |
10839 | /// Called on well-formed 'aligned' clause. |
10840 | OMPClause *ActOnOpenMPAlignedClause(ArrayRef<Expr *> VarList, |
10841 | Expr *Alignment, |
10842 | SourceLocation StartLoc, |
10843 | SourceLocation LParenLoc, |
10844 | SourceLocation ColonLoc, |
10845 | SourceLocation EndLoc); |
10846 | /// Called on well-formed 'copyin' clause. |
10847 | OMPClause *ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
10848 | SourceLocation StartLoc, |
10849 | SourceLocation LParenLoc, |
10850 | SourceLocation EndLoc); |
10851 | /// Called on well-formed 'copyprivate' clause. |
10852 | OMPClause *ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
10853 | SourceLocation StartLoc, |
10854 | SourceLocation LParenLoc, |
10855 | SourceLocation EndLoc); |
10856 | /// Called on well-formed 'flush' pseudo clause. |
10857 | OMPClause *ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
10858 | SourceLocation StartLoc, |
10859 | SourceLocation LParenLoc, |
10860 | SourceLocation EndLoc); |
10861 | /// Called on well-formed 'depobj' pseudo clause. |
10862 | OMPClause *ActOnOpenMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, |
10863 | SourceLocation LParenLoc, |
10864 | SourceLocation EndLoc); |
10865 | /// Called on well-formed 'depend' clause. |
10866 | OMPClause * |
10867 | ActOnOpenMPDependClause(Expr *DepModifier, OpenMPDependClauseKind DepKind, |
10868 | SourceLocation DepLoc, SourceLocation ColonLoc, |
10869 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
10870 | SourceLocation LParenLoc, SourceLocation EndLoc); |
10871 | /// Called on well-formed 'device' clause. |
10872 | OMPClause *ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier, |
10873 | Expr *Device, SourceLocation StartLoc, |
10874 | SourceLocation LParenLoc, |
10875 | SourceLocation ModifierLoc, |
10876 | SourceLocation EndLoc); |
10877 | /// Called on well-formed 'map' clause. |
10878 | OMPClause * |
10879 | ActOnOpenMPMapClause(ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
10880 | ArrayRef<SourceLocation> MapTypeModifiersLoc, |
10881 | CXXScopeSpec &MapperIdScopeSpec, |
10882 | DeclarationNameInfo &MapperId, |
10883 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
10884 | SourceLocation MapLoc, SourceLocation ColonLoc, |
10885 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
10886 | ArrayRef<Expr *> UnresolvedMappers = llvm::None); |
10887 | /// Called on well-formed 'num_teams' clause. |
10888 | OMPClause *ActOnOpenMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, |
10889 | SourceLocation LParenLoc, |
10890 | SourceLocation EndLoc); |
10891 | /// Called on well-formed 'thread_limit' clause. |
10892 | OMPClause *ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
10893 | SourceLocation StartLoc, |
10894 | SourceLocation LParenLoc, |
10895 | SourceLocation EndLoc); |
10896 | /// Called on well-formed 'priority' clause. |
10897 | OMPClause *ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc, |
10898 | SourceLocation LParenLoc, |
10899 | SourceLocation EndLoc); |
10900 | /// Called on well-formed 'dist_schedule' clause. |
10901 | OMPClause *ActOnOpenMPDistScheduleClause( |
10902 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, |
10903 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, |
10904 | SourceLocation CommaLoc, SourceLocation EndLoc); |
10905 | /// Called on well-formed 'defaultmap' clause. |
10906 | OMPClause *ActOnOpenMPDefaultmapClause( |
10907 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
10908 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
10909 | SourceLocation KindLoc, SourceLocation EndLoc); |
10910 | /// Called on well-formed 'to' clause. |
10911 | OMPClause * |
10912 | ActOnOpenMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
10913 | ArrayRef<SourceLocation> MotionModifiersLoc, |
10914 | CXXScopeSpec &MapperIdScopeSpec, |
10915 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
10916 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
10917 | ArrayRef<Expr *> UnresolvedMappers = llvm::None); |
10918 | /// Called on well-formed 'from' clause. |
10919 | OMPClause * |
10920 | ActOnOpenMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
10921 | ArrayRef<SourceLocation> MotionModifiersLoc, |
10922 | CXXScopeSpec &MapperIdScopeSpec, |
10923 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
10924 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
10925 | ArrayRef<Expr *> UnresolvedMappers = llvm::None); |
10926 | /// Called on well-formed 'use_device_ptr' clause. |
10927 | OMPClause *ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
10928 | const OMPVarListLocTy &Locs); |
10929 | /// Called on well-formed 'use_device_addr' clause. |
10930 | OMPClause *ActOnOpenMPUseDeviceAddrClause(ArrayRef<Expr *> VarList, |
10931 | const OMPVarListLocTy &Locs); |
10932 | /// Called on well-formed 'is_device_ptr' clause. |
10933 | OMPClause *ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
10934 | const OMPVarListLocTy &Locs); |
10935 | /// Called on well-formed 'nontemporal' clause. |
10936 | OMPClause *ActOnOpenMPNontemporalClause(ArrayRef<Expr *> VarList, |
10937 | SourceLocation StartLoc, |
10938 | SourceLocation LParenLoc, |
10939 | SourceLocation EndLoc); |
10940 | |
10941 | /// Data for list of allocators. |
10942 | struct UsesAllocatorsData { |
10943 | /// Allocator. |
10944 | Expr *Allocator = nullptr; |
10945 | /// Allocator traits. |
10946 | Expr *AllocatorTraits = nullptr; |
10947 | /// Locations of '(' and ')' symbols. |
10948 | SourceLocation LParenLoc, RParenLoc; |
10949 | }; |
10950 | /// Called on well-formed 'uses_allocators' clause. |
10951 | OMPClause *ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, |
10952 | SourceLocation LParenLoc, |
10953 | SourceLocation EndLoc, |
10954 | ArrayRef<UsesAllocatorsData> Data); |
10955 | /// Called on well-formed 'affinity' clause. |
10956 | OMPClause *ActOnOpenMPAffinityClause(SourceLocation StartLoc, |
10957 | SourceLocation LParenLoc, |
10958 | SourceLocation ColonLoc, |
10959 | SourceLocation EndLoc, Expr *Modifier, |
10960 | ArrayRef<Expr *> Locators); |
10961 | |
10962 | /// The kind of conversion being performed. |
10963 | enum CheckedConversionKind { |
10964 | /// An implicit conversion. |
10965 | CCK_ImplicitConversion, |
10966 | /// A C-style cast. |
10967 | CCK_CStyleCast, |
10968 | /// A functional-style cast. |
10969 | CCK_FunctionalCast, |
10970 | /// A cast other than a C-style cast. |
10971 | CCK_OtherCast, |
10972 | /// A conversion for an operand of a builtin overloaded operator. |
10973 | CCK_ForBuiltinOverloadedOp |
10974 | }; |
10975 | |
10976 | static bool isCast(CheckedConversionKind CCK) { |
10977 | return CCK == CCK_CStyleCast || CCK == CCK_FunctionalCast || |
10978 | CCK == CCK_OtherCast; |
10979 | } |
10980 | |
10981 | /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit |
10982 | /// cast. If there is already an implicit cast, merge into the existing one. |
10983 | /// If isLvalue, the result of the cast is an lvalue. |
10984 | ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, |
10985 | ExprValueKind VK = VK_RValue, |
10986 | const CXXCastPath *BasePath = nullptr, |
10987 | CheckedConversionKind CCK |
10988 | = CCK_ImplicitConversion); |
10989 | |
10990 | /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding |
10991 | /// to the conversion from scalar type ScalarTy to the Boolean type. |
10992 | static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); |
10993 | |
10994 | /// IgnoredValueConversions - Given that an expression's result is |
10995 | /// syntactically ignored, perform any conversions that are |
10996 | /// required. |
10997 | ExprResult IgnoredValueConversions(Expr *E); |
10998 | |
10999 | // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts |
11000 | // functions and arrays to their respective pointers (C99 6.3.2.1). |
11001 | ExprResult UsualUnaryConversions(Expr *E); |
11002 | |
11003 | /// CallExprUnaryConversions - a special case of an unary conversion |
11004 | /// performed on a function designator of a call expression. |
11005 | ExprResult CallExprUnaryConversions(Expr *E); |
11006 | |
11007 | // DefaultFunctionArrayConversion - converts functions and arrays |
11008 | // to their respective pointers (C99 6.3.2.1). |
11009 | ExprResult DefaultFunctionArrayConversion(Expr *E, bool Diagnose = true); |
11010 | |
11011 | // DefaultFunctionArrayLvalueConversion - converts functions and |
11012 | // arrays to their respective pointers and performs the |
11013 | // lvalue-to-rvalue conversion. |
11014 | ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, |
11015 | bool Diagnose = true); |
11016 | |
11017 | // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on |
11018 | // the operand. This function is a no-op if the operand has a function type |
11019 | // or an array type. |
11020 | ExprResult DefaultLvalueConversion(Expr *E); |
11021 | |
11022 | // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that |
11023 | // do not have a prototype. Integer promotions are performed on each |
11024 | // argument, and arguments that have type float are promoted to double. |
11025 | ExprResult DefaultArgumentPromotion(Expr *E); |
11026 | |
11027 | /// If \p E is a prvalue denoting an unmaterialized temporary, materialize |
11028 | /// it as an xvalue. In C++98, the result will still be a prvalue, because |
11029 | /// we don't have xvalues there. |
11030 | ExprResult TemporaryMaterializationConversion(Expr *E); |
11031 | |
11032 | // Used for emitting the right warning by DefaultVariadicArgumentPromotion |
11033 | enum VariadicCallType { |
11034 | VariadicFunction, |
11035 | VariadicBlock, |
11036 | VariadicMethod, |
11037 | VariadicConstructor, |
11038 | VariadicDoesNotApply |
11039 | }; |
11040 | |
11041 | VariadicCallType getVariadicCallType(FunctionDecl *FDecl, |
11042 | const FunctionProtoType *Proto, |
11043 | Expr *Fn); |
11044 | |
11045 | // Used for determining in which context a type is allowed to be passed to a |
11046 | // vararg function. |
11047 | enum VarArgKind { |
11048 | VAK_Valid, |
11049 | VAK_ValidInCXX11, |
11050 | VAK_Undefined, |
11051 | VAK_MSVCUndefined, |
11052 | VAK_Invalid |
11053 | }; |
11054 | |
11055 | // Determines which VarArgKind fits an expression. |
11056 | VarArgKind isValidVarArgType(const QualType &Ty); |
11057 | |
11058 | /// Check to see if the given expression is a valid argument to a variadic |
11059 | /// function, issuing a diagnostic if not. |
11060 | void checkVariadicArgument(const Expr *E, VariadicCallType CT); |
11061 | |
11062 | /// Check to see if a given expression could have '.c_str()' called on it. |
11063 | bool hasCStrMethod(const Expr *E); |
11064 | |
11065 | /// GatherArgumentsForCall - Collector argument expressions for various |
11066 | /// form of call prototypes. |
11067 | bool GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl, |
11068 | const FunctionProtoType *Proto, |
11069 | unsigned FirstParam, ArrayRef<Expr *> Args, |
11070 | SmallVectorImpl<Expr *> &AllArgs, |
11071 | VariadicCallType CallType = VariadicDoesNotApply, |
11072 | bool AllowExplicit = false, |
11073 | bool IsListInitialization = false); |
11074 | |
11075 | // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but |
11076 | // will create a runtime trap if the resulting type is not a POD type. |
11077 | ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, |
11078 | FunctionDecl *FDecl); |
11079 | |
11080 | /// Context in which we're performing a usual arithmetic conversion. |
11081 | enum ArithConvKind { |
11082 | /// An arithmetic operation. |
11083 | ACK_Arithmetic, |
11084 | /// A bitwise operation. |
11085 | ACK_BitwiseOp, |
11086 | /// A comparison. |
11087 | ACK_Comparison, |
11088 | /// A conditional (?:) operator. |
11089 | ACK_Conditional, |
11090 | /// A compound assignment expression. |
11091 | ACK_CompAssign, |
11092 | }; |
11093 | |
11094 | // UsualArithmeticConversions - performs the UsualUnaryConversions on it's |
11095 | // operands and then handles various conversions that are common to binary |
11096 | // operators (C99 6.3.1.8). If both operands aren't arithmetic, this |
11097 | // routine returns the first non-arithmetic type found. The client is |
11098 | // responsible for emitting appropriate error diagnostics. |
11099 | QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, |
11100 | SourceLocation Loc, ArithConvKind ACK); |
11101 | |
11102 | /// AssignConvertType - All of the 'assignment' semantic checks return this |
11103 | /// enum to indicate whether the assignment was allowed. These checks are |
11104 | /// done for simple assignments, as well as initialization, return from |
11105 | /// function, argument passing, etc. The query is phrased in terms of a |
11106 | /// source and destination type. |
11107 | enum AssignConvertType { |
11108 | /// Compatible - the types are compatible according to the standard. |
11109 | Compatible, |
11110 | |
11111 | /// PointerToInt - The assignment converts a pointer to an int, which we |
11112 | /// accept as an extension. |
11113 | PointerToInt, |
11114 | |
11115 | /// IntToPointer - The assignment converts an int to a pointer, which we |
11116 | /// accept as an extension. |
11117 | IntToPointer, |
11118 | |
11119 | /// FunctionVoidPointer - The assignment is between a function pointer and |
11120 | /// void*, which the standard doesn't allow, but we accept as an extension. |
11121 | FunctionVoidPointer, |
11122 | |
11123 | /// IncompatiblePointer - The assignment is between two pointers types that |
11124 | /// are not compatible, but we accept them as an extension. |
11125 | IncompatiblePointer, |
11126 | |
11127 | /// IncompatibleFunctionPointer - The assignment is between two function |
11128 | /// pointers types that are not compatible, but we accept them as an |
11129 | /// extension. |
11130 | IncompatibleFunctionPointer, |
11131 | |
11132 | /// IncompatiblePointerSign - The assignment is between two pointers types |
11133 | /// which point to integers which have a different sign, but are otherwise |
11134 | /// identical. This is a subset of the above, but broken out because it's by |
11135 | /// far the most common case of incompatible pointers. |
11136 | IncompatiblePointerSign, |
11137 | |
11138 | /// CompatiblePointerDiscardsQualifiers - The assignment discards |
11139 | /// c/v/r qualifiers, which we accept as an extension. |
11140 | CompatiblePointerDiscardsQualifiers, |
11141 | |
11142 | /// IncompatiblePointerDiscardsQualifiers - The assignment |
11143 | /// discards qualifiers that we don't permit to be discarded, |
11144 | /// like address spaces. |
11145 | IncompatiblePointerDiscardsQualifiers, |
11146 | |
11147 | /// IncompatibleNestedPointerAddressSpaceMismatch - The assignment |
11148 | /// changes address spaces in nested pointer types which is not allowed. |
11149 | /// For instance, converting __private int ** to __generic int ** is |
11150 | /// illegal even though __private could be converted to __generic. |
11151 | IncompatibleNestedPointerAddressSpaceMismatch, |
11152 | |
11153 | /// IncompatibleNestedPointerQualifiers - The assignment is between two |
11154 | /// nested pointer types, and the qualifiers other than the first two |
11155 | /// levels differ e.g. char ** -> const char **, but we accept them as an |
11156 | /// extension. |
11157 | IncompatibleNestedPointerQualifiers, |
11158 | |
11159 | /// IncompatibleVectors - The assignment is between two vector types that |
11160 | /// have the same size, which we accept as an extension. |
11161 | IncompatibleVectors, |
11162 | |
11163 | /// IntToBlockPointer - The assignment converts an int to a block |
11164 | /// pointer. We disallow this. |
11165 | IntToBlockPointer, |
11166 | |
11167 | /// IncompatibleBlockPointer - The assignment is between two block |
11168 | /// pointers types that are not compatible. |
11169 | IncompatibleBlockPointer, |
11170 | |
11171 | /// IncompatibleObjCQualifiedId - The assignment is between a qualified |
11172 | /// id type and something else (that is incompatible with it). For example, |
11173 | /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. |
11174 | IncompatibleObjCQualifiedId, |
11175 | |
11176 | /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an |
11177 | /// object with __weak qualifier. |
11178 | IncompatibleObjCWeakRef, |
11179 | |
11180 | /// Incompatible - We reject this conversion outright, it is invalid to |
11181 | /// represent it in the AST. |
11182 | Incompatible |
11183 | }; |
11184 | |
11185 | /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the |
11186 | /// assignment conversion type specified by ConvTy. This returns true if the |
11187 | /// conversion was invalid or false if the conversion was accepted. |
11188 | bool DiagnoseAssignmentResult(AssignConvertType ConvTy, |
11189 | SourceLocation Loc, |
11190 | QualType DstType, QualType SrcType, |
11191 | Expr *SrcExpr, AssignmentAction Action, |
11192 | bool *Complained = nullptr); |
11193 | |
11194 | /// IsValueInFlagEnum - Determine if a value is allowed as part of a flag |
11195 | /// enum. If AllowMask is true, then we also allow the complement of a valid |
11196 | /// value, to be used as a mask. |
11197 | bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val, |
11198 | bool AllowMask) const; |
11199 | |
11200 | /// DiagnoseAssignmentEnum - Warn if assignment to enum is a constant |
11201 | /// integer not in the range of enum values. |
11202 | void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, |
11203 | Expr *SrcExpr); |
11204 | |
11205 | /// CheckAssignmentConstraints - Perform type checking for assignment, |
11206 | /// argument passing, variable initialization, and function return values. |
11207 | /// C99 6.5.16. |
11208 | AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, |
11209 | QualType LHSType, |
11210 | QualType RHSType); |
11211 | |
11212 | /// Check assignment constraints and optionally prepare for a conversion of |
11213 | /// the RHS to the LHS type. The conversion is prepared for if ConvertRHS |
11214 | /// is true. |
11215 | AssignConvertType CheckAssignmentConstraints(QualType LHSType, |
11216 | ExprResult &RHS, |
11217 | CastKind &Kind, |
11218 | bool ConvertRHS = true); |
11219 | |
11220 | /// Check assignment constraints for an assignment of RHS to LHSType. |
11221 | /// |
11222 | /// \param LHSType The destination type for the assignment. |
11223 | /// \param RHS The source expression for the assignment. |
11224 | /// \param Diagnose If \c true, diagnostics may be produced when checking |
11225 | /// for assignability. If a diagnostic is produced, \p RHS will be |
11226 | /// set to ExprError(). Note that this function may still return |
11227 | /// without producing a diagnostic, even for an invalid assignment. |
11228 | /// \param DiagnoseCFAudited If \c true, the target is a function parameter |
11229 | /// in an audited Core Foundation API and does not need to be checked |
11230 | /// for ARC retain issues. |
11231 | /// \param ConvertRHS If \c true, \p RHS will be updated to model the |
11232 | /// conversions necessary to perform the assignment. If \c false, |
11233 | /// \p Diagnose must also be \c false. |
11234 | AssignConvertType CheckSingleAssignmentConstraints( |
11235 | QualType LHSType, ExprResult &RHS, bool Diagnose = true, |
11236 | bool DiagnoseCFAudited = false, bool ConvertRHS = true); |
11237 | |
11238 | // If the lhs type is a transparent union, check whether we |
11239 | // can initialize the transparent union with the given expression. |
11240 | AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, |
11241 | ExprResult &RHS); |
11242 | |
11243 | bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); |
11244 | |
11245 | bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); |
11246 | |
11247 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
11248 | AssignmentAction Action, |
11249 | bool AllowExplicit = false); |
11250 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
11251 | const ImplicitConversionSequence& ICS, |
11252 | AssignmentAction Action, |
11253 | CheckedConversionKind CCK |
11254 | = CCK_ImplicitConversion); |
11255 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
11256 | const StandardConversionSequence& SCS, |
11257 | AssignmentAction Action, |
11258 | CheckedConversionKind CCK); |
11259 | |
11260 | ExprResult PerformQualificationConversion( |
11261 | Expr *E, QualType Ty, ExprValueKind VK = VK_RValue, |
11262 | CheckedConversionKind CCK = CCK_ImplicitConversion); |
11263 | |
11264 | /// the following "Check" methods will return a valid/converted QualType |
11265 | /// or a null QualType (indicating an error diagnostic was issued). |
11266 | |
11267 | /// type checking binary operators (subroutines of CreateBuiltinBinOp). |
11268 | QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS, |
11269 | ExprResult &RHS); |
11270 | QualType InvalidLogicalVectorOperands(SourceLocation Loc, ExprResult &LHS, |
11271 | ExprResult &RHS); |
11272 | QualType CheckPointerToMemberOperands( // C++ 5.5 |
11273 | ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, |
11274 | SourceLocation OpLoc, bool isIndirect); |
11275 | QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
11276 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign, |
11277 | bool IsDivide); |
11278 | QualType CheckRemainderOperands( // C99 6.5.5 |
11279 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
11280 | bool IsCompAssign = false); |
11281 | QualType CheckAdditionOperands( // C99 6.5.6 |
11282 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
11283 | BinaryOperatorKind Opc, QualType* CompLHSTy = nullptr); |
11284 | QualType CheckSubtractionOperands( // C99 6.5.6 |
11285 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
11286 | QualType* CompLHSTy = nullptr); |
11287 | QualType CheckShiftOperands( // C99 6.5.7 |
11288 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
11289 | BinaryOperatorKind Opc, bool IsCompAssign = false); |
11290 | void CheckPtrComparisonWithNullChar(ExprResult &E, ExprResult &NullE); |
11291 | QualType CheckCompareOperands( // C99 6.5.8/9 |
11292 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
11293 | BinaryOperatorKind Opc); |
11294 | QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
11295 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
11296 | BinaryOperatorKind Opc); |
11297 | QualType CheckLogicalOperands( // C99 6.5.[13,14] |
11298 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
11299 | BinaryOperatorKind Opc); |
11300 | // CheckAssignmentOperands is used for both simple and compound assignment. |
11301 | // For simple assignment, pass both expressions and a null converted type. |
11302 | // For compound assignment, pass both expressions and the converted type. |
11303 | QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] |
11304 | Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType); |
11305 | |
11306 | ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc, |
11307 | UnaryOperatorKind Opcode, Expr *Op); |
11308 | ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc, |
11309 | BinaryOperatorKind Opcode, |
11310 | Expr *LHS, Expr *RHS); |
11311 | ExprResult checkPseudoObjectRValue(Expr *E); |
11312 | Expr *recreateSyntacticForm(PseudoObjectExpr *E); |
11313 | |
11314 | QualType CheckConditionalOperands( // C99 6.5.15 |
11315 | ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, |
11316 | ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc); |
11317 | QualType CXXCheckConditionalOperands( // C++ 5.16 |
11318 | ExprResult &cond, ExprResult &lhs, ExprResult &rhs, |
11319 | ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); |
11320 | QualType CheckGNUVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS, |
11321 | ExprResult &RHS, |
11322 | SourceLocation QuestionLoc); |
11323 | QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, |
11324 | bool ConvertArgs = true); |
11325 | QualType FindCompositePointerType(SourceLocation Loc, |
11326 | ExprResult &E1, ExprResult &E2, |
11327 | bool ConvertArgs = true) { |
11328 | Expr *E1Tmp = E1.get(), *E2Tmp = E2.get(); |
11329 | QualType Composite = |
11330 | FindCompositePointerType(Loc, E1Tmp, E2Tmp, ConvertArgs); |
11331 | E1 = E1Tmp; |
11332 | E2 = E2Tmp; |
11333 | return Composite; |
11334 | } |
11335 | |
11336 | QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, |
11337 | SourceLocation QuestionLoc); |
11338 | |
11339 | bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr, |
11340 | SourceLocation QuestionLoc); |
11341 | |
11342 | void DiagnoseAlwaysNonNullPointer(Expr *E, |
11343 | Expr::NullPointerConstantKind NullType, |
11344 | bool IsEqual, SourceRange Range); |
11345 | |
11346 | /// type checking for vector binary operators. |
11347 | QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS, |
11348 | SourceLocation Loc, bool IsCompAssign, |
11349 | bool AllowBothBool, bool AllowBoolConversion); |
11350 | QualType GetSignedVectorType(QualType V); |
11351 | QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, |
11352 | SourceLocation Loc, |
11353 | BinaryOperatorKind Opc); |
11354 | QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, |
11355 | SourceLocation Loc); |
11356 | |
11357 | /// Type checking for matrix binary operators. |
11358 | QualType CheckMatrixElementwiseOperands(ExprResult &LHS, ExprResult &RHS, |
11359 | SourceLocation Loc, |
11360 | bool IsCompAssign); |
11361 | QualType CheckMatrixMultiplyOperands(ExprResult &LHS, ExprResult &RHS, |
11362 | SourceLocation Loc, bool IsCompAssign); |
11363 | |
11364 | bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType); |
11365 | bool isLaxVectorConversion(QualType srcType, QualType destType); |
11366 | |
11367 | /// type checking declaration initializers (C99 6.7.8) |
11368 | bool CheckForConstantInitializer(Expr *e, QualType t); |
11369 | |
11370 | // type checking C++ declaration initializers (C++ [dcl.init]). |
11371 | |
11372 | /// ReferenceCompareResult - Expresses the result of comparing two |
11373 | /// types (cv1 T1 and cv2 T2) to determine their compatibility for the |
11374 | /// purposes of initialization by reference (C++ [dcl.init.ref]p4). |
11375 | enum ReferenceCompareResult { |
11376 | /// Ref_Incompatible - The two types are incompatible, so direct |
11377 | /// reference binding is not possible. |
11378 | Ref_Incompatible = 0, |
11379 | /// Ref_Related - The two types are reference-related, which means |
11380 | /// that their unqualified forms (T1 and T2) are either the same |
11381 | /// or T1 is a base class of T2. |
11382 | Ref_Related, |
11383 | /// Ref_Compatible - The two types are reference-compatible. |
11384 | Ref_Compatible |
11385 | }; |
11386 | |
11387 | // Fake up a scoped enumeration that still contextually converts to bool. |
11388 | struct ReferenceConversionsScope { |
11389 | /// The conversions that would be performed on an lvalue of type T2 when |
11390 | /// binding a reference of type T1 to it, as determined when evaluating |
11391 | /// whether T1 is reference-compatible with T2. |
11392 | enum ReferenceConversions { |
11393 | Qualification = 0x1, |
11394 | NestedQualification = 0x2, |
11395 | Function = 0x4, |
11396 | DerivedToBase = 0x8, |
11397 | ObjC = 0x10, |
11398 | ObjCLifetime = 0x20, |
11399 | |
11400 | LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/ObjCLifetime)LLVM_BITMASK_LARGEST_ENUMERATOR = ObjCLifetime |
11401 | }; |
11402 | }; |
11403 | using ReferenceConversions = ReferenceConversionsScope::ReferenceConversions; |
11404 | |
11405 | ReferenceCompareResult |
11406 | CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2, |
11407 | ReferenceConversions *Conv = nullptr); |
11408 | |
11409 | ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, |
11410 | Expr *CastExpr, CastKind &CastKind, |
11411 | ExprValueKind &VK, CXXCastPath &Path); |
11412 | |
11413 | /// Force an expression with unknown-type to an expression of the |
11414 | /// given type. |
11415 | ExprResult forceUnknownAnyToType(Expr *E, QualType ToType); |
11416 | |
11417 | /// Type-check an expression that's being passed to an |
11418 | /// __unknown_anytype parameter. |
11419 | ExprResult checkUnknownAnyArg(SourceLocation callLoc, |
11420 | Expr *result, QualType ¶mType); |
11421 | |
11422 | // CheckVectorCast - check type constraints for vectors. |
11423 | // Since vectors are an extension, there are no C standard reference for this. |
11424 | // We allow casting between vectors and integer datatypes of the same size. |
11425 | // returns true if the cast is invalid |
11426 | bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, |
11427 | CastKind &Kind); |
11428 | |
11429 | /// Prepare `SplattedExpr` for a vector splat operation, adding |
11430 | /// implicit casts if necessary. |
11431 | ExprResult prepareVectorSplat(QualType VectorTy, Expr *SplattedExpr); |
11432 | |
11433 | // CheckExtVectorCast - check type constraints for extended vectors. |
11434 | // Since vectors are an extension, there are no C standard reference for this. |
11435 | // We allow casting between vectors and integer datatypes of the same size, |
11436 | // or vectors and the element type of that vector. |
11437 | // returns the cast expr |
11438 | ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr, |
11439 | CastKind &Kind); |
11440 | |
11441 | ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, QualType Type, |
11442 | SourceLocation LParenLoc, |
11443 | Expr *CastExpr, |
11444 | SourceLocation RParenLoc); |
11445 | |
11446 | enum ARCConversionResult { ACR_okay, ACR_unbridged, ACR_error }; |
11447 | |
11448 | /// Checks for invalid conversions and casts between |
11449 | /// retainable pointers and other pointer kinds for ARC and Weak. |
11450 | ARCConversionResult CheckObjCConversion(SourceRange castRange, |
11451 | QualType castType, Expr *&op, |
11452 | CheckedConversionKind CCK, |
11453 | bool Diagnose = true, |
11454 | bool DiagnoseCFAudited = false, |
11455 | BinaryOperatorKind Opc = BO_PtrMemD |
11456 | ); |
11457 | |
11458 | Expr *stripARCUnbridgedCast(Expr *e); |
11459 | void diagnoseARCUnbridgedCast(Expr *e); |
11460 | |
11461 | bool CheckObjCARCUnavailableWeakConversion(QualType castType, |
11462 | QualType ExprType); |
11463 | |
11464 | /// checkRetainCycles - Check whether an Objective-C message send |
11465 | /// might create an obvious retain cycle. |
11466 | void checkRetainCycles(ObjCMessageExpr *msg); |
11467 | void checkRetainCycles(Expr *receiver, Expr *argument); |
11468 | void checkRetainCycles(VarDecl *Var, Expr *Init); |
11469 | |
11470 | /// checkUnsafeAssigns - Check whether +1 expr is being assigned |
11471 | /// to weak/__unsafe_unretained type. |
11472 | bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); |
11473 | |
11474 | /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned |
11475 | /// to weak/__unsafe_unretained expression. |
11476 | void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); |
11477 | |
11478 | /// CheckMessageArgumentTypes - Check types in an Obj-C message send. |
11479 | /// \param Method - May be null. |
11480 | /// \param [out] ReturnType - The return type of the send. |
11481 | /// \return true iff there were any incompatible types. |
11482 | bool CheckMessageArgumentTypes(const Expr *Receiver, QualType ReceiverType, |
11483 | MultiExprArg Args, Selector Sel, |
11484 | ArrayRef<SourceLocation> SelectorLocs, |
11485 | ObjCMethodDecl *Method, bool isClassMessage, |
11486 | bool isSuperMessage, SourceLocation lbrac, |
11487 | SourceLocation rbrac, SourceRange RecRange, |
11488 | QualType &ReturnType, ExprValueKind &VK); |
11489 | |
11490 | /// Determine the result of a message send expression based on |
11491 | /// the type of the receiver, the method expected to receive the message, |
11492 | /// and the form of the message send. |
11493 | QualType getMessageSendResultType(const Expr *Receiver, QualType ReceiverType, |
11494 | ObjCMethodDecl *Method, bool isClassMessage, |
11495 | bool isSuperMessage); |
11496 | |
11497 | /// If the given expression involves a message send to a method |
11498 | /// with a related result type, emit a note describing what happened. |
11499 | void EmitRelatedResultTypeNote(const Expr *E); |
11500 | |
11501 | /// Given that we had incompatible pointer types in a return |
11502 | /// statement, check whether we're in a method with a related result |
11503 | /// type, and if so, emit a note describing what happened. |
11504 | void EmitRelatedResultTypeNoteForReturn(QualType destType); |
11505 | |
11506 | class ConditionResult { |
11507 | Decl *ConditionVar; |
11508 | FullExprArg Condition; |
11509 | bool Invalid; |
11510 | bool HasKnownValue; |
11511 | bool KnownValue; |
11512 | |
11513 | friend class Sema; |
11514 | ConditionResult(Sema &S, Decl *ConditionVar, FullExprArg Condition, |
11515 | bool IsConstexpr) |
11516 | : ConditionVar(ConditionVar), Condition(Condition), Invalid(false), |
11517 | HasKnownValue(IsConstexpr && Condition.get() && |
11518 | !Condition.get()->isValueDependent()), |
11519 | KnownValue(HasKnownValue && |
11520 | !!Condition.get()->EvaluateKnownConstInt(S.Context)) {} |
11521 | explicit ConditionResult(bool Invalid) |
11522 | : ConditionVar(nullptr), Condition(nullptr), Invalid(Invalid), |
11523 | HasKnownValue(false), KnownValue(false) {} |
11524 | |
11525 | public: |
11526 | ConditionResult() : ConditionResult(false) {} |
11527 | bool isInvalid() const { return Invalid; } |
11528 | std::pair<VarDecl *, Expr *> get() const { |
11529 | return std::make_pair(cast_or_null<VarDecl>(ConditionVar), |
11530 | Condition.get()); |
11531 | } |
11532 | llvm::Optional<bool> getKnownValue() const { |
11533 | if (!HasKnownValue) |
11534 | return None; |
11535 | return KnownValue; |
11536 | } |
11537 | }; |
11538 | static ConditionResult ConditionError() { return ConditionResult(true); } |
11539 | |
11540 | enum class ConditionKind { |
11541 | Boolean, ///< A boolean condition, from 'if', 'while', 'for', or 'do'. |
11542 | ConstexprIf, ///< A constant boolean condition from 'if constexpr'. |
11543 | Switch ///< An integral condition for a 'switch' statement. |
11544 | }; |
11545 | |
11546 | ConditionResult ActOnCondition(Scope *S, SourceLocation Loc, |
11547 | Expr *SubExpr, ConditionKind CK); |
11548 | |
11549 | ConditionResult ActOnConditionVariable(Decl *ConditionVar, |
11550 | SourceLocation StmtLoc, |
11551 | ConditionKind CK); |
11552 | |
11553 | DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); |
11554 | |
11555 | ExprResult CheckConditionVariable(VarDecl *ConditionVar, |
11556 | SourceLocation StmtLoc, |
11557 | ConditionKind CK); |
11558 | ExprResult CheckSwitchCondition(SourceLocation SwitchLoc, Expr *Cond); |
11559 | |
11560 | /// CheckBooleanCondition - Diagnose problems involving the use of |
11561 | /// the given expression as a boolean condition (e.g. in an if |
11562 | /// statement). Also performs the standard function and array |
11563 | /// decays, possibly changing the input variable. |
11564 | /// |
11565 | /// \param Loc - A location associated with the condition, e.g. the |
11566 | /// 'if' keyword. |
11567 | /// \return true iff there were any errors |
11568 | ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E, |
11569 | bool IsConstexpr = false); |
11570 | |
11571 | /// ActOnExplicitBoolSpecifier - Build an ExplicitSpecifier from an expression |
11572 | /// found in an explicit(bool) specifier. |
11573 | ExplicitSpecifier ActOnExplicitBoolSpecifier(Expr *E); |
11574 | |
11575 | /// tryResolveExplicitSpecifier - Attempt to resolve the explict specifier. |
11576 | /// Returns true if the explicit specifier is now resolved. |
11577 | bool tryResolveExplicitSpecifier(ExplicitSpecifier &ExplicitSpec); |
11578 | |
11579 | /// DiagnoseAssignmentAsCondition - Given that an expression is |
11580 | /// being used as a boolean condition, warn if it's an assignment. |
11581 | void DiagnoseAssignmentAsCondition(Expr *E); |
11582 | |
11583 | /// Redundant parentheses over an equality comparison can indicate |
11584 | /// that the user intended an assignment used as condition. |
11585 | void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE); |
11586 | |
11587 | /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. |
11588 | ExprResult CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr = false); |
11589 | |
11590 | /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have |
11591 | /// the specified width and sign. If an overflow occurs, detect it and emit |
11592 | /// the specified diagnostic. |
11593 | void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, |
11594 | unsigned NewWidth, bool NewSign, |
11595 | SourceLocation Loc, unsigned DiagID); |
11596 | |
11597 | /// Checks that the Objective-C declaration is declared in the global scope. |
11598 | /// Emits an error and marks the declaration as invalid if it's not declared |
11599 | /// in the global scope. |
11600 | bool CheckObjCDeclScope(Decl *D); |
11601 | |
11602 | /// Abstract base class used for diagnosing integer constant |
11603 | /// expression violations. |
11604 | class VerifyICEDiagnoser { |
11605 | public: |
11606 | bool Suppress; |
11607 | |
11608 | VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) { } |
11609 | |
11610 | virtual SemaDiagnosticBuilder |
11611 | diagnoseNotICEType(Sema &S, SourceLocation Loc, QualType T); |
11612 | virtual SemaDiagnosticBuilder diagnoseNotICE(Sema &S, |
11613 | SourceLocation Loc) = 0; |
11614 | virtual SemaDiagnosticBuilder diagnoseFold(Sema &S, SourceLocation Loc); |
11615 | virtual ~VerifyICEDiagnoser() {} |
11616 | }; |
11617 | |
11618 | /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE, |
11619 | /// and reports the appropriate diagnostics. Returns false on success. |
11620 | /// Can optionally return the value of the expression. |
11621 | ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
11622 | VerifyICEDiagnoser &Diagnoser, |
11623 | bool AllowFold = true); |
11624 | ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
11625 | unsigned DiagID, |
11626 | bool AllowFold = true); |
11627 | ExprResult VerifyIntegerConstantExpression(Expr *E, |
11628 | llvm::APSInt *Result = nullptr); |
11629 | |
11630 | /// VerifyBitField - verifies that a bit field expression is an ICE and has |
11631 | /// the correct width, and that the field type is valid. |
11632 | /// Returns false on success. |
11633 | /// Can optionally return whether the bit-field is of width 0 |
11634 | ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, |
11635 | QualType FieldTy, bool IsMsStruct, |
11636 | Expr *BitWidth, bool *ZeroWidth = nullptr); |
11637 | |
11638 | private: |
11639 | unsigned ForceCUDAHostDeviceDepth = 0; |
11640 | |
11641 | public: |
11642 | /// Increments our count of the number of times we've seen a pragma forcing |
11643 | /// functions to be __host__ __device__. So long as this count is greater |
11644 | /// than zero, all functions encountered will be __host__ __device__. |
11645 | void PushForceCUDAHostDevice(); |
11646 | |
11647 | /// Decrements our count of the number of times we've seen a pragma forcing |
11648 | /// functions to be __host__ __device__. Returns false if the count is 0 |
11649 | /// before incrementing, so you can emit an error. |
11650 | bool PopForceCUDAHostDevice(); |
11651 | |
11652 | /// Diagnostics that are emitted only if we discover that the given function |
11653 | /// must be codegen'ed. Because handling these correctly adds overhead to |
11654 | /// compilation, this is currently only enabled for CUDA compilations. |
11655 | llvm::DenseMap<CanonicalDeclPtr<FunctionDecl>, |
11656 | std::vector<PartialDiagnosticAt>> |
11657 | DeviceDeferredDiags; |
11658 | |
11659 | /// A pair of a canonical FunctionDecl and a SourceLocation. When used as the |
11660 | /// key in a hashtable, both the FD and location are hashed. |
11661 | struct FunctionDeclAndLoc { |
11662 | CanonicalDeclPtr<FunctionDecl> FD; |
11663 | SourceLocation Loc; |
11664 | }; |
11665 | |
11666 | /// FunctionDecls and SourceLocations for which CheckCUDACall has emitted a |
11667 | /// (maybe deferred) "bad call" diagnostic. We use this to avoid emitting the |
11668 | /// same deferred diag twice. |
11669 | llvm::DenseSet<FunctionDeclAndLoc> LocsWithCUDACallDiags; |
11670 | |
11671 | /// An inverse call graph, mapping known-emitted functions to one of their |
11672 | /// known-emitted callers (plus the location of the call). |
11673 | /// |
11674 | /// Functions that we can tell a priori must be emitted aren't added to this |
11675 | /// map. |
11676 | llvm::DenseMap</* Callee = */ CanonicalDeclPtr<FunctionDecl>, |
11677 | /* Caller = */ FunctionDeclAndLoc> |
11678 | DeviceKnownEmittedFns; |
11679 | |
11680 | /// Diagnostic builder for CUDA/OpenMP devices errors which may or may not be |
11681 | /// deferred. |
11682 | /// |
11683 | /// In CUDA, there exist constructs (e.g. variable-length arrays, try/catch) |
11684 | /// which are not allowed to appear inside __device__ functions and are |
11685 | /// allowed to appear in __host__ __device__ functions only if the host+device |
11686 | /// function is never codegen'ed. |
11687 | /// |
11688 | /// To handle this, we use the notion of "deferred diagnostics", where we |
11689 | /// attach a diagnostic to a FunctionDecl that's emitted iff it's codegen'ed. |
11690 | /// |
11691 | /// This class lets you emit either a regular diagnostic, a deferred |
11692 | /// diagnostic, or no diagnostic at all, according to an argument you pass to |
11693 | /// its constructor, thus simplifying the process of creating these "maybe |
11694 | /// deferred" diagnostics. |
11695 | class DeviceDiagBuilder { |
11696 | public: |
11697 | enum Kind { |
11698 | /// Emit no diagnostics. |
11699 | K_Nop, |
11700 | /// Emit the diagnostic immediately (i.e., behave like Sema::Diag()). |
11701 | K_Immediate, |
11702 | /// Emit the diagnostic immediately, and, if it's a warning or error, also |
11703 | /// emit a call stack showing how this function can be reached by an a |
11704 | /// priori known-emitted function. |
11705 | K_ImmediateWithCallStack, |
11706 | /// Create a deferred diagnostic, which is emitted only if the function |
11707 | /// it's attached to is codegen'ed. Also emit a call stack as with |
11708 | /// K_ImmediateWithCallStack. |
11709 | K_Deferred |
11710 | }; |
11711 | |
11712 | DeviceDiagBuilder(Kind K, SourceLocation Loc, unsigned DiagID, |
11713 | FunctionDecl *Fn, Sema &S); |
11714 | DeviceDiagBuilder(DeviceDiagBuilder &&D); |
11715 | DeviceDiagBuilder(const DeviceDiagBuilder &) = default; |
11716 | ~DeviceDiagBuilder(); |
11717 | |
11718 | /// Convertible to bool: True if we immediately emitted an error, false if |
11719 | /// we didn't emit an error or we created a deferred error. |
11720 | /// |
11721 | /// Example usage: |
11722 | /// |
11723 | /// if (DeviceDiagBuilder(...) << foo << bar) |
11724 | /// return ExprError(); |
11725 | /// |
11726 | /// But see CUDADiagIfDeviceCode() and CUDADiagIfHostCode() -- you probably |
11727 | /// want to use these instead of creating a DeviceDiagBuilder yourself. |
11728 | operator bool() const { return ImmediateDiag.hasValue(); } |
11729 | |
11730 | template <typename T> |
11731 | friend const DeviceDiagBuilder &operator<<(const DeviceDiagBuilder &Diag, |
11732 | const T &Value) { |
11733 | if (Diag.ImmediateDiag.hasValue()) |
11734 | *Diag.ImmediateDiag << Value; |
11735 | else if (Diag.PartialDiagId.hasValue()) |
11736 | Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second |
11737 | << Value; |
11738 | return Diag; |
11739 | } |
11740 | |
11741 | private: |
11742 | Sema &S; |
11743 | SourceLocation Loc; |
11744 | unsigned DiagID; |
11745 | FunctionDecl *Fn; |
11746 | bool ShowCallStack; |
11747 | |
11748 | // Invariant: At most one of these Optionals has a value. |
11749 | // FIXME: Switch these to a Variant once that exists. |
11750 | llvm::Optional<SemaDiagnosticBuilder> ImmediateDiag; |
11751 | llvm::Optional<unsigned> PartialDiagId; |
11752 | }; |
11753 | |
11754 | /// Creates a DeviceDiagBuilder that emits the diagnostic if the current context |
11755 | /// is "used as device code". |
11756 | /// |
11757 | /// - If CurContext is a __host__ function, does not emit any diagnostics. |
11758 | /// - If CurContext is a __device__ or __global__ function, emits the |
11759 | /// diagnostics immediately. |
11760 | /// - If CurContext is a __host__ __device__ function and we are compiling for |
11761 | /// the device, creates a diagnostic which is emitted if and when we realize |
11762 | /// that the function will be codegen'ed. |
11763 | /// |
11764 | /// Example usage: |
11765 | /// |
11766 | /// // Variable-length arrays are not allowed in CUDA device code. |
11767 | /// if (CUDADiagIfDeviceCode(Loc, diag::err_cuda_vla) << CurrentCUDATarget()) |
11768 | /// return ExprError(); |
11769 | /// // Otherwise, continue parsing as normal. |
11770 | DeviceDiagBuilder CUDADiagIfDeviceCode(SourceLocation Loc, unsigned DiagID); |
11771 | |
11772 | /// Creates a DeviceDiagBuilder that emits the diagnostic if the current context |
11773 | /// is "used as host code". |
11774 | /// |
11775 | /// Same as CUDADiagIfDeviceCode, with "host" and "device" switched. |
11776 | DeviceDiagBuilder CUDADiagIfHostCode(SourceLocation Loc, unsigned DiagID); |
11777 | |
11778 | /// Creates a DeviceDiagBuilder that emits the diagnostic if the current |
11779 | /// context is "used as device code". |
11780 | /// |
11781 | /// - If CurContext is a `declare target` function or it is known that the |
11782 | /// function is emitted for the device, emits the diagnostics immediately. |
11783 | /// - If CurContext is a non-`declare target` function and we are compiling |
11784 | /// for the device, creates a diagnostic which is emitted if and when we |
11785 | /// realize that the function will be codegen'ed. |
11786 | /// |
11787 | /// Example usage: |
11788 | /// |
11789 | /// // Variable-length arrays are not allowed in NVPTX device code. |
11790 | /// if (diagIfOpenMPDeviceCode(Loc, diag::err_vla_unsupported)) |
11791 | /// return ExprError(); |
11792 | /// // Otherwise, continue parsing as normal. |
11793 | DeviceDiagBuilder diagIfOpenMPDeviceCode(SourceLocation Loc, unsigned DiagID); |
11794 | |
11795 | /// Creates a DeviceDiagBuilder that emits the diagnostic if the current |
11796 | /// context is "used as host code". |
11797 | /// |
11798 | /// - If CurContext is a `declare target` function or it is known that the |
11799 | /// function is emitted for the host, emits the diagnostics immediately. |
11800 | /// - If CurContext is a non-host function, just ignore it. |
11801 | /// |
11802 | /// Example usage: |
11803 | /// |
11804 | /// // Variable-length arrays are not allowed in NVPTX device code. |
11805 | /// if (diagIfOpenMPHostode(Loc, diag::err_vla_unsupported)) |
11806 | /// return ExprError(); |
11807 | /// // Otherwise, continue parsing as normal. |
11808 | DeviceDiagBuilder diagIfOpenMPHostCode(SourceLocation Loc, unsigned DiagID); |
11809 | |
11810 | DeviceDiagBuilder targetDiag(SourceLocation Loc, unsigned DiagID); |
11811 | |
11812 | /// Check if the expression is allowed to be used in expressions for the |
11813 | /// offloading devices. |
11814 | void checkDeviceDecl(const ValueDecl *D, SourceLocation Loc); |
11815 | |
11816 | enum CUDAFunctionTarget { |
11817 | CFT_Device, |
11818 | CFT_Global, |
11819 | CFT_Host, |
11820 | CFT_HostDevice, |
11821 | CFT_InvalidTarget |
11822 | }; |
11823 | |
11824 | /// Determines whether the given function is a CUDA device/host/kernel/etc. |
11825 | /// function. |
11826 | /// |
11827 | /// Use this rather than examining the function's attributes yourself -- you |
11828 | /// will get it wrong. Returns CFT_Host if D is null. |
11829 | CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D, |
11830 | bool IgnoreImplicitHDAttr = false); |
11831 | CUDAFunctionTarget IdentifyCUDATarget(const ParsedAttributesView &Attrs); |
11832 | |
11833 | /// Gets the CUDA target for the current context. |
11834 | CUDAFunctionTarget CurrentCUDATarget() { |
11835 | return IdentifyCUDATarget(dyn_cast<FunctionDecl>(CurContext)); |
11836 | } |
11837 | |
11838 | static bool isCUDAImplicitHostDeviceFunction(const FunctionDecl *D); |
11839 | |
11840 | // CUDA function call preference. Must be ordered numerically from |
11841 | // worst to best. |
11842 | enum CUDAFunctionPreference { |
11843 | CFP_Never, // Invalid caller/callee combination. |
11844 | CFP_WrongSide, // Calls from host-device to host or device |
11845 | // function that do not match current compilation |
11846 | // mode. |
11847 | CFP_HostDevice, // Any calls to host/device functions. |
11848 | CFP_SameSide, // Calls from host-device to host or device |
11849 | // function matching current compilation mode. |
11850 | CFP_Native, // host-to-host or device-to-device calls. |
11851 | }; |
11852 | |
11853 | /// Identifies relative preference of a given Caller/Callee |
11854 | /// combination, based on their host/device attributes. |
11855 | /// \param Caller function which needs address of \p Callee. |
11856 | /// nullptr in case of global context. |
11857 | /// \param Callee target function |
11858 | /// |
11859 | /// \returns preference value for particular Caller/Callee combination. |
11860 | CUDAFunctionPreference IdentifyCUDAPreference(const FunctionDecl *Caller, |
11861 | const FunctionDecl *Callee); |
11862 | |
11863 | /// Determines whether Caller may invoke Callee, based on their CUDA |
11864 | /// host/device attributes. Returns false if the call is not allowed. |
11865 | /// |
11866 | /// Note: Will return true for CFP_WrongSide calls. These may appear in |
11867 | /// semantically correct CUDA programs, but only if they're never codegen'ed. |
11868 | bool IsAllowedCUDACall(const FunctionDecl *Caller, |
11869 | const FunctionDecl *Callee) { |
11870 | return IdentifyCUDAPreference(Caller, Callee) != CFP_Never; |
11871 | } |
11872 | |
11873 | /// May add implicit CUDAHostAttr and CUDADeviceAttr attributes to FD, |
11874 | /// depending on FD and the current compilation settings. |
11875 | void maybeAddCUDAHostDeviceAttrs(FunctionDecl *FD, |
11876 | const LookupResult &Previous); |
11877 | |
11878 | /// May add implicit CUDAConstantAttr attribute to VD, depending on VD |
11879 | /// and current compilation settings. |
11880 | void MaybeAddCUDAConstantAttr(VarDecl *VD); |
11881 | |
11882 | public: |
11883 | /// Check whether we're allowed to call Callee from the current context. |
11884 | /// |
11885 | /// - If the call is never allowed in a semantically-correct program |
11886 | /// (CFP_Never), emits an error and returns false. |
11887 | /// |
11888 | /// - If the call is allowed in semantically-correct programs, but only if |
11889 | /// it's never codegen'ed (CFP_WrongSide), creates a deferred diagnostic to |
11890 | /// be emitted if and when the caller is codegen'ed, and returns true. |
11891 | /// |
11892 | /// Will only create deferred diagnostics for a given SourceLocation once, |
11893 | /// so you can safely call this multiple times without generating duplicate |
11894 | /// deferred errors. |
11895 | /// |
11896 | /// - Otherwise, returns true without emitting any diagnostics. |
11897 | bool CheckCUDACall(SourceLocation Loc, FunctionDecl *Callee); |
11898 | |
11899 | void CUDACheckLambdaCapture(CXXMethodDecl *D, const sema::Capture &Capture); |
11900 | |
11901 | /// Set __device__ or __host__ __device__ attributes on the given lambda |
11902 | /// operator() method. |
11903 | /// |
11904 | /// CUDA lambdas by default is host device function unless it has explicit |
11905 | /// host or device attribute. |
11906 | void CUDASetLambdaAttrs(CXXMethodDecl *Method); |
11907 | |
11908 | /// Finds a function in \p Matches with highest calling priority |
11909 | /// from \p Caller context and erases all functions with lower |
11910 | /// calling priority. |
11911 | void EraseUnwantedCUDAMatches( |
11912 | const FunctionDecl *Caller, |
11913 | SmallVectorImpl<std::pair<DeclAccessPair, FunctionDecl *>> &Matches); |
11914 | |
11915 | /// Given a implicit special member, infer its CUDA target from the |
11916 | /// calls it needs to make to underlying base/field special members. |
11917 | /// \param ClassDecl the class for which the member is being created. |
11918 | /// \param CSM the kind of special member. |
11919 | /// \param MemberDecl the special member itself. |
11920 | /// \param ConstRHS true if this is a copy operation with a const object on |
11921 | /// its RHS. |
11922 | /// \param Diagnose true if this call should emit diagnostics. |
11923 | /// \return true if there was an error inferring. |
11924 | /// The result of this call is implicit CUDA target attribute(s) attached to |
11925 | /// the member declaration. |
11926 | bool inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl, |
11927 | CXXSpecialMember CSM, |
11928 | CXXMethodDecl *MemberDecl, |
11929 | bool ConstRHS, |
11930 | bool Diagnose); |
11931 | |
11932 | /// \return true if \p CD can be considered empty according to CUDA |
11933 | /// (E.2.3.1 in CUDA 7.5 Programming guide). |
11934 | bool isEmptyCudaConstructor(SourceLocation Loc, CXXConstructorDecl *CD); |
11935 | bool isEmptyCudaDestructor(SourceLocation Loc, CXXDestructorDecl *CD); |
11936 | |
11937 | // \brief Checks that initializers of \p Var satisfy CUDA restrictions. In |
11938 | // case of error emits appropriate diagnostic and invalidates \p Var. |
11939 | // |
11940 | // \details CUDA allows only empty constructors as initializers for global |
11941 | // variables (see E.2.3.1, CUDA 7.5). The same restriction also applies to all |
11942 | // __shared__ variables whether they are local or not (they all are implicitly |
11943 | // static in CUDA). One exception is that CUDA allows constant initializers |
11944 | // for __constant__ and __device__ variables. |
11945 | void checkAllowedCUDAInitializer(VarDecl *VD); |
11946 | |
11947 | /// Check whether NewFD is a valid overload for CUDA. Emits |
11948 | /// diagnostics and invalidates NewFD if not. |
11949 | void checkCUDATargetOverload(FunctionDecl *NewFD, |
11950 | const LookupResult &Previous); |
11951 | /// Copies target attributes from the template TD to the function FD. |
11952 | void inheritCUDATargetAttrs(FunctionDecl *FD, const FunctionTemplateDecl &TD); |
11953 | |
11954 | /// Returns the name of the launch configuration function. This is the name |
11955 | /// of the function that will be called to configure kernel call, with the |
11956 | /// parameters specified via <<<>>>. |
11957 | std::string getCudaConfigureFuncName() const; |
11958 | |
11959 | /// \name Code completion |
11960 | //@{ |
11961 | /// Describes the context in which code completion occurs. |
11962 | enum ParserCompletionContext { |
11963 | /// Code completion occurs at top-level or namespace context. |
11964 | PCC_Namespace, |
11965 | /// Code completion occurs within a class, struct, or union. |
11966 | PCC_Class, |
11967 | /// Code completion occurs within an Objective-C interface, protocol, |
11968 | /// or category. |
11969 | PCC_ObjCInterface, |
11970 | /// Code completion occurs within an Objective-C implementation or |
11971 | /// category implementation |
11972 | PCC_ObjCImplementation, |
11973 | /// Code completion occurs within the list of instance variables |
11974 | /// in an Objective-C interface, protocol, category, or implementation. |
11975 | PCC_ObjCInstanceVariableList, |
11976 | /// Code completion occurs following one or more template |
11977 | /// headers. |
11978 | PCC_Template, |
11979 | /// Code completion occurs following one or more template |
11980 | /// headers within a class. |
11981 | PCC_MemberTemplate, |
11982 | /// Code completion occurs within an expression. |
11983 | PCC_Expression, |
11984 | /// Code completion occurs within a statement, which may |
11985 | /// also be an expression or a declaration. |
11986 | PCC_Statement, |
11987 | /// Code completion occurs at the beginning of the |
11988 | /// initialization statement (or expression) in a for loop. |
11989 | PCC_ForInit, |
11990 | /// Code completion occurs within the condition of an if, |
11991 | /// while, switch, or for statement. |
11992 | PCC_Condition, |
11993 | /// Code completion occurs within the body of a function on a |
11994 | /// recovery path, where we do not have a specific handle on our position |
11995 | /// in the grammar. |
11996 | PCC_RecoveryInFunction, |
11997 | /// Code completion occurs where only a type is permitted. |
11998 | PCC_Type, |
11999 | /// Code completion occurs in a parenthesized expression, which |
12000 | /// might also be a type cast. |
12001 | PCC_ParenthesizedExpression, |
12002 | /// Code completion occurs within a sequence of declaration |
12003 | /// specifiers within a function, method, or block. |
12004 | PCC_LocalDeclarationSpecifiers |
12005 | }; |
12006 | |
12007 | void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path); |
12008 | void CodeCompleteOrdinaryName(Scope *S, |
12009 | ParserCompletionContext CompletionContext); |
12010 | void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, |
12011 | bool AllowNonIdentifiers, |
12012 | bool AllowNestedNameSpecifiers); |
12013 | |
12014 | struct CodeCompleteExpressionData; |
12015 | void CodeCompleteExpression(Scope *S, |
12016 | const CodeCompleteExpressionData &Data); |
12017 | void CodeCompleteExpression(Scope *S, QualType PreferredType, |
12018 | bool IsParenthesized = false); |
12019 | void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase, |
12020 | SourceLocation OpLoc, bool IsArrow, |
12021 | bool IsBaseExprStatement, |
12022 | QualType PreferredType); |
12023 | void CodeCompletePostfixExpression(Scope *S, ExprResult LHS, |
12024 | QualType PreferredType); |
12025 | void CodeCompleteTag(Scope *S, unsigned TagSpec); |
12026 | void CodeCompleteTypeQualifiers(DeclSpec &DS); |
12027 | void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D, |
12028 | const VirtSpecifiers *VS = nullptr); |
12029 | void CodeCompleteBracketDeclarator(Scope *S); |
12030 | void CodeCompleteCase(Scope *S); |
12031 | /// Reports signatures for a call to CodeCompleteConsumer and returns the |
12032 | /// preferred type for the current argument. Returned type can be null. |
12033 | QualType ProduceCallSignatureHelp(Scope *S, Expr *Fn, ArrayRef<Expr *> Args, |
12034 | SourceLocation OpenParLoc); |
12035 | QualType ProduceConstructorSignatureHelp(Scope *S, QualType Type, |
12036 | SourceLocation Loc, |
12037 | ArrayRef<Expr *> Args, |
12038 | SourceLocation OpenParLoc); |
12039 | QualType ProduceCtorInitMemberSignatureHelp(Scope *S, Decl *ConstructorDecl, |
12040 | CXXScopeSpec SS, |
12041 | ParsedType TemplateTypeTy, |
12042 | ArrayRef<Expr *> ArgExprs, |
12043 | IdentifierInfo *II, |
12044 | SourceLocation OpenParLoc); |
12045 | void CodeCompleteInitializer(Scope *S, Decl *D); |
12046 | /// Trigger code completion for a record of \p BaseType. \p InitExprs are |
12047 | /// expressions in the initializer list seen so far and \p D is the current |
12048 | /// Designation being parsed. |
12049 | void CodeCompleteDesignator(const QualType BaseType, |
12050 | llvm::ArrayRef<Expr *> InitExprs, |
12051 | const Designation &D); |
12052 | void CodeCompleteAfterIf(Scope *S, bool IsBracedThen); |
12053 | |
12054 | void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext, |
12055 | bool IsUsingDeclaration, QualType BaseType, |
12056 | QualType PreferredType); |
12057 | void CodeCompleteUsing(Scope *S); |
12058 | void CodeCompleteUsingDirective(Scope *S); |
12059 | void CodeCompleteNamespaceDecl(Scope *S); |
12060 | void CodeCompleteNamespaceAliasDecl(Scope *S); |
12061 | void CodeCompleteOperatorName(Scope *S); |
12062 | void CodeCompleteConstructorInitializer( |
12063 | Decl *Constructor, |
12064 | ArrayRef<CXXCtorInitializer *> Initializers); |
12065 | |
12066 | void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, |
12067 | bool AfterAmpersand); |
12068 | void CodeCompleteAfterFunctionEquals(Declarator &D); |
12069 | |
12070 | void CodeCompleteObjCAtDirective(Scope *S); |
12071 | void CodeCompleteObjCAtVisibility(Scope *S); |
12072 | void CodeCompleteObjCAtStatement(Scope *S); |
12073 | void CodeCompleteObjCAtExpression(Scope *S); |
12074 | void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); |
12075 | void CodeCompleteObjCPropertyGetter(Scope *S); |
12076 | void CodeCompleteObjCPropertySetter(Scope *S); |
12077 | void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, |
12078 | bool IsParameter); |
12079 | void CodeCompleteObjCMessageReceiver(Scope *S); |
12080 | void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, |
12081 | ArrayRef<IdentifierInfo *> SelIdents, |
12082 | bool AtArgumentExpression); |
12083 | void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, |
12084 | ArrayRef<IdentifierInfo *> SelIdents, |
12085 | bool AtArgumentExpression, |
12086 | bool IsSuper = false); |
12087 | void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, |
12088 | ArrayRef<IdentifierInfo *> SelIdents, |
12089 | bool AtArgumentExpression, |
12090 | ObjCInterfaceDecl *Super = nullptr); |
12091 | void CodeCompleteObjCForCollection(Scope *S, |
12092 | DeclGroupPtrTy IterationVar); |
12093 | void CodeCompleteObjCSelector(Scope *S, |
12094 | ArrayRef<IdentifierInfo *> SelIdents); |
12095 | void CodeCompleteObjCProtocolReferences( |
12096 | ArrayRef<IdentifierLocPair> Protocols); |
12097 | void CodeCompleteObjCProtocolDecl(Scope *S); |
12098 | void CodeCompleteObjCInterfaceDecl(Scope *S); |
12099 | void CodeCompleteObjCSuperclass(Scope *S, |
12100 | IdentifierInfo *ClassName, |
12101 | SourceLocation ClassNameLoc); |
12102 | void CodeCompleteObjCImplementationDecl(Scope *S); |
12103 | void CodeCompleteObjCInterfaceCategory(Scope *S, |
12104 | IdentifierInfo *ClassName, |
12105 | SourceLocation ClassNameLoc); |
12106 | void CodeCompleteObjCImplementationCategory(Scope *S, |
12107 | IdentifierInfo *ClassName, |
12108 | SourceLocation ClassNameLoc); |
12109 | void CodeCompleteObjCPropertyDefinition(Scope *S); |
12110 | void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, |
12111 | IdentifierInfo *PropertyName); |
12112 | void CodeCompleteObjCMethodDecl(Scope *S, Optional<bool> IsInstanceMethod, |
12113 | ParsedType ReturnType); |
12114 | void CodeCompleteObjCMethodDeclSelector(Scope *S, |
12115 | bool IsInstanceMethod, |
12116 | bool AtParameterName, |
12117 | ParsedType ReturnType, |
12118 | ArrayRef<IdentifierInfo *> SelIdents); |
12119 | void CodeCompleteObjCClassPropertyRefExpr(Scope *S, IdentifierInfo &ClassName, |
12120 | SourceLocation ClassNameLoc, |
12121 | bool IsBaseExprStatement); |
12122 | void CodeCompletePreprocessorDirective(bool InConditional); |
12123 | void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); |
12124 | void CodeCompletePreprocessorMacroName(bool IsDefinition); |
12125 | void CodeCompletePreprocessorExpression(); |
12126 | void CodeCompletePreprocessorMacroArgument(Scope *S, |
12127 | IdentifierInfo *Macro, |
12128 | MacroInfo *MacroInfo, |
12129 | unsigned Argument); |
12130 | void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled); |
12131 | void CodeCompleteNaturalLanguage(); |
12132 | void CodeCompleteAvailabilityPlatformName(); |
12133 | void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, |
12134 | CodeCompletionTUInfo &CCTUInfo, |
12135 | SmallVectorImpl<CodeCompletionResult> &Results); |
12136 | //@} |
12137 | |
12138 | //===--------------------------------------------------------------------===// |
12139 | // Extra semantic analysis beyond the C type system |
12140 | |
12141 | public: |
12142 | SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, |
12143 | unsigned ByteNo) const; |
12144 | |
12145 | private: |
12146 | void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, |
12147 | const ArraySubscriptExpr *ASE=nullptr, |
12148 | bool AllowOnePastEnd=true, bool IndexNegated=false); |
12149 | void CheckArrayAccess(const Expr *E); |
12150 | // Used to grab the relevant information from a FormatAttr and a |
12151 | // FunctionDeclaration. |
12152 | struct FormatStringInfo { |
12153 | unsigned FormatIdx; |
12154 | unsigned FirstDataArg; |
12155 | bool HasVAListArg; |
12156 | }; |
12157 | |
12158 | static bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember, |
12159 | FormatStringInfo *FSI); |
12160 | bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, |
12161 | const FunctionProtoType *Proto); |
12162 | bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc, |
12163 | ArrayRef<const Expr *> Args); |
12164 | bool CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall, |
12165 | const FunctionProtoType *Proto); |
12166 | bool CheckOtherCall(CallExpr *TheCall, const FunctionProtoType *Proto); |
12167 | void CheckConstructorCall(FunctionDecl *FDecl, |
12168 | ArrayRef<const Expr *> Args, |
12169 | const FunctionProtoType *Proto, |
12170 | SourceLocation Loc); |
12171 | |
12172 | void checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, |
12173 | const Expr *ThisArg, ArrayRef<const Expr *> Args, |
12174 | bool IsMemberFunction, SourceLocation Loc, SourceRange Range, |
12175 | VariadicCallType CallType); |
12176 | |
12177 | bool CheckObjCString(Expr *Arg); |
12178 | ExprResult CheckOSLogFormatStringArg(Expr *Arg); |
12179 | |
12180 | ExprResult CheckBuiltinFunctionCall(FunctionDecl *FDecl, |
12181 | unsigned BuiltinID, CallExpr *TheCall); |
12182 | |
12183 | bool CheckTSBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12184 | CallExpr *TheCall); |
12185 | |
12186 | void checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD, CallExpr *TheCall); |
12187 | |
12188 | bool CheckARMBuiltinExclusiveCall(unsigned BuiltinID, CallExpr *TheCall, |
12189 | unsigned MaxWidth); |
12190 | bool CheckNeonBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12191 | CallExpr *TheCall); |
12192 | bool CheckMVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
12193 | bool CheckSVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
12194 | bool CheckCDEBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12195 | CallExpr *TheCall); |
12196 | bool CheckARMCoprocessorImmediate(const TargetInfo &TI, const Expr *CoprocArg, |
12197 | bool WantCDE); |
12198 | bool CheckARMBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12199 | CallExpr *TheCall); |
12200 | |
12201 | bool CheckAArch64BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12202 | CallExpr *TheCall); |
12203 | bool CheckBPFBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
12204 | bool CheckHexagonBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
12205 | bool CheckHexagonBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall); |
12206 | bool CheckMipsBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12207 | CallExpr *TheCall); |
12208 | bool CheckMipsBuiltinCpu(const TargetInfo &TI, unsigned BuiltinID, |
12209 | CallExpr *TheCall); |
12210 | bool CheckMipsBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall); |
12211 | bool CheckSystemZBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
12212 | bool CheckX86BuiltinRoundingOrSAE(unsigned BuiltinID, CallExpr *TheCall); |
12213 | bool CheckX86BuiltinGatherScatterScale(unsigned BuiltinID, CallExpr *TheCall); |
12214 | bool CheckX86BuiltinTileArguments(unsigned BuiltinID, CallExpr *TheCall); |
12215 | bool CheckX86BuiltinTileArgumentsRange(CallExpr *TheCall, |
12216 | ArrayRef<int> ArgNums); |
12217 | bool CheckX86BuiltinTileDuplicate(CallExpr *TheCall, ArrayRef<int> ArgNums); |
12218 | bool CheckX86BuiltinTileRangeAndDuplicate(CallExpr *TheCall, |
12219 | ArrayRef<int> ArgNums); |
12220 | bool CheckX86BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12221 | CallExpr *TheCall); |
12222 | bool CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12223 | CallExpr *TheCall); |
12224 | bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
12225 | |
12226 | bool SemaBuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall); |
12227 | bool SemaBuiltinVAStartARMMicrosoft(CallExpr *Call); |
12228 | bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); |
12229 | bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); |
12230 | bool SemaBuiltinComplex(CallExpr *TheCall); |
12231 | bool SemaBuiltinVSX(CallExpr *TheCall); |
12232 | bool SemaBuiltinOSLogFormat(CallExpr *TheCall); |
12233 | |
12234 | public: |
12235 | // Used by C++ template instantiation. |
12236 | ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); |
12237 | ExprResult SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo, |
12238 | SourceLocation BuiltinLoc, |
12239 | SourceLocation RParenLoc); |
12240 | |
12241 | private: |
12242 | bool SemaBuiltinPrefetch(CallExpr *TheCall); |
12243 | bool SemaBuiltinAllocaWithAlign(CallExpr *TheCall); |
12244 | bool SemaBuiltinAssume(CallExpr *TheCall); |
12245 | bool SemaBuiltinAssumeAligned(CallExpr *TheCall); |
12246 | bool SemaBuiltinLongjmp(CallExpr *TheCall); |
12247 | bool SemaBuiltinSetjmp(CallExpr *TheCall); |
12248 | ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); |
12249 | ExprResult SemaBuiltinNontemporalOverloaded(ExprResult TheCallResult); |
12250 | ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult, |
12251 | AtomicExpr::AtomicOp Op); |
12252 | ExprResult SemaBuiltinOperatorNewDeleteOverloaded(ExprResult TheCallResult, |
12253 | bool IsDelete); |
12254 | bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, |
12255 | llvm::APSInt &Result); |
12256 | bool SemaBuiltinConstantArgRange(CallExpr *TheCall, int ArgNum, int Low, |
12257 | int High, bool RangeIsError = true); |
12258 | bool SemaBuiltinConstantArgMultiple(CallExpr *TheCall, int ArgNum, |
12259 | unsigned Multiple); |
12260 | bool SemaBuiltinConstantArgPower2(CallExpr *TheCall, int ArgNum); |
12261 | bool SemaBuiltinConstantArgShiftedByte(CallExpr *TheCall, int ArgNum, |
12262 | unsigned ArgBits); |
12263 | bool SemaBuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall, int ArgNum, |
12264 | unsigned ArgBits); |
12265 | bool SemaBuiltinARMSpecialReg(unsigned BuiltinID, CallExpr *TheCall, |
12266 | int ArgNum, unsigned ExpectedFieldNum, |
12267 | bool AllowName); |
12268 | bool SemaBuiltinARMMemoryTaggingCall(unsigned BuiltinID, CallExpr *TheCall); |
12269 | |
12270 | // Matrix builtin handling. |
12271 | ExprResult SemaBuiltinMatrixTranspose(CallExpr *TheCall, |
12272 | ExprResult CallResult); |
12273 | ExprResult SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall, |
12274 | ExprResult CallResult); |
12275 | ExprResult SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall, |
12276 | ExprResult CallResult); |
12277 | |
12278 | public: |
12279 | enum FormatStringType { |
12280 | FST_Scanf, |
12281 | FST_Printf, |
12282 | FST_NSString, |
12283 | FST_Strftime, |
12284 | FST_Strfmon, |
12285 | FST_Kprintf, |
12286 | FST_FreeBSDKPrintf, |
12287 | FST_OSTrace, |
12288 | FST_OSLog, |
12289 | FST_Unknown |
12290 | }; |
12291 | static FormatStringType GetFormatStringType(const FormatAttr *Format); |
12292 | |
12293 | bool FormatStringHasSArg(const StringLiteral *FExpr); |
12294 | |
12295 | static bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx); |
12296 | |
12297 | private: |
12298 | bool CheckFormatArguments(const FormatAttr *Format, |
12299 | ArrayRef<const Expr *> Args, |
12300 | bool IsCXXMember, |
12301 | VariadicCallType CallType, |
12302 | SourceLocation Loc, SourceRange Range, |
12303 | llvm::SmallBitVector &CheckedVarArgs); |
12304 | bool CheckFormatArguments(ArrayRef<const Expr *> Args, |
12305 | bool HasVAListArg, unsigned format_idx, |
12306 | unsigned firstDataArg, FormatStringType Type, |
12307 | VariadicCallType CallType, |
12308 | SourceLocation Loc, SourceRange range, |
12309 | llvm::SmallBitVector &CheckedVarArgs); |
12310 | |
12311 | void CheckAbsoluteValueFunction(const CallExpr *Call, |
12312 | const FunctionDecl *FDecl); |
12313 | |
12314 | void CheckMaxUnsignedZero(const CallExpr *Call, const FunctionDecl *FDecl); |
12315 | |
12316 | void CheckMemaccessArguments(const CallExpr *Call, |
12317 | unsigned BId, |
12318 | IdentifierInfo *FnName); |
12319 | |
12320 | void CheckStrlcpycatArguments(const CallExpr *Call, |
12321 | IdentifierInfo *FnName); |
12322 | |
12323 | void CheckStrncatArguments(const CallExpr *Call, |
12324 | IdentifierInfo *FnName); |
12325 | |
12326 | void CheckReturnValExpr(Expr *RetValExp, QualType lhsType, |
12327 | SourceLocation ReturnLoc, |
12328 | bool isObjCMethod = false, |
12329 | const AttrVec *Attrs = nullptr, |
12330 | const FunctionDecl *FD = nullptr); |
12331 | |
12332 | public: |
12333 | void CheckFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS); |
12334 | |
12335 | private: |
12336 | void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); |
12337 | void CheckBoolLikeConversion(Expr *E, SourceLocation CC); |
12338 | void CheckForIntOverflow(Expr *E); |
12339 | void CheckUnsequencedOperations(const Expr *E); |
12340 | |
12341 | /// Perform semantic checks on a completed expression. This will either |
12342 | /// be a full-expression or a default argument expression. |
12343 | void CheckCompletedExpr(Expr *E, SourceLocation CheckLoc = SourceLocation(), |
12344 | bool IsConstexpr = false); |
12345 | |
12346 | void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, |
12347 | Expr *Init); |
12348 | |
12349 | /// Check if there is a field shadowing. |
12350 | void CheckShadowInheritedFields(const SourceLocation &Loc, |
12351 | DeclarationName FieldName, |
12352 | const CXXRecordDecl *RD, |
12353 | bool DeclIsField = true); |
12354 | |
12355 | /// Check if the given expression contains 'break' or 'continue' |
12356 | /// statement that produces control flow different from GCC. |
12357 | void CheckBreakContinueBinding(Expr *E); |
12358 | |
12359 | /// Check whether receiver is mutable ObjC container which |
12360 | /// attempts to add itself into the container |
12361 | void CheckObjCCircularContainer(ObjCMessageExpr *Message); |
12362 | |
12363 | void AnalyzeDeleteExprMismatch(const CXXDeleteExpr *DE); |
12364 | void AnalyzeDeleteExprMismatch(FieldDecl *Field, SourceLocation DeleteLoc, |
12365 | bool DeleteWasArrayForm); |
12366 | public: |
12367 | /// Register a magic integral constant to be used as a type tag. |
12368 | void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind, |
12369 | uint64_t MagicValue, QualType Type, |
12370 | bool LayoutCompatible, bool MustBeNull); |
12371 | |
12372 | struct TypeTagData { |
12373 | TypeTagData() {} |
12374 | |
12375 | TypeTagData(QualType Type, bool LayoutCompatible, bool MustBeNull) : |
12376 | Type(Type), LayoutCompatible(LayoutCompatible), |
12377 | MustBeNull(MustBeNull) |
12378 | {} |
12379 | |
12380 | QualType Type; |
12381 | |
12382 | /// If true, \c Type should be compared with other expression's types for |
12383 | /// layout-compatibility. |
12384 | unsigned LayoutCompatible : 1; |
12385 | unsigned MustBeNull : 1; |
12386 | }; |
12387 | |
12388 | /// A pair of ArgumentKind identifier and magic value. This uniquely |
12389 | /// identifies the magic value. |
12390 | typedef std::pair<const IdentifierInfo *, uint64_t> TypeTagMagicValue; |
12391 | |
12392 | private: |
12393 | /// A map from magic value to type information. |
12394 | std::unique_ptr<llvm::DenseMap<TypeTagMagicValue, TypeTagData>> |
12395 | TypeTagForDatatypeMagicValues; |
12396 | |
12397 | /// Peform checks on a call of a function with argument_with_type_tag |
12398 | /// or pointer_with_type_tag attributes. |
12399 | void CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr, |
12400 | const ArrayRef<const Expr *> ExprArgs, |
12401 | SourceLocation CallSiteLoc); |
12402 | |
12403 | /// Check if we are taking the address of a packed field |
12404 | /// as this may be a problem if the pointer value is dereferenced. |
12405 | void CheckAddressOfPackedMember(Expr *rhs); |
12406 | |
12407 | /// The parser's current scope. |
12408 | /// |
12409 | /// The parser maintains this state here. |
12410 | Scope *CurScope; |
12411 | |
12412 | mutable IdentifierInfo *Ident_super; |
12413 | mutable IdentifierInfo *Ident___float128; |
12414 | |
12415 | /// Nullability type specifiers. |
12416 | IdentifierInfo *Ident__Nonnull = nullptr; |
12417 | IdentifierInfo *Ident__Nullable = nullptr; |
12418 | IdentifierInfo *Ident__Null_unspecified = nullptr; |
12419 | |
12420 | IdentifierInfo *Ident_NSError = nullptr; |
12421 | |
12422 | /// The handler for the FileChanged preprocessor events. |
12423 | /// |
12424 | /// Used for diagnostics that implement custom semantic analysis for #include |
12425 | /// directives, like -Wpragma-pack. |
12426 | sema::SemaPPCallbacks *SemaPPCallbackHandler; |
12427 | |
12428 | protected: |
12429 | friend class Parser; |
12430 | friend class InitializationSequence; |
12431 | friend class ASTReader; |
12432 | friend class ASTDeclReader; |
12433 | friend class ASTWriter; |
12434 | |
12435 | public: |
12436 | /// Retrieve the keyword associated |
12437 | IdentifierInfo *getNullabilityKeyword(NullabilityKind nullability); |
12438 | |
12439 | /// The struct behind the CFErrorRef pointer. |
12440 | RecordDecl *CFError = nullptr; |
12441 | bool isCFError(RecordDecl *D); |
12442 | |
12443 | /// Retrieve the identifier "NSError". |
12444 | IdentifierInfo *getNSErrorIdent(); |
12445 | |
12446 | /// Retrieve the parser's current scope. |
12447 | /// |
12448 | /// This routine must only be used when it is certain that semantic analysis |
12449 | /// and the parser are in precisely the same context, which is not the case |
12450 | /// when, e.g., we are performing any kind of template instantiation. |
12451 | /// Therefore, the only safe places to use this scope are in the parser |
12452 | /// itself and in routines directly invoked from the parser and *never* from |
12453 | /// template substitution or instantiation. |
12454 | Scope *getCurScope() const { return CurScope; } |
12455 | |
12456 | void incrementMSManglingNumber() const { |
12457 | return CurScope->incrementMSManglingNumber(); |
12458 | } |
12459 | |
12460 | IdentifierInfo *getSuperIdentifier() const; |
12461 | IdentifierInfo *getFloat128Identifier() const; |
12462 | |
12463 | Decl *getObjCDeclContext() const; |
12464 | |
12465 | DeclContext *getCurLexicalContext() const { |
12466 | return OriginalLexicalContext ? OriginalLexicalContext : CurContext; |
12467 | } |
12468 | |
12469 | const DeclContext *getCurObjCLexicalContext() const { |
12470 | const DeclContext *DC = getCurLexicalContext(); |
12471 | // A category implicitly has the attribute of the interface. |
12472 | if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(DC)) |
12473 | DC = CatD->getClassInterface(); |
12474 | return DC; |
12475 | } |
12476 | |
12477 | /// Determine the number of levels of enclosing template parameters. This is |
12478 | /// only usable while parsing. Note that this does not include dependent |
12479 | /// contexts in which no template parameters have yet been declared, such as |
12480 | /// in a terse function template or generic lambda before the first 'auto' is |
12481 | /// encountered. |
12482 | unsigned getTemplateDepth(Scope *S) const; |
12483 | |
12484 | /// To be used for checking whether the arguments being passed to |
12485 | /// function exceeds the number of parameters expected for it. |
12486 | static bool TooManyArguments(size_t NumParams, size_t NumArgs, |
12487 | bool PartialOverloading = false) { |
12488 | // We check whether we're just after a comma in code-completion. |
12489 | if (NumArgs > 0 && PartialOverloading) |
12490 | return NumArgs + 1 > NumParams; // If so, we view as an extra argument. |
12491 | return NumArgs > NumParams; |
12492 | } |
12493 | |
12494 | // Emitting members of dllexported classes is delayed until the class |
12495 | // (including field initializers) is fully parsed. |
12496 | SmallVector<CXXRecordDecl*, 4> DelayedDllExportClasses; |
12497 | SmallVector<CXXMethodDecl*, 4> DelayedDllExportMemberFunctions; |
12498 | |
12499 | private: |
12500 | int ParsingClassDepth = 0; |
12501 | |
12502 | class SavePendingParsedClassStateRAII { |
12503 | public: |
12504 | SavePendingParsedClassStateRAII(Sema &S) : S(S) { swapSavedState(); } |
12505 | |
12506 | ~SavePendingParsedClassStateRAII() { |
12507 | assert(S.DelayedOverridingExceptionSpecChecks.empty() &&((S.DelayedOverridingExceptionSpecChecks.empty() && "there shouldn't be any pending delayed exception spec checks" ) ? static_cast<void> (0) : __assert_fail ("S.DelayedOverridingExceptionSpecChecks.empty() && \"there shouldn't be any pending delayed exception spec checks\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 12508, __PRETTY_FUNCTION__)) |
12508 | "there shouldn't be any pending delayed exception spec checks")((S.DelayedOverridingExceptionSpecChecks.empty() && "there shouldn't be any pending delayed exception spec checks" ) ? static_cast<void> (0) : __assert_fail ("S.DelayedOverridingExceptionSpecChecks.empty() && \"there shouldn't be any pending delayed exception spec checks\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 12508, __PRETTY_FUNCTION__)); |
12509 | assert(S.DelayedEquivalentExceptionSpecChecks.empty() &&((S.DelayedEquivalentExceptionSpecChecks.empty() && "there shouldn't be any pending delayed exception spec checks" ) ? static_cast<void> (0) : __assert_fail ("S.DelayedEquivalentExceptionSpecChecks.empty() && \"there shouldn't be any pending delayed exception spec checks\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 12510, __PRETTY_FUNCTION__)) |
12510 | "there shouldn't be any pending delayed exception spec checks")((S.DelayedEquivalentExceptionSpecChecks.empty() && "there shouldn't be any pending delayed exception spec checks" ) ? static_cast<void> (0) : __assert_fail ("S.DelayedEquivalentExceptionSpecChecks.empty() && \"there shouldn't be any pending delayed exception spec checks\"" , "/build/llvm-toolchain-snapshot-12~++20200927111121+5811d723998/clang/include/clang/Sema/Sema.h" , 12510, __PRETTY_FUNCTION__)); |
12511 | swapSavedState(); |
12512 | } |
12513 | |
12514 | private: |
12515 | Sema &S; |
12516 | decltype(DelayedOverridingExceptionSpecChecks) |
12517 | SavedOverridingExceptionSpecChecks; |
12518 | decltype(DelayedEquivalentExceptionSpecChecks) |
12519 | SavedEquivalentExceptionSpecChecks; |
12520 | |
12521 | void swapSavedState() { |
12522 | SavedOverridingExceptionSpecChecks.swap( |
12523 | S.DelayedOverridingExceptionSpecChecks); |
12524 | SavedEquivalentExceptionSpecChecks.swap( |
12525 | S.DelayedEquivalentExceptionSpecChecks); |
12526 | } |
12527 | }; |
12528 | |
12529 | /// Helper class that collects misaligned member designations and |
12530 | /// their location info for delayed diagnostics. |
12531 | struct MisalignedMember { |
12532 | Expr *E; |
12533 | RecordDecl *RD; |
12534 | ValueDecl *MD; |
12535 | CharUnits Alignment; |
12536 | |
12537 | MisalignedMember() : E(), RD(), MD(), Alignment() {} |
12538 | MisalignedMember(Expr *E, RecordDecl *RD, ValueDecl *MD, |
12539 | CharUnits Alignment) |
12540 | : E(E), RD(RD), MD(MD), Alignment(Alignment) {} |
12541 | explicit MisalignedMember(Expr *E) |
12542 | : MisalignedMember(E, nullptr, nullptr, CharUnits()) {} |
12543 | |
12544 | bool operator==(const MisalignedMember &m) { return this->E == m.E; } |
12545 | }; |
12546 | /// Small set of gathered accesses to potentially misaligned members |
12547 | /// due to the packed attribute. |
12548 | SmallVector<MisalignedMember, 4> MisalignedMembers; |
12549 | |
12550 | /// Adds an expression to the set of gathered misaligned members. |
12551 | void AddPotentialMisalignedMembers(Expr *E, RecordDecl *RD, ValueDecl *MD, |
12552 | CharUnits Alignment); |
12553 | |
12554 | public: |
12555 | /// Diagnoses the current set of gathered accesses. This typically |
12556 | /// happens at full expression level. The set is cleared after emitting the |
12557 | /// diagnostics. |
12558 | void DiagnoseMisalignedMembers(); |
12559 | |
12560 | /// This function checks if the expression is in the sef of potentially |
12561 | /// misaligned members and it is converted to some pointer type T with lower |
12562 | /// or equal alignment requirements. If so it removes it. This is used when |
12563 | /// we do not want to diagnose such misaligned access (e.g. in conversions to |
12564 | /// void*). |
12565 | void DiscardMisalignedMemberAddress(const Type *T, Expr *E); |
12566 | |
12567 | /// This function calls Action when it determines that E designates a |
12568 | /// misaligned member due to the packed attribute. This is used to emit |
12569 | /// local diagnostics like in reference binding. |
12570 | void RefersToMemberWithReducedAlignment( |
12571 | Expr *E, |
12572 | llvm::function_ref<void(Expr *, RecordDecl *, FieldDecl *, CharUnits)> |
12573 | Action); |
12574 | |
12575 | /// Describes the reason a calling convention specification was ignored, used |
12576 | /// for diagnostics. |
12577 | enum class CallingConventionIgnoredReason { |
12578 | ForThisTarget = 0, |
12579 | VariadicFunction, |
12580 | ConstructorDestructor, |
12581 | BuiltinFunction |
12582 | }; |
12583 | /// Creates a DeviceDiagBuilder that emits the diagnostic if the current |
12584 | /// context is "used as device code". |
12585 | /// |
12586 | /// - If CurLexicalContext is a kernel function or it is known that the |
12587 | /// function will be emitted for the device, emits the diagnostics |
12588 | /// immediately. |
12589 | /// - If CurLexicalContext is a function and we are compiling |
12590 | /// for the device, but we don't know that this function will be codegen'ed |
12591 | /// for devive yet, creates a diagnostic which is emitted if and when we |
12592 | /// realize that the function will be codegen'ed. |
12593 | /// |
12594 | /// Example usage: |
12595 | /// |
12596 | /// Diagnose __float128 type usage only from SYCL device code if the current |
12597 | /// target doesn't support it |
12598 | /// if (!S.Context.getTargetInfo().hasFloat128Type() && |
12599 | /// S.getLangOpts().SYCLIsDevice) |
12600 | /// SYCLDiagIfDeviceCode(Loc, diag::err_type_unsupported) << "__float128"; |
12601 | DeviceDiagBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, unsigned DiagID); |
12602 | |
12603 | /// Check whether we're allowed to call Callee from the current context. |
12604 | /// |
12605 | /// - If the call is never allowed in a semantically-correct program |
12606 | /// emits an error and returns false. |
12607 | /// |
12608 | /// - If the call is allowed in semantically-correct programs, but only if |
12609 | /// it's never codegen'ed, creates a deferred diagnostic to be emitted if |
12610 | /// and when the caller is codegen'ed, and returns true. |
12611 | /// |
12612 | /// - Otherwise, returns true without emitting any diagnostics. |
12613 | /// |
12614 | /// Adds Callee to DeviceCallGraph if we don't know if its caller will be |
12615 | /// codegen'ed yet. |
12616 | bool checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee); |
12617 | }; |
12618 | |
12619 | /// RAII object that enters a new expression evaluation context. |
12620 | class EnterExpressionEvaluationContext { |
12621 | Sema &Actions; |
12622 | bool Entered = true; |
12623 | |
12624 | public: |
12625 | EnterExpressionEvaluationContext( |
12626 | Sema &Actions, Sema::ExpressionEvaluationContext NewContext, |
12627 | Decl *LambdaContextDecl = nullptr, |
12628 | Sema::ExpressionEvaluationContextRecord::ExpressionKind ExprContext = |
12629 | Sema::ExpressionEvaluationContextRecord::EK_Other, |
12630 | bool ShouldEnter = true) |
12631 | : Actions(Actions), Entered(ShouldEnter) { |
12632 | if (Entered) |
12633 | Actions.PushExpressionEvaluationContext(NewContext, LambdaContextDecl, |
12634 | ExprContext); |
12635 | } |
12636 | EnterExpressionEvaluationContext( |
12637 | Sema &Actions, Sema::ExpressionEvaluationContext NewContext, |
12638 | Sema::ReuseLambdaContextDecl_t, |
12639 | Sema::ExpressionEvaluationContextRecord::ExpressionKind ExprContext = |
12640 | Sema::ExpressionEvaluationContextRecord::EK_Other) |
12641 | : Actions(Actions) { |
12642 | Actions.PushExpressionEvaluationContext( |
12643 | NewContext, Sema::ReuseLambdaContextDecl, ExprContext); |
12644 | } |
12645 | |
12646 | enum InitListTag { InitList }; |
12647 | EnterExpressionEvaluationContext(Sema &Actions, InitListTag, |
12648 | bool ShouldEnter = true) |
12649 | : Actions(Actions), Entered(false) { |
12650 | // In C++11 onwards, narrowing checks are performed on the contents of |
12651 | // braced-init-lists, even when they occur within unevaluated operands. |
12652 | // Therefore we still need to instantiate constexpr functions used in such |
12653 | // a context. |
12654 | if (ShouldEnter && Actions.isUnevaluatedContext() && |
12655 | Actions.getLangOpts().CPlusPlus11) { |
12656 | Actions.PushExpressionEvaluationContext( |
12657 | Sema::ExpressionEvaluationContext::UnevaluatedList); |
12658 | Entered = true; |
12659 | } |
12660 | } |
12661 | |
12662 | ~EnterExpressionEvaluationContext() { |
12663 | if (Entered) |
12664 | Actions.PopExpressionEvaluationContext(); |
12665 | } |
12666 | }; |
12667 | |
12668 | DeductionFailureInfo |
12669 | MakeDeductionFailureInfo(ASTContext &Context, Sema::TemplateDeductionResult TDK, |
12670 | sema::TemplateDeductionInfo &Info); |
12671 | |
12672 | /// Contains a late templated function. |
12673 | /// Will be parsed at the end of the translation unit, used by Sema & Parser. |
12674 | struct LateParsedTemplate { |
12675 | CachedTokens Toks; |
12676 | /// The template function declaration to be late parsed. |
12677 | Decl *D; |
12678 | }; |
12679 | } // end namespace clang |
12680 | |
12681 | namespace llvm { |
12682 | // Hash a FunctionDeclAndLoc by looking at both its FunctionDecl and its |
12683 | // SourceLocation. |
12684 | template <> struct DenseMapInfo<clang::Sema::FunctionDeclAndLoc> { |
12685 | using FunctionDeclAndLoc = clang::Sema::FunctionDeclAndLoc; |
12686 | using FDBaseInfo = DenseMapInfo<clang::CanonicalDeclPtr<clang::FunctionDecl>>; |
12687 | |
12688 | static FunctionDeclAndLoc getEmptyKey() { |
12689 | return {FDBaseInfo::getEmptyKey(), clang::SourceLocation()}; |
12690 | } |
12691 | |
12692 | static FunctionDeclAndLoc getTombstoneKey() { |
12693 | return {FDBaseInfo::getTombstoneKey(), clang::SourceLocation()}; |
12694 | } |
12695 | |
12696 | static unsigned getHashValue(const FunctionDeclAndLoc &FDL) { |
12697 | return hash_combine(FDBaseInfo::getHashValue(FDL.FD), |
12698 | FDL.Loc.getRawEncoding()); |
12699 | } |
12700 | |
12701 | static bool isEqual(const FunctionDeclAndLoc &LHS, |
12702 | const FunctionDeclAndLoc &RHS) { |
12703 | return LHS.FD == RHS.FD && LHS.Loc == RHS.Loc; |
12704 | } |
12705 | }; |
12706 | } // namespace llvm |
12707 | |
12708 | #endif |