File: | clang/lib/Sema/SemaTemplateInstantiate.cpp |
Warning: | line 2795, 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?")(static_cast <bool> (Spec->getSpecializedTemplate() && "No variable template?") ? void (0) : __assert_fail ("Spec->getSpecializedTemplate() && \"No variable template?\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 88, __extension__ __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?")(static_cast <bool> (Spec->getSpecializedTemplate() && "No class template?") ? void (0) : __assert_fail ("Spec->getSpecializedTemplate() && \"No class template?\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 133, __extension__ __PRETTY_FUNCTION__)); | ||||
134 | if (Spec->getSpecializedTemplate()->isMemberSpecialization()) | ||||
135 | break; | ||||
136 | } | ||||
137 | // Add template arguments from a function template specialization. | ||||
138 | else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) { | ||||
139 | if (!RelativeToPrimary && | ||||
140 | Function->getTemplateSpecializationKindForInstantiation() == | ||||
141 | TSK_ExplicitSpecialization) | ||||
142 | break; | ||||
143 | |||||
144 | if (!RelativeToPrimary && Function->getTemplateSpecializationKind() == | ||||
145 | TSK_ExplicitSpecialization) { | ||||
146 | // This is an implicit instantiation of an explicit specialization. We | ||||
147 | // don't get any template arguments from this function but might get | ||||
148 | // some from an enclosing template. | ||||
149 | } else if (const TemplateArgumentList *TemplateArgs | ||||
150 | = Function->getTemplateSpecializationArgs()) { | ||||
151 | // Add the template arguments for this specialization. | ||||
152 | Result.addOuterTemplateArguments(TemplateArgs); | ||||
153 | |||||
154 | // If this function was instantiated from a specialized member that is | ||||
155 | // a function template, we're done. | ||||
156 | assert(Function->getPrimaryTemplate() && "No function template?")(static_cast <bool> (Function->getPrimaryTemplate() && "No function template?") ? void (0) : __assert_fail ("Function->getPrimaryTemplate() && \"No function template?\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 156, __extension__ __PRETTY_FUNCTION__)); | ||||
157 | if (Function->getPrimaryTemplate()->isMemberSpecialization()) | ||||
158 | break; | ||||
159 | |||||
160 | // If this function is a generic lambda specialization, we are done. | ||||
161 | if (isGenericLambdaCallOperatorOrStaticInvokerSpecialization(Function)) | ||||
162 | break; | ||||
163 | |||||
164 | } else if (Function->getDescribedFunctionTemplate()) { | ||||
165 | assert(Result.getNumSubstitutedLevels() == 0 &&(static_cast <bool> (Result.getNumSubstitutedLevels() == 0 && "Outer template not instantiated?") ? void (0) : __assert_fail ("Result.getNumSubstitutedLevels() == 0 && \"Outer template not instantiated?\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 166, __extension__ __PRETTY_FUNCTION__)) | ||||
166 | "Outer template not instantiated?")(static_cast <bool> (Result.getNumSubstitutedLevels() == 0 && "Outer template not instantiated?") ? void (0) : __assert_fail ("Result.getNumSubstitutedLevels() == 0 && \"Outer template not instantiated?\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 166, __extension__ __PRETTY_FUNCTION__)); | ||||
167 | } | ||||
168 | |||||
169 | // If this is a friend declaration and it declares an entity at | ||||
170 | // namespace scope, take arguments from its lexical parent | ||||
171 | // instead of its semantic parent, unless of course the pattern we're | ||||
172 | // instantiating actually comes from the file's context! | ||||
173 | if (Function->getFriendObjectKind() && | ||||
174 | Function->getDeclContext()->isFileContext() && | ||||
175 | (!Pattern || !Pattern->getLexicalDeclContext()->isFileContext())) { | ||||
176 | Ctx = Function->getLexicalDeclContext(); | ||||
177 | RelativeToPrimary = false; | ||||
178 | continue; | ||||
179 | } | ||||
180 | } else if (CXXRecordDecl *Rec = dyn_cast<CXXRecordDecl>(Ctx)) { | ||||
181 | if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) { | ||||
182 | assert(Result.getNumSubstitutedLevels() == 0 &&(static_cast <bool> (Result.getNumSubstitutedLevels() == 0 && "Outer template not instantiated?") ? void (0) : __assert_fail ("Result.getNumSubstitutedLevels() == 0 && \"Outer template not instantiated?\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 183, __extension__ __PRETTY_FUNCTION__)) | ||||
183 | "Outer template not instantiated?")(static_cast <bool> (Result.getNumSubstitutedLevels() == 0 && "Outer template not instantiated?") ? void (0) : __assert_fail ("Result.getNumSubstitutedLevels() == 0 && \"Outer template not instantiated?\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 183, __extension__ __PRETTY_FUNCTION__)); | ||||
184 | if (ClassTemplate->isMemberSpecialization()) | ||||
185 | break; | ||||
186 | } | ||||
187 | } | ||||
188 | |||||
189 | Ctx = Ctx->getParent(); | ||||
190 | RelativeToPrimary = false; | ||||
191 | } | ||||
192 | |||||
193 | return Result; | ||||
194 | } | ||||
195 | |||||
196 | bool Sema::CodeSynthesisContext::isInstantiationRecord() const { | ||||
197 | switch (Kind) { | ||||
198 | case TemplateInstantiation: | ||||
199 | case ExceptionSpecInstantiation: | ||||
200 | case DefaultTemplateArgumentInstantiation: | ||||
201 | case DefaultFunctionArgumentInstantiation: | ||||
202 | case ExplicitTemplateArgumentSubstitution: | ||||
203 | case DeducedTemplateArgumentSubstitution: | ||||
204 | case PriorTemplateArgumentSubstitution: | ||||
205 | case ConstraintsCheck: | ||||
206 | case NestedRequirementConstraintsCheck: | ||||
207 | return true; | ||||
208 | |||||
209 | case RequirementInstantiation: | ||||
210 | case DefaultTemplateArgumentChecking: | ||||
211 | case DeclaringSpecialMember: | ||||
212 | case DeclaringImplicitEqualityComparison: | ||||
213 | case DefiningSynthesizedFunction: | ||||
214 | case ExceptionSpecEvaluation: | ||||
215 | case ConstraintSubstitution: | ||||
216 | case ParameterMappingSubstitution: | ||||
217 | case ConstraintNormalization: | ||||
218 | case RewritingOperatorAsSpaceship: | ||||
219 | case InitializingStructuredBinding: | ||||
220 | case MarkingClassDllexported: | ||||
221 | return false; | ||||
222 | |||||
223 | // This function should never be called when Kind's value is Memoization. | ||||
224 | case Memoization: | ||||
225 | break; | ||||
226 | } | ||||
227 | |||||
228 | llvm_unreachable("Invalid SynthesisKind!")::llvm::llvm_unreachable_internal("Invalid SynthesisKind!", "clang/lib/Sema/SemaTemplateInstantiate.cpp" , 228); | ||||
229 | } | ||||
230 | |||||
231 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
232 | Sema &SemaRef, CodeSynthesisContext::SynthesisKind Kind, | ||||
233 | SourceLocation PointOfInstantiation, SourceRange InstantiationRange, | ||||
234 | Decl *Entity, NamedDecl *Template, ArrayRef<TemplateArgument> TemplateArgs, | ||||
235 | sema::TemplateDeductionInfo *DeductionInfo) | ||||
236 | : SemaRef(SemaRef) { | ||||
237 | // Don't allow further instantiation if a fatal error and an uncompilable | ||||
238 | // error have occurred. Any diagnostics we might have raised will not be | ||||
239 | // visible, and we do not need to construct a correct AST. | ||||
240 | if (SemaRef.Diags.hasFatalErrorOccurred() && | ||||
241 | SemaRef.hasUncompilableErrorOccurred()) { | ||||
242 | Invalid = true; | ||||
243 | return; | ||||
244 | } | ||||
245 | Invalid = CheckInstantiationDepth(PointOfInstantiation, InstantiationRange); | ||||
246 | if (!Invalid
| ||||
247 | CodeSynthesisContext Inst; | ||||
248 | Inst.Kind = Kind; | ||||
249 | Inst.PointOfInstantiation = PointOfInstantiation; | ||||
250 | Inst.Entity = Entity; | ||||
251 | Inst.Template = Template; | ||||
252 | Inst.TemplateArgs = TemplateArgs.data(); | ||||
253 | Inst.NumTemplateArgs = TemplateArgs.size(); | ||||
254 | Inst.DeductionInfo = DeductionInfo; | ||||
255 | Inst.InstantiationRange = InstantiationRange; | ||||
256 | SemaRef.pushCodeSynthesisContext(Inst); | ||||
257 | |||||
258 | AlreadyInstantiating = !Inst.Entity
| ||||
259 | !SemaRef.InstantiatingSpecializations | ||||
260 | .insert({Inst.Entity->getCanonicalDecl(), Inst.Kind}) | ||||
261 | .second; | ||||
262 | atTemplateBegin(SemaRef.TemplateInstCallbacks, SemaRef, Inst); | ||||
263 | } | ||||
264 | } | ||||
265 | |||||
266 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
267 | Sema &SemaRef, SourceLocation PointOfInstantiation, Decl *Entity, | ||||
268 | SourceRange InstantiationRange) | ||||
269 | : InstantiatingTemplate(SemaRef, | ||||
270 | CodeSynthesisContext::TemplateInstantiation, | ||||
271 | PointOfInstantiation, InstantiationRange, Entity) {} | ||||
272 | |||||
273 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
274 | Sema &SemaRef, SourceLocation PointOfInstantiation, FunctionDecl *Entity, | ||||
275 | ExceptionSpecification, SourceRange InstantiationRange) | ||||
276 | : InstantiatingTemplate( | ||||
277 | SemaRef, CodeSynthesisContext::ExceptionSpecInstantiation, | ||||
278 | PointOfInstantiation, InstantiationRange, Entity) {} | ||||
279 | |||||
280 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
281 | Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateParameter Param, | ||||
282 | TemplateDecl *Template, ArrayRef<TemplateArgument> TemplateArgs, | ||||
283 | SourceRange InstantiationRange) | ||||
284 | : InstantiatingTemplate( | ||||
285 | SemaRef, | ||||
286 | CodeSynthesisContext::DefaultTemplateArgumentInstantiation, | ||||
287 | PointOfInstantiation, InstantiationRange, getAsNamedDecl(Param), | ||||
288 | Template, TemplateArgs) {} | ||||
289 | |||||
290 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
291 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
292 | FunctionTemplateDecl *FunctionTemplate, | ||||
293 | ArrayRef<TemplateArgument> TemplateArgs, | ||||
294 | CodeSynthesisContext::SynthesisKind Kind, | ||||
295 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||
296 | : InstantiatingTemplate(SemaRef, Kind, PointOfInstantiation, | ||||
297 | InstantiationRange, FunctionTemplate, nullptr, | ||||
298 | TemplateArgs, &DeductionInfo) { | ||||
299 | assert((static_cast <bool> (Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution ) ? void (0) : __assert_fail ("Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 301, __extension__ __PRETTY_FUNCTION__)) | ||||
300 | Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution ||(static_cast <bool> (Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution ) ? void (0) : __assert_fail ("Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 301, __extension__ __PRETTY_FUNCTION__)) | ||||
301 | Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution)(static_cast <bool> (Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution ) ? void (0) : __assert_fail ("Kind == CodeSynthesisContext::ExplicitTemplateArgumentSubstitution || Kind == CodeSynthesisContext::DeducedTemplateArgumentSubstitution" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 301, __extension__ __PRETTY_FUNCTION__)); | ||||
302 | } | ||||
303 | |||||
304 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
305 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
306 | TemplateDecl *Template, | ||||
307 | ArrayRef<TemplateArgument> TemplateArgs, | ||||
308 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||
309 | : InstantiatingTemplate( | ||||
310 | SemaRef, | ||||
311 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | ||||
312 | PointOfInstantiation, InstantiationRange, Template, nullptr, | ||||
313 | TemplateArgs, &DeductionInfo) {} | ||||
314 | |||||
315 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
316 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
317 | ClassTemplatePartialSpecializationDecl *PartialSpec, | ||||
318 | ArrayRef<TemplateArgument> TemplateArgs, | ||||
319 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||
320 | : InstantiatingTemplate( | ||||
321 | SemaRef, | ||||
322 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | ||||
323 | PointOfInstantiation, InstantiationRange, PartialSpec, nullptr, | ||||
324 | TemplateArgs, &DeductionInfo) {} | ||||
325 | |||||
326 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
327 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
328 | VarTemplatePartialSpecializationDecl *PartialSpec, | ||||
329 | ArrayRef<TemplateArgument> TemplateArgs, | ||||
330 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||
331 | : InstantiatingTemplate( | ||||
332 | SemaRef, | ||||
333 | CodeSynthesisContext::DeducedTemplateArgumentSubstitution, | ||||
334 | PointOfInstantiation, InstantiationRange, PartialSpec, nullptr, | ||||
335 | TemplateArgs, &DeductionInfo) {} | ||||
336 | |||||
337 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
338 | Sema &SemaRef, SourceLocation PointOfInstantiation, ParmVarDecl *Param, | ||||
339 | ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange) | ||||
340 | : InstantiatingTemplate( | ||||
341 | SemaRef, | ||||
342 | CodeSynthesisContext::DefaultFunctionArgumentInstantiation, | ||||
343 | PointOfInstantiation, InstantiationRange, Param, nullptr, | ||||
344 | TemplateArgs) {} | ||||
345 | |||||
346 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
347 | Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template, | ||||
348 | NonTypeTemplateParmDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | ||||
349 | SourceRange InstantiationRange) | ||||
350 | : InstantiatingTemplate( | ||||
351 | SemaRef, | ||||
352 | CodeSynthesisContext::PriorTemplateArgumentSubstitution, | ||||
353 | PointOfInstantiation, InstantiationRange, Param, Template, | ||||
354 | TemplateArgs) {} | ||||
355 | |||||
356 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
357 | Sema &SemaRef, SourceLocation PointOfInstantiation, NamedDecl *Template, | ||||
358 | TemplateTemplateParmDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | ||||
359 | SourceRange InstantiationRange) | ||||
360 | : InstantiatingTemplate( | ||||
361 | SemaRef, | ||||
362 | CodeSynthesisContext::PriorTemplateArgumentSubstitution, | ||||
363 | PointOfInstantiation, InstantiationRange, Param, Template, | ||||
364 | TemplateArgs) {} | ||||
365 | |||||
366 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
367 | Sema &SemaRef, SourceLocation PointOfInstantiation, TemplateDecl *Template, | ||||
368 | NamedDecl *Param, ArrayRef<TemplateArgument> TemplateArgs, | ||||
369 | SourceRange InstantiationRange) | ||||
370 | : InstantiatingTemplate( | ||||
371 | SemaRef, CodeSynthesisContext::DefaultTemplateArgumentChecking, | ||||
372 | PointOfInstantiation, InstantiationRange, Param, Template, | ||||
373 | TemplateArgs) {} | ||||
374 | |||||
375 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
376 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
377 | concepts::Requirement *Req, sema::TemplateDeductionInfo &DeductionInfo, | ||||
378 | SourceRange InstantiationRange) | ||||
379 | : InstantiatingTemplate( | ||||
380 | SemaRef, CodeSynthesisContext::RequirementInstantiation, | ||||
381 | PointOfInstantiation, InstantiationRange, /*Entity=*/nullptr, | ||||
382 | /*Template=*/nullptr, /*TemplateArgs=*/None, &DeductionInfo) {} | ||||
383 | |||||
384 | |||||
385 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
386 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
387 | concepts::NestedRequirement *Req, ConstraintsCheck, | ||||
388 | SourceRange InstantiationRange) | ||||
389 | : InstantiatingTemplate( | ||||
390 | SemaRef, CodeSynthesisContext::NestedRequirementConstraintsCheck, | ||||
391 | PointOfInstantiation, InstantiationRange, /*Entity=*/nullptr, | ||||
392 | /*Template=*/nullptr, /*TemplateArgs=*/None) {} | ||||
393 | |||||
394 | |||||
395 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
396 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
397 | ConstraintsCheck, NamedDecl *Template, | ||||
398 | ArrayRef<TemplateArgument> TemplateArgs, SourceRange InstantiationRange) | ||||
399 | : InstantiatingTemplate( | ||||
400 | SemaRef, CodeSynthesisContext::ConstraintsCheck, | ||||
401 | PointOfInstantiation, InstantiationRange, Template, nullptr, | ||||
402 | TemplateArgs) {} | ||||
403 | |||||
404 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
405 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
406 | ConstraintSubstitution, NamedDecl *Template, | ||||
407 | sema::TemplateDeductionInfo &DeductionInfo, SourceRange InstantiationRange) | ||||
408 | : InstantiatingTemplate( | ||||
409 | SemaRef, CodeSynthesisContext::ConstraintSubstitution, | ||||
410 | PointOfInstantiation, InstantiationRange, Template, nullptr, | ||||
411 | {}, &DeductionInfo) {} | ||||
412 | |||||
413 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
414 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
415 | ConstraintNormalization, NamedDecl *Template, | ||||
416 | SourceRange InstantiationRange) | ||||
417 | : InstantiatingTemplate( | ||||
418 | SemaRef, CodeSynthesisContext::ConstraintNormalization, | ||||
419 | PointOfInstantiation, InstantiationRange, Template) {} | ||||
420 | |||||
421 | Sema::InstantiatingTemplate::InstantiatingTemplate( | ||||
422 | Sema &SemaRef, SourceLocation PointOfInstantiation, | ||||
423 | ParameterMappingSubstitution, NamedDecl *Template, | ||||
424 | SourceRange InstantiationRange) | ||||
425 | : InstantiatingTemplate( | ||||
426 | SemaRef, CodeSynthesisContext::ParameterMappingSubstitution, | ||||
427 | PointOfInstantiation, InstantiationRange, Template) {} | ||||
428 | |||||
429 | void Sema::pushCodeSynthesisContext(CodeSynthesisContext Ctx) { | ||||
430 | Ctx.SavedInNonInstantiationSFINAEContext = InNonInstantiationSFINAEContext; | ||||
431 | InNonInstantiationSFINAEContext = false; | ||||
432 | |||||
433 | CodeSynthesisContexts.push_back(Ctx); | ||||
434 | |||||
435 | if (!Ctx.isInstantiationRecord()) | ||||
436 | ++NonInstantiationEntries; | ||||
437 | |||||
438 | // Check to see if we're low on stack space. We can't do anything about this | ||||
439 | // from here, but we can at least warn the user. | ||||
440 | if (isStackNearlyExhausted()) | ||||
441 | warnStackExhausted(Ctx.PointOfInstantiation); | ||||
442 | } | ||||
443 | |||||
444 | void Sema::popCodeSynthesisContext() { | ||||
445 | auto &Active = CodeSynthesisContexts.back(); | ||||
446 | if (!Active.isInstantiationRecord()) { | ||||
447 | assert(NonInstantiationEntries > 0)(static_cast <bool> (NonInstantiationEntries > 0) ? void (0) : __assert_fail ("NonInstantiationEntries > 0", "clang/lib/Sema/SemaTemplateInstantiate.cpp" , 447, __extension__ __PRETTY_FUNCTION__)); | ||||
448 | --NonInstantiationEntries; | ||||
449 | } | ||||
450 | |||||
451 | InNonInstantiationSFINAEContext = Active.SavedInNonInstantiationSFINAEContext; | ||||
452 | |||||
453 | // Name lookup no longer looks in this template's defining module. | ||||
454 | assert(CodeSynthesisContexts.size() >=(static_cast <bool> (CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && "forgot to remove a lookup module for a template instantiation" ) ? void (0) : __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 456, __extension__ __PRETTY_FUNCTION__)) | ||||
455 | CodeSynthesisContextLookupModules.size() &&(static_cast <bool> (CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && "forgot to remove a lookup module for a template instantiation" ) ? void (0) : __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 456, __extension__ __PRETTY_FUNCTION__)) | ||||
456 | "forgot to remove a lookup module for a template instantiation")(static_cast <bool> (CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && "forgot to remove a lookup module for a template instantiation" ) ? void (0) : __assert_fail ("CodeSynthesisContexts.size() >= CodeSynthesisContextLookupModules.size() && \"forgot to remove a lookup module for a template instantiation\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 456, __extension__ __PRETTY_FUNCTION__)); | ||||
457 | if (CodeSynthesisContexts.size() == | ||||
458 | CodeSynthesisContextLookupModules.size()) { | ||||
459 | if (Module *M = CodeSynthesisContextLookupModules.back()) | ||||
460 | LookupModulesCache.erase(M); | ||||
461 | CodeSynthesisContextLookupModules.pop_back(); | ||||
462 | } | ||||
463 | |||||
464 | // If we've left the code synthesis context for the current context stack, | ||||
465 | // stop remembering that we've emitted that stack. | ||||
466 | if (CodeSynthesisContexts.size() == | ||||
467 | LastEmittedCodeSynthesisContextDepth) | ||||
468 | LastEmittedCodeSynthesisContextDepth = 0; | ||||
469 | |||||
470 | CodeSynthesisContexts.pop_back(); | ||||
471 | } | ||||
472 | |||||
473 | void Sema::InstantiatingTemplate::Clear() { | ||||
474 | if (!Invalid) { | ||||
475 | if (!AlreadyInstantiating) { | ||||
476 | auto &Active = SemaRef.CodeSynthesisContexts.back(); | ||||
477 | if (Active.Entity) | ||||
478 | SemaRef.InstantiatingSpecializations.erase( | ||||
479 | {Active.Entity->getCanonicalDecl(), Active.Kind}); | ||||
480 | } | ||||
481 | |||||
482 | atTemplateEnd(SemaRef.TemplateInstCallbacks, SemaRef, | ||||
483 | SemaRef.CodeSynthesisContexts.back()); | ||||
484 | |||||
485 | SemaRef.popCodeSynthesisContext(); | ||||
486 | Invalid = true; | ||||
487 | } | ||||
488 | } | ||||
489 | |||||
490 | bool Sema::InstantiatingTemplate::CheckInstantiationDepth( | ||||
491 | SourceLocation PointOfInstantiation, | ||||
492 | SourceRange InstantiationRange) { | ||||
493 | assert(SemaRef.NonInstantiationEntries <=(static_cast <bool> (SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts.size()) ? void (0) : __assert_fail ("SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts.size()" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 494, __extension__ __PRETTY_FUNCTION__)) | ||||
494 | SemaRef.CodeSynthesisContexts.size())(static_cast <bool> (SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts.size()) ? void (0) : __assert_fail ("SemaRef.NonInstantiationEntries <= SemaRef.CodeSynthesisContexts.size()" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 494, __extension__ __PRETTY_FUNCTION__)); | ||||
495 | if ((SemaRef.CodeSynthesisContexts.size() - | ||||
496 | SemaRef.NonInstantiationEntries) | ||||
497 | <= SemaRef.getLangOpts().InstantiationDepth) | ||||
498 | return false; | ||||
499 | |||||
500 | SemaRef.Diag(PointOfInstantiation, | ||||
501 | diag::err_template_recursion_depth_exceeded) | ||||
502 | << SemaRef.getLangOpts().InstantiationDepth | ||||
503 | << InstantiationRange; | ||||
504 | SemaRef.Diag(PointOfInstantiation, diag::note_template_recursion_depth) | ||||
505 | << SemaRef.getLangOpts().InstantiationDepth; | ||||
506 | return true; | ||||
507 | } | ||||
508 | |||||
509 | /// Prints the current instantiation stack through a series of | ||||
510 | /// notes. | ||||
511 | void Sema::PrintInstantiationStack() { | ||||
512 | // Determine which template instantiations to skip, if any. | ||||
513 | unsigned SkipStart = CodeSynthesisContexts.size(), SkipEnd = SkipStart; | ||||
514 | unsigned Limit = Diags.getTemplateBacktraceLimit(); | ||||
515 | if (Limit && Limit < CodeSynthesisContexts.size()) { | ||||
516 | SkipStart = Limit / 2 + Limit % 2; | ||||
517 | SkipEnd = CodeSynthesisContexts.size() - Limit / 2; | ||||
518 | } | ||||
519 | |||||
520 | // FIXME: In all of these cases, we need to show the template arguments | ||||
521 | unsigned InstantiationIdx = 0; | ||||
522 | for (SmallVectorImpl<CodeSynthesisContext>::reverse_iterator | ||||
523 | Active = CodeSynthesisContexts.rbegin(), | ||||
524 | ActiveEnd = CodeSynthesisContexts.rend(); | ||||
525 | Active != ActiveEnd; | ||||
526 | ++Active, ++InstantiationIdx) { | ||||
527 | // Skip this instantiation? | ||||
528 | if (InstantiationIdx >= SkipStart && InstantiationIdx < SkipEnd) { | ||||
529 | if (InstantiationIdx == SkipStart) { | ||||
530 | // Note that we're skipping instantiations. | ||||
531 | Diags.Report(Active->PointOfInstantiation, | ||||
532 | diag::note_instantiation_contexts_suppressed) | ||||
533 | << unsigned(CodeSynthesisContexts.size() - Limit); | ||||
534 | } | ||||
535 | continue; | ||||
536 | } | ||||
537 | |||||
538 | switch (Active->Kind) { | ||||
539 | case CodeSynthesisContext::TemplateInstantiation: { | ||||
540 | Decl *D = Active->Entity; | ||||
541 | if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) { | ||||
542 | unsigned DiagID = diag::note_template_member_class_here; | ||||
543 | if (isa<ClassTemplateSpecializationDecl>(Record)) | ||||
544 | DiagID = diag::note_template_class_instantiation_here; | ||||
545 | Diags.Report(Active->PointOfInstantiation, DiagID) | ||||
546 | << Record << Active->InstantiationRange; | ||||
547 | } else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) { | ||||
548 | unsigned DiagID; | ||||
549 | if (Function->getPrimaryTemplate()) | ||||
550 | DiagID = diag::note_function_template_spec_here; | ||||
551 | else | ||||
552 | DiagID = diag::note_template_member_function_here; | ||||
553 | Diags.Report(Active->PointOfInstantiation, DiagID) | ||||
554 | << Function | ||||
555 | << Active->InstantiationRange; | ||||
556 | } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) { | ||||
557 | Diags.Report(Active->PointOfInstantiation, | ||||
558 | VD->isStaticDataMember()? | ||||
559 | diag::note_template_static_data_member_def_here | ||||
560 | : diag::note_template_variable_def_here) | ||||
561 | << VD | ||||
562 | << Active->InstantiationRange; | ||||
563 | } else if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) { | ||||
564 | Diags.Report(Active->PointOfInstantiation, | ||||
565 | diag::note_template_enum_def_here) | ||||
566 | << ED | ||||
567 | << Active->InstantiationRange; | ||||
568 | } else if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) { | ||||
569 | Diags.Report(Active->PointOfInstantiation, | ||||
570 | diag::note_template_nsdmi_here) | ||||
571 | << FD << Active->InstantiationRange; | ||||
572 | } else { | ||||
573 | Diags.Report(Active->PointOfInstantiation, | ||||
574 | diag::note_template_type_alias_instantiation_here) | ||||
575 | << cast<TypeAliasTemplateDecl>(D) | ||||
576 | << Active->InstantiationRange; | ||||
577 | } | ||||
578 | break; | ||||
579 | } | ||||
580 | |||||
581 | case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: { | ||||
582 | TemplateDecl *Template = cast<TemplateDecl>(Active->Template); | ||||
583 | SmallString<128> TemplateArgsStr; | ||||
584 | llvm::raw_svector_ostream OS(TemplateArgsStr); | ||||
585 | Template->printName(OS); | ||||
586 | printTemplateArgumentList(OS, Active->template_arguments(), | ||||
587 | getPrintingPolicy()); | ||||
588 | Diags.Report(Active->PointOfInstantiation, | ||||
589 | diag::note_default_arg_instantiation_here) | ||||
590 | << OS.str() | ||||
591 | << Active->InstantiationRange; | ||||
592 | break; | ||||
593 | } | ||||
594 | |||||
595 | case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution: { | ||||
596 | FunctionTemplateDecl *FnTmpl = cast<FunctionTemplateDecl>(Active->Entity); | ||||
597 | Diags.Report(Active->PointOfInstantiation, | ||||
598 | diag::note_explicit_template_arg_substitution_here) | ||||
599 | << FnTmpl | ||||
600 | << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(), | ||||
601 | Active->TemplateArgs, | ||||
602 | Active->NumTemplateArgs) | ||||
603 | << Active->InstantiationRange; | ||||
604 | break; | ||||
605 | } | ||||
606 | |||||
607 | case CodeSynthesisContext::DeducedTemplateArgumentSubstitution: { | ||||
608 | if (FunctionTemplateDecl *FnTmpl = | ||||
609 | dyn_cast<FunctionTemplateDecl>(Active->Entity)) { | ||||
610 | Diags.Report(Active->PointOfInstantiation, | ||||
611 | diag::note_function_template_deduction_instantiation_here) | ||||
612 | << FnTmpl | ||||
613 | << getTemplateArgumentBindingsText(FnTmpl->getTemplateParameters(), | ||||
614 | Active->TemplateArgs, | ||||
615 | Active->NumTemplateArgs) | ||||
616 | << Active->InstantiationRange; | ||||
617 | } else { | ||||
618 | bool IsVar = isa<VarTemplateDecl>(Active->Entity) || | ||||
619 | isa<VarTemplateSpecializationDecl>(Active->Entity); | ||||
620 | bool IsTemplate = false; | ||||
621 | TemplateParameterList *Params; | ||||
622 | if (auto *D = dyn_cast<TemplateDecl>(Active->Entity)) { | ||||
623 | IsTemplate = true; | ||||
624 | Params = D->getTemplateParameters(); | ||||
625 | } else if (auto *D = dyn_cast<ClassTemplatePartialSpecializationDecl>( | ||||
626 | Active->Entity)) { | ||||
627 | Params = D->getTemplateParameters(); | ||||
628 | } else if (auto *D = dyn_cast<VarTemplatePartialSpecializationDecl>( | ||||
629 | Active->Entity)) { | ||||
630 | Params = D->getTemplateParameters(); | ||||
631 | } else { | ||||
632 | llvm_unreachable("unexpected template kind")::llvm::llvm_unreachable_internal("unexpected template kind", "clang/lib/Sema/SemaTemplateInstantiate.cpp", 632); | ||||
633 | } | ||||
634 | |||||
635 | Diags.Report(Active->PointOfInstantiation, | ||||
636 | diag::note_deduced_template_arg_substitution_here) | ||||
637 | << IsVar << IsTemplate << cast<NamedDecl>(Active->Entity) | ||||
638 | << getTemplateArgumentBindingsText(Params, Active->TemplateArgs, | ||||
639 | Active->NumTemplateArgs) | ||||
640 | << Active->InstantiationRange; | ||||
641 | } | ||||
642 | break; | ||||
643 | } | ||||
644 | |||||
645 | case CodeSynthesisContext::DefaultFunctionArgumentInstantiation: { | ||||
646 | ParmVarDecl *Param = cast<ParmVarDecl>(Active->Entity); | ||||
647 | FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext()); | ||||
648 | |||||
649 | SmallString<128> TemplateArgsStr; | ||||
650 | llvm::raw_svector_ostream OS(TemplateArgsStr); | ||||
651 | FD->printName(OS); | ||||
652 | printTemplateArgumentList(OS, Active->template_arguments(), | ||||
653 | getPrintingPolicy()); | ||||
654 | Diags.Report(Active->PointOfInstantiation, | ||||
655 | diag::note_default_function_arg_instantiation_here) | ||||
656 | << OS.str() | ||||
657 | << Active->InstantiationRange; | ||||
658 | break; | ||||
659 | } | ||||
660 | |||||
661 | case CodeSynthesisContext::PriorTemplateArgumentSubstitution: { | ||||
662 | NamedDecl *Parm = cast<NamedDecl>(Active->Entity); | ||||
663 | std::string Name; | ||||
664 | if (!Parm->getName().empty()) | ||||
665 | Name = std::string(" '") + Parm->getName().str() + "'"; | ||||
666 | |||||
667 | TemplateParameterList *TemplateParams = nullptr; | ||||
668 | if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template)) | ||||
669 | TemplateParams = Template->getTemplateParameters(); | ||||
670 | else | ||||
671 | TemplateParams = | ||||
672 | cast<ClassTemplatePartialSpecializationDecl>(Active->Template) | ||||
673 | ->getTemplateParameters(); | ||||
674 | Diags.Report(Active->PointOfInstantiation, | ||||
675 | diag::note_prior_template_arg_substitution) | ||||
676 | << isa<TemplateTemplateParmDecl>(Parm) | ||||
677 | << Name | ||||
678 | << getTemplateArgumentBindingsText(TemplateParams, | ||||
679 | Active->TemplateArgs, | ||||
680 | Active->NumTemplateArgs) | ||||
681 | << Active->InstantiationRange; | ||||
682 | break; | ||||
683 | } | ||||
684 | |||||
685 | case CodeSynthesisContext::DefaultTemplateArgumentChecking: { | ||||
686 | TemplateParameterList *TemplateParams = nullptr; | ||||
687 | if (TemplateDecl *Template = dyn_cast<TemplateDecl>(Active->Template)) | ||||
688 | TemplateParams = Template->getTemplateParameters(); | ||||
689 | else | ||||
690 | TemplateParams = | ||||
691 | cast<ClassTemplatePartialSpecializationDecl>(Active->Template) | ||||
692 | ->getTemplateParameters(); | ||||
693 | |||||
694 | Diags.Report(Active->PointOfInstantiation, | ||||
695 | diag::note_template_default_arg_checking) | ||||
696 | << getTemplateArgumentBindingsText(TemplateParams, | ||||
697 | Active->TemplateArgs, | ||||
698 | Active->NumTemplateArgs) | ||||
699 | << Active->InstantiationRange; | ||||
700 | break; | ||||
701 | } | ||||
702 | |||||
703 | case CodeSynthesisContext::ExceptionSpecEvaluation: | ||||
704 | Diags.Report(Active->PointOfInstantiation, | ||||
705 | diag::note_evaluating_exception_spec_here) | ||||
706 | << cast<FunctionDecl>(Active->Entity); | ||||
707 | break; | ||||
708 | |||||
709 | case CodeSynthesisContext::ExceptionSpecInstantiation: | ||||
710 | Diags.Report(Active->PointOfInstantiation, | ||||
711 | diag::note_template_exception_spec_instantiation_here) | ||||
712 | << cast<FunctionDecl>(Active->Entity) | ||||
713 | << Active->InstantiationRange; | ||||
714 | break; | ||||
715 | |||||
716 | case CodeSynthesisContext::RequirementInstantiation: | ||||
717 | Diags.Report(Active->PointOfInstantiation, | ||||
718 | diag::note_template_requirement_instantiation_here) | ||||
719 | << Active->InstantiationRange; | ||||
720 | break; | ||||
721 | |||||
722 | case CodeSynthesisContext::NestedRequirementConstraintsCheck: | ||||
723 | Diags.Report(Active->PointOfInstantiation, | ||||
724 | diag::note_nested_requirement_here) | ||||
725 | << Active->InstantiationRange; | ||||
726 | break; | ||||
727 | |||||
728 | case CodeSynthesisContext::DeclaringSpecialMember: | ||||
729 | Diags.Report(Active->PointOfInstantiation, | ||||
730 | diag::note_in_declaration_of_implicit_special_member) | ||||
731 | << cast<CXXRecordDecl>(Active->Entity) << Active->SpecialMember; | ||||
732 | break; | ||||
733 | |||||
734 | case CodeSynthesisContext::DeclaringImplicitEqualityComparison: | ||||
735 | Diags.Report(Active->Entity->getLocation(), | ||||
736 | diag::note_in_declaration_of_implicit_equality_comparison); | ||||
737 | break; | ||||
738 | |||||
739 | case CodeSynthesisContext::DefiningSynthesizedFunction: { | ||||
740 | // FIXME: For synthesized functions that are not defaulted, | ||||
741 | // produce a note. | ||||
742 | auto *FD = dyn_cast<FunctionDecl>(Active->Entity); | ||||
743 | DefaultedFunctionKind DFK = | ||||
744 | FD ? getDefaultedFunctionKind(FD) : DefaultedFunctionKind(); | ||||
745 | if (DFK.isSpecialMember()) { | ||||
746 | auto *MD = cast<CXXMethodDecl>(FD); | ||||
747 | Diags.Report(Active->PointOfInstantiation, | ||||
748 | diag::note_member_synthesized_at) | ||||
749 | << MD->isExplicitlyDefaulted() << DFK.asSpecialMember() | ||||
750 | << Context.getTagDeclType(MD->getParent()); | ||||
751 | } else if (DFK.isComparison()) { | ||||
752 | Diags.Report(Active->PointOfInstantiation, | ||||
753 | diag::note_comparison_synthesized_at) | ||||
754 | << (int)DFK.asComparison() | ||||
755 | << Context.getTagDeclType( | ||||
756 | cast<CXXRecordDecl>(FD->getLexicalDeclContext())); | ||||
757 | } | ||||
758 | break; | ||||
759 | } | ||||
760 | |||||
761 | case CodeSynthesisContext::RewritingOperatorAsSpaceship: | ||||
762 | Diags.Report(Active->Entity->getLocation(), | ||||
763 | diag::note_rewriting_operator_as_spaceship); | ||||
764 | break; | ||||
765 | |||||
766 | case CodeSynthesisContext::InitializingStructuredBinding: | ||||
767 | Diags.Report(Active->PointOfInstantiation, | ||||
768 | diag::note_in_binding_decl_init) | ||||
769 | << cast<BindingDecl>(Active->Entity); | ||||
770 | break; | ||||
771 | |||||
772 | case CodeSynthesisContext::MarkingClassDllexported: | ||||
773 | Diags.Report(Active->PointOfInstantiation, | ||||
774 | diag::note_due_to_dllexported_class) | ||||
775 | << cast<CXXRecordDecl>(Active->Entity) << !getLangOpts().CPlusPlus11; | ||||
776 | break; | ||||
777 | |||||
778 | case CodeSynthesisContext::Memoization: | ||||
779 | break; | ||||
780 | |||||
781 | case CodeSynthesisContext::ConstraintsCheck: { | ||||
782 | unsigned DiagID = 0; | ||||
783 | if (!Active->Entity) { | ||||
784 | Diags.Report(Active->PointOfInstantiation, | ||||
785 | diag::note_nested_requirement_here) | ||||
786 | << Active->InstantiationRange; | ||||
787 | break; | ||||
788 | } | ||||
789 | if (isa<ConceptDecl>(Active->Entity)) | ||||
790 | DiagID = diag::note_concept_specialization_here; | ||||
791 | else if (isa<TemplateDecl>(Active->Entity)) | ||||
792 | DiagID = diag::note_checking_constraints_for_template_id_here; | ||||
793 | else if (isa<VarTemplatePartialSpecializationDecl>(Active->Entity)) | ||||
794 | DiagID = diag::note_checking_constraints_for_var_spec_id_here; | ||||
795 | else if (isa<ClassTemplatePartialSpecializationDecl>(Active->Entity)) | ||||
796 | DiagID = diag::note_checking_constraints_for_class_spec_id_here; | ||||
797 | else { | ||||
798 | assert(isa<FunctionDecl>(Active->Entity))(static_cast <bool> (isa<FunctionDecl>(Active-> Entity)) ? void (0) : __assert_fail ("isa<FunctionDecl>(Active->Entity)" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 798, __extension__ __PRETTY_FUNCTION__)); | ||||
799 | DiagID = diag::note_checking_constraints_for_function_here; | ||||
800 | } | ||||
801 | SmallString<128> TemplateArgsStr; | ||||
802 | llvm::raw_svector_ostream OS(TemplateArgsStr); | ||||
803 | cast<NamedDecl>(Active->Entity)->printName(OS); | ||||
804 | if (!isa<FunctionDecl>(Active->Entity)) { | ||||
805 | printTemplateArgumentList(OS, Active->template_arguments(), | ||||
806 | getPrintingPolicy()); | ||||
807 | } | ||||
808 | Diags.Report(Active->PointOfInstantiation, DiagID) << OS.str() | ||||
809 | << Active->InstantiationRange; | ||||
810 | break; | ||||
811 | } | ||||
812 | case CodeSynthesisContext::ConstraintSubstitution: | ||||
813 | Diags.Report(Active->PointOfInstantiation, | ||||
814 | diag::note_constraint_substitution_here) | ||||
815 | << Active->InstantiationRange; | ||||
816 | break; | ||||
817 | case CodeSynthesisContext::ConstraintNormalization: | ||||
818 | Diags.Report(Active->PointOfInstantiation, | ||||
819 | diag::note_constraint_normalization_here) | ||||
820 | << cast<NamedDecl>(Active->Entity)->getName() | ||||
821 | << Active->InstantiationRange; | ||||
822 | break; | ||||
823 | case CodeSynthesisContext::ParameterMappingSubstitution: | ||||
824 | Diags.Report(Active->PointOfInstantiation, | ||||
825 | diag::note_parameter_mapping_substitution_here) | ||||
826 | << Active->InstantiationRange; | ||||
827 | break; | ||||
828 | } | ||||
829 | } | ||||
830 | } | ||||
831 | |||||
832 | Optional<TemplateDeductionInfo *> Sema::isSFINAEContext() const { | ||||
833 | if (InNonInstantiationSFINAEContext) | ||||
834 | return Optional<TemplateDeductionInfo *>(nullptr); | ||||
835 | |||||
836 | for (SmallVectorImpl<CodeSynthesisContext>::const_reverse_iterator | ||||
837 | Active = CodeSynthesisContexts.rbegin(), | ||||
838 | ActiveEnd = CodeSynthesisContexts.rend(); | ||||
839 | Active != ActiveEnd; | ||||
840 | ++Active) | ||||
841 | { | ||||
842 | switch (Active->Kind) { | ||||
843 | case CodeSynthesisContext::TemplateInstantiation: | ||||
844 | // An instantiation of an alias template may or may not be a SFINAE | ||||
845 | // context, depending on what else is on the stack. | ||||
846 | if (isa<TypeAliasTemplateDecl>(Active->Entity)) | ||||
847 | break; | ||||
848 | LLVM_FALLTHROUGH[[gnu::fallthrough]]; | ||||
849 | case CodeSynthesisContext::DefaultFunctionArgumentInstantiation: | ||||
850 | case CodeSynthesisContext::ExceptionSpecInstantiation: | ||||
851 | case CodeSynthesisContext::ConstraintsCheck: | ||||
852 | case CodeSynthesisContext::ParameterMappingSubstitution: | ||||
853 | case CodeSynthesisContext::ConstraintNormalization: | ||||
854 | case CodeSynthesisContext::NestedRequirementConstraintsCheck: | ||||
855 | // This is a template instantiation, so there is no SFINAE. | ||||
856 | return None; | ||||
857 | |||||
858 | case CodeSynthesisContext::DefaultTemplateArgumentInstantiation: | ||||
859 | case CodeSynthesisContext::PriorTemplateArgumentSubstitution: | ||||
860 | case CodeSynthesisContext::DefaultTemplateArgumentChecking: | ||||
861 | case CodeSynthesisContext::RewritingOperatorAsSpaceship: | ||||
862 | // A default template argument instantiation and substitution into | ||||
863 | // template parameters with arguments for prior parameters may or may | ||||
864 | // not be a SFINAE context; look further up the stack. | ||||
865 | break; | ||||
866 | |||||
867 | case CodeSynthesisContext::ExplicitTemplateArgumentSubstitution: | ||||
868 | case CodeSynthesisContext::DeducedTemplateArgumentSubstitution: | ||||
869 | case CodeSynthesisContext::ConstraintSubstitution: | ||||
870 | case CodeSynthesisContext::RequirementInstantiation: | ||||
871 | // We're either substituting explicitly-specified template arguments, | ||||
872 | // deduced template arguments, a constraint expression or a requirement | ||||
873 | // in a requires expression, so SFINAE applies. | ||||
874 | assert(Active->DeductionInfo && "Missing deduction info pointer")(static_cast <bool> (Active->DeductionInfo && "Missing deduction info pointer") ? void (0) : __assert_fail ("Active->DeductionInfo && \"Missing deduction info pointer\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 874, __extension__ __PRETTY_FUNCTION__)); | ||||
875 | return Active->DeductionInfo; | ||||
876 | |||||
877 | case CodeSynthesisContext::DeclaringSpecialMember: | ||||
878 | case CodeSynthesisContext::DeclaringImplicitEqualityComparison: | ||||
879 | case CodeSynthesisContext::DefiningSynthesizedFunction: | ||||
880 | case CodeSynthesisContext::InitializingStructuredBinding: | ||||
881 | case CodeSynthesisContext::MarkingClassDllexported: | ||||
882 | // This happens in a context unrelated to template instantiation, so | ||||
883 | // there is no SFINAE. | ||||
884 | return None; | ||||
885 | |||||
886 | case CodeSynthesisContext::ExceptionSpecEvaluation: | ||||
887 | // FIXME: This should not be treated as a SFINAE context, because | ||||
888 | // we will cache an incorrect exception specification. However, clang | ||||
889 | // bootstrap relies this! See PR31692. | ||||
890 | break; | ||||
891 | |||||
892 | case CodeSynthesisContext::Memoization: | ||||
893 | break; | ||||
894 | } | ||||
895 | |||||
896 | // The inner context was transparent for SFINAE. If it occurred within a | ||||
897 | // non-instantiation SFINAE context, then SFINAE applies. | ||||
898 | if (Active->SavedInNonInstantiationSFINAEContext) | ||||
899 | return Optional<TemplateDeductionInfo *>(nullptr); | ||||
900 | } | ||||
901 | |||||
902 | return None; | ||||
903 | } | ||||
904 | |||||
905 | //===----------------------------------------------------------------------===/ | ||||
906 | // Template Instantiation for Types | ||||
907 | //===----------------------------------------------------------------------===/ | ||||
908 | namespace { | ||||
909 | class TemplateInstantiator : public TreeTransform<TemplateInstantiator> { | ||||
910 | const MultiLevelTemplateArgumentList &TemplateArgs; | ||||
911 | SourceLocation Loc; | ||||
912 | DeclarationName Entity; | ||||
913 | |||||
914 | public: | ||||
915 | typedef TreeTransform<TemplateInstantiator> inherited; | ||||
916 | |||||
917 | TemplateInstantiator(Sema &SemaRef, | ||||
918 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||
919 | SourceLocation Loc, | ||||
920 | DeclarationName Entity) | ||||
921 | : inherited(SemaRef), TemplateArgs(TemplateArgs), Loc(Loc), | ||||
922 | Entity(Entity) { } | ||||
923 | |||||
924 | /// Determine whether the given type \p T has already been | ||||
925 | /// transformed. | ||||
926 | /// | ||||
927 | /// For the purposes of template instantiation, a type has already been | ||||
928 | /// transformed if it is NULL or if it is not dependent. | ||||
929 | bool AlreadyTransformed(QualType T); | ||||
930 | |||||
931 | /// Returns the location of the entity being instantiated, if known. | ||||
932 | SourceLocation getBaseLocation() { return Loc; } | ||||
933 | |||||
934 | /// Returns the name of the entity being instantiated, if any. | ||||
935 | DeclarationName getBaseEntity() { return Entity; } | ||||
936 | |||||
937 | /// Sets the "base" location and entity when that | ||||
938 | /// information is known based on another transformation. | ||||
939 | void setBase(SourceLocation Loc, DeclarationName Entity) { | ||||
940 | this->Loc = Loc; | ||||
941 | this->Entity = Entity; | ||||
942 | } | ||||
943 | |||||
944 | unsigned TransformTemplateDepth(unsigned Depth) { | ||||
945 | return TemplateArgs.getNewDepth(Depth); | ||||
946 | } | ||||
947 | |||||
948 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, | ||||
949 | SourceRange PatternRange, | ||||
950 | ArrayRef<UnexpandedParameterPack> Unexpanded, | ||||
951 | bool &ShouldExpand, bool &RetainExpansion, | ||||
952 | Optional<unsigned> &NumExpansions) { | ||||
953 | return getSema().CheckParameterPacksForExpansion(EllipsisLoc, | ||||
954 | PatternRange, Unexpanded, | ||||
955 | TemplateArgs, | ||||
956 | ShouldExpand, | ||||
957 | RetainExpansion, | ||||
958 | NumExpansions); | ||||
959 | } | ||||
960 | |||||
961 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { | ||||
962 | SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Pack); | ||||
963 | } | ||||
964 | |||||
965 | TemplateArgument ForgetPartiallySubstitutedPack() { | ||||
966 | TemplateArgument Result; | ||||
967 | if (NamedDecl *PartialPack | ||||
968 | = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){ | ||||
969 | MultiLevelTemplateArgumentList &TemplateArgs | ||||
970 | = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs); | ||||
971 | unsigned Depth, Index; | ||||
972 | std::tie(Depth, Index) = getDepthAndIndex(PartialPack); | ||||
973 | if (TemplateArgs.hasTemplateArgument(Depth, Index)) { | ||||
974 | Result = TemplateArgs(Depth, Index); | ||||
975 | TemplateArgs.setArgument(Depth, Index, TemplateArgument()); | ||||
976 | } | ||||
977 | } | ||||
978 | |||||
979 | return Result; | ||||
980 | } | ||||
981 | |||||
982 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { | ||||
983 | if (Arg.isNull()) | ||||
984 | return; | ||||
985 | |||||
986 | if (NamedDecl *PartialPack | ||||
987 | = SemaRef.CurrentInstantiationScope->getPartiallySubstitutedPack()){ | ||||
988 | MultiLevelTemplateArgumentList &TemplateArgs | ||||
989 | = const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs); | ||||
990 | unsigned Depth, Index; | ||||
991 | std::tie(Depth, Index) = getDepthAndIndex(PartialPack); | ||||
992 | TemplateArgs.setArgument(Depth, Index, Arg); | ||||
993 | } | ||||
994 | } | ||||
995 | |||||
996 | /// Transform the given declaration by instantiating a reference to | ||||
997 | /// this declaration. | ||||
998 | Decl *TransformDecl(SourceLocation Loc, Decl *D); | ||||
999 | |||||
1000 | void transformAttrs(Decl *Old, Decl *New) { | ||||
1001 | SemaRef.InstantiateAttrs(TemplateArgs, Old, New); | ||||
1002 | } | ||||
1003 | |||||
1004 | void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> NewDecls) { | ||||
1005 | if (Old->isParameterPack()) { | ||||
1006 | SemaRef.CurrentInstantiationScope->MakeInstantiatedLocalArgPack(Old); | ||||
1007 | for (auto *New : NewDecls) | ||||
1008 | SemaRef.CurrentInstantiationScope->InstantiatedLocalPackArg( | ||||
1009 | Old, cast<VarDecl>(New)); | ||||
1010 | return; | ||||
1011 | } | ||||
1012 | |||||
1013 | assert(NewDecls.size() == 1 &&(static_cast <bool> (NewDecls.size() == 1 && "should only have multiple expansions for a pack" ) ? void (0) : __assert_fail ("NewDecls.size() == 1 && \"should only have multiple expansions for a pack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1014, __extension__ __PRETTY_FUNCTION__)) | ||||
1014 | "should only have multiple expansions for a pack")(static_cast <bool> (NewDecls.size() == 1 && "should only have multiple expansions for a pack" ) ? void (0) : __assert_fail ("NewDecls.size() == 1 && \"should only have multiple expansions for a pack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1014, __extension__ __PRETTY_FUNCTION__)); | ||||
1015 | Decl *New = NewDecls.front(); | ||||
1016 | |||||
1017 | // If we've instantiated the call operator of a lambda or the call | ||||
1018 | // operator template of a generic lambda, update the "instantiation of" | ||||
1019 | // information. | ||||
1020 | auto *NewMD = dyn_cast<CXXMethodDecl>(New); | ||||
1021 | if (NewMD && isLambdaCallOperator(NewMD)) { | ||||
1022 | auto *OldMD = dyn_cast<CXXMethodDecl>(Old); | ||||
1023 | if (auto *NewTD = NewMD->getDescribedFunctionTemplate()) | ||||
1024 | NewTD->setInstantiatedFromMemberTemplate( | ||||
1025 | OldMD->getDescribedFunctionTemplate()); | ||||
1026 | else | ||||
1027 | NewMD->setInstantiationOfMemberFunction(OldMD, | ||||
1028 | TSK_ImplicitInstantiation); | ||||
1029 | } | ||||
1030 | |||||
1031 | SemaRef.CurrentInstantiationScope->InstantiatedLocal(Old, New); | ||||
1032 | |||||
1033 | // We recreated a local declaration, but not by instantiating it. There | ||||
1034 | // may be pending dependent diagnostics to produce. | ||||
1035 | if (auto *DC = dyn_cast<DeclContext>(Old)) | ||||
1036 | SemaRef.PerformDependentDiagnostics(DC, TemplateArgs); | ||||
1037 | } | ||||
1038 | |||||
1039 | /// Transform the definition of the given declaration by | ||||
1040 | /// instantiating it. | ||||
1041 | Decl *TransformDefinition(SourceLocation Loc, Decl *D); | ||||
1042 | |||||
1043 | /// Transform the first qualifier within a scope by instantiating the | ||||
1044 | /// declaration. | ||||
1045 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc); | ||||
1046 | |||||
1047 | /// Rebuild the exception declaration and register the declaration | ||||
1048 | /// as an instantiated local. | ||||
1049 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, | ||||
1050 | TypeSourceInfo *Declarator, | ||||
1051 | SourceLocation StartLoc, | ||||
1052 | SourceLocation NameLoc, | ||||
1053 | IdentifierInfo *Name); | ||||
1054 | |||||
1055 | /// Rebuild the Objective-C exception declaration and register the | ||||
1056 | /// declaration as an instantiated local. | ||||
1057 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, | ||||
1058 | TypeSourceInfo *TSInfo, QualType T); | ||||
1059 | |||||
1060 | /// Check for tag mismatches when instantiating an | ||||
1061 | /// elaborated type. | ||||
1062 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, | ||||
1063 | ElaboratedTypeKeyword Keyword, | ||||
1064 | NestedNameSpecifierLoc QualifierLoc, | ||||
1065 | QualType T); | ||||
1066 | |||||
1067 | TemplateName | ||||
1068 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, | ||||
1069 | SourceLocation NameLoc, | ||||
1070 | QualType ObjectType = QualType(), | ||||
1071 | NamedDecl *FirstQualifierInScope = nullptr, | ||||
1072 | bool AllowInjectedClassName = false); | ||||
1073 | |||||
1074 | const LoopHintAttr *TransformLoopHintAttr(const LoopHintAttr *LH); | ||||
1075 | |||||
1076 | ExprResult TransformPredefinedExpr(PredefinedExpr *E); | ||||
1077 | ExprResult TransformDeclRefExpr(DeclRefExpr *E); | ||||
1078 | ExprResult TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E); | ||||
1079 | |||||
1080 | ExprResult TransformTemplateParmRefExpr(DeclRefExpr *E, | ||||
1081 | NonTypeTemplateParmDecl *D); | ||||
1082 | ExprResult TransformSubstNonTypeTemplateParmPackExpr( | ||||
1083 | SubstNonTypeTemplateParmPackExpr *E); | ||||
1084 | ExprResult TransformSubstNonTypeTemplateParmExpr( | ||||
1085 | SubstNonTypeTemplateParmExpr *E); | ||||
1086 | |||||
1087 | /// Rebuild a DeclRefExpr for a VarDecl reference. | ||||
1088 | ExprResult RebuildVarDeclRefExpr(VarDecl *PD, SourceLocation Loc); | ||||
1089 | |||||
1090 | /// Transform a reference to a function or init-capture parameter pack. | ||||
1091 | ExprResult TransformFunctionParmPackRefExpr(DeclRefExpr *E, VarDecl *PD); | ||||
1092 | |||||
1093 | /// Transform a FunctionParmPackExpr which was built when we couldn't | ||||
1094 | /// expand a function parameter pack reference which refers to an expanded | ||||
1095 | /// pack. | ||||
1096 | ExprResult TransformFunctionParmPackExpr(FunctionParmPackExpr *E); | ||||
1097 | |||||
1098 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, | ||||
1099 | FunctionProtoTypeLoc TL) { | ||||
1100 | // Call the base version; it will forward to our overridden version below. | ||||
1101 | return inherited::TransformFunctionProtoType(TLB, TL); | ||||
1102 | } | ||||
1103 | |||||
1104 | template<typename Fn> | ||||
1105 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, | ||||
1106 | FunctionProtoTypeLoc TL, | ||||
1107 | CXXRecordDecl *ThisContext, | ||||
1108 | Qualifiers ThisTypeQuals, | ||||
1109 | Fn TransformExceptionSpec); | ||||
1110 | |||||
1111 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, | ||||
1112 | int indexAdjustment, | ||||
1113 | Optional<unsigned> NumExpansions, | ||||
1114 | bool ExpectParameterPack); | ||||
1115 | |||||
1116 | /// Transforms a template type parameter type by performing | ||||
1117 | /// substitution of the corresponding template type argument. | ||||
1118 | QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, | ||||
1119 | TemplateTypeParmTypeLoc TL); | ||||
1120 | |||||
1121 | /// Transforms an already-substituted template type parameter pack | ||||
1122 | /// into either itself (if we aren't substituting into its pack expansion) | ||||
1123 | /// or the appropriate substituted argument. | ||||
1124 | QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB, | ||||
1125 | SubstTemplateTypeParmPackTypeLoc TL); | ||||
1126 | |||||
1127 | ExprResult TransformLambdaExpr(LambdaExpr *E) { | ||||
1128 | LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); | ||||
1129 | return TreeTransform<TemplateInstantiator>::TransformLambdaExpr(E); | ||||
1130 | } | ||||
1131 | |||||
1132 | ExprResult TransformRequiresExpr(RequiresExpr *E) { | ||||
1133 | LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); | ||||
1134 | return TreeTransform<TemplateInstantiator>::TransformRequiresExpr(E); | ||||
1135 | } | ||||
1136 | |||||
1137 | bool TransformRequiresExprRequirements( | ||||
1138 | ArrayRef<concepts::Requirement *> Reqs, | ||||
1139 | SmallVectorImpl<concepts::Requirement *> &Transformed) { | ||||
1140 | bool SatisfactionDetermined = false; | ||||
1141 | for (concepts::Requirement *Req : Reqs) { | ||||
1142 | concepts::Requirement *TransReq = nullptr; | ||||
1143 | if (!SatisfactionDetermined) { | ||||
1144 | if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) | ||||
1145 | TransReq = TransformTypeRequirement(TypeReq); | ||||
1146 | else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) | ||||
1147 | TransReq = TransformExprRequirement(ExprReq); | ||||
1148 | else | ||||
1149 | TransReq = TransformNestedRequirement( | ||||
1150 | cast<concepts::NestedRequirement>(Req)); | ||||
1151 | if (!TransReq) | ||||
1152 | return true; | ||||
1153 | if (!TransReq->isDependent() && !TransReq->isSatisfied()) | ||||
1154 | // [expr.prim.req]p6 | ||||
1155 | // [...] The substitution and semantic constraint checking | ||||
1156 | // proceeds in lexical order and stops when a condition that | ||||
1157 | // determines the result of the requires-expression is | ||||
1158 | // encountered. [..] | ||||
1159 | SatisfactionDetermined = true; | ||||
1160 | } else | ||||
1161 | TransReq = Req; | ||||
1162 | Transformed.push_back(TransReq); | ||||
1163 | } | ||||
1164 | return false; | ||||
1165 | } | ||||
1166 | |||||
1167 | TemplateParameterList *TransformTemplateParameterList( | ||||
1168 | TemplateParameterList *OrigTPL) { | ||||
1169 | if (!OrigTPL || !OrigTPL->size()) return OrigTPL; | ||||
1170 | |||||
1171 | DeclContext *Owner = OrigTPL->getParam(0)->getDeclContext(); | ||||
1172 | TemplateDeclInstantiator DeclInstantiator(getSema(), | ||||
1173 | /* DeclContext *Owner */ Owner, TemplateArgs); | ||||
1174 | return DeclInstantiator.SubstTemplateParams(OrigTPL); | ||||
1175 | } | ||||
1176 | |||||
1177 | concepts::TypeRequirement * | ||||
1178 | TransformTypeRequirement(concepts::TypeRequirement *Req); | ||||
1179 | concepts::ExprRequirement * | ||||
1180 | TransformExprRequirement(concepts::ExprRequirement *Req); | ||||
1181 | concepts::NestedRequirement * | ||||
1182 | TransformNestedRequirement(concepts::NestedRequirement *Req); | ||||
1183 | |||||
1184 | private: | ||||
1185 | ExprResult transformNonTypeTemplateParmRef(NonTypeTemplateParmDecl *parm, | ||||
1186 | SourceLocation loc, | ||||
1187 | TemplateArgument arg); | ||||
1188 | }; | ||||
1189 | } | ||||
1190 | |||||
1191 | bool TemplateInstantiator::AlreadyTransformed(QualType T) { | ||||
1192 | if (T.isNull()) | ||||
1193 | return true; | ||||
1194 | |||||
1195 | if (T->isInstantiationDependentType() || T->isVariablyModifiedType()) | ||||
1196 | return false; | ||||
1197 | |||||
1198 | getSema().MarkDeclarationsReferencedInType(Loc, T); | ||||
1199 | return true; | ||||
1200 | } | ||||
1201 | |||||
1202 | static TemplateArgument | ||||
1203 | getPackSubstitutedTemplateArgument(Sema &S, TemplateArgument Arg) { | ||||
1204 | assert(S.ArgumentPackSubstitutionIndex >= 0)(static_cast <bool> (S.ArgumentPackSubstitutionIndex >= 0) ? void (0) : __assert_fail ("S.ArgumentPackSubstitutionIndex >= 0" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1204, __extension__ __PRETTY_FUNCTION__)); | ||||
1205 | assert(S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size())(static_cast <bool> (S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size()) ? void (0) : __assert_fail ("S.ArgumentPackSubstitutionIndex < (int)Arg.pack_size()" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1205, __extension__ __PRETTY_FUNCTION__)); | ||||
1206 | Arg = Arg.pack_begin()[S.ArgumentPackSubstitutionIndex]; | ||||
1207 | if (Arg.isPackExpansion()) | ||||
1208 | Arg = Arg.getPackExpansionPattern(); | ||||
1209 | return Arg; | ||||
1210 | } | ||||
1211 | |||||
1212 | Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) { | ||||
1213 | if (!D) | ||||
1214 | return nullptr; | ||||
1215 | |||||
1216 | if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(D)) { | ||||
1217 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | ||||
1218 | // If the corresponding template argument is NULL or non-existent, it's | ||||
1219 | // because we are performing instantiation from explicitly-specified | ||||
1220 | // template arguments in a function template, but there were some | ||||
1221 | // arguments left unspecified. | ||||
1222 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), | ||||
1223 | TTP->getPosition())) | ||||
1224 | return D; | ||||
1225 | |||||
1226 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition()); | ||||
1227 | |||||
1228 | if (TTP->isParameterPack()) { | ||||
1229 | assert(Arg.getKind() == TemplateArgument::Pack &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1230, __extension__ __PRETTY_FUNCTION__)) | ||||
1230 | "Missing argument pack")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1230, __extension__ __PRETTY_FUNCTION__)); | ||||
1231 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1232 | } | ||||
1233 | |||||
1234 | TemplateName Template = Arg.getAsTemplate().getNameToSubstitute(); | ||||
1235 | assert(!Template.isNull() && Template.getAsTemplateDecl() &&(static_cast <bool> (!Template.isNull() && Template .getAsTemplateDecl() && "Wrong kind of template template argument" ) ? void (0) : __assert_fail ("!Template.isNull() && Template.getAsTemplateDecl() && \"Wrong kind of template template argument\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1236, __extension__ __PRETTY_FUNCTION__)) | ||||
1236 | "Wrong kind of template template argument")(static_cast <bool> (!Template.isNull() && Template .getAsTemplateDecl() && "Wrong kind of template template argument" ) ? void (0) : __assert_fail ("!Template.isNull() && Template.getAsTemplateDecl() && \"Wrong kind of template template argument\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1236, __extension__ __PRETTY_FUNCTION__)); | ||||
1237 | return Template.getAsTemplateDecl(); | ||||
1238 | } | ||||
1239 | |||||
1240 | // Fall through to find the instantiated declaration for this template | ||||
1241 | // template parameter. | ||||
1242 | } | ||||
1243 | |||||
1244 | return SemaRef.FindInstantiatedDecl(Loc, cast<NamedDecl>(D), TemplateArgs); | ||||
1245 | } | ||||
1246 | |||||
1247 | Decl *TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) { | ||||
1248 | Decl *Inst = getSema().SubstDecl(D, getSema().CurContext, TemplateArgs); | ||||
1249 | if (!Inst) | ||||
1250 | return nullptr; | ||||
1251 | |||||
1252 | getSema().CurrentInstantiationScope->InstantiatedLocal(D, Inst); | ||||
1253 | return Inst; | ||||
1254 | } | ||||
1255 | |||||
1256 | NamedDecl * | ||||
1257 | TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D, | ||||
1258 | SourceLocation Loc) { | ||||
1259 | // If the first part of the nested-name-specifier was a template type | ||||
1260 | // parameter, instantiate that type parameter down to a tag type. | ||||
1261 | if (TemplateTypeParmDecl *TTPD = dyn_cast_or_null<TemplateTypeParmDecl>(D)) { | ||||
1262 | const TemplateTypeParmType *TTP | ||||
1263 | = cast<TemplateTypeParmType>(getSema().Context.getTypeDeclType(TTPD)); | ||||
1264 | |||||
1265 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | ||||
1266 | // FIXME: This needs testing w/ member access expressions. | ||||
1267 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getIndex()); | ||||
1268 | |||||
1269 | if (TTP->isParameterPack()) { | ||||
1270 | assert(Arg.getKind() == TemplateArgument::Pack &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1271, __extension__ __PRETTY_FUNCTION__)) | ||||
1271 | "Missing argument pack")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1271, __extension__ __PRETTY_FUNCTION__)); | ||||
1272 | |||||
1273 | if (getSema().ArgumentPackSubstitutionIndex == -1) | ||||
1274 | return nullptr; | ||||
1275 | |||||
1276 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1277 | } | ||||
1278 | |||||
1279 | QualType T = Arg.getAsType(); | ||||
1280 | if (T.isNull()) | ||||
1281 | return cast_or_null<NamedDecl>(TransformDecl(Loc, D)); | ||||
1282 | |||||
1283 | if (const TagType *Tag = T->getAs<TagType>()) | ||||
1284 | return Tag->getDecl(); | ||||
1285 | |||||
1286 | // The resulting type is not a tag; complain. | ||||
1287 | getSema().Diag(Loc, diag::err_nested_name_spec_non_tag) << T; | ||||
1288 | return nullptr; | ||||
1289 | } | ||||
1290 | } | ||||
1291 | |||||
1292 | return cast_or_null<NamedDecl>(TransformDecl(Loc, D)); | ||||
1293 | } | ||||
1294 | |||||
1295 | VarDecl * | ||||
1296 | TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl, | ||||
1297 | TypeSourceInfo *Declarator, | ||||
1298 | SourceLocation StartLoc, | ||||
1299 | SourceLocation NameLoc, | ||||
1300 | IdentifierInfo *Name) { | ||||
1301 | VarDecl *Var = inherited::RebuildExceptionDecl(ExceptionDecl, Declarator, | ||||
1302 | StartLoc, NameLoc, Name); | ||||
1303 | if (Var) | ||||
1304 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); | ||||
1305 | return Var; | ||||
1306 | } | ||||
1307 | |||||
1308 | VarDecl *TemplateInstantiator::RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, | ||||
1309 | TypeSourceInfo *TSInfo, | ||||
1310 | QualType T) { | ||||
1311 | VarDecl *Var = inherited::RebuildObjCExceptionDecl(ExceptionDecl, TSInfo, T); | ||||
1312 | if (Var) | ||||
1313 | getSema().CurrentInstantiationScope->InstantiatedLocal(ExceptionDecl, Var); | ||||
1314 | return Var; | ||||
1315 | } | ||||
1316 | |||||
1317 | QualType | ||||
1318 | TemplateInstantiator::RebuildElaboratedType(SourceLocation KeywordLoc, | ||||
1319 | ElaboratedTypeKeyword Keyword, | ||||
1320 | NestedNameSpecifierLoc QualifierLoc, | ||||
1321 | QualType T) { | ||||
1322 | if (const TagType *TT = T->getAs<TagType>()) { | ||||
1323 | TagDecl* TD = TT->getDecl(); | ||||
1324 | |||||
1325 | SourceLocation TagLocation = KeywordLoc; | ||||
1326 | |||||
1327 | IdentifierInfo *Id = TD->getIdentifier(); | ||||
1328 | |||||
1329 | // TODO: should we even warn on struct/class mismatches for this? Seems | ||||
1330 | // like it's likely to produce a lot of spurious errors. | ||||
1331 | if (Id && Keyword != ETK_None && Keyword != ETK_Typename) { | ||||
1332 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); | ||||
1333 | if (!SemaRef.isAcceptableTagRedeclaration(TD, Kind, /*isDefinition*/false, | ||||
1334 | TagLocation, Id)) { | ||||
1335 | SemaRef.Diag(TagLocation, diag::err_use_with_wrong_tag) | ||||
1336 | << Id | ||||
1337 | << FixItHint::CreateReplacement(SourceRange(TagLocation), | ||||
1338 | TD->getKindName()); | ||||
1339 | SemaRef.Diag(TD->getLocation(), diag::note_previous_use); | ||||
1340 | } | ||||
1341 | } | ||||
1342 | } | ||||
1343 | |||||
1344 | return TreeTransform<TemplateInstantiator>::RebuildElaboratedType(KeywordLoc, | ||||
1345 | Keyword, | ||||
1346 | QualifierLoc, | ||||
1347 | T); | ||||
1348 | } | ||||
1349 | |||||
1350 | TemplateName TemplateInstantiator::TransformTemplateName( | ||||
1351 | CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc, | ||||
1352 | QualType ObjectType, NamedDecl *FirstQualifierInScope, | ||||
1353 | bool AllowInjectedClassName) { | ||||
1354 | if (TemplateTemplateParmDecl *TTP | ||||
1355 | = dyn_cast_or_null<TemplateTemplateParmDecl>(Name.getAsTemplateDecl())) { | ||||
1356 | if (TTP->getDepth() < TemplateArgs.getNumLevels()) { | ||||
1357 | // If the corresponding template argument is NULL or non-existent, it's | ||||
1358 | // because we are performing instantiation from explicitly-specified | ||||
1359 | // template arguments in a function template, but there were some | ||||
1360 | // arguments left unspecified. | ||||
1361 | if (!TemplateArgs.hasTemplateArgument(TTP->getDepth(), | ||||
1362 | TTP->getPosition())) | ||||
1363 | return Name; | ||||
1364 | |||||
1365 | TemplateArgument Arg = TemplateArgs(TTP->getDepth(), TTP->getPosition()); | ||||
1366 | |||||
1367 | if (TemplateArgs.isRewrite()) { | ||||
1368 | // We're rewriting the template parameter as a reference to another | ||||
1369 | // template parameter. | ||||
1370 | if (Arg.getKind() == TemplateArgument::Pack) { | ||||
1371 | assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&(static_cast <bool> (Arg.pack_size() == 1 && Arg .pack_begin()->isPackExpansion() && "unexpected pack arguments in template rewrite" ) ? void (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1372, __extension__ __PRETTY_FUNCTION__)) | ||||
1372 | "unexpected pack arguments in template rewrite")(static_cast <bool> (Arg.pack_size() == 1 && Arg .pack_begin()->isPackExpansion() && "unexpected pack arguments in template rewrite" ) ? void (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1372, __extension__ __PRETTY_FUNCTION__)); | ||||
1373 | Arg = Arg.pack_begin()->getPackExpansionPattern(); | ||||
1374 | } | ||||
1375 | assert(Arg.getKind() == TemplateArgument::Template &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Template && "unexpected nontype template argument kind in template rewrite" ) ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Template && \"unexpected nontype template argument kind in template rewrite\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1376, __extension__ __PRETTY_FUNCTION__)) | ||||
1376 | "unexpected nontype template argument kind in template rewrite")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Template && "unexpected nontype template argument kind in template rewrite" ) ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Template && \"unexpected nontype template argument kind in template rewrite\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1376, __extension__ __PRETTY_FUNCTION__)); | ||||
1377 | return Arg.getAsTemplate(); | ||||
1378 | } | ||||
1379 | |||||
1380 | if (TTP->isParameterPack()) { | ||||
1381 | assert(Arg.getKind() == TemplateArgument::Pack &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1382, __extension__ __PRETTY_FUNCTION__)) | ||||
1382 | "Missing argument pack")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1382, __extension__ __PRETTY_FUNCTION__)); | ||||
1383 | |||||
1384 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||
1385 | // We have the template argument pack to substitute, but we're not | ||||
1386 | // actually expanding the enclosing pack expansion yet. So, just | ||||
1387 | // keep the entire argument pack. | ||||
1388 | return getSema().Context.getSubstTemplateTemplateParmPack(TTP, Arg); | ||||
1389 | } | ||||
1390 | |||||
1391 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1392 | } | ||||
1393 | |||||
1394 | TemplateName Template = Arg.getAsTemplate().getNameToSubstitute(); | ||||
1395 | assert(!Template.isNull() && "Null template template argument")(static_cast <bool> (!Template.isNull() && "Null template template argument" ) ? void (0) : __assert_fail ("!Template.isNull() && \"Null template template argument\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1395, __extension__ __PRETTY_FUNCTION__)); | ||||
1396 | assert(!Template.getAsQualifiedTemplateName() &&(static_cast <bool> (!Template.getAsQualifiedTemplateName () && "template decl to substitute is qualified?") ? void (0) : __assert_fail ("!Template.getAsQualifiedTemplateName() && \"template decl to substitute is qualified?\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1397, __extension__ __PRETTY_FUNCTION__)) | ||||
1397 | "template decl to substitute is qualified?")(static_cast <bool> (!Template.getAsQualifiedTemplateName () && "template decl to substitute is qualified?") ? void (0) : __assert_fail ("!Template.getAsQualifiedTemplateName() && \"template decl to substitute is qualified?\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1397, __extension__ __PRETTY_FUNCTION__)); | ||||
1398 | |||||
1399 | Template = getSema().Context.getSubstTemplateTemplateParm(TTP, Template); | ||||
1400 | return Template; | ||||
1401 | } | ||||
1402 | } | ||||
1403 | |||||
1404 | if (SubstTemplateTemplateParmPackStorage *SubstPack | ||||
1405 | = Name.getAsSubstTemplateTemplateParmPack()) { | ||||
1406 | if (getSema().ArgumentPackSubstitutionIndex == -1) | ||||
1407 | return Name; | ||||
1408 | |||||
1409 | TemplateArgument Arg = SubstPack->getArgumentPack(); | ||||
1410 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1411 | return Arg.getAsTemplate().getNameToSubstitute(); | ||||
1412 | } | ||||
1413 | |||||
1414 | return inherited::TransformTemplateName(SS, Name, NameLoc, ObjectType, | ||||
1415 | FirstQualifierInScope, | ||||
1416 | AllowInjectedClassName); | ||||
1417 | } | ||||
1418 | |||||
1419 | ExprResult | ||||
1420 | TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) { | ||||
1421 | if (!E->isTypeDependent()) | ||||
1422 | return E; | ||||
1423 | |||||
1424 | return getSema().BuildPredefinedExpr(E->getLocation(), E->getIdentKind()); | ||||
1425 | } | ||||
1426 | |||||
1427 | ExprResult | ||||
1428 | TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E, | ||||
1429 | NonTypeTemplateParmDecl *NTTP) { | ||||
1430 | // If the corresponding template argument is NULL or non-existent, it's | ||||
1431 | // because we are performing instantiation from explicitly-specified | ||||
1432 | // template arguments in a function template, but there were some | ||||
1433 | // arguments left unspecified. | ||||
1434 | if (!TemplateArgs.hasTemplateArgument(NTTP->getDepth(), | ||||
1435 | NTTP->getPosition())) | ||||
1436 | return E; | ||||
1437 | |||||
1438 | TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), NTTP->getPosition()); | ||||
1439 | |||||
1440 | if (TemplateArgs.isRewrite()) { | ||||
1441 | // We're rewriting the template parameter as a reference to another | ||||
1442 | // template parameter. | ||||
1443 | if (Arg.getKind() == TemplateArgument::Pack) { | ||||
1444 | assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&(static_cast <bool> (Arg.pack_size() == 1 && Arg .pack_begin()->isPackExpansion() && "unexpected pack arguments in template rewrite" ) ? void (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1445, __extension__ __PRETTY_FUNCTION__)) | ||||
1445 | "unexpected pack arguments in template rewrite")(static_cast <bool> (Arg.pack_size() == 1 && Arg .pack_begin()->isPackExpansion() && "unexpected pack arguments in template rewrite" ) ? void (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1445, __extension__ __PRETTY_FUNCTION__)); | ||||
1446 | Arg = Arg.pack_begin()->getPackExpansionPattern(); | ||||
1447 | } | ||||
1448 | assert(Arg.getKind() == TemplateArgument::Expression &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Expression && "unexpected nontype template argument kind in template rewrite" ) ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Expression && \"unexpected nontype template argument kind in template rewrite\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1449, __extension__ __PRETTY_FUNCTION__)) | ||||
1449 | "unexpected nontype template argument kind in template rewrite")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Expression && "unexpected nontype template argument kind in template rewrite" ) ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Expression && \"unexpected nontype template argument kind in template rewrite\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1449, __extension__ __PRETTY_FUNCTION__)); | ||||
1450 | // FIXME: This can lead to the same subexpression appearing multiple times | ||||
1451 | // in a complete expression. | ||||
1452 | return Arg.getAsExpr(); | ||||
1453 | } | ||||
1454 | |||||
1455 | if (NTTP->isParameterPack()) { | ||||
1456 | assert(Arg.getKind() == TemplateArgument::Pack &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1457, __extension__ __PRETTY_FUNCTION__)) | ||||
1457 | "Missing argument pack")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1457, __extension__ __PRETTY_FUNCTION__)); | ||||
1458 | |||||
1459 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||
1460 | // We have an argument pack, but we can't select a particular argument | ||||
1461 | // out of it yet. Therefore, we'll build an expression to hold on to that | ||||
1462 | // argument pack. | ||||
1463 | QualType TargetType = SemaRef.SubstType(NTTP->getType(), TemplateArgs, | ||||
1464 | E->getLocation(), | ||||
1465 | NTTP->getDeclName()); | ||||
1466 | if (TargetType.isNull()) | ||||
1467 | return ExprError(); | ||||
1468 | |||||
1469 | QualType ExprType = TargetType.getNonLValueExprType(SemaRef.Context); | ||||
1470 | if (TargetType->isRecordType()) | ||||
1471 | ExprType.addConst(); | ||||
1472 | |||||
1473 | return new (SemaRef.Context) SubstNonTypeTemplateParmPackExpr( | ||||
1474 | ExprType, TargetType->isReferenceType() ? VK_LValue : VK_PRValue, | ||||
1475 | NTTP, E->getLocation(), Arg); | ||||
1476 | } | ||||
1477 | |||||
1478 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1479 | } | ||||
1480 | |||||
1481 | return transformNonTypeTemplateParmRef(NTTP, E->getLocation(), Arg); | ||||
1482 | } | ||||
1483 | |||||
1484 | const LoopHintAttr * | ||||
1485 | TemplateInstantiator::TransformLoopHintAttr(const LoopHintAttr *LH) { | ||||
1486 | Expr *TransformedExpr = getDerived().TransformExpr(LH->getValue()).get(); | ||||
1487 | |||||
1488 | if (TransformedExpr == LH->getValue()) | ||||
1489 | return LH; | ||||
1490 | |||||
1491 | // Generate error if there is a problem with the value. | ||||
1492 | if (getSema().CheckLoopHintExpr(TransformedExpr, LH->getLocation())) | ||||
1493 | return LH; | ||||
1494 | |||||
1495 | // Create new LoopHintValueAttr with integral expression in place of the | ||||
1496 | // non-type template parameter. | ||||
1497 | return LoopHintAttr::CreateImplicit(getSema().Context, LH->getOption(), | ||||
1498 | LH->getState(), TransformedExpr, *LH); | ||||
1499 | } | ||||
1500 | |||||
1501 | ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef( | ||||
1502 | NonTypeTemplateParmDecl *parm, | ||||
1503 | SourceLocation loc, | ||||
1504 | TemplateArgument arg) { | ||||
1505 | ExprResult result; | ||||
1506 | |||||
1507 | // Determine the substituted parameter type. We can usually infer this from | ||||
1508 | // the template argument, but not always. | ||||
1509 | auto SubstParamType = [&] { | ||||
1510 | QualType T; | ||||
1511 | if (parm->isExpandedParameterPack()) | ||||
1512 | T = parm->getExpansionType(SemaRef.ArgumentPackSubstitutionIndex); | ||||
1513 | else | ||||
1514 | T = parm->getType(); | ||||
1515 | if (parm->isParameterPack() && isa<PackExpansionType>(T)) | ||||
1516 | T = cast<PackExpansionType>(T)->getPattern(); | ||||
1517 | return SemaRef.SubstType(T, TemplateArgs, loc, parm->getDeclName()); | ||||
1518 | }; | ||||
1519 | |||||
1520 | bool refParam = false; | ||||
1521 | |||||
1522 | // The template argument itself might be an expression, in which case we just | ||||
1523 | // return that expression. This happens when substituting into an alias | ||||
1524 | // template. | ||||
1525 | if (arg.getKind() == TemplateArgument::Expression) { | ||||
1526 | Expr *argExpr = arg.getAsExpr(); | ||||
1527 | result = argExpr; | ||||
1528 | if (argExpr->isLValue()) { | ||||
1529 | if (argExpr->getType()->isRecordType()) { | ||||
1530 | // Check whether the parameter was actually a reference. | ||||
1531 | QualType paramType = SubstParamType(); | ||||
1532 | if (paramType.isNull()) | ||||
1533 | return ExprError(); | ||||
1534 | refParam = paramType->isReferenceType(); | ||||
1535 | } else { | ||||
1536 | refParam = true; | ||||
1537 | } | ||||
1538 | } | ||||
1539 | } else if (arg.getKind() == TemplateArgument::Declaration || | ||||
1540 | arg.getKind() == TemplateArgument::NullPtr) { | ||||
1541 | ValueDecl *VD; | ||||
1542 | if (arg.getKind() == TemplateArgument::Declaration) { | ||||
1543 | VD = arg.getAsDecl(); | ||||
1544 | |||||
1545 | // Find the instantiation of the template argument. This is | ||||
1546 | // required for nested templates. | ||||
1547 | VD = cast_or_null<ValueDecl>( | ||||
1548 | getSema().FindInstantiatedDecl(loc, VD, TemplateArgs)); | ||||
1549 | if (!VD) | ||||
1550 | return ExprError(); | ||||
1551 | } else { | ||||
1552 | // Propagate NULL template argument. | ||||
1553 | VD = nullptr; | ||||
1554 | } | ||||
1555 | |||||
1556 | QualType paramType = VD ? arg.getParamTypeForDecl() : arg.getNullPtrType(); | ||||
1557 | assert(!paramType.isNull() && "type substitution failed for param type")(static_cast <bool> (!paramType.isNull() && "type substitution failed for param type" ) ? void (0) : __assert_fail ("!paramType.isNull() && \"type substitution failed for param type\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1557, __extension__ __PRETTY_FUNCTION__)); | ||||
1558 | assert(!paramType->isDependentType() && "param type still dependent")(static_cast <bool> (!paramType->isDependentType() && "param type still dependent") ? void (0) : __assert_fail ("!paramType->isDependentType() && \"param type still dependent\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1558, __extension__ __PRETTY_FUNCTION__)); | ||||
1559 | result = SemaRef.BuildExpressionFromDeclTemplateArgument(arg, paramType, loc); | ||||
1560 | refParam = paramType->isReferenceType(); | ||||
1561 | } else { | ||||
1562 | result = SemaRef.BuildExpressionFromIntegralTemplateArgument(arg, loc); | ||||
1563 | assert(result.isInvalid() ||(static_cast <bool> (result.isInvalid() || SemaRef.Context .hasSameType(result.get()->getType(), arg.getIntegralType( ))) ? void (0) : __assert_fail ("result.isInvalid() || SemaRef.Context.hasSameType(result.get()->getType(), arg.getIntegralType())" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1565, __extension__ __PRETTY_FUNCTION__)) | ||||
1564 | SemaRef.Context.hasSameType(result.get()->getType(),(static_cast <bool> (result.isInvalid() || SemaRef.Context .hasSameType(result.get()->getType(), arg.getIntegralType( ))) ? void (0) : __assert_fail ("result.isInvalid() || SemaRef.Context.hasSameType(result.get()->getType(), arg.getIntegralType())" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1565, __extension__ __PRETTY_FUNCTION__)) | ||||
1565 | arg.getIntegralType()))(static_cast <bool> (result.isInvalid() || SemaRef.Context .hasSameType(result.get()->getType(), arg.getIntegralType( ))) ? void (0) : __assert_fail ("result.isInvalid() || SemaRef.Context.hasSameType(result.get()->getType(), arg.getIntegralType())" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1565, __extension__ __PRETTY_FUNCTION__)); | ||||
1566 | } | ||||
1567 | |||||
1568 | if (result.isInvalid()) | ||||
1569 | return ExprError(); | ||||
1570 | |||||
1571 | Expr *resultExpr = result.get(); | ||||
1572 | return new (SemaRef.Context) SubstNonTypeTemplateParmExpr( | ||||
1573 | resultExpr->getType(), resultExpr->getValueKind(), loc, parm, refParam, | ||||
1574 | resultExpr); | ||||
1575 | } | ||||
1576 | |||||
1577 | ExprResult | ||||
1578 | TemplateInstantiator::TransformSubstNonTypeTemplateParmPackExpr( | ||||
1579 | SubstNonTypeTemplateParmPackExpr *E) { | ||||
1580 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||
1581 | // We aren't expanding the parameter pack, so just return ourselves. | ||||
1582 | return E; | ||||
1583 | } | ||||
1584 | |||||
1585 | TemplateArgument Arg = E->getArgumentPack(); | ||||
1586 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1587 | return transformNonTypeTemplateParmRef(E->getParameterPack(), | ||||
1588 | E->getParameterPackLocation(), | ||||
1589 | Arg); | ||||
1590 | } | ||||
1591 | |||||
1592 | ExprResult | ||||
1593 | TemplateInstantiator::TransformSubstNonTypeTemplateParmExpr( | ||||
1594 | SubstNonTypeTemplateParmExpr *E) { | ||||
1595 | ExprResult SubstReplacement = E->getReplacement(); | ||||
1596 | if (!isa<ConstantExpr>(SubstReplacement.get())) | ||||
1597 | SubstReplacement = TransformExpr(E->getReplacement()); | ||||
1598 | if (SubstReplacement.isInvalid()) | ||||
1599 | return true; | ||||
1600 | QualType SubstType = TransformType(E->getParameterType(getSema().Context)); | ||||
1601 | if (SubstType.isNull()) | ||||
1602 | return true; | ||||
1603 | // The type may have been previously dependent and not now, which means we | ||||
1604 | // might have to implicit cast the argument to the new type, for example: | ||||
1605 | // template<auto T, decltype(T) U> | ||||
1606 | // concept C = sizeof(U) == 4; | ||||
1607 | // void foo() requires C<2, 'a'> { } | ||||
1608 | // When normalizing foo(), we first form the normalized constraints of C: | ||||
1609 | // AtomicExpr(sizeof(U) == 4, | ||||
1610 | // U=SubstNonTypeTemplateParmExpr(Param=U, | ||||
1611 | // Expr=DeclRef(U), | ||||
1612 | // Type=decltype(T))) | ||||
1613 | // Then we substitute T = 2, U = 'a' into the parameter mapping, and need to | ||||
1614 | // produce: | ||||
1615 | // AtomicExpr(sizeof(U) == 4, | ||||
1616 | // U=SubstNonTypeTemplateParmExpr(Param=U, | ||||
1617 | // Expr=ImpCast( | ||||
1618 | // decltype(2), | ||||
1619 | // SubstNTTPE(Param=U, Expr='a', | ||||
1620 | // Type=char)), | ||||
1621 | // Type=decltype(2))) | ||||
1622 | // The call to CheckTemplateArgument here produces the ImpCast. | ||||
1623 | TemplateArgument Converted; | ||||
1624 | if (SemaRef.CheckTemplateArgument(E->getParameter(), SubstType, | ||||
1625 | SubstReplacement.get(), | ||||
1626 | Converted).isInvalid()) | ||||
1627 | return true; | ||||
1628 | return transformNonTypeTemplateParmRef(E->getParameter(), | ||||
1629 | E->getExprLoc(), Converted); | ||||
1630 | } | ||||
1631 | |||||
1632 | ExprResult TemplateInstantiator::RebuildVarDeclRefExpr(VarDecl *PD, | ||||
1633 | SourceLocation Loc) { | ||||
1634 | DeclarationNameInfo NameInfo(PD->getDeclName(), Loc); | ||||
1635 | return getSema().BuildDeclarationNameExpr(CXXScopeSpec(), NameInfo, PD); | ||||
1636 | } | ||||
1637 | |||||
1638 | ExprResult | ||||
1639 | TemplateInstantiator::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { | ||||
1640 | if (getSema().ArgumentPackSubstitutionIndex != -1) { | ||||
1641 | // We can expand this parameter pack now. | ||||
1642 | VarDecl *D = E->getExpansion(getSema().ArgumentPackSubstitutionIndex); | ||||
1643 | VarDecl *VD = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), D)); | ||||
1644 | if (!VD) | ||||
1645 | return ExprError(); | ||||
1646 | return RebuildVarDeclRefExpr(VD, E->getExprLoc()); | ||||
1647 | } | ||||
1648 | |||||
1649 | QualType T = TransformType(E->getType()); | ||||
1650 | if (T.isNull()) | ||||
1651 | return ExprError(); | ||||
1652 | |||||
1653 | // Transform each of the parameter expansions into the corresponding | ||||
1654 | // parameters in the instantiation of the function decl. | ||||
1655 | SmallVector<VarDecl *, 8> Vars; | ||||
1656 | Vars.reserve(E->getNumExpansions()); | ||||
1657 | for (FunctionParmPackExpr::iterator I = E->begin(), End = E->end(); | ||||
1658 | I != End; ++I) { | ||||
1659 | VarDecl *D = cast_or_null<VarDecl>(TransformDecl(E->getExprLoc(), *I)); | ||||
1660 | if (!D) | ||||
1661 | return ExprError(); | ||||
1662 | Vars.push_back(D); | ||||
1663 | } | ||||
1664 | |||||
1665 | auto *PackExpr = | ||||
1666 | FunctionParmPackExpr::Create(getSema().Context, T, E->getParameterPack(), | ||||
1667 | E->getParameterPackLocation(), Vars); | ||||
1668 | getSema().MarkFunctionParmPackReferenced(PackExpr); | ||||
1669 | return PackExpr; | ||||
1670 | } | ||||
1671 | |||||
1672 | ExprResult | ||||
1673 | TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E, | ||||
1674 | VarDecl *PD) { | ||||
1675 | typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack; | ||||
1676 | llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found | ||||
1677 | = getSema().CurrentInstantiationScope->findInstantiationOf(PD); | ||||
1678 | assert(Found && "no instantiation for parameter pack")(static_cast <bool> (Found && "no instantiation for parameter pack" ) ? void (0) : __assert_fail ("Found && \"no instantiation for parameter pack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1678, __extension__ __PRETTY_FUNCTION__)); | ||||
1679 | |||||
1680 | Decl *TransformedDecl; | ||||
1681 | if (DeclArgumentPack *Pack = Found->dyn_cast<DeclArgumentPack *>()) { | ||||
1682 | // If this is a reference to a function parameter pack which we can | ||||
1683 | // substitute but can't yet expand, build a FunctionParmPackExpr for it. | ||||
1684 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||
1685 | QualType T = TransformType(E->getType()); | ||||
1686 | if (T.isNull()) | ||||
1687 | return ExprError(); | ||||
1688 | auto *PackExpr = FunctionParmPackExpr::Create(getSema().Context, T, PD, | ||||
1689 | E->getExprLoc(), *Pack); | ||||
1690 | getSema().MarkFunctionParmPackReferenced(PackExpr); | ||||
1691 | return PackExpr; | ||||
1692 | } | ||||
1693 | |||||
1694 | TransformedDecl = (*Pack)[getSema().ArgumentPackSubstitutionIndex]; | ||||
1695 | } else { | ||||
1696 | TransformedDecl = Found->get<Decl*>(); | ||||
1697 | } | ||||
1698 | |||||
1699 | // We have either an unexpanded pack or a specific expansion. | ||||
1700 | return RebuildVarDeclRefExpr(cast<VarDecl>(TransformedDecl), E->getExprLoc()); | ||||
1701 | } | ||||
1702 | |||||
1703 | ExprResult | ||||
1704 | TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) { | ||||
1705 | NamedDecl *D = E->getDecl(); | ||||
1706 | |||||
1707 | // Handle references to non-type template parameters and non-type template | ||||
1708 | // parameter packs. | ||||
1709 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(D)) { | ||||
1710 | if (NTTP->getDepth() < TemplateArgs.getNumLevels()) | ||||
1711 | return TransformTemplateParmRefExpr(E, NTTP); | ||||
1712 | |||||
1713 | // We have a non-type template parameter that isn't fully substituted; | ||||
1714 | // FindInstantiatedDecl will find it in the local instantiation scope. | ||||
1715 | } | ||||
1716 | |||||
1717 | // Handle references to function parameter packs. | ||||
1718 | if (VarDecl *PD = dyn_cast<VarDecl>(D)) | ||||
1719 | if (PD->isParameterPack()) | ||||
1720 | return TransformFunctionParmPackRefExpr(E, PD); | ||||
1721 | |||||
1722 | return TreeTransform<TemplateInstantiator>::TransformDeclRefExpr(E); | ||||
1723 | } | ||||
1724 | |||||
1725 | ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr( | ||||
1726 | CXXDefaultArgExpr *E) { | ||||
1727 | assert(!cast<FunctionDecl>(E->getParam()->getDeclContext())->(static_cast <bool> (!cast<FunctionDecl>(E->getParam ()->getDeclContext())-> getDescribedFunctionTemplate() && "Default arg expressions are never formed in dependent cases." ) ? void (0) : __assert_fail ("!cast<FunctionDecl>(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1729, __extension__ __PRETTY_FUNCTION__)) | ||||
1728 | getDescribedFunctionTemplate() &&(static_cast <bool> (!cast<FunctionDecl>(E->getParam ()->getDeclContext())-> getDescribedFunctionTemplate() && "Default arg expressions are never formed in dependent cases." ) ? void (0) : __assert_fail ("!cast<FunctionDecl>(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1729, __extension__ __PRETTY_FUNCTION__)) | ||||
1729 | "Default arg expressions are never formed in dependent cases.")(static_cast <bool> (!cast<FunctionDecl>(E->getParam ()->getDeclContext())-> getDescribedFunctionTemplate() && "Default arg expressions are never formed in dependent cases." ) ? void (0) : __assert_fail ("!cast<FunctionDecl>(E->getParam()->getDeclContext())-> getDescribedFunctionTemplate() && \"Default arg expressions are never formed in dependent cases.\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1729, __extension__ __PRETTY_FUNCTION__)); | ||||
1730 | return SemaRef.BuildCXXDefaultArgExpr(E->getUsedLocation(), | ||||
1731 | cast<FunctionDecl>(E->getParam()->getDeclContext()), | ||||
1732 | E->getParam()); | ||||
1733 | } | ||||
1734 | |||||
1735 | template<typename Fn> | ||||
1736 | QualType TemplateInstantiator::TransformFunctionProtoType(TypeLocBuilder &TLB, | ||||
1737 | FunctionProtoTypeLoc TL, | ||||
1738 | CXXRecordDecl *ThisContext, | ||||
1739 | Qualifiers ThisTypeQuals, | ||||
1740 | Fn TransformExceptionSpec) { | ||||
1741 | // We need a local instantiation scope for this function prototype. | ||||
1742 | LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true); | ||||
1743 | return inherited::TransformFunctionProtoType( | ||||
1744 | TLB, TL, ThisContext, ThisTypeQuals, TransformExceptionSpec); | ||||
1745 | } | ||||
1746 | |||||
1747 | ParmVarDecl * | ||||
1748 | TemplateInstantiator::TransformFunctionTypeParam(ParmVarDecl *OldParm, | ||||
1749 | int indexAdjustment, | ||||
1750 | Optional<unsigned> NumExpansions, | ||||
1751 | bool ExpectParameterPack) { | ||||
1752 | auto NewParm = | ||||
1753 | SemaRef.SubstParmVarDecl(OldParm, TemplateArgs, indexAdjustment, | ||||
1754 | NumExpansions, ExpectParameterPack); | ||||
1755 | if (NewParm && SemaRef.getLangOpts().OpenCL) | ||||
1756 | SemaRef.deduceOpenCLAddressSpace(NewParm); | ||||
1757 | return NewParm; | ||||
1758 | } | ||||
1759 | |||||
1760 | QualType | ||||
1761 | TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB, | ||||
1762 | TemplateTypeParmTypeLoc TL) { | ||||
1763 | const TemplateTypeParmType *T = TL.getTypePtr(); | ||||
1764 | if (T->getDepth() < TemplateArgs.getNumLevels()) { | ||||
1765 | // Replace the template type parameter with its corresponding | ||||
1766 | // template argument. | ||||
1767 | |||||
1768 | // If the corresponding template argument is NULL or doesn't exist, it's | ||||
1769 | // because we are performing instantiation from explicitly-specified | ||||
1770 | // template arguments in a function template class, but there were some | ||||
1771 | // arguments left unspecified. | ||||
1772 | if (!TemplateArgs.hasTemplateArgument(T->getDepth(), T->getIndex())) { | ||||
1773 | TemplateTypeParmTypeLoc NewTL | ||||
1774 | = TLB.push<TemplateTypeParmTypeLoc>(TL.getType()); | ||||
1775 | NewTL.setNameLoc(TL.getNameLoc()); | ||||
1776 | return TL.getType(); | ||||
1777 | } | ||||
1778 | |||||
1779 | TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex()); | ||||
1780 | |||||
1781 | if (TemplateArgs.isRewrite()) { | ||||
1782 | // We're rewriting the template parameter as a reference to another | ||||
1783 | // template parameter. | ||||
1784 | if (Arg.getKind() == TemplateArgument::Pack) { | ||||
1785 | assert(Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() &&(static_cast <bool> (Arg.pack_size() == 1 && Arg .pack_begin()->isPackExpansion() && "unexpected pack arguments in template rewrite" ) ? void (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1786, __extension__ __PRETTY_FUNCTION__)) | ||||
1786 | "unexpected pack arguments in template rewrite")(static_cast <bool> (Arg.pack_size() == 1 && Arg .pack_begin()->isPackExpansion() && "unexpected pack arguments in template rewrite" ) ? void (0) : __assert_fail ("Arg.pack_size() == 1 && Arg.pack_begin()->isPackExpansion() && \"unexpected pack arguments in template rewrite\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1786, __extension__ __PRETTY_FUNCTION__)); | ||||
1787 | Arg = Arg.pack_begin()->getPackExpansionPattern(); | ||||
1788 | } | ||||
1789 | assert(Arg.getKind() == TemplateArgument::Type &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Type && "unexpected nontype template argument kind in template rewrite" ) ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Type && \"unexpected nontype template argument kind in template rewrite\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1790, __extension__ __PRETTY_FUNCTION__)) | ||||
1790 | "unexpected nontype template argument kind in template rewrite")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Type && "unexpected nontype template argument kind in template rewrite" ) ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Type && \"unexpected nontype template argument kind in template rewrite\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1790, __extension__ __PRETTY_FUNCTION__)); | ||||
1791 | QualType NewT = Arg.getAsType(); | ||||
1792 | assert(isa<TemplateTypeParmType>(NewT) &&(static_cast <bool> (isa<TemplateTypeParmType>(NewT ) && "type parm not rewritten to type parm") ? void ( 0) : __assert_fail ("isa<TemplateTypeParmType>(NewT) && \"type parm not rewritten to type parm\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1793, __extension__ __PRETTY_FUNCTION__)) | ||||
1793 | "type parm not rewritten to type parm")(static_cast <bool> (isa<TemplateTypeParmType>(NewT ) && "type parm not rewritten to type parm") ? void ( 0) : __assert_fail ("isa<TemplateTypeParmType>(NewT) && \"type parm not rewritten to type parm\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1793, __extension__ __PRETTY_FUNCTION__)); | ||||
1794 | auto NewTL = TLB.push<TemplateTypeParmTypeLoc>(NewT); | ||||
1795 | NewTL.setNameLoc(TL.getNameLoc()); | ||||
1796 | return NewT; | ||||
1797 | } | ||||
1798 | |||||
1799 | if (T->isParameterPack()) { | ||||
1800 | assert(Arg.getKind() == TemplateArgument::Pack &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1801, __extension__ __PRETTY_FUNCTION__)) | ||||
1801 | "Missing argument pack")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Pack && "Missing argument pack") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Pack && \"Missing argument pack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1801, __extension__ __PRETTY_FUNCTION__)); | ||||
1802 | |||||
1803 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||
1804 | // We have the template argument pack, but we're not expanding the | ||||
1805 | // enclosing pack expansion yet. Just save the template argument | ||||
1806 | // pack for later substitution. | ||||
1807 | QualType Result | ||||
1808 | = getSema().Context.getSubstTemplateTypeParmPackType(T, Arg); | ||||
1809 | SubstTemplateTypeParmPackTypeLoc NewTL | ||||
1810 | = TLB.push<SubstTemplateTypeParmPackTypeLoc>(Result); | ||||
1811 | NewTL.setNameLoc(TL.getNameLoc()); | ||||
1812 | return Result; | ||||
1813 | } | ||||
1814 | |||||
1815 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1816 | } | ||||
1817 | |||||
1818 | assert(Arg.getKind() == TemplateArgument::Type &&(static_cast <bool> (Arg.getKind() == TemplateArgument:: Type && "Template argument kind mismatch") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Type && \"Template argument kind mismatch\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1819, __extension__ __PRETTY_FUNCTION__)) | ||||
1819 | "Template argument kind mismatch")(static_cast <bool> (Arg.getKind() == TemplateArgument:: Type && "Template argument kind mismatch") ? void (0) : __assert_fail ("Arg.getKind() == TemplateArgument::Type && \"Template argument kind mismatch\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1819, __extension__ __PRETTY_FUNCTION__)); | ||||
1820 | |||||
1821 | QualType Replacement = Arg.getAsType(); | ||||
1822 | |||||
1823 | // TODO: only do this uniquing once, at the start of instantiation. | ||||
1824 | QualType Result | ||||
1825 | = getSema().Context.getSubstTemplateTypeParmType(T, Replacement); | ||||
1826 | SubstTemplateTypeParmTypeLoc NewTL | ||||
1827 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); | ||||
1828 | NewTL.setNameLoc(TL.getNameLoc()); | ||||
1829 | return Result; | ||||
1830 | } | ||||
1831 | |||||
1832 | // The template type parameter comes from an inner template (e.g., | ||||
1833 | // the template parameter list of a member template inside the | ||||
1834 | // template we are instantiating). Create a new template type | ||||
1835 | // parameter with the template "level" reduced by one. | ||||
1836 | TemplateTypeParmDecl *NewTTPDecl = nullptr; | ||||
1837 | if (TemplateTypeParmDecl *OldTTPDecl = T->getDecl()) | ||||
1838 | NewTTPDecl = cast_or_null<TemplateTypeParmDecl>( | ||||
1839 | TransformDecl(TL.getNameLoc(), OldTTPDecl)); | ||||
1840 | |||||
1841 | QualType Result = getSema().Context.getTemplateTypeParmType( | ||||
1842 | T->getDepth() - TemplateArgs.getNumSubstitutedLevels(), T->getIndex(), | ||||
1843 | T->isParameterPack(), NewTTPDecl); | ||||
1844 | TemplateTypeParmTypeLoc NewTL = TLB.push<TemplateTypeParmTypeLoc>(Result); | ||||
1845 | NewTL.setNameLoc(TL.getNameLoc()); | ||||
1846 | return Result; | ||||
1847 | } | ||||
1848 | |||||
1849 | QualType | ||||
1850 | TemplateInstantiator::TransformSubstTemplateTypeParmPackType( | ||||
1851 | TypeLocBuilder &TLB, | ||||
1852 | SubstTemplateTypeParmPackTypeLoc TL) { | ||||
1853 | if (getSema().ArgumentPackSubstitutionIndex == -1) { | ||||
1854 | // We aren't expanding the parameter pack, so just return ourselves. | ||||
1855 | SubstTemplateTypeParmPackTypeLoc NewTL | ||||
1856 | = TLB.push<SubstTemplateTypeParmPackTypeLoc>(TL.getType()); | ||||
1857 | NewTL.setNameLoc(TL.getNameLoc()); | ||||
1858 | return TL.getType(); | ||||
1859 | } | ||||
1860 | |||||
1861 | TemplateArgument Arg = TL.getTypePtr()->getArgumentPack(); | ||||
1862 | Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); | ||||
1863 | QualType Result = Arg.getAsType(); | ||||
1864 | |||||
1865 | Result = getSema().Context.getSubstTemplateTypeParmType( | ||||
1866 | TL.getTypePtr()->getReplacedParameter(), | ||||
1867 | Result); | ||||
1868 | SubstTemplateTypeParmTypeLoc NewTL | ||||
1869 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); | ||||
1870 | NewTL.setNameLoc(TL.getNameLoc()); | ||||
1871 | return Result; | ||||
1872 | } | ||||
1873 | |||||
1874 | template<typename EntityPrinter> | ||||
1875 | static concepts::Requirement::SubstitutionDiagnostic * | ||||
1876 | createSubstDiag(Sema &S, TemplateDeductionInfo &Info, EntityPrinter Printer) { | ||||
1877 | SmallString<128> Message; | ||||
1878 | SourceLocation ErrorLoc; | ||||
1879 | if (Info.hasSFINAEDiagnostic()) { | ||||
1880 | PartialDiagnosticAt PDA(SourceLocation(), | ||||
1881 | PartialDiagnostic::NullDiagnostic{}); | ||||
1882 | Info.takeSFINAEDiagnostic(PDA); | ||||
1883 | PDA.second.EmitToString(S.getDiagnostics(), Message); | ||||
1884 | ErrorLoc = PDA.first; | ||||
1885 | } else { | ||||
1886 | ErrorLoc = Info.getLocation(); | ||||
1887 | } | ||||
1888 | char *MessageBuf = new (S.Context) char[Message.size()]; | ||||
1889 | std::copy(Message.begin(), Message.end(), MessageBuf); | ||||
1890 | SmallString<128> Entity; | ||||
1891 | llvm::raw_svector_ostream OS(Entity); | ||||
1892 | Printer(OS); | ||||
1893 | char *EntityBuf = new (S.Context) char[Entity.size()]; | ||||
1894 | std::copy(Entity.begin(), Entity.end(), EntityBuf); | ||||
1895 | return new (S.Context) concepts::Requirement::SubstitutionDiagnostic{ | ||||
1896 | StringRef(EntityBuf, Entity.size()), ErrorLoc, | ||||
1897 | StringRef(MessageBuf, Message.size())}; | ||||
1898 | } | ||||
1899 | |||||
1900 | concepts::TypeRequirement * | ||||
1901 | TemplateInstantiator::TransformTypeRequirement(concepts::TypeRequirement *Req) { | ||||
1902 | if (!Req->isDependent() && !AlwaysRebuild()) | ||||
1903 | return Req; | ||||
1904 | if (Req->isSubstitutionFailure()) { | ||||
1905 | if (AlwaysRebuild()) | ||||
1906 | return RebuildTypeRequirement( | ||||
1907 | Req->getSubstitutionDiagnostic()); | ||||
1908 | return Req; | ||||
1909 | } | ||||
1910 | |||||
1911 | Sema::SFINAETrap Trap(SemaRef); | ||||
1912 | TemplateDeductionInfo Info(Req->getType()->getTypeLoc().getBeginLoc()); | ||||
1913 | Sema::InstantiatingTemplate TypeInst(SemaRef, | ||||
1914 | Req->getType()->getTypeLoc().getBeginLoc(), Req, Info, | ||||
1915 | Req->getType()->getTypeLoc().getSourceRange()); | ||||
1916 | if (TypeInst.isInvalid()) | ||||
1917 | return nullptr; | ||||
1918 | TypeSourceInfo *TransType = TransformType(Req->getType()); | ||||
1919 | if (!TransType || Trap.hasErrorOccurred()) | ||||
1920 | return RebuildTypeRequirement(createSubstDiag(SemaRef, Info, | ||||
1921 | [&] (llvm::raw_ostream& OS) { | ||||
1922 | Req->getType()->getType().print(OS, SemaRef.getPrintingPolicy()); | ||||
1923 | })); | ||||
1924 | return RebuildTypeRequirement(TransType); | ||||
1925 | } | ||||
1926 | |||||
1927 | concepts::ExprRequirement * | ||||
1928 | TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) { | ||||
1929 | if (!Req->isDependent() && !AlwaysRebuild()) | ||||
1930 | return Req; | ||||
1931 | |||||
1932 | Sema::SFINAETrap Trap(SemaRef); | ||||
1933 | |||||
1934 | llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> | ||||
1935 | TransExpr; | ||||
1936 | if (Req->isExprSubstitutionFailure()) | ||||
1937 | TransExpr = Req->getExprSubstitutionDiagnostic(); | ||||
1938 | else { | ||||
1939 | Expr *E = Req->getExpr(); | ||||
1940 | TemplateDeductionInfo Info(E->getBeginLoc()); | ||||
1941 | Sema::InstantiatingTemplate ExprInst(SemaRef, E->getBeginLoc(), Req, Info, | ||||
1942 | E->getSourceRange()); | ||||
1943 | if (ExprInst.isInvalid()) | ||||
1944 | return nullptr; | ||||
1945 | ExprResult TransExprRes = TransformExpr(E); | ||||
1946 | if (TransExprRes.isInvalid() || Trap.hasErrorOccurred()) | ||||
1947 | TransExpr = createSubstDiag(SemaRef, Info, [&](llvm::raw_ostream &OS) { | ||||
1948 | E->printPretty(OS, nullptr, SemaRef.getPrintingPolicy()); | ||||
1949 | }); | ||||
1950 | else | ||||
1951 | TransExpr = TransExprRes.get(); | ||||
1952 | } | ||||
1953 | |||||
1954 | llvm::Optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq; | ||||
1955 | const auto &RetReq = Req->getReturnTypeRequirement(); | ||||
1956 | if (RetReq.isEmpty()) | ||||
1957 | TransRetReq.emplace(); | ||||
1958 | else if (RetReq.isSubstitutionFailure()) | ||||
1959 | TransRetReq.emplace(RetReq.getSubstitutionDiagnostic()); | ||||
1960 | else if (RetReq.isTypeConstraint()) { | ||||
1961 | TemplateParameterList *OrigTPL = | ||||
1962 | RetReq.getTypeConstraintTemplateParameterList(); | ||||
1963 | TemplateDeductionInfo Info(OrigTPL->getTemplateLoc()); | ||||
1964 | Sema::InstantiatingTemplate TPLInst(SemaRef, OrigTPL->getTemplateLoc(), | ||||
1965 | Req, Info, OrigTPL->getSourceRange()); | ||||
1966 | if (TPLInst.isInvalid()) | ||||
1967 | return nullptr; | ||||
1968 | TemplateParameterList *TPL = | ||||
1969 | TransformTemplateParameterList(OrigTPL); | ||||
1970 | if (!TPL) | ||||
1971 | TransRetReq.emplace(createSubstDiag(SemaRef, Info, | ||||
1972 | [&] (llvm::raw_ostream& OS) { | ||||
1973 | RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint() | ||||
1974 | ->printPretty(OS, nullptr, SemaRef.getPrintingPolicy()); | ||||
1975 | })); | ||||
1976 | else { | ||||
1977 | TPLInst.Clear(); | ||||
1978 | TransRetReq.emplace(TPL); | ||||
1979 | } | ||||
1980 | } | ||||
1981 | assert(TransRetReq.hasValue() &&(static_cast <bool> (TransRetReq.hasValue() && "All code paths leading here must set TransRetReq" ) ? void (0) : __assert_fail ("TransRetReq.hasValue() && \"All code paths leading here must set TransRetReq\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1982, __extension__ __PRETTY_FUNCTION__)) | ||||
1982 | "All code paths leading here must set TransRetReq")(static_cast <bool> (TransRetReq.hasValue() && "All code paths leading here must set TransRetReq" ) ? void (0) : __assert_fail ("TransRetReq.hasValue() && \"All code paths leading here must set TransRetReq\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 1982, __extension__ __PRETTY_FUNCTION__)); | ||||
1983 | if (Expr *E = TransExpr.dyn_cast<Expr *>()) | ||||
1984 | return RebuildExprRequirement(E, Req->isSimple(), Req->getNoexceptLoc(), | ||||
1985 | std::move(*TransRetReq)); | ||||
1986 | return RebuildExprRequirement( | ||||
1987 | TransExpr.get<concepts::Requirement::SubstitutionDiagnostic *>(), | ||||
1988 | Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq)); | ||||
1989 | } | ||||
1990 | |||||
1991 | concepts::NestedRequirement * | ||||
1992 | TemplateInstantiator::TransformNestedRequirement( | ||||
1993 | concepts::NestedRequirement *Req) { | ||||
1994 | if (!Req->isDependent() && !AlwaysRebuild()) | ||||
1995 | return Req; | ||||
1996 | if (Req->isSubstitutionFailure()) { | ||||
1997 | if (AlwaysRebuild()) | ||||
1998 | return RebuildNestedRequirement( | ||||
1999 | Req->getSubstitutionDiagnostic()); | ||||
2000 | return Req; | ||||
2001 | } | ||||
2002 | Sema::InstantiatingTemplate ReqInst(SemaRef, | ||||
2003 | Req->getConstraintExpr()->getBeginLoc(), Req, | ||||
2004 | Sema::InstantiatingTemplate::ConstraintsCheck{}, | ||||
2005 | Req->getConstraintExpr()->getSourceRange()); | ||||
2006 | |||||
2007 | ExprResult TransConstraint; | ||||
2008 | TemplateDeductionInfo Info(Req->getConstraintExpr()->getBeginLoc()); | ||||
2009 | { | ||||
2010 | EnterExpressionEvaluationContext ContextRAII( | ||||
2011 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); | ||||
2012 | Sema::SFINAETrap Trap(SemaRef); | ||||
2013 | Sema::InstantiatingTemplate ConstrInst(SemaRef, | ||||
2014 | Req->getConstraintExpr()->getBeginLoc(), Req, Info, | ||||
2015 | Req->getConstraintExpr()->getSourceRange()); | ||||
2016 | if (ConstrInst.isInvalid()) | ||||
2017 | return nullptr; | ||||
2018 | TransConstraint = TransformExpr(Req->getConstraintExpr()); | ||||
2019 | if (TransConstraint.isInvalid() || Trap.hasErrorOccurred()) | ||||
2020 | return RebuildNestedRequirement(createSubstDiag(SemaRef, Info, | ||||
2021 | [&] (llvm::raw_ostream& OS) { | ||||
2022 | Req->getConstraintExpr()->printPretty(OS, nullptr, | ||||
2023 | SemaRef.getPrintingPolicy()); | ||||
2024 | })); | ||||
2025 | } | ||||
2026 | return RebuildNestedRequirement(TransConstraint.get()); | ||||
2027 | } | ||||
2028 | |||||
2029 | |||||
2030 | /// Perform substitution on the type T with a given set of template | ||||
2031 | /// arguments. | ||||
2032 | /// | ||||
2033 | /// This routine substitutes the given template arguments into the | ||||
2034 | /// type T and produces the instantiated type. | ||||
2035 | /// | ||||
2036 | /// \param T the type into which the template arguments will be | ||||
2037 | /// substituted. If this type is not dependent, it will be returned | ||||
2038 | /// immediately. | ||||
2039 | /// | ||||
2040 | /// \param Args the template arguments that will be | ||||
2041 | /// substituted for the top-level template parameters within T. | ||||
2042 | /// | ||||
2043 | /// \param Loc the location in the source code where this substitution | ||||
2044 | /// is being performed. It will typically be the location of the | ||||
2045 | /// declarator (if we're instantiating the type of some declaration) | ||||
2046 | /// or the location of the type in the source code (if, e.g., we're | ||||
2047 | /// instantiating the type of a cast expression). | ||||
2048 | /// | ||||
2049 | /// \param Entity the name of the entity associated with a declaration | ||||
2050 | /// being instantiated (if any). May be empty to indicate that there | ||||
2051 | /// is no such entity (if, e.g., this is a type that occurs as part of | ||||
2052 | /// a cast expression) or that the entity has no name (e.g., an | ||||
2053 | /// unnamed function parameter). | ||||
2054 | /// | ||||
2055 | /// \param AllowDeducedTST Whether a DeducedTemplateSpecializationType is | ||||
2056 | /// acceptable as the top level type of the result. | ||||
2057 | /// | ||||
2058 | /// \returns If the instantiation succeeds, the instantiated | ||||
2059 | /// type. Otherwise, produces diagnostics and returns a NULL type. | ||||
2060 | TypeSourceInfo *Sema::SubstType(TypeSourceInfo *T, | ||||
2061 | const MultiLevelTemplateArgumentList &Args, | ||||
2062 | SourceLocation Loc, | ||||
2063 | DeclarationName Entity, | ||||
2064 | bool AllowDeducedTST) { | ||||
2065 | assert(!CodeSynthesisContexts.empty() &&(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2067, __extension__ __PRETTY_FUNCTION__)) | ||||
2066 | "Cannot perform an instantiation without some context on the "(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2067, __extension__ __PRETTY_FUNCTION__)) | ||||
2067 | "instantiation stack")(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2067, __extension__ __PRETTY_FUNCTION__)); | ||||
2068 | |||||
2069 | if (!T->getType()->isInstantiationDependentType() && | ||||
2070 | !T->getType()->isVariablyModifiedType()) | ||||
2071 | return T; | ||||
2072 | |||||
2073 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | ||||
2074 | return AllowDeducedTST ? Instantiator.TransformTypeWithDeducedTST(T) | ||||
2075 | : Instantiator.TransformType(T); | ||||
2076 | } | ||||
2077 | |||||
2078 | TypeSourceInfo *Sema::SubstType(TypeLoc TL, | ||||
2079 | const MultiLevelTemplateArgumentList &Args, | ||||
2080 | SourceLocation Loc, | ||||
2081 | DeclarationName Entity) { | ||||
2082 | assert(!CodeSynthesisContexts.empty() &&(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2084, __extension__ __PRETTY_FUNCTION__)) | ||||
2083 | "Cannot perform an instantiation without some context on the "(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2084, __extension__ __PRETTY_FUNCTION__)) | ||||
2084 | "instantiation stack")(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2084, __extension__ __PRETTY_FUNCTION__)); | ||||
2085 | |||||
2086 | if (TL.getType().isNull()) | ||||
2087 | return nullptr; | ||||
2088 | |||||
2089 | if (!TL.getType()->isInstantiationDependentType() && | ||||
2090 | !TL.getType()->isVariablyModifiedType()) { | ||||
2091 | // FIXME: Make a copy of the TypeLoc data here, so that we can | ||||
2092 | // return a new TypeSourceInfo. Inefficient! | ||||
2093 | TypeLocBuilder TLB; | ||||
2094 | TLB.pushFullCopy(TL); | ||||
2095 | return TLB.getTypeSourceInfo(Context, TL.getType()); | ||||
2096 | } | ||||
2097 | |||||
2098 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | ||||
2099 | TypeLocBuilder TLB; | ||||
2100 | TLB.reserve(TL.getFullDataSize()); | ||||
2101 | QualType Result = Instantiator.TransformType(TLB, TL); | ||||
2102 | if (Result.isNull()) | ||||
2103 | return nullptr; | ||||
2104 | |||||
2105 | return TLB.getTypeSourceInfo(Context, Result); | ||||
2106 | } | ||||
2107 | |||||
2108 | /// Deprecated form of the above. | ||||
2109 | QualType Sema::SubstType(QualType T, | ||||
2110 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||
2111 | SourceLocation Loc, DeclarationName Entity) { | ||||
2112 | assert(!CodeSynthesisContexts.empty() &&(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2114, __extension__ __PRETTY_FUNCTION__)) | ||||
2113 | "Cannot perform an instantiation without some context on the "(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2114, __extension__ __PRETTY_FUNCTION__)) | ||||
2114 | "instantiation stack")(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2114, __extension__ __PRETTY_FUNCTION__)); | ||||
2115 | |||||
2116 | // If T is not a dependent type or a variably-modified type, there | ||||
2117 | // is nothing to do. | ||||
2118 | if (!T->isInstantiationDependentType() && !T->isVariablyModifiedType()) | ||||
2119 | return T; | ||||
2120 | |||||
2121 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity); | ||||
2122 | return Instantiator.TransformType(T); | ||||
2123 | } | ||||
2124 | |||||
2125 | static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) { | ||||
2126 | if (T->getType()->isInstantiationDependentType() || | ||||
2127 | T->getType()->isVariablyModifiedType()) | ||||
2128 | return true; | ||||
2129 | |||||
2130 | TypeLoc TL = T->getTypeLoc().IgnoreParens(); | ||||
2131 | if (!TL.getAs<FunctionProtoTypeLoc>()) | ||||
2132 | return false; | ||||
2133 | |||||
2134 | FunctionProtoTypeLoc FP = TL.castAs<FunctionProtoTypeLoc>(); | ||||
2135 | for (ParmVarDecl *P : FP.getParams()) { | ||||
2136 | // This must be synthesized from a typedef. | ||||
2137 | if (!P) continue; | ||||
2138 | |||||
2139 | // If there are any parameters, a new TypeSourceInfo that refers to the | ||||
2140 | // instantiated parameters must be built. | ||||
2141 | return true; | ||||
2142 | } | ||||
2143 | |||||
2144 | return false; | ||||
2145 | } | ||||
2146 | |||||
2147 | /// A form of SubstType intended specifically for instantiating the | ||||
2148 | /// type of a FunctionDecl. Its purpose is solely to force the | ||||
2149 | /// instantiation of default-argument expressions and to avoid | ||||
2150 | /// instantiating an exception-specification. | ||||
2151 | TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T, | ||||
2152 | const MultiLevelTemplateArgumentList &Args, | ||||
2153 | SourceLocation Loc, | ||||
2154 | DeclarationName Entity, | ||||
2155 | CXXRecordDecl *ThisContext, | ||||
2156 | Qualifiers ThisTypeQuals) { | ||||
2157 | assert(!CodeSynthesisContexts.empty() &&(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2159, __extension__ __PRETTY_FUNCTION__)) | ||||
2158 | "Cannot perform an instantiation without some context on the "(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2159, __extension__ __PRETTY_FUNCTION__)) | ||||
2159 | "instantiation stack")(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2159, __extension__ __PRETTY_FUNCTION__)); | ||||
2160 | |||||
2161 | if (!NeedsInstantiationAsFunctionType(T)) | ||||
2162 | return T; | ||||
2163 | |||||
2164 | TemplateInstantiator Instantiator(*this, Args, Loc, Entity); | ||||
2165 | |||||
2166 | TypeLocBuilder TLB; | ||||
2167 | |||||
2168 | TypeLoc TL = T->getTypeLoc(); | ||||
2169 | TLB.reserve(TL.getFullDataSize()); | ||||
2170 | |||||
2171 | QualType Result; | ||||
2172 | |||||
2173 | if (FunctionProtoTypeLoc Proto = | ||||
2174 | TL.IgnoreParens().getAs<FunctionProtoTypeLoc>()) { | ||||
2175 | // Instantiate the type, other than its exception specification. The | ||||
2176 | // exception specification is instantiated in InitFunctionInstantiation | ||||
2177 | // once we've built the FunctionDecl. | ||||
2178 | // FIXME: Set the exception specification to EST_Uninstantiated here, | ||||
2179 | // instead of rebuilding the function type again later. | ||||
2180 | Result = Instantiator.TransformFunctionProtoType( | ||||
2181 | TLB, Proto, ThisContext, ThisTypeQuals, | ||||
2182 | [](FunctionProtoType::ExceptionSpecInfo &ESI, | ||||
2183 | bool &Changed) { return false; }); | ||||
2184 | } else { | ||||
2185 | Result = Instantiator.TransformType(TLB, TL); | ||||
2186 | } | ||||
2187 | if (Result.isNull()) | ||||
2188 | return nullptr; | ||||
2189 | |||||
2190 | return TLB.getTypeSourceInfo(Context, Result); | ||||
2191 | } | ||||
2192 | |||||
2193 | bool Sema::SubstExceptionSpec(SourceLocation Loc, | ||||
2194 | FunctionProtoType::ExceptionSpecInfo &ESI, | ||||
2195 | SmallVectorImpl<QualType> &ExceptionStorage, | ||||
2196 | const MultiLevelTemplateArgumentList &Args) { | ||||
2197 | assert(ESI.Type != EST_Uninstantiated)(static_cast <bool> (ESI.Type != EST_Uninstantiated) ? void (0) : __assert_fail ("ESI.Type != EST_Uninstantiated", "clang/lib/Sema/SemaTemplateInstantiate.cpp" , 2197, __extension__ __PRETTY_FUNCTION__)); | ||||
2198 | |||||
2199 | bool Changed = false; | ||||
2200 | TemplateInstantiator Instantiator(*this, Args, Loc, DeclarationName()); | ||||
2201 | return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage, | ||||
2202 | Changed); | ||||
2203 | } | ||||
2204 | |||||
2205 | void Sema::SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, | ||||
2206 | const MultiLevelTemplateArgumentList &Args) { | ||||
2207 | FunctionProtoType::ExceptionSpecInfo ESI = | ||||
2208 | Proto->getExtProtoInfo().ExceptionSpec; | ||||
2209 | |||||
2210 | SmallVector<QualType, 4> ExceptionStorage; | ||||
2211 | if (SubstExceptionSpec(New->getTypeSourceInfo()->getTypeLoc().getEndLoc(), | ||||
2212 | ESI, ExceptionStorage, Args)) | ||||
2213 | // On error, recover by dropping the exception specification. | ||||
2214 | ESI.Type = EST_None; | ||||
2215 | |||||
2216 | UpdateExceptionSpec(New, ESI); | ||||
2217 | } | ||||
2218 | |||||
2219 | namespace { | ||||
2220 | |||||
2221 | struct GetContainedInventedTypeParmVisitor : | ||||
2222 | public TypeVisitor<GetContainedInventedTypeParmVisitor, | ||||
2223 | TemplateTypeParmDecl *> { | ||||
2224 | using TypeVisitor<GetContainedInventedTypeParmVisitor, | ||||
2225 | TemplateTypeParmDecl *>::Visit; | ||||
2226 | |||||
2227 | TemplateTypeParmDecl *Visit(QualType T) { | ||||
2228 | if (T.isNull()) | ||||
2229 | return nullptr; | ||||
2230 | return Visit(T.getTypePtr()); | ||||
2231 | } | ||||
2232 | // The deduced type itself. | ||||
2233 | TemplateTypeParmDecl *VisitTemplateTypeParmType( | ||||
2234 | const TemplateTypeParmType *T) { | ||||
2235 | if (!T->getDecl() || !T->getDecl()->isImplicit()) | ||||
2236 | return nullptr; | ||||
2237 | return T->getDecl(); | ||||
2238 | } | ||||
2239 | |||||
2240 | // Only these types can contain 'auto' types, and subsequently be replaced | ||||
2241 | // by references to invented parameters. | ||||
2242 | |||||
2243 | TemplateTypeParmDecl *VisitElaboratedType(const ElaboratedType *T) { | ||||
2244 | return Visit(T->getNamedType()); | ||||
2245 | } | ||||
2246 | |||||
2247 | TemplateTypeParmDecl *VisitPointerType(const PointerType *T) { | ||||
2248 | return Visit(T->getPointeeType()); | ||||
2249 | } | ||||
2250 | |||||
2251 | TemplateTypeParmDecl *VisitBlockPointerType(const BlockPointerType *T) { | ||||
2252 | return Visit(T->getPointeeType()); | ||||
2253 | } | ||||
2254 | |||||
2255 | TemplateTypeParmDecl *VisitReferenceType(const ReferenceType *T) { | ||||
2256 | return Visit(T->getPointeeTypeAsWritten()); | ||||
2257 | } | ||||
2258 | |||||
2259 | TemplateTypeParmDecl *VisitMemberPointerType(const MemberPointerType *T) { | ||||
2260 | return Visit(T->getPointeeType()); | ||||
2261 | } | ||||
2262 | |||||
2263 | TemplateTypeParmDecl *VisitArrayType(const ArrayType *T) { | ||||
2264 | return Visit(T->getElementType()); | ||||
2265 | } | ||||
2266 | |||||
2267 | TemplateTypeParmDecl *VisitDependentSizedExtVectorType( | ||||
2268 | const DependentSizedExtVectorType *T) { | ||||
2269 | return Visit(T->getElementType()); | ||||
2270 | } | ||||
2271 | |||||
2272 | TemplateTypeParmDecl *VisitVectorType(const VectorType *T) { | ||||
2273 | return Visit(T->getElementType()); | ||||
2274 | } | ||||
2275 | |||||
2276 | TemplateTypeParmDecl *VisitFunctionProtoType(const FunctionProtoType *T) { | ||||
2277 | return VisitFunctionType(T); | ||||
2278 | } | ||||
2279 | |||||
2280 | TemplateTypeParmDecl *VisitFunctionType(const FunctionType *T) { | ||||
2281 | return Visit(T->getReturnType()); | ||||
2282 | } | ||||
2283 | |||||
2284 | TemplateTypeParmDecl *VisitParenType(const ParenType *T) { | ||||
2285 | return Visit(T->getInnerType()); | ||||
2286 | } | ||||
2287 | |||||
2288 | TemplateTypeParmDecl *VisitAttributedType(const AttributedType *T) { | ||||
2289 | return Visit(T->getModifiedType()); | ||||
2290 | } | ||||
2291 | |||||
2292 | TemplateTypeParmDecl *VisitMacroQualifiedType(const MacroQualifiedType *T) { | ||||
2293 | return Visit(T->getUnderlyingType()); | ||||
2294 | } | ||||
2295 | |||||
2296 | TemplateTypeParmDecl *VisitAdjustedType(const AdjustedType *T) { | ||||
2297 | return Visit(T->getOriginalType()); | ||||
2298 | } | ||||
2299 | |||||
2300 | TemplateTypeParmDecl *VisitPackExpansionType(const PackExpansionType *T) { | ||||
2301 | return Visit(T->getPattern()); | ||||
2302 | } | ||||
2303 | }; | ||||
2304 | |||||
2305 | } // namespace | ||||
2306 | |||||
2307 | bool Sema::SubstTypeConstraint( | ||||
2308 | TemplateTypeParmDecl *Inst, const TypeConstraint *TC, | ||||
2309 | const MultiLevelTemplateArgumentList &TemplateArgs) { | ||||
2310 | const ASTTemplateArgumentListInfo *TemplArgInfo = | ||||
2311 | TC->getTemplateArgsAsWritten(); | ||||
2312 | TemplateArgumentListInfo InstArgs; | ||||
2313 | |||||
2314 | if (TemplArgInfo) { | ||||
2315 | InstArgs.setLAngleLoc(TemplArgInfo->LAngleLoc); | ||||
2316 | InstArgs.setRAngleLoc(TemplArgInfo->RAngleLoc); | ||||
2317 | if (SubstTemplateArguments(TemplArgInfo->arguments(), TemplateArgs, | ||||
2318 | InstArgs)) | ||||
2319 | return true; | ||||
2320 | } | ||||
2321 | return AttachTypeConstraint( | ||||
2322 | TC->getNestedNameSpecifierLoc(), TC->getConceptNameInfo(), | ||||
2323 | TC->getNamedConcept(), &InstArgs, Inst, | ||||
2324 | Inst->isParameterPack() | ||||
2325 | ? cast<CXXFoldExpr>(TC->getImmediatelyDeclaredConstraint()) | ||||
2326 | ->getEllipsisLoc() | ||||
2327 | : SourceLocation()); | ||||
2328 | } | ||||
2329 | |||||
2330 | ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm, | ||||
2331 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||
2332 | int indexAdjustment, | ||||
2333 | Optional<unsigned> NumExpansions, | ||||
2334 | bool ExpectParameterPack) { | ||||
2335 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); | ||||
2336 | TypeSourceInfo *NewDI = nullptr; | ||||
2337 | |||||
2338 | TypeLoc OldTL = OldDI->getTypeLoc(); | ||||
2339 | if (PackExpansionTypeLoc ExpansionTL = OldTL.getAs<PackExpansionTypeLoc>()) { | ||||
2340 | |||||
2341 | // We have a function parameter pack. Substitute into the pattern of the | ||||
2342 | // expansion. | ||||
2343 | NewDI = SubstType(ExpansionTL.getPatternLoc(), TemplateArgs, | ||||
2344 | OldParm->getLocation(), OldParm->getDeclName()); | ||||
2345 | if (!NewDI) | ||||
2346 | return nullptr; | ||||
2347 | |||||
2348 | if (NewDI->getType()->containsUnexpandedParameterPack()) { | ||||
2349 | // We still have unexpanded parameter packs, which means that | ||||
2350 | // our function parameter is still a function parameter pack. | ||||
2351 | // Therefore, make its type a pack expansion type. | ||||
2352 | NewDI = CheckPackExpansion(NewDI, ExpansionTL.getEllipsisLoc(), | ||||
2353 | NumExpansions); | ||||
2354 | } else if (ExpectParameterPack) { | ||||
2355 | // We expected to get a parameter pack but didn't (because the type | ||||
2356 | // itself is not a pack expansion type), so complain. This can occur when | ||||
2357 | // the substitution goes through an alias template that "loses" the | ||||
2358 | // pack expansion. | ||||
2359 | Diag(OldParm->getLocation(), | ||||
2360 | diag::err_function_parameter_pack_without_parameter_packs) | ||||
2361 | << NewDI->getType(); | ||||
2362 | return nullptr; | ||||
2363 | } | ||||
2364 | } else { | ||||
2365 | NewDI = SubstType(OldDI, TemplateArgs, OldParm->getLocation(), | ||||
2366 | OldParm->getDeclName()); | ||||
2367 | } | ||||
2368 | |||||
2369 | if (!NewDI) | ||||
2370 | return nullptr; | ||||
2371 | |||||
2372 | if (NewDI->getType()->isVoidType()) { | ||||
2373 | Diag(OldParm->getLocation(), diag::err_param_with_void_type); | ||||
2374 | return nullptr; | ||||
2375 | } | ||||
2376 | |||||
2377 | // In abbreviated templates, TemplateTypeParmDecls with possible | ||||
2378 | // TypeConstraints are created when the parameter list is originally parsed. | ||||
2379 | // The TypeConstraints can therefore reference other functions parameters in | ||||
2380 | // the abbreviated function template, which is why we must instantiate them | ||||
2381 | // here, when the instantiated versions of those referenced parameters are in | ||||
2382 | // scope. | ||||
2383 | if (TemplateTypeParmDecl *TTP = | ||||
2384 | GetContainedInventedTypeParmVisitor().Visit(OldDI->getType())) { | ||||
2385 | if (const TypeConstraint *TC = TTP->getTypeConstraint()) { | ||||
2386 | auto *Inst = cast_or_null<TemplateTypeParmDecl>( | ||||
2387 | FindInstantiatedDecl(TTP->getLocation(), TTP, TemplateArgs)); | ||||
2388 | // We will first get here when instantiating the abbreviated function | ||||
2389 | // template's described function, but we might also get here later. | ||||
2390 | // Make sure we do not instantiate the TypeConstraint more than once. | ||||
2391 | if (Inst && !Inst->getTypeConstraint()) { | ||||
2392 | // TODO: Concepts: do not instantiate the constraint (delayed constraint | ||||
2393 | // substitution) | ||||
2394 | if (SubstTypeConstraint(Inst, TC, TemplateArgs)) | ||||
2395 | return nullptr; | ||||
2396 | } | ||||
2397 | } | ||||
2398 | } | ||||
2399 | |||||
2400 | ParmVarDecl *NewParm = CheckParameter(Context.getTranslationUnitDecl(), | ||||
2401 | OldParm->getInnerLocStart(), | ||||
2402 | OldParm->getLocation(), | ||||
2403 | OldParm->getIdentifier(), | ||||
2404 | NewDI->getType(), NewDI, | ||||
2405 | OldParm->getStorageClass()); | ||||
2406 | if (!NewParm) | ||||
2407 | return nullptr; | ||||
2408 | |||||
2409 | // Mark the (new) default argument as uninstantiated (if any). | ||||
2410 | if (OldParm->hasUninstantiatedDefaultArg()) { | ||||
2411 | Expr *Arg = OldParm->getUninstantiatedDefaultArg(); | ||||
2412 | NewParm->setUninstantiatedDefaultArg(Arg); | ||||
2413 | } else if (OldParm->hasUnparsedDefaultArg()) { | ||||
2414 | NewParm->setUnparsedDefaultArg(); | ||||
2415 | UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm); | ||||
2416 | } else if (Expr *Arg = OldParm->getDefaultArg()) { | ||||
2417 | FunctionDecl *OwningFunc = cast<FunctionDecl>(OldParm->getDeclContext()); | ||||
2418 | if (OwningFunc->isInLocalScopeForInstantiation()) { | ||||
2419 | // Instantiate default arguments for methods of local classes (DR1484) | ||||
2420 | // and non-defining declarations. | ||||
2421 | Sema::ContextRAII SavedContext(*this, OwningFunc); | ||||
2422 | LocalInstantiationScope Local(*this, true); | ||||
2423 | ExprResult NewArg = SubstExpr(Arg, TemplateArgs); | ||||
2424 | if (NewArg.isUsable()) { | ||||
2425 | // It would be nice if we still had this. | ||||
2426 | SourceLocation EqualLoc = NewArg.get()->getBeginLoc(); | ||||
2427 | ExprResult Result = | ||||
2428 | ConvertParamDefaultArgument(NewParm, NewArg.get(), EqualLoc); | ||||
2429 | if (Result.isInvalid()) | ||||
2430 | return nullptr; | ||||
2431 | |||||
2432 | SetParamDefaultArgument(NewParm, Result.getAs<Expr>(), EqualLoc); | ||||
2433 | } | ||||
2434 | } else { | ||||
2435 | // FIXME: if we non-lazily instantiated non-dependent default args for | ||||
2436 | // non-dependent parameter types we could remove a bunch of duplicate | ||||
2437 | // conversion warnings for such arguments. | ||||
2438 | NewParm->setUninstantiatedDefaultArg(Arg); | ||||
2439 | } | ||||
2440 | } | ||||
2441 | |||||
2442 | NewParm->setHasInheritedDefaultArg(OldParm->hasInheritedDefaultArg()); | ||||
2443 | |||||
2444 | if (OldParm->isParameterPack() && !NewParm->isParameterPack()) { | ||||
2445 | // Add the new parameter to the instantiated parameter pack. | ||||
2446 | CurrentInstantiationScope->InstantiatedLocalPackArg(OldParm, NewParm); | ||||
2447 | } else { | ||||
2448 | // Introduce an Old -> New mapping | ||||
2449 | CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm); | ||||
2450 | } | ||||
2451 | |||||
2452 | // FIXME: OldParm may come from a FunctionProtoType, in which case CurContext | ||||
2453 | // can be anything, is this right ? | ||||
2454 | NewParm->setDeclContext(CurContext); | ||||
2455 | |||||
2456 | NewParm->setScopeInfo(OldParm->getFunctionScopeDepth(), | ||||
2457 | OldParm->getFunctionScopeIndex() + indexAdjustment); | ||||
2458 | |||||
2459 | InstantiateAttrs(TemplateArgs, OldParm, NewParm); | ||||
2460 | |||||
2461 | return NewParm; | ||||
2462 | } | ||||
2463 | |||||
2464 | /// Substitute the given template arguments into the given set of | ||||
2465 | /// parameters, producing the set of parameter types that would be generated | ||||
2466 | /// from such a substitution. | ||||
2467 | bool Sema::SubstParmTypes( | ||||
2468 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, | ||||
2469 | const FunctionProtoType::ExtParameterInfo *ExtParamInfos, | ||||
2470 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||
2471 | SmallVectorImpl<QualType> &ParamTypes, | ||||
2472 | SmallVectorImpl<ParmVarDecl *> *OutParams, | ||||
2473 | ExtParameterInfoBuilder &ParamInfos) { | ||||
2474 | assert(!CodeSynthesisContexts.empty() &&(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2476, __extension__ __PRETTY_FUNCTION__)) | ||||
2475 | "Cannot perform an instantiation without some context on the "(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2476, __extension__ __PRETTY_FUNCTION__)) | ||||
2476 | "instantiation stack")(static_cast <bool> (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack") ? void (0) : __assert_fail ("!CodeSynthesisContexts.empty() && \"Cannot perform an instantiation without some context on the \" \"instantiation stack\"" , "clang/lib/Sema/SemaTemplateInstantiate.cpp", 2476, __extension__ __PRETTY_FUNCTION__)); | ||||
2477 | |||||
2478 | TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, | ||||
2479 | DeclarationName()); | ||||
2480 | return Instantiator.TransformFunctionTypeParams( | ||||
2481 | Loc, Params, nullptr, ExtParamInfos, ParamTypes, OutParams, ParamInfos); | ||||
2482 | } | ||||
2483 | |||||
2484 | /// Perform substitution on the base class specifiers of the | ||||
2485 | /// given class template specialization. | ||||
2486 | /// | ||||
2487 | /// Produces a diagnostic and returns true on error, returns false and | ||||
2488 | /// attaches the instantiated base classes to the class template | ||||
2489 | /// specialization if successful. | ||||
2490 | bool | ||||
2491 | Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, | ||||
2492 | CXXRecordDecl *Pattern, | ||||
2493 | const MultiLevelTemplateArgumentList &TemplateArgs) { | ||||
2494 | bool Invalid = false; | ||||
2495 | SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases; | ||||
2496 | for (const auto &Base : Pattern->bases()) { | ||||
2497 | if (!Base.getType()->isDependentType()) { | ||||
2498 | if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl()) { | ||||
2499 | if (RD->isInvalidDecl()) | ||||
2500 | Instantiation->setInvalidDecl(); | ||||
2501 | } | ||||
2502 | InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(Base)); | ||||
2503 | continue; | ||||
2504 | } | ||||
2505 | |||||
2506 | SourceLocation EllipsisLoc; | ||||
2507 | TypeSourceInfo *BaseTypeLoc; | ||||
2508 | if (Base.isPackExpansion()) { | ||||
2509 | // This is a pack expansion. See whether we should expand it now, or | ||||
2510 | // wait until later. | ||||
2511 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; | ||||
2512 | collectUnexpandedParameterPacks(Base.getTypeSourceInfo()->getTypeLoc(), | ||||
2513 | Unexpanded); | ||||
2514 | bool ShouldExpand = false; | ||||
2515 | bool RetainExpansion = false; | ||||
2516 | Optional<unsigned> NumExpansions; | ||||
2517 | if (CheckParameterPacksForExpansion(Base.getEllipsisLoc(), | ||||
2518 | Base.getSourceRange(), | ||||
2519 | Unexpanded, | ||||
2520 | TemplateArgs, ShouldExpand, | ||||
2521 | RetainExpansion, | ||||
2522 | NumExpansions)) { | ||||
2523 | Invalid = true; | ||||
2524 | continue; | ||||
2525 | } | ||||
2526 | |||||
2527 | // If we should expand this pack expansion now, do so. | ||||
2528 | if (ShouldExpand) { | ||||
2529 | for (unsigned I = 0; I != *NumExpansions; ++I) { | ||||
2530 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I); | ||||
2531 | |||||
2532 | TypeSourceInfo *BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | ||||
2533 | TemplateArgs, | ||||
2534 | Base.getSourceRange().getBegin(), | ||||
2535 | DeclarationName()); | ||||
2536 | if (!BaseTypeLoc) { | ||||
2537 | Invalid = true; | ||||
2538 | continue; | ||||
2539 | } | ||||
2540 | |||||
2541 | if (CXXBaseSpecifier *InstantiatedBase | ||||
2542 | = CheckBaseSpecifier(Instantiation, | ||||
2543 | Base.getSourceRange(), | ||||
2544 | Base.isVirtual(), | ||||
2545 | Base.getAccessSpecifierAsWritten(), | ||||
2546 | BaseTypeLoc, | ||||
2547 | SourceLocation())) | ||||
2548 | InstantiatedBases.push_back(InstantiatedBase); | ||||
2549 | else | ||||
2550 | Invalid = true; | ||||
2551 | } | ||||
2552 | |||||
2553 | continue; | ||||
2554 | } | ||||
2555 | |||||
2556 | // The resulting base specifier will (still) be a pack expansion. | ||||
2557 | EllipsisLoc = Base.getEllipsisLoc(); | ||||
2558 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1); | ||||
2559 | BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | ||||
2560 | TemplateArgs, | ||||
2561 | Base.getSourceRange().getBegin(), | ||||
2562 | DeclarationName()); | ||||
2563 | } else { | ||||
2564 | BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), | ||||
2565 | TemplateArgs, | ||||
2566 | Base.getSourceRange().getBegin(), | ||||
2567 | DeclarationName()); | ||||
2568 | } | ||||
2569 | |||||
2570 | if (!BaseTypeLoc) { | ||||
2571 | Invalid = true; | ||||
2572 | continue; | ||||
2573 | } | ||||
2574 | |||||
2575 | if (CXXBaseSpecifier *InstantiatedBase | ||||
2576 | = CheckBaseSpecifier(Instantiation, | ||||
2577 | Base.getSourceRange(), | ||||
2578 | Base.isVirtual(), | ||||
2579 | Base.getAccessSpecifierAsWritten(), | ||||
2580 | BaseTypeLoc, | ||||
2581 | EllipsisLoc)) | ||||
2582 | InstantiatedBases.push_back(InstantiatedBase); | ||||
2583 | else | ||||
2584 | Invalid = true; | ||||
2585 | } | ||||
2586 | |||||
2587 | if (!Invalid && AttachBaseSpecifiers(Instantiation, InstantiatedBases)) | ||||
2588 | Invalid = true; | ||||
2589 | |||||
2590 | return Invalid; | ||||
2591 | } | ||||
2592 | |||||
2593 | // Defined via #include from SemaTemplateInstantiateDecl.cpp | ||||
2594 | namespace clang { | ||||
2595 | namespace sema { | ||||
2596 | Attr *instantiateTemplateAttribute(const Attr *At, ASTContext &C, Sema &S, | ||||
2597 | const MultiLevelTemplateArgumentList &TemplateArgs); | ||||
2598 | Attr *instantiateTemplateAttributeForDecl( | ||||
2599 | const Attr *At, ASTContext &C, Sema &S, | ||||
2600 | const MultiLevelTemplateArgumentList &TemplateArgs); | ||||
2601 | } | ||||
2602 | } | ||||
2603 | |||||
2604 | /// Instantiate the definition of a class from a given pattern. | ||||
2605 | /// | ||||
2606 | /// \param PointOfInstantiation The point of instantiation within the | ||||
2607 | /// source code. | ||||
2608 | /// | ||||
2609 | /// \param Instantiation is the declaration whose definition is being | ||||
2610 | /// instantiated. This will be either a class template specialization | ||||
2611 | /// or a member class of a class template specialization. | ||||
2612 | /// | ||||
2613 | /// \param Pattern is the pattern from which the instantiation | ||||
2614 | /// occurs. This will be either the declaration of a class template or | ||||
2615 | /// the declaration of a member class of a class template. | ||||
2616 | /// | ||||
2617 | /// \param TemplateArgs The template arguments to be substituted into | ||||
2618 | /// the pattern. | ||||
2619 | /// | ||||
2620 | /// \param TSK the kind of implicit or explicit instantiation to perform. | ||||
2621 | /// | ||||
2622 | /// \param Complain whether to complain if the class cannot be instantiated due | ||||
2623 | /// to the lack of a definition. | ||||
2624 | /// | ||||
2625 | /// \returns true if an error occurred, false otherwise. | ||||
2626 | bool | ||||
2627 | Sema::InstantiateClass(SourceLocation PointOfInstantiation, | ||||
2628 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, | ||||
2629 | const MultiLevelTemplateArgumentList &TemplateArgs, | ||||
2630 | TemplateSpecializationKind TSK, | ||||
2631 | bool Complain) { | ||||
2632 | CXXRecordDecl *PatternDef | ||||
2633 | = cast_or_null<CXXRecordDecl>(Pattern->getDefinition()); | ||||
2634 | if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Instantiation, | ||||
2635 | Instantiation->getInstantiatedFromMemberClass(), | ||||
2636 | Pattern, PatternDef, TSK, Complain)) | ||||
2637 | return true; | ||||
2638 | |||||
2639 | llvm::TimeTraceScope TimeScope("InstantiateClass", [&]() { | ||||
2640 | std::string Name; | ||||
2641 | llvm::raw_string_ostream OS(Name); | ||||
2642 | Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(), | ||||
2643 | /*Qualified=*/true); | ||||
2644 | return Name; | ||||
2645 | }); | ||||
2646 | |||||
2647 | Pattern = PatternDef; | ||||
2648 | |||||
2649 | // Record the point of instantiation. | ||||
2650 | if (MemberSpecializationInfo *MSInfo | ||||
2651 | = Instantiation->getMemberSpecializationInfo()) { | ||||
2652 | MSInfo->setTemplateSpecializationKind(TSK); | ||||
2653 | MSInfo->setPointOfInstantiation(PointOfInstantiation); | ||||
2654 | } else if (ClassTemplateSpecializationDecl *Spec
|
30.1 | 'Spec' is null |
61 | 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/StmtOpenMP.h" |
36 | #include "clang/AST/TypeLoc.h" |
37 | #include "clang/AST/TypeOrdering.h" |
38 | #include "clang/Basic/BitmaskEnum.h" |
39 | #include "clang/Basic/Builtins.h" |
40 | #include "clang/Basic/DarwinSDKInfo.h" |
41 | #include "clang/Basic/ExpressionTraits.h" |
42 | #include "clang/Basic/Module.h" |
43 | #include "clang/Basic/OpenCLOptions.h" |
44 | #include "clang/Basic/OpenMPKinds.h" |
45 | #include "clang/Basic/PragmaKinds.h" |
46 | #include "clang/Basic/Specifiers.h" |
47 | #include "clang/Basic/TemplateKinds.h" |
48 | #include "clang/Basic/TypeTraits.h" |
49 | #include "clang/Sema/AnalysisBasedWarnings.h" |
50 | #include "clang/Sema/CleanupInfo.h" |
51 | #include "clang/Sema/DeclSpec.h" |
52 | #include "clang/Sema/ExternalSemaSource.h" |
53 | #include "clang/Sema/IdentifierResolver.h" |
54 | #include "clang/Sema/ObjCMethodList.h" |
55 | #include "clang/Sema/Ownership.h" |
56 | #include "clang/Sema/Scope.h" |
57 | #include "clang/Sema/SemaConcept.h" |
58 | #include "clang/Sema/TypoCorrection.h" |
59 | #include "clang/Sema/Weak.h" |
60 | #include "llvm/ADT/ArrayRef.h" |
61 | #include "llvm/ADT/Optional.h" |
62 | #include "llvm/ADT/SetVector.h" |
63 | #include "llvm/ADT/SmallBitVector.h" |
64 | #include "llvm/ADT/SmallPtrSet.h" |
65 | #include "llvm/ADT/SmallSet.h" |
66 | #include "llvm/ADT/SmallVector.h" |
67 | #include "llvm/ADT/TinyPtrVector.h" |
68 | #include "llvm/Frontend/OpenMP/OMPConstants.h" |
69 | #include <deque> |
70 | #include <memory> |
71 | #include <string> |
72 | #include <tuple> |
73 | #include <vector> |
74 | |
75 | namespace llvm { |
76 | class APSInt; |
77 | template <typename ValueT, typename ValueInfoT> class DenseSet; |
78 | class SmallBitVector; |
79 | struct InlineAsmIdentifierInfo; |
80 | } |
81 | |
82 | namespace clang { |
83 | class ADLResult; |
84 | class ASTConsumer; |
85 | class ASTContext; |
86 | class ASTMutationListener; |
87 | class ASTReader; |
88 | class ASTWriter; |
89 | class ArrayType; |
90 | class ParsedAttr; |
91 | class BindingDecl; |
92 | class BlockDecl; |
93 | class CapturedDecl; |
94 | class CXXBasePath; |
95 | class CXXBasePaths; |
96 | class CXXBindTemporaryExpr; |
97 | typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; |
98 | class CXXConstructorDecl; |
99 | class CXXConversionDecl; |
100 | class CXXDeleteExpr; |
101 | class CXXDestructorDecl; |
102 | class CXXFieldCollector; |
103 | class CXXMemberCallExpr; |
104 | class CXXMethodDecl; |
105 | class CXXScopeSpec; |
106 | class CXXTemporary; |
107 | class CXXTryStmt; |
108 | class CallExpr; |
109 | class ClassTemplateDecl; |
110 | class ClassTemplatePartialSpecializationDecl; |
111 | class ClassTemplateSpecializationDecl; |
112 | class VarTemplatePartialSpecializationDecl; |
113 | class CodeCompleteConsumer; |
114 | class CodeCompletionAllocator; |
115 | class CodeCompletionTUInfo; |
116 | class CodeCompletionResult; |
117 | class CoroutineBodyStmt; |
118 | class Decl; |
119 | class DeclAccessPair; |
120 | class DeclContext; |
121 | class DeclRefExpr; |
122 | class DeclaratorDecl; |
123 | class DeducedTemplateArgument; |
124 | class DependentDiagnostic; |
125 | class DesignatedInitExpr; |
126 | class Designation; |
127 | class EnableIfAttr; |
128 | class EnumConstantDecl; |
129 | class Expr; |
130 | class ExtVectorType; |
131 | class FormatAttr; |
132 | class FriendDecl; |
133 | class FunctionDecl; |
134 | class FunctionProtoType; |
135 | class FunctionTemplateDecl; |
136 | class ImplicitConversionSequence; |
137 | typedef MutableArrayRef<ImplicitConversionSequence> ConversionSequenceList; |
138 | class InitListExpr; |
139 | class InitializationKind; |
140 | class InitializationSequence; |
141 | class InitializedEntity; |
142 | class IntegerLiteral; |
143 | class LabelStmt; |
144 | class LambdaExpr; |
145 | class LangOptions; |
146 | class LocalInstantiationScope; |
147 | class LookupResult; |
148 | class MacroInfo; |
149 | typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> ModuleIdPath; |
150 | class ModuleLoader; |
151 | class MultiLevelTemplateArgumentList; |
152 | class NamedDecl; |
153 | class ObjCCategoryDecl; |
154 | class ObjCCategoryImplDecl; |
155 | class ObjCCompatibleAliasDecl; |
156 | class ObjCContainerDecl; |
157 | class ObjCImplDecl; |
158 | class ObjCImplementationDecl; |
159 | class ObjCInterfaceDecl; |
160 | class ObjCIvarDecl; |
161 | template <class T> class ObjCList; |
162 | class ObjCMessageExpr; |
163 | class ObjCMethodDecl; |
164 | class ObjCPropertyDecl; |
165 | class ObjCProtocolDecl; |
166 | class OMPThreadPrivateDecl; |
167 | class OMPRequiresDecl; |
168 | class OMPDeclareReductionDecl; |
169 | class OMPDeclareSimdDecl; |
170 | class OMPClause; |
171 | struct OMPVarListLocTy; |
172 | struct OverloadCandidate; |
173 | enum class OverloadCandidateParamOrder : char; |
174 | enum OverloadCandidateRewriteKind : unsigned; |
175 | class OverloadCandidateSet; |
176 | class OverloadExpr; |
177 | class ParenListExpr; |
178 | class ParmVarDecl; |
179 | class Preprocessor; |
180 | class PseudoDestructorTypeStorage; |
181 | class PseudoObjectExpr; |
182 | class QualType; |
183 | class StandardConversionSequence; |
184 | class Stmt; |
185 | class StringLiteral; |
186 | class SwitchStmt; |
187 | class TemplateArgument; |
188 | class TemplateArgumentList; |
189 | class TemplateArgumentLoc; |
190 | class TemplateDecl; |
191 | class TemplateInstantiationCallback; |
192 | class TemplateParameterList; |
193 | class TemplatePartialOrderingContext; |
194 | class TemplateTemplateParmDecl; |
195 | class Token; |
196 | class TypeAliasDecl; |
197 | class TypedefDecl; |
198 | class TypedefNameDecl; |
199 | class TypeLoc; |
200 | class TypoCorrectionConsumer; |
201 | class UnqualifiedId; |
202 | class UnresolvedLookupExpr; |
203 | class UnresolvedMemberExpr; |
204 | class UnresolvedSetImpl; |
205 | class UnresolvedSetIterator; |
206 | class UsingDecl; |
207 | class UsingShadowDecl; |
208 | class ValueDecl; |
209 | class VarDecl; |
210 | class VarTemplateSpecializationDecl; |
211 | class VisibilityAttr; |
212 | class VisibleDeclConsumer; |
213 | class IndirectFieldDecl; |
214 | struct DeductionFailureInfo; |
215 | class TemplateSpecCandidateSet; |
216 | |
217 | namespace sema { |
218 | class AccessedEntity; |
219 | class BlockScopeInfo; |
220 | class Capture; |
221 | class CapturedRegionScopeInfo; |
222 | class CapturingScopeInfo; |
223 | class CompoundScopeInfo; |
224 | class DelayedDiagnostic; |
225 | class DelayedDiagnosticPool; |
226 | class FunctionScopeInfo; |
227 | class LambdaScopeInfo; |
228 | class PossiblyUnreachableDiag; |
229 | class SemaPPCallbacks; |
230 | class TemplateDeductionInfo; |
231 | } |
232 | |
233 | namespace threadSafety { |
234 | class BeforeSet; |
235 | void threadSafetyCleanup(BeforeSet* Cache); |
236 | } |
237 | |
238 | // FIXME: No way to easily map from TemplateTypeParmTypes to |
239 | // TemplateTypeParmDecls, so we have this horrible PointerUnion. |
240 | typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>, |
241 | SourceLocation> UnexpandedParameterPack; |
242 | |
243 | /// Describes whether we've seen any nullability information for the given |
244 | /// file. |
245 | struct FileNullability { |
246 | /// The first pointer declarator (of any pointer kind) in the file that does |
247 | /// not have a corresponding nullability annotation. |
248 | SourceLocation PointerLoc; |
249 | |
250 | /// The end location for the first pointer declarator in the file. Used for |
251 | /// placing fix-its. |
252 | SourceLocation PointerEndLoc; |
253 | |
254 | /// Which kind of pointer declarator we saw. |
255 | uint8_t PointerKind; |
256 | |
257 | /// Whether we saw any type nullability annotations in the given file. |
258 | bool SawTypeNullability = false; |
259 | }; |
260 | |
261 | /// A mapping from file IDs to a record of whether we've seen nullability |
262 | /// information in that file. |
263 | class FileNullabilityMap { |
264 | /// A mapping from file IDs to the nullability information for each file ID. |
265 | llvm::DenseMap<FileID, FileNullability> Map; |
266 | |
267 | /// A single-element cache based on the file ID. |
268 | struct { |
269 | FileID File; |
270 | FileNullability Nullability; |
271 | } Cache; |
272 | |
273 | public: |
274 | FileNullability &operator[](FileID file) { |
275 | // Check the single-element cache. |
276 | if (file == Cache.File) |
277 | return Cache.Nullability; |
278 | |
279 | // It's not in the single-element cache; flush the cache if we have one. |
280 | if (!Cache.File.isInvalid()) { |
281 | Map[Cache.File] = Cache.Nullability; |
282 | } |
283 | |
284 | // Pull this entry into the cache. |
285 | Cache.File = file; |
286 | Cache.Nullability = Map[file]; |
287 | return Cache.Nullability; |
288 | } |
289 | }; |
290 | |
291 | /// Tracks expected type during expression parsing, for use in code completion. |
292 | /// The type is tied to a particular token, all functions that update or consume |
293 | /// the type take a start location of the token they are looking at as a |
294 | /// parameter. This avoids updating the type on hot paths in the parser. |
295 | class PreferredTypeBuilder { |
296 | public: |
297 | PreferredTypeBuilder(bool Enabled) : Enabled(Enabled) {} |
298 | |
299 | void enterCondition(Sema &S, SourceLocation Tok); |
300 | void enterReturn(Sema &S, SourceLocation Tok); |
301 | void enterVariableInit(SourceLocation Tok, Decl *D); |
302 | /// Handles e.g. BaseType{ .D = Tok... |
303 | void enterDesignatedInitializer(SourceLocation Tok, QualType BaseType, |
304 | const Designation &D); |
305 | /// Computing a type for the function argument may require running |
306 | /// overloading, so we postpone its computation until it is actually needed. |
307 | /// |
308 | /// Clients should be very careful when using this funciton, as it stores a |
309 | /// function_ref, clients should make sure all calls to get() with the same |
310 | /// location happen while function_ref is alive. |
311 | /// |
312 | /// The callback should also emit signature help as a side-effect, but only |
313 | /// if the completion point has been reached. |
314 | void enterFunctionArgument(SourceLocation Tok, |
315 | llvm::function_ref<QualType()> ComputeType); |
316 | |
317 | void enterParenExpr(SourceLocation Tok, SourceLocation LParLoc); |
318 | void enterUnary(Sema &S, SourceLocation Tok, tok::TokenKind OpKind, |
319 | SourceLocation OpLoc); |
320 | void enterBinary(Sema &S, SourceLocation Tok, Expr *LHS, tok::TokenKind Op); |
321 | void enterMemAccess(Sema &S, SourceLocation Tok, Expr *Base); |
322 | void enterSubscript(Sema &S, SourceLocation Tok, Expr *LHS); |
323 | /// Handles all type casts, including C-style cast, C++ casts, etc. |
324 | void enterTypeCast(SourceLocation Tok, QualType CastType); |
325 | |
326 | /// Get the expected type associated with this location, if any. |
327 | /// |
328 | /// If the location is a function argument, determining the expected type |
329 | /// involves considering all function overloads and the arguments so far. |
330 | /// In this case, signature help for these function overloads will be reported |
331 | /// as a side-effect (only if the completion point has been reached). |
332 | QualType get(SourceLocation Tok) const { |
333 | if (!Enabled || Tok != ExpectedLoc) |
334 | return QualType(); |
335 | if (!Type.isNull()) |
336 | return Type; |
337 | if (ComputeType) |
338 | return ComputeType(); |
339 | return QualType(); |
340 | } |
341 | |
342 | private: |
343 | bool Enabled; |
344 | /// Start position of a token for which we store expected type. |
345 | SourceLocation ExpectedLoc; |
346 | /// Expected type for a token starting at ExpectedLoc. |
347 | QualType Type; |
348 | /// A function to compute expected type at ExpectedLoc. It is only considered |
349 | /// if Type is null. |
350 | llvm::function_ref<QualType()> ComputeType; |
351 | }; |
352 | |
353 | /// Sema - This implements semantic analysis and AST building for C. |
354 | class Sema final { |
355 | Sema(const Sema &) = delete; |
356 | void operator=(const Sema &) = delete; |
357 | |
358 | ///Source of additional semantic information. |
359 | ExternalSemaSource *ExternalSource; |
360 | |
361 | ///Whether Sema has generated a multiplexer and has to delete it. |
362 | bool isMultiplexExternalSource; |
363 | |
364 | static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD); |
365 | |
366 | bool isVisibleSlow(const NamedDecl *D); |
367 | |
368 | /// Determine whether two declarations should be linked together, given that |
369 | /// the old declaration might not be visible and the new declaration might |
370 | /// not have external linkage. |
371 | bool shouldLinkPossiblyHiddenDecl(const NamedDecl *Old, |
372 | const NamedDecl *New) { |
373 | if (isVisible(Old)) |
374 | return true; |
375 | // See comment in below overload for why it's safe to compute the linkage |
376 | // of the new declaration here. |
377 | if (New->isExternallyDeclarable()) { |
378 | assert(Old->isExternallyDeclarable() &&(static_cast <bool> (Old->isExternallyDeclarable() && "should not have found a non-externally-declarable previous decl" ) ? void (0) : __assert_fail ("Old->isExternallyDeclarable() && \"should not have found a non-externally-declarable previous decl\"" , "clang/include/clang/Sema/Sema.h", 379, __extension__ __PRETTY_FUNCTION__ )) |
379 | "should not have found a non-externally-declarable previous decl")(static_cast <bool> (Old->isExternallyDeclarable() && "should not have found a non-externally-declarable previous decl" ) ? void (0) : __assert_fail ("Old->isExternallyDeclarable() && \"should not have found a non-externally-declarable previous decl\"" , "clang/include/clang/Sema/Sema.h", 379, __extension__ __PRETTY_FUNCTION__ )); |
380 | return true; |
381 | } |
382 | return false; |
383 | } |
384 | bool shouldLinkPossiblyHiddenDecl(LookupResult &Old, const NamedDecl *New); |
385 | |
386 | void setupImplicitSpecialMemberType(CXXMethodDecl *SpecialMem, |
387 | QualType ResultTy, |
388 | ArrayRef<QualType> Args); |
389 | |
390 | public: |
391 | /// The maximum alignment, same as in llvm::Value. We duplicate them here |
392 | /// because that allows us not to duplicate the constants in clang code, |
393 | /// which we must to since we can't directly use the llvm constants. |
394 | /// The value is verified against llvm here: lib/CodeGen/CGDecl.cpp |
395 | /// |
396 | /// This is the greatest alignment value supported by load, store, and alloca |
397 | /// instructions, and global values. |
398 | static const unsigned MaxAlignmentExponent = 32; |
399 | static const uint64_t MaximumAlignment = 1ull << MaxAlignmentExponent; |
400 | |
401 | typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; |
402 | typedef OpaquePtr<TemplateName> TemplateTy; |
403 | typedef OpaquePtr<QualType> TypeTy; |
404 | |
405 | OpenCLOptions OpenCLFeatures; |
406 | FPOptions CurFPFeatures; |
407 | |
408 | const LangOptions &LangOpts; |
409 | Preprocessor &PP; |
410 | ASTContext &Context; |
411 | ASTConsumer &Consumer; |
412 | DiagnosticsEngine &Diags; |
413 | SourceManager &SourceMgr; |
414 | |
415 | /// Flag indicating whether or not to collect detailed statistics. |
416 | bool CollectStats; |
417 | |
418 | /// Code-completion consumer. |
419 | CodeCompleteConsumer *CodeCompleter; |
420 | |
421 | /// CurContext - This is the current declaration context of parsing. |
422 | DeclContext *CurContext; |
423 | |
424 | /// Generally null except when we temporarily switch decl contexts, |
425 | /// like in \see ActOnObjCTemporaryExitContainerContext. |
426 | DeclContext *OriginalLexicalContext; |
427 | |
428 | /// VAListTagName - The declaration name corresponding to __va_list_tag. |
429 | /// This is used as part of a hack to omit that class from ADL results. |
430 | DeclarationName VAListTagName; |
431 | |
432 | bool MSStructPragmaOn; // True when \#pragma ms_struct on |
433 | |
434 | /// Controls member pointer representation format under the MS ABI. |
435 | LangOptions::PragmaMSPointersToMembersKind |
436 | MSPointerToMemberRepresentationMethod; |
437 | |
438 | /// Stack of active SEH __finally scopes. Can be empty. |
439 | SmallVector<Scope*, 2> CurrentSEHFinally; |
440 | |
441 | /// Source location for newly created implicit MSInheritanceAttrs |
442 | SourceLocation ImplicitMSInheritanceAttrLoc; |
443 | |
444 | /// Holds TypoExprs that are created from `createDelayedTypo`. This is used by |
445 | /// `TransformTypos` in order to keep track of any TypoExprs that are created |
446 | /// recursively during typo correction and wipe them away if the correction |
447 | /// fails. |
448 | llvm::SmallVector<TypoExpr *, 2> TypoExprs; |
449 | |
450 | /// pragma clang section kind |
451 | enum PragmaClangSectionKind { |
452 | PCSK_Invalid = 0, |
453 | PCSK_BSS = 1, |
454 | PCSK_Data = 2, |
455 | PCSK_Rodata = 3, |
456 | PCSK_Text = 4, |
457 | PCSK_Relro = 5 |
458 | }; |
459 | |
460 | enum PragmaClangSectionAction { |
461 | PCSA_Set = 0, |
462 | PCSA_Clear = 1 |
463 | }; |
464 | |
465 | struct PragmaClangSection { |
466 | std::string SectionName; |
467 | bool Valid = false; |
468 | SourceLocation PragmaLocation; |
469 | }; |
470 | |
471 | PragmaClangSection PragmaClangBSSSection; |
472 | PragmaClangSection PragmaClangDataSection; |
473 | PragmaClangSection PragmaClangRodataSection; |
474 | PragmaClangSection PragmaClangRelroSection; |
475 | PragmaClangSection PragmaClangTextSection; |
476 | |
477 | enum PragmaMsStackAction { |
478 | PSK_Reset = 0x0, // #pragma () |
479 | PSK_Set = 0x1, // #pragma (value) |
480 | PSK_Push = 0x2, // #pragma (push[, id]) |
481 | PSK_Pop = 0x4, // #pragma (pop[, id]) |
482 | PSK_Show = 0x8, // #pragma (show) -- only for "pack"! |
483 | PSK_Push_Set = PSK_Push | PSK_Set, // #pragma (push[, id], value) |
484 | PSK_Pop_Set = PSK_Pop | PSK_Set, // #pragma (pop[, id], value) |
485 | }; |
486 | |
487 | // #pragma pack and align. |
488 | class AlignPackInfo { |
489 | public: |
490 | // `Native` represents default align mode, which may vary based on the |
491 | // platform. |
492 | enum Mode : unsigned char { Native, Natural, Packed, Mac68k }; |
493 | |
494 | // #pragma pack info constructor |
495 | AlignPackInfo(AlignPackInfo::Mode M, unsigned Num, bool IsXL) |
496 | : PackAttr(true), AlignMode(M), PackNumber(Num), XLStack(IsXL) { |
497 | assert(Num == PackNumber && "The pack number has been truncated.")(static_cast <bool> (Num == PackNumber && "The pack number has been truncated." ) ? void (0) : __assert_fail ("Num == PackNumber && \"The pack number has been truncated.\"" , "clang/include/clang/Sema/Sema.h", 497, __extension__ __PRETTY_FUNCTION__ )); |
498 | } |
499 | |
500 | // #pragma align info constructor |
501 | AlignPackInfo(AlignPackInfo::Mode M, bool IsXL) |
502 | : PackAttr(false), AlignMode(M), |
503 | PackNumber(M == Packed ? 1 : UninitPackVal), XLStack(IsXL) {} |
504 | |
505 | explicit AlignPackInfo(bool IsXL) : AlignPackInfo(Native, IsXL) {} |
506 | |
507 | AlignPackInfo() : AlignPackInfo(Native, false) {} |
508 | |
509 | // When a AlignPackInfo itself cannot be used, this returns an 32-bit |
510 | // integer encoding for it. This should only be passed to |
511 | // AlignPackInfo::getFromRawEncoding, it should not be inspected directly. |
512 | static uint32_t getRawEncoding(const AlignPackInfo &Info) { |
513 | std::uint32_t Encoding{}; |
514 | if (Info.IsXLStack()) |
515 | Encoding |= IsXLMask; |
516 | |
517 | Encoding |= static_cast<uint32_t>(Info.getAlignMode()) << 1; |
518 | |
519 | if (Info.IsPackAttr()) |
520 | Encoding |= PackAttrMask; |
521 | |
522 | Encoding |= static_cast<uint32_t>(Info.getPackNumber()) << 4; |
523 | |
524 | return Encoding; |
525 | } |
526 | |
527 | static AlignPackInfo getFromRawEncoding(unsigned Encoding) { |
528 | bool IsXL = static_cast<bool>(Encoding & IsXLMask); |
529 | AlignPackInfo::Mode M = |
530 | static_cast<AlignPackInfo::Mode>((Encoding & AlignModeMask) >> 1); |
531 | int PackNumber = (Encoding & PackNumMask) >> 4; |
532 | |
533 | if (Encoding & PackAttrMask) |
534 | return AlignPackInfo(M, PackNumber, IsXL); |
535 | |
536 | return AlignPackInfo(M, IsXL); |
537 | } |
538 | |
539 | bool IsPackAttr() const { return PackAttr; } |
540 | |
541 | bool IsAlignAttr() const { return !PackAttr; } |
542 | |
543 | Mode getAlignMode() const { return AlignMode; } |
544 | |
545 | unsigned getPackNumber() const { return PackNumber; } |
546 | |
547 | bool IsPackSet() const { |
548 | // #pragma align, #pragma pack(), and #pragma pack(0) do not set the pack |
549 | // attriute on a decl. |
550 | return PackNumber != UninitPackVal && PackNumber != 0; |
551 | } |
552 | |
553 | bool IsXLStack() const { return XLStack; } |
554 | |
555 | bool operator==(const AlignPackInfo &Info) const { |
556 | return std::tie(AlignMode, PackNumber, PackAttr, XLStack) == |
557 | std::tie(Info.AlignMode, Info.PackNumber, Info.PackAttr, |
558 | Info.XLStack); |
559 | } |
560 | |
561 | bool operator!=(const AlignPackInfo &Info) const { |
562 | return !(*this == Info); |
563 | } |
564 | |
565 | private: |
566 | /// \brief True if this is a pragma pack attribute, |
567 | /// not a pragma align attribute. |
568 | bool PackAttr; |
569 | |
570 | /// \brief The alignment mode that is in effect. |
571 | Mode AlignMode; |
572 | |
573 | /// \brief The pack number of the stack. |
574 | unsigned char PackNumber; |
575 | |
576 | /// \brief True if it is a XL #pragma align/pack stack. |
577 | bool XLStack; |
578 | |
579 | /// \brief Uninitialized pack value. |
580 | static constexpr unsigned char UninitPackVal = -1; |
581 | |
582 | // Masks to encode and decode an AlignPackInfo. |
583 | static constexpr uint32_t IsXLMask{0x0000'0001}; |
584 | static constexpr uint32_t AlignModeMask{0x0000'0006}; |
585 | static constexpr uint32_t PackAttrMask{0x00000'0008}; |
586 | static constexpr uint32_t PackNumMask{0x0000'01F0}; |
587 | }; |
588 | |
589 | template<typename ValueType> |
590 | struct PragmaStack { |
591 | struct Slot { |
592 | llvm::StringRef StackSlotLabel; |
593 | ValueType Value; |
594 | SourceLocation PragmaLocation; |
595 | SourceLocation PragmaPushLocation; |
596 | Slot(llvm::StringRef StackSlotLabel, ValueType Value, |
597 | SourceLocation PragmaLocation, SourceLocation PragmaPushLocation) |
598 | : StackSlotLabel(StackSlotLabel), Value(Value), |
599 | PragmaLocation(PragmaLocation), |
600 | PragmaPushLocation(PragmaPushLocation) {} |
601 | }; |
602 | |
603 | void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, |
604 | llvm::StringRef StackSlotLabel, ValueType Value) { |
605 | if (Action == PSK_Reset) { |
606 | CurrentValue = DefaultValue; |
607 | CurrentPragmaLocation = PragmaLocation; |
608 | return; |
609 | } |
610 | if (Action & PSK_Push) |
611 | Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation, |
612 | PragmaLocation); |
613 | else if (Action & PSK_Pop) { |
614 | if (!StackSlotLabel.empty()) { |
615 | // If we've got a label, try to find it and jump there. |
616 | auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) { |
617 | return x.StackSlotLabel == StackSlotLabel; |
618 | }); |
619 | // If we found the label so pop from there. |
620 | if (I != Stack.rend()) { |
621 | CurrentValue = I->Value; |
622 | CurrentPragmaLocation = I->PragmaLocation; |
623 | Stack.erase(std::prev(I.base()), Stack.end()); |
624 | } |
625 | } else if (!Stack.empty()) { |
626 | // We do not have a label, just pop the last entry. |
627 | CurrentValue = Stack.back().Value; |
628 | CurrentPragmaLocation = Stack.back().PragmaLocation; |
629 | Stack.pop_back(); |
630 | } |
631 | } |
632 | if (Action & PSK_Set) { |
633 | CurrentValue = Value; |
634 | CurrentPragmaLocation = PragmaLocation; |
635 | } |
636 | } |
637 | |
638 | // MSVC seems to add artificial slots to #pragma stacks on entering a C++ |
639 | // method body to restore the stacks on exit, so it works like this: |
640 | // |
641 | // struct S { |
642 | // #pragma <name>(push, InternalPragmaSlot, <current_pragma_value>) |
643 | // void Method {} |
644 | // #pragma <name>(pop, InternalPragmaSlot) |
645 | // }; |
646 | // |
647 | // It works even with #pragma vtordisp, although MSVC doesn't support |
648 | // #pragma vtordisp(push [, id], n) |
649 | // syntax. |
650 | // |
651 | // Push / pop a named sentinel slot. |
652 | void SentinelAction(PragmaMsStackAction Action, StringRef Label) { |
653 | assert((Action == PSK_Push || Action == PSK_Pop) &&(static_cast <bool> ((Action == PSK_Push || Action == PSK_Pop ) && "Can only push / pop #pragma stack sentinels!") ? void (0) : __assert_fail ("(Action == PSK_Push || Action == PSK_Pop) && \"Can only push / pop #pragma stack sentinels!\"" , "clang/include/clang/Sema/Sema.h", 654, __extension__ __PRETTY_FUNCTION__ )) |
654 | "Can only push / pop #pragma stack sentinels!")(static_cast <bool> ((Action == PSK_Push || Action == PSK_Pop ) && "Can only push / pop #pragma stack sentinels!") ? void (0) : __assert_fail ("(Action == PSK_Push || Action == PSK_Pop) && \"Can only push / pop #pragma stack sentinels!\"" , "clang/include/clang/Sema/Sema.h", 654, __extension__ __PRETTY_FUNCTION__ )); |
655 | Act(CurrentPragmaLocation, Action, Label, CurrentValue); |
656 | } |
657 | |
658 | // Constructors. |
659 | explicit PragmaStack(const ValueType &Default) |
660 | : DefaultValue(Default), CurrentValue(Default) {} |
661 | |
662 | bool hasValue() const { return CurrentValue != DefaultValue; } |
663 | |
664 | SmallVector<Slot, 2> Stack; |
665 | ValueType DefaultValue; // Value used for PSK_Reset action. |
666 | ValueType CurrentValue; |
667 | SourceLocation CurrentPragmaLocation; |
668 | }; |
669 | // FIXME: We should serialize / deserialize these if they occur in a PCH (but |
670 | // we shouldn't do so if they're in a module). |
671 | |
672 | /// Whether to insert vtordisps prior to virtual bases in the Microsoft |
673 | /// C++ ABI. Possible values are 0, 1, and 2, which mean: |
674 | /// |
675 | /// 0: Suppress all vtordisps |
676 | /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial |
677 | /// structors |
678 | /// 2: Always insert vtordisps to support RTTI on partially constructed |
679 | /// objects |
680 | PragmaStack<MSVtorDispMode> VtorDispStack; |
681 | PragmaStack<AlignPackInfo> AlignPackStack; |
682 | // The current #pragma align/pack values and locations at each #include. |
683 | struct AlignPackIncludeState { |
684 | AlignPackInfo CurrentValue; |
685 | SourceLocation CurrentPragmaLocation; |
686 | bool HasNonDefaultValue, ShouldWarnOnInclude; |
687 | }; |
688 | SmallVector<AlignPackIncludeState, 8> AlignPackIncludeStack; |
689 | // Segment #pragmas. |
690 | PragmaStack<StringLiteral *> DataSegStack; |
691 | PragmaStack<StringLiteral *> BSSSegStack; |
692 | PragmaStack<StringLiteral *> ConstSegStack; |
693 | PragmaStack<StringLiteral *> CodeSegStack; |
694 | |
695 | // This stack tracks the current state of Sema.CurFPFeatures. |
696 | PragmaStack<FPOptionsOverride> FpPragmaStack; |
697 | FPOptionsOverride CurFPFeatureOverrides() { |
698 | FPOptionsOverride result; |
699 | if (!FpPragmaStack.hasValue()) { |
700 | result = FPOptionsOverride(); |
701 | } else { |
702 | result = FpPragmaStack.CurrentValue; |
703 | } |
704 | return result; |
705 | } |
706 | |
707 | // RAII object to push / pop sentinel slots for all MS #pragma stacks. |
708 | // Actions should be performed only if we enter / exit a C++ method body. |
709 | class PragmaStackSentinelRAII { |
710 | public: |
711 | PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct); |
712 | ~PragmaStackSentinelRAII(); |
713 | |
714 | private: |
715 | Sema &S; |
716 | StringRef SlotLabel; |
717 | bool ShouldAct; |
718 | }; |
719 | |
720 | /// A mapping that describes the nullability we've seen in each header file. |
721 | FileNullabilityMap NullabilityMap; |
722 | |
723 | /// Last section used with #pragma init_seg. |
724 | StringLiteral *CurInitSeg; |
725 | SourceLocation CurInitSegLoc; |
726 | |
727 | /// VisContext - Manages the stack for \#pragma GCC visibility. |
728 | void *VisContext; // Really a "PragmaVisStack*" |
729 | |
730 | /// This an attribute introduced by \#pragma clang attribute. |
731 | struct PragmaAttributeEntry { |
732 | SourceLocation Loc; |
733 | ParsedAttr *Attribute; |
734 | SmallVector<attr::SubjectMatchRule, 4> MatchRules; |
735 | bool IsUsed; |
736 | }; |
737 | |
738 | /// A push'd group of PragmaAttributeEntries. |
739 | struct PragmaAttributeGroup { |
740 | /// The location of the push attribute. |
741 | SourceLocation Loc; |
742 | /// The namespace of this push group. |
743 | const IdentifierInfo *Namespace; |
744 | SmallVector<PragmaAttributeEntry, 2> Entries; |
745 | }; |
746 | |
747 | SmallVector<PragmaAttributeGroup, 2> PragmaAttributeStack; |
748 | |
749 | /// The declaration that is currently receiving an attribute from the |
750 | /// #pragma attribute stack. |
751 | const Decl *PragmaAttributeCurrentTargetDecl; |
752 | |
753 | /// This represents the last location of a "#pragma clang optimize off" |
754 | /// directive if such a directive has not been closed by an "on" yet. If |
755 | /// optimizations are currently "on", this is set to an invalid location. |
756 | SourceLocation OptimizeOffPragmaLocation; |
757 | |
758 | /// Flag indicating if Sema is building a recovery call expression. |
759 | /// |
760 | /// This flag is used to avoid building recovery call expressions |
761 | /// if Sema is already doing so, which would cause infinite recursions. |
762 | bool IsBuildingRecoveryCallExpr; |
763 | |
764 | /// Used to control the generation of ExprWithCleanups. |
765 | CleanupInfo Cleanup; |
766 | |
767 | /// ExprCleanupObjects - This is the stack of objects requiring |
768 | /// cleanup that are created by the current full expression. |
769 | SmallVector<ExprWithCleanups::CleanupObject, 8> ExprCleanupObjects; |
770 | |
771 | /// Store a set of either DeclRefExprs or MemberExprs that contain a reference |
772 | /// to a variable (constant) that may or may not be odr-used in this Expr, and |
773 | /// we won't know until all lvalue-to-rvalue and discarded value conversions |
774 | /// have been applied to all subexpressions of the enclosing full expression. |
775 | /// This is cleared at the end of each full expression. |
776 | using MaybeODRUseExprSet = llvm::SetVector<Expr *, SmallVector<Expr *, 4>, |
777 | llvm::SmallPtrSet<Expr *, 4>>; |
778 | MaybeODRUseExprSet MaybeODRUseExprs; |
779 | |
780 | std::unique_ptr<sema::FunctionScopeInfo> CachedFunctionScope; |
781 | |
782 | /// Stack containing information about each of the nested |
783 | /// function, block, and method scopes that are currently active. |
784 | SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes; |
785 | |
786 | /// The index of the first FunctionScope that corresponds to the current |
787 | /// context. |
788 | unsigned FunctionScopesStart = 0; |
789 | |
790 | ArrayRef<sema::FunctionScopeInfo*> getFunctionScopes() const { |
791 | return llvm::makeArrayRef(FunctionScopes.begin() + FunctionScopesStart, |
792 | FunctionScopes.end()); |
793 | } |
794 | |
795 | /// Stack containing information needed when in C++2a an 'auto' is encountered |
796 | /// in a function declaration parameter type specifier in order to invent a |
797 | /// corresponding template parameter in the enclosing abbreviated function |
798 | /// template. This information is also present in LambdaScopeInfo, stored in |
799 | /// the FunctionScopes stack. |
800 | SmallVector<InventedTemplateParameterInfo, 4> InventedParameterInfos; |
801 | |
802 | /// The index of the first InventedParameterInfo that refers to the current |
803 | /// context. |
804 | unsigned InventedParameterInfosStart = 0; |
805 | |
806 | ArrayRef<InventedTemplateParameterInfo> getInventedParameterInfos() const { |
807 | return llvm::makeArrayRef(InventedParameterInfos.begin() + |
808 | InventedParameterInfosStart, |
809 | InventedParameterInfos.end()); |
810 | } |
811 | |
812 | typedef LazyVector<TypedefNameDecl *, ExternalSemaSource, |
813 | &ExternalSemaSource::ReadExtVectorDecls, 2, 2> |
814 | ExtVectorDeclsType; |
815 | |
816 | /// ExtVectorDecls - This is a list all the extended vector types. This allows |
817 | /// us to associate a raw vector type with one of the ext_vector type names. |
818 | /// This is only necessary for issuing pretty diagnostics. |
819 | ExtVectorDeclsType ExtVectorDecls; |
820 | |
821 | /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. |
822 | std::unique_ptr<CXXFieldCollector> FieldCollector; |
823 | |
824 | typedef llvm::SmallSetVector<NamedDecl *, 16> NamedDeclSetType; |
825 | |
826 | /// Set containing all declared private fields that are not used. |
827 | NamedDeclSetType UnusedPrivateFields; |
828 | |
829 | /// Set containing all typedefs that are likely unused. |
830 | llvm::SmallSetVector<const TypedefNameDecl *, 4> |
831 | UnusedLocalTypedefNameCandidates; |
832 | |
833 | /// Delete-expressions to be analyzed at the end of translation unit |
834 | /// |
835 | /// This list contains class members, and locations of delete-expressions |
836 | /// that could not be proven as to whether they mismatch with new-expression |
837 | /// used in initializer of the field. |
838 | typedef std::pair<SourceLocation, bool> DeleteExprLoc; |
839 | typedef llvm::SmallVector<DeleteExprLoc, 4> DeleteLocs; |
840 | llvm::MapVector<FieldDecl *, DeleteLocs> DeleteExprs; |
841 | |
842 | typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy; |
843 | |
844 | /// PureVirtualClassDiagSet - a set of class declarations which we have |
845 | /// emitted a list of pure virtual functions. Used to prevent emitting the |
846 | /// same list more than once. |
847 | std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet; |
848 | |
849 | /// ParsingInitForAutoVars - a set of declarations with auto types for which |
850 | /// we are currently parsing the initializer. |
851 | llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars; |
852 | |
853 | /// Look for a locally scoped extern "C" declaration by the given name. |
854 | NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name); |
855 | |
856 | typedef LazyVector<VarDecl *, ExternalSemaSource, |
857 | &ExternalSemaSource::ReadTentativeDefinitions, 2, 2> |
858 | TentativeDefinitionsType; |
859 | |
860 | /// All the tentative definitions encountered in the TU. |
861 | TentativeDefinitionsType TentativeDefinitions; |
862 | |
863 | /// All the external declarations encoutered and used in the TU. |
864 | SmallVector<VarDecl *, 4> ExternalDeclarations; |
865 | |
866 | typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource, |
867 | &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2> |
868 | UnusedFileScopedDeclsType; |
869 | |
870 | /// The set of file scoped decls seen so far that have not been used |
871 | /// and must warn if not used. Only contains the first declaration. |
872 | UnusedFileScopedDeclsType UnusedFileScopedDecls; |
873 | |
874 | typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource, |
875 | &ExternalSemaSource::ReadDelegatingConstructors, 2, 2> |
876 | DelegatingCtorDeclsType; |
877 | |
878 | /// All the delegating constructors seen so far in the file, used for |
879 | /// cycle detection at the end of the TU. |
880 | DelegatingCtorDeclsType DelegatingCtorDecls; |
881 | |
882 | /// All the overriding functions seen during a class definition |
883 | /// that had their exception spec checks delayed, plus the overridden |
884 | /// function. |
885 | SmallVector<std::pair<const CXXMethodDecl*, const CXXMethodDecl*>, 2> |
886 | DelayedOverridingExceptionSpecChecks; |
887 | |
888 | /// All the function redeclarations seen during a class definition that had |
889 | /// their exception spec checks delayed, plus the prior declaration they |
890 | /// should be checked against. Except during error recovery, the new decl |
891 | /// should always be a friend declaration, as that's the only valid way to |
892 | /// redeclare a special member before its class is complete. |
893 | SmallVector<std::pair<FunctionDecl*, FunctionDecl*>, 2> |
894 | DelayedEquivalentExceptionSpecChecks; |
895 | |
896 | typedef llvm::MapVector<const FunctionDecl *, |
897 | std::unique_ptr<LateParsedTemplate>> |
898 | LateParsedTemplateMapT; |
899 | LateParsedTemplateMapT LateParsedTemplateMap; |
900 | |
901 | /// Callback to the parser to parse templated functions when needed. |
902 | typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT); |
903 | typedef void LateTemplateParserCleanupCB(void *P); |
904 | LateTemplateParserCB *LateTemplateParser; |
905 | LateTemplateParserCleanupCB *LateTemplateParserCleanup; |
906 | void *OpaqueParser; |
907 | |
908 | void SetLateTemplateParser(LateTemplateParserCB *LTP, |
909 | LateTemplateParserCleanupCB *LTPCleanup, |
910 | void *P) { |
911 | LateTemplateParser = LTP; |
912 | LateTemplateParserCleanup = LTPCleanup; |
913 | OpaqueParser = P; |
914 | } |
915 | |
916 | class DelayedDiagnostics; |
917 | |
918 | class DelayedDiagnosticsState { |
919 | sema::DelayedDiagnosticPool *SavedPool; |
920 | friend class Sema::DelayedDiagnostics; |
921 | }; |
922 | typedef DelayedDiagnosticsState ParsingDeclState; |
923 | typedef DelayedDiagnosticsState ProcessingContextState; |
924 | |
925 | /// A class which encapsulates the logic for delaying diagnostics |
926 | /// during parsing and other processing. |
927 | class DelayedDiagnostics { |
928 | /// The current pool of diagnostics into which delayed |
929 | /// diagnostics should go. |
930 | sema::DelayedDiagnosticPool *CurPool; |
931 | |
932 | public: |
933 | DelayedDiagnostics() : CurPool(nullptr) {} |
934 | |
935 | /// Adds a delayed diagnostic. |
936 | void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h |
937 | |
938 | /// Determines whether diagnostics should be delayed. |
939 | bool shouldDelayDiagnostics() { return CurPool != nullptr; } |
940 | |
941 | /// Returns the current delayed-diagnostics pool. |
942 | sema::DelayedDiagnosticPool *getCurrentPool() const { |
943 | return CurPool; |
944 | } |
945 | |
946 | /// Enter a new scope. Access and deprecation diagnostics will be |
947 | /// collected in this pool. |
948 | DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) { |
949 | DelayedDiagnosticsState state; |
950 | state.SavedPool = CurPool; |
951 | CurPool = &pool; |
952 | return state; |
953 | } |
954 | |
955 | /// Leave a delayed-diagnostic state that was previously pushed. |
956 | /// Do not emit any of the diagnostics. This is performed as part |
957 | /// of the bookkeeping of popping a pool "properly". |
958 | void popWithoutEmitting(DelayedDiagnosticsState state) { |
959 | CurPool = state.SavedPool; |
960 | } |
961 | |
962 | /// Enter a new scope where access and deprecation diagnostics are |
963 | /// not delayed. |
964 | DelayedDiagnosticsState pushUndelayed() { |
965 | DelayedDiagnosticsState state; |
966 | state.SavedPool = CurPool; |
967 | CurPool = nullptr; |
968 | return state; |
969 | } |
970 | |
971 | /// Undo a previous pushUndelayed(). |
972 | void popUndelayed(DelayedDiagnosticsState state) { |
973 | assert(CurPool == nullptr)(static_cast <bool> (CurPool == nullptr) ? void (0) : __assert_fail ("CurPool == nullptr", "clang/include/clang/Sema/Sema.h", 973 , __extension__ __PRETTY_FUNCTION__)); |
974 | CurPool = state.SavedPool; |
975 | } |
976 | } DelayedDiagnostics; |
977 | |
978 | /// A RAII object to temporarily push a declaration context. |
979 | class ContextRAII { |
980 | private: |
981 | Sema &S; |
982 | DeclContext *SavedContext; |
983 | ProcessingContextState SavedContextState; |
984 | QualType SavedCXXThisTypeOverride; |
985 | unsigned SavedFunctionScopesStart; |
986 | unsigned SavedInventedParameterInfosStart; |
987 | |
988 | public: |
989 | ContextRAII(Sema &S, DeclContext *ContextToPush, bool NewThisContext = true) |
990 | : S(S), SavedContext(S.CurContext), |
991 | SavedContextState(S.DelayedDiagnostics.pushUndelayed()), |
992 | SavedCXXThisTypeOverride(S.CXXThisTypeOverride), |
993 | SavedFunctionScopesStart(S.FunctionScopesStart), |
994 | SavedInventedParameterInfosStart(S.InventedParameterInfosStart) |
995 | { |
996 | assert(ContextToPush && "pushing null context")(static_cast <bool> (ContextToPush && "pushing null context" ) ? void (0) : __assert_fail ("ContextToPush && \"pushing null context\"" , "clang/include/clang/Sema/Sema.h", 996, __extension__ __PRETTY_FUNCTION__ )); |
997 | S.CurContext = ContextToPush; |
998 | if (NewThisContext) |
999 | S.CXXThisTypeOverride = QualType(); |
1000 | // Any saved FunctionScopes do not refer to this context. |
1001 | S.FunctionScopesStart = S.FunctionScopes.size(); |
1002 | S.InventedParameterInfosStart = S.InventedParameterInfos.size(); |
1003 | } |
1004 | |
1005 | void pop() { |
1006 | if (!SavedContext) return; |
1007 | S.CurContext = SavedContext; |
1008 | S.DelayedDiagnostics.popUndelayed(SavedContextState); |
1009 | S.CXXThisTypeOverride = SavedCXXThisTypeOverride; |
1010 | S.FunctionScopesStart = SavedFunctionScopesStart; |
1011 | S.InventedParameterInfosStart = SavedInventedParameterInfosStart; |
1012 | SavedContext = nullptr; |
1013 | } |
1014 | |
1015 | ~ContextRAII() { |
1016 | pop(); |
1017 | } |
1018 | }; |
1019 | |
1020 | /// Whether the AST is currently being rebuilt to correct immediate |
1021 | /// invocations. Immediate invocation candidates and references to consteval |
1022 | /// functions aren't tracked when this is set. |
1023 | bool RebuildingImmediateInvocation = false; |
1024 | |
1025 | /// Used to change context to isConstantEvaluated without pushing a heavy |
1026 | /// ExpressionEvaluationContextRecord object. |
1027 | bool isConstantEvaluatedOverride; |
1028 | |
1029 | bool isConstantEvaluated() { |
1030 | return ExprEvalContexts.back().isConstantEvaluated() || |
1031 | isConstantEvaluatedOverride; |
1032 | } |
1033 | |
1034 | /// RAII object to handle the state changes required to synthesize |
1035 | /// a function body. |
1036 | class SynthesizedFunctionScope { |
1037 | Sema &S; |
1038 | Sema::ContextRAII SavedContext; |
1039 | bool PushedCodeSynthesisContext = false; |
1040 | |
1041 | public: |
1042 | SynthesizedFunctionScope(Sema &S, DeclContext *DC) |
1043 | : S(S), SavedContext(S, DC) { |
1044 | S.PushFunctionScope(); |
1045 | S.PushExpressionEvaluationContext( |
1046 | Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
1047 | if (auto *FD = dyn_cast<FunctionDecl>(DC)) |
1048 | FD->setWillHaveBody(true); |
1049 | else |
1050 | assert(isa<ObjCMethodDecl>(DC))(static_cast <bool> (isa<ObjCMethodDecl>(DC)) ? void (0) : __assert_fail ("isa<ObjCMethodDecl>(DC)", "clang/include/clang/Sema/Sema.h" , 1050, __extension__ __PRETTY_FUNCTION__)); |
1051 | } |
1052 | |
1053 | void addContextNote(SourceLocation UseLoc) { |
1054 | assert(!PushedCodeSynthesisContext)(static_cast <bool> (!PushedCodeSynthesisContext) ? void (0) : __assert_fail ("!PushedCodeSynthesisContext", "clang/include/clang/Sema/Sema.h" , 1054, __extension__ __PRETTY_FUNCTION__)); |
1055 | |
1056 | Sema::CodeSynthesisContext Ctx; |
1057 | Ctx.Kind = Sema::CodeSynthesisContext::DefiningSynthesizedFunction; |
1058 | Ctx.PointOfInstantiation = UseLoc; |
1059 | Ctx.Entity = cast<Decl>(S.CurContext); |
1060 | S.pushCodeSynthesisContext(Ctx); |
1061 | |
1062 | PushedCodeSynthesisContext = true; |
1063 | } |
1064 | |
1065 | ~SynthesizedFunctionScope() { |
1066 | if (PushedCodeSynthesisContext) |
1067 | S.popCodeSynthesisContext(); |
1068 | if (auto *FD = dyn_cast<FunctionDecl>(S.CurContext)) |
1069 | FD->setWillHaveBody(false); |
1070 | S.PopExpressionEvaluationContext(); |
1071 | S.PopFunctionScopeInfo(); |
1072 | } |
1073 | }; |
1074 | |
1075 | /// WeakUndeclaredIdentifiers - Identifiers contained in |
1076 | /// \#pragma weak before declared. rare. may alias another |
1077 | /// identifier, declared or undeclared |
1078 | llvm::MapVector<IdentifierInfo *, WeakInfo> WeakUndeclaredIdentifiers; |
1079 | |
1080 | /// ExtnameUndeclaredIdentifiers - Identifiers contained in |
1081 | /// \#pragma redefine_extname before declared. Used in Solaris system headers |
1082 | /// to define functions that occur in multiple standards to call the version |
1083 | /// in the currently selected standard. |
1084 | llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers; |
1085 | |
1086 | |
1087 | /// Load weak undeclared identifiers from the external source. |
1088 | void LoadExternalWeakUndeclaredIdentifiers(); |
1089 | |
1090 | /// WeakTopLevelDecl - Translation-unit scoped declarations generated by |
1091 | /// \#pragma weak during processing of other Decls. |
1092 | /// I couldn't figure out a clean way to generate these in-line, so |
1093 | /// we store them here and handle separately -- which is a hack. |
1094 | /// It would be best to refactor this. |
1095 | SmallVector<Decl*,2> WeakTopLevelDecl; |
1096 | |
1097 | IdentifierResolver IdResolver; |
1098 | |
1099 | /// Translation Unit Scope - useful to Objective-C actions that need |
1100 | /// to lookup file scope declarations in the "ordinary" C decl namespace. |
1101 | /// For example, user-defined classes, built-in "id" type, etc. |
1102 | Scope *TUScope; |
1103 | |
1104 | /// The C++ "std" namespace, where the standard library resides. |
1105 | LazyDeclPtr StdNamespace; |
1106 | |
1107 | /// The C++ "std::bad_alloc" class, which is defined by the C++ |
1108 | /// standard library. |
1109 | LazyDeclPtr StdBadAlloc; |
1110 | |
1111 | /// The C++ "std::align_val_t" enum class, which is defined by the C++ |
1112 | /// standard library. |
1113 | LazyDeclPtr StdAlignValT; |
1114 | |
1115 | /// The C++ "std::experimental" namespace, where the experimental parts |
1116 | /// of the standard library resides. |
1117 | NamespaceDecl *StdExperimentalNamespaceCache; |
1118 | |
1119 | /// The C++ "std::initializer_list" template, which is defined in |
1120 | /// \<initializer_list>. |
1121 | ClassTemplateDecl *StdInitializerList; |
1122 | |
1123 | /// The C++ "std::coroutine_traits" template, which is defined in |
1124 | /// \<coroutine_traits> |
1125 | ClassTemplateDecl *StdCoroutineTraitsCache; |
1126 | /// The namespace where coroutine components are defined. In standard, |
1127 | /// they are defined in std namespace. And in the previous implementation, |
1128 | /// they are defined in std::experimental namespace. |
1129 | NamespaceDecl *CoroTraitsNamespaceCache; |
1130 | |
1131 | /// The C++ "type_info" declaration, which is defined in \<typeinfo>. |
1132 | RecordDecl *CXXTypeInfoDecl; |
1133 | |
1134 | /// The MSVC "_GUID" struct, which is defined in MSVC header files. |
1135 | RecordDecl *MSVCGuidDecl; |
1136 | |
1137 | /// Caches identifiers/selectors for NSFoundation APIs. |
1138 | std::unique_ptr<NSAPI> NSAPIObj; |
1139 | |
1140 | /// The declaration of the Objective-C NSNumber class. |
1141 | ObjCInterfaceDecl *NSNumberDecl; |
1142 | |
1143 | /// The declaration of the Objective-C NSValue class. |
1144 | ObjCInterfaceDecl *NSValueDecl; |
1145 | |
1146 | /// Pointer to NSNumber type (NSNumber *). |
1147 | QualType NSNumberPointer; |
1148 | |
1149 | /// Pointer to NSValue type (NSValue *). |
1150 | QualType NSValuePointer; |
1151 | |
1152 | /// The Objective-C NSNumber methods used to create NSNumber literals. |
1153 | ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]; |
1154 | |
1155 | /// The declaration of the Objective-C NSString class. |
1156 | ObjCInterfaceDecl *NSStringDecl; |
1157 | |
1158 | /// Pointer to NSString type (NSString *). |
1159 | QualType NSStringPointer; |
1160 | |
1161 | /// The declaration of the stringWithUTF8String: method. |
1162 | ObjCMethodDecl *StringWithUTF8StringMethod; |
1163 | |
1164 | /// The declaration of the valueWithBytes:objCType: method. |
1165 | ObjCMethodDecl *ValueWithBytesObjCTypeMethod; |
1166 | |
1167 | /// The declaration of the Objective-C NSArray class. |
1168 | ObjCInterfaceDecl *NSArrayDecl; |
1169 | |
1170 | /// The declaration of the arrayWithObjects:count: method. |
1171 | ObjCMethodDecl *ArrayWithObjectsMethod; |
1172 | |
1173 | /// The declaration of the Objective-C NSDictionary class. |
1174 | ObjCInterfaceDecl *NSDictionaryDecl; |
1175 | |
1176 | /// The declaration of the dictionaryWithObjects:forKeys:count: method. |
1177 | ObjCMethodDecl *DictionaryWithObjectsMethod; |
1178 | |
1179 | /// id<NSCopying> type. |
1180 | QualType QIDNSCopying; |
1181 | |
1182 | /// will hold 'respondsToSelector:' |
1183 | Selector RespondsToSelectorSel; |
1184 | |
1185 | /// A flag to remember whether the implicit forms of operator new and delete |
1186 | /// have been declared. |
1187 | bool GlobalNewDeleteDeclared; |
1188 | |
1189 | /// Describes how the expressions currently being parsed are |
1190 | /// evaluated at run-time, if at all. |
1191 | enum class ExpressionEvaluationContext { |
1192 | /// The current expression and its subexpressions occur within an |
1193 | /// unevaluated operand (C++11 [expr]p7), such as the subexpression of |
1194 | /// \c sizeof, where the type of the expression may be significant but |
1195 | /// no code will be generated to evaluate the value of the expression at |
1196 | /// run time. |
1197 | Unevaluated, |
1198 | |
1199 | /// The current expression occurs within a braced-init-list within |
1200 | /// an unevaluated operand. This is mostly like a regular unevaluated |
1201 | /// context, except that we still instantiate constexpr functions that are |
1202 | /// referenced here so that we can perform narrowing checks correctly. |
1203 | UnevaluatedList, |
1204 | |
1205 | /// The current expression occurs within a discarded statement. |
1206 | /// This behaves largely similarly to an unevaluated operand in preventing |
1207 | /// definitions from being required, but not in other ways. |
1208 | DiscardedStatement, |
1209 | |
1210 | /// The current expression occurs within an unevaluated |
1211 | /// operand that unconditionally permits abstract references to |
1212 | /// fields, such as a SIZE operator in MS-style inline assembly. |
1213 | UnevaluatedAbstract, |
1214 | |
1215 | /// The current context is "potentially evaluated" in C++11 terms, |
1216 | /// but the expression is evaluated at compile-time (like the values of |
1217 | /// cases in a switch statement). |
1218 | ConstantEvaluated, |
1219 | |
1220 | /// In addition of being constant evaluated, the current expression |
1221 | /// occurs in an immediate function context - either a consteval function |
1222 | /// or a consteval if function. |
1223 | ImmediateFunctionContext, |
1224 | |
1225 | /// The current expression is potentially evaluated at run time, |
1226 | /// which means that code may be generated to evaluate the value of the |
1227 | /// expression at run time. |
1228 | PotentiallyEvaluated, |
1229 | |
1230 | /// The current expression is potentially evaluated, but any |
1231 | /// declarations referenced inside that expression are only used if |
1232 | /// in fact the current expression is used. |
1233 | /// |
1234 | /// This value is used when parsing default function arguments, for which |
1235 | /// we would like to provide diagnostics (e.g., passing non-POD arguments |
1236 | /// through varargs) but do not want to mark declarations as "referenced" |
1237 | /// until the default argument is used. |
1238 | PotentiallyEvaluatedIfUsed |
1239 | }; |
1240 | |
1241 | using ImmediateInvocationCandidate = llvm::PointerIntPair<ConstantExpr *, 1>; |
1242 | |
1243 | /// Data structure used to record current or nested |
1244 | /// expression evaluation contexts. |
1245 | struct ExpressionEvaluationContextRecord { |
1246 | /// The expression evaluation context. |
1247 | ExpressionEvaluationContext Context; |
1248 | |
1249 | /// Whether the enclosing context needed a cleanup. |
1250 | CleanupInfo ParentCleanup; |
1251 | |
1252 | /// The number of active cleanup objects when we entered |
1253 | /// this expression evaluation context. |
1254 | unsigned NumCleanupObjects; |
1255 | |
1256 | /// The number of typos encountered during this expression evaluation |
1257 | /// context (i.e. the number of TypoExprs created). |
1258 | unsigned NumTypos; |
1259 | |
1260 | MaybeODRUseExprSet SavedMaybeODRUseExprs; |
1261 | |
1262 | /// The lambdas that are present within this context, if it |
1263 | /// is indeed an unevaluated context. |
1264 | SmallVector<LambdaExpr *, 2> Lambdas; |
1265 | |
1266 | /// The declaration that provides context for lambda expressions |
1267 | /// and block literals if the normal declaration context does not |
1268 | /// suffice, e.g., in a default function argument. |
1269 | Decl *ManglingContextDecl; |
1270 | |
1271 | /// If we are processing a decltype type, a set of call expressions |
1272 | /// for which we have deferred checking the completeness of the return type. |
1273 | SmallVector<CallExpr *, 8> DelayedDecltypeCalls; |
1274 | |
1275 | /// If we are processing a decltype type, a set of temporary binding |
1276 | /// expressions for which we have deferred checking the destructor. |
1277 | SmallVector<CXXBindTemporaryExpr *, 8> DelayedDecltypeBinds; |
1278 | |
1279 | llvm::SmallPtrSet<const Expr *, 8> PossibleDerefs; |
1280 | |
1281 | /// Expressions appearing as the LHS of a volatile assignment in this |
1282 | /// context. We produce a warning for these when popping the context if |
1283 | /// they are not discarded-value expressions nor unevaluated operands. |
1284 | SmallVector<Expr*, 2> VolatileAssignmentLHSs; |
1285 | |
1286 | /// Set of candidates for starting an immediate invocation. |
1287 | llvm::SmallVector<ImmediateInvocationCandidate, 4> ImmediateInvocationCandidates; |
1288 | |
1289 | /// Set of DeclRefExprs referencing a consteval function when used in a |
1290 | /// context not already known to be immediately invoked. |
1291 | llvm::SmallPtrSet<DeclRefExpr *, 4> ReferenceToConsteval; |
1292 | |
1293 | /// \brief Describes whether we are in an expression constext which we have |
1294 | /// to handle differently. |
1295 | enum ExpressionKind { |
1296 | EK_Decltype, EK_TemplateArgument, EK_Other |
1297 | } ExprContext; |
1298 | |
1299 | // A context can be nested in both a discarded statement context and |
1300 | // an immediate function context, so they need to be tracked independently. |
1301 | bool InDiscardedStatement; |
1302 | bool InImmediateFunctionContext; |
1303 | |
1304 | ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context, |
1305 | unsigned NumCleanupObjects, |
1306 | CleanupInfo ParentCleanup, |
1307 | Decl *ManglingContextDecl, |
1308 | ExpressionKind ExprContext) |
1309 | : Context(Context), ParentCleanup(ParentCleanup), |
1310 | NumCleanupObjects(NumCleanupObjects), NumTypos(0), |
1311 | ManglingContextDecl(ManglingContextDecl), ExprContext(ExprContext), |
1312 | InDiscardedStatement(false), InImmediateFunctionContext(false) {} |
1313 | |
1314 | bool isUnevaluated() const { |
1315 | return Context == ExpressionEvaluationContext::Unevaluated || |
1316 | Context == ExpressionEvaluationContext::UnevaluatedAbstract || |
1317 | Context == ExpressionEvaluationContext::UnevaluatedList; |
1318 | } |
1319 | |
1320 | bool isConstantEvaluated() const { |
1321 | return Context == ExpressionEvaluationContext::ConstantEvaluated || |
1322 | Context == ExpressionEvaluationContext::ImmediateFunctionContext; |
1323 | } |
1324 | |
1325 | bool isImmediateFunctionContext() const { |
1326 | return Context == ExpressionEvaluationContext::ImmediateFunctionContext || |
1327 | (Context == ExpressionEvaluationContext::DiscardedStatement && |
1328 | InImmediateFunctionContext); |
1329 | } |
1330 | |
1331 | bool isDiscardedStatementContext() const { |
1332 | return Context == ExpressionEvaluationContext::DiscardedStatement || |
1333 | (Context == |
1334 | ExpressionEvaluationContext::ImmediateFunctionContext && |
1335 | InDiscardedStatement); |
1336 | } |
1337 | }; |
1338 | |
1339 | /// A stack of expression evaluation contexts. |
1340 | SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts; |
1341 | |
1342 | /// Emit a warning for all pending noderef expressions that we recorded. |
1343 | void WarnOnPendingNoDerefs(ExpressionEvaluationContextRecord &Rec); |
1344 | |
1345 | /// Compute the mangling number context for a lambda expression or |
1346 | /// block literal. Also return the extra mangling decl if any. |
1347 | /// |
1348 | /// \param DC - The DeclContext containing the lambda expression or |
1349 | /// block literal. |
1350 | std::tuple<MangleNumberingContext *, Decl *> |
1351 | getCurrentMangleNumberContext(const DeclContext *DC); |
1352 | |
1353 | |
1354 | /// SpecialMemberOverloadResult - The overloading result for a special member |
1355 | /// function. |
1356 | /// |
1357 | /// This is basically a wrapper around PointerIntPair. The lowest bits of the |
1358 | /// integer are used to determine whether overload resolution succeeded. |
1359 | class SpecialMemberOverloadResult { |
1360 | public: |
1361 | enum Kind { |
1362 | NoMemberOrDeleted, |
1363 | Ambiguous, |
1364 | Success |
1365 | }; |
1366 | |
1367 | private: |
1368 | llvm::PointerIntPair<CXXMethodDecl *, 2> Pair; |
1369 | |
1370 | public: |
1371 | SpecialMemberOverloadResult() {} |
1372 | SpecialMemberOverloadResult(CXXMethodDecl *MD) |
1373 | : Pair(MD, MD->isDeleted() ? NoMemberOrDeleted : Success) {} |
1374 | |
1375 | CXXMethodDecl *getMethod() const { return Pair.getPointer(); } |
1376 | void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); } |
1377 | |
1378 | Kind getKind() const { return static_cast<Kind>(Pair.getInt()); } |
1379 | void setKind(Kind K) { Pair.setInt(K); } |
1380 | }; |
1381 | |
1382 | class SpecialMemberOverloadResultEntry |
1383 | : public llvm::FastFoldingSetNode, |
1384 | public SpecialMemberOverloadResult { |
1385 | public: |
1386 | SpecialMemberOverloadResultEntry(const llvm::FoldingSetNodeID &ID) |
1387 | : FastFoldingSetNode(ID) |
1388 | {} |
1389 | }; |
1390 | |
1391 | /// A cache of special member function overload resolution results |
1392 | /// for C++ records. |
1393 | llvm::FoldingSet<SpecialMemberOverloadResultEntry> SpecialMemberCache; |
1394 | |
1395 | /// A cache of the flags available in enumerations with the flag_bits |
1396 | /// attribute. |
1397 | mutable llvm::DenseMap<const EnumDecl*, llvm::APInt> FlagBitsCache; |
1398 | |
1399 | /// The kind of translation unit we are processing. |
1400 | /// |
1401 | /// When we're processing a complete translation unit, Sema will perform |
1402 | /// end-of-translation-unit semantic tasks (such as creating |
1403 | /// initializers for tentative definitions in C) once parsing has |
1404 | /// completed. Modules and precompiled headers perform different kinds of |
1405 | /// checks. |
1406 | const TranslationUnitKind TUKind; |
1407 | |
1408 | llvm::BumpPtrAllocator BumpAlloc; |
1409 | |
1410 | /// The number of SFINAE diagnostics that have been trapped. |
1411 | unsigned NumSFINAEErrors; |
1412 | |
1413 | typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>> |
1414 | UnparsedDefaultArgInstantiationsMap; |
1415 | |
1416 | /// A mapping from parameters with unparsed default arguments to the |
1417 | /// set of instantiations of each parameter. |
1418 | /// |
1419 | /// This mapping is a temporary data structure used when parsing |
1420 | /// nested class templates or nested classes of class templates, |
1421 | /// where we might end up instantiating an inner class before the |
1422 | /// default arguments of its methods have been parsed. |
1423 | UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations; |
1424 | |
1425 | // Contains the locations of the beginning of unparsed default |
1426 | // argument locations. |
1427 | llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs; |
1428 | |
1429 | /// UndefinedInternals - all the used, undefined objects which require a |
1430 | /// definition in this translation unit. |
1431 | llvm::MapVector<NamedDecl *, SourceLocation> UndefinedButUsed; |
1432 | |
1433 | /// Determine if VD, which must be a variable or function, is an external |
1434 | /// symbol that nonetheless can't be referenced from outside this translation |
1435 | /// unit because its type has no linkage and it's not extern "C". |
1436 | bool isExternalWithNoLinkageType(ValueDecl *VD); |
1437 | |
1438 | /// Obtain a sorted list of functions that are undefined but ODR-used. |
1439 | void getUndefinedButUsed( |
1440 | SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined); |
1441 | |
1442 | /// Retrieves list of suspicious delete-expressions that will be checked at |
1443 | /// the end of translation unit. |
1444 | const llvm::MapVector<FieldDecl *, DeleteLocs> & |
1445 | getMismatchingDeleteExpressions() const; |
1446 | |
1447 | class GlobalMethodPool { |
1448 | public: |
1449 | using Lists = std::pair<ObjCMethodList, ObjCMethodList>; |
1450 | using iterator = llvm::DenseMap<Selector, Lists>::iterator; |
1451 | iterator begin() { return Methods.begin(); } |
1452 | iterator end() { return Methods.end(); } |
1453 | iterator find(Selector Sel) { return Methods.find(Sel); } |
1454 | std::pair<iterator, bool> insert(std::pair<Selector, Lists> &&Val) { |
1455 | return Methods.insert(Val); |
1456 | } |
1457 | int count(Selector Sel) const { return Methods.count(Sel); } |
1458 | bool empty() const { return Methods.empty(); } |
1459 | |
1460 | private: |
1461 | llvm::DenseMap<Selector, Lists> Methods; |
1462 | }; |
1463 | |
1464 | /// Method Pool - allows efficient lookup when typechecking messages to "id". |
1465 | /// We need to maintain a list, since selectors can have differing signatures |
1466 | /// across classes. In Cocoa, this happens to be extremely uncommon (only 1% |
1467 | /// of selectors are "overloaded"). |
1468 | /// At the head of the list it is recorded whether there were 0, 1, or >= 2 |
1469 | /// methods inside categories with a particular selector. |
1470 | GlobalMethodPool MethodPool; |
1471 | |
1472 | /// Method selectors used in a \@selector expression. Used for implementation |
1473 | /// of -Wselector. |
1474 | llvm::MapVector<Selector, SourceLocation> ReferencedSelectors; |
1475 | |
1476 | /// List of SourceLocations where 'self' is implicitly retained inside a |
1477 | /// block. |
1478 | llvm::SmallVector<std::pair<SourceLocation, const BlockDecl *>, 1> |
1479 | ImplicitlyRetainedSelfLocs; |
1480 | |
1481 | /// Kinds of C++ special members. |
1482 | enum CXXSpecialMember { |
1483 | CXXDefaultConstructor, |
1484 | CXXCopyConstructor, |
1485 | CXXMoveConstructor, |
1486 | CXXCopyAssignment, |
1487 | CXXMoveAssignment, |
1488 | CXXDestructor, |
1489 | CXXInvalid |
1490 | }; |
1491 | |
1492 | typedef llvm::PointerIntPair<CXXRecordDecl *, 3, CXXSpecialMember> |
1493 | SpecialMemberDecl; |
1494 | |
1495 | /// The C++ special members which we are currently in the process of |
1496 | /// declaring. If this process recursively triggers the declaration of the |
1497 | /// same special member, we should act as if it is not yet declared. |
1498 | llvm::SmallPtrSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared; |
1499 | |
1500 | /// Kinds of defaulted comparison operator functions. |
1501 | enum class DefaultedComparisonKind : unsigned char { |
1502 | /// This is not a defaultable comparison operator. |
1503 | None, |
1504 | /// This is an operator== that should be implemented as a series of |
1505 | /// subobject comparisons. |
1506 | Equal, |
1507 | /// This is an operator<=> that should be implemented as a series of |
1508 | /// subobject comparisons. |
1509 | ThreeWay, |
1510 | /// This is an operator!= that should be implemented as a rewrite in terms |
1511 | /// of a == comparison. |
1512 | NotEqual, |
1513 | /// This is an <, <=, >, or >= that should be implemented as a rewrite in |
1514 | /// terms of a <=> comparison. |
1515 | Relational, |
1516 | }; |
1517 | |
1518 | /// The function definitions which were renamed as part of typo-correction |
1519 | /// to match their respective declarations. We want to keep track of them |
1520 | /// to ensure that we don't emit a "redefinition" error if we encounter a |
1521 | /// correctly named definition after the renamed definition. |
1522 | llvm::SmallPtrSet<const NamedDecl *, 4> TypoCorrectedFunctionDefinitions; |
1523 | |
1524 | /// Stack of types that correspond to the parameter entities that are |
1525 | /// currently being copy-initialized. Can be empty. |
1526 | llvm::SmallVector<QualType, 4> CurrentParameterCopyTypes; |
1527 | |
1528 | void ReadMethodPool(Selector Sel); |
1529 | void updateOutOfDateSelector(Selector Sel); |
1530 | |
1531 | /// Private Helper predicate to check for 'self'. |
1532 | bool isSelfExpr(Expr *RExpr); |
1533 | bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method); |
1534 | |
1535 | /// Cause the active diagnostic on the DiagosticsEngine to be |
1536 | /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and |
1537 | /// should not be used elsewhere. |
1538 | void EmitCurrentDiagnostic(unsigned DiagID); |
1539 | |
1540 | /// Records and restores the CurFPFeatures state on entry/exit of compound |
1541 | /// statements. |
1542 | class FPFeaturesStateRAII { |
1543 | public: |
1544 | FPFeaturesStateRAII(Sema &S) : S(S), OldFPFeaturesState(S.CurFPFeatures) { |
1545 | OldOverrides = S.FpPragmaStack.CurrentValue; |
1546 | } |
1547 | ~FPFeaturesStateRAII() { |
1548 | S.CurFPFeatures = OldFPFeaturesState; |
1549 | S.FpPragmaStack.CurrentValue = OldOverrides; |
1550 | } |
1551 | FPOptionsOverride getOverrides() { return OldOverrides; } |
1552 | |
1553 | private: |
1554 | Sema& S; |
1555 | FPOptions OldFPFeaturesState; |
1556 | FPOptionsOverride OldOverrides; |
1557 | }; |
1558 | |
1559 | void addImplicitTypedef(StringRef Name, QualType T); |
1560 | |
1561 | bool WarnedStackExhausted = false; |
1562 | |
1563 | /// Increment when we find a reference; decrement when we find an ignored |
1564 | /// assignment. Ultimately the value is 0 if every reference is an ignored |
1565 | /// assignment. |
1566 | llvm::DenseMap<const VarDecl *, int> RefsMinusAssignments; |
1567 | |
1568 | Optional<std::unique_ptr<DarwinSDKInfo>> CachedDarwinSDKInfo; |
1569 | |
1570 | public: |
1571 | Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, |
1572 | TranslationUnitKind TUKind = TU_Complete, |
1573 | CodeCompleteConsumer *CompletionConsumer = nullptr); |
1574 | ~Sema(); |
1575 | |
1576 | /// Perform initialization that occurs after the parser has been |
1577 | /// initialized but before it parses anything. |
1578 | void Initialize(); |
1579 | |
1580 | /// This virtual key function only exists to limit the emission of debug info |
1581 | /// describing the Sema class. GCC and Clang only emit debug info for a class |
1582 | /// with a vtable when the vtable is emitted. Sema is final and not |
1583 | /// polymorphic, but the debug info size savings are so significant that it is |
1584 | /// worth adding a vtable just to take advantage of this optimization. |
1585 | virtual void anchor(); |
1586 | |
1587 | const LangOptions &getLangOpts() const { return LangOpts; } |
1588 | OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; } |
1589 | FPOptions &getCurFPFeatures() { return CurFPFeatures; } |
1590 | |
1591 | DiagnosticsEngine &getDiagnostics() const { return Diags; } |
1592 | SourceManager &getSourceManager() const { return SourceMgr; } |
1593 | Preprocessor &getPreprocessor() const { return PP; } |
1594 | ASTContext &getASTContext() const { return Context; } |
1595 | ASTConsumer &getASTConsumer() const { return Consumer; } |
1596 | ASTMutationListener *getASTMutationListener() const; |
1597 | ExternalSemaSource* getExternalSource() const { return ExternalSource; } |
1598 | DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(SourceLocation Loc, |
1599 | StringRef Platform); |
1600 | |
1601 | ///Registers an external source. If an external source already exists, |
1602 | /// creates a multiplex external source and appends to it. |
1603 | /// |
1604 | ///\param[in] E - A non-null external sema source. |
1605 | /// |
1606 | void addExternalSource(ExternalSemaSource *E); |
1607 | |
1608 | void PrintStats() const; |
1609 | |
1610 | /// Warn that the stack is nearly exhausted. |
1611 | void warnStackExhausted(SourceLocation Loc); |
1612 | |
1613 | /// Run some code with "sufficient" stack space. (Currently, at least 256K is |
1614 | /// guaranteed). Produces a warning if we're low on stack space and allocates |
1615 | /// more in that case. Use this in code that may recurse deeply (for example, |
1616 | /// in template instantiation) to avoid stack overflow. |
1617 | void runWithSufficientStackSpace(SourceLocation Loc, |
1618 | llvm::function_ref<void()> Fn); |
1619 | |
1620 | /// Helper class that creates diagnostics with optional |
1621 | /// template instantiation stacks. |
1622 | /// |
1623 | /// This class provides a wrapper around the basic DiagnosticBuilder |
1624 | /// class that emits diagnostics. ImmediateDiagBuilder is |
1625 | /// responsible for emitting the diagnostic (as DiagnosticBuilder |
1626 | /// does) and, if the diagnostic comes from inside a template |
1627 | /// instantiation, printing the template instantiation stack as |
1628 | /// well. |
1629 | class ImmediateDiagBuilder : public DiagnosticBuilder { |
1630 | Sema &SemaRef; |
1631 | unsigned DiagID; |
1632 | |
1633 | public: |
1634 | ImmediateDiagBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID) |
1635 | : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) {} |
1636 | ImmediateDiagBuilder(DiagnosticBuilder &&DB, Sema &SemaRef, unsigned DiagID) |
1637 | : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) {} |
1638 | |
1639 | // This is a cunning lie. DiagnosticBuilder actually performs move |
1640 | // construction in its copy constructor (but due to varied uses, it's not |
1641 | // possible to conveniently express this as actual move construction). So |
1642 | // the default copy ctor here is fine, because the base class disables the |
1643 | // source anyway, so the user-defined ~ImmediateDiagBuilder is a safe no-op |
1644 | // in that case anwyay. |
1645 | ImmediateDiagBuilder(const ImmediateDiagBuilder &) = default; |
1646 | |
1647 | ~ImmediateDiagBuilder() { |
1648 | // If we aren't active, there is nothing to do. |
1649 | if (!isActive()) return; |
1650 | |
1651 | // Otherwise, we need to emit the diagnostic. First clear the diagnostic |
1652 | // builder itself so it won't emit the diagnostic in its own destructor. |
1653 | // |
1654 | // This seems wasteful, in that as written the DiagnosticBuilder dtor will |
1655 | // do its own needless checks to see if the diagnostic needs to be |
1656 | // emitted. However, because we take care to ensure that the builder |
1657 | // objects never escape, a sufficiently smart compiler will be able to |
1658 | // eliminate that code. |
1659 | Clear(); |
1660 | |
1661 | // Dispatch to Sema to emit the diagnostic. |
1662 | SemaRef.EmitCurrentDiagnostic(DiagID); |
1663 | } |
1664 | |
1665 | /// Teach operator<< to produce an object of the correct type. |
1666 | template <typename T> |
1667 | friend const ImmediateDiagBuilder & |
1668 | operator<<(const ImmediateDiagBuilder &Diag, const T &Value) { |
1669 | const DiagnosticBuilder &BaseDiag = Diag; |
1670 | BaseDiag << Value; |
1671 | return Diag; |
1672 | } |
1673 | |
1674 | // It is necessary to limit this to rvalue reference to avoid calling this |
1675 | // function with a bitfield lvalue argument since non-const reference to |
1676 | // bitfield is not allowed. |
1677 | template <typename T, typename = typename std::enable_if< |
1678 | !std::is_lvalue_reference<T>::value>::type> |
1679 | const ImmediateDiagBuilder &operator<<(T &&V) const { |
1680 | const DiagnosticBuilder &BaseDiag = *this; |
1681 | BaseDiag << std::move(V); |
1682 | return *this; |
1683 | } |
1684 | }; |
1685 | |
1686 | /// A generic diagnostic builder for errors which may or may not be deferred. |
1687 | /// |
1688 | /// In CUDA, there exist constructs (e.g. variable-length arrays, try/catch) |
1689 | /// which are not allowed to appear inside __device__ functions and are |
1690 | /// allowed to appear in __host__ __device__ functions only if the host+device |
1691 | /// function is never codegen'ed. |
1692 | /// |
1693 | /// To handle this, we use the notion of "deferred diagnostics", where we |
1694 | /// attach a diagnostic to a FunctionDecl that's emitted iff it's codegen'ed. |
1695 | /// |
1696 | /// This class lets you emit either a regular diagnostic, a deferred |
1697 | /// diagnostic, or no diagnostic at all, according to an argument you pass to |
1698 | /// its constructor, thus simplifying the process of creating these "maybe |
1699 | /// deferred" diagnostics. |
1700 | class SemaDiagnosticBuilder { |
1701 | public: |
1702 | enum Kind { |
1703 | /// Emit no diagnostics. |
1704 | K_Nop, |
1705 | /// Emit the diagnostic immediately (i.e., behave like Sema::Diag()). |
1706 | K_Immediate, |
1707 | /// Emit the diagnostic immediately, and, if it's a warning or error, also |
1708 | /// emit a call stack showing how this function can be reached by an a |
1709 | /// priori known-emitted function. |
1710 | K_ImmediateWithCallStack, |
1711 | /// Create a deferred diagnostic, which is emitted only if the function |
1712 | /// it's attached to is codegen'ed. Also emit a call stack as with |
1713 | /// K_ImmediateWithCallStack. |
1714 | K_Deferred |
1715 | }; |
1716 | |
1717 | SemaDiagnosticBuilder(Kind K, SourceLocation Loc, unsigned DiagID, |
1718 | FunctionDecl *Fn, Sema &S); |
1719 | SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D); |
1720 | SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default; |
1721 | ~SemaDiagnosticBuilder(); |
1722 | |
1723 | bool isImmediate() const { return ImmediateDiag.hasValue(); } |
1724 | |
1725 | /// Convertible to bool: True if we immediately emitted an error, false if |
1726 | /// we didn't emit an error or we created a deferred error. |
1727 | /// |
1728 | /// Example usage: |
1729 | /// |
1730 | /// if (SemaDiagnosticBuilder(...) << foo << bar) |
1731 | /// return ExprError(); |
1732 | /// |
1733 | /// But see CUDADiagIfDeviceCode() and CUDADiagIfHostCode() -- you probably |
1734 | /// want to use these instead of creating a SemaDiagnosticBuilder yourself. |
1735 | operator bool() const { return isImmediate(); } |
1736 | |
1737 | template <typename T> |
1738 | friend const SemaDiagnosticBuilder & |
1739 | operator<<(const SemaDiagnosticBuilder &Diag, const T &Value) { |
1740 | if (Diag.ImmediateDiag.hasValue()) |
1741 | *Diag.ImmediateDiag << Value; |
1742 | else if (Diag.PartialDiagId.hasValue()) |
1743 | Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second |
1744 | << Value; |
1745 | return Diag; |
1746 | } |
1747 | |
1748 | // It is necessary to limit this to rvalue reference to avoid calling this |
1749 | // function with a bitfield lvalue argument since non-const reference to |
1750 | // bitfield is not allowed. |
1751 | template <typename T, typename = typename std::enable_if< |
1752 | !std::is_lvalue_reference<T>::value>::type> |
1753 | const SemaDiagnosticBuilder &operator<<(T &&V) const { |
1754 | if (ImmediateDiag.hasValue()) |
1755 | *ImmediateDiag << std::move(V); |
1756 | else if (PartialDiagId.hasValue()) |
1757 | S.DeviceDeferredDiags[Fn][*PartialDiagId].second << std::move(V); |
1758 | return *this; |
1759 | } |
1760 | |
1761 | friend const SemaDiagnosticBuilder & |
1762 | operator<<(const SemaDiagnosticBuilder &Diag, const PartialDiagnostic &PD) { |
1763 | if (Diag.ImmediateDiag.hasValue()) |
1764 | PD.Emit(*Diag.ImmediateDiag); |
1765 | else if (Diag.PartialDiagId.hasValue()) |
1766 | Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second = PD; |
1767 | return Diag; |
1768 | } |
1769 | |
1770 | void AddFixItHint(const FixItHint &Hint) const { |
1771 | if (ImmediateDiag.hasValue()) |
1772 | ImmediateDiag->AddFixItHint(Hint); |
1773 | else if (PartialDiagId.hasValue()) |
1774 | S.DeviceDeferredDiags[Fn][*PartialDiagId].second.AddFixItHint(Hint); |
1775 | } |
1776 | |
1777 | friend ExprResult ExprError(const SemaDiagnosticBuilder &) { |
1778 | return ExprError(); |
1779 | } |
1780 | friend StmtResult StmtError(const SemaDiagnosticBuilder &) { |
1781 | return StmtError(); |
1782 | } |
1783 | operator ExprResult() const { return ExprError(); } |
1784 | operator StmtResult() const { return StmtError(); } |
1785 | operator TypeResult() const { return TypeError(); } |
1786 | operator DeclResult() const { return DeclResult(true); } |
1787 | operator MemInitResult() const { return MemInitResult(true); } |
1788 | |
1789 | private: |
1790 | Sema &S; |
1791 | SourceLocation Loc; |
1792 | unsigned DiagID; |
1793 | FunctionDecl *Fn; |
1794 | bool ShowCallStack; |
1795 | |
1796 | // Invariant: At most one of these Optionals has a value. |
1797 | // FIXME: Switch these to a Variant once that exists. |
1798 | llvm::Optional<ImmediateDiagBuilder> ImmediateDiag; |
1799 | llvm::Optional<unsigned> PartialDiagId; |
1800 | }; |
1801 | |
1802 | /// Is the last error level diagnostic immediate. This is used to determined |
1803 | /// whether the next info diagnostic should be immediate. |
1804 | bool IsLastErrorImmediate = true; |
1805 | |
1806 | /// Emit a diagnostic. |
1807 | SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, |
1808 | bool DeferHint = false); |
1809 | |
1810 | /// Emit a partial diagnostic. |
1811 | SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD, |
1812 | bool DeferHint = false); |
1813 | |
1814 | /// Build a partial diagnostic. |
1815 | PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h |
1816 | |
1817 | /// Whether deferrable diagnostics should be deferred. |
1818 | bool DeferDiags = false; |
1819 | |
1820 | /// RAII class to control scope of DeferDiags. |
1821 | class DeferDiagsRAII { |
1822 | Sema &S; |
1823 | bool SavedDeferDiags = false; |
1824 | |
1825 | public: |
1826 | DeferDiagsRAII(Sema &S, bool DeferDiags) |
1827 | : S(S), SavedDeferDiags(S.DeferDiags) { |
1828 | S.DeferDiags = DeferDiags; |
1829 | } |
1830 | ~DeferDiagsRAII() { S.DeferDiags = SavedDeferDiags; } |
1831 | }; |
1832 | |
1833 | /// Whether uncompilable error has occurred. This includes error happens |
1834 | /// in deferred diagnostics. |
1835 | bool hasUncompilableErrorOccurred() const; |
1836 | |
1837 | bool findMacroSpelling(SourceLocation &loc, StringRef name); |
1838 | |
1839 | /// Get a string to suggest for zero-initialization of a type. |
1840 | std::string |
1841 | getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const; |
1842 | std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const; |
1843 | |
1844 | /// Calls \c Lexer::getLocForEndOfToken() |
1845 | SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0); |
1846 | |
1847 | /// Retrieve the module loader associated with the preprocessor. |
1848 | ModuleLoader &getModuleLoader() const; |
1849 | |
1850 | /// Invent a new identifier for parameters of abbreviated templates. |
1851 | IdentifierInfo * |
1852 | InventAbbreviatedTemplateParameterTypeName(IdentifierInfo *ParamName, |
1853 | unsigned Index); |
1854 | |
1855 | void emitAndClearUnusedLocalTypedefWarnings(); |
1856 | |
1857 | private: |
1858 | /// Function or variable declarations to be checked for whether the deferred |
1859 | /// diagnostics should be emitted. |
1860 | llvm::SmallSetVector<Decl *, 4> DeclsToCheckForDeferredDiags; |
1861 | |
1862 | public: |
1863 | // Emit all deferred diagnostics. |
1864 | void emitDeferredDiags(); |
1865 | |
1866 | enum TUFragmentKind { |
1867 | /// The global module fragment, between 'module;' and a module-declaration. |
1868 | Global, |
1869 | /// A normal translation unit fragment. For a non-module unit, this is the |
1870 | /// entire translation unit. Otherwise, it runs from the module-declaration |
1871 | /// to the private-module-fragment (if any) or the end of the TU (if not). |
1872 | Normal, |
1873 | /// The private module fragment, between 'module :private;' and the end of |
1874 | /// the translation unit. |
1875 | Private |
1876 | }; |
1877 | |
1878 | void ActOnStartOfTranslationUnit(); |
1879 | void ActOnEndOfTranslationUnit(); |
1880 | void ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind); |
1881 | |
1882 | void CheckDelegatingCtorCycles(); |
1883 | |
1884 | Scope *getScopeForContext(DeclContext *Ctx); |
1885 | |
1886 | void PushFunctionScope(); |
1887 | void PushBlockScope(Scope *BlockScope, BlockDecl *Block); |
1888 | sema::LambdaScopeInfo *PushLambdaScope(); |
1889 | |
1890 | /// This is used to inform Sema what the current TemplateParameterDepth |
1891 | /// is during Parsing. Currently it is used to pass on the depth |
1892 | /// when parsing generic lambda 'auto' parameters. |
1893 | void RecordParsingTemplateParameterDepth(unsigned Depth); |
1894 | |
1895 | void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD, |
1896 | RecordDecl *RD, CapturedRegionKind K, |
1897 | unsigned OpenMPCaptureLevel = 0); |
1898 | |
1899 | /// Custom deleter to allow FunctionScopeInfos to be kept alive for a short |
1900 | /// time after they've been popped. |
1901 | class PoppedFunctionScopeDeleter { |
1902 | Sema *Self; |
1903 | |
1904 | public: |
1905 | explicit PoppedFunctionScopeDeleter(Sema *Self) : Self(Self) {} |
1906 | void operator()(sema::FunctionScopeInfo *Scope) const; |
1907 | }; |
1908 | |
1909 | using PoppedFunctionScopePtr = |
1910 | std::unique_ptr<sema::FunctionScopeInfo, PoppedFunctionScopeDeleter>; |
1911 | |
1912 | PoppedFunctionScopePtr |
1913 | PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr, |
1914 | const Decl *D = nullptr, |
1915 | QualType BlockType = QualType()); |
1916 | |
1917 | sema::FunctionScopeInfo *getCurFunction() const { |
1918 | return FunctionScopes.empty() ? nullptr : FunctionScopes.back(); |
1919 | } |
1920 | |
1921 | sema::FunctionScopeInfo *getEnclosingFunction() const; |
1922 | |
1923 | void setFunctionHasBranchIntoScope(); |
1924 | void setFunctionHasBranchProtectedScope(); |
1925 | void setFunctionHasIndirectGoto(); |
1926 | void setFunctionHasMustTail(); |
1927 | |
1928 | void PushCompoundScope(bool IsStmtExpr); |
1929 | void PopCompoundScope(); |
1930 | |
1931 | sema::CompoundScopeInfo &getCurCompoundScope() const; |
1932 | |
1933 | bool hasAnyUnrecoverableErrorsInThisFunction() const; |
1934 | |
1935 | /// Retrieve the current block, if any. |
1936 | sema::BlockScopeInfo *getCurBlock(); |
1937 | |
1938 | /// Get the innermost lambda enclosing the current location, if any. This |
1939 | /// looks through intervening non-lambda scopes such as local functions and |
1940 | /// blocks. |
1941 | sema::LambdaScopeInfo *getEnclosingLambda() const; |
1942 | |
1943 | /// Retrieve the current lambda scope info, if any. |
1944 | /// \param IgnoreNonLambdaCapturingScope true if should find the top-most |
1945 | /// lambda scope info ignoring all inner capturing scopes that are not |
1946 | /// lambda scopes. |
1947 | sema::LambdaScopeInfo * |
1948 | getCurLambda(bool IgnoreNonLambdaCapturingScope = false); |
1949 | |
1950 | /// Retrieve the current generic lambda info, if any. |
1951 | sema::LambdaScopeInfo *getCurGenericLambda(); |
1952 | |
1953 | /// Retrieve the current captured region, if any. |
1954 | sema::CapturedRegionScopeInfo *getCurCapturedRegion(); |
1955 | |
1956 | /// Retrieve the current function, if any, that should be analyzed for |
1957 | /// potential availability violations. |
1958 | sema::FunctionScopeInfo *getCurFunctionAvailabilityContext(); |
1959 | |
1960 | /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls |
1961 | SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; } |
1962 | |
1963 | /// Called before parsing a function declarator belonging to a function |
1964 | /// declaration. |
1965 | void ActOnStartFunctionDeclarationDeclarator(Declarator &D, |
1966 | unsigned TemplateParameterDepth); |
1967 | |
1968 | /// Called after parsing a function declarator belonging to a function |
1969 | /// declaration. |
1970 | void ActOnFinishFunctionDeclarationDeclarator(Declarator &D); |
1971 | |
1972 | void ActOnComment(SourceRange Comment); |
1973 | |
1974 | //===--------------------------------------------------------------------===// |
1975 | // Type Analysis / Processing: SemaType.cpp. |
1976 | // |
1977 | |
1978 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, |
1979 | const DeclSpec *DS = nullptr); |
1980 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA, |
1981 | const DeclSpec *DS = nullptr); |
1982 | QualType BuildPointerType(QualType T, |
1983 | SourceLocation Loc, DeclarationName Entity); |
1984 | QualType BuildReferenceType(QualType T, bool LValueRef, |
1985 | SourceLocation Loc, DeclarationName Entity); |
1986 | QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, |
1987 | Expr *ArraySize, unsigned Quals, |
1988 | SourceRange Brackets, DeclarationName Entity); |
1989 | QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc); |
1990 | QualType BuildExtVectorType(QualType T, Expr *ArraySize, |
1991 | SourceLocation AttrLoc); |
1992 | QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, |
1993 | SourceLocation AttrLoc); |
1994 | |
1995 | QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace, |
1996 | SourceLocation AttrLoc); |
1997 | |
1998 | /// Same as above, but constructs the AddressSpace index if not provided. |
1999 | QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace, |
2000 | SourceLocation AttrLoc); |
2001 | |
2002 | bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc); |
2003 | |
2004 | bool CheckFunctionReturnType(QualType T, SourceLocation Loc); |
2005 | |
2006 | /// Build a function type. |
2007 | /// |
2008 | /// This routine checks the function type according to C++ rules and |
2009 | /// under the assumption that the result type and parameter types have |
2010 | /// just been instantiated from a template. It therefore duplicates |
2011 | /// some of the behavior of GetTypeForDeclarator, but in a much |
2012 | /// simpler form that is only suitable for this narrow use case. |
2013 | /// |
2014 | /// \param T The return type of the function. |
2015 | /// |
2016 | /// \param ParamTypes The parameter types of the function. This array |
2017 | /// will be modified to account for adjustments to the types of the |
2018 | /// function parameters. |
2019 | /// |
2020 | /// \param Loc The location of the entity whose type involves this |
2021 | /// function type or, if there is no such entity, the location of the |
2022 | /// type that will have function type. |
2023 | /// |
2024 | /// \param Entity The name of the entity that involves the function |
2025 | /// type, if known. |
2026 | /// |
2027 | /// \param EPI Extra information about the function type. Usually this will |
2028 | /// be taken from an existing function with the same prototype. |
2029 | /// |
2030 | /// \returns A suitable function type, if there are no errors. The |
2031 | /// unqualified type will always be a FunctionProtoType. |
2032 | /// Otherwise, returns a NULL type. |
2033 | QualType BuildFunctionType(QualType T, |
2034 | MutableArrayRef<QualType> ParamTypes, |
2035 | SourceLocation Loc, DeclarationName Entity, |
2036 | const FunctionProtoType::ExtProtoInfo &EPI); |
2037 | |
2038 | QualType BuildMemberPointerType(QualType T, QualType Class, |
2039 | SourceLocation Loc, |
2040 | DeclarationName Entity); |
2041 | QualType BuildBlockPointerType(QualType T, |
2042 | SourceLocation Loc, DeclarationName Entity); |
2043 | QualType BuildParenType(QualType T); |
2044 | QualType BuildAtomicType(QualType T, SourceLocation Loc); |
2045 | QualType BuildReadPipeType(QualType T, |
2046 | SourceLocation Loc); |
2047 | QualType BuildWritePipeType(QualType T, |
2048 | SourceLocation Loc); |
2049 | QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc); |
2050 | |
2051 | TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S); |
2052 | TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy); |
2053 | |
2054 | /// Package the given type and TSI into a ParsedType. |
2055 | ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo); |
2056 | DeclarationNameInfo GetNameForDeclarator(Declarator &D); |
2057 | DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name); |
2058 | static QualType GetTypeFromParser(ParsedType Ty, |
2059 | TypeSourceInfo **TInfo = nullptr); |
2060 | CanThrowResult canThrow(const Stmt *E); |
2061 | /// Determine whether the callee of a particular function call can throw. |
2062 | /// E, D and Loc are all optional. |
2063 | static CanThrowResult canCalleeThrow(Sema &S, const Expr *E, const Decl *D, |
2064 | SourceLocation Loc = SourceLocation()); |
2065 | const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc, |
2066 | const FunctionProtoType *FPT); |
2067 | void UpdateExceptionSpec(FunctionDecl *FD, |
2068 | const FunctionProtoType::ExceptionSpecInfo &ESI); |
2069 | bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range); |
2070 | bool CheckDistantExceptionSpec(QualType T); |
2071 | bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New); |
2072 | bool CheckEquivalentExceptionSpec( |
2073 | const FunctionProtoType *Old, SourceLocation OldLoc, |
2074 | const FunctionProtoType *New, SourceLocation NewLoc); |
2075 | bool CheckEquivalentExceptionSpec( |
2076 | const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, |
2077 | const FunctionProtoType *Old, SourceLocation OldLoc, |
2078 | const FunctionProtoType *New, SourceLocation NewLoc); |
2079 | bool handlerCanCatch(QualType HandlerType, QualType ExceptionType); |
2080 | bool CheckExceptionSpecSubset(const PartialDiagnostic &DiagID, |
2081 | const PartialDiagnostic &NestedDiagID, |
2082 | const PartialDiagnostic &NoteID, |
2083 | const PartialDiagnostic &NoThrowDiagID, |
2084 | const FunctionProtoType *Superset, |
2085 | SourceLocation SuperLoc, |
2086 | const FunctionProtoType *Subset, |
2087 | SourceLocation SubLoc); |
2088 | bool CheckParamExceptionSpec(const PartialDiagnostic &NestedDiagID, |
2089 | const PartialDiagnostic &NoteID, |
2090 | const FunctionProtoType *Target, |
2091 | SourceLocation TargetLoc, |
2092 | const FunctionProtoType *Source, |
2093 | SourceLocation SourceLoc); |
2094 | |
2095 | TypeResult ActOnTypeName(Scope *S, Declarator &D); |
2096 | |
2097 | /// The parser has parsed the context-sensitive type 'instancetype' |
2098 | /// in an Objective-C message declaration. Return the appropriate type. |
2099 | ParsedType ActOnObjCInstanceType(SourceLocation Loc); |
2100 | |
2101 | /// Abstract class used to diagnose incomplete types. |
2102 | struct TypeDiagnoser { |
2103 | TypeDiagnoser() {} |
2104 | |
2105 | virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0; |
2106 | virtual ~TypeDiagnoser() {} |
2107 | }; |
2108 | |
2109 | static int getPrintable(int I) { return I; } |
2110 | static unsigned getPrintable(unsigned I) { return I; } |
2111 | static bool getPrintable(bool B) { return B; } |
2112 | static const char * getPrintable(const char *S) { return S; } |
2113 | static StringRef getPrintable(StringRef S) { return S; } |
2114 | static const std::string &getPrintable(const std::string &S) { return S; } |
2115 | static const IdentifierInfo *getPrintable(const IdentifierInfo *II) { |
2116 | return II; |
2117 | } |
2118 | static DeclarationName getPrintable(DeclarationName N) { return N; } |
2119 | static QualType getPrintable(QualType T) { return T; } |
2120 | static SourceRange getPrintable(SourceRange R) { return R; } |
2121 | static SourceRange getPrintable(SourceLocation L) { return L; } |
2122 | static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); } |
2123 | static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();} |
2124 | |
2125 | template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser { |
2126 | protected: |
2127 | unsigned DiagID; |
2128 | std::tuple<const Ts &...> Args; |
2129 | |
2130 | template <std::size_t... Is> |
2131 | void emit(const SemaDiagnosticBuilder &DB, |
2132 | std::index_sequence<Is...>) const { |
2133 | // Apply all tuple elements to the builder in order. |
2134 | bool Dummy[] = {false, (DB << getPrintable(std::get<Is>(Args)))...}; |
2135 | (void)Dummy; |
2136 | } |
2137 | |
2138 | public: |
2139 | BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args) |
2140 | : TypeDiagnoser(), DiagID(DiagID), Args(Args...) { |
2141 | assert(DiagID != 0 && "no diagnostic for type diagnoser")(static_cast <bool> (DiagID != 0 && "no diagnostic for type diagnoser" ) ? void (0) : __assert_fail ("DiagID != 0 && \"no diagnostic for type diagnoser\"" , "clang/include/clang/Sema/Sema.h", 2141, __extension__ __PRETTY_FUNCTION__ )); |
2142 | } |
2143 | |
2144 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
2145 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID); |
2146 | emit(DB, std::index_sequence_for<Ts...>()); |
2147 | DB << T; |
2148 | } |
2149 | }; |
2150 | |
2151 | /// Do a check to make sure \p Name looks like a legal argument for the |
2152 | /// swift_name attribute applied to decl \p D. Raise a diagnostic if the name |
2153 | /// is invalid for the given declaration. |
2154 | /// |
2155 | /// \p AL is used to provide caret diagnostics in case of a malformed name. |
2156 | /// |
2157 | /// \returns true if the name is a valid swift name for \p D, false otherwise. |
2158 | bool DiagnoseSwiftName(Decl *D, StringRef Name, SourceLocation Loc, |
2159 | const ParsedAttr &AL, bool IsAsync); |
2160 | |
2161 | /// A derivative of BoundTypeDiagnoser for which the diagnostic's type |
2162 | /// parameter is preceded by a 0/1 enum that is 1 if the type is sizeless. |
2163 | /// For example, a diagnostic with no other parameters would generally have |
2164 | /// the form "...%select{incomplete|sizeless}0 type %1...". |
2165 | template <typename... Ts> |
2166 | class SizelessTypeDiagnoser : public BoundTypeDiagnoser<Ts...> { |
2167 | public: |
2168 | SizelessTypeDiagnoser(unsigned DiagID, const Ts &... Args) |
2169 | : BoundTypeDiagnoser<Ts...>(DiagID, Args...) {} |
2170 | |
2171 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
2172 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, this->DiagID); |
2173 | this->emit(DB, std::index_sequence_for<Ts...>()); |
2174 | DB << T->isSizelessType() << T; |
2175 | } |
2176 | }; |
2177 | |
2178 | enum class CompleteTypeKind { |
2179 | /// Apply the normal rules for complete types. In particular, |
2180 | /// treat all sizeless types as incomplete. |
2181 | Normal, |
2182 | |
2183 | /// Relax the normal rules for complete types so that they include |
2184 | /// sizeless built-in types. |
2185 | AcceptSizeless, |
2186 | |
2187 | // FIXME: Eventually we should flip the default to Normal and opt in |
2188 | // to AcceptSizeless rather than opt out of it. |
2189 | Default = AcceptSizeless |
2190 | }; |
2191 | |
2192 | private: |
2193 | /// Methods for marking which expressions involve dereferencing a pointer |
2194 | /// marked with the 'noderef' attribute. Expressions are checked bottom up as |
2195 | /// they are parsed, meaning that a noderef pointer may not be accessed. For |
2196 | /// example, in `&*p` where `p` is a noderef pointer, we will first parse the |
2197 | /// `*p`, but need to check that `address of` is called on it. This requires |
2198 | /// keeping a container of all pending expressions and checking if the address |
2199 | /// of them are eventually taken. |
2200 | void CheckSubscriptAccessOfNoDeref(const ArraySubscriptExpr *E); |
2201 | void CheckAddressOfNoDeref(const Expr *E); |
2202 | void CheckMemberAccessOfNoDeref(const MemberExpr *E); |
2203 | |
2204 | bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T, |
2205 | CompleteTypeKind Kind, TypeDiagnoser *Diagnoser); |
2206 | |
2207 | struct ModuleScope { |
2208 | SourceLocation BeginLoc; |
2209 | clang::Module *Module = nullptr; |
2210 | bool ModuleInterface = false; |
2211 | bool ImplicitGlobalModuleFragment = false; |
2212 | VisibleModuleSet OuterVisibleModules; |
2213 | }; |
2214 | /// The modules we're currently parsing. |
2215 | llvm::SmallVector<ModuleScope, 16> ModuleScopes; |
2216 | |
2217 | /// Namespace definitions that we will export when they finish. |
2218 | llvm::SmallPtrSet<const NamespaceDecl*, 8> DeferredExportedNamespaces; |
2219 | |
2220 | /// Get the module whose scope we are currently within. |
2221 | Module *getCurrentModule() const { |
2222 | return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module; |
2223 | } |
2224 | |
2225 | /// Helper function to judge if we are in module purview. |
2226 | /// Return false if we are not in a module. |
2227 | bool isCurrentModulePurview() const { |
2228 | return getCurrentModule() ? getCurrentModule()->isModulePurview() : false; |
2229 | } |
2230 | |
2231 | /// Enter the scope of the global module. |
2232 | Module *PushGlobalModuleFragment(SourceLocation BeginLoc, bool IsImplicit); |
2233 | /// Leave the scope of the global module. |
2234 | void PopGlobalModuleFragment(); |
2235 | |
2236 | VisibleModuleSet VisibleModules; |
2237 | |
2238 | public: |
2239 | /// Get the module owning an entity. |
2240 | Module *getOwningModule(const Decl *Entity) { |
2241 | return Entity->getOwningModule(); |
2242 | } |
2243 | |
2244 | /// Make a merged definition of an existing hidden definition \p ND |
2245 | /// visible at the specified location. |
2246 | void makeMergedDefinitionVisible(NamedDecl *ND); |
2247 | |
2248 | bool isModuleVisible(const Module *M, bool ModulePrivate = false); |
2249 | |
2250 | // When loading a non-modular PCH files, this is used to restore module |
2251 | // visibility. |
2252 | void makeModuleVisible(Module *Mod, SourceLocation ImportLoc) { |
2253 | VisibleModules.setVisible(Mod, ImportLoc); |
2254 | } |
2255 | |
2256 | /// Determine whether a declaration is visible to name lookup. |
2257 | bool isVisible(const NamedDecl *D) { |
2258 | return D->isUnconditionallyVisible() || isVisibleSlow(D); |
2259 | } |
2260 | |
2261 | /// Determine whether any declaration of an entity is visible. |
2262 | bool |
2263 | hasVisibleDeclaration(const NamedDecl *D, |
2264 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
2265 | return isVisible(D) || hasVisibleDeclarationSlow(D, Modules); |
2266 | } |
2267 | bool hasVisibleDeclarationSlow(const NamedDecl *D, |
2268 | llvm::SmallVectorImpl<Module *> *Modules); |
2269 | |
2270 | bool hasVisibleMergedDefinition(NamedDecl *Def); |
2271 | bool hasMergedDefinitionInCurrentModule(NamedDecl *Def); |
2272 | |
2273 | /// Determine if \p D and \p Suggested have a structurally compatible |
2274 | /// layout as described in C11 6.2.7/1. |
2275 | bool hasStructuralCompatLayout(Decl *D, Decl *Suggested); |
2276 | |
2277 | /// Determine if \p D has a visible definition. If not, suggest a declaration |
2278 | /// that should be made visible to expose the definition. |
2279 | bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, |
2280 | bool OnlyNeedComplete = false); |
2281 | bool hasVisibleDefinition(const NamedDecl *D) { |
2282 | NamedDecl *Hidden; |
2283 | return hasVisibleDefinition(const_cast<NamedDecl*>(D), &Hidden); |
2284 | } |
2285 | |
2286 | /// Determine if the template parameter \p D has a visible default argument. |
2287 | bool |
2288 | hasVisibleDefaultArgument(const NamedDecl *D, |
2289 | llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2290 | |
2291 | /// Determine if there is a visible declaration of \p D that is an explicit |
2292 | /// specialization declaration for a specialization of a template. (For a |
2293 | /// member specialization, use hasVisibleMemberSpecialization.) |
2294 | bool hasVisibleExplicitSpecialization( |
2295 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2296 | |
2297 | /// Determine if there is a visible declaration of \p D that is a member |
2298 | /// specialization declaration (as opposed to an instantiated declaration). |
2299 | bool hasVisibleMemberSpecialization( |
2300 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2301 | |
2302 | /// Determine if \p A and \p B are equivalent internal linkage declarations |
2303 | /// from different modules, and thus an ambiguity error can be downgraded to |
2304 | /// an extension warning. |
2305 | bool isEquivalentInternalLinkageDeclaration(const NamedDecl *A, |
2306 | const NamedDecl *B); |
2307 | void diagnoseEquivalentInternalLinkageDeclarations( |
2308 | SourceLocation Loc, const NamedDecl *D, |
2309 | ArrayRef<const NamedDecl *> Equiv); |
2310 | |
2311 | bool isUsualDeallocationFunction(const CXXMethodDecl *FD); |
2312 | |
2313 | bool isCompleteType(SourceLocation Loc, QualType T, |
2314 | CompleteTypeKind Kind = CompleteTypeKind::Default) { |
2315 | return !RequireCompleteTypeImpl(Loc, T, Kind, nullptr); |
2316 | } |
2317 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
2318 | CompleteTypeKind Kind, TypeDiagnoser &Diagnoser); |
2319 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
2320 | CompleteTypeKind Kind, unsigned DiagID); |
2321 | |
2322 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
2323 | TypeDiagnoser &Diagnoser) { |
2324 | return RequireCompleteType(Loc, T, CompleteTypeKind::Default, Diagnoser); |
2325 | } |
2326 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID) { |
2327 | return RequireCompleteType(Loc, T, CompleteTypeKind::Default, DiagID); |
2328 | } |
2329 | |
2330 | template <typename... Ts> |
2331 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID, |
2332 | const Ts &...Args) { |
2333 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2334 | return RequireCompleteType(Loc, T, Diagnoser); |
2335 | } |
2336 | |
2337 | template <typename... Ts> |
2338 | bool RequireCompleteSizedType(SourceLocation Loc, QualType T, unsigned DiagID, |
2339 | const Ts &... Args) { |
2340 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2341 | return RequireCompleteType(Loc, T, CompleteTypeKind::Normal, Diagnoser); |
2342 | } |
2343 | |
2344 | /// Get the type of expression E, triggering instantiation to complete the |
2345 | /// type if necessary -- that is, if the expression refers to a templated |
2346 | /// static data member of incomplete array type. |
2347 | /// |
2348 | /// May still return an incomplete type if instantiation was not possible or |
2349 | /// if the type is incomplete for a different reason. Use |
2350 | /// RequireCompleteExprType instead if a diagnostic is expected for an |
2351 | /// incomplete expression type. |
2352 | QualType getCompletedType(Expr *E); |
2353 | |
2354 | void completeExprArrayBound(Expr *E); |
2355 | bool RequireCompleteExprType(Expr *E, CompleteTypeKind Kind, |
2356 | TypeDiagnoser &Diagnoser); |
2357 | bool RequireCompleteExprType(Expr *E, unsigned DiagID); |
2358 | |
2359 | template <typename... Ts> |
2360 | bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) { |
2361 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2362 | return RequireCompleteExprType(E, CompleteTypeKind::Default, Diagnoser); |
2363 | } |
2364 | |
2365 | template <typename... Ts> |
2366 | bool RequireCompleteSizedExprType(Expr *E, unsigned DiagID, |
2367 | const Ts &... Args) { |
2368 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2369 | return RequireCompleteExprType(E, CompleteTypeKind::Normal, Diagnoser); |
2370 | } |
2371 | |
2372 | bool RequireLiteralType(SourceLocation Loc, QualType T, |
2373 | TypeDiagnoser &Diagnoser); |
2374 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID); |
2375 | |
2376 | template <typename... Ts> |
2377 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID, |
2378 | const Ts &...Args) { |
2379 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2380 | return RequireLiteralType(Loc, T, Diagnoser); |
2381 | } |
2382 | |
2383 | QualType getElaboratedType(ElaboratedTypeKeyword Keyword, |
2384 | const CXXScopeSpec &SS, QualType T, |
2385 | TagDecl *OwnedTagDecl = nullptr); |
2386 | |
2387 | // Returns the underlying type of a decltype with the given expression. |
2388 | QualType getDecltypeForExpr(Expr *E); |
2389 | |
2390 | QualType BuildTypeofExprType(Expr *E); |
2391 | /// If AsUnevaluated is false, E is treated as though it were an evaluated |
2392 | /// context, such as when building a type for decltype(auto). |
2393 | QualType BuildDecltypeType(Expr *E, bool AsUnevaluated = true); |
2394 | QualType BuildUnaryTransformType(QualType BaseType, |
2395 | UnaryTransformType::UTTKind UKind, |
2396 | SourceLocation Loc); |
2397 | |
2398 | //===--------------------------------------------------------------------===// |
2399 | // Symbol table / Decl tracking callbacks: SemaDecl.cpp. |
2400 | // |
2401 | |
2402 | struct SkipBodyInfo { |
2403 | SkipBodyInfo() |
2404 | : ShouldSkip(false), CheckSameAsPrevious(false), Previous(nullptr), |
2405 | New(nullptr) {} |
2406 | bool ShouldSkip; |
2407 | bool CheckSameAsPrevious; |
2408 | NamedDecl *Previous; |
2409 | NamedDecl *New; |
2410 | }; |
2411 | |
2412 | DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr); |
2413 | |
2414 | void DiagnoseUseOfUnimplementedSelectors(); |
2415 | |
2416 | bool isSimpleTypeSpecifier(tok::TokenKind Kind) const; |
2417 | |
2418 | ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, |
2419 | Scope *S, CXXScopeSpec *SS = nullptr, |
2420 | bool isClassName = false, bool HasTrailingDot = false, |
2421 | ParsedType ObjectType = nullptr, |
2422 | bool IsCtorOrDtorName = false, |
2423 | bool WantNontrivialTypeSourceInfo = false, |
2424 | bool IsClassTemplateDeductionContext = true, |
2425 | IdentifierInfo **CorrectedII = nullptr); |
2426 | TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S); |
2427 | bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S); |
2428 | void DiagnoseUnknownTypeName(IdentifierInfo *&II, |
2429 | SourceLocation IILoc, |
2430 | Scope *S, |
2431 | CXXScopeSpec *SS, |
2432 | ParsedType &SuggestedType, |
2433 | bool IsTemplateName = false); |
2434 | |
2435 | /// Attempt to behave like MSVC in situations where lookup of an unqualified |
2436 | /// type name has failed in a dependent context. In these situations, we |
2437 | /// automatically form a DependentTypeName that will retry lookup in a related |
2438 | /// scope during instantiation. |
2439 | ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II, |
2440 | SourceLocation NameLoc, |
2441 | bool IsTemplateTypeArg); |
2442 | |
2443 | /// Describes the result of the name lookup and resolution performed |
2444 | /// by \c ClassifyName(). |
2445 | enum NameClassificationKind { |
2446 | /// This name is not a type or template in this context, but might be |
2447 | /// something else. |
2448 | NC_Unknown, |
2449 | /// Classification failed; an error has been produced. |
2450 | NC_Error, |
2451 | /// The name has been typo-corrected to a keyword. |
2452 | NC_Keyword, |
2453 | /// The name was classified as a type. |
2454 | NC_Type, |
2455 | /// The name was classified as a specific non-type, non-template |
2456 | /// declaration. ActOnNameClassifiedAsNonType should be called to |
2457 | /// convert the declaration to an expression. |
2458 | NC_NonType, |
2459 | /// The name was classified as an ADL-only function name. |
2460 | /// ActOnNameClassifiedAsUndeclaredNonType should be called to convert the |
2461 | /// result to an expression. |
2462 | NC_UndeclaredNonType, |
2463 | /// The name denotes a member of a dependent type that could not be |
2464 | /// resolved. ActOnNameClassifiedAsDependentNonType should be called to |
2465 | /// convert the result to an expression. |
2466 | NC_DependentNonType, |
2467 | /// The name was classified as an overload set, and an expression |
2468 | /// representing that overload set has been formed. |
2469 | /// ActOnNameClassifiedAsOverloadSet should be called to form a suitable |
2470 | /// expression referencing the overload set. |
2471 | NC_OverloadSet, |
2472 | /// The name was classified as a template whose specializations are types. |
2473 | NC_TypeTemplate, |
2474 | /// The name was classified as a variable template name. |
2475 | NC_VarTemplate, |
2476 | /// The name was classified as a function template name. |
2477 | NC_FunctionTemplate, |
2478 | /// The name was classified as an ADL-only function template name. |
2479 | NC_UndeclaredTemplate, |
2480 | /// The name was classified as a concept name. |
2481 | NC_Concept, |
2482 | }; |
2483 | |
2484 | class NameClassification { |
2485 | NameClassificationKind Kind; |
2486 | union { |
2487 | ExprResult Expr; |
2488 | NamedDecl *NonTypeDecl; |
2489 | TemplateName Template; |
2490 | ParsedType Type; |
2491 | }; |
2492 | |
2493 | explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {} |
2494 | |
2495 | public: |
2496 | NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {} |
2497 | |
2498 | NameClassification(const IdentifierInfo *Keyword) : Kind(NC_Keyword) {} |
2499 | |
2500 | static NameClassification Error() { |
2501 | return NameClassification(NC_Error); |
2502 | } |
2503 | |
2504 | static NameClassification Unknown() { |
2505 | return NameClassification(NC_Unknown); |
2506 | } |
2507 | |
2508 | static NameClassification OverloadSet(ExprResult E) { |
2509 | NameClassification Result(NC_OverloadSet); |
2510 | Result.Expr = E; |
2511 | return Result; |
2512 | } |
2513 | |
2514 | static NameClassification NonType(NamedDecl *D) { |
2515 | NameClassification Result(NC_NonType); |
2516 | Result.NonTypeDecl = D; |
2517 | return Result; |
2518 | } |
2519 | |
2520 | static NameClassification UndeclaredNonType() { |
2521 | return NameClassification(NC_UndeclaredNonType); |
2522 | } |
2523 | |
2524 | static NameClassification DependentNonType() { |
2525 | return NameClassification(NC_DependentNonType); |
2526 | } |
2527 | |
2528 | static NameClassification TypeTemplate(TemplateName Name) { |
2529 | NameClassification Result(NC_TypeTemplate); |
2530 | Result.Template = Name; |
2531 | return Result; |
2532 | } |
2533 | |
2534 | static NameClassification VarTemplate(TemplateName Name) { |
2535 | NameClassification Result(NC_VarTemplate); |
2536 | Result.Template = Name; |
2537 | return Result; |
2538 | } |
2539 | |
2540 | static NameClassification FunctionTemplate(TemplateName Name) { |
2541 | NameClassification Result(NC_FunctionTemplate); |
2542 | Result.Template = Name; |
2543 | return Result; |
2544 | } |
2545 | |
2546 | static NameClassification Concept(TemplateName Name) { |
2547 | NameClassification Result(NC_Concept); |
2548 | Result.Template = Name; |
2549 | return Result; |
2550 | } |
2551 | |
2552 | static NameClassification UndeclaredTemplate(TemplateName Name) { |
2553 | NameClassification Result(NC_UndeclaredTemplate); |
2554 | Result.Template = Name; |
2555 | return Result; |
2556 | } |
2557 | |
2558 | NameClassificationKind getKind() const { return Kind; } |
2559 | |
2560 | ExprResult getExpression() const { |
2561 | assert(Kind == NC_OverloadSet)(static_cast <bool> (Kind == NC_OverloadSet) ? void (0) : __assert_fail ("Kind == NC_OverloadSet", "clang/include/clang/Sema/Sema.h" , 2561, __extension__ __PRETTY_FUNCTION__)); |
2562 | return Expr; |
2563 | } |
2564 | |
2565 | ParsedType getType() const { |
2566 | assert(Kind == NC_Type)(static_cast <bool> (Kind == NC_Type) ? void (0) : __assert_fail ("Kind == NC_Type", "clang/include/clang/Sema/Sema.h", 2566, __extension__ __PRETTY_FUNCTION__)); |
2567 | return Type; |
2568 | } |
2569 | |
2570 | NamedDecl *getNonTypeDecl() const { |
2571 | assert(Kind == NC_NonType)(static_cast <bool> (Kind == NC_NonType) ? void (0) : __assert_fail ("Kind == NC_NonType", "clang/include/clang/Sema/Sema.h", 2571 , __extension__ __PRETTY_FUNCTION__)); |
2572 | return NonTypeDecl; |
2573 | } |
2574 | |
2575 | TemplateName getTemplateName() const { |
2576 | assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate ||(static_cast <bool> (Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate) ? void (0) : __assert_fail ("Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate" , "clang/include/clang/Sema/Sema.h", 2578, __extension__ __PRETTY_FUNCTION__ )) |
2577 | Kind == NC_VarTemplate || Kind == NC_Concept ||(static_cast <bool> (Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate) ? void (0) : __assert_fail ("Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate" , "clang/include/clang/Sema/Sema.h", 2578, __extension__ __PRETTY_FUNCTION__ )) |
2578 | Kind == NC_UndeclaredTemplate)(static_cast <bool> (Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate) ? void (0) : __assert_fail ("Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate" , "clang/include/clang/Sema/Sema.h", 2578, __extension__ __PRETTY_FUNCTION__ )); |
2579 | return Template; |
2580 | } |
2581 | |
2582 | TemplateNameKind getTemplateNameKind() const { |
2583 | switch (Kind) { |
2584 | case NC_TypeTemplate: |
2585 | return TNK_Type_template; |
2586 | case NC_FunctionTemplate: |
2587 | return TNK_Function_template; |
2588 | case NC_VarTemplate: |
2589 | return TNK_Var_template; |
2590 | case NC_Concept: |
2591 | return TNK_Concept_template; |
2592 | case NC_UndeclaredTemplate: |
2593 | return TNK_Undeclared_template; |
2594 | default: |
2595 | llvm_unreachable("unsupported name classification.")::llvm::llvm_unreachable_internal("unsupported name classification." , "clang/include/clang/Sema/Sema.h", 2595); |
2596 | } |
2597 | } |
2598 | }; |
2599 | |
2600 | /// Perform name lookup on the given name, classifying it based on |
2601 | /// the results of name lookup and the following token. |
2602 | /// |
2603 | /// This routine is used by the parser to resolve identifiers and help direct |
2604 | /// parsing. When the identifier cannot be found, this routine will attempt |
2605 | /// to correct the typo and classify based on the resulting name. |
2606 | /// |
2607 | /// \param S The scope in which we're performing name lookup. |
2608 | /// |
2609 | /// \param SS The nested-name-specifier that precedes the name. |
2610 | /// |
2611 | /// \param Name The identifier. If typo correction finds an alternative name, |
2612 | /// this pointer parameter will be updated accordingly. |
2613 | /// |
2614 | /// \param NameLoc The location of the identifier. |
2615 | /// |
2616 | /// \param NextToken The token following the identifier. Used to help |
2617 | /// disambiguate the name. |
2618 | /// |
2619 | /// \param CCC The correction callback, if typo correction is desired. |
2620 | NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS, |
2621 | IdentifierInfo *&Name, SourceLocation NameLoc, |
2622 | const Token &NextToken, |
2623 | CorrectionCandidateCallback *CCC = nullptr); |
2624 | |
2625 | /// Act on the result of classifying a name as an undeclared (ADL-only) |
2626 | /// non-type declaration. |
2627 | ExprResult ActOnNameClassifiedAsUndeclaredNonType(IdentifierInfo *Name, |
2628 | SourceLocation NameLoc); |
2629 | /// Act on the result of classifying a name as an undeclared member of a |
2630 | /// dependent base class. |
2631 | ExprResult ActOnNameClassifiedAsDependentNonType(const CXXScopeSpec &SS, |
2632 | IdentifierInfo *Name, |
2633 | SourceLocation NameLoc, |
2634 | bool IsAddressOfOperand); |
2635 | /// Act on the result of classifying a name as a specific non-type |
2636 | /// declaration. |
2637 | ExprResult ActOnNameClassifiedAsNonType(Scope *S, const CXXScopeSpec &SS, |
2638 | NamedDecl *Found, |
2639 | SourceLocation NameLoc, |
2640 | const Token &NextToken); |
2641 | /// Act on the result of classifying a name as an overload set. |
2642 | ExprResult ActOnNameClassifiedAsOverloadSet(Scope *S, Expr *OverloadSet); |
2643 | |
2644 | /// Describes the detailed kind of a template name. Used in diagnostics. |
2645 | enum class TemplateNameKindForDiagnostics { |
2646 | ClassTemplate, |
2647 | FunctionTemplate, |
2648 | VarTemplate, |
2649 | AliasTemplate, |
2650 | TemplateTemplateParam, |
2651 | Concept, |
2652 | DependentTemplate |
2653 | }; |
2654 | TemplateNameKindForDiagnostics |
2655 | getTemplateNameKindForDiagnostics(TemplateName Name); |
2656 | |
2657 | /// Determine whether it's plausible that E was intended to be a |
2658 | /// template-name. |
2659 | bool mightBeIntendedToBeTemplateName(ExprResult E, bool &Dependent) { |
2660 | if (!getLangOpts().CPlusPlus || E.isInvalid()) |
2661 | return false; |
2662 | Dependent = false; |
2663 | if (auto *DRE = dyn_cast<DeclRefExpr>(E.get())) |
2664 | return !DRE->hasExplicitTemplateArgs(); |
2665 | if (auto *ME = dyn_cast<MemberExpr>(E.get())) |
2666 | return !ME->hasExplicitTemplateArgs(); |
2667 | Dependent = true; |
2668 | if (auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(E.get())) |
2669 | return !DSDRE->hasExplicitTemplateArgs(); |
2670 | if (auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(E.get())) |
2671 | return !DSME->hasExplicitTemplateArgs(); |
2672 | // Any additional cases recognized here should also be handled by |
2673 | // diagnoseExprIntendedAsTemplateName. |
2674 | return false; |
2675 | } |
2676 | void diagnoseExprIntendedAsTemplateName(Scope *S, ExprResult TemplateName, |
2677 | SourceLocation Less, |
2678 | SourceLocation Greater); |
2679 | |
2680 | void warnOnReservedIdentifier(const NamedDecl *D); |
2681 | |
2682 | Decl *ActOnDeclarator(Scope *S, Declarator &D); |
2683 | |
2684 | NamedDecl *HandleDeclarator(Scope *S, Declarator &D, |
2685 | MultiTemplateParamsArg TemplateParameterLists); |
2686 | bool tryToFixVariablyModifiedVarType(TypeSourceInfo *&TInfo, |
2687 | QualType &T, SourceLocation Loc, |
2688 | unsigned FailedFoldDiagID); |
2689 | void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S); |
2690 | bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info); |
2691 | bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, |
2692 | DeclarationName Name, SourceLocation Loc, |
2693 | bool IsTemplateId); |
2694 | void |
2695 | diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals, |
2696 | SourceLocation FallbackLoc, |
2697 | SourceLocation ConstQualLoc = SourceLocation(), |
2698 | SourceLocation VolatileQualLoc = SourceLocation(), |
2699 | SourceLocation RestrictQualLoc = SourceLocation(), |
2700 | SourceLocation AtomicQualLoc = SourceLocation(), |
2701 | SourceLocation UnalignedQualLoc = SourceLocation()); |
2702 | |
2703 | static bool adjustContextForLocalExternDecl(DeclContext *&DC); |
2704 | void DiagnoseFunctionSpecifiers(const DeclSpec &DS); |
2705 | NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D, |
2706 | const LookupResult &R); |
2707 | NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult &R); |
2708 | NamedDecl *getShadowedDeclaration(const BindingDecl *D, |
2709 | const LookupResult &R); |
2710 | void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl, |
2711 | const LookupResult &R); |
2712 | void CheckShadow(Scope *S, VarDecl *D); |
2713 | |
2714 | /// Warn if 'E', which is an expression that is about to be modified, refers |
2715 | /// to a shadowing declaration. |
2716 | void CheckShadowingDeclModification(Expr *E, SourceLocation Loc); |
2717 | |
2718 | void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI); |
2719 | |
2720 | private: |
2721 | /// Map of current shadowing declarations to shadowed declarations. Warn if |
2722 | /// it looks like the user is trying to modify the shadowing declaration. |
2723 | llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls; |
2724 | |
2725 | public: |
2726 | void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); |
2727 | void handleTagNumbering(const TagDecl *Tag, Scope *TagScope); |
2728 | void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec, |
2729 | TypedefNameDecl *NewTD); |
2730 | void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D); |
2731 | NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
2732 | TypeSourceInfo *TInfo, |
2733 | LookupResult &Previous); |
2734 | NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D, |
2735 | LookupResult &Previous, bool &Redeclaration); |
2736 | NamedDecl *ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, |
2737 | TypeSourceInfo *TInfo, |
2738 | LookupResult &Previous, |
2739 | MultiTemplateParamsArg TemplateParamLists, |
2740 | bool &AddToScope, |
2741 | ArrayRef<BindingDecl *> Bindings = None); |
2742 | NamedDecl * |
2743 | ActOnDecompositionDeclarator(Scope *S, Declarator &D, |
2744 | MultiTemplateParamsArg TemplateParamLists); |
2745 | // Returns true if the variable declaration is a redeclaration |
2746 | bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous); |
2747 | void CheckVariableDeclarationType(VarDecl *NewVD); |
2748 | bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit, |
2749 | Expr *Init); |
2750 | void CheckCompleteVariableDeclaration(VarDecl *VD); |
2751 | void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD); |
2752 | void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D); |
2753 | |
2754 | NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
2755 | TypeSourceInfo *TInfo, |
2756 | LookupResult &Previous, |
2757 | MultiTemplateParamsArg TemplateParamLists, |
2758 | bool &AddToScope); |
2759 | bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); |
2760 | |
2761 | enum class CheckConstexprKind { |
2762 | /// Diagnose issues that are non-constant or that are extensions. |
2763 | Diagnose, |
2764 | /// Identify whether this function satisfies the formal rules for constexpr |
2765 | /// functions in the current lanugage mode (with no extensions). |
2766 | CheckValid |
2767 | }; |
2768 | |
2769 | bool CheckConstexprFunctionDefinition(const FunctionDecl *FD, |
2770 | CheckConstexprKind Kind); |
2771 | |
2772 | void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD); |
2773 | void FindHiddenVirtualMethods(CXXMethodDecl *MD, |
2774 | SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods); |
2775 | void NoteHiddenVirtualMethods(CXXMethodDecl *MD, |
2776 | SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods); |
2777 | // Returns true if the function declaration is a redeclaration |
2778 | bool CheckFunctionDeclaration(Scope *S, |
2779 | FunctionDecl *NewFD, LookupResult &Previous, |
2780 | bool IsMemberSpecialization); |
2781 | bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl); |
2782 | bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD, |
2783 | QualType NewT, QualType OldT); |
2784 | void CheckMain(FunctionDecl *FD, const DeclSpec &D); |
2785 | void CheckMSVCRTEntryPoint(FunctionDecl *FD); |
2786 | Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, |
2787 | bool IsDefinition); |
2788 | void CheckFunctionOrTemplateParamDeclarator(Scope *S, Declarator &D); |
2789 | Decl *ActOnParamDeclarator(Scope *S, Declarator &D); |
2790 | ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, |
2791 | SourceLocation Loc, |
2792 | QualType T); |
2793 | ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc, |
2794 | SourceLocation NameLoc, IdentifierInfo *Name, |
2795 | QualType T, TypeSourceInfo *TSInfo, |
2796 | StorageClass SC); |
2797 | void ActOnParamDefaultArgument(Decl *param, |
2798 | SourceLocation EqualLoc, |
2799 | Expr *defarg); |
2800 | void ActOnParamUnparsedDefaultArgument(Decl *param, SourceLocation EqualLoc, |
2801 | SourceLocation ArgLoc); |
2802 | void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc); |
2803 | ExprResult ConvertParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
2804 | SourceLocation EqualLoc); |
2805 | void SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
2806 | SourceLocation EqualLoc); |
2807 | |
2808 | // Contexts where using non-trivial C union types can be disallowed. This is |
2809 | // passed to err_non_trivial_c_union_in_invalid_context. |
2810 | enum NonTrivialCUnionContext { |
2811 | // Function parameter. |
2812 | NTCUC_FunctionParam, |
2813 | // Function return. |
2814 | NTCUC_FunctionReturn, |
2815 | // Default-initialized object. |
2816 | NTCUC_DefaultInitializedObject, |
2817 | // Variable with automatic storage duration. |
2818 | NTCUC_AutoVar, |
2819 | // Initializer expression that might copy from another object. |
2820 | NTCUC_CopyInit, |
2821 | // Assignment. |
2822 | NTCUC_Assignment, |
2823 | // Compound literal. |
2824 | NTCUC_CompoundLiteral, |
2825 | // Block capture. |
2826 | NTCUC_BlockCapture, |
2827 | // lvalue-to-rvalue conversion of volatile type. |
2828 | NTCUC_LValueToRValueVolatile, |
2829 | }; |
2830 | |
2831 | /// Emit diagnostics if the initializer or any of its explicit or |
2832 | /// implicitly-generated subexpressions require copying or |
2833 | /// default-initializing a type that is or contains a C union type that is |
2834 | /// non-trivial to copy or default-initialize. |
2835 | void checkNonTrivialCUnionInInitializer(const Expr *Init, SourceLocation Loc); |
2836 | |
2837 | // These flags are passed to checkNonTrivialCUnion. |
2838 | enum NonTrivialCUnionKind { |
2839 | NTCUK_Init = 0x1, |
2840 | NTCUK_Destruct = 0x2, |
2841 | NTCUK_Copy = 0x4, |
2842 | }; |
2843 | |
2844 | /// Emit diagnostics if a non-trivial C union type or a struct that contains |
2845 | /// a non-trivial C union is used in an invalid context. |
2846 | void checkNonTrivialCUnion(QualType QT, SourceLocation Loc, |
2847 | NonTrivialCUnionContext UseContext, |
2848 | unsigned NonTrivialKind); |
2849 | |
2850 | void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit); |
2851 | void ActOnUninitializedDecl(Decl *dcl); |
2852 | void ActOnInitializerError(Decl *Dcl); |
2853 | |
2854 | void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc); |
2855 | void ActOnCXXForRangeDecl(Decl *D); |
2856 | StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, |
2857 | IdentifierInfo *Ident, |
2858 | ParsedAttributes &Attrs, |
2859 | SourceLocation AttrEnd); |
2860 | void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc); |
2861 | void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc); |
2862 | void CheckStaticLocalForDllExport(VarDecl *VD); |
2863 | void FinalizeDeclaration(Decl *D); |
2864 | DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, |
2865 | ArrayRef<Decl *> Group); |
2866 | DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group); |
2867 | |
2868 | /// Should be called on all declarations that might have attached |
2869 | /// documentation comments. |
2870 | void ActOnDocumentableDecl(Decl *D); |
2871 | void ActOnDocumentableDecls(ArrayRef<Decl *> Group); |
2872 | |
2873 | void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, |
2874 | SourceLocation LocAfterDecls); |
2875 | void CheckForFunctionRedefinition( |
2876 | FunctionDecl *FD, const FunctionDecl *EffectiveDefinition = nullptr, |
2877 | SkipBodyInfo *SkipBody = nullptr); |
2878 | Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D, |
2879 | MultiTemplateParamsArg TemplateParamLists, |
2880 | SkipBodyInfo *SkipBody = nullptr); |
2881 | Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D, |
2882 | SkipBodyInfo *SkipBody = nullptr); |
2883 | void ActOnStartTrailingRequiresClause(Scope *S, Declarator &D); |
2884 | ExprResult ActOnFinishTrailingRequiresClause(ExprResult ConstraintExpr); |
2885 | ExprResult ActOnRequiresClause(ExprResult ConstraintExpr); |
2886 | void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); |
2887 | bool isObjCMethodDecl(Decl *D) { |
2888 | return D && isa<ObjCMethodDecl>(D); |
2889 | } |
2890 | |
2891 | /// Determine whether we can delay parsing the body of a function or |
2892 | /// function template until it is used, assuming we don't care about emitting |
2893 | /// code for that function. |
2894 | /// |
2895 | /// This will be \c false if we may need the body of the function in the |
2896 | /// middle of parsing an expression (where it's impractical to switch to |
2897 | /// parsing a different function), for instance, if it's constexpr in C++11 |
2898 | /// or has an 'auto' return type in C++14. These cases are essentially bugs. |
2899 | bool canDelayFunctionBody(const Declarator &D); |
2900 | |
2901 | /// Determine whether we can skip parsing the body of a function |
2902 | /// definition, assuming we don't care about analyzing its body or emitting |
2903 | /// code for that function. |
2904 | /// |
2905 | /// This will be \c false only if we may need the body of the function in |
2906 | /// order to parse the rest of the program (for instance, if it is |
2907 | /// \c constexpr in C++11 or has an 'auto' return type in C++14). |
2908 | bool canSkipFunctionBody(Decl *D); |
2909 | |
2910 | void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope); |
2911 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body); |
2912 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation); |
2913 | Decl *ActOnSkippedFunctionBody(Decl *Decl); |
2914 | void ActOnFinishInlineFunctionDef(FunctionDecl *D); |
2915 | |
2916 | /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an |
2917 | /// attribute for which parsing is delayed. |
2918 | void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs); |
2919 | |
2920 | /// Diagnose any unused parameters in the given sequence of |
2921 | /// ParmVarDecl pointers. |
2922 | void DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters); |
2923 | |
2924 | /// Diagnose whether the size of parameters or return value of a |
2925 | /// function or obj-c method definition is pass-by-value and larger than a |
2926 | /// specified threshold. |
2927 | void |
2928 | DiagnoseSizeOfParametersAndReturnValue(ArrayRef<ParmVarDecl *> Parameters, |
2929 | QualType ReturnTy, NamedDecl *D); |
2930 | |
2931 | void DiagnoseInvalidJumps(Stmt *Body); |
2932 | Decl *ActOnFileScopeAsmDecl(Expr *expr, |
2933 | SourceLocation AsmLoc, |
2934 | SourceLocation RParenLoc); |
2935 | |
2936 | /// Handle a C++11 empty-declaration and attribute-declaration. |
2937 | Decl *ActOnEmptyDeclaration(Scope *S, const ParsedAttributesView &AttrList, |
2938 | SourceLocation SemiLoc); |
2939 | |
2940 | enum class ModuleDeclKind { |
2941 | Interface, ///< 'export module X;' |
2942 | Implementation, ///< 'module X;' |
2943 | }; |
2944 | |
2945 | /// The parser has processed a module-declaration that begins the definition |
2946 | /// of a module interface or implementation. |
2947 | DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc, |
2948 | SourceLocation ModuleLoc, ModuleDeclKind MDK, |
2949 | ModuleIdPath Path, bool IsFirstDecl); |
2950 | |
2951 | /// The parser has processed a global-module-fragment declaration that begins |
2952 | /// the definition of the global module fragment of the current module unit. |
2953 | /// \param ModuleLoc The location of the 'module' keyword. |
2954 | DeclGroupPtrTy ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc); |
2955 | |
2956 | /// The parser has processed a private-module-fragment declaration that begins |
2957 | /// the definition of the private module fragment of the current module unit. |
2958 | /// \param ModuleLoc The location of the 'module' keyword. |
2959 | /// \param PrivateLoc The location of the 'private' keyword. |
2960 | DeclGroupPtrTy ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc, |
2961 | SourceLocation PrivateLoc); |
2962 | |
2963 | /// The parser has processed a module import declaration. |
2964 | /// |
2965 | /// \param StartLoc The location of the first token in the declaration. This |
2966 | /// could be the location of an '@', 'export', or 'import'. |
2967 | /// \param ExportLoc The location of the 'export' keyword, if any. |
2968 | /// \param ImportLoc The location of the 'import' keyword. |
2969 | /// \param Path The module access path. |
2970 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
2971 | SourceLocation ExportLoc, |
2972 | SourceLocation ImportLoc, ModuleIdPath Path); |
2973 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
2974 | SourceLocation ExportLoc, |
2975 | SourceLocation ImportLoc, Module *M, |
2976 | ModuleIdPath Path = {}); |
2977 | |
2978 | /// The parser has processed a module import translated from a |
2979 | /// #include or similar preprocessing directive. |
2980 | void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
2981 | void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
2982 | |
2983 | /// The parsed has entered a submodule. |
2984 | void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod); |
2985 | /// The parser has left a submodule. |
2986 | void ActOnModuleEnd(SourceLocation DirectiveLoc, Module *Mod); |
2987 | |
2988 | /// Create an implicit import of the given module at the given |
2989 | /// source location, for error recovery, if possible. |
2990 | /// |
2991 | /// This routine is typically used when an entity found by name lookup |
2992 | /// is actually hidden within a module that we know about but the user |
2993 | /// has forgotten to import. |
2994 | void createImplicitModuleImportForErrorRecovery(SourceLocation Loc, |
2995 | Module *Mod); |
2996 | |
2997 | /// Kinds of missing import. Note, the values of these enumerators correspond |
2998 | /// to %select values in diagnostics. |
2999 | enum class MissingImportKind { |
3000 | Declaration, |
3001 | Definition, |
3002 | DefaultArgument, |
3003 | ExplicitSpecialization, |
3004 | PartialSpecialization |
3005 | }; |
3006 | |
3007 | /// Diagnose that the specified declaration needs to be visible but |
3008 | /// isn't, and suggest a module import that would resolve the problem. |
3009 | void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl, |
3010 | MissingImportKind MIK, bool Recover = true); |
3011 | void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl, |
3012 | SourceLocation DeclLoc, ArrayRef<Module *> Modules, |
3013 | MissingImportKind MIK, bool Recover); |
3014 | |
3015 | Decl *ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, |
3016 | SourceLocation LBraceLoc); |
3017 | Decl *ActOnFinishExportDecl(Scope *S, Decl *ExportDecl, |
3018 | SourceLocation RBraceLoc); |
3019 | |
3020 | /// We've found a use of a templated declaration that would trigger an |
3021 | /// implicit instantiation. Check that any relevant explicit specializations |
3022 | /// and partial specializations are visible, and diagnose if not. |
3023 | void checkSpecializationVisibility(SourceLocation Loc, NamedDecl *Spec); |
3024 | |
3025 | /// Retrieve a suitable printing policy for diagnostics. |
3026 | PrintingPolicy getPrintingPolicy() const { |
3027 | return getPrintingPolicy(Context, PP); |
3028 | } |
3029 | |
3030 | /// Retrieve a suitable printing policy for diagnostics. |
3031 | static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx, |
3032 | const Preprocessor &PP); |
3033 | |
3034 | /// Scope actions. |
3035 | void ActOnPopScope(SourceLocation Loc, Scope *S); |
3036 | void ActOnTranslationUnitScope(Scope *S); |
3037 | |
3038 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
3039 | RecordDecl *&AnonRecord); |
3040 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
3041 | MultiTemplateParamsArg TemplateParams, |
3042 | bool IsExplicitInstantiation, |
3043 | RecordDecl *&AnonRecord); |
3044 | |
3045 | Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, |
3046 | AccessSpecifier AS, |
3047 | RecordDecl *Record, |
3048 | const PrintingPolicy &Policy); |
3049 | |
3050 | Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, |
3051 | RecordDecl *Record); |
3052 | |
3053 | /// Common ways to introduce type names without a tag for use in diagnostics. |
3054 | /// Keep in sync with err_tag_reference_non_tag. |
3055 | enum NonTagKind { |
3056 | NTK_NonStruct, |
3057 | NTK_NonClass, |
3058 | NTK_NonUnion, |
3059 | NTK_NonEnum, |
3060 | NTK_Typedef, |
3061 | NTK_TypeAlias, |
3062 | NTK_Template, |
3063 | NTK_TypeAliasTemplate, |
3064 | NTK_TemplateTemplateArgument, |
3065 | }; |
3066 | |
3067 | /// Given a non-tag type declaration, returns an enum useful for indicating |
3068 | /// what kind of non-tag type this is. |
3069 | NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK); |
3070 | |
3071 | bool isAcceptableTagRedeclaration(const TagDecl *Previous, |
3072 | TagTypeKind NewTag, bool isDefinition, |
3073 | SourceLocation NewTagLoc, |
3074 | const IdentifierInfo *Name); |
3075 | |
3076 | enum TagUseKind { |
3077 | TUK_Reference, // Reference to a tag: 'struct foo *X;' |
3078 | TUK_Declaration, // Fwd decl of a tag: 'struct foo;' |
3079 | TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;' |
3080 | TUK_Friend // Friend declaration: 'friend struct foo;' |
3081 | }; |
3082 | |
3083 | Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, |
3084 | SourceLocation KWLoc, CXXScopeSpec &SS, IdentifierInfo *Name, |
3085 | SourceLocation NameLoc, const ParsedAttributesView &Attr, |
3086 | AccessSpecifier AS, SourceLocation ModulePrivateLoc, |
3087 | MultiTemplateParamsArg TemplateParameterLists, bool &OwnedDecl, |
3088 | bool &IsDependent, SourceLocation ScopedEnumKWLoc, |
3089 | bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, |
3090 | bool IsTypeSpecifier, bool IsTemplateParamOrArg, |
3091 | SkipBodyInfo *SkipBody = nullptr); |
3092 | |
3093 | Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, |
3094 | unsigned TagSpec, SourceLocation TagLoc, |
3095 | CXXScopeSpec &SS, IdentifierInfo *Name, |
3096 | SourceLocation NameLoc, |
3097 | const ParsedAttributesView &Attr, |
3098 | MultiTemplateParamsArg TempParamLists); |
3099 | |
3100 | TypeResult ActOnDependentTag(Scope *S, |
3101 | unsigned TagSpec, |
3102 | TagUseKind TUK, |
3103 | const CXXScopeSpec &SS, |
3104 | IdentifierInfo *Name, |
3105 | SourceLocation TagLoc, |
3106 | SourceLocation NameLoc); |
3107 | |
3108 | void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, |
3109 | IdentifierInfo *ClassName, |
3110 | SmallVectorImpl<Decl *> &Decls); |
3111 | Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, |
3112 | Declarator &D, Expr *BitfieldWidth); |
3113 | |
3114 | FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, |
3115 | Declarator &D, Expr *BitfieldWidth, |
3116 | InClassInitStyle InitStyle, |
3117 | AccessSpecifier AS); |
3118 | MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD, |
3119 | SourceLocation DeclStart, Declarator &D, |
3120 | Expr *BitfieldWidth, |
3121 | InClassInitStyle InitStyle, |
3122 | AccessSpecifier AS, |
3123 | const ParsedAttr &MSPropertyAttr); |
3124 | |
3125 | FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, |
3126 | TypeSourceInfo *TInfo, |
3127 | RecordDecl *Record, SourceLocation Loc, |
3128 | bool Mutable, Expr *BitfieldWidth, |
3129 | InClassInitStyle InitStyle, |
3130 | SourceLocation TSSL, |
3131 | AccessSpecifier AS, NamedDecl *PrevDecl, |
3132 | Declarator *D = nullptr); |
3133 | |
3134 | bool CheckNontrivialField(FieldDecl *FD); |
3135 | void DiagnoseNontrivial(const CXXRecordDecl *Record, CXXSpecialMember CSM); |
3136 | |
3137 | enum TrivialABIHandling { |
3138 | /// The triviality of a method unaffected by "trivial_abi". |
3139 | TAH_IgnoreTrivialABI, |
3140 | |
3141 | /// The triviality of a method affected by "trivial_abi". |
3142 | TAH_ConsiderTrivialABI |
3143 | }; |
3144 | |
3145 | bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM, |
3146 | TrivialABIHandling TAH = TAH_IgnoreTrivialABI, |
3147 | bool Diagnose = false); |
3148 | |
3149 | /// For a defaulted function, the kind of defaulted function that it is. |
3150 | class DefaultedFunctionKind { |
3151 | CXXSpecialMember SpecialMember : 8; |
3152 | DefaultedComparisonKind Comparison : 8; |
3153 | |
3154 | public: |
3155 | DefaultedFunctionKind() |
3156 | : SpecialMember(CXXInvalid), Comparison(DefaultedComparisonKind::None) { |
3157 | } |
3158 | DefaultedFunctionKind(CXXSpecialMember CSM) |
3159 | : SpecialMember(CSM), Comparison(DefaultedComparisonKind::None) {} |
3160 | DefaultedFunctionKind(DefaultedComparisonKind Comp) |
3161 | : SpecialMember(CXXInvalid), Comparison(Comp) {} |
3162 | |
3163 | bool isSpecialMember() const { return SpecialMember != CXXInvalid; } |
3164 | bool isComparison() const { |
3165 | return Comparison != DefaultedComparisonKind::None; |
3166 | } |
3167 | |
3168 | explicit operator bool() const { |
3169 | return isSpecialMember() || isComparison(); |
3170 | } |
3171 | |
3172 | CXXSpecialMember asSpecialMember() const { return SpecialMember; } |
3173 | DefaultedComparisonKind asComparison() const { return Comparison; } |
3174 | |
3175 | /// Get the index of this function kind for use in diagnostics. |
3176 | unsigned getDiagnosticIndex() const { |
3177 | static_assert(CXXInvalid > CXXDestructor, |
3178 | "invalid should have highest index"); |
3179 | static_assert((unsigned)DefaultedComparisonKind::None == 0, |
3180 | "none should be equal to zero"); |
3181 | return SpecialMember + (unsigned)Comparison; |
3182 | } |
3183 | }; |
3184 | |
3185 | DefaultedFunctionKind getDefaultedFunctionKind(const FunctionDecl *FD); |
3186 | |
3187 | CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD) { |
3188 | return getDefaultedFunctionKind(MD).asSpecialMember(); |
3189 | } |
3190 | DefaultedComparisonKind getDefaultedComparisonKind(const FunctionDecl *FD) { |
3191 | return getDefaultedFunctionKind(FD).asComparison(); |
3192 | } |
3193 | |
3194 | void ActOnLastBitfield(SourceLocation DeclStart, |
3195 | SmallVectorImpl<Decl *> &AllIvarDecls); |
3196 | Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, |
3197 | Declarator &D, Expr *BitfieldWidth, |
3198 | tok::ObjCKeywordKind visibility); |
3199 | |
3200 | // This is used for both record definitions and ObjC interface declarations. |
3201 | void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, |
3202 | ArrayRef<Decl *> Fields, SourceLocation LBrac, |
3203 | SourceLocation RBrac, const ParsedAttributesView &AttrList); |
3204 | |
3205 | /// ActOnTagStartDefinition - Invoked when we have entered the |
3206 | /// scope of a tag's definition (e.g., for an enumeration, class, |
3207 | /// struct, or union). |
3208 | void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); |
3209 | |
3210 | /// Perform ODR-like check for C/ObjC when merging tag types from modules. |
3211 | /// Differently from C++, actually parse the body and reject / error out |
3212 | /// in case of a structural mismatch. |
3213 | bool ActOnDuplicateDefinition(DeclSpec &DS, Decl *Prev, |
3214 | SkipBodyInfo &SkipBody); |
3215 | |
3216 | typedef void *SkippedDefinitionContext; |
3217 | |
3218 | /// Invoked when we enter a tag definition that we're skipping. |
3219 | SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD); |
3220 | |
3221 | Decl *ActOnObjCContainerStartDefinition(Decl *IDecl); |
3222 | |
3223 | /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a |
3224 | /// C++ record definition's base-specifiers clause and are starting its |
3225 | /// member declarations. |
3226 | void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, |
3227 | SourceLocation FinalLoc, |
3228 | bool IsFinalSpelledSealed, |
3229 | bool IsAbstract, |
3230 | SourceLocation LBraceLoc); |
3231 | |
3232 | /// ActOnTagFinishDefinition - Invoked once we have finished parsing |
3233 | /// the definition of a tag (enumeration, class, struct, or union). |
3234 | void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, |
3235 | SourceRange BraceRange); |
3236 | |
3237 | void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context); |
3238 | |
3239 | void ActOnObjCContainerFinishDefinition(); |
3240 | |
3241 | /// Invoked when we must temporarily exit the objective-c container |
3242 | /// scope for parsing/looking-up C constructs. |
3243 | /// |
3244 | /// Must be followed by a call to \see ActOnObjCReenterContainerContext |
3245 | void ActOnObjCTemporaryExitContainerContext(DeclContext *DC); |
3246 | void ActOnObjCReenterContainerContext(DeclContext *DC); |
3247 | |
3248 | /// ActOnTagDefinitionError - Invoked when there was an unrecoverable |
3249 | /// error parsing the definition of a tag. |
3250 | void ActOnTagDefinitionError(Scope *S, Decl *TagDecl); |
3251 | |
3252 | EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, |
3253 | EnumConstantDecl *LastEnumConst, |
3254 | SourceLocation IdLoc, |
3255 | IdentifierInfo *Id, |
3256 | Expr *val); |
3257 | bool CheckEnumUnderlyingType(TypeSourceInfo *TI); |
3258 | bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, |
3259 | QualType EnumUnderlyingTy, bool IsFixed, |
3260 | const EnumDecl *Prev); |
3261 | |
3262 | /// Determine whether the body of an anonymous enumeration should be skipped. |
3263 | /// \param II The name of the first enumerator. |
3264 | SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, |
3265 | SourceLocation IILoc); |
3266 | |
3267 | Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, |
3268 | SourceLocation IdLoc, IdentifierInfo *Id, |
3269 | const ParsedAttributesView &Attrs, |
3270 | SourceLocation EqualLoc, Expr *Val); |
3271 | void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, |
3272 | Decl *EnumDecl, ArrayRef<Decl *> Elements, Scope *S, |
3273 | const ParsedAttributesView &Attr); |
3274 | |
3275 | /// Set the current declaration context until it gets popped. |
3276 | void PushDeclContext(Scope *S, DeclContext *DC); |
3277 | void PopDeclContext(); |
3278 | |
3279 | /// EnterDeclaratorContext - Used when we must lookup names in the context |
3280 | /// of a declarator's nested name specifier. |
3281 | void EnterDeclaratorContext(Scope *S, DeclContext *DC); |
3282 | void ExitDeclaratorContext(Scope *S); |
3283 | |
3284 | /// Enter a template parameter scope, after it's been associated with a particular |
3285 | /// DeclContext. Causes lookup within the scope to chain through enclosing contexts |
3286 | /// in the correct order. |
3287 | void EnterTemplatedContext(Scope *S, DeclContext *DC); |
3288 | |
3289 | /// Push the parameters of D, which must be a function, into scope. |
3290 | void ActOnReenterFunctionContext(Scope* S, Decl* D); |
3291 | void ActOnExitFunctionContext(); |
3292 | |
3293 | DeclContext *getFunctionLevelDeclContext(); |
3294 | |
3295 | /// getCurFunctionDecl - If inside of a function body, this returns a pointer |
3296 | /// to the function decl for the function being parsed. If we're currently |
3297 | /// in a 'block', this returns the containing context. |
3298 | FunctionDecl *getCurFunctionDecl(); |
3299 | |
3300 | /// getCurMethodDecl - If inside of a method body, this returns a pointer to |
3301 | /// the method decl for the method being parsed. If we're currently |
3302 | /// in a 'block', this returns the containing context. |
3303 | ObjCMethodDecl *getCurMethodDecl(); |
3304 | |
3305 | /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method |
3306 | /// or C function we're in, otherwise return null. If we're currently |
3307 | /// in a 'block', this returns the containing context. |
3308 | NamedDecl *getCurFunctionOrMethodDecl(); |
3309 | |
3310 | /// Add this decl to the scope shadowed decl chains. |
3311 | void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true); |
3312 | |
3313 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
3314 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
3315 | /// true if 'D' belongs to the given declaration context. |
3316 | /// |
3317 | /// \param AllowInlineNamespace If \c true, allow the declaration to be in the |
3318 | /// enclosing namespace set of the context, rather than contained |
3319 | /// directly within it. |
3320 | bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr, |
3321 | bool AllowInlineNamespace = false); |
3322 | |
3323 | /// Finds the scope corresponding to the given decl context, if it |
3324 | /// happens to be an enclosing scope. Otherwise return NULL. |
3325 | static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC); |
3326 | |
3327 | /// Subroutines of ActOnDeclarator(). |
3328 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, |
3329 | TypeSourceInfo *TInfo); |
3330 | bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New); |
3331 | |
3332 | /// Describes the kind of merge to perform for availability |
3333 | /// attributes (including "deprecated", "unavailable", and "availability"). |
3334 | enum AvailabilityMergeKind { |
3335 | /// Don't merge availability attributes at all. |
3336 | AMK_None, |
3337 | /// Merge availability attributes for a redeclaration, which requires |
3338 | /// an exact match. |
3339 | AMK_Redeclaration, |
3340 | /// Merge availability attributes for an override, which requires |
3341 | /// an exact match or a weakening of constraints. |
3342 | AMK_Override, |
3343 | /// Merge availability attributes for an implementation of |
3344 | /// a protocol requirement. |
3345 | AMK_ProtocolImplementation, |
3346 | /// Merge availability attributes for an implementation of |
3347 | /// an optional protocol requirement. |
3348 | AMK_OptionalProtocolImplementation |
3349 | }; |
3350 | |
3351 | /// Describes the kind of priority given to an availability attribute. |
3352 | /// |
3353 | /// The sum of priorities deteremines the final priority of the attribute. |
3354 | /// The final priority determines how the attribute will be merged. |
3355 | /// An attribute with a lower priority will always remove higher priority |
3356 | /// attributes for the specified platform when it is being applied. An |
3357 | /// attribute with a higher priority will not be applied if the declaration |
3358 | /// already has an availability attribute with a lower priority for the |
3359 | /// specified platform. The final prirority values are not expected to match |
3360 | /// the values in this enumeration, but instead should be treated as a plain |
3361 | /// integer value. This enumeration just names the priority weights that are |
3362 | /// used to calculate that final vaue. |
3363 | enum AvailabilityPriority : int { |
3364 | /// The availability attribute was specified explicitly next to the |
3365 | /// declaration. |
3366 | AP_Explicit = 0, |
3367 | |
3368 | /// The availability attribute was applied using '#pragma clang attribute'. |
3369 | AP_PragmaClangAttribute = 1, |
3370 | |
3371 | /// The availability attribute for a specific platform was inferred from |
3372 | /// an availability attribute for another platform. |
3373 | AP_InferredFromOtherPlatform = 2 |
3374 | }; |
3375 | |
3376 | /// Attribute merging methods. Return true if a new attribute was added. |
3377 | AvailabilityAttr * |
3378 | mergeAvailabilityAttr(NamedDecl *D, const AttributeCommonInfo &CI, |
3379 | IdentifierInfo *Platform, bool Implicit, |
3380 | VersionTuple Introduced, VersionTuple Deprecated, |
3381 | VersionTuple Obsoleted, bool IsUnavailable, |
3382 | StringRef Message, bool IsStrict, StringRef Replacement, |
3383 | AvailabilityMergeKind AMK, int Priority); |
3384 | TypeVisibilityAttr * |
3385 | mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
3386 | TypeVisibilityAttr::VisibilityType Vis); |
3387 | VisibilityAttr *mergeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
3388 | VisibilityAttr::VisibilityType Vis); |
3389 | UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI, |
3390 | StringRef UuidAsWritten, MSGuidDecl *GuidDecl); |
3391 | DLLImportAttr *mergeDLLImportAttr(Decl *D, const AttributeCommonInfo &CI); |
3392 | DLLExportAttr *mergeDLLExportAttr(Decl *D, const AttributeCommonInfo &CI); |
3393 | MSInheritanceAttr *mergeMSInheritanceAttr(Decl *D, |
3394 | const AttributeCommonInfo &CI, |
3395 | bool BestCase, |
3396 | MSInheritanceModel Model); |
3397 | ErrorAttr *mergeErrorAttr(Decl *D, const AttributeCommonInfo &CI, |
3398 | StringRef NewUserDiagnostic); |
3399 | FormatAttr *mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI, |
3400 | IdentifierInfo *Format, int FormatIdx, |
3401 | int FirstArg); |
3402 | SectionAttr *mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI, |
3403 | StringRef Name); |
3404 | CodeSegAttr *mergeCodeSegAttr(Decl *D, const AttributeCommonInfo &CI, |
3405 | StringRef Name); |
3406 | AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, |
3407 | const AttributeCommonInfo &CI, |
3408 | const IdentifierInfo *Ident); |
3409 | MinSizeAttr *mergeMinSizeAttr(Decl *D, const AttributeCommonInfo &CI); |
3410 | SwiftNameAttr *mergeSwiftNameAttr(Decl *D, const SwiftNameAttr &SNA, |
3411 | StringRef Name); |
3412 | OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, |
3413 | const AttributeCommonInfo &CI); |
3414 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL); |
3415 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, |
3416 | const InternalLinkageAttr &AL); |
3417 | WebAssemblyImportNameAttr *mergeImportNameAttr( |
3418 | Decl *D, const WebAssemblyImportNameAttr &AL); |
3419 | WebAssemblyImportModuleAttr *mergeImportModuleAttr( |
3420 | Decl *D, const WebAssemblyImportModuleAttr &AL); |
3421 | EnforceTCBAttr *mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL); |
3422 | EnforceTCBLeafAttr *mergeEnforceTCBLeafAttr(Decl *D, |
3423 | const EnforceTCBLeafAttr &AL); |
3424 | BTFDeclTagAttr *mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL); |
3425 | |
3426 | void mergeDeclAttributes(NamedDecl *New, Decl *Old, |
3427 | AvailabilityMergeKind AMK = AMK_Redeclaration); |
3428 | void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, |
3429 | LookupResult &OldDecls); |
3430 | bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S, |
3431 | bool MergeTypeWithOld); |
3432 | bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, |
3433 | Scope *S, bool MergeTypeWithOld); |
3434 | void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old); |
3435 | void MergeVarDecl(VarDecl *New, LookupResult &Previous); |
3436 | void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld); |
3437 | void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old); |
3438 | bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn); |
3439 | void notePreviousDefinition(const NamedDecl *Old, SourceLocation New); |
3440 | bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S); |
3441 | |
3442 | // AssignmentAction - This is used by all the assignment diagnostic functions |
3443 | // to represent what is actually causing the operation |
3444 | enum AssignmentAction { |
3445 | AA_Assigning, |
3446 | AA_Passing, |
3447 | AA_Returning, |
3448 | AA_Converting, |
3449 | AA_Initializing, |
3450 | AA_Sending, |
3451 | AA_Casting, |
3452 | AA_Passing_CFAudited |
3453 | }; |
3454 | |
3455 | /// C++ Overloading. |
3456 | enum OverloadKind { |
3457 | /// This is a legitimate overload: the existing declarations are |
3458 | /// functions or function templates with different signatures. |
3459 | Ovl_Overload, |
3460 | |
3461 | /// This is not an overload because the signature exactly matches |
3462 | /// an existing declaration. |
3463 | Ovl_Match, |
3464 | |
3465 | /// This is not an overload because the lookup results contain a |
3466 | /// non-function. |
3467 | Ovl_NonFunction |
3468 | }; |
3469 | OverloadKind CheckOverload(Scope *S, |
3470 | FunctionDecl *New, |
3471 | const LookupResult &OldDecls, |
3472 | NamedDecl *&OldDecl, |
3473 | bool IsForUsingDecl); |
3474 | bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl, |
3475 | bool ConsiderCudaAttrs = true, |
3476 | bool ConsiderRequiresClauses = true); |
3477 | |
3478 | enum class AllowedExplicit { |
3479 | /// Allow no explicit functions to be used. |
3480 | None, |
3481 | /// Allow explicit conversion functions but not explicit constructors. |
3482 | Conversions, |
3483 | /// Allow both explicit conversion functions and explicit constructors. |
3484 | All |
3485 | }; |
3486 | |
3487 | ImplicitConversionSequence |
3488 | TryImplicitConversion(Expr *From, QualType ToType, |
3489 | bool SuppressUserConversions, |
3490 | AllowedExplicit AllowExplicit, |
3491 | bool InOverloadResolution, |
3492 | bool CStyle, |
3493 | bool AllowObjCWritebackConversion); |
3494 | |
3495 | bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); |
3496 | bool IsFloatingPointPromotion(QualType FromType, QualType ToType); |
3497 | bool IsComplexPromotion(QualType FromType, QualType ToType); |
3498 | bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, |
3499 | bool InOverloadResolution, |
3500 | QualType& ConvertedType, bool &IncompatibleObjC); |
3501 | bool isObjCPointerConversion(QualType FromType, QualType ToType, |
3502 | QualType& ConvertedType, bool &IncompatibleObjC); |
3503 | bool isObjCWritebackConversion(QualType FromType, QualType ToType, |
3504 | QualType &ConvertedType); |
3505 | bool IsBlockPointerConversion(QualType FromType, QualType ToType, |
3506 | QualType& ConvertedType); |
3507 | bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType, |
3508 | const FunctionProtoType *NewType, |
3509 | unsigned *ArgPos = nullptr); |
3510 | void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, |
3511 | QualType FromType, QualType ToType); |
3512 | |
3513 | void maybeExtendBlockObject(ExprResult &E); |
3514 | CastKind PrepareCastToObjCObjectPointer(ExprResult &E); |
3515 | bool CheckPointerConversion(Expr *From, QualType ToType, |
3516 | CastKind &Kind, |
3517 | CXXCastPath& BasePath, |
3518 | bool IgnoreBaseAccess, |
3519 | bool Diagnose = true); |
3520 | bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, |
3521 | bool InOverloadResolution, |
3522 | QualType &ConvertedType); |
3523 | bool CheckMemberPointerConversion(Expr *From, QualType ToType, |
3524 | CastKind &Kind, |
3525 | CXXCastPath &BasePath, |
3526 | bool IgnoreBaseAccess); |
3527 | bool IsQualificationConversion(QualType FromType, QualType ToType, |
3528 | bool CStyle, bool &ObjCLifetimeConversion); |
3529 | bool IsFunctionConversion(QualType FromType, QualType ToType, |
3530 | QualType &ResultTy); |
3531 | bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); |
3532 | bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg); |
3533 | |
3534 | bool CanPerformAggregateInitializationForOverloadResolution( |
3535 | const InitializedEntity &Entity, InitListExpr *From); |
3536 | |
3537 | bool IsStringInit(Expr *Init, const ArrayType *AT); |
3538 | |
3539 | bool CanPerformCopyInitialization(const InitializedEntity &Entity, |
3540 | ExprResult Init); |
3541 | ExprResult PerformCopyInitialization(const InitializedEntity &Entity, |
3542 | SourceLocation EqualLoc, |
3543 | ExprResult Init, |
3544 | bool TopLevelOfInitList = false, |
3545 | bool AllowExplicit = false); |
3546 | ExprResult PerformObjectArgumentInitialization(Expr *From, |
3547 | NestedNameSpecifier *Qualifier, |
3548 | NamedDecl *FoundDecl, |
3549 | CXXMethodDecl *Method); |
3550 | |
3551 | /// Check that the lifetime of the initializer (and its subobjects) is |
3552 | /// sufficient for initializing the entity, and perform lifetime extension |
3553 | /// (when permitted) if not. |
3554 | void checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init); |
3555 | |
3556 | ExprResult PerformContextuallyConvertToBool(Expr *From); |
3557 | ExprResult PerformContextuallyConvertToObjCPointer(Expr *From); |
3558 | |
3559 | /// Contexts in which a converted constant expression is required. |
3560 | enum CCEKind { |
3561 | CCEK_CaseValue, ///< Expression in a case label. |
3562 | CCEK_Enumerator, ///< Enumerator value with fixed underlying type. |
3563 | CCEK_TemplateArg, ///< Value of a non-type template parameter. |
3564 | CCEK_ArrayBound, ///< Array bound in array declarator or new-expression. |
3565 | CCEK_ExplicitBool, ///< Condition in an explicit(bool) specifier. |
3566 | CCEK_Noexcept ///< Condition in a noexcept(bool) specifier. |
3567 | }; |
3568 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
3569 | llvm::APSInt &Value, CCEKind CCE); |
3570 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
3571 | APValue &Value, CCEKind CCE, |
3572 | NamedDecl *Dest = nullptr); |
3573 | |
3574 | /// Abstract base class used to perform a contextual implicit |
3575 | /// conversion from an expression to any type passing a filter. |
3576 | class ContextualImplicitConverter { |
3577 | public: |
3578 | bool Suppress; |
3579 | bool SuppressConversion; |
3580 | |
3581 | ContextualImplicitConverter(bool Suppress = false, |
3582 | bool SuppressConversion = false) |
3583 | : Suppress(Suppress), SuppressConversion(SuppressConversion) {} |
3584 | |
3585 | /// Determine whether the specified type is a valid destination type |
3586 | /// for this conversion. |
3587 | virtual bool match(QualType T) = 0; |
3588 | |
3589 | /// Emits a diagnostic complaining that the expression does not have |
3590 | /// integral or enumeration type. |
3591 | virtual SemaDiagnosticBuilder |
3592 | diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) = 0; |
3593 | |
3594 | /// Emits a diagnostic when the expression has incomplete class type. |
3595 | virtual SemaDiagnosticBuilder |
3596 | diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0; |
3597 | |
3598 | /// Emits a diagnostic when the only matching conversion function |
3599 | /// is explicit. |
3600 | virtual SemaDiagnosticBuilder diagnoseExplicitConv( |
3601 | Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0; |
3602 | |
3603 | /// Emits a note for the explicit conversion function. |
3604 | virtual SemaDiagnosticBuilder |
3605 | noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
3606 | |
3607 | /// Emits a diagnostic when there are multiple possible conversion |
3608 | /// functions. |
3609 | virtual SemaDiagnosticBuilder |
3610 | diagnoseAmbiguous(Sema &S, SourceLocation Loc, QualType T) = 0; |
3611 | |
3612 | /// Emits a note for one of the candidate conversions. |
3613 | virtual SemaDiagnosticBuilder |
3614 | noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
3615 | |
3616 | /// Emits a diagnostic when we picked a conversion function |
3617 | /// (for cases when we are not allowed to pick a conversion function). |
3618 | virtual SemaDiagnosticBuilder diagnoseConversion( |
3619 | Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0; |
3620 | |
3621 | virtual ~ContextualImplicitConverter() {} |
3622 | }; |
3623 | |
3624 | class ICEConvertDiagnoser : public ContextualImplicitConverter { |
3625 | bool AllowScopedEnumerations; |
3626 | |
3627 | public: |
3628 | ICEConvertDiagnoser(bool AllowScopedEnumerations, |
3629 | bool Suppress, bool SuppressConversion) |
3630 | : ContextualImplicitConverter(Suppress, SuppressConversion), |
3631 | AllowScopedEnumerations(AllowScopedEnumerations) {} |
3632 | |
3633 | /// Match an integral or (possibly scoped) enumeration type. |
3634 | bool match(QualType T) override; |
3635 | |
3636 | SemaDiagnosticBuilder |
3637 | diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) override { |
3638 | return diagnoseNotInt(S, Loc, T); |
3639 | } |
3640 | |
3641 | /// Emits a diagnostic complaining that the expression does not have |
3642 | /// integral or enumeration type. |
3643 | virtual SemaDiagnosticBuilder |
3644 | diagnoseNotInt(Sema &S, SourceLocation Loc, QualType T) = 0; |
3645 | }; |
3646 | |
3647 | /// Perform a contextual implicit conversion. |
3648 | ExprResult PerformContextualImplicitConversion( |
3649 | SourceLocation Loc, Expr *FromE, ContextualImplicitConverter &Converter); |
3650 | |
3651 | |
3652 | enum ObjCSubscriptKind { |
3653 | OS_Array, |
3654 | OS_Dictionary, |
3655 | OS_Error |
3656 | }; |
3657 | ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE); |
3658 | |
3659 | // Note that LK_String is intentionally after the other literals, as |
3660 | // this is used for diagnostics logic. |
3661 | enum ObjCLiteralKind { |
3662 | LK_Array, |
3663 | LK_Dictionary, |
3664 | LK_Numeric, |
3665 | LK_Boxed, |
3666 | LK_String, |
3667 | LK_Block, |
3668 | LK_None |
3669 | }; |
3670 | ObjCLiteralKind CheckLiteralKind(Expr *FromE); |
3671 | |
3672 | ExprResult PerformObjectMemberConversion(Expr *From, |
3673 | NestedNameSpecifier *Qualifier, |
3674 | NamedDecl *FoundDecl, |
3675 | NamedDecl *Member); |
3676 | |
3677 | // Members have to be NamespaceDecl* or TranslationUnitDecl*. |
3678 | // TODO: make this is a typesafe union. |
3679 | typedef llvm::SmallSetVector<DeclContext *, 16> AssociatedNamespaceSet; |
3680 | typedef llvm::SmallSetVector<CXXRecordDecl *, 16> AssociatedClassSet; |
3681 | |
3682 | using ADLCallKind = CallExpr::ADLCallKind; |
3683 | |
3684 | void AddOverloadCandidate(FunctionDecl *Function, DeclAccessPair FoundDecl, |
3685 | ArrayRef<Expr *> Args, |
3686 | OverloadCandidateSet &CandidateSet, |
3687 | bool SuppressUserConversions = false, |
3688 | bool PartialOverloading = false, |
3689 | bool AllowExplicit = true, |
3690 | bool AllowExplicitConversion = false, |
3691 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
3692 | ConversionSequenceList EarlyConversions = None, |
3693 | OverloadCandidateParamOrder PO = {}); |
3694 | void AddFunctionCandidates(const UnresolvedSetImpl &Functions, |
3695 | ArrayRef<Expr *> Args, |
3696 | OverloadCandidateSet &CandidateSet, |
3697 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
3698 | bool SuppressUserConversions = false, |
3699 | bool PartialOverloading = false, |
3700 | bool FirstArgumentIsBase = false); |
3701 | void AddMethodCandidate(DeclAccessPair FoundDecl, |
3702 | QualType ObjectType, |
3703 | Expr::Classification ObjectClassification, |
3704 | ArrayRef<Expr *> Args, |
3705 | OverloadCandidateSet& CandidateSet, |
3706 | bool SuppressUserConversion = false, |
3707 | OverloadCandidateParamOrder PO = {}); |
3708 | void AddMethodCandidate(CXXMethodDecl *Method, |
3709 | DeclAccessPair FoundDecl, |
3710 | CXXRecordDecl *ActingContext, QualType ObjectType, |
3711 | Expr::Classification ObjectClassification, |
3712 | ArrayRef<Expr *> Args, |
3713 | OverloadCandidateSet& CandidateSet, |
3714 | bool SuppressUserConversions = false, |
3715 | bool PartialOverloading = false, |
3716 | ConversionSequenceList EarlyConversions = None, |
3717 | OverloadCandidateParamOrder PO = {}); |
3718 | void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, |
3719 | DeclAccessPair FoundDecl, |
3720 | CXXRecordDecl *ActingContext, |
3721 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
3722 | QualType ObjectType, |
3723 | Expr::Classification ObjectClassification, |
3724 | ArrayRef<Expr *> Args, |
3725 | OverloadCandidateSet& CandidateSet, |
3726 | bool SuppressUserConversions = false, |
3727 | bool PartialOverloading = false, |
3728 | OverloadCandidateParamOrder PO = {}); |
3729 | void AddTemplateOverloadCandidate( |
3730 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
3731 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
3732 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
3733 | bool PartialOverloading = false, bool AllowExplicit = true, |
3734 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
3735 | OverloadCandidateParamOrder PO = {}); |
3736 | bool CheckNonDependentConversions( |
3737 | FunctionTemplateDecl *FunctionTemplate, ArrayRef<QualType> ParamTypes, |
3738 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, |
3739 | ConversionSequenceList &Conversions, bool SuppressUserConversions, |
3740 | CXXRecordDecl *ActingContext = nullptr, QualType ObjectType = QualType(), |
3741 | Expr::Classification ObjectClassification = {}, |
3742 | OverloadCandidateParamOrder PO = {}); |
3743 | void AddConversionCandidate( |
3744 | CXXConversionDecl *Conversion, DeclAccessPair FoundDecl, |
3745 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
3746 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
3747 | bool AllowExplicit, bool AllowResultConversion = true); |
3748 | void AddTemplateConversionCandidate( |
3749 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
3750 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
3751 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
3752 | bool AllowExplicit, bool AllowResultConversion = true); |
3753 | void AddSurrogateCandidate(CXXConversionDecl *Conversion, |
3754 | DeclAccessPair FoundDecl, |
3755 | CXXRecordDecl *ActingContext, |
3756 | const FunctionProtoType *Proto, |
3757 | Expr *Object, ArrayRef<Expr *> Args, |
3758 | OverloadCandidateSet& CandidateSet); |
3759 | void AddNonMemberOperatorCandidates( |
3760 | const UnresolvedSetImpl &Functions, ArrayRef<Expr *> Args, |
3761 | OverloadCandidateSet &CandidateSet, |
3762 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
3763 | void AddMemberOperatorCandidates(OverloadedOperatorKind Op, |
3764 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
3765 | OverloadCandidateSet &CandidateSet, |
3766 | OverloadCandidateParamOrder PO = {}); |
3767 | void AddBuiltinCandidate(QualType *ParamTys, ArrayRef<Expr *> Args, |
3768 | OverloadCandidateSet& CandidateSet, |
3769 | bool IsAssignmentOperator = false, |
3770 | unsigned NumContextualBoolArguments = 0); |
3771 | void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, |
3772 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
3773 | OverloadCandidateSet& CandidateSet); |
3774 | void AddArgumentDependentLookupCandidates(DeclarationName Name, |
3775 | SourceLocation Loc, |
3776 | ArrayRef<Expr *> Args, |
3777 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
3778 | OverloadCandidateSet& CandidateSet, |
3779 | bool PartialOverloading = false); |
3780 | |
3781 | // Emit as a 'note' the specific overload candidate |
3782 | void NoteOverloadCandidate( |
3783 | NamedDecl *Found, FunctionDecl *Fn, |
3784 | OverloadCandidateRewriteKind RewriteKind = OverloadCandidateRewriteKind(), |
3785 | QualType DestType = QualType(), bool TakingAddress = false); |
3786 | |
3787 | // Emit as a series of 'note's all template and non-templates identified by |
3788 | // the expression Expr |
3789 | void NoteAllOverloadCandidates(Expr *E, QualType DestType = QualType(), |
3790 | bool TakingAddress = false); |
3791 | |
3792 | /// Check the enable_if expressions on the given function. Returns the first |
3793 | /// failing attribute, or NULL if they were all successful. |
3794 | EnableIfAttr *CheckEnableIf(FunctionDecl *Function, SourceLocation CallLoc, |
3795 | ArrayRef<Expr *> Args, |
3796 | bool MissingImplicitThis = false); |
3797 | |
3798 | /// Find the failed Boolean condition within a given Boolean |
3799 | /// constant expression, and describe it with a string. |
3800 | std::pair<Expr *, std::string> findFailedBooleanCondition(Expr *Cond); |
3801 | |
3802 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
3803 | /// non-ArgDependent DiagnoseIfAttrs. |
3804 | /// |
3805 | /// Argument-dependent diagnose_if attributes should be checked each time a |
3806 | /// function is used as a direct callee of a function call. |
3807 | /// |
3808 | /// Returns true if any errors were emitted. |
3809 | bool diagnoseArgDependentDiagnoseIfAttrs(const FunctionDecl *Function, |
3810 | const Expr *ThisArg, |
3811 | ArrayRef<const Expr *> Args, |
3812 | SourceLocation Loc); |
3813 | |
3814 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
3815 | /// ArgDependent DiagnoseIfAttrs. |
3816 | /// |
3817 | /// Argument-independent diagnose_if attributes should be checked on every use |
3818 | /// of a function. |
3819 | /// |
3820 | /// Returns true if any errors were emitted. |
3821 | bool diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND, |
3822 | SourceLocation Loc); |
3823 | |
3824 | /// Returns whether the given function's address can be taken or not, |
3825 | /// optionally emitting a diagnostic if the address can't be taken. |
3826 | /// |
3827 | /// Returns false if taking the address of the function is illegal. |
3828 | bool checkAddressOfFunctionIsAvailable(const FunctionDecl *Function, |
3829 | bool Complain = false, |
3830 | SourceLocation Loc = SourceLocation()); |
3831 | |
3832 | // [PossiblyAFunctionType] --> [Return] |
3833 | // NonFunctionType --> NonFunctionType |
3834 | // R (A) --> R(A) |
3835 | // R (*)(A) --> R (A) |
3836 | // R (&)(A) --> R (A) |
3837 | // R (S::*)(A) --> R (A) |
3838 | QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType); |
3839 | |
3840 | FunctionDecl * |
3841 | ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, |
3842 | QualType TargetType, |
3843 | bool Complain, |
3844 | DeclAccessPair &Found, |
3845 | bool *pHadMultipleCandidates = nullptr); |
3846 | |
3847 | FunctionDecl * |
3848 | resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &FoundResult); |
3849 | |
3850 | bool resolveAndFixAddressOfSingleOverloadCandidate( |
3851 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false); |
3852 | |
3853 | FunctionDecl * |
3854 | ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, |
3855 | bool Complain = false, |
3856 | DeclAccessPair *Found = nullptr); |
3857 | |
3858 | bool ResolveAndFixSingleFunctionTemplateSpecialization( |
3859 | ExprResult &SrcExpr, |
3860 | bool DoFunctionPointerConverion = false, |
3861 | bool Complain = false, |
3862 | SourceRange OpRangeForComplaining = SourceRange(), |
3863 | QualType DestTypeForComplaining = QualType(), |
3864 | unsigned DiagIDForComplaining = 0); |
3865 | |
3866 | |
3867 | Expr *FixOverloadedFunctionReference(Expr *E, |
3868 | DeclAccessPair FoundDecl, |
3869 | FunctionDecl *Fn); |
3870 | ExprResult FixOverloadedFunctionReference(ExprResult, |
3871 | DeclAccessPair FoundDecl, |
3872 | FunctionDecl *Fn); |
3873 | |
3874 | void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, |
3875 | ArrayRef<Expr *> Args, |
3876 | OverloadCandidateSet &CandidateSet, |
3877 | bool PartialOverloading = false); |
3878 | void AddOverloadedCallCandidates( |
3879 | LookupResult &R, TemplateArgumentListInfo *ExplicitTemplateArgs, |
3880 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet); |
3881 | |
3882 | // An enum used to represent the different possible results of building a |
3883 | // range-based for loop. |
3884 | enum ForRangeStatus { |
3885 | FRS_Success, |
3886 | FRS_NoViableFunction, |
3887 | FRS_DiagnosticIssued |
3888 | }; |
3889 | |
3890 | ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc, |
3891 | SourceLocation RangeLoc, |
3892 | const DeclarationNameInfo &NameInfo, |
3893 | LookupResult &MemberLookup, |
3894 | OverloadCandidateSet *CandidateSet, |
3895 | Expr *Range, ExprResult *CallExpr); |
3896 | |
3897 | ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn, |
3898 | UnresolvedLookupExpr *ULE, |
3899 | SourceLocation LParenLoc, |
3900 | MultiExprArg Args, |
3901 | SourceLocation RParenLoc, |
3902 | Expr *ExecConfig, |
3903 | bool AllowTypoCorrection=true, |
3904 | bool CalleesAddressIsTaken=false); |
3905 | |
3906 | bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, |
3907 | MultiExprArg Args, SourceLocation RParenLoc, |
3908 | OverloadCandidateSet *CandidateSet, |
3909 | ExprResult *Result); |
3910 | |
3911 | ExprResult CreateUnresolvedLookupExpr(CXXRecordDecl *NamingClass, |
3912 | NestedNameSpecifierLoc NNSLoc, |
3913 | DeclarationNameInfo DNI, |
3914 | const UnresolvedSetImpl &Fns, |
3915 | bool PerformADL = true); |
3916 | |
3917 | ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, |
3918 | UnaryOperatorKind Opc, |
3919 | const UnresolvedSetImpl &Fns, |
3920 | Expr *input, bool RequiresADL = true); |
3921 | |
3922 | void LookupOverloadedBinOp(OverloadCandidateSet &CandidateSet, |
3923 | OverloadedOperatorKind Op, |
3924 | const UnresolvedSetImpl &Fns, |
3925 | ArrayRef<Expr *> Args, bool RequiresADL = true); |
3926 | ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, |
3927 | BinaryOperatorKind Opc, |
3928 | const UnresolvedSetImpl &Fns, |
3929 | Expr *LHS, Expr *RHS, |
3930 | bool RequiresADL = true, |
3931 | bool AllowRewrittenCandidates = true, |
3932 | FunctionDecl *DefaultedFn = nullptr); |
3933 | ExprResult BuildSynthesizedThreeWayComparison(SourceLocation OpLoc, |
3934 | const UnresolvedSetImpl &Fns, |
3935 | Expr *LHS, Expr *RHS, |
3936 | FunctionDecl *DefaultedFn); |
3937 | |
3938 | ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, |
3939 | SourceLocation RLoc, |
3940 | Expr *Base,Expr *Idx); |
3941 | |
3942 | ExprResult BuildCallToMemberFunction(Scope *S, Expr *MemExpr, |
3943 | SourceLocation LParenLoc, |
3944 | MultiExprArg Args, |
3945 | SourceLocation RParenLoc, |
3946 | Expr *ExecConfig = nullptr, |
3947 | bool IsExecConfig = false, |
3948 | bool AllowRecovery = false); |
3949 | ExprResult |
3950 | BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, |
3951 | MultiExprArg Args, |
3952 | SourceLocation RParenLoc); |
3953 | |
3954 | ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, |
3955 | SourceLocation OpLoc, |
3956 | bool *NoArrowOperatorFound = nullptr); |
3957 | |
3958 | /// CheckCallReturnType - Checks that a call expression's return type is |
3959 | /// complete. Returns true on failure. The location passed in is the location |
3960 | /// that best represents the call. |
3961 | bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, |
3962 | CallExpr *CE, FunctionDecl *FD); |
3963 | |
3964 | /// Helpers for dealing with blocks and functions. |
3965 | bool CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters, |
3966 | bool CheckParameterNames); |
3967 | void CheckCXXDefaultArguments(FunctionDecl *FD); |
3968 | void CheckExtraCXXDefaultArguments(Declarator &D); |
3969 | Scope *getNonFieldDeclScope(Scope *S); |
3970 | |
3971 | /// \name Name lookup |
3972 | /// |
3973 | /// These routines provide name lookup that is used during semantic |
3974 | /// analysis to resolve the various kinds of names (identifiers, |
3975 | /// overloaded operator names, constructor names, etc.) into zero or |
3976 | /// more declarations within a particular scope. The major entry |
3977 | /// points are LookupName, which performs unqualified name lookup, |
3978 | /// and LookupQualifiedName, which performs qualified name lookup. |
3979 | /// |
3980 | /// All name lookup is performed based on some specific criteria, |
3981 | /// which specify what names will be visible to name lookup and how |
3982 | /// far name lookup should work. These criteria are important both |
3983 | /// for capturing language semantics (certain lookups will ignore |
3984 | /// certain names, for example) and for performance, since name |
3985 | /// lookup is often a bottleneck in the compilation of C++. Name |
3986 | /// lookup criteria is specified via the LookupCriteria enumeration. |
3987 | /// |
3988 | /// The results of name lookup can vary based on the kind of name |
3989 | /// lookup performed, the current language, and the translation |
3990 | /// unit. In C, for example, name lookup will either return nothing |
3991 | /// (no entity found) or a single declaration. In C++, name lookup |
3992 | /// can additionally refer to a set of overloaded functions or |
3993 | /// result in an ambiguity. All of the possible results of name |
3994 | /// lookup are captured by the LookupResult class, which provides |
3995 | /// the ability to distinguish among them. |
3996 | //@{ |
3997 | |
3998 | /// Describes the kind of name lookup to perform. |
3999 | enum LookupNameKind { |
4000 | /// Ordinary name lookup, which finds ordinary names (functions, |
4001 | /// variables, typedefs, etc.) in C and most kinds of names |
4002 | /// (functions, variables, members, types, etc.) in C++. |
4003 | LookupOrdinaryName = 0, |
4004 | /// Tag name lookup, which finds the names of enums, classes, |
4005 | /// structs, and unions. |
4006 | LookupTagName, |
4007 | /// Label name lookup. |
4008 | LookupLabel, |
4009 | /// Member name lookup, which finds the names of |
4010 | /// class/struct/union members. |
4011 | LookupMemberName, |
4012 | /// Look up of an operator name (e.g., operator+) for use with |
4013 | /// operator overloading. This lookup is similar to ordinary name |
4014 | /// lookup, but will ignore any declarations that are class members. |
4015 | LookupOperatorName, |
4016 | /// Look up a name following ~ in a destructor name. This is an ordinary |
4017 | /// lookup, but prefers tags to typedefs. |
4018 | LookupDestructorName, |
4019 | /// Look up of a name that precedes the '::' scope resolution |
4020 | /// operator in C++. This lookup completely ignores operator, object, |
4021 | /// function, and enumerator names (C++ [basic.lookup.qual]p1). |
4022 | LookupNestedNameSpecifierName, |
4023 | /// Look up a namespace name within a C++ using directive or |
4024 | /// namespace alias definition, ignoring non-namespace names (C++ |
4025 | /// [basic.lookup.udir]p1). |
4026 | LookupNamespaceName, |
4027 | /// Look up all declarations in a scope with the given name, |
4028 | /// including resolved using declarations. This is appropriate |
4029 | /// for checking redeclarations for a using declaration. |
4030 | LookupUsingDeclName, |
4031 | /// Look up an ordinary name that is going to be redeclared as a |
4032 | /// name with linkage. This lookup ignores any declarations that |
4033 | /// are outside of the current scope unless they have linkage. See |
4034 | /// C99 6.2.2p4-5 and C++ [basic.link]p6. |
4035 | LookupRedeclarationWithLinkage, |
4036 | /// Look up a friend of a local class. This lookup does not look |
4037 | /// outside the innermost non-class scope. See C++11 [class.friend]p11. |
4038 | LookupLocalFriendName, |
4039 | /// Look up the name of an Objective-C protocol. |
4040 | LookupObjCProtocolName, |
4041 | /// Look up implicit 'self' parameter of an objective-c method. |
4042 | LookupObjCImplicitSelfParam, |
4043 | /// Look up the name of an OpenMP user-defined reduction operation. |
4044 | LookupOMPReductionName, |
4045 | /// Look up the name of an OpenMP user-defined mapper. |
4046 | LookupOMPMapperName, |
4047 | /// Look up any declaration with any name. |
4048 | LookupAnyName |
4049 | }; |
4050 | |
4051 | /// Specifies whether (or how) name lookup is being performed for a |
4052 | /// redeclaration (vs. a reference). |
4053 | enum RedeclarationKind { |
4054 | /// The lookup is a reference to this name that is not for the |
4055 | /// purpose of redeclaring the name. |
4056 | NotForRedeclaration = 0, |
4057 | /// The lookup results will be used for redeclaration of a name, |
4058 | /// if an entity by that name already exists and is visible. |
4059 | ForVisibleRedeclaration, |
4060 | /// The lookup results will be used for redeclaration of a name |
4061 | /// with external linkage; non-visible lookup results with external linkage |
4062 | /// may also be found. |
4063 | ForExternalRedeclaration |
4064 | }; |
4065 | |
4066 | RedeclarationKind forRedeclarationInCurContext() { |
4067 | // A declaration with an owning module for linkage can never link against |
4068 | // anything that is not visible. We don't need to check linkage here; if |
4069 | // the context has internal linkage, redeclaration lookup won't find things |
4070 | // from other TUs, and we can't safely compute linkage yet in general. |
4071 | if (cast<Decl>(CurContext) |
4072 | ->getOwningModuleForLinkage(/*IgnoreLinkage*/true)) |
4073 | return ForVisibleRedeclaration; |
4074 | return ForExternalRedeclaration; |
4075 | } |
4076 | |
4077 | /// The possible outcomes of name lookup for a literal operator. |
4078 | enum LiteralOperatorLookupResult { |
4079 | /// The lookup resulted in an error. |
4080 | LOLR_Error, |
4081 | /// The lookup found no match but no diagnostic was issued. |
4082 | LOLR_ErrorNoDiagnostic, |
4083 | /// The lookup found a single 'cooked' literal operator, which |
4084 | /// expects a normal literal to be built and passed to it. |
4085 | LOLR_Cooked, |
4086 | /// The lookup found a single 'raw' literal operator, which expects |
4087 | /// a string literal containing the spelling of the literal token. |
4088 | LOLR_Raw, |
4089 | /// The lookup found an overload set of literal operator templates, |
4090 | /// which expect the characters of the spelling of the literal token to be |
4091 | /// passed as a non-type template argument pack. |
4092 | LOLR_Template, |
4093 | /// The lookup found an overload set of literal operator templates, |
4094 | /// which expect the character type and characters of the spelling of the |
4095 | /// string literal token to be passed as template arguments. |
4096 | LOLR_StringTemplatePack, |
4097 | }; |
4098 | |
4099 | SpecialMemberOverloadResult LookupSpecialMember(CXXRecordDecl *D, |
4100 | CXXSpecialMember SM, |
4101 | bool ConstArg, |
4102 | bool VolatileArg, |
4103 | bool RValueThis, |
4104 | bool ConstThis, |
4105 | bool VolatileThis); |
4106 | |
4107 | typedef std::function<void(const TypoCorrection &)> TypoDiagnosticGenerator; |
4108 | typedef std::function<ExprResult(Sema &, TypoExpr *, TypoCorrection)> |
4109 | TypoRecoveryCallback; |
4110 | |
4111 | private: |
4112 | bool CppLookupName(LookupResult &R, Scope *S); |
4113 | |
4114 | struct TypoExprState { |
4115 | std::unique_ptr<TypoCorrectionConsumer> Consumer; |
4116 | TypoDiagnosticGenerator DiagHandler; |
4117 | TypoRecoveryCallback RecoveryHandler; |
4118 | TypoExprState(); |
4119 | TypoExprState(TypoExprState &&other) noexcept; |
4120 | TypoExprState &operator=(TypoExprState &&other) noexcept; |
4121 | }; |
4122 | |
4123 | /// The set of unhandled TypoExprs and their associated state. |
4124 | llvm::MapVector<TypoExpr *, TypoExprState> DelayedTypos; |
4125 | |
4126 | /// Creates a new TypoExpr AST node. |
4127 | TypoExpr *createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC, |
4128 | TypoDiagnosticGenerator TDG, |
4129 | TypoRecoveryCallback TRC, SourceLocation TypoLoc); |
4130 | |
4131 | // The set of known/encountered (unique, canonicalized) NamespaceDecls. |
4132 | // |
4133 | // The boolean value will be true to indicate that the namespace was loaded |
4134 | // from an AST/PCH file, or false otherwise. |
4135 | llvm::MapVector<NamespaceDecl*, bool> KnownNamespaces; |
4136 | |
4137 | /// Whether we have already loaded known namespaces from an extenal |
4138 | /// source. |
4139 | bool LoadedExternalKnownNamespaces; |
4140 | |
4141 | /// Helper for CorrectTypo and CorrectTypoDelayed used to create and |
4142 | /// populate a new TypoCorrectionConsumer. Returns nullptr if typo correction |
4143 | /// should be skipped entirely. |
4144 | std::unique_ptr<TypoCorrectionConsumer> |
4145 | makeTypoCorrectionConsumer(const DeclarationNameInfo &Typo, |
4146 | Sema::LookupNameKind LookupKind, Scope *S, |
4147 | CXXScopeSpec *SS, |
4148 | CorrectionCandidateCallback &CCC, |
4149 | DeclContext *MemberContext, bool EnteringContext, |
4150 | const ObjCObjectPointerType *OPT, |
4151 | bool ErrorRecovery); |
4152 | |
4153 | public: |
4154 | const TypoExprState &getTypoExprState(TypoExpr *TE) const; |
4155 | |
4156 | /// Clears the state of the given TypoExpr. |
4157 | void clearDelayedTypo(TypoExpr *TE); |
4158 | |
4159 | /// Look up a name, looking for a single declaration. Return |
4160 | /// null if the results were absent, ambiguous, or overloaded. |
4161 | /// |
4162 | /// It is preferable to use the elaborated form and explicitly handle |
4163 | /// ambiguity and overloaded. |
4164 | NamedDecl *LookupSingleName(Scope *S, DeclarationName Name, |
4165 | SourceLocation Loc, |
4166 | LookupNameKind NameKind, |
4167 | RedeclarationKind Redecl |
4168 | = NotForRedeclaration); |
4169 | bool LookupBuiltin(LookupResult &R); |
4170 | void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID); |
4171 | bool LookupName(LookupResult &R, Scope *S, |
4172 | bool AllowBuiltinCreation = false); |
4173 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
4174 | bool InUnqualifiedLookup = false); |
4175 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
4176 | CXXScopeSpec &SS); |
4177 | bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, |
4178 | bool AllowBuiltinCreation = false, |
4179 | bool EnteringContext = false); |
4180 | ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, |
4181 | RedeclarationKind Redecl |
4182 | = NotForRedeclaration); |
4183 | bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class); |
4184 | |
4185 | void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, |
4186 | UnresolvedSetImpl &Functions); |
4187 | |
4188 | LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, |
4189 | SourceLocation GnuLabelLoc = SourceLocation()); |
4190 | |
4191 | DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); |
4192 | CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class); |
4193 | CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class, |
4194 | unsigned Quals); |
4195 | CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, |
4196 | bool RValueThis, unsigned ThisQuals); |
4197 | CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class, |
4198 | unsigned Quals); |
4199 | CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals, |
4200 | bool RValueThis, unsigned ThisQuals); |
4201 | CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); |
4202 | |
4203 | bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id, |
4204 | bool IsUDSuffix); |
4205 | LiteralOperatorLookupResult |
4206 | LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef<QualType> ArgTys, |
4207 | bool AllowRaw, bool AllowTemplate, |
4208 | bool AllowStringTemplate, bool DiagnoseMissing, |
4209 | StringLiteral *StringLit = nullptr); |
4210 | bool isKnownName(StringRef name); |
4211 | |
4212 | /// Status of the function emission on the CUDA/HIP/OpenMP host/device attrs. |
4213 | enum class FunctionEmissionStatus { |
4214 | Emitted, |
4215 | CUDADiscarded, // Discarded due to CUDA/HIP hostness |
4216 | OMPDiscarded, // Discarded due to OpenMP hostness |
4217 | TemplateDiscarded, // Discarded due to uninstantiated templates |
4218 | Unknown, |
4219 | }; |
4220 | FunctionEmissionStatus getEmissionStatus(FunctionDecl *Decl, |
4221 | bool Final = false); |
4222 | |
4223 | // Whether the callee should be ignored in CUDA/HIP/OpenMP host/device check. |
4224 | bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee); |
4225 | |
4226 | void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc, |
4227 | ArrayRef<Expr *> Args, ADLResult &Functions); |
4228 | |
4229 | void LookupVisibleDecls(Scope *S, LookupNameKind Kind, |
4230 | VisibleDeclConsumer &Consumer, |
4231 | bool IncludeGlobalScope = true, |
4232 | bool LoadExternal = true); |
4233 | void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, |
4234 | VisibleDeclConsumer &Consumer, |
4235 | bool IncludeGlobalScope = true, |
4236 | bool IncludeDependentBases = false, |
4237 | bool LoadExternal = true); |
4238 | |
4239 | enum CorrectTypoKind { |
4240 | CTK_NonError, // CorrectTypo used in a non error recovery situation. |
4241 | CTK_ErrorRecovery // CorrectTypo used in normal error recovery. |
4242 | }; |
4243 | |
4244 | TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, |
4245 | Sema::LookupNameKind LookupKind, |
4246 | Scope *S, CXXScopeSpec *SS, |
4247 | CorrectionCandidateCallback &CCC, |
4248 | CorrectTypoKind Mode, |
4249 | DeclContext *MemberContext = nullptr, |
4250 | bool EnteringContext = false, |
4251 | const ObjCObjectPointerType *OPT = nullptr, |
4252 | bool RecordFailure = true); |
4253 | |
4254 | TypoExpr *CorrectTypoDelayed(const DeclarationNameInfo &Typo, |
4255 | Sema::LookupNameKind LookupKind, Scope *S, |
4256 | CXXScopeSpec *SS, |
4257 | CorrectionCandidateCallback &CCC, |
4258 | TypoDiagnosticGenerator TDG, |
4259 | TypoRecoveryCallback TRC, CorrectTypoKind Mode, |
4260 | DeclContext *MemberContext = nullptr, |
4261 | bool EnteringContext = false, |
4262 | const ObjCObjectPointerType *OPT = nullptr); |
4263 | |
4264 | /// Process any TypoExprs in the given Expr and its children, |
4265 | /// generating diagnostics as appropriate and returning a new Expr if there |
4266 | /// were typos that were all successfully corrected and ExprError if one or |
4267 | /// more typos could not be corrected. |
4268 | /// |
4269 | /// \param E The Expr to check for TypoExprs. |
4270 | /// |
4271 | /// \param InitDecl A VarDecl to avoid because the Expr being corrected is its |
4272 | /// initializer. |
4273 | /// |
4274 | /// \param RecoverUncorrectedTypos If true, when typo correction fails, it |
4275 | /// will rebuild the given Expr with all TypoExprs degraded to RecoveryExprs. |
4276 | /// |
4277 | /// \param Filter A function applied to a newly rebuilt Expr to determine if |
4278 | /// it is an acceptable/usable result from a single combination of typo |
4279 | /// corrections. As long as the filter returns ExprError, different |
4280 | /// combinations of corrections will be tried until all are exhausted. |
4281 | ExprResult CorrectDelayedTyposInExpr( |
4282 | Expr *E, VarDecl *InitDecl = nullptr, |
4283 | bool RecoverUncorrectedTypos = false, |
4284 | llvm::function_ref<ExprResult(Expr *)> Filter = |
4285 | [](Expr *E) -> ExprResult { return E; }); |
4286 | |
4287 | ExprResult CorrectDelayedTyposInExpr( |
4288 | ExprResult ER, VarDecl *InitDecl = nullptr, |
4289 | bool RecoverUncorrectedTypos = false, |
4290 | llvm::function_ref<ExprResult(Expr *)> Filter = |
4291 | [](Expr *E) -> ExprResult { return E; }) { |
4292 | return ER.isInvalid() |
4293 | ? ER |
4294 | : CorrectDelayedTyposInExpr(ER.get(), InitDecl, |
4295 | RecoverUncorrectedTypos, Filter); |
4296 | } |
4297 | |
4298 | void diagnoseTypo(const TypoCorrection &Correction, |
4299 | const PartialDiagnostic &TypoDiag, |
4300 | bool ErrorRecovery = true); |
4301 | |
4302 | void diagnoseTypo(const TypoCorrection &Correction, |
4303 | const PartialDiagnostic &TypoDiag, |
4304 | const PartialDiagnostic &PrevNote, |
4305 | bool ErrorRecovery = true); |
4306 | |
4307 | void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F); |
4308 | |
4309 | void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc, |
4310 | ArrayRef<Expr *> Args, |
4311 | AssociatedNamespaceSet &AssociatedNamespaces, |
4312 | AssociatedClassSet &AssociatedClasses); |
4313 | |
4314 | void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, |
4315 | bool ConsiderLinkage, bool AllowInlineNamespace); |
4316 | |
4317 | bool CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old); |
4318 | |
4319 | void DiagnoseAmbiguousLookup(LookupResult &Result); |
4320 | //@} |
4321 | |
4322 | /// Attempts to produce a RecoveryExpr after some AST node cannot be created. |
4323 | ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, |
4324 | ArrayRef<Expr *> SubExprs, |
4325 | QualType T = QualType()); |
4326 | |
4327 | ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id, |
4328 | SourceLocation IdLoc, |
4329 | bool TypoCorrection = false); |
4330 | FunctionDecl *CreateBuiltin(IdentifierInfo *II, QualType Type, unsigned ID, |
4331 | SourceLocation Loc); |
4332 | NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, |
4333 | Scope *S, bool ForRedeclaration, |
4334 | SourceLocation Loc); |
4335 | NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
4336 | Scope *S); |
4337 | void AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction( |
4338 | FunctionDecl *FD); |
4339 | void AddKnownFunctionAttributes(FunctionDecl *FD); |
4340 | |
4341 | // More parsing and symbol table subroutines. |
4342 | |
4343 | void ProcessPragmaWeak(Scope *S, Decl *D); |
4344 | // Decl attributes - this routine is the top level dispatcher. |
4345 | void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD); |
4346 | // Helper for delayed processing of attributes. |
4347 | void ProcessDeclAttributeDelayed(Decl *D, |
4348 | const ParsedAttributesView &AttrList); |
4349 | void ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AL, |
4350 | bool IncludeCXX11Attributes = true); |
4351 | bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, |
4352 | const ParsedAttributesView &AttrList); |
4353 | |
4354 | void checkUnusedDeclAttributes(Declarator &D); |
4355 | |
4356 | /// Handles semantic checking for features that are common to all attributes, |
4357 | /// such as checking whether a parameter was properly specified, or the |
4358 | /// correct number of arguments were passed, etc. Returns true if the |
4359 | /// attribute has been diagnosed. |
4360 | bool checkCommonAttributeFeatures(const Decl *D, const ParsedAttr &A); |
4361 | bool checkCommonAttributeFeatures(const Stmt *S, const ParsedAttr &A); |
4362 | |
4363 | /// Determine if type T is a valid subject for a nonnull and similar |
4364 | /// attributes. By default, we look through references (the behavior used by |
4365 | /// nonnull), but if the second parameter is true, then we treat a reference |
4366 | /// type as valid. |
4367 | bool isValidPointerAttrType(QualType T, bool RefOkay = false); |
4368 | |
4369 | bool CheckRegparmAttr(const ParsedAttr &attr, unsigned &value); |
4370 | bool CheckCallingConvAttr(const ParsedAttr &attr, CallingConv &CC, |
4371 | const FunctionDecl *FD = nullptr); |
4372 | bool CheckAttrTarget(const ParsedAttr &CurrAttr); |
4373 | bool CheckAttrNoArgs(const ParsedAttr &CurrAttr); |
4374 | bool checkStringLiteralArgumentAttr(const ParsedAttr &Attr, unsigned ArgNum, |
4375 | StringRef &Str, |
4376 | SourceLocation *ArgLocation = nullptr); |
4377 | llvm::Error isValidSectionSpecifier(StringRef Str); |
4378 | bool checkSectionName(SourceLocation LiteralLoc, StringRef Str); |
4379 | bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str); |
4380 | bool checkTargetClonesAttrString(SourceLocation LiteralLoc, StringRef Str, |
4381 | const StringLiteral *Literal, |
4382 | bool &HasDefault, bool &HasCommas, |
4383 | SmallVectorImpl<StringRef> &Strings); |
4384 | bool checkMSInheritanceAttrOnDefinition( |
4385 | CXXRecordDecl *RD, SourceRange Range, bool BestCase, |
4386 | MSInheritanceModel SemanticSpelling); |
4387 | |
4388 | void CheckAlignasUnderalignment(Decl *D); |
4389 | |
4390 | /// Adjust the calling convention of a method to be the ABI default if it |
4391 | /// wasn't specified explicitly. This handles method types formed from |
4392 | /// function type typedefs and typename template arguments. |
4393 | void adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor, |
4394 | SourceLocation Loc); |
4395 | |
4396 | // Check if there is an explicit attribute, but only look through parens. |
4397 | // The intent is to look for an attribute on the current declarator, but not |
4398 | // one that came from a typedef. |
4399 | bool hasExplicitCallingConv(QualType T); |
4400 | |
4401 | /// Get the outermost AttributedType node that sets a calling convention. |
4402 | /// Valid types should not have multiple attributes with different CCs. |
4403 | const AttributedType *getCallingConvAttributedType(QualType T) const; |
4404 | |
4405 | /// Process the attributes before creating an attributed statement. Returns |
4406 | /// the semantic attributes that have been processed. |
4407 | void ProcessStmtAttributes(Stmt *Stmt, |
4408 | const ParsedAttributesWithRange &InAttrs, |
4409 | SmallVectorImpl<const Attr *> &OutAttrs); |
4410 | |
4411 | void WarnConflictingTypedMethods(ObjCMethodDecl *Method, |
4412 | ObjCMethodDecl *MethodDecl, |
4413 | bool IsProtocolMethodDecl); |
4414 | |
4415 | void CheckConflictingOverridingMethod(ObjCMethodDecl *Method, |
4416 | ObjCMethodDecl *Overridden, |
4417 | bool IsProtocolMethodDecl); |
4418 | |
4419 | /// WarnExactTypedMethods - This routine issues a warning if method |
4420 | /// implementation declaration matches exactly that of its declaration. |
4421 | void WarnExactTypedMethods(ObjCMethodDecl *Method, |
4422 | ObjCMethodDecl *MethodDecl, |
4423 | bool IsProtocolMethodDecl); |
4424 | |
4425 | typedef llvm::SmallPtrSet<Selector, 8> SelectorSet; |
4426 | |
4427 | /// CheckImplementationIvars - This routine checks if the instance variables |
4428 | /// listed in the implelementation match those listed in the interface. |
4429 | void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, |
4430 | ObjCIvarDecl **Fields, unsigned nIvars, |
4431 | SourceLocation Loc); |
4432 | |
4433 | /// ImplMethodsVsClassMethods - This is main routine to warn if any method |
4434 | /// remains unimplemented in the class or category \@implementation. |
4435 | void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, |
4436 | ObjCContainerDecl* IDecl, |
4437 | bool IncompleteImpl = false); |
4438 | |
4439 | /// DiagnoseUnimplementedProperties - This routine warns on those properties |
4440 | /// which must be implemented by this implementation. |
4441 | void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, |
4442 | ObjCContainerDecl *CDecl, |
4443 | bool SynthesizeProperties); |
4444 | |
4445 | /// Diagnose any null-resettable synthesized setters. |
4446 | void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl); |
4447 | |
4448 | /// DefaultSynthesizeProperties - This routine default synthesizes all |
4449 | /// properties which must be synthesized in the class's \@implementation. |
4450 | void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, |
4451 | ObjCInterfaceDecl *IDecl, |
4452 | SourceLocation AtEnd); |
4453 | void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd); |
4454 | |
4455 | /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is |
4456 | /// an ivar synthesized for 'Method' and 'Method' is a property accessor |
4457 | /// declared in class 'IFace'. |
4458 | bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace, |
4459 | ObjCMethodDecl *Method, ObjCIvarDecl *IV); |
4460 | |
4461 | /// DiagnoseUnusedBackingIvarInAccessor - Issue an 'unused' warning if ivar which |
4462 | /// backs the property is not used in the property's accessor. |
4463 | void DiagnoseUnusedBackingIvarInAccessor(Scope *S, |
4464 | const ObjCImplementationDecl *ImplD); |
4465 | |
4466 | /// GetIvarBackingPropertyAccessor - If method is a property setter/getter and |
4467 | /// it property has a backing ivar, returns this ivar; otherwise, returns NULL. |
4468 | /// It also returns ivar's property on success. |
4469 | ObjCIvarDecl *GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method, |
4470 | const ObjCPropertyDecl *&PDecl) const; |
4471 | |
4472 | /// Called by ActOnProperty to handle \@property declarations in |
4473 | /// class extensions. |
4474 | ObjCPropertyDecl *HandlePropertyInClassExtension(Scope *S, |
4475 | SourceLocation AtLoc, |
4476 | SourceLocation LParenLoc, |
4477 | FieldDeclarator &FD, |
4478 | Selector GetterSel, |
4479 | SourceLocation GetterNameLoc, |
4480 | Selector SetterSel, |
4481 | SourceLocation SetterNameLoc, |
4482 | const bool isReadWrite, |
4483 | unsigned &Attributes, |
4484 | const unsigned AttributesAsWritten, |
4485 | QualType T, |
4486 | TypeSourceInfo *TSI, |
4487 | tok::ObjCKeywordKind MethodImplKind); |
4488 | |
4489 | /// Called by ActOnProperty and HandlePropertyInClassExtension to |
4490 | /// handle creating the ObjcPropertyDecl for a category or \@interface. |
4491 | ObjCPropertyDecl *CreatePropertyDecl(Scope *S, |
4492 | ObjCContainerDecl *CDecl, |
4493 | SourceLocation AtLoc, |
4494 | SourceLocation LParenLoc, |
4495 | FieldDeclarator &FD, |
4496 | Selector GetterSel, |
4497 | SourceLocation GetterNameLoc, |
4498 | Selector SetterSel, |
4499 | SourceLocation SetterNameLoc, |
4500 | const bool isReadWrite, |
4501 | const unsigned Attributes, |
4502 | const unsigned AttributesAsWritten, |
4503 | QualType T, |
4504 | TypeSourceInfo *TSI, |
4505 | tok::ObjCKeywordKind MethodImplKind, |
4506 | DeclContext *lexicalDC = nullptr); |
4507 | |
4508 | /// AtomicPropertySetterGetterRules - This routine enforces the rule (via |
4509 | /// warning) when atomic property has one but not the other user-declared |
4510 | /// setter or getter. |
4511 | void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl, |
4512 | ObjCInterfaceDecl* IDecl); |
4513 | |
4514 | void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D); |
4515 | |
4516 | void DiagnoseMissingDesignatedInitOverrides( |
4517 | const ObjCImplementationDecl *ImplD, |
4518 | const ObjCInterfaceDecl *IFD); |
4519 | |
4520 | void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); |
4521 | |
4522 | enum MethodMatchStrategy { |
4523 | MMS_loose, |
4524 | MMS_strict |
4525 | }; |
4526 | |
4527 | /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns |
4528 | /// true, or false, accordingly. |
4529 | bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, |
4530 | const ObjCMethodDecl *PrevMethod, |
4531 | MethodMatchStrategy strategy = MMS_strict); |
4532 | |
4533 | /// MatchAllMethodDeclarations - Check methods declaraed in interface or |
4534 | /// or protocol against those declared in their implementations. |
4535 | void MatchAllMethodDeclarations(const SelectorSet &InsMap, |
4536 | const SelectorSet &ClsMap, |
4537 | SelectorSet &InsMapSeen, |
4538 | SelectorSet &ClsMapSeen, |
4539 | ObjCImplDecl* IMPDecl, |
4540 | ObjCContainerDecl* IDecl, |
4541 | bool &IncompleteImpl, |
4542 | bool ImmediateClass, |
4543 | bool WarnCategoryMethodImpl=false); |
4544 | |
4545 | /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in |
4546 | /// category matches with those implemented in its primary class and |
4547 | /// warns each time an exact match is found. |
4548 | void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP); |
4549 | |
4550 | /// Add the given method to the list of globally-known methods. |
4551 | void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method); |
4552 | |
4553 | /// Returns default addr space for method qualifiers. |
4554 | LangAS getDefaultCXXMethodAddrSpace() const; |
4555 | |
4556 | private: |
4557 | /// AddMethodToGlobalPool - Add an instance or factory method to the global |
4558 | /// pool. See descriptoin of AddInstanceMethodToGlobalPool. |
4559 | void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); |
4560 | |
4561 | /// LookupMethodInGlobalPool - Returns the instance or factory method and |
4562 | /// optionally warns if there are multiple signatures. |
4563 | ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, |
4564 | bool receiverIdOrClass, |
4565 | bool instance); |
4566 | |
4567 | public: |
4568 | /// - Returns instance or factory methods in global method pool for |
4569 | /// given selector. It checks the desired kind first, if none is found, and |
4570 | /// parameter checkTheOther is set, it then checks the other kind. If no such |
4571 | /// method or only one method is found, function returns false; otherwise, it |
4572 | /// returns true. |
4573 | bool |
4574 | CollectMultipleMethodsInGlobalPool(Selector Sel, |
4575 | SmallVectorImpl<ObjCMethodDecl*>& Methods, |
4576 | bool InstanceFirst, bool CheckTheOther, |
4577 | const ObjCObjectType *TypeBound = nullptr); |
4578 | |
4579 | bool |
4580 | AreMultipleMethodsInGlobalPool(Selector Sel, ObjCMethodDecl *BestMethod, |
4581 | SourceRange R, bool receiverIdOrClass, |
4582 | SmallVectorImpl<ObjCMethodDecl*>& Methods); |
4583 | |
4584 | void |
4585 | DiagnoseMultipleMethodInGlobalPool(SmallVectorImpl<ObjCMethodDecl*> &Methods, |
4586 | Selector Sel, SourceRange R, |
4587 | bool receiverIdOrClass); |
4588 | |
4589 | private: |
4590 | /// - Returns a selector which best matches given argument list or |
4591 | /// nullptr if none could be found |
4592 | ObjCMethodDecl *SelectBestMethod(Selector Sel, MultiExprArg Args, |
4593 | bool IsInstance, |
4594 | SmallVectorImpl<ObjCMethodDecl*>& Methods); |
4595 | |
4596 | |
4597 | /// Record the typo correction failure and return an empty correction. |
4598 | TypoCorrection FailedCorrection(IdentifierInfo *Typo, SourceLocation TypoLoc, |
4599 | bool RecordFailure = true) { |
4600 | if (RecordFailure) |
4601 | TypoCorrectionFailures[Typo].insert(TypoLoc); |
4602 | return TypoCorrection(); |
4603 | } |
4604 | |
4605 | public: |
4606 | /// AddInstanceMethodToGlobalPool - All instance methods in a translation |
4607 | /// unit are added to a global pool. This allows us to efficiently associate |
4608 | /// a selector with a method declaraation for purposes of typechecking |
4609 | /// messages sent to "id" (where the class of the object is unknown). |
4610 | void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { |
4611 | AddMethodToGlobalPool(Method, impl, /*instance*/true); |
4612 | } |
4613 | |
4614 | /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. |
4615 | void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { |
4616 | AddMethodToGlobalPool(Method, impl, /*instance*/false); |
4617 | } |
4618 | |
4619 | /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global |
4620 | /// pool. |
4621 | void AddAnyMethodToGlobalPool(Decl *D); |
4622 | |
4623 | /// LookupInstanceMethodInGlobalPool - Returns the method and warns if |
4624 | /// there are multiple signatures. |
4625 | ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, |
4626 | bool receiverIdOrClass=false) { |
4627 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
4628 | /*instance*/true); |
4629 | } |
4630 | |
4631 | /// LookupFactoryMethodInGlobalPool - Returns the method and warns if |
4632 | /// there are multiple signatures. |
4633 | ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, |
4634 | bool receiverIdOrClass=false) { |
4635 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
4636 | /*instance*/false); |
4637 | } |
4638 | |
4639 | const ObjCMethodDecl *SelectorsForTypoCorrection(Selector Sel, |
4640 | QualType ObjectType=QualType()); |
4641 | /// LookupImplementedMethodInGlobalPool - Returns the method which has an |
4642 | /// implementation. |
4643 | ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); |
4644 | |
4645 | /// CollectIvarsToConstructOrDestruct - Collect those ivars which require |
4646 | /// initialization. |
4647 | void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, |
4648 | SmallVectorImpl<ObjCIvarDecl*> &Ivars); |
4649 | |
4650 | //===--------------------------------------------------------------------===// |
4651 | // Statement Parsing Callbacks: SemaStmt.cpp. |
4652 | public: |
4653 | class FullExprArg { |
4654 | public: |
4655 | FullExprArg() : E(nullptr) { } |
4656 | FullExprArg(Sema &actions) : E(nullptr) { } |
4657 | |
4658 | ExprResult release() { |
4659 | return E; |
4660 | } |
4661 | |
4662 | Expr *get() const { return E; } |
4663 | |
4664 | Expr *operator->() { |
4665 | return E; |
4666 | } |
4667 | |
4668 | private: |
4669 | // FIXME: No need to make the entire Sema class a friend when it's just |
4670 | // Sema::MakeFullExpr that needs access to the constructor below. |
4671 | friend class Sema; |
4672 | |
4673 | explicit FullExprArg(Expr *expr) : E(expr) {} |
4674 | |
4675 | Expr *E; |
4676 | }; |
4677 | |
4678 | FullExprArg MakeFullExpr(Expr *Arg) { |
4679 | return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation()); |
4680 | } |
4681 | FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) { |
4682 | return FullExprArg( |
4683 | ActOnFinishFullExpr(Arg, CC, /*DiscardedValue*/ false).get()); |
4684 | } |
4685 | FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) { |
4686 | ExprResult FE = |
4687 | ActOnFinishFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation(), |
4688 | /*DiscardedValue*/ true); |
4689 | return FullExprArg(FE.get()); |
4690 | } |
4691 | |
4692 | StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue = true); |
4693 | StmtResult ActOnExprStmtError(); |
4694 | |
4695 | StmtResult ActOnNullStmt(SourceLocation SemiLoc, |
4696 | bool HasLeadingEmptyMacro = false); |
4697 | |
4698 | void ActOnStartOfCompoundStmt(bool IsStmtExpr); |
4699 | void ActOnAfterCompoundStatementLeadingPragmas(); |
4700 | void ActOnFinishOfCompoundStmt(); |
4701 | StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
4702 | ArrayRef<Stmt *> Elts, bool isStmtExpr); |
4703 | |
4704 | /// A RAII object to enter scope of a compound statement. |
4705 | class CompoundScopeRAII { |
4706 | public: |
4707 | CompoundScopeRAII(Sema &S, bool IsStmtExpr = false) : S(S) { |
4708 | S.ActOnStartOfCompoundStmt(IsStmtExpr); |
4709 | } |
4710 | |
4711 | ~CompoundScopeRAII() { |
4712 | S.ActOnFinishOfCompoundStmt(); |
4713 | } |
4714 | |
4715 | private: |
4716 | Sema &S; |
4717 | }; |
4718 | |
4719 | /// An RAII helper that pops function a function scope on exit. |
4720 | struct FunctionScopeRAII { |
4721 | Sema &S; |
4722 | bool Active; |
4723 | FunctionScopeRAII(Sema &S) : S(S), Active(true) {} |
4724 | ~FunctionScopeRAII() { |
4725 | if (Active) |
4726 | S.PopFunctionScopeInfo(); |
4727 | } |
4728 | void disable() { Active = false; } |
4729 | }; |
4730 | |
4731 | StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, |
4732 | SourceLocation StartLoc, |
4733 | SourceLocation EndLoc); |
4734 | void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); |
4735 | StmtResult ActOnForEachLValueExpr(Expr *E); |
4736 | ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val); |
4737 | StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, |
4738 | SourceLocation DotDotDotLoc, ExprResult RHS, |
4739 | SourceLocation ColonLoc); |
4740 | void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); |
4741 | |
4742 | StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, |
4743 | SourceLocation ColonLoc, |
4744 | Stmt *SubStmt, Scope *CurScope); |
4745 | StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, |
4746 | SourceLocation ColonLoc, Stmt *SubStmt); |
4747 | |
4748 | StmtResult BuildAttributedStmt(SourceLocation AttrsLoc, |
4749 | ArrayRef<const Attr *> Attrs, Stmt *SubStmt); |
4750 | StmtResult ActOnAttributedStmt(const ParsedAttributesWithRange &AttrList, |
4751 | Stmt *SubStmt); |
4752 | |
4753 | class ConditionResult; |
4754 | |
4755 | StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, |
4756 | SourceLocation LParenLoc, Stmt *InitStmt, |
4757 | ConditionResult Cond, SourceLocation RParenLoc, |
4758 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
4759 | StmtResult BuildIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, |
4760 | SourceLocation LParenLoc, Stmt *InitStmt, |
4761 | ConditionResult Cond, SourceLocation RParenLoc, |
4762 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
4763 | StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, |
4764 | SourceLocation LParenLoc, Stmt *InitStmt, |
4765 | ConditionResult Cond, |
4766 | SourceLocation RParenLoc); |
4767 | StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, |
4768 | Stmt *Switch, Stmt *Body); |
4769 | StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, |
4770 | ConditionResult Cond, SourceLocation RParenLoc, |
4771 | Stmt *Body); |
4772 | StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, |
4773 | SourceLocation WhileLoc, SourceLocation CondLParen, |
4774 | Expr *Cond, SourceLocation CondRParen); |
4775 | |
4776 | StmtResult ActOnForStmt(SourceLocation ForLoc, |
4777 | SourceLocation LParenLoc, |
4778 | Stmt *First, |
4779 | ConditionResult Second, |
4780 | FullExprArg Third, |
4781 | SourceLocation RParenLoc, |
4782 | Stmt *Body); |
4783 | ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, |
4784 | Expr *collection); |
4785 | StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, |
4786 | Stmt *First, Expr *collection, |
4787 | SourceLocation RParenLoc); |
4788 | StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body); |
4789 | |
4790 | enum BuildForRangeKind { |
4791 | /// Initial building of a for-range statement. |
4792 | BFRK_Build, |
4793 | /// Instantiation or recovery rebuild of a for-range statement. Don't |
4794 | /// attempt any typo-correction. |
4795 | BFRK_Rebuild, |
4796 | /// Determining whether a for-range statement could be built. Avoid any |
4797 | /// unnecessary or irreversible actions. |
4798 | BFRK_Check |
4799 | }; |
4800 | |
4801 | StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc, |
4802 | SourceLocation CoawaitLoc, |
4803 | Stmt *InitStmt, |
4804 | Stmt *LoopVar, |
4805 | SourceLocation ColonLoc, Expr *Collection, |
4806 | SourceLocation RParenLoc, |
4807 | BuildForRangeKind Kind); |
4808 | StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, |
4809 | SourceLocation CoawaitLoc, |
4810 | Stmt *InitStmt, |
4811 | SourceLocation ColonLoc, |
4812 | Stmt *RangeDecl, Stmt *Begin, Stmt *End, |
4813 | Expr *Cond, Expr *Inc, |
4814 | Stmt *LoopVarDecl, |
4815 | SourceLocation RParenLoc, |
4816 | BuildForRangeKind Kind); |
4817 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body); |
4818 | |
4819 | StmtResult ActOnGotoStmt(SourceLocation GotoLoc, |
4820 | SourceLocation LabelLoc, |
4821 | LabelDecl *TheDecl); |
4822 | StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, |
4823 | SourceLocation StarLoc, |
4824 | Expr *DestExp); |
4825 | StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope); |
4826 | StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope); |
4827 | |
4828 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
4829 | CapturedRegionKind Kind, unsigned NumParams); |
4830 | typedef std::pair<StringRef, QualType> CapturedParamNameType; |
4831 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
4832 | CapturedRegionKind Kind, |
4833 | ArrayRef<CapturedParamNameType> Params, |
4834 | unsigned OpenMPCaptureLevel = 0); |
4835 | StmtResult ActOnCapturedRegionEnd(Stmt *S); |
4836 | void ActOnCapturedRegionError(); |
4837 | RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD, |
4838 | SourceLocation Loc, |
4839 | unsigned NumParams); |
4840 | |
4841 | struct NamedReturnInfo { |
4842 | const VarDecl *Candidate; |
4843 | |
4844 | enum Status : uint8_t { None, MoveEligible, MoveEligibleAndCopyElidable }; |
4845 | Status S; |
4846 | |
4847 | bool isMoveEligible() const { return S != None; }; |
4848 | bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; } |
4849 | }; |
4850 | enum class SimplerImplicitMoveMode { ForceOff, Normal, ForceOn }; |
4851 | NamedReturnInfo getNamedReturnInfo( |
4852 | Expr *&E, SimplerImplicitMoveMode Mode = SimplerImplicitMoveMode::Normal); |
4853 | NamedReturnInfo getNamedReturnInfo(const VarDecl *VD); |
4854 | const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info, |
4855 | QualType ReturnType); |
4856 | |
4857 | ExprResult |
4858 | PerformMoveOrCopyInitialization(const InitializedEntity &Entity, |
4859 | const NamedReturnInfo &NRInfo, Expr *Value, |
4860 | bool SupressSimplerImplicitMoves = false); |
4861 | |
4862 | StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
4863 | Scope *CurScope); |
4864 | StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
4865 | bool AllowRecovery = false); |
4866 | StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
4867 | NamedReturnInfo &NRInfo, |
4868 | bool SupressSimplerImplicitMoves); |
4869 | |
4870 | StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
4871 | bool IsVolatile, unsigned NumOutputs, |
4872 | unsigned NumInputs, IdentifierInfo **Names, |
4873 | MultiExprArg Constraints, MultiExprArg Exprs, |
4874 | Expr *AsmString, MultiExprArg Clobbers, |
4875 | unsigned NumLabels, |
4876 | SourceLocation RParenLoc); |
4877 | |
4878 | void FillInlineAsmIdentifierInfo(Expr *Res, |
4879 | llvm::InlineAsmIdentifierInfo &Info); |
4880 | ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS, |
4881 | SourceLocation TemplateKWLoc, |
4882 | UnqualifiedId &Id, |
4883 | bool IsUnevaluatedContext); |
4884 | bool LookupInlineAsmField(StringRef Base, StringRef Member, |
4885 | unsigned &Offset, SourceLocation AsmLoc); |
4886 | ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member, |
4887 | SourceLocation AsmLoc); |
4888 | StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
4889 | ArrayRef<Token> AsmToks, |
4890 | StringRef AsmString, |
4891 | unsigned NumOutputs, unsigned NumInputs, |
4892 | ArrayRef<StringRef> Constraints, |
4893 | ArrayRef<StringRef> Clobbers, |
4894 | ArrayRef<Expr*> Exprs, |
4895 | SourceLocation EndLoc); |
4896 | LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName, |
4897 | SourceLocation Location, |
4898 | bool AlwaysCreate); |
4899 | |
4900 | VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, |
4901 | SourceLocation StartLoc, |
4902 | SourceLocation IdLoc, IdentifierInfo *Id, |
4903 | bool Invalid = false); |
4904 | |
4905 | Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); |
4906 | |
4907 | StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, |
4908 | Decl *Parm, Stmt *Body); |
4909 | |
4910 | StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); |
4911 | |
4912 | StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, |
4913 | MultiStmtArg Catch, Stmt *Finally); |
4914 | |
4915 | StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); |
4916 | StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, |
4917 | Scope *CurScope); |
4918 | ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, |
4919 | Expr *operand); |
4920 | StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, |
4921 | Expr *SynchExpr, |
4922 | Stmt *SynchBody); |
4923 | |
4924 | StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body); |
4925 | |
4926 | VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, |
4927 | SourceLocation StartLoc, |
4928 | SourceLocation IdLoc, |
4929 | IdentifierInfo *Id); |
4930 | |
4931 | Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); |
4932 | |
4933 | StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, |
4934 | Decl *ExDecl, Stmt *HandlerBlock); |
4935 | StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, |
4936 | ArrayRef<Stmt *> Handlers); |
4937 | |
4938 | StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ? |
4939 | SourceLocation TryLoc, Stmt *TryBlock, |
4940 | Stmt *Handler); |
4941 | StmtResult ActOnSEHExceptBlock(SourceLocation Loc, |
4942 | Expr *FilterExpr, |
4943 | Stmt *Block); |
4944 | void ActOnStartSEHFinallyBlock(); |
4945 | void ActOnAbortSEHFinallyBlock(); |
4946 | StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block); |
4947 | StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope); |
4948 | |
4949 | void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); |
4950 | |
4951 | bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; |
4952 | |
4953 | /// If it's a file scoped decl that must warn if not used, keep track |
4954 | /// of it. |
4955 | void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); |
4956 | |
4957 | /// DiagnoseUnusedExprResult - If the statement passed in is an expression |
4958 | /// whose result is unused, warn. |
4959 | void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID); |
4960 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D); |
4961 | void DiagnoseUnusedDecl(const NamedDecl *ND); |
4962 | |
4963 | /// If VD is set but not otherwise used, diagnose, for a parameter or a |
4964 | /// variable. |
4965 | void DiagnoseUnusedButSetDecl(const VarDecl *VD); |
4966 | |
4967 | /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null |
4968 | /// statement as a \p Body, and it is located on the same line. |
4969 | /// |
4970 | /// This helps prevent bugs due to typos, such as: |
4971 | /// if (condition); |
4972 | /// do_stuff(); |
4973 | void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, |
4974 | const Stmt *Body, |
4975 | unsigned DiagID); |
4976 | |
4977 | /// Warn if a for/while loop statement \p S, which is followed by |
4978 | /// \p PossibleBody, has a suspicious null statement as a body. |
4979 | void DiagnoseEmptyLoopBody(const Stmt *S, |
4980 | const Stmt *PossibleBody); |
4981 | |
4982 | /// Warn if a value is moved to itself. |
4983 | void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr, |
4984 | SourceLocation OpLoc); |
4985 | |
4986 | /// Warn if we're implicitly casting from a _Nullable pointer type to a |
4987 | /// _Nonnull one. |
4988 | void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType, |
4989 | SourceLocation Loc); |
4990 | |
4991 | /// Warn when implicitly casting 0 to nullptr. |
4992 | void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E); |
4993 | |
4994 | ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) { |
4995 | return DelayedDiagnostics.push(pool); |
4996 | } |
4997 | void PopParsingDeclaration(ParsingDeclState state, Decl *decl); |
4998 | |
4999 | typedef ProcessingContextState ParsingClassState; |
5000 | ParsingClassState PushParsingClass() { |
5001 | ParsingClassDepth++; |
5002 | return DelayedDiagnostics.pushUndelayed(); |
5003 | } |
5004 | void PopParsingClass(ParsingClassState state) { |
5005 | ParsingClassDepth--; |
5006 | DelayedDiagnostics.popUndelayed(state); |
5007 | } |
5008 | |
5009 | void redelayDiagnostics(sema::DelayedDiagnosticPool &pool); |
5010 | |
5011 | void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
5012 | const ObjCInterfaceDecl *UnknownObjCClass, |
5013 | bool ObjCPropertyAccess, |
5014 | bool AvoidPartialAvailabilityChecks = false, |
5015 | ObjCInterfaceDecl *ClassReceiver = nullptr); |
5016 | |
5017 | bool makeUnavailableInSystemHeader(SourceLocation loc, |
5018 | UnavailableAttr::ImplicitReason reason); |
5019 | |
5020 | /// Issue any -Wunguarded-availability warnings in \c FD |
5021 | void DiagnoseUnguardedAvailabilityViolations(Decl *FD); |
5022 | |
5023 | void handleDelayedAvailabilityCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
5024 | |
5025 | //===--------------------------------------------------------------------===// |
5026 | // Expression Parsing Callbacks: SemaExpr.cpp. |
5027 | |
5028 | bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid); |
5029 | bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
5030 | const ObjCInterfaceDecl *UnknownObjCClass = nullptr, |
5031 | bool ObjCPropertyAccess = false, |
5032 | bool AvoidPartialAvailabilityChecks = false, |
5033 | ObjCInterfaceDecl *ClassReciever = nullptr); |
5034 | void NoteDeletedFunction(FunctionDecl *FD); |
5035 | void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD); |
5036 | bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, |
5037 | ObjCMethodDecl *Getter, |
5038 | SourceLocation Loc); |
5039 | void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, |
5040 | ArrayRef<Expr *> Args); |
5041 | |
5042 | void PushExpressionEvaluationContext( |
5043 | ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl = nullptr, |
5044 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
5045 | ExpressionEvaluationContextRecord::EK_Other); |
5046 | enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl }; |
5047 | void PushExpressionEvaluationContext( |
5048 | ExpressionEvaluationContext NewContext, ReuseLambdaContextDecl_t, |
5049 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
5050 | ExpressionEvaluationContextRecord::EK_Other); |
5051 | void PopExpressionEvaluationContext(); |
5052 | |
5053 | void DiscardCleanupsInEvaluationContext(); |
5054 | |
5055 | ExprResult TransformToPotentiallyEvaluated(Expr *E); |
5056 | ExprResult HandleExprEvaluationContextForTypeof(Expr *E); |
5057 | |
5058 | ExprResult CheckUnevaluatedOperand(Expr *E); |
5059 | void CheckUnusedVolatileAssignment(Expr *E); |
5060 | |
5061 | ExprResult ActOnConstantExpression(ExprResult Res); |
5062 | |
5063 | // Functions for marking a declaration referenced. These functions also |
5064 | // contain the relevant logic for marking if a reference to a function or |
5065 | // variable is an odr-use (in the C++11 sense). There are separate variants |
5066 | // for expressions referring to a decl; these exist because odr-use marking |
5067 | // needs to be delayed for some constant variables when we build one of the |
5068 | // named expressions. |
5069 | // |
5070 | // MightBeOdrUse indicates whether the use could possibly be an odr-use, and |
5071 | // should usually be true. This only needs to be set to false if the lack of |
5072 | // odr-use cannot be determined from the current context (for instance, |
5073 | // because the name denotes a virtual function and was written without an |
5074 | // explicit nested-name-specifier). |
5075 | void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse); |
5076 | void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, |
5077 | bool MightBeOdrUse = true); |
5078 | void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var); |
5079 | void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base = nullptr); |
5080 | void MarkMemberReferenced(MemberExpr *E); |
5081 | void MarkFunctionParmPackReferenced(FunctionParmPackExpr *E); |
5082 | void MarkCaptureUsedInEnclosingContext(VarDecl *Capture, SourceLocation Loc, |
5083 | unsigned CapturingScopeIndex); |
5084 | |
5085 | ExprResult CheckLValueToRValueConversionOperand(Expr *E); |
5086 | void CleanupVarDeclMarking(); |
5087 | |
5088 | enum TryCaptureKind { |
5089 | TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef |
5090 | }; |
5091 | |
5092 | /// Try to capture the given variable. |
5093 | /// |
5094 | /// \param Var The variable to capture. |
5095 | /// |
5096 | /// \param Loc The location at which the capture occurs. |
5097 | /// |
5098 | /// \param Kind The kind of capture, which may be implicit (for either a |
5099 | /// block or a lambda), or explicit by-value or by-reference (for a lambda). |
5100 | /// |
5101 | /// \param EllipsisLoc The location of the ellipsis, if one is provided in |
5102 | /// an explicit lambda capture. |
5103 | /// |
5104 | /// \param BuildAndDiagnose Whether we are actually supposed to add the |
5105 | /// captures or diagnose errors. If false, this routine merely check whether |
5106 | /// the capture can occur without performing the capture itself or complaining |
5107 | /// if the variable cannot be captured. |
5108 | /// |
5109 | /// \param CaptureType Will be set to the type of the field used to capture |
5110 | /// this variable in the innermost block or lambda. Only valid when the |
5111 | /// variable can be captured. |
5112 | /// |
5113 | /// \param DeclRefType Will be set to the type of a reference to the capture |
5114 | /// from within the current scope. Only valid when the variable can be |
5115 | /// captured. |
5116 | /// |
5117 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
5118 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
5119 | /// This is useful when enclosing lambdas must speculatively capture |
5120 | /// variables that may or may not be used in certain specializations of |
5121 | /// a nested generic lambda. |
5122 | /// |
5123 | /// \returns true if an error occurred (i.e., the variable cannot be |
5124 | /// captured) and false if the capture succeeded. |
5125 | bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind, |
5126 | SourceLocation EllipsisLoc, bool BuildAndDiagnose, |
5127 | QualType &CaptureType, |
5128 | QualType &DeclRefType, |
5129 | const unsigned *const FunctionScopeIndexToStopAt); |
5130 | |
5131 | /// Try to capture the given variable. |
5132 | bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, |
5133 | TryCaptureKind Kind = TryCapture_Implicit, |
5134 | SourceLocation EllipsisLoc = SourceLocation()); |
5135 | |
5136 | /// Checks if the variable must be captured. |
5137 | bool NeedToCaptureVariable(VarDecl *Var, SourceLocation Loc); |
5138 | |
5139 | /// Given a variable, determine the type that a reference to that |
5140 | /// variable will have in the given scope. |
5141 | QualType getCapturedDeclRefType(VarDecl *Var, SourceLocation Loc); |
5142 | |
5143 | /// Mark all of the declarations referenced within a particular AST node as |
5144 | /// referenced. Used when template instantiation instantiates a non-dependent |
5145 | /// type -- entities referenced by the type are now referenced. |
5146 | void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); |
5147 | void MarkDeclarationsReferencedInExpr(Expr *E, |
5148 | bool SkipLocalVariables = false, |
5149 | ArrayRef<const Expr *> StopAt = None); |
5150 | |
5151 | /// Try to recover by turning the given expression into a |
5152 | /// call. Returns true if recovery was attempted or an error was |
5153 | /// emitted; this may also leave the ExprResult invalid. |
5154 | bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, |
5155 | bool ForceComplain = false, |
5156 | bool (*IsPlausibleResult)(QualType) = nullptr); |
5157 | |
5158 | /// Figure out if an expression could be turned into a call. |
5159 | bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy, |
5160 | UnresolvedSetImpl &NonTemplateOverloads); |
5161 | |
5162 | /// Try to convert an expression \p E to type \p Ty. Returns the result of the |
5163 | /// conversion. |
5164 | ExprResult tryConvertExprToType(Expr *E, QualType Ty); |
5165 | |
5166 | /// Conditionally issue a diagnostic based on the statements's reachability |
5167 | /// analysis. |
5168 | /// |
5169 | /// \param Stmts If Stmts is non-empty, delay reporting the diagnostic until |
5170 | /// the function body is parsed, and then do a basic reachability analysis to |
5171 | /// determine if the statement is reachable. If it is unreachable, the |
5172 | /// diagnostic will not be emitted. |
5173 | bool DiagIfReachable(SourceLocation Loc, ArrayRef<const Stmt *> Stmts, |
5174 | const PartialDiagnostic &PD); |
5175 | |
5176 | /// Conditionally issue a diagnostic based on the current |
5177 | /// evaluation context. |
5178 | /// |
5179 | /// \param Statement If Statement is non-null, delay reporting the |
5180 | /// diagnostic until the function body is parsed, and then do a basic |
5181 | /// reachability analysis to determine if the statement is reachable. |
5182 | /// If it is unreachable, the diagnostic will not be emitted. |
5183 | bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, |
5184 | const PartialDiagnostic &PD); |
5185 | /// Similar, but diagnostic is only produced if all the specified statements |
5186 | /// are reachable. |
5187 | bool DiagRuntimeBehavior(SourceLocation Loc, ArrayRef<const Stmt*> Stmts, |
5188 | const PartialDiagnostic &PD); |
5189 | |
5190 | // Primary Expressions. |
5191 | SourceRange getExprRange(Expr *E) const; |
5192 | |
5193 | ExprResult ActOnIdExpression( |
5194 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
5195 | UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand, |
5196 | CorrectionCandidateCallback *CCC = nullptr, |
5197 | bool IsInlineAsmIdentifier = false, Token *KeywordReplacement = nullptr); |
5198 | |
5199 | void DecomposeUnqualifiedId(const UnqualifiedId &Id, |
5200 | TemplateArgumentListInfo &Buffer, |
5201 | DeclarationNameInfo &NameInfo, |
5202 | const TemplateArgumentListInfo *&TemplateArgs); |
5203 | |
5204 | bool DiagnoseDependentMemberLookup(LookupResult &R); |
5205 | |
5206 | bool |
5207 | DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, |
5208 | CorrectionCandidateCallback &CCC, |
5209 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
5210 | ArrayRef<Expr *> Args = None, TypoExpr **Out = nullptr); |
5211 | |
5212 | DeclResult LookupIvarInObjCMethod(LookupResult &Lookup, Scope *S, |
5213 | IdentifierInfo *II); |
5214 | ExprResult BuildIvarRefExpr(Scope *S, SourceLocation Loc, ObjCIvarDecl *IV); |
5215 | |
5216 | ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S, |
5217 | IdentifierInfo *II, |
5218 | bool AllowBuiltinCreation=false); |
5219 | |
5220 | ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, |
5221 | SourceLocation TemplateKWLoc, |
5222 | const DeclarationNameInfo &NameInfo, |
5223 | bool isAddressOfOperand, |
5224 | const TemplateArgumentListInfo *TemplateArgs); |
5225 | |
5226 | /// If \p D cannot be odr-used in the current expression evaluation context, |
5227 | /// return a reason explaining why. Otherwise, return NOUR_None. |
5228 | NonOdrUseReason getNonOdrUseReasonInCurrentContext(ValueDecl *D); |
5229 | |
5230 | DeclRefExpr *BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
5231 | SourceLocation Loc, |
5232 | const CXXScopeSpec *SS = nullptr); |
5233 | DeclRefExpr * |
5234 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
5235 | const DeclarationNameInfo &NameInfo, |
5236 | const CXXScopeSpec *SS = nullptr, |
5237 | NamedDecl *FoundD = nullptr, |
5238 | SourceLocation TemplateKWLoc = SourceLocation(), |
5239 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
5240 | DeclRefExpr * |
5241 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
5242 | const DeclarationNameInfo &NameInfo, |
5243 | NestedNameSpecifierLoc NNS, |
5244 | NamedDecl *FoundD = nullptr, |
5245 | SourceLocation TemplateKWLoc = SourceLocation(), |
5246 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
5247 | |
5248 | ExprResult |
5249 | BuildAnonymousStructUnionMemberReference( |
5250 | const CXXScopeSpec &SS, |
5251 | SourceLocation nameLoc, |
5252 | IndirectFieldDecl *indirectField, |
5253 | DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_none), |
5254 | Expr *baseObjectExpr = nullptr, |
5255 | SourceLocation opLoc = SourceLocation()); |
5256 | |
5257 | ExprResult BuildPossibleImplicitMemberExpr( |
5258 | const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, |
5259 | const TemplateArgumentListInfo *TemplateArgs, const Scope *S, |
5260 | UnresolvedLookupExpr *AsULE = nullptr); |
5261 | ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, |
5262 | SourceLocation TemplateKWLoc, |
5263 | LookupResult &R, |
5264 | const TemplateArgumentListInfo *TemplateArgs, |
5265 | bool IsDefiniteInstance, |
5266 | const Scope *S); |
5267 | bool UseArgumentDependentLookup(const CXXScopeSpec &SS, |
5268 | const LookupResult &R, |
5269 | bool HasTrailingLParen); |
5270 | |
5271 | ExprResult |
5272 | BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, |
5273 | const DeclarationNameInfo &NameInfo, |
5274 | bool IsAddressOfOperand, const Scope *S, |
5275 | TypeSourceInfo **RecoveryTSI = nullptr); |
5276 | |
5277 | ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS, |
5278 | SourceLocation TemplateKWLoc, |
5279 | const DeclarationNameInfo &NameInfo, |
5280 | const TemplateArgumentListInfo *TemplateArgs); |
5281 | |
5282 | ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, |
5283 | LookupResult &R, |
5284 | bool NeedsADL, |
5285 | bool AcceptInvalidDecl = false); |
5286 | ExprResult BuildDeclarationNameExpr( |
5287 | const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D, |
5288 | NamedDecl *FoundD = nullptr, |
5289 | const TemplateArgumentListInfo *TemplateArgs = nullptr, |
5290 | bool AcceptInvalidDecl = false); |
5291 | |
5292 | ExprResult BuildLiteralOperatorCall(LookupResult &R, |
5293 | DeclarationNameInfo &SuffixInfo, |
5294 | ArrayRef<Expr *> Args, |
5295 | SourceLocation LitEndLoc, |
5296 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
5297 | |
5298 | ExprResult BuildPredefinedExpr(SourceLocation Loc, |
5299 | PredefinedExpr::IdentKind IK); |
5300 | ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); |
5301 | ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val); |
5302 | |
5303 | ExprResult BuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, |
5304 | SourceLocation LParen, |
5305 | SourceLocation RParen, |
5306 | TypeSourceInfo *TSI); |
5307 | ExprResult ActOnSYCLUniqueStableNameExpr(SourceLocation OpLoc, |
5308 | SourceLocation LParen, |
5309 | SourceLocation RParen, |
5310 | ParsedType ParsedTy); |
5311 | |
5312 | bool CheckLoopHintExpr(Expr *E, SourceLocation Loc); |
5313 | |
5314 | ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr); |
5315 | ExprResult ActOnCharacterConstant(const Token &Tok, |
5316 | Scope *UDLScope = nullptr); |
5317 | ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E); |
5318 | ExprResult ActOnParenListExpr(SourceLocation L, |
5319 | SourceLocation R, |
5320 | MultiExprArg Val); |
5321 | |
5322 | /// ActOnStringLiteral - The specified tokens were lexed as pasted string |
5323 | /// fragments (e.g. "foo" "bar" L"baz"). |
5324 | ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks, |
5325 | Scope *UDLScope = nullptr); |
5326 | |
5327 | ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, |
5328 | SourceLocation DefaultLoc, |
5329 | SourceLocation RParenLoc, |
5330 | Expr *ControllingExpr, |
5331 | ArrayRef<ParsedType> ArgTypes, |
5332 | ArrayRef<Expr *> ArgExprs); |
5333 | ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, |
5334 | SourceLocation DefaultLoc, |
5335 | SourceLocation RParenLoc, |
5336 | Expr *ControllingExpr, |
5337 | ArrayRef<TypeSourceInfo *> Types, |
5338 | ArrayRef<Expr *> Exprs); |
5339 | |
5340 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
5341 | ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, |
5342 | Expr *InputExpr); |
5343 | ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, |
5344 | UnaryOperatorKind Opc, Expr *Input); |
5345 | ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, |
5346 | tok::TokenKind Op, Expr *Input); |
5347 | |
5348 | bool isQualifiedMemberAccess(Expr *E); |
5349 | QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc); |
5350 | |
5351 | ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, |
5352 | SourceLocation OpLoc, |
5353 | UnaryExprOrTypeTrait ExprKind, |
5354 | SourceRange R); |
5355 | ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, |
5356 | UnaryExprOrTypeTrait ExprKind); |
5357 | ExprResult |
5358 | ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, |
5359 | UnaryExprOrTypeTrait ExprKind, |
5360 | bool IsType, void *TyOrEx, |
5361 | SourceRange ArgRange); |
5362 | |
5363 | ExprResult CheckPlaceholderExpr(Expr *E); |
5364 | bool CheckVecStepExpr(Expr *E); |
5365 | |
5366 | bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind); |
5367 | bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc, |
5368 | SourceRange ExprRange, |
5369 | UnaryExprOrTypeTrait ExprKind); |
5370 | ExprResult ActOnSizeofParameterPackExpr(Scope *S, |
5371 | SourceLocation OpLoc, |
5372 | IdentifierInfo &Name, |
5373 | SourceLocation NameLoc, |
5374 | SourceLocation RParenLoc); |
5375 | ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, |
5376 | tok::TokenKind Kind, Expr *Input); |
5377 | |
5378 | ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, |
5379 | Expr *Idx, SourceLocation RLoc); |
5380 | ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, |
5381 | Expr *Idx, SourceLocation RLoc); |
5382 | |
5383 | ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, |
5384 | Expr *ColumnIdx, |
5385 | SourceLocation RBLoc); |
5386 | |
5387 | ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, |
5388 | Expr *LowerBound, |
5389 | SourceLocation ColonLocFirst, |
5390 | SourceLocation ColonLocSecond, |
5391 | Expr *Length, Expr *Stride, |
5392 | SourceLocation RBLoc); |
5393 | ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, |
5394 | SourceLocation RParenLoc, |
5395 | ArrayRef<Expr *> Dims, |
5396 | ArrayRef<SourceRange> Brackets); |
5397 | |
5398 | /// Data structure for iterator expression. |
5399 | struct OMPIteratorData { |
5400 | IdentifierInfo *DeclIdent = nullptr; |
5401 | SourceLocation DeclIdentLoc; |
5402 | ParsedType Type; |
5403 | OMPIteratorExpr::IteratorRange Range; |
5404 | SourceLocation AssignLoc; |
5405 | SourceLocation ColonLoc; |
5406 | SourceLocation SecColonLoc; |
5407 | }; |
5408 | |
5409 | ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc, |
5410 | SourceLocation LLoc, SourceLocation RLoc, |
5411 | ArrayRef<OMPIteratorData> Data); |
5412 | |
5413 | // This struct is for use by ActOnMemberAccess to allow |
5414 | // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after |
5415 | // changing the access operator from a '.' to a '->' (to see if that is the |
5416 | // change needed to fix an error about an unknown member, e.g. when the class |
5417 | // defines a custom operator->). |
5418 | struct ActOnMemberAccessExtraArgs { |
5419 | Scope *S; |
5420 | UnqualifiedId &Id; |
5421 | Decl *ObjCImpDecl; |
5422 | }; |
5423 | |
5424 | ExprResult BuildMemberReferenceExpr( |
5425 | Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, |
5426 | CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
5427 | NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, |
5428 | const TemplateArgumentListInfo *TemplateArgs, |
5429 | const Scope *S, |
5430 | ActOnMemberAccessExtraArgs *ExtraArgs = nullptr); |
5431 | |
5432 | ExprResult |
5433 | BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, |
5434 | bool IsArrow, const CXXScopeSpec &SS, |
5435 | SourceLocation TemplateKWLoc, |
5436 | NamedDecl *FirstQualifierInScope, LookupResult &R, |
5437 | const TemplateArgumentListInfo *TemplateArgs, |
5438 | const Scope *S, |
5439 | bool SuppressQualifierCheck = false, |
5440 | ActOnMemberAccessExtraArgs *ExtraArgs = nullptr); |
5441 | |
5442 | ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, |
5443 | SourceLocation OpLoc, |
5444 | const CXXScopeSpec &SS, FieldDecl *Field, |
5445 | DeclAccessPair FoundDecl, |
5446 | const DeclarationNameInfo &MemberNameInfo); |
5447 | |
5448 | ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow); |
5449 | |
5450 | bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, |
5451 | const CXXScopeSpec &SS, |
5452 | const LookupResult &R); |
5453 | |
5454 | ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, |
5455 | bool IsArrow, SourceLocation OpLoc, |
5456 | const CXXScopeSpec &SS, |
5457 | SourceLocation TemplateKWLoc, |
5458 | NamedDecl *FirstQualifierInScope, |
5459 | const DeclarationNameInfo &NameInfo, |
5460 | const TemplateArgumentListInfo *TemplateArgs); |
5461 | |
5462 | ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, |
5463 | SourceLocation OpLoc, |
5464 | tok::TokenKind OpKind, |
5465 | CXXScopeSpec &SS, |
5466 | SourceLocation TemplateKWLoc, |
5467 | UnqualifiedId &Member, |
5468 | Decl *ObjCImpDecl); |
5469 | |
5470 | MemberExpr * |
5471 | BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc, |
5472 | const CXXScopeSpec *SS, SourceLocation TemplateKWLoc, |
5473 | ValueDecl *Member, DeclAccessPair FoundDecl, |
5474 | bool HadMultipleCandidates, |
5475 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, |
5476 | ExprValueKind VK, ExprObjectKind OK, |
5477 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
5478 | MemberExpr * |
5479 | BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc, |
5480 | NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, |
5481 | ValueDecl *Member, DeclAccessPair FoundDecl, |
5482 | bool HadMultipleCandidates, |
5483 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, |
5484 | ExprValueKind VK, ExprObjectKind OK, |
5485 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
5486 | |
5487 | void ActOnDefaultCtorInitializers(Decl *CDtorDecl); |
5488 | bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, |
5489 | FunctionDecl *FDecl, |
5490 | const FunctionProtoType *Proto, |
5491 | ArrayRef<Expr *> Args, |
5492 | SourceLocation RParenLoc, |
5493 | bool ExecConfig = false); |
5494 | void CheckStaticArrayArgument(SourceLocation CallLoc, |
5495 | ParmVarDecl *Param, |
5496 | const Expr *ArgExpr); |
5497 | |
5498 | /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. |
5499 | /// This provides the location of the left/right parens and a list of comma |
5500 | /// locations. |
5501 | ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
5502 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
5503 | Expr *ExecConfig = nullptr); |
5504 | ExprResult BuildCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
5505 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
5506 | Expr *ExecConfig = nullptr, |
5507 | bool IsExecConfig = false, |
5508 | bool AllowRecovery = false); |
5509 | Expr *BuildBuiltinCallExpr(SourceLocation Loc, Builtin::ID Id, |
5510 | MultiExprArg CallArgs); |
5511 | enum class AtomicArgumentOrder { API, AST }; |
5512 | ExprResult |
5513 | BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, |
5514 | SourceLocation RParenLoc, MultiExprArg Args, |
5515 | AtomicExpr::AtomicOp Op, |
5516 | AtomicArgumentOrder ArgOrder = AtomicArgumentOrder::API); |
5517 | ExprResult |
5518 | BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, SourceLocation LParenLoc, |
5519 | ArrayRef<Expr *> Arg, SourceLocation RParenLoc, |
5520 | Expr *Config = nullptr, bool IsExecConfig = false, |
5521 | ADLCallKind UsesADL = ADLCallKind::NotADL); |
5522 | |
5523 | ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, |
5524 | MultiExprArg ExecConfig, |
5525 | SourceLocation GGGLoc); |
5526 | |
5527 | ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, |
5528 | Declarator &D, ParsedType &Ty, |
5529 | SourceLocation RParenLoc, Expr *CastExpr); |
5530 | ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, |
5531 | TypeSourceInfo *Ty, |
5532 | SourceLocation RParenLoc, |
5533 | Expr *Op); |
5534 | CastKind PrepareScalarCast(ExprResult &src, QualType destType); |
5535 | |
5536 | /// Build an altivec or OpenCL literal. |
5537 | ExprResult BuildVectorLiteral(SourceLocation LParenLoc, |
5538 | SourceLocation RParenLoc, Expr *E, |
5539 | TypeSourceInfo *TInfo); |
5540 | |
5541 | ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); |
5542 | |
5543 | ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, |
5544 | ParsedType Ty, |
5545 | SourceLocation RParenLoc, |
5546 | Expr *InitExpr); |
5547 | |
5548 | ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, |
5549 | TypeSourceInfo *TInfo, |
5550 | SourceLocation RParenLoc, |
5551 | Expr *LiteralExpr); |
5552 | |
5553 | ExprResult ActOnInitList(SourceLocation LBraceLoc, |
5554 | MultiExprArg InitArgList, |
5555 | SourceLocation RBraceLoc); |
5556 | |
5557 | ExprResult BuildInitList(SourceLocation LBraceLoc, |
5558 | MultiExprArg InitArgList, |
5559 | SourceLocation RBraceLoc); |
5560 | |
5561 | ExprResult ActOnDesignatedInitializer(Designation &Desig, |
5562 | SourceLocation EqualOrColonLoc, |
5563 | bool GNUSyntax, |
5564 | ExprResult Init); |
5565 | |
5566 | private: |
5567 | static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind); |
5568 | |
5569 | public: |
5570 | ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, |
5571 | tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr); |
5572 | ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, |
5573 | BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr); |
5574 | ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, |
5575 | Expr *LHSExpr, Expr *RHSExpr); |
5576 | void LookupBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, |
5577 | UnresolvedSetImpl &Functions); |
5578 | |
5579 | void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc); |
5580 | |
5581 | /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
5582 | /// in the case of a the GNU conditional expr extension. |
5583 | ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, |
5584 | SourceLocation ColonLoc, |
5585 | Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr); |
5586 | |
5587 | /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". |
5588 | ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, |
5589 | LabelDecl *TheDecl); |
5590 | |
5591 | void ActOnStartStmtExpr(); |
5592 | ExprResult ActOnStmtExpr(Scope *S, SourceLocation LPLoc, Stmt *SubStmt, |
5593 | SourceLocation RPLoc); |
5594 | ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, |
5595 | SourceLocation RPLoc, unsigned TemplateDepth); |
5596 | // Handle the final expression in a statement expression. |
5597 | ExprResult ActOnStmtExprResult(ExprResult E); |
5598 | void ActOnStmtExprError(); |
5599 | |
5600 | // __builtin_offsetof(type, identifier(.identifier|[expr])*) |
5601 | struct OffsetOfComponent { |
5602 | SourceLocation LocStart, LocEnd; |
5603 | bool isBrackets; // true if [expr], false if .ident |
5604 | union { |
5605 | IdentifierInfo *IdentInfo; |
5606 | Expr *E; |
5607 | } U; |
5608 | }; |
5609 | |
5610 | /// __builtin_offsetof(type, a.b[123][456].c) |
5611 | ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, |
5612 | TypeSourceInfo *TInfo, |
5613 | ArrayRef<OffsetOfComponent> Components, |
5614 | SourceLocation RParenLoc); |
5615 | ExprResult ActOnBuiltinOffsetOf(Scope *S, |
5616 | SourceLocation BuiltinLoc, |
5617 | SourceLocation TypeLoc, |
5618 | ParsedType ParsedArgTy, |
5619 | ArrayRef<OffsetOfComponent> Components, |
5620 | SourceLocation RParenLoc); |
5621 | |
5622 | // __builtin_choose_expr(constExpr, expr1, expr2) |
5623 | ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, |
5624 | Expr *CondExpr, Expr *LHSExpr, |
5625 | Expr *RHSExpr, SourceLocation RPLoc); |
5626 | |
5627 | // __builtin_va_arg(expr, type) |
5628 | ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, |
5629 | SourceLocation RPLoc); |
5630 | ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, |
5631 | TypeSourceInfo *TInfo, SourceLocation RPLoc); |
5632 | |
5633 | // __builtin_LINE(), __builtin_FUNCTION(), __builtin_FILE(), |
5634 | // __builtin_COLUMN() |
5635 | ExprResult ActOnSourceLocExpr(SourceLocExpr::IdentKind Kind, |
5636 | SourceLocation BuiltinLoc, |
5637 | SourceLocation RPLoc); |
5638 | |
5639 | // Build a potentially resolved SourceLocExpr. |
5640 | ExprResult BuildSourceLocExpr(SourceLocExpr::IdentKind Kind, |
5641 | SourceLocation BuiltinLoc, SourceLocation RPLoc, |
5642 | DeclContext *ParentContext); |
5643 | |
5644 | // __null |
5645 | ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); |
5646 | |
5647 | bool CheckCaseExpression(Expr *E); |
5648 | |
5649 | /// Describes the result of an "if-exists" condition check. |
5650 | enum IfExistsResult { |
5651 | /// The symbol exists. |
5652 | IER_Exists, |
5653 | |
5654 | /// The symbol does not exist. |
5655 | IER_DoesNotExist, |
5656 | |
5657 | /// The name is a dependent name, so the results will differ |
5658 | /// from one instantiation to the next. |
5659 | IER_Dependent, |
5660 | |
5661 | /// An error occurred. |
5662 | IER_Error |
5663 | }; |
5664 | |
5665 | IfExistsResult |
5666 | CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, |
5667 | const DeclarationNameInfo &TargetNameInfo); |
5668 | |
5669 | IfExistsResult |
5670 | CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc, |
5671 | bool IsIfExists, CXXScopeSpec &SS, |
5672 | UnqualifiedId &Name); |
5673 | |
5674 | StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
5675 | bool IsIfExists, |
5676 | NestedNameSpecifierLoc QualifierLoc, |
5677 | DeclarationNameInfo NameInfo, |
5678 | Stmt *Nested); |
5679 | StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, |
5680 | bool IsIfExists, |
5681 | CXXScopeSpec &SS, UnqualifiedId &Name, |
5682 | Stmt *Nested); |
5683 | |
5684 | //===------------------------- "Block" Extension ------------------------===// |
5685 | |
5686 | /// ActOnBlockStart - This callback is invoked when a block literal is |
5687 | /// started. |
5688 | void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); |
5689 | |
5690 | /// ActOnBlockArguments - This callback allows processing of block arguments. |
5691 | /// If there are no arguments, this is still invoked. |
5692 | void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, |
5693 | Scope *CurScope); |
5694 | |
5695 | /// ActOnBlockError - If there is an error parsing a block, this callback |
5696 | /// is invoked to pop the information about the block from the action impl. |
5697 | void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); |
5698 | |
5699 | /// ActOnBlockStmtExpr - This is called when the body of a block statement |
5700 | /// literal was successfully completed. ^(int x){...} |
5701 | ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, |
5702 | Scope *CurScope); |
5703 | |
5704 | //===---------------------------- Clang Extensions ----------------------===// |
5705 | |
5706 | /// __builtin_convertvector(...) |
5707 | ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy, |
5708 | SourceLocation BuiltinLoc, |
5709 | SourceLocation RParenLoc); |
5710 | |
5711 | //===---------------------------- OpenCL Features -----------------------===// |
5712 | |
5713 | /// __builtin_astype(...) |
5714 | ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, |
5715 | SourceLocation BuiltinLoc, |
5716 | SourceLocation RParenLoc); |
5717 | ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy, |
5718 | SourceLocation BuiltinLoc, |
5719 | SourceLocation RParenLoc); |
5720 | |
5721 | //===---------------------------- C++ Features --------------------------===// |
5722 | |
5723 | // Act on C++ namespaces |
5724 | Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, |
5725 | SourceLocation NamespaceLoc, |
5726 | SourceLocation IdentLoc, IdentifierInfo *Ident, |
5727 | SourceLocation LBrace, |
5728 | const ParsedAttributesView &AttrList, |
5729 | UsingDirectiveDecl *&UsingDecl); |
5730 | void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); |
5731 | |
5732 | NamespaceDecl *getStdNamespace() const; |
5733 | NamespaceDecl *getOrCreateStdNamespace(); |
5734 | |
5735 | NamespaceDecl *lookupStdExperimentalNamespace(); |
5736 | NamespaceDecl *getCachedCoroNamespace() { return CoroTraitsNamespaceCache; } |
5737 | |
5738 | CXXRecordDecl *getStdBadAlloc() const; |
5739 | EnumDecl *getStdAlignValT() const; |
5740 | |
5741 | private: |
5742 | // A cache representing if we've fully checked the various comparison category |
5743 | // types stored in ASTContext. The bit-index corresponds to the integer value |
5744 | // of a ComparisonCategoryType enumerator. |
5745 | llvm::SmallBitVector FullyCheckedComparisonCategories; |
5746 | |
5747 | ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl, |
5748 | CXXScopeSpec &SS, |
5749 | ParsedType TemplateTypeTy, |
5750 | IdentifierInfo *MemberOrBase); |
5751 | |
5752 | public: |
5753 | enum class ComparisonCategoryUsage { |
5754 | /// The '<=>' operator was used in an expression and a builtin operator |
5755 | /// was selected. |
5756 | OperatorInExpression, |
5757 | /// A defaulted 'operator<=>' needed the comparison category. This |
5758 | /// typically only applies to 'std::strong_ordering', due to the implicit |
5759 | /// fallback return value. |
5760 | DefaultedOperator, |
5761 | }; |
5762 | |
5763 | /// Lookup the specified comparison category types in the standard |
5764 | /// library, an check the VarDecls possibly returned by the operator<=> |
5765 | /// builtins for that type. |
5766 | /// |
5767 | /// \return The type of the comparison category type corresponding to the |
5768 | /// specified Kind, or a null type if an error occurs |
5769 | QualType CheckComparisonCategoryType(ComparisonCategoryType Kind, |
5770 | SourceLocation Loc, |
5771 | ComparisonCategoryUsage Usage); |
5772 | |
5773 | /// Tests whether Ty is an instance of std::initializer_list and, if |
5774 | /// it is and Element is not NULL, assigns the element type to Element. |
5775 | bool isStdInitializerList(QualType Ty, QualType *Element); |
5776 | |
5777 | /// Looks for the std::initializer_list template and instantiates it |
5778 | /// with Element, or emits an error if it's not found. |
5779 | /// |
5780 | /// \returns The instantiated template, or null on error. |
5781 | QualType BuildStdInitializerList(QualType Element, SourceLocation Loc); |
5782 | |
5783 | /// Determine whether Ctor is an initializer-list constructor, as |
5784 | /// defined in [dcl.init.list]p2. |
5785 | bool isInitListConstructor(const FunctionDecl *Ctor); |
5786 | |
5787 | Decl *ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc, |
5788 | SourceLocation NamespcLoc, CXXScopeSpec &SS, |
5789 | SourceLocation IdentLoc, |
5790 | IdentifierInfo *NamespcName, |
5791 | const ParsedAttributesView &AttrList); |
5792 | |
5793 | void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); |
5794 | |
5795 | Decl *ActOnNamespaceAliasDef(Scope *CurScope, |
5796 | SourceLocation NamespaceLoc, |
5797 | SourceLocation AliasLoc, |
5798 | IdentifierInfo *Alias, |
5799 | CXXScopeSpec &SS, |
5800 | SourceLocation IdentLoc, |
5801 | IdentifierInfo *Ident); |
5802 | |
5803 | void FilterUsingLookup(Scope *S, LookupResult &lookup); |
5804 | void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); |
5805 | bool CheckUsingShadowDecl(BaseUsingDecl *BUD, NamedDecl *Target, |
5806 | const LookupResult &PreviousDecls, |
5807 | UsingShadowDecl *&PrevShadow); |
5808 | UsingShadowDecl *BuildUsingShadowDecl(Scope *S, BaseUsingDecl *BUD, |
5809 | NamedDecl *Target, |
5810 | UsingShadowDecl *PrevDecl); |
5811 | |
5812 | bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, |
5813 | bool HasTypenameKeyword, |
5814 | const CXXScopeSpec &SS, |
5815 | SourceLocation NameLoc, |
5816 | const LookupResult &Previous); |
5817 | bool CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename, |
5818 | const CXXScopeSpec &SS, |
5819 | const DeclarationNameInfo &NameInfo, |
5820 | SourceLocation NameLoc, |
5821 | const LookupResult *R = nullptr, |
5822 | const UsingDecl *UD = nullptr); |
5823 | |
5824 | NamedDecl *BuildUsingDeclaration( |
5825 | Scope *S, AccessSpecifier AS, SourceLocation UsingLoc, |
5826 | bool HasTypenameKeyword, SourceLocation TypenameLoc, CXXScopeSpec &SS, |
5827 | DeclarationNameInfo NameInfo, SourceLocation EllipsisLoc, |
5828 | const ParsedAttributesView &AttrList, bool IsInstantiation, |
5829 | bool IsUsingIfExists); |
5830 | NamedDecl *BuildUsingEnumDeclaration(Scope *S, AccessSpecifier AS, |
5831 | SourceLocation UsingLoc, |
5832 | SourceLocation EnumLoc, |
5833 | SourceLocation NameLoc, EnumDecl *ED); |
5834 | NamedDecl *BuildUsingPackDecl(NamedDecl *InstantiatedFrom, |
5835 | ArrayRef<NamedDecl *> Expansions); |
5836 | |
5837 | bool CheckInheritingConstructorUsingDecl(UsingDecl *UD); |
5838 | |
5839 | /// Given a derived-class using shadow declaration for a constructor and the |
5840 | /// correspnding base class constructor, find or create the implicit |
5841 | /// synthesized derived class constructor to use for this initialization. |
5842 | CXXConstructorDecl * |
5843 | findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor, |
5844 | ConstructorUsingShadowDecl *DerivedShadow); |
5845 | |
5846 | Decl *ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS, |
5847 | SourceLocation UsingLoc, |
5848 | SourceLocation TypenameLoc, CXXScopeSpec &SS, |
5849 | UnqualifiedId &Name, SourceLocation EllipsisLoc, |
5850 | const ParsedAttributesView &AttrList); |
5851 | Decl *ActOnUsingEnumDeclaration(Scope *CurScope, AccessSpecifier AS, |
5852 | SourceLocation UsingLoc, |
5853 | SourceLocation EnumLoc, const DeclSpec &); |
5854 | Decl *ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS, |
5855 | MultiTemplateParamsArg TemplateParams, |
5856 | SourceLocation UsingLoc, UnqualifiedId &Name, |
5857 | const ParsedAttributesView &AttrList, |
5858 | TypeResult Type, Decl *DeclFromDeclSpec); |
5859 | |
5860 | /// BuildCXXConstructExpr - Creates a complete call to a constructor, |
5861 | /// including handling of its default argument expressions. |
5862 | /// |
5863 | /// \param ConstructKind - a CXXConstructExpr::ConstructionKind |
5864 | ExprResult |
5865 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
5866 | NamedDecl *FoundDecl, |
5867 | CXXConstructorDecl *Constructor, MultiExprArg Exprs, |
5868 | bool HadMultipleCandidates, bool IsListInitialization, |
5869 | bool IsStdInitListInitialization, |
5870 | bool RequiresZeroInit, unsigned ConstructKind, |
5871 | SourceRange ParenRange); |
5872 | |
5873 | /// Build a CXXConstructExpr whose constructor has already been resolved if |
5874 | /// it denotes an inherited constructor. |
5875 | ExprResult |
5876 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
5877 | CXXConstructorDecl *Constructor, bool Elidable, |
5878 | MultiExprArg Exprs, |
5879 | bool HadMultipleCandidates, bool IsListInitialization, |
5880 | bool IsStdInitListInitialization, |
5881 | bool RequiresZeroInit, unsigned ConstructKind, |
5882 | SourceRange ParenRange); |
5883 | |
5884 | // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if |
5885 | // the constructor can be elidable? |
5886 | ExprResult |
5887 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
5888 | NamedDecl *FoundDecl, |
5889 | CXXConstructorDecl *Constructor, bool Elidable, |
5890 | MultiExprArg Exprs, bool HadMultipleCandidates, |
5891 | bool IsListInitialization, |
5892 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
5893 | unsigned ConstructKind, SourceRange ParenRange); |
5894 | |
5895 | ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field); |
5896 | |
5897 | |
5898 | /// Instantiate or parse a C++ default argument expression as necessary. |
5899 | /// Return true on error. |
5900 | bool CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
5901 | ParmVarDecl *Param); |
5902 | |
5903 | /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating |
5904 | /// the default expr if needed. |
5905 | ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, |
5906 | FunctionDecl *FD, |
5907 | ParmVarDecl *Param); |
5908 | |
5909 | /// FinalizeVarWithDestructor - Prepare for calling destructor on the |
5910 | /// constructed variable. |
5911 | void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); |
5912 | |
5913 | /// Helper class that collects exception specifications for |
5914 | /// implicitly-declared special member functions. |
5915 | class ImplicitExceptionSpecification { |
5916 | // Pointer to allow copying |
5917 | Sema *Self; |
5918 | // We order exception specifications thus: |
5919 | // noexcept is the most restrictive, but is only used in C++11. |
5920 | // throw() comes next. |
5921 | // Then a throw(collected exceptions) |
5922 | // Finally no specification, which is expressed as noexcept(false). |
5923 | // throw(...) is used instead if any called function uses it. |
5924 | ExceptionSpecificationType ComputedEST; |
5925 | llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; |
5926 | SmallVector<QualType, 4> Exceptions; |
5927 | |
5928 | void ClearExceptions() { |
5929 | ExceptionsSeen.clear(); |
5930 | Exceptions.clear(); |
5931 | } |
5932 | |
5933 | public: |
5934 | explicit ImplicitExceptionSpecification(Sema &Self) |
5935 | : Self(&Self), ComputedEST(EST_BasicNoexcept) { |
5936 | if (!Self.getLangOpts().CPlusPlus11) |
5937 | ComputedEST = EST_DynamicNone; |
5938 | } |
5939 | |
5940 | /// Get the computed exception specification type. |
5941 | ExceptionSpecificationType getExceptionSpecType() const { |
5942 | assert(!isComputedNoexcept(ComputedEST) &&(static_cast <bool> (!isComputedNoexcept(ComputedEST) && "noexcept(expr) should not be a possible result") ? void (0) : __assert_fail ("!isComputedNoexcept(ComputedEST) && \"noexcept(expr) should not be a possible result\"" , "clang/include/clang/Sema/Sema.h", 5943, __extension__ __PRETTY_FUNCTION__ )) |
5943 | "noexcept(expr) should not be a possible result")(static_cast <bool> (!isComputedNoexcept(ComputedEST) && "noexcept(expr) should not be a possible result") ? void (0) : __assert_fail ("!isComputedNoexcept(ComputedEST) && \"noexcept(expr) should not be a possible result\"" , "clang/include/clang/Sema/Sema.h", 5943, __extension__ __PRETTY_FUNCTION__ )); |
5944 | return ComputedEST; |
5945 | } |
5946 | |
5947 | /// The number of exceptions in the exception specification. |
5948 | unsigned size() const { return Exceptions.size(); } |
5949 | |
5950 | /// The set of exceptions in the exception specification. |
5951 | const QualType *data() const { return Exceptions.data(); } |
5952 | |
5953 | /// Integrate another called method into the collected data. |
5954 | void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method); |
5955 | |
5956 | /// Integrate an invoked expression into the collected data. |
5957 | void CalledExpr(Expr *E) { CalledStmt(E); } |
5958 | |
5959 | /// Integrate an invoked statement into the collected data. |
5960 | void CalledStmt(Stmt *S); |
5961 | |
5962 | /// Overwrite an EPI's exception specification with this |
5963 | /// computed exception specification. |
5964 | FunctionProtoType::ExceptionSpecInfo getExceptionSpec() const { |
5965 | FunctionProtoType::ExceptionSpecInfo ESI; |
5966 | ESI.Type = getExceptionSpecType(); |
5967 | if (ESI.Type == EST_Dynamic) { |
5968 | ESI.Exceptions = Exceptions; |
5969 | } else if (ESI.Type == EST_None) { |
5970 | /// C++11 [except.spec]p14: |
5971 | /// The exception-specification is noexcept(false) if the set of |
5972 | /// potential exceptions of the special member function contains "any" |
5973 | ESI.Type = EST_NoexceptFalse; |
5974 | ESI.NoexceptExpr = Self->ActOnCXXBoolLiteral(SourceLocation(), |
5975 | tok::kw_false).get(); |
5976 | } |
5977 | return ESI; |
5978 | } |
5979 | }; |
5980 | |
5981 | /// Evaluate the implicit exception specification for a defaulted |
5982 | /// special member function. |
5983 | void EvaluateImplicitExceptionSpec(SourceLocation Loc, FunctionDecl *FD); |
5984 | |
5985 | /// Check the given noexcept-specifier, convert its expression, and compute |
5986 | /// the appropriate ExceptionSpecificationType. |
5987 | ExprResult ActOnNoexceptSpec(Expr *NoexceptExpr, |
5988 | ExceptionSpecificationType &EST); |
5989 | |
5990 | /// Check the given exception-specification and update the |
5991 | /// exception specification information with the results. |
5992 | void checkExceptionSpecification(bool IsTopLevel, |
5993 | ExceptionSpecificationType EST, |
5994 | ArrayRef<ParsedType> DynamicExceptions, |
5995 | ArrayRef<SourceRange> DynamicExceptionRanges, |
5996 | Expr *NoexceptExpr, |
5997 | SmallVectorImpl<QualType> &Exceptions, |
5998 | FunctionProtoType::ExceptionSpecInfo &ESI); |
5999 | |
6000 | /// Determine if we're in a case where we need to (incorrectly) eagerly |
6001 | /// parse an exception specification to work around a libstdc++ bug. |
6002 | bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D); |
6003 | |
6004 | /// Add an exception-specification to the given member function |
6005 | /// (or member function template). The exception-specification was parsed |
6006 | /// after the method itself was declared. |
6007 | void actOnDelayedExceptionSpecification(Decl *Method, |
6008 | ExceptionSpecificationType EST, |
6009 | SourceRange SpecificationRange, |
6010 | ArrayRef<ParsedType> DynamicExceptions, |
6011 | ArrayRef<SourceRange> DynamicExceptionRanges, |
6012 | Expr *NoexceptExpr); |
6013 | |
6014 | class InheritedConstructorInfo; |
6015 | |
6016 | /// Determine if a special member function should have a deleted |
6017 | /// definition when it is defaulted. |
6018 | bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM, |
6019 | InheritedConstructorInfo *ICI = nullptr, |
6020 | bool Diagnose = false); |
6021 | |
6022 | /// Produce notes explaining why a defaulted function was defined as deleted. |
6023 | void DiagnoseDeletedDefaultedFunction(FunctionDecl *FD); |
6024 | |
6025 | /// Declare the implicit default constructor for the given class. |
6026 | /// |
6027 | /// \param ClassDecl The class declaration into which the implicit |
6028 | /// default constructor will be added. |
6029 | /// |
6030 | /// \returns The implicitly-declared default constructor. |
6031 | CXXConstructorDecl *DeclareImplicitDefaultConstructor( |
6032 | CXXRecordDecl *ClassDecl); |
6033 | |
6034 | /// DefineImplicitDefaultConstructor - Checks for feasibility of |
6035 | /// defining this constructor as the default constructor. |
6036 | void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, |
6037 | CXXConstructorDecl *Constructor); |
6038 | |
6039 | /// Declare the implicit destructor for the given class. |
6040 | /// |
6041 | /// \param ClassDecl The class declaration into which the implicit |
6042 | /// destructor will be added. |
6043 | /// |
6044 | /// \returns The implicitly-declared destructor. |
6045 | CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); |
6046 | |
6047 | /// DefineImplicitDestructor - Checks for feasibility of |
6048 | /// defining this destructor as the default destructor. |
6049 | void DefineImplicitDestructor(SourceLocation CurrentLocation, |
6050 | CXXDestructorDecl *Destructor); |
6051 | |
6052 | /// Build an exception spec for destructors that don't have one. |
6053 | /// |
6054 | /// C++11 says that user-defined destructors with no exception spec get one |
6055 | /// that looks as if the destructor was implicitly declared. |
6056 | void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor); |
6057 | |
6058 | /// Define the specified inheriting constructor. |
6059 | void DefineInheritingConstructor(SourceLocation UseLoc, |
6060 | CXXConstructorDecl *Constructor); |
6061 | |
6062 | /// Declare the implicit copy constructor for the given class. |
6063 | /// |
6064 | /// \param ClassDecl The class declaration into which the implicit |
6065 | /// copy constructor will be added. |
6066 | /// |
6067 | /// \returns The implicitly-declared copy constructor. |
6068 | CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); |
6069 | |
6070 | /// DefineImplicitCopyConstructor - Checks for feasibility of |
6071 | /// defining this constructor as the copy constructor. |
6072 | void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, |
6073 | CXXConstructorDecl *Constructor); |
6074 | |
6075 | /// Declare the implicit move constructor for the given class. |
6076 | /// |
6077 | /// \param ClassDecl The Class declaration into which the implicit |
6078 | /// move constructor will be added. |
6079 | /// |
6080 | /// \returns The implicitly-declared move constructor, or NULL if it wasn't |
6081 | /// declared. |
6082 | CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl); |
6083 | |
6084 | /// DefineImplicitMoveConstructor - Checks for feasibility of |
6085 | /// defining this constructor as the move constructor. |
6086 | void DefineImplicitMoveConstructor(SourceLocation CurrentLocation, |
6087 | CXXConstructorDecl *Constructor); |
6088 | |
6089 | /// Declare the implicit copy assignment operator for the given class. |
6090 | /// |
6091 | /// \param ClassDecl The class declaration into which the implicit |
6092 | /// copy assignment operator will be added. |
6093 | /// |
6094 | /// \returns The implicitly-declared copy assignment operator. |
6095 | CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); |
6096 | |
6097 | /// Defines an implicitly-declared copy assignment operator. |
6098 | void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, |
6099 | CXXMethodDecl *MethodDecl); |
6100 | |
6101 | /// Declare the implicit move assignment operator for the given class. |
6102 | /// |
6103 | /// \param ClassDecl The Class declaration into which the implicit |
6104 | /// move assignment operator will be added. |
6105 | /// |
6106 | /// \returns The implicitly-declared move assignment operator, or NULL if it |
6107 | /// wasn't declared. |
6108 | CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl); |
6109 | |
6110 | /// Defines an implicitly-declared move assignment operator. |
6111 | void DefineImplicitMoveAssignment(SourceLocation CurrentLocation, |
6112 | CXXMethodDecl *MethodDecl); |
6113 | |
6114 | /// Force the declaration of any implicitly-declared members of this |
6115 | /// class. |
6116 | void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); |
6117 | |
6118 | /// Check a completed declaration of an implicit special member. |
6119 | void CheckImplicitSpecialMemberDeclaration(Scope *S, FunctionDecl *FD); |
6120 | |
6121 | /// Determine whether the given function is an implicitly-deleted |
6122 | /// special member function. |
6123 | bool isImplicitlyDeleted(FunctionDecl *FD); |
6124 | |
6125 | /// Check whether 'this' shows up in the type of a static member |
6126 | /// function after the (naturally empty) cv-qualifier-seq would be. |
6127 | /// |
6128 | /// \returns true if an error occurred. |
6129 | bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method); |
6130 | |
6131 | /// Whether this' shows up in the exception specification of a static |
6132 | /// member function. |
6133 | bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method); |
6134 | |
6135 | /// Check whether 'this' shows up in the attributes of the given |
6136 | /// static member function. |
6137 | /// |
6138 | /// \returns true if an error occurred. |
6139 | bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method); |
6140 | |
6141 | /// MaybeBindToTemporary - If the passed in expression has a record type with |
6142 | /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise |
6143 | /// it simply returns the passed in expression. |
6144 | ExprResult MaybeBindToTemporary(Expr *E); |
6145 | |
6146 | /// Wrap the expression in a ConstantExpr if it is a potential immediate |
6147 | /// invocation. |
6148 | ExprResult CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl); |
6149 | |
6150 | bool CompleteConstructorCall(CXXConstructorDecl *Constructor, |
6151 | QualType DeclInitType, MultiExprArg ArgsPtr, |
6152 | SourceLocation Loc, |
6153 | SmallVectorImpl<Expr *> &ConvertedArgs, |
6154 | bool AllowExplicit = false, |
6155 | bool IsListInitialization = false); |
6156 | |
6157 | ParsedType getInheritingConstructorName(CXXScopeSpec &SS, |
6158 | SourceLocation NameLoc, |
6159 | IdentifierInfo &Name); |
6160 | |
6161 | ParsedType getConstructorName(IdentifierInfo &II, SourceLocation NameLoc, |
6162 | Scope *S, CXXScopeSpec &SS, |
6163 | bool EnteringContext); |
6164 | ParsedType getDestructorName(SourceLocation TildeLoc, |
6165 | IdentifierInfo &II, SourceLocation NameLoc, |
6166 | Scope *S, CXXScopeSpec &SS, |
6167 | ParsedType ObjectType, |
6168 | bool EnteringContext); |
6169 | |
6170 | ParsedType getDestructorTypeForDecltype(const DeclSpec &DS, |
6171 | ParsedType ObjectType); |
6172 | |
6173 | // Checks that reinterpret casts don't have undefined behavior. |
6174 | void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, |
6175 | bool IsDereference, SourceRange Range); |
6176 | |
6177 | // Checks that the vector type should be initialized from a scalar |
6178 | // by splatting the value rather than populating a single element. |
6179 | // This is the case for AltiVecVector types as well as with |
6180 | // AltiVecPixel and AltiVecBool when -faltivec-src-compat=xl is specified. |
6181 | bool ShouldSplatAltivecScalarInCast(const VectorType *VecTy); |
6182 | |
6183 | // Checks if the -faltivec-src-compat=gcc option is specified. |
6184 | // If so, AltiVecVector, AltiVecBool and AltiVecPixel types are |
6185 | // treated the same way as they are when trying to initialize |
6186 | // these vectors on gcc (an error is emitted). |
6187 | bool CheckAltivecInitFromScalar(SourceRange R, QualType VecTy, |
6188 | QualType SrcTy); |
6189 | |
6190 | /// ActOnCXXNamedCast - Parse |
6191 | /// {dynamic,static,reinterpret,const,addrspace}_cast's. |
6192 | ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, |
6193 | tok::TokenKind Kind, |
6194 | SourceLocation LAngleBracketLoc, |
6195 | Declarator &D, |
6196 | SourceLocation RAngleBracketLoc, |
6197 | SourceLocation LParenLoc, |
6198 | Expr *E, |
6199 | SourceLocation RParenLoc); |
6200 | |
6201 | ExprResult BuildCXXNamedCast(SourceLocation OpLoc, |
6202 | tok::TokenKind Kind, |
6203 | TypeSourceInfo *Ty, |
6204 | Expr *E, |
6205 | SourceRange AngleBrackets, |
6206 | SourceRange Parens); |
6207 | |
6208 | ExprResult ActOnBuiltinBitCastExpr(SourceLocation KWLoc, Declarator &Dcl, |
6209 | ExprResult Operand, |
6210 | SourceLocation RParenLoc); |
6211 | |
6212 | ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, |
6213 | Expr *Operand, SourceLocation RParenLoc); |
6214 | |
6215 | ExprResult BuildCXXTypeId(QualType TypeInfoType, |
6216 | SourceLocation TypeidLoc, |
6217 | TypeSourceInfo *Operand, |
6218 | SourceLocation RParenLoc); |
6219 | ExprResult BuildCXXTypeId(QualType TypeInfoType, |
6220 | SourceLocation TypeidLoc, |
6221 | Expr *Operand, |
6222 | SourceLocation RParenLoc); |
6223 | |
6224 | /// ActOnCXXTypeid - Parse typeid( something ). |
6225 | ExprResult ActOnCXXTypeid(SourceLocation OpLoc, |
6226 | SourceLocation LParenLoc, bool isType, |
6227 | void *TyOrExpr, |
6228 | SourceLocation RParenLoc); |
6229 | |
6230 | ExprResult BuildCXXUuidof(QualType TypeInfoType, |
6231 | SourceLocation TypeidLoc, |
6232 | TypeSourceInfo *Operand, |
6233 | SourceLocation RParenLoc); |
6234 | ExprResult BuildCXXUuidof(QualType TypeInfoType, |
6235 | SourceLocation TypeidLoc, |
6236 | Expr *Operand, |
6237 | SourceLocation RParenLoc); |
6238 | |
6239 | /// ActOnCXXUuidof - Parse __uuidof( something ). |
6240 | ExprResult ActOnCXXUuidof(SourceLocation OpLoc, |
6241 | SourceLocation LParenLoc, bool isType, |
6242 | void *TyOrExpr, |
6243 | SourceLocation RParenLoc); |
6244 | |
6245 | /// Handle a C++1z fold-expression: ( expr op ... op expr ). |
6246 | ExprResult ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS, |
6247 | tok::TokenKind Operator, |
6248 | SourceLocation EllipsisLoc, Expr *RHS, |
6249 | SourceLocation RParenLoc); |
6250 | ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, |
6251 | SourceLocation LParenLoc, Expr *LHS, |
6252 | BinaryOperatorKind Operator, |
6253 | SourceLocation EllipsisLoc, Expr *RHS, |
6254 | SourceLocation RParenLoc, |
6255 | Optional<unsigned> NumExpansions); |
6256 | ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
6257 | BinaryOperatorKind Operator); |
6258 | |
6259 | //// ActOnCXXThis - Parse 'this' pointer. |
6260 | ExprResult ActOnCXXThis(SourceLocation loc); |
6261 | |
6262 | /// Build a CXXThisExpr and mark it referenced in the current context. |
6263 | Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit); |
6264 | void MarkThisReferenced(CXXThisExpr *This); |
6265 | |
6266 | /// Try to retrieve the type of the 'this' pointer. |
6267 | /// |
6268 | /// \returns The type of 'this', if possible. Otherwise, returns a NULL type. |
6269 | QualType getCurrentThisType(); |
6270 | |
6271 | /// When non-NULL, the C++ 'this' expression is allowed despite the |
6272 | /// current context not being a non-static member function. In such cases, |
6273 | /// this provides the type used for 'this'. |
6274 | QualType CXXThisTypeOverride; |
6275 | |
6276 | /// RAII object used to temporarily allow the C++ 'this' expression |
6277 | /// to be used, with the given qualifiers on the current class type. |
6278 | class CXXThisScopeRAII { |
6279 | Sema &S; |
6280 | QualType OldCXXThisTypeOverride; |
6281 | bool Enabled; |
6282 | |
6283 | public: |
6284 | /// Introduce a new scope where 'this' may be allowed (when enabled), |
6285 | /// using the given declaration (which is either a class template or a |
6286 | /// class) along with the given qualifiers. |
6287 | /// along with the qualifiers placed on '*this'. |
6288 | CXXThisScopeRAII(Sema &S, Decl *ContextDecl, Qualifiers CXXThisTypeQuals, |
6289 | bool Enabled = true); |
6290 | |
6291 | ~CXXThisScopeRAII(); |
6292 | }; |
6293 | |
6294 | /// Make sure the value of 'this' is actually available in the current |
6295 | /// context, if it is a potentially evaluated context. |
6296 | /// |
6297 | /// \param Loc The location at which the capture of 'this' occurs. |
6298 | /// |
6299 | /// \param Explicit Whether 'this' is explicitly captured in a lambda |
6300 | /// capture list. |
6301 | /// |
6302 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
6303 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
6304 | /// This is useful when enclosing lambdas must speculatively capture |
6305 | /// 'this' that may or may not be used in certain specializations of |
6306 | /// a nested generic lambda (depending on whether the name resolves to |
6307 | /// a non-static member function or a static function). |
6308 | /// \return returns 'true' if failed, 'false' if success. |
6309 | bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false, |
6310 | bool BuildAndDiagnose = true, |
6311 | const unsigned *const FunctionScopeIndexToStopAt = nullptr, |
6312 | bool ByCopy = false); |
6313 | |
6314 | /// Determine whether the given type is the type of *this that is used |
6315 | /// outside of the body of a member function for a type that is currently |
6316 | /// being defined. |
6317 | bool isThisOutsideMemberFunctionBody(QualType BaseType); |
6318 | |
6319 | /// ActOnCXXBoolLiteral - Parse {true,false} literals. |
6320 | ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
6321 | |
6322 | |
6323 | /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals. |
6324 | ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
6325 | |
6326 | ExprResult |
6327 | ActOnObjCAvailabilityCheckExpr(llvm::ArrayRef<AvailabilitySpec> AvailSpecs, |
6328 | SourceLocation AtLoc, SourceLocation RParen); |
6329 | |
6330 | /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. |
6331 | ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); |
6332 | |
6333 | //// ActOnCXXThrow - Parse throw expressions. |
6334 | ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); |
6335 | ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, |
6336 | bool IsThrownVarInScope); |
6337 | bool CheckCXXThrowOperand(SourceLocation ThrowLoc, QualType ThrowTy, Expr *E); |
6338 | |
6339 | /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. |
6340 | /// Can be interpreted either as function-style casting ("int(x)") |
6341 | /// or class type construction ("ClassType(x,y,z)") |
6342 | /// or creation of a value-initialized type ("int()"). |
6343 | ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, |
6344 | SourceLocation LParenOrBraceLoc, |
6345 | MultiExprArg Exprs, |
6346 | SourceLocation RParenOrBraceLoc, |
6347 | bool ListInitialization); |
6348 | |
6349 | ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, |
6350 | SourceLocation LParenLoc, |
6351 | MultiExprArg Exprs, |
6352 | SourceLocation RParenLoc, |
6353 | bool ListInitialization); |
6354 | |
6355 | /// ActOnCXXNew - Parsed a C++ 'new' expression. |
6356 | ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, |
6357 | SourceLocation PlacementLParen, |
6358 | MultiExprArg PlacementArgs, |
6359 | SourceLocation PlacementRParen, |
6360 | SourceRange TypeIdParens, Declarator &D, |
6361 | Expr *Initializer); |
6362 | ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal, |
6363 | SourceLocation PlacementLParen, |
6364 | MultiExprArg PlacementArgs, |
6365 | SourceLocation PlacementRParen, |
6366 | SourceRange TypeIdParens, |
6367 | QualType AllocType, |
6368 | TypeSourceInfo *AllocTypeInfo, |
6369 | Optional<Expr *> ArraySize, |
6370 | SourceRange DirectInitRange, |
6371 | Expr *Initializer); |
6372 | |
6373 | /// Determine whether \p FD is an aligned allocation or deallocation |
6374 | /// function that is unavailable. |
6375 | bool isUnavailableAlignedAllocationFunction(const FunctionDecl &FD) const; |
6376 | |
6377 | /// Produce diagnostics if \p FD is an aligned allocation or deallocation |
6378 | /// function that is unavailable. |
6379 | void diagnoseUnavailableAlignedAllocation(const FunctionDecl &FD, |
6380 | SourceLocation Loc); |
6381 | |
6382 | bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, |
6383 | SourceRange R); |
6384 | |
6385 | /// The scope in which to find allocation functions. |
6386 | enum AllocationFunctionScope { |
6387 | /// Only look for allocation functions in the global scope. |
6388 | AFS_Global, |
6389 | /// Only look for allocation functions in the scope of the |
6390 | /// allocated class. |
6391 | AFS_Class, |
6392 | /// Look for allocation functions in both the global scope |
6393 | /// and in the scope of the allocated class. |
6394 | AFS_Both |
6395 | }; |
6396 | |
6397 | /// Finds the overloads of operator new and delete that are appropriate |
6398 | /// for the allocation. |
6399 | bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, |
6400 | AllocationFunctionScope NewScope, |
6401 | AllocationFunctionScope DeleteScope, |
6402 | QualType AllocType, bool IsArray, |
6403 | bool &PassAlignment, MultiExprArg PlaceArgs, |
6404 | FunctionDecl *&OperatorNew, |
6405 | FunctionDecl *&OperatorDelete, |
6406 | bool Diagnose = true); |
6407 | void DeclareGlobalNewDelete(); |
6408 | void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, |
6409 | ArrayRef<QualType> Params); |
6410 | |
6411 | bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, |
6412 | DeclarationName Name, FunctionDecl* &Operator, |
6413 | bool Diagnose = true); |
6414 | FunctionDecl *FindUsualDeallocationFunction(SourceLocation StartLoc, |
6415 | bool CanProvideSize, |
6416 | bool Overaligned, |
6417 | DeclarationName Name); |
6418 | FunctionDecl *FindDeallocationFunctionForDestructor(SourceLocation StartLoc, |
6419 | CXXRecordDecl *RD); |
6420 | |
6421 | /// ActOnCXXDelete - Parsed a C++ 'delete' expression |
6422 | ExprResult ActOnCXXDelete(SourceLocation StartLoc, |
6423 | bool UseGlobal, bool ArrayForm, |
6424 | Expr *Operand); |
6425 | void CheckVirtualDtorCall(CXXDestructorDecl *dtor, SourceLocation Loc, |
6426 | bool IsDelete, bool CallCanBeVirtual, |
6427 | bool WarnOnNonAbstractTypes, |
6428 | SourceLocation DtorLoc); |
6429 | |
6430 | ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, |
6431 | Expr *Operand, SourceLocation RParen); |
6432 | ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, |
6433 | SourceLocation RParen); |
6434 | |
6435 | /// Parsed one of the type trait support pseudo-functions. |
6436 | ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
6437 | ArrayRef<ParsedType> Args, |
6438 | SourceLocation RParenLoc); |
6439 | ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
6440 | ArrayRef<TypeSourceInfo *> Args, |
6441 | SourceLocation RParenLoc); |
6442 | |
6443 | /// ActOnArrayTypeTrait - Parsed one of the binary type trait support |
6444 | /// pseudo-functions. |
6445 | ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, |
6446 | SourceLocation KWLoc, |
6447 | ParsedType LhsTy, |
6448 | Expr *DimExpr, |
6449 | SourceLocation RParen); |
6450 | |
6451 | ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, |
6452 | SourceLocation KWLoc, |
6453 | TypeSourceInfo *TSInfo, |
6454 | Expr *DimExpr, |
6455 | SourceLocation RParen); |
6456 | |
6457 | /// ActOnExpressionTrait - Parsed one of the unary type trait support |
6458 | /// pseudo-functions. |
6459 | ExprResult ActOnExpressionTrait(ExpressionTrait OET, |
6460 | SourceLocation KWLoc, |
6461 | Expr *Queried, |
6462 | SourceLocation RParen); |
6463 | |
6464 | ExprResult BuildExpressionTrait(ExpressionTrait OET, |
6465 | SourceLocation KWLoc, |
6466 | Expr *Queried, |
6467 | SourceLocation RParen); |
6468 | |
6469 | ExprResult ActOnStartCXXMemberReference(Scope *S, |
6470 | Expr *Base, |
6471 | SourceLocation OpLoc, |
6472 | tok::TokenKind OpKind, |
6473 | ParsedType &ObjectType, |
6474 | bool &MayBePseudoDestructor); |
6475 | |
6476 | ExprResult BuildPseudoDestructorExpr(Expr *Base, |
6477 | SourceLocation OpLoc, |
6478 | tok::TokenKind OpKind, |
6479 | const CXXScopeSpec &SS, |
6480 | TypeSourceInfo *ScopeType, |
6481 | SourceLocation CCLoc, |
6482 | SourceLocation TildeLoc, |
6483 | PseudoDestructorTypeStorage DestroyedType); |
6484 | |
6485 | ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, |
6486 | SourceLocation OpLoc, |
6487 | tok::TokenKind OpKind, |
6488 | CXXScopeSpec &SS, |
6489 | UnqualifiedId &FirstTypeName, |
6490 | SourceLocation CCLoc, |
6491 | SourceLocation TildeLoc, |
6492 | UnqualifiedId &SecondTypeName); |
6493 | |
6494 | ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, |
6495 | SourceLocation OpLoc, |
6496 | tok::TokenKind OpKind, |
6497 | SourceLocation TildeLoc, |
6498 | const DeclSpec& DS); |
6499 | |
6500 | /// MaybeCreateExprWithCleanups - If the current full-expression |
6501 | /// requires any cleanups, surround it with a ExprWithCleanups node. |
6502 | /// Otherwise, just returns the passed-in expression. |
6503 | Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); |
6504 | Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); |
6505 | ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); |
6506 | |
6507 | MaterializeTemporaryExpr * |
6508 | CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, |
6509 | bool BoundToLvalueReference); |
6510 | |
6511 | ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue) { |
6512 | return ActOnFinishFullExpr( |
6513 | Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue); |
6514 | } |
6515 | ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC, |
6516 | bool DiscardedValue, bool IsConstexpr = false); |
6517 | StmtResult ActOnFinishFullStmt(Stmt *Stmt); |
6518 | |
6519 | // Marks SS invalid if it represents an incomplete type. |
6520 | bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); |
6521 | // Complete an enum decl, maybe without a scope spec. |
6522 | bool RequireCompleteEnumDecl(EnumDecl *D, SourceLocation L, |
6523 | CXXScopeSpec *SS = nullptr); |
6524 | |
6525 | DeclContext *computeDeclContext(QualType T); |
6526 | DeclContext *computeDeclContext(const CXXScopeSpec &SS, |
6527 | bool EnteringContext = false); |
6528 | bool isDependentScopeSpecifier(const CXXScopeSpec &SS); |
6529 | CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); |
6530 | |
6531 | /// The parser has parsed a global nested-name-specifier '::'. |
6532 | /// |
6533 | /// \param CCLoc The location of the '::'. |
6534 | /// |
6535 | /// \param SS The nested-name-specifier, which will be updated in-place |
6536 | /// to reflect the parsed nested-name-specifier. |
6537 | /// |
6538 | /// \returns true if an error occurred, false otherwise. |
6539 | bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS); |
6540 | |
6541 | /// The parser has parsed a '__super' nested-name-specifier. |
6542 | /// |
6543 | /// \param SuperLoc The location of the '__super' keyword. |
6544 | /// |
6545 | /// \param ColonColonLoc The location of the '::'. |
6546 | /// |
6547 | /// \param SS The nested-name-specifier, which will be updated in-place |
6548 | /// to reflect the parsed nested-name-specifier. |
6549 | /// |
6550 | /// \returns true if an error occurred, false otherwise. |
6551 | bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc, |
6552 | SourceLocation ColonColonLoc, CXXScopeSpec &SS); |
6553 | |
6554 | bool isAcceptableNestedNameSpecifier(const NamedDecl *SD, |
6555 | bool *CanCorrect = nullptr); |
6556 | NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); |
6557 | |
6558 | /// Keeps information about an identifier in a nested-name-spec. |
6559 | /// |
6560 | struct NestedNameSpecInfo { |
6561 | /// The type of the object, if we're parsing nested-name-specifier in |
6562 | /// a member access expression. |
6563 | ParsedType ObjectType; |
6564 | |
6565 | /// The identifier preceding the '::'. |
6566 | IdentifierInfo *Identifier; |
6567 | |
6568 | /// The location of the identifier. |
6569 | SourceLocation IdentifierLoc; |
6570 | |
6571 | /// The location of the '::'. |
6572 | SourceLocation CCLoc; |
6573 | |
6574 | /// Creates info object for the most typical case. |
6575 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
6576 | SourceLocation ColonColonLoc, ParsedType ObjectType = ParsedType()) |
6577 | : ObjectType(ObjectType), Identifier(II), IdentifierLoc(IdLoc), |
6578 | CCLoc(ColonColonLoc) { |
6579 | } |
6580 | |
6581 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
6582 | SourceLocation ColonColonLoc, QualType ObjectType) |
6583 | : ObjectType(ParsedType::make(ObjectType)), Identifier(II), |
6584 | IdentifierLoc(IdLoc), CCLoc(ColonColonLoc) { |
6585 | } |
6586 | }; |
6587 | |
6588 | bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, |
6589 | NestedNameSpecInfo &IdInfo); |
6590 | |
6591 | bool BuildCXXNestedNameSpecifier(Scope *S, |
6592 | NestedNameSpecInfo &IdInfo, |
6593 | bool EnteringContext, |
6594 | CXXScopeSpec &SS, |
6595 | NamedDecl *ScopeLookupResult, |
6596 | bool ErrorRecoveryLookup, |
6597 | bool *IsCorrectedToColon = nullptr, |
6598 | bool OnlyNamespace = false); |
6599 | |
6600 | /// The parser has parsed a nested-name-specifier 'identifier::'. |
6601 | /// |
6602 | /// \param S The scope in which this nested-name-specifier occurs. |
6603 | /// |
6604 | /// \param IdInfo Parser information about an identifier in the |
6605 | /// nested-name-spec. |
6606 | /// |
6607 | /// \param EnteringContext Whether we're entering the context nominated by |
6608 | /// this nested-name-specifier. |
6609 | /// |
6610 | /// \param SS The nested-name-specifier, which is both an input |
6611 | /// parameter (the nested-name-specifier before this type) and an |
6612 | /// output parameter (containing the full nested-name-specifier, |
6613 | /// including this new type). |
6614 | /// |
6615 | /// \param ErrorRecoveryLookup If true, then this method is called to improve |
6616 | /// error recovery. In this case do not emit error message. |
6617 | /// |
6618 | /// \param IsCorrectedToColon If not null, suggestions to replace '::' -> ':' |
6619 | /// are allowed. The bool value pointed by this parameter is set to 'true' |
6620 | /// if the identifier is treated as if it was followed by ':', not '::'. |
6621 | /// |
6622 | /// \param OnlyNamespace If true, only considers namespaces in lookup. |
6623 | /// |
6624 | /// \returns true if an error occurred, false otherwise. |
6625 | bool ActOnCXXNestedNameSpecifier(Scope *S, |
6626 | NestedNameSpecInfo &IdInfo, |
6627 | bool EnteringContext, |
6628 | CXXScopeSpec &SS, |
6629 | bool ErrorRecoveryLookup = false, |
6630 | bool *IsCorrectedToColon = nullptr, |
6631 | bool OnlyNamespace = false); |
6632 | |
6633 | ExprResult ActOnDecltypeExpression(Expr *E); |
6634 | |
6635 | bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, |
6636 | const DeclSpec &DS, |
6637 | SourceLocation ColonColonLoc); |
6638 | |
6639 | bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, |
6640 | NestedNameSpecInfo &IdInfo, |
6641 | bool EnteringContext); |
6642 | |
6643 | /// The parser has parsed a nested-name-specifier |
6644 | /// 'template[opt] template-name < template-args >::'. |
6645 | /// |
6646 | /// \param S The scope in which this nested-name-specifier occurs. |
6647 | /// |
6648 | /// \param SS The nested-name-specifier, which is both an input |
6649 | /// parameter (the nested-name-specifier before this type) and an |
6650 | /// output parameter (containing the full nested-name-specifier, |
6651 | /// including this new type). |
6652 | /// |
6653 | /// \param TemplateKWLoc the location of the 'template' keyword, if any. |
6654 | /// \param TemplateName the template name. |
6655 | /// \param TemplateNameLoc The location of the template name. |
6656 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
6657 | /// \param TemplateArgs The template arguments. |
6658 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
6659 | /// \param CCLoc The location of the '::'. |
6660 | /// |
6661 | /// \param EnteringContext Whether we're entering the context of the |
6662 | /// nested-name-specifier. |
6663 | /// |
6664 | /// |
6665 | /// \returns true if an error occurred, false otherwise. |
6666 | bool ActOnCXXNestedNameSpecifier(Scope *S, |
6667 | CXXScopeSpec &SS, |
6668 | SourceLocation TemplateKWLoc, |
6669 | TemplateTy TemplateName, |
6670 | SourceLocation TemplateNameLoc, |
6671 | SourceLocation LAngleLoc, |
6672 | ASTTemplateArgsPtr TemplateArgs, |
6673 | SourceLocation RAngleLoc, |
6674 | SourceLocation CCLoc, |
6675 | bool EnteringContext); |
6676 | |
6677 | /// Given a C++ nested-name-specifier, produce an annotation value |
6678 | /// that the parser can use later to reconstruct the given |
6679 | /// nested-name-specifier. |
6680 | /// |
6681 | /// \param SS A nested-name-specifier. |
6682 | /// |
6683 | /// \returns A pointer containing all of the information in the |
6684 | /// nested-name-specifier \p SS. |
6685 | void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); |
6686 | |
6687 | /// Given an annotation pointer for a nested-name-specifier, restore |
6688 | /// the nested-name-specifier structure. |
6689 | /// |
6690 | /// \param Annotation The annotation pointer, produced by |
6691 | /// \c SaveNestedNameSpecifierAnnotation(). |
6692 | /// |
6693 | /// \param AnnotationRange The source range corresponding to the annotation. |
6694 | /// |
6695 | /// \param SS The nested-name-specifier that will be updated with the contents |
6696 | /// of the annotation pointer. |
6697 | void RestoreNestedNameSpecifierAnnotation(void *Annotation, |
6698 | SourceRange AnnotationRange, |
6699 | CXXScopeSpec &SS); |
6700 | |
6701 | bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
6702 | |
6703 | /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global |
6704 | /// scope or nested-name-specifier) is parsed, part of a declarator-id. |
6705 | /// After this method is called, according to [C++ 3.4.3p3], names should be |
6706 | /// looked up in the declarator-id's scope, until the declarator is parsed and |
6707 | /// ActOnCXXExitDeclaratorScope is called. |
6708 | /// The 'SS' should be a non-empty valid CXXScopeSpec. |
6709 | bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); |
6710 | |
6711 | /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously |
6712 | /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same |
6713 | /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. |
6714 | /// Used to indicate that names should revert to being looked up in the |
6715 | /// defining scope. |
6716 | void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
6717 | |
6718 | /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an |
6719 | /// initializer for the declaration 'Dcl'. |
6720 | /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a |
6721 | /// static data member of class X, names should be looked up in the scope of |
6722 | /// class X. |
6723 | void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); |
6724 | |
6725 | /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an |
6726 | /// initializer for the declaration 'Dcl'. |
6727 | void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); |
6728 | |
6729 | /// Create a new lambda closure type. |
6730 | CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange, |
6731 | TypeSourceInfo *Info, |
6732 | bool KnownDependent, |
6733 | LambdaCaptureDefault CaptureDefault); |
6734 | |
6735 | /// Start the definition of a lambda expression. |
6736 | CXXMethodDecl *startLambdaDefinition(CXXRecordDecl *Class, |
6737 | SourceRange IntroducerRange, |
6738 | TypeSourceInfo *MethodType, |
6739 | SourceLocation EndLoc, |
6740 | ArrayRef<ParmVarDecl *> Params, |
6741 | ConstexprSpecKind ConstexprKind, |
6742 | Expr *TrailingRequiresClause); |
6743 | |
6744 | /// Number lambda for linkage purposes if necessary. |
6745 | void handleLambdaNumbering( |
6746 | CXXRecordDecl *Class, CXXMethodDecl *Method, |
6747 | Optional<std::tuple<bool, unsigned, unsigned, Decl *>> Mangling = None); |
6748 | |
6749 | /// Endow the lambda scope info with the relevant properties. |
6750 | void buildLambdaScope(sema::LambdaScopeInfo *LSI, |
6751 | CXXMethodDecl *CallOperator, |
6752 | SourceRange IntroducerRange, |
6753 | LambdaCaptureDefault CaptureDefault, |
6754 | SourceLocation CaptureDefaultLoc, |
6755 | bool ExplicitParams, |
6756 | bool ExplicitResultType, |
6757 | bool Mutable); |
6758 | |
6759 | /// Perform initialization analysis of the init-capture and perform |
6760 | /// any implicit conversions such as an lvalue-to-rvalue conversion if |
6761 | /// not being used to initialize a reference. |
6762 | ParsedType actOnLambdaInitCaptureInitialization( |
6763 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
6764 | IdentifierInfo *Id, LambdaCaptureInitKind InitKind, Expr *&Init) { |
6765 | return ParsedType::make(buildLambdaInitCaptureInitialization( |
6766 | Loc, ByRef, EllipsisLoc, None, Id, |
6767 | InitKind != LambdaCaptureInitKind::CopyInit, Init)); |
6768 | } |
6769 | QualType buildLambdaInitCaptureInitialization( |
6770 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
6771 | Optional<unsigned> NumExpansions, IdentifierInfo *Id, bool DirectInit, |
6772 | Expr *&Init); |
6773 | |
6774 | /// Create a dummy variable within the declcontext of the lambda's |
6775 | /// call operator, for name lookup purposes for a lambda init capture. |
6776 | /// |
6777 | /// CodeGen handles emission of lambda captures, ignoring these dummy |
6778 | /// variables appropriately. |
6779 | VarDecl *createLambdaInitCaptureVarDecl(SourceLocation Loc, |
6780 | QualType InitCaptureType, |
6781 | SourceLocation EllipsisLoc, |
6782 | IdentifierInfo *Id, |
6783 | unsigned InitStyle, Expr *Init); |
6784 | |
6785 | /// Add an init-capture to a lambda scope. |
6786 | void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var); |
6787 | |
6788 | /// Note that we have finished the explicit captures for the |
6789 | /// given lambda. |
6790 | void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI); |
6791 | |
6792 | /// \brief This is called after parsing the explicit template parameter list |
6793 | /// on a lambda (if it exists) in C++2a. |
6794 | void ActOnLambdaExplicitTemplateParameterList(SourceLocation LAngleLoc, |
6795 | ArrayRef<NamedDecl *> TParams, |
6796 | SourceLocation RAngleLoc, |
6797 | ExprResult RequiresClause); |
6798 | |
6799 | /// Introduce the lambda parameters into scope. |
6800 | void addLambdaParameters( |
6801 | ArrayRef<LambdaIntroducer::LambdaCapture> Captures, |
6802 | CXXMethodDecl *CallOperator, Scope *CurScope); |
6803 | |
6804 | /// Deduce a block or lambda's return type based on the return |
6805 | /// statements present in the body. |
6806 | void deduceClosureReturnType(sema::CapturingScopeInfo &CSI); |
6807 | |
6808 | /// ActOnStartOfLambdaDefinition - This is called just before we start |
6809 | /// parsing the body of a lambda; it analyzes the explicit captures and |
6810 | /// arguments, and sets up various data-structures for the body of the |
6811 | /// lambda. |
6812 | void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, |
6813 | Declarator &ParamInfo, Scope *CurScope); |
6814 | |
6815 | /// ActOnLambdaError - If there is an error parsing a lambda, this callback |
6816 | /// is invoked to pop the information about the lambda. |
6817 | void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, |
6818 | bool IsInstantiation = false); |
6819 | |
6820 | /// ActOnLambdaExpr - This is called when the body of a lambda expression |
6821 | /// was successfully completed. |
6822 | ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, |
6823 | Scope *CurScope); |
6824 | |
6825 | /// Does copying/destroying the captured variable have side effects? |
6826 | bool CaptureHasSideEffects(const sema::Capture &From); |
6827 | |
6828 | /// Diagnose if an explicit lambda capture is unused. Returns true if a |
6829 | /// diagnostic is emitted. |
6830 | bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange, |
6831 | const sema::Capture &From); |
6832 | |
6833 | /// Build a FieldDecl suitable to hold the given capture. |
6834 | FieldDecl *BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture); |
6835 | |
6836 | /// Initialize the given capture with a suitable expression. |
6837 | ExprResult BuildCaptureInit(const sema::Capture &Capture, |
6838 | SourceLocation ImplicitCaptureLoc, |
6839 | bool IsOpenMPMapping = false); |
6840 | |
6841 | /// Complete a lambda-expression having processed and attached the |
6842 | /// lambda body. |
6843 | ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, |
6844 | sema::LambdaScopeInfo *LSI); |
6845 | |
6846 | /// Get the return type to use for a lambda's conversion function(s) to |
6847 | /// function pointer type, given the type of the call operator. |
6848 | QualType |
6849 | getLambdaConversionFunctionResultType(const FunctionProtoType *CallOpType, |
6850 | CallingConv CC); |
6851 | |
6852 | /// Define the "body" of the conversion from a lambda object to a |
6853 | /// function pointer. |
6854 | /// |
6855 | /// This routine doesn't actually define a sensible body; rather, it fills |
6856 | /// in the initialization expression needed to copy the lambda object into |
6857 | /// the block, and IR generation actually generates the real body of the |
6858 | /// block pointer conversion. |
6859 | void DefineImplicitLambdaToFunctionPointerConversion( |
6860 | SourceLocation CurrentLoc, CXXConversionDecl *Conv); |
6861 | |
6862 | /// Define the "body" of the conversion from a lambda object to a |
6863 | /// block pointer. |
6864 | /// |
6865 | /// This routine doesn't actually define a sensible body; rather, it fills |
6866 | /// in the initialization expression needed to copy the lambda object into |
6867 | /// the block, and IR generation actually generates the real body of the |
6868 | /// block pointer conversion. |
6869 | void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc, |
6870 | CXXConversionDecl *Conv); |
6871 | |
6872 | ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, |
6873 | SourceLocation ConvLocation, |
6874 | CXXConversionDecl *Conv, |
6875 | Expr *Src); |
6876 | |
6877 | /// Check whether the given expression is a valid constraint expression. |
6878 | /// A diagnostic is emitted if it is not, false is returned, and |
6879 | /// PossibleNonPrimary will be set to true if the failure might be due to a |
6880 | /// non-primary expression being used as an atomic constraint. |
6881 | bool CheckConstraintExpression(const Expr *CE, Token NextToken = Token(), |
6882 | bool *PossibleNonPrimary = nullptr, |
6883 | bool IsTrailingRequiresClause = false); |
6884 | |
6885 | private: |
6886 | /// Caches pairs of template-like decls whose associated constraints were |
6887 | /// checked for subsumption and whether or not the first's constraints did in |
6888 | /// fact subsume the second's. |
6889 | llvm::DenseMap<std::pair<NamedDecl *, NamedDecl *>, bool> SubsumptionCache; |
6890 | /// Caches the normalized associated constraints of declarations (concepts or |
6891 | /// constrained declarations). If an error occurred while normalizing the |
6892 | /// associated constraints of the template or concept, nullptr will be cached |
6893 | /// here. |
6894 | llvm::DenseMap<NamedDecl *, NormalizedConstraint *> |
6895 | NormalizationCache; |
6896 | |
6897 | llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &> |
6898 | SatisfactionCache; |
6899 | |
6900 | public: |
6901 | const NormalizedConstraint * |
6902 | getNormalizedAssociatedConstraints( |
6903 | NamedDecl *ConstrainedDecl, ArrayRef<const Expr *> AssociatedConstraints); |
6904 | |
6905 | /// \brief Check whether the given declaration's associated constraints are |
6906 | /// at least as constrained than another declaration's according to the |
6907 | /// partial ordering of constraints. |
6908 | /// |
6909 | /// \param Result If no error occurred, receives the result of true if D1 is |
6910 | /// at least constrained than D2, and false otherwise. |
6911 | /// |
6912 | /// \returns true if an error occurred, false otherwise. |
6913 | bool IsAtLeastAsConstrained(NamedDecl *D1, ArrayRef<const Expr *> AC1, |
6914 | NamedDecl *D2, ArrayRef<const Expr *> AC2, |
6915 | bool &Result); |
6916 | |
6917 | /// If D1 was not at least as constrained as D2, but would've been if a pair |
6918 | /// of atomic constraints involved had been declared in a concept and not |
6919 | /// repeated in two separate places in code. |
6920 | /// \returns true if such a diagnostic was emitted, false otherwise. |
6921 | bool MaybeEmitAmbiguousAtomicConstraintsDiagnostic(NamedDecl *D1, |
6922 | ArrayRef<const Expr *> AC1, NamedDecl *D2, ArrayRef<const Expr *> AC2); |
6923 | |
6924 | /// \brief Check whether the given list of constraint expressions are |
6925 | /// satisfied (as if in a 'conjunction') given template arguments. |
6926 | /// \param Template the template-like entity that triggered the constraints |
6927 | /// check (either a concept or a constrained entity). |
6928 | /// \param ConstraintExprs a list of constraint expressions, treated as if |
6929 | /// they were 'AND'ed together. |
6930 | /// \param TemplateArgs the list of template arguments to substitute into the |
6931 | /// constraint expression. |
6932 | /// \param TemplateIDRange The source range of the template id that |
6933 | /// caused the constraints check. |
6934 | /// \param Satisfaction if true is returned, will contain details of the |
6935 | /// satisfaction, with enough information to diagnose an unsatisfied |
6936 | /// expression. |
6937 | /// \returns true if an error occurred and satisfaction could not be checked, |
6938 | /// false otherwise. |
6939 | bool CheckConstraintSatisfaction( |
6940 | const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs, |
6941 | ArrayRef<TemplateArgument> TemplateArgs, |
6942 | SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction); |
6943 | |
6944 | /// \brief Check whether the given non-dependent constraint expression is |
6945 | /// satisfied. Returns false and updates Satisfaction with the satisfaction |
6946 | /// verdict if successful, emits a diagnostic and returns true if an error |
6947 | /// occured and satisfaction could not be determined. |
6948 | /// |
6949 | /// \returns true if an error occurred, false otherwise. |
6950 | bool CheckConstraintSatisfaction(const Expr *ConstraintExpr, |
6951 | ConstraintSatisfaction &Satisfaction); |
6952 | |
6953 | /// Check whether the given function decl's trailing requires clause is |
6954 | /// satisfied, if any. Returns false and updates Satisfaction with the |
6955 | /// satisfaction verdict if successful, emits a diagnostic and returns true if |
6956 | /// an error occured and satisfaction could not be determined. |
6957 | /// |
6958 | /// \returns true if an error occurred, false otherwise. |
6959 | bool CheckFunctionConstraints(const FunctionDecl *FD, |
6960 | ConstraintSatisfaction &Satisfaction, |
6961 | SourceLocation UsageLoc = SourceLocation()); |
6962 | |
6963 | |
6964 | /// \brief Ensure that the given template arguments satisfy the constraints |
6965 | /// associated with the given template, emitting a diagnostic if they do not. |
6966 | /// |
6967 | /// \param Template The template to which the template arguments are being |
6968 | /// provided. |
6969 | /// |
6970 | /// \param TemplateArgs The converted, canonicalized template arguments. |
6971 | /// |
6972 | /// \param TemplateIDRange The source range of the template id that |
6973 | /// caused the constraints check. |
6974 | /// |
6975 | /// \returns true if the constrains are not satisfied or could not be checked |
6976 | /// for satisfaction, false if the constraints are satisfied. |
6977 | bool EnsureTemplateArgumentListConstraints(TemplateDecl *Template, |
6978 | ArrayRef<TemplateArgument> TemplateArgs, |
6979 | SourceRange TemplateIDRange); |
6980 | |
6981 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
6982 | /// unsatisfied. |
6983 | /// \param First whether this is the first time an unsatisfied constraint is |
6984 | /// diagnosed for this error. |
6985 | void |
6986 | DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction &Satisfaction, |
6987 | bool First = true); |
6988 | |
6989 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
6990 | /// unsatisfied. |
6991 | void |
6992 | DiagnoseUnsatisfiedConstraint(const ASTConstraintSatisfaction &Satisfaction, |
6993 | bool First = true); |
6994 | |
6995 | // ParseObjCStringLiteral - Parse Objective-C string literals. |
6996 | ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, |
6997 | ArrayRef<Expr *> Strings); |
6998 | |
6999 | ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S); |
7000 | |
7001 | /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the |
7002 | /// numeric literal expression. Type of the expression will be "NSNumber *" |
7003 | /// or "id" if NSNumber is unavailable. |
7004 | ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number); |
7005 | ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc, |
7006 | bool Value); |
7007 | ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements); |
7008 | |
7009 | /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the |
7010 | /// '@' prefixed parenthesized expression. The type of the expression will |
7011 | /// either be "NSNumber *", "NSString *" or "NSValue *" depending on the type |
7012 | /// of ValueType, which is allowed to be a built-in numeric type, "char *", |
7013 | /// "const char *" or C structure with attribute 'objc_boxable'. |
7014 | ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr); |
7015 | |
7016 | ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, |
7017 | Expr *IndexExpr, |
7018 | ObjCMethodDecl *getterMethod, |
7019 | ObjCMethodDecl *setterMethod); |
7020 | |
7021 | ExprResult BuildObjCDictionaryLiteral(SourceRange SR, |
7022 | MutableArrayRef<ObjCDictionaryElement> Elements); |
7023 | |
7024 | ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, |
7025 | TypeSourceInfo *EncodedTypeInfo, |
7026 | SourceLocation RParenLoc); |
7027 | ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, |
7028 | CXXConversionDecl *Method, |
7029 | bool HadMultipleCandidates); |
7030 | |
7031 | ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, |
7032 | SourceLocation EncodeLoc, |
7033 | SourceLocation LParenLoc, |
7034 | ParsedType Ty, |
7035 | SourceLocation RParenLoc); |
7036 | |
7037 | /// ParseObjCSelectorExpression - Build selector expression for \@selector |
7038 | ExprResult ParseObjCSelectorExpression(Selector Sel, |
7039 | SourceLocation AtLoc, |
7040 | SourceLocation SelLoc, |
7041 | SourceLocation LParenLoc, |
7042 | SourceLocation RParenLoc, |
7043 | bool WarnMultipleSelectors); |
7044 | |
7045 | /// ParseObjCProtocolExpression - Build protocol expression for \@protocol |
7046 | ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, |
7047 | SourceLocation AtLoc, |
7048 | SourceLocation ProtoLoc, |
7049 | SourceLocation LParenLoc, |
7050 | SourceLocation ProtoIdLoc, |
7051 | SourceLocation RParenLoc); |
7052 | |
7053 | //===--------------------------------------------------------------------===// |
7054 | // C++ Declarations |
7055 | // |
7056 | Decl *ActOnStartLinkageSpecification(Scope *S, |
7057 | SourceLocation ExternLoc, |
7058 | Expr *LangStr, |
7059 | SourceLocation LBraceLoc); |
7060 | Decl *ActOnFinishLinkageSpecification(Scope *S, |
7061 | Decl *LinkageSpec, |
7062 | SourceLocation RBraceLoc); |
7063 | |
7064 | |
7065 | //===--------------------------------------------------------------------===// |
7066 | // C++ Classes |
7067 | // |
7068 | CXXRecordDecl *getCurrentClass(Scope *S, const CXXScopeSpec *SS); |
7069 | bool isCurrentClassName(const IdentifierInfo &II, Scope *S, |
7070 | const CXXScopeSpec *SS = nullptr); |
7071 | bool isCurrentClassNameTypo(IdentifierInfo *&II, const CXXScopeSpec *SS); |
7072 | |
7073 | bool ActOnAccessSpecifier(AccessSpecifier Access, SourceLocation ASLoc, |
7074 | SourceLocation ColonLoc, |
7075 | const ParsedAttributesView &Attrs); |
7076 | |
7077 | NamedDecl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, |
7078 | Declarator &D, |
7079 | MultiTemplateParamsArg TemplateParameterLists, |
7080 | Expr *BitfieldWidth, const VirtSpecifiers &VS, |
7081 | InClassInitStyle InitStyle); |
7082 | |
7083 | void ActOnStartCXXInClassMemberInitializer(); |
7084 | void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl, |
7085 | SourceLocation EqualLoc, |
7086 | Expr *Init); |
7087 | |
7088 | MemInitResult ActOnMemInitializer(Decl *ConstructorD, |
7089 | Scope *S, |
7090 | CXXScopeSpec &SS, |
7091 | IdentifierInfo *MemberOrBase, |
7092 | ParsedType TemplateTypeTy, |
7093 | const DeclSpec &DS, |
7094 | SourceLocation IdLoc, |
7095 | SourceLocation LParenLoc, |
7096 | ArrayRef<Expr *> Args, |
7097 | SourceLocation RParenLoc, |
7098 | SourceLocation EllipsisLoc); |
7099 | |
7100 | MemInitResult ActOnMemInitializer(Decl *ConstructorD, |
7101 | Scope *S, |
7102 | CXXScopeSpec &SS, |
7103 | IdentifierInfo *MemberOrBase, |
7104 | ParsedType TemplateTypeTy, |
7105 | const DeclSpec &DS, |
7106 | SourceLocation IdLoc, |
7107 | Expr *InitList, |
7108 | SourceLocation EllipsisLoc); |
7109 | |
7110 | MemInitResult BuildMemInitializer(Decl *ConstructorD, |
7111 | Scope *S, |
7112 | CXXScopeSpec &SS, |
7113 | IdentifierInfo *MemberOrBase, |
7114 | ParsedType TemplateTypeTy, |
7115 | const DeclSpec &DS, |
7116 | SourceLocation IdLoc, |
7117 | Expr *Init, |
7118 | SourceLocation EllipsisLoc); |
7119 | |
7120 | MemInitResult BuildMemberInitializer(ValueDecl *Member, |
7121 | Expr *Init, |
7122 | SourceLocation IdLoc); |
7123 | |
7124 | MemInitResult BuildBaseInitializer(QualType BaseType, |
7125 | TypeSourceInfo *BaseTInfo, |
7126 | Expr *Init, |
7127 | CXXRecordDecl *ClassDecl, |
7128 | SourceLocation EllipsisLoc); |
7129 | |
7130 | MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, |
7131 | Expr *Init, |
7132 | CXXRecordDecl *ClassDecl); |
7133 | |
7134 | bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, |
7135 | CXXCtorInitializer *Initializer); |
7136 | |
7137 | bool SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors, |
7138 | ArrayRef<CXXCtorInitializer *> Initializers = None); |
7139 | |
7140 | void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); |
7141 | |
7142 | |
7143 | /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, |
7144 | /// mark all the non-trivial destructors of its members and bases as |
7145 | /// referenced. |
7146 | void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, |
7147 | CXXRecordDecl *Record); |
7148 | |
7149 | /// Mark destructors of virtual bases of this class referenced. In the Itanium |
7150 | /// C++ ABI, this is done when emitting a destructor for any non-abstract |
7151 | /// class. In the Microsoft C++ ABI, this is done any time a class's |
7152 | /// destructor is referenced. |
7153 | void MarkVirtualBaseDestructorsReferenced( |
7154 | SourceLocation Location, CXXRecordDecl *ClassDecl, |
7155 | llvm::SmallPtrSetImpl<const RecordType *> *DirectVirtualBases = nullptr); |
7156 | |
7157 | /// Do semantic checks to allow the complete destructor variant to be emitted |
7158 | /// when the destructor is defined in another translation unit. In the Itanium |
7159 | /// C++ ABI, destructor variants are emitted together. In the MS C++ ABI, they |
7160 | /// can be emitted in separate TUs. To emit the complete variant, run a subset |
7161 | /// of the checks performed when emitting a regular destructor. |
7162 | void CheckCompleteDestructorVariant(SourceLocation CurrentLocation, |
7163 | CXXDestructorDecl *Dtor); |
7164 | |
7165 | /// The list of classes whose vtables have been used within |
7166 | /// this translation unit, and the source locations at which the |
7167 | /// first use occurred. |
7168 | typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse; |
7169 | |
7170 | /// The list of vtables that are required but have not yet been |
7171 | /// materialized. |
7172 | SmallVector<VTableUse, 16> VTableUses; |
7173 | |
7174 | /// The set of classes whose vtables have been used within |
7175 | /// this translation unit, and a bit that will be true if the vtable is |
7176 | /// required to be emitted (otherwise, it should be emitted only if needed |
7177 | /// by code generation). |
7178 | llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; |
7179 | |
7180 | /// Load any externally-stored vtable uses. |
7181 | void LoadExternalVTableUses(); |
7182 | |
7183 | /// Note that the vtable for the given class was used at the |
7184 | /// given location. |
7185 | void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, |
7186 | bool DefinitionRequired = false); |
7187 | |
7188 | /// Mark the exception specifications of all virtual member functions |
7189 | /// in the given class as needed. |
7190 | void MarkVirtualMemberExceptionSpecsNeeded(SourceLocation Loc, |
7191 | const CXXRecordDecl *RD); |
7192 | |
7193 | /// MarkVirtualMembersReferenced - Will mark all members of the given |
7194 | /// CXXRecordDecl referenced. |
7195 | void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD, |
7196 | bool ConstexprOnly = false); |
7197 | |
7198 | /// Define all of the vtables that have been used in this |
7199 | /// translation unit and reference any virtual members used by those |
7200 | /// vtables. |
7201 | /// |
7202 | /// \returns true if any work was done, false otherwise. |
7203 | bool DefineUsedVTables(); |
7204 | |
7205 | void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); |
7206 | |
7207 | void ActOnMemInitializers(Decl *ConstructorDecl, |
7208 | SourceLocation ColonLoc, |
7209 | ArrayRef<CXXCtorInitializer*> MemInits, |
7210 | bool AnyErrors); |
7211 | |
7212 | /// Check class-level dllimport/dllexport attribute. The caller must |
7213 | /// ensure that referenceDLLExportedClassMethods is called some point later |
7214 | /// when all outer classes of Class are complete. |
7215 | void checkClassLevelDLLAttribute(CXXRecordDecl *Class); |
7216 | void checkClassLevelCodeSegAttribute(CXXRecordDecl *Class); |
7217 | |
7218 | void referenceDLLExportedClassMethods(); |
7219 | |
7220 | void propagateDLLAttrToBaseClassTemplate( |
7221 | CXXRecordDecl *Class, Attr *ClassAttr, |
7222 | ClassTemplateSpecializationDecl *BaseTemplateSpec, |
7223 | SourceLocation BaseLoc); |
7224 | |
7225 | /// Add gsl::Pointer attribute to std::container::iterator |
7226 | /// \param ND The declaration that introduces the name |
7227 | /// std::container::iterator. \param UnderlyingRecord The record named by ND. |
7228 | void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord); |
7229 | |
7230 | /// Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types. |
7231 | void inferGslOwnerPointerAttribute(CXXRecordDecl *Record); |
7232 | |
7233 | /// Add [[gsl::Pointer]] attributes for std:: types. |
7234 | void inferGslPointerAttribute(TypedefNameDecl *TD); |
7235 | |
7236 | void CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record); |
7237 | |
7238 | /// Check that the C++ class annoated with "trivial_abi" satisfies all the |
7239 | /// conditions that are needed for the attribute to have an effect. |
7240 | void checkIllFormedTrivialABIStruct(CXXRecordDecl &RD); |
7241 | |
7242 | void ActOnFinishCXXMemberSpecification(Scope *S, SourceLocation RLoc, |
7243 | Decl *TagDecl, SourceLocation LBrac, |
7244 | SourceLocation RBrac, |
7245 | const ParsedAttributesView &AttrList); |
7246 | void ActOnFinishCXXMemberDecls(); |
7247 | void ActOnFinishCXXNonNestedClass(); |
7248 | |
7249 | void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param); |
7250 | unsigned ActOnReenterTemplateScope(Decl *Template, |
7251 | llvm::function_ref<Scope *()> EnterScope); |
7252 | void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); |
7253 | void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
7254 | void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); |
7255 | void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); |
7256 | void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
7257 | void ActOnFinishDelayedMemberInitializers(Decl *Record); |
7258 | void MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD, |
7259 | CachedTokens &Toks); |
7260 | void UnmarkAsLateParsedTemplate(FunctionDecl *FD); |
7261 | bool IsInsideALocalClassWithinATemplateFunction(); |
7262 | |
7263 | Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
7264 | Expr *AssertExpr, |
7265 | Expr *AssertMessageExpr, |
7266 | SourceLocation RParenLoc); |
7267 | Decl *BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
7268 | Expr *AssertExpr, |
7269 | StringLiteral *AssertMessageExpr, |
7270 | SourceLocation RParenLoc, |
7271 | bool Failed); |
7272 | |
7273 | FriendDecl *CheckFriendTypeDecl(SourceLocation LocStart, |
7274 | SourceLocation FriendLoc, |
7275 | TypeSourceInfo *TSInfo); |
7276 | Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, |
7277 | MultiTemplateParamsArg TemplateParams); |
7278 | NamedDecl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, |
7279 | MultiTemplateParamsArg TemplateParams); |
7280 | |
7281 | QualType CheckConstructorDeclarator(Declarator &D, QualType R, |
7282 | StorageClass& SC); |
7283 | void CheckConstructor(CXXConstructorDecl *Constructor); |
7284 | QualType CheckDestructorDeclarator(Declarator &D, QualType R, |
7285 | StorageClass& SC); |
7286 | bool CheckDestructor(CXXDestructorDecl *Destructor); |
7287 | void CheckConversionDeclarator(Declarator &D, QualType &R, |
7288 | StorageClass& SC); |
7289 | Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); |
7290 | void CheckDeductionGuideDeclarator(Declarator &D, QualType &R, |
7291 | StorageClass &SC); |
7292 | void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD); |
7293 | |
7294 | void CheckExplicitlyDefaultedFunction(Scope *S, FunctionDecl *MD); |
7295 | |
7296 | bool CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD, |
7297 | CXXSpecialMember CSM); |
7298 | void CheckDelayedMemberExceptionSpecs(); |
7299 | |
7300 | bool CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *MD, |
7301 | DefaultedComparisonKind DCK); |
7302 | void DeclareImplicitEqualityComparison(CXXRecordDecl *RD, |
7303 | FunctionDecl *Spaceship); |
7304 | void DefineDefaultedComparison(SourceLocation Loc, FunctionDecl *FD, |
7305 | DefaultedComparisonKind DCK); |
7306 | |
7307 | //===--------------------------------------------------------------------===// |
7308 | // C++ Derived Classes |
7309 | // |
7310 | |
7311 | /// ActOnBaseSpecifier - Parsed a base specifier |
7312 | CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, |
7313 | SourceRange SpecifierRange, |
7314 | bool Virtual, AccessSpecifier Access, |
7315 | TypeSourceInfo *TInfo, |
7316 | SourceLocation EllipsisLoc); |
7317 | |
7318 | BaseResult ActOnBaseSpecifier(Decl *classdecl, |
7319 | SourceRange SpecifierRange, |
7320 | ParsedAttributes &Attrs, |
7321 | bool Virtual, AccessSpecifier Access, |
7322 | ParsedType basetype, |
7323 | SourceLocation BaseLoc, |
7324 | SourceLocation EllipsisLoc); |
7325 | |
7326 | bool AttachBaseSpecifiers(CXXRecordDecl *Class, |
7327 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
7328 | void ActOnBaseSpecifiers(Decl *ClassDecl, |
7329 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
7330 | |
7331 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base); |
7332 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base, |
7333 | CXXBasePaths &Paths); |
7334 | |
7335 | // FIXME: I don't like this name. |
7336 | void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); |
7337 | |
7338 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
7339 | SourceLocation Loc, SourceRange Range, |
7340 | CXXCastPath *BasePath = nullptr, |
7341 | bool IgnoreAccess = false); |
7342 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
7343 | unsigned InaccessibleBaseID, |
7344 | unsigned AmbiguousBaseConvID, |
7345 | SourceLocation Loc, SourceRange Range, |
7346 | DeclarationName Name, |
7347 | CXXCastPath *BasePath, |
7348 | bool IgnoreAccess = false); |
7349 | |
7350 | std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); |
7351 | |
7352 | bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New, |
7353 | const CXXMethodDecl *Old); |
7354 | |
7355 | /// CheckOverridingFunctionReturnType - Checks whether the return types are |
7356 | /// covariant, according to C++ [class.virtual]p5. |
7357 | bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, |
7358 | const CXXMethodDecl *Old); |
7359 | |
7360 | /// CheckOverridingFunctionExceptionSpec - Checks whether the exception |
7361 | /// spec is a subset of base spec. |
7362 | bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, |
7363 | const CXXMethodDecl *Old); |
7364 | |
7365 | bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); |
7366 | |
7367 | /// CheckOverrideControl - Check C++11 override control semantics. |
7368 | void CheckOverrideControl(NamedDecl *D); |
7369 | |
7370 | /// DiagnoseAbsenceOfOverrideControl - Diagnose if 'override' keyword was |
7371 | /// not used in the declaration of an overriding method. |
7372 | void DiagnoseAbsenceOfOverrideControl(NamedDecl *D, bool Inconsistent); |
7373 | |
7374 | /// CheckForFunctionMarkedFinal - Checks whether a virtual member function |
7375 | /// overrides a virtual member function marked 'final', according to |
7376 | /// C++11 [class.virtual]p4. |
7377 | bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, |
7378 | const CXXMethodDecl *Old); |
7379 | |
7380 | |
7381 | //===--------------------------------------------------------------------===// |
7382 | // C++ Access Control |
7383 | // |
7384 | |
7385 | enum AccessResult { |
7386 | AR_accessible, |
7387 | AR_inaccessible, |
7388 | AR_dependent, |
7389 | AR_delayed |
7390 | }; |
7391 | |
7392 | bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, |
7393 | NamedDecl *PrevMemberDecl, |
7394 | AccessSpecifier LexicalAS); |
7395 | |
7396 | AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, |
7397 | DeclAccessPair FoundDecl); |
7398 | AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, |
7399 | DeclAccessPair FoundDecl); |
7400 | AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, |
7401 | SourceRange PlacementRange, |
7402 | CXXRecordDecl *NamingClass, |
7403 | DeclAccessPair FoundDecl, |
7404 | bool Diagnose = true); |
7405 | AccessResult CheckConstructorAccess(SourceLocation Loc, |
7406 | CXXConstructorDecl *D, |
7407 | DeclAccessPair FoundDecl, |
7408 | const InitializedEntity &Entity, |
7409 | bool IsCopyBindingRefToTemp = false); |
7410 | AccessResult CheckConstructorAccess(SourceLocation Loc, |
7411 | CXXConstructorDecl *D, |
7412 | DeclAccessPair FoundDecl, |
7413 | const InitializedEntity &Entity, |
7414 | const PartialDiagnostic &PDiag); |
7415 | AccessResult CheckDestructorAccess(SourceLocation Loc, |
7416 | CXXDestructorDecl *Dtor, |
7417 | const PartialDiagnostic &PDiag, |
7418 | QualType objectType = QualType()); |
7419 | AccessResult CheckFriendAccess(NamedDecl *D); |
7420 | AccessResult CheckMemberAccess(SourceLocation UseLoc, |
7421 | CXXRecordDecl *NamingClass, |
7422 | DeclAccessPair Found); |
7423 | AccessResult |
7424 | CheckStructuredBindingMemberAccess(SourceLocation UseLoc, |
7425 | CXXRecordDecl *DecomposedClass, |
7426 | DeclAccessPair Field); |
7427 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, |
7428 | Expr *ObjectExpr, |
7429 | Expr *ArgExpr, |
7430 | DeclAccessPair FoundDecl); |
7431 | AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, |
7432 | DeclAccessPair FoundDecl); |
7433 | AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, |
7434 | QualType Base, QualType Derived, |
7435 | const CXXBasePath &Path, |
7436 | unsigned DiagID, |
7437 | bool ForceCheck = false, |
7438 | bool ForceUnprivileged = false); |
7439 | void CheckLookupAccess(const LookupResult &R); |
7440 | bool IsSimplyAccessible(NamedDecl *Decl, CXXRecordDecl *NamingClass, |
7441 | QualType BaseType); |
7442 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
7443 | DeclAccessPair Found, QualType ObjectType, |
7444 | SourceLocation Loc, |
7445 | const PartialDiagnostic &Diag); |
7446 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
7447 | DeclAccessPair Found, |
7448 | QualType ObjectType) { |
7449 | return isMemberAccessibleForDeletion(NamingClass, Found, ObjectType, |
7450 | SourceLocation(), PDiag()); |
7451 | } |
7452 | |
7453 | void HandleDependentAccessCheck(const DependentDiagnostic &DD, |
7454 | const MultiLevelTemplateArgumentList &TemplateArgs); |
7455 | void PerformDependentDiagnostics(const DeclContext *Pattern, |
7456 | const MultiLevelTemplateArgumentList &TemplateArgs); |
7457 | |
7458 | void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
7459 | |
7460 | /// When true, access checking violations are treated as SFINAE |
7461 | /// failures rather than hard errors. |
7462 | bool AccessCheckingSFINAE; |
7463 | |
7464 | enum AbstractDiagSelID { |
7465 | AbstractNone = -1, |
7466 | AbstractReturnType, |
7467 | AbstractParamType, |
7468 | AbstractVariableType, |
7469 | AbstractFieldType, |
7470 | AbstractIvarType, |
7471 | AbstractSynthesizedIvarType, |
7472 | AbstractArrayType |
7473 | }; |
7474 | |
7475 | bool isAbstractType(SourceLocation Loc, QualType T); |
7476 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, |
7477 | TypeDiagnoser &Diagnoser); |
7478 | template <typename... Ts> |
7479 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, |
7480 | const Ts &...Args) { |
7481 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
7482 | return RequireNonAbstractType(Loc, T, Diagnoser); |
7483 | } |
7484 | |
7485 | void DiagnoseAbstractType(const CXXRecordDecl *RD); |
7486 | |
7487 | //===--------------------------------------------------------------------===// |
7488 | // C++ Overloaded Operators [C++ 13.5] |
7489 | // |
7490 | |
7491 | bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); |
7492 | |
7493 | bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); |
7494 | |
7495 | //===--------------------------------------------------------------------===// |
7496 | // C++ Templates [C++ 14] |
7497 | // |
7498 | void FilterAcceptableTemplateNames(LookupResult &R, |
7499 | bool AllowFunctionTemplates = true, |
7500 | bool AllowDependent = true); |
7501 | bool hasAnyAcceptableTemplateNames(LookupResult &R, |
7502 | bool AllowFunctionTemplates = true, |
7503 | bool AllowDependent = true, |
7504 | bool AllowNonTemplateFunctions = false); |
7505 | /// Try to interpret the lookup result D as a template-name. |
7506 | /// |
7507 | /// \param D A declaration found by name lookup. |
7508 | /// \param AllowFunctionTemplates Whether function templates should be |
7509 | /// considered valid results. |
7510 | /// \param AllowDependent Whether unresolved using declarations (that might |
7511 | /// name templates) should be considered valid results. |
7512 | static NamedDecl *getAsTemplateNameDecl(NamedDecl *D, |
7513 | bool AllowFunctionTemplates = true, |
7514 | bool AllowDependent = true); |
7515 | |
7516 | enum TemplateNameIsRequiredTag { TemplateNameIsRequired }; |
7517 | /// Whether and why a template name is required in this lookup. |
7518 | class RequiredTemplateKind { |
7519 | public: |
7520 | /// Template name is required if TemplateKWLoc is valid. |
7521 | RequiredTemplateKind(SourceLocation TemplateKWLoc = SourceLocation()) |
7522 | : TemplateKW(TemplateKWLoc) {} |
7523 | /// Template name is unconditionally required. |
7524 | RequiredTemplateKind(TemplateNameIsRequiredTag) {} |
7525 | |
7526 | SourceLocation getTemplateKeywordLoc() const { |
7527 | return TemplateKW.getValueOr(SourceLocation()); |
7528 | } |
7529 | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } |
7530 | bool isRequired() const { return TemplateKW != SourceLocation(); } |
7531 | explicit operator bool() const { return isRequired(); } |
7532 | |
7533 | private: |
7534 | llvm::Optional<SourceLocation> TemplateKW; |
7535 | }; |
7536 | |
7537 | enum class AssumedTemplateKind { |
7538 | /// This is not assumed to be a template name. |
7539 | None, |
7540 | /// This is assumed to be a template name because lookup found nothing. |
7541 | FoundNothing, |
7542 | /// This is assumed to be a template name because lookup found one or more |
7543 | /// functions (but no function templates). |
7544 | FoundFunctions, |
7545 | }; |
7546 | bool LookupTemplateName( |
7547 | LookupResult &R, Scope *S, CXXScopeSpec &SS, QualType ObjectType, |
7548 | bool EnteringContext, bool &MemberOfUnknownSpecialization, |
7549 | RequiredTemplateKind RequiredTemplate = SourceLocation(), |
7550 | AssumedTemplateKind *ATK = nullptr, bool AllowTypoCorrection = true); |
7551 | |
7552 | TemplateNameKind isTemplateName(Scope *S, |
7553 | CXXScopeSpec &SS, |
7554 | bool hasTemplateKeyword, |
7555 | const UnqualifiedId &Name, |
7556 | ParsedType ObjectType, |
7557 | bool EnteringContext, |
7558 | TemplateTy &Template, |
7559 | bool &MemberOfUnknownSpecialization, |
7560 | bool Disambiguation = false); |
7561 | |
7562 | /// Try to resolve an undeclared template name as a type template. |
7563 | /// |
7564 | /// Sets II to the identifier corresponding to the template name, and updates |
7565 | /// Name to a corresponding (typo-corrected) type template name and TNK to |
7566 | /// the corresponding kind, if possible. |
7567 | void ActOnUndeclaredTypeTemplateName(Scope *S, TemplateTy &Name, |
7568 | TemplateNameKind &TNK, |
7569 | SourceLocation NameLoc, |
7570 | IdentifierInfo *&II); |
7571 | |
7572 | bool resolveAssumedTemplateNameAsType(Scope *S, TemplateName &Name, |
7573 | SourceLocation NameLoc, |
7574 | bool Diagnose = true); |
7575 | |
7576 | /// Determine whether a particular identifier might be the name in a C++1z |
7577 | /// deduction-guide declaration. |
7578 | bool isDeductionGuideName(Scope *S, const IdentifierInfo &Name, |
7579 | SourceLocation NameLoc, |
7580 | ParsedTemplateTy *Template = nullptr); |
7581 | |
7582 | bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, |
7583 | SourceLocation IILoc, |
7584 | Scope *S, |
7585 | const CXXScopeSpec *SS, |
7586 | TemplateTy &SuggestedTemplate, |
7587 | TemplateNameKind &SuggestedKind); |
7588 | |
7589 | bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation, |
7590 | NamedDecl *Instantiation, |
7591 | bool InstantiatedFromMember, |
7592 | const NamedDecl *Pattern, |
7593 | const NamedDecl *PatternDef, |
7594 | TemplateSpecializationKind TSK, |
7595 | bool Complain = true); |
7596 | |
7597 | void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); |
7598 | TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); |
7599 | |
7600 | NamedDecl *ActOnTypeParameter(Scope *S, bool Typename, |
7601 | SourceLocation EllipsisLoc, |
7602 | SourceLocation KeyLoc, |
7603 | IdentifierInfo *ParamName, |
7604 | SourceLocation ParamNameLoc, |
7605 | unsigned Depth, unsigned Position, |
7606 | SourceLocation EqualLoc, |
7607 | ParsedType DefaultArg, bool HasTypeConstraint); |
7608 | |
7609 | bool ActOnTypeConstraint(const CXXScopeSpec &SS, |
7610 | TemplateIdAnnotation *TypeConstraint, |
7611 | TemplateTypeParmDecl *ConstrainedParameter, |
7612 | SourceLocation EllipsisLoc); |
7613 | bool BuildTypeConstraint(const CXXScopeSpec &SS, |
7614 | TemplateIdAnnotation *TypeConstraint, |
7615 | TemplateTypeParmDecl *ConstrainedParameter, |
7616 | SourceLocation EllipsisLoc, |
7617 | bool AllowUnexpandedPack); |
7618 | |
7619 | bool AttachTypeConstraint(NestedNameSpecifierLoc NS, |
7620 | DeclarationNameInfo NameInfo, |
7621 | ConceptDecl *NamedConcept, |
7622 | const TemplateArgumentListInfo *TemplateArgs, |
7623 | TemplateTypeParmDecl *ConstrainedParameter, |
7624 | SourceLocation EllipsisLoc); |
7625 | |
7626 | bool AttachTypeConstraint(AutoTypeLoc TL, |
7627 | NonTypeTemplateParmDecl *ConstrainedParameter, |
7628 | SourceLocation EllipsisLoc); |
7629 | |
7630 | bool RequireStructuralType(QualType T, SourceLocation Loc); |
7631 | |
7632 | QualType CheckNonTypeTemplateParameterType(TypeSourceInfo *&TSI, |
7633 | SourceLocation Loc); |
7634 | QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); |
7635 | |
7636 | NamedDecl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, |
7637 | unsigned Depth, |
7638 | unsigned Position, |
7639 | SourceLocation EqualLoc, |
7640 | Expr *DefaultArg); |
7641 | NamedDecl *ActOnTemplateTemplateParameter(Scope *S, |
7642 | SourceLocation TmpLoc, |
7643 | TemplateParameterList *Params, |
7644 | SourceLocation EllipsisLoc, |
7645 | IdentifierInfo *ParamName, |
7646 | SourceLocation ParamNameLoc, |
7647 | unsigned Depth, |
7648 | unsigned Position, |
7649 | SourceLocation EqualLoc, |
7650 | ParsedTemplateArgument DefaultArg); |
7651 | |
7652 | TemplateParameterList * |
7653 | ActOnTemplateParameterList(unsigned Depth, |
7654 | SourceLocation ExportLoc, |
7655 | SourceLocation TemplateLoc, |
7656 | SourceLocation LAngleLoc, |
7657 | ArrayRef<NamedDecl *> Params, |
7658 | SourceLocation RAngleLoc, |
7659 | Expr *RequiresClause); |
7660 | |
7661 | /// The context in which we are checking a template parameter list. |
7662 | enum TemplateParamListContext { |
7663 | TPC_ClassTemplate, |
7664 | TPC_VarTemplate, |
7665 | TPC_FunctionTemplate, |
7666 | TPC_ClassTemplateMember, |
7667 | TPC_FriendClassTemplate, |
7668 | TPC_FriendFunctionTemplate, |
7669 | TPC_FriendFunctionTemplateDefinition, |
7670 | TPC_TypeAliasTemplate |
7671 | }; |
7672 | |
7673 | bool CheckTemplateParameterList(TemplateParameterList *NewParams, |
7674 | TemplateParameterList *OldParams, |
7675 | TemplateParamListContext TPC, |
7676 | SkipBodyInfo *SkipBody = nullptr); |
7677 | TemplateParameterList *MatchTemplateParametersToScopeSpecifier( |
7678 | SourceLocation DeclStartLoc, SourceLocation DeclLoc, |
7679 | const CXXScopeSpec &SS, TemplateIdAnnotation *TemplateId, |
7680 | ArrayRef<TemplateParameterList *> ParamLists, |
7681 | bool IsFriend, bool &IsMemberSpecialization, bool &Invalid, |
7682 | bool SuppressDiagnostic = false); |
7683 | |
7684 | DeclResult CheckClassTemplate( |
7685 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
7686 | CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, |
7687 | const ParsedAttributesView &Attr, TemplateParameterList *TemplateParams, |
7688 | AccessSpecifier AS, SourceLocation ModulePrivateLoc, |
7689 | SourceLocation FriendLoc, unsigned NumOuterTemplateParamLists, |
7690 | TemplateParameterList **OuterTemplateParamLists, |
7691 | SkipBodyInfo *SkipBody = nullptr); |
7692 | |
7693 | TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, |
7694 | QualType NTTPType, |
7695 | SourceLocation Loc); |
7696 | |
7697 | /// Get a template argument mapping the given template parameter to itself, |
7698 | /// e.g. for X in \c template<int X>, this would return an expression template |
7699 | /// argument referencing X. |
7700 | TemplateArgumentLoc getIdentityTemplateArgumentLoc(NamedDecl *Param, |
7701 | SourceLocation Location); |
7702 | |
7703 | void translateTemplateArguments(const ASTTemplateArgsPtr &In, |
7704 | TemplateArgumentListInfo &Out); |
7705 | |
7706 | ParsedTemplateArgument ActOnTemplateTypeArgument(TypeResult ParsedType); |
7707 | |
7708 | void NoteAllFoundTemplates(TemplateName Name); |
7709 | |
7710 | QualType CheckTemplateIdType(TemplateName Template, |
7711 | SourceLocation TemplateLoc, |
7712 | TemplateArgumentListInfo &TemplateArgs); |
7713 | |
7714 | TypeResult |
7715 | ActOnTemplateIdType(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
7716 | TemplateTy Template, IdentifierInfo *TemplateII, |
7717 | SourceLocation TemplateIILoc, SourceLocation LAngleLoc, |
7718 | ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, |
7719 | bool IsCtorOrDtorName = false, bool IsClassName = false); |
7720 | |
7721 | /// Parsed an elaborated-type-specifier that refers to a template-id, |
7722 | /// such as \c class T::template apply<U>. |
7723 | TypeResult ActOnTagTemplateIdType(TagUseKind TUK, |
7724 | TypeSpecifierType TagSpec, |
7725 | SourceLocation TagLoc, |
7726 | CXXScopeSpec &SS, |
7727 | SourceLocation TemplateKWLoc, |
7728 | TemplateTy TemplateD, |
7729 | SourceLocation TemplateLoc, |
7730 | SourceLocation LAngleLoc, |
7731 | ASTTemplateArgsPtr TemplateArgsIn, |
7732 | SourceLocation RAngleLoc); |
7733 | |
7734 | DeclResult ActOnVarTemplateSpecialization( |
7735 | Scope *S, Declarator &D, TypeSourceInfo *DI, |
7736 | SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams, |
7737 | StorageClass SC, bool IsPartialSpecialization); |
7738 | |
7739 | /// Get the specialization of the given variable template corresponding to |
7740 | /// the specified argument list, or a null-but-valid result if the arguments |
7741 | /// are dependent. |
7742 | DeclResult CheckVarTemplateId(VarTemplateDecl *Template, |
7743 | SourceLocation TemplateLoc, |
7744 | SourceLocation TemplateNameLoc, |
7745 | const TemplateArgumentListInfo &TemplateArgs); |
7746 | |
7747 | /// Form a reference to the specialization of the given variable template |
7748 | /// corresponding to the specified argument list, or a null-but-valid result |
7749 | /// if the arguments are dependent. |
7750 | ExprResult CheckVarTemplateId(const CXXScopeSpec &SS, |
7751 | const DeclarationNameInfo &NameInfo, |
7752 | VarTemplateDecl *Template, |
7753 | SourceLocation TemplateLoc, |
7754 | const TemplateArgumentListInfo *TemplateArgs); |
7755 | |
7756 | ExprResult |
7757 | CheckConceptTemplateId(const CXXScopeSpec &SS, |
7758 | SourceLocation TemplateKWLoc, |
7759 | const DeclarationNameInfo &ConceptNameInfo, |
7760 | NamedDecl *FoundDecl, ConceptDecl *NamedConcept, |
7761 | const TemplateArgumentListInfo *TemplateArgs); |
7762 | |
7763 | void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc); |
7764 | |
7765 | ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, |
7766 | SourceLocation TemplateKWLoc, |
7767 | LookupResult &R, |
7768 | bool RequiresADL, |
7769 | const TemplateArgumentListInfo *TemplateArgs); |
7770 | |
7771 | ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, |
7772 | SourceLocation TemplateKWLoc, |
7773 | const DeclarationNameInfo &NameInfo, |
7774 | const TemplateArgumentListInfo *TemplateArgs); |
7775 | |
7776 | TemplateNameKind ActOnTemplateName( |
7777 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
7778 | const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, |
7779 | TemplateTy &Template, bool AllowInjectedClassName = false); |
7780 | |
7781 | DeclResult ActOnClassTemplateSpecialization( |
7782 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
7783 | SourceLocation ModulePrivateLoc, CXXScopeSpec &SS, |
7784 | TemplateIdAnnotation &TemplateId, const ParsedAttributesView &Attr, |
7785 | MultiTemplateParamsArg TemplateParameterLists, |
7786 | SkipBodyInfo *SkipBody = nullptr); |
7787 | |
7788 | bool CheckTemplatePartialSpecializationArgs(SourceLocation Loc, |
7789 | TemplateDecl *PrimaryTemplate, |
7790 | unsigned NumExplicitArgs, |
7791 | ArrayRef<TemplateArgument> Args); |
7792 | void CheckTemplatePartialSpecialization( |
7793 | ClassTemplatePartialSpecializationDecl *Partial); |
7794 | void CheckTemplatePartialSpecialization( |
7795 | VarTemplatePartialSpecializationDecl *Partial); |
7796 | |
7797 | Decl *ActOnTemplateDeclarator(Scope *S, |
7798 | MultiTemplateParamsArg TemplateParameterLists, |
7799 | Declarator &D); |
7800 | |
7801 | bool |
7802 | CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, |
7803 | TemplateSpecializationKind NewTSK, |
7804 | NamedDecl *PrevDecl, |
7805 | TemplateSpecializationKind PrevTSK, |
7806 | SourceLocation PrevPtOfInstantiation, |
7807 | bool &SuppressNew); |
7808 | |
7809 | bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, |
7810 | const TemplateArgumentListInfo &ExplicitTemplateArgs, |
7811 | LookupResult &Previous); |
7812 | |
7813 | bool CheckFunctionTemplateSpecialization( |
7814 | FunctionDecl *FD, TemplateArgumentListInfo *ExplicitTemplateArgs, |
7815 | LookupResult &Previous, bool QualifiedFriend = false); |
7816 | bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
7817 | void CompleteMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
7818 | |
7819 | DeclResult ActOnExplicitInstantiation( |
7820 | Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc, |
7821 | unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS, |
7822 | TemplateTy Template, SourceLocation TemplateNameLoc, |
7823 | SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, |
7824 | SourceLocation RAngleLoc, const ParsedAttributesView &Attr); |
7825 | |
7826 | DeclResult ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, |
7827 | SourceLocation TemplateLoc, |
7828 | unsigned TagSpec, SourceLocation KWLoc, |
7829 | CXXScopeSpec &SS, IdentifierInfo *Name, |
7830 | SourceLocation NameLoc, |
7831 | const ParsedAttributesView &Attr); |
7832 | |
7833 | DeclResult ActOnExplicitInstantiation(Scope *S, |
7834 | SourceLocation ExternLoc, |
7835 | SourceLocation TemplateLoc, |
7836 | Declarator &D); |
7837 | |
7838 | TemplateArgumentLoc |
7839 | SubstDefaultTemplateArgumentIfAvailable(TemplateDecl *Template, |
7840 | SourceLocation TemplateLoc, |
7841 | SourceLocation RAngleLoc, |
7842 | Decl *Param, |
7843 | SmallVectorImpl<TemplateArgument> |
7844 | &Converted, |
7845 | bool &HasDefaultArg); |
7846 | |
7847 | /// Specifies the context in which a particular template |
7848 | /// argument is being checked. |
7849 | enum CheckTemplateArgumentKind { |
7850 | /// The template argument was specified in the code or was |
7851 | /// instantiated with some deduced template arguments. |
7852 | CTAK_Specified, |
7853 | |
7854 | /// The template argument was deduced via template argument |
7855 | /// deduction. |
7856 | CTAK_Deduced, |
7857 | |
7858 | /// The template argument was deduced from an array bound |
7859 | /// via template argument deduction. |
7860 | CTAK_DeducedFromArrayBound |
7861 | }; |
7862 | |
7863 | bool CheckTemplateArgument(NamedDecl *Param, |
7864 | TemplateArgumentLoc &Arg, |
7865 | NamedDecl *Template, |
7866 | SourceLocation TemplateLoc, |
7867 | SourceLocation RAngleLoc, |
7868 | unsigned ArgumentPackIndex, |
7869 | SmallVectorImpl<TemplateArgument> &Converted, |
7870 | CheckTemplateArgumentKind CTAK = CTAK_Specified); |
7871 | |
7872 | /// Check that the given template arguments can be be provided to |
7873 | /// the given template, converting the arguments along the way. |
7874 | /// |
7875 | /// \param Template The template to which the template arguments are being |
7876 | /// provided. |
7877 | /// |
7878 | /// \param TemplateLoc The location of the template name in the source. |
7879 | /// |
7880 | /// \param TemplateArgs The list of template arguments. If the template is |
7881 | /// a template template parameter, this function may extend the set of |
7882 | /// template arguments to also include substituted, defaulted template |
7883 | /// arguments. |
7884 | /// |
7885 | /// \param PartialTemplateArgs True if the list of template arguments is |
7886 | /// intentionally partial, e.g., because we're checking just the initial |
7887 | /// set of template arguments. |
7888 | /// |
7889 | /// \param Converted Will receive the converted, canonicalized template |
7890 | /// arguments. |
7891 | /// |
7892 | /// \param UpdateArgsWithConversions If \c true, update \p TemplateArgs to |
7893 | /// contain the converted forms of the template arguments as written. |
7894 | /// Otherwise, \p TemplateArgs will not be modified. |
7895 | /// |
7896 | /// \param ConstraintsNotSatisfied If provided, and an error occured, will |
7897 | /// receive true if the cause for the error is the associated constraints of |
7898 | /// the template not being satisfied by the template arguments. |
7899 | /// |
7900 | /// \returns true if an error occurred, false otherwise. |
7901 | bool CheckTemplateArgumentList(TemplateDecl *Template, |
7902 | SourceLocation TemplateLoc, |
7903 | TemplateArgumentListInfo &TemplateArgs, |
7904 | bool PartialTemplateArgs, |
7905 | SmallVectorImpl<TemplateArgument> &Converted, |
7906 | bool UpdateArgsWithConversions = true, |
7907 | bool *ConstraintsNotSatisfied = nullptr); |
7908 | |
7909 | bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param, |
7910 | TemplateArgumentLoc &Arg, |
7911 | SmallVectorImpl<TemplateArgument> &Converted); |
7912 | |
7913 | bool CheckTemplateArgument(TypeSourceInfo *Arg); |
7914 | ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, |
7915 | QualType InstantiatedParamType, Expr *Arg, |
7916 | TemplateArgument &Converted, |
7917 | CheckTemplateArgumentKind CTAK = CTAK_Specified); |
7918 | bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, |
7919 | TemplateParameterList *Params, |
7920 | TemplateArgumentLoc &Arg); |
7921 | |
7922 | ExprResult |
7923 | BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, |
7924 | QualType ParamType, |
7925 | SourceLocation Loc); |
7926 | ExprResult |
7927 | BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, |
7928 | SourceLocation Loc); |
7929 | |
7930 | /// Enumeration describing how template parameter lists are compared |
7931 | /// for equality. |
7932 | enum TemplateParameterListEqualKind { |
7933 | /// We are matching the template parameter lists of two templates |
7934 | /// that might be redeclarations. |
7935 | /// |
7936 | /// \code |
7937 | /// template<typename T> struct X; |
7938 | /// template<typename T> struct X; |
7939 | /// \endcode |
7940 | TPL_TemplateMatch, |
7941 | |
7942 | /// We are matching the template parameter lists of two template |
7943 | /// template parameters as part of matching the template parameter lists |
7944 | /// of two templates that might be redeclarations. |
7945 | /// |
7946 | /// \code |
7947 | /// template<template<int I> class TT> struct X; |
7948 | /// template<template<int Value> class Other> struct X; |
7949 | /// \endcode |
7950 | TPL_TemplateTemplateParmMatch, |
7951 | |
7952 | /// We are matching the template parameter lists of a template |
7953 | /// template argument against the template parameter lists of a template |
7954 | /// template parameter. |
7955 | /// |
7956 | /// \code |
7957 | /// template<template<int Value> class Metafun> struct X; |
7958 | /// template<int Value> struct integer_c; |
7959 | /// X<integer_c> xic; |
7960 | /// \endcode |
7961 | TPL_TemplateTemplateArgumentMatch |
7962 | }; |
7963 | |
7964 | bool TemplateParameterListsAreEqual(TemplateParameterList *New, |
7965 | TemplateParameterList *Old, |
7966 | bool Complain, |
7967 | TemplateParameterListEqualKind Kind, |
7968 | SourceLocation TemplateArgLoc |
7969 | = SourceLocation()); |
7970 | |
7971 | bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); |
7972 | |
7973 | /// Called when the parser has parsed a C++ typename |
7974 | /// specifier, e.g., "typename T::type". |
7975 | /// |
7976 | /// \param S The scope in which this typename type occurs. |
7977 | /// \param TypenameLoc the location of the 'typename' keyword |
7978 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
7979 | /// \param II the identifier we're retrieving (e.g., 'type' in the example). |
7980 | /// \param IdLoc the location of the identifier. |
7981 | TypeResult |
7982 | ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, |
7983 | const CXXScopeSpec &SS, const IdentifierInfo &II, |
7984 | SourceLocation IdLoc); |
7985 | |
7986 | /// Called when the parser has parsed a C++ typename |
7987 | /// specifier that ends in a template-id, e.g., |
7988 | /// "typename MetaFun::template apply<T1, T2>". |
7989 | /// |
7990 | /// \param S The scope in which this typename type occurs. |
7991 | /// \param TypenameLoc the location of the 'typename' keyword |
7992 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
7993 | /// \param TemplateLoc the location of the 'template' keyword, if any. |
7994 | /// \param TemplateName The template name. |
7995 | /// \param TemplateII The identifier used to name the template. |
7996 | /// \param TemplateIILoc The location of the template name. |
7997 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
7998 | /// \param TemplateArgs The template arguments. |
7999 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
8000 | TypeResult |
8001 | ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, |
8002 | const CXXScopeSpec &SS, |
8003 | SourceLocation TemplateLoc, |
8004 | TemplateTy TemplateName, |
8005 | IdentifierInfo *TemplateII, |
8006 | SourceLocation TemplateIILoc, |
8007 | SourceLocation LAngleLoc, |
8008 | ASTTemplateArgsPtr TemplateArgs, |
8009 | SourceLocation RAngleLoc); |
8010 | |
8011 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
8012 | SourceLocation KeywordLoc, |
8013 | NestedNameSpecifierLoc QualifierLoc, |
8014 | const IdentifierInfo &II, |
8015 | SourceLocation IILoc, |
8016 | TypeSourceInfo **TSI, |
8017 | bool DeducedTSTContext); |
8018 | |
8019 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
8020 | SourceLocation KeywordLoc, |
8021 | NestedNameSpecifierLoc QualifierLoc, |
8022 | const IdentifierInfo &II, |
8023 | SourceLocation IILoc, |
8024 | bool DeducedTSTContext = true); |
8025 | |
8026 | |
8027 | TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, |
8028 | SourceLocation Loc, |
8029 | DeclarationName Name); |
8030 | bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); |
8031 | |
8032 | ExprResult RebuildExprInCurrentInstantiation(Expr *E); |
8033 | bool RebuildTemplateParamsInCurrentInstantiation( |
8034 | TemplateParameterList *Params); |
8035 | |
8036 | std::string |
8037 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
8038 | const TemplateArgumentList &Args); |
8039 | |
8040 | std::string |
8041 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
8042 | const TemplateArgument *Args, |
8043 | unsigned NumArgs); |
8044 | |
8045 | //===--------------------------------------------------------------------===// |
8046 | // C++ Concepts |
8047 | //===--------------------------------------------------------------------===// |
8048 | Decl *ActOnConceptDefinition( |
8049 | Scope *S, MultiTemplateParamsArg TemplateParameterLists, |
8050 | IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr); |
8051 | |
8052 | RequiresExprBodyDecl * |
8053 | ActOnStartRequiresExpr(SourceLocation RequiresKWLoc, |
8054 | ArrayRef<ParmVarDecl *> LocalParameters, |
8055 | Scope *BodyScope); |
8056 | void ActOnFinishRequiresExpr(); |
8057 | concepts::Requirement *ActOnSimpleRequirement(Expr *E); |
8058 | concepts::Requirement *ActOnTypeRequirement( |
8059 | SourceLocation TypenameKWLoc, CXXScopeSpec &SS, SourceLocation NameLoc, |
8060 | IdentifierInfo *TypeName, TemplateIdAnnotation *TemplateId); |
8061 | concepts::Requirement *ActOnCompoundRequirement(Expr *E, |
8062 | SourceLocation NoexceptLoc); |
8063 | concepts::Requirement * |
8064 | ActOnCompoundRequirement( |
8065 | Expr *E, SourceLocation NoexceptLoc, CXXScopeSpec &SS, |
8066 | TemplateIdAnnotation *TypeConstraint, unsigned Depth); |
8067 | concepts::Requirement *ActOnNestedRequirement(Expr *Constraint); |
8068 | concepts::ExprRequirement * |
8069 | BuildExprRequirement( |
8070 | Expr *E, bool IsSatisfied, SourceLocation NoexceptLoc, |
8071 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
8072 | concepts::ExprRequirement * |
8073 | BuildExprRequirement( |
8074 | concepts::Requirement::SubstitutionDiagnostic *ExprSubstDiag, |
8075 | bool IsSatisfied, SourceLocation NoexceptLoc, |
8076 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
8077 | concepts::TypeRequirement *BuildTypeRequirement(TypeSourceInfo *Type); |
8078 | concepts::TypeRequirement * |
8079 | BuildTypeRequirement( |
8080 | concepts::Requirement::SubstitutionDiagnostic *SubstDiag); |
8081 | concepts::NestedRequirement *BuildNestedRequirement(Expr *E); |
8082 | concepts::NestedRequirement * |
8083 | BuildNestedRequirement( |
8084 | concepts::Requirement::SubstitutionDiagnostic *SubstDiag); |
8085 | ExprResult ActOnRequiresExpr(SourceLocation RequiresKWLoc, |
8086 | RequiresExprBodyDecl *Body, |
8087 | ArrayRef<ParmVarDecl *> LocalParameters, |
8088 | ArrayRef<concepts::Requirement *> Requirements, |
8089 | SourceLocation ClosingBraceLoc); |
8090 | |
8091 | //===--------------------------------------------------------------------===// |
8092 | // C++ Variadic Templates (C++0x [temp.variadic]) |
8093 | //===--------------------------------------------------------------------===// |
8094 | |
8095 | /// Determine whether an unexpanded parameter pack might be permitted in this |
8096 | /// location. Useful for error recovery. |
8097 | bool isUnexpandedParameterPackPermitted(); |
8098 | |
8099 | /// The context in which an unexpanded parameter pack is |
8100 | /// being diagnosed. |
8101 | /// |
8102 | /// Note that the values of this enumeration line up with the first |
8103 | /// argument to the \c err_unexpanded_parameter_pack diagnostic. |
8104 | enum UnexpandedParameterPackContext { |
8105 | /// An arbitrary expression. |
8106 | UPPC_Expression = 0, |
8107 | |
8108 | /// The base type of a class type. |
8109 | UPPC_BaseType, |
8110 | |
8111 | /// The type of an arbitrary declaration. |
8112 | UPPC_DeclarationType, |
8113 | |
8114 | /// The type of a data member. |
8115 | UPPC_DataMemberType, |
8116 | |
8117 | /// The size of a bit-field. |
8118 | UPPC_BitFieldWidth, |
8119 | |
8120 | /// The expression in a static assertion. |
8121 | UPPC_StaticAssertExpression, |
8122 | |
8123 | /// The fixed underlying type of an enumeration. |
8124 | UPPC_FixedUnderlyingType, |
8125 | |
8126 | /// The enumerator value. |
8127 | UPPC_EnumeratorValue, |
8128 | |
8129 | /// A using declaration. |
8130 | UPPC_UsingDeclaration, |
8131 | |
8132 | /// A friend declaration. |
8133 | UPPC_FriendDeclaration, |
8134 | |
8135 | /// A declaration qualifier. |
8136 | UPPC_DeclarationQualifier, |
8137 | |
8138 | /// An initializer. |
8139 | UPPC_Initializer, |
8140 | |
8141 | /// A default argument. |
8142 | UPPC_DefaultArgument, |
8143 | |
8144 | /// The type of a non-type template parameter. |
8145 | UPPC_NonTypeTemplateParameterType, |
8146 | |
8147 | /// The type of an exception. |
8148 | UPPC_ExceptionType, |
8149 | |
8150 | /// Partial specialization. |
8151 | UPPC_PartialSpecialization, |
8152 | |
8153 | /// Microsoft __if_exists. |
8154 | UPPC_IfExists, |
8155 | |
8156 | /// Microsoft __if_not_exists. |
8157 | UPPC_IfNotExists, |
8158 | |
8159 | /// Lambda expression. |
8160 | UPPC_Lambda, |
8161 | |
8162 | /// Block expression. |
8163 | UPPC_Block, |
8164 | |
8165 | /// A type constraint. |
8166 | UPPC_TypeConstraint, |
8167 | |
8168 | // A requirement in a requires-expression. |
8169 | UPPC_Requirement, |
8170 | |
8171 | // A requires-clause. |
8172 | UPPC_RequiresClause, |
8173 | }; |
8174 | |
8175 | /// Diagnose unexpanded parameter packs. |
8176 | /// |
8177 | /// \param Loc The location at which we should emit the diagnostic. |
8178 | /// |
8179 | /// \param UPPC The context in which we are diagnosing unexpanded |
8180 | /// parameter packs. |
8181 | /// |
8182 | /// \param Unexpanded the set of unexpanded parameter packs. |
8183 | /// |
8184 | /// \returns true if an error occurred, false otherwise. |
8185 | bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc, |
8186 | UnexpandedParameterPackContext UPPC, |
8187 | ArrayRef<UnexpandedParameterPack> Unexpanded); |
8188 | |
8189 | /// If the given type contains an unexpanded parameter pack, |
8190 | /// diagnose the error. |
8191 | /// |
8192 | /// \param Loc The source location where a diagnostc should be emitted. |
8193 | /// |
8194 | /// \param T The type that is being checked for unexpanded parameter |
8195 | /// packs. |
8196 | /// |
8197 | /// \returns true if an error occurred, false otherwise. |
8198 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, |
8199 | UnexpandedParameterPackContext UPPC); |
8200 | |
8201 | /// If the given expression contains an unexpanded parameter |
8202 | /// pack, diagnose the error. |
8203 | /// |
8204 | /// \param E The expression that is being checked for unexpanded |
8205 | /// parameter packs. |
8206 | /// |
8207 | /// \returns true if an error occurred, false otherwise. |
8208 | bool DiagnoseUnexpandedParameterPack(Expr *E, |
8209 | UnexpandedParameterPackContext UPPC = UPPC_Expression); |
8210 | |
8211 | /// If the given requirees-expression contains an unexpanded reference to one |
8212 | /// of its own parameter packs, diagnose the error. |
8213 | /// |
8214 | /// \param RE The requiress-expression that is being checked for unexpanded |
8215 | /// parameter packs. |
8216 | /// |
8217 | /// \returns true if an error occurred, false otherwise. |
8218 | bool DiagnoseUnexpandedParameterPackInRequiresExpr(RequiresExpr *RE); |
8219 | |
8220 | /// If the given nested-name-specifier contains an unexpanded |
8221 | /// parameter pack, diagnose the error. |
8222 | /// |
8223 | /// \param SS The nested-name-specifier that is being checked for |
8224 | /// unexpanded parameter packs. |
8225 | /// |
8226 | /// \returns true if an error occurred, false otherwise. |
8227 | bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, |
8228 | UnexpandedParameterPackContext UPPC); |
8229 | |
8230 | /// If the given name contains an unexpanded parameter pack, |
8231 | /// diagnose the error. |
8232 | /// |
8233 | /// \param NameInfo The name (with source location information) that |
8234 | /// is being checked for unexpanded parameter packs. |
8235 | /// |
8236 | /// \returns true if an error occurred, false otherwise. |
8237 | bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, |
8238 | UnexpandedParameterPackContext UPPC); |
8239 | |
8240 | /// If the given template name contains an unexpanded parameter pack, |
8241 | /// diagnose the error. |
8242 | /// |
8243 | /// \param Loc The location of the template name. |
8244 | /// |
8245 | /// \param Template The template name that is being checked for unexpanded |
8246 | /// parameter packs. |
8247 | /// |
8248 | /// \returns true if an error occurred, false otherwise. |
8249 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, |
8250 | TemplateName Template, |
8251 | UnexpandedParameterPackContext UPPC); |
8252 | |
8253 | /// If the given template argument contains an unexpanded parameter |
8254 | /// pack, diagnose the error. |
8255 | /// |
8256 | /// \param Arg The template argument that is being checked for unexpanded |
8257 | /// parameter packs. |
8258 | /// |
8259 | /// \returns true if an error occurred, false otherwise. |
8260 | bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, |
8261 | UnexpandedParameterPackContext UPPC); |
8262 | |
8263 | /// Collect the set of unexpanded parameter packs within the given |
8264 | /// template argument. |
8265 | /// |
8266 | /// \param Arg The template argument that will be traversed to find |
8267 | /// unexpanded parameter packs. |
8268 | void collectUnexpandedParameterPacks(TemplateArgument Arg, |
8269 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
8270 | |
8271 | /// Collect the set of unexpanded parameter packs within the given |
8272 | /// template argument. |
8273 | /// |
8274 | /// \param Arg The template argument that will be traversed to find |
8275 | /// unexpanded parameter packs. |
8276 | void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, |
8277 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
8278 | |
8279 | /// Collect the set of unexpanded parameter packs within the given |
8280 | /// type. |
8281 | /// |
8282 | /// \param T The type that will be traversed to find |
8283 | /// unexpanded parameter packs. |
8284 | void collectUnexpandedParameterPacks(QualType T, |
8285 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
8286 | |
8287 | /// Collect the set of unexpanded parameter packs within the given |
8288 | /// type. |
8289 | /// |
8290 | /// \param TL The type that will be traversed to find |
8291 | /// unexpanded parameter packs. |
8292 | void collectUnexpandedParameterPacks(TypeLoc TL, |
8293 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
8294 | |
8295 | /// Collect the set of unexpanded parameter packs within the given |
8296 | /// nested-name-specifier. |
8297 | /// |
8298 | /// \param NNS The nested-name-specifier that will be traversed to find |
8299 | /// unexpanded parameter packs. |
8300 | void collectUnexpandedParameterPacks(NestedNameSpecifierLoc NNS, |
8301 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
8302 | |
8303 | /// Collect the set of unexpanded parameter packs within the given |
8304 | /// name. |
8305 | /// |
8306 | /// \param NameInfo The name that will be traversed to find |
8307 | /// unexpanded parameter packs. |
8308 | void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo, |
8309 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
8310 | |
8311 | /// Invoked when parsing a template argument followed by an |
8312 | /// ellipsis, which creates a pack expansion. |
8313 | /// |
8314 | /// \param Arg The template argument preceding the ellipsis, which |
8315 | /// may already be invalid. |
8316 | /// |
8317 | /// \param EllipsisLoc The location of the ellipsis. |
8318 | ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, |
8319 | SourceLocation EllipsisLoc); |
8320 | |
8321 | /// Invoked when parsing a type followed by an ellipsis, which |
8322 | /// creates a pack expansion. |
8323 | /// |
8324 | /// \param Type The type preceding the ellipsis, which will become |
8325 | /// the pattern of the pack expansion. |
8326 | /// |
8327 | /// \param EllipsisLoc The location of the ellipsis. |
8328 | TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); |
8329 | |
8330 | /// Construct a pack expansion type from the pattern of the pack |
8331 | /// expansion. |
8332 | TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, |
8333 | SourceLocation EllipsisLoc, |
8334 | Optional<unsigned> NumExpansions); |
8335 | |
8336 | /// Construct a pack expansion type from the pattern of the pack |
8337 | /// expansion. |
8338 | QualType CheckPackExpansion(QualType Pattern, |
8339 | SourceRange PatternRange, |
8340 | SourceLocation EllipsisLoc, |
8341 | Optional<unsigned> NumExpansions); |
8342 | |
8343 | /// Invoked when parsing an expression followed by an ellipsis, which |
8344 | /// creates a pack expansion. |
8345 | /// |
8346 | /// \param Pattern The expression preceding the ellipsis, which will become |
8347 | /// the pattern of the pack expansion. |
8348 | /// |
8349 | /// \param EllipsisLoc The location of the ellipsis. |
8350 | ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); |
8351 | |
8352 | /// Invoked when parsing an expression followed by an ellipsis, which |
8353 | /// creates a pack expansion. |
8354 | /// |
8355 | /// \param Pattern The expression preceding the ellipsis, which will become |
8356 | /// the pattern of the pack expansion. |
8357 | /// |
8358 | /// \param EllipsisLoc The location of the ellipsis. |
8359 | ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
8360 | Optional<unsigned> NumExpansions); |
8361 | |
8362 | /// Determine whether we could expand a pack expansion with the |
8363 | /// given set of parameter packs into separate arguments by repeatedly |
8364 | /// transforming the pattern. |
8365 | /// |
8366 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
8367 | /// pack expansion. |
8368 | /// |
8369 | /// \param PatternRange The source range that covers the entire pattern of |
8370 | /// the pack expansion. |
8371 | /// |
8372 | /// \param Unexpanded The set of unexpanded parameter packs within the |
8373 | /// pattern. |
8374 | /// |
8375 | /// \param ShouldExpand Will be set to \c true if the transformer should |
8376 | /// expand the corresponding pack expansions into separate arguments. When |
8377 | /// set, \c NumExpansions must also be set. |
8378 | /// |
8379 | /// \param RetainExpansion Whether the caller should add an unexpanded |
8380 | /// pack expansion after all of the expanded arguments. This is used |
8381 | /// when extending explicitly-specified template argument packs per |
8382 | /// C++0x [temp.arg.explicit]p9. |
8383 | /// |
8384 | /// \param NumExpansions The number of separate arguments that will be in |
8385 | /// the expanded form of the corresponding pack expansion. This is both an |
8386 | /// input and an output parameter, which can be set by the caller if the |
8387 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
8388 | /// and will be set by the callee when the number of expansions is known. |
8389 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
8390 | /// set this value in other cases. |
8391 | /// |
8392 | /// \returns true if an error occurred (e.g., because the parameter packs |
8393 | /// are to be instantiated with arguments of different lengths), false |
8394 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
8395 | /// must be set. |
8396 | bool CheckParameterPacksForExpansion(SourceLocation EllipsisLoc, |
8397 | SourceRange PatternRange, |
8398 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
8399 | const MultiLevelTemplateArgumentList &TemplateArgs, |
8400 | bool &ShouldExpand, |
8401 | bool &RetainExpansion, |
8402 | Optional<unsigned> &NumExpansions); |
8403 | |
8404 | /// Determine the number of arguments in the given pack expansion |
8405 | /// type. |
8406 | /// |
8407 | /// This routine assumes that the number of arguments in the expansion is |
8408 | /// consistent across all of the unexpanded parameter packs in its pattern. |
8409 | /// |
8410 | /// Returns an empty Optional if the type can't be expanded. |
8411 | Optional<unsigned> getNumArgumentsInExpansion(QualType T, |
8412 | const MultiLevelTemplateArgumentList &TemplateArgs); |
8413 | |
8414 | /// Determine whether the given declarator contains any unexpanded |
8415 | /// parameter packs. |
8416 | /// |
8417 | /// This routine is used by the parser to disambiguate function declarators |
8418 | /// with an ellipsis prior to the ')', e.g., |
8419 | /// |
8420 | /// \code |
8421 | /// void f(T...); |
8422 | /// \endcode |
8423 | /// |
8424 | /// To determine whether we have an (unnamed) function parameter pack or |
8425 | /// a variadic function. |
8426 | /// |
8427 | /// \returns true if the declarator contains any unexpanded parameter packs, |
8428 | /// false otherwise. |
8429 | bool containsUnexpandedParameterPacks(Declarator &D); |
8430 | |
8431 | /// Returns the pattern of the pack expansion for a template argument. |
8432 | /// |
8433 | /// \param OrigLoc The template argument to expand. |
8434 | /// |
8435 | /// \param Ellipsis Will be set to the location of the ellipsis. |
8436 | /// |
8437 | /// \param NumExpansions Will be set to the number of expansions that will |
8438 | /// be generated from this pack expansion, if known a priori. |
8439 | TemplateArgumentLoc getTemplateArgumentPackExpansionPattern( |
8440 | TemplateArgumentLoc OrigLoc, |
8441 | SourceLocation &Ellipsis, |
8442 | Optional<unsigned> &NumExpansions) const; |
8443 | |
8444 | /// Given a template argument that contains an unexpanded parameter pack, but |
8445 | /// which has already been substituted, attempt to determine the number of |
8446 | /// elements that will be produced once this argument is fully-expanded. |
8447 | /// |
8448 | /// This is intended for use when transforming 'sizeof...(Arg)' in order to |
8449 | /// avoid actually expanding the pack where possible. |
8450 | Optional<unsigned> getFullyPackExpandedSize(TemplateArgument Arg); |
8451 | |
8452 | //===--------------------------------------------------------------------===// |
8453 | // C++ Template Argument Deduction (C++ [temp.deduct]) |
8454 | //===--------------------------------------------------------------------===// |
8455 | |
8456 | /// Adjust the type \p ArgFunctionType to match the calling convention, |
8457 | /// noreturn, and optionally the exception specification of \p FunctionType. |
8458 | /// Deduction often wants to ignore these properties when matching function |
8459 | /// types. |
8460 | QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType, |
8461 | bool AdjustExceptionSpec = false); |
8462 | |
8463 | /// Describes the result of template argument deduction. |
8464 | /// |
8465 | /// The TemplateDeductionResult enumeration describes the result of |
8466 | /// template argument deduction, as returned from |
8467 | /// DeduceTemplateArguments(). The separate TemplateDeductionInfo |
8468 | /// structure provides additional information about the results of |
8469 | /// template argument deduction, e.g., the deduced template argument |
8470 | /// list (if successful) or the specific template parameters or |
8471 | /// deduced arguments that were involved in the failure. |
8472 | enum TemplateDeductionResult { |
8473 | /// Template argument deduction was successful. |
8474 | TDK_Success = 0, |
8475 | /// The declaration was invalid; do nothing. |
8476 | TDK_Invalid, |
8477 | /// Template argument deduction exceeded the maximum template |
8478 | /// instantiation depth (which has already been diagnosed). |
8479 | TDK_InstantiationDepth, |
8480 | /// Template argument deduction did not deduce a value |
8481 | /// for every template parameter. |
8482 | TDK_Incomplete, |
8483 | /// Template argument deduction did not deduce a value for every |
8484 | /// expansion of an expanded template parameter pack. |
8485 | TDK_IncompletePack, |
8486 | /// Template argument deduction produced inconsistent |
8487 | /// deduced values for the given template parameter. |
8488 | TDK_Inconsistent, |
8489 | /// Template argument deduction failed due to inconsistent |
8490 | /// cv-qualifiers on a template parameter type that would |
8491 | /// otherwise be deduced, e.g., we tried to deduce T in "const T" |
8492 | /// but were given a non-const "X". |
8493 | TDK_Underqualified, |
8494 | /// Substitution of the deduced template argument values |
8495 | /// resulted in an error. |
8496 | TDK_SubstitutionFailure, |
8497 | /// After substituting deduced template arguments, a dependent |
8498 | /// parameter type did not match the corresponding argument. |
8499 | TDK_DeducedMismatch, |
8500 | /// After substituting deduced template arguments, an element of |
8501 | /// a dependent parameter type did not match the corresponding element |
8502 | /// of the corresponding argument (when deducing from an initializer list). |
8503 | TDK_DeducedMismatchNested, |
8504 | /// A non-depnedent component of the parameter did not match the |
8505 | /// corresponding component of the argument. |
8506 | TDK_NonDeducedMismatch, |
8507 | /// When performing template argument deduction for a function |
8508 | /// template, there were too many call arguments. |
8509 | TDK_TooManyArguments, |
8510 | /// When performing template argument deduction for a function |
8511 | /// template, there were too few call arguments. |
8512 | TDK_TooFewArguments, |
8513 | /// The explicitly-specified template arguments were not valid |
8514 | /// template arguments for the given template. |
8515 | TDK_InvalidExplicitArguments, |
8516 | /// Checking non-dependent argument conversions failed. |
8517 | TDK_NonDependentConversionFailure, |
8518 | /// The deduced arguments did not satisfy the constraints associated |
8519 | /// with the template. |
8520 | TDK_ConstraintsNotSatisfied, |
8521 | /// Deduction failed; that's all we know. |
8522 | TDK_MiscellaneousDeductionFailure, |
8523 | /// CUDA Target attributes do not match. |
8524 | TDK_CUDATargetMismatch |
8525 | }; |
8526 | |
8527 | TemplateDeductionResult |
8528 | DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, |
8529 | const TemplateArgumentList &TemplateArgs, |
8530 | sema::TemplateDeductionInfo &Info); |
8531 | |
8532 | TemplateDeductionResult |
8533 | DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, |
8534 | const TemplateArgumentList &TemplateArgs, |
8535 | sema::TemplateDeductionInfo &Info); |
8536 | |
8537 | TemplateDeductionResult SubstituteExplicitTemplateArguments( |
8538 | FunctionTemplateDecl *FunctionTemplate, |
8539 | TemplateArgumentListInfo &ExplicitTemplateArgs, |
8540 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
8541 | SmallVectorImpl<QualType> &ParamTypes, QualType *FunctionType, |
8542 | sema::TemplateDeductionInfo &Info); |
8543 | |
8544 | /// brief A function argument from which we performed template argument |
8545 | // deduction for a call. |
8546 | struct OriginalCallArg { |
8547 | OriginalCallArg(QualType OriginalParamType, bool DecomposedParam, |
8548 | unsigned ArgIdx, QualType OriginalArgType) |
8549 | : OriginalParamType(OriginalParamType), |
8550 | DecomposedParam(DecomposedParam), ArgIdx(ArgIdx), |
8551 | OriginalArgType(OriginalArgType) {} |
8552 | |
8553 | QualType OriginalParamType; |
8554 | bool DecomposedParam; |
8555 | unsigned ArgIdx; |
8556 | QualType OriginalArgType; |
8557 | }; |
8558 | |
8559 | TemplateDeductionResult FinishTemplateArgumentDeduction( |
8560 | FunctionTemplateDecl *FunctionTemplate, |
8561 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
8562 | unsigned NumExplicitlySpecified, FunctionDecl *&Specialization, |
8563 | sema::TemplateDeductionInfo &Info, |
8564 | SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = nullptr, |
8565 | bool PartialOverloading = false, |
8566 | llvm::function_ref<bool()> CheckNonDependent = []{ return false; }); |
8567 | |
8568 | TemplateDeductionResult DeduceTemplateArguments( |
8569 | FunctionTemplateDecl *FunctionTemplate, |
8570 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
8571 | FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, |
8572 | bool PartialOverloading, |
8573 | llvm::function_ref<bool(ArrayRef<QualType>)> CheckNonDependent); |
8574 | |
8575 | TemplateDeductionResult |
8576 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
8577 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
8578 | QualType ArgFunctionType, |
8579 | FunctionDecl *&Specialization, |
8580 | sema::TemplateDeductionInfo &Info, |
8581 | bool IsAddressOfFunction = false); |
8582 | |
8583 | TemplateDeductionResult |
8584 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
8585 | QualType ToType, |
8586 | CXXConversionDecl *&Specialization, |
8587 | sema::TemplateDeductionInfo &Info); |
8588 | |
8589 | TemplateDeductionResult |
8590 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
8591 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
8592 | FunctionDecl *&Specialization, |
8593 | sema::TemplateDeductionInfo &Info, |
8594 | bool IsAddressOfFunction = false); |
8595 | |
8596 | /// Substitute Replacement for \p auto in \p TypeWithAuto |
8597 | QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement); |
8598 | /// Substitute Replacement for auto in TypeWithAuto |
8599 | TypeSourceInfo* SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
8600 | QualType Replacement); |
8601 | |
8602 | // Substitute auto in TypeWithAuto for a Dependent auto type |
8603 | QualType SubstAutoTypeDependent(QualType TypeWithAuto); |
8604 | |
8605 | // Substitute auto in TypeWithAuto for a Dependent auto type |
8606 | TypeSourceInfo * |
8607 | SubstAutoTypeSourceInfoDependent(TypeSourceInfo *TypeWithAuto); |
8608 | |
8609 | /// Completely replace the \c auto in \p TypeWithAuto by |
8610 | /// \p Replacement. This does not retain any \c auto type sugar. |
8611 | QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement); |
8612 | TypeSourceInfo *ReplaceAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
8613 | QualType Replacement); |
8614 | |
8615 | /// Result type of DeduceAutoType. |
8616 | enum DeduceAutoResult { |
8617 | DAR_Succeeded, |
8618 | DAR_Failed, |
8619 | DAR_FailedAlreadyDiagnosed |
8620 | }; |
8621 | |
8622 | DeduceAutoResult |
8623 | DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer, QualType &Result, |
8624 | Optional<unsigned> DependentDeductionDepth = None, |
8625 | bool IgnoreConstraints = false); |
8626 | DeduceAutoResult |
8627 | DeduceAutoType(TypeLoc AutoTypeLoc, Expr *&Initializer, QualType &Result, |
8628 | Optional<unsigned> DependentDeductionDepth = None, |
8629 | bool IgnoreConstraints = false); |
8630 | void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init); |
8631 | bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc, |
8632 | bool Diagnose = true); |
8633 | |
8634 | /// Declare implicit deduction guides for a class template if we've |
8635 | /// not already done so. |
8636 | void DeclareImplicitDeductionGuides(TemplateDecl *Template, |
8637 | SourceLocation Loc); |
8638 | |
8639 | QualType DeduceTemplateSpecializationFromInitializer( |
8640 | TypeSourceInfo *TInfo, const InitializedEntity &Entity, |
8641 | const InitializationKind &Kind, MultiExprArg Init); |
8642 | |
8643 | QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name, |
8644 | QualType Type, TypeSourceInfo *TSI, |
8645 | SourceRange Range, bool DirectInit, |
8646 | Expr *Init); |
8647 | |
8648 | TypeLoc getReturnTypeLoc(FunctionDecl *FD) const; |
8649 | |
8650 | bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD, |
8651 | SourceLocation ReturnLoc, |
8652 | Expr *&RetExpr, AutoType *AT); |
8653 | |
8654 | FunctionTemplateDecl *getMoreSpecializedTemplate( |
8655 | FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc, |
8656 | TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1, |
8657 | unsigned NumCallArguments2, bool Reversed = false); |
8658 | UnresolvedSetIterator |
8659 | getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd, |
8660 | TemplateSpecCandidateSet &FailedCandidates, |
8661 | SourceLocation Loc, |
8662 | const PartialDiagnostic &NoneDiag, |
8663 | const PartialDiagnostic &AmbigDiag, |
8664 | const PartialDiagnostic &CandidateDiag, |
8665 | bool Complain = true, QualType TargetType = QualType()); |
8666 | |
8667 | ClassTemplatePartialSpecializationDecl * |
8668 | getMoreSpecializedPartialSpecialization( |
8669 | ClassTemplatePartialSpecializationDecl *PS1, |
8670 | ClassTemplatePartialSpecializationDecl *PS2, |
8671 | SourceLocation Loc); |
8672 | |
8673 | bool isMoreSpecializedThanPrimary(ClassTemplatePartialSpecializationDecl *T, |
8674 | sema::TemplateDeductionInfo &Info); |
8675 | |
8676 | VarTemplatePartialSpecializationDecl *getMoreSpecializedPartialSpecialization( |
8677 | VarTemplatePartialSpecializationDecl *PS1, |
8678 | VarTemplatePartialSpecializationDecl *PS2, SourceLocation Loc); |
8679 | |
8680 | bool isMoreSpecializedThanPrimary(VarTemplatePartialSpecializationDecl *T, |
8681 | sema::TemplateDeductionInfo &Info); |
8682 | |
8683 | bool isTemplateTemplateParameterAtLeastAsSpecializedAs( |
8684 | TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc); |
8685 | |
8686 | void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced, |
8687 | unsigned Depth, llvm::SmallBitVector &Used); |
8688 | |
8689 | void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, |
8690 | bool OnlyDeduced, |
8691 | unsigned Depth, |
8692 | llvm::SmallBitVector &Used); |
8693 | void MarkDeducedTemplateParameters( |
8694 | const FunctionTemplateDecl *FunctionTemplate, |
8695 | llvm::SmallBitVector &Deduced) { |
8696 | return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced); |
8697 | } |
8698 | static void MarkDeducedTemplateParameters(ASTContext &Ctx, |
8699 | const FunctionTemplateDecl *FunctionTemplate, |
8700 | llvm::SmallBitVector &Deduced); |
8701 | |
8702 | //===--------------------------------------------------------------------===// |
8703 | // C++ Template Instantiation |
8704 | // |
8705 | |
8706 | MultiLevelTemplateArgumentList |
8707 | getTemplateInstantiationArgs(NamedDecl *D, |
8708 | const TemplateArgumentList *Innermost = nullptr, |
8709 | bool RelativeToPrimary = false, |
8710 | const FunctionDecl *Pattern = nullptr); |
8711 | |
8712 | /// A context in which code is being synthesized (where a source location |
8713 | /// alone is not sufficient to identify the context). This covers template |
8714 | /// instantiation and various forms of implicitly-generated functions. |
8715 | struct CodeSynthesisContext { |
8716 | /// The kind of template instantiation we are performing |
8717 | enum SynthesisKind { |
8718 | /// We are instantiating a template declaration. The entity is |
8719 | /// the declaration we're instantiating (e.g., a CXXRecordDecl). |
8720 | TemplateInstantiation, |
8721 | |
8722 | /// We are instantiating a default argument for a template |
8723 | /// parameter. The Entity is the template parameter whose argument is |
8724 | /// being instantiated, the Template is the template, and the |
8725 | /// TemplateArgs/NumTemplateArguments provide the template arguments as |
8726 | /// specified. |
8727 | DefaultTemplateArgumentInstantiation, |
8728 | |
8729 | /// We are instantiating a default argument for a function. |
8730 | /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs |
8731 | /// provides the template arguments as specified. |
8732 | DefaultFunctionArgumentInstantiation, |
8733 | |
8734 | /// We are substituting explicit template arguments provided for |
8735 | /// a function template. The entity is a FunctionTemplateDecl. |
8736 | ExplicitTemplateArgumentSubstitution, |
8737 | |
8738 | /// We are substituting template argument determined as part of |
8739 | /// template argument deduction for either a class template |
8740 | /// partial specialization or a function template. The |
8741 | /// Entity is either a {Class|Var}TemplatePartialSpecializationDecl or |
8742 | /// a TemplateDecl. |
8743 | DeducedTemplateArgumentSubstitution, |
8744 | |
8745 | /// We are substituting prior template arguments into a new |
8746 | /// template parameter. The template parameter itself is either a |
8747 | /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. |
8748 | PriorTemplateArgumentSubstitution, |
8749 | |
8750 | /// We are checking the validity of a default template argument that |
8751 | /// has been used when naming a template-id. |
8752 | DefaultTemplateArgumentChecking, |
8753 | |
8754 | /// We are computing the exception specification for a defaulted special |
8755 | /// member function. |
8756 | ExceptionSpecEvaluation, |
8757 | |
8758 | /// We are instantiating the exception specification for a function |
8759 | /// template which was deferred until it was needed. |
8760 | ExceptionSpecInstantiation, |
8761 | |
8762 | /// We are instantiating a requirement of a requires expression. |
8763 | RequirementInstantiation, |
8764 | |
8765 | /// We are checking the satisfaction of a nested requirement of a requires |
8766 | /// expression. |
8767 | NestedRequirementConstraintsCheck, |
8768 | |
8769 | /// We are declaring an implicit special member function. |
8770 | DeclaringSpecialMember, |
8771 | |
8772 | /// We are declaring an implicit 'operator==' for a defaulted |
8773 | /// 'operator<=>'. |
8774 | DeclaringImplicitEqualityComparison, |
8775 | |
8776 | /// We are defining a synthesized function (such as a defaulted special |
8777 | /// member). |
8778 | DefiningSynthesizedFunction, |
8779 | |
8780 | // We are checking the constraints associated with a constrained entity or |
8781 | // the constraint expression of a concept. This includes the checks that |
8782 | // atomic constraints have the type 'bool' and that they can be constant |
8783 | // evaluated. |
8784 | ConstraintsCheck, |
8785 | |
8786 | // We are substituting template arguments into a constraint expression. |
8787 | ConstraintSubstitution, |
8788 | |
8789 | // We are normalizing a constraint expression. |
8790 | ConstraintNormalization, |
8791 | |
8792 | // We are substituting into the parameter mapping of an atomic constraint |
8793 | // during normalization. |
8794 | ParameterMappingSubstitution, |
8795 | |
8796 | /// We are rewriting a comparison operator in terms of an operator<=>. |
8797 | RewritingOperatorAsSpaceship, |
8798 | |
8799 | /// We are initializing a structured binding. |
8800 | InitializingStructuredBinding, |
8801 | |
8802 | /// We are marking a class as __dllexport. |
8803 | MarkingClassDllexported, |
8804 | |
8805 | /// Added for Template instantiation observation. |
8806 | /// Memoization means we are _not_ instantiating a template because |
8807 | /// it is already instantiated (but we entered a context where we |
8808 | /// would have had to if it was not already instantiated). |
8809 | Memoization |
8810 | } Kind; |
8811 | |
8812 | /// Was the enclosing context a non-instantiation SFINAE context? |
8813 | bool SavedInNonInstantiationSFINAEContext; |
8814 | |
8815 | /// The point of instantiation or synthesis within the source code. |
8816 | SourceLocation PointOfInstantiation; |
8817 | |
8818 | /// The entity that is being synthesized. |
8819 | Decl *Entity; |
8820 | |
8821 | /// The template (or partial specialization) in which we are |
8822 | /// performing the instantiation, for substitutions of prior template |
8823 | /// arguments. |
8824 | NamedDecl *Template; |
8825 | |
8826 | /// The list of template arguments we are substituting, if they |
8827 | /// are not part of the entity. |
8828 | const TemplateArgument *TemplateArgs; |
8829 | |
8830 | // FIXME: Wrap this union around more members, or perhaps store the |
8831 | // kind-specific members in the RAII object owning the context. |
8832 | union { |
8833 | /// The number of template arguments in TemplateArgs. |
8834 | unsigned NumTemplateArgs; |
8835 | |
8836 | /// The special member being declared or defined. |
8837 | CXXSpecialMember SpecialMember; |
8838 | }; |
8839 | |
8840 | ArrayRef<TemplateArgument> template_arguments() const { |
8841 | assert(Kind != DeclaringSpecialMember)(static_cast <bool> (Kind != DeclaringSpecialMember) ? void (0) : __assert_fail ("Kind != DeclaringSpecialMember", "clang/include/clang/Sema/Sema.h" , 8841, __extension__ __PRETTY_FUNCTION__)); |
8842 | return {TemplateArgs, NumTemplateArgs}; |
8843 | } |
8844 | |
8845 | /// The template deduction info object associated with the |
8846 | /// substitution or checking of explicit or deduced template arguments. |
8847 | sema::TemplateDeductionInfo *DeductionInfo; |
8848 | |
8849 | /// The source range that covers the construct that cause |
8850 | /// the instantiation, e.g., the template-id that causes a class |
8851 | /// template instantiation. |
8852 | SourceRange InstantiationRange; |
8853 | |
8854 | CodeSynthesisContext() |
8855 | : Kind(TemplateInstantiation), |
8856 | SavedInNonInstantiationSFINAEContext(false), Entity(nullptr), |
8857 | Template(nullptr), TemplateArgs(nullptr), NumTemplateArgs(0), |
8858 | DeductionInfo(nullptr) {} |
8859 | |
8860 | /// Determines whether this template is an actual instantiation |
8861 | /// that should be counted toward the maximum instantiation depth. |
8862 | bool isInstantiationRecord() const; |
8863 | }; |
8864 | |
8865 | /// List of active code synthesis contexts. |
8866 | /// |
8867 | /// This vector is treated as a stack. As synthesis of one entity requires |
8868 | /// synthesis of another, additional contexts are pushed onto the stack. |
8869 | SmallVector<CodeSynthesisContext, 16> CodeSynthesisContexts; |
8870 | |
8871 | /// Specializations whose definitions are currently being instantiated. |
8872 | llvm::DenseSet<std::pair<Decl *, unsigned>> InstantiatingSpecializations; |
8873 | |
8874 | /// Non-dependent types used in templates that have already been instantiated |
8875 | /// by some template instantiation. |
8876 | llvm::DenseSet<QualType> InstantiatedNonDependentTypes; |
8877 | |
8878 | /// Extra modules inspected when performing a lookup during a template |
8879 | /// instantiation. Computed lazily. |
8880 | SmallVector<Module*, 16> CodeSynthesisContextLookupModules; |
8881 | |
8882 | /// Cache of additional modules that should be used for name lookup |
8883 | /// within the current template instantiation. Computed lazily; use |
8884 | /// getLookupModules() to get a complete set. |
8885 | llvm::DenseSet<Module*> LookupModulesCache; |
8886 | |
8887 | /// Get the set of additional modules that should be checked during |
8888 | /// name lookup. A module and its imports become visible when instanting a |
8889 | /// template defined within it. |
8890 | llvm::DenseSet<Module*> &getLookupModules(); |
8891 | |
8892 | /// Map from the most recent declaration of a namespace to the most |
8893 | /// recent visible declaration of that namespace. |
8894 | llvm::DenseMap<NamedDecl*, NamedDecl*> VisibleNamespaceCache; |
8895 | |
8896 | /// Whether we are in a SFINAE context that is not associated with |
8897 | /// template instantiation. |
8898 | /// |
8899 | /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside |
8900 | /// of a template instantiation or template argument deduction. |
8901 | bool InNonInstantiationSFINAEContext; |
8902 | |
8903 | /// The number of \p CodeSynthesisContexts that are not template |
8904 | /// instantiations and, therefore, should not be counted as part of the |
8905 | /// instantiation depth. |
8906 | /// |
8907 | /// When the instantiation depth reaches the user-configurable limit |
8908 | /// \p LangOptions::InstantiationDepth we will abort instantiation. |
8909 | // FIXME: Should we have a similar limit for other forms of synthesis? |
8910 | unsigned NonInstantiationEntries; |
8911 | |
8912 | /// The depth of the context stack at the point when the most recent |
8913 | /// error or warning was produced. |
8914 | /// |
8915 | /// This value is used to suppress printing of redundant context stacks |
8916 | /// when there are multiple errors or warnings in the same instantiation. |
8917 | // FIXME: Does this belong in Sema? It's tough to implement it anywhere else. |
8918 | unsigned LastEmittedCodeSynthesisContextDepth = 0; |
8919 | |
8920 | /// The template instantiation callbacks to trace or track |
8921 | /// instantiations (objects can be chained). |
8922 | /// |
8923 | /// This callbacks is used to print, trace or track template |
8924 | /// instantiations as they are being constructed. |
8925 | std::vector<std::unique_ptr<TemplateInstantiationCallback>> |
8926 | TemplateInstCallbacks; |
8927 | |
8928 | /// The current index into pack expansion arguments that will be |
8929 | /// used for substitution of parameter packs. |
8930 | /// |
8931 | /// The pack expansion index will be -1 to indicate that parameter packs |
8932 | /// should be instantiated as themselves. Otherwise, the index specifies |
8933 | /// which argument within the parameter pack will be used for substitution. |
8934 | int ArgumentPackSubstitutionIndex; |
8935 | |
8936 | /// RAII object used to change the argument pack substitution index |
8937 | /// within a \c Sema object. |
8938 | /// |
8939 | /// See \c ArgumentPackSubstitutionIndex for more information. |
8940 | class ArgumentPackSubstitutionIndexRAII { |
8941 | Sema &Self; |
8942 | int OldSubstitutionIndex; |
8943 | |
8944 | public: |
8945 | ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) |
8946 | : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { |
8947 | Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; |
8948 | } |
8949 | |
8950 | ~ArgumentPackSubstitutionIndexRAII() { |
8951 | Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; |
8952 | } |
8953 | }; |
8954 | |
8955 | friend class ArgumentPackSubstitutionRAII; |
8956 | |
8957 | /// For each declaration that involved template argument deduction, the |
8958 | /// set of diagnostics that were suppressed during that template argument |
8959 | /// deduction. |
8960 | /// |
8961 | /// FIXME: Serialize this structure to the AST file. |
8962 | typedef llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> > |
8963 | SuppressedDiagnosticsMap; |
8964 | SuppressedDiagnosticsMap SuppressedDiagnostics; |
8965 | |
8966 | /// A stack object to be created when performing template |
8967 | /// instantiation. |
8968 | /// |
8969 | /// Construction of an object of type \c InstantiatingTemplate |
8970 | /// pushes the current instantiation onto the stack of active |
8971 | /// instantiations. If the size of this stack exceeds the maximum |
8972 | /// number of recursive template instantiations, construction |
8973 | /// produces an error and evaluates true. |
8974 | /// |
8975 | /// Destruction of this object will pop the named instantiation off |
8976 | /// the stack. |
8977 | struct InstantiatingTemplate { |
8978 | /// Note that we are instantiating a class template, |
8979 | /// function template, variable template, alias template, |
8980 | /// or a member thereof. |
8981 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8982 | Decl *Entity, |
8983 | SourceRange InstantiationRange = SourceRange()); |
8984 | |
8985 | struct ExceptionSpecification {}; |
8986 | /// Note that we are instantiating an exception specification |
8987 | /// of a function template. |
8988 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8989 | FunctionDecl *Entity, ExceptionSpecification, |
8990 | SourceRange InstantiationRange = SourceRange()); |
8991 | |
8992 | /// Note that we are instantiating a default argument in a |
8993 | /// template-id. |
8994 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
8995 | TemplateParameter Param, TemplateDecl *Template, |
8996 | ArrayRef<TemplateArgument> TemplateArgs, |
8997 | SourceRange InstantiationRange = SourceRange()); |
8998 | |
8999 | /// Note that we are substituting either explicitly-specified or |
9000 | /// deduced template arguments during function template argument deduction. |
9001 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9002 | FunctionTemplateDecl *FunctionTemplate, |
9003 | ArrayRef<TemplateArgument> TemplateArgs, |
9004 | CodeSynthesisContext::SynthesisKind Kind, |
9005 | sema::TemplateDeductionInfo &DeductionInfo, |
9006 | SourceRange InstantiationRange = SourceRange()); |
9007 | |
9008 | /// Note that we are instantiating as part of template |
9009 | /// argument deduction for a class template declaration. |
9010 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9011 | TemplateDecl *Template, |
9012 | ArrayRef<TemplateArgument> TemplateArgs, |
9013 | sema::TemplateDeductionInfo &DeductionInfo, |
9014 | SourceRange InstantiationRange = SourceRange()); |
9015 | |
9016 | /// Note that we are instantiating as part of template |
9017 | /// argument deduction for a class template partial |
9018 | /// specialization. |
9019 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9020 | ClassTemplatePartialSpecializationDecl *PartialSpec, |
9021 | ArrayRef<TemplateArgument> TemplateArgs, |
9022 | sema::TemplateDeductionInfo &DeductionInfo, |
9023 | SourceRange InstantiationRange = SourceRange()); |
9024 | |
9025 | /// Note that we are instantiating as part of template |
9026 | /// argument deduction for a variable template partial |
9027 | /// specialization. |
9028 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9029 | VarTemplatePartialSpecializationDecl *PartialSpec, |
9030 | ArrayRef<TemplateArgument> TemplateArgs, |
9031 | sema::TemplateDeductionInfo &DeductionInfo, |
9032 | SourceRange InstantiationRange = SourceRange()); |
9033 | |
9034 | /// Note that we are instantiating a default argument for a function |
9035 | /// parameter. |
9036 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9037 | ParmVarDecl *Param, |
9038 | ArrayRef<TemplateArgument> TemplateArgs, |
9039 | SourceRange InstantiationRange = SourceRange()); |
9040 | |
9041 | /// Note that we are substituting prior template arguments into a |
9042 | /// non-type parameter. |
9043 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9044 | NamedDecl *Template, |
9045 | NonTypeTemplateParmDecl *Param, |
9046 | ArrayRef<TemplateArgument> TemplateArgs, |
9047 | SourceRange InstantiationRange); |
9048 | |
9049 | /// Note that we are substituting prior template arguments into a |
9050 | /// template template parameter. |
9051 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9052 | NamedDecl *Template, |
9053 | TemplateTemplateParmDecl *Param, |
9054 | ArrayRef<TemplateArgument> TemplateArgs, |
9055 | SourceRange InstantiationRange); |
9056 | |
9057 | /// Note that we are checking the default template argument |
9058 | /// against the template parameter for a given template-id. |
9059 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9060 | TemplateDecl *Template, |
9061 | NamedDecl *Param, |
9062 | ArrayRef<TemplateArgument> TemplateArgs, |
9063 | SourceRange InstantiationRange); |
9064 | |
9065 | struct ConstraintsCheck {}; |
9066 | /// \brief Note that we are checking the constraints associated with some |
9067 | /// constrained entity (a concept declaration or a template with associated |
9068 | /// constraints). |
9069 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9070 | ConstraintsCheck, NamedDecl *Template, |
9071 | ArrayRef<TemplateArgument> TemplateArgs, |
9072 | SourceRange InstantiationRange); |
9073 | |
9074 | struct ConstraintSubstitution {}; |
9075 | /// \brief Note that we are checking a constraint expression associated |
9076 | /// with a template declaration or as part of the satisfaction check of a |
9077 | /// concept. |
9078 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9079 | ConstraintSubstitution, NamedDecl *Template, |
9080 | sema::TemplateDeductionInfo &DeductionInfo, |
9081 | SourceRange InstantiationRange); |
9082 | |
9083 | struct ConstraintNormalization {}; |
9084 | /// \brief Note that we are normalizing a constraint expression. |
9085 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9086 | ConstraintNormalization, NamedDecl *Template, |
9087 | SourceRange InstantiationRange); |
9088 | |
9089 | struct ParameterMappingSubstitution {}; |
9090 | /// \brief Note that we are subtituting into the parameter mapping of an |
9091 | /// atomic constraint during constraint normalization. |
9092 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9093 | ParameterMappingSubstitution, NamedDecl *Template, |
9094 | SourceRange InstantiationRange); |
9095 | |
9096 | /// \brief Note that we are substituting template arguments into a part of |
9097 | /// a requirement of a requires expression. |
9098 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9099 | concepts::Requirement *Req, |
9100 | sema::TemplateDeductionInfo &DeductionInfo, |
9101 | SourceRange InstantiationRange = SourceRange()); |
9102 | |
9103 | /// \brief Note that we are checking the satisfaction of the constraint |
9104 | /// expression inside of a nested requirement. |
9105 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9106 | concepts::NestedRequirement *Req, ConstraintsCheck, |
9107 | SourceRange InstantiationRange = SourceRange()); |
9108 | |
9109 | /// Note that we have finished instantiating this template. |
9110 | void Clear(); |
9111 | |
9112 | ~InstantiatingTemplate() { Clear(); } |
9113 | |
9114 | /// Determines whether we have exceeded the maximum |
9115 | /// recursive template instantiations. |
9116 | bool isInvalid() const { return Invalid; } |
9117 | |
9118 | /// Determine whether we are already instantiating this |
9119 | /// specialization in some surrounding active instantiation. |
9120 | bool isAlreadyInstantiating() const { return AlreadyInstantiating; } |
9121 | |
9122 | private: |
9123 | Sema &SemaRef; |
9124 | bool Invalid; |
9125 | bool AlreadyInstantiating; |
9126 | bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, |
9127 | SourceRange InstantiationRange); |
9128 | |
9129 | InstantiatingTemplate( |
9130 | Sema &SemaRef, CodeSynthesisContext::SynthesisKind Kind, |
9131 | SourceLocation PointOfInstantiation, SourceRange InstantiationRange, |
9132 | Decl *Entity, NamedDecl *Template = nullptr, |
9133 | ArrayRef<TemplateArgument> TemplateArgs = None, |
9134 | sema::TemplateDeductionInfo *DeductionInfo = nullptr); |
9135 | |
9136 | InstantiatingTemplate(const InstantiatingTemplate&) = delete; |
9137 | |
9138 | InstantiatingTemplate& |
9139 | operator=(const InstantiatingTemplate&) = delete; |
9140 | }; |
9141 | |
9142 | void pushCodeSynthesisContext(CodeSynthesisContext Ctx); |
9143 | void popCodeSynthesisContext(); |
9144 | |
9145 | /// Determine whether we are currently performing template instantiation. |
9146 | bool inTemplateInstantiation() const { |
9147 | return CodeSynthesisContexts.size() > NonInstantiationEntries; |
9148 | } |
9149 | |
9150 | void PrintContextStack() { |
9151 | if (!CodeSynthesisContexts.empty() && |
9152 | CodeSynthesisContexts.size() != LastEmittedCodeSynthesisContextDepth) { |
9153 | PrintInstantiationStack(); |
9154 | LastEmittedCodeSynthesisContextDepth = CodeSynthesisContexts.size(); |
9155 | } |
9156 | if (PragmaAttributeCurrentTargetDecl) |
9157 | PrintPragmaAttributeInstantiationPoint(); |
9158 | } |
9159 | void PrintInstantiationStack(); |
9160 | |
9161 | void PrintPragmaAttributeInstantiationPoint(); |
9162 | |
9163 | /// Determines whether we are currently in a context where |
9164 | /// template argument substitution failures are not considered |
9165 | /// errors. |
9166 | /// |
9167 | /// \returns An empty \c Optional if we're not in a SFINAE context. |
9168 | /// Otherwise, contains a pointer that, if non-NULL, contains the nearest |
9169 | /// template-deduction context object, which can be used to capture |
9170 | /// diagnostics that will be suppressed. |
9171 | Optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; |
9172 | |
9173 | /// Determines whether we are currently in a context that |
9174 | /// is not evaluated as per C++ [expr] p5. |
9175 | bool isUnevaluatedContext() const { |
9176 | assert(!ExprEvalContexts.empty() &&(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9177, __extension__ __PRETTY_FUNCTION__ )) |
9177 | "Must be in an expression evaluation context")(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9177, __extension__ __PRETTY_FUNCTION__ )); |
9178 | return ExprEvalContexts.back().isUnevaluated(); |
9179 | } |
9180 | |
9181 | bool isImmediateFunctionContext() const { |
9182 | assert(!ExprEvalContexts.empty() &&(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9183, __extension__ __PRETTY_FUNCTION__ )) |
9183 | "Must be in an expression evaluation context")(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9183, __extension__ __PRETTY_FUNCTION__ )); |
9184 | return ExprEvalContexts.back().isImmediateFunctionContext(); |
9185 | } |
9186 | |
9187 | /// RAII class used to determine whether SFINAE has |
9188 | /// trapped any errors that occur during template argument |
9189 | /// deduction. |
9190 | class SFINAETrap { |
9191 | Sema &SemaRef; |
9192 | unsigned PrevSFINAEErrors; |
9193 | bool PrevInNonInstantiationSFINAEContext; |
9194 | bool PrevAccessCheckingSFINAE; |
9195 | bool PrevLastDiagnosticIgnored; |
9196 | |
9197 | public: |
9198 | explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) |
9199 | : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), |
9200 | PrevInNonInstantiationSFINAEContext( |
9201 | SemaRef.InNonInstantiationSFINAEContext), |
9202 | PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE), |
9203 | PrevLastDiagnosticIgnored( |
9204 | SemaRef.getDiagnostics().isLastDiagnosticIgnored()) |
9205 | { |
9206 | if (!SemaRef.isSFINAEContext()) |
9207 | SemaRef.InNonInstantiationSFINAEContext = true; |
9208 | SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; |
9209 | } |
9210 | |
9211 | ~SFINAETrap() { |
9212 | SemaRef.NumSFINAEErrors = PrevSFINAEErrors; |
9213 | SemaRef.InNonInstantiationSFINAEContext |
9214 | = PrevInNonInstantiationSFINAEContext; |
9215 | SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; |
9216 | SemaRef.getDiagnostics().setLastDiagnosticIgnored( |
9217 | PrevLastDiagnosticIgnored); |
9218 | } |
9219 | |
9220 | /// Determine whether any SFINAE errors have been trapped. |
9221 | bool hasErrorOccurred() const { |
9222 | return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; |
9223 | } |
9224 | }; |
9225 | |
9226 | /// RAII class used to indicate that we are performing provisional |
9227 | /// semantic analysis to determine the validity of a construct, so |
9228 | /// typo-correction and diagnostics in the immediate context (not within |
9229 | /// implicitly-instantiated templates) should be suppressed. |
9230 | class TentativeAnalysisScope { |
9231 | Sema &SemaRef; |
9232 | // FIXME: Using a SFINAETrap for this is a hack. |
9233 | SFINAETrap Trap; |
9234 | bool PrevDisableTypoCorrection; |
9235 | public: |
9236 | explicit TentativeAnalysisScope(Sema &SemaRef) |
9237 | : SemaRef(SemaRef), Trap(SemaRef, true), |
9238 | PrevDisableTypoCorrection(SemaRef.DisableTypoCorrection) { |
9239 | SemaRef.DisableTypoCorrection = true; |
9240 | } |
9241 | ~TentativeAnalysisScope() { |
9242 | SemaRef.DisableTypoCorrection = PrevDisableTypoCorrection; |
9243 | } |
9244 | }; |
9245 | |
9246 | /// The current instantiation scope used to store local |
9247 | /// variables. |
9248 | LocalInstantiationScope *CurrentInstantiationScope; |
9249 | |
9250 | /// Tracks whether we are in a context where typo correction is |
9251 | /// disabled. |
9252 | bool DisableTypoCorrection; |
9253 | |
9254 | /// The number of typos corrected by CorrectTypo. |
9255 | unsigned TyposCorrected; |
9256 | |
9257 | typedef llvm::SmallSet<SourceLocation, 2> SrcLocSet; |
9258 | typedef llvm::DenseMap<IdentifierInfo *, SrcLocSet> IdentifierSourceLocations; |
9259 | |
9260 | /// A cache containing identifiers for which typo correction failed and |
9261 | /// their locations, so that repeated attempts to correct an identifier in a |
9262 | /// given location are ignored if typo correction already failed for it. |
9263 | IdentifierSourceLocations TypoCorrectionFailures; |
9264 | |
9265 | /// Worker object for performing CFG-based warnings. |
9266 | sema::AnalysisBasedWarnings AnalysisWarnings; |
9267 | threadSafety::BeforeSet *ThreadSafetyDeclCache; |
9268 | |
9269 | /// An entity for which implicit template instantiation is required. |
9270 | /// |
9271 | /// The source location associated with the declaration is the first place in |
9272 | /// the source code where the declaration was "used". It is not necessarily |
9273 | /// the point of instantiation (which will be either before or after the |
9274 | /// namespace-scope declaration that triggered this implicit instantiation), |
9275 | /// However, it is the location that diagnostics should generally refer to, |
9276 | /// because users will need to know what code triggered the instantiation. |
9277 | typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; |
9278 | |
9279 | /// The queue of implicit template instantiations that are required |
9280 | /// but have not yet been performed. |
9281 | std::deque<PendingImplicitInstantiation> PendingInstantiations; |
9282 | |
9283 | /// Queue of implicit template instantiations that cannot be performed |
9284 | /// eagerly. |
9285 | SmallVector<PendingImplicitInstantiation, 1> LateParsedInstantiations; |
9286 | |
9287 | class GlobalEagerInstantiationScope { |
9288 | public: |
9289 | GlobalEagerInstantiationScope(Sema &S, bool Enabled) |
9290 | : S(S), Enabled(Enabled) { |
9291 | if (!Enabled) return; |
9292 | |
9293 | SavedPendingInstantiations.swap(S.PendingInstantiations); |
9294 | SavedVTableUses.swap(S.VTableUses); |
9295 | } |
9296 | |
9297 | void perform() { |
9298 | if (Enabled) { |
9299 | S.DefineUsedVTables(); |
9300 | S.PerformPendingInstantiations(); |
9301 | } |
9302 | } |
9303 | |
9304 | ~GlobalEagerInstantiationScope() { |
9305 | if (!Enabled) return; |
9306 | |
9307 | // Restore the set of pending vtables. |
9308 | assert(S.VTableUses.empty() &&(static_cast <bool> (S.VTableUses.empty() && "VTableUses should be empty before it is discarded." ) ? void (0) : __assert_fail ("S.VTableUses.empty() && \"VTableUses should be empty before it is discarded.\"" , "clang/include/clang/Sema/Sema.h", 9309, __extension__ __PRETTY_FUNCTION__ )) |
9309 | "VTableUses should be empty before it is discarded.")(static_cast <bool> (S.VTableUses.empty() && "VTableUses should be empty before it is discarded." ) ? void (0) : __assert_fail ("S.VTableUses.empty() && \"VTableUses should be empty before it is discarded.\"" , "clang/include/clang/Sema/Sema.h", 9309, __extension__ __PRETTY_FUNCTION__ )); |
9310 | S.VTableUses.swap(SavedVTableUses); |
9311 | |
9312 | // Restore the set of pending implicit instantiations. |
9313 | if (S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) { |
9314 | assert(S.PendingInstantiations.empty() &&(static_cast <bool> (S.PendingInstantiations.empty() && "PendingInstantiations should be empty before it is discarded." ) ? void (0) : __assert_fail ("S.PendingInstantiations.empty() && \"PendingInstantiations should be empty before it is discarded.\"" , "clang/include/clang/Sema/Sema.h", 9315, __extension__ __PRETTY_FUNCTION__ )) |
9315 | "PendingInstantiations should be empty before it is discarded.")(static_cast <bool> (S.PendingInstantiations.empty() && "PendingInstantiations should be empty before it is discarded." ) ? void (0) : __assert_fail ("S.PendingInstantiations.empty() && \"PendingInstantiations should be empty before it is discarded.\"" , "clang/include/clang/Sema/Sema.h", 9315, __extension__ __PRETTY_FUNCTION__ )); |
9316 | S.PendingInstantiations.swap(SavedPendingInstantiations); |
9317 | } else { |
9318 | // Template instantiations in the PCH may be delayed until the TU. |
9319 | S.PendingInstantiations.swap(SavedPendingInstantiations); |
9320 | S.PendingInstantiations.insert(S.PendingInstantiations.end(), |
9321 | SavedPendingInstantiations.begin(), |
9322 | SavedPendingInstantiations.end()); |
9323 | } |
9324 | } |
9325 | |
9326 | private: |
9327 | Sema &S; |
9328 | SmallVector<VTableUse, 16> SavedVTableUses; |
9329 | std::deque<PendingImplicitInstantiation> SavedPendingInstantiations; |
9330 | bool Enabled; |
9331 | }; |
9332 | |
9333 | /// The queue of implicit template instantiations that are required |
9334 | /// and must be performed within the current local scope. |
9335 | /// |
9336 | /// This queue is only used for member functions of local classes in |
9337 | /// templates, which must be instantiated in the same scope as their |
9338 | /// enclosing function, so that they can reference function-local |
9339 | /// types, static variables, enumerators, etc. |
9340 | std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; |
9341 | |
9342 | class LocalEagerInstantiationScope { |
9343 | public: |
9344 | LocalEagerInstantiationScope(Sema &S) : S(S) { |
9345 | SavedPendingLocalImplicitInstantiations.swap( |
9346 | S.PendingLocalImplicitInstantiations); |
9347 | } |
9348 | |
9349 | void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/true); } |
9350 | |
9351 | ~LocalEagerInstantiationScope() { |
9352 | assert(S.PendingLocalImplicitInstantiations.empty() &&(static_cast <bool> (S.PendingLocalImplicitInstantiations .empty() && "there shouldn't be any pending local implicit instantiations" ) ? void (0) : __assert_fail ("S.PendingLocalImplicitInstantiations.empty() && \"there shouldn't be any pending local implicit instantiations\"" , "clang/include/clang/Sema/Sema.h", 9353, __extension__ __PRETTY_FUNCTION__ )) |
9353 | "there shouldn't be any pending local implicit instantiations")(static_cast <bool> (S.PendingLocalImplicitInstantiations .empty() && "there shouldn't be any pending local implicit instantiations" ) ? void (0) : __assert_fail ("S.PendingLocalImplicitInstantiations.empty() && \"there shouldn't be any pending local implicit instantiations\"" , "clang/include/clang/Sema/Sema.h", 9353, __extension__ __PRETTY_FUNCTION__ )); |
9354 | SavedPendingLocalImplicitInstantiations.swap( |
9355 | S.PendingLocalImplicitInstantiations); |
9356 | } |
9357 | |
9358 | private: |
9359 | Sema &S; |
9360 | std::deque<PendingImplicitInstantiation> |
9361 | SavedPendingLocalImplicitInstantiations; |
9362 | }; |
9363 | |
9364 | /// A helper class for building up ExtParameterInfos. |
9365 | class ExtParameterInfoBuilder { |
9366 | SmallVector<FunctionProtoType::ExtParameterInfo, 16> Infos; |
9367 | bool HasInteresting = false; |
9368 | |
9369 | public: |
9370 | /// Set the ExtParameterInfo for the parameter at the given index, |
9371 | /// |
9372 | void set(unsigned index, FunctionProtoType::ExtParameterInfo info) { |
9373 | assert(Infos.size() <= index)(static_cast <bool> (Infos.size() <= index) ? void ( 0) : __assert_fail ("Infos.size() <= index", "clang/include/clang/Sema/Sema.h" , 9373, __extension__ __PRETTY_FUNCTION__)); |
9374 | Infos.resize(index); |
9375 | Infos.push_back(info); |
9376 | |
9377 | if (!HasInteresting) |
9378 | HasInteresting = (info != FunctionProtoType::ExtParameterInfo()); |
9379 | } |
9380 | |
9381 | /// Return a pointer (suitable for setting in an ExtProtoInfo) to the |
9382 | /// ExtParameterInfo array we've built up. |
9383 | const FunctionProtoType::ExtParameterInfo * |
9384 | getPointerOrNull(unsigned numParams) { |
9385 | if (!HasInteresting) return nullptr; |
9386 | Infos.resize(numParams); |
9387 | return Infos.data(); |
9388 | } |
9389 | }; |
9390 | |
9391 | void PerformPendingInstantiations(bool LocalOnly = false); |
9392 | |
9393 | TypeSourceInfo *SubstType(TypeSourceInfo *T, |
9394 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9395 | SourceLocation Loc, DeclarationName Entity, |
9396 | bool AllowDeducedTST = false); |
9397 | |
9398 | QualType SubstType(QualType T, |
9399 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9400 | SourceLocation Loc, DeclarationName Entity); |
9401 | |
9402 | TypeSourceInfo *SubstType(TypeLoc TL, |
9403 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9404 | SourceLocation Loc, DeclarationName Entity); |
9405 | |
9406 | TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T, |
9407 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9408 | SourceLocation Loc, |
9409 | DeclarationName Entity, |
9410 | CXXRecordDecl *ThisContext, |
9411 | Qualifiers ThisTypeQuals); |
9412 | void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, |
9413 | const MultiLevelTemplateArgumentList &Args); |
9414 | bool SubstExceptionSpec(SourceLocation Loc, |
9415 | FunctionProtoType::ExceptionSpecInfo &ESI, |
9416 | SmallVectorImpl<QualType> &ExceptionStorage, |
9417 | const MultiLevelTemplateArgumentList &Args); |
9418 | ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D, |
9419 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9420 | int indexAdjustment, |
9421 | Optional<unsigned> NumExpansions, |
9422 | bool ExpectParameterPack); |
9423 | bool SubstParmTypes(SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
9424 | const FunctionProtoType::ExtParameterInfo *ExtParamInfos, |
9425 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9426 | SmallVectorImpl<QualType> &ParamTypes, |
9427 | SmallVectorImpl<ParmVarDecl *> *OutParams, |
9428 | ExtParameterInfoBuilder &ParamInfos); |
9429 | ExprResult SubstExpr(Expr *E, |
9430 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9431 | |
9432 | /// Substitute the given template arguments into a list of |
9433 | /// expressions, expanding pack expansions if required. |
9434 | /// |
9435 | /// \param Exprs The list of expressions to substitute into. |
9436 | /// |
9437 | /// \param IsCall Whether this is some form of call, in which case |
9438 | /// default arguments will be dropped. |
9439 | /// |
9440 | /// \param TemplateArgs The set of template arguments to substitute. |
9441 | /// |
9442 | /// \param Outputs Will receive all of the substituted arguments. |
9443 | /// |
9444 | /// \returns true if an error occurred, false otherwise. |
9445 | bool SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall, |
9446 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9447 | SmallVectorImpl<Expr *> &Outputs); |
9448 | |
9449 | StmtResult SubstStmt(Stmt *S, |
9450 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9451 | |
9452 | TemplateParameterList * |
9453 | SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner, |
9454 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9455 | |
9456 | bool |
9457 | SubstTemplateArguments(ArrayRef<TemplateArgumentLoc> Args, |
9458 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9459 | TemplateArgumentListInfo &Outputs); |
9460 | |
9461 | |
9462 | Decl *SubstDecl(Decl *D, DeclContext *Owner, |
9463 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9464 | |
9465 | /// Substitute the name and return type of a defaulted 'operator<=>' to form |
9466 | /// an implicit 'operator=='. |
9467 | FunctionDecl *SubstSpaceshipAsEqualEqual(CXXRecordDecl *RD, |
9468 | FunctionDecl *Spaceship); |
9469 | |
9470 | ExprResult SubstInitializer(Expr *E, |
9471 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9472 | bool CXXDirectInit); |
9473 | |
9474 | bool |
9475 | SubstBaseSpecifiers(CXXRecordDecl *Instantiation, |
9476 | CXXRecordDecl *Pattern, |
9477 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9478 | |
9479 | bool |
9480 | InstantiateClass(SourceLocation PointOfInstantiation, |
9481 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
9482 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9483 | TemplateSpecializationKind TSK, |
9484 | bool Complain = true); |
9485 | |
9486 | bool InstantiateEnum(SourceLocation PointOfInstantiation, |
9487 | EnumDecl *Instantiation, EnumDecl *Pattern, |
9488 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9489 | TemplateSpecializationKind TSK); |
9490 | |
9491 | bool InstantiateInClassInitializer( |
9492 | SourceLocation PointOfInstantiation, FieldDecl *Instantiation, |
9493 | FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs); |
9494 | |
9495 | struct LateInstantiatedAttribute { |
9496 | const Attr *TmplAttr; |
9497 | LocalInstantiationScope *Scope; |
9498 | Decl *NewDecl; |
9499 | |
9500 | LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S, |
9501 | Decl *D) |
9502 | : TmplAttr(A), Scope(S), NewDecl(D) |
9503 | { } |
9504 | }; |
9505 | typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec; |
9506 | |
9507 | void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, |
9508 | const Decl *Pattern, Decl *Inst, |
9509 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
9510 | LocalInstantiationScope *OuterMostScope = nullptr); |
9511 | |
9512 | void |
9513 | InstantiateAttrsForDecl(const MultiLevelTemplateArgumentList &TemplateArgs, |
9514 | const Decl *Pattern, Decl *Inst, |
9515 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
9516 | LocalInstantiationScope *OuterMostScope = nullptr); |
9517 | |
9518 | void InstantiateDefaultCtorDefaultArgs(CXXConstructorDecl *Ctor); |
9519 | |
9520 | bool usesPartialOrExplicitSpecialization( |
9521 | SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec); |
9522 | |
9523 | bool |
9524 | InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, |
9525 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
9526 | TemplateSpecializationKind TSK, |
9527 | bool Complain = true); |
9528 | |
9529 | void InstantiateClassMembers(SourceLocation PointOfInstantiation, |
9530 | CXXRecordDecl *Instantiation, |
9531 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9532 | TemplateSpecializationKind TSK); |
9533 | |
9534 | void InstantiateClassTemplateSpecializationMembers( |
9535 | SourceLocation PointOfInstantiation, |
9536 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
9537 | TemplateSpecializationKind TSK); |
9538 | |
9539 | NestedNameSpecifierLoc |
9540 | SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
9541 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9542 | |
9543 | DeclarationNameInfo |
9544 | SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
9545 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9546 | TemplateName |
9547 | SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, |
9548 | SourceLocation Loc, |
9549 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9550 | |
9551 | bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC, |
9552 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9553 | |
9554 | bool InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD, |
9555 | ParmVarDecl *Param); |
9556 | void InstantiateExceptionSpec(SourceLocation PointOfInstantiation, |
9557 | FunctionDecl *Function); |
9558 | bool CheckInstantiatedFunctionTemplateConstraints( |
9559 | SourceLocation PointOfInstantiation, FunctionDecl *Decl, |
9560 | ArrayRef<TemplateArgument> TemplateArgs, |
9561 | ConstraintSatisfaction &Satisfaction); |
9562 | FunctionDecl *InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD, |
9563 | const TemplateArgumentList *Args, |
9564 | SourceLocation Loc); |
9565 | void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, |
9566 | FunctionDecl *Function, |
9567 | bool Recursive = false, |
9568 | bool DefinitionRequired = false, |
9569 | bool AtEndOfTU = false); |
9570 | VarTemplateSpecializationDecl *BuildVarTemplateInstantiation( |
9571 | VarTemplateDecl *VarTemplate, VarDecl *FromVar, |
9572 | const TemplateArgumentList &TemplateArgList, |
9573 | const TemplateArgumentListInfo &TemplateArgsInfo, |
9574 | SmallVectorImpl<TemplateArgument> &Converted, |
9575 | SourceLocation PointOfInstantiation, |
9576 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
9577 | LocalInstantiationScope *StartingScope = nullptr); |
9578 | VarTemplateSpecializationDecl *CompleteVarTemplateSpecializationDecl( |
9579 | VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl, |
9580 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9581 | void |
9582 | BuildVariableInstantiation(VarDecl *NewVar, VarDecl *OldVar, |
9583 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9584 | LateInstantiatedAttrVec *LateAttrs, |
9585 | DeclContext *Owner, |
9586 | LocalInstantiationScope *StartingScope, |
9587 | bool InstantiatingVarTemplate = false, |
9588 | VarTemplateSpecializationDecl *PrevVTSD = nullptr); |
9589 | |
9590 | void InstantiateVariableInitializer( |
9591 | VarDecl *Var, VarDecl *OldVar, |
9592 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9593 | void InstantiateVariableDefinition(SourceLocation PointOfInstantiation, |
9594 | VarDecl *Var, bool Recursive = false, |
9595 | bool DefinitionRequired = false, |
9596 | bool AtEndOfTU = false); |
9597 | |
9598 | void InstantiateMemInitializers(CXXConstructorDecl *New, |
9599 | const CXXConstructorDecl *Tmpl, |
9600 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9601 | |
9602 | NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, |
9603 | const MultiLevelTemplateArgumentList &TemplateArgs, |
9604 | bool FindingInstantiatedContext = false); |
9605 | DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, |
9606 | const MultiLevelTemplateArgumentList &TemplateArgs); |
9607 | |
9608 | // Objective-C declarations. |
9609 | enum ObjCContainerKind { |
9610 | OCK_None = -1, |
9611 | OCK_Interface = 0, |
9612 | OCK_Protocol, |
9613 | OCK_Category, |
9614 | OCK_ClassExtension, |
9615 | OCK_Implementation, |
9616 | OCK_CategoryImplementation |
9617 | }; |
9618 | ObjCContainerKind getObjCContainerKind() const; |
9619 | |
9620 | DeclResult actOnObjCTypeParam(Scope *S, |
9621 | ObjCTypeParamVariance variance, |
9622 | SourceLocation varianceLoc, |
9623 | unsigned index, |
9624 | IdentifierInfo *paramName, |
9625 | SourceLocation paramLoc, |
9626 | SourceLocation colonLoc, |
9627 | ParsedType typeBound); |
9628 | |
9629 | ObjCTypeParamList *actOnObjCTypeParamList(Scope *S, SourceLocation lAngleLoc, |
9630 | ArrayRef<Decl *> typeParams, |
9631 | SourceLocation rAngleLoc); |
9632 | void popObjCTypeParamList(Scope *S, ObjCTypeParamList *typeParamList); |
9633 | |
9634 | Decl *ActOnStartClassInterface( |
9635 | Scope *S, SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, |
9636 | SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, |
9637 | IdentifierInfo *SuperName, SourceLocation SuperLoc, |
9638 | ArrayRef<ParsedType> SuperTypeArgs, SourceRange SuperTypeArgsRange, |
9639 | Decl *const *ProtoRefs, unsigned NumProtoRefs, |
9640 | const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, |
9641 | const ParsedAttributesView &AttrList); |
9642 | |
9643 | void ActOnSuperClassOfClassInterface(Scope *S, |
9644 | SourceLocation AtInterfaceLoc, |
9645 | ObjCInterfaceDecl *IDecl, |
9646 | IdentifierInfo *ClassName, |
9647 | SourceLocation ClassLoc, |
9648 | IdentifierInfo *SuperName, |
9649 | SourceLocation SuperLoc, |
9650 | ArrayRef<ParsedType> SuperTypeArgs, |
9651 | SourceRange SuperTypeArgsRange); |
9652 | |
9653 | void ActOnTypedefedProtocols(SmallVectorImpl<Decl *> &ProtocolRefs, |
9654 | SmallVectorImpl<SourceLocation> &ProtocolLocs, |
9655 | IdentifierInfo *SuperName, |
9656 | SourceLocation SuperLoc); |
9657 | |
9658 | Decl *ActOnCompatibilityAlias( |
9659 | SourceLocation AtCompatibilityAliasLoc, |
9660 | IdentifierInfo *AliasName, SourceLocation AliasLocation, |
9661 | IdentifierInfo *ClassName, SourceLocation ClassLocation); |
9662 | |
9663 | bool CheckForwardProtocolDeclarationForCircularDependency( |
9664 | IdentifierInfo *PName, |
9665 | SourceLocation &PLoc, SourceLocation PrevLoc, |
9666 | const ObjCList<ObjCProtocolDecl> &PList); |
9667 | |
9668 | Decl *ActOnStartProtocolInterface( |
9669 | SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName, |
9670 | SourceLocation ProtocolLoc, Decl *const *ProtoRefNames, |
9671 | unsigned NumProtoRefs, const SourceLocation *ProtoLocs, |
9672 | SourceLocation EndProtoLoc, const ParsedAttributesView &AttrList); |
9673 | |
9674 | Decl *ActOnStartCategoryInterface( |
9675 | SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, |
9676 | SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, |
9677 | IdentifierInfo *CategoryName, SourceLocation CategoryLoc, |
9678 | Decl *const *ProtoRefs, unsigned NumProtoRefs, |
9679 | const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, |
9680 | const ParsedAttributesView &AttrList); |
9681 | |
9682 | Decl *ActOnStartClassImplementation(SourceLocation AtClassImplLoc, |
9683 | IdentifierInfo *ClassName, |
9684 | SourceLocation ClassLoc, |
9685 | IdentifierInfo *SuperClassname, |
9686 | SourceLocation SuperClassLoc, |
9687 | const ParsedAttributesView &AttrList); |
9688 | |
9689 | Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc, |
9690 | IdentifierInfo *ClassName, |
9691 | SourceLocation ClassLoc, |
9692 | IdentifierInfo *CatName, |
9693 | SourceLocation CatLoc, |
9694 | const ParsedAttributesView &AttrList); |
9695 | |
9696 | DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, |
9697 | ArrayRef<Decl *> Decls); |
9698 | |
9699 | DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, |
9700 | IdentifierInfo **IdentList, |
9701 | SourceLocation *IdentLocs, |
9702 | ArrayRef<ObjCTypeParamList *> TypeParamLists, |
9703 | unsigned NumElts); |
9704 | |
9705 | DeclGroupPtrTy |
9706 | ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, |
9707 | ArrayRef<IdentifierLocPair> IdentList, |
9708 | const ParsedAttributesView &attrList); |
9709 | |
9710 | void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer, |
9711 | ArrayRef<IdentifierLocPair> ProtocolId, |
9712 | SmallVectorImpl<Decl *> &Protocols); |
9713 | |
9714 | void DiagnoseTypeArgsAndProtocols(IdentifierInfo *ProtocolId, |
9715 | SourceLocation ProtocolLoc, |
9716 | IdentifierInfo *TypeArgId, |
9717 | SourceLocation TypeArgLoc, |
9718 | bool SelectProtocolFirst = false); |
9719 | |
9720 | /// Given a list of identifiers (and their locations), resolve the |
9721 | /// names to either Objective-C protocol qualifiers or type |
9722 | /// arguments, as appropriate. |
9723 | void actOnObjCTypeArgsOrProtocolQualifiers( |
9724 | Scope *S, |
9725 | ParsedType baseType, |
9726 | SourceLocation lAngleLoc, |
9727 | ArrayRef<IdentifierInfo *> identifiers, |
9728 | ArrayRef<SourceLocation> identifierLocs, |
9729 | SourceLocation rAngleLoc, |
9730 | SourceLocation &typeArgsLAngleLoc, |
9731 | SmallVectorImpl<ParsedType> &typeArgs, |
9732 | SourceLocation &typeArgsRAngleLoc, |
9733 | SourceLocation &protocolLAngleLoc, |
9734 | SmallVectorImpl<Decl *> &protocols, |
9735 | SourceLocation &protocolRAngleLoc, |
9736 | bool warnOnIncompleteProtocols); |
9737 | |
9738 | /// Build a an Objective-C protocol-qualified 'id' type where no |
9739 | /// base type was specified. |
9740 | TypeResult actOnObjCProtocolQualifierType( |
9741 | SourceLocation lAngleLoc, |
9742 | ArrayRef<Decl *> protocols, |
9743 | ArrayRef<SourceLocation> protocolLocs, |
9744 | SourceLocation rAngleLoc); |
9745 | |
9746 | /// Build a specialized and/or protocol-qualified Objective-C type. |
9747 | TypeResult actOnObjCTypeArgsAndProtocolQualifiers( |
9748 | Scope *S, |
9749 | SourceLocation Loc, |
9750 | ParsedType BaseType, |
9751 | SourceLocation TypeArgsLAngleLoc, |
9752 | ArrayRef<ParsedType> TypeArgs, |
9753 | SourceLocation TypeArgsRAngleLoc, |
9754 | SourceLocation ProtocolLAngleLoc, |
9755 | ArrayRef<Decl *> Protocols, |
9756 | ArrayRef<SourceLocation> ProtocolLocs, |
9757 | SourceLocation ProtocolRAngleLoc); |
9758 | |
9759 | /// Build an Objective-C type parameter type. |
9760 | QualType BuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, |
9761 | SourceLocation ProtocolLAngleLoc, |
9762 | ArrayRef<ObjCProtocolDecl *> Protocols, |
9763 | ArrayRef<SourceLocation> ProtocolLocs, |
9764 | SourceLocation ProtocolRAngleLoc, |
9765 | bool FailOnError = false); |
9766 | |
9767 | /// Build an Objective-C object pointer type. |
9768 | QualType BuildObjCObjectType(QualType BaseType, |
9769 | SourceLocation Loc, |
9770 | SourceLocation TypeArgsLAngleLoc, |
9771 | ArrayRef<TypeSourceInfo *> TypeArgs, |
9772 | SourceLocation TypeArgsRAngleLoc, |
9773 | SourceLocation ProtocolLAngleLoc, |
9774 | ArrayRef<ObjCProtocolDecl *> Protocols, |
9775 | ArrayRef<SourceLocation> ProtocolLocs, |
9776 | SourceLocation ProtocolRAngleLoc, |
9777 | bool FailOnError = false); |
9778 | |
9779 | /// Ensure attributes are consistent with type. |
9780 | /// \param [in, out] Attributes The attributes to check; they will |
9781 | /// be modified to be consistent with \p PropertyTy. |
9782 | void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, |
9783 | SourceLocation Loc, |
9784 | unsigned &Attributes, |
9785 | bool propertyInPrimaryClass); |
9786 | |
9787 | /// Process the specified property declaration and create decls for the |
9788 | /// setters and getters as needed. |
9789 | /// \param property The property declaration being processed |
9790 | void ProcessPropertyDecl(ObjCPropertyDecl *property); |
9791 | |
9792 | |
9793 | void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, |
9794 | ObjCPropertyDecl *SuperProperty, |
9795 | const IdentifierInfo *Name, |
9796 | bool OverridingProtocolProperty); |
9797 | |
9798 | void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, |
9799 | ObjCInterfaceDecl *ID); |
9800 | |
9801 | Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd, |
9802 | ArrayRef<Decl *> allMethods = None, |
9803 | ArrayRef<DeclGroupPtrTy> allTUVars = None); |
9804 | |
9805 | Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, |
9806 | SourceLocation LParenLoc, |
9807 | FieldDeclarator &FD, ObjCDeclSpec &ODS, |
9808 | Selector GetterSel, Selector SetterSel, |
9809 | tok::ObjCKeywordKind MethodImplKind, |
9810 | DeclContext *lexicalDC = nullptr); |
9811 | |
9812 | Decl *ActOnPropertyImplDecl(Scope *S, |
9813 | SourceLocation AtLoc, |
9814 | SourceLocation PropertyLoc, |
9815 | bool ImplKind, |
9816 | IdentifierInfo *PropertyId, |
9817 | IdentifierInfo *PropertyIvar, |
9818 | SourceLocation PropertyIvarLoc, |
9819 | ObjCPropertyQueryKind QueryKind); |
9820 | |
9821 | enum ObjCSpecialMethodKind { |
9822 | OSMK_None, |
9823 | OSMK_Alloc, |
9824 | OSMK_New, |
9825 | OSMK_Copy, |
9826 | OSMK_RetainingInit, |
9827 | OSMK_NonRetainingInit |
9828 | }; |
9829 | |
9830 | struct ObjCArgInfo { |
9831 | IdentifierInfo *Name; |
9832 | SourceLocation NameLoc; |
9833 | // The Type is null if no type was specified, and the DeclSpec is invalid |
9834 | // in this case. |
9835 | ParsedType Type; |
9836 | ObjCDeclSpec DeclSpec; |
9837 | |
9838 | /// ArgAttrs - Attribute list for this argument. |
9839 | ParsedAttributesView ArgAttrs; |
9840 | }; |
9841 | |
9842 | Decl *ActOnMethodDeclaration( |
9843 | Scope *S, |
9844 | SourceLocation BeginLoc, // location of the + or -. |
9845 | SourceLocation EndLoc, // location of the ; or {. |
9846 | tok::TokenKind MethodType, ObjCDeclSpec &ReturnQT, ParsedType ReturnType, |
9847 | ArrayRef<SourceLocation> SelectorLocs, Selector Sel, |
9848 | // optional arguments. The number of types/arguments is obtained |
9849 | // from the Sel.getNumArgs(). |
9850 | ObjCArgInfo *ArgInfo, DeclaratorChunk::ParamInfo *CParamInfo, |
9851 | unsigned CNumArgs, // c-style args |
9852 | const ParsedAttributesView &AttrList, tok::ObjCKeywordKind MethodImplKind, |
9853 | bool isVariadic, bool MethodDefinition); |
9854 | |
9855 | ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, |
9856 | const ObjCObjectPointerType *OPT, |
9857 | bool IsInstance); |
9858 | ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty, |
9859 | bool IsInstance); |
9860 | |
9861 | bool CheckARCMethodDecl(ObjCMethodDecl *method); |
9862 | bool inferObjCARCLifetime(ValueDecl *decl); |
9863 | |
9864 | void deduceOpenCLAddressSpace(ValueDecl *decl); |
9865 | |
9866 | ExprResult |
9867 | HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, |
9868 | Expr *BaseExpr, |
9869 | SourceLocation OpLoc, |
9870 | DeclarationName MemberName, |
9871 | SourceLocation MemberLoc, |
9872 | SourceLocation SuperLoc, QualType SuperType, |
9873 | bool Super); |
9874 | |
9875 | ExprResult |
9876 | ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, |
9877 | IdentifierInfo &propertyName, |
9878 | SourceLocation receiverNameLoc, |
9879 | SourceLocation propertyNameLoc); |
9880 | |
9881 | ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc); |
9882 | |
9883 | /// Describes the kind of message expression indicated by a message |
9884 | /// send that starts with an identifier. |
9885 | enum ObjCMessageKind { |
9886 | /// The message is sent to 'super'. |
9887 | ObjCSuperMessage, |
9888 | /// The message is an instance message. |
9889 | ObjCInstanceMessage, |
9890 | /// The message is a class message, and the identifier is a type |
9891 | /// name. |
9892 | ObjCClassMessage |
9893 | }; |
9894 | |
9895 | ObjCMessageKind getObjCMessageKind(Scope *S, |
9896 | IdentifierInfo *Name, |
9897 | SourceLocation NameLoc, |
9898 | bool IsSuper, |
9899 | bool HasTrailingDot, |
9900 | ParsedType &ReceiverType); |
9901 | |
9902 | ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, |
9903 | Selector Sel, |
9904 | SourceLocation LBracLoc, |
9905 | ArrayRef<SourceLocation> SelectorLocs, |
9906 | SourceLocation RBracLoc, |
9907 | MultiExprArg Args); |
9908 | |
9909 | ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, |
9910 | QualType ReceiverType, |
9911 | SourceLocation SuperLoc, |
9912 | Selector Sel, |
9913 | ObjCMethodDecl *Method, |
9914 | SourceLocation LBracLoc, |
9915 | ArrayRef<SourceLocation> SelectorLocs, |
9916 | SourceLocation RBracLoc, |
9917 | MultiExprArg Args, |
9918 | bool isImplicit = false); |
9919 | |
9920 | ExprResult BuildClassMessageImplicit(QualType ReceiverType, |
9921 | bool isSuperReceiver, |
9922 | SourceLocation Loc, |
9923 | Selector Sel, |
9924 | ObjCMethodDecl *Method, |
9925 | MultiExprArg Args); |
9926 | |
9927 | ExprResult ActOnClassMessage(Scope *S, |
9928 | ParsedType Receiver, |
9929 | Selector Sel, |
9930 | SourceLocation LBracLoc, |
9931 | ArrayRef<SourceLocation> SelectorLocs, |
9932 | SourceLocation RBracLoc, |
9933 | MultiExprArg Args); |
9934 | |
9935 | ExprResult BuildInstanceMessage(Expr *Receiver, |
9936 | QualType ReceiverType, |
9937 | SourceLocation SuperLoc, |
9938 | Selector Sel, |
9939 | ObjCMethodDecl *Method, |
9940 | SourceLocation LBracLoc, |
9941 | ArrayRef<SourceLocation> SelectorLocs, |
9942 | SourceLocation RBracLoc, |
9943 | MultiExprArg Args, |
9944 | bool isImplicit = false); |
9945 | |
9946 | ExprResult BuildInstanceMessageImplicit(Expr *Receiver, |
9947 | QualType ReceiverType, |
9948 | SourceLocation Loc, |
9949 | Selector Sel, |
9950 | ObjCMethodDecl *Method, |
9951 | MultiExprArg Args); |
9952 | |
9953 | ExprResult ActOnInstanceMessage(Scope *S, |
9954 | Expr *Receiver, |
9955 | Selector Sel, |
9956 | SourceLocation LBracLoc, |
9957 | ArrayRef<SourceLocation> SelectorLocs, |
9958 | SourceLocation RBracLoc, |
9959 | MultiExprArg Args); |
9960 | |
9961 | ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, |
9962 | ObjCBridgeCastKind Kind, |
9963 | SourceLocation BridgeKeywordLoc, |
9964 | TypeSourceInfo *TSInfo, |
9965 | Expr *SubExpr); |
9966 | |
9967 | ExprResult ActOnObjCBridgedCast(Scope *S, |
9968 | SourceLocation LParenLoc, |
9969 | ObjCBridgeCastKind Kind, |
9970 | SourceLocation BridgeKeywordLoc, |
9971 | ParsedType Type, |
9972 | SourceLocation RParenLoc, |
9973 | Expr *SubExpr); |
9974 | |
9975 | void CheckTollFreeBridgeCast(QualType castType, Expr *castExpr); |
9976 | |
9977 | void CheckObjCBridgeRelatedCast(QualType castType, Expr *castExpr); |
9978 | |
9979 | bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr, |
9980 | CastKind &Kind); |
9981 | |
9982 | bool checkObjCBridgeRelatedComponents(SourceLocation Loc, |
9983 | QualType DestType, QualType SrcType, |
9984 | ObjCInterfaceDecl *&RelatedClass, |
9985 | ObjCMethodDecl *&ClassMethod, |
9986 | ObjCMethodDecl *&InstanceMethod, |
9987 | TypedefNameDecl *&TDNDecl, |
9988 | bool CfToNs, bool Diagnose = true); |
9989 | |
9990 | bool CheckObjCBridgeRelatedConversions(SourceLocation Loc, |
9991 | QualType DestType, QualType SrcType, |
9992 | Expr *&SrcExpr, bool Diagnose = true); |
9993 | |
9994 | bool CheckConversionToObjCLiteral(QualType DstType, Expr *&SrcExpr, |
9995 | bool Diagnose = true); |
9996 | |
9997 | bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); |
9998 | |
9999 | /// Check whether the given new method is a valid override of the |
10000 | /// given overridden method, and set any properties that should be inherited. |
10001 | void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, |
10002 | const ObjCMethodDecl *Overridden); |
10003 | |
10004 | /// Describes the compatibility of a result type with its method. |
10005 | enum ResultTypeCompatibilityKind { |
10006 | RTC_Compatible, |
10007 | RTC_Incompatible, |
10008 | RTC_Unknown |
10009 | }; |
10010 | |
10011 | void CheckObjCMethodDirectOverrides(ObjCMethodDecl *method, |
10012 | ObjCMethodDecl *overridden); |
10013 | |
10014 | void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod, |
10015 | ObjCInterfaceDecl *CurrentClass, |
10016 | ResultTypeCompatibilityKind RTC); |
10017 | |
10018 | enum PragmaOptionsAlignKind { |
10019 | POAK_Native, // #pragma options align=native |
10020 | POAK_Natural, // #pragma options align=natural |
10021 | POAK_Packed, // #pragma options align=packed |
10022 | POAK_Power, // #pragma options align=power |
10023 | POAK_Mac68k, // #pragma options align=mac68k |
10024 | POAK_Reset // #pragma options align=reset |
10025 | }; |
10026 | |
10027 | /// ActOnPragmaClangSection - Called on well formed \#pragma clang section |
10028 | void ActOnPragmaClangSection(SourceLocation PragmaLoc, |
10029 | PragmaClangSectionAction Action, |
10030 | PragmaClangSectionKind SecKind, StringRef SecName); |
10031 | |
10032 | /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align. |
10033 | void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, |
10034 | SourceLocation PragmaLoc); |
10035 | |
10036 | /// ActOnPragmaPack - Called on well formed \#pragma pack(...). |
10037 | void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, |
10038 | StringRef SlotLabel, Expr *Alignment); |
10039 | |
10040 | enum class PragmaAlignPackDiagnoseKind { |
10041 | NonDefaultStateAtInclude, |
10042 | ChangedStateAtExit |
10043 | }; |
10044 | |
10045 | void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind, |
10046 | SourceLocation IncludeLoc); |
10047 | void DiagnoseUnterminatedPragmaAlignPack(); |
10048 | |
10049 | /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off]. |
10050 | void ActOnPragmaMSStruct(PragmaMSStructKind Kind); |
10051 | |
10052 | /// ActOnPragmaMSComment - Called on well formed |
10053 | /// \#pragma comment(kind, "arg"). |
10054 | void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind, |
10055 | StringRef Arg); |
10056 | |
10057 | /// ActOnPragmaMSPointersToMembers - called on well formed \#pragma |
10058 | /// pointers_to_members(representation method[, general purpose |
10059 | /// representation]). |
10060 | void ActOnPragmaMSPointersToMembers( |
10061 | LangOptions::PragmaMSPointersToMembersKind Kind, |
10062 | SourceLocation PragmaLoc); |
10063 | |
10064 | /// Called on well formed \#pragma vtordisp(). |
10065 | void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, |
10066 | SourceLocation PragmaLoc, |
10067 | MSVtorDispMode Value); |
10068 | |
10069 | enum PragmaSectionKind { |
10070 | PSK_DataSeg, |
10071 | PSK_BSSSeg, |
10072 | PSK_ConstSeg, |
10073 | PSK_CodeSeg, |
10074 | }; |
10075 | |
10076 | bool UnifySection(StringRef SectionName, int SectionFlags, |
10077 | NamedDecl *TheDecl); |
10078 | bool UnifySection(StringRef SectionName, |
10079 | int SectionFlags, |
10080 | SourceLocation PragmaSectionLocation); |
10081 | |
10082 | /// Called on well formed \#pragma bss_seg/data_seg/const_seg/code_seg. |
10083 | void ActOnPragmaMSSeg(SourceLocation PragmaLocation, |
10084 | PragmaMsStackAction Action, |
10085 | llvm::StringRef StackSlotLabel, |
10086 | StringLiteral *SegmentName, |
10087 | llvm::StringRef PragmaName); |
10088 | |
10089 | /// Called on well formed \#pragma section(). |
10090 | void ActOnPragmaMSSection(SourceLocation PragmaLocation, |
10091 | int SectionFlags, StringLiteral *SegmentName); |
10092 | |
10093 | /// Called on well-formed \#pragma init_seg(). |
10094 | void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, |
10095 | StringLiteral *SegmentName); |
10096 | |
10097 | /// Called on #pragma clang __debug dump II |
10098 | void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II); |
10099 | |
10100 | /// ActOnPragmaDetectMismatch - Call on well-formed \#pragma detect_mismatch |
10101 | void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, |
10102 | StringRef Value); |
10103 | |
10104 | /// Are precise floating point semantics currently enabled? |
10105 | bool isPreciseFPEnabled() { |
10106 | return !CurFPFeatures.getAllowFPReassociate() && |
10107 | !CurFPFeatures.getNoSignedZero() && |
10108 | !CurFPFeatures.getAllowReciprocal() && |
10109 | !CurFPFeatures.getAllowApproxFunc(); |
10110 | } |
10111 | |
10112 | /// ActOnPragmaFloatControl - Call on well-formed \#pragma float_control |
10113 | void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, |
10114 | PragmaFloatControlKind Value); |
10115 | |
10116 | /// ActOnPragmaUnused - Called on well-formed '\#pragma unused'. |
10117 | void ActOnPragmaUnused(const Token &Identifier, |
10118 | Scope *curScope, |
10119 | SourceLocation PragmaLoc); |
10120 | |
10121 | /// ActOnPragmaVisibility - Called on well formed \#pragma GCC visibility... . |
10122 | void ActOnPragmaVisibility(const IdentifierInfo* VisType, |
10123 | SourceLocation PragmaLoc); |
10124 | |
10125 | NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II, |
10126 | SourceLocation Loc); |
10127 | void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W); |
10128 | |
10129 | /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident. |
10130 | void ActOnPragmaWeakID(IdentifierInfo* WeakName, |
10131 | SourceLocation PragmaLoc, |
10132 | SourceLocation WeakNameLoc); |
10133 | |
10134 | /// ActOnPragmaRedefineExtname - Called on well formed |
10135 | /// \#pragma redefine_extname oldname newname. |
10136 | void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName, |
10137 | IdentifierInfo* AliasName, |
10138 | SourceLocation PragmaLoc, |
10139 | SourceLocation WeakNameLoc, |
10140 | SourceLocation AliasNameLoc); |
10141 | |
10142 | /// ActOnPragmaWeakAlias - Called on well formed \#pragma weak ident = ident. |
10143 | void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, |
10144 | IdentifierInfo* AliasName, |
10145 | SourceLocation PragmaLoc, |
10146 | SourceLocation WeakNameLoc, |
10147 | SourceLocation AliasNameLoc); |
10148 | |
10149 | /// ActOnPragmaFPContract - Called on well formed |
10150 | /// \#pragma {STDC,OPENCL} FP_CONTRACT and |
10151 | /// \#pragma clang fp contract |
10152 | void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC); |
10153 | |
10154 | /// Called on well formed |
10155 | /// \#pragma clang fp reassociate |
10156 | void ActOnPragmaFPReassociate(SourceLocation Loc, bool IsEnabled); |
10157 | |
10158 | /// ActOnPragmaFenvAccess - Called on well formed |
10159 | /// \#pragma STDC FENV_ACCESS |
10160 | void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled); |
10161 | |
10162 | /// Called on well formed '\#pragma clang fp' that has option 'exceptions'. |
10163 | void ActOnPragmaFPExceptions(SourceLocation Loc, |
10164 | LangOptions::FPExceptionModeKind); |
10165 | |
10166 | /// Called to set constant rounding mode for floating point operations. |
10167 | void setRoundingMode(SourceLocation Loc, llvm::RoundingMode); |
10168 | |
10169 | /// Called to set exception behavior for floating point operations. |
10170 | void setExceptionMode(SourceLocation Loc, LangOptions::FPExceptionModeKind); |
10171 | |
10172 | /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to |
10173 | /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'. |
10174 | void AddAlignmentAttributesForRecord(RecordDecl *RD); |
10175 | |
10176 | /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. |
10177 | void AddMsStructLayoutForRecord(RecordDecl *RD); |
10178 | |
10179 | /// PushNamespaceVisibilityAttr - Note that we've entered a |
10180 | /// namespace with a visibility attribute. |
10181 | void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, |
10182 | SourceLocation Loc); |
10183 | |
10184 | /// AddPushedVisibilityAttribute - If '\#pragma GCC visibility' was used, |
10185 | /// add an appropriate visibility attribute. |
10186 | void AddPushedVisibilityAttribute(Decl *RD); |
10187 | |
10188 | /// PopPragmaVisibility - Pop the top element of the visibility stack; used |
10189 | /// for '\#pragma GCC visibility' and visibility attributes on namespaces. |
10190 | void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc); |
10191 | |
10192 | /// FreeVisContext - Deallocate and null out VisContext. |
10193 | void FreeVisContext(); |
10194 | |
10195 | /// AddCFAuditedAttribute - Check whether we're currently within |
10196 | /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding |
10197 | /// the appropriate attribute. |
10198 | void AddCFAuditedAttribute(Decl *D); |
10199 | |
10200 | void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, |
10201 | SourceLocation PragmaLoc, |
10202 | attr::ParsedSubjectMatchRuleSet Rules); |
10203 | void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, |
10204 | const IdentifierInfo *Namespace); |
10205 | |
10206 | /// Called on well-formed '\#pragma clang attribute pop'. |
10207 | void ActOnPragmaAttributePop(SourceLocation PragmaLoc, |
10208 | const IdentifierInfo *Namespace); |
10209 | |
10210 | /// Adds the attributes that have been specified using the |
10211 | /// '\#pragma clang attribute push' directives to the given declaration. |
10212 | void AddPragmaAttributes(Scope *S, Decl *D); |
10213 | |
10214 | void DiagnoseUnterminatedPragmaAttribute(); |
10215 | |
10216 | /// Called on well formed \#pragma clang optimize. |
10217 | void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc); |
10218 | |
10219 | /// Get the location for the currently active "\#pragma clang optimize |
10220 | /// off". If this location is invalid, then the state of the pragma is "on". |
10221 | SourceLocation getOptimizeOffPragmaLocation() const { |
10222 | return OptimizeOffPragmaLocation; |
10223 | } |
10224 | |
10225 | /// Only called on function definitions; if there is a pragma in scope |
10226 | /// with the effect of a range-based optnone, consider marking the function |
10227 | /// with attribute optnone. |
10228 | void AddRangeBasedOptnone(FunctionDecl *FD); |
10229 | |
10230 | /// Adds the 'optnone' attribute to the function declaration if there |
10231 | /// are no conflicts; Loc represents the location causing the 'optnone' |
10232 | /// attribute to be added (usually because of a pragma). |
10233 | void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc); |
10234 | |
10235 | /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. |
10236 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
10237 | bool IsPackExpansion); |
10238 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, TypeSourceInfo *T, |
10239 | bool IsPackExpansion); |
10240 | |
10241 | /// AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular |
10242 | /// declaration. |
10243 | void AddAssumeAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
10244 | Expr *OE); |
10245 | |
10246 | /// AddAllocAlignAttr - Adds an alloc_align attribute to a particular |
10247 | /// declaration. |
10248 | void AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI, |
10249 | Expr *ParamExpr); |
10250 | |
10251 | /// AddAlignValueAttr - Adds an align_value attribute to a particular |
10252 | /// declaration. |
10253 | void AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E); |
10254 | |
10255 | /// AddAnnotationAttr - Adds an annotation Annot with Args arguments to D. |
10256 | void AddAnnotationAttr(Decl *D, const AttributeCommonInfo &CI, |
10257 | StringRef Annot, MutableArrayRef<Expr *> Args); |
10258 | |
10259 | /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular |
10260 | /// declaration. |
10261 | void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI, |
10262 | Expr *MaxThreads, Expr *MinBlocks); |
10263 | |
10264 | /// AddModeAttr - Adds a mode attribute to a particular declaration. |
10265 | void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Name, |
10266 | bool InInstantiation = false); |
10267 | |
10268 | void AddParameterABIAttr(Decl *D, const AttributeCommonInfo &CI, |
10269 | ParameterABI ABI); |
10270 | |
10271 | enum class RetainOwnershipKind {NS, CF, OS}; |
10272 | void AddXConsumedAttr(Decl *D, const AttributeCommonInfo &CI, |
10273 | RetainOwnershipKind K, bool IsTemplateInstantiation); |
10274 | |
10275 | /// addAMDGPUFlatWorkGroupSizeAttr - Adds an amdgpu_flat_work_group_size |
10276 | /// attribute to a particular declaration. |
10277 | void addAMDGPUFlatWorkGroupSizeAttr(Decl *D, const AttributeCommonInfo &CI, |
10278 | Expr *Min, Expr *Max); |
10279 | |
10280 | /// addAMDGPUWavePersEUAttr - Adds an amdgpu_waves_per_eu attribute to a |
10281 | /// particular declaration. |
10282 | void addAMDGPUWavesPerEUAttr(Decl *D, const AttributeCommonInfo &CI, |
10283 | Expr *Min, Expr *Max); |
10284 | |
10285 | bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type); |
10286 | |
10287 | //===--------------------------------------------------------------------===// |
10288 | // C++ Coroutines TS |
10289 | // |
10290 | bool ActOnCoroutineBodyStart(Scope *S, SourceLocation KwLoc, |
10291 | StringRef Keyword); |
10292 | ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
10293 | ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
10294 | StmtResult ActOnCoreturnStmt(Scope *S, SourceLocation KwLoc, Expr *E); |
10295 | |
10296 | ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *E, |
10297 | bool IsImplicit = false); |
10298 | ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *E, |
10299 | UnresolvedLookupExpr* Lookup); |
10300 | ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E); |
10301 | StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E, |
10302 | bool IsImplicit = false); |
10303 | StmtResult BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs); |
10304 | bool buildCoroutineParameterMoves(SourceLocation Loc); |
10305 | VarDecl *buildCoroutinePromise(SourceLocation Loc); |
10306 | void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body); |
10307 | /// Lookup 'coroutine_traits' in std namespace and std::experimental |
10308 | /// namespace. The namespace found is recorded in Namespace. |
10309 | ClassTemplateDecl *lookupCoroutineTraits(SourceLocation KwLoc, |
10310 | SourceLocation FuncLoc, |
10311 | NamespaceDecl *&Namespace); |
10312 | /// Check that the expression co_await promise.final_suspend() shall not be |
10313 | /// potentially-throwing. |
10314 | bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend); |
10315 | |
10316 | //===--------------------------------------------------------------------===// |
10317 | // OpenMP directives and clauses. |
10318 | // |
10319 | private: |
10320 | void *VarDataSharingAttributesStack; |
10321 | |
10322 | struct DeclareTargetContextInfo { |
10323 | struct MapInfo { |
10324 | OMPDeclareTargetDeclAttr::MapTypeTy MT; |
10325 | SourceLocation Loc; |
10326 | }; |
10327 | /// Explicitly listed variables and functions in a 'to' or 'link' clause. |
10328 | llvm::DenseMap<NamedDecl *, MapInfo> ExplicitlyMapped; |
10329 | |
10330 | /// The 'device_type' as parsed from the clause. |
10331 | OMPDeclareTargetDeclAttr::DevTypeTy DT = OMPDeclareTargetDeclAttr::DT_Any; |
10332 | |
10333 | /// The directive kind, `begin declare target` or `declare target`. |
10334 | OpenMPDirectiveKind Kind; |
10335 | |
10336 | /// The directive with indirect clause. |
10337 | Optional<Expr *> Indirect; |
10338 | |
10339 | /// The directive location. |
10340 | SourceLocation Loc; |
10341 | |
10342 | DeclareTargetContextInfo(OpenMPDirectiveKind Kind, SourceLocation Loc) |
10343 | : Kind(Kind), Loc(Loc) {} |
10344 | }; |
10345 | |
10346 | /// Number of nested '#pragma omp declare target' directives. |
10347 | SmallVector<DeclareTargetContextInfo, 4> DeclareTargetNesting; |
10348 | |
10349 | /// Initialization of data-sharing attributes stack. |
10350 | void InitDataSharingAttributesStack(); |
10351 | void DestroyDataSharingAttributesStack(); |
10352 | ExprResult |
10353 | VerifyPositiveIntegerConstantInClause(Expr *Op, OpenMPClauseKind CKind, |
10354 | bool StrictlyPositive = true, |
10355 | bool SuppressExprDiags = false); |
10356 | /// Returns OpenMP nesting level for current directive. |
10357 | unsigned getOpenMPNestingLevel() const; |
10358 | |
10359 | /// Adjusts the function scopes index for the target-based regions. |
10360 | void adjustOpenMPTargetScopeIndex(unsigned &FunctionScopesIndex, |
10361 | unsigned Level) const; |
10362 | |
10363 | /// Returns the number of scopes associated with the construct on the given |
10364 | /// OpenMP level. |
10365 | int getNumberOfConstructScopes(unsigned Level) const; |
10366 | |
10367 | /// Push new OpenMP function region for non-capturing function. |
10368 | void pushOpenMPFunctionRegion(); |
10369 | |
10370 | /// Pop OpenMP function region for non-capturing function. |
10371 | void popOpenMPFunctionRegion(const sema::FunctionScopeInfo *OldFSI); |
10372 | |
10373 | /// Analyzes and checks a loop nest for use by a loop transformation. |
10374 | /// |
10375 | /// \param Kind The loop transformation directive kind. |
10376 | /// \param NumLoops How many nested loops the directive is expecting. |
10377 | /// \param AStmt Associated statement of the transformation directive. |
10378 | /// \param LoopHelpers [out] The loop analysis result. |
10379 | /// \param Body [out] The body code nested in \p NumLoops loop. |
10380 | /// \param OriginalInits [out] Collection of statements and declarations that |
10381 | /// must have been executed/declared before entering the |
10382 | /// loop. |
10383 | /// |
10384 | /// \return Whether there was any error. |
10385 | bool checkTransformableLoopNest( |
10386 | OpenMPDirectiveKind Kind, Stmt *AStmt, int NumLoops, |
10387 | SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers, |
10388 | Stmt *&Body, |
10389 | SmallVectorImpl<SmallVector<llvm::PointerUnion<Stmt *, Decl *>, 0>> |
10390 | &OriginalInits); |
10391 | |
10392 | /// Helper to keep information about the current `omp begin/end declare |
10393 | /// variant` nesting. |
10394 | struct OMPDeclareVariantScope { |
10395 | /// The associated OpenMP context selector. |
10396 | OMPTraitInfo *TI; |
10397 | |
10398 | /// The associated OpenMP context selector mangling. |
10399 | std::string NameSuffix; |
10400 | |
10401 | OMPDeclareVariantScope(OMPTraitInfo &TI); |
10402 | }; |
10403 | |
10404 | /// Return the OMPTraitInfo for the surrounding scope, if any. |
10405 | OMPTraitInfo *getOMPTraitInfoForSurroundingScope() { |
10406 | return OMPDeclareVariantScopes.empty() ? nullptr |
10407 | : OMPDeclareVariantScopes.back().TI; |
10408 | } |
10409 | |
10410 | /// The current `omp begin/end declare variant` scopes. |
10411 | SmallVector<OMPDeclareVariantScope, 4> OMPDeclareVariantScopes; |
10412 | |
10413 | /// The current `omp begin/end assumes` scopes. |
10414 | SmallVector<AssumptionAttr *, 4> OMPAssumeScoped; |
10415 | |
10416 | /// All `omp assumes` we encountered so far. |
10417 | SmallVector<AssumptionAttr *, 4> OMPAssumeGlobal; |
10418 | |
10419 | public: |
10420 | /// The declarator \p D defines a function in the scope \p S which is nested |
10421 | /// in an `omp begin/end declare variant` scope. In this method we create a |
10422 | /// declaration for \p D and rename \p D according to the OpenMP context |
10423 | /// selector of the surrounding scope. Return all base functions in \p Bases. |
10424 | void ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope( |
10425 | Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists, |
10426 | SmallVectorImpl<FunctionDecl *> &Bases); |
10427 | |
10428 | /// Register \p D as specialization of all base functions in \p Bases in the |
10429 | /// current `omp begin/end declare variant` scope. |
10430 | void ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope( |
10431 | Decl *D, SmallVectorImpl<FunctionDecl *> &Bases); |
10432 | |
10433 | /// Act on \p D, a function definition inside of an `omp [begin/end] assumes`. |
10434 | void ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Decl *D); |
10435 | |
10436 | /// Can we exit an OpenMP declare variant scope at the moment. |
10437 | bool isInOpenMPDeclareVariantScope() const { |
10438 | return !OMPDeclareVariantScopes.empty(); |
10439 | } |
10440 | |
10441 | /// Given the potential call expression \p Call, determine if there is a |
10442 | /// specialization via the OpenMP declare variant mechanism available. If |
10443 | /// there is, return the specialized call expression, otherwise return the |
10444 | /// original \p Call. |
10445 | ExprResult ActOnOpenMPCall(ExprResult Call, Scope *Scope, |
10446 | SourceLocation LParenLoc, MultiExprArg ArgExprs, |
10447 | SourceLocation RParenLoc, Expr *ExecConfig); |
10448 | |
10449 | /// Handle a `omp begin declare variant`. |
10450 | void ActOnOpenMPBeginDeclareVariant(SourceLocation Loc, OMPTraitInfo &TI); |
10451 | |
10452 | /// Handle a `omp end declare variant`. |
10453 | void ActOnOpenMPEndDeclareVariant(); |
10454 | |
10455 | /// Checks if the variant/multiversion functions are compatible. |
10456 | bool areMultiversionVariantFunctionsCompatible( |
10457 | const FunctionDecl *OldFD, const FunctionDecl *NewFD, |
10458 | const PartialDiagnostic &NoProtoDiagID, |
10459 | const PartialDiagnosticAt &NoteCausedDiagIDAt, |
10460 | const PartialDiagnosticAt &NoSupportDiagIDAt, |
10461 | const PartialDiagnosticAt &DiffDiagIDAt, bool TemplatesSupported, |
10462 | bool ConstexprSupported, bool CLinkageMayDiffer); |
10463 | |
10464 | /// Function tries to capture lambda's captured variables in the OpenMP region |
10465 | /// before the original lambda is captured. |
10466 | void tryCaptureOpenMPLambdas(ValueDecl *V); |
10467 | |
10468 | /// Return true if the provided declaration \a VD should be captured by |
10469 | /// reference. |
10470 | /// \param Level Relative level of nested OpenMP construct for that the check |
10471 | /// is performed. |
10472 | /// \param OpenMPCaptureLevel Capture level within an OpenMP construct. |
10473 | bool isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level, |
10474 | unsigned OpenMPCaptureLevel) const; |
10475 | |
10476 | /// Check if the specified variable is used in one of the private |
10477 | /// clauses (private, firstprivate, lastprivate, reduction etc.) in OpenMP |
10478 | /// constructs. |
10479 | VarDecl *isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo = false, |
10480 | unsigned StopAt = 0); |
10481 | ExprResult getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
10482 | ExprObjectKind OK, SourceLocation Loc); |
10483 | |
10484 | /// If the current region is a loop-based region, mark the start of the loop |
10485 | /// construct. |
10486 | void startOpenMPLoop(); |
10487 | |
10488 | /// If the current region is a range loop-based region, mark the start of the |
10489 | /// loop construct. |
10490 | void startOpenMPCXXRangeFor(); |
10491 | |
10492 | /// Check if the specified variable is used in 'private' clause. |
10493 | /// \param Level Relative level of nested OpenMP construct for that the check |
10494 | /// is performed. |
10495 | OpenMPClauseKind isOpenMPPrivateDecl(ValueDecl *D, unsigned Level, |
10496 | unsigned CapLevel) const; |
10497 | |
10498 | /// Sets OpenMP capture kind (OMPC_private, OMPC_firstprivate, OMPC_map etc.) |
10499 | /// for \p FD based on DSA for the provided corresponding captured declaration |
10500 | /// \p D. |
10501 | void setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, unsigned Level); |
10502 | |
10503 | /// Check if the specified variable is captured by 'target' directive. |
10504 | /// \param Level Relative level of nested OpenMP construct for that the check |
10505 | /// is performed. |
10506 | bool isOpenMPTargetCapturedDecl(const ValueDecl *D, unsigned Level, |
10507 | unsigned CaptureLevel) const; |
10508 | |
10509 | /// Check if the specified global variable must be captured by outer capture |
10510 | /// regions. |
10511 | /// \param Level Relative level of nested OpenMP construct for that |
10512 | /// the check is performed. |
10513 | bool isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level, |
10514 | unsigned CaptureLevel) const; |
10515 | |
10516 | ExprResult PerformOpenMPImplicitIntegerConversion(SourceLocation OpLoc, |
10517 | Expr *Op); |
10518 | /// Called on start of new data sharing attribute block. |
10519 | void StartOpenMPDSABlock(OpenMPDirectiveKind K, |
10520 | const DeclarationNameInfo &DirName, Scope *CurScope, |
10521 | SourceLocation Loc); |
10522 | /// Start analysis of clauses. |
10523 | void StartOpenMPClause(OpenMPClauseKind K); |
10524 | /// End analysis of clauses. |
10525 | void EndOpenMPClause(); |
10526 | /// Called on end of data sharing attribute block. |
10527 | void EndOpenMPDSABlock(Stmt *CurDirective); |
10528 | |
10529 | /// Check if the current region is an OpenMP loop region and if it is, |
10530 | /// mark loop control variable, used in \p Init for loop initialization, as |
10531 | /// private by default. |
10532 | /// \param Init First part of the for loop. |
10533 | void ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init); |
10534 | |
10535 | /// Called on well-formed '\#pragma omp metadirective' after parsing |
10536 | /// of the associated statement. |
10537 | StmtResult ActOnOpenMPMetaDirective(ArrayRef<OMPClause *> Clauses, |
10538 | Stmt *AStmt, SourceLocation StartLoc, |
10539 | SourceLocation EndLoc); |
10540 | |
10541 | // OpenMP directives and clauses. |
10542 | /// Called on correct id-expression from the '#pragma omp |
10543 | /// threadprivate'. |
10544 | ExprResult ActOnOpenMPIdExpression(Scope *CurScope, CXXScopeSpec &ScopeSpec, |
10545 | const DeclarationNameInfo &Id, |
10546 | OpenMPDirectiveKind Kind); |
10547 | /// Called on well-formed '#pragma omp threadprivate'. |
10548 | DeclGroupPtrTy ActOnOpenMPThreadprivateDirective( |
10549 | SourceLocation Loc, |
10550 | ArrayRef<Expr *> VarList); |
10551 | /// Builds a new OpenMPThreadPrivateDecl and checks its correctness. |
10552 | OMPThreadPrivateDecl *CheckOMPThreadPrivateDecl(SourceLocation Loc, |
10553 | ArrayRef<Expr *> VarList); |
10554 | /// Called on well-formed '#pragma omp allocate'. |
10555 | DeclGroupPtrTy ActOnOpenMPAllocateDirective(SourceLocation Loc, |
10556 | ArrayRef<Expr *> VarList, |
10557 | ArrayRef<OMPClause *> Clauses, |
10558 | DeclContext *Owner = nullptr); |
10559 | |
10560 | /// Called on well-formed '#pragma omp [begin] assume[s]'. |
10561 | void ActOnOpenMPAssumesDirective(SourceLocation Loc, |
10562 | OpenMPDirectiveKind DKind, |
10563 | ArrayRef<std::string> Assumptions, |
10564 | bool SkippedClauses); |
10565 | |
10566 | /// Check if there is an active global `omp begin assumes` directive. |
10567 | bool isInOpenMPAssumeScope() const { return !OMPAssumeScoped.empty(); } |
10568 | |
10569 | /// Check if there is an active global `omp assumes` directive. |
10570 | bool hasGlobalOpenMPAssumes() const { return !OMPAssumeGlobal.empty(); } |
10571 | |
10572 | /// Called on well-formed '#pragma omp end assumes'. |
10573 | void ActOnOpenMPEndAssumesDirective(); |
10574 | |
10575 | /// Called on well-formed '#pragma omp requires'. |
10576 | DeclGroupPtrTy ActOnOpenMPRequiresDirective(SourceLocation Loc, |
10577 | ArrayRef<OMPClause *> ClauseList); |
10578 | /// Check restrictions on Requires directive |
10579 | OMPRequiresDecl *CheckOMPRequiresDecl(SourceLocation Loc, |
10580 | ArrayRef<OMPClause *> Clauses); |
10581 | /// Check if the specified type is allowed to be used in 'omp declare |
10582 | /// reduction' construct. |
10583 | QualType ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
10584 | TypeResult ParsedType); |
10585 | /// Called on start of '#pragma omp declare reduction'. |
10586 | DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveStart( |
10587 | Scope *S, DeclContext *DC, DeclarationName Name, |
10588 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
10589 | AccessSpecifier AS, Decl *PrevDeclInScope = nullptr); |
10590 | /// Initialize declare reduction construct initializer. |
10591 | void ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D); |
10592 | /// Finish current declare reduction construct initializer. |
10593 | void ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner); |
10594 | /// Initialize declare reduction construct initializer. |
10595 | /// \return omp_priv variable. |
10596 | VarDecl *ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D); |
10597 | /// Finish current declare reduction construct initializer. |
10598 | void ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, Expr *Initializer, |
10599 | VarDecl *OmpPrivParm); |
10600 | /// Called at the end of '#pragma omp declare reduction'. |
10601 | DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveEnd( |
10602 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid); |
10603 | |
10604 | /// Check variable declaration in 'omp declare mapper' construct. |
10605 | TypeResult ActOnOpenMPDeclareMapperVarDecl(Scope *S, Declarator &D); |
10606 | /// Check if the specified type is allowed to be used in 'omp declare |
10607 | /// mapper' construct. |
10608 | QualType ActOnOpenMPDeclareMapperType(SourceLocation TyLoc, |
10609 | TypeResult ParsedType); |
10610 | /// Called on start of '#pragma omp declare mapper'. |
10611 | DeclGroupPtrTy ActOnOpenMPDeclareMapperDirective( |
10612 | Scope *S, DeclContext *DC, DeclarationName Name, QualType MapperType, |
10613 | SourceLocation StartLoc, DeclarationName VN, AccessSpecifier AS, |
10614 | Expr *MapperVarRef, ArrayRef<OMPClause *> Clauses, |
10615 | Decl *PrevDeclInScope = nullptr); |
10616 | /// Build the mapper variable of '#pragma omp declare mapper'. |
10617 | ExprResult ActOnOpenMPDeclareMapperDirectiveVarDecl(Scope *S, |
10618 | QualType MapperType, |
10619 | SourceLocation StartLoc, |
10620 | DeclarationName VN); |
10621 | bool isOpenMPDeclareMapperVarDeclAllowed(const VarDecl *VD) const; |
10622 | const ValueDecl *getOpenMPDeclareMapperVarName() const; |
10623 | |
10624 | /// Called on the start of target region i.e. '#pragma omp declare target'. |
10625 | bool ActOnStartOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI); |
10626 | |
10627 | /// Called at the end of target region i.e. '#pragma omp end declare target'. |
10628 | const DeclareTargetContextInfo ActOnOpenMPEndDeclareTargetDirective(); |
10629 | |
10630 | /// Called once a target context is completed, that can be when a |
10631 | /// '#pragma omp end declare target' was encountered or when a |
10632 | /// '#pragma omp declare target' without declaration-definition-seq was |
10633 | /// encountered. |
10634 | void ActOnFinishedOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI); |
10635 | |
10636 | /// Searches for the provided declaration name for OpenMP declare target |
10637 | /// directive. |
10638 | NamedDecl *lookupOpenMPDeclareTargetName(Scope *CurScope, |
10639 | CXXScopeSpec &ScopeSpec, |
10640 | const DeclarationNameInfo &Id); |
10641 | |
10642 | /// Called on correct id-expression from the '#pragma omp declare target'. |
10643 | void ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc, |
10644 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
10645 | DeclareTargetContextInfo &DTCI); |
10646 | |
10647 | /// Check declaration inside target region. |
10648 | void |
10649 | checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, |
10650 | SourceLocation IdLoc = SourceLocation()); |
10651 | /// Finishes analysis of the deferred functions calls that may be declared as |
10652 | /// host/nohost during device/host compilation. |
10653 | void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller, |
10654 | const FunctionDecl *Callee, |
10655 | SourceLocation Loc); |
10656 | /// Return true inside OpenMP declare target region. |
10657 | bool isInOpenMPDeclareTargetContext() const { |
10658 | return !DeclareTargetNesting.empty(); |
10659 | } |
10660 | /// Return true inside OpenMP target region. |
10661 | bool isInOpenMPTargetExecutionDirective() const; |
10662 | |
10663 | /// Return the number of captured regions created for an OpenMP directive. |
10664 | static int getOpenMPCaptureLevels(OpenMPDirectiveKind Kind); |
10665 | |
10666 | /// Initialization of captured region for OpenMP region. |
10667 | void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope); |
10668 | |
10669 | /// Called for syntactical loops (ForStmt or CXXForRangeStmt) associated to |
10670 | /// an OpenMP loop directive. |
10671 | StmtResult ActOnOpenMPCanonicalLoop(Stmt *AStmt); |
10672 | |
10673 | /// Process a canonical OpenMP loop nest that can either be a canonical |
10674 | /// literal loop (ForStmt or CXXForRangeStmt), or the generated loop of an |
10675 | /// OpenMP loop transformation construct. |
10676 | StmtResult ActOnOpenMPLoopnest(Stmt *AStmt); |
10677 | |
10678 | /// End of OpenMP region. |
10679 | /// |
10680 | /// \param S Statement associated with the current OpenMP region. |
10681 | /// \param Clauses List of clauses for the current OpenMP region. |
10682 | /// |
10683 | /// \returns Statement for finished OpenMP region. |
10684 | StmtResult ActOnOpenMPRegionEnd(StmtResult S, ArrayRef<OMPClause *> Clauses); |
10685 | StmtResult ActOnOpenMPExecutableDirective( |
10686 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
10687 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
10688 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc); |
10689 | /// Called on well-formed '\#pragma omp parallel' after parsing |
10690 | /// of the associated statement. |
10691 | StmtResult ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
10692 | Stmt *AStmt, |
10693 | SourceLocation StartLoc, |
10694 | SourceLocation EndLoc); |
10695 | using VarsWithInheritedDSAType = |
10696 | llvm::SmallDenseMap<const ValueDecl *, const Expr *, 4>; |
10697 | /// Called on well-formed '\#pragma omp simd' after parsing |
10698 | /// of the associated statement. |
10699 | StmtResult |
10700 | ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
10701 | SourceLocation StartLoc, SourceLocation EndLoc, |
10702 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10703 | /// Called on well-formed '#pragma omp tile' after parsing of its clauses and |
10704 | /// the associated statement. |
10705 | StmtResult ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses, |
10706 | Stmt *AStmt, SourceLocation StartLoc, |
10707 | SourceLocation EndLoc); |
10708 | /// Called on well-formed '#pragma omp unroll' after parsing of its clauses |
10709 | /// and the associated statement. |
10710 | StmtResult ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses, |
10711 | Stmt *AStmt, SourceLocation StartLoc, |
10712 | SourceLocation EndLoc); |
10713 | /// Called on well-formed '\#pragma omp for' after parsing |
10714 | /// of the associated statement. |
10715 | StmtResult |
10716 | ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
10717 | SourceLocation StartLoc, SourceLocation EndLoc, |
10718 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10719 | /// Called on well-formed '\#pragma omp for simd' after parsing |
10720 | /// of the associated statement. |
10721 | StmtResult |
10722 | ActOnOpenMPForSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
10723 | SourceLocation StartLoc, SourceLocation EndLoc, |
10724 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10725 | /// Called on well-formed '\#pragma omp sections' after parsing |
10726 | /// of the associated statement. |
10727 | StmtResult ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
10728 | Stmt *AStmt, SourceLocation StartLoc, |
10729 | SourceLocation EndLoc); |
10730 | /// Called on well-formed '\#pragma omp section' after parsing of the |
10731 | /// associated statement. |
10732 | StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc, |
10733 | SourceLocation EndLoc); |
10734 | /// Called on well-formed '\#pragma omp single' after parsing of the |
10735 | /// associated statement. |
10736 | StmtResult ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
10737 | Stmt *AStmt, SourceLocation StartLoc, |
10738 | SourceLocation EndLoc); |
10739 | /// Called on well-formed '\#pragma omp master' after parsing of the |
10740 | /// associated statement. |
10741 | StmtResult ActOnOpenMPMasterDirective(Stmt *AStmt, SourceLocation StartLoc, |
10742 | SourceLocation EndLoc); |
10743 | /// Called on well-formed '\#pragma omp critical' after parsing of the |
10744 | /// associated statement. |
10745 | StmtResult ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
10746 | ArrayRef<OMPClause *> Clauses, |
10747 | Stmt *AStmt, SourceLocation StartLoc, |
10748 | SourceLocation EndLoc); |
10749 | /// Called on well-formed '\#pragma omp parallel for' after parsing |
10750 | /// of the associated statement. |
10751 | StmtResult ActOnOpenMPParallelForDirective( |
10752 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10753 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10754 | /// Called on well-formed '\#pragma omp parallel for simd' after |
10755 | /// parsing of the associated statement. |
10756 | StmtResult ActOnOpenMPParallelForSimdDirective( |
10757 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10758 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10759 | /// Called on well-formed '\#pragma omp parallel master' after |
10760 | /// parsing of the associated statement. |
10761 | StmtResult ActOnOpenMPParallelMasterDirective(ArrayRef<OMPClause *> Clauses, |
10762 | Stmt *AStmt, |
10763 | SourceLocation StartLoc, |
10764 | SourceLocation EndLoc); |
10765 | /// Called on well-formed '\#pragma omp parallel sections' after |
10766 | /// parsing of the associated statement. |
10767 | StmtResult ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
10768 | Stmt *AStmt, |
10769 | SourceLocation StartLoc, |
10770 | SourceLocation EndLoc); |
10771 | /// Called on well-formed '\#pragma omp task' after parsing of the |
10772 | /// associated statement. |
10773 | StmtResult ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
10774 | Stmt *AStmt, SourceLocation StartLoc, |
10775 | SourceLocation EndLoc); |
10776 | /// Called on well-formed '\#pragma omp taskyield'. |
10777 | StmtResult ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
10778 | SourceLocation EndLoc); |
10779 | /// Called on well-formed '\#pragma omp barrier'. |
10780 | StmtResult ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
10781 | SourceLocation EndLoc); |
10782 | /// Called on well-formed '\#pragma omp taskwait'. |
10783 | StmtResult ActOnOpenMPTaskwaitDirective(ArrayRef<OMPClause *> Clauses, |
10784 | SourceLocation StartLoc, |
10785 | SourceLocation EndLoc); |
10786 | /// Called on well-formed '\#pragma omp taskgroup'. |
10787 | StmtResult ActOnOpenMPTaskgroupDirective(ArrayRef<OMPClause *> Clauses, |
10788 | Stmt *AStmt, SourceLocation StartLoc, |
10789 | SourceLocation EndLoc); |
10790 | /// Called on well-formed '\#pragma omp flush'. |
10791 | StmtResult ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
10792 | SourceLocation StartLoc, |
10793 | SourceLocation EndLoc); |
10794 | /// Called on well-formed '\#pragma omp depobj'. |
10795 | StmtResult ActOnOpenMPDepobjDirective(ArrayRef<OMPClause *> Clauses, |
10796 | SourceLocation StartLoc, |
10797 | SourceLocation EndLoc); |
10798 | /// Called on well-formed '\#pragma omp scan'. |
10799 | StmtResult ActOnOpenMPScanDirective(ArrayRef<OMPClause *> Clauses, |
10800 | SourceLocation StartLoc, |
10801 | SourceLocation EndLoc); |
10802 | /// Called on well-formed '\#pragma omp ordered' after parsing of the |
10803 | /// associated statement. |
10804 | StmtResult ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
10805 | Stmt *AStmt, SourceLocation StartLoc, |
10806 | SourceLocation EndLoc); |
10807 | /// Called on well-formed '\#pragma omp atomic' after parsing of the |
10808 | /// associated statement. |
10809 | StmtResult ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
10810 | Stmt *AStmt, SourceLocation StartLoc, |
10811 | SourceLocation EndLoc); |
10812 | /// Called on well-formed '\#pragma omp target' after parsing of the |
10813 | /// associated statement. |
10814 | StmtResult ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
10815 | Stmt *AStmt, SourceLocation StartLoc, |
10816 | SourceLocation EndLoc); |
10817 | /// Called on well-formed '\#pragma omp target data' after parsing of |
10818 | /// the associated statement. |
10819 | StmtResult ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
10820 | Stmt *AStmt, SourceLocation StartLoc, |
10821 | SourceLocation EndLoc); |
10822 | /// Called on well-formed '\#pragma omp target enter data' after |
10823 | /// parsing of the associated statement. |
10824 | StmtResult ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
10825 | SourceLocation StartLoc, |
10826 | SourceLocation EndLoc, |
10827 | Stmt *AStmt); |
10828 | /// Called on well-formed '\#pragma omp target exit data' after |
10829 | /// parsing of the associated statement. |
10830 | StmtResult ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
10831 | SourceLocation StartLoc, |
10832 | SourceLocation EndLoc, |
10833 | Stmt *AStmt); |
10834 | /// Called on well-formed '\#pragma omp target parallel' after |
10835 | /// parsing of the associated statement. |
10836 | StmtResult ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
10837 | Stmt *AStmt, |
10838 | SourceLocation StartLoc, |
10839 | SourceLocation EndLoc); |
10840 | /// Called on well-formed '\#pragma omp target parallel for' after |
10841 | /// parsing of the associated statement. |
10842 | StmtResult ActOnOpenMPTargetParallelForDirective( |
10843 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10844 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10845 | /// Called on well-formed '\#pragma omp teams' after parsing of the |
10846 | /// associated statement. |
10847 | StmtResult ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
10848 | Stmt *AStmt, SourceLocation StartLoc, |
10849 | SourceLocation EndLoc); |
10850 | /// Called on well-formed '\#pragma omp cancellation point'. |
10851 | StmtResult |
10852 | ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
10853 | SourceLocation EndLoc, |
10854 | OpenMPDirectiveKind CancelRegion); |
10855 | /// Called on well-formed '\#pragma omp cancel'. |
10856 | StmtResult ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
10857 | SourceLocation StartLoc, |
10858 | SourceLocation EndLoc, |
10859 | OpenMPDirectiveKind CancelRegion); |
10860 | /// Called on well-formed '\#pragma omp taskloop' after parsing of the |
10861 | /// associated statement. |
10862 | StmtResult |
10863 | ActOnOpenMPTaskLoopDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
10864 | SourceLocation StartLoc, SourceLocation EndLoc, |
10865 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10866 | /// Called on well-formed '\#pragma omp taskloop simd' after parsing of |
10867 | /// the associated statement. |
10868 | StmtResult ActOnOpenMPTaskLoopSimdDirective( |
10869 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10870 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10871 | /// Called on well-formed '\#pragma omp master taskloop' after parsing of the |
10872 | /// associated statement. |
10873 | StmtResult ActOnOpenMPMasterTaskLoopDirective( |
10874 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10875 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10876 | /// Called on well-formed '\#pragma omp master taskloop simd' after parsing of |
10877 | /// the associated statement. |
10878 | StmtResult ActOnOpenMPMasterTaskLoopSimdDirective( |
10879 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10880 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10881 | /// Called on well-formed '\#pragma omp parallel master taskloop' after |
10882 | /// parsing of the associated statement. |
10883 | StmtResult ActOnOpenMPParallelMasterTaskLoopDirective( |
10884 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10885 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10886 | /// Called on well-formed '\#pragma omp parallel master taskloop simd' after |
10887 | /// parsing of the associated statement. |
10888 | StmtResult ActOnOpenMPParallelMasterTaskLoopSimdDirective( |
10889 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10890 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10891 | /// Called on well-formed '\#pragma omp distribute' after parsing |
10892 | /// of the associated statement. |
10893 | StmtResult |
10894 | ActOnOpenMPDistributeDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
10895 | SourceLocation StartLoc, SourceLocation EndLoc, |
10896 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10897 | /// Called on well-formed '\#pragma omp target update'. |
10898 | StmtResult ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
10899 | SourceLocation StartLoc, |
10900 | SourceLocation EndLoc, |
10901 | Stmt *AStmt); |
10902 | /// Called on well-formed '\#pragma omp distribute parallel for' after |
10903 | /// parsing of the associated statement. |
10904 | StmtResult ActOnOpenMPDistributeParallelForDirective( |
10905 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10906 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10907 | /// Called on well-formed '\#pragma omp distribute parallel for simd' |
10908 | /// after parsing of the associated statement. |
10909 | StmtResult ActOnOpenMPDistributeParallelForSimdDirective( |
10910 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10911 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10912 | /// Called on well-formed '\#pragma omp distribute simd' after |
10913 | /// parsing of the associated statement. |
10914 | StmtResult ActOnOpenMPDistributeSimdDirective( |
10915 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10916 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10917 | /// Called on well-formed '\#pragma omp target parallel for simd' after |
10918 | /// parsing of the associated statement. |
10919 | StmtResult ActOnOpenMPTargetParallelForSimdDirective( |
10920 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10921 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10922 | /// Called on well-formed '\#pragma omp target simd' after parsing of |
10923 | /// the associated statement. |
10924 | StmtResult |
10925 | ActOnOpenMPTargetSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
10926 | SourceLocation StartLoc, SourceLocation EndLoc, |
10927 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10928 | /// Called on well-formed '\#pragma omp teams distribute' after parsing of |
10929 | /// the associated statement. |
10930 | StmtResult ActOnOpenMPTeamsDistributeDirective( |
10931 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10932 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10933 | /// Called on well-formed '\#pragma omp teams distribute simd' after parsing |
10934 | /// of the associated statement. |
10935 | StmtResult ActOnOpenMPTeamsDistributeSimdDirective( |
10936 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10937 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10938 | /// Called on well-formed '\#pragma omp teams distribute parallel for simd' |
10939 | /// after parsing of the associated statement. |
10940 | StmtResult ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
10941 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10942 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10943 | /// Called on well-formed '\#pragma omp teams distribute parallel for' |
10944 | /// after parsing of the associated statement. |
10945 | StmtResult ActOnOpenMPTeamsDistributeParallelForDirective( |
10946 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10947 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10948 | /// Called on well-formed '\#pragma omp target teams' after parsing of the |
10949 | /// associated statement. |
10950 | StmtResult ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses, |
10951 | Stmt *AStmt, |
10952 | SourceLocation StartLoc, |
10953 | SourceLocation EndLoc); |
10954 | /// Called on well-formed '\#pragma omp target teams distribute' after parsing |
10955 | /// of the associated statement. |
10956 | StmtResult ActOnOpenMPTargetTeamsDistributeDirective( |
10957 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10958 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10959 | /// Called on well-formed '\#pragma omp target teams distribute parallel for' |
10960 | /// after parsing of the associated statement. |
10961 | StmtResult ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
10962 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10963 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10964 | /// Called on well-formed '\#pragma omp target teams distribute parallel for |
10965 | /// simd' after parsing of the associated statement. |
10966 | StmtResult ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
10967 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10968 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10969 | /// Called on well-formed '\#pragma omp target teams distribute simd' after |
10970 | /// parsing of the associated statement. |
10971 | StmtResult ActOnOpenMPTargetTeamsDistributeSimdDirective( |
10972 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10973 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10974 | /// Called on well-formed '\#pragma omp interop'. |
10975 | StmtResult ActOnOpenMPInteropDirective(ArrayRef<OMPClause *> Clauses, |
10976 | SourceLocation StartLoc, |
10977 | SourceLocation EndLoc); |
10978 | /// Called on well-formed '\#pragma omp dispatch' after parsing of the |
10979 | // /associated statement. |
10980 | StmtResult ActOnOpenMPDispatchDirective(ArrayRef<OMPClause *> Clauses, |
10981 | Stmt *AStmt, SourceLocation StartLoc, |
10982 | SourceLocation EndLoc); |
10983 | /// Called on well-formed '\#pragma omp masked' after parsing of the |
10984 | // /associated statement. |
10985 | StmtResult ActOnOpenMPMaskedDirective(ArrayRef<OMPClause *> Clauses, |
10986 | Stmt *AStmt, SourceLocation StartLoc, |
10987 | SourceLocation EndLoc); |
10988 | |
10989 | /// Called on well-formed '\#pragma omp loop' after parsing of the |
10990 | /// associated statement. |
10991 | StmtResult ActOnOpenMPGenericLoopDirective( |
10992 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
10993 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
10994 | |
10995 | /// Checks correctness of linear modifiers. |
10996 | bool CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
10997 | SourceLocation LinLoc); |
10998 | /// Checks that the specified declaration matches requirements for the linear |
10999 | /// decls. |
11000 | bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc, |
11001 | OpenMPLinearClauseKind LinKind, QualType Type, |
11002 | bool IsDeclareSimd = false); |
11003 | |
11004 | /// Called on well-formed '\#pragma omp declare simd' after parsing of |
11005 | /// the associated method/function. |
11006 | DeclGroupPtrTy ActOnOpenMPDeclareSimdDirective( |
11007 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, |
11008 | Expr *Simdlen, ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
11009 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
11010 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR); |
11011 | |
11012 | /// Checks '\#pragma omp declare variant' variant function and original |
11013 | /// functions after parsing of the associated method/function. |
11014 | /// \param DG Function declaration to which declare variant directive is |
11015 | /// applied to. |
11016 | /// \param VariantRef Expression that references the variant function, which |
11017 | /// must be used instead of the original one, specified in \p DG. |
11018 | /// \param TI The trait info object representing the match clause. |
11019 | /// \param NumAppendArgs The number of omp_interop_t arguments to account for |
11020 | /// in checking. |
11021 | /// \returns None, if the function/variant function are not compatible with |
11022 | /// the pragma, pair of original function/variant ref expression otherwise. |
11023 | Optional<std::pair<FunctionDecl *, Expr *>> |
11024 | checkOpenMPDeclareVariantFunction(DeclGroupPtrTy DG, Expr *VariantRef, |
11025 | OMPTraitInfo &TI, unsigned NumAppendArgs, |
11026 | SourceRange SR); |
11027 | |
11028 | /// Called on well-formed '\#pragma omp declare variant' after parsing of |
11029 | /// the associated method/function. |
11030 | /// \param FD Function declaration to which declare variant directive is |
11031 | /// applied to. |
11032 | /// \param VariantRef Expression that references the variant function, which |
11033 | /// must be used instead of the original one, specified in \p DG. |
11034 | /// \param TI The context traits associated with the function variant. |
11035 | /// \param AdjustArgsNothing The list of 'nothing' arguments. |
11036 | /// \param AdjustArgsNeedDevicePtr The list of 'need_device_ptr' arguments. |
11037 | /// \param AppendArgs The list of 'append_args' arguments. |
11038 | /// \param AdjustArgsLoc The Location of an 'adjust_args' clause. |
11039 | /// \param AppendArgsLoc The Location of an 'append_args' clause. |
11040 | /// \param SR The SourceRange of the 'declare variant' directive. |
11041 | void ActOnOpenMPDeclareVariantDirective( |
11042 | FunctionDecl *FD, Expr *VariantRef, OMPTraitInfo &TI, |
11043 | ArrayRef<Expr *> AdjustArgsNothing, |
11044 | ArrayRef<Expr *> AdjustArgsNeedDevicePtr, |
11045 | ArrayRef<OMPDeclareVariantAttr::InteropType> AppendArgs, |
11046 | SourceLocation AdjustArgsLoc, SourceLocation AppendArgsLoc, |
11047 | SourceRange SR); |
11048 | |
11049 | OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, |
11050 | Expr *Expr, |
11051 | SourceLocation StartLoc, |
11052 | SourceLocation LParenLoc, |
11053 | SourceLocation EndLoc); |
11054 | /// Called on well-formed 'allocator' clause. |
11055 | OMPClause *ActOnOpenMPAllocatorClause(Expr *Allocator, |
11056 | SourceLocation StartLoc, |
11057 | SourceLocation LParenLoc, |
11058 | SourceLocation EndLoc); |
11059 | /// Called on well-formed 'if' clause. |
11060 | OMPClause *ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
11061 | Expr *Condition, SourceLocation StartLoc, |
11062 | SourceLocation LParenLoc, |
11063 | SourceLocation NameModifierLoc, |
11064 | SourceLocation ColonLoc, |
11065 | SourceLocation EndLoc); |
11066 | /// Called on well-formed 'final' clause. |
11067 | OMPClause *ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
11068 | SourceLocation LParenLoc, |
11069 | SourceLocation EndLoc); |
11070 | /// Called on well-formed 'num_threads' clause. |
11071 | OMPClause *ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
11072 | SourceLocation StartLoc, |
11073 | SourceLocation LParenLoc, |
11074 | SourceLocation EndLoc); |
11075 | /// Called on well-formed 'align' clause. |
11076 | OMPClause *ActOnOpenMPAlignClause(Expr *Alignment, SourceLocation StartLoc, |
11077 | SourceLocation LParenLoc, |
11078 | SourceLocation EndLoc); |
11079 | /// Called on well-formed 'safelen' clause. |
11080 | OMPClause *ActOnOpenMPSafelenClause(Expr *Length, |
11081 | SourceLocation StartLoc, |
11082 | SourceLocation LParenLoc, |
11083 | SourceLocation EndLoc); |
11084 | /// Called on well-formed 'simdlen' clause. |
11085 | OMPClause *ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc, |
11086 | SourceLocation LParenLoc, |
11087 | SourceLocation EndLoc); |
11088 | /// Called on well-form 'sizes' clause. |
11089 | OMPClause *ActOnOpenMPSizesClause(ArrayRef<Expr *> SizeExprs, |
11090 | SourceLocation StartLoc, |
11091 | SourceLocation LParenLoc, |
11092 | SourceLocation EndLoc); |
11093 | /// Called on well-form 'full' clauses. |
11094 | OMPClause *ActOnOpenMPFullClause(SourceLocation StartLoc, |
11095 | SourceLocation EndLoc); |
11096 | /// Called on well-form 'partial' clauses. |
11097 | OMPClause *ActOnOpenMPPartialClause(Expr *FactorExpr, SourceLocation StartLoc, |
11098 | SourceLocation LParenLoc, |
11099 | SourceLocation EndLoc); |
11100 | /// Called on well-formed 'collapse' clause. |
11101 | OMPClause *ActOnOpenMPCollapseClause(Expr *NumForLoops, |
11102 | SourceLocation StartLoc, |
11103 | SourceLocation LParenLoc, |
11104 | SourceLocation EndLoc); |
11105 | /// Called on well-formed 'ordered' clause. |
11106 | OMPClause * |
11107 | ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, |
11108 | SourceLocation LParenLoc = SourceLocation(), |
11109 | Expr *NumForLoops = nullptr); |
11110 | /// Called on well-formed 'grainsize' clause. |
11111 | OMPClause *ActOnOpenMPGrainsizeClause(Expr *Size, SourceLocation StartLoc, |
11112 | SourceLocation LParenLoc, |
11113 | SourceLocation EndLoc); |
11114 | /// Called on well-formed 'num_tasks' clause. |
11115 | OMPClause *ActOnOpenMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc, |
11116 | SourceLocation LParenLoc, |
11117 | SourceLocation EndLoc); |
11118 | /// Called on well-formed 'hint' clause. |
11119 | OMPClause *ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
11120 | SourceLocation LParenLoc, |
11121 | SourceLocation EndLoc); |
11122 | /// Called on well-formed 'detach' clause. |
11123 | OMPClause *ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc, |
11124 | SourceLocation LParenLoc, |
11125 | SourceLocation EndLoc); |
11126 | |
11127 | OMPClause *ActOnOpenMPSimpleClause(OpenMPClauseKind Kind, |
11128 | unsigned Argument, |
11129 | SourceLocation ArgumentLoc, |
11130 | SourceLocation StartLoc, |
11131 | SourceLocation LParenLoc, |
11132 | SourceLocation EndLoc); |
11133 | /// Called on well-formed 'when' clause. |
11134 | OMPClause *ActOnOpenMPWhenClause(OMPTraitInfo &TI, SourceLocation StartLoc, |
11135 | SourceLocation LParenLoc, |
11136 | SourceLocation EndLoc); |
11137 | /// Called on well-formed 'default' clause. |
11138 | OMPClause *ActOnOpenMPDefaultClause(llvm::omp::DefaultKind Kind, |
11139 | SourceLocation KindLoc, |
11140 | SourceLocation StartLoc, |
11141 | SourceLocation LParenLoc, |
11142 | SourceLocation EndLoc); |
11143 | /// Called on well-formed 'proc_bind' clause. |
11144 | OMPClause *ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind, |
11145 | SourceLocation KindLoc, |
11146 | SourceLocation StartLoc, |
11147 | SourceLocation LParenLoc, |
11148 | SourceLocation EndLoc); |
11149 | /// Called on well-formed 'order' clause. |
11150 | OMPClause *ActOnOpenMPOrderClause(OpenMPOrderClauseKind Kind, |
11151 | SourceLocation KindLoc, |
11152 | SourceLocation StartLoc, |
11153 | SourceLocation LParenLoc, |
11154 | SourceLocation EndLoc); |
11155 | /// Called on well-formed 'update' clause. |
11156 | OMPClause *ActOnOpenMPUpdateClause(OpenMPDependClauseKind Kind, |
11157 | SourceLocation KindLoc, |
11158 | SourceLocation StartLoc, |
11159 | SourceLocation LParenLoc, |
11160 | SourceLocation EndLoc); |
11161 | |
11162 | OMPClause *ActOnOpenMPSingleExprWithArgClause( |
11163 | OpenMPClauseKind Kind, ArrayRef<unsigned> Arguments, Expr *Expr, |
11164 | SourceLocation StartLoc, SourceLocation LParenLoc, |
11165 | ArrayRef<SourceLocation> ArgumentsLoc, SourceLocation DelimLoc, |
11166 | SourceLocation EndLoc); |
11167 | /// Called on well-formed 'schedule' clause. |
11168 | OMPClause *ActOnOpenMPScheduleClause( |
11169 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
11170 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
11171 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
11172 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc); |
11173 | |
11174 | OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc, |
11175 | SourceLocation EndLoc); |
11176 | /// Called on well-formed 'nowait' clause. |
11177 | OMPClause *ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
11178 | SourceLocation EndLoc); |
11179 | /// Called on well-formed 'untied' clause. |
11180 | OMPClause *ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
11181 | SourceLocation EndLoc); |
11182 | /// Called on well-formed 'mergeable' clause. |
11183 | OMPClause *ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
11184 | SourceLocation EndLoc); |
11185 | /// Called on well-formed 'read' clause. |
11186 | OMPClause *ActOnOpenMPReadClause(SourceLocation StartLoc, |
11187 | SourceLocation EndLoc); |
11188 | /// Called on well-formed 'write' clause. |
11189 | OMPClause *ActOnOpenMPWriteClause(SourceLocation StartLoc, |
11190 | SourceLocation EndLoc); |
11191 | /// Called on well-formed 'update' clause. |
11192 | OMPClause *ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
11193 | SourceLocation EndLoc); |
11194 | /// Called on well-formed 'capture' clause. |
11195 | OMPClause *ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
11196 | SourceLocation EndLoc); |
11197 | /// Called on well-formed 'compare' clause. |
11198 | OMPClause *ActOnOpenMPCompareClause(SourceLocation StartLoc, |
11199 | SourceLocation EndLoc); |
11200 | /// Called on well-formed 'seq_cst' clause. |
11201 | OMPClause *ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
11202 | SourceLocation EndLoc); |
11203 | /// Called on well-formed 'acq_rel' clause. |
11204 | OMPClause *ActOnOpenMPAcqRelClause(SourceLocation StartLoc, |
11205 | SourceLocation EndLoc); |
11206 | /// Called on well-formed 'acquire' clause. |
11207 | OMPClause *ActOnOpenMPAcquireClause(SourceLocation StartLoc, |
11208 | SourceLocation EndLoc); |
11209 | /// Called on well-formed 'release' clause. |
11210 | OMPClause *ActOnOpenMPReleaseClause(SourceLocation StartLoc, |
11211 | SourceLocation EndLoc); |
11212 | /// Called on well-formed 'relaxed' clause. |
11213 | OMPClause *ActOnOpenMPRelaxedClause(SourceLocation StartLoc, |
11214 | SourceLocation EndLoc); |
11215 | |
11216 | /// Called on well-formed 'init' clause. |
11217 | OMPClause *ActOnOpenMPInitClause(Expr *InteropVar, ArrayRef<Expr *> PrefExprs, |
11218 | bool IsTarget, bool IsTargetSync, |
11219 | SourceLocation StartLoc, |
11220 | SourceLocation LParenLoc, |
11221 | SourceLocation VarLoc, |
11222 | SourceLocation EndLoc); |
11223 | |
11224 | /// Called on well-formed 'use' clause. |
11225 | OMPClause *ActOnOpenMPUseClause(Expr *InteropVar, SourceLocation StartLoc, |
11226 | SourceLocation LParenLoc, |
11227 | SourceLocation VarLoc, SourceLocation EndLoc); |
11228 | |
11229 | /// Called on well-formed 'destroy' clause. |
11230 | OMPClause *ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, |
11231 | SourceLocation LParenLoc, |
11232 | SourceLocation VarLoc, |
11233 | SourceLocation EndLoc); |
11234 | /// Called on well-formed 'novariants' clause. |
11235 | OMPClause *ActOnOpenMPNovariantsClause(Expr *Condition, |
11236 | SourceLocation StartLoc, |
11237 | SourceLocation LParenLoc, |
11238 | SourceLocation EndLoc); |
11239 | /// Called on well-formed 'nocontext' clause. |
11240 | OMPClause *ActOnOpenMPNocontextClause(Expr *Condition, |
11241 | SourceLocation StartLoc, |
11242 | SourceLocation LParenLoc, |
11243 | SourceLocation EndLoc); |
11244 | /// Called on well-formed 'filter' clause. |
11245 | OMPClause *ActOnOpenMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, |
11246 | SourceLocation LParenLoc, |
11247 | SourceLocation EndLoc); |
11248 | /// Called on well-formed 'threads' clause. |
11249 | OMPClause *ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
11250 | SourceLocation EndLoc); |
11251 | /// Called on well-formed 'simd' clause. |
11252 | OMPClause *ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
11253 | SourceLocation EndLoc); |
11254 | /// Called on well-formed 'nogroup' clause. |
11255 | OMPClause *ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
11256 | SourceLocation EndLoc); |
11257 | /// Called on well-formed 'unified_address' clause. |
11258 | OMPClause *ActOnOpenMPUnifiedAddressClause(SourceLocation StartLoc, |
11259 | SourceLocation EndLoc); |
11260 | |
11261 | /// Called on well-formed 'unified_address' clause. |
11262 | OMPClause *ActOnOpenMPUnifiedSharedMemoryClause(SourceLocation StartLoc, |
11263 | SourceLocation EndLoc); |
11264 | |
11265 | /// Called on well-formed 'reverse_offload' clause. |
11266 | OMPClause *ActOnOpenMPReverseOffloadClause(SourceLocation StartLoc, |
11267 | SourceLocation EndLoc); |
11268 | |
11269 | /// Called on well-formed 'dynamic_allocators' clause. |
11270 | OMPClause *ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc, |
11271 | SourceLocation EndLoc); |
11272 | |
11273 | /// Called on well-formed 'atomic_default_mem_order' clause. |
11274 | OMPClause *ActOnOpenMPAtomicDefaultMemOrderClause( |
11275 | OpenMPAtomicDefaultMemOrderClauseKind Kind, SourceLocation KindLoc, |
11276 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); |
11277 | |
11278 | OMPClause *ActOnOpenMPVarListClause( |
11279 | OpenMPClauseKind Kind, ArrayRef<Expr *> Vars, Expr *DepModOrTailExpr, |
11280 | const OMPVarListLocTy &Locs, SourceLocation ColonLoc, |
11281 | CXXScopeSpec &ReductionOrMapperIdScopeSpec, |
11282 | DeclarationNameInfo &ReductionOrMapperId, int ExtraModifier, |
11283 | ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
11284 | ArrayRef<SourceLocation> MapTypeModifiersLoc, bool IsMapTypeImplicit, |
11285 | SourceLocation ExtraModifierLoc, |
11286 | ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
11287 | ArrayRef<SourceLocation> MotionModifiersLoc); |
11288 | /// Called on well-formed 'inclusive' clause. |
11289 | OMPClause *ActOnOpenMPInclusiveClause(ArrayRef<Expr *> VarList, |
11290 | SourceLocation StartLoc, |
11291 | SourceLocation LParenLoc, |
11292 | SourceLocation EndLoc); |
11293 | /// Called on well-formed 'exclusive' clause. |
11294 | OMPClause *ActOnOpenMPExclusiveClause(ArrayRef<Expr *> VarList, |
11295 | SourceLocation StartLoc, |
11296 | SourceLocation LParenLoc, |
11297 | SourceLocation EndLoc); |
11298 | /// Called on well-formed 'allocate' clause. |
11299 | OMPClause * |
11300 | ActOnOpenMPAllocateClause(Expr *Allocator, ArrayRef<Expr *> VarList, |
11301 | SourceLocation StartLoc, SourceLocation ColonLoc, |
11302 | SourceLocation LParenLoc, SourceLocation EndLoc); |
11303 | /// Called on well-formed 'private' clause. |
11304 | OMPClause *ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
11305 | SourceLocation StartLoc, |
11306 | SourceLocation LParenLoc, |
11307 | SourceLocation EndLoc); |
11308 | /// Called on well-formed 'firstprivate' clause. |
11309 | OMPClause *ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
11310 | SourceLocation StartLoc, |
11311 | SourceLocation LParenLoc, |
11312 | SourceLocation EndLoc); |
11313 | /// Called on well-formed 'lastprivate' clause. |
11314 | OMPClause *ActOnOpenMPLastprivateClause( |
11315 | ArrayRef<Expr *> VarList, OpenMPLastprivateModifier LPKind, |
11316 | SourceLocation LPKindLoc, SourceLocation ColonLoc, |
11317 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); |
11318 | /// Called on well-formed 'shared' clause. |
11319 | OMPClause *ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
11320 | SourceLocation StartLoc, |
11321 | SourceLocation LParenLoc, |
11322 | SourceLocation EndLoc); |
11323 | /// Called on well-formed 'reduction' clause. |
11324 | OMPClause *ActOnOpenMPReductionClause( |
11325 | ArrayRef<Expr *> VarList, OpenMPReductionClauseModifier Modifier, |
11326 | SourceLocation StartLoc, SourceLocation LParenLoc, |
11327 | SourceLocation ModifierLoc, SourceLocation ColonLoc, |
11328 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
11329 | const DeclarationNameInfo &ReductionId, |
11330 | ArrayRef<Expr *> UnresolvedReductions = llvm::None); |
11331 | /// Called on well-formed 'task_reduction' clause. |
11332 | OMPClause *ActOnOpenMPTaskReductionClause( |
11333 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
11334 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
11335 | CXXScopeSpec &ReductionIdScopeSpec, |
11336 | const DeclarationNameInfo &ReductionId, |
11337 | ArrayRef<Expr *> UnresolvedReductions = llvm::None); |
11338 | /// Called on well-formed 'in_reduction' clause. |
11339 | OMPClause *ActOnOpenMPInReductionClause( |
11340 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
11341 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
11342 | CXXScopeSpec &ReductionIdScopeSpec, |
11343 | const DeclarationNameInfo &ReductionId, |
11344 | ArrayRef<Expr *> UnresolvedReductions = llvm::None); |
11345 | /// Called on well-formed 'linear' clause. |
11346 | OMPClause * |
11347 | ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
11348 | SourceLocation StartLoc, SourceLocation LParenLoc, |
11349 | OpenMPLinearClauseKind LinKind, SourceLocation LinLoc, |
11350 | SourceLocation ColonLoc, SourceLocation EndLoc); |
11351 | /// Called on well-formed 'aligned' clause. |
11352 | OMPClause *ActOnOpenMPAlignedClause(ArrayRef<Expr *> VarList, |
11353 | Expr *Alignment, |
11354 | SourceLocation StartLoc, |
11355 | SourceLocation LParenLoc, |
11356 | SourceLocation ColonLoc, |
11357 | SourceLocation EndLoc); |
11358 | /// Called on well-formed 'copyin' clause. |
11359 | OMPClause *ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
11360 | SourceLocation StartLoc, |
11361 | SourceLocation LParenLoc, |
11362 | SourceLocation EndLoc); |
11363 | /// Called on well-formed 'copyprivate' clause. |
11364 | OMPClause *ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
11365 | SourceLocation StartLoc, |
11366 | SourceLocation LParenLoc, |
11367 | SourceLocation EndLoc); |
11368 | /// Called on well-formed 'flush' pseudo clause. |
11369 | OMPClause *ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
11370 | SourceLocation StartLoc, |
11371 | SourceLocation LParenLoc, |
11372 | SourceLocation EndLoc); |
11373 | /// Called on well-formed 'depobj' pseudo clause. |
11374 | OMPClause *ActOnOpenMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, |
11375 | SourceLocation LParenLoc, |
11376 | SourceLocation EndLoc); |
11377 | /// Called on well-formed 'depend' clause. |
11378 | OMPClause * |
11379 | ActOnOpenMPDependClause(Expr *DepModifier, OpenMPDependClauseKind DepKind, |
11380 | SourceLocation DepLoc, SourceLocation ColonLoc, |
11381 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
11382 | SourceLocation LParenLoc, SourceLocation EndLoc); |
11383 | /// Called on well-formed 'device' clause. |
11384 | OMPClause *ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier, |
11385 | Expr *Device, SourceLocation StartLoc, |
11386 | SourceLocation LParenLoc, |
11387 | SourceLocation ModifierLoc, |
11388 | SourceLocation EndLoc); |
11389 | /// Called on well-formed 'map' clause. |
11390 | OMPClause *ActOnOpenMPMapClause( |
11391 | ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
11392 | ArrayRef<SourceLocation> MapTypeModifiersLoc, |
11393 | CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, |
11394 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
11395 | SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
11396 | const OMPVarListLocTy &Locs, bool NoDiagnose = false, |
11397 | ArrayRef<Expr *> UnresolvedMappers = llvm::None); |
11398 | /// Called on well-formed 'num_teams' clause. |
11399 | OMPClause *ActOnOpenMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, |
11400 | SourceLocation LParenLoc, |
11401 | SourceLocation EndLoc); |
11402 | /// Called on well-formed 'thread_limit' clause. |
11403 | OMPClause *ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
11404 | SourceLocation StartLoc, |
11405 | SourceLocation LParenLoc, |
11406 | SourceLocation EndLoc); |
11407 | /// Called on well-formed 'priority' clause. |
11408 | OMPClause *ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc, |
11409 | SourceLocation LParenLoc, |
11410 | SourceLocation EndLoc); |
11411 | /// Called on well-formed 'dist_schedule' clause. |
11412 | OMPClause *ActOnOpenMPDistScheduleClause( |
11413 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, |
11414 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, |
11415 | SourceLocation CommaLoc, SourceLocation EndLoc); |
11416 | /// Called on well-formed 'defaultmap' clause. |
11417 | OMPClause *ActOnOpenMPDefaultmapClause( |
11418 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
11419 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
11420 | SourceLocation KindLoc, SourceLocation EndLoc); |
11421 | /// Called on well-formed 'to' clause. |
11422 | OMPClause * |
11423 | ActOnOpenMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
11424 | ArrayRef<SourceLocation> MotionModifiersLoc, |
11425 | CXXScopeSpec &MapperIdScopeSpec, |
11426 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
11427 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
11428 | ArrayRef<Expr *> UnresolvedMappers = llvm::None); |
11429 | /// Called on well-formed 'from' clause. |
11430 | OMPClause * |
11431 | ActOnOpenMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
11432 | ArrayRef<SourceLocation> MotionModifiersLoc, |
11433 | CXXScopeSpec &MapperIdScopeSpec, |
11434 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
11435 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
11436 | ArrayRef<Expr *> UnresolvedMappers = llvm::None); |
11437 | /// Called on well-formed 'use_device_ptr' clause. |
11438 | OMPClause *ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
11439 | const OMPVarListLocTy &Locs); |
11440 | /// Called on well-formed 'use_device_addr' clause. |
11441 | OMPClause *ActOnOpenMPUseDeviceAddrClause(ArrayRef<Expr *> VarList, |
11442 | const OMPVarListLocTy &Locs); |
11443 | /// Called on well-formed 'is_device_ptr' clause. |
11444 | OMPClause *ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
11445 | const OMPVarListLocTy &Locs); |
11446 | /// Called on well-formed 'nontemporal' clause. |
11447 | OMPClause *ActOnOpenMPNontemporalClause(ArrayRef<Expr *> VarList, |
11448 | SourceLocation StartLoc, |
11449 | SourceLocation LParenLoc, |
11450 | SourceLocation EndLoc); |
11451 | |
11452 | /// Data for list of allocators. |
11453 | struct UsesAllocatorsData { |
11454 | /// Allocator. |
11455 | Expr *Allocator = nullptr; |
11456 | /// Allocator traits. |
11457 | Expr *AllocatorTraits = nullptr; |
11458 | /// Locations of '(' and ')' symbols. |
11459 | SourceLocation LParenLoc, RParenLoc; |
11460 | }; |
11461 | /// Called on well-formed 'uses_allocators' clause. |
11462 | OMPClause *ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, |
11463 | SourceLocation LParenLoc, |
11464 | SourceLocation EndLoc, |
11465 | ArrayRef<UsesAllocatorsData> Data); |
11466 | /// Called on well-formed 'affinity' clause. |
11467 | OMPClause *ActOnOpenMPAffinityClause(SourceLocation StartLoc, |
11468 | SourceLocation LParenLoc, |
11469 | SourceLocation ColonLoc, |
11470 | SourceLocation EndLoc, Expr *Modifier, |
11471 | ArrayRef<Expr *> Locators); |
11472 | /// Called on a well-formed 'bind' clause. |
11473 | OMPClause *ActOnOpenMPBindClause(OpenMPBindClauseKind Kind, |
11474 | SourceLocation KindLoc, |
11475 | SourceLocation StartLoc, |
11476 | SourceLocation LParenLoc, |
11477 | SourceLocation EndLoc); |
11478 | |
11479 | /// The kind of conversion being performed. |
11480 | enum CheckedConversionKind { |
11481 | /// An implicit conversion. |
11482 | CCK_ImplicitConversion, |
11483 | /// A C-style cast. |
11484 | CCK_CStyleCast, |
11485 | /// A functional-style cast. |
11486 | CCK_FunctionalCast, |
11487 | /// A cast other than a C-style cast. |
11488 | CCK_OtherCast, |
11489 | /// A conversion for an operand of a builtin overloaded operator. |
11490 | CCK_ForBuiltinOverloadedOp |
11491 | }; |
11492 | |
11493 | static bool isCast(CheckedConversionKind CCK) { |
11494 | return CCK == CCK_CStyleCast || CCK == CCK_FunctionalCast || |
11495 | CCK == CCK_OtherCast; |
11496 | } |
11497 | |
11498 | /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit |
11499 | /// cast. If there is already an implicit cast, merge into the existing one. |
11500 | /// If isLvalue, the result of the cast is an lvalue. |
11501 | ExprResult |
11502 | ImpCastExprToType(Expr *E, QualType Type, CastKind CK, |
11503 | ExprValueKind VK = VK_PRValue, |
11504 | const CXXCastPath *BasePath = nullptr, |
11505 | CheckedConversionKind CCK = CCK_ImplicitConversion); |
11506 | |
11507 | /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding |
11508 | /// to the conversion from scalar type ScalarTy to the Boolean type. |
11509 | static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); |
11510 | |
11511 | /// IgnoredValueConversions - Given that an expression's result is |
11512 | /// syntactically ignored, perform any conversions that are |
11513 | /// required. |
11514 | ExprResult IgnoredValueConversions(Expr *E); |
11515 | |
11516 | // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts |
11517 | // functions and arrays to their respective pointers (C99 6.3.2.1). |
11518 | ExprResult UsualUnaryConversions(Expr *E); |
11519 | |
11520 | /// CallExprUnaryConversions - a special case of an unary conversion |
11521 | /// performed on a function designator of a call expression. |
11522 | ExprResult CallExprUnaryConversions(Expr *E); |
11523 | |
11524 | // DefaultFunctionArrayConversion - converts functions and arrays |
11525 | // to their respective pointers (C99 6.3.2.1). |
11526 | ExprResult DefaultFunctionArrayConversion(Expr *E, bool Diagnose = true); |
11527 | |
11528 | // DefaultFunctionArrayLvalueConversion - converts functions and |
11529 | // arrays to their respective pointers and performs the |
11530 | // lvalue-to-rvalue conversion. |
11531 | ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, |
11532 | bool Diagnose = true); |
11533 | |
11534 | // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on |
11535 | // the operand. This function is a no-op if the operand has a function type |
11536 | // or an array type. |
11537 | ExprResult DefaultLvalueConversion(Expr *E); |
11538 | |
11539 | // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that |
11540 | // do not have a prototype. Integer promotions are performed on each |
11541 | // argument, and arguments that have type float are promoted to double. |
11542 | ExprResult DefaultArgumentPromotion(Expr *E); |
11543 | |
11544 | /// If \p E is a prvalue denoting an unmaterialized temporary, materialize |
11545 | /// it as an xvalue. In C++98, the result will still be a prvalue, because |
11546 | /// we don't have xvalues there. |
11547 | ExprResult TemporaryMaterializationConversion(Expr *E); |
11548 | |
11549 | // Used for emitting the right warning by DefaultVariadicArgumentPromotion |
11550 | enum VariadicCallType { |
11551 | VariadicFunction, |
11552 | VariadicBlock, |
11553 | VariadicMethod, |
11554 | VariadicConstructor, |
11555 | VariadicDoesNotApply |
11556 | }; |
11557 | |
11558 | VariadicCallType getVariadicCallType(FunctionDecl *FDecl, |
11559 | const FunctionProtoType *Proto, |
11560 | Expr *Fn); |
11561 | |
11562 | // Used for determining in which context a type is allowed to be passed to a |
11563 | // vararg function. |
11564 | enum VarArgKind { |
11565 | VAK_Valid, |
11566 | VAK_ValidInCXX11, |
11567 | VAK_Undefined, |
11568 | VAK_MSVCUndefined, |
11569 | VAK_Invalid |
11570 | }; |
11571 | |
11572 | // Determines which VarArgKind fits an expression. |
11573 | VarArgKind isValidVarArgType(const QualType &Ty); |
11574 | |
11575 | /// Check to see if the given expression is a valid argument to a variadic |
11576 | /// function, issuing a diagnostic if not. |
11577 | void checkVariadicArgument(const Expr *E, VariadicCallType CT); |
11578 | |
11579 | /// Check whether the given statement can have musttail applied to it, |
11580 | /// issuing a diagnostic and returning false if not. In the success case, |
11581 | /// the statement is rewritten to remove implicit nodes from the return |
11582 | /// value. |
11583 | bool checkAndRewriteMustTailAttr(Stmt *St, const Attr &MTA); |
11584 | |
11585 | private: |
11586 | /// Check whether the given statement can have musttail applied to it, |
11587 | /// issuing a diagnostic and returning false if not. |
11588 | bool checkMustTailAttr(const Stmt *St, const Attr &MTA); |
11589 | |
11590 | public: |
11591 | /// Check to see if a given expression could have '.c_str()' called on it. |
11592 | bool hasCStrMethod(const Expr *E); |
11593 | |
11594 | /// GatherArgumentsForCall - Collector argument expressions for various |
11595 | /// form of call prototypes. |
11596 | bool GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl, |
11597 | const FunctionProtoType *Proto, |
11598 | unsigned FirstParam, ArrayRef<Expr *> Args, |
11599 | SmallVectorImpl<Expr *> &AllArgs, |
11600 | VariadicCallType CallType = VariadicDoesNotApply, |
11601 | bool AllowExplicit = false, |
11602 | bool IsListInitialization = false); |
11603 | |
11604 | // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but |
11605 | // will create a runtime trap if the resulting type is not a POD type. |
11606 | ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, |
11607 | FunctionDecl *FDecl); |
11608 | |
11609 | /// Context in which we're performing a usual arithmetic conversion. |
11610 | enum ArithConvKind { |
11611 | /// An arithmetic operation. |
11612 | ACK_Arithmetic, |
11613 | /// A bitwise operation. |
11614 | ACK_BitwiseOp, |
11615 | /// A comparison. |
11616 | ACK_Comparison, |
11617 | /// A conditional (?:) operator. |
11618 | ACK_Conditional, |
11619 | /// A compound assignment expression. |
11620 | ACK_CompAssign, |
11621 | }; |
11622 | |
11623 | // UsualArithmeticConversions - performs the UsualUnaryConversions on it's |
11624 | // operands and then handles various conversions that are common to binary |
11625 | // operators (C99 6.3.1.8). If both operands aren't arithmetic, this |
11626 | // routine returns the first non-arithmetic type found. The client is |
11627 | // responsible for emitting appropriate error diagnostics. |
11628 | QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, |
11629 | SourceLocation Loc, ArithConvKind ACK); |
11630 | |
11631 | /// AssignConvertType - All of the 'assignment' semantic checks return this |
11632 | /// enum to indicate whether the assignment was allowed. These checks are |
11633 | /// done for simple assignments, as well as initialization, return from |
11634 | /// function, argument passing, etc. The query is phrased in terms of a |
11635 | /// source and destination type. |
11636 | enum AssignConvertType { |
11637 | /// Compatible - the types are compatible according to the standard. |
11638 | Compatible, |
11639 | |
11640 | /// PointerToInt - The assignment converts a pointer to an int, which we |
11641 | /// accept as an extension. |
11642 | PointerToInt, |
11643 | |
11644 | /// IntToPointer - The assignment converts an int to a pointer, which we |
11645 | /// accept as an extension. |
11646 | IntToPointer, |
11647 | |
11648 | /// FunctionVoidPointer - The assignment is between a function pointer and |
11649 | /// void*, which the standard doesn't allow, but we accept as an extension. |
11650 | FunctionVoidPointer, |
11651 | |
11652 | /// IncompatiblePointer - The assignment is between two pointers types that |
11653 | /// are not compatible, but we accept them as an extension. |
11654 | IncompatiblePointer, |
11655 | |
11656 | /// IncompatibleFunctionPointer - The assignment is between two function |
11657 | /// pointers types that are not compatible, but we accept them as an |
11658 | /// extension. |
11659 | IncompatibleFunctionPointer, |
11660 | |
11661 | /// IncompatiblePointerSign - The assignment is between two pointers types |
11662 | /// which point to integers which have a different sign, but are otherwise |
11663 | /// identical. This is a subset of the above, but broken out because it's by |
11664 | /// far the most common case of incompatible pointers. |
11665 | IncompatiblePointerSign, |
11666 | |
11667 | /// CompatiblePointerDiscardsQualifiers - The assignment discards |
11668 | /// c/v/r qualifiers, which we accept as an extension. |
11669 | CompatiblePointerDiscardsQualifiers, |
11670 | |
11671 | /// IncompatiblePointerDiscardsQualifiers - The assignment |
11672 | /// discards qualifiers that we don't permit to be discarded, |
11673 | /// like address spaces. |
11674 | IncompatiblePointerDiscardsQualifiers, |
11675 | |
11676 | /// IncompatibleNestedPointerAddressSpaceMismatch - The assignment |
11677 | /// changes address spaces in nested pointer types which is not allowed. |
11678 | /// For instance, converting __private int ** to __generic int ** is |
11679 | /// illegal even though __private could be converted to __generic. |
11680 | IncompatibleNestedPointerAddressSpaceMismatch, |
11681 | |
11682 | /// IncompatibleNestedPointerQualifiers - The assignment is between two |
11683 | /// nested pointer types, and the qualifiers other than the first two |
11684 | /// levels differ e.g. char ** -> const char **, but we accept them as an |
11685 | /// extension. |
11686 | IncompatibleNestedPointerQualifiers, |
11687 | |
11688 | /// IncompatibleVectors - The assignment is between two vector types that |
11689 | /// have the same size, which we accept as an extension. |
11690 | IncompatibleVectors, |
11691 | |
11692 | /// IntToBlockPointer - The assignment converts an int to a block |
11693 | /// pointer. We disallow this. |
11694 | IntToBlockPointer, |
11695 | |
11696 | /// IncompatibleBlockPointer - The assignment is between two block |
11697 | /// pointers types that are not compatible. |
11698 | IncompatibleBlockPointer, |
11699 | |
11700 | /// IncompatibleObjCQualifiedId - The assignment is between a qualified |
11701 | /// id type and something else (that is incompatible with it). For example, |
11702 | /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. |
11703 | IncompatibleObjCQualifiedId, |
11704 | |
11705 | /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an |
11706 | /// object with __weak qualifier. |
11707 | IncompatibleObjCWeakRef, |
11708 | |
11709 | /// Incompatible - We reject this conversion outright, it is invalid to |
11710 | /// represent it in the AST. |
11711 | Incompatible |
11712 | }; |
11713 | |
11714 | /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the |
11715 | /// assignment conversion type specified by ConvTy. This returns true if the |
11716 | /// conversion was invalid or false if the conversion was accepted. |
11717 | bool DiagnoseAssignmentResult(AssignConvertType ConvTy, |
11718 | SourceLocation Loc, |
11719 | QualType DstType, QualType SrcType, |
11720 | Expr *SrcExpr, AssignmentAction Action, |
11721 | bool *Complained = nullptr); |
11722 | |
11723 | /// IsValueInFlagEnum - Determine if a value is allowed as part of a flag |
11724 | /// enum. If AllowMask is true, then we also allow the complement of a valid |
11725 | /// value, to be used as a mask. |
11726 | bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val, |
11727 | bool AllowMask) const; |
11728 | |
11729 | /// DiagnoseAssignmentEnum - Warn if assignment to enum is a constant |
11730 | /// integer not in the range of enum values. |
11731 | void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, |
11732 | Expr *SrcExpr); |
11733 | |
11734 | /// CheckAssignmentConstraints - Perform type checking for assignment, |
11735 | /// argument passing, variable initialization, and function return values. |
11736 | /// C99 6.5.16. |
11737 | AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, |
11738 | QualType LHSType, |
11739 | QualType RHSType); |
11740 | |
11741 | /// Check assignment constraints and optionally prepare for a conversion of |
11742 | /// the RHS to the LHS type. The conversion is prepared for if ConvertRHS |
11743 | /// is true. |
11744 | AssignConvertType CheckAssignmentConstraints(QualType LHSType, |
11745 | ExprResult &RHS, |
11746 | CastKind &Kind, |
11747 | bool ConvertRHS = true); |
11748 | |
11749 | /// Check assignment constraints for an assignment of RHS to LHSType. |
11750 | /// |
11751 | /// \param LHSType The destination type for the assignment. |
11752 | /// \param RHS The source expression for the assignment. |
11753 | /// \param Diagnose If \c true, diagnostics may be produced when checking |
11754 | /// for assignability. If a diagnostic is produced, \p RHS will be |
11755 | /// set to ExprError(). Note that this function may still return |
11756 | /// without producing a diagnostic, even for an invalid assignment. |
11757 | /// \param DiagnoseCFAudited If \c true, the target is a function parameter |
11758 | /// in an audited Core Foundation API and does not need to be checked |
11759 | /// for ARC retain issues. |
11760 | /// \param ConvertRHS If \c true, \p RHS will be updated to model the |
11761 | /// conversions necessary to perform the assignment. If \c false, |
11762 | /// \p Diagnose must also be \c false. |
11763 | AssignConvertType CheckSingleAssignmentConstraints( |
11764 | QualType LHSType, ExprResult &RHS, bool Diagnose = true, |
11765 | bool DiagnoseCFAudited = false, bool ConvertRHS = true); |
11766 | |
11767 | // If the lhs type is a transparent union, check whether we |
11768 | // can initialize the transparent union with the given expression. |
11769 | AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, |
11770 | ExprResult &RHS); |
11771 | |
11772 | bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); |
11773 | |
11774 | bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); |
11775 | |
11776 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
11777 | AssignmentAction Action, |
11778 | bool AllowExplicit = false); |
11779 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
11780 | const ImplicitConversionSequence& ICS, |
11781 | AssignmentAction Action, |
11782 | CheckedConversionKind CCK |
11783 | = CCK_ImplicitConversion); |
11784 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
11785 | const StandardConversionSequence& SCS, |
11786 | AssignmentAction Action, |
11787 | CheckedConversionKind CCK); |
11788 | |
11789 | ExprResult PerformQualificationConversion( |
11790 | Expr *E, QualType Ty, ExprValueKind VK = VK_PRValue, |
11791 | CheckedConversionKind CCK = CCK_ImplicitConversion); |
11792 | |
11793 | /// the following "Check" methods will return a valid/converted QualType |
11794 | /// or a null QualType (indicating an error diagnostic was issued). |
11795 | |
11796 | /// type checking binary operators (subroutines of CreateBuiltinBinOp). |
11797 | QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS, |
11798 | ExprResult &RHS); |
11799 | QualType InvalidLogicalVectorOperands(SourceLocation Loc, ExprResult &LHS, |
11800 | ExprResult &RHS); |
11801 | QualType CheckPointerToMemberOperands( // C++ 5.5 |
11802 | ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, |
11803 | SourceLocation OpLoc, bool isIndirect); |
11804 | QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
11805 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign, |
11806 | bool IsDivide); |
11807 | QualType CheckRemainderOperands( // C99 6.5.5 |
11808 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
11809 | bool IsCompAssign = false); |
11810 | QualType CheckAdditionOperands( // C99 6.5.6 |
11811 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
11812 | BinaryOperatorKind Opc, QualType* CompLHSTy = nullptr); |
11813 | QualType CheckSubtractionOperands( // C99 6.5.6 |
11814 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
11815 | QualType* CompLHSTy = nullptr); |
11816 | QualType CheckShiftOperands( // C99 6.5.7 |
11817 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
11818 | BinaryOperatorKind Opc, bool IsCompAssign = false); |
11819 | void CheckPtrComparisonWithNullChar(ExprResult &E, ExprResult &NullE); |
11820 | QualType CheckCompareOperands( // C99 6.5.8/9 |
11821 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
11822 | BinaryOperatorKind Opc); |
11823 | QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
11824 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
11825 | BinaryOperatorKind Opc); |
11826 | QualType CheckLogicalOperands( // C99 6.5.[13,14] |
11827 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
11828 | BinaryOperatorKind Opc); |
11829 | // CheckAssignmentOperands is used for both simple and compound assignment. |
11830 | // For simple assignment, pass both expressions and a null converted type. |
11831 | // For compound assignment, pass both expressions and the converted type. |
11832 | QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] |
11833 | Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType); |
11834 | |
11835 | ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc, |
11836 | UnaryOperatorKind Opcode, Expr *Op); |
11837 | ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc, |
11838 | BinaryOperatorKind Opcode, |
11839 | Expr *LHS, Expr *RHS); |
11840 | ExprResult checkPseudoObjectRValue(Expr *E); |
11841 | Expr *recreateSyntacticForm(PseudoObjectExpr *E); |
11842 | |
11843 | QualType CheckConditionalOperands( // C99 6.5.15 |
11844 | ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, |
11845 | ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc); |
11846 | QualType CXXCheckConditionalOperands( // C++ 5.16 |
11847 | ExprResult &cond, ExprResult &lhs, ExprResult &rhs, |
11848 | ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); |
11849 | QualType CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS, |
11850 | ExprResult &RHS, |
11851 | SourceLocation QuestionLoc); |
11852 | QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, |
11853 | bool ConvertArgs = true); |
11854 | QualType FindCompositePointerType(SourceLocation Loc, |
11855 | ExprResult &E1, ExprResult &E2, |
11856 | bool ConvertArgs = true) { |
11857 | Expr *E1Tmp = E1.get(), *E2Tmp = E2.get(); |
11858 | QualType Composite = |
11859 | FindCompositePointerType(Loc, E1Tmp, E2Tmp, ConvertArgs); |
11860 | E1 = E1Tmp; |
11861 | E2 = E2Tmp; |
11862 | return Composite; |
11863 | } |
11864 | |
11865 | QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, |
11866 | SourceLocation QuestionLoc); |
11867 | |
11868 | bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr, |
11869 | SourceLocation QuestionLoc); |
11870 | |
11871 | void DiagnoseAlwaysNonNullPointer(Expr *E, |
11872 | Expr::NullPointerConstantKind NullType, |
11873 | bool IsEqual, SourceRange Range); |
11874 | |
11875 | /// type checking for vector binary operators. |
11876 | QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS, |
11877 | SourceLocation Loc, bool IsCompAssign, |
11878 | bool AllowBothBool, bool AllowBoolConversion); |
11879 | QualType GetSignedVectorType(QualType V); |
11880 | QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, |
11881 | SourceLocation Loc, |
11882 | BinaryOperatorKind Opc); |
11883 | QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, |
11884 | SourceLocation Loc); |
11885 | |
11886 | /// Type checking for matrix binary operators. |
11887 | QualType CheckMatrixElementwiseOperands(ExprResult &LHS, ExprResult &RHS, |
11888 | SourceLocation Loc, |
11889 | bool IsCompAssign); |
11890 | QualType CheckMatrixMultiplyOperands(ExprResult &LHS, ExprResult &RHS, |
11891 | SourceLocation Loc, bool IsCompAssign); |
11892 | |
11893 | bool isValidSveBitcast(QualType srcType, QualType destType); |
11894 | |
11895 | bool areMatrixTypesOfTheSameDimension(QualType srcTy, QualType destTy); |
11896 | |
11897 | bool areVectorTypesSameSize(QualType srcType, QualType destType); |
11898 | bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType); |
11899 | bool isLaxVectorConversion(QualType srcType, QualType destType); |
11900 | |
11901 | /// type checking declaration initializers (C99 6.7.8) |
11902 | bool CheckForConstantInitializer(Expr *e, QualType t); |
11903 | |
11904 | // type checking C++ declaration initializers (C++ [dcl.init]). |
11905 | |
11906 | /// ReferenceCompareResult - Expresses the result of comparing two |
11907 | /// types (cv1 T1 and cv2 T2) to determine their compatibility for the |
11908 | /// purposes of initialization by reference (C++ [dcl.init.ref]p4). |
11909 | enum ReferenceCompareResult { |
11910 | /// Ref_Incompatible - The two types are incompatible, so direct |
11911 | /// reference binding is not possible. |
11912 | Ref_Incompatible = 0, |
11913 | /// Ref_Related - The two types are reference-related, which means |
11914 | /// that their unqualified forms (T1 and T2) are either the same |
11915 | /// or T1 is a base class of T2. |
11916 | Ref_Related, |
11917 | /// Ref_Compatible - The two types are reference-compatible. |
11918 | Ref_Compatible |
11919 | }; |
11920 | |
11921 | // Fake up a scoped enumeration that still contextually converts to bool. |
11922 | struct ReferenceConversionsScope { |
11923 | /// The conversions that would be performed on an lvalue of type T2 when |
11924 | /// binding a reference of type T1 to it, as determined when evaluating |
11925 | /// whether T1 is reference-compatible with T2. |
11926 | enum ReferenceConversions { |
11927 | Qualification = 0x1, |
11928 | NestedQualification = 0x2, |
11929 | Function = 0x4, |
11930 | DerivedToBase = 0x8, |
11931 | ObjC = 0x10, |
11932 | ObjCLifetime = 0x20, |
11933 | |
11934 | LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/ObjCLifetime)LLVM_BITMASK_LARGEST_ENUMERATOR = ObjCLifetime |
11935 | }; |
11936 | }; |
11937 | using ReferenceConversions = ReferenceConversionsScope::ReferenceConversions; |
11938 | |
11939 | ReferenceCompareResult |
11940 | CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2, |
11941 | ReferenceConversions *Conv = nullptr); |
11942 | |
11943 | ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, |
11944 | Expr *CastExpr, CastKind &CastKind, |
11945 | ExprValueKind &VK, CXXCastPath &Path); |
11946 | |
11947 | /// Force an expression with unknown-type to an expression of the |
11948 | /// given type. |
11949 | ExprResult forceUnknownAnyToType(Expr *E, QualType ToType); |
11950 | |
11951 | /// Type-check an expression that's being passed to an |
11952 | /// __unknown_anytype parameter. |
11953 | ExprResult checkUnknownAnyArg(SourceLocation callLoc, |
11954 | Expr *result, QualType ¶mType); |
11955 | |
11956 | // CheckMatrixCast - Check type constraints for matrix casts. |
11957 | // We allow casting between matrixes of the same dimensions i.e. when they |
11958 | // have the same number of rows and column. Returns true if the cast is |
11959 | // invalid. |
11960 | bool CheckMatrixCast(SourceRange R, QualType DestTy, QualType SrcTy, |
11961 | CastKind &Kind); |
11962 | |
11963 | // CheckVectorCast - check type constraints for vectors. |
11964 | // Since vectors are an extension, there are no C standard reference for this. |
11965 | // We allow casting between vectors and integer datatypes of the same size. |
11966 | // returns true if the cast is invalid |
11967 | bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, |
11968 | CastKind &Kind); |
11969 | |
11970 | /// Prepare `SplattedExpr` for a vector splat operation, adding |
11971 | /// implicit casts if necessary. |
11972 | ExprResult prepareVectorSplat(QualType VectorTy, Expr *SplattedExpr); |
11973 | |
11974 | // CheckExtVectorCast - check type constraints for extended vectors. |
11975 | // Since vectors are an extension, there are no C standard reference for this. |
11976 | // We allow casting between vectors and integer datatypes of the same size, |
11977 | // or vectors and the element type of that vector. |
11978 | // returns the cast expr |
11979 | ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr, |
11980 | CastKind &Kind); |
11981 | |
11982 | ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, QualType Type, |
11983 | SourceLocation LParenLoc, |
11984 | Expr *CastExpr, |
11985 | SourceLocation RParenLoc); |
11986 | |
11987 | enum ARCConversionResult { ACR_okay, ACR_unbridged, ACR_error }; |
11988 | |
11989 | /// Checks for invalid conversions and casts between |
11990 | /// retainable pointers and other pointer kinds for ARC and Weak. |
11991 | ARCConversionResult CheckObjCConversion(SourceRange castRange, |
11992 | QualType castType, Expr *&op, |
11993 | CheckedConversionKind CCK, |
11994 | bool Diagnose = true, |
11995 | bool DiagnoseCFAudited = false, |
11996 | BinaryOperatorKind Opc = BO_PtrMemD |
11997 | ); |
11998 | |
11999 | Expr *stripARCUnbridgedCast(Expr *e); |
12000 | void diagnoseARCUnbridgedCast(Expr *e); |
12001 | |
12002 | bool CheckObjCARCUnavailableWeakConversion(QualType castType, |
12003 | QualType ExprType); |
12004 | |
12005 | /// checkRetainCycles - Check whether an Objective-C message send |
12006 | /// might create an obvious retain cycle. |
12007 | void checkRetainCycles(ObjCMessageExpr *msg); |
12008 | void checkRetainCycles(Expr *receiver, Expr *argument); |
12009 | void checkRetainCycles(VarDecl *Var, Expr *Init); |
12010 | |
12011 | /// checkUnsafeAssigns - Check whether +1 expr is being assigned |
12012 | /// to weak/__unsafe_unretained type. |
12013 | bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); |
12014 | |
12015 | /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned |
12016 | /// to weak/__unsafe_unretained expression. |
12017 | void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); |
12018 | |
12019 | /// CheckMessageArgumentTypes - Check types in an Obj-C message send. |
12020 | /// \param Method - May be null. |
12021 | /// \param [out] ReturnType - The return type of the send. |
12022 | /// \return true iff there were any incompatible types. |
12023 | bool CheckMessageArgumentTypes(const Expr *Receiver, QualType ReceiverType, |
12024 | MultiExprArg Args, Selector Sel, |
12025 | ArrayRef<SourceLocation> SelectorLocs, |
12026 | ObjCMethodDecl *Method, bool isClassMessage, |
12027 | bool isSuperMessage, SourceLocation lbrac, |
12028 | SourceLocation rbrac, SourceRange RecRange, |
12029 | QualType &ReturnType, ExprValueKind &VK); |
12030 | |
12031 | /// Determine the result of a message send expression based on |
12032 | /// the type of the receiver, the method expected to receive the message, |
12033 | /// and the form of the message send. |
12034 | QualType getMessageSendResultType(const Expr *Receiver, QualType ReceiverType, |
12035 | ObjCMethodDecl *Method, bool isClassMessage, |
12036 | bool isSuperMessage); |
12037 | |
12038 | /// If the given expression involves a message send to a method |
12039 | /// with a related result type, emit a note describing what happened. |
12040 | void EmitRelatedResultTypeNote(const Expr *E); |
12041 | |
12042 | /// Given that we had incompatible pointer types in a return |
12043 | /// statement, check whether we're in a method with a related result |
12044 | /// type, and if so, emit a note describing what happened. |
12045 | void EmitRelatedResultTypeNoteForReturn(QualType destType); |
12046 | |
12047 | class ConditionResult { |
12048 | Decl *ConditionVar; |
12049 | FullExprArg Condition; |
12050 | bool Invalid; |
12051 | bool HasKnownValue; |
12052 | bool KnownValue; |
12053 | |
12054 | friend class Sema; |
12055 | ConditionResult(Sema &S, Decl *ConditionVar, FullExprArg Condition, |
12056 | bool IsConstexpr) |
12057 | : ConditionVar(ConditionVar), Condition(Condition), Invalid(false), |
12058 | HasKnownValue(IsConstexpr && Condition.get() && |
12059 | !Condition.get()->isValueDependent()), |
12060 | KnownValue(HasKnownValue && |
12061 | !!Condition.get()->EvaluateKnownConstInt(S.Context)) {} |
12062 | explicit ConditionResult(bool Invalid) |
12063 | : ConditionVar(nullptr), Condition(nullptr), Invalid(Invalid), |
12064 | HasKnownValue(false), KnownValue(false) {} |
12065 | |
12066 | public: |
12067 | ConditionResult() : ConditionResult(false) {} |
12068 | bool isInvalid() const { return Invalid; } |
12069 | std::pair<VarDecl *, Expr *> get() const { |
12070 | return std::make_pair(cast_or_null<VarDecl>(ConditionVar), |
12071 | Condition.get()); |
12072 | } |
12073 | llvm::Optional<bool> getKnownValue() const { |
12074 | if (!HasKnownValue) |
12075 | return None; |
12076 | return KnownValue; |
12077 | } |
12078 | }; |
12079 | static ConditionResult ConditionError() { return ConditionResult(true); } |
12080 | |
12081 | enum class ConditionKind { |
12082 | Boolean, ///< A boolean condition, from 'if', 'while', 'for', or 'do'. |
12083 | ConstexprIf, ///< A constant boolean condition from 'if constexpr'. |
12084 | Switch ///< An integral condition for a 'switch' statement. |
12085 | }; |
12086 | QualType PreferredConditionType(ConditionKind K) const { |
12087 | return K == ConditionKind::Switch ? Context.IntTy : Context.BoolTy; |
12088 | } |
12089 | |
12090 | ConditionResult ActOnCondition(Scope *S, SourceLocation Loc, Expr *SubExpr, |
12091 | ConditionKind CK, bool MissingOK = false); |
12092 | |
12093 | ConditionResult ActOnConditionVariable(Decl *ConditionVar, |
12094 | SourceLocation StmtLoc, |
12095 | ConditionKind CK); |
12096 | |
12097 | DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); |
12098 | |
12099 | ExprResult CheckConditionVariable(VarDecl *ConditionVar, |
12100 | SourceLocation StmtLoc, |
12101 | ConditionKind CK); |
12102 | ExprResult CheckSwitchCondition(SourceLocation SwitchLoc, Expr *Cond); |
12103 | |
12104 | /// CheckBooleanCondition - Diagnose problems involving the use of |
12105 | /// the given expression as a boolean condition (e.g. in an if |
12106 | /// statement). Also performs the standard function and array |
12107 | /// decays, possibly changing the input variable. |
12108 | /// |
12109 | /// \param Loc - A location associated with the condition, e.g. the |
12110 | /// 'if' keyword. |
12111 | /// \return true iff there were any errors |
12112 | ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E, |
12113 | bool IsConstexpr = false); |
12114 | |
12115 | /// ActOnExplicitBoolSpecifier - Build an ExplicitSpecifier from an expression |
12116 | /// found in an explicit(bool) specifier. |
12117 | ExplicitSpecifier ActOnExplicitBoolSpecifier(Expr *E); |
12118 | |
12119 | /// tryResolveExplicitSpecifier - Attempt to resolve the explict specifier. |
12120 | /// Returns true if the explicit specifier is now resolved. |
12121 | bool tryResolveExplicitSpecifier(ExplicitSpecifier &ExplicitSpec); |
12122 | |
12123 | /// DiagnoseAssignmentAsCondition - Given that an expression is |
12124 | /// being used as a boolean condition, warn if it's an assignment. |
12125 | void DiagnoseAssignmentAsCondition(Expr *E); |
12126 | |
12127 | /// Redundant parentheses over an equality comparison can indicate |
12128 | /// that the user intended an assignment used as condition. |
12129 | void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE); |
12130 | |
12131 | /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. |
12132 | ExprResult CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr = false); |
12133 | |
12134 | /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have |
12135 | /// the specified width and sign. If an overflow occurs, detect it and emit |
12136 | /// the specified diagnostic. |
12137 | void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, |
12138 | unsigned NewWidth, bool NewSign, |
12139 | SourceLocation Loc, unsigned DiagID); |
12140 | |
12141 | /// Checks that the Objective-C declaration is declared in the global scope. |
12142 | /// Emits an error and marks the declaration as invalid if it's not declared |
12143 | /// in the global scope. |
12144 | bool CheckObjCDeclScope(Decl *D); |
12145 | |
12146 | /// Abstract base class used for diagnosing integer constant |
12147 | /// expression violations. |
12148 | class VerifyICEDiagnoser { |
12149 | public: |
12150 | bool Suppress; |
12151 | |
12152 | VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) { } |
12153 | |
12154 | virtual SemaDiagnosticBuilder |
12155 | diagnoseNotICEType(Sema &S, SourceLocation Loc, QualType T); |
12156 | virtual SemaDiagnosticBuilder diagnoseNotICE(Sema &S, |
12157 | SourceLocation Loc) = 0; |
12158 | virtual SemaDiagnosticBuilder diagnoseFold(Sema &S, SourceLocation Loc); |
12159 | virtual ~VerifyICEDiagnoser() {} |
12160 | }; |
12161 | |
12162 | enum AllowFoldKind { |
12163 | NoFold, |
12164 | AllowFold, |
12165 | }; |
12166 | |
12167 | /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE, |
12168 | /// and reports the appropriate diagnostics. Returns false on success. |
12169 | /// Can optionally return the value of the expression. |
12170 | ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
12171 | VerifyICEDiagnoser &Diagnoser, |
12172 | AllowFoldKind CanFold = NoFold); |
12173 | ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
12174 | unsigned DiagID, |
12175 | AllowFoldKind CanFold = NoFold); |
12176 | ExprResult VerifyIntegerConstantExpression(Expr *E, |
12177 | llvm::APSInt *Result = nullptr, |
12178 | AllowFoldKind CanFold = NoFold); |
12179 | ExprResult VerifyIntegerConstantExpression(Expr *E, |
12180 | AllowFoldKind CanFold = NoFold) { |
12181 | return VerifyIntegerConstantExpression(E, nullptr, CanFold); |
12182 | } |
12183 | |
12184 | /// VerifyBitField - verifies that a bit field expression is an ICE and has |
12185 | /// the correct width, and that the field type is valid. |
12186 | /// Returns false on success. |
12187 | /// Can optionally return whether the bit-field is of width 0 |
12188 | ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, |
12189 | QualType FieldTy, bool IsMsStruct, |
12190 | Expr *BitWidth, bool *ZeroWidth = nullptr); |
12191 | |
12192 | private: |
12193 | unsigned ForceCUDAHostDeviceDepth = 0; |
12194 | |
12195 | public: |
12196 | /// Increments our count of the number of times we've seen a pragma forcing |
12197 | /// functions to be __host__ __device__. So long as this count is greater |
12198 | /// than zero, all functions encountered will be __host__ __device__. |
12199 | void PushForceCUDAHostDevice(); |
12200 | |
12201 | /// Decrements our count of the number of times we've seen a pragma forcing |
12202 | /// functions to be __host__ __device__. Returns false if the count is 0 |
12203 | /// before incrementing, so you can emit an error. |
12204 | bool PopForceCUDAHostDevice(); |
12205 | |
12206 | /// Diagnostics that are emitted only if we discover that the given function |
12207 | /// must be codegen'ed. Because handling these correctly adds overhead to |
12208 | /// compilation, this is currently only enabled for CUDA compilations. |
12209 | llvm::DenseMap<CanonicalDeclPtr<FunctionDecl>, |
12210 | std::vector<PartialDiagnosticAt>> |
12211 | DeviceDeferredDiags; |
12212 | |
12213 | /// A pair of a canonical FunctionDecl and a SourceLocation. When used as the |
12214 | /// key in a hashtable, both the FD and location are hashed. |
12215 | struct FunctionDeclAndLoc { |
12216 | CanonicalDeclPtr<FunctionDecl> FD; |
12217 | SourceLocation Loc; |
12218 | }; |
12219 | |
12220 | /// FunctionDecls and SourceLocations for which CheckCUDACall has emitted a |
12221 | /// (maybe deferred) "bad call" diagnostic. We use this to avoid emitting the |
12222 | /// same deferred diag twice. |
12223 | llvm::DenseSet<FunctionDeclAndLoc> LocsWithCUDACallDiags; |
12224 | |
12225 | /// An inverse call graph, mapping known-emitted functions to one of their |
12226 | /// known-emitted callers (plus the location of the call). |
12227 | /// |
12228 | /// Functions that we can tell a priori must be emitted aren't added to this |
12229 | /// map. |
12230 | llvm::DenseMap</* Callee = */ CanonicalDeclPtr<FunctionDecl>, |
12231 | /* Caller = */ FunctionDeclAndLoc> |
12232 | DeviceKnownEmittedFns; |
12233 | |
12234 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
12235 | /// context is "used as device code". |
12236 | /// |
12237 | /// - If CurContext is a __host__ function, does not emit any diagnostics |
12238 | /// unless \p EmitOnBothSides is true. |
12239 | /// - If CurContext is a __device__ or __global__ function, emits the |
12240 | /// diagnostics immediately. |
12241 | /// - If CurContext is a __host__ __device__ function and we are compiling for |
12242 | /// the device, creates a diagnostic which is emitted if and when we realize |
12243 | /// that the function will be codegen'ed. |
12244 | /// |
12245 | /// Example usage: |
12246 | /// |
12247 | /// // Variable-length arrays are not allowed in CUDA device code. |
12248 | /// if (CUDADiagIfDeviceCode(Loc, diag::err_cuda_vla) << CurrentCUDATarget()) |
12249 | /// return ExprError(); |
12250 | /// // Otherwise, continue parsing as normal. |
12251 | SemaDiagnosticBuilder CUDADiagIfDeviceCode(SourceLocation Loc, |
12252 | unsigned DiagID); |
12253 | |
12254 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
12255 | /// context is "used as host code". |
12256 | /// |
12257 | /// Same as CUDADiagIfDeviceCode, with "host" and "device" switched. |
12258 | SemaDiagnosticBuilder CUDADiagIfHostCode(SourceLocation Loc, unsigned DiagID); |
12259 | |
12260 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
12261 | /// context is "used as device code". |
12262 | /// |
12263 | /// - If CurContext is a `declare target` function or it is known that the |
12264 | /// function is emitted for the device, emits the diagnostics immediately. |
12265 | /// - If CurContext is a non-`declare target` function and we are compiling |
12266 | /// for the device, creates a diagnostic which is emitted if and when we |
12267 | /// realize that the function will be codegen'ed. |
12268 | /// |
12269 | /// Example usage: |
12270 | /// |
12271 | /// // Variable-length arrays are not allowed in NVPTX device code. |
12272 | /// if (diagIfOpenMPDeviceCode(Loc, diag::err_vla_unsupported)) |
12273 | /// return ExprError(); |
12274 | /// // Otherwise, continue parsing as normal. |
12275 | SemaDiagnosticBuilder |
12276 | diagIfOpenMPDeviceCode(SourceLocation Loc, unsigned DiagID, FunctionDecl *FD); |
12277 | |
12278 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
12279 | /// context is "used as host code". |
12280 | /// |
12281 | /// - If CurContext is a `declare target` function or it is known that the |
12282 | /// function is emitted for the host, emits the diagnostics immediately. |
12283 | /// - If CurContext is a non-host function, just ignore it. |
12284 | /// |
12285 | /// Example usage: |
12286 | /// |
12287 | /// // Variable-length arrays are not allowed in NVPTX device code. |
12288 | /// if (diagIfOpenMPHostode(Loc, diag::err_vla_unsupported)) |
12289 | /// return ExprError(); |
12290 | /// // Otherwise, continue parsing as normal. |
12291 | SemaDiagnosticBuilder diagIfOpenMPHostCode(SourceLocation Loc, |
12292 | unsigned DiagID, FunctionDecl *FD); |
12293 | |
12294 | SemaDiagnosticBuilder targetDiag(SourceLocation Loc, unsigned DiagID, |
12295 | FunctionDecl *FD = nullptr); |
12296 | SemaDiagnosticBuilder targetDiag(SourceLocation Loc, |
12297 | const PartialDiagnostic &PD, |
12298 | FunctionDecl *FD = nullptr) { |
12299 | return targetDiag(Loc, PD.getDiagID(), FD) << PD; |
12300 | } |
12301 | |
12302 | /// Check if the type is allowed to be used for the current target. |
12303 | void checkTypeSupport(QualType Ty, SourceLocation Loc, |
12304 | ValueDecl *D = nullptr); |
12305 | |
12306 | enum CUDAFunctionTarget { |
12307 | CFT_Device, |
12308 | CFT_Global, |
12309 | CFT_Host, |
12310 | CFT_HostDevice, |
12311 | CFT_InvalidTarget |
12312 | }; |
12313 | |
12314 | /// Determines whether the given function is a CUDA device/host/kernel/etc. |
12315 | /// function. |
12316 | /// |
12317 | /// Use this rather than examining the function's attributes yourself -- you |
12318 | /// will get it wrong. Returns CFT_Host if D is null. |
12319 | CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D, |
12320 | bool IgnoreImplicitHDAttr = false); |
12321 | CUDAFunctionTarget IdentifyCUDATarget(const ParsedAttributesView &Attrs); |
12322 | |
12323 | enum CUDAVariableTarget { |
12324 | CVT_Device, /// Emitted on device side with a shadow variable on host side |
12325 | CVT_Host, /// Emitted on host side only |
12326 | CVT_Both, /// Emitted on both sides with different addresses |
12327 | CVT_Unified, /// Emitted as a unified address, e.g. managed variables |
12328 | }; |
12329 | /// Determines whether the given variable is emitted on host or device side. |
12330 | CUDAVariableTarget IdentifyCUDATarget(const VarDecl *D); |
12331 | |
12332 | /// Gets the CUDA target for the current context. |
12333 | CUDAFunctionTarget CurrentCUDATarget() { |
12334 | return IdentifyCUDATarget(dyn_cast<FunctionDecl>(CurContext)); |
12335 | } |
12336 | |
12337 | static bool isCUDAImplicitHostDeviceFunction(const FunctionDecl *D); |
12338 | |
12339 | // CUDA function call preference. Must be ordered numerically from |
12340 | // worst to best. |
12341 | enum CUDAFunctionPreference { |
12342 | CFP_Never, // Invalid caller/callee combination. |
12343 | CFP_WrongSide, // Calls from host-device to host or device |
12344 | // function that do not match current compilation |
12345 | // mode. |
12346 | CFP_HostDevice, // Any calls to host/device functions. |
12347 | CFP_SameSide, // Calls from host-device to host or device |
12348 | // function matching current compilation mode. |
12349 | CFP_Native, // host-to-host or device-to-device calls. |
12350 | }; |
12351 | |
12352 | /// Identifies relative preference of a given Caller/Callee |
12353 | /// combination, based on their host/device attributes. |
12354 | /// \param Caller function which needs address of \p Callee. |
12355 | /// nullptr in case of global context. |
12356 | /// \param Callee target function |
12357 | /// |
12358 | /// \returns preference value for particular Caller/Callee combination. |
12359 | CUDAFunctionPreference IdentifyCUDAPreference(const FunctionDecl *Caller, |
12360 | const FunctionDecl *Callee); |
12361 | |
12362 | /// Determines whether Caller may invoke Callee, based on their CUDA |
12363 | /// host/device attributes. Returns false if the call is not allowed. |
12364 | /// |
12365 | /// Note: Will return true for CFP_WrongSide calls. These may appear in |
12366 | /// semantically correct CUDA programs, but only if they're never codegen'ed. |
12367 | bool IsAllowedCUDACall(const FunctionDecl *Caller, |
12368 | const FunctionDecl *Callee) { |
12369 | return IdentifyCUDAPreference(Caller, Callee) != CFP_Never; |
12370 | } |
12371 | |
12372 | /// May add implicit CUDAHostAttr and CUDADeviceAttr attributes to FD, |
12373 | /// depending on FD and the current compilation settings. |
12374 | void maybeAddCUDAHostDeviceAttrs(FunctionDecl *FD, |
12375 | const LookupResult &Previous); |
12376 | |
12377 | /// May add implicit CUDAConstantAttr attribute to VD, depending on VD |
12378 | /// and current compilation settings. |
12379 | void MaybeAddCUDAConstantAttr(VarDecl *VD); |
12380 | |
12381 | public: |
12382 | /// Check whether we're allowed to call Callee from the current context. |
12383 | /// |
12384 | /// - If the call is never allowed in a semantically-correct program |
12385 | /// (CFP_Never), emits an error and returns false. |
12386 | /// |
12387 | /// - If the call is allowed in semantically-correct programs, but only if |
12388 | /// it's never codegen'ed (CFP_WrongSide), creates a deferred diagnostic to |
12389 | /// be emitted if and when the caller is codegen'ed, and returns true. |
12390 | /// |
12391 | /// Will only create deferred diagnostics for a given SourceLocation once, |
12392 | /// so you can safely call this multiple times without generating duplicate |
12393 | /// deferred errors. |
12394 | /// |
12395 | /// - Otherwise, returns true without emitting any diagnostics. |
12396 | bool CheckCUDACall(SourceLocation Loc, FunctionDecl *Callee); |
12397 | |
12398 | void CUDACheckLambdaCapture(CXXMethodDecl *D, const sema::Capture &Capture); |
12399 | |
12400 | /// Set __device__ or __host__ __device__ attributes on the given lambda |
12401 | /// operator() method. |
12402 | /// |
12403 | /// CUDA lambdas by default is host device function unless it has explicit |
12404 | /// host or device attribute. |
12405 | void CUDASetLambdaAttrs(CXXMethodDecl *Method); |
12406 | |
12407 | /// Finds a function in \p Matches with highest calling priority |
12408 | /// from \p Caller context and erases all functions with lower |
12409 | /// calling priority. |
12410 | void EraseUnwantedCUDAMatches( |
12411 | const FunctionDecl *Caller, |
12412 | SmallVectorImpl<std::pair<DeclAccessPair, FunctionDecl *>> &Matches); |
12413 | |
12414 | /// Given a implicit special member, infer its CUDA target from the |
12415 | /// calls it needs to make to underlying base/field special members. |
12416 | /// \param ClassDecl the class for which the member is being created. |
12417 | /// \param CSM the kind of special member. |
12418 | /// \param MemberDecl the special member itself. |
12419 | /// \param ConstRHS true if this is a copy operation with a const object on |
12420 | /// its RHS. |
12421 | /// \param Diagnose true if this call should emit diagnostics. |
12422 | /// \return true if there was an error inferring. |
12423 | /// The result of this call is implicit CUDA target attribute(s) attached to |
12424 | /// the member declaration. |
12425 | bool inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl, |
12426 | CXXSpecialMember CSM, |
12427 | CXXMethodDecl *MemberDecl, |
12428 | bool ConstRHS, |
12429 | bool Diagnose); |
12430 | |
12431 | /// \return true if \p CD can be considered empty according to CUDA |
12432 | /// (E.2.3.1 in CUDA 7.5 Programming guide). |
12433 | bool isEmptyCudaConstructor(SourceLocation Loc, CXXConstructorDecl *CD); |
12434 | bool isEmptyCudaDestructor(SourceLocation Loc, CXXDestructorDecl *CD); |
12435 | |
12436 | // \brief Checks that initializers of \p Var satisfy CUDA restrictions. In |
12437 | // case of error emits appropriate diagnostic and invalidates \p Var. |
12438 | // |
12439 | // \details CUDA allows only empty constructors as initializers for global |
12440 | // variables (see E.2.3.1, CUDA 7.5). The same restriction also applies to all |
12441 | // __shared__ variables whether they are local or not (they all are implicitly |
12442 | // static in CUDA). One exception is that CUDA allows constant initializers |
12443 | // for __constant__ and __device__ variables. |
12444 | void checkAllowedCUDAInitializer(VarDecl *VD); |
12445 | |
12446 | /// Check whether NewFD is a valid overload for CUDA. Emits |
12447 | /// diagnostics and invalidates NewFD if not. |
12448 | void checkCUDATargetOverload(FunctionDecl *NewFD, |
12449 | const LookupResult &Previous); |
12450 | /// Copies target attributes from the template TD to the function FD. |
12451 | void inheritCUDATargetAttrs(FunctionDecl *FD, const FunctionTemplateDecl &TD); |
12452 | |
12453 | /// Returns the name of the launch configuration function. This is the name |
12454 | /// of the function that will be called to configure kernel call, with the |
12455 | /// parameters specified via <<<>>>. |
12456 | std::string getCudaConfigureFuncName() const; |
12457 | |
12458 | /// \name Code completion |
12459 | //@{ |
12460 | /// Describes the context in which code completion occurs. |
12461 | enum ParserCompletionContext { |
12462 | /// Code completion occurs at top-level or namespace context. |
12463 | PCC_Namespace, |
12464 | /// Code completion occurs within a class, struct, or union. |
12465 | PCC_Class, |
12466 | /// Code completion occurs within an Objective-C interface, protocol, |
12467 | /// or category. |
12468 | PCC_ObjCInterface, |
12469 | /// Code completion occurs within an Objective-C implementation or |
12470 | /// category implementation |
12471 | PCC_ObjCImplementation, |
12472 | /// Code completion occurs within the list of instance variables |
12473 | /// in an Objective-C interface, protocol, category, or implementation. |
12474 | PCC_ObjCInstanceVariableList, |
12475 | /// Code completion occurs following one or more template |
12476 | /// headers. |
12477 | PCC_Template, |
12478 | /// Code completion occurs following one or more template |
12479 | /// headers within a class. |
12480 | PCC_MemberTemplate, |
12481 | /// Code completion occurs within an expression. |
12482 | PCC_Expression, |
12483 | /// Code completion occurs within a statement, which may |
12484 | /// also be an expression or a declaration. |
12485 | PCC_Statement, |
12486 | /// Code completion occurs at the beginning of the |
12487 | /// initialization statement (or expression) in a for loop. |
12488 | PCC_ForInit, |
12489 | /// Code completion occurs within the condition of an if, |
12490 | /// while, switch, or for statement. |
12491 | PCC_Condition, |
12492 | /// Code completion occurs within the body of a function on a |
12493 | /// recovery path, where we do not have a specific handle on our position |
12494 | /// in the grammar. |
12495 | PCC_RecoveryInFunction, |
12496 | /// Code completion occurs where only a type is permitted. |
12497 | PCC_Type, |
12498 | /// Code completion occurs in a parenthesized expression, which |
12499 | /// might also be a type cast. |
12500 | PCC_ParenthesizedExpression, |
12501 | /// Code completion occurs within a sequence of declaration |
12502 | /// specifiers within a function, method, or block. |
12503 | PCC_LocalDeclarationSpecifiers |
12504 | }; |
12505 | |
12506 | void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path); |
12507 | void CodeCompleteOrdinaryName(Scope *S, |
12508 | ParserCompletionContext CompletionContext); |
12509 | void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, |
12510 | bool AllowNonIdentifiers, |
12511 | bool AllowNestedNameSpecifiers); |
12512 | |
12513 | struct CodeCompleteExpressionData; |
12514 | void CodeCompleteExpression(Scope *S, |
12515 | const CodeCompleteExpressionData &Data); |
12516 | void CodeCompleteExpression(Scope *S, QualType PreferredType, |
12517 | bool IsParenthesized = false); |
12518 | void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase, |
12519 | SourceLocation OpLoc, bool IsArrow, |
12520 | bool IsBaseExprStatement, |
12521 | QualType PreferredType); |
12522 | void CodeCompletePostfixExpression(Scope *S, ExprResult LHS, |
12523 | QualType PreferredType); |
12524 | void CodeCompleteTag(Scope *S, unsigned TagSpec); |
12525 | void CodeCompleteTypeQualifiers(DeclSpec &DS); |
12526 | void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D, |
12527 | const VirtSpecifiers *VS = nullptr); |
12528 | void CodeCompleteBracketDeclarator(Scope *S); |
12529 | void CodeCompleteCase(Scope *S); |
12530 | enum class AttributeCompletion { |
12531 | Attribute, |
12532 | Scope, |
12533 | None, |
12534 | }; |
12535 | void CodeCompleteAttribute( |
12536 | AttributeCommonInfo::Syntax Syntax, |
12537 | AttributeCompletion Completion = AttributeCompletion::Attribute, |
12538 | const IdentifierInfo *Scope = nullptr); |
12539 | /// Determines the preferred type of the current function argument, by |
12540 | /// examining the signatures of all possible overloads. |
12541 | /// Returns null if unknown or ambiguous, or if code completion is off. |
12542 | /// |
12543 | /// If the code completion point has been reached, also reports the function |
12544 | /// signatures that were considered. |
12545 | /// |
12546 | /// FIXME: rename to GuessCallArgumentType to reduce confusion. |
12547 | QualType ProduceCallSignatureHelp(Expr *Fn, ArrayRef<Expr *> Args, |
12548 | SourceLocation OpenParLoc); |
12549 | QualType ProduceConstructorSignatureHelp(QualType Type, SourceLocation Loc, |
12550 | ArrayRef<Expr *> Args, |
12551 | SourceLocation OpenParLoc, |
12552 | bool Braced); |
12553 | QualType ProduceCtorInitMemberSignatureHelp( |
12554 | Decl *ConstructorDecl, CXXScopeSpec SS, ParsedType TemplateTypeTy, |
12555 | ArrayRef<Expr *> ArgExprs, IdentifierInfo *II, SourceLocation OpenParLoc, |
12556 | bool Braced); |
12557 | QualType ProduceTemplateArgumentSignatureHelp( |
12558 | TemplateTy, ArrayRef<ParsedTemplateArgument>, SourceLocation LAngleLoc); |
12559 | void CodeCompleteInitializer(Scope *S, Decl *D); |
12560 | /// Trigger code completion for a record of \p BaseType. \p InitExprs are |
12561 | /// expressions in the initializer list seen so far and \p D is the current |
12562 | /// Designation being parsed. |
12563 | void CodeCompleteDesignator(const QualType BaseType, |
12564 | llvm::ArrayRef<Expr *> InitExprs, |
12565 | const Designation &D); |
12566 | void CodeCompleteAfterIf(Scope *S, bool IsBracedThen); |
12567 | |
12568 | void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext, |
12569 | bool IsUsingDeclaration, QualType BaseType, |
12570 | QualType PreferredType); |
12571 | void CodeCompleteUsing(Scope *S); |
12572 | void CodeCompleteUsingDirective(Scope *S); |
12573 | void CodeCompleteNamespaceDecl(Scope *S); |
12574 | void CodeCompleteNamespaceAliasDecl(Scope *S); |
12575 | void CodeCompleteOperatorName(Scope *S); |
12576 | void CodeCompleteConstructorInitializer( |
12577 | Decl *Constructor, |
12578 | ArrayRef<CXXCtorInitializer *> Initializers); |
12579 | |
12580 | void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, |
12581 | bool AfterAmpersand); |
12582 | void CodeCompleteAfterFunctionEquals(Declarator &D); |
12583 | |
12584 | void CodeCompleteObjCAtDirective(Scope *S); |
12585 | void CodeCompleteObjCAtVisibility(Scope *S); |
12586 | void CodeCompleteObjCAtStatement(Scope *S); |
12587 | void CodeCompleteObjCAtExpression(Scope *S); |
12588 | void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); |
12589 | void CodeCompleteObjCPropertyGetter(Scope *S); |
12590 | void CodeCompleteObjCPropertySetter(Scope *S); |
12591 | void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, |
12592 | bool IsParameter); |
12593 | void CodeCompleteObjCMessageReceiver(Scope *S); |
12594 | void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, |
12595 | ArrayRef<IdentifierInfo *> SelIdents, |
12596 | bool AtArgumentExpression); |
12597 | void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, |
12598 | ArrayRef<IdentifierInfo *> SelIdents, |
12599 | bool AtArgumentExpression, |
12600 | bool IsSuper = false); |
12601 | void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, |
12602 | ArrayRef<IdentifierInfo *> SelIdents, |
12603 | bool AtArgumentExpression, |
12604 | ObjCInterfaceDecl *Super = nullptr); |
12605 | void CodeCompleteObjCForCollection(Scope *S, |
12606 | DeclGroupPtrTy IterationVar); |
12607 | void CodeCompleteObjCSelector(Scope *S, |
12608 | ArrayRef<IdentifierInfo *> SelIdents); |
12609 | void CodeCompleteObjCProtocolReferences( |
12610 | ArrayRef<IdentifierLocPair> Protocols); |
12611 | void CodeCompleteObjCProtocolDecl(Scope *S); |
12612 | void CodeCompleteObjCInterfaceDecl(Scope *S); |
12613 | void CodeCompleteObjCSuperclass(Scope *S, |
12614 | IdentifierInfo *ClassName, |
12615 | SourceLocation ClassNameLoc); |
12616 | void CodeCompleteObjCImplementationDecl(Scope *S); |
12617 | void CodeCompleteObjCInterfaceCategory(Scope *S, |
12618 | IdentifierInfo *ClassName, |
12619 | SourceLocation ClassNameLoc); |
12620 | void CodeCompleteObjCImplementationCategory(Scope *S, |
12621 | IdentifierInfo *ClassName, |
12622 | SourceLocation ClassNameLoc); |
12623 | void CodeCompleteObjCPropertyDefinition(Scope *S); |
12624 | void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, |
12625 | IdentifierInfo *PropertyName); |
12626 | void CodeCompleteObjCMethodDecl(Scope *S, Optional<bool> IsInstanceMethod, |
12627 | ParsedType ReturnType); |
12628 | void CodeCompleteObjCMethodDeclSelector(Scope *S, |
12629 | bool IsInstanceMethod, |
12630 | bool AtParameterName, |
12631 | ParsedType ReturnType, |
12632 | ArrayRef<IdentifierInfo *> SelIdents); |
12633 | void CodeCompleteObjCClassPropertyRefExpr(Scope *S, IdentifierInfo &ClassName, |
12634 | SourceLocation ClassNameLoc, |
12635 | bool IsBaseExprStatement); |
12636 | void CodeCompletePreprocessorDirective(bool InConditional); |
12637 | void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); |
12638 | void CodeCompletePreprocessorMacroName(bool IsDefinition); |
12639 | void CodeCompletePreprocessorExpression(); |
12640 | void CodeCompletePreprocessorMacroArgument(Scope *S, |
12641 | IdentifierInfo *Macro, |
12642 | MacroInfo *MacroInfo, |
12643 | unsigned Argument); |
12644 | void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled); |
12645 | void CodeCompleteNaturalLanguage(); |
12646 | void CodeCompleteAvailabilityPlatformName(); |
12647 | void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, |
12648 | CodeCompletionTUInfo &CCTUInfo, |
12649 | SmallVectorImpl<CodeCompletionResult> &Results); |
12650 | //@} |
12651 | |
12652 | //===--------------------------------------------------------------------===// |
12653 | // Extra semantic analysis beyond the C type system |
12654 | |
12655 | public: |
12656 | SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, |
12657 | unsigned ByteNo) const; |
12658 | |
12659 | private: |
12660 | void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, |
12661 | const ArraySubscriptExpr *ASE=nullptr, |
12662 | bool AllowOnePastEnd=true, bool IndexNegated=false); |
12663 | void CheckArrayAccess(const Expr *E); |
12664 | // Used to grab the relevant information from a FormatAttr and a |
12665 | // FunctionDeclaration. |
12666 | struct FormatStringInfo { |
12667 | unsigned FormatIdx; |
12668 | unsigned FirstDataArg; |
12669 | bool HasVAListArg; |
12670 | }; |
12671 | |
12672 | static bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember, |
12673 | FormatStringInfo *FSI); |
12674 | bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, |
12675 | const FunctionProtoType *Proto); |
12676 | bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc, |
12677 | ArrayRef<const Expr *> Args); |
12678 | bool CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall, |
12679 | const FunctionProtoType *Proto); |
12680 | bool CheckOtherCall(CallExpr *TheCall, const FunctionProtoType *Proto); |
12681 | void CheckConstructorCall(FunctionDecl *FDecl, QualType ThisType, |
12682 | ArrayRef<const Expr *> Args, |
12683 | const FunctionProtoType *Proto, SourceLocation Loc); |
12684 | |
12685 | void CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl, |
12686 | StringRef ParamName, QualType ArgTy, QualType ParamTy); |
12687 | |
12688 | void checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, |
12689 | const Expr *ThisArg, ArrayRef<const Expr *> Args, |
12690 | bool IsMemberFunction, SourceLocation Loc, SourceRange Range, |
12691 | VariadicCallType CallType); |
12692 | |
12693 | bool CheckObjCString(Expr *Arg); |
12694 | ExprResult CheckOSLogFormatStringArg(Expr *Arg); |
12695 | |
12696 | ExprResult CheckBuiltinFunctionCall(FunctionDecl *FDecl, |
12697 | unsigned BuiltinID, CallExpr *TheCall); |
12698 | |
12699 | bool CheckTSBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12700 | CallExpr *TheCall); |
12701 | |
12702 | void checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD, CallExpr *TheCall); |
12703 | |
12704 | bool CheckARMBuiltinExclusiveCall(unsigned BuiltinID, CallExpr *TheCall, |
12705 | unsigned MaxWidth); |
12706 | bool CheckNeonBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12707 | CallExpr *TheCall); |
12708 | bool CheckMVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
12709 | bool CheckSVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
12710 | bool CheckCDEBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12711 | CallExpr *TheCall); |
12712 | bool CheckARMCoprocessorImmediate(const TargetInfo &TI, const Expr *CoprocArg, |
12713 | bool WantCDE); |
12714 | bool CheckARMBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12715 | CallExpr *TheCall); |
12716 | |
12717 | bool CheckAArch64BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12718 | CallExpr *TheCall); |
12719 | bool CheckBPFBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
12720 | bool CheckHexagonBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
12721 | bool CheckHexagonBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall); |
12722 | bool CheckMipsBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12723 | CallExpr *TheCall); |
12724 | bool CheckMipsBuiltinCpu(const TargetInfo &TI, unsigned BuiltinID, |
12725 | CallExpr *TheCall); |
12726 | bool CheckMipsBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall); |
12727 | bool CheckSystemZBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
12728 | bool CheckX86BuiltinRoundingOrSAE(unsigned BuiltinID, CallExpr *TheCall); |
12729 | bool CheckX86BuiltinGatherScatterScale(unsigned BuiltinID, CallExpr *TheCall); |
12730 | bool CheckX86BuiltinTileArguments(unsigned BuiltinID, CallExpr *TheCall); |
12731 | bool CheckX86BuiltinTileArgumentsRange(CallExpr *TheCall, |
12732 | ArrayRef<int> ArgNums); |
12733 | bool CheckX86BuiltinTileDuplicate(CallExpr *TheCall, ArrayRef<int> ArgNums); |
12734 | bool CheckX86BuiltinTileRangeAndDuplicate(CallExpr *TheCall, |
12735 | ArrayRef<int> ArgNums); |
12736 | bool CheckX86BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12737 | CallExpr *TheCall); |
12738 | bool CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12739 | CallExpr *TheCall); |
12740 | bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
12741 | bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum); |
12742 | bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
12743 | CallExpr *TheCall); |
12744 | |
12745 | bool SemaBuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall); |
12746 | bool SemaBuiltinVAStartARMMicrosoft(CallExpr *Call); |
12747 | bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); |
12748 | bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); |
12749 | bool SemaBuiltinComplex(CallExpr *TheCall); |
12750 | bool SemaBuiltinVSX(CallExpr *TheCall); |
12751 | bool SemaBuiltinOSLogFormat(CallExpr *TheCall); |
12752 | bool SemaValueIsRunOfOnes(CallExpr *TheCall, unsigned ArgNum); |
12753 | |
12754 | public: |
12755 | // Used by C++ template instantiation. |
12756 | ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); |
12757 | ExprResult SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo, |
12758 | SourceLocation BuiltinLoc, |
12759 | SourceLocation RParenLoc); |
12760 | |
12761 | private: |
12762 | bool SemaBuiltinPrefetch(CallExpr *TheCall); |
12763 | bool SemaBuiltinAllocaWithAlign(CallExpr *TheCall); |
12764 | bool SemaBuiltinArithmeticFence(CallExpr *TheCall); |
12765 | bool SemaBuiltinAssume(CallExpr *TheCall); |
12766 | bool SemaBuiltinAssumeAligned(CallExpr *TheCall); |
12767 | bool SemaBuiltinLongjmp(CallExpr *TheCall); |
12768 | bool SemaBuiltinSetjmp(CallExpr *TheCall); |
12769 | ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); |
12770 | ExprResult SemaBuiltinNontemporalOverloaded(ExprResult TheCallResult); |
12771 | ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult, |
12772 | AtomicExpr::AtomicOp Op); |
12773 | ExprResult SemaBuiltinOperatorNewDeleteOverloaded(ExprResult TheCallResult, |
12774 | bool IsDelete); |
12775 | bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, |
12776 | llvm::APSInt &Result); |
12777 | bool SemaBuiltinConstantArgRange(CallExpr *TheCall, int ArgNum, int Low, |
12778 | int High, bool RangeIsError = true); |
12779 | bool SemaBuiltinConstantArgMultiple(CallExpr *TheCall, int ArgNum, |
12780 | unsigned Multiple); |
12781 | bool SemaBuiltinConstantArgPower2(CallExpr *TheCall, int ArgNum); |
12782 | bool SemaBuiltinConstantArgShiftedByte(CallExpr *TheCall, int ArgNum, |
12783 | unsigned ArgBits); |
12784 | bool SemaBuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall, int ArgNum, |
12785 | unsigned ArgBits); |
12786 | bool SemaBuiltinARMSpecialReg(unsigned BuiltinID, CallExpr *TheCall, |
12787 | int ArgNum, unsigned ExpectedFieldNum, |
12788 | bool AllowName); |
12789 | bool SemaBuiltinARMMemoryTaggingCall(unsigned BuiltinID, CallExpr *TheCall); |
12790 | bool SemaBuiltinPPCMMACall(CallExpr *TheCall, unsigned BuiltinID, |
12791 | const char *TypeDesc); |
12792 | |
12793 | bool CheckPPCMMAType(QualType Type, SourceLocation TypeLoc); |
12794 | |
12795 | bool SemaBuiltinElementwiseMath(CallExpr *TheCall); |
12796 | bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall); |
12797 | bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall); |
12798 | |
12799 | // Matrix builtin handling. |
12800 | ExprResult SemaBuiltinMatrixTranspose(CallExpr *TheCall, |
12801 | ExprResult CallResult); |
12802 | ExprResult SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall, |
12803 | ExprResult CallResult); |
12804 | ExprResult SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall, |
12805 | ExprResult CallResult); |
12806 | |
12807 | public: |
12808 | enum FormatStringType { |
12809 | FST_Scanf, |
12810 | FST_Printf, |
12811 | FST_NSString, |
12812 | FST_Strftime, |
12813 | FST_Strfmon, |
12814 | FST_Kprintf, |
12815 | FST_FreeBSDKPrintf, |
12816 | FST_OSTrace, |
12817 | FST_OSLog, |
12818 | FST_Unknown |
12819 | }; |
12820 | static FormatStringType GetFormatStringType(const FormatAttr *Format); |
12821 | |
12822 | bool FormatStringHasSArg(const StringLiteral *FExpr); |
12823 | |
12824 | static bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx); |
12825 | |
12826 | private: |
12827 | bool CheckFormatArguments(const FormatAttr *Format, |
12828 | ArrayRef<const Expr *> Args, |
12829 | bool IsCXXMember, |
12830 | VariadicCallType CallType, |
12831 | SourceLocation Loc, SourceRange Range, |
12832 | llvm::SmallBitVector &CheckedVarArgs); |
12833 | bool CheckFormatArguments(ArrayRef<const Expr *> Args, |
12834 | bool HasVAListArg, unsigned format_idx, |
12835 | unsigned firstDataArg, FormatStringType Type, |
12836 | VariadicCallType CallType, |
12837 | SourceLocation Loc, SourceRange range, |
12838 | llvm::SmallBitVector &CheckedVarArgs); |
12839 | |
12840 | void CheckAbsoluteValueFunction(const CallExpr *Call, |
12841 | const FunctionDecl *FDecl); |
12842 | |
12843 | void CheckMaxUnsignedZero(const CallExpr *Call, const FunctionDecl *FDecl); |
12844 | |
12845 | void CheckMemaccessArguments(const CallExpr *Call, |
12846 | unsigned BId, |
12847 | IdentifierInfo *FnName); |
12848 | |
12849 | void CheckStrlcpycatArguments(const CallExpr *Call, |
12850 | IdentifierInfo *FnName); |
12851 | |
12852 | void CheckStrncatArguments(const CallExpr *Call, |
12853 | IdentifierInfo *FnName); |
12854 | |
12855 | void CheckFreeArguments(const CallExpr *E); |
12856 | |
12857 | void CheckReturnValExpr(Expr *RetValExp, QualType lhsType, |
12858 | SourceLocation ReturnLoc, |
12859 | bool isObjCMethod = false, |
12860 | const AttrVec *Attrs = nullptr, |
12861 | const FunctionDecl *FD = nullptr); |
12862 | |
12863 | public: |
12864 | void CheckFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS); |
12865 | |
12866 | private: |
12867 | void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); |
12868 | void CheckBoolLikeConversion(Expr *E, SourceLocation CC); |
12869 | void CheckForIntOverflow(Expr *E); |
12870 | void CheckUnsequencedOperations(const Expr *E); |
12871 | |
12872 | /// Perform semantic checks on a completed expression. This will either |
12873 | /// be a full-expression or a default argument expression. |
12874 | void CheckCompletedExpr(Expr *E, SourceLocation CheckLoc = SourceLocation(), |
12875 | bool IsConstexpr = false); |
12876 | |
12877 | void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, |
12878 | Expr *Init); |
12879 | |
12880 | /// Check if there is a field shadowing. |
12881 | void CheckShadowInheritedFields(const SourceLocation &Loc, |
12882 | DeclarationName FieldName, |
12883 | const CXXRecordDecl *RD, |
12884 | bool DeclIsField = true); |
12885 | |
12886 | /// Check if the given expression contains 'break' or 'continue' |
12887 | /// statement that produces control flow different from GCC. |
12888 | void CheckBreakContinueBinding(Expr *E); |
12889 | |
12890 | /// Check whether receiver is mutable ObjC container which |
12891 | /// attempts to add itself into the container |
12892 | void CheckObjCCircularContainer(ObjCMessageExpr *Message); |
12893 | |
12894 | void CheckTCBEnforcement(const CallExpr *TheCall, const FunctionDecl *Callee); |
12895 | |
12896 | void AnalyzeDeleteExprMismatch(const CXXDeleteExpr *DE); |
12897 | void AnalyzeDeleteExprMismatch(FieldDecl *Field, SourceLocation DeleteLoc, |
12898 | bool DeleteWasArrayForm); |
12899 | public: |
12900 | /// Register a magic integral constant to be used as a type tag. |
12901 | void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind, |
12902 | uint64_t MagicValue, QualType Type, |
12903 | bool LayoutCompatible, bool MustBeNull); |
12904 | |
12905 | struct TypeTagData { |
12906 | TypeTagData() {} |
12907 | |
12908 | TypeTagData(QualType Type, bool LayoutCompatible, bool MustBeNull) : |
12909 | Type(Type), LayoutCompatible(LayoutCompatible), |
12910 | MustBeNull(MustBeNull) |
12911 | {} |
12912 | |
12913 | QualType Type; |
12914 | |
12915 | /// If true, \c Type should be compared with other expression's types for |
12916 | /// layout-compatibility. |
12917 | unsigned LayoutCompatible : 1; |
12918 | unsigned MustBeNull : 1; |
12919 | }; |
12920 | |
12921 | /// A pair of ArgumentKind identifier and magic value. This uniquely |
12922 | /// identifies the magic value. |
12923 | typedef std::pair<const IdentifierInfo *, uint64_t> TypeTagMagicValue; |
12924 | |
12925 | private: |
12926 | /// A map from magic value to type information. |
12927 | std::unique_ptr<llvm::DenseMap<TypeTagMagicValue, TypeTagData>> |
12928 | TypeTagForDatatypeMagicValues; |
12929 | |
12930 | /// Peform checks on a call of a function with argument_with_type_tag |
12931 | /// or pointer_with_type_tag attributes. |
12932 | void CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr, |
12933 | const ArrayRef<const Expr *> ExprArgs, |
12934 | SourceLocation CallSiteLoc); |
12935 | |
12936 | /// Check if we are taking the address of a packed field |
12937 | /// as this may be a problem if the pointer value is dereferenced. |
12938 | void CheckAddressOfPackedMember(Expr *rhs); |
12939 | |
12940 | /// The parser's current scope. |
12941 | /// |
12942 | /// The parser maintains this state here. |
12943 | Scope *CurScope; |
12944 | |
12945 | mutable IdentifierInfo *Ident_super; |
12946 | mutable IdentifierInfo *Ident___float128; |
12947 | |
12948 | /// Nullability type specifiers. |
12949 | IdentifierInfo *Ident__Nonnull = nullptr; |
12950 | IdentifierInfo *Ident__Nullable = nullptr; |
12951 | IdentifierInfo *Ident__Nullable_result = nullptr; |
12952 | IdentifierInfo *Ident__Null_unspecified = nullptr; |
12953 | |
12954 | IdentifierInfo *Ident_NSError = nullptr; |
12955 | |
12956 | /// The handler for the FileChanged preprocessor events. |
12957 | /// |
12958 | /// Used for diagnostics that implement custom semantic analysis for #include |
12959 | /// directives, like -Wpragma-pack. |
12960 | sema::SemaPPCallbacks *SemaPPCallbackHandler; |
12961 | |
12962 | protected: |
12963 | friend class Parser; |
12964 | friend class InitializationSequence; |
12965 | friend class ASTReader; |
12966 | friend class ASTDeclReader; |
12967 | friend class ASTWriter; |
12968 | |
12969 | public: |
12970 | /// Retrieve the keyword associated |
12971 | IdentifierInfo *getNullabilityKeyword(NullabilityKind nullability); |
12972 | |
12973 | /// The struct behind the CFErrorRef pointer. |
12974 | RecordDecl *CFError = nullptr; |
12975 | bool isCFError(RecordDecl *D); |
12976 | |
12977 | /// Retrieve the identifier "NSError". |
12978 | IdentifierInfo *getNSErrorIdent(); |
12979 | |
12980 | /// Retrieve the parser's current scope. |
12981 | /// |
12982 | /// This routine must only be used when it is certain that semantic analysis |
12983 | /// and the parser are in precisely the same context, which is not the case |
12984 | /// when, e.g., we are performing any kind of template instantiation. |
12985 | /// Therefore, the only safe places to use this scope are in the parser |
12986 | /// itself and in routines directly invoked from the parser and *never* from |
12987 | /// template substitution or instantiation. |
12988 | Scope *getCurScope() const { return CurScope; } |
12989 | |
12990 | void incrementMSManglingNumber() const { |
12991 | return CurScope->incrementMSManglingNumber(); |
12992 | } |
12993 | |
12994 | IdentifierInfo *getSuperIdentifier() const; |
12995 | IdentifierInfo *getFloat128Identifier() const; |
12996 | |
12997 | Decl *getObjCDeclContext() const; |
12998 | |
12999 | DeclContext *getCurLexicalContext() const { |
13000 | return OriginalLexicalContext ? OriginalLexicalContext : CurContext; |
13001 | } |
13002 | |
13003 | const DeclContext *getCurObjCLexicalContext() const { |
13004 | const DeclContext *DC = getCurLexicalContext(); |
13005 | // A category implicitly has the attribute of the interface. |
13006 | if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(DC)) |
13007 | DC = CatD->getClassInterface(); |
13008 | return DC; |
13009 | } |
13010 | |
13011 | /// Determine the number of levels of enclosing template parameters. This is |
13012 | /// only usable while parsing. Note that this does not include dependent |
13013 | /// contexts in which no template parameters have yet been declared, such as |
13014 | /// in a terse function template or generic lambda before the first 'auto' is |
13015 | /// encountered. |
13016 | unsigned getTemplateDepth(Scope *S) const; |
13017 | |
13018 | /// To be used for checking whether the arguments being passed to |
13019 | /// function exceeds the number of parameters expected for it. |
13020 | static bool TooManyArguments(size_t NumParams, size_t NumArgs, |
13021 | bool PartialOverloading = false) { |
13022 | // We check whether we're just after a comma in code-completion. |
13023 | if (NumArgs > 0 && PartialOverloading) |
13024 | return NumArgs + 1 > NumParams; // If so, we view as an extra argument. |
13025 | return NumArgs > NumParams; |
13026 | } |
13027 | |
13028 | // Emitting members of dllexported classes is delayed until the class |
13029 | // (including field initializers) is fully parsed. |
13030 | SmallVector<CXXRecordDecl*, 4> DelayedDllExportClasses; |
13031 | SmallVector<CXXMethodDecl*, 4> DelayedDllExportMemberFunctions; |
13032 | |
13033 | private: |
13034 | int ParsingClassDepth = 0; |
13035 | |
13036 | class SavePendingParsedClassStateRAII { |
13037 | public: |
13038 | SavePendingParsedClassStateRAII(Sema &S) : S(S) { swapSavedState(); } |
13039 | |
13040 | ~SavePendingParsedClassStateRAII() { |
13041 | assert(S.DelayedOverridingExceptionSpecChecks.empty() &&(static_cast <bool> (S.DelayedOverridingExceptionSpecChecks .empty() && "there shouldn't be any pending delayed exception spec checks" ) ? void (0) : __assert_fail ("S.DelayedOverridingExceptionSpecChecks.empty() && \"there shouldn't be any pending delayed exception spec checks\"" , "clang/include/clang/Sema/Sema.h", 13042, __extension__ __PRETTY_FUNCTION__ )) |
13042 | "there shouldn't be any pending delayed exception spec checks")(static_cast <bool> (S.DelayedOverridingExceptionSpecChecks .empty() && "there shouldn't be any pending delayed exception spec checks" ) ? void (0) : __assert_fail ("S.DelayedOverridingExceptionSpecChecks.empty() && \"there shouldn't be any pending delayed exception spec checks\"" , "clang/include/clang/Sema/Sema.h", 13042, __extension__ __PRETTY_FUNCTION__ )); |
13043 | assert(S.DelayedEquivalentExceptionSpecChecks.empty() &&(static_cast <bool> (S.DelayedEquivalentExceptionSpecChecks .empty() && "there shouldn't be any pending delayed exception spec checks" ) ? void (0) : __assert_fail ("S.DelayedEquivalentExceptionSpecChecks.empty() && \"there shouldn't be any pending delayed exception spec checks\"" , "clang/include/clang/Sema/Sema.h", 13044, __extension__ __PRETTY_FUNCTION__ )) |
13044 | "there shouldn't be any pending delayed exception spec checks")(static_cast <bool> (S.DelayedEquivalentExceptionSpecChecks .empty() && "there shouldn't be any pending delayed exception spec checks" ) ? void (0) : __assert_fail ("S.DelayedEquivalentExceptionSpecChecks.empty() && \"there shouldn't be any pending delayed exception spec checks\"" , "clang/include/clang/Sema/Sema.h", 13044, __extension__ __PRETTY_FUNCTION__ )); |
13045 | swapSavedState(); |
13046 | } |
13047 | |
13048 | private: |
13049 | Sema &S; |
13050 | decltype(DelayedOverridingExceptionSpecChecks) |
13051 | SavedOverridingExceptionSpecChecks; |
13052 | decltype(DelayedEquivalentExceptionSpecChecks) |
13053 | SavedEquivalentExceptionSpecChecks; |
13054 | |
13055 | void swapSavedState() { |
13056 | SavedOverridingExceptionSpecChecks.swap( |
13057 | S.DelayedOverridingExceptionSpecChecks); |
13058 | SavedEquivalentExceptionSpecChecks.swap( |
13059 | S.DelayedEquivalentExceptionSpecChecks); |
13060 | } |
13061 | }; |
13062 | |
13063 | /// Helper class that collects misaligned member designations and |
13064 | /// their location info for delayed diagnostics. |
13065 | struct MisalignedMember { |
13066 | Expr *E; |
13067 | RecordDecl *RD; |
13068 | ValueDecl *MD; |
13069 | CharUnits Alignment; |
13070 | |
13071 | MisalignedMember() : E(), RD(), MD() {} |
13072 | MisalignedMember(Expr *E, RecordDecl *RD, ValueDecl *MD, |
13073 | CharUnits Alignment) |
13074 | : E(E), RD(RD), MD(MD), Alignment(Alignment) {} |
13075 | explicit MisalignedMember(Expr *E) |
13076 | : MisalignedMember(E, nullptr, nullptr, CharUnits()) {} |
13077 | |
13078 | bool operator==(const MisalignedMember &m) { return this->E == m.E; } |
13079 | }; |
13080 | /// Small set of gathered accesses to potentially misaligned members |
13081 | /// due to the packed attribute. |
13082 | SmallVector<MisalignedMember, 4> MisalignedMembers; |
13083 | |
13084 | /// Adds an expression to the set of gathered misaligned members. |
13085 | void AddPotentialMisalignedMembers(Expr *E, RecordDecl *RD, ValueDecl *MD, |
13086 | CharUnits Alignment); |
13087 | |
13088 | public: |
13089 | /// Diagnoses the current set of gathered accesses. This typically |
13090 | /// happens at full expression level. The set is cleared after emitting the |
13091 | /// diagnostics. |
13092 | void DiagnoseMisalignedMembers(); |
13093 | |
13094 | /// This function checks if the expression is in the sef of potentially |
13095 | /// misaligned members and it is converted to some pointer type T with lower |
13096 | /// or equal alignment requirements. If so it removes it. This is used when |
13097 | /// we do not want to diagnose such misaligned access (e.g. in conversions to |
13098 | /// void*). |
13099 | void DiscardMisalignedMemberAddress(const Type *T, Expr *E); |
13100 | |
13101 | /// This function calls Action when it determines that E designates a |
13102 | /// misaligned member due to the packed attribute. This is used to emit |
13103 | /// local diagnostics like in reference binding. |
13104 | void RefersToMemberWithReducedAlignment( |
13105 | Expr *E, |
13106 | llvm::function_ref<void(Expr *, RecordDecl *, FieldDecl *, CharUnits)> |
13107 | Action); |
13108 | |
13109 | /// Describes the reason a calling convention specification was ignored, used |
13110 | /// for diagnostics. |
13111 | enum class CallingConventionIgnoredReason { |
13112 | ForThisTarget = 0, |
13113 | VariadicFunction, |
13114 | ConstructorDestructor, |
13115 | BuiltinFunction |
13116 | }; |
13117 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
13118 | /// context is "used as device code". |
13119 | /// |
13120 | /// - If CurLexicalContext is a kernel function or it is known that the |
13121 | /// function will be emitted for the device, emits the diagnostics |
13122 | /// immediately. |
13123 | /// - If CurLexicalContext is a function and we are compiling |
13124 | /// for the device, but we don't know that this function will be codegen'ed |
13125 | /// for devive yet, creates a diagnostic which is emitted if and when we |
13126 | /// realize that the function will be codegen'ed. |
13127 | /// |
13128 | /// Example usage: |
13129 | /// |
13130 | /// Diagnose __float128 type usage only from SYCL device code if the current |
13131 | /// target doesn't support it |
13132 | /// if (!S.Context.getTargetInfo().hasFloat128Type() && |
13133 | /// S.getLangOpts().SYCLIsDevice) |
13134 | /// SYCLDiagIfDeviceCode(Loc, diag::err_type_unsupported) << "__float128"; |
13135 | SemaDiagnosticBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, |
13136 | unsigned DiagID); |
13137 | |
13138 | /// Check whether we're allowed to call Callee from the current context. |
13139 | /// |
13140 | /// - If the call is never allowed in a semantically-correct program |
13141 | /// emits an error and returns false. |
13142 | /// |
13143 | /// - If the call is allowed in semantically-correct programs, but only if |
13144 | /// it's never codegen'ed, creates a deferred diagnostic to be emitted if |
13145 | /// and when the caller is codegen'ed, and returns true. |
13146 | /// |
13147 | /// - Otherwise, returns true without emitting any diagnostics. |
13148 | /// |
13149 | /// Adds Callee to DeviceCallGraph if we don't know if its caller will be |
13150 | /// codegen'ed yet. |
13151 | bool checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee); |
13152 | void deepTypeCheckForSYCLDevice(SourceLocation UsedAt, |
13153 | llvm::DenseSet<QualType> Visited, |
13154 | ValueDecl *DeclToCheck); |
13155 | }; |
13156 | |
13157 | /// RAII object that enters a new expression evaluation context. |
13158 | class EnterExpressionEvaluationContext { |
13159 | Sema &Actions; |
13160 | bool Entered = true; |
13161 | |
13162 | public: |
13163 | EnterExpressionEvaluationContext( |
13164 | Sema &Actions, Sema::ExpressionEvaluationContext NewContext, |
13165 | Decl *LambdaContextDecl = nullptr, |
13166 | Sema::ExpressionEvaluationContextRecord::ExpressionKind ExprContext = |
13167 | Sema::ExpressionEvaluationContextRecord::EK_Other, |
13168 | bool ShouldEnter = true) |
13169 | : Actions(Actions), Entered(ShouldEnter) { |
13170 | if (Entered) |
13171 | Actions.PushExpressionEvaluationContext(NewContext, LambdaContextDecl, |
13172 | ExprContext); |
13173 | } |
13174 | EnterExpressionEvaluationContext( |
13175 | Sema &Actions, Sema::ExpressionEvaluationContext NewContext, |
13176 | Sema::ReuseLambdaContextDecl_t, |
13177 | Sema::ExpressionEvaluationContextRecord::ExpressionKind ExprContext = |
13178 | Sema::ExpressionEvaluationContextRecord::EK_Other) |
13179 | : Actions(Actions) { |
13180 | Actions.PushExpressionEvaluationContext( |
13181 | NewContext, Sema::ReuseLambdaContextDecl, ExprContext); |
13182 | } |
13183 | |
13184 | enum InitListTag { InitList }; |
13185 | EnterExpressionEvaluationContext(Sema &Actions, InitListTag, |
13186 | bool ShouldEnter = true) |
13187 | : Actions(Actions), Entered(false) { |
13188 | // In C++11 onwards, narrowing checks are performed on the contents of |
13189 | // braced-init-lists, even when they occur within unevaluated operands. |
13190 | // Therefore we still need to instantiate constexpr functions used in such |
13191 | // a context. |
13192 | if (ShouldEnter && Actions.isUnevaluatedContext() && |
13193 | Actions.getLangOpts().CPlusPlus11) { |
13194 | Actions.PushExpressionEvaluationContext( |
13195 | Sema::ExpressionEvaluationContext::UnevaluatedList); |
13196 | Entered = true; |
13197 | } |
13198 | } |
13199 | |
13200 | ~EnterExpressionEvaluationContext() { |
13201 | if (Entered) |
13202 | Actions.PopExpressionEvaluationContext(); |
13203 | } |
13204 | }; |
13205 | |
13206 | DeductionFailureInfo |
13207 | MakeDeductionFailureInfo(ASTContext &Context, Sema::TemplateDeductionResult TDK, |
13208 | sema::TemplateDeductionInfo &Info); |
13209 | |
13210 | /// Contains a late templated function. |
13211 | /// Will be parsed at the end of the translation unit, used by Sema & Parser. |
13212 | struct LateParsedTemplate { |
13213 | CachedTokens Toks; |
13214 | /// The template function declaration to be late parsed. |
13215 | Decl *D; |
13216 | }; |
13217 | |
13218 | template <> |
13219 | void Sema::PragmaStack<Sema::AlignPackInfo>::Act(SourceLocation PragmaLocation, |
13220 | PragmaMsStackAction Action, |
13221 | llvm::StringRef StackSlotLabel, |
13222 | AlignPackInfo Value); |
13223 | |
13224 | } // end namespace clang |
13225 | |
13226 | namespace llvm { |
13227 | // Hash a FunctionDeclAndLoc by looking at both its FunctionDecl and its |
13228 | // SourceLocation. |
13229 | template <> struct DenseMapInfo<clang::Sema::FunctionDeclAndLoc> { |
13230 | using FunctionDeclAndLoc = clang::Sema::FunctionDeclAndLoc; |
13231 | using FDBaseInfo = DenseMapInfo<clang::CanonicalDeclPtr<clang::FunctionDecl>>; |
13232 | |
13233 | static FunctionDeclAndLoc getEmptyKey() { |
13234 | return {FDBaseInfo::getEmptyKey(), clang::SourceLocation()}; |
13235 | } |
13236 | |
13237 | static FunctionDeclAndLoc getTombstoneKey() { |
13238 | return {FDBaseInfo::getTombstoneKey(), clang::SourceLocation()}; |
13239 | } |
13240 | |
13241 | static unsigned getHashValue(const FunctionDeclAndLoc &FDL) { |
13242 | return hash_combine(FDBaseInfo::getHashValue(FDL.FD), |
13243 | FDL.Loc.getHashValue()); |
13244 | } |
13245 | |
13246 | static bool isEqual(const FunctionDeclAndLoc &LHS, |
13247 | const FunctionDeclAndLoc &RHS) { |
13248 | return LHS.FD == RHS.FD && LHS.Loc == RHS.Loc; |
13249 | } |
13250 | }; |
13251 | } // namespace llvm |
13252 | |
13253 | #endif |