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 | struct PragmaPackInfo { |
485 | PragmaMsStackAction Action; |
486 | StringRef SlotLabel; |
487 | Token Alignment; |
488 | }; |
489 | |
490 | // #pragma pack and align. |
491 | class AlignPackInfo { |
492 | public: |
493 | // `Native` represents default align mode, which may vary based on the |
494 | // platform. |
495 | enum Mode : unsigned char { Native, Natural, Packed, Mac68k }; |
496 | |
497 | // #pragma pack info constructor |
498 | AlignPackInfo(AlignPackInfo::Mode M, unsigned Num, bool IsXL) |
499 | : PackAttr(true), AlignMode(M), PackNumber(Num), XLStack(IsXL) { |
500 | assert(Num == PackNumber && "The pack number has been truncated." ); |
501 | } |
502 | |
503 | // #pragma align info constructor |
504 | AlignPackInfo(AlignPackInfo::Mode M, bool IsXL) |
505 | : PackAttr(false), AlignMode(M), |
506 | PackNumber(M == Packed ? 1 : UninitPackVal), XLStack(IsXL) {} |
507 | |
508 | explicit AlignPackInfo(bool IsXL) : AlignPackInfo(Native, IsXL) {} |
509 | |
510 | AlignPackInfo() : AlignPackInfo(Native, false) {} |
511 | |
512 | // When a AlignPackInfo itself cannot be used, this returns an 32-bit |
513 | // integer encoding for it. This should only be passed to |
514 | // AlignPackInfo::getFromRawEncoding, it should not be inspected directly. |
515 | static uint32_t getRawEncoding(const AlignPackInfo &Info) { |
516 | std::uint32_t Encoding{}; |
517 | if (Info.IsXLStack()) |
518 | Encoding |= IsXLMask; |
519 | |
520 | Encoding |= static_cast<uint32_t>(Info.getAlignMode()) << 1; |
521 | |
522 | if (Info.IsPackAttr()) |
523 | Encoding |= PackAttrMask; |
524 | |
525 | Encoding |= static_cast<uint32_t>(Info.getPackNumber()) << 4; |
526 | |
527 | return Encoding; |
528 | } |
529 | |
530 | static AlignPackInfo getFromRawEncoding(unsigned Encoding) { |
531 | bool IsXL = static_cast<bool>(Encoding & IsXLMask); |
532 | AlignPackInfo::Mode M = |
533 | static_cast<AlignPackInfo::Mode>((Encoding & AlignModeMask) >> 1); |
534 | int PackNumber = (Encoding & PackNumMask) >> 4; |
535 | |
536 | if (Encoding & PackAttrMask) |
537 | return AlignPackInfo(M, PackNumber, IsXL); |
538 | |
539 | return AlignPackInfo(M, IsXL); |
540 | } |
541 | |
542 | bool IsPackAttr() const { return PackAttr; } |
543 | |
544 | bool IsAlignAttr() const { return !PackAttr; } |
545 | |
546 | Mode getAlignMode() const { return AlignMode; } |
547 | |
548 | unsigned getPackNumber() const { return PackNumber; } |
549 | |
550 | bool IsPackSet() const { |
551 | // #pragma align, #pragma pack(), and #pragma pack(0) do not set the pack |
552 | // attriute on a decl. |
553 | return PackNumber != UninitPackVal && PackNumber != 0; |
554 | } |
555 | |
556 | bool IsXLStack() const { return XLStack; } |
557 | |
558 | bool operator==(const AlignPackInfo &Info) const { |
559 | return std::tie(AlignMode, PackNumber, PackAttr, XLStack) == |
560 | std::tie(Info.AlignMode, Info.PackNumber, Info.PackAttr, |
561 | Info.XLStack); |
562 | } |
563 | |
564 | bool operator!=(const AlignPackInfo &Info) const { |
565 | return !(*this == Info); |
566 | } |
567 | |
568 | private: |
569 | /// \brief True if this is a pragma pack attribute, |
570 | /// not a pragma align attribute. |
571 | bool PackAttr; |
572 | |
573 | /// \brief The alignment mode that is in effect. |
574 | Mode AlignMode; |
575 | |
576 | /// \brief The pack number of the stack. |
577 | unsigned char PackNumber; |
578 | |
579 | /// \brief True if it is a XL #pragma align/pack stack. |
580 | bool XLStack; |
581 | |
582 | /// \brief Uninitialized pack value. |
583 | static constexpr unsigned char UninitPackVal = -1; |
584 | |
585 | // Masks to encode and decode an AlignPackInfo. |
586 | static constexpr uint32_t IsXLMask{0x0000'0001}; |
587 | static constexpr uint32_t AlignModeMask{0x0000'0006}; |
588 | static constexpr uint32_t PackAttrMask{0x00000'0008}; |
589 | static constexpr uint32_t PackNumMask{0x0000'01F0}; |
590 | }; |
591 | |
592 | template<typename ValueType> |
593 | struct PragmaStack { |
594 | struct Slot { |
595 | llvm::StringRef StackSlotLabel; |
596 | ValueType Value; |
597 | SourceLocation PragmaLocation; |
598 | SourceLocation PragmaPushLocation; |
599 | Slot(llvm::StringRef StackSlotLabel, ValueType Value, |
600 | SourceLocation PragmaLocation, SourceLocation PragmaPushLocation) |
601 | : StackSlotLabel(StackSlotLabel), Value(Value), |
602 | PragmaLocation(PragmaLocation), |
603 | PragmaPushLocation(PragmaPushLocation) {} |
604 | }; |
605 | |
606 | void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, |
607 | llvm::StringRef StackSlotLabel, ValueType Value) { |
608 | if (Action == PSK_Reset) { |
609 | CurrentValue = DefaultValue; |
610 | CurrentPragmaLocation = PragmaLocation; |
611 | return; |
612 | } |
613 | if (Action & PSK_Push) |
614 | Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation, |
615 | PragmaLocation); |
616 | else if (Action & PSK_Pop) { |
617 | if (!StackSlotLabel.empty()) { |
618 | // If we've got a label, try to find it and jump there. |
619 | auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) { |
620 | return x.StackSlotLabel == StackSlotLabel; |
621 | }); |
622 | // If we found the label so pop from there. |
623 | if (I != Stack.rend()) { |
624 | CurrentValue = I->Value; |
625 | CurrentPragmaLocation = I->PragmaLocation; |
626 | Stack.erase(std::prev(I.base()), Stack.end()); |
627 | } |
628 | } else if (!Stack.empty()) { |
629 | // We do not have a label, just pop the last entry. |
630 | CurrentValue = Stack.back().Value; |
631 | CurrentPragmaLocation = Stack.back().PragmaLocation; |
632 | Stack.pop_back(); |
633 | } |
634 | } |
635 | if (Action & PSK_Set) { |
636 | CurrentValue = Value; |
637 | CurrentPragmaLocation = PragmaLocation; |
638 | } |
639 | } |
640 | |
641 | // MSVC seems to add artificial slots to #pragma stacks on entering a C++ |
642 | // method body to restore the stacks on exit, so it works like this: |
643 | // |
644 | // struct S { |
645 | // #pragma <name>(push, InternalPragmaSlot, <current_pragma_value>) |
646 | // void Method {} |
647 | // #pragma <name>(pop, InternalPragmaSlot) |
648 | // }; |
649 | // |
650 | // It works even with #pragma vtordisp, although MSVC doesn't support |
651 | // #pragma vtordisp(push [, id], n) |
652 | // syntax. |
653 | // |
654 | // Push / pop a named sentinel slot. |
655 | void SentinelAction(PragmaMsStackAction Action, StringRef Label) { |
656 | assert((Action == PSK_Push || Action == PSK_Pop) && |
657 | "Can only push / pop #pragma stack sentinels!" ); |
658 | Act(CurrentPragmaLocation, Action, Label, CurrentValue); |
659 | } |
660 | |
661 | // Constructors. |
662 | explicit PragmaStack(const ValueType &Default) |
663 | : DefaultValue(Default), CurrentValue(Default) {} |
664 | |
665 | bool hasValue() const { return CurrentValue != DefaultValue; } |
666 | |
667 | SmallVector<Slot, 2> Stack; |
668 | ValueType DefaultValue; // Value used for PSK_Reset action. |
669 | ValueType CurrentValue; |
670 | SourceLocation CurrentPragmaLocation; |
671 | }; |
672 | // FIXME: We should serialize / deserialize these if they occur in a PCH (but |
673 | // we shouldn't do so if they're in a module). |
674 | |
675 | /// Whether to insert vtordisps prior to virtual bases in the Microsoft |
676 | /// C++ ABI. Possible values are 0, 1, and 2, which mean: |
677 | /// |
678 | /// 0: Suppress all vtordisps |
679 | /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial |
680 | /// structors |
681 | /// 2: Always insert vtordisps to support RTTI on partially constructed |
682 | /// objects |
683 | PragmaStack<MSVtorDispMode> VtorDispStack; |
684 | PragmaStack<AlignPackInfo> AlignPackStack; |
685 | // The current #pragma align/pack values and locations at each #include. |
686 | struct AlignPackIncludeState { |
687 | AlignPackInfo CurrentValue; |
688 | SourceLocation CurrentPragmaLocation; |
689 | bool HasNonDefaultValue, ShouldWarnOnInclude; |
690 | }; |
691 | SmallVector<AlignPackIncludeState, 8> AlignPackIncludeStack; |
692 | // Segment #pragmas. |
693 | PragmaStack<StringLiteral *> DataSegStack; |
694 | PragmaStack<StringLiteral *> BSSSegStack; |
695 | PragmaStack<StringLiteral *> ConstSegStack; |
696 | PragmaStack<StringLiteral *> CodeSegStack; |
697 | |
698 | // #pragma strict_gs_check. |
699 | PragmaStack<bool> StrictGuardStackCheckStack; |
700 | |
701 | // This stack tracks the current state of Sema.CurFPFeatures. |
702 | PragmaStack<FPOptionsOverride> FpPragmaStack; |
703 | FPOptionsOverride CurFPFeatureOverrides() { |
704 | FPOptionsOverride result; |
705 | if (!FpPragmaStack.hasValue()) { |
706 | result = FPOptionsOverride(); |
707 | } else { |
708 | result = FpPragmaStack.CurrentValue; |
709 | } |
710 | return result; |
711 | } |
712 | |
713 | // Saves the current floating-point pragma stack and clear it in this Sema. |
714 | class FpPragmaStackSaveRAII { |
715 | public: |
716 | FpPragmaStackSaveRAII(Sema &S) |
717 | : S(S), SavedStack(std::move(S.FpPragmaStack)) { |
718 | S.FpPragmaStack.Stack.clear(); |
719 | } |
720 | ~FpPragmaStackSaveRAII() { S.FpPragmaStack = std::move(SavedStack); } |
721 | |
722 | private: |
723 | Sema &S; |
724 | PragmaStack<FPOptionsOverride> SavedStack; |
725 | }; |
726 | |
727 | void resetFPOptions(FPOptions FPO) { |
728 | CurFPFeatures = FPO; |
729 | FpPragmaStack.CurrentValue = FPO.getChangesFrom(FPOptions(LangOpts)); |
730 | } |
731 | |
732 | // RAII object to push / pop sentinel slots for all MS #pragma stacks. |
733 | // Actions should be performed only if we enter / exit a C++ method body. |
734 | class PragmaStackSentinelRAII { |
735 | public: |
736 | PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct); |
737 | ~PragmaStackSentinelRAII(); |
738 | |
739 | private: |
740 | Sema &S; |
741 | StringRef SlotLabel; |
742 | bool ShouldAct; |
743 | }; |
744 | |
745 | /// A mapping that describes the nullability we've seen in each header file. |
746 | FileNullabilityMap NullabilityMap; |
747 | |
748 | /// Last section used with #pragma init_seg. |
749 | StringLiteral *CurInitSeg; |
750 | SourceLocation CurInitSegLoc; |
751 | |
752 | /// Sections used with #pragma alloc_text. |
753 | llvm::StringMap<std::tuple<StringRef, SourceLocation>> FunctionToSectionMap; |
754 | |
755 | /// VisContext - Manages the stack for \#pragma GCC visibility. |
756 | void *VisContext; // Really a "PragmaVisStack*" |
757 | |
758 | /// This an attribute introduced by \#pragma clang attribute. |
759 | struct PragmaAttributeEntry { |
760 | SourceLocation Loc; |
761 | ParsedAttr *Attribute; |
762 | SmallVector<attr::SubjectMatchRule, 4> MatchRules; |
763 | bool IsUsed; |
764 | }; |
765 | |
766 | /// A push'd group of PragmaAttributeEntries. |
767 | struct PragmaAttributeGroup { |
768 | /// The location of the push attribute. |
769 | SourceLocation Loc; |
770 | /// The namespace of this push group. |
771 | const IdentifierInfo *Namespace; |
772 | SmallVector<PragmaAttributeEntry, 2> Entries; |
773 | }; |
774 | |
775 | SmallVector<PragmaAttributeGroup, 2> PragmaAttributeStack; |
776 | |
777 | /// The declaration that is currently receiving an attribute from the |
778 | /// #pragma attribute stack. |
779 | const Decl *PragmaAttributeCurrentTargetDecl; |
780 | |
781 | /// This represents the last location of a "#pragma clang optimize off" |
782 | /// directive if such a directive has not been closed by an "on" yet. If |
783 | /// optimizations are currently "on", this is set to an invalid location. |
784 | SourceLocation OptimizeOffPragmaLocation; |
785 | |
786 | /// The "on" or "off" argument passed by \#pragma optimize, that denotes |
787 | /// whether the optimizations in the list passed to the pragma should be |
788 | /// turned off or on. This boolean is true by default because command line |
789 | /// options are honored when `#pragma optimize("", on)`. |
790 | /// (i.e. `ModifyFnAttributeMSPragmaOptimze()` does nothing) |
791 | bool MSPragmaOptimizeIsOn = true; |
792 | |
793 | /// Set of no-builtin functions listed by \#pragma function. |
794 | llvm::SmallSetVector<StringRef, 4> MSFunctionNoBuiltins; |
795 | |
796 | /// Flag indicating if Sema is building a recovery call expression. |
797 | /// |
798 | /// This flag is used to avoid building recovery call expressions |
799 | /// if Sema is already doing so, which would cause infinite recursions. |
800 | bool IsBuildingRecoveryCallExpr; |
801 | |
802 | /// Used to control the generation of ExprWithCleanups. |
803 | CleanupInfo Cleanup; |
804 | |
805 | /// ExprCleanupObjects - This is the stack of objects requiring |
806 | /// cleanup that are created by the current full expression. |
807 | SmallVector<ExprWithCleanups::CleanupObject, 8> ExprCleanupObjects; |
808 | |
809 | /// Store a set of either DeclRefExprs or MemberExprs that contain a reference |
810 | /// to a variable (constant) that may or may not be odr-used in this Expr, and |
811 | /// we won't know until all lvalue-to-rvalue and discarded value conversions |
812 | /// have been applied to all subexpressions of the enclosing full expression. |
813 | /// This is cleared at the end of each full expression. |
814 | using MaybeODRUseExprSet = llvm::SmallSetVector<Expr *, 4>; |
815 | MaybeODRUseExprSet MaybeODRUseExprs; |
816 | |
817 | std::unique_ptr<sema::FunctionScopeInfo> CachedFunctionScope; |
818 | |
819 | /// Stack containing information about each of the nested |
820 | /// function, block, and method scopes that are currently active. |
821 | SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes; |
822 | |
823 | /// The index of the first FunctionScope that corresponds to the current |
824 | /// context. |
825 | unsigned FunctionScopesStart = 0; |
826 | |
827 | /// Track the number of currently active capturing scopes. |
828 | unsigned CapturingFunctionScopes = 0; |
829 | |
830 | ArrayRef<sema::FunctionScopeInfo*> getFunctionScopes() const { |
831 | return llvm::ArrayRef(FunctionScopes.begin() + FunctionScopesStart, |
832 | FunctionScopes.end()); |
833 | } |
834 | |
835 | /// Stack containing information needed when in C++2a an 'auto' is encountered |
836 | /// in a function declaration parameter type specifier in order to invent a |
837 | /// corresponding template parameter in the enclosing abbreviated function |
838 | /// template. This information is also present in LambdaScopeInfo, stored in |
839 | /// the FunctionScopes stack. |
840 | SmallVector<InventedTemplateParameterInfo, 4> InventedParameterInfos; |
841 | |
842 | /// The index of the first InventedParameterInfo that refers to the current |
843 | /// context. |
844 | unsigned InventedParameterInfosStart = 0; |
845 | |
846 | ArrayRef<InventedTemplateParameterInfo> getInventedParameterInfos() const { |
847 | return llvm::ArrayRef(InventedParameterInfos.begin() + |
848 | InventedParameterInfosStart, |
849 | InventedParameterInfos.end()); |
850 | } |
851 | |
852 | typedef LazyVector<TypedefNameDecl *, ExternalSemaSource, |
853 | &ExternalSemaSource::ReadExtVectorDecls, 2, 2> |
854 | ExtVectorDeclsType; |
855 | |
856 | /// ExtVectorDecls - This is a list all the extended vector types. This allows |
857 | /// us to associate a raw vector type with one of the ext_vector type names. |
858 | /// This is only necessary for issuing pretty diagnostics. |
859 | ExtVectorDeclsType ExtVectorDecls; |
860 | |
861 | /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. |
862 | std::unique_ptr<CXXFieldCollector> FieldCollector; |
863 | |
864 | typedef llvm::SmallSetVector<const NamedDecl *, 16> NamedDeclSetType; |
865 | |
866 | /// Set containing all declared private fields that are not used. |
867 | NamedDeclSetType UnusedPrivateFields; |
868 | |
869 | /// Set containing all typedefs that are likely unused. |
870 | llvm::SmallSetVector<const TypedefNameDecl *, 4> |
871 | UnusedLocalTypedefNameCandidates; |
872 | |
873 | /// Delete-expressions to be analyzed at the end of translation unit |
874 | /// |
875 | /// This list contains class members, and locations of delete-expressions |
876 | /// that could not be proven as to whether they mismatch with new-expression |
877 | /// used in initializer of the field. |
878 | typedef std::pair<SourceLocation, bool> DeleteExprLoc; |
879 | typedef llvm::SmallVector<DeleteExprLoc, 4> DeleteLocs; |
880 | llvm::MapVector<FieldDecl *, DeleteLocs> DeleteExprs; |
881 | |
882 | typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy; |
883 | |
884 | /// PureVirtualClassDiagSet - a set of class declarations which we have |
885 | /// emitted a list of pure virtual functions. Used to prevent emitting the |
886 | /// same list more than once. |
887 | std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet; |
888 | |
889 | /// ParsingInitForAutoVars - a set of declarations with auto types for which |
890 | /// we are currently parsing the initializer. |
891 | llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars; |
892 | |
893 | /// Look for a locally scoped extern "C" declaration by the given name. |
894 | NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name); |
895 | |
896 | typedef LazyVector<VarDecl *, ExternalSemaSource, |
897 | &ExternalSemaSource::ReadTentativeDefinitions, 2, 2> |
898 | TentativeDefinitionsType; |
899 | |
900 | /// All the tentative definitions encountered in the TU. |
901 | TentativeDefinitionsType TentativeDefinitions; |
902 | |
903 | /// All the external declarations encoutered and used in the TU. |
904 | SmallVector<VarDecl *, 4> ExternalDeclarations; |
905 | |
906 | typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource, |
907 | &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2> |
908 | UnusedFileScopedDeclsType; |
909 | |
910 | /// The set of file scoped decls seen so far that have not been used |
911 | /// and must warn if not used. Only contains the first declaration. |
912 | UnusedFileScopedDeclsType UnusedFileScopedDecls; |
913 | |
914 | typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource, |
915 | &ExternalSemaSource::ReadDelegatingConstructors, 2, 2> |
916 | DelegatingCtorDeclsType; |
917 | |
918 | /// All the delegating constructors seen so far in the file, used for |
919 | /// cycle detection at the end of the TU. |
920 | DelegatingCtorDeclsType DelegatingCtorDecls; |
921 | |
922 | /// All the overriding functions seen during a class definition |
923 | /// that had their exception spec checks delayed, plus the overridden |
924 | /// function. |
925 | SmallVector<std::pair<const CXXMethodDecl*, const CXXMethodDecl*>, 2> |
926 | DelayedOverridingExceptionSpecChecks; |
927 | |
928 | /// All the function redeclarations seen during a class definition that had |
929 | /// their exception spec checks delayed, plus the prior declaration they |
930 | /// should be checked against. Except during error recovery, the new decl |
931 | /// should always be a friend declaration, as that's the only valid way to |
932 | /// redeclare a special member before its class is complete. |
933 | SmallVector<std::pair<FunctionDecl*, FunctionDecl*>, 2> |
934 | DelayedEquivalentExceptionSpecChecks; |
935 | |
936 | typedef llvm::MapVector<const FunctionDecl *, |
937 | std::unique_ptr<LateParsedTemplate>> |
938 | LateParsedTemplateMapT; |
939 | LateParsedTemplateMapT LateParsedTemplateMap; |
940 | |
941 | /// Callback to the parser to parse templated functions when needed. |
942 | typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT); |
943 | typedef void LateTemplateParserCleanupCB(void *P); |
944 | LateTemplateParserCB *LateTemplateParser; |
945 | LateTemplateParserCleanupCB *LateTemplateParserCleanup; |
946 | void *OpaqueParser; |
947 | |
948 | void SetLateTemplateParser(LateTemplateParserCB *LTP, |
949 | LateTemplateParserCleanupCB *LTPCleanup, |
950 | void *P) { |
951 | LateTemplateParser = LTP; |
952 | LateTemplateParserCleanup = LTPCleanup; |
953 | OpaqueParser = P; |
954 | } |
955 | |
956 | class DelayedDiagnostics; |
957 | |
958 | class DelayedDiagnosticsState { |
959 | sema::DelayedDiagnosticPool *SavedPool = nullptr; |
960 | friend class Sema::DelayedDiagnostics; |
961 | }; |
962 | typedef DelayedDiagnosticsState ParsingDeclState; |
963 | typedef DelayedDiagnosticsState ProcessingContextState; |
964 | |
965 | /// A class which encapsulates the logic for delaying diagnostics |
966 | /// during parsing and other processing. |
967 | class DelayedDiagnostics { |
968 | /// The current pool of diagnostics into which delayed |
969 | /// diagnostics should go. |
970 | sema::DelayedDiagnosticPool *CurPool = nullptr; |
971 | |
972 | public: |
973 | DelayedDiagnostics() = default; |
974 | |
975 | /// Adds a delayed diagnostic. |
976 | void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h |
977 | |
978 | /// Determines whether diagnostics should be delayed. |
979 | bool shouldDelayDiagnostics() { return CurPool != nullptr; } |
980 | |
981 | /// Returns the current delayed-diagnostics pool. |
982 | sema::DelayedDiagnosticPool *getCurrentPool() const { |
983 | return CurPool; |
984 | } |
985 | |
986 | /// Enter a new scope. Access and deprecation diagnostics will be |
987 | /// collected in this pool. |
988 | DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) { |
989 | DelayedDiagnosticsState state; |
990 | state.SavedPool = CurPool; |
991 | CurPool = &pool; |
992 | return state; |
993 | } |
994 | |
995 | /// Leave a delayed-diagnostic state that was previously pushed. |
996 | /// Do not emit any of the diagnostics. This is performed as part |
997 | /// of the bookkeeping of popping a pool "properly". |
998 | void popWithoutEmitting(DelayedDiagnosticsState state) { |
999 | CurPool = state.SavedPool; |
1000 | } |
1001 | |
1002 | /// Enter a new scope where access and deprecation diagnostics are |
1003 | /// not delayed. |
1004 | DelayedDiagnosticsState pushUndelayed() { |
1005 | DelayedDiagnosticsState state; |
1006 | state.SavedPool = CurPool; |
1007 | CurPool = nullptr; |
1008 | return state; |
1009 | } |
1010 | |
1011 | /// Undo a previous pushUndelayed(). |
1012 | void popUndelayed(DelayedDiagnosticsState state) { |
1013 | assert(CurPool == nullptr); |
1014 | CurPool = state.SavedPool; |
1015 | } |
1016 | } DelayedDiagnostics; |
1017 | |
1018 | /// A RAII object to temporarily push a declaration context. |
1019 | class { |
1020 | private: |
1021 | Sema &; |
1022 | DeclContext *; |
1023 | ProcessingContextState ; |
1024 | QualType ; |
1025 | unsigned ; |
1026 | unsigned ; |
1027 | |
1028 | public: |
1029 | (Sema &S, DeclContext *ContextToPush, bool NewThisContext = true) |
1030 | : S(S), SavedContext(S.CurContext), |
1031 | SavedContextState(S.DelayedDiagnostics.pushUndelayed()), |
1032 | SavedCXXThisTypeOverride(S.CXXThisTypeOverride), |
1033 | SavedFunctionScopesStart(S.FunctionScopesStart), |
1034 | SavedInventedParameterInfosStart(S.InventedParameterInfosStart) |
1035 | { |
1036 | assert(ContextToPush && "pushing null context" ); |
1037 | S.CurContext = ContextToPush; |
1038 | if (NewThisContext) |
1039 | S.CXXThisTypeOverride = QualType(); |
1040 | // Any saved FunctionScopes do not refer to this context. |
1041 | S.FunctionScopesStart = S.FunctionScopes.size(); |
1042 | S.InventedParameterInfosStart = S.InventedParameterInfos.size(); |
1043 | } |
1044 | |
1045 | void () { |
1046 | if (!SavedContext) return; |
1047 | S.CurContext = SavedContext; |
1048 | S.DelayedDiagnostics.popUndelayed(SavedContextState); |
1049 | S.CXXThisTypeOverride = SavedCXXThisTypeOverride; |
1050 | S.FunctionScopesStart = SavedFunctionScopesStart; |
1051 | S.InventedParameterInfosStart = SavedInventedParameterInfosStart; |
1052 | SavedContext = nullptr; |
1053 | } |
1054 | |
1055 | () { |
1056 | pop(); |
1057 | } |
1058 | }; |
1059 | |
1060 | /// Whether the AST is currently being rebuilt to correct immediate |
1061 | /// invocations. Immediate invocation candidates and references to consteval |
1062 | /// functions aren't tracked when this is set. |
1063 | bool RebuildingImmediateInvocation = false; |
1064 | |
1065 | /// Used to change context to isConstantEvaluated without pushing a heavy |
1066 | /// ExpressionEvaluationContextRecord object. |
1067 | bool isConstantEvaluatedOverride; |
1068 | |
1069 | bool isConstantEvaluated() const { |
1070 | return ExprEvalContexts.back().isConstantEvaluated() || |
1071 | isConstantEvaluatedOverride; |
1072 | } |
1073 | |
1074 | /// RAII object to handle the state changes required to synthesize |
1075 | /// a function body. |
1076 | class SynthesizedFunctionScope { |
1077 | Sema &S; |
1078 | Sema::ContextRAII SavedContext; |
1079 | bool PushedCodeSynthesisContext = false; |
1080 | |
1081 | public: |
1082 | SynthesizedFunctionScope(Sema &S, DeclContext *DC) |
1083 | : S(S), SavedContext(S, DC) { |
1084 | auto *FD = dyn_cast<FunctionDecl>(DC); |
1085 | S.PushFunctionScope(); |
1086 | S.PushExpressionEvaluationContext( |
1087 | (FD && FD->isConsteval()) |
1088 | ? ExpressionEvaluationContext::ImmediateFunctionContext |
1089 | : ExpressionEvaluationContext::PotentiallyEvaluated); |
1090 | if (FD) { |
1091 | FD->setWillHaveBody(true); |
1092 | S.ExprEvalContexts.back().InImmediateFunctionContext = |
1093 | FD->isImmediateFunction(); |
1094 | S.ExprEvalContexts.back().InImmediateEscalatingFunctionContext = |
1095 | S.getLangOpts().CPlusPlus20 && FD->isImmediateEscalating(); |
1096 | } else |
1097 | assert(isa<ObjCMethodDecl>(DC)); |
1098 | } |
1099 | |
1100 | void addContextNote(SourceLocation UseLoc) { |
1101 | assert(!PushedCodeSynthesisContext); |
1102 | |
1103 | Sema::CodeSynthesisContext Ctx; |
1104 | Ctx.Kind = Sema::CodeSynthesisContext::DefiningSynthesizedFunction; |
1105 | Ctx.PointOfInstantiation = UseLoc; |
1106 | Ctx.Entity = cast<Decl>(S.CurContext); |
1107 | S.pushCodeSynthesisContext(Ctx); |
1108 | |
1109 | PushedCodeSynthesisContext = true; |
1110 | } |
1111 | |
1112 | ~SynthesizedFunctionScope() { |
1113 | if (PushedCodeSynthesisContext) |
1114 | S.popCodeSynthesisContext(); |
1115 | if (auto *FD = dyn_cast<FunctionDecl>(S.CurContext)) { |
1116 | FD->setWillHaveBody(false); |
1117 | S.CheckImmediateEscalatingFunctionDefinition(FD, S.getCurFunction()); |
1118 | } |
1119 | S.PopExpressionEvaluationContext(); |
1120 | S.PopFunctionScopeInfo(); |
1121 | } |
1122 | }; |
1123 | |
1124 | /// WeakUndeclaredIdentifiers - Identifiers contained in \#pragma weak before |
1125 | /// declared. Rare. May alias another identifier, declared or undeclared. |
1126 | /// |
1127 | /// For aliases, the target identifier is used as a key for eventual |
1128 | /// processing when the target is declared. For the single-identifier form, |
1129 | /// the sole identifier is used as the key. Each entry is a `SetVector` |
1130 | /// (ordered by parse order) of aliases (identified by the alias name) in case |
1131 | /// of multiple aliases to the same undeclared identifier. |
1132 | llvm::MapVector< |
1133 | IdentifierInfo *, |
1134 | llvm::SetVector< |
1135 | WeakInfo, llvm::SmallVector<WeakInfo, 1u>, |
1136 | llvm::SmallDenseSet<WeakInfo, 2u, WeakInfo::DenseMapInfoByAliasOnly>>> |
1137 | WeakUndeclaredIdentifiers; |
1138 | |
1139 | /// ExtnameUndeclaredIdentifiers - Identifiers contained in |
1140 | /// \#pragma redefine_extname before declared. Used in Solaris system headers |
1141 | /// to define functions that occur in multiple standards to call the version |
1142 | /// in the currently selected standard. |
1143 | llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers; |
1144 | |
1145 | |
1146 | /// Load weak undeclared identifiers from the external source. |
1147 | void LoadExternalWeakUndeclaredIdentifiers(); |
1148 | |
1149 | /// WeakTopLevelDecl - Translation-unit scoped declarations generated by |
1150 | /// \#pragma weak during processing of other Decls. |
1151 | /// I couldn't figure out a clean way to generate these in-line, so |
1152 | /// we store them here and handle separately -- which is a hack. |
1153 | /// It would be best to refactor this. |
1154 | SmallVector<Decl*,2> WeakTopLevelDecl; |
1155 | |
1156 | IdentifierResolver IdResolver; |
1157 | |
1158 | /// Translation Unit Scope - useful to Objective-C actions that need |
1159 | /// to lookup file scope declarations in the "ordinary" C decl namespace. |
1160 | /// For example, user-defined classes, built-in "id" type, etc. |
1161 | Scope *TUScope; |
1162 | |
1163 | /// The C++ "std" namespace, where the standard library resides. |
1164 | LazyDeclPtr StdNamespace; |
1165 | |
1166 | /// The C++ "std::bad_alloc" class, which is defined by the C++ |
1167 | /// standard library. |
1168 | LazyDeclPtr StdBadAlloc; |
1169 | |
1170 | /// The C++ "std::align_val_t" enum class, which is defined by the C++ |
1171 | /// standard library. |
1172 | LazyDeclPtr StdAlignValT; |
1173 | |
1174 | /// The C++ "std::initializer_list" template, which is defined in |
1175 | /// \<initializer_list>. |
1176 | ClassTemplateDecl *StdInitializerList; |
1177 | |
1178 | /// The C++ "std::coroutine_traits" template, which is defined in |
1179 | /// \<coroutine_traits> |
1180 | ClassTemplateDecl *StdCoroutineTraitsCache; |
1181 | |
1182 | /// The C++ "type_info" declaration, which is defined in \<typeinfo>. |
1183 | RecordDecl *CXXTypeInfoDecl; |
1184 | |
1185 | /// The C++ "std::source_location::__impl" struct, defined in |
1186 | /// \<source_location>. |
1187 | RecordDecl *StdSourceLocationImplDecl; |
1188 | |
1189 | /// Caches identifiers/selectors for NSFoundation APIs. |
1190 | std::unique_ptr<NSAPI> NSAPIObj; |
1191 | |
1192 | /// The declaration of the Objective-C NSNumber class. |
1193 | ObjCInterfaceDecl *NSNumberDecl; |
1194 | |
1195 | /// The declaration of the Objective-C NSValue class. |
1196 | ObjCInterfaceDecl *NSValueDecl; |
1197 | |
1198 | /// Pointer to NSNumber type (NSNumber *). |
1199 | QualType NSNumberPointer; |
1200 | |
1201 | /// Pointer to NSValue type (NSValue *). |
1202 | QualType NSValuePointer; |
1203 | |
1204 | /// The Objective-C NSNumber methods used to create NSNumber literals. |
1205 | ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]; |
1206 | |
1207 | /// The declaration of the Objective-C NSString class. |
1208 | ObjCInterfaceDecl *NSStringDecl; |
1209 | |
1210 | /// Pointer to NSString type (NSString *). |
1211 | QualType NSStringPointer; |
1212 | |
1213 | /// The declaration of the stringWithUTF8String: method. |
1214 | ObjCMethodDecl *StringWithUTF8StringMethod; |
1215 | |
1216 | /// The declaration of the valueWithBytes:objCType: method. |
1217 | ObjCMethodDecl *ValueWithBytesObjCTypeMethod; |
1218 | |
1219 | /// The declaration of the Objective-C NSArray class. |
1220 | ObjCInterfaceDecl *NSArrayDecl; |
1221 | |
1222 | /// The declaration of the arrayWithObjects:count: method. |
1223 | ObjCMethodDecl *ArrayWithObjectsMethod; |
1224 | |
1225 | /// The declaration of the Objective-C NSDictionary class. |
1226 | ObjCInterfaceDecl *NSDictionaryDecl; |
1227 | |
1228 | /// The declaration of the dictionaryWithObjects:forKeys:count: method. |
1229 | ObjCMethodDecl *DictionaryWithObjectsMethod; |
1230 | |
1231 | /// id<NSCopying> type. |
1232 | QualType QIDNSCopying; |
1233 | |
1234 | /// will hold 'respondsToSelector:' |
1235 | Selector RespondsToSelectorSel; |
1236 | |
1237 | /// A flag to remember whether the implicit forms of operator new and delete |
1238 | /// have been declared. |
1239 | bool GlobalNewDeleteDeclared; |
1240 | |
1241 | /// Describes how the expressions currently being parsed are |
1242 | /// evaluated at run-time, if at all. |
1243 | enum class ExpressionEvaluationContext { |
1244 | /// The current expression and its subexpressions occur within an |
1245 | /// unevaluated operand (C++11 [expr]p7), such as the subexpression of |
1246 | /// \c sizeof, where the type of the expression may be significant but |
1247 | /// no code will be generated to evaluate the value of the expression at |
1248 | /// run time. |
1249 | Unevaluated, |
1250 | |
1251 | /// The current expression occurs within a braced-init-list within |
1252 | /// an unevaluated operand. This is mostly like a regular unevaluated |
1253 | /// context, except that we still instantiate constexpr functions that are |
1254 | /// referenced here so that we can perform narrowing checks correctly. |
1255 | UnevaluatedList, |
1256 | |
1257 | /// The current expression occurs within a discarded statement. |
1258 | /// This behaves largely similarly to an unevaluated operand in preventing |
1259 | /// definitions from being required, but not in other ways. |
1260 | DiscardedStatement, |
1261 | |
1262 | /// The current expression occurs within an unevaluated |
1263 | /// operand that unconditionally permits abstract references to |
1264 | /// fields, such as a SIZE operator in MS-style inline assembly. |
1265 | UnevaluatedAbstract, |
1266 | |
1267 | /// The current context is "potentially evaluated" in C++11 terms, |
1268 | /// but the expression is evaluated at compile-time (like the values of |
1269 | /// cases in a switch statement). |
1270 | ConstantEvaluated, |
1271 | |
1272 | /// In addition of being constant evaluated, the current expression |
1273 | /// occurs in an immediate function context - either a consteval function |
1274 | /// or a consteval if statement. |
1275 | ImmediateFunctionContext, |
1276 | |
1277 | /// The current expression is potentially evaluated at run time, |
1278 | /// which means that code may be generated to evaluate the value of the |
1279 | /// expression at run time. |
1280 | PotentiallyEvaluated, |
1281 | |
1282 | /// The current expression is potentially evaluated, but any |
1283 | /// declarations referenced inside that expression are only used if |
1284 | /// in fact the current expression is used. |
1285 | /// |
1286 | /// This value is used when parsing default function arguments, for which |
1287 | /// we would like to provide diagnostics (e.g., passing non-POD arguments |
1288 | /// through varargs) but do not want to mark declarations as "referenced" |
1289 | /// until the default argument is used. |
1290 | PotentiallyEvaluatedIfUsed |
1291 | }; |
1292 | |
1293 | using ImmediateInvocationCandidate = llvm::PointerIntPair<ConstantExpr *, 1>; |
1294 | |
1295 | /// Data structure used to record current or nested |
1296 | /// expression evaluation contexts. |
1297 | struct ExpressionEvaluationContextRecord { |
1298 | /// The expression evaluation context. |
1299 | ExpressionEvaluationContext Context; |
1300 | |
1301 | /// Whether the enclosing context needed a cleanup. |
1302 | CleanupInfo ParentCleanup; |
1303 | |
1304 | /// The number of active cleanup objects when we entered |
1305 | /// this expression evaluation context. |
1306 | unsigned NumCleanupObjects; |
1307 | |
1308 | /// The number of typos encountered during this expression evaluation |
1309 | /// context (i.e. the number of TypoExprs created). |
1310 | unsigned NumTypos; |
1311 | |
1312 | MaybeODRUseExprSet SavedMaybeODRUseExprs; |
1313 | |
1314 | /// The lambdas that are present within this context, if it |
1315 | /// is indeed an unevaluated context. |
1316 | SmallVector<LambdaExpr *, 2> Lambdas; |
1317 | |
1318 | /// The declaration that provides context for lambda expressions |
1319 | /// and block literals if the normal declaration context does not |
1320 | /// suffice, e.g., in a default function argument. |
1321 | Decl *ManglingContextDecl; |
1322 | |
1323 | /// If we are processing a decltype type, a set of call expressions |
1324 | /// for which we have deferred checking the completeness of the return type. |
1325 | SmallVector<CallExpr *, 8> DelayedDecltypeCalls; |
1326 | |
1327 | /// If we are processing a decltype type, a set of temporary binding |
1328 | /// expressions for which we have deferred checking the destructor. |
1329 | SmallVector<CXXBindTemporaryExpr *, 8> DelayedDecltypeBinds; |
1330 | |
1331 | llvm::SmallPtrSet<const Expr *, 8> PossibleDerefs; |
1332 | |
1333 | /// Expressions appearing as the LHS of a volatile assignment in this |
1334 | /// context. We produce a warning for these when popping the context if |
1335 | /// they are not discarded-value expressions nor unevaluated operands. |
1336 | SmallVector<Expr*, 2> VolatileAssignmentLHSs; |
1337 | |
1338 | /// Set of candidates for starting an immediate invocation. |
1339 | llvm::SmallVector<ImmediateInvocationCandidate, 4> ImmediateInvocationCandidates; |
1340 | |
1341 | /// Set of DeclRefExprs referencing a consteval function when used in a |
1342 | /// context not already known to be immediately invoked. |
1343 | llvm::SmallPtrSet<DeclRefExpr *, 4> ReferenceToConsteval; |
1344 | |
1345 | /// \brief Describes whether we are in an expression constext which we have |
1346 | /// to handle differently. |
1347 | enum ExpressionKind { |
1348 | EK_Decltype, EK_TemplateArgument, EK_Other |
1349 | } ExprContext; |
1350 | |
1351 | // A context can be nested in both a discarded statement context and |
1352 | // an immediate function context, so they need to be tracked independently. |
1353 | bool InDiscardedStatement; |
1354 | bool InImmediateFunctionContext; |
1355 | bool InImmediateEscalatingFunctionContext; |
1356 | |
1357 | bool IsCurrentlyCheckingDefaultArgumentOrInitializer = false; |
1358 | |
1359 | // When evaluating immediate functions in the initializer of a default |
1360 | // argument or default member initializer, this is the declaration whose |
1361 | // default initializer is being evaluated and the location of the call |
1362 | // or constructor definition. |
1363 | struct InitializationContext { |
1364 | InitializationContext(SourceLocation Loc, ValueDecl *Decl, |
1365 | DeclContext *Context) |
1366 | : Loc(Loc), Decl(Decl), Context(Context) { |
1367 | assert(Decl && Context && "invalid initialization context" ); |
1368 | } |
1369 | |
1370 | SourceLocation Loc; |
1371 | ValueDecl *Decl = nullptr; |
1372 | DeclContext *Context = nullptr; |
1373 | }; |
1374 | std::optional<InitializationContext> DelayedDefaultInitializationContext; |
1375 | |
1376 | ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context, |
1377 | unsigned NumCleanupObjects, |
1378 | CleanupInfo ParentCleanup, |
1379 | Decl *ManglingContextDecl, |
1380 | ExpressionKind ExprContext) |
1381 | : Context(Context), ParentCleanup(ParentCleanup), |
1382 | NumCleanupObjects(NumCleanupObjects), NumTypos(0), |
1383 | ManglingContextDecl(ManglingContextDecl), ExprContext(ExprContext), |
1384 | InDiscardedStatement(false), InImmediateFunctionContext(false), |
1385 | InImmediateEscalatingFunctionContext(false) {} |
1386 | |
1387 | bool isUnevaluated() const { |
1388 | return Context == ExpressionEvaluationContext::Unevaluated || |
1389 | Context == ExpressionEvaluationContext::UnevaluatedAbstract || |
1390 | Context == ExpressionEvaluationContext::UnevaluatedList; |
1391 | } |
1392 | |
1393 | bool isConstantEvaluated() const { |
1394 | return Context == ExpressionEvaluationContext::ConstantEvaluated || |
1395 | Context == ExpressionEvaluationContext::ImmediateFunctionContext; |
1396 | } |
1397 | |
1398 | bool isImmediateFunctionContext() const { |
1399 | return Context == ExpressionEvaluationContext::ImmediateFunctionContext || |
1400 | (Context == ExpressionEvaluationContext::DiscardedStatement && |
1401 | InImmediateFunctionContext) || |
1402 | // C++23 [expr.const]p14: |
1403 | // An expression or conversion is in an immediate function |
1404 | // context if it is potentially evaluated and either: |
1405 | // * its innermost enclosing non-block scope is a function |
1406 | // parameter scope of an immediate function, or |
1407 | // * its enclosing statement is enclosed by the compound- |
1408 | // statement of a consteval if statement. |
1409 | (Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
1410 | InImmediateFunctionContext); |
1411 | } |
1412 | |
1413 | bool isDiscardedStatementContext() const { |
1414 | return Context == ExpressionEvaluationContext::DiscardedStatement || |
1415 | (Context == |
1416 | ExpressionEvaluationContext::ImmediateFunctionContext && |
1417 | InDiscardedStatement); |
1418 | } |
1419 | }; |
1420 | |
1421 | /// A stack of expression evaluation contexts. |
1422 | SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts; |
1423 | |
1424 | // Set of failed immediate invocations to avoid double diagnosing. |
1425 | llvm::SmallPtrSet<ConstantExpr *, 4> FailedImmediateInvocations; |
1426 | |
1427 | /// Emit a warning for all pending noderef expressions that we recorded. |
1428 | void WarnOnPendingNoDerefs(ExpressionEvaluationContextRecord &Rec); |
1429 | |
1430 | /// Compute the mangling number context for a lambda expression or |
1431 | /// block literal. Also return the extra mangling decl if any. |
1432 | /// |
1433 | /// \param DC - The DeclContext containing the lambda expression or |
1434 | /// block literal. |
1435 | std::tuple<MangleNumberingContext *, Decl *> |
1436 | getCurrentMangleNumberContext(const DeclContext *DC); |
1437 | |
1438 | |
1439 | /// SpecialMemberOverloadResult - The overloading result for a special member |
1440 | /// function. |
1441 | /// |
1442 | /// This is basically a wrapper around PointerIntPair. The lowest bits of the |
1443 | /// integer are used to determine whether overload resolution succeeded. |
1444 | class SpecialMemberOverloadResult { |
1445 | public: |
1446 | enum Kind { |
1447 | NoMemberOrDeleted, |
1448 | Ambiguous, |
1449 | Success |
1450 | }; |
1451 | |
1452 | private: |
1453 | llvm::PointerIntPair<CXXMethodDecl *, 2> Pair; |
1454 | |
1455 | public: |
1456 | SpecialMemberOverloadResult() {} |
1457 | SpecialMemberOverloadResult(CXXMethodDecl *MD) |
1458 | : Pair(MD, MD->isDeleted() ? NoMemberOrDeleted : Success) {} |
1459 | |
1460 | CXXMethodDecl *getMethod() const { return Pair.getPointer(); } |
1461 | void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); } |
1462 | |
1463 | Kind getKind() const { return static_cast<Kind>(Pair.getInt()); } |
1464 | void setKind(Kind K) { Pair.setInt(K); } |
1465 | }; |
1466 | |
1467 | class SpecialMemberOverloadResultEntry |
1468 | : public llvm::FastFoldingSetNode, |
1469 | public SpecialMemberOverloadResult { |
1470 | public: |
1471 | SpecialMemberOverloadResultEntry(const llvm::FoldingSetNodeID &ID) |
1472 | : FastFoldingSetNode(ID) |
1473 | {} |
1474 | }; |
1475 | |
1476 | /// A cache of special member function overload resolution results |
1477 | /// for C++ records. |
1478 | llvm::FoldingSet<SpecialMemberOverloadResultEntry> SpecialMemberCache; |
1479 | |
1480 | /// A cache of the flags available in enumerations with the flag_bits |
1481 | /// attribute. |
1482 | mutable llvm::DenseMap<const EnumDecl*, llvm::APInt> FlagBitsCache; |
1483 | |
1484 | /// The kind of translation unit we are processing. |
1485 | /// |
1486 | /// When we're processing a complete translation unit, Sema will perform |
1487 | /// end-of-translation-unit semantic tasks (such as creating |
1488 | /// initializers for tentative definitions in C) once parsing has |
1489 | /// completed. Modules and precompiled headers perform different kinds of |
1490 | /// checks. |
1491 | const TranslationUnitKind TUKind; |
1492 | |
1493 | llvm::BumpPtrAllocator BumpAlloc; |
1494 | |
1495 | /// The number of SFINAE diagnostics that have been trapped. |
1496 | unsigned NumSFINAEErrors; |
1497 | |
1498 | typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>> |
1499 | UnparsedDefaultArgInstantiationsMap; |
1500 | |
1501 | /// A mapping from parameters with unparsed default arguments to the |
1502 | /// set of instantiations of each parameter. |
1503 | /// |
1504 | /// This mapping is a temporary data structure used when parsing |
1505 | /// nested class templates or nested classes of class templates, |
1506 | /// where we might end up instantiating an inner class before the |
1507 | /// default arguments of its methods have been parsed. |
1508 | UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations; |
1509 | |
1510 | // Contains the locations of the beginning of unparsed default |
1511 | // argument locations. |
1512 | llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs; |
1513 | |
1514 | /// UndefinedInternals - all the used, undefined objects which require a |
1515 | /// definition in this translation unit. |
1516 | llvm::MapVector<NamedDecl *, SourceLocation> UndefinedButUsed; |
1517 | |
1518 | /// Determine if VD, which must be a variable or function, is an external |
1519 | /// symbol that nonetheless can't be referenced from outside this translation |
1520 | /// unit because its type has no linkage and it's not extern "C". |
1521 | bool isExternalWithNoLinkageType(const ValueDecl *VD) const; |
1522 | |
1523 | /// Obtain a sorted list of functions that are undefined but ODR-used. |
1524 | void getUndefinedButUsed( |
1525 | SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined); |
1526 | |
1527 | /// Retrieves list of suspicious delete-expressions that will be checked at |
1528 | /// the end of translation unit. |
1529 | const llvm::MapVector<FieldDecl *, DeleteLocs> & |
1530 | getMismatchingDeleteExpressions() const; |
1531 | |
1532 | class GlobalMethodPool { |
1533 | public: |
1534 | using Lists = std::pair<ObjCMethodList, ObjCMethodList>; |
1535 | using iterator = llvm::DenseMap<Selector, Lists>::iterator; |
1536 | iterator begin() { return Methods.begin(); } |
1537 | iterator end() { return Methods.end(); } |
1538 | iterator find(Selector Sel) { return Methods.find(Sel); } |
1539 | std::pair<iterator, bool> insert(std::pair<Selector, Lists> &&Val) { |
1540 | return Methods.insert(Val); |
1541 | } |
1542 | int count(Selector Sel) const { return Methods.count(Sel); } |
1543 | bool empty() const { return Methods.empty(); } |
1544 | |
1545 | private: |
1546 | llvm::DenseMap<Selector, Lists> Methods; |
1547 | }; |
1548 | |
1549 | /// Method Pool - allows efficient lookup when typechecking messages to "id". |
1550 | /// We need to maintain a list, since selectors can have differing signatures |
1551 | /// across classes. In Cocoa, this happens to be extremely uncommon (only 1% |
1552 | /// of selectors are "overloaded"). |
1553 | /// At the head of the list it is recorded whether there were 0, 1, or >= 2 |
1554 | /// methods inside categories with a particular selector. |
1555 | GlobalMethodPool MethodPool; |
1556 | |
1557 | /// Method selectors used in a \@selector expression. Used for implementation |
1558 | /// of -Wselector. |
1559 | llvm::MapVector<Selector, SourceLocation> ReferencedSelectors; |
1560 | |
1561 | /// List of SourceLocations where 'self' is implicitly retained inside a |
1562 | /// block. |
1563 | llvm::SmallVector<std::pair<SourceLocation, const BlockDecl *>, 1> |
1564 | ImplicitlyRetainedSelfLocs; |
1565 | |
1566 | /// Kinds of C++ special members. |
1567 | enum CXXSpecialMember { |
1568 | CXXDefaultConstructor, |
1569 | CXXCopyConstructor, |
1570 | CXXMoveConstructor, |
1571 | CXXCopyAssignment, |
1572 | CXXMoveAssignment, |
1573 | CXXDestructor, |
1574 | CXXInvalid |
1575 | }; |
1576 | |
1577 | typedef llvm::PointerIntPair<CXXRecordDecl *, 3, CXXSpecialMember> |
1578 | SpecialMemberDecl; |
1579 | |
1580 | /// The C++ special members which we are currently in the process of |
1581 | /// declaring. If this process recursively triggers the declaration of the |
1582 | /// same special member, we should act as if it is not yet declared. |
1583 | llvm::SmallPtrSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared; |
1584 | |
1585 | /// Kinds of defaulted comparison operator functions. |
1586 | enum class DefaultedComparisonKind : unsigned char { |
1587 | /// This is not a defaultable comparison operator. |
1588 | None, |
1589 | /// This is an operator== that should be implemented as a series of |
1590 | /// subobject comparisons. |
1591 | Equal, |
1592 | /// This is an operator<=> that should be implemented as a series of |
1593 | /// subobject comparisons. |
1594 | ThreeWay, |
1595 | /// This is an operator!= that should be implemented as a rewrite in terms |
1596 | /// of a == comparison. |
1597 | NotEqual, |
1598 | /// This is an <, <=, >, or >= that should be implemented as a rewrite in |
1599 | /// terms of a <=> comparison. |
1600 | Relational, |
1601 | }; |
1602 | |
1603 | /// The function definitions which were renamed as part of typo-correction |
1604 | /// to match their respective declarations. We want to keep track of them |
1605 | /// to ensure that we don't emit a "redefinition" error if we encounter a |
1606 | /// correctly named definition after the renamed definition. |
1607 | llvm::SmallPtrSet<const NamedDecl *, 4> TypoCorrectedFunctionDefinitions; |
1608 | |
1609 | /// Stack of types that correspond to the parameter entities that are |
1610 | /// currently being copy-initialized. Can be empty. |
1611 | llvm::SmallVector<QualType, 4> CurrentParameterCopyTypes; |
1612 | |
1613 | void ReadMethodPool(Selector Sel); |
1614 | void updateOutOfDateSelector(Selector Sel); |
1615 | |
1616 | /// Private Helper predicate to check for 'self'. |
1617 | bool isSelfExpr(Expr *RExpr); |
1618 | bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method); |
1619 | |
1620 | /// Cause the active diagnostic on the DiagosticsEngine to be |
1621 | /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and |
1622 | /// should not be used elsewhere. |
1623 | void EmitCurrentDiagnostic(unsigned DiagID); |
1624 | |
1625 | /// Records and restores the CurFPFeatures state on entry/exit of compound |
1626 | /// statements. |
1627 | class FPFeaturesStateRAII { |
1628 | public: |
1629 | FPFeaturesStateRAII(Sema &S); |
1630 | ~FPFeaturesStateRAII(); |
1631 | FPOptionsOverride getOverrides() { return OldOverrides; } |
1632 | |
1633 | private: |
1634 | Sema& S; |
1635 | FPOptions OldFPFeaturesState; |
1636 | FPOptionsOverride OldOverrides; |
1637 | LangOptions::FPEvalMethodKind OldEvalMethod; |
1638 | SourceLocation OldFPPragmaLocation; |
1639 | }; |
1640 | |
1641 | void addImplicitTypedef(StringRef Name, QualType T); |
1642 | |
1643 | bool WarnedStackExhausted = false; |
1644 | |
1645 | /// Increment when we find a reference; decrement when we find an ignored |
1646 | /// assignment. Ultimately the value is 0 if every reference is an ignored |
1647 | /// assignment. |
1648 | llvm::DenseMap<const VarDecl *, int> RefsMinusAssignments; |
1649 | |
1650 | /// Indicate RISC-V vector builtin functions enabled or not. |
1651 | bool DeclareRISCVVBuiltins = false; |
1652 | |
1653 | /// Indicate RISC-V SiFive vector builtin functions enabled or not. |
1654 | bool DeclareRISCVSiFiveVectorBuiltins = false; |
1655 | |
1656 | private: |
1657 | std::unique_ptr<sema::RISCVIntrinsicManager> RVIntrinsicManager; |
1658 | |
1659 | std::optional<std::unique_ptr<DarwinSDKInfo>> CachedDarwinSDKInfo; |
1660 | |
1661 | bool WarnedDarwinSDKInfoMissing = false; |
1662 | |
1663 | public: |
1664 | Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, |
1665 | TranslationUnitKind TUKind = TU_Complete, |
1666 | CodeCompleteConsumer *CompletionConsumer = nullptr); |
1667 | ~Sema(); |
1668 | |
1669 | /// Perform initialization that occurs after the parser has been |
1670 | /// initialized but before it parses anything. |
1671 | void Initialize(); |
1672 | |
1673 | /// This virtual key function only exists to limit the emission of debug info |
1674 | /// describing the Sema class. GCC and Clang only emit debug info for a class |
1675 | /// with a vtable when the vtable is emitted. Sema is final and not |
1676 | /// polymorphic, but the debug info size savings are so significant that it is |
1677 | /// worth adding a vtable just to take advantage of this optimization. |
1678 | virtual void anchor(); |
1679 | |
1680 | const LangOptions &getLangOpts() const { return LangOpts; } |
1681 | OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; } |
1682 | FPOptions &getCurFPFeatures() { return CurFPFeatures; } |
1683 | |
1684 | DiagnosticsEngine &getDiagnostics() const { return Diags; } |
1685 | SourceManager &getSourceManager() const { return SourceMgr; } |
1686 | Preprocessor &getPreprocessor() const { return PP; } |
1687 | ASTContext &getASTContext() const { return Context; } |
1688 | ASTConsumer &getASTConsumer() const { return Consumer; } |
1689 | ASTMutationListener *getASTMutationListener() const; |
1690 | ExternalSemaSource *getExternalSource() const { return ExternalSource.get(); } |
1691 | |
1692 | DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(SourceLocation Loc, |
1693 | StringRef Platform); |
1694 | DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(); |
1695 | |
1696 | ///Registers an external source. If an external source already exists, |
1697 | /// creates a multiplex external source and appends to it. |
1698 | /// |
1699 | ///\param[in] E - A non-null external sema source. |
1700 | /// |
1701 | void addExternalSource(ExternalSemaSource *E); |
1702 | |
1703 | void PrintStats() const; |
1704 | |
1705 | /// Warn that the stack is nearly exhausted. |
1706 | void warnStackExhausted(SourceLocation Loc); |
1707 | |
1708 | /// Run some code with "sufficient" stack space. (Currently, at least 256K is |
1709 | /// guaranteed). Produces a warning if we're low on stack space and allocates |
1710 | /// more in that case. Use this in code that may recurse deeply (for example, |
1711 | /// in template instantiation) to avoid stack overflow. |
1712 | void runWithSufficientStackSpace(SourceLocation Loc, |
1713 | llvm::function_ref<void()> Fn); |
1714 | |
1715 | /// Helper class that creates diagnostics with optional |
1716 | /// template instantiation stacks. |
1717 | /// |
1718 | /// This class provides a wrapper around the basic DiagnosticBuilder |
1719 | /// class that emits diagnostics. ImmediateDiagBuilder is |
1720 | /// responsible for emitting the diagnostic (as DiagnosticBuilder |
1721 | /// does) and, if the diagnostic comes from inside a template |
1722 | /// instantiation, printing the template instantiation stack as |
1723 | /// well. |
1724 | class ImmediateDiagBuilder : public DiagnosticBuilder { |
1725 | Sema &SemaRef; |
1726 | unsigned DiagID; |
1727 | |
1728 | public: |
1729 | ImmediateDiagBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID) |
1730 | : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) {} |
1731 | ImmediateDiagBuilder(DiagnosticBuilder &&DB, Sema &SemaRef, unsigned DiagID) |
1732 | : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) {} |
1733 | |
1734 | // This is a cunning lie. DiagnosticBuilder actually performs move |
1735 | // construction in its copy constructor (but due to varied uses, it's not |
1736 | // possible to conveniently express this as actual move construction). So |
1737 | // the default copy ctor here is fine, because the base class disables the |
1738 | // source anyway, so the user-defined ~ImmediateDiagBuilder is a safe no-op |
1739 | // in that case anwyay. |
1740 | ImmediateDiagBuilder(const ImmediateDiagBuilder &) = default; |
1741 | |
1742 | ~ImmediateDiagBuilder() { |
1743 | // If we aren't active, there is nothing to do. |
1744 | if (!isActive()) return; |
1745 | |
1746 | // Otherwise, we need to emit the diagnostic. First clear the diagnostic |
1747 | // builder itself so it won't emit the diagnostic in its own destructor. |
1748 | // |
1749 | // This seems wasteful, in that as written the DiagnosticBuilder dtor will |
1750 | // do its own needless checks to see if the diagnostic needs to be |
1751 | // emitted. However, because we take care to ensure that the builder |
1752 | // objects never escape, a sufficiently smart compiler will be able to |
1753 | // eliminate that code. |
1754 | Clear(); |
1755 | |
1756 | // Dispatch to Sema to emit the diagnostic. |
1757 | SemaRef.EmitCurrentDiagnostic(DiagID); |
1758 | } |
1759 | |
1760 | /// Teach operator<< to produce an object of the correct type. |
1761 | template <typename T> |
1762 | friend const ImmediateDiagBuilder & |
1763 | operator<<(const ImmediateDiagBuilder &Diag, const T &Value) { |
1764 | const DiagnosticBuilder &BaseDiag = Diag; |
1765 | BaseDiag << Value; |
1766 | return Diag; |
1767 | } |
1768 | |
1769 | // It is necessary to limit this to rvalue reference to avoid calling this |
1770 | // function with a bitfield lvalue argument since non-const reference to |
1771 | // bitfield is not allowed. |
1772 | template <typename T, |
1773 | typename = std::enable_if_t<!std::is_lvalue_reference<T>::value>> |
1774 | const ImmediateDiagBuilder &operator<<(T &&V) const { |
1775 | const DiagnosticBuilder &BaseDiag = *this; |
1776 | BaseDiag << std::move(V); |
1777 | return *this; |
1778 | } |
1779 | }; |
1780 | |
1781 | /// A generic diagnostic builder for errors which may or may not be deferred. |
1782 | /// |
1783 | /// In CUDA, there exist constructs (e.g. variable-length arrays, try/catch) |
1784 | /// which are not allowed to appear inside __device__ functions and are |
1785 | /// allowed to appear in __host__ __device__ functions only if the host+device |
1786 | /// function is never codegen'ed. |
1787 | /// |
1788 | /// To handle this, we use the notion of "deferred diagnostics", where we |
1789 | /// attach a diagnostic to a FunctionDecl that's emitted iff it's codegen'ed. |
1790 | /// |
1791 | /// This class lets you emit either a regular diagnostic, a deferred |
1792 | /// diagnostic, or no diagnostic at all, according to an argument you pass to |
1793 | /// its constructor, thus simplifying the process of creating these "maybe |
1794 | /// deferred" diagnostics. |
1795 | class SemaDiagnosticBuilder { |
1796 | public: |
1797 | enum Kind { |
1798 | /// Emit no diagnostics. |
1799 | K_Nop, |
1800 | /// Emit the diagnostic immediately (i.e., behave like Sema::Diag()). |
1801 | K_Immediate, |
1802 | /// Emit the diagnostic immediately, and, if it's a warning or error, also |
1803 | /// emit a call stack showing how this function can be reached by an a |
1804 | /// priori known-emitted function. |
1805 | K_ImmediateWithCallStack, |
1806 | /// Create a deferred diagnostic, which is emitted only if the function |
1807 | /// it's attached to is codegen'ed. Also emit a call stack as with |
1808 | /// K_ImmediateWithCallStack. |
1809 | K_Deferred |
1810 | }; |
1811 | |
1812 | SemaDiagnosticBuilder(Kind K, SourceLocation Loc, unsigned DiagID, |
1813 | const FunctionDecl *Fn, Sema &S); |
1814 | SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D); |
1815 | SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default; |
1816 | |
1817 | // The copy and move assignment operator is defined as deleted pending |
1818 | // further motivation. |
1819 | SemaDiagnosticBuilder &operator=(const SemaDiagnosticBuilder &) = delete; |
1820 | SemaDiagnosticBuilder &operator=(SemaDiagnosticBuilder &&) = delete; |
1821 | |
1822 | ~SemaDiagnosticBuilder(); |
1823 | |
1824 | bool isImmediate() const { return ImmediateDiag.has_value(); } |
1825 | |
1826 | /// Convertible to bool: True if we immediately emitted an error, false if |
1827 | /// we didn't emit an error or we created a deferred error. |
1828 | /// |
1829 | /// Example usage: |
1830 | /// |
1831 | /// if (SemaDiagnosticBuilder(...) << foo << bar) |
1832 | /// return ExprError(); |
1833 | /// |
1834 | /// But see CUDADiagIfDeviceCode() and CUDADiagIfHostCode() -- you probably |
1835 | /// want to use these instead of creating a SemaDiagnosticBuilder yourself. |
1836 | operator bool() const { return isImmediate(); } |
1837 | |
1838 | template <typename T> |
1839 | friend const SemaDiagnosticBuilder & |
1840 | operator<<(const SemaDiagnosticBuilder &Diag, const T &Value) { |
1841 | if (Diag.ImmediateDiag) |
1842 | *Diag.ImmediateDiag << Value; |
1843 | else if (Diag.PartialDiagId) |
1844 | Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second |
1845 | << Value; |
1846 | return Diag; |
1847 | } |
1848 | |
1849 | // It is necessary to limit this to rvalue reference to avoid calling this |
1850 | // function with a bitfield lvalue argument since non-const reference to |
1851 | // bitfield is not allowed. |
1852 | template <typename T, |
1853 | typename = std::enable_if_t<!std::is_lvalue_reference<T>::value>> |
1854 | const SemaDiagnosticBuilder &operator<<(T &&V) const { |
1855 | if (ImmediateDiag) |
1856 | *ImmediateDiag << std::move(V); |
1857 | else if (PartialDiagId) |
1858 | S.DeviceDeferredDiags[Fn][*PartialDiagId].second << std::move(V); |
1859 | return *this; |
1860 | } |
1861 | |
1862 | friend const SemaDiagnosticBuilder & |
1863 | operator<<(const SemaDiagnosticBuilder &Diag, const PartialDiagnostic &PD) { |
1864 | if (Diag.ImmediateDiag) |
1865 | PD.Emit(*Diag.ImmediateDiag); |
1866 | else if (Diag.PartialDiagId) |
1867 | Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second = PD; |
1868 | return Diag; |
1869 | } |
1870 | |
1871 | void AddFixItHint(const FixItHint &Hint) const { |
1872 | if (ImmediateDiag) |
1873 | ImmediateDiag->AddFixItHint(Hint); |
1874 | else if (PartialDiagId) |
1875 | S.DeviceDeferredDiags[Fn][*PartialDiagId].second.AddFixItHint(Hint); |
1876 | } |
1877 | |
1878 | friend ExprResult ExprError(const SemaDiagnosticBuilder &) { |
1879 | return ExprError(); |
1880 | } |
1881 | friend StmtResult StmtError(const SemaDiagnosticBuilder &) { |
1882 | return StmtError(); |
1883 | } |
1884 | operator ExprResult() const { return ExprError(); } |
1885 | operator StmtResult() const { return StmtError(); } |
1886 | operator TypeResult() const { return TypeError(); } |
1887 | operator DeclResult() const { return DeclResult(true); } |
1888 | operator MemInitResult() const { return MemInitResult(true); } |
1889 | |
1890 | private: |
1891 | Sema &S; |
1892 | SourceLocation Loc; |
1893 | unsigned DiagID; |
1894 | const FunctionDecl *Fn; |
1895 | bool ShowCallStack; |
1896 | |
1897 | // Invariant: At most one of these Optionals has a value. |
1898 | // FIXME: Switch these to a Variant once that exists. |
1899 | std::optional<ImmediateDiagBuilder> ImmediateDiag; |
1900 | std::optional<unsigned> PartialDiagId; |
1901 | }; |
1902 | |
1903 | /// Is the last error level diagnostic immediate. This is used to determined |
1904 | /// whether the next info diagnostic should be immediate. |
1905 | bool IsLastErrorImmediate = true; |
1906 | |
1907 | /// Emit a diagnostic. |
1908 | SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, |
1909 | bool DeferHint = false); |
1910 | |
1911 | /// Emit a partial diagnostic. |
1912 | SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD, |
1913 | bool DeferHint = false); |
1914 | |
1915 | /// Build a partial diagnostic. |
1916 | PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h |
1917 | |
1918 | /// Whether deferrable diagnostics should be deferred. |
1919 | bool DeferDiags = false; |
1920 | |
1921 | /// RAII class to control scope of DeferDiags. |
1922 | class DeferDiagsRAII { |
1923 | Sema &S; |
1924 | bool SavedDeferDiags = false; |
1925 | |
1926 | public: |
1927 | DeferDiagsRAII(Sema &S, bool DeferDiags) |
1928 | : S(S), SavedDeferDiags(S.DeferDiags) { |
1929 | S.DeferDiags = DeferDiags; |
1930 | } |
1931 | ~DeferDiagsRAII() { S.DeferDiags = SavedDeferDiags; } |
1932 | }; |
1933 | |
1934 | /// Whether uncompilable error has occurred. This includes error happens |
1935 | /// in deferred diagnostics. |
1936 | bool hasUncompilableErrorOccurred() const; |
1937 | |
1938 | bool findMacroSpelling(SourceLocation &loc, StringRef name); |
1939 | |
1940 | /// Get a string to suggest for zero-initialization of a type. |
1941 | std::string |
1942 | getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const; |
1943 | std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const; |
1944 | |
1945 | /// Calls \c Lexer::getLocForEndOfToken() |
1946 | SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0); |
1947 | |
1948 | /// Retrieve the module loader associated with the preprocessor. |
1949 | ModuleLoader &getModuleLoader() const; |
1950 | |
1951 | /// Invent a new identifier for parameters of abbreviated templates. |
1952 | IdentifierInfo * |
1953 | InventAbbreviatedTemplateParameterTypeName(IdentifierInfo *ParamName, |
1954 | unsigned Index); |
1955 | |
1956 | void emitAndClearUnusedLocalTypedefWarnings(); |
1957 | |
1958 | private: |
1959 | /// Function or variable declarations to be checked for whether the deferred |
1960 | /// diagnostics should be emitted. |
1961 | llvm::SmallSetVector<Decl *, 4> DeclsToCheckForDeferredDiags; |
1962 | |
1963 | public: |
1964 | // Emit all deferred diagnostics. |
1965 | void emitDeferredDiags(); |
1966 | |
1967 | enum TUFragmentKind { |
1968 | /// The global module fragment, between 'module;' and a module-declaration. |
1969 | Global, |
1970 | /// A normal translation unit fragment. For a non-module unit, this is the |
1971 | /// entire translation unit. Otherwise, it runs from the module-declaration |
1972 | /// to the private-module-fragment (if any) or the end of the TU (if not). |
1973 | Normal, |
1974 | /// The private module fragment, between 'module :private;' and the end of |
1975 | /// the translation unit. |
1976 | Private |
1977 | }; |
1978 | |
1979 | void ActOnStartOfTranslationUnit(); |
1980 | void ActOnEndOfTranslationUnit(); |
1981 | void ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind); |
1982 | |
1983 | void CheckDelegatingCtorCycles(); |
1984 | |
1985 | Scope *getScopeForContext(DeclContext *Ctx); |
1986 | |
1987 | void PushFunctionScope(); |
1988 | void PushBlockScope(Scope *BlockScope, BlockDecl *Block); |
1989 | sema::LambdaScopeInfo *PushLambdaScope(); |
1990 | |
1991 | /// This is used to inform Sema what the current TemplateParameterDepth |
1992 | /// is during Parsing. Currently it is used to pass on the depth |
1993 | /// when parsing generic lambda 'auto' parameters. |
1994 | void RecordParsingTemplateParameterDepth(unsigned Depth); |
1995 | |
1996 | void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD, |
1997 | RecordDecl *RD, CapturedRegionKind K, |
1998 | unsigned OpenMPCaptureLevel = 0); |
1999 | |
2000 | /// Custom deleter to allow FunctionScopeInfos to be kept alive for a short |
2001 | /// time after they've been popped. |
2002 | class PoppedFunctionScopeDeleter { |
2003 | Sema *Self; |
2004 | |
2005 | public: |
2006 | explicit PoppedFunctionScopeDeleter(Sema *Self) : Self(Self) {} |
2007 | void operator()(sema::FunctionScopeInfo *Scope) const; |
2008 | }; |
2009 | |
2010 | using PoppedFunctionScopePtr = |
2011 | std::unique_ptr<sema::FunctionScopeInfo, PoppedFunctionScopeDeleter>; |
2012 | |
2013 | PoppedFunctionScopePtr |
2014 | PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr, |
2015 | const Decl *D = nullptr, |
2016 | QualType BlockType = QualType()); |
2017 | |
2018 | sema::FunctionScopeInfo *getCurFunction() const { |
2019 | return FunctionScopes.empty() ? nullptr : FunctionScopes.back(); |
2020 | } |
2021 | |
2022 | sema::FunctionScopeInfo *getEnclosingFunction() const; |
2023 | |
2024 | void setFunctionHasBranchIntoScope(); |
2025 | void setFunctionHasBranchProtectedScope(); |
2026 | void setFunctionHasIndirectGoto(); |
2027 | void setFunctionHasMustTail(); |
2028 | |
2029 | void PushCompoundScope(bool IsStmtExpr); |
2030 | void PopCompoundScope(); |
2031 | |
2032 | sema::CompoundScopeInfo &getCurCompoundScope() const; |
2033 | |
2034 | bool hasAnyUnrecoverableErrorsInThisFunction() const; |
2035 | |
2036 | /// Retrieve the current block, if any. |
2037 | sema::BlockScopeInfo *getCurBlock(); |
2038 | |
2039 | /// Get the innermost lambda enclosing the current location, if any. This |
2040 | /// looks through intervening non-lambda scopes such as local functions and |
2041 | /// blocks. |
2042 | sema::LambdaScopeInfo *getEnclosingLambda() const; |
2043 | |
2044 | /// Retrieve the current lambda scope info, if any. |
2045 | /// \param IgnoreNonLambdaCapturingScope true if should find the top-most |
2046 | /// lambda scope info ignoring all inner capturing scopes that are not |
2047 | /// lambda scopes. |
2048 | sema::LambdaScopeInfo * |
2049 | getCurLambda(bool IgnoreNonLambdaCapturingScope = false); |
2050 | |
2051 | /// Retrieve the current generic lambda info, if any. |
2052 | sema::LambdaScopeInfo *getCurGenericLambda(); |
2053 | |
2054 | /// Retrieve the current captured region, if any. |
2055 | sema::CapturedRegionScopeInfo *getCurCapturedRegion(); |
2056 | |
2057 | /// Retrieve the current function, if any, that should be analyzed for |
2058 | /// potential availability violations. |
2059 | sema::FunctionScopeInfo *getCurFunctionAvailabilityContext(); |
2060 | |
2061 | /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls |
2062 | SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; } |
2063 | |
2064 | /// Called before parsing a function declarator belonging to a function |
2065 | /// declaration. |
2066 | void ActOnStartFunctionDeclarationDeclarator(Declarator &D, |
2067 | unsigned TemplateParameterDepth); |
2068 | |
2069 | /// Called after parsing a function declarator belonging to a function |
2070 | /// declaration. |
2071 | void ActOnFinishFunctionDeclarationDeclarator(Declarator &D); |
2072 | |
2073 | void (SourceRange ); |
2074 | |
2075 | //===--------------------------------------------------------------------===// |
2076 | // Type Analysis / Processing: SemaType.cpp. |
2077 | // |
2078 | |
2079 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, |
2080 | const DeclSpec *DS = nullptr); |
2081 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA, |
2082 | const DeclSpec *DS = nullptr); |
2083 | QualType BuildPointerType(QualType T, |
2084 | SourceLocation Loc, DeclarationName Entity); |
2085 | QualType BuildReferenceType(QualType T, bool LValueRef, |
2086 | SourceLocation Loc, DeclarationName Entity); |
2087 | QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, |
2088 | Expr *ArraySize, unsigned Quals, |
2089 | SourceRange Brackets, DeclarationName Entity); |
2090 | QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc); |
2091 | QualType BuildExtVectorType(QualType T, Expr *ArraySize, |
2092 | SourceLocation AttrLoc); |
2093 | QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, |
2094 | SourceLocation AttrLoc); |
2095 | |
2096 | QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace, |
2097 | SourceLocation AttrLoc); |
2098 | |
2099 | /// Same as above, but constructs the AddressSpace index if not provided. |
2100 | QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace, |
2101 | SourceLocation AttrLoc); |
2102 | |
2103 | bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc); |
2104 | |
2105 | bool CheckFunctionReturnType(QualType T, SourceLocation Loc); |
2106 | |
2107 | /// Build a function type. |
2108 | /// |
2109 | /// This routine checks the function type according to C++ rules and |
2110 | /// under the assumption that the result type and parameter types have |
2111 | /// just been instantiated from a template. It therefore duplicates |
2112 | /// some of the behavior of GetTypeForDeclarator, but in a much |
2113 | /// simpler form that is only suitable for this narrow use case. |
2114 | /// |
2115 | /// \param T The return type of the function. |
2116 | /// |
2117 | /// \param ParamTypes The parameter types of the function. This array |
2118 | /// will be modified to account for adjustments to the types of the |
2119 | /// function parameters. |
2120 | /// |
2121 | /// \param Loc The location of the entity whose type involves this |
2122 | /// function type or, if there is no such entity, the location of the |
2123 | /// type that will have function type. |
2124 | /// |
2125 | /// \param Entity The name of the entity that involves the function |
2126 | /// type, if known. |
2127 | /// |
2128 | /// \param EPI Extra information about the function type. Usually this will |
2129 | /// be taken from an existing function with the same prototype. |
2130 | /// |
2131 | /// \returns A suitable function type, if there are no errors. The |
2132 | /// unqualified type will always be a FunctionProtoType. |
2133 | /// Otherwise, returns a NULL type. |
2134 | QualType BuildFunctionType(QualType T, |
2135 | MutableArrayRef<QualType> ParamTypes, |
2136 | SourceLocation Loc, DeclarationName Entity, |
2137 | const FunctionProtoType::ExtProtoInfo &EPI); |
2138 | |
2139 | QualType BuildMemberPointerType(QualType T, QualType Class, |
2140 | SourceLocation Loc, |
2141 | DeclarationName Entity); |
2142 | QualType BuildBlockPointerType(QualType T, |
2143 | SourceLocation Loc, DeclarationName Entity); |
2144 | QualType BuildParenType(QualType T); |
2145 | QualType BuildAtomicType(QualType T, SourceLocation Loc); |
2146 | QualType BuildReadPipeType(QualType T, |
2147 | SourceLocation Loc); |
2148 | QualType BuildWritePipeType(QualType T, |
2149 | SourceLocation Loc); |
2150 | QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc); |
2151 | |
2152 | TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S); |
2153 | TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy); |
2154 | |
2155 | /// Package the given type and TSI into a ParsedType. |
2156 | ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo); |
2157 | DeclarationNameInfo GetNameForDeclarator(Declarator &D); |
2158 | DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name); |
2159 | static QualType GetTypeFromParser(ParsedType Ty, |
2160 | TypeSourceInfo **TInfo = nullptr); |
2161 | CanThrowResult canThrow(const Stmt *E); |
2162 | /// Determine whether the callee of a particular function call can throw. |
2163 | /// E, D and Loc are all optional. |
2164 | static CanThrowResult canCalleeThrow(Sema &S, const Expr *E, const Decl *D, |
2165 | SourceLocation Loc = SourceLocation()); |
2166 | const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc, |
2167 | const FunctionProtoType *FPT); |
2168 | void UpdateExceptionSpec(FunctionDecl *FD, |
2169 | const FunctionProtoType::ExceptionSpecInfo &ESI); |
2170 | bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range); |
2171 | bool CheckDistantExceptionSpec(QualType T); |
2172 | bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New); |
2173 | bool CheckEquivalentExceptionSpec( |
2174 | const FunctionProtoType *Old, SourceLocation OldLoc, |
2175 | const FunctionProtoType *New, SourceLocation NewLoc); |
2176 | bool CheckEquivalentExceptionSpec( |
2177 | const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, |
2178 | const FunctionProtoType *Old, SourceLocation OldLoc, |
2179 | const FunctionProtoType *New, SourceLocation NewLoc); |
2180 | bool handlerCanCatch(QualType HandlerType, QualType ExceptionType); |
2181 | bool CheckExceptionSpecSubset(const PartialDiagnostic &DiagID, |
2182 | const PartialDiagnostic &NestedDiagID, |
2183 | const PartialDiagnostic &NoteID, |
2184 | const PartialDiagnostic &NoThrowDiagID, |
2185 | const FunctionProtoType *Superset, |
2186 | SourceLocation SuperLoc, |
2187 | const FunctionProtoType *Subset, |
2188 | SourceLocation SubLoc); |
2189 | bool CheckParamExceptionSpec(const PartialDiagnostic &NestedDiagID, |
2190 | const PartialDiagnostic &NoteID, |
2191 | const FunctionProtoType *Target, |
2192 | SourceLocation TargetLoc, |
2193 | const FunctionProtoType *Source, |
2194 | SourceLocation SourceLoc); |
2195 | |
2196 | TypeResult ActOnTypeName(Scope *S, Declarator &D); |
2197 | |
2198 | /// The parser has parsed the context-sensitive type 'instancetype' |
2199 | /// in an Objective-C message declaration. Return the appropriate type. |
2200 | ParsedType ActOnObjCInstanceType(SourceLocation Loc); |
2201 | |
2202 | /// Abstract class used to diagnose incomplete types. |
2203 | struct TypeDiagnoser { |
2204 | TypeDiagnoser() {} |
2205 | |
2206 | virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0; |
2207 | virtual ~TypeDiagnoser() {} |
2208 | }; |
2209 | |
2210 | static int getPrintable(int I) { return I; } |
2211 | static unsigned getPrintable(unsigned I) { return I; } |
2212 | static bool getPrintable(bool B) { return B; } |
2213 | static const char * getPrintable(const char *S) { return S; } |
2214 | static StringRef getPrintable(StringRef S) { return S; } |
2215 | static const std::string &getPrintable(const std::string &S) { return S; } |
2216 | static const IdentifierInfo *getPrintable(const IdentifierInfo *II) { |
2217 | return II; |
2218 | } |
2219 | static DeclarationName getPrintable(DeclarationName N) { return N; } |
2220 | static QualType getPrintable(QualType T) { return T; } |
2221 | static SourceRange getPrintable(SourceRange R) { return R; } |
2222 | static SourceRange getPrintable(SourceLocation L) { return L; } |
2223 | static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); } |
2224 | static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();} |
2225 | |
2226 | template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser { |
2227 | protected: |
2228 | unsigned DiagID; |
2229 | std::tuple<const Ts &...> Args; |
2230 | |
2231 | template <std::size_t... Is> |
2232 | void emit(const SemaDiagnosticBuilder &DB, |
2233 | std::index_sequence<Is...>) const { |
2234 | // Apply all tuple elements to the builder in order. |
2235 | bool Dummy[] = {false, (DB << getPrintable(std::get<Is>(Args)))...}; |
2236 | (void)Dummy; |
2237 | } |
2238 | |
2239 | public: |
2240 | BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args) |
2241 | : TypeDiagnoser(), DiagID(DiagID), Args(Args...) { |
2242 | assert(DiagID != 0 && "no diagnostic for type diagnoser" ); |
2243 | } |
2244 | |
2245 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
2246 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID); |
2247 | emit(DB, std::index_sequence_for<Ts...>()); |
2248 | DB << T; |
2249 | } |
2250 | }; |
2251 | |
2252 | /// Do a check to make sure \p Name looks like a legal argument for the |
2253 | /// swift_name attribute applied to decl \p D. Raise a diagnostic if the name |
2254 | /// is invalid for the given declaration. |
2255 | /// |
2256 | /// \p AL is used to provide caret diagnostics in case of a malformed name. |
2257 | /// |
2258 | /// \returns true if the name is a valid swift name for \p D, false otherwise. |
2259 | bool DiagnoseSwiftName(Decl *D, StringRef Name, SourceLocation Loc, |
2260 | const ParsedAttr &AL, bool IsAsync); |
2261 | |
2262 | /// A derivative of BoundTypeDiagnoser for which the diagnostic's type |
2263 | /// parameter is preceded by a 0/1 enum that is 1 if the type is sizeless. |
2264 | /// For example, a diagnostic with no other parameters would generally have |
2265 | /// the form "...%select{incomplete|sizeless}0 type %1...". |
2266 | template <typename... Ts> |
2267 | class SizelessTypeDiagnoser : public BoundTypeDiagnoser<Ts...> { |
2268 | public: |
2269 | SizelessTypeDiagnoser(unsigned DiagID, const Ts &... Args) |
2270 | : BoundTypeDiagnoser<Ts...>(DiagID, Args...) {} |
2271 | |
2272 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
2273 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, this->DiagID); |
2274 | this->emit(DB, std::index_sequence_for<Ts...>()); |
2275 | DB << T->isSizelessType() << T; |
2276 | } |
2277 | }; |
2278 | |
2279 | enum class CompleteTypeKind { |
2280 | /// Apply the normal rules for complete types. In particular, |
2281 | /// treat all sizeless types as incomplete. |
2282 | Normal, |
2283 | |
2284 | /// Relax the normal rules for complete types so that they include |
2285 | /// sizeless built-in types. |
2286 | AcceptSizeless, |
2287 | |
2288 | // FIXME: Eventually we should flip the default to Normal and opt in |
2289 | // to AcceptSizeless rather than opt out of it. |
2290 | Default = AcceptSizeless |
2291 | }; |
2292 | |
2293 | enum class AcceptableKind { Visible, Reachable }; |
2294 | |
2295 | private: |
2296 | /// Methods for marking which expressions involve dereferencing a pointer |
2297 | /// marked with the 'noderef' attribute. Expressions are checked bottom up as |
2298 | /// they are parsed, meaning that a noderef pointer may not be accessed. For |
2299 | /// example, in `&*p` where `p` is a noderef pointer, we will first parse the |
2300 | /// `*p`, but need to check that `address of` is called on it. This requires |
2301 | /// keeping a container of all pending expressions and checking if the address |
2302 | /// of them are eventually taken. |
2303 | void CheckSubscriptAccessOfNoDeref(const ArraySubscriptExpr *E); |
2304 | void CheckAddressOfNoDeref(const Expr *E); |
2305 | void CheckMemberAccessOfNoDeref(const MemberExpr *E); |
2306 | |
2307 | bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T, |
2308 | CompleteTypeKind Kind, TypeDiagnoser *Diagnoser); |
2309 | |
2310 | struct ModuleScope { |
2311 | SourceLocation BeginLoc; |
2312 | clang::Module *Module = nullptr; |
2313 | bool ModuleInterface = false; |
2314 | VisibleModuleSet OuterVisibleModules; |
2315 | }; |
2316 | /// The modules we're currently parsing. |
2317 | llvm::SmallVector<ModuleScope, 16> ModuleScopes; |
2318 | |
2319 | /// For an interface unit, this is the implicitly imported interface unit. |
2320 | clang::Module *ThePrimaryInterface = nullptr; |
2321 | |
2322 | /// The explicit global module fragment of the current translation unit. |
2323 | /// The explicit Global Module Fragment, as specified in C++ |
2324 | /// [module.global.frag]. |
2325 | clang::Module *TheGlobalModuleFragment = nullptr; |
2326 | |
2327 | /// The implicit global module fragments of the current translation unit. |
2328 | /// We would only create at most two implicit global module fragments to |
2329 | /// avoid performance penalties when there are many language linkage |
2330 | /// exports. |
2331 | /// |
2332 | /// The contents in the implicit global module fragment can't be discarded |
2333 | /// no matter if it is exported or not. |
2334 | clang::Module *TheImplicitGlobalModuleFragment = nullptr; |
2335 | clang::Module *TheExportedImplicitGlobalModuleFragment = nullptr; |
2336 | |
2337 | /// Namespace definitions that we will export when they finish. |
2338 | llvm::SmallPtrSet<const NamespaceDecl*, 8> DeferredExportedNamespaces; |
2339 | |
2340 | /// In a C++ standard module, inline declarations require a definition to be |
2341 | /// present at the end of a definition domain. This set holds the decls to |
2342 | /// be checked at the end of the TU. |
2343 | llvm::SmallPtrSet<const FunctionDecl *, 8> PendingInlineFuncDecls; |
2344 | |
2345 | /// Helper function to judge if we are in module purview. |
2346 | /// Return false if we are not in a module. |
2347 | bool isCurrentModulePurview() const { |
2348 | return getCurrentModule() ? getCurrentModule()->isModulePurview() : false; |
2349 | } |
2350 | |
2351 | /// Enter the scope of the explicit global module fragment. |
2352 | Module *PushGlobalModuleFragment(SourceLocation BeginLoc); |
2353 | /// Leave the scope of the explicit global module fragment. |
2354 | void PopGlobalModuleFragment(); |
2355 | |
2356 | /// Enter the scope of an implicit global module fragment. |
2357 | Module *PushImplicitGlobalModuleFragment(SourceLocation BeginLoc, |
2358 | bool IsExported); |
2359 | /// Leave the scope of an implicit global module fragment. |
2360 | void PopImplicitGlobalModuleFragment(); |
2361 | |
2362 | VisibleModuleSet VisibleModules; |
2363 | |
2364 | /// Cache for module units which is usable for current module. |
2365 | llvm::DenseSet<const Module *> UsableModuleUnitsCache; |
2366 | |
2367 | bool isUsableModule(const Module *M); |
2368 | |
2369 | bool isAcceptableSlow(const NamedDecl *D, AcceptableKind Kind); |
2370 | |
2371 | public: |
2372 | /// Get the module unit whose scope we are currently within. |
2373 | Module *getCurrentModule() const { |
2374 | return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module; |
2375 | } |
2376 | |
2377 | /// Is the module scope we are an interface? |
2378 | bool currentModuleIsInterface() const { |
2379 | return ModuleScopes.empty() ? false : ModuleScopes.back().ModuleInterface; |
2380 | } |
2381 | |
2382 | /// Is the module scope we are in a C++ Header Unit? |
2383 | bool () const { |
2384 | return ModuleScopes.empty() ? false |
2385 | : ModuleScopes.back().Module->isHeaderUnit(); |
2386 | } |
2387 | |
2388 | /// Get the module owning an entity. |
2389 | Module *getOwningModule(const Decl *Entity) { |
2390 | return Entity->getOwningModule(); |
2391 | } |
2392 | |
2393 | /// Make a merged definition of an existing hidden definition \p ND |
2394 | /// visible at the specified location. |
2395 | void makeMergedDefinitionVisible(NamedDecl *ND); |
2396 | |
2397 | bool isModuleVisible(const Module *M, bool ModulePrivate = false); |
2398 | |
2399 | // When loading a non-modular PCH files, this is used to restore module |
2400 | // visibility. |
2401 | void makeModuleVisible(Module *Mod, SourceLocation ImportLoc) { |
2402 | VisibleModules.setVisible(Mod, ImportLoc); |
2403 | } |
2404 | |
2405 | /// Determine whether a declaration is visible to name lookup. |
2406 | bool isVisible(const NamedDecl *D) { |
2407 | return D->isUnconditionallyVisible() || |
2408 | isAcceptableSlow(D, AcceptableKind::Visible); |
2409 | } |
2410 | |
2411 | /// Determine whether a declaration is reachable. |
2412 | bool isReachable(const NamedDecl *D) { |
2413 | // All visible declarations are reachable. |
2414 | return D->isUnconditionallyVisible() || |
2415 | isAcceptableSlow(D, AcceptableKind::Reachable); |
2416 | } |
2417 | |
2418 | /// Determine whether a declaration is acceptable (visible/reachable). |
2419 | bool isAcceptable(const NamedDecl *D, AcceptableKind Kind) { |
2420 | return Kind == AcceptableKind::Visible ? isVisible(D) : isReachable(D); |
2421 | } |
2422 | |
2423 | /// Determine whether any declaration of an entity is visible. |
2424 | bool |
2425 | hasVisibleDeclaration(const NamedDecl *D, |
2426 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
2427 | return isVisible(D) || hasVisibleDeclarationSlow(D, Modules); |
2428 | } |
2429 | |
2430 | bool hasVisibleDeclarationSlow(const NamedDecl *D, |
2431 | llvm::SmallVectorImpl<Module *> *Modules); |
2432 | /// Determine whether any declaration of an entity is reachable. |
2433 | bool |
2434 | hasReachableDeclaration(const NamedDecl *D, |
2435 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
2436 | return isReachable(D) || hasReachableDeclarationSlow(D, Modules); |
2437 | } |
2438 | bool hasReachableDeclarationSlow( |
2439 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2440 | |
2441 | bool hasVisibleMergedDefinition(const NamedDecl *Def); |
2442 | bool hasMergedDefinitionInCurrentModule(const NamedDecl *Def); |
2443 | |
2444 | /// Determine if \p D and \p Suggested have a structurally compatible |
2445 | /// layout as described in C11 6.2.7/1. |
2446 | bool hasStructuralCompatLayout(Decl *D, Decl *Suggested); |
2447 | |
2448 | /// Determine if \p D has a visible definition. If not, suggest a declaration |
2449 | /// that should be made visible to expose the definition. |
2450 | bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, |
2451 | bool OnlyNeedComplete = false); |
2452 | bool hasVisibleDefinition(const NamedDecl *D) { |
2453 | NamedDecl *Hidden; |
2454 | return hasVisibleDefinition(const_cast<NamedDecl*>(D), &Hidden); |
2455 | } |
2456 | |
2457 | /// Determine if \p D has a reachable definition. If not, suggest a |
2458 | /// declaration that should be made reachable to expose the definition. |
2459 | bool hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested, |
2460 | bool OnlyNeedComplete = false); |
2461 | bool hasReachableDefinition(NamedDecl *D) { |
2462 | NamedDecl *Hidden; |
2463 | return hasReachableDefinition(D, &Hidden); |
2464 | } |
2465 | |
2466 | bool hasAcceptableDefinition(NamedDecl *D, NamedDecl **Suggested, |
2467 | AcceptableKind Kind, |
2468 | bool OnlyNeedComplete = false); |
2469 | bool hasAcceptableDefinition(NamedDecl *D, AcceptableKind Kind) { |
2470 | NamedDecl *Hidden; |
2471 | return hasAcceptableDefinition(D, &Hidden, Kind); |
2472 | } |
2473 | |
2474 | /// Determine if the template parameter \p D has a visible default argument. |
2475 | bool |
2476 | hasVisibleDefaultArgument(const NamedDecl *D, |
2477 | llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2478 | /// Determine if the template parameter \p D has a reachable default argument. |
2479 | bool hasReachableDefaultArgument( |
2480 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2481 | /// Determine if the template parameter \p D has a reachable default argument. |
2482 | bool hasAcceptableDefaultArgument(const NamedDecl *D, |
2483 | llvm::SmallVectorImpl<Module *> *Modules, |
2484 | Sema::AcceptableKind Kind); |
2485 | |
2486 | /// Determine if there is a visible declaration of \p D that is an explicit |
2487 | /// specialization declaration for a specialization of a template. (For a |
2488 | /// member specialization, use hasVisibleMemberSpecialization.) |
2489 | bool hasVisibleExplicitSpecialization( |
2490 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2491 | /// Determine if there is a reachable declaration of \p D that is an explicit |
2492 | /// specialization declaration for a specialization of a template. (For a |
2493 | /// member specialization, use hasReachableMemberSpecialization.) |
2494 | bool hasReachableExplicitSpecialization( |
2495 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2496 | |
2497 | /// Determine if there is a visible declaration of \p D that is a member |
2498 | /// specialization declaration (as opposed to an instantiated declaration). |
2499 | bool hasVisibleMemberSpecialization( |
2500 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2501 | /// Determine if there is a reachable declaration of \p D that is a member |
2502 | /// specialization declaration (as opposed to an instantiated declaration). |
2503 | bool hasReachableMemberSpecialization( |
2504 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
2505 | |
2506 | /// Determine if \p A and \p B are equivalent internal linkage declarations |
2507 | /// from different modules, and thus an ambiguity error can be downgraded to |
2508 | /// an extension warning. |
2509 | bool isEquivalentInternalLinkageDeclaration(const NamedDecl *A, |
2510 | const NamedDecl *B); |
2511 | void diagnoseEquivalentInternalLinkageDeclarations( |
2512 | SourceLocation Loc, const NamedDecl *D, |
2513 | ArrayRef<const NamedDecl *> Equiv); |
2514 | |
2515 | bool isUsualDeallocationFunction(const CXXMethodDecl *FD); |
2516 | |
2517 | // Check whether the size of array element of type \p EltTy is a multiple of |
2518 | // its alignment and return false if it isn't. |
2519 | bool checkArrayElementAlignment(QualType EltTy, SourceLocation Loc); |
2520 | |
2521 | bool isCompleteType(SourceLocation Loc, QualType T, |
2522 | CompleteTypeKind Kind = CompleteTypeKind::Default) { |
2523 | return !RequireCompleteTypeImpl(Loc, T, Kind, nullptr); |
2524 | } |
2525 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
2526 | CompleteTypeKind Kind, TypeDiagnoser &Diagnoser); |
2527 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
2528 | CompleteTypeKind Kind, unsigned DiagID); |
2529 | |
2530 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
2531 | TypeDiagnoser &Diagnoser) { |
2532 | return RequireCompleteType(Loc, T, CompleteTypeKind::Default, Diagnoser); |
2533 | } |
2534 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID) { |
2535 | return RequireCompleteType(Loc, T, CompleteTypeKind::Default, DiagID); |
2536 | } |
2537 | |
2538 | template <typename... Ts> |
2539 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID, |
2540 | const Ts &...Args) { |
2541 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2542 | return RequireCompleteType(Loc, T, Diagnoser); |
2543 | } |
2544 | |
2545 | template <typename... Ts> |
2546 | bool RequireCompleteSizedType(SourceLocation Loc, QualType T, unsigned DiagID, |
2547 | const Ts &... Args) { |
2548 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2549 | return RequireCompleteType(Loc, T, CompleteTypeKind::Normal, Diagnoser); |
2550 | } |
2551 | |
2552 | /// Get the type of expression E, triggering instantiation to complete the |
2553 | /// type if necessary -- that is, if the expression refers to a templated |
2554 | /// static data member of incomplete array type. |
2555 | /// |
2556 | /// May still return an incomplete type if instantiation was not possible or |
2557 | /// if the type is incomplete for a different reason. Use |
2558 | /// RequireCompleteExprType instead if a diagnostic is expected for an |
2559 | /// incomplete expression type. |
2560 | QualType getCompletedType(Expr *E); |
2561 | |
2562 | void completeExprArrayBound(Expr *E); |
2563 | bool RequireCompleteExprType(Expr *E, CompleteTypeKind Kind, |
2564 | TypeDiagnoser &Diagnoser); |
2565 | bool RequireCompleteExprType(Expr *E, unsigned DiagID); |
2566 | |
2567 | template <typename... Ts> |
2568 | bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) { |
2569 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2570 | return RequireCompleteExprType(E, CompleteTypeKind::Default, Diagnoser); |
2571 | } |
2572 | |
2573 | template <typename... Ts> |
2574 | bool RequireCompleteSizedExprType(Expr *E, unsigned DiagID, |
2575 | const Ts &... Args) { |
2576 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2577 | return RequireCompleteExprType(E, CompleteTypeKind::Normal, Diagnoser); |
2578 | } |
2579 | |
2580 | bool RequireLiteralType(SourceLocation Loc, QualType T, |
2581 | TypeDiagnoser &Diagnoser); |
2582 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID); |
2583 | |
2584 | template <typename... Ts> |
2585 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID, |
2586 | const Ts &...Args) { |
2587 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
2588 | return RequireLiteralType(Loc, T, Diagnoser); |
2589 | } |
2590 | |
2591 | QualType getElaboratedType(ElaboratedTypeKeyword Keyword, |
2592 | const CXXScopeSpec &SS, QualType T, |
2593 | TagDecl *OwnedTagDecl = nullptr); |
2594 | |
2595 | // Returns the underlying type of a decltype with the given expression. |
2596 | QualType getDecltypeForExpr(Expr *E); |
2597 | |
2598 | QualType BuildTypeofExprType(Expr *E, TypeOfKind Kind); |
2599 | /// If AsUnevaluated is false, E is treated as though it were an evaluated |
2600 | /// context, such as when building a type for decltype(auto). |
2601 | QualType BuildDecltypeType(Expr *E, bool AsUnevaluated = true); |
2602 | |
2603 | using UTTKind = UnaryTransformType::UTTKind; |
2604 | QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind, |
2605 | SourceLocation Loc); |
2606 | QualType BuiltinEnumUnderlyingType(QualType BaseType, SourceLocation Loc); |
2607 | QualType BuiltinAddPointer(QualType BaseType, SourceLocation Loc); |
2608 | QualType BuiltinRemovePointer(QualType BaseType, SourceLocation Loc); |
2609 | QualType BuiltinDecay(QualType BaseType, SourceLocation Loc); |
2610 | QualType BuiltinAddReference(QualType BaseType, UTTKind UKind, |
2611 | SourceLocation Loc); |
2612 | QualType BuiltinRemoveExtent(QualType BaseType, UTTKind UKind, |
2613 | SourceLocation Loc); |
2614 | QualType BuiltinRemoveReference(QualType BaseType, UTTKind UKind, |
2615 | SourceLocation Loc); |
2616 | QualType BuiltinChangeCVRQualifiers(QualType BaseType, UTTKind UKind, |
2617 | SourceLocation Loc); |
2618 | QualType BuiltinChangeSignedness(QualType BaseType, UTTKind UKind, |
2619 | SourceLocation Loc); |
2620 | |
2621 | //===--------------------------------------------------------------------===// |
2622 | // Symbol table / Decl tracking callbacks: SemaDecl.cpp. |
2623 | // |
2624 | |
2625 | struct SkipBodyInfo { |
2626 | SkipBodyInfo() = default; |
2627 | bool ShouldSkip = false; |
2628 | bool CheckSameAsPrevious = false; |
2629 | NamedDecl *Previous = nullptr; |
2630 | NamedDecl *New = nullptr; |
2631 | }; |
2632 | |
2633 | DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr); |
2634 | |
2635 | void DiagnoseUseOfUnimplementedSelectors(); |
2636 | |
2637 | bool isSimpleTypeSpecifier(tok::TokenKind Kind) const; |
2638 | |
2639 | ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, |
2640 | Scope *S, CXXScopeSpec *SS = nullptr, |
2641 | bool isClassName = false, bool HasTrailingDot = false, |
2642 | ParsedType ObjectType = nullptr, |
2643 | bool IsCtorOrDtorName = false, |
2644 | bool WantNontrivialTypeSourceInfo = false, |
2645 | bool IsClassTemplateDeductionContext = true, |
2646 | ImplicitTypenameContext AllowImplicitTypename = |
2647 | ImplicitTypenameContext::No, |
2648 | IdentifierInfo **CorrectedII = nullptr); |
2649 | TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S); |
2650 | bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S); |
2651 | void DiagnoseUnknownTypeName(IdentifierInfo *&II, |
2652 | SourceLocation IILoc, |
2653 | Scope *S, |
2654 | CXXScopeSpec *SS, |
2655 | ParsedType &SuggestedType, |
2656 | bool IsTemplateName = false); |
2657 | |
2658 | /// Attempt to behave like MSVC in situations where lookup of an unqualified |
2659 | /// type name has failed in a dependent context. In these situations, we |
2660 | /// automatically form a DependentTypeName that will retry lookup in a related |
2661 | /// scope during instantiation. |
2662 | ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II, |
2663 | SourceLocation NameLoc, |
2664 | bool IsTemplateTypeArg); |
2665 | |
2666 | /// Describes the result of the name lookup and resolution performed |
2667 | /// by \c ClassifyName(). |
2668 | enum NameClassificationKind { |
2669 | /// This name is not a type or template in this context, but might be |
2670 | /// something else. |
2671 | NC_Unknown, |
2672 | /// Classification failed; an error has been produced. |
2673 | NC_Error, |
2674 | /// The name has been typo-corrected to a keyword. |
2675 | NC_Keyword, |
2676 | /// The name was classified as a type. |
2677 | NC_Type, |
2678 | /// The name was classified as a specific non-type, non-template |
2679 | /// declaration. ActOnNameClassifiedAsNonType should be called to |
2680 | /// convert the declaration to an expression. |
2681 | NC_NonType, |
2682 | /// The name was classified as an ADL-only function name. |
2683 | /// ActOnNameClassifiedAsUndeclaredNonType should be called to convert the |
2684 | /// result to an expression. |
2685 | NC_UndeclaredNonType, |
2686 | /// The name denotes a member of a dependent type that could not be |
2687 | /// resolved. ActOnNameClassifiedAsDependentNonType should be called to |
2688 | /// convert the result to an expression. |
2689 | NC_DependentNonType, |
2690 | /// The name was classified as an overload set, and an expression |
2691 | /// representing that overload set has been formed. |
2692 | /// ActOnNameClassifiedAsOverloadSet should be called to form a suitable |
2693 | /// expression referencing the overload set. |
2694 | NC_OverloadSet, |
2695 | /// The name was classified as a template whose specializations are types. |
2696 | NC_TypeTemplate, |
2697 | /// The name was classified as a variable template name. |
2698 | NC_VarTemplate, |
2699 | /// The name was classified as a function template name. |
2700 | NC_FunctionTemplate, |
2701 | /// The name was classified as an ADL-only function template name. |
2702 | NC_UndeclaredTemplate, |
2703 | /// The name was classified as a concept name. |
2704 | NC_Concept, |
2705 | }; |
2706 | |
2707 | class NameClassification { |
2708 | NameClassificationKind Kind; |
2709 | union { |
2710 | ExprResult Expr; |
2711 | NamedDecl *NonTypeDecl; |
2712 | TemplateName Template; |
2713 | ParsedType Type; |
2714 | }; |
2715 | |
2716 | explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {} |
2717 | |
2718 | public: |
2719 | NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {} |
2720 | |
2721 | NameClassification(const IdentifierInfo *Keyword) : Kind(NC_Keyword) {} |
2722 | |
2723 | static NameClassification Error() { |
2724 | return NameClassification(NC_Error); |
2725 | } |
2726 | |
2727 | static NameClassification Unknown() { |
2728 | return NameClassification(NC_Unknown); |
2729 | } |
2730 | |
2731 | static NameClassification OverloadSet(ExprResult E) { |
2732 | NameClassification Result(NC_OverloadSet); |
2733 | Result.Expr = E; |
2734 | return Result; |
2735 | } |
2736 | |
2737 | static NameClassification NonType(NamedDecl *D) { |
2738 | NameClassification Result(NC_NonType); |
2739 | Result.NonTypeDecl = D; |
2740 | return Result; |
2741 | } |
2742 | |
2743 | static NameClassification UndeclaredNonType() { |
2744 | return NameClassification(NC_UndeclaredNonType); |
2745 | } |
2746 | |
2747 | static NameClassification DependentNonType() { |
2748 | return NameClassification(NC_DependentNonType); |
2749 | } |
2750 | |
2751 | static NameClassification TypeTemplate(TemplateName Name) { |
2752 | NameClassification Result(NC_TypeTemplate); |
2753 | Result.Template = Name; |
2754 | return Result; |
2755 | } |
2756 | |
2757 | static NameClassification VarTemplate(TemplateName Name) { |
2758 | NameClassification Result(NC_VarTemplate); |
2759 | Result.Template = Name; |
2760 | return Result; |
2761 | } |
2762 | |
2763 | static NameClassification FunctionTemplate(TemplateName Name) { |
2764 | NameClassification Result(NC_FunctionTemplate); |
2765 | Result.Template = Name; |
2766 | return Result; |
2767 | } |
2768 | |
2769 | static NameClassification Concept(TemplateName Name) { |
2770 | NameClassification Result(NC_Concept); |
2771 | Result.Template = Name; |
2772 | return Result; |
2773 | } |
2774 | |
2775 | static NameClassification UndeclaredTemplate(TemplateName Name) { |
2776 | NameClassification Result(NC_UndeclaredTemplate); |
2777 | Result.Template = Name; |
2778 | return Result; |
2779 | } |
2780 | |
2781 | NameClassificationKind getKind() const { return Kind; } |
2782 | |
2783 | ExprResult getExpression() const { |
2784 | assert(Kind == NC_OverloadSet); |
2785 | return Expr; |
2786 | } |
2787 | |
2788 | ParsedType getType() const { |
2789 | assert(Kind == NC_Type); |
2790 | return Type; |
2791 | } |
2792 | |
2793 | NamedDecl *getNonTypeDecl() const { |
2794 | assert(Kind == NC_NonType); |
2795 | return NonTypeDecl; |
2796 | } |
2797 | |
2798 | TemplateName getTemplateName() const { |
2799 | assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || |
2800 | Kind == NC_VarTemplate || Kind == NC_Concept || |
2801 | Kind == NC_UndeclaredTemplate); |
2802 | return Template; |
2803 | } |
2804 | |
2805 | TemplateNameKind getTemplateNameKind() const { |
2806 | switch (Kind) { |
2807 | case NC_TypeTemplate: |
2808 | return TNK_Type_template; |
2809 | case NC_FunctionTemplate: |
2810 | return TNK_Function_template; |
2811 | case NC_VarTemplate: |
2812 | return TNK_Var_template; |
2813 | case NC_Concept: |
2814 | return TNK_Concept_template; |
2815 | case NC_UndeclaredTemplate: |
2816 | return TNK_Undeclared_template; |
2817 | default: |
2818 | llvm_unreachable("unsupported name classification." ); |
2819 | } |
2820 | } |
2821 | }; |
2822 | |
2823 | /// Perform name lookup on the given name, classifying it based on |
2824 | /// the results of name lookup and the following token. |
2825 | /// |
2826 | /// This routine is used by the parser to resolve identifiers and help direct |
2827 | /// parsing. When the identifier cannot be found, this routine will attempt |
2828 | /// to correct the typo and classify based on the resulting name. |
2829 | /// |
2830 | /// \param S The scope in which we're performing name lookup. |
2831 | /// |
2832 | /// \param SS The nested-name-specifier that precedes the name. |
2833 | /// |
2834 | /// \param Name The identifier. If typo correction finds an alternative name, |
2835 | /// this pointer parameter will be updated accordingly. |
2836 | /// |
2837 | /// \param NameLoc The location of the identifier. |
2838 | /// |
2839 | /// \param NextToken The token following the identifier. Used to help |
2840 | /// disambiguate the name. |
2841 | /// |
2842 | /// \param CCC The correction callback, if typo correction is desired. |
2843 | NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS, |
2844 | IdentifierInfo *&Name, SourceLocation NameLoc, |
2845 | const Token &NextToken, |
2846 | CorrectionCandidateCallback *CCC = nullptr); |
2847 | |
2848 | /// Act on the result of classifying a name as an undeclared (ADL-only) |
2849 | /// non-type declaration. |
2850 | ExprResult ActOnNameClassifiedAsUndeclaredNonType(IdentifierInfo *Name, |
2851 | SourceLocation NameLoc); |
2852 | /// Act on the result of classifying a name as an undeclared member of a |
2853 | /// dependent base class. |
2854 | ExprResult ActOnNameClassifiedAsDependentNonType(const CXXScopeSpec &SS, |
2855 | IdentifierInfo *Name, |
2856 | SourceLocation NameLoc, |
2857 | bool IsAddressOfOperand); |
2858 | /// Act on the result of classifying a name as a specific non-type |
2859 | /// declaration. |
2860 | ExprResult ActOnNameClassifiedAsNonType(Scope *S, const CXXScopeSpec &SS, |
2861 | NamedDecl *Found, |
2862 | SourceLocation NameLoc, |
2863 | const Token &NextToken); |
2864 | /// Act on the result of classifying a name as an overload set. |
2865 | ExprResult ActOnNameClassifiedAsOverloadSet(Scope *S, Expr *OverloadSet); |
2866 | |
2867 | /// Describes the detailed kind of a template name. Used in diagnostics. |
2868 | enum class TemplateNameKindForDiagnostics { |
2869 | ClassTemplate, |
2870 | FunctionTemplate, |
2871 | VarTemplate, |
2872 | AliasTemplate, |
2873 | TemplateTemplateParam, |
2874 | Concept, |
2875 | DependentTemplate |
2876 | }; |
2877 | TemplateNameKindForDiagnostics |
2878 | getTemplateNameKindForDiagnostics(TemplateName Name); |
2879 | |
2880 | /// Determine whether it's plausible that E was intended to be a |
2881 | /// template-name. |
2882 | bool mightBeIntendedToBeTemplateName(ExprResult E, bool &Dependent) { |
2883 | if (!getLangOpts().CPlusPlus || E.isInvalid()) |
2884 | return false; |
2885 | Dependent = false; |
2886 | if (auto *DRE = dyn_cast<DeclRefExpr>(E.get())) |
2887 | return !DRE->hasExplicitTemplateArgs(); |
2888 | if (auto *ME = dyn_cast<MemberExpr>(E.get())) |
2889 | return !ME->hasExplicitTemplateArgs(); |
2890 | Dependent = true; |
2891 | if (auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(E.get())) |
2892 | return !DSDRE->hasExplicitTemplateArgs(); |
2893 | if (auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(E.get())) |
2894 | return !DSME->hasExplicitTemplateArgs(); |
2895 | // Any additional cases recognized here should also be handled by |
2896 | // diagnoseExprIntendedAsTemplateName. |
2897 | return false; |
2898 | } |
2899 | void diagnoseExprIntendedAsTemplateName(Scope *S, ExprResult TemplateName, |
2900 | SourceLocation Less, |
2901 | SourceLocation Greater); |
2902 | |
2903 | void warnOnReservedIdentifier(const NamedDecl *D); |
2904 | |
2905 | Decl *ActOnDeclarator(Scope *S, Declarator &D); |
2906 | |
2907 | NamedDecl *HandleDeclarator(Scope *S, Declarator &D, |
2908 | MultiTemplateParamsArg TemplateParameterLists); |
2909 | bool tryToFixVariablyModifiedVarType(TypeSourceInfo *&TInfo, |
2910 | QualType &T, SourceLocation Loc, |
2911 | unsigned FailedFoldDiagID); |
2912 | void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S); |
2913 | bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info); |
2914 | bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, |
2915 | DeclarationName Name, SourceLocation Loc, |
2916 | bool IsTemplateId); |
2917 | void |
2918 | diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals, |
2919 | SourceLocation FallbackLoc, |
2920 | SourceLocation ConstQualLoc = SourceLocation(), |
2921 | SourceLocation VolatileQualLoc = SourceLocation(), |
2922 | SourceLocation RestrictQualLoc = SourceLocation(), |
2923 | SourceLocation AtomicQualLoc = SourceLocation(), |
2924 | SourceLocation UnalignedQualLoc = SourceLocation()); |
2925 | |
2926 | static bool adjustContextForLocalExternDecl(DeclContext *&DC); |
2927 | void DiagnoseFunctionSpecifiers(const DeclSpec &DS); |
2928 | NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D, |
2929 | const LookupResult &R); |
2930 | NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult &R); |
2931 | NamedDecl *getShadowedDeclaration(const BindingDecl *D, |
2932 | const LookupResult &R); |
2933 | void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl, |
2934 | const LookupResult &R); |
2935 | void CheckShadow(Scope *S, VarDecl *D); |
2936 | |
2937 | /// Warn if 'E', which is an expression that is about to be modified, refers |
2938 | /// to a shadowing declaration. |
2939 | void CheckShadowingDeclModification(Expr *E, SourceLocation Loc); |
2940 | |
2941 | void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI); |
2942 | |
2943 | private: |
2944 | /// Map of current shadowing declarations to shadowed declarations. Warn if |
2945 | /// it looks like the user is trying to modify the shadowing declaration. |
2946 | llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls; |
2947 | |
2948 | public: |
2949 | void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); |
2950 | void handleTagNumbering(const TagDecl *Tag, Scope *TagScope); |
2951 | void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec, |
2952 | TypedefNameDecl *NewTD); |
2953 | void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D); |
2954 | NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
2955 | TypeSourceInfo *TInfo, |
2956 | LookupResult &Previous); |
2957 | NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D, |
2958 | LookupResult &Previous, bool &Redeclaration); |
2959 | NamedDecl *ActOnVariableDeclarator( |
2960 | Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, |
2961 | LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists, |
2962 | bool &AddToScope, ArrayRef<BindingDecl *> Bindings = std::nullopt); |
2963 | NamedDecl * |
2964 | ActOnDecompositionDeclarator(Scope *S, Declarator &D, |
2965 | MultiTemplateParamsArg TemplateParamLists); |
2966 | // Returns true if the variable declaration is a redeclaration |
2967 | bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous); |
2968 | void CheckVariableDeclarationType(VarDecl *NewVD); |
2969 | bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit, |
2970 | Expr *Init); |
2971 | void CheckCompleteVariableDeclaration(VarDecl *VD); |
2972 | void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD); |
2973 | void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D); |
2974 | |
2975 | NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
2976 | TypeSourceInfo *TInfo, |
2977 | LookupResult &Previous, |
2978 | MultiTemplateParamsArg TemplateParamLists, |
2979 | bool &AddToScope); |
2980 | bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); |
2981 | |
2982 | enum class CheckConstexprKind { |
2983 | /// Diagnose issues that are non-constant or that are extensions. |
2984 | Diagnose, |
2985 | /// Identify whether this function satisfies the formal rules for constexpr |
2986 | /// functions in the current lanugage mode (with no extensions). |
2987 | CheckValid |
2988 | }; |
2989 | |
2990 | bool CheckConstexprFunctionDefinition(const FunctionDecl *FD, |
2991 | CheckConstexprKind Kind); |
2992 | |
2993 | void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD); |
2994 | void FindHiddenVirtualMethods(CXXMethodDecl *MD, |
2995 | SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods); |
2996 | void NoteHiddenVirtualMethods(CXXMethodDecl *MD, |
2997 | SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods); |
2998 | // Returns true if the function declaration is a redeclaration |
2999 | bool CheckFunctionDeclaration(Scope *S, |
3000 | FunctionDecl *NewFD, LookupResult &Previous, |
3001 | bool IsMemberSpecialization, bool DeclIsDefn); |
3002 | bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl); |
3003 | bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD, |
3004 | QualType NewT, QualType OldT); |
3005 | void CheckMain(FunctionDecl *FD, const DeclSpec &D); |
3006 | void CheckMSVCRTEntryPoint(FunctionDecl *FD); |
3007 | void CheckHLSLEntryPoint(FunctionDecl *FD); |
3008 | Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, |
3009 | bool IsDefinition); |
3010 | void CheckFunctionOrTemplateParamDeclarator(Scope *S, Declarator &D); |
3011 | Decl *ActOnParamDeclarator(Scope *S, Declarator &D); |
3012 | ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, |
3013 | SourceLocation Loc, |
3014 | QualType T); |
3015 | ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc, |
3016 | SourceLocation NameLoc, IdentifierInfo *Name, |
3017 | QualType T, TypeSourceInfo *TSInfo, |
3018 | StorageClass SC); |
3019 | void ActOnParamDefaultArgument(Decl *param, |
3020 | SourceLocation EqualLoc, |
3021 | Expr *defarg); |
3022 | void ActOnParamUnparsedDefaultArgument(Decl *param, SourceLocation EqualLoc, |
3023 | SourceLocation ArgLoc); |
3024 | void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc); |
3025 | ExprResult ConvertParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
3026 | SourceLocation EqualLoc); |
3027 | void SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
3028 | SourceLocation EqualLoc); |
3029 | |
3030 | // Contexts where using non-trivial C union types can be disallowed. This is |
3031 | // passed to err_non_trivial_c_union_in_invalid_context. |
3032 | enum NonTrivialCUnionContext { |
3033 | // Function parameter. |
3034 | NTCUC_FunctionParam, |
3035 | // Function return. |
3036 | NTCUC_FunctionReturn, |
3037 | // Default-initialized object. |
3038 | NTCUC_DefaultInitializedObject, |
3039 | // Variable with automatic storage duration. |
3040 | NTCUC_AutoVar, |
3041 | // Initializer expression that might copy from another object. |
3042 | NTCUC_CopyInit, |
3043 | // Assignment. |
3044 | NTCUC_Assignment, |
3045 | // Compound literal. |
3046 | NTCUC_CompoundLiteral, |
3047 | // Block capture. |
3048 | NTCUC_BlockCapture, |
3049 | // lvalue-to-rvalue conversion of volatile type. |
3050 | NTCUC_LValueToRValueVolatile, |
3051 | }; |
3052 | |
3053 | /// Emit diagnostics if the initializer or any of its explicit or |
3054 | /// implicitly-generated subexpressions require copying or |
3055 | /// default-initializing a type that is or contains a C union type that is |
3056 | /// non-trivial to copy or default-initialize. |
3057 | void checkNonTrivialCUnionInInitializer(const Expr *Init, SourceLocation Loc); |
3058 | |
3059 | // These flags are passed to checkNonTrivialCUnion. |
3060 | enum NonTrivialCUnionKind { |
3061 | NTCUK_Init = 0x1, |
3062 | NTCUK_Destruct = 0x2, |
3063 | NTCUK_Copy = 0x4, |
3064 | }; |
3065 | |
3066 | /// Emit diagnostics if a non-trivial C union type or a struct that contains |
3067 | /// a non-trivial C union is used in an invalid context. |
3068 | void checkNonTrivialCUnion(QualType QT, SourceLocation Loc, |
3069 | NonTrivialCUnionContext UseContext, |
3070 | unsigned NonTrivialKind); |
3071 | |
3072 | void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit); |
3073 | void ActOnUninitializedDecl(Decl *dcl); |
3074 | void ActOnInitializerError(Decl *Dcl); |
3075 | |
3076 | void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc); |
3077 | void ActOnCXXForRangeDecl(Decl *D); |
3078 | StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, |
3079 | IdentifierInfo *Ident, |
3080 | ParsedAttributes &Attrs); |
3081 | void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc); |
3082 | void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc); |
3083 | void CheckStaticLocalForDllExport(VarDecl *VD); |
3084 | void CheckThreadLocalForLargeAlignment(VarDecl *VD); |
3085 | void FinalizeDeclaration(Decl *D); |
3086 | DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, |
3087 | ArrayRef<Decl *> Group); |
3088 | DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group); |
3089 | |
3090 | /// Should be called on all declarations that might have attached |
3091 | /// documentation comments. |
3092 | void ActOnDocumentableDecl(Decl *D); |
3093 | void ActOnDocumentableDecls(ArrayRef<Decl *> Group); |
3094 | |
3095 | enum class FnBodyKind { |
3096 | /// C++ [dcl.fct.def.general]p1 |
3097 | /// function-body: |
3098 | /// ctor-initializer[opt] compound-statement |
3099 | /// function-try-block |
3100 | Other, |
3101 | /// = default ; |
3102 | Default, |
3103 | /// = delete ; |
3104 | Delete |
3105 | }; |
3106 | |
3107 | void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, |
3108 | SourceLocation LocAfterDecls); |
3109 | void CheckForFunctionRedefinition( |
3110 | FunctionDecl *FD, const FunctionDecl *EffectiveDefinition = nullptr, |
3111 | SkipBodyInfo *SkipBody = nullptr); |
3112 | Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D, |
3113 | MultiTemplateParamsArg TemplateParamLists, |
3114 | SkipBodyInfo *SkipBody = nullptr, |
3115 | FnBodyKind BodyKind = FnBodyKind::Other); |
3116 | Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D, |
3117 | SkipBodyInfo *SkipBody = nullptr, |
3118 | FnBodyKind BodyKind = FnBodyKind::Other); |
3119 | void SetFunctionBodyKind(Decl *D, SourceLocation Loc, FnBodyKind BodyKind); |
3120 | void ActOnStartTrailingRequiresClause(Scope *S, Declarator &D); |
3121 | ExprResult ActOnFinishTrailingRequiresClause(ExprResult ConstraintExpr); |
3122 | ExprResult ActOnRequiresClause(ExprResult ConstraintExpr); |
3123 | void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); |
3124 | bool isObjCMethodDecl(Decl *D) { |
3125 | return D && isa<ObjCMethodDecl>(D); |
3126 | } |
3127 | |
3128 | /// Determine whether we can delay parsing the body of a function or |
3129 | /// function template until it is used, assuming we don't care about emitting |
3130 | /// code for that function. |
3131 | /// |
3132 | /// This will be \c false if we may need the body of the function in the |
3133 | /// middle of parsing an expression (where it's impractical to switch to |
3134 | /// parsing a different function), for instance, if it's constexpr in C++11 |
3135 | /// or has an 'auto' return type in C++14. These cases are essentially bugs. |
3136 | bool canDelayFunctionBody(const Declarator &D); |
3137 | |
3138 | /// Determine whether we can skip parsing the body of a function |
3139 | /// definition, assuming we don't care about analyzing its body or emitting |
3140 | /// code for that function. |
3141 | /// |
3142 | /// This will be \c false only if we may need the body of the function in |
3143 | /// order to parse the rest of the program (for instance, if it is |
3144 | /// \c constexpr in C++11 or has an 'auto' return type in C++14). |
3145 | bool canSkipFunctionBody(Decl *D); |
3146 | |
3147 | /// Determine whether \param D is function like (function or function |
3148 | /// template) for parsing. |
3149 | bool isDeclaratorFunctionLike(Declarator &D); |
3150 | |
3151 | void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope); |
3152 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body); |
3153 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation); |
3154 | Decl *ActOnSkippedFunctionBody(Decl *Decl); |
3155 | void ActOnFinishInlineFunctionDef(FunctionDecl *D); |
3156 | |
3157 | /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an |
3158 | /// attribute for which parsing is delayed. |
3159 | void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs); |
3160 | |
3161 | /// Diagnose any unused parameters in the given sequence of |
3162 | /// ParmVarDecl pointers. |
3163 | void DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters); |
3164 | |
3165 | /// Diagnose whether the size of parameters or return value of a |
3166 | /// function or obj-c method definition is pass-by-value and larger than a |
3167 | /// specified threshold. |
3168 | void |
3169 | DiagnoseSizeOfParametersAndReturnValue(ArrayRef<ParmVarDecl *> Parameters, |
3170 | QualType ReturnTy, NamedDecl *D); |
3171 | |
3172 | void DiagnoseInvalidJumps(Stmt *Body); |
3173 | Decl *ActOnFileScopeAsmDecl(Expr *expr, |
3174 | SourceLocation AsmLoc, |
3175 | SourceLocation RParenLoc); |
3176 | |
3177 | Decl *ActOnTopLevelStmtDecl(Stmt *Statement); |
3178 | |
3179 | /// Handle a C++11 empty-declaration and attribute-declaration. |
3180 | Decl *ActOnEmptyDeclaration(Scope *S, const ParsedAttributesView &AttrList, |
3181 | SourceLocation SemiLoc); |
3182 | |
3183 | enum class ModuleDeclKind { |
3184 | Interface, ///< 'export module X;' |
3185 | Implementation, ///< 'module X;' |
3186 | PartitionInterface, ///< 'export module X:Y;' |
3187 | PartitionImplementation, ///< 'module X:Y;' |
3188 | }; |
3189 | |
3190 | /// An enumeration to represent the transition of states in parsing module |
3191 | /// fragments and imports. If we are not parsing a C++20 TU, or we find |
3192 | /// an error in state transition, the state is set to NotACXX20Module. |
3193 | enum class ModuleImportState { |
3194 | FirstDecl, ///< Parsing the first decl in a TU. |
3195 | GlobalFragment, ///< after 'module;' but before 'module X;' |
3196 | ImportAllowed, ///< after 'module X;' but before any non-import decl. |
3197 | ImportFinished, ///< after any non-import decl. |
3198 | PrivateFragmentImportAllowed, ///< after 'module :private;' but before any |
3199 | ///< non-import decl. |
3200 | PrivateFragmentImportFinished, ///< after 'module :private;' but a |
3201 | ///< non-import decl has already been seen. |
3202 | NotACXX20Module ///< Not a C++20 TU, or an invalid state was found. |
3203 | }; |
3204 | |
3205 | private: |
3206 | /// The parser has begun a translation unit to be compiled as a C++20 |
3207 | /// Header Unit, helper for ActOnStartOfTranslationUnit() only. |
3208 | void HandleStartOfHeaderUnit(); |
3209 | |
3210 | public: |
3211 | /// The parser has processed a module-declaration that begins the definition |
3212 | /// of a module interface or implementation. |
3213 | DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc, |
3214 | SourceLocation ModuleLoc, ModuleDeclKind MDK, |
3215 | ModuleIdPath Path, ModuleIdPath Partition, |
3216 | ModuleImportState &ImportState); |
3217 | |
3218 | /// The parser has processed a global-module-fragment declaration that begins |
3219 | /// the definition of the global module fragment of the current module unit. |
3220 | /// \param ModuleLoc The location of the 'module' keyword. |
3221 | DeclGroupPtrTy ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc); |
3222 | |
3223 | /// The parser has processed a private-module-fragment declaration that begins |
3224 | /// the definition of the private module fragment of the current module unit. |
3225 | /// \param ModuleLoc The location of the 'module' keyword. |
3226 | /// \param PrivateLoc The location of the 'private' keyword. |
3227 | DeclGroupPtrTy ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc, |
3228 | SourceLocation PrivateLoc); |
3229 | |
3230 | /// The parser has processed a module import declaration. |
3231 | /// |
3232 | /// \param StartLoc The location of the first token in the declaration. This |
3233 | /// could be the location of an '@', 'export', or 'import'. |
3234 | /// \param ExportLoc The location of the 'export' keyword, if any. |
3235 | /// \param ImportLoc The location of the 'import' keyword. |
3236 | /// \param Path The module toplevel name as an access path. |
3237 | /// \param IsPartition If the name is for a partition. |
3238 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
3239 | SourceLocation ExportLoc, |
3240 | SourceLocation ImportLoc, ModuleIdPath Path, |
3241 | bool IsPartition = false); |
3242 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
3243 | SourceLocation ExportLoc, |
3244 | SourceLocation ImportLoc, Module *M, |
3245 | ModuleIdPath Path = {}); |
3246 | |
3247 | /// The parser has processed a module import translated from a |
3248 | /// #include or similar preprocessing directive. |
3249 | void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
3250 | void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
3251 | |
3252 | /// The parsed has entered a submodule. |
3253 | void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod); |
3254 | /// The parser has left a submodule. |
3255 | void ActOnModuleEnd(SourceLocation DirectiveLoc, Module *Mod); |
3256 | |
3257 | /// Create an implicit import of the given module at the given |
3258 | /// source location, for error recovery, if possible. |
3259 | /// |
3260 | /// This routine is typically used when an entity found by name lookup |
3261 | /// is actually hidden within a module that we know about but the user |
3262 | /// has forgotten to import. |
3263 | void createImplicitModuleImportForErrorRecovery(SourceLocation Loc, |
3264 | Module *Mod); |
3265 | |
3266 | /// Kinds of missing import. Note, the values of these enumerators correspond |
3267 | /// to %select values in diagnostics. |
3268 | enum class MissingImportKind { |
3269 | Declaration, |
3270 | Definition, |
3271 | DefaultArgument, |
3272 | ExplicitSpecialization, |
3273 | PartialSpecialization |
3274 | }; |
3275 | |
3276 | /// Diagnose that the specified declaration needs to be visible but |
3277 | /// isn't, and suggest a module import that would resolve the problem. |
3278 | void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl, |
3279 | MissingImportKind MIK, bool Recover = true); |
3280 | void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl, |
3281 | SourceLocation DeclLoc, ArrayRef<Module *> Modules, |
3282 | MissingImportKind MIK, bool Recover); |
3283 | |
3284 | Decl *ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, |
3285 | SourceLocation LBraceLoc); |
3286 | Decl *ActOnFinishExportDecl(Scope *S, Decl *ExportDecl, |
3287 | SourceLocation RBraceLoc); |
3288 | |
3289 | /// We've found a use of a templated declaration that would trigger an |
3290 | /// implicit instantiation. Check that any relevant explicit specializations |
3291 | /// and partial specializations are visible/reachable, and diagnose if not. |
3292 | void checkSpecializationVisibility(SourceLocation Loc, NamedDecl *Spec); |
3293 | void checkSpecializationReachability(SourceLocation Loc, NamedDecl *Spec); |
3294 | |
3295 | /// Retrieve a suitable printing policy for diagnostics. |
3296 | PrintingPolicy getPrintingPolicy() const { |
3297 | return getPrintingPolicy(Context, PP); |
3298 | } |
3299 | |
3300 | /// Retrieve a suitable printing policy for diagnostics. |
3301 | static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx, |
3302 | const Preprocessor &PP); |
3303 | |
3304 | /// Scope actions. |
3305 | void ActOnPopScope(SourceLocation Loc, Scope *S); |
3306 | void ActOnTranslationUnitScope(Scope *S); |
3307 | |
3308 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
3309 | const ParsedAttributesView &DeclAttrs, |
3310 | RecordDecl *&AnonRecord); |
3311 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
3312 | const ParsedAttributesView &DeclAttrs, |
3313 | MultiTemplateParamsArg TemplateParams, |
3314 | bool IsExplicitInstantiation, |
3315 | RecordDecl *&AnonRecord); |
3316 | |
3317 | Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, |
3318 | AccessSpecifier AS, |
3319 | RecordDecl *Record, |
3320 | const PrintingPolicy &Policy); |
3321 | |
3322 | Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, |
3323 | RecordDecl *Record); |
3324 | |
3325 | /// Common ways to introduce type names without a tag for use in diagnostics. |
3326 | /// Keep in sync with err_tag_reference_non_tag. |
3327 | enum NonTagKind { |
3328 | NTK_NonStruct, |
3329 | NTK_NonClass, |
3330 | NTK_NonUnion, |
3331 | NTK_NonEnum, |
3332 | NTK_Typedef, |
3333 | NTK_TypeAlias, |
3334 | NTK_Template, |
3335 | NTK_TypeAliasTemplate, |
3336 | NTK_TemplateTemplateArgument, |
3337 | }; |
3338 | |
3339 | /// Given a non-tag type declaration, returns an enum useful for indicating |
3340 | /// what kind of non-tag type this is. |
3341 | NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK); |
3342 | |
3343 | bool isAcceptableTagRedeclaration(const TagDecl *Previous, |
3344 | TagTypeKind NewTag, bool isDefinition, |
3345 | SourceLocation NewTagLoc, |
3346 | const IdentifierInfo *Name); |
3347 | |
3348 | enum TagUseKind { |
3349 | TUK_Reference, // Reference to a tag: 'struct foo *X;' |
3350 | TUK_Declaration, // Fwd decl of a tag: 'struct foo;' |
3351 | TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;' |
3352 | TUK_Friend // Friend declaration: 'friend struct foo;' |
3353 | }; |
3354 | |
3355 | enum OffsetOfKind { |
3356 | // Not parsing a type within __builtin_offsetof. |
3357 | OOK_Outside, |
3358 | // Parsing a type within __builtin_offsetof. |
3359 | OOK_Builtin, |
3360 | // Parsing a type within macro "offsetof", defined in __buitin_offsetof |
3361 | // To improve our diagnostic message. |
3362 | OOK_Macro, |
3363 | }; |
3364 | |
3365 | DeclResult ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, |
3366 | SourceLocation KWLoc, CXXScopeSpec &SS, |
3367 | IdentifierInfo *Name, SourceLocation NameLoc, |
3368 | const ParsedAttributesView &Attr, AccessSpecifier AS, |
3369 | SourceLocation ModulePrivateLoc, |
3370 | MultiTemplateParamsArg TemplateParameterLists, |
3371 | bool &OwnedDecl, bool &IsDependent, |
3372 | SourceLocation ScopedEnumKWLoc, |
3373 | bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, |
3374 | bool IsTypeSpecifier, bool IsTemplateParamOrArg, |
3375 | OffsetOfKind OOK, SkipBodyInfo *SkipBody = nullptr); |
3376 | |
3377 | DeclResult ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, |
3378 | unsigned TagSpec, SourceLocation TagLoc, |
3379 | CXXScopeSpec &SS, IdentifierInfo *Name, |
3380 | SourceLocation NameLoc, |
3381 | const ParsedAttributesView &Attr, |
3382 | MultiTemplateParamsArg TempParamLists); |
3383 | |
3384 | TypeResult ActOnDependentTag(Scope *S, |
3385 | unsigned TagSpec, |
3386 | TagUseKind TUK, |
3387 | const CXXScopeSpec &SS, |
3388 | IdentifierInfo *Name, |
3389 | SourceLocation TagLoc, |
3390 | SourceLocation NameLoc); |
3391 | |
3392 | void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, |
3393 | IdentifierInfo *ClassName, |
3394 | SmallVectorImpl<Decl *> &Decls); |
3395 | Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, |
3396 | Declarator &D, Expr *BitfieldWidth); |
3397 | |
3398 | FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, |
3399 | Declarator &D, Expr *BitfieldWidth, |
3400 | InClassInitStyle InitStyle, |
3401 | AccessSpecifier AS); |
3402 | MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD, |
3403 | SourceLocation DeclStart, Declarator &D, |
3404 | Expr *BitfieldWidth, |
3405 | InClassInitStyle InitStyle, |
3406 | AccessSpecifier AS, |
3407 | const ParsedAttr &MSPropertyAttr); |
3408 | |
3409 | FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, |
3410 | TypeSourceInfo *TInfo, |
3411 | RecordDecl *Record, SourceLocation Loc, |
3412 | bool Mutable, Expr *BitfieldWidth, |
3413 | InClassInitStyle InitStyle, |
3414 | SourceLocation TSSL, |
3415 | AccessSpecifier AS, NamedDecl *PrevDecl, |
3416 | Declarator *D = nullptr); |
3417 | |
3418 | bool CheckNontrivialField(FieldDecl *FD); |
3419 | void DiagnoseNontrivial(const CXXRecordDecl *Record, CXXSpecialMember CSM); |
3420 | |
3421 | enum TrivialABIHandling { |
3422 | /// The triviality of a method unaffected by "trivial_abi". |
3423 | TAH_IgnoreTrivialABI, |
3424 | |
3425 | /// The triviality of a method affected by "trivial_abi". |
3426 | TAH_ConsiderTrivialABI |
3427 | }; |
3428 | |
3429 | bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM, |
3430 | TrivialABIHandling TAH = TAH_IgnoreTrivialABI, |
3431 | bool Diagnose = false); |
3432 | |
3433 | /// For a defaulted function, the kind of defaulted function that it is. |
3434 | class DefaultedFunctionKind { |
3435 | CXXSpecialMember SpecialMember : 8; |
3436 | DefaultedComparisonKind Comparison : 8; |
3437 | |
3438 | public: |
3439 | DefaultedFunctionKind() |
3440 | : SpecialMember(CXXInvalid), Comparison(DefaultedComparisonKind::None) { |
3441 | } |
3442 | DefaultedFunctionKind(CXXSpecialMember CSM) |
3443 | : SpecialMember(CSM), Comparison(DefaultedComparisonKind::None) {} |
3444 | DefaultedFunctionKind(DefaultedComparisonKind Comp) |
3445 | : SpecialMember(CXXInvalid), Comparison(Comp) {} |
3446 | |
3447 | bool isSpecialMember() const { return SpecialMember != CXXInvalid; } |
3448 | bool isComparison() const { |
3449 | return Comparison != DefaultedComparisonKind::None; |
3450 | } |
3451 | |
3452 | explicit operator bool() const { |
3453 | return isSpecialMember() || isComparison(); |
3454 | } |
3455 | |
3456 | CXXSpecialMember asSpecialMember() const { return SpecialMember; } |
3457 | DefaultedComparisonKind asComparison() const { return Comparison; } |
3458 | |
3459 | /// Get the index of this function kind for use in diagnostics. |
3460 | unsigned getDiagnosticIndex() const { |
3461 | static_assert(CXXInvalid > CXXDestructor, |
3462 | "invalid should have highest index" ); |
3463 | static_assert((unsigned)DefaultedComparisonKind::None == 0, |
3464 | "none should be equal to zero" ); |
3465 | return SpecialMember + (unsigned)Comparison; |
3466 | } |
3467 | }; |
3468 | |
3469 | DefaultedFunctionKind getDefaultedFunctionKind(const FunctionDecl *FD); |
3470 | |
3471 | CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD) { |
3472 | return getDefaultedFunctionKind(MD).asSpecialMember(); |
3473 | } |
3474 | DefaultedComparisonKind getDefaultedComparisonKind(const FunctionDecl *FD) { |
3475 | return getDefaultedFunctionKind(FD).asComparison(); |
3476 | } |
3477 | |
3478 | void ActOnLastBitfield(SourceLocation DeclStart, |
3479 | SmallVectorImpl<Decl *> &AllIvarDecls); |
3480 | Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, |
3481 | Declarator &D, Expr *BitfieldWidth, |
3482 | tok::ObjCKeywordKind visibility); |
3483 | |
3484 | // This is used for both record definitions and ObjC interface declarations. |
3485 | void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, |
3486 | ArrayRef<Decl *> Fields, SourceLocation LBrac, |
3487 | SourceLocation RBrac, const ParsedAttributesView &AttrList); |
3488 | |
3489 | /// ActOnTagStartDefinition - Invoked when we have entered the |
3490 | /// scope of a tag's definition (e.g., for an enumeration, class, |
3491 | /// struct, or union). |
3492 | void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); |
3493 | |
3494 | /// Perform ODR-like check for C/ObjC when merging tag types from modules. |
3495 | /// Differently from C++, actually parse the body and reject / error out |
3496 | /// in case of a structural mismatch. |
3497 | bool ActOnDuplicateDefinition(Decl *Prev, SkipBodyInfo &SkipBody); |
3498 | |
3499 | /// Check ODR hashes for C/ObjC when merging types from modules. |
3500 | /// Differently from C++, actually parse the body and reject in case |
3501 | /// of a mismatch. |
3502 | template <typename T, |
3503 | typename = std::enable_if_t<std::is_base_of<NamedDecl, T>::value>> |
3504 | bool ActOnDuplicateODRHashDefinition(T *Duplicate, T *Previous) { |
3505 | if (Duplicate->getODRHash() != Previous->getODRHash()) |
3506 | return false; |
3507 | |
3508 | // Make the previous decl visible. |
3509 | makeMergedDefinitionVisible(Previous); |
3510 | return true; |
3511 | } |
3512 | |
3513 | typedef void *SkippedDefinitionContext; |
3514 | |
3515 | /// Invoked when we enter a tag definition that we're skipping. |
3516 | SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD); |
3517 | |
3518 | void ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl); |
3519 | |
3520 | /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a |
3521 | /// C++ record definition's base-specifiers clause and are starting its |
3522 | /// member declarations. |
3523 | void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, |
3524 | SourceLocation FinalLoc, |
3525 | bool IsFinalSpelledSealed, |
3526 | bool IsAbstract, |
3527 | SourceLocation LBraceLoc); |
3528 | |
3529 | /// ActOnTagFinishDefinition - Invoked once we have finished parsing |
3530 | /// the definition of a tag (enumeration, class, struct, or union). |
3531 | void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, |
3532 | SourceRange BraceRange); |
3533 | |
3534 | void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context); |
3535 | |
3536 | void ActOnObjCContainerFinishDefinition(); |
3537 | |
3538 | /// Invoked when we must temporarily exit the objective-c container |
3539 | /// scope for parsing/looking-up C constructs. |
3540 | /// |
3541 | /// Must be followed by a call to \see ActOnObjCReenterContainerContext |
3542 | void ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx); |
3543 | void ActOnObjCReenterContainerContext(ObjCContainerDecl *ObjCCtx); |
3544 | |
3545 | /// ActOnTagDefinitionError - Invoked when there was an unrecoverable |
3546 | /// error parsing the definition of a tag. |
3547 | void ActOnTagDefinitionError(Scope *S, Decl *TagDecl); |
3548 | |
3549 | EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, |
3550 | EnumConstantDecl *LastEnumConst, |
3551 | SourceLocation IdLoc, |
3552 | IdentifierInfo *Id, |
3553 | Expr *val); |
3554 | bool CheckEnumUnderlyingType(TypeSourceInfo *TI); |
3555 | bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, |
3556 | QualType EnumUnderlyingTy, bool IsFixed, |
3557 | const EnumDecl *Prev); |
3558 | |
3559 | /// Determine whether the body of an anonymous enumeration should be skipped. |
3560 | /// \param II The name of the first enumerator. |
3561 | SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, |
3562 | SourceLocation IILoc); |
3563 | |
3564 | Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, |
3565 | SourceLocation IdLoc, IdentifierInfo *Id, |
3566 | const ParsedAttributesView &Attrs, |
3567 | SourceLocation EqualLoc, Expr *Val); |
3568 | void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, |
3569 | Decl *EnumDecl, ArrayRef<Decl *> Elements, Scope *S, |
3570 | const ParsedAttributesView &Attr); |
3571 | |
3572 | /// Set the current declaration context until it gets popped. |
3573 | void PushDeclContext(Scope *S, DeclContext *DC); |
3574 | void PopDeclContext(); |
3575 | |
3576 | /// EnterDeclaratorContext - Used when we must lookup names in the context |
3577 | /// of a declarator's nested name specifier. |
3578 | void EnterDeclaratorContext(Scope *S, DeclContext *DC); |
3579 | void ExitDeclaratorContext(Scope *S); |
3580 | |
3581 | /// Enter a template parameter scope, after it's been associated with a particular |
3582 | /// DeclContext. Causes lookup within the scope to chain through enclosing contexts |
3583 | /// in the correct order. |
3584 | void EnterTemplatedContext(Scope *S, DeclContext *DC); |
3585 | |
3586 | /// Push the parameters of D, which must be a function, into scope. |
3587 | void ActOnReenterFunctionContext(Scope* S, Decl* D); |
3588 | void ActOnExitFunctionContext(); |
3589 | |
3590 | /// If \p AllowLambda is true, treat lambda as function. |
3591 | DeclContext *getFunctionLevelDeclContext(bool AllowLambda = false) const; |
3592 | |
3593 | /// Returns a pointer to the innermost enclosing function, or nullptr if the |
3594 | /// current context is not inside a function. If \p AllowLambda is true, |
3595 | /// this can return the call operator of an enclosing lambda, otherwise |
3596 | /// lambdas are skipped when looking for an enclosing function. |
3597 | FunctionDecl *getCurFunctionDecl(bool AllowLambda = false) const; |
3598 | |
3599 | /// getCurMethodDecl - If inside of a method body, this returns a pointer to |
3600 | /// the method decl for the method being parsed. If we're currently |
3601 | /// in a 'block', this returns the containing context. |
3602 | ObjCMethodDecl *getCurMethodDecl(); |
3603 | |
3604 | /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method |
3605 | /// or C function we're in, otherwise return null. If we're currently |
3606 | /// in a 'block', this returns the containing context. |
3607 | NamedDecl *getCurFunctionOrMethodDecl() const; |
3608 | |
3609 | /// Add this decl to the scope shadowed decl chains. |
3610 | void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true); |
3611 | |
3612 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
3613 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
3614 | /// true if 'D' belongs to the given declaration context. |
3615 | /// |
3616 | /// \param AllowInlineNamespace If \c true, allow the declaration to be in the |
3617 | /// enclosing namespace set of the context, rather than contained |
3618 | /// directly within it. |
3619 | bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr, |
3620 | bool AllowInlineNamespace = false) const; |
3621 | |
3622 | /// Finds the scope corresponding to the given decl context, if it |
3623 | /// happens to be an enclosing scope. Otherwise return NULL. |
3624 | static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC); |
3625 | |
3626 | /// Subroutines of ActOnDeclarator(). |
3627 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, |
3628 | TypeSourceInfo *TInfo); |
3629 | bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New); |
3630 | |
3631 | /// Describes the kind of merge to perform for availability |
3632 | /// attributes (including "deprecated", "unavailable", and "availability"). |
3633 | enum AvailabilityMergeKind { |
3634 | /// Don't merge availability attributes at all. |
3635 | AMK_None, |
3636 | /// Merge availability attributes for a redeclaration, which requires |
3637 | /// an exact match. |
3638 | AMK_Redeclaration, |
3639 | /// Merge availability attributes for an override, which requires |
3640 | /// an exact match or a weakening of constraints. |
3641 | AMK_Override, |
3642 | /// Merge availability attributes for an implementation of |
3643 | /// a protocol requirement. |
3644 | AMK_ProtocolImplementation, |
3645 | /// Merge availability attributes for an implementation of |
3646 | /// an optional protocol requirement. |
3647 | AMK_OptionalProtocolImplementation |
3648 | }; |
3649 | |
3650 | /// Describes the kind of priority given to an availability attribute. |
3651 | /// |
3652 | /// The sum of priorities deteremines the final priority of the attribute. |
3653 | /// The final priority determines how the attribute will be merged. |
3654 | /// An attribute with a lower priority will always remove higher priority |
3655 | /// attributes for the specified platform when it is being applied. An |
3656 | /// attribute with a higher priority will not be applied if the declaration |
3657 | /// already has an availability attribute with a lower priority for the |
3658 | /// specified platform. The final prirority values are not expected to match |
3659 | /// the values in this enumeration, but instead should be treated as a plain |
3660 | /// integer value. This enumeration just names the priority weights that are |
3661 | /// used to calculate that final vaue. |
3662 | enum AvailabilityPriority : int { |
3663 | /// The availability attribute was specified explicitly next to the |
3664 | /// declaration. |
3665 | AP_Explicit = 0, |
3666 | |
3667 | /// The availability attribute was applied using '#pragma clang attribute'. |
3668 | AP_PragmaClangAttribute = 1, |
3669 | |
3670 | /// The availability attribute for a specific platform was inferred from |
3671 | /// an availability attribute for another platform. |
3672 | AP_InferredFromOtherPlatform = 2 |
3673 | }; |
3674 | |
3675 | /// Attribute merging methods. Return true if a new attribute was added. |
3676 | AvailabilityAttr * |
3677 | mergeAvailabilityAttr(NamedDecl *D, const AttributeCommonInfo &CI, |
3678 | IdentifierInfo *Platform, bool Implicit, |
3679 | VersionTuple Introduced, VersionTuple Deprecated, |
3680 | VersionTuple Obsoleted, bool IsUnavailable, |
3681 | StringRef Message, bool IsStrict, StringRef Replacement, |
3682 | AvailabilityMergeKind AMK, int Priority); |
3683 | TypeVisibilityAttr * |
3684 | mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
3685 | TypeVisibilityAttr::VisibilityType Vis); |
3686 | VisibilityAttr *mergeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
3687 | VisibilityAttr::VisibilityType Vis); |
3688 | UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI, |
3689 | StringRef UuidAsWritten, MSGuidDecl *GuidDecl); |
3690 | DLLImportAttr *mergeDLLImportAttr(Decl *D, const AttributeCommonInfo &CI); |
3691 | DLLExportAttr *mergeDLLExportAttr(Decl *D, const AttributeCommonInfo &CI); |
3692 | MSInheritanceAttr *mergeMSInheritanceAttr(Decl *D, |
3693 | const AttributeCommonInfo &CI, |
3694 | bool BestCase, |
3695 | MSInheritanceModel Model); |
3696 | ErrorAttr *mergeErrorAttr(Decl *D, const AttributeCommonInfo &CI, |
3697 | StringRef NewUserDiagnostic); |
3698 | FormatAttr *mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI, |
3699 | IdentifierInfo *Format, int FormatIdx, |
3700 | int FirstArg); |
3701 | SectionAttr *mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI, |
3702 | StringRef Name); |
3703 | CodeSegAttr *mergeCodeSegAttr(Decl *D, const AttributeCommonInfo &CI, |
3704 | StringRef Name); |
3705 | AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, |
3706 | const AttributeCommonInfo &CI, |
3707 | const IdentifierInfo *Ident); |
3708 | MinSizeAttr *mergeMinSizeAttr(Decl *D, const AttributeCommonInfo &CI); |
3709 | SwiftNameAttr *mergeSwiftNameAttr(Decl *D, const SwiftNameAttr &SNA, |
3710 | StringRef Name); |
3711 | OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, |
3712 | const AttributeCommonInfo &CI); |
3713 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL); |
3714 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, |
3715 | const InternalLinkageAttr &AL); |
3716 | WebAssemblyImportNameAttr *mergeImportNameAttr( |
3717 | Decl *D, const WebAssemblyImportNameAttr &AL); |
3718 | WebAssemblyImportModuleAttr *mergeImportModuleAttr( |
3719 | Decl *D, const WebAssemblyImportModuleAttr &AL); |
3720 | EnforceTCBAttr *mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL); |
3721 | EnforceTCBLeafAttr *mergeEnforceTCBLeafAttr(Decl *D, |
3722 | const EnforceTCBLeafAttr &AL); |
3723 | BTFDeclTagAttr *mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL); |
3724 | HLSLNumThreadsAttr *mergeHLSLNumThreadsAttr(Decl *D, |
3725 | const AttributeCommonInfo &AL, |
3726 | int X, int Y, int Z); |
3727 | HLSLShaderAttr *mergeHLSLShaderAttr(Decl *D, const AttributeCommonInfo &AL, |
3728 | HLSLShaderAttr::ShaderType ShaderType); |
3729 | |
3730 | void mergeDeclAttributes(NamedDecl *New, Decl *Old, |
3731 | AvailabilityMergeKind AMK = AMK_Redeclaration); |
3732 | void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, |
3733 | LookupResult &OldDecls); |
3734 | bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S, |
3735 | bool MergeTypeWithOld, bool NewDeclIsDefn); |
3736 | bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, |
3737 | Scope *S, bool MergeTypeWithOld); |
3738 | void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old); |
3739 | void MergeVarDecl(VarDecl *New, LookupResult &Previous); |
3740 | void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld); |
3741 | void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old); |
3742 | bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn); |
3743 | void notePreviousDefinition(const NamedDecl *Old, SourceLocation New); |
3744 | bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S); |
3745 | |
3746 | // AssignmentAction - This is used by all the assignment diagnostic functions |
3747 | // to represent what is actually causing the operation |
3748 | enum AssignmentAction { |
3749 | AA_Assigning, |
3750 | AA_Passing, |
3751 | AA_Returning, |
3752 | AA_Converting, |
3753 | AA_Initializing, |
3754 | AA_Sending, |
3755 | AA_Casting, |
3756 | AA_Passing_CFAudited |
3757 | }; |
3758 | |
3759 | /// C++ Overloading. |
3760 | enum OverloadKind { |
3761 | /// This is a legitimate overload: the existing declarations are |
3762 | /// functions or function templates with different signatures. |
3763 | Ovl_Overload, |
3764 | |
3765 | /// This is not an overload because the signature exactly matches |
3766 | /// an existing declaration. |
3767 | Ovl_Match, |
3768 | |
3769 | /// This is not an overload because the lookup results contain a |
3770 | /// non-function. |
3771 | Ovl_NonFunction |
3772 | }; |
3773 | OverloadKind CheckOverload(Scope *S, |
3774 | FunctionDecl *New, |
3775 | const LookupResult &OldDecls, |
3776 | NamedDecl *&OldDecl, |
3777 | bool UseMemberUsingDeclRules); |
3778 | bool IsOverload(FunctionDecl *New, FunctionDecl *Old, |
3779 | bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs = true, |
3780 | bool ConsiderRequiresClauses = true); |
3781 | |
3782 | // Calculates whether the expression Constraint depends on an enclosing |
3783 | // template, for the purposes of [temp.friend] p9. |
3784 | // TemplateDepth is the 'depth' of the friend function, which is used to |
3785 | // compare whether a declaration reference is referring to a containing |
3786 | // template, or just the current friend function. A 'lower' TemplateDepth in |
3787 | // the AST refers to a 'containing' template. As the constraint is |
3788 | // uninstantiated, this is relative to the 'top' of the TU. |
3789 | bool |
3790 | ConstraintExpressionDependsOnEnclosingTemplate(const FunctionDecl *Friend, |
3791 | unsigned TemplateDepth, |
3792 | const Expr *Constraint); |
3793 | |
3794 | // Calculates whether the friend function depends on an enclosing template for |
3795 | // the purposes of [temp.friend] p9. |
3796 | bool FriendConstraintsDependOnEnclosingTemplate(const FunctionDecl *FD); |
3797 | |
3798 | // Calculates whether two constraint expressions are equal irrespective of a |
3799 | // difference in 'depth'. This takes a pair of optional 'NamedDecl's 'Old' and |
3800 | // 'New', which are the "source" of the constraint, since this is necessary |
3801 | // for figuring out the relative 'depth' of the constraint. The depth of the |
3802 | // 'primary template' and the 'instantiated from' templates aren't necessarily |
3803 | // the same, such as a case when one is a 'friend' defined in a class. |
3804 | bool AreConstraintExpressionsEqual(const NamedDecl *Old, |
3805 | const Expr *OldConstr, |
3806 | const NamedDecl *New, |
3807 | const Expr *NewConstr); |
3808 | |
3809 | enum class AllowedExplicit { |
3810 | /// Allow no explicit functions to be used. |
3811 | None, |
3812 | /// Allow explicit conversion functions but not explicit constructors. |
3813 | Conversions, |
3814 | /// Allow both explicit conversion functions and explicit constructors. |
3815 | All |
3816 | }; |
3817 | |
3818 | ImplicitConversionSequence |
3819 | TryImplicitConversion(Expr *From, QualType ToType, |
3820 | bool SuppressUserConversions, |
3821 | AllowedExplicit AllowExplicit, |
3822 | bool InOverloadResolution, |
3823 | bool CStyle, |
3824 | bool AllowObjCWritebackConversion); |
3825 | |
3826 | bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); |
3827 | bool IsFloatingPointPromotion(QualType FromType, QualType ToType); |
3828 | bool IsComplexPromotion(QualType FromType, QualType ToType); |
3829 | bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, |
3830 | bool InOverloadResolution, |
3831 | QualType& ConvertedType, bool &IncompatibleObjC); |
3832 | bool isObjCPointerConversion(QualType FromType, QualType ToType, |
3833 | QualType& ConvertedType, bool &IncompatibleObjC); |
3834 | bool isObjCWritebackConversion(QualType FromType, QualType ToType, |
3835 | QualType &ConvertedType); |
3836 | bool IsBlockPointerConversion(QualType FromType, QualType ToType, |
3837 | QualType& ConvertedType); |
3838 | bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType, |
3839 | const FunctionProtoType *NewType, |
3840 | unsigned *ArgPos = nullptr, |
3841 | bool Reversed = false); |
3842 | void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, |
3843 | QualType FromType, QualType ToType); |
3844 | |
3845 | void maybeExtendBlockObject(ExprResult &E); |
3846 | CastKind PrepareCastToObjCObjectPointer(ExprResult &E); |
3847 | bool CheckPointerConversion(Expr *From, QualType ToType, |
3848 | CastKind &Kind, |
3849 | CXXCastPath& BasePath, |
3850 | bool IgnoreBaseAccess, |
3851 | bool Diagnose = true); |
3852 | bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, |
3853 | bool InOverloadResolution, |
3854 | QualType &ConvertedType); |
3855 | bool CheckMemberPointerConversion(Expr *From, QualType ToType, |
3856 | CastKind &Kind, |
3857 | CXXCastPath &BasePath, |
3858 | bool IgnoreBaseAccess); |
3859 | bool IsQualificationConversion(QualType FromType, QualType ToType, |
3860 | bool CStyle, bool &ObjCLifetimeConversion); |
3861 | bool IsFunctionConversion(QualType FromType, QualType ToType, |
3862 | QualType &ResultTy); |
3863 | bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); |
3864 | bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg); |
3865 | |
3866 | bool CanPerformAggregateInitializationForOverloadResolution( |
3867 | const InitializedEntity &Entity, InitListExpr *From); |
3868 | |
3869 | bool IsStringInit(Expr *Init, const ArrayType *AT); |
3870 | |
3871 | bool CanPerformCopyInitialization(const InitializedEntity &Entity, |
3872 | ExprResult Init); |
3873 | ExprResult PerformCopyInitialization(const InitializedEntity &Entity, |
3874 | SourceLocation EqualLoc, |
3875 | ExprResult Init, |
3876 | bool TopLevelOfInitList = false, |
3877 | bool AllowExplicit = false); |
3878 | ExprResult PerformObjectArgumentInitialization(Expr *From, |
3879 | NestedNameSpecifier *Qualifier, |
3880 | NamedDecl *FoundDecl, |
3881 | CXXMethodDecl *Method); |
3882 | |
3883 | /// Check that the lifetime of the initializer (and its subobjects) is |
3884 | /// sufficient for initializing the entity, and perform lifetime extension |
3885 | /// (when permitted) if not. |
3886 | void checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init); |
3887 | |
3888 | ExprResult PerformContextuallyConvertToBool(Expr *From); |
3889 | ExprResult PerformContextuallyConvertToObjCPointer(Expr *From); |
3890 | |
3891 | /// Contexts in which a converted constant expression is required. |
3892 | enum CCEKind { |
3893 | CCEK_CaseValue, ///< Expression in a case label. |
3894 | CCEK_Enumerator, ///< Enumerator value with fixed underlying type. |
3895 | CCEK_TemplateArg, ///< Value of a non-type template parameter. |
3896 | CCEK_ArrayBound, ///< Array bound in array declarator or new-expression. |
3897 | CCEK_ExplicitBool, ///< Condition in an explicit(bool) specifier. |
3898 | CCEK_Noexcept, ///< Condition in a noexcept(bool) specifier. |
3899 | CCEK_StaticAssertMessageSize, ///< Call to size() in a static assert |
3900 | ///< message. |
3901 | CCEK_StaticAssertMessageData, ///< Call to data() in a static assert |
3902 | ///< message. |
3903 | }; |
3904 | |
3905 | ExprResult BuildConvertedConstantExpression(Expr *From, QualType T, |
3906 | CCEKind CCE, |
3907 | NamedDecl *Dest = nullptr); |
3908 | |
3909 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
3910 | llvm::APSInt &Value, CCEKind CCE); |
3911 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
3912 | APValue &Value, CCEKind CCE, |
3913 | NamedDecl *Dest = nullptr); |
3914 | |
3915 | /// Abstract base class used to perform a contextual implicit |
3916 | /// conversion from an expression to any type passing a filter. |
3917 | class ContextualImplicitConverter { |
3918 | public: |
3919 | bool Suppress; |
3920 | bool SuppressConversion; |
3921 | |
3922 | ContextualImplicitConverter(bool Suppress = false, |
3923 | bool SuppressConversion = false) |
3924 | : Suppress(Suppress), SuppressConversion(SuppressConversion) {} |
3925 | |
3926 | /// Determine whether the specified type is a valid destination type |
3927 | /// for this conversion. |
3928 | virtual bool match(QualType T) = 0; |
3929 | |
3930 | /// Emits a diagnostic complaining that the expression does not have |
3931 | /// integral or enumeration type. |
3932 | virtual SemaDiagnosticBuilder |
3933 | diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) = 0; |
3934 | |
3935 | /// Emits a diagnostic when the expression has incomplete class type. |
3936 | virtual SemaDiagnosticBuilder |
3937 | diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0; |
3938 | |
3939 | /// Emits a diagnostic when the only matching conversion function |
3940 | /// is explicit. |
3941 | virtual SemaDiagnosticBuilder diagnoseExplicitConv( |
3942 | Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0; |
3943 | |
3944 | /// Emits a note for the explicit conversion function. |
3945 | virtual SemaDiagnosticBuilder |
3946 | noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
3947 | |
3948 | /// Emits a diagnostic when there are multiple possible conversion |
3949 | /// functions. |
3950 | virtual SemaDiagnosticBuilder |
3951 | diagnoseAmbiguous(Sema &S, SourceLocation Loc, QualType T) = 0; |
3952 | |
3953 | /// Emits a note for one of the candidate conversions. |
3954 | virtual SemaDiagnosticBuilder |
3955 | noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
3956 | |
3957 | /// Emits a diagnostic when we picked a conversion function |
3958 | /// (for cases when we are not allowed to pick a conversion function). |
3959 | virtual SemaDiagnosticBuilder diagnoseConversion( |
3960 | Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0; |
3961 | |
3962 | virtual ~ContextualImplicitConverter() {} |
3963 | }; |
3964 | |
3965 | class ICEConvertDiagnoser : public ContextualImplicitConverter { |
3966 | bool AllowScopedEnumerations; |
3967 | |
3968 | public: |
3969 | ICEConvertDiagnoser(bool AllowScopedEnumerations, |
3970 | bool Suppress, bool SuppressConversion) |
3971 | : ContextualImplicitConverter(Suppress, SuppressConversion), |
3972 | AllowScopedEnumerations(AllowScopedEnumerations) {} |
3973 | |
3974 | /// Match an integral or (possibly scoped) enumeration type. |
3975 | bool match(QualType T) override; |
3976 | |
3977 | SemaDiagnosticBuilder |
3978 | diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) override { |
3979 | return diagnoseNotInt(S, Loc, T); |
3980 | } |
3981 | |
3982 | /// Emits a diagnostic complaining that the expression does not have |
3983 | /// integral or enumeration type. |
3984 | virtual SemaDiagnosticBuilder |
3985 | diagnoseNotInt(Sema &S, SourceLocation Loc, QualType T) = 0; |
3986 | }; |
3987 | |
3988 | /// Perform a contextual implicit conversion. |
3989 | ExprResult PerformContextualImplicitConversion( |
3990 | SourceLocation Loc, Expr *FromE, ContextualImplicitConverter &Converter); |
3991 | |
3992 | |
3993 | enum ObjCSubscriptKind { |
3994 | OS_Array, |
3995 | OS_Dictionary, |
3996 | OS_Error |
3997 | }; |
3998 | ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE); |
3999 | |
4000 | // Note that LK_String is intentionally after the other literals, as |
4001 | // this is used for diagnostics logic. |
4002 | enum ObjCLiteralKind { |
4003 | LK_Array, |
4004 | LK_Dictionary, |
4005 | LK_Numeric, |
4006 | LK_Boxed, |
4007 | LK_String, |
4008 | LK_Block, |
4009 | LK_None |
4010 | }; |
4011 | ObjCLiteralKind CheckLiteralKind(Expr *FromE); |
4012 | |
4013 | ExprResult PerformObjectMemberConversion(Expr *From, |
4014 | NestedNameSpecifier *Qualifier, |
4015 | NamedDecl *FoundDecl, |
4016 | NamedDecl *Member); |
4017 | |
4018 | // Members have to be NamespaceDecl* or TranslationUnitDecl*. |
4019 | // TODO: make this is a typesafe union. |
4020 | typedef llvm::SmallSetVector<DeclContext *, 16> AssociatedNamespaceSet; |
4021 | typedef llvm::SmallSetVector<CXXRecordDecl *, 16> AssociatedClassSet; |
4022 | |
4023 | using ADLCallKind = CallExpr::ADLCallKind; |
4024 | |
4025 | void AddOverloadCandidate( |
4026 | FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef<Expr *> Args, |
4027 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
4028 | bool PartialOverloading = false, bool AllowExplicit = true, |
4029 | bool AllowExplicitConversion = false, |
4030 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
4031 | ConversionSequenceList EarlyConversions = std::nullopt, |
4032 | OverloadCandidateParamOrder PO = {}, |
4033 | bool AggregateCandidateDeduction = false); |
4034 | void AddFunctionCandidates(const UnresolvedSetImpl &Functions, |
4035 | ArrayRef<Expr *> Args, |
4036 | OverloadCandidateSet &CandidateSet, |
4037 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
4038 | bool SuppressUserConversions = false, |
4039 | bool PartialOverloading = false, |
4040 | bool FirstArgumentIsBase = false); |
4041 | void AddMethodCandidate(DeclAccessPair FoundDecl, |
4042 | QualType ObjectType, |
4043 | Expr::Classification ObjectClassification, |
4044 | ArrayRef<Expr *> Args, |
4045 | OverloadCandidateSet& CandidateSet, |
4046 | bool SuppressUserConversion = false, |
4047 | OverloadCandidateParamOrder PO = {}); |
4048 | void |
4049 | AddMethodCandidate(CXXMethodDecl *Method, DeclAccessPair FoundDecl, |
4050 | CXXRecordDecl *ActingContext, QualType ObjectType, |
4051 | Expr::Classification ObjectClassification, |
4052 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, |
4053 | bool SuppressUserConversions = false, |
4054 | bool PartialOverloading = false, |
4055 | ConversionSequenceList EarlyConversions = std::nullopt, |
4056 | OverloadCandidateParamOrder PO = {}); |
4057 | void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, |
4058 | DeclAccessPair FoundDecl, |
4059 | CXXRecordDecl *ActingContext, |
4060 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
4061 | QualType ObjectType, |
4062 | Expr::Classification ObjectClassification, |
4063 | ArrayRef<Expr *> Args, |
4064 | OverloadCandidateSet& CandidateSet, |
4065 | bool SuppressUserConversions = false, |
4066 | bool PartialOverloading = false, |
4067 | OverloadCandidateParamOrder PO = {}); |
4068 | void AddTemplateOverloadCandidate( |
4069 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
4070 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
4071 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
4072 | bool PartialOverloading = false, bool AllowExplicit = true, |
4073 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
4074 | OverloadCandidateParamOrder PO = {}, |
4075 | bool AggregateCandidateDeduction = false); |
4076 | bool CheckNonDependentConversions( |
4077 | FunctionTemplateDecl *FunctionTemplate, ArrayRef<QualType> ParamTypes, |
4078 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, |
4079 | ConversionSequenceList &Conversions, bool SuppressUserConversions, |
4080 | CXXRecordDecl *ActingContext = nullptr, QualType ObjectType = QualType(), |
4081 | Expr::Classification ObjectClassification = {}, |
4082 | OverloadCandidateParamOrder PO = {}); |
4083 | void AddConversionCandidate( |
4084 | CXXConversionDecl *Conversion, DeclAccessPair FoundDecl, |
4085 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
4086 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
4087 | bool AllowExplicit, bool AllowResultConversion = true); |
4088 | void AddTemplateConversionCandidate( |
4089 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
4090 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
4091 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
4092 | bool AllowExplicit, bool AllowResultConversion = true); |
4093 | void AddSurrogateCandidate(CXXConversionDecl *Conversion, |
4094 | DeclAccessPair FoundDecl, |
4095 | CXXRecordDecl *ActingContext, |
4096 | const FunctionProtoType *Proto, |
4097 | Expr *Object, ArrayRef<Expr *> Args, |
4098 | OverloadCandidateSet& CandidateSet); |
4099 | void AddNonMemberOperatorCandidates( |
4100 | const UnresolvedSetImpl &Functions, ArrayRef<Expr *> Args, |
4101 | OverloadCandidateSet &CandidateSet, |
4102 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
4103 | void AddMemberOperatorCandidates(OverloadedOperatorKind Op, |
4104 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
4105 | OverloadCandidateSet &CandidateSet, |
4106 | OverloadCandidateParamOrder PO = {}); |
4107 | void AddBuiltinCandidate(QualType *ParamTys, ArrayRef<Expr *> Args, |
4108 | OverloadCandidateSet& CandidateSet, |
4109 | bool IsAssignmentOperator = false, |
4110 | unsigned NumContextualBoolArguments = 0); |
4111 | void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, |
4112 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
4113 | OverloadCandidateSet& CandidateSet); |
4114 | void AddArgumentDependentLookupCandidates(DeclarationName Name, |
4115 | SourceLocation Loc, |
4116 | ArrayRef<Expr *> Args, |
4117 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
4118 | OverloadCandidateSet& CandidateSet, |
4119 | bool PartialOverloading = false); |
4120 | |
4121 | // Emit as a 'note' the specific overload candidate |
4122 | void NoteOverloadCandidate( |
4123 | const NamedDecl *Found, const FunctionDecl *Fn, |
4124 | OverloadCandidateRewriteKind RewriteKind = OverloadCandidateRewriteKind(), |
4125 | QualType DestType = QualType(), bool TakingAddress = false); |
4126 | |
4127 | // Emit as a series of 'note's all template and non-templates identified by |
4128 | // the expression Expr |
4129 | void NoteAllOverloadCandidates(Expr *E, QualType DestType = QualType(), |
4130 | bool TakingAddress = false); |
4131 | |
4132 | /// Check the enable_if expressions on the given function. Returns the first |
4133 | /// failing attribute, or NULL if they were all successful. |
4134 | EnableIfAttr *CheckEnableIf(FunctionDecl *Function, SourceLocation CallLoc, |
4135 | ArrayRef<Expr *> Args, |
4136 | bool MissingImplicitThis = false); |
4137 | |
4138 | /// Find the failed Boolean condition within a given Boolean |
4139 | /// constant expression, and describe it with a string. |
4140 | std::pair<Expr *, std::string> findFailedBooleanCondition(Expr *Cond); |
4141 | |
4142 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
4143 | /// non-ArgDependent DiagnoseIfAttrs. |
4144 | /// |
4145 | /// Argument-dependent diagnose_if attributes should be checked each time a |
4146 | /// function is used as a direct callee of a function call. |
4147 | /// |
4148 | /// Returns true if any errors were emitted. |
4149 | bool diagnoseArgDependentDiagnoseIfAttrs(const FunctionDecl *Function, |
4150 | const Expr *ThisArg, |
4151 | ArrayRef<const Expr *> Args, |
4152 | SourceLocation Loc); |
4153 | |
4154 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
4155 | /// ArgDependent DiagnoseIfAttrs. |
4156 | /// |
4157 | /// Argument-independent diagnose_if attributes should be checked on every use |
4158 | /// of a function. |
4159 | /// |
4160 | /// Returns true if any errors were emitted. |
4161 | bool diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND, |
4162 | SourceLocation Loc); |
4163 | |
4164 | /// Returns whether the given function's address can be taken or not, |
4165 | /// optionally emitting a diagnostic if the address can't be taken. |
4166 | /// |
4167 | /// Returns false if taking the address of the function is illegal. |
4168 | bool checkAddressOfFunctionIsAvailable(const FunctionDecl *Function, |
4169 | bool Complain = false, |
4170 | SourceLocation Loc = SourceLocation()); |
4171 | |
4172 | // [PossiblyAFunctionType] --> [Return] |
4173 | // NonFunctionType --> NonFunctionType |
4174 | // R (A) --> R(A) |
4175 | // R (*)(A) --> R (A) |
4176 | // R (&)(A) --> R (A) |
4177 | // R (S::*)(A) --> R (A) |
4178 | QualType (QualType PossiblyAFunctionType); |
4179 | |
4180 | FunctionDecl * |
4181 | ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, |
4182 | QualType TargetType, |
4183 | bool Complain, |
4184 | DeclAccessPair &Found, |
4185 | bool *pHadMultipleCandidates = nullptr); |
4186 | |
4187 | FunctionDecl * |
4188 | resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &FoundResult); |
4189 | |
4190 | bool resolveAndFixAddressOfSingleOverloadCandidate( |
4191 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false); |
4192 | |
4193 | FunctionDecl *ResolveSingleFunctionTemplateSpecialization( |
4194 | OverloadExpr *ovl, bool Complain = false, DeclAccessPair *Found = nullptr, |
4195 | TemplateSpecCandidateSet *FailedTSC = nullptr); |
4196 | |
4197 | bool ResolveAndFixSingleFunctionTemplateSpecialization( |
4198 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false, |
4199 | bool Complain = false, SourceRange OpRangeForComplaining = SourceRange(), |
4200 | QualType DestTypeForComplaining = QualType(), |
4201 | unsigned DiagIDForComplaining = 0); |
4202 | |
4203 | Expr *FixOverloadedFunctionReference(Expr *E, |
4204 | DeclAccessPair FoundDecl, |
4205 | FunctionDecl *Fn); |
4206 | ExprResult FixOverloadedFunctionReference(ExprResult, |
4207 | DeclAccessPair FoundDecl, |
4208 | FunctionDecl *Fn); |
4209 | |
4210 | void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, |
4211 | ArrayRef<Expr *> Args, |
4212 | OverloadCandidateSet &CandidateSet, |
4213 | bool PartialOverloading = false); |
4214 | void AddOverloadedCallCandidates( |
4215 | LookupResult &R, TemplateArgumentListInfo *ExplicitTemplateArgs, |
4216 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet); |
4217 | |
4218 | // An enum used to represent the different possible results of building a |
4219 | // range-based for loop. |
4220 | enum ForRangeStatus { |
4221 | FRS_Success, |
4222 | FRS_NoViableFunction, |
4223 | FRS_DiagnosticIssued |
4224 | }; |
4225 | |
4226 | ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc, |
4227 | SourceLocation RangeLoc, |
4228 | const DeclarationNameInfo &NameInfo, |
4229 | LookupResult &MemberLookup, |
4230 | OverloadCandidateSet *CandidateSet, |
4231 | Expr *Range, ExprResult *CallExpr); |
4232 | |
4233 | ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn, |
4234 | UnresolvedLookupExpr *ULE, |
4235 | SourceLocation LParenLoc, |
4236 | MultiExprArg Args, |
4237 | SourceLocation RParenLoc, |
4238 | Expr *ExecConfig, |
4239 | bool AllowTypoCorrection=true, |
4240 | bool CalleesAddressIsTaken=false); |
4241 | |
4242 | bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, |
4243 | MultiExprArg Args, SourceLocation RParenLoc, |
4244 | OverloadCandidateSet *CandidateSet, |
4245 | ExprResult *Result); |
4246 | |
4247 | ExprResult CreateUnresolvedLookupExpr(CXXRecordDecl *NamingClass, |
4248 | NestedNameSpecifierLoc NNSLoc, |
4249 | DeclarationNameInfo DNI, |
4250 | const UnresolvedSetImpl &Fns, |
4251 | bool PerformADL = true); |
4252 | |
4253 | ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, |
4254 | UnaryOperatorKind Opc, |
4255 | const UnresolvedSetImpl &Fns, |
4256 | Expr *input, bool RequiresADL = true); |
4257 | |
4258 | void LookupOverloadedBinOp(OverloadCandidateSet &CandidateSet, |
4259 | OverloadedOperatorKind Op, |
4260 | const UnresolvedSetImpl &Fns, |
4261 | ArrayRef<Expr *> Args, bool RequiresADL = true); |
4262 | ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, |
4263 | BinaryOperatorKind Opc, |
4264 | const UnresolvedSetImpl &Fns, |
4265 | Expr *LHS, Expr *RHS, |
4266 | bool RequiresADL = true, |
4267 | bool AllowRewrittenCandidates = true, |
4268 | FunctionDecl *DefaultedFn = nullptr); |
4269 | ExprResult BuildSynthesizedThreeWayComparison(SourceLocation OpLoc, |
4270 | const UnresolvedSetImpl &Fns, |
4271 | Expr *LHS, Expr *RHS, |
4272 | FunctionDecl *DefaultedFn); |
4273 | |
4274 | ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, |
4275 | SourceLocation RLoc, Expr *Base, |
4276 | MultiExprArg Args); |
4277 | |
4278 | ExprResult BuildCallToMemberFunction(Scope *S, Expr *MemExpr, |
4279 | SourceLocation LParenLoc, |
4280 | MultiExprArg Args, |
4281 | SourceLocation RParenLoc, |
4282 | Expr *ExecConfig = nullptr, |
4283 | bool IsExecConfig = false, |
4284 | bool AllowRecovery = false); |
4285 | ExprResult |
4286 | BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, |
4287 | MultiExprArg Args, |
4288 | SourceLocation RParenLoc); |
4289 | |
4290 | ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, |
4291 | SourceLocation OpLoc, |
4292 | bool *NoArrowOperatorFound = nullptr); |
4293 | |
4294 | /// CheckCallReturnType - Checks that a call expression's return type is |
4295 | /// complete. Returns true on failure. The location passed in is the location |
4296 | /// that best represents the call. |
4297 | bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, |
4298 | CallExpr *CE, FunctionDecl *FD); |
4299 | |
4300 | /// Helpers for dealing with blocks and functions. |
4301 | bool CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters, |
4302 | bool CheckParameterNames); |
4303 | void CheckCXXDefaultArguments(FunctionDecl *FD); |
4304 | void (Declarator &D); |
4305 | Scope *getNonFieldDeclScope(Scope *S); |
4306 | |
4307 | /// \name Name lookup |
4308 | /// |
4309 | /// These routines provide name lookup that is used during semantic |
4310 | /// analysis to resolve the various kinds of names (identifiers, |
4311 | /// overloaded operator names, constructor names, etc.) into zero or |
4312 | /// more declarations within a particular scope. The major entry |
4313 | /// points are LookupName, which performs unqualified name lookup, |
4314 | /// and LookupQualifiedName, which performs qualified name lookup. |
4315 | /// |
4316 | /// All name lookup is performed based on some specific criteria, |
4317 | /// which specify what names will be visible to name lookup and how |
4318 | /// far name lookup should work. These criteria are important both |
4319 | /// for capturing language semantics (certain lookups will ignore |
4320 | /// certain names, for example) and for performance, since name |
4321 | /// lookup is often a bottleneck in the compilation of C++. Name |
4322 | /// lookup criteria is specified via the LookupCriteria enumeration. |
4323 | /// |
4324 | /// The results of name lookup can vary based on the kind of name |
4325 | /// lookup performed, the current language, and the translation |
4326 | /// unit. In C, for example, name lookup will either return nothing |
4327 | /// (no entity found) or a single declaration. In C++, name lookup |
4328 | /// can additionally refer to a set of overloaded functions or |
4329 | /// result in an ambiguity. All of the possible results of name |
4330 | /// lookup are captured by the LookupResult class, which provides |
4331 | /// the ability to distinguish among them. |
4332 | //@{ |
4333 | |
4334 | /// Describes the kind of name lookup to perform. |
4335 | enum LookupNameKind { |
4336 | /// Ordinary name lookup, which finds ordinary names (functions, |
4337 | /// variables, typedefs, etc.) in C and most kinds of names |
4338 | /// (functions, variables, members, types, etc.) in C++. |
4339 | LookupOrdinaryName = 0, |
4340 | /// Tag name lookup, which finds the names of enums, classes, |
4341 | /// structs, and unions. |
4342 | LookupTagName, |
4343 | /// Label name lookup. |
4344 | LookupLabel, |
4345 | /// Member name lookup, which finds the names of |
4346 | /// class/struct/union members. |
4347 | LookupMemberName, |
4348 | /// Look up of an operator name (e.g., operator+) for use with |
4349 | /// operator overloading. This lookup is similar to ordinary name |
4350 | /// lookup, but will ignore any declarations that are class members. |
4351 | LookupOperatorName, |
4352 | /// Look up a name following ~ in a destructor name. This is an ordinary |
4353 | /// lookup, but prefers tags to typedefs. |
4354 | LookupDestructorName, |
4355 | /// Look up of a name that precedes the '::' scope resolution |
4356 | /// operator in C++. This lookup completely ignores operator, object, |
4357 | /// function, and enumerator names (C++ [basic.lookup.qual]p1). |
4358 | LookupNestedNameSpecifierName, |
4359 | /// Look up a namespace name within a C++ using directive or |
4360 | /// namespace alias definition, ignoring non-namespace names (C++ |
4361 | /// [basic.lookup.udir]p1). |
4362 | LookupNamespaceName, |
4363 | /// Look up all declarations in a scope with the given name, |
4364 | /// including resolved using declarations. This is appropriate |
4365 | /// for checking redeclarations for a using declaration. |
4366 | LookupUsingDeclName, |
4367 | /// Look up an ordinary name that is going to be redeclared as a |
4368 | /// name with linkage. This lookup ignores any declarations that |
4369 | /// are outside of the current scope unless they have linkage. See |
4370 | /// C99 6.2.2p4-5 and C++ [basic.link]p6. |
4371 | LookupRedeclarationWithLinkage, |
4372 | /// Look up a friend of a local class. This lookup does not look |
4373 | /// outside the innermost non-class scope. See C++11 [class.friend]p11. |
4374 | LookupLocalFriendName, |
4375 | /// Look up the name of an Objective-C protocol. |
4376 | LookupObjCProtocolName, |
4377 | /// Look up implicit 'self' parameter of an objective-c method. |
4378 | LookupObjCImplicitSelfParam, |
4379 | /// Look up the name of an OpenMP user-defined reduction operation. |
4380 | LookupOMPReductionName, |
4381 | /// Look up the name of an OpenMP user-defined mapper. |
4382 | LookupOMPMapperName, |
4383 | /// Look up any declaration with any name. |
4384 | LookupAnyName |
4385 | }; |
4386 | |
4387 | /// Specifies whether (or how) name lookup is being performed for a |
4388 | /// redeclaration (vs. a reference). |
4389 | enum RedeclarationKind { |
4390 | /// The lookup is a reference to this name that is not for the |
4391 | /// purpose of redeclaring the name. |
4392 | NotForRedeclaration = 0, |
4393 | /// The lookup results will be used for redeclaration of a name, |
4394 | /// if an entity by that name already exists and is visible. |
4395 | ForVisibleRedeclaration, |
4396 | /// The lookup results will be used for redeclaration of a name |
4397 | /// with external linkage; non-visible lookup results with external linkage |
4398 | /// may also be found. |
4399 | ForExternalRedeclaration |
4400 | }; |
4401 | |
4402 | RedeclarationKind forRedeclarationInCurContext() const { |
4403 | // A declaration with an owning module for linkage can never link against |
4404 | // anything that is not visible. We don't need to check linkage here; if |
4405 | // the context has internal linkage, redeclaration lookup won't find things |
4406 | // from other TUs, and we can't safely compute linkage yet in general. |
4407 | if (cast<Decl>(CurContext) |
4408 | ->getOwningModuleForLinkage(/*IgnoreLinkage*/true)) |
4409 | return ForVisibleRedeclaration; |
4410 | return ForExternalRedeclaration; |
4411 | } |
4412 | |
4413 | /// The possible outcomes of name lookup for a literal operator. |
4414 | enum LiteralOperatorLookupResult { |
4415 | /// The lookup resulted in an error. |
4416 | LOLR_Error, |
4417 | /// The lookup found no match but no diagnostic was issued. |
4418 | LOLR_ErrorNoDiagnostic, |
4419 | /// The lookup found a single 'cooked' literal operator, which |
4420 | /// expects a normal literal to be built and passed to it. |
4421 | LOLR_Cooked, |
4422 | /// The lookup found a single 'raw' literal operator, which expects |
4423 | /// a string literal containing the spelling of the literal token. |
4424 | LOLR_Raw, |
4425 | /// The lookup found an overload set of literal operator templates, |
4426 | /// which expect the characters of the spelling of the literal token to be |
4427 | /// passed as a non-type template argument pack. |
4428 | LOLR_Template, |
4429 | /// The lookup found an overload set of literal operator templates, |
4430 | /// which expect the character type and characters of the spelling of the |
4431 | /// string literal token to be passed as template arguments. |
4432 | LOLR_StringTemplatePack, |
4433 | }; |
4434 | |
4435 | SpecialMemberOverloadResult LookupSpecialMember(CXXRecordDecl *D, |
4436 | CXXSpecialMember SM, |
4437 | bool ConstArg, |
4438 | bool VolatileArg, |
4439 | bool RValueThis, |
4440 | bool ConstThis, |
4441 | bool VolatileThis); |
4442 | |
4443 | typedef std::function<void(const TypoCorrection &)> TypoDiagnosticGenerator; |
4444 | typedef std::function<ExprResult(Sema &, TypoExpr *, TypoCorrection)> |
4445 | TypoRecoveryCallback; |
4446 | |
4447 | private: |
4448 | bool CppLookupName(LookupResult &R, Scope *S); |
4449 | |
4450 | struct TypoExprState { |
4451 | std::unique_ptr<TypoCorrectionConsumer> Consumer; |
4452 | TypoDiagnosticGenerator DiagHandler; |
4453 | TypoRecoveryCallback RecoveryHandler; |
4454 | TypoExprState(); |
4455 | TypoExprState(TypoExprState &&other) noexcept; |
4456 | TypoExprState &operator=(TypoExprState &&other) noexcept; |
4457 | }; |
4458 | |
4459 | /// The set of unhandled TypoExprs and their associated state. |
4460 | llvm::MapVector<TypoExpr *, TypoExprState> DelayedTypos; |
4461 | |
4462 | /// Creates a new TypoExpr AST node. |
4463 | TypoExpr *createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC, |
4464 | TypoDiagnosticGenerator TDG, |
4465 | TypoRecoveryCallback TRC, SourceLocation TypoLoc); |
4466 | |
4467 | // The set of known/encountered (unique, canonicalized) NamespaceDecls. |
4468 | // |
4469 | // The boolean value will be true to indicate that the namespace was loaded |
4470 | // from an AST/PCH file, or false otherwise. |
4471 | llvm::MapVector<NamespaceDecl*, bool> KnownNamespaces; |
4472 | |
4473 | /// Whether we have already loaded known namespaces from an extenal |
4474 | /// source. |
4475 | bool LoadedExternalKnownNamespaces; |
4476 | |
4477 | /// Helper for CorrectTypo and CorrectTypoDelayed used to create and |
4478 | /// populate a new TypoCorrectionConsumer. Returns nullptr if typo correction |
4479 | /// should be skipped entirely. |
4480 | std::unique_ptr<TypoCorrectionConsumer> |
4481 | makeTypoCorrectionConsumer(const DeclarationNameInfo &Typo, |
4482 | Sema::LookupNameKind LookupKind, Scope *S, |
4483 | CXXScopeSpec *SS, |
4484 | CorrectionCandidateCallback &CCC, |
4485 | DeclContext *MemberContext, bool EnteringContext, |
4486 | const ObjCObjectPointerType *OPT, |
4487 | bool ErrorRecovery); |
4488 | |
4489 | public: |
4490 | const TypoExprState &getTypoExprState(TypoExpr *TE) const; |
4491 | |
4492 | /// Clears the state of the given TypoExpr. |
4493 | void clearDelayedTypo(TypoExpr *TE); |
4494 | |
4495 | /// Look up a name, looking for a single declaration. Return |
4496 | /// null if the results were absent, ambiguous, or overloaded. |
4497 | /// |
4498 | /// It is preferable to use the elaborated form and explicitly handle |
4499 | /// ambiguity and overloaded. |
4500 | NamedDecl *LookupSingleName(Scope *S, DeclarationName Name, |
4501 | SourceLocation Loc, |
4502 | LookupNameKind NameKind, |
4503 | RedeclarationKind Redecl |
4504 | = NotForRedeclaration); |
4505 | bool LookupBuiltin(LookupResult &R); |
4506 | void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID); |
4507 | bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation = false, |
4508 | bool ForceNoCPlusPlus = false); |
4509 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
4510 | bool InUnqualifiedLookup = false); |
4511 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
4512 | CXXScopeSpec &SS); |
4513 | bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, |
4514 | bool AllowBuiltinCreation = false, |
4515 | bool EnteringContext = false); |
4516 | ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, |
4517 | RedeclarationKind Redecl |
4518 | = NotForRedeclaration); |
4519 | bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class); |
4520 | |
4521 | void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, |
4522 | UnresolvedSetImpl &Functions); |
4523 | |
4524 | LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, |
4525 | SourceLocation GnuLabelLoc = SourceLocation()); |
4526 | |
4527 | DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); |
4528 | CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class); |
4529 | CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class, |
4530 | unsigned Quals); |
4531 | CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, |
4532 | bool RValueThis, unsigned ThisQuals); |
4533 | CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class, |
4534 | unsigned Quals); |
4535 | CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals, |
4536 | bool RValueThis, unsigned ThisQuals); |
4537 | CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); |
4538 | |
4539 | bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id, |
4540 | bool IsUDSuffix); |
4541 | LiteralOperatorLookupResult |
4542 | LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef<QualType> ArgTys, |
4543 | bool AllowRaw, bool AllowTemplate, |
4544 | bool AllowStringTemplate, bool DiagnoseMissing, |
4545 | StringLiteral *StringLit = nullptr); |
4546 | bool isKnownName(StringRef name); |
4547 | |
4548 | /// Status of the function emission on the CUDA/HIP/OpenMP host/device attrs. |
4549 | enum class FunctionEmissionStatus { |
4550 | Emitted, |
4551 | CUDADiscarded, // Discarded due to CUDA/HIP hostness |
4552 | OMPDiscarded, // Discarded due to OpenMP hostness |
4553 | TemplateDiscarded, // Discarded due to uninstantiated templates |
4554 | Unknown, |
4555 | }; |
4556 | FunctionEmissionStatus getEmissionStatus(const FunctionDecl *Decl, |
4557 | bool Final = false); |
4558 | |
4559 | // Whether the callee should be ignored in CUDA/HIP/OpenMP host/device check. |
4560 | bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee); |
4561 | |
4562 | void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc, |
4563 | ArrayRef<Expr *> Args, ADLResult &Functions); |
4564 | |
4565 | void LookupVisibleDecls(Scope *S, LookupNameKind Kind, |
4566 | VisibleDeclConsumer &Consumer, |
4567 | bool IncludeGlobalScope = true, |
4568 | bool LoadExternal = true); |
4569 | void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, |
4570 | VisibleDeclConsumer &Consumer, |
4571 | bool IncludeGlobalScope = true, |
4572 | bool IncludeDependentBases = false, |
4573 | bool LoadExternal = true); |
4574 | |
4575 | enum CorrectTypoKind { |
4576 | CTK_NonError, // CorrectTypo used in a non error recovery situation. |
4577 | CTK_ErrorRecovery // CorrectTypo used in normal error recovery. |
4578 | }; |
4579 | |
4580 | TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, |
4581 | Sema::LookupNameKind LookupKind, |
4582 | Scope *S, CXXScopeSpec *SS, |
4583 | CorrectionCandidateCallback &CCC, |
4584 | CorrectTypoKind Mode, |
4585 | DeclContext *MemberContext = nullptr, |
4586 | bool EnteringContext = false, |
4587 | const ObjCObjectPointerType *OPT = nullptr, |
4588 | bool RecordFailure = true); |
4589 | |
4590 | TypoExpr *CorrectTypoDelayed(const DeclarationNameInfo &Typo, |
4591 | Sema::LookupNameKind LookupKind, Scope *S, |
4592 | CXXScopeSpec *SS, |
4593 | CorrectionCandidateCallback &CCC, |
4594 | TypoDiagnosticGenerator TDG, |
4595 | TypoRecoveryCallback TRC, CorrectTypoKind Mode, |
4596 | DeclContext *MemberContext = nullptr, |
4597 | bool EnteringContext = false, |
4598 | const ObjCObjectPointerType *OPT = nullptr); |
4599 | |
4600 | /// Process any TypoExprs in the given Expr and its children, |
4601 | /// generating diagnostics as appropriate and returning a new Expr if there |
4602 | /// were typos that were all successfully corrected and ExprError if one or |
4603 | /// more typos could not be corrected. |
4604 | /// |
4605 | /// \param E The Expr to check for TypoExprs. |
4606 | /// |
4607 | /// \param InitDecl A VarDecl to avoid because the Expr being corrected is its |
4608 | /// initializer. |
4609 | /// |
4610 | /// \param RecoverUncorrectedTypos If true, when typo correction fails, it |
4611 | /// will rebuild the given Expr with all TypoExprs degraded to RecoveryExprs. |
4612 | /// |
4613 | /// \param Filter A function applied to a newly rebuilt Expr to determine if |
4614 | /// it is an acceptable/usable result from a single combination of typo |
4615 | /// corrections. As long as the filter returns ExprError, different |
4616 | /// combinations of corrections will be tried until all are exhausted. |
4617 | ExprResult CorrectDelayedTyposInExpr( |
4618 | Expr *E, VarDecl *InitDecl = nullptr, |
4619 | bool RecoverUncorrectedTypos = false, |
4620 | llvm::function_ref<ExprResult(Expr *)> Filter = |
4621 | [](Expr *E) -> ExprResult { return E; }); |
4622 | |
4623 | ExprResult CorrectDelayedTyposInExpr( |
4624 | ExprResult ER, VarDecl *InitDecl = nullptr, |
4625 | bool RecoverUncorrectedTypos = false, |
4626 | llvm::function_ref<ExprResult(Expr *)> Filter = |
4627 | [](Expr *E) -> ExprResult { return E; }) { |
4628 | return ER.isInvalid() |
4629 | ? ER |
4630 | : CorrectDelayedTyposInExpr(ER.get(), InitDecl, |
4631 | RecoverUncorrectedTypos, Filter); |
4632 | } |
4633 | |
4634 | void diagnoseTypo(const TypoCorrection &Correction, |
4635 | const PartialDiagnostic &TypoDiag, |
4636 | bool ErrorRecovery = true); |
4637 | |
4638 | void diagnoseTypo(const TypoCorrection &Correction, |
4639 | const PartialDiagnostic &TypoDiag, |
4640 | const PartialDiagnostic &PrevNote, |
4641 | bool ErrorRecovery = true); |
4642 | |
4643 | void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F); |
4644 | |
4645 | void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc, |
4646 | ArrayRef<Expr *> Args, |
4647 | AssociatedNamespaceSet &AssociatedNamespaces, |
4648 | AssociatedClassSet &AssociatedClasses); |
4649 | |
4650 | void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, |
4651 | bool ConsiderLinkage, bool AllowInlineNamespace); |
4652 | |
4653 | bool CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old); |
4654 | bool CheckRedeclarationExported(NamedDecl *New, NamedDecl *Old); |
4655 | bool CheckRedeclarationInModule(NamedDecl *New, NamedDecl *Old); |
4656 | bool IsRedefinitionInModule(const NamedDecl *New, |
4657 | const NamedDecl *Old) const; |
4658 | |
4659 | void DiagnoseAmbiguousLookup(LookupResult &Result); |
4660 | //@} |
4661 | |
4662 | /// Attempts to produce a RecoveryExpr after some AST node cannot be created. |
4663 | ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, |
4664 | ArrayRef<Expr *> SubExprs, |
4665 | QualType T = QualType()); |
4666 | |
4667 | ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id, |
4668 | SourceLocation IdLoc, |
4669 | bool TypoCorrection = false); |
4670 | FunctionDecl *CreateBuiltin(IdentifierInfo *II, QualType Type, unsigned ID, |
4671 | SourceLocation Loc); |
4672 | NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, |
4673 | Scope *S, bool ForRedeclaration, |
4674 | SourceLocation Loc); |
4675 | NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
4676 | Scope *S); |
4677 | void AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction( |
4678 | FunctionDecl *FD); |
4679 | void AddKnownFunctionAttributes(FunctionDecl *FD); |
4680 | |
4681 | // More parsing and symbol table subroutines. |
4682 | |
4683 | void ProcessPragmaWeak(Scope *S, Decl *D); |
4684 | // Decl attributes - this routine is the top level dispatcher. |
4685 | void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD); |
4686 | // Helper for delayed processing of attributes. |
4687 | void ProcessDeclAttributeDelayed(Decl *D, |
4688 | const ParsedAttributesView &AttrList); |
4689 | |
4690 | // Options for ProcessDeclAttributeList(). |
4691 | struct ProcessDeclAttributeOptions { |
4692 | ProcessDeclAttributeOptions() |
4693 | : IncludeCXX11Attributes(true), IgnoreTypeAttributes(false) {} |
4694 | |
4695 | ProcessDeclAttributeOptions WithIncludeCXX11Attributes(bool Val) { |
4696 | ProcessDeclAttributeOptions Result = *this; |
4697 | Result.IncludeCXX11Attributes = Val; |
4698 | return Result; |
4699 | } |
4700 | |
4701 | ProcessDeclAttributeOptions WithIgnoreTypeAttributes(bool Val) { |
4702 | ProcessDeclAttributeOptions Result = *this; |
4703 | Result.IgnoreTypeAttributes = Val; |
4704 | return Result; |
4705 | } |
4706 | |
4707 | // Should C++11 attributes be processed? |
4708 | bool IncludeCXX11Attributes; |
4709 | |
4710 | // Should any type attributes encountered be ignored? |
4711 | // If this option is false, a diagnostic will be emitted for any type |
4712 | // attributes of a kind that does not "slide" from the declaration to |
4713 | // the decl-specifier-seq. |
4714 | bool IgnoreTypeAttributes; |
4715 | }; |
4716 | |
4717 | void ProcessDeclAttributeList(Scope *S, Decl *D, |
4718 | const ParsedAttributesView &AttrList, |
4719 | const ProcessDeclAttributeOptions &Options = |
4720 | ProcessDeclAttributeOptions()); |
4721 | bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, |
4722 | const ParsedAttributesView &AttrList); |
4723 | |
4724 | void checkUnusedDeclAttributes(Declarator &D); |
4725 | |
4726 | /// Handles semantic checking for features that are common to all attributes, |
4727 | /// such as checking whether a parameter was properly specified, or the |
4728 | /// correct number of arguments were passed, etc. Returns true if the |
4729 | /// attribute has been diagnosed. |
4730 | bool checkCommonAttributeFeatures(const Decl *D, const ParsedAttr &A, |
4731 | bool SkipArgCountCheck = false); |
4732 | bool checkCommonAttributeFeatures(const Stmt *S, const ParsedAttr &A, |
4733 | bool SkipArgCountCheck = false); |
4734 | |
4735 | /// Determine if type T is a valid subject for a nonnull and similar |
4736 | /// attributes. By default, we look through references (the behavior used by |
4737 | /// nonnull), but if the second parameter is true, then we treat a reference |
4738 | /// type as valid. |
4739 | bool isValidPointerAttrType(QualType T, bool RefOkay = false); |
4740 | |
4741 | bool CheckRegparmAttr(const ParsedAttr &attr, unsigned &value); |
4742 | bool CheckCallingConvAttr(const ParsedAttr &attr, CallingConv &CC, |
4743 | const FunctionDecl *FD = nullptr); |
4744 | bool CheckAttrTarget(const ParsedAttr &CurrAttr); |
4745 | bool CheckAttrNoArgs(const ParsedAttr &CurrAttr); |
4746 | bool checkStringLiteralArgumentAttr(const AttributeCommonInfo &CI, |
4747 | const Expr *E, StringRef &Str, |
4748 | SourceLocation *ArgLocation = nullptr); |
4749 | bool checkStringLiteralArgumentAttr(const ParsedAttr &Attr, unsigned ArgNum, |
4750 | StringRef &Str, |
4751 | SourceLocation *ArgLocation = nullptr); |
4752 | llvm::Error isValidSectionSpecifier(StringRef Str); |
4753 | bool checkSectionName(SourceLocation LiteralLoc, StringRef Str); |
4754 | bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str); |
4755 | bool checkTargetVersionAttr(SourceLocation LiteralLoc, StringRef &Str, |
4756 | bool &isDefault); |
4757 | bool |
4758 | checkTargetClonesAttrString(SourceLocation LiteralLoc, StringRef Str, |
4759 | const StringLiteral *Literal, bool &HasDefault, |
4760 | bool &HasCommas, bool &HasNotDefault, |
4761 | SmallVectorImpl<SmallString<64>> &StringsBuffer); |
4762 | bool checkMSInheritanceAttrOnDefinition( |
4763 | CXXRecordDecl *RD, SourceRange Range, bool BestCase, |
4764 | MSInheritanceModel SemanticSpelling); |
4765 | |
4766 | void CheckAlignasUnderalignment(Decl *D); |
4767 | |
4768 | bool CheckNoInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, |
4769 | const AttributeCommonInfo &A); |
4770 | bool CheckAlwaysInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, |
4771 | const AttributeCommonInfo &A); |
4772 | |
4773 | /// Adjust the calling convention of a method to be the ABI default if it |
4774 | /// wasn't specified explicitly. This handles method types formed from |
4775 | /// function type typedefs and typename template arguments. |
4776 | void adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor, |
4777 | SourceLocation Loc); |
4778 | |
4779 | // Check if there is an explicit attribute, but only look through parens. |
4780 | // The intent is to look for an attribute on the current declarator, but not |
4781 | // one that came from a typedef. |
4782 | bool hasExplicitCallingConv(QualType T); |
4783 | |
4784 | /// Get the outermost AttributedType node that sets a calling convention. |
4785 | /// Valid types should not have multiple attributes with different CCs. |
4786 | const AttributedType *getCallingConvAttributedType(QualType T) const; |
4787 | |
4788 | /// Process the attributes before creating an attributed statement. Returns |
4789 | /// the semantic attributes that have been processed. |
4790 | void ProcessStmtAttributes(Stmt *Stmt, const ParsedAttributes &InAttrs, |
4791 | SmallVectorImpl<const Attr *> &OutAttrs); |
4792 | |
4793 | void WarnConflictingTypedMethods(ObjCMethodDecl *Method, |
4794 | ObjCMethodDecl *MethodDecl, |
4795 | bool IsProtocolMethodDecl); |
4796 | |
4797 | void CheckConflictingOverridingMethod(ObjCMethodDecl *Method, |
4798 | ObjCMethodDecl *Overridden, |
4799 | bool IsProtocolMethodDecl); |
4800 | |
4801 | /// WarnExactTypedMethods - This routine issues a warning if method |
4802 | /// implementation declaration matches exactly that of its declaration. |
4803 | void WarnExactTypedMethods(ObjCMethodDecl *Method, |
4804 | ObjCMethodDecl *MethodDecl, |
4805 | bool IsProtocolMethodDecl); |
4806 | |
4807 | typedef llvm::SmallPtrSet<Selector, 8> SelectorSet; |
4808 | |
4809 | /// CheckImplementationIvars - This routine checks if the instance variables |
4810 | /// listed in the implelementation match those listed in the interface. |
4811 | void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, |
4812 | ObjCIvarDecl **Fields, unsigned nIvars, |
4813 | SourceLocation Loc); |
4814 | |
4815 | /// ImplMethodsVsClassMethods - This is main routine to warn if any method |
4816 | /// remains unimplemented in the class or category \@implementation. |
4817 | void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, |
4818 | ObjCContainerDecl* IDecl, |
4819 | bool IncompleteImpl = false); |
4820 | |
4821 | /// DiagnoseUnimplementedProperties - This routine warns on those properties |
4822 | /// which must be implemented by this implementation. |
4823 | void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, |
4824 | ObjCContainerDecl *CDecl, |
4825 | bool SynthesizeProperties); |
4826 | |
4827 | /// Diagnose any null-resettable synthesized setters. |
4828 | void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl); |
4829 | |
4830 | /// DefaultSynthesizeProperties - This routine default synthesizes all |
4831 | /// properties which must be synthesized in the class's \@implementation. |
4832 | void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, |
4833 | ObjCInterfaceDecl *IDecl, |
4834 | SourceLocation AtEnd); |
4835 | void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd); |
4836 | |
4837 | /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is |
4838 | /// an ivar synthesized for 'Method' and 'Method' is a property accessor |
4839 | /// declared in class 'IFace'. |
4840 | bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace, |
4841 | ObjCMethodDecl *Method, ObjCIvarDecl *IV); |
4842 | |
4843 | /// DiagnoseUnusedBackingIvarInAccessor - Issue an 'unused' warning if ivar which |
4844 | /// backs the property is not used in the property's accessor. |
4845 | void DiagnoseUnusedBackingIvarInAccessor(Scope *S, |
4846 | const ObjCImplementationDecl *ImplD); |
4847 | |
4848 | /// GetIvarBackingPropertyAccessor - If method is a property setter/getter and |
4849 | /// it property has a backing ivar, returns this ivar; otherwise, returns NULL. |
4850 | /// It also returns ivar's property on success. |
4851 | ObjCIvarDecl *GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method, |
4852 | const ObjCPropertyDecl *&PDecl) const; |
4853 | |
4854 | /// Called by ActOnProperty to handle \@property declarations in |
4855 | /// class extensions. |
4856 | ObjCPropertyDecl *HandlePropertyInClassExtension(Scope *S, |
4857 | SourceLocation AtLoc, |
4858 | SourceLocation LParenLoc, |
4859 | FieldDeclarator &FD, |
4860 | Selector GetterSel, |
4861 | SourceLocation GetterNameLoc, |
4862 | Selector SetterSel, |
4863 | SourceLocation SetterNameLoc, |
4864 | const bool isReadWrite, |
4865 | unsigned &Attributes, |
4866 | const unsigned AttributesAsWritten, |
4867 | QualType T, |
4868 | TypeSourceInfo *TSI, |
4869 | tok::ObjCKeywordKind MethodImplKind); |
4870 | |
4871 | /// Called by ActOnProperty and HandlePropertyInClassExtension to |
4872 | /// handle creating the ObjcPropertyDecl for a category or \@interface. |
4873 | ObjCPropertyDecl *CreatePropertyDecl(Scope *S, |
4874 | ObjCContainerDecl *CDecl, |
4875 | SourceLocation AtLoc, |
4876 | SourceLocation LParenLoc, |
4877 | FieldDeclarator &FD, |
4878 | Selector GetterSel, |
4879 | SourceLocation GetterNameLoc, |
4880 | Selector SetterSel, |
4881 | SourceLocation SetterNameLoc, |
4882 | const bool isReadWrite, |
4883 | const unsigned Attributes, |
4884 | const unsigned AttributesAsWritten, |
4885 | QualType T, |
4886 | TypeSourceInfo *TSI, |
4887 | tok::ObjCKeywordKind MethodImplKind, |
4888 | DeclContext *lexicalDC = nullptr); |
4889 | |
4890 | /// AtomicPropertySetterGetterRules - This routine enforces the rule (via |
4891 | /// warning) when atomic property has one but not the other user-declared |
4892 | /// setter or getter. |
4893 | void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl, |
4894 | ObjCInterfaceDecl* IDecl); |
4895 | |
4896 | void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D); |
4897 | |
4898 | void DiagnoseMissingDesignatedInitOverrides( |
4899 | const ObjCImplementationDecl *ImplD, |
4900 | const ObjCInterfaceDecl *IFD); |
4901 | |
4902 | void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); |
4903 | |
4904 | enum MethodMatchStrategy { |
4905 | MMS_loose, |
4906 | MMS_strict |
4907 | }; |
4908 | |
4909 | /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns |
4910 | /// true, or false, accordingly. |
4911 | bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, |
4912 | const ObjCMethodDecl *PrevMethod, |
4913 | MethodMatchStrategy strategy = MMS_strict); |
4914 | |
4915 | /// MatchAllMethodDeclarations - Check methods declaraed in interface or |
4916 | /// or protocol against those declared in their implementations. |
4917 | void MatchAllMethodDeclarations(const SelectorSet &InsMap, |
4918 | const SelectorSet &ClsMap, |
4919 | SelectorSet &InsMapSeen, |
4920 | SelectorSet &ClsMapSeen, |
4921 | ObjCImplDecl* IMPDecl, |
4922 | ObjCContainerDecl* IDecl, |
4923 | bool &IncompleteImpl, |
4924 | bool ImmediateClass, |
4925 | bool WarnCategoryMethodImpl=false); |
4926 | |
4927 | /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in |
4928 | /// category matches with those implemented in its primary class and |
4929 | /// warns each time an exact match is found. |
4930 | void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP); |
4931 | |
4932 | /// Add the given method to the list of globally-known methods. |
4933 | void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method); |
4934 | |
4935 | /// Returns default addr space for method qualifiers. |
4936 | LangAS getDefaultCXXMethodAddrSpace() const; |
4937 | |
4938 | private: |
4939 | /// AddMethodToGlobalPool - Add an instance or factory method to the global |
4940 | /// pool. See descriptoin of AddInstanceMethodToGlobalPool. |
4941 | void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); |
4942 | |
4943 | /// LookupMethodInGlobalPool - Returns the instance or factory method and |
4944 | /// optionally warns if there are multiple signatures. |
4945 | ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, |
4946 | bool receiverIdOrClass, |
4947 | bool instance); |
4948 | |
4949 | public: |
4950 | /// - Returns instance or factory methods in global method pool for |
4951 | /// given selector. It checks the desired kind first, if none is found, and |
4952 | /// parameter checkTheOther is set, it then checks the other kind. If no such |
4953 | /// method or only one method is found, function returns false; otherwise, it |
4954 | /// returns true. |
4955 | bool |
4956 | CollectMultipleMethodsInGlobalPool(Selector Sel, |
4957 | SmallVectorImpl<ObjCMethodDecl*>& Methods, |
4958 | bool InstanceFirst, bool CheckTheOther, |
4959 | const ObjCObjectType *TypeBound = nullptr); |
4960 | |
4961 | bool |
4962 | AreMultipleMethodsInGlobalPool(Selector Sel, ObjCMethodDecl *BestMethod, |
4963 | SourceRange R, bool receiverIdOrClass, |
4964 | SmallVectorImpl<ObjCMethodDecl*>& Methods); |
4965 | |
4966 | void |
4967 | DiagnoseMultipleMethodInGlobalPool(SmallVectorImpl<ObjCMethodDecl*> &Methods, |
4968 | Selector Sel, SourceRange R, |
4969 | bool receiverIdOrClass); |
4970 | |
4971 | private: |
4972 | /// - Returns a selector which best matches given argument list or |
4973 | /// nullptr if none could be found |
4974 | ObjCMethodDecl *SelectBestMethod(Selector Sel, MultiExprArg Args, |
4975 | bool IsInstance, |
4976 | SmallVectorImpl<ObjCMethodDecl*>& Methods); |
4977 | |
4978 | |
4979 | /// Record the typo correction failure and return an empty correction. |
4980 | TypoCorrection FailedCorrection(IdentifierInfo *Typo, SourceLocation TypoLoc, |
4981 | bool RecordFailure = true) { |
4982 | if (RecordFailure) |
4983 | TypoCorrectionFailures[Typo].insert(TypoLoc); |
4984 | return TypoCorrection(); |
4985 | } |
4986 | |
4987 | public: |
4988 | /// AddInstanceMethodToGlobalPool - All instance methods in a translation |
4989 | /// unit are added to a global pool. This allows us to efficiently associate |
4990 | /// a selector with a method declaraation for purposes of typechecking |
4991 | /// messages sent to "id" (where the class of the object is unknown). |
4992 | void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { |
4993 | AddMethodToGlobalPool(Method, impl, /*instance*/true); |
4994 | } |
4995 | |
4996 | /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. |
4997 | void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { |
4998 | AddMethodToGlobalPool(Method, impl, /*instance*/false); |
4999 | } |
5000 | |
5001 | /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global |
5002 | /// pool. |
5003 | void AddAnyMethodToGlobalPool(Decl *D); |
5004 | |
5005 | /// LookupInstanceMethodInGlobalPool - Returns the method and warns if |
5006 | /// there are multiple signatures. |
5007 | ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, |
5008 | bool receiverIdOrClass=false) { |
5009 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
5010 | /*instance*/true); |
5011 | } |
5012 | |
5013 | /// LookupFactoryMethodInGlobalPool - Returns the method and warns if |
5014 | /// there are multiple signatures. |
5015 | ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, |
5016 | bool receiverIdOrClass=false) { |
5017 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
5018 | /*instance*/false); |
5019 | } |
5020 | |
5021 | const ObjCMethodDecl *SelectorsForTypoCorrection(Selector Sel, |
5022 | QualType ObjectType=QualType()); |
5023 | /// LookupImplementedMethodInGlobalPool - Returns the method which has an |
5024 | /// implementation. |
5025 | ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); |
5026 | |
5027 | /// CollectIvarsToConstructOrDestruct - Collect those ivars which require |
5028 | /// initialization. |
5029 | void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, |
5030 | SmallVectorImpl<ObjCIvarDecl*> &Ivars); |
5031 | |
5032 | //===--------------------------------------------------------------------===// |
5033 | // Statement Parsing Callbacks: SemaStmt.cpp. |
5034 | public: |
5035 | class FullExprArg { |
5036 | public: |
5037 | FullExprArg() : E(nullptr) { } |
5038 | FullExprArg(Sema &actions) : E(nullptr) { } |
5039 | |
5040 | ExprResult release() { |
5041 | return E; |
5042 | } |
5043 | |
5044 | Expr *get() const { return E; } |
5045 | |
5046 | Expr *operator->() { |
5047 | return E; |
5048 | } |
5049 | |
5050 | private: |
5051 | // FIXME: No need to make the entire Sema class a friend when it's just |
5052 | // Sema::MakeFullExpr that needs access to the constructor below. |
5053 | friend class Sema; |
5054 | |
5055 | explicit FullExprArg(Expr *expr) : E(expr) {} |
5056 | |
5057 | Expr *E; |
5058 | }; |
5059 | |
5060 | FullExprArg MakeFullExpr(Expr *Arg) { |
5061 | return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation()); |
5062 | } |
5063 | FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) { |
5064 | return FullExprArg( |
5065 | ActOnFinishFullExpr(Arg, CC, /*DiscardedValue*/ false).get()); |
5066 | } |
5067 | FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) { |
5068 | ExprResult FE = |
5069 | ActOnFinishFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation(), |
5070 | /*DiscardedValue*/ true); |
5071 | return FullExprArg(FE.get()); |
5072 | } |
5073 | |
5074 | StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue = true); |
5075 | StmtResult ActOnExprStmtError(); |
5076 | |
5077 | StmtResult ActOnNullStmt(SourceLocation SemiLoc, |
5078 | bool HasLeadingEmptyMacro = false); |
5079 | |
5080 | void ActOnStartOfCompoundStmt(bool IsStmtExpr); |
5081 | void ActOnAfterCompoundStatementLeadingPragmas(); |
5082 | void ActOnFinishOfCompoundStmt(); |
5083 | StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
5084 | ArrayRef<Stmt *> Elts, bool isStmtExpr); |
5085 | |
5086 | /// A RAII object to enter scope of a compound statement. |
5087 | class CompoundScopeRAII { |
5088 | public: |
5089 | CompoundScopeRAII(Sema &S, bool IsStmtExpr = false) : S(S) { |
5090 | S.ActOnStartOfCompoundStmt(IsStmtExpr); |
5091 | } |
5092 | |
5093 | ~CompoundScopeRAII() { |
5094 | S.ActOnFinishOfCompoundStmt(); |
5095 | } |
5096 | |
5097 | private: |
5098 | Sema &S; |
5099 | }; |
5100 | |
5101 | /// An RAII helper that pops function a function scope on exit. |
5102 | struct FunctionScopeRAII { |
5103 | Sema &S; |
5104 | bool Active; |
5105 | FunctionScopeRAII(Sema &S) : S(S), Active(true) {} |
5106 | ~FunctionScopeRAII() { |
5107 | if (Active) |
5108 | S.PopFunctionScopeInfo(); |
5109 | } |
5110 | void disable() { Active = false; } |
5111 | }; |
5112 | |
5113 | StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, |
5114 | SourceLocation StartLoc, |
5115 | SourceLocation EndLoc); |
5116 | void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); |
5117 | StmtResult ActOnForEachLValueExpr(Expr *E); |
5118 | ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val); |
5119 | StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, |
5120 | SourceLocation DotDotDotLoc, ExprResult RHS, |
5121 | SourceLocation ColonLoc); |
5122 | void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); |
5123 | |
5124 | StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, |
5125 | SourceLocation ColonLoc, |
5126 | Stmt *SubStmt, Scope *CurScope); |
5127 | StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, |
5128 | SourceLocation ColonLoc, Stmt *SubStmt); |
5129 | |
5130 | StmtResult BuildAttributedStmt(SourceLocation AttrsLoc, |
5131 | ArrayRef<const Attr *> Attrs, Stmt *SubStmt); |
5132 | StmtResult ActOnAttributedStmt(const ParsedAttributes &AttrList, |
5133 | Stmt *SubStmt); |
5134 | |
5135 | class ConditionResult; |
5136 | |
5137 | StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, |
5138 | SourceLocation LParenLoc, Stmt *InitStmt, |
5139 | ConditionResult Cond, SourceLocation RParenLoc, |
5140 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
5141 | StmtResult BuildIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, |
5142 | SourceLocation LParenLoc, Stmt *InitStmt, |
5143 | ConditionResult Cond, SourceLocation RParenLoc, |
5144 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
5145 | StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, |
5146 | SourceLocation LParenLoc, Stmt *InitStmt, |
5147 | ConditionResult Cond, |
5148 | SourceLocation RParenLoc); |
5149 | StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, |
5150 | Stmt *Switch, Stmt *Body); |
5151 | StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, |
5152 | ConditionResult Cond, SourceLocation RParenLoc, |
5153 | Stmt *Body); |
5154 | StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, |
5155 | SourceLocation WhileLoc, SourceLocation CondLParen, |
5156 | Expr *Cond, SourceLocation CondRParen); |
5157 | |
5158 | StmtResult ActOnForStmt(SourceLocation ForLoc, |
5159 | SourceLocation LParenLoc, |
5160 | Stmt *First, |
5161 | ConditionResult Second, |
5162 | FullExprArg Third, |
5163 | SourceLocation RParenLoc, |
5164 | Stmt *Body); |
5165 | ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, |
5166 | Expr *collection); |
5167 | StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, |
5168 | Stmt *First, Expr *collection, |
5169 | SourceLocation RParenLoc); |
5170 | StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body); |
5171 | |
5172 | enum BuildForRangeKind { |
5173 | /// Initial building of a for-range statement. |
5174 | BFRK_Build, |
5175 | /// Instantiation or recovery rebuild of a for-range statement. Don't |
5176 | /// attempt any typo-correction. |
5177 | BFRK_Rebuild, |
5178 | /// Determining whether a for-range statement could be built. Avoid any |
5179 | /// unnecessary or irreversible actions. |
5180 | BFRK_Check |
5181 | }; |
5182 | |
5183 | StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc, |
5184 | SourceLocation CoawaitLoc, |
5185 | Stmt *InitStmt, |
5186 | Stmt *LoopVar, |
5187 | SourceLocation ColonLoc, Expr *Collection, |
5188 | SourceLocation RParenLoc, |
5189 | BuildForRangeKind Kind); |
5190 | StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, |
5191 | SourceLocation CoawaitLoc, |
5192 | Stmt *InitStmt, |
5193 | SourceLocation ColonLoc, |
5194 | Stmt *RangeDecl, Stmt *Begin, Stmt *End, |
5195 | Expr *Cond, Expr *Inc, |
5196 | Stmt *LoopVarDecl, |
5197 | SourceLocation RParenLoc, |
5198 | BuildForRangeKind Kind); |
5199 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body); |
5200 | |
5201 | StmtResult ActOnGotoStmt(SourceLocation GotoLoc, |
5202 | SourceLocation LabelLoc, |
5203 | LabelDecl *TheDecl); |
5204 | StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, |
5205 | SourceLocation StarLoc, |
5206 | Expr *DestExp); |
5207 | StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope); |
5208 | StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope); |
5209 | |
5210 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
5211 | CapturedRegionKind Kind, unsigned NumParams); |
5212 | typedef std::pair<StringRef, QualType> CapturedParamNameType; |
5213 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
5214 | CapturedRegionKind Kind, |
5215 | ArrayRef<CapturedParamNameType> Params, |
5216 | unsigned OpenMPCaptureLevel = 0); |
5217 | StmtResult ActOnCapturedRegionEnd(Stmt *S); |
5218 | void ActOnCapturedRegionError(); |
5219 | RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD, |
5220 | SourceLocation Loc, |
5221 | unsigned NumParams); |
5222 | |
5223 | struct NamedReturnInfo { |
5224 | const VarDecl *Candidate; |
5225 | |
5226 | enum Status : uint8_t { None, MoveEligible, MoveEligibleAndCopyElidable }; |
5227 | Status S; |
5228 | |
5229 | bool isMoveEligible() const { return S != None; }; |
5230 | bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; } |
5231 | }; |
5232 | enum class SimplerImplicitMoveMode { ForceOff, Normal, ForceOn }; |
5233 | NamedReturnInfo getNamedReturnInfo( |
5234 | Expr *&E, SimplerImplicitMoveMode Mode = SimplerImplicitMoveMode::Normal); |
5235 | NamedReturnInfo getNamedReturnInfo(const VarDecl *VD); |
5236 | const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info, |
5237 | QualType ReturnType); |
5238 | |
5239 | ExprResult |
5240 | PerformMoveOrCopyInitialization(const InitializedEntity &Entity, |
5241 | const NamedReturnInfo &NRInfo, Expr *Value, |
5242 | bool SupressSimplerImplicitMoves = false); |
5243 | |
5244 | StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
5245 | Scope *CurScope); |
5246 | StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
5247 | bool AllowRecovery = false); |
5248 | StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
5249 | NamedReturnInfo &NRInfo, |
5250 | bool SupressSimplerImplicitMoves); |
5251 | |
5252 | StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
5253 | bool IsVolatile, unsigned NumOutputs, |
5254 | unsigned NumInputs, IdentifierInfo **Names, |
5255 | MultiExprArg Constraints, MultiExprArg Exprs, |
5256 | Expr *AsmString, MultiExprArg Clobbers, |
5257 | unsigned NumLabels, |
5258 | SourceLocation RParenLoc); |
5259 | |
5260 | void FillInlineAsmIdentifierInfo(Expr *Res, |
5261 | llvm::InlineAsmIdentifierInfo &Info); |
5262 | ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS, |
5263 | SourceLocation TemplateKWLoc, |
5264 | UnqualifiedId &Id, |
5265 | bool IsUnevaluatedContext); |
5266 | bool LookupInlineAsmField(StringRef Base, StringRef Member, |
5267 | unsigned &Offset, SourceLocation AsmLoc); |
5268 | ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member, |
5269 | SourceLocation AsmLoc); |
5270 | StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
5271 | ArrayRef<Token> AsmToks, |
5272 | StringRef AsmString, |
5273 | unsigned NumOutputs, unsigned NumInputs, |
5274 | ArrayRef<StringRef> Constraints, |
5275 | ArrayRef<StringRef> Clobbers, |
5276 | ArrayRef<Expr*> Exprs, |
5277 | SourceLocation EndLoc); |
5278 | LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName, |
5279 | SourceLocation Location, |
5280 | bool AlwaysCreate); |
5281 | |
5282 | VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, |
5283 | SourceLocation StartLoc, |
5284 | SourceLocation IdLoc, IdentifierInfo *Id, |
5285 | bool Invalid = false); |
5286 | |
5287 | Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); |
5288 | |
5289 | StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, |
5290 | Decl *Parm, Stmt *Body); |
5291 | |
5292 | StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); |
5293 | |
5294 | StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, |
5295 | MultiStmtArg Catch, Stmt *Finally); |
5296 | |
5297 | StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); |
5298 | StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, |
5299 | Scope *CurScope); |
5300 | ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, |
5301 | Expr *operand); |
5302 | StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, |
5303 | Expr *SynchExpr, |
5304 | Stmt *SynchBody); |
5305 | |
5306 | StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body); |
5307 | |
5308 | VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, |
5309 | SourceLocation StartLoc, |
5310 | SourceLocation IdLoc, |
5311 | IdentifierInfo *Id); |
5312 | |
5313 | Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); |
5314 | |
5315 | StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, |
5316 | Decl *ExDecl, Stmt *HandlerBlock); |
5317 | StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, |
5318 | ArrayRef<Stmt *> Handlers); |
5319 | |
5320 | StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ? |
5321 | SourceLocation TryLoc, Stmt *TryBlock, |
5322 | Stmt *Handler); |
5323 | StmtResult ActOnSEHExceptBlock(SourceLocation Loc, |
5324 | Expr *FilterExpr, |
5325 | Stmt *Block); |
5326 | void ActOnStartSEHFinallyBlock(); |
5327 | void ActOnAbortSEHFinallyBlock(); |
5328 | StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block); |
5329 | StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope); |
5330 | |
5331 | void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); |
5332 | |
5333 | bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; |
5334 | |
5335 | /// If it's a file scoped decl that must warn if not used, keep track |
5336 | /// of it. |
5337 | void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); |
5338 | |
5339 | typedef llvm::function_ref<void(SourceLocation Loc, PartialDiagnostic PD)> |
5340 | DiagReceiverTy; |
5341 | |
5342 | /// DiagnoseUnusedExprResult - If the statement passed in is an expression |
5343 | /// whose result is unused, warn. |
5344 | void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID); |
5345 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D); |
5346 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D, |
5347 | DiagReceiverTy DiagReceiver); |
5348 | void DiagnoseUnusedDecl(const NamedDecl *ND); |
5349 | void DiagnoseUnusedDecl(const NamedDecl *ND, DiagReceiverTy DiagReceiver); |
5350 | |
5351 | /// If VD is set but not otherwise used, diagnose, for a parameter or a |
5352 | /// variable. |
5353 | void DiagnoseUnusedButSetDecl(const VarDecl *VD, DiagReceiverTy DiagReceiver); |
5354 | |
5355 | /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null |
5356 | /// statement as a \p Body, and it is located on the same line. |
5357 | /// |
5358 | /// This helps prevent bugs due to typos, such as: |
5359 | /// if (condition); |
5360 | /// do_stuff(); |
5361 | void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, |
5362 | const Stmt *Body, |
5363 | unsigned DiagID); |
5364 | |
5365 | /// Warn if a for/while loop statement \p S, which is followed by |
5366 | /// \p PossibleBody, has a suspicious null statement as a body. |
5367 | void DiagnoseEmptyLoopBody(const Stmt *S, |
5368 | const Stmt *PossibleBody); |
5369 | |
5370 | /// Warn if a value is moved to itself. |
5371 | void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr, |
5372 | SourceLocation OpLoc); |
5373 | |
5374 | /// Returns a field in a CXXRecordDecl that has the same name as the decl \p |
5375 | /// SelfAssigned when inside a CXXMethodDecl. |
5376 | const FieldDecl * |
5377 | getSelfAssignmentClassMemberCandidate(const ValueDecl *SelfAssigned); |
5378 | |
5379 | /// Warn if we're implicitly casting from a _Nullable pointer type to a |
5380 | /// _Nonnull one. |
5381 | void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType, |
5382 | SourceLocation Loc); |
5383 | |
5384 | /// Warn when implicitly casting 0 to nullptr. |
5385 | void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E); |
5386 | |
5387 | ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) { |
5388 | return DelayedDiagnostics.push(pool); |
5389 | } |
5390 | void PopParsingDeclaration(ParsingDeclState state, Decl *decl); |
5391 | |
5392 | typedef ProcessingContextState ParsingClassState; |
5393 | ParsingClassState PushParsingClass() { |
5394 | ParsingClassDepth++; |
5395 | return DelayedDiagnostics.pushUndelayed(); |
5396 | } |
5397 | void PopParsingClass(ParsingClassState state) { |
5398 | ParsingClassDepth--; |
5399 | DelayedDiagnostics.popUndelayed(state); |
5400 | } |
5401 | |
5402 | void redelayDiagnostics(sema::DelayedDiagnosticPool &pool); |
5403 | |
5404 | void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
5405 | const ObjCInterfaceDecl *UnknownObjCClass, |
5406 | bool ObjCPropertyAccess, |
5407 | bool AvoidPartialAvailabilityChecks = false, |
5408 | ObjCInterfaceDecl *ClassReceiver = nullptr); |
5409 | |
5410 | bool (SourceLocation loc, |
5411 | UnavailableAttr::ImplicitReason reason); |
5412 | |
5413 | /// Issue any -Wunguarded-availability warnings in \c FD |
5414 | void DiagnoseUnguardedAvailabilityViolations(Decl *FD); |
5415 | |
5416 | void handleDelayedAvailabilityCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
5417 | |
5418 | //===--------------------------------------------------------------------===// |
5419 | // Expression Parsing Callbacks: SemaExpr.cpp. |
5420 | |
5421 | bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid); |
5422 | // A version of DiagnoseUseOfDecl that should be used if overload resolution |
5423 | // has been used to find this declaration, which means we don't have to bother |
5424 | // checking the trailing requires clause. |
5425 | bool DiagnoseUseOfOverloadedDecl(NamedDecl *D, SourceLocation Loc) { |
5426 | return DiagnoseUseOfDecl( |
5427 | D, Loc, /*UnknownObjCClass=*/nullptr, /*ObjCPropertyAccess=*/false, |
5428 | /*AvoidPartialAvailabilityChecks=*/false, /*ClassReceiver=*/nullptr, |
5429 | /*SkipTrailingRequiresClause=*/true); |
5430 | } |
5431 | |
5432 | bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
5433 | const ObjCInterfaceDecl *UnknownObjCClass = nullptr, |
5434 | bool ObjCPropertyAccess = false, |
5435 | bool AvoidPartialAvailabilityChecks = false, |
5436 | ObjCInterfaceDecl *ClassReciever = nullptr, |
5437 | bool SkipTrailingRequiresClause = false); |
5438 | void NoteDeletedFunction(FunctionDecl *FD); |
5439 | void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD); |
5440 | bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, |
5441 | ObjCMethodDecl *Getter, |
5442 | SourceLocation Loc); |
5443 | void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, |
5444 | ArrayRef<Expr *> Args); |
5445 | |
5446 | void PushExpressionEvaluationContext( |
5447 | ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl = nullptr, |
5448 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
5449 | ExpressionEvaluationContextRecord::EK_Other); |
5450 | enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl }; |
5451 | void PushExpressionEvaluationContext( |
5452 | ExpressionEvaluationContext NewContext, ReuseLambdaContextDecl_t, |
5453 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
5454 | ExpressionEvaluationContextRecord::EK_Other); |
5455 | void PopExpressionEvaluationContext(); |
5456 | |
5457 | void DiscardCleanupsInEvaluationContext(); |
5458 | |
5459 | ExprResult TransformToPotentiallyEvaluated(Expr *E); |
5460 | TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo); |
5461 | ExprResult HandleExprEvaluationContextForTypeof(Expr *E); |
5462 | |
5463 | ExprResult CheckUnevaluatedOperand(Expr *E); |
5464 | void CheckUnusedVolatileAssignment(Expr *E); |
5465 | |
5466 | ExprResult ActOnConstantExpression(ExprResult Res); |
5467 | |
5468 | // Functions for marking a declaration referenced. These functions also |
5469 | // contain the relevant logic for marking if a reference to a function or |
5470 | // variable is an odr-use (in the C++11 sense). There are separate variants |
5471 | // for expressions referring to a decl; these exist because odr-use marking |
5472 | // needs to be delayed for some constant variables when we build one of the |
5473 | // named expressions. |
5474 | // |
5475 | // MightBeOdrUse indicates whether the use could possibly be an odr-use, and |
5476 | // should usually be true. This only needs to be set to false if the lack of |
5477 | // odr-use cannot be determined from the current context (for instance, |
5478 | // because the name denotes a virtual function and was written without an |
5479 | // explicit nested-name-specifier). |
5480 | void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse); |
5481 | void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, |
5482 | bool MightBeOdrUse = true); |
5483 | void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var); |
5484 | void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base = nullptr); |
5485 | void MarkMemberReferenced(MemberExpr *E); |
5486 | void MarkFunctionParmPackReferenced(FunctionParmPackExpr *E); |
5487 | void MarkCaptureUsedInEnclosingContext(ValueDecl *Capture, SourceLocation Loc, |
5488 | unsigned CapturingScopeIndex); |
5489 | |
5490 | ExprResult CheckLValueToRValueConversionOperand(Expr *E); |
5491 | void CleanupVarDeclMarking(); |
5492 | |
5493 | enum TryCaptureKind { |
5494 | TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef |
5495 | }; |
5496 | |
5497 | /// Try to capture the given variable. |
5498 | /// |
5499 | /// \param Var The variable to capture. |
5500 | /// |
5501 | /// \param Loc The location at which the capture occurs. |
5502 | /// |
5503 | /// \param Kind The kind of capture, which may be implicit (for either a |
5504 | /// block or a lambda), or explicit by-value or by-reference (for a lambda). |
5505 | /// |
5506 | /// \param EllipsisLoc The location of the ellipsis, if one is provided in |
5507 | /// an explicit lambda capture. |
5508 | /// |
5509 | /// \param BuildAndDiagnose Whether we are actually supposed to add the |
5510 | /// captures or diagnose errors. If false, this routine merely check whether |
5511 | /// the capture can occur without performing the capture itself or complaining |
5512 | /// if the variable cannot be captured. |
5513 | /// |
5514 | /// \param CaptureType Will be set to the type of the field used to capture |
5515 | /// this variable in the innermost block or lambda. Only valid when the |
5516 | /// variable can be captured. |
5517 | /// |
5518 | /// \param DeclRefType Will be set to the type of a reference to the capture |
5519 | /// from within the current scope. Only valid when the variable can be |
5520 | /// captured. |
5521 | /// |
5522 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
5523 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
5524 | /// This is useful when enclosing lambdas must speculatively capture |
5525 | /// variables that may or may not be used in certain specializations of |
5526 | /// a nested generic lambda. |
5527 | /// |
5528 | /// \returns true if an error occurred (i.e., the variable cannot be |
5529 | /// captured) and false if the capture succeeded. |
5530 | bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, |
5531 | TryCaptureKind Kind, SourceLocation EllipsisLoc, |
5532 | bool BuildAndDiagnose, QualType &CaptureType, |
5533 | QualType &DeclRefType, |
5534 | const unsigned *const FunctionScopeIndexToStopAt); |
5535 | |
5536 | /// Try to capture the given variable. |
5537 | bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, |
5538 | TryCaptureKind Kind = TryCapture_Implicit, |
5539 | SourceLocation EllipsisLoc = SourceLocation()); |
5540 | |
5541 | /// Checks if the variable must be captured. |
5542 | bool NeedToCaptureVariable(ValueDecl *Var, SourceLocation Loc); |
5543 | |
5544 | /// Given a variable, determine the type that a reference to that |
5545 | /// variable will have in the given scope. |
5546 | QualType getCapturedDeclRefType(ValueDecl *Var, SourceLocation Loc); |
5547 | |
5548 | /// Mark all of the declarations referenced within a particular AST node as |
5549 | /// referenced. Used when template instantiation instantiates a non-dependent |
5550 | /// type -- entities referenced by the type are now referenced. |
5551 | void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); |
5552 | void MarkDeclarationsReferencedInExpr( |
5553 | Expr *E, bool SkipLocalVariables = false, |
5554 | ArrayRef<const Expr *> StopAt = std::nullopt); |
5555 | |
5556 | /// Try to recover by turning the given expression into a |
5557 | /// call. Returns true if recovery was attempted or an error was |
5558 | /// emitted; this may also leave the ExprResult invalid. |
5559 | bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, |
5560 | bool ForceComplain = false, |
5561 | bool (*IsPlausibleResult)(QualType) = nullptr); |
5562 | |
5563 | /// Figure out if an expression could be turned into a call. |
5564 | bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy, |
5565 | UnresolvedSetImpl &NonTemplateOverloads); |
5566 | |
5567 | /// Try to convert an expression \p E to type \p Ty. Returns the result of the |
5568 | /// conversion. |
5569 | ExprResult tryConvertExprToType(Expr *E, QualType Ty); |
5570 | |
5571 | /// Conditionally issue a diagnostic based on the statements's reachability |
5572 | /// analysis. |
5573 | /// |
5574 | /// \param Stmts If Stmts is non-empty, delay reporting the diagnostic until |
5575 | /// the function body is parsed, and then do a basic reachability analysis to |
5576 | /// determine if the statement is reachable. If it is unreachable, the |
5577 | /// diagnostic will not be emitted. |
5578 | bool DiagIfReachable(SourceLocation Loc, ArrayRef<const Stmt *> Stmts, |
5579 | const PartialDiagnostic &PD); |
5580 | |
5581 | /// Conditionally issue a diagnostic based on the current |
5582 | /// evaluation context. |
5583 | /// |
5584 | /// \param Statement If Statement is non-null, delay reporting the |
5585 | /// diagnostic until the function body is parsed, and then do a basic |
5586 | /// reachability analysis to determine if the statement is reachable. |
5587 | /// If it is unreachable, the diagnostic will not be emitted. |
5588 | bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, |
5589 | const PartialDiagnostic &PD); |
5590 | /// Similar, but diagnostic is only produced if all the specified statements |
5591 | /// are reachable. |
5592 | bool DiagRuntimeBehavior(SourceLocation Loc, ArrayRef<const Stmt*> Stmts, |
5593 | const PartialDiagnostic &PD); |
5594 | |
5595 | // Primary Expressions. |
5596 | SourceRange getExprRange(Expr *E) const; |
5597 | |
5598 | ExprResult ActOnIdExpression( |
5599 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
5600 | UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand, |
5601 | CorrectionCandidateCallback *CCC = nullptr, |
5602 | bool IsInlineAsmIdentifier = false, Token *KeywordReplacement = nullptr); |
5603 | |
5604 | void DecomposeUnqualifiedId(const UnqualifiedId &Id, |
5605 | TemplateArgumentListInfo &Buffer, |
5606 | DeclarationNameInfo &NameInfo, |
5607 | const TemplateArgumentListInfo *&TemplateArgs); |
5608 | |
5609 | bool DiagnoseDependentMemberLookup(const LookupResult &R); |
5610 | |
5611 | bool |
5612 | DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, |
5613 | CorrectionCandidateCallback &CCC, |
5614 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
5615 | ArrayRef<Expr *> Args = std::nullopt, |
5616 | TypoExpr **Out = nullptr); |
5617 | |
5618 | DeclResult LookupIvarInObjCMethod(LookupResult &Lookup, Scope *S, |
5619 | IdentifierInfo *II); |
5620 | ExprResult BuildIvarRefExpr(Scope *S, SourceLocation Loc, ObjCIvarDecl *IV); |
5621 | |
5622 | ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S, |
5623 | IdentifierInfo *II, |
5624 | bool AllowBuiltinCreation=false); |
5625 | |
5626 | ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, |
5627 | SourceLocation TemplateKWLoc, |
5628 | const DeclarationNameInfo &NameInfo, |
5629 | bool isAddressOfOperand, |
5630 | const TemplateArgumentListInfo *TemplateArgs); |
5631 | |
5632 | /// If \p D cannot be odr-used in the current expression evaluation context, |
5633 | /// return a reason explaining why. Otherwise, return NOUR_None. |
5634 | NonOdrUseReason getNonOdrUseReasonInCurrentContext(ValueDecl *D); |
5635 | |
5636 | DeclRefExpr *BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
5637 | SourceLocation Loc, |
5638 | const CXXScopeSpec *SS = nullptr); |
5639 | DeclRefExpr * |
5640 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
5641 | const DeclarationNameInfo &NameInfo, |
5642 | const CXXScopeSpec *SS = nullptr, |
5643 | NamedDecl *FoundD = nullptr, |
5644 | SourceLocation TemplateKWLoc = SourceLocation(), |
5645 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
5646 | DeclRefExpr * |
5647 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
5648 | const DeclarationNameInfo &NameInfo, |
5649 | NestedNameSpecifierLoc NNS, |
5650 | NamedDecl *FoundD = nullptr, |
5651 | SourceLocation TemplateKWLoc = SourceLocation(), |
5652 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
5653 | |
5654 | ExprResult |
5655 | BuildAnonymousStructUnionMemberReference( |
5656 | const CXXScopeSpec &SS, |
5657 | SourceLocation nameLoc, |
5658 | IndirectFieldDecl *indirectField, |
5659 | DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_none), |
5660 | Expr *baseObjectExpr = nullptr, |
5661 | SourceLocation opLoc = SourceLocation()); |
5662 | |
5663 | ExprResult BuildPossibleImplicitMemberExpr( |
5664 | const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, |
5665 | const TemplateArgumentListInfo *TemplateArgs, const Scope *S, |
5666 | UnresolvedLookupExpr *AsULE = nullptr); |
5667 | ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, |
5668 | SourceLocation TemplateKWLoc, |
5669 | LookupResult &R, |
5670 | const TemplateArgumentListInfo *TemplateArgs, |
5671 | bool IsDefiniteInstance, |
5672 | const Scope *S); |
5673 | bool UseArgumentDependentLookup(const CXXScopeSpec &SS, |
5674 | const LookupResult &R, |
5675 | bool HasTrailingLParen); |
5676 | |
5677 | ExprResult |
5678 | BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, |
5679 | const DeclarationNameInfo &NameInfo, |
5680 | bool IsAddressOfOperand, const Scope *S, |
5681 | TypeSourceInfo **RecoveryTSI = nullptr); |
5682 | |
5683 | ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS, |
5684 | SourceLocation TemplateKWLoc, |
5685 | const DeclarationNameInfo &NameInfo, |
5686 | const TemplateArgumentListInfo *TemplateArgs); |
5687 | |
5688 | ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, |
5689 | LookupResult &R, |
5690 | bool NeedsADL, |
5691 | bool AcceptInvalidDecl = false); |
5692 | ExprResult BuildDeclarationNameExpr( |
5693 | const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D, |
5694 | NamedDecl *FoundD = nullptr, |
5695 | const TemplateArgumentListInfo *TemplateArgs = nullptr, |
5696 | bool AcceptInvalidDecl = false); |
5697 | |
5698 | ExprResult BuildLiteralOperatorCall(LookupResult &R, |
5699 | DeclarationNameInfo &SuffixInfo, |
5700 | ArrayRef<Expr *> Args, |
5701 | SourceLocation LitEndLoc, |
5702 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
5703 | |
5704 | ExprResult BuildPredefinedExpr(SourceLocation Loc, |
5705 | PredefinedExpr::IdentKind IK); |
5706 | ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); |
5707 | ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val); |
5708 | |
5709 | ExprResult BuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, |
5710 | SourceLocation LParen, |
5711 | SourceLocation RParen, |
5712 | TypeSourceInfo *TSI); |
5713 | ExprResult ActOnSYCLUniqueStableNameExpr(SourceLocation OpLoc, |
5714 | SourceLocation LParen, |
5715 | SourceLocation RParen, |
5716 | ParsedType ParsedTy); |
5717 | |
5718 | bool CheckLoopHintExpr(Expr *E, SourceLocation Loc); |
5719 | |
5720 | ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr); |
5721 | ExprResult ActOnCharacterConstant(const Token &Tok, |
5722 | Scope *UDLScope = nullptr); |
5723 | ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E); |
5724 | ExprResult ActOnParenListExpr(SourceLocation L, |
5725 | SourceLocation R, |
5726 | MultiExprArg Val); |
5727 | |
5728 | /// ActOnStringLiteral - The specified tokens were lexed as pasted string |
5729 | /// fragments (e.g. "foo" "bar" L"baz"). |
5730 | ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks, |
5731 | Scope *UDLScope = nullptr); |
5732 | |
5733 | ExprResult ActOnUnevaluatedStringLiteral(ArrayRef<Token> StringToks); |
5734 | |
5735 | /// ControllingExprOrType is either an opaque pointer coming out of a |
5736 | /// ParsedType or an Expr *. FIXME: it'd be better to split this interface |
5737 | /// into two so we don't take a void *, but that's awkward because one of |
5738 | /// the operands is either a ParsedType or an Expr *, which doesn't lend |
5739 | /// itself to generic code very well. |
5740 | ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, |
5741 | SourceLocation DefaultLoc, |
5742 | SourceLocation RParenLoc, |
5743 | bool PredicateIsExpr, |
5744 | void *ControllingExprOrType, |
5745 | ArrayRef<ParsedType> ArgTypes, |
5746 | ArrayRef<Expr *> ArgExprs); |
5747 | /// ControllingExprOrType is either a TypeSourceInfo * or an Expr *. FIXME: |
5748 | /// it'd be better to split this interface into two so we don't take a |
5749 | /// void *, but see the FIXME on ActOnGenericSelectionExpr as to why that |
5750 | /// isn't a trivial change. |
5751 | ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, |
5752 | SourceLocation DefaultLoc, |
5753 | SourceLocation RParenLoc, |
5754 | bool PredicateIsExpr, |
5755 | void *ControllingExprOrType, |
5756 | ArrayRef<TypeSourceInfo *> Types, |
5757 | ArrayRef<Expr *> Exprs); |
5758 | |
5759 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
5760 | ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, |
5761 | Expr *InputExpr, bool IsAfterAmp = false); |
5762 | ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, |
5763 | Expr *Input, bool IsAfterAmp = false); |
5764 | ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Op, |
5765 | Expr *Input, bool IsAfterAmp = false); |
5766 | |
5767 | bool isQualifiedMemberAccess(Expr *E); |
5768 | QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc); |
5769 | |
5770 | bool CheckTypeTraitArity(unsigned Arity, SourceLocation Loc, size_t N); |
5771 | |
5772 | bool ActOnAlignasTypeArgument(StringRef KWName, ParsedType Ty, |
5773 | SourceLocation OpLoc, SourceRange R); |
5774 | bool CheckAlignasTypeArgument(StringRef KWName, TypeSourceInfo *TInfo, |
5775 | SourceLocation OpLoc, SourceRange R); |
5776 | |
5777 | ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, |
5778 | SourceLocation OpLoc, |
5779 | UnaryExprOrTypeTrait ExprKind, |
5780 | SourceRange R); |
5781 | ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, |
5782 | UnaryExprOrTypeTrait ExprKind); |
5783 | ExprResult |
5784 | ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, |
5785 | UnaryExprOrTypeTrait ExprKind, |
5786 | bool IsType, void *TyOrEx, |
5787 | SourceRange ArgRange); |
5788 | |
5789 | ExprResult CheckPlaceholderExpr(Expr *E); |
5790 | bool CheckVecStepExpr(Expr *E); |
5791 | |
5792 | bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind); |
5793 | bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc, |
5794 | SourceRange ExprRange, |
5795 | UnaryExprOrTypeTrait ExprKind, |
5796 | StringRef KWName); |
5797 | ExprResult ActOnSizeofParameterPackExpr(Scope *S, |
5798 | SourceLocation OpLoc, |
5799 | IdentifierInfo &Name, |
5800 | SourceLocation NameLoc, |
5801 | SourceLocation RParenLoc); |
5802 | ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, |
5803 | tok::TokenKind Kind, Expr *Input); |
5804 | |
5805 | ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, |
5806 | MultiExprArg ArgExprs, |
5807 | SourceLocation RLoc); |
5808 | ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, |
5809 | Expr *Idx, SourceLocation RLoc); |
5810 | |
5811 | ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, |
5812 | Expr *ColumnIdx, |
5813 | SourceLocation RBLoc); |
5814 | |
5815 | ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, |
5816 | Expr *LowerBound, |
5817 | SourceLocation ColonLocFirst, |
5818 | SourceLocation ColonLocSecond, |
5819 | Expr *Length, Expr *Stride, |
5820 | SourceLocation RBLoc); |
5821 | ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, |
5822 | SourceLocation RParenLoc, |
5823 | ArrayRef<Expr *> Dims, |
5824 | ArrayRef<SourceRange> Brackets); |
5825 | |
5826 | /// Data structure for iterator expression. |
5827 | struct OMPIteratorData { |
5828 | IdentifierInfo *DeclIdent = nullptr; |
5829 | SourceLocation DeclIdentLoc; |
5830 | ParsedType Type; |
5831 | OMPIteratorExpr::IteratorRange Range; |
5832 | SourceLocation AssignLoc; |
5833 | SourceLocation ColonLoc; |
5834 | SourceLocation SecColonLoc; |
5835 | }; |
5836 | |
5837 | ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc, |
5838 | SourceLocation LLoc, SourceLocation RLoc, |
5839 | ArrayRef<OMPIteratorData> Data); |
5840 | |
5841 | // This struct is for use by ActOnMemberAccess to allow |
5842 | // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after |
5843 | // changing the access operator from a '.' to a '->' (to see if that is the |
5844 | // change needed to fix an error about an unknown member, e.g. when the class |
5845 | // defines a custom operator->). |
5846 | struct { |
5847 | Scope *; |
5848 | UnqualifiedId &; |
5849 | Decl *; |
5850 | }; |
5851 | |
5852 | ExprResult BuildMemberReferenceExpr( |
5853 | Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, |
5854 | CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
5855 | NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, |
5856 | const TemplateArgumentListInfo *TemplateArgs, |
5857 | const Scope *S, |
5858 | ActOnMemberAccessExtraArgs * = nullptr); |
5859 | |
5860 | ExprResult |
5861 | BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, |
5862 | bool IsArrow, const CXXScopeSpec &SS, |
5863 | SourceLocation TemplateKWLoc, |
5864 | NamedDecl *FirstQualifierInScope, LookupResult &R, |
5865 | const TemplateArgumentListInfo *TemplateArgs, |
5866 | const Scope *S, |
5867 | bool SuppressQualifierCheck = false, |
5868 | ActOnMemberAccessExtraArgs * = nullptr); |
5869 | |
5870 | ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, |
5871 | SourceLocation OpLoc, |
5872 | const CXXScopeSpec &SS, FieldDecl *Field, |
5873 | DeclAccessPair FoundDecl, |
5874 | const DeclarationNameInfo &MemberNameInfo); |
5875 | |
5876 | ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow); |
5877 | |
5878 | bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, |
5879 | const CXXScopeSpec &SS, |
5880 | const LookupResult &R); |
5881 | |
5882 | ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, |
5883 | bool IsArrow, SourceLocation OpLoc, |
5884 | const CXXScopeSpec &SS, |
5885 | SourceLocation TemplateKWLoc, |
5886 | NamedDecl *FirstQualifierInScope, |
5887 | const DeclarationNameInfo &NameInfo, |
5888 | const TemplateArgumentListInfo *TemplateArgs); |
5889 | |
5890 | ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, |
5891 | SourceLocation OpLoc, |
5892 | tok::TokenKind OpKind, |
5893 | CXXScopeSpec &SS, |
5894 | SourceLocation TemplateKWLoc, |
5895 | UnqualifiedId &Member, |
5896 | Decl *ObjCImpDecl); |
5897 | |
5898 | MemberExpr * |
5899 | BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc, |
5900 | const CXXScopeSpec *SS, SourceLocation TemplateKWLoc, |
5901 | ValueDecl *Member, DeclAccessPair FoundDecl, |
5902 | bool HadMultipleCandidates, |
5903 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, |
5904 | ExprValueKind VK, ExprObjectKind OK, |
5905 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
5906 | MemberExpr * |
5907 | BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc, |
5908 | NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, |
5909 | ValueDecl *Member, DeclAccessPair FoundDecl, |
5910 | bool HadMultipleCandidates, |
5911 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, |
5912 | ExprValueKind VK, ExprObjectKind OK, |
5913 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
5914 | |
5915 | void ActOnDefaultCtorInitializers(Decl *CDtorDecl); |
5916 | bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, |
5917 | FunctionDecl *FDecl, |
5918 | const FunctionProtoType *Proto, |
5919 | ArrayRef<Expr *> Args, |
5920 | SourceLocation RParenLoc, |
5921 | bool ExecConfig = false); |
5922 | void CheckStaticArrayArgument(SourceLocation CallLoc, |
5923 | ParmVarDecl *Param, |
5924 | const Expr *ArgExpr); |
5925 | |
5926 | /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. |
5927 | /// This provides the location of the left/right parens and a list of comma |
5928 | /// locations. |
5929 | ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
5930 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
5931 | Expr *ExecConfig = nullptr); |
5932 | ExprResult BuildCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
5933 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
5934 | Expr *ExecConfig = nullptr, |
5935 | bool IsExecConfig = false, |
5936 | bool AllowRecovery = false); |
5937 | Expr *BuildBuiltinCallExpr(SourceLocation Loc, Builtin::ID Id, |
5938 | MultiExprArg CallArgs); |
5939 | enum class AtomicArgumentOrder { API, AST }; |
5940 | ExprResult |
5941 | BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, |
5942 | SourceLocation RParenLoc, MultiExprArg Args, |
5943 | AtomicExpr::AtomicOp Op, |
5944 | AtomicArgumentOrder ArgOrder = AtomicArgumentOrder::API); |
5945 | ExprResult |
5946 | BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, SourceLocation LParenLoc, |
5947 | ArrayRef<Expr *> Arg, SourceLocation RParenLoc, |
5948 | Expr *Config = nullptr, bool IsExecConfig = false, |
5949 | ADLCallKind UsesADL = ADLCallKind::NotADL); |
5950 | |
5951 | ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, |
5952 | MultiExprArg ExecConfig, |
5953 | SourceLocation GGGLoc); |
5954 | |
5955 | ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, |
5956 | Declarator &D, ParsedType &Ty, |
5957 | SourceLocation RParenLoc, Expr *CastExpr); |
5958 | ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, |
5959 | TypeSourceInfo *Ty, |
5960 | SourceLocation RParenLoc, |
5961 | Expr *Op); |
5962 | CastKind PrepareScalarCast(ExprResult &src, QualType destType); |
5963 | |
5964 | /// Build an altivec or OpenCL literal. |
5965 | ExprResult BuildVectorLiteral(SourceLocation LParenLoc, |
5966 | SourceLocation RParenLoc, Expr *E, |
5967 | TypeSourceInfo *TInfo); |
5968 | |
5969 | ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); |
5970 | |
5971 | ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, |
5972 | ParsedType Ty, |
5973 | SourceLocation RParenLoc, |
5974 | Expr *InitExpr); |
5975 | |
5976 | ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, |
5977 | TypeSourceInfo *TInfo, |
5978 | SourceLocation RParenLoc, |
5979 | Expr *LiteralExpr); |
5980 | |
5981 | ExprResult ActOnInitList(SourceLocation LBraceLoc, |
5982 | MultiExprArg InitArgList, |
5983 | SourceLocation RBraceLoc); |
5984 | |
5985 | ExprResult BuildInitList(SourceLocation LBraceLoc, |
5986 | MultiExprArg InitArgList, |
5987 | SourceLocation RBraceLoc); |
5988 | |
5989 | ExprResult ActOnDesignatedInitializer(Designation &Desig, |
5990 | SourceLocation EqualOrColonLoc, |
5991 | bool GNUSyntax, |
5992 | ExprResult Init); |
5993 | |
5994 | private: |
5995 | static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind); |
5996 | |
5997 | public: |
5998 | ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, |
5999 | tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr); |
6000 | ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, |
6001 | BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr); |
6002 | ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, |
6003 | Expr *LHSExpr, Expr *RHSExpr); |
6004 | void LookupBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, |
6005 | UnresolvedSetImpl &Functions); |
6006 | |
6007 | void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc); |
6008 | |
6009 | /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
6010 | /// in the case of a the GNU conditional expr extension. |
6011 | ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, |
6012 | SourceLocation ColonLoc, |
6013 | Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr); |
6014 | |
6015 | /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". |
6016 | ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, |
6017 | LabelDecl *TheDecl); |
6018 | |
6019 | void ActOnStartStmtExpr(); |
6020 | ExprResult ActOnStmtExpr(Scope *S, SourceLocation LPLoc, Stmt *SubStmt, |
6021 | SourceLocation RPLoc); |
6022 | ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, |
6023 | SourceLocation RPLoc, unsigned TemplateDepth); |
6024 | // Handle the final expression in a statement expression. |
6025 | ExprResult ActOnStmtExprResult(ExprResult E); |
6026 | void ActOnStmtExprError(); |
6027 | |
6028 | // __builtin_offsetof(type, identifier(.identifier|[expr])*) |
6029 | struct OffsetOfComponent { |
6030 | SourceLocation LocStart, LocEnd; |
6031 | bool isBrackets; // true if [expr], false if .ident |
6032 | union { |
6033 | IdentifierInfo *IdentInfo; |
6034 | Expr *E; |
6035 | } U; |
6036 | }; |
6037 | |
6038 | /// __builtin_offsetof(type, a.b[123][456].c) |
6039 | ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, |
6040 | TypeSourceInfo *TInfo, |
6041 | ArrayRef<OffsetOfComponent> Components, |
6042 | SourceLocation RParenLoc); |
6043 | ExprResult ActOnBuiltinOffsetOf(Scope *S, |
6044 | SourceLocation BuiltinLoc, |
6045 | SourceLocation TypeLoc, |
6046 | ParsedType ParsedArgTy, |
6047 | ArrayRef<OffsetOfComponent> Components, |
6048 | SourceLocation RParenLoc); |
6049 | |
6050 | // __builtin_choose_expr(constExpr, expr1, expr2) |
6051 | ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, |
6052 | Expr *CondExpr, Expr *LHSExpr, |
6053 | Expr *RHSExpr, SourceLocation RPLoc); |
6054 | |
6055 | // __builtin_va_arg(expr, type) |
6056 | ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, |
6057 | SourceLocation RPLoc); |
6058 | ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, |
6059 | TypeSourceInfo *TInfo, SourceLocation RPLoc); |
6060 | |
6061 | // __builtin_LINE(), __builtin_FUNCTION(), __builtin_FUNCSIG(), |
6062 | // __builtin_FILE(), __builtin_COLUMN(), __builtin_source_location() |
6063 | ExprResult ActOnSourceLocExpr(SourceLocExpr::IdentKind Kind, |
6064 | SourceLocation BuiltinLoc, |
6065 | SourceLocation RPLoc); |
6066 | |
6067 | // Build a potentially resolved SourceLocExpr. |
6068 | ExprResult BuildSourceLocExpr(SourceLocExpr::IdentKind Kind, |
6069 | QualType ResultTy, SourceLocation BuiltinLoc, |
6070 | SourceLocation RPLoc, |
6071 | DeclContext *ParentContext); |
6072 | |
6073 | // __null |
6074 | ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); |
6075 | |
6076 | bool CheckCaseExpression(Expr *E); |
6077 | |
6078 | /// Describes the result of an "if-exists" condition check. |
6079 | enum IfExistsResult { |
6080 | /// The symbol exists. |
6081 | IER_Exists, |
6082 | |
6083 | /// The symbol does not exist. |
6084 | IER_DoesNotExist, |
6085 | |
6086 | /// The name is a dependent name, so the results will differ |
6087 | /// from one instantiation to the next. |
6088 | IER_Dependent, |
6089 | |
6090 | /// An error occurred. |
6091 | IER_Error |
6092 | }; |
6093 | |
6094 | IfExistsResult |
6095 | CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, |
6096 | const DeclarationNameInfo &TargetNameInfo); |
6097 | |
6098 | IfExistsResult |
6099 | CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc, |
6100 | bool IsIfExists, CXXScopeSpec &SS, |
6101 | UnqualifiedId &Name); |
6102 | |
6103 | StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
6104 | bool IsIfExists, |
6105 | NestedNameSpecifierLoc QualifierLoc, |
6106 | DeclarationNameInfo NameInfo, |
6107 | Stmt *Nested); |
6108 | StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, |
6109 | bool IsIfExists, |
6110 | CXXScopeSpec &SS, UnqualifiedId &Name, |
6111 | Stmt *Nested); |
6112 | |
6113 | //===------------------------- "Block" Extension ------------------------===// |
6114 | |
6115 | /// ActOnBlockStart - This callback is invoked when a block literal is |
6116 | /// started. |
6117 | void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); |
6118 | |
6119 | /// ActOnBlockArguments - This callback allows processing of block arguments. |
6120 | /// If there are no arguments, this is still invoked. |
6121 | void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, |
6122 | Scope *CurScope); |
6123 | |
6124 | /// ActOnBlockError - If there is an error parsing a block, this callback |
6125 | /// is invoked to pop the information about the block from the action impl. |
6126 | void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); |
6127 | |
6128 | /// ActOnBlockStmtExpr - This is called when the body of a block statement |
6129 | /// literal was successfully completed. ^(int x){...} |
6130 | ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, |
6131 | Scope *CurScope); |
6132 | |
6133 | //===---------------------------- Clang Extensions ----------------------===// |
6134 | |
6135 | /// __builtin_convertvector(...) |
6136 | ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy, |
6137 | SourceLocation BuiltinLoc, |
6138 | SourceLocation RParenLoc); |
6139 | |
6140 | //===---------------------------- OpenCL Features -----------------------===// |
6141 | |
6142 | /// __builtin_astype(...) |
6143 | ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, |
6144 | SourceLocation BuiltinLoc, |
6145 | SourceLocation RParenLoc); |
6146 | ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy, |
6147 | SourceLocation BuiltinLoc, |
6148 | SourceLocation RParenLoc); |
6149 | |
6150 | //===---------------------------- HLSL Features -------------------------===// |
6151 | Decl *ActOnStartHLSLBuffer(Scope *BufferScope, bool CBuffer, |
6152 | SourceLocation KwLoc, IdentifierInfo *Ident, |
6153 | SourceLocation IdentLoc, SourceLocation LBrace); |
6154 | void ActOnFinishHLSLBuffer(Decl *Dcl, SourceLocation RBrace); |
6155 | |
6156 | //===---------------------------- C++ Features --------------------------===// |
6157 | |
6158 | // Act on C++ namespaces |
6159 | Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, |
6160 | SourceLocation NamespaceLoc, |
6161 | SourceLocation IdentLoc, IdentifierInfo *Ident, |
6162 | SourceLocation LBrace, |
6163 | const ParsedAttributesView &AttrList, |
6164 | UsingDirectiveDecl *&UsingDecl, bool IsNested); |
6165 | void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); |
6166 | |
6167 | NamespaceDecl *getStdNamespace() const; |
6168 | NamespaceDecl *getOrCreateStdNamespace(); |
6169 | |
6170 | CXXRecordDecl *getStdBadAlloc() const; |
6171 | EnumDecl *getStdAlignValT() const; |
6172 | |
6173 | private: |
6174 | // A cache representing if we've fully checked the various comparison category |
6175 | // types stored in ASTContext. The bit-index corresponds to the integer value |
6176 | // of a ComparisonCategoryType enumerator. |
6177 | llvm::SmallBitVector FullyCheckedComparisonCategories; |
6178 | |
6179 | ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl, |
6180 | CXXScopeSpec &SS, |
6181 | ParsedType TemplateTypeTy, |
6182 | IdentifierInfo *MemberOrBase); |
6183 | |
6184 | public: |
6185 | enum class ComparisonCategoryUsage { |
6186 | /// The '<=>' operator was used in an expression and a builtin operator |
6187 | /// was selected. |
6188 | OperatorInExpression, |
6189 | /// A defaulted 'operator<=>' needed the comparison category. This |
6190 | /// typically only applies to 'std::strong_ordering', due to the implicit |
6191 | /// fallback return value. |
6192 | DefaultedOperator, |
6193 | }; |
6194 | |
6195 | /// Lookup the specified comparison category types in the standard |
6196 | /// library, an check the VarDecls possibly returned by the operator<=> |
6197 | /// builtins for that type. |
6198 | /// |
6199 | /// \return The type of the comparison category type corresponding to the |
6200 | /// specified Kind, or a null type if an error occurs |
6201 | QualType CheckComparisonCategoryType(ComparisonCategoryType Kind, |
6202 | SourceLocation Loc, |
6203 | ComparisonCategoryUsage Usage); |
6204 | |
6205 | /// Tests whether Ty is an instance of std::initializer_list and, if |
6206 | /// it is and Element is not NULL, assigns the element type to Element. |
6207 | bool isStdInitializerList(QualType Ty, QualType *Element); |
6208 | |
6209 | /// Looks for the std::initializer_list template and instantiates it |
6210 | /// with Element, or emits an error if it's not found. |
6211 | /// |
6212 | /// \returns The instantiated template, or null on error. |
6213 | QualType BuildStdInitializerList(QualType Element, SourceLocation Loc); |
6214 | |
6215 | /// Determine whether Ctor is an initializer-list constructor, as |
6216 | /// defined in [dcl.init.list]p2. |
6217 | bool isInitListConstructor(const FunctionDecl *Ctor); |
6218 | |
6219 | Decl *ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc, |
6220 | SourceLocation NamespcLoc, CXXScopeSpec &SS, |
6221 | SourceLocation IdentLoc, |
6222 | IdentifierInfo *NamespcName, |
6223 | const ParsedAttributesView &AttrList); |
6224 | |
6225 | void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); |
6226 | |
6227 | Decl *ActOnNamespaceAliasDef(Scope *CurScope, |
6228 | SourceLocation NamespaceLoc, |
6229 | SourceLocation AliasLoc, |
6230 | IdentifierInfo *Alias, |
6231 | CXXScopeSpec &SS, |
6232 | SourceLocation IdentLoc, |
6233 | IdentifierInfo *Ident); |
6234 | |
6235 | void FilterUsingLookup(Scope *S, LookupResult &lookup); |
6236 | void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); |
6237 | bool CheckUsingShadowDecl(BaseUsingDecl *BUD, NamedDecl *Target, |
6238 | const LookupResult &PreviousDecls, |
6239 | UsingShadowDecl *&PrevShadow); |
6240 | UsingShadowDecl *BuildUsingShadowDecl(Scope *S, BaseUsingDecl *BUD, |
6241 | NamedDecl *Target, |
6242 | UsingShadowDecl *PrevDecl); |
6243 | |
6244 | bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, |
6245 | bool HasTypenameKeyword, |
6246 | const CXXScopeSpec &SS, |
6247 | SourceLocation NameLoc, |
6248 | const LookupResult &Previous); |
6249 | bool CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename, |
6250 | const CXXScopeSpec &SS, |
6251 | const DeclarationNameInfo &NameInfo, |
6252 | SourceLocation NameLoc, |
6253 | const LookupResult *R = nullptr, |
6254 | const UsingDecl *UD = nullptr); |
6255 | |
6256 | NamedDecl *BuildUsingDeclaration( |
6257 | Scope *S, AccessSpecifier AS, SourceLocation UsingLoc, |
6258 | bool HasTypenameKeyword, SourceLocation TypenameLoc, CXXScopeSpec &SS, |
6259 | DeclarationNameInfo NameInfo, SourceLocation EllipsisLoc, |
6260 | const ParsedAttributesView &AttrList, bool IsInstantiation, |
6261 | bool IsUsingIfExists); |
6262 | NamedDecl *BuildUsingEnumDeclaration(Scope *S, AccessSpecifier AS, |
6263 | SourceLocation UsingLoc, |
6264 | SourceLocation EnumLoc, |
6265 | SourceLocation NameLoc, |
6266 | TypeSourceInfo *EnumType, EnumDecl *ED); |
6267 | NamedDecl *BuildUsingPackDecl(NamedDecl *InstantiatedFrom, |
6268 | ArrayRef<NamedDecl *> Expansions); |
6269 | |
6270 | bool CheckInheritingConstructorUsingDecl(UsingDecl *UD); |
6271 | |
6272 | /// Given a derived-class using shadow declaration for a constructor and the |
6273 | /// correspnding base class constructor, find or create the implicit |
6274 | /// synthesized derived class constructor to use for this initialization. |
6275 | CXXConstructorDecl * |
6276 | findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor, |
6277 | ConstructorUsingShadowDecl *DerivedShadow); |
6278 | |
6279 | Decl *ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS, |
6280 | SourceLocation UsingLoc, |
6281 | SourceLocation TypenameLoc, CXXScopeSpec &SS, |
6282 | UnqualifiedId &Name, SourceLocation EllipsisLoc, |
6283 | const ParsedAttributesView &AttrList); |
6284 | Decl *ActOnUsingEnumDeclaration(Scope *CurScope, AccessSpecifier AS, |
6285 | SourceLocation UsingLoc, |
6286 | SourceLocation EnumLoc, |
6287 | SourceLocation IdentLoc, IdentifierInfo &II, |
6288 | CXXScopeSpec *SS = nullptr); |
6289 | Decl *ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS, |
6290 | MultiTemplateParamsArg TemplateParams, |
6291 | SourceLocation UsingLoc, UnqualifiedId &Name, |
6292 | const ParsedAttributesView &AttrList, |
6293 | TypeResult Type, Decl *DeclFromDeclSpec); |
6294 | |
6295 | /// BuildCXXConstructExpr - Creates a complete call to a constructor, |
6296 | /// including handling of its default argument expressions. |
6297 | /// |
6298 | /// \param ConstructKind - a CXXConstructExpr::ConstructionKind |
6299 | ExprResult |
6300 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
6301 | NamedDecl *FoundDecl, |
6302 | CXXConstructorDecl *Constructor, MultiExprArg Exprs, |
6303 | bool HadMultipleCandidates, bool IsListInitialization, |
6304 | bool IsStdInitListInitialization, |
6305 | bool RequiresZeroInit, unsigned ConstructKind, |
6306 | SourceRange ParenRange); |
6307 | |
6308 | /// Build a CXXConstructExpr whose constructor has already been resolved if |
6309 | /// it denotes an inherited constructor. |
6310 | ExprResult |
6311 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
6312 | CXXConstructorDecl *Constructor, bool Elidable, |
6313 | MultiExprArg Exprs, |
6314 | bool HadMultipleCandidates, bool IsListInitialization, |
6315 | bool IsStdInitListInitialization, |
6316 | bool RequiresZeroInit, unsigned ConstructKind, |
6317 | SourceRange ParenRange); |
6318 | |
6319 | // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if |
6320 | // the constructor can be elidable? |
6321 | ExprResult |
6322 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
6323 | NamedDecl *FoundDecl, |
6324 | CXXConstructorDecl *Constructor, bool Elidable, |
6325 | MultiExprArg Exprs, bool HadMultipleCandidates, |
6326 | bool IsListInitialization, |
6327 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
6328 | unsigned ConstructKind, SourceRange ParenRange); |
6329 | |
6330 | ExprResult ConvertMemberDefaultInitExpression(FieldDecl *FD, Expr *InitExpr, |
6331 | SourceLocation InitLoc); |
6332 | |
6333 | ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field); |
6334 | |
6335 | |
6336 | /// Instantiate or parse a C++ default argument expression as necessary. |
6337 | /// Return true on error. |
6338 | bool CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
6339 | ParmVarDecl *Param, Expr *Init = nullptr, |
6340 | bool SkipImmediateInvocations = true); |
6341 | |
6342 | /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating |
6343 | /// the default expr if needed. |
6344 | ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
6345 | ParmVarDecl *Param, Expr *Init = nullptr); |
6346 | |
6347 | /// FinalizeVarWithDestructor - Prepare for calling destructor on the |
6348 | /// constructed variable. |
6349 | void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); |
6350 | |
6351 | /// Helper class that collects exception specifications for |
6352 | /// implicitly-declared special member functions. |
6353 | class ImplicitExceptionSpecification { |
6354 | // Pointer to allow copying |
6355 | Sema *Self; |
6356 | // We order exception specifications thus: |
6357 | // noexcept is the most restrictive, but is only used in C++11. |
6358 | // throw() comes next. |
6359 | // Then a throw(collected exceptions) |
6360 | // Finally no specification, which is expressed as noexcept(false). |
6361 | // throw(...) is used instead if any called function uses it. |
6362 | ExceptionSpecificationType ComputedEST; |
6363 | llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; |
6364 | SmallVector<QualType, 4> Exceptions; |
6365 | |
6366 | void ClearExceptions() { |
6367 | ExceptionsSeen.clear(); |
6368 | Exceptions.clear(); |
6369 | } |
6370 | |
6371 | public: |
6372 | explicit ImplicitExceptionSpecification(Sema &Self) |
6373 | : Self(&Self), ComputedEST(EST_BasicNoexcept) { |
6374 | if (!Self.getLangOpts().CPlusPlus11) |
6375 | ComputedEST = EST_DynamicNone; |
6376 | } |
6377 | |
6378 | /// Get the computed exception specification type. |
6379 | ExceptionSpecificationType getExceptionSpecType() const { |
6380 | assert(!isComputedNoexcept(ComputedEST) && |
6381 | "noexcept(expr) should not be a possible result" ); |
6382 | return ComputedEST; |
6383 | } |
6384 | |
6385 | /// The number of exceptions in the exception specification. |
6386 | unsigned size() const { return Exceptions.size(); } |
6387 | |
6388 | /// The set of exceptions in the exception specification. |
6389 | const QualType *data() const { return Exceptions.data(); } |
6390 | |
6391 | /// Integrate another called method into the collected data. |
6392 | void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method); |
6393 | |
6394 | /// Integrate an invoked expression into the collected data. |
6395 | void CalledExpr(Expr *E) { CalledStmt(E); } |
6396 | |
6397 | /// Integrate an invoked statement into the collected data. |
6398 | void CalledStmt(Stmt *S); |
6399 | |
6400 | /// Overwrite an EPI's exception specification with this |
6401 | /// computed exception specification. |
6402 | FunctionProtoType::ExceptionSpecInfo getExceptionSpec() const { |
6403 | FunctionProtoType::ExceptionSpecInfo ESI; |
6404 | ESI.Type = getExceptionSpecType(); |
6405 | if (ESI.Type == EST_Dynamic) { |
6406 | ESI.Exceptions = Exceptions; |
6407 | } else if (ESI.Type == EST_None) { |
6408 | /// C++11 [except.spec]p14: |
6409 | /// The exception-specification is noexcept(false) if the set of |
6410 | /// potential exceptions of the special member function contains "any" |
6411 | ESI.Type = EST_NoexceptFalse; |
6412 | ESI.NoexceptExpr = Self->ActOnCXXBoolLiteral(SourceLocation(), |
6413 | tok::kw_false).get(); |
6414 | } |
6415 | return ESI; |
6416 | } |
6417 | }; |
6418 | |
6419 | /// Evaluate the implicit exception specification for a defaulted |
6420 | /// special member function. |
6421 | void EvaluateImplicitExceptionSpec(SourceLocation Loc, FunctionDecl *FD); |
6422 | |
6423 | /// Check the given noexcept-specifier, convert its expression, and compute |
6424 | /// the appropriate ExceptionSpecificationType. |
6425 | ExprResult ActOnNoexceptSpec(Expr *NoexceptExpr, |
6426 | ExceptionSpecificationType &EST); |
6427 | |
6428 | /// Check the given exception-specification and update the |
6429 | /// exception specification information with the results. |
6430 | void checkExceptionSpecification(bool IsTopLevel, |
6431 | ExceptionSpecificationType EST, |
6432 | ArrayRef<ParsedType> DynamicExceptions, |
6433 | ArrayRef<SourceRange> DynamicExceptionRanges, |
6434 | Expr *NoexceptExpr, |
6435 | SmallVectorImpl<QualType> &Exceptions, |
6436 | FunctionProtoType::ExceptionSpecInfo &ESI); |
6437 | |
6438 | /// Determine if we're in a case where we need to (incorrectly) eagerly |
6439 | /// parse an exception specification to work around a libstdc++ bug. |
6440 | bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D); |
6441 | |
6442 | /// Add an exception-specification to the given member function |
6443 | /// (or member function template). The exception-specification was parsed |
6444 | /// after the method itself was declared. |
6445 | void actOnDelayedExceptionSpecification(Decl *Method, |
6446 | ExceptionSpecificationType EST, |
6447 | SourceRange SpecificationRange, |
6448 | ArrayRef<ParsedType> DynamicExceptions, |
6449 | ArrayRef<SourceRange> DynamicExceptionRanges, |
6450 | Expr *NoexceptExpr); |
6451 | |
6452 | class InheritedConstructorInfo; |
6453 | |
6454 | /// Determine if a special member function should have a deleted |
6455 | /// definition when it is defaulted. |
6456 | bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM, |
6457 | InheritedConstructorInfo *ICI = nullptr, |
6458 | bool Diagnose = false); |
6459 | |
6460 | /// Produce notes explaining why a defaulted function was defined as deleted. |
6461 | void DiagnoseDeletedDefaultedFunction(FunctionDecl *FD); |
6462 | |
6463 | /// Declare the implicit default constructor for the given class. |
6464 | /// |
6465 | /// \param ClassDecl The class declaration into which the implicit |
6466 | /// default constructor will be added. |
6467 | /// |
6468 | /// \returns The implicitly-declared default constructor. |
6469 | CXXConstructorDecl *DeclareImplicitDefaultConstructor( |
6470 | CXXRecordDecl *ClassDecl); |
6471 | |
6472 | /// DefineImplicitDefaultConstructor - Checks for feasibility of |
6473 | /// defining this constructor as the default constructor. |
6474 | void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, |
6475 | CXXConstructorDecl *Constructor); |
6476 | |
6477 | /// Declare the implicit destructor for the given class. |
6478 | /// |
6479 | /// \param ClassDecl The class declaration into which the implicit |
6480 | /// destructor will be added. |
6481 | /// |
6482 | /// \returns The implicitly-declared destructor. |
6483 | CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); |
6484 | |
6485 | /// DefineImplicitDestructor - Checks for feasibility of |
6486 | /// defining this destructor as the default destructor. |
6487 | void DefineImplicitDestructor(SourceLocation CurrentLocation, |
6488 | CXXDestructorDecl *Destructor); |
6489 | |
6490 | /// Build an exception spec for destructors that don't have one. |
6491 | /// |
6492 | /// C++11 says that user-defined destructors with no exception spec get one |
6493 | /// that looks as if the destructor was implicitly declared. |
6494 | void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor); |
6495 | |
6496 | /// Define the specified inheriting constructor. |
6497 | void DefineInheritingConstructor(SourceLocation UseLoc, |
6498 | CXXConstructorDecl *Constructor); |
6499 | |
6500 | /// Declare the implicit copy constructor for the given class. |
6501 | /// |
6502 | /// \param ClassDecl The class declaration into which the implicit |
6503 | /// copy constructor will be added. |
6504 | /// |
6505 | /// \returns The implicitly-declared copy constructor. |
6506 | CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); |
6507 | |
6508 | /// DefineImplicitCopyConstructor - Checks for feasibility of |
6509 | /// defining this constructor as the copy constructor. |
6510 | void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, |
6511 | CXXConstructorDecl *Constructor); |
6512 | |
6513 | /// Declare the implicit move constructor for the given class. |
6514 | /// |
6515 | /// \param ClassDecl The Class declaration into which the implicit |
6516 | /// move constructor will be added. |
6517 | /// |
6518 | /// \returns The implicitly-declared move constructor, or NULL if it wasn't |
6519 | /// declared. |
6520 | CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl); |
6521 | |
6522 | /// DefineImplicitMoveConstructor - Checks for feasibility of |
6523 | /// defining this constructor as the move constructor. |
6524 | void DefineImplicitMoveConstructor(SourceLocation CurrentLocation, |
6525 | CXXConstructorDecl *Constructor); |
6526 | |
6527 | /// Declare the implicit copy assignment operator for the given class. |
6528 | /// |
6529 | /// \param ClassDecl The class declaration into which the implicit |
6530 | /// copy assignment operator will be added. |
6531 | /// |
6532 | /// \returns The implicitly-declared copy assignment operator. |
6533 | CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); |
6534 | |
6535 | /// Defines an implicitly-declared copy assignment operator. |
6536 | void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, |
6537 | CXXMethodDecl *MethodDecl); |
6538 | |
6539 | /// Declare the implicit move assignment operator for the given class. |
6540 | /// |
6541 | /// \param ClassDecl The Class declaration into which the implicit |
6542 | /// move assignment operator will be added. |
6543 | /// |
6544 | /// \returns The implicitly-declared move assignment operator, or NULL if it |
6545 | /// wasn't declared. |
6546 | CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl); |
6547 | |
6548 | /// Defines an implicitly-declared move assignment operator. |
6549 | void DefineImplicitMoveAssignment(SourceLocation CurrentLocation, |
6550 | CXXMethodDecl *MethodDecl); |
6551 | |
6552 | /// Force the declaration of any implicitly-declared members of this |
6553 | /// class. |
6554 | void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); |
6555 | |
6556 | /// Check a completed declaration of an implicit special member. |
6557 | void CheckImplicitSpecialMemberDeclaration(Scope *S, FunctionDecl *FD); |
6558 | |
6559 | /// Determine whether the given function is an implicitly-deleted |
6560 | /// special member function. |
6561 | bool isImplicitlyDeleted(FunctionDecl *FD); |
6562 | |
6563 | /// Check whether 'this' shows up in the type of a static member |
6564 | /// function after the (naturally empty) cv-qualifier-seq would be. |
6565 | /// |
6566 | /// \returns true if an error occurred. |
6567 | bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method); |
6568 | |
6569 | /// Whether this' shows up in the exception specification of a static |
6570 | /// member function. |
6571 | bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method); |
6572 | |
6573 | /// Check whether 'this' shows up in the attributes of the given |
6574 | /// static member function. |
6575 | /// |
6576 | /// \returns true if an error occurred. |
6577 | bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method); |
6578 | |
6579 | /// MaybeBindToTemporary - If the passed in expression has a record type with |
6580 | /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise |
6581 | /// it simply returns the passed in expression. |
6582 | ExprResult MaybeBindToTemporary(Expr *E); |
6583 | |
6584 | /// Wrap the expression in a ConstantExpr if it is a potential immediate |
6585 | /// invocation. |
6586 | ExprResult CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl); |
6587 | |
6588 | bool CheckImmediateEscalatingFunctionDefinition( |
6589 | FunctionDecl *FD, const sema::FunctionScopeInfo *FSI); |
6590 | |
6591 | void MarkExpressionAsImmediateEscalating(Expr *E); |
6592 | |
6593 | void DiagnoseImmediateEscalatingReason(FunctionDecl *FD); |
6594 | |
6595 | bool CompleteConstructorCall(CXXConstructorDecl *Constructor, |
6596 | QualType DeclInitType, MultiExprArg ArgsPtr, |
6597 | SourceLocation Loc, |
6598 | SmallVectorImpl<Expr *> &ConvertedArgs, |
6599 | bool AllowExplicit = false, |
6600 | bool IsListInitialization = false); |
6601 | |
6602 | ParsedType getInheritingConstructorName(CXXScopeSpec &SS, |
6603 | SourceLocation NameLoc, |
6604 | IdentifierInfo &Name); |
6605 | |
6606 | ParsedType getConstructorName(IdentifierInfo &II, SourceLocation NameLoc, |
6607 | Scope *S, CXXScopeSpec &SS, |
6608 | bool EnteringContext); |
6609 | ParsedType getDestructorName(SourceLocation TildeLoc, |
6610 | IdentifierInfo &II, SourceLocation NameLoc, |
6611 | Scope *S, CXXScopeSpec &SS, |
6612 | ParsedType ObjectType, |
6613 | bool EnteringContext); |
6614 | |
6615 | ParsedType getDestructorTypeForDecltype(const DeclSpec &DS, |
6616 | ParsedType ObjectType); |
6617 | |
6618 | // Checks that reinterpret casts don't have undefined behavior. |
6619 | void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, |
6620 | bool IsDereference, SourceRange Range); |
6621 | |
6622 | // Checks that the vector type should be initialized from a scalar |
6623 | // by splatting the value rather than populating a single element. |
6624 | // This is the case for AltiVecVector types as well as with |
6625 | // AltiVecPixel and AltiVecBool when -faltivec-src-compat=xl is specified. |
6626 | bool ShouldSplatAltivecScalarInCast(const VectorType *VecTy); |
6627 | |
6628 | // Checks if the -faltivec-src-compat=gcc option is specified. |
6629 | // If so, AltiVecVector, AltiVecBool and AltiVecPixel types are |
6630 | // treated the same way as they are when trying to initialize |
6631 | // these vectors on gcc (an error is emitted). |
6632 | bool CheckAltivecInitFromScalar(SourceRange R, QualType VecTy, |
6633 | QualType SrcTy); |
6634 | |
6635 | /// ActOnCXXNamedCast - Parse |
6636 | /// {dynamic,static,reinterpret,const,addrspace}_cast's. |
6637 | ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, |
6638 | tok::TokenKind Kind, |
6639 | SourceLocation LAngleBracketLoc, |
6640 | Declarator &D, |
6641 | SourceLocation RAngleBracketLoc, |
6642 | SourceLocation LParenLoc, |
6643 | Expr *E, |
6644 | SourceLocation RParenLoc); |
6645 | |
6646 | ExprResult BuildCXXNamedCast(SourceLocation OpLoc, |
6647 | tok::TokenKind Kind, |
6648 | TypeSourceInfo *Ty, |
6649 | Expr *E, |
6650 | SourceRange AngleBrackets, |
6651 | SourceRange Parens); |
6652 | |
6653 | ExprResult ActOnBuiltinBitCastExpr(SourceLocation KWLoc, Declarator &Dcl, |
6654 | ExprResult Operand, |
6655 | SourceLocation RParenLoc); |
6656 | |
6657 | ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, |
6658 | Expr *Operand, SourceLocation RParenLoc); |
6659 | |
6660 | ExprResult BuildCXXTypeId(QualType TypeInfoType, |
6661 | SourceLocation TypeidLoc, |
6662 | TypeSourceInfo *Operand, |
6663 | SourceLocation RParenLoc); |
6664 | ExprResult BuildCXXTypeId(QualType TypeInfoType, |
6665 | SourceLocation TypeidLoc, |
6666 | Expr *Operand, |
6667 | SourceLocation RParenLoc); |
6668 | |
6669 | /// ActOnCXXTypeid - Parse typeid( something ). |
6670 | ExprResult ActOnCXXTypeid(SourceLocation OpLoc, |
6671 | SourceLocation LParenLoc, bool isType, |
6672 | void *TyOrExpr, |
6673 | SourceLocation RParenLoc); |
6674 | |
6675 | ExprResult BuildCXXUuidof(QualType TypeInfoType, |
6676 | SourceLocation TypeidLoc, |
6677 | TypeSourceInfo *Operand, |
6678 | SourceLocation RParenLoc); |
6679 | ExprResult BuildCXXUuidof(QualType TypeInfoType, |
6680 | SourceLocation TypeidLoc, |
6681 | Expr *Operand, |
6682 | SourceLocation RParenLoc); |
6683 | |
6684 | /// ActOnCXXUuidof - Parse __uuidof( something ). |
6685 | ExprResult ActOnCXXUuidof(SourceLocation OpLoc, |
6686 | SourceLocation LParenLoc, bool isType, |
6687 | void *TyOrExpr, |
6688 | SourceLocation RParenLoc); |
6689 | |
6690 | /// Handle a C++1z fold-expression: ( expr op ... op expr ). |
6691 | ExprResult ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS, |
6692 | tok::TokenKind Operator, |
6693 | SourceLocation EllipsisLoc, Expr *RHS, |
6694 | SourceLocation RParenLoc); |
6695 | ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, |
6696 | SourceLocation LParenLoc, Expr *LHS, |
6697 | BinaryOperatorKind Operator, |
6698 | SourceLocation EllipsisLoc, Expr *RHS, |
6699 | SourceLocation RParenLoc, |
6700 | std::optional<unsigned> NumExpansions); |
6701 | ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
6702 | BinaryOperatorKind Operator); |
6703 | |
6704 | //// ActOnCXXThis - Parse 'this' pointer. |
6705 | ExprResult ActOnCXXThis(SourceLocation loc); |
6706 | |
6707 | /// Build a CXXThisExpr and mark it referenced in the current context. |
6708 | Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit); |
6709 | void MarkThisReferenced(CXXThisExpr *This); |
6710 | |
6711 | /// Try to retrieve the type of the 'this' pointer. |
6712 | /// |
6713 | /// \returns The type of 'this', if possible. Otherwise, returns a NULL type. |
6714 | QualType getCurrentThisType(); |
6715 | |
6716 | /// When non-NULL, the C++ 'this' expression is allowed despite the |
6717 | /// current context not being a non-static member function. In such cases, |
6718 | /// this provides the type used for 'this'. |
6719 | QualType CXXThisTypeOverride; |
6720 | |
6721 | /// RAII object used to temporarily allow the C++ 'this' expression |
6722 | /// to be used, with the given qualifiers on the current class type. |
6723 | class CXXThisScopeRAII { |
6724 | Sema &S; |
6725 | QualType OldCXXThisTypeOverride; |
6726 | bool Enabled; |
6727 | |
6728 | public: |
6729 | /// Introduce a new scope where 'this' may be allowed (when enabled), |
6730 | /// using the given declaration (which is either a class template or a |
6731 | /// class) along with the given qualifiers. |
6732 | /// along with the qualifiers placed on '*this'. |
6733 | CXXThisScopeRAII(Sema &S, Decl *ContextDecl, Qualifiers CXXThisTypeQuals, |
6734 | bool Enabled = true); |
6735 | |
6736 | ~CXXThisScopeRAII(); |
6737 | }; |
6738 | |
6739 | /// Make sure the value of 'this' is actually available in the current |
6740 | /// context, if it is a potentially evaluated context. |
6741 | /// |
6742 | /// \param Loc The location at which the capture of 'this' occurs. |
6743 | /// |
6744 | /// \param Explicit Whether 'this' is explicitly captured in a lambda |
6745 | /// capture list. |
6746 | /// |
6747 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
6748 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
6749 | /// This is useful when enclosing lambdas must speculatively capture |
6750 | /// 'this' that may or may not be used in certain specializations of |
6751 | /// a nested generic lambda (depending on whether the name resolves to |
6752 | /// a non-static member function or a static function). |
6753 | /// \return returns 'true' if failed, 'false' if success. |
6754 | bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false, |
6755 | bool BuildAndDiagnose = true, |
6756 | const unsigned *const FunctionScopeIndexToStopAt = nullptr, |
6757 | bool ByCopy = false); |
6758 | |
6759 | /// Determine whether the given type is the type of *this that is used |
6760 | /// outside of the body of a member function for a type that is currently |
6761 | /// being defined. |
6762 | bool isThisOutsideMemberFunctionBody(QualType BaseType); |
6763 | |
6764 | /// ActOnCXXBoolLiteral - Parse {true,false} literals. |
6765 | ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
6766 | |
6767 | |
6768 | /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals. |
6769 | ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
6770 | |
6771 | ExprResult |
6772 | ActOnObjCAvailabilityCheckExpr(llvm::ArrayRef<AvailabilitySpec> AvailSpecs, |
6773 | SourceLocation AtLoc, SourceLocation RParen); |
6774 | |
6775 | /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. |
6776 | ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); |
6777 | |
6778 | //// ActOnCXXThrow - Parse throw expressions. |
6779 | ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); |
6780 | ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, |
6781 | bool IsThrownVarInScope); |
6782 | bool CheckCXXThrowOperand(SourceLocation ThrowLoc, QualType ThrowTy, Expr *E); |
6783 | |
6784 | /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. |
6785 | /// Can be interpreted either as function-style casting ("int(x)") |
6786 | /// or class type construction ("ClassType(x,y,z)") |
6787 | /// or creation of a value-initialized type ("int()"). |
6788 | ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, |
6789 | SourceLocation LParenOrBraceLoc, |
6790 | MultiExprArg Exprs, |
6791 | SourceLocation RParenOrBraceLoc, |
6792 | bool ListInitialization); |
6793 | |
6794 | ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, |
6795 | SourceLocation LParenLoc, |
6796 | MultiExprArg Exprs, |
6797 | SourceLocation RParenLoc, |
6798 | bool ListInitialization); |
6799 | |
6800 | /// ActOnCXXNew - Parsed a C++ 'new' expression. |
6801 | ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, |
6802 | SourceLocation PlacementLParen, |
6803 | MultiExprArg PlacementArgs, |
6804 | SourceLocation PlacementRParen, |
6805 | SourceRange TypeIdParens, Declarator &D, |
6806 | Expr *Initializer); |
6807 | ExprResult |
6808 | BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, |
6809 | MultiExprArg PlacementArgs, SourceLocation PlacementRParen, |
6810 | SourceRange TypeIdParens, QualType AllocType, |
6811 | TypeSourceInfo *AllocTypeInfo, std::optional<Expr *> ArraySize, |
6812 | SourceRange DirectInitRange, Expr *Initializer); |
6813 | |
6814 | /// Determine whether \p FD is an aligned allocation or deallocation |
6815 | /// function that is unavailable. |
6816 | bool isUnavailableAlignedAllocationFunction(const FunctionDecl &FD) const; |
6817 | |
6818 | /// Produce diagnostics if \p FD is an aligned allocation or deallocation |
6819 | /// function that is unavailable. |
6820 | void diagnoseUnavailableAlignedAllocation(const FunctionDecl &FD, |
6821 | SourceLocation Loc); |
6822 | |
6823 | bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, |
6824 | SourceRange R); |
6825 | |
6826 | /// The scope in which to find allocation functions. |
6827 | enum AllocationFunctionScope { |
6828 | /// Only look for allocation functions in the global scope. |
6829 | AFS_Global, |
6830 | /// Only look for allocation functions in the scope of the |
6831 | /// allocated class. |
6832 | AFS_Class, |
6833 | /// Look for allocation functions in both the global scope |
6834 | /// and in the scope of the allocated class. |
6835 | AFS_Both |
6836 | }; |
6837 | |
6838 | /// Finds the overloads of operator new and delete that are appropriate |
6839 | /// for the allocation. |
6840 | bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, |
6841 | AllocationFunctionScope NewScope, |
6842 | AllocationFunctionScope DeleteScope, |
6843 | QualType AllocType, bool IsArray, |
6844 | bool &PassAlignment, MultiExprArg PlaceArgs, |
6845 | FunctionDecl *&OperatorNew, |
6846 | FunctionDecl *&OperatorDelete, |
6847 | bool Diagnose = true); |
6848 | void DeclareGlobalNewDelete(); |
6849 | void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, |
6850 | ArrayRef<QualType> Params); |
6851 | |
6852 | bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, |
6853 | DeclarationName Name, FunctionDecl *&Operator, |
6854 | bool Diagnose = true, bool WantSize = false, |
6855 | bool WantAligned = false); |
6856 | FunctionDecl *FindUsualDeallocationFunction(SourceLocation StartLoc, |
6857 | bool CanProvideSize, |
6858 | bool Overaligned, |
6859 | DeclarationName Name); |
6860 | FunctionDecl *FindDeallocationFunctionForDestructor(SourceLocation StartLoc, |
6861 | CXXRecordDecl *RD); |
6862 | |
6863 | /// ActOnCXXDelete - Parsed a C++ 'delete' expression |
6864 | ExprResult ActOnCXXDelete(SourceLocation StartLoc, |
6865 | bool UseGlobal, bool ArrayForm, |
6866 | Expr *Operand); |
6867 | void CheckVirtualDtorCall(CXXDestructorDecl *dtor, SourceLocation Loc, |
6868 | bool IsDelete, bool CallCanBeVirtual, |
6869 | bool WarnOnNonAbstractTypes, |
6870 | SourceLocation DtorLoc); |
6871 | |
6872 | ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, |
6873 | Expr *Operand, SourceLocation RParen); |
6874 | ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, |
6875 | SourceLocation RParen); |
6876 | |
6877 | /// Parsed one of the type trait support pseudo-functions. |
6878 | ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
6879 | ArrayRef<ParsedType> Args, |
6880 | SourceLocation RParenLoc); |
6881 | ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
6882 | ArrayRef<TypeSourceInfo *> Args, |
6883 | SourceLocation RParenLoc); |
6884 | |
6885 | /// ActOnArrayTypeTrait - Parsed one of the binary type trait support |
6886 | /// pseudo-functions. |
6887 | ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, |
6888 | SourceLocation KWLoc, |
6889 | ParsedType LhsTy, |
6890 | Expr *DimExpr, |
6891 | SourceLocation RParen); |
6892 | |
6893 | ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, |
6894 | SourceLocation KWLoc, |
6895 | TypeSourceInfo *TSInfo, |
6896 | Expr *DimExpr, |
6897 | SourceLocation RParen); |
6898 | |
6899 | /// ActOnExpressionTrait - Parsed one of the unary type trait support |
6900 | /// pseudo-functions. |
6901 | ExprResult ActOnExpressionTrait(ExpressionTrait OET, |
6902 | SourceLocation KWLoc, |
6903 | Expr *Queried, |
6904 | SourceLocation RParen); |
6905 | |
6906 | ExprResult BuildExpressionTrait(ExpressionTrait OET, |
6907 | SourceLocation KWLoc, |
6908 | Expr *Queried, |
6909 | SourceLocation RParen); |
6910 | |
6911 | ExprResult ActOnStartCXXMemberReference(Scope *S, |
6912 | Expr *Base, |
6913 | SourceLocation OpLoc, |
6914 | tok::TokenKind OpKind, |
6915 | ParsedType &ObjectType, |
6916 | bool &MayBePseudoDestructor); |
6917 | |
6918 | ExprResult BuildPseudoDestructorExpr(Expr *Base, |
6919 | SourceLocation OpLoc, |
6920 | tok::TokenKind OpKind, |
6921 | const CXXScopeSpec &SS, |
6922 | TypeSourceInfo *ScopeType, |
6923 | SourceLocation CCLoc, |
6924 | SourceLocation TildeLoc, |
6925 | PseudoDestructorTypeStorage DestroyedType); |
6926 | |
6927 | ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, |
6928 | SourceLocation OpLoc, |
6929 | tok::TokenKind OpKind, |
6930 | CXXScopeSpec &SS, |
6931 | UnqualifiedId &FirstTypeName, |
6932 | SourceLocation CCLoc, |
6933 | SourceLocation TildeLoc, |
6934 | UnqualifiedId &SecondTypeName); |
6935 | |
6936 | ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, |
6937 | SourceLocation OpLoc, |
6938 | tok::TokenKind OpKind, |
6939 | SourceLocation TildeLoc, |
6940 | const DeclSpec& DS); |
6941 | |
6942 | /// MaybeCreateExprWithCleanups - If the current full-expression |
6943 | /// requires any cleanups, surround it with a ExprWithCleanups node. |
6944 | /// Otherwise, just returns the passed-in expression. |
6945 | Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); |
6946 | Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); |
6947 | ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); |
6948 | |
6949 | MaterializeTemporaryExpr * |
6950 | CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, |
6951 | bool BoundToLvalueReference); |
6952 | |
6953 | ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue) { |
6954 | return ActOnFinishFullExpr( |
6955 | Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue); |
6956 | } |
6957 | ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC, |
6958 | bool DiscardedValue, bool IsConstexpr = false, |
6959 | bool IsTemplateArgument = false); |
6960 | StmtResult ActOnFinishFullStmt(Stmt *Stmt); |
6961 | |
6962 | // Marks SS invalid if it represents an incomplete type. |
6963 | bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); |
6964 | // Complete an enum decl, maybe without a scope spec. |
6965 | bool RequireCompleteEnumDecl(EnumDecl *D, SourceLocation L, |
6966 | CXXScopeSpec *SS = nullptr); |
6967 | |
6968 | DeclContext *computeDeclContext(QualType T); |
6969 | DeclContext *computeDeclContext(const CXXScopeSpec &SS, |
6970 | bool EnteringContext = false); |
6971 | bool isDependentScopeSpecifier(const CXXScopeSpec &SS); |
6972 | CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); |
6973 | |
6974 | /// The parser has parsed a global nested-name-specifier '::'. |
6975 | /// |
6976 | /// \param CCLoc The location of the '::'. |
6977 | /// |
6978 | /// \param SS The nested-name-specifier, which will be updated in-place |
6979 | /// to reflect the parsed nested-name-specifier. |
6980 | /// |
6981 | /// \returns true if an error occurred, false otherwise. |
6982 | bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS); |
6983 | |
6984 | /// The parser has parsed a '__super' nested-name-specifier. |
6985 | /// |
6986 | /// \param SuperLoc The location of the '__super' keyword. |
6987 | /// |
6988 | /// \param ColonColonLoc The location of the '::'. |
6989 | /// |
6990 | /// \param SS The nested-name-specifier, which will be updated in-place |
6991 | /// to reflect the parsed nested-name-specifier. |
6992 | /// |
6993 | /// \returns true if an error occurred, false otherwise. |
6994 | bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc, |
6995 | SourceLocation ColonColonLoc, CXXScopeSpec &SS); |
6996 | |
6997 | bool isAcceptableNestedNameSpecifier(const NamedDecl *SD, |
6998 | bool *CanCorrect = nullptr); |
6999 | NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); |
7000 | |
7001 | /// Keeps information about an identifier in a nested-name-spec. |
7002 | /// |
7003 | struct NestedNameSpecInfo { |
7004 | /// The type of the object, if we're parsing nested-name-specifier in |
7005 | /// a member access expression. |
7006 | ParsedType ObjectType; |
7007 | |
7008 | /// The identifier preceding the '::'. |
7009 | IdentifierInfo *Identifier; |
7010 | |
7011 | /// The location of the identifier. |
7012 | SourceLocation IdentifierLoc; |
7013 | |
7014 | /// The location of the '::'. |
7015 | SourceLocation CCLoc; |
7016 | |
7017 | /// Creates info object for the most typical case. |
7018 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
7019 | SourceLocation ColonColonLoc, ParsedType ObjectType = ParsedType()) |
7020 | : ObjectType(ObjectType), Identifier(II), IdentifierLoc(IdLoc), |
7021 | CCLoc(ColonColonLoc) { |
7022 | } |
7023 | |
7024 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
7025 | SourceLocation ColonColonLoc, QualType ObjectType) |
7026 | : ObjectType(ParsedType::make(ObjectType)), Identifier(II), |
7027 | IdentifierLoc(IdLoc), CCLoc(ColonColonLoc) { |
7028 | } |
7029 | }; |
7030 | |
7031 | bool BuildCXXNestedNameSpecifier(Scope *S, |
7032 | NestedNameSpecInfo &IdInfo, |
7033 | bool EnteringContext, |
7034 | CXXScopeSpec &SS, |
7035 | NamedDecl *ScopeLookupResult, |
7036 | bool ErrorRecoveryLookup, |
7037 | bool *IsCorrectedToColon = nullptr, |
7038 | bool OnlyNamespace = false); |
7039 | |
7040 | /// The parser has parsed a nested-name-specifier 'identifier::'. |
7041 | /// |
7042 | /// \param S The scope in which this nested-name-specifier occurs. |
7043 | /// |
7044 | /// \param IdInfo Parser information about an identifier in the |
7045 | /// nested-name-spec. |
7046 | /// |
7047 | /// \param EnteringContext Whether we're entering the context nominated by |
7048 | /// this nested-name-specifier. |
7049 | /// |
7050 | /// \param SS The nested-name-specifier, which is both an input |
7051 | /// parameter (the nested-name-specifier before this type) and an |
7052 | /// output parameter (containing the full nested-name-specifier, |
7053 | /// including this new type). |
7054 | /// |
7055 | /// \param IsCorrectedToColon If not null, suggestions to replace '::' -> ':' |
7056 | /// are allowed. The bool value pointed by this parameter is set to 'true' |
7057 | /// if the identifier is treated as if it was followed by ':', not '::'. |
7058 | /// |
7059 | /// \param OnlyNamespace If true, only considers namespaces in lookup. |
7060 | /// |
7061 | /// \returns true if an error occurred, false otherwise. |
7062 | bool ActOnCXXNestedNameSpecifier(Scope *S, |
7063 | NestedNameSpecInfo &IdInfo, |
7064 | bool EnteringContext, |
7065 | CXXScopeSpec &SS, |
7066 | bool *IsCorrectedToColon = nullptr, |
7067 | bool OnlyNamespace = false); |
7068 | |
7069 | ExprResult ActOnDecltypeExpression(Expr *E); |
7070 | |
7071 | bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, |
7072 | const DeclSpec &DS, |
7073 | SourceLocation ColonColonLoc); |
7074 | |
7075 | bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, |
7076 | NestedNameSpecInfo &IdInfo, |
7077 | bool EnteringContext); |
7078 | |
7079 | /// The parser has parsed a nested-name-specifier |
7080 | /// 'template[opt] template-name < template-args >::'. |
7081 | /// |
7082 | /// \param S The scope in which this nested-name-specifier occurs. |
7083 | /// |
7084 | /// \param SS The nested-name-specifier, which is both an input |
7085 | /// parameter (the nested-name-specifier before this type) and an |
7086 | /// output parameter (containing the full nested-name-specifier, |
7087 | /// including this new type). |
7088 | /// |
7089 | /// \param TemplateKWLoc the location of the 'template' keyword, if any. |
7090 | /// \param TemplateName the template name. |
7091 | /// \param TemplateNameLoc The location of the template name. |
7092 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
7093 | /// \param TemplateArgs The template arguments. |
7094 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
7095 | /// \param CCLoc The location of the '::'. |
7096 | /// |
7097 | /// \param EnteringContext Whether we're entering the context of the |
7098 | /// nested-name-specifier. |
7099 | /// |
7100 | /// |
7101 | /// \returns true if an error occurred, false otherwise. |
7102 | bool ActOnCXXNestedNameSpecifier(Scope *S, |
7103 | CXXScopeSpec &SS, |
7104 | SourceLocation TemplateKWLoc, |
7105 | TemplateTy TemplateName, |
7106 | SourceLocation TemplateNameLoc, |
7107 | SourceLocation LAngleLoc, |
7108 | ASTTemplateArgsPtr TemplateArgs, |
7109 | SourceLocation RAngleLoc, |
7110 | SourceLocation CCLoc, |
7111 | bool EnteringContext); |
7112 | |
7113 | /// Given a C++ nested-name-specifier, produce an annotation value |
7114 | /// that the parser can use later to reconstruct the given |
7115 | /// nested-name-specifier. |
7116 | /// |
7117 | /// \param SS A nested-name-specifier. |
7118 | /// |
7119 | /// \returns A pointer containing all of the information in the |
7120 | /// nested-name-specifier \p SS. |
7121 | void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); |
7122 | |
7123 | /// Given an annotation pointer for a nested-name-specifier, restore |
7124 | /// the nested-name-specifier structure. |
7125 | /// |
7126 | /// \param Annotation The annotation pointer, produced by |
7127 | /// \c SaveNestedNameSpecifierAnnotation(). |
7128 | /// |
7129 | /// \param AnnotationRange The source range corresponding to the annotation. |
7130 | /// |
7131 | /// \param SS The nested-name-specifier that will be updated with the contents |
7132 | /// of the annotation pointer. |
7133 | void RestoreNestedNameSpecifierAnnotation(void *Annotation, |
7134 | SourceRange AnnotationRange, |
7135 | CXXScopeSpec &SS); |
7136 | |
7137 | bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
7138 | |
7139 | /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global |
7140 | /// scope or nested-name-specifier) is parsed, part of a declarator-id. |
7141 | /// After this method is called, according to [C++ 3.4.3p3], names should be |
7142 | /// looked up in the declarator-id's scope, until the declarator is parsed and |
7143 | /// ActOnCXXExitDeclaratorScope is called. |
7144 | /// The 'SS' should be a non-empty valid CXXScopeSpec. |
7145 | bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); |
7146 | |
7147 | /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously |
7148 | /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same |
7149 | /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. |
7150 | /// Used to indicate that names should revert to being looked up in the |
7151 | /// defining scope. |
7152 | void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
7153 | |
7154 | /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an |
7155 | /// initializer for the declaration 'Dcl'. |
7156 | /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a |
7157 | /// static data member of class X, names should be looked up in the scope of |
7158 | /// class X. |
7159 | void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); |
7160 | |
7161 | /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an |
7162 | /// initializer for the declaration 'Dcl'. |
7163 | void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); |
7164 | |
7165 | /// Create a new lambda closure type. |
7166 | CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange, |
7167 | TypeSourceInfo *Info, |
7168 | unsigned LambdaDependencyKind, |
7169 | LambdaCaptureDefault CaptureDefault); |
7170 | |
7171 | /// Number lambda for linkage purposes if necessary. |
7172 | void handleLambdaNumbering(CXXRecordDecl *Class, CXXMethodDecl *Method, |
7173 | std::optional<CXXRecordDecl::LambdaNumbering> |
7174 | NumberingOverride = std::nullopt); |
7175 | |
7176 | /// Endow the lambda scope info with the relevant properties. |
7177 | void buildLambdaScope(sema::LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator, |
7178 | SourceRange IntroducerRange, |
7179 | LambdaCaptureDefault CaptureDefault, |
7180 | SourceLocation CaptureDefaultLoc, bool ExplicitParams, |
7181 | bool Mutable); |
7182 | |
7183 | CXXMethodDecl *CreateLambdaCallOperator(SourceRange IntroducerRange, |
7184 | CXXRecordDecl *Class); |
7185 | void CompleteLambdaCallOperator( |
7186 | CXXMethodDecl *Method, SourceLocation LambdaLoc, |
7187 | SourceLocation CallOperatorLoc, Expr *TrailingRequiresClause, |
7188 | TypeSourceInfo *MethodTyInfo, ConstexprSpecKind ConstexprKind, |
7189 | StorageClass SC, ArrayRef<ParmVarDecl *> Params, |
7190 | bool HasExplicitResultType); |
7191 | |
7192 | /// Perform initialization analysis of the init-capture and perform |
7193 | /// any implicit conversions such as an lvalue-to-rvalue conversion if |
7194 | /// not being used to initialize a reference. |
7195 | ParsedType actOnLambdaInitCaptureInitialization( |
7196 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
7197 | IdentifierInfo *Id, LambdaCaptureInitKind InitKind, Expr *&Init) { |
7198 | return ParsedType::make(buildLambdaInitCaptureInitialization( |
7199 | Loc, ByRef, EllipsisLoc, std::nullopt, Id, |
7200 | InitKind != LambdaCaptureInitKind::CopyInit, Init)); |
7201 | } |
7202 | QualType buildLambdaInitCaptureInitialization( |
7203 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
7204 | std::optional<unsigned> NumExpansions, IdentifierInfo *Id, |
7205 | bool DirectInit, Expr *&Init); |
7206 | |
7207 | /// Create a dummy variable within the declcontext of the lambda's |
7208 | /// call operator, for name lookup purposes for a lambda init capture. |
7209 | /// |
7210 | /// CodeGen handles emission of lambda captures, ignoring these dummy |
7211 | /// variables appropriately. |
7212 | VarDecl *createLambdaInitCaptureVarDecl( |
7213 | SourceLocation Loc, QualType InitCaptureType, SourceLocation EllipsisLoc, |
7214 | IdentifierInfo *Id, unsigned InitStyle, Expr *Init, DeclContext *DeclCtx); |
7215 | |
7216 | /// Add an init-capture to a lambda scope. |
7217 | void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var, bool ByRef); |
7218 | |
7219 | /// Note that we have finished the explicit captures for the |
7220 | /// given lambda. |
7221 | void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI); |
7222 | |
7223 | /// Deduce a block or lambda's return type based on the return |
7224 | /// statements present in the body. |
7225 | void deduceClosureReturnType(sema::CapturingScopeInfo &CSI); |
7226 | |
7227 | /// Once the Lambdas capture are known, we can start to create the closure, |
7228 | /// call operator method, and keep track of the captures. |
7229 | /// We do the capture lookup here, but they are not actually captured until |
7230 | /// after we know what the qualifiers of the call operator are. |
7231 | void ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro, |
7232 | Scope *CurContext); |
7233 | |
7234 | /// This is called after parsing the explicit template parameter list |
7235 | /// on a lambda (if it exists) in C++2a. |
7236 | void ActOnLambdaExplicitTemplateParameterList(LambdaIntroducer &Intro, |
7237 | SourceLocation LAngleLoc, |
7238 | ArrayRef<NamedDecl *> TParams, |
7239 | SourceLocation RAngleLoc, |
7240 | ExprResult RequiresClause); |
7241 | |
7242 | void ActOnLambdaClosureQualifiers(LambdaIntroducer &Intro, |
7243 | SourceLocation MutableLoc); |
7244 | |
7245 | void ActOnLambdaClosureParameters( |
7246 | Scope *LambdaScope, |
7247 | MutableArrayRef<DeclaratorChunk::ParamInfo> ParamInfo); |
7248 | |
7249 | /// ActOnStartOfLambdaDefinition - This is called just before we start |
7250 | /// parsing the body of a lambda; it analyzes the explicit captures and |
7251 | /// arguments, and sets up various data-structures for the body of the |
7252 | /// lambda. |
7253 | void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, |
7254 | Declarator &ParamInfo, const DeclSpec &DS); |
7255 | |
7256 | /// ActOnLambdaError - If there is an error parsing a lambda, this callback |
7257 | /// is invoked to pop the information about the lambda. |
7258 | void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, |
7259 | bool IsInstantiation = false); |
7260 | |
7261 | /// ActOnLambdaExpr - This is called when the body of a lambda expression |
7262 | /// was successfully completed. |
7263 | ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, |
7264 | Scope *CurScope); |
7265 | |
7266 | /// Does copying/destroying the captured variable have side effects? |
7267 | bool CaptureHasSideEffects(const sema::Capture &From); |
7268 | |
7269 | /// Diagnose if an explicit lambda capture is unused. Returns true if a |
7270 | /// diagnostic is emitted. |
7271 | bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange, |
7272 | const sema::Capture &From); |
7273 | |
7274 | /// Build a FieldDecl suitable to hold the given capture. |
7275 | FieldDecl *BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture); |
7276 | |
7277 | /// Initialize the given capture with a suitable expression. |
7278 | ExprResult BuildCaptureInit(const sema::Capture &Capture, |
7279 | SourceLocation ImplicitCaptureLoc, |
7280 | bool IsOpenMPMapping = false); |
7281 | |
7282 | /// Complete a lambda-expression having processed and attached the |
7283 | /// lambda body. |
7284 | ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, |
7285 | sema::LambdaScopeInfo *LSI); |
7286 | |
7287 | /// Get the return type to use for a lambda's conversion function(s) to |
7288 | /// function pointer type, given the type of the call operator. |
7289 | QualType |
7290 | getLambdaConversionFunctionResultType(const FunctionProtoType *CallOpType, |
7291 | CallingConv CC); |
7292 | |
7293 | /// Define the "body" of the conversion from a lambda object to a |
7294 | /// function pointer. |
7295 | /// |
7296 | /// This routine doesn't actually define a sensible body; rather, it fills |
7297 | /// in the initialization expression needed to copy the lambda object into |
7298 | /// the block, and IR generation actually generates the real body of the |
7299 | /// block pointer conversion. |
7300 | void DefineImplicitLambdaToFunctionPointerConversion( |
7301 | SourceLocation CurrentLoc, CXXConversionDecl *Conv); |
7302 | |
7303 | /// Define the "body" of the conversion from a lambda object to a |
7304 | /// block pointer. |
7305 | /// |
7306 | /// This routine doesn't actually define a sensible body; rather, it fills |
7307 | /// in the initialization expression needed to copy the lambda object into |
7308 | /// the block, and IR generation actually generates the real body of the |
7309 | /// block pointer conversion. |
7310 | void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc, |
7311 | CXXConversionDecl *Conv); |
7312 | |
7313 | ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, |
7314 | SourceLocation ConvLocation, |
7315 | CXXConversionDecl *Conv, |
7316 | Expr *Src); |
7317 | |
7318 | /// Check whether the given expression is a valid constraint expression. |
7319 | /// A diagnostic is emitted if it is not, false is returned, and |
7320 | /// PossibleNonPrimary will be set to true if the failure might be due to a |
7321 | /// non-primary expression being used as an atomic constraint. |
7322 | bool CheckConstraintExpression(const Expr *CE, Token NextToken = Token(), |
7323 | bool *PossibleNonPrimary = nullptr, |
7324 | bool IsTrailingRequiresClause = false); |
7325 | |
7326 | private: |
7327 | /// Caches pairs of template-like decls whose associated constraints were |
7328 | /// checked for subsumption and whether or not the first's constraints did in |
7329 | /// fact subsume the second's. |
7330 | llvm::DenseMap<std::pair<NamedDecl *, NamedDecl *>, bool> SubsumptionCache; |
7331 | /// Caches the normalized associated constraints of declarations (concepts or |
7332 | /// constrained declarations). If an error occurred while normalizing the |
7333 | /// associated constraints of the template or concept, nullptr will be cached |
7334 | /// here. |
7335 | llvm::DenseMap<NamedDecl *, NormalizedConstraint *> |
7336 | NormalizationCache; |
7337 | |
7338 | llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &> |
7339 | SatisfactionCache; |
7340 | |
7341 | /// Introduce the instantiated function parameters into the local |
7342 | /// instantiation scope, and set the parameter names to those used |
7343 | /// in the template. |
7344 | bool addInstantiatedParametersToScope( |
7345 | FunctionDecl *Function, const FunctionDecl *PatternDecl, |
7346 | LocalInstantiationScope &Scope, |
7347 | const MultiLevelTemplateArgumentList &TemplateArgs); |
7348 | |
7349 | /// Introduce the instantiated captures of the lambda into the local |
7350 | /// instantiation scope. |
7351 | bool addInstantiatedCapturesToScope( |
7352 | FunctionDecl *Function, const FunctionDecl *PatternDecl, |
7353 | LocalInstantiationScope &Scope, |
7354 | const MultiLevelTemplateArgumentList &TemplateArgs); |
7355 | |
7356 | /// used by SetupConstraintCheckingTemplateArgumentsAndScope to recursively(in |
7357 | /// the case of lambdas) set up the LocalInstantiationScope of the current |
7358 | /// function. |
7359 | bool SetupConstraintScope( |
7360 | FunctionDecl *FD, std::optional<ArrayRef<TemplateArgument>> TemplateArgs, |
7361 | MultiLevelTemplateArgumentList MLTAL, LocalInstantiationScope &Scope); |
7362 | |
7363 | /// Used during constraint checking, sets up the constraint template argument |
7364 | /// lists, and calls SetupConstraintScope to set up the |
7365 | /// LocalInstantiationScope to have the proper set of ParVarDecls configured. |
7366 | std::optional<MultiLevelTemplateArgumentList> |
7367 | SetupConstraintCheckingTemplateArgumentsAndScope( |
7368 | FunctionDecl *FD, std::optional<ArrayRef<TemplateArgument>> TemplateArgs, |
7369 | LocalInstantiationScope &Scope); |
7370 | |
7371 | private: |
7372 | // The current stack of constraint satisfactions, so we can exit-early. |
7373 | using SatisfactionStackEntryTy = |
7374 | std::pair<const NamedDecl *, llvm::FoldingSetNodeID>; |
7375 | llvm::SmallVector<SatisfactionStackEntryTy, 10> |
7376 | SatisfactionStack; |
7377 | |
7378 | public: |
7379 | void PushSatisfactionStackEntry(const NamedDecl *D, |
7380 | const llvm::FoldingSetNodeID &ID) { |
7381 | const NamedDecl *Can = cast<NamedDecl>(D->getCanonicalDecl()); |
7382 | SatisfactionStack.emplace_back(Can, ID); |
7383 | } |
7384 | |
7385 | void PopSatisfactionStackEntry() { SatisfactionStack.pop_back(); } |
7386 | |
7387 | bool SatisfactionStackContains(const NamedDecl *D, |
7388 | const llvm::FoldingSetNodeID &ID) const { |
7389 | const NamedDecl *Can = cast<NamedDecl>(D->getCanonicalDecl()); |
7390 | return llvm::find(SatisfactionStack, |
7391 | SatisfactionStackEntryTy{Can, ID}) != |
7392 | SatisfactionStack.end(); |
7393 | } |
7394 | |
7395 | // Resets the current SatisfactionStack for cases where we are instantiating |
7396 | // constraints as a 'side effect' of normal instantiation in a way that is not |
7397 | // indicative of recursive definition. |
7398 | class SatisfactionStackResetRAII { |
7399 | llvm::SmallVector<SatisfactionStackEntryTy, 10> |
7400 | BackupSatisfactionStack; |
7401 | Sema &SemaRef; |
7402 | |
7403 | public: |
7404 | SatisfactionStackResetRAII(Sema &S) : SemaRef(S) { |
7405 | SemaRef.SwapSatisfactionStack(BackupSatisfactionStack); |
7406 | } |
7407 | |
7408 | ~SatisfactionStackResetRAII() { |
7409 | SemaRef.SwapSatisfactionStack(BackupSatisfactionStack); |
7410 | } |
7411 | }; |
7412 | |
7413 | void SwapSatisfactionStack( |
7414 | llvm::SmallVectorImpl<SatisfactionStackEntryTy> &NewSS) { |
7415 | SatisfactionStack.swap(NewSS); |
7416 | } |
7417 | |
7418 | const NormalizedConstraint * |
7419 | getNormalizedAssociatedConstraints( |
7420 | NamedDecl *ConstrainedDecl, ArrayRef<const Expr *> AssociatedConstraints); |
7421 | |
7422 | /// \brief Check whether the given declaration's associated constraints are |
7423 | /// at least as constrained than another declaration's according to the |
7424 | /// partial ordering of constraints. |
7425 | /// |
7426 | /// \param Result If no error occurred, receives the result of true if D1 is |
7427 | /// at least constrained than D2, and false otherwise. |
7428 | /// |
7429 | /// \returns true if an error occurred, false otherwise. |
7430 | bool IsAtLeastAsConstrained(NamedDecl *D1, MutableArrayRef<const Expr *> AC1, |
7431 | NamedDecl *D2, MutableArrayRef<const Expr *> AC2, |
7432 | bool &Result); |
7433 | |
7434 | /// If D1 was not at least as constrained as D2, but would've been if a pair |
7435 | /// of atomic constraints involved had been declared in a concept and not |
7436 | /// repeated in two separate places in code. |
7437 | /// \returns true if such a diagnostic was emitted, false otherwise. |
7438 | bool MaybeEmitAmbiguousAtomicConstraintsDiagnostic(NamedDecl *D1, |
7439 | ArrayRef<const Expr *> AC1, NamedDecl *D2, ArrayRef<const Expr *> AC2); |
7440 | |
7441 | /// \brief Check whether the given list of constraint expressions are |
7442 | /// satisfied (as if in a 'conjunction') given template arguments. |
7443 | /// \param Template the template-like entity that triggered the constraints |
7444 | /// check (either a concept or a constrained entity). |
7445 | /// \param ConstraintExprs a list of constraint expressions, treated as if |
7446 | /// they were 'AND'ed together. |
7447 | /// \param TemplateArgLists the list of template arguments to substitute into |
7448 | /// the constraint expression. |
7449 | /// \param TemplateIDRange The source range of the template id that |
7450 | /// caused the constraints check. |
7451 | /// \param Satisfaction if true is returned, will contain details of the |
7452 | /// satisfaction, with enough information to diagnose an unsatisfied |
7453 | /// expression. |
7454 | /// \returns true if an error occurred and satisfaction could not be checked, |
7455 | /// false otherwise. |
7456 | bool CheckConstraintSatisfaction( |
7457 | const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs, |
7458 | const MultiLevelTemplateArgumentList &TemplateArgLists, |
7459 | SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction) { |
7460 | llvm::SmallVector<Expr *, 4> Converted; |
7461 | return CheckConstraintSatisfaction(Template, ConstraintExprs, Converted, |
7462 | TemplateArgLists, TemplateIDRange, |
7463 | Satisfaction); |
7464 | } |
7465 | |
7466 | /// \brief Check whether the given list of constraint expressions are |
7467 | /// satisfied (as if in a 'conjunction') given template arguments. |
7468 | /// Additionally, takes an empty list of Expressions which is populated with |
7469 | /// the instantiated versions of the ConstraintExprs. |
7470 | /// \param Template the template-like entity that triggered the constraints |
7471 | /// check (either a concept or a constrained entity). |
7472 | /// \param ConstraintExprs a list of constraint expressions, treated as if |
7473 | /// they were 'AND'ed together. |
7474 | /// \param ConvertedConstraints a out parameter that will get populated with |
7475 | /// the instantiated version of the ConstraintExprs if we successfully checked |
7476 | /// satisfaction. |
7477 | /// \param TemplateArgList the multi-level list of template arguments to |
7478 | /// substitute into the constraint expression. This should be relative to the |
7479 | /// top-level (hence multi-level), since we need to instantiate fully at the |
7480 | /// time of checking. |
7481 | /// \param TemplateIDRange The source range of the template id that |
7482 | /// caused the constraints check. |
7483 | /// \param Satisfaction if true is returned, will contain details of the |
7484 | /// satisfaction, with enough information to diagnose an unsatisfied |
7485 | /// expression. |
7486 | /// \returns true if an error occurred and satisfaction could not be checked, |
7487 | /// false otherwise. |
7488 | bool CheckConstraintSatisfaction( |
7489 | const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs, |
7490 | llvm::SmallVectorImpl<Expr *> &ConvertedConstraints, |
7491 | const MultiLevelTemplateArgumentList &TemplateArgList, |
7492 | SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction); |
7493 | |
7494 | /// \brief Check whether the given non-dependent constraint expression is |
7495 | /// satisfied. Returns false and updates Satisfaction with the satisfaction |
7496 | /// verdict if successful, emits a diagnostic and returns true if an error |
7497 | /// occurred and satisfaction could not be determined. |
7498 | /// |
7499 | /// \returns true if an error occurred, false otherwise. |
7500 | bool CheckConstraintSatisfaction(const Expr *ConstraintExpr, |
7501 | ConstraintSatisfaction &Satisfaction); |
7502 | |
7503 | /// Check whether the given function decl's trailing requires clause is |
7504 | /// satisfied, if any. Returns false and updates Satisfaction with the |
7505 | /// satisfaction verdict if successful, emits a diagnostic and returns true if |
7506 | /// an error occurred and satisfaction could not be determined. |
7507 | /// |
7508 | /// \returns true if an error occurred, false otherwise. |
7509 | bool CheckFunctionConstraints(const FunctionDecl *FD, |
7510 | ConstraintSatisfaction &Satisfaction, |
7511 | SourceLocation UsageLoc = SourceLocation(), |
7512 | bool ForOverloadResolution = false); |
7513 | |
7514 | /// \brief Ensure that the given template arguments satisfy the constraints |
7515 | /// associated with the given template, emitting a diagnostic if they do not. |
7516 | /// |
7517 | /// \param Template The template to which the template arguments are being |
7518 | /// provided. |
7519 | /// |
7520 | /// \param TemplateArgs The converted, canonicalized template arguments. |
7521 | /// |
7522 | /// \param TemplateIDRange The source range of the template id that |
7523 | /// caused the constraints check. |
7524 | /// |
7525 | /// \returns true if the constrains are not satisfied or could not be checked |
7526 | /// for satisfaction, false if the constraints are satisfied. |
7527 | bool EnsureTemplateArgumentListConstraints( |
7528 | TemplateDecl *Template, |
7529 | const MultiLevelTemplateArgumentList &TemplateArgs, |
7530 | SourceRange TemplateIDRange); |
7531 | |
7532 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
7533 | /// unsatisfied. |
7534 | /// \param First whether this is the first time an unsatisfied constraint is |
7535 | /// diagnosed for this error. |
7536 | void |
7537 | DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction &Satisfaction, |
7538 | bool First = true); |
7539 | |
7540 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
7541 | /// unsatisfied. |
7542 | void |
7543 | DiagnoseUnsatisfiedConstraint(const ASTConstraintSatisfaction &Satisfaction, |
7544 | bool First = true); |
7545 | |
7546 | // ParseObjCStringLiteral - Parse Objective-C string literals. |
7547 | ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, |
7548 | ArrayRef<Expr *> Strings); |
7549 | |
7550 | ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S); |
7551 | |
7552 | /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the |
7553 | /// numeric literal expression. Type of the expression will be "NSNumber *" |
7554 | /// or "id" if NSNumber is unavailable. |
7555 | ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number); |
7556 | ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc, |
7557 | bool Value); |
7558 | ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements); |
7559 | |
7560 | /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the |
7561 | /// '@' prefixed parenthesized expression. The type of the expression will |
7562 | /// either be "NSNumber *", "NSString *" or "NSValue *" depending on the type |
7563 | /// of ValueType, which is allowed to be a built-in numeric type, "char *", |
7564 | /// "const char *" or C structure with attribute 'objc_boxable'. |
7565 | ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr); |
7566 | |
7567 | ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, |
7568 | Expr *IndexExpr, |
7569 | ObjCMethodDecl *getterMethod, |
7570 | ObjCMethodDecl *setterMethod); |
7571 | |
7572 | ExprResult BuildObjCDictionaryLiteral(SourceRange SR, |
7573 | MutableArrayRef<ObjCDictionaryElement> Elements); |
7574 | |
7575 | ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, |
7576 | TypeSourceInfo *EncodedTypeInfo, |
7577 | SourceLocation RParenLoc); |
7578 | ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, |
7579 | CXXConversionDecl *Method, |
7580 | bool HadMultipleCandidates); |
7581 | |
7582 | ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, |
7583 | SourceLocation EncodeLoc, |
7584 | SourceLocation LParenLoc, |
7585 | ParsedType Ty, |
7586 | SourceLocation RParenLoc); |
7587 | |
7588 | /// ParseObjCSelectorExpression - Build selector expression for \@selector |
7589 | ExprResult ParseObjCSelectorExpression(Selector Sel, |
7590 | SourceLocation AtLoc, |
7591 | SourceLocation SelLoc, |
7592 | SourceLocation LParenLoc, |
7593 | SourceLocation RParenLoc, |
7594 | bool WarnMultipleSelectors); |
7595 | |
7596 | /// ParseObjCProtocolExpression - Build protocol expression for \@protocol |
7597 | ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, |
7598 | SourceLocation AtLoc, |
7599 | SourceLocation ProtoLoc, |
7600 | SourceLocation LParenLoc, |
7601 | SourceLocation ProtoIdLoc, |
7602 | SourceLocation RParenLoc); |
7603 | |
7604 | //===--------------------------------------------------------------------===// |
7605 | // C++ Declarations |
7606 | // |
7607 | Decl *ActOnStartLinkageSpecification(Scope *S, |
7608 | SourceLocation ExternLoc, |
7609 | Expr *LangStr, |
7610 | SourceLocation LBraceLoc); |
7611 | Decl *ActOnFinishLinkageSpecification(Scope *S, |
7612 | Decl *LinkageSpec, |
7613 | SourceLocation RBraceLoc); |
7614 | |
7615 | |
7616 | //===--------------------------------------------------------------------===// |
7617 | // C++ Classes |
7618 | // |
7619 | CXXRecordDecl *getCurrentClass(Scope *S, const CXXScopeSpec *SS); |
7620 | bool isCurrentClassName(const IdentifierInfo &II, Scope *S, |
7621 | const CXXScopeSpec *SS = nullptr); |
7622 | bool isCurrentClassNameTypo(IdentifierInfo *&II, const CXXScopeSpec *SS); |
7623 | |
7624 | bool ActOnAccessSpecifier(AccessSpecifier Access, SourceLocation ASLoc, |
7625 | SourceLocation ColonLoc, |
7626 | const ParsedAttributesView &Attrs); |
7627 | |
7628 | NamedDecl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, |
7629 | Declarator &D, |
7630 | MultiTemplateParamsArg TemplateParameterLists, |
7631 | Expr *BitfieldWidth, const VirtSpecifiers &VS, |
7632 | InClassInitStyle InitStyle); |
7633 | |
7634 | void ActOnStartCXXInClassMemberInitializer(); |
7635 | void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl, |
7636 | SourceLocation EqualLoc, |
7637 | Expr *Init); |
7638 | |
7639 | MemInitResult ActOnMemInitializer(Decl *ConstructorD, |
7640 | Scope *S, |
7641 | CXXScopeSpec &SS, |
7642 | IdentifierInfo *MemberOrBase, |
7643 | ParsedType TemplateTypeTy, |
7644 | const DeclSpec &DS, |
7645 | SourceLocation IdLoc, |
7646 | SourceLocation LParenLoc, |
7647 | ArrayRef<Expr *> Args, |
7648 | SourceLocation RParenLoc, |
7649 | SourceLocation EllipsisLoc); |
7650 | |
7651 | MemInitResult ActOnMemInitializer(Decl *ConstructorD, |
7652 | Scope *S, |
7653 | CXXScopeSpec &SS, |
7654 | IdentifierInfo *MemberOrBase, |
7655 | ParsedType TemplateTypeTy, |
7656 | const DeclSpec &DS, |
7657 | SourceLocation IdLoc, |
7658 | Expr *InitList, |
7659 | SourceLocation EllipsisLoc); |
7660 | |
7661 | MemInitResult BuildMemInitializer(Decl *ConstructorD, |
7662 | Scope *S, |
7663 | CXXScopeSpec &SS, |
7664 | IdentifierInfo *MemberOrBase, |
7665 | ParsedType TemplateTypeTy, |
7666 | const DeclSpec &DS, |
7667 | SourceLocation IdLoc, |
7668 | Expr *Init, |
7669 | SourceLocation EllipsisLoc); |
7670 | |
7671 | MemInitResult BuildMemberInitializer(ValueDecl *Member, |
7672 | Expr *Init, |
7673 | SourceLocation IdLoc); |
7674 | |
7675 | MemInitResult BuildBaseInitializer(QualType BaseType, |
7676 | TypeSourceInfo *BaseTInfo, |
7677 | Expr *Init, |
7678 | CXXRecordDecl *ClassDecl, |
7679 | SourceLocation EllipsisLoc); |
7680 | |
7681 | MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, |
7682 | Expr *Init, |
7683 | CXXRecordDecl *ClassDecl); |
7684 | |
7685 | bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, |
7686 | CXXCtorInitializer *Initializer); |
7687 | |
7688 | bool SetCtorInitializers( |
7689 | CXXConstructorDecl *Constructor, bool AnyErrors, |
7690 | ArrayRef<CXXCtorInitializer *> Initializers = std::nullopt); |
7691 | |
7692 | void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); |
7693 | |
7694 | |
7695 | /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, |
7696 | /// mark all the non-trivial destructors of its members and bases as |
7697 | /// referenced. |
7698 | void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, |
7699 | CXXRecordDecl *Record); |
7700 | |
7701 | /// Mark destructors of virtual bases of this class referenced. In the Itanium |
7702 | /// C++ ABI, this is done when emitting a destructor for any non-abstract |
7703 | /// class. In the Microsoft C++ ABI, this is done any time a class's |
7704 | /// destructor is referenced. |
7705 | void MarkVirtualBaseDestructorsReferenced( |
7706 | SourceLocation Location, CXXRecordDecl *ClassDecl, |
7707 | llvm::SmallPtrSetImpl<const RecordType *> *DirectVirtualBases = nullptr); |
7708 | |
7709 | /// Do semantic checks to allow the complete destructor variant to be emitted |
7710 | /// when the destructor is defined in another translation unit. In the Itanium |
7711 | /// C++ ABI, destructor variants are emitted together. In the MS C++ ABI, they |
7712 | /// can be emitted in separate TUs. To emit the complete variant, run a subset |
7713 | /// of the checks performed when emitting a regular destructor. |
7714 | void CheckCompleteDestructorVariant(SourceLocation CurrentLocation, |
7715 | CXXDestructorDecl *Dtor); |
7716 | |
7717 | /// The list of classes whose vtables have been used within |
7718 | /// this translation unit, and the source locations at which the |
7719 | /// first use occurred. |
7720 | typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse; |
7721 | |
7722 | /// The list of vtables that are required but have not yet been |
7723 | /// materialized. |
7724 | SmallVector<VTableUse, 16> VTableUses; |
7725 | |
7726 | /// The set of classes whose vtables have been used within |
7727 | /// this translation unit, and a bit that will be true if the vtable is |
7728 | /// required to be emitted (otherwise, it should be emitted only if needed |
7729 | /// by code generation). |
7730 | llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; |
7731 | |
7732 | /// Load any externally-stored vtable uses. |
7733 | void LoadExternalVTableUses(); |
7734 | |
7735 | /// Note that the vtable for the given class was used at the |
7736 | /// given location. |
7737 | void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, |
7738 | bool DefinitionRequired = false); |
7739 | |
7740 | /// Mark the exception specifications of all virtual member functions |
7741 | /// in the given class as needed. |
7742 | void MarkVirtualMemberExceptionSpecsNeeded(SourceLocation Loc, |
7743 | const CXXRecordDecl *RD); |
7744 | |
7745 | /// MarkVirtualMembersReferenced - Will mark all members of the given |
7746 | /// CXXRecordDecl referenced. |
7747 | void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD, |
7748 | bool ConstexprOnly = false); |
7749 | |
7750 | /// Define all of the vtables that have been used in this |
7751 | /// translation unit and reference any virtual members used by those |
7752 | /// vtables. |
7753 | /// |
7754 | /// \returns true if any work was done, false otherwise. |
7755 | bool DefineUsedVTables(); |
7756 | |
7757 | void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); |
7758 | |
7759 | void ActOnMemInitializers(Decl *ConstructorDecl, |
7760 | SourceLocation ColonLoc, |
7761 | ArrayRef<CXXCtorInitializer*> MemInits, |
7762 | bool AnyErrors); |
7763 | |
7764 | /// Check class-level dllimport/dllexport attribute. The caller must |
7765 | /// ensure that referenceDLLExportedClassMethods is called some point later |
7766 | /// when all outer classes of Class are complete. |
7767 | void checkClassLevelDLLAttribute(CXXRecordDecl *Class); |
7768 | void checkClassLevelCodeSegAttribute(CXXRecordDecl *Class); |
7769 | |
7770 | void referenceDLLExportedClassMethods(); |
7771 | |
7772 | void propagateDLLAttrToBaseClassTemplate( |
7773 | CXXRecordDecl *Class, Attr *ClassAttr, |
7774 | ClassTemplateSpecializationDecl *BaseTemplateSpec, |
7775 | SourceLocation BaseLoc); |
7776 | |
7777 | /// Add gsl::Pointer attribute to std::container::iterator |
7778 | /// \param ND The declaration that introduces the name |
7779 | /// std::container::iterator. \param UnderlyingRecord The record named by ND. |
7780 | void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord); |
7781 | |
7782 | /// Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types. |
7783 | void inferGslOwnerPointerAttribute(CXXRecordDecl *Record); |
7784 | |
7785 | /// Add [[gsl::Pointer]] attributes for std:: types. |
7786 | void inferGslPointerAttribute(TypedefNameDecl *TD); |
7787 | |
7788 | void CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record); |
7789 | |
7790 | /// Check that the C++ class annoated with "trivial_abi" satisfies all the |
7791 | /// conditions that are needed for the attribute to have an effect. |
7792 | void checkIllFormedTrivialABIStruct(CXXRecordDecl &RD); |
7793 | |
7794 | void ActOnFinishCXXMemberSpecification(Scope *S, SourceLocation RLoc, |
7795 | Decl *TagDecl, SourceLocation LBrac, |
7796 | SourceLocation RBrac, |
7797 | const ParsedAttributesView &AttrList); |
7798 | void ActOnFinishCXXMemberDecls(); |
7799 | void ActOnFinishCXXNonNestedClass(); |
7800 | |
7801 | void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param); |
7802 | unsigned ActOnReenterTemplateScope(Decl *Template, |
7803 | llvm::function_ref<Scope *()> EnterScope); |
7804 | void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); |
7805 | void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
7806 | void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); |
7807 | void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); |
7808 | void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
7809 | void ActOnFinishDelayedMemberInitializers(Decl *Record); |
7810 | void MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD, |
7811 | CachedTokens &Toks); |
7812 | void UnmarkAsLateParsedTemplate(FunctionDecl *FD); |
7813 | bool IsInsideALocalClassWithinATemplateFunction(); |
7814 | |
7815 | bool EvaluateStaticAssertMessageAsString(Expr *Message, std::string &Result, |
7816 | ASTContext &Ctx, |
7817 | bool ErrorOnInvalidMessage); |
7818 | Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
7819 | Expr *AssertExpr, |
7820 | Expr *AssertMessageExpr, |
7821 | SourceLocation RParenLoc); |
7822 | Decl *BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
7823 | Expr *AssertExpr, Expr *AssertMessageExpr, |
7824 | SourceLocation RParenLoc, bool Failed); |
7825 | void DiagnoseStaticAssertDetails(const Expr *E); |
7826 | |
7827 | FriendDecl *CheckFriendTypeDecl(SourceLocation LocStart, |
7828 | SourceLocation FriendLoc, |
7829 | TypeSourceInfo *TSInfo); |
7830 | Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, |
7831 | MultiTemplateParamsArg TemplateParams); |
7832 | NamedDecl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, |
7833 | MultiTemplateParamsArg TemplateParams); |
7834 | |
7835 | QualType CheckConstructorDeclarator(Declarator &D, QualType R, |
7836 | StorageClass& SC); |
7837 | void CheckConstructor(CXXConstructorDecl *Constructor); |
7838 | QualType CheckDestructorDeclarator(Declarator &D, QualType R, |
7839 | StorageClass& SC); |
7840 | bool CheckDestructor(CXXDestructorDecl *Destructor); |
7841 | void CheckConversionDeclarator(Declarator &D, QualType &R, |
7842 | StorageClass& SC); |
7843 | Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); |
7844 | bool CheckDeductionGuideDeclarator(Declarator &D, QualType &R, |
7845 | StorageClass &SC); |
7846 | void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD); |
7847 | |
7848 | void CheckExplicitlyDefaultedFunction(Scope *S, FunctionDecl *MD); |
7849 | |
7850 | bool CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD, |
7851 | CXXSpecialMember CSM, |
7852 | SourceLocation DefaultLoc); |
7853 | void CheckDelayedMemberExceptionSpecs(); |
7854 | |
7855 | bool CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *MD, |
7856 | DefaultedComparisonKind DCK); |
7857 | void DeclareImplicitEqualityComparison(CXXRecordDecl *RD, |
7858 | FunctionDecl *Spaceship); |
7859 | void DefineDefaultedComparison(SourceLocation Loc, FunctionDecl *FD, |
7860 | DefaultedComparisonKind DCK); |
7861 | |
7862 | //===--------------------------------------------------------------------===// |
7863 | // C++ Derived Classes |
7864 | // |
7865 | |
7866 | /// ActOnBaseSpecifier - Parsed a base specifier |
7867 | CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, |
7868 | SourceRange SpecifierRange, |
7869 | bool Virtual, AccessSpecifier Access, |
7870 | TypeSourceInfo *TInfo, |
7871 | SourceLocation EllipsisLoc); |
7872 | |
7873 | BaseResult ActOnBaseSpecifier(Decl *classdecl, SourceRange SpecifierRange, |
7874 | const ParsedAttributesView &Attrs, bool Virtual, |
7875 | AccessSpecifier Access, ParsedType basetype, |
7876 | SourceLocation BaseLoc, |
7877 | SourceLocation EllipsisLoc); |
7878 | |
7879 | bool AttachBaseSpecifiers(CXXRecordDecl *Class, |
7880 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
7881 | void ActOnBaseSpecifiers(Decl *ClassDecl, |
7882 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
7883 | |
7884 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base); |
7885 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base, |
7886 | CXXBasePaths &Paths); |
7887 | |
7888 | // FIXME: I don't like this name. |
7889 | void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); |
7890 | |
7891 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
7892 | SourceLocation Loc, SourceRange Range, |
7893 | CXXCastPath *BasePath = nullptr, |
7894 | bool IgnoreAccess = false); |
7895 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
7896 | unsigned InaccessibleBaseID, |
7897 | unsigned AmbiguousBaseConvID, |
7898 | SourceLocation Loc, SourceRange Range, |
7899 | DeclarationName Name, |
7900 | CXXCastPath *BasePath, |
7901 | bool IgnoreAccess = false); |
7902 | |
7903 | std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); |
7904 | |
7905 | bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New, |
7906 | const CXXMethodDecl *Old); |
7907 | |
7908 | /// CheckOverridingFunctionReturnType - Checks whether the return types are |
7909 | /// covariant, according to C++ [class.virtual]p5. |
7910 | bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, |
7911 | const CXXMethodDecl *Old); |
7912 | |
7913 | /// CheckOverridingFunctionExceptionSpec - Checks whether the exception |
7914 | /// spec is a subset of base spec. |
7915 | bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, |
7916 | const CXXMethodDecl *Old); |
7917 | |
7918 | bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); |
7919 | |
7920 | /// CheckOverrideControl - Check C++11 override control semantics. |
7921 | void CheckOverrideControl(NamedDecl *D); |
7922 | |
7923 | /// DiagnoseAbsenceOfOverrideControl - Diagnose if 'override' keyword was |
7924 | /// not used in the declaration of an overriding method. |
7925 | void DiagnoseAbsenceOfOverrideControl(NamedDecl *D, bool Inconsistent); |
7926 | |
7927 | /// CheckForFunctionMarkedFinal - Checks whether a virtual member function |
7928 | /// overrides a virtual member function marked 'final', according to |
7929 | /// C++11 [class.virtual]p4. |
7930 | bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, |
7931 | const CXXMethodDecl *Old); |
7932 | |
7933 | |
7934 | //===--------------------------------------------------------------------===// |
7935 | // C++ Access Control |
7936 | // |
7937 | |
7938 | enum AccessResult { |
7939 | AR_accessible, |
7940 | AR_inaccessible, |
7941 | AR_dependent, |
7942 | AR_delayed |
7943 | }; |
7944 | |
7945 | bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, |
7946 | NamedDecl *PrevMemberDecl, |
7947 | AccessSpecifier LexicalAS); |
7948 | |
7949 | AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, |
7950 | DeclAccessPair FoundDecl); |
7951 | AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, |
7952 | DeclAccessPair FoundDecl); |
7953 | AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, |
7954 | SourceRange PlacementRange, |
7955 | CXXRecordDecl *NamingClass, |
7956 | DeclAccessPair FoundDecl, |
7957 | bool Diagnose = true); |
7958 | AccessResult CheckConstructorAccess(SourceLocation Loc, |
7959 | CXXConstructorDecl *D, |
7960 | DeclAccessPair FoundDecl, |
7961 | const InitializedEntity &Entity, |
7962 | bool IsCopyBindingRefToTemp = false); |
7963 | AccessResult CheckConstructorAccess(SourceLocation Loc, |
7964 | CXXConstructorDecl *D, |
7965 | DeclAccessPair FoundDecl, |
7966 | const InitializedEntity &Entity, |
7967 | const PartialDiagnostic &PDiag); |
7968 | AccessResult CheckDestructorAccess(SourceLocation Loc, |
7969 | CXXDestructorDecl *Dtor, |
7970 | const PartialDiagnostic &PDiag, |
7971 | QualType objectType = QualType()); |
7972 | AccessResult CheckFriendAccess(NamedDecl *D); |
7973 | AccessResult CheckMemberAccess(SourceLocation UseLoc, |
7974 | CXXRecordDecl *NamingClass, |
7975 | DeclAccessPair Found); |
7976 | AccessResult |
7977 | CheckStructuredBindingMemberAccess(SourceLocation UseLoc, |
7978 | CXXRecordDecl *DecomposedClass, |
7979 | DeclAccessPair Field); |
7980 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, |
7981 | const SourceRange &, |
7982 | DeclAccessPair FoundDecl); |
7983 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, |
7984 | Expr *ObjectExpr, |
7985 | Expr *ArgExpr, |
7986 | DeclAccessPair FoundDecl); |
7987 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, |
7988 | ArrayRef<Expr *> ArgExprs, |
7989 | DeclAccessPair FoundDecl); |
7990 | AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, |
7991 | DeclAccessPair FoundDecl); |
7992 | AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, |
7993 | QualType Base, QualType Derived, |
7994 | const CXXBasePath &Path, |
7995 | unsigned DiagID, |
7996 | bool ForceCheck = false, |
7997 | bool ForceUnprivileged = false); |
7998 | void CheckLookupAccess(const LookupResult &R); |
7999 | bool IsSimplyAccessible(NamedDecl *Decl, CXXRecordDecl *NamingClass, |
8000 | QualType BaseType); |
8001 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
8002 | DeclAccessPair Found, QualType ObjectType, |
8003 | SourceLocation Loc, |
8004 | const PartialDiagnostic &Diag); |
8005 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
8006 | DeclAccessPair Found, |
8007 | QualType ObjectType) { |
8008 | return isMemberAccessibleForDeletion(NamingClass, Found, ObjectType, |
8009 | SourceLocation(), PDiag()); |
8010 | } |
8011 | |
8012 | void HandleDependentAccessCheck(const DependentDiagnostic &DD, |
8013 | const MultiLevelTemplateArgumentList &TemplateArgs); |
8014 | void PerformDependentDiagnostics(const DeclContext *Pattern, |
8015 | const MultiLevelTemplateArgumentList &TemplateArgs); |
8016 | |
8017 | void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
8018 | |
8019 | /// When true, access checking violations are treated as SFINAE |
8020 | /// failures rather than hard errors. |
8021 | bool AccessCheckingSFINAE; |
8022 | |
8023 | enum AbstractDiagSelID { |
8024 | AbstractNone = -1, |
8025 | AbstractReturnType, |
8026 | AbstractParamType, |
8027 | AbstractVariableType, |
8028 | AbstractFieldType, |
8029 | AbstractIvarType, |
8030 | AbstractSynthesizedIvarType, |
8031 | AbstractArrayType |
8032 | }; |
8033 | |
8034 | bool isAbstractType(SourceLocation Loc, QualType T); |
8035 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, |
8036 | TypeDiagnoser &Diagnoser); |
8037 | template <typename... Ts> |
8038 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, |
8039 | const Ts &...Args) { |
8040 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
8041 | return RequireNonAbstractType(Loc, T, Diagnoser); |
8042 | } |
8043 | |
8044 | void DiagnoseAbstractType(const CXXRecordDecl *RD); |
8045 | |
8046 | //===--------------------------------------------------------------------===// |
8047 | // C++ Overloaded Operators [C++ 13.5] |
8048 | // |
8049 | |
8050 | bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); |
8051 | |
8052 | bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); |
8053 | |
8054 | //===--------------------------------------------------------------------===// |
8055 | // C++ Templates [C++ 14] |
8056 | // |
8057 | void FilterAcceptableTemplateNames(LookupResult &R, |
8058 | bool AllowFunctionTemplates = true, |
8059 | bool AllowDependent = true); |
8060 | bool hasAnyAcceptableTemplateNames(LookupResult &R, |
8061 | bool AllowFunctionTemplates = true, |
8062 | bool AllowDependent = true, |
8063 | bool AllowNonTemplateFunctions = false); |
8064 | /// Try to interpret the lookup result D as a template-name. |
8065 | /// |
8066 | /// \param D A declaration found by name lookup. |
8067 | /// \param AllowFunctionTemplates Whether function templates should be |
8068 | /// considered valid results. |
8069 | /// \param AllowDependent Whether unresolved using declarations (that might |
8070 | /// name templates) should be considered valid results. |
8071 | static NamedDecl *getAsTemplateNameDecl(NamedDecl *D, |
8072 | bool AllowFunctionTemplates = true, |
8073 | bool AllowDependent = true); |
8074 | |
8075 | enum TemplateNameIsRequiredTag { TemplateNameIsRequired }; |
8076 | /// Whether and why a template name is required in this lookup. |
8077 | class RequiredTemplateKind { |
8078 | public: |
8079 | /// Template name is required if TemplateKWLoc is valid. |
8080 | RequiredTemplateKind(SourceLocation TemplateKWLoc = SourceLocation()) |
8081 | : TemplateKW(TemplateKWLoc) {} |
8082 | /// Template name is unconditionally required. |
8083 | RequiredTemplateKind(TemplateNameIsRequiredTag) {} |
8084 | |
8085 | SourceLocation getTemplateKeywordLoc() const { |
8086 | return TemplateKW.value_or(SourceLocation()); |
8087 | } |
8088 | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } |
8089 | bool isRequired() const { return TemplateKW != SourceLocation(); } |
8090 | explicit operator bool() const { return isRequired(); } |
8091 | |
8092 | private: |
8093 | std::optional<SourceLocation> TemplateKW; |
8094 | }; |
8095 | |
8096 | enum class AssumedTemplateKind { |
8097 | /// This is not assumed to be a template name. |
8098 | None, |
8099 | /// This is assumed to be a template name because lookup found nothing. |
8100 | FoundNothing, |
8101 | /// This is assumed to be a template name because lookup found one or more |
8102 | /// functions (but no function templates). |
8103 | FoundFunctions, |
8104 | }; |
8105 | bool LookupTemplateName( |
8106 | LookupResult &R, Scope *S, CXXScopeSpec &SS, QualType ObjectType, |
8107 | bool EnteringContext, bool &MemberOfUnknownSpecialization, |
8108 | RequiredTemplateKind RequiredTemplate = SourceLocation(), |
8109 | AssumedTemplateKind *ATK = nullptr, bool AllowTypoCorrection = true); |
8110 | |
8111 | TemplateNameKind isTemplateName(Scope *S, |
8112 | CXXScopeSpec &SS, |
8113 | bool hasTemplateKeyword, |
8114 | const UnqualifiedId &Name, |
8115 | ParsedType ObjectType, |
8116 | bool EnteringContext, |
8117 | TemplateTy &Template, |
8118 | bool &MemberOfUnknownSpecialization, |
8119 | bool Disambiguation = false); |
8120 | |
8121 | /// Try to resolve an undeclared template name as a type template. |
8122 | /// |
8123 | /// Sets II to the identifier corresponding to the template name, and updates |
8124 | /// Name to a corresponding (typo-corrected) type template name and TNK to |
8125 | /// the corresponding kind, if possible. |
8126 | void ActOnUndeclaredTypeTemplateName(Scope *S, TemplateTy &Name, |
8127 | TemplateNameKind &TNK, |
8128 | SourceLocation NameLoc, |
8129 | IdentifierInfo *&II); |
8130 | |
8131 | bool resolveAssumedTemplateNameAsType(Scope *S, TemplateName &Name, |
8132 | SourceLocation NameLoc, |
8133 | bool Diagnose = true); |
8134 | |
8135 | /// Determine whether a particular identifier might be the name in a C++1z |
8136 | /// deduction-guide declaration. |
8137 | bool isDeductionGuideName(Scope *S, const IdentifierInfo &Name, |
8138 | SourceLocation NameLoc, CXXScopeSpec &SS, |
8139 | ParsedTemplateTy *Template = nullptr); |
8140 | |
8141 | bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, |
8142 | SourceLocation IILoc, |
8143 | Scope *S, |
8144 | const CXXScopeSpec *SS, |
8145 | TemplateTy &SuggestedTemplate, |
8146 | TemplateNameKind &SuggestedKind); |
8147 | |
8148 | bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation, |
8149 | NamedDecl *Instantiation, |
8150 | bool InstantiatedFromMember, |
8151 | const NamedDecl *Pattern, |
8152 | const NamedDecl *PatternDef, |
8153 | TemplateSpecializationKind TSK, |
8154 | bool Complain = true); |
8155 | |
8156 | void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); |
8157 | TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); |
8158 | |
8159 | NamedDecl *ActOnTypeParameter(Scope *S, bool Typename, |
8160 | SourceLocation EllipsisLoc, |
8161 | SourceLocation KeyLoc, |
8162 | IdentifierInfo *ParamName, |
8163 | SourceLocation ParamNameLoc, |
8164 | unsigned Depth, unsigned Position, |
8165 | SourceLocation EqualLoc, |
8166 | ParsedType DefaultArg, bool HasTypeConstraint); |
8167 | |
8168 | bool CheckTypeConstraint(TemplateIdAnnotation *TypeConstraint); |
8169 | |
8170 | bool ActOnTypeConstraint(const CXXScopeSpec &SS, |
8171 | TemplateIdAnnotation *TypeConstraint, |
8172 | TemplateTypeParmDecl *ConstrainedParameter, |
8173 | SourceLocation EllipsisLoc); |
8174 | bool BuildTypeConstraint(const CXXScopeSpec &SS, |
8175 | TemplateIdAnnotation *TypeConstraint, |
8176 | TemplateTypeParmDecl *ConstrainedParameter, |
8177 | SourceLocation EllipsisLoc, |
8178 | bool AllowUnexpandedPack); |
8179 | |
8180 | bool AttachTypeConstraint(NestedNameSpecifierLoc NS, |
8181 | DeclarationNameInfo NameInfo, |
8182 | ConceptDecl *NamedConcept, |
8183 | const TemplateArgumentListInfo *TemplateArgs, |
8184 | TemplateTypeParmDecl *ConstrainedParameter, |
8185 | SourceLocation EllipsisLoc); |
8186 | |
8187 | bool AttachTypeConstraint(AutoTypeLoc TL, |
8188 | NonTypeTemplateParmDecl *NewConstrainedParm, |
8189 | NonTypeTemplateParmDecl *OrigConstrainedParm, |
8190 | SourceLocation EllipsisLoc); |
8191 | |
8192 | bool RequireStructuralType(QualType T, SourceLocation Loc); |
8193 | |
8194 | QualType CheckNonTypeTemplateParameterType(TypeSourceInfo *&TSI, |
8195 | SourceLocation Loc); |
8196 | QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); |
8197 | |
8198 | NamedDecl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, |
8199 | unsigned Depth, |
8200 | unsigned Position, |
8201 | SourceLocation EqualLoc, |
8202 | Expr *DefaultArg); |
8203 | NamedDecl *ActOnTemplateTemplateParameter(Scope *S, |
8204 | SourceLocation TmpLoc, |
8205 | TemplateParameterList *Params, |
8206 | SourceLocation EllipsisLoc, |
8207 | IdentifierInfo *ParamName, |
8208 | SourceLocation ParamNameLoc, |
8209 | unsigned Depth, |
8210 | unsigned Position, |
8211 | SourceLocation EqualLoc, |
8212 | ParsedTemplateArgument DefaultArg); |
8213 | |
8214 | TemplateParameterList * |
8215 | ActOnTemplateParameterList(unsigned Depth, |
8216 | SourceLocation ExportLoc, |
8217 | SourceLocation TemplateLoc, |
8218 | SourceLocation LAngleLoc, |
8219 | ArrayRef<NamedDecl *> Params, |
8220 | SourceLocation RAngleLoc, |
8221 | Expr *RequiresClause); |
8222 | |
8223 | /// The context in which we are checking a template parameter list. |
8224 | enum TemplateParamListContext { |
8225 | TPC_ClassTemplate, |
8226 | TPC_VarTemplate, |
8227 | TPC_FunctionTemplate, |
8228 | TPC_ClassTemplateMember, |
8229 | TPC_FriendClassTemplate, |
8230 | TPC_FriendFunctionTemplate, |
8231 | TPC_FriendFunctionTemplateDefinition, |
8232 | TPC_TypeAliasTemplate |
8233 | }; |
8234 | |
8235 | bool CheckTemplateParameterList(TemplateParameterList *NewParams, |
8236 | TemplateParameterList *OldParams, |
8237 | TemplateParamListContext TPC, |
8238 | SkipBodyInfo *SkipBody = nullptr); |
8239 | TemplateParameterList *MatchTemplateParametersToScopeSpecifier( |
8240 | SourceLocation DeclStartLoc, SourceLocation DeclLoc, |
8241 | const CXXScopeSpec &SS, TemplateIdAnnotation *TemplateId, |
8242 | ArrayRef<TemplateParameterList *> ParamLists, |
8243 | bool IsFriend, bool &IsMemberSpecialization, bool &Invalid, |
8244 | bool SuppressDiagnostic = false); |
8245 | |
8246 | DeclResult CheckClassTemplate( |
8247 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
8248 | CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, |
8249 | const ParsedAttributesView &Attr, TemplateParameterList *TemplateParams, |
8250 | AccessSpecifier AS, SourceLocation ModulePrivateLoc, |
8251 | SourceLocation FriendLoc, unsigned NumOuterTemplateParamLists, |
8252 | TemplateParameterList **OuterTemplateParamLists, |
8253 | SkipBodyInfo *SkipBody = nullptr); |
8254 | |
8255 | TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, |
8256 | QualType NTTPType, |
8257 | SourceLocation Loc); |
8258 | |
8259 | /// Get a template argument mapping the given template parameter to itself, |
8260 | /// e.g. for X in \c template<int X>, this would return an expression template |
8261 | /// argument referencing X. |
8262 | TemplateArgumentLoc getIdentityTemplateArgumentLoc(NamedDecl *Param, |
8263 | SourceLocation Location); |
8264 | |
8265 | void translateTemplateArguments(const ASTTemplateArgsPtr &In, |
8266 | TemplateArgumentListInfo &Out); |
8267 | |
8268 | ParsedTemplateArgument ActOnTemplateTypeArgument(TypeResult ParsedType); |
8269 | |
8270 | void NoteAllFoundTemplates(TemplateName Name); |
8271 | |
8272 | QualType CheckTemplateIdType(TemplateName Template, |
8273 | SourceLocation TemplateLoc, |
8274 | TemplateArgumentListInfo &TemplateArgs); |
8275 | |
8276 | TypeResult |
8277 | ActOnTemplateIdType(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
8278 | TemplateTy Template, IdentifierInfo *TemplateII, |
8279 | SourceLocation TemplateIILoc, SourceLocation LAngleLoc, |
8280 | ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, |
8281 | bool IsCtorOrDtorName = false, bool IsClassName = false, |
8282 | ImplicitTypenameContext AllowImplicitTypename = |
8283 | ImplicitTypenameContext::No); |
8284 | |
8285 | /// Parsed an elaborated-type-specifier that refers to a template-id, |
8286 | /// such as \c class T::template apply<U>. |
8287 | TypeResult ActOnTagTemplateIdType(TagUseKind TUK, |
8288 | TypeSpecifierType TagSpec, |
8289 | SourceLocation TagLoc, |
8290 | CXXScopeSpec &SS, |
8291 | SourceLocation TemplateKWLoc, |
8292 | TemplateTy TemplateD, |
8293 | SourceLocation TemplateLoc, |
8294 | SourceLocation LAngleLoc, |
8295 | ASTTemplateArgsPtr TemplateArgsIn, |
8296 | SourceLocation RAngleLoc); |
8297 | |
8298 | DeclResult ActOnVarTemplateSpecialization( |
8299 | Scope *S, Declarator &D, TypeSourceInfo *DI, |
8300 | SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams, |
8301 | StorageClass SC, bool IsPartialSpecialization); |
8302 | |
8303 | /// Get the specialization of the given variable template corresponding to |
8304 | /// the specified argument list, or a null-but-valid result if the arguments |
8305 | /// are dependent. |
8306 | DeclResult CheckVarTemplateId(VarTemplateDecl *Template, |
8307 | SourceLocation TemplateLoc, |
8308 | SourceLocation TemplateNameLoc, |
8309 | const TemplateArgumentListInfo &TemplateArgs); |
8310 | |
8311 | /// Form a reference to the specialization of the given variable template |
8312 | /// corresponding to the specified argument list, or a null-but-valid result |
8313 | /// if the arguments are dependent. |
8314 | ExprResult CheckVarTemplateId(const CXXScopeSpec &SS, |
8315 | const DeclarationNameInfo &NameInfo, |
8316 | VarTemplateDecl *Template, |
8317 | SourceLocation TemplateLoc, |
8318 | const TemplateArgumentListInfo *TemplateArgs); |
8319 | |
8320 | ExprResult |
8321 | CheckConceptTemplateId(const CXXScopeSpec &SS, |
8322 | SourceLocation TemplateKWLoc, |
8323 | const DeclarationNameInfo &ConceptNameInfo, |
8324 | NamedDecl *FoundDecl, ConceptDecl *NamedConcept, |
8325 | const TemplateArgumentListInfo *TemplateArgs); |
8326 | |
8327 | void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc); |
8328 | |
8329 | ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, |
8330 | SourceLocation TemplateKWLoc, |
8331 | LookupResult &R, |
8332 | bool RequiresADL, |
8333 | const TemplateArgumentListInfo *TemplateArgs); |
8334 | |
8335 | ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, |
8336 | SourceLocation TemplateKWLoc, |
8337 | const DeclarationNameInfo &NameInfo, |
8338 | const TemplateArgumentListInfo *TemplateArgs); |
8339 | |
8340 | TemplateNameKind ActOnTemplateName( |
8341 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
8342 | const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, |
8343 | TemplateTy &Template, bool AllowInjectedClassName = false); |
8344 | |
8345 | DeclResult ActOnClassTemplateSpecialization( |
8346 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
8347 | SourceLocation ModulePrivateLoc, CXXScopeSpec &SS, |
8348 | TemplateIdAnnotation &TemplateId, const ParsedAttributesView &Attr, |
8349 | MultiTemplateParamsArg TemplateParameterLists, |
8350 | SkipBodyInfo *SkipBody = nullptr); |
8351 | |
8352 | bool CheckTemplatePartialSpecializationArgs(SourceLocation Loc, |
8353 | TemplateDecl *PrimaryTemplate, |
8354 | unsigned NumExplicitArgs, |
8355 | ArrayRef<TemplateArgument> Args); |
8356 | void CheckTemplatePartialSpecialization( |
8357 | ClassTemplatePartialSpecializationDecl *Partial); |
8358 | void CheckTemplatePartialSpecialization( |
8359 | VarTemplatePartialSpecializationDecl *Partial); |
8360 | |
8361 | Decl *ActOnTemplateDeclarator(Scope *S, |
8362 | MultiTemplateParamsArg TemplateParameterLists, |
8363 | Declarator &D); |
8364 | |
8365 | bool |
8366 | CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, |
8367 | TemplateSpecializationKind NewTSK, |
8368 | NamedDecl *PrevDecl, |
8369 | TemplateSpecializationKind PrevTSK, |
8370 | SourceLocation PrevPtOfInstantiation, |
8371 | bool &SuppressNew); |
8372 | |
8373 | bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, |
8374 | const TemplateArgumentListInfo &ExplicitTemplateArgs, |
8375 | LookupResult &Previous); |
8376 | |
8377 | bool CheckFunctionTemplateSpecialization( |
8378 | FunctionDecl *FD, TemplateArgumentListInfo *ExplicitTemplateArgs, |
8379 | LookupResult &Previous, bool QualifiedFriend = false); |
8380 | bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
8381 | void CompleteMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
8382 | |
8383 | DeclResult ActOnExplicitInstantiation( |
8384 | Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc, |
8385 | unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS, |
8386 | TemplateTy Template, SourceLocation TemplateNameLoc, |
8387 | SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, |
8388 | SourceLocation RAngleLoc, const ParsedAttributesView &Attr); |
8389 | |
8390 | DeclResult ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, |
8391 | SourceLocation TemplateLoc, |
8392 | unsigned TagSpec, SourceLocation KWLoc, |
8393 | CXXScopeSpec &SS, IdentifierInfo *Name, |
8394 | SourceLocation NameLoc, |
8395 | const ParsedAttributesView &Attr); |
8396 | |
8397 | DeclResult ActOnExplicitInstantiation(Scope *S, |
8398 | SourceLocation ExternLoc, |
8399 | SourceLocation TemplateLoc, |
8400 | Declarator &D); |
8401 | |
8402 | TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable( |
8403 | TemplateDecl *Template, SourceLocation TemplateLoc, |
8404 | SourceLocation RAngleLoc, Decl *Param, |
8405 | ArrayRef<TemplateArgument> SugaredConverted, |
8406 | ArrayRef<TemplateArgument> CanonicalConverted, bool &HasDefaultArg); |
8407 | |
8408 | /// Specifies the context in which a particular template |
8409 | /// argument is being checked. |
8410 | enum CheckTemplateArgumentKind { |
8411 | /// The template argument was specified in the code or was |
8412 | /// instantiated with some deduced template arguments. |
8413 | CTAK_Specified, |
8414 | |
8415 | /// The template argument was deduced via template argument |
8416 | /// deduction. |
8417 | CTAK_Deduced, |
8418 | |
8419 | /// The template argument was deduced from an array bound |
8420 | /// via template argument deduction. |
8421 | CTAK_DeducedFromArrayBound |
8422 | }; |
8423 | |
8424 | bool |
8425 | CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, |
8426 | NamedDecl *Template, SourceLocation TemplateLoc, |
8427 | SourceLocation RAngleLoc, unsigned ArgumentPackIndex, |
8428 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
8429 | SmallVectorImpl<TemplateArgument> &CanonicalConverted, |
8430 | CheckTemplateArgumentKind CTAK); |
8431 | |
8432 | /// Check that the given template arguments can be provided to |
8433 | /// the given template, converting the arguments along the way. |
8434 | /// |
8435 | /// \param Template The template to which the template arguments are being |
8436 | /// provided. |
8437 | /// |
8438 | /// \param TemplateLoc The location of the template name in the source. |
8439 | /// |
8440 | /// \param TemplateArgs The list of template arguments. If the template is |
8441 | /// a template template parameter, this function may extend the set of |
8442 | /// template arguments to also include substituted, defaulted template |
8443 | /// arguments. |
8444 | /// |
8445 | /// \param PartialTemplateArgs True if the list of template arguments is |
8446 | /// intentionally partial, e.g., because we're checking just the initial |
8447 | /// set of template arguments. |
8448 | /// |
8449 | /// \param Converted Will receive the converted, canonicalized template |
8450 | /// arguments. |
8451 | /// |
8452 | /// \param UpdateArgsWithConversions If \c true, update \p TemplateArgs to |
8453 | /// contain the converted forms of the template arguments as written. |
8454 | /// Otherwise, \p TemplateArgs will not be modified. |
8455 | /// |
8456 | /// \param ConstraintsNotSatisfied If provided, and an error occurred, will |
8457 | /// receive true if the cause for the error is the associated constraints of |
8458 | /// the template not being satisfied by the template arguments. |
8459 | /// |
8460 | /// \returns true if an error occurred, false otherwise. |
8461 | bool CheckTemplateArgumentList( |
8462 | TemplateDecl *Template, SourceLocation TemplateLoc, |
8463 | TemplateArgumentListInfo &TemplateArgs, bool PartialTemplateArgs, |
8464 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
8465 | SmallVectorImpl<TemplateArgument> &CanonicalConverted, |
8466 | bool UpdateArgsWithConversions = true, |
8467 | bool *ConstraintsNotSatisfied = nullptr); |
8468 | |
8469 | bool CheckTemplateTypeArgument( |
8470 | TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg, |
8471 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
8472 | SmallVectorImpl<TemplateArgument> &CanonicalConverted); |
8473 | |
8474 | bool CheckTemplateArgument(TypeSourceInfo *Arg); |
8475 | ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, |
8476 | QualType InstantiatedParamType, Expr *Arg, |
8477 | TemplateArgument &SugaredConverted, |
8478 | TemplateArgument &CanonicalConverted, |
8479 | CheckTemplateArgumentKind CTAK); |
8480 | bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, |
8481 | TemplateParameterList *Params, |
8482 | TemplateArgumentLoc &Arg); |
8483 | |
8484 | ExprResult |
8485 | BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, |
8486 | QualType ParamType, |
8487 | SourceLocation Loc); |
8488 | ExprResult |
8489 | BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, |
8490 | SourceLocation Loc); |
8491 | |
8492 | /// Enumeration describing how template parameter lists are compared |
8493 | /// for equality. |
8494 | enum TemplateParameterListEqualKind { |
8495 | /// We are matching the template parameter lists of two templates |
8496 | /// that might be redeclarations. |
8497 | /// |
8498 | /// \code |
8499 | /// template<typename T> struct X; |
8500 | /// template<typename T> struct X; |
8501 | /// \endcode |
8502 | TPL_TemplateMatch, |
8503 | |
8504 | /// We are matching the template parameter lists of two template |
8505 | /// template parameters as part of matching the template parameter lists |
8506 | /// of two templates that might be redeclarations. |
8507 | /// |
8508 | /// \code |
8509 | /// template<template<int I> class TT> struct X; |
8510 | /// template<template<int Value> class Other> struct X; |
8511 | /// \endcode |
8512 | TPL_TemplateTemplateParmMatch, |
8513 | |
8514 | /// We are matching the template parameter lists of a template |
8515 | /// template argument against the template parameter lists of a template |
8516 | /// template parameter. |
8517 | /// |
8518 | /// \code |
8519 | /// template<template<int Value> class Metafun> struct X; |
8520 | /// template<int Value> struct integer_c; |
8521 | /// X<integer_c> xic; |
8522 | /// \endcode |
8523 | TPL_TemplateTemplateArgumentMatch, |
8524 | |
8525 | /// We are determining whether the template-parameters are equivalent |
8526 | /// according to C++ [temp.over.link]/6. This comparison does not consider |
8527 | /// constraints. |
8528 | /// |
8529 | /// \code |
8530 | /// template<C1 T> void f(T); |
8531 | /// template<C2 T> void f(T); |
8532 | /// \endcode |
8533 | TPL_TemplateParamsEquivalent, |
8534 | }; |
8535 | |
8536 | bool TemplateParameterListsAreEqual( |
8537 | const NamedDecl *NewInstFrom, TemplateParameterList *New, |
8538 | const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain, |
8539 | TemplateParameterListEqualKind Kind, |
8540 | SourceLocation TemplateArgLoc = SourceLocation()); |
8541 | |
8542 | bool TemplateParameterListsAreEqual( |
8543 | TemplateParameterList *New, TemplateParameterList *Old, bool Complain, |
8544 | TemplateParameterListEqualKind Kind, |
8545 | SourceLocation TemplateArgLoc = SourceLocation()) { |
8546 | return TemplateParameterListsAreEqual(nullptr, New, nullptr, Old, Complain, |
8547 | Kind, TemplateArgLoc); |
8548 | } |
8549 | |
8550 | bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); |
8551 | |
8552 | /// Called when the parser has parsed a C++ typename |
8553 | /// specifier, e.g., "typename T::type". |
8554 | /// |
8555 | /// \param S The scope in which this typename type occurs. |
8556 | /// \param TypenameLoc the location of the 'typename' keyword |
8557 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
8558 | /// \param II the identifier we're retrieving (e.g., 'type' in the example). |
8559 | /// \param IdLoc the location of the identifier. |
8560 | /// \param IsImplicitTypename context where T::type refers to a type. |
8561 | TypeResult ActOnTypenameType( |
8562 | Scope *S, SourceLocation TypenameLoc, const CXXScopeSpec &SS, |
8563 | const IdentifierInfo &II, SourceLocation IdLoc, |
8564 | ImplicitTypenameContext IsImplicitTypename = ImplicitTypenameContext::No); |
8565 | |
8566 | /// Called when the parser has parsed a C++ typename |
8567 | /// specifier that ends in a template-id, e.g., |
8568 | /// "typename MetaFun::template apply<T1, T2>". |
8569 | /// |
8570 | /// \param S The scope in which this typename type occurs. |
8571 | /// \param TypenameLoc the location of the 'typename' keyword |
8572 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
8573 | /// \param TemplateLoc the location of the 'template' keyword, if any. |
8574 | /// \param TemplateName The template name. |
8575 | /// \param TemplateII The identifier used to name the template. |
8576 | /// \param TemplateIILoc The location of the template name. |
8577 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
8578 | /// \param TemplateArgs The template arguments. |
8579 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
8580 | TypeResult |
8581 | ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, |
8582 | const CXXScopeSpec &SS, |
8583 | SourceLocation TemplateLoc, |
8584 | TemplateTy TemplateName, |
8585 | IdentifierInfo *TemplateII, |
8586 | SourceLocation TemplateIILoc, |
8587 | SourceLocation LAngleLoc, |
8588 | ASTTemplateArgsPtr TemplateArgs, |
8589 | SourceLocation RAngleLoc); |
8590 | |
8591 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
8592 | SourceLocation KeywordLoc, |
8593 | NestedNameSpecifierLoc QualifierLoc, |
8594 | const IdentifierInfo &II, |
8595 | SourceLocation IILoc, |
8596 | TypeSourceInfo **TSI, |
8597 | bool DeducedTSTContext); |
8598 | |
8599 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
8600 | SourceLocation KeywordLoc, |
8601 | NestedNameSpecifierLoc QualifierLoc, |
8602 | const IdentifierInfo &II, |
8603 | SourceLocation IILoc, |
8604 | bool DeducedTSTContext = true); |
8605 | |
8606 | |
8607 | TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, |
8608 | SourceLocation Loc, |
8609 | DeclarationName Name); |
8610 | bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); |
8611 | |
8612 | ExprResult RebuildExprInCurrentInstantiation(Expr *E); |
8613 | bool RebuildTemplateParamsInCurrentInstantiation( |
8614 | TemplateParameterList *Params); |
8615 | |
8616 | std::string |
8617 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
8618 | const TemplateArgumentList &Args); |
8619 | |
8620 | std::string |
8621 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
8622 | const TemplateArgument *Args, |
8623 | unsigned NumArgs); |
8624 | |
8625 | //===--------------------------------------------------------------------===// |
8626 | // C++ Concepts |
8627 | //===--------------------------------------------------------------------===// |
8628 | Decl *ActOnConceptDefinition( |
8629 | Scope *S, MultiTemplateParamsArg TemplateParameterLists, |
8630 | IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr); |
8631 | |
8632 | void CheckConceptRedefinition(ConceptDecl *NewDecl, LookupResult &Previous, |
8633 | bool &AddToScope); |
8634 | |
8635 | RequiresExprBodyDecl * |
8636 | ActOnStartRequiresExpr(SourceLocation RequiresKWLoc, |
8637 | ArrayRef<ParmVarDecl *> LocalParameters, |
8638 | Scope *BodyScope); |
8639 | void ActOnFinishRequiresExpr(); |
8640 | concepts::Requirement *ActOnSimpleRequirement(Expr *E); |
8641 | concepts::Requirement *ActOnTypeRequirement( |
8642 | SourceLocation TypenameKWLoc, CXXScopeSpec &SS, SourceLocation NameLoc, |
8643 | IdentifierInfo *TypeName, TemplateIdAnnotation *TemplateId); |
8644 | concepts::Requirement *ActOnCompoundRequirement(Expr *E, |
8645 | SourceLocation NoexceptLoc); |
8646 | concepts::Requirement * |
8647 | ActOnCompoundRequirement( |
8648 | Expr *E, SourceLocation NoexceptLoc, CXXScopeSpec &SS, |
8649 | TemplateIdAnnotation *TypeConstraint, unsigned Depth); |
8650 | concepts::Requirement *ActOnNestedRequirement(Expr *Constraint); |
8651 | concepts::ExprRequirement * |
8652 | BuildExprRequirement( |
8653 | Expr *E, bool IsSatisfied, SourceLocation NoexceptLoc, |
8654 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
8655 | concepts::ExprRequirement * |
8656 | BuildExprRequirement( |
8657 | concepts::Requirement::SubstitutionDiagnostic *ExprSubstDiag, |
8658 | bool IsSatisfied, SourceLocation NoexceptLoc, |
8659 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
8660 | concepts::TypeRequirement *BuildTypeRequirement(TypeSourceInfo *Type); |
8661 | concepts::TypeRequirement * |
8662 | BuildTypeRequirement( |
8663 | concepts::Requirement::SubstitutionDiagnostic *SubstDiag); |
8664 | concepts::NestedRequirement *BuildNestedRequirement(Expr *E); |
8665 | concepts::NestedRequirement * |
8666 | BuildNestedRequirement(StringRef InvalidConstraintEntity, |
8667 | const ASTConstraintSatisfaction &Satisfaction); |
8668 | ExprResult ActOnRequiresExpr(SourceLocation RequiresKWLoc, |
8669 | RequiresExprBodyDecl *Body, |
8670 | ArrayRef<ParmVarDecl *> LocalParameters, |
8671 | ArrayRef<concepts::Requirement *> Requirements, |
8672 | SourceLocation ClosingBraceLoc); |
8673 | |
8674 | //===--------------------------------------------------------------------===// |
8675 | // C++ Variadic Templates (C++0x [temp.variadic]) |
8676 | //===--------------------------------------------------------------------===// |
8677 | |
8678 | /// Determine whether an unexpanded parameter pack might be permitted in this |
8679 | /// location. Useful for error recovery. |
8680 | bool isUnexpandedParameterPackPermitted(); |
8681 | |
8682 | /// The context in which an unexpanded parameter pack is |
8683 | /// being diagnosed. |
8684 | /// |
8685 | /// Note that the values of this enumeration line up with the first |
8686 | /// argument to the \c err_unexpanded_parameter_pack diagnostic. |
8687 | enum UnexpandedParameterPackContext { |
8688 | /// An arbitrary expression. |
8689 | UPPC_Expression = 0, |
8690 | |
8691 | /// The base type of a class type. |
8692 | UPPC_BaseType, |
8693 | |
8694 | /// The type of an arbitrary declaration. |
8695 | UPPC_DeclarationType, |
8696 | |
8697 | /// The type of a data member. |
8698 | UPPC_DataMemberType, |
8699 | |
8700 | /// The size of a bit-field. |
8701 | UPPC_BitFieldWidth, |
8702 | |
8703 | /// The expression in a static assertion. |
8704 | UPPC_StaticAssertExpression, |
8705 | |
8706 | /// The fixed underlying type of an enumeration. |
8707 | UPPC_FixedUnderlyingType, |
8708 | |
8709 | /// The enumerator value. |
8710 | UPPC_EnumeratorValue, |
8711 | |
8712 | /// A using declaration. |
8713 | UPPC_UsingDeclaration, |
8714 | |
8715 | /// A friend declaration. |
8716 | UPPC_FriendDeclaration, |
8717 | |
8718 | /// A declaration qualifier. |
8719 | UPPC_DeclarationQualifier, |
8720 | |
8721 | /// An initializer. |
8722 | UPPC_Initializer, |
8723 | |
8724 | /// A default argument. |
8725 | UPPC_DefaultArgument, |
8726 | |
8727 | /// The type of a non-type template parameter. |
8728 | UPPC_NonTypeTemplateParameterType, |
8729 | |
8730 | /// The type of an exception. |
8731 | UPPC_ExceptionType, |
8732 | |
8733 | /// Partial specialization. |
8734 | UPPC_PartialSpecialization, |
8735 | |
8736 | /// Microsoft __if_exists. |
8737 | UPPC_IfExists, |
8738 | |
8739 | /// Microsoft __if_not_exists. |
8740 | UPPC_IfNotExists, |
8741 | |
8742 | /// Lambda expression. |
8743 | UPPC_Lambda, |
8744 | |
8745 | /// Block expression. |
8746 | UPPC_Block, |
8747 | |
8748 | /// A type constraint. |
8749 | UPPC_TypeConstraint, |
8750 | |
8751 | // A requirement in a requires-expression. |
8752 | UPPC_Requirement, |
8753 | |
8754 | // A requires-clause. |
8755 | UPPC_RequiresClause, |
8756 | }; |
8757 | |
8758 | /// Diagnose unexpanded parameter packs. |
8759 | /// |
8760 | /// \param Loc The location at which we should emit the diagnostic. |
8761 | /// |
8762 | /// \param UPPC The context in which we are diagnosing unexpanded |
8763 | /// parameter packs. |
8764 | /// |
8765 | /// \param Unexpanded the set of unexpanded parameter packs. |
8766 | /// |
8767 | /// \returns true if an error occurred, false otherwise. |
8768 | bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc, |
8769 | UnexpandedParameterPackContext UPPC, |
8770 | ArrayRef<UnexpandedParameterPack> Unexpanded); |
8771 | |
8772 | /// If the given type contains an unexpanded parameter pack, |
8773 | /// diagnose the error. |
8774 | /// |
8775 | /// \param Loc The source location where a diagnostc should be emitted. |
8776 | /// |
8777 | /// \param T The type that is being checked for unexpanded parameter |
8778 | /// packs. |
8779 | /// |
8780 | /// \returns true if an error occurred, false otherwise. |
8781 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, |
8782 | UnexpandedParameterPackContext UPPC); |
8783 | |
8784 | /// If the given expression contains an unexpanded parameter |
8785 | /// pack, diagnose the error. |
8786 | /// |
8787 | /// \param E The expression that is being checked for unexpanded |
8788 | /// parameter packs. |
8789 | /// |
8790 | /// \returns true if an error occurred, false otherwise. |
8791 | bool DiagnoseUnexpandedParameterPack(Expr *E, |
8792 | UnexpandedParameterPackContext UPPC = UPPC_Expression); |
8793 | |
8794 | /// If the given requirees-expression contains an unexpanded reference to one |
8795 | /// of its own parameter packs, diagnose the error. |
8796 | /// |
8797 | /// \param RE The requiress-expression that is being checked for unexpanded |
8798 | /// parameter packs. |
8799 | /// |
8800 | /// \returns true if an error occurred, false otherwise. |
8801 | bool DiagnoseUnexpandedParameterPackInRequiresExpr(RequiresExpr *RE); |
8802 | |
8803 | /// If the given nested-name-specifier contains an unexpanded |
8804 | /// parameter pack, diagnose the error. |
8805 | /// |
8806 | /// \param SS The nested-name-specifier that is being checked for |
8807 | /// unexpanded parameter packs. |
8808 | /// |
8809 | /// \returns true if an error occurred, false otherwise. |
8810 | bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, |
8811 | UnexpandedParameterPackContext UPPC); |
8812 | |
8813 | /// If the given name contains an unexpanded parameter pack, |
8814 | /// diagnose the error. |
8815 | /// |
8816 | /// \param NameInfo The name (with source location information) that |
8817 | /// is being checked for unexpanded parameter packs. |
8818 | /// |
8819 | /// \returns true if an error occurred, false otherwise. |
8820 | bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, |
8821 | UnexpandedParameterPackContext UPPC); |
8822 | |
8823 | /// If the given template name contains an unexpanded parameter pack, |
8824 | /// diagnose the error. |
8825 | /// |
8826 | /// \param Loc The location of the template name. |
8827 | /// |
8828 | /// \param Template The template name that is being checked for unexpanded |
8829 | /// parameter packs. |
8830 | /// |
8831 | /// \returns true if an error occurred, false otherwise. |
8832 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, |
8833 | TemplateName Template, |
8834 | UnexpandedParameterPackContext UPPC); |
8835 | |
8836 | /// If the given template argument contains an unexpanded parameter |
8837 | /// pack, diagnose the error. |
8838 | /// |
8839 | /// \param Arg The template argument that is being checked for unexpanded |
8840 | /// parameter packs. |
8841 | /// |
8842 | /// \returns true if an error occurred, false otherwise. |
8843 | bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, |
8844 | UnexpandedParameterPackContext UPPC); |
8845 | |
8846 | /// Collect the set of unexpanded parameter packs within the given |
8847 | /// template argument. |
8848 | /// |
8849 | /// \param Arg The template argument that will be traversed to find |
8850 | /// unexpanded parameter packs. |
8851 | void collectUnexpandedParameterPacks(TemplateArgument Arg, |
8852 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
8853 | |
8854 | /// Collect the set of unexpanded parameter packs within the given |
8855 | /// template argument. |
8856 | /// |
8857 | /// \param Arg The template argument that will be traversed to find |
8858 | /// unexpanded parameter packs. |
8859 | void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, |
8860 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
8861 | |
8862 | /// Collect the set of unexpanded parameter packs within the given |
8863 | /// type. |
8864 | /// |
8865 | /// \param T The type that will be traversed to find |
8866 | /// unexpanded parameter packs. |
8867 | void collectUnexpandedParameterPacks(QualType T, |
8868 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
8869 | |
8870 | /// Collect the set of unexpanded parameter packs within the given |
8871 | /// type. |
8872 | /// |
8873 | /// \param TL The type that will be traversed to find |
8874 | /// unexpanded parameter packs. |
8875 | void collectUnexpandedParameterPacks(TypeLoc TL, |
8876 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
8877 | |
8878 | /// Collect the set of unexpanded parameter packs within the given |
8879 | /// nested-name-specifier. |
8880 | /// |
8881 | /// \param NNS The nested-name-specifier that will be traversed to find |
8882 | /// unexpanded parameter packs. |
8883 | void collectUnexpandedParameterPacks(NestedNameSpecifierLoc NNS, |
8884 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
8885 | |
8886 | /// Collect the set of unexpanded parameter packs within the given |
8887 | /// name. |
8888 | /// |
8889 | /// \param NameInfo The name that will be traversed to find |
8890 | /// unexpanded parameter packs. |
8891 | void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo, |
8892 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
8893 | |
8894 | /// Invoked when parsing a template argument followed by an |
8895 | /// ellipsis, which creates a pack expansion. |
8896 | /// |
8897 | /// \param Arg The template argument preceding the ellipsis, which |
8898 | /// may already be invalid. |
8899 | /// |
8900 | /// \param EllipsisLoc The location of the ellipsis. |
8901 | ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, |
8902 | SourceLocation EllipsisLoc); |
8903 | |
8904 | /// Invoked when parsing a type followed by an ellipsis, which |
8905 | /// creates a pack expansion. |
8906 | /// |
8907 | /// \param Type The type preceding the ellipsis, which will become |
8908 | /// the pattern of the pack expansion. |
8909 | /// |
8910 | /// \param EllipsisLoc The location of the ellipsis. |
8911 | TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); |
8912 | |
8913 | /// Construct a pack expansion type from the pattern of the pack |
8914 | /// expansion. |
8915 | TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, |
8916 | SourceLocation EllipsisLoc, |
8917 | std::optional<unsigned> NumExpansions); |
8918 | |
8919 | /// Construct a pack expansion type from the pattern of the pack |
8920 | /// expansion. |
8921 | QualType CheckPackExpansion(QualType Pattern, SourceRange PatternRange, |
8922 | SourceLocation EllipsisLoc, |
8923 | std::optional<unsigned> NumExpansions); |
8924 | |
8925 | /// Invoked when parsing an expression followed by an ellipsis, which |
8926 | /// creates a pack expansion. |
8927 | /// |
8928 | /// \param Pattern The expression preceding the ellipsis, which will become |
8929 | /// the pattern of the pack expansion. |
8930 | /// |
8931 | /// \param EllipsisLoc The location of the ellipsis. |
8932 | ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); |
8933 | |
8934 | /// Invoked when parsing an expression followed by an ellipsis, which |
8935 | /// creates a pack expansion. |
8936 | /// |
8937 | /// \param Pattern The expression preceding the ellipsis, which will become |
8938 | /// the pattern of the pack expansion. |
8939 | /// |
8940 | /// \param EllipsisLoc The location of the ellipsis. |
8941 | ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
8942 | std::optional<unsigned> NumExpansions); |
8943 | |
8944 | /// Determine whether we could expand a pack expansion with the |
8945 | /// given set of parameter packs into separate arguments by repeatedly |
8946 | /// transforming the pattern. |
8947 | /// |
8948 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
8949 | /// pack expansion. |
8950 | /// |
8951 | /// \param PatternRange The source range that covers the entire pattern of |
8952 | /// the pack expansion. |
8953 | /// |
8954 | /// \param Unexpanded The set of unexpanded parameter packs within the |
8955 | /// pattern. |
8956 | /// |
8957 | /// \param ShouldExpand Will be set to \c true if the transformer should |
8958 | /// expand the corresponding pack expansions into separate arguments. When |
8959 | /// set, \c NumExpansions must also be set. |
8960 | /// |
8961 | /// \param RetainExpansion Whether the caller should add an unexpanded |
8962 | /// pack expansion after all of the expanded arguments. This is used |
8963 | /// when extending explicitly-specified template argument packs per |
8964 | /// C++0x [temp.arg.explicit]p9. |
8965 | /// |
8966 | /// \param NumExpansions The number of separate arguments that will be in |
8967 | /// the expanded form of the corresponding pack expansion. This is both an |
8968 | /// input and an output parameter, which can be set by the caller if the |
8969 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
8970 | /// and will be set by the callee when the number of expansions is known. |
8971 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
8972 | /// set this value in other cases. |
8973 | /// |
8974 | /// \returns true if an error occurred (e.g., because the parameter packs |
8975 | /// are to be instantiated with arguments of different lengths), false |
8976 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
8977 | /// must be set. |
8978 | bool CheckParameterPacksForExpansion( |
8979 | SourceLocation EllipsisLoc, SourceRange PatternRange, |
8980 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
8981 | const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand, |
8982 | bool &RetainExpansion, std::optional<unsigned> &NumExpansions); |
8983 | |
8984 | /// Determine the number of arguments in the given pack expansion |
8985 | /// type. |
8986 | /// |
8987 | /// This routine assumes that the number of arguments in the expansion is |
8988 | /// consistent across all of the unexpanded parameter packs in its pattern. |
8989 | /// |
8990 | /// Returns an empty Optional if the type can't be expanded. |
8991 | std::optional<unsigned> getNumArgumentsInExpansion( |
8992 | QualType T, const MultiLevelTemplateArgumentList &TemplateArgs); |
8993 | |
8994 | /// Determine whether the given declarator contains any unexpanded |
8995 | /// parameter packs. |
8996 | /// |
8997 | /// This routine is used by the parser to disambiguate function declarators |
8998 | /// with an ellipsis prior to the ')', e.g., |
8999 | /// |
9000 | /// \code |
9001 | /// void f(T...); |
9002 | /// \endcode |
9003 | /// |
9004 | /// To determine whether we have an (unnamed) function parameter pack or |
9005 | /// a variadic function. |
9006 | /// |
9007 | /// \returns true if the declarator contains any unexpanded parameter packs, |
9008 | /// false otherwise. |
9009 | bool containsUnexpandedParameterPacks(Declarator &D); |
9010 | |
9011 | /// Returns the pattern of the pack expansion for a template argument. |
9012 | /// |
9013 | /// \param OrigLoc The template argument to expand. |
9014 | /// |
9015 | /// \param Ellipsis Will be set to the location of the ellipsis. |
9016 | /// |
9017 | /// \param NumExpansions Will be set to the number of expansions that will |
9018 | /// be generated from this pack expansion, if known a priori. |
9019 | TemplateArgumentLoc getTemplateArgumentPackExpansionPattern( |
9020 | TemplateArgumentLoc OrigLoc, SourceLocation &Ellipsis, |
9021 | std::optional<unsigned> &NumExpansions) const; |
9022 | |
9023 | /// Given a template argument that contains an unexpanded parameter pack, but |
9024 | /// which has already been substituted, attempt to determine the number of |
9025 | /// elements that will be produced once this argument is fully-expanded. |
9026 | /// |
9027 | /// This is intended for use when transforming 'sizeof...(Arg)' in order to |
9028 | /// avoid actually expanding the pack where possible. |
9029 | std::optional<unsigned> getFullyPackExpandedSize(TemplateArgument Arg); |
9030 | |
9031 | //===--------------------------------------------------------------------===// |
9032 | // C++ Template Argument Deduction (C++ [temp.deduct]) |
9033 | //===--------------------------------------------------------------------===// |
9034 | |
9035 | /// Adjust the type \p ArgFunctionType to match the calling convention, |
9036 | /// noreturn, and optionally the exception specification of \p FunctionType. |
9037 | /// Deduction often wants to ignore these properties when matching function |
9038 | /// types. |
9039 | QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType, |
9040 | bool AdjustExceptionSpec = false); |
9041 | |
9042 | /// Describes the result of template argument deduction. |
9043 | /// |
9044 | /// The TemplateDeductionResult enumeration describes the result of |
9045 | /// template argument deduction, as returned from |
9046 | /// DeduceTemplateArguments(). The separate TemplateDeductionInfo |
9047 | /// structure provides additional information about the results of |
9048 | /// template argument deduction, e.g., the deduced template argument |
9049 | /// list (if successful) or the specific template parameters or |
9050 | /// deduced arguments that were involved in the failure. |
9051 | enum TemplateDeductionResult { |
9052 | /// Template argument deduction was successful. |
9053 | TDK_Success = 0, |
9054 | /// The declaration was invalid; do nothing. |
9055 | TDK_Invalid, |
9056 | /// Template argument deduction exceeded the maximum template |
9057 | /// instantiation depth (which has already been diagnosed). |
9058 | TDK_InstantiationDepth, |
9059 | /// Template argument deduction did not deduce a value |
9060 | /// for every template parameter. |
9061 | TDK_Incomplete, |
9062 | /// Template argument deduction did not deduce a value for every |
9063 | /// expansion of an expanded template parameter pack. |
9064 | TDK_IncompletePack, |
9065 | /// Template argument deduction produced inconsistent |
9066 | /// deduced values for the given template parameter. |
9067 | TDK_Inconsistent, |
9068 | /// Template argument deduction failed due to inconsistent |
9069 | /// cv-qualifiers on a template parameter type that would |
9070 | /// otherwise be deduced, e.g., we tried to deduce T in "const T" |
9071 | /// but were given a non-const "X". |
9072 | TDK_Underqualified, |
9073 | /// Substitution of the deduced template argument values |
9074 | /// resulted in an error. |
9075 | TDK_SubstitutionFailure, |
9076 | /// After substituting deduced template arguments, a dependent |
9077 | /// parameter type did not match the corresponding argument. |
9078 | TDK_DeducedMismatch, |
9079 | /// After substituting deduced template arguments, an element of |
9080 | /// a dependent parameter type did not match the corresponding element |
9081 | /// of the corresponding argument (when deducing from an initializer list). |
9082 | TDK_DeducedMismatchNested, |
9083 | /// A non-depnedent component of the parameter did not match the |
9084 | /// corresponding component of the argument. |
9085 | TDK_NonDeducedMismatch, |
9086 | /// When performing template argument deduction for a function |
9087 | /// template, there were too many call arguments. |
9088 | TDK_TooManyArguments, |
9089 | /// When performing template argument deduction for a function |
9090 | /// template, there were too few call arguments. |
9091 | TDK_TooFewArguments, |
9092 | /// The explicitly-specified template arguments were not valid |
9093 | /// template arguments for the given template. |
9094 | TDK_InvalidExplicitArguments, |
9095 | /// Checking non-dependent argument conversions failed. |
9096 | TDK_NonDependentConversionFailure, |
9097 | /// The deduced arguments did not satisfy the constraints associated |
9098 | /// with the template. |
9099 | TDK_ConstraintsNotSatisfied, |
9100 | /// Deduction failed; that's all we know. |
9101 | TDK_MiscellaneousDeductionFailure, |
9102 | /// CUDA Target attributes do not match. |
9103 | TDK_CUDATargetMismatch, |
9104 | /// Some error which was already diagnosed. |
9105 | TDK_AlreadyDiagnosed |
9106 | }; |
9107 | |
9108 | TemplateDeductionResult |
9109 | DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, |
9110 | const TemplateArgumentList &TemplateArgs, |
9111 | sema::TemplateDeductionInfo &Info); |
9112 | |
9113 | TemplateDeductionResult |
9114 | DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, |
9115 | const TemplateArgumentList &TemplateArgs, |
9116 | sema::TemplateDeductionInfo &Info); |
9117 | |
9118 | TemplateDeductionResult SubstituteExplicitTemplateArguments( |
9119 | FunctionTemplateDecl *FunctionTemplate, |
9120 | TemplateArgumentListInfo &ExplicitTemplateArgs, |
9121 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
9122 | SmallVectorImpl<QualType> &ParamTypes, QualType *FunctionType, |
9123 | sema::TemplateDeductionInfo &Info); |
9124 | |
9125 | /// brief A function argument from which we performed template argument |
9126 | // deduction for a call. |
9127 | struct OriginalCallArg { |
9128 | OriginalCallArg(QualType OriginalParamType, bool DecomposedParam, |
9129 | unsigned ArgIdx, QualType OriginalArgType) |
9130 | : OriginalParamType(OriginalParamType), |
9131 | DecomposedParam(DecomposedParam), ArgIdx(ArgIdx), |
9132 | OriginalArgType(OriginalArgType) {} |
9133 | |
9134 | QualType OriginalParamType; |
9135 | bool DecomposedParam; |
9136 | unsigned ArgIdx; |
9137 | QualType OriginalArgType; |
9138 | }; |
9139 | |
9140 | TemplateDeductionResult FinishTemplateArgumentDeduction( |
9141 | FunctionTemplateDecl *FunctionTemplate, |
9142 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
9143 | unsigned NumExplicitlySpecified, FunctionDecl *&Specialization, |
9144 | sema::TemplateDeductionInfo &Info, |
9145 | SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = nullptr, |
9146 | bool PartialOverloading = false, |
9147 | llvm::function_ref<bool()> CheckNonDependent = []{ return false; }); |
9148 | |
9149 | TemplateDeductionResult DeduceTemplateArguments( |
9150 | FunctionTemplateDecl *FunctionTemplate, |
9151 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
9152 | FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, |
9153 | bool PartialOverloading, bool AggregateDeductionCandidate, |
9154 | llvm::function_ref<bool(ArrayRef<QualType>)> CheckNonDependent); |
9155 | |
9156 | TemplateDeductionResult |
9157 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
9158 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
9159 | QualType ArgFunctionType, |
9160 | FunctionDecl *&Specialization, |
9161 | sema::TemplateDeductionInfo &Info, |
9162 | bool IsAddressOfFunction = false); |
9163 | |
9164 | TemplateDeductionResult |
9165 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
9166 | QualType ToType, |
9167 | CXXConversionDecl *&Specialization, |
9168 | sema::TemplateDeductionInfo &Info); |
9169 | |
9170 | TemplateDeductionResult |
9171 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
9172 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
9173 | FunctionDecl *&Specialization, |
9174 | sema::TemplateDeductionInfo &Info, |
9175 | bool IsAddressOfFunction = false); |
9176 | |
9177 | /// Substitute Replacement for \p auto in \p TypeWithAuto |
9178 | QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement); |
9179 | /// Substitute Replacement for auto in TypeWithAuto |
9180 | TypeSourceInfo* SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
9181 | QualType Replacement); |
9182 | |
9183 | // Substitute auto in TypeWithAuto for a Dependent auto type |
9184 | QualType SubstAutoTypeDependent(QualType TypeWithAuto); |
9185 | |
9186 | // Substitute auto in TypeWithAuto for a Dependent auto type |
9187 | TypeSourceInfo * |
9188 | SubstAutoTypeSourceInfoDependent(TypeSourceInfo *TypeWithAuto); |
9189 | |
9190 | /// Completely replace the \c auto in \p TypeWithAuto by |
9191 | /// \p Replacement. This does not retain any \c auto type sugar. |
9192 | QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement); |
9193 | TypeSourceInfo *ReplaceAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
9194 | QualType Replacement); |
9195 | |
9196 | TemplateDeductionResult |
9197 | DeduceAutoType(TypeLoc AutoTypeLoc, Expr *Initializer, QualType &Result, |
9198 | sema::TemplateDeductionInfo &Info, |
9199 | bool DependentDeduction = false, |
9200 | bool IgnoreConstraints = false, |
9201 | TemplateSpecCandidateSet *FailedTSC = nullptr); |
9202 | void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init); |
9203 | bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc, |
9204 | bool Diagnose = true); |
9205 | |
9206 | bool CheckIfFunctionSpecializationIsImmediate(FunctionDecl *FD, |
9207 | SourceLocation Loc); |
9208 | |
9209 | /// Declare implicit deduction guides for a class template if we've |
9210 | /// not already done so. |
9211 | void DeclareImplicitDeductionGuides(TemplateDecl *Template, |
9212 | SourceLocation Loc); |
9213 | FunctionTemplateDecl *DeclareImplicitDeductionGuideFromInitList( |
9214 | TemplateDecl *Template, MutableArrayRef<QualType> ParamTypes, |
9215 | SourceLocation Loc); |
9216 | llvm::DenseMap<unsigned, CXXDeductionGuideDecl *> |
9217 | AggregateDeductionCandidates; |
9218 | |
9219 | QualType DeduceTemplateSpecializationFromInitializer( |
9220 | TypeSourceInfo *TInfo, const InitializedEntity &Entity, |
9221 | const InitializationKind &Kind, MultiExprArg Init, |
9222 | ParenListExpr *PL = nullptr); |
9223 | |
9224 | QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name, |
9225 | QualType Type, TypeSourceInfo *TSI, |
9226 | SourceRange Range, bool DirectInit, |
9227 | Expr *Init); |
9228 | |
9229 | TypeLoc getReturnTypeLoc(FunctionDecl *FD) const; |
9230 | |
9231 | bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD, |
9232 | SourceLocation ReturnLoc, Expr *RetExpr, |
9233 | const AutoType *AT); |
9234 | |
9235 | FunctionTemplateDecl *getMoreSpecializedTemplate( |
9236 | FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc, |
9237 | TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1, |
9238 | unsigned NumCallArguments2, bool Reversed = false); |
9239 | UnresolvedSetIterator |
9240 | getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd, |
9241 | TemplateSpecCandidateSet &FailedCandidates, |
9242 | SourceLocation Loc, |
9243 | const PartialDiagnostic &NoneDiag, |
9244 | const PartialDiagnostic &AmbigDiag, |
9245 | const PartialDiagnostic &CandidateDiag, |
9246 | bool Complain = true, QualType TargetType = QualType()); |
9247 | |
9248 | ClassTemplatePartialSpecializationDecl * |
9249 | getMoreSpecializedPartialSpecialization( |
9250 | ClassTemplatePartialSpecializationDecl *PS1, |
9251 | ClassTemplatePartialSpecializationDecl *PS2, |
9252 | SourceLocation Loc); |
9253 | |
9254 | bool isMoreSpecializedThanPrimary(ClassTemplatePartialSpecializationDecl *T, |
9255 | sema::TemplateDeductionInfo &Info); |
9256 | |
9257 | VarTemplatePartialSpecializationDecl *getMoreSpecializedPartialSpecialization( |
9258 | VarTemplatePartialSpecializationDecl *PS1, |
9259 | VarTemplatePartialSpecializationDecl *PS2, SourceLocation Loc); |
9260 | |
9261 | bool isMoreSpecializedThanPrimary(VarTemplatePartialSpecializationDecl *T, |
9262 | sema::TemplateDeductionInfo &Info); |
9263 | |
9264 | bool isTemplateTemplateParameterAtLeastAsSpecializedAs( |
9265 | TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc); |
9266 | |
9267 | void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced, |
9268 | unsigned Depth, llvm::SmallBitVector &Used); |
9269 | |
9270 | void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, |
9271 | bool OnlyDeduced, |
9272 | unsigned Depth, |
9273 | llvm::SmallBitVector &Used); |
9274 | void MarkDeducedTemplateParameters( |
9275 | const FunctionTemplateDecl *FunctionTemplate, |
9276 | llvm::SmallBitVector &Deduced) { |
9277 | return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced); |
9278 | } |
9279 | static void MarkDeducedTemplateParameters(ASTContext &Ctx, |
9280 | const FunctionTemplateDecl *FunctionTemplate, |
9281 | llvm::SmallBitVector &Deduced); |
9282 | |
9283 | //===--------------------------------------------------------------------===// |
9284 | // C++ Template Instantiation |
9285 | // |
9286 | |
9287 | MultiLevelTemplateArgumentList |
9288 | getTemplateInstantiationArgs(const NamedDecl *D, bool Final = false, |
9289 | const TemplateArgumentList *Innermost = nullptr, |
9290 | bool RelativeToPrimary = false, |
9291 | const FunctionDecl *Pattern = nullptr, |
9292 | bool ForConstraintInstantiation = false, |
9293 | bool SkipForSpecialization = false); |
9294 | |
9295 | /// A context in which code is being synthesized (where a source location |
9296 | /// alone is not sufficient to identify the context). This covers template |
9297 | /// instantiation and various forms of implicitly-generated functions. |
9298 | struct CodeSynthesisContext { |
9299 | /// The kind of template instantiation we are performing |
9300 | enum SynthesisKind { |
9301 | /// We are instantiating a template declaration. The entity is |
9302 | /// the declaration we're instantiating (e.g., a CXXRecordDecl). |
9303 | TemplateInstantiation, |
9304 | |
9305 | /// We are instantiating a default argument for a template |
9306 | /// parameter. The Entity is the template parameter whose argument is |
9307 | /// being instantiated, the Template is the template, and the |
9308 | /// TemplateArgs/NumTemplateArguments provide the template arguments as |
9309 | /// specified. |
9310 | DefaultTemplateArgumentInstantiation, |
9311 | |
9312 | /// We are instantiating a default argument for a function. |
9313 | /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs |
9314 | /// provides the template arguments as specified. |
9315 | DefaultFunctionArgumentInstantiation, |
9316 | |
9317 | /// We are substituting explicit template arguments provided for |
9318 | /// a function template. The entity is a FunctionTemplateDecl. |
9319 | ExplicitTemplateArgumentSubstitution, |
9320 | |
9321 | /// We are substituting template argument determined as part of |
9322 | /// template argument deduction for either a class template |
9323 | /// partial specialization or a function template. The |
9324 | /// Entity is either a {Class|Var}TemplatePartialSpecializationDecl or |
9325 | /// a TemplateDecl. |
9326 | DeducedTemplateArgumentSubstitution, |
9327 | |
9328 | /// We are substituting into a lambda expression. |
9329 | LambdaExpressionSubstitution, |
9330 | |
9331 | /// We are substituting prior template arguments into a new |
9332 | /// template parameter. The template parameter itself is either a |
9333 | /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. |
9334 | PriorTemplateArgumentSubstitution, |
9335 | |
9336 | /// We are checking the validity of a default template argument that |
9337 | /// has been used when naming a template-id. |
9338 | DefaultTemplateArgumentChecking, |
9339 | |
9340 | /// We are computing the exception specification for a defaulted special |
9341 | /// member function. |
9342 | ExceptionSpecEvaluation, |
9343 | |
9344 | /// We are instantiating the exception specification for a function |
9345 | /// template which was deferred until it was needed. |
9346 | ExceptionSpecInstantiation, |
9347 | |
9348 | /// We are instantiating a requirement of a requires expression. |
9349 | RequirementInstantiation, |
9350 | |
9351 | /// We are checking the satisfaction of a nested requirement of a requires |
9352 | /// expression. |
9353 | NestedRequirementConstraintsCheck, |
9354 | |
9355 | /// We are declaring an implicit special member function. |
9356 | DeclaringSpecialMember, |
9357 | |
9358 | /// We are declaring an implicit 'operator==' for a defaulted |
9359 | /// 'operator<=>'. |
9360 | DeclaringImplicitEqualityComparison, |
9361 | |
9362 | /// We are defining a synthesized function (such as a defaulted special |
9363 | /// member). |
9364 | DefiningSynthesizedFunction, |
9365 | |
9366 | // We are checking the constraints associated with a constrained entity or |
9367 | // the constraint expression of a concept. This includes the checks that |
9368 | // atomic constraints have the type 'bool' and that they can be constant |
9369 | // evaluated. |
9370 | ConstraintsCheck, |
9371 | |
9372 | // We are substituting template arguments into a constraint expression. |
9373 | ConstraintSubstitution, |
9374 | |
9375 | // We are normalizing a constraint expression. |
9376 | ConstraintNormalization, |
9377 | |
9378 | // Instantiating a Requires Expression parameter clause. |
9379 | RequirementParameterInstantiation, |
9380 | |
9381 | // We are substituting into the parameter mapping of an atomic constraint |
9382 | // during normalization. |
9383 | ParameterMappingSubstitution, |
9384 | |
9385 | /// We are rewriting a comparison operator in terms of an operator<=>. |
9386 | RewritingOperatorAsSpaceship, |
9387 | |
9388 | /// We are initializing a structured binding. |
9389 | InitializingStructuredBinding, |
9390 | |
9391 | /// We are marking a class as __dllexport. |
9392 | MarkingClassDllexported, |
9393 | |
9394 | /// We are building an implied call from __builtin_dump_struct. The |
9395 | /// arguments are in CallArgs. |
9396 | BuildingBuiltinDumpStructCall, |
9397 | |
9398 | /// Added for Template instantiation observation. |
9399 | /// Memoization means we are _not_ instantiating a template because |
9400 | /// it is already instantiated (but we entered a context where we |
9401 | /// would have had to if it was not already instantiated). |
9402 | Memoization, |
9403 | |
9404 | /// We are building deduction guides for a class. |
9405 | BuildingDeductionGuides, |
9406 | } Kind; |
9407 | |
9408 | /// Was the enclosing context a non-instantiation SFINAE context? |
9409 | bool SavedInNonInstantiationSFINAEContext; |
9410 | |
9411 | /// The point of instantiation or synthesis within the source code. |
9412 | SourceLocation PointOfInstantiation; |
9413 | |
9414 | /// The entity that is being synthesized. |
9415 | Decl *Entity; |
9416 | |
9417 | /// The template (or partial specialization) in which we are |
9418 | /// performing the instantiation, for substitutions of prior template |
9419 | /// arguments. |
9420 | NamedDecl *Template; |
9421 | |
9422 | union { |
9423 | /// The list of template arguments we are substituting, if they |
9424 | /// are not part of the entity. |
9425 | const TemplateArgument *TemplateArgs; |
9426 | |
9427 | /// The list of argument expressions in a synthesized call. |
9428 | const Expr *const *CallArgs; |
9429 | }; |
9430 | |
9431 | // FIXME: Wrap this union around more members, or perhaps store the |
9432 | // kind-specific members in the RAII object owning the context. |
9433 | union { |
9434 | /// The number of template arguments in TemplateArgs. |
9435 | unsigned NumTemplateArgs; |
9436 | |
9437 | /// The number of expressions in CallArgs. |
9438 | unsigned NumCallArgs; |
9439 | |
9440 | /// The special member being declared or defined. |
9441 | CXXSpecialMember SpecialMember; |
9442 | }; |
9443 | |
9444 | ArrayRef<TemplateArgument> template_arguments() const { |
9445 | assert(Kind != DeclaringSpecialMember); |
9446 | return {TemplateArgs, NumTemplateArgs}; |
9447 | } |
9448 | |
9449 | /// The template deduction info object associated with the |
9450 | /// substitution or checking of explicit or deduced template arguments. |
9451 | sema::TemplateDeductionInfo *DeductionInfo; |
9452 | |
9453 | /// The source range that covers the construct that cause |
9454 | /// the instantiation, e.g., the template-id that causes a class |
9455 | /// template instantiation. |
9456 | SourceRange InstantiationRange; |
9457 | |
9458 | CodeSynthesisContext() |
9459 | : Kind(TemplateInstantiation), |
9460 | SavedInNonInstantiationSFINAEContext(false), Entity(nullptr), |
9461 | Template(nullptr), TemplateArgs(nullptr), NumTemplateArgs(0), |
9462 | DeductionInfo(nullptr) {} |
9463 | |
9464 | /// Determines whether this template is an actual instantiation |
9465 | /// that should be counted toward the maximum instantiation depth. |
9466 | bool isInstantiationRecord() const; |
9467 | }; |
9468 | |
9469 | /// List of active code synthesis contexts. |
9470 | /// |
9471 | /// This vector is treated as a stack. As synthesis of one entity requires |
9472 | /// synthesis of another, additional contexts are pushed onto the stack. |
9473 | SmallVector<CodeSynthesisContext, 16> CodeSynthesisContexts; |
9474 | |
9475 | /// Specializations whose definitions are currently being instantiated. |
9476 | llvm::DenseSet<std::pair<Decl *, unsigned>> InstantiatingSpecializations; |
9477 | |
9478 | /// Non-dependent types used in templates that have already been instantiated |
9479 | /// by some template instantiation. |
9480 | llvm::DenseSet<QualType> InstantiatedNonDependentTypes; |
9481 | |
9482 | /// Extra modules inspected when performing a lookup during a template |
9483 | /// instantiation. Computed lazily. |
9484 | SmallVector<Module*, 16> CodeSynthesisContextLookupModules; |
9485 | |
9486 | /// Cache of additional modules that should be used for name lookup |
9487 | /// within the current template instantiation. Computed lazily; use |
9488 | /// getLookupModules() to get a complete set. |
9489 | llvm::DenseSet<Module*> LookupModulesCache; |
9490 | |
9491 | /// Get the set of additional modules that should be checked during |
9492 | /// name lookup. A module and its imports become visible when instanting a |
9493 | /// template defined within it. |
9494 | llvm::DenseSet<Module*> &getLookupModules(); |
9495 | |
9496 | /// Map from the most recent declaration of a namespace to the most |
9497 | /// recent visible declaration of that namespace. |
9498 | llvm::DenseMap<NamedDecl*, NamedDecl*> VisibleNamespaceCache; |
9499 | |
9500 | /// Whether we are in a SFINAE context that is not associated with |
9501 | /// template instantiation. |
9502 | /// |
9503 | /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside |
9504 | /// of a template instantiation or template argument deduction. |
9505 | bool InNonInstantiationSFINAEContext; |
9506 | |
9507 | /// The number of \p CodeSynthesisContexts that are not template |
9508 | /// instantiations and, therefore, should not be counted as part of the |
9509 | /// instantiation depth. |
9510 | /// |
9511 | /// When the instantiation depth reaches the user-configurable limit |
9512 | /// \p LangOptions::InstantiationDepth we will abort instantiation. |
9513 | // FIXME: Should we have a similar limit for other forms of synthesis? |
9514 | unsigned NonInstantiationEntries; |
9515 | |
9516 | /// The depth of the context stack at the point when the most recent |
9517 | /// error or warning was produced. |
9518 | /// |
9519 | /// This value is used to suppress printing of redundant context stacks |
9520 | /// when there are multiple errors or warnings in the same instantiation. |
9521 | // FIXME: Does this belong in Sema? It's tough to implement it anywhere else. |
9522 | unsigned LastEmittedCodeSynthesisContextDepth = 0; |
9523 | |
9524 | /// The template instantiation callbacks to trace or track |
9525 | /// instantiations (objects can be chained). |
9526 | /// |
9527 | /// This callbacks is used to print, trace or track template |
9528 | /// instantiations as they are being constructed. |
9529 | std::vector<std::unique_ptr<TemplateInstantiationCallback>> |
9530 | TemplateInstCallbacks; |
9531 | |
9532 | /// The current index into pack expansion arguments that will be |
9533 | /// used for substitution of parameter packs. |
9534 | /// |
9535 | /// The pack expansion index will be -1 to indicate that parameter packs |
9536 | /// should be instantiated as themselves. Otherwise, the index specifies |
9537 | /// which argument within the parameter pack will be used for substitution. |
9538 | int ArgumentPackSubstitutionIndex; |
9539 | |
9540 | /// RAII object used to change the argument pack substitution index |
9541 | /// within a \c Sema object. |
9542 | /// |
9543 | /// See \c ArgumentPackSubstitutionIndex for more information. |
9544 | class ArgumentPackSubstitutionIndexRAII { |
9545 | Sema &Self; |
9546 | int OldSubstitutionIndex; |
9547 | |
9548 | public: |
9549 | ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) |
9550 | : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { |
9551 | Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; |
9552 | } |
9553 | |
9554 | ~ArgumentPackSubstitutionIndexRAII() { |
9555 | Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; |
9556 | } |
9557 | }; |
9558 | |
9559 | friend class ArgumentPackSubstitutionRAII; |
9560 | |
9561 | /// For each declaration that involved template argument deduction, the |
9562 | /// set of diagnostics that were suppressed during that template argument |
9563 | /// deduction. |
9564 | /// |
9565 | /// FIXME: Serialize this structure to the AST file. |
9566 | typedef llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> > |
9567 | SuppressedDiagnosticsMap; |
9568 | SuppressedDiagnosticsMap SuppressedDiagnostics; |
9569 | |
9570 | /// A stack object to be created when performing template |
9571 | /// instantiation. |
9572 | /// |
9573 | /// Construction of an object of type \c InstantiatingTemplate |
9574 | /// pushes the current instantiation onto the stack of active |
9575 | /// instantiations. If the size of this stack exceeds the maximum |
9576 | /// number of recursive template instantiations, construction |
9577 | /// produces an error and evaluates true. |
9578 | /// |
9579 | /// Destruction of this object will pop the named instantiation off |
9580 | /// the stack. |
9581 | struct InstantiatingTemplate { |
9582 | /// Note that we are instantiating a class template, |
9583 | /// function template, variable template, alias template, |
9584 | /// or a member thereof. |
9585 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9586 | Decl *Entity, |
9587 | SourceRange InstantiationRange = SourceRange()); |
9588 | |
9589 | struct ExceptionSpecification {}; |
9590 | /// Note that we are instantiating an exception specification |
9591 | /// of a function template. |
9592 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9593 | FunctionDecl *Entity, ExceptionSpecification, |
9594 | SourceRange InstantiationRange = SourceRange()); |
9595 | |
9596 | /// Note that we are instantiating a default argument in a |
9597 | /// template-id. |
9598 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9599 | TemplateParameter Param, TemplateDecl *Template, |
9600 | ArrayRef<TemplateArgument> TemplateArgs, |
9601 | SourceRange InstantiationRange = SourceRange()); |
9602 | |
9603 | /// Note that we are substituting either explicitly-specified or |
9604 | /// deduced template arguments during function template argument deduction. |
9605 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9606 | FunctionTemplateDecl *FunctionTemplate, |
9607 | ArrayRef<TemplateArgument> TemplateArgs, |
9608 | CodeSynthesisContext::SynthesisKind Kind, |
9609 | sema::TemplateDeductionInfo &DeductionInfo, |
9610 | SourceRange InstantiationRange = SourceRange()); |
9611 | |
9612 | /// Note that we are instantiating as part of template |
9613 | /// argument deduction for a class template declaration. |
9614 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9615 | TemplateDecl *Template, |
9616 | ArrayRef<TemplateArgument> TemplateArgs, |
9617 | sema::TemplateDeductionInfo &DeductionInfo, |
9618 | SourceRange InstantiationRange = SourceRange()); |
9619 | |
9620 | /// Note that we are instantiating as part of template |
9621 | /// argument deduction for a class template partial |
9622 | /// specialization. |
9623 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9624 | ClassTemplatePartialSpecializationDecl *PartialSpec, |
9625 | ArrayRef<TemplateArgument> TemplateArgs, |
9626 | sema::TemplateDeductionInfo &DeductionInfo, |
9627 | SourceRange InstantiationRange = SourceRange()); |
9628 | |
9629 | /// Note that we are instantiating as part of template |
9630 | /// argument deduction for a variable template partial |
9631 | /// specialization. |
9632 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9633 | VarTemplatePartialSpecializationDecl *PartialSpec, |
9634 | ArrayRef<TemplateArgument> TemplateArgs, |
9635 | sema::TemplateDeductionInfo &DeductionInfo, |
9636 | SourceRange InstantiationRange = SourceRange()); |
9637 | |
9638 | /// Note that we are instantiating a default argument for a function |
9639 | /// parameter. |
9640 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9641 | ParmVarDecl *Param, |
9642 | ArrayRef<TemplateArgument> TemplateArgs, |
9643 | SourceRange InstantiationRange = SourceRange()); |
9644 | |
9645 | /// Note that we are substituting prior template arguments into a |
9646 | /// non-type parameter. |
9647 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9648 | NamedDecl *Template, |
9649 | NonTypeTemplateParmDecl *Param, |
9650 | ArrayRef<TemplateArgument> TemplateArgs, |
9651 | SourceRange InstantiationRange); |
9652 | |
9653 | /// Note that we are substituting prior template arguments into a |
9654 | /// template template parameter. |
9655 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9656 | NamedDecl *Template, |
9657 | TemplateTemplateParmDecl *Param, |
9658 | ArrayRef<TemplateArgument> TemplateArgs, |
9659 | SourceRange InstantiationRange); |
9660 | |
9661 | /// Note that we are checking the default template argument |
9662 | /// against the template parameter for a given template-id. |
9663 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9664 | TemplateDecl *Template, |
9665 | NamedDecl *Param, |
9666 | ArrayRef<TemplateArgument> TemplateArgs, |
9667 | SourceRange InstantiationRange); |
9668 | |
9669 | struct ConstraintsCheck {}; |
9670 | /// \brief Note that we are checking the constraints associated with some |
9671 | /// constrained entity (a concept declaration or a template with associated |
9672 | /// constraints). |
9673 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9674 | ConstraintsCheck, NamedDecl *Template, |
9675 | ArrayRef<TemplateArgument> TemplateArgs, |
9676 | SourceRange InstantiationRange); |
9677 | |
9678 | struct ConstraintSubstitution {}; |
9679 | /// \brief Note that we are checking a constraint expression associated |
9680 | /// with a template declaration or as part of the satisfaction check of a |
9681 | /// concept. |
9682 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9683 | ConstraintSubstitution, NamedDecl *Template, |
9684 | sema::TemplateDeductionInfo &DeductionInfo, |
9685 | SourceRange InstantiationRange); |
9686 | |
9687 | struct ConstraintNormalization {}; |
9688 | /// \brief Note that we are normalizing a constraint expression. |
9689 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9690 | ConstraintNormalization, NamedDecl *Template, |
9691 | SourceRange InstantiationRange); |
9692 | |
9693 | struct ParameterMappingSubstitution {}; |
9694 | /// \brief Note that we are subtituting into the parameter mapping of an |
9695 | /// atomic constraint during constraint normalization. |
9696 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9697 | ParameterMappingSubstitution, NamedDecl *Template, |
9698 | SourceRange InstantiationRange); |
9699 | |
9700 | /// \brief Note that we are substituting template arguments into a part of |
9701 | /// a requirement of a requires expression. |
9702 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9703 | concepts::Requirement *Req, |
9704 | sema::TemplateDeductionInfo &DeductionInfo, |
9705 | SourceRange InstantiationRange = SourceRange()); |
9706 | |
9707 | /// \brief Note that we are checking the satisfaction of the constraint |
9708 | /// expression inside of a nested requirement. |
9709 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9710 | concepts::NestedRequirement *Req, ConstraintsCheck, |
9711 | SourceRange InstantiationRange = SourceRange()); |
9712 | |
9713 | /// \brief Note that we are checking a requires clause. |
9714 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9715 | const RequiresExpr *E, |
9716 | sema::TemplateDeductionInfo &DeductionInfo, |
9717 | SourceRange InstantiationRange); |
9718 | |
9719 | struct BuildingDeductionGuidesTag {}; |
9720 | /// \brief Note that we are building deduction guides. |
9721 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9722 | TemplateDecl *Entity, BuildingDeductionGuidesTag, |
9723 | SourceRange InstantiationRange = SourceRange()); |
9724 | |
9725 | /// Note that we have finished instantiating this template. |
9726 | void Clear(); |
9727 | |
9728 | ~InstantiatingTemplate() { Clear(); } |
9729 | |
9730 | /// Determines whether we have exceeded the maximum |
9731 | /// recursive template instantiations. |
9732 | bool isInvalid() const { return Invalid; } |
9733 | |
9734 | /// Determine whether we are already instantiating this |
9735 | /// specialization in some surrounding active instantiation. |
9736 | bool isAlreadyInstantiating() const { return AlreadyInstantiating; } |
9737 | |
9738 | private: |
9739 | Sema &SemaRef; |
9740 | bool Invalid; |
9741 | bool AlreadyInstantiating; |
9742 | bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, |
9743 | SourceRange InstantiationRange); |
9744 | |
9745 | InstantiatingTemplate( |
9746 | Sema &SemaRef, CodeSynthesisContext::SynthesisKind Kind, |
9747 | SourceLocation PointOfInstantiation, SourceRange InstantiationRange, |
9748 | Decl *Entity, NamedDecl *Template = nullptr, |
9749 | ArrayRef<TemplateArgument> TemplateArgs = std::nullopt, |
9750 | sema::TemplateDeductionInfo *DeductionInfo = nullptr); |
9751 | |
9752 | InstantiatingTemplate(const InstantiatingTemplate&) = delete; |
9753 | |
9754 | InstantiatingTemplate& |
9755 | operator=(const InstantiatingTemplate&) = delete; |
9756 | }; |
9757 | |
9758 | void pushCodeSynthesisContext(CodeSynthesisContext Ctx); |
9759 | void popCodeSynthesisContext(); |
9760 | |
9761 | /// Determine whether we are currently performing template instantiation. |
9762 | bool inTemplateInstantiation() const { |
9763 | return CodeSynthesisContexts.size() > NonInstantiationEntries; |
9764 | } |
9765 | |
9766 | void PrintContextStack() { |
9767 | if (!CodeSynthesisContexts.empty() && |
9768 | CodeSynthesisContexts.size() != LastEmittedCodeSynthesisContextDepth) { |
9769 | PrintInstantiationStack(); |
9770 | LastEmittedCodeSynthesisContextDepth = CodeSynthesisContexts.size(); |
9771 | } |
9772 | if (PragmaAttributeCurrentTargetDecl) |
9773 | PrintPragmaAttributeInstantiationPoint(); |
9774 | } |
9775 | void PrintInstantiationStack(); |
9776 | |
9777 | void PrintPragmaAttributeInstantiationPoint(); |
9778 | |
9779 | /// Determines whether we are currently in a context where |
9780 | /// template argument substitution failures are not considered |
9781 | /// errors. |
9782 | /// |
9783 | /// \returns An empty \c Optional if we're not in a SFINAE context. |
9784 | /// Otherwise, contains a pointer that, if non-NULL, contains the nearest |
9785 | /// template-deduction context object, which can be used to capture |
9786 | /// diagnostics that will be suppressed. |
9787 | std::optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; |
9788 | |
9789 | /// Determines whether we are currently in a context that |
9790 | /// is not evaluated as per C++ [expr] p5. |
9791 | bool isUnevaluatedContext() const { |
9792 | assert(!ExprEvalContexts.empty() && |
9793 | "Must be in an expression evaluation context" ); |
9794 | return ExprEvalContexts.back().isUnevaluated(); |
9795 | } |
9796 | |
9797 | bool isConstantEvaluatedContext() const { |
9798 | assert(!ExprEvalContexts.empty() && |
9799 | "Must be in an expression evaluation context" ); |
9800 | return ExprEvalContexts.back().isConstantEvaluated(); |
9801 | } |
9802 | |
9803 | bool isImmediateFunctionContext() const { |
9804 | assert(!ExprEvalContexts.empty() && |
9805 | "Must be in an expression evaluation context" ); |
9806 | return ExprEvalContexts.back().isImmediateFunctionContext(); |
9807 | } |
9808 | |
9809 | bool isCheckingDefaultArgumentOrInitializer() const { |
9810 | assert(!ExprEvalContexts.empty() && |
9811 | "Must be in an expression evaluation context" ); |
9812 | const ExpressionEvaluationContextRecord &Ctx = ExprEvalContexts.back(); |
9813 | return (Ctx.Context == |
9814 | ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed) || |
9815 | Ctx.IsCurrentlyCheckingDefaultArgumentOrInitializer; |
9816 | } |
9817 | |
9818 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> |
9819 | InnermostDeclarationWithDelayedImmediateInvocations() const { |
9820 | assert(!ExprEvalContexts.empty() && |
9821 | "Must be in an expression evaluation context" ); |
9822 | for (const auto &Ctx : llvm::reverse(ExprEvalContexts)) { |
9823 | if (Ctx.Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
9824 | Ctx.DelayedDefaultInitializationContext) |
9825 | return Ctx.DelayedDefaultInitializationContext; |
9826 | if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() || |
9827 | Ctx.isUnevaluated()) |
9828 | break; |
9829 | } |
9830 | return std::nullopt; |
9831 | } |
9832 | |
9833 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> |
9834 | OutermostDeclarationWithDelayedImmediateInvocations() const { |
9835 | assert(!ExprEvalContexts.empty() && |
9836 | "Must be in an expression evaluation context" ); |
9837 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> Res; |
9838 | for (auto &Ctx : llvm::reverse(ExprEvalContexts)) { |
9839 | if (Ctx.Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
9840 | !Ctx.DelayedDefaultInitializationContext && Res) |
9841 | break; |
9842 | if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() || |
9843 | Ctx.isUnevaluated()) |
9844 | break; |
9845 | Res = Ctx.DelayedDefaultInitializationContext; |
9846 | } |
9847 | return Res; |
9848 | } |
9849 | |
9850 | /// RAII class used to determine whether SFINAE has |
9851 | /// trapped any errors that occur during template argument |
9852 | /// deduction. |
9853 | class SFINAETrap { |
9854 | Sema &SemaRef; |
9855 | unsigned PrevSFINAEErrors; |
9856 | bool PrevInNonInstantiationSFINAEContext; |
9857 | bool PrevAccessCheckingSFINAE; |
9858 | bool PrevLastDiagnosticIgnored; |
9859 | |
9860 | public: |
9861 | explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) |
9862 | : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), |
9863 | PrevInNonInstantiationSFINAEContext( |
9864 | SemaRef.InNonInstantiationSFINAEContext), |
9865 | PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE), |
9866 | PrevLastDiagnosticIgnored( |
9867 | SemaRef.getDiagnostics().isLastDiagnosticIgnored()) |
9868 | { |
9869 | if (!SemaRef.isSFINAEContext()) |
9870 | SemaRef.InNonInstantiationSFINAEContext = true; |
9871 | SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; |
9872 | } |
9873 | |
9874 | ~SFINAETrap() { |
9875 | SemaRef.NumSFINAEErrors = PrevSFINAEErrors; |
9876 | SemaRef.InNonInstantiationSFINAEContext |
9877 | = PrevInNonInstantiationSFINAEContext; |
9878 | SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; |
9879 | SemaRef.getDiagnostics().setLastDiagnosticIgnored( |
9880 | PrevLastDiagnosticIgnored); |
9881 | } |
9882 | |
9883 | /// Determine whether any SFINAE errors have been trapped. |
9884 | bool hasErrorOccurred() const { |
9885 | return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; |
9886 | } |
9887 | }; |
9888 | |
9889 | /// RAII class used to indicate that we are performing provisional |
9890 | /// semantic analysis to determine the validity of a construct, so |
9891 | /// typo-correction and diagnostics in the immediate context (not within |
9892 | /// implicitly-instantiated templates) should be suppressed. |
9893 | class TentativeAnalysisScope { |
9894 | Sema &SemaRef; |
9895 | // FIXME: Using a SFINAETrap for this is a hack. |
9896 | SFINAETrap Trap; |
9897 | bool PrevDisableTypoCorrection; |
9898 | public: |
9899 | explicit TentativeAnalysisScope(Sema &SemaRef) |
9900 | : SemaRef(SemaRef), Trap(SemaRef, true), |
9901 | PrevDisableTypoCorrection(SemaRef.DisableTypoCorrection) { |
9902 | SemaRef.DisableTypoCorrection = true; |
9903 | } |
9904 | ~TentativeAnalysisScope() { |
9905 | SemaRef.DisableTypoCorrection = PrevDisableTypoCorrection; |
9906 | } |
9907 | }; |
9908 | |
9909 | /// The current instantiation scope used to store local |
9910 | /// variables. |
9911 | LocalInstantiationScope *CurrentInstantiationScope; |
9912 | |
9913 | /// Tracks whether we are in a context where typo correction is |
9914 | /// disabled. |
9915 | bool DisableTypoCorrection; |
9916 | |
9917 | /// The number of typos corrected by CorrectTypo. |
9918 | unsigned TyposCorrected; |
9919 | |
9920 | typedef llvm::SmallSet<SourceLocation, 2> SrcLocSet; |
9921 | typedef llvm::DenseMap<IdentifierInfo *, SrcLocSet> IdentifierSourceLocations; |
9922 | |
9923 | /// A cache containing identifiers for which typo correction failed and |
9924 | /// their locations, so that repeated attempts to correct an identifier in a |
9925 | /// given location are ignored if typo correction already failed for it. |
9926 | IdentifierSourceLocations TypoCorrectionFailures; |
9927 | |
9928 | /// Worker object for performing CFG-based warnings. |
9929 | sema::AnalysisBasedWarnings AnalysisWarnings; |
9930 | threadSafety::BeforeSet *ThreadSafetyDeclCache; |
9931 | |
9932 | /// An entity for which implicit template instantiation is required. |
9933 | /// |
9934 | /// The source location associated with the declaration is the first place in |
9935 | /// the source code where the declaration was "used". It is not necessarily |
9936 | /// the point of instantiation (which will be either before or after the |
9937 | /// namespace-scope declaration that triggered this implicit instantiation), |
9938 | /// However, it is the location that diagnostics should generally refer to, |
9939 | /// because users will need to know what code triggered the instantiation. |
9940 | typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; |
9941 | |
9942 | /// The queue of implicit template instantiations that are required |
9943 | /// but have not yet been performed. |
9944 | std::deque<PendingImplicitInstantiation> PendingInstantiations; |
9945 | |
9946 | /// Queue of implicit template instantiations that cannot be performed |
9947 | /// eagerly. |
9948 | SmallVector<PendingImplicitInstantiation, 1> LateParsedInstantiations; |
9949 | |
9950 | SmallVector<SmallVector<VTableUse, 16>, 8> SavedVTableUses; |
9951 | SmallVector<std::deque<PendingImplicitInstantiation>, 8> |
9952 | SavedPendingInstantiations; |
9953 | |
9954 | class GlobalEagerInstantiationScope { |
9955 | public: |
9956 | GlobalEagerInstantiationScope(Sema &S, bool Enabled) |
9957 | : S(S), Enabled(Enabled) { |
9958 | if (!Enabled) return; |
9959 | |
9960 | S.SavedPendingInstantiations.emplace_back(); |
9961 | S.SavedPendingInstantiations.back().swap(S.PendingInstantiations); |
9962 | |
9963 | S.SavedVTableUses.emplace_back(); |
9964 | S.SavedVTableUses.back().swap(S.VTableUses); |
9965 | } |
9966 | |
9967 | void perform() { |
9968 | if (Enabled) { |
9969 | S.DefineUsedVTables(); |
9970 | S.PerformPendingInstantiations(); |
9971 | } |
9972 | } |
9973 | |
9974 | ~GlobalEagerInstantiationScope() { |
9975 | if (!Enabled) return; |
9976 | |
9977 | // Restore the set of pending vtables. |
9978 | assert(S.VTableUses.empty() && |
9979 | "VTableUses should be empty before it is discarded." ); |
9980 | S.VTableUses.swap(S.SavedVTableUses.back()); |
9981 | S.SavedVTableUses.pop_back(); |
9982 | |
9983 | // Restore the set of pending implicit instantiations. |
9984 | if (S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) { |
9985 | assert(S.PendingInstantiations.empty() && |
9986 | "PendingInstantiations should be empty before it is discarded." ); |
9987 | S.PendingInstantiations.swap(S.SavedPendingInstantiations.back()); |
9988 | S.SavedPendingInstantiations.pop_back(); |
9989 | } else { |
9990 | // Template instantiations in the PCH may be delayed until the TU. |
9991 | S.PendingInstantiations.swap(S.SavedPendingInstantiations.back()); |
9992 | S.PendingInstantiations.insert( |
9993 | S.PendingInstantiations.end(), |
9994 | S.SavedPendingInstantiations.back().begin(), |
9995 | S.SavedPendingInstantiations.back().end()); |
9996 | S.SavedPendingInstantiations.pop_back(); |
9997 | } |
9998 | } |
9999 | |
10000 | private: |
10001 | Sema &S; |
10002 | bool Enabled; |
10003 | }; |
10004 | |
10005 | /// The queue of implicit template instantiations that are required |
10006 | /// and must be performed within the current local scope. |
10007 | /// |
10008 | /// This queue is only used for member functions of local classes in |
10009 | /// templates, which must be instantiated in the same scope as their |
10010 | /// enclosing function, so that they can reference function-local |
10011 | /// types, static variables, enumerators, etc. |
10012 | std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; |
10013 | |
10014 | class LocalEagerInstantiationScope { |
10015 | public: |
10016 | LocalEagerInstantiationScope(Sema &S) : S(S) { |
10017 | SavedPendingLocalImplicitInstantiations.swap( |
10018 | S.PendingLocalImplicitInstantiations); |
10019 | } |
10020 | |
10021 | void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/true); } |
10022 | |
10023 | ~LocalEagerInstantiationScope() { |
10024 | assert(S.PendingLocalImplicitInstantiations.empty() && |
10025 | "there shouldn't be any pending local implicit instantiations" ); |
10026 | SavedPendingLocalImplicitInstantiations.swap( |
10027 | S.PendingLocalImplicitInstantiations); |
10028 | } |
10029 | |
10030 | private: |
10031 | Sema &S; |
10032 | std::deque<PendingImplicitInstantiation> |
10033 | SavedPendingLocalImplicitInstantiations; |
10034 | }; |
10035 | |
10036 | /// A helper class for building up ExtParameterInfos. |
10037 | class ExtParameterInfoBuilder { |
10038 | SmallVector<FunctionProtoType::ExtParameterInfo, 16> Infos; |
10039 | bool HasInteresting = false; |
10040 | |
10041 | public: |
10042 | /// Set the ExtParameterInfo for the parameter at the given index, |
10043 | /// |
10044 | void set(unsigned index, FunctionProtoType::ExtParameterInfo info) { |
10045 | assert(Infos.size() <= index); |
10046 | Infos.resize(index); |
10047 | Infos.push_back(info); |
10048 | |
10049 | if (!HasInteresting) |
10050 | HasInteresting = (info != FunctionProtoType::ExtParameterInfo()); |
10051 | } |
10052 | |
10053 | /// Return a pointer (suitable for setting in an ExtProtoInfo) to the |
10054 | /// ExtParameterInfo array we've built up. |
10055 | const FunctionProtoType::ExtParameterInfo * |
10056 | getPointerOrNull(unsigned numParams) { |
10057 | if (!HasInteresting) return nullptr; |
10058 | Infos.resize(numParams); |
10059 | return Infos.data(); |
10060 | } |
10061 | }; |
10062 | |
10063 | void PerformPendingInstantiations(bool LocalOnly = false); |
10064 | |
10065 | TypeSourceInfo *SubstType(TypeSourceInfo *T, |
10066 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10067 | SourceLocation Loc, DeclarationName Entity, |
10068 | bool AllowDeducedTST = false); |
10069 | |
10070 | QualType SubstType(QualType T, |
10071 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10072 | SourceLocation Loc, DeclarationName Entity); |
10073 | |
10074 | TypeSourceInfo *SubstType(TypeLoc TL, |
10075 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10076 | SourceLocation Loc, DeclarationName Entity); |
10077 | |
10078 | TypeSourceInfo *SubstFunctionDeclType( |
10079 | TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, |
10080 | SourceLocation Loc, DeclarationName Entity, CXXRecordDecl *ThisContext, |
10081 | Qualifiers ThisTypeQuals, bool EvaluateConstraints = true); |
10082 | void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, |
10083 | const MultiLevelTemplateArgumentList &Args); |
10084 | bool SubstExceptionSpec(SourceLocation Loc, |
10085 | FunctionProtoType::ExceptionSpecInfo &ESI, |
10086 | SmallVectorImpl<QualType> &ExceptionStorage, |
10087 | const MultiLevelTemplateArgumentList &Args); |
10088 | ParmVarDecl * |
10089 | SubstParmVarDecl(ParmVarDecl *D, |
10090 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10091 | int indexAdjustment, std::optional<unsigned> NumExpansions, |
10092 | bool ExpectParameterPack, bool EvaluateConstraints = true); |
10093 | bool SubstParmTypes(SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
10094 | const FunctionProtoType::ExtParameterInfo *ExtParamInfos, |
10095 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10096 | SmallVectorImpl<QualType> &ParamTypes, |
10097 | SmallVectorImpl<ParmVarDecl *> *OutParams, |
10098 | ExtParameterInfoBuilder &ParamInfos); |
10099 | bool SubstDefaultArgument(SourceLocation Loc, ParmVarDecl *Param, |
10100 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10101 | bool ForCallExpr = false); |
10102 | ExprResult SubstExpr(Expr *E, |
10103 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10104 | |
10105 | // A RAII type used by the TemplateDeclInstantiator and TemplateInstantiator |
10106 | // to disable constraint evaluation, then restore the state. |
10107 | template <typename InstTy> struct ConstraintEvalRAII { |
10108 | InstTy &TI; |
10109 | bool OldValue; |
10110 | |
10111 | ConstraintEvalRAII(InstTy &TI) |
10112 | : TI(TI), OldValue(TI.getEvaluateConstraints()) { |
10113 | TI.setEvaluateConstraints(false); |
10114 | } |
10115 | ~ConstraintEvalRAII() { TI.setEvaluateConstraints(OldValue); } |
10116 | }; |
10117 | |
10118 | // Unlike the above, this evaluates constraints, which should only happen at |
10119 | // 'constraint checking' time. |
10120 | ExprResult |
10121 | SubstConstraintExpr(Expr *E, |
10122 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10123 | |
10124 | /// Substitute the given template arguments into a list of |
10125 | /// expressions, expanding pack expansions if required. |
10126 | /// |
10127 | /// \param Exprs The list of expressions to substitute into. |
10128 | /// |
10129 | /// \param IsCall Whether this is some form of call, in which case |
10130 | /// default arguments will be dropped. |
10131 | /// |
10132 | /// \param TemplateArgs The set of template arguments to substitute. |
10133 | /// |
10134 | /// \param Outputs Will receive all of the substituted arguments. |
10135 | /// |
10136 | /// \returns true if an error occurred, false otherwise. |
10137 | bool SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall, |
10138 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10139 | SmallVectorImpl<Expr *> &Outputs); |
10140 | |
10141 | StmtResult SubstStmt(Stmt *S, |
10142 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10143 | |
10144 | TemplateParameterList * |
10145 | SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner, |
10146 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10147 | bool EvaluateConstraints = true); |
10148 | |
10149 | bool |
10150 | SubstTemplateArguments(ArrayRef<TemplateArgumentLoc> Args, |
10151 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10152 | TemplateArgumentListInfo &Outputs); |
10153 | |
10154 | Decl *SubstDecl(Decl *D, DeclContext *Owner, |
10155 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10156 | |
10157 | /// Substitute the name and return type of a defaulted 'operator<=>' to form |
10158 | /// an implicit 'operator=='. |
10159 | FunctionDecl *SubstSpaceshipAsEqualEqual(CXXRecordDecl *RD, |
10160 | FunctionDecl *Spaceship); |
10161 | |
10162 | ExprResult SubstInitializer(Expr *E, |
10163 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10164 | bool CXXDirectInit); |
10165 | |
10166 | bool |
10167 | SubstBaseSpecifiers(CXXRecordDecl *Instantiation, |
10168 | CXXRecordDecl *Pattern, |
10169 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10170 | |
10171 | bool |
10172 | InstantiateClass(SourceLocation PointOfInstantiation, |
10173 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
10174 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10175 | TemplateSpecializationKind TSK, |
10176 | bool Complain = true); |
10177 | |
10178 | bool InstantiateEnum(SourceLocation PointOfInstantiation, |
10179 | EnumDecl *Instantiation, EnumDecl *Pattern, |
10180 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10181 | TemplateSpecializationKind TSK); |
10182 | |
10183 | bool InstantiateInClassInitializer( |
10184 | SourceLocation PointOfInstantiation, FieldDecl *Instantiation, |
10185 | FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs); |
10186 | |
10187 | struct LateInstantiatedAttribute { |
10188 | const Attr *TmplAttr; |
10189 | LocalInstantiationScope *Scope; |
10190 | Decl *NewDecl; |
10191 | |
10192 | LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S, |
10193 | Decl *D) |
10194 | : TmplAttr(A), Scope(S), NewDecl(D) |
10195 | { } |
10196 | }; |
10197 | typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec; |
10198 | |
10199 | void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, |
10200 | const Decl *Pattern, Decl *Inst, |
10201 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
10202 | LocalInstantiationScope *OuterMostScope = nullptr); |
10203 | void updateAttrsForLateParsedTemplate(const Decl *Pattern, Decl *Inst); |
10204 | |
10205 | void |
10206 | InstantiateAttrsForDecl(const MultiLevelTemplateArgumentList &TemplateArgs, |
10207 | const Decl *Pattern, Decl *Inst, |
10208 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
10209 | LocalInstantiationScope *OuterMostScope = nullptr); |
10210 | |
10211 | void InstantiateDefaultCtorDefaultArgs(CXXConstructorDecl *Ctor); |
10212 | |
10213 | bool usesPartialOrExplicitSpecialization( |
10214 | SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec); |
10215 | |
10216 | bool |
10217 | InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, |
10218 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
10219 | TemplateSpecializationKind TSK, |
10220 | bool Complain = true); |
10221 | |
10222 | void InstantiateClassMembers(SourceLocation PointOfInstantiation, |
10223 | CXXRecordDecl *Instantiation, |
10224 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10225 | TemplateSpecializationKind TSK); |
10226 | |
10227 | void InstantiateClassTemplateSpecializationMembers( |
10228 | SourceLocation PointOfInstantiation, |
10229 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
10230 | TemplateSpecializationKind TSK); |
10231 | |
10232 | NestedNameSpecifierLoc |
10233 | SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
10234 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10235 | |
10236 | DeclarationNameInfo |
10237 | SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
10238 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10239 | TemplateName |
10240 | SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, |
10241 | SourceLocation Loc, |
10242 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10243 | |
10244 | bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC, |
10245 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10246 | bool EvaluateConstraint); |
10247 | |
10248 | bool InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD, |
10249 | ParmVarDecl *Param); |
10250 | void InstantiateExceptionSpec(SourceLocation PointOfInstantiation, |
10251 | FunctionDecl *Function); |
10252 | bool CheckInstantiatedFunctionTemplateConstraints( |
10253 | SourceLocation PointOfInstantiation, FunctionDecl *Decl, |
10254 | ArrayRef<TemplateArgument> TemplateArgs, |
10255 | ConstraintSatisfaction &Satisfaction); |
10256 | FunctionDecl *InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD, |
10257 | const TemplateArgumentList *Args, |
10258 | SourceLocation Loc); |
10259 | void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, |
10260 | FunctionDecl *Function, |
10261 | bool Recursive = false, |
10262 | bool DefinitionRequired = false, |
10263 | bool AtEndOfTU = false); |
10264 | VarTemplateSpecializationDecl *BuildVarTemplateInstantiation( |
10265 | VarTemplateDecl *VarTemplate, VarDecl *FromVar, |
10266 | const TemplateArgumentList &TemplateArgList, |
10267 | const TemplateArgumentListInfo &TemplateArgsInfo, |
10268 | SmallVectorImpl<TemplateArgument> &Converted, |
10269 | SourceLocation PointOfInstantiation, |
10270 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
10271 | LocalInstantiationScope *StartingScope = nullptr); |
10272 | VarTemplateSpecializationDecl *CompleteVarTemplateSpecializationDecl( |
10273 | VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl, |
10274 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10275 | void |
10276 | BuildVariableInstantiation(VarDecl *NewVar, VarDecl *OldVar, |
10277 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10278 | LateInstantiatedAttrVec *LateAttrs, |
10279 | DeclContext *Owner, |
10280 | LocalInstantiationScope *StartingScope, |
10281 | bool InstantiatingVarTemplate = false, |
10282 | VarTemplateSpecializationDecl *PrevVTSD = nullptr); |
10283 | |
10284 | void InstantiateVariableInitializer( |
10285 | VarDecl *Var, VarDecl *OldVar, |
10286 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10287 | void InstantiateVariableDefinition(SourceLocation PointOfInstantiation, |
10288 | VarDecl *Var, bool Recursive = false, |
10289 | bool DefinitionRequired = false, |
10290 | bool AtEndOfTU = false); |
10291 | |
10292 | void InstantiateMemInitializers(CXXConstructorDecl *New, |
10293 | const CXXConstructorDecl *Tmpl, |
10294 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10295 | |
10296 | NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, |
10297 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10298 | bool FindingInstantiatedContext = false); |
10299 | DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, |
10300 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10301 | |
10302 | // Objective-C declarations. |
10303 | enum ObjCContainerKind { |
10304 | OCK_None = -1, |
10305 | OCK_Interface = 0, |
10306 | OCK_Protocol, |
10307 | OCK_Category, |
10308 | OCK_ClassExtension, |
10309 | OCK_Implementation, |
10310 | OCK_CategoryImplementation |
10311 | }; |
10312 | ObjCContainerKind getObjCContainerKind() const; |
10313 | |
10314 | DeclResult actOnObjCTypeParam(Scope *S, |
10315 | ObjCTypeParamVariance variance, |
10316 | SourceLocation varianceLoc, |
10317 | unsigned index, |
10318 | IdentifierInfo *paramName, |
10319 | SourceLocation paramLoc, |
10320 | SourceLocation colonLoc, |
10321 | ParsedType typeBound); |
10322 | |
10323 | ObjCTypeParamList *actOnObjCTypeParamList(Scope *S, SourceLocation lAngleLoc, |
10324 | ArrayRef<Decl *> typeParams, |
10325 | SourceLocation rAngleLoc); |
10326 | void popObjCTypeParamList(Scope *S, ObjCTypeParamList *typeParamList); |
10327 | |
10328 | ObjCInterfaceDecl *ActOnStartClassInterface( |
10329 | Scope *S, SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, |
10330 | SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, |
10331 | IdentifierInfo *SuperName, SourceLocation SuperLoc, |
10332 | ArrayRef<ParsedType> SuperTypeArgs, SourceRange SuperTypeArgsRange, |
10333 | Decl *const *ProtoRefs, unsigned NumProtoRefs, |
10334 | const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, |
10335 | const ParsedAttributesView &AttrList, SkipBodyInfo *SkipBody); |
10336 | |
10337 | void ActOnSuperClassOfClassInterface(Scope *S, |
10338 | SourceLocation AtInterfaceLoc, |
10339 | ObjCInterfaceDecl *IDecl, |
10340 | IdentifierInfo *ClassName, |
10341 | SourceLocation ClassLoc, |
10342 | IdentifierInfo *SuperName, |
10343 | SourceLocation SuperLoc, |
10344 | ArrayRef<ParsedType> SuperTypeArgs, |
10345 | SourceRange SuperTypeArgsRange); |
10346 | |
10347 | void ActOnTypedefedProtocols(SmallVectorImpl<Decl *> &ProtocolRefs, |
10348 | SmallVectorImpl<SourceLocation> &ProtocolLocs, |
10349 | IdentifierInfo *SuperName, |
10350 | SourceLocation SuperLoc); |
10351 | |
10352 | Decl *ActOnCompatibilityAlias( |
10353 | SourceLocation AtCompatibilityAliasLoc, |
10354 | IdentifierInfo *AliasName, SourceLocation AliasLocation, |
10355 | IdentifierInfo *ClassName, SourceLocation ClassLocation); |
10356 | |
10357 | bool CheckForwardProtocolDeclarationForCircularDependency( |
10358 | IdentifierInfo *PName, |
10359 | SourceLocation &PLoc, SourceLocation PrevLoc, |
10360 | const ObjCList<ObjCProtocolDecl> &PList); |
10361 | |
10362 | ObjCProtocolDecl *ActOnStartProtocolInterface( |
10363 | SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName, |
10364 | SourceLocation ProtocolLoc, Decl *const *ProtoRefNames, |
10365 | unsigned NumProtoRefs, const SourceLocation *ProtoLocs, |
10366 | SourceLocation EndProtoLoc, const ParsedAttributesView &AttrList, |
10367 | SkipBodyInfo *SkipBody); |
10368 | |
10369 | ObjCCategoryDecl *ActOnStartCategoryInterface( |
10370 | SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, |
10371 | SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, |
10372 | IdentifierInfo *CategoryName, SourceLocation CategoryLoc, |
10373 | Decl *const *ProtoRefs, unsigned NumProtoRefs, |
10374 | const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, |
10375 | const ParsedAttributesView &AttrList); |
10376 | |
10377 | ObjCImplementationDecl *ActOnStartClassImplementation( |
10378 | SourceLocation AtClassImplLoc, IdentifierInfo *ClassName, |
10379 | SourceLocation ClassLoc, IdentifierInfo *SuperClassname, |
10380 | SourceLocation SuperClassLoc, const ParsedAttributesView &AttrList); |
10381 | |
10382 | ObjCCategoryImplDecl *ActOnStartCategoryImplementation( |
10383 | SourceLocation AtCatImplLoc, IdentifierInfo *ClassName, |
10384 | SourceLocation ClassLoc, IdentifierInfo *CatName, SourceLocation CatLoc, |
10385 | const ParsedAttributesView &AttrList); |
10386 | |
10387 | DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, |
10388 | ArrayRef<Decl *> Decls); |
10389 | |
10390 | DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, |
10391 | IdentifierInfo **IdentList, |
10392 | SourceLocation *IdentLocs, |
10393 | ArrayRef<ObjCTypeParamList *> TypeParamLists, |
10394 | unsigned NumElts); |
10395 | |
10396 | DeclGroupPtrTy |
10397 | ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, |
10398 | ArrayRef<IdentifierLocPair> IdentList, |
10399 | const ParsedAttributesView &attrList); |
10400 | |
10401 | void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer, |
10402 | ArrayRef<IdentifierLocPair> ProtocolId, |
10403 | SmallVectorImpl<Decl *> &Protocols); |
10404 | |
10405 | void DiagnoseTypeArgsAndProtocols(IdentifierInfo *ProtocolId, |
10406 | SourceLocation ProtocolLoc, |
10407 | IdentifierInfo *TypeArgId, |
10408 | SourceLocation TypeArgLoc, |
10409 | bool SelectProtocolFirst = false); |
10410 | |
10411 | /// Given a list of identifiers (and their locations), resolve the |
10412 | /// names to either Objective-C protocol qualifiers or type |
10413 | /// arguments, as appropriate. |
10414 | void actOnObjCTypeArgsOrProtocolQualifiers( |
10415 | Scope *S, |
10416 | ParsedType baseType, |
10417 | SourceLocation lAngleLoc, |
10418 | ArrayRef<IdentifierInfo *> identifiers, |
10419 | ArrayRef<SourceLocation> identifierLocs, |
10420 | SourceLocation rAngleLoc, |
10421 | SourceLocation &typeArgsLAngleLoc, |
10422 | SmallVectorImpl<ParsedType> &typeArgs, |
10423 | SourceLocation &typeArgsRAngleLoc, |
10424 | SourceLocation &protocolLAngleLoc, |
10425 | SmallVectorImpl<Decl *> &protocols, |
10426 | SourceLocation &protocolRAngleLoc, |
10427 | bool warnOnIncompleteProtocols); |
10428 | |
10429 | /// Build a an Objective-C protocol-qualified 'id' type where no |
10430 | /// base type was specified. |
10431 | TypeResult actOnObjCProtocolQualifierType( |
10432 | SourceLocation lAngleLoc, |
10433 | ArrayRef<Decl *> protocols, |
10434 | ArrayRef<SourceLocation> protocolLocs, |
10435 | SourceLocation rAngleLoc); |
10436 | |
10437 | /// Build a specialized and/or protocol-qualified Objective-C type. |
10438 | TypeResult actOnObjCTypeArgsAndProtocolQualifiers( |
10439 | Scope *S, |
10440 | SourceLocation Loc, |
10441 | ParsedType BaseType, |
10442 | SourceLocation TypeArgsLAngleLoc, |
10443 | ArrayRef<ParsedType> TypeArgs, |
10444 | SourceLocation TypeArgsRAngleLoc, |
10445 | SourceLocation ProtocolLAngleLoc, |
10446 | ArrayRef<Decl *> Protocols, |
10447 | ArrayRef<SourceLocation> ProtocolLocs, |
10448 | SourceLocation ProtocolRAngleLoc); |
10449 | |
10450 | /// Build an Objective-C type parameter type. |
10451 | QualType BuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, |
10452 | SourceLocation ProtocolLAngleLoc, |
10453 | ArrayRef<ObjCProtocolDecl *> Protocols, |
10454 | ArrayRef<SourceLocation> ProtocolLocs, |
10455 | SourceLocation ProtocolRAngleLoc, |
10456 | bool FailOnError = false); |
10457 | |
10458 | /// Build an Objective-C object pointer type. |
10459 | QualType BuildObjCObjectType( |
10460 | QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, |
10461 | ArrayRef<TypeSourceInfo *> TypeArgs, SourceLocation TypeArgsRAngleLoc, |
10462 | SourceLocation ProtocolLAngleLoc, ArrayRef<ObjCProtocolDecl *> Protocols, |
10463 | ArrayRef<SourceLocation> ProtocolLocs, SourceLocation ProtocolRAngleLoc, |
10464 | bool FailOnError, bool Rebuilding); |
10465 | |
10466 | /// Ensure attributes are consistent with type. |
10467 | /// \param [in, out] Attributes The attributes to check; they will |
10468 | /// be modified to be consistent with \p PropertyTy. |
10469 | void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, |
10470 | SourceLocation Loc, |
10471 | unsigned &Attributes, |
10472 | bool propertyInPrimaryClass); |
10473 | |
10474 | /// Process the specified property declaration and create decls for the |
10475 | /// setters and getters as needed. |
10476 | /// \param property The property declaration being processed |
10477 | void ProcessPropertyDecl(ObjCPropertyDecl *property); |
10478 | |
10479 | |
10480 | void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, |
10481 | ObjCPropertyDecl *SuperProperty, |
10482 | const IdentifierInfo *Name, |
10483 | bool OverridingProtocolProperty); |
10484 | |
10485 | void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, |
10486 | ObjCInterfaceDecl *ID); |
10487 | |
10488 | Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd, |
10489 | ArrayRef<Decl *> allMethods = std::nullopt, |
10490 | ArrayRef<DeclGroupPtrTy> allTUVars = std::nullopt); |
10491 | |
10492 | Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, |
10493 | SourceLocation LParenLoc, |
10494 | FieldDeclarator &FD, ObjCDeclSpec &ODS, |
10495 | Selector GetterSel, Selector SetterSel, |
10496 | tok::ObjCKeywordKind MethodImplKind, |
10497 | DeclContext *lexicalDC = nullptr); |
10498 | |
10499 | Decl *ActOnPropertyImplDecl(Scope *S, |
10500 | SourceLocation AtLoc, |
10501 | SourceLocation PropertyLoc, |
10502 | bool ImplKind, |
10503 | IdentifierInfo *PropertyId, |
10504 | IdentifierInfo *PropertyIvar, |
10505 | SourceLocation PropertyIvarLoc, |
10506 | ObjCPropertyQueryKind QueryKind); |
10507 | |
10508 | enum ObjCSpecialMethodKind { |
10509 | OSMK_None, |
10510 | OSMK_Alloc, |
10511 | OSMK_New, |
10512 | OSMK_Copy, |
10513 | OSMK_RetainingInit, |
10514 | OSMK_NonRetainingInit |
10515 | }; |
10516 | |
10517 | struct ObjCArgInfo { |
10518 | IdentifierInfo *Name; |
10519 | SourceLocation NameLoc; |
10520 | // The Type is null if no type was specified, and the DeclSpec is invalid |
10521 | // in this case. |
10522 | ParsedType Type; |
10523 | ObjCDeclSpec DeclSpec; |
10524 | |
10525 | /// ArgAttrs - Attribute list for this argument. |
10526 | ParsedAttributesView ArgAttrs; |
10527 | }; |
10528 | |
10529 | Decl *ActOnMethodDeclaration( |
10530 | Scope *S, |
10531 | SourceLocation BeginLoc, // location of the + or -. |
10532 | SourceLocation EndLoc, // location of the ; or {. |
10533 | tok::TokenKind MethodType, ObjCDeclSpec &ReturnQT, ParsedType ReturnType, |
10534 | ArrayRef<SourceLocation> SelectorLocs, Selector Sel, |
10535 | // optional arguments. The number of types/arguments is obtained |
10536 | // from the Sel.getNumArgs(). |
10537 | ObjCArgInfo *ArgInfo, DeclaratorChunk::ParamInfo *CParamInfo, |
10538 | unsigned CNumArgs, // c-style args |
10539 | const ParsedAttributesView &AttrList, tok::ObjCKeywordKind MethodImplKind, |
10540 | bool isVariadic, bool MethodDefinition); |
10541 | |
10542 | ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, |
10543 | const ObjCObjectPointerType *OPT, |
10544 | bool IsInstance); |
10545 | ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty, |
10546 | bool IsInstance); |
10547 | |
10548 | bool CheckARCMethodDecl(ObjCMethodDecl *method); |
10549 | bool inferObjCARCLifetime(ValueDecl *decl); |
10550 | |
10551 | void deduceOpenCLAddressSpace(ValueDecl *decl); |
10552 | |
10553 | ExprResult |
10554 | HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, |
10555 | Expr *BaseExpr, |
10556 | SourceLocation OpLoc, |
10557 | DeclarationName MemberName, |
10558 | SourceLocation MemberLoc, |
10559 | SourceLocation SuperLoc, QualType SuperType, |
10560 | bool Super); |
10561 | |
10562 | ExprResult |
10563 | ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, |
10564 | IdentifierInfo &propertyName, |
10565 | SourceLocation receiverNameLoc, |
10566 | SourceLocation propertyNameLoc); |
10567 | |
10568 | ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc); |
10569 | |
10570 | /// Describes the kind of message expression indicated by a message |
10571 | /// send that starts with an identifier. |
10572 | enum ObjCMessageKind { |
10573 | /// The message is sent to 'super'. |
10574 | ObjCSuperMessage, |
10575 | /// The message is an instance message. |
10576 | ObjCInstanceMessage, |
10577 | /// The message is a class message, and the identifier is a type |
10578 | /// name. |
10579 | ObjCClassMessage |
10580 | }; |
10581 | |
10582 | ObjCMessageKind getObjCMessageKind(Scope *S, |
10583 | IdentifierInfo *Name, |
10584 | SourceLocation NameLoc, |
10585 | bool IsSuper, |
10586 | bool HasTrailingDot, |
10587 | ParsedType &ReceiverType); |
10588 | |
10589 | ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, |
10590 | Selector Sel, |
10591 | SourceLocation LBracLoc, |
10592 | ArrayRef<SourceLocation> SelectorLocs, |
10593 | SourceLocation RBracLoc, |
10594 | MultiExprArg Args); |
10595 | |
10596 | ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, |
10597 | QualType ReceiverType, |
10598 | SourceLocation SuperLoc, |
10599 | Selector Sel, |
10600 | ObjCMethodDecl *Method, |
10601 | SourceLocation LBracLoc, |
10602 | ArrayRef<SourceLocation> SelectorLocs, |
10603 | SourceLocation RBracLoc, |
10604 | MultiExprArg Args, |
10605 | bool isImplicit = false); |
10606 | |
10607 | ExprResult BuildClassMessageImplicit(QualType ReceiverType, |
10608 | bool isSuperReceiver, |
10609 | SourceLocation Loc, |
10610 | Selector Sel, |
10611 | ObjCMethodDecl *Method, |
10612 | MultiExprArg Args); |
10613 | |
10614 | ExprResult ActOnClassMessage(Scope *S, |
10615 | ParsedType Receiver, |
10616 | Selector Sel, |
10617 | SourceLocation LBracLoc, |
10618 | ArrayRef<SourceLocation> SelectorLocs, |
10619 | SourceLocation RBracLoc, |
10620 | MultiExprArg Args); |
10621 | |
10622 | ExprResult BuildInstanceMessage(Expr *Receiver, |
10623 | QualType ReceiverType, |
10624 | SourceLocation SuperLoc, |
10625 | Selector Sel, |
10626 | ObjCMethodDecl *Method, |
10627 | SourceLocation LBracLoc, |
10628 | ArrayRef<SourceLocation> SelectorLocs, |
10629 | SourceLocation RBracLoc, |
10630 | MultiExprArg Args, |
10631 | bool isImplicit = false); |
10632 | |
10633 | ExprResult BuildInstanceMessageImplicit(Expr *Receiver, |
10634 | QualType ReceiverType, |
10635 | SourceLocation Loc, |
10636 | Selector Sel, |
10637 | ObjCMethodDecl *Method, |
10638 | MultiExprArg Args); |
10639 | |
10640 | ExprResult ActOnInstanceMessage(Scope *S, |
10641 | Expr *Receiver, |
10642 | Selector Sel, |
10643 | SourceLocation LBracLoc, |
10644 | ArrayRef<SourceLocation> SelectorLocs, |
10645 | SourceLocation RBracLoc, |
10646 | MultiExprArg Args); |
10647 | |
10648 | ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, |
10649 | ObjCBridgeCastKind Kind, |
10650 | SourceLocation BridgeKeywordLoc, |
10651 | TypeSourceInfo *TSInfo, |
10652 | Expr *SubExpr); |
10653 | |
10654 | ExprResult ActOnObjCBridgedCast(Scope *S, |
10655 | SourceLocation LParenLoc, |
10656 | ObjCBridgeCastKind Kind, |
10657 | SourceLocation BridgeKeywordLoc, |
10658 | ParsedType Type, |
10659 | SourceLocation RParenLoc, |
10660 | Expr *SubExpr); |
10661 | |
10662 | void CheckTollFreeBridgeCast(QualType castType, Expr *castExpr); |
10663 | |
10664 | void CheckObjCBridgeRelatedCast(QualType castType, Expr *castExpr); |
10665 | |
10666 | bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr, |
10667 | CastKind &Kind); |
10668 | |
10669 | bool checkObjCBridgeRelatedComponents(SourceLocation Loc, |
10670 | QualType DestType, QualType SrcType, |
10671 | ObjCInterfaceDecl *&RelatedClass, |
10672 | ObjCMethodDecl *&ClassMethod, |
10673 | ObjCMethodDecl *&InstanceMethod, |
10674 | TypedefNameDecl *&TDNDecl, |
10675 | bool CfToNs, bool Diagnose = true); |
10676 | |
10677 | bool CheckObjCBridgeRelatedConversions(SourceLocation Loc, |
10678 | QualType DestType, QualType SrcType, |
10679 | Expr *&SrcExpr, bool Diagnose = true); |
10680 | |
10681 | bool CheckConversionToObjCLiteral(QualType DstType, Expr *&SrcExpr, |
10682 | bool Diagnose = true); |
10683 | |
10684 | bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); |
10685 | |
10686 | /// Check whether the given new method is a valid override of the |
10687 | /// given overridden method, and set any properties that should be inherited. |
10688 | void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, |
10689 | const ObjCMethodDecl *Overridden); |
10690 | |
10691 | /// Describes the compatibility of a result type with its method. |
10692 | enum ResultTypeCompatibilityKind { |
10693 | RTC_Compatible, |
10694 | RTC_Incompatible, |
10695 | RTC_Unknown |
10696 | }; |
10697 | |
10698 | void CheckObjCMethodDirectOverrides(ObjCMethodDecl *method, |
10699 | ObjCMethodDecl *overridden); |
10700 | |
10701 | void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod, |
10702 | ObjCInterfaceDecl *CurrentClass, |
10703 | ResultTypeCompatibilityKind RTC); |
10704 | |
10705 | enum PragmaOptionsAlignKind { |
10706 | POAK_Native, // #pragma options align=native |
10707 | POAK_Natural, // #pragma options align=natural |
10708 | POAK_Packed, // #pragma options align=packed |
10709 | POAK_Power, // #pragma options align=power |
10710 | POAK_Mac68k, // #pragma options align=mac68k |
10711 | POAK_Reset // #pragma options align=reset |
10712 | }; |
10713 | |
10714 | /// ActOnPragmaClangSection - Called on well formed \#pragma clang section |
10715 | void ActOnPragmaClangSection(SourceLocation PragmaLoc, |
10716 | PragmaClangSectionAction Action, |
10717 | PragmaClangSectionKind SecKind, StringRef SecName); |
10718 | |
10719 | /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align. |
10720 | void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, |
10721 | SourceLocation PragmaLoc); |
10722 | |
10723 | /// ActOnPragmaPack - Called on well formed \#pragma pack(...). |
10724 | void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, |
10725 | StringRef SlotLabel, Expr *Alignment); |
10726 | |
10727 | enum class PragmaAlignPackDiagnoseKind { |
10728 | NonDefaultStateAtInclude, |
10729 | ChangedStateAtExit |
10730 | }; |
10731 | |
10732 | void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind, |
10733 | SourceLocation IncludeLoc); |
10734 | void DiagnoseUnterminatedPragmaAlignPack(); |
10735 | |
10736 | /// ActOnPragmaMSStrictGuardStackCheck - Called on well formed \#pragma |
10737 | /// strict_gs_check. |
10738 | void ActOnPragmaMSStrictGuardStackCheck(SourceLocation PragmaLocation, |
10739 | PragmaMsStackAction Action, |
10740 | bool Value); |
10741 | |
10742 | /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off]. |
10743 | void ActOnPragmaMSStruct(PragmaMSStructKind Kind); |
10744 | |
10745 | /// ActOnPragmaMSComment - Called on well formed |
10746 | /// \#pragma comment(kind, "arg"). |
10747 | void (SourceLocation , PragmaMSCommentKind Kind, |
10748 | StringRef Arg); |
10749 | |
10750 | /// ActOnPragmaMSPointersToMembers - called on well formed \#pragma |
10751 | /// pointers_to_members(representation method[, general purpose |
10752 | /// representation]). |
10753 | void ActOnPragmaMSPointersToMembers( |
10754 | LangOptions::PragmaMSPointersToMembersKind Kind, |
10755 | SourceLocation PragmaLoc); |
10756 | |
10757 | /// Called on well formed \#pragma vtordisp(). |
10758 | void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, |
10759 | SourceLocation PragmaLoc, |
10760 | MSVtorDispMode Value); |
10761 | |
10762 | enum PragmaSectionKind { |
10763 | PSK_DataSeg, |
10764 | PSK_BSSSeg, |
10765 | PSK_ConstSeg, |
10766 | PSK_CodeSeg, |
10767 | }; |
10768 | |
10769 | bool UnifySection(StringRef SectionName, int SectionFlags, |
10770 | NamedDecl *TheDecl); |
10771 | bool UnifySection(StringRef SectionName, |
10772 | int SectionFlags, |
10773 | SourceLocation PragmaSectionLocation); |
10774 | |
10775 | /// Called on well formed \#pragma bss_seg/data_seg/const_seg/code_seg. |
10776 | void ActOnPragmaMSSeg(SourceLocation PragmaLocation, |
10777 | PragmaMsStackAction Action, |
10778 | llvm::StringRef StackSlotLabel, |
10779 | StringLiteral *SegmentName, |
10780 | llvm::StringRef PragmaName); |
10781 | |
10782 | /// Called on well formed \#pragma section(). |
10783 | void ActOnPragmaMSSection(SourceLocation PragmaLocation, |
10784 | int SectionFlags, StringLiteral *SegmentName); |
10785 | |
10786 | /// Called on well-formed \#pragma init_seg(). |
10787 | void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, |
10788 | StringLiteral *SegmentName); |
10789 | |
10790 | /// Called on well-formed \#pragma alloc_text(). |
10791 | void ActOnPragmaMSAllocText( |
10792 | SourceLocation PragmaLocation, StringRef Section, |
10793 | const SmallVector<std::tuple<IdentifierInfo *, SourceLocation>> |
10794 | &Functions); |
10795 | |
10796 | /// Called on #pragma clang __debug dump II |
10797 | void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II); |
10798 | |
10799 | /// Called on #pragma clang __debug dump E |
10800 | void ActOnPragmaDump(Expr *E); |
10801 | |
10802 | /// ActOnPragmaDetectMismatch - Call on well-formed \#pragma detect_mismatch |
10803 | void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, |
10804 | StringRef Value); |
10805 | |
10806 | /// Are precise floating point semantics currently enabled? |
10807 | bool isPreciseFPEnabled() { |
10808 | return !CurFPFeatures.getAllowFPReassociate() && |
10809 | !CurFPFeatures.getNoSignedZero() && |
10810 | !CurFPFeatures.getAllowReciprocal() && |
10811 | !CurFPFeatures.getAllowApproxFunc(); |
10812 | } |
10813 | |
10814 | void ActOnPragmaFPEvalMethod(SourceLocation Loc, |
10815 | LangOptions::FPEvalMethodKind Value); |
10816 | |
10817 | /// ActOnPragmaFloatControl - Call on well-formed \#pragma float_control |
10818 | void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, |
10819 | PragmaFloatControlKind Value); |
10820 | |
10821 | /// ActOnPragmaUnused - Called on well-formed '\#pragma unused'. |
10822 | void ActOnPragmaUnused(const Token &Identifier, |
10823 | Scope *curScope, |
10824 | SourceLocation PragmaLoc); |
10825 | |
10826 | /// ActOnPragmaVisibility - Called on well formed \#pragma GCC visibility... . |
10827 | void ActOnPragmaVisibility(const IdentifierInfo* VisType, |
10828 | SourceLocation PragmaLoc); |
10829 | |
10830 | NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, const IdentifierInfo *II, |
10831 | SourceLocation Loc); |
10832 | void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, const WeakInfo &W); |
10833 | |
10834 | /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident. |
10835 | void ActOnPragmaWeakID(IdentifierInfo* WeakName, |
10836 | SourceLocation PragmaLoc, |
10837 | SourceLocation WeakNameLoc); |
10838 | |
10839 | /// ActOnPragmaRedefineExtname - Called on well formed |
10840 | /// \#pragma redefine_extname oldname newname. |
10841 | void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName, |
10842 | IdentifierInfo* AliasName, |
10843 | SourceLocation PragmaLoc, |
10844 | SourceLocation WeakNameLoc, |
10845 | SourceLocation AliasNameLoc); |
10846 | |
10847 | /// ActOnPragmaWeakAlias - Called on well formed \#pragma weak ident = ident. |
10848 | void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, |
10849 | IdentifierInfo* AliasName, |
10850 | SourceLocation PragmaLoc, |
10851 | SourceLocation WeakNameLoc, |
10852 | SourceLocation AliasNameLoc); |
10853 | |
10854 | /// ActOnPragmaFPContract - Called on well formed |
10855 | /// \#pragma {STDC,OPENCL} FP_CONTRACT and |
10856 | /// \#pragma clang fp contract |
10857 | void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC); |
10858 | |
10859 | /// Called on well formed |
10860 | /// \#pragma clang fp reassociate |
10861 | void ActOnPragmaFPReassociate(SourceLocation Loc, bool IsEnabled); |
10862 | |
10863 | /// ActOnPragmaFenvAccess - Called on well formed |
10864 | /// \#pragma STDC FENV_ACCESS |
10865 | void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled); |
10866 | |
10867 | /// Called on well formed '\#pragma clang fp' that has option 'exceptions'. |
10868 | void ActOnPragmaFPExceptions(SourceLocation Loc, |
10869 | LangOptions::FPExceptionModeKind); |
10870 | |
10871 | /// Called to set constant rounding mode for floating point operations. |
10872 | void ActOnPragmaFEnvRound(SourceLocation Loc, llvm::RoundingMode); |
10873 | |
10874 | /// Called to set exception behavior for floating point operations. |
10875 | void setExceptionMode(SourceLocation Loc, LangOptions::FPExceptionModeKind); |
10876 | |
10877 | /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to |
10878 | /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'. |
10879 | void AddAlignmentAttributesForRecord(RecordDecl *RD); |
10880 | |
10881 | /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. |
10882 | void AddMsStructLayoutForRecord(RecordDecl *RD); |
10883 | |
10884 | /// PushNamespaceVisibilityAttr - Note that we've entered a |
10885 | /// namespace with a visibility attribute. |
10886 | void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, |
10887 | SourceLocation Loc); |
10888 | |
10889 | /// AddPushedVisibilityAttribute - If '\#pragma GCC visibility' was used, |
10890 | /// add an appropriate visibility attribute. |
10891 | void AddPushedVisibilityAttribute(Decl *RD); |
10892 | |
10893 | /// PopPragmaVisibility - Pop the top element of the visibility stack; used |
10894 | /// for '\#pragma GCC visibility' and visibility attributes on namespaces. |
10895 | void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc); |
10896 | |
10897 | /// FreeVisContext - Deallocate and null out VisContext. |
10898 | void FreeVisContext(); |
10899 | |
10900 | /// AddCFAuditedAttribute - Check whether we're currently within |
10901 | /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding |
10902 | /// the appropriate attribute. |
10903 | void AddCFAuditedAttribute(Decl *D); |
10904 | |
10905 | void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, |
10906 | SourceLocation PragmaLoc, |
10907 | attr::ParsedSubjectMatchRuleSet Rules); |
10908 | void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, |
10909 | const IdentifierInfo *Namespace); |
10910 | |
10911 | /// Called on well-formed '\#pragma clang attribute pop'. |
10912 | void ActOnPragmaAttributePop(SourceLocation PragmaLoc, |
10913 | const IdentifierInfo *Namespace); |
10914 | |
10915 | /// Adds the attributes that have been specified using the |
10916 | /// '\#pragma clang attribute push' directives to the given declaration. |
10917 | void AddPragmaAttributes(Scope *S, Decl *D); |
10918 | |
10919 | void DiagnoseUnterminatedPragmaAttribute(); |
10920 | |
10921 | /// Called on well formed \#pragma clang optimize. |
10922 | void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc); |
10923 | |
10924 | /// #pragma optimize("[optimization-list]", on | off). |
10925 | void ActOnPragmaMSOptimize(SourceLocation Loc, bool IsOn); |
10926 | |
10927 | /// Call on well formed \#pragma function. |
10928 | void |
10929 | ActOnPragmaMSFunction(SourceLocation Loc, |
10930 | const llvm::SmallVectorImpl<StringRef> &NoBuiltins); |
10931 | |
10932 | /// Get the location for the currently active "\#pragma clang optimize |
10933 | /// off". If this location is invalid, then the state of the pragma is "on". |
10934 | SourceLocation getOptimizeOffPragmaLocation() const { |
10935 | return OptimizeOffPragmaLocation; |
10936 | } |
10937 | |
10938 | /// Only called on function definitions; if there is a pragma in scope |
10939 | /// with the effect of a range-based optnone, consider marking the function |
10940 | /// with attribute optnone. |
10941 | void AddRangeBasedOptnone(FunctionDecl *FD); |
10942 | |
10943 | /// Only called on function definitions; if there is a `#pragma alloc_text` |
10944 | /// that decides which code section the function should be in, add |
10945 | /// attribute section to the function. |
10946 | void AddSectionMSAllocText(FunctionDecl *FD); |
10947 | |
10948 | /// Adds the 'optnone' attribute to the function declaration if there |
10949 | /// are no conflicts; Loc represents the location causing the 'optnone' |
10950 | /// attribute to be added (usually because of a pragma). |
10951 | void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc); |
10952 | |
10953 | /// Only called on function definitions; if there is a MSVC #pragma optimize |
10954 | /// in scope, consider changing the function's attributes based on the |
10955 | /// optimization list passed to the pragma. |
10956 | void ModifyFnAttributesMSPragmaOptimize(FunctionDecl *FD); |
10957 | |
10958 | /// Only called on function definitions; if there is a pragma in scope |
10959 | /// with the effect of a range-based no_builtin, consider marking the function |
10960 | /// with attribute no_builtin. |
10961 | void AddImplicitMSFunctionNoBuiltinAttr(FunctionDecl *FD); |
10962 | |
10963 | /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. |
10964 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
10965 | bool IsPackExpansion); |
10966 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, TypeSourceInfo *T, |
10967 | bool IsPackExpansion); |
10968 | |
10969 | /// AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular |
10970 | /// declaration. |
10971 | void AddAssumeAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
10972 | Expr *OE); |
10973 | |
10974 | /// AddAllocAlignAttr - Adds an alloc_align attribute to a particular |
10975 | /// declaration. |
10976 | void AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI, |
10977 | Expr *ParamExpr); |
10978 | |
10979 | /// AddAlignValueAttr - Adds an align_value attribute to a particular |
10980 | /// declaration. |
10981 | void AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E); |
10982 | |
10983 | /// AddAnnotationAttr - Adds an annotation Annot with Args arguments to D. |
10984 | void AddAnnotationAttr(Decl *D, const AttributeCommonInfo &CI, |
10985 | StringRef Annot, MutableArrayRef<Expr *> Args); |
10986 | |
10987 | /// ConstantFoldAttrArgs - Folds attribute arguments into ConstantExprs |
10988 | /// (unless they are value dependent or type dependent). Returns false |
10989 | /// and emits a diagnostic if one or more of the arguments could not be |
10990 | /// folded into a constant. |
10991 | bool ConstantFoldAttrArgs(const AttributeCommonInfo &CI, |
10992 | MutableArrayRef<Expr *> Args); |
10993 | |
10994 | /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular |
10995 | /// declaration. |
10996 | void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI, |
10997 | Expr *MaxThreads, Expr *MinBlocks); |
10998 | |
10999 | /// AddModeAttr - Adds a mode attribute to a particular declaration. |
11000 | void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Name, |
11001 | bool InInstantiation = false); |
11002 | |
11003 | void AddParameterABIAttr(Decl *D, const AttributeCommonInfo &CI, |
11004 | ParameterABI ABI); |
11005 | |
11006 | enum class RetainOwnershipKind {NS, CF, OS}; |
11007 | void AddXConsumedAttr(Decl *D, const AttributeCommonInfo &CI, |
11008 | RetainOwnershipKind K, bool IsTemplateInstantiation); |
11009 | |
11010 | /// addAMDGPUFlatWorkGroupSizeAttr - Adds an amdgpu_flat_work_group_size |
11011 | /// attribute to a particular declaration. |
11012 | void addAMDGPUFlatWorkGroupSizeAttr(Decl *D, const AttributeCommonInfo &CI, |
11013 | Expr *Min, Expr *Max); |
11014 | |
11015 | /// addAMDGPUWavePersEUAttr - Adds an amdgpu_waves_per_eu attribute to a |
11016 | /// particular declaration. |
11017 | void addAMDGPUWavesPerEUAttr(Decl *D, const AttributeCommonInfo &CI, |
11018 | Expr *Min, Expr *Max); |
11019 | |
11020 | bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type); |
11021 | |
11022 | //===--------------------------------------------------------------------===// |
11023 | // C++ Coroutines |
11024 | // |
11025 | bool ActOnCoroutineBodyStart(Scope *S, SourceLocation KwLoc, |
11026 | StringRef Keyword); |
11027 | ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
11028 | ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
11029 | StmtResult ActOnCoreturnStmt(Scope *S, SourceLocation KwLoc, Expr *E); |
11030 | |
11031 | ExprResult BuildOperatorCoawaitLookupExpr(Scope *S, SourceLocation Loc); |
11032 | ExprResult BuildOperatorCoawaitCall(SourceLocation Loc, Expr *E, |
11033 | UnresolvedLookupExpr *Lookup); |
11034 | ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, |
11035 | Expr *Awaiter, bool IsImplicit = false); |
11036 | ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, |
11037 | UnresolvedLookupExpr *Lookup); |
11038 | ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E); |
11039 | StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E, |
11040 | bool IsImplicit = false); |
11041 | StmtResult BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs); |
11042 | bool buildCoroutineParameterMoves(SourceLocation Loc); |
11043 | VarDecl *buildCoroutinePromise(SourceLocation Loc); |
11044 | void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body); |
11045 | /// Lookup 'coroutine_traits' in std namespace and std::experimental |
11046 | /// namespace. The namespace found is recorded in Namespace. |
11047 | ClassTemplateDecl *lookupCoroutineTraits(SourceLocation KwLoc, |
11048 | SourceLocation FuncLoc); |
11049 | /// Check that the expression co_await promise.final_suspend() shall not be |
11050 | /// potentially-throwing. |
11051 | bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend); |
11052 | |
11053 | //===--------------------------------------------------------------------===// |
11054 | // OpenMP directives and clauses. |
11055 | // |
11056 | private: |
11057 | void *VarDataSharingAttributesStack; |
11058 | |
11059 | struct DeclareTargetContextInfo { |
11060 | struct MapInfo { |
11061 | OMPDeclareTargetDeclAttr::MapTypeTy MT; |
11062 | SourceLocation Loc; |
11063 | }; |
11064 | /// Explicitly listed variables and functions in a 'to' or 'link' clause. |
11065 | llvm::DenseMap<NamedDecl *, MapInfo> ExplicitlyMapped; |
11066 | |
11067 | /// The 'device_type' as parsed from the clause. |
11068 | OMPDeclareTargetDeclAttr::DevTypeTy DT = OMPDeclareTargetDeclAttr::DT_Any; |
11069 | |
11070 | /// The directive kind, `begin declare target` or `declare target`. |
11071 | OpenMPDirectiveKind Kind; |
11072 | |
11073 | /// The directive with indirect clause. |
11074 | std::optional<Expr *> Indirect; |
11075 | |
11076 | /// The directive location. |
11077 | SourceLocation Loc; |
11078 | |
11079 | DeclareTargetContextInfo(OpenMPDirectiveKind Kind, SourceLocation Loc) |
11080 | : Kind(Kind), Loc(Loc) {} |
11081 | }; |
11082 | |
11083 | /// Number of nested '#pragma omp declare target' directives. |
11084 | SmallVector<DeclareTargetContextInfo, 4> DeclareTargetNesting; |
11085 | |
11086 | /// Initialization of data-sharing attributes stack. |
11087 | void InitDataSharingAttributesStack(); |
11088 | void DestroyDataSharingAttributesStack(); |
11089 | |
11090 | /// Returns OpenMP nesting level for current directive. |
11091 | unsigned getOpenMPNestingLevel() const; |
11092 | |
11093 | /// Adjusts the function scopes index for the target-based regions. |
11094 | void adjustOpenMPTargetScopeIndex(unsigned &FunctionScopesIndex, |
11095 | unsigned Level) const; |
11096 | |
11097 | /// Returns the number of scopes associated with the construct on the given |
11098 | /// OpenMP level. |
11099 | int getNumberOfConstructScopes(unsigned Level) const; |
11100 | |
11101 | /// Push new OpenMP function region for non-capturing function. |
11102 | void pushOpenMPFunctionRegion(); |
11103 | |
11104 | /// Pop OpenMP function region for non-capturing function. |
11105 | void popOpenMPFunctionRegion(const sema::FunctionScopeInfo *OldFSI); |
11106 | |
11107 | /// Analyzes and checks a loop nest for use by a loop transformation. |
11108 | /// |
11109 | /// \param Kind The loop transformation directive kind. |
11110 | /// \param NumLoops How many nested loops the directive is expecting. |
11111 | /// \param AStmt Associated statement of the transformation directive. |
11112 | /// \param LoopHelpers [out] The loop analysis result. |
11113 | /// \param Body [out] The body code nested in \p NumLoops loop. |
11114 | /// \param OriginalInits [out] Collection of statements and declarations that |
11115 | /// must have been executed/declared before entering the |
11116 | /// loop. |
11117 | /// |
11118 | /// \return Whether there was any error. |
11119 | bool checkTransformableLoopNest( |
11120 | OpenMPDirectiveKind Kind, Stmt *AStmt, int NumLoops, |
11121 | SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers, |
11122 | Stmt *&Body, |
11123 | SmallVectorImpl<SmallVector<llvm::PointerUnion<Stmt *, Decl *>, 0>> |
11124 | &OriginalInits); |
11125 | |
11126 | /// Helper to keep information about the current `omp begin/end declare |
11127 | /// variant` nesting. |
11128 | struct OMPDeclareVariantScope { |
11129 | /// The associated OpenMP context selector. |
11130 | OMPTraitInfo *TI; |
11131 | |
11132 | /// The associated OpenMP context selector mangling. |
11133 | std::string NameSuffix; |
11134 | |
11135 | OMPDeclareVariantScope(OMPTraitInfo &TI); |
11136 | }; |
11137 | |
11138 | /// Return the OMPTraitInfo for the surrounding scope, if any. |
11139 | OMPTraitInfo *getOMPTraitInfoForSurroundingScope() { |
11140 | return OMPDeclareVariantScopes.empty() ? nullptr |
11141 | : OMPDeclareVariantScopes.back().TI; |
11142 | } |
11143 | |
11144 | /// The current `omp begin/end declare variant` scopes. |
11145 | SmallVector<OMPDeclareVariantScope, 4> OMPDeclareVariantScopes; |
11146 | |
11147 | /// The current `omp begin/end assumes` scopes. |
11148 | SmallVector<AssumptionAttr *, 4> OMPAssumeScoped; |
11149 | |
11150 | /// All `omp assumes` we encountered so far. |
11151 | SmallVector<AssumptionAttr *, 4> OMPAssumeGlobal; |
11152 | |
11153 | public: |
11154 | /// The declarator \p D defines a function in the scope \p S which is nested |
11155 | /// in an `omp begin/end declare variant` scope. In this method we create a |
11156 | /// declaration for \p D and rename \p D according to the OpenMP context |
11157 | /// selector of the surrounding scope. Return all base functions in \p Bases. |
11158 | void ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope( |
11159 | Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists, |
11160 | SmallVectorImpl<FunctionDecl *> &Bases); |
11161 | |
11162 | /// Register \p D as specialization of all base functions in \p Bases in the |
11163 | /// current `omp begin/end declare variant` scope. |
11164 | void ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope( |
11165 | Decl *D, SmallVectorImpl<FunctionDecl *> &Bases); |
11166 | |
11167 | /// Act on \p D, a function definition inside of an `omp [begin/end] assumes`. |
11168 | void ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Decl *D); |
11169 | |
11170 | /// Can we exit an OpenMP declare variant scope at the moment. |
11171 | bool isInOpenMPDeclareVariantScope() const { |
11172 | return !OMPDeclareVariantScopes.empty(); |
11173 | } |
11174 | |
11175 | ExprResult |
11176 | VerifyPositiveIntegerConstantInClause(Expr *Op, OpenMPClauseKind CKind, |
11177 | bool StrictlyPositive = true, |
11178 | bool SuppressExprDiags = false); |
11179 | |
11180 | /// Given the potential call expression \p Call, determine if there is a |
11181 | /// specialization via the OpenMP declare variant mechanism available. If |
11182 | /// there is, return the specialized call expression, otherwise return the |
11183 | /// original \p Call. |
11184 | ExprResult ActOnOpenMPCall(ExprResult Call, Scope *Scope, |
11185 | SourceLocation LParenLoc, MultiExprArg ArgExprs, |
11186 | SourceLocation RParenLoc, Expr *ExecConfig); |
11187 | |
11188 | /// Handle a `omp begin declare variant`. |
11189 | void ActOnOpenMPBeginDeclareVariant(SourceLocation Loc, OMPTraitInfo &TI); |
11190 | |
11191 | /// Handle a `omp end declare variant`. |
11192 | void ActOnOpenMPEndDeclareVariant(); |
11193 | |
11194 | /// Checks if the variant/multiversion functions are compatible. |
11195 | bool areMultiversionVariantFunctionsCompatible( |
11196 | const FunctionDecl *OldFD, const FunctionDecl *NewFD, |
11197 | const PartialDiagnostic &NoProtoDiagID, |
11198 | const PartialDiagnosticAt &NoteCausedDiagIDAt, |
11199 | const PartialDiagnosticAt &NoSupportDiagIDAt, |
11200 | const PartialDiagnosticAt &DiffDiagIDAt, bool TemplatesSupported, |
11201 | bool ConstexprSupported, bool CLinkageMayDiffer); |
11202 | |
11203 | /// Function tries to capture lambda's captured variables in the OpenMP region |
11204 | /// before the original lambda is captured. |
11205 | void tryCaptureOpenMPLambdas(ValueDecl *V); |
11206 | |
11207 | /// Return true if the provided declaration \a VD should be captured by |
11208 | /// reference. |
11209 | /// \param Level Relative level of nested OpenMP construct for that the check |
11210 | /// is performed. |
11211 | /// \param OpenMPCaptureLevel Capture level within an OpenMP construct. |
11212 | bool isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level, |
11213 | unsigned OpenMPCaptureLevel) const; |
11214 | |
11215 | /// Check if the specified variable is used in one of the private |
11216 | /// clauses (private, firstprivate, lastprivate, reduction etc.) in OpenMP |
11217 | /// constructs. |
11218 | VarDecl *isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo = false, |
11219 | unsigned StopAt = 0); |
11220 | |
11221 | /// The member expression(this->fd) needs to be rebuilt in the template |
11222 | /// instantiation to generate private copy for OpenMP when default |
11223 | /// clause is used. The function will return true if default |
11224 | /// cluse is used. |
11225 | bool isOpenMPRebuildMemberExpr(ValueDecl *D); |
11226 | |
11227 | ExprResult getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
11228 | ExprObjectKind OK, SourceLocation Loc); |
11229 | |
11230 | /// If the current region is a loop-based region, mark the start of the loop |
11231 | /// construct. |
11232 | void startOpenMPLoop(); |
11233 | |
11234 | /// If the current region is a range loop-based region, mark the start of the |
11235 | /// loop construct. |
11236 | void startOpenMPCXXRangeFor(); |
11237 | |
11238 | /// Check if the specified variable is used in 'private' clause. |
11239 | /// \param Level Relative level of nested OpenMP construct for that the check |
11240 | /// is performed. |
11241 | OpenMPClauseKind isOpenMPPrivateDecl(ValueDecl *D, unsigned Level, |
11242 | unsigned CapLevel) const; |
11243 | |
11244 | /// Sets OpenMP capture kind (OMPC_private, OMPC_firstprivate, OMPC_map etc.) |
11245 | /// for \p FD based on DSA for the provided corresponding captured declaration |
11246 | /// \p D. |
11247 | void setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, unsigned Level); |
11248 | |
11249 | /// Check if the specified variable is captured by 'target' directive. |
11250 | /// \param Level Relative level of nested OpenMP construct for that the check |
11251 | /// is performed. |
11252 | bool isOpenMPTargetCapturedDecl(const ValueDecl *D, unsigned Level, |
11253 | unsigned CaptureLevel) const; |
11254 | |
11255 | /// Check if the specified global variable must be captured by outer capture |
11256 | /// regions. |
11257 | /// \param Level Relative level of nested OpenMP construct for that |
11258 | /// the check is performed. |
11259 | bool isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level, |
11260 | unsigned CaptureLevel) const; |
11261 | |
11262 | ExprResult PerformOpenMPImplicitIntegerConversion(SourceLocation OpLoc, |
11263 | Expr *Op); |
11264 | /// Called on start of new data sharing attribute block. |
11265 | void StartOpenMPDSABlock(OpenMPDirectiveKind K, |
11266 | const DeclarationNameInfo &DirName, Scope *CurScope, |
11267 | SourceLocation Loc); |
11268 | /// Start analysis of clauses. |
11269 | void StartOpenMPClause(OpenMPClauseKind K); |
11270 | /// End analysis of clauses. |
11271 | void EndOpenMPClause(); |
11272 | /// Called on end of data sharing attribute block. |
11273 | void EndOpenMPDSABlock(Stmt *CurDirective); |
11274 | |
11275 | /// Check if the current region is an OpenMP loop region and if it is, |
11276 | /// mark loop control variable, used in \p Init for loop initialization, as |
11277 | /// private by default. |
11278 | /// \param Init First part of the for loop. |
11279 | void ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init); |
11280 | |
11281 | /// Called on well-formed '\#pragma omp metadirective' after parsing |
11282 | /// of the associated statement. |
11283 | StmtResult ActOnOpenMPMetaDirective(ArrayRef<OMPClause *> Clauses, |
11284 | Stmt *AStmt, SourceLocation StartLoc, |
11285 | SourceLocation EndLoc); |
11286 | |
11287 | // OpenMP directives and clauses. |
11288 | /// Called on correct id-expression from the '#pragma omp |
11289 | /// threadprivate'. |
11290 | ExprResult ActOnOpenMPIdExpression(Scope *CurScope, CXXScopeSpec &ScopeSpec, |
11291 | const DeclarationNameInfo &Id, |
11292 | OpenMPDirectiveKind Kind); |
11293 | /// Called on well-formed '#pragma omp threadprivate'. |
11294 | DeclGroupPtrTy ActOnOpenMPThreadprivateDirective( |
11295 | SourceLocation Loc, |
11296 | ArrayRef<Expr *> VarList); |
11297 | /// Builds a new OpenMPThreadPrivateDecl and checks its correctness. |
11298 | OMPThreadPrivateDecl *CheckOMPThreadPrivateDecl(SourceLocation Loc, |
11299 | ArrayRef<Expr *> VarList); |
11300 | /// Called on well-formed '#pragma omp allocate'. |
11301 | DeclGroupPtrTy ActOnOpenMPAllocateDirective(SourceLocation Loc, |
11302 | ArrayRef<Expr *> VarList, |
11303 | ArrayRef<OMPClause *> Clauses, |
11304 | DeclContext *Owner = nullptr); |
11305 | |
11306 | /// Called on well-formed '#pragma omp [begin] assume[s]'. |
11307 | void ActOnOpenMPAssumesDirective(SourceLocation Loc, |
11308 | OpenMPDirectiveKind DKind, |
11309 | ArrayRef<std::string> Assumptions, |
11310 | bool SkippedClauses); |
11311 | |
11312 | /// Check if there is an active global `omp begin assumes` directive. |
11313 | bool isInOpenMPAssumeScope() const { return !OMPAssumeScoped.empty(); } |
11314 | |
11315 | /// Check if there is an active global `omp assumes` directive. |
11316 | bool hasGlobalOpenMPAssumes() const { return !OMPAssumeGlobal.empty(); } |
11317 | |
11318 | /// Called on well-formed '#pragma omp end assumes'. |
11319 | void ActOnOpenMPEndAssumesDirective(); |
11320 | |
11321 | /// Called on well-formed '#pragma omp requires'. |
11322 | DeclGroupPtrTy ActOnOpenMPRequiresDirective(SourceLocation Loc, |
11323 | ArrayRef<OMPClause *> ClauseList); |
11324 | /// Check restrictions on Requires directive |
11325 | OMPRequiresDecl *CheckOMPRequiresDecl(SourceLocation Loc, |
11326 | ArrayRef<OMPClause *> Clauses); |
11327 | /// Check if the specified type is allowed to be used in 'omp declare |
11328 | /// reduction' construct. |
11329 | QualType ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
11330 | TypeResult ParsedType); |
11331 | /// Called on start of '#pragma omp declare reduction'. |
11332 | DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveStart( |
11333 | Scope *S, DeclContext *DC, DeclarationName Name, |
11334 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
11335 | AccessSpecifier AS, Decl *PrevDeclInScope = nullptr); |
11336 | /// Initialize declare reduction construct initializer. |
11337 | void ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D); |
11338 | /// Finish current declare reduction construct initializer. |
11339 | void ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner); |
11340 | /// Initialize declare reduction construct initializer. |
11341 | /// \return omp_priv variable. |
11342 | VarDecl *ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D); |
11343 | /// Finish current declare reduction construct initializer. |
11344 | void ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, Expr *Initializer, |
11345 | VarDecl *OmpPrivParm); |
11346 | /// Called at the end of '#pragma omp declare reduction'. |
11347 | DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveEnd( |
11348 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid); |
11349 | |
11350 | /// Check variable declaration in 'omp declare mapper' construct. |
11351 | TypeResult ActOnOpenMPDeclareMapperVarDecl(Scope *S, Declarator &D); |
11352 | /// Check if the specified type is allowed to be used in 'omp declare |
11353 | /// mapper' construct. |
11354 | QualType ActOnOpenMPDeclareMapperType(SourceLocation TyLoc, |
11355 | TypeResult ParsedType); |
11356 | /// Called on start of '#pragma omp declare mapper'. |
11357 | DeclGroupPtrTy ActOnOpenMPDeclareMapperDirective( |
11358 | Scope *S, DeclContext *DC, DeclarationName Name, QualType MapperType, |
11359 | SourceLocation StartLoc, DeclarationName VN, AccessSpecifier AS, |
11360 | Expr *MapperVarRef, ArrayRef<OMPClause *> Clauses, |
11361 | Decl *PrevDeclInScope = nullptr); |
11362 | /// Build the mapper variable of '#pragma omp declare mapper'. |
11363 | ExprResult ActOnOpenMPDeclareMapperDirectiveVarDecl(Scope *S, |
11364 | QualType MapperType, |
11365 | SourceLocation StartLoc, |
11366 | DeclarationName VN); |
11367 | void ActOnOpenMPIteratorVarDecl(VarDecl *VD); |
11368 | bool isOpenMPDeclareMapperVarDeclAllowed(const VarDecl *VD) const; |
11369 | const ValueDecl *getOpenMPDeclareMapperVarName() const; |
11370 | |
11371 | /// Called on the start of target region i.e. '#pragma omp declare target'. |
11372 | bool ActOnStartOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI); |
11373 | |
11374 | /// Called at the end of target region i.e. '#pragma omp end declare target'. |
11375 | const DeclareTargetContextInfo ActOnOpenMPEndDeclareTargetDirective(); |
11376 | |
11377 | /// Called once a target context is completed, that can be when a |
11378 | /// '#pragma omp end declare target' was encountered or when a |
11379 | /// '#pragma omp declare target' without declaration-definition-seq was |
11380 | /// encountered. |
11381 | void ActOnFinishedOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI); |
11382 | |
11383 | /// Report unterminated 'omp declare target' or 'omp begin declare target' at |
11384 | /// the end of a compilation unit. |
11385 | void DiagnoseUnterminatedOpenMPDeclareTarget(); |
11386 | |
11387 | /// Searches for the provided declaration name for OpenMP declare target |
11388 | /// directive. |
11389 | NamedDecl *lookupOpenMPDeclareTargetName(Scope *CurScope, |
11390 | CXXScopeSpec &ScopeSpec, |
11391 | const DeclarationNameInfo &Id); |
11392 | |
11393 | /// Called on correct id-expression from the '#pragma omp declare target'. |
11394 | void ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc, |
11395 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
11396 | DeclareTargetContextInfo &DTCI); |
11397 | |
11398 | /// Check declaration inside target region. |
11399 | void |
11400 | checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, |
11401 | SourceLocation IdLoc = SourceLocation()); |
11402 | |
11403 | /// Adds OMPDeclareTargetDeclAttr to referenced variables in declare target |
11404 | /// directive. |
11405 | void ActOnOpenMPDeclareTargetInitializer(Decl *D); |
11406 | |
11407 | /// Finishes analysis of the deferred functions calls that may be declared as |
11408 | /// host/nohost during device/host compilation. |
11409 | void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller, |
11410 | const FunctionDecl *Callee, |
11411 | SourceLocation Loc); |
11412 | |
11413 | /// Return true if currently in OpenMP task with untied clause context. |
11414 | bool isInOpenMPTaskUntiedContext() const; |
11415 | |
11416 | /// Return true inside OpenMP declare target region. |
11417 | bool isInOpenMPDeclareTargetContext() const { |
11418 | return !DeclareTargetNesting.empty(); |
11419 | } |
11420 | /// Return true inside OpenMP target region. |
11421 | bool isInOpenMPTargetExecutionDirective() const; |
11422 | |
11423 | /// Return the number of captured regions created for an OpenMP directive. |
11424 | static int getOpenMPCaptureLevels(OpenMPDirectiveKind Kind); |
11425 | |
11426 | /// Initialization of captured region for OpenMP region. |
11427 | void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope); |
11428 | |
11429 | /// Called for syntactical loops (ForStmt or CXXForRangeStmt) associated to |
11430 | /// an OpenMP loop directive. |
11431 | StmtResult ActOnOpenMPCanonicalLoop(Stmt *AStmt); |
11432 | |
11433 | /// Process a canonical OpenMP loop nest that can either be a canonical |
11434 | /// literal loop (ForStmt or CXXForRangeStmt), or the generated loop of an |
11435 | /// OpenMP loop transformation construct. |
11436 | StmtResult ActOnOpenMPLoopnest(Stmt *AStmt); |
11437 | |
11438 | /// End of OpenMP region. |
11439 | /// |
11440 | /// \param S Statement associated with the current OpenMP region. |
11441 | /// \param Clauses List of clauses for the current OpenMP region. |
11442 | /// |
11443 | /// \returns Statement for finished OpenMP region. |
11444 | StmtResult ActOnOpenMPRegionEnd(StmtResult S, ArrayRef<OMPClause *> Clauses); |
11445 | StmtResult ActOnOpenMPExecutableDirective( |
11446 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
11447 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
11448 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc); |
11449 | /// Called on well-formed '\#pragma omp parallel' after parsing |
11450 | /// of the associated statement. |
11451 | StmtResult ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
11452 | Stmt *AStmt, |
11453 | SourceLocation StartLoc, |
11454 | SourceLocation EndLoc); |
11455 | using VarsWithInheritedDSAType = |
11456 | llvm::SmallDenseMap<const ValueDecl *, const Expr *, 4>; |
11457 | /// Called on well-formed '\#pragma omp simd' after parsing |
11458 | /// of the associated statement. |
11459 | StmtResult |
11460 | ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
11461 | SourceLocation StartLoc, SourceLocation EndLoc, |
11462 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11463 | /// Called on well-formed '#pragma omp tile' after parsing of its clauses and |
11464 | /// the associated statement. |
11465 | StmtResult ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses, |
11466 | Stmt *AStmt, SourceLocation StartLoc, |
11467 | SourceLocation EndLoc); |
11468 | /// Called on well-formed '#pragma omp unroll' after parsing of its clauses |
11469 | /// and the associated statement. |
11470 | StmtResult ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses, |
11471 | Stmt *AStmt, SourceLocation StartLoc, |
11472 | SourceLocation EndLoc); |
11473 | /// Called on well-formed '\#pragma omp for' after parsing |
11474 | /// of the associated statement. |
11475 | StmtResult |
11476 | ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
11477 | SourceLocation StartLoc, SourceLocation EndLoc, |
11478 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11479 | /// Called on well-formed '\#pragma omp for simd' after parsing |
11480 | /// of the associated statement. |
11481 | StmtResult |
11482 | ActOnOpenMPForSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
11483 | SourceLocation StartLoc, SourceLocation EndLoc, |
11484 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11485 | /// Called on well-formed '\#pragma omp sections' after parsing |
11486 | /// of the associated statement. |
11487 | StmtResult ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
11488 | Stmt *AStmt, SourceLocation StartLoc, |
11489 | SourceLocation EndLoc); |
11490 | /// Called on well-formed '\#pragma omp section' after parsing of the |
11491 | /// associated statement. |
11492 | StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc, |
11493 | SourceLocation EndLoc); |
11494 | /// Called on well-formed '\#pragma omp single' after parsing of the |
11495 | /// associated statement. |
11496 | StmtResult ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
11497 | Stmt *AStmt, SourceLocation StartLoc, |
11498 | SourceLocation EndLoc); |
11499 | /// Called on well-formed '\#pragma omp master' after parsing of the |
11500 | /// associated statement. |
11501 | StmtResult ActOnOpenMPMasterDirective(Stmt *AStmt, SourceLocation StartLoc, |
11502 | SourceLocation EndLoc); |
11503 | /// Called on well-formed '\#pragma omp critical' after parsing of the |
11504 | /// associated statement. |
11505 | StmtResult ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
11506 | ArrayRef<OMPClause *> Clauses, |
11507 | Stmt *AStmt, SourceLocation StartLoc, |
11508 | SourceLocation EndLoc); |
11509 | /// Called on well-formed '\#pragma omp parallel for' after parsing |
11510 | /// of the associated statement. |
11511 | StmtResult ActOnOpenMPParallelForDirective( |
11512 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11513 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11514 | /// Called on well-formed '\#pragma omp parallel for simd' after |
11515 | /// parsing of the associated statement. |
11516 | StmtResult ActOnOpenMPParallelForSimdDirective( |
11517 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11518 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11519 | /// Called on well-formed '\#pragma omp parallel master' after |
11520 | /// parsing of the associated statement. |
11521 | StmtResult ActOnOpenMPParallelMasterDirective(ArrayRef<OMPClause *> Clauses, |
11522 | Stmt *AStmt, |
11523 | SourceLocation StartLoc, |
11524 | SourceLocation EndLoc); |
11525 | /// Called on well-formed '\#pragma omp parallel masked' after |
11526 | /// parsing of the associated statement. |
11527 | StmtResult ActOnOpenMPParallelMaskedDirective(ArrayRef<OMPClause *> Clauses, |
11528 | Stmt *AStmt, |
11529 | SourceLocation StartLoc, |
11530 | SourceLocation EndLoc); |
11531 | /// Called on well-formed '\#pragma omp parallel sections' after |
11532 | /// parsing of the associated statement. |
11533 | StmtResult ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
11534 | Stmt *AStmt, |
11535 | SourceLocation StartLoc, |
11536 | SourceLocation EndLoc); |
11537 | /// Called on well-formed '\#pragma omp task' after parsing of the |
11538 | /// associated statement. |
11539 | StmtResult ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
11540 | Stmt *AStmt, SourceLocation StartLoc, |
11541 | SourceLocation EndLoc); |
11542 | /// Called on well-formed '\#pragma omp taskyield'. |
11543 | StmtResult ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
11544 | SourceLocation EndLoc); |
11545 | /// Called on well-formed '\#pragma omp error'. |
11546 | /// Error direcitive is allowed in both declared and excutable contexts. |
11547 | /// Adding InExContext to identify which context is called from. |
11548 | StmtResult ActOnOpenMPErrorDirective(ArrayRef<OMPClause *> Clauses, |
11549 | SourceLocation StartLoc, |
11550 | SourceLocation EndLoc, |
11551 | bool InExContext = true); |
11552 | /// Called on well-formed '\#pragma omp barrier'. |
11553 | StmtResult ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
11554 | SourceLocation EndLoc); |
11555 | /// Called on well-formed '\#pragma omp taskwait'. |
11556 | StmtResult ActOnOpenMPTaskwaitDirective(ArrayRef<OMPClause *> Clauses, |
11557 | SourceLocation StartLoc, |
11558 | SourceLocation EndLoc); |
11559 | /// Called on well-formed '\#pragma omp taskgroup'. |
11560 | StmtResult ActOnOpenMPTaskgroupDirective(ArrayRef<OMPClause *> Clauses, |
11561 | Stmt *AStmt, SourceLocation StartLoc, |
11562 | SourceLocation EndLoc); |
11563 | /// Called on well-formed '\#pragma omp flush'. |
11564 | StmtResult ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
11565 | SourceLocation StartLoc, |
11566 | SourceLocation EndLoc); |
11567 | /// Called on well-formed '\#pragma omp depobj'. |
11568 | StmtResult ActOnOpenMPDepobjDirective(ArrayRef<OMPClause *> Clauses, |
11569 | SourceLocation StartLoc, |
11570 | SourceLocation EndLoc); |
11571 | /// Called on well-formed '\#pragma omp scan'. |
11572 | StmtResult ActOnOpenMPScanDirective(ArrayRef<OMPClause *> Clauses, |
11573 | SourceLocation StartLoc, |
11574 | SourceLocation EndLoc); |
11575 | /// Called on well-formed '\#pragma omp ordered' after parsing of the |
11576 | /// associated statement. |
11577 | StmtResult ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
11578 | Stmt *AStmt, SourceLocation StartLoc, |
11579 | SourceLocation EndLoc); |
11580 | /// Called on well-formed '\#pragma omp atomic' after parsing of the |
11581 | /// associated statement. |
11582 | StmtResult ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
11583 | Stmt *AStmt, SourceLocation StartLoc, |
11584 | SourceLocation EndLoc); |
11585 | /// Called on well-formed '\#pragma omp target' after parsing of the |
11586 | /// associated statement. |
11587 | StmtResult ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
11588 | Stmt *AStmt, SourceLocation StartLoc, |
11589 | SourceLocation EndLoc); |
11590 | /// Called on well-formed '\#pragma omp target data' after parsing of |
11591 | /// the associated statement. |
11592 | StmtResult ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
11593 | Stmt *AStmt, SourceLocation StartLoc, |
11594 | SourceLocation EndLoc); |
11595 | /// Called on well-formed '\#pragma omp target enter data' after |
11596 | /// parsing of the associated statement. |
11597 | StmtResult ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
11598 | SourceLocation StartLoc, |
11599 | SourceLocation EndLoc, |
11600 | Stmt *AStmt); |
11601 | /// Called on well-formed '\#pragma omp target exit data' after |
11602 | /// parsing of the associated statement. |
11603 | StmtResult ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
11604 | SourceLocation StartLoc, |
11605 | SourceLocation EndLoc, |
11606 | Stmt *AStmt); |
11607 | /// Called on well-formed '\#pragma omp target parallel' after |
11608 | /// parsing of the associated statement. |
11609 | StmtResult ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
11610 | Stmt *AStmt, |
11611 | SourceLocation StartLoc, |
11612 | SourceLocation EndLoc); |
11613 | /// Called on well-formed '\#pragma omp target parallel for' after |
11614 | /// parsing of the associated statement. |
11615 | StmtResult ActOnOpenMPTargetParallelForDirective( |
11616 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11617 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11618 | /// Called on well-formed '\#pragma omp teams' after parsing of the |
11619 | /// associated statement. |
11620 | StmtResult ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
11621 | Stmt *AStmt, SourceLocation StartLoc, |
11622 | SourceLocation EndLoc); |
11623 | /// Called on well-formed '\#pragma omp teams loop' after parsing of the |
11624 | /// associated statement. |
11625 | StmtResult ActOnOpenMPTeamsGenericLoopDirective( |
11626 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11627 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11628 | /// Called on well-formed '\#pragma omp target teams loop' after parsing of |
11629 | /// the associated statement. |
11630 | StmtResult ActOnOpenMPTargetTeamsGenericLoopDirective( |
11631 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11632 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11633 | /// Called on well-formed '\#pragma omp parallel loop' after parsing of the |
11634 | /// associated statement. |
11635 | StmtResult ActOnOpenMPParallelGenericLoopDirective( |
11636 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11637 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11638 | /// Called on well-formed '\#pragma omp target parallel loop' after parsing |
11639 | /// of the associated statement. |
11640 | StmtResult ActOnOpenMPTargetParallelGenericLoopDirective( |
11641 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11642 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11643 | /// Called on well-formed '\#pragma omp cancellation point'. |
11644 | StmtResult |
11645 | ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
11646 | SourceLocation EndLoc, |
11647 | OpenMPDirectiveKind CancelRegion); |
11648 | /// Called on well-formed '\#pragma omp cancel'. |
11649 | StmtResult ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
11650 | SourceLocation StartLoc, |
11651 | SourceLocation EndLoc, |
11652 | OpenMPDirectiveKind CancelRegion); |
11653 | /// Called on well-formed '\#pragma omp taskloop' after parsing of the |
11654 | /// associated statement. |
11655 | StmtResult |
11656 | ActOnOpenMPTaskLoopDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
11657 | SourceLocation StartLoc, SourceLocation EndLoc, |
11658 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11659 | /// Called on well-formed '\#pragma omp taskloop simd' after parsing of |
11660 | /// the associated statement. |
11661 | StmtResult ActOnOpenMPTaskLoopSimdDirective( |
11662 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11663 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11664 | /// Called on well-formed '\#pragma omp master taskloop' after parsing of the |
11665 | /// associated statement. |
11666 | StmtResult ActOnOpenMPMasterTaskLoopDirective( |
11667 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11668 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11669 | /// Called on well-formed '\#pragma omp master taskloop simd' after parsing of |
11670 | /// the associated statement. |
11671 | StmtResult ActOnOpenMPMasterTaskLoopSimdDirective( |
11672 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11673 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11674 | /// Called on well-formed '\#pragma omp parallel master taskloop' after |
11675 | /// parsing of the associated statement. |
11676 | StmtResult ActOnOpenMPParallelMasterTaskLoopDirective( |
11677 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11678 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11679 | /// Called on well-formed '\#pragma omp parallel master taskloop simd' after |
11680 | /// parsing of the associated statement. |
11681 | StmtResult ActOnOpenMPParallelMasterTaskLoopSimdDirective( |
11682 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11683 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11684 | /// Called on well-formed '\#pragma omp masked taskloop' after parsing of the |
11685 | /// associated statement. |
11686 | StmtResult ActOnOpenMPMaskedTaskLoopDirective( |
11687 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11688 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11689 | /// Called on well-formed '\#pragma omp masked taskloop simd' after parsing of |
11690 | /// the associated statement. |
11691 | StmtResult ActOnOpenMPMaskedTaskLoopSimdDirective( |
11692 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11693 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11694 | /// Called on well-formed '\#pragma omp parallel masked taskloop' after |
11695 | /// parsing of the associated statement. |
11696 | StmtResult ActOnOpenMPParallelMaskedTaskLoopDirective( |
11697 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11698 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11699 | /// Called on well-formed '\#pragma omp parallel masked taskloop simd' after |
11700 | /// parsing of the associated statement. |
11701 | StmtResult ActOnOpenMPParallelMaskedTaskLoopSimdDirective( |
11702 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11703 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11704 | /// Called on well-formed '\#pragma omp distribute' after parsing |
11705 | /// of the associated statement. |
11706 | StmtResult |
11707 | ActOnOpenMPDistributeDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
11708 | SourceLocation StartLoc, SourceLocation EndLoc, |
11709 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11710 | /// Called on well-formed '\#pragma omp target update'. |
11711 | StmtResult ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
11712 | SourceLocation StartLoc, |
11713 | SourceLocation EndLoc, |
11714 | Stmt *AStmt); |
11715 | /// Called on well-formed '\#pragma omp distribute parallel for' after |
11716 | /// parsing of the associated statement. |
11717 | StmtResult ActOnOpenMPDistributeParallelForDirective( |
11718 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11719 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11720 | /// Called on well-formed '\#pragma omp distribute parallel for simd' |
11721 | /// after parsing of the associated statement. |
11722 | StmtResult ActOnOpenMPDistributeParallelForSimdDirective( |
11723 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11724 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11725 | /// Called on well-formed '\#pragma omp distribute simd' after |
11726 | /// parsing of the associated statement. |
11727 | StmtResult ActOnOpenMPDistributeSimdDirective( |
11728 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11729 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11730 | /// Called on well-formed '\#pragma omp target parallel for simd' after |
11731 | /// parsing of the associated statement. |
11732 | StmtResult ActOnOpenMPTargetParallelForSimdDirective( |
11733 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11734 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11735 | /// Called on well-formed '\#pragma omp target simd' after parsing of |
11736 | /// the associated statement. |
11737 | StmtResult |
11738 | ActOnOpenMPTargetSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
11739 | SourceLocation StartLoc, SourceLocation EndLoc, |
11740 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11741 | /// Called on well-formed '\#pragma omp teams distribute' after parsing of |
11742 | /// the associated statement. |
11743 | StmtResult ActOnOpenMPTeamsDistributeDirective( |
11744 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11745 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11746 | /// Called on well-formed '\#pragma omp teams distribute simd' after parsing |
11747 | /// of the associated statement. |
11748 | StmtResult ActOnOpenMPTeamsDistributeSimdDirective( |
11749 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11750 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11751 | /// Called on well-formed '\#pragma omp teams distribute parallel for simd' |
11752 | /// after parsing of the associated statement. |
11753 | StmtResult ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
11754 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11755 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11756 | /// Called on well-formed '\#pragma omp teams distribute parallel for' |
11757 | /// after parsing of the associated statement. |
11758 | StmtResult ActOnOpenMPTeamsDistributeParallelForDirective( |
11759 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11760 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11761 | /// Called on well-formed '\#pragma omp target teams' after parsing of the |
11762 | /// associated statement. |
11763 | StmtResult ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses, |
11764 | Stmt *AStmt, |
11765 | SourceLocation StartLoc, |
11766 | SourceLocation EndLoc); |
11767 | /// Called on well-formed '\#pragma omp target teams distribute' after parsing |
11768 | /// of the associated statement. |
11769 | StmtResult ActOnOpenMPTargetTeamsDistributeDirective( |
11770 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11771 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11772 | /// Called on well-formed '\#pragma omp target teams distribute parallel for' |
11773 | /// after parsing of the associated statement. |
11774 | StmtResult ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
11775 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11776 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11777 | /// Called on well-formed '\#pragma omp target teams distribute parallel for |
11778 | /// simd' after parsing of the associated statement. |
11779 | StmtResult ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
11780 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11781 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11782 | /// Called on well-formed '\#pragma omp target teams distribute simd' after |
11783 | /// parsing of the associated statement. |
11784 | StmtResult ActOnOpenMPTargetTeamsDistributeSimdDirective( |
11785 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11786 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11787 | /// Called on well-formed '\#pragma omp interop'. |
11788 | StmtResult ActOnOpenMPInteropDirective(ArrayRef<OMPClause *> Clauses, |
11789 | SourceLocation StartLoc, |
11790 | SourceLocation EndLoc); |
11791 | /// Called on well-formed '\#pragma omp dispatch' after parsing of the |
11792 | // /associated statement. |
11793 | StmtResult ActOnOpenMPDispatchDirective(ArrayRef<OMPClause *> Clauses, |
11794 | Stmt *AStmt, SourceLocation StartLoc, |
11795 | SourceLocation EndLoc); |
11796 | /// Called on well-formed '\#pragma omp masked' after parsing of the |
11797 | // /associated statement. |
11798 | StmtResult ActOnOpenMPMaskedDirective(ArrayRef<OMPClause *> Clauses, |
11799 | Stmt *AStmt, SourceLocation StartLoc, |
11800 | SourceLocation EndLoc); |
11801 | |
11802 | /// Called on well-formed '\#pragma omp loop' after parsing of the |
11803 | /// associated statement. |
11804 | StmtResult ActOnOpenMPGenericLoopDirective( |
11805 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
11806 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
11807 | |
11808 | /// Checks correctness of linear modifiers. |
11809 | bool CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
11810 | SourceLocation LinLoc); |
11811 | /// Checks that the specified declaration matches requirements for the linear |
11812 | /// decls. |
11813 | bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc, |
11814 | OpenMPLinearClauseKind LinKind, QualType Type, |
11815 | bool IsDeclareSimd = false); |
11816 | |
11817 | /// Called on well-formed '\#pragma omp declare simd' after parsing of |
11818 | /// the associated method/function. |
11819 | DeclGroupPtrTy ActOnOpenMPDeclareSimdDirective( |
11820 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, |
11821 | Expr *Simdlen, ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
11822 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
11823 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR); |
11824 | |
11825 | /// Checks '\#pragma omp declare variant' variant function and original |
11826 | /// functions after parsing of the associated method/function. |
11827 | /// \param DG Function declaration to which declare variant directive is |
11828 | /// applied to. |
11829 | /// \param VariantRef Expression that references the variant function, which |
11830 | /// must be used instead of the original one, specified in \p DG. |
11831 | /// \param TI The trait info object representing the match clause. |
11832 | /// \param NumAppendArgs The number of omp_interop_t arguments to account for |
11833 | /// in checking. |
11834 | /// \returns std::nullopt, if the function/variant function are not compatible |
11835 | /// with the pragma, pair of original function/variant ref expression |
11836 | /// otherwise. |
11837 | std::optional<std::pair<FunctionDecl *, Expr *>> |
11838 | checkOpenMPDeclareVariantFunction(DeclGroupPtrTy DG, Expr *VariantRef, |
11839 | OMPTraitInfo &TI, unsigned NumAppendArgs, |
11840 | SourceRange SR); |
11841 | |
11842 | /// Called on well-formed '\#pragma omp declare variant' after parsing of |
11843 | /// the associated method/function. |
11844 | /// \param FD Function declaration to which declare variant directive is |
11845 | /// applied to. |
11846 | /// \param VariantRef Expression that references the variant function, which |
11847 | /// must be used instead of the original one, specified in \p DG. |
11848 | /// \param TI The context traits associated with the function variant. |
11849 | /// \param AdjustArgsNothing The list of 'nothing' arguments. |
11850 | /// \param AdjustArgsNeedDevicePtr The list of 'need_device_ptr' arguments. |
11851 | /// \param AppendArgs The list of 'append_args' arguments. |
11852 | /// \param AdjustArgsLoc The Location of an 'adjust_args' clause. |
11853 | /// \param AppendArgsLoc The Location of an 'append_args' clause. |
11854 | /// \param SR The SourceRange of the 'declare variant' directive. |
11855 | void ActOnOpenMPDeclareVariantDirective( |
11856 | FunctionDecl *FD, Expr *VariantRef, OMPTraitInfo &TI, |
11857 | ArrayRef<Expr *> AdjustArgsNothing, |
11858 | ArrayRef<Expr *> AdjustArgsNeedDevicePtr, |
11859 | ArrayRef<OMPInteropInfo> AppendArgs, SourceLocation AdjustArgsLoc, |
11860 | SourceLocation AppendArgsLoc, SourceRange SR); |
11861 | |
11862 | OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, |
11863 | Expr *Expr, |
11864 | SourceLocation StartLoc, |
11865 | SourceLocation LParenLoc, |
11866 | SourceLocation EndLoc); |
11867 | /// Called on well-formed 'allocator' clause. |
11868 | OMPClause *ActOnOpenMPAllocatorClause(Expr *Allocator, |
11869 | SourceLocation StartLoc, |
11870 | SourceLocation LParenLoc, |
11871 | SourceLocation EndLoc); |
11872 | /// Called on well-formed 'if' clause. |
11873 | OMPClause *ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
11874 | Expr *Condition, SourceLocation StartLoc, |
11875 | SourceLocation LParenLoc, |
11876 | SourceLocation NameModifierLoc, |
11877 | SourceLocation ColonLoc, |
11878 | SourceLocation EndLoc); |
11879 | /// Called on well-formed 'final' clause. |
11880 | OMPClause *ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
11881 | SourceLocation LParenLoc, |
11882 | SourceLocation EndLoc); |
11883 | /// Called on well-formed 'num_threads' clause. |
11884 | OMPClause *ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
11885 | SourceLocation StartLoc, |
11886 | SourceLocation LParenLoc, |
11887 | SourceLocation EndLoc); |
11888 | /// Called on well-formed 'align' clause. |
11889 | OMPClause *ActOnOpenMPAlignClause(Expr *Alignment, SourceLocation StartLoc, |
11890 | SourceLocation LParenLoc, |
11891 | SourceLocation EndLoc); |
11892 | /// Called on well-formed 'safelen' clause. |
11893 | OMPClause *ActOnOpenMPSafelenClause(Expr *Length, |
11894 | SourceLocation StartLoc, |
11895 | SourceLocation LParenLoc, |
11896 | SourceLocation EndLoc); |
11897 | /// Called on well-formed 'simdlen' clause. |
11898 | OMPClause *ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc, |
11899 | SourceLocation LParenLoc, |
11900 | SourceLocation EndLoc); |
11901 | /// Called on well-form 'sizes' clause. |
11902 | OMPClause *ActOnOpenMPSizesClause(ArrayRef<Expr *> SizeExprs, |
11903 | SourceLocation StartLoc, |
11904 | SourceLocation LParenLoc, |
11905 | SourceLocation EndLoc); |
11906 | /// Called on well-form 'full' clauses. |
11907 | OMPClause *ActOnOpenMPFullClause(SourceLocation StartLoc, |
11908 | SourceLocation EndLoc); |
11909 | /// Called on well-form 'partial' clauses. |
11910 | OMPClause *ActOnOpenMPPartialClause(Expr *FactorExpr, SourceLocation StartLoc, |
11911 | SourceLocation LParenLoc, |
11912 | SourceLocation EndLoc); |
11913 | /// Called on well-formed 'collapse' clause. |
11914 | OMPClause *ActOnOpenMPCollapseClause(Expr *NumForLoops, |
11915 | SourceLocation StartLoc, |
11916 | SourceLocation LParenLoc, |
11917 | SourceLocation EndLoc); |
11918 | /// Called on well-formed 'ordered' clause. |
11919 | OMPClause * |
11920 | ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, |
11921 | SourceLocation LParenLoc = SourceLocation(), |
11922 | Expr *NumForLoops = nullptr); |
11923 | /// Called on well-formed 'grainsize' clause. |
11924 | OMPClause *ActOnOpenMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, |
11925 | Expr *Size, SourceLocation StartLoc, |
11926 | SourceLocation LParenLoc, |
11927 | SourceLocation ModifierLoc, |
11928 | SourceLocation EndLoc); |
11929 | /// Called on well-formed 'num_tasks' clause. |
11930 | OMPClause *ActOnOpenMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, |
11931 | Expr *NumTasks, SourceLocation StartLoc, |
11932 | SourceLocation LParenLoc, |
11933 | SourceLocation ModifierLoc, |
11934 | SourceLocation EndLoc); |
11935 | /// Called on well-formed 'hint' clause. |
11936 | OMPClause *ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
11937 | SourceLocation LParenLoc, |
11938 | SourceLocation EndLoc); |
11939 | /// Called on well-formed 'detach' clause. |
11940 | OMPClause *ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc, |
11941 | SourceLocation LParenLoc, |
11942 | SourceLocation EndLoc); |
11943 | |
11944 | OMPClause *ActOnOpenMPSimpleClause(OpenMPClauseKind Kind, |
11945 | unsigned Argument, |
11946 | SourceLocation ArgumentLoc, |
11947 | SourceLocation StartLoc, |
11948 | SourceLocation LParenLoc, |
11949 | SourceLocation EndLoc); |
11950 | /// Called on well-formed 'when' clause. |
11951 | OMPClause *ActOnOpenMPWhenClause(OMPTraitInfo &TI, SourceLocation StartLoc, |
11952 | SourceLocation LParenLoc, |
11953 | SourceLocation EndLoc); |
11954 | /// Called on well-formed 'default' clause. |
11955 | OMPClause *ActOnOpenMPDefaultClause(llvm::omp::DefaultKind Kind, |
11956 | SourceLocation KindLoc, |
11957 | SourceLocation StartLoc, |
11958 | SourceLocation LParenLoc, |
11959 | SourceLocation EndLoc); |
11960 | /// Called on well-formed 'proc_bind' clause. |
11961 | OMPClause *ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind, |
11962 | SourceLocation KindLoc, |
11963 | SourceLocation StartLoc, |
11964 | SourceLocation LParenLoc, |
11965 | SourceLocation EndLoc); |
11966 | /// Called on well-formed 'order' clause. |
11967 | OMPClause *ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier, |
11968 | OpenMPOrderClauseKind Kind, |
11969 | SourceLocation StartLoc, |
11970 | SourceLocation LParenLoc, |
11971 | SourceLocation MLoc, SourceLocation KindLoc, |
11972 | SourceLocation EndLoc); |
11973 | /// Called on well-formed 'update' clause. |
11974 | OMPClause *ActOnOpenMPUpdateClause(OpenMPDependClauseKind Kind, |
11975 | SourceLocation KindLoc, |
11976 | SourceLocation StartLoc, |
11977 | SourceLocation LParenLoc, |
11978 | SourceLocation EndLoc); |
11979 | |
11980 | OMPClause *ActOnOpenMPSingleExprWithArgClause( |
11981 | OpenMPClauseKind Kind, ArrayRef<unsigned> Arguments, Expr *Expr, |
11982 | SourceLocation StartLoc, SourceLocation LParenLoc, |
11983 | ArrayRef<SourceLocation> ArgumentsLoc, SourceLocation DelimLoc, |
11984 | SourceLocation EndLoc); |
11985 | /// Called on well-formed 'schedule' clause. |
11986 | OMPClause *ActOnOpenMPScheduleClause( |
11987 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
11988 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
11989 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
11990 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc); |
11991 | |
11992 | OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc, |
11993 | SourceLocation EndLoc); |
11994 | /// Called on well-formed 'nowait' clause. |
11995 | OMPClause *ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
11996 | SourceLocation EndLoc); |
11997 | /// Called on well-formed 'untied' clause. |
11998 | OMPClause *ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
11999 | SourceLocation EndLoc); |
12000 | /// Called on well-formed 'mergeable' clause. |
12001 | OMPClause *ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
12002 | SourceLocation EndLoc); |
12003 | /// Called on well-formed 'read' clause. |
12004 | OMPClause *ActOnOpenMPReadClause(SourceLocation StartLoc, |
12005 | SourceLocation EndLoc); |
12006 | /// Called on well-formed 'write' clause. |
12007 | OMPClause *ActOnOpenMPWriteClause(SourceLocation StartLoc, |
12008 | SourceLocation EndLoc); |
12009 | /// Called on well-formed 'update' clause. |
12010 | OMPClause *ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
12011 | SourceLocation EndLoc); |
12012 | /// Called on well-formed 'capture' clause. |
12013 | OMPClause *ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
12014 | SourceLocation EndLoc); |
12015 | /// Called on well-formed 'compare' clause. |
12016 | OMPClause *ActOnOpenMPCompareClause(SourceLocation StartLoc, |
12017 | SourceLocation EndLoc); |
12018 | /// Called on well-formed 'seq_cst' clause. |
12019 | OMPClause *ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
12020 | SourceLocation EndLoc); |
12021 | /// Called on well-formed 'acq_rel' clause. |
12022 | OMPClause *ActOnOpenMPAcqRelClause(SourceLocation StartLoc, |
12023 | SourceLocation EndLoc); |
12024 | /// Called on well-formed 'acquire' clause. |
12025 | OMPClause *ActOnOpenMPAcquireClause(SourceLocation StartLoc, |
12026 | SourceLocation EndLoc); |
12027 | /// Called on well-formed 'release' clause. |
12028 | OMPClause *ActOnOpenMPReleaseClause(SourceLocation StartLoc, |
12029 | SourceLocation EndLoc); |
12030 | /// Called on well-formed 'relaxed' clause. |
12031 | OMPClause *ActOnOpenMPRelaxedClause(SourceLocation StartLoc, |
12032 | SourceLocation EndLoc); |
12033 | |
12034 | /// Called on well-formed 'init' clause. |
12035 | OMPClause * |
12036 | ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, |
12037 | SourceLocation StartLoc, SourceLocation LParenLoc, |
12038 | SourceLocation VarLoc, SourceLocation EndLoc); |
12039 | |
12040 | /// Called on well-formed 'use' clause. |
12041 | OMPClause *ActOnOpenMPUseClause(Expr *InteropVar, SourceLocation StartLoc, |
12042 | SourceLocation LParenLoc, |
12043 | SourceLocation VarLoc, SourceLocation EndLoc); |
12044 | |
12045 | /// Called on well-formed 'destroy' clause. |
12046 | OMPClause *ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, |
12047 | SourceLocation LParenLoc, |
12048 | SourceLocation VarLoc, |
12049 | SourceLocation EndLoc); |
12050 | /// Called on well-formed 'novariants' clause. |
12051 | OMPClause *ActOnOpenMPNovariantsClause(Expr *Condition, |
12052 | SourceLocation StartLoc, |
12053 | SourceLocation LParenLoc, |
12054 | SourceLocation EndLoc); |
12055 | /// Called on well-formed 'nocontext' clause. |
12056 | OMPClause *ActOnOpenMPNocontextClause(Expr *Condition, |
12057 | SourceLocation StartLoc, |
12058 | SourceLocation LParenLoc, |
12059 | SourceLocation EndLoc); |
12060 | /// Called on well-formed 'filter' clause. |
12061 | OMPClause *ActOnOpenMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, |
12062 | SourceLocation LParenLoc, |
12063 | SourceLocation EndLoc); |
12064 | /// Called on well-formed 'threads' clause. |
12065 | OMPClause *ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
12066 | SourceLocation EndLoc); |
12067 | /// Called on well-formed 'simd' clause. |
12068 | OMPClause *ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
12069 | SourceLocation EndLoc); |
12070 | /// Called on well-formed 'nogroup' clause. |
12071 | OMPClause *ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
12072 | SourceLocation EndLoc); |
12073 | /// Called on well-formed 'unified_address' clause. |
12074 | OMPClause *ActOnOpenMPUnifiedAddressClause(SourceLocation StartLoc, |
12075 | SourceLocation EndLoc); |
12076 | |
12077 | /// Called on well-formed 'unified_address' clause. |
12078 | OMPClause *ActOnOpenMPUnifiedSharedMemoryClause(SourceLocation StartLoc, |
12079 | SourceLocation EndLoc); |
12080 | |
12081 | /// Called on well-formed 'reverse_offload' clause. |
12082 | OMPClause *ActOnOpenMPReverseOffloadClause(SourceLocation StartLoc, |
12083 | SourceLocation EndLoc); |
12084 | |
12085 | /// Called on well-formed 'dynamic_allocators' clause. |
12086 | OMPClause *ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc, |
12087 | SourceLocation EndLoc); |
12088 | |
12089 | /// Called on well-formed 'atomic_default_mem_order' clause. |
12090 | OMPClause *ActOnOpenMPAtomicDefaultMemOrderClause( |
12091 | OpenMPAtomicDefaultMemOrderClauseKind Kind, SourceLocation KindLoc, |
12092 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); |
12093 | |
12094 | /// Called on well-formed 'at' clause. |
12095 | OMPClause *ActOnOpenMPAtClause(OpenMPAtClauseKind Kind, |
12096 | SourceLocation KindLoc, |
12097 | SourceLocation StartLoc, |
12098 | SourceLocation LParenLoc, |
12099 | SourceLocation EndLoc); |
12100 | |
12101 | /// Called on well-formed 'severity' clause. |
12102 | OMPClause *ActOnOpenMPSeverityClause(OpenMPSeverityClauseKind Kind, |
12103 | SourceLocation KindLoc, |
12104 | SourceLocation StartLoc, |
12105 | SourceLocation LParenLoc, |
12106 | SourceLocation EndLoc); |
12107 | |
12108 | /// Called on well-formed 'message' clause. |
12109 | /// passing string for message. |
12110 | OMPClause *ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc, |
12111 | SourceLocation LParenLoc, |
12112 | SourceLocation EndLoc); |
12113 | |
12114 | /// Data used for processing a list of variables in OpenMP clauses. |
12115 | struct OpenMPVarListDataTy final { |
12116 | Expr *DepModOrTailExpr = nullptr; |
12117 | Expr *IteratorExpr = nullptr; |
12118 | SourceLocation ColonLoc; |
12119 | SourceLocation RLoc; |
12120 | CXXScopeSpec ReductionOrMapperIdScopeSpec; |
12121 | DeclarationNameInfo ReductionOrMapperId; |
12122 | int = -1; ///< Additional modifier for linear, map, depend or |
12123 | ///< lastprivate clause. |
12124 | SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers> |
12125 | MapTypeModifiers; |
12126 | SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers> |
12127 | MapTypeModifiersLoc; |
12128 | SmallVector<OpenMPMotionModifierKind, NumberOfOMPMotionModifiers> |
12129 | MotionModifiers; |
12130 | SmallVector<SourceLocation, NumberOfOMPMotionModifiers> MotionModifiersLoc; |
12131 | bool IsMapTypeImplicit = false; |
12132 | SourceLocation ; |
12133 | SourceLocation OmpAllMemoryLoc; |
12134 | }; |
12135 | |
12136 | OMPClause *ActOnOpenMPVarListClause(OpenMPClauseKind Kind, |
12137 | ArrayRef<Expr *> Vars, |
12138 | const OMPVarListLocTy &Locs, |
12139 | OpenMPVarListDataTy &Data); |
12140 | /// Called on well-formed 'inclusive' clause. |
12141 | OMPClause *ActOnOpenMPInclusiveClause(ArrayRef<Expr *> VarList, |
12142 | SourceLocation StartLoc, |
12143 | SourceLocation LParenLoc, |
12144 | SourceLocation EndLoc); |
12145 | /// Called on well-formed 'exclusive' clause. |
12146 | OMPClause *ActOnOpenMPExclusiveClause(ArrayRef<Expr *> VarList, |
12147 | SourceLocation StartLoc, |
12148 | SourceLocation LParenLoc, |
12149 | SourceLocation EndLoc); |
12150 | /// Called on well-formed 'allocate' clause. |
12151 | OMPClause * |
12152 | ActOnOpenMPAllocateClause(Expr *Allocator, ArrayRef<Expr *> VarList, |
12153 | SourceLocation StartLoc, SourceLocation ColonLoc, |
12154 | SourceLocation LParenLoc, SourceLocation EndLoc); |
12155 | /// Called on well-formed 'private' clause. |
12156 | OMPClause *ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
12157 | SourceLocation StartLoc, |
12158 | SourceLocation LParenLoc, |
12159 | SourceLocation EndLoc); |
12160 | /// Called on well-formed 'firstprivate' clause. |
12161 | OMPClause *ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
12162 | SourceLocation StartLoc, |
12163 | SourceLocation LParenLoc, |
12164 | SourceLocation EndLoc); |
12165 | /// Called on well-formed 'lastprivate' clause. |
12166 | OMPClause *ActOnOpenMPLastprivateClause( |
12167 | ArrayRef<Expr *> VarList, OpenMPLastprivateModifier LPKind, |
12168 | SourceLocation LPKindLoc, SourceLocation ColonLoc, |
12169 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); |
12170 | /// Called on well-formed 'shared' clause. |
12171 | OMPClause *ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
12172 | SourceLocation StartLoc, |
12173 | SourceLocation LParenLoc, |
12174 | SourceLocation EndLoc); |
12175 | /// Called on well-formed 'reduction' clause. |
12176 | OMPClause *ActOnOpenMPReductionClause( |
12177 | ArrayRef<Expr *> VarList, OpenMPReductionClauseModifier Modifier, |
12178 | SourceLocation StartLoc, SourceLocation LParenLoc, |
12179 | SourceLocation ModifierLoc, SourceLocation ColonLoc, |
12180 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
12181 | const DeclarationNameInfo &ReductionId, |
12182 | ArrayRef<Expr *> UnresolvedReductions = std::nullopt); |
12183 | /// Called on well-formed 'task_reduction' clause. |
12184 | OMPClause *ActOnOpenMPTaskReductionClause( |
12185 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
12186 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
12187 | CXXScopeSpec &ReductionIdScopeSpec, |
12188 | const DeclarationNameInfo &ReductionId, |
12189 | ArrayRef<Expr *> UnresolvedReductions = std::nullopt); |
12190 | /// Called on well-formed 'in_reduction' clause. |
12191 | OMPClause *ActOnOpenMPInReductionClause( |
12192 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
12193 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
12194 | CXXScopeSpec &ReductionIdScopeSpec, |
12195 | const DeclarationNameInfo &ReductionId, |
12196 | ArrayRef<Expr *> UnresolvedReductions = std::nullopt); |
12197 | /// Called on well-formed 'linear' clause. |
12198 | OMPClause * |
12199 | ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
12200 | SourceLocation StartLoc, SourceLocation LParenLoc, |
12201 | OpenMPLinearClauseKind LinKind, SourceLocation LinLoc, |
12202 | SourceLocation ColonLoc, SourceLocation EndLoc); |
12203 | /// Called on well-formed 'aligned' clause. |
12204 | OMPClause *ActOnOpenMPAlignedClause(ArrayRef<Expr *> VarList, |
12205 | Expr *Alignment, |
12206 | SourceLocation StartLoc, |
12207 | SourceLocation LParenLoc, |
12208 | SourceLocation ColonLoc, |
12209 | SourceLocation EndLoc); |
12210 | /// Called on well-formed 'copyin' clause. |
12211 | OMPClause *ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
12212 | SourceLocation StartLoc, |
12213 | SourceLocation LParenLoc, |
12214 | SourceLocation EndLoc); |
12215 | /// Called on well-formed 'copyprivate' clause. |
12216 | OMPClause *ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
12217 | SourceLocation StartLoc, |
12218 | SourceLocation LParenLoc, |
12219 | SourceLocation EndLoc); |
12220 | /// Called on well-formed 'flush' pseudo clause. |
12221 | OMPClause *ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
12222 | SourceLocation StartLoc, |
12223 | SourceLocation LParenLoc, |
12224 | SourceLocation EndLoc); |
12225 | /// Called on well-formed 'depobj' pseudo clause. |
12226 | OMPClause *ActOnOpenMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, |
12227 | SourceLocation LParenLoc, |
12228 | SourceLocation EndLoc); |
12229 | /// Called on well-formed 'depend' clause. |
12230 | OMPClause *ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data, |
12231 | Expr *DepModifier, |
12232 | ArrayRef<Expr *> VarList, |
12233 | SourceLocation StartLoc, |
12234 | SourceLocation LParenLoc, |
12235 | SourceLocation EndLoc); |
12236 | /// Called on well-formed 'device' clause. |
12237 | OMPClause *ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier, |
12238 | Expr *Device, SourceLocation StartLoc, |
12239 | SourceLocation LParenLoc, |
12240 | SourceLocation ModifierLoc, |
12241 | SourceLocation EndLoc); |
12242 | /// Called on well-formed 'map' clause. |
12243 | OMPClause *ActOnOpenMPMapClause( |
12244 | Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
12245 | ArrayRef<SourceLocation> MapTypeModifiersLoc, |
12246 | CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, |
12247 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
12248 | SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
12249 | const OMPVarListLocTy &Locs, bool NoDiagnose = false, |
12250 | ArrayRef<Expr *> UnresolvedMappers = std::nullopt); |
12251 | /// Called on well-formed 'num_teams' clause. |
12252 | OMPClause *ActOnOpenMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, |
12253 | SourceLocation LParenLoc, |
12254 | SourceLocation EndLoc); |
12255 | /// Called on well-formed 'thread_limit' clause. |
12256 | OMPClause *ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
12257 | SourceLocation StartLoc, |
12258 | SourceLocation LParenLoc, |
12259 | SourceLocation EndLoc); |
12260 | /// Called on well-formed 'priority' clause. |
12261 | OMPClause *ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc, |
12262 | SourceLocation LParenLoc, |
12263 | SourceLocation EndLoc); |
12264 | /// Called on well-formed 'dist_schedule' clause. |
12265 | OMPClause *ActOnOpenMPDistScheduleClause( |
12266 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, |
12267 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, |
12268 | SourceLocation CommaLoc, SourceLocation EndLoc); |
12269 | /// Called on well-formed 'defaultmap' clause. |
12270 | OMPClause *ActOnOpenMPDefaultmapClause( |
12271 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
12272 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
12273 | SourceLocation KindLoc, SourceLocation EndLoc); |
12274 | /// Called on well-formed 'to' clause. |
12275 | OMPClause * |
12276 | ActOnOpenMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
12277 | ArrayRef<SourceLocation> MotionModifiersLoc, |
12278 | CXXScopeSpec &MapperIdScopeSpec, |
12279 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
12280 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
12281 | ArrayRef<Expr *> UnresolvedMappers = std::nullopt); |
12282 | /// Called on well-formed 'from' clause. |
12283 | OMPClause * |
12284 | ActOnOpenMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
12285 | ArrayRef<SourceLocation> MotionModifiersLoc, |
12286 | CXXScopeSpec &MapperIdScopeSpec, |
12287 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
12288 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
12289 | ArrayRef<Expr *> UnresolvedMappers = std::nullopt); |
12290 | /// Called on well-formed 'use_device_ptr' clause. |
12291 | OMPClause *ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
12292 | const OMPVarListLocTy &Locs); |
12293 | /// Called on well-formed 'use_device_addr' clause. |
12294 | OMPClause *ActOnOpenMPUseDeviceAddrClause(ArrayRef<Expr *> VarList, |
12295 | const OMPVarListLocTy &Locs); |
12296 | /// Called on well-formed 'is_device_ptr' clause. |
12297 | OMPClause *ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
12298 | const OMPVarListLocTy &Locs); |
12299 | /// Called on well-formed 'has_device_addr' clause. |
12300 | OMPClause *ActOnOpenMPHasDeviceAddrClause(ArrayRef<Expr *> VarList, |
12301 | const OMPVarListLocTy &Locs); |
12302 | /// Called on well-formed 'nontemporal' clause. |
12303 | OMPClause *ActOnOpenMPNontemporalClause(ArrayRef<Expr *> VarList, |
12304 | SourceLocation StartLoc, |
12305 | SourceLocation LParenLoc, |
12306 | SourceLocation EndLoc); |
12307 | |
12308 | /// Data for list of allocators. |
12309 | struct UsesAllocatorsData { |
12310 | /// Allocator. |
12311 | Expr *Allocator = nullptr; |
12312 | /// Allocator traits. |
12313 | Expr *AllocatorTraits = nullptr; |
12314 | /// Locations of '(' and ')' symbols. |
12315 | SourceLocation LParenLoc, RParenLoc; |
12316 | }; |
12317 | /// Called on well-formed 'uses_allocators' clause. |
12318 | OMPClause *ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, |
12319 | SourceLocation LParenLoc, |
12320 | SourceLocation EndLoc, |
12321 | ArrayRef<UsesAllocatorsData> Data); |
12322 | /// Called on well-formed 'affinity' clause. |
12323 | OMPClause *ActOnOpenMPAffinityClause(SourceLocation StartLoc, |
12324 | SourceLocation LParenLoc, |
12325 | SourceLocation ColonLoc, |
12326 | SourceLocation EndLoc, Expr *Modifier, |
12327 | ArrayRef<Expr *> Locators); |
12328 | /// Called on a well-formed 'bind' clause. |
12329 | OMPClause *ActOnOpenMPBindClause(OpenMPBindClauseKind Kind, |
12330 | SourceLocation KindLoc, |
12331 | SourceLocation StartLoc, |
12332 | SourceLocation LParenLoc, |
12333 | SourceLocation EndLoc); |
12334 | |
12335 | /// Called on a well-formed 'ompx_dyn_cgroup_mem' clause. |
12336 | OMPClause *ActOnOpenMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, |
12337 | SourceLocation LParenLoc, |
12338 | SourceLocation EndLoc); |
12339 | |
12340 | /// Called on well-formed 'doacross' clause. |
12341 | OMPClause * |
12342 | ActOnOpenMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, |
12343 | SourceLocation DepLoc, SourceLocation ColonLoc, |
12344 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
12345 | SourceLocation LParenLoc, SourceLocation EndLoc); |
12346 | |
12347 | /// The kind of conversion being performed. |
12348 | enum CheckedConversionKind { |
12349 | /// An implicit conversion. |
12350 | CCK_ImplicitConversion, |
12351 | /// A C-style cast. |
12352 | CCK_CStyleCast, |
12353 | /// A functional-style cast. |
12354 | CCK_FunctionalCast, |
12355 | /// A cast other than a C-style cast. |
12356 | CCK_OtherCast, |
12357 | /// A conversion for an operand of a builtin overloaded operator. |
12358 | CCK_ForBuiltinOverloadedOp |
12359 | }; |
12360 | |
12361 | static bool isCast(CheckedConversionKind CCK) { |
12362 | return CCK == CCK_CStyleCast || CCK == CCK_FunctionalCast || |
12363 | CCK == CCK_OtherCast; |
12364 | } |
12365 | |
12366 | /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit |
12367 | /// cast. If there is already an implicit cast, merge into the existing one. |
12368 | /// If isLvalue, the result of the cast is an lvalue. |
12369 | ExprResult |
12370 | ImpCastExprToType(Expr *E, QualType Type, CastKind CK, |
12371 | ExprValueKind VK = VK_PRValue, |
12372 | const CXXCastPath *BasePath = nullptr, |
12373 | CheckedConversionKind CCK = CCK_ImplicitConversion); |
12374 | |
12375 | /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding |
12376 | /// to the conversion from scalar type ScalarTy to the Boolean type. |
12377 | static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); |
12378 | |
12379 | /// IgnoredValueConversions - Given that an expression's result is |
12380 | /// syntactically ignored, perform any conversions that are |
12381 | /// required. |
12382 | ExprResult IgnoredValueConversions(Expr *E); |
12383 | |
12384 | // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts |
12385 | // functions and arrays to their respective pointers (C99 6.3.2.1). |
12386 | ExprResult UsualUnaryConversions(Expr *E); |
12387 | |
12388 | /// CallExprUnaryConversions - a special case of an unary conversion |
12389 | /// performed on a function designator of a call expression. |
12390 | ExprResult CallExprUnaryConversions(Expr *E); |
12391 | |
12392 | // DefaultFunctionArrayConversion - converts functions and arrays |
12393 | // to their respective pointers (C99 6.3.2.1). |
12394 | ExprResult DefaultFunctionArrayConversion(Expr *E, bool Diagnose = true); |
12395 | |
12396 | // DefaultFunctionArrayLvalueConversion - converts functions and |
12397 | // arrays to their respective pointers and performs the |
12398 | // lvalue-to-rvalue conversion. |
12399 | ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, |
12400 | bool Diagnose = true); |
12401 | |
12402 | // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on |
12403 | // the operand. This function is a no-op if the operand has a function type |
12404 | // or an array type. |
12405 | ExprResult DefaultLvalueConversion(Expr *E); |
12406 | |
12407 | // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that |
12408 | // do not have a prototype. Integer promotions are performed on each |
12409 | // argument, and arguments that have type float are promoted to double. |
12410 | ExprResult DefaultArgumentPromotion(Expr *E); |
12411 | |
12412 | /// If \p E is a prvalue denoting an unmaterialized temporary, materialize |
12413 | /// it as an xvalue. In C++98, the result will still be a prvalue, because |
12414 | /// we don't have xvalues there. |
12415 | ExprResult TemporaryMaterializationConversion(Expr *E); |
12416 | |
12417 | // Used for emitting the right warning by DefaultVariadicArgumentPromotion |
12418 | enum VariadicCallType { |
12419 | VariadicFunction, |
12420 | VariadicBlock, |
12421 | VariadicMethod, |
12422 | VariadicConstructor, |
12423 | VariadicDoesNotApply |
12424 | }; |
12425 | |
12426 | VariadicCallType getVariadicCallType(FunctionDecl *FDecl, |
12427 | const FunctionProtoType *Proto, |
12428 | Expr *Fn); |
12429 | |
12430 | // Used for determining in which context a type is allowed to be passed to a |
12431 | // vararg function. |
12432 | enum VarArgKind { |
12433 | VAK_Valid, |
12434 | VAK_ValidInCXX11, |
12435 | VAK_Undefined, |
12436 | VAK_MSVCUndefined, |
12437 | VAK_Invalid |
12438 | }; |
12439 | |
12440 | // Determines which VarArgKind fits an expression. |
12441 | VarArgKind isValidVarArgType(const QualType &Ty); |
12442 | |
12443 | /// Check to see if the given expression is a valid argument to a variadic |
12444 | /// function, issuing a diagnostic if not. |
12445 | void checkVariadicArgument(const Expr *E, VariadicCallType CT); |
12446 | |
12447 | /// Check whether the given statement can have musttail applied to it, |
12448 | /// issuing a diagnostic and returning false if not. In the success case, |
12449 | /// the statement is rewritten to remove implicit nodes from the return |
12450 | /// value. |
12451 | bool checkAndRewriteMustTailAttr(Stmt *St, const Attr &MTA); |
12452 | |
12453 | private: |
12454 | /// Check whether the given statement can have musttail applied to it, |
12455 | /// issuing a diagnostic and returning false if not. |
12456 | bool checkMustTailAttr(const Stmt *St, const Attr &MTA); |
12457 | |
12458 | public: |
12459 | /// Check to see if a given expression could have '.c_str()' called on it. |
12460 | bool hasCStrMethod(const Expr *E); |
12461 | |
12462 | /// GatherArgumentsForCall - Collector argument expressions for various |
12463 | /// form of call prototypes. |
12464 | bool GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl, |
12465 | const FunctionProtoType *Proto, |
12466 | unsigned FirstParam, ArrayRef<Expr *> Args, |
12467 | SmallVectorImpl<Expr *> &AllArgs, |
12468 | VariadicCallType CallType = VariadicDoesNotApply, |
12469 | bool AllowExplicit = false, |
12470 | bool IsListInitialization = false); |
12471 | |
12472 | // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but |
12473 | // will create a runtime trap if the resulting type is not a POD type. |
12474 | ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, |
12475 | FunctionDecl *FDecl); |
12476 | |
12477 | /// Context in which we're performing a usual arithmetic conversion. |
12478 | enum ArithConvKind { |
12479 | /// An arithmetic operation. |
12480 | ACK_Arithmetic, |
12481 | /// A bitwise operation. |
12482 | ACK_BitwiseOp, |
12483 | /// A comparison. |
12484 | ACK_Comparison, |
12485 | /// A conditional (?:) operator. |
12486 | ACK_Conditional, |
12487 | /// A compound assignment expression. |
12488 | ACK_CompAssign, |
12489 | }; |
12490 | |
12491 | // UsualArithmeticConversions - performs the UsualUnaryConversions on it's |
12492 | // operands and then handles various conversions that are common to binary |
12493 | // operators (C99 6.3.1.8). If both operands aren't arithmetic, this |
12494 | // routine returns the first non-arithmetic type found. The client is |
12495 | // responsible for emitting appropriate error diagnostics. |
12496 | QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, |
12497 | SourceLocation Loc, ArithConvKind ACK); |
12498 | |
12499 | /// AssignConvertType - All of the 'assignment' semantic checks return this |
12500 | /// enum to indicate whether the assignment was allowed. These checks are |
12501 | /// done for simple assignments, as well as initialization, return from |
12502 | /// function, argument passing, etc. The query is phrased in terms of a |
12503 | /// source and destination type. |
12504 | enum AssignConvertType { |
12505 | /// Compatible - the types are compatible according to the standard. |
12506 | Compatible, |
12507 | |
12508 | /// PointerToInt - The assignment converts a pointer to an int, which we |
12509 | /// accept as an extension. |
12510 | PointerToInt, |
12511 | |
12512 | /// IntToPointer - The assignment converts an int to a pointer, which we |
12513 | /// accept as an extension. |
12514 | IntToPointer, |
12515 | |
12516 | /// FunctionVoidPointer - The assignment is between a function pointer and |
12517 | /// void*, which the standard doesn't allow, but we accept as an extension. |
12518 | FunctionVoidPointer, |
12519 | |
12520 | /// IncompatiblePointer - The assignment is between two pointers types that |
12521 | /// are not compatible, but we accept them as an extension. |
12522 | IncompatiblePointer, |
12523 | |
12524 | /// IncompatibleFunctionPointer - The assignment is between two function |
12525 | /// pointers types that are not compatible, but we accept them as an |
12526 | /// extension. |
12527 | IncompatibleFunctionPointer, |
12528 | |
12529 | /// IncompatibleFunctionPointerStrict - The assignment is between two |
12530 | /// function pointer types that are not identical, but are compatible, |
12531 | /// unless compiled with -fsanitize=cfi, in which case the type mismatch |
12532 | /// may trip an indirect call runtime check. |
12533 | IncompatibleFunctionPointerStrict, |
12534 | |
12535 | /// IncompatiblePointerSign - The assignment is between two pointers types |
12536 | /// which point to integers which have a different sign, but are otherwise |
12537 | /// identical. This is a subset of the above, but broken out because it's by |
12538 | /// far the most common case of incompatible pointers. |
12539 | IncompatiblePointerSign, |
12540 | |
12541 | /// CompatiblePointerDiscardsQualifiers - The assignment discards |
12542 | /// c/v/r qualifiers, which we accept as an extension. |
12543 | CompatiblePointerDiscardsQualifiers, |
12544 | |
12545 | /// IncompatiblePointerDiscardsQualifiers - The assignment |
12546 | /// discards qualifiers that we don't permit to be discarded, |
12547 | /// like address spaces. |
12548 | IncompatiblePointerDiscardsQualifiers, |
12549 | |
12550 | /// IncompatibleNestedPointerAddressSpaceMismatch - The assignment |
12551 | /// changes address spaces in nested pointer types which is not allowed. |
12552 | /// For instance, converting __private int ** to __generic int ** is |
12553 | /// illegal even though __private could be converted to __generic. |
12554 | IncompatibleNestedPointerAddressSpaceMismatch, |
12555 | |
12556 | /// IncompatibleNestedPointerQualifiers - The assignment is between two |
12557 | /// nested pointer types, and the qualifiers other than the first two |
12558 | /// levels differ e.g. char ** -> const char **, but we accept them as an |
12559 | /// extension. |
12560 | IncompatibleNestedPointerQualifiers, |
12561 | |
12562 | /// IncompatibleVectors - The assignment is between two vector types that |
12563 | /// have the same size, which we accept as an extension. |
12564 | IncompatibleVectors, |
12565 | |
12566 | /// IntToBlockPointer - The assignment converts an int to a block |
12567 | /// pointer. We disallow this. |
12568 | IntToBlockPointer, |
12569 | |
12570 | /// IncompatibleBlockPointer - The assignment is between two block |
12571 | /// pointers types that are not compatible. |
12572 | IncompatibleBlockPointer, |
12573 | |
12574 | /// IncompatibleObjCQualifiedId - The assignment is between a qualified |
12575 | /// id type and something else (that is incompatible with it). For example, |
12576 | /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. |
12577 | IncompatibleObjCQualifiedId, |
12578 | |
12579 | /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an |
12580 | /// object with __weak qualifier. |
12581 | IncompatibleObjCWeakRef, |
12582 | |
12583 | /// Incompatible - We reject this conversion outright, it is invalid to |
12584 | /// represent it in the AST. |
12585 | Incompatible |
12586 | }; |
12587 | |
12588 | /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the |
12589 | /// assignment conversion type specified by ConvTy. This returns true if the |
12590 | /// conversion was invalid or false if the conversion was accepted. |
12591 | bool DiagnoseAssignmentResult(AssignConvertType ConvTy, |
12592 | SourceLocation Loc, |
12593 | QualType DstType, QualType SrcType, |
12594 | Expr *SrcExpr, AssignmentAction Action, |
12595 | bool *Complained = nullptr); |
12596 | |
12597 | /// IsValueInFlagEnum - Determine if a value is allowed as part of a flag |
12598 | /// enum. If AllowMask is true, then we also allow the complement of a valid |
12599 | /// value, to be used as a mask. |
12600 | bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val, |
12601 | bool AllowMask) const; |
12602 | |
12603 | /// DiagnoseAssignmentEnum - Warn if assignment to enum is a constant |
12604 | /// integer not in the range of enum values. |
12605 | void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, |
12606 | Expr *SrcExpr); |
12607 | |
12608 | /// CheckAssignmentConstraints - Perform type checking for assignment, |
12609 | /// argument passing, variable initialization, and function return values. |
12610 | /// C99 6.5.16. |
12611 | AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, |
12612 | QualType LHSType, |
12613 | QualType RHSType); |
12614 | |
12615 | /// Check assignment constraints and optionally prepare for a conversion of |
12616 | /// the RHS to the LHS type. The conversion is prepared for if ConvertRHS |
12617 | /// is true. |
12618 | AssignConvertType CheckAssignmentConstraints(QualType LHSType, |
12619 | ExprResult &RHS, |
12620 | CastKind &Kind, |
12621 | bool ConvertRHS = true); |
12622 | |
12623 | /// Check assignment constraints for an assignment of RHS to LHSType. |
12624 | /// |
12625 | /// \param LHSType The destination type for the assignment. |
12626 | /// \param RHS The source expression for the assignment. |
12627 | /// \param Diagnose If \c true, diagnostics may be produced when checking |
12628 | /// for assignability. If a diagnostic is produced, \p RHS will be |
12629 | /// set to ExprError(). Note that this function may still return |
12630 | /// without producing a diagnostic, even for an invalid assignment. |
12631 | /// \param DiagnoseCFAudited If \c true, the target is a function parameter |
12632 | /// in an audited Core Foundation API and does not need to be checked |
12633 | /// for ARC retain issues. |
12634 | /// \param ConvertRHS If \c true, \p RHS will be updated to model the |
12635 | /// conversions necessary to perform the assignment. If \c false, |
12636 | /// \p Diagnose must also be \c false. |
12637 | AssignConvertType CheckSingleAssignmentConstraints( |
12638 | QualType LHSType, ExprResult &RHS, bool Diagnose = true, |
12639 | bool DiagnoseCFAudited = false, bool ConvertRHS = true); |
12640 | |
12641 | // If the lhs type is a transparent union, check whether we |
12642 | // can initialize the transparent union with the given expression. |
12643 | AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, |
12644 | ExprResult &RHS); |
12645 | |
12646 | bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); |
12647 | |
12648 | bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); |
12649 | |
12650 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
12651 | AssignmentAction Action, |
12652 | bool AllowExplicit = false); |
12653 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
12654 | const ImplicitConversionSequence& ICS, |
12655 | AssignmentAction Action, |
12656 | CheckedConversionKind CCK |
12657 | = CCK_ImplicitConversion); |
12658 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
12659 | const StandardConversionSequence& SCS, |
12660 | AssignmentAction Action, |
12661 | CheckedConversionKind CCK); |
12662 | |
12663 | ExprResult PerformQualificationConversion( |
12664 | Expr *E, QualType Ty, ExprValueKind VK = VK_PRValue, |
12665 | CheckedConversionKind CCK = CCK_ImplicitConversion); |
12666 | |
12667 | /// the following "Check" methods will return a valid/converted QualType |
12668 | /// or a null QualType (indicating an error diagnostic was issued). |
12669 | |
12670 | /// type checking binary operators (subroutines of CreateBuiltinBinOp). |
12671 | QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS, |
12672 | ExprResult &RHS); |
12673 | QualType InvalidLogicalVectorOperands(SourceLocation Loc, ExprResult &LHS, |
12674 | ExprResult &RHS); |
12675 | QualType CheckPointerToMemberOperands( // C++ 5.5 |
12676 | ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, |
12677 | SourceLocation OpLoc, bool isIndirect); |
12678 | QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
12679 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign, |
12680 | bool IsDivide); |
12681 | QualType CheckRemainderOperands( // C99 6.5.5 |
12682 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
12683 | bool IsCompAssign = false); |
12684 | QualType CheckAdditionOperands( // C99 6.5.6 |
12685 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
12686 | BinaryOperatorKind Opc, QualType* CompLHSTy = nullptr); |
12687 | QualType CheckSubtractionOperands( // C99 6.5.6 |
12688 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
12689 | QualType* CompLHSTy = nullptr); |
12690 | QualType CheckShiftOperands( // C99 6.5.7 |
12691 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
12692 | BinaryOperatorKind Opc, bool IsCompAssign = false); |
12693 | void CheckPtrComparisonWithNullChar(ExprResult &E, ExprResult &NullE); |
12694 | QualType CheckCompareOperands( // C99 6.5.8/9 |
12695 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
12696 | BinaryOperatorKind Opc); |
12697 | QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
12698 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
12699 | BinaryOperatorKind Opc); |
12700 | QualType CheckLogicalOperands( // C99 6.5.[13,14] |
12701 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
12702 | BinaryOperatorKind Opc); |
12703 | // CheckAssignmentOperands is used for both simple and compound assignment. |
12704 | // For simple assignment, pass both expressions and a null converted type. |
12705 | // For compound assignment, pass both expressions and the converted type. |
12706 | QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] |
12707 | Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType, |
12708 | BinaryOperatorKind Opc); |
12709 | |
12710 | ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc, |
12711 | UnaryOperatorKind Opcode, Expr *Op); |
12712 | ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc, |
12713 | BinaryOperatorKind Opcode, |
12714 | Expr *LHS, Expr *RHS); |
12715 | ExprResult checkPseudoObjectRValue(Expr *E); |
12716 | Expr *recreateSyntacticForm(PseudoObjectExpr *E); |
12717 | |
12718 | QualType CheckConditionalOperands( // C99 6.5.15 |
12719 | ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, |
12720 | ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc); |
12721 | QualType CXXCheckConditionalOperands( // C++ 5.16 |
12722 | ExprResult &cond, ExprResult &lhs, ExprResult &rhs, |
12723 | ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); |
12724 | QualType CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS, |
12725 | ExprResult &RHS, |
12726 | SourceLocation QuestionLoc); |
12727 | |
12728 | QualType CheckSizelessVectorConditionalTypes(ExprResult &Cond, |
12729 | ExprResult &LHS, ExprResult &RHS, |
12730 | SourceLocation QuestionLoc); |
12731 | QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, |
12732 | bool ConvertArgs = true); |
12733 | QualType FindCompositePointerType(SourceLocation Loc, |
12734 | ExprResult &E1, ExprResult &E2, |
12735 | bool ConvertArgs = true) { |
12736 | Expr *E1Tmp = E1.get(), *E2Tmp = E2.get(); |
12737 | QualType Composite = |
12738 | FindCompositePointerType(Loc, E1Tmp, E2Tmp, ConvertArgs); |
12739 | E1 = E1Tmp; |
12740 | E2 = E2Tmp; |
12741 | return Composite; |
12742 | } |
12743 | |
12744 | QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, |
12745 | SourceLocation QuestionLoc); |
12746 | |
12747 | bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr, |
12748 | SourceLocation QuestionLoc); |
12749 | |
12750 | void DiagnoseAlwaysNonNullPointer(Expr *E, |
12751 | Expr::NullPointerConstantKind NullType, |
12752 | bool IsEqual, SourceRange Range); |
12753 | |
12754 | /// type checking for vector binary operators. |
12755 | QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS, |
12756 | SourceLocation Loc, bool IsCompAssign, |
12757 | bool AllowBothBool, bool AllowBoolConversion, |
12758 | bool AllowBoolOperation, bool ReportInvalid); |
12759 | QualType GetSignedVectorType(QualType V); |
12760 | QualType GetSignedSizelessVectorType(QualType V); |
12761 | QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, |
12762 | SourceLocation Loc, |
12763 | BinaryOperatorKind Opc); |
12764 | QualType CheckSizelessVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, |
12765 | SourceLocation Loc, |
12766 | BinaryOperatorKind Opc); |
12767 | QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, |
12768 | SourceLocation Loc); |
12769 | |
12770 | // type checking for sizeless vector binary operators. |
12771 | QualType CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS, |
12772 | SourceLocation Loc, bool IsCompAssign, |
12773 | ArithConvKind OperationKind); |
12774 | |
12775 | /// Type checking for matrix binary operators. |
12776 | QualType CheckMatrixElementwiseOperands(ExprResult &LHS, ExprResult &RHS, |
12777 | SourceLocation Loc, |
12778 | bool IsCompAssign); |
12779 | QualType CheckMatrixMultiplyOperands(ExprResult &LHS, ExprResult &RHS, |
12780 | SourceLocation Loc, bool IsCompAssign); |
12781 | |
12782 | bool isValidSveBitcast(QualType srcType, QualType destType); |
12783 | bool isValidRVVBitcast(QualType srcType, QualType destType); |
12784 | |
12785 | bool areMatrixTypesOfTheSameDimension(QualType srcTy, QualType destTy); |
12786 | |
12787 | bool areVectorTypesSameSize(QualType srcType, QualType destType); |
12788 | bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType); |
12789 | bool isLaxVectorConversion(QualType srcType, QualType destType); |
12790 | bool anyAltivecTypes(QualType srcType, QualType destType); |
12791 | |
12792 | /// type checking declaration initializers (C99 6.7.8) |
12793 | bool CheckForConstantInitializer(Expr *e, QualType t); |
12794 | |
12795 | // type checking C++ declaration initializers (C++ [dcl.init]). |
12796 | |
12797 | /// ReferenceCompareResult - Expresses the result of comparing two |
12798 | /// types (cv1 T1 and cv2 T2) to determine their compatibility for the |
12799 | /// purposes of initialization by reference (C++ [dcl.init.ref]p4). |
12800 | enum ReferenceCompareResult { |
12801 | /// Ref_Incompatible - The two types are incompatible, so direct |
12802 | /// reference binding is not possible. |
12803 | Ref_Incompatible = 0, |
12804 | /// Ref_Related - The two types are reference-related, which means |
12805 | /// that their unqualified forms (T1 and T2) are either the same |
12806 | /// or T1 is a base class of T2. |
12807 | Ref_Related, |
12808 | /// Ref_Compatible - The two types are reference-compatible. |
12809 | Ref_Compatible |
12810 | }; |
12811 | |
12812 | // Fake up a scoped enumeration that still contextually converts to bool. |
12813 | struct ReferenceConversionsScope { |
12814 | /// The conversions that would be performed on an lvalue of type T2 when |
12815 | /// binding a reference of type T1 to it, as determined when evaluating |
12816 | /// whether T1 is reference-compatible with T2. |
12817 | enum ReferenceConversions { |
12818 | Qualification = 0x1, |
12819 | NestedQualification = 0x2, |
12820 | Function = 0x4, |
12821 | DerivedToBase = 0x8, |
12822 | ObjC = 0x10, |
12823 | ObjCLifetime = 0x20, |
12824 | |
12825 | LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/ObjCLifetime) |
12826 | }; |
12827 | }; |
12828 | using ReferenceConversions = ReferenceConversionsScope::ReferenceConversions; |
12829 | |
12830 | ReferenceCompareResult |
12831 | CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2, |
12832 | ReferenceConversions *Conv = nullptr); |
12833 | |
12834 | ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, |
12835 | Expr *CastExpr, CastKind &CastKind, |
12836 | ExprValueKind &VK, CXXCastPath &Path); |
12837 | |
12838 | /// Force an expression with unknown-type to an expression of the |
12839 | /// given type. |
12840 | ExprResult forceUnknownAnyToType(Expr *E, QualType ToType); |
12841 | |
12842 | /// Type-check an expression that's being passed to an |
12843 | /// __unknown_anytype parameter. |
12844 | ExprResult checkUnknownAnyArg(SourceLocation callLoc, |
12845 | Expr *result, QualType ¶mType); |
12846 | |
12847 | // CheckMatrixCast - Check type constraints for matrix casts. |
12848 | // We allow casting between matrixes of the same dimensions i.e. when they |
12849 | // have the same number of rows and column. Returns true if the cast is |
12850 | // invalid. |
12851 | bool CheckMatrixCast(SourceRange R, QualType DestTy, QualType SrcTy, |
12852 | CastKind &Kind); |
12853 | |
12854 | // CheckVectorCast - check type constraints for vectors. |
12855 | // Since vectors are an extension, there are no C standard reference for this. |
12856 | // We allow casting between vectors and integer datatypes of the same size. |
12857 | // returns true if the cast is invalid |
12858 | bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, |
12859 | CastKind &Kind); |
12860 | |
12861 | /// Prepare `SplattedExpr` for a vector splat operation, adding |
12862 | /// implicit casts if necessary. |
12863 | ExprResult prepareVectorSplat(QualType VectorTy, Expr *SplattedExpr); |
12864 | |
12865 | // CheckExtVectorCast - check type constraints for extended vectors. |
12866 | // Since vectors are an extension, there are no C standard reference for this. |
12867 | // We allow casting between vectors and integer datatypes of the same size, |
12868 | // or vectors and the element type of that vector. |
12869 | // returns the cast expr |
12870 | ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr, |
12871 | CastKind &Kind); |
12872 | |
12873 | ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, QualType Type, |
12874 | SourceLocation LParenLoc, |
12875 | Expr *CastExpr, |
12876 | SourceLocation RParenLoc); |
12877 | |
12878 | enum ARCConversionResult { ACR_okay, ACR_unbridged, ACR_error }; |
12879 | |
12880 | /// Checks for invalid conversions and casts between |
12881 | /// retainable pointers and other pointer kinds for ARC and Weak. |
12882 | ARCConversionResult CheckObjCConversion(SourceRange castRange, |
12883 | QualType castType, Expr *&op, |
12884 | CheckedConversionKind CCK, |
12885 | bool Diagnose = true, |
12886 | bool DiagnoseCFAudited = false, |
12887 | BinaryOperatorKind Opc = BO_PtrMemD |
12888 | ); |
12889 | |
12890 | Expr *stripARCUnbridgedCast(Expr *e); |
12891 | void diagnoseARCUnbridgedCast(Expr *e); |
12892 | |
12893 | bool CheckObjCARCUnavailableWeakConversion(QualType castType, |
12894 | QualType ExprType); |
12895 | |
12896 | /// checkRetainCycles - Check whether an Objective-C message send |
12897 | /// might create an obvious retain cycle. |
12898 | void checkRetainCycles(ObjCMessageExpr *msg); |
12899 | void checkRetainCycles(Expr *receiver, Expr *argument); |
12900 | void checkRetainCycles(VarDecl *Var, Expr *Init); |
12901 | |
12902 | /// checkUnsafeAssigns - Check whether +1 expr is being assigned |
12903 | /// to weak/__unsafe_unretained type. |
12904 | bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); |
12905 | |
12906 | /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned |
12907 | /// to weak/__unsafe_unretained expression. |
12908 | void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); |
12909 | |
12910 | /// CheckMessageArgumentTypes - Check types in an Obj-C message send. |
12911 | /// \param Method - May be null. |
12912 | /// \param [out] ReturnType - The return type of the send. |
12913 | /// \return true iff there were any incompatible types. |
12914 | bool CheckMessageArgumentTypes(const Expr *Receiver, QualType ReceiverType, |
12915 | MultiExprArg Args, Selector Sel, |
12916 | ArrayRef<SourceLocation> SelectorLocs, |
12917 | ObjCMethodDecl *Method, bool isClassMessage, |
12918 | bool isSuperMessage, SourceLocation lbrac, |
12919 | SourceLocation rbrac, SourceRange RecRange, |
12920 | QualType &ReturnType, ExprValueKind &VK); |
12921 | |
12922 | /// Determine the result of a message send expression based on |
12923 | /// the type of the receiver, the method expected to receive the message, |
12924 | /// and the form of the message send. |
12925 | QualType getMessageSendResultType(const Expr *Receiver, QualType ReceiverType, |
12926 | ObjCMethodDecl *Method, bool isClassMessage, |
12927 | bool isSuperMessage); |
12928 | |
12929 | /// If the given expression involves a message send to a method |
12930 | /// with a related result type, emit a note describing what happened. |
12931 | void EmitRelatedResultTypeNote(const Expr *E); |
12932 | |
12933 | /// Given that we had incompatible pointer types in a return |
12934 | /// statement, check whether we're in a method with a related result |
12935 | /// type, and if so, emit a note describing what happened. |
12936 | void EmitRelatedResultTypeNoteForReturn(QualType destType); |
12937 | |
12938 | class ConditionResult { |
12939 | Decl *ConditionVar; |
12940 | FullExprArg Condition; |
12941 | bool Invalid; |
12942 | std::optional<bool> KnownValue; |
12943 | |
12944 | friend class Sema; |
12945 | ConditionResult(Sema &S, Decl *ConditionVar, FullExprArg Condition, |
12946 | bool IsConstexpr) |
12947 | : ConditionVar(ConditionVar), Condition(Condition), Invalid(false) { |
12948 | if (IsConstexpr && Condition.get()) { |
12949 | if (std::optional<llvm::APSInt> Val = |
12950 | Condition.get()->getIntegerConstantExpr(S.Context)) { |
12951 | KnownValue = !!(*Val); |
12952 | } |
12953 | } |
12954 | } |
12955 | explicit ConditionResult(bool Invalid) |
12956 | : ConditionVar(nullptr), Condition(nullptr), Invalid(Invalid), |
12957 | KnownValue(std::nullopt) {} |
12958 | |
12959 | public: |
12960 | ConditionResult() : ConditionResult(false) {} |
12961 | bool isInvalid() const { return Invalid; } |
12962 | std::pair<VarDecl *, Expr *> get() const { |
12963 | return std::make_pair(cast_or_null<VarDecl>(ConditionVar), |
12964 | Condition.get()); |
12965 | } |
12966 | std::optional<bool> getKnownValue() const { return KnownValue; } |
12967 | }; |
12968 | static ConditionResult ConditionError() { return ConditionResult(true); } |
12969 | |
12970 | enum class ConditionKind { |
12971 | Boolean, ///< A boolean condition, from 'if', 'while', 'for', or 'do'. |
12972 | ConstexprIf, ///< A constant boolean condition from 'if constexpr'. |
12973 | Switch ///< An integral condition for a 'switch' statement. |
12974 | }; |
12975 | QualType PreferredConditionType(ConditionKind K) const { |
12976 | return K == ConditionKind::Switch ? Context.IntTy : Context.BoolTy; |
12977 | } |
12978 | |
12979 | ConditionResult ActOnCondition(Scope *S, SourceLocation Loc, Expr *SubExpr, |
12980 | ConditionKind CK, bool MissingOK = false); |
12981 | |
12982 | ConditionResult ActOnConditionVariable(Decl *ConditionVar, |
12983 | SourceLocation StmtLoc, |
12984 | ConditionKind CK); |
12985 | |
12986 | DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); |
12987 | |
12988 | ExprResult CheckConditionVariable(VarDecl *ConditionVar, |
12989 | SourceLocation StmtLoc, |
12990 | ConditionKind CK); |
12991 | ExprResult CheckSwitchCondition(SourceLocation SwitchLoc, Expr *Cond); |
12992 | |
12993 | /// CheckBooleanCondition - Diagnose problems involving the use of |
12994 | /// the given expression as a boolean condition (e.g. in an if |
12995 | /// statement). Also performs the standard function and array |
12996 | /// decays, possibly changing the input variable. |
12997 | /// |
12998 | /// \param Loc - A location associated with the condition, e.g. the |
12999 | /// 'if' keyword. |
13000 | /// \return true iff there were any errors |
13001 | ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E, |
13002 | bool IsConstexpr = false); |
13003 | |
13004 | /// ActOnExplicitBoolSpecifier - Build an ExplicitSpecifier from an expression |
13005 | /// found in an explicit(bool) specifier. |
13006 | ExplicitSpecifier ActOnExplicitBoolSpecifier(Expr *E); |
13007 | |
13008 | /// tryResolveExplicitSpecifier - Attempt to resolve the explict specifier. |
13009 | /// Returns true if the explicit specifier is now resolved. |
13010 | bool tryResolveExplicitSpecifier(ExplicitSpecifier &ExplicitSpec); |
13011 | |
13012 | /// DiagnoseAssignmentAsCondition - Given that an expression is |
13013 | /// being used as a boolean condition, warn if it's an assignment. |
13014 | void DiagnoseAssignmentAsCondition(Expr *E); |
13015 | |
13016 | /// Redundant parentheses over an equality comparison can indicate |
13017 | /// that the user intended an assignment used as condition. |
13018 | void (ParenExpr *ParenE); |
13019 | |
13020 | /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. |
13021 | ExprResult CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr = false); |
13022 | |
13023 | /// Checks that the Objective-C declaration is declared in the global scope. |
13024 | /// Emits an error and marks the declaration as invalid if it's not declared |
13025 | /// in the global scope. |
13026 | bool CheckObjCDeclScope(Decl *D); |
13027 | |
13028 | /// Abstract base class used for diagnosing integer constant |
13029 | /// expression violations. |
13030 | class VerifyICEDiagnoser { |
13031 | public: |
13032 | bool Suppress; |
13033 | |
13034 | VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) { } |
13035 | |
13036 | virtual SemaDiagnosticBuilder |
13037 | diagnoseNotICEType(Sema &S, SourceLocation Loc, QualType T); |
13038 | virtual SemaDiagnosticBuilder diagnoseNotICE(Sema &S, |
13039 | SourceLocation Loc) = 0; |
13040 | virtual SemaDiagnosticBuilder diagnoseFold(Sema &S, SourceLocation Loc); |
13041 | virtual ~VerifyICEDiagnoser() {} |
13042 | }; |
13043 | |
13044 | enum AllowFoldKind { |
13045 | NoFold, |
13046 | AllowFold, |
13047 | }; |
13048 | |
13049 | /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE, |
13050 | /// and reports the appropriate diagnostics. Returns false on success. |
13051 | /// Can optionally return the value of the expression. |
13052 | ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
13053 | VerifyICEDiagnoser &Diagnoser, |
13054 | AllowFoldKind CanFold = NoFold); |
13055 | ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
13056 | unsigned DiagID, |
13057 | AllowFoldKind CanFold = NoFold); |
13058 | ExprResult VerifyIntegerConstantExpression(Expr *E, |
13059 | llvm::APSInt *Result = nullptr, |
13060 | AllowFoldKind CanFold = NoFold); |
13061 | ExprResult VerifyIntegerConstantExpression(Expr *E, |
13062 | AllowFoldKind CanFold = NoFold) { |
13063 | return VerifyIntegerConstantExpression(E, nullptr, CanFold); |
13064 | } |
13065 | |
13066 | /// VerifyBitField - verifies that a bit field expression is an ICE and has |
13067 | /// the correct width, and that the field type is valid. |
13068 | /// Returns false on success. |
13069 | ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, |
13070 | QualType FieldTy, bool IsMsStruct, Expr *BitWidth); |
13071 | |
13072 | private: |
13073 | unsigned ForceCUDAHostDeviceDepth = 0; |
13074 | |
13075 | public: |
13076 | /// Increments our count of the number of times we've seen a pragma forcing |
13077 | /// functions to be __host__ __device__. So long as this count is greater |
13078 | /// than zero, all functions encountered will be __host__ __device__. |
13079 | void PushForceCUDAHostDevice(); |
13080 | |
13081 | /// Decrements our count of the number of times we've seen a pragma forcing |
13082 | /// functions to be __host__ __device__. Returns false if the count is 0 |
13083 | /// before incrementing, so you can emit an error. |
13084 | bool PopForceCUDAHostDevice(); |
13085 | |
13086 | /// Diagnostics that are emitted only if we discover that the given function |
13087 | /// must be codegen'ed. Because handling these correctly adds overhead to |
13088 | /// compilation, this is currently only enabled for CUDA compilations. |
13089 | llvm::DenseMap<CanonicalDeclPtr<const FunctionDecl>, |
13090 | std::vector<PartialDiagnosticAt>> |
13091 | DeviceDeferredDiags; |
13092 | |
13093 | /// A pair of a canonical FunctionDecl and a SourceLocation. When used as the |
13094 | /// key in a hashtable, both the FD and location are hashed. |
13095 | struct FunctionDeclAndLoc { |
13096 | CanonicalDeclPtr<const FunctionDecl> FD; |
13097 | SourceLocation Loc; |
13098 | }; |
13099 | |
13100 | /// FunctionDecls and SourceLocations for which CheckCUDACall has emitted a |
13101 | /// (maybe deferred) "bad call" diagnostic. We use this to avoid emitting the |
13102 | /// same deferred diag twice. |
13103 | llvm::DenseSet<FunctionDeclAndLoc> LocsWithCUDACallDiags; |
13104 | |
13105 | /// An inverse call graph, mapping known-emitted functions to one of their |
13106 | /// known-emitted callers (plus the location of the call). |
13107 | /// |
13108 | /// Functions that we can tell a priori must be emitted aren't added to this |
13109 | /// map. |
13110 | llvm::DenseMap</* Callee = */ CanonicalDeclPtr<const FunctionDecl>, |
13111 | /* Caller = */ FunctionDeclAndLoc> |
13112 | DeviceKnownEmittedFns; |
13113 | |
13114 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
13115 | /// context is "used as device code". |
13116 | /// |
13117 | /// - If CurContext is a __host__ function, does not emit any diagnostics |
13118 | /// unless \p EmitOnBothSides is true. |
13119 | /// - If CurContext is a __device__ or __global__ function, emits the |
13120 | /// diagnostics immediately. |
13121 | /// - If CurContext is a __host__ __device__ function and we are compiling for |
13122 | /// the device, creates a diagnostic which is emitted if and when we realize |
13123 | /// that the function will be codegen'ed. |
13124 | /// |
13125 | /// Example usage: |
13126 | /// |
13127 | /// // Variable-length arrays are not allowed in CUDA device code. |
13128 | /// if (CUDADiagIfDeviceCode(Loc, diag::err_cuda_vla) << CurrentCUDATarget()) |
13129 | /// return ExprError(); |
13130 | /// // Otherwise, continue parsing as normal. |
13131 | SemaDiagnosticBuilder CUDADiagIfDeviceCode(SourceLocation Loc, |
13132 | unsigned DiagID); |
13133 | |
13134 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
13135 | /// context is "used as host code". |
13136 | /// |
13137 | /// Same as CUDADiagIfDeviceCode, with "host" and "device" switched. |
13138 | SemaDiagnosticBuilder CUDADiagIfHostCode(SourceLocation Loc, unsigned DiagID); |
13139 | |
13140 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
13141 | /// context is "used as device code". |
13142 | /// |
13143 | /// - If CurContext is a `declare target` function or it is known that the |
13144 | /// function is emitted for the device, emits the diagnostics immediately. |
13145 | /// - If CurContext is a non-`declare target` function and we are compiling |
13146 | /// for the device, creates a diagnostic which is emitted if and when we |
13147 | /// realize that the function will be codegen'ed. |
13148 | /// |
13149 | /// Example usage: |
13150 | /// |
13151 | /// // Variable-length arrays are not allowed in NVPTX device code. |
13152 | /// if (diagIfOpenMPDeviceCode(Loc, diag::err_vla_unsupported)) |
13153 | /// return ExprError(); |
13154 | /// // Otherwise, continue parsing as normal. |
13155 | SemaDiagnosticBuilder diagIfOpenMPDeviceCode(SourceLocation Loc, |
13156 | unsigned DiagID, |
13157 | const FunctionDecl *FD); |
13158 | |
13159 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
13160 | /// context is "used as host code". |
13161 | /// |
13162 | /// - If CurContext is a `declare target` function or it is known that the |
13163 | /// function is emitted for the host, emits the diagnostics immediately. |
13164 | /// - If CurContext is a non-host function, just ignore it. |
13165 | /// |
13166 | /// Example usage: |
13167 | /// |
13168 | /// // Variable-length arrays are not allowed in NVPTX device code. |
13169 | /// if (diagIfOpenMPHostode(Loc, diag::err_vla_unsupported)) |
13170 | /// return ExprError(); |
13171 | /// // Otherwise, continue parsing as normal. |
13172 | SemaDiagnosticBuilder diagIfOpenMPHostCode(SourceLocation Loc, |
13173 | unsigned DiagID, |
13174 | const FunctionDecl *FD); |
13175 | |
13176 | SemaDiagnosticBuilder targetDiag(SourceLocation Loc, unsigned DiagID, |
13177 | const FunctionDecl *FD = nullptr); |
13178 | SemaDiagnosticBuilder targetDiag(SourceLocation Loc, |
13179 | const PartialDiagnostic &PD, |
13180 | const FunctionDecl *FD = nullptr) { |
13181 | return targetDiag(Loc, PD.getDiagID(), FD) << PD; |
13182 | } |
13183 | |
13184 | /// Check if the type is allowed to be used for the current target. |
13185 | void checkTypeSupport(QualType Ty, SourceLocation Loc, |
13186 | ValueDecl *D = nullptr); |
13187 | |
13188 | enum CUDAFunctionTarget { |
13189 | CFT_Device, |
13190 | CFT_Global, |
13191 | CFT_Host, |
13192 | CFT_HostDevice, |
13193 | CFT_InvalidTarget |
13194 | }; |
13195 | |
13196 | /// Determines whether the given function is a CUDA device/host/kernel/etc. |
13197 | /// function. |
13198 | /// |
13199 | /// Use this rather than examining the function's attributes yourself -- you |
13200 | /// will get it wrong. Returns CFT_Host if D is null. |
13201 | CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D, |
13202 | bool IgnoreImplicitHDAttr = false); |
13203 | CUDAFunctionTarget IdentifyCUDATarget(const ParsedAttributesView &Attrs); |
13204 | |
13205 | enum CUDAVariableTarget { |
13206 | CVT_Device, /// Emitted on device side with a shadow variable on host side |
13207 | CVT_Host, /// Emitted on host side only |
13208 | CVT_Both, /// Emitted on both sides with different addresses |
13209 | CVT_Unified, /// Emitted as a unified address, e.g. managed variables |
13210 | }; |
13211 | /// Determines whether the given variable is emitted on host or device side. |
13212 | CUDAVariableTarget IdentifyCUDATarget(const VarDecl *D); |
13213 | |
13214 | /// Gets the CUDA target for the current context. |
13215 | CUDAFunctionTarget CurrentCUDATarget() { |
13216 | return IdentifyCUDATarget(dyn_cast<FunctionDecl>(CurContext)); |
13217 | } |
13218 | |
13219 | static bool isCUDAImplicitHostDeviceFunction(const FunctionDecl *D); |
13220 | |
13221 | // CUDA function call preference. Must be ordered numerically from |
13222 | // worst to best. |
13223 | enum CUDAFunctionPreference { |
13224 | CFP_Never, // Invalid caller/callee combination. |
13225 | CFP_WrongSide, // Calls from host-device to host or device |
13226 | // function that do not match current compilation |
13227 | // mode. |
13228 | CFP_HostDevice, // Any calls to host/device functions. |
13229 | CFP_SameSide, // Calls from host-device to host or device |
13230 | // function matching current compilation mode. |
13231 | CFP_Native, // host-to-host or device-to-device calls. |
13232 | }; |
13233 | |
13234 | /// Identifies relative preference of a given Caller/Callee |
13235 | /// combination, based on their host/device attributes. |
13236 | /// \param Caller function which needs address of \p Callee. |
13237 | /// nullptr in case of global context. |
13238 | /// \param Callee target function |
13239 | /// |
13240 | /// \returns preference value for particular Caller/Callee combination. |
13241 | CUDAFunctionPreference IdentifyCUDAPreference(const FunctionDecl *Caller, |
13242 | const FunctionDecl *Callee); |
13243 | |
13244 | /// Determines whether Caller may invoke Callee, based on their CUDA |
13245 | /// host/device attributes. Returns false if the call is not allowed. |
13246 | /// |
13247 | /// Note: Will return true for CFP_WrongSide calls. These may appear in |
13248 | /// semantically correct CUDA programs, but only if they're never codegen'ed. |
13249 | bool IsAllowedCUDACall(const FunctionDecl *Caller, |
13250 | const FunctionDecl *Callee) { |
13251 | return IdentifyCUDAPreference(Caller, Callee) != CFP_Never; |
13252 | } |
13253 | |
13254 | /// May add implicit CUDAHostAttr and CUDADeviceAttr attributes to FD, |
13255 | /// depending on FD and the current compilation settings. |
13256 | void maybeAddCUDAHostDeviceAttrs(FunctionDecl *FD, |
13257 | const LookupResult &Previous); |
13258 | |
13259 | /// May add implicit CUDAConstantAttr attribute to VD, depending on VD |
13260 | /// and current compilation settings. |
13261 | void MaybeAddCUDAConstantAttr(VarDecl *VD); |
13262 | |
13263 | public: |
13264 | /// Check whether we're allowed to call Callee from the current context. |
13265 | /// |
13266 | /// - If the call is never allowed in a semantically-correct program |
13267 | /// (CFP_Never), emits an error and returns false. |
13268 | /// |
13269 | /// - If the call is allowed in semantically-correct programs, but only if |
13270 | /// it's never codegen'ed (CFP_WrongSide), creates a deferred diagnostic to |
13271 | /// be emitted if and when the caller is codegen'ed, and returns true. |
13272 | /// |
13273 | /// Will only create deferred diagnostics for a given SourceLocation once, |
13274 | /// so you can safely call this multiple times without generating duplicate |
13275 | /// deferred errors. |
13276 | /// |
13277 | /// - Otherwise, returns true without emitting any diagnostics. |
13278 | bool CheckCUDACall(SourceLocation Loc, FunctionDecl *Callee); |
13279 | |
13280 | void CUDACheckLambdaCapture(CXXMethodDecl *D, const sema::Capture &Capture); |
13281 | |
13282 | /// Set __device__ or __host__ __device__ attributes on the given lambda |
13283 | /// operator() method. |
13284 | /// |
13285 | /// CUDA lambdas by default is host device function unless it has explicit |
13286 | /// host or device attribute. |
13287 | void CUDASetLambdaAttrs(CXXMethodDecl *Method); |
13288 | |
13289 | /// Finds a function in \p Matches with highest calling priority |
13290 | /// from \p Caller context and erases all functions with lower |
13291 | /// calling priority. |
13292 | void EraseUnwantedCUDAMatches( |
13293 | const FunctionDecl *Caller, |
13294 | SmallVectorImpl<std::pair<DeclAccessPair, FunctionDecl *>> &Matches); |
13295 | |
13296 | /// Given a implicit special member, infer its CUDA target from the |
13297 | /// calls it needs to make to underlying base/field special members. |
13298 | /// \param ClassDecl the class for which the member is being created. |
13299 | /// \param CSM the kind of special member. |
13300 | /// \param MemberDecl the special member itself. |
13301 | /// \param ConstRHS true if this is a copy operation with a const object on |
13302 | /// its RHS. |
13303 | /// \param Diagnose true if this call should emit diagnostics. |
13304 | /// \return true if there was an error inferring. |
13305 | /// The result of this call is implicit CUDA target attribute(s) attached to |
13306 | /// the member declaration. |
13307 | bool inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl, |
13308 | CXXSpecialMember CSM, |
13309 | CXXMethodDecl *MemberDecl, |
13310 | bool ConstRHS, |
13311 | bool Diagnose); |
13312 | |
13313 | /// \return true if \p CD can be considered empty according to CUDA |
13314 | /// (E.2.3.1 in CUDA 7.5 Programming guide). |
13315 | bool isEmptyCudaConstructor(SourceLocation Loc, CXXConstructorDecl *CD); |
13316 | bool isEmptyCudaDestructor(SourceLocation Loc, CXXDestructorDecl *CD); |
13317 | |
13318 | // \brief Checks that initializers of \p Var satisfy CUDA restrictions. In |
13319 | // case of error emits appropriate diagnostic and invalidates \p Var. |
13320 | // |
13321 | // \details CUDA allows only empty constructors as initializers for global |
13322 | // variables (see E.2.3.1, CUDA 7.5). The same restriction also applies to all |
13323 | // __shared__ variables whether they are local or not (they all are implicitly |
13324 | // static in CUDA). One exception is that CUDA allows constant initializers |
13325 | // for __constant__ and __device__ variables. |
13326 | void checkAllowedCUDAInitializer(VarDecl *VD); |
13327 | |
13328 | /// Check whether NewFD is a valid overload for CUDA. Emits |
13329 | /// diagnostics and invalidates NewFD if not. |
13330 | void checkCUDATargetOverload(FunctionDecl *NewFD, |
13331 | const LookupResult &Previous); |
13332 | /// Copies target attributes from the template TD to the function FD. |
13333 | void inheritCUDATargetAttrs(FunctionDecl *FD, const FunctionTemplateDecl &TD); |
13334 | |
13335 | /// Returns the name of the launch configuration function. This is the name |
13336 | /// of the function that will be called to configure kernel call, with the |
13337 | /// parameters specified via <<<>>>. |
13338 | std::string getCudaConfigureFuncName() const; |
13339 | |
13340 | /// \name Code completion |
13341 | //@{ |
13342 | /// Describes the context in which code completion occurs. |
13343 | enum ParserCompletionContext { |
13344 | /// Code completion occurs at top-level or namespace context. |
13345 | PCC_Namespace, |
13346 | /// Code completion occurs within a class, struct, or union. |
13347 | PCC_Class, |
13348 | /// Code completion occurs within an Objective-C interface, protocol, |
13349 | /// or category. |
13350 | PCC_ObjCInterface, |
13351 | /// Code completion occurs within an Objective-C implementation or |
13352 | /// category implementation |
13353 | PCC_ObjCImplementation, |
13354 | /// Code completion occurs within the list of instance variables |
13355 | /// in an Objective-C interface, protocol, category, or implementation. |
13356 | PCC_ObjCInstanceVariableList, |
13357 | /// Code completion occurs following one or more template |
13358 | /// headers. |
13359 | PCC_Template, |
13360 | /// Code completion occurs following one or more template |
13361 | /// headers within a class. |
13362 | PCC_MemberTemplate, |
13363 | /// Code completion occurs within an expression. |
13364 | PCC_Expression, |
13365 | /// Code completion occurs within a statement, which may |
13366 | /// also be an expression or a declaration. |
13367 | PCC_Statement, |
13368 | /// Code completion occurs at the beginning of the |
13369 | /// initialization statement (or expression) in a for loop. |
13370 | PCC_ForInit, |
13371 | /// Code completion occurs within the condition of an if, |
13372 | /// while, switch, or for statement. |
13373 | PCC_Condition, |
13374 | /// Code completion occurs within the body of a function on a |
13375 | /// recovery path, where we do not have a specific handle on our position |
13376 | /// in the grammar. |
13377 | PCC_RecoveryInFunction, |
13378 | /// Code completion occurs where only a type is permitted. |
13379 | PCC_Type, |
13380 | /// Code completion occurs in a parenthesized expression, which |
13381 | /// might also be a type cast. |
13382 | PCC_ParenthesizedExpression, |
13383 | /// Code completion occurs within a sequence of declaration |
13384 | /// specifiers within a function, method, or block. |
13385 | PCC_LocalDeclarationSpecifiers |
13386 | }; |
13387 | |
13388 | void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path); |
13389 | void CodeCompleteOrdinaryName(Scope *S, |
13390 | ParserCompletionContext CompletionContext); |
13391 | void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, |
13392 | bool AllowNonIdentifiers, |
13393 | bool AllowNestedNameSpecifiers); |
13394 | |
13395 | struct CodeCompleteExpressionData; |
13396 | void CodeCompleteExpression(Scope *S, |
13397 | const CodeCompleteExpressionData &Data); |
13398 | void CodeCompleteExpression(Scope *S, QualType PreferredType, |
13399 | bool IsParenthesized = false); |
13400 | void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase, |
13401 | SourceLocation OpLoc, bool IsArrow, |
13402 | bool IsBaseExprStatement, |
13403 | QualType PreferredType); |
13404 | void CodeCompletePostfixExpression(Scope *S, ExprResult LHS, |
13405 | QualType PreferredType); |
13406 | void CodeCompleteTag(Scope *S, unsigned TagSpec); |
13407 | void CodeCompleteTypeQualifiers(DeclSpec &DS); |
13408 | void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D, |
13409 | const VirtSpecifiers *VS = nullptr); |
13410 | void CodeCompleteBracketDeclarator(Scope *S); |
13411 | void CodeCompleteCase(Scope *S); |
13412 | enum class AttributeCompletion { |
13413 | Attribute, |
13414 | Scope, |
13415 | None, |
13416 | }; |
13417 | void CodeCompleteAttribute( |
13418 | AttributeCommonInfo::Syntax Syntax, |
13419 | AttributeCompletion Completion = AttributeCompletion::Attribute, |
13420 | const IdentifierInfo *Scope = nullptr); |
13421 | /// Determines the preferred type of the current function argument, by |
13422 | /// examining the signatures of all possible overloads. |
13423 | /// Returns null if unknown or ambiguous, or if code completion is off. |
13424 | /// |
13425 | /// If the code completion point has been reached, also reports the function |
13426 | /// signatures that were considered. |
13427 | /// |
13428 | /// FIXME: rename to GuessCallArgumentType to reduce confusion. |
13429 | QualType ProduceCallSignatureHelp(Expr *Fn, ArrayRef<Expr *> Args, |
13430 | SourceLocation OpenParLoc); |
13431 | QualType ProduceConstructorSignatureHelp(QualType Type, SourceLocation Loc, |
13432 | ArrayRef<Expr *> Args, |
13433 | SourceLocation OpenParLoc, |
13434 | bool Braced); |
13435 | QualType ProduceCtorInitMemberSignatureHelp( |
13436 | Decl *ConstructorDecl, CXXScopeSpec SS, ParsedType TemplateTypeTy, |
13437 | ArrayRef<Expr *> ArgExprs, IdentifierInfo *II, SourceLocation OpenParLoc, |
13438 | bool Braced); |
13439 | QualType ProduceTemplateArgumentSignatureHelp( |
13440 | TemplateTy, ArrayRef<ParsedTemplateArgument>, SourceLocation LAngleLoc); |
13441 | void CodeCompleteInitializer(Scope *S, Decl *D); |
13442 | /// Trigger code completion for a record of \p BaseType. \p InitExprs are |
13443 | /// expressions in the initializer list seen so far and \p D is the current |
13444 | /// Designation being parsed. |
13445 | void CodeCompleteDesignator(const QualType BaseType, |
13446 | llvm::ArrayRef<Expr *> InitExprs, |
13447 | const Designation &D); |
13448 | void CodeCompleteAfterIf(Scope *S, bool IsBracedThen); |
13449 | |
13450 | void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext, |
13451 | bool IsUsingDeclaration, QualType BaseType, |
13452 | QualType PreferredType); |
13453 | void CodeCompleteUsing(Scope *S); |
13454 | void CodeCompleteUsingDirective(Scope *S); |
13455 | void CodeCompleteNamespaceDecl(Scope *S); |
13456 | void CodeCompleteNamespaceAliasDecl(Scope *S); |
13457 | void CodeCompleteOperatorName(Scope *S); |
13458 | void CodeCompleteConstructorInitializer( |
13459 | Decl *Constructor, |
13460 | ArrayRef<CXXCtorInitializer *> Initializers); |
13461 | |
13462 | void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, |
13463 | bool AfterAmpersand); |
13464 | void CodeCompleteAfterFunctionEquals(Declarator &D); |
13465 | |
13466 | void CodeCompleteObjCAtDirective(Scope *S); |
13467 | void CodeCompleteObjCAtVisibility(Scope *S); |
13468 | void CodeCompleteObjCAtStatement(Scope *S); |
13469 | void CodeCompleteObjCAtExpression(Scope *S); |
13470 | void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); |
13471 | void CodeCompleteObjCPropertyGetter(Scope *S); |
13472 | void CodeCompleteObjCPropertySetter(Scope *S); |
13473 | void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, |
13474 | bool IsParameter); |
13475 | void CodeCompleteObjCMessageReceiver(Scope *S); |
13476 | void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, |
13477 | ArrayRef<IdentifierInfo *> SelIdents, |
13478 | bool AtArgumentExpression); |
13479 | void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, |
13480 | ArrayRef<IdentifierInfo *> SelIdents, |
13481 | bool AtArgumentExpression, |
13482 | bool IsSuper = false); |
13483 | void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, |
13484 | ArrayRef<IdentifierInfo *> SelIdents, |
13485 | bool AtArgumentExpression, |
13486 | ObjCInterfaceDecl *Super = nullptr); |
13487 | void CodeCompleteObjCForCollection(Scope *S, |
13488 | DeclGroupPtrTy IterationVar); |
13489 | void CodeCompleteObjCSelector(Scope *S, |
13490 | ArrayRef<IdentifierInfo *> SelIdents); |
13491 | void CodeCompleteObjCProtocolReferences( |
13492 | ArrayRef<IdentifierLocPair> Protocols); |
13493 | void CodeCompleteObjCProtocolDecl(Scope *S); |
13494 | void CodeCompleteObjCInterfaceDecl(Scope *S); |
13495 | void CodeCompleteObjCClassForwardDecl(Scope *S); |
13496 | void CodeCompleteObjCSuperclass(Scope *S, |
13497 | IdentifierInfo *ClassName, |
13498 | SourceLocation ClassNameLoc); |
13499 | void CodeCompleteObjCImplementationDecl(Scope *S); |
13500 | void CodeCompleteObjCInterfaceCategory(Scope *S, |
13501 | IdentifierInfo *ClassName, |
13502 | SourceLocation ClassNameLoc); |
13503 | void CodeCompleteObjCImplementationCategory(Scope *S, |
13504 | IdentifierInfo *ClassName, |
13505 | SourceLocation ClassNameLoc); |
13506 | void CodeCompleteObjCPropertyDefinition(Scope *S); |
13507 | void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, |
13508 | IdentifierInfo *PropertyName); |
13509 | void CodeCompleteObjCMethodDecl(Scope *S, |
13510 | std::optional<bool> IsInstanceMethod, |
13511 | ParsedType ReturnType); |
13512 | void CodeCompleteObjCMethodDeclSelector(Scope *S, |
13513 | bool IsInstanceMethod, |
13514 | bool AtParameterName, |
13515 | ParsedType ReturnType, |
13516 | ArrayRef<IdentifierInfo *> SelIdents); |
13517 | void CodeCompleteObjCClassPropertyRefExpr(Scope *S, IdentifierInfo &ClassName, |
13518 | SourceLocation ClassNameLoc, |
13519 | bool IsBaseExprStatement); |
13520 | void CodeCompletePreprocessorDirective(bool InConditional); |
13521 | void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); |
13522 | void CodeCompletePreprocessorMacroName(bool IsDefinition); |
13523 | void CodeCompletePreprocessorExpression(); |
13524 | void CodeCompletePreprocessorMacroArgument(Scope *S, |
13525 | IdentifierInfo *Macro, |
13526 | MacroInfo *MacroInfo, |
13527 | unsigned Argument); |
13528 | void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled); |
13529 | void CodeCompleteNaturalLanguage(); |
13530 | void CodeCompleteAvailabilityPlatformName(); |
13531 | void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, |
13532 | CodeCompletionTUInfo &CCTUInfo, |
13533 | SmallVectorImpl<CodeCompletionResult> &Results); |
13534 | //@} |
13535 | |
13536 | //===--------------------------------------------------------------------===// |
13537 | // Extra semantic analysis beyond the C type system |
13538 | |
13539 | public: |
13540 | SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, |
13541 | unsigned ByteNo) const; |
13542 | |
13543 | enum FormatArgumentPassingKind { |
13544 | FAPK_Fixed, // values to format are fixed (no C-style variadic arguments) |
13545 | FAPK_Variadic, // values to format are passed as variadic arguments |
13546 | FAPK_VAList, // values to format are passed in a va_list |
13547 | }; |
13548 | |
13549 | // Used to grab the relevant information from a FormatAttr and a |
13550 | // FunctionDeclaration. |
13551 | struct FormatStringInfo { |
13552 | unsigned FormatIdx; |
13553 | unsigned FirstDataArg; |
13554 | FormatArgumentPassingKind ArgPassingKind; |
13555 | }; |
13556 | |
13557 | static bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember, |
13558 | bool IsVariadic, FormatStringInfo *FSI); |
13559 | |
13560 | private: |
13561 | void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, |
13562 | const ArraySubscriptExpr *ASE = nullptr, |
13563 | bool AllowOnePastEnd = true, bool IndexNegated = false); |
13564 | void CheckArrayAccess(const Expr *E); |
13565 | |
13566 | bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, |
13567 | const FunctionProtoType *Proto); |
13568 | bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc, |
13569 | ArrayRef<const Expr *> Args); |
13570 | bool CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall, |
13571 | const FunctionProtoType *Proto); |
13572 | bool CheckOtherCall(CallExpr *TheCall, const FunctionProtoType *Proto); |
13573 | void CheckConstructorCall(FunctionDecl *FDecl, QualType ThisType, |
13574 | ArrayRef<const Expr *> Args, |
13575 | const FunctionProtoType *Proto, SourceLocation Loc); |
13576 | |
13577 | void checkAIXMemberAlignment(SourceLocation Loc, const Expr *Arg); |
13578 | |
13579 | void CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl, |
13580 | StringRef ParamName, QualType ArgTy, QualType ParamTy); |
13581 | |
13582 | void checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, |
13583 | const Expr *ThisArg, ArrayRef<const Expr *> Args, |
13584 | bool IsMemberFunction, SourceLocation Loc, SourceRange Range, |
13585 | VariadicCallType CallType); |
13586 | |
13587 | bool CheckObjCString(Expr *Arg); |
13588 | ExprResult CheckOSLogFormatStringArg(Expr *Arg); |
13589 | |
13590 | ExprResult CheckBuiltinFunctionCall(FunctionDecl *FDecl, |
13591 | unsigned BuiltinID, CallExpr *TheCall); |
13592 | |
13593 | bool CheckTSBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13594 | CallExpr *TheCall); |
13595 | |
13596 | void checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD, CallExpr *TheCall); |
13597 | |
13598 | bool CheckARMBuiltinExclusiveCall(unsigned BuiltinID, CallExpr *TheCall, |
13599 | unsigned MaxWidth); |
13600 | bool CheckNeonBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13601 | CallExpr *TheCall); |
13602 | bool CheckMVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
13603 | bool CheckSVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
13604 | bool CheckCDEBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13605 | CallExpr *TheCall); |
13606 | bool CheckARMCoprocessorImmediate(const TargetInfo &TI, const Expr *CoprocArg, |
13607 | bool WantCDE); |
13608 | bool CheckARMBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13609 | CallExpr *TheCall); |
13610 | |
13611 | bool CheckAArch64BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13612 | CallExpr *TheCall); |
13613 | bool CheckBPFBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
13614 | bool CheckHexagonBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
13615 | bool CheckHexagonBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall); |
13616 | bool CheckMipsBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13617 | CallExpr *TheCall); |
13618 | bool CheckMipsBuiltinCpu(const TargetInfo &TI, unsigned BuiltinID, |
13619 | CallExpr *TheCall); |
13620 | bool CheckMipsBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall); |
13621 | bool CheckSystemZBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
13622 | bool CheckX86BuiltinRoundingOrSAE(unsigned BuiltinID, CallExpr *TheCall); |
13623 | bool CheckX86BuiltinGatherScatterScale(unsigned BuiltinID, CallExpr *TheCall); |
13624 | bool CheckX86BuiltinTileArguments(unsigned BuiltinID, CallExpr *TheCall); |
13625 | bool CheckX86BuiltinTileArgumentsRange(CallExpr *TheCall, |
13626 | ArrayRef<int> ArgNums); |
13627 | bool CheckX86BuiltinTileDuplicate(CallExpr *TheCall, ArrayRef<int> ArgNums); |
13628 | bool CheckX86BuiltinTileRangeAndDuplicate(CallExpr *TheCall, |
13629 | ArrayRef<int> ArgNums); |
13630 | bool CheckX86BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13631 | CallExpr *TheCall); |
13632 | bool CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13633 | CallExpr *TheCall); |
13634 | bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
13635 | bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum); |
13636 | bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13637 | CallExpr *TheCall); |
13638 | void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D); |
13639 | bool CheckLoongArchBuiltinFunctionCall(const TargetInfo &TI, |
13640 | unsigned BuiltinID, CallExpr *TheCall); |
13641 | bool CheckWebAssemblyBuiltinFunctionCall(const TargetInfo &TI, |
13642 | unsigned BuiltinID, |
13643 | CallExpr *TheCall); |
13644 | bool CheckNVPTXBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
13645 | CallExpr *TheCall); |
13646 | |
13647 | bool SemaBuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall); |
13648 | bool SemaBuiltinVAStartARMMicrosoft(CallExpr *Call); |
13649 | bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); |
13650 | bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); |
13651 | bool SemaBuiltinComplex(CallExpr *TheCall); |
13652 | bool SemaBuiltinVSX(CallExpr *TheCall); |
13653 | bool SemaBuiltinOSLogFormat(CallExpr *TheCall); |
13654 | bool SemaValueIsRunOfOnes(CallExpr *TheCall, unsigned ArgNum); |
13655 | |
13656 | public: |
13657 | // Used by C++ template instantiation. |
13658 | ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); |
13659 | ExprResult SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo, |
13660 | SourceLocation BuiltinLoc, |
13661 | SourceLocation RParenLoc); |
13662 | |
13663 | private: |
13664 | bool SemaBuiltinPrefetch(CallExpr *TheCall); |
13665 | bool SemaBuiltinAllocaWithAlign(CallExpr *TheCall); |
13666 | bool SemaBuiltinArithmeticFence(CallExpr *TheCall); |
13667 | bool SemaBuiltinAssume(CallExpr *TheCall); |
13668 | bool SemaBuiltinAssumeAligned(CallExpr *TheCall); |
13669 | bool SemaBuiltinLongjmp(CallExpr *TheCall); |
13670 | bool SemaBuiltinSetjmp(CallExpr *TheCall); |
13671 | ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); |
13672 | ExprResult SemaBuiltinNontemporalOverloaded(ExprResult TheCallResult); |
13673 | ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult, |
13674 | AtomicExpr::AtomicOp Op); |
13675 | ExprResult SemaBuiltinOperatorNewDeleteOverloaded(ExprResult TheCallResult, |
13676 | bool IsDelete); |
13677 | bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, |
13678 | llvm::APSInt &Result); |
13679 | bool SemaBuiltinConstantArgRange(CallExpr *TheCall, int ArgNum, int Low, |
13680 | int High, bool RangeIsError = true); |
13681 | bool SemaBuiltinConstantArgMultiple(CallExpr *TheCall, int ArgNum, |
13682 | unsigned Multiple); |
13683 | bool SemaBuiltinConstantArgPower2(CallExpr *TheCall, int ArgNum); |
13684 | bool SemaBuiltinConstantArgShiftedByte(CallExpr *TheCall, int ArgNum, |
13685 | unsigned ArgBits); |
13686 | bool SemaBuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall, int ArgNum, |
13687 | unsigned ArgBits); |
13688 | bool SemaBuiltinARMSpecialReg(unsigned BuiltinID, CallExpr *TheCall, |
13689 | int ArgNum, unsigned ExpectedFieldNum, |
13690 | bool AllowName); |
13691 | bool SemaBuiltinARMMemoryTaggingCall(unsigned BuiltinID, CallExpr *TheCall); |
13692 | bool SemaBuiltinPPCMMACall(CallExpr *TheCall, unsigned BuiltinID, |
13693 | const char *TypeDesc); |
13694 | |
13695 | bool CheckPPCMMAType(QualType Type, SourceLocation TypeLoc); |
13696 | |
13697 | bool SemaBuiltinElementwiseMath(CallExpr *TheCall); |
13698 | bool SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall); |
13699 | bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall); |
13700 | bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall); |
13701 | |
13702 | bool SemaBuiltinNonDeterministicValue(CallExpr *TheCall); |
13703 | |
13704 | // Matrix builtin handling. |
13705 | ExprResult SemaBuiltinMatrixTranspose(CallExpr *TheCall, |
13706 | ExprResult CallResult); |
13707 | ExprResult SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall, |
13708 | ExprResult CallResult); |
13709 | ExprResult SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall, |
13710 | ExprResult CallResult); |
13711 | |
13712 | // WebAssembly builtin handling. |
13713 | bool BuiltinWasmRefNullExtern(CallExpr *TheCall); |
13714 | bool BuiltinWasmRefNullFunc(CallExpr *TheCall); |
13715 | bool BuiltinWasmTableGet(CallExpr *TheCall); |
13716 | bool BuiltinWasmTableSet(CallExpr *TheCall); |
13717 | bool BuiltinWasmTableSize(CallExpr *TheCall); |
13718 | bool BuiltinWasmTableGrow(CallExpr *TheCall); |
13719 | bool BuiltinWasmTableFill(CallExpr *TheCall); |
13720 | bool BuiltinWasmTableCopy(CallExpr *TheCall); |
13721 | |
13722 | public: |
13723 | enum FormatStringType { |
13724 | FST_Scanf, |
13725 | FST_Printf, |
13726 | FST_NSString, |
13727 | FST_Strftime, |
13728 | FST_Strfmon, |
13729 | FST_Kprintf, |
13730 | FST_FreeBSDKPrintf, |
13731 | FST_OSTrace, |
13732 | FST_OSLog, |
13733 | FST_Unknown |
13734 | }; |
13735 | static FormatStringType GetFormatStringType(const FormatAttr *Format); |
13736 | |
13737 | bool FormatStringHasSArg(const StringLiteral *FExpr); |
13738 | |
13739 | static bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx); |
13740 | |
13741 | private: |
13742 | bool CheckFormatArguments(const FormatAttr *Format, |
13743 | ArrayRef<const Expr *> Args, bool IsCXXMember, |
13744 | VariadicCallType CallType, SourceLocation Loc, |
13745 | SourceRange Range, |
13746 | llvm::SmallBitVector &CheckedVarArgs); |
13747 | bool CheckFormatArguments(ArrayRef<const Expr *> Args, |
13748 | FormatArgumentPassingKind FAPK, unsigned format_idx, |
13749 | unsigned firstDataArg, FormatStringType Type, |
13750 | VariadicCallType CallType, SourceLocation Loc, |
13751 | SourceRange range, |
13752 | llvm::SmallBitVector &CheckedVarArgs); |
13753 | |
13754 | void CheckAbsoluteValueFunction(const CallExpr *Call, |
13755 | const FunctionDecl *FDecl); |
13756 | |
13757 | void CheckMaxUnsignedZero(const CallExpr *Call, const FunctionDecl *FDecl); |
13758 | |
13759 | void CheckMemaccessArguments(const CallExpr *Call, |
13760 | unsigned BId, |
13761 | IdentifierInfo *FnName); |
13762 | |
13763 | void CheckStrlcpycatArguments(const CallExpr *Call, |
13764 | IdentifierInfo *FnName); |
13765 | |
13766 | void CheckStrncatArguments(const CallExpr *Call, |
13767 | IdentifierInfo *FnName); |
13768 | |
13769 | void CheckFreeArguments(const CallExpr *E); |
13770 | |
13771 | void CheckReturnValExpr(Expr *RetValExp, QualType lhsType, |
13772 | SourceLocation ReturnLoc, |
13773 | bool isObjCMethod = false, |
13774 | const AttrVec *Attrs = nullptr, |
13775 | const FunctionDecl *FD = nullptr); |
13776 | |
13777 | public: |
13778 | void CheckFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS, |
13779 | BinaryOperatorKind Opcode); |
13780 | |
13781 | private: |
13782 | void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); |
13783 | void CheckBoolLikeConversion(Expr *E, SourceLocation CC); |
13784 | void CheckForIntOverflow(const Expr *E); |
13785 | void CheckUnsequencedOperations(const Expr *E); |
13786 | |
13787 | /// Perform semantic checks on a completed expression. This will either |
13788 | /// be a full-expression or a default argument expression. |
13789 | void CheckCompletedExpr(Expr *E, SourceLocation CheckLoc = SourceLocation(), |
13790 | bool IsConstexpr = false); |
13791 | |
13792 | void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, |
13793 | Expr *Init); |
13794 | |
13795 | /// Check if there is a field shadowing. |
13796 | void CheckShadowInheritedFields(const SourceLocation &Loc, |
13797 | DeclarationName FieldName, |
13798 | const CXXRecordDecl *RD, |
13799 | bool DeclIsField = true); |
13800 | |
13801 | /// Check if the given expression contains 'break' or 'continue' |
13802 | /// statement that produces control flow different from GCC. |
13803 | void CheckBreakContinueBinding(Expr *E); |
13804 | |
13805 | /// Check whether receiver is mutable ObjC container which |
13806 | /// attempts to add itself into the container |
13807 | void CheckObjCCircularContainer(ObjCMessageExpr *Message); |
13808 | |
13809 | void CheckTCBEnforcement(const SourceLocation CallExprLoc, |
13810 | const NamedDecl *Callee); |
13811 | |
13812 | void AnalyzeDeleteExprMismatch(const CXXDeleteExpr *DE); |
13813 | void AnalyzeDeleteExprMismatch(FieldDecl *Field, SourceLocation DeleteLoc, |
13814 | bool DeleteWasArrayForm); |
13815 | public: |
13816 | /// Register a magic integral constant to be used as a type tag. |
13817 | void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind, |
13818 | uint64_t MagicValue, QualType Type, |
13819 | bool LayoutCompatible, bool MustBeNull); |
13820 | |
13821 | struct TypeTagData { |
13822 | TypeTagData() {} |
13823 | |
13824 | TypeTagData(QualType Type, bool LayoutCompatible, bool MustBeNull) : |
13825 | Type(Type), LayoutCompatible(LayoutCompatible), |
13826 | MustBeNull(MustBeNull) |
13827 | {} |
13828 | |
13829 | QualType Type; |
13830 | |
13831 | /// If true, \c Type should be compared with other expression's types for |
13832 | /// layout-compatibility. |
13833 | unsigned LayoutCompatible : 1; |
13834 | unsigned MustBeNull : 1; |
13835 | }; |
13836 | |
13837 | /// A pair of ArgumentKind identifier and magic value. This uniquely |
13838 | /// identifies the magic value. |
13839 | typedef std::pair<const IdentifierInfo *, uint64_t> TypeTagMagicValue; |
13840 | |
13841 | private: |
13842 | /// A map from magic value to type information. |
13843 | std::unique_ptr<llvm::DenseMap<TypeTagMagicValue, TypeTagData>> |
13844 | TypeTagForDatatypeMagicValues; |
13845 | |
13846 | /// Peform checks on a call of a function with argument_with_type_tag |
13847 | /// or pointer_with_type_tag attributes. |
13848 | void CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr, |
13849 | const ArrayRef<const Expr *> ExprArgs, |
13850 | SourceLocation CallSiteLoc); |
13851 | |
13852 | /// Check if we are taking the address of a packed field |
13853 | /// as this may be a problem if the pointer value is dereferenced. |
13854 | void CheckAddressOfPackedMember(Expr *rhs); |
13855 | |
13856 | /// The parser's current scope. |
13857 | /// |
13858 | /// The parser maintains this state here. |
13859 | Scope *CurScope; |
13860 | |
13861 | mutable IdentifierInfo *Ident_super; |
13862 | |
13863 | /// Nullability type specifiers. |
13864 | IdentifierInfo *Ident__Nonnull = nullptr; |
13865 | IdentifierInfo *Ident__Nullable = nullptr; |
13866 | IdentifierInfo *Ident__Nullable_result = nullptr; |
13867 | IdentifierInfo *Ident__Null_unspecified = nullptr; |
13868 | |
13869 | IdentifierInfo *Ident_NSError = nullptr; |
13870 | |
13871 | /// The handler for the FileChanged preprocessor events. |
13872 | /// |
13873 | /// Used for diagnostics that implement custom semantic analysis for #include |
13874 | /// directives, like -Wpragma-pack. |
13875 | sema::SemaPPCallbacks *SemaPPCallbackHandler; |
13876 | |
13877 | protected: |
13878 | friend class Parser; |
13879 | friend class InitializationSequence; |
13880 | friend class ASTReader; |
13881 | friend class ASTDeclReader; |
13882 | friend class ASTWriter; |
13883 | |
13884 | public: |
13885 | /// Retrieve the keyword associated |
13886 | IdentifierInfo *getNullabilityKeyword(NullabilityKind nullability); |
13887 | |
13888 | /// The struct behind the CFErrorRef pointer. |
13889 | RecordDecl *CFError = nullptr; |
13890 | bool isCFError(RecordDecl *D); |
13891 | |
13892 | /// Retrieve the identifier "NSError". |
13893 | IdentifierInfo *getNSErrorIdent(); |
13894 | |
13895 | /// Retrieve the parser's current scope. |
13896 | /// |
13897 | /// This routine must only be used when it is certain that semantic analysis |
13898 | /// and the parser are in precisely the same context, which is not the case |
13899 | /// when, e.g., we are performing any kind of template instantiation. |
13900 | /// Therefore, the only safe places to use this scope are in the parser |
13901 | /// itself and in routines directly invoked from the parser and *never* from |
13902 | /// template substitution or instantiation. |
13903 | Scope *getCurScope() const { return CurScope; } |
13904 | |
13905 | void incrementMSManglingNumber() const { |
13906 | return CurScope->incrementMSManglingNumber(); |
13907 | } |
13908 | |
13909 | IdentifierInfo *getSuperIdentifier() const; |
13910 | |
13911 | ObjCContainerDecl *getObjCDeclContext() const; |
13912 | |
13913 | DeclContext *getCurLexicalContext() const { |
13914 | return OriginalLexicalContext ? OriginalLexicalContext : CurContext; |
13915 | } |
13916 | |
13917 | const DeclContext *getCurObjCLexicalContext() const { |
13918 | const DeclContext *DC = getCurLexicalContext(); |
13919 | // A category implicitly has the attribute of the interface. |
13920 | if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(DC)) |
13921 | DC = CatD->getClassInterface(); |
13922 | return DC; |
13923 | } |
13924 | |
13925 | /// Determine the number of levels of enclosing template parameters. This is |
13926 | /// only usable while parsing. Note that this does not include dependent |
13927 | /// contexts in which no template parameters have yet been declared, such as |
13928 | /// in a terse function template or generic lambda before the first 'auto' is |
13929 | /// encountered. |
13930 | unsigned getTemplateDepth(Scope *S) const; |
13931 | |
13932 | /// To be used for checking whether the arguments being passed to |
13933 | /// function exceeds the number of parameters expected for it. |
13934 | static bool TooManyArguments(size_t NumParams, size_t NumArgs, |
13935 | bool PartialOverloading = false) { |
13936 | // We check whether we're just after a comma in code-completion. |
13937 | if (NumArgs > 0 && PartialOverloading) |
13938 | return NumArgs + 1 > NumParams; // If so, we view as an extra argument. |
13939 | return NumArgs > NumParams; |
13940 | } |
13941 | |
13942 | // Emitting members of dllexported classes is delayed until the class |
13943 | // (including field initializers) is fully parsed. |
13944 | SmallVector<CXXRecordDecl*, 4> DelayedDllExportClasses; |
13945 | SmallVector<CXXMethodDecl*, 4> DelayedDllExportMemberFunctions; |
13946 | |
13947 | private: |
13948 | int ParsingClassDepth = 0; |
13949 | |
13950 | class SavePendingParsedClassStateRAII { |
13951 | public: |
13952 | SavePendingParsedClassStateRAII(Sema &S) : S(S) { swapSavedState(); } |
13953 | |
13954 | ~SavePendingParsedClassStateRAII() { |
13955 | assert(S.DelayedOverridingExceptionSpecChecks.empty() && |
13956 | "there shouldn't be any pending delayed exception spec checks" ); |
13957 | assert(S.DelayedEquivalentExceptionSpecChecks.empty() && |
13958 | "there shouldn't be any pending delayed exception spec checks" ); |
13959 | swapSavedState(); |
13960 | } |
13961 | |
13962 | private: |
13963 | Sema &S; |
13964 | decltype(DelayedOverridingExceptionSpecChecks) |
13965 | SavedOverridingExceptionSpecChecks; |
13966 | decltype(DelayedEquivalentExceptionSpecChecks) |
13967 | SavedEquivalentExceptionSpecChecks; |
13968 | |
13969 | void swapSavedState() { |
13970 | SavedOverridingExceptionSpecChecks.swap( |
13971 | S.DelayedOverridingExceptionSpecChecks); |
13972 | SavedEquivalentExceptionSpecChecks.swap( |
13973 | S.DelayedEquivalentExceptionSpecChecks); |
13974 | } |
13975 | }; |
13976 | |
13977 | /// Helper class that collects misaligned member designations and |
13978 | /// their location info for delayed diagnostics. |
13979 | struct MisalignedMember { |
13980 | Expr *E; |
13981 | RecordDecl *RD; |
13982 | ValueDecl *MD; |
13983 | CharUnits Alignment; |
13984 | |
13985 | MisalignedMember() : E(), RD(), MD() {} |
13986 | MisalignedMember(Expr *E, RecordDecl *RD, ValueDecl *MD, |
13987 | CharUnits Alignment) |
13988 | : E(E), RD(RD), MD(MD), Alignment(Alignment) {} |
13989 | explicit MisalignedMember(Expr *E) |
13990 | : MisalignedMember(E, nullptr, nullptr, CharUnits()) {} |
13991 | |
13992 | bool operator==(const MisalignedMember &m) { return this->E == m.E; } |
13993 | }; |
13994 | /// Small set of gathered accesses to potentially misaligned members |
13995 | /// due to the packed attribute. |
13996 | SmallVector<MisalignedMember, 4> MisalignedMembers; |
13997 | |
13998 | /// Adds an expression to the set of gathered misaligned members. |
13999 | void AddPotentialMisalignedMembers(Expr *E, RecordDecl *RD, ValueDecl *MD, |
14000 | CharUnits Alignment); |
14001 | |
14002 | public: |
14003 | /// Diagnoses the current set of gathered accesses. This typically |
14004 | /// happens at full expression level. The set is cleared after emitting the |
14005 | /// diagnostics. |
14006 | void DiagnoseMisalignedMembers(); |
14007 | |
14008 | /// This function checks if the expression is in the sef of potentially |
14009 | /// misaligned members and it is converted to some pointer type T with lower |
14010 | /// or equal alignment requirements. If so it removes it. This is used when |
14011 | /// we do not want to diagnose such misaligned access (e.g. in conversions to |
14012 | /// void*). |
14013 | void DiscardMisalignedMemberAddress(const Type *T, Expr *E); |
14014 | |
14015 | /// This function calls Action when it determines that E designates a |
14016 | /// misaligned member due to the packed attribute. This is used to emit |
14017 | /// local diagnostics like in reference binding. |
14018 | void RefersToMemberWithReducedAlignment( |
14019 | Expr *E, |
14020 | llvm::function_ref<void(Expr *, RecordDecl *, FieldDecl *, CharUnits)> |
14021 | Action); |
14022 | |
14023 | /// Describes the reason a calling convention specification was ignored, used |
14024 | /// for diagnostics. |
14025 | enum class CallingConventionIgnoredReason { |
14026 | ForThisTarget = 0, |
14027 | VariadicFunction, |
14028 | ConstructorDestructor, |
14029 | BuiltinFunction |
14030 | }; |
14031 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
14032 | /// context is "used as device code". |
14033 | /// |
14034 | /// - If CurLexicalContext is a kernel function or it is known that the |
14035 | /// function will be emitted for the device, emits the diagnostics |
14036 | /// immediately. |
14037 | /// - If CurLexicalContext is a function and we are compiling |
14038 | /// for the device, but we don't know that this function will be codegen'ed |
14039 | /// for devive yet, creates a diagnostic which is emitted if and when we |
14040 | /// realize that the function will be codegen'ed. |
14041 | /// |
14042 | /// Example usage: |
14043 | /// |
14044 | /// Diagnose __float128 type usage only from SYCL device code if the current |
14045 | /// target doesn't support it |
14046 | /// if (!S.Context.getTargetInfo().hasFloat128Type() && |
14047 | /// S.getLangOpts().SYCLIsDevice) |
14048 | /// SYCLDiagIfDeviceCode(Loc, diag::err_type_unsupported) << "__float128"; |
14049 | SemaDiagnosticBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, |
14050 | unsigned DiagID); |
14051 | |
14052 | void deepTypeCheckForSYCLDevice(SourceLocation UsedAt, |
14053 | llvm::DenseSet<QualType> Visited, |
14054 | ValueDecl *DeclToCheck); |
14055 | }; |
14056 | |
14057 | DeductionFailureInfo |
14058 | MakeDeductionFailureInfo(ASTContext &Context, Sema::TemplateDeductionResult TDK, |
14059 | sema::TemplateDeductionInfo &Info); |
14060 | |
14061 | /// Contains a late templated function. |
14062 | /// Will be parsed at the end of the translation unit, used by Sema & Parser. |
14063 | struct LateParsedTemplate { |
14064 | CachedTokens Toks; |
14065 | /// The template function declaration to be late parsed. |
14066 | Decl *D; |
14067 | /// Floating-point options in the point of definition. |
14068 | FPOptions FPO; |
14069 | }; |
14070 | |
14071 | template <> |
14072 | void Sema::PragmaStack<Sema::AlignPackInfo>::Act(SourceLocation PragmaLocation, |
14073 | PragmaMsStackAction Action, |
14074 | llvm::StringRef StackSlotLabel, |
14075 | AlignPackInfo Value); |
14076 | |
14077 | std::unique_ptr<sema::RISCVIntrinsicManager> |
14078 | CreateRISCVIntrinsicManager(Sema &S); |
14079 | } // end namespace clang |
14080 | |
14081 | namespace llvm { |
14082 | // Hash a FunctionDeclAndLoc by looking at both its FunctionDecl and its |
14083 | // SourceLocation. |
14084 | template <> struct DenseMapInfo<clang::Sema::FunctionDeclAndLoc> { |
14085 | using FunctionDeclAndLoc = clang::Sema::FunctionDeclAndLoc; |
14086 | using FDBaseInfo = |
14087 | DenseMapInfo<clang::CanonicalDeclPtr<const clang::FunctionDecl>>; |
14088 | |
14089 | static FunctionDeclAndLoc getEmptyKey() { |
14090 | return {FDBaseInfo::getEmptyKey(), clang::SourceLocation()}; |
14091 | } |
14092 | |
14093 | static FunctionDeclAndLoc getTombstoneKey() { |
14094 | return {FDBaseInfo::getTombstoneKey(), clang::SourceLocation()}; |
14095 | } |
14096 | |
14097 | static unsigned getHashValue(const FunctionDeclAndLoc &FDL) { |
14098 | return hash_combine(FDBaseInfo::getHashValue(FDL.FD), |
14099 | FDL.Loc.getHashValue()); |
14100 | } |
14101 | |
14102 | static bool isEqual(const FunctionDeclAndLoc &LHS, |
14103 | const FunctionDeclAndLoc &RHS) { |
14104 | return LHS.FD == RHS.FD && LHS.Loc == RHS.Loc; |
14105 | } |
14106 | }; |
14107 | } // namespace llvm |
14108 | |
14109 | #endif |
14110 | |