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/APINotes/APINotesManager.h" |
18 | #include "clang/AST/ASTConcept.h" |
19 | #include "clang/AST/ASTFwd.h" |
20 | #include "clang/AST/Attr.h" |
21 | #include "clang/AST/Availability.h" |
22 | #include "clang/AST/ComparisonCategories.h" |
23 | #include "clang/AST/DeclTemplate.h" |
24 | #include "clang/AST/DeclarationName.h" |
25 | #include "clang/AST/Expr.h" |
26 | #include "clang/AST/ExprCXX.h" |
27 | #include "clang/AST/ExprConcepts.h" |
28 | #include "clang/AST/ExprObjC.h" |
29 | #include "clang/AST/ExprOpenMP.h" |
30 | #include "clang/AST/ExternalASTSource.h" |
31 | #include "clang/AST/LocInfoType.h" |
32 | #include "clang/AST/MangleNumberingContext.h" |
33 | #include "clang/AST/NSAPI.h" |
34 | #include "clang/AST/PrettyPrinter.h" |
35 | #include "clang/AST/StmtCXX.h" |
36 | #include "clang/AST/StmtOpenMP.h" |
37 | #include "clang/AST/TypeLoc.h" |
38 | #include "clang/AST/TypeOrdering.h" |
39 | #include "clang/Basic/BitmaskEnum.h" |
40 | #include "clang/Basic/Builtins.h" |
41 | #include "clang/Basic/DarwinSDKInfo.h" |
42 | #include "clang/Basic/ExpressionTraits.h" |
43 | #include "clang/Basic/Module.h" |
44 | #include "clang/Basic/OpenCLOptions.h" |
45 | #include "clang/Basic/OpenMPKinds.h" |
46 | #include "clang/Basic/PragmaKinds.h" |
47 | #include "clang/Basic/Specifiers.h" |
48 | #include "clang/Basic/TemplateKinds.h" |
49 | #include "clang/Basic/TypeTraits.h" |
50 | #include "clang/Sema/AnalysisBasedWarnings.h" |
51 | #include "clang/Sema/CleanupInfo.h" |
52 | #include "clang/Sema/DeclSpec.h" |
53 | #include "clang/Sema/ExternalSemaSource.h" |
54 | #include "clang/Sema/IdentifierResolver.h" |
55 | #include "clang/Sema/ObjCMethodList.h" |
56 | #include "clang/Sema/Ownership.h" |
57 | #include "clang/Sema/Scope.h" |
58 | #include "clang/Sema/SemaConcept.h" |
59 | #include "clang/Sema/TypoCorrection.h" |
60 | #include "clang/Sema/Weak.h" |
61 | #include "llvm/ADT/ArrayRef.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 <optional> |
72 | #include <string> |
73 | #include <tuple> |
74 | #include <vector> |
75 | |
76 | namespace llvm { |
77 | class APSInt; |
78 | template <typename ValueT, typename ValueInfoT> class DenseSet; |
79 | class SmallBitVector; |
80 | struct InlineAsmIdentifierInfo; |
81 | } |
82 | |
83 | namespace clang { |
84 | class ADLResult; |
85 | class ASTConsumer; |
86 | class ASTContext; |
87 | class ASTMutationListener; |
88 | class ASTReader; |
89 | class ASTWriter; |
90 | class ArrayType; |
91 | class ParsedAttr; |
92 | class BindingDecl; |
93 | class BlockDecl; |
94 | class CapturedDecl; |
95 | class CXXBasePath; |
96 | class CXXBasePaths; |
97 | class CXXBindTemporaryExpr; |
98 | typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; |
99 | class CXXConstructorDecl; |
100 | class CXXConversionDecl; |
101 | class CXXDeleteExpr; |
102 | class CXXDestructorDecl; |
103 | class CXXFieldCollector; |
104 | class CXXMemberCallExpr; |
105 | class CXXMethodDecl; |
106 | class CXXScopeSpec; |
107 | class CXXTemporary; |
108 | class CXXTryStmt; |
109 | class CallExpr; |
110 | class ClassTemplateDecl; |
111 | class ClassTemplatePartialSpecializationDecl; |
112 | class ClassTemplateSpecializationDecl; |
113 | class VarTemplatePartialSpecializationDecl; |
114 | class CodeCompleteConsumer; |
115 | class CodeCompletionAllocator; |
116 | class CodeCompletionTUInfo; |
117 | class CodeCompletionResult; |
118 | class CoroutineBodyStmt; |
119 | class Decl; |
120 | class DeclAccessPair; |
121 | class DeclContext; |
122 | class DeclRefExpr; |
123 | class DeclaratorDecl; |
124 | class DeducedTemplateArgument; |
125 | class DependentDiagnostic; |
126 | class DesignatedInitExpr; |
127 | class Designation; |
128 | class EnableIfAttr; |
129 | class EnumConstantDecl; |
130 | class Expr; |
131 | class ExtVectorType; |
132 | class FormatAttr; |
133 | class FriendDecl; |
134 | class FunctionDecl; |
135 | class FunctionProtoType; |
136 | class FunctionTemplateDecl; |
137 | class ImplicitConversionSequence; |
138 | typedef MutableArrayRef<ImplicitConversionSequence> ConversionSequenceList; |
139 | class InitListExpr; |
140 | class InitializationKind; |
141 | class InitializationSequence; |
142 | class InitializedEntity; |
143 | class IntegerLiteral; |
144 | class LabelStmt; |
145 | class LambdaExpr; |
146 | class LangOptions; |
147 | class LocalInstantiationScope; |
148 | class LookupResult; |
149 | class MacroInfo; |
150 | typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> ModuleIdPath; |
151 | class ModuleLoader; |
152 | class MultiLevelTemplateArgumentList; |
153 | class NamedDecl; |
154 | class ObjCCategoryDecl; |
155 | class ObjCCategoryImplDecl; |
156 | class ObjCCompatibleAliasDecl; |
157 | class ObjCContainerDecl; |
158 | class ObjCImplDecl; |
159 | class ObjCImplementationDecl; |
160 | class ObjCInterfaceDecl; |
161 | class ObjCIvarDecl; |
162 | template <class T> class ObjCList; |
163 | class ObjCMessageExpr; |
164 | class ObjCMethodDecl; |
165 | class ObjCPropertyDecl; |
166 | class ObjCProtocolDecl; |
167 | class OMPThreadPrivateDecl; |
168 | class OMPRequiresDecl; |
169 | class OMPDeclareReductionDecl; |
170 | class OMPDeclareSimdDecl; |
171 | class OMPClause; |
172 | struct OMPVarListLocTy; |
173 | struct OverloadCandidate; |
174 | enum class OverloadCandidateParamOrder : char; |
175 | enum OverloadCandidateRewriteKind : unsigned; |
176 | class OverloadCandidateSet; |
177 | class OverloadExpr; |
178 | class ParenListExpr; |
179 | class ParmVarDecl; |
180 | class Preprocessor; |
181 | class PseudoDestructorTypeStorage; |
182 | class PseudoObjectExpr; |
183 | class QualType; |
184 | class StandardConversionSequence; |
185 | class Stmt; |
186 | class StringLiteral; |
187 | class SwitchStmt; |
188 | class TemplateArgument; |
189 | class TemplateArgumentList; |
190 | class TemplateArgumentLoc; |
191 | class TemplateDecl; |
192 | class TemplateInstantiationCallback; |
193 | class TemplateParameterList; |
194 | class TemplatePartialOrderingContext; |
195 | class TemplateTemplateParmDecl; |
196 | class Token; |
197 | class TypeAliasDecl; |
198 | class TypedefDecl; |
199 | class TypedefNameDecl; |
200 | class TypeLoc; |
201 | class TypoCorrectionConsumer; |
202 | class UnqualifiedId; |
203 | class UnresolvedLookupExpr; |
204 | class UnresolvedMemberExpr; |
205 | class UnresolvedSetImpl; |
206 | class UnresolvedSetIterator; |
207 | class UsingDecl; |
208 | class UsingShadowDecl; |
209 | class ValueDecl; |
210 | class VarDecl; |
211 | class VarTemplateSpecializationDecl; |
212 | class VisibilityAttr; |
213 | class VisibleDeclConsumer; |
214 | class IndirectFieldDecl; |
215 | struct DeductionFailureInfo; |
216 | class TemplateSpecCandidateSet; |
217 | |
218 | namespace sema { |
219 | class AccessedEntity; |
220 | class BlockScopeInfo; |
221 | class Capture; |
222 | class CapturedRegionScopeInfo; |
223 | class CapturingScopeInfo; |
224 | class CompoundScopeInfo; |
225 | class DelayedDiagnostic; |
226 | class DelayedDiagnosticPool; |
227 | class FunctionScopeInfo; |
228 | class LambdaScopeInfo; |
229 | class PossiblyUnreachableDiag; |
230 | class RISCVIntrinsicManager; |
231 | class SemaPPCallbacks; |
232 | class TemplateDeductionInfo; |
233 | } |
234 | |
235 | namespace threadSafety { |
236 | class BeforeSet; |
237 | void threadSafetyCleanup(BeforeSet* Cache); |
238 | } |
239 | |
240 | // FIXME: No way to easily map from TemplateTypeParmTypes to |
241 | // TemplateTypeParmDecls, so we have this horrible PointerUnion. |
242 | typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType *, NamedDecl *>, |
243 | SourceLocation> |
244 | UnexpandedParameterPack; |
245 | |
246 | /// Describes whether we've seen any nullability information for the given |
247 | /// file. |
248 | struct FileNullability { |
249 | /// The first pointer declarator (of any pointer kind) in the file that does |
250 | /// not have a corresponding nullability annotation. |
251 | SourceLocation PointerLoc; |
252 | |
253 | /// The end location for the first pointer declarator in the file. Used for |
254 | /// placing fix-its. |
255 | SourceLocation PointerEndLoc; |
256 | |
257 | /// Which kind of pointer declarator we saw. |
258 | uint8_t PointerKind; |
259 | |
260 | /// Whether we saw any type nullability annotations in the given file. |
261 | bool SawTypeNullability = false; |
262 | }; |
263 | |
264 | /// A mapping from file IDs to a record of whether we've seen nullability |
265 | /// information in that file. |
266 | class FileNullabilityMap { |
267 | /// A mapping from file IDs to the nullability information for each file ID. |
268 | llvm::DenseMap<FileID, FileNullability> Map; |
269 | |
270 | /// A single-element cache based on the file ID. |
271 | struct { |
272 | FileID File; |
273 | FileNullability Nullability; |
274 | } Cache; |
275 | |
276 | public: |
277 | FileNullability &operator[](FileID file) { |
278 | // Check the single-element cache. |
279 | if (file == Cache.File) |
280 | return Cache.Nullability; |
281 | |
282 | // It's not in the single-element cache; flush the cache if we have one. |
283 | if (!Cache.File.isInvalid()) { |
284 | Map[Cache.File] = Cache.Nullability; |
285 | } |
286 | |
287 | // Pull this entry into the cache. |
288 | Cache.File = file; |
289 | Cache.Nullability = Map[file]; |
290 | return Cache.Nullability; |
291 | } |
292 | }; |
293 | |
294 | /// Tracks expected type during expression parsing, for use in code completion. |
295 | /// The type is tied to a particular token, all functions that update or consume |
296 | /// the type take a start location of the token they are looking at as a |
297 | /// parameter. This avoids updating the type on hot paths in the parser. |
298 | class PreferredTypeBuilder { |
299 | public: |
300 | PreferredTypeBuilder(bool Enabled) : Enabled(Enabled) {} |
301 | |
302 | void enterCondition(Sema &S, SourceLocation Tok); |
303 | void enterReturn(Sema &S, SourceLocation Tok); |
304 | void enterVariableInit(SourceLocation Tok, Decl *D); |
305 | /// Handles e.g. BaseType{ .D = Tok... |
306 | void enterDesignatedInitializer(SourceLocation Tok, QualType BaseType, |
307 | const Designation &D); |
308 | /// Computing a type for the function argument may require running |
309 | /// overloading, so we postpone its computation until it is actually needed. |
310 | /// |
311 | /// Clients should be very careful when using this function, as it stores a |
312 | /// function_ref, clients should make sure all calls to get() with the same |
313 | /// location happen while function_ref is alive. |
314 | /// |
315 | /// The callback should also emit signature help as a side-effect, but only |
316 | /// if the completion point has been reached. |
317 | void enterFunctionArgument(SourceLocation Tok, |
318 | llvm::function_ref<QualType()> ComputeType); |
319 | |
320 | void enterParenExpr(SourceLocation Tok, SourceLocation LParLoc); |
321 | void enterUnary(Sema &S, SourceLocation Tok, tok::TokenKind OpKind, |
322 | SourceLocation OpLoc); |
323 | void enterBinary(Sema &S, SourceLocation Tok, Expr *LHS, tok::TokenKind Op); |
324 | void enterMemAccess(Sema &S, SourceLocation Tok, Expr *Base); |
325 | void enterSubscript(Sema &S, SourceLocation Tok, Expr *LHS); |
326 | /// Handles all type casts, including C-style cast, C++ casts, etc. |
327 | void enterTypeCast(SourceLocation Tok, QualType CastType); |
328 | |
329 | /// Get the expected type associated with this location, if any. |
330 | /// |
331 | /// If the location is a function argument, determining the expected type |
332 | /// involves considering all function overloads and the arguments so far. |
333 | /// In this case, signature help for these function overloads will be reported |
334 | /// as a side-effect (only if the completion point has been reached). |
335 | QualType get(SourceLocation Tok) const { |
336 | if (!Enabled || Tok != ExpectedLoc) |
337 | return QualType(); |
338 | if (!Type.isNull()) |
339 | return Type; |
340 | if (ComputeType) |
341 | return ComputeType(); |
342 | return QualType(); |
343 | } |
344 | |
345 | private: |
346 | bool Enabled; |
347 | /// Start position of a token for which we store expected type. |
348 | SourceLocation ExpectedLoc; |
349 | /// Expected type for a token starting at ExpectedLoc. |
350 | QualType Type; |
351 | /// A function to compute expected type at ExpectedLoc. It is only considered |
352 | /// if Type is null. |
353 | llvm::function_ref<QualType()> ComputeType; |
354 | }; |
355 | |
356 | /// Describes the result of template argument deduction. |
357 | /// |
358 | /// The TemplateDeductionResult enumeration describes the result of |
359 | /// template argument deduction, as returned from |
360 | /// DeduceTemplateArguments(). The separate TemplateDeductionInfo |
361 | /// structure provides additional information about the results of |
362 | /// template argument deduction, e.g., the deduced template argument |
363 | /// list (if successful) or the specific template parameters or |
364 | /// deduced arguments that were involved in the failure. |
365 | enum class TemplateDeductionResult { |
366 | /// Template argument deduction was successful. |
367 | Success = 0, |
368 | /// The declaration was invalid; do nothing. |
369 | Invalid, |
370 | /// Template argument deduction exceeded the maximum template |
371 | /// instantiation depth (which has already been diagnosed). |
372 | InstantiationDepth, |
373 | /// Template argument deduction did not deduce a value |
374 | /// for every template parameter. |
375 | Incomplete, |
376 | /// Template argument deduction did not deduce a value for every |
377 | /// expansion of an expanded template parameter pack. |
378 | IncompletePack, |
379 | /// Template argument deduction produced inconsistent |
380 | /// deduced values for the given template parameter. |
381 | Inconsistent, |
382 | /// Template argument deduction failed due to inconsistent |
383 | /// cv-qualifiers on a template parameter type that would |
384 | /// otherwise be deduced, e.g., we tried to deduce T in "const T" |
385 | /// but were given a non-const "X". |
386 | Underqualified, |
387 | /// Substitution of the deduced template argument values |
388 | /// resulted in an error. |
389 | SubstitutionFailure, |
390 | /// After substituting deduced template arguments, a dependent |
391 | /// parameter type did not match the corresponding argument. |
392 | DeducedMismatch, |
393 | /// After substituting deduced template arguments, an element of |
394 | /// a dependent parameter type did not match the corresponding element |
395 | /// of the corresponding argument (when deducing from an initializer list). |
396 | DeducedMismatchNested, |
397 | /// A non-depnedent component of the parameter did not match the |
398 | /// corresponding component of the argument. |
399 | NonDeducedMismatch, |
400 | /// When performing template argument deduction for a function |
401 | /// template, there were too many call arguments. |
402 | TooManyArguments, |
403 | /// When performing template argument deduction for a function |
404 | /// template, there were too few call arguments. |
405 | TooFewArguments, |
406 | /// The explicitly-specified template arguments were not valid |
407 | /// template arguments for the given template. |
408 | InvalidExplicitArguments, |
409 | /// Checking non-dependent argument conversions failed. |
410 | NonDependentConversionFailure, |
411 | /// The deduced arguments did not satisfy the constraints associated |
412 | /// with the template. |
413 | ConstraintsNotSatisfied, |
414 | /// Deduction failed; that's all we know. |
415 | MiscellaneousDeductionFailure, |
416 | /// CUDA Target attributes do not match. |
417 | CUDATargetMismatch, |
418 | /// Some error which was already diagnosed. |
419 | AlreadyDiagnosed |
420 | }; |
421 | |
422 | /// Sema - This implements semantic analysis and AST building for C. |
423 | class Sema final { |
424 | Sema(const Sema &) = delete; |
425 | void operator=(const Sema &) = delete; |
426 | |
427 | ///Source of additional semantic information. |
428 | IntrusiveRefCntPtr<ExternalSemaSource> ExternalSource; |
429 | |
430 | static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD); |
431 | |
432 | /// Determine whether two declarations should be linked together, given that |
433 | /// the old declaration might not be visible and the new declaration might |
434 | /// not have external linkage. |
435 | bool shouldLinkPossiblyHiddenDecl(const NamedDecl *Old, |
436 | const NamedDecl *New) { |
437 | if (isVisible(D: Old)) |
438 | return true; |
439 | // See comment in below overload for why it's safe to compute the linkage |
440 | // of the new declaration here. |
441 | if (New->isExternallyDeclarable()) { |
442 | assert(Old->isExternallyDeclarable() && |
443 | "should not have found a non-externally-declarable previous decl" ); |
444 | return true; |
445 | } |
446 | return false; |
447 | } |
448 | bool shouldLinkPossiblyHiddenDecl(LookupResult &Old, const NamedDecl *New); |
449 | |
450 | void setupImplicitSpecialMemberType(CXXMethodDecl *SpecialMem, |
451 | QualType ResultTy, |
452 | ArrayRef<QualType> Args); |
453 | |
454 | public: |
455 | /// The maximum alignment, same as in llvm::Value. We duplicate them here |
456 | /// because that allows us not to duplicate the constants in clang code, |
457 | /// which we must to since we can't directly use the llvm constants. |
458 | /// The value is verified against llvm here: lib/CodeGen/CGDecl.cpp |
459 | /// |
460 | /// This is the greatest alignment value supported by load, store, and alloca |
461 | /// instructions, and global values. |
462 | static const unsigned MaxAlignmentExponent = 32; |
463 | static const uint64_t MaximumAlignment = 1ull << MaxAlignmentExponent; |
464 | |
465 | typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; |
466 | typedef OpaquePtr<TemplateName> TemplateTy; |
467 | typedef OpaquePtr<QualType> TypeTy; |
468 | |
469 | OpenCLOptions OpenCLFeatures; |
470 | FPOptions CurFPFeatures; |
471 | |
472 | const LangOptions &LangOpts; |
473 | Preprocessor &PP; |
474 | ASTContext &Context; |
475 | ASTConsumer &Consumer; |
476 | DiagnosticsEngine &Diags; |
477 | SourceManager &SourceMgr; |
478 | api_notes::APINotesManager APINotes; |
479 | |
480 | /// Flag indicating whether or not to collect detailed statistics. |
481 | bool CollectStats; |
482 | |
483 | /// Code-completion consumer. |
484 | CodeCompleteConsumer *CodeCompleter; |
485 | |
486 | /// CurContext - This is the current declaration context of parsing. |
487 | DeclContext *CurContext; |
488 | |
489 | /// Generally null except when we temporarily switch decl contexts, |
490 | /// like in \see ActOnObjCTemporaryExitContainerContext. |
491 | DeclContext *OriginalLexicalContext; |
492 | |
493 | /// VAListTagName - The declaration name corresponding to __va_list_tag. |
494 | /// This is used as part of a hack to omit that class from ADL results. |
495 | DeclarationName VAListTagName; |
496 | |
497 | bool MSStructPragmaOn; // True when \#pragma ms_struct on |
498 | |
499 | /// Controls member pointer representation format under the MS ABI. |
500 | LangOptions::PragmaMSPointersToMembersKind |
501 | MSPointerToMemberRepresentationMethod; |
502 | |
503 | /// Stack of active SEH __finally scopes. Can be empty. |
504 | SmallVector<Scope*, 2> CurrentSEHFinally; |
505 | |
506 | /// Source location for newly created implicit MSInheritanceAttrs |
507 | SourceLocation ImplicitMSInheritanceAttrLoc; |
508 | |
509 | /// Holds TypoExprs that are created from `createDelayedTypo`. This is used by |
510 | /// `TransformTypos` in order to keep track of any TypoExprs that are created |
511 | /// recursively during typo correction and wipe them away if the correction |
512 | /// fails. |
513 | llvm::SmallVector<TypoExpr *, 2> TypoExprs; |
514 | |
515 | /// pragma clang section kind |
516 | enum PragmaClangSectionKind { |
517 | PCSK_Invalid = 0, |
518 | PCSK_BSS = 1, |
519 | PCSK_Data = 2, |
520 | PCSK_Rodata = 3, |
521 | PCSK_Text = 4, |
522 | PCSK_Relro = 5 |
523 | }; |
524 | |
525 | enum PragmaClangSectionAction { |
526 | PCSA_Set = 0, |
527 | PCSA_Clear = 1 |
528 | }; |
529 | |
530 | struct PragmaClangSection { |
531 | std::string SectionName; |
532 | bool Valid = false; |
533 | SourceLocation PragmaLocation; |
534 | }; |
535 | |
536 | PragmaClangSection PragmaClangBSSSection; |
537 | PragmaClangSection PragmaClangDataSection; |
538 | PragmaClangSection PragmaClangRodataSection; |
539 | PragmaClangSection PragmaClangRelroSection; |
540 | PragmaClangSection PragmaClangTextSection; |
541 | |
542 | enum PragmaMsStackAction { |
543 | PSK_Reset = 0x0, // #pragma () |
544 | PSK_Set = 0x1, // #pragma (value) |
545 | PSK_Push = 0x2, // #pragma (push[, id]) |
546 | PSK_Pop = 0x4, // #pragma (pop[, id]) |
547 | PSK_Show = 0x8, // #pragma (show) -- only for "pack"! |
548 | PSK_Push_Set = PSK_Push | PSK_Set, // #pragma (push[, id], value) |
549 | PSK_Pop_Set = PSK_Pop | PSK_Set, // #pragma (pop[, id], value) |
550 | }; |
551 | |
552 | struct PragmaPackInfo { |
553 | PragmaMsStackAction Action; |
554 | StringRef SlotLabel; |
555 | Token Alignment; |
556 | }; |
557 | |
558 | // #pragma pack and align. |
559 | class AlignPackInfo { |
560 | public: |
561 | // `Native` represents default align mode, which may vary based on the |
562 | // platform. |
563 | enum Mode : unsigned char { Native, Natural, Packed, Mac68k }; |
564 | |
565 | // #pragma pack info constructor |
566 | AlignPackInfo(AlignPackInfo::Mode M, unsigned Num, bool IsXL) |
567 | : PackAttr(true), AlignMode(M), PackNumber(Num), XLStack(IsXL) { |
568 | assert(Num == PackNumber && "The pack number has been truncated." ); |
569 | } |
570 | |
571 | // #pragma align info constructor |
572 | AlignPackInfo(AlignPackInfo::Mode M, bool IsXL) |
573 | : PackAttr(false), AlignMode(M), |
574 | PackNumber(M == Packed ? 1 : UninitPackVal), XLStack(IsXL) {} |
575 | |
576 | explicit AlignPackInfo(bool IsXL) : AlignPackInfo(Native, IsXL) {} |
577 | |
578 | AlignPackInfo() : AlignPackInfo(Native, false) {} |
579 | |
580 | // When a AlignPackInfo itself cannot be used, this returns an 32-bit |
581 | // integer encoding for it. This should only be passed to |
582 | // AlignPackInfo::getFromRawEncoding, it should not be inspected directly. |
583 | static uint32_t getRawEncoding(const AlignPackInfo &Info) { |
584 | std::uint32_t Encoding{}; |
585 | if (Info.IsXLStack()) |
586 | Encoding |= IsXLMask; |
587 | |
588 | Encoding |= static_cast<uint32_t>(Info.getAlignMode()) << 1; |
589 | |
590 | if (Info.IsPackAttr()) |
591 | Encoding |= PackAttrMask; |
592 | |
593 | Encoding |= static_cast<uint32_t>(Info.getPackNumber()) << 4; |
594 | |
595 | return Encoding; |
596 | } |
597 | |
598 | static AlignPackInfo getFromRawEncoding(unsigned Encoding) { |
599 | bool IsXL = static_cast<bool>(Encoding & IsXLMask); |
600 | AlignPackInfo::Mode M = |
601 | static_cast<AlignPackInfo::Mode>((Encoding & AlignModeMask) >> 1); |
602 | int PackNumber = (Encoding & PackNumMask) >> 4; |
603 | |
604 | if (Encoding & PackAttrMask) |
605 | return AlignPackInfo(M, PackNumber, IsXL); |
606 | |
607 | return AlignPackInfo(M, IsXL); |
608 | } |
609 | |
610 | bool IsPackAttr() const { return PackAttr; } |
611 | |
612 | bool IsAlignAttr() const { return !PackAttr; } |
613 | |
614 | Mode getAlignMode() const { return AlignMode; } |
615 | |
616 | unsigned getPackNumber() const { return PackNumber; } |
617 | |
618 | bool IsPackSet() const { |
619 | // #pragma align, #pragma pack(), and #pragma pack(0) do not set the pack |
620 | // attriute on a decl. |
621 | return PackNumber != UninitPackVal && PackNumber != 0; |
622 | } |
623 | |
624 | bool IsXLStack() const { return XLStack; } |
625 | |
626 | bool operator==(const AlignPackInfo &Info) const { |
627 | return std::tie(args: AlignMode, args: PackNumber, args: PackAttr, args: XLStack) == |
628 | std::tie(args: Info.AlignMode, args: Info.PackNumber, args: Info.PackAttr, |
629 | args: Info.XLStack); |
630 | } |
631 | |
632 | bool operator!=(const AlignPackInfo &Info) const { |
633 | return !(*this == Info); |
634 | } |
635 | |
636 | private: |
637 | /// \brief True if this is a pragma pack attribute, |
638 | /// not a pragma align attribute. |
639 | bool PackAttr; |
640 | |
641 | /// \brief The alignment mode that is in effect. |
642 | Mode AlignMode; |
643 | |
644 | /// \brief The pack number of the stack. |
645 | unsigned char PackNumber; |
646 | |
647 | /// \brief True if it is a XL #pragma align/pack stack. |
648 | bool XLStack; |
649 | |
650 | /// \brief Uninitialized pack value. |
651 | static constexpr unsigned char UninitPackVal = -1; |
652 | |
653 | // Masks to encode and decode an AlignPackInfo. |
654 | static constexpr uint32_t IsXLMask{0x0000'0001}; |
655 | static constexpr uint32_t AlignModeMask{0x0000'0006}; |
656 | static constexpr uint32_t PackAttrMask{0x00000'0008}; |
657 | static constexpr uint32_t PackNumMask{0x0000'01F0}; |
658 | }; |
659 | |
660 | template<typename ValueType> |
661 | struct PragmaStack { |
662 | struct Slot { |
663 | llvm::StringRef StackSlotLabel; |
664 | ValueType Value; |
665 | SourceLocation PragmaLocation; |
666 | SourceLocation PragmaPushLocation; |
667 | Slot(llvm::StringRef StackSlotLabel, ValueType Value, |
668 | SourceLocation PragmaLocation, SourceLocation PragmaPushLocation) |
669 | : StackSlotLabel(StackSlotLabel), Value(Value), |
670 | PragmaLocation(PragmaLocation), |
671 | PragmaPushLocation(PragmaPushLocation) {} |
672 | }; |
673 | |
674 | void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, |
675 | llvm::StringRef StackSlotLabel, ValueType Value) { |
676 | if (Action == PSK_Reset) { |
677 | CurrentValue = DefaultValue; |
678 | CurrentPragmaLocation = PragmaLocation; |
679 | return; |
680 | } |
681 | if (Action & PSK_Push) |
682 | Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation, |
683 | PragmaLocation); |
684 | else if (Action & PSK_Pop) { |
685 | if (!StackSlotLabel.empty()) { |
686 | // If we've got a label, try to find it and jump there. |
687 | auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) { |
688 | return x.StackSlotLabel == StackSlotLabel; |
689 | }); |
690 | // If we found the label so pop from there. |
691 | if (I != Stack.rend()) { |
692 | CurrentValue = I->Value; |
693 | CurrentPragmaLocation = I->PragmaLocation; |
694 | Stack.erase(std::prev(I.base()), Stack.end()); |
695 | } |
696 | } else if (!Stack.empty()) { |
697 | // We do not have a label, just pop the last entry. |
698 | CurrentValue = Stack.back().Value; |
699 | CurrentPragmaLocation = Stack.back().PragmaLocation; |
700 | Stack.pop_back(); |
701 | } |
702 | } |
703 | if (Action & PSK_Set) { |
704 | CurrentValue = Value; |
705 | CurrentPragmaLocation = PragmaLocation; |
706 | } |
707 | } |
708 | |
709 | // MSVC seems to add artificial slots to #pragma stacks on entering a C++ |
710 | // method body to restore the stacks on exit, so it works like this: |
711 | // |
712 | // struct S { |
713 | // #pragma <name>(push, InternalPragmaSlot, <current_pragma_value>) |
714 | // void Method {} |
715 | // #pragma <name>(pop, InternalPragmaSlot) |
716 | // }; |
717 | // |
718 | // It works even with #pragma vtordisp, although MSVC doesn't support |
719 | // #pragma vtordisp(push [, id], n) |
720 | // syntax. |
721 | // |
722 | // Push / pop a named sentinel slot. |
723 | void SentinelAction(PragmaMsStackAction Action, StringRef Label) { |
724 | assert((Action == PSK_Push || Action == PSK_Pop) && |
725 | "Can only push / pop #pragma stack sentinels!" ); |
726 | Act(PragmaLocation: CurrentPragmaLocation, Action, StackSlotLabel: Label, Value: CurrentValue); |
727 | } |
728 | |
729 | // Constructors. |
730 | explicit PragmaStack(const ValueType &Default) |
731 | : DefaultValue(Default), CurrentValue(Default) {} |
732 | |
733 | bool hasValue() const { return CurrentValue != DefaultValue; } |
734 | |
735 | SmallVector<Slot, 2> Stack; |
736 | ValueType DefaultValue; // Value used for PSK_Reset action. |
737 | ValueType CurrentValue; |
738 | SourceLocation CurrentPragmaLocation; |
739 | }; |
740 | // FIXME: We should serialize / deserialize these if they occur in a PCH (but |
741 | // we shouldn't do so if they're in a module). |
742 | |
743 | /// Whether to insert vtordisps prior to virtual bases in the Microsoft |
744 | /// C++ ABI. Possible values are 0, 1, and 2, which mean: |
745 | /// |
746 | /// 0: Suppress all vtordisps |
747 | /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial |
748 | /// structors |
749 | /// 2: Always insert vtordisps to support RTTI on partially constructed |
750 | /// objects |
751 | PragmaStack<MSVtorDispMode> VtorDispStack; |
752 | PragmaStack<AlignPackInfo> AlignPackStack; |
753 | // The current #pragma align/pack values and locations at each #include. |
754 | struct AlignPackIncludeState { |
755 | AlignPackInfo CurrentValue; |
756 | SourceLocation CurrentPragmaLocation; |
757 | bool HasNonDefaultValue, ShouldWarnOnInclude; |
758 | }; |
759 | SmallVector<AlignPackIncludeState, 8> AlignPackIncludeStack; |
760 | // Segment #pragmas. |
761 | PragmaStack<StringLiteral *> DataSegStack; |
762 | PragmaStack<StringLiteral *> BSSSegStack; |
763 | PragmaStack<StringLiteral *> ConstSegStack; |
764 | PragmaStack<StringLiteral *> CodeSegStack; |
765 | |
766 | // #pragma strict_gs_check. |
767 | PragmaStack<bool> StrictGuardStackCheckStack; |
768 | |
769 | // This stack tracks the current state of Sema.CurFPFeatures. |
770 | PragmaStack<FPOptionsOverride> FpPragmaStack; |
771 | FPOptionsOverride CurFPFeatureOverrides() { |
772 | FPOptionsOverride result; |
773 | if (!FpPragmaStack.hasValue()) { |
774 | result = FPOptionsOverride(); |
775 | } else { |
776 | result = FpPragmaStack.CurrentValue; |
777 | } |
778 | return result; |
779 | } |
780 | |
781 | // Saves the current floating-point pragma stack and clear it in this Sema. |
782 | class FpPragmaStackSaveRAII { |
783 | public: |
784 | FpPragmaStackSaveRAII(Sema &S) |
785 | : S(S), SavedStack(std::move(S.FpPragmaStack)) { |
786 | S.FpPragmaStack.Stack.clear(); |
787 | } |
788 | ~FpPragmaStackSaveRAII() { S.FpPragmaStack = std::move(SavedStack); } |
789 | |
790 | private: |
791 | Sema &S; |
792 | PragmaStack<FPOptionsOverride> SavedStack; |
793 | }; |
794 | |
795 | void resetFPOptions(FPOptions FPO) { |
796 | CurFPFeatures = FPO; |
797 | FpPragmaStack.CurrentValue = FPO.getChangesFrom(Base: FPOptions(LangOpts)); |
798 | } |
799 | |
800 | // RAII object to push / pop sentinel slots for all MS #pragma stacks. |
801 | // Actions should be performed only if we enter / exit a C++ method body. |
802 | class PragmaStackSentinelRAII { |
803 | public: |
804 | PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct); |
805 | ~PragmaStackSentinelRAII(); |
806 | |
807 | private: |
808 | Sema &S; |
809 | StringRef SlotLabel; |
810 | bool ShouldAct; |
811 | }; |
812 | |
813 | /// A mapping that describes the nullability we've seen in each header file. |
814 | FileNullabilityMap NullabilityMap; |
815 | |
816 | /// Last section used with #pragma init_seg. |
817 | StringLiteral *CurInitSeg; |
818 | SourceLocation CurInitSegLoc; |
819 | |
820 | /// Sections used with #pragma alloc_text. |
821 | llvm::StringMap<std::tuple<StringRef, SourceLocation>> FunctionToSectionMap; |
822 | |
823 | /// VisContext - Manages the stack for \#pragma GCC visibility. |
824 | void *VisContext; // Really a "PragmaVisStack*" |
825 | |
826 | /// This an attribute introduced by \#pragma clang attribute. |
827 | struct PragmaAttributeEntry { |
828 | SourceLocation Loc; |
829 | ParsedAttr *Attribute; |
830 | SmallVector<attr::SubjectMatchRule, 4> MatchRules; |
831 | bool IsUsed; |
832 | }; |
833 | |
834 | /// A push'd group of PragmaAttributeEntries. |
835 | struct PragmaAttributeGroup { |
836 | /// The location of the push attribute. |
837 | SourceLocation Loc; |
838 | /// The namespace of this push group. |
839 | const IdentifierInfo *Namespace; |
840 | SmallVector<PragmaAttributeEntry, 2> Entries; |
841 | }; |
842 | |
843 | SmallVector<PragmaAttributeGroup, 2> PragmaAttributeStack; |
844 | |
845 | /// The declaration that is currently receiving an attribute from the |
846 | /// #pragma attribute stack. |
847 | const Decl *PragmaAttributeCurrentTargetDecl; |
848 | |
849 | /// This represents the last location of a "#pragma clang optimize off" |
850 | /// directive if such a directive has not been closed by an "on" yet. If |
851 | /// optimizations are currently "on", this is set to an invalid location. |
852 | SourceLocation OptimizeOffPragmaLocation; |
853 | |
854 | /// The "on" or "off" argument passed by \#pragma optimize, that denotes |
855 | /// whether the optimizations in the list passed to the pragma should be |
856 | /// turned off or on. This boolean is true by default because command line |
857 | /// options are honored when `#pragma optimize("", on)`. |
858 | /// (i.e. `ModifyFnAttributeMSPragmaOptimze()` does nothing) |
859 | bool MSPragmaOptimizeIsOn = true; |
860 | |
861 | /// Set of no-builtin functions listed by \#pragma function. |
862 | llvm::SmallSetVector<StringRef, 4> MSFunctionNoBuiltins; |
863 | |
864 | /// Flag indicating if Sema is building a recovery call expression. |
865 | /// |
866 | /// This flag is used to avoid building recovery call expressions |
867 | /// if Sema is already doing so, which would cause infinite recursions. |
868 | bool IsBuildingRecoveryCallExpr; |
869 | |
870 | /// Used to control the generation of ExprWithCleanups. |
871 | CleanupInfo Cleanup; |
872 | |
873 | /// ExprCleanupObjects - This is the stack of objects requiring |
874 | /// cleanup that are created by the current full expression. |
875 | SmallVector<ExprWithCleanups::CleanupObject, 8> ExprCleanupObjects; |
876 | |
877 | /// Store a set of either DeclRefExprs or MemberExprs that contain a reference |
878 | /// to a variable (constant) that may or may not be odr-used in this Expr, and |
879 | /// we won't know until all lvalue-to-rvalue and discarded value conversions |
880 | /// have been applied to all subexpressions of the enclosing full expression. |
881 | /// This is cleared at the end of each full expression. |
882 | using MaybeODRUseExprSet = llvm::SmallSetVector<Expr *, 4>; |
883 | MaybeODRUseExprSet MaybeODRUseExprs; |
884 | |
885 | std::unique_ptr<sema::FunctionScopeInfo> CachedFunctionScope; |
886 | |
887 | /// Stack containing information about each of the nested |
888 | /// function, block, and method scopes that are currently active. |
889 | SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes; |
890 | |
891 | /// The index of the first FunctionScope that corresponds to the current |
892 | /// context. |
893 | unsigned FunctionScopesStart = 0; |
894 | |
895 | /// Track the number of currently active capturing scopes. |
896 | unsigned CapturingFunctionScopes = 0; |
897 | |
898 | ArrayRef<sema::FunctionScopeInfo*> getFunctionScopes() const { |
899 | return llvm::ArrayRef(FunctionScopes.begin() + FunctionScopesStart, |
900 | FunctionScopes.end()); |
901 | } |
902 | |
903 | /// Stack containing information needed when in C++2a an 'auto' is encountered |
904 | /// in a function declaration parameter type specifier in order to invent a |
905 | /// corresponding template parameter in the enclosing abbreviated function |
906 | /// template. This information is also present in LambdaScopeInfo, stored in |
907 | /// the FunctionScopes stack. |
908 | SmallVector<InventedTemplateParameterInfo, 4> InventedParameterInfos; |
909 | |
910 | /// The index of the first InventedParameterInfo that refers to the current |
911 | /// context. |
912 | unsigned InventedParameterInfosStart = 0; |
913 | |
914 | ArrayRef<InventedTemplateParameterInfo> getInventedParameterInfos() const { |
915 | return llvm::ArrayRef(InventedParameterInfos.begin() + |
916 | InventedParameterInfosStart, |
917 | InventedParameterInfos.end()); |
918 | } |
919 | |
920 | typedef LazyVector<TypedefNameDecl *, ExternalSemaSource, |
921 | &ExternalSemaSource::ReadExtVectorDecls, 2, 2> |
922 | ExtVectorDeclsType; |
923 | |
924 | /// ExtVectorDecls - This is a list all the extended vector types. This allows |
925 | /// us to associate a raw vector type with one of the ext_vector type names. |
926 | /// This is only necessary for issuing pretty diagnostics. |
927 | ExtVectorDeclsType ExtVectorDecls; |
928 | |
929 | /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. |
930 | std::unique_ptr<CXXFieldCollector> FieldCollector; |
931 | |
932 | typedef llvm::SmallSetVector<const NamedDecl *, 16> NamedDeclSetType; |
933 | |
934 | /// Set containing all declared private fields that are not used. |
935 | NamedDeclSetType UnusedPrivateFields; |
936 | |
937 | /// Set containing all typedefs that are likely unused. |
938 | llvm::SmallSetVector<const TypedefNameDecl *, 4> |
939 | UnusedLocalTypedefNameCandidates; |
940 | |
941 | /// Delete-expressions to be analyzed at the end of translation unit |
942 | /// |
943 | /// This list contains class members, and locations of delete-expressions |
944 | /// that could not be proven as to whether they mismatch with new-expression |
945 | /// used in initializer of the field. |
946 | typedef std::pair<SourceLocation, bool> DeleteExprLoc; |
947 | typedef llvm::SmallVector<DeleteExprLoc, 4> DeleteLocs; |
948 | llvm::MapVector<FieldDecl *, DeleteLocs> DeleteExprs; |
949 | |
950 | typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy; |
951 | |
952 | /// PureVirtualClassDiagSet - a set of class declarations which we have |
953 | /// emitted a list of pure virtual functions. Used to prevent emitting the |
954 | /// same list more than once. |
955 | std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet; |
956 | |
957 | /// ParsingInitForAutoVars - a set of declarations with auto types for which |
958 | /// we are currently parsing the initializer. |
959 | llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars; |
960 | |
961 | /// Look for a locally scoped extern "C" declaration by the given name. |
962 | NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name); |
963 | |
964 | typedef LazyVector<VarDecl *, ExternalSemaSource, |
965 | &ExternalSemaSource::ReadTentativeDefinitions, 2, 2> |
966 | TentativeDefinitionsType; |
967 | |
968 | /// All the tentative definitions encountered in the TU. |
969 | TentativeDefinitionsType TentativeDefinitions; |
970 | |
971 | /// All the external declarations encoutered and used in the TU. |
972 | SmallVector<VarDecl *, 4> ExternalDeclarations; |
973 | |
974 | typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource, |
975 | &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2> |
976 | UnusedFileScopedDeclsType; |
977 | |
978 | /// The set of file scoped decls seen so far that have not been used |
979 | /// and must warn if not used. Only contains the first declaration. |
980 | UnusedFileScopedDeclsType UnusedFileScopedDecls; |
981 | |
982 | typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource, |
983 | &ExternalSemaSource::ReadDelegatingConstructors, 2, 2> |
984 | DelegatingCtorDeclsType; |
985 | |
986 | /// All the delegating constructors seen so far in the file, used for |
987 | /// cycle detection at the end of the TU. |
988 | DelegatingCtorDeclsType DelegatingCtorDecls; |
989 | |
990 | /// All the overriding functions seen during a class definition |
991 | /// that had their exception spec checks delayed, plus the overridden |
992 | /// function. |
993 | SmallVector<std::pair<const CXXMethodDecl*, const CXXMethodDecl*>, 2> |
994 | DelayedOverridingExceptionSpecChecks; |
995 | |
996 | /// All the function redeclarations seen during a class definition that had |
997 | /// their exception spec checks delayed, plus the prior declaration they |
998 | /// should be checked against. Except during error recovery, the new decl |
999 | /// should always be a friend declaration, as that's the only valid way to |
1000 | /// redeclare a special member before its class is complete. |
1001 | SmallVector<std::pair<FunctionDecl*, FunctionDecl*>, 2> |
1002 | DelayedEquivalentExceptionSpecChecks; |
1003 | |
1004 | typedef llvm::MapVector<const FunctionDecl *, |
1005 | std::unique_ptr<LateParsedTemplate>> |
1006 | LateParsedTemplateMapT; |
1007 | LateParsedTemplateMapT LateParsedTemplateMap; |
1008 | |
1009 | /// Callback to the parser to parse templated functions when needed. |
1010 | typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT); |
1011 | typedef void LateTemplateParserCleanupCB(void *P); |
1012 | LateTemplateParserCB *LateTemplateParser; |
1013 | LateTemplateParserCleanupCB *LateTemplateParserCleanup; |
1014 | void *OpaqueParser; |
1015 | |
1016 | void SetLateTemplateParser(LateTemplateParserCB *LTP, |
1017 | LateTemplateParserCleanupCB *LTPCleanup, |
1018 | void *P) { |
1019 | LateTemplateParser = LTP; |
1020 | LateTemplateParserCleanup = LTPCleanup; |
1021 | OpaqueParser = P; |
1022 | } |
1023 | |
1024 | /// Callback to the parser to parse a type expressed as a string. |
1025 | std::function<TypeResult(StringRef, StringRef, SourceLocation)> |
1026 | ParseTypeFromStringCallback; |
1027 | |
1028 | class DelayedDiagnostics; |
1029 | |
1030 | class DelayedDiagnosticsState { |
1031 | sema::DelayedDiagnosticPool *SavedPool = nullptr; |
1032 | friend class Sema::DelayedDiagnostics; |
1033 | }; |
1034 | typedef DelayedDiagnosticsState ParsingDeclState; |
1035 | typedef DelayedDiagnosticsState ProcessingContextState; |
1036 | |
1037 | /// A class which encapsulates the logic for delaying diagnostics |
1038 | /// during parsing and other processing. |
1039 | class DelayedDiagnostics { |
1040 | /// The current pool of diagnostics into which delayed |
1041 | /// diagnostics should go. |
1042 | sema::DelayedDiagnosticPool *CurPool = nullptr; |
1043 | |
1044 | public: |
1045 | DelayedDiagnostics() = default; |
1046 | |
1047 | /// Adds a delayed diagnostic. |
1048 | void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h |
1049 | |
1050 | /// Determines whether diagnostics should be delayed. |
1051 | bool shouldDelayDiagnostics() { return CurPool != nullptr; } |
1052 | |
1053 | /// Returns the current delayed-diagnostics pool. |
1054 | sema::DelayedDiagnosticPool *getCurrentPool() const { |
1055 | return CurPool; |
1056 | } |
1057 | |
1058 | /// Enter a new scope. Access and deprecation diagnostics will be |
1059 | /// collected in this pool. |
1060 | DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) { |
1061 | DelayedDiagnosticsState state; |
1062 | state.SavedPool = CurPool; |
1063 | CurPool = &pool; |
1064 | return state; |
1065 | } |
1066 | |
1067 | /// Leave a delayed-diagnostic state that was previously pushed. |
1068 | /// Do not emit any of the diagnostics. This is performed as part |
1069 | /// of the bookkeeping of popping a pool "properly". |
1070 | void popWithoutEmitting(DelayedDiagnosticsState state) { |
1071 | CurPool = state.SavedPool; |
1072 | } |
1073 | |
1074 | /// Enter a new scope where access and deprecation diagnostics are |
1075 | /// not delayed. |
1076 | DelayedDiagnosticsState pushUndelayed() { |
1077 | DelayedDiagnosticsState state; |
1078 | state.SavedPool = CurPool; |
1079 | CurPool = nullptr; |
1080 | return state; |
1081 | } |
1082 | |
1083 | /// Undo a previous pushUndelayed(). |
1084 | void popUndelayed(DelayedDiagnosticsState state) { |
1085 | assert(CurPool == nullptr); |
1086 | CurPool = state.SavedPool; |
1087 | } |
1088 | } DelayedDiagnostics; |
1089 | |
1090 | enum CUDAFunctionTarget { |
1091 | CFT_Device, |
1092 | CFT_Global, |
1093 | CFT_Host, |
1094 | CFT_HostDevice, |
1095 | CFT_InvalidTarget |
1096 | }; |
1097 | |
1098 | /// A RAII object to temporarily push a declaration context. |
1099 | class { |
1100 | private: |
1101 | Sema &; |
1102 | DeclContext *; |
1103 | ProcessingContextState ; |
1104 | QualType ; |
1105 | unsigned ; |
1106 | unsigned ; |
1107 | |
1108 | public: |
1109 | (Sema &S, DeclContext *ContextToPush, bool NewThisContext = true) |
1110 | : S(S), SavedContext(S.CurContext), |
1111 | SavedContextState(S.DelayedDiagnostics.pushUndelayed()), |
1112 | SavedCXXThisTypeOverride(S.CXXThisTypeOverride), |
1113 | SavedFunctionScopesStart(S.FunctionScopesStart), |
1114 | SavedInventedParameterInfosStart(S.InventedParameterInfosStart) |
1115 | { |
1116 | assert(ContextToPush && "pushing null context" ); |
1117 | S.CurContext = ContextToPush; |
1118 | if (NewThisContext) |
1119 | S.CXXThisTypeOverride = QualType(); |
1120 | // Any saved FunctionScopes do not refer to this context. |
1121 | S.FunctionScopesStart = S.FunctionScopes.size(); |
1122 | S.InventedParameterInfosStart = S.InventedParameterInfos.size(); |
1123 | } |
1124 | |
1125 | void () { |
1126 | if (!SavedContext) return; |
1127 | S.CurContext = SavedContext; |
1128 | S.DelayedDiagnostics.popUndelayed(state: SavedContextState); |
1129 | S.CXXThisTypeOverride = SavedCXXThisTypeOverride; |
1130 | S.FunctionScopesStart = SavedFunctionScopesStart; |
1131 | S.InventedParameterInfosStart = SavedInventedParameterInfosStart; |
1132 | SavedContext = nullptr; |
1133 | } |
1134 | |
1135 | () { |
1136 | pop(); |
1137 | } |
1138 | }; |
1139 | |
1140 | /// RAII object to handle the state changes required to synthesize |
1141 | /// a function body. |
1142 | class SynthesizedFunctionScope { |
1143 | Sema &S; |
1144 | Sema::ContextRAII SavedContext; |
1145 | bool PushedCodeSynthesisContext = false; |
1146 | |
1147 | public: |
1148 | SynthesizedFunctionScope(Sema &S, DeclContext *DC) |
1149 | : S(S), SavedContext(S, DC) { |
1150 | auto *FD = dyn_cast<FunctionDecl>(Val: DC); |
1151 | S.PushFunctionScope(); |
1152 | S.PushExpressionEvaluationContext( |
1153 | NewContext: (FD && FD->isConsteval()) |
1154 | ? ExpressionEvaluationContext::ImmediateFunctionContext |
1155 | : ExpressionEvaluationContext::PotentiallyEvaluated); |
1156 | if (FD) { |
1157 | FD->setWillHaveBody(true); |
1158 | S.ExprEvalContexts.back().InImmediateFunctionContext = |
1159 | FD->isImmediateFunction(); |
1160 | S.ExprEvalContexts.back().InImmediateEscalatingFunctionContext = |
1161 | S.getLangOpts().CPlusPlus20 && FD->isImmediateEscalating(); |
1162 | } else |
1163 | assert(isa<ObjCMethodDecl>(DC)); |
1164 | } |
1165 | |
1166 | void addContextNote(SourceLocation UseLoc) { |
1167 | assert(!PushedCodeSynthesisContext); |
1168 | |
1169 | Sema::CodeSynthesisContext Ctx; |
1170 | Ctx.Kind = Sema::CodeSynthesisContext::DefiningSynthesizedFunction; |
1171 | Ctx.PointOfInstantiation = UseLoc; |
1172 | Ctx.Entity = cast<Decl>(Val: S.CurContext); |
1173 | S.pushCodeSynthesisContext(Ctx); |
1174 | |
1175 | PushedCodeSynthesisContext = true; |
1176 | } |
1177 | |
1178 | ~SynthesizedFunctionScope() { |
1179 | if (PushedCodeSynthesisContext) |
1180 | S.popCodeSynthesisContext(); |
1181 | if (auto *FD = dyn_cast<FunctionDecl>(Val: S.CurContext)) { |
1182 | FD->setWillHaveBody(false); |
1183 | S.CheckImmediateEscalatingFunctionDefinition(FD, FSI: S.getCurFunction()); |
1184 | } |
1185 | S.PopExpressionEvaluationContext(); |
1186 | S.PopFunctionScopeInfo(); |
1187 | } |
1188 | }; |
1189 | |
1190 | /// WeakUndeclaredIdentifiers - Identifiers contained in \#pragma weak before |
1191 | /// declared. Rare. May alias another identifier, declared or undeclared. |
1192 | /// |
1193 | /// For aliases, the target identifier is used as a key for eventual |
1194 | /// processing when the target is declared. For the single-identifier form, |
1195 | /// the sole identifier is used as the key. Each entry is a `SetVector` |
1196 | /// (ordered by parse order) of aliases (identified by the alias name) in case |
1197 | /// of multiple aliases to the same undeclared identifier. |
1198 | llvm::MapVector< |
1199 | IdentifierInfo *, |
1200 | llvm::SetVector< |
1201 | WeakInfo, llvm::SmallVector<WeakInfo, 1u>, |
1202 | llvm::SmallDenseSet<WeakInfo, 2u, WeakInfo::DenseMapInfoByAliasOnly>>> |
1203 | WeakUndeclaredIdentifiers; |
1204 | |
1205 | /// ExtnameUndeclaredIdentifiers - Identifiers contained in |
1206 | /// \#pragma redefine_extname before declared. Used in Solaris system headers |
1207 | /// to define functions that occur in multiple standards to call the version |
1208 | /// in the currently selected standard. |
1209 | llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers; |
1210 | |
1211 | |
1212 | /// Load weak undeclared identifiers from the external source. |
1213 | void LoadExternalWeakUndeclaredIdentifiers(); |
1214 | |
1215 | /// WeakTopLevelDecl - Translation-unit scoped declarations generated by |
1216 | /// \#pragma weak during processing of other Decls. |
1217 | /// I couldn't figure out a clean way to generate these in-line, so |
1218 | /// we store them here and handle separately -- which is a hack. |
1219 | /// It would be best to refactor this. |
1220 | SmallVector<Decl*,2> WeakTopLevelDecl; |
1221 | |
1222 | IdentifierResolver IdResolver; |
1223 | |
1224 | /// Translation Unit Scope - useful to Objective-C actions that need |
1225 | /// to lookup file scope declarations in the "ordinary" C decl namespace. |
1226 | /// For example, user-defined classes, built-in "id" type, etc. |
1227 | Scope *TUScope; |
1228 | |
1229 | /// The C++ "std" namespace, where the standard library resides. |
1230 | LazyDeclPtr StdNamespace; |
1231 | |
1232 | /// The C++ "std::bad_alloc" class, which is defined by the C++ |
1233 | /// standard library. |
1234 | LazyDeclPtr StdBadAlloc; |
1235 | |
1236 | /// The C++ "std::align_val_t" enum class, which is defined by the C++ |
1237 | /// standard library. |
1238 | LazyDeclPtr StdAlignValT; |
1239 | |
1240 | /// The C++ "std::initializer_list" template, which is defined in |
1241 | /// \<initializer_list>. |
1242 | ClassTemplateDecl *StdInitializerList; |
1243 | |
1244 | /// The C++ "std::coroutine_traits" template, which is defined in |
1245 | /// \<coroutine_traits> |
1246 | ClassTemplateDecl *StdCoroutineTraitsCache; |
1247 | |
1248 | /// The C++ "type_info" declaration, which is defined in \<typeinfo>. |
1249 | RecordDecl *CXXTypeInfoDecl; |
1250 | |
1251 | /// The C++ "std::source_location::__impl" struct, defined in |
1252 | /// \<source_location>. |
1253 | RecordDecl *StdSourceLocationImplDecl; |
1254 | |
1255 | /// Caches identifiers/selectors for NSFoundation APIs. |
1256 | std::unique_ptr<NSAPI> NSAPIObj; |
1257 | |
1258 | /// The declaration of the Objective-C NSNumber class. |
1259 | ObjCInterfaceDecl *NSNumberDecl; |
1260 | |
1261 | /// The declaration of the Objective-C NSValue class. |
1262 | ObjCInterfaceDecl *NSValueDecl; |
1263 | |
1264 | /// Pointer to NSNumber type (NSNumber *). |
1265 | QualType NSNumberPointer; |
1266 | |
1267 | /// Pointer to NSValue type (NSValue *). |
1268 | QualType NSValuePointer; |
1269 | |
1270 | /// The Objective-C NSNumber methods used to create NSNumber literals. |
1271 | ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]; |
1272 | |
1273 | /// The declaration of the Objective-C NSString class. |
1274 | ObjCInterfaceDecl *NSStringDecl; |
1275 | |
1276 | /// Pointer to NSString type (NSString *). |
1277 | QualType NSStringPointer; |
1278 | |
1279 | /// The declaration of the stringWithUTF8String: method. |
1280 | ObjCMethodDecl *StringWithUTF8StringMethod; |
1281 | |
1282 | /// The declaration of the valueWithBytes:objCType: method. |
1283 | ObjCMethodDecl *ValueWithBytesObjCTypeMethod; |
1284 | |
1285 | /// The declaration of the Objective-C NSArray class. |
1286 | ObjCInterfaceDecl *NSArrayDecl; |
1287 | |
1288 | /// The declaration of the arrayWithObjects:count: method. |
1289 | ObjCMethodDecl *ArrayWithObjectsMethod; |
1290 | |
1291 | /// The declaration of the Objective-C NSDictionary class. |
1292 | ObjCInterfaceDecl *NSDictionaryDecl; |
1293 | |
1294 | /// The declaration of the dictionaryWithObjects:forKeys:count: method. |
1295 | ObjCMethodDecl *DictionaryWithObjectsMethod; |
1296 | |
1297 | /// id<NSCopying> type. |
1298 | QualType QIDNSCopying; |
1299 | |
1300 | /// will hold 'respondsToSelector:' |
1301 | Selector RespondsToSelectorSel; |
1302 | |
1303 | /// A flag to remember whether the implicit forms of operator new and delete |
1304 | /// have been declared. |
1305 | bool GlobalNewDeleteDeclared; |
1306 | |
1307 | /// Describes how the expressions currently being parsed are |
1308 | /// evaluated at run-time, if at all. |
1309 | enum class ExpressionEvaluationContext { |
1310 | /// The current expression and its subexpressions occur within an |
1311 | /// unevaluated operand (C++11 [expr]p7), such as the subexpression of |
1312 | /// \c sizeof, where the type of the expression may be significant but |
1313 | /// no code will be generated to evaluate the value of the expression at |
1314 | /// run time. |
1315 | Unevaluated, |
1316 | |
1317 | /// The current expression occurs within a braced-init-list within |
1318 | /// an unevaluated operand. This is mostly like a regular unevaluated |
1319 | /// context, except that we still instantiate constexpr functions that are |
1320 | /// referenced here so that we can perform narrowing checks correctly. |
1321 | UnevaluatedList, |
1322 | |
1323 | /// The current expression occurs within a discarded statement. |
1324 | /// This behaves largely similarly to an unevaluated operand in preventing |
1325 | /// definitions from being required, but not in other ways. |
1326 | DiscardedStatement, |
1327 | |
1328 | /// The current expression occurs within an unevaluated |
1329 | /// operand that unconditionally permits abstract references to |
1330 | /// fields, such as a SIZE operator in MS-style inline assembly. |
1331 | UnevaluatedAbstract, |
1332 | |
1333 | /// The current context is "potentially evaluated" in C++11 terms, |
1334 | /// but the expression is evaluated at compile-time (like the values of |
1335 | /// cases in a switch statement). |
1336 | ConstantEvaluated, |
1337 | |
1338 | /// In addition of being constant evaluated, the current expression |
1339 | /// occurs in an immediate function context - either a consteval function |
1340 | /// or a consteval if statement. |
1341 | ImmediateFunctionContext, |
1342 | |
1343 | /// The current expression is potentially evaluated at run time, |
1344 | /// which means that code may be generated to evaluate the value of the |
1345 | /// expression at run time. |
1346 | PotentiallyEvaluated, |
1347 | |
1348 | /// The current expression is potentially evaluated, but any |
1349 | /// declarations referenced inside that expression are only used if |
1350 | /// in fact the current expression is used. |
1351 | /// |
1352 | /// This value is used when parsing default function arguments, for which |
1353 | /// we would like to provide diagnostics (e.g., passing non-POD arguments |
1354 | /// through varargs) but do not want to mark declarations as "referenced" |
1355 | /// until the default argument is used. |
1356 | PotentiallyEvaluatedIfUsed |
1357 | }; |
1358 | |
1359 | using ImmediateInvocationCandidate = llvm::PointerIntPair<ConstantExpr *, 1>; |
1360 | |
1361 | /// Data structure used to record current or nested |
1362 | /// expression evaluation contexts. |
1363 | struct ExpressionEvaluationContextRecord { |
1364 | /// The expression evaluation context. |
1365 | ExpressionEvaluationContext Context; |
1366 | |
1367 | /// Whether the enclosing context needed a cleanup. |
1368 | CleanupInfo ParentCleanup; |
1369 | |
1370 | /// The number of active cleanup objects when we entered |
1371 | /// this expression evaluation context. |
1372 | unsigned NumCleanupObjects; |
1373 | |
1374 | /// The number of typos encountered during this expression evaluation |
1375 | /// context (i.e. the number of TypoExprs created). |
1376 | unsigned NumTypos; |
1377 | |
1378 | MaybeODRUseExprSet SavedMaybeODRUseExprs; |
1379 | |
1380 | /// The lambdas that are present within this context, if it |
1381 | /// is indeed an unevaluated context. |
1382 | SmallVector<LambdaExpr *, 2> Lambdas; |
1383 | |
1384 | /// The declaration that provides context for lambda expressions |
1385 | /// and block literals if the normal declaration context does not |
1386 | /// suffice, e.g., in a default function argument. |
1387 | Decl *ManglingContextDecl; |
1388 | |
1389 | /// If we are processing a decltype type, a set of call expressions |
1390 | /// for which we have deferred checking the completeness of the return type. |
1391 | SmallVector<CallExpr *, 8> DelayedDecltypeCalls; |
1392 | |
1393 | /// If we are processing a decltype type, a set of temporary binding |
1394 | /// expressions for which we have deferred checking the destructor. |
1395 | SmallVector<CXXBindTemporaryExpr *, 8> DelayedDecltypeBinds; |
1396 | |
1397 | llvm::SmallPtrSet<const Expr *, 8> PossibleDerefs; |
1398 | |
1399 | /// Expressions appearing as the LHS of a volatile assignment in this |
1400 | /// context. We produce a warning for these when popping the context if |
1401 | /// they are not discarded-value expressions nor unevaluated operands. |
1402 | SmallVector<Expr*, 2> VolatileAssignmentLHSs; |
1403 | |
1404 | /// Set of candidates for starting an immediate invocation. |
1405 | llvm::SmallVector<ImmediateInvocationCandidate, 4> ImmediateInvocationCandidates; |
1406 | |
1407 | /// Set of DeclRefExprs referencing a consteval function when used in a |
1408 | /// context not already known to be immediately invoked. |
1409 | llvm::SmallPtrSet<DeclRefExpr *, 4> ReferenceToConsteval; |
1410 | |
1411 | /// P2718R0 - Lifetime extension in range-based for loops. |
1412 | /// MaterializeTemporaryExprs in for-range-init expressions which need to |
1413 | /// extend lifetime. Add MaterializeTemporaryExpr* if the value of |
1414 | /// InLifetimeExtendingContext is true. |
1415 | SmallVector<MaterializeTemporaryExpr *, 8> ForRangeLifetimeExtendTemps; |
1416 | |
1417 | /// \brief Describes whether we are in an expression constext which we have |
1418 | /// to handle differently. |
1419 | enum ExpressionKind { |
1420 | EK_Decltype, EK_TemplateArgument, EK_Other |
1421 | } ExprContext; |
1422 | |
1423 | // A context can be nested in both a discarded statement context and |
1424 | // an immediate function context, so they need to be tracked independently. |
1425 | bool InDiscardedStatement; |
1426 | bool InImmediateFunctionContext; |
1427 | bool InImmediateEscalatingFunctionContext; |
1428 | |
1429 | bool IsCurrentlyCheckingDefaultArgumentOrInitializer = false; |
1430 | |
1431 | // We are in a constant context, but we also allow |
1432 | // non constant expressions, for example for array bounds (which may be |
1433 | // VLAs). |
1434 | bool InConditionallyConstantEvaluateContext = false; |
1435 | |
1436 | /// Whether we are currently in a context in which all temporaries must be |
1437 | /// lifetime-extended, even if they're not bound to a reference (for |
1438 | /// example, in a for-range initializer). |
1439 | bool InLifetimeExtendingContext = false; |
1440 | |
1441 | /// Whether we are currently in a context in which all temporaries must be |
1442 | /// materialized. |
1443 | /// |
1444 | /// [class.temporary]/p2: |
1445 | /// The materialization of a temporary object is generally delayed as long |
1446 | /// as possible in order to avoid creating unnecessary temporary objects. |
1447 | /// |
1448 | /// Temporary objects are materialized: |
1449 | /// (2.1) when binding a reference to a prvalue ([dcl.init.ref], |
1450 | /// [expr.type.conv], [expr.dynamic.cast], [expr.static.cast], |
1451 | /// [expr.const.cast], [expr.cast]), |
1452 | /// |
1453 | /// (2.2) when performing member access on a class prvalue ([expr.ref], |
1454 | /// [expr.mptr.oper]), |
1455 | /// |
1456 | /// (2.3) when performing an array-to-pointer conversion or subscripting |
1457 | /// on an array prvalue ([conv.array], [expr.sub]), |
1458 | /// |
1459 | /// (2.4) when initializing an object of type |
1460 | /// std​::​initializer_list<T> from a braced-init-list |
1461 | /// ([dcl.init.list]), |
1462 | /// |
1463 | /// (2.5) for certain unevaluated operands ([expr.typeid], [expr.sizeof]) |
1464 | /// |
1465 | /// (2.6) when a prvalue that has type other than cv void appears as a |
1466 | /// discarded-value expression ([expr.context]). |
1467 | bool InMaterializeTemporaryObjectContext = false; |
1468 | |
1469 | // When evaluating immediate functions in the initializer of a default |
1470 | // argument or default member initializer, this is the declaration whose |
1471 | // default initializer is being evaluated and the location of the call |
1472 | // or constructor definition. |
1473 | struct InitializationContext { |
1474 | InitializationContext(SourceLocation Loc, ValueDecl *Decl, |
1475 | DeclContext *Context) |
1476 | : Loc(Loc), Decl(Decl), Context(Context) { |
1477 | assert(Decl && Context && "invalid initialization context" ); |
1478 | } |
1479 | |
1480 | SourceLocation Loc; |
1481 | ValueDecl *Decl = nullptr; |
1482 | DeclContext *Context = nullptr; |
1483 | }; |
1484 | std::optional<InitializationContext> DelayedDefaultInitializationContext; |
1485 | |
1486 | ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context, |
1487 | unsigned NumCleanupObjects, |
1488 | CleanupInfo ParentCleanup, |
1489 | Decl *ManglingContextDecl, |
1490 | ExpressionKind ExprContext) |
1491 | : Context(Context), ParentCleanup(ParentCleanup), |
1492 | NumCleanupObjects(NumCleanupObjects), NumTypos(0), |
1493 | ManglingContextDecl(ManglingContextDecl), ExprContext(ExprContext), |
1494 | InDiscardedStatement(false), InImmediateFunctionContext(false), |
1495 | InImmediateEscalatingFunctionContext(false) {} |
1496 | |
1497 | bool isUnevaluated() const { |
1498 | return Context == ExpressionEvaluationContext::Unevaluated || |
1499 | Context == ExpressionEvaluationContext::UnevaluatedAbstract || |
1500 | Context == ExpressionEvaluationContext::UnevaluatedList; |
1501 | } |
1502 | |
1503 | bool isConstantEvaluated() const { |
1504 | return Context == ExpressionEvaluationContext::ConstantEvaluated || |
1505 | Context == ExpressionEvaluationContext::ImmediateFunctionContext; |
1506 | } |
1507 | |
1508 | bool isImmediateFunctionContext() const { |
1509 | return Context == ExpressionEvaluationContext::ImmediateFunctionContext || |
1510 | (Context == ExpressionEvaluationContext::DiscardedStatement && |
1511 | InImmediateFunctionContext) || |
1512 | // C++23 [expr.const]p14: |
1513 | // An expression or conversion is in an immediate function |
1514 | // context if it is potentially evaluated and either: |
1515 | // * its innermost enclosing non-block scope is a function |
1516 | // parameter scope of an immediate function, or |
1517 | // * its enclosing statement is enclosed by the compound- |
1518 | // statement of a consteval if statement. |
1519 | (Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
1520 | InImmediateFunctionContext); |
1521 | } |
1522 | |
1523 | bool isDiscardedStatementContext() const { |
1524 | return Context == ExpressionEvaluationContext::DiscardedStatement || |
1525 | (Context == |
1526 | ExpressionEvaluationContext::ImmediateFunctionContext && |
1527 | InDiscardedStatement); |
1528 | } |
1529 | }; |
1530 | |
1531 | /// A stack of expression evaluation contexts. |
1532 | SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts; |
1533 | |
1534 | // Set of failed immediate invocations to avoid double diagnosing. |
1535 | llvm::SmallPtrSet<ConstantExpr *, 4> FailedImmediateInvocations; |
1536 | |
1537 | /// Emit a warning for all pending noderef expressions that we recorded. |
1538 | void WarnOnPendingNoDerefs(ExpressionEvaluationContextRecord &Rec); |
1539 | |
1540 | /// Compute the mangling number context for a lambda expression or |
1541 | /// block literal. Also return the extra mangling decl if any. |
1542 | /// |
1543 | /// \param DC - The DeclContext containing the lambda expression or |
1544 | /// block literal. |
1545 | std::tuple<MangleNumberingContext *, Decl *> |
1546 | getCurrentMangleNumberContext(const DeclContext *DC); |
1547 | |
1548 | |
1549 | /// SpecialMemberOverloadResult - The overloading result for a special member |
1550 | /// function. |
1551 | /// |
1552 | /// This is basically a wrapper around PointerIntPair. The lowest bits of the |
1553 | /// integer are used to determine whether overload resolution succeeded. |
1554 | class SpecialMemberOverloadResult { |
1555 | public: |
1556 | enum Kind { |
1557 | NoMemberOrDeleted, |
1558 | Ambiguous, |
1559 | Success |
1560 | }; |
1561 | |
1562 | private: |
1563 | llvm::PointerIntPair<CXXMethodDecl *, 2> Pair; |
1564 | |
1565 | public: |
1566 | SpecialMemberOverloadResult() {} |
1567 | SpecialMemberOverloadResult(CXXMethodDecl *MD) |
1568 | : Pair(MD, MD->isDeleted() ? NoMemberOrDeleted : Success) {} |
1569 | |
1570 | CXXMethodDecl *getMethod() const { return Pair.getPointer(); } |
1571 | void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); } |
1572 | |
1573 | Kind getKind() const { return static_cast<Kind>(Pair.getInt()); } |
1574 | void setKind(Kind K) { Pair.setInt(K); } |
1575 | }; |
1576 | |
1577 | class SpecialMemberOverloadResultEntry |
1578 | : public llvm::FastFoldingSetNode, |
1579 | public SpecialMemberOverloadResult { |
1580 | public: |
1581 | SpecialMemberOverloadResultEntry(const llvm::FoldingSetNodeID &ID) |
1582 | : FastFoldingSetNode(ID) |
1583 | {} |
1584 | }; |
1585 | |
1586 | /// A cache of special member function overload resolution results |
1587 | /// for C++ records. |
1588 | llvm::FoldingSet<SpecialMemberOverloadResultEntry> SpecialMemberCache; |
1589 | |
1590 | /// A cache of the flags available in enumerations with the flag_bits |
1591 | /// attribute. |
1592 | mutable llvm::DenseMap<const EnumDecl*, llvm::APInt> FlagBitsCache; |
1593 | |
1594 | /// The kind of translation unit we are processing. |
1595 | /// |
1596 | /// When we're processing a complete translation unit, Sema will perform |
1597 | /// end-of-translation-unit semantic tasks (such as creating |
1598 | /// initializers for tentative definitions in C) once parsing has |
1599 | /// completed. Modules and precompiled headers perform different kinds of |
1600 | /// checks. |
1601 | const TranslationUnitKind TUKind; |
1602 | |
1603 | llvm::BumpPtrAllocator BumpAlloc; |
1604 | |
1605 | /// The number of SFINAE diagnostics that have been trapped. |
1606 | unsigned NumSFINAEErrors; |
1607 | |
1608 | typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>> |
1609 | UnparsedDefaultArgInstantiationsMap; |
1610 | |
1611 | /// A mapping from parameters with unparsed default arguments to the |
1612 | /// set of instantiations of each parameter. |
1613 | /// |
1614 | /// This mapping is a temporary data structure used when parsing |
1615 | /// nested class templates or nested classes of class templates, |
1616 | /// where we might end up instantiating an inner class before the |
1617 | /// default arguments of its methods have been parsed. |
1618 | UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations; |
1619 | |
1620 | // Contains the locations of the beginning of unparsed default |
1621 | // argument locations. |
1622 | llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs; |
1623 | |
1624 | /// UndefinedInternals - all the used, undefined objects which require a |
1625 | /// definition in this translation unit. |
1626 | llvm::MapVector<NamedDecl *, SourceLocation> UndefinedButUsed; |
1627 | |
1628 | /// Determine if VD, which must be a variable or function, is an external |
1629 | /// symbol that nonetheless can't be referenced from outside this translation |
1630 | /// unit because its type has no linkage and it's not extern "C". |
1631 | bool isExternalWithNoLinkageType(const ValueDecl *VD) const; |
1632 | |
1633 | /// Obtain a sorted list of functions that are undefined but ODR-used. |
1634 | void getUndefinedButUsed( |
1635 | SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined); |
1636 | |
1637 | /// Retrieves list of suspicious delete-expressions that will be checked at |
1638 | /// the end of translation unit. |
1639 | const llvm::MapVector<FieldDecl *, DeleteLocs> & |
1640 | getMismatchingDeleteExpressions() const; |
1641 | |
1642 | class GlobalMethodPool { |
1643 | public: |
1644 | using Lists = std::pair<ObjCMethodList, ObjCMethodList>; |
1645 | using iterator = llvm::DenseMap<Selector, Lists>::iterator; |
1646 | iterator begin() { return Methods.begin(); } |
1647 | iterator end() { return Methods.end(); } |
1648 | iterator find(Selector Sel) { return Methods.find(Val: Sel); } |
1649 | std::pair<iterator, bool> insert(std::pair<Selector, Lists> &&Val) { |
1650 | return Methods.insert(KV: Val); |
1651 | } |
1652 | int count(Selector Sel) const { return Methods.count(Val: Sel); } |
1653 | bool empty() const { return Methods.empty(); } |
1654 | |
1655 | private: |
1656 | llvm::DenseMap<Selector, Lists> Methods; |
1657 | }; |
1658 | |
1659 | /// Method Pool - allows efficient lookup when typechecking messages to "id". |
1660 | /// We need to maintain a list, since selectors can have differing signatures |
1661 | /// across classes. In Cocoa, this happens to be extremely uncommon (only 1% |
1662 | /// of selectors are "overloaded"). |
1663 | /// At the head of the list it is recorded whether there were 0, 1, or >= 2 |
1664 | /// methods inside categories with a particular selector. |
1665 | GlobalMethodPool MethodPool; |
1666 | |
1667 | /// Method selectors used in a \@selector expression. Used for implementation |
1668 | /// of -Wselector. |
1669 | llvm::MapVector<Selector, SourceLocation> ReferencedSelectors; |
1670 | |
1671 | /// List of SourceLocations where 'self' is implicitly retained inside a |
1672 | /// block. |
1673 | llvm::SmallVector<std::pair<SourceLocation, const BlockDecl *>, 1> |
1674 | ImplicitlyRetainedSelfLocs; |
1675 | |
1676 | /// Kinds of C++ special members. |
1677 | enum CXXSpecialMember { |
1678 | CXXDefaultConstructor, |
1679 | CXXCopyConstructor, |
1680 | CXXMoveConstructor, |
1681 | CXXCopyAssignment, |
1682 | CXXMoveAssignment, |
1683 | CXXDestructor, |
1684 | CXXInvalid |
1685 | }; |
1686 | |
1687 | typedef llvm::PointerIntPair<CXXRecordDecl *, 3, CXXSpecialMember> |
1688 | SpecialMemberDecl; |
1689 | |
1690 | /// The C++ special members which we are currently in the process of |
1691 | /// declaring. If this process recursively triggers the declaration of the |
1692 | /// same special member, we should act as if it is not yet declared. |
1693 | llvm::SmallPtrSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared; |
1694 | |
1695 | /// Kinds of defaulted comparison operator functions. |
1696 | enum class DefaultedComparisonKind : unsigned char { |
1697 | /// This is not a defaultable comparison operator. |
1698 | None, |
1699 | /// This is an operator== that should be implemented as a series of |
1700 | /// subobject comparisons. |
1701 | Equal, |
1702 | /// This is an operator<=> that should be implemented as a series of |
1703 | /// subobject comparisons. |
1704 | ThreeWay, |
1705 | /// This is an operator!= that should be implemented as a rewrite in terms |
1706 | /// of a == comparison. |
1707 | NotEqual, |
1708 | /// This is an <, <=, >, or >= that should be implemented as a rewrite in |
1709 | /// terms of a <=> comparison. |
1710 | Relational, |
1711 | }; |
1712 | |
1713 | /// The function definitions which were renamed as part of typo-correction |
1714 | /// to match their respective declarations. We want to keep track of them |
1715 | /// to ensure that we don't emit a "redefinition" error if we encounter a |
1716 | /// correctly named definition after the renamed definition. |
1717 | llvm::SmallPtrSet<const NamedDecl *, 4> TypoCorrectedFunctionDefinitions; |
1718 | |
1719 | /// Stack of types that correspond to the parameter entities that are |
1720 | /// currently being copy-initialized. Can be empty. |
1721 | llvm::SmallVector<QualType, 4> CurrentParameterCopyTypes; |
1722 | |
1723 | void ReadMethodPool(Selector Sel); |
1724 | void updateOutOfDateSelector(Selector Sel); |
1725 | |
1726 | /// Private Helper predicate to check for 'self'. |
1727 | bool isSelfExpr(Expr *RExpr); |
1728 | bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method); |
1729 | |
1730 | /// Cause the active diagnostic on the DiagosticsEngine to be |
1731 | /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and |
1732 | /// should not be used elsewhere. |
1733 | void EmitCurrentDiagnostic(unsigned DiagID); |
1734 | |
1735 | /// Records and restores the CurFPFeatures state on entry/exit of compound |
1736 | /// statements. |
1737 | class FPFeaturesStateRAII { |
1738 | public: |
1739 | FPFeaturesStateRAII(Sema &S); |
1740 | ~FPFeaturesStateRAII(); |
1741 | FPOptionsOverride getOverrides() { return OldOverrides; } |
1742 | |
1743 | private: |
1744 | Sema& S; |
1745 | FPOptions OldFPFeaturesState; |
1746 | FPOptionsOverride OldOverrides; |
1747 | LangOptions::FPEvalMethodKind OldEvalMethod; |
1748 | SourceLocation OldFPPragmaLocation; |
1749 | }; |
1750 | |
1751 | void addImplicitTypedef(StringRef Name, QualType T); |
1752 | |
1753 | bool WarnedStackExhausted = false; |
1754 | |
1755 | /// Increment when we find a reference; decrement when we find an ignored |
1756 | /// assignment. Ultimately the value is 0 if every reference is an ignored |
1757 | /// assignment. |
1758 | llvm::DenseMap<const VarDecl *, int> RefsMinusAssignments; |
1759 | |
1760 | /// Indicate RISC-V vector builtin functions enabled or not. |
1761 | bool DeclareRISCVVBuiltins = false; |
1762 | |
1763 | /// Indicate RISC-V SiFive vector builtin functions enabled or not. |
1764 | bool DeclareRISCVSiFiveVectorBuiltins = false; |
1765 | |
1766 | private: |
1767 | std::unique_ptr<sema::RISCVIntrinsicManager> RVIntrinsicManager; |
1768 | |
1769 | std::optional<std::unique_ptr<DarwinSDKInfo>> CachedDarwinSDKInfo; |
1770 | |
1771 | bool WarnedDarwinSDKInfoMissing = false; |
1772 | |
1773 | public: |
1774 | Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, |
1775 | TranslationUnitKind TUKind = TU_Complete, |
1776 | CodeCompleteConsumer *CompletionConsumer = nullptr); |
1777 | ~Sema(); |
1778 | |
1779 | /// Perform initialization that occurs after the parser has been |
1780 | /// initialized but before it parses anything. |
1781 | void Initialize(); |
1782 | |
1783 | /// This virtual key function only exists to limit the emission of debug info |
1784 | /// describing the Sema class. GCC and Clang only emit debug info for a class |
1785 | /// with a vtable when the vtable is emitted. Sema is final and not |
1786 | /// polymorphic, but the debug info size savings are so significant that it is |
1787 | /// worth adding a vtable just to take advantage of this optimization. |
1788 | virtual void anchor(); |
1789 | |
1790 | const LangOptions &getLangOpts() const { return LangOpts; } |
1791 | OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; } |
1792 | FPOptions &getCurFPFeatures() { return CurFPFeatures; } |
1793 | |
1794 | DiagnosticsEngine &getDiagnostics() const { return Diags; } |
1795 | SourceManager &getSourceManager() const { return SourceMgr; } |
1796 | Preprocessor &getPreprocessor() const { return PP; } |
1797 | ASTContext &getASTContext() const { return Context; } |
1798 | ASTConsumer &getASTConsumer() const { return Consumer; } |
1799 | ASTMutationListener *getASTMutationListener() const; |
1800 | ExternalSemaSource *getExternalSource() const { return ExternalSource.get(); } |
1801 | |
1802 | DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(SourceLocation Loc, |
1803 | StringRef Platform); |
1804 | DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(); |
1805 | |
1806 | ///Registers an external source. If an external source already exists, |
1807 | /// creates a multiplex external source and appends to it. |
1808 | /// |
1809 | ///\param[in] E - A non-null external sema source. |
1810 | /// |
1811 | void addExternalSource(ExternalSemaSource *E); |
1812 | |
1813 | void PrintStats() const; |
1814 | |
1815 | /// Warn that the stack is nearly exhausted. |
1816 | void warnStackExhausted(SourceLocation Loc); |
1817 | |
1818 | /// Run some code with "sufficient" stack space. (Currently, at least 256K is |
1819 | /// guaranteed). Produces a warning if we're low on stack space and allocates |
1820 | /// more in that case. Use this in code that may recurse deeply (for example, |
1821 | /// in template instantiation) to avoid stack overflow. |
1822 | void runWithSufficientStackSpace(SourceLocation Loc, |
1823 | llvm::function_ref<void()> Fn); |
1824 | |
1825 | /// Helper class that creates diagnostics with optional |
1826 | /// template instantiation stacks. |
1827 | /// |
1828 | /// This class provides a wrapper around the basic DiagnosticBuilder |
1829 | /// class that emits diagnostics. ImmediateDiagBuilder is |
1830 | /// responsible for emitting the diagnostic (as DiagnosticBuilder |
1831 | /// does) and, if the diagnostic comes from inside a template |
1832 | /// instantiation, printing the template instantiation stack as |
1833 | /// well. |
1834 | class ImmediateDiagBuilder : public DiagnosticBuilder { |
1835 | Sema &SemaRef; |
1836 | unsigned DiagID; |
1837 | |
1838 | public: |
1839 | ImmediateDiagBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID) |
1840 | : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) {} |
1841 | ImmediateDiagBuilder(DiagnosticBuilder &&DB, Sema &SemaRef, unsigned DiagID) |
1842 | : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) {} |
1843 | |
1844 | // This is a cunning lie. DiagnosticBuilder actually performs move |
1845 | // construction in its copy constructor (but due to varied uses, it's not |
1846 | // possible to conveniently express this as actual move construction). So |
1847 | // the default copy ctor here is fine, because the base class disables the |
1848 | // source anyway, so the user-defined ~ImmediateDiagBuilder is a safe no-op |
1849 | // in that case anwyay. |
1850 | ImmediateDiagBuilder(const ImmediateDiagBuilder &) = default; |
1851 | |
1852 | ~ImmediateDiagBuilder() { |
1853 | // If we aren't active, there is nothing to do. |
1854 | if (!isActive()) return; |
1855 | |
1856 | // Otherwise, we need to emit the diagnostic. First clear the diagnostic |
1857 | // builder itself so it won't emit the diagnostic in its own destructor. |
1858 | // |
1859 | // This seems wasteful, in that as written the DiagnosticBuilder dtor will |
1860 | // do its own needless checks to see if the diagnostic needs to be |
1861 | // emitted. However, because we take care to ensure that the builder |
1862 | // objects never escape, a sufficiently smart compiler will be able to |
1863 | // eliminate that code. |
1864 | Clear(); |
1865 | |
1866 | // Dispatch to Sema to emit the diagnostic. |
1867 | SemaRef.EmitCurrentDiagnostic(DiagID); |
1868 | } |
1869 | |
1870 | /// Teach operator<< to produce an object of the correct type. |
1871 | template <typename T> |
1872 | friend const ImmediateDiagBuilder & |
1873 | operator<<(const ImmediateDiagBuilder &Diag, const T &Value) { |
1874 | const DiagnosticBuilder &BaseDiag = Diag; |
1875 | BaseDiag << Value; |
1876 | return Diag; |
1877 | } |
1878 | |
1879 | // It is necessary to limit this to rvalue reference to avoid calling this |
1880 | // function with a bitfield lvalue argument since non-const reference to |
1881 | // bitfield is not allowed. |
1882 | template <typename T, |
1883 | typename = std::enable_if_t<!std::is_lvalue_reference<T>::value>> |
1884 | const ImmediateDiagBuilder &operator<<(T &&V) const { |
1885 | const DiagnosticBuilder &BaseDiag = *this; |
1886 | BaseDiag << std::move(V); |
1887 | return *this; |
1888 | } |
1889 | }; |
1890 | |
1891 | /// A generic diagnostic builder for errors which may or may not be deferred. |
1892 | /// |
1893 | /// In CUDA, there exist constructs (e.g. variable-length arrays, try/catch) |
1894 | /// which are not allowed to appear inside __device__ functions and are |
1895 | /// allowed to appear in __host__ __device__ functions only if the host+device |
1896 | /// function is never codegen'ed. |
1897 | /// |
1898 | /// To handle this, we use the notion of "deferred diagnostics", where we |
1899 | /// attach a diagnostic to a FunctionDecl that's emitted iff it's codegen'ed. |
1900 | /// |
1901 | /// This class lets you emit either a regular diagnostic, a deferred |
1902 | /// diagnostic, or no diagnostic at all, according to an argument you pass to |
1903 | /// its constructor, thus simplifying the process of creating these "maybe |
1904 | /// deferred" diagnostics. |
1905 | class SemaDiagnosticBuilder { |
1906 | public: |
1907 | enum Kind { |
1908 | /// Emit no diagnostics. |
1909 | K_Nop, |
1910 | /// Emit the diagnostic immediately (i.e., behave like Sema::Diag()). |
1911 | K_Immediate, |
1912 | /// Emit the diagnostic immediately, and, if it's a warning or error, also |
1913 | /// emit a call stack showing how this function can be reached by an a |
1914 | /// priori known-emitted function. |
1915 | K_ImmediateWithCallStack, |
1916 | /// Create a deferred diagnostic, which is emitted only if the function |
1917 | /// it's attached to is codegen'ed. Also emit a call stack as with |
1918 | /// K_ImmediateWithCallStack. |
1919 | K_Deferred |
1920 | }; |
1921 | |
1922 | SemaDiagnosticBuilder(Kind K, SourceLocation Loc, unsigned DiagID, |
1923 | const FunctionDecl *Fn, Sema &S); |
1924 | SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D); |
1925 | SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default; |
1926 | |
1927 | // The copy and move assignment operator is defined as deleted pending |
1928 | // further motivation. |
1929 | SemaDiagnosticBuilder &operator=(const SemaDiagnosticBuilder &) = delete; |
1930 | SemaDiagnosticBuilder &operator=(SemaDiagnosticBuilder &&) = delete; |
1931 | |
1932 | ~SemaDiagnosticBuilder(); |
1933 | |
1934 | bool isImmediate() const { return ImmediateDiag.has_value(); } |
1935 | |
1936 | /// Convertible to bool: True if we immediately emitted an error, false if |
1937 | /// we didn't emit an error or we created a deferred error. |
1938 | /// |
1939 | /// Example usage: |
1940 | /// |
1941 | /// if (SemaDiagnosticBuilder(...) << foo << bar) |
1942 | /// return ExprError(); |
1943 | /// |
1944 | /// But see CUDADiagIfDeviceCode() and CUDADiagIfHostCode() -- you probably |
1945 | /// want to use these instead of creating a SemaDiagnosticBuilder yourself. |
1946 | operator bool() const { return isImmediate(); } |
1947 | |
1948 | template <typename T> |
1949 | friend const SemaDiagnosticBuilder & |
1950 | operator<<(const SemaDiagnosticBuilder &Diag, const T &Value) { |
1951 | if (Diag.ImmediateDiag) |
1952 | *Diag.ImmediateDiag << Value; |
1953 | else if (Diag.PartialDiagId) |
1954 | Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second |
1955 | << Value; |
1956 | return Diag; |
1957 | } |
1958 | |
1959 | // It is necessary to limit this to rvalue reference to avoid calling this |
1960 | // function with a bitfield lvalue argument since non-const reference to |
1961 | // bitfield is not allowed. |
1962 | template <typename T, |
1963 | typename = std::enable_if_t<!std::is_lvalue_reference<T>::value>> |
1964 | const SemaDiagnosticBuilder &operator<<(T &&V) const { |
1965 | if (ImmediateDiag) |
1966 | *ImmediateDiag << std::move(V); |
1967 | else if (PartialDiagId) |
1968 | S.DeviceDeferredDiags[Fn][*PartialDiagId].second << std::move(V); |
1969 | return *this; |
1970 | } |
1971 | |
1972 | friend const SemaDiagnosticBuilder & |
1973 | operator<<(const SemaDiagnosticBuilder &Diag, const PartialDiagnostic &PD) { |
1974 | if (Diag.ImmediateDiag) |
1975 | PD.Emit(DB: *Diag.ImmediateDiag); |
1976 | else if (Diag.PartialDiagId) |
1977 | Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second = PD; |
1978 | return Diag; |
1979 | } |
1980 | |
1981 | void AddFixItHint(const FixItHint &Hint) const { |
1982 | if (ImmediateDiag) |
1983 | ImmediateDiag->AddFixItHint(Hint); |
1984 | else if (PartialDiagId) |
1985 | S.DeviceDeferredDiags[Fn][*PartialDiagId].second.AddFixItHint(Hint); |
1986 | } |
1987 | |
1988 | friend ExprResult ExprError(const SemaDiagnosticBuilder &) { |
1989 | return ExprError(); |
1990 | } |
1991 | friend StmtResult StmtError(const SemaDiagnosticBuilder &) { |
1992 | return StmtError(); |
1993 | } |
1994 | operator ExprResult() const { return ExprError(); } |
1995 | operator StmtResult() const { return StmtError(); } |
1996 | operator TypeResult() const { return TypeError(); } |
1997 | operator DeclResult() const { return DeclResult(true); } |
1998 | operator MemInitResult() const { return MemInitResult(true); } |
1999 | |
2000 | private: |
2001 | Sema &S; |
2002 | SourceLocation Loc; |
2003 | unsigned DiagID; |
2004 | const FunctionDecl *Fn; |
2005 | bool ShowCallStack; |
2006 | |
2007 | // Invariant: At most one of these Optionals has a value. |
2008 | // FIXME: Switch these to a Variant once that exists. |
2009 | std::optional<ImmediateDiagBuilder> ImmediateDiag; |
2010 | std::optional<unsigned> PartialDiagId; |
2011 | }; |
2012 | |
2013 | /// Is the last error level diagnostic immediate. This is used to determined |
2014 | /// whether the next info diagnostic should be immediate. |
2015 | bool IsLastErrorImmediate = true; |
2016 | |
2017 | /// Emit a diagnostic. |
2018 | SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, |
2019 | bool DeferHint = false); |
2020 | |
2021 | /// Emit a partial diagnostic. |
2022 | SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD, |
2023 | bool DeferHint = false); |
2024 | |
2025 | /// Build a partial diagnostic. |
2026 | PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h |
2027 | |
2028 | /// Whether deferrable diagnostics should be deferred. |
2029 | bool DeferDiags = false; |
2030 | |
2031 | /// RAII class to control scope of DeferDiags. |
2032 | class DeferDiagsRAII { |
2033 | Sema &S; |
2034 | bool SavedDeferDiags = false; |
2035 | |
2036 | public: |
2037 | DeferDiagsRAII(Sema &S, bool DeferDiags) |
2038 | : S(S), SavedDeferDiags(S.DeferDiags) { |
2039 | S.DeferDiags = DeferDiags; |
2040 | } |
2041 | ~DeferDiagsRAII() { S.DeferDiags = SavedDeferDiags; } |
2042 | }; |
2043 | |
2044 | /// Whether uncompilable error has occurred. This includes error happens |
2045 | /// in deferred diagnostics. |
2046 | bool hasUncompilableErrorOccurred() const; |
2047 | |
2048 | bool findMacroSpelling(SourceLocation &loc, StringRef name); |
2049 | |
2050 | /// Get a string to suggest for zero-initialization of a type. |
2051 | std::string |
2052 | getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const; |
2053 | std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const; |
2054 | |
2055 | /// Calls \c Lexer::getLocForEndOfToken() |
2056 | SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0); |
2057 | |
2058 | /// Retrieve the module loader associated with the preprocessor. |
2059 | ModuleLoader &getModuleLoader() const; |
2060 | |
2061 | /// Invent a new identifier for parameters of abbreviated templates. |
2062 | IdentifierInfo * |
2063 | InventAbbreviatedTemplateParameterTypeName(IdentifierInfo *ParamName, |
2064 | unsigned Index); |
2065 | |
2066 | void emitAndClearUnusedLocalTypedefWarnings(); |
2067 | |
2068 | private: |
2069 | /// Function or variable declarations to be checked for whether the deferred |
2070 | /// diagnostics should be emitted. |
2071 | llvm::SmallSetVector<Decl *, 4> DeclsToCheckForDeferredDiags; |
2072 | |
2073 | public: |
2074 | // Emit all deferred diagnostics. |
2075 | void emitDeferredDiags(); |
2076 | |
2077 | enum TUFragmentKind { |
2078 | /// The global module fragment, between 'module;' and a module-declaration. |
2079 | Global, |
2080 | /// A normal translation unit fragment. For a non-module unit, this is the |
2081 | /// entire translation unit. Otherwise, it runs from the module-declaration |
2082 | /// to the private-module-fragment (if any) or the end of the TU (if not). |
2083 | Normal, |
2084 | /// The private module fragment, between 'module :private;' and the end of |
2085 | /// the translation unit. |
2086 | Private |
2087 | }; |
2088 | |
2089 | void ActOnStartOfTranslationUnit(); |
2090 | void ActOnEndOfTranslationUnit(); |
2091 | void ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind); |
2092 | |
2093 | void CheckDelegatingCtorCycles(); |
2094 | |
2095 | Scope *getScopeForContext(DeclContext *Ctx); |
2096 | |
2097 | void PushFunctionScope(); |
2098 | void PushBlockScope(Scope *BlockScope, BlockDecl *Block); |
2099 | sema::LambdaScopeInfo *PushLambdaScope(); |
2100 | |
2101 | /// This is used to inform Sema what the current TemplateParameterDepth |
2102 | /// is during Parsing. Currently it is used to pass on the depth |
2103 | /// when parsing generic lambda 'auto' parameters. |
2104 | void RecordParsingTemplateParameterDepth(unsigned Depth); |
2105 | |
2106 | void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD, |
2107 | RecordDecl *RD, CapturedRegionKind K, |
2108 | unsigned OpenMPCaptureLevel = 0); |
2109 | |
2110 | /// Custom deleter to allow FunctionScopeInfos to be kept alive for a short |
2111 | /// time after they've been popped. |
2112 | class PoppedFunctionScopeDeleter { |
2113 | Sema *Self; |
2114 | |
2115 | public: |
2116 | explicit PoppedFunctionScopeDeleter(Sema *Self) : Self(Self) {} |
2117 | void operator()(sema::FunctionScopeInfo *Scope) const; |
2118 | }; |
2119 | |
2120 | using PoppedFunctionScopePtr = |
2121 | std::unique_ptr<sema::FunctionScopeInfo, PoppedFunctionScopeDeleter>; |
2122 | |
2123 | PoppedFunctionScopePtr |
2124 | PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr, |
2125 | const Decl *D = nullptr, |
2126 | QualType BlockType = QualType()); |
2127 | |
2128 | sema::FunctionScopeInfo *getCurFunction() const { |
2129 | return FunctionScopes.empty() ? nullptr : FunctionScopes.back(); |
2130 | } |
2131 | |
2132 | sema::FunctionScopeInfo *getEnclosingFunction() const; |
2133 | |
2134 | void setFunctionHasBranchIntoScope(); |
2135 | void setFunctionHasBranchProtectedScope(); |
2136 | void setFunctionHasIndirectGoto(); |
2137 | void setFunctionHasMustTail(); |
2138 | |
2139 | void PushCompoundScope(bool IsStmtExpr); |
2140 | void PopCompoundScope(); |
2141 | |
2142 | sema::CompoundScopeInfo &getCurCompoundScope() const; |
2143 | |
2144 | bool hasAnyUnrecoverableErrorsInThisFunction() const; |
2145 | |
2146 | /// Retrieve the current block, if any. |
2147 | sema::BlockScopeInfo *getCurBlock(); |
2148 | |
2149 | /// Get the innermost lambda enclosing the current location, if any. This |
2150 | /// looks through intervening non-lambda scopes such as local functions and |
2151 | /// blocks. |
2152 | sema::LambdaScopeInfo *getEnclosingLambda() const; |
2153 | |
2154 | /// Retrieve the current lambda scope info, if any. |
2155 | /// \param IgnoreNonLambdaCapturingScope true if should find the top-most |
2156 | /// lambda scope info ignoring all inner capturing scopes that are not |
2157 | /// lambda scopes. |
2158 | sema::LambdaScopeInfo * |
2159 | getCurLambda(bool IgnoreNonLambdaCapturingScope = false); |
2160 | |
2161 | /// Retrieve the current generic lambda info, if any. |
2162 | sema::LambdaScopeInfo *getCurGenericLambda(); |
2163 | |
2164 | /// Retrieve the current captured region, if any. |
2165 | sema::CapturedRegionScopeInfo *getCurCapturedRegion(); |
2166 | |
2167 | /// Retrieve the current function, if any, that should be analyzed for |
2168 | /// potential availability violations. |
2169 | sema::FunctionScopeInfo *getCurFunctionAvailabilityContext(); |
2170 | |
2171 | /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls |
2172 | SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; } |
2173 | |
2174 | /// Called before parsing a function declarator belonging to a function |
2175 | /// declaration. |
2176 | void ActOnStartFunctionDeclarationDeclarator(Declarator &D, |
2177 | unsigned TemplateParameterDepth); |
2178 | |
2179 | /// Called after parsing a function declarator belonging to a function |
2180 | /// declaration. |
2181 | void ActOnFinishFunctionDeclarationDeclarator(Declarator &D); |
2182 | |
2183 | void (SourceRange ); |
2184 | |
2185 | //===--------------------------------------------------------------------===// |
2186 | // Type Analysis / Processing: SemaType.cpp. |
2187 | // |
2188 | |
2189 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, |
2190 | const DeclSpec *DS = nullptr); |
2191 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA, |
2192 | const DeclSpec *DS = nullptr); |
2193 | QualType BuildPointerType(QualType T, |
2194 | SourceLocation Loc, DeclarationName Entity); |
2195 | QualType BuildReferenceType(QualType T, bool LValueRef, |
2196 | SourceLocation Loc, DeclarationName Entity); |
2197 | QualType BuildArrayType(QualType T, ArraySizeModifier ASM, Expr *ArraySize, |
2198 | unsigned Quals, SourceRange Brackets, |
2199 | DeclarationName Entity); |
2200 | QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc); |
2201 | QualType BuildExtVectorType(QualType T, Expr *ArraySize, |
2202 | SourceLocation AttrLoc); |
2203 | QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, |
2204 | SourceLocation AttrLoc); |
2205 | |
2206 | QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace, |
2207 | SourceLocation AttrLoc); |
2208 | |
2209 | /// Same as above, but constructs the AddressSpace index if not provided. |
2210 | QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace, |
2211 | SourceLocation AttrLoc); |
2212 | |
2213 | CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E); |
2214 | bool CheckRebuiltStmtAttributes(ArrayRef<const Attr *> Attrs); |
2215 | |
2216 | bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc); |
2217 | |
2218 | bool CheckFunctionReturnType(QualType T, SourceLocation Loc); |
2219 | |
2220 | /// Check an argument list for placeholders that we won't try to |
2221 | /// handle later. |
2222 | bool CheckArgsForPlaceholders(MultiExprArg args); |
2223 | |
2224 | /// Build a function type. |
2225 | /// |
2226 | /// This routine checks the function type according to C++ rules and |
2227 | /// under the assumption that the result type and parameter types have |
2228 | /// just been instantiated from a template. It therefore duplicates |
2229 | /// some of the behavior of GetTypeForDeclarator, but in a much |
2230 | /// simpler form that is only suitable for this narrow use case. |
2231 | /// |
2232 | /// \param T The return type of the function. |
2233 | /// |
2234 | /// \param ParamTypes The parameter types of the function. This array |
2235 | /// will be modified to account for adjustments to the types of the |
2236 | /// function parameters. |
2237 | /// |
2238 | /// \param Loc The location of the entity whose type involves this |
2239 | /// function type or, if there is no such entity, the location of the |
2240 | /// type that will have function type. |
2241 | /// |
2242 | /// \param Entity The name of the entity that involves the function |
2243 | /// type, if known. |
2244 | /// |
2245 | /// \param EPI Extra information about the function type. Usually this will |
2246 | /// be taken from an existing function with the same prototype. |
2247 | /// |
2248 | /// \returns A suitable function type, if there are no errors. The |
2249 | /// unqualified type will always be a FunctionProtoType. |
2250 | /// Otherwise, returns a NULL type. |
2251 | QualType BuildFunctionType(QualType T, |
2252 | MutableArrayRef<QualType> ParamTypes, |
2253 | SourceLocation Loc, DeclarationName Entity, |
2254 | const FunctionProtoType::ExtProtoInfo &EPI); |
2255 | |
2256 | QualType BuildMemberPointerType(QualType T, QualType Class, |
2257 | SourceLocation Loc, |
2258 | DeclarationName Entity); |
2259 | QualType BuildBlockPointerType(QualType T, |
2260 | SourceLocation Loc, DeclarationName Entity); |
2261 | QualType BuildParenType(QualType T); |
2262 | QualType BuildAtomicType(QualType T, SourceLocation Loc); |
2263 | QualType BuildReadPipeType(QualType T, |
2264 | SourceLocation Loc); |
2265 | QualType BuildWritePipeType(QualType T, |
2266 | SourceLocation Loc); |
2267 | QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc); |
2268 | |
2269 | TypeSourceInfo *GetTypeForDeclarator(Declarator &D); |
2270 | TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy); |
2271 | |
2272 | /// Package the given type and TSI into a ParsedType. |
2273 | ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo); |
2274 | DeclarationNameInfo GetNameForDeclarator(Declarator &D); |
2275 | DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name); |
2276 | static QualType GetTypeFromParser(ParsedType Ty, |
2277 | TypeSourceInfo **TInfo = nullptr); |
2278 | CanThrowResult canThrow(const Stmt *E); |
2279 | /// Determine whether the callee of a particular function call can throw. |
2280 | /// E, D and Loc are all optional. |
2281 | static CanThrowResult canCalleeThrow(Sema &S, const Expr *E, const Decl *D, |
2282 | SourceLocation Loc = SourceLocation()); |
2283 | const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc, |
2284 | const FunctionProtoType *FPT); |
2285 | void UpdateExceptionSpec(FunctionDecl *FD, |
2286 | const FunctionProtoType::ExceptionSpecInfo &ESI); |
2287 | bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range); |
2288 | bool CheckDistantExceptionSpec(QualType T); |
2289 | bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New); |
2290 | bool CheckEquivalentExceptionSpec( |
2291 | const FunctionProtoType *Old, SourceLocation OldLoc, |
2292 | const FunctionProtoType *New, SourceLocation NewLoc); |
2293 | bool CheckEquivalentExceptionSpec( |
2294 | const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, |
2295 | const FunctionProtoType *Old, SourceLocation OldLoc, |
2296 | const FunctionProtoType *New, SourceLocation NewLoc); |
2297 | bool handlerCanCatch(QualType HandlerType, QualType ExceptionType); |
2298 | bool CheckExceptionSpecSubset( |
2299 | const PartialDiagnostic &DiagID, const PartialDiagnostic &NestedDiagID, |
2300 | const PartialDiagnostic &NoteID, const PartialDiagnostic &NoThrowDiagID, |
2301 | const FunctionProtoType *Superset, bool SkipSupersetFirstParameter, |
2302 | SourceLocation SuperLoc, const FunctionProtoType *Subset, |
2303 | bool SkipSubsetFirstParameter, SourceLocation SubLoc); |
2304 | bool CheckParamExceptionSpec( |
2305 | const PartialDiagnostic &NestedDiagID, const PartialDiagnostic &NoteID, |
2306 | const FunctionProtoType *Target, bool SkipTargetFirstParameter, |
2307 | SourceLocation TargetLoc, const FunctionProtoType *Source, |
2308 | bool SkipSourceFirstParameter, SourceLocation SourceLoc); |
2309 | |
2310 | TypeResult ActOnTypeName(Declarator &D); |
2311 | |
2312 | /// The parser has parsed the context-sensitive type 'instancetype' |
2313 | /// in an Objective-C message declaration. Return the appropriate type. |
2314 | ParsedType ActOnObjCInstanceType(SourceLocation Loc); |
2315 | |
2316 | /// Abstract class used to diagnose incomplete types. |
2317 | struct TypeDiagnoser { |
2318 | TypeDiagnoser() {} |
2319 | |
2320 | virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0; |
2321 | virtual ~TypeDiagnoser() {} |
2322 | }; |
2323 | |
2324 | static int getPrintable(int I) { return I; } |
2325 | static unsigned getPrintable(unsigned I) { return I; } |
2326 | static bool getPrintable(bool B) { return B; } |
2327 | static const char * getPrintable(const char *S) { return S; } |
2328 | static StringRef getPrintable(StringRef S) { return S; } |
2329 | static const std::string &getPrintable(const std::string &S) { return S; } |
2330 | static const IdentifierInfo *getPrintable(const IdentifierInfo *II) { |
2331 | return II; |
2332 | } |
2333 | static DeclarationName getPrintable(DeclarationName N) { return N; } |
2334 | static QualType getPrintable(QualType T) { return T; } |
2335 | static SourceRange getPrintable(SourceRange R) { return R; } |
2336 | static SourceRange getPrintable(SourceLocation L) { return L; } |
2337 | static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); } |
2338 | static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();} |
2339 | |
2340 | template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser { |
2341 | protected: |
2342 | unsigned DiagID; |
2343 | std::tuple<const Ts &...> Args; |
2344 | |
2345 | template <std::size_t... Is> |
2346 | void emit(const SemaDiagnosticBuilder &DB, |
2347 | std::index_sequence<Is...>) const { |
2348 | // Apply all tuple elements to the builder in order. |
2349 | bool Dummy[] = {false, (DB << getPrintable(std::get<Is>(Args)))...}; |
2350 | (void)Dummy; |
2351 | } |
2352 | |
2353 | public: |
2354 | BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args) |
2355 | : TypeDiagnoser(), DiagID(DiagID), Args(Args...) { |
2356 | assert(DiagID != 0 && "no diagnostic for type diagnoser" ); |
2357 | } |
2358 | |
2359 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
2360 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID); |
2361 | emit(DB, std::index_sequence_for<Ts...>()); |
2362 | DB << T; |
2363 | } |
2364 | }; |
2365 | |
2366 | /// Do a check to make sure \p Name looks like a legal argument for the |
2367 | /// swift_name attribute applied to decl \p D. Raise a diagnostic if the name |
2368 | /// is invalid for the given declaration. |
2369 | /// |
2370 | /// \p AL is used to provide caret diagnostics in case of a malformed name. |
2371 | /// |
2372 | /// \returns true if the name is a valid swift name for \p D, false otherwise. |
2373 | bool DiagnoseSwiftName(Decl *D, StringRef Name, SourceLocation Loc, |
2374 | const ParsedAttr &AL, bool IsAsync); |
2375 | |
2376 | /// A derivative of BoundTypeDiagnoser for which the diagnostic's type |
2377 | /// parameter is preceded by a 0/1 enum that is 1 if the type is sizeless. |
2378 | /// For example, a diagnostic with no other parameters would generally have |
2379 | /// the form "...%select{incomplete|sizeless}0 type %1...". |
2380 | template <typename... Ts> |
2381 | class SizelessTypeDiagnoser : public BoundTypeDiagnoser<Ts...> { |
2382 | public: |
2383 | SizelessTypeDiagnoser(unsigned DiagID, const Ts &... Args) |
2384 | : BoundTypeDiagnoser<Ts...>(DiagID, Args...) {} |
2385 | |
2386 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
2387 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, this->DiagID); |
2388 | this->emit(DB, std::index_sequence_for<Ts...>()); |
2389 | DB << T->isSizelessType() << T; |
2390 | } |
2391 | }; |
2392 | |
2393 | enum class CompleteTypeKind { |
2394 | /// Apply the normal rules for complete types. In particular, |
2395 | /// treat all sizeless types as incomplete. |
2396 | Normal, |
2397 | |
2398 | /// Relax the normal rules for complete types so that they include |
2399 | /// sizeless built-in types. |
2400 | AcceptSizeless, |
2401 | |
2402 | // FIXME: Eventually we should flip the default to Normal and opt in |
2403 | // to AcceptSizeless rather than opt out of it. |
2404 | Default = AcceptSizeless |
2405 | }; |
2406 | |
2407 | enum class AcceptableKind { Visible, Reachable }; |
2408 | |
2409 | private: |
2410 | /// Methods for marking which expressions involve dereferencing a pointer |
2411 | /// marked with the 'noderef' attribute. Expressions are checked bottom up as |
2412 | /// they are parsed, meaning that a noderef pointer may not be accessed. For |
2413 | /// example, in `&*p` where `p` is a noderef pointer, we will first parse the |
2414 | /// `*p`, but need to check that `address of` is called on it. This requires |
2415 | /// keeping a container of all pending expressions and checking if the address |
2416 | /// of them are eventually taken. |
2417 | void CheckSubscriptAccessOfNoDeref(const ArraySubscriptExpr *E); |
2418 | void CheckAddressOfNoDeref(const Expr *E); |
2419 | void CheckMemberAccessOfNoDeref(const MemberExpr *E); |
2420 | |
2421 | bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T, |
2422 | CompleteTypeKind Kind, TypeDiagnoser *Diagnoser); |
2423 | |
2424 | struct ModuleScope { |
2425 | SourceLocation BeginLoc; |
2426 | clang::Module *Module = nullptr; |
2427 | VisibleModuleSet OuterVisibleModules; |
2428 | }; |
2429 | /// The modules we're currently parsing. |
2430 | llvm::SmallVector<ModuleScope, 16> ModuleScopes; |
2431 | |
2432 | /// For an interface unit, this is the implicitly imported interface unit. |
2433 | clang::Module *ThePrimaryInterface = nullptr; |
2434 | |
2435 | /// The explicit global module fragment of the current translation unit. |
2436 | /// The explicit Global Module Fragment, as specified in C++ |
2437 | /// [module.global.frag]. |
2438 | clang::Module *TheGlobalModuleFragment = nullptr; |
2439 | |
2440 | /// The implicit global module fragments of the current translation unit. |
2441 | /// |
2442 | /// The contents in the implicit global module fragment can't be discarded. |
2443 | clang::Module *TheImplicitGlobalModuleFragment = nullptr; |
2444 | |
2445 | /// Namespace definitions that we will export when they finish. |
2446 | llvm::SmallPtrSet<const NamespaceDecl*, 8> DeferredExportedNamespaces; |
2447 | |
2448 | /// In a C++ standard module, inline declarations require a definition to be |
2449 | /// present at the end of a definition domain. This set holds the decls to |
2450 | /// be checked at the end of the TU. |
2451 | llvm::SmallPtrSet<const FunctionDecl *, 8> PendingInlineFuncDecls; |
2452 | |
2453 | /// Helper function to judge if we are in module purview. |
2454 | /// Return false if we are not in a module. |
2455 | bool isCurrentModulePurview() const; |
2456 | |
2457 | /// Enter the scope of the explicit global module fragment. |
2458 | Module *PushGlobalModuleFragment(SourceLocation BeginLoc); |
2459 | /// Leave the scope of the explicit global module fragment. |
2460 | void PopGlobalModuleFragment(); |
2461 | |
2462 | /// Enter the scope of an implicit global module fragment. |
2463 | Module *PushImplicitGlobalModuleFragment(SourceLocation BeginLoc); |
2464 | /// Leave the scope of an implicit global module fragment. |
2465 | void PopImplicitGlobalModuleFragment(); |
2466 | |
2467 | VisibleModuleSet VisibleModules; |
2468 | |
2469 | /// Cache for module units which is usable for current module. |
2470 | llvm::DenseSet<const Module *> UsableModuleUnitsCache; |
2471 | |
2472 | bool isUsableModule(const Module *M); |
2473 | |
2474 | bool isAcceptableSlow(const NamedDecl *D, AcceptableKind Kind); |
2475 | |
2476 | public: |
2477 | /// Get the module unit whose scope we are currently within. |
2478 | Module *getCurrentModule() const { |
2479 | return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module; |
2480 | } |
2481 | |
2482 | /// Is the module scope we are an implementation unit? |
2483 | bool currentModuleIsImplementation() const { |
2484 | return ModuleScopes.empty() |
2485 | ? false |
2486 | : ModuleScopes.back().Module->isModuleImplementation(); |
2487 | } |
2488 | |
2489 | /// Is the module scope we are in a C++ Header Unit? |
2490 | bool () const { |
2491 | return ModuleScopes.empty() ? false |
2492 | : ModuleScopes.back().Module->isHeaderUnit(); |
2493 | } |
2494 | |
2495 | /// Get the module owning an entity. |
2496 | Module *getOwningModule(const Decl *Entity) { |
2497 | return Entity->getOwningModule(); |
2498 | } |
2499 | |
2500 | /// Make a merged definition of an existing hidden definition \p ND |
2501 | /// visible at the specified location. |
2502 | void makeMergedDefinitionVisible(NamedDecl *ND); |
2503 | |
2504 | bool isModuleVisible(const Module *M, bool ModulePrivate = false); |
2505 | |
2506 | // When loading a non-modular PCH files, this is used to restore module |
2507 | // visibility. |
2508 | void makeModuleVisible(Module *Mod, SourceLocation ImportLoc) { |
2509 | VisibleModules.setVisible(M: Mod, Loc: ImportLoc); |
2510 | } |
2511 | |
2512 | /// Determine whether a declaration is visible to name lookup. |
2513 | bool isVisible(const NamedDecl *D) { |
2514 | return D->isUnconditionallyVisible() || |
2515 | isAcceptableSlow(D, Kind: AcceptableKind::Visible); |
2516 | } |
2517 | |
2518 | /// Determine whether a declaration is reachable. |
2519 | bool isReachable(const NamedDecl *D) { |
2520 | // All visible declarations are reachable. |
2521 | return D->isUnconditionallyVisible() || |
2522 | isAcceptableSlow(D, Kind: AcceptableKind::Reachable); |
2523 | } |
2524 | |
2525 | /// Determine whether a declaration is acceptable (visible/reachable). |
2526 | bool isAcceptable(const NamedDecl *D, AcceptableKind Kind) { |
2527 | return Kind == AcceptableKind::Visible ? isVisible(D) : isReachable(D); |
2528 | } |
2529 | |
2530 | /// Determine whether any declaration of an entity is visible. |
2531 | bool |
2532 | hasVisibleDeclaration(const NamedDecl *D, |
2533 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
2534 | return isVisible(D) || hasVisibleDeclarationSlow(D, Modules); |
2535 | } |
2536 | |
2537 | bool hasVisibleDeclarationSlow(const NamedDecl *D, |
2538 | llvm::SmallVectorImpl<Module *> *Modules); |
2539 | /// Determine whether any declaration of an entity is reachable. |
2540 | bool |
2541 | hasReachableDeclaration(const NamedDecl *D, |
2542 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
2543 | return isReachable(D) || hasReachableDeclarationSlow(D, Modules); |
2544 | } |
2545 | bool hasReachableDeclarationSlow( |
2546 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2547 | |
2548 | bool hasVisibleMergedDefinition(const NamedDecl *Def); |
2549 | bool hasMergedDefinitionInCurrentModule(const NamedDecl *Def); |
2550 | |
2551 | /// Determine if \p D and \p Suggested have a structurally compatible |
2552 | /// layout as described in C11 6.2.7/1. |
2553 | bool hasStructuralCompatLayout(Decl *D, Decl *Suggested); |
2554 | |
2555 | /// Determine if \p D has a visible definition. If not, suggest a declaration |
2556 | /// that should be made visible to expose the definition. |
2557 | bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, |
2558 | bool OnlyNeedComplete = false); |
2559 | bool hasVisibleDefinition(const NamedDecl *D) { |
2560 | NamedDecl *Hidden; |
2561 | return hasVisibleDefinition(D: const_cast<NamedDecl*>(D), Suggested: &Hidden); |
2562 | } |
2563 | |
2564 | /// Determine if \p D has a reachable definition. If not, suggest a |
2565 | /// declaration that should be made reachable to expose the definition. |
2566 | bool hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested, |
2567 | bool OnlyNeedComplete = false); |
2568 | bool hasReachableDefinition(NamedDecl *D) { |
2569 | NamedDecl *Hidden; |
2570 | return hasReachableDefinition(D, Suggested: &Hidden); |
2571 | } |
2572 | |
2573 | bool hasAcceptableDefinition(NamedDecl *D, NamedDecl **Suggested, |
2574 | AcceptableKind Kind, |
2575 | bool OnlyNeedComplete = false); |
2576 | bool hasAcceptableDefinition(NamedDecl *D, AcceptableKind Kind) { |
2577 | NamedDecl *Hidden; |
2578 | return hasAcceptableDefinition(D, Suggested: &Hidden, Kind); |
2579 | } |
2580 | |
2581 | /// Determine if the template parameter \p D has a visible default argument. |
2582 | bool |
2583 | hasVisibleDefaultArgument(const NamedDecl *D, |
2584 | llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2585 | /// Determine if the template parameter \p D has a reachable default argument. |
2586 | bool hasReachableDefaultArgument( |
2587 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2588 | /// Determine if the template parameter \p D has a reachable default argument. |
2589 | bool hasAcceptableDefaultArgument(const NamedDecl *D, |
2590 | llvm::SmallVectorImpl<Module *> *Modules, |
2591 | Sema::AcceptableKind Kind); |
2592 | |
2593 | /// Determine if there is a visible declaration of \p D that is an explicit |
2594 | /// specialization declaration for a specialization of a template. (For a |
2595 | /// member specialization, use hasVisibleMemberSpecialization.) |
2596 | bool hasVisibleExplicitSpecialization( |
2597 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2598 | /// Determine if there is a reachable declaration of \p D that is an explicit |
2599 | /// specialization declaration for a specialization of a template. (For a |
2600 | /// member specialization, use hasReachableMemberSpecialization.) |
2601 | bool hasReachableExplicitSpecialization( |
2602 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2603 | |
2604 | /// Determine if there is a visible declaration of \p D that is a member |
2605 | /// specialization declaration (as opposed to an instantiated declaration). |
2606 | bool hasVisibleMemberSpecialization( |
2607 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2608 | /// Determine if there is a reachable declaration of \p D that is a member |
2609 | /// specialization declaration (as opposed to an instantiated declaration). |
2610 | bool hasReachableMemberSpecialization( |
2611 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2612 | |
2613 | /// Determine if \p A and \p B are equivalent internal linkage declarations |
2614 | /// from different modules, and thus an ambiguity error can be downgraded to |
2615 | /// an extension warning. |
2616 | bool isEquivalentInternalLinkageDeclaration(const NamedDecl *A, |
2617 | const NamedDecl *B); |
2618 | void diagnoseEquivalentInternalLinkageDeclarations( |
2619 | SourceLocation Loc, const NamedDecl *D, |
2620 | ArrayRef<const NamedDecl *> Equiv); |
2621 | |
2622 | bool isUsualDeallocationFunction(const CXXMethodDecl *FD); |
2623 | |
2624 | // Check whether the size of array element of type \p EltTy is a multiple of |
2625 | // its alignment and return false if it isn't. |
2626 | bool checkArrayElementAlignment(QualType EltTy, SourceLocation Loc); |
2627 | |
2628 | bool isCompleteType(SourceLocation Loc, QualType T, |
2629 | CompleteTypeKind Kind = CompleteTypeKind::Default) { |
2630 | return !RequireCompleteTypeImpl(Loc, T, Kind, Diagnoser: nullptr); |
2631 | } |
2632 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
2633 | CompleteTypeKind Kind, TypeDiagnoser &Diagnoser); |
2634 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
2635 | CompleteTypeKind Kind, unsigned DiagID); |
2636 | |
2637 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
2638 | TypeDiagnoser &Diagnoser) { |
2639 | return RequireCompleteType(Loc, T, Kind: CompleteTypeKind::Default, Diagnoser); |
2640 | } |
2641 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID) { |
2642 | return RequireCompleteType(Loc, T, Kind: CompleteTypeKind::Default, DiagID); |
2643 | } |
2644 | |
2645 | template <typename... Ts> |
2646 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID, |
2647 | const Ts &...Args) { |
2648 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2649 | return RequireCompleteType(Loc, T, Diagnoser); |
2650 | } |
2651 | |
2652 | template <typename... Ts> |
2653 | bool RequireCompleteSizedType(SourceLocation Loc, QualType T, unsigned DiagID, |
2654 | const Ts &... Args) { |
2655 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2656 | return RequireCompleteType(Loc, T, CompleteTypeKind::Normal, Diagnoser); |
2657 | } |
2658 | |
2659 | /// Get the type of expression E, triggering instantiation to complete the |
2660 | /// type if necessary -- that is, if the expression refers to a templated |
2661 | /// static data member of incomplete array type. |
2662 | /// |
2663 | /// May still return an incomplete type if instantiation was not possible or |
2664 | /// if the type is incomplete for a different reason. Use |
2665 | /// RequireCompleteExprType instead if a diagnostic is expected for an |
2666 | /// incomplete expression type. |
2667 | QualType getCompletedType(Expr *E); |
2668 | |
2669 | void completeExprArrayBound(Expr *E); |
2670 | bool RequireCompleteExprType(Expr *E, CompleteTypeKind Kind, |
2671 | TypeDiagnoser &Diagnoser); |
2672 | bool RequireCompleteExprType(Expr *E, unsigned DiagID); |
2673 | |
2674 | template <typename... Ts> |
2675 | bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) { |
2676 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2677 | return RequireCompleteExprType(E, CompleteTypeKind::Default, Diagnoser); |
2678 | } |
2679 | |
2680 | template <typename... Ts> |
2681 | bool RequireCompleteSizedExprType(Expr *E, unsigned DiagID, |
2682 | const Ts &... Args) { |
2683 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2684 | return RequireCompleteExprType(E, CompleteTypeKind::Normal, Diagnoser); |
2685 | } |
2686 | |
2687 | bool RequireLiteralType(SourceLocation Loc, QualType T, |
2688 | TypeDiagnoser &Diagnoser); |
2689 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID); |
2690 | |
2691 | template <typename... Ts> |
2692 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID, |
2693 | const Ts &...Args) { |
2694 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2695 | return RequireLiteralType(Loc, T, Diagnoser); |
2696 | } |
2697 | |
2698 | QualType getElaboratedType(ElaboratedTypeKeyword Keyword, |
2699 | const CXXScopeSpec &SS, QualType T, |
2700 | TagDecl *OwnedTagDecl = nullptr); |
2701 | |
2702 | // Returns the underlying type of a decltype with the given expression. |
2703 | QualType getDecltypeForExpr(Expr *E); |
2704 | |
2705 | QualType BuildTypeofExprType(Expr *E, TypeOfKind Kind); |
2706 | /// If AsUnevaluated is false, E is treated as though it were an evaluated |
2707 | /// context, such as when building a type for decltype(auto). |
2708 | QualType BuildDecltypeType(Expr *E, bool AsUnevaluated = true); |
2709 | |
2710 | QualType ActOnPackIndexingType(QualType Pattern, Expr *IndexExpr, |
2711 | SourceLocation Loc, |
2712 | SourceLocation EllipsisLoc); |
2713 | QualType BuildPackIndexingType(QualType Pattern, Expr *IndexExpr, |
2714 | SourceLocation Loc, SourceLocation EllipsisLoc, |
2715 | bool FullySubstituted = false, |
2716 | ArrayRef<QualType> Expansions = {}); |
2717 | |
2718 | using UTTKind = UnaryTransformType::UTTKind; |
2719 | QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind, |
2720 | SourceLocation Loc); |
2721 | QualType BuiltinEnumUnderlyingType(QualType BaseType, SourceLocation Loc); |
2722 | QualType BuiltinAddPointer(QualType BaseType, SourceLocation Loc); |
2723 | QualType BuiltinRemovePointer(QualType BaseType, SourceLocation Loc); |
2724 | QualType BuiltinDecay(QualType BaseType, SourceLocation Loc); |
2725 | QualType BuiltinAddReference(QualType BaseType, UTTKind UKind, |
2726 | SourceLocation Loc); |
2727 | QualType BuiltinRemoveExtent(QualType BaseType, UTTKind UKind, |
2728 | SourceLocation Loc); |
2729 | QualType BuiltinRemoveReference(QualType BaseType, UTTKind UKind, |
2730 | SourceLocation Loc); |
2731 | QualType BuiltinChangeCVRQualifiers(QualType BaseType, UTTKind UKind, |
2732 | SourceLocation Loc); |
2733 | QualType BuiltinChangeSignedness(QualType BaseType, UTTKind UKind, |
2734 | SourceLocation Loc); |
2735 | |
2736 | //===--------------------------------------------------------------------===// |
2737 | // Symbol table / Decl tracking callbacks: SemaDecl.cpp. |
2738 | // |
2739 | |
2740 | struct SkipBodyInfo { |
2741 | SkipBodyInfo() = default; |
2742 | bool ShouldSkip = false; |
2743 | bool CheckSameAsPrevious = false; |
2744 | NamedDecl *Previous = nullptr; |
2745 | NamedDecl *New = nullptr; |
2746 | }; |
2747 | |
2748 | DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr); |
2749 | |
2750 | void DiagnoseUseOfUnimplementedSelectors(); |
2751 | |
2752 | ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, |
2753 | Scope *S, CXXScopeSpec *SS = nullptr, |
2754 | bool isClassName = false, bool HasTrailingDot = false, |
2755 | ParsedType ObjectType = nullptr, |
2756 | bool IsCtorOrDtorName = false, |
2757 | bool WantNontrivialTypeSourceInfo = false, |
2758 | bool IsClassTemplateDeductionContext = true, |
2759 | ImplicitTypenameContext AllowImplicitTypename = |
2760 | ImplicitTypenameContext::No, |
2761 | IdentifierInfo **CorrectedII = nullptr); |
2762 | TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S); |
2763 | bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S); |
2764 | void DiagnoseUnknownTypeName(IdentifierInfo *&II, |
2765 | SourceLocation IILoc, |
2766 | Scope *S, |
2767 | CXXScopeSpec *SS, |
2768 | ParsedType &SuggestedType, |
2769 | bool IsTemplateName = false); |
2770 | |
2771 | /// Attempt to behave like MSVC in situations where lookup of an unqualified |
2772 | /// type name has failed in a dependent context. In these situations, we |
2773 | /// automatically form a DependentTypeName that will retry lookup in a related |
2774 | /// scope during instantiation. |
2775 | ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II, |
2776 | SourceLocation NameLoc, |
2777 | bool IsTemplateTypeArg); |
2778 | |
2779 | /// Describes the result of the name lookup and resolution performed |
2780 | /// by \c ClassifyName(). |
2781 | enum NameClassificationKind { |
2782 | /// This name is not a type or template in this context, but might be |
2783 | /// something else. |
2784 | NC_Unknown, |
2785 | /// Classification failed; an error has been produced. |
2786 | NC_Error, |
2787 | /// The name has been typo-corrected to a keyword. |
2788 | NC_Keyword, |
2789 | /// The name was classified as a type. |
2790 | NC_Type, |
2791 | /// The name was classified as a specific non-type, non-template |
2792 | /// declaration. ActOnNameClassifiedAsNonType should be called to |
2793 | /// convert the declaration to an expression. |
2794 | NC_NonType, |
2795 | /// The name was classified as an ADL-only function name. |
2796 | /// ActOnNameClassifiedAsUndeclaredNonType should be called to convert the |
2797 | /// result to an expression. |
2798 | NC_UndeclaredNonType, |
2799 | /// The name denotes a member of a dependent type that could not be |
2800 | /// resolved. ActOnNameClassifiedAsDependentNonType should be called to |
2801 | /// convert the result to an expression. |
2802 | NC_DependentNonType, |
2803 | /// The name was classified as an overload set, and an expression |
2804 | /// representing that overload set has been formed. |
2805 | /// ActOnNameClassifiedAsOverloadSet should be called to form a suitable |
2806 | /// expression referencing the overload set. |
2807 | NC_OverloadSet, |
2808 | /// The name was classified as a template whose specializations are types. |
2809 | NC_TypeTemplate, |
2810 | /// The name was classified as a variable template name. |
2811 | NC_VarTemplate, |
2812 | /// The name was classified as a function template name. |
2813 | NC_FunctionTemplate, |
2814 | /// The name was classified as an ADL-only function template name. |
2815 | NC_UndeclaredTemplate, |
2816 | /// The name was classified as a concept name. |
2817 | NC_Concept, |
2818 | }; |
2819 | |
2820 | class NameClassification { |
2821 | NameClassificationKind Kind; |
2822 | union { |
2823 | ExprResult Expr; |
2824 | NamedDecl *NonTypeDecl; |
2825 | TemplateName Template; |
2826 | ParsedType Type; |
2827 | }; |
2828 | |
2829 | explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {} |
2830 | |
2831 | public: |
2832 | NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {} |
2833 | |
2834 | NameClassification(const IdentifierInfo *Keyword) : Kind(NC_Keyword) {} |
2835 | |
2836 | static NameClassification Error() { |
2837 | return NameClassification(NC_Error); |
2838 | } |
2839 | |
2840 | static NameClassification Unknown() { |
2841 | return NameClassification(NC_Unknown); |
2842 | } |
2843 | |
2844 | static NameClassification OverloadSet(ExprResult E) { |
2845 | NameClassification Result(NC_OverloadSet); |
2846 | Result.Expr = E; |
2847 | return Result; |
2848 | } |
2849 | |
2850 | static NameClassification NonType(NamedDecl *D) { |
2851 | NameClassification Result(NC_NonType); |
2852 | Result.NonTypeDecl = D; |
2853 | return Result; |
2854 | } |
2855 | |
2856 | static NameClassification UndeclaredNonType() { |
2857 | return NameClassification(NC_UndeclaredNonType); |
2858 | } |
2859 | |
2860 | static NameClassification DependentNonType() { |
2861 | return NameClassification(NC_DependentNonType); |
2862 | } |
2863 | |
2864 | static NameClassification TypeTemplate(TemplateName Name) { |
2865 | NameClassification Result(NC_TypeTemplate); |
2866 | Result.Template = Name; |
2867 | return Result; |
2868 | } |
2869 | |
2870 | static NameClassification VarTemplate(TemplateName Name) { |
2871 | NameClassification Result(NC_VarTemplate); |
2872 | Result.Template = Name; |
2873 | return Result; |
2874 | } |
2875 | |
2876 | static NameClassification FunctionTemplate(TemplateName Name) { |
2877 | NameClassification Result(NC_FunctionTemplate); |
2878 | Result.Template = Name; |
2879 | return Result; |
2880 | } |
2881 | |
2882 | static NameClassification Concept(TemplateName Name) { |
2883 | NameClassification Result(NC_Concept); |
2884 | Result.Template = Name; |
2885 | return Result; |
2886 | } |
2887 | |
2888 | static NameClassification UndeclaredTemplate(TemplateName Name) { |
2889 | NameClassification Result(NC_UndeclaredTemplate); |
2890 | Result.Template = Name; |
2891 | return Result; |
2892 | } |
2893 | |
2894 | NameClassificationKind getKind() const { return Kind; } |
2895 | |
2896 | ExprResult getExpression() const { |
2897 | assert(Kind == NC_OverloadSet); |
2898 | return Expr; |
2899 | } |
2900 | |
2901 | ParsedType getType() const { |
2902 | assert(Kind == NC_Type); |
2903 | return Type; |
2904 | } |
2905 | |
2906 | NamedDecl *getNonTypeDecl() const { |
2907 | assert(Kind == NC_NonType); |
2908 | return NonTypeDecl; |
2909 | } |
2910 | |
2911 | TemplateName getTemplateName() const { |
2912 | assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || |
2913 | Kind == NC_VarTemplate || Kind == NC_Concept || |
2914 | Kind == NC_UndeclaredTemplate); |
2915 | return Template; |
2916 | } |
2917 | |
2918 | TemplateNameKind getTemplateNameKind() const { |
2919 | switch (Kind) { |
2920 | case NC_TypeTemplate: |
2921 | return TNK_Type_template; |
2922 | case NC_FunctionTemplate: |
2923 | return TNK_Function_template; |
2924 | case NC_VarTemplate: |
2925 | return TNK_Var_template; |
2926 | case NC_Concept: |
2927 | return TNK_Concept_template; |
2928 | case NC_UndeclaredTemplate: |
2929 | return TNK_Undeclared_template; |
2930 | default: |
2931 | llvm_unreachable("unsupported name classification." ); |
2932 | } |
2933 | } |
2934 | }; |
2935 | |
2936 | /// Perform name lookup on the given name, classifying it based on |
2937 | /// the results of name lookup and the following token. |
2938 | /// |
2939 | /// This routine is used by the parser to resolve identifiers and help direct |
2940 | /// parsing. When the identifier cannot be found, this routine will attempt |
2941 | /// to correct the typo and classify based on the resulting name. |
2942 | /// |
2943 | /// \param S The scope in which we're performing name lookup. |
2944 | /// |
2945 | /// \param SS The nested-name-specifier that precedes the name. |
2946 | /// |
2947 | /// \param Name The identifier. If typo correction finds an alternative name, |
2948 | /// this pointer parameter will be updated accordingly. |
2949 | /// |
2950 | /// \param NameLoc The location of the identifier. |
2951 | /// |
2952 | /// \param NextToken The token following the identifier. Used to help |
2953 | /// disambiguate the name. |
2954 | /// |
2955 | /// \param CCC The correction callback, if typo correction is desired. |
2956 | NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS, |
2957 | IdentifierInfo *&Name, SourceLocation NameLoc, |
2958 | const Token &NextToken, |
2959 | CorrectionCandidateCallback *CCC = nullptr); |
2960 | |
2961 | /// Act on the result of classifying a name as an undeclared (ADL-only) |
2962 | /// non-type declaration. |
2963 | ExprResult ActOnNameClassifiedAsUndeclaredNonType(IdentifierInfo *Name, |
2964 | SourceLocation NameLoc); |
2965 | /// Act on the result of classifying a name as an undeclared member of a |
2966 | /// dependent base class. |
2967 | ExprResult ActOnNameClassifiedAsDependentNonType(const CXXScopeSpec &SS, |
2968 | IdentifierInfo *Name, |
2969 | SourceLocation NameLoc, |
2970 | bool IsAddressOfOperand); |
2971 | /// Act on the result of classifying a name as a specific non-type |
2972 | /// declaration. |
2973 | ExprResult ActOnNameClassifiedAsNonType(Scope *S, const CXXScopeSpec &SS, |
2974 | NamedDecl *Found, |
2975 | SourceLocation NameLoc, |
2976 | const Token &NextToken); |
2977 | /// Act on the result of classifying a name as an overload set. |
2978 | ExprResult ActOnNameClassifiedAsOverloadSet(Scope *S, Expr *OverloadSet); |
2979 | |
2980 | /// Describes the detailed kind of a template name. Used in diagnostics. |
2981 | enum class TemplateNameKindForDiagnostics { |
2982 | ClassTemplate, |
2983 | FunctionTemplate, |
2984 | VarTemplate, |
2985 | AliasTemplate, |
2986 | TemplateTemplateParam, |
2987 | Concept, |
2988 | DependentTemplate |
2989 | }; |
2990 | TemplateNameKindForDiagnostics |
2991 | getTemplateNameKindForDiagnostics(TemplateName Name); |
2992 | |
2993 | /// Determine whether it's plausible that E was intended to be a |
2994 | /// template-name. |
2995 | bool mightBeIntendedToBeTemplateName(ExprResult E, bool &Dependent) { |
2996 | if (!getLangOpts().CPlusPlus || E.isInvalid()) |
2997 | return false; |
2998 | Dependent = false; |
2999 | if (auto *DRE = dyn_cast<DeclRefExpr>(Val: E.get())) |
3000 | return !DRE->hasExplicitTemplateArgs(); |
3001 | if (auto *ME = dyn_cast<MemberExpr>(Val: E.get())) |
3002 | return !ME->hasExplicitTemplateArgs(); |
3003 | Dependent = true; |
3004 | if (auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(Val: E.get())) |
3005 | return !DSDRE->hasExplicitTemplateArgs(); |
3006 | if (auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(Val: E.get())) |
3007 | return !DSME->hasExplicitTemplateArgs(); |
3008 | // Any additional cases recognized here should also be handled by |
3009 | // diagnoseExprIntendedAsTemplateName. |
3010 | return false; |
3011 | } |
3012 | void diagnoseExprIntendedAsTemplateName(Scope *S, ExprResult TemplateName, |
3013 | SourceLocation Less, |
3014 | SourceLocation Greater); |
3015 | |
3016 | void warnOnReservedIdentifier(const NamedDecl *D); |
3017 | |
3018 | Decl *ActOnDeclarator(Scope *S, Declarator &D); |
3019 | |
3020 | NamedDecl *HandleDeclarator(Scope *S, Declarator &D, |
3021 | MultiTemplateParamsArg TemplateParameterLists); |
3022 | bool tryToFixVariablyModifiedVarType(TypeSourceInfo *&TInfo, |
3023 | QualType &T, SourceLocation Loc, |
3024 | unsigned FailedFoldDiagID); |
3025 | void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S); |
3026 | bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info); |
3027 | bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, |
3028 | DeclarationName Name, SourceLocation Loc, |
3029 | TemplateIdAnnotation *TemplateId, |
3030 | bool IsMemberSpecialization); |
3031 | void |
3032 | diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals, |
3033 | SourceLocation FallbackLoc, |
3034 | SourceLocation ConstQualLoc = SourceLocation(), |
3035 | SourceLocation VolatileQualLoc = SourceLocation(), |
3036 | SourceLocation RestrictQualLoc = SourceLocation(), |
3037 | SourceLocation AtomicQualLoc = SourceLocation(), |
3038 | SourceLocation UnalignedQualLoc = SourceLocation()); |
3039 | |
3040 | static bool adjustContextForLocalExternDecl(DeclContext *&DC); |
3041 | void DiagnoseFunctionSpecifiers(const DeclSpec &DS); |
3042 | NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D, |
3043 | const LookupResult &R); |
3044 | NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult &R); |
3045 | NamedDecl *getShadowedDeclaration(const BindingDecl *D, |
3046 | const LookupResult &R); |
3047 | void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl, |
3048 | const LookupResult &R); |
3049 | void CheckShadow(Scope *S, VarDecl *D); |
3050 | |
3051 | /// Warn if 'E', which is an expression that is about to be modified, refers |
3052 | /// to a shadowing declaration. |
3053 | void CheckShadowingDeclModification(Expr *E, SourceLocation Loc); |
3054 | |
3055 | void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI); |
3056 | |
3057 | private: |
3058 | /// Map of current shadowing declarations to shadowed declarations. Warn if |
3059 | /// it looks like the user is trying to modify the shadowing declaration. |
3060 | llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls; |
3061 | |
3062 | public: |
3063 | void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); |
3064 | void handleTagNumbering(const TagDecl *Tag, Scope *TagScope); |
3065 | void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec, |
3066 | TypedefNameDecl *NewTD); |
3067 | void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D); |
3068 | NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
3069 | TypeSourceInfo *TInfo, |
3070 | LookupResult &Previous); |
3071 | NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D, |
3072 | LookupResult &Previous, bool &Redeclaration); |
3073 | NamedDecl *ActOnVariableDeclarator( |
3074 | Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, |
3075 | LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists, |
3076 | bool &AddToScope, ArrayRef<BindingDecl *> Bindings = std::nullopt); |
3077 | NamedDecl * |
3078 | ActOnDecompositionDeclarator(Scope *S, Declarator &D, |
3079 | MultiTemplateParamsArg TemplateParamLists); |
3080 | void DiagPlaceholderVariableDefinition(SourceLocation Loc); |
3081 | bool DiagRedefinedPlaceholderFieldDecl(SourceLocation Loc, |
3082 | RecordDecl *ClassDecl, |
3083 | const IdentifierInfo *Name); |
3084 | // Returns true if the variable declaration is a redeclaration |
3085 | bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous); |
3086 | void CheckVariableDeclarationType(VarDecl *NewVD); |
3087 | bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit, |
3088 | Expr *Init); |
3089 | void CheckCompleteVariableDeclaration(VarDecl *VD); |
3090 | void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD); |
3091 | void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D); |
3092 | |
3093 | NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
3094 | TypeSourceInfo *TInfo, |
3095 | LookupResult &Previous, |
3096 | MultiTemplateParamsArg TemplateParamLists, |
3097 | bool &AddToScope); |
3098 | bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); |
3099 | |
3100 | enum class CheckConstexprKind { |
3101 | /// Diagnose issues that are non-constant or that are extensions. |
3102 | Diagnose, |
3103 | /// Identify whether this function satisfies the formal rules for constexpr |
3104 | /// functions in the current lanugage mode (with no extensions). |
3105 | CheckValid |
3106 | }; |
3107 | |
3108 | bool CheckConstexprFunctionDefinition(const FunctionDecl *FD, |
3109 | CheckConstexprKind Kind); |
3110 | |
3111 | void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD); |
3112 | void FindHiddenVirtualMethods(CXXMethodDecl *MD, |
3113 | SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods); |
3114 | void NoteHiddenVirtualMethods(CXXMethodDecl *MD, |
3115 | SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods); |
3116 | // Returns true if the function declaration is a redeclaration |
3117 | bool CheckFunctionDeclaration(Scope *S, |
3118 | FunctionDecl *NewFD, LookupResult &Previous, |
3119 | bool IsMemberSpecialization, bool DeclIsDefn); |
3120 | bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl); |
3121 | bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD, |
3122 | QualType NewT, QualType OldT); |
3123 | void CheckMain(FunctionDecl *FD, const DeclSpec &D); |
3124 | void CheckMSVCRTEntryPoint(FunctionDecl *FD); |
3125 | void ActOnHLSLTopLevelFunction(FunctionDecl *FD); |
3126 | void CheckHLSLEntryPoint(FunctionDecl *FD); |
3127 | void CheckHLSLSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param, |
3128 | const HLSLAnnotationAttr *AnnotationAttr); |
3129 | void DiagnoseHLSLAttrStageMismatch( |
3130 | const Attr *A, HLSLShaderAttr::ShaderType Stage, |
3131 | std::initializer_list<HLSLShaderAttr::ShaderType> AllowedStages); |
3132 | Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, |
3133 | bool IsDefinition); |
3134 | void CheckFunctionOrTemplateParamDeclarator(Scope *S, Declarator &D); |
3135 | Decl *ActOnParamDeclarator(Scope *S, Declarator &D, |
3136 | SourceLocation ExplicitThisLoc = {}); |
3137 | ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, |
3138 | SourceLocation Loc, |
3139 | QualType T); |
3140 | QualType AdjustParameterTypeForObjCAutoRefCount(QualType T, |
3141 | SourceLocation NameLoc, |
3142 | TypeSourceInfo *TSInfo); |
3143 | ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc, |
3144 | SourceLocation NameLoc, IdentifierInfo *Name, |
3145 | QualType T, TypeSourceInfo *TSInfo, |
3146 | StorageClass SC); |
3147 | void ActOnParamDefaultArgument(Decl *param, |
3148 | SourceLocation EqualLoc, |
3149 | Expr *defarg); |
3150 | void ActOnParamUnparsedDefaultArgument(Decl *param, SourceLocation EqualLoc, |
3151 | SourceLocation ArgLoc); |
3152 | void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc, |
3153 | Expr* DefaultArg); |
3154 | ExprResult ConvertParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
3155 | SourceLocation EqualLoc); |
3156 | void SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
3157 | SourceLocation EqualLoc); |
3158 | |
3159 | // Contexts where using non-trivial C union types can be disallowed. This is |
3160 | // passed to err_non_trivial_c_union_in_invalid_context. |
3161 | enum NonTrivialCUnionContext { |
3162 | // Function parameter. |
3163 | NTCUC_FunctionParam, |
3164 | // Function return. |
3165 | NTCUC_FunctionReturn, |
3166 | // Default-initialized object. |
3167 | NTCUC_DefaultInitializedObject, |
3168 | // Variable with automatic storage duration. |
3169 | NTCUC_AutoVar, |
3170 | // Initializer expression that might copy from another object. |
3171 | NTCUC_CopyInit, |
3172 | // Assignment. |
3173 | NTCUC_Assignment, |
3174 | // Compound literal. |
3175 | NTCUC_CompoundLiteral, |
3176 | // Block capture. |
3177 | NTCUC_BlockCapture, |
3178 | // lvalue-to-rvalue conversion of volatile type. |
3179 | NTCUC_LValueToRValueVolatile, |
3180 | }; |
3181 | |
3182 | /// Emit diagnostics if the initializer or any of its explicit or |
3183 | /// implicitly-generated subexpressions require copying or |
3184 | /// default-initializing a type that is or contains a C union type that is |
3185 | /// non-trivial to copy or default-initialize. |
3186 | void checkNonTrivialCUnionInInitializer(const Expr *Init, SourceLocation Loc); |
3187 | |
3188 | // These flags are passed to checkNonTrivialCUnion. |
3189 | enum NonTrivialCUnionKind { |
3190 | NTCUK_Init = 0x1, |
3191 | NTCUK_Destruct = 0x2, |
3192 | NTCUK_Copy = 0x4, |
3193 | }; |
3194 | |
3195 | /// Emit diagnostics if a non-trivial C union type or a struct that contains |
3196 | /// a non-trivial C union is used in an invalid context. |
3197 | void checkNonTrivialCUnion(QualType QT, SourceLocation Loc, |
3198 | NonTrivialCUnionContext UseContext, |
3199 | unsigned NonTrivialKind); |
3200 | |
3201 | void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit); |
3202 | void ActOnUninitializedDecl(Decl *dcl); |
3203 | void ActOnInitializerError(Decl *Dcl); |
3204 | |
3205 | void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc); |
3206 | void ActOnCXXForRangeDecl(Decl *D); |
3207 | StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, |
3208 | IdentifierInfo *Ident, |
3209 | ParsedAttributes &Attrs); |
3210 | void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc); |
3211 | void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc); |
3212 | void CheckStaticLocalForDllExport(VarDecl *VD); |
3213 | void CheckThreadLocalForLargeAlignment(VarDecl *VD); |
3214 | void FinalizeDeclaration(Decl *D); |
3215 | DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, |
3216 | ArrayRef<Decl *> Group); |
3217 | DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group); |
3218 | |
3219 | /// Should be called on all declarations that might have attached |
3220 | /// documentation comments. |
3221 | void ActOnDocumentableDecl(Decl *D); |
3222 | void ActOnDocumentableDecls(ArrayRef<Decl *> Group); |
3223 | |
3224 | enum class FnBodyKind { |
3225 | /// C++ [dcl.fct.def.general]p1 |
3226 | /// function-body: |
3227 | /// ctor-initializer[opt] compound-statement |
3228 | /// function-try-block |
3229 | Other, |
3230 | /// = default ; |
3231 | Default, |
3232 | /// = delete ; |
3233 | Delete |
3234 | }; |
3235 | |
3236 | void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, |
3237 | SourceLocation LocAfterDecls); |
3238 | void CheckForFunctionRedefinition( |
3239 | FunctionDecl *FD, const FunctionDecl *EffectiveDefinition = nullptr, |
3240 | SkipBodyInfo *SkipBody = nullptr); |
3241 | Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D, |
3242 | MultiTemplateParamsArg TemplateParamLists, |
3243 | SkipBodyInfo *SkipBody = nullptr, |
3244 | FnBodyKind BodyKind = FnBodyKind::Other); |
3245 | Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D, |
3246 | SkipBodyInfo *SkipBody = nullptr, |
3247 | FnBodyKind BodyKind = FnBodyKind::Other); |
3248 | void SetFunctionBodyKind(Decl *D, SourceLocation Loc, FnBodyKind BodyKind); |
3249 | void ActOnStartTrailingRequiresClause(Scope *S, Declarator &D); |
3250 | ExprResult ActOnFinishTrailingRequiresClause(ExprResult ConstraintExpr); |
3251 | ExprResult ActOnRequiresClause(ExprResult ConstraintExpr); |
3252 | void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); |
3253 | bool isObjCMethodDecl(Decl *D) { |
3254 | return D && isa<ObjCMethodDecl>(Val: D); |
3255 | } |
3256 | |
3257 | /// Determine whether we can delay parsing the body of a function or |
3258 | /// function template until it is used, assuming we don't care about emitting |
3259 | /// code for that function. |
3260 | /// |
3261 | /// This will be \c false if we may need the body of the function in the |
3262 | /// middle of parsing an expression (where it's impractical to switch to |
3263 | /// parsing a different function), for instance, if it's constexpr in C++11 |
3264 | /// or has an 'auto' return type in C++14. These cases are essentially bugs. |
3265 | bool canDelayFunctionBody(const Declarator &D); |
3266 | |
3267 | /// Determine whether we can skip parsing the body of a function |
3268 | /// definition, assuming we don't care about analyzing its body or emitting |
3269 | /// code for that function. |
3270 | /// |
3271 | /// This will be \c false only if we may need the body of the function in |
3272 | /// order to parse the rest of the program (for instance, if it is |
3273 | /// \c constexpr in C++11 or has an 'auto' return type in C++14). |
3274 | bool canSkipFunctionBody(Decl *D); |
3275 | |
3276 | /// Determine whether \param D is function like (function or function |
3277 | /// template) for parsing. |
3278 | bool isDeclaratorFunctionLike(Declarator &D); |
3279 | |
3280 | void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope); |
3281 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body); |
3282 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation); |
3283 | Decl *ActOnSkippedFunctionBody(Decl *Decl); |
3284 | void ActOnFinishInlineFunctionDef(FunctionDecl *D); |
3285 | |
3286 | /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an |
3287 | /// attribute for which parsing is delayed. |
3288 | void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs); |
3289 | |
3290 | /// Diagnose any unused parameters in the given sequence of |
3291 | /// ParmVarDecl pointers. |
3292 | void DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters); |
3293 | |
3294 | /// Diagnose whether the size of parameters or return value of a |
3295 | /// function or obj-c method definition is pass-by-value and larger than a |
3296 | /// specified threshold. |
3297 | void |
3298 | DiagnoseSizeOfParametersAndReturnValue(ArrayRef<ParmVarDecl *> Parameters, |
3299 | QualType ReturnTy, NamedDecl *D); |
3300 | |
3301 | void DiagnoseInvalidJumps(Stmt *Body); |
3302 | Decl *ActOnFileScopeAsmDecl(Expr *expr, |
3303 | SourceLocation AsmLoc, |
3304 | SourceLocation RParenLoc); |
3305 | |
3306 | Decl *ActOnTopLevelStmtDecl(Stmt *Statement); |
3307 | |
3308 | /// Handle a C++11 empty-declaration and attribute-declaration. |
3309 | Decl *ActOnEmptyDeclaration(Scope *S, const ParsedAttributesView &AttrList, |
3310 | SourceLocation SemiLoc); |
3311 | |
3312 | enum class ModuleDeclKind { |
3313 | Interface, ///< 'export module X;' |
3314 | Implementation, ///< 'module X;' |
3315 | PartitionInterface, ///< 'export module X:Y;' |
3316 | PartitionImplementation, ///< 'module X:Y;' |
3317 | }; |
3318 | |
3319 | /// An enumeration to represent the transition of states in parsing module |
3320 | /// fragments and imports. If we are not parsing a C++20 TU, or we find |
3321 | /// an error in state transition, the state is set to NotACXX20Module. |
3322 | enum class ModuleImportState { |
3323 | FirstDecl, ///< Parsing the first decl in a TU. |
3324 | GlobalFragment, ///< after 'module;' but before 'module X;' |
3325 | ImportAllowed, ///< after 'module X;' but before any non-import decl. |
3326 | ImportFinished, ///< after any non-import decl. |
3327 | PrivateFragmentImportAllowed, ///< after 'module :private;' but before any |
3328 | ///< non-import decl. |
3329 | PrivateFragmentImportFinished, ///< after 'module :private;' but a |
3330 | ///< non-import decl has already been seen. |
3331 | NotACXX20Module ///< Not a C++20 TU, or an invalid state was found. |
3332 | }; |
3333 | |
3334 | private: |
3335 | /// The parser has begun a translation unit to be compiled as a C++20 |
3336 | /// Header Unit, helper for ActOnStartOfTranslationUnit() only. |
3337 | void HandleStartOfHeaderUnit(); |
3338 | |
3339 | public: |
3340 | /// The parser has processed a module-declaration that begins the definition |
3341 | /// of a module interface or implementation. |
3342 | DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc, |
3343 | SourceLocation ModuleLoc, ModuleDeclKind MDK, |
3344 | ModuleIdPath Path, ModuleIdPath Partition, |
3345 | ModuleImportState &ImportState); |
3346 | |
3347 | /// The parser has processed a global-module-fragment declaration that begins |
3348 | /// the definition of the global module fragment of the current module unit. |
3349 | /// \param ModuleLoc The location of the 'module' keyword. |
3350 | DeclGroupPtrTy ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc); |
3351 | |
3352 | /// The parser has processed a private-module-fragment declaration that begins |
3353 | /// the definition of the private module fragment of the current module unit. |
3354 | /// \param ModuleLoc The location of the 'module' keyword. |
3355 | /// \param PrivateLoc The location of the 'private' keyword. |
3356 | DeclGroupPtrTy ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc, |
3357 | SourceLocation PrivateLoc); |
3358 | |
3359 | /// The parser has processed a module import declaration. |
3360 | /// |
3361 | /// \param StartLoc The location of the first token in the declaration. This |
3362 | /// could be the location of an '@', 'export', or 'import'. |
3363 | /// \param ExportLoc The location of the 'export' keyword, if any. |
3364 | /// \param ImportLoc The location of the 'import' keyword. |
3365 | /// \param Path The module toplevel name as an access path. |
3366 | /// \param IsPartition If the name is for a partition. |
3367 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
3368 | SourceLocation ExportLoc, |
3369 | SourceLocation ImportLoc, ModuleIdPath Path, |
3370 | bool IsPartition = false); |
3371 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
3372 | SourceLocation ExportLoc, |
3373 | SourceLocation ImportLoc, Module *M, |
3374 | ModuleIdPath Path = {}); |
3375 | |
3376 | /// The parser has processed a module import translated from a |
3377 | /// #include or similar preprocessing directive. |
3378 | void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
3379 | void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
3380 | |
3381 | /// The parsed has entered a submodule. |
3382 | void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod); |
3383 | /// The parser has left a submodule. |
3384 | void ActOnModuleEnd(SourceLocation DirectiveLoc, Module *Mod); |
3385 | |
3386 | /// Create an implicit import of the given module at the given |
3387 | /// source location, for error recovery, if possible. |
3388 | /// |
3389 | /// This routine is typically used when an entity found by name lookup |
3390 | /// is actually hidden within a module that we know about but the user |
3391 | /// has forgotten to import. |
3392 | void createImplicitModuleImportForErrorRecovery(SourceLocation Loc, |
3393 | Module *Mod); |
3394 | |
3395 | /// Kinds of missing import. Note, the values of these enumerators correspond |
3396 | /// to %select values in diagnostics. |
3397 | enum class MissingImportKind { |
3398 | Declaration, |
3399 | Definition, |
3400 | DefaultArgument, |
3401 | ExplicitSpecialization, |
3402 | PartialSpecialization |
3403 | }; |
3404 | |
3405 | /// Diagnose that the specified declaration needs to be visible but |
3406 | /// isn't, and suggest a module import that would resolve the problem. |
3407 | void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl, |
3408 | MissingImportKind MIK, bool Recover = true); |
3409 | void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl, |
3410 | SourceLocation DeclLoc, ArrayRef<Module *> Modules, |
3411 | MissingImportKind MIK, bool Recover); |
3412 | |
3413 | Decl *ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, |
3414 | SourceLocation LBraceLoc); |
3415 | Decl *ActOnFinishExportDecl(Scope *S, Decl *ExportDecl, |
3416 | SourceLocation RBraceLoc); |
3417 | |
3418 | /// We've found a use of a templated declaration that would trigger an |
3419 | /// implicit instantiation. Check that any relevant explicit specializations |
3420 | /// and partial specializations are visible/reachable, and diagnose if not. |
3421 | void checkSpecializationVisibility(SourceLocation Loc, NamedDecl *Spec); |
3422 | void checkSpecializationReachability(SourceLocation Loc, NamedDecl *Spec); |
3423 | |
3424 | /// Retrieve a suitable printing policy for diagnostics. |
3425 | PrintingPolicy getPrintingPolicy() const { |
3426 | return getPrintingPolicy(Ctx: Context, PP); |
3427 | } |
3428 | |
3429 | /// Retrieve a suitable printing policy for diagnostics. |
3430 | static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx, |
3431 | const Preprocessor &PP); |
3432 | |
3433 | /// Scope actions. |
3434 | void ActOnPopScope(SourceLocation Loc, Scope *S); |
3435 | void ActOnTranslationUnitScope(Scope *S); |
3436 | |
3437 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
3438 | const ParsedAttributesView &DeclAttrs, |
3439 | RecordDecl *&AnonRecord); |
3440 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
3441 | const ParsedAttributesView &DeclAttrs, |
3442 | MultiTemplateParamsArg TemplateParams, |
3443 | bool IsExplicitInstantiation, |
3444 | RecordDecl *&AnonRecord); |
3445 | |
3446 | Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, |
3447 | AccessSpecifier AS, |
3448 | RecordDecl *Record, |
3449 | const PrintingPolicy &Policy); |
3450 | |
3451 | /// Called once it is known whether |
3452 | /// a tag declaration is an anonymous union or struct. |
3453 | void ActOnDefinedDeclarationSpecifier(Decl *D); |
3454 | |
3455 | void DiagPlaceholderFieldDeclDefinitions(RecordDecl *Record); |
3456 | |
3457 | Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, |
3458 | RecordDecl *Record); |
3459 | |
3460 | /// Common ways to introduce type names without a tag for use in diagnostics. |
3461 | /// Keep in sync with err_tag_reference_non_tag. |
3462 | enum NonTagKind { |
3463 | NTK_NonStruct, |
3464 | NTK_NonClass, |
3465 | NTK_NonUnion, |
3466 | NTK_NonEnum, |
3467 | NTK_Typedef, |
3468 | NTK_TypeAlias, |
3469 | NTK_Template, |
3470 | NTK_TypeAliasTemplate, |
3471 | NTK_TemplateTemplateArgument, |
3472 | }; |
3473 | |
3474 | /// Given a non-tag type declaration, returns an enum useful for indicating |
3475 | /// what kind of non-tag type this is. |
3476 | NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK); |
3477 | |
3478 | bool isAcceptableTagRedeclaration(const TagDecl *Previous, |
3479 | TagTypeKind NewTag, bool isDefinition, |
3480 | SourceLocation NewTagLoc, |
3481 | const IdentifierInfo *Name); |
3482 | |
3483 | enum TagUseKind { |
3484 | TUK_Reference, // Reference to a tag: 'struct foo *X;' |
3485 | TUK_Declaration, // Fwd decl of a tag: 'struct foo;' |
3486 | TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;' |
3487 | TUK_Friend // Friend declaration: 'friend struct foo;' |
3488 | }; |
3489 | |
3490 | enum OffsetOfKind { |
3491 | // Not parsing a type within __builtin_offsetof. |
3492 | OOK_Outside, |
3493 | // Parsing a type within __builtin_offsetof. |
3494 | OOK_Builtin, |
3495 | // Parsing a type within macro "offsetof", defined in __buitin_offsetof |
3496 | // To improve our diagnostic message. |
3497 | OOK_Macro, |
3498 | }; |
3499 | |
3500 | DeclResult ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, |
3501 | SourceLocation KWLoc, CXXScopeSpec &SS, |
3502 | IdentifierInfo *Name, SourceLocation NameLoc, |
3503 | const ParsedAttributesView &Attr, AccessSpecifier AS, |
3504 | SourceLocation ModulePrivateLoc, |
3505 | MultiTemplateParamsArg TemplateParameterLists, |
3506 | bool &OwnedDecl, bool &IsDependent, |
3507 | SourceLocation ScopedEnumKWLoc, |
3508 | bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, |
3509 | bool IsTypeSpecifier, bool IsTemplateParamOrArg, |
3510 | OffsetOfKind OOK, SkipBodyInfo *SkipBody = nullptr); |
3511 | |
3512 | DeclResult ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, |
3513 | unsigned TagSpec, SourceLocation TagLoc, |
3514 | CXXScopeSpec &SS, IdentifierInfo *Name, |
3515 | SourceLocation NameLoc, |
3516 | const ParsedAttributesView &Attr, |
3517 | MultiTemplateParamsArg TempParamLists); |
3518 | |
3519 | TypeResult ActOnDependentTag(Scope *S, |
3520 | unsigned TagSpec, |
3521 | TagUseKind TUK, |
3522 | const CXXScopeSpec &SS, |
3523 | IdentifierInfo *Name, |
3524 | SourceLocation TagLoc, |
3525 | SourceLocation NameLoc); |
3526 | |
3527 | void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, |
3528 | IdentifierInfo *ClassName, |
3529 | SmallVectorImpl<Decl *> &Decls); |
3530 | Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, |
3531 | Declarator &D, Expr *BitfieldWidth); |
3532 | |
3533 | FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, |
3534 | Declarator &D, Expr *BitfieldWidth, |
3535 | InClassInitStyle InitStyle, |
3536 | AccessSpecifier AS); |
3537 | MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD, |
3538 | SourceLocation DeclStart, Declarator &D, |
3539 | Expr *BitfieldWidth, |
3540 | InClassInitStyle InitStyle, |
3541 | AccessSpecifier AS, |
3542 | const ParsedAttr &MSPropertyAttr); |
3543 | |
3544 | FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, |
3545 | TypeSourceInfo *TInfo, |
3546 | RecordDecl *Record, SourceLocation Loc, |
3547 | bool Mutable, Expr *BitfieldWidth, |
3548 | InClassInitStyle InitStyle, |
3549 | SourceLocation TSSL, |
3550 | AccessSpecifier AS, NamedDecl *PrevDecl, |
3551 | Declarator *D = nullptr); |
3552 | |
3553 | bool CheckNontrivialField(FieldDecl *FD); |
3554 | void DiagnoseNontrivial(const CXXRecordDecl *Record, CXXSpecialMember CSM); |
3555 | |
3556 | enum TrivialABIHandling { |
3557 | /// The triviality of a method unaffected by "trivial_abi". |
3558 | TAH_IgnoreTrivialABI, |
3559 | |
3560 | /// The triviality of a method affected by "trivial_abi". |
3561 | TAH_ConsiderTrivialABI |
3562 | }; |
3563 | |
3564 | bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM, |
3565 | TrivialABIHandling TAH = TAH_IgnoreTrivialABI, |
3566 | bool Diagnose = false); |
3567 | |
3568 | /// For a defaulted function, the kind of defaulted function that it is. |
3569 | class DefaultedFunctionKind { |
3570 | unsigned SpecialMember : 8; |
3571 | unsigned Comparison : 8; |
3572 | |
3573 | public: |
3574 | DefaultedFunctionKind() |
3575 | : SpecialMember(CXXInvalid), Comparison(llvm::to_underlying(E: DefaultedComparisonKind::None)) { |
3576 | } |
3577 | DefaultedFunctionKind(CXXSpecialMember CSM) |
3578 | : SpecialMember(CSM), Comparison(llvm::to_underlying(E: DefaultedComparisonKind::None)) {} |
3579 | DefaultedFunctionKind(DefaultedComparisonKind Comp) |
3580 | : SpecialMember(CXXInvalid), Comparison(llvm::to_underlying(E: Comp)) {} |
3581 | |
3582 | bool isSpecialMember() const { return SpecialMember != CXXInvalid; } |
3583 | bool isComparison() const { |
3584 | return static_cast<DefaultedComparisonKind>(Comparison) != DefaultedComparisonKind::None; |
3585 | } |
3586 | |
3587 | explicit operator bool() const { |
3588 | return isSpecialMember() || isComparison(); |
3589 | } |
3590 | |
3591 | CXXSpecialMember asSpecialMember() const { return static_cast<CXXSpecialMember>(SpecialMember); } |
3592 | DefaultedComparisonKind asComparison() const { return static_cast<DefaultedComparisonKind>(Comparison); } |
3593 | |
3594 | /// Get the index of this function kind for use in diagnostics. |
3595 | unsigned getDiagnosticIndex() const { |
3596 | static_assert(CXXInvalid > CXXDestructor, |
3597 | "invalid should have highest index" ); |
3598 | static_assert((unsigned)DefaultedComparisonKind::None == 0, |
3599 | "none should be equal to zero" ); |
3600 | return SpecialMember + Comparison; |
3601 | } |
3602 | }; |
3603 | |
3604 | DefaultedFunctionKind getDefaultedFunctionKind(const FunctionDecl *FD); |
3605 | |
3606 | CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD) { |
3607 | return getDefaultedFunctionKind(MD).asSpecialMember(); |
3608 | } |
3609 | DefaultedComparisonKind getDefaultedComparisonKind(const FunctionDecl *FD) { |
3610 | return getDefaultedFunctionKind(FD).asComparison(); |
3611 | } |
3612 | |
3613 | void ActOnLastBitfield(SourceLocation DeclStart, |
3614 | SmallVectorImpl<Decl *> &AllIvarDecls); |
3615 | Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, Declarator &D, |
3616 | Expr *BitWidth, tok::ObjCKeywordKind visibility); |
3617 | |
3618 | // This is used for both record definitions and ObjC interface declarations. |
3619 | void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, |
3620 | ArrayRef<Decl *> Fields, SourceLocation LBrac, |
3621 | SourceLocation RBrac, const ParsedAttributesView &AttrList); |
3622 | |
3623 | /// ActOnTagStartDefinition - Invoked when we have entered the |
3624 | /// scope of a tag's definition (e.g., for an enumeration, class, |
3625 | /// struct, or union). |
3626 | void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); |
3627 | |
3628 | /// Perform ODR-like check for C/ObjC when merging tag types from modules. |
3629 | /// Differently from C++, actually parse the body and reject / error out |
3630 | /// in case of a structural mismatch. |
3631 | bool ActOnDuplicateDefinition(Decl *Prev, SkipBodyInfo &SkipBody); |
3632 | |
3633 | /// Check ODR hashes for C/ObjC when merging types from modules. |
3634 | /// Differently from C++, actually parse the body and reject in case |
3635 | /// of a mismatch. |
3636 | template <typename T, |
3637 | typename = std::enable_if_t<std::is_base_of<NamedDecl, T>::value>> |
3638 | bool ActOnDuplicateODRHashDefinition(T *Duplicate, T *Previous) { |
3639 | if (Duplicate->getODRHash() != Previous->getODRHash()) |
3640 | return false; |
3641 | |
3642 | // Make the previous decl visible. |
3643 | makeMergedDefinitionVisible(ND: Previous); |
3644 | return true; |
3645 | } |
3646 | |
3647 | typedef void *SkippedDefinitionContext; |
3648 | |
3649 | /// Invoked when we enter a tag definition that we're skipping. |
3650 | SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD); |
3651 | |
3652 | void ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl); |
3653 | |
3654 | /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a |
3655 | /// C++ record definition's base-specifiers clause and are starting its |
3656 | /// member declarations. |
3657 | void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, |
3658 | SourceLocation FinalLoc, |
3659 | bool IsFinalSpelledSealed, |
3660 | bool IsAbstract, |
3661 | SourceLocation LBraceLoc); |
3662 | |
3663 | /// ActOnTagFinishDefinition - Invoked once we have finished parsing |
3664 | /// the definition of a tag (enumeration, class, struct, or union). |
3665 | void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, |
3666 | SourceRange BraceRange); |
3667 | |
3668 | void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context); |
3669 | |
3670 | void ActOnObjCContainerFinishDefinition(); |
3671 | |
3672 | /// Invoked when we must temporarily exit the objective-c container |
3673 | /// scope for parsing/looking-up C constructs. |
3674 | /// |
3675 | /// Must be followed by a call to \see ActOnObjCReenterContainerContext |
3676 | void ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx); |
3677 | void ActOnObjCReenterContainerContext(ObjCContainerDecl *ObjCCtx); |
3678 | |
3679 | /// ActOnTagDefinitionError - Invoked when there was an unrecoverable |
3680 | /// error parsing the definition of a tag. |
3681 | void ActOnTagDefinitionError(Scope *S, Decl *TagDecl); |
3682 | |
3683 | EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, |
3684 | EnumConstantDecl *LastEnumConst, |
3685 | SourceLocation IdLoc, |
3686 | IdentifierInfo *Id, |
3687 | Expr *val); |
3688 | bool CheckEnumUnderlyingType(TypeSourceInfo *TI); |
3689 | bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, |
3690 | QualType EnumUnderlyingTy, bool IsFixed, |
3691 | const EnumDecl *Prev); |
3692 | |
3693 | /// Determine whether the body of an anonymous enumeration should be skipped. |
3694 | /// \param II The name of the first enumerator. |
3695 | SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, |
3696 | SourceLocation IILoc); |
3697 | |
3698 | Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, |
3699 | SourceLocation IdLoc, IdentifierInfo *Id, |
3700 | const ParsedAttributesView &Attrs, |
3701 | SourceLocation EqualLoc, Expr *Val); |
3702 | void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, |
3703 | Decl *EnumDecl, ArrayRef<Decl *> Elements, Scope *S, |
3704 | const ParsedAttributesView &Attr); |
3705 | |
3706 | /// Set the current declaration context until it gets popped. |
3707 | void PushDeclContext(Scope *S, DeclContext *DC); |
3708 | void PopDeclContext(); |
3709 | |
3710 | /// EnterDeclaratorContext - Used when we must lookup names in the context |
3711 | /// of a declarator's nested name specifier. |
3712 | void EnterDeclaratorContext(Scope *S, DeclContext *DC); |
3713 | void ExitDeclaratorContext(Scope *S); |
3714 | |
3715 | /// Enter a template parameter scope, after it's been associated with a particular |
3716 | /// DeclContext. Causes lookup within the scope to chain through enclosing contexts |
3717 | /// in the correct order. |
3718 | void EnterTemplatedContext(Scope *S, DeclContext *DC); |
3719 | |
3720 | /// Push the parameters of D, which must be a function, into scope. |
3721 | void ActOnReenterFunctionContext(Scope* S, Decl* D); |
3722 | void ActOnExitFunctionContext(); |
3723 | |
3724 | /// If \p AllowLambda is true, treat lambda as function. |
3725 | DeclContext *getFunctionLevelDeclContext(bool AllowLambda = false) const; |
3726 | |
3727 | /// Returns a pointer to the innermost enclosing function, or nullptr if the |
3728 | /// current context is not inside a function. If \p AllowLambda is true, |
3729 | /// this can return the call operator of an enclosing lambda, otherwise |
3730 | /// lambdas are skipped when looking for an enclosing function. |
3731 | FunctionDecl *getCurFunctionDecl(bool AllowLambda = false) const; |
3732 | |
3733 | /// getCurMethodDecl - If inside of a method body, this returns a pointer to |
3734 | /// the method decl for the method being parsed. If we're currently |
3735 | /// in a 'block', this returns the containing context. |
3736 | ObjCMethodDecl *getCurMethodDecl(); |
3737 | |
3738 | /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method |
3739 | /// or C function we're in, otherwise return null. If we're currently |
3740 | /// in a 'block', this returns the containing context. |
3741 | NamedDecl *getCurFunctionOrMethodDecl() const; |
3742 | |
3743 | /// Add this decl to the scope shadowed decl chains. |
3744 | void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true); |
3745 | |
3746 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
3747 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
3748 | /// true if 'D' belongs to the given declaration context. |
3749 | /// |
3750 | /// \param AllowInlineNamespace If \c true, allow the declaration to be in the |
3751 | /// enclosing namespace set of the context, rather than contained |
3752 | /// directly within it. |
3753 | bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr, |
3754 | bool AllowInlineNamespace = false) const; |
3755 | |
3756 | /// Finds the scope corresponding to the given decl context, if it |
3757 | /// happens to be an enclosing scope. Otherwise return NULL. |
3758 | static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC); |
3759 | |
3760 | /// Subroutines of ActOnDeclarator(). |
3761 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, |
3762 | TypeSourceInfo *TInfo); |
3763 | bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New); |
3764 | |
3765 | /// Describes the kind of merge to perform for availability |
3766 | /// attributes (including "deprecated", "unavailable", and "availability"). |
3767 | enum AvailabilityMergeKind { |
3768 | /// Don't merge availability attributes at all. |
3769 | AMK_None, |
3770 | /// Merge availability attributes for a redeclaration, which requires |
3771 | /// an exact match. |
3772 | AMK_Redeclaration, |
3773 | /// Merge availability attributes for an override, which requires |
3774 | /// an exact match or a weakening of constraints. |
3775 | AMK_Override, |
3776 | /// Merge availability attributes for an implementation of |
3777 | /// a protocol requirement. |
3778 | AMK_ProtocolImplementation, |
3779 | /// Merge availability attributes for an implementation of |
3780 | /// an optional protocol requirement. |
3781 | AMK_OptionalProtocolImplementation |
3782 | }; |
3783 | |
3784 | /// Describes the kind of priority given to an availability attribute. |
3785 | /// |
3786 | /// The sum of priorities deteremines the final priority of the attribute. |
3787 | /// The final priority determines how the attribute will be merged. |
3788 | /// An attribute with a lower priority will always remove higher priority |
3789 | /// attributes for the specified platform when it is being applied. An |
3790 | /// attribute with a higher priority will not be applied if the declaration |
3791 | /// already has an availability attribute with a lower priority for the |
3792 | /// specified platform. The final prirority values are not expected to match |
3793 | /// the values in this enumeration, but instead should be treated as a plain |
3794 | /// integer value. This enumeration just names the priority weights that are |
3795 | /// used to calculate that final vaue. |
3796 | enum AvailabilityPriority : int { |
3797 | /// The availability attribute was specified explicitly next to the |
3798 | /// declaration. |
3799 | AP_Explicit = 0, |
3800 | |
3801 | /// The availability attribute was applied using '#pragma clang attribute'. |
3802 | AP_PragmaClangAttribute = 1, |
3803 | |
3804 | /// The availability attribute for a specific platform was inferred from |
3805 | /// an availability attribute for another platform. |
3806 | AP_InferredFromOtherPlatform = 2 |
3807 | }; |
3808 | |
3809 | /// Attribute merging methods. Return true if a new attribute was added. |
3810 | AvailabilityAttr * |
3811 | mergeAvailabilityAttr(NamedDecl *D, const AttributeCommonInfo &CI, |
3812 | IdentifierInfo *Platform, bool Implicit, |
3813 | VersionTuple Introduced, VersionTuple Deprecated, |
3814 | VersionTuple Obsoleted, bool IsUnavailable, |
3815 | StringRef Message, bool IsStrict, StringRef Replacement, |
3816 | AvailabilityMergeKind AMK, int Priority); |
3817 | TypeVisibilityAttr * |
3818 | mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
3819 | TypeVisibilityAttr::VisibilityType Vis); |
3820 | VisibilityAttr *mergeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
3821 | VisibilityAttr::VisibilityType Vis); |
3822 | UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI, |
3823 | StringRef UuidAsWritten, MSGuidDecl *GuidDecl); |
3824 | DLLImportAttr *mergeDLLImportAttr(Decl *D, const AttributeCommonInfo &CI); |
3825 | DLLExportAttr *mergeDLLExportAttr(Decl *D, const AttributeCommonInfo &CI); |
3826 | MSInheritanceAttr *mergeMSInheritanceAttr(Decl *D, |
3827 | const AttributeCommonInfo &CI, |
3828 | bool BestCase, |
3829 | MSInheritanceModel Model); |
3830 | ErrorAttr *mergeErrorAttr(Decl *D, const AttributeCommonInfo &CI, |
3831 | StringRef NewUserDiagnostic); |
3832 | FormatAttr *mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI, |
3833 | IdentifierInfo *Format, int FormatIdx, |
3834 | int FirstArg); |
3835 | SectionAttr *mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI, |
3836 | StringRef Name); |
3837 | CodeSegAttr *mergeCodeSegAttr(Decl *D, const AttributeCommonInfo &CI, |
3838 | StringRef Name); |
3839 | AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, |
3840 | const AttributeCommonInfo &CI, |
3841 | const IdentifierInfo *Ident); |
3842 | MinSizeAttr *mergeMinSizeAttr(Decl *D, const AttributeCommonInfo &CI); |
3843 | SwiftNameAttr *mergeSwiftNameAttr(Decl *D, const SwiftNameAttr &SNA, |
3844 | StringRef Name); |
3845 | OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, |
3846 | const AttributeCommonInfo &CI); |
3847 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL); |
3848 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, |
3849 | const InternalLinkageAttr &AL); |
3850 | WebAssemblyImportNameAttr *mergeImportNameAttr( |
3851 | Decl *D, const WebAssemblyImportNameAttr &AL); |
3852 | WebAssemblyImportModuleAttr *mergeImportModuleAttr( |
3853 | Decl *D, const WebAssemblyImportModuleAttr &AL); |
3854 | EnforceTCBAttr *mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL); |
3855 | EnforceTCBLeafAttr *mergeEnforceTCBLeafAttr(Decl *D, |
3856 | const EnforceTCBLeafAttr &AL); |
3857 | BTFDeclTagAttr *mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL); |
3858 | HLSLNumThreadsAttr *mergeHLSLNumThreadsAttr(Decl *D, |
3859 | const AttributeCommonInfo &AL, |
3860 | int X, int Y, int Z); |
3861 | HLSLShaderAttr *mergeHLSLShaderAttr(Decl *D, const AttributeCommonInfo &AL, |
3862 | HLSLShaderAttr::ShaderType ShaderType); |
3863 | HLSLParamModifierAttr * |
3864 | mergeHLSLParamModifierAttr(Decl *D, const AttributeCommonInfo &AL, |
3865 | HLSLParamModifierAttr::Spelling Spelling); |
3866 | |
3867 | void mergeDeclAttributes(NamedDecl *New, Decl *Old, |
3868 | AvailabilityMergeKind AMK = AMK_Redeclaration); |
3869 | void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, |
3870 | LookupResult &OldDecls); |
3871 | bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S, |
3872 | bool MergeTypeWithOld, bool NewDeclIsDefn); |
3873 | bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, |
3874 | Scope *S, bool MergeTypeWithOld); |
3875 | void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old); |
3876 | void MergeVarDecl(VarDecl *New, LookupResult &Previous); |
3877 | void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld); |
3878 | void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old); |
3879 | bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn); |
3880 | void notePreviousDefinition(const NamedDecl *Old, SourceLocation New); |
3881 | bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S); |
3882 | |
3883 | // AssignmentAction - This is used by all the assignment diagnostic functions |
3884 | // to represent what is actually causing the operation |
3885 | enum AssignmentAction { |
3886 | AA_Assigning, |
3887 | AA_Passing, |
3888 | AA_Returning, |
3889 | AA_Converting, |
3890 | AA_Initializing, |
3891 | AA_Sending, |
3892 | AA_Casting, |
3893 | AA_Passing_CFAudited |
3894 | }; |
3895 | |
3896 | /// C++ Overloading. |
3897 | enum OverloadKind { |
3898 | /// This is a legitimate overload: the existing declarations are |
3899 | /// functions or function templates with different signatures. |
3900 | Ovl_Overload, |
3901 | |
3902 | /// This is not an overload because the signature exactly matches |
3903 | /// an existing declaration. |
3904 | Ovl_Match, |
3905 | |
3906 | /// This is not an overload because the lookup results contain a |
3907 | /// non-function. |
3908 | Ovl_NonFunction |
3909 | }; |
3910 | OverloadKind CheckOverload(Scope *S, |
3911 | FunctionDecl *New, |
3912 | const LookupResult &OldDecls, |
3913 | NamedDecl *&OldDecl, |
3914 | bool UseMemberUsingDeclRules); |
3915 | bool IsOverload(FunctionDecl *New, FunctionDecl *Old, |
3916 | bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs = true); |
3917 | |
3918 | // Checks whether MD constitutes an override the base class method BaseMD. |
3919 | // When checking for overrides, the object object members are ignored. |
3920 | bool IsOverride(FunctionDecl *MD, FunctionDecl *BaseMD, |
3921 | bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs = true); |
3922 | |
3923 | // Calculates whether the expression Constraint depends on an enclosing |
3924 | // template, for the purposes of [temp.friend] p9. |
3925 | // TemplateDepth is the 'depth' of the friend function, which is used to |
3926 | // compare whether a declaration reference is referring to a containing |
3927 | // template, or just the current friend function. A 'lower' TemplateDepth in |
3928 | // the AST refers to a 'containing' template. As the constraint is |
3929 | // uninstantiated, this is relative to the 'top' of the TU. |
3930 | bool |
3931 | ConstraintExpressionDependsOnEnclosingTemplate(const FunctionDecl *Friend, |
3932 | unsigned TemplateDepth, |
3933 | const Expr *Constraint); |
3934 | |
3935 | // Calculates whether the friend function depends on an enclosing template for |
3936 | // the purposes of [temp.friend] p9. |
3937 | bool FriendConstraintsDependOnEnclosingTemplate(const FunctionDecl *FD); |
3938 | |
3939 | enum class AllowedExplicit { |
3940 | /// Allow no explicit functions to be used. |
3941 | None, |
3942 | /// Allow explicit conversion functions but not explicit constructors. |
3943 | Conversions, |
3944 | /// Allow both explicit conversion functions and explicit constructors. |
3945 | All |
3946 | }; |
3947 | |
3948 | ImplicitConversionSequence |
3949 | TryImplicitConversion(Expr *From, QualType ToType, |
3950 | bool SuppressUserConversions, |
3951 | AllowedExplicit AllowExplicit, |
3952 | bool InOverloadResolution, |
3953 | bool CStyle, |
3954 | bool AllowObjCWritebackConversion); |
3955 | |
3956 | bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); |
3957 | bool IsFloatingPointPromotion(QualType FromType, QualType ToType); |
3958 | bool IsComplexPromotion(QualType FromType, QualType ToType); |
3959 | bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, |
3960 | bool InOverloadResolution, |
3961 | QualType& ConvertedType, bool &IncompatibleObjC); |
3962 | bool isObjCPointerConversion(QualType FromType, QualType ToType, |
3963 | QualType& ConvertedType, bool &IncompatibleObjC); |
3964 | bool isObjCWritebackConversion(QualType FromType, QualType ToType, |
3965 | QualType &ConvertedType); |
3966 | bool IsBlockPointerConversion(QualType FromType, QualType ToType, |
3967 | QualType& ConvertedType); |
3968 | |
3969 | bool FunctionParamTypesAreEqual(ArrayRef<QualType> Old, |
3970 | ArrayRef<QualType> New, |
3971 | unsigned *ArgPos = nullptr, |
3972 | bool Reversed = false); |
3973 | |
3974 | bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType, |
3975 | const FunctionProtoType *NewType, |
3976 | unsigned *ArgPos = nullptr, |
3977 | bool Reversed = false); |
3978 | |
3979 | bool FunctionNonObjectParamTypesAreEqual(const FunctionDecl *OldFunction, |
3980 | const FunctionDecl *NewFunction, |
3981 | unsigned *ArgPos = nullptr, |
3982 | bool Reversed = false); |
3983 | |
3984 | void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, |
3985 | QualType FromType, QualType ToType); |
3986 | |
3987 | void maybeExtendBlockObject(ExprResult &E); |
3988 | CastKind PrepareCastToObjCObjectPointer(ExprResult &E); |
3989 | bool CheckPointerConversion(Expr *From, QualType ToType, |
3990 | CastKind &Kind, |
3991 | CXXCastPath& BasePath, |
3992 | bool IgnoreBaseAccess, |
3993 | bool Diagnose = true); |
3994 | bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, |
3995 | bool InOverloadResolution, |
3996 | QualType &ConvertedType); |
3997 | bool CheckMemberPointerConversion(Expr *From, QualType ToType, |
3998 | CastKind &Kind, |
3999 | CXXCastPath &BasePath, |
4000 | bool IgnoreBaseAccess); |
4001 | bool IsQualificationConversion(QualType FromType, QualType ToType, |
4002 | bool CStyle, bool &ObjCLifetimeConversion); |
4003 | bool IsFunctionConversion(QualType FromType, QualType ToType, |
4004 | QualType &ResultTy); |
4005 | bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); |
4006 | bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg); |
4007 | |
4008 | bool CanPerformAggregateInitializationForOverloadResolution( |
4009 | const InitializedEntity &Entity, InitListExpr *From); |
4010 | |
4011 | bool IsStringInit(Expr *Init, const ArrayType *AT); |
4012 | |
4013 | bool CanPerformCopyInitialization(const InitializedEntity &Entity, |
4014 | ExprResult Init); |
4015 | ExprResult PerformCopyInitialization(const InitializedEntity &Entity, |
4016 | SourceLocation EqualLoc, |
4017 | ExprResult Init, |
4018 | bool TopLevelOfInitList = false, |
4019 | bool AllowExplicit = false); |
4020 | ExprResult InitializeExplicitObjectArgument(Sema &S, Expr *Obj, |
4021 | FunctionDecl *Fun); |
4022 | ExprResult PerformImplicitObjectArgumentInitialization( |
4023 | Expr *From, NestedNameSpecifier *Qualifier, NamedDecl *FoundDecl, |
4024 | CXXMethodDecl *Method); |
4025 | |
4026 | /// Check that the lifetime of the initializer (and its subobjects) is |
4027 | /// sufficient for initializing the entity, and perform lifetime extension |
4028 | /// (when permitted) if not. |
4029 | void checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init); |
4030 | |
4031 | ExprResult PerformContextuallyConvertToBool(Expr *From); |
4032 | ExprResult PerformContextuallyConvertToObjCPointer(Expr *From); |
4033 | |
4034 | /// Contexts in which a converted constant expression is required. |
4035 | enum CCEKind { |
4036 | CCEK_CaseValue, ///< Expression in a case label. |
4037 | CCEK_Enumerator, ///< Enumerator value with fixed underlying type. |
4038 | CCEK_TemplateArg, ///< Value of a non-type template parameter. |
4039 | CCEK_ArrayBound, ///< Array bound in array declarator or new-expression. |
4040 | CCEK_ExplicitBool, ///< Condition in an explicit(bool) specifier. |
4041 | CCEK_Noexcept, ///< Condition in a noexcept(bool) specifier. |
4042 | CCEK_StaticAssertMessageSize, ///< Call to size() in a static assert |
4043 | ///< message. |
4044 | CCEK_StaticAssertMessageData, ///< Call to data() in a static assert |
4045 | ///< message. |
4046 | }; |
4047 | |
4048 | ExprResult BuildConvertedConstantExpression(Expr *From, QualType T, |
4049 | CCEKind CCE, |
4050 | NamedDecl *Dest = nullptr); |
4051 | |
4052 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
4053 | llvm::APSInt &Value, CCEKind CCE); |
4054 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
4055 | APValue &Value, CCEKind CCE, |
4056 | NamedDecl *Dest = nullptr); |
4057 | |
4058 | ExprResult |
4059 | EvaluateConvertedConstantExpression(Expr *E, QualType T, APValue &Value, |
4060 | CCEKind CCE, bool RequireInt, |
4061 | const APValue &PreNarrowingValue); |
4062 | |
4063 | /// Abstract base class used to perform a contextual implicit |
4064 | /// conversion from an expression to any type passing a filter. |
4065 | class ContextualImplicitConverter { |
4066 | public: |
4067 | bool Suppress; |
4068 | bool SuppressConversion; |
4069 | |
4070 | ContextualImplicitConverter(bool Suppress = false, |
4071 | bool SuppressConversion = false) |
4072 | : Suppress(Suppress), SuppressConversion(SuppressConversion) {} |
4073 | |
4074 | /// Determine whether the specified type is a valid destination type |
4075 | /// for this conversion. |
4076 | virtual bool match(QualType T) = 0; |
4077 | |
4078 | /// Emits a diagnostic complaining that the expression does not have |
4079 | /// integral or enumeration type. |
4080 | virtual SemaDiagnosticBuilder |
4081 | diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) = 0; |
4082 | |
4083 | /// Emits a diagnostic when the expression has incomplete class type. |
4084 | virtual SemaDiagnosticBuilder |
4085 | diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0; |
4086 | |
4087 | /// Emits a diagnostic when the only matching conversion function |
4088 | /// is explicit. |
4089 | virtual SemaDiagnosticBuilder diagnoseExplicitConv( |
4090 | Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0; |
4091 | |
4092 | /// Emits a note for the explicit conversion function. |
4093 | virtual SemaDiagnosticBuilder |
4094 | noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
4095 | |
4096 | /// Emits a diagnostic when there are multiple possible conversion |
4097 | /// functions. |
4098 | virtual SemaDiagnosticBuilder |
4099 | diagnoseAmbiguous(Sema &S, SourceLocation Loc, QualType T) = 0; |
4100 | |
4101 | /// Emits a note for one of the candidate conversions. |
4102 | virtual SemaDiagnosticBuilder |
4103 | noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
4104 | |
4105 | /// Emits a diagnostic when we picked a conversion function |
4106 | /// (for cases when we are not allowed to pick a conversion function). |
4107 | virtual SemaDiagnosticBuilder diagnoseConversion( |
4108 | Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0; |
4109 | |
4110 | virtual ~ContextualImplicitConverter() {} |
4111 | }; |
4112 | |
4113 | class ICEConvertDiagnoser : public ContextualImplicitConverter { |
4114 | bool AllowScopedEnumerations; |
4115 | |
4116 | public: |
4117 | ICEConvertDiagnoser(bool AllowScopedEnumerations, |
4118 | bool Suppress, bool SuppressConversion) |
4119 | : ContextualImplicitConverter(Suppress, SuppressConversion), |
4120 | AllowScopedEnumerations(AllowScopedEnumerations) {} |
4121 | |
4122 | /// Match an integral or (possibly scoped) enumeration type. |
4123 | bool match(QualType T) override; |
4124 | |
4125 | SemaDiagnosticBuilder |
4126 | diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) override { |
4127 | return diagnoseNotInt(S, Loc, T); |
4128 | } |
4129 | |
4130 | /// Emits a diagnostic complaining that the expression does not have |
4131 | /// integral or enumeration type. |
4132 | virtual SemaDiagnosticBuilder |
4133 | diagnoseNotInt(Sema &S, SourceLocation Loc, QualType T) = 0; |
4134 | }; |
4135 | |
4136 | /// Perform a contextual implicit conversion. |
4137 | ExprResult PerformContextualImplicitConversion( |
4138 | SourceLocation Loc, Expr *FromE, ContextualImplicitConverter &Converter); |
4139 | |
4140 | |
4141 | enum ObjCSubscriptKind { |
4142 | OS_Array, |
4143 | OS_Dictionary, |
4144 | OS_Error |
4145 | }; |
4146 | ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE); |
4147 | |
4148 | // Note that LK_String is intentionally after the other literals, as |
4149 | // this is used for diagnostics logic. |
4150 | enum ObjCLiteralKind { |
4151 | LK_Array, |
4152 | LK_Dictionary, |
4153 | LK_Numeric, |
4154 | LK_Boxed, |
4155 | LK_String, |
4156 | LK_Block, |
4157 | LK_None |
4158 | }; |
4159 | ObjCLiteralKind CheckLiteralKind(Expr *FromE); |
4160 | |
4161 | ExprResult PerformObjectMemberConversion(Expr *From, |
4162 | NestedNameSpecifier *Qualifier, |
4163 | NamedDecl *FoundDecl, |
4164 | NamedDecl *Member); |
4165 | |
4166 | // Members have to be NamespaceDecl* or TranslationUnitDecl*. |
4167 | // TODO: make this is a typesafe union. |
4168 | typedef llvm::SmallSetVector<DeclContext *, 16> AssociatedNamespaceSet; |
4169 | typedef llvm::SmallSetVector<CXXRecordDecl *, 16> AssociatedClassSet; |
4170 | |
4171 | using ADLCallKind = CallExpr::ADLCallKind; |
4172 | |
4173 | void AddOverloadCandidate( |
4174 | FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef<Expr *> Args, |
4175 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
4176 | bool PartialOverloading = false, bool AllowExplicit = true, |
4177 | bool AllowExplicitConversion = false, |
4178 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
4179 | ConversionSequenceList EarlyConversions = std::nullopt, |
4180 | OverloadCandidateParamOrder PO = {}, |
4181 | bool AggregateCandidateDeduction = false); |
4182 | void AddFunctionCandidates(const UnresolvedSetImpl &Functions, |
4183 | ArrayRef<Expr *> Args, |
4184 | OverloadCandidateSet &CandidateSet, |
4185 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
4186 | bool SuppressUserConversions = false, |
4187 | bool PartialOverloading = false, |
4188 | bool FirstArgumentIsBase = false); |
4189 | void AddMethodCandidate(DeclAccessPair FoundDecl, |
4190 | QualType ObjectType, |
4191 | Expr::Classification ObjectClassification, |
4192 | ArrayRef<Expr *> Args, |
4193 | OverloadCandidateSet& CandidateSet, |
4194 | bool SuppressUserConversion = false, |
4195 | OverloadCandidateParamOrder PO = {}); |
4196 | void |
4197 | AddMethodCandidate(CXXMethodDecl *Method, DeclAccessPair FoundDecl, |
4198 | CXXRecordDecl *ActingContext, QualType ObjectType, |
4199 | Expr::Classification ObjectClassification, |
4200 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, |
4201 | bool SuppressUserConversions = false, |
4202 | bool PartialOverloading = false, |
4203 | ConversionSequenceList EarlyConversions = std::nullopt, |
4204 | OverloadCandidateParamOrder PO = {}); |
4205 | void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, |
4206 | DeclAccessPair FoundDecl, |
4207 | CXXRecordDecl *ActingContext, |
4208 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
4209 | QualType ObjectType, |
4210 | Expr::Classification ObjectClassification, |
4211 | ArrayRef<Expr *> Args, |
4212 | OverloadCandidateSet& CandidateSet, |
4213 | bool SuppressUserConversions = false, |
4214 | bool PartialOverloading = false, |
4215 | OverloadCandidateParamOrder PO = {}); |
4216 | void AddTemplateOverloadCandidate( |
4217 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
4218 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
4219 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
4220 | bool PartialOverloading = false, bool AllowExplicit = true, |
4221 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
4222 | OverloadCandidateParamOrder PO = {}, |
4223 | bool AggregateCandidateDeduction = false); |
4224 | bool CheckNonDependentConversions( |
4225 | FunctionTemplateDecl *FunctionTemplate, ArrayRef<QualType> ParamTypes, |
4226 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, |
4227 | ConversionSequenceList &Conversions, bool SuppressUserConversions, |
4228 | CXXRecordDecl *ActingContext = nullptr, QualType ObjectType = QualType(), |
4229 | Expr::Classification ObjectClassification = {}, |
4230 | OverloadCandidateParamOrder PO = {}); |
4231 | void AddConversionCandidate( |
4232 | CXXConversionDecl *Conversion, DeclAccessPair FoundDecl, |
4233 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
4234 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
4235 | bool AllowExplicit, bool AllowResultConversion = true); |
4236 | void AddTemplateConversionCandidate( |
4237 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
4238 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
4239 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
4240 | bool AllowExplicit, bool AllowResultConversion = true); |
4241 | void AddSurrogateCandidate(CXXConversionDecl *Conversion, |
4242 | DeclAccessPair FoundDecl, |
4243 | CXXRecordDecl *ActingContext, |
4244 | const FunctionProtoType *Proto, |
4245 | Expr *Object, ArrayRef<Expr *> Args, |
4246 | OverloadCandidateSet& CandidateSet); |
4247 | void AddNonMemberOperatorCandidates( |
4248 | const UnresolvedSetImpl &Functions, ArrayRef<Expr *> Args, |
4249 | OverloadCandidateSet &CandidateSet, |
4250 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
4251 | void AddMemberOperatorCandidates(OverloadedOperatorKind Op, |
4252 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
4253 | OverloadCandidateSet &CandidateSet, |
4254 | OverloadCandidateParamOrder PO = {}); |
4255 | void AddBuiltinCandidate(QualType *ParamTys, ArrayRef<Expr *> Args, |
4256 | OverloadCandidateSet& CandidateSet, |
4257 | bool IsAssignmentOperator = false, |
4258 | unsigned NumContextualBoolArguments = 0); |
4259 | void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, |
4260 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
4261 | OverloadCandidateSet& CandidateSet); |
4262 | void AddArgumentDependentLookupCandidates(DeclarationName Name, |
4263 | SourceLocation Loc, |
4264 | ArrayRef<Expr *> Args, |
4265 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
4266 | OverloadCandidateSet& CandidateSet, |
4267 | bool PartialOverloading = false); |
4268 | |
4269 | // Emit as a 'note' the specific overload candidate |
4270 | void NoteOverloadCandidate( |
4271 | const NamedDecl *Found, const FunctionDecl *Fn, |
4272 | OverloadCandidateRewriteKind RewriteKind = OverloadCandidateRewriteKind(), |
4273 | QualType DestType = QualType(), bool TakingAddress = false); |
4274 | |
4275 | // Emit as a series of 'note's all template and non-templates identified by |
4276 | // the expression Expr |
4277 | void NoteAllOverloadCandidates(Expr *E, QualType DestType = QualType(), |
4278 | bool TakingAddress = false); |
4279 | |
4280 | /// Check the enable_if expressions on the given function. Returns the first |
4281 | /// failing attribute, or NULL if they were all successful. |
4282 | EnableIfAttr *CheckEnableIf(FunctionDecl *Function, SourceLocation CallLoc, |
4283 | ArrayRef<Expr *> Args, |
4284 | bool MissingImplicitThis = false); |
4285 | |
4286 | /// Find the failed Boolean condition within a given Boolean |
4287 | /// constant expression, and describe it with a string. |
4288 | std::pair<Expr *, std::string> findFailedBooleanCondition(Expr *Cond); |
4289 | |
4290 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
4291 | /// non-ArgDependent DiagnoseIfAttrs. |
4292 | /// |
4293 | /// Argument-dependent diagnose_if attributes should be checked each time a |
4294 | /// function is used as a direct callee of a function call. |
4295 | /// |
4296 | /// Returns true if any errors were emitted. |
4297 | bool diagnoseArgDependentDiagnoseIfAttrs(const FunctionDecl *Function, |
4298 | const Expr *ThisArg, |
4299 | ArrayRef<const Expr *> Args, |
4300 | SourceLocation Loc); |
4301 | |
4302 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
4303 | /// ArgDependent DiagnoseIfAttrs. |
4304 | /// |
4305 | /// Argument-independent diagnose_if attributes should be checked on every use |
4306 | /// of a function. |
4307 | /// |
4308 | /// Returns true if any errors were emitted. |
4309 | bool diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND, |
4310 | SourceLocation Loc); |
4311 | |
4312 | /// Returns whether the given function's address can be taken or not, |
4313 | /// optionally emitting a diagnostic if the address can't be taken. |
4314 | /// |
4315 | /// Returns false if taking the address of the function is illegal. |
4316 | bool checkAddressOfFunctionIsAvailable(const FunctionDecl *Function, |
4317 | bool Complain = false, |
4318 | SourceLocation Loc = SourceLocation()); |
4319 | |
4320 | // [PossiblyAFunctionType] --> [Return] |
4321 | // NonFunctionType --> NonFunctionType |
4322 | // R (A) --> R(A) |
4323 | // R (*)(A) --> R (A) |
4324 | // R (&)(A) --> R (A) |
4325 | // R (S::*)(A) --> R (A) |
4326 | QualType (QualType PossiblyAFunctionType); |
4327 | |
4328 | FunctionDecl * |
4329 | ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, |
4330 | QualType TargetType, |
4331 | bool Complain, |
4332 | DeclAccessPair &Found, |
4333 | bool *pHadMultipleCandidates = nullptr); |
4334 | |
4335 | FunctionDecl * |
4336 | resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &FoundResult); |
4337 | |
4338 | bool resolveAndFixAddressOfSingleOverloadCandidate( |
4339 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false); |
4340 | |
4341 | FunctionDecl *ResolveSingleFunctionTemplateSpecialization( |
4342 | OverloadExpr *ovl, bool Complain = false, DeclAccessPair *Found = nullptr, |
4343 | TemplateSpecCandidateSet *FailedTSC = nullptr); |
4344 | |
4345 | bool ResolveAndFixSingleFunctionTemplateSpecialization( |
4346 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false, |
4347 | bool Complain = false, SourceRange OpRangeForComplaining = SourceRange(), |
4348 | QualType DestTypeForComplaining = QualType(), |
4349 | unsigned DiagIDForComplaining = 0); |
4350 | |
4351 | ExprResult FixOverloadedFunctionReference(Expr *E, DeclAccessPair FoundDecl, |
4352 | FunctionDecl *Fn); |
4353 | ExprResult FixOverloadedFunctionReference(ExprResult, |
4354 | DeclAccessPair FoundDecl, |
4355 | FunctionDecl *Fn); |
4356 | |
4357 | void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, |
4358 | ArrayRef<Expr *> Args, |
4359 | OverloadCandidateSet &CandidateSet, |
4360 | bool PartialOverloading = false); |
4361 | void AddOverloadedCallCandidates( |
4362 | LookupResult &R, TemplateArgumentListInfo *ExplicitTemplateArgs, |
4363 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet); |
4364 | |
4365 | // An enum used to represent the different possible results of building a |
4366 | // range-based for loop. |
4367 | enum ForRangeStatus { |
4368 | FRS_Success, |
4369 | FRS_NoViableFunction, |
4370 | FRS_DiagnosticIssued |
4371 | }; |
4372 | |
4373 | ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc, |
4374 | SourceLocation RangeLoc, |
4375 | const DeclarationNameInfo &NameInfo, |
4376 | LookupResult &MemberLookup, |
4377 | OverloadCandidateSet *CandidateSet, |
4378 | Expr *Range, ExprResult *CallExpr); |
4379 | |
4380 | ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn, |
4381 | UnresolvedLookupExpr *ULE, |
4382 | SourceLocation LParenLoc, |
4383 | MultiExprArg Args, |
4384 | SourceLocation RParenLoc, |
4385 | Expr *ExecConfig, |
4386 | bool AllowTypoCorrection=true, |
4387 | bool CalleesAddressIsTaken=false); |
4388 | |
4389 | bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, |
4390 | MultiExprArg Args, SourceLocation RParenLoc, |
4391 | OverloadCandidateSet *CandidateSet, |
4392 | ExprResult *Result); |
4393 | |
4394 | ExprResult CreateUnresolvedLookupExpr(CXXRecordDecl *NamingClass, |
4395 | NestedNameSpecifierLoc NNSLoc, |
4396 | DeclarationNameInfo DNI, |
4397 | const UnresolvedSetImpl &Fns, |
4398 | bool PerformADL = true); |
4399 | |
4400 | ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, |
4401 | UnaryOperatorKind Opc, |
4402 | const UnresolvedSetImpl &Fns, |
4403 | Expr *input, bool RequiresADL = true); |
4404 | |
4405 | void LookupOverloadedBinOp(OverloadCandidateSet &CandidateSet, |
4406 | OverloadedOperatorKind Op, |
4407 | const UnresolvedSetImpl &Fns, |
4408 | ArrayRef<Expr *> Args, bool RequiresADL = true); |
4409 | ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, |
4410 | BinaryOperatorKind Opc, |
4411 | const UnresolvedSetImpl &Fns, |
4412 | Expr *LHS, Expr *RHS, |
4413 | bool RequiresADL = true, |
4414 | bool AllowRewrittenCandidates = true, |
4415 | FunctionDecl *DefaultedFn = nullptr); |
4416 | ExprResult BuildSynthesizedThreeWayComparison(SourceLocation OpLoc, |
4417 | const UnresolvedSetImpl &Fns, |
4418 | Expr *LHS, Expr *RHS, |
4419 | FunctionDecl *DefaultedFn); |
4420 | |
4421 | ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, |
4422 | SourceLocation RLoc, Expr *Base, |
4423 | MultiExprArg Args); |
4424 | |
4425 | ExprResult BuildCallToMemberFunction(Scope *S, Expr *MemExpr, |
4426 | SourceLocation LParenLoc, |
4427 | MultiExprArg Args, |
4428 | SourceLocation RParenLoc, |
4429 | Expr *ExecConfig = nullptr, |
4430 | bool IsExecConfig = false, |
4431 | bool AllowRecovery = false); |
4432 | ExprResult |
4433 | BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, |
4434 | MultiExprArg Args, |
4435 | SourceLocation RParenLoc); |
4436 | |
4437 | ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, |
4438 | SourceLocation OpLoc, |
4439 | bool *NoArrowOperatorFound = nullptr); |
4440 | |
4441 | /// CheckCallReturnType - Checks that a call expression's return type is |
4442 | /// complete. Returns true on failure. The location passed in is the location |
4443 | /// that best represents the call. |
4444 | bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, |
4445 | CallExpr *CE, FunctionDecl *FD); |
4446 | |
4447 | /// Helpers for dealing with blocks and functions. |
4448 | bool CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters, |
4449 | bool CheckParameterNames); |
4450 | void CheckCXXDefaultArguments(FunctionDecl *FD); |
4451 | void (Declarator &D); |
4452 | Scope *getNonFieldDeclScope(Scope *S); |
4453 | |
4454 | /// \name Name lookup |
4455 | /// |
4456 | /// These routines provide name lookup that is used during semantic |
4457 | /// analysis to resolve the various kinds of names (identifiers, |
4458 | /// overloaded operator names, constructor names, etc.) into zero or |
4459 | /// more declarations within a particular scope. The major entry |
4460 | /// points are LookupName, which performs unqualified name lookup, |
4461 | /// and LookupQualifiedName, which performs qualified name lookup. |
4462 | /// |
4463 | /// All name lookup is performed based on some specific criteria, |
4464 | /// which specify what names will be visible to name lookup and how |
4465 | /// far name lookup should work. These criteria are important both |
4466 | /// for capturing language semantics (certain lookups will ignore |
4467 | /// certain names, for example) and for performance, since name |
4468 | /// lookup is often a bottleneck in the compilation of C++. Name |
4469 | /// lookup criteria is specified via the LookupCriteria enumeration. |
4470 | /// |
4471 | /// The results of name lookup can vary based on the kind of name |
4472 | /// lookup performed, the current language, and the translation |
4473 | /// unit. In C, for example, name lookup will either return nothing |
4474 | /// (no entity found) or a single declaration. In C++, name lookup |
4475 | /// can additionally refer to a set of overloaded functions or |
4476 | /// result in an ambiguity. All of the possible results of name |
4477 | /// lookup are captured by the LookupResult class, which provides |
4478 | /// the ability to distinguish among them. |
4479 | //@{ |
4480 | |
4481 | /// Describes the kind of name lookup to perform. |
4482 | enum LookupNameKind { |
4483 | /// Ordinary name lookup, which finds ordinary names (functions, |
4484 | /// variables, typedefs, etc.) in C and most kinds of names |
4485 | /// (functions, variables, members, types, etc.) in C++. |
4486 | LookupOrdinaryName = 0, |
4487 | /// Tag name lookup, which finds the names of enums, classes, |
4488 | /// structs, and unions. |
4489 | LookupTagName, |
4490 | /// Label name lookup. |
4491 | LookupLabel, |
4492 | /// Member name lookup, which finds the names of |
4493 | /// class/struct/union members. |
4494 | LookupMemberName, |
4495 | /// Look up of an operator name (e.g., operator+) for use with |
4496 | /// operator overloading. This lookup is similar to ordinary name |
4497 | /// lookup, but will ignore any declarations that are class members. |
4498 | LookupOperatorName, |
4499 | /// Look up a name following ~ in a destructor name. This is an ordinary |
4500 | /// lookup, but prefers tags to typedefs. |
4501 | LookupDestructorName, |
4502 | /// Look up of a name that precedes the '::' scope resolution |
4503 | /// operator in C++. This lookup completely ignores operator, object, |
4504 | /// function, and enumerator names (C++ [basic.lookup.qual]p1). |
4505 | LookupNestedNameSpecifierName, |
4506 | /// Look up a namespace name within a C++ using directive or |
4507 | /// namespace alias definition, ignoring non-namespace names (C++ |
4508 | /// [basic.lookup.udir]p1). |
4509 | LookupNamespaceName, |
4510 | /// Look up all declarations in a scope with the given name, |
4511 | /// including resolved using declarations. This is appropriate |
4512 | /// for checking redeclarations for a using declaration. |
4513 | LookupUsingDeclName, |
4514 | /// Look up an ordinary name that is going to be redeclared as a |
4515 | /// name with linkage. This lookup ignores any declarations that |
4516 | /// are outside of the current scope unless they have linkage. See |
4517 | /// C99 6.2.2p4-5 and C++ [basic.link]p6. |
4518 | LookupRedeclarationWithLinkage, |
4519 | /// Look up a friend of a local class. This lookup does not look |
4520 | /// outside the innermost non-class scope. See C++11 [class.friend]p11. |
4521 | LookupLocalFriendName, |
4522 | /// Look up the name of an Objective-C protocol. |
4523 | LookupObjCProtocolName, |
4524 | /// Look up implicit 'self' parameter of an objective-c method. |
4525 | LookupObjCImplicitSelfParam, |
4526 | /// Look up the name of an OpenMP user-defined reduction operation. |
4527 | LookupOMPReductionName, |
4528 | /// Look up the name of an OpenMP user-defined mapper. |
4529 | LookupOMPMapperName, |
4530 | /// Look up any declaration with any name. |
4531 | LookupAnyName |
4532 | }; |
4533 | |
4534 | /// Specifies whether (or how) name lookup is being performed for a |
4535 | /// redeclaration (vs. a reference). |
4536 | enum RedeclarationKind { |
4537 | /// The lookup is a reference to this name that is not for the |
4538 | /// purpose of redeclaring the name. |
4539 | NotForRedeclaration = 0, |
4540 | /// The lookup results will be used for redeclaration of a name, |
4541 | /// if an entity by that name already exists and is visible. |
4542 | ForVisibleRedeclaration, |
4543 | /// The lookup results will be used for redeclaration of a name |
4544 | /// with external linkage; non-visible lookup results with external linkage |
4545 | /// may also be found. |
4546 | ForExternalRedeclaration |
4547 | }; |
4548 | |
4549 | RedeclarationKind forRedeclarationInCurContext() const { |
4550 | // A declaration with an owning module for linkage can never link against |
4551 | // anything that is not visible. We don't need to check linkage here; if |
4552 | // the context has internal linkage, redeclaration lookup won't find things |
4553 | // from other TUs, and we can't safely compute linkage yet in general. |
4554 | if (cast<Decl>(Val: CurContext) |
4555 | ->getOwningModuleForLinkage(/*IgnoreLinkage*/IgnoreLinkage: true)) |
4556 | return ForVisibleRedeclaration; |
4557 | return ForExternalRedeclaration; |
4558 | } |
4559 | |
4560 | /// The possible outcomes of name lookup for a literal operator. |
4561 | enum LiteralOperatorLookupResult { |
4562 | /// The lookup resulted in an error. |
4563 | LOLR_Error, |
4564 | /// The lookup found no match but no diagnostic was issued. |
4565 | LOLR_ErrorNoDiagnostic, |
4566 | /// The lookup found a single 'cooked' literal operator, which |
4567 | /// expects a normal literal to be built and passed to it. |
4568 | LOLR_Cooked, |
4569 | /// The lookup found a single 'raw' literal operator, which expects |
4570 | /// a string literal containing the spelling of the literal token. |
4571 | LOLR_Raw, |
4572 | /// The lookup found an overload set of literal operator templates, |
4573 | /// which expect the characters of the spelling of the literal token to be |
4574 | /// passed as a non-type template argument pack. |
4575 | LOLR_Template, |
4576 | /// The lookup found an overload set of literal operator templates, |
4577 | /// which expect the character type and characters of the spelling of the |
4578 | /// string literal token to be passed as template arguments. |
4579 | LOLR_StringTemplatePack, |
4580 | }; |
4581 | |
4582 | SpecialMemberOverloadResult LookupSpecialMember(CXXRecordDecl *D, |
4583 | CXXSpecialMember SM, |
4584 | bool ConstArg, |
4585 | bool VolatileArg, |
4586 | bool RValueThis, |
4587 | bool ConstThis, |
4588 | bool VolatileThis); |
4589 | |
4590 | typedef std::function<void(const TypoCorrection &)> TypoDiagnosticGenerator; |
4591 | typedef std::function<ExprResult(Sema &, TypoExpr *, TypoCorrection)> |
4592 | TypoRecoveryCallback; |
4593 | |
4594 | private: |
4595 | bool CppLookupName(LookupResult &R, Scope *S); |
4596 | |
4597 | struct TypoExprState { |
4598 | std::unique_ptr<TypoCorrectionConsumer> Consumer; |
4599 | TypoDiagnosticGenerator DiagHandler; |
4600 | TypoRecoveryCallback RecoveryHandler; |
4601 | TypoExprState(); |
4602 | TypoExprState(TypoExprState &&other) noexcept; |
4603 | TypoExprState &operator=(TypoExprState &&other) noexcept; |
4604 | }; |
4605 | |
4606 | /// The set of unhandled TypoExprs and their associated state. |
4607 | llvm::MapVector<TypoExpr *, TypoExprState> DelayedTypos; |
4608 | |
4609 | /// Creates a new TypoExpr AST node. |
4610 | TypoExpr *createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC, |
4611 | TypoDiagnosticGenerator TDG, |
4612 | TypoRecoveryCallback TRC, SourceLocation TypoLoc); |
4613 | |
4614 | // The set of known/encountered (unique, canonicalized) NamespaceDecls. |
4615 | // |
4616 | // The boolean value will be true to indicate that the namespace was loaded |
4617 | // from an AST/PCH file, or false otherwise. |
4618 | llvm::MapVector<NamespaceDecl*, bool> KnownNamespaces; |
4619 | |
4620 | /// Whether we have already loaded known namespaces from an extenal |
4621 | /// source. |
4622 | bool LoadedExternalKnownNamespaces; |
4623 | |
4624 | /// Helper for CorrectTypo and CorrectTypoDelayed used to create and |
4625 | /// populate a new TypoCorrectionConsumer. Returns nullptr if typo correction |
4626 | /// should be skipped entirely. |
4627 | std::unique_ptr<TypoCorrectionConsumer> |
4628 | makeTypoCorrectionConsumer(const DeclarationNameInfo &Typo, |
4629 | Sema::LookupNameKind LookupKind, Scope *S, |
4630 | CXXScopeSpec *SS, |
4631 | CorrectionCandidateCallback &CCC, |
4632 | DeclContext *MemberContext, bool EnteringContext, |
4633 | const ObjCObjectPointerType *OPT, |
4634 | bool ErrorRecovery); |
4635 | |
4636 | public: |
4637 | const TypoExprState &getTypoExprState(TypoExpr *TE) const; |
4638 | |
4639 | /// Clears the state of the given TypoExpr. |
4640 | void clearDelayedTypo(TypoExpr *TE); |
4641 | |
4642 | /// Look up a name, looking for a single declaration. Return |
4643 | /// null if the results were absent, ambiguous, or overloaded. |
4644 | /// |
4645 | /// It is preferable to use the elaborated form and explicitly handle |
4646 | /// ambiguity and overloaded. |
4647 | NamedDecl *LookupSingleName(Scope *S, DeclarationName Name, |
4648 | SourceLocation Loc, |
4649 | LookupNameKind NameKind, |
4650 | RedeclarationKind Redecl |
4651 | = NotForRedeclaration); |
4652 | bool LookupBuiltin(LookupResult &R); |
4653 | void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID); |
4654 | bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation = false, |
4655 | bool ForceNoCPlusPlus = false); |
4656 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
4657 | bool InUnqualifiedLookup = false); |
4658 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
4659 | CXXScopeSpec &SS); |
4660 | bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, |
4661 | bool AllowBuiltinCreation = false, |
4662 | bool EnteringContext = false); |
4663 | ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, |
4664 | RedeclarationKind Redecl |
4665 | = NotForRedeclaration); |
4666 | bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class); |
4667 | |
4668 | void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, |
4669 | UnresolvedSetImpl &Functions); |
4670 | |
4671 | LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, |
4672 | SourceLocation GnuLabelLoc = SourceLocation()); |
4673 | |
4674 | DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); |
4675 | CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class); |
4676 | CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class, |
4677 | unsigned Quals); |
4678 | CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, |
4679 | bool RValueThis, unsigned ThisQuals); |
4680 | CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class, |
4681 | unsigned Quals); |
4682 | CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals, |
4683 | bool RValueThis, unsigned ThisQuals); |
4684 | CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); |
4685 | |
4686 | bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id, |
4687 | bool IsUDSuffix); |
4688 | LiteralOperatorLookupResult |
4689 | LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef<QualType> ArgTys, |
4690 | bool AllowRaw, bool AllowTemplate, |
4691 | bool AllowStringTemplate, bool DiagnoseMissing, |
4692 | StringLiteral *StringLit = nullptr); |
4693 | bool isKnownName(StringRef name); |
4694 | |
4695 | /// Status of the function emission on the CUDA/HIP/OpenMP host/device attrs. |
4696 | enum class FunctionEmissionStatus { |
4697 | Emitted, |
4698 | CUDADiscarded, // Discarded due to CUDA/HIP hostness |
4699 | OMPDiscarded, // Discarded due to OpenMP hostness |
4700 | TemplateDiscarded, // Discarded due to uninstantiated templates |
4701 | Unknown, |
4702 | }; |
4703 | FunctionEmissionStatus getEmissionStatus(const FunctionDecl *Decl, |
4704 | bool Final = false); |
4705 | |
4706 | // Whether the callee should be ignored in CUDA/HIP/OpenMP host/device check. |
4707 | bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee); |
4708 | |
4709 | void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc, |
4710 | ArrayRef<Expr *> Args, ADLResult &Functions); |
4711 | |
4712 | void LookupVisibleDecls(Scope *S, LookupNameKind Kind, |
4713 | VisibleDeclConsumer &Consumer, |
4714 | bool IncludeGlobalScope = true, |
4715 | bool LoadExternal = true); |
4716 | void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, |
4717 | VisibleDeclConsumer &Consumer, |
4718 | bool IncludeGlobalScope = true, |
4719 | bool IncludeDependentBases = false, |
4720 | bool LoadExternal = true); |
4721 | |
4722 | enum CorrectTypoKind { |
4723 | CTK_NonError, // CorrectTypo used in a non error recovery situation. |
4724 | CTK_ErrorRecovery // CorrectTypo used in normal error recovery. |
4725 | }; |
4726 | |
4727 | TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, |
4728 | Sema::LookupNameKind LookupKind, |
4729 | Scope *S, CXXScopeSpec *SS, |
4730 | CorrectionCandidateCallback &CCC, |
4731 | CorrectTypoKind Mode, |
4732 | DeclContext *MemberContext = nullptr, |
4733 | bool EnteringContext = false, |
4734 | const ObjCObjectPointerType *OPT = nullptr, |
4735 | bool RecordFailure = true); |
4736 | |
4737 | TypoExpr *CorrectTypoDelayed(const DeclarationNameInfo &Typo, |
4738 | Sema::LookupNameKind LookupKind, Scope *S, |
4739 | CXXScopeSpec *SS, |
4740 | CorrectionCandidateCallback &CCC, |
4741 | TypoDiagnosticGenerator TDG, |
4742 | TypoRecoveryCallback TRC, CorrectTypoKind Mode, |
4743 | DeclContext *MemberContext = nullptr, |
4744 | bool EnteringContext = false, |
4745 | const ObjCObjectPointerType *OPT = nullptr); |
4746 | |
4747 | /// Process any TypoExprs in the given Expr and its children, |
4748 | /// generating diagnostics as appropriate and returning a new Expr if there |
4749 | /// were typos that were all successfully corrected and ExprError if one or |
4750 | /// more typos could not be corrected. |
4751 | /// |
4752 | /// \param E The Expr to check for TypoExprs. |
4753 | /// |
4754 | /// \param InitDecl A VarDecl to avoid because the Expr being corrected is its |
4755 | /// initializer. |
4756 | /// |
4757 | /// \param RecoverUncorrectedTypos If true, when typo correction fails, it |
4758 | /// will rebuild the given Expr with all TypoExprs degraded to RecoveryExprs. |
4759 | /// |
4760 | /// \param Filter A function applied to a newly rebuilt Expr to determine if |
4761 | /// it is an acceptable/usable result from a single combination of typo |
4762 | /// corrections. As long as the filter returns ExprError, different |
4763 | /// combinations of corrections will be tried until all are exhausted. |
4764 | ExprResult CorrectDelayedTyposInExpr( |
4765 | Expr *E, VarDecl *InitDecl = nullptr, |
4766 | bool RecoverUncorrectedTypos = false, |
4767 | llvm::function_ref<ExprResult(Expr *)> Filter = |
4768 | [](Expr *E) -> ExprResult { return E; }); |
4769 | |
4770 | ExprResult CorrectDelayedTyposInExpr( |
4771 | ExprResult ER, VarDecl *InitDecl = nullptr, |
4772 | bool RecoverUncorrectedTypos = false, |
4773 | llvm::function_ref<ExprResult(Expr *)> Filter = |
4774 | [](Expr *E) -> ExprResult { return E; }) { |
4775 | return ER.isInvalid() |
4776 | ? ER |
4777 | : CorrectDelayedTyposInExpr(E: ER.get(), InitDecl, |
4778 | RecoverUncorrectedTypos, Filter); |
4779 | } |
4780 | |
4781 | void diagnoseTypo(const TypoCorrection &Correction, |
4782 | const PartialDiagnostic &TypoDiag, |
4783 | bool ErrorRecovery = true); |
4784 | |
4785 | void diagnoseTypo(const TypoCorrection &Correction, |
4786 | const PartialDiagnostic &TypoDiag, |
4787 | const PartialDiagnostic &PrevNote, |
4788 | bool ErrorRecovery = true); |
4789 | |
4790 | void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F); |
4791 | |
4792 | void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc, |
4793 | ArrayRef<Expr *> Args, |
4794 | AssociatedNamespaceSet &AssociatedNamespaces, |
4795 | AssociatedClassSet &AssociatedClasses); |
4796 | |
4797 | void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, |
4798 | bool ConsiderLinkage, bool AllowInlineNamespace); |
4799 | |
4800 | bool CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old); |
4801 | bool CheckRedeclarationExported(NamedDecl *New, NamedDecl *Old); |
4802 | bool CheckRedeclarationInModule(NamedDecl *New, NamedDecl *Old); |
4803 | bool IsRedefinitionInModule(const NamedDecl *New, |
4804 | const NamedDecl *Old) const; |
4805 | |
4806 | void DiagnoseAmbiguousLookup(LookupResult &Result); |
4807 | //@} |
4808 | |
4809 | /// Attempts to produce a RecoveryExpr after some AST node cannot be created. |
4810 | ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, |
4811 | ArrayRef<Expr *> SubExprs, |
4812 | QualType T = QualType()); |
4813 | |
4814 | ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id, |
4815 | SourceLocation IdLoc, |
4816 | bool TypoCorrection = false); |
4817 | FunctionDecl *CreateBuiltin(IdentifierInfo *II, QualType Type, unsigned ID, |
4818 | SourceLocation Loc); |
4819 | NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, |
4820 | Scope *S, bool ForRedeclaration, |
4821 | SourceLocation Loc); |
4822 | NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
4823 | Scope *S); |
4824 | void AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction( |
4825 | FunctionDecl *FD); |
4826 | void AddKnownFunctionAttributes(FunctionDecl *FD); |
4827 | |
4828 | // More parsing and symbol table subroutines. |
4829 | |
4830 | void ProcessPragmaWeak(Scope *S, Decl *D); |
4831 | // Decl attributes - this routine is the top level dispatcher. |
4832 | void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD); |
4833 | // Helper for delayed processing of attributes. |
4834 | void ProcessDeclAttributeDelayed(Decl *D, |
4835 | const ParsedAttributesView &AttrList); |
4836 | |
4837 | // Options for ProcessDeclAttributeList(). |
4838 | struct ProcessDeclAttributeOptions { |
4839 | ProcessDeclAttributeOptions() |
4840 | : IncludeCXX11Attributes(true), IgnoreTypeAttributes(false) {} |
4841 | |
4842 | ProcessDeclAttributeOptions WithIncludeCXX11Attributes(bool Val) { |
4843 | ProcessDeclAttributeOptions Result = *this; |
4844 | Result.IncludeCXX11Attributes = Val; |
4845 | return Result; |
4846 | } |
4847 | |
4848 | ProcessDeclAttributeOptions WithIgnoreTypeAttributes(bool Val) { |
4849 | ProcessDeclAttributeOptions Result = *this; |
4850 | Result.IgnoreTypeAttributes = Val; |
4851 | return Result; |
4852 | } |
4853 | |
4854 | // Should C++11 attributes be processed? |
4855 | bool IncludeCXX11Attributes; |
4856 | |
4857 | // Should any type attributes encountered be ignored? |
4858 | // If this option is false, a diagnostic will be emitted for any type |
4859 | // attributes of a kind that does not "slide" from the declaration to |
4860 | // the decl-specifier-seq. |
4861 | bool IgnoreTypeAttributes; |
4862 | }; |
4863 | |
4864 | void ProcessDeclAttributeList(Scope *S, Decl *D, |
4865 | const ParsedAttributesView &AttrList, |
4866 | const ProcessDeclAttributeOptions &Options = |
4867 | ProcessDeclAttributeOptions()); |
4868 | bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, |
4869 | const ParsedAttributesView &AttrList); |
4870 | |
4871 | void checkUnusedDeclAttributes(Declarator &D); |
4872 | |
4873 | /// Handles semantic checking for features that are common to all attributes, |
4874 | /// such as checking whether a parameter was properly specified, or the |
4875 | /// correct number of arguments were passed, etc. Returns true if the |
4876 | /// attribute has been diagnosed. |
4877 | bool checkCommonAttributeFeatures(const Decl *D, const ParsedAttr &A, |
4878 | bool SkipArgCountCheck = false); |
4879 | bool checkCommonAttributeFeatures(const Stmt *S, const ParsedAttr &A, |
4880 | bool SkipArgCountCheck = false); |
4881 | |
4882 | /// Determine if type T is a valid subject for a nonnull and similar |
4883 | /// attributes. By default, we look through references (the behavior used by |
4884 | /// nonnull), but if the second parameter is true, then we treat a reference |
4885 | /// type as valid. |
4886 | bool isValidPointerAttrType(QualType T, bool RefOkay = false); |
4887 | |
4888 | bool CheckRegparmAttr(const ParsedAttr &attr, unsigned &value); |
4889 | |
4890 | /// Check validaty of calling convention attribute \p attr. If \p FD |
4891 | /// is not null pointer, use \p FD to determine the CUDA/HIP host/device |
4892 | /// target. Otherwise, it is specified by \p CFT. |
4893 | bool CheckCallingConvAttr(const ParsedAttr &attr, CallingConv &CC, |
4894 | const FunctionDecl *FD = nullptr, |
4895 | CUDAFunctionTarget CFT = CFT_InvalidTarget); |
4896 | bool CheckAttrTarget(const ParsedAttr &CurrAttr); |
4897 | bool CheckAttrNoArgs(const ParsedAttr &CurrAttr); |
4898 | bool checkStringLiteralArgumentAttr(const AttributeCommonInfo &CI, |
4899 | const Expr *E, StringRef &Str, |
4900 | SourceLocation *ArgLocation = nullptr); |
4901 | bool checkStringLiteralArgumentAttr(const ParsedAttr &Attr, unsigned ArgNum, |
4902 | StringRef &Str, |
4903 | SourceLocation *ArgLocation = nullptr); |
4904 | llvm::Error isValidSectionSpecifier(StringRef Str); |
4905 | bool checkSectionName(SourceLocation LiteralLoc, StringRef Str); |
4906 | bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str); |
4907 | bool checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D, |
4908 | StringRef &Str, bool &isDefault); |
4909 | bool checkTargetClonesAttrString( |
4910 | SourceLocation LiteralLoc, StringRef Str, const StringLiteral *Literal, |
4911 | Decl *D, bool &HasDefault, bool &HasCommas, bool &HasNotDefault, |
4912 | SmallVectorImpl<SmallString<64>> &StringsBuffer); |
4913 | bool checkMSInheritanceAttrOnDefinition( |
4914 | CXXRecordDecl *RD, SourceRange Range, bool BestCase, |
4915 | MSInheritanceModel SemanticSpelling); |
4916 | |
4917 | void CheckAlignasUnderalignment(Decl *D); |
4918 | |
4919 | bool CheckNoInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, |
4920 | const AttributeCommonInfo &A); |
4921 | bool CheckAlwaysInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, |
4922 | const AttributeCommonInfo &A); |
4923 | |
4924 | bool CheckCountedByAttr(Scope *Scope, const FieldDecl *FD); |
4925 | |
4926 | /// Adjust the calling convention of a method to be the ABI default if it |
4927 | /// wasn't specified explicitly. This handles method types formed from |
4928 | /// function type typedefs and typename template arguments. |
4929 | void adjustMemberFunctionCC(QualType &T, bool HasThisPointer, |
4930 | bool IsCtorOrDtor, SourceLocation Loc); |
4931 | |
4932 | // Check if there is an explicit attribute, but only look through parens. |
4933 | // The intent is to look for an attribute on the current declarator, but not |
4934 | // one that came from a typedef. |
4935 | bool hasExplicitCallingConv(QualType T); |
4936 | |
4937 | /// Get the outermost AttributedType node that sets a calling convention. |
4938 | /// Valid types should not have multiple attributes with different CCs. |
4939 | const AttributedType *getCallingConvAttributedType(QualType T) const; |
4940 | |
4941 | /// Check whether a nullability type specifier can be added to the given |
4942 | /// type through some means not written in source (e.g. API notes). |
4943 | /// |
4944 | /// \param Type The type to which the nullability specifier will be |
4945 | /// added. On success, this type will be updated appropriately. |
4946 | /// |
4947 | /// \param Nullability The nullability specifier to add. |
4948 | /// |
4949 | /// \param DiagLoc The location to use for diagnostics. |
4950 | /// |
4951 | /// \param AllowArrayTypes Whether to accept nullability specifiers on an |
4952 | /// array type (e.g., because it will decay to a pointer). |
4953 | /// |
4954 | /// \param OverrideExisting Whether to override an existing, locally-specified |
4955 | /// nullability specifier rather than complaining about the conflict. |
4956 | /// |
4957 | /// \returns true if nullability cannot be applied, false otherwise. |
4958 | bool CheckImplicitNullabilityTypeSpecifier(QualType &Type, |
4959 | NullabilityKind Nullability, |
4960 | SourceLocation DiagLoc, |
4961 | bool AllowArrayTypes, |
4962 | bool OverrideExisting); |
4963 | |
4964 | /// Process the attributes before creating an attributed statement. Returns |
4965 | /// the semantic attributes that have been processed. |
4966 | void ProcessStmtAttributes(Stmt *Stmt, const ParsedAttributes &InAttrs, |
4967 | SmallVectorImpl<const Attr *> &OutAttrs); |
4968 | |
4969 | void WarnConflictingTypedMethods(ObjCMethodDecl *Method, |
4970 | ObjCMethodDecl *MethodDecl, |
4971 | bool IsProtocolMethodDecl); |
4972 | |
4973 | void CheckConflictingOverridingMethod(ObjCMethodDecl *Method, |
4974 | ObjCMethodDecl *Overridden, |
4975 | bool IsProtocolMethodDecl); |
4976 | |
4977 | /// WarnExactTypedMethods - This routine issues a warning if method |
4978 | /// implementation declaration matches exactly that of its declaration. |
4979 | void WarnExactTypedMethods(ObjCMethodDecl *Method, |
4980 | ObjCMethodDecl *MethodDecl, |
4981 | bool IsProtocolMethodDecl); |
4982 | |
4983 | typedef llvm::SmallPtrSet<Selector, 8> SelectorSet; |
4984 | |
4985 | /// CheckImplementationIvars - This routine checks if the instance variables |
4986 | /// listed in the implelementation match those listed in the interface. |
4987 | void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, |
4988 | ObjCIvarDecl **Fields, unsigned nIvars, |
4989 | SourceLocation Loc); |
4990 | |
4991 | /// ImplMethodsVsClassMethods - This is main routine to warn if any method |
4992 | /// remains unimplemented in the class or category \@implementation. |
4993 | void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, |
4994 | ObjCContainerDecl* IDecl, |
4995 | bool IncompleteImpl = false); |
4996 | |
4997 | /// DiagnoseUnimplementedProperties - This routine warns on those properties |
4998 | /// which must be implemented by this implementation. |
4999 | void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, |
5000 | ObjCContainerDecl *CDecl, |
5001 | bool SynthesizeProperties); |
5002 | |
5003 | /// Diagnose any null-resettable synthesized setters. |
5004 | void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl); |
5005 | |
5006 | /// DefaultSynthesizeProperties - This routine default synthesizes all |
5007 | /// properties which must be synthesized in the class's \@implementation. |
5008 | void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, |
5009 | ObjCInterfaceDecl *IDecl, |
5010 | SourceLocation AtEnd); |
5011 | void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd); |
5012 | |
5013 | /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is |
5014 | /// an ivar synthesized for 'Method' and 'Method' is a property accessor |
5015 | /// declared in class 'IFace'. |
5016 | bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace, |
5017 | ObjCMethodDecl *Method, ObjCIvarDecl *IV); |
5018 | |
5019 | /// DiagnoseUnusedBackingIvarInAccessor - Issue an 'unused' warning if ivar which |
5020 | /// backs the property is not used in the property's accessor. |
5021 | void DiagnoseUnusedBackingIvarInAccessor(Scope *S, |
5022 | const ObjCImplementationDecl *ImplD); |
5023 | |
5024 | /// GetIvarBackingPropertyAccessor - If method is a property setter/getter and |
5025 | /// it property has a backing ivar, returns this ivar; otherwise, returns NULL. |
5026 | /// It also returns ivar's property on success. |
5027 | ObjCIvarDecl *GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method, |
5028 | const ObjCPropertyDecl *&PDecl) const; |
5029 | |
5030 | /// Called by ActOnProperty to handle \@property declarations in |
5031 | /// class extensions. |
5032 | ObjCPropertyDecl *HandlePropertyInClassExtension(Scope *S, |
5033 | SourceLocation AtLoc, |
5034 | SourceLocation LParenLoc, |
5035 | FieldDeclarator &FD, |
5036 | Selector GetterSel, |
5037 | SourceLocation GetterNameLoc, |
5038 | Selector SetterSel, |
5039 | SourceLocation SetterNameLoc, |
5040 | const bool isReadWrite, |
5041 | unsigned &Attributes, |
5042 | const unsigned AttributesAsWritten, |
5043 | QualType T, |
5044 | TypeSourceInfo *TSI, |
5045 | tok::ObjCKeywordKind MethodImplKind); |
5046 | |
5047 | /// Called by ActOnProperty and HandlePropertyInClassExtension to |
5048 | /// handle creating the ObjcPropertyDecl for a category or \@interface. |
5049 | ObjCPropertyDecl *CreatePropertyDecl(Scope *S, |
5050 | ObjCContainerDecl *CDecl, |
5051 | SourceLocation AtLoc, |
5052 | SourceLocation LParenLoc, |
5053 | FieldDeclarator &FD, |
5054 | Selector GetterSel, |
5055 | SourceLocation GetterNameLoc, |
5056 | Selector SetterSel, |
5057 | SourceLocation SetterNameLoc, |
5058 | const bool isReadWrite, |
5059 | const unsigned Attributes, |
5060 | const unsigned AttributesAsWritten, |
5061 | QualType T, |
5062 | TypeSourceInfo *TSI, |
5063 | tok::ObjCKeywordKind MethodImplKind, |
5064 | DeclContext *lexicalDC = nullptr); |
5065 | |
5066 | /// AtomicPropertySetterGetterRules - This routine enforces the rule (via |
5067 | /// warning) when atomic property has one but not the other user-declared |
5068 | /// setter or getter. |
5069 | void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl, |
5070 | ObjCInterfaceDecl* IDecl); |
5071 | |
5072 | void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D); |
5073 | |
5074 | void DiagnoseMissingDesignatedInitOverrides( |
5075 | const ObjCImplementationDecl *ImplD, |
5076 | const ObjCInterfaceDecl *IFD); |
5077 | |
5078 | void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); |
5079 | |
5080 | enum MethodMatchStrategy { |
5081 | MMS_loose, |
5082 | MMS_strict |
5083 | }; |
5084 | |
5085 | /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns |
5086 | /// true, or false, accordingly. |
5087 | bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, |
5088 | const ObjCMethodDecl *PrevMethod, |
5089 | MethodMatchStrategy strategy = MMS_strict); |
5090 | |
5091 | /// MatchAllMethodDeclarations - Check methods declaraed in interface or |
5092 | /// or protocol against those declared in their implementations. |
5093 | void MatchAllMethodDeclarations(const SelectorSet &InsMap, |
5094 | const SelectorSet &ClsMap, |
5095 | SelectorSet &InsMapSeen, |
5096 | SelectorSet &ClsMapSeen, |
5097 | ObjCImplDecl* IMPDecl, |
5098 | ObjCContainerDecl* IDecl, |
5099 | bool &IncompleteImpl, |
5100 | bool ImmediateClass, |
5101 | bool WarnCategoryMethodImpl=false); |
5102 | |
5103 | /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in |
5104 | /// category matches with those implemented in its primary class and |
5105 | /// warns each time an exact match is found. |
5106 | void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP); |
5107 | |
5108 | /// Add the given method to the list of globally-known methods. |
5109 | void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method); |
5110 | |
5111 | /// Returns default addr space for method qualifiers. |
5112 | LangAS getDefaultCXXMethodAddrSpace() const; |
5113 | |
5114 | private: |
5115 | /// AddMethodToGlobalPool - Add an instance or factory method to the global |
5116 | /// pool. See descriptoin of AddInstanceMethodToGlobalPool. |
5117 | void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); |
5118 | |
5119 | /// LookupMethodInGlobalPool - Returns the instance or factory method and |
5120 | /// optionally warns if there are multiple signatures. |
5121 | ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, |
5122 | bool receiverIdOrClass, |
5123 | bool instance); |
5124 | |
5125 | public: |
5126 | /// - Returns instance or factory methods in global method pool for |
5127 | /// given selector. It checks the desired kind first, if none is found, and |
5128 | /// parameter checkTheOther is set, it then checks the other kind. If no such |
5129 | /// method or only one method is found, function returns false; otherwise, it |
5130 | /// returns true. |
5131 | bool |
5132 | CollectMultipleMethodsInGlobalPool(Selector Sel, |
5133 | SmallVectorImpl<ObjCMethodDecl*>& Methods, |
5134 | bool InstanceFirst, bool CheckTheOther, |
5135 | const ObjCObjectType *TypeBound = nullptr); |
5136 | |
5137 | bool |
5138 | AreMultipleMethodsInGlobalPool(Selector Sel, ObjCMethodDecl *BestMethod, |
5139 | SourceRange R, bool receiverIdOrClass, |
5140 | SmallVectorImpl<ObjCMethodDecl*>& Methods); |
5141 | |
5142 | void |
5143 | DiagnoseMultipleMethodInGlobalPool(SmallVectorImpl<ObjCMethodDecl*> &Methods, |
5144 | Selector Sel, SourceRange R, |
5145 | bool receiverIdOrClass); |
5146 | |
5147 | private: |
5148 | /// - Returns a selector which best matches given argument list or |
5149 | /// nullptr if none could be found |
5150 | ObjCMethodDecl *SelectBestMethod(Selector Sel, MultiExprArg Args, |
5151 | bool IsInstance, |
5152 | SmallVectorImpl<ObjCMethodDecl*>& Methods); |
5153 | |
5154 | |
5155 | /// Record the typo correction failure and return an empty correction. |
5156 | TypoCorrection FailedCorrection(IdentifierInfo *Typo, SourceLocation TypoLoc, |
5157 | bool RecordFailure = true) { |
5158 | if (RecordFailure) |
5159 | TypoCorrectionFailures[Typo].insert(V: TypoLoc); |
5160 | return TypoCorrection(); |
5161 | } |
5162 | |
5163 | public: |
5164 | /// AddInstanceMethodToGlobalPool - All instance methods in a translation |
5165 | /// unit are added to a global pool. This allows us to efficiently associate |
5166 | /// a selector with a method declaraation for purposes of typechecking |
5167 | /// messages sent to "id" (where the class of the object is unknown). |
5168 | void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { |
5169 | AddMethodToGlobalPool(Method, impl, /*instance*/instance: true); |
5170 | } |
5171 | |
5172 | /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. |
5173 | void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { |
5174 | AddMethodToGlobalPool(Method, impl, /*instance*/instance: false); |
5175 | } |
5176 | |
5177 | /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global |
5178 | /// pool. |
5179 | void AddAnyMethodToGlobalPool(Decl *D); |
5180 | |
5181 | /// LookupInstanceMethodInGlobalPool - Returns the method and warns if |
5182 | /// there are multiple signatures. |
5183 | ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, |
5184 | bool receiverIdOrClass=false) { |
5185 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
5186 | /*instance*/instance: true); |
5187 | } |
5188 | |
5189 | /// LookupFactoryMethodInGlobalPool - Returns the method and warns if |
5190 | /// there are multiple signatures. |
5191 | ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, |
5192 | bool receiverIdOrClass=false) { |
5193 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
5194 | /*instance*/instance: false); |
5195 | } |
5196 | |
5197 | const ObjCMethodDecl *SelectorsForTypoCorrection(Selector Sel, |
5198 | QualType ObjectType=QualType()); |
5199 | /// LookupImplementedMethodInGlobalPool - Returns the method which has an |
5200 | /// implementation. |
5201 | ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); |
5202 | |
5203 | /// CollectIvarsToConstructOrDestruct - Collect those ivars which require |
5204 | /// initialization. |
5205 | void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, |
5206 | SmallVectorImpl<ObjCIvarDecl*> &Ivars); |
5207 | |
5208 | //===--------------------------------------------------------------------===// |
5209 | // Statement Parsing Callbacks: SemaStmt.cpp. |
5210 | public: |
5211 | class FullExprArg { |
5212 | public: |
5213 | FullExprArg() : E(nullptr) { } |
5214 | FullExprArg(Sema &actions) : E(nullptr) { } |
5215 | |
5216 | ExprResult release() { |
5217 | return E; |
5218 | } |
5219 | |
5220 | Expr *get() const { return E; } |
5221 | |
5222 | Expr *operator->() { |
5223 | return E; |
5224 | } |
5225 | |
5226 | private: |
5227 | // FIXME: No need to make the entire Sema class a friend when it's just |
5228 | // Sema::MakeFullExpr that needs access to the constructor below. |
5229 | friend class Sema; |
5230 | |
5231 | explicit FullExprArg(Expr *expr) : E(expr) {} |
5232 | |
5233 | Expr *E; |
5234 | }; |
5235 | |
5236 | FullExprArg MakeFullExpr(Expr *Arg) { |
5237 | return MakeFullExpr(Arg, CC: Arg ? Arg->getExprLoc() : SourceLocation()); |
5238 | } |
5239 | FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) { |
5240 | return FullExprArg( |
5241 | ActOnFinishFullExpr(Expr: Arg, CC, /*DiscardedValue*/ DiscardedValue: false).get()); |
5242 | } |
5243 | FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) { |
5244 | ExprResult FE = |
5245 | ActOnFinishFullExpr(Expr: Arg, CC: Arg ? Arg->getExprLoc() : SourceLocation(), |
5246 | /*DiscardedValue*/ DiscardedValue: true); |
5247 | return FullExprArg(FE.get()); |
5248 | } |
5249 | |
5250 | StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue = true); |
5251 | StmtResult ActOnExprStmtError(); |
5252 | |
5253 | StmtResult ActOnNullStmt(SourceLocation SemiLoc, |
5254 | bool HasLeadingEmptyMacro = false); |
5255 | |
5256 | void ActOnStartOfCompoundStmt(bool IsStmtExpr); |
5257 | void ActOnAfterCompoundStatementLeadingPragmas(); |
5258 | void ActOnFinishOfCompoundStmt(); |
5259 | StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
5260 | ArrayRef<Stmt *> Elts, bool isStmtExpr); |
5261 | |
5262 | /// A RAII object to enter scope of a compound statement. |
5263 | class CompoundScopeRAII { |
5264 | public: |
5265 | CompoundScopeRAII(Sema &S, bool IsStmtExpr = false) : S(S) { |
5266 | S.ActOnStartOfCompoundStmt(IsStmtExpr); |
5267 | } |
5268 | |
5269 | ~CompoundScopeRAII() { |
5270 | S.ActOnFinishOfCompoundStmt(); |
5271 | } |
5272 | |
5273 | private: |
5274 | Sema &S; |
5275 | }; |
5276 | |
5277 | /// An RAII helper that pops function a function scope on exit. |
5278 | struct FunctionScopeRAII { |
5279 | Sema &S; |
5280 | bool Active; |
5281 | FunctionScopeRAII(Sema &S) : S(S), Active(true) {} |
5282 | ~FunctionScopeRAII() { |
5283 | if (Active) |
5284 | S.PopFunctionScopeInfo(); |
5285 | } |
5286 | void disable() { Active = false; } |
5287 | }; |
5288 | |
5289 | StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, |
5290 | SourceLocation StartLoc, |
5291 | SourceLocation EndLoc); |
5292 | void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); |
5293 | StmtResult ActOnForEachLValueExpr(Expr *E); |
5294 | ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val); |
5295 | StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, |
5296 | SourceLocation DotDotDotLoc, ExprResult RHS, |
5297 | SourceLocation ColonLoc); |
5298 | void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); |
5299 | |
5300 | StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, |
5301 | SourceLocation ColonLoc, |
5302 | Stmt *SubStmt, Scope *CurScope); |
5303 | StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, |
5304 | SourceLocation ColonLoc, Stmt *SubStmt); |
5305 | |
5306 | StmtResult BuildAttributedStmt(SourceLocation AttrsLoc, |
5307 | ArrayRef<const Attr *> Attrs, Stmt *SubStmt); |
5308 | StmtResult ActOnAttributedStmt(const ParsedAttributes &AttrList, |
5309 | Stmt *SubStmt); |
5310 | |
5311 | class ConditionResult; |
5312 | |
5313 | StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, |
5314 | SourceLocation LParenLoc, Stmt *InitStmt, |
5315 | ConditionResult Cond, SourceLocation RParenLoc, |
5316 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
5317 | StmtResult BuildIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, |
5318 | SourceLocation LParenLoc, Stmt *InitStmt, |
5319 | ConditionResult Cond, SourceLocation RParenLoc, |
5320 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
5321 | StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, |
5322 | SourceLocation LParenLoc, Stmt *InitStmt, |
5323 | ConditionResult Cond, |
5324 | SourceLocation RParenLoc); |
5325 | StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, |
5326 | Stmt *Switch, Stmt *Body); |
5327 | StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, |
5328 | ConditionResult Cond, SourceLocation RParenLoc, |
5329 | Stmt *Body); |
5330 | StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, |
5331 | SourceLocation WhileLoc, SourceLocation CondLParen, |
5332 | Expr *Cond, SourceLocation CondRParen); |
5333 | |
5334 | StmtResult ActOnForStmt(SourceLocation ForLoc, |
5335 | SourceLocation LParenLoc, |
5336 | Stmt *First, |
5337 | ConditionResult Second, |
5338 | FullExprArg Third, |
5339 | SourceLocation RParenLoc, |
5340 | Stmt *Body); |
5341 | ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, |
5342 | Expr *collection); |
5343 | StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, |
5344 | Stmt *First, Expr *collection, |
5345 | SourceLocation RParenLoc); |
5346 | StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body); |
5347 | |
5348 | enum BuildForRangeKind { |
5349 | /// Initial building of a for-range statement. |
5350 | BFRK_Build, |
5351 | /// Instantiation or recovery rebuild of a for-range statement. Don't |
5352 | /// attempt any typo-correction. |
5353 | BFRK_Rebuild, |
5354 | /// Determining whether a for-range statement could be built. Avoid any |
5355 | /// unnecessary or irreversible actions. |
5356 | BFRK_Check |
5357 | }; |
5358 | |
5359 | StmtResult ActOnCXXForRangeStmt( |
5360 | Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc, |
5361 | Stmt *InitStmt, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection, |
5362 | SourceLocation RParenLoc, BuildForRangeKind Kind, |
5363 | ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps = {}); |
5364 | StmtResult BuildCXXForRangeStmt( |
5365 | SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, |
5366 | SourceLocation ColonLoc, Stmt *RangeDecl, Stmt *Begin, Stmt *End, |
5367 | Expr *Cond, Expr *Inc, Stmt *LoopVarDecl, SourceLocation RParenLoc, |
5368 | BuildForRangeKind Kind, |
5369 | ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps = {}); |
5370 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body); |
5371 | |
5372 | StmtResult ActOnGotoStmt(SourceLocation GotoLoc, |
5373 | SourceLocation LabelLoc, |
5374 | LabelDecl *TheDecl); |
5375 | StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, |
5376 | SourceLocation StarLoc, |
5377 | Expr *DestExp); |
5378 | StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope); |
5379 | StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope); |
5380 | |
5381 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
5382 | CapturedRegionKind Kind, unsigned NumParams); |
5383 | typedef std::pair<StringRef, QualType> CapturedParamNameType; |
5384 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
5385 | CapturedRegionKind Kind, |
5386 | ArrayRef<CapturedParamNameType> Params, |
5387 | unsigned OpenMPCaptureLevel = 0); |
5388 | StmtResult ActOnCapturedRegionEnd(Stmt *S); |
5389 | void ActOnCapturedRegionError(); |
5390 | RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD, |
5391 | SourceLocation Loc, |
5392 | unsigned NumParams); |
5393 | |
5394 | struct NamedReturnInfo { |
5395 | const VarDecl *Candidate; |
5396 | |
5397 | enum Status : uint8_t { None, MoveEligible, MoveEligibleAndCopyElidable }; |
5398 | Status S; |
5399 | |
5400 | bool isMoveEligible() const { return S != None; }; |
5401 | bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; } |
5402 | }; |
5403 | enum class SimplerImplicitMoveMode { ForceOff, Normal, ForceOn }; |
5404 | NamedReturnInfo getNamedReturnInfo( |
5405 | Expr *&E, SimplerImplicitMoveMode Mode = SimplerImplicitMoveMode::Normal); |
5406 | NamedReturnInfo getNamedReturnInfo(const VarDecl *VD); |
5407 | const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info, |
5408 | QualType ReturnType); |
5409 | |
5410 | ExprResult |
5411 | PerformMoveOrCopyInitialization(const InitializedEntity &Entity, |
5412 | const NamedReturnInfo &NRInfo, Expr *Value, |
5413 | bool SupressSimplerImplicitMoves = false); |
5414 | |
5415 | StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
5416 | Scope *CurScope); |
5417 | StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
5418 | bool AllowRecovery = false); |
5419 | StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
5420 | NamedReturnInfo &NRInfo, |
5421 | bool SupressSimplerImplicitMoves); |
5422 | |
5423 | StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
5424 | bool IsVolatile, unsigned NumOutputs, |
5425 | unsigned NumInputs, IdentifierInfo **Names, |
5426 | MultiExprArg Constraints, MultiExprArg Exprs, |
5427 | Expr *AsmString, MultiExprArg Clobbers, |
5428 | unsigned NumLabels, |
5429 | SourceLocation RParenLoc); |
5430 | |
5431 | void FillInlineAsmIdentifierInfo(Expr *Res, |
5432 | llvm::InlineAsmIdentifierInfo &Info); |
5433 | ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS, |
5434 | SourceLocation TemplateKWLoc, |
5435 | UnqualifiedId &Id, |
5436 | bool IsUnevaluatedContext); |
5437 | bool LookupInlineAsmField(StringRef Base, StringRef Member, |
5438 | unsigned &Offset, SourceLocation AsmLoc); |
5439 | ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member, |
5440 | SourceLocation AsmLoc); |
5441 | StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
5442 | ArrayRef<Token> AsmToks, |
5443 | StringRef AsmString, |
5444 | unsigned NumOutputs, unsigned NumInputs, |
5445 | ArrayRef<StringRef> Constraints, |
5446 | ArrayRef<StringRef> Clobbers, |
5447 | ArrayRef<Expr*> Exprs, |
5448 | SourceLocation EndLoc); |
5449 | LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName, |
5450 | SourceLocation Location, |
5451 | bool AlwaysCreate); |
5452 | |
5453 | VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, |
5454 | SourceLocation StartLoc, |
5455 | SourceLocation IdLoc, IdentifierInfo *Id, |
5456 | bool Invalid = false); |
5457 | |
5458 | Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); |
5459 | |
5460 | StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, |
5461 | Decl *Parm, Stmt *Body); |
5462 | |
5463 | StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); |
5464 | |
5465 | StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, |
5466 | MultiStmtArg Catch, Stmt *Finally); |
5467 | |
5468 | StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); |
5469 | StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, |
5470 | Scope *CurScope); |
5471 | ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, |
5472 | Expr *operand); |
5473 | StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, |
5474 | Expr *SynchExpr, |
5475 | Stmt *SynchBody); |
5476 | |
5477 | StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body); |
5478 | |
5479 | VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, |
5480 | SourceLocation StartLoc, |
5481 | SourceLocation IdLoc, |
5482 | IdentifierInfo *Id); |
5483 | |
5484 | Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); |
5485 | |
5486 | StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, |
5487 | Decl *ExDecl, Stmt *HandlerBlock); |
5488 | StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, |
5489 | ArrayRef<Stmt *> Handlers); |
5490 | |
5491 | StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ? |
5492 | SourceLocation TryLoc, Stmt *TryBlock, |
5493 | Stmt *Handler); |
5494 | StmtResult ActOnSEHExceptBlock(SourceLocation Loc, |
5495 | Expr *FilterExpr, |
5496 | Stmt *Block); |
5497 | void ActOnStartSEHFinallyBlock(); |
5498 | void ActOnAbortSEHFinallyBlock(); |
5499 | StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block); |
5500 | StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope); |
5501 | |
5502 | void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); |
5503 | |
5504 | bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; |
5505 | |
5506 | /// If it's a file scoped decl that must warn if not used, keep track |
5507 | /// of it. |
5508 | void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); |
5509 | |
5510 | typedef llvm::function_ref<void(SourceLocation Loc, PartialDiagnostic PD)> |
5511 | DiagReceiverTy; |
5512 | |
5513 | /// DiagnoseUnusedExprResult - If the statement passed in is an expression |
5514 | /// whose result is unused, warn. |
5515 | void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID); |
5516 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D); |
5517 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D, |
5518 | DiagReceiverTy DiagReceiver); |
5519 | void DiagnoseUnusedDecl(const NamedDecl *ND); |
5520 | void DiagnoseUnusedDecl(const NamedDecl *ND, DiagReceiverTy DiagReceiver); |
5521 | |
5522 | /// If VD is set but not otherwise used, diagnose, for a parameter or a |
5523 | /// variable. |
5524 | void DiagnoseUnusedButSetDecl(const VarDecl *VD, DiagReceiverTy DiagReceiver); |
5525 | |
5526 | /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null |
5527 | /// statement as a \p Body, and it is located on the same line. |
5528 | /// |
5529 | /// This helps prevent bugs due to typos, such as: |
5530 | /// if (condition); |
5531 | /// do_stuff(); |
5532 | void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, |
5533 | const Stmt *Body, |
5534 | unsigned DiagID); |
5535 | |
5536 | /// Warn if a for/while loop statement \p S, which is followed by |
5537 | /// \p PossibleBody, has a suspicious null statement as a body. |
5538 | void DiagnoseEmptyLoopBody(const Stmt *S, |
5539 | const Stmt *PossibleBody); |
5540 | |
5541 | /// Warn if a value is moved to itself. |
5542 | void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr, |
5543 | SourceLocation OpLoc); |
5544 | |
5545 | /// Returns a field in a CXXRecordDecl that has the same name as the decl \p |
5546 | /// SelfAssigned when inside a CXXMethodDecl. |
5547 | const FieldDecl * |
5548 | getSelfAssignmentClassMemberCandidate(const ValueDecl *SelfAssigned); |
5549 | |
5550 | /// Warn if we're implicitly casting from a _Nullable pointer type to a |
5551 | /// _Nonnull one. |
5552 | void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType, |
5553 | SourceLocation Loc); |
5554 | |
5555 | /// Warn when implicitly casting 0 to nullptr. |
5556 | void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E); |
5557 | |
5558 | ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) { |
5559 | return DelayedDiagnostics.push(pool); |
5560 | } |
5561 | void PopParsingDeclaration(ParsingDeclState state, Decl *decl); |
5562 | |
5563 | typedef ProcessingContextState ParsingClassState; |
5564 | ParsingClassState PushParsingClass() { |
5565 | ParsingClassDepth++; |
5566 | return DelayedDiagnostics.pushUndelayed(); |
5567 | } |
5568 | void PopParsingClass(ParsingClassState state) { |
5569 | ParsingClassDepth--; |
5570 | DelayedDiagnostics.popUndelayed(state); |
5571 | } |
5572 | |
5573 | void redelayDiagnostics(sema::DelayedDiagnosticPool &pool); |
5574 | |
5575 | void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
5576 | const ObjCInterfaceDecl *UnknownObjCClass, |
5577 | bool ObjCPropertyAccess, |
5578 | bool AvoidPartialAvailabilityChecks = false, |
5579 | ObjCInterfaceDecl *ClassReceiver = nullptr); |
5580 | |
5581 | bool (SourceLocation loc, |
5582 | UnavailableAttr::ImplicitReason reason); |
5583 | |
5584 | /// Issue any -Wunguarded-availability warnings in \c FD |
5585 | void DiagnoseUnguardedAvailabilityViolations(Decl *FD); |
5586 | |
5587 | void handleDelayedAvailabilityCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
5588 | |
5589 | //===--------------------------------------------------------------------===// |
5590 | // Expression Parsing Callbacks: SemaExpr.cpp. |
5591 | |
5592 | bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid); |
5593 | // A version of DiagnoseUseOfDecl that should be used if overload resolution |
5594 | // has been used to find this declaration, which means we don't have to bother |
5595 | // checking the trailing requires clause. |
5596 | bool DiagnoseUseOfOverloadedDecl(NamedDecl *D, SourceLocation Loc) { |
5597 | return DiagnoseUseOfDecl( |
5598 | D, Locs: Loc, /*UnknownObjCClass=*/UnknownObjCClass: nullptr, /*ObjCPropertyAccess=*/ObjCPropertyAccess: false, |
5599 | /*AvoidPartialAvailabilityChecks=*/AvoidPartialAvailabilityChecks: false, /*ClassReceiver=*/ClassReciever: nullptr, |
5600 | /*SkipTrailingRequiresClause=*/SkipTrailingRequiresClause: true); |
5601 | } |
5602 | |
5603 | bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
5604 | const ObjCInterfaceDecl *UnknownObjCClass = nullptr, |
5605 | bool ObjCPropertyAccess = false, |
5606 | bool AvoidPartialAvailabilityChecks = false, |
5607 | ObjCInterfaceDecl *ClassReciever = nullptr, |
5608 | bool SkipTrailingRequiresClause = false); |
5609 | void NoteDeletedFunction(FunctionDecl *FD); |
5610 | void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD); |
5611 | bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, |
5612 | ObjCMethodDecl *Getter, |
5613 | SourceLocation Loc); |
5614 | void DiagnoseSentinelCalls(const NamedDecl *D, SourceLocation Loc, |
5615 | ArrayRef<Expr *> Args); |
5616 | |
5617 | void PushExpressionEvaluationContext( |
5618 | ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl = nullptr, |
5619 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
5620 | ExpressionEvaluationContextRecord::EK_Other); |
5621 | enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl }; |
5622 | void PushExpressionEvaluationContext( |
5623 | ExpressionEvaluationContext NewContext, ReuseLambdaContextDecl_t, |
5624 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
5625 | ExpressionEvaluationContextRecord::EK_Other); |
5626 | void PopExpressionEvaluationContext(); |
5627 | |
5628 | void DiscardCleanupsInEvaluationContext(); |
5629 | |
5630 | ExprResult TransformToPotentiallyEvaluated(Expr *E); |
5631 | TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo); |
5632 | ExprResult HandleExprEvaluationContextForTypeof(Expr *E); |
5633 | |
5634 | ExprResult CheckUnevaluatedOperand(Expr *E); |
5635 | void CheckUnusedVolatileAssignment(Expr *E); |
5636 | |
5637 | ExprResult ActOnConstantExpression(ExprResult Res); |
5638 | |
5639 | // Functions for marking a declaration referenced. These functions also |
5640 | // contain the relevant logic for marking if a reference to a function or |
5641 | // variable is an odr-use (in the C++11 sense). There are separate variants |
5642 | // for expressions referring to a decl; these exist because odr-use marking |
5643 | // needs to be delayed for some constant variables when we build one of the |
5644 | // named expressions. |
5645 | // |
5646 | // MightBeOdrUse indicates whether the use could possibly be an odr-use, and |
5647 | // should usually be true. This only needs to be set to false if the lack of |
5648 | // odr-use cannot be determined from the current context (for instance, |
5649 | // because the name denotes a virtual function and was written without an |
5650 | // explicit nested-name-specifier). |
5651 | void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse); |
5652 | void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, |
5653 | bool MightBeOdrUse = true); |
5654 | void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var); |
5655 | void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base = nullptr); |
5656 | void MarkMemberReferenced(MemberExpr *E); |
5657 | void MarkFunctionParmPackReferenced(FunctionParmPackExpr *E); |
5658 | void MarkCaptureUsedInEnclosingContext(ValueDecl *Capture, SourceLocation Loc, |
5659 | unsigned CapturingScopeIndex); |
5660 | |
5661 | ExprResult CheckLValueToRValueConversionOperand(Expr *E); |
5662 | void CleanupVarDeclMarking(); |
5663 | |
5664 | enum TryCaptureKind { |
5665 | TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef |
5666 | }; |
5667 | |
5668 | /// Try to capture the given variable. |
5669 | /// |
5670 | /// \param Var The variable to capture. |
5671 | /// |
5672 | /// \param Loc The location at which the capture occurs. |
5673 | /// |
5674 | /// \param Kind The kind of capture, which may be implicit (for either a |
5675 | /// block or a lambda), or explicit by-value or by-reference (for a lambda). |
5676 | /// |
5677 | /// \param EllipsisLoc The location of the ellipsis, if one is provided in |
5678 | /// an explicit lambda capture. |
5679 | /// |
5680 | /// \param BuildAndDiagnose Whether we are actually supposed to add the |
5681 | /// captures or diagnose errors. If false, this routine merely check whether |
5682 | /// the capture can occur without performing the capture itself or complaining |
5683 | /// if the variable cannot be captured. |
5684 | /// |
5685 | /// \param CaptureType Will be set to the type of the field used to capture |
5686 | /// this variable in the innermost block or lambda. Only valid when the |
5687 | /// variable can be captured. |
5688 | /// |
5689 | /// \param DeclRefType Will be set to the type of a reference to the capture |
5690 | /// from within the current scope. Only valid when the variable can be |
5691 | /// captured. |
5692 | /// |
5693 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
5694 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
5695 | /// This is useful when enclosing lambdas must speculatively capture |
5696 | /// variables that may or may not be used in certain specializations of |
5697 | /// a nested generic lambda. |
5698 | /// |
5699 | /// \returns true if an error occurred (i.e., the variable cannot be |
5700 | /// captured) and false if the capture succeeded. |
5701 | bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, |
5702 | TryCaptureKind Kind, SourceLocation EllipsisLoc, |
5703 | bool BuildAndDiagnose, QualType &CaptureType, |
5704 | QualType &DeclRefType, |
5705 | const unsigned *const FunctionScopeIndexToStopAt); |
5706 | |
5707 | /// Try to capture the given variable. |
5708 | bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, |
5709 | TryCaptureKind Kind = TryCapture_Implicit, |
5710 | SourceLocation EllipsisLoc = SourceLocation()); |
5711 | |
5712 | /// Checks if the variable must be captured. |
5713 | bool NeedToCaptureVariable(ValueDecl *Var, SourceLocation Loc); |
5714 | |
5715 | /// Given a variable, determine the type that a reference to that |
5716 | /// variable will have in the given scope. |
5717 | QualType getCapturedDeclRefType(ValueDecl *Var, SourceLocation Loc); |
5718 | |
5719 | /// Mark all of the declarations referenced within a particular AST node as |
5720 | /// referenced. Used when template instantiation instantiates a non-dependent |
5721 | /// type -- entities referenced by the type are now referenced. |
5722 | void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); |
5723 | void MarkDeclarationsReferencedInExpr( |
5724 | Expr *E, bool SkipLocalVariables = false, |
5725 | ArrayRef<const Expr *> StopAt = std::nullopt); |
5726 | |
5727 | /// Try to recover by turning the given expression into a |
5728 | /// call. Returns true if recovery was attempted or an error was |
5729 | /// emitted; this may also leave the ExprResult invalid. |
5730 | bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, |
5731 | bool ForceComplain = false, |
5732 | bool (*IsPlausibleResult)(QualType) = nullptr); |
5733 | |
5734 | /// Figure out if an expression could be turned into a call. |
5735 | bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy, |
5736 | UnresolvedSetImpl &NonTemplateOverloads); |
5737 | |
5738 | /// Try to convert an expression \p E to type \p Ty. Returns the result of the |
5739 | /// conversion. |
5740 | ExprResult tryConvertExprToType(Expr *E, QualType Ty); |
5741 | |
5742 | /// Conditionally issue a diagnostic based on the statements's reachability |
5743 | /// analysis. |
5744 | /// |
5745 | /// \param Stmts If Stmts is non-empty, delay reporting the diagnostic until |
5746 | /// the function body is parsed, and then do a basic reachability analysis to |
5747 | /// determine if the statement is reachable. If it is unreachable, the |
5748 | /// diagnostic will not be emitted. |
5749 | bool DiagIfReachable(SourceLocation Loc, ArrayRef<const Stmt *> Stmts, |
5750 | const PartialDiagnostic &PD); |
5751 | |
5752 | /// Conditionally issue a diagnostic based on the current |
5753 | /// evaluation context. |
5754 | /// |
5755 | /// \param Statement If Statement is non-null, delay reporting the |
5756 | /// diagnostic until the function body is parsed, and then do a basic |
5757 | /// reachability analysis to determine if the statement is reachable. |
5758 | /// If it is unreachable, the diagnostic will not be emitted. |
5759 | bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, |
5760 | const PartialDiagnostic &PD); |
5761 | /// Similar, but diagnostic is only produced if all the specified statements |
5762 | /// are reachable. |
5763 | bool DiagRuntimeBehavior(SourceLocation Loc, ArrayRef<const Stmt*> Stmts, |
5764 | const PartialDiagnostic &PD); |
5765 | |
5766 | // Primary Expressions. |
5767 | SourceRange getExprRange(Expr *E) const; |
5768 | |
5769 | ExprResult ActOnIdExpression( |
5770 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
5771 | UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand, |
5772 | CorrectionCandidateCallback *CCC = nullptr, |
5773 | bool IsInlineAsmIdentifier = false, Token *KeywordReplacement = nullptr); |
5774 | |
5775 | void DecomposeUnqualifiedId(const UnqualifiedId &Id, |
5776 | TemplateArgumentListInfo &Buffer, |
5777 | DeclarationNameInfo &NameInfo, |
5778 | const TemplateArgumentListInfo *&TemplateArgs); |
5779 | |
5780 | bool DiagnoseDependentMemberLookup(const LookupResult &R); |
5781 | |
5782 | bool |
5783 | DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, |
5784 | CorrectionCandidateCallback &CCC, |
5785 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
5786 | ArrayRef<Expr *> Args = std::nullopt, |
5787 | DeclContext *LookupCtx = nullptr, |
5788 | TypoExpr **Out = nullptr); |
5789 | |
5790 | DeclResult LookupIvarInObjCMethod(LookupResult &Lookup, Scope *S, |
5791 | IdentifierInfo *II); |
5792 | ExprResult BuildIvarRefExpr(Scope *S, SourceLocation Loc, ObjCIvarDecl *IV); |
5793 | |
5794 | ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S, |
5795 | IdentifierInfo *II, |
5796 | bool AllowBuiltinCreation=false); |
5797 | |
5798 | ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, |
5799 | SourceLocation TemplateKWLoc, |
5800 | const DeclarationNameInfo &NameInfo, |
5801 | bool isAddressOfOperand, |
5802 | const TemplateArgumentListInfo *TemplateArgs); |
5803 | |
5804 | /// If \p D cannot be odr-used in the current expression evaluation context, |
5805 | /// return a reason explaining why. Otherwise, return NOUR_None. |
5806 | NonOdrUseReason getNonOdrUseReasonInCurrentContext(ValueDecl *D); |
5807 | |
5808 | DeclRefExpr *BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
5809 | SourceLocation Loc, |
5810 | const CXXScopeSpec *SS = nullptr); |
5811 | DeclRefExpr * |
5812 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
5813 | const DeclarationNameInfo &NameInfo, |
5814 | const CXXScopeSpec *SS = nullptr, |
5815 | NamedDecl *FoundD = nullptr, |
5816 | SourceLocation TemplateKWLoc = SourceLocation(), |
5817 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
5818 | DeclRefExpr * |
5819 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
5820 | const DeclarationNameInfo &NameInfo, |
5821 | NestedNameSpecifierLoc NNS, |
5822 | NamedDecl *FoundD = nullptr, |
5823 | SourceLocation TemplateKWLoc = SourceLocation(), |
5824 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
5825 | |
5826 | ExprResult |
5827 | BuildAnonymousStructUnionMemberReference( |
5828 | const CXXScopeSpec &SS, |
5829 | SourceLocation nameLoc, |
5830 | IndirectFieldDecl *indirectField, |
5831 | DeclAccessPair FoundDecl = DeclAccessPair::make(D: nullptr, AS: AS_none), |
5832 | Expr *baseObjectExpr = nullptr, |
5833 | SourceLocation opLoc = SourceLocation()); |
5834 | |
5835 | ExprResult BuildPossibleImplicitMemberExpr( |
5836 | const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, |
5837 | const TemplateArgumentListInfo *TemplateArgs, const Scope *S, |
5838 | UnresolvedLookupExpr *AsULE = nullptr); |
5839 | ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, |
5840 | SourceLocation TemplateKWLoc, |
5841 | LookupResult &R, |
5842 | const TemplateArgumentListInfo *TemplateArgs, |
5843 | bool IsDefiniteInstance, |
5844 | const Scope *S); |
5845 | bool UseArgumentDependentLookup(const CXXScopeSpec &SS, |
5846 | const LookupResult &R, |
5847 | bool HasTrailingLParen); |
5848 | |
5849 | ExprResult |
5850 | BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, |
5851 | const DeclarationNameInfo &NameInfo, |
5852 | bool IsAddressOfOperand, const Scope *S, |
5853 | TypeSourceInfo **RecoveryTSI = nullptr); |
5854 | |
5855 | ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS, |
5856 | SourceLocation TemplateKWLoc, |
5857 | const DeclarationNameInfo &NameInfo, |
5858 | const TemplateArgumentListInfo *TemplateArgs); |
5859 | |
5860 | ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, |
5861 | LookupResult &R, |
5862 | bool NeedsADL, |
5863 | bool AcceptInvalidDecl = false); |
5864 | ExprResult BuildDeclarationNameExpr( |
5865 | const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D, |
5866 | NamedDecl *FoundD = nullptr, |
5867 | const TemplateArgumentListInfo *TemplateArgs = nullptr, |
5868 | bool AcceptInvalidDecl = false); |
5869 | |
5870 | ExprResult BuildLiteralOperatorCall(LookupResult &R, |
5871 | DeclarationNameInfo &SuffixInfo, |
5872 | ArrayRef<Expr *> Args, |
5873 | SourceLocation LitEndLoc, |
5874 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
5875 | |
5876 | // ExpandFunctionLocalPredefinedMacros - Returns a new vector of Tokens, |
5877 | // where Tokens representing function local predefined macros (such as |
5878 | // __FUNCTION__) are replaced (expanded) with string-literal Tokens. |
5879 | std::vector<Token> ExpandFunctionLocalPredefinedMacros(ArrayRef<Token> Toks); |
5880 | |
5881 | ExprResult BuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK); |
5882 | ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); |
5883 | ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val); |
5884 | |
5885 | ExprResult BuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, |
5886 | SourceLocation LParen, |
5887 | SourceLocation RParen, |
5888 | TypeSourceInfo *TSI); |
5889 | ExprResult ActOnSYCLUniqueStableNameExpr(SourceLocation OpLoc, |
5890 | SourceLocation LParen, |
5891 | SourceLocation RParen, |
5892 | ParsedType ParsedTy); |
5893 | |
5894 | bool CheckLoopHintExpr(Expr *E, SourceLocation Loc); |
5895 | |
5896 | ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr); |
5897 | ExprResult ActOnCharacterConstant(const Token &Tok, |
5898 | Scope *UDLScope = nullptr); |
5899 | ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E); |
5900 | ExprResult ActOnParenListExpr(SourceLocation L, |
5901 | SourceLocation R, |
5902 | MultiExprArg Val); |
5903 | |
5904 | /// ActOnStringLiteral - The specified tokens were lexed as pasted string |
5905 | /// fragments (e.g. "foo" "bar" L"baz"). |
5906 | ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks, |
5907 | Scope *UDLScope = nullptr); |
5908 | |
5909 | ExprResult ActOnUnevaluatedStringLiteral(ArrayRef<Token> StringToks); |
5910 | |
5911 | /// ControllingExprOrType is either an opaque pointer coming out of a |
5912 | /// ParsedType or an Expr *. FIXME: it'd be better to split this interface |
5913 | /// into two so we don't take a void *, but that's awkward because one of |
5914 | /// the operands is either a ParsedType or an Expr *, which doesn't lend |
5915 | /// itself to generic code very well. |
5916 | ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, |
5917 | SourceLocation DefaultLoc, |
5918 | SourceLocation RParenLoc, |
5919 | bool PredicateIsExpr, |
5920 | void *ControllingExprOrType, |
5921 | ArrayRef<ParsedType> ArgTypes, |
5922 | ArrayRef<Expr *> ArgExprs); |
5923 | /// ControllingExprOrType is either a TypeSourceInfo * or an Expr *. FIXME: |
5924 | /// it'd be better to split this interface into two so we don't take a |
5925 | /// void *, but see the FIXME on ActOnGenericSelectionExpr as to why that |
5926 | /// isn't a trivial change. |
5927 | ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, |
5928 | SourceLocation DefaultLoc, |
5929 | SourceLocation RParenLoc, |
5930 | bool PredicateIsExpr, |
5931 | void *ControllingExprOrType, |
5932 | ArrayRef<TypeSourceInfo *> Types, |
5933 | ArrayRef<Expr *> Exprs); |
5934 | |
5935 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
5936 | ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, |
5937 | Expr *InputExpr, bool IsAfterAmp = false); |
5938 | ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, |
5939 | Expr *Input, bool IsAfterAmp = false); |
5940 | ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Op, |
5941 | Expr *Input, bool IsAfterAmp = false); |
5942 | |
5943 | bool isQualifiedMemberAccess(Expr *E); |
5944 | bool CheckUseOfCXXMethodAsAddressOfOperand(SourceLocation OpLoc, |
5945 | const Expr *Op, |
5946 | const CXXMethodDecl *MD); |
5947 | |
5948 | QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc); |
5949 | |
5950 | bool CheckTypeTraitArity(unsigned Arity, SourceLocation Loc, size_t N); |
5951 | |
5952 | bool ActOnAlignasTypeArgument(StringRef KWName, ParsedType Ty, |
5953 | SourceLocation OpLoc, SourceRange R); |
5954 | bool CheckAlignasTypeArgument(StringRef KWName, TypeSourceInfo *TInfo, |
5955 | SourceLocation OpLoc, SourceRange R); |
5956 | |
5957 | ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, |
5958 | SourceLocation OpLoc, |
5959 | UnaryExprOrTypeTrait ExprKind, |
5960 | SourceRange R); |
5961 | ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, |
5962 | UnaryExprOrTypeTrait ExprKind); |
5963 | ExprResult |
5964 | ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, |
5965 | UnaryExprOrTypeTrait ExprKind, |
5966 | bool IsType, void *TyOrEx, |
5967 | SourceRange ArgRange); |
5968 | |
5969 | ExprResult CheckPlaceholderExpr(Expr *E); |
5970 | bool CheckVecStepExpr(Expr *E); |
5971 | |
5972 | bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind); |
5973 | bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc, |
5974 | SourceRange ExprRange, |
5975 | UnaryExprOrTypeTrait ExprKind, |
5976 | StringRef KWName); |
5977 | ExprResult ActOnSizeofParameterPackExpr(Scope *S, |
5978 | SourceLocation OpLoc, |
5979 | IdentifierInfo &Name, |
5980 | SourceLocation NameLoc, |
5981 | SourceLocation RParenLoc); |
5982 | |
5983 | ExprResult ActOnPackIndexingExpr(Scope *S, Expr *PackExpression, |
5984 | SourceLocation EllipsisLoc, |
5985 | SourceLocation LSquareLoc, Expr *IndexExpr, |
5986 | SourceLocation RSquareLoc); |
5987 | |
5988 | ExprResult BuildPackIndexingExpr(Expr *PackExpression, |
5989 | SourceLocation EllipsisLoc, Expr *IndexExpr, |
5990 | SourceLocation RSquareLoc, |
5991 | ArrayRef<Expr *> ExpandedExprs = {}, |
5992 | bool EmptyPack = false); |
5993 | |
5994 | ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, |
5995 | tok::TokenKind Kind, Expr *Input); |
5996 | |
5997 | ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, |
5998 | MultiExprArg ArgExprs, |
5999 | SourceLocation RLoc); |
6000 | ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, |
6001 | Expr *Idx, SourceLocation RLoc); |
6002 | |
6003 | ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, |
6004 | Expr *ColumnIdx, |
6005 | SourceLocation RBLoc); |
6006 | |
6007 | ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, |
6008 | Expr *LowerBound, |
6009 | SourceLocation ColonLocFirst, |
6010 | SourceLocation ColonLocSecond, |
6011 | Expr *Length, Expr *Stride, |
6012 | SourceLocation RBLoc); |
6013 | ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, |
6014 | SourceLocation RParenLoc, |
6015 | ArrayRef<Expr *> Dims, |
6016 | ArrayRef<SourceRange> Brackets); |
6017 | |
6018 | /// Data structure for iterator expression. |
6019 | struct OMPIteratorData { |
6020 | IdentifierInfo *DeclIdent = nullptr; |
6021 | SourceLocation DeclIdentLoc; |
6022 | ParsedType Type; |
6023 | OMPIteratorExpr::IteratorRange Range; |
6024 | SourceLocation AssignLoc; |
6025 | SourceLocation ColonLoc; |
6026 | SourceLocation SecColonLoc; |
6027 | }; |
6028 | |
6029 | ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc, |
6030 | SourceLocation LLoc, SourceLocation RLoc, |
6031 | ArrayRef<OMPIteratorData> Data); |
6032 | |
6033 | // This struct is for use by ActOnMemberAccess to allow |
6034 | // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after |
6035 | // changing the access operator from a '.' to a '->' (to see if that is the |
6036 | // change needed to fix an error about an unknown member, e.g. when the class |
6037 | // defines a custom operator->). |
6038 | struct { |
6039 | Scope *; |
6040 | UnqualifiedId &; |
6041 | Decl *; |
6042 | }; |
6043 | |
6044 | ExprResult BuildMemberReferenceExpr( |
6045 | Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, |
6046 | CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
6047 | NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, |
6048 | const TemplateArgumentListInfo *TemplateArgs, |
6049 | const Scope *S, |
6050 | ActOnMemberAccessExtraArgs * = nullptr); |
6051 | |
6052 | ExprResult |
6053 | BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, |
6054 | bool IsArrow, const CXXScopeSpec &SS, |
6055 | SourceLocation TemplateKWLoc, |
6056 | NamedDecl *FirstQualifierInScope, LookupResult &R, |
6057 | const TemplateArgumentListInfo *TemplateArgs, |
6058 | const Scope *S, |
6059 | bool SuppressQualifierCheck = false, |
6060 | ActOnMemberAccessExtraArgs * = nullptr); |
6061 | |
6062 | ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, |
6063 | SourceLocation OpLoc, |
6064 | const CXXScopeSpec &SS, FieldDecl *Field, |
6065 | DeclAccessPair FoundDecl, |
6066 | const DeclarationNameInfo &MemberNameInfo); |
6067 | |
6068 | ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow); |
6069 | |
6070 | bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, |
6071 | const CXXScopeSpec &SS, |
6072 | const LookupResult &R); |
6073 | |
6074 | ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, |
6075 | bool IsArrow, SourceLocation OpLoc, |
6076 | const CXXScopeSpec &SS, |
6077 | SourceLocation TemplateKWLoc, |
6078 | NamedDecl *FirstQualifierInScope, |
6079 | const DeclarationNameInfo &NameInfo, |
6080 | const TemplateArgumentListInfo *TemplateArgs); |
6081 | |
6082 | ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, |
6083 | SourceLocation OpLoc, |
6084 | tok::TokenKind OpKind, |
6085 | CXXScopeSpec &SS, |
6086 | SourceLocation TemplateKWLoc, |
6087 | UnqualifiedId &Member, |
6088 | Decl *ObjCImpDecl); |
6089 | |
6090 | MemberExpr * |
6091 | BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc, |
6092 | const CXXScopeSpec *SS, SourceLocation TemplateKWLoc, |
6093 | ValueDecl *Member, DeclAccessPair FoundDecl, |
6094 | bool HadMultipleCandidates, |
6095 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, |
6096 | ExprValueKind VK, ExprObjectKind OK, |
6097 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
6098 | MemberExpr * |
6099 | BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc, |
6100 | NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, |
6101 | ValueDecl *Member, DeclAccessPair FoundDecl, |
6102 | bool HadMultipleCandidates, |
6103 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, |
6104 | ExprValueKind VK, ExprObjectKind OK, |
6105 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
6106 | |
6107 | void ActOnDefaultCtorInitializers(Decl *CDtorDecl); |
6108 | bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, |
6109 | FunctionDecl *FDecl, |
6110 | const FunctionProtoType *Proto, |
6111 | ArrayRef<Expr *> Args, |
6112 | SourceLocation RParenLoc, |
6113 | bool ExecConfig = false); |
6114 | void CheckStaticArrayArgument(SourceLocation CallLoc, |
6115 | ParmVarDecl *Param, |
6116 | const Expr *ArgExpr); |
6117 | |
6118 | /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. |
6119 | /// This provides the location of the left/right parens and a list of comma |
6120 | /// locations. |
6121 | ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
6122 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
6123 | Expr *ExecConfig = nullptr); |
6124 | ExprResult BuildCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
6125 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
6126 | Expr *ExecConfig = nullptr, |
6127 | bool IsExecConfig = false, |
6128 | bool AllowRecovery = false); |
6129 | Expr *BuildBuiltinCallExpr(SourceLocation Loc, Builtin::ID Id, |
6130 | MultiExprArg CallArgs); |
6131 | enum class AtomicArgumentOrder { API, AST }; |
6132 | ExprResult |
6133 | BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, |
6134 | SourceLocation RParenLoc, MultiExprArg Args, |
6135 | AtomicExpr::AtomicOp Op, |
6136 | AtomicArgumentOrder ArgOrder = AtomicArgumentOrder::API); |
6137 | ExprResult |
6138 | BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, SourceLocation LParenLoc, |
6139 | ArrayRef<Expr *> Arg, SourceLocation RParenLoc, |
6140 | Expr *Config = nullptr, bool IsExecConfig = false, |
6141 | ADLCallKind UsesADL = ADLCallKind::NotADL); |
6142 | |
6143 | ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, |
6144 | MultiExprArg ExecConfig, |
6145 | SourceLocation GGGLoc); |
6146 | |
6147 | ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, |
6148 | Declarator &D, ParsedType &Ty, |
6149 | SourceLocation RParenLoc, Expr *CastExpr); |
6150 | ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, |
6151 | TypeSourceInfo *Ty, |
6152 | SourceLocation RParenLoc, |
6153 | Expr *Op); |
6154 | CastKind PrepareScalarCast(ExprResult &src, QualType destType); |
6155 | |
6156 | /// Build an altivec or OpenCL literal. |
6157 | ExprResult BuildVectorLiteral(SourceLocation LParenLoc, |
6158 | SourceLocation RParenLoc, Expr *E, |
6159 | TypeSourceInfo *TInfo); |
6160 | |
6161 | ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); |
6162 | |
6163 | ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, |
6164 | ParsedType Ty, |
6165 | SourceLocation RParenLoc, |
6166 | Expr *InitExpr); |
6167 | |
6168 | ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, |
6169 | TypeSourceInfo *TInfo, |
6170 | SourceLocation RParenLoc, |
6171 | Expr *LiteralExpr); |
6172 | |
6173 | ExprResult ActOnInitList(SourceLocation LBraceLoc, |
6174 | MultiExprArg InitArgList, |
6175 | SourceLocation RBraceLoc); |
6176 | |
6177 | ExprResult BuildInitList(SourceLocation LBraceLoc, |
6178 | MultiExprArg InitArgList, |
6179 | SourceLocation RBraceLoc); |
6180 | |
6181 | ExprResult ActOnDesignatedInitializer(Designation &Desig, |
6182 | SourceLocation EqualOrColonLoc, |
6183 | bool GNUSyntax, |
6184 | ExprResult Init); |
6185 | |
6186 | private: |
6187 | static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind); |
6188 | |
6189 | public: |
6190 | ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, |
6191 | tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr); |
6192 | ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, |
6193 | BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr); |
6194 | ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, |
6195 | Expr *LHSExpr, Expr *RHSExpr); |
6196 | void LookupBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, |
6197 | UnresolvedSetImpl &Functions); |
6198 | |
6199 | void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc); |
6200 | |
6201 | /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
6202 | /// in the case of a the GNU conditional expr extension. |
6203 | ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, |
6204 | SourceLocation ColonLoc, |
6205 | Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr); |
6206 | |
6207 | /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". |
6208 | ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, |
6209 | LabelDecl *TheDecl); |
6210 | |
6211 | void ActOnStartStmtExpr(); |
6212 | ExprResult ActOnStmtExpr(Scope *S, SourceLocation LPLoc, Stmt *SubStmt, |
6213 | SourceLocation RPLoc); |
6214 | ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, |
6215 | SourceLocation RPLoc, unsigned TemplateDepth); |
6216 | // Handle the final expression in a statement expression. |
6217 | ExprResult ActOnStmtExprResult(ExprResult E); |
6218 | void ActOnStmtExprError(); |
6219 | |
6220 | // __builtin_offsetof(type, identifier(.identifier|[expr])*) |
6221 | struct OffsetOfComponent { |
6222 | SourceLocation LocStart, LocEnd; |
6223 | bool isBrackets; // true if [expr], false if .ident |
6224 | union { |
6225 | IdentifierInfo *IdentInfo; |
6226 | Expr *E; |
6227 | } U; |
6228 | }; |
6229 | |
6230 | /// __builtin_offsetof(type, a.b[123][456].c) |
6231 | ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, |
6232 | TypeSourceInfo *TInfo, |
6233 | ArrayRef<OffsetOfComponent> Components, |
6234 | SourceLocation RParenLoc); |
6235 | ExprResult ActOnBuiltinOffsetOf(Scope *S, |
6236 | SourceLocation BuiltinLoc, |
6237 | SourceLocation TypeLoc, |
6238 | ParsedType ParsedArgTy, |
6239 | ArrayRef<OffsetOfComponent> Components, |
6240 | SourceLocation RParenLoc); |
6241 | |
6242 | // __builtin_choose_expr(constExpr, expr1, expr2) |
6243 | ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, |
6244 | Expr *CondExpr, Expr *LHSExpr, |
6245 | Expr *RHSExpr, SourceLocation RPLoc); |
6246 | |
6247 | // __builtin_va_arg(expr, type) |
6248 | ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, |
6249 | SourceLocation RPLoc); |
6250 | ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, |
6251 | TypeSourceInfo *TInfo, SourceLocation RPLoc); |
6252 | |
6253 | // __builtin_LINE(), __builtin_FUNCTION(), __builtin_FUNCSIG(), |
6254 | // __builtin_FILE(), __builtin_COLUMN(), __builtin_source_location() |
6255 | ExprResult ActOnSourceLocExpr(SourceLocIdentKind Kind, |
6256 | SourceLocation BuiltinLoc, |
6257 | SourceLocation RPLoc); |
6258 | |
6259 | // Build a potentially resolved SourceLocExpr. |
6260 | ExprResult BuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, |
6261 | SourceLocation BuiltinLoc, SourceLocation RPLoc, |
6262 | DeclContext *ParentContext); |
6263 | |
6264 | // __null |
6265 | ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); |
6266 | |
6267 | bool CheckCaseExpression(Expr *E); |
6268 | |
6269 | /// Describes the result of an "if-exists" condition check. |
6270 | enum IfExistsResult { |
6271 | /// The symbol exists. |
6272 | IER_Exists, |
6273 | |
6274 | /// The symbol does not exist. |
6275 | IER_DoesNotExist, |
6276 | |
6277 | /// The name is a dependent name, so the results will differ |
6278 | /// from one instantiation to the next. |
6279 | IER_Dependent, |
6280 | |
6281 | /// An error occurred. |
6282 | IER_Error |
6283 | }; |
6284 | |
6285 | IfExistsResult |
6286 | CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, |
6287 | const DeclarationNameInfo &TargetNameInfo); |
6288 | |
6289 | IfExistsResult |
6290 | CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc, |
6291 | bool IsIfExists, CXXScopeSpec &SS, |
6292 | UnqualifiedId &Name); |
6293 | |
6294 | StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
6295 | bool IsIfExists, |
6296 | NestedNameSpecifierLoc QualifierLoc, |
6297 | DeclarationNameInfo NameInfo, |
6298 | Stmt *Nested); |
6299 | StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, |
6300 | bool IsIfExists, |
6301 | CXXScopeSpec &SS, UnqualifiedId &Name, |
6302 | Stmt *Nested); |
6303 | |
6304 | //===------------------------- "Block" Extension ------------------------===// |
6305 | |
6306 | /// ActOnBlockStart - This callback is invoked when a block literal is |
6307 | /// started. |
6308 | void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); |
6309 | |
6310 | /// ActOnBlockArguments - This callback allows processing of block arguments. |
6311 | /// If there are no arguments, this is still invoked. |
6312 | void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, |
6313 | Scope *CurScope); |
6314 | |
6315 | /// ActOnBlockError - If there is an error parsing a block, this callback |
6316 | /// is invoked to pop the information about the block from the action impl. |
6317 | void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); |
6318 | |
6319 | /// ActOnBlockStmtExpr - This is called when the body of a block statement |
6320 | /// literal was successfully completed. ^(int x){...} |
6321 | ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, |
6322 | Scope *CurScope); |
6323 | |
6324 | //===---------------------------- Clang Extensions ----------------------===// |
6325 | |
6326 | /// __builtin_convertvector(...) |
6327 | ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy, |
6328 | SourceLocation BuiltinLoc, |
6329 | SourceLocation RParenLoc); |
6330 | |
6331 | //===---------------------------- OpenCL Features -----------------------===// |
6332 | |
6333 | /// __builtin_astype(...) |
6334 | ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, |
6335 | SourceLocation BuiltinLoc, |
6336 | SourceLocation RParenLoc); |
6337 | ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy, |
6338 | SourceLocation BuiltinLoc, |
6339 | SourceLocation RParenLoc); |
6340 | |
6341 | //===---------------------------- HLSL Features -------------------------===// |
6342 | Decl *ActOnStartHLSLBuffer(Scope *BufferScope, bool CBuffer, |
6343 | SourceLocation KwLoc, IdentifierInfo *Ident, |
6344 | SourceLocation IdentLoc, SourceLocation LBrace); |
6345 | void ActOnFinishHLSLBuffer(Decl *Dcl, SourceLocation RBrace); |
6346 | |
6347 | //===---------------------------- C++ Features --------------------------===// |
6348 | |
6349 | // Act on C++ namespaces |
6350 | Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, |
6351 | SourceLocation NamespaceLoc, |
6352 | SourceLocation IdentLoc, IdentifierInfo *Ident, |
6353 | SourceLocation LBrace, |
6354 | const ParsedAttributesView &AttrList, |
6355 | UsingDirectiveDecl *&UsingDecl, bool IsNested); |
6356 | void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); |
6357 | |
6358 | NamespaceDecl *getStdNamespace() const; |
6359 | NamespaceDecl *getOrCreateStdNamespace(); |
6360 | |
6361 | CXXRecordDecl *getStdBadAlloc() const; |
6362 | EnumDecl *getStdAlignValT() const; |
6363 | |
6364 | ValueDecl *tryLookupUnambiguousFieldDecl(RecordDecl *ClassDecl, |
6365 | const IdentifierInfo *MemberOrBase); |
6366 | |
6367 | private: |
6368 | // A cache representing if we've fully checked the various comparison category |
6369 | // types stored in ASTContext. The bit-index corresponds to the integer value |
6370 | // of a ComparisonCategoryType enumerator. |
6371 | llvm::SmallBitVector FullyCheckedComparisonCategories; |
6372 | |
6373 | ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl, |
6374 | CXXScopeSpec &SS, |
6375 | ParsedType TemplateTypeTy, |
6376 | IdentifierInfo *MemberOrBase); |
6377 | |
6378 | public: |
6379 | enum class ComparisonCategoryUsage { |
6380 | /// The '<=>' operator was used in an expression and a builtin operator |
6381 | /// was selected. |
6382 | OperatorInExpression, |
6383 | /// A defaulted 'operator<=>' needed the comparison category. This |
6384 | /// typically only applies to 'std::strong_ordering', due to the implicit |
6385 | /// fallback return value. |
6386 | DefaultedOperator, |
6387 | }; |
6388 | |
6389 | /// Lookup the specified comparison category types in the standard |
6390 | /// library, an check the VarDecls possibly returned by the operator<=> |
6391 | /// builtins for that type. |
6392 | /// |
6393 | /// \return The type of the comparison category type corresponding to the |
6394 | /// specified Kind, or a null type if an error occurs |
6395 | QualType CheckComparisonCategoryType(ComparisonCategoryType Kind, |
6396 | SourceLocation Loc, |
6397 | ComparisonCategoryUsage Usage); |
6398 | |
6399 | /// Tests whether Ty is an instance of std::initializer_list and, if |
6400 | /// it is and Element is not NULL, assigns the element type to Element. |
6401 | bool isStdInitializerList(QualType Ty, QualType *Element); |
6402 | |
6403 | /// Looks for the std::initializer_list template and instantiates it |
6404 | /// with Element, or emits an error if it's not found. |
6405 | /// |
6406 | /// \returns The instantiated template, or null on error. |
6407 | QualType BuildStdInitializerList(QualType Element, SourceLocation Loc); |
6408 | |
6409 | /// Determine whether Ctor is an initializer-list constructor, as |
6410 | /// defined in [dcl.init.list]p2. |
6411 | bool isInitListConstructor(const FunctionDecl *Ctor); |
6412 | |
6413 | Decl *ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc, |
6414 | SourceLocation NamespcLoc, CXXScopeSpec &SS, |
6415 | SourceLocation IdentLoc, |
6416 | IdentifierInfo *NamespcName, |
6417 | const ParsedAttributesView &AttrList); |
6418 | |
6419 | void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); |
6420 | |
6421 | Decl *ActOnNamespaceAliasDef(Scope *CurScope, |
6422 | SourceLocation NamespaceLoc, |
6423 | SourceLocation AliasLoc, |
6424 | IdentifierInfo *Alias, |
6425 | CXXScopeSpec &SS, |
6426 | SourceLocation IdentLoc, |
6427 | IdentifierInfo *Ident); |
6428 | |
6429 | void FilterUsingLookup(Scope *S, LookupResult &lookup); |
6430 | void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); |
6431 | bool CheckUsingShadowDecl(BaseUsingDecl *BUD, NamedDecl *Target, |
6432 | const LookupResult &PreviousDecls, |
6433 | UsingShadowDecl *&PrevShadow); |
6434 | UsingShadowDecl *BuildUsingShadowDecl(Scope *S, BaseUsingDecl *BUD, |
6435 | NamedDecl *Target, |
6436 | UsingShadowDecl *PrevDecl); |
6437 | |
6438 | bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, |
6439 | bool HasTypenameKeyword, |
6440 | const CXXScopeSpec &SS, |
6441 | SourceLocation NameLoc, |
6442 | const LookupResult &Previous); |
6443 | bool CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename, |
6444 | const CXXScopeSpec &SS, |
6445 | const DeclarationNameInfo &NameInfo, |
6446 | SourceLocation NameLoc, |
6447 | const LookupResult *R = nullptr, |
6448 | const UsingDecl *UD = nullptr); |
6449 | |
6450 | NamedDecl *BuildUsingDeclaration( |
6451 | Scope *S, AccessSpecifier AS, SourceLocation UsingLoc, |
6452 | bool HasTypenameKeyword, SourceLocation TypenameLoc, CXXScopeSpec &SS, |
6453 | DeclarationNameInfo NameInfo, SourceLocation EllipsisLoc, |
6454 | const ParsedAttributesView &AttrList, bool IsInstantiation, |
6455 | bool IsUsingIfExists); |
6456 | NamedDecl *BuildUsingEnumDeclaration(Scope *S, AccessSpecifier AS, |
6457 | SourceLocation UsingLoc, |
6458 | SourceLocation EnumLoc, |
6459 | SourceLocation NameLoc, |
6460 | TypeSourceInfo *EnumType, EnumDecl *ED); |
6461 | NamedDecl *BuildUsingPackDecl(NamedDecl *InstantiatedFrom, |
6462 | ArrayRef<NamedDecl *> Expansions); |
6463 | |
6464 | bool CheckInheritingConstructorUsingDecl(UsingDecl *UD); |
6465 | |
6466 | /// Given a derived-class using shadow declaration for a constructor and the |
6467 | /// correspnding base class constructor, find or create the implicit |
6468 | /// synthesized derived class constructor to use for this initialization. |
6469 | CXXConstructorDecl * |
6470 | findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor, |
6471 | ConstructorUsingShadowDecl *DerivedShadow); |
6472 | |
6473 | Decl *ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS, |
6474 | SourceLocation UsingLoc, |
6475 | SourceLocation TypenameLoc, CXXScopeSpec &SS, |
6476 | UnqualifiedId &Name, SourceLocation EllipsisLoc, |
6477 | const ParsedAttributesView &AttrList); |
6478 | Decl *ActOnUsingEnumDeclaration(Scope *CurScope, AccessSpecifier AS, |
6479 | SourceLocation UsingLoc, |
6480 | SourceLocation EnumLoc, |
6481 | SourceLocation IdentLoc, IdentifierInfo &II, |
6482 | CXXScopeSpec *SS = nullptr); |
6483 | Decl *ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS, |
6484 | MultiTemplateParamsArg TemplateParams, |
6485 | SourceLocation UsingLoc, UnqualifiedId &Name, |
6486 | const ParsedAttributesView &AttrList, |
6487 | TypeResult Type, Decl *DeclFromDeclSpec); |
6488 | |
6489 | /// BuildCXXConstructExpr - Creates a complete call to a constructor, |
6490 | /// including handling of its default argument expressions. |
6491 | /// |
6492 | /// \param ConstructKind - a CXXConstructExpr::ConstructionKind |
6493 | ExprResult BuildCXXConstructExpr( |
6494 | SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, |
6495 | CXXConstructorDecl *Constructor, MultiExprArg Exprs, |
6496 | bool HadMultipleCandidates, bool IsListInitialization, |
6497 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
6498 | CXXConstructionKind ConstructKind, SourceRange ParenRange); |
6499 | |
6500 | /// Build a CXXConstructExpr whose constructor has already been resolved if |
6501 | /// it denotes an inherited constructor. |
6502 | ExprResult BuildCXXConstructExpr( |
6503 | SourceLocation ConstructLoc, QualType DeclInitType, |
6504 | CXXConstructorDecl *Constructor, bool Elidable, MultiExprArg Exprs, |
6505 | bool HadMultipleCandidates, bool IsListInitialization, |
6506 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
6507 | CXXConstructionKind ConstructKind, SourceRange ParenRange); |
6508 | |
6509 | // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if |
6510 | // the constructor can be elidable? |
6511 | ExprResult BuildCXXConstructExpr( |
6512 | SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, |
6513 | CXXConstructorDecl *Constructor, bool Elidable, MultiExprArg Exprs, |
6514 | bool HadMultipleCandidates, bool IsListInitialization, |
6515 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
6516 | CXXConstructionKind ConstructKind, SourceRange ParenRange); |
6517 | |
6518 | ExprResult ConvertMemberDefaultInitExpression(FieldDecl *FD, Expr *InitExpr, |
6519 | SourceLocation InitLoc); |
6520 | |
6521 | ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field); |
6522 | |
6523 | |
6524 | /// Instantiate or parse a C++ default argument expression as necessary. |
6525 | /// Return true on error. |
6526 | bool CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
6527 | ParmVarDecl *Param, Expr *Init = nullptr, |
6528 | bool SkipImmediateInvocations = true); |
6529 | |
6530 | /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating |
6531 | /// the default expr if needed. |
6532 | ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
6533 | ParmVarDecl *Param, Expr *Init = nullptr); |
6534 | |
6535 | /// FinalizeVarWithDestructor - Prepare for calling destructor on the |
6536 | /// constructed variable. |
6537 | void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); |
6538 | |
6539 | /// Helper class that collects exception specifications for |
6540 | /// implicitly-declared special member functions. |
6541 | class ImplicitExceptionSpecification { |
6542 | // Pointer to allow copying |
6543 | Sema *Self; |
6544 | // We order exception specifications thus: |
6545 | // noexcept is the most restrictive, but is only used in C++11. |
6546 | // throw() comes next. |
6547 | // Then a throw(collected exceptions) |
6548 | // Finally no specification, which is expressed as noexcept(false). |
6549 | // throw(...) is used instead if any called function uses it. |
6550 | ExceptionSpecificationType ComputedEST; |
6551 | llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; |
6552 | SmallVector<QualType, 4> Exceptions; |
6553 | |
6554 | void ClearExceptions() { |
6555 | ExceptionsSeen.clear(); |
6556 | Exceptions.clear(); |
6557 | } |
6558 | |
6559 | public: |
6560 | explicit ImplicitExceptionSpecification(Sema &Self) |
6561 | : Self(&Self), ComputedEST(EST_BasicNoexcept) { |
6562 | if (!Self.getLangOpts().CPlusPlus11) |
6563 | ComputedEST = EST_DynamicNone; |
6564 | } |
6565 | |
6566 | /// Get the computed exception specification type. |
6567 | ExceptionSpecificationType getExceptionSpecType() const { |
6568 | assert(!isComputedNoexcept(ComputedEST) && |
6569 | "noexcept(expr) should not be a possible result" ); |
6570 | return ComputedEST; |
6571 | } |
6572 | |
6573 | /// The number of exceptions in the exception specification. |
6574 | unsigned size() const { return Exceptions.size(); } |
6575 | |
6576 | /// The set of exceptions in the exception specification. |
6577 | const QualType *data() const { return Exceptions.data(); } |
6578 | |
6579 | /// Integrate another called method into the collected data. |
6580 | void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method); |
6581 | |
6582 | /// Integrate an invoked expression into the collected data. |
6583 | void CalledExpr(Expr *E) { CalledStmt(E); } |
6584 | |
6585 | /// Integrate an invoked statement into the collected data. |
6586 | void CalledStmt(Stmt *S); |
6587 | |
6588 | /// Overwrite an EPI's exception specification with this |
6589 | /// computed exception specification. |
6590 | FunctionProtoType::ExceptionSpecInfo getExceptionSpec() const { |
6591 | FunctionProtoType::ExceptionSpecInfo ESI; |
6592 | ESI.Type = getExceptionSpecType(); |
6593 | if (ESI.Type == EST_Dynamic) { |
6594 | ESI.Exceptions = Exceptions; |
6595 | } else if (ESI.Type == EST_None) { |
6596 | /// C++11 [except.spec]p14: |
6597 | /// The exception-specification is noexcept(false) if the set of |
6598 | /// potential exceptions of the special member function contains "any" |
6599 | ESI.Type = EST_NoexceptFalse; |
6600 | ESI.NoexceptExpr = Self->ActOnCXXBoolLiteral(OpLoc: SourceLocation(), |
6601 | Kind: tok::kw_false).get(); |
6602 | } |
6603 | return ESI; |
6604 | } |
6605 | }; |
6606 | |
6607 | /// Evaluate the implicit exception specification for a defaulted |
6608 | /// special member function. |
6609 | void EvaluateImplicitExceptionSpec(SourceLocation Loc, FunctionDecl *FD); |
6610 | |
6611 | /// Check the given noexcept-specifier, convert its expression, and compute |
6612 | /// the appropriate ExceptionSpecificationType. |
6613 | ExprResult ActOnNoexceptSpec(Expr *NoexceptExpr, |
6614 | ExceptionSpecificationType &EST); |
6615 | |
6616 | /// Check the given exception-specification and update the |
6617 | /// exception specification information with the results. |
6618 | void checkExceptionSpecification(bool IsTopLevel, |
6619 | ExceptionSpecificationType EST, |
6620 | ArrayRef<ParsedType> DynamicExceptions, |
6621 | ArrayRef<SourceRange> DynamicExceptionRanges, |
6622 | Expr *NoexceptExpr, |
6623 | SmallVectorImpl<QualType> &Exceptions, |
6624 | FunctionProtoType::ExceptionSpecInfo &ESI); |
6625 | |
6626 | /// Determine if we're in a case where we need to (incorrectly) eagerly |
6627 | /// parse an exception specification to work around a libstdc++ bug. |
6628 | bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D); |
6629 | |
6630 | /// Add an exception-specification to the given member function |
6631 | /// (or member function template). The exception-specification was parsed |
6632 | /// after the method itself was declared. |
6633 | void actOnDelayedExceptionSpecification(Decl *Method, |
6634 | ExceptionSpecificationType EST, |
6635 | SourceRange SpecificationRange, |
6636 | ArrayRef<ParsedType> DynamicExceptions, |
6637 | ArrayRef<SourceRange> DynamicExceptionRanges, |
6638 | Expr *NoexceptExpr); |
6639 | |
6640 | class InheritedConstructorInfo; |
6641 | |
6642 | /// Determine if a special member function should have a deleted |
6643 | /// definition when it is defaulted. |
6644 | bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM, |
6645 | InheritedConstructorInfo *ICI = nullptr, |
6646 | bool Diagnose = false); |
6647 | |
6648 | /// Produce notes explaining why a defaulted function was defined as deleted. |
6649 | void DiagnoseDeletedDefaultedFunction(FunctionDecl *FD); |
6650 | |
6651 | /// Declare the implicit default constructor for the given class. |
6652 | /// |
6653 | /// \param ClassDecl The class declaration into which the implicit |
6654 | /// default constructor will be added. |
6655 | /// |
6656 | /// \returns The implicitly-declared default constructor. |
6657 | CXXConstructorDecl *DeclareImplicitDefaultConstructor( |
6658 | CXXRecordDecl *ClassDecl); |
6659 | |
6660 | /// DefineImplicitDefaultConstructor - Checks for feasibility of |
6661 | /// defining this constructor as the default constructor. |
6662 | void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, |
6663 | CXXConstructorDecl *Constructor); |
6664 | |
6665 | /// Declare the implicit destructor for the given class. |
6666 | /// |
6667 | /// \param ClassDecl The class declaration into which the implicit |
6668 | /// destructor will be added. |
6669 | /// |
6670 | /// \returns The implicitly-declared destructor. |
6671 | CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); |
6672 | |
6673 | /// DefineImplicitDestructor - Checks for feasibility of |
6674 | /// defining this destructor as the default destructor. |
6675 | void DefineImplicitDestructor(SourceLocation CurrentLocation, |
6676 | CXXDestructorDecl *Destructor); |
6677 | |
6678 | /// Build an exception spec for destructors that don't have one. |
6679 | /// |
6680 | /// C++11 says that user-defined destructors with no exception spec get one |
6681 | /// that looks as if the destructor was implicitly declared. |
6682 | void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor); |
6683 | |
6684 | /// Define the specified inheriting constructor. |
6685 | void DefineInheritingConstructor(SourceLocation UseLoc, |
6686 | CXXConstructorDecl *Constructor); |
6687 | |
6688 | /// Declare the implicit copy constructor for the given class. |
6689 | /// |
6690 | /// \param ClassDecl The class declaration into which the implicit |
6691 | /// copy constructor will be added. |
6692 | /// |
6693 | /// \returns The implicitly-declared copy constructor. |
6694 | CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); |
6695 | |
6696 | /// DefineImplicitCopyConstructor - Checks for feasibility of |
6697 | /// defining this constructor as the copy constructor. |
6698 | void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, |
6699 | CXXConstructorDecl *Constructor); |
6700 | |
6701 | /// Declare the implicit move constructor for the given class. |
6702 | /// |
6703 | /// \param ClassDecl The Class declaration into which the implicit |
6704 | /// move constructor will be added. |
6705 | /// |
6706 | /// \returns The implicitly-declared move constructor, or NULL if it wasn't |
6707 | /// declared. |
6708 | CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl); |
6709 | |
6710 | /// DefineImplicitMoveConstructor - Checks for feasibility of |
6711 | /// defining this constructor as the move constructor. |
6712 | void DefineImplicitMoveConstructor(SourceLocation CurrentLocation, |
6713 | CXXConstructorDecl *Constructor); |
6714 | |
6715 | /// Declare the implicit copy assignment operator for the given class. |
6716 | /// |
6717 | /// \param ClassDecl The class declaration into which the implicit |
6718 | /// copy assignment operator will be added. |
6719 | /// |
6720 | /// \returns The implicitly-declared copy assignment operator. |
6721 | CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); |
6722 | |
6723 | /// Defines an implicitly-declared copy assignment operator. |
6724 | void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, |
6725 | CXXMethodDecl *MethodDecl); |
6726 | |
6727 | /// Declare the implicit move assignment operator for the given class. |
6728 | /// |
6729 | /// \param ClassDecl The Class declaration into which the implicit |
6730 | /// move assignment operator will be added. |
6731 | /// |
6732 | /// \returns The implicitly-declared move assignment operator, or NULL if it |
6733 | /// wasn't declared. |
6734 | CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl); |
6735 | |
6736 | /// Defines an implicitly-declared move assignment operator. |
6737 | void DefineImplicitMoveAssignment(SourceLocation CurrentLocation, |
6738 | CXXMethodDecl *MethodDecl); |
6739 | |
6740 | /// Force the declaration of any implicitly-declared members of this |
6741 | /// class. |
6742 | void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); |
6743 | |
6744 | /// Check a completed declaration of an implicit special member. |
6745 | void CheckImplicitSpecialMemberDeclaration(Scope *S, FunctionDecl *FD); |
6746 | |
6747 | /// Determine whether the given function is an implicitly-deleted |
6748 | /// special member function. |
6749 | bool isImplicitlyDeleted(FunctionDecl *FD); |
6750 | |
6751 | /// Check whether 'this' shows up in the type of a static member |
6752 | /// function after the (naturally empty) cv-qualifier-seq would be. |
6753 | /// |
6754 | /// \returns true if an error occurred. |
6755 | bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method); |
6756 | |
6757 | /// Whether this' shows up in the exception specification of a static |
6758 | /// member function. |
6759 | bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method); |
6760 | |
6761 | /// Check whether 'this' shows up in the attributes of the given |
6762 | /// static member function. |
6763 | /// |
6764 | /// \returns true if an error occurred. |
6765 | bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method); |
6766 | |
6767 | /// MaybeBindToTemporary - If the passed in expression has a record type with |
6768 | /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise |
6769 | /// it simply returns the passed in expression. |
6770 | ExprResult MaybeBindToTemporary(Expr *E); |
6771 | |
6772 | /// Wrap the expression in a ConstantExpr if it is a potential immediate |
6773 | /// invocation. |
6774 | ExprResult CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl); |
6775 | |
6776 | bool CheckImmediateEscalatingFunctionDefinition( |
6777 | FunctionDecl *FD, const sema::FunctionScopeInfo *FSI); |
6778 | |
6779 | void MarkExpressionAsImmediateEscalating(Expr *E); |
6780 | |
6781 | void DiagnoseImmediateEscalatingReason(FunctionDecl *FD); |
6782 | |
6783 | bool CompleteConstructorCall(CXXConstructorDecl *Constructor, |
6784 | QualType DeclInitType, MultiExprArg ArgsPtr, |
6785 | SourceLocation Loc, |
6786 | SmallVectorImpl<Expr *> &ConvertedArgs, |
6787 | bool AllowExplicit = false, |
6788 | bool IsListInitialization = false); |
6789 | |
6790 | ParsedType getInheritingConstructorName(CXXScopeSpec &SS, |
6791 | SourceLocation NameLoc, |
6792 | IdentifierInfo &Name); |
6793 | |
6794 | ParsedType getConstructorName(IdentifierInfo &II, SourceLocation NameLoc, |
6795 | Scope *S, CXXScopeSpec &SS, |
6796 | bool EnteringContext); |
6797 | ParsedType getDestructorName(IdentifierInfo &II, SourceLocation NameLoc, |
6798 | Scope *S, CXXScopeSpec &SS, |
6799 | ParsedType ObjectType, bool EnteringContext); |
6800 | |
6801 | ParsedType getDestructorTypeForDecltype(const DeclSpec &DS, |
6802 | ParsedType ObjectType); |
6803 | |
6804 | // Checks that reinterpret casts don't have undefined behavior. |
6805 | void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, |
6806 | bool IsDereference, SourceRange Range); |
6807 | |
6808 | // Checks that the vector type should be initialized from a scalar |
6809 | // by splatting the value rather than populating a single element. |
6810 | // This is the case for AltiVecVector types as well as with |
6811 | // AltiVecPixel and AltiVecBool when -faltivec-src-compat=xl is specified. |
6812 | bool ShouldSplatAltivecScalarInCast(const VectorType *VecTy); |
6813 | |
6814 | // Checks if the -faltivec-src-compat=gcc option is specified. |
6815 | // If so, AltiVecVector, AltiVecBool and AltiVecPixel types are |
6816 | // treated the same way as they are when trying to initialize |
6817 | // these vectors on gcc (an error is emitted). |
6818 | bool CheckAltivecInitFromScalar(SourceRange R, QualType VecTy, |
6819 | QualType SrcTy); |
6820 | |
6821 | /// ActOnCXXNamedCast - Parse |
6822 | /// {dynamic,static,reinterpret,const,addrspace}_cast's. |
6823 | ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, |
6824 | tok::TokenKind Kind, |
6825 | SourceLocation LAngleBracketLoc, |
6826 | Declarator &D, |
6827 | SourceLocation RAngleBracketLoc, |
6828 | SourceLocation LParenLoc, |
6829 | Expr *E, |
6830 | SourceLocation RParenLoc); |
6831 | |
6832 | ExprResult BuildCXXNamedCast(SourceLocation OpLoc, |
6833 | tok::TokenKind Kind, |
6834 | TypeSourceInfo *Ty, |
6835 | Expr *E, |
6836 | SourceRange AngleBrackets, |
6837 | SourceRange Parens); |
6838 | |
6839 | ExprResult ActOnBuiltinBitCastExpr(SourceLocation KWLoc, Declarator &Dcl, |
6840 | ExprResult Operand, |
6841 | SourceLocation RParenLoc); |
6842 | |
6843 | ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, |
6844 | Expr *Operand, SourceLocation RParenLoc); |
6845 | |
6846 | ExprResult BuildCXXTypeId(QualType TypeInfoType, |
6847 | SourceLocation TypeidLoc, |
6848 | TypeSourceInfo *Operand, |
6849 | SourceLocation RParenLoc); |
6850 | ExprResult BuildCXXTypeId(QualType TypeInfoType, |
6851 | SourceLocation TypeidLoc, |
6852 | Expr *Operand, |
6853 | SourceLocation RParenLoc); |
6854 | |
6855 | /// ActOnCXXTypeid - Parse typeid( something ). |
6856 | ExprResult ActOnCXXTypeid(SourceLocation OpLoc, |
6857 | SourceLocation LParenLoc, bool isType, |
6858 | void *TyOrExpr, |
6859 | SourceLocation RParenLoc); |
6860 | |
6861 | ExprResult BuildCXXUuidof(QualType TypeInfoType, |
6862 | SourceLocation TypeidLoc, |
6863 | TypeSourceInfo *Operand, |
6864 | SourceLocation RParenLoc); |
6865 | ExprResult BuildCXXUuidof(QualType TypeInfoType, |
6866 | SourceLocation TypeidLoc, |
6867 | Expr *Operand, |
6868 | SourceLocation RParenLoc); |
6869 | |
6870 | /// ActOnCXXUuidof - Parse __uuidof( something ). |
6871 | ExprResult ActOnCXXUuidof(SourceLocation OpLoc, |
6872 | SourceLocation LParenLoc, bool isType, |
6873 | void *TyOrExpr, |
6874 | SourceLocation RParenLoc); |
6875 | |
6876 | /// Handle a C++1z fold-expression: ( expr op ... op expr ). |
6877 | ExprResult ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS, |
6878 | tok::TokenKind Operator, |
6879 | SourceLocation EllipsisLoc, Expr *RHS, |
6880 | SourceLocation RParenLoc); |
6881 | ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, |
6882 | SourceLocation LParenLoc, Expr *LHS, |
6883 | BinaryOperatorKind Operator, |
6884 | SourceLocation EllipsisLoc, Expr *RHS, |
6885 | SourceLocation RParenLoc, |
6886 | std::optional<unsigned> NumExpansions); |
6887 | ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
6888 | BinaryOperatorKind Operator); |
6889 | |
6890 | //// ActOnCXXThis - Parse 'this' pointer. |
6891 | ExprResult ActOnCXXThis(SourceLocation loc); |
6892 | |
6893 | /// Build a CXXThisExpr and mark it referenced in the current context. |
6894 | Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit); |
6895 | void MarkThisReferenced(CXXThisExpr *This); |
6896 | |
6897 | /// Try to retrieve the type of the 'this' pointer. |
6898 | /// |
6899 | /// \returns The type of 'this', if possible. Otherwise, returns a NULL type. |
6900 | QualType getCurrentThisType(); |
6901 | |
6902 | /// When non-NULL, the C++ 'this' expression is allowed despite the |
6903 | /// current context not being a non-static member function. In such cases, |
6904 | /// this provides the type used for 'this'. |
6905 | QualType CXXThisTypeOverride; |
6906 | |
6907 | /// RAII object used to temporarily allow the C++ 'this' expression |
6908 | /// to be used, with the given qualifiers on the current class type. |
6909 | class CXXThisScopeRAII { |
6910 | Sema &S; |
6911 | QualType OldCXXThisTypeOverride; |
6912 | bool Enabled; |
6913 | |
6914 | public: |
6915 | /// Introduce a new scope where 'this' may be allowed (when enabled), |
6916 | /// using the given declaration (which is either a class template or a |
6917 | /// class) along with the given qualifiers. |
6918 | /// along with the qualifiers placed on '*this'. |
6919 | CXXThisScopeRAII(Sema &S, Decl *ContextDecl, Qualifiers CXXThisTypeQuals, |
6920 | bool Enabled = true); |
6921 | |
6922 | ~CXXThisScopeRAII(); |
6923 | }; |
6924 | |
6925 | /// Make sure the value of 'this' is actually available in the current |
6926 | /// context, if it is a potentially evaluated context. |
6927 | /// |
6928 | /// \param Loc The location at which the capture of 'this' occurs. |
6929 | /// |
6930 | /// \param Explicit Whether 'this' is explicitly captured in a lambda |
6931 | /// capture list. |
6932 | /// |
6933 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
6934 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
6935 | /// This is useful when enclosing lambdas must speculatively capture |
6936 | /// 'this' that may or may not be used in certain specializations of |
6937 | /// a nested generic lambda (depending on whether the name resolves to |
6938 | /// a non-static member function or a static function). |
6939 | /// \return returns 'true' if failed, 'false' if success. |
6940 | bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false, |
6941 | bool BuildAndDiagnose = true, |
6942 | const unsigned *const FunctionScopeIndexToStopAt = nullptr, |
6943 | bool ByCopy = false); |
6944 | |
6945 | /// Determine whether the given type is the type of *this that is used |
6946 | /// outside of the body of a member function for a type that is currently |
6947 | /// being defined. |
6948 | bool isThisOutsideMemberFunctionBody(QualType BaseType); |
6949 | |
6950 | /// ActOnCXXBoolLiteral - Parse {true,false} literals. |
6951 | ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
6952 | |
6953 | |
6954 | /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals. |
6955 | ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
6956 | |
6957 | ExprResult |
6958 | ActOnObjCAvailabilityCheckExpr(llvm::ArrayRef<AvailabilitySpec> AvailSpecs, |
6959 | SourceLocation AtLoc, SourceLocation RParen); |
6960 | |
6961 | /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. |
6962 | ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); |
6963 | |
6964 | //// ActOnCXXThrow - Parse throw expressions. |
6965 | ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); |
6966 | ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, |
6967 | bool IsThrownVarInScope); |
6968 | bool CheckCXXThrowOperand(SourceLocation ThrowLoc, QualType ThrowTy, Expr *E); |
6969 | |
6970 | /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. |
6971 | /// Can be interpreted either as function-style casting ("int(x)") |
6972 | /// or class type construction ("ClassType(x,y,z)") |
6973 | /// or creation of a value-initialized type ("int()"). |
6974 | ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, |
6975 | SourceLocation LParenOrBraceLoc, |
6976 | MultiExprArg Exprs, |
6977 | SourceLocation RParenOrBraceLoc, |
6978 | bool ListInitialization); |
6979 | |
6980 | ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, |
6981 | SourceLocation LParenLoc, |
6982 | MultiExprArg Exprs, |
6983 | SourceLocation RParenLoc, |
6984 | bool ListInitialization); |
6985 | |
6986 | /// ActOnCXXNew - Parsed a C++ 'new' expression. |
6987 | ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, |
6988 | SourceLocation PlacementLParen, |
6989 | MultiExprArg PlacementArgs, |
6990 | SourceLocation PlacementRParen, |
6991 | SourceRange TypeIdParens, Declarator &D, |
6992 | Expr *Initializer); |
6993 | ExprResult |
6994 | BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, |
6995 | MultiExprArg PlacementArgs, SourceLocation PlacementRParen, |
6996 | SourceRange TypeIdParens, QualType AllocType, |
6997 | TypeSourceInfo *AllocTypeInfo, std::optional<Expr *> ArraySize, |
6998 | SourceRange DirectInitRange, Expr *Initializer); |
6999 | |
7000 | /// Determine whether \p FD is an aligned allocation or deallocation |
7001 | /// function that is unavailable. |
7002 | bool isUnavailableAlignedAllocationFunction(const FunctionDecl &FD) const; |
7003 | |
7004 | /// Produce diagnostics if \p FD is an aligned allocation or deallocation |
7005 | /// function that is unavailable. |
7006 | void diagnoseUnavailableAlignedAllocation(const FunctionDecl &FD, |
7007 | SourceLocation Loc); |
7008 | |
7009 | bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, |
7010 | SourceRange R); |
7011 | |
7012 | /// The scope in which to find allocation functions. |
7013 | enum AllocationFunctionScope { |
7014 | /// Only look for allocation functions in the global scope. |
7015 | AFS_Global, |
7016 | /// Only look for allocation functions in the scope of the |
7017 | /// allocated class. |
7018 | AFS_Class, |
7019 | /// Look for allocation functions in both the global scope |
7020 | /// and in the scope of the allocated class. |
7021 | AFS_Both |
7022 | }; |
7023 | |
7024 | /// Finds the overloads of operator new and delete that are appropriate |
7025 | /// for the allocation. |
7026 | bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, |
7027 | AllocationFunctionScope NewScope, |
7028 | AllocationFunctionScope DeleteScope, |
7029 | QualType AllocType, bool IsArray, |
7030 | bool &PassAlignment, MultiExprArg PlaceArgs, |
7031 | FunctionDecl *&OperatorNew, |
7032 | FunctionDecl *&OperatorDelete, |
7033 | bool Diagnose = true); |
7034 | void DeclareGlobalNewDelete(); |
7035 | void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, |
7036 | ArrayRef<QualType> Params); |
7037 | |
7038 | bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, |
7039 | DeclarationName Name, FunctionDecl *&Operator, |
7040 | bool Diagnose = true, bool WantSize = false, |
7041 | bool WantAligned = false); |
7042 | FunctionDecl *FindUsualDeallocationFunction(SourceLocation StartLoc, |
7043 | bool CanProvideSize, |
7044 | bool Overaligned, |
7045 | DeclarationName Name); |
7046 | FunctionDecl *FindDeallocationFunctionForDestructor(SourceLocation StartLoc, |
7047 | CXXRecordDecl *RD); |
7048 | |
7049 | /// ActOnCXXDelete - Parsed a C++ 'delete' expression |
7050 | ExprResult ActOnCXXDelete(SourceLocation StartLoc, |
7051 | bool UseGlobal, bool ArrayForm, |
7052 | Expr *Operand); |
7053 | void CheckVirtualDtorCall(CXXDestructorDecl *dtor, SourceLocation Loc, |
7054 | bool IsDelete, bool CallCanBeVirtual, |
7055 | bool WarnOnNonAbstractTypes, |
7056 | SourceLocation DtorLoc); |
7057 | |
7058 | ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, |
7059 | Expr *Operand, SourceLocation RParen); |
7060 | ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, |
7061 | SourceLocation RParen); |
7062 | |
7063 | /// Parsed one of the type trait support pseudo-functions. |
7064 | ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
7065 | ArrayRef<ParsedType> Args, |
7066 | SourceLocation RParenLoc); |
7067 | ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
7068 | ArrayRef<TypeSourceInfo *> Args, |
7069 | SourceLocation RParenLoc); |
7070 | |
7071 | /// ActOnArrayTypeTrait - Parsed one of the binary type trait support |
7072 | /// pseudo-functions. |
7073 | ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, |
7074 | SourceLocation KWLoc, |
7075 | ParsedType LhsTy, |
7076 | Expr *DimExpr, |
7077 | SourceLocation RParen); |
7078 | |
7079 | ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, |
7080 | SourceLocation KWLoc, |
7081 | TypeSourceInfo *TSInfo, |
7082 | Expr *DimExpr, |
7083 | SourceLocation RParen); |
7084 | |
7085 | /// ActOnExpressionTrait - Parsed one of the unary type trait support |
7086 | /// pseudo-functions. |
7087 | ExprResult ActOnExpressionTrait(ExpressionTrait OET, |
7088 | SourceLocation KWLoc, |
7089 | Expr *Queried, |
7090 | SourceLocation RParen); |
7091 | |
7092 | ExprResult BuildExpressionTrait(ExpressionTrait OET, |
7093 | SourceLocation KWLoc, |
7094 | Expr *Queried, |
7095 | SourceLocation RParen); |
7096 | |
7097 | ExprResult ActOnStartCXXMemberReference(Scope *S, |
7098 | Expr *Base, |
7099 | SourceLocation OpLoc, |
7100 | tok::TokenKind OpKind, |
7101 | ParsedType &ObjectType, |
7102 | bool &MayBePseudoDestructor); |
7103 | |
7104 | ExprResult BuildPseudoDestructorExpr(Expr *Base, |
7105 | SourceLocation OpLoc, |
7106 | tok::TokenKind OpKind, |
7107 | const CXXScopeSpec &SS, |
7108 | TypeSourceInfo *ScopeType, |
7109 | SourceLocation CCLoc, |
7110 | SourceLocation TildeLoc, |
7111 | PseudoDestructorTypeStorage DestroyedType); |
7112 | |
7113 | ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, |
7114 | SourceLocation OpLoc, |
7115 | tok::TokenKind OpKind, |
7116 | CXXScopeSpec &SS, |
7117 | UnqualifiedId &FirstTypeName, |
7118 | SourceLocation CCLoc, |
7119 | SourceLocation TildeLoc, |
7120 | UnqualifiedId &SecondTypeName); |
7121 | |
7122 | ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, |
7123 | SourceLocation OpLoc, |
7124 | tok::TokenKind OpKind, |
7125 | SourceLocation TildeLoc, |
7126 | const DeclSpec& DS); |
7127 | |
7128 | /// MaybeCreateExprWithCleanups - If the current full-expression |
7129 | /// requires any cleanups, surround it with a ExprWithCleanups node. |
7130 | /// Otherwise, just returns the passed-in expression. |
7131 | Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); |
7132 | Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); |
7133 | ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); |
7134 | |
7135 | MaterializeTemporaryExpr * |
7136 | CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, |
7137 | bool BoundToLvalueReference); |
7138 | |
7139 | ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue) { |
7140 | return ActOnFinishFullExpr( |
7141 | Expr, CC: Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue); |
7142 | } |
7143 | ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC, |
7144 | bool DiscardedValue, bool IsConstexpr = false, |
7145 | bool IsTemplateArgument = false); |
7146 | StmtResult ActOnFinishFullStmt(Stmt *Stmt); |
7147 | |
7148 | // Marks SS invalid if it represents an incomplete type. |
7149 | bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); |
7150 | // Complete an enum decl, maybe without a scope spec. |
7151 | bool RequireCompleteEnumDecl(EnumDecl *D, SourceLocation L, |
7152 | CXXScopeSpec *SS = nullptr); |
7153 | |
7154 | DeclContext *computeDeclContext(QualType T); |
7155 | DeclContext *computeDeclContext(const CXXScopeSpec &SS, |
7156 | bool EnteringContext = false); |
7157 | bool isDependentScopeSpecifier(const CXXScopeSpec &SS); |
7158 | CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); |
7159 | |
7160 | /// The parser has parsed a global nested-name-specifier '::'. |
7161 | /// |
7162 | /// \param CCLoc The location of the '::'. |
7163 | /// |
7164 | /// \param SS The nested-name-specifier, which will be updated in-place |
7165 | /// to reflect the parsed nested-name-specifier. |
7166 | /// |
7167 | /// \returns true if an error occurred, false otherwise. |
7168 | bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS); |
7169 | |
7170 | /// The parser has parsed a '__super' nested-name-specifier. |
7171 | /// |
7172 | /// \param SuperLoc The location of the '__super' keyword. |
7173 | /// |
7174 | /// \param ColonColonLoc The location of the '::'. |
7175 | /// |
7176 | /// \param SS The nested-name-specifier, which will be updated in-place |
7177 | /// to reflect the parsed nested-name-specifier. |
7178 | /// |
7179 | /// \returns true if an error occurred, false otherwise. |
7180 | bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc, |
7181 | SourceLocation ColonColonLoc, CXXScopeSpec &SS); |
7182 | |
7183 | bool isAcceptableNestedNameSpecifier(const NamedDecl *SD, |
7184 | bool *CanCorrect = nullptr); |
7185 | NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); |
7186 | |
7187 | /// Keeps information about an identifier in a nested-name-spec. |
7188 | /// |
7189 | struct NestedNameSpecInfo { |
7190 | /// The type of the object, if we're parsing nested-name-specifier in |
7191 | /// a member access expression. |
7192 | ParsedType ObjectType; |
7193 | |
7194 | /// The identifier preceding the '::'. |
7195 | IdentifierInfo *Identifier; |
7196 | |
7197 | /// The location of the identifier. |
7198 | SourceLocation IdentifierLoc; |
7199 | |
7200 | /// The location of the '::'. |
7201 | SourceLocation CCLoc; |
7202 | |
7203 | /// Creates info object for the most typical case. |
7204 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
7205 | SourceLocation ColonColonLoc, ParsedType ObjectType = ParsedType()) |
7206 | : ObjectType(ObjectType), Identifier(II), IdentifierLoc(IdLoc), |
7207 | CCLoc(ColonColonLoc) { |
7208 | } |
7209 | |
7210 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
7211 | SourceLocation ColonColonLoc, QualType ObjectType) |
7212 | : ObjectType(ParsedType::make(P: ObjectType)), Identifier(II), |
7213 | IdentifierLoc(IdLoc), CCLoc(ColonColonLoc) { |
7214 | } |
7215 | }; |
7216 | |
7217 | bool BuildCXXNestedNameSpecifier(Scope *S, |
7218 | NestedNameSpecInfo &IdInfo, |
7219 | bool EnteringContext, |
7220 | CXXScopeSpec &SS, |
7221 | NamedDecl *ScopeLookupResult, |
7222 | bool ErrorRecoveryLookup, |
7223 | bool *IsCorrectedToColon = nullptr, |
7224 | bool OnlyNamespace = false); |
7225 | |
7226 | /// The parser has parsed a nested-name-specifier 'identifier::'. |
7227 | /// |
7228 | /// \param S The scope in which this nested-name-specifier occurs. |
7229 | /// |
7230 | /// \param IdInfo Parser information about an identifier in the |
7231 | /// nested-name-spec. |
7232 | /// |
7233 | /// \param EnteringContext Whether we're entering the context nominated by |
7234 | /// this nested-name-specifier. |
7235 | /// |
7236 | /// \param SS The nested-name-specifier, which is both an input |
7237 | /// parameter (the nested-name-specifier before this type) and an |
7238 | /// output parameter (containing the full nested-name-specifier, |
7239 | /// including this new type). |
7240 | /// |
7241 | /// \param IsCorrectedToColon If not null, suggestions to replace '::' -> ':' |
7242 | /// are allowed. The bool value pointed by this parameter is set to 'true' |
7243 | /// if the identifier is treated as if it was followed by ':', not '::'. |
7244 | /// |
7245 | /// \param OnlyNamespace If true, only considers namespaces in lookup. |
7246 | /// |
7247 | /// \returns true if an error occurred, false otherwise. |
7248 | bool ActOnCXXNestedNameSpecifier(Scope *S, |
7249 | NestedNameSpecInfo &IdInfo, |
7250 | bool EnteringContext, |
7251 | CXXScopeSpec &SS, |
7252 | bool *IsCorrectedToColon = nullptr, |
7253 | bool OnlyNamespace = false); |
7254 | |
7255 | ExprResult ActOnDecltypeExpression(Expr *E); |
7256 | |
7257 | bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, |
7258 | const DeclSpec &DS, |
7259 | SourceLocation ColonColonLoc); |
7260 | |
7261 | bool ActOnCXXNestedNameSpecifierIndexedPack(CXXScopeSpec &SS, |
7262 | const DeclSpec &DS, |
7263 | SourceLocation ColonColonLoc, |
7264 | QualType Type); |
7265 | |
7266 | bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, |
7267 | NestedNameSpecInfo &IdInfo, |
7268 | bool EnteringContext); |
7269 | |
7270 | bool IsInvalidSMECallConversion(QualType FromType, QualType ToType); |
7271 | |
7272 | /// The parser has parsed a nested-name-specifier |
7273 | /// 'template[opt] template-name < template-args >::'. |
7274 | /// |
7275 | /// \param S The scope in which this nested-name-specifier occurs. |
7276 | /// |
7277 | /// \param SS The nested-name-specifier, which is both an input |
7278 | /// parameter (the nested-name-specifier before this type) and an |
7279 | /// output parameter (containing the full nested-name-specifier, |
7280 | /// including this new type). |
7281 | /// |
7282 | /// \param TemplateKWLoc the location of the 'template' keyword, if any. |
7283 | /// \param TemplateName the template name. |
7284 | /// \param TemplateNameLoc The location of the template name. |
7285 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
7286 | /// \param TemplateArgs The template arguments. |
7287 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
7288 | /// \param CCLoc The location of the '::'. |
7289 | /// |
7290 | /// \param EnteringContext Whether we're entering the context of the |
7291 | /// nested-name-specifier. |
7292 | /// |
7293 | /// |
7294 | /// \returns true if an error occurred, false otherwise. |
7295 | bool ActOnCXXNestedNameSpecifier(Scope *S, |
7296 | CXXScopeSpec &SS, |
7297 | SourceLocation TemplateKWLoc, |
7298 | TemplateTy TemplateName, |
7299 | SourceLocation TemplateNameLoc, |
7300 | SourceLocation LAngleLoc, |
7301 | ASTTemplateArgsPtr TemplateArgs, |
7302 | SourceLocation RAngleLoc, |
7303 | SourceLocation CCLoc, |
7304 | bool EnteringContext); |
7305 | |
7306 | /// Given a C++ nested-name-specifier, produce an annotation value |
7307 | /// that the parser can use later to reconstruct the given |
7308 | /// nested-name-specifier. |
7309 | /// |
7310 | /// \param SS A nested-name-specifier. |
7311 | /// |
7312 | /// \returns A pointer containing all of the information in the |
7313 | /// nested-name-specifier \p SS. |
7314 | void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); |
7315 | |
7316 | /// Given an annotation pointer for a nested-name-specifier, restore |
7317 | /// the nested-name-specifier structure. |
7318 | /// |
7319 | /// \param Annotation The annotation pointer, produced by |
7320 | /// \c SaveNestedNameSpecifierAnnotation(). |
7321 | /// |
7322 | /// \param AnnotationRange The source range corresponding to the annotation. |
7323 | /// |
7324 | /// \param SS The nested-name-specifier that will be updated with the contents |
7325 | /// of the annotation pointer. |
7326 | void RestoreNestedNameSpecifierAnnotation(void *Annotation, |
7327 | SourceRange AnnotationRange, |
7328 | CXXScopeSpec &SS); |
7329 | |
7330 | bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
7331 | |
7332 | /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global |
7333 | /// scope or nested-name-specifier) is parsed, part of a declarator-id. |
7334 | /// After this method is called, according to [C++ 3.4.3p3], names should be |
7335 | /// looked up in the declarator-id's scope, until the declarator is parsed and |
7336 | /// ActOnCXXExitDeclaratorScope is called. |
7337 | /// The 'SS' should be a non-empty valid CXXScopeSpec. |
7338 | bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); |
7339 | |
7340 | /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously |
7341 | /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same |
7342 | /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. |
7343 | /// Used to indicate that names should revert to being looked up in the |
7344 | /// defining scope. |
7345 | void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
7346 | |
7347 | /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an |
7348 | /// initializer for the declaration 'Dcl'. |
7349 | /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a |
7350 | /// static data member of class X, names should be looked up in the scope of |
7351 | /// class X. |
7352 | void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); |
7353 | |
7354 | /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an |
7355 | /// initializer for the declaration 'Dcl'. |
7356 | void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); |
7357 | |
7358 | /// Create a new lambda closure type. |
7359 | CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange, |
7360 | TypeSourceInfo *Info, |
7361 | unsigned LambdaDependencyKind, |
7362 | LambdaCaptureDefault CaptureDefault); |
7363 | |
7364 | /// Number lambda for linkage purposes if necessary. |
7365 | void handleLambdaNumbering(CXXRecordDecl *Class, CXXMethodDecl *Method, |
7366 | std::optional<CXXRecordDecl::LambdaNumbering> |
7367 | NumberingOverride = std::nullopt); |
7368 | |
7369 | /// Endow the lambda scope info with the relevant properties. |
7370 | void buildLambdaScope(sema::LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator, |
7371 | SourceRange IntroducerRange, |
7372 | LambdaCaptureDefault CaptureDefault, |
7373 | SourceLocation CaptureDefaultLoc, bool ExplicitParams, |
7374 | bool Mutable); |
7375 | |
7376 | CXXMethodDecl *CreateLambdaCallOperator(SourceRange IntroducerRange, |
7377 | CXXRecordDecl *Class); |
7378 | |
7379 | void AddTemplateParametersToLambdaCallOperator( |
7380 | CXXMethodDecl *CallOperator, CXXRecordDecl *Class, |
7381 | TemplateParameterList *TemplateParams); |
7382 | |
7383 | void CompleteLambdaCallOperator( |
7384 | CXXMethodDecl *Method, SourceLocation LambdaLoc, |
7385 | SourceLocation CallOperatorLoc, Expr *TrailingRequiresClause, |
7386 | TypeSourceInfo *MethodTyInfo, ConstexprSpecKind ConstexprKind, |
7387 | StorageClass SC, ArrayRef<ParmVarDecl *> Params, |
7388 | bool HasExplicitResultType); |
7389 | |
7390 | void DiagnoseInvalidExplicitObjectParameterInLambda(CXXMethodDecl *Method); |
7391 | |
7392 | /// Perform initialization analysis of the init-capture and perform |
7393 | /// any implicit conversions such as an lvalue-to-rvalue conversion if |
7394 | /// not being used to initialize a reference. |
7395 | ParsedType actOnLambdaInitCaptureInitialization( |
7396 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
7397 | IdentifierInfo *Id, LambdaCaptureInitKind InitKind, Expr *&Init) { |
7398 | return ParsedType::make(P: buildLambdaInitCaptureInitialization( |
7399 | Loc, ByRef, EllipsisLoc, NumExpansions: std::nullopt, Id, |
7400 | DirectInit: InitKind != LambdaCaptureInitKind::CopyInit, Init)); |
7401 | } |
7402 | QualType buildLambdaInitCaptureInitialization( |
7403 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
7404 | std::optional<unsigned> NumExpansions, IdentifierInfo *Id, |
7405 | bool DirectInit, Expr *&Init); |
7406 | |
7407 | /// Create a dummy variable within the declcontext of the lambda's |
7408 | /// call operator, for name lookup purposes for a lambda init capture. |
7409 | /// |
7410 | /// CodeGen handles emission of lambda captures, ignoring these dummy |
7411 | /// variables appropriately. |
7412 | VarDecl *createLambdaInitCaptureVarDecl( |
7413 | SourceLocation Loc, QualType InitCaptureType, SourceLocation EllipsisLoc, |
7414 | IdentifierInfo *Id, unsigned InitStyle, Expr *Init, DeclContext *DeclCtx); |
7415 | |
7416 | /// Add an init-capture to a lambda scope. |
7417 | void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var, bool ByRef); |
7418 | |
7419 | /// Note that we have finished the explicit captures for the |
7420 | /// given lambda. |
7421 | void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI); |
7422 | |
7423 | /// Deduce a block or lambda's return type based on the return |
7424 | /// statements present in the body. |
7425 | void deduceClosureReturnType(sema::CapturingScopeInfo &CSI); |
7426 | |
7427 | /// Once the Lambdas capture are known, we can start to create the closure, |
7428 | /// call operator method, and keep track of the captures. |
7429 | /// We do the capture lookup here, but they are not actually captured until |
7430 | /// after we know what the qualifiers of the call operator are. |
7431 | void ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro, |
7432 | Scope *CurContext); |
7433 | |
7434 | /// This is called after parsing the explicit template parameter list |
7435 | /// on a lambda (if it exists) in C++2a. |
7436 | void ActOnLambdaExplicitTemplateParameterList(LambdaIntroducer &Intro, |
7437 | SourceLocation LAngleLoc, |
7438 | ArrayRef<NamedDecl *> TParams, |
7439 | SourceLocation RAngleLoc, |
7440 | ExprResult RequiresClause); |
7441 | |
7442 | void ActOnLambdaClosureQualifiers(LambdaIntroducer &Intro, |
7443 | SourceLocation MutableLoc); |
7444 | |
7445 | void ActOnLambdaClosureParameters( |
7446 | Scope *LambdaScope, |
7447 | MutableArrayRef<DeclaratorChunk::ParamInfo> ParamInfo); |
7448 | |
7449 | /// ActOnStartOfLambdaDefinition - This is called just before we start |
7450 | /// parsing the body of a lambda; it analyzes the explicit captures and |
7451 | /// arguments, and sets up various data-structures for the body of the |
7452 | /// lambda. |
7453 | void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, |
7454 | Declarator &ParamInfo, const DeclSpec &DS); |
7455 | |
7456 | /// ActOnLambdaError - If there is an error parsing a lambda, this callback |
7457 | /// is invoked to pop the information about the lambda. |
7458 | void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, |
7459 | bool IsInstantiation = false); |
7460 | |
7461 | /// ActOnLambdaExpr - This is called when the body of a lambda expression |
7462 | /// was successfully completed. |
7463 | ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body); |
7464 | |
7465 | /// Does copying/destroying the captured variable have side effects? |
7466 | bool CaptureHasSideEffects(const sema::Capture &From); |
7467 | |
7468 | /// Diagnose if an explicit lambda capture is unused. Returns true if a |
7469 | /// diagnostic is emitted. |
7470 | bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange, |
7471 | const sema::Capture &From); |
7472 | |
7473 | /// Build a FieldDecl suitable to hold the given capture. |
7474 | FieldDecl *BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture); |
7475 | |
7476 | /// Initialize the given capture with a suitable expression. |
7477 | ExprResult BuildCaptureInit(const sema::Capture &Capture, |
7478 | SourceLocation ImplicitCaptureLoc, |
7479 | bool IsOpenMPMapping = false); |
7480 | |
7481 | /// Complete a lambda-expression having processed and attached the |
7482 | /// lambda body. |
7483 | ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, |
7484 | sema::LambdaScopeInfo *LSI); |
7485 | |
7486 | /// Get the return type to use for a lambda's conversion function(s) to |
7487 | /// function pointer type, given the type of the call operator. |
7488 | QualType |
7489 | getLambdaConversionFunctionResultType(const FunctionProtoType *CallOpType, |
7490 | CallingConv CC); |
7491 | |
7492 | /// Define the "body" of the conversion from a lambda object to a |
7493 | /// function pointer. |
7494 | /// |
7495 | /// This routine doesn't actually define a sensible body; rather, it fills |
7496 | /// in the initialization expression needed to copy the lambda object into |
7497 | /// the block, and IR generation actually generates the real body of the |
7498 | /// block pointer conversion. |
7499 | void DefineImplicitLambdaToFunctionPointerConversion( |
7500 | SourceLocation CurrentLoc, CXXConversionDecl *Conv); |
7501 | |
7502 | /// Define the "body" of the conversion from a lambda object to a |
7503 | /// block pointer. |
7504 | /// |
7505 | /// This routine doesn't actually define a sensible body; rather, it fills |
7506 | /// in the initialization expression needed to copy the lambda object into |
7507 | /// the block, and IR generation actually generates the real body of the |
7508 | /// block pointer conversion. |
7509 | void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc, |
7510 | CXXConversionDecl *Conv); |
7511 | |
7512 | ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, |
7513 | SourceLocation ConvLocation, |
7514 | CXXConversionDecl *Conv, |
7515 | Expr *Src); |
7516 | |
7517 | sema::LambdaScopeInfo *RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator); |
7518 | |
7519 | class LambdaScopeForCallOperatorInstantiationRAII |
7520 | : private FunctionScopeRAII { |
7521 | public: |
7522 | LambdaScopeForCallOperatorInstantiationRAII( |
7523 | Sema &SemasRef, FunctionDecl *FD, MultiLevelTemplateArgumentList MLTAL, |
7524 | LocalInstantiationScope &Scope, |
7525 | bool ShouldAddDeclsFromParentScope = true); |
7526 | }; |
7527 | |
7528 | /// Check whether the given expression is a valid constraint expression. |
7529 | /// A diagnostic is emitted if it is not, false is returned, and |
7530 | /// PossibleNonPrimary will be set to true if the failure might be due to a |
7531 | /// non-primary expression being used as an atomic constraint. |
7532 | bool CheckConstraintExpression(const Expr *CE, Token NextToken = Token(), |
7533 | bool *PossibleNonPrimary = nullptr, |
7534 | bool IsTrailingRequiresClause = false); |
7535 | |
7536 | private: |
7537 | /// Caches pairs of template-like decls whose associated constraints were |
7538 | /// checked for subsumption and whether or not the first's constraints did in |
7539 | /// fact subsume the second's. |
7540 | llvm::DenseMap<std::pair<NamedDecl *, NamedDecl *>, bool> SubsumptionCache; |
7541 | /// Caches the normalized associated constraints of declarations (concepts or |
7542 | /// constrained declarations). If an error occurred while normalizing the |
7543 | /// associated constraints of the template or concept, nullptr will be cached |
7544 | /// here. |
7545 | llvm::DenseMap<NamedDecl *, NormalizedConstraint *> |
7546 | NormalizationCache; |
7547 | |
7548 | llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &> |
7549 | SatisfactionCache; |
7550 | |
7551 | /// Introduce the instantiated local variables into the local |
7552 | /// instantiation scope. |
7553 | void addInstantiatedLocalVarsToScope(FunctionDecl *Function, |
7554 | const FunctionDecl *PatternDecl, |
7555 | LocalInstantiationScope &Scope); |
7556 | /// Introduce the instantiated function parameters into the local |
7557 | /// instantiation scope, and set the parameter names to those used |
7558 | /// in the template. |
7559 | bool addInstantiatedParametersToScope( |
7560 | FunctionDecl *Function, const FunctionDecl *PatternDecl, |
7561 | LocalInstantiationScope &Scope, |
7562 | const MultiLevelTemplateArgumentList &TemplateArgs); |
7563 | |
7564 | /// Introduce the instantiated captures of the lambda into the local |
7565 | /// instantiation scope. |
7566 | bool addInstantiatedCapturesToScope( |
7567 | FunctionDecl *Function, const FunctionDecl *PatternDecl, |
7568 | LocalInstantiationScope &Scope, |
7569 | const MultiLevelTemplateArgumentList &TemplateArgs); |
7570 | |
7571 | /// used by SetupConstraintCheckingTemplateArgumentsAndScope to recursively(in |
7572 | /// the case of lambdas) set up the LocalInstantiationScope of the current |
7573 | /// function. |
7574 | bool SetupConstraintScope( |
7575 | FunctionDecl *FD, std::optional<ArrayRef<TemplateArgument>> TemplateArgs, |
7576 | MultiLevelTemplateArgumentList MLTAL, LocalInstantiationScope &Scope); |
7577 | |
7578 | /// Used during constraint checking, sets up the constraint template argument |
7579 | /// lists, and calls SetupConstraintScope to set up the |
7580 | /// LocalInstantiationScope to have the proper set of ParVarDecls configured. |
7581 | std::optional<MultiLevelTemplateArgumentList> |
7582 | SetupConstraintCheckingTemplateArgumentsAndScope( |
7583 | FunctionDecl *FD, std::optional<ArrayRef<TemplateArgument>> TemplateArgs, |
7584 | LocalInstantiationScope &Scope); |
7585 | |
7586 | private: |
7587 | // The current stack of constraint satisfactions, so we can exit-early. |
7588 | using SatisfactionStackEntryTy = |
7589 | std::pair<const NamedDecl *, llvm::FoldingSetNodeID>; |
7590 | llvm::SmallVector<SatisfactionStackEntryTy, 10> |
7591 | SatisfactionStack; |
7592 | |
7593 | public: |
7594 | void PushSatisfactionStackEntry(const NamedDecl *D, |
7595 | const llvm::FoldingSetNodeID &ID) { |
7596 | const NamedDecl *Can = cast<NamedDecl>(D->getCanonicalDecl()); |
7597 | SatisfactionStack.emplace_back(Args&: Can, Args: ID); |
7598 | } |
7599 | |
7600 | void PopSatisfactionStackEntry() { SatisfactionStack.pop_back(); } |
7601 | |
7602 | bool SatisfactionStackContains(const NamedDecl *D, |
7603 | const llvm::FoldingSetNodeID &ID) const { |
7604 | const NamedDecl *Can = cast<NamedDecl>(D->getCanonicalDecl()); |
7605 | return llvm::find(Range: SatisfactionStack, |
7606 | Val: SatisfactionStackEntryTy{Can, ID}) != |
7607 | SatisfactionStack.end(); |
7608 | } |
7609 | |
7610 | // Resets the current SatisfactionStack for cases where we are instantiating |
7611 | // constraints as a 'side effect' of normal instantiation in a way that is not |
7612 | // indicative of recursive definition. |
7613 | class SatisfactionStackResetRAII { |
7614 | llvm::SmallVector<SatisfactionStackEntryTy, 10> |
7615 | BackupSatisfactionStack; |
7616 | Sema &SemaRef; |
7617 | |
7618 | public: |
7619 | SatisfactionStackResetRAII(Sema &S) : SemaRef(S) { |
7620 | SemaRef.SwapSatisfactionStack(NewSS&: BackupSatisfactionStack); |
7621 | } |
7622 | |
7623 | ~SatisfactionStackResetRAII() { |
7624 | SemaRef.SwapSatisfactionStack(NewSS&: BackupSatisfactionStack); |
7625 | } |
7626 | }; |
7627 | |
7628 | void SwapSatisfactionStack( |
7629 | llvm::SmallVectorImpl<SatisfactionStackEntryTy> &NewSS) { |
7630 | SatisfactionStack.swap(RHS&: NewSS); |
7631 | } |
7632 | |
7633 | const NormalizedConstraint * |
7634 | getNormalizedAssociatedConstraints( |
7635 | NamedDecl *ConstrainedDecl, ArrayRef<const Expr *> AssociatedConstraints); |
7636 | |
7637 | /// \brief Check whether the given declaration's associated constraints are |
7638 | /// at least as constrained than another declaration's according to the |
7639 | /// partial ordering of constraints. |
7640 | /// |
7641 | /// \param Result If no error occurred, receives the result of true if D1 is |
7642 | /// at least constrained than D2, and false otherwise. |
7643 | /// |
7644 | /// \returns true if an error occurred, false otherwise. |
7645 | bool IsAtLeastAsConstrained(NamedDecl *D1, MutableArrayRef<const Expr *> AC1, |
7646 | NamedDecl *D2, MutableArrayRef<const Expr *> AC2, |
7647 | bool &Result); |
7648 | |
7649 | /// If D1 was not at least as constrained as D2, but would've been if a pair |
7650 | /// of atomic constraints involved had been declared in a concept and not |
7651 | /// repeated in two separate places in code. |
7652 | /// \returns true if such a diagnostic was emitted, false otherwise. |
7653 | bool MaybeEmitAmbiguousAtomicConstraintsDiagnostic(NamedDecl *D1, |
7654 | ArrayRef<const Expr *> AC1, NamedDecl *D2, ArrayRef<const Expr *> AC2); |
7655 | |
7656 | /// \brief Check whether the given list of constraint expressions are |
7657 | /// satisfied (as if in a 'conjunction') given template arguments. |
7658 | /// \param Template the template-like entity that triggered the constraints |
7659 | /// check (either a concept or a constrained entity). |
7660 | /// \param ConstraintExprs a list of constraint expressions, treated as if |
7661 | /// they were 'AND'ed together. |
7662 | /// \param TemplateArgLists the list of template arguments to substitute into |
7663 | /// the constraint expression. |
7664 | /// \param TemplateIDRange The source range of the template id that |
7665 | /// caused the constraints check. |
7666 | /// \param Satisfaction if true is returned, will contain details of the |
7667 | /// satisfaction, with enough information to diagnose an unsatisfied |
7668 | /// expression. |
7669 | /// \returns true if an error occurred and satisfaction could not be checked, |
7670 | /// false otherwise. |
7671 | bool CheckConstraintSatisfaction( |
7672 | const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs, |
7673 | const MultiLevelTemplateArgumentList &TemplateArgLists, |
7674 | SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction) { |
7675 | llvm::SmallVector<Expr *, 4> Converted; |
7676 | return CheckConstraintSatisfaction(Template, ConstraintExprs, ConvertedConstraints&: Converted, |
7677 | TemplateArgList: TemplateArgLists, TemplateIDRange, |
7678 | Satisfaction); |
7679 | } |
7680 | |
7681 | /// \brief Check whether the given list of constraint expressions are |
7682 | /// satisfied (as if in a 'conjunction') given template arguments. |
7683 | /// Additionally, takes an empty list of Expressions which is populated with |
7684 | /// the instantiated versions of the ConstraintExprs. |
7685 | /// \param Template the template-like entity that triggered the constraints |
7686 | /// check (either a concept or a constrained entity). |
7687 | /// \param ConstraintExprs a list of constraint expressions, treated as if |
7688 | /// they were 'AND'ed together. |
7689 | /// \param ConvertedConstraints a out parameter that will get populated with |
7690 | /// the instantiated version of the ConstraintExprs if we successfully checked |
7691 | /// satisfaction. |
7692 | /// \param TemplateArgList the multi-level list of template arguments to |
7693 | /// substitute into the constraint expression. This should be relative to the |
7694 | /// top-level (hence multi-level), since we need to instantiate fully at the |
7695 | /// time of checking. |
7696 | /// \param TemplateIDRange The source range of the template id that |
7697 | /// caused the constraints check. |
7698 | /// \param Satisfaction if true is returned, will contain details of the |
7699 | /// satisfaction, with enough information to diagnose an unsatisfied |
7700 | /// expression. |
7701 | /// \returns true if an error occurred and satisfaction could not be checked, |
7702 | /// false otherwise. |
7703 | bool CheckConstraintSatisfaction( |
7704 | const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs, |
7705 | llvm::SmallVectorImpl<Expr *> &ConvertedConstraints, |
7706 | const MultiLevelTemplateArgumentList &TemplateArgList, |
7707 | SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction); |
7708 | |
7709 | /// \brief Check whether the given non-dependent constraint expression is |
7710 | /// satisfied. Returns false and updates Satisfaction with the satisfaction |
7711 | /// verdict if successful, emits a diagnostic and returns true if an error |
7712 | /// occurred and satisfaction could not be determined. |
7713 | /// |
7714 | /// \returns true if an error occurred, false otherwise. |
7715 | bool CheckConstraintSatisfaction(const Expr *ConstraintExpr, |
7716 | ConstraintSatisfaction &Satisfaction); |
7717 | |
7718 | /// Check whether the given function decl's trailing requires clause is |
7719 | /// satisfied, if any. Returns false and updates Satisfaction with the |
7720 | /// satisfaction verdict if successful, emits a diagnostic and returns true if |
7721 | /// an error occurred and satisfaction could not be determined. |
7722 | /// |
7723 | /// \returns true if an error occurred, false otherwise. |
7724 | bool CheckFunctionConstraints(const FunctionDecl *FD, |
7725 | ConstraintSatisfaction &Satisfaction, |
7726 | SourceLocation UsageLoc = SourceLocation(), |
7727 | bool ForOverloadResolution = false); |
7728 | |
7729 | /// \brief Ensure that the given template arguments satisfy the constraints |
7730 | /// associated with the given template, emitting a diagnostic if they do not. |
7731 | /// |
7732 | /// \param Template The template to which the template arguments are being |
7733 | /// provided. |
7734 | /// |
7735 | /// \param TemplateArgs The converted, canonicalized template arguments. |
7736 | /// |
7737 | /// \param TemplateIDRange The source range of the template id that |
7738 | /// caused the constraints check. |
7739 | /// |
7740 | /// \returns true if the constrains are not satisfied or could not be checked |
7741 | /// for satisfaction, false if the constraints are satisfied. |
7742 | bool EnsureTemplateArgumentListConstraints( |
7743 | TemplateDecl *Template, |
7744 | const MultiLevelTemplateArgumentList &TemplateArgs, |
7745 | SourceRange TemplateIDRange); |
7746 | |
7747 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
7748 | /// unsatisfied. |
7749 | /// \param First whether this is the first time an unsatisfied constraint is |
7750 | /// diagnosed for this error. |
7751 | void |
7752 | DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction &Satisfaction, |
7753 | bool First = true); |
7754 | |
7755 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
7756 | /// unsatisfied. |
7757 | void |
7758 | DiagnoseUnsatisfiedConstraint(const ASTConstraintSatisfaction &Satisfaction, |
7759 | bool First = true); |
7760 | |
7761 | // ParseObjCStringLiteral - Parse Objective-C string literals. |
7762 | ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, |
7763 | ArrayRef<Expr *> Strings); |
7764 | |
7765 | ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S); |
7766 | |
7767 | /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the |
7768 | /// numeric literal expression. Type of the expression will be "NSNumber *" |
7769 | /// or "id" if NSNumber is unavailable. |
7770 | ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number); |
7771 | ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc, |
7772 | bool Value); |
7773 | ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements); |
7774 | |
7775 | /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the |
7776 | /// '@' prefixed parenthesized expression. The type of the expression will |
7777 | /// either be "NSNumber *", "NSString *" or "NSValue *" depending on the type |
7778 | /// of ValueType, which is allowed to be a built-in numeric type, "char *", |
7779 | /// "const char *" or C structure with attribute 'objc_boxable'. |
7780 | ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr); |
7781 | |
7782 | ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, |
7783 | Expr *IndexExpr, |
7784 | ObjCMethodDecl *getterMethod, |
7785 | ObjCMethodDecl *setterMethod); |
7786 | |
7787 | ExprResult BuildObjCDictionaryLiteral(SourceRange SR, |
7788 | MutableArrayRef<ObjCDictionaryElement> Elements); |
7789 | |
7790 | ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, |
7791 | TypeSourceInfo *EncodedTypeInfo, |
7792 | SourceLocation RParenLoc); |
7793 | ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, |
7794 | CXXConversionDecl *Method, |
7795 | bool HadMultipleCandidates); |
7796 | |
7797 | ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, |
7798 | SourceLocation EncodeLoc, |
7799 | SourceLocation LParenLoc, |
7800 | ParsedType Ty, |
7801 | SourceLocation RParenLoc); |
7802 | |
7803 | /// ParseObjCSelectorExpression - Build selector expression for \@selector |
7804 | ExprResult ParseObjCSelectorExpression(Selector Sel, |
7805 | SourceLocation AtLoc, |
7806 | SourceLocation SelLoc, |
7807 | SourceLocation LParenLoc, |
7808 | SourceLocation RParenLoc, |
7809 | bool WarnMultipleSelectors); |
7810 | |
7811 | /// ParseObjCProtocolExpression - Build protocol expression for \@protocol |
7812 | ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, |
7813 | SourceLocation AtLoc, |
7814 | SourceLocation ProtoLoc, |
7815 | SourceLocation LParenLoc, |
7816 | SourceLocation ProtoIdLoc, |
7817 | SourceLocation RParenLoc); |
7818 | |
7819 | //===--------------------------------------------------------------------===// |
7820 | // C++ Declarations |
7821 | // |
7822 | Decl *ActOnStartLinkageSpecification(Scope *S, |
7823 | SourceLocation ExternLoc, |
7824 | Expr *LangStr, |
7825 | SourceLocation LBraceLoc); |
7826 | Decl *ActOnFinishLinkageSpecification(Scope *S, |
7827 | Decl *LinkageSpec, |
7828 | SourceLocation RBraceLoc); |
7829 | |
7830 | |
7831 | //===--------------------------------------------------------------------===// |
7832 | // C++ Classes |
7833 | // |
7834 | CXXRecordDecl *getCurrentClass(Scope *S, const CXXScopeSpec *SS); |
7835 | bool isCurrentClassName(const IdentifierInfo &II, Scope *S, |
7836 | const CXXScopeSpec *SS = nullptr); |
7837 | bool isCurrentClassNameTypo(IdentifierInfo *&II, const CXXScopeSpec *SS); |
7838 | |
7839 | bool ActOnAccessSpecifier(AccessSpecifier Access, SourceLocation ASLoc, |
7840 | SourceLocation ColonLoc, |
7841 | const ParsedAttributesView &Attrs); |
7842 | |
7843 | NamedDecl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, |
7844 | Declarator &D, |
7845 | MultiTemplateParamsArg TemplateParameterLists, |
7846 | Expr *BitfieldWidth, const VirtSpecifiers &VS, |
7847 | InClassInitStyle InitStyle); |
7848 | |
7849 | void ActOnStartCXXInClassMemberInitializer(); |
7850 | void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl, |
7851 | SourceLocation EqualLoc, |
7852 | Expr *Init); |
7853 | |
7854 | MemInitResult ActOnMemInitializer(Decl *ConstructorD, |
7855 | Scope *S, |
7856 | CXXScopeSpec &SS, |
7857 | IdentifierInfo *MemberOrBase, |
7858 | ParsedType TemplateTypeTy, |
7859 | const DeclSpec &DS, |
7860 | SourceLocation IdLoc, |
7861 | SourceLocation LParenLoc, |
7862 | ArrayRef<Expr *> Args, |
7863 | SourceLocation RParenLoc, |
7864 | SourceLocation EllipsisLoc); |
7865 | |
7866 | MemInitResult ActOnMemInitializer(Decl *ConstructorD, |
7867 | Scope *S, |
7868 | CXXScopeSpec &SS, |
7869 | IdentifierInfo *MemberOrBase, |
7870 | ParsedType TemplateTypeTy, |
7871 | const DeclSpec &DS, |
7872 | SourceLocation IdLoc, |
7873 | Expr *InitList, |
7874 | SourceLocation EllipsisLoc); |
7875 | |
7876 | MemInitResult BuildMemInitializer(Decl *ConstructorD, |
7877 | Scope *S, |
7878 | CXXScopeSpec &SS, |
7879 | IdentifierInfo *MemberOrBase, |
7880 | ParsedType TemplateTypeTy, |
7881 | const DeclSpec &DS, |
7882 | SourceLocation IdLoc, |
7883 | Expr *Init, |
7884 | SourceLocation EllipsisLoc); |
7885 | |
7886 | MemInitResult BuildMemberInitializer(ValueDecl *Member, |
7887 | Expr *Init, |
7888 | SourceLocation IdLoc); |
7889 | |
7890 | MemInitResult BuildBaseInitializer(QualType BaseType, |
7891 | TypeSourceInfo *BaseTInfo, |
7892 | Expr *Init, |
7893 | CXXRecordDecl *ClassDecl, |
7894 | SourceLocation EllipsisLoc); |
7895 | |
7896 | MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, |
7897 | Expr *Init, |
7898 | CXXRecordDecl *ClassDecl); |
7899 | |
7900 | bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, |
7901 | CXXCtorInitializer *Initializer); |
7902 | |
7903 | bool SetCtorInitializers( |
7904 | CXXConstructorDecl *Constructor, bool AnyErrors, |
7905 | ArrayRef<CXXCtorInitializer *> Initializers = std::nullopt); |
7906 | |
7907 | void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); |
7908 | |
7909 | |
7910 | /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, |
7911 | /// mark all the non-trivial destructors of its members and bases as |
7912 | /// referenced. |
7913 | void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, |
7914 | CXXRecordDecl *Record); |
7915 | |
7916 | /// Mark destructors of virtual bases of this class referenced. In the Itanium |
7917 | /// C++ ABI, this is done when emitting a destructor for any non-abstract |
7918 | /// class. In the Microsoft C++ ABI, this is done any time a class's |
7919 | /// destructor is referenced. |
7920 | void MarkVirtualBaseDestructorsReferenced( |
7921 | SourceLocation Location, CXXRecordDecl *ClassDecl, |
7922 | llvm::SmallPtrSetImpl<const RecordType *> *DirectVirtualBases = nullptr); |
7923 | |
7924 | /// Do semantic checks to allow the complete destructor variant to be emitted |
7925 | /// when the destructor is defined in another translation unit. In the Itanium |
7926 | /// C++ ABI, destructor variants are emitted together. In the MS C++ ABI, they |
7927 | /// can be emitted in separate TUs. To emit the complete variant, run a subset |
7928 | /// of the checks performed when emitting a regular destructor. |
7929 | void CheckCompleteDestructorVariant(SourceLocation CurrentLocation, |
7930 | CXXDestructorDecl *Dtor); |
7931 | |
7932 | /// The list of classes whose vtables have been used within |
7933 | /// this translation unit, and the source locations at which the |
7934 | /// first use occurred. |
7935 | typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse; |
7936 | |
7937 | /// The list of vtables that are required but have not yet been |
7938 | /// materialized. |
7939 | SmallVector<VTableUse, 16> VTableUses; |
7940 | |
7941 | /// The set of classes whose vtables have been used within |
7942 | /// this translation unit, and a bit that will be true if the vtable is |
7943 | /// required to be emitted (otherwise, it should be emitted only if needed |
7944 | /// by code generation). |
7945 | llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; |
7946 | |
7947 | /// Load any externally-stored vtable uses. |
7948 | void LoadExternalVTableUses(); |
7949 | |
7950 | /// Note that the vtable for the given class was used at the |
7951 | /// given location. |
7952 | void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, |
7953 | bool DefinitionRequired = false); |
7954 | |
7955 | /// Mark the exception specifications of all virtual member functions |
7956 | /// in the given class as needed. |
7957 | void MarkVirtualMemberExceptionSpecsNeeded(SourceLocation Loc, |
7958 | const CXXRecordDecl *RD); |
7959 | |
7960 | /// MarkVirtualMembersReferenced - Will mark all members of the given |
7961 | /// CXXRecordDecl referenced. |
7962 | void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD, |
7963 | bool ConstexprOnly = false); |
7964 | |
7965 | /// Define all of the vtables that have been used in this |
7966 | /// translation unit and reference any virtual members used by those |
7967 | /// vtables. |
7968 | /// |
7969 | /// \returns true if any work was done, false otherwise. |
7970 | bool DefineUsedVTables(); |
7971 | |
7972 | void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); |
7973 | |
7974 | void ActOnMemInitializers(Decl *ConstructorDecl, |
7975 | SourceLocation ColonLoc, |
7976 | ArrayRef<CXXCtorInitializer*> MemInits, |
7977 | bool AnyErrors); |
7978 | |
7979 | /// Check class-level dllimport/dllexport attribute. The caller must |
7980 | /// ensure that referenceDLLExportedClassMethods is called some point later |
7981 | /// when all outer classes of Class are complete. |
7982 | void checkClassLevelDLLAttribute(CXXRecordDecl *Class); |
7983 | void checkClassLevelCodeSegAttribute(CXXRecordDecl *Class); |
7984 | |
7985 | void referenceDLLExportedClassMethods(); |
7986 | |
7987 | void propagateDLLAttrToBaseClassTemplate( |
7988 | CXXRecordDecl *Class, Attr *ClassAttr, |
7989 | ClassTemplateSpecializationDecl *BaseTemplateSpec, |
7990 | SourceLocation BaseLoc); |
7991 | |
7992 | /// Add gsl::Pointer attribute to std::container::iterator |
7993 | /// \param ND The declaration that introduces the name |
7994 | /// std::container::iterator. \param UnderlyingRecord The record named by ND. |
7995 | void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord); |
7996 | |
7997 | /// Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types. |
7998 | void inferGslOwnerPointerAttribute(CXXRecordDecl *Record); |
7999 | |
8000 | /// Add [[gsl::Pointer]] attributes for std:: types. |
8001 | void inferGslPointerAttribute(TypedefNameDecl *TD); |
8002 | |
8003 | void CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record); |
8004 | |
8005 | /// Check that the C++ class annoated with "trivial_abi" satisfies all the |
8006 | /// conditions that are needed for the attribute to have an effect. |
8007 | void checkIllFormedTrivialABIStruct(CXXRecordDecl &RD); |
8008 | |
8009 | void ActOnFinishCXXMemberSpecification(Scope *S, SourceLocation RLoc, |
8010 | Decl *TagDecl, SourceLocation LBrac, |
8011 | SourceLocation RBrac, |
8012 | const ParsedAttributesView &AttrList); |
8013 | void ActOnFinishCXXMemberDecls(); |
8014 | void ActOnFinishCXXNonNestedClass(); |
8015 | |
8016 | void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param); |
8017 | unsigned ActOnReenterTemplateScope(Decl *Template, |
8018 | llvm::function_ref<Scope *()> EnterScope); |
8019 | void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); |
8020 | void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
8021 | void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); |
8022 | void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); |
8023 | void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
8024 | void ActOnFinishDelayedMemberInitializers(Decl *Record); |
8025 | void MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD, |
8026 | CachedTokens &Toks); |
8027 | void UnmarkAsLateParsedTemplate(FunctionDecl *FD); |
8028 | bool IsInsideALocalClassWithinATemplateFunction(); |
8029 | |
8030 | bool EvaluateStaticAssertMessageAsString(Expr *Message, std::string &Result, |
8031 | ASTContext &Ctx, |
8032 | bool ErrorOnInvalidMessage); |
8033 | Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
8034 | Expr *AssertExpr, |
8035 | Expr *AssertMessageExpr, |
8036 | SourceLocation RParenLoc); |
8037 | Decl *BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
8038 | Expr *AssertExpr, Expr *AssertMessageExpr, |
8039 | SourceLocation RParenLoc, bool Failed); |
8040 | void DiagnoseStaticAssertDetails(const Expr *E); |
8041 | |
8042 | Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, |
8043 | MultiTemplateParamsArg TemplateParams); |
8044 | NamedDecl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, |
8045 | MultiTemplateParamsArg TemplateParams); |
8046 | |
8047 | QualType CheckConstructorDeclarator(Declarator &D, QualType R, |
8048 | StorageClass& SC); |
8049 | void CheckConstructor(CXXConstructorDecl *Constructor); |
8050 | QualType CheckDestructorDeclarator(Declarator &D, QualType R, |
8051 | StorageClass& SC); |
8052 | bool CheckDestructor(CXXDestructorDecl *Destructor); |
8053 | void CheckConversionDeclarator(Declarator &D, QualType &R, |
8054 | StorageClass& SC); |
8055 | Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); |
8056 | bool CheckDeductionGuideDeclarator(Declarator &D, QualType &R, |
8057 | StorageClass &SC); |
8058 | void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD); |
8059 | |
8060 | void CheckExplicitlyDefaultedFunction(Scope *S, FunctionDecl *MD); |
8061 | |
8062 | bool CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD, |
8063 | CXXSpecialMember CSM, |
8064 | SourceLocation DefaultLoc); |
8065 | void CheckDelayedMemberExceptionSpecs(); |
8066 | |
8067 | bool CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *MD, |
8068 | DefaultedComparisonKind DCK); |
8069 | void DeclareImplicitEqualityComparison(CXXRecordDecl *RD, |
8070 | FunctionDecl *Spaceship); |
8071 | void DefineDefaultedComparison(SourceLocation Loc, FunctionDecl *FD, |
8072 | DefaultedComparisonKind DCK); |
8073 | |
8074 | void CheckExplicitObjectMemberFunction(Declarator &D, DeclarationName Name, |
8075 | QualType R, bool IsLambda, |
8076 | DeclContext *DC = nullptr); |
8077 | void CheckExplicitObjectMemberFunction(DeclContext *DC, Declarator &D, |
8078 | DeclarationName Name, QualType R); |
8079 | void CheckExplicitObjectLambda(Declarator &D); |
8080 | |
8081 | //===--------------------------------------------------------------------===// |
8082 | // C++ Derived Classes |
8083 | // |
8084 | |
8085 | /// ActOnBaseSpecifier - Parsed a base specifier |
8086 | CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, |
8087 | SourceRange SpecifierRange, |
8088 | bool Virtual, AccessSpecifier Access, |
8089 | TypeSourceInfo *TInfo, |
8090 | SourceLocation EllipsisLoc); |
8091 | |
8092 | BaseResult ActOnBaseSpecifier(Decl *classdecl, SourceRange SpecifierRange, |
8093 | const ParsedAttributesView &Attrs, bool Virtual, |
8094 | AccessSpecifier Access, ParsedType basetype, |
8095 | SourceLocation BaseLoc, |
8096 | SourceLocation EllipsisLoc); |
8097 | |
8098 | bool AttachBaseSpecifiers(CXXRecordDecl *Class, |
8099 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
8100 | void ActOnBaseSpecifiers(Decl *ClassDecl, |
8101 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
8102 | |
8103 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base); |
8104 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base, |
8105 | CXXBasePaths &Paths); |
8106 | |
8107 | // FIXME: I don't like this name. |
8108 | void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); |
8109 | |
8110 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
8111 | SourceLocation Loc, SourceRange Range, |
8112 | CXXCastPath *BasePath = nullptr, |
8113 | bool IgnoreAccess = false); |
8114 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
8115 | unsigned InaccessibleBaseID, |
8116 | unsigned AmbiguousBaseConvID, |
8117 | SourceLocation Loc, SourceRange Range, |
8118 | DeclarationName Name, |
8119 | CXXCastPath *BasePath, |
8120 | bool IgnoreAccess = false); |
8121 | |
8122 | std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); |
8123 | |
8124 | bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New, |
8125 | const CXXMethodDecl *Old); |
8126 | |
8127 | /// CheckOverridingFunctionReturnType - Checks whether the return types are |
8128 | /// covariant, according to C++ [class.virtual]p5. |
8129 | bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, |
8130 | const CXXMethodDecl *Old); |
8131 | |
8132 | // Check that the overriding method has no explicit object parameter. |
8133 | bool CheckExplicitObjectOverride(CXXMethodDecl *New, |
8134 | const CXXMethodDecl *Old); |
8135 | |
8136 | /// CheckOverridingFunctionExceptionSpec - Checks whether the exception |
8137 | /// spec is a subset of base spec. |
8138 | bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, |
8139 | const CXXMethodDecl *Old); |
8140 | |
8141 | bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); |
8142 | |
8143 | /// CheckOverrideControl - Check C++11 override control semantics. |
8144 | void CheckOverrideControl(NamedDecl *D); |
8145 | |
8146 | /// DiagnoseAbsenceOfOverrideControl - Diagnose if 'override' keyword was |
8147 | /// not used in the declaration of an overriding method. |
8148 | void DiagnoseAbsenceOfOverrideControl(NamedDecl *D, bool Inconsistent); |
8149 | |
8150 | /// CheckForFunctionMarkedFinal - Checks whether a virtual member function |
8151 | /// overrides a virtual member function marked 'final', according to |
8152 | /// C++11 [class.virtual]p4. |
8153 | bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, |
8154 | const CXXMethodDecl *Old); |
8155 | |
8156 | |
8157 | //===--------------------------------------------------------------------===// |
8158 | // C++ Access Control |
8159 | // |
8160 | |
8161 | enum AccessResult { |
8162 | AR_accessible, |
8163 | AR_inaccessible, |
8164 | AR_dependent, |
8165 | AR_delayed |
8166 | }; |
8167 | |
8168 | bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, |
8169 | NamedDecl *PrevMemberDecl, |
8170 | AccessSpecifier LexicalAS); |
8171 | |
8172 | AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, |
8173 | DeclAccessPair FoundDecl); |
8174 | AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, |
8175 | DeclAccessPair FoundDecl); |
8176 | AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, |
8177 | SourceRange PlacementRange, |
8178 | CXXRecordDecl *NamingClass, |
8179 | DeclAccessPair FoundDecl, |
8180 | bool Diagnose = true); |
8181 | AccessResult CheckConstructorAccess(SourceLocation Loc, |
8182 | CXXConstructorDecl *D, |
8183 | DeclAccessPair FoundDecl, |
8184 | const InitializedEntity &Entity, |
8185 | bool IsCopyBindingRefToTemp = false); |
8186 | AccessResult CheckConstructorAccess(SourceLocation Loc, |
8187 | CXXConstructorDecl *D, |
8188 | DeclAccessPair FoundDecl, |
8189 | const InitializedEntity &Entity, |
8190 | const PartialDiagnostic &PDiag); |
8191 | AccessResult CheckDestructorAccess(SourceLocation Loc, |
8192 | CXXDestructorDecl *Dtor, |
8193 | const PartialDiagnostic &PDiag, |
8194 | QualType objectType = QualType()); |
8195 | AccessResult CheckFriendAccess(NamedDecl *D); |
8196 | AccessResult CheckMemberAccess(SourceLocation UseLoc, |
8197 | CXXRecordDecl *NamingClass, |
8198 | DeclAccessPair Found); |
8199 | AccessResult |
8200 | CheckStructuredBindingMemberAccess(SourceLocation UseLoc, |
8201 | CXXRecordDecl *DecomposedClass, |
8202 | DeclAccessPair Field); |
8203 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, |
8204 | const SourceRange &, |
8205 | DeclAccessPair FoundDecl); |
8206 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, |
8207 | Expr *ObjectExpr, |
8208 | Expr *ArgExpr, |
8209 | DeclAccessPair FoundDecl); |
8210 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, |
8211 | ArrayRef<Expr *> ArgExprs, |
8212 | DeclAccessPair FoundDecl); |
8213 | AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, |
8214 | DeclAccessPair FoundDecl); |
8215 | AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, |
8216 | QualType Base, QualType Derived, |
8217 | const CXXBasePath &Path, |
8218 | unsigned DiagID, |
8219 | bool ForceCheck = false, |
8220 | bool ForceUnprivileged = false); |
8221 | void CheckLookupAccess(const LookupResult &R); |
8222 | bool IsSimplyAccessible(NamedDecl *Decl, CXXRecordDecl *NamingClass, |
8223 | QualType BaseType); |
8224 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
8225 | DeclAccessPair Found, QualType ObjectType, |
8226 | SourceLocation Loc, |
8227 | const PartialDiagnostic &Diag); |
8228 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
8229 | DeclAccessPair Found, |
8230 | QualType ObjectType) { |
8231 | return isMemberAccessibleForDeletion(NamingClass, Found, ObjectType, |
8232 | Loc: SourceLocation(), Diag: PDiag()); |
8233 | } |
8234 | |
8235 | void HandleDependentAccessCheck(const DependentDiagnostic &DD, |
8236 | const MultiLevelTemplateArgumentList &TemplateArgs); |
8237 | void PerformDependentDiagnostics(const DeclContext *Pattern, |
8238 | const MultiLevelTemplateArgumentList &TemplateArgs); |
8239 | |
8240 | void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
8241 | |
8242 | /// When true, access checking violations are treated as SFINAE |
8243 | /// failures rather than hard errors. |
8244 | bool AccessCheckingSFINAE; |
8245 | |
8246 | enum AbstractDiagSelID { |
8247 | AbstractNone = -1, |
8248 | AbstractReturnType, |
8249 | AbstractParamType, |
8250 | AbstractVariableType, |
8251 | AbstractFieldType, |
8252 | AbstractIvarType, |
8253 | AbstractSynthesizedIvarType, |
8254 | AbstractArrayType |
8255 | }; |
8256 | |
8257 | bool isAbstractType(SourceLocation Loc, QualType T); |
8258 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, |
8259 | TypeDiagnoser &Diagnoser); |
8260 | template <typename... Ts> |
8261 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, |
8262 | const Ts &...Args) { |
8263 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
8264 | return RequireNonAbstractType(Loc, T, Diagnoser); |
8265 | } |
8266 | |
8267 | void DiagnoseAbstractType(const CXXRecordDecl *RD); |
8268 | |
8269 | //===--------------------------------------------------------------------===// |
8270 | // C++ Overloaded Operators [C++ 13.5] |
8271 | // |
8272 | |
8273 | bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); |
8274 | |
8275 | bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); |
8276 | |
8277 | //===--------------------------------------------------------------------===// |
8278 | // C++ Templates [C++ 14] |
8279 | // |
8280 | void FilterAcceptableTemplateNames(LookupResult &R, |
8281 | bool AllowFunctionTemplates = true, |
8282 | bool AllowDependent = true); |
8283 | bool hasAnyAcceptableTemplateNames(LookupResult &R, |
8284 | bool AllowFunctionTemplates = true, |
8285 | bool AllowDependent = true, |
8286 | bool AllowNonTemplateFunctions = false); |
8287 | /// Try to interpret the lookup result D as a template-name. |
8288 | /// |
8289 | /// \param D A declaration found by name lookup. |
8290 | /// \param AllowFunctionTemplates Whether function templates should be |
8291 | /// considered valid results. |
8292 | /// \param AllowDependent Whether unresolved using declarations (that might |
8293 | /// name templates) should be considered valid results. |
8294 | static NamedDecl *getAsTemplateNameDecl(NamedDecl *D, |
8295 | bool AllowFunctionTemplates = true, |
8296 | bool AllowDependent = true); |
8297 | |
8298 | enum TemplateNameIsRequiredTag { TemplateNameIsRequired }; |
8299 | /// Whether and why a template name is required in this lookup. |
8300 | class RequiredTemplateKind { |
8301 | public: |
8302 | /// Template name is required if TemplateKWLoc is valid. |
8303 | RequiredTemplateKind(SourceLocation TemplateKWLoc = SourceLocation()) |
8304 | : TemplateKW(TemplateKWLoc) {} |
8305 | /// Template name is unconditionally required. |
8306 | RequiredTemplateKind(TemplateNameIsRequiredTag) {} |
8307 | |
8308 | SourceLocation getTemplateKeywordLoc() const { |
8309 | return TemplateKW.value_or(u: SourceLocation()); |
8310 | } |
8311 | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } |
8312 | bool isRequired() const { return TemplateKW != SourceLocation(); } |
8313 | explicit operator bool() const { return isRequired(); } |
8314 | |
8315 | private: |
8316 | std::optional<SourceLocation> TemplateKW; |
8317 | }; |
8318 | |
8319 | enum class AssumedTemplateKind { |
8320 | /// This is not assumed to be a template name. |
8321 | None, |
8322 | /// This is assumed to be a template name because lookup found nothing. |
8323 | FoundNothing, |
8324 | /// This is assumed to be a template name because lookup found one or more |
8325 | /// functions (but no function templates). |
8326 | FoundFunctions, |
8327 | }; |
8328 | bool LookupTemplateName( |
8329 | LookupResult &R, Scope *S, CXXScopeSpec &SS, QualType ObjectType, |
8330 | bool EnteringContext, bool &MemberOfUnknownSpecialization, |
8331 | RequiredTemplateKind RequiredTemplate = SourceLocation(), |
8332 | AssumedTemplateKind *ATK = nullptr, bool AllowTypoCorrection = true); |
8333 | |
8334 | TemplateNameKind isTemplateName(Scope *S, |
8335 | CXXScopeSpec &SS, |
8336 | bool hasTemplateKeyword, |
8337 | const UnqualifiedId &Name, |
8338 | ParsedType ObjectType, |
8339 | bool EnteringContext, |
8340 | TemplateTy &Template, |
8341 | bool &MemberOfUnknownSpecialization, |
8342 | bool Disambiguation = false); |
8343 | |
8344 | /// Try to resolve an undeclared template name as a type template. |
8345 | /// |
8346 | /// Sets II to the identifier corresponding to the template name, and updates |
8347 | /// Name to a corresponding (typo-corrected) type template name and TNK to |
8348 | /// the corresponding kind, if possible. |
8349 | void ActOnUndeclaredTypeTemplateName(Scope *S, TemplateTy &Name, |
8350 | TemplateNameKind &TNK, |
8351 | SourceLocation NameLoc, |
8352 | IdentifierInfo *&II); |
8353 | |
8354 | bool resolveAssumedTemplateNameAsType(Scope *S, TemplateName &Name, |
8355 | SourceLocation NameLoc, |
8356 | bool Diagnose = true); |
8357 | |
8358 | /// Determine whether a particular identifier might be the name in a C++1z |
8359 | /// deduction-guide declaration. |
8360 | bool isDeductionGuideName(Scope *S, const IdentifierInfo &Name, |
8361 | SourceLocation NameLoc, CXXScopeSpec &SS, |
8362 | ParsedTemplateTy *Template = nullptr); |
8363 | |
8364 | bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, |
8365 | SourceLocation IILoc, |
8366 | Scope *S, |
8367 | const CXXScopeSpec *SS, |
8368 | TemplateTy &SuggestedTemplate, |
8369 | TemplateNameKind &SuggestedKind); |
8370 | |
8371 | bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation, |
8372 | NamedDecl *Instantiation, |
8373 | bool InstantiatedFromMember, |
8374 | const NamedDecl *Pattern, |
8375 | const NamedDecl *PatternDef, |
8376 | TemplateSpecializationKind TSK, |
8377 | bool Complain = true); |
8378 | |
8379 | void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); |
8380 | TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); |
8381 | |
8382 | NamedDecl *ActOnTypeParameter(Scope *S, bool Typename, |
8383 | SourceLocation EllipsisLoc, |
8384 | SourceLocation KeyLoc, |
8385 | IdentifierInfo *ParamName, |
8386 | SourceLocation ParamNameLoc, |
8387 | unsigned Depth, unsigned Position, |
8388 | SourceLocation EqualLoc, |
8389 | ParsedType DefaultArg, bool HasTypeConstraint); |
8390 | |
8391 | bool CheckTypeConstraint(TemplateIdAnnotation *TypeConstraint); |
8392 | |
8393 | bool ActOnTypeConstraint(const CXXScopeSpec &SS, |
8394 | TemplateIdAnnotation *TypeConstraint, |
8395 | TemplateTypeParmDecl *ConstrainedParameter, |
8396 | SourceLocation EllipsisLoc); |
8397 | bool BuildTypeConstraint(const CXXScopeSpec &SS, |
8398 | TemplateIdAnnotation *TypeConstraint, |
8399 | TemplateTypeParmDecl *ConstrainedParameter, |
8400 | SourceLocation EllipsisLoc, |
8401 | bool AllowUnexpandedPack); |
8402 | |
8403 | bool AttachTypeConstraint(NestedNameSpecifierLoc NS, |
8404 | DeclarationNameInfo NameInfo, |
8405 | ConceptDecl *NamedConcept, |
8406 | const TemplateArgumentListInfo *TemplateArgs, |
8407 | TemplateTypeParmDecl *ConstrainedParameter, |
8408 | SourceLocation EllipsisLoc); |
8409 | |
8410 | bool AttachTypeConstraint(AutoTypeLoc TL, |
8411 | NonTypeTemplateParmDecl *NewConstrainedParm, |
8412 | NonTypeTemplateParmDecl *OrigConstrainedParm, |
8413 | SourceLocation EllipsisLoc); |
8414 | |
8415 | bool RequireStructuralType(QualType T, SourceLocation Loc); |
8416 | |
8417 | QualType CheckNonTypeTemplateParameterType(TypeSourceInfo *&TSI, |
8418 | SourceLocation Loc); |
8419 | QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); |
8420 | |
8421 | NamedDecl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, |
8422 | unsigned Depth, |
8423 | unsigned Position, |
8424 | SourceLocation EqualLoc, |
8425 | Expr *DefaultArg); |
8426 | NamedDecl *ActOnTemplateTemplateParameter(Scope *S, |
8427 | SourceLocation TmpLoc, |
8428 | TemplateParameterList *Params, |
8429 | SourceLocation EllipsisLoc, |
8430 | IdentifierInfo *ParamName, |
8431 | SourceLocation ParamNameLoc, |
8432 | unsigned Depth, |
8433 | unsigned Position, |
8434 | SourceLocation EqualLoc, |
8435 | ParsedTemplateArgument DefaultArg); |
8436 | |
8437 | TemplateParameterList * |
8438 | ActOnTemplateParameterList(unsigned Depth, |
8439 | SourceLocation ExportLoc, |
8440 | SourceLocation TemplateLoc, |
8441 | SourceLocation LAngleLoc, |
8442 | ArrayRef<NamedDecl *> Params, |
8443 | SourceLocation RAngleLoc, |
8444 | Expr *RequiresClause); |
8445 | |
8446 | /// The context in which we are checking a template parameter list. |
8447 | enum TemplateParamListContext { |
8448 | TPC_ClassTemplate, |
8449 | TPC_VarTemplate, |
8450 | TPC_FunctionTemplate, |
8451 | TPC_ClassTemplateMember, |
8452 | TPC_FriendClassTemplate, |
8453 | TPC_FriendFunctionTemplate, |
8454 | TPC_FriendFunctionTemplateDefinition, |
8455 | TPC_TypeAliasTemplate |
8456 | }; |
8457 | |
8458 | bool CheckTemplateParameterList(TemplateParameterList *NewParams, |
8459 | TemplateParameterList *OldParams, |
8460 | TemplateParamListContext TPC, |
8461 | SkipBodyInfo *SkipBody = nullptr); |
8462 | TemplateParameterList *MatchTemplateParametersToScopeSpecifier( |
8463 | SourceLocation DeclStartLoc, SourceLocation DeclLoc, |
8464 | const CXXScopeSpec &SS, TemplateIdAnnotation *TemplateId, |
8465 | ArrayRef<TemplateParameterList *> ParamLists, |
8466 | bool IsFriend, bool &IsMemberSpecialization, bool &Invalid, |
8467 | bool SuppressDiagnostic = false); |
8468 | |
8469 | DeclResult CheckClassTemplate( |
8470 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
8471 | CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, |
8472 | const ParsedAttributesView &Attr, TemplateParameterList *TemplateParams, |
8473 | AccessSpecifier AS, SourceLocation ModulePrivateLoc, |
8474 | SourceLocation FriendLoc, unsigned NumOuterTemplateParamLists, |
8475 | TemplateParameterList **OuterTemplateParamLists, |
8476 | SkipBodyInfo *SkipBody = nullptr); |
8477 | |
8478 | TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, |
8479 | QualType NTTPType, |
8480 | SourceLocation Loc); |
8481 | |
8482 | /// Get a template argument mapping the given template parameter to itself, |
8483 | /// e.g. for X in \c template<int X>, this would return an expression template |
8484 | /// argument referencing X. |
8485 | TemplateArgumentLoc getIdentityTemplateArgumentLoc(NamedDecl *Param, |
8486 | SourceLocation Location); |
8487 | |
8488 | void translateTemplateArguments(const ASTTemplateArgsPtr &In, |
8489 | TemplateArgumentListInfo &Out); |
8490 | |
8491 | ParsedTemplateArgument ActOnTemplateTypeArgument(TypeResult ParsedType); |
8492 | |
8493 | void NoteAllFoundTemplates(TemplateName Name); |
8494 | |
8495 | QualType CheckTemplateIdType(TemplateName Template, |
8496 | SourceLocation TemplateLoc, |
8497 | TemplateArgumentListInfo &TemplateArgs); |
8498 | |
8499 | TypeResult |
8500 | ActOnTemplateIdType(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
8501 | TemplateTy Template, IdentifierInfo *TemplateII, |
8502 | SourceLocation TemplateIILoc, SourceLocation LAngleLoc, |
8503 | ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, |
8504 | bool IsCtorOrDtorName = false, bool IsClassName = false, |
8505 | ImplicitTypenameContext AllowImplicitTypename = |
8506 | ImplicitTypenameContext::No); |
8507 | |
8508 | /// Parsed an elaborated-type-specifier that refers to a template-id, |
8509 | /// such as \c class T::template apply<U>. |
8510 | TypeResult ActOnTagTemplateIdType(TagUseKind TUK, |
8511 | TypeSpecifierType TagSpec, |
8512 | SourceLocation TagLoc, |
8513 | CXXScopeSpec &SS, |
8514 | SourceLocation TemplateKWLoc, |
8515 | TemplateTy TemplateD, |
8516 | SourceLocation TemplateLoc, |
8517 | SourceLocation LAngleLoc, |
8518 | ASTTemplateArgsPtr TemplateArgsIn, |
8519 | SourceLocation RAngleLoc); |
8520 | |
8521 | DeclResult ActOnVarTemplateSpecialization( |
8522 | Scope *S, Declarator &D, TypeSourceInfo *DI, LookupResult &Previous, |
8523 | SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams, |
8524 | StorageClass SC, bool IsPartialSpecialization); |
8525 | |
8526 | /// Get the specialization of the given variable template corresponding to |
8527 | /// the specified argument list, or a null-but-valid result if the arguments |
8528 | /// are dependent. |
8529 | DeclResult CheckVarTemplateId(VarTemplateDecl *Template, |
8530 | SourceLocation TemplateLoc, |
8531 | SourceLocation TemplateNameLoc, |
8532 | const TemplateArgumentListInfo &TemplateArgs); |
8533 | |
8534 | /// Form a reference to the specialization of the given variable template |
8535 | /// corresponding to the specified argument list, or a null-but-valid result |
8536 | /// if the arguments are dependent. |
8537 | ExprResult CheckVarTemplateId(const CXXScopeSpec &SS, |
8538 | const DeclarationNameInfo &NameInfo, |
8539 | VarTemplateDecl *Template, |
8540 | SourceLocation TemplateLoc, |
8541 | const TemplateArgumentListInfo *TemplateArgs); |
8542 | |
8543 | ExprResult |
8544 | CheckConceptTemplateId(const CXXScopeSpec &SS, |
8545 | SourceLocation TemplateKWLoc, |
8546 | const DeclarationNameInfo &ConceptNameInfo, |
8547 | NamedDecl *FoundDecl, ConceptDecl *NamedConcept, |
8548 | const TemplateArgumentListInfo *TemplateArgs); |
8549 | |
8550 | void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc); |
8551 | |
8552 | ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, |
8553 | SourceLocation TemplateKWLoc, |
8554 | LookupResult &R, |
8555 | bool RequiresADL, |
8556 | const TemplateArgumentListInfo *TemplateArgs); |
8557 | |
8558 | ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, |
8559 | SourceLocation TemplateKWLoc, |
8560 | const DeclarationNameInfo &NameInfo, |
8561 | const TemplateArgumentListInfo *TemplateArgs); |
8562 | |
8563 | TemplateNameKind ActOnTemplateName( |
8564 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
8565 | const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, |
8566 | TemplateTy &Template, bool AllowInjectedClassName = false); |
8567 | |
8568 | DeclResult ActOnClassTemplateSpecialization( |
8569 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
8570 | SourceLocation ModulePrivateLoc, CXXScopeSpec &SS, |
8571 | TemplateIdAnnotation &TemplateId, const ParsedAttributesView &Attr, |
8572 | MultiTemplateParamsArg TemplateParameterLists, |
8573 | SkipBodyInfo *SkipBody = nullptr); |
8574 | |
8575 | bool CheckTemplatePartialSpecializationArgs(SourceLocation Loc, |
8576 | TemplateDecl *PrimaryTemplate, |
8577 | unsigned NumExplicitArgs, |
8578 | ArrayRef<TemplateArgument> Args); |
8579 | void CheckTemplatePartialSpecialization( |
8580 | ClassTemplatePartialSpecializationDecl *Partial); |
8581 | void CheckTemplatePartialSpecialization( |
8582 | VarTemplatePartialSpecializationDecl *Partial); |
8583 | |
8584 | Decl *ActOnTemplateDeclarator(Scope *S, |
8585 | MultiTemplateParamsArg TemplateParameterLists, |
8586 | Declarator &D); |
8587 | |
8588 | bool |
8589 | CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, |
8590 | TemplateSpecializationKind NewTSK, |
8591 | NamedDecl *PrevDecl, |
8592 | TemplateSpecializationKind PrevTSK, |
8593 | SourceLocation PrevPtOfInstantiation, |
8594 | bool &SuppressNew); |
8595 | |
8596 | bool CheckDependentFunctionTemplateSpecialization( |
8597 | FunctionDecl *FD, const TemplateArgumentListInfo *ExplicitTemplateArgs, |
8598 | LookupResult &Previous); |
8599 | |
8600 | bool CheckFunctionTemplateSpecialization( |
8601 | FunctionDecl *FD, TemplateArgumentListInfo *ExplicitTemplateArgs, |
8602 | LookupResult &Previous, bool QualifiedFriend = false); |
8603 | bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
8604 | void CompleteMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
8605 | |
8606 | DeclResult ActOnExplicitInstantiation( |
8607 | Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc, |
8608 | unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS, |
8609 | TemplateTy Template, SourceLocation TemplateNameLoc, |
8610 | SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, |
8611 | SourceLocation RAngleLoc, const ParsedAttributesView &Attr); |
8612 | |
8613 | DeclResult ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, |
8614 | SourceLocation TemplateLoc, |
8615 | unsigned TagSpec, SourceLocation KWLoc, |
8616 | CXXScopeSpec &SS, IdentifierInfo *Name, |
8617 | SourceLocation NameLoc, |
8618 | const ParsedAttributesView &Attr); |
8619 | |
8620 | DeclResult ActOnExplicitInstantiation(Scope *S, |
8621 | SourceLocation ExternLoc, |
8622 | SourceLocation TemplateLoc, |
8623 | Declarator &D); |
8624 | |
8625 | TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable( |
8626 | TemplateDecl *Template, SourceLocation TemplateLoc, |
8627 | SourceLocation RAngleLoc, Decl *Param, |
8628 | ArrayRef<TemplateArgument> SugaredConverted, |
8629 | ArrayRef<TemplateArgument> CanonicalConverted, bool &HasDefaultArg); |
8630 | |
8631 | SourceLocation getTopMostPointOfInstantiation(const NamedDecl *) const; |
8632 | |
8633 | /// Specifies the context in which a particular template |
8634 | /// argument is being checked. |
8635 | enum CheckTemplateArgumentKind { |
8636 | /// The template argument was specified in the code or was |
8637 | /// instantiated with some deduced template arguments. |
8638 | CTAK_Specified, |
8639 | |
8640 | /// The template argument was deduced via template argument |
8641 | /// deduction. |
8642 | CTAK_Deduced, |
8643 | |
8644 | /// The template argument was deduced from an array bound |
8645 | /// via template argument deduction. |
8646 | CTAK_DeducedFromArrayBound |
8647 | }; |
8648 | |
8649 | bool |
8650 | CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, |
8651 | NamedDecl *Template, SourceLocation TemplateLoc, |
8652 | SourceLocation RAngleLoc, unsigned ArgumentPackIndex, |
8653 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
8654 | SmallVectorImpl<TemplateArgument> &CanonicalConverted, |
8655 | CheckTemplateArgumentKind CTAK); |
8656 | |
8657 | /// Check that the given template arguments can be provided to |
8658 | /// the given template, converting the arguments along the way. |
8659 | /// |
8660 | /// \param Template The template to which the template arguments are being |
8661 | /// provided. |
8662 | /// |
8663 | /// \param TemplateLoc The location of the template name in the source. |
8664 | /// |
8665 | /// \param TemplateArgs The list of template arguments. If the template is |
8666 | /// a template template parameter, this function may extend the set of |
8667 | /// template arguments to also include substituted, defaulted template |
8668 | /// arguments. |
8669 | /// |
8670 | /// \param PartialTemplateArgs True if the list of template arguments is |
8671 | /// intentionally partial, e.g., because we're checking just the initial |
8672 | /// set of template arguments. |
8673 | /// |
8674 | /// \param Converted Will receive the converted, canonicalized template |
8675 | /// arguments. |
8676 | /// |
8677 | /// \param UpdateArgsWithConversions If \c true, update \p TemplateArgs to |
8678 | /// contain the converted forms of the template arguments as written. |
8679 | /// Otherwise, \p TemplateArgs will not be modified. |
8680 | /// |
8681 | /// \param ConstraintsNotSatisfied If provided, and an error occurred, will |
8682 | /// receive true if the cause for the error is the associated constraints of |
8683 | /// the template not being satisfied by the template arguments. |
8684 | /// |
8685 | /// \returns true if an error occurred, false otherwise. |
8686 | bool CheckTemplateArgumentList( |
8687 | TemplateDecl *Template, SourceLocation TemplateLoc, |
8688 | TemplateArgumentListInfo &TemplateArgs, bool PartialTemplateArgs, |
8689 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
8690 | SmallVectorImpl<TemplateArgument> &CanonicalConverted, |
8691 | bool UpdateArgsWithConversions = true, |
8692 | bool *ConstraintsNotSatisfied = nullptr); |
8693 | |
8694 | bool CheckTemplateTypeArgument( |
8695 | TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg, |
8696 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
8697 | SmallVectorImpl<TemplateArgument> &CanonicalConverted); |
8698 | |
8699 | bool CheckTemplateArgument(TypeSourceInfo *Arg); |
8700 | ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, |
8701 | QualType InstantiatedParamType, Expr *Arg, |
8702 | TemplateArgument &SugaredConverted, |
8703 | TemplateArgument &CanonicalConverted, |
8704 | CheckTemplateArgumentKind CTAK); |
8705 | bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, |
8706 | TemplateParameterList *Params, |
8707 | TemplateArgumentLoc &Arg); |
8708 | |
8709 | void NoteTemplateLocation(const NamedDecl &Decl, |
8710 | std::optional<SourceRange> ParamRange = {}); |
8711 | void NoteTemplateParameterLocation(const NamedDecl &Decl); |
8712 | |
8713 | ExprResult |
8714 | BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, |
8715 | QualType ParamType, |
8716 | SourceLocation Loc); |
8717 | ExprResult |
8718 | BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg, |
8719 | SourceLocation Loc); |
8720 | |
8721 | /// Enumeration describing how template parameter lists are compared |
8722 | /// for equality. |
8723 | enum TemplateParameterListEqualKind { |
8724 | /// We are matching the template parameter lists of two templates |
8725 | /// that might be redeclarations. |
8726 | /// |
8727 | /// \code |
8728 | /// template<typename T> struct X; |
8729 | /// template<typename T> struct X; |
8730 | /// \endcode |
8731 | TPL_TemplateMatch, |
8732 | |
8733 | /// We are matching the template parameter lists of two template |
8734 | /// template parameters as part of matching the template parameter lists |
8735 | /// of two templates that might be redeclarations. |
8736 | /// |
8737 | /// \code |
8738 | /// template<template<int I> class TT> struct X; |
8739 | /// template<template<int Value> class Other> struct X; |
8740 | /// \endcode |
8741 | TPL_TemplateTemplateParmMatch, |
8742 | |
8743 | /// We are matching the template parameter lists of a template |
8744 | /// template argument against the template parameter lists of a template |
8745 | /// template parameter. |
8746 | /// |
8747 | /// \code |
8748 | /// template<template<int Value> class Metafun> struct X; |
8749 | /// template<int Value> struct integer_c; |
8750 | /// X<integer_c> xic; |
8751 | /// \endcode |
8752 | TPL_TemplateTemplateArgumentMatch, |
8753 | |
8754 | /// We are determining whether the template-parameters are equivalent |
8755 | /// according to C++ [temp.over.link]/6. This comparison does not consider |
8756 | /// constraints. |
8757 | /// |
8758 | /// \code |
8759 | /// template<C1 T> void f(T); |
8760 | /// template<C2 T> void f(T); |
8761 | /// \endcode |
8762 | TPL_TemplateParamsEquivalent, |
8763 | }; |
8764 | |
8765 | // A struct to represent the 'new' declaration, which is either itself just |
8766 | // the named decl, or the important information we need about it in order to |
8767 | // do constraint comparisons. |
8768 | class TemplateCompareNewDeclInfo { |
8769 | const NamedDecl *ND = nullptr; |
8770 | const DeclContext *DC = nullptr; |
8771 | const DeclContext *LexicalDC = nullptr; |
8772 | SourceLocation Loc; |
8773 | |
8774 | public: |
8775 | TemplateCompareNewDeclInfo(const NamedDecl *ND) : ND(ND) {} |
8776 | TemplateCompareNewDeclInfo(const DeclContext *DeclCtx, |
8777 | const DeclContext *LexicalDeclCtx, |
8778 | SourceLocation Loc) |
8779 | |
8780 | : DC(DeclCtx), LexicalDC(LexicalDeclCtx), Loc(Loc) { |
8781 | assert(DC && LexicalDC && |
8782 | "Constructor only for cases where we have the information to put " |
8783 | "in here" ); |
8784 | } |
8785 | |
8786 | // If this was constructed with no information, we cannot do substitution |
8787 | // for constraint comparison, so make sure we can check that. |
8788 | bool isInvalid() const { return !ND && !DC; } |
8789 | |
8790 | const NamedDecl *getDecl() const { return ND; } |
8791 | |
8792 | bool ContainsDecl(const NamedDecl *ND) const { return this->ND == ND; } |
8793 | |
8794 | const DeclContext *getLexicalDeclContext() const { |
8795 | return ND ? ND->getLexicalDeclContext() : LexicalDC; |
8796 | } |
8797 | |
8798 | const DeclContext *getDeclContext() const { |
8799 | return ND ? ND->getDeclContext() : DC; |
8800 | } |
8801 | |
8802 | SourceLocation getLocation() const { return ND ? ND->getLocation() : Loc; } |
8803 | }; |
8804 | |
8805 | bool TemplateParameterListsAreEqual( |
8806 | const TemplateCompareNewDeclInfo &NewInstFrom, TemplateParameterList *New, |
8807 | const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain, |
8808 | TemplateParameterListEqualKind Kind, |
8809 | SourceLocation TemplateArgLoc = SourceLocation()); |
8810 | |
8811 | bool TemplateParameterListsAreEqual( |
8812 | TemplateParameterList *New, TemplateParameterList *Old, bool Complain, |
8813 | TemplateParameterListEqualKind Kind, |
8814 | SourceLocation TemplateArgLoc = SourceLocation()) { |
8815 | return TemplateParameterListsAreEqual(NewInstFrom: nullptr, New, OldInstFrom: nullptr, Old, Complain, |
8816 | Kind, TemplateArgLoc); |
8817 | } |
8818 | |
8819 | // Calculates whether two constraint expressions are equal irrespective of a |
8820 | // difference in 'depth'. This takes a pair of optional 'NamedDecl's 'Old' and |
8821 | // 'New', which are the "source" of the constraint, since this is necessary |
8822 | // for figuring out the relative 'depth' of the constraint. The depth of the |
8823 | // 'primary template' and the 'instantiated from' templates aren't necessarily |
8824 | // the same, such as a case when one is a 'friend' defined in a class. |
8825 | bool AreConstraintExpressionsEqual(const NamedDecl *Old, |
8826 | const Expr *OldConstr, |
8827 | const TemplateCompareNewDeclInfo &New, |
8828 | const Expr *NewConstr); |
8829 | |
8830 | bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); |
8831 | |
8832 | /// Called when the parser has parsed a C++ typename |
8833 | /// specifier, e.g., "typename T::type". |
8834 | /// |
8835 | /// \param S The scope in which this typename type occurs. |
8836 | /// \param TypenameLoc the location of the 'typename' keyword |
8837 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
8838 | /// \param II the identifier we're retrieving (e.g., 'type' in the example). |
8839 | /// \param IdLoc the location of the identifier. |
8840 | /// \param IsImplicitTypename context where T::type refers to a type. |
8841 | TypeResult ActOnTypenameType( |
8842 | Scope *S, SourceLocation TypenameLoc, const CXXScopeSpec &SS, |
8843 | const IdentifierInfo &II, SourceLocation IdLoc, |
8844 | ImplicitTypenameContext IsImplicitTypename = ImplicitTypenameContext::No); |
8845 | |
8846 | /// Called when the parser has parsed a C++ typename |
8847 | /// specifier that ends in a template-id, e.g., |
8848 | /// "typename MetaFun::template apply<T1, T2>". |
8849 | /// |
8850 | /// \param S The scope in which this typename type occurs. |
8851 | /// \param TypenameLoc the location of the 'typename' keyword |
8852 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
8853 | /// \param TemplateLoc the location of the 'template' keyword, if any. |
8854 | /// \param TemplateName The template name. |
8855 | /// \param TemplateII The identifier used to name the template. |
8856 | /// \param TemplateIILoc The location of the template name. |
8857 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
8858 | /// \param TemplateArgs The template arguments. |
8859 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
8860 | TypeResult |
8861 | ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, |
8862 | const CXXScopeSpec &SS, |
8863 | SourceLocation TemplateLoc, |
8864 | TemplateTy TemplateName, |
8865 | IdentifierInfo *TemplateII, |
8866 | SourceLocation TemplateIILoc, |
8867 | SourceLocation LAngleLoc, |
8868 | ASTTemplateArgsPtr TemplateArgs, |
8869 | SourceLocation RAngleLoc); |
8870 | |
8871 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
8872 | SourceLocation KeywordLoc, |
8873 | NestedNameSpecifierLoc QualifierLoc, |
8874 | const IdentifierInfo &II, |
8875 | SourceLocation IILoc, |
8876 | TypeSourceInfo **TSI, |
8877 | bool DeducedTSTContext); |
8878 | |
8879 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
8880 | SourceLocation KeywordLoc, |
8881 | NestedNameSpecifierLoc QualifierLoc, |
8882 | const IdentifierInfo &II, |
8883 | SourceLocation IILoc, |
8884 | bool DeducedTSTContext = true); |
8885 | |
8886 | |
8887 | TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, |
8888 | SourceLocation Loc, |
8889 | DeclarationName Name); |
8890 | bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); |
8891 | |
8892 | ExprResult RebuildExprInCurrentInstantiation(Expr *E); |
8893 | bool RebuildTemplateParamsInCurrentInstantiation( |
8894 | TemplateParameterList *Params); |
8895 | |
8896 | std::string |
8897 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
8898 | const TemplateArgumentList &Args); |
8899 | |
8900 | std::string |
8901 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
8902 | const TemplateArgument *Args, |
8903 | unsigned NumArgs); |
8904 | |
8905 | //===--------------------------------------------------------------------===// |
8906 | // C++ Concepts |
8907 | //===--------------------------------------------------------------------===// |
8908 | Decl *ActOnConceptDefinition( |
8909 | Scope *S, MultiTemplateParamsArg TemplateParameterLists, |
8910 | IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr); |
8911 | |
8912 | void CheckConceptRedefinition(ConceptDecl *NewDecl, LookupResult &Previous, |
8913 | bool &AddToScope); |
8914 | |
8915 | RequiresExprBodyDecl * |
8916 | ActOnStartRequiresExpr(SourceLocation RequiresKWLoc, |
8917 | ArrayRef<ParmVarDecl *> LocalParameters, |
8918 | Scope *BodyScope); |
8919 | void ActOnFinishRequiresExpr(); |
8920 | concepts::Requirement *ActOnSimpleRequirement(Expr *E); |
8921 | concepts::Requirement *ActOnTypeRequirement( |
8922 | SourceLocation TypenameKWLoc, CXXScopeSpec &SS, SourceLocation NameLoc, |
8923 | IdentifierInfo *TypeName, TemplateIdAnnotation *TemplateId); |
8924 | concepts::Requirement *ActOnCompoundRequirement(Expr *E, |
8925 | SourceLocation NoexceptLoc); |
8926 | concepts::Requirement * |
8927 | ActOnCompoundRequirement( |
8928 | Expr *E, SourceLocation NoexceptLoc, CXXScopeSpec &SS, |
8929 | TemplateIdAnnotation *TypeConstraint, unsigned Depth); |
8930 | concepts::Requirement *ActOnNestedRequirement(Expr *Constraint); |
8931 | concepts::ExprRequirement * |
8932 | BuildExprRequirement( |
8933 | Expr *E, bool IsSatisfied, SourceLocation NoexceptLoc, |
8934 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
8935 | concepts::ExprRequirement * |
8936 | BuildExprRequirement( |
8937 | concepts::Requirement::SubstitutionDiagnostic *ExprSubstDiag, |
8938 | bool IsSatisfied, SourceLocation NoexceptLoc, |
8939 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
8940 | concepts::TypeRequirement *BuildTypeRequirement(TypeSourceInfo *Type); |
8941 | concepts::TypeRequirement * |
8942 | BuildTypeRequirement( |
8943 | concepts::Requirement::SubstitutionDiagnostic *SubstDiag); |
8944 | concepts::NestedRequirement *BuildNestedRequirement(Expr *E); |
8945 | concepts::NestedRequirement * |
8946 | BuildNestedRequirement(StringRef InvalidConstraintEntity, |
8947 | const ASTConstraintSatisfaction &Satisfaction); |
8948 | ExprResult ActOnRequiresExpr(SourceLocation RequiresKWLoc, |
8949 | RequiresExprBodyDecl *Body, |
8950 | SourceLocation LParenLoc, |
8951 | ArrayRef<ParmVarDecl *> LocalParameters, |
8952 | SourceLocation RParenLoc, |
8953 | ArrayRef<concepts::Requirement *> Requirements, |
8954 | SourceLocation ClosingBraceLoc); |
8955 | |
8956 | //===--------------------------------------------------------------------===// |
8957 | // C++ Variadic Templates (C++0x [temp.variadic]) |
8958 | //===--------------------------------------------------------------------===// |
8959 | |
8960 | /// Determine whether an unexpanded parameter pack might be permitted in this |
8961 | /// location. Useful for error recovery. |
8962 | bool isUnexpandedParameterPackPermitted(); |
8963 | |
8964 | /// The context in which an unexpanded parameter pack is |
8965 | /// being diagnosed. |
8966 | /// |
8967 | /// Note that the values of this enumeration line up with the first |
8968 | /// argument to the \c err_unexpanded_parameter_pack diagnostic. |
8969 | enum UnexpandedParameterPackContext { |
8970 | /// An arbitrary expression. |
8971 | UPPC_Expression = 0, |
8972 | |
8973 | /// The base type of a class type. |
8974 | UPPC_BaseType, |
8975 | |
8976 | /// The type of an arbitrary declaration. |
8977 | UPPC_DeclarationType, |
8978 | |
8979 | /// The type of a data member. |
8980 | UPPC_DataMemberType, |
8981 | |
8982 | /// The size of a bit-field. |
8983 | UPPC_BitFieldWidth, |
8984 | |
8985 | /// The expression in a static assertion. |
8986 | UPPC_StaticAssertExpression, |
8987 | |
8988 | /// The fixed underlying type of an enumeration. |
8989 | UPPC_FixedUnderlyingType, |
8990 | |
8991 | /// The enumerator value. |
8992 | UPPC_EnumeratorValue, |
8993 | |
8994 | /// A using declaration. |
8995 | UPPC_UsingDeclaration, |
8996 | |
8997 | /// A friend declaration. |
8998 | UPPC_FriendDeclaration, |
8999 | |
9000 | /// A declaration qualifier. |
9001 | UPPC_DeclarationQualifier, |
9002 | |
9003 | /// An initializer. |
9004 | UPPC_Initializer, |
9005 | |
9006 | /// A default argument. |
9007 | UPPC_DefaultArgument, |
9008 | |
9009 | /// The type of a non-type template parameter. |
9010 | UPPC_NonTypeTemplateParameterType, |
9011 | |
9012 | /// The type of an exception. |
9013 | UPPC_ExceptionType, |
9014 | |
9015 | /// Explicit specialization. |
9016 | UPPC_ExplicitSpecialization, |
9017 | |
9018 | /// Partial specialization. |
9019 | UPPC_PartialSpecialization, |
9020 | |
9021 | /// Microsoft __if_exists. |
9022 | UPPC_IfExists, |
9023 | |
9024 | /// Microsoft __if_not_exists. |
9025 | UPPC_IfNotExists, |
9026 | |
9027 | /// Lambda expression. |
9028 | UPPC_Lambda, |
9029 | |
9030 | /// Block expression. |
9031 | UPPC_Block, |
9032 | |
9033 | /// A type constraint. |
9034 | UPPC_TypeConstraint, |
9035 | |
9036 | // A requirement in a requires-expression. |
9037 | UPPC_Requirement, |
9038 | |
9039 | // A requires-clause. |
9040 | UPPC_RequiresClause, |
9041 | }; |
9042 | |
9043 | /// Diagnose unexpanded parameter packs. |
9044 | /// |
9045 | /// \param Loc The location at which we should emit the diagnostic. |
9046 | /// |
9047 | /// \param UPPC The context in which we are diagnosing unexpanded |
9048 | /// parameter packs. |
9049 | /// |
9050 | /// \param Unexpanded the set of unexpanded parameter packs. |
9051 | /// |
9052 | /// \returns true if an error occurred, false otherwise. |
9053 | bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc, |
9054 | UnexpandedParameterPackContext UPPC, |
9055 | ArrayRef<UnexpandedParameterPack> Unexpanded); |
9056 | |
9057 | /// If the given type contains an unexpanded parameter pack, |
9058 | /// diagnose the error. |
9059 | /// |
9060 | /// \param Loc The source location where a diagnostc should be emitted. |
9061 | /// |
9062 | /// \param T The type that is being checked for unexpanded parameter |
9063 | /// packs. |
9064 | /// |
9065 | /// \returns true if an error occurred, false otherwise. |
9066 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, |
9067 | UnexpandedParameterPackContext UPPC); |
9068 | |
9069 | /// If the given expression contains an unexpanded parameter |
9070 | /// pack, diagnose the error. |
9071 | /// |
9072 | /// \param E The expression that is being checked for unexpanded |
9073 | /// parameter packs. |
9074 | /// |
9075 | /// \returns true if an error occurred, false otherwise. |
9076 | bool DiagnoseUnexpandedParameterPack(Expr *E, |
9077 | UnexpandedParameterPackContext UPPC = UPPC_Expression); |
9078 | |
9079 | /// If the given requirees-expression contains an unexpanded reference to one |
9080 | /// of its own parameter packs, diagnose the error. |
9081 | /// |
9082 | /// \param RE The requiress-expression that is being checked for unexpanded |
9083 | /// parameter packs. |
9084 | /// |
9085 | /// \returns true if an error occurred, false otherwise. |
9086 | bool DiagnoseUnexpandedParameterPackInRequiresExpr(RequiresExpr *RE); |
9087 | |
9088 | /// If the given nested-name-specifier contains an unexpanded |
9089 | /// parameter pack, diagnose the error. |
9090 | /// |
9091 | /// \param SS The nested-name-specifier that is being checked for |
9092 | /// unexpanded parameter packs. |
9093 | /// |
9094 | /// \returns true if an error occurred, false otherwise. |
9095 | bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, |
9096 | UnexpandedParameterPackContext UPPC); |
9097 | |
9098 | /// If the given name contains an unexpanded parameter pack, |
9099 | /// diagnose the error. |
9100 | /// |
9101 | /// \param NameInfo The name (with source location information) that |
9102 | /// is being checked for unexpanded parameter packs. |
9103 | /// |
9104 | /// \returns true if an error occurred, false otherwise. |
9105 | bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, |
9106 | UnexpandedParameterPackContext UPPC); |
9107 | |
9108 | /// If the given template name contains an unexpanded parameter pack, |
9109 | /// diagnose the error. |
9110 | /// |
9111 | /// \param Loc The location of the template name. |
9112 | /// |
9113 | /// \param Template The template name that is being checked for unexpanded |
9114 | /// parameter packs. |
9115 | /// |
9116 | /// \returns true if an error occurred, false otherwise. |
9117 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, |
9118 | TemplateName Template, |
9119 | UnexpandedParameterPackContext UPPC); |
9120 | |
9121 | /// If the given template argument contains an unexpanded parameter |
9122 | /// pack, diagnose the error. |
9123 | /// |
9124 | /// \param Arg The template argument that is being checked for unexpanded |
9125 | /// parameter packs. |
9126 | /// |
9127 | /// \returns true if an error occurred, false otherwise. |
9128 | bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, |
9129 | UnexpandedParameterPackContext UPPC); |
9130 | |
9131 | /// Collect the set of unexpanded parameter packs within the given |
9132 | /// template argument. |
9133 | /// |
9134 | /// \param Arg The template argument that will be traversed to find |
9135 | /// unexpanded parameter packs. |
9136 | void collectUnexpandedParameterPacks(TemplateArgument Arg, |
9137 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
9138 | |
9139 | /// Collect the set of unexpanded parameter packs within the given |
9140 | /// template argument. |
9141 | /// |
9142 | /// \param Arg The template argument that will be traversed to find |
9143 | /// unexpanded parameter packs. |
9144 | void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, |
9145 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
9146 | |
9147 | /// Collect the set of unexpanded parameter packs within the given |
9148 | /// type. |
9149 | /// |
9150 | /// \param T The type that will be traversed to find |
9151 | /// unexpanded parameter packs. |
9152 | void collectUnexpandedParameterPacks(QualType T, |
9153 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
9154 | |
9155 | /// Collect the set of unexpanded parameter packs within the given |
9156 | /// type. |
9157 | /// |
9158 | /// \param TL The type that will be traversed to find |
9159 | /// unexpanded parameter packs. |
9160 | void collectUnexpandedParameterPacks(TypeLoc TL, |
9161 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
9162 | |
9163 | /// Collect the set of unexpanded parameter packs within the given |
9164 | /// nested-name-specifier. |
9165 | /// |
9166 | /// \param NNS The nested-name-specifier that will be traversed to find |
9167 | /// unexpanded parameter packs. |
9168 | void collectUnexpandedParameterPacks(NestedNameSpecifierLoc NNS, |
9169 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
9170 | |
9171 | /// Collect the set of unexpanded parameter packs within the given |
9172 | /// name. |
9173 | /// |
9174 | /// \param NameInfo The name that will be traversed to find |
9175 | /// unexpanded parameter packs. |
9176 | void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo, |
9177 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
9178 | |
9179 | /// Invoked when parsing a template argument followed by an |
9180 | /// ellipsis, which creates a pack expansion. |
9181 | /// |
9182 | /// \param Arg The template argument preceding the ellipsis, which |
9183 | /// may already be invalid. |
9184 | /// |
9185 | /// \param EllipsisLoc The location of the ellipsis. |
9186 | ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, |
9187 | SourceLocation EllipsisLoc); |
9188 | |
9189 | /// Invoked when parsing a type followed by an ellipsis, which |
9190 | /// creates a pack expansion. |
9191 | /// |
9192 | /// \param Type The type preceding the ellipsis, which will become |
9193 | /// the pattern of the pack expansion. |
9194 | /// |
9195 | /// \param EllipsisLoc The location of the ellipsis. |
9196 | TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); |
9197 | |
9198 | /// Construct a pack expansion type from the pattern of the pack |
9199 | /// expansion. |
9200 | TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, |
9201 | SourceLocation EllipsisLoc, |
9202 | std::optional<unsigned> NumExpansions); |
9203 | |
9204 | /// Construct a pack expansion type from the pattern of the pack |
9205 | /// expansion. |
9206 | QualType CheckPackExpansion(QualType Pattern, SourceRange PatternRange, |
9207 | SourceLocation EllipsisLoc, |
9208 | std::optional<unsigned> NumExpansions); |
9209 | |
9210 | /// Invoked when parsing an expression followed by an ellipsis, which |
9211 | /// creates a pack expansion. |
9212 | /// |
9213 | /// \param Pattern The expression preceding the ellipsis, which will become |
9214 | /// the pattern of the pack expansion. |
9215 | /// |
9216 | /// \param EllipsisLoc The location of the ellipsis. |
9217 | ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); |
9218 | |
9219 | /// Invoked when parsing an expression followed by an ellipsis, which |
9220 | /// creates a pack expansion. |
9221 | /// |
9222 | /// \param Pattern The expression preceding the ellipsis, which will become |
9223 | /// the pattern of the pack expansion. |
9224 | /// |
9225 | /// \param EllipsisLoc The location of the ellipsis. |
9226 | ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
9227 | std::optional<unsigned> NumExpansions); |
9228 | |
9229 | /// Determine whether we could expand a pack expansion with the |
9230 | /// given set of parameter packs into separate arguments by repeatedly |
9231 | /// transforming the pattern. |
9232 | /// |
9233 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
9234 | /// pack expansion. |
9235 | /// |
9236 | /// \param PatternRange The source range that covers the entire pattern of |
9237 | /// the pack expansion. |
9238 | /// |
9239 | /// \param Unexpanded The set of unexpanded parameter packs within the |
9240 | /// pattern. |
9241 | /// |
9242 | /// \param ShouldExpand Will be set to \c true if the transformer should |
9243 | /// expand the corresponding pack expansions into separate arguments. When |
9244 | /// set, \c NumExpansions must also be set. |
9245 | /// |
9246 | /// \param RetainExpansion Whether the caller should add an unexpanded |
9247 | /// pack expansion after all of the expanded arguments. This is used |
9248 | /// when extending explicitly-specified template argument packs per |
9249 | /// C++0x [temp.arg.explicit]p9. |
9250 | /// |
9251 | /// \param NumExpansions The number of separate arguments that will be in |
9252 | /// the expanded form of the corresponding pack expansion. This is both an |
9253 | /// input and an output parameter, which can be set by the caller if the |
9254 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
9255 | /// and will be set by the callee when the number of expansions is known. |
9256 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
9257 | /// set this value in other cases. |
9258 | /// |
9259 | /// \returns true if an error occurred (e.g., because the parameter packs |
9260 | /// are to be instantiated with arguments of different lengths), false |
9261 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
9262 | /// must be set. |
9263 | bool CheckParameterPacksForExpansion( |
9264 | SourceLocation EllipsisLoc, SourceRange PatternRange, |
9265 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
9266 | const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand, |
9267 | bool &RetainExpansion, std::optional<unsigned> &NumExpansions); |
9268 | |
9269 | /// Determine the number of arguments in the given pack expansion |
9270 | /// type. |
9271 | /// |
9272 | /// This routine assumes that the number of arguments in the expansion is |
9273 | /// consistent across all of the unexpanded parameter packs in its pattern. |
9274 | /// |
9275 | /// Returns an empty Optional if the type can't be expanded. |
9276 | std::optional<unsigned> getNumArgumentsInExpansion( |
9277 | QualType T, const MultiLevelTemplateArgumentList &TemplateArgs); |
9278 | |
9279 | /// Determine whether the given declarator contains any unexpanded |
9280 | /// parameter packs. |
9281 | /// |
9282 | /// This routine is used by the parser to disambiguate function declarators |
9283 | /// with an ellipsis prior to the ')', e.g., |
9284 | /// |
9285 | /// \code |
9286 | /// void f(T...); |
9287 | /// \endcode |
9288 | /// |
9289 | /// To determine whether we have an (unnamed) function parameter pack or |
9290 | /// a variadic function. |
9291 | /// |
9292 | /// \returns true if the declarator contains any unexpanded parameter packs, |
9293 | /// false otherwise. |
9294 | bool containsUnexpandedParameterPacks(Declarator &D); |
9295 | |
9296 | /// Returns the pattern of the pack expansion for a template argument. |
9297 | /// |
9298 | /// \param OrigLoc The template argument to expand. |
9299 | /// |
9300 | /// \param Ellipsis Will be set to the location of the ellipsis. |
9301 | /// |
9302 | /// \param NumExpansions Will be set to the number of expansions that will |
9303 | /// be generated from this pack expansion, if known a priori. |
9304 | TemplateArgumentLoc getTemplateArgumentPackExpansionPattern( |
9305 | TemplateArgumentLoc OrigLoc, SourceLocation &Ellipsis, |
9306 | std::optional<unsigned> &NumExpansions) const; |
9307 | |
9308 | /// Given a template argument that contains an unexpanded parameter pack, but |
9309 | /// which has already been substituted, attempt to determine the number of |
9310 | /// elements that will be produced once this argument is fully-expanded. |
9311 | /// |
9312 | /// This is intended for use when transforming 'sizeof...(Arg)' in order to |
9313 | /// avoid actually expanding the pack where possible. |
9314 | std::optional<unsigned> getFullyPackExpandedSize(TemplateArgument Arg); |
9315 | |
9316 | //===--------------------------------------------------------------------===// |
9317 | // C++ Template Argument Deduction (C++ [temp.deduct]) |
9318 | //===--------------------------------------------------------------------===// |
9319 | |
9320 | /// Adjust the type \p ArgFunctionType to match the calling convention, |
9321 | /// noreturn, and optionally the exception specification of \p FunctionType. |
9322 | /// Deduction often wants to ignore these properties when matching function |
9323 | /// types. |
9324 | QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType, |
9325 | bool AdjustExceptionSpec = false); |
9326 | |
9327 | TemplateDeductionResult |
9328 | DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, |
9329 | ArrayRef<TemplateArgument> TemplateArgs, |
9330 | sema::TemplateDeductionInfo &Info); |
9331 | |
9332 | TemplateDeductionResult |
9333 | DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, |
9334 | ArrayRef<TemplateArgument> TemplateArgs, |
9335 | sema::TemplateDeductionInfo &Info); |
9336 | |
9337 | TemplateDeductionResult SubstituteExplicitTemplateArguments( |
9338 | FunctionTemplateDecl *FunctionTemplate, |
9339 | TemplateArgumentListInfo &ExplicitTemplateArgs, |
9340 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
9341 | SmallVectorImpl<QualType> &ParamTypes, QualType *FunctionType, |
9342 | sema::TemplateDeductionInfo &Info); |
9343 | |
9344 | /// brief A function argument from which we performed template argument |
9345 | // deduction for a call. |
9346 | struct OriginalCallArg { |
9347 | OriginalCallArg(QualType OriginalParamType, bool DecomposedParam, |
9348 | unsigned ArgIdx, QualType OriginalArgType) |
9349 | : OriginalParamType(OriginalParamType), |
9350 | DecomposedParam(DecomposedParam), ArgIdx(ArgIdx), |
9351 | OriginalArgType(OriginalArgType) {} |
9352 | |
9353 | QualType OriginalParamType; |
9354 | bool DecomposedParam; |
9355 | unsigned ArgIdx; |
9356 | QualType OriginalArgType; |
9357 | }; |
9358 | |
9359 | TemplateDeductionResult FinishTemplateArgumentDeduction( |
9360 | FunctionTemplateDecl *FunctionTemplate, |
9361 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
9362 | unsigned NumExplicitlySpecified, FunctionDecl *&Specialization, |
9363 | sema::TemplateDeductionInfo &Info, |
9364 | SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = nullptr, |
9365 | bool PartialOverloading = false, |
9366 | llvm::function_ref<bool()> CheckNonDependent = []{ return false; }); |
9367 | |
9368 | TemplateDeductionResult DeduceTemplateArguments( |
9369 | FunctionTemplateDecl *FunctionTemplate, |
9370 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
9371 | FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, |
9372 | bool PartialOverloading, bool AggregateDeductionCandidate, |
9373 | QualType ObjectType, Expr::Classification ObjectClassification, |
9374 | llvm::function_ref<bool(ArrayRef<QualType>)> CheckNonDependent); |
9375 | |
9376 | TemplateDeductionResult |
9377 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
9378 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
9379 | QualType ArgFunctionType, |
9380 | FunctionDecl *&Specialization, |
9381 | sema::TemplateDeductionInfo &Info, |
9382 | bool IsAddressOfFunction = false); |
9383 | |
9384 | TemplateDeductionResult DeduceTemplateArguments( |
9385 | FunctionTemplateDecl *FunctionTemplate, QualType ObjectType, |
9386 | Expr::Classification ObjectClassification, QualType ToType, |
9387 | CXXConversionDecl *&Specialization, sema::TemplateDeductionInfo &Info); |
9388 | |
9389 | TemplateDeductionResult |
9390 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
9391 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
9392 | FunctionDecl *&Specialization, |
9393 | sema::TemplateDeductionInfo &Info, |
9394 | bool IsAddressOfFunction = false); |
9395 | |
9396 | /// Substitute Replacement for \p auto in \p TypeWithAuto |
9397 | QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement); |
9398 | /// Substitute Replacement for auto in TypeWithAuto |
9399 | TypeSourceInfo* SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
9400 | QualType Replacement); |
9401 | |
9402 | // Substitute auto in TypeWithAuto for a Dependent auto type |
9403 | QualType SubstAutoTypeDependent(QualType TypeWithAuto); |
9404 | |
9405 | // Substitute auto in TypeWithAuto for a Dependent auto type |
9406 | TypeSourceInfo * |
9407 | SubstAutoTypeSourceInfoDependent(TypeSourceInfo *TypeWithAuto); |
9408 | |
9409 | /// Completely replace the \c auto in \p TypeWithAuto by |
9410 | /// \p Replacement. This does not retain any \c auto type sugar. |
9411 | QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement); |
9412 | TypeSourceInfo *ReplaceAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
9413 | QualType Replacement); |
9414 | |
9415 | TemplateDeductionResult |
9416 | DeduceAutoType(TypeLoc AutoTypeLoc, Expr *Initializer, QualType &Result, |
9417 | sema::TemplateDeductionInfo &Info, |
9418 | bool DependentDeduction = false, |
9419 | bool IgnoreConstraints = false, |
9420 | TemplateSpecCandidateSet *FailedTSC = nullptr); |
9421 | void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init); |
9422 | bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc, |
9423 | bool Diagnose = true); |
9424 | |
9425 | bool CheckIfFunctionSpecializationIsImmediate(FunctionDecl *FD, |
9426 | SourceLocation Loc); |
9427 | |
9428 | /// Declare implicit deduction guides for a class template if we've |
9429 | /// not already done so. |
9430 | void DeclareImplicitDeductionGuides(TemplateDecl *Template, |
9431 | SourceLocation Loc); |
9432 | FunctionTemplateDecl *DeclareImplicitDeductionGuideFromInitList( |
9433 | TemplateDecl *Template, MutableArrayRef<QualType> ParamTypes, |
9434 | SourceLocation Loc); |
9435 | llvm::DenseMap<unsigned, CXXDeductionGuideDecl *> |
9436 | AggregateDeductionCandidates; |
9437 | |
9438 | QualType DeduceTemplateSpecializationFromInitializer( |
9439 | TypeSourceInfo *TInfo, const InitializedEntity &Entity, |
9440 | const InitializationKind &Kind, MultiExprArg Init); |
9441 | |
9442 | QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name, |
9443 | QualType Type, TypeSourceInfo *TSI, |
9444 | SourceRange Range, bool DirectInit, |
9445 | Expr *Init); |
9446 | |
9447 | TypeLoc getReturnTypeLoc(FunctionDecl *FD) const; |
9448 | |
9449 | bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD, |
9450 | SourceLocation ReturnLoc, Expr *RetExpr, |
9451 | const AutoType *AT); |
9452 | |
9453 | FunctionTemplateDecl *getMoreSpecializedTemplate( |
9454 | FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc, |
9455 | TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1, |
9456 | unsigned NumCallArguments2, bool Reversed = false); |
9457 | UnresolvedSetIterator |
9458 | getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd, |
9459 | TemplateSpecCandidateSet &FailedCandidates, |
9460 | SourceLocation Loc, |
9461 | const PartialDiagnostic &NoneDiag, |
9462 | const PartialDiagnostic &AmbigDiag, |
9463 | const PartialDiagnostic &CandidateDiag, |
9464 | bool Complain = true, QualType TargetType = QualType()); |
9465 | |
9466 | ClassTemplatePartialSpecializationDecl * |
9467 | getMoreSpecializedPartialSpecialization( |
9468 | ClassTemplatePartialSpecializationDecl *PS1, |
9469 | ClassTemplatePartialSpecializationDecl *PS2, |
9470 | SourceLocation Loc); |
9471 | |
9472 | bool isMoreSpecializedThanPrimary(ClassTemplatePartialSpecializationDecl *T, |
9473 | sema::TemplateDeductionInfo &Info); |
9474 | |
9475 | VarTemplatePartialSpecializationDecl *getMoreSpecializedPartialSpecialization( |
9476 | VarTemplatePartialSpecializationDecl *PS1, |
9477 | VarTemplatePartialSpecializationDecl *PS2, SourceLocation Loc); |
9478 | |
9479 | bool isMoreSpecializedThanPrimary(VarTemplatePartialSpecializationDecl *T, |
9480 | sema::TemplateDeductionInfo &Info); |
9481 | |
9482 | bool isTemplateTemplateParameterAtLeastAsSpecializedAs( |
9483 | TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc); |
9484 | |
9485 | void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced, |
9486 | unsigned Depth, llvm::SmallBitVector &Used); |
9487 | |
9488 | void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, |
9489 | bool OnlyDeduced, |
9490 | unsigned Depth, |
9491 | llvm::SmallBitVector &Used); |
9492 | void MarkDeducedTemplateParameters( |
9493 | const FunctionTemplateDecl *FunctionTemplate, |
9494 | llvm::SmallBitVector &Deduced) { |
9495 | return MarkDeducedTemplateParameters(Ctx&: Context, FunctionTemplate, Deduced); |
9496 | } |
9497 | static void MarkDeducedTemplateParameters(ASTContext &Ctx, |
9498 | const FunctionTemplateDecl *FunctionTemplate, |
9499 | llvm::SmallBitVector &Deduced); |
9500 | |
9501 | //===--------------------------------------------------------------------===// |
9502 | // C++ Template Instantiation |
9503 | // |
9504 | |
9505 | MultiLevelTemplateArgumentList getTemplateInstantiationArgs( |
9506 | const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false, |
9507 | std::optional<ArrayRef<TemplateArgument>> Innermost = std::nullopt, |
9508 | bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr, |
9509 | bool ForConstraintInstantiation = false, |
9510 | bool SkipForSpecialization = false); |
9511 | |
9512 | /// A context in which code is being synthesized (where a source location |
9513 | /// alone is not sufficient to identify the context). This covers template |
9514 | /// instantiation and various forms of implicitly-generated functions. |
9515 | struct CodeSynthesisContext { |
9516 | /// The kind of template instantiation we are performing |
9517 | enum SynthesisKind { |
9518 | /// We are instantiating a template declaration. The entity is |
9519 | /// the declaration we're instantiating (e.g., a CXXRecordDecl). |
9520 | TemplateInstantiation, |
9521 | |
9522 | /// We are instantiating a default argument for a template |
9523 | /// parameter. The Entity is the template parameter whose argument is |
9524 | /// being instantiated, the Template is the template, and the |
9525 | /// TemplateArgs/NumTemplateArguments provide the template arguments as |
9526 | /// specified. |
9527 | DefaultTemplateArgumentInstantiation, |
9528 | |
9529 | /// We are instantiating a default argument for a function. |
9530 | /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs |
9531 | /// provides the template arguments as specified. |
9532 | DefaultFunctionArgumentInstantiation, |
9533 | |
9534 | /// We are substituting explicit template arguments provided for |
9535 | /// a function template. The entity is a FunctionTemplateDecl. |
9536 | ExplicitTemplateArgumentSubstitution, |
9537 | |
9538 | /// We are substituting template argument determined as part of |
9539 | /// template argument deduction for either a class template |
9540 | /// partial specialization or a function template. The |
9541 | /// Entity is either a {Class|Var}TemplatePartialSpecializationDecl or |
9542 | /// a TemplateDecl. |
9543 | DeducedTemplateArgumentSubstitution, |
9544 | |
9545 | /// We are substituting into a lambda expression. |
9546 | LambdaExpressionSubstitution, |
9547 | |
9548 | /// We are substituting prior template arguments into a new |
9549 | /// template parameter. The template parameter itself is either a |
9550 | /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. |
9551 | PriorTemplateArgumentSubstitution, |
9552 | |
9553 | /// We are checking the validity of a default template argument that |
9554 | /// has been used when naming a template-id. |
9555 | DefaultTemplateArgumentChecking, |
9556 | |
9557 | /// We are computing the exception specification for a defaulted special |
9558 | /// member function. |
9559 | ExceptionSpecEvaluation, |
9560 | |
9561 | /// We are instantiating the exception specification for a function |
9562 | /// template which was deferred until it was needed. |
9563 | ExceptionSpecInstantiation, |
9564 | |
9565 | /// We are instantiating a requirement of a requires expression. |
9566 | RequirementInstantiation, |
9567 | |
9568 | /// We are checking the satisfaction of a nested requirement of a requires |
9569 | /// expression. |
9570 | NestedRequirementConstraintsCheck, |
9571 | |
9572 | /// We are declaring an implicit special member function. |
9573 | DeclaringSpecialMember, |
9574 | |
9575 | /// We are declaring an implicit 'operator==' for a defaulted |
9576 | /// 'operator<=>'. |
9577 | DeclaringImplicitEqualityComparison, |
9578 | |
9579 | /// We are defining a synthesized function (such as a defaulted special |
9580 | /// member). |
9581 | DefiningSynthesizedFunction, |
9582 | |
9583 | // We are checking the constraints associated with a constrained entity or |
9584 | // the constraint expression of a concept. This includes the checks that |
9585 | // atomic constraints have the type 'bool' and that they can be constant |
9586 | // evaluated. |
9587 | ConstraintsCheck, |
9588 | |
9589 | // We are substituting template arguments into a constraint expression. |
9590 | ConstraintSubstitution, |
9591 | |
9592 | // We are normalizing a constraint expression. |
9593 | ConstraintNormalization, |
9594 | |
9595 | // Instantiating a Requires Expression parameter clause. |
9596 | RequirementParameterInstantiation, |
9597 | |
9598 | // We are substituting into the parameter mapping of an atomic constraint |
9599 | // during normalization. |
9600 | ParameterMappingSubstitution, |
9601 | |
9602 | /// We are rewriting a comparison operator in terms of an operator<=>. |
9603 | RewritingOperatorAsSpaceship, |
9604 | |
9605 | /// We are initializing a structured binding. |
9606 | InitializingStructuredBinding, |
9607 | |
9608 | /// We are marking a class as __dllexport. |
9609 | MarkingClassDllexported, |
9610 | |
9611 | /// We are building an implied call from __builtin_dump_struct. The |
9612 | /// arguments are in CallArgs. |
9613 | BuildingBuiltinDumpStructCall, |
9614 | |
9615 | /// Added for Template instantiation observation. |
9616 | /// Memoization means we are _not_ instantiating a template because |
9617 | /// it is already instantiated (but we entered a context where we |
9618 | /// would have had to if it was not already instantiated). |
9619 | Memoization, |
9620 | |
9621 | /// We are building deduction guides for a class. |
9622 | BuildingDeductionGuides, |
9623 | } Kind; |
9624 | |
9625 | /// Was the enclosing context a non-instantiation SFINAE context? |
9626 | bool SavedInNonInstantiationSFINAEContext; |
9627 | |
9628 | /// The point of instantiation or synthesis within the source code. |
9629 | SourceLocation PointOfInstantiation; |
9630 | |
9631 | /// The entity that is being synthesized. |
9632 | Decl *Entity; |
9633 | |
9634 | /// The template (or partial specialization) in which we are |
9635 | /// performing the instantiation, for substitutions of prior template |
9636 | /// arguments. |
9637 | NamedDecl *Template; |
9638 | |
9639 | union { |
9640 | /// The list of template arguments we are substituting, if they |
9641 | /// are not part of the entity. |
9642 | const TemplateArgument *TemplateArgs; |
9643 | |
9644 | /// The list of argument expressions in a synthesized call. |
9645 | const Expr *const *CallArgs; |
9646 | }; |
9647 | |
9648 | // FIXME: Wrap this union around more members, or perhaps store the |
9649 | // kind-specific members in the RAII object owning the context. |
9650 | union { |
9651 | /// The number of template arguments in TemplateArgs. |
9652 | unsigned NumTemplateArgs; |
9653 | |
9654 | /// The number of expressions in CallArgs. |
9655 | unsigned NumCallArgs; |
9656 | |
9657 | /// The special member being declared or defined. |
9658 | CXXSpecialMember SpecialMember; |
9659 | }; |
9660 | |
9661 | ArrayRef<TemplateArgument> template_arguments() const { |
9662 | assert(Kind != DeclaringSpecialMember); |
9663 | return {TemplateArgs, NumTemplateArgs}; |
9664 | } |
9665 | |
9666 | /// The template deduction info object associated with the |
9667 | /// substitution or checking of explicit or deduced template arguments. |
9668 | sema::TemplateDeductionInfo *DeductionInfo; |
9669 | |
9670 | /// The source range that covers the construct that cause |
9671 | /// the instantiation, e.g., the template-id that causes a class |
9672 | /// template instantiation. |
9673 | SourceRange InstantiationRange; |
9674 | |
9675 | CodeSynthesisContext() |
9676 | : Kind(TemplateInstantiation), |
9677 | SavedInNonInstantiationSFINAEContext(false), Entity(nullptr), |
9678 | Template(nullptr), TemplateArgs(nullptr), NumTemplateArgs(0), |
9679 | DeductionInfo(nullptr) {} |
9680 | |
9681 | /// Determines whether this template is an actual instantiation |
9682 | /// that should be counted toward the maximum instantiation depth. |
9683 | bool isInstantiationRecord() const; |
9684 | }; |
9685 | |
9686 | /// List of active code synthesis contexts. |
9687 | /// |
9688 | /// This vector is treated as a stack. As synthesis of one entity requires |
9689 | /// synthesis of another, additional contexts are pushed onto the stack. |
9690 | SmallVector<CodeSynthesisContext, 16> CodeSynthesisContexts; |
9691 | |
9692 | /// Specializations whose definitions are currently being instantiated. |
9693 | llvm::DenseSet<std::pair<Decl *, unsigned>> InstantiatingSpecializations; |
9694 | |
9695 | /// Non-dependent types used in templates that have already been instantiated |
9696 | /// by some template instantiation. |
9697 | llvm::DenseSet<QualType> InstantiatedNonDependentTypes; |
9698 | |
9699 | /// Extra modules inspected when performing a lookup during a template |
9700 | /// instantiation. Computed lazily. |
9701 | SmallVector<Module*, 16> CodeSynthesisContextLookupModules; |
9702 | |
9703 | /// Cache of additional modules that should be used for name lookup |
9704 | /// within the current template instantiation. Computed lazily; use |
9705 | /// getLookupModules() to get a complete set. |
9706 | llvm::DenseSet<Module*> LookupModulesCache; |
9707 | |
9708 | /// Get the set of additional modules that should be checked during |
9709 | /// name lookup. A module and its imports become visible when instanting a |
9710 | /// template defined within it. |
9711 | llvm::DenseSet<Module*> &getLookupModules(); |
9712 | |
9713 | /// Map from the most recent declaration of a namespace to the most |
9714 | /// recent visible declaration of that namespace. |
9715 | llvm::DenseMap<NamedDecl*, NamedDecl*> VisibleNamespaceCache; |
9716 | |
9717 | /// Whether we are in a SFINAE context that is not associated with |
9718 | /// template instantiation. |
9719 | /// |
9720 | /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside |
9721 | /// of a template instantiation or template argument deduction. |
9722 | bool InNonInstantiationSFINAEContext; |
9723 | |
9724 | /// The number of \p CodeSynthesisContexts that are not template |
9725 | /// instantiations and, therefore, should not be counted as part of the |
9726 | /// instantiation depth. |
9727 | /// |
9728 | /// When the instantiation depth reaches the user-configurable limit |
9729 | /// \p LangOptions::InstantiationDepth we will abort instantiation. |
9730 | // FIXME: Should we have a similar limit for other forms of synthesis? |
9731 | unsigned NonInstantiationEntries; |
9732 | |
9733 | /// The depth of the context stack at the point when the most recent |
9734 | /// error or warning was produced. |
9735 | /// |
9736 | /// This value is used to suppress printing of redundant context stacks |
9737 | /// when there are multiple errors or warnings in the same instantiation. |
9738 | // FIXME: Does this belong in Sema? It's tough to implement it anywhere else. |
9739 | unsigned LastEmittedCodeSynthesisContextDepth = 0; |
9740 | |
9741 | /// The template instantiation callbacks to trace or track |
9742 | /// instantiations (objects can be chained). |
9743 | /// |
9744 | /// This callbacks is used to print, trace or track template |
9745 | /// instantiations as they are being constructed. |
9746 | std::vector<std::unique_ptr<TemplateInstantiationCallback>> |
9747 | TemplateInstCallbacks; |
9748 | |
9749 | /// The current index into pack expansion arguments that will be |
9750 | /// used for substitution of parameter packs. |
9751 | /// |
9752 | /// The pack expansion index will be -1 to indicate that parameter packs |
9753 | /// should be instantiated as themselves. Otherwise, the index specifies |
9754 | /// which argument within the parameter pack will be used for substitution. |
9755 | int ArgumentPackSubstitutionIndex; |
9756 | |
9757 | /// RAII object used to change the argument pack substitution index |
9758 | /// within a \c Sema object. |
9759 | /// |
9760 | /// See \c ArgumentPackSubstitutionIndex for more information. |
9761 | class ArgumentPackSubstitutionIndexRAII { |
9762 | Sema &Self; |
9763 | int OldSubstitutionIndex; |
9764 | |
9765 | public: |
9766 | ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) |
9767 | : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { |
9768 | Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; |
9769 | } |
9770 | |
9771 | ~ArgumentPackSubstitutionIndexRAII() { |
9772 | Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; |
9773 | } |
9774 | }; |
9775 | |
9776 | friend class ArgumentPackSubstitutionRAII; |
9777 | |
9778 | /// For each declaration that involved template argument deduction, the |
9779 | /// set of diagnostics that were suppressed during that template argument |
9780 | /// deduction. |
9781 | /// |
9782 | /// FIXME: Serialize this structure to the AST file. |
9783 | typedef llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> > |
9784 | SuppressedDiagnosticsMap; |
9785 | SuppressedDiagnosticsMap SuppressedDiagnostics; |
9786 | |
9787 | /// A stack object to be created when performing template |
9788 | /// instantiation. |
9789 | /// |
9790 | /// Construction of an object of type \c InstantiatingTemplate |
9791 | /// pushes the current instantiation onto the stack of active |
9792 | /// instantiations. If the size of this stack exceeds the maximum |
9793 | /// number of recursive template instantiations, construction |
9794 | /// produces an error and evaluates true. |
9795 | /// |
9796 | /// Destruction of this object will pop the named instantiation off |
9797 | /// the stack. |
9798 | struct InstantiatingTemplate { |
9799 | /// Note that we are instantiating a class template, |
9800 | /// function template, variable template, alias template, |
9801 | /// or a member thereof. |
9802 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9803 | Decl *Entity, |
9804 | SourceRange InstantiationRange = SourceRange()); |
9805 | |
9806 | struct ExceptionSpecification {}; |
9807 | /// Note that we are instantiating an exception specification |
9808 | /// of a function template. |
9809 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9810 | FunctionDecl *Entity, ExceptionSpecification, |
9811 | SourceRange InstantiationRange = SourceRange()); |
9812 | |
9813 | /// Note that we are instantiating a default argument in a |
9814 | /// template-id. |
9815 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9816 | TemplateParameter Param, TemplateDecl *Template, |
9817 | ArrayRef<TemplateArgument> TemplateArgs, |
9818 | SourceRange InstantiationRange = SourceRange()); |
9819 | |
9820 | /// Note that we are substituting either explicitly-specified or |
9821 | /// deduced template arguments during function template argument deduction. |
9822 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9823 | FunctionTemplateDecl *FunctionTemplate, |
9824 | ArrayRef<TemplateArgument> TemplateArgs, |
9825 | CodeSynthesisContext::SynthesisKind Kind, |
9826 | sema::TemplateDeductionInfo &DeductionInfo, |
9827 | SourceRange InstantiationRange = SourceRange()); |
9828 | |
9829 | /// Note that we are instantiating as part of template |
9830 | /// argument deduction for a class template declaration. |
9831 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9832 | TemplateDecl *Template, |
9833 | ArrayRef<TemplateArgument> TemplateArgs, |
9834 | sema::TemplateDeductionInfo &DeductionInfo, |
9835 | SourceRange InstantiationRange = SourceRange()); |
9836 | |
9837 | /// Note that we are instantiating as part of template |
9838 | /// argument deduction for a class template partial |
9839 | /// specialization. |
9840 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9841 | ClassTemplatePartialSpecializationDecl *PartialSpec, |
9842 | ArrayRef<TemplateArgument> TemplateArgs, |
9843 | sema::TemplateDeductionInfo &DeductionInfo, |
9844 | SourceRange InstantiationRange = SourceRange()); |
9845 | |
9846 | /// Note that we are instantiating as part of template |
9847 | /// argument deduction for a variable template partial |
9848 | /// specialization. |
9849 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9850 | VarTemplatePartialSpecializationDecl *PartialSpec, |
9851 | ArrayRef<TemplateArgument> TemplateArgs, |
9852 | sema::TemplateDeductionInfo &DeductionInfo, |
9853 | SourceRange InstantiationRange = SourceRange()); |
9854 | |
9855 | /// Note that we are instantiating a default argument for a function |
9856 | /// parameter. |
9857 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9858 | ParmVarDecl *Param, |
9859 | ArrayRef<TemplateArgument> TemplateArgs, |
9860 | SourceRange InstantiationRange = SourceRange()); |
9861 | |
9862 | /// Note that we are substituting prior template arguments into a |
9863 | /// non-type parameter. |
9864 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9865 | NamedDecl *Template, |
9866 | NonTypeTemplateParmDecl *Param, |
9867 | ArrayRef<TemplateArgument> TemplateArgs, |
9868 | SourceRange InstantiationRange); |
9869 | |
9870 | /// Note that we are substituting prior template arguments into a |
9871 | /// template template parameter. |
9872 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9873 | NamedDecl *Template, |
9874 | TemplateTemplateParmDecl *Param, |
9875 | ArrayRef<TemplateArgument> TemplateArgs, |
9876 | SourceRange InstantiationRange); |
9877 | |
9878 | /// Note that we are checking the default template argument |
9879 | /// against the template parameter for a given template-id. |
9880 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9881 | TemplateDecl *Template, |
9882 | NamedDecl *Param, |
9883 | ArrayRef<TemplateArgument> TemplateArgs, |
9884 | SourceRange InstantiationRange); |
9885 | |
9886 | struct ConstraintsCheck {}; |
9887 | /// \brief Note that we are checking the constraints associated with some |
9888 | /// constrained entity (a concept declaration or a template with associated |
9889 | /// constraints). |
9890 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9891 | ConstraintsCheck, NamedDecl *Template, |
9892 | ArrayRef<TemplateArgument> TemplateArgs, |
9893 | SourceRange InstantiationRange); |
9894 | |
9895 | struct ConstraintSubstitution {}; |
9896 | /// \brief Note that we are checking a constraint expression associated |
9897 | /// with a template declaration or as part of the satisfaction check of a |
9898 | /// concept. |
9899 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9900 | ConstraintSubstitution, NamedDecl *Template, |
9901 | sema::TemplateDeductionInfo &DeductionInfo, |
9902 | SourceRange InstantiationRange); |
9903 | |
9904 | struct ConstraintNormalization {}; |
9905 | /// \brief Note that we are normalizing a constraint expression. |
9906 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9907 | ConstraintNormalization, NamedDecl *Template, |
9908 | SourceRange InstantiationRange); |
9909 | |
9910 | struct ParameterMappingSubstitution {}; |
9911 | /// \brief Note that we are subtituting into the parameter mapping of an |
9912 | /// atomic constraint during constraint normalization. |
9913 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9914 | ParameterMappingSubstitution, NamedDecl *Template, |
9915 | SourceRange InstantiationRange); |
9916 | |
9917 | /// \brief Note that we are substituting template arguments into a part of |
9918 | /// a requirement of a requires expression. |
9919 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9920 | concepts::Requirement *Req, |
9921 | sema::TemplateDeductionInfo &DeductionInfo, |
9922 | SourceRange InstantiationRange = SourceRange()); |
9923 | |
9924 | /// \brief Note that we are checking the satisfaction of the constraint |
9925 | /// expression inside of a nested requirement. |
9926 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9927 | concepts::NestedRequirement *Req, ConstraintsCheck, |
9928 | SourceRange InstantiationRange = SourceRange()); |
9929 | |
9930 | /// \brief Note that we are checking a requires clause. |
9931 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9932 | const RequiresExpr *E, |
9933 | sema::TemplateDeductionInfo &DeductionInfo, |
9934 | SourceRange InstantiationRange); |
9935 | |
9936 | struct BuildingDeductionGuidesTag {}; |
9937 | /// \brief Note that we are building deduction guides. |
9938 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9939 | TemplateDecl *Entity, BuildingDeductionGuidesTag, |
9940 | SourceRange InstantiationRange = SourceRange()); |
9941 | |
9942 | /// Note that we have finished instantiating this template. |
9943 | void Clear(); |
9944 | |
9945 | ~InstantiatingTemplate() { Clear(); } |
9946 | |
9947 | /// Determines whether we have exceeded the maximum |
9948 | /// recursive template instantiations. |
9949 | bool isInvalid() const { return Invalid; } |
9950 | |
9951 | /// Determine whether we are already instantiating this |
9952 | /// specialization in some surrounding active instantiation. |
9953 | bool isAlreadyInstantiating() const { return AlreadyInstantiating; } |
9954 | |
9955 | private: |
9956 | Sema &SemaRef; |
9957 | bool Invalid; |
9958 | bool AlreadyInstantiating; |
9959 | bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, |
9960 | SourceRange InstantiationRange); |
9961 | |
9962 | InstantiatingTemplate( |
9963 | Sema &SemaRef, CodeSynthesisContext::SynthesisKind Kind, |
9964 | SourceLocation PointOfInstantiation, SourceRange InstantiationRange, |
9965 | Decl *Entity, NamedDecl *Template = nullptr, |
9966 | ArrayRef<TemplateArgument> TemplateArgs = std::nullopt, |
9967 | sema::TemplateDeductionInfo *DeductionInfo = nullptr); |
9968 | |
9969 | InstantiatingTemplate(const InstantiatingTemplate&) = delete; |
9970 | |
9971 | InstantiatingTemplate& |
9972 | operator=(const InstantiatingTemplate&) = delete; |
9973 | }; |
9974 | |
9975 | void pushCodeSynthesisContext(CodeSynthesisContext Ctx); |
9976 | void popCodeSynthesisContext(); |
9977 | |
9978 | /// Determine whether we are currently performing template instantiation. |
9979 | bool inTemplateInstantiation() const { |
9980 | return CodeSynthesisContexts.size() > NonInstantiationEntries; |
9981 | } |
9982 | |
9983 | void PrintContextStack() { |
9984 | if (!CodeSynthesisContexts.empty() && |
9985 | CodeSynthesisContexts.size() != LastEmittedCodeSynthesisContextDepth) { |
9986 | PrintInstantiationStack(); |
9987 | LastEmittedCodeSynthesisContextDepth = CodeSynthesisContexts.size(); |
9988 | } |
9989 | if (PragmaAttributeCurrentTargetDecl) |
9990 | PrintPragmaAttributeInstantiationPoint(); |
9991 | } |
9992 | void PrintInstantiationStack(); |
9993 | |
9994 | void PrintPragmaAttributeInstantiationPoint(); |
9995 | |
9996 | /// Determines whether we are currently in a context where |
9997 | /// template argument substitution failures are not considered |
9998 | /// errors. |
9999 | /// |
10000 | /// \returns An empty \c Optional if we're not in a SFINAE context. |
10001 | /// Otherwise, contains a pointer that, if non-NULL, contains the nearest |
10002 | /// template-deduction context object, which can be used to capture |
10003 | /// diagnostics that will be suppressed. |
10004 | std::optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; |
10005 | |
10006 | /// Whether the AST is currently being rebuilt to correct immediate |
10007 | /// invocations. Immediate invocation candidates and references to consteval |
10008 | /// functions aren't tracked when this is set. |
10009 | bool RebuildingImmediateInvocation = false; |
10010 | |
10011 | /// Used to change context to isConstantEvaluated without pushing a heavy |
10012 | /// ExpressionEvaluationContextRecord object. |
10013 | bool isConstantEvaluatedOverride = false; |
10014 | |
10015 | const ExpressionEvaluationContextRecord ¤tEvaluationContext() const { |
10016 | assert(!ExprEvalContexts.empty() && |
10017 | "Must be in an expression evaluation context" ); |
10018 | return ExprEvalContexts.back(); |
10019 | }; |
10020 | |
10021 | bool isConstantEvaluatedContext() const { |
10022 | return currentEvaluationContext().isConstantEvaluated() || |
10023 | isConstantEvaluatedOverride; |
10024 | } |
10025 | |
10026 | bool isAlwaysConstantEvaluatedContext() const { |
10027 | const ExpressionEvaluationContextRecord &Ctx = currentEvaluationContext(); |
10028 | return (Ctx.isConstantEvaluated() || isConstantEvaluatedOverride) && |
10029 | !Ctx.InConditionallyConstantEvaluateContext; |
10030 | } |
10031 | |
10032 | /// Determines whether we are currently in a context that |
10033 | /// is not evaluated as per C++ [expr] p5. |
10034 | bool isUnevaluatedContext() const { |
10035 | return currentEvaluationContext().isUnevaluated(); |
10036 | } |
10037 | |
10038 | bool isImmediateFunctionContext() const { |
10039 | return currentEvaluationContext().isImmediateFunctionContext(); |
10040 | } |
10041 | |
10042 | bool isInLifetimeExtendingContext() const { |
10043 | assert(!ExprEvalContexts.empty() && |
10044 | "Must be in an expression evaluation context" ); |
10045 | return ExprEvalContexts.back().InLifetimeExtendingContext; |
10046 | } |
10047 | |
10048 | bool isInMaterializeTemporaryObjectContext() const { |
10049 | assert(!ExprEvalContexts.empty() && |
10050 | "Must be in an expression evaluation context" ); |
10051 | return ExprEvalContexts.back().InMaterializeTemporaryObjectContext; |
10052 | } |
10053 | |
10054 | bool isCheckingDefaultArgumentOrInitializer() const { |
10055 | const ExpressionEvaluationContextRecord &Ctx = currentEvaluationContext(); |
10056 | return (Ctx.Context == |
10057 | ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed) || |
10058 | Ctx.IsCurrentlyCheckingDefaultArgumentOrInitializer; |
10059 | } |
10060 | |
10061 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> |
10062 | InnermostDeclarationWithDelayedImmediateInvocations() const { |
10063 | assert(!ExprEvalContexts.empty() && |
10064 | "Must be in an expression evaluation context" ); |
10065 | for (const auto &Ctx : llvm::reverse(C: ExprEvalContexts)) { |
10066 | if (Ctx.Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
10067 | Ctx.DelayedDefaultInitializationContext) |
10068 | return Ctx.DelayedDefaultInitializationContext; |
10069 | if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() || |
10070 | Ctx.isUnevaluated()) |
10071 | break; |
10072 | } |
10073 | return std::nullopt; |
10074 | } |
10075 | |
10076 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> |
10077 | OutermostDeclarationWithDelayedImmediateInvocations() const { |
10078 | assert(!ExprEvalContexts.empty() && |
10079 | "Must be in an expression evaluation context" ); |
10080 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> Res; |
10081 | for (auto &Ctx : llvm::reverse(C: ExprEvalContexts)) { |
10082 | if (Ctx.Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
10083 | !Ctx.DelayedDefaultInitializationContext && Res) |
10084 | break; |
10085 | if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() || |
10086 | Ctx.isUnevaluated()) |
10087 | break; |
10088 | Res = Ctx.DelayedDefaultInitializationContext; |
10089 | } |
10090 | return Res; |
10091 | } |
10092 | |
10093 | /// keepInLifetimeExtendingContext - Pull down InLifetimeExtendingContext |
10094 | /// flag from previous context. |
10095 | void keepInLifetimeExtendingContext() { |
10096 | if (ExprEvalContexts.size() > 2 && |
10097 | ExprEvalContexts[ExprEvalContexts.size() - 2] |
10098 | .InLifetimeExtendingContext) { |
10099 | auto &LastRecord = ExprEvalContexts.back(); |
10100 | auto &PrevRecord = ExprEvalContexts[ExprEvalContexts.size() - 2]; |
10101 | LastRecord.InLifetimeExtendingContext = |
10102 | PrevRecord.InLifetimeExtendingContext; |
10103 | } |
10104 | } |
10105 | |
10106 | /// keepInMaterializeTemporaryObjectContext - Pull down |
10107 | /// InMaterializeTemporaryObjectContext flag from previous context. |
10108 | void keepInMaterializeTemporaryObjectContext() { |
10109 | if (ExprEvalContexts.size() > 2 && |
10110 | ExprEvalContexts[ExprEvalContexts.size() - 2] |
10111 | .InMaterializeTemporaryObjectContext) { |
10112 | auto &LastRecord = ExprEvalContexts.back(); |
10113 | auto &PrevRecord = ExprEvalContexts[ExprEvalContexts.size() - 2]; |
10114 | LastRecord.InMaterializeTemporaryObjectContext = |
10115 | PrevRecord.InMaterializeTemporaryObjectContext; |
10116 | } |
10117 | } |
10118 | |
10119 | /// RAII class used to determine whether SFINAE has |
10120 | /// trapped any errors that occur during template argument |
10121 | /// deduction. |
10122 | class SFINAETrap { |
10123 | Sema &SemaRef; |
10124 | unsigned PrevSFINAEErrors; |
10125 | bool PrevInNonInstantiationSFINAEContext; |
10126 | bool PrevAccessCheckingSFINAE; |
10127 | bool PrevLastDiagnosticIgnored; |
10128 | |
10129 | public: |
10130 | explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) |
10131 | : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), |
10132 | PrevInNonInstantiationSFINAEContext( |
10133 | SemaRef.InNonInstantiationSFINAEContext), |
10134 | PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE), |
10135 | PrevLastDiagnosticIgnored( |
10136 | SemaRef.getDiagnostics().isLastDiagnosticIgnored()) |
10137 | { |
10138 | if (!SemaRef.isSFINAEContext()) |
10139 | SemaRef.InNonInstantiationSFINAEContext = true; |
10140 | SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; |
10141 | } |
10142 | |
10143 | ~SFINAETrap() { |
10144 | SemaRef.NumSFINAEErrors = PrevSFINAEErrors; |
10145 | SemaRef.InNonInstantiationSFINAEContext |
10146 | = PrevInNonInstantiationSFINAEContext; |
10147 | SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; |
10148 | SemaRef.getDiagnostics().setLastDiagnosticIgnored( |
10149 | PrevLastDiagnosticIgnored); |
10150 | } |
10151 | |
10152 | /// Determine whether any SFINAE errors have been trapped. |
10153 | bool hasErrorOccurred() const { |
10154 | return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; |
10155 | } |
10156 | }; |
10157 | |
10158 | /// RAII class used to indicate that we are performing provisional |
10159 | /// semantic analysis to determine the validity of a construct, so |
10160 | /// typo-correction and diagnostics in the immediate context (not within |
10161 | /// implicitly-instantiated templates) should be suppressed. |
10162 | class TentativeAnalysisScope { |
10163 | Sema &SemaRef; |
10164 | // FIXME: Using a SFINAETrap for this is a hack. |
10165 | SFINAETrap Trap; |
10166 | bool PrevDisableTypoCorrection; |
10167 | public: |
10168 | explicit TentativeAnalysisScope(Sema &SemaRef) |
10169 | : SemaRef(SemaRef), Trap(SemaRef, true), |
10170 | PrevDisableTypoCorrection(SemaRef.DisableTypoCorrection) { |
10171 | SemaRef.DisableTypoCorrection = true; |
10172 | } |
10173 | ~TentativeAnalysisScope() { |
10174 | SemaRef.DisableTypoCorrection = PrevDisableTypoCorrection; |
10175 | } |
10176 | }; |
10177 | |
10178 | /// The current instantiation scope used to store local |
10179 | /// variables. |
10180 | LocalInstantiationScope *CurrentInstantiationScope; |
10181 | |
10182 | /// Tracks whether we are in a context where typo correction is |
10183 | /// disabled. |
10184 | bool DisableTypoCorrection; |
10185 | |
10186 | /// The number of typos corrected by CorrectTypo. |
10187 | unsigned TyposCorrected; |
10188 | |
10189 | typedef llvm::SmallSet<SourceLocation, 2> SrcLocSet; |
10190 | typedef llvm::DenseMap<IdentifierInfo *, SrcLocSet> IdentifierSourceLocations; |
10191 | |
10192 | /// A cache containing identifiers for which typo correction failed and |
10193 | /// their locations, so that repeated attempts to correct an identifier in a |
10194 | /// given location are ignored if typo correction already failed for it. |
10195 | IdentifierSourceLocations TypoCorrectionFailures; |
10196 | |
10197 | /// Worker object for performing CFG-based warnings. |
10198 | sema::AnalysisBasedWarnings AnalysisWarnings; |
10199 | threadSafety::BeforeSet *ThreadSafetyDeclCache; |
10200 | |
10201 | /// An entity for which implicit template instantiation is required. |
10202 | /// |
10203 | /// The source location associated with the declaration is the first place in |
10204 | /// the source code where the declaration was "used". It is not necessarily |
10205 | /// the point of instantiation (which will be either before or after the |
10206 | /// namespace-scope declaration that triggered this implicit instantiation), |
10207 | /// However, it is the location that diagnostics should generally refer to, |
10208 | /// because users will need to know what code triggered the instantiation. |
10209 | typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; |
10210 | |
10211 | /// The queue of implicit template instantiations that are required |
10212 | /// but have not yet been performed. |
10213 | std::deque<PendingImplicitInstantiation> PendingInstantiations; |
10214 | |
10215 | /// Queue of implicit template instantiations that cannot be performed |
10216 | /// eagerly. |
10217 | SmallVector<PendingImplicitInstantiation, 1> LateParsedInstantiations; |
10218 | |
10219 | SmallVector<SmallVector<VTableUse, 16>, 8> SavedVTableUses; |
10220 | SmallVector<std::deque<PendingImplicitInstantiation>, 8> |
10221 | SavedPendingInstantiations; |
10222 | |
10223 | class GlobalEagerInstantiationScope { |
10224 | public: |
10225 | GlobalEagerInstantiationScope(Sema &S, bool Enabled) |
10226 | : S(S), Enabled(Enabled) { |
10227 | if (!Enabled) return; |
10228 | |
10229 | S.SavedPendingInstantiations.emplace_back(); |
10230 | S.SavedPendingInstantiations.back().swap(x&: S.PendingInstantiations); |
10231 | |
10232 | S.SavedVTableUses.emplace_back(); |
10233 | S.SavedVTableUses.back().swap(RHS&: S.VTableUses); |
10234 | } |
10235 | |
10236 | void perform() { |
10237 | if (Enabled) { |
10238 | S.DefineUsedVTables(); |
10239 | S.PerformPendingInstantiations(); |
10240 | } |
10241 | } |
10242 | |
10243 | ~GlobalEagerInstantiationScope() { |
10244 | if (!Enabled) return; |
10245 | |
10246 | // Restore the set of pending vtables. |
10247 | assert(S.VTableUses.empty() && |
10248 | "VTableUses should be empty before it is discarded." ); |
10249 | S.VTableUses.swap(RHS&: S.SavedVTableUses.back()); |
10250 | S.SavedVTableUses.pop_back(); |
10251 | |
10252 | // Restore the set of pending implicit instantiations. |
10253 | if (S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) { |
10254 | assert(S.PendingInstantiations.empty() && |
10255 | "PendingInstantiations should be empty before it is discarded." ); |
10256 | S.PendingInstantiations.swap(x&: S.SavedPendingInstantiations.back()); |
10257 | S.SavedPendingInstantiations.pop_back(); |
10258 | } else { |
10259 | // Template instantiations in the PCH may be delayed until the TU. |
10260 | S.PendingInstantiations.swap(x&: S.SavedPendingInstantiations.back()); |
10261 | S.PendingInstantiations.insert( |
10262 | position: S.PendingInstantiations.end(), |
10263 | first: S.SavedPendingInstantiations.back().begin(), |
10264 | last: S.SavedPendingInstantiations.back().end()); |
10265 | S.SavedPendingInstantiations.pop_back(); |
10266 | } |
10267 | } |
10268 | |
10269 | private: |
10270 | Sema &S; |
10271 | bool Enabled; |
10272 | }; |
10273 | |
10274 | /// The queue of implicit template instantiations that are required |
10275 | /// and must be performed within the current local scope. |
10276 | /// |
10277 | /// This queue is only used for member functions of local classes in |
10278 | /// templates, which must be instantiated in the same scope as their |
10279 | /// enclosing function, so that they can reference function-local |
10280 | /// types, static variables, enumerators, etc. |
10281 | std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; |
10282 | |
10283 | class LocalEagerInstantiationScope { |
10284 | public: |
10285 | LocalEagerInstantiationScope(Sema &S) : S(S) { |
10286 | SavedPendingLocalImplicitInstantiations.swap( |
10287 | x&: S.PendingLocalImplicitInstantiations); |
10288 | } |
10289 | |
10290 | void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/LocalOnly: true); } |
10291 | |
10292 | ~LocalEagerInstantiationScope() { |
10293 | assert(S.PendingLocalImplicitInstantiations.empty() && |
10294 | "there shouldn't be any pending local implicit instantiations" ); |
10295 | SavedPendingLocalImplicitInstantiations.swap( |
10296 | x&: S.PendingLocalImplicitInstantiations); |
10297 | } |
10298 | |
10299 | private: |
10300 | Sema &S; |
10301 | std::deque<PendingImplicitInstantiation> |
10302 | SavedPendingLocalImplicitInstantiations; |
10303 | }; |
10304 | |
10305 | /// A helper class for building up ExtParameterInfos. |
10306 | class ExtParameterInfoBuilder { |
10307 | SmallVector<FunctionProtoType::ExtParameterInfo, 16> Infos; |
10308 | bool HasInteresting = false; |
10309 | |
10310 | public: |
10311 | /// Set the ExtParameterInfo for the parameter at the given index, |
10312 | /// |
10313 | void set(unsigned index, FunctionProtoType::ExtParameterInfo info) { |
10314 | assert(Infos.size() <= index); |
10315 | Infos.resize(N: index); |
10316 | Infos.push_back(Elt: info); |
10317 | |
10318 | if (!HasInteresting) |
10319 | HasInteresting = (info != FunctionProtoType::ExtParameterInfo()); |
10320 | } |
10321 | |
10322 | /// Return a pointer (suitable for setting in an ExtProtoInfo) to the |
10323 | /// ExtParameterInfo array we've built up. |
10324 | const FunctionProtoType::ExtParameterInfo * |
10325 | getPointerOrNull(unsigned numParams) { |
10326 | if (!HasInteresting) return nullptr; |
10327 | Infos.resize(N: numParams); |
10328 | return Infos.data(); |
10329 | } |
10330 | }; |
10331 | |
10332 | void PerformPendingInstantiations(bool LocalOnly = false); |
10333 | |
10334 | TypeSourceInfo *SubstType(TypeSourceInfo *T, |
10335 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10336 | SourceLocation Loc, DeclarationName Entity, |
10337 | bool AllowDeducedTST = false); |
10338 | |
10339 | QualType SubstType(QualType T, |
10340 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10341 | SourceLocation Loc, DeclarationName Entity); |
10342 | |
10343 | TypeSourceInfo *SubstType(TypeLoc TL, |
10344 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10345 | SourceLocation Loc, DeclarationName Entity); |
10346 | |
10347 | TypeSourceInfo *SubstFunctionDeclType( |
10348 | TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, |
10349 | SourceLocation Loc, DeclarationName Entity, CXXRecordDecl *ThisContext, |
10350 | Qualifiers ThisTypeQuals, bool EvaluateConstraints = true); |
10351 | void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, |
10352 | const MultiLevelTemplateArgumentList &Args); |
10353 | bool SubstExceptionSpec(SourceLocation Loc, |
10354 | FunctionProtoType::ExceptionSpecInfo &ESI, |
10355 | SmallVectorImpl<QualType> &ExceptionStorage, |
10356 | const MultiLevelTemplateArgumentList &Args); |
10357 | ParmVarDecl * |
10358 | SubstParmVarDecl(ParmVarDecl *D, |
10359 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10360 | int indexAdjustment, std::optional<unsigned> NumExpansions, |
10361 | bool ExpectParameterPack, bool EvaluateConstraints = true); |
10362 | bool SubstParmTypes(SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
10363 | const FunctionProtoType::ExtParameterInfo *ExtParamInfos, |
10364 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10365 | SmallVectorImpl<QualType> &ParamTypes, |
10366 | SmallVectorImpl<ParmVarDecl *> *OutParams, |
10367 | ExtParameterInfoBuilder &ParamInfos); |
10368 | bool SubstDefaultArgument(SourceLocation Loc, ParmVarDecl *Param, |
10369 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10370 | bool ForCallExpr = false); |
10371 | ExprResult SubstExpr(Expr *E, |
10372 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10373 | |
10374 | // A RAII type used by the TemplateDeclInstantiator and TemplateInstantiator |
10375 | // to disable constraint evaluation, then restore the state. |
10376 | template <typename InstTy> struct ConstraintEvalRAII { |
10377 | InstTy &TI; |
10378 | bool OldValue; |
10379 | |
10380 | ConstraintEvalRAII(InstTy &TI) |
10381 | : TI(TI), OldValue(TI.getEvaluateConstraints()) { |
10382 | TI.setEvaluateConstraints(false); |
10383 | } |
10384 | ~ConstraintEvalRAII() { TI.setEvaluateConstraints(OldValue); } |
10385 | }; |
10386 | |
10387 | // Must be used instead of SubstExpr at 'constraint checking' time. |
10388 | ExprResult |
10389 | SubstConstraintExpr(Expr *E, |
10390 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10391 | // Unlike the above, this does not evaluates constraints. |
10392 | ExprResult SubstConstraintExprWithoutSatisfaction( |
10393 | Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs); |
10394 | |
10395 | /// Substitute the given template arguments into a list of |
10396 | /// expressions, expanding pack expansions if required. |
10397 | /// |
10398 | /// \param Exprs The list of expressions to substitute into. |
10399 | /// |
10400 | /// \param IsCall Whether this is some form of call, in which case |
10401 | /// default arguments will be dropped. |
10402 | /// |
10403 | /// \param TemplateArgs The set of template arguments to substitute. |
10404 | /// |
10405 | /// \param Outputs Will receive all of the substituted arguments. |
10406 | /// |
10407 | /// \returns true if an error occurred, false otherwise. |
10408 | bool SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall, |
10409 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10410 | SmallVectorImpl<Expr *> &Outputs); |
10411 | |
10412 | StmtResult SubstStmt(Stmt *S, |
10413 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10414 | |
10415 | TemplateParameterList * |
10416 | SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner, |
10417 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10418 | bool EvaluateConstraints = true); |
10419 | |
10420 | bool |
10421 | SubstTemplateArguments(ArrayRef<TemplateArgumentLoc> Args, |
10422 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10423 | TemplateArgumentListInfo &Outputs); |
10424 | |
10425 | Decl *SubstDecl(Decl *D, DeclContext *Owner, |
10426 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10427 | |
10428 | /// Substitute the name and return type of a defaulted 'operator<=>' to form |
10429 | /// an implicit 'operator=='. |
10430 | FunctionDecl *SubstSpaceshipAsEqualEqual(CXXRecordDecl *RD, |
10431 | FunctionDecl *Spaceship); |
10432 | |
10433 | ExprResult SubstInitializer(Expr *E, |
10434 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10435 | bool CXXDirectInit); |
10436 | |
10437 | bool |
10438 | SubstBaseSpecifiers(CXXRecordDecl *Instantiation, |
10439 | CXXRecordDecl *Pattern, |
10440 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10441 | |
10442 | bool |
10443 | InstantiateClass(SourceLocation PointOfInstantiation, |
10444 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
10445 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10446 | TemplateSpecializationKind TSK, |
10447 | bool Complain = true); |
10448 | |
10449 | bool InstantiateEnum(SourceLocation PointOfInstantiation, |
10450 | EnumDecl *Instantiation, EnumDecl *Pattern, |
10451 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10452 | TemplateSpecializationKind TSK); |
10453 | |
10454 | bool InstantiateInClassInitializer( |
10455 | SourceLocation PointOfInstantiation, FieldDecl *Instantiation, |
10456 | FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs); |
10457 | |
10458 | struct LateInstantiatedAttribute { |
10459 | const Attr *TmplAttr; |
10460 | LocalInstantiationScope *Scope; |
10461 | Decl *NewDecl; |
10462 | |
10463 | LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S, |
10464 | Decl *D) |
10465 | : TmplAttr(A), Scope(S), NewDecl(D) |
10466 | { } |
10467 | }; |
10468 | typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec; |
10469 | |
10470 | void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, |
10471 | const Decl *Pattern, Decl *Inst, |
10472 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
10473 | LocalInstantiationScope *OuterMostScope = nullptr); |
10474 | void updateAttrsForLateParsedTemplate(const Decl *Pattern, Decl *Inst); |
10475 | |
10476 | void |
10477 | InstantiateAttrsForDecl(const MultiLevelTemplateArgumentList &TemplateArgs, |
10478 | const Decl *Pattern, Decl *Inst, |
10479 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
10480 | LocalInstantiationScope *OuterMostScope = nullptr); |
10481 | |
10482 | void InstantiateDefaultCtorDefaultArgs(CXXConstructorDecl *Ctor); |
10483 | |
10484 | bool usesPartialOrExplicitSpecialization( |
10485 | SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec); |
10486 | |
10487 | bool |
10488 | InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, |
10489 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
10490 | TemplateSpecializationKind TSK, |
10491 | bool Complain = true); |
10492 | |
10493 | void InstantiateClassMembers(SourceLocation PointOfInstantiation, |
10494 | CXXRecordDecl *Instantiation, |
10495 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10496 | TemplateSpecializationKind TSK); |
10497 | |
10498 | void InstantiateClassTemplateSpecializationMembers( |
10499 | SourceLocation PointOfInstantiation, |
10500 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
10501 | TemplateSpecializationKind TSK); |
10502 | |
10503 | NestedNameSpecifierLoc |
10504 | SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
10505 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10506 | |
10507 | DeclarationNameInfo |
10508 | SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
10509 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10510 | TemplateName |
10511 | SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, |
10512 | SourceLocation Loc, |
10513 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10514 | |
10515 | bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC, |
10516 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10517 | bool EvaluateConstraint); |
10518 | |
10519 | bool InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD, |
10520 | ParmVarDecl *Param); |
10521 | void InstantiateExceptionSpec(SourceLocation PointOfInstantiation, |
10522 | FunctionDecl *Function); |
10523 | bool CheckInstantiatedFunctionTemplateConstraints( |
10524 | SourceLocation PointOfInstantiation, FunctionDecl *Decl, |
10525 | ArrayRef<TemplateArgument> TemplateArgs, |
10526 | ConstraintSatisfaction &Satisfaction); |
10527 | FunctionDecl *InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD, |
10528 | const TemplateArgumentList *Args, |
10529 | SourceLocation Loc); |
10530 | void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, |
10531 | FunctionDecl *Function, |
10532 | bool Recursive = false, |
10533 | bool DefinitionRequired = false, |
10534 | bool AtEndOfTU = false); |
10535 | VarTemplateSpecializationDecl *BuildVarTemplateInstantiation( |
10536 | VarTemplateDecl *VarTemplate, VarDecl *FromVar, |
10537 | const TemplateArgumentList *PartialSpecArgs, |
10538 | const TemplateArgumentListInfo &TemplateArgsInfo, |
10539 | SmallVectorImpl<TemplateArgument> &Converted, |
10540 | SourceLocation PointOfInstantiation, |
10541 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
10542 | LocalInstantiationScope *StartingScope = nullptr); |
10543 | VarTemplateSpecializationDecl *CompleteVarTemplateSpecializationDecl( |
10544 | VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl, |
10545 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10546 | void |
10547 | BuildVariableInstantiation(VarDecl *NewVar, VarDecl *OldVar, |
10548 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10549 | LateInstantiatedAttrVec *LateAttrs, |
10550 | DeclContext *Owner, |
10551 | LocalInstantiationScope *StartingScope, |
10552 | bool InstantiatingVarTemplate = false, |
10553 | VarTemplateSpecializationDecl *PrevVTSD = nullptr); |
10554 | |
10555 | void InstantiateVariableInitializer( |
10556 | VarDecl *Var, VarDecl *OldVar, |
10557 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10558 | void InstantiateVariableDefinition(SourceLocation PointOfInstantiation, |
10559 | VarDecl *Var, bool Recursive = false, |
10560 | bool DefinitionRequired = false, |
10561 | bool AtEndOfTU = false); |
10562 | |
10563 | void InstantiateMemInitializers(CXXConstructorDecl *New, |
10564 | const CXXConstructorDecl *Tmpl, |
10565 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10566 | |
10567 | ExplicitSpecifier instantiateExplicitSpecifier( |
10568 | const MultiLevelTemplateArgumentList &TemplateArgs, ExplicitSpecifier ES); |
10569 | |
10570 | NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, |
10571 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10572 | bool FindingInstantiatedContext = false); |
10573 | DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, |
10574 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10575 | |
10576 | // Objective-C declarations. |
10577 | enum ObjCContainerKind { |
10578 | OCK_None = -1, |
10579 | OCK_Interface = 0, |
10580 | OCK_Protocol, |
10581 | OCK_Category, |
10582 | OCK_ClassExtension, |
10583 | OCK_Implementation, |
10584 | OCK_CategoryImplementation |
10585 | }; |
10586 | ObjCContainerKind getObjCContainerKind() const; |
10587 | |
10588 | DeclResult actOnObjCTypeParam(Scope *S, |
10589 | ObjCTypeParamVariance variance, |
10590 | SourceLocation varianceLoc, |
10591 | unsigned index, |
10592 | IdentifierInfo *paramName, |
10593 | SourceLocation paramLoc, |
10594 | SourceLocation colonLoc, |
10595 | ParsedType typeBound); |
10596 | |
10597 | ObjCTypeParamList *actOnObjCTypeParamList(Scope *S, SourceLocation lAngleLoc, |
10598 | ArrayRef<Decl *> typeParams, |
10599 | SourceLocation rAngleLoc); |
10600 | void popObjCTypeParamList(Scope *S, ObjCTypeParamList *typeParamList); |
10601 | |
10602 | ObjCInterfaceDecl *ActOnStartClassInterface( |
10603 | Scope *S, SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, |
10604 | SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, |
10605 | IdentifierInfo *SuperName, SourceLocation SuperLoc, |
10606 | ArrayRef<ParsedType> SuperTypeArgs, SourceRange SuperTypeArgsRange, |
10607 | Decl *const *ProtoRefs, unsigned NumProtoRefs, |
10608 | const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, |
10609 | const ParsedAttributesView &AttrList, SkipBodyInfo *SkipBody); |
10610 | |
10611 | void ActOnSuperClassOfClassInterface(Scope *S, |
10612 | SourceLocation AtInterfaceLoc, |
10613 | ObjCInterfaceDecl *IDecl, |
10614 | IdentifierInfo *ClassName, |
10615 | SourceLocation ClassLoc, |
10616 | IdentifierInfo *SuperName, |
10617 | SourceLocation SuperLoc, |
10618 | ArrayRef<ParsedType> SuperTypeArgs, |
10619 | SourceRange SuperTypeArgsRange); |
10620 | |
10621 | void ActOnTypedefedProtocols(SmallVectorImpl<Decl *> &ProtocolRefs, |
10622 | SmallVectorImpl<SourceLocation> &ProtocolLocs, |
10623 | IdentifierInfo *SuperName, |
10624 | SourceLocation SuperLoc); |
10625 | |
10626 | Decl *ActOnCompatibilityAlias( |
10627 | SourceLocation AtCompatibilityAliasLoc, |
10628 | IdentifierInfo *AliasName, SourceLocation AliasLocation, |
10629 | IdentifierInfo *ClassName, SourceLocation ClassLocation); |
10630 | |
10631 | bool CheckForwardProtocolDeclarationForCircularDependency( |
10632 | IdentifierInfo *PName, |
10633 | SourceLocation &PLoc, SourceLocation PrevLoc, |
10634 | const ObjCList<ObjCProtocolDecl> &PList); |
10635 | |
10636 | ObjCProtocolDecl *ActOnStartProtocolInterface( |
10637 | SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName, |
10638 | SourceLocation ProtocolLoc, Decl *const *ProtoRefNames, |
10639 | unsigned NumProtoRefs, const SourceLocation *ProtoLocs, |
10640 | SourceLocation EndProtoLoc, const ParsedAttributesView &AttrList, |
10641 | SkipBodyInfo *SkipBody); |
10642 | |
10643 | ObjCCategoryDecl *ActOnStartCategoryInterface( |
10644 | SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, |
10645 | SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, |
10646 | IdentifierInfo *CategoryName, SourceLocation CategoryLoc, |
10647 | Decl *const *ProtoRefs, unsigned NumProtoRefs, |
10648 | const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, |
10649 | const ParsedAttributesView &AttrList); |
10650 | |
10651 | ObjCImplementationDecl *ActOnStartClassImplementation( |
10652 | SourceLocation AtClassImplLoc, IdentifierInfo *ClassName, |
10653 | SourceLocation ClassLoc, IdentifierInfo *SuperClassname, |
10654 | SourceLocation SuperClassLoc, const ParsedAttributesView &AttrList); |
10655 | |
10656 | ObjCCategoryImplDecl *ActOnStartCategoryImplementation( |
10657 | SourceLocation AtCatImplLoc, IdentifierInfo *ClassName, |
10658 | SourceLocation ClassLoc, IdentifierInfo *CatName, SourceLocation CatLoc, |
10659 | const ParsedAttributesView &AttrList); |
10660 | |
10661 | DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, |
10662 | ArrayRef<Decl *> Decls); |
10663 | |
10664 | DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, |
10665 | IdentifierInfo **IdentList, |
10666 | SourceLocation *IdentLocs, |
10667 | ArrayRef<ObjCTypeParamList *> TypeParamLists, |
10668 | unsigned NumElts); |
10669 | |
10670 | DeclGroupPtrTy |
10671 | ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, |
10672 | ArrayRef<IdentifierLocPair> IdentList, |
10673 | const ParsedAttributesView &attrList); |
10674 | |
10675 | void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer, |
10676 | ArrayRef<IdentifierLocPair> ProtocolId, |
10677 | SmallVectorImpl<Decl *> &Protocols); |
10678 | |
10679 | void DiagnoseTypeArgsAndProtocols(IdentifierInfo *ProtocolId, |
10680 | SourceLocation ProtocolLoc, |
10681 | IdentifierInfo *TypeArgId, |
10682 | SourceLocation TypeArgLoc, |
10683 | bool SelectProtocolFirst = false); |
10684 | |
10685 | /// Given a list of identifiers (and their locations), resolve the |
10686 | /// names to either Objective-C protocol qualifiers or type |
10687 | /// arguments, as appropriate. |
10688 | void actOnObjCTypeArgsOrProtocolQualifiers( |
10689 | Scope *S, |
10690 | ParsedType baseType, |
10691 | SourceLocation lAngleLoc, |
10692 | ArrayRef<IdentifierInfo *> identifiers, |
10693 | ArrayRef<SourceLocation> identifierLocs, |
10694 | SourceLocation rAngleLoc, |
10695 | SourceLocation &typeArgsLAngleLoc, |
10696 | SmallVectorImpl<ParsedType> &typeArgs, |
10697 | SourceLocation &typeArgsRAngleLoc, |
10698 | SourceLocation &protocolLAngleLoc, |
10699 | SmallVectorImpl<Decl *> &protocols, |
10700 | SourceLocation &protocolRAngleLoc, |
10701 | bool warnOnIncompleteProtocols); |
10702 | |
10703 | /// Build a an Objective-C protocol-qualified 'id' type where no |
10704 | /// base type was specified. |
10705 | TypeResult actOnObjCProtocolQualifierType( |
10706 | SourceLocation lAngleLoc, |
10707 | ArrayRef<Decl *> protocols, |
10708 | ArrayRef<SourceLocation> protocolLocs, |
10709 | SourceLocation rAngleLoc); |
10710 | |
10711 | /// Build a specialized and/or protocol-qualified Objective-C type. |
10712 | TypeResult actOnObjCTypeArgsAndProtocolQualifiers( |
10713 | Scope *S, |
10714 | SourceLocation Loc, |
10715 | ParsedType BaseType, |
10716 | SourceLocation TypeArgsLAngleLoc, |
10717 | ArrayRef<ParsedType> TypeArgs, |
10718 | SourceLocation TypeArgsRAngleLoc, |
10719 | SourceLocation ProtocolLAngleLoc, |
10720 | ArrayRef<Decl *> Protocols, |
10721 | ArrayRef<SourceLocation> ProtocolLocs, |
10722 | SourceLocation ProtocolRAngleLoc); |
10723 | |
10724 | /// Build an Objective-C type parameter type. |
10725 | QualType BuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, |
10726 | SourceLocation ProtocolLAngleLoc, |
10727 | ArrayRef<ObjCProtocolDecl *> Protocols, |
10728 | ArrayRef<SourceLocation> ProtocolLocs, |
10729 | SourceLocation ProtocolRAngleLoc, |
10730 | bool FailOnError = false); |
10731 | |
10732 | /// Build an Objective-C object pointer type. |
10733 | QualType BuildObjCObjectType( |
10734 | QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, |
10735 | ArrayRef<TypeSourceInfo *> TypeArgs, SourceLocation TypeArgsRAngleLoc, |
10736 | SourceLocation ProtocolLAngleLoc, ArrayRef<ObjCProtocolDecl *> Protocols, |
10737 | ArrayRef<SourceLocation> ProtocolLocs, SourceLocation ProtocolRAngleLoc, |
10738 | bool FailOnError, bool Rebuilding); |
10739 | |
10740 | /// Ensure attributes are consistent with type. |
10741 | /// \param [in, out] Attributes The attributes to check; they will |
10742 | /// be modified to be consistent with \p PropertyTy. |
10743 | void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, |
10744 | SourceLocation Loc, |
10745 | unsigned &Attributes, |
10746 | bool propertyInPrimaryClass); |
10747 | |
10748 | /// Process the specified property declaration and create decls for the |
10749 | /// setters and getters as needed. |
10750 | /// \param property The property declaration being processed |
10751 | void ProcessPropertyDecl(ObjCPropertyDecl *property); |
10752 | |
10753 | |
10754 | void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, |
10755 | ObjCPropertyDecl *SuperProperty, |
10756 | const IdentifierInfo *Name, |
10757 | bool OverridingProtocolProperty); |
10758 | |
10759 | void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, |
10760 | ObjCInterfaceDecl *ID); |
10761 | |
10762 | Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd, |
10763 | ArrayRef<Decl *> allMethods = std::nullopt, |
10764 | ArrayRef<DeclGroupPtrTy> allTUVars = std::nullopt); |
10765 | |
10766 | Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, |
10767 | SourceLocation LParenLoc, |
10768 | FieldDeclarator &FD, ObjCDeclSpec &ODS, |
10769 | Selector GetterSel, Selector SetterSel, |
10770 | tok::ObjCKeywordKind MethodImplKind, |
10771 | DeclContext *lexicalDC = nullptr); |
10772 | |
10773 | Decl *ActOnPropertyImplDecl(Scope *S, |
10774 | SourceLocation AtLoc, |
10775 | SourceLocation PropertyLoc, |
10776 | bool ImplKind, |
10777 | IdentifierInfo *PropertyId, |
10778 | IdentifierInfo *PropertyIvar, |
10779 | SourceLocation PropertyIvarLoc, |
10780 | ObjCPropertyQueryKind QueryKind); |
10781 | |
10782 | enum ObjCSpecialMethodKind { |
10783 | OSMK_None, |
10784 | OSMK_Alloc, |
10785 | OSMK_New, |
10786 | OSMK_Copy, |
10787 | OSMK_RetainingInit, |
10788 | OSMK_NonRetainingInit |
10789 | }; |
10790 | |
10791 | struct ObjCArgInfo { |
10792 | IdentifierInfo *Name; |
10793 | SourceLocation NameLoc; |
10794 | // The Type is null if no type was specified, and the DeclSpec is invalid |
10795 | // in this case. |
10796 | ParsedType Type; |
10797 | ObjCDeclSpec DeclSpec; |
10798 | |
10799 | /// ArgAttrs - Attribute list for this argument. |
10800 | ParsedAttributesView ArgAttrs; |
10801 | }; |
10802 | |
10803 | Decl *ActOnMethodDeclaration( |
10804 | Scope *S, |
10805 | SourceLocation BeginLoc, // location of the + or -. |
10806 | SourceLocation EndLoc, // location of the ; or {. |
10807 | tok::TokenKind MethodType, ObjCDeclSpec &ReturnQT, ParsedType ReturnType, |
10808 | ArrayRef<SourceLocation> SelectorLocs, Selector Sel, |
10809 | // optional arguments. The number of types/arguments is obtained |
10810 | // from the Sel.getNumArgs(). |
10811 | ObjCArgInfo *ArgInfo, DeclaratorChunk::ParamInfo *CParamInfo, |
10812 | unsigned CNumArgs, // c-style args |
10813 | const ParsedAttributesView &AttrList, tok::ObjCKeywordKind MethodImplKind, |
10814 | bool isVariadic, bool MethodDefinition); |
10815 | |
10816 | ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, |
10817 | const ObjCObjectPointerType *OPT, |
10818 | bool IsInstance); |
10819 | ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty, |
10820 | bool IsInstance); |
10821 | |
10822 | bool CheckARCMethodDecl(ObjCMethodDecl *method); |
10823 | bool inferObjCARCLifetime(ValueDecl *decl); |
10824 | |
10825 | void deduceOpenCLAddressSpace(ValueDecl *decl); |
10826 | |
10827 | ExprResult |
10828 | HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, |
10829 | Expr *BaseExpr, |
10830 | SourceLocation OpLoc, |
10831 | DeclarationName MemberName, |
10832 | SourceLocation MemberLoc, |
10833 | SourceLocation SuperLoc, QualType SuperType, |
10834 | bool Super); |
10835 | |
10836 | ExprResult |
10837 | ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, |
10838 | IdentifierInfo &propertyName, |
10839 | SourceLocation receiverNameLoc, |
10840 | SourceLocation propertyNameLoc); |
10841 | |
10842 | ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc); |
10843 | |
10844 | /// Describes the kind of message expression indicated by a message |
10845 | /// send that starts with an identifier. |
10846 | enum ObjCMessageKind { |
10847 | /// The message is sent to 'super'. |
10848 | ObjCSuperMessage, |
10849 | /// The message is an instance message. |
10850 | ObjCInstanceMessage, |
10851 | /// The message is a class message, and the identifier is a type |
10852 | /// name. |
10853 | ObjCClassMessage |
10854 | }; |
10855 | |
10856 | ObjCMessageKind getObjCMessageKind(Scope *S, |
10857 | IdentifierInfo *Name, |
10858 | SourceLocation NameLoc, |
10859 | bool IsSuper, |
10860 | bool HasTrailingDot, |
10861 | ParsedType &ReceiverType); |
10862 | |
10863 | ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, |
10864 | Selector Sel, |
10865 | SourceLocation LBracLoc, |
10866 | ArrayRef<SourceLocation> SelectorLocs, |
10867 | SourceLocation RBracLoc, |
10868 | MultiExprArg Args); |
10869 | |
10870 | ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, |
10871 | QualType ReceiverType, |
10872 | SourceLocation SuperLoc, |
10873 | Selector Sel, |
10874 | ObjCMethodDecl *Method, |
10875 | SourceLocation LBracLoc, |
10876 | ArrayRef<SourceLocation> SelectorLocs, |
10877 | SourceLocation RBracLoc, |
10878 | MultiExprArg Args, |
10879 | bool isImplicit = false); |
10880 | |
10881 | ExprResult BuildClassMessageImplicit(QualType ReceiverType, |
10882 | bool isSuperReceiver, |
10883 | SourceLocation Loc, |
10884 | Selector Sel, |
10885 | ObjCMethodDecl *Method, |
10886 | MultiExprArg Args); |
10887 | |
10888 | ExprResult ActOnClassMessage(Scope *S, |
10889 | ParsedType Receiver, |
10890 | Selector Sel, |
10891 | SourceLocation LBracLoc, |
10892 | ArrayRef<SourceLocation> SelectorLocs, |
10893 | SourceLocation RBracLoc, |
10894 | MultiExprArg Args); |
10895 | |
10896 | ExprResult BuildInstanceMessage(Expr *Receiver, |
10897 | QualType ReceiverType, |
10898 | SourceLocation SuperLoc, |
10899 | Selector Sel, |
10900 | ObjCMethodDecl *Method, |
10901 | SourceLocation LBracLoc, |
10902 | ArrayRef<SourceLocation> SelectorLocs, |
10903 | SourceLocation RBracLoc, |
10904 | MultiExprArg Args, |
10905 | bool isImplicit = false); |
10906 | |
10907 | ExprResult BuildInstanceMessageImplicit(Expr *Receiver, |
10908 | QualType ReceiverType, |
10909 | SourceLocation Loc, |
10910 | Selector Sel, |
10911 | ObjCMethodDecl *Method, |
10912 | MultiExprArg Args); |
10913 | |
10914 | ExprResult ActOnInstanceMessage(Scope *S, |
10915 | Expr *Receiver, |
10916 | Selector Sel, |
10917 | SourceLocation LBracLoc, |
10918 | ArrayRef<SourceLocation> SelectorLocs, |
10919 | SourceLocation RBracLoc, |
10920 | MultiExprArg Args); |
10921 | |
10922 | ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, |
10923 | ObjCBridgeCastKind Kind, |
10924 | SourceLocation BridgeKeywordLoc, |
10925 | TypeSourceInfo *TSInfo, |
10926 | Expr *SubExpr); |
10927 | |
10928 | ExprResult ActOnObjCBridgedCast(Scope *S, |
10929 | SourceLocation LParenLoc, |
10930 | ObjCBridgeCastKind Kind, |
10931 | SourceLocation BridgeKeywordLoc, |
10932 | ParsedType Type, |
10933 | SourceLocation RParenLoc, |
10934 | Expr *SubExpr); |
10935 | |
10936 | void CheckTollFreeBridgeCast(QualType castType, Expr *castExpr); |
10937 | |
10938 | void CheckObjCBridgeRelatedCast(QualType castType, Expr *castExpr); |
10939 | |
10940 | bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr, |
10941 | CastKind &Kind); |
10942 | |
10943 | bool checkObjCBridgeRelatedComponents(SourceLocation Loc, |
10944 | QualType DestType, QualType SrcType, |
10945 | ObjCInterfaceDecl *&RelatedClass, |
10946 | ObjCMethodDecl *&ClassMethod, |
10947 | ObjCMethodDecl *&InstanceMethod, |
10948 | TypedefNameDecl *&TDNDecl, |
10949 | bool CfToNs, bool Diagnose = true); |
10950 | |
10951 | bool CheckObjCBridgeRelatedConversions(SourceLocation Loc, |
10952 | QualType DestType, QualType SrcType, |
10953 | Expr *&SrcExpr, bool Diagnose = true); |
10954 | |
10955 | bool CheckConversionToObjCLiteral(QualType DstType, Expr *&SrcExpr, |
10956 | bool Diagnose = true); |
10957 | |
10958 | bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); |
10959 | |
10960 | /// Check whether the given new method is a valid override of the |
10961 | /// given overridden method, and set any properties that should be inherited. |
10962 | void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, |
10963 | const ObjCMethodDecl *Overridden); |
10964 | |
10965 | /// Describes the compatibility of a result type with its method. |
10966 | enum ResultTypeCompatibilityKind { |
10967 | RTC_Compatible, |
10968 | RTC_Incompatible, |
10969 | RTC_Unknown |
10970 | }; |
10971 | |
10972 | void CheckObjCMethodDirectOverrides(ObjCMethodDecl *method, |
10973 | ObjCMethodDecl *overridden); |
10974 | |
10975 | void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod, |
10976 | ObjCInterfaceDecl *CurrentClass, |
10977 | ResultTypeCompatibilityKind RTC); |
10978 | |
10979 | enum PragmaOptionsAlignKind { |
10980 | POAK_Native, // #pragma options align=native |
10981 | POAK_Natural, // #pragma options align=natural |
10982 | POAK_Packed, // #pragma options align=packed |
10983 | POAK_Power, // #pragma options align=power |
10984 | POAK_Mac68k, // #pragma options align=mac68k |
10985 | POAK_Reset // #pragma options align=reset |
10986 | }; |
10987 | |
10988 | /// ActOnPragmaClangSection - Called on well formed \#pragma clang section |
10989 | void ActOnPragmaClangSection(SourceLocation PragmaLoc, |
10990 | PragmaClangSectionAction Action, |
10991 | PragmaClangSectionKind SecKind, StringRef SecName); |
10992 | |
10993 | /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align. |
10994 | void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, |
10995 | SourceLocation PragmaLoc); |
10996 | |
10997 | /// ActOnPragmaPack - Called on well formed \#pragma pack(...). |
10998 | void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, |
10999 | StringRef SlotLabel, Expr *Alignment); |
11000 | |
11001 | enum class PragmaAlignPackDiagnoseKind { |
11002 | NonDefaultStateAtInclude, |
11003 | ChangedStateAtExit |
11004 | }; |
11005 | |
11006 | void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind, |
11007 | SourceLocation IncludeLoc); |
11008 | void DiagnoseUnterminatedPragmaAlignPack(); |
11009 | |
11010 | /// ActOnPragmaMSStrictGuardStackCheck - Called on well formed \#pragma |
11011 | /// strict_gs_check. |
11012 | void ActOnPragmaMSStrictGuardStackCheck(SourceLocation PragmaLocation, |
11013 | PragmaMsStackAction Action, |
11014 | bool Value); |
11015 | |
11016 | /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off]. |
11017 | void ActOnPragmaMSStruct(PragmaMSStructKind Kind); |
11018 | |
11019 | /// ActOnPragmaMSComment - Called on well formed |
11020 | /// \#pragma comment(kind, "arg"). |
11021 | void (SourceLocation , PragmaMSCommentKind Kind, |
11022 | StringRef Arg); |
11023 | |
11024 | /// ActOnPragmaMSPointersToMembers - called on well formed \#pragma |
11025 | /// pointers_to_members(representation method[, general purpose |
11026 | /// representation]). |
11027 | void ActOnPragmaMSPointersToMembers( |
11028 | LangOptions::PragmaMSPointersToMembersKind Kind, |
11029 | SourceLocation PragmaLoc); |
11030 | |
11031 | /// Called on well formed \#pragma vtordisp(). |
11032 | void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, |
11033 | SourceLocation PragmaLoc, |
11034 | MSVtorDispMode Value); |
11035 | |
11036 | enum PragmaSectionKind { |
11037 | PSK_DataSeg, |
11038 | PSK_BSSSeg, |
11039 | PSK_ConstSeg, |
11040 | PSK_CodeSeg, |
11041 | }; |
11042 | |
11043 | bool UnifySection(StringRef SectionName, int SectionFlags, |
11044 | NamedDecl *TheDecl); |
11045 | bool UnifySection(StringRef SectionName, |
11046 | int SectionFlags, |
11047 | SourceLocation PragmaSectionLocation); |
11048 | |
11049 | /// Called on well formed \#pragma bss_seg/data_seg/const_seg/code_seg. |
11050 | void ActOnPragmaMSSeg(SourceLocation PragmaLocation, |
11051 | PragmaMsStackAction Action, |
11052 | llvm::StringRef StackSlotLabel, |
11053 | StringLiteral *SegmentName, |
11054 | llvm::StringRef PragmaName); |
11055 | |
11056 | /// Called on well formed \#pragma section(). |
11057 | void ActOnPragmaMSSection(SourceLocation PragmaLocation, |
11058 | int SectionFlags, StringLiteral *SegmentName); |
11059 | |
11060 | /// Called on well-formed \#pragma init_seg(). |
11061 | void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, |
11062 | StringLiteral *SegmentName); |
11063 | |
11064 | /// Called on well-formed \#pragma alloc_text(). |
11065 | void ActOnPragmaMSAllocText( |
11066 | SourceLocation PragmaLocation, StringRef Section, |
11067 | const SmallVector<std::tuple<IdentifierInfo *, SourceLocation>> |
11068 | &Functions); |
11069 | |
11070 | /// Called on #pragma clang __debug dump II |
11071 | void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II); |
11072 | |
11073 | /// Called on #pragma clang __debug dump E |
11074 | void ActOnPragmaDump(Expr *E); |
11075 | |
11076 | /// ActOnPragmaDetectMismatch - Call on well-formed \#pragma detect_mismatch |
11077 | void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, |
11078 | StringRef Value); |
11079 | |
11080 | /// Are precise floating point semantics currently enabled? |
11081 | bool isPreciseFPEnabled() { |
11082 | return !CurFPFeatures.getAllowFPReassociate() && |
11083 | !CurFPFeatures.getNoSignedZero() && |
11084 | !CurFPFeatures.getAllowReciprocal() && |
11085 | !CurFPFeatures.getAllowApproxFunc(); |
11086 | } |
11087 | |
11088 | void ActOnPragmaFPEvalMethod(SourceLocation Loc, |
11089 | LangOptions::FPEvalMethodKind Value); |
11090 | |
11091 | /// ActOnPragmaFloatControl - Call on well-formed \#pragma float_control |
11092 | void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, |
11093 | PragmaFloatControlKind Value); |
11094 | |
11095 | /// ActOnPragmaUnused - Called on well-formed '\#pragma unused'. |
11096 | void ActOnPragmaUnused(const Token &Identifier, |
11097 | Scope *curScope, |
11098 | SourceLocation PragmaLoc); |
11099 | |
11100 | /// ActOnPragmaVisibility - Called on well formed \#pragma GCC visibility... . |
11101 | void ActOnPragmaVisibility(const IdentifierInfo* VisType, |
11102 | SourceLocation PragmaLoc); |
11103 | |
11104 | NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, const IdentifierInfo *II, |
11105 | SourceLocation Loc); |
11106 | void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, const WeakInfo &W); |
11107 | |
11108 | /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident. |
11109 | void ActOnPragmaWeakID(IdentifierInfo* WeakName, |
11110 | SourceLocation PragmaLoc, |
11111 | SourceLocation WeakNameLoc); |
11112 | |
11113 | /// ActOnPragmaRedefineExtname - Called on well formed |
11114 | /// \#pragma redefine_extname oldname newname. |
11115 | void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName, |
11116 | IdentifierInfo* AliasName, |
11117 | SourceLocation PragmaLoc, |
11118 | SourceLocation WeakNameLoc, |
11119 | SourceLocation AliasNameLoc); |
11120 | |
11121 | /// ActOnPragmaWeakAlias - Called on well formed \#pragma weak ident = ident. |
11122 | void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, |
11123 | IdentifierInfo* AliasName, |
11124 | SourceLocation PragmaLoc, |
11125 | SourceLocation WeakNameLoc, |
11126 | SourceLocation AliasNameLoc); |
11127 | |
11128 | /// ActOnPragmaFPContract - Called on well formed |
11129 | /// \#pragma {STDC,OPENCL} FP_CONTRACT and |
11130 | /// \#pragma clang fp contract |
11131 | void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC); |
11132 | |
11133 | /// Called on well formed |
11134 | /// \#pragma clang fp reassociate |
11135 | /// or |
11136 | /// \#pragma clang fp reciprocal |
11137 | void ActOnPragmaFPValueChangingOption(SourceLocation Loc, PragmaFPKind Kind, |
11138 | bool IsEnabled); |
11139 | |
11140 | /// ActOnPragmaFenvAccess - Called on well formed |
11141 | /// \#pragma STDC FENV_ACCESS |
11142 | void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled); |
11143 | |
11144 | /// ActOnPragmaCXLimitedRange - Called on well formed |
11145 | /// \#pragma STDC CX_LIMITED_RANGE |
11146 | void ActOnPragmaCXLimitedRange(SourceLocation Loc, |
11147 | LangOptions::ComplexRangeKind Range); |
11148 | |
11149 | /// Called on well formed '\#pragma clang fp' that has option 'exceptions'. |
11150 | void ActOnPragmaFPExceptions(SourceLocation Loc, |
11151 | LangOptions::FPExceptionModeKind); |
11152 | |
11153 | /// Called to set constant rounding mode for floating point operations. |
11154 | void ActOnPragmaFEnvRound(SourceLocation Loc, llvm::RoundingMode); |
11155 | |
11156 | /// Called to set exception behavior for floating point operations. |
11157 | void setExceptionMode(SourceLocation Loc, LangOptions::FPExceptionModeKind); |
11158 | |
11159 | /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to |
11160 | /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'. |
11161 | void AddAlignmentAttributesForRecord(RecordDecl *RD); |
11162 | |
11163 | /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. |
11164 | void AddMsStructLayoutForRecord(RecordDecl *RD); |
11165 | |
11166 | /// PushNamespaceVisibilityAttr - Note that we've entered a |
11167 | /// namespace with a visibility attribute. |
11168 | void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, |
11169 | SourceLocation Loc); |
11170 | |
11171 | /// AddPushedVisibilityAttribute - If '\#pragma GCC visibility' was used, |
11172 | /// add an appropriate visibility attribute. |
11173 | void AddPushedVisibilityAttribute(Decl *RD); |
11174 | |
11175 | /// PopPragmaVisibility - Pop the top element of the visibility stack; used |
11176 | /// for '\#pragma GCC visibility' and visibility attributes on namespaces. |
11177 | void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc); |
11178 | |
11179 | /// FreeVisContext - Deallocate and null out VisContext. |
11180 | void FreeVisContext(); |
11181 | |
11182 | /// AddCFAuditedAttribute - Check whether we're currently within |
11183 | /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding |
11184 | /// the appropriate attribute. |
11185 | void AddCFAuditedAttribute(Decl *D); |
11186 | |
11187 | void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, |
11188 | SourceLocation PragmaLoc, |
11189 | attr::ParsedSubjectMatchRuleSet Rules); |
11190 | void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, |
11191 | const IdentifierInfo *Namespace); |
11192 | |
11193 | /// Called on well-formed '\#pragma clang attribute pop'. |
11194 | void ActOnPragmaAttributePop(SourceLocation PragmaLoc, |
11195 | const IdentifierInfo *Namespace); |
11196 | |
11197 | /// Adds the attributes that have been specified using the |
11198 | /// '\#pragma clang attribute push' directives to the given declaration. |
11199 | void AddPragmaAttributes(Scope *S, Decl *D); |
11200 | |
11201 | void DiagnoseUnterminatedPragmaAttribute(); |
11202 | |
11203 | /// Called on well formed \#pragma clang optimize. |
11204 | void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc); |
11205 | |
11206 | /// #pragma optimize("[optimization-list]", on | off). |
11207 | void ActOnPragmaMSOptimize(SourceLocation Loc, bool IsOn); |
11208 | |
11209 | /// Call on well formed \#pragma function. |
11210 | void |
11211 | ActOnPragmaMSFunction(SourceLocation Loc, |
11212 | const llvm::SmallVectorImpl<StringRef> &NoBuiltins); |
11213 | |
11214 | /// Get the location for the currently active "\#pragma clang optimize |
11215 | /// off". If this location is invalid, then the state of the pragma is "on". |
11216 | SourceLocation getOptimizeOffPragmaLocation() const { |
11217 | return OptimizeOffPragmaLocation; |
11218 | } |
11219 | |
11220 | /// Only called on function definitions; if there is a pragma in scope |
11221 | /// with the effect of a range-based optnone, consider marking the function |
11222 | /// with attribute optnone. |
11223 | void AddRangeBasedOptnone(FunctionDecl *FD); |
11224 | |
11225 | /// Only called on function definitions; if there is a `#pragma alloc_text` |
11226 | /// that decides which code section the function should be in, add |
11227 | /// attribute section to the function. |
11228 | void AddSectionMSAllocText(FunctionDecl *FD); |
11229 | |
11230 | /// Adds the 'optnone' attribute to the function declaration if there |
11231 | /// are no conflicts; Loc represents the location causing the 'optnone' |
11232 | /// attribute to be added (usually because of a pragma). |
11233 | void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc); |
11234 | |
11235 | /// Only called on function definitions; if there is a MSVC #pragma optimize |
11236 | /// in scope, consider changing the function's attributes based on the |
11237 | /// optimization list passed to the pragma. |
11238 | void ModifyFnAttributesMSPragmaOptimize(FunctionDecl *FD); |
11239 | |
11240 | /// Only called on function definitions; if there is a pragma in scope |
11241 | /// with the effect of a range-based no_builtin, consider marking the function |
11242 | /// with attribute no_builtin. |
11243 | void AddImplicitMSFunctionNoBuiltinAttr(FunctionDecl *FD); |
11244 | |
11245 | /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. |
11246 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
11247 | bool IsPackExpansion); |
11248 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, TypeSourceInfo *T, |
11249 | bool IsPackExpansion); |
11250 | |
11251 | /// AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular |
11252 | /// declaration. |
11253 | void AddAssumeAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
11254 | Expr *OE); |
11255 | |
11256 | /// AddAllocAlignAttr - Adds an alloc_align attribute to a particular |
11257 | /// declaration. |
11258 | void AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI, |
11259 | Expr *ParamExpr); |
11260 | |
11261 | /// AddAlignValueAttr - Adds an align_value attribute to a particular |
11262 | /// declaration. |
11263 | void AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E); |
11264 | |
11265 | /// AddAnnotationAttr - Adds an annotation Annot with Args arguments to D. |
11266 | void AddAnnotationAttr(Decl *D, const AttributeCommonInfo &CI, |
11267 | StringRef Annot, MutableArrayRef<Expr *> Args); |
11268 | |
11269 | /// ConstantFoldAttrArgs - Folds attribute arguments into ConstantExprs |
11270 | /// (unless they are value dependent or type dependent). Returns false |
11271 | /// and emits a diagnostic if one or more of the arguments could not be |
11272 | /// folded into a constant. |
11273 | bool ConstantFoldAttrArgs(const AttributeCommonInfo &CI, |
11274 | MutableArrayRef<Expr *> Args); |
11275 | |
11276 | /// Create an CUDALaunchBoundsAttr attribute. |
11277 | CUDALaunchBoundsAttr *CreateLaunchBoundsAttr(const AttributeCommonInfo &CI, |
11278 | Expr *MaxThreads, |
11279 | Expr *MinBlocks, |
11280 | Expr *MaxBlocks); |
11281 | |
11282 | /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular |
11283 | /// declaration. |
11284 | void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI, |
11285 | Expr *MaxThreads, Expr *MinBlocks, Expr *MaxBlocks); |
11286 | |
11287 | /// AddModeAttr - Adds a mode attribute to a particular declaration. |
11288 | void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Name, |
11289 | bool InInstantiation = false); |
11290 | |
11291 | void AddParameterABIAttr(Decl *D, const AttributeCommonInfo &CI, |
11292 | ParameterABI ABI); |
11293 | |
11294 | enum class RetainOwnershipKind {NS, CF, OS}; |
11295 | void AddXConsumedAttr(Decl *D, const AttributeCommonInfo &CI, |
11296 | RetainOwnershipKind K, bool IsTemplateInstantiation); |
11297 | |
11298 | /// Create an AMDGPUWavesPerEUAttr attribute. |
11299 | AMDGPUFlatWorkGroupSizeAttr * |
11300 | CreateAMDGPUFlatWorkGroupSizeAttr(const AttributeCommonInfo &CI, Expr *Min, |
11301 | Expr *Max); |
11302 | |
11303 | /// addAMDGPUFlatWorkGroupSizeAttr - Adds an amdgpu_flat_work_group_size |
11304 | /// attribute to a particular declaration. |
11305 | void addAMDGPUFlatWorkGroupSizeAttr(Decl *D, const AttributeCommonInfo &CI, |
11306 | Expr *Min, Expr *Max); |
11307 | |
11308 | /// Create an AMDGPUWavesPerEUAttr attribute. |
11309 | AMDGPUWavesPerEUAttr * |
11310 | CreateAMDGPUWavesPerEUAttr(const AttributeCommonInfo &CI, Expr *Min, |
11311 | Expr *Max); |
11312 | |
11313 | /// addAMDGPUWavePersEUAttr - Adds an amdgpu_waves_per_eu attribute to a |
11314 | /// particular declaration. |
11315 | void addAMDGPUWavesPerEUAttr(Decl *D, const AttributeCommonInfo &CI, |
11316 | Expr *Min, Expr *Max); |
11317 | |
11318 | bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type); |
11319 | |
11320 | //===--------------------------------------------------------------------===// |
11321 | // C++ Coroutines |
11322 | // |
11323 | bool ActOnCoroutineBodyStart(Scope *S, SourceLocation KwLoc, |
11324 | StringRef Keyword); |
11325 | ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
11326 | ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
11327 | StmtResult ActOnCoreturnStmt(Scope *S, SourceLocation KwLoc, Expr *E); |
11328 | |
11329 | ExprResult BuildOperatorCoawaitLookupExpr(Scope *S, SourceLocation Loc); |
11330 | ExprResult BuildOperatorCoawaitCall(SourceLocation Loc, Expr *E, |
11331 | UnresolvedLookupExpr *Lookup); |
11332 | ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, |
11333 | Expr *Awaiter, bool IsImplicit = false); |
11334 | ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, |
11335 | UnresolvedLookupExpr *Lookup); |
11336 | ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E); |
11337 | StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E, |
11338 | bool IsImplicit = false); |
11339 | StmtResult BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs); |
11340 | bool buildCoroutineParameterMoves(SourceLocation Loc); |
11341 | VarDecl *buildCoroutinePromise(SourceLocation Loc); |
11342 | void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body); |
11343 | |
11344 | // Heuristically tells if the function is `get_return_object` member of a |
11345 | // coroutine promise_type by matching the function name. |
11346 | static bool CanBeGetReturnObject(const FunctionDecl *FD); |
11347 | static bool CanBeGetReturnTypeOnAllocFailure(const FunctionDecl *FD); |
11348 | |
11349 | // As a clang extension, enforces that a non-coroutine function must be marked |
11350 | // with [[clang::coro_wrapper]] if it returns a type marked with |
11351 | // [[clang::coro_return_type]]. |
11352 | // Expects that FD is not a coroutine. |
11353 | void CheckCoroutineWrapper(FunctionDecl *FD); |
11354 | /// Lookup 'coroutine_traits' in std namespace and std::experimental |
11355 | /// namespace. The namespace found is recorded in Namespace. |
11356 | ClassTemplateDecl *lookupCoroutineTraits(SourceLocation KwLoc, |
11357 | SourceLocation FuncLoc); |
11358 | /// Check that the expression co_await promise.final_suspend() shall not be |
11359 | /// potentially-throwing. |
11360 | bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend); |
11361 | |
11362 | //===--------------------------------------------------------------------===// |
11363 | // OpenMP directives and clauses. |
11364 | // |
11365 | private: |
11366 | void *VarDataSharingAttributesStack; |
11367 | |
11368 | struct DeclareTargetContextInfo { |
11369 | struct MapInfo { |
11370 | OMPDeclareTargetDeclAttr::MapTypeTy MT; |
11371 | SourceLocation Loc; |
11372 | }; |
11373 | /// Explicitly listed variables and functions in a 'to' or 'link' clause. |
11374 | llvm::DenseMap<NamedDecl *, MapInfo> ExplicitlyMapped; |
11375 | |
11376 | /// The 'device_type' as parsed from the clause. |
11377 | OMPDeclareTargetDeclAttr::DevTypeTy DT = OMPDeclareTargetDeclAttr::DT_Any; |
11378 | |
11379 | /// The directive kind, `begin declare target` or `declare target`. |
11380 | OpenMPDirectiveKind Kind; |
11381 | |
11382 | /// The directive with indirect clause. |
11383 | std::optional<Expr *> Indirect; |
11384 | |
11385 | /// The directive location. |
11386 | SourceLocation Loc; |
11387 | |
11388 | DeclareTargetContextInfo(OpenMPDirectiveKind Kind, SourceLocation Loc) |
11389 | : Kind(Kind), Loc(Loc) {} |
11390 | }; |
11391 | |
11392 | /// Number of nested '#pragma omp declare target' directives. |
11393 | SmallVector<DeclareTargetContextInfo, 4> DeclareTargetNesting; |
11394 | |
11395 | /// Initialization of data-sharing attributes stack. |
11396 | void InitDataSharingAttributesStack(); |
11397 | void DestroyDataSharingAttributesStack(); |
11398 | |
11399 | /// Returns OpenMP nesting level for current directive. |
11400 | unsigned getOpenMPNestingLevel() const; |
11401 | |
11402 | /// Adjusts the function scopes index for the target-based regions. |
11403 | void adjustOpenMPTargetScopeIndex(unsigned &FunctionScopesIndex, |
11404 | unsigned Level) const; |
11405 | |
11406 | /// Returns the number of scopes associated with the construct on the given |
11407 | /// OpenMP level. |
11408 | int getNumberOfConstructScopes(unsigned Level) const; |
11409 | |
11410 | /// Push new OpenMP function region for non-capturing function. |
11411 | void pushOpenMPFunctionRegion(); |
11412 | |
11413 | /// Pop OpenMP function region for non-capturing function. |
11414 | void popOpenMPFunctionRegion(const sema::FunctionScopeInfo *OldFSI); |
11415 | |
11416 | /// Analyzes and checks a loop nest for use by a loop transformation. |
11417 | /// |
11418 | /// \param Kind The loop transformation directive kind. |
11419 | /// \param NumLoops How many nested loops the directive is expecting. |
11420 | /// \param AStmt Associated statement of the transformation directive. |
11421 | /// \param LoopHelpers [out] The loop analysis result. |
11422 | /// \param Body [out] The body code nested in \p NumLoops loop. |
11423 | /// \param OriginalInits [out] Collection of statements and declarations that |
11424 | /// must have been executed/declared before entering the |
11425 | /// loop. |
11426 | /// |
11427 | /// \return Whether there was any error. |
11428 | bool checkTransformableLoopNest( |
11429 | OpenMPDirectiveKind Kind, Stmt *AStmt, int NumLoops, |
11430 | SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers, |
11431 | Stmt *&Body, |
11432 | SmallVectorImpl<SmallVector<llvm::PointerUnion<Stmt *, Decl *>, 0>> |
11433 | &OriginalInits); |
11434 | |
11435 | /// Helper to keep information about the current `omp begin/end declare |
11436 | /// variant` nesting. |
11437 | struct OMPDeclareVariantScope { |
11438 | /// The associated OpenMP context selector. |
11439 | OMPTraitInfo *TI; |
11440 | |
11441 | /// The associated OpenMP context selector mangling. |
11442 | std::string NameSuffix; |
11443 | |
11444 | OMPDeclareVariantScope(OMPTraitInfo &TI); |
11445 | }; |
11446 | |
11447 | /// Return the OMPTraitInfo for the surrounding scope, if any. |
11448 | OMPTraitInfo *getOMPTraitInfoForSurroundingScope() { |
11449 | return OMPDeclareVariantScopes.empty() ? nullptr |
11450 | : OMPDeclareVariantScopes.back().TI; |
11451 | } |
11452 | |
11453 | /// The current `omp begin/end declare variant` scopes. |
11454 | SmallVector<OMPDeclareVariantScope, 4> OMPDeclareVariantScopes; |
11455 | |
11456 | /// The current `omp begin/end assumes` scopes. |
11457 | SmallVector<AssumptionAttr *, 4> OMPAssumeScoped; |
11458 | |
11459 | /// All `omp assumes` we encountered so far. |
11460 | SmallVector<AssumptionAttr *, 4> OMPAssumeGlobal; |
11461 | |
11462 | /// OMPD_loop is mapped to OMPD_for, OMPD_distribute or OMPD_simd depending |
11463 | /// on the parameter of the bind clause. In the methods for the |
11464 | /// mapped directives, check the parameters of the lastprivate clause. |
11465 | bool checkLastPrivateForMappedDirectives(ArrayRef<OMPClause *> Clauses); |
11466 | /// Depending on the bind clause of OMPD_loop map the directive to new |
11467 | /// directives. |
11468 | /// 1) loop bind(parallel) --> OMPD_for |
11469 | /// 2) loop bind(teams) --> OMPD_distribute |
11470 | /// 3) loop bind(thread) --> OMPD_simd |
11471 | /// This is being handled in Sema instead of Codegen because of the need for |
11472 | /// rigorous semantic checking in the new mapped directives. |
11473 | bool mapLoopConstruct(llvm::SmallVector<OMPClause *> &ClausesWithoutBind, |
11474 | ArrayRef<OMPClause *> Clauses, |
11475 | OpenMPBindClauseKind &BindKind, |
11476 | OpenMPDirectiveKind &Kind, |
11477 | OpenMPDirectiveKind &PrevMappedDirective, |
11478 | SourceLocation StartLoc, SourceLocation EndLoc, |
11479 | const DeclarationNameInfo &DirName, |
11480 | OpenMPDirectiveKind CancelRegion); |
11481 | |
11482 | public: |
11483 | /// The declarator \p D defines a function in the scope \p S which is nested |
11484 | /// in an `omp begin/end declare variant` scope. In this method we create a |
11485 | /// declaration for \p D and rename \p D according to the OpenMP context |
11486 | /// selector of the surrounding scope. Return all base functions in \p Bases. |
11487 | void ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope( |
11488 | Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists, |
11489 | SmallVectorImpl<FunctionDecl *> &Bases); |
11490 | |
11491 | /// Register \p D as specialization of all base functions in \p Bases in the |
11492 | /// current `omp begin/end declare variant` scope. |
11493 | void ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope( |
11494 | Decl *D, SmallVectorImpl<FunctionDecl *> &Bases); |
11495 | |
11496 | /// Act on \p D, a function definition inside of an `omp [begin/end] assumes`. |
11497 | void ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Decl *D); |
11498 | |
11499 | /// Can we exit an OpenMP declare variant scope at the moment. |
11500 | bool isInOpenMPDeclareVariantScope() const { |
11501 | return !OMPDeclareVariantScopes.empty(); |
11502 | } |
11503 | |
11504 | ExprResult |
11505 | VerifyPositiveIntegerConstantInClause(Expr *Op, OpenMPClauseKind CKind, |
11506 | bool StrictlyPositive = true, |
11507 | bool SuppressExprDiags = false); |
11508 | |
11509 | /// Given the potential call expression \p Call, determine if there is a |
11510 | /// specialization via the OpenMP declare variant mechanism available. If |
11511 | /// there is, return the specialized call expression, otherwise return the |
11512 | /// original \p Call. |
11513 | ExprResult ActOnOpenMPCall(ExprResult Call, Scope *Scope, |
11514 | SourceLocation LParenLoc, MultiExprArg ArgExprs, |
11515 | SourceLocation RParenLoc, Expr *ExecConfig); |
11516 | |
11517 | /// Handle a `omp begin declare variant`. |
11518 | void ActOnOpenMPBeginDeclareVariant(SourceLocation Loc, OMPTraitInfo &TI); |
11519 | |
11520 | /// Handle a `omp end declare variant`. |
11521 | void ActOnOpenMPEndDeclareVariant(); |
11522 | |
11523 | /// Checks if the variant/multiversion functions are compatible. |
11524 | bool areMultiversionVariantFunctionsCompatible( |
11525 | const FunctionDecl *OldFD, const FunctionDecl *NewFD, |
11526 | const PartialDiagnostic &NoProtoDiagID, |
11527 | const PartialDiagnosticAt &NoteCausedDiagIDAt, |
11528 | const PartialDiagnosticAt &NoSupportDiagIDAt, |
11529 | const PartialDiagnosticAt &DiffDiagIDAt, bool TemplatesSupported, |
11530 | bool ConstexprSupported, bool CLinkageMayDiffer); |
11531 | |
11532 | /// Function tries to capture lambda's captured variables in the OpenMP region |
11533 | /// before the original lambda is captured. |
11534 | void tryCaptureOpenMPLambdas(ValueDecl *V); |
11535 | |
11536 | /// Return true if the provided declaration \a VD should be captured by |
11537 | /// reference. |
11538 | /// \param Level Relative level of nested OpenMP construct for that the check |
11539 | /// is performed. |
11540 | /// \param OpenMPCaptureLevel Capture level within an OpenMP construct. |
11541 | bool isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level, |
11542 | unsigned OpenMPCaptureLevel) const; |
11543 | |
11544 | /// Check if the specified variable is used in one of the private |
11545 | /// clauses (private, firstprivate, lastprivate, reduction etc.) in OpenMP |
11546 | /// constructs. |
11547 | VarDecl *isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo = false, |
11548 | unsigned StopAt = 0); |
11549 | |
11550 | /// The member expression(this->fd) needs to be rebuilt in the template |
11551 | /// instantiation to generate private copy for OpenMP when default |
11552 | /// clause is used. The function will return true if default |
11553 | /// cluse is used. |
11554 | bool isOpenMPRebuildMemberExpr(ValueDecl *D); |
11555 | |
11556 | ExprResult getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
11557 | ExprObjectKind OK, SourceLocation Loc); |
11558 | |
11559 | /// If the current region is a loop-based region, mark the start of the loop |
11560 | /// construct. |
11561 | void startOpenMPLoop(); |
11562 | |
11563 | /// If the current region is a range loop-based region, mark the start of the |
11564 | /// loop construct. |
11565 | void startOpenMPCXXRangeFor(); |
11566 | |
11567 | /// Check if the specified variable is used in 'private' clause. |
11568 | /// \param Level Relative level of nested OpenMP construct for that the check |
11569 | /// is performed. |
11570 | OpenMPClauseKind isOpenMPPrivateDecl(ValueDecl *D, unsigned Level, |
11571 | unsigned CapLevel) const; |
11572 | |
11573 | /// Sets OpenMP capture kind (OMPC_private, OMPC_firstprivate, OMPC_map etc.) |
11574 | /// for \p FD based on DSA for the provided corresponding captured declaration |
11575 | /// \p D. |
11576 | void setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, unsigned Level); |
11577 | |
11578 | /// Check if the specified variable is captured by 'target' directive. |
11579 | /// \param Level Relative level of nested OpenMP construct for that the check |
11580 | /// is performed. |
11581 | bool isOpenMPTargetCapturedDecl(const ValueDecl *D, unsigned Level, |
11582 | unsigned CaptureLevel) const; |
11583 | |
11584 | /// Check if the specified global variable must be captured by outer capture |
11585 | /// regions. |
11586 | /// \param Level Relative level of nested OpenMP construct for that |
11587 | /// the check is performed. |
11588 | bool isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level, |
11589 | unsigned CaptureLevel) const; |
11590 | |
11591 | ExprResult PerformOpenMPImplicitIntegerConversion(SourceLocation OpLoc, |
11592 | Expr *Op); |
11593 | /// Called on start of new data sharing attribute block. |
11594 | void StartOpenMPDSABlock(OpenMPDirectiveKind K, |
11595 | const DeclarationNameInfo &DirName, Scope *CurScope, |
11596 | SourceLocation Loc); |
11597 | /// Start analysis of clauses. |
11598 | void StartOpenMPClause(OpenMPClauseKind K); |
11599 | /// End analysis of clauses. |
11600 | void EndOpenMPClause(); |
11601 | /// Called on end of data sharing attribute block. |
11602 | void EndOpenMPDSABlock(Stmt *CurDirective); |
11603 | |
11604 | /// Check if the current region is an OpenMP loop region and if it is, |
11605 | /// mark loop control variable, used in \p Init for loop initialization, as |
11606 | /// private by default. |
11607 | /// \param Init First part of the for loop. |
11608 | void ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init); |
11609 | |
11610 | /// Called on well-formed '\#pragma omp metadirective' after parsing |
11611 | /// of the associated statement. |
11612 | StmtResult ActOnOpenMPMetaDirective(ArrayRef<OMPClause *> Clauses, |
11613 | Stmt *AStmt, SourceLocation StartLoc, |
11614 | SourceLocation EndLoc); |
11615 | |
11616 | // OpenMP directives and clauses. |
11617 | /// Called on correct id-expression from the '#pragma omp |
11618 | /// threadprivate'. |
11619 | ExprResult ActOnOpenMPIdExpression(Scope *CurScope, CXXScopeSpec &ScopeSpec, |
11620 | const DeclarationNameInfo &Id, |
11621 | OpenMPDirectiveKind Kind); |
11622 | /// Called on well-formed '#pragma omp threadprivate'. |
11623 | DeclGroupPtrTy ActOnOpenMPThreadprivateDirective( |
11624 | SourceLocation Loc, |
11625 | ArrayRef<Expr *> VarList); |
11626 | /// Builds a new OpenMPThreadPrivateDecl and checks its correctness. |
11627 | OMPThreadPrivateDecl *CheckOMPThreadPrivateDecl(SourceLocation Loc, |
11628 | ArrayRef<Expr *> VarList); |
11629 | /// Called on well-formed '#pragma omp allocate'. |
11630 | DeclGroupPtrTy ActOnOpenMPAllocateDirective(SourceLocation Loc, |
11631 | ArrayRef<Expr *> VarList, |
11632 | ArrayRef<OMPClause *> Clauses, |
11633 | DeclContext *Owner = nullptr); |
11634 | |
11635 | /// Called on well-formed '#pragma omp [begin] assume[s]'. |
11636 | void ActOnOpenMPAssumesDirective(SourceLocation Loc, |
11637 | OpenMPDirectiveKind DKind, |
11638 | ArrayRef<std::string> Assumptions, |
11639 | bool SkippedClauses); |
11640 | |
11641 | /// Check if there is an active global `omp begin assumes` directive. |
11642 | bool isInOpenMPAssumeScope() const { return !OMPAssumeScoped.empty(); } |
11643 | |
11644 | /// Check if there is an active global `omp assumes` directive. |
11645 | bool hasGlobalOpenMPAssumes() const { return !OMPAssumeGlobal.empty(); } |
11646 | |
11647 | /// Called on well-formed '#pragma omp end assumes'. |
11648 | void ActOnOpenMPEndAssumesDirective(); |
11649 | |
11650 | /// Called on well-formed '#pragma omp requires'. |
11651 | DeclGroupPtrTy ActOnOpenMPRequiresDirective(SourceLocation Loc, |
11652 | ArrayRef<OMPClause *> ClauseList); |
11653 | /// Check restrictions on Requires directive |
11654 | OMPRequiresDecl *CheckOMPRequiresDecl(SourceLocation Loc, |
11655 | ArrayRef<OMPClause *> Clauses); |
11656 | /// Check if the specified type is allowed to be used in 'omp declare |
11657 | /// reduction' construct. |
11658 | QualType ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
11659 | TypeResult ParsedType); |
11660 | /// Called on start of '#pragma omp declare reduction'. |
11661 | DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveStart( |
11662 | Scope *S, DeclContext *DC, DeclarationName Name, |
11663 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
11664 | AccessSpecifier AS, Decl *PrevDeclInScope = nullptr); |
11665 | /// Initialize declare reduction construct initializer. |
11666 | void ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D); |
11667 | /// Finish current declare reduction construct initializer. |
11668 | void ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner); |
11669 | /// Initialize declare reduction construct initializer. |
11670 | /// \return omp_priv variable. |
11671 | VarDecl *ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D); |
11672 | /// Finish current declare reduction construct initializer. |
11673 | void ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, Expr *Initializer, |
11674 | VarDecl *OmpPrivParm); |
11675 | /// Called at the end of '#pragma omp declare reduction'. |
11676 | DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveEnd( |
11677 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid); |
11678 | |
11679 | /// Check variable declaration in 'omp declare mapper' construct. |
11680 | TypeResult ActOnOpenMPDeclareMapperVarDecl(Scope *S, Declarator &D); |
11681 | /// Check if the specified type is allowed to be used in 'omp declare |
11682 | /// mapper' construct. |
11683 | QualType ActOnOpenMPDeclareMapperType(SourceLocation TyLoc, |
11684 | TypeResult ParsedType); |
11685 | /// Called on start of '#pragma omp declare mapper'. |
11686 | DeclGroupPtrTy ActOnOpenMPDeclareMapperDirective( |
11687 | Scope *S, DeclContext *DC, DeclarationName Name, QualType MapperType, |
11688 | SourceLocation StartLoc, DeclarationName VN, AccessSpecifier AS, |
11689 | Expr *MapperVarRef, ArrayRef<OMPClause *> Clauses, |
11690 | Decl *PrevDeclInScope = nullptr); |
11691 | /// Build the mapper variable of '#pragma omp declare mapper'. |
11692 | ExprResult ActOnOpenMPDeclareMapperDirectiveVarDecl(Scope *S, |
11693 | QualType MapperType, |
11694 | SourceLocation StartLoc, |
11695 | DeclarationName VN); |
11696 | void ActOnOpenMPIteratorVarDecl(VarDecl *VD); |
11697 | bool isOpenMPDeclareMapperVarDeclAllowed(const VarDecl *VD) const; |
11698 | const ValueDecl *getOpenMPDeclareMapperVarName() const; |
11699 | |
11700 | /// Called on the start of target region i.e. '#pragma omp declare target'. |
11701 | bool ActOnStartOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI); |
11702 | |
11703 | /// Called at the end of target region i.e. '#pragma omp end declare target'. |
11704 | const DeclareTargetContextInfo ActOnOpenMPEndDeclareTargetDirective(); |
11705 | |
11706 | /// Called once a target context is completed, that can be when a |
11707 | /// '#pragma omp end declare target' was encountered or when a |
11708 | /// '#pragma omp declare target' without declaration-definition-seq was |
11709 | /// encountered. |
11710 | void ActOnFinishedOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI); |
11711 | |
11712 | /// Report unterminated 'omp declare target' or 'omp begin declare target' at |
11713 | /// the end of a compilation unit. |
11714 | void DiagnoseUnterminatedOpenMPDeclareTarget(); |
11715 | |
11716 | /// Searches for the provided declaration name for OpenMP declare target |
11717 | /// directive. |
11718 | NamedDecl *lookupOpenMPDeclareTargetName(Scope *CurScope, |
11719 | CXXScopeSpec &ScopeSpec, |
11720 | const DeclarationNameInfo &Id); |
11721 | |
11722 | /// Called on correct id-expression from the '#pragma omp declare target'. |
11723 | void ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc, |
11724 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
11725 | DeclareTargetContextInfo &DTCI); |
11726 | |
11727 | /// Check declaration inside target region. |
11728 | void |
11729 | checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, |
11730 | SourceLocation IdLoc = SourceLocation()); |
11731 | |
11732 | /// Adds OMPDeclareTargetDeclAttr to referenced variables in declare target |
11733 | /// directive. |
11734 | void ActOnOpenMPDeclareTargetInitializer(Decl *D); |
11735 | |
11736 | /// Finishes analysis of the deferred functions calls that may be declared as |
11737 | /// host/nohost during device/host compilation. |
11738 | void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller, |
11739 | const FunctionDecl *Callee, |
11740 | SourceLocation Loc); |
11741 | |
11742 | /// Return true if currently in OpenMP task with untied clause context. |
11743 | bool isInOpenMPTaskUntiedContext() const; |
11744 | |
11745 | /// Return true inside OpenMP declare target region. |
11746 | bool isInOpenMPDeclareTargetContext() const { |
11747 | return !DeclareTargetNesting.empty(); |
11748 | } |
11749 | /// Return true inside OpenMP target region. |
11750 | bool isInOpenMPTargetExecutionDirective() const; |
11751 | |
11752 | /// Return the number of captured regions created for an OpenMP directive. |
11753 | static int getOpenMPCaptureLevels(OpenMPDirectiveKind Kind); |
11754 | |
11755 | /// Initialization of captured region for OpenMP region. |
11756 | void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope); |
11757 | |
11758 | /// Called for syntactical loops (ForStmt or CXXForRangeStmt) associated to |
11759 | /// an OpenMP loop directive. |
11760 | StmtResult ActOnOpenMPCanonicalLoop(Stmt *AStmt); |
11761 | |
11762 | /// Process a canonical OpenMP loop nest that can either be a canonical |
11763 | /// literal loop (ForStmt or CXXForRangeStmt), or the generated loop of an |
11764 | /// OpenMP loop transformation construct. |
11765 | StmtResult ActOnOpenMPLoopnest(Stmt *AStmt); |
11766 | |
11767 | /// End of OpenMP region. |
11768 | /// |
11769 | /// \param S Statement associated with the current OpenMP region. |
11770 | /// \param Clauses List of clauses for the current OpenMP region. |
11771 | /// |
11772 | /// \returns Statement for finished OpenMP region. |
11773 | StmtResult ActOnOpenMPRegionEnd(StmtResult S, ArrayRef<OMPClause *> Clauses); |
11774 | StmtResult ActOnOpenMPExecutableDirective( |
11775 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
11776 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
11777 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc, |
11778 | OpenMPDirectiveKind PrevMappedDirective = llvm::omp::OMPD_unknown); |
11779 | /// Called on well-formed '\#pragma omp parallel' after parsing |
11780 | /// of the associated statement. |
11781 | StmtResult ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
11782 | Stmt *AStmt, |
11783 | SourceLocation StartLoc, |
11784 | SourceLocation EndLoc); |
11785 | using VarsWithInheritedDSAType = |
11786 | llvm::SmallDenseMap<const ValueDecl *, const Expr *, 4>; |
11787 | /// Called on well-formed '\#pragma omp simd' after parsing |
11788 | /// of the associated statement. |
11789 | StmtResult |
11790 | ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
11791 | SourceLocation StartLoc, SourceLocation EndLoc, |
11792 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11793 | /// Called on well-formed '#pragma omp tile' after parsing of its clauses and |
11794 | /// the associated statement. |
11795 | StmtResult ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses, |
11796 | Stmt *AStmt, SourceLocation StartLoc, |
11797 | SourceLocation EndLoc); |
11798 | /// Called on well-formed '#pragma omp unroll' after parsing of its clauses |
11799 | /// and the associated statement. |
11800 | StmtResult ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses, |
11801 | Stmt *AStmt, SourceLocation StartLoc, |
11802 | SourceLocation EndLoc); |
11803 | /// Called on well-formed '\#pragma omp for' after parsing |
11804 | /// of the associated statement. |
11805 | StmtResult |
11806 | ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
11807 | SourceLocation StartLoc, SourceLocation EndLoc, |
11808 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11809 | /// Called on well-formed '\#pragma omp for simd' after parsing |
11810 | /// of the associated statement. |
11811 | StmtResult |
11812 | ActOnOpenMPForSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
11813 | SourceLocation StartLoc, SourceLocation EndLoc, |
11814 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11815 | /// Called on well-formed '\#pragma omp sections' after parsing |
11816 | /// of the associated statement. |
11817 | StmtResult ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
11818 | Stmt *AStmt, SourceLocation StartLoc, |
11819 | SourceLocation EndLoc); |
11820 | /// Called on well-formed '\#pragma omp section' after parsing of the |
11821 | /// associated statement. |
11822 | StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc, |
11823 | SourceLocation EndLoc); |
11824 | /// Called on well-formed '\#pragma omp scope' after parsing of the |
11825 | /// associated statement. |
11826 | StmtResult ActOnOpenMPScopeDirective(ArrayRef<OMPClause *> Clauses, |
11827 | Stmt *AStmt, SourceLocation StartLoc, |
11828 | SourceLocation EndLoc); |
11829 | /// Called on well-formed '\#pragma omp single' after parsing of the |
11830 | /// associated statement. |
11831 | StmtResult ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
11832 | Stmt *AStmt, SourceLocation StartLoc, |
11833 | SourceLocation EndLoc); |
11834 | /// Called on well-formed '\#pragma omp master' after parsing of the |
11835 | /// associated statement. |
11836 | StmtResult ActOnOpenMPMasterDirective(Stmt *AStmt, SourceLocation StartLoc, |
11837 | SourceLocation EndLoc); |
11838 | /// Called on well-formed '\#pragma omp critical' after parsing of the |
11839 | /// associated statement. |
11840 | StmtResult ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
11841 | ArrayRef<OMPClause *> Clauses, |
11842 | Stmt *AStmt, SourceLocation StartLoc, |
11843 | SourceLocation EndLoc); |
11844 | /// Called on well-formed '\#pragma omp parallel for' after parsing |
11845 | /// of the associated statement. |
11846 | StmtResult ActOnOpenMPParallelForDirective( |
11847 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11848 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11849 | /// Called on well-formed '\#pragma omp parallel for simd' after |
11850 | /// parsing of the associated statement. |
11851 | StmtResult ActOnOpenMPParallelForSimdDirective( |
11852 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11853 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11854 | /// Called on well-formed '\#pragma omp parallel master' after |
11855 | /// parsing of the associated statement. |
11856 | StmtResult ActOnOpenMPParallelMasterDirective(ArrayRef<OMPClause *> Clauses, |
11857 | Stmt *AStmt, |
11858 | SourceLocation StartLoc, |
11859 | SourceLocation EndLoc); |
11860 | /// Called on well-formed '\#pragma omp parallel masked' after |
11861 | /// parsing of the associated statement. |
11862 | StmtResult ActOnOpenMPParallelMaskedDirective(ArrayRef<OMPClause *> Clauses, |
11863 | Stmt *AStmt, |
11864 | SourceLocation StartLoc, |
11865 | SourceLocation EndLoc); |
11866 | /// Called on well-formed '\#pragma omp parallel sections' after |
11867 | /// parsing of the associated statement. |
11868 | StmtResult ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
11869 | Stmt *AStmt, |
11870 | SourceLocation StartLoc, |
11871 | SourceLocation EndLoc); |
11872 | /// Called on well-formed '\#pragma omp task' after parsing of the |
11873 | /// associated statement. |
11874 | StmtResult ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
11875 | Stmt *AStmt, SourceLocation StartLoc, |
11876 | SourceLocation EndLoc); |
11877 | /// Called on well-formed '\#pragma omp taskyield'. |
11878 | StmtResult ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
11879 | SourceLocation EndLoc); |
11880 | /// Called on well-formed '\#pragma omp error'. |
11881 | /// Error direcitive is allowed in both declared and excutable contexts. |
11882 | /// Adding InExContext to identify which context is called from. |
11883 | StmtResult ActOnOpenMPErrorDirective(ArrayRef<OMPClause *> Clauses, |
11884 | SourceLocation StartLoc, |
11885 | SourceLocation EndLoc, |
11886 | bool InExContext = true); |
11887 | /// Called on well-formed '\#pragma omp barrier'. |
11888 | StmtResult ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
11889 | SourceLocation EndLoc); |
11890 | /// Called on well-formed '\#pragma omp taskwait'. |
11891 | StmtResult ActOnOpenMPTaskwaitDirective(ArrayRef<OMPClause *> Clauses, |
11892 | SourceLocation StartLoc, |
11893 | SourceLocation EndLoc); |
11894 | /// Called on well-formed '\#pragma omp taskgroup'. |
11895 | StmtResult ActOnOpenMPTaskgroupDirective(ArrayRef<OMPClause *> Clauses, |
11896 | Stmt *AStmt, SourceLocation StartLoc, |
11897 | SourceLocation EndLoc); |
11898 | /// Called on well-formed '\#pragma omp flush'. |
11899 | StmtResult ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
11900 | SourceLocation StartLoc, |
11901 | SourceLocation EndLoc); |
11902 | /// Called on well-formed '\#pragma omp depobj'. |
11903 | StmtResult ActOnOpenMPDepobjDirective(ArrayRef<OMPClause *> Clauses, |
11904 | SourceLocation StartLoc, |
11905 | SourceLocation EndLoc); |
11906 | /// Called on well-formed '\#pragma omp scan'. |
11907 | StmtResult ActOnOpenMPScanDirective(ArrayRef<OMPClause *> Clauses, |
11908 | SourceLocation StartLoc, |
11909 | SourceLocation EndLoc); |
11910 | /// Called on well-formed '\#pragma omp ordered' after parsing of the |
11911 | /// associated statement. |
11912 | StmtResult ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
11913 | Stmt *AStmt, SourceLocation StartLoc, |
11914 | SourceLocation EndLoc); |
11915 | /// Called on well-formed '\#pragma omp atomic' after parsing of the |
11916 | /// associated statement. |
11917 | StmtResult ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
11918 | Stmt *AStmt, SourceLocation StartLoc, |
11919 | SourceLocation EndLoc); |
11920 | /// Called on well-formed '\#pragma omp target' after parsing of the |
11921 | /// associated statement. |
11922 | StmtResult ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
11923 | Stmt *AStmt, SourceLocation StartLoc, |
11924 | SourceLocation EndLoc); |
11925 | /// Called on well-formed '\#pragma omp target data' after parsing of |
11926 | /// the associated statement. |
11927 | StmtResult ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
11928 | Stmt *AStmt, SourceLocation StartLoc, |
11929 | SourceLocation EndLoc); |
11930 | /// Called on well-formed '\#pragma omp target enter data' after |
11931 | /// parsing of the associated statement. |
11932 | StmtResult ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
11933 | SourceLocation StartLoc, |
11934 | SourceLocation EndLoc, |
11935 | Stmt *AStmt); |
11936 | /// Called on well-formed '\#pragma omp target exit data' after |
11937 | /// parsing of the associated statement. |
11938 | StmtResult ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
11939 | SourceLocation StartLoc, |
11940 | SourceLocation EndLoc, |
11941 | Stmt *AStmt); |
11942 | /// Called on well-formed '\#pragma omp target parallel' after |
11943 | /// parsing of the associated statement. |
11944 | StmtResult ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
11945 | Stmt *AStmt, |
11946 | SourceLocation StartLoc, |
11947 | SourceLocation EndLoc); |
11948 | /// Called on well-formed '\#pragma omp target parallel for' after |
11949 | /// parsing of the associated statement. |
11950 | StmtResult ActOnOpenMPTargetParallelForDirective( |
11951 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11952 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11953 | /// Called on well-formed '\#pragma omp teams' after parsing of the |
11954 | /// associated statement. |
11955 | StmtResult ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
11956 | Stmt *AStmt, SourceLocation StartLoc, |
11957 | SourceLocation EndLoc); |
11958 | /// Called on well-formed '\#pragma omp teams loop' after parsing of the |
11959 | /// associated statement. |
11960 | StmtResult ActOnOpenMPTeamsGenericLoopDirective( |
11961 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11962 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11963 | /// Called on well-formed '\#pragma omp target teams loop' after parsing of |
11964 | /// the associated statement. |
11965 | StmtResult ActOnOpenMPTargetTeamsGenericLoopDirective( |
11966 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11967 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11968 | /// Called on well-formed '\#pragma omp parallel loop' after parsing of the |
11969 | /// associated statement. |
11970 | StmtResult ActOnOpenMPParallelGenericLoopDirective( |
11971 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11972 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11973 | /// Called on well-formed '\#pragma omp target parallel loop' after parsing |
11974 | /// of the associated statement. |
11975 | StmtResult ActOnOpenMPTargetParallelGenericLoopDirective( |
11976 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11977 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11978 | /// Called on well-formed '\#pragma omp cancellation point'. |
11979 | StmtResult |
11980 | ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
11981 | SourceLocation EndLoc, |
11982 | OpenMPDirectiveKind CancelRegion); |
11983 | /// Called on well-formed '\#pragma omp cancel'. |
11984 | StmtResult ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
11985 | SourceLocation StartLoc, |
11986 | SourceLocation EndLoc, |
11987 | OpenMPDirectiveKind CancelRegion); |
11988 | /// Called on well-formed '\#pragma omp taskloop' after parsing of the |
11989 | /// associated statement. |
11990 | StmtResult |
11991 | ActOnOpenMPTaskLoopDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
11992 | SourceLocation StartLoc, SourceLocation EndLoc, |
11993 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11994 | /// Called on well-formed '\#pragma omp taskloop simd' after parsing of |
11995 | /// the associated statement. |
11996 | StmtResult ActOnOpenMPTaskLoopSimdDirective( |
11997 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11998 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11999 | /// Called on well-formed '\#pragma omp master taskloop' after parsing of the |
12000 | /// associated statement. |
12001 | StmtResult ActOnOpenMPMasterTaskLoopDirective( |
12002 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12003 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12004 | /// Called on well-formed '\#pragma omp master taskloop simd' after parsing of |
12005 | /// the associated statement. |
12006 | StmtResult ActOnOpenMPMasterTaskLoopSimdDirective( |
12007 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12008 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12009 | /// Called on well-formed '\#pragma omp parallel master taskloop' after |
12010 | /// parsing of the associated statement. |
12011 | StmtResult ActOnOpenMPParallelMasterTaskLoopDirective( |
12012 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12013 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12014 | /// Called on well-formed '\#pragma omp parallel master taskloop simd' after |
12015 | /// parsing of the associated statement. |
12016 | StmtResult ActOnOpenMPParallelMasterTaskLoopSimdDirective( |
12017 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12018 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12019 | /// Called on well-formed '\#pragma omp masked taskloop' after parsing of the |
12020 | /// associated statement. |
12021 | StmtResult ActOnOpenMPMaskedTaskLoopDirective( |
12022 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12023 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12024 | /// Called on well-formed '\#pragma omp masked taskloop simd' after parsing of |
12025 | /// the associated statement. |
12026 | StmtResult ActOnOpenMPMaskedTaskLoopSimdDirective( |
12027 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12028 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12029 | /// Called on well-formed '\#pragma omp parallel masked taskloop' after |
12030 | /// parsing of the associated statement. |
12031 | StmtResult ActOnOpenMPParallelMaskedTaskLoopDirective( |
12032 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12033 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12034 | /// Called on well-formed '\#pragma omp parallel masked taskloop simd' after |
12035 | /// parsing of the associated statement. |
12036 | StmtResult ActOnOpenMPParallelMaskedTaskLoopSimdDirective( |
12037 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12038 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12039 | /// Called on well-formed '\#pragma omp distribute' after parsing |
12040 | /// of the associated statement. |
12041 | StmtResult |
12042 | ActOnOpenMPDistributeDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
12043 | SourceLocation StartLoc, SourceLocation EndLoc, |
12044 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12045 | /// Called on well-formed '\#pragma omp target update'. |
12046 | StmtResult ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
12047 | SourceLocation StartLoc, |
12048 | SourceLocation EndLoc, |
12049 | Stmt *AStmt); |
12050 | /// Called on well-formed '\#pragma omp distribute parallel for' after |
12051 | /// parsing of the associated statement. |
12052 | StmtResult ActOnOpenMPDistributeParallelForDirective( |
12053 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12054 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12055 | /// Called on well-formed '\#pragma omp distribute parallel for simd' |
12056 | /// after parsing of the associated statement. |
12057 | StmtResult ActOnOpenMPDistributeParallelForSimdDirective( |
12058 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12059 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12060 | /// Called on well-formed '\#pragma omp distribute simd' after |
12061 | /// parsing of the associated statement. |
12062 | StmtResult ActOnOpenMPDistributeSimdDirective( |
12063 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12064 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12065 | /// Called on well-formed '\#pragma omp target parallel for simd' after |
12066 | /// parsing of the associated statement. |
12067 | StmtResult ActOnOpenMPTargetParallelForSimdDirective( |
12068 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12069 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12070 | /// Called on well-formed '\#pragma omp target simd' after parsing of |
12071 | /// the associated statement. |
12072 | StmtResult |
12073 | ActOnOpenMPTargetSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
12074 | SourceLocation StartLoc, SourceLocation EndLoc, |
12075 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12076 | /// Called on well-formed '\#pragma omp teams distribute' after parsing of |
12077 | /// the associated statement. |
12078 | StmtResult ActOnOpenMPTeamsDistributeDirective( |
12079 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12080 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12081 | /// Called on well-formed '\#pragma omp teams distribute simd' after parsing |
12082 | /// of the associated statement. |
12083 | StmtResult ActOnOpenMPTeamsDistributeSimdDirective( |
12084 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12085 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12086 | /// Called on well-formed '\#pragma omp teams distribute parallel for simd' |
12087 | /// after parsing of the associated statement. |
12088 | StmtResult ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
12089 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12090 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12091 | /// Called on well-formed '\#pragma omp teams distribute parallel for' |
12092 | /// after parsing of the associated statement. |
12093 | StmtResult ActOnOpenMPTeamsDistributeParallelForDirective( |
12094 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12095 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12096 | /// Called on well-formed '\#pragma omp target teams' after parsing of the |
12097 | /// associated statement. |
12098 | StmtResult ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses, |
12099 | Stmt *AStmt, |
12100 | SourceLocation StartLoc, |
12101 | SourceLocation EndLoc); |
12102 | /// Called on well-formed '\#pragma omp target teams distribute' after parsing |
12103 | /// of the associated statement. |
12104 | StmtResult ActOnOpenMPTargetTeamsDistributeDirective( |
12105 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12106 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12107 | /// Called on well-formed '\#pragma omp target teams distribute parallel for' |
12108 | /// after parsing of the associated statement. |
12109 | StmtResult ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
12110 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12111 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12112 | /// Called on well-formed '\#pragma omp target teams distribute parallel for |
12113 | /// simd' after parsing of the associated statement. |
12114 | StmtResult ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
12115 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12116 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12117 | /// Called on well-formed '\#pragma omp target teams distribute simd' after |
12118 | /// parsing of the associated statement. |
12119 | StmtResult ActOnOpenMPTargetTeamsDistributeSimdDirective( |
12120 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12121 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12122 | /// Called on well-formed '\#pragma omp interop'. |
12123 | StmtResult ActOnOpenMPInteropDirective(ArrayRef<OMPClause *> Clauses, |
12124 | SourceLocation StartLoc, |
12125 | SourceLocation EndLoc); |
12126 | /// Called on well-formed '\#pragma omp dispatch' after parsing of the |
12127 | // /associated statement. |
12128 | StmtResult ActOnOpenMPDispatchDirective(ArrayRef<OMPClause *> Clauses, |
12129 | Stmt *AStmt, SourceLocation StartLoc, |
12130 | SourceLocation EndLoc); |
12131 | /// Called on well-formed '\#pragma omp masked' after parsing of the |
12132 | // /associated statement. |
12133 | StmtResult ActOnOpenMPMaskedDirective(ArrayRef<OMPClause *> Clauses, |
12134 | Stmt *AStmt, SourceLocation StartLoc, |
12135 | SourceLocation EndLoc); |
12136 | |
12137 | /// Called on well-formed '\#pragma omp loop' after parsing of the |
12138 | /// associated statement. |
12139 | StmtResult ActOnOpenMPGenericLoopDirective( |
12140 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
12141 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
12142 | |
12143 | /// Checks correctness of linear modifiers. |
12144 | bool CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
12145 | SourceLocation LinLoc); |
12146 | /// Checks that the specified declaration matches requirements for the linear |
12147 | /// decls. |
12148 | bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc, |
12149 | OpenMPLinearClauseKind LinKind, QualType Type, |
12150 | bool IsDeclareSimd = false); |
12151 | |
12152 | /// Called on well-formed '\#pragma omp declare simd' after parsing of |
12153 | /// the associated method/function. |
12154 | DeclGroupPtrTy ActOnOpenMPDeclareSimdDirective( |
12155 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, |
12156 | Expr *Simdlen, ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
12157 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
12158 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR); |
12159 | |
12160 | /// Checks '\#pragma omp declare variant' variant function and original |
12161 | /// functions after parsing of the associated method/function. |
12162 | /// \param DG Function declaration to which declare variant directive is |
12163 | /// applied to. |
12164 | /// \param VariantRef Expression that references the variant function, which |
12165 | /// must be used instead of the original one, specified in \p DG. |
12166 | /// \param TI The trait info object representing the match clause. |
12167 | /// \param NumAppendArgs The number of omp_interop_t arguments to account for |
12168 | /// in checking. |
12169 | /// \returns std::nullopt, if the function/variant function are not compatible |
12170 | /// with the pragma, pair of original function/variant ref expression |
12171 | /// otherwise. |
12172 | std::optional<std::pair<FunctionDecl *, Expr *>> |
12173 | checkOpenMPDeclareVariantFunction(DeclGroupPtrTy DG, Expr *VariantRef, |
12174 | OMPTraitInfo &TI, unsigned NumAppendArgs, |
12175 | SourceRange SR); |
12176 | |
12177 | /// Called on well-formed '\#pragma omp declare variant' after parsing of |
12178 | /// the associated method/function. |
12179 | /// \param FD Function declaration to which declare variant directive is |
12180 | /// applied to. |
12181 | /// \param VariantRef Expression that references the variant function, which |
12182 | /// must be used instead of the original one, specified in \p DG. |
12183 | /// \param TI The context traits associated with the function variant. |
12184 | /// \param AdjustArgsNothing The list of 'nothing' arguments. |
12185 | /// \param AdjustArgsNeedDevicePtr The list of 'need_device_ptr' arguments. |
12186 | /// \param AppendArgs The list of 'append_args' arguments. |
12187 | /// \param AdjustArgsLoc The Location of an 'adjust_args' clause. |
12188 | /// \param AppendArgsLoc The Location of an 'append_args' clause. |
12189 | /// \param SR The SourceRange of the 'declare variant' directive. |
12190 | void ActOnOpenMPDeclareVariantDirective( |
12191 | FunctionDecl *FD, Expr *VariantRef, OMPTraitInfo &TI, |
12192 | ArrayRef<Expr *> AdjustArgsNothing, |
12193 | ArrayRef<Expr *> AdjustArgsNeedDevicePtr, |
12194 | ArrayRef<OMPInteropInfo> AppendArgs, SourceLocation AdjustArgsLoc, |
12195 | SourceLocation AppendArgsLoc, SourceRange SR); |
12196 | |
12197 | OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, |
12198 | Expr *Expr, |
12199 | SourceLocation StartLoc, |
12200 | SourceLocation LParenLoc, |
12201 | SourceLocation EndLoc); |
12202 | /// Called on well-formed 'allocator' clause. |
12203 | OMPClause *ActOnOpenMPAllocatorClause(Expr *Allocator, |
12204 | SourceLocation StartLoc, |
12205 | SourceLocation LParenLoc, |
12206 | SourceLocation EndLoc); |
12207 | /// Called on well-formed 'if' clause. |
12208 | OMPClause *ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
12209 | Expr *Condition, SourceLocation StartLoc, |
12210 | SourceLocation LParenLoc, |
12211 | SourceLocation NameModifierLoc, |
12212 | SourceLocation ColonLoc, |
12213 | SourceLocation EndLoc); |
12214 | /// Called on well-formed 'final' clause. |
12215 | OMPClause *ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
12216 | SourceLocation LParenLoc, |
12217 | SourceLocation EndLoc); |
12218 | /// Called on well-formed 'num_threads' clause. |
12219 | OMPClause *ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
12220 | SourceLocation StartLoc, |
12221 | SourceLocation LParenLoc, |
12222 | SourceLocation EndLoc); |
12223 | /// Called on well-formed 'align' clause. |
12224 | OMPClause *ActOnOpenMPAlignClause(Expr *Alignment, SourceLocation StartLoc, |
12225 | SourceLocation LParenLoc, |
12226 | SourceLocation EndLoc); |
12227 | /// Called on well-formed 'safelen' clause. |
12228 | OMPClause *ActOnOpenMPSafelenClause(Expr *Length, |
12229 | SourceLocation StartLoc, |
12230 | SourceLocation LParenLoc, |
12231 | SourceLocation EndLoc); |
12232 | /// Called on well-formed 'simdlen' clause. |
12233 | OMPClause *ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc, |
12234 | SourceLocation LParenLoc, |
12235 | SourceLocation EndLoc); |
12236 | /// Called on well-form 'sizes' clause. |
12237 | OMPClause *ActOnOpenMPSizesClause(ArrayRef<Expr *> SizeExprs, |
12238 | SourceLocation StartLoc, |
12239 | SourceLocation LParenLoc, |
12240 | SourceLocation EndLoc); |
12241 | /// Called on well-form 'full' clauses. |
12242 | OMPClause *ActOnOpenMPFullClause(SourceLocation StartLoc, |
12243 | SourceLocation EndLoc); |
12244 | /// Called on well-form 'partial' clauses. |
12245 | OMPClause *ActOnOpenMPPartialClause(Expr *FactorExpr, SourceLocation StartLoc, |
12246 | SourceLocation LParenLoc, |
12247 | SourceLocation EndLoc); |
12248 | /// Called on well-formed 'collapse' clause. |
12249 | OMPClause *ActOnOpenMPCollapseClause(Expr *NumForLoops, |
12250 | SourceLocation StartLoc, |
12251 | SourceLocation LParenLoc, |
12252 | SourceLocation EndLoc); |
12253 | /// Called on well-formed 'ordered' clause. |
12254 | OMPClause * |
12255 | ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, |
12256 | SourceLocation LParenLoc = SourceLocation(), |
12257 | Expr *NumForLoops = nullptr); |
12258 | /// Called on well-formed 'grainsize' clause. |
12259 | OMPClause *ActOnOpenMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, |
12260 | Expr *Size, SourceLocation StartLoc, |
12261 | SourceLocation LParenLoc, |
12262 | SourceLocation ModifierLoc, |
12263 | SourceLocation EndLoc); |
12264 | /// Called on well-formed 'num_tasks' clause. |
12265 | OMPClause *ActOnOpenMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, |
12266 | Expr *NumTasks, SourceLocation StartLoc, |
12267 | SourceLocation LParenLoc, |
12268 | SourceLocation ModifierLoc, |
12269 | SourceLocation EndLoc); |
12270 | /// Called on well-formed 'hint' clause. |
12271 | OMPClause *ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
12272 | SourceLocation LParenLoc, |
12273 | SourceLocation EndLoc); |
12274 | /// Called on well-formed 'detach' clause. |
12275 | OMPClause *ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc, |
12276 | SourceLocation LParenLoc, |
12277 | SourceLocation EndLoc); |
12278 | |
12279 | OMPClause *ActOnOpenMPSimpleClause(OpenMPClauseKind Kind, |
12280 | unsigned Argument, |
12281 | SourceLocation ArgumentLoc, |
12282 | SourceLocation StartLoc, |
12283 | SourceLocation LParenLoc, |
12284 | SourceLocation EndLoc); |
12285 | /// Called on well-formed 'when' clause. |
12286 | OMPClause *ActOnOpenMPWhenClause(OMPTraitInfo &TI, SourceLocation StartLoc, |
12287 | SourceLocation LParenLoc, |
12288 | SourceLocation EndLoc); |
12289 | /// Called on well-formed 'default' clause. |
12290 | OMPClause *ActOnOpenMPDefaultClause(llvm::omp::DefaultKind Kind, |
12291 | SourceLocation KindLoc, |
12292 | SourceLocation StartLoc, |
12293 | SourceLocation LParenLoc, |
12294 | SourceLocation EndLoc); |
12295 | /// Called on well-formed 'proc_bind' clause. |
12296 | OMPClause *ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind, |
12297 | SourceLocation KindLoc, |
12298 | SourceLocation StartLoc, |
12299 | SourceLocation LParenLoc, |
12300 | SourceLocation EndLoc); |
12301 | /// Called on well-formed 'order' clause. |
12302 | OMPClause *ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier, |
12303 | OpenMPOrderClauseKind Kind, |
12304 | SourceLocation StartLoc, |
12305 | SourceLocation LParenLoc, |
12306 | SourceLocation MLoc, SourceLocation KindLoc, |
12307 | SourceLocation EndLoc); |
12308 | /// Called on well-formed 'update' clause. |
12309 | OMPClause *ActOnOpenMPUpdateClause(OpenMPDependClauseKind Kind, |
12310 | SourceLocation KindLoc, |
12311 | SourceLocation StartLoc, |
12312 | SourceLocation LParenLoc, |
12313 | SourceLocation EndLoc); |
12314 | |
12315 | OMPClause *ActOnOpenMPSingleExprWithArgClause( |
12316 | OpenMPClauseKind Kind, ArrayRef<unsigned> Arguments, Expr *Expr, |
12317 | SourceLocation StartLoc, SourceLocation LParenLoc, |
12318 | ArrayRef<SourceLocation> ArgumentsLoc, SourceLocation DelimLoc, |
12319 | SourceLocation EndLoc); |
12320 | /// Called on well-formed 'schedule' clause. |
12321 | OMPClause *ActOnOpenMPScheduleClause( |
12322 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
12323 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
12324 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
12325 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc); |
12326 | |
12327 | OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc, |
12328 | SourceLocation EndLoc); |
12329 | /// Called on well-formed 'nowait' clause. |
12330 | OMPClause *ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
12331 | SourceLocation EndLoc); |
12332 | /// Called on well-formed 'untied' clause. |
12333 | OMPClause *ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
12334 | SourceLocation EndLoc); |
12335 | /// Called on well-formed 'mergeable' clause. |
12336 | OMPClause *ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
12337 | SourceLocation EndLoc); |
12338 | /// Called on well-formed 'read' clause. |
12339 | OMPClause *ActOnOpenMPReadClause(SourceLocation StartLoc, |
12340 | SourceLocation EndLoc); |
12341 | /// Called on well-formed 'write' clause. |
12342 | OMPClause *ActOnOpenMPWriteClause(SourceLocation StartLoc, |
12343 | SourceLocation EndLoc); |
12344 | /// Called on well-formed 'update' clause. |
12345 | OMPClause *ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
12346 | SourceLocation EndLoc); |
12347 | /// Called on well-formed 'capture' clause. |
12348 | OMPClause *ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
12349 | SourceLocation EndLoc); |
12350 | /// Called on well-formed 'compare' clause. |
12351 | OMPClause *ActOnOpenMPCompareClause(SourceLocation StartLoc, |
12352 | SourceLocation EndLoc); |
12353 | /// Called on well-formed 'fail' clause. |
12354 | OMPClause *ActOnOpenMPFailClause(SourceLocation StartLoc, |
12355 | SourceLocation EndLoc); |
12356 | OMPClause *ActOnOpenMPFailClause( |
12357 | OpenMPClauseKind Kind, SourceLocation KindLoc, |
12358 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); |
12359 | |
12360 | /// Called on well-formed 'seq_cst' clause. |
12361 | OMPClause *ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
12362 | SourceLocation EndLoc); |
12363 | /// Called on well-formed 'acq_rel' clause. |
12364 | OMPClause *ActOnOpenMPAcqRelClause(SourceLocation StartLoc, |
12365 | SourceLocation EndLoc); |
12366 | /// Called on well-formed 'acquire' clause. |
12367 | OMPClause *ActOnOpenMPAcquireClause(SourceLocation StartLoc, |
12368 | SourceLocation EndLoc); |
12369 | /// Called on well-formed 'release' clause. |
12370 | OMPClause *ActOnOpenMPReleaseClause(SourceLocation StartLoc, |
12371 | SourceLocation EndLoc); |
12372 | /// Called on well-formed 'relaxed' clause. |
12373 | OMPClause *ActOnOpenMPRelaxedClause(SourceLocation StartLoc, |
12374 | SourceLocation EndLoc); |
12375 | /// Called on well-formed 'weak' clause. |
12376 | OMPClause *ActOnOpenMPWeakClause(SourceLocation StartLoc, |
12377 | SourceLocation EndLoc); |
12378 | |
12379 | /// Called on well-formed 'init' clause. |
12380 | OMPClause * |
12381 | ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, |
12382 | SourceLocation StartLoc, SourceLocation LParenLoc, |
12383 | SourceLocation VarLoc, SourceLocation EndLoc); |
12384 | |
12385 | /// Called on well-formed 'use' clause. |
12386 | OMPClause *ActOnOpenMPUseClause(Expr *InteropVar, SourceLocation StartLoc, |
12387 | SourceLocation LParenLoc, |
12388 | SourceLocation VarLoc, SourceLocation EndLoc); |
12389 | |
12390 | /// Called on well-formed 'destroy' clause. |
12391 | OMPClause *ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, |
12392 | SourceLocation LParenLoc, |
12393 | SourceLocation VarLoc, |
12394 | SourceLocation EndLoc); |
12395 | /// Called on well-formed 'novariants' clause. |
12396 | OMPClause *ActOnOpenMPNovariantsClause(Expr *Condition, |
12397 | SourceLocation StartLoc, |
12398 | SourceLocation LParenLoc, |
12399 | SourceLocation EndLoc); |
12400 | /// Called on well-formed 'nocontext' clause. |
12401 | OMPClause *ActOnOpenMPNocontextClause(Expr *Condition, |
12402 | SourceLocation StartLoc, |
12403 | SourceLocation LParenLoc, |
12404 | SourceLocation EndLoc); |
12405 | /// Called on well-formed 'filter' clause. |
12406 | OMPClause *ActOnOpenMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, |
12407 | SourceLocation LParenLoc, |
12408 | SourceLocation EndLoc); |
12409 | /// Called on well-formed 'threads' clause. |
12410 | OMPClause *ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
12411 | SourceLocation EndLoc); |
12412 | /// Called on well-formed 'simd' clause. |
12413 | OMPClause *ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
12414 | SourceLocation EndLoc); |
12415 | /// Called on well-formed 'nogroup' clause. |
12416 | OMPClause *ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
12417 | SourceLocation EndLoc); |
12418 | /// Called on well-formed 'unified_address' clause. |
12419 | OMPClause *ActOnOpenMPUnifiedAddressClause(SourceLocation StartLoc, |
12420 | SourceLocation EndLoc); |
12421 | |
12422 | /// Called on well-formed 'unified_address' clause. |
12423 | OMPClause *ActOnOpenMPUnifiedSharedMemoryClause(SourceLocation StartLoc, |
12424 | SourceLocation EndLoc); |
12425 | |
12426 | /// Called on well-formed 'reverse_offload' clause. |
12427 | OMPClause *ActOnOpenMPReverseOffloadClause(SourceLocation StartLoc, |
12428 | SourceLocation EndLoc); |
12429 | |
12430 | /// Called on well-formed 'dynamic_allocators' clause. |
12431 | OMPClause *ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc, |
12432 | SourceLocation EndLoc); |
12433 | |
12434 | /// Called on well-formed 'atomic_default_mem_order' clause. |
12435 | OMPClause *ActOnOpenMPAtomicDefaultMemOrderClause( |
12436 | OpenMPAtomicDefaultMemOrderClauseKind Kind, SourceLocation KindLoc, |
12437 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); |
12438 | |
12439 | /// Called on well-formed 'at' clause. |
12440 | OMPClause *ActOnOpenMPAtClause(OpenMPAtClauseKind Kind, |
12441 | SourceLocation KindLoc, |
12442 | SourceLocation StartLoc, |
12443 | SourceLocation LParenLoc, |
12444 | SourceLocation EndLoc); |
12445 | |
12446 | /// Called on well-formed 'severity' clause. |
12447 | OMPClause *ActOnOpenMPSeverityClause(OpenMPSeverityClauseKind Kind, |
12448 | SourceLocation KindLoc, |
12449 | SourceLocation StartLoc, |
12450 | SourceLocation LParenLoc, |
12451 | SourceLocation EndLoc); |
12452 | |
12453 | /// Called on well-formed 'message' clause. |
12454 | /// passing string for message. |
12455 | OMPClause *ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc, |
12456 | SourceLocation LParenLoc, |
12457 | SourceLocation EndLoc); |
12458 | |
12459 | /// Data used for processing a list of variables in OpenMP clauses. |
12460 | struct OpenMPVarListDataTy final { |
12461 | Expr *DepModOrTailExpr = nullptr; |
12462 | Expr *IteratorExpr = nullptr; |
12463 | SourceLocation ColonLoc; |
12464 | SourceLocation RLoc; |
12465 | CXXScopeSpec ReductionOrMapperIdScopeSpec; |
12466 | DeclarationNameInfo ReductionOrMapperId; |
12467 | int = -1; ///< Additional modifier for linear, map, depend or |
12468 | ///< lastprivate clause. |
12469 | SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers> |
12470 | MapTypeModifiers; |
12471 | SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers> |
12472 | MapTypeModifiersLoc; |
12473 | SmallVector<OpenMPMotionModifierKind, NumberOfOMPMotionModifiers> |
12474 | MotionModifiers; |
12475 | SmallVector<SourceLocation, NumberOfOMPMotionModifiers> MotionModifiersLoc; |
12476 | bool IsMapTypeImplicit = false; |
12477 | SourceLocation ; |
12478 | SourceLocation OmpAllMemoryLoc; |
12479 | SourceLocation |
12480 | StepModifierLoc; /// 'step' modifier location for linear clause |
12481 | }; |
12482 | |
12483 | OMPClause *ActOnOpenMPVarListClause(OpenMPClauseKind Kind, |
12484 | ArrayRef<Expr *> Vars, |
12485 | const OMPVarListLocTy &Locs, |
12486 | OpenMPVarListDataTy &Data); |
12487 | /// Called on well-formed 'inclusive' clause. |
12488 | OMPClause *ActOnOpenMPInclusiveClause(ArrayRef<Expr *> VarList, |
12489 | SourceLocation StartLoc, |
12490 | SourceLocation LParenLoc, |
12491 | SourceLocation EndLoc); |
12492 | /// Called on well-formed 'exclusive' clause. |
12493 | OMPClause *ActOnOpenMPExclusiveClause(ArrayRef<Expr *> VarList, |
12494 | SourceLocation StartLoc, |
12495 | SourceLocation LParenLoc, |
12496 | SourceLocation EndLoc); |
12497 | /// Called on well-formed 'allocate' clause. |
12498 | OMPClause * |
12499 | ActOnOpenMPAllocateClause(Expr *Allocator, ArrayRef<Expr *> VarList, |
12500 | SourceLocation StartLoc, SourceLocation ColonLoc, |
12501 | SourceLocation LParenLoc, SourceLocation EndLoc); |
12502 | /// Called on well-formed 'private' clause. |
12503 | OMPClause *ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
12504 | SourceLocation StartLoc, |
12505 | SourceLocation LParenLoc, |
12506 | SourceLocation EndLoc); |
12507 | /// Called on well-formed 'firstprivate' clause. |
12508 | OMPClause *ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
12509 | SourceLocation StartLoc, |
12510 | SourceLocation LParenLoc, |
12511 | SourceLocation EndLoc); |
12512 | /// Called on well-formed 'lastprivate' clause. |
12513 | OMPClause *ActOnOpenMPLastprivateClause( |
12514 | ArrayRef<Expr *> VarList, OpenMPLastprivateModifier LPKind, |
12515 | SourceLocation LPKindLoc, SourceLocation ColonLoc, |
12516 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); |
12517 | /// Called on well-formed 'shared' clause. |
12518 | OMPClause *ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
12519 | SourceLocation StartLoc, |
12520 | SourceLocation LParenLoc, |
12521 | SourceLocation EndLoc); |
12522 | /// Called on well-formed 'reduction' clause. |
12523 | OMPClause *ActOnOpenMPReductionClause( |
12524 | ArrayRef<Expr *> VarList, OpenMPReductionClauseModifier Modifier, |
12525 | SourceLocation StartLoc, SourceLocation LParenLoc, |
12526 | SourceLocation ModifierLoc, SourceLocation ColonLoc, |
12527 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
12528 | const DeclarationNameInfo &ReductionId, |
12529 | ArrayRef<Expr *> UnresolvedReductions = std::nullopt); |
12530 | /// Called on well-formed 'task_reduction' clause. |
12531 | OMPClause *ActOnOpenMPTaskReductionClause( |
12532 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
12533 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
12534 | CXXScopeSpec &ReductionIdScopeSpec, |
12535 | const DeclarationNameInfo &ReductionId, |
12536 | ArrayRef<Expr *> UnresolvedReductions = std::nullopt); |
12537 | /// Called on well-formed 'in_reduction' clause. |
12538 | OMPClause *ActOnOpenMPInReductionClause( |
12539 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
12540 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
12541 | CXXScopeSpec &ReductionIdScopeSpec, |
12542 | const DeclarationNameInfo &ReductionId, |
12543 | ArrayRef<Expr *> UnresolvedReductions = std::nullopt); |
12544 | /// Called on well-formed 'linear' clause. |
12545 | OMPClause *ActOnOpenMPLinearClause( |
12546 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
12547 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
12548 | SourceLocation LinLoc, SourceLocation ColonLoc, |
12549 | SourceLocation StepModifierLoc, SourceLocation EndLoc); |
12550 | /// Called on well-formed 'aligned' clause. |
12551 | OMPClause *ActOnOpenMPAlignedClause(ArrayRef<Expr *> VarList, |
12552 | Expr *Alignment, |
12553 | SourceLocation StartLoc, |
12554 | SourceLocation LParenLoc, |
12555 | SourceLocation ColonLoc, |
12556 | SourceLocation EndLoc); |
12557 | /// Called on well-formed 'copyin' clause. |
12558 | OMPClause *ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
12559 | SourceLocation StartLoc, |
12560 | SourceLocation LParenLoc, |
12561 | SourceLocation EndLoc); |
12562 | /// Called on well-formed 'copyprivate' clause. |
12563 | OMPClause *ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
12564 | SourceLocation StartLoc, |
12565 | SourceLocation LParenLoc, |
12566 | SourceLocation EndLoc); |
12567 | /// Called on well-formed 'flush' pseudo clause. |
12568 | OMPClause *ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
12569 | SourceLocation StartLoc, |
12570 | SourceLocation LParenLoc, |
12571 | SourceLocation EndLoc); |
12572 | /// Called on well-formed 'depobj' pseudo clause. |
12573 | OMPClause *ActOnOpenMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, |
12574 | SourceLocation LParenLoc, |
12575 | SourceLocation EndLoc); |
12576 | /// Called on well-formed 'depend' clause. |
12577 | OMPClause *ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data, |
12578 | Expr *DepModifier, |
12579 | ArrayRef<Expr *> VarList, |
12580 | SourceLocation StartLoc, |
12581 | SourceLocation LParenLoc, |
12582 | SourceLocation EndLoc); |
12583 | /// Called on well-formed 'device' clause. |
12584 | OMPClause *ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier, |
12585 | Expr *Device, SourceLocation StartLoc, |
12586 | SourceLocation LParenLoc, |
12587 | SourceLocation ModifierLoc, |
12588 | SourceLocation EndLoc); |
12589 | /// Called on well-formed 'map' clause. |
12590 | OMPClause *ActOnOpenMPMapClause( |
12591 | Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
12592 | ArrayRef<SourceLocation> MapTypeModifiersLoc, |
12593 | CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, |
12594 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
12595 | SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
12596 | const OMPVarListLocTy &Locs, bool NoDiagnose = false, |
12597 | ArrayRef<Expr *> UnresolvedMappers = std::nullopt); |
12598 | /// Called on well-formed 'num_teams' clause. |
12599 | OMPClause *ActOnOpenMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, |
12600 | SourceLocation LParenLoc, |
12601 | SourceLocation EndLoc); |
12602 | /// Called on well-formed 'thread_limit' clause. |
12603 | OMPClause *ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
12604 | SourceLocation StartLoc, |
12605 | SourceLocation LParenLoc, |
12606 | SourceLocation EndLoc); |
12607 | /// Called on well-formed 'priority' clause. |
12608 | OMPClause *ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc, |
12609 | SourceLocation LParenLoc, |
12610 | SourceLocation EndLoc); |
12611 | /// Called on well-formed 'dist_schedule' clause. |
12612 | OMPClause *ActOnOpenMPDistScheduleClause( |
12613 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, |
12614 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, |
12615 | SourceLocation CommaLoc, SourceLocation EndLoc); |
12616 | /// Called on well-formed 'defaultmap' clause. |
12617 | OMPClause *ActOnOpenMPDefaultmapClause( |
12618 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
12619 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
12620 | SourceLocation KindLoc, SourceLocation EndLoc); |
12621 | /// Called on well-formed 'to' clause. |
12622 | OMPClause * |
12623 | ActOnOpenMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
12624 | ArrayRef<SourceLocation> MotionModifiersLoc, |
12625 | CXXScopeSpec &MapperIdScopeSpec, |
12626 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
12627 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
12628 | ArrayRef<Expr *> UnresolvedMappers = std::nullopt); |
12629 | /// Called on well-formed 'from' clause. |
12630 | OMPClause * |
12631 | ActOnOpenMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
12632 | ArrayRef<SourceLocation> MotionModifiersLoc, |
12633 | CXXScopeSpec &MapperIdScopeSpec, |
12634 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
12635 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
12636 | ArrayRef<Expr *> UnresolvedMappers = std::nullopt); |
12637 | /// Called on well-formed 'use_device_ptr' clause. |
12638 | OMPClause *ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
12639 | const OMPVarListLocTy &Locs); |
12640 | /// Called on well-formed 'use_device_addr' clause. |
12641 | OMPClause *ActOnOpenMPUseDeviceAddrClause(ArrayRef<Expr *> VarList, |
12642 | const OMPVarListLocTy &Locs); |
12643 | /// Called on well-formed 'is_device_ptr' clause. |
12644 | OMPClause *ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
12645 | const OMPVarListLocTy &Locs); |
12646 | /// Called on well-formed 'has_device_addr' clause. |
12647 | OMPClause *ActOnOpenMPHasDeviceAddrClause(ArrayRef<Expr *> VarList, |
12648 | const OMPVarListLocTy &Locs); |
12649 | /// Called on well-formed 'nontemporal' clause. |
12650 | OMPClause *ActOnOpenMPNontemporalClause(ArrayRef<Expr *> VarList, |
12651 | SourceLocation StartLoc, |
12652 | SourceLocation LParenLoc, |
12653 | SourceLocation EndLoc); |
12654 | |
12655 | /// Data for list of allocators. |
12656 | struct UsesAllocatorsData { |
12657 | /// Allocator. |
12658 | Expr *Allocator = nullptr; |
12659 | /// Allocator traits. |
12660 | Expr *AllocatorTraits = nullptr; |
12661 | /// Locations of '(' and ')' symbols. |
12662 | SourceLocation LParenLoc, RParenLoc; |
12663 | }; |
12664 | /// Called on well-formed 'uses_allocators' clause. |
12665 | OMPClause *ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, |
12666 | SourceLocation LParenLoc, |
12667 | SourceLocation EndLoc, |
12668 | ArrayRef<UsesAllocatorsData> Data); |
12669 | /// Called on well-formed 'affinity' clause. |
12670 | OMPClause *ActOnOpenMPAffinityClause(SourceLocation StartLoc, |
12671 | SourceLocation LParenLoc, |
12672 | SourceLocation ColonLoc, |
12673 | SourceLocation EndLoc, Expr *Modifier, |
12674 | ArrayRef<Expr *> Locators); |
12675 | /// Called on a well-formed 'bind' clause. |
12676 | OMPClause *ActOnOpenMPBindClause(OpenMPBindClauseKind Kind, |
12677 | SourceLocation KindLoc, |
12678 | SourceLocation StartLoc, |
12679 | SourceLocation LParenLoc, |
12680 | SourceLocation EndLoc); |
12681 | |
12682 | /// Called on a well-formed 'ompx_dyn_cgroup_mem' clause. |
12683 | OMPClause *ActOnOpenMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, |
12684 | SourceLocation LParenLoc, |
12685 | SourceLocation EndLoc); |
12686 | |
12687 | /// Called on well-formed 'doacross' clause. |
12688 | OMPClause * |
12689 | ActOnOpenMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, |
12690 | SourceLocation DepLoc, SourceLocation ColonLoc, |
12691 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
12692 | SourceLocation LParenLoc, SourceLocation EndLoc); |
12693 | |
12694 | /// Called on a well-formed 'ompx_attribute' clause. |
12695 | OMPClause *ActOnOpenMPXAttributeClause(ArrayRef<const Attr *> Attrs, |
12696 | SourceLocation StartLoc, |
12697 | SourceLocation LParenLoc, |
12698 | SourceLocation EndLoc); |
12699 | |
12700 | /// Called on a well-formed 'ompx_bare' clause. |
12701 | OMPClause *ActOnOpenMPXBareClause(SourceLocation StartLoc, |
12702 | SourceLocation EndLoc); |
12703 | |
12704 | /// The kind of conversion being performed. |
12705 | enum CheckedConversionKind { |
12706 | /// An implicit conversion. |
12707 | CCK_ImplicitConversion, |
12708 | /// A C-style cast. |
12709 | CCK_CStyleCast, |
12710 | /// A functional-style cast. |
12711 | CCK_FunctionalCast, |
12712 | /// A cast other than a C-style cast. |
12713 | CCK_OtherCast, |
12714 | /// A conversion for an operand of a builtin overloaded operator. |
12715 | CCK_ForBuiltinOverloadedOp |
12716 | }; |
12717 | |
12718 | static bool isCast(CheckedConversionKind CCK) { |
12719 | return CCK == CCK_CStyleCast || CCK == CCK_FunctionalCast || |
12720 | CCK == CCK_OtherCast; |
12721 | } |
12722 | |
12723 | /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit |
12724 | /// cast. If there is already an implicit cast, merge into the existing one. |
12725 | /// If isLvalue, the result of the cast is an lvalue. |
12726 | ExprResult |
12727 | ImpCastExprToType(Expr *E, QualType Type, CastKind CK, |
12728 | ExprValueKind VK = VK_PRValue, |
12729 | const CXXCastPath *BasePath = nullptr, |
12730 | CheckedConversionKind CCK = CCK_ImplicitConversion); |
12731 | |
12732 | /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding |
12733 | /// to the conversion from scalar type ScalarTy to the Boolean type. |
12734 | static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); |
12735 | |
12736 | /// IgnoredValueConversions - Given that an expression's result is |
12737 | /// syntactically ignored, perform any conversions that are |
12738 | /// required. |
12739 | ExprResult IgnoredValueConversions(Expr *E); |
12740 | |
12741 | // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts |
12742 | // functions and arrays to their respective pointers (C99 6.3.2.1). |
12743 | ExprResult UsualUnaryConversions(Expr *E); |
12744 | |
12745 | /// CallExprUnaryConversions - a special case of an unary conversion |
12746 | /// performed on a function designator of a call expression. |
12747 | ExprResult CallExprUnaryConversions(Expr *E); |
12748 | |
12749 | // DefaultFunctionArrayConversion - converts functions and arrays |
12750 | // to their respective pointers (C99 6.3.2.1). |
12751 | ExprResult DefaultFunctionArrayConversion(Expr *E, bool Diagnose = true); |
12752 | |
12753 | // DefaultFunctionArrayLvalueConversion - converts functions and |
12754 | // arrays to their respective pointers and performs the |
12755 | // lvalue-to-rvalue conversion. |
12756 | ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, |
12757 | bool Diagnose = true); |
12758 | |
12759 | // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on |
12760 | // the operand. This function is a no-op if the operand has a function type |
12761 | // or an array type. |
12762 | ExprResult DefaultLvalueConversion(Expr *E); |
12763 | |
12764 | // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that |
12765 | // do not have a prototype. Integer promotions are performed on each |
12766 | // argument, and arguments that have type float are promoted to double. |
12767 | ExprResult DefaultArgumentPromotion(Expr *E); |
12768 | |
12769 | /// If \p E is a prvalue denoting an unmaterialized temporary, materialize |
12770 | /// it as an xvalue. In C++98, the result will still be a prvalue, because |
12771 | /// we don't have xvalues there. |
12772 | ExprResult TemporaryMaterializationConversion(Expr *E); |
12773 | |
12774 | // Used for emitting the right warning by DefaultVariadicArgumentPromotion |
12775 | enum VariadicCallType { |
12776 | VariadicFunction, |
12777 | VariadicBlock, |
12778 | VariadicMethod, |
12779 | VariadicConstructor, |
12780 | VariadicDoesNotApply |
12781 | }; |
12782 | |
12783 | VariadicCallType getVariadicCallType(FunctionDecl *FDecl, |
12784 | const FunctionProtoType *Proto, |
12785 | Expr *Fn); |
12786 | |
12787 | // Used for determining in which context a type is allowed to be passed to a |
12788 | // vararg function. |
12789 | enum VarArgKind { |
12790 | VAK_Valid, |
12791 | VAK_ValidInCXX11, |
12792 | VAK_Undefined, |
12793 | VAK_MSVCUndefined, |
12794 | VAK_Invalid |
12795 | }; |
12796 | |
12797 | // Determines which VarArgKind fits an expression. |
12798 | VarArgKind isValidVarArgType(const QualType &Ty); |
12799 | |
12800 | /// Check to see if the given expression is a valid argument to a variadic |
12801 | /// function, issuing a diagnostic if not. |
12802 | void checkVariadicArgument(const Expr *E, VariadicCallType CT); |
12803 | |
12804 | /// Check whether the given statement can have musttail applied to it, |
12805 | /// issuing a diagnostic and returning false if not. In the success case, |
12806 | /// the statement is rewritten to remove implicit nodes from the return |
12807 | /// value. |
12808 | bool checkAndRewriteMustTailAttr(Stmt *St, const Attr &MTA); |
12809 | |
12810 | private: |
12811 | /// Check whether the given statement can have musttail applied to it, |
12812 | /// issuing a diagnostic and returning false if not. |
12813 | bool checkMustTailAttr(const Stmt *St, const Attr &MTA); |
12814 | |
12815 | public: |
12816 | /// Check to see if a given expression could have '.c_str()' called on it. |
12817 | bool hasCStrMethod(const Expr *E); |
12818 | |
12819 | /// GatherArgumentsForCall - Collector argument expressions for various |
12820 | /// form of call prototypes. |
12821 | bool GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl, |
12822 | const FunctionProtoType *Proto, |
12823 | unsigned FirstParam, ArrayRef<Expr *> Args, |
12824 | SmallVectorImpl<Expr *> &AllArgs, |
12825 | VariadicCallType CallType = VariadicDoesNotApply, |
12826 | bool AllowExplicit = false, |
12827 | bool IsListInitialization = false); |
12828 | |
12829 | // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but |
12830 | // will create a runtime trap if the resulting type is not a POD type. |
12831 | ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, |
12832 | FunctionDecl *FDecl); |
12833 | |
12834 | /// Context in which we're performing a usual arithmetic conversion. |
12835 | enum ArithConvKind { |
12836 | /// An arithmetic operation. |
12837 | ACK_Arithmetic, |
12838 | /// A bitwise operation. |
12839 | ACK_BitwiseOp, |
12840 | /// A comparison. |
12841 | ACK_Comparison, |
12842 | /// A conditional (?:) operator. |
12843 | ACK_Conditional, |
12844 | /// A compound assignment expression. |
12845 | ACK_CompAssign, |
12846 | }; |
12847 | |
12848 | // UsualArithmeticConversions - performs the UsualUnaryConversions on it's |
12849 | // operands and then handles various conversions that are common to binary |
12850 | // operators (C99 6.3.1.8). If both operands aren't arithmetic, this |
12851 | // routine returns the first non-arithmetic type found. The client is |
12852 | // responsible for emitting appropriate error diagnostics. |
12853 | QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, |
12854 | SourceLocation Loc, ArithConvKind ACK); |
12855 | |
12856 | /// AssignConvertType - All of the 'assignment' semantic checks return this |
12857 | /// enum to indicate whether the assignment was allowed. These checks are |
12858 | /// done for simple assignments, as well as initialization, return from |
12859 | /// function, argument passing, etc. The query is phrased in terms of a |
12860 | /// source and destination type. |
12861 | enum AssignConvertType { |
12862 | /// Compatible - the types are compatible according to the standard. |
12863 | Compatible, |
12864 | |
12865 | /// PointerToInt - The assignment converts a pointer to an int, which we |
12866 | /// accept as an extension. |
12867 | PointerToInt, |
12868 | |
12869 | /// IntToPointer - The assignment converts an int to a pointer, which we |
12870 | /// accept as an extension. |
12871 | IntToPointer, |
12872 | |
12873 | /// FunctionVoidPointer - The assignment is between a function pointer and |
12874 | /// void*, which the standard doesn't allow, but we accept as an extension. |
12875 | FunctionVoidPointer, |
12876 | |
12877 | /// IncompatiblePointer - The assignment is between two pointers types that |
12878 | /// are not compatible, but we accept them as an extension. |
12879 | IncompatiblePointer, |
12880 | |
12881 | /// IncompatibleFunctionPointer - The assignment is between two function |
12882 | /// pointers types that are not compatible, but we accept them as an |
12883 | /// extension. |
12884 | IncompatibleFunctionPointer, |
12885 | |
12886 | /// IncompatibleFunctionPointerStrict - The assignment is between two |
12887 | /// function pointer types that are not identical, but are compatible, |
12888 | /// unless compiled with -fsanitize=cfi, in which case the type mismatch |
12889 | /// may trip an indirect call runtime check. |
12890 | IncompatibleFunctionPointerStrict, |
12891 | |
12892 | /// IncompatiblePointerSign - The assignment is between two pointers types |
12893 | /// which point to integers which have a different sign, but are otherwise |
12894 | /// identical. This is a subset of the above, but broken out because it's by |
12895 | /// far the most common case of incompatible pointers. |
12896 | IncompatiblePointerSign, |
12897 | |
12898 | /// CompatiblePointerDiscardsQualifiers - The assignment discards |
12899 | /// c/v/r qualifiers, which we accept as an extension. |
12900 | CompatiblePointerDiscardsQualifiers, |
12901 | |
12902 | /// IncompatiblePointerDiscardsQualifiers - The assignment |
12903 | /// discards qualifiers that we don't permit to be discarded, |
12904 | /// like address spaces. |
12905 | IncompatiblePointerDiscardsQualifiers, |
12906 | |
12907 | /// IncompatibleNestedPointerAddressSpaceMismatch - The assignment |
12908 | /// changes address spaces in nested pointer types which is not allowed. |
12909 | /// For instance, converting __private int ** to __generic int ** is |
12910 | /// illegal even though __private could be converted to __generic. |
12911 | IncompatibleNestedPointerAddressSpaceMismatch, |
12912 | |
12913 | /// IncompatibleNestedPointerQualifiers - The assignment is between two |
12914 | /// nested pointer types, and the qualifiers other than the first two |
12915 | /// levels differ e.g. char ** -> const char **, but we accept them as an |
12916 | /// extension. |
12917 | IncompatibleNestedPointerQualifiers, |
12918 | |
12919 | /// IncompatibleVectors - The assignment is between two vector types that |
12920 | /// have the same size, which we accept as an extension. |
12921 | IncompatibleVectors, |
12922 | |
12923 | /// IntToBlockPointer - The assignment converts an int to a block |
12924 | /// pointer. We disallow this. |
12925 | IntToBlockPointer, |
12926 | |
12927 | /// IncompatibleBlockPointer - The assignment is between two block |
12928 | /// pointers types that are not compatible. |
12929 | IncompatibleBlockPointer, |
12930 | |
12931 | /// IncompatibleObjCQualifiedId - The assignment is between a qualified |
12932 | /// id type and something else (that is incompatible with it). For example, |
12933 | /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. |
12934 | IncompatibleObjCQualifiedId, |
12935 | |
12936 | /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an |
12937 | /// object with __weak qualifier. |
12938 | IncompatibleObjCWeakRef, |
12939 | |
12940 | /// Incompatible - We reject this conversion outright, it is invalid to |
12941 | /// represent it in the AST. |
12942 | Incompatible |
12943 | }; |
12944 | |
12945 | /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the |
12946 | /// assignment conversion type specified by ConvTy. This returns true if the |
12947 | /// conversion was invalid or false if the conversion was accepted. |
12948 | bool DiagnoseAssignmentResult(AssignConvertType ConvTy, |
12949 | SourceLocation Loc, |
12950 | QualType DstType, QualType SrcType, |
12951 | Expr *SrcExpr, AssignmentAction Action, |
12952 | bool *Complained = nullptr); |
12953 | |
12954 | /// IsValueInFlagEnum - Determine if a value is allowed as part of a flag |
12955 | /// enum. If AllowMask is true, then we also allow the complement of a valid |
12956 | /// value, to be used as a mask. |
12957 | bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val, |
12958 | bool AllowMask) const; |
12959 | |
12960 | /// DiagnoseAssignmentEnum - Warn if assignment to enum is a constant |
12961 | /// integer not in the range of enum values. |
12962 | void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, |
12963 | Expr *SrcExpr); |
12964 | |
12965 | /// CheckAssignmentConstraints - Perform type checking for assignment, |
12966 | /// argument passing, variable initialization, and function return values. |
12967 | /// C99 6.5.16. |
12968 | AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, |
12969 | QualType LHSType, |
12970 | QualType RHSType); |
12971 | |
12972 | /// Check assignment constraints and optionally prepare for a conversion of |
12973 | /// the RHS to the LHS type. The conversion is prepared for if ConvertRHS |
12974 | /// is true. |
12975 | AssignConvertType CheckAssignmentConstraints(QualType LHSType, |
12976 | ExprResult &RHS, |
12977 | CastKind &Kind, |
12978 | bool ConvertRHS = true); |
12979 | |
12980 | /// Check assignment constraints for an assignment of RHS to LHSType. |
12981 | /// |
12982 | /// \param LHSType The destination type for the assignment. |
12983 | /// \param RHS The source expression for the assignment. |
12984 | /// \param Diagnose If \c true, diagnostics may be produced when checking |
12985 | /// for assignability. If a diagnostic is produced, \p RHS will be |
12986 | /// set to ExprError(). Note that this function may still return |
12987 | /// without producing a diagnostic, even for an invalid assignment. |
12988 | /// \param DiagnoseCFAudited If \c true, the target is a function parameter |
12989 | /// in an audited Core Foundation API and does not need to be checked |
12990 | /// for ARC retain issues. |
12991 | /// \param ConvertRHS If \c true, \p RHS will be updated to model the |
12992 | /// conversions necessary to perform the assignment. If \c false, |
12993 | /// \p Diagnose must also be \c false. |
12994 | AssignConvertType CheckSingleAssignmentConstraints( |
12995 | QualType LHSType, ExprResult &RHS, bool Diagnose = true, |
12996 | bool DiagnoseCFAudited = false, bool ConvertRHS = true); |
12997 | |
12998 | // If the lhs type is a transparent union, check whether we |
12999 | // can initialize the transparent union with the given expression. |
13000 | AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, |
13001 | ExprResult &RHS); |
13002 | |
13003 | bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); |
13004 | |
13005 | bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); |
13006 | |
13007 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
13008 | AssignmentAction Action, |
13009 | bool AllowExplicit = false); |
13010 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
13011 | const ImplicitConversionSequence& ICS, |
13012 | AssignmentAction Action, |
13013 | CheckedConversionKind CCK |
13014 | = CCK_ImplicitConversion); |
13015 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
13016 | const StandardConversionSequence& SCS, |
13017 | AssignmentAction Action, |
13018 | CheckedConversionKind CCK); |
13019 | |
13020 | ExprResult PerformQualificationConversion( |
13021 | Expr *E, QualType Ty, ExprValueKind VK = VK_PRValue, |
13022 | CheckedConversionKind CCK = CCK_ImplicitConversion); |
13023 | |
13024 | /// the following "Check" methods will return a valid/converted QualType |
13025 | /// or a null QualType (indicating an error diagnostic was issued). |
13026 | |
13027 | /// type checking binary operators (subroutines of CreateBuiltinBinOp). |
13028 | QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS, |
13029 | ExprResult &RHS); |
13030 | QualType InvalidLogicalVectorOperands(SourceLocation Loc, ExprResult &LHS, |
13031 | ExprResult &RHS); |
13032 | QualType CheckPointerToMemberOperands( // C++ 5.5 |
13033 | ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, |
13034 | SourceLocation OpLoc, bool isIndirect); |
13035 | QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
13036 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign, |
13037 | bool IsDivide); |
13038 | QualType CheckRemainderOperands( // C99 6.5.5 |
13039 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
13040 | bool IsCompAssign = false); |
13041 | QualType CheckAdditionOperands( // C99 6.5.6 |
13042 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
13043 | BinaryOperatorKind Opc, QualType* CompLHSTy = nullptr); |
13044 | QualType CheckSubtractionOperands( // C99 6.5.6 |
13045 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
13046 | QualType* CompLHSTy = nullptr); |
13047 | QualType CheckShiftOperands( // C99 6.5.7 |
13048 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
13049 | BinaryOperatorKind Opc, bool IsCompAssign = false); |
13050 | void CheckPtrComparisonWithNullChar(ExprResult &E, ExprResult &NullE); |
13051 | QualType CheckCompareOperands( // C99 6.5.8/9 |
13052 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
13053 | BinaryOperatorKind Opc); |
13054 | QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
13055 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
13056 | BinaryOperatorKind Opc); |
13057 | QualType CheckLogicalOperands( // C99 6.5.[13,14] |
13058 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
13059 | BinaryOperatorKind Opc); |
13060 | // CheckAssignmentOperands is used for both simple and compound assignment. |
13061 | // For simple assignment, pass both expressions and a null converted type. |
13062 | // For compound assignment, pass both expressions and the converted type. |
13063 | QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] |
13064 | Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType, |
13065 | BinaryOperatorKind Opc); |
13066 | |
13067 | ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc, |
13068 | UnaryOperatorKind Opcode, Expr *Op); |
13069 | ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc, |
13070 | BinaryOperatorKind Opcode, |
13071 | Expr *LHS, Expr *RHS); |
13072 | ExprResult checkPseudoObjectRValue(Expr *E); |
13073 | Expr *recreateSyntacticForm(PseudoObjectExpr *E); |
13074 | |
13075 | QualType CheckConditionalOperands( // C99 6.5.15 |
13076 | ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, |
13077 | ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc); |
13078 | QualType CXXCheckConditionalOperands( // C++ 5.16 |
13079 | ExprResult &cond, ExprResult &lhs, ExprResult &rhs, |
13080 | ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); |
13081 | QualType CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS, |
13082 | ExprResult &RHS, |
13083 | SourceLocation QuestionLoc); |
13084 | |
13085 | QualType CheckSizelessVectorConditionalTypes(ExprResult &Cond, |
13086 | ExprResult &LHS, ExprResult &RHS, |
13087 | SourceLocation QuestionLoc); |
13088 | QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, |
13089 | bool ConvertArgs = true); |
13090 | QualType FindCompositePointerType(SourceLocation Loc, |
13091 | ExprResult &E1, ExprResult &E2, |
13092 | bool ConvertArgs = true) { |
13093 | Expr *E1Tmp = E1.get(), *E2Tmp = E2.get(); |
13094 | QualType Composite = |
13095 | FindCompositePointerType(Loc, E1&: E1Tmp, E2&: E2Tmp, ConvertArgs); |
13096 | E1 = E1Tmp; |
13097 | E2 = E2Tmp; |
13098 | return Composite; |
13099 | } |
13100 | |
13101 | QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, |
13102 | SourceLocation QuestionLoc); |
13103 | |
13104 | bool DiagnoseConditionalForNull(const Expr *LHSExpr, const Expr *RHSExpr, |
13105 | SourceLocation QuestionLoc); |
13106 | |
13107 | void DiagnoseAlwaysNonNullPointer(Expr *E, |
13108 | Expr::NullPointerConstantKind NullType, |
13109 | bool IsEqual, SourceRange Range); |
13110 | |
13111 | /// type checking for vector binary operators. |
13112 | QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS, |
13113 | SourceLocation Loc, bool IsCompAssign, |
13114 | bool AllowBothBool, bool AllowBoolConversion, |
13115 | bool AllowBoolOperation, bool ReportInvalid); |
13116 | QualType GetSignedVectorType(QualType V); |
13117 | QualType GetSignedSizelessVectorType(QualType V); |
13118 | QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, |
13119 | SourceLocation Loc, |
13120 | BinaryOperatorKind Opc); |
13121 | QualType CheckSizelessVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, |
13122 | SourceLocation Loc, |
13123 | BinaryOperatorKind Opc); |
13124 | QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, |
13125 | SourceLocation Loc); |
13126 | |
13127 | // type checking for sizeless vector binary operators. |
13128 | QualType CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS, |
13129 | SourceLocation Loc, bool IsCompAssign, |
13130 | ArithConvKind OperationKind); |
13131 | |
13132 | /// Type checking for matrix binary operators. |
13133 | QualType CheckMatrixElementwiseOperands(ExprResult &LHS, ExprResult &RHS, |
13134 | SourceLocation Loc, |
13135 | bool IsCompAssign); |
13136 | QualType CheckMatrixMultiplyOperands(ExprResult &LHS, ExprResult &RHS, |
13137 | SourceLocation Loc, bool IsCompAssign); |
13138 | |
13139 | bool isValidSveBitcast(QualType srcType, QualType destType); |
13140 | bool isValidRVVBitcast(QualType srcType, QualType destType); |
13141 | |
13142 | bool areMatrixTypesOfTheSameDimension(QualType srcTy, QualType destTy); |
13143 | |
13144 | bool areVectorTypesSameSize(QualType srcType, QualType destType); |
13145 | bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType); |
13146 | bool isLaxVectorConversion(QualType srcType, QualType destType); |
13147 | bool anyAltivecTypes(QualType srcType, QualType destType); |
13148 | |
13149 | /// type checking declaration initializers (C99 6.7.8) |
13150 | bool CheckForConstantInitializer(Expr *e, QualType t); |
13151 | |
13152 | // type checking C++ declaration initializers (C++ [dcl.init]). |
13153 | |
13154 | /// ReferenceCompareResult - Expresses the result of comparing two |
13155 | /// types (cv1 T1 and cv2 T2) to determine their compatibility for the |
13156 | /// purposes of initialization by reference (C++ [dcl.init.ref]p4). |
13157 | enum ReferenceCompareResult { |
13158 | /// Ref_Incompatible - The two types are incompatible, so direct |
13159 | /// reference binding is not possible. |
13160 | Ref_Incompatible = 0, |
13161 | /// Ref_Related - The two types are reference-related, which means |
13162 | /// that their unqualified forms (T1 and T2) are either the same |
13163 | /// or T1 is a base class of T2. |
13164 | Ref_Related, |
13165 | /// Ref_Compatible - The two types are reference-compatible. |
13166 | Ref_Compatible |
13167 | }; |
13168 | |
13169 | // Fake up a scoped enumeration that still contextually converts to bool. |
13170 | struct ReferenceConversionsScope { |
13171 | /// The conversions that would be performed on an lvalue of type T2 when |
13172 | /// binding a reference of type T1 to it, as determined when evaluating |
13173 | /// whether T1 is reference-compatible with T2. |
13174 | enum ReferenceConversions { |
13175 | Qualification = 0x1, |
13176 | NestedQualification = 0x2, |
13177 | Function = 0x4, |
13178 | DerivedToBase = 0x8, |
13179 | ObjC = 0x10, |
13180 | ObjCLifetime = 0x20, |
13181 | |
13182 | LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/ObjCLifetime) |
13183 | }; |
13184 | }; |
13185 | using ReferenceConversions = ReferenceConversionsScope::ReferenceConversions; |
13186 | |
13187 | ReferenceCompareResult |
13188 | CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2, |
13189 | ReferenceConversions *Conv = nullptr); |
13190 | |
13191 | ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, |
13192 | Expr *CastExpr, CastKind &CastKind, |
13193 | ExprValueKind &VK, CXXCastPath &Path); |
13194 | |
13195 | /// Force an expression with unknown-type to an expression of the |
13196 | /// given type. |
13197 | ExprResult forceUnknownAnyToType(Expr *E, QualType ToType); |
13198 | |
13199 | /// Type-check an expression that's being passed to an |
13200 | /// __unknown_anytype parameter. |
13201 | ExprResult checkUnknownAnyArg(SourceLocation callLoc, |
13202 | Expr *result, QualType ¶mType); |
13203 | |
13204 | // CheckMatrixCast - Check type constraints for matrix casts. |
13205 | // We allow casting between matrixes of the same dimensions i.e. when they |
13206 | // have the same number of rows and column. Returns true if the cast is |
13207 | // invalid. |
13208 | bool CheckMatrixCast(SourceRange R, QualType DestTy, QualType SrcTy, |
13209 | CastKind &Kind); |
13210 | |
13211 | // CheckVectorCast - check type constraints for vectors. |
13212 | // Since vectors are an extension, there are no C standard reference for this. |
13213 | // We allow casting between vectors and integer datatypes of the same size. |
13214 | // returns true if the cast is invalid |
13215 | bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, |
13216 | CastKind &Kind); |
13217 | |
13218 | /// Prepare `SplattedExpr` for a vector splat operation, adding |
13219 | /// implicit casts if necessary. |
13220 | ExprResult prepareVectorSplat(QualType VectorTy, Expr *SplattedExpr); |
13221 | |
13222 | // CheckExtVectorCast - check type constraints for extended vectors. |
13223 | // Since vectors are an extension, there are no C standard reference for this. |
13224 | // We allow casting between vectors and integer datatypes of the same size, |
13225 | // or vectors and the element type of that vector. |
13226 | // returns the cast expr |
13227 | ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr, |
13228 | CastKind &Kind); |
13229 | |
13230 | ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, QualType Type, |
13231 | SourceLocation LParenLoc, |
13232 | Expr *CastExpr, |
13233 | SourceLocation RParenLoc); |
13234 | |
13235 | enum ARCConversionResult { ACR_okay, ACR_unbridged, ACR_error }; |
13236 | |
13237 | /// Checks for invalid conversions and casts between |
13238 | /// retainable pointers and other pointer kinds for ARC and Weak. |
13239 | ARCConversionResult CheckObjCConversion(SourceRange castRange, |
13240 | QualType castType, Expr *&op, |
13241 | CheckedConversionKind CCK, |
13242 | bool Diagnose = true, |
13243 | bool DiagnoseCFAudited = false, |
13244 | BinaryOperatorKind Opc = BO_PtrMemD |
13245 | ); |
13246 | |
13247 | Expr *stripARCUnbridgedCast(Expr *e); |
13248 | void diagnoseARCUnbridgedCast(Expr *e); |
13249 | |
13250 | bool CheckObjCARCUnavailableWeakConversion(QualType castType, |
13251 | QualType ExprType); |
13252 | |
13253 | /// checkRetainCycles - Check whether an Objective-C message send |
13254 | /// might create an obvious retain cycle. |
13255 | void checkRetainCycles(ObjCMessageExpr *msg); |
13256 | void checkRetainCycles(Expr *receiver, Expr *argument); |
13257 | void checkRetainCycles(VarDecl *Var, Expr *Init); |
13258 | |
13259 | /// checkUnsafeAssigns - Check whether +1 expr is being assigned |
13260 | /// to weak/__unsafe_unretained type. |
13261 | bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); |
13262 | |
13263 | /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned |
13264 | /// to weak/__unsafe_unretained expression. |
13265 | void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); |
13266 | |
13267 | /// CheckMessageArgumentTypes - Check types in an Obj-C message send. |
13268 | /// \param Method - May be null. |
13269 | /// \param [out] ReturnType - The return type of the send. |
13270 | /// \return true iff there were any incompatible types. |
13271 | bool CheckMessageArgumentTypes(const Expr *Receiver, QualType ReceiverType, |
13272 | MultiExprArg Args, Selector Sel, |
13273 | ArrayRef<SourceLocation> SelectorLocs, |
13274 | ObjCMethodDecl *Method, bool isClassMessage, |
13275 | bool isSuperMessage, SourceLocation lbrac, |
13276 | SourceLocation rbrac, SourceRange RecRange, |
13277 | QualType &ReturnType, ExprValueKind &VK); |
13278 | |
13279 | /// Determine the result of a message send expression based on |
13280 | /// the type of the receiver, the method expected to receive the message, |
13281 | /// and the form of the message send. |
13282 | QualType getMessageSendResultType(const Expr *Receiver, QualType ReceiverType, |
13283 | ObjCMethodDecl *Method, bool isClassMessage, |
13284 | bool isSuperMessage); |
13285 | |
13286 | /// If the given expression involves a message send to a method |
13287 | /// with a related result type, emit a note describing what happened. |
13288 | void EmitRelatedResultTypeNote(const Expr *E); |
13289 | |
13290 | /// Given that we had incompatible pointer types in a return |
13291 | /// statement, check whether we're in a method with a related result |
13292 | /// type, and if so, emit a note describing what happened. |
13293 | void EmitRelatedResultTypeNoteForReturn(QualType destType); |
13294 | |
13295 | class ConditionResult { |
13296 | Decl *ConditionVar; |
13297 | FullExprArg Condition; |
13298 | bool Invalid; |
13299 | std::optional<bool> KnownValue; |
13300 | |
13301 | friend class Sema; |
13302 | ConditionResult(Sema &S, Decl *ConditionVar, FullExprArg Condition, |
13303 | bool IsConstexpr) |
13304 | : ConditionVar(ConditionVar), Condition(Condition), Invalid(false) { |
13305 | if (IsConstexpr && Condition.get()) { |
13306 | if (std::optional<llvm::APSInt> Val = |
13307 | Condition.get()->getIntegerConstantExpr(Ctx: S.Context)) { |
13308 | KnownValue = !!(*Val); |
13309 | } |
13310 | } |
13311 | } |
13312 | explicit ConditionResult(bool Invalid) |
13313 | : ConditionVar(nullptr), Condition(nullptr), Invalid(Invalid), |
13314 | KnownValue(std::nullopt) {} |
13315 | |
13316 | public: |
13317 | ConditionResult() : ConditionResult(false) {} |
13318 | bool isInvalid() const { return Invalid; } |
13319 | std::pair<VarDecl *, Expr *> get() const { |
13320 | return std::make_pair(x: cast_or_null<VarDecl>(Val: ConditionVar), |
13321 | y: Condition.get()); |
13322 | } |
13323 | std::optional<bool> getKnownValue() const { return KnownValue; } |
13324 | }; |
13325 | static ConditionResult ConditionError() { return ConditionResult(true); } |
13326 | |
13327 | enum class ConditionKind { |
13328 | Boolean, ///< A boolean condition, from 'if', 'while', 'for', or 'do'. |
13329 | ConstexprIf, ///< A constant boolean condition from 'if constexpr'. |
13330 | Switch ///< An integral condition for a 'switch' statement. |
13331 | }; |
13332 | QualType PreferredConditionType(ConditionKind K) const { |
13333 | return K == ConditionKind::Switch ? Context.IntTy : Context.BoolTy; |
13334 | } |
13335 | |
13336 | ConditionResult ActOnCondition(Scope *S, SourceLocation Loc, Expr *SubExpr, |
13337 | ConditionKind CK, bool MissingOK = false); |
13338 | |
13339 | ConditionResult ActOnConditionVariable(Decl *ConditionVar, |
13340 | SourceLocation StmtLoc, |
13341 | ConditionKind CK); |
13342 | |
13343 | DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); |
13344 | |
13345 | ExprResult CheckConditionVariable(VarDecl *ConditionVar, |
13346 | SourceLocation StmtLoc, |
13347 | ConditionKind CK); |
13348 | ExprResult CheckSwitchCondition(SourceLocation SwitchLoc, Expr *Cond); |
13349 | |
13350 | /// CheckBooleanCondition - Diagnose problems involving the use of |
13351 | /// the given expression as a boolean condition (e.g. in an if |
13352 | /// statement). Also performs the standard function and array |
13353 | /// decays, possibly changing the input variable. |
13354 | /// |
13355 | /// \param Loc - A location associated with the condition, e.g. the |
13356 | /// 'if' keyword. |
13357 | /// \return true iff there were any errors |
13358 | ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E, |
13359 | bool IsConstexpr = false); |
13360 | |
13361 | /// ActOnExplicitBoolSpecifier - Build an ExplicitSpecifier from an expression |
13362 | /// found in an explicit(bool) specifier. |
13363 | ExplicitSpecifier ActOnExplicitBoolSpecifier(Expr *E); |
13364 | |
13365 | /// tryResolveExplicitSpecifier - Attempt to resolve the explict specifier. |
13366 | /// Returns true if the explicit specifier is now resolved. |
13367 | bool tryResolveExplicitSpecifier(ExplicitSpecifier &ExplicitSpec); |
13368 | |
13369 | /// DiagnoseAssignmentAsCondition - Given that an expression is |
13370 | /// being used as a boolean condition, warn if it's an assignment. |
13371 | void DiagnoseAssignmentAsCondition(Expr *E); |
13372 | |
13373 | /// Redundant parentheses over an equality comparison can indicate |
13374 | /// that the user intended an assignment used as condition. |
13375 | void (ParenExpr *ParenE); |
13376 | |
13377 | /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. |
13378 | ExprResult CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr = false); |
13379 | |
13380 | /// Checks that the Objective-C declaration is declared in the global scope. |
13381 | /// Emits an error and marks the declaration as invalid if it's not declared |
13382 | /// in the global scope. |
13383 | bool CheckObjCDeclScope(Decl *D); |
13384 | |
13385 | /// Abstract base class used for diagnosing integer constant |
13386 | /// expression violations. |
13387 | class VerifyICEDiagnoser { |
13388 | public: |
13389 | bool Suppress; |
13390 | |
13391 | VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) { } |
13392 | |
13393 | virtual SemaDiagnosticBuilder |
13394 | diagnoseNotICEType(Sema &S, SourceLocation Loc, QualType T); |
13395 | virtual SemaDiagnosticBuilder diagnoseNotICE(Sema &S, |
13396 | SourceLocation Loc) = 0; |
13397 | virtual SemaDiagnosticBuilder diagnoseFold(Sema &S, SourceLocation Loc); |
13398 | virtual ~VerifyICEDiagnoser() {} |
13399 | }; |
13400 | |
13401 | enum AllowFoldKind { |
13402 | NoFold, |
13403 | AllowFold, |
13404 | }; |
13405 | |
13406 | /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE, |
13407 | /// and reports the appropriate diagnostics. Returns false on success. |
13408 | /// Can optionally return the value of the expression. |
13409 | ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
13410 | VerifyICEDiagnoser &Diagnoser, |
13411 | AllowFoldKind CanFold = NoFold); |
13412 | ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
13413 | unsigned DiagID, |
13414 | AllowFoldKind CanFold = NoFold); |
13415 | ExprResult VerifyIntegerConstantExpression(Expr *E, |
13416 | llvm::APSInt *Result = nullptr, |
13417 | AllowFoldKind CanFold = NoFold); |
13418 | ExprResult VerifyIntegerConstantExpression(Expr *E, |
13419 | AllowFoldKind CanFold = NoFold) { |
13420 | return VerifyIntegerConstantExpression(E, Result: nullptr, CanFold); |
13421 | } |
13422 | |
13423 | /// VerifyBitField - verifies that a bit field expression is an ICE and has |
13424 | /// the correct width, and that the field type is valid. |
13425 | /// Returns false on success. |
13426 | ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, |
13427 | QualType FieldTy, bool IsMsStruct, Expr *BitWidth); |
13428 | |
13429 | private: |
13430 | unsigned ForceCUDAHostDeviceDepth = 0; |
13431 | |
13432 | public: |
13433 | /// Increments our count of the number of times we've seen a pragma forcing |
13434 | /// functions to be __host__ __device__. So long as this count is greater |
13435 | /// than zero, all functions encountered will be __host__ __device__. |
13436 | void PushForceCUDAHostDevice(); |
13437 | |
13438 | /// Decrements our count of the number of times we've seen a pragma forcing |
13439 | /// functions to be __host__ __device__. Returns false if the count is 0 |
13440 | /// before incrementing, so you can emit an error. |
13441 | bool PopForceCUDAHostDevice(); |
13442 | |
13443 | /// Diagnostics that are emitted only if we discover that the given function |
13444 | /// must be codegen'ed. Because handling these correctly adds overhead to |
13445 | /// compilation, this is currently only enabled for CUDA compilations. |
13446 | llvm::DenseMap<CanonicalDeclPtr<const FunctionDecl>, |
13447 | std::vector<PartialDiagnosticAt>> |
13448 | DeviceDeferredDiags; |
13449 | |
13450 | /// A pair of a canonical FunctionDecl and a SourceLocation. When used as the |
13451 | /// key in a hashtable, both the FD and location are hashed. |
13452 | struct FunctionDeclAndLoc { |
13453 | CanonicalDeclPtr<const FunctionDecl> FD; |
13454 | SourceLocation Loc; |
13455 | }; |
13456 | |
13457 | /// FunctionDecls and SourceLocations for which CheckCUDACall has emitted a |
13458 | /// (maybe deferred) "bad call" diagnostic. We use this to avoid emitting the |
13459 | /// same deferred diag twice. |
13460 | llvm::DenseSet<FunctionDeclAndLoc> LocsWithCUDACallDiags; |
13461 | |
13462 | /// An inverse call graph, mapping known-emitted functions to one of their |
13463 | /// known-emitted callers (plus the location of the call). |
13464 | /// |
13465 | /// Functions that we can tell a priori must be emitted aren't added to this |
13466 | /// map. |
13467 | llvm::DenseMap</* Callee = */ CanonicalDeclPtr<const FunctionDecl>, |
13468 | /* Caller = */ FunctionDeclAndLoc> |
13469 | DeviceKnownEmittedFns; |
13470 | |
13471 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
13472 | /// context is "used as device code". |
13473 | /// |
13474 | /// - If CurContext is a __host__ function, does not emit any diagnostics |
13475 | /// unless \p EmitOnBothSides is true. |
13476 | /// - If CurContext is a __device__ or __global__ function, emits the |
13477 | /// diagnostics immediately. |
13478 | /// - If CurContext is a __host__ __device__ function and we are compiling for |
13479 | /// the device, creates a diagnostic which is emitted if and when we realize |
13480 | /// that the function will be codegen'ed. |
13481 | /// |
13482 | /// Example usage: |
13483 | /// |
13484 | /// // Variable-length arrays are not allowed in CUDA device code. |
13485 | /// if (CUDADiagIfDeviceCode(Loc, diag::err_cuda_vla) << CurrentCUDATarget()) |
13486 | /// return ExprError(); |
13487 | /// // Otherwise, continue parsing as normal. |
13488 | SemaDiagnosticBuilder CUDADiagIfDeviceCode(SourceLocation Loc, |
13489 | unsigned DiagID); |
13490 | |
13491 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
13492 | /// context is "used as host code". |
13493 | /// |
13494 | /// Same as CUDADiagIfDeviceCode, with "host" and "device" switched. |
13495 | SemaDiagnosticBuilder CUDADiagIfHostCode(SourceLocation Loc, unsigned DiagID); |
13496 | |
13497 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
13498 | /// context is "used as device code". |
13499 | /// |
13500 | /// - If CurContext is a `declare target` function or it is known that the |
13501 | /// function is emitted for the device, emits the diagnostics immediately. |
13502 | /// - If CurContext is a non-`declare target` function and we are compiling |
13503 | /// for the device, creates a diagnostic which is emitted if and when we |
13504 | /// realize that the function will be codegen'ed. |
13505 | /// |
13506 | /// Example usage: |
13507 | /// |
13508 | /// // Variable-length arrays are not allowed in NVPTX device code. |
13509 | /// if (diagIfOpenMPDeviceCode(Loc, diag::err_vla_unsupported)) |
13510 | /// return ExprError(); |
13511 | /// // Otherwise, continue parsing as normal. |
13512 | SemaDiagnosticBuilder diagIfOpenMPDeviceCode(SourceLocation Loc, |
13513 | unsigned DiagID, |
13514 | const FunctionDecl *FD); |
13515 | |
13516 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
13517 | /// context is "used as host code". |
13518 | /// |
13519 | /// - If CurContext is a `declare target` function or it is known that the |
13520 | /// function is emitted for the host, emits the diagnostics immediately. |
13521 | /// - If CurContext is a non-host function, just ignore it. |
13522 | /// |
13523 | /// Example usage: |
13524 | /// |
13525 | /// // Variable-length arrays are not allowed in NVPTX device code. |
13526 | /// if (diagIfOpenMPHostode(Loc, diag::err_vla_unsupported)) |
13527 | /// return ExprError(); |
13528 | /// // Otherwise, continue parsing as normal. |
13529 | SemaDiagnosticBuilder diagIfOpenMPHostCode(SourceLocation Loc, |
13530 | unsigned DiagID, |
13531 | const FunctionDecl *FD); |
13532 | |
13533 | SemaDiagnosticBuilder targetDiag(SourceLocation Loc, unsigned DiagID, |
13534 | const FunctionDecl *FD = nullptr); |
13535 | SemaDiagnosticBuilder targetDiag(SourceLocation Loc, |
13536 | const PartialDiagnostic &PD, |
13537 | const FunctionDecl *FD = nullptr) { |
13538 | return targetDiag(Loc, DiagID: PD.getDiagID(), FD) << PD; |
13539 | } |
13540 | |
13541 | /// Check if the type is allowed to be used for the current target. |
13542 | void checkTypeSupport(QualType Ty, SourceLocation Loc, |
13543 | ValueDecl *D = nullptr); |
13544 | |
13545 | /// Determines whether the given function is a CUDA device/host/kernel/etc. |
13546 | /// function. |
13547 | /// |
13548 | /// Use this rather than examining the function's attributes yourself -- you |
13549 | /// will get it wrong. Returns CFT_Host if D is null. |
13550 | CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D, |
13551 | bool IgnoreImplicitHDAttr = false); |
13552 | CUDAFunctionTarget IdentifyCUDATarget(const ParsedAttributesView &Attrs); |
13553 | |
13554 | enum CUDAVariableTarget { |
13555 | CVT_Device, /// Emitted on device side with a shadow variable on host side |
13556 | CVT_Host, /// Emitted on host side only |
13557 | CVT_Both, /// Emitted on both sides with different addresses |
13558 | CVT_Unified, /// Emitted as a unified address, e.g. managed variables |
13559 | }; |
13560 | /// Determines whether the given variable is emitted on host or device side. |
13561 | CUDAVariableTarget IdentifyCUDATarget(const VarDecl *D); |
13562 | |
13563 | /// Defines kinds of CUDA global host/device context where a function may be |
13564 | /// called. |
13565 | enum CUDATargetContextKind { |
13566 | CTCK_Unknown, /// Unknown context |
13567 | CTCK_InitGlobalVar, /// Function called during global variable |
13568 | /// initialization |
13569 | }; |
13570 | |
13571 | /// Define the current global CUDA host/device context where a function may be |
13572 | /// called. Only used when a function is called outside of any functions. |
13573 | struct CUDATargetContext { |
13574 | CUDAFunctionTarget Target = CFT_HostDevice; |
13575 | CUDATargetContextKind Kind = CTCK_Unknown; |
13576 | Decl *D = nullptr; |
13577 | } CurCUDATargetCtx; |
13578 | |
13579 | struct { |
13580 | Sema &; |
13581 | CUDATargetContext ; |
13582 | (Sema &S_, CUDATargetContextKind K, Decl *D); |
13583 | () { S.CurCUDATargetCtx = SavedCtx; } |
13584 | }; |
13585 | |
13586 | /// Gets the CUDA target for the current context. |
13587 | CUDAFunctionTarget CurrentCUDATarget() { |
13588 | return IdentifyCUDATarget(D: dyn_cast<FunctionDecl>(Val: CurContext)); |
13589 | } |
13590 | |
13591 | static bool isCUDAImplicitHostDeviceFunction(const FunctionDecl *D); |
13592 | |
13593 | // CUDA function call preference. Must be ordered numerically from |
13594 | // worst to best. |
13595 | enum CUDAFunctionPreference { |
13596 | CFP_Never, // Invalid caller/callee combination. |
13597 | CFP_WrongSide, // Calls from host-device to host or device |
13598 | // function that do not match current compilation |
13599 | // mode. |
13600 | CFP_HostDevice, // Any calls to host/device functions. |
13601 | CFP_SameSide, // Calls from host-device to host or device |
13602 | // function matching current compilation mode. |
13603 | CFP_Native, // host-to-host or device-to-device calls. |
13604 | }; |
13605 | |
13606 | /// Identifies relative preference of a given Caller/Callee |
13607 | /// combination, based on their host/device attributes. |
13608 | /// \param Caller function which needs address of \p Callee. |
13609 | /// nullptr in case of global context. |
13610 | /// \param Callee target function |
13611 | /// |
13612 | /// \returns preference value for particular Caller/Callee combination. |
13613 | CUDAFunctionPreference IdentifyCUDAPreference(const FunctionDecl *Caller, |
13614 | const FunctionDecl *Callee); |
13615 | |
13616 | /// Determines whether Caller may invoke Callee, based on their CUDA |
13617 | /// host/device attributes. Returns false if the call is not allowed. |
13618 | /// |
13619 | /// Note: Will return true for CFP_WrongSide calls. These may appear in |
13620 | /// semantically correct CUDA programs, but only if they're never codegen'ed. |
13621 | bool IsAllowedCUDACall(const FunctionDecl *Caller, |
13622 | const FunctionDecl *Callee) { |
13623 | return IdentifyCUDAPreference(Caller, Callee) != CFP_Never; |
13624 | } |
13625 | |
13626 | /// May add implicit CUDAHostAttr and CUDADeviceAttr attributes to FD, |
13627 | /// depending on FD and the current compilation settings. |
13628 | void maybeAddCUDAHostDeviceAttrs(FunctionDecl *FD, |
13629 | const LookupResult &Previous); |
13630 | |
13631 | /// May add implicit CUDAConstantAttr attribute to VD, depending on VD |
13632 | /// and current compilation settings. |
13633 | void MaybeAddCUDAConstantAttr(VarDecl *VD); |
13634 | |
13635 | public: |
13636 | /// Check whether we're allowed to call Callee from the current context. |
13637 | /// |
13638 | /// - If the call is never allowed in a semantically-correct program |
13639 | /// (CFP_Never), emits an error and returns false. |
13640 | /// |
13641 | /// - If the call is allowed in semantically-correct programs, but only if |
13642 | /// it's never codegen'ed (CFP_WrongSide), creates a deferred diagnostic to |
13643 | /// be emitted if and when the caller is codegen'ed, and returns true. |
13644 | /// |
13645 | /// Will only create deferred diagnostics for a given SourceLocation once, |
13646 | /// so you can safely call this multiple times without generating duplicate |
13647 | /// deferred errors. |
13648 | /// |
13649 | /// - Otherwise, returns true without emitting any diagnostics. |
13650 | bool CheckCUDACall(SourceLocation Loc, FunctionDecl *Callee); |
13651 | |
13652 | void CUDACheckLambdaCapture(CXXMethodDecl *D, const sema::Capture &Capture); |
13653 | |
13654 | /// Set __device__ or __host__ __device__ attributes on the given lambda |
13655 | /// operator() method. |
13656 | /// |
13657 | /// CUDA lambdas by default is host device function unless it has explicit |
13658 | /// host or device attribute. |
13659 | void CUDASetLambdaAttrs(CXXMethodDecl *Method); |
13660 | |
13661 | /// Record \p FD if it is a CUDA/HIP implicit host device function used on |
13662 | /// device side in device compilation. |
13663 | void CUDARecordImplicitHostDeviceFuncUsedByDevice(const FunctionDecl *FD); |
13664 | |
13665 | /// Finds a function in \p Matches with highest calling priority |
13666 | /// from \p Caller context and erases all functions with lower |
13667 | /// calling priority. |
13668 | void EraseUnwantedCUDAMatches( |
13669 | const FunctionDecl *Caller, |
13670 | SmallVectorImpl<std::pair<DeclAccessPair, FunctionDecl *>> &Matches); |
13671 | |
13672 | /// Given a implicit special member, infer its CUDA target from the |
13673 | /// calls it needs to make to underlying base/field special members. |
13674 | /// \param ClassDecl the class for which the member is being created. |
13675 | /// \param CSM the kind of special member. |
13676 | /// \param MemberDecl the special member itself. |
13677 | /// \param ConstRHS true if this is a copy operation with a const object on |
13678 | /// its RHS. |
13679 | /// \param Diagnose true if this call should emit diagnostics. |
13680 | /// \return true if there was an error inferring. |
13681 | /// The result of this call is implicit CUDA target attribute(s) attached to |
13682 | /// the member declaration. |
13683 | bool inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl, |
13684 | CXXSpecialMember CSM, |
13685 | CXXMethodDecl *MemberDecl, |
13686 | bool ConstRHS, |
13687 | bool Diagnose); |
13688 | |
13689 | /// \return true if \p CD can be considered empty according to CUDA |
13690 | /// (E.2.3.1 in CUDA 7.5 Programming guide). |
13691 | bool isEmptyCudaConstructor(SourceLocation Loc, CXXConstructorDecl *CD); |
13692 | bool isEmptyCudaDestructor(SourceLocation Loc, CXXDestructorDecl *CD); |
13693 | |
13694 | // \brief Checks that initializers of \p Var satisfy CUDA restrictions. In |
13695 | // case of error emits appropriate diagnostic and invalidates \p Var. |
13696 | // |
13697 | // \details CUDA allows only empty constructors as initializers for global |
13698 | // variables (see E.2.3.1, CUDA 7.5). The same restriction also applies to all |
13699 | // __shared__ variables whether they are local or not (they all are implicitly |
13700 | // static in CUDA). One exception is that CUDA allows constant initializers |
13701 | // for __constant__ and __device__ variables. |
13702 | void checkAllowedCUDAInitializer(VarDecl *VD); |
13703 | |
13704 | /// Check whether NewFD is a valid overload for CUDA. Emits |
13705 | /// diagnostics and invalidates NewFD if not. |
13706 | void checkCUDATargetOverload(FunctionDecl *NewFD, |
13707 | const LookupResult &Previous); |
13708 | /// Copies target attributes from the template TD to the function FD. |
13709 | void inheritCUDATargetAttrs(FunctionDecl *FD, const FunctionTemplateDecl &TD); |
13710 | |
13711 | /// Returns the name of the launch configuration function. This is the name |
13712 | /// of the function that will be called to configure kernel call, with the |
13713 | /// parameters specified via <<<>>>. |
13714 | std::string getCudaConfigureFuncName() const; |
13715 | |
13716 | /// \name Code completion |
13717 | //@{ |
13718 | /// Describes the context in which code completion occurs. |
13719 | enum ParserCompletionContext { |
13720 | /// Code completion occurs at top-level or namespace context. |
13721 | PCC_Namespace, |
13722 | /// Code completion occurs within a class, struct, or union. |
13723 | PCC_Class, |
13724 | /// Code completion occurs within an Objective-C interface, protocol, |
13725 | /// or category. |
13726 | PCC_ObjCInterface, |
13727 | /// Code completion occurs within an Objective-C implementation or |
13728 | /// category implementation |
13729 | PCC_ObjCImplementation, |
13730 | /// Code completion occurs within the list of instance variables |
13731 | /// in an Objective-C interface, protocol, category, or implementation. |
13732 | PCC_ObjCInstanceVariableList, |
13733 | /// Code completion occurs following one or more template |
13734 | /// headers. |
13735 | PCC_Template, |
13736 | /// Code completion occurs following one or more template |
13737 | /// headers within a class. |
13738 | PCC_MemberTemplate, |
13739 | /// Code completion occurs within an expression. |
13740 | PCC_Expression, |
13741 | /// Code completion occurs within a statement, which may |
13742 | /// also be an expression or a declaration. |
13743 | PCC_Statement, |
13744 | /// Code completion occurs at the beginning of the |
13745 | /// initialization statement (or expression) in a for loop. |
13746 | PCC_ForInit, |
13747 | /// Code completion occurs within the condition of an if, |
13748 | /// while, switch, or for statement. |
13749 | PCC_Condition, |
13750 | /// Code completion occurs within the body of a function on a |
13751 | /// recovery path, where we do not have a specific handle on our position |
13752 | /// in the grammar. |
13753 | PCC_RecoveryInFunction, |
13754 | /// Code completion occurs where only a type is permitted. |
13755 | PCC_Type, |
13756 | /// Code completion occurs in a parenthesized expression, which |
13757 | /// might also be a type cast. |
13758 | PCC_ParenthesizedExpression, |
13759 | /// Code completion occurs within a sequence of declaration |
13760 | /// specifiers within a function, method, or block. |
13761 | PCC_LocalDeclarationSpecifiers, |
13762 | /// Code completion occurs at top-level in a REPL session |
13763 | PCC_TopLevelOrExpression, |
13764 | }; |
13765 | |
13766 | void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path); |
13767 | void CodeCompleteOrdinaryName(Scope *S, |
13768 | ParserCompletionContext CompletionContext); |
13769 | void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, |
13770 | bool AllowNonIdentifiers, |
13771 | bool AllowNestedNameSpecifiers); |
13772 | |
13773 | struct CodeCompleteExpressionData; |
13774 | void CodeCompleteExpression(Scope *S, |
13775 | const CodeCompleteExpressionData &Data); |
13776 | void CodeCompleteExpression(Scope *S, QualType PreferredType, |
13777 | bool IsParenthesized = false); |
13778 | void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase, |
13779 | SourceLocation OpLoc, bool IsArrow, |
13780 | bool IsBaseExprStatement, |
13781 | QualType PreferredType); |
13782 | void CodeCompletePostfixExpression(Scope *S, ExprResult LHS, |
13783 | QualType PreferredType); |
13784 | void CodeCompleteTag(Scope *S, unsigned TagSpec); |
13785 | void CodeCompleteTypeQualifiers(DeclSpec &DS); |
13786 | void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D, |
13787 | const VirtSpecifiers *VS = nullptr); |
13788 | void CodeCompleteBracketDeclarator(Scope *S); |
13789 | void CodeCompleteCase(Scope *S); |
13790 | enum class AttributeCompletion { |
13791 | Attribute, |
13792 | Scope, |
13793 | None, |
13794 | }; |
13795 | void CodeCompleteAttribute( |
13796 | AttributeCommonInfo::Syntax Syntax, |
13797 | AttributeCompletion Completion = AttributeCompletion::Attribute, |
13798 | const IdentifierInfo *Scope = nullptr); |
13799 | /// Determines the preferred type of the current function argument, by |
13800 | /// examining the signatures of all possible overloads. |
13801 | /// Returns null if unknown or ambiguous, or if code completion is off. |
13802 | /// |
13803 | /// If the code completion point has been reached, also reports the function |
13804 | /// signatures that were considered. |
13805 | /// |
13806 | /// FIXME: rename to GuessCallArgumentType to reduce confusion. |
13807 | QualType ProduceCallSignatureHelp(Expr *Fn, ArrayRef<Expr *> Args, |
13808 | SourceLocation OpenParLoc); |
13809 | QualType ProduceConstructorSignatureHelp(QualType Type, SourceLocation Loc, |
13810 | ArrayRef<Expr *> Args, |
13811 | SourceLocation OpenParLoc, |
13812 | bool Braced); |
13813 | QualType ProduceCtorInitMemberSignatureHelp( |
13814 | Decl *ConstructorDecl, CXXScopeSpec SS, ParsedType TemplateTypeTy, |
13815 | ArrayRef<Expr *> ArgExprs, IdentifierInfo *II, SourceLocation OpenParLoc, |
13816 | bool Braced); |
13817 | QualType ProduceTemplateArgumentSignatureHelp( |
13818 | TemplateTy, ArrayRef<ParsedTemplateArgument>, SourceLocation LAngleLoc); |
13819 | void CodeCompleteInitializer(Scope *S, Decl *D); |
13820 | /// Trigger code completion for a record of \p BaseType. \p InitExprs are |
13821 | /// expressions in the initializer list seen so far and \p D is the current |
13822 | /// Designation being parsed. |
13823 | void CodeCompleteDesignator(const QualType BaseType, |
13824 | llvm::ArrayRef<Expr *> InitExprs, |
13825 | const Designation &D); |
13826 | void CodeCompleteAfterIf(Scope *S, bool IsBracedThen); |
13827 | |
13828 | void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext, |
13829 | bool IsUsingDeclaration, QualType BaseType, |
13830 | QualType PreferredType); |
13831 | void CodeCompleteUsing(Scope *S); |
13832 | void CodeCompleteUsingDirective(Scope *S); |
13833 | void CodeCompleteNamespaceDecl(Scope *S); |
13834 | void CodeCompleteNamespaceAliasDecl(Scope *S); |
13835 | void CodeCompleteOperatorName(Scope *S); |
13836 | void CodeCompleteConstructorInitializer( |
13837 | Decl *Constructor, |
13838 | ArrayRef<CXXCtorInitializer *> Initializers); |
13839 | |
13840 | void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, |
13841 | bool AfterAmpersand); |
13842 | void CodeCompleteAfterFunctionEquals(Declarator &D); |
13843 | |
13844 | void CodeCompleteObjCAtDirective(Scope *S); |
13845 | void CodeCompleteObjCAtVisibility(Scope *S); |
13846 | void CodeCompleteObjCAtStatement(Scope *S); |
13847 | void CodeCompleteObjCAtExpression(Scope *S); |
13848 | void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); |
13849 | void CodeCompleteObjCPropertyGetter(Scope *S); |
13850 | void CodeCompleteObjCPropertySetter(Scope *S); |
13851 | void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, |
13852 | bool IsParameter); |
13853 | void CodeCompleteObjCMessageReceiver(Scope *S); |
13854 | void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, |
13855 | ArrayRef<IdentifierInfo *> SelIdents, |
13856 | bool AtArgumentExpression); |
13857 | void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, |
13858 | ArrayRef<IdentifierInfo *> SelIdents, |
13859 | bool AtArgumentExpression, |
13860 | bool IsSuper = false); |
13861 | void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, |
13862 | ArrayRef<IdentifierInfo *> SelIdents, |
13863 | bool AtArgumentExpression, |
13864 | ObjCInterfaceDecl *Super = nullptr); |
13865 | void CodeCompleteObjCForCollection(Scope *S, |
13866 | DeclGroupPtrTy IterationVar); |
13867 | void CodeCompleteObjCSelector(Scope *S, |
13868 | ArrayRef<IdentifierInfo *> SelIdents); |
13869 | void CodeCompleteObjCProtocolReferences( |
13870 | ArrayRef<IdentifierLocPair> Protocols); |
13871 | void CodeCompleteObjCProtocolDecl(Scope *S); |
13872 | void CodeCompleteObjCInterfaceDecl(Scope *S); |
13873 | void CodeCompleteObjCClassForwardDecl(Scope *S); |
13874 | void CodeCompleteObjCSuperclass(Scope *S, |
13875 | IdentifierInfo *ClassName, |
13876 | SourceLocation ClassNameLoc); |
13877 | void CodeCompleteObjCImplementationDecl(Scope *S); |
13878 | void CodeCompleteObjCInterfaceCategory(Scope *S, |
13879 | IdentifierInfo *ClassName, |
13880 | SourceLocation ClassNameLoc); |
13881 | void CodeCompleteObjCImplementationCategory(Scope *S, |
13882 | IdentifierInfo *ClassName, |
13883 | SourceLocation ClassNameLoc); |
13884 | void CodeCompleteObjCPropertyDefinition(Scope *S); |
13885 | void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, |
13886 | IdentifierInfo *PropertyName); |
13887 | void CodeCompleteObjCMethodDecl(Scope *S, |
13888 | std::optional<bool> IsInstanceMethod, |
13889 | ParsedType ReturnType); |
13890 | void CodeCompleteObjCMethodDeclSelector(Scope *S, |
13891 | bool IsInstanceMethod, |
13892 | bool AtParameterName, |
13893 | ParsedType ReturnType, |
13894 | ArrayRef<IdentifierInfo *> SelIdents); |
13895 | void CodeCompleteObjCClassPropertyRefExpr(Scope *S, IdentifierInfo &ClassName, |
13896 | SourceLocation ClassNameLoc, |
13897 | bool IsBaseExprStatement); |
13898 | void CodeCompletePreprocessorDirective(bool InConditional); |
13899 | void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); |
13900 | void CodeCompletePreprocessorMacroName(bool IsDefinition); |
13901 | void CodeCompletePreprocessorExpression(); |
13902 | void CodeCompletePreprocessorMacroArgument(Scope *S, |
13903 | IdentifierInfo *Macro, |
13904 | MacroInfo *MacroInfo, |
13905 | unsigned Argument); |
13906 | void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled); |
13907 | void CodeCompleteNaturalLanguage(); |
13908 | void CodeCompleteAvailabilityPlatformName(); |
13909 | void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, |
13910 | CodeCompletionTUInfo &CCTUInfo, |
13911 | SmallVectorImpl<CodeCompletionResult> &Results); |
13912 | //@} |
13913 | |
13914 | //===--------------------------------------------------------------------===// |
13915 | // Extra semantic analysis beyond the C type system |
13916 | |
13917 | public: |
13918 | SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, |
13919 | unsigned ByteNo) const; |
13920 | |
13921 | enum FormatArgumentPassingKind { |
13922 | FAPK_Fixed, // values to format are fixed (no C-style variadic arguments) |
13923 | FAPK_Variadic, // values to format are passed as variadic arguments |
13924 | FAPK_VAList, // values to format are passed in a va_list |
13925 | }; |
13926 | |
13927 | // Used to grab the relevant information from a FormatAttr and a |
13928 | // FunctionDeclaration. |
13929 | struct FormatStringInfo { |
13930 | unsigned FormatIdx; |
13931 | unsigned FirstDataArg; |
13932 | FormatArgumentPassingKind ArgPassingKind; |
13933 | }; |
13934 | |
13935 | static bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember, |
13936 | bool IsVariadic, FormatStringInfo *FSI); |
13937 | |
13938 | private: |
13939 | void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, |
13940 | const ArraySubscriptExpr *ASE = nullptr, |
13941 | bool AllowOnePastEnd = true, bool IndexNegated = false); |
13942 | void CheckArrayAccess(const Expr *E); |
13943 | |
13944 | bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, |
13945 | const FunctionProtoType *Proto); |
13946 | bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc, |
13947 | ArrayRef<const Expr *> Args); |
13948 | bool CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall, |
13949 | const FunctionProtoType *Proto); |
13950 | bool CheckOtherCall(CallExpr *TheCall, const FunctionProtoType *Proto); |
13951 | void CheckConstructorCall(FunctionDecl *FDecl, QualType ThisType, |
13952 | ArrayRef<const Expr *> Args, |
13953 | const FunctionProtoType *Proto, SourceLocation Loc); |
13954 | |
13955 | void checkAIXMemberAlignment(SourceLocation Loc, const Expr *Arg); |
13956 | |
13957 | void CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl, |
13958 | StringRef ParamName, QualType ArgTy, QualType ParamTy); |
13959 | |
13960 | void checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, |
13961 | const Expr *ThisArg, ArrayRef<const Expr *> Args, |
13962 | bool IsMemberFunction, SourceLocation Loc, SourceRange Range, |
13963 | VariadicCallType CallType); |
13964 | |
13965 | bool CheckObjCString(Expr *Arg); |
13966 | ExprResult CheckOSLogFormatStringArg(Expr *Arg); |
13967 | |
13968 | ExprResult CheckBuiltinFunctionCall(FunctionDecl *FDecl, |
13969 | unsigned BuiltinID, CallExpr *TheCall); |
13970 | |
13971 | bool CheckTSBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13972 | CallExpr *TheCall); |
13973 | |
13974 | void checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD, CallExpr *TheCall); |
13975 | |
13976 | bool CheckARMBuiltinExclusiveCall(unsigned BuiltinID, CallExpr *TheCall, |
13977 | unsigned MaxWidth); |
13978 | bool CheckNeonBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13979 | CallExpr *TheCall); |
13980 | bool CheckMVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
13981 | bool CheckSVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
13982 | bool ParseSVEImmChecks(CallExpr *TheCall, |
13983 | SmallVector<std::tuple<int, int, int>, 3> &ImmChecks); |
13984 | bool CheckSMEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
13985 | bool CheckCDEBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13986 | CallExpr *TheCall); |
13987 | bool CheckARMCoprocessorImmediate(const TargetInfo &TI, const Expr *CoprocArg, |
13988 | bool WantCDE); |
13989 | bool CheckARMBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13990 | CallExpr *TheCall); |
13991 | |
13992 | bool CheckAArch64BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13993 | CallExpr *TheCall); |
13994 | bool CheckBPFBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
13995 | bool CheckHexagonBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
13996 | bool CheckHexagonBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall); |
13997 | bool CheckMipsBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13998 | CallExpr *TheCall); |
13999 | bool CheckMipsBuiltinCpu(const TargetInfo &TI, unsigned BuiltinID, |
14000 | CallExpr *TheCall); |
14001 | bool CheckMipsBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall); |
14002 | bool CheckSystemZBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
14003 | bool CheckX86BuiltinRoundingOrSAE(unsigned BuiltinID, CallExpr *TheCall); |
14004 | bool CheckX86BuiltinGatherScatterScale(unsigned BuiltinID, CallExpr *TheCall); |
14005 | bool CheckX86BuiltinTileArguments(unsigned BuiltinID, CallExpr *TheCall); |
14006 | bool CheckX86BuiltinTileArgumentsRange(CallExpr *TheCall, |
14007 | ArrayRef<int> ArgNums); |
14008 | bool CheckX86BuiltinTileDuplicate(CallExpr *TheCall, ArrayRef<int> ArgNums); |
14009 | bool CheckX86BuiltinTileRangeAndDuplicate(CallExpr *TheCall, |
14010 | ArrayRef<int> ArgNums); |
14011 | bool CheckX86BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
14012 | CallExpr *TheCall); |
14013 | bool CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
14014 | CallExpr *TheCall); |
14015 | bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
14016 | bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum); |
14017 | bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
14018 | CallExpr *TheCall); |
14019 | void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D); |
14020 | bool CheckLoongArchBuiltinFunctionCall(const TargetInfo &TI, |
14021 | unsigned BuiltinID, CallExpr *TheCall); |
14022 | bool CheckWebAssemblyBuiltinFunctionCall(const TargetInfo &TI, |
14023 | unsigned BuiltinID, |
14024 | CallExpr *TheCall); |
14025 | bool CheckNVPTXBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
14026 | CallExpr *TheCall); |
14027 | |
14028 | bool SemaBuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall); |
14029 | bool SemaBuiltinVAStartARMMicrosoft(CallExpr *Call); |
14030 | bool SemaBuiltinUnorderedCompare(CallExpr *TheCall, unsigned BuiltinID); |
14031 | bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs, |
14032 | unsigned BuiltinID); |
14033 | bool SemaBuiltinComplex(CallExpr *TheCall); |
14034 | bool SemaBuiltinVSX(CallExpr *TheCall); |
14035 | bool SemaBuiltinOSLogFormat(CallExpr *TheCall); |
14036 | bool SemaValueIsRunOfOnes(CallExpr *TheCall, unsigned ArgNum); |
14037 | |
14038 | public: |
14039 | // Used by C++ template instantiation. |
14040 | ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); |
14041 | ExprResult SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo, |
14042 | SourceLocation BuiltinLoc, |
14043 | SourceLocation RParenLoc); |
14044 | |
14045 | private: |
14046 | bool SemaBuiltinPrefetch(CallExpr *TheCall); |
14047 | bool SemaBuiltinAllocaWithAlign(CallExpr *TheCall); |
14048 | bool SemaBuiltinArithmeticFence(CallExpr *TheCall); |
14049 | bool SemaBuiltinAssume(CallExpr *TheCall); |
14050 | bool SemaBuiltinAssumeAligned(CallExpr *TheCall); |
14051 | bool SemaBuiltinLongjmp(CallExpr *TheCall); |
14052 | bool SemaBuiltinSetjmp(CallExpr *TheCall); |
14053 | ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); |
14054 | ExprResult SemaBuiltinNontemporalOverloaded(ExprResult TheCallResult); |
14055 | ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult, |
14056 | AtomicExpr::AtomicOp Op); |
14057 | ExprResult SemaBuiltinOperatorNewDeleteOverloaded(ExprResult TheCallResult, |
14058 | bool IsDelete); |
14059 | bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, |
14060 | llvm::APSInt &Result); |
14061 | bool SemaBuiltinConstantArgRange(CallExpr *TheCall, int ArgNum, int Low, |
14062 | int High, bool RangeIsError = true); |
14063 | bool SemaBuiltinConstantArgMultiple(CallExpr *TheCall, int ArgNum, |
14064 | unsigned Multiple); |
14065 | bool SemaBuiltinConstantArgPower2(CallExpr *TheCall, int ArgNum); |
14066 | bool SemaBuiltinConstantArgShiftedByte(CallExpr *TheCall, int ArgNum, |
14067 | unsigned ArgBits); |
14068 | bool SemaBuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall, int ArgNum, |
14069 | unsigned ArgBits); |
14070 | bool SemaBuiltinARMSpecialReg(unsigned BuiltinID, CallExpr *TheCall, |
14071 | int ArgNum, unsigned ExpectedFieldNum, |
14072 | bool AllowName); |
14073 | bool SemaBuiltinARMMemoryTaggingCall(unsigned BuiltinID, CallExpr *TheCall); |
14074 | bool SemaBuiltinPPCMMACall(CallExpr *TheCall, unsigned BuiltinID, |
14075 | const char *TypeDesc); |
14076 | |
14077 | bool CheckPPCMMAType(QualType Type, SourceLocation TypeLoc); |
14078 | |
14079 | bool SemaBuiltinElementwiseMath(CallExpr *TheCall); |
14080 | bool SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall); |
14081 | bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall); |
14082 | bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall); |
14083 | |
14084 | bool SemaBuiltinNonDeterministicValue(CallExpr *TheCall); |
14085 | |
14086 | // Matrix builtin handling. |
14087 | ExprResult SemaBuiltinMatrixTranspose(CallExpr *TheCall, |
14088 | ExprResult CallResult); |
14089 | ExprResult SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall, |
14090 | ExprResult CallResult); |
14091 | ExprResult SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall, |
14092 | ExprResult CallResult); |
14093 | |
14094 | // WebAssembly builtin handling. |
14095 | bool BuiltinWasmRefNullExtern(CallExpr *TheCall); |
14096 | bool BuiltinWasmRefNullFunc(CallExpr *TheCall); |
14097 | bool BuiltinWasmTableGet(CallExpr *TheCall); |
14098 | bool BuiltinWasmTableSet(CallExpr *TheCall); |
14099 | bool BuiltinWasmTableSize(CallExpr *TheCall); |
14100 | bool BuiltinWasmTableGrow(CallExpr *TheCall); |
14101 | bool BuiltinWasmTableFill(CallExpr *TheCall); |
14102 | bool BuiltinWasmTableCopy(CallExpr *TheCall); |
14103 | |
14104 | public: |
14105 | enum FormatStringType { |
14106 | FST_Scanf, |
14107 | FST_Printf, |
14108 | FST_NSString, |
14109 | FST_Strftime, |
14110 | FST_Strfmon, |
14111 | FST_Kprintf, |
14112 | FST_FreeBSDKPrintf, |
14113 | FST_OSTrace, |
14114 | FST_OSLog, |
14115 | FST_Unknown |
14116 | }; |
14117 | static FormatStringType GetFormatStringType(const FormatAttr *Format); |
14118 | |
14119 | bool FormatStringHasSArg(const StringLiteral *FExpr); |
14120 | |
14121 | static bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx); |
14122 | |
14123 | private: |
14124 | bool CheckFormatArguments(const FormatAttr *Format, |
14125 | ArrayRef<const Expr *> Args, bool IsCXXMember, |
14126 | VariadicCallType CallType, SourceLocation Loc, |
14127 | SourceRange Range, |
14128 | llvm::SmallBitVector &CheckedVarArgs); |
14129 | bool CheckFormatArguments(ArrayRef<const Expr *> Args, |
14130 | FormatArgumentPassingKind FAPK, unsigned format_idx, |
14131 | unsigned firstDataArg, FormatStringType Type, |
14132 | VariadicCallType CallType, SourceLocation Loc, |
14133 | SourceRange range, |
14134 | llvm::SmallBitVector &CheckedVarArgs); |
14135 | |
14136 | void CheckInfNaNFunction(const CallExpr *Call, const FunctionDecl *FDecl); |
14137 | |
14138 | void CheckAbsoluteValueFunction(const CallExpr *Call, |
14139 | const FunctionDecl *FDecl); |
14140 | |
14141 | void CheckMaxUnsignedZero(const CallExpr *Call, const FunctionDecl *FDecl); |
14142 | |
14143 | void CheckMemaccessArguments(const CallExpr *Call, |
14144 | unsigned BId, |
14145 | IdentifierInfo *FnName); |
14146 | |
14147 | void CheckStrlcpycatArguments(const CallExpr *Call, |
14148 | IdentifierInfo *FnName); |
14149 | |
14150 | void CheckStrncatArguments(const CallExpr *Call, |
14151 | IdentifierInfo *FnName); |
14152 | |
14153 | void CheckFreeArguments(const CallExpr *E); |
14154 | |
14155 | void CheckReturnValExpr(Expr *RetValExp, QualType lhsType, |
14156 | SourceLocation ReturnLoc, |
14157 | bool isObjCMethod = false, |
14158 | const AttrVec *Attrs = nullptr, |
14159 | const FunctionDecl *FD = nullptr); |
14160 | |
14161 | public: |
14162 | void CheckFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS, |
14163 | BinaryOperatorKind Opcode); |
14164 | |
14165 | private: |
14166 | void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); |
14167 | void CheckBoolLikeConversion(Expr *E, SourceLocation CC); |
14168 | void CheckForIntOverflow(const Expr *E); |
14169 | void CheckUnsequencedOperations(const Expr *E); |
14170 | |
14171 | /// Perform semantic checks on a completed expression. This will either |
14172 | /// be a full-expression or a default argument expression. |
14173 | void CheckCompletedExpr(Expr *E, SourceLocation CheckLoc = SourceLocation(), |
14174 | bool IsConstexpr = false); |
14175 | |
14176 | void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, |
14177 | Expr *Init); |
14178 | |
14179 | /// Check if there is a field shadowing. |
14180 | void CheckShadowInheritedFields(const SourceLocation &Loc, |
14181 | DeclarationName FieldName, |
14182 | const CXXRecordDecl *RD, |
14183 | bool DeclIsField = true); |
14184 | |
14185 | /// Check if the given expression contains 'break' or 'continue' |
14186 | /// statement that produces control flow different from GCC. |
14187 | void CheckBreakContinueBinding(Expr *E); |
14188 | |
14189 | /// Check whether receiver is mutable ObjC container which |
14190 | /// attempts to add itself into the container |
14191 | void CheckObjCCircularContainer(ObjCMessageExpr *Message); |
14192 | |
14193 | void CheckTCBEnforcement(const SourceLocation CallExprLoc, |
14194 | const NamedDecl *Callee); |
14195 | |
14196 | void AnalyzeDeleteExprMismatch(const CXXDeleteExpr *DE); |
14197 | void AnalyzeDeleteExprMismatch(FieldDecl *Field, SourceLocation DeleteLoc, |
14198 | bool DeleteWasArrayForm); |
14199 | public: |
14200 | /// Register a magic integral constant to be used as a type tag. |
14201 | void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind, |
14202 | uint64_t MagicValue, QualType Type, |
14203 | bool LayoutCompatible, bool MustBeNull); |
14204 | |
14205 | struct TypeTagData { |
14206 | TypeTagData() {} |
14207 | |
14208 | TypeTagData(QualType Type, bool LayoutCompatible, bool MustBeNull) : |
14209 | Type(Type), LayoutCompatible(LayoutCompatible), |
14210 | MustBeNull(MustBeNull) |
14211 | {} |
14212 | |
14213 | QualType Type; |
14214 | |
14215 | /// If true, \c Type should be compared with other expression's types for |
14216 | /// layout-compatibility. |
14217 | LLVM_PREFERRED_TYPE(bool) |
14218 | unsigned LayoutCompatible : 1; |
14219 | LLVM_PREFERRED_TYPE(bool) |
14220 | unsigned MustBeNull : 1; |
14221 | }; |
14222 | |
14223 | /// A pair of ArgumentKind identifier and magic value. This uniquely |
14224 | /// identifies the magic value. |
14225 | typedef std::pair<const IdentifierInfo *, uint64_t> TypeTagMagicValue; |
14226 | |
14227 | private: |
14228 | /// A map from magic value to type information. |
14229 | std::unique_ptr<llvm::DenseMap<TypeTagMagicValue, TypeTagData>> |
14230 | TypeTagForDatatypeMagicValues; |
14231 | |
14232 | /// Peform checks on a call of a function with argument_with_type_tag |
14233 | /// or pointer_with_type_tag attributes. |
14234 | void CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr, |
14235 | const ArrayRef<const Expr *> ExprArgs, |
14236 | SourceLocation CallSiteLoc); |
14237 | |
14238 | /// Check if we are taking the address of a packed field |
14239 | /// as this may be a problem if the pointer value is dereferenced. |
14240 | void CheckAddressOfPackedMember(Expr *rhs); |
14241 | |
14242 | /// The parser's current scope. |
14243 | /// |
14244 | /// The parser maintains this state here. |
14245 | Scope *CurScope; |
14246 | |
14247 | mutable IdentifierInfo *Ident_super; |
14248 | |
14249 | /// Nullability type specifiers. |
14250 | IdentifierInfo *Ident__Nonnull = nullptr; |
14251 | IdentifierInfo *Ident__Nullable = nullptr; |
14252 | IdentifierInfo *Ident__Nullable_result = nullptr; |
14253 | IdentifierInfo *Ident__Null_unspecified = nullptr; |
14254 | |
14255 | IdentifierInfo *Ident_NSError = nullptr; |
14256 | |
14257 | /// The handler for the FileChanged preprocessor events. |
14258 | /// |
14259 | /// Used for diagnostics that implement custom semantic analysis for #include |
14260 | /// directives, like -Wpragma-pack. |
14261 | sema::SemaPPCallbacks *SemaPPCallbackHandler; |
14262 | |
14263 | protected: |
14264 | friend class Parser; |
14265 | friend class InitializationSequence; |
14266 | friend class ASTReader; |
14267 | friend class ASTDeclReader; |
14268 | friend class ASTWriter; |
14269 | |
14270 | public: |
14271 | /// Retrieve the keyword associated |
14272 | IdentifierInfo *getNullabilityKeyword(NullabilityKind nullability); |
14273 | |
14274 | /// The struct behind the CFErrorRef pointer. |
14275 | RecordDecl *CFError = nullptr; |
14276 | bool isCFError(RecordDecl *D); |
14277 | |
14278 | /// Retrieve the identifier "NSError". |
14279 | IdentifierInfo *getNSErrorIdent(); |
14280 | |
14281 | /// Retrieve the parser's current scope. |
14282 | /// |
14283 | /// This routine must only be used when it is certain that semantic analysis |
14284 | /// and the parser are in precisely the same context, which is not the case |
14285 | /// when, e.g., we are performing any kind of template instantiation. |
14286 | /// Therefore, the only safe places to use this scope are in the parser |
14287 | /// itself and in routines directly invoked from the parser and *never* from |
14288 | /// template substitution or instantiation. |
14289 | Scope *getCurScope() const { return CurScope; } |
14290 | |
14291 | void incrementMSManglingNumber() const { |
14292 | return CurScope->incrementMSManglingNumber(); |
14293 | } |
14294 | |
14295 | IdentifierInfo *getSuperIdentifier() const; |
14296 | |
14297 | ObjCContainerDecl *getObjCDeclContext() const; |
14298 | |
14299 | DeclContext *getCurLexicalContext() const { |
14300 | return OriginalLexicalContext ? OriginalLexicalContext : CurContext; |
14301 | } |
14302 | |
14303 | const DeclContext *getCurObjCLexicalContext() const { |
14304 | const DeclContext *DC = getCurLexicalContext(); |
14305 | // A category implicitly has the attribute of the interface. |
14306 | if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(Val: DC)) |
14307 | DC = CatD->getClassInterface(); |
14308 | return DC; |
14309 | } |
14310 | |
14311 | /// Determine the number of levels of enclosing template parameters. This is |
14312 | /// only usable while parsing. Note that this does not include dependent |
14313 | /// contexts in which no template parameters have yet been declared, such as |
14314 | /// in a terse function template or generic lambda before the first 'auto' is |
14315 | /// encountered. |
14316 | unsigned getTemplateDepth(Scope *S) const; |
14317 | |
14318 | /// To be used for checking whether the arguments being passed to |
14319 | /// function exceeds the number of parameters expected for it. |
14320 | static bool TooManyArguments(size_t NumParams, size_t NumArgs, |
14321 | bool PartialOverloading = false) { |
14322 | // We check whether we're just after a comma in code-completion. |
14323 | if (NumArgs > 0 && PartialOverloading) |
14324 | return NumArgs + 1 > NumParams; // If so, we view as an extra argument. |
14325 | return NumArgs > NumParams; |
14326 | } |
14327 | |
14328 | // Emitting members of dllexported classes is delayed until the class |
14329 | // (including field initializers) is fully parsed. |
14330 | SmallVector<CXXRecordDecl*, 4> DelayedDllExportClasses; |
14331 | SmallVector<CXXMethodDecl*, 4> DelayedDllExportMemberFunctions; |
14332 | |
14333 | private: |
14334 | int ParsingClassDepth = 0; |
14335 | |
14336 | class SavePendingParsedClassStateRAII { |
14337 | public: |
14338 | SavePendingParsedClassStateRAII(Sema &S) : S(S) { swapSavedState(); } |
14339 | |
14340 | ~SavePendingParsedClassStateRAII() { |
14341 | assert(S.DelayedOverridingExceptionSpecChecks.empty() && |
14342 | "there shouldn't be any pending delayed exception spec checks" ); |
14343 | assert(S.DelayedEquivalentExceptionSpecChecks.empty() && |
14344 | "there shouldn't be any pending delayed exception spec checks" ); |
14345 | swapSavedState(); |
14346 | } |
14347 | |
14348 | private: |
14349 | Sema &S; |
14350 | decltype(DelayedOverridingExceptionSpecChecks) |
14351 | SavedOverridingExceptionSpecChecks; |
14352 | decltype(DelayedEquivalentExceptionSpecChecks) |
14353 | SavedEquivalentExceptionSpecChecks; |
14354 | |
14355 | void swapSavedState() { |
14356 | SavedOverridingExceptionSpecChecks.swap( |
14357 | RHS&: S.DelayedOverridingExceptionSpecChecks); |
14358 | SavedEquivalentExceptionSpecChecks.swap( |
14359 | RHS&: S.DelayedEquivalentExceptionSpecChecks); |
14360 | } |
14361 | }; |
14362 | |
14363 | /// Helper class that collects misaligned member designations and |
14364 | /// their location info for delayed diagnostics. |
14365 | struct MisalignedMember { |
14366 | Expr *E; |
14367 | RecordDecl *RD; |
14368 | ValueDecl *MD; |
14369 | CharUnits Alignment; |
14370 | |
14371 | MisalignedMember() : E(), RD(), MD() {} |
14372 | MisalignedMember(Expr *E, RecordDecl *RD, ValueDecl *MD, |
14373 | CharUnits Alignment) |
14374 | : E(E), RD(RD), MD(MD), Alignment(Alignment) {} |
14375 | explicit MisalignedMember(Expr *E) |
14376 | : MisalignedMember(E, nullptr, nullptr, CharUnits()) {} |
14377 | |
14378 | bool operator==(const MisalignedMember &m) { return this->E == m.E; } |
14379 | }; |
14380 | /// Small set of gathered accesses to potentially misaligned members |
14381 | /// due to the packed attribute. |
14382 | SmallVector<MisalignedMember, 4> MisalignedMembers; |
14383 | |
14384 | /// Adds an expression to the set of gathered misaligned members. |
14385 | void AddPotentialMisalignedMembers(Expr *E, RecordDecl *RD, ValueDecl *MD, |
14386 | CharUnits Alignment); |
14387 | |
14388 | public: |
14389 | /// Diagnoses the current set of gathered accesses. This typically |
14390 | /// happens at full expression level. The set is cleared after emitting the |
14391 | /// diagnostics. |
14392 | void DiagnoseMisalignedMembers(); |
14393 | |
14394 | /// This function checks if the expression is in the sef of potentially |
14395 | /// misaligned members and it is converted to some pointer type T with lower |
14396 | /// or equal alignment requirements. If so it removes it. This is used when |
14397 | /// we do not want to diagnose such misaligned access (e.g. in conversions to |
14398 | /// void*). |
14399 | void DiscardMisalignedMemberAddress(const Type *T, Expr *E); |
14400 | |
14401 | /// This function calls Action when it determines that E designates a |
14402 | /// misaligned member due to the packed attribute. This is used to emit |
14403 | /// local diagnostics like in reference binding. |
14404 | void RefersToMemberWithReducedAlignment( |
14405 | Expr *E, |
14406 | llvm::function_ref<void(Expr *, RecordDecl *, FieldDecl *, CharUnits)> |
14407 | Action); |
14408 | |
14409 | /// Describes the reason a calling convention specification was ignored, used |
14410 | /// for diagnostics. |
14411 | enum class CallingConventionIgnoredReason { |
14412 | ForThisTarget = 0, |
14413 | VariadicFunction, |
14414 | ConstructorDestructor, |
14415 | BuiltinFunction |
14416 | }; |
14417 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
14418 | /// context is "used as device code". |
14419 | /// |
14420 | /// - If CurLexicalContext is a kernel function or it is known that the |
14421 | /// function will be emitted for the device, emits the diagnostics |
14422 | /// immediately. |
14423 | /// - If CurLexicalContext is a function and we are compiling |
14424 | /// for the device, but we don't know that this function will be codegen'ed |
14425 | /// for devive yet, creates a diagnostic which is emitted if and when we |
14426 | /// realize that the function will be codegen'ed. |
14427 | /// |
14428 | /// Example usage: |
14429 | /// |
14430 | /// Diagnose __float128 type usage only from SYCL device code if the current |
14431 | /// target doesn't support it |
14432 | /// if (!S.Context.getTargetInfo().hasFloat128Type() && |
14433 | /// S.getLangOpts().SYCLIsDevice) |
14434 | /// SYCLDiagIfDeviceCode(Loc, diag::err_type_unsupported) << "__float128"; |
14435 | SemaDiagnosticBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, |
14436 | unsigned DiagID); |
14437 | |
14438 | void deepTypeCheckForSYCLDevice(SourceLocation UsedAt, |
14439 | llvm::DenseSet<QualType> Visited, |
14440 | ValueDecl *DeclToCheck); |
14441 | }; |
14442 | |
14443 | DeductionFailureInfo |
14444 | MakeDeductionFailureInfo(ASTContext &Context, TemplateDeductionResult TDK, |
14445 | sema::TemplateDeductionInfo &Info); |
14446 | |
14447 | /// Contains a late templated function. |
14448 | /// Will be parsed at the end of the translation unit, used by Sema & Parser. |
14449 | struct LateParsedTemplate { |
14450 | CachedTokens Toks; |
14451 | /// The template function declaration to be late parsed. |
14452 | Decl *D; |
14453 | /// Floating-point options in the point of definition. |
14454 | FPOptions FPO; |
14455 | }; |
14456 | |
14457 | template <> |
14458 | void Sema::PragmaStack<Sema::AlignPackInfo>::Act(SourceLocation PragmaLocation, |
14459 | PragmaMsStackAction Action, |
14460 | llvm::StringRef StackSlotLabel, |
14461 | AlignPackInfo Value); |
14462 | |
14463 | std::unique_ptr<sema::RISCVIntrinsicManager> |
14464 | CreateRISCVIntrinsicManager(Sema &S); |
14465 | } // end namespace clang |
14466 | |
14467 | namespace llvm { |
14468 | // Hash a FunctionDeclAndLoc by looking at both its FunctionDecl and its |
14469 | // SourceLocation. |
14470 | template <> struct DenseMapInfo<clang::Sema::FunctionDeclAndLoc> { |
14471 | using FunctionDeclAndLoc = clang::Sema::FunctionDeclAndLoc; |
14472 | using FDBaseInfo = |
14473 | DenseMapInfo<clang::CanonicalDeclPtr<const clang::FunctionDecl>>; |
14474 | |
14475 | static FunctionDeclAndLoc getEmptyKey() { |
14476 | return {.FD: FDBaseInfo::getEmptyKey(), .Loc: clang::SourceLocation()}; |
14477 | } |
14478 | |
14479 | static FunctionDeclAndLoc getTombstoneKey() { |
14480 | return {.FD: FDBaseInfo::getTombstoneKey(), .Loc: clang::SourceLocation()}; |
14481 | } |
14482 | |
14483 | static unsigned getHashValue(const FunctionDeclAndLoc &FDL) { |
14484 | return hash_combine(args: FDBaseInfo::getHashValue(P: FDL.FD), |
14485 | args: FDL.Loc.getHashValue()); |
14486 | } |
14487 | |
14488 | static bool isEqual(const FunctionDeclAndLoc &LHS, |
14489 | const FunctionDeclAndLoc &RHS) { |
14490 | return LHS.FD == RHS.FD && LHS.Loc == RHS.Loc; |
14491 | } |
14492 | }; |
14493 | } // namespace llvm |
14494 | |
14495 | #endif |
14496 | |