Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
14 | pmbaty | 1 | //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===// |
2 | // |
||
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
||
4 | // See https://llvm.org/LICENSE.txt for license information. |
||
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
||
6 | // |
||
7 | //===----------------------------------------------------------------------===// |
||
8 | // |
||
9 | // This file defines the Sema class, which performs semantic analysis and |
||
10 | // builds ASTs. |
||
11 | // |
||
12 | //===----------------------------------------------------------------------===// |
||
13 | |||
14 | #ifndef LLVM_CLANG_SEMA_SEMA_H |
||
15 | #define LLVM_CLANG_SEMA_SEMA_H |
||
16 | |||
17 | #include "clang/AST/ASTConcept.h" |
||
18 | #include "clang/AST/ASTFwd.h" |
||
19 | #include "clang/AST/Attr.h" |
||
20 | #include "clang/AST/Availability.h" |
||
21 | #include "clang/AST/ComparisonCategories.h" |
||
22 | #include "clang/AST/DeclTemplate.h" |
||
23 | #include "clang/AST/DeclarationName.h" |
||
24 | #include "clang/AST/Expr.h" |
||
25 | #include "clang/AST/ExprCXX.h" |
||
26 | #include "clang/AST/ExprConcepts.h" |
||
27 | #include "clang/AST/ExprObjC.h" |
||
28 | #include "clang/AST/ExprOpenMP.h" |
||
29 | #include "clang/AST/ExternalASTSource.h" |
||
30 | #include "clang/AST/LocInfoType.h" |
||
31 | #include "clang/AST/MangleNumberingContext.h" |
||
32 | #include "clang/AST/NSAPI.h" |
||
33 | #include "clang/AST/PrettyPrinter.h" |
||
34 | #include "clang/AST/StmtCXX.h" |
||
35 | #include "clang/AST/StmtOpenMP.h" |
||
36 | #include "clang/AST/TypeLoc.h" |
||
37 | #include "clang/AST/TypeOrdering.h" |
||
38 | #include "clang/Basic/BitmaskEnum.h" |
||
39 | #include "clang/Basic/Builtins.h" |
||
40 | #include "clang/Basic/DarwinSDKInfo.h" |
||
41 | #include "clang/Basic/ExpressionTraits.h" |
||
42 | #include "clang/Basic/Module.h" |
||
43 | #include "clang/Basic/OpenCLOptions.h" |
||
44 | #include "clang/Basic/OpenMPKinds.h" |
||
45 | #include "clang/Basic/PragmaKinds.h" |
||
46 | #include "clang/Basic/Specifiers.h" |
||
47 | #include "clang/Basic/TemplateKinds.h" |
||
48 | #include "clang/Basic/TypeTraits.h" |
||
49 | #include "clang/Sema/AnalysisBasedWarnings.h" |
||
50 | #include "clang/Sema/CleanupInfo.h" |
||
51 | #include "clang/Sema/DeclSpec.h" |
||
52 | #include "clang/Sema/ExternalSemaSource.h" |
||
53 | #include "clang/Sema/IdentifierResolver.h" |
||
54 | #include "clang/Sema/ObjCMethodList.h" |
||
55 | #include "clang/Sema/Ownership.h" |
||
56 | #include "clang/Sema/Scope.h" |
||
57 | #include "clang/Sema/SemaConcept.h" |
||
58 | #include "clang/Sema/TypoCorrection.h" |
||
59 | #include "clang/Sema/Weak.h" |
||
60 | #include "llvm/ADT/ArrayRef.h" |
||
61 | #include "llvm/ADT/SetVector.h" |
||
62 | #include "llvm/ADT/SmallBitVector.h" |
||
63 | #include "llvm/ADT/SmallPtrSet.h" |
||
64 | #include "llvm/ADT/SmallSet.h" |
||
65 | #include "llvm/ADT/SmallVector.h" |
||
66 | #include "llvm/ADT/TinyPtrVector.h" |
||
67 | #include "llvm/Frontend/OpenMP/OMPConstants.h" |
||
68 | #include <deque> |
||
69 | #include <memory> |
||
70 | #include <optional> |
||
71 | #include <string> |
||
72 | #include <tuple> |
||
73 | #include <vector> |
||
74 | |||
75 | namespace llvm { |
||
76 | class APSInt; |
||
77 | template <typename ValueT, typename ValueInfoT> class DenseSet; |
||
78 | class SmallBitVector; |
||
79 | struct InlineAsmIdentifierInfo; |
||
80 | } |
||
81 | |||
82 | namespace clang { |
||
83 | class ADLResult; |
||
84 | class ASTConsumer; |
||
85 | class ASTContext; |
||
86 | class ASTMutationListener; |
||
87 | class ASTReader; |
||
88 | class ASTWriter; |
||
89 | class ArrayType; |
||
90 | class ParsedAttr; |
||
91 | class BindingDecl; |
||
92 | class BlockDecl; |
||
93 | class CapturedDecl; |
||
94 | class CXXBasePath; |
||
95 | class CXXBasePaths; |
||
96 | class CXXBindTemporaryExpr; |
||
97 | typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; |
||
98 | class CXXConstructorDecl; |
||
99 | class CXXConversionDecl; |
||
100 | class CXXDeleteExpr; |
||
101 | class CXXDestructorDecl; |
||
102 | class CXXFieldCollector; |
||
103 | class CXXMemberCallExpr; |
||
104 | class CXXMethodDecl; |
||
105 | class CXXScopeSpec; |
||
106 | class CXXTemporary; |
||
107 | class CXXTryStmt; |
||
108 | class CallExpr; |
||
109 | class ClassTemplateDecl; |
||
110 | class ClassTemplatePartialSpecializationDecl; |
||
111 | class ClassTemplateSpecializationDecl; |
||
112 | class VarTemplatePartialSpecializationDecl; |
||
113 | class CodeCompleteConsumer; |
||
114 | class CodeCompletionAllocator; |
||
115 | class CodeCompletionTUInfo; |
||
116 | class CodeCompletionResult; |
||
117 | class CoroutineBodyStmt; |
||
118 | class Decl; |
||
119 | class DeclAccessPair; |
||
120 | class DeclContext; |
||
121 | class DeclRefExpr; |
||
122 | class DeclaratorDecl; |
||
123 | class DeducedTemplateArgument; |
||
124 | class DependentDiagnostic; |
||
125 | class DesignatedInitExpr; |
||
126 | class Designation; |
||
127 | class EnableIfAttr; |
||
128 | class EnumConstantDecl; |
||
129 | class Expr; |
||
130 | class ExtVectorType; |
||
131 | class FormatAttr; |
||
132 | class FriendDecl; |
||
133 | class FunctionDecl; |
||
134 | class FunctionProtoType; |
||
135 | class FunctionTemplateDecl; |
||
136 | class ImplicitConversionSequence; |
||
137 | typedef MutableArrayRef<ImplicitConversionSequence> ConversionSequenceList; |
||
138 | class InitListExpr; |
||
139 | class InitializationKind; |
||
140 | class InitializationSequence; |
||
141 | class InitializedEntity; |
||
142 | class IntegerLiteral; |
||
143 | class LabelStmt; |
||
144 | class LambdaExpr; |
||
145 | class LangOptions; |
||
146 | class LocalInstantiationScope; |
||
147 | class LookupResult; |
||
148 | class MacroInfo; |
||
149 | typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> ModuleIdPath; |
||
150 | class ModuleLoader; |
||
151 | class MultiLevelTemplateArgumentList; |
||
152 | class NamedDecl; |
||
153 | class ObjCCategoryDecl; |
||
154 | class ObjCCategoryImplDecl; |
||
155 | class ObjCCompatibleAliasDecl; |
||
156 | class ObjCContainerDecl; |
||
157 | class ObjCImplDecl; |
||
158 | class ObjCImplementationDecl; |
||
159 | class ObjCInterfaceDecl; |
||
160 | class ObjCIvarDecl; |
||
161 | template <class T> class ObjCList; |
||
162 | class ObjCMessageExpr; |
||
163 | class ObjCMethodDecl; |
||
164 | class ObjCPropertyDecl; |
||
165 | class ObjCProtocolDecl; |
||
166 | class OMPThreadPrivateDecl; |
||
167 | class OMPRequiresDecl; |
||
168 | class OMPDeclareReductionDecl; |
||
169 | class OMPDeclareSimdDecl; |
||
170 | class OMPClause; |
||
171 | struct OMPVarListLocTy; |
||
172 | struct OverloadCandidate; |
||
173 | enum class OverloadCandidateParamOrder : char; |
||
174 | enum OverloadCandidateRewriteKind : unsigned; |
||
175 | class OverloadCandidateSet; |
||
176 | class OverloadExpr; |
||
177 | class ParenListExpr; |
||
178 | class ParmVarDecl; |
||
179 | class Preprocessor; |
||
180 | class PseudoDestructorTypeStorage; |
||
181 | class PseudoObjectExpr; |
||
182 | class QualType; |
||
183 | class StandardConversionSequence; |
||
184 | class Stmt; |
||
185 | class StringLiteral; |
||
186 | class SwitchStmt; |
||
187 | class TemplateArgument; |
||
188 | class TemplateArgumentList; |
||
189 | class TemplateArgumentLoc; |
||
190 | class TemplateDecl; |
||
191 | class TemplateInstantiationCallback; |
||
192 | class TemplateParameterList; |
||
193 | class TemplatePartialOrderingContext; |
||
194 | class TemplateTemplateParmDecl; |
||
195 | class Token; |
||
196 | class TypeAliasDecl; |
||
197 | class TypedefDecl; |
||
198 | class TypedefNameDecl; |
||
199 | class TypeLoc; |
||
200 | class TypoCorrectionConsumer; |
||
201 | class UnqualifiedId; |
||
202 | class UnresolvedLookupExpr; |
||
203 | class UnresolvedMemberExpr; |
||
204 | class UnresolvedSetImpl; |
||
205 | class UnresolvedSetIterator; |
||
206 | class UsingDecl; |
||
207 | class UsingShadowDecl; |
||
208 | class ValueDecl; |
||
209 | class VarDecl; |
||
210 | class VarTemplateSpecializationDecl; |
||
211 | class VisibilityAttr; |
||
212 | class VisibleDeclConsumer; |
||
213 | class IndirectFieldDecl; |
||
214 | struct DeductionFailureInfo; |
||
215 | class TemplateSpecCandidateSet; |
||
216 | |||
217 | namespace sema { |
||
218 | class AccessedEntity; |
||
219 | class BlockScopeInfo; |
||
220 | class Capture; |
||
221 | class CapturedRegionScopeInfo; |
||
222 | class CapturingScopeInfo; |
||
223 | class CompoundScopeInfo; |
||
224 | class DelayedDiagnostic; |
||
225 | class DelayedDiagnosticPool; |
||
226 | class FunctionScopeInfo; |
||
227 | class LambdaScopeInfo; |
||
228 | class PossiblyUnreachableDiag; |
||
229 | class RISCVIntrinsicManager; |
||
230 | class SemaPPCallbacks; |
||
231 | class TemplateDeductionInfo; |
||
232 | } |
||
233 | |||
234 | namespace threadSafety { |
||
235 | class BeforeSet; |
||
236 | void threadSafetyCleanup(BeforeSet* Cache); |
||
237 | } |
||
238 | |||
239 | // FIXME: No way to easily map from TemplateTypeParmTypes to |
||
240 | // TemplateTypeParmDecls, so we have this horrible PointerUnion. |
||
241 | typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType *, NamedDecl *>, |
||
242 | SourceLocation> |
||
243 | UnexpandedParameterPack; |
||
244 | |||
245 | /// Describes whether we've seen any nullability information for the given |
||
246 | /// file. |
||
247 | struct FileNullability { |
||
248 | /// The first pointer declarator (of any pointer kind) in the file that does |
||
249 | /// not have a corresponding nullability annotation. |
||
250 | SourceLocation PointerLoc; |
||
251 | |||
252 | /// The end location for the first pointer declarator in the file. Used for |
||
253 | /// placing fix-its. |
||
254 | SourceLocation PointerEndLoc; |
||
255 | |||
256 | /// Which kind of pointer declarator we saw. |
||
257 | uint8_t PointerKind; |
||
258 | |||
259 | /// Whether we saw any type nullability annotations in the given file. |
||
260 | bool SawTypeNullability = false; |
||
261 | }; |
||
262 | |||
263 | /// A mapping from file IDs to a record of whether we've seen nullability |
||
264 | /// information in that file. |
||
265 | class FileNullabilityMap { |
||
266 | /// A mapping from file IDs to the nullability information for each file ID. |
||
267 | llvm::DenseMap<FileID, FileNullability> Map; |
||
268 | |||
269 | /// A single-element cache based on the file ID. |
||
270 | struct { |
||
271 | FileID File; |
||
272 | FileNullability Nullability; |
||
273 | } Cache; |
||
274 | |||
275 | public: |
||
276 | FileNullability &operator[](FileID file) { |
||
277 | // Check the single-element cache. |
||
278 | if (file == Cache.File) |
||
279 | return Cache.Nullability; |
||
280 | |||
281 | // It's not in the single-element cache; flush the cache if we have one. |
||
282 | if (!Cache.File.isInvalid()) { |
||
283 | Map[Cache.File] = Cache.Nullability; |
||
284 | } |
||
285 | |||
286 | // Pull this entry into the cache. |
||
287 | Cache.File = file; |
||
288 | Cache.Nullability = Map[file]; |
||
289 | return Cache.Nullability; |
||
290 | } |
||
291 | }; |
||
292 | |||
293 | /// Tracks expected type during expression parsing, for use in code completion. |
||
294 | /// The type is tied to a particular token, all functions that update or consume |
||
295 | /// the type take a start location of the token they are looking at as a |
||
296 | /// parameter. This avoids updating the type on hot paths in the parser. |
||
297 | class PreferredTypeBuilder { |
||
298 | public: |
||
299 | PreferredTypeBuilder(bool Enabled) : Enabled(Enabled) {} |
||
300 | |||
301 | void enterCondition(Sema &S, SourceLocation Tok); |
||
302 | void enterReturn(Sema &S, SourceLocation Tok); |
||
303 | void enterVariableInit(SourceLocation Tok, Decl *D); |
||
304 | /// Handles e.g. BaseType{ .D = Tok... |
||
305 | void enterDesignatedInitializer(SourceLocation Tok, QualType BaseType, |
||
306 | const Designation &D); |
||
307 | /// Computing a type for the function argument may require running |
||
308 | /// overloading, so we postpone its computation until it is actually needed. |
||
309 | /// |
||
310 | /// Clients should be very careful when using this function, as it stores a |
||
311 | /// function_ref, clients should make sure all calls to get() with the same |
||
312 | /// location happen while function_ref is alive. |
||
313 | /// |
||
314 | /// The callback should also emit signature help as a side-effect, but only |
||
315 | /// if the completion point has been reached. |
||
316 | void enterFunctionArgument(SourceLocation Tok, |
||
317 | llvm::function_ref<QualType()> ComputeType); |
||
318 | |||
319 | void enterParenExpr(SourceLocation Tok, SourceLocation LParLoc); |
||
320 | void enterUnary(Sema &S, SourceLocation Tok, tok::TokenKind OpKind, |
||
321 | SourceLocation OpLoc); |
||
322 | void enterBinary(Sema &S, SourceLocation Tok, Expr *LHS, tok::TokenKind Op); |
||
323 | void enterMemAccess(Sema &S, SourceLocation Tok, Expr *Base); |
||
324 | void enterSubscript(Sema &S, SourceLocation Tok, Expr *LHS); |
||
325 | /// Handles all type casts, including C-style cast, C++ casts, etc. |
||
326 | void enterTypeCast(SourceLocation Tok, QualType CastType); |
||
327 | |||
328 | /// Get the expected type associated with this location, if any. |
||
329 | /// |
||
330 | /// If the location is a function argument, determining the expected type |
||
331 | /// involves considering all function overloads and the arguments so far. |
||
332 | /// In this case, signature help for these function overloads will be reported |
||
333 | /// as a side-effect (only if the completion point has been reached). |
||
334 | QualType get(SourceLocation Tok) const { |
||
335 | if (!Enabled || Tok != ExpectedLoc) |
||
336 | return QualType(); |
||
337 | if (!Type.isNull()) |
||
338 | return Type; |
||
339 | if (ComputeType) |
||
340 | return ComputeType(); |
||
341 | return QualType(); |
||
342 | } |
||
343 | |||
344 | private: |
||
345 | bool Enabled; |
||
346 | /// Start position of a token for which we store expected type. |
||
347 | SourceLocation ExpectedLoc; |
||
348 | /// Expected type for a token starting at ExpectedLoc. |
||
349 | QualType Type; |
||
350 | /// A function to compute expected type at ExpectedLoc. It is only considered |
||
351 | /// if Type is null. |
||
352 | llvm::function_ref<QualType()> ComputeType; |
||
353 | }; |
||
354 | |||
355 | /// Sema - This implements semantic analysis and AST building for C. |
||
356 | class Sema final { |
||
357 | Sema(const Sema &) = delete; |
||
358 | void operator=(const Sema &) = delete; |
||
359 | |||
360 | ///Source of additional semantic information. |
||
361 | IntrusiveRefCntPtr<ExternalSemaSource> ExternalSource; |
||
362 | |||
363 | static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD); |
||
364 | |||
365 | /// Determine whether two declarations should be linked together, given that |
||
366 | /// the old declaration might not be visible and the new declaration might |
||
367 | /// not have external linkage. |
||
368 | bool shouldLinkPossiblyHiddenDecl(const NamedDecl *Old, |
||
369 | const NamedDecl *New) { |
||
370 | if (isVisible(Old)) |
||
371 | return true; |
||
372 | // See comment in below overload for why it's safe to compute the linkage |
||
373 | // of the new declaration here. |
||
374 | if (New->isExternallyDeclarable()) { |
||
375 | assert(Old->isExternallyDeclarable() && |
||
376 | "should not have found a non-externally-declarable previous decl"); |
||
377 | return true; |
||
378 | } |
||
379 | return false; |
||
380 | } |
||
381 | bool shouldLinkPossiblyHiddenDecl(LookupResult &Old, const NamedDecl *New); |
||
382 | |||
383 | void setupImplicitSpecialMemberType(CXXMethodDecl *SpecialMem, |
||
384 | QualType ResultTy, |
||
385 | ArrayRef<QualType> Args); |
||
386 | |||
387 | public: |
||
388 | /// The maximum alignment, same as in llvm::Value. We duplicate them here |
||
389 | /// because that allows us not to duplicate the constants in clang code, |
||
390 | /// which we must to since we can't directly use the llvm constants. |
||
391 | /// The value is verified against llvm here: lib/CodeGen/CGDecl.cpp |
||
392 | /// |
||
393 | /// This is the greatest alignment value supported by load, store, and alloca |
||
394 | /// instructions, and global values. |
||
395 | static const unsigned MaxAlignmentExponent = 32; |
||
396 | static const uint64_t MaximumAlignment = 1ull << MaxAlignmentExponent; |
||
397 | |||
398 | typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; |
||
399 | typedef OpaquePtr<TemplateName> TemplateTy; |
||
400 | typedef OpaquePtr<QualType> TypeTy; |
||
401 | |||
402 | OpenCLOptions OpenCLFeatures; |
||
403 | FPOptions CurFPFeatures; |
||
404 | |||
405 | const LangOptions &LangOpts; |
||
406 | Preprocessor &PP; |
||
407 | ASTContext &Context; |
||
408 | ASTConsumer &Consumer; |
||
409 | DiagnosticsEngine &Diags; |
||
410 | SourceManager &SourceMgr; |
||
411 | |||
412 | /// Flag indicating whether or not to collect detailed statistics. |
||
413 | bool CollectStats; |
||
414 | |||
415 | /// Code-completion consumer. |
||
416 | CodeCompleteConsumer *CodeCompleter; |
||
417 | |||
418 | /// CurContext - This is the current declaration context of parsing. |
||
419 | DeclContext *CurContext; |
||
420 | |||
421 | /// Generally null except when we temporarily switch decl contexts, |
||
422 | /// like in \see ActOnObjCTemporaryExitContainerContext. |
||
423 | DeclContext *OriginalLexicalContext; |
||
424 | |||
425 | /// VAListTagName - The declaration name corresponding to __va_list_tag. |
||
426 | /// This is used as part of a hack to omit that class from ADL results. |
||
427 | DeclarationName VAListTagName; |
||
428 | |||
429 | bool MSStructPragmaOn; // True when \#pragma ms_struct on |
||
430 | |||
431 | /// Controls member pointer representation format under the MS ABI. |
||
432 | LangOptions::PragmaMSPointersToMembersKind |
||
433 | MSPointerToMemberRepresentationMethod; |
||
434 | |||
435 | /// Stack of active SEH __finally scopes. Can be empty. |
||
436 | SmallVector<Scope*, 2> CurrentSEHFinally; |
||
437 | |||
438 | /// Source location for newly created implicit MSInheritanceAttrs |
||
439 | SourceLocation ImplicitMSInheritanceAttrLoc; |
||
440 | |||
441 | /// Holds TypoExprs that are created from `createDelayedTypo`. This is used by |
||
442 | /// `TransformTypos` in order to keep track of any TypoExprs that are created |
||
443 | /// recursively during typo correction and wipe them away if the correction |
||
444 | /// fails. |
||
445 | llvm::SmallVector<TypoExpr *, 2> TypoExprs; |
||
446 | |||
447 | /// pragma clang section kind |
||
448 | enum PragmaClangSectionKind { |
||
449 | PCSK_Invalid = 0, |
||
450 | PCSK_BSS = 1, |
||
451 | PCSK_Data = 2, |
||
452 | PCSK_Rodata = 3, |
||
453 | PCSK_Text = 4, |
||
454 | PCSK_Relro = 5 |
||
455 | }; |
||
456 | |||
457 | enum PragmaClangSectionAction { |
||
458 | PCSA_Set = 0, |
||
459 | PCSA_Clear = 1 |
||
460 | }; |
||
461 | |||
462 | struct PragmaClangSection { |
||
463 | std::string SectionName; |
||
464 | bool Valid = false; |
||
465 | SourceLocation PragmaLocation; |
||
466 | }; |
||
467 | |||
468 | PragmaClangSection PragmaClangBSSSection; |
||
469 | PragmaClangSection PragmaClangDataSection; |
||
470 | PragmaClangSection PragmaClangRodataSection; |
||
471 | PragmaClangSection PragmaClangRelroSection; |
||
472 | PragmaClangSection PragmaClangTextSection; |
||
473 | |||
474 | enum PragmaMsStackAction { |
||
475 | PSK_Reset = 0x0, // #pragma () |
||
476 | PSK_Set = 0x1, // #pragma (value) |
||
477 | PSK_Push = 0x2, // #pragma (push[, id]) |
||
478 | PSK_Pop = 0x4, // #pragma (pop[, id]) |
||
479 | PSK_Show = 0x8, // #pragma (show) -- only for "pack"! |
||
480 | PSK_Push_Set = PSK_Push | PSK_Set, // #pragma (push[, id], value) |
||
481 | PSK_Pop_Set = PSK_Pop | PSK_Set, // #pragma (pop[, id], value) |
||
482 | }; |
||
483 | |||
484 | // #pragma pack and align. |
||
485 | class AlignPackInfo { |
||
486 | public: |
||
487 | // `Native` represents default align mode, which may vary based on the |
||
488 | // platform. |
||
489 | enum Mode : unsigned char { Native, Natural, Packed, Mac68k }; |
||
490 | |||
491 | // #pragma pack info constructor |
||
492 | AlignPackInfo(AlignPackInfo::Mode M, unsigned Num, bool IsXL) |
||
493 | : PackAttr(true), AlignMode(M), PackNumber(Num), XLStack(IsXL) { |
||
494 | assert(Num == PackNumber && "The pack number has been truncated."); |
||
495 | } |
||
496 | |||
497 | // #pragma align info constructor |
||
498 | AlignPackInfo(AlignPackInfo::Mode M, bool IsXL) |
||
499 | : PackAttr(false), AlignMode(M), |
||
500 | PackNumber(M == Packed ? 1 : UninitPackVal), XLStack(IsXL) {} |
||
501 | |||
502 | explicit AlignPackInfo(bool IsXL) : AlignPackInfo(Native, IsXL) {} |
||
503 | |||
504 | AlignPackInfo() : AlignPackInfo(Native, false) {} |
||
505 | |||
506 | // When a AlignPackInfo itself cannot be used, this returns an 32-bit |
||
507 | // integer encoding for it. This should only be passed to |
||
508 | // AlignPackInfo::getFromRawEncoding, it should not be inspected directly. |
||
509 | static uint32_t getRawEncoding(const AlignPackInfo &Info) { |
||
510 | std::uint32_t Encoding{}; |
||
511 | if (Info.IsXLStack()) |
||
512 | Encoding |= IsXLMask; |
||
513 | |||
514 | Encoding |= static_cast<uint32_t>(Info.getAlignMode()) << 1; |
||
515 | |||
516 | if (Info.IsPackAttr()) |
||
517 | Encoding |= PackAttrMask; |
||
518 | |||
519 | Encoding |= static_cast<uint32_t>(Info.getPackNumber()) << 4; |
||
520 | |||
521 | return Encoding; |
||
522 | } |
||
523 | |||
524 | static AlignPackInfo getFromRawEncoding(unsigned Encoding) { |
||
525 | bool IsXL = static_cast<bool>(Encoding & IsXLMask); |
||
526 | AlignPackInfo::Mode M = |
||
527 | static_cast<AlignPackInfo::Mode>((Encoding & AlignModeMask) >> 1); |
||
528 | int PackNumber = (Encoding & PackNumMask) >> 4; |
||
529 | |||
530 | if (Encoding & PackAttrMask) |
||
531 | return AlignPackInfo(M, PackNumber, IsXL); |
||
532 | |||
533 | return AlignPackInfo(M, IsXL); |
||
534 | } |
||
535 | |||
536 | bool IsPackAttr() const { return PackAttr; } |
||
537 | |||
538 | bool IsAlignAttr() const { return !PackAttr; } |
||
539 | |||
540 | Mode getAlignMode() const { return AlignMode; } |
||
541 | |||
542 | unsigned getPackNumber() const { return PackNumber; } |
||
543 | |||
544 | bool IsPackSet() const { |
||
545 | // #pragma align, #pragma pack(), and #pragma pack(0) do not set the pack |
||
546 | // attriute on a decl. |
||
547 | return PackNumber != UninitPackVal && PackNumber != 0; |
||
548 | } |
||
549 | |||
550 | bool IsXLStack() const { return XLStack; } |
||
551 | |||
552 | bool operator==(const AlignPackInfo &Info) const { |
||
553 | return std::tie(AlignMode, PackNumber, PackAttr, XLStack) == |
||
554 | std::tie(Info.AlignMode, Info.PackNumber, Info.PackAttr, |
||
555 | Info.XLStack); |
||
556 | } |
||
557 | |||
558 | bool operator!=(const AlignPackInfo &Info) const { |
||
559 | return !(*this == Info); |
||
560 | } |
||
561 | |||
562 | private: |
||
563 | /// \brief True if this is a pragma pack attribute, |
||
564 | /// not a pragma align attribute. |
||
565 | bool PackAttr; |
||
566 | |||
567 | /// \brief The alignment mode that is in effect. |
||
568 | Mode AlignMode; |
||
569 | |||
570 | /// \brief The pack number of the stack. |
||
571 | unsigned char PackNumber; |
||
572 | |||
573 | /// \brief True if it is a XL #pragma align/pack stack. |
||
574 | bool XLStack; |
||
575 | |||
576 | /// \brief Uninitialized pack value. |
||
577 | static constexpr unsigned char UninitPackVal = -1; |
||
578 | |||
579 | // Masks to encode and decode an AlignPackInfo. |
||
580 | static constexpr uint32_t IsXLMask{0x0000'0001}; |
||
581 | static constexpr uint32_t AlignModeMask{0x0000'0006}; |
||
582 | static constexpr uint32_t PackAttrMask{0x00000'0008}; |
||
583 | static constexpr uint32_t PackNumMask{0x0000'01F0}; |
||
584 | }; |
||
585 | |||
586 | template<typename ValueType> |
||
587 | struct PragmaStack { |
||
588 | struct Slot { |
||
589 | llvm::StringRef StackSlotLabel; |
||
590 | ValueType Value; |
||
591 | SourceLocation PragmaLocation; |
||
592 | SourceLocation PragmaPushLocation; |
||
593 | Slot(llvm::StringRef StackSlotLabel, ValueType Value, |
||
594 | SourceLocation PragmaLocation, SourceLocation PragmaPushLocation) |
||
595 | : StackSlotLabel(StackSlotLabel), Value(Value), |
||
596 | PragmaLocation(PragmaLocation), |
||
597 | PragmaPushLocation(PragmaPushLocation) {} |
||
598 | }; |
||
599 | |||
600 | void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, |
||
601 | llvm::StringRef StackSlotLabel, ValueType Value) { |
||
602 | if (Action == PSK_Reset) { |
||
603 | CurrentValue = DefaultValue; |
||
604 | CurrentPragmaLocation = PragmaLocation; |
||
605 | return; |
||
606 | } |
||
607 | if (Action & PSK_Push) |
||
608 | Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation, |
||
609 | PragmaLocation); |
||
610 | else if (Action & PSK_Pop) { |
||
611 | if (!StackSlotLabel.empty()) { |
||
612 | // If we've got a label, try to find it and jump there. |
||
613 | auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) { |
||
614 | return x.StackSlotLabel == StackSlotLabel; |
||
615 | }); |
||
616 | // If we found the label so pop from there. |
||
617 | if (I != Stack.rend()) { |
||
618 | CurrentValue = I->Value; |
||
619 | CurrentPragmaLocation = I->PragmaLocation; |
||
620 | Stack.erase(std::prev(I.base()), Stack.end()); |
||
621 | } |
||
622 | } else if (!Stack.empty()) { |
||
623 | // We do not have a label, just pop the last entry. |
||
624 | CurrentValue = Stack.back().Value; |
||
625 | CurrentPragmaLocation = Stack.back().PragmaLocation; |
||
626 | Stack.pop_back(); |
||
627 | } |
||
628 | } |
||
629 | if (Action & PSK_Set) { |
||
630 | CurrentValue = Value; |
||
631 | CurrentPragmaLocation = PragmaLocation; |
||
632 | } |
||
633 | } |
||
634 | |||
635 | // MSVC seems to add artificial slots to #pragma stacks on entering a C++ |
||
636 | // method body to restore the stacks on exit, so it works like this: |
||
637 | // |
||
638 | // struct S { |
||
639 | // #pragma <name>(push, InternalPragmaSlot, <current_pragma_value>) |
||
640 | // void Method {} |
||
641 | // #pragma <name>(pop, InternalPragmaSlot) |
||
642 | // }; |
||
643 | // |
||
644 | // It works even with #pragma vtordisp, although MSVC doesn't support |
||
645 | // #pragma vtordisp(push [, id], n) |
||
646 | // syntax. |
||
647 | // |
||
648 | // Push / pop a named sentinel slot. |
||
649 | void SentinelAction(PragmaMsStackAction Action, StringRef Label) { |
||
650 | assert((Action == PSK_Push || Action == PSK_Pop) && |
||
651 | "Can only push / pop #pragma stack sentinels!"); |
||
652 | Act(CurrentPragmaLocation, Action, Label, CurrentValue); |
||
653 | } |
||
654 | |||
655 | // Constructors. |
||
656 | explicit PragmaStack(const ValueType &Default) |
||
657 | : DefaultValue(Default), CurrentValue(Default) {} |
||
658 | |||
659 | bool hasValue() const { return CurrentValue != DefaultValue; } |
||
660 | |||
661 | SmallVector<Slot, 2> Stack; |
||
662 | ValueType DefaultValue; // Value used for PSK_Reset action. |
||
663 | ValueType CurrentValue; |
||
664 | SourceLocation CurrentPragmaLocation; |
||
665 | }; |
||
666 | // FIXME: We should serialize / deserialize these if they occur in a PCH (but |
||
667 | // we shouldn't do so if they're in a module). |
||
668 | |||
669 | /// Whether to insert vtordisps prior to virtual bases in the Microsoft |
||
670 | /// C++ ABI. Possible values are 0, 1, and 2, which mean: |
||
671 | /// |
||
672 | /// 0: Suppress all vtordisps |
||
673 | /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial |
||
674 | /// structors |
||
675 | /// 2: Always insert vtordisps to support RTTI on partially constructed |
||
676 | /// objects |
||
677 | PragmaStack<MSVtorDispMode> VtorDispStack; |
||
678 | PragmaStack<AlignPackInfo> AlignPackStack; |
||
679 | // The current #pragma align/pack values and locations at each #include. |
||
680 | struct AlignPackIncludeState { |
||
681 | AlignPackInfo CurrentValue; |
||
682 | SourceLocation CurrentPragmaLocation; |
||
683 | bool HasNonDefaultValue, ShouldWarnOnInclude; |
||
684 | }; |
||
685 | SmallVector<AlignPackIncludeState, 8> AlignPackIncludeStack; |
||
686 | // Segment #pragmas. |
||
687 | PragmaStack<StringLiteral *> DataSegStack; |
||
688 | PragmaStack<StringLiteral *> BSSSegStack; |
||
689 | PragmaStack<StringLiteral *> ConstSegStack; |
||
690 | PragmaStack<StringLiteral *> CodeSegStack; |
||
691 | |||
692 | // #pragma strict_gs_check. |
||
693 | PragmaStack<bool> StrictGuardStackCheckStack; |
||
694 | |||
695 | // This stack tracks the current state of Sema.CurFPFeatures. |
||
696 | PragmaStack<FPOptionsOverride> FpPragmaStack; |
||
697 | FPOptionsOverride CurFPFeatureOverrides() { |
||
698 | FPOptionsOverride result; |
||
699 | if (!FpPragmaStack.hasValue()) { |
||
700 | result = FPOptionsOverride(); |
||
701 | } else { |
||
702 | result = FpPragmaStack.CurrentValue; |
||
703 | } |
||
704 | return result; |
||
705 | } |
||
706 | |||
707 | // RAII object to push / pop sentinel slots for all MS #pragma stacks. |
||
708 | // Actions should be performed only if we enter / exit a C++ method body. |
||
709 | class PragmaStackSentinelRAII { |
||
710 | public: |
||
711 | PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct); |
||
712 | ~PragmaStackSentinelRAII(); |
||
713 | |||
714 | private: |
||
715 | Sema &S; |
||
716 | StringRef SlotLabel; |
||
717 | bool ShouldAct; |
||
718 | }; |
||
719 | |||
720 | /// A mapping that describes the nullability we've seen in each header file. |
||
721 | FileNullabilityMap NullabilityMap; |
||
722 | |||
723 | /// Last section used with #pragma init_seg. |
||
724 | StringLiteral *CurInitSeg; |
||
725 | SourceLocation CurInitSegLoc; |
||
726 | |||
727 | /// Sections used with #pragma alloc_text. |
||
728 | llvm::StringMap<std::tuple<StringRef, SourceLocation>> FunctionToSectionMap; |
||
729 | |||
730 | /// VisContext - Manages the stack for \#pragma GCC visibility. |
||
731 | void *VisContext; // Really a "PragmaVisStack*" |
||
732 | |||
733 | /// This an attribute introduced by \#pragma clang attribute. |
||
734 | struct PragmaAttributeEntry { |
||
735 | SourceLocation Loc; |
||
736 | ParsedAttr *Attribute; |
||
737 | SmallVector<attr::SubjectMatchRule, 4> MatchRules; |
||
738 | bool IsUsed; |
||
739 | }; |
||
740 | |||
741 | /// A push'd group of PragmaAttributeEntries. |
||
742 | struct PragmaAttributeGroup { |
||
743 | /// The location of the push attribute. |
||
744 | SourceLocation Loc; |
||
745 | /// The namespace of this push group. |
||
746 | const IdentifierInfo *Namespace; |
||
747 | SmallVector<PragmaAttributeEntry, 2> Entries; |
||
748 | }; |
||
749 | |||
750 | SmallVector<PragmaAttributeGroup, 2> PragmaAttributeStack; |
||
751 | |||
752 | /// The declaration that is currently receiving an attribute from the |
||
753 | /// #pragma attribute stack. |
||
754 | const Decl *PragmaAttributeCurrentTargetDecl; |
||
755 | |||
756 | /// This represents the last location of a "#pragma clang optimize off" |
||
757 | /// directive if such a directive has not been closed by an "on" yet. If |
||
758 | /// optimizations are currently "on", this is set to an invalid location. |
||
759 | SourceLocation OptimizeOffPragmaLocation; |
||
760 | |||
761 | /// The "on" or "off" argument passed by \#pragma optimize, that denotes |
||
762 | /// whether the optimizations in the list passed to the pragma should be |
||
763 | /// turned off or on. This boolean is true by default because command line |
||
764 | /// options are honored when `#pragma optimize("", on)`. |
||
765 | /// (i.e. `ModifyFnAttributeMSPragmaOptimze()` does nothing) |
||
766 | bool MSPragmaOptimizeIsOn = true; |
||
767 | |||
768 | /// Set of no-builtin functions listed by \#pragma function. |
||
769 | llvm::SmallSetVector<StringRef, 4> MSFunctionNoBuiltins; |
||
770 | |||
771 | /// Flag indicating if Sema is building a recovery call expression. |
||
772 | /// |
||
773 | /// This flag is used to avoid building recovery call expressions |
||
774 | /// if Sema is already doing so, which would cause infinite recursions. |
||
775 | bool IsBuildingRecoveryCallExpr; |
||
776 | |||
777 | /// Used to control the generation of ExprWithCleanups. |
||
778 | CleanupInfo Cleanup; |
||
779 | |||
780 | /// ExprCleanupObjects - This is the stack of objects requiring |
||
781 | /// cleanup that are created by the current full expression. |
||
782 | SmallVector<ExprWithCleanups::CleanupObject, 8> ExprCleanupObjects; |
||
783 | |||
784 | /// Store a set of either DeclRefExprs or MemberExprs that contain a reference |
||
785 | /// to a variable (constant) that may or may not be odr-used in this Expr, and |
||
786 | /// we won't know until all lvalue-to-rvalue and discarded value conversions |
||
787 | /// have been applied to all subexpressions of the enclosing full expression. |
||
788 | /// This is cleared at the end of each full expression. |
||
789 | using MaybeODRUseExprSet = llvm::SetVector<Expr *, SmallVector<Expr *, 4>, |
||
790 | llvm::SmallPtrSet<Expr *, 4>>; |
||
791 | MaybeODRUseExprSet MaybeODRUseExprs; |
||
792 | |||
793 | std::unique_ptr<sema::FunctionScopeInfo> CachedFunctionScope; |
||
794 | |||
795 | /// Stack containing information about each of the nested |
||
796 | /// function, block, and method scopes that are currently active. |
||
797 | SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes; |
||
798 | |||
799 | /// The index of the first FunctionScope that corresponds to the current |
||
800 | /// context. |
||
801 | unsigned FunctionScopesStart = 0; |
||
802 | |||
803 | ArrayRef<sema::FunctionScopeInfo*> getFunctionScopes() const { |
||
804 | return llvm::ArrayRef(FunctionScopes.begin() + FunctionScopesStart, |
||
805 | FunctionScopes.end()); |
||
806 | } |
||
807 | |||
808 | /// Stack containing information needed when in C++2a an 'auto' is encountered |
||
809 | /// in a function declaration parameter type specifier in order to invent a |
||
810 | /// corresponding template parameter in the enclosing abbreviated function |
||
811 | /// template. This information is also present in LambdaScopeInfo, stored in |
||
812 | /// the FunctionScopes stack. |
||
813 | SmallVector<InventedTemplateParameterInfo, 4> InventedParameterInfos; |
||
814 | |||
815 | /// The index of the first InventedParameterInfo that refers to the current |
||
816 | /// context. |
||
817 | unsigned InventedParameterInfosStart = 0; |
||
818 | |||
819 | ArrayRef<InventedTemplateParameterInfo> getInventedParameterInfos() const { |
||
820 | return llvm::ArrayRef(InventedParameterInfos.begin() + |
||
821 | InventedParameterInfosStart, |
||
822 | InventedParameterInfos.end()); |
||
823 | } |
||
824 | |||
825 | typedef LazyVector<TypedefNameDecl *, ExternalSemaSource, |
||
826 | &ExternalSemaSource::ReadExtVectorDecls, 2, 2> |
||
827 | ExtVectorDeclsType; |
||
828 | |||
829 | /// ExtVectorDecls - This is a list all the extended vector types. This allows |
||
830 | /// us to associate a raw vector type with one of the ext_vector type names. |
||
831 | /// This is only necessary for issuing pretty diagnostics. |
||
832 | ExtVectorDeclsType ExtVectorDecls; |
||
833 | |||
834 | /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. |
||
835 | std::unique_ptr<CXXFieldCollector> FieldCollector; |
||
836 | |||
837 | typedef llvm::SmallSetVector<NamedDecl *, 16> NamedDeclSetType; |
||
838 | |||
839 | /// Set containing all declared private fields that are not used. |
||
840 | NamedDeclSetType UnusedPrivateFields; |
||
841 | |||
842 | /// Set containing all typedefs that are likely unused. |
||
843 | llvm::SmallSetVector<const TypedefNameDecl *, 4> |
||
844 | UnusedLocalTypedefNameCandidates; |
||
845 | |||
846 | /// Delete-expressions to be analyzed at the end of translation unit |
||
847 | /// |
||
848 | /// This list contains class members, and locations of delete-expressions |
||
849 | /// that could not be proven as to whether they mismatch with new-expression |
||
850 | /// used in initializer of the field. |
||
851 | typedef std::pair<SourceLocation, bool> DeleteExprLoc; |
||
852 | typedef llvm::SmallVector<DeleteExprLoc, 4> DeleteLocs; |
||
853 | llvm::MapVector<FieldDecl *, DeleteLocs> DeleteExprs; |
||
854 | |||
855 | typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy; |
||
856 | |||
857 | /// PureVirtualClassDiagSet - a set of class declarations which we have |
||
858 | /// emitted a list of pure virtual functions. Used to prevent emitting the |
||
859 | /// same list more than once. |
||
860 | std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet; |
||
861 | |||
862 | /// ParsingInitForAutoVars - a set of declarations with auto types for which |
||
863 | /// we are currently parsing the initializer. |
||
864 | llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars; |
||
865 | |||
866 | /// Look for a locally scoped extern "C" declaration by the given name. |
||
867 | NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name); |
||
868 | |||
869 | typedef LazyVector<VarDecl *, ExternalSemaSource, |
||
870 | &ExternalSemaSource::ReadTentativeDefinitions, 2, 2> |
||
871 | TentativeDefinitionsType; |
||
872 | |||
873 | /// All the tentative definitions encountered in the TU. |
||
874 | TentativeDefinitionsType TentativeDefinitions; |
||
875 | |||
876 | /// All the external declarations encoutered and used in the TU. |
||
877 | SmallVector<VarDecl *, 4> ExternalDeclarations; |
||
878 | |||
879 | typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource, |
||
880 | &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2> |
||
881 | UnusedFileScopedDeclsType; |
||
882 | |||
883 | /// The set of file scoped decls seen so far that have not been used |
||
884 | /// and must warn if not used. Only contains the first declaration. |
||
885 | UnusedFileScopedDeclsType UnusedFileScopedDecls; |
||
886 | |||
887 | typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource, |
||
888 | &ExternalSemaSource::ReadDelegatingConstructors, 2, 2> |
||
889 | DelegatingCtorDeclsType; |
||
890 | |||
891 | /// All the delegating constructors seen so far in the file, used for |
||
892 | /// cycle detection at the end of the TU. |
||
893 | DelegatingCtorDeclsType DelegatingCtorDecls; |
||
894 | |||
895 | /// All the overriding functions seen during a class definition |
||
896 | /// that had their exception spec checks delayed, plus the overridden |
||
897 | /// function. |
||
898 | SmallVector<std::pair<const CXXMethodDecl*, const CXXMethodDecl*>, 2> |
||
899 | DelayedOverridingExceptionSpecChecks; |
||
900 | |||
901 | /// All the function redeclarations seen during a class definition that had |
||
902 | /// their exception spec checks delayed, plus the prior declaration they |
||
903 | /// should be checked against. Except during error recovery, the new decl |
||
904 | /// should always be a friend declaration, as that's the only valid way to |
||
905 | /// redeclare a special member before its class is complete. |
||
906 | SmallVector<std::pair<FunctionDecl*, FunctionDecl*>, 2> |
||
907 | DelayedEquivalentExceptionSpecChecks; |
||
908 | |||
909 | typedef llvm::MapVector<const FunctionDecl *, |
||
910 | std::unique_ptr<LateParsedTemplate>> |
||
911 | LateParsedTemplateMapT; |
||
912 | LateParsedTemplateMapT LateParsedTemplateMap; |
||
913 | |||
914 | /// Callback to the parser to parse templated functions when needed. |
||
915 | typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT); |
||
916 | typedef void LateTemplateParserCleanupCB(void *P); |
||
917 | LateTemplateParserCB *LateTemplateParser; |
||
918 | LateTemplateParserCleanupCB *LateTemplateParserCleanup; |
||
919 | void *OpaqueParser; |
||
920 | |||
921 | void SetLateTemplateParser(LateTemplateParserCB *LTP, |
||
922 | LateTemplateParserCleanupCB *LTPCleanup, |
||
923 | void *P) { |
||
924 | LateTemplateParser = LTP; |
||
925 | LateTemplateParserCleanup = LTPCleanup; |
||
926 | OpaqueParser = P; |
||
927 | } |
||
928 | |||
929 | class DelayedDiagnostics; |
||
930 | |||
931 | class DelayedDiagnosticsState { |
||
932 | sema::DelayedDiagnosticPool *SavedPool; |
||
933 | friend class Sema::DelayedDiagnostics; |
||
934 | }; |
||
935 | typedef DelayedDiagnosticsState ParsingDeclState; |
||
936 | typedef DelayedDiagnosticsState ProcessingContextState; |
||
937 | |||
938 | /// A class which encapsulates the logic for delaying diagnostics |
||
939 | /// during parsing and other processing. |
||
940 | class DelayedDiagnostics { |
||
941 | /// The current pool of diagnostics into which delayed |
||
942 | /// diagnostics should go. |
||
943 | sema::DelayedDiagnosticPool *CurPool; |
||
944 | |||
945 | public: |
||
946 | DelayedDiagnostics() : CurPool(nullptr) {} |
||
947 | |||
948 | /// Adds a delayed diagnostic. |
||
949 | void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h |
||
950 | |||
951 | /// Determines whether diagnostics should be delayed. |
||
952 | bool shouldDelayDiagnostics() { return CurPool != nullptr; } |
||
953 | |||
954 | /// Returns the current delayed-diagnostics pool. |
||
955 | sema::DelayedDiagnosticPool *getCurrentPool() const { |
||
956 | return CurPool; |
||
957 | } |
||
958 | |||
959 | /// Enter a new scope. Access and deprecation diagnostics will be |
||
960 | /// collected in this pool. |
||
961 | DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) { |
||
962 | DelayedDiagnosticsState state; |
||
963 | state.SavedPool = CurPool; |
||
964 | CurPool = &pool; |
||
965 | return state; |
||
966 | } |
||
967 | |||
968 | /// Leave a delayed-diagnostic state that was previously pushed. |
||
969 | /// Do not emit any of the diagnostics. This is performed as part |
||
970 | /// of the bookkeeping of popping a pool "properly". |
||
971 | void popWithoutEmitting(DelayedDiagnosticsState state) { |
||
972 | CurPool = state.SavedPool; |
||
973 | } |
||
974 | |||
975 | /// Enter a new scope where access and deprecation diagnostics are |
||
976 | /// not delayed. |
||
977 | DelayedDiagnosticsState pushUndelayed() { |
||
978 | DelayedDiagnosticsState state; |
||
979 | state.SavedPool = CurPool; |
||
980 | CurPool = nullptr; |
||
981 | return state; |
||
982 | } |
||
983 | |||
984 | /// Undo a previous pushUndelayed(). |
||
985 | void popUndelayed(DelayedDiagnosticsState state) { |
||
986 | assert(CurPool == nullptr); |
||
987 | CurPool = state.SavedPool; |
||
988 | } |
||
989 | } DelayedDiagnostics; |
||
990 | |||
991 | /// A RAII object to temporarily push a declaration context. |
||
992 | class ContextRAII { |
||
993 | private: |
||
994 | Sema &S; |
||
995 | DeclContext *SavedContext; |
||
996 | ProcessingContextState SavedContextState; |
||
997 | QualType SavedCXXThisTypeOverride; |
||
998 | unsigned SavedFunctionScopesStart; |
||
999 | unsigned SavedInventedParameterInfosStart; |
||
1000 | |||
1001 | public: |
||
1002 | ContextRAII(Sema &S, DeclContext *ContextToPush, bool NewThisContext = true) |
||
1003 | : S(S), SavedContext(S.CurContext), |
||
1004 | SavedContextState(S.DelayedDiagnostics.pushUndelayed()), |
||
1005 | SavedCXXThisTypeOverride(S.CXXThisTypeOverride), |
||
1006 | SavedFunctionScopesStart(S.FunctionScopesStart), |
||
1007 | SavedInventedParameterInfosStart(S.InventedParameterInfosStart) |
||
1008 | { |
||
1009 | assert(ContextToPush && "pushing null context"); |
||
1010 | S.CurContext = ContextToPush; |
||
1011 | if (NewThisContext) |
||
1012 | S.CXXThisTypeOverride = QualType(); |
||
1013 | // Any saved FunctionScopes do not refer to this context. |
||
1014 | S.FunctionScopesStart = S.FunctionScopes.size(); |
||
1015 | S.InventedParameterInfosStart = S.InventedParameterInfos.size(); |
||
1016 | } |
||
1017 | |||
1018 | void pop() { |
||
1019 | if (!SavedContext) return; |
||
1020 | S.CurContext = SavedContext; |
||
1021 | S.DelayedDiagnostics.popUndelayed(SavedContextState); |
||
1022 | S.CXXThisTypeOverride = SavedCXXThisTypeOverride; |
||
1023 | S.FunctionScopesStart = SavedFunctionScopesStart; |
||
1024 | S.InventedParameterInfosStart = SavedInventedParameterInfosStart; |
||
1025 | SavedContext = nullptr; |
||
1026 | } |
||
1027 | |||
1028 | ~ContextRAII() { |
||
1029 | pop(); |
||
1030 | } |
||
1031 | }; |
||
1032 | |||
1033 | /// Whether the AST is currently being rebuilt to correct immediate |
||
1034 | /// invocations. Immediate invocation candidates and references to consteval |
||
1035 | /// functions aren't tracked when this is set. |
||
1036 | bool RebuildingImmediateInvocation = false; |
||
1037 | |||
1038 | /// Used to change context to isConstantEvaluated without pushing a heavy |
||
1039 | /// ExpressionEvaluationContextRecord object. |
||
1040 | bool isConstantEvaluatedOverride; |
||
1041 | |||
1042 | bool isConstantEvaluated() { |
||
1043 | return ExprEvalContexts.back().isConstantEvaluated() || |
||
1044 | isConstantEvaluatedOverride; |
||
1045 | } |
||
1046 | |||
1047 | /// RAII object to handle the state changes required to synthesize |
||
1048 | /// a function body. |
||
1049 | class SynthesizedFunctionScope { |
||
1050 | Sema &S; |
||
1051 | Sema::ContextRAII SavedContext; |
||
1052 | bool PushedCodeSynthesisContext = false; |
||
1053 | |||
1054 | public: |
||
1055 | SynthesizedFunctionScope(Sema &S, DeclContext *DC) |
||
1056 | : S(S), SavedContext(S, DC) { |
||
1057 | S.PushFunctionScope(); |
||
1058 | S.PushExpressionEvaluationContext( |
||
1059 | Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
||
1060 | if (auto *FD = dyn_cast<FunctionDecl>(DC)) |
||
1061 | FD->setWillHaveBody(true); |
||
1062 | else |
||
1063 | assert(isa<ObjCMethodDecl>(DC)); |
||
1064 | } |
||
1065 | |||
1066 | void addContextNote(SourceLocation UseLoc) { |
||
1067 | assert(!PushedCodeSynthesisContext); |
||
1068 | |||
1069 | Sema::CodeSynthesisContext Ctx; |
||
1070 | Ctx.Kind = Sema::CodeSynthesisContext::DefiningSynthesizedFunction; |
||
1071 | Ctx.PointOfInstantiation = UseLoc; |
||
1072 | Ctx.Entity = cast<Decl>(S.CurContext); |
||
1073 | S.pushCodeSynthesisContext(Ctx); |
||
1074 | |||
1075 | PushedCodeSynthesisContext = true; |
||
1076 | } |
||
1077 | |||
1078 | ~SynthesizedFunctionScope() { |
||
1079 | if (PushedCodeSynthesisContext) |
||
1080 | S.popCodeSynthesisContext(); |
||
1081 | if (auto *FD = dyn_cast<FunctionDecl>(S.CurContext)) |
||
1082 | FD->setWillHaveBody(false); |
||
1083 | S.PopExpressionEvaluationContext(); |
||
1084 | S.PopFunctionScopeInfo(); |
||
1085 | } |
||
1086 | }; |
||
1087 | |||
1088 | /// WeakUndeclaredIdentifiers - Identifiers contained in \#pragma weak before |
||
1089 | /// declared. Rare. May alias another identifier, declared or undeclared. |
||
1090 | /// |
||
1091 | /// For aliases, the target identifier is used as a key for eventual |
||
1092 | /// processing when the target is declared. For the single-identifier form, |
||
1093 | /// the sole identifier is used as the key. Each entry is a `SetVector` |
||
1094 | /// (ordered by parse order) of aliases (identified by the alias name) in case |
||
1095 | /// of multiple aliases to the same undeclared identifier. |
||
1096 | llvm::MapVector< |
||
1097 | IdentifierInfo *, |
||
1098 | llvm::SetVector< |
||
1099 | WeakInfo, llvm::SmallVector<WeakInfo, 1u>, |
||
1100 | llvm::SmallDenseSet<WeakInfo, 2u, WeakInfo::DenseMapInfoByAliasOnly>>> |
||
1101 | WeakUndeclaredIdentifiers; |
||
1102 | |||
1103 | /// ExtnameUndeclaredIdentifiers - Identifiers contained in |
||
1104 | /// \#pragma redefine_extname before declared. Used in Solaris system headers |
||
1105 | /// to define functions that occur in multiple standards to call the version |
||
1106 | /// in the currently selected standard. |
||
1107 | llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers; |
||
1108 | |||
1109 | |||
1110 | /// Load weak undeclared identifiers from the external source. |
||
1111 | void LoadExternalWeakUndeclaredIdentifiers(); |
||
1112 | |||
1113 | /// WeakTopLevelDecl - Translation-unit scoped declarations generated by |
||
1114 | /// \#pragma weak during processing of other Decls. |
||
1115 | /// I couldn't figure out a clean way to generate these in-line, so |
||
1116 | /// we store them here and handle separately -- which is a hack. |
||
1117 | /// It would be best to refactor this. |
||
1118 | SmallVector<Decl*,2> WeakTopLevelDecl; |
||
1119 | |||
1120 | IdentifierResolver IdResolver; |
||
1121 | |||
1122 | /// Translation Unit Scope - useful to Objective-C actions that need |
||
1123 | /// to lookup file scope declarations in the "ordinary" C decl namespace. |
||
1124 | /// For example, user-defined classes, built-in "id" type, etc. |
||
1125 | Scope *TUScope; |
||
1126 | |||
1127 | /// The C++ "std" namespace, where the standard library resides. |
||
1128 | LazyDeclPtr StdNamespace; |
||
1129 | |||
1130 | /// The C++ "std::bad_alloc" class, which is defined by the C++ |
||
1131 | /// standard library. |
||
1132 | LazyDeclPtr StdBadAlloc; |
||
1133 | |||
1134 | /// The C++ "std::align_val_t" enum class, which is defined by the C++ |
||
1135 | /// standard library. |
||
1136 | LazyDeclPtr StdAlignValT; |
||
1137 | |||
1138 | /// The C++ "std::experimental" namespace, where the experimental parts |
||
1139 | /// of the standard library resides. |
||
1140 | NamespaceDecl *StdExperimentalNamespaceCache; |
||
1141 | |||
1142 | /// The C++ "std::initializer_list" template, which is defined in |
||
1143 | /// \<initializer_list>. |
||
1144 | ClassTemplateDecl *StdInitializerList; |
||
1145 | |||
1146 | /// The C++ "std::coroutine_traits" template, which is defined in |
||
1147 | /// \<coroutine_traits> |
||
1148 | ClassTemplateDecl *StdCoroutineTraitsCache; |
||
1149 | /// The namespace where coroutine components are defined. In standard, |
||
1150 | /// they are defined in std namespace. And in the previous implementation, |
||
1151 | /// they are defined in std::experimental namespace. |
||
1152 | NamespaceDecl *CoroTraitsNamespaceCache; |
||
1153 | |||
1154 | /// The C++ "type_info" declaration, which is defined in \<typeinfo>. |
||
1155 | RecordDecl *CXXTypeInfoDecl; |
||
1156 | |||
1157 | /// The MSVC "_GUID" struct, which is defined in MSVC header files. |
||
1158 | RecordDecl *MSVCGuidDecl; |
||
1159 | |||
1160 | /// The C++ "std::source_location::__impl" struct, defined in |
||
1161 | /// \<source_location>. |
||
1162 | RecordDecl *StdSourceLocationImplDecl; |
||
1163 | |||
1164 | /// Caches identifiers/selectors for NSFoundation APIs. |
||
1165 | std::unique_ptr<NSAPI> NSAPIObj; |
||
1166 | |||
1167 | /// The declaration of the Objective-C NSNumber class. |
||
1168 | ObjCInterfaceDecl *NSNumberDecl; |
||
1169 | |||
1170 | /// The declaration of the Objective-C NSValue class. |
||
1171 | ObjCInterfaceDecl *NSValueDecl; |
||
1172 | |||
1173 | /// Pointer to NSNumber type (NSNumber *). |
||
1174 | QualType NSNumberPointer; |
||
1175 | |||
1176 | /// Pointer to NSValue type (NSValue *). |
||
1177 | QualType NSValuePointer; |
||
1178 | |||
1179 | /// The Objective-C NSNumber methods used to create NSNumber literals. |
||
1180 | ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]; |
||
1181 | |||
1182 | /// The declaration of the Objective-C NSString class. |
||
1183 | ObjCInterfaceDecl *NSStringDecl; |
||
1184 | |||
1185 | /// Pointer to NSString type (NSString *). |
||
1186 | QualType NSStringPointer; |
||
1187 | |||
1188 | /// The declaration of the stringWithUTF8String: method. |
||
1189 | ObjCMethodDecl *StringWithUTF8StringMethod; |
||
1190 | |||
1191 | /// The declaration of the valueWithBytes:objCType: method. |
||
1192 | ObjCMethodDecl *ValueWithBytesObjCTypeMethod; |
||
1193 | |||
1194 | /// The declaration of the Objective-C NSArray class. |
||
1195 | ObjCInterfaceDecl *NSArrayDecl; |
||
1196 | |||
1197 | /// The declaration of the arrayWithObjects:count: method. |
||
1198 | ObjCMethodDecl *ArrayWithObjectsMethod; |
||
1199 | |||
1200 | /// The declaration of the Objective-C NSDictionary class. |
||
1201 | ObjCInterfaceDecl *NSDictionaryDecl; |
||
1202 | |||
1203 | /// The declaration of the dictionaryWithObjects:forKeys:count: method. |
||
1204 | ObjCMethodDecl *DictionaryWithObjectsMethod; |
||
1205 | |||
1206 | /// id<NSCopying> type. |
||
1207 | QualType QIDNSCopying; |
||
1208 | |||
1209 | /// will hold 'respondsToSelector:' |
||
1210 | Selector RespondsToSelectorSel; |
||
1211 | |||
1212 | /// A flag to remember whether the implicit forms of operator new and delete |
||
1213 | /// have been declared. |
||
1214 | bool GlobalNewDeleteDeclared; |
||
1215 | |||
1216 | /// Describes how the expressions currently being parsed are |
||
1217 | /// evaluated at run-time, if at all. |
||
1218 | enum class ExpressionEvaluationContext { |
||
1219 | /// The current expression and its subexpressions occur within an |
||
1220 | /// unevaluated operand (C++11 [expr]p7), such as the subexpression of |
||
1221 | /// \c sizeof, where the type of the expression may be significant but |
||
1222 | /// no code will be generated to evaluate the value of the expression at |
||
1223 | /// run time. |
||
1224 | Unevaluated, |
||
1225 | |||
1226 | /// The current expression occurs within a braced-init-list within |
||
1227 | /// an unevaluated operand. This is mostly like a regular unevaluated |
||
1228 | /// context, except that we still instantiate constexpr functions that are |
||
1229 | /// referenced here so that we can perform narrowing checks correctly. |
||
1230 | UnevaluatedList, |
||
1231 | |||
1232 | /// The current expression occurs within a discarded statement. |
||
1233 | /// This behaves largely similarly to an unevaluated operand in preventing |
||
1234 | /// definitions from being required, but not in other ways. |
||
1235 | DiscardedStatement, |
||
1236 | |||
1237 | /// The current expression occurs within an unevaluated |
||
1238 | /// operand that unconditionally permits abstract references to |
||
1239 | /// fields, such as a SIZE operator in MS-style inline assembly. |
||
1240 | UnevaluatedAbstract, |
||
1241 | |||
1242 | /// The current context is "potentially evaluated" in C++11 terms, |
||
1243 | /// but the expression is evaluated at compile-time (like the values of |
||
1244 | /// cases in a switch statement). |
||
1245 | ConstantEvaluated, |
||
1246 | |||
1247 | /// In addition of being constant evaluated, the current expression |
||
1248 | /// occurs in an immediate function context - either a consteval function |
||
1249 | /// or a consteval if function. |
||
1250 | ImmediateFunctionContext, |
||
1251 | |||
1252 | /// The current expression is potentially evaluated at run time, |
||
1253 | /// which means that code may be generated to evaluate the value of the |
||
1254 | /// expression at run time. |
||
1255 | PotentiallyEvaluated, |
||
1256 | |||
1257 | /// The current expression is potentially evaluated, but any |
||
1258 | /// declarations referenced inside that expression are only used if |
||
1259 | /// in fact the current expression is used. |
||
1260 | /// |
||
1261 | /// This value is used when parsing default function arguments, for which |
||
1262 | /// we would like to provide diagnostics (e.g., passing non-POD arguments |
||
1263 | /// through varargs) but do not want to mark declarations as "referenced" |
||
1264 | /// until the default argument is used. |
||
1265 | PotentiallyEvaluatedIfUsed |
||
1266 | }; |
||
1267 | |||
1268 | using ImmediateInvocationCandidate = llvm::PointerIntPair<ConstantExpr *, 1>; |
||
1269 | |||
1270 | /// Data structure used to record current or nested |
||
1271 | /// expression evaluation contexts. |
||
1272 | struct ExpressionEvaluationContextRecord { |
||
1273 | /// The expression evaluation context. |
||
1274 | ExpressionEvaluationContext Context; |
||
1275 | |||
1276 | /// Whether the enclosing context needed a cleanup. |
||
1277 | CleanupInfo ParentCleanup; |
||
1278 | |||
1279 | /// The number of active cleanup objects when we entered |
||
1280 | /// this expression evaluation context. |
||
1281 | unsigned NumCleanupObjects; |
||
1282 | |||
1283 | /// The number of typos encountered during this expression evaluation |
||
1284 | /// context (i.e. the number of TypoExprs created). |
||
1285 | unsigned NumTypos; |
||
1286 | |||
1287 | MaybeODRUseExprSet SavedMaybeODRUseExprs; |
||
1288 | |||
1289 | /// The lambdas that are present within this context, if it |
||
1290 | /// is indeed an unevaluated context. |
||
1291 | SmallVector<LambdaExpr *, 2> Lambdas; |
||
1292 | |||
1293 | /// The declaration that provides context for lambda expressions |
||
1294 | /// and block literals if the normal declaration context does not |
||
1295 | /// suffice, e.g., in a default function argument. |
||
1296 | Decl *ManglingContextDecl; |
||
1297 | |||
1298 | /// If we are processing a decltype type, a set of call expressions |
||
1299 | /// for which we have deferred checking the completeness of the return type. |
||
1300 | SmallVector<CallExpr *, 8> DelayedDecltypeCalls; |
||
1301 | |||
1302 | /// If we are processing a decltype type, a set of temporary binding |
||
1303 | /// expressions for which we have deferred checking the destructor. |
||
1304 | SmallVector<CXXBindTemporaryExpr *, 8> DelayedDecltypeBinds; |
||
1305 | |||
1306 | llvm::SmallPtrSet<const Expr *, 8> PossibleDerefs; |
||
1307 | |||
1308 | /// Expressions appearing as the LHS of a volatile assignment in this |
||
1309 | /// context. We produce a warning for these when popping the context if |
||
1310 | /// they are not discarded-value expressions nor unevaluated operands. |
||
1311 | SmallVector<Expr*, 2> VolatileAssignmentLHSs; |
||
1312 | |||
1313 | /// Set of candidates for starting an immediate invocation. |
||
1314 | llvm::SmallVector<ImmediateInvocationCandidate, 4> ImmediateInvocationCandidates; |
||
1315 | |||
1316 | /// Set of DeclRefExprs referencing a consteval function when used in a |
||
1317 | /// context not already known to be immediately invoked. |
||
1318 | llvm::SmallPtrSet<DeclRefExpr *, 4> ReferenceToConsteval; |
||
1319 | |||
1320 | /// \brief Describes whether we are in an expression constext which we have |
||
1321 | /// to handle differently. |
||
1322 | enum ExpressionKind { |
||
1323 | EK_Decltype, EK_TemplateArgument, EK_Other |
||
1324 | } ExprContext; |
||
1325 | |||
1326 | // A context can be nested in both a discarded statement context and |
||
1327 | // an immediate function context, so they need to be tracked independently. |
||
1328 | bool InDiscardedStatement; |
||
1329 | bool InImmediateFunctionContext; |
||
1330 | |||
1331 | bool IsCurrentlyCheckingDefaultArgumentOrInitializer = false; |
||
1332 | |||
1333 | // When evaluating immediate functions in the initializer of a default |
||
1334 | // argument or default member initializer, this is the declaration whose |
||
1335 | // default initializer is being evaluated and the location of the call |
||
1336 | // or constructor definition. |
||
1337 | struct InitializationContext { |
||
1338 | InitializationContext(SourceLocation Loc, ValueDecl *Decl, |
||
1339 | DeclContext *Context) |
||
1340 | : Loc(Loc), Decl(Decl), Context(Context) { |
||
1341 | assert(Decl && Context && "invalid initialization context"); |
||
1342 | } |
||
1343 | |||
1344 | SourceLocation Loc; |
||
1345 | ValueDecl *Decl = nullptr; |
||
1346 | DeclContext *Context = nullptr; |
||
1347 | }; |
||
1348 | std::optional<InitializationContext> DelayedDefaultInitializationContext; |
||
1349 | |||
1350 | ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context, |
||
1351 | unsigned NumCleanupObjects, |
||
1352 | CleanupInfo ParentCleanup, |
||
1353 | Decl *ManglingContextDecl, |
||
1354 | ExpressionKind ExprContext) |
||
1355 | : Context(Context), ParentCleanup(ParentCleanup), |
||
1356 | NumCleanupObjects(NumCleanupObjects), NumTypos(0), |
||
1357 | ManglingContextDecl(ManglingContextDecl), ExprContext(ExprContext), |
||
1358 | InDiscardedStatement(false), InImmediateFunctionContext(false) {} |
||
1359 | |||
1360 | bool isUnevaluated() const { |
||
1361 | return Context == ExpressionEvaluationContext::Unevaluated || |
||
1362 | Context == ExpressionEvaluationContext::UnevaluatedAbstract || |
||
1363 | Context == ExpressionEvaluationContext::UnevaluatedList; |
||
1364 | } |
||
1365 | |||
1366 | bool isConstantEvaluated() const { |
||
1367 | return Context == ExpressionEvaluationContext::ConstantEvaluated || |
||
1368 | Context == ExpressionEvaluationContext::ImmediateFunctionContext; |
||
1369 | } |
||
1370 | |||
1371 | bool isImmediateFunctionContext() const { |
||
1372 | return Context == ExpressionEvaluationContext::ImmediateFunctionContext || |
||
1373 | (Context == ExpressionEvaluationContext::DiscardedStatement && |
||
1374 | InImmediateFunctionContext) || |
||
1375 | // C++2b [expr.const]p14: |
||
1376 | // An expression or conversion is in an immediate function |
||
1377 | // context if it is potentially evaluated and either: |
||
1378 | // * its innermost enclosing non-block scope is a function |
||
1379 | // parameter scope of an immediate function, or |
||
1380 | // * its enclosing statement is enclosed by the compound- |
||
1381 | // statement of a consteval if statement. |
||
1382 | (Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
||
1383 | InImmediateFunctionContext); |
||
1384 | } |
||
1385 | |||
1386 | bool isDiscardedStatementContext() const { |
||
1387 | return Context == ExpressionEvaluationContext::DiscardedStatement || |
||
1388 | (Context == |
||
1389 | ExpressionEvaluationContext::ImmediateFunctionContext && |
||
1390 | InDiscardedStatement); |
||
1391 | } |
||
1392 | }; |
||
1393 | |||
1394 | /// A stack of expression evaluation contexts. |
||
1395 | SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts; |
||
1396 | |||
1397 | // Set of failed immediate invocations to avoid double diagnosing. |
||
1398 | llvm::SmallPtrSet<ConstantExpr *, 4> FailedImmediateInvocations; |
||
1399 | |||
1400 | /// Emit a warning for all pending noderef expressions that we recorded. |
||
1401 | void WarnOnPendingNoDerefs(ExpressionEvaluationContextRecord &Rec); |
||
1402 | |||
1403 | /// Compute the mangling number context for a lambda expression or |
||
1404 | /// block literal. Also return the extra mangling decl if any. |
||
1405 | /// |
||
1406 | /// \param DC - The DeclContext containing the lambda expression or |
||
1407 | /// block literal. |
||
1408 | std::tuple<MangleNumberingContext *, Decl *> |
||
1409 | getCurrentMangleNumberContext(const DeclContext *DC); |
||
1410 | |||
1411 | |||
1412 | /// SpecialMemberOverloadResult - The overloading result for a special member |
||
1413 | /// function. |
||
1414 | /// |
||
1415 | /// This is basically a wrapper around PointerIntPair. The lowest bits of the |
||
1416 | /// integer are used to determine whether overload resolution succeeded. |
||
1417 | class SpecialMemberOverloadResult { |
||
1418 | public: |
||
1419 | enum Kind { |
||
1420 | NoMemberOrDeleted, |
||
1421 | Ambiguous, |
||
1422 | Success |
||
1423 | }; |
||
1424 | |||
1425 | private: |
||
1426 | llvm::PointerIntPair<CXXMethodDecl *, 2> Pair; |
||
1427 | |||
1428 | public: |
||
1429 | SpecialMemberOverloadResult() {} |
||
1430 | SpecialMemberOverloadResult(CXXMethodDecl *MD) |
||
1431 | : Pair(MD, MD->isDeleted() ? NoMemberOrDeleted : Success) {} |
||
1432 | |||
1433 | CXXMethodDecl *getMethod() const { return Pair.getPointer(); } |
||
1434 | void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); } |
||
1435 | |||
1436 | Kind getKind() const { return static_cast<Kind>(Pair.getInt()); } |
||
1437 | void setKind(Kind K) { Pair.setInt(K); } |
||
1438 | }; |
||
1439 | |||
1440 | class SpecialMemberOverloadResultEntry |
||
1441 | : public llvm::FastFoldingSetNode, |
||
1442 | public SpecialMemberOverloadResult { |
||
1443 | public: |
||
1444 | SpecialMemberOverloadResultEntry(const llvm::FoldingSetNodeID &ID) |
||
1445 | : FastFoldingSetNode(ID) |
||
1446 | {} |
||
1447 | }; |
||
1448 | |||
1449 | /// A cache of special member function overload resolution results |
||
1450 | /// for C++ records. |
||
1451 | llvm::FoldingSet<SpecialMemberOverloadResultEntry> SpecialMemberCache; |
||
1452 | |||
1453 | /// A cache of the flags available in enumerations with the flag_bits |
||
1454 | /// attribute. |
||
1455 | mutable llvm::DenseMap<const EnumDecl*, llvm::APInt> FlagBitsCache; |
||
1456 | |||
1457 | /// The kind of translation unit we are processing. |
||
1458 | /// |
||
1459 | /// When we're processing a complete translation unit, Sema will perform |
||
1460 | /// end-of-translation-unit semantic tasks (such as creating |
||
1461 | /// initializers for tentative definitions in C) once parsing has |
||
1462 | /// completed. Modules and precompiled headers perform different kinds of |
||
1463 | /// checks. |
||
1464 | const TranslationUnitKind TUKind; |
||
1465 | |||
1466 | llvm::BumpPtrAllocator BumpAlloc; |
||
1467 | |||
1468 | /// The number of SFINAE diagnostics that have been trapped. |
||
1469 | unsigned NumSFINAEErrors; |
||
1470 | |||
1471 | typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>> |
||
1472 | UnparsedDefaultArgInstantiationsMap; |
||
1473 | |||
1474 | /// A mapping from parameters with unparsed default arguments to the |
||
1475 | /// set of instantiations of each parameter. |
||
1476 | /// |
||
1477 | /// This mapping is a temporary data structure used when parsing |
||
1478 | /// nested class templates or nested classes of class templates, |
||
1479 | /// where we might end up instantiating an inner class before the |
||
1480 | /// default arguments of its methods have been parsed. |
||
1481 | UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations; |
||
1482 | |||
1483 | // Contains the locations of the beginning of unparsed default |
||
1484 | // argument locations. |
||
1485 | llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs; |
||
1486 | |||
1487 | /// UndefinedInternals - all the used, undefined objects which require a |
||
1488 | /// definition in this translation unit. |
||
1489 | llvm::MapVector<NamedDecl *, SourceLocation> UndefinedButUsed; |
||
1490 | |||
1491 | /// Determine if VD, which must be a variable or function, is an external |
||
1492 | /// symbol that nonetheless can't be referenced from outside this translation |
||
1493 | /// unit because its type has no linkage and it's not extern "C". |
||
1494 | bool isExternalWithNoLinkageType(ValueDecl *VD); |
||
1495 | |||
1496 | /// Obtain a sorted list of functions that are undefined but ODR-used. |
||
1497 | void getUndefinedButUsed( |
||
1498 | SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined); |
||
1499 | |||
1500 | /// Retrieves list of suspicious delete-expressions that will be checked at |
||
1501 | /// the end of translation unit. |
||
1502 | const llvm::MapVector<FieldDecl *, DeleteLocs> & |
||
1503 | getMismatchingDeleteExpressions() const; |
||
1504 | |||
1505 | class GlobalMethodPool { |
||
1506 | public: |
||
1507 | using Lists = std::pair<ObjCMethodList, ObjCMethodList>; |
||
1508 | using iterator = llvm::DenseMap<Selector, Lists>::iterator; |
||
1509 | iterator begin() { return Methods.begin(); } |
||
1510 | iterator end() { return Methods.end(); } |
||
1511 | iterator find(Selector Sel) { return Methods.find(Sel); } |
||
1512 | std::pair<iterator, bool> insert(std::pair<Selector, Lists> &&Val) { |
||
1513 | return Methods.insert(Val); |
||
1514 | } |
||
1515 | int count(Selector Sel) const { return Methods.count(Sel); } |
||
1516 | bool empty() const { return Methods.empty(); } |
||
1517 | |||
1518 | private: |
||
1519 | llvm::DenseMap<Selector, Lists> Methods; |
||
1520 | }; |
||
1521 | |||
1522 | /// Method Pool - allows efficient lookup when typechecking messages to "id". |
||
1523 | /// We need to maintain a list, since selectors can have differing signatures |
||
1524 | /// across classes. In Cocoa, this happens to be extremely uncommon (only 1% |
||
1525 | /// of selectors are "overloaded"). |
||
1526 | /// At the head of the list it is recorded whether there were 0, 1, or >= 2 |
||
1527 | /// methods inside categories with a particular selector. |
||
1528 | GlobalMethodPool MethodPool; |
||
1529 | |||
1530 | /// Method selectors used in a \@selector expression. Used for implementation |
||
1531 | /// of -Wselector. |
||
1532 | llvm::MapVector<Selector, SourceLocation> ReferencedSelectors; |
||
1533 | |||
1534 | /// List of SourceLocations where 'self' is implicitly retained inside a |
||
1535 | /// block. |
||
1536 | llvm::SmallVector<std::pair<SourceLocation, const BlockDecl *>, 1> |
||
1537 | ImplicitlyRetainedSelfLocs; |
||
1538 | |||
1539 | /// Kinds of C++ special members. |
||
1540 | enum CXXSpecialMember { |
||
1541 | CXXDefaultConstructor, |
||
1542 | CXXCopyConstructor, |
||
1543 | CXXMoveConstructor, |
||
1544 | CXXCopyAssignment, |
||
1545 | CXXMoveAssignment, |
||
1546 | CXXDestructor, |
||
1547 | CXXInvalid |
||
1548 | }; |
||
1549 | |||
1550 | typedef llvm::PointerIntPair<CXXRecordDecl *, 3, CXXSpecialMember> |
||
1551 | SpecialMemberDecl; |
||
1552 | |||
1553 | /// The C++ special members which we are currently in the process of |
||
1554 | /// declaring. If this process recursively triggers the declaration of the |
||
1555 | /// same special member, we should act as if it is not yet declared. |
||
1556 | llvm::SmallPtrSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared; |
||
1557 | |||
1558 | /// Kinds of defaulted comparison operator functions. |
||
1559 | enum class DefaultedComparisonKind : unsigned char { |
||
1560 | /// This is not a defaultable comparison operator. |
||
1561 | None, |
||
1562 | /// This is an operator== that should be implemented as a series of |
||
1563 | /// subobject comparisons. |
||
1564 | Equal, |
||
1565 | /// This is an operator<=> that should be implemented as a series of |
||
1566 | /// subobject comparisons. |
||
1567 | ThreeWay, |
||
1568 | /// This is an operator!= that should be implemented as a rewrite in terms |
||
1569 | /// of a == comparison. |
||
1570 | NotEqual, |
||
1571 | /// This is an <, <=, >, or >= that should be implemented as a rewrite in |
||
1572 | /// terms of a <=> comparison. |
||
1573 | Relational, |
||
1574 | }; |
||
1575 | |||
1576 | /// The function definitions which were renamed as part of typo-correction |
||
1577 | /// to match their respective declarations. We want to keep track of them |
||
1578 | /// to ensure that we don't emit a "redefinition" error if we encounter a |
||
1579 | /// correctly named definition after the renamed definition. |
||
1580 | llvm::SmallPtrSet<const NamedDecl *, 4> TypoCorrectedFunctionDefinitions; |
||
1581 | |||
1582 | /// Stack of types that correspond to the parameter entities that are |
||
1583 | /// currently being copy-initialized. Can be empty. |
||
1584 | llvm::SmallVector<QualType, 4> CurrentParameterCopyTypes; |
||
1585 | |||
1586 | void ReadMethodPool(Selector Sel); |
||
1587 | void updateOutOfDateSelector(Selector Sel); |
||
1588 | |||
1589 | /// Private Helper predicate to check for 'self'. |
||
1590 | bool isSelfExpr(Expr *RExpr); |
||
1591 | bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method); |
||
1592 | |||
1593 | /// Cause the active diagnostic on the DiagosticsEngine to be |
||
1594 | /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and |
||
1595 | /// should not be used elsewhere. |
||
1596 | void EmitCurrentDiagnostic(unsigned DiagID); |
||
1597 | |||
1598 | /// Records and restores the CurFPFeatures state on entry/exit of compound |
||
1599 | /// statements. |
||
1600 | class FPFeaturesStateRAII { |
||
1601 | public: |
||
1602 | FPFeaturesStateRAII(Sema &S); |
||
1603 | ~FPFeaturesStateRAII(); |
||
1604 | FPOptionsOverride getOverrides() { return OldOverrides; } |
||
1605 | |||
1606 | private: |
||
1607 | Sema& S; |
||
1608 | FPOptions OldFPFeaturesState; |
||
1609 | FPOptionsOverride OldOverrides; |
||
1610 | LangOptions::FPEvalMethodKind OldEvalMethod; |
||
1611 | SourceLocation OldFPPragmaLocation; |
||
1612 | }; |
||
1613 | |||
1614 | void addImplicitTypedef(StringRef Name, QualType T); |
||
1615 | |||
1616 | bool WarnedStackExhausted = false; |
||
1617 | |||
1618 | /// Increment when we find a reference; decrement when we find an ignored |
||
1619 | /// assignment. Ultimately the value is 0 if every reference is an ignored |
||
1620 | /// assignment. |
||
1621 | llvm::DenseMap<const VarDecl *, int> RefsMinusAssignments; |
||
1622 | |||
1623 | /// Indicate RISC-V vector builtin functions enabled or not. |
||
1624 | bool DeclareRISCVVBuiltins = false; |
||
1625 | |||
1626 | private: |
||
1627 | std::unique_ptr<sema::RISCVIntrinsicManager> RVIntrinsicManager; |
||
1628 | |||
1629 | std::optional<std::unique_ptr<DarwinSDKInfo>> CachedDarwinSDKInfo; |
||
1630 | |||
1631 | bool WarnedDarwinSDKInfoMissing = false; |
||
1632 | |||
1633 | public: |
||
1634 | Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, |
||
1635 | TranslationUnitKind TUKind = TU_Complete, |
||
1636 | CodeCompleteConsumer *CompletionConsumer = nullptr); |
||
1637 | ~Sema(); |
||
1638 | |||
1639 | /// Perform initialization that occurs after the parser has been |
||
1640 | /// initialized but before it parses anything. |
||
1641 | void Initialize(); |
||
1642 | |||
1643 | /// This virtual key function only exists to limit the emission of debug info |
||
1644 | /// describing the Sema class. GCC and Clang only emit debug info for a class |
||
1645 | /// with a vtable when the vtable is emitted. Sema is final and not |
||
1646 | /// polymorphic, but the debug info size savings are so significant that it is |
||
1647 | /// worth adding a vtable just to take advantage of this optimization. |
||
1648 | virtual void anchor(); |
||
1649 | |||
1650 | const LangOptions &getLangOpts() const { return LangOpts; } |
||
1651 | OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; } |
||
1652 | FPOptions &getCurFPFeatures() { return CurFPFeatures; } |
||
1653 | |||
1654 | DiagnosticsEngine &getDiagnostics() const { return Diags; } |
||
1655 | SourceManager &getSourceManager() const { return SourceMgr; } |
||
1656 | Preprocessor &getPreprocessor() const { return PP; } |
||
1657 | ASTContext &getASTContext() const { return Context; } |
||
1658 | ASTConsumer &getASTConsumer() const { return Consumer; } |
||
1659 | ASTMutationListener *getASTMutationListener() const; |
||
1660 | ExternalSemaSource *getExternalSource() const { return ExternalSource.get(); } |
||
1661 | |||
1662 | DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(SourceLocation Loc, |
||
1663 | StringRef Platform); |
||
1664 | DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(); |
||
1665 | |||
1666 | ///Registers an external source. If an external source already exists, |
||
1667 | /// creates a multiplex external source and appends to it. |
||
1668 | /// |
||
1669 | ///\param[in] E - A non-null external sema source. |
||
1670 | /// |
||
1671 | void addExternalSource(ExternalSemaSource *E); |
||
1672 | |||
1673 | void PrintStats() const; |
||
1674 | |||
1675 | /// Warn that the stack is nearly exhausted. |
||
1676 | void warnStackExhausted(SourceLocation Loc); |
||
1677 | |||
1678 | /// Run some code with "sufficient" stack space. (Currently, at least 256K is |
||
1679 | /// guaranteed). Produces a warning if we're low on stack space and allocates |
||
1680 | /// more in that case. Use this in code that may recurse deeply (for example, |
||
1681 | /// in template instantiation) to avoid stack overflow. |
||
1682 | void runWithSufficientStackSpace(SourceLocation Loc, |
||
1683 | llvm::function_ref<void()> Fn); |
||
1684 | |||
1685 | /// Helper class that creates diagnostics with optional |
||
1686 | /// template instantiation stacks. |
||
1687 | /// |
||
1688 | /// This class provides a wrapper around the basic DiagnosticBuilder |
||
1689 | /// class that emits diagnostics. ImmediateDiagBuilder is |
||
1690 | /// responsible for emitting the diagnostic (as DiagnosticBuilder |
||
1691 | /// does) and, if the diagnostic comes from inside a template |
||
1692 | /// instantiation, printing the template instantiation stack as |
||
1693 | /// well. |
||
1694 | class ImmediateDiagBuilder : public DiagnosticBuilder { |
||
1695 | Sema &SemaRef; |
||
1696 | unsigned DiagID; |
||
1697 | |||
1698 | public: |
||
1699 | ImmediateDiagBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID) |
||
1700 | : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) {} |
||
1701 | ImmediateDiagBuilder(DiagnosticBuilder &&DB, Sema &SemaRef, unsigned DiagID) |
||
1702 | : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) {} |
||
1703 | |||
1704 | // This is a cunning lie. DiagnosticBuilder actually performs move |
||
1705 | // construction in its copy constructor (but due to varied uses, it's not |
||
1706 | // possible to conveniently express this as actual move construction). So |
||
1707 | // the default copy ctor here is fine, because the base class disables the |
||
1708 | // source anyway, so the user-defined ~ImmediateDiagBuilder is a safe no-op |
||
1709 | // in that case anwyay. |
||
1710 | ImmediateDiagBuilder(const ImmediateDiagBuilder &) = default; |
||
1711 | |||
1712 | ~ImmediateDiagBuilder() { |
||
1713 | // If we aren't active, there is nothing to do. |
||
1714 | if (!isActive()) return; |
||
1715 | |||
1716 | // Otherwise, we need to emit the diagnostic. First clear the diagnostic |
||
1717 | // builder itself so it won't emit the diagnostic in its own destructor. |
||
1718 | // |
||
1719 | // This seems wasteful, in that as written the DiagnosticBuilder dtor will |
||
1720 | // do its own needless checks to see if the diagnostic needs to be |
||
1721 | // emitted. However, because we take care to ensure that the builder |
||
1722 | // objects never escape, a sufficiently smart compiler will be able to |
||
1723 | // eliminate that code. |
||
1724 | Clear(); |
||
1725 | |||
1726 | // Dispatch to Sema to emit the diagnostic. |
||
1727 | SemaRef.EmitCurrentDiagnostic(DiagID); |
||
1728 | } |
||
1729 | |||
1730 | /// Teach operator<< to produce an object of the correct type. |
||
1731 | template <typename T> |
||
1732 | friend const ImmediateDiagBuilder & |
||
1733 | operator<<(const ImmediateDiagBuilder &Diag, const T &Value) { |
||
1734 | const DiagnosticBuilder &BaseDiag = Diag; |
||
1735 | BaseDiag << Value; |
||
1736 | return Diag; |
||
1737 | } |
||
1738 | |||
1739 | // It is necessary to limit this to rvalue reference to avoid calling this |
||
1740 | // function with a bitfield lvalue argument since non-const reference to |
||
1741 | // bitfield is not allowed. |
||
1742 | template <typename T, |
||
1743 | typename = std::enable_if_t<!std::is_lvalue_reference<T>::value>> |
||
1744 | const ImmediateDiagBuilder &operator<<(T &&V) const { |
||
1745 | const DiagnosticBuilder &BaseDiag = *this; |
||
1746 | BaseDiag << std::move(V); |
||
1747 | return *this; |
||
1748 | } |
||
1749 | }; |
||
1750 | |||
1751 | /// A generic diagnostic builder for errors which may or may not be deferred. |
||
1752 | /// |
||
1753 | /// In CUDA, there exist constructs (e.g. variable-length arrays, try/catch) |
||
1754 | /// which are not allowed to appear inside __device__ functions and are |
||
1755 | /// allowed to appear in __host__ __device__ functions only if the host+device |
||
1756 | /// function is never codegen'ed. |
||
1757 | /// |
||
1758 | /// To handle this, we use the notion of "deferred diagnostics", where we |
||
1759 | /// attach a diagnostic to a FunctionDecl that's emitted iff it's codegen'ed. |
||
1760 | /// |
||
1761 | /// This class lets you emit either a regular diagnostic, a deferred |
||
1762 | /// diagnostic, or no diagnostic at all, according to an argument you pass to |
||
1763 | /// its constructor, thus simplifying the process of creating these "maybe |
||
1764 | /// deferred" diagnostics. |
||
1765 | class SemaDiagnosticBuilder { |
||
1766 | public: |
||
1767 | enum Kind { |
||
1768 | /// Emit no diagnostics. |
||
1769 | K_Nop, |
||
1770 | /// Emit the diagnostic immediately (i.e., behave like Sema::Diag()). |
||
1771 | K_Immediate, |
||
1772 | /// Emit the diagnostic immediately, and, if it's a warning or error, also |
||
1773 | /// emit a call stack showing how this function can be reached by an a |
||
1774 | /// priori known-emitted function. |
||
1775 | K_ImmediateWithCallStack, |
||
1776 | /// Create a deferred diagnostic, which is emitted only if the function |
||
1777 | /// it's attached to is codegen'ed. Also emit a call stack as with |
||
1778 | /// K_ImmediateWithCallStack. |
||
1779 | K_Deferred |
||
1780 | }; |
||
1781 | |||
1782 | SemaDiagnosticBuilder(Kind K, SourceLocation Loc, unsigned DiagID, |
||
1783 | FunctionDecl *Fn, Sema &S); |
||
1784 | SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D); |
||
1785 | SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default; |
||
1786 | ~SemaDiagnosticBuilder(); |
||
1787 | |||
1788 | bool isImmediate() const { return ImmediateDiag.has_value(); } |
||
1789 | |||
1790 | /// Convertible to bool: True if we immediately emitted an error, false if |
||
1791 | /// we didn't emit an error or we created a deferred error. |
||
1792 | /// |
||
1793 | /// Example usage: |
||
1794 | /// |
||
1795 | /// if (SemaDiagnosticBuilder(...) << foo << bar) |
||
1796 | /// return ExprError(); |
||
1797 | /// |
||
1798 | /// But see CUDADiagIfDeviceCode() and CUDADiagIfHostCode() -- you probably |
||
1799 | /// want to use these instead of creating a SemaDiagnosticBuilder yourself. |
||
1800 | operator bool() const { return isImmediate(); } |
||
1801 | |||
1802 | template <typename T> |
||
1803 | friend const SemaDiagnosticBuilder & |
||
1804 | operator<<(const SemaDiagnosticBuilder &Diag, const T &Value) { |
||
1805 | if (Diag.ImmediateDiag) |
||
1806 | *Diag.ImmediateDiag << Value; |
||
1807 | else if (Diag.PartialDiagId) |
||
1808 | Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second |
||
1809 | << Value; |
||
1810 | return Diag; |
||
1811 | } |
||
1812 | |||
1813 | // It is necessary to limit this to rvalue reference to avoid calling this |
||
1814 | // function with a bitfield lvalue argument since non-const reference to |
||
1815 | // bitfield is not allowed. |
||
1816 | template <typename T, |
||
1817 | typename = std::enable_if_t<!std::is_lvalue_reference<T>::value>> |
||
1818 | const SemaDiagnosticBuilder &operator<<(T &&V) const { |
||
1819 | if (ImmediateDiag) |
||
1820 | *ImmediateDiag << std::move(V); |
||
1821 | else if (PartialDiagId) |
||
1822 | S.DeviceDeferredDiags[Fn][*PartialDiagId].second << std::move(V); |
||
1823 | return *this; |
||
1824 | } |
||
1825 | |||
1826 | friend const SemaDiagnosticBuilder & |
||
1827 | operator<<(const SemaDiagnosticBuilder &Diag, const PartialDiagnostic &PD) { |
||
1828 | if (Diag.ImmediateDiag) |
||
1829 | PD.Emit(*Diag.ImmediateDiag); |
||
1830 | else if (Diag.PartialDiagId) |
||
1831 | Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second = PD; |
||
1832 | return Diag; |
||
1833 | } |
||
1834 | |||
1835 | void AddFixItHint(const FixItHint &Hint) const { |
||
1836 | if (ImmediateDiag) |
||
1837 | ImmediateDiag->AddFixItHint(Hint); |
||
1838 | else if (PartialDiagId) |
||
1839 | S.DeviceDeferredDiags[Fn][*PartialDiagId].second.AddFixItHint(Hint); |
||
1840 | } |
||
1841 | |||
1842 | friend ExprResult ExprError(const SemaDiagnosticBuilder &) { |
||
1843 | return ExprError(); |
||
1844 | } |
||
1845 | friend StmtResult StmtError(const SemaDiagnosticBuilder &) { |
||
1846 | return StmtError(); |
||
1847 | } |
||
1848 | operator ExprResult() const { return ExprError(); } |
||
1849 | operator StmtResult() const { return StmtError(); } |
||
1850 | operator TypeResult() const { return TypeError(); } |
||
1851 | operator DeclResult() const { return DeclResult(true); } |
||
1852 | operator MemInitResult() const { return MemInitResult(true); } |
||
1853 | |||
1854 | private: |
||
1855 | Sema &S; |
||
1856 | SourceLocation Loc; |
||
1857 | unsigned DiagID; |
||
1858 | FunctionDecl *Fn; |
||
1859 | bool ShowCallStack; |
||
1860 | |||
1861 | // Invariant: At most one of these Optionals has a value. |
||
1862 | // FIXME: Switch these to a Variant once that exists. |
||
1863 | std::optional<ImmediateDiagBuilder> ImmediateDiag; |
||
1864 | std::optional<unsigned> PartialDiagId; |
||
1865 | }; |
||
1866 | |||
1867 | /// Is the last error level diagnostic immediate. This is used to determined |
||
1868 | /// whether the next info diagnostic should be immediate. |
||
1869 | bool IsLastErrorImmediate = true; |
||
1870 | |||
1871 | /// Emit a diagnostic. |
||
1872 | SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, |
||
1873 | bool DeferHint = false); |
||
1874 | |||
1875 | /// Emit a partial diagnostic. |
||
1876 | SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD, |
||
1877 | bool DeferHint = false); |
||
1878 | |||
1879 | /// Build a partial diagnostic. |
||
1880 | PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h |
||
1881 | |||
1882 | /// Whether deferrable diagnostics should be deferred. |
||
1883 | bool DeferDiags = false; |
||
1884 | |||
1885 | /// RAII class to control scope of DeferDiags. |
||
1886 | class DeferDiagsRAII { |
||
1887 | Sema &S; |
||
1888 | bool SavedDeferDiags = false; |
||
1889 | |||
1890 | public: |
||
1891 | DeferDiagsRAII(Sema &S, bool DeferDiags) |
||
1892 | : S(S), SavedDeferDiags(S.DeferDiags) { |
||
1893 | S.DeferDiags = DeferDiags; |
||
1894 | } |
||
1895 | ~DeferDiagsRAII() { S.DeferDiags = SavedDeferDiags; } |
||
1896 | }; |
||
1897 | |||
1898 | /// Whether uncompilable error has occurred. This includes error happens |
||
1899 | /// in deferred diagnostics. |
||
1900 | bool hasUncompilableErrorOccurred() const; |
||
1901 | |||
1902 | bool findMacroSpelling(SourceLocation &loc, StringRef name); |
||
1903 | |||
1904 | /// Get a string to suggest for zero-initialization of a type. |
||
1905 | std::string |
||
1906 | getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const; |
||
1907 | std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const; |
||
1908 | |||
1909 | /// Calls \c Lexer::getLocForEndOfToken() |
||
1910 | SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0); |
||
1911 | |||
1912 | /// Retrieve the module loader associated with the preprocessor. |
||
1913 | ModuleLoader &getModuleLoader() const; |
||
1914 | |||
1915 | /// Invent a new identifier for parameters of abbreviated templates. |
||
1916 | IdentifierInfo * |
||
1917 | InventAbbreviatedTemplateParameterTypeName(IdentifierInfo *ParamName, |
||
1918 | unsigned Index); |
||
1919 | |||
1920 | void emitAndClearUnusedLocalTypedefWarnings(); |
||
1921 | |||
1922 | private: |
||
1923 | /// Function or variable declarations to be checked for whether the deferred |
||
1924 | /// diagnostics should be emitted. |
||
1925 | llvm::SmallSetVector<Decl *, 4> DeclsToCheckForDeferredDiags; |
||
1926 | |||
1927 | public: |
||
1928 | // Emit all deferred diagnostics. |
||
1929 | void emitDeferredDiags(); |
||
1930 | |||
1931 | enum TUFragmentKind { |
||
1932 | /// The global module fragment, between 'module;' and a module-declaration. |
||
1933 | Global, |
||
1934 | /// A normal translation unit fragment. For a non-module unit, this is the |
||
1935 | /// entire translation unit. Otherwise, it runs from the module-declaration |
||
1936 | /// to the private-module-fragment (if any) or the end of the TU (if not). |
||
1937 | Normal, |
||
1938 | /// The private module fragment, between 'module :private;' and the end of |
||
1939 | /// the translation unit. |
||
1940 | Private |
||
1941 | }; |
||
1942 | |||
1943 | void ActOnStartOfTranslationUnit(); |
||
1944 | void ActOnEndOfTranslationUnit(); |
||
1945 | void ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind); |
||
1946 | |||
1947 | void CheckDelegatingCtorCycles(); |
||
1948 | |||
1949 | Scope *getScopeForContext(DeclContext *Ctx); |
||
1950 | |||
1951 | void PushFunctionScope(); |
||
1952 | void PushBlockScope(Scope *BlockScope, BlockDecl *Block); |
||
1953 | sema::LambdaScopeInfo *PushLambdaScope(); |
||
1954 | |||
1955 | /// This is used to inform Sema what the current TemplateParameterDepth |
||
1956 | /// is during Parsing. Currently it is used to pass on the depth |
||
1957 | /// when parsing generic lambda 'auto' parameters. |
||
1958 | void RecordParsingTemplateParameterDepth(unsigned Depth); |
||
1959 | |||
1960 | void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD, |
||
1961 | RecordDecl *RD, CapturedRegionKind K, |
||
1962 | unsigned OpenMPCaptureLevel = 0); |
||
1963 | |||
1964 | /// Custom deleter to allow FunctionScopeInfos to be kept alive for a short |
||
1965 | /// time after they've been popped. |
||
1966 | class PoppedFunctionScopeDeleter { |
||
1967 | Sema *Self; |
||
1968 | |||
1969 | public: |
||
1970 | explicit PoppedFunctionScopeDeleter(Sema *Self) : Self(Self) {} |
||
1971 | void operator()(sema::FunctionScopeInfo *Scope) const; |
||
1972 | }; |
||
1973 | |||
1974 | using PoppedFunctionScopePtr = |
||
1975 | std::unique_ptr<sema::FunctionScopeInfo, PoppedFunctionScopeDeleter>; |
||
1976 | |||
1977 | PoppedFunctionScopePtr |
||
1978 | PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr, |
||
1979 | const Decl *D = nullptr, |
||
1980 | QualType BlockType = QualType()); |
||
1981 | |||
1982 | sema::FunctionScopeInfo *getCurFunction() const { |
||
1983 | return FunctionScopes.empty() ? nullptr : FunctionScopes.back(); |
||
1984 | } |
||
1985 | |||
1986 | sema::FunctionScopeInfo *getEnclosingFunction() const; |
||
1987 | |||
1988 | void setFunctionHasBranchIntoScope(); |
||
1989 | void setFunctionHasBranchProtectedScope(); |
||
1990 | void setFunctionHasIndirectGoto(); |
||
1991 | void setFunctionHasMustTail(); |
||
1992 | |||
1993 | void PushCompoundScope(bool IsStmtExpr); |
||
1994 | void PopCompoundScope(); |
||
1995 | |||
1996 | sema::CompoundScopeInfo &getCurCompoundScope() const; |
||
1997 | |||
1998 | bool hasAnyUnrecoverableErrorsInThisFunction() const; |
||
1999 | |||
2000 | /// Retrieve the current block, if any. |
||
2001 | sema::BlockScopeInfo *getCurBlock(); |
||
2002 | |||
2003 | /// Get the innermost lambda enclosing the current location, if any. This |
||
2004 | /// looks through intervening non-lambda scopes such as local functions and |
||
2005 | /// blocks. |
||
2006 | sema::LambdaScopeInfo *getEnclosingLambda() const; |
||
2007 | |||
2008 | /// Retrieve the current lambda scope info, if any. |
||
2009 | /// \param IgnoreNonLambdaCapturingScope true if should find the top-most |
||
2010 | /// lambda scope info ignoring all inner capturing scopes that are not |
||
2011 | /// lambda scopes. |
||
2012 | sema::LambdaScopeInfo * |
||
2013 | getCurLambda(bool IgnoreNonLambdaCapturingScope = false); |
||
2014 | |||
2015 | /// Retrieve the current generic lambda info, if any. |
||
2016 | sema::LambdaScopeInfo *getCurGenericLambda(); |
||
2017 | |||
2018 | /// Retrieve the current captured region, if any. |
||
2019 | sema::CapturedRegionScopeInfo *getCurCapturedRegion(); |
||
2020 | |||
2021 | /// Retrieve the current function, if any, that should be analyzed for |
||
2022 | /// potential availability violations. |
||
2023 | sema::FunctionScopeInfo *getCurFunctionAvailabilityContext(); |
||
2024 | |||
2025 | /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls |
||
2026 | SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; } |
||
2027 | |||
2028 | /// Called before parsing a function declarator belonging to a function |
||
2029 | /// declaration. |
||
2030 | void ActOnStartFunctionDeclarationDeclarator(Declarator &D, |
||
2031 | unsigned TemplateParameterDepth); |
||
2032 | |||
2033 | /// Called after parsing a function declarator belonging to a function |
||
2034 | /// declaration. |
||
2035 | void ActOnFinishFunctionDeclarationDeclarator(Declarator &D); |
||
2036 | |||
2037 | void ActOnComment(SourceRange Comment); |
||
2038 | |||
2039 | //===--------------------------------------------------------------------===// |
||
2040 | // Type Analysis / Processing: SemaType.cpp. |
||
2041 | // |
||
2042 | |||
2043 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, |
||
2044 | const DeclSpec *DS = nullptr); |
||
2045 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA, |
||
2046 | const DeclSpec *DS = nullptr); |
||
2047 | QualType BuildPointerType(QualType T, |
||
2048 | SourceLocation Loc, DeclarationName Entity); |
||
2049 | QualType BuildReferenceType(QualType T, bool LValueRef, |
||
2050 | SourceLocation Loc, DeclarationName Entity); |
||
2051 | QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, |
||
2052 | Expr *ArraySize, unsigned Quals, |
||
2053 | SourceRange Brackets, DeclarationName Entity); |
||
2054 | QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc); |
||
2055 | QualType BuildExtVectorType(QualType T, Expr *ArraySize, |
||
2056 | SourceLocation AttrLoc); |
||
2057 | QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, |
||
2058 | SourceLocation AttrLoc); |
||
2059 | |||
2060 | QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace, |
||
2061 | SourceLocation AttrLoc); |
||
2062 | |||
2063 | /// Same as above, but constructs the AddressSpace index if not provided. |
||
2064 | QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace, |
||
2065 | SourceLocation AttrLoc); |
||
2066 | |||
2067 | bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc); |
||
2068 | |||
2069 | bool CheckFunctionReturnType(QualType T, SourceLocation Loc); |
||
2070 | |||
2071 | /// Build a function type. |
||
2072 | /// |
||
2073 | /// This routine checks the function type according to C++ rules and |
||
2074 | /// under the assumption that the result type and parameter types have |
||
2075 | /// just been instantiated from a template. It therefore duplicates |
||
2076 | /// some of the behavior of GetTypeForDeclarator, but in a much |
||
2077 | /// simpler form that is only suitable for this narrow use case. |
||
2078 | /// |
||
2079 | /// \param T The return type of the function. |
||
2080 | /// |
||
2081 | /// \param ParamTypes The parameter types of the function. This array |
||
2082 | /// will be modified to account for adjustments to the types of the |
||
2083 | /// function parameters. |
||
2084 | /// |
||
2085 | /// \param Loc The location of the entity whose type involves this |
||
2086 | /// function type or, if there is no such entity, the location of the |
||
2087 | /// type that will have function type. |
||
2088 | /// |
||
2089 | /// \param Entity The name of the entity that involves the function |
||
2090 | /// type, if known. |
||
2091 | /// |
||
2092 | /// \param EPI Extra information about the function type. Usually this will |
||
2093 | /// be taken from an existing function with the same prototype. |
||
2094 | /// |
||
2095 | /// \returns A suitable function type, if there are no errors. The |
||
2096 | /// unqualified type will always be a FunctionProtoType. |
||
2097 | /// Otherwise, returns a NULL type. |
||
2098 | QualType BuildFunctionType(QualType T, |
||
2099 | MutableArrayRef<QualType> ParamTypes, |
||
2100 | SourceLocation Loc, DeclarationName Entity, |
||
2101 | const FunctionProtoType::ExtProtoInfo &EPI); |
||
2102 | |||
2103 | QualType BuildMemberPointerType(QualType T, QualType Class, |
||
2104 | SourceLocation Loc, |
||
2105 | DeclarationName Entity); |
||
2106 | QualType BuildBlockPointerType(QualType T, |
||
2107 | SourceLocation Loc, DeclarationName Entity); |
||
2108 | QualType BuildParenType(QualType T); |
||
2109 | QualType BuildAtomicType(QualType T, SourceLocation Loc); |
||
2110 | QualType BuildReadPipeType(QualType T, |
||
2111 | SourceLocation Loc); |
||
2112 | QualType BuildWritePipeType(QualType T, |
||
2113 | SourceLocation Loc); |
||
2114 | QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc); |
||
2115 | |||
2116 | TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S); |
||
2117 | TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy); |
||
2118 | |||
2119 | /// Package the given type and TSI into a ParsedType. |
||
2120 | ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo); |
||
2121 | DeclarationNameInfo GetNameForDeclarator(Declarator &D); |
||
2122 | DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name); |
||
2123 | static QualType GetTypeFromParser(ParsedType Ty, |
||
2124 | TypeSourceInfo **TInfo = nullptr); |
||
2125 | CanThrowResult canThrow(const Stmt *E); |
||
2126 | /// Determine whether the callee of a particular function call can throw. |
||
2127 | /// E, D and Loc are all optional. |
||
2128 | static CanThrowResult canCalleeThrow(Sema &S, const Expr *E, const Decl *D, |
||
2129 | SourceLocation Loc = SourceLocation()); |
||
2130 | const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc, |
||
2131 | const FunctionProtoType *FPT); |
||
2132 | void UpdateExceptionSpec(FunctionDecl *FD, |
||
2133 | const FunctionProtoType::ExceptionSpecInfo &ESI); |
||
2134 | bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range); |
||
2135 | bool CheckDistantExceptionSpec(QualType T); |
||
2136 | bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New); |
||
2137 | bool CheckEquivalentExceptionSpec( |
||
2138 | const FunctionProtoType *Old, SourceLocation OldLoc, |
||
2139 | const FunctionProtoType *New, SourceLocation NewLoc); |
||
2140 | bool CheckEquivalentExceptionSpec( |
||
2141 | const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, |
||
2142 | const FunctionProtoType *Old, SourceLocation OldLoc, |
||
2143 | const FunctionProtoType *New, SourceLocation NewLoc); |
||
2144 | bool handlerCanCatch(QualType HandlerType, QualType ExceptionType); |
||
2145 | bool CheckExceptionSpecSubset(const PartialDiagnostic &DiagID, |
||
2146 | const PartialDiagnostic &NestedDiagID, |
||
2147 | const PartialDiagnostic &NoteID, |
||
2148 | const PartialDiagnostic &NoThrowDiagID, |
||
2149 | const FunctionProtoType *Superset, |
||
2150 | SourceLocation SuperLoc, |
||
2151 | const FunctionProtoType *Subset, |
||
2152 | SourceLocation SubLoc); |
||
2153 | bool CheckParamExceptionSpec(const PartialDiagnostic &NestedDiagID, |
||
2154 | const PartialDiagnostic &NoteID, |
||
2155 | const FunctionProtoType *Target, |
||
2156 | SourceLocation TargetLoc, |
||
2157 | const FunctionProtoType *Source, |
||
2158 | SourceLocation SourceLoc); |
||
2159 | |||
2160 | TypeResult ActOnTypeName(Scope *S, Declarator &D); |
||
2161 | |||
2162 | /// The parser has parsed the context-sensitive type 'instancetype' |
||
2163 | /// in an Objective-C message declaration. Return the appropriate type. |
||
2164 | ParsedType ActOnObjCInstanceType(SourceLocation Loc); |
||
2165 | |||
2166 | /// Abstract class used to diagnose incomplete types. |
||
2167 | struct TypeDiagnoser { |
||
2168 | TypeDiagnoser() {} |
||
2169 | |||
2170 | virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0; |
||
2171 | virtual ~TypeDiagnoser() {} |
||
2172 | }; |
||
2173 | |||
2174 | static int getPrintable(int I) { return I; } |
||
2175 | static unsigned getPrintable(unsigned I) { return I; } |
||
2176 | static bool getPrintable(bool B) { return B; } |
||
2177 | static const char * getPrintable(const char *S) { return S; } |
||
2178 | static StringRef getPrintable(StringRef S) { return S; } |
||
2179 | static const std::string &getPrintable(const std::string &S) { return S; } |
||
2180 | static const IdentifierInfo *getPrintable(const IdentifierInfo *II) { |
||
2181 | return II; |
||
2182 | } |
||
2183 | static DeclarationName getPrintable(DeclarationName N) { return N; } |
||
2184 | static QualType getPrintable(QualType T) { return T; } |
||
2185 | static SourceRange getPrintable(SourceRange R) { return R; } |
||
2186 | static SourceRange getPrintable(SourceLocation L) { return L; } |
||
2187 | static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); } |
||
2188 | static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();} |
||
2189 | |||
2190 | template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser { |
||
2191 | protected: |
||
2192 | unsigned DiagID; |
||
2193 | std::tuple<const Ts &...> Args; |
||
2194 | |||
2195 | template <std::size_t... Is> |
||
2196 | void emit(const SemaDiagnosticBuilder &DB, |
||
2197 | std::index_sequence<Is...>) const { |
||
2198 | // Apply all tuple elements to the builder in order. |
||
2199 | bool Dummy[] = {false, (DB << getPrintable(std::get<Is>(Args)))...}; |
||
2200 | (void)Dummy; |
||
2201 | } |
||
2202 | |||
2203 | public: |
||
2204 | BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args) |
||
2205 | : TypeDiagnoser(), DiagID(DiagID), Args(Args...) { |
||
2206 | assert(DiagID != 0 && "no diagnostic for type diagnoser"); |
||
2207 | } |
||
2208 | |||
2209 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
||
2210 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID); |
||
2211 | emit(DB, std::index_sequence_for<Ts...>()); |
||
2212 | DB << T; |
||
2213 | } |
||
2214 | }; |
||
2215 | |||
2216 | /// Do a check to make sure \p Name looks like a legal argument for the |
||
2217 | /// swift_name attribute applied to decl \p D. Raise a diagnostic if the name |
||
2218 | /// is invalid for the given declaration. |
||
2219 | /// |
||
2220 | /// \p AL is used to provide caret diagnostics in case of a malformed name. |
||
2221 | /// |
||
2222 | /// \returns true if the name is a valid swift name for \p D, false otherwise. |
||
2223 | bool DiagnoseSwiftName(Decl *D, StringRef Name, SourceLocation Loc, |
||
2224 | const ParsedAttr &AL, bool IsAsync); |
||
2225 | |||
2226 | /// A derivative of BoundTypeDiagnoser for which the diagnostic's type |
||
2227 | /// parameter is preceded by a 0/1 enum that is 1 if the type is sizeless. |
||
2228 | /// For example, a diagnostic with no other parameters would generally have |
||
2229 | /// the form "...%select{incomplete|sizeless}0 type %1...". |
||
2230 | template <typename... Ts> |
||
2231 | class SizelessTypeDiagnoser : public BoundTypeDiagnoser<Ts...> { |
||
2232 | public: |
||
2233 | SizelessTypeDiagnoser(unsigned DiagID, const Ts &... Args) |
||
2234 | : BoundTypeDiagnoser<Ts...>(DiagID, Args...) {} |
||
2235 | |||
2236 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
||
2237 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, this->DiagID); |
||
2238 | this->emit(DB, std::index_sequence_for<Ts...>()); |
||
2239 | DB << T->isSizelessType() << T; |
||
2240 | } |
||
2241 | }; |
||
2242 | |||
2243 | enum class CompleteTypeKind { |
||
2244 | /// Apply the normal rules for complete types. In particular, |
||
2245 | /// treat all sizeless types as incomplete. |
||
2246 | Normal, |
||
2247 | |||
2248 | /// Relax the normal rules for complete types so that they include |
||
2249 | /// sizeless built-in types. |
||
2250 | AcceptSizeless, |
||
2251 | |||
2252 | // FIXME: Eventually we should flip the default to Normal and opt in |
||
2253 | // to AcceptSizeless rather than opt out of it. |
||
2254 | Default = AcceptSizeless |
||
2255 | }; |
||
2256 | |||
2257 | enum class AcceptableKind { Visible, Reachable }; |
||
2258 | |||
2259 | private: |
||
2260 | /// Methods for marking which expressions involve dereferencing a pointer |
||
2261 | /// marked with the 'noderef' attribute. Expressions are checked bottom up as |
||
2262 | /// they are parsed, meaning that a noderef pointer may not be accessed. For |
||
2263 | /// example, in `&*p` where `p` is a noderef pointer, we will first parse the |
||
2264 | /// `*p`, but need to check that `address of` is called on it. This requires |
||
2265 | /// keeping a container of all pending expressions and checking if the address |
||
2266 | /// of them are eventually taken. |
||
2267 | void CheckSubscriptAccessOfNoDeref(const ArraySubscriptExpr *E); |
||
2268 | void CheckAddressOfNoDeref(const Expr *E); |
||
2269 | void CheckMemberAccessOfNoDeref(const MemberExpr *E); |
||
2270 | |||
2271 | bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T, |
||
2272 | CompleteTypeKind Kind, TypeDiagnoser *Diagnoser); |
||
2273 | |||
2274 | struct ModuleScope { |
||
2275 | SourceLocation BeginLoc; |
||
2276 | clang::Module *Module = nullptr; |
||
2277 | bool ModuleInterface = false; |
||
2278 | bool IsPartition = false; |
||
2279 | bool ImplicitGlobalModuleFragment = false; |
||
2280 | VisibleModuleSet OuterVisibleModules; |
||
2281 | }; |
||
2282 | /// The modules we're currently parsing. |
||
2283 | llvm::SmallVector<ModuleScope, 16> ModuleScopes; |
||
2284 | /// The global module fragment of the current translation unit. |
||
2285 | clang::Module *GlobalModuleFragment = nullptr; |
||
2286 | |||
2287 | /// The modules we imported directly. |
||
2288 | llvm::SmallPtrSet<clang::Module *, 8> DirectModuleImports; |
||
2289 | |||
2290 | /// Namespace definitions that we will export when they finish. |
||
2291 | llvm::SmallPtrSet<const NamespaceDecl*, 8> DeferredExportedNamespaces; |
||
2292 | |||
2293 | /// In a C++ standard module, inline declarations require a definition to be |
||
2294 | /// present at the end of a definition domain. This set holds the decls to |
||
2295 | /// be checked at the end of the TU. |
||
2296 | llvm::SmallPtrSet<const FunctionDecl *, 8> PendingInlineFuncDecls; |
||
2297 | |||
2298 | /// Helper function to judge if we are in module purview. |
||
2299 | /// Return false if we are not in a module. |
||
2300 | bool isCurrentModulePurview() const { |
||
2301 | return getCurrentModule() ? getCurrentModule()->isModulePurview() : false; |
||
2302 | } |
||
2303 | |||
2304 | /// Enter the scope of the global module. |
||
2305 | Module *PushGlobalModuleFragment(SourceLocation BeginLoc, bool IsImplicit); |
||
2306 | /// Leave the scope of the global module. |
||
2307 | void PopGlobalModuleFragment(); |
||
2308 | |||
2309 | VisibleModuleSet VisibleModules; |
||
2310 | |||
2311 | /// Cache for module units which is usable for current module. |
||
2312 | llvm::DenseSet<const Module *> UsableModuleUnitsCache; |
||
2313 | |||
2314 | bool isUsableModule(const Module *M); |
||
2315 | |||
2316 | bool isAcceptableSlow(const NamedDecl *D, AcceptableKind Kind); |
||
2317 | |||
2318 | public: |
||
2319 | /// Get the module unit whose scope we are currently within. |
||
2320 | Module *getCurrentModule() const { |
||
2321 | return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module; |
||
2322 | } |
||
2323 | |||
2324 | /// Is the module scope we are an interface? |
||
2325 | bool currentModuleIsInterface() const { |
||
2326 | return ModuleScopes.empty() ? false : ModuleScopes.back().ModuleInterface; |
||
2327 | } |
||
2328 | |||
2329 | /// Is the module scope we are in a C++ Header Unit? |
||
2330 | bool currentModuleIsHeaderUnit() const { |
||
2331 | return ModuleScopes.empty() ? false |
||
2332 | : ModuleScopes.back().Module->isHeaderUnit(); |
||
2333 | } |
||
2334 | |||
2335 | /// Get the module owning an entity. |
||
2336 | Module *getOwningModule(const Decl *Entity) { |
||
2337 | return Entity->getOwningModule(); |
||
2338 | } |
||
2339 | |||
2340 | bool isModuleDirectlyImported(const Module *M) { |
||
2341 | return DirectModuleImports.contains(M); |
||
2342 | } |
||
2343 | |||
2344 | // Determine whether the module M belongs to the current TU. |
||
2345 | bool isModuleUnitOfCurrentTU(const Module *M) const; |
||
2346 | |||
2347 | /// Make a merged definition of an existing hidden definition \p ND |
||
2348 | /// visible at the specified location. |
||
2349 | void makeMergedDefinitionVisible(NamedDecl *ND); |
||
2350 | |||
2351 | bool isModuleVisible(const Module *M, bool ModulePrivate = false); |
||
2352 | |||
2353 | // When loading a non-modular PCH files, this is used to restore module |
||
2354 | // visibility. |
||
2355 | void makeModuleVisible(Module *Mod, SourceLocation ImportLoc) { |
||
2356 | VisibleModules.setVisible(Mod, ImportLoc); |
||
2357 | } |
||
2358 | |||
2359 | /// Determine whether a declaration is visible to name lookup. |
||
2360 | bool isVisible(const NamedDecl *D) { |
||
2361 | return D->isUnconditionallyVisible() || |
||
2362 | isAcceptableSlow(D, AcceptableKind::Visible); |
||
2363 | } |
||
2364 | |||
2365 | /// Determine whether a declaration is reachable. |
||
2366 | bool isReachable(const NamedDecl *D) { |
||
2367 | // All visible declarations are reachable. |
||
2368 | return D->isUnconditionallyVisible() || |
||
2369 | isAcceptableSlow(D, AcceptableKind::Reachable); |
||
2370 | } |
||
2371 | |||
2372 | /// Determine whether a declaration is acceptable (visible/reachable). |
||
2373 | bool isAcceptable(const NamedDecl *D, AcceptableKind Kind) { |
||
2374 | return Kind == AcceptableKind::Visible ? isVisible(D) : isReachable(D); |
||
2375 | } |
||
2376 | |||
2377 | /// Determine whether any declaration of an entity is visible. |
||
2378 | bool |
||
2379 | hasVisibleDeclaration(const NamedDecl *D, |
||
2380 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
||
2381 | return isVisible(D) || hasVisibleDeclarationSlow(D, Modules); |
||
2382 | } |
||
2383 | |||
2384 | bool hasVisibleDeclarationSlow(const NamedDecl *D, |
||
2385 | llvm::SmallVectorImpl<Module *> *Modules); |
||
2386 | /// Determine whether any declaration of an entity is reachable. |
||
2387 | bool |
||
2388 | hasReachableDeclaration(const NamedDecl *D, |
||
2389 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
||
2390 | return isReachable(D) || hasReachableDeclarationSlow(D, Modules); |
||
2391 | } |
||
2392 | bool hasReachableDeclarationSlow( |
||
2393 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
||
2394 | |||
2395 | bool hasVisibleMergedDefinition(NamedDecl *Def); |
||
2396 | bool hasMergedDefinitionInCurrentModule(NamedDecl *Def); |
||
2397 | |||
2398 | /// Determine if \p D and \p Suggested have a structurally compatible |
||
2399 | /// layout as described in C11 6.2.7/1. |
||
2400 | bool hasStructuralCompatLayout(Decl *D, Decl *Suggested); |
||
2401 | |||
2402 | /// Determine if \p D has a visible definition. If not, suggest a declaration |
||
2403 | /// that should be made visible to expose the definition. |
||
2404 | bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, |
||
2405 | bool OnlyNeedComplete = false); |
||
2406 | bool hasVisibleDefinition(const NamedDecl *D) { |
||
2407 | NamedDecl *Hidden; |
||
2408 | return hasVisibleDefinition(const_cast<NamedDecl*>(D), &Hidden); |
||
2409 | } |
||
2410 | |||
2411 | /// Determine if \p D has a reachable definition. If not, suggest a |
||
2412 | /// declaration that should be made reachable to expose the definition. |
||
2413 | bool hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested, |
||
2414 | bool OnlyNeedComplete = false); |
||
2415 | bool hasReachableDefinition(NamedDecl *D) { |
||
2416 | NamedDecl *Hidden; |
||
2417 | return hasReachableDefinition(D, &Hidden); |
||
2418 | } |
||
2419 | |||
2420 | bool hasAcceptableDefinition(NamedDecl *D, NamedDecl **Suggested, |
||
2421 | AcceptableKind Kind, |
||
2422 | bool OnlyNeedComplete = false); |
||
2423 | bool hasAcceptableDefinition(NamedDecl *D, AcceptableKind Kind) { |
||
2424 | NamedDecl *Hidden; |
||
2425 | return hasAcceptableDefinition(D, &Hidden, Kind); |
||
2426 | } |
||
2427 | |||
2428 | /// Determine if the template parameter \p D has a visible default argument. |
||
2429 | bool |
||
2430 | hasVisibleDefaultArgument(const NamedDecl *D, |
||
2431 | llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
||
2432 | /// Determine if the template parameter \p D has a reachable default argument. |
||
2433 | bool hasReachableDefaultArgument( |
||
2434 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
||
2435 | /// Determine if the template parameter \p D has a reachable default argument. |
||
2436 | bool hasAcceptableDefaultArgument(const NamedDecl *D, |
||
2437 | llvm::SmallVectorImpl<Module *> *Modules, |
||
2438 | Sema::AcceptableKind Kind); |
||
2439 | |||
2440 | /// Determine if there is a visible declaration of \p D that is an explicit |
||
2441 | /// specialization declaration for a specialization of a template. (For a |
||
2442 | /// member specialization, use hasVisibleMemberSpecialization.) |
||
2443 | bool hasVisibleExplicitSpecialization( |
||
2444 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
||
2445 | /// Determine if there is a reachable declaration of \p D that is an explicit |
||
2446 | /// specialization declaration for a specialization of a template. (For a |
||
2447 | /// member specialization, use hasReachableMemberSpecialization.) |
||
2448 | bool hasReachableExplicitSpecialization( |
||
2449 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
||
2450 | |||
2451 | /// Determine if there is a visible declaration of \p D that is a member |
||
2452 | /// specialization declaration (as opposed to an instantiated declaration). |
||
2453 | bool hasVisibleMemberSpecialization( |
||
2454 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
||
2455 | /// Determine if there is a reachable declaration of \p D that is a member |
||
2456 | /// specialization declaration (as opposed to an instantiated declaration). |
||
2457 | bool hasReachableMemberSpecialization( |
||
2458 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
||
2459 | |||
2460 | /// Determine if \p A and \p B are equivalent internal linkage declarations |
||
2461 | /// from different modules, and thus an ambiguity error can be downgraded to |
||
2462 | /// an extension warning. |
||
2463 | bool isEquivalentInternalLinkageDeclaration(const NamedDecl *A, |
||
2464 | const NamedDecl *B); |
||
2465 | void diagnoseEquivalentInternalLinkageDeclarations( |
||
2466 | SourceLocation Loc, const NamedDecl *D, |
||
2467 | ArrayRef<const NamedDecl *> Equiv); |
||
2468 | |||
2469 | bool isUsualDeallocationFunction(const CXXMethodDecl *FD); |
||
2470 | |||
2471 | // Check whether the size of array element of type \p EltTy is a multiple of |
||
2472 | // its alignment and return false if it isn't. |
||
2473 | bool checkArrayElementAlignment(QualType EltTy, SourceLocation Loc); |
||
2474 | |||
2475 | bool isCompleteType(SourceLocation Loc, QualType T, |
||
2476 | CompleteTypeKind Kind = CompleteTypeKind::Default) { |
||
2477 | return !RequireCompleteTypeImpl(Loc, T, Kind, nullptr); |
||
2478 | } |
||
2479 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
||
2480 | CompleteTypeKind Kind, TypeDiagnoser &Diagnoser); |
||
2481 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
||
2482 | CompleteTypeKind Kind, unsigned DiagID); |
||
2483 | |||
2484 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
||
2485 | TypeDiagnoser &Diagnoser) { |
||
2486 | return RequireCompleteType(Loc, T, CompleteTypeKind::Default, Diagnoser); |
||
2487 | } |
||
2488 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID) { |
||
2489 | return RequireCompleteType(Loc, T, CompleteTypeKind::Default, DiagID); |
||
2490 | } |
||
2491 | |||
2492 | template <typename... Ts> |
||
2493 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID, |
||
2494 | const Ts &...Args) { |
||
2495 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
||
2496 | return RequireCompleteType(Loc, T, Diagnoser); |
||
2497 | } |
||
2498 | |||
2499 | template <typename... Ts> |
||
2500 | bool RequireCompleteSizedType(SourceLocation Loc, QualType T, unsigned DiagID, |
||
2501 | const Ts &... Args) { |
||
2502 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
||
2503 | return RequireCompleteType(Loc, T, CompleteTypeKind::Normal, Diagnoser); |
||
2504 | } |
||
2505 | |||
2506 | /// Get the type of expression E, triggering instantiation to complete the |
||
2507 | /// type if necessary -- that is, if the expression refers to a templated |
||
2508 | /// static data member of incomplete array type. |
||
2509 | /// |
||
2510 | /// May still return an incomplete type if instantiation was not possible or |
||
2511 | /// if the type is incomplete for a different reason. Use |
||
2512 | /// RequireCompleteExprType instead if a diagnostic is expected for an |
||
2513 | /// incomplete expression type. |
||
2514 | QualType getCompletedType(Expr *E); |
||
2515 | |||
2516 | void completeExprArrayBound(Expr *E); |
||
2517 | bool RequireCompleteExprType(Expr *E, CompleteTypeKind Kind, |
||
2518 | TypeDiagnoser &Diagnoser); |
||
2519 | bool RequireCompleteExprType(Expr *E, unsigned DiagID); |
||
2520 | |||
2521 | template <typename... Ts> |
||
2522 | bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) { |
||
2523 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
||
2524 | return RequireCompleteExprType(E, CompleteTypeKind::Default, Diagnoser); |
||
2525 | } |
||
2526 | |||
2527 | template <typename... Ts> |
||
2528 | bool RequireCompleteSizedExprType(Expr *E, unsigned DiagID, |
||
2529 | const Ts &... Args) { |
||
2530 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
||
2531 | return RequireCompleteExprType(E, CompleteTypeKind::Normal, Diagnoser); |
||
2532 | } |
||
2533 | |||
2534 | bool RequireLiteralType(SourceLocation Loc, QualType T, |
||
2535 | TypeDiagnoser &Diagnoser); |
||
2536 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID); |
||
2537 | |||
2538 | template <typename... Ts> |
||
2539 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID, |
||
2540 | const Ts &...Args) { |
||
2541 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
||
2542 | return RequireLiteralType(Loc, T, Diagnoser); |
||
2543 | } |
||
2544 | |||
2545 | QualType getElaboratedType(ElaboratedTypeKeyword Keyword, |
||
2546 | const CXXScopeSpec &SS, QualType T, |
||
2547 | TagDecl *OwnedTagDecl = nullptr); |
||
2548 | |||
2549 | // Returns the underlying type of a decltype with the given expression. |
||
2550 | QualType getDecltypeForExpr(Expr *E); |
||
2551 | |||
2552 | QualType BuildTypeofExprType(Expr *E, TypeOfKind Kind); |
||
2553 | /// If AsUnevaluated is false, E is treated as though it were an evaluated |
||
2554 | /// context, such as when building a type for decltype(auto). |
||
2555 | QualType BuildDecltypeType(Expr *E, bool AsUnevaluated = true); |
||
2556 | |||
2557 | using UTTKind = UnaryTransformType::UTTKind; |
||
2558 | QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind, |
||
2559 | SourceLocation Loc); |
||
2560 | QualType BuiltinEnumUnderlyingType(QualType BaseType, SourceLocation Loc); |
||
2561 | QualType BuiltinAddPointer(QualType BaseType, SourceLocation Loc); |
||
2562 | QualType BuiltinRemovePointer(QualType BaseType, SourceLocation Loc); |
||
2563 | QualType BuiltinDecay(QualType BaseType, SourceLocation Loc); |
||
2564 | QualType BuiltinAddReference(QualType BaseType, UTTKind UKind, |
||
2565 | SourceLocation Loc); |
||
2566 | QualType BuiltinRemoveExtent(QualType BaseType, UTTKind UKind, |
||
2567 | SourceLocation Loc); |
||
2568 | QualType BuiltinRemoveReference(QualType BaseType, UTTKind UKind, |
||
2569 | SourceLocation Loc); |
||
2570 | QualType BuiltinChangeCVRQualifiers(QualType BaseType, UTTKind UKind, |
||
2571 | SourceLocation Loc); |
||
2572 | QualType BuiltinChangeSignedness(QualType BaseType, UTTKind UKind, |
||
2573 | SourceLocation Loc); |
||
2574 | |||
2575 | //===--------------------------------------------------------------------===// |
||
2576 | // Symbol table / Decl tracking callbacks: SemaDecl.cpp. |
||
2577 | // |
||
2578 | |||
2579 | struct SkipBodyInfo { |
||
2580 | SkipBodyInfo() |
||
2581 | : ShouldSkip(false), CheckSameAsPrevious(false), Previous(nullptr), |
||
2582 | New(nullptr) {} |
||
2583 | bool ShouldSkip; |
||
2584 | bool CheckSameAsPrevious; |
||
2585 | NamedDecl *Previous; |
||
2586 | NamedDecl *New; |
||
2587 | }; |
||
2588 | |||
2589 | DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr); |
||
2590 | |||
2591 | void DiagnoseUseOfUnimplementedSelectors(); |
||
2592 | |||
2593 | bool isSimpleTypeSpecifier(tok::TokenKind Kind) const; |
||
2594 | |||
2595 | ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, |
||
2596 | Scope *S, CXXScopeSpec *SS = nullptr, |
||
2597 | bool isClassName = false, bool HasTrailingDot = false, |
||
2598 | ParsedType ObjectType = nullptr, |
||
2599 | bool IsCtorOrDtorName = false, |
||
2600 | bool WantNontrivialTypeSourceInfo = false, |
||
2601 | bool IsClassTemplateDeductionContext = true, |
||
2602 | ImplicitTypenameContext AllowImplicitTypename = |
||
2603 | ImplicitTypenameContext::No, |
||
2604 | IdentifierInfo **CorrectedII = nullptr); |
||
2605 | TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S); |
||
2606 | bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S); |
||
2607 | void DiagnoseUnknownTypeName(IdentifierInfo *&II, |
||
2608 | SourceLocation IILoc, |
||
2609 | Scope *S, |
||
2610 | CXXScopeSpec *SS, |
||
2611 | ParsedType &SuggestedType, |
||
2612 | bool IsTemplateName = false); |
||
2613 | |||
2614 | /// Attempt to behave like MSVC in situations where lookup of an unqualified |
||
2615 | /// type name has failed in a dependent context. In these situations, we |
||
2616 | /// automatically form a DependentTypeName that will retry lookup in a related |
||
2617 | /// scope during instantiation. |
||
2618 | ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II, |
||
2619 | SourceLocation NameLoc, |
||
2620 | bool IsTemplateTypeArg); |
||
2621 | |||
2622 | /// Describes the result of the name lookup and resolution performed |
||
2623 | /// by \c ClassifyName(). |
||
2624 | enum NameClassificationKind { |
||
2625 | /// This name is not a type or template in this context, but might be |
||
2626 | /// something else. |
||
2627 | NC_Unknown, |
||
2628 | /// Classification failed; an error has been produced. |
||
2629 | NC_Error, |
||
2630 | /// The name has been typo-corrected to a keyword. |
||
2631 | NC_Keyword, |
||
2632 | /// The name was classified as a type. |
||
2633 | NC_Type, |
||
2634 | /// The name was classified as a specific non-type, non-template |
||
2635 | /// declaration. ActOnNameClassifiedAsNonType should be called to |
||
2636 | /// convert the declaration to an expression. |
||
2637 | NC_NonType, |
||
2638 | /// The name was classified as an ADL-only function name. |
||
2639 | /// ActOnNameClassifiedAsUndeclaredNonType should be called to convert the |
||
2640 | /// result to an expression. |
||
2641 | NC_UndeclaredNonType, |
||
2642 | /// The name denotes a member of a dependent type that could not be |
||
2643 | /// resolved. ActOnNameClassifiedAsDependentNonType should be called to |
||
2644 | /// convert the result to an expression. |
||
2645 | NC_DependentNonType, |
||
2646 | /// The name was classified as an overload set, and an expression |
||
2647 | /// representing that overload set has been formed. |
||
2648 | /// ActOnNameClassifiedAsOverloadSet should be called to form a suitable |
||
2649 | /// expression referencing the overload set. |
||
2650 | NC_OverloadSet, |
||
2651 | /// The name was classified as a template whose specializations are types. |
||
2652 | NC_TypeTemplate, |
||
2653 | /// The name was classified as a variable template name. |
||
2654 | NC_VarTemplate, |
||
2655 | /// The name was classified as a function template name. |
||
2656 | NC_FunctionTemplate, |
||
2657 | /// The name was classified as an ADL-only function template name. |
||
2658 | NC_UndeclaredTemplate, |
||
2659 | /// The name was classified as a concept name. |
||
2660 | NC_Concept, |
||
2661 | }; |
||
2662 | |||
2663 | class NameClassification { |
||
2664 | NameClassificationKind Kind; |
||
2665 | union { |
||
2666 | ExprResult Expr; |
||
2667 | NamedDecl *NonTypeDecl; |
||
2668 | TemplateName Template; |
||
2669 | ParsedType Type; |
||
2670 | }; |
||
2671 | |||
2672 | explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {} |
||
2673 | |||
2674 | public: |
||
2675 | NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {} |
||
2676 | |||
2677 | NameClassification(const IdentifierInfo *Keyword) : Kind(NC_Keyword) {} |
||
2678 | |||
2679 | static NameClassification Error() { |
||
2680 | return NameClassification(NC_Error); |
||
2681 | } |
||
2682 | |||
2683 | static NameClassification Unknown() { |
||
2684 | return NameClassification(NC_Unknown); |
||
2685 | } |
||
2686 | |||
2687 | static NameClassification OverloadSet(ExprResult E) { |
||
2688 | NameClassification Result(NC_OverloadSet); |
||
2689 | Result.Expr = E; |
||
2690 | return Result; |
||
2691 | } |
||
2692 | |||
2693 | static NameClassification NonType(NamedDecl *D) { |
||
2694 | NameClassification Result(NC_NonType); |
||
2695 | Result.NonTypeDecl = D; |
||
2696 | return Result; |
||
2697 | } |
||
2698 | |||
2699 | static NameClassification UndeclaredNonType() { |
||
2700 | return NameClassification(NC_UndeclaredNonType); |
||
2701 | } |
||
2702 | |||
2703 | static NameClassification DependentNonType() { |
||
2704 | return NameClassification(NC_DependentNonType); |
||
2705 | } |
||
2706 | |||
2707 | static NameClassification TypeTemplate(TemplateName Name) { |
||
2708 | NameClassification Result(NC_TypeTemplate); |
||
2709 | Result.Template = Name; |
||
2710 | return Result; |
||
2711 | } |
||
2712 | |||
2713 | static NameClassification VarTemplate(TemplateName Name) { |
||
2714 | NameClassification Result(NC_VarTemplate); |
||
2715 | Result.Template = Name; |
||
2716 | return Result; |
||
2717 | } |
||
2718 | |||
2719 | static NameClassification FunctionTemplate(TemplateName Name) { |
||
2720 | NameClassification Result(NC_FunctionTemplate); |
||
2721 | Result.Template = Name; |
||
2722 | return Result; |
||
2723 | } |
||
2724 | |||
2725 | static NameClassification Concept(TemplateName Name) { |
||
2726 | NameClassification Result(NC_Concept); |
||
2727 | Result.Template = Name; |
||
2728 | return Result; |
||
2729 | } |
||
2730 | |||
2731 | static NameClassification UndeclaredTemplate(TemplateName Name) { |
||
2732 | NameClassification Result(NC_UndeclaredTemplate); |
||
2733 | Result.Template = Name; |
||
2734 | return Result; |
||
2735 | } |
||
2736 | |||
2737 | NameClassificationKind getKind() const { return Kind; } |
||
2738 | |||
2739 | ExprResult getExpression() const { |
||
2740 | assert(Kind == NC_OverloadSet); |
||
2741 | return Expr; |
||
2742 | } |
||
2743 | |||
2744 | ParsedType getType() const { |
||
2745 | assert(Kind == NC_Type); |
||
2746 | return Type; |
||
2747 | } |
||
2748 | |||
2749 | NamedDecl *getNonTypeDecl() const { |
||
2750 | assert(Kind == NC_NonType); |
||
2751 | return NonTypeDecl; |
||
2752 | } |
||
2753 | |||
2754 | TemplateName getTemplateName() const { |
||
2755 | assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || |
||
2756 | Kind == NC_VarTemplate || Kind == NC_Concept || |
||
2757 | Kind == NC_UndeclaredTemplate); |
||
2758 | return Template; |
||
2759 | } |
||
2760 | |||
2761 | TemplateNameKind getTemplateNameKind() const { |
||
2762 | switch (Kind) { |
||
2763 | case NC_TypeTemplate: |
||
2764 | return TNK_Type_template; |
||
2765 | case NC_FunctionTemplate: |
||
2766 | return TNK_Function_template; |
||
2767 | case NC_VarTemplate: |
||
2768 | return TNK_Var_template; |
||
2769 | case NC_Concept: |
||
2770 | return TNK_Concept_template; |
||
2771 | case NC_UndeclaredTemplate: |
||
2772 | return TNK_Undeclared_template; |
||
2773 | default: |
||
2774 | llvm_unreachable("unsupported name classification."); |
||
2775 | } |
||
2776 | } |
||
2777 | }; |
||
2778 | |||
2779 | /// Perform name lookup on the given name, classifying it based on |
||
2780 | /// the results of name lookup and the following token. |
||
2781 | /// |
||
2782 | /// This routine is used by the parser to resolve identifiers and help direct |
||
2783 | /// parsing. When the identifier cannot be found, this routine will attempt |
||
2784 | /// to correct the typo and classify based on the resulting name. |
||
2785 | /// |
||
2786 | /// \param S The scope in which we're performing name lookup. |
||
2787 | /// |
||
2788 | /// \param SS The nested-name-specifier that precedes the name. |
||
2789 | /// |
||
2790 | /// \param Name The identifier. If typo correction finds an alternative name, |
||
2791 | /// this pointer parameter will be updated accordingly. |
||
2792 | /// |
||
2793 | /// \param NameLoc The location of the identifier. |
||
2794 | /// |
||
2795 | /// \param NextToken The token following the identifier. Used to help |
||
2796 | /// disambiguate the name. |
||
2797 | /// |
||
2798 | /// \param CCC The correction callback, if typo correction is desired. |
||
2799 | NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS, |
||
2800 | IdentifierInfo *&Name, SourceLocation NameLoc, |
||
2801 | const Token &NextToken, |
||
2802 | CorrectionCandidateCallback *CCC = nullptr); |
||
2803 | |||
2804 | /// Act on the result of classifying a name as an undeclared (ADL-only) |
||
2805 | /// non-type declaration. |
||
2806 | ExprResult ActOnNameClassifiedAsUndeclaredNonType(IdentifierInfo *Name, |
||
2807 | SourceLocation NameLoc); |
||
2808 | /// Act on the result of classifying a name as an undeclared member of a |
||
2809 | /// dependent base class. |
||
2810 | ExprResult ActOnNameClassifiedAsDependentNonType(const CXXScopeSpec &SS, |
||
2811 | IdentifierInfo *Name, |
||
2812 | SourceLocation NameLoc, |
||
2813 | bool IsAddressOfOperand); |
||
2814 | /// Act on the result of classifying a name as a specific non-type |
||
2815 | /// declaration. |
||
2816 | ExprResult ActOnNameClassifiedAsNonType(Scope *S, const CXXScopeSpec &SS, |
||
2817 | NamedDecl *Found, |
||
2818 | SourceLocation NameLoc, |
||
2819 | const Token &NextToken); |
||
2820 | /// Act on the result of classifying a name as an overload set. |
||
2821 | ExprResult ActOnNameClassifiedAsOverloadSet(Scope *S, Expr *OverloadSet); |
||
2822 | |||
2823 | /// Describes the detailed kind of a template name. Used in diagnostics. |
||
2824 | enum class TemplateNameKindForDiagnostics { |
||
2825 | ClassTemplate, |
||
2826 | FunctionTemplate, |
||
2827 | VarTemplate, |
||
2828 | AliasTemplate, |
||
2829 | TemplateTemplateParam, |
||
2830 | Concept, |
||
2831 | DependentTemplate |
||
2832 | }; |
||
2833 | TemplateNameKindForDiagnostics |
||
2834 | getTemplateNameKindForDiagnostics(TemplateName Name); |
||
2835 | |||
2836 | /// Determine whether it's plausible that E was intended to be a |
||
2837 | /// template-name. |
||
2838 | bool mightBeIntendedToBeTemplateName(ExprResult E, bool &Dependent) { |
||
2839 | if (!getLangOpts().CPlusPlus || E.isInvalid()) |
||
2840 | return false; |
||
2841 | Dependent = false; |
||
2842 | if (auto *DRE = dyn_cast<DeclRefExpr>(E.get())) |
||
2843 | return !DRE->hasExplicitTemplateArgs(); |
||
2844 | if (auto *ME = dyn_cast<MemberExpr>(E.get())) |
||
2845 | return !ME->hasExplicitTemplateArgs(); |
||
2846 | Dependent = true; |
||
2847 | if (auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(E.get())) |
||
2848 | return !DSDRE->hasExplicitTemplateArgs(); |
||
2849 | if (auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(E.get())) |
||
2850 | return !DSME->hasExplicitTemplateArgs(); |
||
2851 | // Any additional cases recognized here should also be handled by |
||
2852 | // diagnoseExprIntendedAsTemplateName. |
||
2853 | return false; |
||
2854 | } |
||
2855 | void diagnoseExprIntendedAsTemplateName(Scope *S, ExprResult TemplateName, |
||
2856 | SourceLocation Less, |
||
2857 | SourceLocation Greater); |
||
2858 | |||
2859 | void warnOnReservedIdentifier(const NamedDecl *D); |
||
2860 | |||
2861 | Decl *ActOnDeclarator(Scope *S, Declarator &D); |
||
2862 | |||
2863 | NamedDecl *HandleDeclarator(Scope *S, Declarator &D, |
||
2864 | MultiTemplateParamsArg TemplateParameterLists); |
||
2865 | bool tryToFixVariablyModifiedVarType(TypeSourceInfo *&TInfo, |
||
2866 | QualType &T, SourceLocation Loc, |
||
2867 | unsigned FailedFoldDiagID); |
||
2868 | void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S); |
||
2869 | bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info); |
||
2870 | bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, |
||
2871 | DeclarationName Name, SourceLocation Loc, |
||
2872 | bool IsTemplateId); |
||
2873 | void |
||
2874 | diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals, |
||
2875 | SourceLocation FallbackLoc, |
||
2876 | SourceLocation ConstQualLoc = SourceLocation(), |
||
2877 | SourceLocation VolatileQualLoc = SourceLocation(), |
||
2878 | SourceLocation RestrictQualLoc = SourceLocation(), |
||
2879 | SourceLocation AtomicQualLoc = SourceLocation(), |
||
2880 | SourceLocation UnalignedQualLoc = SourceLocation()); |
||
2881 | |||
2882 | static bool adjustContextForLocalExternDecl(DeclContext *&DC); |
||
2883 | void DiagnoseFunctionSpecifiers(const DeclSpec &DS); |
||
2884 | NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D, |
||
2885 | const LookupResult &R); |
||
2886 | NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult &R); |
||
2887 | NamedDecl *getShadowedDeclaration(const BindingDecl *D, |
||
2888 | const LookupResult &R); |
||
2889 | void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl, |
||
2890 | const LookupResult &R); |
||
2891 | void CheckShadow(Scope *S, VarDecl *D); |
||
2892 | |||
2893 | /// Warn if 'E', which is an expression that is about to be modified, refers |
||
2894 | /// to a shadowing declaration. |
||
2895 | void CheckShadowingDeclModification(Expr *E, SourceLocation Loc); |
||
2896 | |||
2897 | void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI); |
||
2898 | |||
2899 | private: |
||
2900 | /// Map of current shadowing declarations to shadowed declarations. Warn if |
||
2901 | /// it looks like the user is trying to modify the shadowing declaration. |
||
2902 | llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls; |
||
2903 | |||
2904 | public: |
||
2905 | void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); |
||
2906 | void handleTagNumbering(const TagDecl *Tag, Scope *TagScope); |
||
2907 | void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec, |
||
2908 | TypedefNameDecl *NewTD); |
||
2909 | void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D); |
||
2910 | NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
||
2911 | TypeSourceInfo *TInfo, |
||
2912 | LookupResult &Previous); |
||
2913 | NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D, |
||
2914 | LookupResult &Previous, bool &Redeclaration); |
||
2915 | NamedDecl *ActOnVariableDeclarator( |
||
2916 | Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, |
||
2917 | LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists, |
||
2918 | bool &AddToScope, ArrayRef<BindingDecl *> Bindings = std::nullopt); |
||
2919 | NamedDecl * |
||
2920 | ActOnDecompositionDeclarator(Scope *S, Declarator &D, |
||
2921 | MultiTemplateParamsArg TemplateParamLists); |
||
2922 | // Returns true if the variable declaration is a redeclaration |
||
2923 | bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous); |
||
2924 | void CheckVariableDeclarationType(VarDecl *NewVD); |
||
2925 | bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit, |
||
2926 | Expr *Init); |
||
2927 | void CheckCompleteVariableDeclaration(VarDecl *VD); |
||
2928 | void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD); |
||
2929 | void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D); |
||
2930 | |||
2931 | NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
||
2932 | TypeSourceInfo *TInfo, |
||
2933 | LookupResult &Previous, |
||
2934 | MultiTemplateParamsArg TemplateParamLists, |
||
2935 | bool &AddToScope); |
||
2936 | bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); |
||
2937 | |||
2938 | enum class CheckConstexprKind { |
||
2939 | /// Diagnose issues that are non-constant or that are extensions. |
||
2940 | Diagnose, |
||
2941 | /// Identify whether this function satisfies the formal rules for constexpr |
||
2942 | /// functions in the current lanugage mode (with no extensions). |
||
2943 | CheckValid |
||
2944 | }; |
||
2945 | |||
2946 | bool CheckConstexprFunctionDefinition(const FunctionDecl *FD, |
||
2947 | CheckConstexprKind Kind); |
||
2948 | |||
2949 | void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD); |
||
2950 | void FindHiddenVirtualMethods(CXXMethodDecl *MD, |
||
2951 | SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods); |
||
2952 | void NoteHiddenVirtualMethods(CXXMethodDecl *MD, |
||
2953 | SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods); |
||
2954 | // Returns true if the function declaration is a redeclaration |
||
2955 | bool CheckFunctionDeclaration(Scope *S, |
||
2956 | FunctionDecl *NewFD, LookupResult &Previous, |
||
2957 | bool IsMemberSpecialization, bool DeclIsDefn); |
||
2958 | bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl); |
||
2959 | bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD, |
||
2960 | QualType NewT, QualType OldT); |
||
2961 | void CheckMain(FunctionDecl *FD, const DeclSpec &D); |
||
2962 | void CheckMSVCRTEntryPoint(FunctionDecl *FD); |
||
2963 | void CheckHLSLEntryPoint(FunctionDecl *FD); |
||
2964 | Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, |
||
2965 | bool IsDefinition); |
||
2966 | void CheckFunctionOrTemplateParamDeclarator(Scope *S, Declarator &D); |
||
2967 | Decl *ActOnParamDeclarator(Scope *S, Declarator &D); |
||
2968 | ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, |
||
2969 | SourceLocation Loc, |
||
2970 | QualType T); |
||
2971 | ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc, |
||
2972 | SourceLocation NameLoc, IdentifierInfo *Name, |
||
2973 | QualType T, TypeSourceInfo *TSInfo, |
||
2974 | StorageClass SC); |
||
2975 | void ActOnParamDefaultArgument(Decl *param, |
||
2976 | SourceLocation EqualLoc, |
||
2977 | Expr *defarg); |
||
2978 | void ActOnParamUnparsedDefaultArgument(Decl *param, SourceLocation EqualLoc, |
||
2979 | SourceLocation ArgLoc); |
||
2980 | void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc); |
||
2981 | ExprResult ConvertParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
||
2982 | SourceLocation EqualLoc); |
||
2983 | void SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
||
2984 | SourceLocation EqualLoc); |
||
2985 | |||
2986 | // Contexts where using non-trivial C union types can be disallowed. This is |
||
2987 | // passed to err_non_trivial_c_union_in_invalid_context. |
||
2988 | enum NonTrivialCUnionContext { |
||
2989 | // Function parameter. |
||
2990 | NTCUC_FunctionParam, |
||
2991 | // Function return. |
||
2992 | NTCUC_FunctionReturn, |
||
2993 | // Default-initialized object. |
||
2994 | NTCUC_DefaultInitializedObject, |
||
2995 | // Variable with automatic storage duration. |
||
2996 | NTCUC_AutoVar, |
||
2997 | // Initializer expression that might copy from another object. |
||
2998 | NTCUC_CopyInit, |
||
2999 | // Assignment. |
||
3000 | NTCUC_Assignment, |
||
3001 | // Compound literal. |
||
3002 | NTCUC_CompoundLiteral, |
||
3003 | // Block capture. |
||
3004 | NTCUC_BlockCapture, |
||
3005 | // lvalue-to-rvalue conversion of volatile type. |
||
3006 | NTCUC_LValueToRValueVolatile, |
||
3007 | }; |
||
3008 | |||
3009 | /// Emit diagnostics if the initializer or any of its explicit or |
||
3010 | /// implicitly-generated subexpressions require copying or |
||
3011 | /// default-initializing a type that is or contains a C union type that is |
||
3012 | /// non-trivial to copy or default-initialize. |
||
3013 | void checkNonTrivialCUnionInInitializer(const Expr *Init, SourceLocation Loc); |
||
3014 | |||
3015 | // These flags are passed to checkNonTrivialCUnion. |
||
3016 | enum NonTrivialCUnionKind { |
||
3017 | NTCUK_Init = 0x1, |
||
3018 | NTCUK_Destruct = 0x2, |
||
3019 | NTCUK_Copy = 0x4, |
||
3020 | }; |
||
3021 | |||
3022 | /// Emit diagnostics if a non-trivial C union type or a struct that contains |
||
3023 | /// a non-trivial C union is used in an invalid context. |
||
3024 | void checkNonTrivialCUnion(QualType QT, SourceLocation Loc, |
||
3025 | NonTrivialCUnionContext UseContext, |
||
3026 | unsigned NonTrivialKind); |
||
3027 | |||
3028 | void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit); |
||
3029 | void ActOnUninitializedDecl(Decl *dcl); |
||
3030 | void ActOnInitializerError(Decl *Dcl); |
||
3031 | |||
3032 | void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc); |
||
3033 | void ActOnCXXForRangeDecl(Decl *D); |
||
3034 | StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, |
||
3035 | IdentifierInfo *Ident, |
||
3036 | ParsedAttributes &Attrs); |
||
3037 | void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc); |
||
3038 | void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc); |
||
3039 | void CheckStaticLocalForDllExport(VarDecl *VD); |
||
3040 | void CheckThreadLocalForLargeAlignment(VarDecl *VD); |
||
3041 | void FinalizeDeclaration(Decl *D); |
||
3042 | DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, |
||
3043 | ArrayRef<Decl *> Group); |
||
3044 | DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group); |
||
3045 | |||
3046 | /// Should be called on all declarations that might have attached |
||
3047 | /// documentation comments. |
||
3048 | void ActOnDocumentableDecl(Decl *D); |
||
3049 | void ActOnDocumentableDecls(ArrayRef<Decl *> Group); |
||
3050 | |||
3051 | enum class FnBodyKind { |
||
3052 | /// C++ [dcl.fct.def.general]p1 |
||
3053 | /// function-body: |
||
3054 | /// ctor-initializer[opt] compound-statement |
||
3055 | /// function-try-block |
||
3056 | Other, |
||
3057 | /// = default ; |
||
3058 | Default, |
||
3059 | /// = delete ; |
||
3060 | Delete |
||
3061 | }; |
||
3062 | |||
3063 | void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, |
||
3064 | SourceLocation LocAfterDecls); |
||
3065 | void CheckForFunctionRedefinition( |
||
3066 | FunctionDecl *FD, const FunctionDecl *EffectiveDefinition = nullptr, |
||
3067 | SkipBodyInfo *SkipBody = nullptr); |
||
3068 | Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D, |
||
3069 | MultiTemplateParamsArg TemplateParamLists, |
||
3070 | SkipBodyInfo *SkipBody = nullptr, |
||
3071 | FnBodyKind BodyKind = FnBodyKind::Other); |
||
3072 | Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D, |
||
3073 | SkipBodyInfo *SkipBody = nullptr, |
||
3074 | FnBodyKind BodyKind = FnBodyKind::Other); |
||
3075 | void SetFunctionBodyKind(Decl *D, SourceLocation Loc, FnBodyKind BodyKind); |
||
3076 | void ActOnStartTrailingRequiresClause(Scope *S, Declarator &D); |
||
3077 | ExprResult ActOnFinishTrailingRequiresClause(ExprResult ConstraintExpr); |
||
3078 | ExprResult ActOnRequiresClause(ExprResult ConstraintExpr); |
||
3079 | void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); |
||
3080 | bool isObjCMethodDecl(Decl *D) { |
||
3081 | return D && isa<ObjCMethodDecl>(D); |
||
3082 | } |
||
3083 | |||
3084 | /// Determine whether we can delay parsing the body of a function or |
||
3085 | /// function template until it is used, assuming we don't care about emitting |
||
3086 | /// code for that function. |
||
3087 | /// |
||
3088 | /// This will be \c false if we may need the body of the function in the |
||
3089 | /// middle of parsing an expression (where it's impractical to switch to |
||
3090 | /// parsing a different function), for instance, if it's constexpr in C++11 |
||
3091 | /// or has an 'auto' return type in C++14. These cases are essentially bugs. |
||
3092 | bool canDelayFunctionBody(const Declarator &D); |
||
3093 | |||
3094 | /// Determine whether we can skip parsing the body of a function |
||
3095 | /// definition, assuming we don't care about analyzing its body or emitting |
||
3096 | /// code for that function. |
||
3097 | /// |
||
3098 | /// This will be \c false only if we may need the body of the function in |
||
3099 | /// order to parse the rest of the program (for instance, if it is |
||
3100 | /// \c constexpr in C++11 or has an 'auto' return type in C++14). |
||
3101 | bool canSkipFunctionBody(Decl *D); |
||
3102 | |||
3103 | /// Determine whether \param D is function like (function or function |
||
3104 | /// template) for parsing. |
||
3105 | bool isDeclaratorFunctionLike(Declarator &D); |
||
3106 | |||
3107 | void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope); |
||
3108 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body); |
||
3109 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation); |
||
3110 | Decl *ActOnSkippedFunctionBody(Decl *Decl); |
||
3111 | void ActOnFinishInlineFunctionDef(FunctionDecl *D); |
||
3112 | |||
3113 | /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an |
||
3114 | /// attribute for which parsing is delayed. |
||
3115 | void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs); |
||
3116 | |||
3117 | /// Diagnose any unused parameters in the given sequence of |
||
3118 | /// ParmVarDecl pointers. |
||
3119 | void DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters); |
||
3120 | |||
3121 | /// Diagnose whether the size of parameters or return value of a |
||
3122 | /// function or obj-c method definition is pass-by-value and larger than a |
||
3123 | /// specified threshold. |
||
3124 | void |
||
3125 | DiagnoseSizeOfParametersAndReturnValue(ArrayRef<ParmVarDecl *> Parameters, |
||
3126 | QualType ReturnTy, NamedDecl *D); |
||
3127 | |||
3128 | void DiagnoseInvalidJumps(Stmt *Body); |
||
3129 | Decl *ActOnFileScopeAsmDecl(Expr *expr, |
||
3130 | SourceLocation AsmLoc, |
||
3131 | SourceLocation RParenLoc); |
||
3132 | |||
3133 | Decl *ActOnTopLevelStmtDecl(Stmt *Statement); |
||
3134 | |||
3135 | /// Handle a C++11 empty-declaration and attribute-declaration. |
||
3136 | Decl *ActOnEmptyDeclaration(Scope *S, const ParsedAttributesView &AttrList, |
||
3137 | SourceLocation SemiLoc); |
||
3138 | |||
3139 | enum class ModuleDeclKind { |
||
3140 | Interface, ///< 'export module X;' |
||
3141 | Implementation, ///< 'module X;' |
||
3142 | PartitionInterface, ///< 'export module X:Y;' |
||
3143 | PartitionImplementation, ///< 'module X:Y;' |
||
3144 | }; |
||
3145 | |||
3146 | /// An enumeration to represent the transition of states in parsing module |
||
3147 | /// fragments and imports. If we are not parsing a C++20 TU, or we find |
||
3148 | /// an error in state transition, the state is set to NotACXX20Module. |
||
3149 | enum class ModuleImportState { |
||
3150 | FirstDecl, ///< Parsing the first decl in a TU. |
||
3151 | GlobalFragment, ///< after 'module;' but before 'module X;' |
||
3152 | ImportAllowed, ///< after 'module X;' but before any non-import decl. |
||
3153 | ImportFinished, ///< after any non-import decl. |
||
3154 | PrivateFragmentImportAllowed, ///< after 'module :private;' but before any |
||
3155 | ///< non-import decl. |
||
3156 | PrivateFragmentImportFinished, ///< after 'module :private;' but a |
||
3157 | ///< non-import decl has already been seen. |
||
3158 | NotACXX20Module ///< Not a C++20 TU, or an invalid state was found. |
||
3159 | }; |
||
3160 | |||
3161 | private: |
||
3162 | /// The parser has begun a translation unit to be compiled as a C++20 |
||
3163 | /// Header Unit, helper for ActOnStartOfTranslationUnit() only. |
||
3164 | void HandleStartOfHeaderUnit(); |
||
3165 | |||
3166 | public: |
||
3167 | /// The parser has processed a module-declaration that begins the definition |
||
3168 | /// of a module interface or implementation. |
||
3169 | DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc, |
||
3170 | SourceLocation ModuleLoc, ModuleDeclKind MDK, |
||
3171 | ModuleIdPath Path, ModuleIdPath Partition, |
||
3172 | ModuleImportState &ImportState); |
||
3173 | |||
3174 | /// The parser has processed a global-module-fragment declaration that begins |
||
3175 | /// the definition of the global module fragment of the current module unit. |
||
3176 | /// \param ModuleLoc The location of the 'module' keyword. |
||
3177 | DeclGroupPtrTy ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc); |
||
3178 | |||
3179 | /// The parser has processed a private-module-fragment declaration that begins |
||
3180 | /// the definition of the private module fragment of the current module unit. |
||
3181 | /// \param ModuleLoc The location of the 'module' keyword. |
||
3182 | /// \param PrivateLoc The location of the 'private' keyword. |
||
3183 | DeclGroupPtrTy ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc, |
||
3184 | SourceLocation PrivateLoc); |
||
3185 | |||
3186 | /// The parser has processed a module import declaration. |
||
3187 | /// |
||
3188 | /// \param StartLoc The location of the first token in the declaration. This |
||
3189 | /// could be the location of an '@', 'export', or 'import'. |
||
3190 | /// \param ExportLoc The location of the 'export' keyword, if any. |
||
3191 | /// \param ImportLoc The location of the 'import' keyword. |
||
3192 | /// \param Path The module toplevel name as an access path. |
||
3193 | /// \param IsPartition If the name is for a partition. |
||
3194 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
||
3195 | SourceLocation ExportLoc, |
||
3196 | SourceLocation ImportLoc, ModuleIdPath Path, |
||
3197 | bool IsPartition = false); |
||
3198 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
||
3199 | SourceLocation ExportLoc, |
||
3200 | SourceLocation ImportLoc, Module *M, |
||
3201 | ModuleIdPath Path = {}); |
||
3202 | |||
3203 | /// The parser has processed a module import translated from a |
||
3204 | /// #include or similar preprocessing directive. |
||
3205 | void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
||
3206 | void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
||
3207 | |||
3208 | /// The parsed has entered a submodule. |
||
3209 | void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod); |
||
3210 | /// The parser has left a submodule. |
||
3211 | void ActOnModuleEnd(SourceLocation DirectiveLoc, Module *Mod); |
||
3212 | |||
3213 | /// Create an implicit import of the given module at the given |
||
3214 | /// source location, for error recovery, if possible. |
||
3215 | /// |
||
3216 | /// This routine is typically used when an entity found by name lookup |
||
3217 | /// is actually hidden within a module that we know about but the user |
||
3218 | /// has forgotten to import. |
||
3219 | void createImplicitModuleImportForErrorRecovery(SourceLocation Loc, |
||
3220 | Module *Mod); |
||
3221 | |||
3222 | /// Kinds of missing import. Note, the values of these enumerators correspond |
||
3223 | /// to %select values in diagnostics. |
||
3224 | enum class MissingImportKind { |
||
3225 | Declaration, |
||
3226 | Definition, |
||
3227 | DefaultArgument, |
||
3228 | ExplicitSpecialization, |
||
3229 | PartialSpecialization |
||
3230 | }; |
||
3231 | |||
3232 | /// Diagnose that the specified declaration needs to be visible but |
||
3233 | /// isn't, and suggest a module import that would resolve the problem. |
||
3234 | void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl, |
||
3235 | MissingImportKind MIK, bool Recover = true); |
||
3236 | void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl, |
||
3237 | SourceLocation DeclLoc, ArrayRef<Module *> Modules, |
||
3238 | MissingImportKind MIK, bool Recover); |
||
3239 | |||
3240 | Decl *ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, |
||
3241 | SourceLocation LBraceLoc); |
||
3242 | Decl *ActOnFinishExportDecl(Scope *S, Decl *ExportDecl, |
||
3243 | SourceLocation RBraceLoc); |
||
3244 | |||
3245 | /// We've found a use of a templated declaration that would trigger an |
||
3246 | /// implicit instantiation. Check that any relevant explicit specializations |
||
3247 | /// and partial specializations are visible/reachable, and diagnose if not. |
||
3248 | void checkSpecializationVisibility(SourceLocation Loc, NamedDecl *Spec); |
||
3249 | void checkSpecializationReachability(SourceLocation Loc, NamedDecl *Spec); |
||
3250 | |||
3251 | /// Retrieve a suitable printing policy for diagnostics. |
||
3252 | PrintingPolicy getPrintingPolicy() const { |
||
3253 | return getPrintingPolicy(Context, PP); |
||
3254 | } |
||
3255 | |||
3256 | /// Retrieve a suitable printing policy for diagnostics. |
||
3257 | static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx, |
||
3258 | const Preprocessor &PP); |
||
3259 | |||
3260 | /// Scope actions. |
||
3261 | void ActOnPopScope(SourceLocation Loc, Scope *S); |
||
3262 | void ActOnTranslationUnitScope(Scope *S); |
||
3263 | |||
3264 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
||
3265 | const ParsedAttributesView &DeclAttrs, |
||
3266 | RecordDecl *&AnonRecord); |
||
3267 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
||
3268 | const ParsedAttributesView &DeclAttrs, |
||
3269 | MultiTemplateParamsArg TemplateParams, |
||
3270 | bool IsExplicitInstantiation, |
||
3271 | RecordDecl *&AnonRecord); |
||
3272 | |||
3273 | Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, |
||
3274 | AccessSpecifier AS, |
||
3275 | RecordDecl *Record, |
||
3276 | const PrintingPolicy &Policy); |
||
3277 | |||
3278 | Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, |
||
3279 | RecordDecl *Record); |
||
3280 | |||
3281 | /// Common ways to introduce type names without a tag for use in diagnostics. |
||
3282 | /// Keep in sync with err_tag_reference_non_tag. |
||
3283 | enum NonTagKind { |
||
3284 | NTK_NonStruct, |
||
3285 | NTK_NonClass, |
||
3286 | NTK_NonUnion, |
||
3287 | NTK_NonEnum, |
||
3288 | NTK_Typedef, |
||
3289 | NTK_TypeAlias, |
||
3290 | NTK_Template, |
||
3291 | NTK_TypeAliasTemplate, |
||
3292 | NTK_TemplateTemplateArgument, |
||
3293 | }; |
||
3294 | |||
3295 | /// Given a non-tag type declaration, returns an enum useful for indicating |
||
3296 | /// what kind of non-tag type this is. |
||
3297 | NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK); |
||
3298 | |||
3299 | bool isAcceptableTagRedeclaration(const TagDecl *Previous, |
||
3300 | TagTypeKind NewTag, bool isDefinition, |
||
3301 | SourceLocation NewTagLoc, |
||
3302 | const IdentifierInfo *Name); |
||
3303 | |||
3304 | enum TagUseKind { |
||
3305 | TUK_Reference, // Reference to a tag: 'struct foo *X;' |
||
3306 | TUK_Declaration, // Fwd decl of a tag: 'struct foo;' |
||
3307 | TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;' |
||
3308 | TUK_Friend // Friend declaration: 'friend struct foo;' |
||
3309 | }; |
||
3310 | |||
3311 | enum OffsetOfKind { |
||
3312 | // Not parsing a type within __builtin_offsetof. |
||
3313 | OOK_Outside, |
||
3314 | // Parsing a type within __builtin_offsetof. |
||
3315 | OOK_Builtin, |
||
3316 | // Parsing a type within macro "offsetof", defined in __buitin_offsetof |
||
3317 | // To improve our diagnostic message. |
||
3318 | OOK_Macro, |
||
3319 | }; |
||
3320 | |||
3321 | DeclResult ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, |
||
3322 | SourceLocation KWLoc, CXXScopeSpec &SS, |
||
3323 | IdentifierInfo *Name, SourceLocation NameLoc, |
||
3324 | const ParsedAttributesView &Attr, AccessSpecifier AS, |
||
3325 | SourceLocation ModulePrivateLoc, |
||
3326 | MultiTemplateParamsArg TemplateParameterLists, |
||
3327 | bool &OwnedDecl, bool &IsDependent, |
||
3328 | SourceLocation ScopedEnumKWLoc, |
||
3329 | bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, |
||
3330 | bool IsTypeSpecifier, bool IsTemplateParamOrArg, |
||
3331 | OffsetOfKind OOK, SkipBodyInfo *SkipBody = nullptr); |
||
3332 | |||
3333 | DeclResult ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, |
||
3334 | unsigned TagSpec, SourceLocation TagLoc, |
||
3335 | CXXScopeSpec &SS, IdentifierInfo *Name, |
||
3336 | SourceLocation NameLoc, |
||
3337 | const ParsedAttributesView &Attr, |
||
3338 | MultiTemplateParamsArg TempParamLists); |
||
3339 | |||
3340 | TypeResult ActOnDependentTag(Scope *S, |
||
3341 | unsigned TagSpec, |
||
3342 | TagUseKind TUK, |
||
3343 | const CXXScopeSpec &SS, |
||
3344 | IdentifierInfo *Name, |
||
3345 | SourceLocation TagLoc, |
||
3346 | SourceLocation NameLoc); |
||
3347 | |||
3348 | void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, |
||
3349 | IdentifierInfo *ClassName, |
||
3350 | SmallVectorImpl<Decl *> &Decls); |
||
3351 | Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, |
||
3352 | Declarator &D, Expr *BitfieldWidth); |
||
3353 | |||
3354 | FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, |
||
3355 | Declarator &D, Expr *BitfieldWidth, |
||
3356 | InClassInitStyle InitStyle, |
||
3357 | AccessSpecifier AS); |
||
3358 | MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD, |
||
3359 | SourceLocation DeclStart, Declarator &D, |
||
3360 | Expr *BitfieldWidth, |
||
3361 | InClassInitStyle InitStyle, |
||
3362 | AccessSpecifier AS, |
||
3363 | const ParsedAttr &MSPropertyAttr); |
||
3364 | |||
3365 | FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, |
||
3366 | TypeSourceInfo *TInfo, |
||
3367 | RecordDecl *Record, SourceLocation Loc, |
||
3368 | bool Mutable, Expr *BitfieldWidth, |
||
3369 | InClassInitStyle InitStyle, |
||
3370 | SourceLocation TSSL, |
||
3371 | AccessSpecifier AS, NamedDecl *PrevDecl, |
||
3372 | Declarator *D = nullptr); |
||
3373 | |||
3374 | bool CheckNontrivialField(FieldDecl *FD); |
||
3375 | void DiagnoseNontrivial(const CXXRecordDecl *Record, CXXSpecialMember CSM); |
||
3376 | |||
3377 | enum TrivialABIHandling { |
||
3378 | /// The triviality of a method unaffected by "trivial_abi". |
||
3379 | TAH_IgnoreTrivialABI, |
||
3380 | |||
3381 | /// The triviality of a method affected by "trivial_abi". |
||
3382 | TAH_ConsiderTrivialABI |
||
3383 | }; |
||
3384 | |||
3385 | bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM, |
||
3386 | TrivialABIHandling TAH = TAH_IgnoreTrivialABI, |
||
3387 | bool Diagnose = false); |
||
3388 | |||
3389 | /// For a defaulted function, the kind of defaulted function that it is. |
||
3390 | class DefaultedFunctionKind { |
||
3391 | CXXSpecialMember SpecialMember : 8; |
||
3392 | DefaultedComparisonKind Comparison : 8; |
||
3393 | |||
3394 | public: |
||
3395 | DefaultedFunctionKind() |
||
3396 | : SpecialMember(CXXInvalid), Comparison(DefaultedComparisonKind::None) { |
||
3397 | } |
||
3398 | DefaultedFunctionKind(CXXSpecialMember CSM) |
||
3399 | : SpecialMember(CSM), Comparison(DefaultedComparisonKind::None) {} |
||
3400 | DefaultedFunctionKind(DefaultedComparisonKind Comp) |
||
3401 | : SpecialMember(CXXInvalid), Comparison(Comp) {} |
||
3402 | |||
3403 | bool isSpecialMember() const { return SpecialMember != CXXInvalid; } |
||
3404 | bool isComparison() const { |
||
3405 | return Comparison != DefaultedComparisonKind::None; |
||
3406 | } |
||
3407 | |||
3408 | explicit operator bool() const { |
||
3409 | return isSpecialMember() || isComparison(); |
||
3410 | } |
||
3411 | |||
3412 | CXXSpecialMember asSpecialMember() const { return SpecialMember; } |
||
3413 | DefaultedComparisonKind asComparison() const { return Comparison; } |
||
3414 | |||
3415 | /// Get the index of this function kind for use in diagnostics. |
||
3416 | unsigned getDiagnosticIndex() const { |
||
3417 | static_assert(CXXInvalid > CXXDestructor, |
||
3418 | "invalid should have highest index"); |
||
3419 | static_assert((unsigned)DefaultedComparisonKind::None == 0, |
||
3420 | "none should be equal to zero"); |
||
3421 | return SpecialMember + (unsigned)Comparison; |
||
3422 | } |
||
3423 | }; |
||
3424 | |||
3425 | DefaultedFunctionKind getDefaultedFunctionKind(const FunctionDecl *FD); |
||
3426 | |||
3427 | CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD) { |
||
3428 | return getDefaultedFunctionKind(MD).asSpecialMember(); |
||
3429 | } |
||
3430 | DefaultedComparisonKind getDefaultedComparisonKind(const FunctionDecl *FD) { |
||
3431 | return getDefaultedFunctionKind(FD).asComparison(); |
||
3432 | } |
||
3433 | |||
3434 | void ActOnLastBitfield(SourceLocation DeclStart, |
||
3435 | SmallVectorImpl<Decl *> &AllIvarDecls); |
||
3436 | Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, |
||
3437 | Declarator &D, Expr *BitfieldWidth, |
||
3438 | tok::ObjCKeywordKind visibility); |
||
3439 | |||
3440 | // This is used for both record definitions and ObjC interface declarations. |
||
3441 | void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, |
||
3442 | ArrayRef<Decl *> Fields, SourceLocation LBrac, |
||
3443 | SourceLocation RBrac, const ParsedAttributesView &AttrList); |
||
3444 | |||
3445 | /// ActOnTagStartDefinition - Invoked when we have entered the |
||
3446 | /// scope of a tag's definition (e.g., for an enumeration, class, |
||
3447 | /// struct, or union). |
||
3448 | void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); |
||
3449 | |||
3450 | /// Perform ODR-like check for C/ObjC when merging tag types from modules. |
||
3451 | /// Differently from C++, actually parse the body and reject / error out |
||
3452 | /// in case of a structural mismatch. |
||
3453 | bool ActOnDuplicateDefinition(Decl *Prev, SkipBodyInfo &SkipBody); |
||
3454 | |||
3455 | /// Check ODR hashes for C/ObjC when merging types from modules. |
||
3456 | /// Differently from C++, actually parse the body and reject in case |
||
3457 | /// of a mismatch. |
||
3458 | template <typename T, |
||
3459 | typename = std::enable_if_t<std::is_base_of<NamedDecl, T>::value>> |
||
3460 | bool ActOnDuplicateODRHashDefinition(T *Duplicate, T *Previous) { |
||
3461 | if (Duplicate->getODRHash() != Previous->getODRHash()) |
||
3462 | return false; |
||
3463 | |||
3464 | // Make the previous decl visible. |
||
3465 | makeMergedDefinitionVisible(Previous); |
||
3466 | return true; |
||
3467 | } |
||
3468 | |||
3469 | typedef void *SkippedDefinitionContext; |
||
3470 | |||
3471 | /// Invoked when we enter a tag definition that we're skipping. |
||
3472 | SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD); |
||
3473 | |||
3474 | void ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl); |
||
3475 | |||
3476 | /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a |
||
3477 | /// C++ record definition's base-specifiers clause and are starting its |
||
3478 | /// member declarations. |
||
3479 | void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, |
||
3480 | SourceLocation FinalLoc, |
||
3481 | bool IsFinalSpelledSealed, |
||
3482 | bool IsAbstract, |
||
3483 | SourceLocation LBraceLoc); |
||
3484 | |||
3485 | /// ActOnTagFinishDefinition - Invoked once we have finished parsing |
||
3486 | /// the definition of a tag (enumeration, class, struct, or union). |
||
3487 | void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, |
||
3488 | SourceRange BraceRange); |
||
3489 | |||
3490 | void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context); |
||
3491 | |||
3492 | void ActOnObjCContainerFinishDefinition(); |
||
3493 | |||
3494 | /// Invoked when we must temporarily exit the objective-c container |
||
3495 | /// scope for parsing/looking-up C constructs. |
||
3496 | /// |
||
3497 | /// Must be followed by a call to \see ActOnObjCReenterContainerContext |
||
3498 | void ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx); |
||
3499 | void ActOnObjCReenterContainerContext(ObjCContainerDecl *ObjCCtx); |
||
3500 | |||
3501 | /// ActOnTagDefinitionError - Invoked when there was an unrecoverable |
||
3502 | /// error parsing the definition of a tag. |
||
3503 | void ActOnTagDefinitionError(Scope *S, Decl *TagDecl); |
||
3504 | |||
3505 | EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, |
||
3506 | EnumConstantDecl *LastEnumConst, |
||
3507 | SourceLocation IdLoc, |
||
3508 | IdentifierInfo *Id, |
||
3509 | Expr *val); |
||
3510 | bool CheckEnumUnderlyingType(TypeSourceInfo *TI); |
||
3511 | bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, |
||
3512 | QualType EnumUnderlyingTy, bool IsFixed, |
||
3513 | const EnumDecl *Prev); |
||
3514 | |||
3515 | /// Determine whether the body of an anonymous enumeration should be skipped. |
||
3516 | /// \param II The name of the first enumerator. |
||
3517 | SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, |
||
3518 | SourceLocation IILoc); |
||
3519 | |||
3520 | Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, |
||
3521 | SourceLocation IdLoc, IdentifierInfo *Id, |
||
3522 | const ParsedAttributesView &Attrs, |
||
3523 | SourceLocation EqualLoc, Expr *Val); |
||
3524 | void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, |
||
3525 | Decl *EnumDecl, ArrayRef<Decl *> Elements, Scope *S, |
||
3526 | const ParsedAttributesView &Attr); |
||
3527 | |||
3528 | /// Set the current declaration context until it gets popped. |
||
3529 | void PushDeclContext(Scope *S, DeclContext *DC); |
||
3530 | void PopDeclContext(); |
||
3531 | |||
3532 | /// EnterDeclaratorContext - Used when we must lookup names in the context |
||
3533 | /// of a declarator's nested name specifier. |
||
3534 | void EnterDeclaratorContext(Scope *S, DeclContext *DC); |
||
3535 | void ExitDeclaratorContext(Scope *S); |
||
3536 | |||
3537 | /// Enter a template parameter scope, after it's been associated with a particular |
||
3538 | /// DeclContext. Causes lookup within the scope to chain through enclosing contexts |
||
3539 | /// in the correct order. |
||
3540 | void EnterTemplatedContext(Scope *S, DeclContext *DC); |
||
3541 | |||
3542 | /// Push the parameters of D, which must be a function, into scope. |
||
3543 | void ActOnReenterFunctionContext(Scope* S, Decl* D); |
||
3544 | void ActOnExitFunctionContext(); |
||
3545 | |||
3546 | /// If \p AllowLambda is true, treat lambda as function. |
||
3547 | DeclContext *getFunctionLevelDeclContext(bool AllowLambda = false); |
||
3548 | |||
3549 | /// Returns a pointer to the innermost enclosing function, or nullptr if the |
||
3550 | /// current context is not inside a function. If \p AllowLambda is true, |
||
3551 | /// this can return the call operator of an enclosing lambda, otherwise |
||
3552 | /// lambdas are skipped when looking for an enclosing function. |
||
3553 | FunctionDecl *getCurFunctionDecl(bool AllowLambda = false); |
||
3554 | |||
3555 | /// getCurMethodDecl - If inside of a method body, this returns a pointer to |
||
3556 | /// the method decl for the method being parsed. If we're currently |
||
3557 | /// in a 'block', this returns the containing context. |
||
3558 | ObjCMethodDecl *getCurMethodDecl(); |
||
3559 | |||
3560 | /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method |
||
3561 | /// or C function we're in, otherwise return null. If we're currently |
||
3562 | /// in a 'block', this returns the containing context. |
||
3563 | NamedDecl *getCurFunctionOrMethodDecl(); |
||
3564 | |||
3565 | /// Add this decl to the scope shadowed decl chains. |
||
3566 | void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true); |
||
3567 | |||
3568 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
||
3569 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
||
3570 | /// true if 'D' belongs to the given declaration context. |
||
3571 | /// |
||
3572 | /// \param AllowInlineNamespace If \c true, allow the declaration to be in the |
||
3573 | /// enclosing namespace set of the context, rather than contained |
||
3574 | /// directly within it. |
||
3575 | bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr, |
||
3576 | bool AllowInlineNamespace = false); |
||
3577 | |||
3578 | /// Finds the scope corresponding to the given decl context, if it |
||
3579 | /// happens to be an enclosing scope. Otherwise return NULL. |
||
3580 | static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC); |
||
3581 | |||
3582 | /// Subroutines of ActOnDeclarator(). |
||
3583 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, |
||
3584 | TypeSourceInfo *TInfo); |
||
3585 | bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New); |
||
3586 | |||
3587 | /// Describes the kind of merge to perform for availability |
||
3588 | /// attributes (including "deprecated", "unavailable", and "availability"). |
||
3589 | enum AvailabilityMergeKind { |
||
3590 | /// Don't merge availability attributes at all. |
||
3591 | AMK_None, |
||
3592 | /// Merge availability attributes for a redeclaration, which requires |
||
3593 | /// an exact match. |
||
3594 | AMK_Redeclaration, |
||
3595 | /// Merge availability attributes for an override, which requires |
||
3596 | /// an exact match or a weakening of constraints. |
||
3597 | AMK_Override, |
||
3598 | /// Merge availability attributes for an implementation of |
||
3599 | /// a protocol requirement. |
||
3600 | AMK_ProtocolImplementation, |
||
3601 | /// Merge availability attributes for an implementation of |
||
3602 | /// an optional protocol requirement. |
||
3603 | AMK_OptionalProtocolImplementation |
||
3604 | }; |
||
3605 | |||
3606 | /// Describes the kind of priority given to an availability attribute. |
||
3607 | /// |
||
3608 | /// The sum of priorities deteremines the final priority of the attribute. |
||
3609 | /// The final priority determines how the attribute will be merged. |
||
3610 | /// An attribute with a lower priority will always remove higher priority |
||
3611 | /// attributes for the specified platform when it is being applied. An |
||
3612 | /// attribute with a higher priority will not be applied if the declaration |
||
3613 | /// already has an availability attribute with a lower priority for the |
||
3614 | /// specified platform. The final prirority values are not expected to match |
||
3615 | /// the values in this enumeration, but instead should be treated as a plain |
||
3616 | /// integer value. This enumeration just names the priority weights that are |
||
3617 | /// used to calculate that final vaue. |
||
3618 | enum AvailabilityPriority : int { |
||
3619 | /// The availability attribute was specified explicitly next to the |
||
3620 | /// declaration. |
||
3621 | AP_Explicit = 0, |
||
3622 | |||
3623 | /// The availability attribute was applied using '#pragma clang attribute'. |
||
3624 | AP_PragmaClangAttribute = 1, |
||
3625 | |||
3626 | /// The availability attribute for a specific platform was inferred from |
||
3627 | /// an availability attribute for another platform. |
||
3628 | AP_InferredFromOtherPlatform = 2 |
||
3629 | }; |
||
3630 | |||
3631 | /// Attribute merging methods. Return true if a new attribute was added. |
||
3632 | AvailabilityAttr * |
||
3633 | mergeAvailabilityAttr(NamedDecl *D, const AttributeCommonInfo &CI, |
||
3634 | IdentifierInfo *Platform, bool Implicit, |
||
3635 | VersionTuple Introduced, VersionTuple Deprecated, |
||
3636 | VersionTuple Obsoleted, bool IsUnavailable, |
||
3637 | StringRef Message, bool IsStrict, StringRef Replacement, |
||
3638 | AvailabilityMergeKind AMK, int Priority); |
||
3639 | TypeVisibilityAttr * |
||
3640 | mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
||
3641 | TypeVisibilityAttr::VisibilityType Vis); |
||
3642 | VisibilityAttr *mergeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
||
3643 | VisibilityAttr::VisibilityType Vis); |
||
3644 | UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI, |
||
3645 | StringRef UuidAsWritten, MSGuidDecl *GuidDecl); |
||
3646 | DLLImportAttr *mergeDLLImportAttr(Decl *D, const AttributeCommonInfo &CI); |
||
3647 | DLLExportAttr *mergeDLLExportAttr(Decl *D, const AttributeCommonInfo &CI); |
||
3648 | MSInheritanceAttr *mergeMSInheritanceAttr(Decl *D, |
||
3649 | const AttributeCommonInfo &CI, |
||
3650 | bool BestCase, |
||
3651 | MSInheritanceModel Model); |
||
3652 | ErrorAttr *mergeErrorAttr(Decl *D, const AttributeCommonInfo &CI, |
||
3653 | StringRef NewUserDiagnostic); |
||
3654 | FormatAttr *mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI, |
||
3655 | IdentifierInfo *Format, int FormatIdx, |
||
3656 | int FirstArg); |
||
3657 | SectionAttr *mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI, |
||
3658 | StringRef Name); |
||
3659 | CodeSegAttr *mergeCodeSegAttr(Decl *D, const AttributeCommonInfo &CI, |
||
3660 | StringRef Name); |
||
3661 | AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, |
||
3662 | const AttributeCommonInfo &CI, |
||
3663 | const IdentifierInfo *Ident); |
||
3664 | MinSizeAttr *mergeMinSizeAttr(Decl *D, const AttributeCommonInfo &CI); |
||
3665 | SwiftNameAttr *mergeSwiftNameAttr(Decl *D, const SwiftNameAttr &SNA, |
||
3666 | StringRef Name); |
||
3667 | OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, |
||
3668 | const AttributeCommonInfo &CI); |
||
3669 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL); |
||
3670 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, |
||
3671 | const InternalLinkageAttr &AL); |
||
3672 | WebAssemblyImportNameAttr *mergeImportNameAttr( |
||
3673 | Decl *D, const WebAssemblyImportNameAttr &AL); |
||
3674 | WebAssemblyImportModuleAttr *mergeImportModuleAttr( |
||
3675 | Decl *D, const WebAssemblyImportModuleAttr &AL); |
||
3676 | EnforceTCBAttr *mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL); |
||
3677 | EnforceTCBLeafAttr *mergeEnforceTCBLeafAttr(Decl *D, |
||
3678 | const EnforceTCBLeafAttr &AL); |
||
3679 | BTFDeclTagAttr *mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL); |
||
3680 | HLSLNumThreadsAttr *mergeHLSLNumThreadsAttr(Decl *D, |
||
3681 | const AttributeCommonInfo &AL, |
||
3682 | int X, int Y, int Z); |
||
3683 | HLSLShaderAttr *mergeHLSLShaderAttr(Decl *D, const AttributeCommonInfo &AL, |
||
3684 | HLSLShaderAttr::ShaderType ShaderType); |
||
3685 | |||
3686 | void mergeDeclAttributes(NamedDecl *New, Decl *Old, |
||
3687 | AvailabilityMergeKind AMK = AMK_Redeclaration); |
||
3688 | void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, |
||
3689 | LookupResult &OldDecls); |
||
3690 | bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S, |
||
3691 | bool MergeTypeWithOld, bool NewDeclIsDefn); |
||
3692 | bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, |
||
3693 | Scope *S, bool MergeTypeWithOld); |
||
3694 | void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old); |
||
3695 | void MergeVarDecl(VarDecl *New, LookupResult &Previous); |
||
3696 | void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld); |
||
3697 | void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old); |
||
3698 | bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn); |
||
3699 | void notePreviousDefinition(const NamedDecl *Old, SourceLocation New); |
||
3700 | bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S); |
||
3701 | |||
3702 | // AssignmentAction - This is used by all the assignment diagnostic functions |
||
3703 | // to represent what is actually causing the operation |
||
3704 | enum AssignmentAction { |
||
3705 | AA_Assigning, |
||
3706 | AA_Passing, |
||
3707 | AA_Returning, |
||
3708 | AA_Converting, |
||
3709 | AA_Initializing, |
||
3710 | AA_Sending, |
||
3711 | AA_Casting, |
||
3712 | AA_Passing_CFAudited |
||
3713 | }; |
||
3714 | |||
3715 | /// C++ Overloading. |
||
3716 | enum OverloadKind { |
||
3717 | /// This is a legitimate overload: the existing declarations are |
||
3718 | /// functions or function templates with different signatures. |
||
3719 | Ovl_Overload, |
||
3720 | |||
3721 | /// This is not an overload because the signature exactly matches |
||
3722 | /// an existing declaration. |
||
3723 | Ovl_Match, |
||
3724 | |||
3725 | /// This is not an overload because the lookup results contain a |
||
3726 | /// non-function. |
||
3727 | Ovl_NonFunction |
||
3728 | }; |
||
3729 | OverloadKind CheckOverload(Scope *S, |
||
3730 | FunctionDecl *New, |
||
3731 | const LookupResult &OldDecls, |
||
3732 | NamedDecl *&OldDecl, |
||
3733 | bool UseMemberUsingDeclRules); |
||
3734 | bool IsOverload(FunctionDecl *New, FunctionDecl *Old, |
||
3735 | bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs = true, |
||
3736 | bool ConsiderRequiresClauses = true); |
||
3737 | |||
3738 | // Calculates whether the expression Constraint depends on an enclosing |
||
3739 | // template, for the purposes of [temp.friend] p9. |
||
3740 | // TemplateDepth is the 'depth' of the friend function, which is used to |
||
3741 | // compare whether a declaration reference is referring to a containing |
||
3742 | // template, or just the current friend function. A 'lower' TemplateDepth in |
||
3743 | // the AST refers to a 'containing' template. As the constraint is |
||
3744 | // uninstantiated, this is relative to the 'top' of the TU. |
||
3745 | bool |
||
3746 | ConstraintExpressionDependsOnEnclosingTemplate(const FunctionDecl *Friend, |
||
3747 | unsigned TemplateDepth, |
||
3748 | const Expr *Constraint); |
||
3749 | |||
3750 | // Calculates whether the friend function depends on an enclosing template for |
||
3751 | // the purposes of [temp.friend] p9. |
||
3752 | bool FriendConstraintsDependOnEnclosingTemplate(const FunctionDecl *FD); |
||
3753 | |||
3754 | // Calculates whether two constraint expressions are equal irrespective of a |
||
3755 | // difference in 'depth'. This takes a pair of optional 'NamedDecl's 'Old' and |
||
3756 | // 'New', which are the "source" of the constraint, since this is necessary |
||
3757 | // for figuring out the relative 'depth' of the constraint. The depth of the |
||
3758 | // 'primary template' and the 'instantiated from' templates aren't necessarily |
||
3759 | // the same, such as a case when one is a 'friend' defined in a class. |
||
3760 | bool AreConstraintExpressionsEqual(const NamedDecl *Old, |
||
3761 | const Expr *OldConstr, |
||
3762 | const NamedDecl *New, |
||
3763 | const Expr *NewConstr); |
||
3764 | |||
3765 | enum class AllowedExplicit { |
||
3766 | /// Allow no explicit functions to be used. |
||
3767 | None, |
||
3768 | /// Allow explicit conversion functions but not explicit constructors. |
||
3769 | Conversions, |
||
3770 | /// Allow both explicit conversion functions and explicit constructors. |
||
3771 | All |
||
3772 | }; |
||
3773 | |||
3774 | ImplicitConversionSequence |
||
3775 | TryImplicitConversion(Expr *From, QualType ToType, |
||
3776 | bool SuppressUserConversions, |
||
3777 | AllowedExplicit AllowExplicit, |
||
3778 | bool InOverloadResolution, |
||
3779 | bool CStyle, |
||
3780 | bool AllowObjCWritebackConversion); |
||
3781 | |||
3782 | bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); |
||
3783 | bool IsFloatingPointPromotion(QualType FromType, QualType ToType); |
||
3784 | bool IsComplexPromotion(QualType FromType, QualType ToType); |
||
3785 | bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, |
||
3786 | bool InOverloadResolution, |
||
3787 | QualType& ConvertedType, bool &IncompatibleObjC); |
||
3788 | bool isObjCPointerConversion(QualType FromType, QualType ToType, |
||
3789 | QualType& ConvertedType, bool &IncompatibleObjC); |
||
3790 | bool isObjCWritebackConversion(QualType FromType, QualType ToType, |
||
3791 | QualType &ConvertedType); |
||
3792 | bool IsBlockPointerConversion(QualType FromType, QualType ToType, |
||
3793 | QualType& ConvertedType); |
||
3794 | bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType, |
||
3795 | const FunctionProtoType *NewType, |
||
3796 | unsigned *ArgPos = nullptr, |
||
3797 | bool Reversed = false); |
||
3798 | void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, |
||
3799 | QualType FromType, QualType ToType); |
||
3800 | |||
3801 | void maybeExtendBlockObject(ExprResult &E); |
||
3802 | CastKind PrepareCastToObjCObjectPointer(ExprResult &E); |
||
3803 | bool CheckPointerConversion(Expr *From, QualType ToType, |
||
3804 | CastKind &Kind, |
||
3805 | CXXCastPath& BasePath, |
||
3806 | bool IgnoreBaseAccess, |
||
3807 | bool Diagnose = true); |
||
3808 | bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, |
||
3809 | bool InOverloadResolution, |
||
3810 | QualType &ConvertedType); |
||
3811 | bool CheckMemberPointerConversion(Expr *From, QualType ToType, |
||
3812 | CastKind &Kind, |
||
3813 | CXXCastPath &BasePath, |
||
3814 | bool IgnoreBaseAccess); |
||
3815 | bool IsQualificationConversion(QualType FromType, QualType ToType, |
||
3816 | bool CStyle, bool &ObjCLifetimeConversion); |
||
3817 | bool IsFunctionConversion(QualType FromType, QualType ToType, |
||
3818 | QualType &ResultTy); |
||
3819 | bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); |
||
3820 | bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg); |
||
3821 | |||
3822 | bool CanPerformAggregateInitializationForOverloadResolution( |
||
3823 | const InitializedEntity &Entity, InitListExpr *From); |
||
3824 | |||
3825 | bool IsStringInit(Expr *Init, const ArrayType *AT); |
||
3826 | |||
3827 | bool CanPerformCopyInitialization(const InitializedEntity &Entity, |
||
3828 | ExprResult Init); |
||
3829 | ExprResult PerformCopyInitialization(const InitializedEntity &Entity, |
||
3830 | SourceLocation EqualLoc, |
||
3831 | ExprResult Init, |
||
3832 | bool TopLevelOfInitList = false, |
||
3833 | bool AllowExplicit = false); |
||
3834 | ExprResult PerformObjectArgumentInitialization(Expr *From, |
||
3835 | NestedNameSpecifier *Qualifier, |
||
3836 | NamedDecl *FoundDecl, |
||
3837 | CXXMethodDecl *Method); |
||
3838 | |||
3839 | /// Check that the lifetime of the initializer (and its subobjects) is |
||
3840 | /// sufficient for initializing the entity, and perform lifetime extension |
||
3841 | /// (when permitted) if not. |
||
3842 | void checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init); |
||
3843 | |||
3844 | ExprResult PerformContextuallyConvertToBool(Expr *From); |
||
3845 | ExprResult PerformContextuallyConvertToObjCPointer(Expr *From); |
||
3846 | |||
3847 | /// Contexts in which a converted constant expression is required. |
||
3848 | enum CCEKind { |
||
3849 | CCEK_CaseValue, ///< Expression in a case label. |
||
3850 | CCEK_Enumerator, ///< Enumerator value with fixed underlying type. |
||
3851 | CCEK_TemplateArg, ///< Value of a non-type template parameter. |
||
3852 | CCEK_ArrayBound, ///< Array bound in array declarator or new-expression. |
||
3853 | CCEK_ExplicitBool, ///< Condition in an explicit(bool) specifier. |
||
3854 | CCEK_Noexcept ///< Condition in a noexcept(bool) specifier. |
||
3855 | }; |
||
3856 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
||
3857 | llvm::APSInt &Value, CCEKind CCE); |
||
3858 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
||
3859 | APValue &Value, CCEKind CCE, |
||
3860 | NamedDecl *Dest = nullptr); |
||
3861 | |||
3862 | /// Abstract base class used to perform a contextual implicit |
||
3863 | /// conversion from an expression to any type passing a filter. |
||
3864 | class ContextualImplicitConverter { |
||
3865 | public: |
||
3866 | bool Suppress; |
||
3867 | bool SuppressConversion; |
||
3868 | |||
3869 | ContextualImplicitConverter(bool Suppress = false, |
||
3870 | bool SuppressConversion = false) |
||
3871 | : Suppress(Suppress), SuppressConversion(SuppressConversion) {} |
||
3872 | |||
3873 | /// Determine whether the specified type is a valid destination type |
||
3874 | /// for this conversion. |
||
3875 | virtual bool match(QualType T) = 0; |
||
3876 | |||
3877 | /// Emits a diagnostic complaining that the expression does not have |
||
3878 | /// integral or enumeration type. |
||
3879 | virtual SemaDiagnosticBuilder |
||
3880 | diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) = 0; |
||
3881 | |||
3882 | /// Emits a diagnostic when the expression has incomplete class type. |
||
3883 | virtual SemaDiagnosticBuilder |
||
3884 | diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0; |
||
3885 | |||
3886 | /// Emits a diagnostic when the only matching conversion function |
||
3887 | /// is explicit. |
||
3888 | virtual SemaDiagnosticBuilder diagnoseExplicitConv( |
||
3889 | Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0; |
||
3890 | |||
3891 | /// Emits a note for the explicit conversion function. |
||
3892 | virtual SemaDiagnosticBuilder |
||
3893 | noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
||
3894 | |||
3895 | /// Emits a diagnostic when there are multiple possible conversion |
||
3896 | /// functions. |
||
3897 | virtual SemaDiagnosticBuilder |
||
3898 | diagnoseAmbiguous(Sema &S, SourceLocation Loc, QualType T) = 0; |
||
3899 | |||
3900 | /// Emits a note for one of the candidate conversions. |
||
3901 | virtual SemaDiagnosticBuilder |
||
3902 | noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
||
3903 | |||
3904 | /// Emits a diagnostic when we picked a conversion function |
||
3905 | /// (for cases when we are not allowed to pick a conversion function). |
||
3906 | virtual SemaDiagnosticBuilder diagnoseConversion( |
||
3907 | Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0; |
||
3908 | |||
3909 | virtual ~ContextualImplicitConverter() {} |
||
3910 | }; |
||
3911 | |||
3912 | class ICEConvertDiagnoser : public ContextualImplicitConverter { |
||
3913 | bool AllowScopedEnumerations; |
||
3914 | |||
3915 | public: |
||
3916 | ICEConvertDiagnoser(bool AllowScopedEnumerations, |
||
3917 | bool Suppress, bool SuppressConversion) |
||
3918 | : ContextualImplicitConverter(Suppress, SuppressConversion), |
||
3919 | AllowScopedEnumerations(AllowScopedEnumerations) {} |
||
3920 | |||
3921 | /// Match an integral or (possibly scoped) enumeration type. |
||
3922 | bool match(QualType T) override; |
||
3923 | |||
3924 | SemaDiagnosticBuilder |
||
3925 | diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) override { |
||
3926 | return diagnoseNotInt(S, Loc, T); |
||
3927 | } |
||
3928 | |||
3929 | /// Emits a diagnostic complaining that the expression does not have |
||
3930 | /// integral or enumeration type. |
||
3931 | virtual SemaDiagnosticBuilder |
||
3932 | diagnoseNotInt(Sema &S, SourceLocation Loc, QualType T) = 0; |
||
3933 | }; |
||
3934 | |||
3935 | /// Perform a contextual implicit conversion. |
||
3936 | ExprResult PerformContextualImplicitConversion( |
||
3937 | SourceLocation Loc, Expr *FromE, ContextualImplicitConverter &Converter); |
||
3938 | |||
3939 | |||
3940 | enum ObjCSubscriptKind { |
||
3941 | OS_Array, |
||
3942 | OS_Dictionary, |
||
3943 | OS_Error |
||
3944 | }; |
||
3945 | ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE); |
||
3946 | |||
3947 | // Note that LK_String is intentionally after the other literals, as |
||
3948 | // this is used for diagnostics logic. |
||
3949 | enum ObjCLiteralKind { |
||
3950 | LK_Array, |
||
3951 | LK_Dictionary, |
||
3952 | LK_Numeric, |
||
3953 | LK_Boxed, |
||
3954 | LK_String, |
||
3955 | LK_Block, |
||
3956 | LK_None |
||
3957 | }; |
||
3958 | ObjCLiteralKind CheckLiteralKind(Expr *FromE); |
||
3959 | |||
3960 | ExprResult PerformObjectMemberConversion(Expr *From, |
||
3961 | NestedNameSpecifier *Qualifier, |
||
3962 | NamedDecl *FoundDecl, |
||
3963 | NamedDecl *Member); |
||
3964 | |||
3965 | // Members have to be NamespaceDecl* or TranslationUnitDecl*. |
||
3966 | // TODO: make this is a typesafe union. |
||
3967 | typedef llvm::SmallSetVector<DeclContext *, 16> AssociatedNamespaceSet; |
||
3968 | typedef llvm::SmallSetVector<CXXRecordDecl *, 16> AssociatedClassSet; |
||
3969 | |||
3970 | using ADLCallKind = CallExpr::ADLCallKind; |
||
3971 | |||
3972 | void AddOverloadCandidate( |
||
3973 | FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef<Expr *> Args, |
||
3974 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
||
3975 | bool PartialOverloading = false, bool AllowExplicit = true, |
||
3976 | bool AllowExplicitConversion = false, |
||
3977 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
||
3978 | ConversionSequenceList EarlyConversions = std::nullopt, |
||
3979 | OverloadCandidateParamOrder PO = {}); |
||
3980 | void AddFunctionCandidates(const UnresolvedSetImpl &Functions, |
||
3981 | ArrayRef<Expr *> Args, |
||
3982 | OverloadCandidateSet &CandidateSet, |
||
3983 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
||
3984 | bool SuppressUserConversions = false, |
||
3985 | bool PartialOverloading = false, |
||
3986 | bool FirstArgumentIsBase = false); |
||
3987 | void AddMethodCandidate(DeclAccessPair FoundDecl, |
||
3988 | QualType ObjectType, |
||
3989 | Expr::Classification ObjectClassification, |
||
3990 | ArrayRef<Expr *> Args, |
||
3991 | OverloadCandidateSet& CandidateSet, |
||
3992 | bool SuppressUserConversion = false, |
||
3993 | OverloadCandidateParamOrder PO = {}); |
||
3994 | void |
||
3995 | AddMethodCandidate(CXXMethodDecl *Method, DeclAccessPair FoundDecl, |
||
3996 | CXXRecordDecl *ActingContext, QualType ObjectType, |
||
3997 | Expr::Classification ObjectClassification, |
||
3998 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, |
||
3999 | bool SuppressUserConversions = false, |
||
4000 | bool PartialOverloading = false, |
||
4001 | ConversionSequenceList EarlyConversions = std::nullopt, |
||
4002 | OverloadCandidateParamOrder PO = {}); |
||
4003 | void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, |
||
4004 | DeclAccessPair FoundDecl, |
||
4005 | CXXRecordDecl *ActingContext, |
||
4006 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
||
4007 | QualType ObjectType, |
||
4008 | Expr::Classification ObjectClassification, |
||
4009 | ArrayRef<Expr *> Args, |
||
4010 | OverloadCandidateSet& CandidateSet, |
||
4011 | bool SuppressUserConversions = false, |
||
4012 | bool PartialOverloading = false, |
||
4013 | OverloadCandidateParamOrder PO = {}); |
||
4014 | void AddTemplateOverloadCandidate( |
||
4015 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
||
4016 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
||
4017 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
||
4018 | bool PartialOverloading = false, bool AllowExplicit = true, |
||
4019 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
||
4020 | OverloadCandidateParamOrder PO = {}); |
||
4021 | bool CheckNonDependentConversions( |
||
4022 | FunctionTemplateDecl *FunctionTemplate, ArrayRef<QualType> ParamTypes, |
||
4023 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, |
||
4024 | ConversionSequenceList &Conversions, bool SuppressUserConversions, |
||
4025 | CXXRecordDecl *ActingContext = nullptr, QualType ObjectType = QualType(), |
||
4026 | Expr::Classification ObjectClassification = {}, |
||
4027 | OverloadCandidateParamOrder PO = {}); |
||
4028 | void AddConversionCandidate( |
||
4029 | CXXConversionDecl *Conversion, DeclAccessPair FoundDecl, |
||
4030 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
||
4031 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
||
4032 | bool AllowExplicit, bool AllowResultConversion = true); |
||
4033 | void AddTemplateConversionCandidate( |
||
4034 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
||
4035 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
||
4036 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
||
4037 | bool AllowExplicit, bool AllowResultConversion = true); |
||
4038 | void AddSurrogateCandidate(CXXConversionDecl *Conversion, |
||
4039 | DeclAccessPair FoundDecl, |
||
4040 | CXXRecordDecl *ActingContext, |
||
4041 | const FunctionProtoType *Proto, |
||
4042 | Expr *Object, ArrayRef<Expr *> Args, |
||
4043 | OverloadCandidateSet& CandidateSet); |
||
4044 | void AddNonMemberOperatorCandidates( |
||
4045 | const UnresolvedSetImpl &Functions, ArrayRef<Expr *> Args, |
||
4046 | OverloadCandidateSet &CandidateSet, |
||
4047 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
||
4048 | void AddMemberOperatorCandidates(OverloadedOperatorKind Op, |
||
4049 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
||
4050 | OverloadCandidateSet &CandidateSet, |
||
4051 | OverloadCandidateParamOrder PO = {}); |
||
4052 | void AddBuiltinCandidate(QualType *ParamTys, ArrayRef<Expr *> Args, |
||
4053 | OverloadCandidateSet& CandidateSet, |
||
4054 | bool IsAssignmentOperator = false, |
||
4055 | unsigned NumContextualBoolArguments = 0); |
||
4056 | void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, |
||
4057 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
||
4058 | OverloadCandidateSet& CandidateSet); |
||
4059 | void AddArgumentDependentLookupCandidates(DeclarationName Name, |
||
4060 | SourceLocation Loc, |
||
4061 | ArrayRef<Expr *> Args, |
||
4062 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
||
4063 | OverloadCandidateSet& CandidateSet, |
||
4064 | bool PartialOverloading = false); |
||
4065 | |||
4066 | // Emit as a 'note' the specific overload candidate |
||
4067 | void NoteOverloadCandidate( |
||
4068 | NamedDecl *Found, FunctionDecl *Fn, |
||
4069 | OverloadCandidateRewriteKind RewriteKind = OverloadCandidateRewriteKind(), |
||
4070 | QualType DestType = QualType(), bool TakingAddress = false); |
||
4071 | |||
4072 | // Emit as a series of 'note's all template and non-templates identified by |
||
4073 | // the expression Expr |
||
4074 | void NoteAllOverloadCandidates(Expr *E, QualType DestType = QualType(), |
||
4075 | bool TakingAddress = false); |
||
4076 | |||
4077 | /// Check the enable_if expressions on the given function. Returns the first |
||
4078 | /// failing attribute, or NULL if they were all successful. |
||
4079 | EnableIfAttr *CheckEnableIf(FunctionDecl *Function, SourceLocation CallLoc, |
||
4080 | ArrayRef<Expr *> Args, |
||
4081 | bool MissingImplicitThis = false); |
||
4082 | |||
4083 | /// Find the failed Boolean condition within a given Boolean |
||
4084 | /// constant expression, and describe it with a string. |
||
4085 | std::pair<Expr *, std::string> findFailedBooleanCondition(Expr *Cond); |
||
4086 | |||
4087 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
||
4088 | /// non-ArgDependent DiagnoseIfAttrs. |
||
4089 | /// |
||
4090 | /// Argument-dependent diagnose_if attributes should be checked each time a |
||
4091 | /// function is used as a direct callee of a function call. |
||
4092 | /// |
||
4093 | /// Returns true if any errors were emitted. |
||
4094 | bool diagnoseArgDependentDiagnoseIfAttrs(const FunctionDecl *Function, |
||
4095 | const Expr *ThisArg, |
||
4096 | ArrayRef<const Expr *> Args, |
||
4097 | SourceLocation Loc); |
||
4098 | |||
4099 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
||
4100 | /// ArgDependent DiagnoseIfAttrs. |
||
4101 | /// |
||
4102 | /// Argument-independent diagnose_if attributes should be checked on every use |
||
4103 | /// of a function. |
||
4104 | /// |
||
4105 | /// Returns true if any errors were emitted. |
||
4106 | bool diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND, |
||
4107 | SourceLocation Loc); |
||
4108 | |||
4109 | /// Returns whether the given function's address can be taken or not, |
||
4110 | /// optionally emitting a diagnostic if the address can't be taken. |
||
4111 | /// |
||
4112 | /// Returns false if taking the address of the function is illegal. |
||
4113 | bool checkAddressOfFunctionIsAvailable(const FunctionDecl *Function, |
||
4114 | bool Complain = false, |
||
4115 | SourceLocation Loc = SourceLocation()); |
||
4116 | |||
4117 | // [PossiblyAFunctionType] --> [Return] |
||
4118 | // NonFunctionType --> NonFunctionType |
||
4119 | // R (A) --> R(A) |
||
4120 | // R (*)(A) --> R (A) |
||
4121 | // R (&)(A) --> R (A) |
||
4122 | // R (S::*)(A) --> R (A) |
||
4123 | QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType); |
||
4124 | |||
4125 | FunctionDecl * |
||
4126 | ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, |
||
4127 | QualType TargetType, |
||
4128 | bool Complain, |
||
4129 | DeclAccessPair &Found, |
||
4130 | bool *pHadMultipleCandidates = nullptr); |
||
4131 | |||
4132 | FunctionDecl * |
||
4133 | resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &FoundResult); |
||
4134 | |||
4135 | bool resolveAndFixAddressOfSingleOverloadCandidate( |
||
4136 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false); |
||
4137 | |||
4138 | FunctionDecl * |
||
4139 | ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, |
||
4140 | bool Complain = false, |
||
4141 | DeclAccessPair *Found = nullptr); |
||
4142 | |||
4143 | bool ResolveAndFixSingleFunctionTemplateSpecialization( |
||
4144 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false, |
||
4145 | bool Complain = false, SourceRange OpRangeForComplaining = SourceRange(), |
||
4146 | QualType DestTypeForComplaining = QualType(), |
||
4147 | unsigned DiagIDForComplaining = 0); |
||
4148 | |||
4149 | Expr *FixOverloadedFunctionReference(Expr *E, |
||
4150 | DeclAccessPair FoundDecl, |
||
4151 | FunctionDecl *Fn); |
||
4152 | ExprResult FixOverloadedFunctionReference(ExprResult, |
||
4153 | DeclAccessPair FoundDecl, |
||
4154 | FunctionDecl *Fn); |
||
4155 | |||
4156 | void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, |
||
4157 | ArrayRef<Expr *> Args, |
||
4158 | OverloadCandidateSet &CandidateSet, |
||
4159 | bool PartialOverloading = false); |
||
4160 | void AddOverloadedCallCandidates( |
||
4161 | LookupResult &R, TemplateArgumentListInfo *ExplicitTemplateArgs, |
||
4162 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet); |
||
4163 | |||
4164 | // An enum used to represent the different possible results of building a |
||
4165 | // range-based for loop. |
||
4166 | enum ForRangeStatus { |
||
4167 | FRS_Success, |
||
4168 | FRS_NoViableFunction, |
||
4169 | FRS_DiagnosticIssued |
||
4170 | }; |
||
4171 | |||
4172 | ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc, |
||
4173 | SourceLocation RangeLoc, |
||
4174 | const DeclarationNameInfo &NameInfo, |
||
4175 | LookupResult &MemberLookup, |
||
4176 | OverloadCandidateSet *CandidateSet, |
||
4177 | Expr *Range, ExprResult *CallExpr); |
||
4178 | |||
4179 | ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn, |
||
4180 | UnresolvedLookupExpr *ULE, |
||
4181 | SourceLocation LParenLoc, |
||
4182 | MultiExprArg Args, |
||
4183 | SourceLocation RParenLoc, |
||
4184 | Expr *ExecConfig, |
||
4185 | bool AllowTypoCorrection=true, |
||
4186 | bool CalleesAddressIsTaken=false); |
||
4187 | |||
4188 | bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, |
||
4189 | MultiExprArg Args, SourceLocation RParenLoc, |
||
4190 | OverloadCandidateSet *CandidateSet, |
||
4191 | ExprResult *Result); |
||
4192 | |||
4193 | ExprResult CreateUnresolvedLookupExpr(CXXRecordDecl *NamingClass, |
||
4194 | NestedNameSpecifierLoc NNSLoc, |
||
4195 | DeclarationNameInfo DNI, |
||
4196 | const UnresolvedSetImpl &Fns, |
||
4197 | bool PerformADL = true); |
||
4198 | |||
4199 | ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, |
||
4200 | UnaryOperatorKind Opc, |
||
4201 | const UnresolvedSetImpl &Fns, |
||
4202 | Expr *input, bool RequiresADL = true); |
||
4203 | |||
4204 | void LookupOverloadedBinOp(OverloadCandidateSet &CandidateSet, |
||
4205 | OverloadedOperatorKind Op, |
||
4206 | const UnresolvedSetImpl &Fns, |
||
4207 | ArrayRef<Expr *> Args, bool RequiresADL = true); |
||
4208 | ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, |
||
4209 | BinaryOperatorKind Opc, |
||
4210 | const UnresolvedSetImpl &Fns, |
||
4211 | Expr *LHS, Expr *RHS, |
||
4212 | bool RequiresADL = true, |
||
4213 | bool AllowRewrittenCandidates = true, |
||
4214 | FunctionDecl *DefaultedFn = nullptr); |
||
4215 | ExprResult BuildSynthesizedThreeWayComparison(SourceLocation OpLoc, |
||
4216 | const UnresolvedSetImpl &Fns, |
||
4217 | Expr *LHS, Expr *RHS, |
||
4218 | FunctionDecl *DefaultedFn); |
||
4219 | |||
4220 | ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, |
||
4221 | SourceLocation RLoc, Expr *Base, |
||
4222 | MultiExprArg Args); |
||
4223 | |||
4224 | ExprResult BuildCallToMemberFunction(Scope *S, Expr *MemExpr, |
||
4225 | SourceLocation LParenLoc, |
||
4226 | MultiExprArg Args, |
||
4227 | SourceLocation RParenLoc, |
||
4228 | Expr *ExecConfig = nullptr, |
||
4229 | bool IsExecConfig = false, |
||
4230 | bool AllowRecovery = false); |
||
4231 | ExprResult |
||
4232 | BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, |
||
4233 | MultiExprArg Args, |
||
4234 | SourceLocation RParenLoc); |
||
4235 | |||
4236 | ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, |
||
4237 | SourceLocation OpLoc, |
||
4238 | bool *NoArrowOperatorFound = nullptr); |
||
4239 | |||
4240 | /// CheckCallReturnType - Checks that a call expression's return type is |
||
4241 | /// complete. Returns true on failure. The location passed in is the location |
||
4242 | /// that best represents the call. |
||
4243 | bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, |
||
4244 | CallExpr *CE, FunctionDecl *FD); |
||
4245 | |||
4246 | /// Helpers for dealing with blocks and functions. |
||
4247 | bool CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters, |
||
4248 | bool CheckParameterNames); |
||
4249 | void CheckCXXDefaultArguments(FunctionDecl *FD); |
||
4250 | void CheckExtraCXXDefaultArguments(Declarator &D); |
||
4251 | Scope *getNonFieldDeclScope(Scope *S); |
||
4252 | |||
4253 | /// \name Name lookup |
||
4254 | /// |
||
4255 | /// These routines provide name lookup that is used during semantic |
||
4256 | /// analysis to resolve the various kinds of names (identifiers, |
||
4257 | /// overloaded operator names, constructor names, etc.) into zero or |
||
4258 | /// more declarations within a particular scope. The major entry |
||
4259 | /// points are LookupName, which performs unqualified name lookup, |
||
4260 | /// and LookupQualifiedName, which performs qualified name lookup. |
||
4261 | /// |
||
4262 | /// All name lookup is performed based on some specific criteria, |
||
4263 | /// which specify what names will be visible to name lookup and how |
||
4264 | /// far name lookup should work. These criteria are important both |
||
4265 | /// for capturing language semantics (certain lookups will ignore |
||
4266 | /// certain names, for example) and for performance, since name |
||
4267 | /// lookup is often a bottleneck in the compilation of C++. Name |
||
4268 | /// lookup criteria is specified via the LookupCriteria enumeration. |
||
4269 | /// |
||
4270 | /// The results of name lookup can vary based on the kind of name |
||
4271 | /// lookup performed, the current language, and the translation |
||
4272 | /// unit. In C, for example, name lookup will either return nothing |
||
4273 | /// (no entity found) or a single declaration. In C++, name lookup |
||
4274 | /// can additionally refer to a set of overloaded functions or |
||
4275 | /// result in an ambiguity. All of the possible results of name |
||
4276 | /// lookup are captured by the LookupResult class, which provides |
||
4277 | /// the ability to distinguish among them. |
||
4278 | //@{ |
||
4279 | |||
4280 | /// Describes the kind of name lookup to perform. |
||
4281 | enum LookupNameKind { |
||
4282 | /// Ordinary name lookup, which finds ordinary names (functions, |
||
4283 | /// variables, typedefs, etc.) in C and most kinds of names |
||
4284 | /// (functions, variables, members, types, etc.) in C++. |
||
4285 | LookupOrdinaryName = 0, |
||
4286 | /// Tag name lookup, which finds the names of enums, classes, |
||
4287 | /// structs, and unions. |
||
4288 | LookupTagName, |
||
4289 | /// Label name lookup. |
||
4290 | LookupLabel, |
||
4291 | /// Member name lookup, which finds the names of |
||
4292 | /// class/struct/union members. |
||
4293 | LookupMemberName, |
||
4294 | /// Look up of an operator name (e.g., operator+) for use with |
||
4295 | /// operator overloading. This lookup is similar to ordinary name |
||
4296 | /// lookup, but will ignore any declarations that are class members. |
||
4297 | LookupOperatorName, |
||
4298 | /// Look up a name following ~ in a destructor name. This is an ordinary |
||
4299 | /// lookup, but prefers tags to typedefs. |
||
4300 | LookupDestructorName, |
||
4301 | /// Look up of a name that precedes the '::' scope resolution |
||
4302 | /// operator in C++. This lookup completely ignores operator, object, |
||
4303 | /// function, and enumerator names (C++ [basic.lookup.qual]p1). |
||
4304 | LookupNestedNameSpecifierName, |
||
4305 | /// Look up a namespace name within a C++ using directive or |
||
4306 | /// namespace alias definition, ignoring non-namespace names (C++ |
||
4307 | /// [basic.lookup.udir]p1). |
||
4308 | LookupNamespaceName, |
||
4309 | /// Look up all declarations in a scope with the given name, |
||
4310 | /// including resolved using declarations. This is appropriate |
||
4311 | /// for checking redeclarations for a using declaration. |
||
4312 | LookupUsingDeclName, |
||
4313 | /// Look up an ordinary name that is going to be redeclared as a |
||
4314 | /// name with linkage. This lookup ignores any declarations that |
||
4315 | /// are outside of the current scope unless they have linkage. See |
||
4316 | /// C99 6.2.2p4-5 and C++ [basic.link]p6. |
||
4317 | LookupRedeclarationWithLinkage, |
||
4318 | /// Look up a friend of a local class. This lookup does not look |
||
4319 | /// outside the innermost non-class scope. See C++11 [class.friend]p11. |
||
4320 | LookupLocalFriendName, |
||
4321 | /// Look up the name of an Objective-C protocol. |
||
4322 | LookupObjCProtocolName, |
||
4323 | /// Look up implicit 'self' parameter of an objective-c method. |
||
4324 | LookupObjCImplicitSelfParam, |
||
4325 | /// Look up the name of an OpenMP user-defined reduction operation. |
||
4326 | LookupOMPReductionName, |
||
4327 | /// Look up the name of an OpenMP user-defined mapper. |
||
4328 | LookupOMPMapperName, |
||
4329 | /// Look up any declaration with any name. |
||
4330 | LookupAnyName |
||
4331 | }; |
||
4332 | |||
4333 | /// Specifies whether (or how) name lookup is being performed for a |
||
4334 | /// redeclaration (vs. a reference). |
||
4335 | enum RedeclarationKind { |
||
4336 | /// The lookup is a reference to this name that is not for the |
||
4337 | /// purpose of redeclaring the name. |
||
4338 | NotForRedeclaration = 0, |
||
4339 | /// The lookup results will be used for redeclaration of a name, |
||
4340 | /// if an entity by that name already exists and is visible. |
||
4341 | ForVisibleRedeclaration, |
||
4342 | /// The lookup results will be used for redeclaration of a name |
||
4343 | /// with external linkage; non-visible lookup results with external linkage |
||
4344 | /// may also be found. |
||
4345 | ForExternalRedeclaration |
||
4346 | }; |
||
4347 | |||
4348 | RedeclarationKind forRedeclarationInCurContext() { |
||
4349 | // A declaration with an owning module for linkage can never link against |
||
4350 | // anything that is not visible. We don't need to check linkage here; if |
||
4351 | // the context has internal linkage, redeclaration lookup won't find things |
||
4352 | // from other TUs, and we can't safely compute linkage yet in general. |
||
4353 | if (cast<Decl>(CurContext) |
||
4354 | ->getOwningModuleForLinkage(/*IgnoreLinkage*/true)) |
||
4355 | return ForVisibleRedeclaration; |
||
4356 | return ForExternalRedeclaration; |
||
4357 | } |
||
4358 | |||
4359 | /// The possible outcomes of name lookup for a literal operator. |
||
4360 | enum LiteralOperatorLookupResult { |
||
4361 | /// The lookup resulted in an error. |
||
4362 | LOLR_Error, |
||
4363 | /// The lookup found no match but no diagnostic was issued. |
||
4364 | LOLR_ErrorNoDiagnostic, |
||
4365 | /// The lookup found a single 'cooked' literal operator, which |
||
4366 | /// expects a normal literal to be built and passed to it. |
||
4367 | LOLR_Cooked, |
||
4368 | /// The lookup found a single 'raw' literal operator, which expects |
||
4369 | /// a string literal containing the spelling of the literal token. |
||
4370 | LOLR_Raw, |
||
4371 | /// The lookup found an overload set of literal operator templates, |
||
4372 | /// which expect the characters of the spelling of the literal token to be |
||
4373 | /// passed as a non-type template argument pack. |
||
4374 | LOLR_Template, |
||
4375 | /// The lookup found an overload set of literal operator templates, |
||
4376 | /// which expect the character type and characters of the spelling of the |
||
4377 | /// string literal token to be passed as template arguments. |
||
4378 | LOLR_StringTemplatePack, |
||
4379 | }; |
||
4380 | |||
4381 | SpecialMemberOverloadResult LookupSpecialMember(CXXRecordDecl *D, |
||
4382 | CXXSpecialMember SM, |
||
4383 | bool ConstArg, |
||
4384 | bool VolatileArg, |
||
4385 | bool RValueThis, |
||
4386 | bool ConstThis, |
||
4387 | bool VolatileThis); |
||
4388 | |||
4389 | typedef std::function<void(const TypoCorrection &)> TypoDiagnosticGenerator; |
||
4390 | typedef std::function<ExprResult(Sema &, TypoExpr *, TypoCorrection)> |
||
4391 | TypoRecoveryCallback; |
||
4392 | |||
4393 | private: |
||
4394 | bool CppLookupName(LookupResult &R, Scope *S); |
||
4395 | |||
4396 | struct TypoExprState { |
||
4397 | std::unique_ptr<TypoCorrectionConsumer> Consumer; |
||
4398 | TypoDiagnosticGenerator DiagHandler; |
||
4399 | TypoRecoveryCallback RecoveryHandler; |
||
4400 | TypoExprState(); |
||
4401 | TypoExprState(TypoExprState &&other) noexcept; |
||
4402 | TypoExprState &operator=(TypoExprState &&other) noexcept; |
||
4403 | }; |
||
4404 | |||
4405 | /// The set of unhandled TypoExprs and their associated state. |
||
4406 | llvm::MapVector<TypoExpr *, TypoExprState> DelayedTypos; |
||
4407 | |||
4408 | /// Creates a new TypoExpr AST node. |
||
4409 | TypoExpr *createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC, |
||
4410 | TypoDiagnosticGenerator TDG, |
||
4411 | TypoRecoveryCallback TRC, SourceLocation TypoLoc); |
||
4412 | |||
4413 | // The set of known/encountered (unique, canonicalized) NamespaceDecls. |
||
4414 | // |
||
4415 | // The boolean value will be true to indicate that the namespace was loaded |
||
4416 | // from an AST/PCH file, or false otherwise. |
||
4417 | llvm::MapVector<NamespaceDecl*, bool> KnownNamespaces; |
||
4418 | |||
4419 | /// Whether we have already loaded known namespaces from an extenal |
||
4420 | /// source. |
||
4421 | bool LoadedExternalKnownNamespaces; |
||
4422 | |||
4423 | /// Helper for CorrectTypo and CorrectTypoDelayed used to create and |
||
4424 | /// populate a new TypoCorrectionConsumer. Returns nullptr if typo correction |
||
4425 | /// should be skipped entirely. |
||
4426 | std::unique_ptr<TypoCorrectionConsumer> |
||
4427 | makeTypoCorrectionConsumer(const DeclarationNameInfo &Typo, |
||
4428 | Sema::LookupNameKind LookupKind, Scope *S, |
||
4429 | CXXScopeSpec *SS, |
||
4430 | CorrectionCandidateCallback &CCC, |
||
4431 | DeclContext *MemberContext, bool EnteringContext, |
||
4432 | const ObjCObjectPointerType *OPT, |
||
4433 | bool ErrorRecovery); |
||
4434 | |||
4435 | public: |
||
4436 | const TypoExprState &getTypoExprState(TypoExpr *TE) const; |
||
4437 | |||
4438 | /// Clears the state of the given TypoExpr. |
||
4439 | void clearDelayedTypo(TypoExpr *TE); |
||
4440 | |||
4441 | /// Look up a name, looking for a single declaration. Return |
||
4442 | /// null if the results were absent, ambiguous, or overloaded. |
||
4443 | /// |
||
4444 | /// It is preferable to use the elaborated form and explicitly handle |
||
4445 | /// ambiguity and overloaded. |
||
4446 | NamedDecl *LookupSingleName(Scope *S, DeclarationName Name, |
||
4447 | SourceLocation Loc, |
||
4448 | LookupNameKind NameKind, |
||
4449 | RedeclarationKind Redecl |
||
4450 | = NotForRedeclaration); |
||
4451 | bool LookupBuiltin(LookupResult &R); |
||
4452 | void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID); |
||
4453 | bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation = false, |
||
4454 | bool ForceNoCPlusPlus = false); |
||
4455 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
||
4456 | bool InUnqualifiedLookup = false); |
||
4457 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
||
4458 | CXXScopeSpec &SS); |
||
4459 | bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, |
||
4460 | bool AllowBuiltinCreation = false, |
||
4461 | bool EnteringContext = false); |
||
4462 | ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, |
||
4463 | RedeclarationKind Redecl |
||
4464 | = NotForRedeclaration); |
||
4465 | bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class); |
||
4466 | |||
4467 | void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, |
||
4468 | UnresolvedSetImpl &Functions); |
||
4469 | |||
4470 | LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, |
||
4471 | SourceLocation GnuLabelLoc = SourceLocation()); |
||
4472 | |||
4473 | DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); |
||
4474 | CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class); |
||
4475 | CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class, |
||
4476 | unsigned Quals); |
||
4477 | CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, |
||
4478 | bool RValueThis, unsigned ThisQuals); |
||
4479 | CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class, |
||
4480 | unsigned Quals); |
||
4481 | CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals, |
||
4482 | bool RValueThis, unsigned ThisQuals); |
||
4483 | CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); |
||
4484 | |||
4485 | bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id, |
||
4486 | bool IsUDSuffix); |
||
4487 | LiteralOperatorLookupResult |
||
4488 | LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef<QualType> ArgTys, |
||
4489 | bool AllowRaw, bool AllowTemplate, |
||
4490 | bool AllowStringTemplate, bool DiagnoseMissing, |
||
4491 | StringLiteral *StringLit = nullptr); |
||
4492 | bool isKnownName(StringRef name); |
||
4493 | |||
4494 | /// Status of the function emission on the CUDA/HIP/OpenMP host/device attrs. |
||
4495 | enum class FunctionEmissionStatus { |
||
4496 | Emitted, |
||
4497 | CUDADiscarded, // Discarded due to CUDA/HIP hostness |
||
4498 | OMPDiscarded, // Discarded due to OpenMP hostness |
||
4499 | TemplateDiscarded, // Discarded due to uninstantiated templates |
||
4500 | Unknown, |
||
4501 | }; |
||
4502 | FunctionEmissionStatus getEmissionStatus(FunctionDecl *Decl, |
||
4503 | bool Final = false); |
||
4504 | |||
4505 | // Whether the callee should be ignored in CUDA/HIP/OpenMP host/device check. |
||
4506 | bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee); |
||
4507 | |||
4508 | void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc, |
||
4509 | ArrayRef<Expr *> Args, ADLResult &Functions); |
||
4510 | |||
4511 | void LookupVisibleDecls(Scope *S, LookupNameKind Kind, |
||
4512 | VisibleDeclConsumer &Consumer, |
||
4513 | bool IncludeGlobalScope = true, |
||
4514 | bool LoadExternal = true); |
||
4515 | void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, |
||
4516 | VisibleDeclConsumer &Consumer, |
||
4517 | bool IncludeGlobalScope = true, |
||
4518 | bool IncludeDependentBases = false, |
||
4519 | bool LoadExternal = true); |
||
4520 | |||
4521 | enum CorrectTypoKind { |
||
4522 | CTK_NonError, // CorrectTypo used in a non error recovery situation. |
||
4523 | CTK_ErrorRecovery // CorrectTypo used in normal error recovery. |
||
4524 | }; |
||
4525 | |||
4526 | TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, |
||
4527 | Sema::LookupNameKind LookupKind, |
||
4528 | Scope *S, CXXScopeSpec *SS, |
||
4529 | CorrectionCandidateCallback &CCC, |
||
4530 | CorrectTypoKind Mode, |
||
4531 | DeclContext *MemberContext = nullptr, |
||
4532 | bool EnteringContext = false, |
||
4533 | const ObjCObjectPointerType *OPT = nullptr, |
||
4534 | bool RecordFailure = true); |
||
4535 | |||
4536 | TypoExpr *CorrectTypoDelayed(const DeclarationNameInfo &Typo, |
||
4537 | Sema::LookupNameKind LookupKind, Scope *S, |
||
4538 | CXXScopeSpec *SS, |
||
4539 | CorrectionCandidateCallback &CCC, |
||
4540 | TypoDiagnosticGenerator TDG, |
||
4541 | TypoRecoveryCallback TRC, CorrectTypoKind Mode, |
||
4542 | DeclContext *MemberContext = nullptr, |
||
4543 | bool EnteringContext = false, |
||
4544 | const ObjCObjectPointerType *OPT = nullptr); |
||
4545 | |||
4546 | /// Process any TypoExprs in the given Expr and its children, |
||
4547 | /// generating diagnostics as appropriate and returning a new Expr if there |
||
4548 | /// were typos that were all successfully corrected and ExprError if one or |
||
4549 | /// more typos could not be corrected. |
||
4550 | /// |
||
4551 | /// \param E The Expr to check for TypoExprs. |
||
4552 | /// |
||
4553 | /// \param InitDecl A VarDecl to avoid because the Expr being corrected is its |
||
4554 | /// initializer. |
||
4555 | /// |
||
4556 | /// \param RecoverUncorrectedTypos If true, when typo correction fails, it |
||
4557 | /// will rebuild the given Expr with all TypoExprs degraded to RecoveryExprs. |
||
4558 | /// |
||
4559 | /// \param Filter A function applied to a newly rebuilt Expr to determine if |
||
4560 | /// it is an acceptable/usable result from a single combination of typo |
||
4561 | /// corrections. As long as the filter returns ExprError, different |
||
4562 | /// combinations of corrections will be tried until all are exhausted. |
||
4563 | ExprResult CorrectDelayedTyposInExpr( |
||
4564 | Expr *E, VarDecl *InitDecl = nullptr, |
||
4565 | bool RecoverUncorrectedTypos = false, |
||
4566 | llvm::function_ref<ExprResult(Expr *)> Filter = |
||
4567 | [](Expr *E) -> ExprResult { return E; }); |
||
4568 | |||
4569 | ExprResult CorrectDelayedTyposInExpr( |
||
4570 | ExprResult ER, VarDecl *InitDecl = nullptr, |
||
4571 | bool RecoverUncorrectedTypos = false, |
||
4572 | llvm::function_ref<ExprResult(Expr *)> Filter = |
||
4573 | [](Expr *E) -> ExprResult { return E; }) { |
||
4574 | return ER.isInvalid() |
||
4575 | ? ER |
||
4576 | : CorrectDelayedTyposInExpr(ER.get(), InitDecl, |
||
4577 | RecoverUncorrectedTypos, Filter); |
||
4578 | } |
||
4579 | |||
4580 | void diagnoseTypo(const TypoCorrection &Correction, |
||
4581 | const PartialDiagnostic &TypoDiag, |
||
4582 | bool ErrorRecovery = true); |
||
4583 | |||
4584 | void diagnoseTypo(const TypoCorrection &Correction, |
||
4585 | const PartialDiagnostic &TypoDiag, |
||
4586 | const PartialDiagnostic &PrevNote, |
||
4587 | bool ErrorRecovery = true); |
||
4588 | |||
4589 | void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F); |
||
4590 | |||
4591 | void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc, |
||
4592 | ArrayRef<Expr *> Args, |
||
4593 | AssociatedNamespaceSet &AssociatedNamespaces, |
||
4594 | AssociatedClassSet &AssociatedClasses); |
||
4595 | |||
4596 | void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, |
||
4597 | bool ConsiderLinkage, bool AllowInlineNamespace); |
||
4598 | |||
4599 | bool CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old); |
||
4600 | bool CheckRedeclarationExported(NamedDecl *New, NamedDecl *Old); |
||
4601 | bool CheckRedeclarationInModule(NamedDecl *New, NamedDecl *Old); |
||
4602 | bool IsRedefinitionInModule(const NamedDecl *New, |
||
4603 | const NamedDecl *Old) const; |
||
4604 | |||
4605 | void DiagnoseAmbiguousLookup(LookupResult &Result); |
||
4606 | //@} |
||
4607 | |||
4608 | /// Attempts to produce a RecoveryExpr after some AST node cannot be created. |
||
4609 | ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, |
||
4610 | ArrayRef<Expr *> SubExprs, |
||
4611 | QualType T = QualType()); |
||
4612 | |||
4613 | ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id, |
||
4614 | SourceLocation IdLoc, |
||
4615 | bool TypoCorrection = false); |
||
4616 | FunctionDecl *CreateBuiltin(IdentifierInfo *II, QualType Type, unsigned ID, |
||
4617 | SourceLocation Loc); |
||
4618 | NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, |
||
4619 | Scope *S, bool ForRedeclaration, |
||
4620 | SourceLocation Loc); |
||
4621 | NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
||
4622 | Scope *S); |
||
4623 | void AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction( |
||
4624 | FunctionDecl *FD); |
||
4625 | void AddKnownFunctionAttributes(FunctionDecl *FD); |
||
4626 | |||
4627 | // More parsing and symbol table subroutines. |
||
4628 | |||
4629 | void ProcessPragmaWeak(Scope *S, Decl *D); |
||
4630 | // Decl attributes - this routine is the top level dispatcher. |
||
4631 | void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD); |
||
4632 | // Helper for delayed processing of attributes. |
||
4633 | void ProcessDeclAttributeDelayed(Decl *D, |
||
4634 | const ParsedAttributesView &AttrList); |
||
4635 | |||
4636 | // Options for ProcessDeclAttributeList(). |
||
4637 | struct ProcessDeclAttributeOptions { |
||
4638 | ProcessDeclAttributeOptions() |
||
4639 | : IncludeCXX11Attributes(true), IgnoreTypeAttributes(false) {} |
||
4640 | |||
4641 | ProcessDeclAttributeOptions WithIncludeCXX11Attributes(bool Val) { |
||
4642 | ProcessDeclAttributeOptions Result = *this; |
||
4643 | Result.IncludeCXX11Attributes = Val; |
||
4644 | return Result; |
||
4645 | } |
||
4646 | |||
4647 | ProcessDeclAttributeOptions WithIgnoreTypeAttributes(bool Val) { |
||
4648 | ProcessDeclAttributeOptions Result = *this; |
||
4649 | Result.IgnoreTypeAttributes = Val; |
||
4650 | return Result; |
||
4651 | } |
||
4652 | |||
4653 | // Should C++11 attributes be processed? |
||
4654 | bool IncludeCXX11Attributes; |
||
4655 | |||
4656 | // Should any type attributes encountered be ignored? |
||
4657 | // If this option is false, a diagnostic will be emitted for any type |
||
4658 | // attributes of a kind that does not "slide" from the declaration to |
||
4659 | // the decl-specifier-seq. |
||
4660 | bool IgnoreTypeAttributes; |
||
4661 | }; |
||
4662 | |||
4663 | void ProcessDeclAttributeList(Scope *S, Decl *D, |
||
4664 | const ParsedAttributesView &AttrList, |
||
4665 | const ProcessDeclAttributeOptions &Options = |
||
4666 | ProcessDeclAttributeOptions()); |
||
4667 | bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, |
||
4668 | const ParsedAttributesView &AttrList); |
||
4669 | |||
4670 | void checkUnusedDeclAttributes(Declarator &D); |
||
4671 | |||
4672 | /// Handles semantic checking for features that are common to all attributes, |
||
4673 | /// such as checking whether a parameter was properly specified, or the |
||
4674 | /// correct number of arguments were passed, etc. Returns true if the |
||
4675 | /// attribute has been diagnosed. |
||
4676 | bool checkCommonAttributeFeatures(const Decl *D, const ParsedAttr &A, |
||
4677 | bool SkipArgCountCheck = false); |
||
4678 | bool checkCommonAttributeFeatures(const Stmt *S, const ParsedAttr &A, |
||
4679 | bool SkipArgCountCheck = false); |
||
4680 | |||
4681 | /// Determine if type T is a valid subject for a nonnull and similar |
||
4682 | /// attributes. By default, we look through references (the behavior used by |
||
4683 | /// nonnull), but if the second parameter is true, then we treat a reference |
||
4684 | /// type as valid. |
||
4685 | bool isValidPointerAttrType(QualType T, bool RefOkay = false); |
||
4686 | |||
4687 | bool CheckRegparmAttr(const ParsedAttr &attr, unsigned &value); |
||
4688 | bool CheckCallingConvAttr(const ParsedAttr &attr, CallingConv &CC, |
||
4689 | const FunctionDecl *FD = nullptr); |
||
4690 | bool CheckAttrTarget(const ParsedAttr &CurrAttr); |
||
4691 | bool CheckAttrNoArgs(const ParsedAttr &CurrAttr); |
||
4692 | bool checkStringLiteralArgumentAttr(const AttributeCommonInfo &CI, |
||
4693 | const Expr *E, StringRef &Str, |
||
4694 | SourceLocation *ArgLocation = nullptr); |
||
4695 | bool checkStringLiteralArgumentAttr(const ParsedAttr &Attr, unsigned ArgNum, |
||
4696 | StringRef &Str, |
||
4697 | SourceLocation *ArgLocation = nullptr); |
||
4698 | llvm::Error isValidSectionSpecifier(StringRef Str); |
||
4699 | bool checkSectionName(SourceLocation LiteralLoc, StringRef Str); |
||
4700 | bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str); |
||
4701 | bool checkTargetVersionAttr(SourceLocation LiteralLoc, StringRef &Str, |
||
4702 | bool &isDefault); |
||
4703 | bool |
||
4704 | checkTargetClonesAttrString(SourceLocation LiteralLoc, StringRef Str, |
||
4705 | const StringLiteral *Literal, bool &HasDefault, |
||
4706 | bool &HasCommas, bool &HasNotDefault, |
||
4707 | SmallVectorImpl<SmallString<64>> &StringsBuffer); |
||
4708 | bool checkMSInheritanceAttrOnDefinition( |
||
4709 | CXXRecordDecl *RD, SourceRange Range, bool BestCase, |
||
4710 | MSInheritanceModel SemanticSpelling); |
||
4711 | |||
4712 | void CheckAlignasUnderalignment(Decl *D); |
||
4713 | |||
4714 | /// Adjust the calling convention of a method to be the ABI default if it |
||
4715 | /// wasn't specified explicitly. This handles method types formed from |
||
4716 | /// function type typedefs and typename template arguments. |
||
4717 | void adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor, |
||
4718 | SourceLocation Loc); |
||
4719 | |||
4720 | // Check if there is an explicit attribute, but only look through parens. |
||
4721 | // The intent is to look for an attribute on the current declarator, but not |
||
4722 | // one that came from a typedef. |
||
4723 | bool hasExplicitCallingConv(QualType T); |
||
4724 | |||
4725 | /// Get the outermost AttributedType node that sets a calling convention. |
||
4726 | /// Valid types should not have multiple attributes with different CCs. |
||
4727 | const AttributedType *getCallingConvAttributedType(QualType T) const; |
||
4728 | |||
4729 | /// Process the attributes before creating an attributed statement. Returns |
||
4730 | /// the semantic attributes that have been processed. |
||
4731 | void ProcessStmtAttributes(Stmt *Stmt, const ParsedAttributes &InAttrs, |
||
4732 | SmallVectorImpl<const Attr *> &OutAttrs); |
||
4733 | |||
4734 | void WarnConflictingTypedMethods(ObjCMethodDecl *Method, |
||
4735 | ObjCMethodDecl *MethodDecl, |
||
4736 | bool IsProtocolMethodDecl); |
||
4737 | |||
4738 | void CheckConflictingOverridingMethod(ObjCMethodDecl *Method, |
||
4739 | ObjCMethodDecl *Overridden, |
||
4740 | bool IsProtocolMethodDecl); |
||
4741 | |||
4742 | /// WarnExactTypedMethods - This routine issues a warning if method |
||
4743 | /// implementation declaration matches exactly that of its declaration. |
||
4744 | void WarnExactTypedMethods(ObjCMethodDecl *Method, |
||
4745 | ObjCMethodDecl *MethodDecl, |
||
4746 | bool IsProtocolMethodDecl); |
||
4747 | |||
4748 | typedef llvm::SmallPtrSet<Selector, 8> SelectorSet; |
||
4749 | |||
4750 | /// CheckImplementationIvars - This routine checks if the instance variables |
||
4751 | /// listed in the implelementation match those listed in the interface. |
||
4752 | void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, |
||
4753 | ObjCIvarDecl **Fields, unsigned nIvars, |
||
4754 | SourceLocation Loc); |
||
4755 | |||
4756 | /// ImplMethodsVsClassMethods - This is main routine to warn if any method |
||
4757 | /// remains unimplemented in the class or category \@implementation. |
||
4758 | void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, |
||
4759 | ObjCContainerDecl* IDecl, |
||
4760 | bool IncompleteImpl = false); |
||
4761 | |||
4762 | /// DiagnoseUnimplementedProperties - This routine warns on those properties |
||
4763 | /// which must be implemented by this implementation. |
||
4764 | void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, |
||
4765 | ObjCContainerDecl *CDecl, |
||
4766 | bool SynthesizeProperties); |
||
4767 | |||
4768 | /// Diagnose any null-resettable synthesized setters. |
||
4769 | void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl); |
||
4770 | |||
4771 | /// DefaultSynthesizeProperties - This routine default synthesizes all |
||
4772 | /// properties which must be synthesized in the class's \@implementation. |
||
4773 | void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, |
||
4774 | ObjCInterfaceDecl *IDecl, |
||
4775 | SourceLocation AtEnd); |
||
4776 | void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd); |
||
4777 | |||
4778 | /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is |
||
4779 | /// an ivar synthesized for 'Method' and 'Method' is a property accessor |
||
4780 | /// declared in class 'IFace'. |
||
4781 | bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace, |
||
4782 | ObjCMethodDecl *Method, ObjCIvarDecl *IV); |
||
4783 | |||
4784 | /// DiagnoseUnusedBackingIvarInAccessor - Issue an 'unused' warning if ivar which |
||
4785 | /// backs the property is not used in the property's accessor. |
||
4786 | void DiagnoseUnusedBackingIvarInAccessor(Scope *S, |
||
4787 | const ObjCImplementationDecl *ImplD); |
||
4788 | |||
4789 | /// GetIvarBackingPropertyAccessor - If method is a property setter/getter and |
||
4790 | /// it property has a backing ivar, returns this ivar; otherwise, returns NULL. |
||
4791 | /// It also returns ivar's property on success. |
||
4792 | ObjCIvarDecl *GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method, |
||
4793 | const ObjCPropertyDecl *&PDecl) const; |
||
4794 | |||
4795 | /// Called by ActOnProperty to handle \@property declarations in |
||
4796 | /// class extensions. |
||
4797 | ObjCPropertyDecl *HandlePropertyInClassExtension(Scope *S, |
||
4798 | SourceLocation AtLoc, |
||
4799 | SourceLocation LParenLoc, |
||
4800 | FieldDeclarator &FD, |
||
4801 | Selector GetterSel, |
||
4802 | SourceLocation GetterNameLoc, |
||
4803 | Selector SetterSel, |
||
4804 | SourceLocation SetterNameLoc, |
||
4805 | const bool isReadWrite, |
||
4806 | unsigned &Attributes, |
||
4807 | const unsigned AttributesAsWritten, |
||
4808 | QualType T, |
||
4809 | TypeSourceInfo *TSI, |
||
4810 | tok::ObjCKeywordKind MethodImplKind); |
||
4811 | |||
4812 | /// Called by ActOnProperty and HandlePropertyInClassExtension to |
||
4813 | /// handle creating the ObjcPropertyDecl for a category or \@interface. |
||
4814 | ObjCPropertyDecl *CreatePropertyDecl(Scope *S, |
||
4815 | ObjCContainerDecl *CDecl, |
||
4816 | SourceLocation AtLoc, |
||
4817 | SourceLocation LParenLoc, |
||
4818 | FieldDeclarator &FD, |
||
4819 | Selector GetterSel, |
||
4820 | SourceLocation GetterNameLoc, |
||
4821 | Selector SetterSel, |
||
4822 | SourceLocation SetterNameLoc, |
||
4823 | const bool isReadWrite, |
||
4824 | const unsigned Attributes, |
||
4825 | const unsigned AttributesAsWritten, |
||
4826 | QualType T, |
||
4827 | TypeSourceInfo *TSI, |
||
4828 | tok::ObjCKeywordKind MethodImplKind, |
||
4829 | DeclContext *lexicalDC = nullptr); |
||
4830 | |||
4831 | /// AtomicPropertySetterGetterRules - This routine enforces the rule (via |
||
4832 | /// warning) when atomic property has one but not the other user-declared |
||
4833 | /// setter or getter. |
||
4834 | void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl, |
||
4835 | ObjCInterfaceDecl* IDecl); |
||
4836 | |||
4837 | void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D); |
||
4838 | |||
4839 | void DiagnoseMissingDesignatedInitOverrides( |
||
4840 | const ObjCImplementationDecl *ImplD, |
||
4841 | const ObjCInterfaceDecl *IFD); |
||
4842 | |||
4843 | void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); |
||
4844 | |||
4845 | enum MethodMatchStrategy { |
||
4846 | MMS_loose, |
||
4847 | MMS_strict |
||
4848 | }; |
||
4849 | |||
4850 | /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns |
||
4851 | /// true, or false, accordingly. |
||
4852 | bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, |
||
4853 | const ObjCMethodDecl *PrevMethod, |
||
4854 | MethodMatchStrategy strategy = MMS_strict); |
||
4855 | |||
4856 | /// MatchAllMethodDeclarations - Check methods declaraed in interface or |
||
4857 | /// or protocol against those declared in their implementations. |
||
4858 | void MatchAllMethodDeclarations(const SelectorSet &InsMap, |
||
4859 | const SelectorSet &ClsMap, |
||
4860 | SelectorSet &InsMapSeen, |
||
4861 | SelectorSet &ClsMapSeen, |
||
4862 | ObjCImplDecl* IMPDecl, |
||
4863 | ObjCContainerDecl* IDecl, |
||
4864 | bool &IncompleteImpl, |
||
4865 | bool ImmediateClass, |
||
4866 | bool WarnCategoryMethodImpl=false); |
||
4867 | |||
4868 | /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in |
||
4869 | /// category matches with those implemented in its primary class and |
||
4870 | /// warns each time an exact match is found. |
||
4871 | void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP); |
||
4872 | |||
4873 | /// Add the given method to the list of globally-known methods. |
||
4874 | void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method); |
||
4875 | |||
4876 | /// Returns default addr space for method qualifiers. |
||
4877 | LangAS getDefaultCXXMethodAddrSpace() const; |
||
4878 | |||
4879 | private: |
||
4880 | /// AddMethodToGlobalPool - Add an instance or factory method to the global |
||
4881 | /// pool. See descriptoin of AddInstanceMethodToGlobalPool. |
||
4882 | void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); |
||
4883 | |||
4884 | /// LookupMethodInGlobalPool - Returns the instance or factory method and |
||
4885 | /// optionally warns if there are multiple signatures. |
||
4886 | ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, |
||
4887 | bool receiverIdOrClass, |
||
4888 | bool instance); |
||
4889 | |||
4890 | public: |
||
4891 | /// - Returns instance or factory methods in global method pool for |
||
4892 | /// given selector. It checks the desired kind first, if none is found, and |
||
4893 | /// parameter checkTheOther is set, it then checks the other kind. If no such |
||
4894 | /// method or only one method is found, function returns false; otherwise, it |
||
4895 | /// returns true. |
||
4896 | bool |
||
4897 | CollectMultipleMethodsInGlobalPool(Selector Sel, |
||
4898 | SmallVectorImpl<ObjCMethodDecl*>& Methods, |
||
4899 | bool InstanceFirst, bool CheckTheOther, |
||
4900 | const ObjCObjectType *TypeBound = nullptr); |
||
4901 | |||
4902 | bool |
||
4903 | AreMultipleMethodsInGlobalPool(Selector Sel, ObjCMethodDecl *BestMethod, |
||
4904 | SourceRange R, bool receiverIdOrClass, |
||
4905 | SmallVectorImpl<ObjCMethodDecl*>& Methods); |
||
4906 | |||
4907 | void |
||
4908 | DiagnoseMultipleMethodInGlobalPool(SmallVectorImpl<ObjCMethodDecl*> &Methods, |
||
4909 | Selector Sel, SourceRange R, |
||
4910 | bool receiverIdOrClass); |
||
4911 | |||
4912 | private: |
||
4913 | /// - Returns a selector which best matches given argument list or |
||
4914 | /// nullptr if none could be found |
||
4915 | ObjCMethodDecl *SelectBestMethod(Selector Sel, MultiExprArg Args, |
||
4916 | bool IsInstance, |
||
4917 | SmallVectorImpl<ObjCMethodDecl*>& Methods); |
||
4918 | |||
4919 | |||
4920 | /// Record the typo correction failure and return an empty correction. |
||
4921 | TypoCorrection FailedCorrection(IdentifierInfo *Typo, SourceLocation TypoLoc, |
||
4922 | bool RecordFailure = true) { |
||
4923 | if (RecordFailure) |
||
4924 | TypoCorrectionFailures[Typo].insert(TypoLoc); |
||
4925 | return TypoCorrection(); |
||
4926 | } |
||
4927 | |||
4928 | public: |
||
4929 | /// AddInstanceMethodToGlobalPool - All instance methods in a translation |
||
4930 | /// unit are added to a global pool. This allows us to efficiently associate |
||
4931 | /// a selector with a method declaraation for purposes of typechecking |
||
4932 | /// messages sent to "id" (where the class of the object is unknown). |
||
4933 | void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { |
||
4934 | AddMethodToGlobalPool(Method, impl, /*instance*/true); |
||
4935 | } |
||
4936 | |||
4937 | /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. |
||
4938 | void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { |
||
4939 | AddMethodToGlobalPool(Method, impl, /*instance*/false); |
||
4940 | } |
||
4941 | |||
4942 | /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global |
||
4943 | /// pool. |
||
4944 | void AddAnyMethodToGlobalPool(Decl *D); |
||
4945 | |||
4946 | /// LookupInstanceMethodInGlobalPool - Returns the method and warns if |
||
4947 | /// there are multiple signatures. |
||
4948 | ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, |
||
4949 | bool receiverIdOrClass=false) { |
||
4950 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
||
4951 | /*instance*/true); |
||
4952 | } |
||
4953 | |||
4954 | /// LookupFactoryMethodInGlobalPool - Returns the method and warns if |
||
4955 | /// there are multiple signatures. |
||
4956 | ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, |
||
4957 | bool receiverIdOrClass=false) { |
||
4958 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
||
4959 | /*instance*/false); |
||
4960 | } |
||
4961 | |||
4962 | const ObjCMethodDecl *SelectorsForTypoCorrection(Selector Sel, |
||
4963 | QualType ObjectType=QualType()); |
||
4964 | /// LookupImplementedMethodInGlobalPool - Returns the method which has an |
||
4965 | /// implementation. |
||
4966 | ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); |
||
4967 | |||
4968 | /// CollectIvarsToConstructOrDestruct - Collect those ivars which require |
||
4969 | /// initialization. |
||
4970 | void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, |
||
4971 | SmallVectorImpl<ObjCIvarDecl*> &Ivars); |
||
4972 | |||
4973 | //===--------------------------------------------------------------------===// |
||
4974 | // Statement Parsing Callbacks: SemaStmt.cpp. |
||
4975 | public: |
||
4976 | class FullExprArg { |
||
4977 | public: |
||
4978 | FullExprArg() : E(nullptr) { } |
||
4979 | FullExprArg(Sema &actions) : E(nullptr) { } |
||
4980 | |||
4981 | ExprResult release() { |
||
4982 | return E; |
||
4983 | } |
||
4984 | |||
4985 | Expr *get() const { return E; } |
||
4986 | |||
4987 | Expr *operator->() { |
||
4988 | return E; |
||
4989 | } |
||
4990 | |||
4991 | private: |
||
4992 | // FIXME: No need to make the entire Sema class a friend when it's just |
||
4993 | // Sema::MakeFullExpr that needs access to the constructor below. |
||
4994 | friend class Sema; |
||
4995 | |||
4996 | explicit FullExprArg(Expr *expr) : E(expr) {} |
||
4997 | |||
4998 | Expr *E; |
||
4999 | }; |
||
5000 | |||
5001 | FullExprArg MakeFullExpr(Expr *Arg) { |
||
5002 | return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation()); |
||
5003 | } |
||
5004 | FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) { |
||
5005 | return FullExprArg( |
||
5006 | ActOnFinishFullExpr(Arg, CC, /*DiscardedValue*/ false).get()); |
||
5007 | } |
||
5008 | FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) { |
||
5009 | ExprResult FE = |
||
5010 | ActOnFinishFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation(), |
||
5011 | /*DiscardedValue*/ true); |
||
5012 | return FullExprArg(FE.get()); |
||
5013 | } |
||
5014 | |||
5015 | StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue = true); |
||
5016 | StmtResult ActOnExprStmtError(); |
||
5017 | |||
5018 | StmtResult ActOnNullStmt(SourceLocation SemiLoc, |
||
5019 | bool HasLeadingEmptyMacro = false); |
||
5020 | |||
5021 | void ActOnStartOfCompoundStmt(bool IsStmtExpr); |
||
5022 | void ActOnAfterCompoundStatementLeadingPragmas(); |
||
5023 | void ActOnFinishOfCompoundStmt(); |
||
5024 | StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
||
5025 | ArrayRef<Stmt *> Elts, bool isStmtExpr); |
||
5026 | |||
5027 | /// A RAII object to enter scope of a compound statement. |
||
5028 | class CompoundScopeRAII { |
||
5029 | public: |
||
5030 | CompoundScopeRAII(Sema &S, bool IsStmtExpr = false) : S(S) { |
||
5031 | S.ActOnStartOfCompoundStmt(IsStmtExpr); |
||
5032 | } |
||
5033 | |||
5034 | ~CompoundScopeRAII() { |
||
5035 | S.ActOnFinishOfCompoundStmt(); |
||
5036 | } |
||
5037 | |||
5038 | private: |
||
5039 | Sema &S; |
||
5040 | }; |
||
5041 | |||
5042 | /// An RAII helper that pops function a function scope on exit. |
||
5043 | struct FunctionScopeRAII { |
||
5044 | Sema &S; |
||
5045 | bool Active; |
||
5046 | FunctionScopeRAII(Sema &S) : S(S), Active(true) {} |
||
5047 | ~FunctionScopeRAII() { |
||
5048 | if (Active) |
||
5049 | S.PopFunctionScopeInfo(); |
||
5050 | } |
||
5051 | void disable() { Active = false; } |
||
5052 | }; |
||
5053 | |||
5054 | StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, |
||
5055 | SourceLocation StartLoc, |
||
5056 | SourceLocation EndLoc); |
||
5057 | void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); |
||
5058 | StmtResult ActOnForEachLValueExpr(Expr *E); |
||
5059 | ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val); |
||
5060 | StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, |
||
5061 | SourceLocation DotDotDotLoc, ExprResult RHS, |
||
5062 | SourceLocation ColonLoc); |
||
5063 | void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); |
||
5064 | |||
5065 | StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, |
||
5066 | SourceLocation ColonLoc, |
||
5067 | Stmt *SubStmt, Scope *CurScope); |
||
5068 | StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, |
||
5069 | SourceLocation ColonLoc, Stmt *SubStmt); |
||
5070 | |||
5071 | StmtResult BuildAttributedStmt(SourceLocation AttrsLoc, |
||
5072 | ArrayRef<const Attr *> Attrs, Stmt *SubStmt); |
||
5073 | StmtResult ActOnAttributedStmt(const ParsedAttributes &AttrList, |
||
5074 | Stmt *SubStmt); |
||
5075 | |||
5076 | class ConditionResult; |
||
5077 | |||
5078 | StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, |
||
5079 | SourceLocation LParenLoc, Stmt *InitStmt, |
||
5080 | ConditionResult Cond, SourceLocation RParenLoc, |
||
5081 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
||
5082 | StmtResult BuildIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, |
||
5083 | SourceLocation LParenLoc, Stmt *InitStmt, |
||
5084 | ConditionResult Cond, SourceLocation RParenLoc, |
||
5085 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
||
5086 | StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, |
||
5087 | SourceLocation LParenLoc, Stmt *InitStmt, |
||
5088 | ConditionResult Cond, |
||
5089 | SourceLocation RParenLoc); |
||
5090 | StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, |
||
5091 | Stmt *Switch, Stmt *Body); |
||
5092 | StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, |
||
5093 | ConditionResult Cond, SourceLocation RParenLoc, |
||
5094 | Stmt *Body); |
||
5095 | StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, |
||
5096 | SourceLocation WhileLoc, SourceLocation CondLParen, |
||
5097 | Expr *Cond, SourceLocation CondRParen); |
||
5098 | |||
5099 | StmtResult ActOnForStmt(SourceLocation ForLoc, |
||
5100 | SourceLocation LParenLoc, |
||
5101 | Stmt *First, |
||
5102 | ConditionResult Second, |
||
5103 | FullExprArg Third, |
||
5104 | SourceLocation RParenLoc, |
||
5105 | Stmt *Body); |
||
5106 | ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, |
||
5107 | Expr *collection); |
||
5108 | StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, |
||
5109 | Stmt *First, Expr *collection, |
||
5110 | SourceLocation RParenLoc); |
||
5111 | StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body); |
||
5112 | |||
5113 | enum BuildForRangeKind { |
||
5114 | /// Initial building of a for-range statement. |
||
5115 | BFRK_Build, |
||
5116 | /// Instantiation or recovery rebuild of a for-range statement. Don't |
||
5117 | /// attempt any typo-correction. |
||
5118 | BFRK_Rebuild, |
||
5119 | /// Determining whether a for-range statement could be built. Avoid any |
||
5120 | /// unnecessary or irreversible actions. |
||
5121 | BFRK_Check |
||
5122 | }; |
||
5123 | |||
5124 | StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc, |
||
5125 | SourceLocation CoawaitLoc, |
||
5126 | Stmt *InitStmt, |
||
5127 | Stmt *LoopVar, |
||
5128 | SourceLocation ColonLoc, Expr *Collection, |
||
5129 | SourceLocation RParenLoc, |
||
5130 | BuildForRangeKind Kind); |
||
5131 | StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, |
||
5132 | SourceLocation CoawaitLoc, |
||
5133 | Stmt *InitStmt, |
||
5134 | SourceLocation ColonLoc, |
||
5135 | Stmt *RangeDecl, Stmt *Begin, Stmt *End, |
||
5136 | Expr *Cond, Expr *Inc, |
||
5137 | Stmt *LoopVarDecl, |
||
5138 | SourceLocation RParenLoc, |
||
5139 | BuildForRangeKind Kind); |
||
5140 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body); |
||
5141 | |||
5142 | StmtResult ActOnGotoStmt(SourceLocation GotoLoc, |
||
5143 | SourceLocation LabelLoc, |
||
5144 | LabelDecl *TheDecl); |
||
5145 | StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, |
||
5146 | SourceLocation StarLoc, |
||
5147 | Expr *DestExp); |
||
5148 | StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope); |
||
5149 | StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope); |
||
5150 | |||
5151 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
||
5152 | CapturedRegionKind Kind, unsigned NumParams); |
||
5153 | typedef std::pair<StringRef, QualType> CapturedParamNameType; |
||
5154 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
||
5155 | CapturedRegionKind Kind, |
||
5156 | ArrayRef<CapturedParamNameType> Params, |
||
5157 | unsigned OpenMPCaptureLevel = 0); |
||
5158 | StmtResult ActOnCapturedRegionEnd(Stmt *S); |
||
5159 | void ActOnCapturedRegionError(); |
||
5160 | RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD, |
||
5161 | SourceLocation Loc, |
||
5162 | unsigned NumParams); |
||
5163 | |||
5164 | struct NamedReturnInfo { |
||
5165 | const VarDecl *Candidate; |
||
5166 | |||
5167 | enum Status : uint8_t { None, MoveEligible, MoveEligibleAndCopyElidable }; |
||
5168 | Status S; |
||
5169 | |||
5170 | bool isMoveEligible() const { return S != None; }; |
||
5171 | bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; } |
||
5172 | }; |
||
5173 | enum class SimplerImplicitMoveMode { ForceOff, Normal, ForceOn }; |
||
5174 | NamedReturnInfo getNamedReturnInfo( |
||
5175 | Expr *&E, SimplerImplicitMoveMode Mode = SimplerImplicitMoveMode::Normal); |
||
5176 | NamedReturnInfo getNamedReturnInfo(const VarDecl *VD); |
||
5177 | const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info, |
||
5178 | QualType ReturnType); |
||
5179 | |||
5180 | ExprResult |
||
5181 | PerformMoveOrCopyInitialization(const InitializedEntity &Entity, |
||
5182 | const NamedReturnInfo &NRInfo, Expr *Value, |
||
5183 | bool SupressSimplerImplicitMoves = false); |
||
5184 | |||
5185 | StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
||
5186 | Scope *CurScope); |
||
5187 | StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
||
5188 | bool AllowRecovery = false); |
||
5189 | StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
||
5190 | NamedReturnInfo &NRInfo, |
||
5191 | bool SupressSimplerImplicitMoves); |
||
5192 | |||
5193 | StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
||
5194 | bool IsVolatile, unsigned NumOutputs, |
||
5195 | unsigned NumInputs, IdentifierInfo **Names, |
||
5196 | MultiExprArg Constraints, MultiExprArg Exprs, |
||
5197 | Expr *AsmString, MultiExprArg Clobbers, |
||
5198 | unsigned NumLabels, |
||
5199 | SourceLocation RParenLoc); |
||
5200 | |||
5201 | void FillInlineAsmIdentifierInfo(Expr *Res, |
||
5202 | llvm::InlineAsmIdentifierInfo &Info); |
||
5203 | ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS, |
||
5204 | SourceLocation TemplateKWLoc, |
||
5205 | UnqualifiedId &Id, |
||
5206 | bool IsUnevaluatedContext); |
||
5207 | bool LookupInlineAsmField(StringRef Base, StringRef Member, |
||
5208 | unsigned &Offset, SourceLocation AsmLoc); |
||
5209 | ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member, |
||
5210 | SourceLocation AsmLoc); |
||
5211 | StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
||
5212 | ArrayRef<Token> AsmToks, |
||
5213 | StringRef AsmString, |
||
5214 | unsigned NumOutputs, unsigned NumInputs, |
||
5215 | ArrayRef<StringRef> Constraints, |
||
5216 | ArrayRef<StringRef> Clobbers, |
||
5217 | ArrayRef<Expr*> Exprs, |
||
5218 | SourceLocation EndLoc); |
||
5219 | LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName, |
||
5220 | SourceLocation Location, |
||
5221 | bool AlwaysCreate); |
||
5222 | |||
5223 | VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, |
||
5224 | SourceLocation StartLoc, |
||
5225 | SourceLocation IdLoc, IdentifierInfo *Id, |
||
5226 | bool Invalid = false); |
||
5227 | |||
5228 | Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); |
||
5229 | |||
5230 | StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, |
||
5231 | Decl *Parm, Stmt *Body); |
||
5232 | |||
5233 | StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); |
||
5234 | |||
5235 | StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, |
||
5236 | MultiStmtArg Catch, Stmt *Finally); |
||
5237 | |||
5238 | StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); |
||
5239 | StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, |
||
5240 | Scope *CurScope); |
||
5241 | ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, |
||
5242 | Expr *operand); |
||
5243 | StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, |
||
5244 | Expr *SynchExpr, |
||
5245 | Stmt *SynchBody); |
||
5246 | |||
5247 | StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body); |
||
5248 | |||
5249 | VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, |
||
5250 | SourceLocation StartLoc, |
||
5251 | SourceLocation IdLoc, |
||
5252 | IdentifierInfo *Id); |
||
5253 | |||
5254 | Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); |
||
5255 | |||
5256 | StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, |
||
5257 | Decl *ExDecl, Stmt *HandlerBlock); |
||
5258 | StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, |
||
5259 | ArrayRef<Stmt *> Handlers); |
||
5260 | |||
5261 | StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ? |
||
5262 | SourceLocation TryLoc, Stmt *TryBlock, |
||
5263 | Stmt *Handler); |
||
5264 | StmtResult ActOnSEHExceptBlock(SourceLocation Loc, |
||
5265 | Expr *FilterExpr, |
||
5266 | Stmt *Block); |
||
5267 | void ActOnStartSEHFinallyBlock(); |
||
5268 | void ActOnAbortSEHFinallyBlock(); |
||
5269 | StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block); |
||
5270 | StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope); |
||
5271 | |||
5272 | void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); |
||
5273 | |||
5274 | bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; |
||
5275 | |||
5276 | /// If it's a file scoped decl that must warn if not used, keep track |
||
5277 | /// of it. |
||
5278 | void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); |
||
5279 | |||
5280 | typedef llvm::function_ref<void(SourceLocation Loc, PartialDiagnostic PD)> |
||
5281 | DiagReceiverTy; |
||
5282 | |||
5283 | /// DiagnoseUnusedExprResult - If the statement passed in is an expression |
||
5284 | /// whose result is unused, warn. |
||
5285 | void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID); |
||
5286 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D); |
||
5287 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D, |
||
5288 | DiagReceiverTy DiagReceiver); |
||
5289 | void DiagnoseUnusedDecl(const NamedDecl *ND); |
||
5290 | void DiagnoseUnusedDecl(const NamedDecl *ND, DiagReceiverTy DiagReceiver); |
||
5291 | |||
5292 | /// If VD is set but not otherwise used, diagnose, for a parameter or a |
||
5293 | /// variable. |
||
5294 | void DiagnoseUnusedButSetDecl(const VarDecl *VD, DiagReceiverTy DiagReceiver); |
||
5295 | |||
5296 | /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null |
||
5297 | /// statement as a \p Body, and it is located on the same line. |
||
5298 | /// |
||
5299 | /// This helps prevent bugs due to typos, such as: |
||
5300 | /// if (condition); |
||
5301 | /// do_stuff(); |
||
5302 | void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, |
||
5303 | const Stmt *Body, |
||
5304 | unsigned DiagID); |
||
5305 | |||
5306 | /// Warn if a for/while loop statement \p S, which is followed by |
||
5307 | /// \p PossibleBody, has a suspicious null statement as a body. |
||
5308 | void DiagnoseEmptyLoopBody(const Stmt *S, |
||
5309 | const Stmt *PossibleBody); |
||
5310 | |||
5311 | /// Warn if a value is moved to itself. |
||
5312 | void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr, |
||
5313 | SourceLocation OpLoc); |
||
5314 | |||
5315 | /// Returns a field in a CXXRecordDecl that has the same name as the decl \p |
||
5316 | /// SelfAssigned when inside a CXXMethodDecl. |
||
5317 | const FieldDecl * |
||
5318 | getSelfAssignmentClassMemberCandidate(const ValueDecl *SelfAssigned); |
||
5319 | |||
5320 | /// Warn if we're implicitly casting from a _Nullable pointer type to a |
||
5321 | /// _Nonnull one. |
||
5322 | void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType, |
||
5323 | SourceLocation Loc); |
||
5324 | |||
5325 | /// Warn when implicitly casting 0 to nullptr. |
||
5326 | void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E); |
||
5327 | |||
5328 | ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) { |
||
5329 | return DelayedDiagnostics.push(pool); |
||
5330 | } |
||
5331 | void PopParsingDeclaration(ParsingDeclState state, Decl *decl); |
||
5332 | |||
5333 | typedef ProcessingContextState ParsingClassState; |
||
5334 | ParsingClassState PushParsingClass() { |
||
5335 | ParsingClassDepth++; |
||
5336 | return DelayedDiagnostics.pushUndelayed(); |
||
5337 | } |
||
5338 | void PopParsingClass(ParsingClassState state) { |
||
5339 | ParsingClassDepth--; |
||
5340 | DelayedDiagnostics.popUndelayed(state); |
||
5341 | } |
||
5342 | |||
5343 | void redelayDiagnostics(sema::DelayedDiagnosticPool &pool); |
||
5344 | |||
5345 | void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
||
5346 | const ObjCInterfaceDecl *UnknownObjCClass, |
||
5347 | bool ObjCPropertyAccess, |
||
5348 | bool AvoidPartialAvailabilityChecks = false, |
||
5349 | ObjCInterfaceDecl *ClassReceiver = nullptr); |
||
5350 | |||
5351 | bool makeUnavailableInSystemHeader(SourceLocation loc, |
||
5352 | UnavailableAttr::ImplicitReason reason); |
||
5353 | |||
5354 | /// Issue any -Wunguarded-availability warnings in \c FD |
||
5355 | void DiagnoseUnguardedAvailabilityViolations(Decl *FD); |
||
5356 | |||
5357 | void handleDelayedAvailabilityCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
||
5358 | |||
5359 | //===--------------------------------------------------------------------===// |
||
5360 | // Expression Parsing Callbacks: SemaExpr.cpp. |
||
5361 | |||
5362 | bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid); |
||
5363 | // A version of DiagnoseUseOfDecl that should be used if overload resolution |
||
5364 | // has been used to find this declaration, which means we don't have to bother |
||
5365 | // checking the trailing requires clause. |
||
5366 | bool DiagnoseUseOfOverloadedDecl(NamedDecl *D, SourceLocation Loc) { |
||
5367 | return DiagnoseUseOfDecl( |
||
5368 | D, Loc, /*UnknownObjCClass=*/nullptr, /*ObjCPropertyAccess=*/false, |
||
5369 | /*AvoidPartialAvailabilityChecks=*/false, /*ClassReceiver=*/nullptr, |
||
5370 | /*SkipTrailingRequiresClause=*/true); |
||
5371 | } |
||
5372 | |||
5373 | bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
||
5374 | const ObjCInterfaceDecl *UnknownObjCClass = nullptr, |
||
5375 | bool ObjCPropertyAccess = false, |
||
5376 | bool AvoidPartialAvailabilityChecks = false, |
||
5377 | ObjCInterfaceDecl *ClassReciever = nullptr, |
||
5378 | bool SkipTrailingRequiresClause = false); |
||
5379 | void NoteDeletedFunction(FunctionDecl *FD); |
||
5380 | void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD); |
||
5381 | bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, |
||
5382 | ObjCMethodDecl *Getter, |
||
5383 | SourceLocation Loc); |
||
5384 | void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, |
||
5385 | ArrayRef<Expr *> Args); |
||
5386 | |||
5387 | void PushExpressionEvaluationContext( |
||
5388 | ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl = nullptr, |
||
5389 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
||
5390 | ExpressionEvaluationContextRecord::EK_Other); |
||
5391 | enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl }; |
||
5392 | void PushExpressionEvaluationContext( |
||
5393 | ExpressionEvaluationContext NewContext, ReuseLambdaContextDecl_t, |
||
5394 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
||
5395 | ExpressionEvaluationContextRecord::EK_Other); |
||
5396 | void PopExpressionEvaluationContext(); |
||
5397 | |||
5398 | void DiscardCleanupsInEvaluationContext(); |
||
5399 | |||
5400 | ExprResult TransformToPotentiallyEvaluated(Expr *E); |
||
5401 | TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo); |
||
5402 | ExprResult HandleExprEvaluationContextForTypeof(Expr *E); |
||
5403 | |||
5404 | ExprResult CheckUnevaluatedOperand(Expr *E); |
||
5405 | void CheckUnusedVolatileAssignment(Expr *E); |
||
5406 | |||
5407 | ExprResult ActOnConstantExpression(ExprResult Res); |
||
5408 | |||
5409 | // Functions for marking a declaration referenced. These functions also |
||
5410 | // contain the relevant logic for marking if a reference to a function or |
||
5411 | // variable is an odr-use (in the C++11 sense). There are separate variants |
||
5412 | // for expressions referring to a decl; these exist because odr-use marking |
||
5413 | // needs to be delayed for some constant variables when we build one of the |
||
5414 | // named expressions. |
||
5415 | // |
||
5416 | // MightBeOdrUse indicates whether the use could possibly be an odr-use, and |
||
5417 | // should usually be true. This only needs to be set to false if the lack of |
||
5418 | // odr-use cannot be determined from the current context (for instance, |
||
5419 | // because the name denotes a virtual function and was written without an |
||
5420 | // explicit nested-name-specifier). |
||
5421 | void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse); |
||
5422 | void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, |
||
5423 | bool MightBeOdrUse = true); |
||
5424 | void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var); |
||
5425 | void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base = nullptr); |
||
5426 | void MarkMemberReferenced(MemberExpr *E); |
||
5427 | void MarkFunctionParmPackReferenced(FunctionParmPackExpr *E); |
||
5428 | void MarkCaptureUsedInEnclosingContext(ValueDecl *Capture, SourceLocation Loc, |
||
5429 | unsigned CapturingScopeIndex); |
||
5430 | |||
5431 | ExprResult CheckLValueToRValueConversionOperand(Expr *E); |
||
5432 | void CleanupVarDeclMarking(); |
||
5433 | |||
5434 | enum TryCaptureKind { |
||
5435 | TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef |
||
5436 | }; |
||
5437 | |||
5438 | /// Try to capture the given variable. |
||
5439 | /// |
||
5440 | /// \param Var The variable to capture. |
||
5441 | /// |
||
5442 | /// \param Loc The location at which the capture occurs. |
||
5443 | /// |
||
5444 | /// \param Kind The kind of capture, which may be implicit (for either a |
||
5445 | /// block or a lambda), or explicit by-value or by-reference (for a lambda). |
||
5446 | /// |
||
5447 | /// \param EllipsisLoc The location of the ellipsis, if one is provided in |
||
5448 | /// an explicit lambda capture. |
||
5449 | /// |
||
5450 | /// \param BuildAndDiagnose Whether we are actually supposed to add the |
||
5451 | /// captures or diagnose errors. If false, this routine merely check whether |
||
5452 | /// the capture can occur without performing the capture itself or complaining |
||
5453 | /// if the variable cannot be captured. |
||
5454 | /// |
||
5455 | /// \param CaptureType Will be set to the type of the field used to capture |
||
5456 | /// this variable in the innermost block or lambda. Only valid when the |
||
5457 | /// variable can be captured. |
||
5458 | /// |
||
5459 | /// \param DeclRefType Will be set to the type of a reference to the capture |
||
5460 | /// from within the current scope. Only valid when the variable can be |
||
5461 | /// captured. |
||
5462 | /// |
||
5463 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
||
5464 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
||
5465 | /// This is useful when enclosing lambdas must speculatively capture |
||
5466 | /// variables that may or may not be used in certain specializations of |
||
5467 | /// a nested generic lambda. |
||
5468 | /// |
||
5469 | /// \returns true if an error occurred (i.e., the variable cannot be |
||
5470 | /// captured) and false if the capture succeeded. |
||
5471 | bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, |
||
5472 | TryCaptureKind Kind, SourceLocation EllipsisLoc, |
||
5473 | bool BuildAndDiagnose, QualType &CaptureType, |
||
5474 | QualType &DeclRefType, |
||
5475 | const unsigned *const FunctionScopeIndexToStopAt); |
||
5476 | |||
5477 | /// Try to capture the given variable. |
||
5478 | bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, |
||
5479 | TryCaptureKind Kind = TryCapture_Implicit, |
||
5480 | SourceLocation EllipsisLoc = SourceLocation()); |
||
5481 | |||
5482 | /// Checks if the variable must be captured. |
||
5483 | bool NeedToCaptureVariable(ValueDecl *Var, SourceLocation Loc); |
||
5484 | |||
5485 | /// Given a variable, determine the type that a reference to that |
||
5486 | /// variable will have in the given scope. |
||
5487 | QualType getCapturedDeclRefType(ValueDecl *Var, SourceLocation Loc); |
||
5488 | |||
5489 | /// Mark all of the declarations referenced within a particular AST node as |
||
5490 | /// referenced. Used when template instantiation instantiates a non-dependent |
||
5491 | /// type -- entities referenced by the type are now referenced. |
||
5492 | void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); |
||
5493 | void MarkDeclarationsReferencedInExpr( |
||
5494 | Expr *E, bool SkipLocalVariables = false, |
||
5495 | ArrayRef<const Expr *> StopAt = std::nullopt); |
||
5496 | |||
5497 | /// Try to recover by turning the given expression into a |
||
5498 | /// call. Returns true if recovery was attempted or an error was |
||
5499 | /// emitted; this may also leave the ExprResult invalid. |
||
5500 | bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, |
||
5501 | bool ForceComplain = false, |
||
5502 | bool (*IsPlausibleResult)(QualType) = nullptr); |
||
5503 | |||
5504 | /// Figure out if an expression could be turned into a call. |
||
5505 | bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy, |
||
5506 | UnresolvedSetImpl &NonTemplateOverloads); |
||
5507 | |||
5508 | /// Try to convert an expression \p E to type \p Ty. Returns the result of the |
||
5509 | /// conversion. |
||
5510 | ExprResult tryConvertExprToType(Expr *E, QualType Ty); |
||
5511 | |||
5512 | /// Conditionally issue a diagnostic based on the statements's reachability |
||
5513 | /// analysis. |
||
5514 | /// |
||
5515 | /// \param Stmts If Stmts is non-empty, delay reporting the diagnostic until |
||
5516 | /// the function body is parsed, and then do a basic reachability analysis to |
||
5517 | /// determine if the statement is reachable. If it is unreachable, the |
||
5518 | /// diagnostic will not be emitted. |
||
5519 | bool DiagIfReachable(SourceLocation Loc, ArrayRef<const Stmt *> Stmts, |
||
5520 | const PartialDiagnostic &PD); |
||
5521 | |||
5522 | /// Conditionally issue a diagnostic based on the current |
||
5523 | /// evaluation context. |
||
5524 | /// |
||
5525 | /// \param Statement If Statement is non-null, delay reporting the |
||
5526 | /// diagnostic until the function body is parsed, and then do a basic |
||
5527 | /// reachability analysis to determine if the statement is reachable. |
||
5528 | /// If it is unreachable, the diagnostic will not be emitted. |
||
5529 | bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, |
||
5530 | const PartialDiagnostic &PD); |
||
5531 | /// Similar, but diagnostic is only produced if all the specified statements |
||
5532 | /// are reachable. |
||
5533 | bool DiagRuntimeBehavior(SourceLocation Loc, ArrayRef<const Stmt*> Stmts, |
||
5534 | const PartialDiagnostic &PD); |
||
5535 | |||
5536 | // Primary Expressions. |
||
5537 | SourceRange getExprRange(Expr *E) const; |
||
5538 | |||
5539 | ExprResult ActOnIdExpression( |
||
5540 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
||
5541 | UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand, |
||
5542 | CorrectionCandidateCallback *CCC = nullptr, |
||
5543 | bool IsInlineAsmIdentifier = false, Token *KeywordReplacement = nullptr); |
||
5544 | |||
5545 | void DecomposeUnqualifiedId(const UnqualifiedId &Id, |
||
5546 | TemplateArgumentListInfo &Buffer, |
||
5547 | DeclarationNameInfo &NameInfo, |
||
5548 | const TemplateArgumentListInfo *&TemplateArgs); |
||
5549 | |||
5550 | bool DiagnoseDependentMemberLookup(LookupResult &R); |
||
5551 | |||
5552 | bool |
||
5553 | DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, |
||
5554 | CorrectionCandidateCallback &CCC, |
||
5555 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
||
5556 | ArrayRef<Expr *> Args = std::nullopt, |
||
5557 | TypoExpr **Out = nullptr); |
||
5558 | |||
5559 | DeclResult LookupIvarInObjCMethod(LookupResult &Lookup, Scope *S, |
||
5560 | IdentifierInfo *II); |
||
5561 | ExprResult BuildIvarRefExpr(Scope *S, SourceLocation Loc, ObjCIvarDecl *IV); |
||
5562 | |||
5563 | ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S, |
||
5564 | IdentifierInfo *II, |
||
5565 | bool AllowBuiltinCreation=false); |
||
5566 | |||
5567 | ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, |
||
5568 | SourceLocation TemplateKWLoc, |
||
5569 | const DeclarationNameInfo &NameInfo, |
||
5570 | bool isAddressOfOperand, |
||
5571 | const TemplateArgumentListInfo *TemplateArgs); |
||
5572 | |||
5573 | /// If \p D cannot be odr-used in the current expression evaluation context, |
||
5574 | /// return a reason explaining why. Otherwise, return NOUR_None. |
||
5575 | NonOdrUseReason getNonOdrUseReasonInCurrentContext(ValueDecl *D); |
||
5576 | |||
5577 | DeclRefExpr *BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
||
5578 | SourceLocation Loc, |
||
5579 | const CXXScopeSpec *SS = nullptr); |
||
5580 | DeclRefExpr * |
||
5581 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
||
5582 | const DeclarationNameInfo &NameInfo, |
||
5583 | const CXXScopeSpec *SS = nullptr, |
||
5584 | NamedDecl *FoundD = nullptr, |
||
5585 | SourceLocation TemplateKWLoc = SourceLocation(), |
||
5586 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
||
5587 | DeclRefExpr * |
||
5588 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
||
5589 | const DeclarationNameInfo &NameInfo, |
||
5590 | NestedNameSpecifierLoc NNS, |
||
5591 | NamedDecl *FoundD = nullptr, |
||
5592 | SourceLocation TemplateKWLoc = SourceLocation(), |
||
5593 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
||
5594 | |||
5595 | ExprResult |
||
5596 | BuildAnonymousStructUnionMemberReference( |
||
5597 | const CXXScopeSpec &SS, |
||
5598 | SourceLocation nameLoc, |
||
5599 | IndirectFieldDecl *indirectField, |
||
5600 | DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_none), |
||
5601 | Expr *baseObjectExpr = nullptr, |
||
5602 | SourceLocation opLoc = SourceLocation()); |
||
5603 | |||
5604 | ExprResult BuildPossibleImplicitMemberExpr( |
||
5605 | const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, |
||
5606 | const TemplateArgumentListInfo *TemplateArgs, const Scope *S, |
||
5607 | UnresolvedLookupExpr *AsULE = nullptr); |
||
5608 | ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, |
||
5609 | SourceLocation TemplateKWLoc, |
||
5610 | LookupResult &R, |
||
5611 | const TemplateArgumentListInfo *TemplateArgs, |
||
5612 | bool IsDefiniteInstance, |
||
5613 | const Scope *S); |
||
5614 | bool UseArgumentDependentLookup(const CXXScopeSpec &SS, |
||
5615 | const LookupResult &R, |
||
5616 | bool HasTrailingLParen); |
||
5617 | |||
5618 | ExprResult |
||
5619 | BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, |
||
5620 | const DeclarationNameInfo &NameInfo, |
||
5621 | bool IsAddressOfOperand, const Scope *S, |
||
5622 | TypeSourceInfo **RecoveryTSI = nullptr); |
||
5623 | |||
5624 | ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS, |
||
5625 | SourceLocation TemplateKWLoc, |
||
5626 | const DeclarationNameInfo &NameInfo, |
||
5627 | const TemplateArgumentListInfo *TemplateArgs); |
||
5628 | |||
5629 | ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, |
||
5630 | LookupResult &R, |
||
5631 | bool NeedsADL, |
||
5632 | bool AcceptInvalidDecl = false); |
||
5633 | ExprResult BuildDeclarationNameExpr( |
||
5634 | const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D, |
||
5635 | NamedDecl *FoundD = nullptr, |
||
5636 | const TemplateArgumentListInfo *TemplateArgs = nullptr, |
||
5637 | bool AcceptInvalidDecl = false); |
||
5638 | |||
5639 | ExprResult BuildLiteralOperatorCall(LookupResult &R, |
||
5640 | DeclarationNameInfo &SuffixInfo, |
||
5641 | ArrayRef<Expr *> Args, |
||
5642 | SourceLocation LitEndLoc, |
||
5643 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
||
5644 | |||
5645 | ExprResult BuildPredefinedExpr(SourceLocation Loc, |
||
5646 | PredefinedExpr::IdentKind IK); |
||
5647 | ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); |
||
5648 | ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val); |
||
5649 | |||
5650 | ExprResult BuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, |
||
5651 | SourceLocation LParen, |
||
5652 | SourceLocation RParen, |
||
5653 | TypeSourceInfo *TSI); |
||
5654 | ExprResult ActOnSYCLUniqueStableNameExpr(SourceLocation OpLoc, |
||
5655 | SourceLocation LParen, |
||
5656 | SourceLocation RParen, |
||
5657 | ParsedType ParsedTy); |
||
5658 | |||
5659 | bool CheckLoopHintExpr(Expr *E, SourceLocation Loc); |
||
5660 | |||
5661 | ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr); |
||
5662 | ExprResult ActOnCharacterConstant(const Token &Tok, |
||
5663 | Scope *UDLScope = nullptr); |
||
5664 | ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E); |
||
5665 | ExprResult ActOnParenListExpr(SourceLocation L, |
||
5666 | SourceLocation R, |
||
5667 | MultiExprArg Val); |
||
5668 | |||
5669 | /// ActOnStringLiteral - The specified tokens were lexed as pasted string |
||
5670 | /// fragments (e.g. "foo" "bar" L"baz"). |
||
5671 | ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks, |
||
5672 | Scope *UDLScope = nullptr); |
||
5673 | |||
5674 | ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, |
||
5675 | SourceLocation DefaultLoc, |
||
5676 | SourceLocation RParenLoc, |
||
5677 | Expr *ControllingExpr, |
||
5678 | ArrayRef<ParsedType> ArgTypes, |
||
5679 | ArrayRef<Expr *> ArgExprs); |
||
5680 | ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, |
||
5681 | SourceLocation DefaultLoc, |
||
5682 | SourceLocation RParenLoc, |
||
5683 | Expr *ControllingExpr, |
||
5684 | ArrayRef<TypeSourceInfo *> Types, |
||
5685 | ArrayRef<Expr *> Exprs); |
||
5686 | |||
5687 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
||
5688 | ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, |
||
5689 | Expr *InputExpr, bool IsAfterAmp = false); |
||
5690 | ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, |
||
5691 | Expr *Input, bool IsAfterAmp = false); |
||
5692 | ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Op, |
||
5693 | Expr *Input, bool IsAfterAmp = false); |
||
5694 | |||
5695 | bool isQualifiedMemberAccess(Expr *E); |
||
5696 | QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc); |
||
5697 | |||
5698 | bool CheckTypeTraitArity(unsigned Arity, SourceLocation Loc, size_t N); |
||
5699 | |||
5700 | ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, |
||
5701 | SourceLocation OpLoc, |
||
5702 | UnaryExprOrTypeTrait ExprKind, |
||
5703 | SourceRange R); |
||
5704 | ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, |
||
5705 | UnaryExprOrTypeTrait ExprKind); |
||
5706 | ExprResult |
||
5707 | ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, |
||
5708 | UnaryExprOrTypeTrait ExprKind, |
||
5709 | bool IsType, void *TyOrEx, |
||
5710 | SourceRange ArgRange); |
||
5711 | |||
5712 | ExprResult CheckPlaceholderExpr(Expr *E); |
||
5713 | bool CheckVecStepExpr(Expr *E); |
||
5714 | |||
5715 | bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind); |
||
5716 | bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc, |
||
5717 | SourceRange ExprRange, |
||
5718 | UnaryExprOrTypeTrait ExprKind); |
||
5719 | ExprResult ActOnSizeofParameterPackExpr(Scope *S, |
||
5720 | SourceLocation OpLoc, |
||
5721 | IdentifierInfo &Name, |
||
5722 | SourceLocation NameLoc, |
||
5723 | SourceLocation RParenLoc); |
||
5724 | ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, |
||
5725 | tok::TokenKind Kind, Expr *Input); |
||
5726 | |||
5727 | ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, |
||
5728 | MultiExprArg ArgExprs, |
||
5729 | SourceLocation RLoc); |
||
5730 | ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, |
||
5731 | Expr *Idx, SourceLocation RLoc); |
||
5732 | |||
5733 | ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, |
||
5734 | Expr *ColumnIdx, |
||
5735 | SourceLocation RBLoc); |
||
5736 | |||
5737 | ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, |
||
5738 | Expr *LowerBound, |
||
5739 | SourceLocation ColonLocFirst, |
||
5740 | SourceLocation ColonLocSecond, |
||
5741 | Expr *Length, Expr *Stride, |
||
5742 | SourceLocation RBLoc); |
||
5743 | ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, |
||
5744 | SourceLocation RParenLoc, |
||
5745 | ArrayRef<Expr *> Dims, |
||
5746 | ArrayRef<SourceRange> Brackets); |
||
5747 | |||
5748 | /// Data structure for iterator expression. |
||
5749 | struct OMPIteratorData { |
||
5750 | IdentifierInfo *DeclIdent = nullptr; |
||
5751 | SourceLocation DeclIdentLoc; |
||
5752 | ParsedType Type; |
||
5753 | OMPIteratorExpr::IteratorRange Range; |
||
5754 | SourceLocation AssignLoc; |
||
5755 | SourceLocation ColonLoc; |
||
5756 | SourceLocation SecColonLoc; |
||
5757 | }; |
||
5758 | |||
5759 | ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc, |
||
5760 | SourceLocation LLoc, SourceLocation RLoc, |
||
5761 | ArrayRef<OMPIteratorData> Data); |
||
5762 | |||
5763 | // This struct is for use by ActOnMemberAccess to allow |
||
5764 | // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after |
||
5765 | // changing the access operator from a '.' to a '->' (to see if that is the |
||
5766 | // change needed to fix an error about an unknown member, e.g. when the class |
||
5767 | // defines a custom operator->). |
||
5768 | struct ActOnMemberAccessExtraArgs { |
||
5769 | Scope *S; |
||
5770 | UnqualifiedId &Id; |
||
5771 | Decl *ObjCImpDecl; |
||
5772 | }; |
||
5773 | |||
5774 | ExprResult BuildMemberReferenceExpr( |
||
5775 | Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, |
||
5776 | CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
||
5777 | NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, |
||
5778 | const TemplateArgumentListInfo *TemplateArgs, |
||
5779 | const Scope *S, |
||
5780 | ActOnMemberAccessExtraArgs *ExtraArgs = nullptr); |
||
5781 | |||
5782 | ExprResult |
||
5783 | BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, |
||
5784 | bool IsArrow, const CXXScopeSpec &SS, |
||
5785 | SourceLocation TemplateKWLoc, |
||
5786 | NamedDecl *FirstQualifierInScope, LookupResult &R, |
||
5787 | const TemplateArgumentListInfo *TemplateArgs, |
||
5788 | const Scope *S, |
||
5789 | bool SuppressQualifierCheck = false, |
||
5790 | ActOnMemberAccessExtraArgs *ExtraArgs = nullptr); |
||
5791 | |||
5792 | ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, |
||
5793 | SourceLocation OpLoc, |
||
5794 | const CXXScopeSpec &SS, FieldDecl *Field, |
||
5795 | DeclAccessPair FoundDecl, |
||
5796 | const DeclarationNameInfo &MemberNameInfo); |
||
5797 | |||
5798 | ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow); |
||
5799 | |||
5800 | bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, |
||
5801 | const CXXScopeSpec &SS, |
||
5802 | const LookupResult &R); |
||
5803 | |||
5804 | ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, |
||
5805 | bool IsArrow, SourceLocation OpLoc, |
||
5806 | const CXXScopeSpec &SS, |
||
5807 | SourceLocation TemplateKWLoc, |
||
5808 | NamedDecl *FirstQualifierInScope, |
||
5809 | const DeclarationNameInfo &NameInfo, |
||
5810 | const TemplateArgumentListInfo *TemplateArgs); |
||
5811 | |||
5812 | ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, |
||
5813 | SourceLocation OpLoc, |
||
5814 | tok::TokenKind OpKind, |
||
5815 | CXXScopeSpec &SS, |
||
5816 | SourceLocation TemplateKWLoc, |
||
5817 | UnqualifiedId &Member, |
||
5818 | Decl *ObjCImpDecl); |
||
5819 | |||
5820 | MemberExpr * |
||
5821 | BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc, |
||
5822 | const CXXScopeSpec *SS, SourceLocation TemplateKWLoc, |
||
5823 | ValueDecl *Member, DeclAccessPair FoundDecl, |
||
5824 | bool HadMultipleCandidates, |
||
5825 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, |
||
5826 | ExprValueKind VK, ExprObjectKind OK, |
||
5827 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
||
5828 | MemberExpr * |
||
5829 | BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc, |
||
5830 | NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, |
||
5831 | ValueDecl *Member, DeclAccessPair FoundDecl, |
||
5832 | bool HadMultipleCandidates, |
||
5833 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, |
||
5834 | ExprValueKind VK, ExprObjectKind OK, |
||
5835 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
||
5836 | |||
5837 | void ActOnDefaultCtorInitializers(Decl *CDtorDecl); |
||
5838 | bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, |
||
5839 | FunctionDecl *FDecl, |
||
5840 | const FunctionProtoType *Proto, |
||
5841 | ArrayRef<Expr *> Args, |
||
5842 | SourceLocation RParenLoc, |
||
5843 | bool ExecConfig = false); |
||
5844 | void CheckStaticArrayArgument(SourceLocation CallLoc, |
||
5845 | ParmVarDecl *Param, |
||
5846 | const Expr *ArgExpr); |
||
5847 | |||
5848 | /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. |
||
5849 | /// This provides the location of the left/right parens and a list of comma |
||
5850 | /// locations. |
||
5851 | ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
||
5852 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
||
5853 | Expr *ExecConfig = nullptr); |
||
5854 | ExprResult BuildCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
||
5855 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
||
5856 | Expr *ExecConfig = nullptr, |
||
5857 | bool IsExecConfig = false, |
||
5858 | bool AllowRecovery = false); |
||
5859 | Expr *BuildBuiltinCallExpr(SourceLocation Loc, Builtin::ID Id, |
||
5860 | MultiExprArg CallArgs); |
||
5861 | enum class AtomicArgumentOrder { API, AST }; |
||
5862 | ExprResult |
||
5863 | BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, |
||
5864 | SourceLocation RParenLoc, MultiExprArg Args, |
||
5865 | AtomicExpr::AtomicOp Op, |
||
5866 | AtomicArgumentOrder ArgOrder = AtomicArgumentOrder::API); |
||
5867 | ExprResult |
||
5868 | BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, SourceLocation LParenLoc, |
||
5869 | ArrayRef<Expr *> Arg, SourceLocation RParenLoc, |
||
5870 | Expr *Config = nullptr, bool IsExecConfig = false, |
||
5871 | ADLCallKind UsesADL = ADLCallKind::NotADL); |
||
5872 | |||
5873 | ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, |
||
5874 | MultiExprArg ExecConfig, |
||
5875 | SourceLocation GGGLoc); |
||
5876 | |||
5877 | ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, |
||
5878 | Declarator &D, ParsedType &Ty, |
||
5879 | SourceLocation RParenLoc, Expr *CastExpr); |
||
5880 | ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, |
||
5881 | TypeSourceInfo *Ty, |
||
5882 | SourceLocation RParenLoc, |
||
5883 | Expr *Op); |
||
5884 | CastKind PrepareScalarCast(ExprResult &src, QualType destType); |
||
5885 | |||
5886 | /// Build an altivec or OpenCL literal. |
||
5887 | ExprResult BuildVectorLiteral(SourceLocation LParenLoc, |
||
5888 | SourceLocation RParenLoc, Expr *E, |
||
5889 | TypeSourceInfo *TInfo); |
||
5890 | |||
5891 | ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); |
||
5892 | |||
5893 | ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, |
||
5894 | ParsedType Ty, |
||
5895 | SourceLocation RParenLoc, |
||
5896 | Expr *InitExpr); |
||
5897 | |||
5898 | ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, |
||
5899 | TypeSourceInfo *TInfo, |
||
5900 | SourceLocation RParenLoc, |
||
5901 | Expr *LiteralExpr); |
||
5902 | |||
5903 | ExprResult ActOnInitList(SourceLocation LBraceLoc, |
||
5904 | MultiExprArg InitArgList, |
||
5905 | SourceLocation RBraceLoc); |
||
5906 | |||
5907 | ExprResult BuildInitList(SourceLocation LBraceLoc, |
||
5908 | MultiExprArg InitArgList, |
||
5909 | SourceLocation RBraceLoc); |
||
5910 | |||
5911 | ExprResult ActOnDesignatedInitializer(Designation &Desig, |
||
5912 | SourceLocation EqualOrColonLoc, |
||
5913 | bool GNUSyntax, |
||
5914 | ExprResult Init); |
||
5915 | |||
5916 | private: |
||
5917 | static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind); |
||
5918 | |||
5919 | public: |
||
5920 | ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, |
||
5921 | tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr); |
||
5922 | ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, |
||
5923 | BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr); |
||
5924 | ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, |
||
5925 | Expr *LHSExpr, Expr *RHSExpr); |
||
5926 | void LookupBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, |
||
5927 | UnresolvedSetImpl &Functions); |
||
5928 | |||
5929 | void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc); |
||
5930 | |||
5931 | /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
||
5932 | /// in the case of a the GNU conditional expr extension. |
||
5933 | ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, |
||
5934 | SourceLocation ColonLoc, |
||
5935 | Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr); |
||
5936 | |||
5937 | /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". |
||
5938 | ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, |
||
5939 | LabelDecl *TheDecl); |
||
5940 | |||
5941 | void ActOnStartStmtExpr(); |
||
5942 | ExprResult ActOnStmtExpr(Scope *S, SourceLocation LPLoc, Stmt *SubStmt, |
||
5943 | SourceLocation RPLoc); |
||
5944 | ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, |
||
5945 | SourceLocation RPLoc, unsigned TemplateDepth); |
||
5946 | // Handle the final expression in a statement expression. |
||
5947 | ExprResult ActOnStmtExprResult(ExprResult E); |
||
5948 | void ActOnStmtExprError(); |
||
5949 | |||
5950 | // __builtin_offsetof(type, identifier(.identifier|[expr])*) |
||
5951 | struct OffsetOfComponent { |
||
5952 | SourceLocation LocStart, LocEnd; |
||
5953 | bool isBrackets; // true if [expr], false if .ident |
||
5954 | union { |
||
5955 | IdentifierInfo *IdentInfo; |
||
5956 | Expr *E; |
||
5957 | } U; |
||
5958 | }; |
||
5959 | |||
5960 | /// __builtin_offsetof(type, a.b[123][456].c) |
||
5961 | ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, |
||
5962 | TypeSourceInfo *TInfo, |
||
5963 | ArrayRef<OffsetOfComponent> Components, |
||
5964 | SourceLocation RParenLoc); |
||
5965 | ExprResult ActOnBuiltinOffsetOf(Scope *S, |
||
5966 | SourceLocation BuiltinLoc, |
||
5967 | SourceLocation TypeLoc, |
||
5968 | ParsedType ParsedArgTy, |
||
5969 | ArrayRef<OffsetOfComponent> Components, |
||
5970 | SourceLocation RParenLoc); |
||
5971 | |||
5972 | // __builtin_choose_expr(constExpr, expr1, expr2) |
||
5973 | ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, |
||
5974 | Expr *CondExpr, Expr *LHSExpr, |
||
5975 | Expr *RHSExpr, SourceLocation RPLoc); |
||
5976 | |||
5977 | // __builtin_va_arg(expr, type) |
||
5978 | ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, |
||
5979 | SourceLocation RPLoc); |
||
5980 | ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, |
||
5981 | TypeSourceInfo *TInfo, SourceLocation RPLoc); |
||
5982 | |||
5983 | // __builtin_LINE(), __builtin_FUNCTION(), __builtin_FILE(), |
||
5984 | // __builtin_COLUMN(), __builtin_source_location() |
||
5985 | ExprResult ActOnSourceLocExpr(SourceLocExpr::IdentKind Kind, |
||
5986 | SourceLocation BuiltinLoc, |
||
5987 | SourceLocation RPLoc); |
||
5988 | |||
5989 | // Build a potentially resolved SourceLocExpr. |
||
5990 | ExprResult BuildSourceLocExpr(SourceLocExpr::IdentKind Kind, |
||
5991 | QualType ResultTy, SourceLocation BuiltinLoc, |
||
5992 | SourceLocation RPLoc, |
||
5993 | DeclContext *ParentContext); |
||
5994 | |||
5995 | // __null |
||
5996 | ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); |
||
5997 | |||
5998 | bool CheckCaseExpression(Expr *E); |
||
5999 | |||
6000 | /// Describes the result of an "if-exists" condition check. |
||
6001 | enum IfExistsResult { |
||
6002 | /// The symbol exists. |
||
6003 | IER_Exists, |
||
6004 | |||
6005 | /// The symbol does not exist. |
||
6006 | IER_DoesNotExist, |
||
6007 | |||
6008 | /// The name is a dependent name, so the results will differ |
||
6009 | /// from one instantiation to the next. |
||
6010 | IER_Dependent, |
||
6011 | |||
6012 | /// An error occurred. |
||
6013 | IER_Error |
||
6014 | }; |
||
6015 | |||
6016 | IfExistsResult |
||
6017 | CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, |
||
6018 | const DeclarationNameInfo &TargetNameInfo); |
||
6019 | |||
6020 | IfExistsResult |
||
6021 | CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc, |
||
6022 | bool IsIfExists, CXXScopeSpec &SS, |
||
6023 | UnqualifiedId &Name); |
||
6024 | |||
6025 | StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
||
6026 | bool IsIfExists, |
||
6027 | NestedNameSpecifierLoc QualifierLoc, |
||
6028 | DeclarationNameInfo NameInfo, |
||
6029 | Stmt *Nested); |
||
6030 | StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, |
||
6031 | bool IsIfExists, |
||
6032 | CXXScopeSpec &SS, UnqualifiedId &Name, |
||
6033 | Stmt *Nested); |
||
6034 | |||
6035 | //===------------------------- "Block" Extension ------------------------===// |
||
6036 | |||
6037 | /// ActOnBlockStart - This callback is invoked when a block literal is |
||
6038 | /// started. |
||
6039 | void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); |
||
6040 | |||
6041 | /// ActOnBlockArguments - This callback allows processing of block arguments. |
||
6042 | /// If there are no arguments, this is still invoked. |
||
6043 | void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, |
||
6044 | Scope *CurScope); |
||
6045 | |||
6046 | /// ActOnBlockError - If there is an error parsing a block, this callback |
||
6047 | /// is invoked to pop the information about the block from the action impl. |
||
6048 | void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); |
||
6049 | |||
6050 | /// ActOnBlockStmtExpr - This is called when the body of a block statement |
||
6051 | /// literal was successfully completed. ^(int x){...} |
||
6052 | ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, |
||
6053 | Scope *CurScope); |
||
6054 | |||
6055 | //===---------------------------- Clang Extensions ----------------------===// |
||
6056 | |||
6057 | /// __builtin_convertvector(...) |
||
6058 | ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy, |
||
6059 | SourceLocation BuiltinLoc, |
||
6060 | SourceLocation RParenLoc); |
||
6061 | |||
6062 | //===---------------------------- OpenCL Features -----------------------===// |
||
6063 | |||
6064 | /// __builtin_astype(...) |
||
6065 | ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, |
||
6066 | SourceLocation BuiltinLoc, |
||
6067 | SourceLocation RParenLoc); |
||
6068 | ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy, |
||
6069 | SourceLocation BuiltinLoc, |
||
6070 | SourceLocation RParenLoc); |
||
6071 | |||
6072 | //===---------------------------- HLSL Features -------------------------===// |
||
6073 | Decl *ActOnStartHLSLBuffer(Scope *BufferScope, bool CBuffer, |
||
6074 | SourceLocation KwLoc, IdentifierInfo *Ident, |
||
6075 | SourceLocation IdentLoc, SourceLocation LBrace); |
||
6076 | void ActOnFinishHLSLBuffer(Decl *Dcl, SourceLocation RBrace); |
||
6077 | |||
6078 | //===---------------------------- C++ Features --------------------------===// |
||
6079 | |||
6080 | // Act on C++ namespaces |
||
6081 | Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, |
||
6082 | SourceLocation NamespaceLoc, |
||
6083 | SourceLocation IdentLoc, IdentifierInfo *Ident, |
||
6084 | SourceLocation LBrace, |
||
6085 | const ParsedAttributesView &AttrList, |
||
6086 | UsingDirectiveDecl *&UsingDecl, bool IsNested); |
||
6087 | void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); |
||
6088 | |||
6089 | NamespaceDecl *getStdNamespace() const; |
||
6090 | NamespaceDecl *getOrCreateStdNamespace(); |
||
6091 | |||
6092 | NamespaceDecl *lookupStdExperimentalNamespace(); |
||
6093 | NamespaceDecl *getCachedCoroNamespace() { return CoroTraitsNamespaceCache; } |
||
6094 | |||
6095 | CXXRecordDecl *getStdBadAlloc() const; |
||
6096 | EnumDecl *getStdAlignValT() const; |
||
6097 | |||
6098 | private: |
||
6099 | // A cache representing if we've fully checked the various comparison category |
||
6100 | // types stored in ASTContext. The bit-index corresponds to the integer value |
||
6101 | // of a ComparisonCategoryType enumerator. |
||
6102 | llvm::SmallBitVector FullyCheckedComparisonCategories; |
||
6103 | |||
6104 | ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl, |
||
6105 | CXXScopeSpec &SS, |
||
6106 | ParsedType TemplateTypeTy, |
||
6107 | IdentifierInfo *MemberOrBase); |
||
6108 | |||
6109 | public: |
||
6110 | enum class ComparisonCategoryUsage { |
||
6111 | /// The '<=>' operator was used in an expression and a builtin operator |
||
6112 | /// was selected. |
||
6113 | OperatorInExpression, |
||
6114 | /// A defaulted 'operator<=>' needed the comparison category. This |
||
6115 | /// typically only applies to 'std::strong_ordering', due to the implicit |
||
6116 | /// fallback return value. |
||
6117 | DefaultedOperator, |
||
6118 | }; |
||
6119 | |||
6120 | /// Lookup the specified comparison category types in the standard |
||
6121 | /// library, an check the VarDecls possibly returned by the operator<=> |
||
6122 | /// builtins for that type. |
||
6123 | /// |
||
6124 | /// \return The type of the comparison category type corresponding to the |
||
6125 | /// specified Kind, or a null type if an error occurs |
||
6126 | QualType CheckComparisonCategoryType(ComparisonCategoryType Kind, |
||
6127 | SourceLocation Loc, |
||
6128 | ComparisonCategoryUsage Usage); |
||
6129 | |||
6130 | /// Tests whether Ty is an instance of std::initializer_list and, if |
||
6131 | /// it is and Element is not NULL, assigns the element type to Element. |
||
6132 | bool isStdInitializerList(QualType Ty, QualType *Element); |
||
6133 | |||
6134 | /// Looks for the std::initializer_list template and instantiates it |
||
6135 | /// with Element, or emits an error if it's not found. |
||
6136 | /// |
||
6137 | /// \returns The instantiated template, or null on error. |
||
6138 | QualType BuildStdInitializerList(QualType Element, SourceLocation Loc); |
||
6139 | |||
6140 | /// Determine whether Ctor is an initializer-list constructor, as |
||
6141 | /// defined in [dcl.init.list]p2. |
||
6142 | bool isInitListConstructor(const FunctionDecl *Ctor); |
||
6143 | |||
6144 | Decl *ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc, |
||
6145 | SourceLocation NamespcLoc, CXXScopeSpec &SS, |
||
6146 | SourceLocation IdentLoc, |
||
6147 | IdentifierInfo *NamespcName, |
||
6148 | const ParsedAttributesView &AttrList); |
||
6149 | |||
6150 | void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); |
||
6151 | |||
6152 | Decl *ActOnNamespaceAliasDef(Scope *CurScope, |
||
6153 | SourceLocation NamespaceLoc, |
||
6154 | SourceLocation AliasLoc, |
||
6155 | IdentifierInfo *Alias, |
||
6156 | CXXScopeSpec &SS, |
||
6157 | SourceLocation IdentLoc, |
||
6158 | IdentifierInfo *Ident); |
||
6159 | |||
6160 | void FilterUsingLookup(Scope *S, LookupResult &lookup); |
||
6161 | void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); |
||
6162 | bool CheckUsingShadowDecl(BaseUsingDecl *BUD, NamedDecl *Target, |
||
6163 | const LookupResult &PreviousDecls, |
||
6164 | UsingShadowDecl *&PrevShadow); |
||
6165 | UsingShadowDecl *BuildUsingShadowDecl(Scope *S, BaseUsingDecl *BUD, |
||
6166 | NamedDecl *Target, |
||
6167 | UsingShadowDecl *PrevDecl); |
||
6168 | |||
6169 | bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, |
||
6170 | bool HasTypenameKeyword, |
||
6171 | const CXXScopeSpec &SS, |
||
6172 | SourceLocation NameLoc, |
||
6173 | const LookupResult &Previous); |
||
6174 | bool CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename, |
||
6175 | const CXXScopeSpec &SS, |
||
6176 | const DeclarationNameInfo &NameInfo, |
||
6177 | SourceLocation NameLoc, |
||
6178 | const LookupResult *R = nullptr, |
||
6179 | const UsingDecl *UD = nullptr); |
||
6180 | |||
6181 | NamedDecl *BuildUsingDeclaration( |
||
6182 | Scope *S, AccessSpecifier AS, SourceLocation UsingLoc, |
||
6183 | bool HasTypenameKeyword, SourceLocation TypenameLoc, CXXScopeSpec &SS, |
||
6184 | DeclarationNameInfo NameInfo, SourceLocation EllipsisLoc, |
||
6185 | const ParsedAttributesView &AttrList, bool IsInstantiation, |
||
6186 | bool IsUsingIfExists); |
||
6187 | NamedDecl *BuildUsingEnumDeclaration(Scope *S, AccessSpecifier AS, |
||
6188 | SourceLocation UsingLoc, |
||
6189 | SourceLocation EnumLoc, |
||
6190 | SourceLocation NameLoc, |
||
6191 | TypeSourceInfo *EnumType, EnumDecl *ED); |
||
6192 | NamedDecl *BuildUsingPackDecl(NamedDecl *InstantiatedFrom, |
||
6193 | ArrayRef<NamedDecl *> Expansions); |
||
6194 | |||
6195 | bool CheckInheritingConstructorUsingDecl(UsingDecl *UD); |
||
6196 | |||
6197 | /// Given a derived-class using shadow declaration for a constructor and the |
||
6198 | /// correspnding base class constructor, find or create the implicit |
||
6199 | /// synthesized derived class constructor to use for this initialization. |
||
6200 | CXXConstructorDecl * |
||
6201 | findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor, |
||
6202 | ConstructorUsingShadowDecl *DerivedShadow); |
||
6203 | |||
6204 | Decl *ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS, |
||
6205 | SourceLocation UsingLoc, |
||
6206 | SourceLocation TypenameLoc, CXXScopeSpec &SS, |
||
6207 | UnqualifiedId &Name, SourceLocation EllipsisLoc, |
||
6208 | const ParsedAttributesView &AttrList); |
||
6209 | Decl *ActOnUsingEnumDeclaration(Scope *CurScope, AccessSpecifier AS, |
||
6210 | SourceLocation UsingLoc, |
||
6211 | SourceLocation EnumLoc, |
||
6212 | SourceLocation IdentLoc, IdentifierInfo &II, |
||
6213 | CXXScopeSpec *SS = nullptr); |
||
6214 | Decl *ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS, |
||
6215 | MultiTemplateParamsArg TemplateParams, |
||
6216 | SourceLocation UsingLoc, UnqualifiedId &Name, |
||
6217 | const ParsedAttributesView &AttrList, |
||
6218 | TypeResult Type, Decl *DeclFromDeclSpec); |
||
6219 | |||
6220 | /// BuildCXXConstructExpr - Creates a complete call to a constructor, |
||
6221 | /// including handling of its default argument expressions. |
||
6222 | /// |
||
6223 | /// \param ConstructKind - a CXXConstructExpr::ConstructionKind |
||
6224 | ExprResult |
||
6225 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
||
6226 | NamedDecl *FoundDecl, |
||
6227 | CXXConstructorDecl *Constructor, MultiExprArg Exprs, |
||
6228 | bool HadMultipleCandidates, bool IsListInitialization, |
||
6229 | bool IsStdInitListInitialization, |
||
6230 | bool RequiresZeroInit, unsigned ConstructKind, |
||
6231 | SourceRange ParenRange); |
||
6232 | |||
6233 | /// Build a CXXConstructExpr whose constructor has already been resolved if |
||
6234 | /// it denotes an inherited constructor. |
||
6235 | ExprResult |
||
6236 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
||
6237 | CXXConstructorDecl *Constructor, bool Elidable, |
||
6238 | MultiExprArg Exprs, |
||
6239 | bool HadMultipleCandidates, bool IsListInitialization, |
||
6240 | bool IsStdInitListInitialization, |
||
6241 | bool RequiresZeroInit, unsigned ConstructKind, |
||
6242 | SourceRange ParenRange); |
||
6243 | |||
6244 | // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if |
||
6245 | // the constructor can be elidable? |
||
6246 | ExprResult |
||
6247 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
||
6248 | NamedDecl *FoundDecl, |
||
6249 | CXXConstructorDecl *Constructor, bool Elidable, |
||
6250 | MultiExprArg Exprs, bool HadMultipleCandidates, |
||
6251 | bool IsListInitialization, |
||
6252 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
||
6253 | unsigned ConstructKind, SourceRange ParenRange); |
||
6254 | |||
6255 | ExprResult ConvertMemberDefaultInitExpression(FieldDecl *FD, Expr *InitExpr, |
||
6256 | SourceLocation InitLoc); |
||
6257 | |||
6258 | ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field); |
||
6259 | |||
6260 | |||
6261 | /// Instantiate or parse a C++ default argument expression as necessary. |
||
6262 | /// Return true on error. |
||
6263 | bool CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
||
6264 | ParmVarDecl *Param, Expr *Init = nullptr, |
||
6265 | bool SkipImmediateInvocations = true); |
||
6266 | |||
6267 | /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating |
||
6268 | /// the default expr if needed. |
||
6269 | ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
||
6270 | ParmVarDecl *Param, Expr *Init = nullptr); |
||
6271 | |||
6272 | /// FinalizeVarWithDestructor - Prepare for calling destructor on the |
||
6273 | /// constructed variable. |
||
6274 | void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); |
||
6275 | |||
6276 | /// Helper class that collects exception specifications for |
||
6277 | /// implicitly-declared special member functions. |
||
6278 | class ImplicitExceptionSpecification { |
||
6279 | // Pointer to allow copying |
||
6280 | Sema *Self; |
||
6281 | // We order exception specifications thus: |
||
6282 | // noexcept is the most restrictive, but is only used in C++11. |
||
6283 | // throw() comes next. |
||
6284 | // Then a throw(collected exceptions) |
||
6285 | // Finally no specification, which is expressed as noexcept(false). |
||
6286 | // throw(...) is used instead if any called function uses it. |
||
6287 | ExceptionSpecificationType ComputedEST; |
||
6288 | llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; |
||
6289 | SmallVector<QualType, 4> Exceptions; |
||
6290 | |||
6291 | void ClearExceptions() { |
||
6292 | ExceptionsSeen.clear(); |
||
6293 | Exceptions.clear(); |
||
6294 | } |
||
6295 | |||
6296 | public: |
||
6297 | explicit ImplicitExceptionSpecification(Sema &Self) |
||
6298 | : Self(&Self), ComputedEST(EST_BasicNoexcept) { |
||
6299 | if (!Self.getLangOpts().CPlusPlus11) |
||
6300 | ComputedEST = EST_DynamicNone; |
||
6301 | } |
||
6302 | |||
6303 | /// Get the computed exception specification type. |
||
6304 | ExceptionSpecificationType getExceptionSpecType() const { |
||
6305 | assert(!isComputedNoexcept(ComputedEST) && |
||
6306 | "noexcept(expr) should not be a possible result"); |
||
6307 | return ComputedEST; |
||
6308 | } |
||
6309 | |||
6310 | /// The number of exceptions in the exception specification. |
||
6311 | unsigned size() const { return Exceptions.size(); } |
||
6312 | |||
6313 | /// The set of exceptions in the exception specification. |
||
6314 | const QualType *data() const { return Exceptions.data(); } |
||
6315 | |||
6316 | /// Integrate another called method into the collected data. |
||
6317 | void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method); |
||
6318 | |||
6319 | /// Integrate an invoked expression into the collected data. |
||
6320 | void CalledExpr(Expr *E) { CalledStmt(E); } |
||
6321 | |||
6322 | /// Integrate an invoked statement into the collected data. |
||
6323 | void CalledStmt(Stmt *S); |
||
6324 | |||
6325 | /// Overwrite an EPI's exception specification with this |
||
6326 | /// computed exception specification. |
||
6327 | FunctionProtoType::ExceptionSpecInfo getExceptionSpec() const { |
||
6328 | FunctionProtoType::ExceptionSpecInfo ESI; |
||
6329 | ESI.Type = getExceptionSpecType(); |
||
6330 | if (ESI.Type == EST_Dynamic) { |
||
6331 | ESI.Exceptions = Exceptions; |
||
6332 | } else if (ESI.Type == EST_None) { |
||
6333 | /// C++11 [except.spec]p14: |
||
6334 | /// The exception-specification is noexcept(false) if the set of |
||
6335 | /// potential exceptions of the special member function contains "any" |
||
6336 | ESI.Type = EST_NoexceptFalse; |
||
6337 | ESI.NoexceptExpr = Self->ActOnCXXBoolLiteral(SourceLocation(), |
||
6338 | tok::kw_false).get(); |
||
6339 | } |
||
6340 | return ESI; |
||
6341 | } |
||
6342 | }; |
||
6343 | |||
6344 | /// Evaluate the implicit exception specification for a defaulted |
||
6345 | /// special member function. |
||
6346 | void EvaluateImplicitExceptionSpec(SourceLocation Loc, FunctionDecl *FD); |
||
6347 | |||
6348 | /// Check the given noexcept-specifier, convert its expression, and compute |
||
6349 | /// the appropriate ExceptionSpecificationType. |
||
6350 | ExprResult ActOnNoexceptSpec(Expr *NoexceptExpr, |
||
6351 | ExceptionSpecificationType &EST); |
||
6352 | |||
6353 | /// Check the given exception-specification and update the |
||
6354 | /// exception specification information with the results. |
||
6355 | void checkExceptionSpecification(bool IsTopLevel, |
||
6356 | ExceptionSpecificationType EST, |
||
6357 | ArrayRef<ParsedType> DynamicExceptions, |
||
6358 | ArrayRef<SourceRange> DynamicExceptionRanges, |
||
6359 | Expr *NoexceptExpr, |
||
6360 | SmallVectorImpl<QualType> &Exceptions, |
||
6361 | FunctionProtoType::ExceptionSpecInfo &ESI); |
||
6362 | |||
6363 | /// Determine if we're in a case where we need to (incorrectly) eagerly |
||
6364 | /// parse an exception specification to work around a libstdc++ bug. |
||
6365 | bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D); |
||
6366 | |||
6367 | /// Add an exception-specification to the given member function |
||
6368 | /// (or member function template). The exception-specification was parsed |
||
6369 | /// after the method itself was declared. |
||
6370 | void actOnDelayedExceptionSpecification(Decl *Method, |
||
6371 | ExceptionSpecificationType EST, |
||
6372 | SourceRange SpecificationRange, |
||
6373 | ArrayRef<ParsedType> DynamicExceptions, |
||
6374 | ArrayRef<SourceRange> DynamicExceptionRanges, |
||
6375 | Expr *NoexceptExpr); |
||
6376 | |||
6377 | class InheritedConstructorInfo; |
||
6378 | |||
6379 | /// Determine if a special member function should have a deleted |
||
6380 | /// definition when it is defaulted. |
||
6381 | bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM, |
||
6382 | InheritedConstructorInfo *ICI = nullptr, |
||
6383 | bool Diagnose = false); |
||
6384 | |||
6385 | /// Produce notes explaining why a defaulted function was defined as deleted. |
||
6386 | void DiagnoseDeletedDefaultedFunction(FunctionDecl *FD); |
||
6387 | |||
6388 | /// Declare the implicit default constructor for the given class. |
||
6389 | /// |
||
6390 | /// \param ClassDecl The class declaration into which the implicit |
||
6391 | /// default constructor will be added. |
||
6392 | /// |
||
6393 | /// \returns The implicitly-declared default constructor. |
||
6394 | CXXConstructorDecl *DeclareImplicitDefaultConstructor( |
||
6395 | CXXRecordDecl *ClassDecl); |
||
6396 | |||
6397 | /// DefineImplicitDefaultConstructor - Checks for feasibility of |
||
6398 | /// defining this constructor as the default constructor. |
||
6399 | void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, |
||
6400 | CXXConstructorDecl *Constructor); |
||
6401 | |||
6402 | /// Declare the implicit destructor for the given class. |
||
6403 | /// |
||
6404 | /// \param ClassDecl The class declaration into which the implicit |
||
6405 | /// destructor will be added. |
||
6406 | /// |
||
6407 | /// \returns The implicitly-declared destructor. |
||
6408 | CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); |
||
6409 | |||
6410 | /// DefineImplicitDestructor - Checks for feasibility of |
||
6411 | /// defining this destructor as the default destructor. |
||
6412 | void DefineImplicitDestructor(SourceLocation CurrentLocation, |
||
6413 | CXXDestructorDecl *Destructor); |
||
6414 | |||
6415 | /// Build an exception spec for destructors that don't have one. |
||
6416 | /// |
||
6417 | /// C++11 says that user-defined destructors with no exception spec get one |
||
6418 | /// that looks as if the destructor was implicitly declared. |
||
6419 | void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor); |
||
6420 | |||
6421 | /// Define the specified inheriting constructor. |
||
6422 | void DefineInheritingConstructor(SourceLocation UseLoc, |
||
6423 | CXXConstructorDecl *Constructor); |
||
6424 | |||
6425 | /// Declare the implicit copy constructor for the given class. |
||
6426 | /// |
||
6427 | /// \param ClassDecl The class declaration into which the implicit |
||
6428 | /// copy constructor will be added. |
||
6429 | /// |
||
6430 | /// \returns The implicitly-declared copy constructor. |
||
6431 | CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); |
||
6432 | |||
6433 | /// DefineImplicitCopyConstructor - Checks for feasibility of |
||
6434 | /// defining this constructor as the copy constructor. |
||
6435 | void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, |
||
6436 | CXXConstructorDecl *Constructor); |
||
6437 | |||
6438 | /// Declare the implicit move constructor for the given class. |
||
6439 | /// |
||
6440 | /// \param ClassDecl The Class declaration into which the implicit |
||
6441 | /// move constructor will be added. |
||
6442 | /// |
||
6443 | /// \returns The implicitly-declared move constructor, or NULL if it wasn't |
||
6444 | /// declared. |
||
6445 | CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl); |
||
6446 | |||
6447 | /// DefineImplicitMoveConstructor - Checks for feasibility of |
||
6448 | /// defining this constructor as the move constructor. |
||
6449 | void DefineImplicitMoveConstructor(SourceLocation CurrentLocation, |
||
6450 | CXXConstructorDecl *Constructor); |
||
6451 | |||
6452 | /// Declare the implicit copy assignment operator for the given class. |
||
6453 | /// |
||
6454 | /// \param ClassDecl The class declaration into which the implicit |
||
6455 | /// copy assignment operator will be added. |
||
6456 | /// |
||
6457 | /// \returns The implicitly-declared copy assignment operator. |
||
6458 | CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); |
||
6459 | |||
6460 | /// Defines an implicitly-declared copy assignment operator. |
||
6461 | void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, |
||
6462 | CXXMethodDecl *MethodDecl); |
||
6463 | |||
6464 | /// Declare the implicit move assignment operator for the given class. |
||
6465 | /// |
||
6466 | /// \param ClassDecl The Class declaration into which the implicit |
||
6467 | /// move assignment operator will be added. |
||
6468 | /// |
||
6469 | /// \returns The implicitly-declared move assignment operator, or NULL if it |
||
6470 | /// wasn't declared. |
||
6471 | CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl); |
||
6472 | |||
6473 | /// Defines an implicitly-declared move assignment operator. |
||
6474 | void DefineImplicitMoveAssignment(SourceLocation CurrentLocation, |
||
6475 | CXXMethodDecl *MethodDecl); |
||
6476 | |||
6477 | /// Force the declaration of any implicitly-declared members of this |
||
6478 | /// class. |
||
6479 | void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); |
||
6480 | |||
6481 | /// Check a completed declaration of an implicit special member. |
||
6482 | void CheckImplicitSpecialMemberDeclaration(Scope *S, FunctionDecl *FD); |
||
6483 | |||
6484 | /// Determine whether the given function is an implicitly-deleted |
||
6485 | /// special member function. |
||
6486 | bool isImplicitlyDeleted(FunctionDecl *FD); |
||
6487 | |||
6488 | /// Check whether 'this' shows up in the type of a static member |
||
6489 | /// function after the (naturally empty) cv-qualifier-seq would be. |
||
6490 | /// |
||
6491 | /// \returns true if an error occurred. |
||
6492 | bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method); |
||
6493 | |||
6494 | /// Whether this' shows up in the exception specification of a static |
||
6495 | /// member function. |
||
6496 | bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method); |
||
6497 | |||
6498 | /// Check whether 'this' shows up in the attributes of the given |
||
6499 | /// static member function. |
||
6500 | /// |
||
6501 | /// \returns true if an error occurred. |
||
6502 | bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method); |
||
6503 | |||
6504 | /// MaybeBindToTemporary - If the passed in expression has a record type with |
||
6505 | /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise |
||
6506 | /// it simply returns the passed in expression. |
||
6507 | ExprResult MaybeBindToTemporary(Expr *E); |
||
6508 | |||
6509 | /// Wrap the expression in a ConstantExpr if it is a potential immediate |
||
6510 | /// invocation. |
||
6511 | ExprResult CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl); |
||
6512 | |||
6513 | bool CompleteConstructorCall(CXXConstructorDecl *Constructor, |
||
6514 | QualType DeclInitType, MultiExprArg ArgsPtr, |
||
6515 | SourceLocation Loc, |
||
6516 | SmallVectorImpl<Expr *> &ConvertedArgs, |
||
6517 | bool AllowExplicit = false, |
||
6518 | bool IsListInitialization = false); |
||
6519 | |||
6520 | ParsedType getInheritingConstructorName(CXXScopeSpec &SS, |
||
6521 | SourceLocation NameLoc, |
||
6522 | IdentifierInfo &Name); |
||
6523 | |||
6524 | ParsedType getConstructorName(IdentifierInfo &II, SourceLocation NameLoc, |
||
6525 | Scope *S, CXXScopeSpec &SS, |
||
6526 | bool EnteringContext); |
||
6527 | ParsedType getDestructorName(SourceLocation TildeLoc, |
||
6528 | IdentifierInfo &II, SourceLocation NameLoc, |
||
6529 | Scope *S, CXXScopeSpec &SS, |
||
6530 | ParsedType ObjectType, |
||
6531 | bool EnteringContext); |
||
6532 | |||
6533 | ParsedType getDestructorTypeForDecltype(const DeclSpec &DS, |
||
6534 | ParsedType ObjectType); |
||
6535 | |||
6536 | // Checks that reinterpret casts don't have undefined behavior. |
||
6537 | void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, |
||
6538 | bool IsDereference, SourceRange Range); |
||
6539 | |||
6540 | // Checks that the vector type should be initialized from a scalar |
||
6541 | // by splatting the value rather than populating a single element. |
||
6542 | // This is the case for AltiVecVector types as well as with |
||
6543 | // AltiVecPixel and AltiVecBool when -faltivec-src-compat=xl is specified. |
||
6544 | bool ShouldSplatAltivecScalarInCast(const VectorType *VecTy); |
||
6545 | |||
6546 | // Checks if the -faltivec-src-compat=gcc option is specified. |
||
6547 | // If so, AltiVecVector, AltiVecBool and AltiVecPixel types are |
||
6548 | // treated the same way as they are when trying to initialize |
||
6549 | // these vectors on gcc (an error is emitted). |
||
6550 | bool CheckAltivecInitFromScalar(SourceRange R, QualType VecTy, |
||
6551 | QualType SrcTy); |
||
6552 | |||
6553 | /// ActOnCXXNamedCast - Parse |
||
6554 | /// {dynamic,static,reinterpret,const,addrspace}_cast's. |
||
6555 | ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, |
||
6556 | tok::TokenKind Kind, |
||
6557 | SourceLocation LAngleBracketLoc, |
||
6558 | Declarator &D, |
||
6559 | SourceLocation RAngleBracketLoc, |
||
6560 | SourceLocation LParenLoc, |
||
6561 | Expr *E, |
||
6562 | SourceLocation RParenLoc); |
||
6563 | |||
6564 | ExprResult BuildCXXNamedCast(SourceLocation OpLoc, |
||
6565 | tok::TokenKind Kind, |
||
6566 | TypeSourceInfo *Ty, |
||
6567 | Expr *E, |
||
6568 | SourceRange AngleBrackets, |
||
6569 | SourceRange Parens); |
||
6570 | |||
6571 | ExprResult ActOnBuiltinBitCastExpr(SourceLocation KWLoc, Declarator &Dcl, |
||
6572 | ExprResult Operand, |
||
6573 | SourceLocation RParenLoc); |
||
6574 | |||
6575 | ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, |
||
6576 | Expr *Operand, SourceLocation RParenLoc); |
||
6577 | |||
6578 | ExprResult BuildCXXTypeId(QualType TypeInfoType, |
||
6579 | SourceLocation TypeidLoc, |
||
6580 | TypeSourceInfo *Operand, |
||
6581 | SourceLocation RParenLoc); |
||
6582 | ExprResult BuildCXXTypeId(QualType TypeInfoType, |
||
6583 | SourceLocation TypeidLoc, |
||
6584 | Expr *Operand, |
||
6585 | SourceLocation RParenLoc); |
||
6586 | |||
6587 | /// ActOnCXXTypeid - Parse typeid( something ). |
||
6588 | ExprResult ActOnCXXTypeid(SourceLocation OpLoc, |
||
6589 | SourceLocation LParenLoc, bool isType, |
||
6590 | void *TyOrExpr, |
||
6591 | SourceLocation RParenLoc); |
||
6592 | |||
6593 | ExprResult BuildCXXUuidof(QualType TypeInfoType, |
||
6594 | SourceLocation TypeidLoc, |
||
6595 | TypeSourceInfo *Operand, |
||
6596 | SourceLocation RParenLoc); |
||
6597 | ExprResult BuildCXXUuidof(QualType TypeInfoType, |
||
6598 | SourceLocation TypeidLoc, |
||
6599 | Expr *Operand, |
||
6600 | SourceLocation RParenLoc); |
||
6601 | |||
6602 | /// ActOnCXXUuidof - Parse __uuidof( something ). |
||
6603 | ExprResult ActOnCXXUuidof(SourceLocation OpLoc, |
||
6604 | SourceLocation LParenLoc, bool isType, |
||
6605 | void *TyOrExpr, |
||
6606 | SourceLocation RParenLoc); |
||
6607 | |||
6608 | /// Handle a C++1z fold-expression: ( expr op ... op expr ). |
||
6609 | ExprResult ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS, |
||
6610 | tok::TokenKind Operator, |
||
6611 | SourceLocation EllipsisLoc, Expr *RHS, |
||
6612 | SourceLocation RParenLoc); |
||
6613 | ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, |
||
6614 | SourceLocation LParenLoc, Expr *LHS, |
||
6615 | BinaryOperatorKind Operator, |
||
6616 | SourceLocation EllipsisLoc, Expr *RHS, |
||
6617 | SourceLocation RParenLoc, |
||
6618 | std::optional<unsigned> NumExpansions); |
||
6619 | ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
||
6620 | BinaryOperatorKind Operator); |
||
6621 | |||
6622 | //// ActOnCXXThis - Parse 'this' pointer. |
||
6623 | ExprResult ActOnCXXThis(SourceLocation loc); |
||
6624 | |||
6625 | /// Build a CXXThisExpr and mark it referenced in the current context. |
||
6626 | Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit); |
||
6627 | void MarkThisReferenced(CXXThisExpr *This); |
||
6628 | |||
6629 | /// Try to retrieve the type of the 'this' pointer. |
||
6630 | /// |
||
6631 | /// \returns The type of 'this', if possible. Otherwise, returns a NULL type. |
||
6632 | QualType getCurrentThisType(); |
||
6633 | |||
6634 | /// When non-NULL, the C++ 'this' expression is allowed despite the |
||
6635 | /// current context not being a non-static member function. In such cases, |
||
6636 | /// this provides the type used for 'this'. |
||
6637 | QualType CXXThisTypeOverride; |
||
6638 | |||
6639 | /// RAII object used to temporarily allow the C++ 'this' expression |
||
6640 | /// to be used, with the given qualifiers on the current class type. |
||
6641 | class CXXThisScopeRAII { |
||
6642 | Sema &S; |
||
6643 | QualType OldCXXThisTypeOverride; |
||
6644 | bool Enabled; |
||
6645 | |||
6646 | public: |
||
6647 | /// Introduce a new scope where 'this' may be allowed (when enabled), |
||
6648 | /// using the given declaration (which is either a class template or a |
||
6649 | /// class) along with the given qualifiers. |
||
6650 | /// along with the qualifiers placed on '*this'. |
||
6651 | CXXThisScopeRAII(Sema &S, Decl *ContextDecl, Qualifiers CXXThisTypeQuals, |
||
6652 | bool Enabled = true); |
||
6653 | |||
6654 | ~CXXThisScopeRAII(); |
||
6655 | }; |
||
6656 | |||
6657 | /// Make sure the value of 'this' is actually available in the current |
||
6658 | /// context, if it is a potentially evaluated context. |
||
6659 | /// |
||
6660 | /// \param Loc The location at which the capture of 'this' occurs. |
||
6661 | /// |
||
6662 | /// \param Explicit Whether 'this' is explicitly captured in a lambda |
||
6663 | /// capture list. |
||
6664 | /// |
||
6665 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
||
6666 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
||
6667 | /// This is useful when enclosing lambdas must speculatively capture |
||
6668 | /// 'this' that may or may not be used in certain specializations of |
||
6669 | /// a nested generic lambda (depending on whether the name resolves to |
||
6670 | /// a non-static member function or a static function). |
||
6671 | /// \return returns 'true' if failed, 'false' if success. |
||
6672 | bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false, |
||
6673 | bool BuildAndDiagnose = true, |
||
6674 | const unsigned *const FunctionScopeIndexToStopAt = nullptr, |
||
6675 | bool ByCopy = false); |
||
6676 | |||
6677 | /// Determine whether the given type is the type of *this that is used |
||
6678 | /// outside of the body of a member function for a type that is currently |
||
6679 | /// being defined. |
||
6680 | bool isThisOutsideMemberFunctionBody(QualType BaseType); |
||
6681 | |||
6682 | /// ActOnCXXBoolLiteral - Parse {true,false} literals. |
||
6683 | ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
||
6684 | |||
6685 | |||
6686 | /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals. |
||
6687 | ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
||
6688 | |||
6689 | ExprResult |
||
6690 | ActOnObjCAvailabilityCheckExpr(llvm::ArrayRef<AvailabilitySpec> AvailSpecs, |
||
6691 | SourceLocation AtLoc, SourceLocation RParen); |
||
6692 | |||
6693 | /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. |
||
6694 | ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); |
||
6695 | |||
6696 | //// ActOnCXXThrow - Parse throw expressions. |
||
6697 | ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); |
||
6698 | ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, |
||
6699 | bool IsThrownVarInScope); |
||
6700 | bool CheckCXXThrowOperand(SourceLocation ThrowLoc, QualType ThrowTy, Expr *E); |
||
6701 | |||
6702 | /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. |
||
6703 | /// Can be interpreted either as function-style casting ("int(x)") |
||
6704 | /// or class type construction ("ClassType(x,y,z)") |
||
6705 | /// or creation of a value-initialized type ("int()"). |
||
6706 | ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, |
||
6707 | SourceLocation LParenOrBraceLoc, |
||
6708 | MultiExprArg Exprs, |
||
6709 | SourceLocation RParenOrBraceLoc, |
||
6710 | bool ListInitialization); |
||
6711 | |||
6712 | ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, |
||
6713 | SourceLocation LParenLoc, |
||
6714 | MultiExprArg Exprs, |
||
6715 | SourceLocation RParenLoc, |
||
6716 | bool ListInitialization); |
||
6717 | |||
6718 | /// ActOnCXXNew - Parsed a C++ 'new' expression. |
||
6719 | ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, |
||
6720 | SourceLocation PlacementLParen, |
||
6721 | MultiExprArg PlacementArgs, |
||
6722 | SourceLocation PlacementRParen, |
||
6723 | SourceRange TypeIdParens, Declarator &D, |
||
6724 | Expr *Initializer); |
||
6725 | ExprResult |
||
6726 | BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, |
||
6727 | MultiExprArg PlacementArgs, SourceLocation PlacementRParen, |
||
6728 | SourceRange TypeIdParens, QualType AllocType, |
||
6729 | TypeSourceInfo *AllocTypeInfo, std::optional<Expr *> ArraySize, |
||
6730 | SourceRange DirectInitRange, Expr *Initializer); |
||
6731 | |||
6732 | /// Determine whether \p FD is an aligned allocation or deallocation |
||
6733 | /// function that is unavailable. |
||
6734 | bool isUnavailableAlignedAllocationFunction(const FunctionDecl &FD) const; |
||
6735 | |||
6736 | /// Produce diagnostics if \p FD is an aligned allocation or deallocation |
||
6737 | /// function that is unavailable. |
||
6738 | void diagnoseUnavailableAlignedAllocation(const FunctionDecl &FD, |
||
6739 | SourceLocation Loc); |
||
6740 | |||
6741 | bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, |
||
6742 | SourceRange R); |
||
6743 | |||
6744 | /// The scope in which to find allocation functions. |
||
6745 | enum AllocationFunctionScope { |
||
6746 | /// Only look for allocation functions in the global scope. |
||
6747 | AFS_Global, |
||
6748 | /// Only look for allocation functions in the scope of the |
||
6749 | /// allocated class. |
||
6750 | AFS_Class, |
||
6751 | /// Look for allocation functions in both the global scope |
||
6752 | /// and in the scope of the allocated class. |
||
6753 | AFS_Both |
||
6754 | }; |
||
6755 | |||
6756 | /// Finds the overloads of operator new and delete that are appropriate |
||
6757 | /// for the allocation. |
||
6758 | bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, |
||
6759 | AllocationFunctionScope NewScope, |
||
6760 | AllocationFunctionScope DeleteScope, |
||
6761 | QualType AllocType, bool IsArray, |
||
6762 | bool &PassAlignment, MultiExprArg PlaceArgs, |
||
6763 | FunctionDecl *&OperatorNew, |
||
6764 | FunctionDecl *&OperatorDelete, |
||
6765 | bool Diagnose = true); |
||
6766 | void DeclareGlobalNewDelete(); |
||
6767 | void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, |
||
6768 | ArrayRef<QualType> Params); |
||
6769 | |||
6770 | bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, |
||
6771 | DeclarationName Name, FunctionDecl *&Operator, |
||
6772 | bool Diagnose = true, bool WantSize = false, |
||
6773 | bool WantAligned = false); |
||
6774 | FunctionDecl *FindUsualDeallocationFunction(SourceLocation StartLoc, |
||
6775 | bool CanProvideSize, |
||
6776 | bool Overaligned, |
||
6777 | DeclarationName Name); |
||
6778 | FunctionDecl *FindDeallocationFunctionForDestructor(SourceLocation StartLoc, |
||
6779 | CXXRecordDecl *RD); |
||
6780 | |||
6781 | /// ActOnCXXDelete - Parsed a C++ 'delete' expression |
||
6782 | ExprResult ActOnCXXDelete(SourceLocation StartLoc, |
||
6783 | bool UseGlobal, bool ArrayForm, |
||
6784 | Expr *Operand); |
||
6785 | void CheckVirtualDtorCall(CXXDestructorDecl *dtor, SourceLocation Loc, |
||
6786 | bool IsDelete, bool CallCanBeVirtual, |
||
6787 | bool WarnOnNonAbstractTypes, |
||
6788 | SourceLocation DtorLoc); |
||
6789 | |||
6790 | ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, |
||
6791 | Expr *Operand, SourceLocation RParen); |
||
6792 | ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, |
||
6793 | SourceLocation RParen); |
||
6794 | |||
6795 | /// Parsed one of the type trait support pseudo-functions. |
||
6796 | ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
||
6797 | ArrayRef<ParsedType> Args, |
||
6798 | SourceLocation RParenLoc); |
||
6799 | ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
||
6800 | ArrayRef<TypeSourceInfo *> Args, |
||
6801 | SourceLocation RParenLoc); |
||
6802 | |||
6803 | /// ActOnArrayTypeTrait - Parsed one of the binary type trait support |
||
6804 | /// pseudo-functions. |
||
6805 | ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, |
||
6806 | SourceLocation KWLoc, |
||
6807 | ParsedType LhsTy, |
||
6808 | Expr *DimExpr, |
||
6809 | SourceLocation RParen); |
||
6810 | |||
6811 | ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, |
||
6812 | SourceLocation KWLoc, |
||
6813 | TypeSourceInfo *TSInfo, |
||
6814 | Expr *DimExpr, |
||
6815 | SourceLocation RParen); |
||
6816 | |||
6817 | /// ActOnExpressionTrait - Parsed one of the unary type trait support |
||
6818 | /// pseudo-functions. |
||
6819 | ExprResult ActOnExpressionTrait(ExpressionTrait OET, |
||
6820 | SourceLocation KWLoc, |
||
6821 | Expr *Queried, |
||
6822 | SourceLocation RParen); |
||
6823 | |||
6824 | ExprResult BuildExpressionTrait(ExpressionTrait OET, |
||
6825 | SourceLocation KWLoc, |
||
6826 | Expr *Queried, |
||
6827 | SourceLocation RParen); |
||
6828 | |||
6829 | ExprResult ActOnStartCXXMemberReference(Scope *S, |
||
6830 | Expr *Base, |
||
6831 | SourceLocation OpLoc, |
||
6832 | tok::TokenKind OpKind, |
||
6833 | ParsedType &ObjectType, |
||
6834 | bool &MayBePseudoDestructor); |
||
6835 | |||
6836 | ExprResult BuildPseudoDestructorExpr(Expr *Base, |
||
6837 | SourceLocation OpLoc, |
||
6838 | tok::TokenKind OpKind, |
||
6839 | const CXXScopeSpec &SS, |
||
6840 | TypeSourceInfo *ScopeType, |
||
6841 | SourceLocation CCLoc, |
||
6842 | SourceLocation TildeLoc, |
||
6843 | PseudoDestructorTypeStorage DestroyedType); |
||
6844 | |||
6845 | ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, |
||
6846 | SourceLocation OpLoc, |
||
6847 | tok::TokenKind OpKind, |
||
6848 | CXXScopeSpec &SS, |
||
6849 | UnqualifiedId &FirstTypeName, |
||
6850 | SourceLocation CCLoc, |
||
6851 | SourceLocation TildeLoc, |
||
6852 | UnqualifiedId &SecondTypeName); |
||
6853 | |||
6854 | ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, |
||
6855 | SourceLocation OpLoc, |
||
6856 | tok::TokenKind OpKind, |
||
6857 | SourceLocation TildeLoc, |
||
6858 | const DeclSpec& DS); |
||
6859 | |||
6860 | /// MaybeCreateExprWithCleanups - If the current full-expression |
||
6861 | /// requires any cleanups, surround it with a ExprWithCleanups node. |
||
6862 | /// Otherwise, just returns the passed-in expression. |
||
6863 | Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); |
||
6864 | Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); |
||
6865 | ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); |
||
6866 | |||
6867 | MaterializeTemporaryExpr * |
||
6868 | CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, |
||
6869 | bool BoundToLvalueReference); |
||
6870 | |||
6871 | ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue) { |
||
6872 | return ActOnFinishFullExpr( |
||
6873 | Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue); |
||
6874 | } |
||
6875 | ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC, |
||
6876 | bool DiscardedValue, bool IsConstexpr = false, |
||
6877 | bool IsTemplateArgument = false); |
||
6878 | StmtResult ActOnFinishFullStmt(Stmt *Stmt); |
||
6879 | |||
6880 | // Marks SS invalid if it represents an incomplete type. |
||
6881 | bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); |
||
6882 | // Complete an enum decl, maybe without a scope spec. |
||
6883 | bool RequireCompleteEnumDecl(EnumDecl *D, SourceLocation L, |
||
6884 | CXXScopeSpec *SS = nullptr); |
||
6885 | |||
6886 | DeclContext *computeDeclContext(QualType T); |
||
6887 | DeclContext *computeDeclContext(const CXXScopeSpec &SS, |
||
6888 | bool EnteringContext = false); |
||
6889 | bool isDependentScopeSpecifier(const CXXScopeSpec &SS); |
||
6890 | CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); |
||
6891 | |||
6892 | /// The parser has parsed a global nested-name-specifier '::'. |
||
6893 | /// |
||
6894 | /// \param CCLoc The location of the '::'. |
||
6895 | /// |
||
6896 | /// \param SS The nested-name-specifier, which will be updated in-place |
||
6897 | /// to reflect the parsed nested-name-specifier. |
||
6898 | /// |
||
6899 | /// \returns true if an error occurred, false otherwise. |
||
6900 | bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS); |
||
6901 | |||
6902 | /// The parser has parsed a '__super' nested-name-specifier. |
||
6903 | /// |
||
6904 | /// \param SuperLoc The location of the '__super' keyword. |
||
6905 | /// |
||
6906 | /// \param ColonColonLoc The location of the '::'. |
||
6907 | /// |
||
6908 | /// \param SS The nested-name-specifier, which will be updated in-place |
||
6909 | /// to reflect the parsed nested-name-specifier. |
||
6910 | /// |
||
6911 | /// \returns true if an error occurred, false otherwise. |
||
6912 | bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc, |
||
6913 | SourceLocation ColonColonLoc, CXXScopeSpec &SS); |
||
6914 | |||
6915 | bool isAcceptableNestedNameSpecifier(const NamedDecl *SD, |
||
6916 | bool *CanCorrect = nullptr); |
||
6917 | NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); |
||
6918 | |||
6919 | /// Keeps information about an identifier in a nested-name-spec. |
||
6920 | /// |
||
6921 | struct NestedNameSpecInfo { |
||
6922 | /// The type of the object, if we're parsing nested-name-specifier in |
||
6923 | /// a member access expression. |
||
6924 | ParsedType ObjectType; |
||
6925 | |||
6926 | /// The identifier preceding the '::'. |
||
6927 | IdentifierInfo *Identifier; |
||
6928 | |||
6929 | /// The location of the identifier. |
||
6930 | SourceLocation IdentifierLoc; |
||
6931 | |||
6932 | /// The location of the '::'. |
||
6933 | SourceLocation CCLoc; |
||
6934 | |||
6935 | /// Creates info object for the most typical case. |
||
6936 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
||
6937 | SourceLocation ColonColonLoc, ParsedType ObjectType = ParsedType()) |
||
6938 | : ObjectType(ObjectType), Identifier(II), IdentifierLoc(IdLoc), |
||
6939 | CCLoc(ColonColonLoc) { |
||
6940 | } |
||
6941 | |||
6942 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
||
6943 | SourceLocation ColonColonLoc, QualType ObjectType) |
||
6944 | : ObjectType(ParsedType::make(ObjectType)), Identifier(II), |
||
6945 | IdentifierLoc(IdLoc), CCLoc(ColonColonLoc) { |
||
6946 | } |
||
6947 | }; |
||
6948 | |||
6949 | bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, |
||
6950 | NestedNameSpecInfo &IdInfo); |
||
6951 | |||
6952 | bool BuildCXXNestedNameSpecifier(Scope *S, |
||
6953 | NestedNameSpecInfo &IdInfo, |
||
6954 | bool EnteringContext, |
||
6955 | CXXScopeSpec &SS, |
||
6956 | NamedDecl *ScopeLookupResult, |
||
6957 | bool ErrorRecoveryLookup, |
||
6958 | bool *IsCorrectedToColon = nullptr, |
||
6959 | bool OnlyNamespace = false); |
||
6960 | |||
6961 | /// The parser has parsed a nested-name-specifier 'identifier::'. |
||
6962 | /// |
||
6963 | /// \param S The scope in which this nested-name-specifier occurs. |
||
6964 | /// |
||
6965 | /// \param IdInfo Parser information about an identifier in the |
||
6966 | /// nested-name-spec. |
||
6967 | /// |
||
6968 | /// \param EnteringContext Whether we're entering the context nominated by |
||
6969 | /// this nested-name-specifier. |
||
6970 | /// |
||
6971 | /// \param SS The nested-name-specifier, which is both an input |
||
6972 | /// parameter (the nested-name-specifier before this type) and an |
||
6973 | /// output parameter (containing the full nested-name-specifier, |
||
6974 | /// including this new type). |
||
6975 | /// |
||
6976 | /// \param IsCorrectedToColon If not null, suggestions to replace '::' -> ':' |
||
6977 | /// are allowed. The bool value pointed by this parameter is set to 'true' |
||
6978 | /// if the identifier is treated as if it was followed by ':', not '::'. |
||
6979 | /// |
||
6980 | /// \param OnlyNamespace If true, only considers namespaces in lookup. |
||
6981 | /// |
||
6982 | /// \returns true if an error occurred, false otherwise. |
||
6983 | bool ActOnCXXNestedNameSpecifier(Scope *S, |
||
6984 | NestedNameSpecInfo &IdInfo, |
||
6985 | bool EnteringContext, |
||
6986 | CXXScopeSpec &SS, |
||
6987 | bool *IsCorrectedToColon = nullptr, |
||
6988 | bool OnlyNamespace = false); |
||
6989 | |||
6990 | ExprResult ActOnDecltypeExpression(Expr *E); |
||
6991 | |||
6992 | bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, |
||
6993 | const DeclSpec &DS, |
||
6994 | SourceLocation ColonColonLoc); |
||
6995 | |||
6996 | bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, |
||
6997 | NestedNameSpecInfo &IdInfo, |
||
6998 | bool EnteringContext); |
||
6999 | |||
7000 | /// The parser has parsed a nested-name-specifier |
||
7001 | /// 'template[opt] template-name < template-args >::'. |
||
7002 | /// |
||
7003 | /// \param S The scope in which this nested-name-specifier occurs. |
||
7004 | /// |
||
7005 | /// \param SS The nested-name-specifier, which is both an input |
||
7006 | /// parameter (the nested-name-specifier before this type) and an |
||
7007 | /// output parameter (containing the full nested-name-specifier, |
||
7008 | /// including this new type). |
||
7009 | /// |
||
7010 | /// \param TemplateKWLoc the location of the 'template' keyword, if any. |
||
7011 | /// \param TemplateName the template name. |
||
7012 | /// \param TemplateNameLoc The location of the template name. |
||
7013 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
||
7014 | /// \param TemplateArgs The template arguments. |
||
7015 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
||
7016 | /// \param CCLoc The location of the '::'. |
||
7017 | /// |
||
7018 | /// \param EnteringContext Whether we're entering the context of the |
||
7019 | /// nested-name-specifier. |
||
7020 | /// |
||
7021 | /// |
||
7022 | /// \returns true if an error occurred, false otherwise. |
||
7023 | bool ActOnCXXNestedNameSpecifier(Scope *S, |
||
7024 | CXXScopeSpec &SS, |
||
7025 | SourceLocation TemplateKWLoc, |
||
7026 | TemplateTy TemplateName, |
||
7027 | SourceLocation TemplateNameLoc, |
||
7028 | SourceLocation LAngleLoc, |
||
7029 | ASTTemplateArgsPtr TemplateArgs, |
||
7030 | SourceLocation RAngleLoc, |
||
7031 | SourceLocation CCLoc, |
||
7032 | bool EnteringContext); |
||
7033 | |||
7034 | /// Given a C++ nested-name-specifier, produce an annotation value |
||
7035 | /// that the parser can use later to reconstruct the given |
||
7036 | /// nested-name-specifier. |
||
7037 | /// |
||
7038 | /// \param SS A nested-name-specifier. |
||
7039 | /// |
||
7040 | /// \returns A pointer containing all of the information in the |
||
7041 | /// nested-name-specifier \p SS. |
||
7042 | void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); |
||
7043 | |||
7044 | /// Given an annotation pointer for a nested-name-specifier, restore |
||
7045 | /// the nested-name-specifier structure. |
||
7046 | /// |
||
7047 | /// \param Annotation The annotation pointer, produced by |
||
7048 | /// \c SaveNestedNameSpecifierAnnotation(). |
||
7049 | /// |
||
7050 | /// \param AnnotationRange The source range corresponding to the annotation. |
||
7051 | /// |
||
7052 | /// \param SS The nested-name-specifier that will be updated with the contents |
||
7053 | /// of the annotation pointer. |
||
7054 | void RestoreNestedNameSpecifierAnnotation(void *Annotation, |
||
7055 | SourceRange AnnotationRange, |
||
7056 | CXXScopeSpec &SS); |
||
7057 | |||
7058 | bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
||
7059 | |||
7060 | /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global |
||
7061 | /// scope or nested-name-specifier) is parsed, part of a declarator-id. |
||
7062 | /// After this method is called, according to [C++ 3.4.3p3], names should be |
||
7063 | /// looked up in the declarator-id's scope, until the declarator is parsed and |
||
7064 | /// ActOnCXXExitDeclaratorScope is called. |
||
7065 | /// The 'SS' should be a non-empty valid CXXScopeSpec. |
||
7066 | bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); |
||
7067 | |||
7068 | /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously |
||
7069 | /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same |
||
7070 | /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. |
||
7071 | /// Used to indicate that names should revert to being looked up in the |
||
7072 | /// defining scope. |
||
7073 | void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
||
7074 | |||
7075 | /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an |
||
7076 | /// initializer for the declaration 'Dcl'. |
||
7077 | /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a |
||
7078 | /// static data member of class X, names should be looked up in the scope of |
||
7079 | /// class X. |
||
7080 | void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); |
||
7081 | |||
7082 | /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an |
||
7083 | /// initializer for the declaration 'Dcl'. |
||
7084 | void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); |
||
7085 | |||
7086 | /// Create a new lambda closure type. |
||
7087 | CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange, |
||
7088 | TypeSourceInfo *Info, |
||
7089 | unsigned LambdaDependencyKind, |
||
7090 | LambdaCaptureDefault CaptureDefault); |
||
7091 | |||
7092 | /// Start the definition of a lambda expression. |
||
7093 | CXXMethodDecl * |
||
7094 | startLambdaDefinition(CXXRecordDecl *Class, SourceRange IntroducerRange, |
||
7095 | TypeSourceInfo *MethodType, SourceLocation EndLoc, |
||
7096 | ArrayRef<ParmVarDecl *> Params, |
||
7097 | ConstexprSpecKind ConstexprKind, StorageClass SC, |
||
7098 | Expr *TrailingRequiresClause); |
||
7099 | |||
7100 | /// Number lambda for linkage purposes if necessary. |
||
7101 | void handleLambdaNumbering( |
||
7102 | CXXRecordDecl *Class, CXXMethodDecl *Method, |
||
7103 | std::optional<std::tuple<bool, unsigned, unsigned, Decl *>> Mangling = |
||
7104 | std::nullopt); |
||
7105 | |||
7106 | /// Endow the lambda scope info with the relevant properties. |
||
7107 | void buildLambdaScope(sema::LambdaScopeInfo *LSI, |
||
7108 | CXXMethodDecl *CallOperator, |
||
7109 | SourceRange IntroducerRange, |
||
7110 | LambdaCaptureDefault CaptureDefault, |
||
7111 | SourceLocation CaptureDefaultLoc, |
||
7112 | bool ExplicitParams, |
||
7113 | bool ExplicitResultType, |
||
7114 | bool Mutable); |
||
7115 | |||
7116 | /// Perform initialization analysis of the init-capture and perform |
||
7117 | /// any implicit conversions such as an lvalue-to-rvalue conversion if |
||
7118 | /// not being used to initialize a reference. |
||
7119 | ParsedType actOnLambdaInitCaptureInitialization( |
||
7120 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
||
7121 | IdentifierInfo *Id, LambdaCaptureInitKind InitKind, Expr *&Init) { |
||
7122 | return ParsedType::make(buildLambdaInitCaptureInitialization( |
||
7123 | Loc, ByRef, EllipsisLoc, std::nullopt, Id, |
||
7124 | InitKind != LambdaCaptureInitKind::CopyInit, Init)); |
||
7125 | } |
||
7126 | QualType buildLambdaInitCaptureInitialization( |
||
7127 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
||
7128 | std::optional<unsigned> NumExpansions, IdentifierInfo *Id, |
||
7129 | bool DirectInit, Expr *&Init); |
||
7130 | |||
7131 | /// Create a dummy variable within the declcontext of the lambda's |
||
7132 | /// call operator, for name lookup purposes for a lambda init capture. |
||
7133 | /// |
||
7134 | /// CodeGen handles emission of lambda captures, ignoring these dummy |
||
7135 | /// variables appropriately. |
||
7136 | VarDecl *createLambdaInitCaptureVarDecl(SourceLocation Loc, |
||
7137 | QualType InitCaptureType, |
||
7138 | SourceLocation EllipsisLoc, |
||
7139 | IdentifierInfo *Id, |
||
7140 | unsigned InitStyle, Expr *Init); |
||
7141 | |||
7142 | /// Add an init-capture to a lambda scope. |
||
7143 | void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var, |
||
7144 | bool isReferenceType); |
||
7145 | |||
7146 | /// Note that we have finished the explicit captures for the |
||
7147 | /// given lambda. |
||
7148 | void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI); |
||
7149 | |||
7150 | /// \brief This is called after parsing the explicit template parameter list |
||
7151 | /// on a lambda (if it exists) in C++2a. |
||
7152 | void ActOnLambdaExplicitTemplateParameterList(SourceLocation LAngleLoc, |
||
7153 | ArrayRef<NamedDecl *> TParams, |
||
7154 | SourceLocation RAngleLoc, |
||
7155 | ExprResult RequiresClause); |
||
7156 | |||
7157 | /// Introduce the lambda parameters into scope. |
||
7158 | void addLambdaParameters( |
||
7159 | ArrayRef<LambdaIntroducer::LambdaCapture> Captures, |
||
7160 | CXXMethodDecl *CallOperator, Scope *CurScope); |
||
7161 | |||
7162 | /// Deduce a block or lambda's return type based on the return |
||
7163 | /// statements present in the body. |
||
7164 | void deduceClosureReturnType(sema::CapturingScopeInfo &CSI); |
||
7165 | |||
7166 | /// ActOnStartOfLambdaDefinition - This is called just before we start |
||
7167 | /// parsing the body of a lambda; it analyzes the explicit captures and |
||
7168 | /// arguments, and sets up various data-structures for the body of the |
||
7169 | /// lambda. |
||
7170 | void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, |
||
7171 | Declarator &ParamInfo, Scope *CurScope); |
||
7172 | |||
7173 | /// ActOnLambdaError - If there is an error parsing a lambda, this callback |
||
7174 | /// is invoked to pop the information about the lambda. |
||
7175 | void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, |
||
7176 | bool IsInstantiation = false); |
||
7177 | |||
7178 | /// ActOnLambdaExpr - This is called when the body of a lambda expression |
||
7179 | /// was successfully completed. |
||
7180 | ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, |
||
7181 | Scope *CurScope); |
||
7182 | |||
7183 | /// Does copying/destroying the captured variable have side effects? |
||
7184 | bool CaptureHasSideEffects(const sema::Capture &From); |
||
7185 | |||
7186 | /// Diagnose if an explicit lambda capture is unused. Returns true if a |
||
7187 | /// diagnostic is emitted. |
||
7188 | bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange, |
||
7189 | const sema::Capture &From); |
||
7190 | |||
7191 | /// Build a FieldDecl suitable to hold the given capture. |
||
7192 | FieldDecl *BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture); |
||
7193 | |||
7194 | /// Initialize the given capture with a suitable expression. |
||
7195 | ExprResult BuildCaptureInit(const sema::Capture &Capture, |
||
7196 | SourceLocation ImplicitCaptureLoc, |
||
7197 | bool IsOpenMPMapping = false); |
||
7198 | |||
7199 | /// Complete a lambda-expression having processed and attached the |
||
7200 | /// lambda body. |
||
7201 | ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, |
||
7202 | sema::LambdaScopeInfo *LSI); |
||
7203 | |||
7204 | /// Get the return type to use for a lambda's conversion function(s) to |
||
7205 | /// function pointer type, given the type of the call operator. |
||
7206 | QualType |
||
7207 | getLambdaConversionFunctionResultType(const FunctionProtoType *CallOpType, |
||
7208 | CallingConv CC); |
||
7209 | |||
7210 | /// Define the "body" of the conversion from a lambda object to a |
||
7211 | /// function pointer. |
||
7212 | /// |
||
7213 | /// This routine doesn't actually define a sensible body; rather, it fills |
||
7214 | /// in the initialization expression needed to copy the lambda object into |
||
7215 | /// the block, and IR generation actually generates the real body of the |
||
7216 | /// block pointer conversion. |
||
7217 | void DefineImplicitLambdaToFunctionPointerConversion( |
||
7218 | SourceLocation CurrentLoc, CXXConversionDecl *Conv); |
||
7219 | |||
7220 | /// Define the "body" of the conversion from a lambda object to a |
||
7221 | /// block pointer. |
||
7222 | /// |
||
7223 | /// This routine doesn't actually define a sensible body; rather, it fills |
||
7224 | /// in the initialization expression needed to copy the lambda object into |
||
7225 | /// the block, and IR generation actually generates the real body of the |
||
7226 | /// block pointer conversion. |
||
7227 | void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc, |
||
7228 | CXXConversionDecl *Conv); |
||
7229 | |||
7230 | ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, |
||
7231 | SourceLocation ConvLocation, |
||
7232 | CXXConversionDecl *Conv, |
||
7233 | Expr *Src); |
||
7234 | |||
7235 | /// Check whether the given expression is a valid constraint expression. |
||
7236 | /// A diagnostic is emitted if it is not, false is returned, and |
||
7237 | /// PossibleNonPrimary will be set to true if the failure might be due to a |
||
7238 | /// non-primary expression being used as an atomic constraint. |
||
7239 | bool CheckConstraintExpression(const Expr *CE, Token NextToken = Token(), |
||
7240 | bool *PossibleNonPrimary = nullptr, |
||
7241 | bool IsTrailingRequiresClause = false); |
||
7242 | |||
7243 | private: |
||
7244 | /// Caches pairs of template-like decls whose associated constraints were |
||
7245 | /// checked for subsumption and whether or not the first's constraints did in |
||
7246 | /// fact subsume the second's. |
||
7247 | llvm::DenseMap<std::pair<NamedDecl *, NamedDecl *>, bool> SubsumptionCache; |
||
7248 | /// Caches the normalized associated constraints of declarations (concepts or |
||
7249 | /// constrained declarations). If an error occurred while normalizing the |
||
7250 | /// associated constraints of the template or concept, nullptr will be cached |
||
7251 | /// here. |
||
7252 | llvm::DenseMap<NamedDecl *, NormalizedConstraint *> |
||
7253 | NormalizationCache; |
||
7254 | |||
7255 | llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &> |
||
7256 | SatisfactionCache; |
||
7257 | |||
7258 | /// Introduce the instantiated function parameters into the local |
||
7259 | /// instantiation scope, and set the parameter names to those used |
||
7260 | /// in the template. |
||
7261 | bool addInstantiatedParametersToScope( |
||
7262 | FunctionDecl *Function, const FunctionDecl *PatternDecl, |
||
7263 | LocalInstantiationScope &Scope, |
||
7264 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
7265 | |||
7266 | /// used by SetupConstraintCheckingTemplateArgumentsAndScope to recursively(in |
||
7267 | /// the case of lambdas) set up the LocalInstantiationScope of the current |
||
7268 | /// function. |
||
7269 | bool SetupConstraintScope( |
||
7270 | FunctionDecl *FD, std::optional<ArrayRef<TemplateArgument>> TemplateArgs, |
||
7271 | MultiLevelTemplateArgumentList MLTAL, LocalInstantiationScope &Scope); |
||
7272 | |||
7273 | /// Used during constraint checking, sets up the constraint template argument |
||
7274 | /// lists, and calls SetupConstraintScope to set up the |
||
7275 | /// LocalInstantiationScope to have the proper set of ParVarDecls configured. |
||
7276 | std::optional<MultiLevelTemplateArgumentList> |
||
7277 | SetupConstraintCheckingTemplateArgumentsAndScope( |
||
7278 | FunctionDecl *FD, std::optional<ArrayRef<TemplateArgument>> TemplateArgs, |
||
7279 | LocalInstantiationScope &Scope); |
||
7280 | |||
7281 | private: |
||
7282 | // The current stack of constraint satisfactions, so we can exit-early. |
||
7283 | using SatisfactionStackEntryTy = |
||
7284 | std::pair<const NamedDecl *, llvm::FoldingSetNodeID>; |
||
7285 | llvm::SmallVector<SatisfactionStackEntryTy, 10> |
||
7286 | SatisfactionStack; |
||
7287 | |||
7288 | public: |
||
7289 | void PushSatisfactionStackEntry(const NamedDecl *D, |
||
7290 | const llvm::FoldingSetNodeID &ID) { |
||
7291 | const NamedDecl *Can = cast<NamedDecl>(D->getCanonicalDecl()); |
||
7292 | SatisfactionStack.emplace_back(Can, ID); |
||
7293 | } |
||
7294 | |||
7295 | void PopSatisfactionStackEntry() { SatisfactionStack.pop_back(); } |
||
7296 | |||
7297 | bool SatisfactionStackContains(const NamedDecl *D, |
||
7298 | const llvm::FoldingSetNodeID &ID) const { |
||
7299 | const NamedDecl *Can = cast<NamedDecl>(D->getCanonicalDecl()); |
||
7300 | return llvm::find(SatisfactionStack, |
||
7301 | SatisfactionStackEntryTy{Can, ID}) != |
||
7302 | SatisfactionStack.end(); |
||
7303 | } |
||
7304 | |||
7305 | // Resets the current SatisfactionStack for cases where we are instantiating |
||
7306 | // constraints as a 'side effect' of normal instantiation in a way that is not |
||
7307 | // indicative of recursive definition. |
||
7308 | class SatisfactionStackResetRAII { |
||
7309 | llvm::SmallVector<SatisfactionStackEntryTy, 10> |
||
7310 | BackupSatisfactionStack; |
||
7311 | Sema &SemaRef; |
||
7312 | |||
7313 | public: |
||
7314 | SatisfactionStackResetRAII(Sema &S) : SemaRef(S) { |
||
7315 | SemaRef.SwapSatisfactionStack(BackupSatisfactionStack); |
||
7316 | } |
||
7317 | |||
7318 | ~SatisfactionStackResetRAII() { |
||
7319 | SemaRef.SwapSatisfactionStack(BackupSatisfactionStack); |
||
7320 | } |
||
7321 | }; |
||
7322 | |||
7323 | void SwapSatisfactionStack( |
||
7324 | llvm::SmallVectorImpl<SatisfactionStackEntryTy> &NewSS) { |
||
7325 | SatisfactionStack.swap(NewSS); |
||
7326 | } |
||
7327 | |||
7328 | const NormalizedConstraint * |
||
7329 | getNormalizedAssociatedConstraints( |
||
7330 | NamedDecl *ConstrainedDecl, ArrayRef<const Expr *> AssociatedConstraints); |
||
7331 | |||
7332 | /// \brief Check whether the given declaration's associated constraints are |
||
7333 | /// at least as constrained than another declaration's according to the |
||
7334 | /// partial ordering of constraints. |
||
7335 | /// |
||
7336 | /// \param Result If no error occurred, receives the result of true if D1 is |
||
7337 | /// at least constrained than D2, and false otherwise. |
||
7338 | /// |
||
7339 | /// \returns true if an error occurred, false otherwise. |
||
7340 | bool IsAtLeastAsConstrained(NamedDecl *D1, MutableArrayRef<const Expr *> AC1, |
||
7341 | NamedDecl *D2, MutableArrayRef<const Expr *> AC2, |
||
7342 | bool &Result); |
||
7343 | |||
7344 | /// If D1 was not at least as constrained as D2, but would've been if a pair |
||
7345 | /// of atomic constraints involved had been declared in a concept and not |
||
7346 | /// repeated in two separate places in code. |
||
7347 | /// \returns true if such a diagnostic was emitted, false otherwise. |
||
7348 | bool MaybeEmitAmbiguousAtomicConstraintsDiagnostic(NamedDecl *D1, |
||
7349 | ArrayRef<const Expr *> AC1, NamedDecl *D2, ArrayRef<const Expr *> AC2); |
||
7350 | |||
7351 | /// \brief Check whether the given list of constraint expressions are |
||
7352 | /// satisfied (as if in a 'conjunction') given template arguments. |
||
7353 | /// \param Template the template-like entity that triggered the constraints |
||
7354 | /// check (either a concept or a constrained entity). |
||
7355 | /// \param ConstraintExprs a list of constraint expressions, treated as if |
||
7356 | /// they were 'AND'ed together. |
||
7357 | /// \param TemplateArgLists the list of template arguments to substitute into |
||
7358 | /// the constraint expression. |
||
7359 | /// \param TemplateIDRange The source range of the template id that |
||
7360 | /// caused the constraints check. |
||
7361 | /// \param Satisfaction if true is returned, will contain details of the |
||
7362 | /// satisfaction, with enough information to diagnose an unsatisfied |
||
7363 | /// expression. |
||
7364 | /// \returns true if an error occurred and satisfaction could not be checked, |
||
7365 | /// false otherwise. |
||
7366 | bool CheckConstraintSatisfaction( |
||
7367 | const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs, |
||
7368 | const MultiLevelTemplateArgumentList &TemplateArgLists, |
||
7369 | SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction) { |
||
7370 | llvm::SmallVector<Expr *, 4> Converted; |
||
7371 | return CheckConstraintSatisfaction(Template, ConstraintExprs, Converted, |
||
7372 | TemplateArgLists, TemplateIDRange, |
||
7373 | Satisfaction); |
||
7374 | } |
||
7375 | |||
7376 | /// \brief Check whether the given list of constraint expressions are |
||
7377 | /// satisfied (as if in a 'conjunction') given template arguments. |
||
7378 | /// Additionally, takes an empty list of Expressions which is populated with |
||
7379 | /// the instantiated versions of the ConstraintExprs. |
||
7380 | /// \param Template the template-like entity that triggered the constraints |
||
7381 | /// check (either a concept or a constrained entity). |
||
7382 | /// \param ConstraintExprs a list of constraint expressions, treated as if |
||
7383 | /// they were 'AND'ed together. |
||
7384 | /// \param ConvertedConstraints a out parameter that will get populated with |
||
7385 | /// the instantiated version of the ConstraintExprs if we successfully checked |
||
7386 | /// satisfaction. |
||
7387 | /// \param TemplateArgList the multi-level list of template arguments to |
||
7388 | /// substitute into the constraint expression. This should be relative to the |
||
7389 | /// top-level (hence multi-level), since we need to instantiate fully at the |
||
7390 | /// time of checking. |
||
7391 | /// \param TemplateIDRange The source range of the template id that |
||
7392 | /// caused the constraints check. |
||
7393 | /// \param Satisfaction if true is returned, will contain details of the |
||
7394 | /// satisfaction, with enough information to diagnose an unsatisfied |
||
7395 | /// expression. |
||
7396 | /// \returns true if an error occurred and satisfaction could not be checked, |
||
7397 | /// false otherwise. |
||
7398 | bool CheckConstraintSatisfaction( |
||
7399 | const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs, |
||
7400 | llvm::SmallVectorImpl<Expr *> &ConvertedConstraints, |
||
7401 | const MultiLevelTemplateArgumentList &TemplateArgList, |
||
7402 | SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction); |
||
7403 | |||
7404 | /// \brief Check whether the given non-dependent constraint expression is |
||
7405 | /// satisfied. Returns false and updates Satisfaction with the satisfaction |
||
7406 | /// verdict if successful, emits a diagnostic and returns true if an error |
||
7407 | /// occurred and satisfaction could not be determined. |
||
7408 | /// |
||
7409 | /// \returns true if an error occurred, false otherwise. |
||
7410 | bool CheckConstraintSatisfaction(const Expr *ConstraintExpr, |
||
7411 | ConstraintSatisfaction &Satisfaction); |
||
7412 | |||
7413 | /// Check whether the given function decl's trailing requires clause is |
||
7414 | /// satisfied, if any. Returns false and updates Satisfaction with the |
||
7415 | /// satisfaction verdict if successful, emits a diagnostic and returns true if |
||
7416 | /// an error occurred and satisfaction could not be determined. |
||
7417 | /// |
||
7418 | /// \returns true if an error occurred, false otherwise. |
||
7419 | bool CheckFunctionConstraints(const FunctionDecl *FD, |
||
7420 | ConstraintSatisfaction &Satisfaction, |
||
7421 | SourceLocation UsageLoc = SourceLocation(), |
||
7422 | bool ForOverloadResolution = false); |
||
7423 | |||
7424 | /// \brief Ensure that the given template arguments satisfy the constraints |
||
7425 | /// associated with the given template, emitting a diagnostic if they do not. |
||
7426 | /// |
||
7427 | /// \param Template The template to which the template arguments are being |
||
7428 | /// provided. |
||
7429 | /// |
||
7430 | /// \param TemplateArgs The converted, canonicalized template arguments. |
||
7431 | /// |
||
7432 | /// \param TemplateIDRange The source range of the template id that |
||
7433 | /// caused the constraints check. |
||
7434 | /// |
||
7435 | /// \returns true if the constrains are not satisfied or could not be checked |
||
7436 | /// for satisfaction, false if the constraints are satisfied. |
||
7437 | bool EnsureTemplateArgumentListConstraints( |
||
7438 | TemplateDecl *Template, |
||
7439 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
7440 | SourceRange TemplateIDRange); |
||
7441 | |||
7442 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
||
7443 | /// unsatisfied. |
||
7444 | /// \param First whether this is the first time an unsatisfied constraint is |
||
7445 | /// diagnosed for this error. |
||
7446 | void |
||
7447 | DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction &Satisfaction, |
||
7448 | bool First = true); |
||
7449 | |||
7450 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
||
7451 | /// unsatisfied. |
||
7452 | void |
||
7453 | DiagnoseUnsatisfiedConstraint(const ASTConstraintSatisfaction &Satisfaction, |
||
7454 | bool First = true); |
||
7455 | |||
7456 | // ParseObjCStringLiteral - Parse Objective-C string literals. |
||
7457 | ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, |
||
7458 | ArrayRef<Expr *> Strings); |
||
7459 | |||
7460 | ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S); |
||
7461 | |||
7462 | /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the |
||
7463 | /// numeric literal expression. Type of the expression will be "NSNumber *" |
||
7464 | /// or "id" if NSNumber is unavailable. |
||
7465 | ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number); |
||
7466 | ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc, |
||
7467 | bool Value); |
||
7468 | ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements); |
||
7469 | |||
7470 | /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the |
||
7471 | /// '@' prefixed parenthesized expression. The type of the expression will |
||
7472 | /// either be "NSNumber *", "NSString *" or "NSValue *" depending on the type |
||
7473 | /// of ValueType, which is allowed to be a built-in numeric type, "char *", |
||
7474 | /// "const char *" or C structure with attribute 'objc_boxable'. |
||
7475 | ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr); |
||
7476 | |||
7477 | ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, |
||
7478 | Expr *IndexExpr, |
||
7479 | ObjCMethodDecl *getterMethod, |
||
7480 | ObjCMethodDecl *setterMethod); |
||
7481 | |||
7482 | ExprResult BuildObjCDictionaryLiteral(SourceRange SR, |
||
7483 | MutableArrayRef<ObjCDictionaryElement> Elements); |
||
7484 | |||
7485 | ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, |
||
7486 | TypeSourceInfo *EncodedTypeInfo, |
||
7487 | SourceLocation RParenLoc); |
||
7488 | ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, |
||
7489 | CXXConversionDecl *Method, |
||
7490 | bool HadMultipleCandidates); |
||
7491 | |||
7492 | ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, |
||
7493 | SourceLocation EncodeLoc, |
||
7494 | SourceLocation LParenLoc, |
||
7495 | ParsedType Ty, |
||
7496 | SourceLocation RParenLoc); |
||
7497 | |||
7498 | /// ParseObjCSelectorExpression - Build selector expression for \@selector |
||
7499 | ExprResult ParseObjCSelectorExpression(Selector Sel, |
||
7500 | SourceLocation AtLoc, |
||
7501 | SourceLocation SelLoc, |
||
7502 | SourceLocation LParenLoc, |
||
7503 | SourceLocation RParenLoc, |
||
7504 | bool WarnMultipleSelectors); |
||
7505 | |||
7506 | /// ParseObjCProtocolExpression - Build protocol expression for \@protocol |
||
7507 | ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, |
||
7508 | SourceLocation AtLoc, |
||
7509 | SourceLocation ProtoLoc, |
||
7510 | SourceLocation LParenLoc, |
||
7511 | SourceLocation ProtoIdLoc, |
||
7512 | SourceLocation RParenLoc); |
||
7513 | |||
7514 | //===--------------------------------------------------------------------===// |
||
7515 | // C++ Declarations |
||
7516 | // |
||
7517 | Decl *ActOnStartLinkageSpecification(Scope *S, |
||
7518 | SourceLocation ExternLoc, |
||
7519 | Expr *LangStr, |
||
7520 | SourceLocation LBraceLoc); |
||
7521 | Decl *ActOnFinishLinkageSpecification(Scope *S, |
||
7522 | Decl *LinkageSpec, |
||
7523 | SourceLocation RBraceLoc); |
||
7524 | |||
7525 | |||
7526 | //===--------------------------------------------------------------------===// |
||
7527 | // C++ Classes |
||
7528 | // |
||
7529 | CXXRecordDecl *getCurrentClass(Scope *S, const CXXScopeSpec *SS); |
||
7530 | bool isCurrentClassName(const IdentifierInfo &II, Scope *S, |
||
7531 | const CXXScopeSpec *SS = nullptr); |
||
7532 | bool isCurrentClassNameTypo(IdentifierInfo *&II, const CXXScopeSpec *SS); |
||
7533 | |||
7534 | bool ActOnAccessSpecifier(AccessSpecifier Access, SourceLocation ASLoc, |
||
7535 | SourceLocation ColonLoc, |
||
7536 | const ParsedAttributesView &Attrs); |
||
7537 | |||
7538 | NamedDecl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, |
||
7539 | Declarator &D, |
||
7540 | MultiTemplateParamsArg TemplateParameterLists, |
||
7541 | Expr *BitfieldWidth, const VirtSpecifiers &VS, |
||
7542 | InClassInitStyle InitStyle); |
||
7543 | |||
7544 | void ActOnStartCXXInClassMemberInitializer(); |
||
7545 | void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl, |
||
7546 | SourceLocation EqualLoc, |
||
7547 | Expr *Init); |
||
7548 | |||
7549 | MemInitResult ActOnMemInitializer(Decl *ConstructorD, |
||
7550 | Scope *S, |
||
7551 | CXXScopeSpec &SS, |
||
7552 | IdentifierInfo *MemberOrBase, |
||
7553 | ParsedType TemplateTypeTy, |
||
7554 | const DeclSpec &DS, |
||
7555 | SourceLocation IdLoc, |
||
7556 | SourceLocation LParenLoc, |
||
7557 | ArrayRef<Expr *> Args, |
||
7558 | SourceLocation RParenLoc, |
||
7559 | SourceLocation EllipsisLoc); |
||
7560 | |||
7561 | MemInitResult ActOnMemInitializer(Decl *ConstructorD, |
||
7562 | Scope *S, |
||
7563 | CXXScopeSpec &SS, |
||
7564 | IdentifierInfo *MemberOrBase, |
||
7565 | ParsedType TemplateTypeTy, |
||
7566 | const DeclSpec &DS, |
||
7567 | SourceLocation IdLoc, |
||
7568 | Expr *InitList, |
||
7569 | SourceLocation EllipsisLoc); |
||
7570 | |||
7571 | MemInitResult BuildMemInitializer(Decl *ConstructorD, |
||
7572 | Scope *S, |
||
7573 | CXXScopeSpec &SS, |
||
7574 | IdentifierInfo *MemberOrBase, |
||
7575 | ParsedType TemplateTypeTy, |
||
7576 | const DeclSpec &DS, |
||
7577 | SourceLocation IdLoc, |
||
7578 | Expr *Init, |
||
7579 | SourceLocation EllipsisLoc); |
||
7580 | |||
7581 | MemInitResult BuildMemberInitializer(ValueDecl *Member, |
||
7582 | Expr *Init, |
||
7583 | SourceLocation IdLoc); |
||
7584 | |||
7585 | MemInitResult BuildBaseInitializer(QualType BaseType, |
||
7586 | TypeSourceInfo *BaseTInfo, |
||
7587 | Expr *Init, |
||
7588 | CXXRecordDecl *ClassDecl, |
||
7589 | SourceLocation EllipsisLoc); |
||
7590 | |||
7591 | MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, |
||
7592 | Expr *Init, |
||
7593 | CXXRecordDecl *ClassDecl); |
||
7594 | |||
7595 | bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, |
||
7596 | CXXCtorInitializer *Initializer); |
||
7597 | |||
7598 | bool SetCtorInitializers( |
||
7599 | CXXConstructorDecl *Constructor, bool AnyErrors, |
||
7600 | ArrayRef<CXXCtorInitializer *> Initializers = std::nullopt); |
||
7601 | |||
7602 | void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); |
||
7603 | |||
7604 | |||
7605 | /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, |
||
7606 | /// mark all the non-trivial destructors of its members and bases as |
||
7607 | /// referenced. |
||
7608 | void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, |
||
7609 | CXXRecordDecl *Record); |
||
7610 | |||
7611 | /// Mark destructors of virtual bases of this class referenced. In the Itanium |
||
7612 | /// C++ ABI, this is done when emitting a destructor for any non-abstract |
||
7613 | /// class. In the Microsoft C++ ABI, this is done any time a class's |
||
7614 | /// destructor is referenced. |
||
7615 | void MarkVirtualBaseDestructorsReferenced( |
||
7616 | SourceLocation Location, CXXRecordDecl *ClassDecl, |
||
7617 | llvm::SmallPtrSetImpl<const RecordType *> *DirectVirtualBases = nullptr); |
||
7618 | |||
7619 | /// Do semantic checks to allow the complete destructor variant to be emitted |
||
7620 | /// when the destructor is defined in another translation unit. In the Itanium |
||
7621 | /// C++ ABI, destructor variants are emitted together. In the MS C++ ABI, they |
||
7622 | /// can be emitted in separate TUs. To emit the complete variant, run a subset |
||
7623 | /// of the checks performed when emitting a regular destructor. |
||
7624 | void CheckCompleteDestructorVariant(SourceLocation CurrentLocation, |
||
7625 | CXXDestructorDecl *Dtor); |
||
7626 | |||
7627 | /// The list of classes whose vtables have been used within |
||
7628 | /// this translation unit, and the source locations at which the |
||
7629 | /// first use occurred. |
||
7630 | typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse; |
||
7631 | |||
7632 | /// The list of vtables that are required but have not yet been |
||
7633 | /// materialized. |
||
7634 | SmallVector<VTableUse, 16> VTableUses; |
||
7635 | |||
7636 | /// The set of classes whose vtables have been used within |
||
7637 | /// this translation unit, and a bit that will be true if the vtable is |
||
7638 | /// required to be emitted (otherwise, it should be emitted only if needed |
||
7639 | /// by code generation). |
||
7640 | llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; |
||
7641 | |||
7642 | /// Load any externally-stored vtable uses. |
||
7643 | void LoadExternalVTableUses(); |
||
7644 | |||
7645 | /// Note that the vtable for the given class was used at the |
||
7646 | /// given location. |
||
7647 | void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, |
||
7648 | bool DefinitionRequired = false); |
||
7649 | |||
7650 | /// Mark the exception specifications of all virtual member functions |
||
7651 | /// in the given class as needed. |
||
7652 | void MarkVirtualMemberExceptionSpecsNeeded(SourceLocation Loc, |
||
7653 | const CXXRecordDecl *RD); |
||
7654 | |||
7655 | /// MarkVirtualMembersReferenced - Will mark all members of the given |
||
7656 | /// CXXRecordDecl referenced. |
||
7657 | void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD, |
||
7658 | bool ConstexprOnly = false); |
||
7659 | |||
7660 | /// Define all of the vtables that have been used in this |
||
7661 | /// translation unit and reference any virtual members used by those |
||
7662 | /// vtables. |
||
7663 | /// |
||
7664 | /// \returns true if any work was done, false otherwise. |
||
7665 | bool DefineUsedVTables(); |
||
7666 | |||
7667 | void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); |
||
7668 | |||
7669 | void ActOnMemInitializers(Decl *ConstructorDecl, |
||
7670 | SourceLocation ColonLoc, |
||
7671 | ArrayRef<CXXCtorInitializer*> MemInits, |
||
7672 | bool AnyErrors); |
||
7673 | |||
7674 | /// Check class-level dllimport/dllexport attribute. The caller must |
||
7675 | /// ensure that referenceDLLExportedClassMethods is called some point later |
||
7676 | /// when all outer classes of Class are complete. |
||
7677 | void checkClassLevelDLLAttribute(CXXRecordDecl *Class); |
||
7678 | void checkClassLevelCodeSegAttribute(CXXRecordDecl *Class); |
||
7679 | |||
7680 | void referenceDLLExportedClassMethods(); |
||
7681 | |||
7682 | void propagateDLLAttrToBaseClassTemplate( |
||
7683 | CXXRecordDecl *Class, Attr *ClassAttr, |
||
7684 | ClassTemplateSpecializationDecl *BaseTemplateSpec, |
||
7685 | SourceLocation BaseLoc); |
||
7686 | |||
7687 | /// Add gsl::Pointer attribute to std::container::iterator |
||
7688 | /// \param ND The declaration that introduces the name |
||
7689 | /// std::container::iterator. \param UnderlyingRecord The record named by ND. |
||
7690 | void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord); |
||
7691 | |||
7692 | /// Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types. |
||
7693 | void inferGslOwnerPointerAttribute(CXXRecordDecl *Record); |
||
7694 | |||
7695 | /// Add [[gsl::Pointer]] attributes for std:: types. |
||
7696 | void inferGslPointerAttribute(TypedefNameDecl *TD); |
||
7697 | |||
7698 | void CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record); |
||
7699 | |||
7700 | /// Check that the C++ class annoated with "trivial_abi" satisfies all the |
||
7701 | /// conditions that are needed for the attribute to have an effect. |
||
7702 | void checkIllFormedTrivialABIStruct(CXXRecordDecl &RD); |
||
7703 | |||
7704 | void ActOnFinishCXXMemberSpecification(Scope *S, SourceLocation RLoc, |
||
7705 | Decl *TagDecl, SourceLocation LBrac, |
||
7706 | SourceLocation RBrac, |
||
7707 | const ParsedAttributesView &AttrList); |
||
7708 | void ActOnFinishCXXMemberDecls(); |
||
7709 | void ActOnFinishCXXNonNestedClass(); |
||
7710 | |||
7711 | void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param); |
||
7712 | unsigned ActOnReenterTemplateScope(Decl *Template, |
||
7713 | llvm::function_ref<Scope *()> EnterScope); |
||
7714 | void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); |
||
7715 | void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
||
7716 | void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); |
||
7717 | void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); |
||
7718 | void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
||
7719 | void ActOnFinishDelayedMemberInitializers(Decl *Record); |
||
7720 | void MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD, |
||
7721 | CachedTokens &Toks); |
||
7722 | void UnmarkAsLateParsedTemplate(FunctionDecl *FD); |
||
7723 | bool IsInsideALocalClassWithinATemplateFunction(); |
||
7724 | |||
7725 | Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
||
7726 | Expr *AssertExpr, |
||
7727 | Expr *AssertMessageExpr, |
||
7728 | SourceLocation RParenLoc); |
||
7729 | Decl *BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
||
7730 | Expr *AssertExpr, |
||
7731 | StringLiteral *AssertMessageExpr, |
||
7732 | SourceLocation RParenLoc, |
||
7733 | bool Failed); |
||
7734 | void DiagnoseStaticAssertDetails(const Expr *E); |
||
7735 | |||
7736 | FriendDecl *CheckFriendTypeDecl(SourceLocation LocStart, |
||
7737 | SourceLocation FriendLoc, |
||
7738 | TypeSourceInfo *TSInfo); |
||
7739 | Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, |
||
7740 | MultiTemplateParamsArg TemplateParams); |
||
7741 | NamedDecl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, |
||
7742 | MultiTemplateParamsArg TemplateParams); |
||
7743 | |||
7744 | QualType CheckConstructorDeclarator(Declarator &D, QualType R, |
||
7745 | StorageClass& SC); |
||
7746 | void CheckConstructor(CXXConstructorDecl *Constructor); |
||
7747 | QualType CheckDestructorDeclarator(Declarator &D, QualType R, |
||
7748 | StorageClass& SC); |
||
7749 | bool CheckDestructor(CXXDestructorDecl *Destructor); |
||
7750 | void CheckConversionDeclarator(Declarator &D, QualType &R, |
||
7751 | StorageClass& SC); |
||
7752 | Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); |
||
7753 | void CheckDeductionGuideDeclarator(Declarator &D, QualType &R, |
||
7754 | StorageClass &SC); |
||
7755 | void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD); |
||
7756 | |||
7757 | void CheckExplicitlyDefaultedFunction(Scope *S, FunctionDecl *MD); |
||
7758 | |||
7759 | bool CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD, |
||
7760 | CXXSpecialMember CSM, |
||
7761 | SourceLocation DefaultLoc); |
||
7762 | void CheckDelayedMemberExceptionSpecs(); |
||
7763 | |||
7764 | bool CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *MD, |
||
7765 | DefaultedComparisonKind DCK); |
||
7766 | void DeclareImplicitEqualityComparison(CXXRecordDecl *RD, |
||
7767 | FunctionDecl *Spaceship); |
||
7768 | void DefineDefaultedComparison(SourceLocation Loc, FunctionDecl *FD, |
||
7769 | DefaultedComparisonKind DCK); |
||
7770 | |||
7771 | //===--------------------------------------------------------------------===// |
||
7772 | // C++ Derived Classes |
||
7773 | // |
||
7774 | |||
7775 | /// ActOnBaseSpecifier - Parsed a base specifier |
||
7776 | CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, |
||
7777 | SourceRange SpecifierRange, |
||
7778 | bool Virtual, AccessSpecifier Access, |
||
7779 | TypeSourceInfo *TInfo, |
||
7780 | SourceLocation EllipsisLoc); |
||
7781 | |||
7782 | BaseResult ActOnBaseSpecifier(Decl *classdecl, SourceRange SpecifierRange, |
||
7783 | const ParsedAttributesView &Attrs, bool Virtual, |
||
7784 | AccessSpecifier Access, ParsedType basetype, |
||
7785 | SourceLocation BaseLoc, |
||
7786 | SourceLocation EllipsisLoc); |
||
7787 | |||
7788 | bool AttachBaseSpecifiers(CXXRecordDecl *Class, |
||
7789 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
||
7790 | void ActOnBaseSpecifiers(Decl *ClassDecl, |
||
7791 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
||
7792 | |||
7793 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base); |
||
7794 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base, |
||
7795 | CXXBasePaths &Paths); |
||
7796 | |||
7797 | // FIXME: I don't like this name. |
||
7798 | void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); |
||
7799 | |||
7800 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
||
7801 | SourceLocation Loc, SourceRange Range, |
||
7802 | CXXCastPath *BasePath = nullptr, |
||
7803 | bool IgnoreAccess = false); |
||
7804 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
||
7805 | unsigned InaccessibleBaseID, |
||
7806 | unsigned AmbiguousBaseConvID, |
||
7807 | SourceLocation Loc, SourceRange Range, |
||
7808 | DeclarationName Name, |
||
7809 | CXXCastPath *BasePath, |
||
7810 | bool IgnoreAccess = false); |
||
7811 | |||
7812 | std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); |
||
7813 | |||
7814 | bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New, |
||
7815 | const CXXMethodDecl *Old); |
||
7816 | |||
7817 | /// CheckOverridingFunctionReturnType - Checks whether the return types are |
||
7818 | /// covariant, according to C++ [class.virtual]p5. |
||
7819 | bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, |
||
7820 | const CXXMethodDecl *Old); |
||
7821 | |||
7822 | /// CheckOverridingFunctionExceptionSpec - Checks whether the exception |
||
7823 | /// spec is a subset of base spec. |
||
7824 | bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, |
||
7825 | const CXXMethodDecl *Old); |
||
7826 | |||
7827 | bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); |
||
7828 | |||
7829 | /// CheckOverrideControl - Check C++11 override control semantics. |
||
7830 | void CheckOverrideControl(NamedDecl *D); |
||
7831 | |||
7832 | /// DiagnoseAbsenceOfOverrideControl - Diagnose if 'override' keyword was |
||
7833 | /// not used in the declaration of an overriding method. |
||
7834 | void DiagnoseAbsenceOfOverrideControl(NamedDecl *D, bool Inconsistent); |
||
7835 | |||
7836 | /// CheckForFunctionMarkedFinal - Checks whether a virtual member function |
||
7837 | /// overrides a virtual member function marked 'final', according to |
||
7838 | /// C++11 [class.virtual]p4. |
||
7839 | bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, |
||
7840 | const CXXMethodDecl *Old); |
||
7841 | |||
7842 | |||
7843 | //===--------------------------------------------------------------------===// |
||
7844 | // C++ Access Control |
||
7845 | // |
||
7846 | |||
7847 | enum AccessResult { |
||
7848 | AR_accessible, |
||
7849 | AR_inaccessible, |
||
7850 | AR_dependent, |
||
7851 | AR_delayed |
||
7852 | }; |
||
7853 | |||
7854 | bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, |
||
7855 | NamedDecl *PrevMemberDecl, |
||
7856 | AccessSpecifier LexicalAS); |
||
7857 | |||
7858 | AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, |
||
7859 | DeclAccessPair FoundDecl); |
||
7860 | AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, |
||
7861 | DeclAccessPair FoundDecl); |
||
7862 | AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, |
||
7863 | SourceRange PlacementRange, |
||
7864 | CXXRecordDecl *NamingClass, |
||
7865 | DeclAccessPair FoundDecl, |
||
7866 | bool Diagnose = true); |
||
7867 | AccessResult CheckConstructorAccess(SourceLocation Loc, |
||
7868 | CXXConstructorDecl *D, |
||
7869 | DeclAccessPair FoundDecl, |
||
7870 | const InitializedEntity &Entity, |
||
7871 | bool IsCopyBindingRefToTemp = false); |
||
7872 | AccessResult CheckConstructorAccess(SourceLocation Loc, |
||
7873 | CXXConstructorDecl *D, |
||
7874 | DeclAccessPair FoundDecl, |
||
7875 | const InitializedEntity &Entity, |
||
7876 | const PartialDiagnostic &PDiag); |
||
7877 | AccessResult CheckDestructorAccess(SourceLocation Loc, |
||
7878 | CXXDestructorDecl *Dtor, |
||
7879 | const PartialDiagnostic &PDiag, |
||
7880 | QualType objectType = QualType()); |
||
7881 | AccessResult CheckFriendAccess(NamedDecl *D); |
||
7882 | AccessResult CheckMemberAccess(SourceLocation UseLoc, |
||
7883 | CXXRecordDecl *NamingClass, |
||
7884 | DeclAccessPair Found); |
||
7885 | AccessResult |
||
7886 | CheckStructuredBindingMemberAccess(SourceLocation UseLoc, |
||
7887 | CXXRecordDecl *DecomposedClass, |
||
7888 | DeclAccessPair Field); |
||
7889 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, |
||
7890 | const SourceRange &, |
||
7891 | DeclAccessPair FoundDecl); |
||
7892 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, |
||
7893 | Expr *ObjectExpr, |
||
7894 | Expr *ArgExpr, |
||
7895 | DeclAccessPair FoundDecl); |
||
7896 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, |
||
7897 | ArrayRef<Expr *> ArgExprs, |
||
7898 | DeclAccessPair FoundDecl); |
||
7899 | AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, |
||
7900 | DeclAccessPair FoundDecl); |
||
7901 | AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, |
||
7902 | QualType Base, QualType Derived, |
||
7903 | const CXXBasePath &Path, |
||
7904 | unsigned DiagID, |
||
7905 | bool ForceCheck = false, |
||
7906 | bool ForceUnprivileged = false); |
||
7907 | void CheckLookupAccess(const LookupResult &R); |
||
7908 | bool IsSimplyAccessible(NamedDecl *Decl, CXXRecordDecl *NamingClass, |
||
7909 | QualType BaseType); |
||
7910 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
||
7911 | DeclAccessPair Found, QualType ObjectType, |
||
7912 | SourceLocation Loc, |
||
7913 | const PartialDiagnostic &Diag); |
||
7914 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
||
7915 | DeclAccessPair Found, |
||
7916 | QualType ObjectType) { |
||
7917 | return isMemberAccessibleForDeletion(NamingClass, Found, ObjectType, |
||
7918 | SourceLocation(), PDiag()); |
||
7919 | } |
||
7920 | |||
7921 | void HandleDependentAccessCheck(const DependentDiagnostic &DD, |
||
7922 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
7923 | void PerformDependentDiagnostics(const DeclContext *Pattern, |
||
7924 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
7925 | |||
7926 | void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
||
7927 | |||
7928 | /// When true, access checking violations are treated as SFINAE |
||
7929 | /// failures rather than hard errors. |
||
7930 | bool AccessCheckingSFINAE; |
||
7931 | |||
7932 | enum AbstractDiagSelID { |
||
7933 | AbstractNone = -1, |
||
7934 | AbstractReturnType, |
||
7935 | AbstractParamType, |
||
7936 | AbstractVariableType, |
||
7937 | AbstractFieldType, |
||
7938 | AbstractIvarType, |
||
7939 | AbstractSynthesizedIvarType, |
||
7940 | AbstractArrayType |
||
7941 | }; |
||
7942 | |||
7943 | bool isAbstractType(SourceLocation Loc, QualType T); |
||
7944 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, |
||
7945 | TypeDiagnoser &Diagnoser); |
||
7946 | template <typename... Ts> |
||
7947 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, |
||
7948 | const Ts &...Args) { |
||
7949 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
||
7950 | return RequireNonAbstractType(Loc, T, Diagnoser); |
||
7951 | } |
||
7952 | |||
7953 | void DiagnoseAbstractType(const CXXRecordDecl *RD); |
||
7954 | |||
7955 | //===--------------------------------------------------------------------===// |
||
7956 | // C++ Overloaded Operators [C++ 13.5] |
||
7957 | // |
||
7958 | |||
7959 | bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); |
||
7960 | |||
7961 | bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); |
||
7962 | |||
7963 | //===--------------------------------------------------------------------===// |
||
7964 | // C++ Templates [C++ 14] |
||
7965 | // |
||
7966 | void FilterAcceptableTemplateNames(LookupResult &R, |
||
7967 | bool AllowFunctionTemplates = true, |
||
7968 | bool AllowDependent = true); |
||
7969 | bool hasAnyAcceptableTemplateNames(LookupResult &R, |
||
7970 | bool AllowFunctionTemplates = true, |
||
7971 | bool AllowDependent = true, |
||
7972 | bool AllowNonTemplateFunctions = false); |
||
7973 | /// Try to interpret the lookup result D as a template-name. |
||
7974 | /// |
||
7975 | /// \param D A declaration found by name lookup. |
||
7976 | /// \param AllowFunctionTemplates Whether function templates should be |
||
7977 | /// considered valid results. |
||
7978 | /// \param AllowDependent Whether unresolved using declarations (that might |
||
7979 | /// name templates) should be considered valid results. |
||
7980 | static NamedDecl *getAsTemplateNameDecl(NamedDecl *D, |
||
7981 | bool AllowFunctionTemplates = true, |
||
7982 | bool AllowDependent = true); |
||
7983 | |||
7984 | enum TemplateNameIsRequiredTag { TemplateNameIsRequired }; |
||
7985 | /// Whether and why a template name is required in this lookup. |
||
7986 | class RequiredTemplateKind { |
||
7987 | public: |
||
7988 | /// Template name is required if TemplateKWLoc is valid. |
||
7989 | RequiredTemplateKind(SourceLocation TemplateKWLoc = SourceLocation()) |
||
7990 | : TemplateKW(TemplateKWLoc) {} |
||
7991 | /// Template name is unconditionally required. |
||
7992 | RequiredTemplateKind(TemplateNameIsRequiredTag) {} |
||
7993 | |||
7994 | SourceLocation getTemplateKeywordLoc() const { |
||
7995 | return TemplateKW.value_or(SourceLocation()); |
||
7996 | } |
||
7997 | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } |
||
7998 | bool isRequired() const { return TemplateKW != SourceLocation(); } |
||
7999 | explicit operator bool() const { return isRequired(); } |
||
8000 | |||
8001 | private: |
||
8002 | std::optional<SourceLocation> TemplateKW; |
||
8003 | }; |
||
8004 | |||
8005 | enum class AssumedTemplateKind { |
||
8006 | /// This is not assumed to be a template name. |
||
8007 | None, |
||
8008 | /// This is assumed to be a template name because lookup found nothing. |
||
8009 | FoundNothing, |
||
8010 | /// This is assumed to be a template name because lookup found one or more |
||
8011 | /// functions (but no function templates). |
||
8012 | FoundFunctions, |
||
8013 | }; |
||
8014 | bool LookupTemplateName( |
||
8015 | LookupResult &R, Scope *S, CXXScopeSpec &SS, QualType ObjectType, |
||
8016 | bool EnteringContext, bool &MemberOfUnknownSpecialization, |
||
8017 | RequiredTemplateKind RequiredTemplate = SourceLocation(), |
||
8018 | AssumedTemplateKind *ATK = nullptr, bool AllowTypoCorrection = true); |
||
8019 | |||
8020 | TemplateNameKind isTemplateName(Scope *S, |
||
8021 | CXXScopeSpec &SS, |
||
8022 | bool hasTemplateKeyword, |
||
8023 | const UnqualifiedId &Name, |
||
8024 | ParsedType ObjectType, |
||
8025 | bool EnteringContext, |
||
8026 | TemplateTy &Template, |
||
8027 | bool &MemberOfUnknownSpecialization, |
||
8028 | bool Disambiguation = false); |
||
8029 | |||
8030 | /// Try to resolve an undeclared template name as a type template. |
||
8031 | /// |
||
8032 | /// Sets II to the identifier corresponding to the template name, and updates |
||
8033 | /// Name to a corresponding (typo-corrected) type template name and TNK to |
||
8034 | /// the corresponding kind, if possible. |
||
8035 | void ActOnUndeclaredTypeTemplateName(Scope *S, TemplateTy &Name, |
||
8036 | TemplateNameKind &TNK, |
||
8037 | SourceLocation NameLoc, |
||
8038 | IdentifierInfo *&II); |
||
8039 | |||
8040 | bool resolveAssumedTemplateNameAsType(Scope *S, TemplateName &Name, |
||
8041 | SourceLocation NameLoc, |
||
8042 | bool Diagnose = true); |
||
8043 | |||
8044 | /// Determine whether a particular identifier might be the name in a C++1z |
||
8045 | /// deduction-guide declaration. |
||
8046 | bool isDeductionGuideName(Scope *S, const IdentifierInfo &Name, |
||
8047 | SourceLocation NameLoc, |
||
8048 | ParsedTemplateTy *Template = nullptr); |
||
8049 | |||
8050 | bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, |
||
8051 | SourceLocation IILoc, |
||
8052 | Scope *S, |
||
8053 | const CXXScopeSpec *SS, |
||
8054 | TemplateTy &SuggestedTemplate, |
||
8055 | TemplateNameKind &SuggestedKind); |
||
8056 | |||
8057 | bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation, |
||
8058 | NamedDecl *Instantiation, |
||
8059 | bool InstantiatedFromMember, |
||
8060 | const NamedDecl *Pattern, |
||
8061 | const NamedDecl *PatternDef, |
||
8062 | TemplateSpecializationKind TSK, |
||
8063 | bool Complain = true); |
||
8064 | |||
8065 | void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); |
||
8066 | TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); |
||
8067 | |||
8068 | NamedDecl *ActOnTypeParameter(Scope *S, bool Typename, |
||
8069 | SourceLocation EllipsisLoc, |
||
8070 | SourceLocation KeyLoc, |
||
8071 | IdentifierInfo *ParamName, |
||
8072 | SourceLocation ParamNameLoc, |
||
8073 | unsigned Depth, unsigned Position, |
||
8074 | SourceLocation EqualLoc, |
||
8075 | ParsedType DefaultArg, bool HasTypeConstraint); |
||
8076 | |||
8077 | bool ActOnTypeConstraint(const CXXScopeSpec &SS, |
||
8078 | TemplateIdAnnotation *TypeConstraint, |
||
8079 | TemplateTypeParmDecl *ConstrainedParameter, |
||
8080 | SourceLocation EllipsisLoc); |
||
8081 | bool BuildTypeConstraint(const CXXScopeSpec &SS, |
||
8082 | TemplateIdAnnotation *TypeConstraint, |
||
8083 | TemplateTypeParmDecl *ConstrainedParameter, |
||
8084 | SourceLocation EllipsisLoc, |
||
8085 | bool AllowUnexpandedPack); |
||
8086 | |||
8087 | bool AttachTypeConstraint(NestedNameSpecifierLoc NS, |
||
8088 | DeclarationNameInfo NameInfo, |
||
8089 | ConceptDecl *NamedConcept, |
||
8090 | const TemplateArgumentListInfo *TemplateArgs, |
||
8091 | TemplateTypeParmDecl *ConstrainedParameter, |
||
8092 | SourceLocation EllipsisLoc); |
||
8093 | |||
8094 | bool AttachTypeConstraint(AutoTypeLoc TL, |
||
8095 | NonTypeTemplateParmDecl *ConstrainedParameter, |
||
8096 | SourceLocation EllipsisLoc); |
||
8097 | |||
8098 | bool RequireStructuralType(QualType T, SourceLocation Loc); |
||
8099 | |||
8100 | QualType CheckNonTypeTemplateParameterType(TypeSourceInfo *&TSI, |
||
8101 | SourceLocation Loc); |
||
8102 | QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); |
||
8103 | |||
8104 | NamedDecl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, |
||
8105 | unsigned Depth, |
||
8106 | unsigned Position, |
||
8107 | SourceLocation EqualLoc, |
||
8108 | Expr *DefaultArg); |
||
8109 | NamedDecl *ActOnTemplateTemplateParameter(Scope *S, |
||
8110 | SourceLocation TmpLoc, |
||
8111 | TemplateParameterList *Params, |
||
8112 | SourceLocation EllipsisLoc, |
||
8113 | IdentifierInfo *ParamName, |
||
8114 | SourceLocation ParamNameLoc, |
||
8115 | unsigned Depth, |
||
8116 | unsigned Position, |
||
8117 | SourceLocation EqualLoc, |
||
8118 | ParsedTemplateArgument DefaultArg); |
||
8119 | |||
8120 | TemplateParameterList * |
||
8121 | ActOnTemplateParameterList(unsigned Depth, |
||
8122 | SourceLocation ExportLoc, |
||
8123 | SourceLocation TemplateLoc, |
||
8124 | SourceLocation LAngleLoc, |
||
8125 | ArrayRef<NamedDecl *> Params, |
||
8126 | SourceLocation RAngleLoc, |
||
8127 | Expr *RequiresClause); |
||
8128 | |||
8129 | /// The context in which we are checking a template parameter list. |
||
8130 | enum TemplateParamListContext { |
||
8131 | TPC_ClassTemplate, |
||
8132 | TPC_VarTemplate, |
||
8133 | TPC_FunctionTemplate, |
||
8134 | TPC_ClassTemplateMember, |
||
8135 | TPC_FriendClassTemplate, |
||
8136 | TPC_FriendFunctionTemplate, |
||
8137 | TPC_FriendFunctionTemplateDefinition, |
||
8138 | TPC_TypeAliasTemplate |
||
8139 | }; |
||
8140 | |||
8141 | bool CheckTemplateParameterList(TemplateParameterList *NewParams, |
||
8142 | TemplateParameterList *OldParams, |
||
8143 | TemplateParamListContext TPC, |
||
8144 | SkipBodyInfo *SkipBody = nullptr); |
||
8145 | TemplateParameterList *MatchTemplateParametersToScopeSpecifier( |
||
8146 | SourceLocation DeclStartLoc, SourceLocation DeclLoc, |
||
8147 | const CXXScopeSpec &SS, TemplateIdAnnotation *TemplateId, |
||
8148 | ArrayRef<TemplateParameterList *> ParamLists, |
||
8149 | bool IsFriend, bool &IsMemberSpecialization, bool &Invalid, |
||
8150 | bool SuppressDiagnostic = false); |
||
8151 | |||
8152 | DeclResult CheckClassTemplate( |
||
8153 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
||
8154 | CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, |
||
8155 | const ParsedAttributesView &Attr, TemplateParameterList *TemplateParams, |
||
8156 | AccessSpecifier AS, SourceLocation ModulePrivateLoc, |
||
8157 | SourceLocation FriendLoc, unsigned NumOuterTemplateParamLists, |
||
8158 | TemplateParameterList **OuterTemplateParamLists, |
||
8159 | SkipBodyInfo *SkipBody = nullptr); |
||
8160 | |||
8161 | TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, |
||
8162 | QualType NTTPType, |
||
8163 | SourceLocation Loc); |
||
8164 | |||
8165 | /// Get a template argument mapping the given template parameter to itself, |
||
8166 | /// e.g. for X in \c template<int X>, this would return an expression template |
||
8167 | /// argument referencing X. |
||
8168 | TemplateArgumentLoc getIdentityTemplateArgumentLoc(NamedDecl *Param, |
||
8169 | SourceLocation Location); |
||
8170 | |||
8171 | void translateTemplateArguments(const ASTTemplateArgsPtr &In, |
||
8172 | TemplateArgumentListInfo &Out); |
||
8173 | |||
8174 | ParsedTemplateArgument ActOnTemplateTypeArgument(TypeResult ParsedType); |
||
8175 | |||
8176 | void NoteAllFoundTemplates(TemplateName Name); |
||
8177 | |||
8178 | QualType CheckTemplateIdType(TemplateName Template, |
||
8179 | SourceLocation TemplateLoc, |
||
8180 | TemplateArgumentListInfo &TemplateArgs); |
||
8181 | |||
8182 | TypeResult |
||
8183 | ActOnTemplateIdType(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
||
8184 | TemplateTy Template, IdentifierInfo *TemplateII, |
||
8185 | SourceLocation TemplateIILoc, SourceLocation LAngleLoc, |
||
8186 | ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, |
||
8187 | bool IsCtorOrDtorName = false, bool IsClassName = false, |
||
8188 | ImplicitTypenameContext AllowImplicitTypename = |
||
8189 | ImplicitTypenameContext::No); |
||
8190 | |||
8191 | /// Parsed an elaborated-type-specifier that refers to a template-id, |
||
8192 | /// such as \c class T::template apply<U>. |
||
8193 | TypeResult ActOnTagTemplateIdType(TagUseKind TUK, |
||
8194 | TypeSpecifierType TagSpec, |
||
8195 | SourceLocation TagLoc, |
||
8196 | CXXScopeSpec &SS, |
||
8197 | SourceLocation TemplateKWLoc, |
||
8198 | TemplateTy TemplateD, |
||
8199 | SourceLocation TemplateLoc, |
||
8200 | SourceLocation LAngleLoc, |
||
8201 | ASTTemplateArgsPtr TemplateArgsIn, |
||
8202 | SourceLocation RAngleLoc); |
||
8203 | |||
8204 | DeclResult ActOnVarTemplateSpecialization( |
||
8205 | Scope *S, Declarator &D, TypeSourceInfo *DI, |
||
8206 | SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams, |
||
8207 | StorageClass SC, bool IsPartialSpecialization); |
||
8208 | |||
8209 | /// Get the specialization of the given variable template corresponding to |
||
8210 | /// the specified argument list, or a null-but-valid result if the arguments |
||
8211 | /// are dependent. |
||
8212 | DeclResult CheckVarTemplateId(VarTemplateDecl *Template, |
||
8213 | SourceLocation TemplateLoc, |
||
8214 | SourceLocation TemplateNameLoc, |
||
8215 | const TemplateArgumentListInfo &TemplateArgs); |
||
8216 | |||
8217 | /// Form a reference to the specialization of the given variable template |
||
8218 | /// corresponding to the specified argument list, or a null-but-valid result |
||
8219 | /// if the arguments are dependent. |
||
8220 | ExprResult CheckVarTemplateId(const CXXScopeSpec &SS, |
||
8221 | const DeclarationNameInfo &NameInfo, |
||
8222 | VarTemplateDecl *Template, |
||
8223 | SourceLocation TemplateLoc, |
||
8224 | const TemplateArgumentListInfo *TemplateArgs); |
||
8225 | |||
8226 | ExprResult |
||
8227 | CheckConceptTemplateId(const CXXScopeSpec &SS, |
||
8228 | SourceLocation TemplateKWLoc, |
||
8229 | const DeclarationNameInfo &ConceptNameInfo, |
||
8230 | NamedDecl *FoundDecl, ConceptDecl *NamedConcept, |
||
8231 | const TemplateArgumentListInfo *TemplateArgs); |
||
8232 | |||
8233 | void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc); |
||
8234 | |||
8235 | ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, |
||
8236 | SourceLocation TemplateKWLoc, |
||
8237 | LookupResult &R, |
||
8238 | bool RequiresADL, |
||
8239 | const TemplateArgumentListInfo *TemplateArgs); |
||
8240 | |||
8241 | ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, |
||
8242 | SourceLocation TemplateKWLoc, |
||
8243 | const DeclarationNameInfo &NameInfo, |
||
8244 | const TemplateArgumentListInfo *TemplateArgs); |
||
8245 | |||
8246 | TemplateNameKind ActOnTemplateName( |
||
8247 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
||
8248 | const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, |
||
8249 | TemplateTy &Template, bool AllowInjectedClassName = false); |
||
8250 | |||
8251 | DeclResult ActOnClassTemplateSpecialization( |
||
8252 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
||
8253 | SourceLocation ModulePrivateLoc, CXXScopeSpec &SS, |
||
8254 | TemplateIdAnnotation &TemplateId, const ParsedAttributesView &Attr, |
||
8255 | MultiTemplateParamsArg TemplateParameterLists, |
||
8256 | SkipBodyInfo *SkipBody = nullptr); |
||
8257 | |||
8258 | bool CheckTemplatePartialSpecializationArgs(SourceLocation Loc, |
||
8259 | TemplateDecl *PrimaryTemplate, |
||
8260 | unsigned NumExplicitArgs, |
||
8261 | ArrayRef<TemplateArgument> Args); |
||
8262 | void CheckTemplatePartialSpecialization( |
||
8263 | ClassTemplatePartialSpecializationDecl *Partial); |
||
8264 | void CheckTemplatePartialSpecialization( |
||
8265 | VarTemplatePartialSpecializationDecl *Partial); |
||
8266 | |||
8267 | Decl *ActOnTemplateDeclarator(Scope *S, |
||
8268 | MultiTemplateParamsArg TemplateParameterLists, |
||
8269 | Declarator &D); |
||
8270 | |||
8271 | bool |
||
8272 | CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, |
||
8273 | TemplateSpecializationKind NewTSK, |
||
8274 | NamedDecl *PrevDecl, |
||
8275 | TemplateSpecializationKind PrevTSK, |
||
8276 | SourceLocation PrevPtOfInstantiation, |
||
8277 | bool &SuppressNew); |
||
8278 | |||
8279 | bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, |
||
8280 | const TemplateArgumentListInfo &ExplicitTemplateArgs, |
||
8281 | LookupResult &Previous); |
||
8282 | |||
8283 | bool CheckFunctionTemplateSpecialization( |
||
8284 | FunctionDecl *FD, TemplateArgumentListInfo *ExplicitTemplateArgs, |
||
8285 | LookupResult &Previous, bool QualifiedFriend = false); |
||
8286 | bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
||
8287 | void CompleteMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
||
8288 | |||
8289 | DeclResult ActOnExplicitInstantiation( |
||
8290 | Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc, |
||
8291 | unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS, |
||
8292 | TemplateTy Template, SourceLocation TemplateNameLoc, |
||
8293 | SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, |
||
8294 | SourceLocation RAngleLoc, const ParsedAttributesView &Attr); |
||
8295 | |||
8296 | DeclResult ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, |
||
8297 | SourceLocation TemplateLoc, |
||
8298 | unsigned TagSpec, SourceLocation KWLoc, |
||
8299 | CXXScopeSpec &SS, IdentifierInfo *Name, |
||
8300 | SourceLocation NameLoc, |
||
8301 | const ParsedAttributesView &Attr); |
||
8302 | |||
8303 | DeclResult ActOnExplicitInstantiation(Scope *S, |
||
8304 | SourceLocation ExternLoc, |
||
8305 | SourceLocation TemplateLoc, |
||
8306 | Declarator &D); |
||
8307 | |||
8308 | TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable( |
||
8309 | TemplateDecl *Template, SourceLocation TemplateLoc, |
||
8310 | SourceLocation RAngleLoc, Decl *Param, |
||
8311 | ArrayRef<TemplateArgument> SugaredConverted, |
||
8312 | ArrayRef<TemplateArgument> CanonicalConverted, bool &HasDefaultArg); |
||
8313 | |||
8314 | /// Specifies the context in which a particular template |
||
8315 | /// argument is being checked. |
||
8316 | enum CheckTemplateArgumentKind { |
||
8317 | /// The template argument was specified in the code or was |
||
8318 | /// instantiated with some deduced template arguments. |
||
8319 | CTAK_Specified, |
||
8320 | |||
8321 | /// The template argument was deduced via template argument |
||
8322 | /// deduction. |
||
8323 | CTAK_Deduced, |
||
8324 | |||
8325 | /// The template argument was deduced from an array bound |
||
8326 | /// via template argument deduction. |
||
8327 | CTAK_DeducedFromArrayBound |
||
8328 | }; |
||
8329 | |||
8330 | bool |
||
8331 | CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, |
||
8332 | NamedDecl *Template, SourceLocation TemplateLoc, |
||
8333 | SourceLocation RAngleLoc, unsigned ArgumentPackIndex, |
||
8334 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
||
8335 | SmallVectorImpl<TemplateArgument> &CanonicalConverted, |
||
8336 | CheckTemplateArgumentKind CTAK); |
||
8337 | |||
8338 | /// Check that the given template arguments can be provided to |
||
8339 | /// the given template, converting the arguments along the way. |
||
8340 | /// |
||
8341 | /// \param Template The template to which the template arguments are being |
||
8342 | /// provided. |
||
8343 | /// |
||
8344 | /// \param TemplateLoc The location of the template name in the source. |
||
8345 | /// |
||
8346 | /// \param TemplateArgs The list of template arguments. If the template is |
||
8347 | /// a template template parameter, this function may extend the set of |
||
8348 | /// template arguments to also include substituted, defaulted template |
||
8349 | /// arguments. |
||
8350 | /// |
||
8351 | /// \param PartialTemplateArgs True if the list of template arguments is |
||
8352 | /// intentionally partial, e.g., because we're checking just the initial |
||
8353 | /// set of template arguments. |
||
8354 | /// |
||
8355 | /// \param Converted Will receive the converted, canonicalized template |
||
8356 | /// arguments. |
||
8357 | /// |
||
8358 | /// \param UpdateArgsWithConversions If \c true, update \p TemplateArgs to |
||
8359 | /// contain the converted forms of the template arguments as written. |
||
8360 | /// Otherwise, \p TemplateArgs will not be modified. |
||
8361 | /// |
||
8362 | /// \param ConstraintsNotSatisfied If provided, and an error occurred, will |
||
8363 | /// receive true if the cause for the error is the associated constraints of |
||
8364 | /// the template not being satisfied by the template arguments. |
||
8365 | /// |
||
8366 | /// \returns true if an error occurred, false otherwise. |
||
8367 | bool CheckTemplateArgumentList( |
||
8368 | TemplateDecl *Template, SourceLocation TemplateLoc, |
||
8369 | TemplateArgumentListInfo &TemplateArgs, bool PartialTemplateArgs, |
||
8370 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
||
8371 | SmallVectorImpl<TemplateArgument> &CanonicalConverted, |
||
8372 | bool UpdateArgsWithConversions = true, |
||
8373 | bool *ConstraintsNotSatisfied = nullptr); |
||
8374 | |||
8375 | bool CheckTemplateTypeArgument( |
||
8376 | TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg, |
||
8377 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
||
8378 | SmallVectorImpl<TemplateArgument> &CanonicalConverted); |
||
8379 | |||
8380 | bool CheckTemplateArgument(TypeSourceInfo *Arg); |
||
8381 | ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, |
||
8382 | QualType InstantiatedParamType, Expr *Arg, |
||
8383 | TemplateArgument &SugaredConverted, |
||
8384 | TemplateArgument &CanonicalConverted, |
||
8385 | CheckTemplateArgumentKind CTAK); |
||
8386 | bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, |
||
8387 | TemplateParameterList *Params, |
||
8388 | TemplateArgumentLoc &Arg); |
||
8389 | |||
8390 | ExprResult |
||
8391 | BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, |
||
8392 | QualType ParamType, |
||
8393 | SourceLocation Loc); |
||
8394 | ExprResult |
||
8395 | BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, |
||
8396 | SourceLocation Loc); |
||
8397 | |||
8398 | /// Enumeration describing how template parameter lists are compared |
||
8399 | /// for equality. |
||
8400 | enum TemplateParameterListEqualKind { |
||
8401 | /// We are matching the template parameter lists of two templates |
||
8402 | /// that might be redeclarations. |
||
8403 | /// |
||
8404 | /// \code |
||
8405 | /// template<typename T> struct X; |
||
8406 | /// template<typename T> struct X; |
||
8407 | /// \endcode |
||
8408 | TPL_TemplateMatch, |
||
8409 | |||
8410 | /// We are matching the template parameter lists of two template |
||
8411 | /// template parameters as part of matching the template parameter lists |
||
8412 | /// of two templates that might be redeclarations. |
||
8413 | /// |
||
8414 | /// \code |
||
8415 | /// template<template<int I> class TT> struct X; |
||
8416 | /// template<template<int Value> class Other> struct X; |
||
8417 | /// \endcode |
||
8418 | TPL_TemplateTemplateParmMatch, |
||
8419 | |||
8420 | /// We are matching the template parameter lists of a template |
||
8421 | /// template argument against the template parameter lists of a template |
||
8422 | /// template parameter. |
||
8423 | /// |
||
8424 | /// \code |
||
8425 | /// template<template<int Value> class Metafun> struct X; |
||
8426 | /// template<int Value> struct integer_c; |
||
8427 | /// X<integer_c> xic; |
||
8428 | /// \endcode |
||
8429 | TPL_TemplateTemplateArgumentMatch |
||
8430 | }; |
||
8431 | |||
8432 | bool TemplateParameterListsAreEqual( |
||
8433 | const NamedDecl *NewInstFrom, TemplateParameterList *New, |
||
8434 | const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain, |
||
8435 | TemplateParameterListEqualKind Kind, |
||
8436 | SourceLocation TemplateArgLoc = SourceLocation(), |
||
8437 | bool PartialOrdering = false); |
||
8438 | |||
8439 | bool TemplateParameterListsAreEqual( |
||
8440 | TemplateParameterList *New, TemplateParameterList *Old, bool Complain, |
||
8441 | TemplateParameterListEqualKind Kind, |
||
8442 | SourceLocation TemplateArgLoc = SourceLocation(), |
||
8443 | bool PartialOrdering = false) { |
||
8444 | return TemplateParameterListsAreEqual(nullptr, New, nullptr, Old, Complain, |
||
8445 | Kind, TemplateArgLoc, |
||
8446 | PartialOrdering); |
||
8447 | } |
||
8448 | |||
8449 | bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); |
||
8450 | |||
8451 | /// Called when the parser has parsed a C++ typename |
||
8452 | /// specifier, e.g., "typename T::type". |
||
8453 | /// |
||
8454 | /// \param S The scope in which this typename type occurs. |
||
8455 | /// \param TypenameLoc the location of the 'typename' keyword |
||
8456 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
||
8457 | /// \param II the identifier we're retrieving (e.g., 'type' in the example). |
||
8458 | /// \param IdLoc the location of the identifier. |
||
8459 | /// \param IsImplicitTypename context where T::type refers to a type. |
||
8460 | TypeResult ActOnTypenameType( |
||
8461 | Scope *S, SourceLocation TypenameLoc, const CXXScopeSpec &SS, |
||
8462 | const IdentifierInfo &II, SourceLocation IdLoc, |
||
8463 | ImplicitTypenameContext IsImplicitTypename = ImplicitTypenameContext::No); |
||
8464 | |||
8465 | /// Called when the parser has parsed a C++ typename |
||
8466 | /// specifier that ends in a template-id, e.g., |
||
8467 | /// "typename MetaFun::template apply<T1, T2>". |
||
8468 | /// |
||
8469 | /// \param S The scope in which this typename type occurs. |
||
8470 | /// \param TypenameLoc the location of the 'typename' keyword |
||
8471 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
||
8472 | /// \param TemplateLoc the location of the 'template' keyword, if any. |
||
8473 | /// \param TemplateName The template name. |
||
8474 | /// \param TemplateII The identifier used to name the template. |
||
8475 | /// \param TemplateIILoc The location of the template name. |
||
8476 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
||
8477 | /// \param TemplateArgs The template arguments. |
||
8478 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
||
8479 | TypeResult |
||
8480 | ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, |
||
8481 | const CXXScopeSpec &SS, |
||
8482 | SourceLocation TemplateLoc, |
||
8483 | TemplateTy TemplateName, |
||
8484 | IdentifierInfo *TemplateII, |
||
8485 | SourceLocation TemplateIILoc, |
||
8486 | SourceLocation LAngleLoc, |
||
8487 | ASTTemplateArgsPtr TemplateArgs, |
||
8488 | SourceLocation RAngleLoc); |
||
8489 | |||
8490 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
||
8491 | SourceLocation KeywordLoc, |
||
8492 | NestedNameSpecifierLoc QualifierLoc, |
||
8493 | const IdentifierInfo &II, |
||
8494 | SourceLocation IILoc, |
||
8495 | TypeSourceInfo **TSI, |
||
8496 | bool DeducedTSTContext); |
||
8497 | |||
8498 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
||
8499 | SourceLocation KeywordLoc, |
||
8500 | NestedNameSpecifierLoc QualifierLoc, |
||
8501 | const IdentifierInfo &II, |
||
8502 | SourceLocation IILoc, |
||
8503 | bool DeducedTSTContext = true); |
||
8504 | |||
8505 | |||
8506 | TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, |
||
8507 | SourceLocation Loc, |
||
8508 | DeclarationName Name); |
||
8509 | bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); |
||
8510 | |||
8511 | ExprResult RebuildExprInCurrentInstantiation(Expr *E); |
||
8512 | bool RebuildTemplateParamsInCurrentInstantiation( |
||
8513 | TemplateParameterList *Params); |
||
8514 | |||
8515 | std::string |
||
8516 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
||
8517 | const TemplateArgumentList &Args); |
||
8518 | |||
8519 | std::string |
||
8520 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
||
8521 | const TemplateArgument *Args, |
||
8522 | unsigned NumArgs); |
||
8523 | |||
8524 | //===--------------------------------------------------------------------===// |
||
8525 | // C++ Concepts |
||
8526 | //===--------------------------------------------------------------------===// |
||
8527 | Decl *ActOnConceptDefinition( |
||
8528 | Scope *S, MultiTemplateParamsArg TemplateParameterLists, |
||
8529 | IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr); |
||
8530 | |||
8531 | void CheckConceptRedefinition(ConceptDecl *NewDecl, LookupResult &Previous, |
||
8532 | bool &AddToScope); |
||
8533 | |||
8534 | RequiresExprBodyDecl * |
||
8535 | ActOnStartRequiresExpr(SourceLocation RequiresKWLoc, |
||
8536 | ArrayRef<ParmVarDecl *> LocalParameters, |
||
8537 | Scope *BodyScope); |
||
8538 | void ActOnFinishRequiresExpr(); |
||
8539 | concepts::Requirement *ActOnSimpleRequirement(Expr *E); |
||
8540 | concepts::Requirement *ActOnTypeRequirement( |
||
8541 | SourceLocation TypenameKWLoc, CXXScopeSpec &SS, SourceLocation NameLoc, |
||
8542 | IdentifierInfo *TypeName, TemplateIdAnnotation *TemplateId); |
||
8543 | concepts::Requirement *ActOnCompoundRequirement(Expr *E, |
||
8544 | SourceLocation NoexceptLoc); |
||
8545 | concepts::Requirement * |
||
8546 | ActOnCompoundRequirement( |
||
8547 | Expr *E, SourceLocation NoexceptLoc, CXXScopeSpec &SS, |
||
8548 | TemplateIdAnnotation *TypeConstraint, unsigned Depth); |
||
8549 | concepts::Requirement *ActOnNestedRequirement(Expr *Constraint); |
||
8550 | concepts::ExprRequirement * |
||
8551 | BuildExprRequirement( |
||
8552 | Expr *E, bool IsSatisfied, SourceLocation NoexceptLoc, |
||
8553 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
||
8554 | concepts::ExprRequirement * |
||
8555 | BuildExprRequirement( |
||
8556 | concepts::Requirement::SubstitutionDiagnostic *ExprSubstDiag, |
||
8557 | bool IsSatisfied, SourceLocation NoexceptLoc, |
||
8558 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
||
8559 | concepts::TypeRequirement *BuildTypeRequirement(TypeSourceInfo *Type); |
||
8560 | concepts::TypeRequirement * |
||
8561 | BuildTypeRequirement( |
||
8562 | concepts::Requirement::SubstitutionDiagnostic *SubstDiag); |
||
8563 | concepts::NestedRequirement *BuildNestedRequirement(Expr *E); |
||
8564 | concepts::NestedRequirement * |
||
8565 | BuildNestedRequirement(StringRef InvalidConstraintEntity, |
||
8566 | const ASTConstraintSatisfaction &Satisfaction); |
||
8567 | ExprResult ActOnRequiresExpr(SourceLocation RequiresKWLoc, |
||
8568 | RequiresExprBodyDecl *Body, |
||
8569 | ArrayRef<ParmVarDecl *> LocalParameters, |
||
8570 | ArrayRef<concepts::Requirement *> Requirements, |
||
8571 | SourceLocation ClosingBraceLoc); |
||
8572 | |||
8573 | //===--------------------------------------------------------------------===// |
||
8574 | // C++ Variadic Templates (C++0x [temp.variadic]) |
||
8575 | //===--------------------------------------------------------------------===// |
||
8576 | |||
8577 | /// Determine whether an unexpanded parameter pack might be permitted in this |
||
8578 | /// location. Useful for error recovery. |
||
8579 | bool isUnexpandedParameterPackPermitted(); |
||
8580 | |||
8581 | /// The context in which an unexpanded parameter pack is |
||
8582 | /// being diagnosed. |
||
8583 | /// |
||
8584 | /// Note that the values of this enumeration line up with the first |
||
8585 | /// argument to the \c err_unexpanded_parameter_pack diagnostic. |
||
8586 | enum UnexpandedParameterPackContext { |
||
8587 | /// An arbitrary expression. |
||
8588 | UPPC_Expression = 0, |
||
8589 | |||
8590 | /// The base type of a class type. |
||
8591 | UPPC_BaseType, |
||
8592 | |||
8593 | /// The type of an arbitrary declaration. |
||
8594 | UPPC_DeclarationType, |
||
8595 | |||
8596 | /// The type of a data member. |
||
8597 | UPPC_DataMemberType, |
||
8598 | |||
8599 | /// The size of a bit-field. |
||
8600 | UPPC_BitFieldWidth, |
||
8601 | |||
8602 | /// The expression in a static assertion. |
||
8603 | UPPC_StaticAssertExpression, |
||
8604 | |||
8605 | /// The fixed underlying type of an enumeration. |
||
8606 | UPPC_FixedUnderlyingType, |
||
8607 | |||
8608 | /// The enumerator value. |
||
8609 | UPPC_EnumeratorValue, |
||
8610 | |||
8611 | /// A using declaration. |
||
8612 | UPPC_UsingDeclaration, |
||
8613 | |||
8614 | /// A friend declaration. |
||
8615 | UPPC_FriendDeclaration, |
||
8616 | |||
8617 | /// A declaration qualifier. |
||
8618 | UPPC_DeclarationQualifier, |
||
8619 | |||
8620 | /// An initializer. |
||
8621 | UPPC_Initializer, |
||
8622 | |||
8623 | /// A default argument. |
||
8624 | UPPC_DefaultArgument, |
||
8625 | |||
8626 | /// The type of a non-type template parameter. |
||
8627 | UPPC_NonTypeTemplateParameterType, |
||
8628 | |||
8629 | /// The type of an exception. |
||
8630 | UPPC_ExceptionType, |
||
8631 | |||
8632 | /// Partial specialization. |
||
8633 | UPPC_PartialSpecialization, |
||
8634 | |||
8635 | /// Microsoft __if_exists. |
||
8636 | UPPC_IfExists, |
||
8637 | |||
8638 | /// Microsoft __if_not_exists. |
||
8639 | UPPC_IfNotExists, |
||
8640 | |||
8641 | /// Lambda expression. |
||
8642 | UPPC_Lambda, |
||
8643 | |||
8644 | /// Block expression. |
||
8645 | UPPC_Block, |
||
8646 | |||
8647 | /// A type constraint. |
||
8648 | UPPC_TypeConstraint, |
||
8649 | |||
8650 | // A requirement in a requires-expression. |
||
8651 | UPPC_Requirement, |
||
8652 | |||
8653 | // A requires-clause. |
||
8654 | UPPC_RequiresClause, |
||
8655 | }; |
||
8656 | |||
8657 | /// Diagnose unexpanded parameter packs. |
||
8658 | /// |
||
8659 | /// \param Loc The location at which we should emit the diagnostic. |
||
8660 | /// |
||
8661 | /// \param UPPC The context in which we are diagnosing unexpanded |
||
8662 | /// parameter packs. |
||
8663 | /// |
||
8664 | /// \param Unexpanded the set of unexpanded parameter packs. |
||
8665 | /// |
||
8666 | /// \returns true if an error occurred, false otherwise. |
||
8667 | bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc, |
||
8668 | UnexpandedParameterPackContext UPPC, |
||
8669 | ArrayRef<UnexpandedParameterPack> Unexpanded); |
||
8670 | |||
8671 | /// If the given type contains an unexpanded parameter pack, |
||
8672 | /// diagnose the error. |
||
8673 | /// |
||
8674 | /// \param Loc The source location where a diagnostc should be emitted. |
||
8675 | /// |
||
8676 | /// \param T The type that is being checked for unexpanded parameter |
||
8677 | /// packs. |
||
8678 | /// |
||
8679 | /// \returns true if an error occurred, false otherwise. |
||
8680 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, |
||
8681 | UnexpandedParameterPackContext UPPC); |
||
8682 | |||
8683 | /// If the given expression contains an unexpanded parameter |
||
8684 | /// pack, diagnose the error. |
||
8685 | /// |
||
8686 | /// \param E The expression that is being checked for unexpanded |
||
8687 | /// parameter packs. |
||
8688 | /// |
||
8689 | /// \returns true if an error occurred, false otherwise. |
||
8690 | bool DiagnoseUnexpandedParameterPack(Expr *E, |
||
8691 | UnexpandedParameterPackContext UPPC = UPPC_Expression); |
||
8692 | |||
8693 | /// If the given requirees-expression contains an unexpanded reference to one |
||
8694 | /// of its own parameter packs, diagnose the error. |
||
8695 | /// |
||
8696 | /// \param RE The requiress-expression that is being checked for unexpanded |
||
8697 | /// parameter packs. |
||
8698 | /// |
||
8699 | /// \returns true if an error occurred, false otherwise. |
||
8700 | bool DiagnoseUnexpandedParameterPackInRequiresExpr(RequiresExpr *RE); |
||
8701 | |||
8702 | /// If the given nested-name-specifier contains an unexpanded |
||
8703 | /// parameter pack, diagnose the error. |
||
8704 | /// |
||
8705 | /// \param SS The nested-name-specifier that is being checked for |
||
8706 | /// unexpanded parameter packs. |
||
8707 | /// |
||
8708 | /// \returns true if an error occurred, false otherwise. |
||
8709 | bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, |
||
8710 | UnexpandedParameterPackContext UPPC); |
||
8711 | |||
8712 | /// If the given name contains an unexpanded parameter pack, |
||
8713 | /// diagnose the error. |
||
8714 | /// |
||
8715 | /// \param NameInfo The name (with source location information) that |
||
8716 | /// is being checked for unexpanded parameter packs. |
||
8717 | /// |
||
8718 | /// \returns true if an error occurred, false otherwise. |
||
8719 | bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, |
||
8720 | UnexpandedParameterPackContext UPPC); |
||
8721 | |||
8722 | /// If the given template name contains an unexpanded parameter pack, |
||
8723 | /// diagnose the error. |
||
8724 | /// |
||
8725 | /// \param Loc The location of the template name. |
||
8726 | /// |
||
8727 | /// \param Template The template name that is being checked for unexpanded |
||
8728 | /// parameter packs. |
||
8729 | /// |
||
8730 | /// \returns true if an error occurred, false otherwise. |
||
8731 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, |
||
8732 | TemplateName Template, |
||
8733 | UnexpandedParameterPackContext UPPC); |
||
8734 | |||
8735 | /// If the given template argument contains an unexpanded parameter |
||
8736 | /// pack, diagnose the error. |
||
8737 | /// |
||
8738 | /// \param Arg The template argument that is being checked for unexpanded |
||
8739 | /// parameter packs. |
||
8740 | /// |
||
8741 | /// \returns true if an error occurred, false otherwise. |
||
8742 | bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, |
||
8743 | UnexpandedParameterPackContext UPPC); |
||
8744 | |||
8745 | /// Collect the set of unexpanded parameter packs within the given |
||
8746 | /// template argument. |
||
8747 | /// |
||
8748 | /// \param Arg The template argument that will be traversed to find |
||
8749 | /// unexpanded parameter packs. |
||
8750 | void collectUnexpandedParameterPacks(TemplateArgument Arg, |
||
8751 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
||
8752 | |||
8753 | /// Collect the set of unexpanded parameter packs within the given |
||
8754 | /// template argument. |
||
8755 | /// |
||
8756 | /// \param Arg The template argument that will be traversed to find |
||
8757 | /// unexpanded parameter packs. |
||
8758 | void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, |
||
8759 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
||
8760 | |||
8761 | /// Collect the set of unexpanded parameter packs within the given |
||
8762 | /// type. |
||
8763 | /// |
||
8764 | /// \param T The type that will be traversed to find |
||
8765 | /// unexpanded parameter packs. |
||
8766 | void collectUnexpandedParameterPacks(QualType T, |
||
8767 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
||
8768 | |||
8769 | /// Collect the set of unexpanded parameter packs within the given |
||
8770 | /// type. |
||
8771 | /// |
||
8772 | /// \param TL The type that will be traversed to find |
||
8773 | /// unexpanded parameter packs. |
||
8774 | void collectUnexpandedParameterPacks(TypeLoc TL, |
||
8775 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
||
8776 | |||
8777 | /// Collect the set of unexpanded parameter packs within the given |
||
8778 | /// nested-name-specifier. |
||
8779 | /// |
||
8780 | /// \param NNS The nested-name-specifier that will be traversed to find |
||
8781 | /// unexpanded parameter packs. |
||
8782 | void collectUnexpandedParameterPacks(NestedNameSpecifierLoc NNS, |
||
8783 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
||
8784 | |||
8785 | /// Collect the set of unexpanded parameter packs within the given |
||
8786 | /// name. |
||
8787 | /// |
||
8788 | /// \param NameInfo The name that will be traversed to find |
||
8789 | /// unexpanded parameter packs. |
||
8790 | void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo, |
||
8791 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
||
8792 | |||
8793 | /// Invoked when parsing a template argument followed by an |
||
8794 | /// ellipsis, which creates a pack expansion. |
||
8795 | /// |
||
8796 | /// \param Arg The template argument preceding the ellipsis, which |
||
8797 | /// may already be invalid. |
||
8798 | /// |
||
8799 | /// \param EllipsisLoc The location of the ellipsis. |
||
8800 | ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, |
||
8801 | SourceLocation EllipsisLoc); |
||
8802 | |||
8803 | /// Invoked when parsing a type followed by an ellipsis, which |
||
8804 | /// creates a pack expansion. |
||
8805 | /// |
||
8806 | /// \param Type The type preceding the ellipsis, which will become |
||
8807 | /// the pattern of the pack expansion. |
||
8808 | /// |
||
8809 | /// \param EllipsisLoc The location of the ellipsis. |
||
8810 | TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); |
||
8811 | |||
8812 | /// Construct a pack expansion type from the pattern of the pack |
||
8813 | /// expansion. |
||
8814 | TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, |
||
8815 | SourceLocation EllipsisLoc, |
||
8816 | std::optional<unsigned> NumExpansions); |
||
8817 | |||
8818 | /// Construct a pack expansion type from the pattern of the pack |
||
8819 | /// expansion. |
||
8820 | QualType CheckPackExpansion(QualType Pattern, SourceRange PatternRange, |
||
8821 | SourceLocation EllipsisLoc, |
||
8822 | std::optional<unsigned> NumExpansions); |
||
8823 | |||
8824 | /// Invoked when parsing an expression followed by an ellipsis, which |
||
8825 | /// creates a pack expansion. |
||
8826 | /// |
||
8827 | /// \param Pattern The expression preceding the ellipsis, which will become |
||
8828 | /// the pattern of the pack expansion. |
||
8829 | /// |
||
8830 | /// \param EllipsisLoc The location of the ellipsis. |
||
8831 | ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); |
||
8832 | |||
8833 | /// Invoked when parsing an expression followed by an ellipsis, which |
||
8834 | /// creates a pack expansion. |
||
8835 | /// |
||
8836 | /// \param Pattern The expression preceding the ellipsis, which will become |
||
8837 | /// the pattern of the pack expansion. |
||
8838 | /// |
||
8839 | /// \param EllipsisLoc The location of the ellipsis. |
||
8840 | ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
||
8841 | std::optional<unsigned> NumExpansions); |
||
8842 | |||
8843 | /// Determine whether we could expand a pack expansion with the |
||
8844 | /// given set of parameter packs into separate arguments by repeatedly |
||
8845 | /// transforming the pattern. |
||
8846 | /// |
||
8847 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
||
8848 | /// pack expansion. |
||
8849 | /// |
||
8850 | /// \param PatternRange The source range that covers the entire pattern of |
||
8851 | /// the pack expansion. |
||
8852 | /// |
||
8853 | /// \param Unexpanded The set of unexpanded parameter packs within the |
||
8854 | /// pattern. |
||
8855 | /// |
||
8856 | /// \param ShouldExpand Will be set to \c true if the transformer should |
||
8857 | /// expand the corresponding pack expansions into separate arguments. When |
||
8858 | /// set, \c NumExpansions must also be set. |
||
8859 | /// |
||
8860 | /// \param RetainExpansion Whether the caller should add an unexpanded |
||
8861 | /// pack expansion after all of the expanded arguments. This is used |
||
8862 | /// when extending explicitly-specified template argument packs per |
||
8863 | /// C++0x [temp.arg.explicit]p9. |
||
8864 | /// |
||
8865 | /// \param NumExpansions The number of separate arguments that will be in |
||
8866 | /// the expanded form of the corresponding pack expansion. This is both an |
||
8867 | /// input and an output parameter, which can be set by the caller if the |
||
8868 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
||
8869 | /// and will be set by the callee when the number of expansions is known. |
||
8870 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
||
8871 | /// set this value in other cases. |
||
8872 | /// |
||
8873 | /// \returns true if an error occurred (e.g., because the parameter packs |
||
8874 | /// are to be instantiated with arguments of different lengths), false |
||
8875 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
||
8876 | /// must be set. |
||
8877 | bool CheckParameterPacksForExpansion( |
||
8878 | SourceLocation EllipsisLoc, SourceRange PatternRange, |
||
8879 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
||
8880 | const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand, |
||
8881 | bool &RetainExpansion, std::optional<unsigned> &NumExpansions); |
||
8882 | |||
8883 | /// Determine the number of arguments in the given pack expansion |
||
8884 | /// type. |
||
8885 | /// |
||
8886 | /// This routine assumes that the number of arguments in the expansion is |
||
8887 | /// consistent across all of the unexpanded parameter packs in its pattern. |
||
8888 | /// |
||
8889 | /// Returns an empty Optional if the type can't be expanded. |
||
8890 | std::optional<unsigned> getNumArgumentsInExpansion( |
||
8891 | QualType T, const MultiLevelTemplateArgumentList &TemplateArgs); |
||
8892 | |||
8893 | /// Determine whether the given declarator contains any unexpanded |
||
8894 | /// parameter packs. |
||
8895 | /// |
||
8896 | /// This routine is used by the parser to disambiguate function declarators |
||
8897 | /// with an ellipsis prior to the ')', e.g., |
||
8898 | /// |
||
8899 | /// \code |
||
8900 | /// void f(T...); |
||
8901 | /// \endcode |
||
8902 | /// |
||
8903 | /// To determine whether we have an (unnamed) function parameter pack or |
||
8904 | /// a variadic function. |
||
8905 | /// |
||
8906 | /// \returns true if the declarator contains any unexpanded parameter packs, |
||
8907 | /// false otherwise. |
||
8908 | bool containsUnexpandedParameterPacks(Declarator &D); |
||
8909 | |||
8910 | /// Returns the pattern of the pack expansion for a template argument. |
||
8911 | /// |
||
8912 | /// \param OrigLoc The template argument to expand. |
||
8913 | /// |
||
8914 | /// \param Ellipsis Will be set to the location of the ellipsis. |
||
8915 | /// |
||
8916 | /// \param NumExpansions Will be set to the number of expansions that will |
||
8917 | /// be generated from this pack expansion, if known a priori. |
||
8918 | TemplateArgumentLoc getTemplateArgumentPackExpansionPattern( |
||
8919 | TemplateArgumentLoc OrigLoc, SourceLocation &Ellipsis, |
||
8920 | std::optional<unsigned> &NumExpansions) const; |
||
8921 | |||
8922 | /// Given a template argument that contains an unexpanded parameter pack, but |
||
8923 | /// which has already been substituted, attempt to determine the number of |
||
8924 | /// elements that will be produced once this argument is fully-expanded. |
||
8925 | /// |
||
8926 | /// This is intended for use when transforming 'sizeof...(Arg)' in order to |
||
8927 | /// avoid actually expanding the pack where possible. |
||
8928 | std::optional<unsigned> getFullyPackExpandedSize(TemplateArgument Arg); |
||
8929 | |||
8930 | //===--------------------------------------------------------------------===// |
||
8931 | // C++ Template Argument Deduction (C++ [temp.deduct]) |
||
8932 | //===--------------------------------------------------------------------===// |
||
8933 | |||
8934 | /// Adjust the type \p ArgFunctionType to match the calling convention, |
||
8935 | /// noreturn, and optionally the exception specification of \p FunctionType. |
||
8936 | /// Deduction often wants to ignore these properties when matching function |
||
8937 | /// types. |
||
8938 | QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType, |
||
8939 | bool AdjustExceptionSpec = false); |
||
8940 | |||
8941 | /// Describes the result of template argument deduction. |
||
8942 | /// |
||
8943 | /// The TemplateDeductionResult enumeration describes the result of |
||
8944 | /// template argument deduction, as returned from |
||
8945 | /// DeduceTemplateArguments(). The separate TemplateDeductionInfo |
||
8946 | /// structure provides additional information about the results of |
||
8947 | /// template argument deduction, e.g., the deduced template argument |
||
8948 | /// list (if successful) or the specific template parameters or |
||
8949 | /// deduced arguments that were involved in the failure. |
||
8950 | enum TemplateDeductionResult { |
||
8951 | /// Template argument deduction was successful. |
||
8952 | TDK_Success = 0, |
||
8953 | /// The declaration was invalid; do nothing. |
||
8954 | TDK_Invalid, |
||
8955 | /// Template argument deduction exceeded the maximum template |
||
8956 | /// instantiation depth (which has already been diagnosed). |
||
8957 | TDK_InstantiationDepth, |
||
8958 | /// Template argument deduction did not deduce a value |
||
8959 | /// for every template parameter. |
||
8960 | TDK_Incomplete, |
||
8961 | /// Template argument deduction did not deduce a value for every |
||
8962 | /// expansion of an expanded template parameter pack. |
||
8963 | TDK_IncompletePack, |
||
8964 | /// Template argument deduction produced inconsistent |
||
8965 | /// deduced values for the given template parameter. |
||
8966 | TDK_Inconsistent, |
||
8967 | /// Template argument deduction failed due to inconsistent |
||
8968 | /// cv-qualifiers on a template parameter type that would |
||
8969 | /// otherwise be deduced, e.g., we tried to deduce T in "const T" |
||
8970 | /// but were given a non-const "X". |
||
8971 | TDK_Underqualified, |
||
8972 | /// Substitution of the deduced template argument values |
||
8973 | /// resulted in an error. |
||
8974 | TDK_SubstitutionFailure, |
||
8975 | /// After substituting deduced template arguments, a dependent |
||
8976 | /// parameter type did not match the corresponding argument. |
||
8977 | TDK_DeducedMismatch, |
||
8978 | /// After substituting deduced template arguments, an element of |
||
8979 | /// a dependent parameter type did not match the corresponding element |
||
8980 | /// of the corresponding argument (when deducing from an initializer list). |
||
8981 | TDK_DeducedMismatchNested, |
||
8982 | /// A non-depnedent component of the parameter did not match the |
||
8983 | /// corresponding component of the argument. |
||
8984 | TDK_NonDeducedMismatch, |
||
8985 | /// When performing template argument deduction for a function |
||
8986 | /// template, there were too many call arguments. |
||
8987 | TDK_TooManyArguments, |
||
8988 | /// When performing template argument deduction for a function |
||
8989 | /// template, there were too few call arguments. |
||
8990 | TDK_TooFewArguments, |
||
8991 | /// The explicitly-specified template arguments were not valid |
||
8992 | /// template arguments for the given template. |
||
8993 | TDK_InvalidExplicitArguments, |
||
8994 | /// Checking non-dependent argument conversions failed. |
||
8995 | TDK_NonDependentConversionFailure, |
||
8996 | /// The deduced arguments did not satisfy the constraints associated |
||
8997 | /// with the template. |
||
8998 | TDK_ConstraintsNotSatisfied, |
||
8999 | /// Deduction failed; that's all we know. |
||
9000 | TDK_MiscellaneousDeductionFailure, |
||
9001 | /// CUDA Target attributes do not match. |
||
9002 | TDK_CUDATargetMismatch, |
||
9003 | /// Some error which was already diagnosed. |
||
9004 | TDK_AlreadyDiagnosed |
||
9005 | }; |
||
9006 | |||
9007 | TemplateDeductionResult |
||
9008 | DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, |
||
9009 | const TemplateArgumentList &TemplateArgs, |
||
9010 | sema::TemplateDeductionInfo &Info); |
||
9011 | |||
9012 | TemplateDeductionResult |
||
9013 | DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, |
||
9014 | const TemplateArgumentList &TemplateArgs, |
||
9015 | sema::TemplateDeductionInfo &Info); |
||
9016 | |||
9017 | TemplateDeductionResult SubstituteExplicitTemplateArguments( |
||
9018 | FunctionTemplateDecl *FunctionTemplate, |
||
9019 | TemplateArgumentListInfo &ExplicitTemplateArgs, |
||
9020 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
||
9021 | SmallVectorImpl<QualType> &ParamTypes, QualType *FunctionType, |
||
9022 | sema::TemplateDeductionInfo &Info); |
||
9023 | |||
9024 | /// brief A function argument from which we performed template argument |
||
9025 | // deduction for a call. |
||
9026 | struct OriginalCallArg { |
||
9027 | OriginalCallArg(QualType OriginalParamType, bool DecomposedParam, |
||
9028 | unsigned ArgIdx, QualType OriginalArgType) |
||
9029 | : OriginalParamType(OriginalParamType), |
||
9030 | DecomposedParam(DecomposedParam), ArgIdx(ArgIdx), |
||
9031 | OriginalArgType(OriginalArgType) {} |
||
9032 | |||
9033 | QualType OriginalParamType; |
||
9034 | bool DecomposedParam; |
||
9035 | unsigned ArgIdx; |
||
9036 | QualType OriginalArgType; |
||
9037 | }; |
||
9038 | |||
9039 | TemplateDeductionResult FinishTemplateArgumentDeduction( |
||
9040 | FunctionTemplateDecl *FunctionTemplate, |
||
9041 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
||
9042 | unsigned NumExplicitlySpecified, FunctionDecl *&Specialization, |
||
9043 | sema::TemplateDeductionInfo &Info, |
||
9044 | SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = nullptr, |
||
9045 | bool PartialOverloading = false, |
||
9046 | llvm::function_ref<bool()> CheckNonDependent = []{ return false; }); |
||
9047 | |||
9048 | TemplateDeductionResult DeduceTemplateArguments( |
||
9049 | FunctionTemplateDecl *FunctionTemplate, |
||
9050 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
||
9051 | FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, |
||
9052 | bool PartialOverloading, |
||
9053 | llvm::function_ref<bool(ArrayRef<QualType>)> CheckNonDependent); |
||
9054 | |||
9055 | TemplateDeductionResult |
||
9056 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
||
9057 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
||
9058 | QualType ArgFunctionType, |
||
9059 | FunctionDecl *&Specialization, |
||
9060 | sema::TemplateDeductionInfo &Info, |
||
9061 | bool IsAddressOfFunction = false); |
||
9062 | |||
9063 | TemplateDeductionResult |
||
9064 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
||
9065 | QualType ToType, |
||
9066 | CXXConversionDecl *&Specialization, |
||
9067 | sema::TemplateDeductionInfo &Info); |
||
9068 | |||
9069 | TemplateDeductionResult |
||
9070 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
||
9071 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
||
9072 | FunctionDecl *&Specialization, |
||
9073 | sema::TemplateDeductionInfo &Info, |
||
9074 | bool IsAddressOfFunction = false); |
||
9075 | |||
9076 | /// Substitute Replacement for \p auto in \p TypeWithAuto |
||
9077 | QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement); |
||
9078 | /// Substitute Replacement for auto in TypeWithAuto |
||
9079 | TypeSourceInfo* SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
||
9080 | QualType Replacement); |
||
9081 | |||
9082 | // Substitute auto in TypeWithAuto for a Dependent auto type |
||
9083 | QualType SubstAutoTypeDependent(QualType TypeWithAuto); |
||
9084 | |||
9085 | // Substitute auto in TypeWithAuto for a Dependent auto type |
||
9086 | TypeSourceInfo * |
||
9087 | SubstAutoTypeSourceInfoDependent(TypeSourceInfo *TypeWithAuto); |
||
9088 | |||
9089 | /// Completely replace the \c auto in \p TypeWithAuto by |
||
9090 | /// \p Replacement. This does not retain any \c auto type sugar. |
||
9091 | QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement); |
||
9092 | TypeSourceInfo *ReplaceAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
||
9093 | QualType Replacement); |
||
9094 | |||
9095 | TemplateDeductionResult DeduceAutoType(TypeLoc AutoTypeLoc, Expr *Initializer, |
||
9096 | QualType &Result, |
||
9097 | sema::TemplateDeductionInfo &Info, |
||
9098 | bool DependentDeduction = false, |
||
9099 | bool IgnoreConstraints = false); |
||
9100 | void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init); |
||
9101 | bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc, |
||
9102 | bool Diagnose = true); |
||
9103 | |||
9104 | /// Declare implicit deduction guides for a class template if we've |
||
9105 | /// not already done so. |
||
9106 | void DeclareImplicitDeductionGuides(TemplateDecl *Template, |
||
9107 | SourceLocation Loc); |
||
9108 | |||
9109 | QualType DeduceTemplateSpecializationFromInitializer( |
||
9110 | TypeSourceInfo *TInfo, const InitializedEntity &Entity, |
||
9111 | const InitializationKind &Kind, MultiExprArg Init); |
||
9112 | |||
9113 | QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name, |
||
9114 | QualType Type, TypeSourceInfo *TSI, |
||
9115 | SourceRange Range, bool DirectInit, |
||
9116 | Expr *Init); |
||
9117 | |||
9118 | TypeLoc getReturnTypeLoc(FunctionDecl *FD) const; |
||
9119 | |||
9120 | bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD, |
||
9121 | SourceLocation ReturnLoc, Expr *RetExpr, |
||
9122 | const AutoType *AT); |
||
9123 | |||
9124 | FunctionTemplateDecl *getMoreSpecializedTemplate( |
||
9125 | FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc, |
||
9126 | TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1, |
||
9127 | unsigned NumCallArguments2, bool Reversed = false); |
||
9128 | UnresolvedSetIterator |
||
9129 | getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd, |
||
9130 | TemplateSpecCandidateSet &FailedCandidates, |
||
9131 | SourceLocation Loc, |
||
9132 | const PartialDiagnostic &NoneDiag, |
||
9133 | const PartialDiagnostic &AmbigDiag, |
||
9134 | const PartialDiagnostic &CandidateDiag, |
||
9135 | bool Complain = true, QualType TargetType = QualType()); |
||
9136 | |||
9137 | ClassTemplatePartialSpecializationDecl * |
||
9138 | getMoreSpecializedPartialSpecialization( |
||
9139 | ClassTemplatePartialSpecializationDecl *PS1, |
||
9140 | ClassTemplatePartialSpecializationDecl *PS2, |
||
9141 | SourceLocation Loc); |
||
9142 | |||
9143 | bool isMoreSpecializedThanPrimary(ClassTemplatePartialSpecializationDecl *T, |
||
9144 | sema::TemplateDeductionInfo &Info); |
||
9145 | |||
9146 | VarTemplatePartialSpecializationDecl *getMoreSpecializedPartialSpecialization( |
||
9147 | VarTemplatePartialSpecializationDecl *PS1, |
||
9148 | VarTemplatePartialSpecializationDecl *PS2, SourceLocation Loc); |
||
9149 | |||
9150 | bool isMoreSpecializedThanPrimary(VarTemplatePartialSpecializationDecl *T, |
||
9151 | sema::TemplateDeductionInfo &Info); |
||
9152 | |||
9153 | bool isTemplateTemplateParameterAtLeastAsSpecializedAs( |
||
9154 | TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc); |
||
9155 | |||
9156 | void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced, |
||
9157 | unsigned Depth, llvm::SmallBitVector &Used); |
||
9158 | |||
9159 | void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, |
||
9160 | bool OnlyDeduced, |
||
9161 | unsigned Depth, |
||
9162 | llvm::SmallBitVector &Used); |
||
9163 | void MarkDeducedTemplateParameters( |
||
9164 | const FunctionTemplateDecl *FunctionTemplate, |
||
9165 | llvm::SmallBitVector &Deduced) { |
||
9166 | return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced); |
||
9167 | } |
||
9168 | static void MarkDeducedTemplateParameters(ASTContext &Ctx, |
||
9169 | const FunctionTemplateDecl *FunctionTemplate, |
||
9170 | llvm::SmallBitVector &Deduced); |
||
9171 | |||
9172 | //===--------------------------------------------------------------------===// |
||
9173 | // C++ Template Instantiation |
||
9174 | // |
||
9175 | |||
9176 | MultiLevelTemplateArgumentList |
||
9177 | getTemplateInstantiationArgs(const NamedDecl *D, bool Final = false, |
||
9178 | const TemplateArgumentList *Innermost = nullptr, |
||
9179 | bool RelativeToPrimary = false, |
||
9180 | const FunctionDecl *Pattern = nullptr, |
||
9181 | bool ForConstraintInstantiation = false, |
||
9182 | bool SkipForSpecialization = false); |
||
9183 | |||
9184 | /// A context in which code is being synthesized (where a source location |
||
9185 | /// alone is not sufficient to identify the context). This covers template |
||
9186 | /// instantiation and various forms of implicitly-generated functions. |
||
9187 | struct CodeSynthesisContext { |
||
9188 | /// The kind of template instantiation we are performing |
||
9189 | enum SynthesisKind { |
||
9190 | /// We are instantiating a template declaration. The entity is |
||
9191 | /// the declaration we're instantiating (e.g., a CXXRecordDecl). |
||
9192 | TemplateInstantiation, |
||
9193 | |||
9194 | /// We are instantiating a default argument for a template |
||
9195 | /// parameter. The Entity is the template parameter whose argument is |
||
9196 | /// being instantiated, the Template is the template, and the |
||
9197 | /// TemplateArgs/NumTemplateArguments provide the template arguments as |
||
9198 | /// specified. |
||
9199 | DefaultTemplateArgumentInstantiation, |
||
9200 | |||
9201 | /// We are instantiating a default argument for a function. |
||
9202 | /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs |
||
9203 | /// provides the template arguments as specified. |
||
9204 | DefaultFunctionArgumentInstantiation, |
||
9205 | |||
9206 | /// We are substituting explicit template arguments provided for |
||
9207 | /// a function template. The entity is a FunctionTemplateDecl. |
||
9208 | ExplicitTemplateArgumentSubstitution, |
||
9209 | |||
9210 | /// We are substituting template argument determined as part of |
||
9211 | /// template argument deduction for either a class template |
||
9212 | /// partial specialization or a function template. The |
||
9213 | /// Entity is either a {Class|Var}TemplatePartialSpecializationDecl or |
||
9214 | /// a TemplateDecl. |
||
9215 | DeducedTemplateArgumentSubstitution, |
||
9216 | |||
9217 | /// We are substituting prior template arguments into a new |
||
9218 | /// template parameter. The template parameter itself is either a |
||
9219 | /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. |
||
9220 | PriorTemplateArgumentSubstitution, |
||
9221 | |||
9222 | /// We are checking the validity of a default template argument that |
||
9223 | /// has been used when naming a template-id. |
||
9224 | DefaultTemplateArgumentChecking, |
||
9225 | |||
9226 | /// We are computing the exception specification for a defaulted special |
||
9227 | /// member function. |
||
9228 | ExceptionSpecEvaluation, |
||
9229 | |||
9230 | /// We are instantiating the exception specification for a function |
||
9231 | /// template which was deferred until it was needed. |
||
9232 | ExceptionSpecInstantiation, |
||
9233 | |||
9234 | /// We are instantiating a requirement of a requires expression. |
||
9235 | RequirementInstantiation, |
||
9236 | |||
9237 | /// We are checking the satisfaction of a nested requirement of a requires |
||
9238 | /// expression. |
||
9239 | NestedRequirementConstraintsCheck, |
||
9240 | |||
9241 | /// We are declaring an implicit special member function. |
||
9242 | DeclaringSpecialMember, |
||
9243 | |||
9244 | /// We are declaring an implicit 'operator==' for a defaulted |
||
9245 | /// 'operator<=>'. |
||
9246 | DeclaringImplicitEqualityComparison, |
||
9247 | |||
9248 | /// We are defining a synthesized function (such as a defaulted special |
||
9249 | /// member). |
||
9250 | DefiningSynthesizedFunction, |
||
9251 | |||
9252 | // We are checking the constraints associated with a constrained entity or |
||
9253 | // the constraint expression of a concept. This includes the checks that |
||
9254 | // atomic constraints have the type 'bool' and that they can be constant |
||
9255 | // evaluated. |
||
9256 | ConstraintsCheck, |
||
9257 | |||
9258 | // We are substituting template arguments into a constraint expression. |
||
9259 | ConstraintSubstitution, |
||
9260 | |||
9261 | // We are normalizing a constraint expression. |
||
9262 | ConstraintNormalization, |
||
9263 | |||
9264 | // Instantiating a Requires Expression parameter clause. |
||
9265 | RequirementParameterInstantiation, |
||
9266 | |||
9267 | // We are substituting into the parameter mapping of an atomic constraint |
||
9268 | // during normalization. |
||
9269 | ParameterMappingSubstitution, |
||
9270 | |||
9271 | /// We are rewriting a comparison operator in terms of an operator<=>. |
||
9272 | RewritingOperatorAsSpaceship, |
||
9273 | |||
9274 | /// We are initializing a structured binding. |
||
9275 | InitializingStructuredBinding, |
||
9276 | |||
9277 | /// We are marking a class as __dllexport. |
||
9278 | MarkingClassDllexported, |
||
9279 | |||
9280 | /// We are building an implied call from __builtin_dump_struct. The |
||
9281 | /// arguments are in CallArgs. |
||
9282 | BuildingBuiltinDumpStructCall, |
||
9283 | |||
9284 | /// Added for Template instantiation observation. |
||
9285 | /// Memoization means we are _not_ instantiating a template because |
||
9286 | /// it is already instantiated (but we entered a context where we |
||
9287 | /// would have had to if it was not already instantiated). |
||
9288 | Memoization |
||
9289 | } Kind; |
||
9290 | |||
9291 | /// Was the enclosing context a non-instantiation SFINAE context? |
||
9292 | bool SavedInNonInstantiationSFINAEContext; |
||
9293 | |||
9294 | /// The point of instantiation or synthesis within the source code. |
||
9295 | SourceLocation PointOfInstantiation; |
||
9296 | |||
9297 | /// The entity that is being synthesized. |
||
9298 | Decl *Entity; |
||
9299 | |||
9300 | /// The template (or partial specialization) in which we are |
||
9301 | /// performing the instantiation, for substitutions of prior template |
||
9302 | /// arguments. |
||
9303 | NamedDecl *Template; |
||
9304 | |||
9305 | union { |
||
9306 | /// The list of template arguments we are substituting, if they |
||
9307 | /// are not part of the entity. |
||
9308 | const TemplateArgument *TemplateArgs; |
||
9309 | |||
9310 | /// The list of argument expressions in a synthesized call. |
||
9311 | const Expr *const *CallArgs; |
||
9312 | }; |
||
9313 | |||
9314 | // FIXME: Wrap this union around more members, or perhaps store the |
||
9315 | // kind-specific members in the RAII object owning the context. |
||
9316 | union { |
||
9317 | /// The number of template arguments in TemplateArgs. |
||
9318 | unsigned NumTemplateArgs; |
||
9319 | |||
9320 | /// The number of expressions in CallArgs. |
||
9321 | unsigned NumCallArgs; |
||
9322 | |||
9323 | /// The special member being declared or defined. |
||
9324 | CXXSpecialMember SpecialMember; |
||
9325 | }; |
||
9326 | |||
9327 | ArrayRef<TemplateArgument> template_arguments() const { |
||
9328 | assert(Kind != DeclaringSpecialMember); |
||
9329 | return {TemplateArgs, NumTemplateArgs}; |
||
9330 | } |
||
9331 | |||
9332 | /// The template deduction info object associated with the |
||
9333 | /// substitution or checking of explicit or deduced template arguments. |
||
9334 | sema::TemplateDeductionInfo *DeductionInfo; |
||
9335 | |||
9336 | /// The source range that covers the construct that cause |
||
9337 | /// the instantiation, e.g., the template-id that causes a class |
||
9338 | /// template instantiation. |
||
9339 | SourceRange InstantiationRange; |
||
9340 | |||
9341 | CodeSynthesisContext() |
||
9342 | : Kind(TemplateInstantiation), |
||
9343 | SavedInNonInstantiationSFINAEContext(false), Entity(nullptr), |
||
9344 | Template(nullptr), TemplateArgs(nullptr), NumTemplateArgs(0), |
||
9345 | DeductionInfo(nullptr) {} |
||
9346 | |||
9347 | /// Determines whether this template is an actual instantiation |
||
9348 | /// that should be counted toward the maximum instantiation depth. |
||
9349 | bool isInstantiationRecord() const; |
||
9350 | }; |
||
9351 | |||
9352 | /// List of active code synthesis contexts. |
||
9353 | /// |
||
9354 | /// This vector is treated as a stack. As synthesis of one entity requires |
||
9355 | /// synthesis of another, additional contexts are pushed onto the stack. |
||
9356 | SmallVector<CodeSynthesisContext, 16> CodeSynthesisContexts; |
||
9357 | |||
9358 | /// Specializations whose definitions are currently being instantiated. |
||
9359 | llvm::DenseSet<std::pair<Decl *, unsigned>> InstantiatingSpecializations; |
||
9360 | |||
9361 | /// Non-dependent types used in templates that have already been instantiated |
||
9362 | /// by some template instantiation. |
||
9363 | llvm::DenseSet<QualType> InstantiatedNonDependentTypes; |
||
9364 | |||
9365 | /// Extra modules inspected when performing a lookup during a template |
||
9366 | /// instantiation. Computed lazily. |
||
9367 | SmallVector<Module*, 16> CodeSynthesisContextLookupModules; |
||
9368 | |||
9369 | /// Cache of additional modules that should be used for name lookup |
||
9370 | /// within the current template instantiation. Computed lazily; use |
||
9371 | /// getLookupModules() to get a complete set. |
||
9372 | llvm::DenseSet<Module*> LookupModulesCache; |
||
9373 | |||
9374 | /// Get the set of additional modules that should be checked during |
||
9375 | /// name lookup. A module and its imports become visible when instanting a |
||
9376 | /// template defined within it. |
||
9377 | llvm::DenseSet<Module*> &getLookupModules(); |
||
9378 | |||
9379 | /// Map from the most recent declaration of a namespace to the most |
||
9380 | /// recent visible declaration of that namespace. |
||
9381 | llvm::DenseMap<NamedDecl*, NamedDecl*> VisibleNamespaceCache; |
||
9382 | |||
9383 | /// Whether we are in a SFINAE context that is not associated with |
||
9384 | /// template instantiation. |
||
9385 | /// |
||
9386 | /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside |
||
9387 | /// of a template instantiation or template argument deduction. |
||
9388 | bool InNonInstantiationSFINAEContext; |
||
9389 | |||
9390 | /// The number of \p CodeSynthesisContexts that are not template |
||
9391 | /// instantiations and, therefore, should not be counted as part of the |
||
9392 | /// instantiation depth. |
||
9393 | /// |
||
9394 | /// When the instantiation depth reaches the user-configurable limit |
||
9395 | /// \p LangOptions::InstantiationDepth we will abort instantiation. |
||
9396 | // FIXME: Should we have a similar limit for other forms of synthesis? |
||
9397 | unsigned NonInstantiationEntries; |
||
9398 | |||
9399 | /// The depth of the context stack at the point when the most recent |
||
9400 | /// error or warning was produced. |
||
9401 | /// |
||
9402 | /// This value is used to suppress printing of redundant context stacks |
||
9403 | /// when there are multiple errors or warnings in the same instantiation. |
||
9404 | // FIXME: Does this belong in Sema? It's tough to implement it anywhere else. |
||
9405 | unsigned LastEmittedCodeSynthesisContextDepth = 0; |
||
9406 | |||
9407 | /// The template instantiation callbacks to trace or track |
||
9408 | /// instantiations (objects can be chained). |
||
9409 | /// |
||
9410 | /// This callbacks is used to print, trace or track template |
||
9411 | /// instantiations as they are being constructed. |
||
9412 | std::vector<std::unique_ptr<TemplateInstantiationCallback>> |
||
9413 | TemplateInstCallbacks; |
||
9414 | |||
9415 | /// The current index into pack expansion arguments that will be |
||
9416 | /// used for substitution of parameter packs. |
||
9417 | /// |
||
9418 | /// The pack expansion index will be -1 to indicate that parameter packs |
||
9419 | /// should be instantiated as themselves. Otherwise, the index specifies |
||
9420 | /// which argument within the parameter pack will be used for substitution. |
||
9421 | int ArgumentPackSubstitutionIndex; |
||
9422 | |||
9423 | /// RAII object used to change the argument pack substitution index |
||
9424 | /// within a \c Sema object. |
||
9425 | /// |
||
9426 | /// See \c ArgumentPackSubstitutionIndex for more information. |
||
9427 | class ArgumentPackSubstitutionIndexRAII { |
||
9428 | Sema &Self; |
||
9429 | int OldSubstitutionIndex; |
||
9430 | |||
9431 | public: |
||
9432 | ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) |
||
9433 | : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { |
||
9434 | Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; |
||
9435 | } |
||
9436 | |||
9437 | ~ArgumentPackSubstitutionIndexRAII() { |
||
9438 | Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; |
||
9439 | } |
||
9440 | }; |
||
9441 | |||
9442 | friend class ArgumentPackSubstitutionRAII; |
||
9443 | |||
9444 | /// For each declaration that involved template argument deduction, the |
||
9445 | /// set of diagnostics that were suppressed during that template argument |
||
9446 | /// deduction. |
||
9447 | /// |
||
9448 | /// FIXME: Serialize this structure to the AST file. |
||
9449 | typedef llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> > |
||
9450 | SuppressedDiagnosticsMap; |
||
9451 | SuppressedDiagnosticsMap SuppressedDiagnostics; |
||
9452 | |||
9453 | /// A stack object to be created when performing template |
||
9454 | /// instantiation. |
||
9455 | /// |
||
9456 | /// Construction of an object of type \c InstantiatingTemplate |
||
9457 | /// pushes the current instantiation onto the stack of active |
||
9458 | /// instantiations. If the size of this stack exceeds the maximum |
||
9459 | /// number of recursive template instantiations, construction |
||
9460 | /// produces an error and evaluates true. |
||
9461 | /// |
||
9462 | /// Destruction of this object will pop the named instantiation off |
||
9463 | /// the stack. |
||
9464 | struct InstantiatingTemplate { |
||
9465 | /// Note that we are instantiating a class template, |
||
9466 | /// function template, variable template, alias template, |
||
9467 | /// or a member thereof. |
||
9468 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9469 | Decl *Entity, |
||
9470 | SourceRange InstantiationRange = SourceRange()); |
||
9471 | |||
9472 | struct ExceptionSpecification {}; |
||
9473 | /// Note that we are instantiating an exception specification |
||
9474 | /// of a function template. |
||
9475 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9476 | FunctionDecl *Entity, ExceptionSpecification, |
||
9477 | SourceRange InstantiationRange = SourceRange()); |
||
9478 | |||
9479 | /// Note that we are instantiating a default argument in a |
||
9480 | /// template-id. |
||
9481 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9482 | TemplateParameter Param, TemplateDecl *Template, |
||
9483 | ArrayRef<TemplateArgument> TemplateArgs, |
||
9484 | SourceRange InstantiationRange = SourceRange()); |
||
9485 | |||
9486 | /// Note that we are substituting either explicitly-specified or |
||
9487 | /// deduced template arguments during function template argument deduction. |
||
9488 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9489 | FunctionTemplateDecl *FunctionTemplate, |
||
9490 | ArrayRef<TemplateArgument> TemplateArgs, |
||
9491 | CodeSynthesisContext::SynthesisKind Kind, |
||
9492 | sema::TemplateDeductionInfo &DeductionInfo, |
||
9493 | SourceRange InstantiationRange = SourceRange()); |
||
9494 | |||
9495 | /// Note that we are instantiating as part of template |
||
9496 | /// argument deduction for a class template declaration. |
||
9497 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9498 | TemplateDecl *Template, |
||
9499 | ArrayRef<TemplateArgument> TemplateArgs, |
||
9500 | sema::TemplateDeductionInfo &DeductionInfo, |
||
9501 | SourceRange InstantiationRange = SourceRange()); |
||
9502 | |||
9503 | /// Note that we are instantiating as part of template |
||
9504 | /// argument deduction for a class template partial |
||
9505 | /// specialization. |
||
9506 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9507 | ClassTemplatePartialSpecializationDecl *PartialSpec, |
||
9508 | ArrayRef<TemplateArgument> TemplateArgs, |
||
9509 | sema::TemplateDeductionInfo &DeductionInfo, |
||
9510 | SourceRange InstantiationRange = SourceRange()); |
||
9511 | |||
9512 | /// Note that we are instantiating as part of template |
||
9513 | /// argument deduction for a variable template partial |
||
9514 | /// specialization. |
||
9515 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9516 | VarTemplatePartialSpecializationDecl *PartialSpec, |
||
9517 | ArrayRef<TemplateArgument> TemplateArgs, |
||
9518 | sema::TemplateDeductionInfo &DeductionInfo, |
||
9519 | SourceRange InstantiationRange = SourceRange()); |
||
9520 | |||
9521 | /// Note that we are instantiating a default argument for a function |
||
9522 | /// parameter. |
||
9523 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9524 | ParmVarDecl *Param, |
||
9525 | ArrayRef<TemplateArgument> TemplateArgs, |
||
9526 | SourceRange InstantiationRange = SourceRange()); |
||
9527 | |||
9528 | /// Note that we are substituting prior template arguments into a |
||
9529 | /// non-type parameter. |
||
9530 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9531 | NamedDecl *Template, |
||
9532 | NonTypeTemplateParmDecl *Param, |
||
9533 | ArrayRef<TemplateArgument> TemplateArgs, |
||
9534 | SourceRange InstantiationRange); |
||
9535 | |||
9536 | /// Note that we are substituting prior template arguments into a |
||
9537 | /// template template parameter. |
||
9538 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9539 | NamedDecl *Template, |
||
9540 | TemplateTemplateParmDecl *Param, |
||
9541 | ArrayRef<TemplateArgument> TemplateArgs, |
||
9542 | SourceRange InstantiationRange); |
||
9543 | |||
9544 | /// Note that we are checking the default template argument |
||
9545 | /// against the template parameter for a given template-id. |
||
9546 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9547 | TemplateDecl *Template, |
||
9548 | NamedDecl *Param, |
||
9549 | ArrayRef<TemplateArgument> TemplateArgs, |
||
9550 | SourceRange InstantiationRange); |
||
9551 | |||
9552 | struct ConstraintsCheck {}; |
||
9553 | /// \brief Note that we are checking the constraints associated with some |
||
9554 | /// constrained entity (a concept declaration or a template with associated |
||
9555 | /// constraints). |
||
9556 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9557 | ConstraintsCheck, NamedDecl *Template, |
||
9558 | ArrayRef<TemplateArgument> TemplateArgs, |
||
9559 | SourceRange InstantiationRange); |
||
9560 | |||
9561 | struct ConstraintSubstitution {}; |
||
9562 | /// \brief Note that we are checking a constraint expression associated |
||
9563 | /// with a template declaration or as part of the satisfaction check of a |
||
9564 | /// concept. |
||
9565 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9566 | ConstraintSubstitution, NamedDecl *Template, |
||
9567 | sema::TemplateDeductionInfo &DeductionInfo, |
||
9568 | SourceRange InstantiationRange); |
||
9569 | |||
9570 | struct ConstraintNormalization {}; |
||
9571 | /// \brief Note that we are normalizing a constraint expression. |
||
9572 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9573 | ConstraintNormalization, NamedDecl *Template, |
||
9574 | SourceRange InstantiationRange); |
||
9575 | |||
9576 | struct ParameterMappingSubstitution {}; |
||
9577 | /// \brief Note that we are subtituting into the parameter mapping of an |
||
9578 | /// atomic constraint during constraint normalization. |
||
9579 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9580 | ParameterMappingSubstitution, NamedDecl *Template, |
||
9581 | SourceRange InstantiationRange); |
||
9582 | |||
9583 | /// \brief Note that we are substituting template arguments into a part of |
||
9584 | /// a requirement of a requires expression. |
||
9585 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9586 | concepts::Requirement *Req, |
||
9587 | sema::TemplateDeductionInfo &DeductionInfo, |
||
9588 | SourceRange InstantiationRange = SourceRange()); |
||
9589 | |||
9590 | /// \brief Note that we are checking the satisfaction of the constraint |
||
9591 | /// expression inside of a nested requirement. |
||
9592 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9593 | concepts::NestedRequirement *Req, ConstraintsCheck, |
||
9594 | SourceRange InstantiationRange = SourceRange()); |
||
9595 | |||
9596 | /// \brief Note that we are checking a requires clause. |
||
9597 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
||
9598 | const RequiresExpr *E, |
||
9599 | sema::TemplateDeductionInfo &DeductionInfo, |
||
9600 | SourceRange InstantiationRange); |
||
9601 | /// Note that we have finished instantiating this template. |
||
9602 | void Clear(); |
||
9603 | |||
9604 | ~InstantiatingTemplate() { Clear(); } |
||
9605 | |||
9606 | /// Determines whether we have exceeded the maximum |
||
9607 | /// recursive template instantiations. |
||
9608 | bool isInvalid() const { return Invalid; } |
||
9609 | |||
9610 | /// Determine whether we are already instantiating this |
||
9611 | /// specialization in some surrounding active instantiation. |
||
9612 | bool isAlreadyInstantiating() const { return AlreadyInstantiating; } |
||
9613 | |||
9614 | private: |
||
9615 | Sema &SemaRef; |
||
9616 | bool Invalid; |
||
9617 | bool AlreadyInstantiating; |
||
9618 | bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, |
||
9619 | SourceRange InstantiationRange); |
||
9620 | |||
9621 | InstantiatingTemplate( |
||
9622 | Sema &SemaRef, CodeSynthesisContext::SynthesisKind Kind, |
||
9623 | SourceLocation PointOfInstantiation, SourceRange InstantiationRange, |
||
9624 | Decl *Entity, NamedDecl *Template = nullptr, |
||
9625 | ArrayRef<TemplateArgument> TemplateArgs = std::nullopt, |
||
9626 | sema::TemplateDeductionInfo *DeductionInfo = nullptr); |
||
9627 | |||
9628 | InstantiatingTemplate(const InstantiatingTemplate&) = delete; |
||
9629 | |||
9630 | InstantiatingTemplate& |
||
9631 | operator=(const InstantiatingTemplate&) = delete; |
||
9632 | }; |
||
9633 | |||
9634 | void pushCodeSynthesisContext(CodeSynthesisContext Ctx); |
||
9635 | void popCodeSynthesisContext(); |
||
9636 | |||
9637 | /// Determine whether we are currently performing template instantiation. |
||
9638 | bool inTemplateInstantiation() const { |
||
9639 | return CodeSynthesisContexts.size() > NonInstantiationEntries; |
||
9640 | } |
||
9641 | |||
9642 | void PrintContextStack() { |
||
9643 | if (!CodeSynthesisContexts.empty() && |
||
9644 | CodeSynthesisContexts.size() != LastEmittedCodeSynthesisContextDepth) { |
||
9645 | PrintInstantiationStack(); |
||
9646 | LastEmittedCodeSynthesisContextDepth = CodeSynthesisContexts.size(); |
||
9647 | } |
||
9648 | if (PragmaAttributeCurrentTargetDecl) |
||
9649 | PrintPragmaAttributeInstantiationPoint(); |
||
9650 | } |
||
9651 | void PrintInstantiationStack(); |
||
9652 | |||
9653 | void PrintPragmaAttributeInstantiationPoint(); |
||
9654 | |||
9655 | /// Determines whether we are currently in a context where |
||
9656 | /// template argument substitution failures are not considered |
||
9657 | /// errors. |
||
9658 | /// |
||
9659 | /// \returns An empty \c Optional if we're not in a SFINAE context. |
||
9660 | /// Otherwise, contains a pointer that, if non-NULL, contains the nearest |
||
9661 | /// template-deduction context object, which can be used to capture |
||
9662 | /// diagnostics that will be suppressed. |
||
9663 | std::optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; |
||
9664 | |||
9665 | /// Determines whether we are currently in a context that |
||
9666 | /// is not evaluated as per C++ [expr] p5. |
||
9667 | bool isUnevaluatedContext() const { |
||
9668 | assert(!ExprEvalContexts.empty() && |
||
9669 | "Must be in an expression evaluation context"); |
||
9670 | return ExprEvalContexts.back().isUnevaluated(); |
||
9671 | } |
||
9672 | |||
9673 | bool isConstantEvaluatedContext() const { |
||
9674 | assert(!ExprEvalContexts.empty() && |
||
9675 | "Must be in an expression evaluation context"); |
||
9676 | return ExprEvalContexts.back().isConstantEvaluated(); |
||
9677 | } |
||
9678 | |||
9679 | bool isImmediateFunctionContext() const { |
||
9680 | assert(!ExprEvalContexts.empty() && |
||
9681 | "Must be in an expression evaluation context"); |
||
9682 | return ExprEvalContexts.back().isImmediateFunctionContext(); |
||
9683 | } |
||
9684 | |||
9685 | bool isCheckingDefaultArgumentOrInitializer() const { |
||
9686 | assert(!ExprEvalContexts.empty() && |
||
9687 | "Must be in an expression evaluation context"); |
||
9688 | const ExpressionEvaluationContextRecord &Ctx = ExprEvalContexts.back(); |
||
9689 | return (Ctx.Context == |
||
9690 | ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed) || |
||
9691 | Ctx.IsCurrentlyCheckingDefaultArgumentOrInitializer; |
||
9692 | } |
||
9693 | |||
9694 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> |
||
9695 | InnermostDeclarationWithDelayedImmediateInvocations() const { |
||
9696 | assert(!ExprEvalContexts.empty() && |
||
9697 | "Must be in an expression evaluation context"); |
||
9698 | for (const auto &Ctx : llvm::reverse(ExprEvalContexts)) { |
||
9699 | if (Ctx.Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
||
9700 | Ctx.DelayedDefaultInitializationContext) |
||
9701 | return Ctx.DelayedDefaultInitializationContext; |
||
9702 | if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() || |
||
9703 | Ctx.isUnevaluated()) |
||
9704 | break; |
||
9705 | } |
||
9706 | return std::nullopt; |
||
9707 | } |
||
9708 | |||
9709 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> |
||
9710 | OutermostDeclarationWithDelayedImmediateInvocations() const { |
||
9711 | assert(!ExprEvalContexts.empty() && |
||
9712 | "Must be in an expression evaluation context"); |
||
9713 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> Res; |
||
9714 | for (auto &Ctx : llvm::reverse(ExprEvalContexts)) { |
||
9715 | if (Ctx.Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
||
9716 | !Ctx.DelayedDefaultInitializationContext && Res) |
||
9717 | break; |
||
9718 | if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() || |
||
9719 | Ctx.isUnevaluated()) |
||
9720 | break; |
||
9721 | Res = Ctx.DelayedDefaultInitializationContext; |
||
9722 | } |
||
9723 | return Res; |
||
9724 | } |
||
9725 | |||
9726 | /// RAII class used to determine whether SFINAE has |
||
9727 | /// trapped any errors that occur during template argument |
||
9728 | /// deduction. |
||
9729 | class SFINAETrap { |
||
9730 | Sema &SemaRef; |
||
9731 | unsigned PrevSFINAEErrors; |
||
9732 | bool PrevInNonInstantiationSFINAEContext; |
||
9733 | bool PrevAccessCheckingSFINAE; |
||
9734 | bool PrevLastDiagnosticIgnored; |
||
9735 | |||
9736 | public: |
||
9737 | explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) |
||
9738 | : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), |
||
9739 | PrevInNonInstantiationSFINAEContext( |
||
9740 | SemaRef.InNonInstantiationSFINAEContext), |
||
9741 | PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE), |
||
9742 | PrevLastDiagnosticIgnored( |
||
9743 | SemaRef.getDiagnostics().isLastDiagnosticIgnored()) |
||
9744 | { |
||
9745 | if (!SemaRef.isSFINAEContext()) |
||
9746 | SemaRef.InNonInstantiationSFINAEContext = true; |
||
9747 | SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; |
||
9748 | } |
||
9749 | |||
9750 | ~SFINAETrap() { |
||
9751 | SemaRef.NumSFINAEErrors = PrevSFINAEErrors; |
||
9752 | SemaRef.InNonInstantiationSFINAEContext |
||
9753 | = PrevInNonInstantiationSFINAEContext; |
||
9754 | SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; |
||
9755 | SemaRef.getDiagnostics().setLastDiagnosticIgnored( |
||
9756 | PrevLastDiagnosticIgnored); |
||
9757 | } |
||
9758 | |||
9759 | /// Determine whether any SFINAE errors have been trapped. |
||
9760 | bool hasErrorOccurred() const { |
||
9761 | return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; |
||
9762 | } |
||
9763 | }; |
||
9764 | |||
9765 | /// RAII class used to indicate that we are performing provisional |
||
9766 | /// semantic analysis to determine the validity of a construct, so |
||
9767 | /// typo-correction and diagnostics in the immediate context (not within |
||
9768 | /// implicitly-instantiated templates) should be suppressed. |
||
9769 | class TentativeAnalysisScope { |
||
9770 | Sema &SemaRef; |
||
9771 | // FIXME: Using a SFINAETrap for this is a hack. |
||
9772 | SFINAETrap Trap; |
||
9773 | bool PrevDisableTypoCorrection; |
||
9774 | public: |
||
9775 | explicit TentativeAnalysisScope(Sema &SemaRef) |
||
9776 | : SemaRef(SemaRef), Trap(SemaRef, true), |
||
9777 | PrevDisableTypoCorrection(SemaRef.DisableTypoCorrection) { |
||
9778 | SemaRef.DisableTypoCorrection = true; |
||
9779 | } |
||
9780 | ~TentativeAnalysisScope() { |
||
9781 | SemaRef.DisableTypoCorrection = PrevDisableTypoCorrection; |
||
9782 | } |
||
9783 | }; |
||
9784 | |||
9785 | /// The current instantiation scope used to store local |
||
9786 | /// variables. |
||
9787 | LocalInstantiationScope *CurrentInstantiationScope; |
||
9788 | |||
9789 | /// Tracks whether we are in a context where typo correction is |
||
9790 | /// disabled. |
||
9791 | bool DisableTypoCorrection; |
||
9792 | |||
9793 | /// The number of typos corrected by CorrectTypo. |
||
9794 | unsigned TyposCorrected; |
||
9795 | |||
9796 | typedef llvm::SmallSet<SourceLocation, 2> SrcLocSet; |
||
9797 | typedef llvm::DenseMap<IdentifierInfo *, SrcLocSet> IdentifierSourceLocations; |
||
9798 | |||
9799 | /// A cache containing identifiers for which typo correction failed and |
||
9800 | /// their locations, so that repeated attempts to correct an identifier in a |
||
9801 | /// given location are ignored if typo correction already failed for it. |
||
9802 | IdentifierSourceLocations TypoCorrectionFailures; |
||
9803 | |||
9804 | /// Worker object for performing CFG-based warnings. |
||
9805 | sema::AnalysisBasedWarnings AnalysisWarnings; |
||
9806 | threadSafety::BeforeSet *ThreadSafetyDeclCache; |
||
9807 | |||
9808 | /// An entity for which implicit template instantiation is required. |
||
9809 | /// |
||
9810 | /// The source location associated with the declaration is the first place in |
||
9811 | /// the source code where the declaration was "used". It is not necessarily |
||
9812 | /// the point of instantiation (which will be either before or after the |
||
9813 | /// namespace-scope declaration that triggered this implicit instantiation), |
||
9814 | /// However, it is the location that diagnostics should generally refer to, |
||
9815 | /// because users will need to know what code triggered the instantiation. |
||
9816 | typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; |
||
9817 | |||
9818 | /// The queue of implicit template instantiations that are required |
||
9819 | /// but have not yet been performed. |
||
9820 | std::deque<PendingImplicitInstantiation> PendingInstantiations; |
||
9821 | |||
9822 | /// Queue of implicit template instantiations that cannot be performed |
||
9823 | /// eagerly. |
||
9824 | SmallVector<PendingImplicitInstantiation, 1> LateParsedInstantiations; |
||
9825 | |||
9826 | class GlobalEagerInstantiationScope { |
||
9827 | public: |
||
9828 | GlobalEagerInstantiationScope(Sema &S, bool Enabled) |
||
9829 | : S(S), Enabled(Enabled) { |
||
9830 | if (!Enabled) return; |
||
9831 | |||
9832 | SavedPendingInstantiations.swap(S.PendingInstantiations); |
||
9833 | SavedVTableUses.swap(S.VTableUses); |
||
9834 | } |
||
9835 | |||
9836 | void perform() { |
||
9837 | if (Enabled) { |
||
9838 | S.DefineUsedVTables(); |
||
9839 | S.PerformPendingInstantiations(); |
||
9840 | } |
||
9841 | } |
||
9842 | |||
9843 | ~GlobalEagerInstantiationScope() { |
||
9844 | if (!Enabled) return; |
||
9845 | |||
9846 | // Restore the set of pending vtables. |
||
9847 | assert(S.VTableUses.empty() && |
||
9848 | "VTableUses should be empty before it is discarded."); |
||
9849 | S.VTableUses.swap(SavedVTableUses); |
||
9850 | |||
9851 | // Restore the set of pending implicit instantiations. |
||
9852 | if (S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) { |
||
9853 | assert(S.PendingInstantiations.empty() && |
||
9854 | "PendingInstantiations should be empty before it is discarded."); |
||
9855 | S.PendingInstantiations.swap(SavedPendingInstantiations); |
||
9856 | } else { |
||
9857 | // Template instantiations in the PCH may be delayed until the TU. |
||
9858 | S.PendingInstantiations.swap(SavedPendingInstantiations); |
||
9859 | S.PendingInstantiations.insert(S.PendingInstantiations.end(), |
||
9860 | SavedPendingInstantiations.begin(), |
||
9861 | SavedPendingInstantiations.end()); |
||
9862 | } |
||
9863 | } |
||
9864 | |||
9865 | private: |
||
9866 | Sema &S; |
||
9867 | SmallVector<VTableUse, 16> SavedVTableUses; |
||
9868 | std::deque<PendingImplicitInstantiation> SavedPendingInstantiations; |
||
9869 | bool Enabled; |
||
9870 | }; |
||
9871 | |||
9872 | /// The queue of implicit template instantiations that are required |
||
9873 | /// and must be performed within the current local scope. |
||
9874 | /// |
||
9875 | /// This queue is only used for member functions of local classes in |
||
9876 | /// templates, which must be instantiated in the same scope as their |
||
9877 | /// enclosing function, so that they can reference function-local |
||
9878 | /// types, static variables, enumerators, etc. |
||
9879 | std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; |
||
9880 | |||
9881 | class LocalEagerInstantiationScope { |
||
9882 | public: |
||
9883 | LocalEagerInstantiationScope(Sema &S) : S(S) { |
||
9884 | SavedPendingLocalImplicitInstantiations.swap( |
||
9885 | S.PendingLocalImplicitInstantiations); |
||
9886 | } |
||
9887 | |||
9888 | void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/true); } |
||
9889 | |||
9890 | ~LocalEagerInstantiationScope() { |
||
9891 | assert(S.PendingLocalImplicitInstantiations.empty() && |
||
9892 | "there shouldn't be any pending local implicit instantiations"); |
||
9893 | SavedPendingLocalImplicitInstantiations.swap( |
||
9894 | S.PendingLocalImplicitInstantiations); |
||
9895 | } |
||
9896 | |||
9897 | private: |
||
9898 | Sema &S; |
||
9899 | std::deque<PendingImplicitInstantiation> |
||
9900 | SavedPendingLocalImplicitInstantiations; |
||
9901 | }; |
||
9902 | |||
9903 | /// A helper class for building up ExtParameterInfos. |
||
9904 | class ExtParameterInfoBuilder { |
||
9905 | SmallVector<FunctionProtoType::ExtParameterInfo, 16> Infos; |
||
9906 | bool HasInteresting = false; |
||
9907 | |||
9908 | public: |
||
9909 | /// Set the ExtParameterInfo for the parameter at the given index, |
||
9910 | /// |
||
9911 | void set(unsigned index, FunctionProtoType::ExtParameterInfo info) { |
||
9912 | assert(Infos.size() <= index); |
||
9913 | Infos.resize(index); |
||
9914 | Infos.push_back(info); |
||
9915 | |||
9916 | if (!HasInteresting) |
||
9917 | HasInteresting = (info != FunctionProtoType::ExtParameterInfo()); |
||
9918 | } |
||
9919 | |||
9920 | /// Return a pointer (suitable for setting in an ExtProtoInfo) to the |
||
9921 | /// ExtParameterInfo array we've built up. |
||
9922 | const FunctionProtoType::ExtParameterInfo * |
||
9923 | getPointerOrNull(unsigned numParams) { |
||
9924 | if (!HasInteresting) return nullptr; |
||
9925 | Infos.resize(numParams); |
||
9926 | return Infos.data(); |
||
9927 | } |
||
9928 | }; |
||
9929 | |||
9930 | void PerformPendingInstantiations(bool LocalOnly = false); |
||
9931 | |||
9932 | TypeSourceInfo *SubstType(TypeSourceInfo *T, |
||
9933 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
9934 | SourceLocation Loc, DeclarationName Entity, |
||
9935 | bool AllowDeducedTST = false); |
||
9936 | |||
9937 | QualType SubstType(QualType T, |
||
9938 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
9939 | SourceLocation Loc, DeclarationName Entity); |
||
9940 | |||
9941 | TypeSourceInfo *SubstType(TypeLoc TL, |
||
9942 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
9943 | SourceLocation Loc, DeclarationName Entity); |
||
9944 | |||
9945 | TypeSourceInfo *SubstFunctionDeclType( |
||
9946 | TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, |
||
9947 | SourceLocation Loc, DeclarationName Entity, CXXRecordDecl *ThisContext, |
||
9948 | Qualifiers ThisTypeQuals, bool EvaluateConstraints = true); |
||
9949 | void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, |
||
9950 | const MultiLevelTemplateArgumentList &Args); |
||
9951 | bool SubstExceptionSpec(SourceLocation Loc, |
||
9952 | FunctionProtoType::ExceptionSpecInfo &ESI, |
||
9953 | SmallVectorImpl<QualType> &ExceptionStorage, |
||
9954 | const MultiLevelTemplateArgumentList &Args); |
||
9955 | ParmVarDecl * |
||
9956 | SubstParmVarDecl(ParmVarDecl *D, |
||
9957 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
9958 | int indexAdjustment, std::optional<unsigned> NumExpansions, |
||
9959 | bool ExpectParameterPack, bool EvaluateConstraints = true); |
||
9960 | bool SubstParmTypes(SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
||
9961 | const FunctionProtoType::ExtParameterInfo *ExtParamInfos, |
||
9962 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
9963 | SmallVectorImpl<QualType> &ParamTypes, |
||
9964 | SmallVectorImpl<ParmVarDecl *> *OutParams, |
||
9965 | ExtParameterInfoBuilder &ParamInfos); |
||
9966 | bool SubstDefaultArgument(SourceLocation Loc, ParmVarDecl *Param, |
||
9967 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
9968 | bool ForCallExpr = false); |
||
9969 | ExprResult SubstExpr(Expr *E, |
||
9970 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
9971 | |||
9972 | // A RAII type used by the TemplateDeclInstantiator and TemplateInstantiator |
||
9973 | // to disable constraint evaluation, then restore the state. |
||
9974 | template <typename InstTy> struct ConstraintEvalRAII { |
||
9975 | InstTy &TI; |
||
9976 | bool OldValue; |
||
9977 | |||
9978 | ConstraintEvalRAII(InstTy &TI) |
||
9979 | : TI(TI), OldValue(TI.getEvaluateConstraints()) { |
||
9980 | TI.setEvaluateConstraints(false); |
||
9981 | } |
||
9982 | ~ConstraintEvalRAII() { TI.setEvaluateConstraints(OldValue); } |
||
9983 | }; |
||
9984 | |||
9985 | // Unlike the above, this evaluates constraints, which should only happen at |
||
9986 | // 'constraint checking' time. |
||
9987 | ExprResult |
||
9988 | SubstConstraintExpr(Expr *E, |
||
9989 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
9990 | |||
9991 | /// Substitute the given template arguments into a list of |
||
9992 | /// expressions, expanding pack expansions if required. |
||
9993 | /// |
||
9994 | /// \param Exprs The list of expressions to substitute into. |
||
9995 | /// |
||
9996 | /// \param IsCall Whether this is some form of call, in which case |
||
9997 | /// default arguments will be dropped. |
||
9998 | /// |
||
9999 | /// \param TemplateArgs The set of template arguments to substitute. |
||
10000 | /// |
||
10001 | /// \param Outputs Will receive all of the substituted arguments. |
||
10002 | /// |
||
10003 | /// \returns true if an error occurred, false otherwise. |
||
10004 | bool SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall, |
||
10005 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
10006 | SmallVectorImpl<Expr *> &Outputs); |
||
10007 | |||
10008 | StmtResult SubstStmt(Stmt *S, |
||
10009 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
10010 | |||
10011 | TemplateParameterList * |
||
10012 | SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner, |
||
10013 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
10014 | bool EvaluateConstraints = true); |
||
10015 | |||
10016 | bool |
||
10017 | SubstTemplateArguments(ArrayRef<TemplateArgumentLoc> Args, |
||
10018 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
10019 | TemplateArgumentListInfo &Outputs); |
||
10020 | |||
10021 | Decl *SubstDecl(Decl *D, DeclContext *Owner, |
||
10022 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
10023 | |||
10024 | /// Substitute the name and return type of a defaulted 'operator<=>' to form |
||
10025 | /// an implicit 'operator=='. |
||
10026 | FunctionDecl *SubstSpaceshipAsEqualEqual(CXXRecordDecl *RD, |
||
10027 | FunctionDecl *Spaceship); |
||
10028 | |||
10029 | ExprResult SubstInitializer(Expr *E, |
||
10030 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
10031 | bool CXXDirectInit); |
||
10032 | |||
10033 | bool |
||
10034 | SubstBaseSpecifiers(CXXRecordDecl *Instantiation, |
||
10035 | CXXRecordDecl *Pattern, |
||
10036 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
10037 | |||
10038 | bool |
||
10039 | InstantiateClass(SourceLocation PointOfInstantiation, |
||
10040 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
||
10041 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
10042 | TemplateSpecializationKind TSK, |
||
10043 | bool Complain = true); |
||
10044 | |||
10045 | bool InstantiateEnum(SourceLocation PointOfInstantiation, |
||
10046 | EnumDecl *Instantiation, EnumDecl *Pattern, |
||
10047 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
10048 | TemplateSpecializationKind TSK); |
||
10049 | |||
10050 | bool InstantiateInClassInitializer( |
||
10051 | SourceLocation PointOfInstantiation, FieldDecl *Instantiation, |
||
10052 | FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs); |
||
10053 | |||
10054 | struct LateInstantiatedAttribute { |
||
10055 | const Attr *TmplAttr; |
||
10056 | LocalInstantiationScope *Scope; |
||
10057 | Decl *NewDecl; |
||
10058 | |||
10059 | LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S, |
||
10060 | Decl *D) |
||
10061 | : TmplAttr(A), Scope(S), NewDecl(D) |
||
10062 | { } |
||
10063 | }; |
||
10064 | typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec; |
||
10065 | |||
10066 | void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, |
||
10067 | const Decl *Pattern, Decl *Inst, |
||
10068 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
||
10069 | LocalInstantiationScope *OuterMostScope = nullptr); |
||
10070 | |||
10071 | void |
||
10072 | InstantiateAttrsForDecl(const MultiLevelTemplateArgumentList &TemplateArgs, |
||
10073 | const Decl *Pattern, Decl *Inst, |
||
10074 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
||
10075 | LocalInstantiationScope *OuterMostScope = nullptr); |
||
10076 | |||
10077 | void InstantiateDefaultCtorDefaultArgs(CXXConstructorDecl *Ctor); |
||
10078 | |||
10079 | bool usesPartialOrExplicitSpecialization( |
||
10080 | SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec); |
||
10081 | |||
10082 | bool |
||
10083 | InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, |
||
10084 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
||
10085 | TemplateSpecializationKind TSK, |
||
10086 | bool Complain = true); |
||
10087 | |||
10088 | void InstantiateClassMembers(SourceLocation PointOfInstantiation, |
||
10089 | CXXRecordDecl *Instantiation, |
||
10090 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
10091 | TemplateSpecializationKind TSK); |
||
10092 | |||
10093 | void InstantiateClassTemplateSpecializationMembers( |
||
10094 | SourceLocation PointOfInstantiation, |
||
10095 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
||
10096 | TemplateSpecializationKind TSK); |
||
10097 | |||
10098 | NestedNameSpecifierLoc |
||
10099 | SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
||
10100 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
10101 | |||
10102 | DeclarationNameInfo |
||
10103 | SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
||
10104 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
10105 | TemplateName |
||
10106 | SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, |
||
10107 | SourceLocation Loc, |
||
10108 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
10109 | |||
10110 | bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC, |
||
10111 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
10112 | bool EvaluateConstraint); |
||
10113 | |||
10114 | bool InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD, |
||
10115 | ParmVarDecl *Param); |
||
10116 | void InstantiateExceptionSpec(SourceLocation PointOfInstantiation, |
||
10117 | FunctionDecl *Function); |
||
10118 | bool CheckInstantiatedFunctionTemplateConstraints( |
||
10119 | SourceLocation PointOfInstantiation, FunctionDecl *Decl, |
||
10120 | ArrayRef<TemplateArgument> TemplateArgs, |
||
10121 | ConstraintSatisfaction &Satisfaction); |
||
10122 | FunctionDecl *InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD, |
||
10123 | const TemplateArgumentList *Args, |
||
10124 | SourceLocation Loc); |
||
10125 | void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, |
||
10126 | FunctionDecl *Function, |
||
10127 | bool Recursive = false, |
||
10128 | bool DefinitionRequired = false, |
||
10129 | bool AtEndOfTU = false); |
||
10130 | VarTemplateSpecializationDecl *BuildVarTemplateInstantiation( |
||
10131 | VarTemplateDecl *VarTemplate, VarDecl *FromVar, |
||
10132 | const TemplateArgumentList &TemplateArgList, |
||
10133 | const TemplateArgumentListInfo &TemplateArgsInfo, |
||
10134 | SmallVectorImpl<TemplateArgument> &Converted, |
||
10135 | SourceLocation PointOfInstantiation, |
||
10136 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
||
10137 | LocalInstantiationScope *StartingScope = nullptr); |
||
10138 | VarTemplateSpecializationDecl *CompleteVarTemplateSpecializationDecl( |
||
10139 | VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl, |
||
10140 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
10141 | void |
||
10142 | BuildVariableInstantiation(VarDecl *NewVar, VarDecl *OldVar, |
||
10143 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
10144 | LateInstantiatedAttrVec *LateAttrs, |
||
10145 | DeclContext *Owner, |
||
10146 | LocalInstantiationScope *StartingScope, |
||
10147 | bool InstantiatingVarTemplate = false, |
||
10148 | VarTemplateSpecializationDecl *PrevVTSD = nullptr); |
||
10149 | |||
10150 | void InstantiateVariableInitializer( |
||
10151 | VarDecl *Var, VarDecl *OldVar, |
||
10152 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
10153 | void InstantiateVariableDefinition(SourceLocation PointOfInstantiation, |
||
10154 | VarDecl *Var, bool Recursive = false, |
||
10155 | bool DefinitionRequired = false, |
||
10156 | bool AtEndOfTU = false); |
||
10157 | |||
10158 | void InstantiateMemInitializers(CXXConstructorDecl *New, |
||
10159 | const CXXConstructorDecl *Tmpl, |
||
10160 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
10161 | |||
10162 | NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, |
||
10163 | const MultiLevelTemplateArgumentList &TemplateArgs, |
||
10164 | bool FindingInstantiatedContext = false); |
||
10165 | DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, |
||
10166 | const MultiLevelTemplateArgumentList &TemplateArgs); |
||
10167 | |||
10168 | // Objective-C declarations. |
||
10169 | enum ObjCContainerKind { |
||
10170 | OCK_None = -1, |
||
10171 | OCK_Interface = 0, |
||
10172 | OCK_Protocol, |
||
10173 | OCK_Category, |
||
10174 | OCK_ClassExtension, |
||
10175 | OCK_Implementation, |
||
10176 | OCK_CategoryImplementation |
||
10177 | }; |
||
10178 | ObjCContainerKind getObjCContainerKind() const; |
||
10179 | |||
10180 | DeclResult actOnObjCTypeParam(Scope *S, |
||
10181 | ObjCTypeParamVariance variance, |
||
10182 | SourceLocation varianceLoc, |
||
10183 | unsigned index, |
||
10184 | IdentifierInfo *paramName, |
||
10185 | SourceLocation paramLoc, |
||
10186 | SourceLocation colonLoc, |
||
10187 | ParsedType typeBound); |
||
10188 | |||
10189 | ObjCTypeParamList *actOnObjCTypeParamList(Scope *S, SourceLocation lAngleLoc, |
||
10190 | ArrayRef<Decl *> typeParams, |
||
10191 | SourceLocation rAngleLoc); |
||
10192 | void popObjCTypeParamList(Scope *S, ObjCTypeParamList *typeParamList); |
||
10193 | |||
10194 | ObjCInterfaceDecl *ActOnStartClassInterface( |
||
10195 | Scope *S, SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, |
||
10196 | SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, |
||
10197 | IdentifierInfo *SuperName, SourceLocation SuperLoc, |
||
10198 | ArrayRef<ParsedType> SuperTypeArgs, SourceRange SuperTypeArgsRange, |
||
10199 | Decl *const *ProtoRefs, unsigned NumProtoRefs, |
||
10200 | const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, |
||
10201 | const ParsedAttributesView &AttrList, SkipBodyInfo *SkipBody); |
||
10202 | |||
10203 | void ActOnSuperClassOfClassInterface(Scope *S, |
||
10204 | SourceLocation AtInterfaceLoc, |
||
10205 | ObjCInterfaceDecl *IDecl, |
||
10206 | IdentifierInfo *ClassName, |
||
10207 | SourceLocation ClassLoc, |
||
10208 | IdentifierInfo *SuperName, |
||
10209 | SourceLocation SuperLoc, |
||
10210 | ArrayRef<ParsedType> SuperTypeArgs, |
||
10211 | SourceRange SuperTypeArgsRange); |
||
10212 | |||
10213 | void ActOnTypedefedProtocols(SmallVectorImpl<Decl *> &ProtocolRefs, |
||
10214 | SmallVectorImpl<SourceLocation> &ProtocolLocs, |
||
10215 | IdentifierInfo *SuperName, |
||
10216 | SourceLocation SuperLoc); |
||
10217 | |||
10218 | Decl *ActOnCompatibilityAlias( |
||
10219 | SourceLocation AtCompatibilityAliasLoc, |
||
10220 | IdentifierInfo *AliasName, SourceLocation AliasLocation, |
||
10221 | IdentifierInfo *ClassName, SourceLocation ClassLocation); |
||
10222 | |||
10223 | bool CheckForwardProtocolDeclarationForCircularDependency( |
||
10224 | IdentifierInfo *PName, |
||
10225 | SourceLocation &PLoc, SourceLocation PrevLoc, |
||
10226 | const ObjCList<ObjCProtocolDecl> &PList); |
||
10227 | |||
10228 | ObjCProtocolDecl *ActOnStartProtocolInterface( |
||
10229 | SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName, |
||
10230 | SourceLocation ProtocolLoc, Decl *const *ProtoRefNames, |
||
10231 | unsigned NumProtoRefs, const SourceLocation *ProtoLocs, |
||
10232 | SourceLocation EndProtoLoc, const ParsedAttributesView &AttrList, |
||
10233 | SkipBodyInfo *SkipBody); |
||
10234 | |||
10235 | ObjCCategoryDecl *ActOnStartCategoryInterface( |
||
10236 | SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, |
||
10237 | SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, |
||
10238 | IdentifierInfo *CategoryName, SourceLocation CategoryLoc, |
||
10239 | Decl *const *ProtoRefs, unsigned NumProtoRefs, |
||
10240 | const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, |
||
10241 | const ParsedAttributesView &AttrList); |
||
10242 | |||
10243 | ObjCImplementationDecl *ActOnStartClassImplementation( |
||
10244 | SourceLocation AtClassImplLoc, IdentifierInfo *ClassName, |
||
10245 | SourceLocation ClassLoc, IdentifierInfo *SuperClassname, |
||
10246 | SourceLocation SuperClassLoc, const ParsedAttributesView &AttrList); |
||
10247 | |||
10248 | ObjCCategoryImplDecl *ActOnStartCategoryImplementation( |
||
10249 | SourceLocation AtCatImplLoc, IdentifierInfo *ClassName, |
||
10250 | SourceLocation ClassLoc, IdentifierInfo *CatName, SourceLocation CatLoc, |
||
10251 | const ParsedAttributesView &AttrList); |
||
10252 | |||
10253 | DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, |
||
10254 | ArrayRef<Decl *> Decls); |
||
10255 | |||
10256 | DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, |
||
10257 | IdentifierInfo **IdentList, |
||
10258 | SourceLocation *IdentLocs, |
||
10259 | ArrayRef<ObjCTypeParamList *> TypeParamLists, |
||
10260 | unsigned NumElts); |
||
10261 | |||
10262 | DeclGroupPtrTy |
||
10263 | ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, |
||
10264 | ArrayRef<IdentifierLocPair> IdentList, |
||
10265 | const ParsedAttributesView &attrList); |
||
10266 | |||
10267 | void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer, |
||
10268 | ArrayRef<IdentifierLocPair> ProtocolId, |
||
10269 | SmallVectorImpl<Decl *> &Protocols); |
||
10270 | |||
10271 | void DiagnoseTypeArgsAndProtocols(IdentifierInfo *ProtocolId, |
||
10272 | SourceLocation ProtocolLoc, |
||
10273 | IdentifierInfo *TypeArgId, |
||
10274 | SourceLocation TypeArgLoc, |
||
10275 | bool SelectProtocolFirst = false); |
||
10276 | |||
10277 | /// Given a list of identifiers (and their locations), resolve the |
||
10278 | /// names to either Objective-C protocol qualifiers or type |
||
10279 | /// arguments, as appropriate. |
||
10280 | void actOnObjCTypeArgsOrProtocolQualifiers( |
||
10281 | Scope *S, |
||
10282 | ParsedType baseType, |
||
10283 | SourceLocation lAngleLoc, |
||
10284 | ArrayRef<IdentifierInfo *> identifiers, |
||
10285 | ArrayRef<SourceLocation> identifierLocs, |
||
10286 | SourceLocation rAngleLoc, |
||
10287 | SourceLocation &typeArgsLAngleLoc, |
||
10288 | SmallVectorImpl<ParsedType> &typeArgs, |
||
10289 | SourceLocation &typeArgsRAngleLoc, |
||
10290 | SourceLocation &protocolLAngleLoc, |
||
10291 | SmallVectorImpl<Decl *> &protocols, |
||
10292 | SourceLocation &protocolRAngleLoc, |
||
10293 | bool warnOnIncompleteProtocols); |
||
10294 | |||
10295 | /// Build a an Objective-C protocol-qualified 'id' type where no |
||
10296 | /// base type was specified. |
||
10297 | TypeResult actOnObjCProtocolQualifierType( |
||
10298 | SourceLocation lAngleLoc, |
||
10299 | ArrayRef<Decl *> protocols, |
||
10300 | ArrayRef<SourceLocation> protocolLocs, |
||
10301 | SourceLocation rAngleLoc); |
||
10302 | |||
10303 | /// Build a specialized and/or protocol-qualified Objective-C type. |
||
10304 | TypeResult actOnObjCTypeArgsAndProtocolQualifiers( |
||
10305 | Scope *S, |
||
10306 | SourceLocation Loc, |
||
10307 | ParsedType BaseType, |
||
10308 | SourceLocation TypeArgsLAngleLoc, |
||
10309 | ArrayRef<ParsedType> TypeArgs, |
||
10310 | SourceLocation TypeArgsRAngleLoc, |
||
10311 | SourceLocation ProtocolLAngleLoc, |
||
10312 | ArrayRef<Decl *> Protocols, |
||
10313 | ArrayRef<SourceLocation> ProtocolLocs, |
||
10314 | SourceLocation ProtocolRAngleLoc); |
||
10315 | |||
10316 | /// Build an Objective-C type parameter type. |
||
10317 | QualType BuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, |
||
10318 | SourceLocation ProtocolLAngleLoc, |
||
10319 | ArrayRef<ObjCProtocolDecl *> Protocols, |
||
10320 | ArrayRef<SourceLocation> ProtocolLocs, |
||
10321 | SourceLocation ProtocolRAngleLoc, |
||
10322 | bool FailOnError = false); |
||
10323 | |||
10324 | /// Build an Objective-C object pointer type. |
||
10325 | QualType BuildObjCObjectType( |
||
10326 | QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, |
||
10327 | ArrayRef<TypeSourceInfo *> TypeArgs, SourceLocation TypeArgsRAngleLoc, |
||
10328 | SourceLocation ProtocolLAngleLoc, ArrayRef<ObjCProtocolDecl *> Protocols, |
||
10329 | ArrayRef<SourceLocation> ProtocolLocs, SourceLocation ProtocolRAngleLoc, |
||
10330 | bool FailOnError, bool Rebuilding); |
||
10331 | |||
10332 | /// Ensure attributes are consistent with type. |
||
10333 | /// \param [in, out] Attributes The attributes to check; they will |
||
10334 | /// be modified to be consistent with \p PropertyTy. |
||
10335 | void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, |
||
10336 | SourceLocation Loc, |
||
10337 | unsigned &Attributes, |
||
10338 | bool propertyInPrimaryClass); |
||
10339 | |||
10340 | /// Process the specified property declaration and create decls for the |
||
10341 | /// setters and getters as needed. |
||
10342 | /// \param property The property declaration being processed |
||
10343 | void ProcessPropertyDecl(ObjCPropertyDecl *property); |
||
10344 | |||
10345 | |||
10346 | void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, |
||
10347 | ObjCPropertyDecl *SuperProperty, |
||
10348 | const IdentifierInfo *Name, |
||
10349 | bool OverridingProtocolProperty); |
||
10350 | |||
10351 | void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, |
||
10352 | ObjCInterfaceDecl *ID); |
||
10353 | |||
10354 | Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd, |
||
10355 | ArrayRef<Decl *> allMethods = std::nullopt, |
||
10356 | ArrayRef<DeclGroupPtrTy> allTUVars = std::nullopt); |
||
10357 | |||
10358 | Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, |
||
10359 | SourceLocation LParenLoc, |
||
10360 | FieldDeclarator &FD, ObjCDeclSpec &ODS, |
||
10361 | Selector GetterSel, Selector SetterSel, |
||
10362 | tok::ObjCKeywordKind MethodImplKind, |
||
10363 | DeclContext *lexicalDC = nullptr); |
||
10364 | |||
10365 | Decl *ActOnPropertyImplDecl(Scope *S, |
||
10366 | SourceLocation AtLoc, |
||
10367 | SourceLocation PropertyLoc, |
||
10368 | bool ImplKind, |
||
10369 | IdentifierInfo *PropertyId, |
||
10370 | IdentifierInfo *PropertyIvar, |
||
10371 | SourceLocation PropertyIvarLoc, |
||
10372 | ObjCPropertyQueryKind QueryKind); |
||
10373 | |||
10374 | enum ObjCSpecialMethodKind { |
||
10375 | OSMK_None, |
||
10376 | OSMK_Alloc, |
||
10377 | OSMK_New, |
||
10378 | OSMK_Copy, |
||
10379 | OSMK_RetainingInit, |
||
10380 | OSMK_NonRetainingInit |
||
10381 | }; |
||
10382 | |||
10383 | struct ObjCArgInfo { |
||
10384 | IdentifierInfo *Name; |
||
10385 | SourceLocation NameLoc; |
||
10386 | // The Type is null if no type was specified, and the DeclSpec is invalid |
||
10387 | // in this case. |
||
10388 | ParsedType Type; |
||
10389 | ObjCDeclSpec DeclSpec; |
||
10390 | |||
10391 | /// ArgAttrs - Attribute list for this argument. |
||
10392 | ParsedAttributesView ArgAttrs; |
||
10393 | }; |
||
10394 | |||
10395 | Decl *ActOnMethodDeclaration( |
||
10396 | Scope *S, |
||
10397 | SourceLocation BeginLoc, // location of the + or -. |
||
10398 | SourceLocation EndLoc, // location of the ; or {. |
||
10399 | tok::TokenKind MethodType, ObjCDeclSpec &ReturnQT, ParsedType ReturnType, |
||
10400 | ArrayRef<SourceLocation> SelectorLocs, Selector Sel, |
||
10401 | // optional arguments. The number of types/arguments is obtained |
||
10402 | // from the Sel.getNumArgs(). |
||
10403 | ObjCArgInfo *ArgInfo, DeclaratorChunk::ParamInfo *CParamInfo, |
||
10404 | unsigned CNumArgs, // c-style args |
||
10405 | const ParsedAttributesView &AttrList, tok::ObjCKeywordKind MethodImplKind, |
||
10406 | bool isVariadic, bool MethodDefinition); |
||
10407 | |||
10408 | ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, |
||
10409 | const ObjCObjectPointerType *OPT, |
||
10410 | bool IsInstance); |
||
10411 | ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty, |
||
10412 | bool IsInstance); |
||
10413 | |||
10414 | bool CheckARCMethodDecl(ObjCMethodDecl *method); |
||
10415 | bool inferObjCARCLifetime(ValueDecl *decl); |
||
10416 | |||
10417 | void deduceOpenCLAddressSpace(ValueDecl *decl); |
||
10418 | |||
10419 | ExprResult |
||
10420 | HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, |
||
10421 | Expr *BaseExpr, |
||
10422 | SourceLocation OpLoc, |
||
10423 | DeclarationName MemberName, |
||
10424 | SourceLocation MemberLoc, |
||
10425 | SourceLocation SuperLoc, QualType SuperType, |
||
10426 | bool Super); |
||
10427 | |||
10428 | ExprResult |
||
10429 | ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, |
||
10430 | IdentifierInfo &propertyName, |
||
10431 | SourceLocation receiverNameLoc, |
||
10432 | SourceLocation propertyNameLoc); |
||
10433 | |||
10434 | ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc); |
||
10435 | |||
10436 | /// Describes the kind of message expression indicated by a message |
||
10437 | /// send that starts with an identifier. |
||
10438 | enum ObjCMessageKind { |
||
10439 | /// The message is sent to 'super'. |
||
10440 | ObjCSuperMessage, |
||
10441 | /// The message is an instance message. |
||
10442 | ObjCInstanceMessage, |
||
10443 | /// The message is a class message, and the identifier is a type |
||
10444 | /// name. |
||
10445 | ObjCClassMessage |
||
10446 | }; |
||
10447 | |||
10448 | ObjCMessageKind getObjCMessageKind(Scope *S, |
||
10449 | IdentifierInfo *Name, |
||
10450 | SourceLocation NameLoc, |
||
10451 | bool IsSuper, |
||
10452 | bool HasTrailingDot, |
||
10453 | ParsedType &ReceiverType); |
||
10454 | |||
10455 | ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, |
||
10456 | Selector Sel, |
||
10457 | SourceLocation LBracLoc, |
||
10458 | ArrayRef<SourceLocation> SelectorLocs, |
||
10459 | SourceLocation RBracLoc, |
||
10460 | MultiExprArg Args); |
||
10461 | |||
10462 | ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, |
||
10463 | QualType ReceiverType, |
||
10464 | SourceLocation SuperLoc, |
||
10465 | Selector Sel, |
||
10466 | ObjCMethodDecl *Method, |
||
10467 | SourceLocation LBracLoc, |
||
10468 | ArrayRef<SourceLocation> SelectorLocs, |
||
10469 | SourceLocation RBracLoc, |
||
10470 | MultiExprArg Args, |
||
10471 | bool isImplicit = false); |
||
10472 | |||
10473 | ExprResult BuildClassMessageImplicit(QualType ReceiverType, |
||
10474 | bool isSuperReceiver, |
||
10475 | SourceLocation Loc, |
||
10476 | Selector Sel, |
||
10477 | ObjCMethodDecl *Method, |
||
10478 | MultiExprArg Args); |
||
10479 | |||
10480 | ExprResult ActOnClassMessage(Scope *S, |
||
10481 | ParsedType Receiver, |
||
10482 | Selector Sel, |
||
10483 | SourceLocation LBracLoc, |
||
10484 | ArrayRef<SourceLocation> SelectorLocs, |
||
10485 | SourceLocation RBracLoc, |
||
10486 | MultiExprArg Args); |
||
10487 | |||
10488 | ExprResult BuildInstanceMessage(Expr *Receiver, |
||
10489 | QualType ReceiverType, |
||
10490 | SourceLocation SuperLoc, |
||
10491 | Selector Sel, |
||
10492 | ObjCMethodDecl *Method, |
||
10493 | SourceLocation LBracLoc, |
||
10494 | ArrayRef<SourceLocation> SelectorLocs, |
||
10495 | SourceLocation RBracLoc, |
||
10496 | MultiExprArg Args, |
||
10497 | bool isImplicit = false); |
||
10498 | |||
10499 | ExprResult BuildInstanceMessageImplicit(Expr *Receiver, |
||
10500 | QualType ReceiverType, |
||
10501 | SourceLocation Loc, |
||
10502 | Selector Sel, |
||
10503 | ObjCMethodDecl *Method, |
||
10504 | MultiExprArg Args); |
||
10505 | |||
10506 | ExprResult ActOnInstanceMessage(Scope *S, |
||
10507 | Expr *Receiver, |
||
10508 | Selector Sel, |
||
10509 | SourceLocation LBracLoc, |
||
10510 | ArrayRef<SourceLocation> SelectorLocs, |
||
10511 | SourceLocation RBracLoc, |
||
10512 | MultiExprArg Args); |
||
10513 | |||
10514 | ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, |
||
10515 | ObjCBridgeCastKind Kind, |
||
10516 | SourceLocation BridgeKeywordLoc, |
||
10517 | TypeSourceInfo *TSInfo, |
||
10518 | Expr *SubExpr); |
||
10519 | |||
10520 | ExprResult ActOnObjCBridgedCast(Scope *S, |
||
10521 | SourceLocation LParenLoc, |
||
10522 | ObjCBridgeCastKind Kind, |
||
10523 | SourceLocation BridgeKeywordLoc, |
||
10524 | ParsedType Type, |
||
10525 | SourceLocation RParenLoc, |
||
10526 | Expr *SubExpr); |
||
10527 | |||
10528 | void CheckTollFreeBridgeCast(QualType castType, Expr *castExpr); |
||
10529 | |||
10530 | void CheckObjCBridgeRelatedCast(QualType castType, Expr *castExpr); |
||
10531 | |||
10532 | bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr, |
||
10533 | CastKind &Kind); |
||
10534 | |||
10535 | bool checkObjCBridgeRelatedComponents(SourceLocation Loc, |
||
10536 | QualType DestType, QualType SrcType, |
||
10537 | ObjCInterfaceDecl *&RelatedClass, |
||
10538 | ObjCMethodDecl *&ClassMethod, |
||
10539 | ObjCMethodDecl *&InstanceMethod, |
||
10540 | TypedefNameDecl *&TDNDecl, |
||
10541 | bool CfToNs, bool Diagnose = true); |
||
10542 | |||
10543 | bool CheckObjCBridgeRelatedConversions(SourceLocation Loc, |
||
10544 | QualType DestType, QualType SrcType, |
||
10545 | Expr *&SrcExpr, bool Diagnose = true); |
||
10546 | |||
10547 | bool CheckConversionToObjCLiteral(QualType DstType, Expr *&SrcExpr, |
||
10548 | bool Diagnose = true); |
||
10549 | |||
10550 | bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); |
||
10551 | |||
10552 | /// Check whether the given new method is a valid override of the |
||
10553 | /// given overridden method, and set any properties that should be inherited. |
||
10554 | void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, |
||
10555 | const ObjCMethodDecl *Overridden); |
||
10556 | |||
10557 | /// Describes the compatibility of a result type with its method. |
||
10558 | enum ResultTypeCompatibilityKind { |
||
10559 | RTC_Compatible, |
||
10560 | RTC_Incompatible, |
||
10561 | RTC_Unknown |
||
10562 | }; |
||
10563 | |||
10564 | void CheckObjCMethodDirectOverrides(ObjCMethodDecl *method, |
||
10565 | ObjCMethodDecl *overridden); |
||
10566 | |||
10567 | void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod, |
||
10568 | ObjCInterfaceDecl *CurrentClass, |
||
10569 | ResultTypeCompatibilityKind RTC); |
||
10570 | |||
10571 | enum PragmaOptionsAlignKind { |
||
10572 | POAK_Native, // #pragma options align=native |
||
10573 | POAK_Natural, // #pragma options align=natural |
||
10574 | POAK_Packed, // #pragma options align=packed |
||
10575 | POAK_Power, // #pragma options align=power |
||
10576 | POAK_Mac68k, // #pragma options align=mac68k |
||
10577 | POAK_Reset // #pragma options align=reset |
||
10578 | }; |
||
10579 | |||
10580 | /// ActOnPragmaClangSection - Called on well formed \#pragma clang section |
||
10581 | void ActOnPragmaClangSection(SourceLocation PragmaLoc, |
||
10582 | PragmaClangSectionAction Action, |
||
10583 | PragmaClangSectionKind SecKind, StringRef SecName); |
||
10584 | |||
10585 | /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align. |
||
10586 | void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, |
||
10587 | SourceLocation PragmaLoc); |
||
10588 | |||
10589 | /// ActOnPragmaPack - Called on well formed \#pragma pack(...). |
||
10590 | void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, |
||
10591 | StringRef SlotLabel, Expr *Alignment); |
||
10592 | |||
10593 | enum class PragmaAlignPackDiagnoseKind { |
||
10594 | NonDefaultStateAtInclude, |
||
10595 | ChangedStateAtExit |
||
10596 | }; |
||
10597 | |||
10598 | void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind, |
||
10599 | SourceLocation IncludeLoc); |
||
10600 | void DiagnoseUnterminatedPragmaAlignPack(); |
||
10601 | |||
10602 | /// ActOnPragmaMSStrictGuardStackCheck - Called on well formed \#pragma |
||
10603 | /// strict_gs_check. |
||
10604 | void ActOnPragmaMSStrictGuardStackCheck(SourceLocation PragmaLocation, |
||
10605 | PragmaMsStackAction Action, |
||
10606 | bool Value); |
||
10607 | |||
10608 | /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off]. |
||
10609 | void ActOnPragmaMSStruct(PragmaMSStructKind Kind); |
||
10610 | |||
10611 | /// ActOnPragmaMSComment - Called on well formed |
||
10612 | /// \#pragma comment(kind, "arg"). |
||
10613 | void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind, |
||
10614 | StringRef Arg); |
||
10615 | |||
10616 | /// ActOnPragmaMSPointersToMembers - called on well formed \#pragma |
||
10617 | /// pointers_to_members(representation method[, general purpose |
||
10618 | /// representation]). |
||
10619 | void ActOnPragmaMSPointersToMembers( |
||
10620 | LangOptions::PragmaMSPointersToMembersKind Kind, |
||
10621 | SourceLocation PragmaLoc); |
||
10622 | |||
10623 | /// Called on well formed \#pragma vtordisp(). |
||
10624 | void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, |
||
10625 | SourceLocation PragmaLoc, |
||
10626 | MSVtorDispMode Value); |
||
10627 | |||
10628 | enum PragmaSectionKind { |
||
10629 | PSK_DataSeg, |
||
10630 | PSK_BSSSeg, |
||
10631 | PSK_ConstSeg, |
||
10632 | PSK_CodeSeg, |
||
10633 | }; |
||
10634 | |||
10635 | bool UnifySection(StringRef SectionName, int SectionFlags, |
||
10636 | NamedDecl *TheDecl); |
||
10637 | bool UnifySection(StringRef SectionName, |
||
10638 | int SectionFlags, |
||
10639 | SourceLocation PragmaSectionLocation); |
||
10640 | |||
10641 | /// Called on well formed \#pragma bss_seg/data_seg/const_seg/code_seg. |
||
10642 | void ActOnPragmaMSSeg(SourceLocation PragmaLocation, |
||
10643 | PragmaMsStackAction Action, |
||
10644 | llvm::StringRef StackSlotLabel, |
||
10645 | StringLiteral *SegmentName, |
||
10646 | llvm::StringRef PragmaName); |
||
10647 | |||
10648 | /// Called on well formed \#pragma section(). |
||
10649 | void ActOnPragmaMSSection(SourceLocation PragmaLocation, |
||
10650 | int SectionFlags, StringLiteral *SegmentName); |
||
10651 | |||
10652 | /// Called on well-formed \#pragma init_seg(). |
||
10653 | void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, |
||
10654 | StringLiteral *SegmentName); |
||
10655 | |||
10656 | /// Called on well-formed \#pragma alloc_text(). |
||
10657 | void ActOnPragmaMSAllocText( |
||
10658 | SourceLocation PragmaLocation, StringRef Section, |
||
10659 | const SmallVector<std::tuple<IdentifierInfo *, SourceLocation>> |
||
10660 | &Functions); |
||
10661 | |||
10662 | /// Called on #pragma clang __debug dump II |
||
10663 | void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II); |
||
10664 | |||
10665 | /// ActOnPragmaDetectMismatch - Call on well-formed \#pragma detect_mismatch |
||
10666 | void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, |
||
10667 | StringRef Value); |
||
10668 | |||
10669 | /// Are precise floating point semantics currently enabled? |
||
10670 | bool isPreciseFPEnabled() { |
||
10671 | return !CurFPFeatures.getAllowFPReassociate() && |
||
10672 | !CurFPFeatures.getNoSignedZero() && |
||
10673 | !CurFPFeatures.getAllowReciprocal() && |
||
10674 | !CurFPFeatures.getAllowApproxFunc(); |
||
10675 | } |
||
10676 | |||
10677 | void ActOnPragmaFPEvalMethod(SourceLocation Loc, |
||
10678 | LangOptions::FPEvalMethodKind Value); |
||
10679 | |||
10680 | /// ActOnPragmaFloatControl - Call on well-formed \#pragma float_control |
||
10681 | void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, |
||
10682 | PragmaFloatControlKind Value); |
||
10683 | |||
10684 | /// ActOnPragmaUnused - Called on well-formed '\#pragma unused'. |
||
10685 | void ActOnPragmaUnused(const Token &Identifier, |
||
10686 | Scope *curScope, |
||
10687 | SourceLocation PragmaLoc); |
||
10688 | |||
10689 | /// ActOnPragmaVisibility - Called on well formed \#pragma GCC visibility... . |
||
10690 | void ActOnPragmaVisibility(const IdentifierInfo* VisType, |
||
10691 | SourceLocation PragmaLoc); |
||
10692 | |||
10693 | NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, const IdentifierInfo *II, |
||
10694 | SourceLocation Loc); |
||
10695 | void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, const WeakInfo &W); |
||
10696 | |||
10697 | /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident. |
||
10698 | void ActOnPragmaWeakID(IdentifierInfo* WeakName, |
||
10699 | SourceLocation PragmaLoc, |
||
10700 | SourceLocation WeakNameLoc); |
||
10701 | |||
10702 | /// ActOnPragmaRedefineExtname - Called on well formed |
||
10703 | /// \#pragma redefine_extname oldname newname. |
||
10704 | void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName, |
||
10705 | IdentifierInfo* AliasName, |
||
10706 | SourceLocation PragmaLoc, |
||
10707 | SourceLocation WeakNameLoc, |
||
10708 | SourceLocation AliasNameLoc); |
||
10709 | |||
10710 | /// ActOnPragmaWeakAlias - Called on well formed \#pragma weak ident = ident. |
||
10711 | void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, |
||
10712 | IdentifierInfo* AliasName, |
||
10713 | SourceLocation PragmaLoc, |
||
10714 | SourceLocation WeakNameLoc, |
||
10715 | SourceLocation AliasNameLoc); |
||
10716 | |||
10717 | /// ActOnPragmaFPContract - Called on well formed |
||
10718 | /// \#pragma {STDC,OPENCL} FP_CONTRACT and |
||
10719 | /// \#pragma clang fp contract |
||
10720 | void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC); |
||
10721 | |||
10722 | /// Called on well formed |
||
10723 | /// \#pragma clang fp reassociate |
||
10724 | void ActOnPragmaFPReassociate(SourceLocation Loc, bool IsEnabled); |
||
10725 | |||
10726 | /// ActOnPragmaFenvAccess - Called on well formed |
||
10727 | /// \#pragma STDC FENV_ACCESS |
||
10728 | void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled); |
||
10729 | |||
10730 | /// Called on well formed '\#pragma clang fp' that has option 'exceptions'. |
||
10731 | void ActOnPragmaFPExceptions(SourceLocation Loc, |
||
10732 | LangOptions::FPExceptionModeKind); |
||
10733 | |||
10734 | /// Called to set constant rounding mode for floating point operations. |
||
10735 | void ActOnPragmaFEnvRound(SourceLocation Loc, llvm::RoundingMode); |
||
10736 | |||
10737 | /// Called to set exception behavior for floating point operations. |
||
10738 | void setExceptionMode(SourceLocation Loc, LangOptions::FPExceptionModeKind); |
||
10739 | |||
10740 | /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to |
||
10741 | /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'. |
||
10742 | void AddAlignmentAttributesForRecord(RecordDecl *RD); |
||
10743 | |||
10744 | /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. |
||
10745 | void AddMsStructLayoutForRecord(RecordDecl *RD); |
||
10746 | |||
10747 | /// PushNamespaceVisibilityAttr - Note that we've entered a |
||
10748 | /// namespace with a visibility attribute. |
||
10749 | void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, |
||
10750 | SourceLocation Loc); |
||
10751 | |||
10752 | /// AddPushedVisibilityAttribute - If '\#pragma GCC visibility' was used, |
||
10753 | /// add an appropriate visibility attribute. |
||
10754 | void AddPushedVisibilityAttribute(Decl *RD); |
||
10755 | |||
10756 | /// PopPragmaVisibility - Pop the top element of the visibility stack; used |
||
10757 | /// for '\#pragma GCC visibility' and visibility attributes on namespaces. |
||
10758 | void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc); |
||
10759 | |||
10760 | /// FreeVisContext - Deallocate and null out VisContext. |
||
10761 | void FreeVisContext(); |
||
10762 | |||
10763 | /// AddCFAuditedAttribute - Check whether we're currently within |
||
10764 | /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding |
||
10765 | /// the appropriate attribute. |
||
10766 | void AddCFAuditedAttribute(Decl *D); |
||
10767 | |||
10768 | void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, |
||
10769 | SourceLocation PragmaLoc, |
||
10770 | attr::ParsedSubjectMatchRuleSet Rules); |
||
10771 | void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, |
||
10772 | const IdentifierInfo *Namespace); |
||
10773 | |||
10774 | /// Called on well-formed '\#pragma clang attribute pop'. |
||
10775 | void ActOnPragmaAttributePop(SourceLocation PragmaLoc, |
||
10776 | const IdentifierInfo *Namespace); |
||
10777 | |||
10778 | /// Adds the attributes that have been specified using the |
||
10779 | /// '\#pragma clang attribute push' directives to the given declaration. |
||
10780 | void AddPragmaAttributes(Scope *S, Decl *D); |
||
10781 | |||
10782 | void DiagnoseUnterminatedPragmaAttribute(); |
||
10783 | |||
10784 | /// Called on well formed \#pragma clang optimize. |
||
10785 | void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc); |
||
10786 | |||
10787 | /// #pragma optimize("[optimization-list]", on | off). |
||
10788 | void ActOnPragmaMSOptimize(SourceLocation Loc, bool IsOn); |
||
10789 | |||
10790 | /// Call on well formed \#pragma function. |
||
10791 | void |
||
10792 | ActOnPragmaMSFunction(SourceLocation Loc, |
||
10793 | const llvm::SmallVectorImpl<StringRef> &NoBuiltins); |
||
10794 | |||
10795 | /// Get the location for the currently active "\#pragma clang optimize |
||
10796 | /// off". If this location is invalid, then the state of the pragma is "on". |
||
10797 | SourceLocation getOptimizeOffPragmaLocation() const { |
||
10798 | return OptimizeOffPragmaLocation; |
||
10799 | } |
||
10800 | |||
10801 | /// Only called on function definitions; if there is a pragma in scope |
||
10802 | /// with the effect of a range-based optnone, consider marking the function |
||
10803 | /// with attribute optnone. |
||
10804 | void AddRangeBasedOptnone(FunctionDecl *FD); |
||
10805 | |||
10806 | /// Only called on function definitions; if there is a `#pragma alloc_text` |
||
10807 | /// that decides which code section the function should be in, add |
||
10808 | /// attribute section to the function. |
||
10809 | void AddSectionMSAllocText(FunctionDecl *FD); |
||
10810 | |||
10811 | /// Adds the 'optnone' attribute to the function declaration if there |
||
10812 | /// are no conflicts; Loc represents the location causing the 'optnone' |
||
10813 | /// attribute to be added (usually because of a pragma). |
||
10814 | void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc); |
||
10815 | |||
10816 | /// Only called on function definitions; if there is a MSVC #pragma optimize |
||
10817 | /// in scope, consider changing the function's attributes based on the |
||
10818 | /// optimization list passed to the pragma. |
||
10819 | void ModifyFnAttributesMSPragmaOptimize(FunctionDecl *FD); |
||
10820 | |||
10821 | /// Only called on function definitions; if there is a pragma in scope |
||
10822 | /// with the effect of a range-based no_builtin, consider marking the function |
||
10823 | /// with attribute no_builtin. |
||
10824 | void AddImplicitMSFunctionNoBuiltinAttr(FunctionDecl *FD); |
||
10825 | |||
10826 | /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. |
||
10827 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
||
10828 | bool IsPackExpansion); |
||
10829 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, TypeSourceInfo *T, |
||
10830 | bool IsPackExpansion); |
||
10831 | |||
10832 | /// AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular |
||
10833 | /// declaration. |
||
10834 | void AddAssumeAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
||
10835 | Expr *OE); |
||
10836 | |||
10837 | /// AddAllocAlignAttr - Adds an alloc_align attribute to a particular |
||
10838 | /// declaration. |
||
10839 | void AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI, |
||
10840 | Expr *ParamExpr); |
||
10841 | |||
10842 | /// AddAlignValueAttr - Adds an align_value attribute to a particular |
||
10843 | /// declaration. |
||
10844 | void AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E); |
||
10845 | |||
10846 | /// AddAnnotationAttr - Adds an annotation Annot with Args arguments to D. |
||
10847 | void AddAnnotationAttr(Decl *D, const AttributeCommonInfo &CI, |
||
10848 | StringRef Annot, MutableArrayRef<Expr *> Args); |
||
10849 | |||
10850 | /// ConstantFoldAttrArgs - Folds attribute arguments into ConstantExprs |
||
10851 | /// (unless they are value dependent or type dependent). Returns false |
||
10852 | /// and emits a diagnostic if one or more of the arguments could not be |
||
10853 | /// folded into a constant. |
||
10854 | bool ConstantFoldAttrArgs(const AttributeCommonInfo &CI, |
||
10855 | MutableArrayRef<Expr *> Args); |
||
10856 | |||
10857 | /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular |
||
10858 | /// declaration. |
||
10859 | void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI, |
||
10860 | Expr *MaxThreads, Expr *MinBlocks); |
||
10861 | |||
10862 | /// AddModeAttr - Adds a mode attribute to a particular declaration. |
||
10863 | void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Name, |
||
10864 | bool InInstantiation = false); |
||
10865 | |||
10866 | void AddParameterABIAttr(Decl *D, const AttributeCommonInfo &CI, |
||
10867 | ParameterABI ABI); |
||
10868 | |||
10869 | enum class RetainOwnershipKind {NS, CF, OS}; |
||
10870 | void AddXConsumedAttr(Decl *D, const AttributeCommonInfo &CI, |
||
10871 | RetainOwnershipKind K, bool IsTemplateInstantiation); |
||
10872 | |||
10873 | /// addAMDGPUFlatWorkGroupSizeAttr - Adds an amdgpu_flat_work_group_size |
||
10874 | /// attribute to a particular declaration. |
||
10875 | void addAMDGPUFlatWorkGroupSizeAttr(Decl *D, const AttributeCommonInfo &CI, |
||
10876 | Expr *Min, Expr *Max); |
||
10877 | |||
10878 | /// addAMDGPUWavePersEUAttr - Adds an amdgpu_waves_per_eu attribute to a |
||
10879 | /// particular declaration. |
||
10880 | void addAMDGPUWavesPerEUAttr(Decl *D, const AttributeCommonInfo &CI, |
||
10881 | Expr *Min, Expr *Max); |
||
10882 | |||
10883 | bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type); |
||
10884 | |||
10885 | //===--------------------------------------------------------------------===// |
||
10886 | // C++ Coroutines TS |
||
10887 | // |
||
10888 | bool ActOnCoroutineBodyStart(Scope *S, SourceLocation KwLoc, |
||
10889 | StringRef Keyword); |
||
10890 | ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
||
10891 | ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
||
10892 | StmtResult ActOnCoreturnStmt(Scope *S, SourceLocation KwLoc, Expr *E); |
||
10893 | |||
10894 | ExprResult BuildOperatorCoawaitLookupExpr(Scope *S, SourceLocation Loc); |
||
10895 | ExprResult BuildOperatorCoawaitCall(SourceLocation Loc, Expr *E, |
||
10896 | UnresolvedLookupExpr *Lookup); |
||
10897 | ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, |
||
10898 | Expr *Awaiter, bool IsImplicit = false); |
||
10899 | ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, |
||
10900 | UnresolvedLookupExpr *Lookup); |
||
10901 | ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E); |
||
10902 | StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E, |
||
10903 | bool IsImplicit = false); |
||
10904 | StmtResult BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs); |
||
10905 | bool buildCoroutineParameterMoves(SourceLocation Loc); |
||
10906 | VarDecl *buildCoroutinePromise(SourceLocation Loc); |
||
10907 | void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body); |
||
10908 | /// Lookup 'coroutine_traits' in std namespace and std::experimental |
||
10909 | /// namespace. The namespace found is recorded in Namespace. |
||
10910 | ClassTemplateDecl *lookupCoroutineTraits(SourceLocation KwLoc, |
||
10911 | SourceLocation FuncLoc, |
||
10912 | NamespaceDecl *&Namespace); |
||
10913 | /// Check that the expression co_await promise.final_suspend() shall not be |
||
10914 | /// potentially-throwing. |
||
10915 | bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend); |
||
10916 | |||
10917 | //===--------------------------------------------------------------------===// |
||
10918 | // OpenMP directives and clauses. |
||
10919 | // |
||
10920 | private: |
||
10921 | void *VarDataSharingAttributesStack; |
||
10922 | |||
10923 | struct DeclareTargetContextInfo { |
||
10924 | struct MapInfo { |
||
10925 | OMPDeclareTargetDeclAttr::MapTypeTy MT; |
||
10926 | SourceLocation Loc; |
||
10927 | }; |
||
10928 | /// Explicitly listed variables and functions in a 'to' or 'link' clause. |
||
10929 | llvm::DenseMap<NamedDecl *, MapInfo> ExplicitlyMapped; |
||
10930 | |||
10931 | /// The 'device_type' as parsed from the clause. |
||
10932 | OMPDeclareTargetDeclAttr::DevTypeTy DT = OMPDeclareTargetDeclAttr::DT_Any; |
||
10933 | |||
10934 | /// The directive kind, `begin declare target` or `declare target`. |
||
10935 | OpenMPDirectiveKind Kind; |
||
10936 | |||
10937 | /// The directive with indirect clause. |
||
10938 | std::optional<Expr *> Indirect; |
||
10939 | |||
10940 | /// The directive location. |
||
10941 | SourceLocation Loc; |
||
10942 | |||
10943 | DeclareTargetContextInfo(OpenMPDirectiveKind Kind, SourceLocation Loc) |
||
10944 | : Kind(Kind), Loc(Loc) {} |
||
10945 | }; |
||
10946 | |||
10947 | /// Number of nested '#pragma omp declare target' directives. |
||
10948 | SmallVector<DeclareTargetContextInfo, 4> DeclareTargetNesting; |
||
10949 | |||
10950 | /// Initialization of data-sharing attributes stack. |
||
10951 | void InitDataSharingAttributesStack(); |
||
10952 | void DestroyDataSharingAttributesStack(); |
||
10953 | ExprResult |
||
10954 | VerifyPositiveIntegerConstantInClause(Expr *Op, OpenMPClauseKind CKind, |
||
10955 | bool StrictlyPositive = true, |
||
10956 | bool SuppressExprDiags = false); |
||
10957 | /// Returns OpenMP nesting level for current directive. |
||
10958 | unsigned getOpenMPNestingLevel() const; |
||
10959 | |||
10960 | /// Adjusts the function scopes index for the target-based regions. |
||
10961 | void adjustOpenMPTargetScopeIndex(unsigned &FunctionScopesIndex, |
||
10962 | unsigned Level) const; |
||
10963 | |||
10964 | /// Returns the number of scopes associated with the construct on the given |
||
10965 | /// OpenMP level. |
||
10966 | int getNumberOfConstructScopes(unsigned Level) const; |
||
10967 | |||
10968 | /// Push new OpenMP function region for non-capturing function. |
||
10969 | void pushOpenMPFunctionRegion(); |
||
10970 | |||
10971 | /// Pop OpenMP function region for non-capturing function. |
||
10972 | void popOpenMPFunctionRegion(const sema::FunctionScopeInfo *OldFSI); |
||
10973 | |||
10974 | /// Analyzes and checks a loop nest for use by a loop transformation. |
||
10975 | /// |
||
10976 | /// \param Kind The loop transformation directive kind. |
||
10977 | /// \param NumLoops How many nested loops the directive is expecting. |
||
10978 | /// \param AStmt Associated statement of the transformation directive. |
||
10979 | /// \param LoopHelpers [out] The loop analysis result. |
||
10980 | /// \param Body [out] The body code nested in \p NumLoops loop. |
||
10981 | /// \param OriginalInits [out] Collection of statements and declarations that |
||
10982 | /// must have been executed/declared before entering the |
||
10983 | /// loop. |
||
10984 | /// |
||
10985 | /// \return Whether there was any error. |
||
10986 | bool checkTransformableLoopNest( |
||
10987 | OpenMPDirectiveKind Kind, Stmt *AStmt, int NumLoops, |
||
10988 | SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers, |
||
10989 | Stmt *&Body, |
||
10990 | SmallVectorImpl<SmallVector<llvm::PointerUnion<Stmt *, Decl *>, 0>> |
||
10991 | &OriginalInits); |
||
10992 | |||
10993 | /// Helper to keep information about the current `omp begin/end declare |
||
10994 | /// variant` nesting. |
||
10995 | struct OMPDeclareVariantScope { |
||
10996 | /// The associated OpenMP context selector. |
||
10997 | OMPTraitInfo *TI; |
||
10998 | |||
10999 | /// The associated OpenMP context selector mangling. |
||
11000 | std::string NameSuffix; |
||
11001 | |||
11002 | OMPDeclareVariantScope(OMPTraitInfo &TI); |
||
11003 | }; |
||
11004 | |||
11005 | /// Return the OMPTraitInfo for the surrounding scope, if any. |
||
11006 | OMPTraitInfo *getOMPTraitInfoForSurroundingScope() { |
||
11007 | return OMPDeclareVariantScopes.empty() ? nullptr |
||
11008 | : OMPDeclareVariantScopes.back().TI; |
||
11009 | } |
||
11010 | |||
11011 | /// The current `omp begin/end declare variant` scopes. |
||
11012 | SmallVector<OMPDeclareVariantScope, 4> OMPDeclareVariantScopes; |
||
11013 | |||
11014 | /// The current `omp begin/end assumes` scopes. |
||
11015 | SmallVector<AssumptionAttr *, 4> OMPAssumeScoped; |
||
11016 | |||
11017 | /// All `omp assumes` we encountered so far. |
||
11018 | SmallVector<AssumptionAttr *, 4> OMPAssumeGlobal; |
||
11019 | |||
11020 | public: |
||
11021 | /// The declarator \p D defines a function in the scope \p S which is nested |
||
11022 | /// in an `omp begin/end declare variant` scope. In this method we create a |
||
11023 | /// declaration for \p D and rename \p D according to the OpenMP context |
||
11024 | /// selector of the surrounding scope. Return all base functions in \p Bases. |
||
11025 | void ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope( |
||
11026 | Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists, |
||
11027 | SmallVectorImpl<FunctionDecl *> &Bases); |
||
11028 | |||
11029 | /// Register \p D as specialization of all base functions in \p Bases in the |
||
11030 | /// current `omp begin/end declare variant` scope. |
||
11031 | void ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope( |
||
11032 | Decl *D, SmallVectorImpl<FunctionDecl *> &Bases); |
||
11033 | |||
11034 | /// Act on \p D, a function definition inside of an `omp [begin/end] assumes`. |
||
11035 | void ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Decl *D); |
||
11036 | |||
11037 | /// Can we exit an OpenMP declare variant scope at the moment. |
||
11038 | bool isInOpenMPDeclareVariantScope() const { |
||
11039 | return !OMPDeclareVariantScopes.empty(); |
||
11040 | } |
||
11041 | |||
11042 | /// Given the potential call expression \p Call, determine if there is a |
||
11043 | /// specialization via the OpenMP declare variant mechanism available. If |
||
11044 | /// there is, return the specialized call expression, otherwise return the |
||
11045 | /// original \p Call. |
||
11046 | ExprResult ActOnOpenMPCall(ExprResult Call, Scope *Scope, |
||
11047 | SourceLocation LParenLoc, MultiExprArg ArgExprs, |
||
11048 | SourceLocation RParenLoc, Expr *ExecConfig); |
||
11049 | |||
11050 | /// Handle a `omp begin declare variant`. |
||
11051 | void ActOnOpenMPBeginDeclareVariant(SourceLocation Loc, OMPTraitInfo &TI); |
||
11052 | |||
11053 | /// Handle a `omp end declare variant`. |
||
11054 | void ActOnOpenMPEndDeclareVariant(); |
||
11055 | |||
11056 | /// Checks if the variant/multiversion functions are compatible. |
||
11057 | bool areMultiversionVariantFunctionsCompatible( |
||
11058 | const FunctionDecl *OldFD, const FunctionDecl *NewFD, |
||
11059 | const PartialDiagnostic &NoProtoDiagID, |
||
11060 | const PartialDiagnosticAt &NoteCausedDiagIDAt, |
||
11061 | const PartialDiagnosticAt &NoSupportDiagIDAt, |
||
11062 | const PartialDiagnosticAt &DiffDiagIDAt, bool TemplatesSupported, |
||
11063 | bool ConstexprSupported, bool CLinkageMayDiffer); |
||
11064 | |||
11065 | /// Function tries to capture lambda's captured variables in the OpenMP region |
||
11066 | /// before the original lambda is captured. |
||
11067 | void tryCaptureOpenMPLambdas(ValueDecl *V); |
||
11068 | |||
11069 | /// Return true if the provided declaration \a VD should be captured by |
||
11070 | /// reference. |
||
11071 | /// \param Level Relative level of nested OpenMP construct for that the check |
||
11072 | /// is performed. |
||
11073 | /// \param OpenMPCaptureLevel Capture level within an OpenMP construct. |
||
11074 | bool isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level, |
||
11075 | unsigned OpenMPCaptureLevel) const; |
||
11076 | |||
11077 | /// Check if the specified variable is used in one of the private |
||
11078 | /// clauses (private, firstprivate, lastprivate, reduction etc.) in OpenMP |
||
11079 | /// constructs. |
||
11080 | VarDecl *isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo = false, |
||
11081 | unsigned StopAt = 0); |
||
11082 | |||
11083 | /// The member expression(this->fd) needs to be rebuilt in the template |
||
11084 | /// instantiation to generate private copy for OpenMP when default |
||
11085 | /// clause is used. The function will return true if default |
||
11086 | /// cluse is used. |
||
11087 | bool isOpenMPRebuildMemberExpr(ValueDecl *D); |
||
11088 | |||
11089 | ExprResult getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
||
11090 | ExprObjectKind OK, SourceLocation Loc); |
||
11091 | |||
11092 | /// If the current region is a loop-based region, mark the start of the loop |
||
11093 | /// construct. |
||
11094 | void startOpenMPLoop(); |
||
11095 | |||
11096 | /// If the current region is a range loop-based region, mark the start of the |
||
11097 | /// loop construct. |
||
11098 | void startOpenMPCXXRangeFor(); |
||
11099 | |||
11100 | /// Check if the specified variable is used in 'private' clause. |
||
11101 | /// \param Level Relative level of nested OpenMP construct for that the check |
||
11102 | /// is performed. |
||
11103 | OpenMPClauseKind isOpenMPPrivateDecl(ValueDecl *D, unsigned Level, |
||
11104 | unsigned CapLevel) const; |
||
11105 | |||
11106 | /// Sets OpenMP capture kind (OMPC_private, OMPC_firstprivate, OMPC_map etc.) |
||
11107 | /// for \p FD based on DSA for the provided corresponding captured declaration |
||
11108 | /// \p D. |
||
11109 | void setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, unsigned Level); |
||
11110 | |||
11111 | /// Check if the specified variable is captured by 'target' directive. |
||
11112 | /// \param Level Relative level of nested OpenMP construct for that the check |
||
11113 | /// is performed. |
||
11114 | bool isOpenMPTargetCapturedDecl(const ValueDecl *D, unsigned Level, |
||
11115 | unsigned CaptureLevel) const; |
||
11116 | |||
11117 | /// Check if the specified global variable must be captured by outer capture |
||
11118 | /// regions. |
||
11119 | /// \param Level Relative level of nested OpenMP construct for that |
||
11120 | /// the check is performed. |
||
11121 | bool isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level, |
||
11122 | unsigned CaptureLevel) const; |
||
11123 | |||
11124 | ExprResult PerformOpenMPImplicitIntegerConversion(SourceLocation OpLoc, |
||
11125 | Expr *Op); |
||
11126 | /// Called on start of new data sharing attribute block. |
||
11127 | void StartOpenMPDSABlock(OpenMPDirectiveKind K, |
||
11128 | const DeclarationNameInfo &DirName, Scope *CurScope, |
||
11129 | SourceLocation Loc); |
||
11130 | /// Start analysis of clauses. |
||
11131 | void StartOpenMPClause(OpenMPClauseKind K); |
||
11132 | /// End analysis of clauses. |
||
11133 | void EndOpenMPClause(); |
||
11134 | /// Called on end of data sharing attribute block. |
||
11135 | void EndOpenMPDSABlock(Stmt *CurDirective); |
||
11136 | |||
11137 | /// Check if the current region is an OpenMP loop region and if it is, |
||
11138 | /// mark loop control variable, used in \p Init for loop initialization, as |
||
11139 | /// private by default. |
||
11140 | /// \param Init First part of the for loop. |
||
11141 | void ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init); |
||
11142 | |||
11143 | /// Called on well-formed '\#pragma omp metadirective' after parsing |
||
11144 | /// of the associated statement. |
||
11145 | StmtResult ActOnOpenMPMetaDirective(ArrayRef<OMPClause *> Clauses, |
||
11146 | Stmt *AStmt, SourceLocation StartLoc, |
||
11147 | SourceLocation EndLoc); |
||
11148 | |||
11149 | // OpenMP directives and clauses. |
||
11150 | /// Called on correct id-expression from the '#pragma omp |
||
11151 | /// threadprivate'. |
||
11152 | ExprResult ActOnOpenMPIdExpression(Scope *CurScope, CXXScopeSpec &ScopeSpec, |
||
11153 | const DeclarationNameInfo &Id, |
||
11154 | OpenMPDirectiveKind Kind); |
||
11155 | /// Called on well-formed '#pragma omp threadprivate'. |
||
11156 | DeclGroupPtrTy ActOnOpenMPThreadprivateDirective( |
||
11157 | SourceLocation Loc, |
||
11158 | ArrayRef<Expr *> VarList); |
||
11159 | /// Builds a new OpenMPThreadPrivateDecl and checks its correctness. |
||
11160 | OMPThreadPrivateDecl *CheckOMPThreadPrivateDecl(SourceLocation Loc, |
||
11161 | ArrayRef<Expr *> VarList); |
||
11162 | /// Called on well-formed '#pragma omp allocate'. |
||
11163 | DeclGroupPtrTy ActOnOpenMPAllocateDirective(SourceLocation Loc, |
||
11164 | ArrayRef<Expr *> VarList, |
||
11165 | ArrayRef<OMPClause *> Clauses, |
||
11166 | DeclContext *Owner = nullptr); |
||
11167 | |||
11168 | /// Called on well-formed '#pragma omp [begin] assume[s]'. |
||
11169 | void ActOnOpenMPAssumesDirective(SourceLocation Loc, |
||
11170 | OpenMPDirectiveKind DKind, |
||
11171 | ArrayRef<std::string> Assumptions, |
||
11172 | bool SkippedClauses); |
||
11173 | |||
11174 | /// Check if there is an active global `omp begin assumes` directive. |
||
11175 | bool isInOpenMPAssumeScope() const { return !OMPAssumeScoped.empty(); } |
||
11176 | |||
11177 | /// Check if there is an active global `omp assumes` directive. |
||
11178 | bool hasGlobalOpenMPAssumes() const { return !OMPAssumeGlobal.empty(); } |
||
11179 | |||
11180 | /// Called on well-formed '#pragma omp end assumes'. |
||
11181 | void ActOnOpenMPEndAssumesDirective(); |
||
11182 | |||
11183 | /// Called on well-formed '#pragma omp requires'. |
||
11184 | DeclGroupPtrTy ActOnOpenMPRequiresDirective(SourceLocation Loc, |
||
11185 | ArrayRef<OMPClause *> ClauseList); |
||
11186 | /// Check restrictions on Requires directive |
||
11187 | OMPRequiresDecl *CheckOMPRequiresDecl(SourceLocation Loc, |
||
11188 | ArrayRef<OMPClause *> Clauses); |
||
11189 | /// Check if the specified type is allowed to be used in 'omp declare |
||
11190 | /// reduction' construct. |
||
11191 | QualType ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
||
11192 | TypeResult ParsedType); |
||
11193 | /// Called on start of '#pragma omp declare reduction'. |
||
11194 | DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveStart( |
||
11195 | Scope *S, DeclContext *DC, DeclarationName Name, |
||
11196 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
||
11197 | AccessSpecifier AS, Decl *PrevDeclInScope = nullptr); |
||
11198 | /// Initialize declare reduction construct initializer. |
||
11199 | void ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D); |
||
11200 | /// Finish current declare reduction construct initializer. |
||
11201 | void ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner); |
||
11202 | /// Initialize declare reduction construct initializer. |
||
11203 | /// \return omp_priv variable. |
||
11204 | VarDecl *ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D); |
||
11205 | /// Finish current declare reduction construct initializer. |
||
11206 | void ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, Expr *Initializer, |
||
11207 | VarDecl *OmpPrivParm); |
||
11208 | /// Called at the end of '#pragma omp declare reduction'. |
||
11209 | DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveEnd( |
||
11210 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid); |
||
11211 | |||
11212 | /// Check variable declaration in 'omp declare mapper' construct. |
||
11213 | TypeResult ActOnOpenMPDeclareMapperVarDecl(Scope *S, Declarator &D); |
||
11214 | /// Check if the specified type is allowed to be used in 'omp declare |
||
11215 | /// mapper' construct. |
||
11216 | QualType ActOnOpenMPDeclareMapperType(SourceLocation TyLoc, |
||
11217 | TypeResult ParsedType); |
||
11218 | /// Called on start of '#pragma omp declare mapper'. |
||
11219 | DeclGroupPtrTy ActOnOpenMPDeclareMapperDirective( |
||
11220 | Scope *S, DeclContext *DC, DeclarationName Name, QualType MapperType, |
||
11221 | SourceLocation StartLoc, DeclarationName VN, AccessSpecifier AS, |
||
11222 | Expr *MapperVarRef, ArrayRef<OMPClause *> Clauses, |
||
11223 | Decl *PrevDeclInScope = nullptr); |
||
11224 | /// Build the mapper variable of '#pragma omp declare mapper'. |
||
11225 | ExprResult ActOnOpenMPDeclareMapperDirectiveVarDecl(Scope *S, |
||
11226 | QualType MapperType, |
||
11227 | SourceLocation StartLoc, |
||
11228 | DeclarationName VN); |
||
11229 | void ActOnOpenMPIteratorVarDecl(VarDecl *VD); |
||
11230 | bool isOpenMPDeclareMapperVarDeclAllowed(const VarDecl *VD) const; |
||
11231 | const ValueDecl *getOpenMPDeclareMapperVarName() const; |
||
11232 | |||
11233 | /// Called on the start of target region i.e. '#pragma omp declare target'. |
||
11234 | bool ActOnStartOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI); |
||
11235 | |||
11236 | /// Called at the end of target region i.e. '#pragma omp end declare target'. |
||
11237 | const DeclareTargetContextInfo ActOnOpenMPEndDeclareTargetDirective(); |
||
11238 | |||
11239 | /// Called once a target context is completed, that can be when a |
||
11240 | /// '#pragma omp end declare target' was encountered or when a |
||
11241 | /// '#pragma omp declare target' without declaration-definition-seq was |
||
11242 | /// encountered. |
||
11243 | void ActOnFinishedOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI); |
||
11244 | |||
11245 | /// Report unterminated 'omp declare target' or 'omp begin declare target' at |
||
11246 | /// the end of a compilation unit. |
||
11247 | void DiagnoseUnterminatedOpenMPDeclareTarget(); |
||
11248 | |||
11249 | /// Searches for the provided declaration name for OpenMP declare target |
||
11250 | /// directive. |
||
11251 | NamedDecl *lookupOpenMPDeclareTargetName(Scope *CurScope, |
||
11252 | CXXScopeSpec &ScopeSpec, |
||
11253 | const DeclarationNameInfo &Id); |
||
11254 | |||
11255 | /// Called on correct id-expression from the '#pragma omp declare target'. |
||
11256 | void ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc, |
||
11257 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
||
11258 | DeclareTargetContextInfo &DTCI); |
||
11259 | |||
11260 | /// Check declaration inside target region. |
||
11261 | void |
||
11262 | checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, |
||
11263 | SourceLocation IdLoc = SourceLocation()); |
||
11264 | /// Finishes analysis of the deferred functions calls that may be declared as |
||
11265 | /// host/nohost during device/host compilation. |
||
11266 | void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller, |
||
11267 | const FunctionDecl *Callee, |
||
11268 | SourceLocation Loc); |
||
11269 | |||
11270 | /// Return true if currently in OpenMP task with untied clause context. |
||
11271 | bool isInOpenMPTaskUntiedContext() const; |
||
11272 | |||
11273 | /// Return true inside OpenMP declare target region. |
||
11274 | bool isInOpenMPDeclareTargetContext() const { |
||
11275 | return !DeclareTargetNesting.empty(); |
||
11276 | } |
||
11277 | /// Return true inside OpenMP target region. |
||
11278 | bool isInOpenMPTargetExecutionDirective() const; |
||
11279 | |||
11280 | /// Return the number of captured regions created for an OpenMP directive. |
||
11281 | static int getOpenMPCaptureLevels(OpenMPDirectiveKind Kind); |
||
11282 | |||
11283 | /// Initialization of captured region for OpenMP region. |
||
11284 | void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope); |
||
11285 | |||
11286 | /// Called for syntactical loops (ForStmt or CXXForRangeStmt) associated to |
||
11287 | /// an OpenMP loop directive. |
||
11288 | StmtResult ActOnOpenMPCanonicalLoop(Stmt *AStmt); |
||
11289 | |||
11290 | /// Process a canonical OpenMP loop nest that can either be a canonical |
||
11291 | /// literal loop (ForStmt or CXXForRangeStmt), or the generated loop of an |
||
11292 | /// OpenMP loop transformation construct. |
||
11293 | StmtResult ActOnOpenMPLoopnest(Stmt *AStmt); |
||
11294 | |||
11295 | /// End of OpenMP region. |
||
11296 | /// |
||
11297 | /// \param S Statement associated with the current OpenMP region. |
||
11298 | /// \param Clauses List of clauses for the current OpenMP region. |
||
11299 | /// |
||
11300 | /// \returns Statement for finished OpenMP region. |
||
11301 | StmtResult ActOnOpenMPRegionEnd(StmtResult S, ArrayRef<OMPClause *> Clauses); |
||
11302 | StmtResult ActOnOpenMPExecutableDirective( |
||
11303 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
||
11304 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
||
11305 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc); |
||
11306 | /// Called on well-formed '\#pragma omp parallel' after parsing |
||
11307 | /// of the associated statement. |
||
11308 | StmtResult ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
||
11309 | Stmt *AStmt, |
||
11310 | SourceLocation StartLoc, |
||
11311 | SourceLocation EndLoc); |
||
11312 | using VarsWithInheritedDSAType = |
||
11313 | llvm::SmallDenseMap<const ValueDecl *, const Expr *, 4>; |
||
11314 | /// Called on well-formed '\#pragma omp simd' after parsing |
||
11315 | /// of the associated statement. |
||
11316 | StmtResult |
||
11317 | ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
||
11318 | SourceLocation StartLoc, SourceLocation EndLoc, |
||
11319 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11320 | /// Called on well-formed '#pragma omp tile' after parsing of its clauses and |
||
11321 | /// the associated statement. |
||
11322 | StmtResult ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses, |
||
11323 | Stmt *AStmt, SourceLocation StartLoc, |
||
11324 | SourceLocation EndLoc); |
||
11325 | /// Called on well-formed '#pragma omp unroll' after parsing of its clauses |
||
11326 | /// and the associated statement. |
||
11327 | StmtResult ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses, |
||
11328 | Stmt *AStmt, SourceLocation StartLoc, |
||
11329 | SourceLocation EndLoc); |
||
11330 | /// Called on well-formed '\#pragma omp for' after parsing |
||
11331 | /// of the associated statement. |
||
11332 | StmtResult |
||
11333 | ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
||
11334 | SourceLocation StartLoc, SourceLocation EndLoc, |
||
11335 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11336 | /// Called on well-formed '\#pragma omp for simd' after parsing |
||
11337 | /// of the associated statement. |
||
11338 | StmtResult |
||
11339 | ActOnOpenMPForSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
||
11340 | SourceLocation StartLoc, SourceLocation EndLoc, |
||
11341 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11342 | /// Called on well-formed '\#pragma omp sections' after parsing |
||
11343 | /// of the associated statement. |
||
11344 | StmtResult ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
||
11345 | Stmt *AStmt, SourceLocation StartLoc, |
||
11346 | SourceLocation EndLoc); |
||
11347 | /// Called on well-formed '\#pragma omp section' after parsing of the |
||
11348 | /// associated statement. |
||
11349 | StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc, |
||
11350 | SourceLocation EndLoc); |
||
11351 | /// Called on well-formed '\#pragma omp single' after parsing of the |
||
11352 | /// associated statement. |
||
11353 | StmtResult ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
||
11354 | Stmt *AStmt, SourceLocation StartLoc, |
||
11355 | SourceLocation EndLoc); |
||
11356 | /// Called on well-formed '\#pragma omp master' after parsing of the |
||
11357 | /// associated statement. |
||
11358 | StmtResult ActOnOpenMPMasterDirective(Stmt *AStmt, SourceLocation StartLoc, |
||
11359 | SourceLocation EndLoc); |
||
11360 | /// Called on well-formed '\#pragma omp critical' after parsing of the |
||
11361 | /// associated statement. |
||
11362 | StmtResult ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
||
11363 | ArrayRef<OMPClause *> Clauses, |
||
11364 | Stmt *AStmt, SourceLocation StartLoc, |
||
11365 | SourceLocation EndLoc); |
||
11366 | /// Called on well-formed '\#pragma omp parallel for' after parsing |
||
11367 | /// of the associated statement. |
||
11368 | StmtResult ActOnOpenMPParallelForDirective( |
||
11369 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11370 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11371 | /// Called on well-formed '\#pragma omp parallel for simd' after |
||
11372 | /// parsing of the associated statement. |
||
11373 | StmtResult ActOnOpenMPParallelForSimdDirective( |
||
11374 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11375 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11376 | /// Called on well-formed '\#pragma omp parallel master' after |
||
11377 | /// parsing of the associated statement. |
||
11378 | StmtResult ActOnOpenMPParallelMasterDirective(ArrayRef<OMPClause *> Clauses, |
||
11379 | Stmt *AStmt, |
||
11380 | SourceLocation StartLoc, |
||
11381 | SourceLocation EndLoc); |
||
11382 | /// Called on well-formed '\#pragma omp parallel masked' after |
||
11383 | /// parsing of the associated statement. |
||
11384 | StmtResult ActOnOpenMPParallelMaskedDirective(ArrayRef<OMPClause *> Clauses, |
||
11385 | Stmt *AStmt, |
||
11386 | SourceLocation StartLoc, |
||
11387 | SourceLocation EndLoc); |
||
11388 | /// Called on well-formed '\#pragma omp parallel sections' after |
||
11389 | /// parsing of the associated statement. |
||
11390 | StmtResult ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
||
11391 | Stmt *AStmt, |
||
11392 | SourceLocation StartLoc, |
||
11393 | SourceLocation EndLoc); |
||
11394 | /// Called on well-formed '\#pragma omp task' after parsing of the |
||
11395 | /// associated statement. |
||
11396 | StmtResult ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
||
11397 | Stmt *AStmt, SourceLocation StartLoc, |
||
11398 | SourceLocation EndLoc); |
||
11399 | /// Called on well-formed '\#pragma omp taskyield'. |
||
11400 | StmtResult ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
||
11401 | SourceLocation EndLoc); |
||
11402 | /// Called on well-formed '\#pragma omp error'. |
||
11403 | /// Error direcitive is allowed in both declared and excutable contexts. |
||
11404 | /// Adding InExContext to identify which context is called from. |
||
11405 | StmtResult ActOnOpenMPErrorDirective(ArrayRef<OMPClause *> Clauses, |
||
11406 | SourceLocation StartLoc, |
||
11407 | SourceLocation EndLoc, |
||
11408 | bool InExContext = true); |
||
11409 | /// Called on well-formed '\#pragma omp barrier'. |
||
11410 | StmtResult ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
||
11411 | SourceLocation EndLoc); |
||
11412 | /// Called on well-formed '\#pragma omp taskwait'. |
||
11413 | StmtResult ActOnOpenMPTaskwaitDirective(ArrayRef<OMPClause *> Clauses, |
||
11414 | SourceLocation StartLoc, |
||
11415 | SourceLocation EndLoc); |
||
11416 | /// Called on well-formed '\#pragma omp taskgroup'. |
||
11417 | StmtResult ActOnOpenMPTaskgroupDirective(ArrayRef<OMPClause *> Clauses, |
||
11418 | Stmt *AStmt, SourceLocation StartLoc, |
||
11419 | SourceLocation EndLoc); |
||
11420 | /// Called on well-formed '\#pragma omp flush'. |
||
11421 | StmtResult ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
||
11422 | SourceLocation StartLoc, |
||
11423 | SourceLocation EndLoc); |
||
11424 | /// Called on well-formed '\#pragma omp depobj'. |
||
11425 | StmtResult ActOnOpenMPDepobjDirective(ArrayRef<OMPClause *> Clauses, |
||
11426 | SourceLocation StartLoc, |
||
11427 | SourceLocation EndLoc); |
||
11428 | /// Called on well-formed '\#pragma omp scan'. |
||
11429 | StmtResult ActOnOpenMPScanDirective(ArrayRef<OMPClause *> Clauses, |
||
11430 | SourceLocation StartLoc, |
||
11431 | SourceLocation EndLoc); |
||
11432 | /// Called on well-formed '\#pragma omp ordered' after parsing of the |
||
11433 | /// associated statement. |
||
11434 | StmtResult ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
||
11435 | Stmt *AStmt, SourceLocation StartLoc, |
||
11436 | SourceLocation EndLoc); |
||
11437 | /// Called on well-formed '\#pragma omp atomic' after parsing of the |
||
11438 | /// associated statement. |
||
11439 | StmtResult ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
||
11440 | Stmt *AStmt, SourceLocation StartLoc, |
||
11441 | SourceLocation EndLoc); |
||
11442 | /// Called on well-formed '\#pragma omp target' after parsing of the |
||
11443 | /// associated statement. |
||
11444 | StmtResult ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
||
11445 | Stmt *AStmt, SourceLocation StartLoc, |
||
11446 | SourceLocation EndLoc); |
||
11447 | /// Called on well-formed '\#pragma omp target data' after parsing of |
||
11448 | /// the associated statement. |
||
11449 | StmtResult ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
||
11450 | Stmt *AStmt, SourceLocation StartLoc, |
||
11451 | SourceLocation EndLoc); |
||
11452 | /// Called on well-formed '\#pragma omp target enter data' after |
||
11453 | /// parsing of the associated statement. |
||
11454 | StmtResult ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
||
11455 | SourceLocation StartLoc, |
||
11456 | SourceLocation EndLoc, |
||
11457 | Stmt *AStmt); |
||
11458 | /// Called on well-formed '\#pragma omp target exit data' after |
||
11459 | /// parsing of the associated statement. |
||
11460 | StmtResult ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
||
11461 | SourceLocation StartLoc, |
||
11462 | SourceLocation EndLoc, |
||
11463 | Stmt *AStmt); |
||
11464 | /// Called on well-formed '\#pragma omp target parallel' after |
||
11465 | /// parsing of the associated statement. |
||
11466 | StmtResult ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
||
11467 | Stmt *AStmt, |
||
11468 | SourceLocation StartLoc, |
||
11469 | SourceLocation EndLoc); |
||
11470 | /// Called on well-formed '\#pragma omp target parallel for' after |
||
11471 | /// parsing of the associated statement. |
||
11472 | StmtResult ActOnOpenMPTargetParallelForDirective( |
||
11473 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11474 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11475 | /// Called on well-formed '\#pragma omp teams' after parsing of the |
||
11476 | /// associated statement. |
||
11477 | StmtResult ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
||
11478 | Stmt *AStmt, SourceLocation StartLoc, |
||
11479 | SourceLocation EndLoc); |
||
11480 | /// Called on well-formed '\#pragma omp teams loop' after parsing of the |
||
11481 | /// associated statement. |
||
11482 | StmtResult ActOnOpenMPTeamsGenericLoopDirective( |
||
11483 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11484 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11485 | /// Called on well-formed '\#pragma omp target teams loop' after parsing of |
||
11486 | /// the associated statement. |
||
11487 | StmtResult ActOnOpenMPTargetTeamsGenericLoopDirective( |
||
11488 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11489 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11490 | /// Called on well-formed '\#pragma omp parallel loop' after parsing of the |
||
11491 | /// associated statement. |
||
11492 | StmtResult ActOnOpenMPParallelGenericLoopDirective( |
||
11493 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11494 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11495 | /// Called on well-formed '\#pragma omp target parallel loop' after parsing |
||
11496 | /// of the associated statement. |
||
11497 | StmtResult ActOnOpenMPTargetParallelGenericLoopDirective( |
||
11498 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11499 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11500 | /// Called on well-formed '\#pragma omp cancellation point'. |
||
11501 | StmtResult |
||
11502 | ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
||
11503 | SourceLocation EndLoc, |
||
11504 | OpenMPDirectiveKind CancelRegion); |
||
11505 | /// Called on well-formed '\#pragma omp cancel'. |
||
11506 | StmtResult ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
||
11507 | SourceLocation StartLoc, |
||
11508 | SourceLocation EndLoc, |
||
11509 | OpenMPDirectiveKind CancelRegion); |
||
11510 | /// Called on well-formed '\#pragma omp taskloop' after parsing of the |
||
11511 | /// associated statement. |
||
11512 | StmtResult |
||
11513 | ActOnOpenMPTaskLoopDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
||
11514 | SourceLocation StartLoc, SourceLocation EndLoc, |
||
11515 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11516 | /// Called on well-formed '\#pragma omp taskloop simd' after parsing of |
||
11517 | /// the associated statement. |
||
11518 | StmtResult ActOnOpenMPTaskLoopSimdDirective( |
||
11519 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11520 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11521 | /// Called on well-formed '\#pragma omp master taskloop' after parsing of the |
||
11522 | /// associated statement. |
||
11523 | StmtResult ActOnOpenMPMasterTaskLoopDirective( |
||
11524 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11525 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11526 | /// Called on well-formed '\#pragma omp master taskloop simd' after parsing of |
||
11527 | /// the associated statement. |
||
11528 | StmtResult ActOnOpenMPMasterTaskLoopSimdDirective( |
||
11529 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11530 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11531 | /// Called on well-formed '\#pragma omp parallel master taskloop' after |
||
11532 | /// parsing of the associated statement. |
||
11533 | StmtResult ActOnOpenMPParallelMasterTaskLoopDirective( |
||
11534 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11535 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11536 | /// Called on well-formed '\#pragma omp parallel master taskloop simd' after |
||
11537 | /// parsing of the associated statement. |
||
11538 | StmtResult ActOnOpenMPParallelMasterTaskLoopSimdDirective( |
||
11539 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11540 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11541 | /// Called on well-formed '\#pragma omp masked taskloop' after parsing of the |
||
11542 | /// associated statement. |
||
11543 | StmtResult ActOnOpenMPMaskedTaskLoopDirective( |
||
11544 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11545 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11546 | /// Called on well-formed '\#pragma omp masked taskloop simd' after parsing of |
||
11547 | /// the associated statement. |
||
11548 | StmtResult ActOnOpenMPMaskedTaskLoopSimdDirective( |
||
11549 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11550 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11551 | /// Called on well-formed '\#pragma omp parallel masked taskloop' after |
||
11552 | /// parsing of the associated statement. |
||
11553 | StmtResult ActOnOpenMPParallelMaskedTaskLoopDirective( |
||
11554 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11555 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11556 | /// Called on well-formed '\#pragma omp parallel masked taskloop simd' after |
||
11557 | /// parsing of the associated statement. |
||
11558 | StmtResult ActOnOpenMPParallelMaskedTaskLoopSimdDirective( |
||
11559 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11560 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11561 | /// Called on well-formed '\#pragma omp distribute' after parsing |
||
11562 | /// of the associated statement. |
||
11563 | StmtResult |
||
11564 | ActOnOpenMPDistributeDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
||
11565 | SourceLocation StartLoc, SourceLocation EndLoc, |
||
11566 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11567 | /// Called on well-formed '\#pragma omp target update'. |
||
11568 | StmtResult ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
||
11569 | SourceLocation StartLoc, |
||
11570 | SourceLocation EndLoc, |
||
11571 | Stmt *AStmt); |
||
11572 | /// Called on well-formed '\#pragma omp distribute parallel for' after |
||
11573 | /// parsing of the associated statement. |
||
11574 | StmtResult ActOnOpenMPDistributeParallelForDirective( |
||
11575 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11576 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11577 | /// Called on well-formed '\#pragma omp distribute parallel for simd' |
||
11578 | /// after parsing of the associated statement. |
||
11579 | StmtResult ActOnOpenMPDistributeParallelForSimdDirective( |
||
11580 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11581 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11582 | /// Called on well-formed '\#pragma omp distribute simd' after |
||
11583 | /// parsing of the associated statement. |
||
11584 | StmtResult ActOnOpenMPDistributeSimdDirective( |
||
11585 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11586 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11587 | /// Called on well-formed '\#pragma omp target parallel for simd' after |
||
11588 | /// parsing of the associated statement. |
||
11589 | StmtResult ActOnOpenMPTargetParallelForSimdDirective( |
||
11590 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11591 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11592 | /// Called on well-formed '\#pragma omp target simd' after parsing of |
||
11593 | /// the associated statement. |
||
11594 | StmtResult |
||
11595 | ActOnOpenMPTargetSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
||
11596 | SourceLocation StartLoc, SourceLocation EndLoc, |
||
11597 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11598 | /// Called on well-formed '\#pragma omp teams distribute' after parsing of |
||
11599 | /// the associated statement. |
||
11600 | StmtResult ActOnOpenMPTeamsDistributeDirective( |
||
11601 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11602 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11603 | /// Called on well-formed '\#pragma omp teams distribute simd' after parsing |
||
11604 | /// of the associated statement. |
||
11605 | StmtResult ActOnOpenMPTeamsDistributeSimdDirective( |
||
11606 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11607 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11608 | /// Called on well-formed '\#pragma omp teams distribute parallel for simd' |
||
11609 | /// after parsing of the associated statement. |
||
11610 | StmtResult ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
||
11611 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11612 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11613 | /// Called on well-formed '\#pragma omp teams distribute parallel for' |
||
11614 | /// after parsing of the associated statement. |
||
11615 | StmtResult ActOnOpenMPTeamsDistributeParallelForDirective( |
||
11616 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11617 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11618 | /// Called on well-formed '\#pragma omp target teams' after parsing of the |
||
11619 | /// associated statement. |
||
11620 | StmtResult ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses, |
||
11621 | Stmt *AStmt, |
||
11622 | SourceLocation StartLoc, |
||
11623 | SourceLocation EndLoc); |
||
11624 | /// Called on well-formed '\#pragma omp target teams distribute' after parsing |
||
11625 | /// of the associated statement. |
||
11626 | StmtResult ActOnOpenMPTargetTeamsDistributeDirective( |
||
11627 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11628 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11629 | /// Called on well-formed '\#pragma omp target teams distribute parallel for' |
||
11630 | /// after parsing of the associated statement. |
||
11631 | StmtResult ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
||
11632 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11633 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11634 | /// Called on well-formed '\#pragma omp target teams distribute parallel for |
||
11635 | /// simd' after parsing of the associated statement. |
||
11636 | StmtResult ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
||
11637 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11638 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11639 | /// Called on well-formed '\#pragma omp target teams distribute simd' after |
||
11640 | /// parsing of the associated statement. |
||
11641 | StmtResult ActOnOpenMPTargetTeamsDistributeSimdDirective( |
||
11642 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11643 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11644 | /// Called on well-formed '\#pragma omp interop'. |
||
11645 | StmtResult ActOnOpenMPInteropDirective(ArrayRef<OMPClause *> Clauses, |
||
11646 | SourceLocation StartLoc, |
||
11647 | SourceLocation EndLoc); |
||
11648 | /// Called on well-formed '\#pragma omp dispatch' after parsing of the |
||
11649 | // /associated statement. |
||
11650 | StmtResult ActOnOpenMPDispatchDirective(ArrayRef<OMPClause *> Clauses, |
||
11651 | Stmt *AStmt, SourceLocation StartLoc, |
||
11652 | SourceLocation EndLoc); |
||
11653 | /// Called on well-formed '\#pragma omp masked' after parsing of the |
||
11654 | // /associated statement. |
||
11655 | StmtResult ActOnOpenMPMaskedDirective(ArrayRef<OMPClause *> Clauses, |
||
11656 | Stmt *AStmt, SourceLocation StartLoc, |
||
11657 | SourceLocation EndLoc); |
||
11658 | |||
11659 | /// Called on well-formed '\#pragma omp loop' after parsing of the |
||
11660 | /// associated statement. |
||
11661 | StmtResult ActOnOpenMPGenericLoopDirective( |
||
11662 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
||
11663 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
||
11664 | |||
11665 | /// Checks correctness of linear modifiers. |
||
11666 | bool CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
||
11667 | SourceLocation LinLoc); |
||
11668 | /// Checks that the specified declaration matches requirements for the linear |
||
11669 | /// decls. |
||
11670 | bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc, |
||
11671 | OpenMPLinearClauseKind LinKind, QualType Type, |
||
11672 | bool IsDeclareSimd = false); |
||
11673 | |||
11674 | /// Called on well-formed '\#pragma omp declare simd' after parsing of |
||
11675 | /// the associated method/function. |
||
11676 | DeclGroupPtrTy ActOnOpenMPDeclareSimdDirective( |
||
11677 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, |
||
11678 | Expr *Simdlen, ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
||
11679 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
||
11680 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR); |
||
11681 | |||
11682 | /// Checks '\#pragma omp declare variant' variant function and original |
||
11683 | /// functions after parsing of the associated method/function. |
||
11684 | /// \param DG Function declaration to which declare variant directive is |
||
11685 | /// applied to. |
||
11686 | /// \param VariantRef Expression that references the variant function, which |
||
11687 | /// must be used instead of the original one, specified in \p DG. |
||
11688 | /// \param TI The trait info object representing the match clause. |
||
11689 | /// \param NumAppendArgs The number of omp_interop_t arguments to account for |
||
11690 | /// in checking. |
||
11691 | /// \returns std::nullopt, if the function/variant function are not compatible |
||
11692 | /// with the pragma, pair of original function/variant ref expression |
||
11693 | /// otherwise. |
||
11694 | std::optional<std::pair<FunctionDecl *, Expr *>> |
||
11695 | checkOpenMPDeclareVariantFunction(DeclGroupPtrTy DG, Expr *VariantRef, |
||
11696 | OMPTraitInfo &TI, unsigned NumAppendArgs, |
||
11697 | SourceRange SR); |
||
11698 | |||
11699 | /// Called on well-formed '\#pragma omp declare variant' after parsing of |
||
11700 | /// the associated method/function. |
||
11701 | /// \param FD Function declaration to which declare variant directive is |
||
11702 | /// applied to. |
||
11703 | /// \param VariantRef Expression that references the variant function, which |
||
11704 | /// must be used instead of the original one, specified in \p DG. |
||
11705 | /// \param TI The context traits associated with the function variant. |
||
11706 | /// \param AdjustArgsNothing The list of 'nothing' arguments. |
||
11707 | /// \param AdjustArgsNeedDevicePtr The list of 'need_device_ptr' arguments. |
||
11708 | /// \param AppendArgs The list of 'append_args' arguments. |
||
11709 | /// \param AdjustArgsLoc The Location of an 'adjust_args' clause. |
||
11710 | /// \param AppendArgsLoc The Location of an 'append_args' clause. |
||
11711 | /// \param SR The SourceRange of the 'declare variant' directive. |
||
11712 | void ActOnOpenMPDeclareVariantDirective( |
||
11713 | FunctionDecl *FD, Expr *VariantRef, OMPTraitInfo &TI, |
||
11714 | ArrayRef<Expr *> AdjustArgsNothing, |
||
11715 | ArrayRef<Expr *> AdjustArgsNeedDevicePtr, |
||
11716 | ArrayRef<OMPInteropInfo> AppendArgs, SourceLocation AdjustArgsLoc, |
||
11717 | SourceLocation AppendArgsLoc, SourceRange SR); |
||
11718 | |||
11719 | OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, |
||
11720 | Expr *Expr, |
||
11721 | SourceLocation StartLoc, |
||
11722 | SourceLocation LParenLoc, |
||
11723 | SourceLocation EndLoc); |
||
11724 | /// Called on well-formed 'allocator' clause. |
||
11725 | OMPClause *ActOnOpenMPAllocatorClause(Expr *Allocator, |
||
11726 | SourceLocation StartLoc, |
||
11727 | SourceLocation LParenLoc, |
||
11728 | SourceLocation EndLoc); |
||
11729 | /// Called on well-formed 'if' clause. |
||
11730 | OMPClause *ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
||
11731 | Expr *Condition, SourceLocation StartLoc, |
||
11732 | SourceLocation LParenLoc, |
||
11733 | SourceLocation NameModifierLoc, |
||
11734 | SourceLocation ColonLoc, |
||
11735 | SourceLocation EndLoc); |
||
11736 | /// Called on well-formed 'final' clause. |
||
11737 | OMPClause *ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
||
11738 | SourceLocation LParenLoc, |
||
11739 | SourceLocation EndLoc); |
||
11740 | /// Called on well-formed 'num_threads' clause. |
||
11741 | OMPClause *ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
||
11742 | SourceLocation StartLoc, |
||
11743 | SourceLocation LParenLoc, |
||
11744 | SourceLocation EndLoc); |
||
11745 | /// Called on well-formed 'align' clause. |
||
11746 | OMPClause *ActOnOpenMPAlignClause(Expr *Alignment, SourceLocation StartLoc, |
||
11747 | SourceLocation LParenLoc, |
||
11748 | SourceLocation EndLoc); |
||
11749 | /// Called on well-formed 'safelen' clause. |
||
11750 | OMPClause *ActOnOpenMPSafelenClause(Expr *Length, |
||
11751 | SourceLocation StartLoc, |
||
11752 | SourceLocation LParenLoc, |
||
11753 | SourceLocation EndLoc); |
||
11754 | /// Called on well-formed 'simdlen' clause. |
||
11755 | OMPClause *ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc, |
||
11756 | SourceLocation LParenLoc, |
||
11757 | SourceLocation EndLoc); |
||
11758 | /// Called on well-form 'sizes' clause. |
||
11759 | OMPClause *ActOnOpenMPSizesClause(ArrayRef<Expr *> SizeExprs, |
||
11760 | SourceLocation StartLoc, |
||
11761 | SourceLocation LParenLoc, |
||
11762 | SourceLocation EndLoc); |
||
11763 | /// Called on well-form 'full' clauses. |
||
11764 | OMPClause *ActOnOpenMPFullClause(SourceLocation StartLoc, |
||
11765 | SourceLocation EndLoc); |
||
11766 | /// Called on well-form 'partial' clauses. |
||
11767 | OMPClause *ActOnOpenMPPartialClause(Expr *FactorExpr, SourceLocation StartLoc, |
||
11768 | SourceLocation LParenLoc, |
||
11769 | SourceLocation EndLoc); |
||
11770 | /// Called on well-formed 'collapse' clause. |
||
11771 | OMPClause *ActOnOpenMPCollapseClause(Expr *NumForLoops, |
||
11772 | SourceLocation StartLoc, |
||
11773 | SourceLocation LParenLoc, |
||
11774 | SourceLocation EndLoc); |
||
11775 | /// Called on well-formed 'ordered' clause. |
||
11776 | OMPClause * |
||
11777 | ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, |
||
11778 | SourceLocation LParenLoc = SourceLocation(), |
||
11779 | Expr *NumForLoops = nullptr); |
||
11780 | /// Called on well-formed 'grainsize' clause. |
||
11781 | OMPClause *ActOnOpenMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, |
||
11782 | Expr *Size, SourceLocation StartLoc, |
||
11783 | SourceLocation LParenLoc, |
||
11784 | SourceLocation ModifierLoc, |
||
11785 | SourceLocation EndLoc); |
||
11786 | /// Called on well-formed 'num_tasks' clause. |
||
11787 | OMPClause *ActOnOpenMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, |
||
11788 | Expr *NumTasks, SourceLocation StartLoc, |
||
11789 | SourceLocation LParenLoc, |
||
11790 | SourceLocation ModifierLoc, |
||
11791 | SourceLocation EndLoc); |
||
11792 | /// Called on well-formed 'hint' clause. |
||
11793 | OMPClause *ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
||
11794 | SourceLocation LParenLoc, |
||
11795 | SourceLocation EndLoc); |
||
11796 | /// Called on well-formed 'detach' clause. |
||
11797 | OMPClause *ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc, |
||
11798 | SourceLocation LParenLoc, |
||
11799 | SourceLocation EndLoc); |
||
11800 | |||
11801 | OMPClause *ActOnOpenMPSimpleClause(OpenMPClauseKind Kind, |
||
11802 | unsigned Argument, |
||
11803 | SourceLocation ArgumentLoc, |
||
11804 | SourceLocation StartLoc, |
||
11805 | SourceLocation LParenLoc, |
||
11806 | SourceLocation EndLoc); |
||
11807 | /// Called on well-formed 'when' clause. |
||
11808 | OMPClause *ActOnOpenMPWhenClause(OMPTraitInfo &TI, SourceLocation StartLoc, |
||
11809 | SourceLocation LParenLoc, |
||
11810 | SourceLocation EndLoc); |
||
11811 | /// Called on well-formed 'default' clause. |
||
11812 | OMPClause *ActOnOpenMPDefaultClause(llvm::omp::DefaultKind Kind, |
||
11813 | SourceLocation KindLoc, |
||
11814 | SourceLocation StartLoc, |
||
11815 | SourceLocation LParenLoc, |
||
11816 | SourceLocation EndLoc); |
||
11817 | /// Called on well-formed 'proc_bind' clause. |
||
11818 | OMPClause *ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind, |
||
11819 | SourceLocation KindLoc, |
||
11820 | SourceLocation StartLoc, |
||
11821 | SourceLocation LParenLoc, |
||
11822 | SourceLocation EndLoc); |
||
11823 | /// Called on well-formed 'order' clause. |
||
11824 | OMPClause *ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier, |
||
11825 | OpenMPOrderClauseKind Kind, |
||
11826 | SourceLocation StartLoc, |
||
11827 | SourceLocation LParenLoc, |
||
11828 | SourceLocation MLoc, SourceLocation KindLoc, |
||
11829 | SourceLocation EndLoc); |
||
11830 | /// Called on well-formed 'update' clause. |
||
11831 | OMPClause *ActOnOpenMPUpdateClause(OpenMPDependClauseKind Kind, |
||
11832 | SourceLocation KindLoc, |
||
11833 | SourceLocation StartLoc, |
||
11834 | SourceLocation LParenLoc, |
||
11835 | SourceLocation EndLoc); |
||
11836 | |||
11837 | OMPClause *ActOnOpenMPSingleExprWithArgClause( |
||
11838 | OpenMPClauseKind Kind, ArrayRef<unsigned> Arguments, Expr *Expr, |
||
11839 | SourceLocation StartLoc, SourceLocation LParenLoc, |
||
11840 | ArrayRef<SourceLocation> ArgumentsLoc, SourceLocation DelimLoc, |
||
11841 | SourceLocation EndLoc); |
||
11842 | /// Called on well-formed 'schedule' clause. |
||
11843 | OMPClause *ActOnOpenMPScheduleClause( |
||
11844 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
||
11845 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
||
11846 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
||
11847 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc); |
||
11848 | |||
11849 | OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc, |
||
11850 | SourceLocation EndLoc); |
||
11851 | /// Called on well-formed 'nowait' clause. |
||
11852 | OMPClause *ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
||
11853 | SourceLocation EndLoc); |
||
11854 | /// Called on well-formed 'untied' clause. |
||
11855 | OMPClause *ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
||
11856 | SourceLocation EndLoc); |
||
11857 | /// Called on well-formed 'mergeable' clause. |
||
11858 | OMPClause *ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
||
11859 | SourceLocation EndLoc); |
||
11860 | /// Called on well-formed 'read' clause. |
||
11861 | OMPClause *ActOnOpenMPReadClause(SourceLocation StartLoc, |
||
11862 | SourceLocation EndLoc); |
||
11863 | /// Called on well-formed 'write' clause. |
||
11864 | OMPClause *ActOnOpenMPWriteClause(SourceLocation StartLoc, |
||
11865 | SourceLocation EndLoc); |
||
11866 | /// Called on well-formed 'update' clause. |
||
11867 | OMPClause *ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
||
11868 | SourceLocation EndLoc); |
||
11869 | /// Called on well-formed 'capture' clause. |
||
11870 | OMPClause *ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
||
11871 | SourceLocation EndLoc); |
||
11872 | /// Called on well-formed 'compare' clause. |
||
11873 | OMPClause *ActOnOpenMPCompareClause(SourceLocation StartLoc, |
||
11874 | SourceLocation EndLoc); |
||
11875 | /// Called on well-formed 'seq_cst' clause. |
||
11876 | OMPClause *ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
||
11877 | SourceLocation EndLoc); |
||
11878 | /// Called on well-formed 'acq_rel' clause. |
||
11879 | OMPClause *ActOnOpenMPAcqRelClause(SourceLocation StartLoc, |
||
11880 | SourceLocation EndLoc); |
||
11881 | /// Called on well-formed 'acquire' clause. |
||
11882 | OMPClause *ActOnOpenMPAcquireClause(SourceLocation StartLoc, |
||
11883 | SourceLocation EndLoc); |
||
11884 | /// Called on well-formed 'release' clause. |
||
11885 | OMPClause *ActOnOpenMPReleaseClause(SourceLocation StartLoc, |
||
11886 | SourceLocation EndLoc); |
||
11887 | /// Called on well-formed 'relaxed' clause. |
||
11888 | OMPClause *ActOnOpenMPRelaxedClause(SourceLocation StartLoc, |
||
11889 | SourceLocation EndLoc); |
||
11890 | |||
11891 | /// Called on well-formed 'init' clause. |
||
11892 | OMPClause * |
||
11893 | ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, |
||
11894 | SourceLocation StartLoc, SourceLocation LParenLoc, |
||
11895 | SourceLocation VarLoc, SourceLocation EndLoc); |
||
11896 | |||
11897 | /// Called on well-formed 'use' clause. |
||
11898 | OMPClause *ActOnOpenMPUseClause(Expr *InteropVar, SourceLocation StartLoc, |
||
11899 | SourceLocation LParenLoc, |
||
11900 | SourceLocation VarLoc, SourceLocation EndLoc); |
||
11901 | |||
11902 | /// Called on well-formed 'destroy' clause. |
||
11903 | OMPClause *ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, |
||
11904 | SourceLocation LParenLoc, |
||
11905 | SourceLocation VarLoc, |
||
11906 | SourceLocation EndLoc); |
||
11907 | /// Called on well-formed 'novariants' clause. |
||
11908 | OMPClause *ActOnOpenMPNovariantsClause(Expr *Condition, |
||
11909 | SourceLocation StartLoc, |
||
11910 | SourceLocation LParenLoc, |
||
11911 | SourceLocation EndLoc); |
||
11912 | /// Called on well-formed 'nocontext' clause. |
||
11913 | OMPClause *ActOnOpenMPNocontextClause(Expr *Condition, |
||
11914 | SourceLocation StartLoc, |
||
11915 | SourceLocation LParenLoc, |
||
11916 | SourceLocation EndLoc); |
||
11917 | /// Called on well-formed 'filter' clause. |
||
11918 | OMPClause *ActOnOpenMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, |
||
11919 | SourceLocation LParenLoc, |
||
11920 | SourceLocation EndLoc); |
||
11921 | /// Called on well-formed 'threads' clause. |
||
11922 | OMPClause *ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
||
11923 | SourceLocation EndLoc); |
||
11924 | /// Called on well-formed 'simd' clause. |
||
11925 | OMPClause *ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
||
11926 | SourceLocation EndLoc); |
||
11927 | /// Called on well-formed 'nogroup' clause. |
||
11928 | OMPClause *ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
||
11929 | SourceLocation EndLoc); |
||
11930 | /// Called on well-formed 'unified_address' clause. |
||
11931 | OMPClause *ActOnOpenMPUnifiedAddressClause(SourceLocation StartLoc, |
||
11932 | SourceLocation EndLoc); |
||
11933 | |||
11934 | /// Called on well-formed 'unified_address' clause. |
||
11935 | OMPClause *ActOnOpenMPUnifiedSharedMemoryClause(SourceLocation StartLoc, |
||
11936 | SourceLocation EndLoc); |
||
11937 | |||
11938 | /// Called on well-formed 'reverse_offload' clause. |
||
11939 | OMPClause *ActOnOpenMPReverseOffloadClause(SourceLocation StartLoc, |
||
11940 | SourceLocation EndLoc); |
||
11941 | |||
11942 | /// Called on well-formed 'dynamic_allocators' clause. |
||
11943 | OMPClause *ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc, |
||
11944 | SourceLocation EndLoc); |
||
11945 | |||
11946 | /// Called on well-formed 'atomic_default_mem_order' clause. |
||
11947 | OMPClause *ActOnOpenMPAtomicDefaultMemOrderClause( |
||
11948 | OpenMPAtomicDefaultMemOrderClauseKind Kind, SourceLocation KindLoc, |
||
11949 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); |
||
11950 | |||
11951 | /// Called on well-formed 'at' clause. |
||
11952 | OMPClause *ActOnOpenMPAtClause(OpenMPAtClauseKind Kind, |
||
11953 | SourceLocation KindLoc, |
||
11954 | SourceLocation StartLoc, |
||
11955 | SourceLocation LParenLoc, |
||
11956 | SourceLocation EndLoc); |
||
11957 | |||
11958 | /// Called on well-formed 'severity' clause. |
||
11959 | OMPClause *ActOnOpenMPSeverityClause(OpenMPSeverityClauseKind Kind, |
||
11960 | SourceLocation KindLoc, |
||
11961 | SourceLocation StartLoc, |
||
11962 | SourceLocation LParenLoc, |
||
11963 | SourceLocation EndLoc); |
||
11964 | |||
11965 | /// Called on well-formed 'message' clause. |
||
11966 | /// passing string for message. |
||
11967 | OMPClause *ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc, |
||
11968 | SourceLocation LParenLoc, |
||
11969 | SourceLocation EndLoc); |
||
11970 | |||
11971 | /// Data used for processing a list of variables in OpenMP clauses. |
||
11972 | struct OpenMPVarListDataTy final { |
||
11973 | Expr *DepModOrTailExpr = nullptr; |
||
11974 | Expr *IteratorExpr = nullptr; |
||
11975 | SourceLocation ColonLoc; |
||
11976 | SourceLocation RLoc; |
||
11977 | CXXScopeSpec ReductionOrMapperIdScopeSpec; |
||
11978 | DeclarationNameInfo ReductionOrMapperId; |
||
11979 | int ExtraModifier = -1; ///< Additional modifier for linear, map, depend or |
||
11980 | ///< lastprivate clause. |
||
11981 | SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers> |
||
11982 | MapTypeModifiers; |
||
11983 | SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers> |
||
11984 | MapTypeModifiersLoc; |
||
11985 | SmallVector<OpenMPMotionModifierKind, NumberOfOMPMotionModifiers> |
||
11986 | MotionModifiers; |
||
11987 | SmallVector<SourceLocation, NumberOfOMPMotionModifiers> MotionModifiersLoc; |
||
11988 | bool IsMapTypeImplicit = false; |
||
11989 | SourceLocation ExtraModifierLoc; |
||
11990 | SourceLocation OmpAllMemoryLoc; |
||
11991 | }; |
||
11992 | |||
11993 | OMPClause *ActOnOpenMPVarListClause(OpenMPClauseKind Kind, |
||
11994 | ArrayRef<Expr *> Vars, |
||
11995 | const OMPVarListLocTy &Locs, |
||
11996 | OpenMPVarListDataTy &Data); |
||
11997 | /// Called on well-formed 'inclusive' clause. |
||
11998 | OMPClause *ActOnOpenMPInclusiveClause(ArrayRef<Expr *> VarList, |
||
11999 | SourceLocation StartLoc, |
||
12000 | SourceLocation LParenLoc, |
||
12001 | SourceLocation EndLoc); |
||
12002 | /// Called on well-formed 'exclusive' clause. |
||
12003 | OMPClause *ActOnOpenMPExclusiveClause(ArrayRef<Expr *> VarList, |
||
12004 | SourceLocation StartLoc, |
||
12005 | SourceLocation LParenLoc, |
||
12006 | SourceLocation EndLoc); |
||
12007 | /// Called on well-formed 'allocate' clause. |
||
12008 | OMPClause * |
||
12009 | ActOnOpenMPAllocateClause(Expr *Allocator, ArrayRef<Expr *> VarList, |
||
12010 | SourceLocation StartLoc, SourceLocation ColonLoc, |
||
12011 | SourceLocation LParenLoc, SourceLocation EndLoc); |
||
12012 | /// Called on well-formed 'private' clause. |
||
12013 | OMPClause *ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
||
12014 | SourceLocation StartLoc, |
||
12015 | SourceLocation LParenLoc, |
||
12016 | SourceLocation EndLoc); |
||
12017 | /// Called on well-formed 'firstprivate' clause. |
||
12018 | OMPClause *ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
||
12019 | SourceLocation StartLoc, |
||
12020 | SourceLocation LParenLoc, |
||
12021 | SourceLocation EndLoc); |
||
12022 | /// Called on well-formed 'lastprivate' clause. |
||
12023 | OMPClause *ActOnOpenMPLastprivateClause( |
||
12024 | ArrayRef<Expr *> VarList, OpenMPLastprivateModifier LPKind, |
||
12025 | SourceLocation LPKindLoc, SourceLocation ColonLoc, |
||
12026 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); |
||
12027 | /// Called on well-formed 'shared' clause. |
||
12028 | OMPClause *ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
||
12029 | SourceLocation StartLoc, |
||
12030 | SourceLocation LParenLoc, |
||
12031 | SourceLocation EndLoc); |
||
12032 | /// Called on well-formed 'reduction' clause. |
||
12033 | OMPClause *ActOnOpenMPReductionClause( |
||
12034 | ArrayRef<Expr *> VarList, OpenMPReductionClauseModifier Modifier, |
||
12035 | SourceLocation StartLoc, SourceLocation LParenLoc, |
||
12036 | SourceLocation ModifierLoc, SourceLocation ColonLoc, |
||
12037 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
||
12038 | const DeclarationNameInfo &ReductionId, |
||
12039 | ArrayRef<Expr *> UnresolvedReductions = std::nullopt); |
||
12040 | /// Called on well-formed 'task_reduction' clause. |
||
12041 | OMPClause *ActOnOpenMPTaskReductionClause( |
||
12042 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
||
12043 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
||
12044 | CXXScopeSpec &ReductionIdScopeSpec, |
||
12045 | const DeclarationNameInfo &ReductionId, |
||
12046 | ArrayRef<Expr *> UnresolvedReductions = std::nullopt); |
||
12047 | /// Called on well-formed 'in_reduction' clause. |
||
12048 | OMPClause *ActOnOpenMPInReductionClause( |
||
12049 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
||
12050 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
||
12051 | CXXScopeSpec &ReductionIdScopeSpec, |
||
12052 | const DeclarationNameInfo &ReductionId, |
||
12053 | ArrayRef<Expr *> UnresolvedReductions = std::nullopt); |
||
12054 | /// Called on well-formed 'linear' clause. |
||
12055 | OMPClause * |
||
12056 | ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
||
12057 | SourceLocation StartLoc, SourceLocation LParenLoc, |
||
12058 | OpenMPLinearClauseKind LinKind, SourceLocation LinLoc, |
||
12059 | SourceLocation ColonLoc, SourceLocation EndLoc); |
||
12060 | /// Called on well-formed 'aligned' clause. |
||
12061 | OMPClause *ActOnOpenMPAlignedClause(ArrayRef<Expr *> VarList, |
||
12062 | Expr *Alignment, |
||
12063 | SourceLocation StartLoc, |
||
12064 | SourceLocation LParenLoc, |
||
12065 | SourceLocation ColonLoc, |
||
12066 | SourceLocation EndLoc); |
||
12067 | /// Called on well-formed 'copyin' clause. |
||
12068 | OMPClause *ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
||
12069 | SourceLocation StartLoc, |
||
12070 | SourceLocation LParenLoc, |
||
12071 | SourceLocation EndLoc); |
||
12072 | /// Called on well-formed 'copyprivate' clause. |
||
12073 | OMPClause *ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
||
12074 | SourceLocation StartLoc, |
||
12075 | SourceLocation LParenLoc, |
||
12076 | SourceLocation EndLoc); |
||
12077 | /// Called on well-formed 'flush' pseudo clause. |
||
12078 | OMPClause *ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
||
12079 | SourceLocation StartLoc, |
||
12080 | SourceLocation LParenLoc, |
||
12081 | SourceLocation EndLoc); |
||
12082 | /// Called on well-formed 'depobj' pseudo clause. |
||
12083 | OMPClause *ActOnOpenMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, |
||
12084 | SourceLocation LParenLoc, |
||
12085 | SourceLocation EndLoc); |
||
12086 | /// Called on well-formed 'depend' clause. |
||
12087 | OMPClause *ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data, |
||
12088 | Expr *DepModifier, |
||
12089 | ArrayRef<Expr *> VarList, |
||
12090 | SourceLocation StartLoc, |
||
12091 | SourceLocation LParenLoc, |
||
12092 | SourceLocation EndLoc); |
||
12093 | /// Called on well-formed 'device' clause. |
||
12094 | OMPClause *ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier, |
||
12095 | Expr *Device, SourceLocation StartLoc, |
||
12096 | SourceLocation LParenLoc, |
||
12097 | SourceLocation ModifierLoc, |
||
12098 | SourceLocation EndLoc); |
||
12099 | /// Called on well-formed 'map' clause. |
||
12100 | OMPClause *ActOnOpenMPMapClause( |
||
12101 | Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
||
12102 | ArrayRef<SourceLocation> MapTypeModifiersLoc, |
||
12103 | CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, |
||
12104 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
||
12105 | SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
||
12106 | const OMPVarListLocTy &Locs, bool NoDiagnose = false, |
||
12107 | ArrayRef<Expr *> UnresolvedMappers = std::nullopt); |
||
12108 | /// Called on well-formed 'num_teams' clause. |
||
12109 | OMPClause *ActOnOpenMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, |
||
12110 | SourceLocation LParenLoc, |
||
12111 | SourceLocation EndLoc); |
||
12112 | /// Called on well-formed 'thread_limit' clause. |
||
12113 | OMPClause *ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
||
12114 | SourceLocation StartLoc, |
||
12115 | SourceLocation LParenLoc, |
||
12116 | SourceLocation EndLoc); |
||
12117 | /// Called on well-formed 'priority' clause. |
||
12118 | OMPClause *ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc, |
||
12119 | SourceLocation LParenLoc, |
||
12120 | SourceLocation EndLoc); |
||
12121 | /// Called on well-formed 'dist_schedule' clause. |
||
12122 | OMPClause *ActOnOpenMPDistScheduleClause( |
||
12123 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, |
||
12124 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, |
||
12125 | SourceLocation CommaLoc, SourceLocation EndLoc); |
||
12126 | /// Called on well-formed 'defaultmap' clause. |
||
12127 | OMPClause *ActOnOpenMPDefaultmapClause( |
||
12128 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
||
12129 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
||
12130 | SourceLocation KindLoc, SourceLocation EndLoc); |
||
12131 | /// Called on well-formed 'to' clause. |
||
12132 | OMPClause * |
||
12133 | ActOnOpenMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
||
12134 | ArrayRef<SourceLocation> MotionModifiersLoc, |
||
12135 | CXXScopeSpec &MapperIdScopeSpec, |
||
12136 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
||
12137 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
||
12138 | ArrayRef<Expr *> UnresolvedMappers = std::nullopt); |
||
12139 | /// Called on well-formed 'from' clause. |
||
12140 | OMPClause * |
||
12141 | ActOnOpenMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
||
12142 | ArrayRef<SourceLocation> MotionModifiersLoc, |
||
12143 | CXXScopeSpec &MapperIdScopeSpec, |
||
12144 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
||
12145 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
||
12146 | ArrayRef<Expr *> UnresolvedMappers = std::nullopt); |
||
12147 | /// Called on well-formed 'use_device_ptr' clause. |
||
12148 | OMPClause *ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
||
12149 | const OMPVarListLocTy &Locs); |
||
12150 | /// Called on well-formed 'use_device_addr' clause. |
||
12151 | OMPClause *ActOnOpenMPUseDeviceAddrClause(ArrayRef<Expr *> VarList, |
||
12152 | const OMPVarListLocTy &Locs); |
||
12153 | /// Called on well-formed 'is_device_ptr' clause. |
||
12154 | OMPClause *ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
||
12155 | const OMPVarListLocTy &Locs); |
||
12156 | /// Called on well-formed 'has_device_addr' clause. |
||
12157 | OMPClause *ActOnOpenMPHasDeviceAddrClause(ArrayRef<Expr *> VarList, |
||
12158 | const OMPVarListLocTy &Locs); |
||
12159 | /// Called on well-formed 'nontemporal' clause. |
||
12160 | OMPClause *ActOnOpenMPNontemporalClause(ArrayRef<Expr *> VarList, |
||
12161 | SourceLocation StartLoc, |
||
12162 | SourceLocation LParenLoc, |
||
12163 | SourceLocation EndLoc); |
||
12164 | |||
12165 | /// Data for list of allocators. |
||
12166 | struct UsesAllocatorsData { |
||
12167 | /// Allocator. |
||
12168 | Expr *Allocator = nullptr; |
||
12169 | /// Allocator traits. |
||
12170 | Expr *AllocatorTraits = nullptr; |
||
12171 | /// Locations of '(' and ')' symbols. |
||
12172 | SourceLocation LParenLoc, RParenLoc; |
||
12173 | }; |
||
12174 | /// Called on well-formed 'uses_allocators' clause. |
||
12175 | OMPClause *ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, |
||
12176 | SourceLocation LParenLoc, |
||
12177 | SourceLocation EndLoc, |
||
12178 | ArrayRef<UsesAllocatorsData> Data); |
||
12179 | /// Called on well-formed 'affinity' clause. |
||
12180 | OMPClause *ActOnOpenMPAffinityClause(SourceLocation StartLoc, |
||
12181 | SourceLocation LParenLoc, |
||
12182 | SourceLocation ColonLoc, |
||
12183 | SourceLocation EndLoc, Expr *Modifier, |
||
12184 | ArrayRef<Expr *> Locators); |
||
12185 | /// Called on a well-formed 'bind' clause. |
||
12186 | OMPClause *ActOnOpenMPBindClause(OpenMPBindClauseKind Kind, |
||
12187 | SourceLocation KindLoc, |
||
12188 | SourceLocation StartLoc, |
||
12189 | SourceLocation LParenLoc, |
||
12190 | SourceLocation EndLoc); |
||
12191 | |||
12192 | /// Called on a well-formed 'ompx_dyn_cgroup_mem' clause. |
||
12193 | OMPClause *ActOnOpenMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, |
||
12194 | SourceLocation LParenLoc, |
||
12195 | SourceLocation EndLoc); |
||
12196 | |||
12197 | /// The kind of conversion being performed. |
||
12198 | enum CheckedConversionKind { |
||
12199 | /// An implicit conversion. |
||
12200 | CCK_ImplicitConversion, |
||
12201 | /// A C-style cast. |
||
12202 | CCK_CStyleCast, |
||
12203 | /// A functional-style cast. |
||
12204 | CCK_FunctionalCast, |
||
12205 | /// A cast other than a C-style cast. |
||
12206 | CCK_OtherCast, |
||
12207 | /// A conversion for an operand of a builtin overloaded operator. |
||
12208 | CCK_ForBuiltinOverloadedOp |
||
12209 | }; |
||
12210 | |||
12211 | static bool isCast(CheckedConversionKind CCK) { |
||
12212 | return CCK == CCK_CStyleCast || CCK == CCK_FunctionalCast || |
||
12213 | CCK == CCK_OtherCast; |
||
12214 | } |
||
12215 | |||
12216 | /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit |
||
12217 | /// cast. If there is already an implicit cast, merge into the existing one. |
||
12218 | /// If isLvalue, the result of the cast is an lvalue. |
||
12219 | ExprResult |
||
12220 | ImpCastExprToType(Expr *E, QualType Type, CastKind CK, |
||
12221 | ExprValueKind VK = VK_PRValue, |
||
12222 | const CXXCastPath *BasePath = nullptr, |
||
12223 | CheckedConversionKind CCK = CCK_ImplicitConversion); |
||
12224 | |||
12225 | /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding |
||
12226 | /// to the conversion from scalar type ScalarTy to the Boolean type. |
||
12227 | static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); |
||
12228 | |||
12229 | /// IgnoredValueConversions - Given that an expression's result is |
||
12230 | /// syntactically ignored, perform any conversions that are |
||
12231 | /// required. |
||
12232 | ExprResult IgnoredValueConversions(Expr *E); |
||
12233 | |||
12234 | // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts |
||
12235 | // functions and arrays to their respective pointers (C99 6.3.2.1). |
||
12236 | ExprResult UsualUnaryConversions(Expr *E); |
||
12237 | |||
12238 | /// CallExprUnaryConversions - a special case of an unary conversion |
||
12239 | /// performed on a function designator of a call expression. |
||
12240 | ExprResult CallExprUnaryConversions(Expr *E); |
||
12241 | |||
12242 | // DefaultFunctionArrayConversion - converts functions and arrays |
||
12243 | // to their respective pointers (C99 6.3.2.1). |
||
12244 | ExprResult DefaultFunctionArrayConversion(Expr *E, bool Diagnose = true); |
||
12245 | |||
12246 | // DefaultFunctionArrayLvalueConversion - converts functions and |
||
12247 | // arrays to their respective pointers and performs the |
||
12248 | // lvalue-to-rvalue conversion. |
||
12249 | ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, |
||
12250 | bool Diagnose = true); |
||
12251 | |||
12252 | // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on |
||
12253 | // the operand. This function is a no-op if the operand has a function type |
||
12254 | // or an array type. |
||
12255 | ExprResult DefaultLvalueConversion(Expr *E); |
||
12256 | |||
12257 | // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that |
||
12258 | // do not have a prototype. Integer promotions are performed on each |
||
12259 | // argument, and arguments that have type float are promoted to double. |
||
12260 | ExprResult DefaultArgumentPromotion(Expr *E); |
||
12261 | |||
12262 | /// If \p E is a prvalue denoting an unmaterialized temporary, materialize |
||
12263 | /// it as an xvalue. In C++98, the result will still be a prvalue, because |
||
12264 | /// we don't have xvalues there. |
||
12265 | ExprResult TemporaryMaterializationConversion(Expr *E); |
||
12266 | |||
12267 | // Used for emitting the right warning by DefaultVariadicArgumentPromotion |
||
12268 | enum VariadicCallType { |
||
12269 | VariadicFunction, |
||
12270 | VariadicBlock, |
||
12271 | VariadicMethod, |
||
12272 | VariadicConstructor, |
||
12273 | VariadicDoesNotApply |
||
12274 | }; |
||
12275 | |||
12276 | VariadicCallType getVariadicCallType(FunctionDecl *FDecl, |
||
12277 | const FunctionProtoType *Proto, |
||
12278 | Expr *Fn); |
||
12279 | |||
12280 | // Used for determining in which context a type is allowed to be passed to a |
||
12281 | // vararg function. |
||
12282 | enum VarArgKind { |
||
12283 | VAK_Valid, |
||
12284 | VAK_ValidInCXX11, |
||
12285 | VAK_Undefined, |
||
12286 | VAK_MSVCUndefined, |
||
12287 | VAK_Invalid |
||
12288 | }; |
||
12289 | |||
12290 | // Determines which VarArgKind fits an expression. |
||
12291 | VarArgKind isValidVarArgType(const QualType &Ty); |
||
12292 | |||
12293 | /// Check to see if the given expression is a valid argument to a variadic |
||
12294 | /// function, issuing a diagnostic if not. |
||
12295 | void checkVariadicArgument(const Expr *E, VariadicCallType CT); |
||
12296 | |||
12297 | /// Check whether the given statement can have musttail applied to it, |
||
12298 | /// issuing a diagnostic and returning false if not. In the success case, |
||
12299 | /// the statement is rewritten to remove implicit nodes from the return |
||
12300 | /// value. |
||
12301 | bool checkAndRewriteMustTailAttr(Stmt *St, const Attr &MTA); |
||
12302 | |||
12303 | private: |
||
12304 | /// Check whether the given statement can have musttail applied to it, |
||
12305 | /// issuing a diagnostic and returning false if not. |
||
12306 | bool checkMustTailAttr(const Stmt *St, const Attr &MTA); |
||
12307 | |||
12308 | public: |
||
12309 | /// Check to see if a given expression could have '.c_str()' called on it. |
||
12310 | bool hasCStrMethod(const Expr *E); |
||
12311 | |||
12312 | /// GatherArgumentsForCall - Collector argument expressions for various |
||
12313 | /// form of call prototypes. |
||
12314 | bool GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl, |
||
12315 | const FunctionProtoType *Proto, |
||
12316 | unsigned FirstParam, ArrayRef<Expr *> Args, |
||
12317 | SmallVectorImpl<Expr *> &AllArgs, |
||
12318 | VariadicCallType CallType = VariadicDoesNotApply, |
||
12319 | bool AllowExplicit = false, |
||
12320 | bool IsListInitialization = false); |
||
12321 | |||
12322 | // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but |
||
12323 | // will create a runtime trap if the resulting type is not a POD type. |
||
12324 | ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, |
||
12325 | FunctionDecl *FDecl); |
||
12326 | |||
12327 | /// Context in which we're performing a usual arithmetic conversion. |
||
12328 | enum ArithConvKind { |
||
12329 | /// An arithmetic operation. |
||
12330 | ACK_Arithmetic, |
||
12331 | /// A bitwise operation. |
||
12332 | ACK_BitwiseOp, |
||
12333 | /// A comparison. |
||
12334 | ACK_Comparison, |
||
12335 | /// A conditional (?:) operator. |
||
12336 | ACK_Conditional, |
||
12337 | /// A compound assignment expression. |
||
12338 | ACK_CompAssign, |
||
12339 | }; |
||
12340 | |||
12341 | // UsualArithmeticConversions - performs the UsualUnaryConversions on it's |
||
12342 | // operands and then handles various conversions that are common to binary |
||
12343 | // operators (C99 6.3.1.8). If both operands aren't arithmetic, this |
||
12344 | // routine returns the first non-arithmetic type found. The client is |
||
12345 | // responsible for emitting appropriate error diagnostics. |
||
12346 | QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, |
||
12347 | SourceLocation Loc, ArithConvKind ACK); |
||
12348 | |||
12349 | /// AssignConvertType - All of the 'assignment' semantic checks return this |
||
12350 | /// enum to indicate whether the assignment was allowed. These checks are |
||
12351 | /// done for simple assignments, as well as initialization, return from |
||
12352 | /// function, argument passing, etc. The query is phrased in terms of a |
||
12353 | /// source and destination type. |
||
12354 | enum AssignConvertType { |
||
12355 | /// Compatible - the types are compatible according to the standard. |
||
12356 | Compatible, |
||
12357 | |||
12358 | /// PointerToInt - The assignment converts a pointer to an int, which we |
||
12359 | /// accept as an extension. |
||
12360 | PointerToInt, |
||
12361 | |||
12362 | /// IntToPointer - The assignment converts an int to a pointer, which we |
||
12363 | /// accept as an extension. |
||
12364 | IntToPointer, |
||
12365 | |||
12366 | /// FunctionVoidPointer - The assignment is between a function pointer and |
||
12367 | /// void*, which the standard doesn't allow, but we accept as an extension. |
||
12368 | FunctionVoidPointer, |
||
12369 | |||
12370 | /// IncompatiblePointer - The assignment is between two pointers types that |
||
12371 | /// are not compatible, but we accept them as an extension. |
||
12372 | IncompatiblePointer, |
||
12373 | |||
12374 | /// IncompatibleFunctionPointer - The assignment is between two function |
||
12375 | /// pointers types that are not compatible, but we accept them as an |
||
12376 | /// extension. |
||
12377 | IncompatibleFunctionPointer, |
||
12378 | |||
12379 | /// IncompatibleFunctionPointerStrict - The assignment is between two |
||
12380 | /// function pointer types that are not identical, but are compatible, |
||
12381 | /// unless compiled with -fsanitize=cfi, in which case the type mismatch |
||
12382 | /// may trip an indirect call runtime check. |
||
12383 | IncompatibleFunctionPointerStrict, |
||
12384 | |||
12385 | /// IncompatiblePointerSign - The assignment is between two pointers types |
||
12386 | /// which point to integers which have a different sign, but are otherwise |
||
12387 | /// identical. This is a subset of the above, but broken out because it's by |
||
12388 | /// far the most common case of incompatible pointers. |
||
12389 | IncompatiblePointerSign, |
||
12390 | |||
12391 | /// CompatiblePointerDiscardsQualifiers - The assignment discards |
||
12392 | /// c/v/r qualifiers, which we accept as an extension. |
||
12393 | CompatiblePointerDiscardsQualifiers, |
||
12394 | |||
12395 | /// IncompatiblePointerDiscardsQualifiers - The assignment |
||
12396 | /// discards qualifiers that we don't permit to be discarded, |
||
12397 | /// like address spaces. |
||
12398 | IncompatiblePointerDiscardsQualifiers, |
||
12399 | |||
12400 | /// IncompatibleNestedPointerAddressSpaceMismatch - The assignment |
||
12401 | /// changes address spaces in nested pointer types which is not allowed. |
||
12402 | /// For instance, converting __private int ** to __generic int ** is |
||
12403 | /// illegal even though __private could be converted to __generic. |
||
12404 | IncompatibleNestedPointerAddressSpaceMismatch, |
||
12405 | |||
12406 | /// IncompatibleNestedPointerQualifiers - The assignment is between two |
||
12407 | /// nested pointer types, and the qualifiers other than the first two |
||
12408 | /// levels differ e.g. char ** -> const char **, but we accept them as an |
||
12409 | /// extension. |
||
12410 | IncompatibleNestedPointerQualifiers, |
||
12411 | |||
12412 | /// IncompatibleVectors - The assignment is between two vector types that |
||
12413 | /// have the same size, which we accept as an extension. |
||
12414 | IncompatibleVectors, |
||
12415 | |||
12416 | /// IntToBlockPointer - The assignment converts an int to a block |
||
12417 | /// pointer. We disallow this. |
||
12418 | IntToBlockPointer, |
||
12419 | |||
12420 | /// IncompatibleBlockPointer - The assignment is between two block |
||
12421 | /// pointers types that are not compatible. |
||
12422 | IncompatibleBlockPointer, |
||
12423 | |||
12424 | /// IncompatibleObjCQualifiedId - The assignment is between a qualified |
||
12425 | /// id type and something else (that is incompatible with it). For example, |
||
12426 | /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. |
||
12427 | IncompatibleObjCQualifiedId, |
||
12428 | |||
12429 | /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an |
||
12430 | /// object with __weak qualifier. |
||
12431 | IncompatibleObjCWeakRef, |
||
12432 | |||
12433 | /// Incompatible - We reject this conversion outright, it is invalid to |
||
12434 | /// represent it in the AST. |
||
12435 | Incompatible |
||
12436 | }; |
||
12437 | |||
12438 | /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the |
||
12439 | /// assignment conversion type specified by ConvTy. This returns true if the |
||
12440 | /// conversion was invalid or false if the conversion was accepted. |
||
12441 | bool DiagnoseAssignmentResult(AssignConvertType ConvTy, |
||
12442 | SourceLocation Loc, |
||
12443 | QualType DstType, QualType SrcType, |
||
12444 | Expr *SrcExpr, AssignmentAction Action, |
||
12445 | bool *Complained = nullptr); |
||
12446 | |||
12447 | /// IsValueInFlagEnum - Determine if a value is allowed as part of a flag |
||
12448 | /// enum. If AllowMask is true, then we also allow the complement of a valid |
||
12449 | /// value, to be used as a mask. |
||
12450 | bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val, |
||
12451 | bool AllowMask) const; |
||
12452 | |||
12453 | /// DiagnoseAssignmentEnum - Warn if assignment to enum is a constant |
||
12454 | /// integer not in the range of enum values. |
||
12455 | void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, |
||
12456 | Expr *SrcExpr); |
||
12457 | |||
12458 | /// CheckAssignmentConstraints - Perform type checking for assignment, |
||
12459 | /// argument passing, variable initialization, and function return values. |
||
12460 | /// C99 6.5.16. |
||
12461 | AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, |
||
12462 | QualType LHSType, |
||
12463 | QualType RHSType); |
||
12464 | |||
12465 | /// Check assignment constraints and optionally prepare for a conversion of |
||
12466 | /// the RHS to the LHS type. The conversion is prepared for if ConvertRHS |
||
12467 | /// is true. |
||
12468 | AssignConvertType CheckAssignmentConstraints(QualType LHSType, |
||
12469 | ExprResult &RHS, |
||
12470 | CastKind &Kind, |
||
12471 | bool ConvertRHS = true); |
||
12472 | |||
12473 | /// Check assignment constraints for an assignment of RHS to LHSType. |
||
12474 | /// |
||
12475 | /// \param LHSType The destination type for the assignment. |
||
12476 | /// \param RHS The source expression for the assignment. |
||
12477 | /// \param Diagnose If \c true, diagnostics may be produced when checking |
||
12478 | /// for assignability. If a diagnostic is produced, \p RHS will be |
||
12479 | /// set to ExprError(). Note that this function may still return |
||
12480 | /// without producing a diagnostic, even for an invalid assignment. |
||
12481 | /// \param DiagnoseCFAudited If \c true, the target is a function parameter |
||
12482 | /// in an audited Core Foundation API and does not need to be checked |
||
12483 | /// for ARC retain issues. |
||
12484 | /// \param ConvertRHS If \c true, \p RHS will be updated to model the |
||
12485 | /// conversions necessary to perform the assignment. If \c false, |
||
12486 | /// \p Diagnose must also be \c false. |
||
12487 | AssignConvertType CheckSingleAssignmentConstraints( |
||
12488 | QualType LHSType, ExprResult &RHS, bool Diagnose = true, |
||
12489 | bool DiagnoseCFAudited = false, bool ConvertRHS = true); |
||
12490 | |||
12491 | // If the lhs type is a transparent union, check whether we |
||
12492 | // can initialize the transparent union with the given expression. |
||
12493 | AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, |
||
12494 | ExprResult &RHS); |
||
12495 | |||
12496 | bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); |
||
12497 | |||
12498 | bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); |
||
12499 | |||
12500 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
||
12501 | AssignmentAction Action, |
||
12502 | bool AllowExplicit = false); |
||
12503 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
||
12504 | const ImplicitConversionSequence& ICS, |
||
12505 | AssignmentAction Action, |
||
12506 | CheckedConversionKind CCK |
||
12507 | = CCK_ImplicitConversion); |
||
12508 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
||
12509 | const StandardConversionSequence& SCS, |
||
12510 | AssignmentAction Action, |
||
12511 | CheckedConversionKind CCK); |
||
12512 | |||
12513 | ExprResult PerformQualificationConversion( |
||
12514 | Expr *E, QualType Ty, ExprValueKind VK = VK_PRValue, |
||
12515 | CheckedConversionKind CCK = CCK_ImplicitConversion); |
||
12516 | |||
12517 | /// the following "Check" methods will return a valid/converted QualType |
||
12518 | /// or a null QualType (indicating an error diagnostic was issued). |
||
12519 | |||
12520 | /// type checking binary operators (subroutines of CreateBuiltinBinOp). |
||
12521 | QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS, |
||
12522 | ExprResult &RHS); |
||
12523 | QualType InvalidLogicalVectorOperands(SourceLocation Loc, ExprResult &LHS, |
||
12524 | ExprResult &RHS); |
||
12525 | QualType CheckPointerToMemberOperands( // C++ 5.5 |
||
12526 | ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, |
||
12527 | SourceLocation OpLoc, bool isIndirect); |
||
12528 | QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
||
12529 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign, |
||
12530 | bool IsDivide); |
||
12531 | QualType CheckRemainderOperands( // C99 6.5.5 |
||
12532 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
||
12533 | bool IsCompAssign = false); |
||
12534 | QualType CheckAdditionOperands( // C99 6.5.6 |
||
12535 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
||
12536 | BinaryOperatorKind Opc, QualType* CompLHSTy = nullptr); |
||
12537 | QualType CheckSubtractionOperands( // C99 6.5.6 |
||
12538 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
||
12539 | QualType* CompLHSTy = nullptr); |
||
12540 | QualType CheckShiftOperands( // C99 6.5.7 |
||
12541 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
||
12542 | BinaryOperatorKind Opc, bool IsCompAssign = false); |
||
12543 | void CheckPtrComparisonWithNullChar(ExprResult &E, ExprResult &NullE); |
||
12544 | QualType CheckCompareOperands( // C99 6.5.8/9 |
||
12545 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
||
12546 | BinaryOperatorKind Opc); |
||
12547 | QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
||
12548 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
||
12549 | BinaryOperatorKind Opc); |
||
12550 | QualType CheckLogicalOperands( // C99 6.5.[13,14] |
||
12551 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
||
12552 | BinaryOperatorKind Opc); |
||
12553 | // CheckAssignmentOperands is used for both simple and compound assignment. |
||
12554 | // For simple assignment, pass both expressions and a null converted type. |
||
12555 | // For compound assignment, pass both expressions and the converted type. |
||
12556 | QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] |
||
12557 | Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType, |
||
12558 | BinaryOperatorKind Opc); |
||
12559 | |||
12560 | ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc, |
||
12561 | UnaryOperatorKind Opcode, Expr *Op); |
||
12562 | ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc, |
||
12563 | BinaryOperatorKind Opcode, |
||
12564 | Expr *LHS, Expr *RHS); |
||
12565 | ExprResult checkPseudoObjectRValue(Expr *E); |
||
12566 | Expr *recreateSyntacticForm(PseudoObjectExpr *E); |
||
12567 | |||
12568 | QualType CheckConditionalOperands( // C99 6.5.15 |
||
12569 | ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, |
||
12570 | ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc); |
||
12571 | QualType CXXCheckConditionalOperands( // C++ 5.16 |
||
12572 | ExprResult &cond, ExprResult &lhs, ExprResult &rhs, |
||
12573 | ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); |
||
12574 | QualType CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS, |
||
12575 | ExprResult &RHS, |
||
12576 | SourceLocation QuestionLoc); |
||
12577 | |||
12578 | QualType CheckSizelessVectorConditionalTypes(ExprResult &Cond, |
||
12579 | ExprResult &LHS, ExprResult &RHS, |
||
12580 | SourceLocation QuestionLoc); |
||
12581 | QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, |
||
12582 | bool ConvertArgs = true); |
||
12583 | QualType FindCompositePointerType(SourceLocation Loc, |
||
12584 | ExprResult &E1, ExprResult &E2, |
||
12585 | bool ConvertArgs = true) { |
||
12586 | Expr *E1Tmp = E1.get(), *E2Tmp = E2.get(); |
||
12587 | QualType Composite = |
||
12588 | FindCompositePointerType(Loc, E1Tmp, E2Tmp, ConvertArgs); |
||
12589 | E1 = E1Tmp; |
||
12590 | E2 = E2Tmp; |
||
12591 | return Composite; |
||
12592 | } |
||
12593 | |||
12594 | QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, |
||
12595 | SourceLocation QuestionLoc); |
||
12596 | |||
12597 | bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr, |
||
12598 | SourceLocation QuestionLoc); |
||
12599 | |||
12600 | void DiagnoseAlwaysNonNullPointer(Expr *E, |
||
12601 | Expr::NullPointerConstantKind NullType, |
||
12602 | bool IsEqual, SourceRange Range); |
||
12603 | |||
12604 | /// type checking for vector binary operators. |
||
12605 | QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS, |
||
12606 | SourceLocation Loc, bool IsCompAssign, |
||
12607 | bool AllowBothBool, bool AllowBoolConversion, |
||
12608 | bool AllowBoolOperation, bool ReportInvalid); |
||
12609 | QualType GetSignedVectorType(QualType V); |
||
12610 | QualType GetSignedSizelessVectorType(QualType V); |
||
12611 | QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, |
||
12612 | SourceLocation Loc, |
||
12613 | BinaryOperatorKind Opc); |
||
12614 | QualType CheckSizelessVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, |
||
12615 | SourceLocation Loc, |
||
12616 | BinaryOperatorKind Opc); |
||
12617 | QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, |
||
12618 | SourceLocation Loc); |
||
12619 | |||
12620 | // type checking for sizeless vector binary operators. |
||
12621 | QualType CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS, |
||
12622 | SourceLocation Loc, bool IsCompAssign, |
||
12623 | ArithConvKind OperationKind); |
||
12624 | |||
12625 | /// Type checking for matrix binary operators. |
||
12626 | QualType CheckMatrixElementwiseOperands(ExprResult &LHS, ExprResult &RHS, |
||
12627 | SourceLocation Loc, |
||
12628 | bool IsCompAssign); |
||
12629 | QualType CheckMatrixMultiplyOperands(ExprResult &LHS, ExprResult &RHS, |
||
12630 | SourceLocation Loc, bool IsCompAssign); |
||
12631 | |||
12632 | bool isValidSveBitcast(QualType srcType, QualType destType); |
||
12633 | |||
12634 | bool areMatrixTypesOfTheSameDimension(QualType srcTy, QualType destTy); |
||
12635 | |||
12636 | bool areVectorTypesSameSize(QualType srcType, QualType destType); |
||
12637 | bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType); |
||
12638 | bool isLaxVectorConversion(QualType srcType, QualType destType); |
||
12639 | bool areSameVectorElemTypes(QualType srcType, QualType destType); |
||
12640 | bool anyAltivecTypes(QualType srcType, QualType destType); |
||
12641 | |||
12642 | /// type checking declaration initializers (C99 6.7.8) |
||
12643 | bool CheckForConstantInitializer(Expr *e, QualType t); |
||
12644 | |||
12645 | // type checking C++ declaration initializers (C++ [dcl.init]). |
||
12646 | |||
12647 | /// ReferenceCompareResult - Expresses the result of comparing two |
||
12648 | /// types (cv1 T1 and cv2 T2) to determine their compatibility for the |
||
12649 | /// purposes of initialization by reference (C++ [dcl.init.ref]p4). |
||
12650 | enum ReferenceCompareResult { |
||
12651 | /// Ref_Incompatible - The two types are incompatible, so direct |
||
12652 | /// reference binding is not possible. |
||
12653 | Ref_Incompatible = 0, |
||
12654 | /// Ref_Related - The two types are reference-related, which means |
||
12655 | /// that their unqualified forms (T1 and T2) are either the same |
||
12656 | /// or T1 is a base class of T2. |
||
12657 | Ref_Related, |
||
12658 | /// Ref_Compatible - The two types are reference-compatible. |
||
12659 | Ref_Compatible |
||
12660 | }; |
||
12661 | |||
12662 | // Fake up a scoped enumeration that still contextually converts to bool. |
||
12663 | struct ReferenceConversionsScope { |
||
12664 | /// The conversions that would be performed on an lvalue of type T2 when |
||
12665 | /// binding a reference of type T1 to it, as determined when evaluating |
||
12666 | /// whether T1 is reference-compatible with T2. |
||
12667 | enum ReferenceConversions { |
||
12668 | Qualification = 0x1, |
||
12669 | NestedQualification = 0x2, |
||
12670 | Function = 0x4, |
||
12671 | DerivedToBase = 0x8, |
||
12672 | ObjC = 0x10, |
||
12673 | ObjCLifetime = 0x20, |
||
12674 | |||
12675 | LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/ObjCLifetime) |
||
12676 | }; |
||
12677 | }; |
||
12678 | using ReferenceConversions = ReferenceConversionsScope::ReferenceConversions; |
||
12679 | |||
12680 | ReferenceCompareResult |
||
12681 | CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2, |
||
12682 | ReferenceConversions *Conv = nullptr); |
||
12683 | |||
12684 | ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, |
||
12685 | Expr *CastExpr, CastKind &CastKind, |
||
12686 | ExprValueKind &VK, CXXCastPath &Path); |
||
12687 | |||
12688 | /// Force an expression with unknown-type to an expression of the |
||
12689 | /// given type. |
||
12690 | ExprResult forceUnknownAnyToType(Expr *E, QualType ToType); |
||
12691 | |||
12692 | /// Type-check an expression that's being passed to an |
||
12693 | /// __unknown_anytype parameter. |
||
12694 | ExprResult checkUnknownAnyArg(SourceLocation callLoc, |
||
12695 | Expr *result, QualType ¶mType); |
||
12696 | |||
12697 | // CheckMatrixCast - Check type constraints for matrix casts. |
||
12698 | // We allow casting between matrixes of the same dimensions i.e. when they |
||
12699 | // have the same number of rows and column. Returns true if the cast is |
||
12700 | // invalid. |
||
12701 | bool CheckMatrixCast(SourceRange R, QualType DestTy, QualType SrcTy, |
||
12702 | CastKind &Kind); |
||
12703 | |||
12704 | // CheckVectorCast - check type constraints for vectors. |
||
12705 | // Since vectors are an extension, there are no C standard reference for this. |
||
12706 | // We allow casting between vectors and integer datatypes of the same size. |
||
12707 | // returns true if the cast is invalid |
||
12708 | bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, |
||
12709 | CastKind &Kind); |
||
12710 | |||
12711 | /// Prepare `SplattedExpr` for a vector splat operation, adding |
||
12712 | /// implicit casts if necessary. |
||
12713 | ExprResult prepareVectorSplat(QualType VectorTy, Expr *SplattedExpr); |
||
12714 | |||
12715 | // CheckExtVectorCast - check type constraints for extended vectors. |
||
12716 | // Since vectors are an extension, there are no C standard reference for this. |
||
12717 | // We allow casting between vectors and integer datatypes of the same size, |
||
12718 | // or vectors and the element type of that vector. |
||
12719 | // returns the cast expr |
||
12720 | ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr, |
||
12721 | CastKind &Kind); |
||
12722 | |||
12723 | ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, QualType Type, |
||
12724 | SourceLocation LParenLoc, |
||
12725 | Expr *CastExpr, |
||
12726 | SourceLocation RParenLoc); |
||
12727 | |||
12728 | enum ARCConversionResult { ACR_okay, ACR_unbridged, ACR_error }; |
||
12729 | |||
12730 | /// Checks for invalid conversions and casts between |
||
12731 | /// retainable pointers and other pointer kinds for ARC and Weak. |
||
12732 | ARCConversionResult CheckObjCConversion(SourceRange castRange, |
||
12733 | QualType castType, Expr *&op, |
||
12734 | CheckedConversionKind CCK, |
||
12735 | bool Diagnose = true, |
||
12736 | bool DiagnoseCFAudited = false, |
||
12737 | BinaryOperatorKind Opc = BO_PtrMemD |
||
12738 | ); |
||
12739 | |||
12740 | Expr *stripARCUnbridgedCast(Expr *e); |
||
12741 | void diagnoseARCUnbridgedCast(Expr *e); |
||
12742 | |||
12743 | bool CheckObjCARCUnavailableWeakConversion(QualType castType, |
||
12744 | QualType ExprType); |
||
12745 | |||
12746 | /// checkRetainCycles - Check whether an Objective-C message send |
||
12747 | /// might create an obvious retain cycle. |
||
12748 | void checkRetainCycles(ObjCMessageExpr *msg); |
||
12749 | void checkRetainCycles(Expr *receiver, Expr *argument); |
||
12750 | void checkRetainCycles(VarDecl *Var, Expr *Init); |
||
12751 | |||
12752 | /// checkUnsafeAssigns - Check whether +1 expr is being assigned |
||
12753 | /// to weak/__unsafe_unretained type. |
||
12754 | bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); |
||
12755 | |||
12756 | /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned |
||
12757 | /// to weak/__unsafe_unretained expression. |
||
12758 | void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); |
||
12759 | |||
12760 | /// CheckMessageArgumentTypes - Check types in an Obj-C message send. |
||
12761 | /// \param Method - May be null. |
||
12762 | /// \param [out] ReturnType - The return type of the send. |
||
12763 | /// \return true iff there were any incompatible types. |
||
12764 | bool CheckMessageArgumentTypes(const Expr *Receiver, QualType ReceiverType, |
||
12765 | MultiExprArg Args, Selector Sel, |
||
12766 | ArrayRef<SourceLocation> SelectorLocs, |
||
12767 | ObjCMethodDecl *Method, bool isClassMessage, |
||
12768 | bool isSuperMessage, SourceLocation lbrac, |
||
12769 | SourceLocation rbrac, SourceRange RecRange, |
||
12770 | QualType &ReturnType, ExprValueKind &VK); |
||
12771 | |||
12772 | /// Determine the result of a message send expression based on |
||
12773 | /// the type of the receiver, the method expected to receive the message, |
||
12774 | /// and the form of the message send. |
||
12775 | QualType getMessageSendResultType(const Expr *Receiver, QualType ReceiverType, |
||
12776 | ObjCMethodDecl *Method, bool isClassMessage, |
||
12777 | bool isSuperMessage); |
||
12778 | |||
12779 | /// If the given expression involves a message send to a method |
||
12780 | /// with a related result type, emit a note describing what happened. |
||
12781 | void EmitRelatedResultTypeNote(const Expr *E); |
||
12782 | |||
12783 | /// Given that we had incompatible pointer types in a return |
||
12784 | /// statement, check whether we're in a method with a related result |
||
12785 | /// type, and if so, emit a note describing what happened. |
||
12786 | void EmitRelatedResultTypeNoteForReturn(QualType destType); |
||
12787 | |||
12788 | class ConditionResult { |
||
12789 | Decl *ConditionVar; |
||
12790 | FullExprArg Condition; |
||
12791 | bool Invalid; |
||
12792 | bool HasKnownValue; |
||
12793 | bool KnownValue; |
||
12794 | |||
12795 | friend class Sema; |
||
12796 | ConditionResult(Sema &S, Decl *ConditionVar, FullExprArg Condition, |
||
12797 | bool IsConstexpr) |
||
12798 | : ConditionVar(ConditionVar), Condition(Condition), Invalid(false), |
||
12799 | HasKnownValue(IsConstexpr && Condition.get() && |
||
12800 | !Condition.get()->isValueDependent()), |
||
12801 | KnownValue(HasKnownValue && |
||
12802 | !!Condition.get()->EvaluateKnownConstInt(S.Context)) {} |
||
12803 | explicit ConditionResult(bool Invalid) |
||
12804 | : ConditionVar(nullptr), Condition(nullptr), Invalid(Invalid), |
||
12805 | HasKnownValue(false), KnownValue(false) {} |
||
12806 | |||
12807 | public: |
||
12808 | ConditionResult() : ConditionResult(false) {} |
||
12809 | bool isInvalid() const { return Invalid; } |
||
12810 | std::pair<VarDecl *, Expr *> get() const { |
||
12811 | return std::make_pair(cast_or_null<VarDecl>(ConditionVar), |
||
12812 | Condition.get()); |
||
12813 | } |
||
12814 | std::optional<bool> getKnownValue() const { |
||
12815 | if (!HasKnownValue) |
||
12816 | return std::nullopt; |
||
12817 | return KnownValue; |
||
12818 | } |
||
12819 | }; |
||
12820 | static ConditionResult ConditionError() { return ConditionResult(true); } |
||
12821 | |||
12822 | enum class ConditionKind { |
||
12823 | Boolean, ///< A boolean condition, from 'if', 'while', 'for', or 'do'. |
||
12824 | ConstexprIf, ///< A constant boolean condition from 'if constexpr'. |
||
12825 | Switch ///< An integral condition for a 'switch' statement. |
||
12826 | }; |
||
12827 | QualType PreferredConditionType(ConditionKind K) const { |
||
12828 | return K == ConditionKind::Switch ? Context.IntTy : Context.BoolTy; |
||
12829 | } |
||
12830 | |||
12831 | ConditionResult ActOnCondition(Scope *S, SourceLocation Loc, Expr *SubExpr, |
||
12832 | ConditionKind CK, bool MissingOK = false); |
||
12833 | |||
12834 | ConditionResult ActOnConditionVariable(Decl *ConditionVar, |
||
12835 | SourceLocation StmtLoc, |
||
12836 | ConditionKind CK); |
||
12837 | |||
12838 | DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); |
||
12839 | |||
12840 | ExprResult CheckConditionVariable(VarDecl *ConditionVar, |
||
12841 | SourceLocation StmtLoc, |
||
12842 | ConditionKind CK); |
||
12843 | ExprResult CheckSwitchCondition(SourceLocation SwitchLoc, Expr *Cond); |
||
12844 | |||
12845 | /// CheckBooleanCondition - Diagnose problems involving the use of |
||
12846 | /// the given expression as a boolean condition (e.g. in an if |
||
12847 | /// statement). Also performs the standard function and array |
||
12848 | /// decays, possibly changing the input variable. |
||
12849 | /// |
||
12850 | /// \param Loc - A location associated with the condition, e.g. the |
||
12851 | /// 'if' keyword. |
||
12852 | /// \return true iff there were any errors |
||
12853 | ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E, |
||
12854 | bool IsConstexpr = false); |
||
12855 | |||
12856 | /// ActOnExplicitBoolSpecifier - Build an ExplicitSpecifier from an expression |
||
12857 | /// found in an explicit(bool) specifier. |
||
12858 | ExplicitSpecifier ActOnExplicitBoolSpecifier(Expr *E); |
||
12859 | |||
12860 | /// tryResolveExplicitSpecifier - Attempt to resolve the explict specifier. |
||
12861 | /// Returns true if the explicit specifier is now resolved. |
||
12862 | bool tryResolveExplicitSpecifier(ExplicitSpecifier &ExplicitSpec); |
||
12863 | |||
12864 | /// DiagnoseAssignmentAsCondition - Given that an expression is |
||
12865 | /// being used as a boolean condition, warn if it's an assignment. |
||
12866 | void DiagnoseAssignmentAsCondition(Expr *E); |
||
12867 | |||
12868 | /// Redundant parentheses over an equality comparison can indicate |
||
12869 | /// that the user intended an assignment used as condition. |
||
12870 | void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE); |
||
12871 | |||
12872 | /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. |
||
12873 | ExprResult CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr = false); |
||
12874 | |||
12875 | /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have |
||
12876 | /// the specified width and sign. If an overflow occurs, detect it and emit |
||
12877 | /// the specified diagnostic. |
||
12878 | void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, |
||
12879 | unsigned NewWidth, bool NewSign, |
||
12880 | SourceLocation Loc, unsigned DiagID); |
||
12881 | |||
12882 | /// Checks that the Objective-C declaration is declared in the global scope. |
||
12883 | /// Emits an error and marks the declaration as invalid if it's not declared |
||
12884 | /// in the global scope. |
||
12885 | bool CheckObjCDeclScope(Decl *D); |
||
12886 | |||
12887 | /// Abstract base class used for diagnosing integer constant |
||
12888 | /// expression violations. |
||
12889 | class VerifyICEDiagnoser { |
||
12890 | public: |
||
12891 | bool Suppress; |
||
12892 | |||
12893 | VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) { } |
||
12894 | |||
12895 | virtual SemaDiagnosticBuilder |
||
12896 | diagnoseNotICEType(Sema &S, SourceLocation Loc, QualType T); |
||
12897 | virtual SemaDiagnosticBuilder diagnoseNotICE(Sema &S, |
||
12898 | SourceLocation Loc) = 0; |
||
12899 | virtual SemaDiagnosticBuilder diagnoseFold(Sema &S, SourceLocation Loc); |
||
12900 | virtual ~VerifyICEDiagnoser() {} |
||
12901 | }; |
||
12902 | |||
12903 | enum AllowFoldKind { |
||
12904 | NoFold, |
||
12905 | AllowFold, |
||
12906 | }; |
||
12907 | |||
12908 | /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE, |
||
12909 | /// and reports the appropriate diagnostics. Returns false on success. |
||
12910 | /// Can optionally return the value of the expression. |
||
12911 | ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
||
12912 | VerifyICEDiagnoser &Diagnoser, |
||
12913 | AllowFoldKind CanFold = NoFold); |
||
12914 | ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
||
12915 | unsigned DiagID, |
||
12916 | AllowFoldKind CanFold = NoFold); |
||
12917 | ExprResult VerifyIntegerConstantExpression(Expr *E, |
||
12918 | llvm::APSInt *Result = nullptr, |
||
12919 | AllowFoldKind CanFold = NoFold); |
||
12920 | ExprResult VerifyIntegerConstantExpression(Expr *E, |
||
12921 | AllowFoldKind CanFold = NoFold) { |
||
12922 | return VerifyIntegerConstantExpression(E, nullptr, CanFold); |
||
12923 | } |
||
12924 | |||
12925 | /// VerifyBitField - verifies that a bit field expression is an ICE and has |
||
12926 | /// the correct width, and that the field type is valid. |
||
12927 | /// Returns false on success. |
||
12928 | ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, |
||
12929 | QualType FieldTy, bool IsMsStruct, Expr *BitWidth); |
||
12930 | |||
12931 | private: |
||
12932 | unsigned ForceCUDAHostDeviceDepth = 0; |
||
12933 | |||
12934 | public: |
||
12935 | /// Increments our count of the number of times we've seen a pragma forcing |
||
12936 | /// functions to be __host__ __device__. So long as this count is greater |
||
12937 | /// than zero, all functions encountered will be __host__ __device__. |
||
12938 | void PushForceCUDAHostDevice(); |
||
12939 | |||
12940 | /// Decrements our count of the number of times we've seen a pragma forcing |
||
12941 | /// functions to be __host__ __device__. Returns false if the count is 0 |
||
12942 | /// before incrementing, so you can emit an error. |
||
12943 | bool PopForceCUDAHostDevice(); |
||
12944 | |||
12945 | /// Diagnostics that are emitted only if we discover that the given function |
||
12946 | /// must be codegen'ed. Because handling these correctly adds overhead to |
||
12947 | /// compilation, this is currently only enabled for CUDA compilations. |
||
12948 | llvm::DenseMap<CanonicalDeclPtr<FunctionDecl>, |
||
12949 | std::vector<PartialDiagnosticAt>> |
||
12950 | DeviceDeferredDiags; |
||
12951 | |||
12952 | /// A pair of a canonical FunctionDecl and a SourceLocation. When used as the |
||
12953 | /// key in a hashtable, both the FD and location are hashed. |
||
12954 | struct FunctionDeclAndLoc { |
||
12955 | CanonicalDeclPtr<FunctionDecl> FD; |
||
12956 | SourceLocation Loc; |
||
12957 | }; |
||
12958 | |||
12959 | /// FunctionDecls and SourceLocations for which CheckCUDACall has emitted a |
||
12960 | /// (maybe deferred) "bad call" diagnostic. We use this to avoid emitting the |
||
12961 | /// same deferred diag twice. |
||
12962 | llvm::DenseSet<FunctionDeclAndLoc> LocsWithCUDACallDiags; |
||
12963 | |||
12964 | /// An inverse call graph, mapping known-emitted functions to one of their |
||
12965 | /// known-emitted callers (plus the location of the call). |
||
12966 | /// |
||
12967 | /// Functions that we can tell a priori must be emitted aren't added to this |
||
12968 | /// map. |
||
12969 | llvm::DenseMap</* Callee = */ CanonicalDeclPtr<FunctionDecl>, |
||
12970 | /* Caller = */ FunctionDeclAndLoc> |
||
12971 | DeviceKnownEmittedFns; |
||
12972 | |||
12973 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
||
12974 | /// context is "used as device code". |
||
12975 | /// |
||
12976 | /// - If CurContext is a __host__ function, does not emit any diagnostics |
||
12977 | /// unless \p EmitOnBothSides is true. |
||
12978 | /// - If CurContext is a __device__ or __global__ function, emits the |
||
12979 | /// diagnostics immediately. |
||
12980 | /// - If CurContext is a __host__ __device__ function and we are compiling for |
||
12981 | /// the device, creates a diagnostic which is emitted if and when we realize |
||
12982 | /// that the function will be codegen'ed. |
||
12983 | /// |
||
12984 | /// Example usage: |
||
12985 | /// |
||
12986 | /// // Variable-length arrays are not allowed in CUDA device code. |
||
12987 | /// if (CUDADiagIfDeviceCode(Loc, diag::err_cuda_vla) << CurrentCUDATarget()) |
||
12988 | /// return ExprError(); |
||
12989 | /// // Otherwise, continue parsing as normal. |
||
12990 | SemaDiagnosticBuilder CUDADiagIfDeviceCode(SourceLocation Loc, |
||
12991 | unsigned DiagID); |
||
12992 | |||
12993 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
||
12994 | /// context is "used as host code". |
||
12995 | /// |
||
12996 | /// Same as CUDADiagIfDeviceCode, with "host" and "device" switched. |
||
12997 | SemaDiagnosticBuilder CUDADiagIfHostCode(SourceLocation Loc, unsigned DiagID); |
||
12998 | |||
12999 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
||
13000 | /// context is "used as device code". |
||
13001 | /// |
||
13002 | /// - If CurContext is a `declare target` function or it is known that the |
||
13003 | /// function is emitted for the device, emits the diagnostics immediately. |
||
13004 | /// - If CurContext is a non-`declare target` function and we are compiling |
||
13005 | /// for the device, creates a diagnostic which is emitted if and when we |
||
13006 | /// realize that the function will be codegen'ed. |
||
13007 | /// |
||
13008 | /// Example usage: |
||
13009 | /// |
||
13010 | /// // Variable-length arrays are not allowed in NVPTX device code. |
||
13011 | /// if (diagIfOpenMPDeviceCode(Loc, diag::err_vla_unsupported)) |
||
13012 | /// return ExprError(); |
||
13013 | /// // Otherwise, continue parsing as normal. |
||
13014 | SemaDiagnosticBuilder |
||
13015 | diagIfOpenMPDeviceCode(SourceLocation Loc, unsigned DiagID, FunctionDecl *FD); |
||
13016 | |||
13017 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
||
13018 | /// context is "used as host code". |
||
13019 | /// |
||
13020 | /// - If CurContext is a `declare target` function or it is known that the |
||
13021 | /// function is emitted for the host, emits the diagnostics immediately. |
||
13022 | /// - If CurContext is a non-host function, just ignore it. |
||
13023 | /// |
||
13024 | /// Example usage: |
||
13025 | /// |
||
13026 | /// // Variable-length arrays are not allowed in NVPTX device code. |
||
13027 | /// if (diagIfOpenMPHostode(Loc, diag::err_vla_unsupported)) |
||
13028 | /// return ExprError(); |
||
13029 | /// // Otherwise, continue parsing as normal. |
||
13030 | SemaDiagnosticBuilder diagIfOpenMPHostCode(SourceLocation Loc, |
||
13031 | unsigned DiagID, FunctionDecl *FD); |
||
13032 | |||
13033 | SemaDiagnosticBuilder targetDiag(SourceLocation Loc, unsigned DiagID, |
||
13034 | FunctionDecl *FD = nullptr); |
||
13035 | SemaDiagnosticBuilder targetDiag(SourceLocation Loc, |
||
13036 | const PartialDiagnostic &PD, |
||
13037 | FunctionDecl *FD = nullptr) { |
||
13038 | return targetDiag(Loc, PD.getDiagID(), FD) << PD; |
||
13039 | } |
||
13040 | |||
13041 | /// Check if the type is allowed to be used for the current target. |
||
13042 | void checkTypeSupport(QualType Ty, SourceLocation Loc, |
||
13043 | ValueDecl *D = nullptr); |
||
13044 | |||
13045 | enum CUDAFunctionTarget { |
||
13046 | CFT_Device, |
||
13047 | CFT_Global, |
||
13048 | CFT_Host, |
||
13049 | CFT_HostDevice, |
||
13050 | CFT_InvalidTarget |
||
13051 | }; |
||
13052 | |||
13053 | /// Determines whether the given function is a CUDA device/host/kernel/etc. |
||
13054 | /// function. |
||
13055 | /// |
||
13056 | /// Use this rather than examining the function's attributes yourself -- you |
||
13057 | /// will get it wrong. Returns CFT_Host if D is null. |
||
13058 | CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D, |
||
13059 | bool IgnoreImplicitHDAttr = false); |
||
13060 | CUDAFunctionTarget IdentifyCUDATarget(const ParsedAttributesView &Attrs); |
||
13061 | |||
13062 | enum CUDAVariableTarget { |
||
13063 | CVT_Device, /// Emitted on device side with a shadow variable on host side |
||
13064 | CVT_Host, /// Emitted on host side only |
||
13065 | CVT_Both, /// Emitted on both sides with different addresses |
||
13066 | CVT_Unified, /// Emitted as a unified address, e.g. managed variables |
||
13067 | }; |
||
13068 | /// Determines whether the given variable is emitted on host or device side. |
||
13069 | CUDAVariableTarget IdentifyCUDATarget(const VarDecl *D); |
||
13070 | |||
13071 | /// Gets the CUDA target for the current context. |
||
13072 | CUDAFunctionTarget CurrentCUDATarget() { |
||
13073 | return IdentifyCUDATarget(dyn_cast<FunctionDecl>(CurContext)); |
||
13074 | } |
||
13075 | |||
13076 | static bool isCUDAImplicitHostDeviceFunction(const FunctionDecl *D); |
||
13077 | |||
13078 | // CUDA function call preference. Must be ordered numerically from |
||
13079 | // worst to best. |
||
13080 | enum CUDAFunctionPreference { |
||
13081 | CFP_Never, // Invalid caller/callee combination. |
||
13082 | CFP_WrongSide, // Calls from host-device to host or device |
||
13083 | // function that do not match current compilation |
||
13084 | // mode. |
||
13085 | CFP_HostDevice, // Any calls to host/device functions. |
||
13086 | CFP_SameSide, // Calls from host-device to host or device |
||
13087 | // function matching current compilation mode. |
||
13088 | CFP_Native, // host-to-host or device-to-device calls. |
||
13089 | }; |
||
13090 | |||
13091 | /// Identifies relative preference of a given Caller/Callee |
||
13092 | /// combination, based on their host/device attributes. |
||
13093 | /// \param Caller function which needs address of \p Callee. |
||
13094 | /// nullptr in case of global context. |
||
13095 | /// \param Callee target function |
||
13096 | /// |
||
13097 | /// \returns preference value for particular Caller/Callee combination. |
||
13098 | CUDAFunctionPreference IdentifyCUDAPreference(const FunctionDecl *Caller, |
||
13099 | const FunctionDecl *Callee); |
||
13100 | |||
13101 | /// Determines whether Caller may invoke Callee, based on their CUDA |
||
13102 | /// host/device attributes. Returns false if the call is not allowed. |
||
13103 | /// |
||
13104 | /// Note: Will return true for CFP_WrongSide calls. These may appear in |
||
13105 | /// semantically correct CUDA programs, but only if they're never codegen'ed. |
||
13106 | bool IsAllowedCUDACall(const FunctionDecl *Caller, |
||
13107 | const FunctionDecl *Callee) { |
||
13108 | return IdentifyCUDAPreference(Caller, Callee) != CFP_Never; |
||
13109 | } |
||
13110 | |||
13111 | /// May add implicit CUDAHostAttr and CUDADeviceAttr attributes to FD, |
||
13112 | /// depending on FD and the current compilation settings. |
||
13113 | void maybeAddCUDAHostDeviceAttrs(FunctionDecl *FD, |
||
13114 | const LookupResult &Previous); |
||
13115 | |||
13116 | /// May add implicit CUDAConstantAttr attribute to VD, depending on VD |
||
13117 | /// and current compilation settings. |
||
13118 | void MaybeAddCUDAConstantAttr(VarDecl *VD); |
||
13119 | |||
13120 | public: |
||
13121 | /// Check whether we're allowed to call Callee from the current context. |
||
13122 | /// |
||
13123 | /// - If the call is never allowed in a semantically-correct program |
||
13124 | /// (CFP_Never), emits an error and returns false. |
||
13125 | /// |
||
13126 | /// - If the call is allowed in semantically-correct programs, but only if |
||
13127 | /// it's never codegen'ed (CFP_WrongSide), creates a deferred diagnostic to |
||
13128 | /// be emitted if and when the caller is codegen'ed, and returns true. |
||
13129 | /// |
||
13130 | /// Will only create deferred diagnostics for a given SourceLocation once, |
||
13131 | /// so you can safely call this multiple times without generating duplicate |
||
13132 | /// deferred errors. |
||
13133 | /// |
||
13134 | /// - Otherwise, returns true without emitting any diagnostics. |
||
13135 | bool CheckCUDACall(SourceLocation Loc, FunctionDecl *Callee); |
||
13136 | |||
13137 | void CUDACheckLambdaCapture(CXXMethodDecl *D, const sema::Capture &Capture); |
||
13138 | |||
13139 | /// Set __device__ or __host__ __device__ attributes on the given lambda |
||
13140 | /// operator() method. |
||
13141 | /// |
||
13142 | /// CUDA lambdas by default is host device function unless it has explicit |
||
13143 | /// host or device attribute. |
||
13144 | void CUDASetLambdaAttrs(CXXMethodDecl *Method); |
||
13145 | |||
13146 | /// Finds a function in \p Matches with highest calling priority |
||
13147 | /// from \p Caller context and erases all functions with lower |
||
13148 | /// calling priority. |
||
13149 | void EraseUnwantedCUDAMatches( |
||
13150 | const FunctionDecl *Caller, |
||
13151 | SmallVectorImpl<std::pair<DeclAccessPair, FunctionDecl *>> &Matches); |
||
13152 | |||
13153 | /// Given a implicit special member, infer its CUDA target from the |
||
13154 | /// calls it needs to make to underlying base/field special members. |
||
13155 | /// \param ClassDecl the class for which the member is being created. |
||
13156 | /// \param CSM the kind of special member. |
||
13157 | /// \param MemberDecl the special member itself. |
||
13158 | /// \param ConstRHS true if this is a copy operation with a const object on |
||
13159 | /// its RHS. |
||
13160 | /// \param Diagnose true if this call should emit diagnostics. |
||
13161 | /// \return true if there was an error inferring. |
||
13162 | /// The result of this call is implicit CUDA target attribute(s) attached to |
||
13163 | /// the member declaration. |
||
13164 | bool inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl, |
||
13165 | CXXSpecialMember CSM, |
||
13166 | CXXMethodDecl *MemberDecl, |
||
13167 | bool ConstRHS, |
||
13168 | bool Diagnose); |
||
13169 | |||
13170 | /// \return true if \p CD can be considered empty according to CUDA |
||
13171 | /// (E.2.3.1 in CUDA 7.5 Programming guide). |
||
13172 | bool isEmptyCudaConstructor(SourceLocation Loc, CXXConstructorDecl *CD); |
||
13173 | bool isEmptyCudaDestructor(SourceLocation Loc, CXXDestructorDecl *CD); |
||
13174 | |||
13175 | // \brief Checks that initializers of \p Var satisfy CUDA restrictions. In |
||
13176 | // case of error emits appropriate diagnostic and invalidates \p Var. |
||
13177 | // |
||
13178 | // \details CUDA allows only empty constructors as initializers for global |
||
13179 | // variables (see E.2.3.1, CUDA 7.5). The same restriction also applies to all |
||
13180 | // __shared__ variables whether they are local or not (they all are implicitly |
||
13181 | // static in CUDA). One exception is that CUDA allows constant initializers |
||
13182 | // for __constant__ and __device__ variables. |
||
13183 | void checkAllowedCUDAInitializer(VarDecl *VD); |
||
13184 | |||
13185 | /// Check whether NewFD is a valid overload for CUDA. Emits |
||
13186 | /// diagnostics and invalidates NewFD if not. |
||
13187 | void checkCUDATargetOverload(FunctionDecl *NewFD, |
||
13188 | const LookupResult &Previous); |
||
13189 | /// Copies target attributes from the template TD to the function FD. |
||
13190 | void inheritCUDATargetAttrs(FunctionDecl *FD, const FunctionTemplateDecl &TD); |
||
13191 | |||
13192 | /// Returns the name of the launch configuration function. This is the name |
||
13193 | /// of the function that will be called to configure kernel call, with the |
||
13194 | /// parameters specified via <<<>>>. |
||
13195 | std::string getCudaConfigureFuncName() const; |
||
13196 | |||
13197 | /// \name Code completion |
||
13198 | //@{ |
||
13199 | /// Describes the context in which code completion occurs. |
||
13200 | enum ParserCompletionContext { |
||
13201 | /// Code completion occurs at top-level or namespace context. |
||
13202 | PCC_Namespace, |
||
13203 | /// Code completion occurs within a class, struct, or union. |
||
13204 | PCC_Class, |
||
13205 | /// Code completion occurs within an Objective-C interface, protocol, |
||
13206 | /// or category. |
||
13207 | PCC_ObjCInterface, |
||
13208 | /// Code completion occurs within an Objective-C implementation or |
||
13209 | /// category implementation |
||
13210 | PCC_ObjCImplementation, |
||
13211 | /// Code completion occurs within the list of instance variables |
||
13212 | /// in an Objective-C interface, protocol, category, or implementation. |
||
13213 | PCC_ObjCInstanceVariableList, |
||
13214 | /// Code completion occurs following one or more template |
||
13215 | /// headers. |
||
13216 | PCC_Template, |
||
13217 | /// Code completion occurs following one or more template |
||
13218 | /// headers within a class. |
||
13219 | PCC_MemberTemplate, |
||
13220 | /// Code completion occurs within an expression. |
||
13221 | PCC_Expression, |
||
13222 | /// Code completion occurs within a statement, which may |
||
13223 | /// also be an expression or a declaration. |
||
13224 | PCC_Statement, |
||
13225 | /// Code completion occurs at the beginning of the |
||
13226 | /// initialization statement (or expression) in a for loop. |
||
13227 | PCC_ForInit, |
||
13228 | /// Code completion occurs within the condition of an if, |
||
13229 | /// while, switch, or for statement. |
||
13230 | PCC_Condition, |
||
13231 | /// Code completion occurs within the body of a function on a |
||
13232 | /// recovery path, where we do not have a specific handle on our position |
||
13233 | /// in the grammar. |
||
13234 | PCC_RecoveryInFunction, |
||
13235 | /// Code completion occurs where only a type is permitted. |
||
13236 | PCC_Type, |
||
13237 | /// Code completion occurs in a parenthesized expression, which |
||
13238 | /// might also be a type cast. |
||
13239 | PCC_ParenthesizedExpression, |
||
13240 | /// Code completion occurs within a sequence of declaration |
||
13241 | /// specifiers within a function, method, or block. |
||
13242 | PCC_LocalDeclarationSpecifiers |
||
13243 | }; |
||
13244 | |||
13245 | void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path); |
||
13246 | void CodeCompleteOrdinaryName(Scope *S, |
||
13247 | ParserCompletionContext CompletionContext); |
||
13248 | void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, |
||
13249 | bool AllowNonIdentifiers, |
||
13250 | bool AllowNestedNameSpecifiers); |
||
13251 | |||
13252 | struct CodeCompleteExpressionData; |
||
13253 | void CodeCompleteExpression(Scope *S, |
||
13254 | const CodeCompleteExpressionData &Data); |
||
13255 | void CodeCompleteExpression(Scope *S, QualType PreferredType, |
||
13256 | bool IsParenthesized = false); |
||
13257 | void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase, |
||
13258 | SourceLocation OpLoc, bool IsArrow, |
||
13259 | bool IsBaseExprStatement, |
||
13260 | QualType PreferredType); |
||
13261 | void CodeCompletePostfixExpression(Scope *S, ExprResult LHS, |
||
13262 | QualType PreferredType); |
||
13263 | void CodeCompleteTag(Scope *S, unsigned TagSpec); |
||
13264 | void CodeCompleteTypeQualifiers(DeclSpec &DS); |
||
13265 | void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D, |
||
13266 | const VirtSpecifiers *VS = nullptr); |
||
13267 | void CodeCompleteBracketDeclarator(Scope *S); |
||
13268 | void CodeCompleteCase(Scope *S); |
||
13269 | enum class AttributeCompletion { |
||
13270 | Attribute, |
||
13271 | Scope, |
||
13272 | None, |
||
13273 | }; |
||
13274 | void CodeCompleteAttribute( |
||
13275 | AttributeCommonInfo::Syntax Syntax, |
||
13276 | AttributeCompletion Completion = AttributeCompletion::Attribute, |
||
13277 | const IdentifierInfo *Scope = nullptr); |
||
13278 | /// Determines the preferred type of the current function argument, by |
||
13279 | /// examining the signatures of all possible overloads. |
||
13280 | /// Returns null if unknown or ambiguous, or if code completion is off. |
||
13281 | /// |
||
13282 | /// If the code completion point has been reached, also reports the function |
||
13283 | /// signatures that were considered. |
||
13284 | /// |
||
13285 | /// FIXME: rename to GuessCallArgumentType to reduce confusion. |
||
13286 | QualType ProduceCallSignatureHelp(Expr *Fn, ArrayRef<Expr *> Args, |
||
13287 | SourceLocation OpenParLoc); |
||
13288 | QualType ProduceConstructorSignatureHelp(QualType Type, SourceLocation Loc, |
||
13289 | ArrayRef<Expr *> Args, |
||
13290 | SourceLocation OpenParLoc, |
||
13291 | bool Braced); |
||
13292 | QualType ProduceCtorInitMemberSignatureHelp( |
||
13293 | Decl *ConstructorDecl, CXXScopeSpec SS, ParsedType TemplateTypeTy, |
||
13294 | ArrayRef<Expr *> ArgExprs, IdentifierInfo *II, SourceLocation OpenParLoc, |
||
13295 | bool Braced); |
||
13296 | QualType ProduceTemplateArgumentSignatureHelp( |
||
13297 | TemplateTy, ArrayRef<ParsedTemplateArgument>, SourceLocation LAngleLoc); |
||
13298 | void CodeCompleteInitializer(Scope *S, Decl *D); |
||
13299 | /// Trigger code completion for a record of \p BaseType. \p InitExprs are |
||
13300 | /// expressions in the initializer list seen so far and \p D is the current |
||
13301 | /// Designation being parsed. |
||
13302 | void CodeCompleteDesignator(const QualType BaseType, |
||
13303 | llvm::ArrayRef<Expr *> InitExprs, |
||
13304 | const Designation &D); |
||
13305 | void CodeCompleteAfterIf(Scope *S, bool IsBracedThen); |
||
13306 | |||
13307 | void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext, |
||
13308 | bool IsUsingDeclaration, QualType BaseType, |
||
13309 | QualType PreferredType); |
||
13310 | void CodeCompleteUsing(Scope *S); |
||
13311 | void CodeCompleteUsingDirective(Scope *S); |
||
13312 | void CodeCompleteNamespaceDecl(Scope *S); |
||
13313 | void CodeCompleteNamespaceAliasDecl(Scope *S); |
||
13314 | void CodeCompleteOperatorName(Scope *S); |
||
13315 | void CodeCompleteConstructorInitializer( |
||
13316 | Decl *Constructor, |
||
13317 | ArrayRef<CXXCtorInitializer *> Initializers); |
||
13318 | |||
13319 | void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, |
||
13320 | bool AfterAmpersand); |
||
13321 | void CodeCompleteAfterFunctionEquals(Declarator &D); |
||
13322 | |||
13323 | void CodeCompleteObjCAtDirective(Scope *S); |
||
13324 | void CodeCompleteObjCAtVisibility(Scope *S); |
||
13325 | void CodeCompleteObjCAtStatement(Scope *S); |
||
13326 | void CodeCompleteObjCAtExpression(Scope *S); |
||
13327 | void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); |
||
13328 | void CodeCompleteObjCPropertyGetter(Scope *S); |
||
13329 | void CodeCompleteObjCPropertySetter(Scope *S); |
||
13330 | void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, |
||
13331 | bool IsParameter); |
||
13332 | void CodeCompleteObjCMessageReceiver(Scope *S); |
||
13333 | void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, |
||
13334 | ArrayRef<IdentifierInfo *> SelIdents, |
||
13335 | bool AtArgumentExpression); |
||
13336 | void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, |
||
13337 | ArrayRef<IdentifierInfo *> SelIdents, |
||
13338 | bool AtArgumentExpression, |
||
13339 | bool IsSuper = false); |
||
13340 | void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, |
||
13341 | ArrayRef<IdentifierInfo *> SelIdents, |
||
13342 | bool AtArgumentExpression, |
||
13343 | ObjCInterfaceDecl *Super = nullptr); |
||
13344 | void CodeCompleteObjCForCollection(Scope *S, |
||
13345 | DeclGroupPtrTy IterationVar); |
||
13346 | void CodeCompleteObjCSelector(Scope *S, |
||
13347 | ArrayRef<IdentifierInfo *> SelIdents); |
||
13348 | void CodeCompleteObjCProtocolReferences( |
||
13349 | ArrayRef<IdentifierLocPair> Protocols); |
||
13350 | void CodeCompleteObjCProtocolDecl(Scope *S); |
||
13351 | void CodeCompleteObjCInterfaceDecl(Scope *S); |
||
13352 | void CodeCompleteObjCSuperclass(Scope *S, |
||
13353 | IdentifierInfo *ClassName, |
||
13354 | SourceLocation ClassNameLoc); |
||
13355 | void CodeCompleteObjCImplementationDecl(Scope *S); |
||
13356 | void CodeCompleteObjCInterfaceCategory(Scope *S, |
||
13357 | IdentifierInfo *ClassName, |
||
13358 | SourceLocation ClassNameLoc); |
||
13359 | void CodeCompleteObjCImplementationCategory(Scope *S, |
||
13360 | IdentifierInfo *ClassName, |
||
13361 | SourceLocation ClassNameLoc); |
||
13362 | void CodeCompleteObjCPropertyDefinition(Scope *S); |
||
13363 | void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, |
||
13364 | IdentifierInfo *PropertyName); |
||
13365 | void CodeCompleteObjCMethodDecl(Scope *S, |
||
13366 | std::optional<bool> IsInstanceMethod, |
||
13367 | ParsedType ReturnType); |
||
13368 | void CodeCompleteObjCMethodDeclSelector(Scope *S, |
||
13369 | bool IsInstanceMethod, |
||
13370 | bool AtParameterName, |
||
13371 | ParsedType ReturnType, |
||
13372 | ArrayRef<IdentifierInfo *> SelIdents); |
||
13373 | void CodeCompleteObjCClassPropertyRefExpr(Scope *S, IdentifierInfo &ClassName, |
||
13374 | SourceLocation ClassNameLoc, |
||
13375 | bool IsBaseExprStatement); |
||
13376 | void CodeCompletePreprocessorDirective(bool InConditional); |
||
13377 | void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); |
||
13378 | void CodeCompletePreprocessorMacroName(bool IsDefinition); |
||
13379 | void CodeCompletePreprocessorExpression(); |
||
13380 | void CodeCompletePreprocessorMacroArgument(Scope *S, |
||
13381 | IdentifierInfo *Macro, |
||
13382 | MacroInfo *MacroInfo, |
||
13383 | unsigned Argument); |
||
13384 | void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled); |
||
13385 | void CodeCompleteNaturalLanguage(); |
||
13386 | void CodeCompleteAvailabilityPlatformName(); |
||
13387 | void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, |
||
13388 | CodeCompletionTUInfo &CCTUInfo, |
||
13389 | SmallVectorImpl<CodeCompletionResult> &Results); |
||
13390 | //@} |
||
13391 | |||
13392 | //===--------------------------------------------------------------------===// |
||
13393 | // Extra semantic analysis beyond the C type system |
||
13394 | |||
13395 | public: |
||
13396 | SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, |
||
13397 | unsigned ByteNo) const; |
||
13398 | |||
13399 | enum FormatArgumentPassingKind { |
||
13400 | FAPK_Fixed, // values to format are fixed (no C-style variadic arguments) |
||
13401 | FAPK_Variadic, // values to format are passed as variadic arguments |
||
13402 | FAPK_VAList, // values to format are passed in a va_list |
||
13403 | }; |
||
13404 | |||
13405 | // Used to grab the relevant information from a FormatAttr and a |
||
13406 | // FunctionDeclaration. |
||
13407 | struct FormatStringInfo { |
||
13408 | unsigned FormatIdx; |
||
13409 | unsigned FirstDataArg; |
||
13410 | FormatArgumentPassingKind ArgPassingKind; |
||
13411 | }; |
||
13412 | |||
13413 | static bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember, |
||
13414 | bool IsVariadic, FormatStringInfo *FSI); |
||
13415 | |||
13416 | private: |
||
13417 | void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, |
||
13418 | const ArraySubscriptExpr *ASE = nullptr, |
||
13419 | bool AllowOnePastEnd = true, bool IndexNegated = false); |
||
13420 | void CheckArrayAccess(const Expr *E); |
||
13421 | |||
13422 | bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, |
||
13423 | const FunctionProtoType *Proto); |
||
13424 | bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc, |
||
13425 | ArrayRef<const Expr *> Args); |
||
13426 | bool CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall, |
||
13427 | const FunctionProtoType *Proto); |
||
13428 | bool CheckOtherCall(CallExpr *TheCall, const FunctionProtoType *Proto); |
||
13429 | void CheckConstructorCall(FunctionDecl *FDecl, QualType ThisType, |
||
13430 | ArrayRef<const Expr *> Args, |
||
13431 | const FunctionProtoType *Proto, SourceLocation Loc); |
||
13432 | |||
13433 | void checkAIXMemberAlignment(SourceLocation Loc, const Expr *Arg); |
||
13434 | |||
13435 | void CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl, |
||
13436 | StringRef ParamName, QualType ArgTy, QualType ParamTy); |
||
13437 | |||
13438 | void checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, |
||
13439 | const Expr *ThisArg, ArrayRef<const Expr *> Args, |
||
13440 | bool IsMemberFunction, SourceLocation Loc, SourceRange Range, |
||
13441 | VariadicCallType CallType); |
||
13442 | |||
13443 | bool CheckObjCString(Expr *Arg); |
||
13444 | ExprResult CheckOSLogFormatStringArg(Expr *Arg); |
||
13445 | |||
13446 | ExprResult CheckBuiltinFunctionCall(FunctionDecl *FDecl, |
||
13447 | unsigned BuiltinID, CallExpr *TheCall); |
||
13448 | |||
13449 | bool CheckTSBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
||
13450 | CallExpr *TheCall); |
||
13451 | |||
13452 | void checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD, CallExpr *TheCall); |
||
13453 | |||
13454 | bool CheckARMBuiltinExclusiveCall(unsigned BuiltinID, CallExpr *TheCall, |
||
13455 | unsigned MaxWidth); |
||
13456 | bool CheckNeonBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
||
13457 | CallExpr *TheCall); |
||
13458 | bool CheckMVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
||
13459 | bool CheckSVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
||
13460 | bool CheckCDEBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
||
13461 | CallExpr *TheCall); |
||
13462 | bool CheckARMCoprocessorImmediate(const TargetInfo &TI, const Expr *CoprocArg, |
||
13463 | bool WantCDE); |
||
13464 | bool CheckARMBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
||
13465 | CallExpr *TheCall); |
||
13466 | |||
13467 | bool CheckAArch64BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
||
13468 | CallExpr *TheCall); |
||
13469 | bool CheckBPFBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
||
13470 | bool CheckHexagonBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
||
13471 | bool CheckHexagonBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall); |
||
13472 | bool CheckMipsBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
||
13473 | CallExpr *TheCall); |
||
13474 | bool CheckMipsBuiltinCpu(const TargetInfo &TI, unsigned BuiltinID, |
||
13475 | CallExpr *TheCall); |
||
13476 | bool CheckMipsBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall); |
||
13477 | bool CheckSystemZBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
||
13478 | bool CheckX86BuiltinRoundingOrSAE(unsigned BuiltinID, CallExpr *TheCall); |
||
13479 | bool CheckX86BuiltinGatherScatterScale(unsigned BuiltinID, CallExpr *TheCall); |
||
13480 | bool CheckX86BuiltinTileArguments(unsigned BuiltinID, CallExpr *TheCall); |
||
13481 | bool CheckX86BuiltinTileArgumentsRange(CallExpr *TheCall, |
||
13482 | ArrayRef<int> ArgNums); |
||
13483 | bool CheckX86BuiltinTileDuplicate(CallExpr *TheCall, ArrayRef<int> ArgNums); |
||
13484 | bool CheckX86BuiltinTileRangeAndDuplicate(CallExpr *TheCall, |
||
13485 | ArrayRef<int> ArgNums); |
||
13486 | bool CheckX86BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
||
13487 | CallExpr *TheCall); |
||
13488 | bool CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
||
13489 | CallExpr *TheCall); |
||
13490 | bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
||
13491 | bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum); |
||
13492 | bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
||
13493 | CallExpr *TheCall); |
||
13494 | bool CheckLoongArchBuiltinFunctionCall(const TargetInfo &TI, |
||
13495 | unsigned BuiltinID, CallExpr *TheCall); |
||
13496 | |||
13497 | bool SemaBuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall); |
||
13498 | bool SemaBuiltinVAStartARMMicrosoft(CallExpr *Call); |
||
13499 | bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); |
||
13500 | bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); |
||
13501 | bool SemaBuiltinComplex(CallExpr *TheCall); |
||
13502 | bool SemaBuiltinVSX(CallExpr *TheCall); |
||
13503 | bool SemaBuiltinOSLogFormat(CallExpr *TheCall); |
||
13504 | bool SemaValueIsRunOfOnes(CallExpr *TheCall, unsigned ArgNum); |
||
13505 | |||
13506 | public: |
||
13507 | // Used by C++ template instantiation. |
||
13508 | ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); |
||
13509 | ExprResult SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo, |
||
13510 | SourceLocation BuiltinLoc, |
||
13511 | SourceLocation RParenLoc); |
||
13512 | |||
13513 | private: |
||
13514 | bool SemaBuiltinPrefetch(CallExpr *TheCall); |
||
13515 | bool SemaBuiltinAllocaWithAlign(CallExpr *TheCall); |
||
13516 | bool SemaBuiltinArithmeticFence(CallExpr *TheCall); |
||
13517 | bool SemaBuiltinAssume(CallExpr *TheCall); |
||
13518 | bool SemaBuiltinAssumeAligned(CallExpr *TheCall); |
||
13519 | bool SemaBuiltinLongjmp(CallExpr *TheCall); |
||
13520 | bool SemaBuiltinSetjmp(CallExpr *TheCall); |
||
13521 | ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); |
||
13522 | ExprResult SemaBuiltinNontemporalOverloaded(ExprResult TheCallResult); |
||
13523 | ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult, |
||
13524 | AtomicExpr::AtomicOp Op); |
||
13525 | ExprResult SemaBuiltinOperatorNewDeleteOverloaded(ExprResult TheCallResult, |
||
13526 | bool IsDelete); |
||
13527 | bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, |
||
13528 | llvm::APSInt &Result); |
||
13529 | bool SemaBuiltinConstantArgRange(CallExpr *TheCall, int ArgNum, int Low, |
||
13530 | int High, bool RangeIsError = true); |
||
13531 | bool SemaBuiltinConstantArgMultiple(CallExpr *TheCall, int ArgNum, |
||
13532 | unsigned Multiple); |
||
13533 | bool SemaBuiltinConstantArgPower2(CallExpr *TheCall, int ArgNum); |
||
13534 | bool SemaBuiltinConstantArgShiftedByte(CallExpr *TheCall, int ArgNum, |
||
13535 | unsigned ArgBits); |
||
13536 | bool SemaBuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall, int ArgNum, |
||
13537 | unsigned ArgBits); |
||
13538 | bool SemaBuiltinARMSpecialReg(unsigned BuiltinID, CallExpr *TheCall, |
||
13539 | int ArgNum, unsigned ExpectedFieldNum, |
||
13540 | bool AllowName); |
||
13541 | bool SemaBuiltinARMMemoryTaggingCall(unsigned BuiltinID, CallExpr *TheCall); |
||
13542 | bool SemaBuiltinPPCMMACall(CallExpr *TheCall, unsigned BuiltinID, |
||
13543 | const char *TypeDesc); |
||
13544 | |||
13545 | bool CheckPPCMMAType(QualType Type, SourceLocation TypeLoc); |
||
13546 | |||
13547 | bool SemaBuiltinElementwiseMath(CallExpr *TheCall); |
||
13548 | bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall); |
||
13549 | bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall); |
||
13550 | |||
13551 | // Matrix builtin handling. |
||
13552 | ExprResult SemaBuiltinMatrixTranspose(CallExpr *TheCall, |
||
13553 | ExprResult CallResult); |
||
13554 | ExprResult SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall, |
||
13555 | ExprResult CallResult); |
||
13556 | ExprResult SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall, |
||
13557 | ExprResult CallResult); |
||
13558 | |||
13559 | public: |
||
13560 | enum FormatStringType { |
||
13561 | FST_Scanf, |
||
13562 | FST_Printf, |
||
13563 | FST_NSString, |
||
13564 | FST_Strftime, |
||
13565 | FST_Strfmon, |
||
13566 | FST_Kprintf, |
||
13567 | FST_FreeBSDKPrintf, |
||
13568 | FST_OSTrace, |
||
13569 | FST_OSLog, |
||
13570 | FST_Unknown |
||
13571 | }; |
||
13572 | static FormatStringType GetFormatStringType(const FormatAttr *Format); |
||
13573 | |||
13574 | bool FormatStringHasSArg(const StringLiteral *FExpr); |
||
13575 | |||
13576 | static bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx); |
||
13577 | |||
13578 | private: |
||
13579 | bool CheckFormatArguments(const FormatAttr *Format, |
||
13580 | ArrayRef<const Expr *> Args, bool IsCXXMember, |
||
13581 | VariadicCallType CallType, SourceLocation Loc, |
||
13582 | SourceRange Range, |
||
13583 | llvm::SmallBitVector &CheckedVarArgs); |
||
13584 | bool CheckFormatArguments(ArrayRef<const Expr *> Args, |
||
13585 | FormatArgumentPassingKind FAPK, unsigned format_idx, |
||
13586 | unsigned firstDataArg, FormatStringType Type, |
||
13587 | VariadicCallType CallType, SourceLocation Loc, |
||
13588 | SourceRange range, |
||
13589 | llvm::SmallBitVector &CheckedVarArgs); |
||
13590 | |||
13591 | void CheckAbsoluteValueFunction(const CallExpr *Call, |
||
13592 | const FunctionDecl *FDecl); |
||
13593 | |||
13594 | void CheckMaxUnsignedZero(const CallExpr *Call, const FunctionDecl *FDecl); |
||
13595 | |||
13596 | void CheckMemaccessArguments(const CallExpr *Call, |
||
13597 | unsigned BId, |
||
13598 | IdentifierInfo *FnName); |
||
13599 | |||
13600 | void CheckStrlcpycatArguments(const CallExpr *Call, |
||
13601 | IdentifierInfo *FnName); |
||
13602 | |||
13603 | void CheckStrncatArguments(const CallExpr *Call, |
||
13604 | IdentifierInfo *FnName); |
||
13605 | |||
13606 | void CheckFreeArguments(const CallExpr *E); |
||
13607 | |||
13608 | void CheckReturnValExpr(Expr *RetValExp, QualType lhsType, |
||
13609 | SourceLocation ReturnLoc, |
||
13610 | bool isObjCMethod = false, |
||
13611 | const AttrVec *Attrs = nullptr, |
||
13612 | const FunctionDecl *FD = nullptr); |
||
13613 | |||
13614 | public: |
||
13615 | void CheckFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS, |
||
13616 | BinaryOperatorKind Opcode); |
||
13617 | |||
13618 | private: |
||
13619 | void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); |
||
13620 | void CheckBoolLikeConversion(Expr *E, SourceLocation CC); |
||
13621 | void CheckForIntOverflow(Expr *E); |
||
13622 | void CheckUnsequencedOperations(const Expr *E); |
||
13623 | |||
13624 | /// Perform semantic checks on a completed expression. This will either |
||
13625 | /// be a full-expression or a default argument expression. |
||
13626 | void CheckCompletedExpr(Expr *E, SourceLocation CheckLoc = SourceLocation(), |
||
13627 | bool IsConstexpr = false); |
||
13628 | |||
13629 | void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, |
||
13630 | Expr *Init); |
||
13631 | |||
13632 | /// Check if there is a field shadowing. |
||
13633 | void CheckShadowInheritedFields(const SourceLocation &Loc, |
||
13634 | DeclarationName FieldName, |
||
13635 | const CXXRecordDecl *RD, |
||
13636 | bool DeclIsField = true); |
||
13637 | |||
13638 | /// Check if the given expression contains 'break' or 'continue' |
||
13639 | /// statement that produces control flow different from GCC. |
||
13640 | void CheckBreakContinueBinding(Expr *E); |
||
13641 | |||
13642 | /// Check whether receiver is mutable ObjC container which |
||
13643 | /// attempts to add itself into the container |
||
13644 | void CheckObjCCircularContainer(ObjCMessageExpr *Message); |
||
13645 | |||
13646 | void CheckTCBEnforcement(const SourceLocation CallExprLoc, |
||
13647 | const NamedDecl *Callee); |
||
13648 | |||
13649 | void AnalyzeDeleteExprMismatch(const CXXDeleteExpr *DE); |
||
13650 | void AnalyzeDeleteExprMismatch(FieldDecl *Field, SourceLocation DeleteLoc, |
||
13651 | bool DeleteWasArrayForm); |
||
13652 | public: |
||
13653 | /// Register a magic integral constant to be used as a type tag. |
||
13654 | void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind, |
||
13655 | uint64_t MagicValue, QualType Type, |
||
13656 | bool LayoutCompatible, bool MustBeNull); |
||
13657 | |||
13658 | struct TypeTagData { |
||
13659 | TypeTagData() {} |
||
13660 | |||
13661 | TypeTagData(QualType Type, bool LayoutCompatible, bool MustBeNull) : |
||
13662 | Type(Type), LayoutCompatible(LayoutCompatible), |
||
13663 | MustBeNull(MustBeNull) |
||
13664 | {} |
||
13665 | |||
13666 | QualType Type; |
||
13667 | |||
13668 | /// If true, \c Type should be compared with other expression's types for |
||
13669 | /// layout-compatibility. |
||
13670 | unsigned LayoutCompatible : 1; |
||
13671 | unsigned MustBeNull : 1; |
||
13672 | }; |
||
13673 | |||
13674 | /// A pair of ArgumentKind identifier and magic value. This uniquely |
||
13675 | /// identifies the magic value. |
||
13676 | typedef std::pair<const IdentifierInfo *, uint64_t> TypeTagMagicValue; |
||
13677 | |||
13678 | private: |
||
13679 | /// A map from magic value to type information. |
||
13680 | std::unique_ptr<llvm::DenseMap<TypeTagMagicValue, TypeTagData>> |
||
13681 | TypeTagForDatatypeMagicValues; |
||
13682 | |||
13683 | /// Peform checks on a call of a function with argument_with_type_tag |
||
13684 | /// or pointer_with_type_tag attributes. |
||
13685 | void CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr, |
||
13686 | const ArrayRef<const Expr *> ExprArgs, |
||
13687 | SourceLocation CallSiteLoc); |
||
13688 | |||
13689 | /// Check if we are taking the address of a packed field |
||
13690 | /// as this may be a problem if the pointer value is dereferenced. |
||
13691 | void CheckAddressOfPackedMember(Expr *rhs); |
||
13692 | |||
13693 | /// The parser's current scope. |
||
13694 | /// |
||
13695 | /// The parser maintains this state here. |
||
13696 | Scope *CurScope; |
||
13697 | |||
13698 | mutable IdentifierInfo *Ident_super; |
||
13699 | mutable IdentifierInfo *Ident___float128; |
||
13700 | |||
13701 | /// Nullability type specifiers. |
||
13702 | IdentifierInfo *Ident__Nonnull = nullptr; |
||
13703 | IdentifierInfo *Ident__Nullable = nullptr; |
||
13704 | IdentifierInfo *Ident__Nullable_result = nullptr; |
||
13705 | IdentifierInfo *Ident__Null_unspecified = nullptr; |
||
13706 | |||
13707 | IdentifierInfo *Ident_NSError = nullptr; |
||
13708 | |||
13709 | /// The handler for the FileChanged preprocessor events. |
||
13710 | /// |
||
13711 | /// Used for diagnostics that implement custom semantic analysis for #include |
||
13712 | /// directives, like -Wpragma-pack. |
||
13713 | sema::SemaPPCallbacks *SemaPPCallbackHandler; |
||
13714 | |||
13715 | protected: |
||
13716 | friend class Parser; |
||
13717 | friend class InitializationSequence; |
||
13718 | friend class ASTReader; |
||
13719 | friend class ASTDeclReader; |
||
13720 | friend class ASTWriter; |
||
13721 | |||
13722 | public: |
||
13723 | /// Retrieve the keyword associated |
||
13724 | IdentifierInfo *getNullabilityKeyword(NullabilityKind nullability); |
||
13725 | |||
13726 | /// The struct behind the CFErrorRef pointer. |
||
13727 | RecordDecl *CFError = nullptr; |
||
13728 | bool isCFError(RecordDecl *D); |
||
13729 | |||
13730 | /// Retrieve the identifier "NSError". |
||
13731 | IdentifierInfo *getNSErrorIdent(); |
||
13732 | |||
13733 | /// Retrieve the parser's current scope. |
||
13734 | /// |
||
13735 | /// This routine must only be used when it is certain that semantic analysis |
||
13736 | /// and the parser are in precisely the same context, which is not the case |
||
13737 | /// when, e.g., we are performing any kind of template instantiation. |
||
13738 | /// Therefore, the only safe places to use this scope are in the parser |
||
13739 | /// itself and in routines directly invoked from the parser and *never* from |
||
13740 | /// template substitution or instantiation. |
||
13741 | Scope *getCurScope() const { return CurScope; } |
||
13742 | |||
13743 | void incrementMSManglingNumber() const { |
||
13744 | return CurScope->incrementMSManglingNumber(); |
||
13745 | } |
||
13746 | |||
13747 | IdentifierInfo *getSuperIdentifier() const; |
||
13748 | IdentifierInfo *getFloat128Identifier() const; |
||
13749 | |||
13750 | ObjCContainerDecl *getObjCDeclContext() const; |
||
13751 | |||
13752 | DeclContext *getCurLexicalContext() const { |
||
13753 | return OriginalLexicalContext ? OriginalLexicalContext : CurContext; |
||
13754 | } |
||
13755 | |||
13756 | const DeclContext *getCurObjCLexicalContext() const { |
||
13757 | const DeclContext *DC = getCurLexicalContext(); |
||
13758 | // A category implicitly has the attribute of the interface. |
||
13759 | if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(DC)) |
||
13760 | DC = CatD->getClassInterface(); |
||
13761 | return DC; |
||
13762 | } |
||
13763 | |||
13764 | /// Determine the number of levels of enclosing template parameters. This is |
||
13765 | /// only usable while parsing. Note that this does not include dependent |
||
13766 | /// contexts in which no template parameters have yet been declared, such as |
||
13767 | /// in a terse function template or generic lambda before the first 'auto' is |
||
13768 | /// encountered. |
||
13769 | unsigned getTemplateDepth(Scope *S) const; |
||
13770 | |||
13771 | /// To be used for checking whether the arguments being passed to |
||
13772 | /// function exceeds the number of parameters expected for it. |
||
13773 | static bool TooManyArguments(size_t NumParams, size_t NumArgs, |
||
13774 | bool PartialOverloading = false) { |
||
13775 | // We check whether we're just after a comma in code-completion. |
||
13776 | if (NumArgs > 0 && PartialOverloading) |
||
13777 | return NumArgs + 1 > NumParams; // If so, we view as an extra argument. |
||
13778 | return NumArgs > NumParams; |
||
13779 | } |
||
13780 | |||
13781 | // Emitting members of dllexported classes is delayed until the class |
||
13782 | // (including field initializers) is fully parsed. |
||
13783 | SmallVector<CXXRecordDecl*, 4> DelayedDllExportClasses; |
||
13784 | SmallVector<CXXMethodDecl*, 4> DelayedDllExportMemberFunctions; |
||
13785 | |||
13786 | private: |
||
13787 | int ParsingClassDepth = 0; |
||
13788 | |||
13789 | class SavePendingParsedClassStateRAII { |
||
13790 | public: |
||
13791 | SavePendingParsedClassStateRAII(Sema &S) : S(S) { swapSavedState(); } |
||
13792 | |||
13793 | ~SavePendingParsedClassStateRAII() { |
||
13794 | assert(S.DelayedOverridingExceptionSpecChecks.empty() && |
||
13795 | "there shouldn't be any pending delayed exception spec checks"); |
||
13796 | assert(S.DelayedEquivalentExceptionSpecChecks.empty() && |
||
13797 | "there shouldn't be any pending delayed exception spec checks"); |
||
13798 | swapSavedState(); |
||
13799 | } |
||
13800 | |||
13801 | private: |
||
13802 | Sema &S; |
||
13803 | decltype(DelayedOverridingExceptionSpecChecks) |
||
13804 | SavedOverridingExceptionSpecChecks; |
||
13805 | decltype(DelayedEquivalentExceptionSpecChecks) |
||
13806 | SavedEquivalentExceptionSpecChecks; |
||
13807 | |||
13808 | void swapSavedState() { |
||
13809 | SavedOverridingExceptionSpecChecks.swap( |
||
13810 | S.DelayedOverridingExceptionSpecChecks); |
||
13811 | SavedEquivalentExceptionSpecChecks.swap( |
||
13812 | S.DelayedEquivalentExceptionSpecChecks); |
||
13813 | } |
||
13814 | }; |
||
13815 | |||
13816 | /// Helper class that collects misaligned member designations and |
||
13817 | /// their location info for delayed diagnostics. |
||
13818 | struct MisalignedMember { |
||
13819 | Expr *E; |
||
13820 | RecordDecl *RD; |
||
13821 | ValueDecl *MD; |
||
13822 | CharUnits Alignment; |
||
13823 | |||
13824 | MisalignedMember() : E(), RD(), MD() {} |
||
13825 | MisalignedMember(Expr *E, RecordDecl *RD, ValueDecl *MD, |
||
13826 | CharUnits Alignment) |
||
13827 | : E(E), RD(RD), MD(MD), Alignment(Alignment) {} |
||
13828 | explicit MisalignedMember(Expr *E) |
||
13829 | : MisalignedMember(E, nullptr, nullptr, CharUnits()) {} |
||
13830 | |||
13831 | bool operator==(const MisalignedMember &m) { return this->E == m.E; } |
||
13832 | }; |
||
13833 | /// Small set of gathered accesses to potentially misaligned members |
||
13834 | /// due to the packed attribute. |
||
13835 | SmallVector<MisalignedMember, 4> MisalignedMembers; |
||
13836 | |||
13837 | /// Adds an expression to the set of gathered misaligned members. |
||
13838 | void AddPotentialMisalignedMembers(Expr *E, RecordDecl *RD, ValueDecl *MD, |
||
13839 | CharUnits Alignment); |
||
13840 | |||
13841 | public: |
||
13842 | /// Diagnoses the current set of gathered accesses. This typically |
||
13843 | /// happens at full expression level. The set is cleared after emitting the |
||
13844 | /// diagnostics. |
||
13845 | void DiagnoseMisalignedMembers(); |
||
13846 | |||
13847 | /// This function checks if the expression is in the sef of potentially |
||
13848 | /// misaligned members and it is converted to some pointer type T with lower |
||
13849 | /// or equal alignment requirements. If so it removes it. This is used when |
||
13850 | /// we do not want to diagnose such misaligned access (e.g. in conversions to |
||
13851 | /// void*). |
||
13852 | void DiscardMisalignedMemberAddress(const Type *T, Expr *E); |
||
13853 | |||
13854 | /// This function calls Action when it determines that E designates a |
||
13855 | /// misaligned member due to the packed attribute. This is used to emit |
||
13856 | /// local diagnostics like in reference binding. |
||
13857 | void RefersToMemberWithReducedAlignment( |
||
13858 | Expr *E, |
||
13859 | llvm::function_ref<void(Expr *, RecordDecl *, FieldDecl *, CharUnits)> |
||
13860 | Action); |
||
13861 | |||
13862 | /// Describes the reason a calling convention specification was ignored, used |
||
13863 | /// for diagnostics. |
||
13864 | enum class CallingConventionIgnoredReason { |
||
13865 | ForThisTarget = 0, |
||
13866 | VariadicFunction, |
||
13867 | ConstructorDestructor, |
||
13868 | BuiltinFunction |
||
13869 | }; |
||
13870 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
||
13871 | /// context is "used as device code". |
||
13872 | /// |
||
13873 | /// - If CurLexicalContext is a kernel function or it is known that the |
||
13874 | /// function will be emitted for the device, emits the diagnostics |
||
13875 | /// immediately. |
||
13876 | /// - If CurLexicalContext is a function and we are compiling |
||
13877 | /// for the device, but we don't know that this function will be codegen'ed |
||
13878 | /// for devive yet, creates a diagnostic which is emitted if and when we |
||
13879 | /// realize that the function will be codegen'ed. |
||
13880 | /// |
||
13881 | /// Example usage: |
||
13882 | /// |
||
13883 | /// Diagnose __float128 type usage only from SYCL device code if the current |
||
13884 | /// target doesn't support it |
||
13885 | /// if (!S.Context.getTargetInfo().hasFloat128Type() && |
||
13886 | /// S.getLangOpts().SYCLIsDevice) |
||
13887 | /// SYCLDiagIfDeviceCode(Loc, diag::err_type_unsupported) << "__float128"; |
||
13888 | SemaDiagnosticBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, |
||
13889 | unsigned DiagID); |
||
13890 | |||
13891 | /// Check whether we're allowed to call Callee from the current context. |
||
13892 | /// |
||
13893 | /// - If the call is never allowed in a semantically-correct program |
||
13894 | /// emits an error and returns false. |
||
13895 | /// |
||
13896 | /// - If the call is allowed in semantically-correct programs, but only if |
||
13897 | /// it's never codegen'ed, creates a deferred diagnostic to be emitted if |
||
13898 | /// and when the caller is codegen'ed, and returns true. |
||
13899 | /// |
||
13900 | /// - Otherwise, returns true without emitting any diagnostics. |
||
13901 | /// |
||
13902 | /// Adds Callee to DeviceCallGraph if we don't know if its caller will be |
||
13903 | /// codegen'ed yet. |
||
13904 | bool checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee); |
||
13905 | void deepTypeCheckForSYCLDevice(SourceLocation UsedAt, |
||
13906 | llvm::DenseSet<QualType> Visited, |
||
13907 | ValueDecl *DeclToCheck); |
||
13908 | }; |
||
13909 | |||
13910 | /// RAII object that enters a new expression evaluation context. |
||
13911 | class EnterExpressionEvaluationContext { |
||
13912 | Sema &Actions; |
||
13913 | bool Entered = true; |
||
13914 | |||
13915 | public: |
||
13916 | EnterExpressionEvaluationContext( |
||
13917 | Sema &Actions, Sema::ExpressionEvaluationContext NewContext, |
||
13918 | Decl *LambdaContextDecl = nullptr, |
||
13919 | Sema::ExpressionEvaluationContextRecord::ExpressionKind ExprContext = |
||
13920 | Sema::ExpressionEvaluationContextRecord::EK_Other, |
||
13921 | bool ShouldEnter = true) |
||
13922 | : Actions(Actions), Entered(ShouldEnter) { |
||
13923 | if (Entered) |
||
13924 | Actions.PushExpressionEvaluationContext(NewContext, LambdaContextDecl, |
||
13925 | ExprContext); |
||
13926 | } |
||
13927 | EnterExpressionEvaluationContext( |
||
13928 | Sema &Actions, Sema::ExpressionEvaluationContext NewContext, |
||
13929 | Sema::ReuseLambdaContextDecl_t, |
||
13930 | Sema::ExpressionEvaluationContextRecord::ExpressionKind ExprContext = |
||
13931 | Sema::ExpressionEvaluationContextRecord::EK_Other) |
||
13932 | : Actions(Actions) { |
||
13933 | Actions.PushExpressionEvaluationContext( |
||
13934 | NewContext, Sema::ReuseLambdaContextDecl, ExprContext); |
||
13935 | } |
||
13936 | |||
13937 | enum InitListTag { InitList }; |
||
13938 | EnterExpressionEvaluationContext(Sema &Actions, InitListTag, |
||
13939 | bool ShouldEnter = true) |
||
13940 | : Actions(Actions), Entered(false) { |
||
13941 | // In C++11 onwards, narrowing checks are performed on the contents of |
||
13942 | // braced-init-lists, even when they occur within unevaluated operands. |
||
13943 | // Therefore we still need to instantiate constexpr functions used in such |
||
13944 | // a context. |
||
13945 | if (ShouldEnter && Actions.isUnevaluatedContext() && |
||
13946 | Actions.getLangOpts().CPlusPlus11) { |
||
13947 | Actions.PushExpressionEvaluationContext( |
||
13948 | Sema::ExpressionEvaluationContext::UnevaluatedList); |
||
13949 | Entered = true; |
||
13950 | } |
||
13951 | } |
||
13952 | |||
13953 | ~EnterExpressionEvaluationContext() { |
||
13954 | if (Entered) |
||
13955 | Actions.PopExpressionEvaluationContext(); |
||
13956 | } |
||
13957 | }; |
||
13958 | |||
13959 | DeductionFailureInfo |
||
13960 | MakeDeductionFailureInfo(ASTContext &Context, Sema::TemplateDeductionResult TDK, |
||
13961 | sema::TemplateDeductionInfo &Info); |
||
13962 | |||
13963 | /// Contains a late templated function. |
||
13964 | /// Will be parsed at the end of the translation unit, used by Sema & Parser. |
||
13965 | struct LateParsedTemplate { |
||
13966 | CachedTokens Toks; |
||
13967 | /// The template function declaration to be late parsed. |
||
13968 | Decl *D; |
||
13969 | }; |
||
13970 | |||
13971 | template <> |
||
13972 | void Sema::PragmaStack<Sema::AlignPackInfo>::Act(SourceLocation PragmaLocation, |
||
13973 | PragmaMsStackAction Action, |
||
13974 | llvm::StringRef StackSlotLabel, |
||
13975 | AlignPackInfo Value); |
||
13976 | |||
13977 | std::unique_ptr<sema::RISCVIntrinsicManager> |
||
13978 | CreateRISCVIntrinsicManager(Sema &S); |
||
13979 | } // end namespace clang |
||
13980 | |||
13981 | namespace llvm { |
||
13982 | // Hash a FunctionDeclAndLoc by looking at both its FunctionDecl and its |
||
13983 | // SourceLocation. |
||
13984 | template <> struct DenseMapInfo<clang::Sema::FunctionDeclAndLoc> { |
||
13985 | using FunctionDeclAndLoc = clang::Sema::FunctionDeclAndLoc; |
||
13986 | using FDBaseInfo = DenseMapInfo<clang::CanonicalDeclPtr<clang::FunctionDecl>>; |
||
13987 | |||
13988 | static FunctionDeclAndLoc getEmptyKey() { |
||
13989 | return {FDBaseInfo::getEmptyKey(), clang::SourceLocation()}; |
||
13990 | } |
||
13991 | |||
13992 | static FunctionDeclAndLoc getTombstoneKey() { |
||
13993 | return {FDBaseInfo::getTombstoneKey(), clang::SourceLocation()}; |
||
13994 | } |
||
13995 | |||
13996 | static unsigned getHashValue(const FunctionDeclAndLoc &FDL) { |
||
13997 | return hash_combine(FDBaseInfo::getHashValue(FDL.FD), |
||
13998 | FDL.Loc.getHashValue()); |
||
13999 | } |
||
14000 | |||
14001 | static bool isEqual(const FunctionDeclAndLoc &LHS, |
||
14002 | const FunctionDeclAndLoc &RHS) { |
||
14003 | return LHS.FD == RHS.FD && LHS.Loc == RHS.Loc; |
||
14004 | } |
||
14005 | }; |
||
14006 | } // namespace llvm |
||
14007 | |||
14008 | #endif |