1 | //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file defines the Sema class, which performs semantic analysis and |
10 | // builds ASTs. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef LLVM_CLANG_SEMA_SEMA_H |
15 | #define LLVM_CLANG_SEMA_SEMA_H |
16 | |
17 | #include "clang/APINotes/APINotesManager.h" |
18 | #include "clang/AST/ASTConcept.h" |
19 | #include "clang/AST/ASTFwd.h" |
20 | #include "clang/AST/Attr.h" |
21 | #include "clang/AST/Availability.h" |
22 | #include "clang/AST/ComparisonCategories.h" |
23 | #include "clang/AST/DeclTemplate.h" |
24 | #include "clang/AST/DeclarationName.h" |
25 | #include "clang/AST/Expr.h" |
26 | #include "clang/AST/ExprCXX.h" |
27 | #include "clang/AST/ExprConcepts.h" |
28 | #include "clang/AST/ExprObjC.h" |
29 | #include "clang/AST/ExternalASTSource.h" |
30 | #include "clang/AST/LocInfoType.h" |
31 | #include "clang/AST/MangleNumberingContext.h" |
32 | #include "clang/AST/NSAPI.h" |
33 | #include "clang/AST/PrettyPrinter.h" |
34 | #include "clang/AST/StmtCXX.h" |
35 | #include "clang/AST/TypeLoc.h" |
36 | #include "clang/AST/TypeOrdering.h" |
37 | #include "clang/Basic/BitmaskEnum.h" |
38 | #include "clang/Basic/Builtins.h" |
39 | #include "clang/Basic/Cuda.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/PragmaKinds.h" |
45 | #include "clang/Basic/Specifiers.h" |
46 | #include "clang/Basic/TemplateKinds.h" |
47 | #include "clang/Basic/TypeTraits.h" |
48 | #include "clang/Sema/AnalysisBasedWarnings.h" |
49 | #include "clang/Sema/CleanupInfo.h" |
50 | #include "clang/Sema/DeclSpec.h" |
51 | #include "clang/Sema/ExternalSemaSource.h" |
52 | #include "clang/Sema/IdentifierResolver.h" |
53 | #include "clang/Sema/ObjCMethodList.h" |
54 | #include "clang/Sema/Ownership.h" |
55 | #include "clang/Sema/Redeclaration.h" |
56 | #include "clang/Sema/Scope.h" |
57 | #include "clang/Sema/SemaBase.h" |
58 | #include "clang/Sema/SemaConcept.h" |
59 | #include "clang/Sema/SemaDiagnostic.h" |
60 | #include "clang/Sema/TypoCorrection.h" |
61 | #include "clang/Sema/Weak.h" |
62 | #include "llvm/ADT/ArrayRef.h" |
63 | #include "llvm/ADT/STLForwardCompat.h" |
64 | #include "llvm/ADT/SetVector.h" |
65 | #include "llvm/ADT/SmallBitVector.h" |
66 | #include "llvm/ADT/SmallPtrSet.h" |
67 | #include "llvm/ADT/SmallSet.h" |
68 | #include "llvm/ADT/SmallVector.h" |
69 | #include "llvm/ADT/TinyPtrVector.h" |
70 | #include <deque> |
71 | #include <memory> |
72 | #include <optional> |
73 | #include <string> |
74 | #include <tuple> |
75 | #include <vector> |
76 | |
77 | namespace llvm { |
78 | class APSInt; |
79 | template <typename ValueT, typename ValueInfoT> class DenseSet; |
80 | class SmallBitVector; |
81 | struct InlineAsmIdentifierInfo; |
82 | } // namespace llvm |
83 | |
84 | namespace clang { |
85 | class ADLResult; |
86 | class ASTConsumer; |
87 | class ASTContext; |
88 | class ASTMutationListener; |
89 | class ASTReader; |
90 | class ASTWriter; |
91 | class ArrayType; |
92 | class ParsedAttr; |
93 | class BindingDecl; |
94 | class BlockDecl; |
95 | class CapturedDecl; |
96 | class CXXBasePath; |
97 | class CXXBasePaths; |
98 | class CXXBindTemporaryExpr; |
99 | typedef SmallVector<CXXBaseSpecifier *, 4> CXXCastPath; |
100 | class CXXConstructorDecl; |
101 | class CXXConversionDecl; |
102 | class CXXDeleteExpr; |
103 | class CXXDestructorDecl; |
104 | class CXXFieldCollector; |
105 | class CXXMemberCallExpr; |
106 | class CXXMethodDecl; |
107 | class CXXScopeSpec; |
108 | class CXXTemporary; |
109 | class CXXTryStmt; |
110 | class CallExpr; |
111 | class ClassTemplateDecl; |
112 | class ClassTemplatePartialSpecializationDecl; |
113 | class ClassTemplateSpecializationDecl; |
114 | class VarTemplatePartialSpecializationDecl; |
115 | class CodeCompleteConsumer; |
116 | class CodeCompletionAllocator; |
117 | class CodeCompletionTUInfo; |
118 | class CodeCompletionResult; |
119 | class CoroutineBodyStmt; |
120 | class Decl; |
121 | class DeclAccessPair; |
122 | class DeclContext; |
123 | class DeclRefExpr; |
124 | class DeclaratorDecl; |
125 | class DeducedTemplateArgument; |
126 | class DependentDiagnostic; |
127 | class DesignatedInitExpr; |
128 | class Designation; |
129 | class EnableIfAttr; |
130 | class EnumConstantDecl; |
131 | class Expr; |
132 | class ExtVectorType; |
133 | class FormatAttr; |
134 | class FriendDecl; |
135 | class FunctionDecl; |
136 | class FunctionProtoType; |
137 | class FunctionTemplateDecl; |
138 | class ImplicitConversionSequence; |
139 | typedef MutableArrayRef<ImplicitConversionSequence> ConversionSequenceList; |
140 | class InitListExpr; |
141 | class InitializationKind; |
142 | class InitializationSequence; |
143 | class InitializedEntity; |
144 | class IntegerLiteral; |
145 | class LabelStmt; |
146 | class LambdaExpr; |
147 | class LangOptions; |
148 | class LocalInstantiationScope; |
149 | class LookupResult; |
150 | class MacroInfo; |
151 | typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> ModuleIdPath; |
152 | class ModuleLoader; |
153 | class MultiLevelTemplateArgumentList; |
154 | class NamedDecl; |
155 | class ObjCCategoryDecl; |
156 | class ObjCCategoryImplDecl; |
157 | class ObjCCompatibleAliasDecl; |
158 | class ObjCContainerDecl; |
159 | class ObjCImplDecl; |
160 | class ObjCImplementationDecl; |
161 | class ObjCInterfaceDecl; |
162 | class ObjCIvarDecl; |
163 | template <class T> class ObjCList; |
164 | class ObjCMessageExpr; |
165 | class ObjCMethodDecl; |
166 | class ObjCPropertyDecl; |
167 | class ObjCProtocolDecl; |
168 | struct OverloadCandidate; |
169 | enum class OverloadCandidateParamOrder : char; |
170 | enum OverloadCandidateRewriteKind : unsigned; |
171 | class OverloadCandidateSet; |
172 | class OverloadExpr; |
173 | class ParenListExpr; |
174 | class ParmVarDecl; |
175 | class Preprocessor; |
176 | class PseudoDestructorTypeStorage; |
177 | class PseudoObjectExpr; |
178 | class QualType; |
179 | class SemaCUDA; |
180 | class SemaHLSL; |
181 | class SemaOpenACC; |
182 | class SemaOpenMP; |
183 | class SemaSYCL; |
184 | class StandardConversionSequence; |
185 | class Stmt; |
186 | class StringLiteral; |
187 | class SwitchStmt; |
188 | class TemplateArgument; |
189 | class TemplateArgumentList; |
190 | class TemplateArgumentLoc; |
191 | class TemplateDecl; |
192 | class TemplateInstantiationCallback; |
193 | class TemplateParameterList; |
194 | class TemplatePartialOrderingContext; |
195 | class TemplateTemplateParmDecl; |
196 | class Token; |
197 | class TypeAliasDecl; |
198 | class TypedefDecl; |
199 | class TypedefNameDecl; |
200 | class TypeLoc; |
201 | class TypoCorrectionConsumer; |
202 | class UnqualifiedId; |
203 | class UnresolvedLookupExpr; |
204 | class UnresolvedMemberExpr; |
205 | class UnresolvedSetImpl; |
206 | class UnresolvedSetIterator; |
207 | class UsingDecl; |
208 | class UsingShadowDecl; |
209 | class ValueDecl; |
210 | class VarDecl; |
211 | class VarTemplateSpecializationDecl; |
212 | class VisibilityAttr; |
213 | class VisibleDeclConsumer; |
214 | class IndirectFieldDecl; |
215 | struct DeductionFailureInfo; |
216 | class TemplateSpecCandidateSet; |
217 | |
218 | namespace sema { |
219 | class AccessedEntity; |
220 | class BlockScopeInfo; |
221 | class Capture; |
222 | class CapturedRegionScopeInfo; |
223 | class CapturingScopeInfo; |
224 | class CompoundScopeInfo; |
225 | class DelayedDiagnostic; |
226 | class DelayedDiagnosticPool; |
227 | class FunctionScopeInfo; |
228 | class LambdaScopeInfo; |
229 | class PossiblyUnreachableDiag; |
230 | class RISCVIntrinsicManager; |
231 | class SemaPPCallbacks; |
232 | class TemplateDeductionInfo; |
233 | } // namespace sema |
234 | |
235 | namespace threadSafety { |
236 | class BeforeSet; |
237 | void threadSafetyCleanup(BeforeSet *Cache); |
238 | } // namespace threadSafety |
239 | |
240 | // FIXME: No way to easily map from TemplateTypeParmTypes to |
241 | // TemplateTypeParmDecls, so we have this horrible PointerUnion. |
242 | typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType *, NamedDecl *>, |
243 | SourceLocation> |
244 | UnexpandedParameterPack; |
245 | |
246 | /// Describes whether we've seen any nullability information for the given |
247 | /// file. |
248 | struct FileNullability { |
249 | /// The first pointer declarator (of any pointer kind) in the file that does |
250 | /// not have a corresponding nullability annotation. |
251 | SourceLocation PointerLoc; |
252 | |
253 | /// The end location for the first pointer declarator in the file. Used for |
254 | /// placing fix-its. |
255 | SourceLocation PointerEndLoc; |
256 | |
257 | /// Which kind of pointer declarator we saw. |
258 | uint8_t PointerKind; |
259 | |
260 | /// Whether we saw any type nullability annotations in the given file. |
261 | bool SawTypeNullability = false; |
262 | }; |
263 | |
264 | /// A mapping from file IDs to a record of whether we've seen nullability |
265 | /// information in that file. |
266 | class FileNullabilityMap { |
267 | /// A mapping from file IDs to the nullability information for each file ID. |
268 | llvm::DenseMap<FileID, FileNullability> Map; |
269 | |
270 | /// A single-element cache based on the file ID. |
271 | struct { |
272 | FileID File; |
273 | FileNullability Nullability; |
274 | } Cache; |
275 | |
276 | public: |
277 | FileNullability &operator[](FileID file) { |
278 | // Check the single-element cache. |
279 | if (file == Cache.File) |
280 | return Cache.Nullability; |
281 | |
282 | // It's not in the single-element cache; flush the cache if we have one. |
283 | if (!Cache.File.isInvalid()) { |
284 | Map[Cache.File] = Cache.Nullability; |
285 | } |
286 | |
287 | // Pull this entry into the cache. |
288 | Cache.File = file; |
289 | Cache.Nullability = Map[file]; |
290 | return Cache.Nullability; |
291 | } |
292 | }; |
293 | |
294 | /// Tracks expected type during expression parsing, for use in code completion. |
295 | /// The type is tied to a particular token, all functions that update or consume |
296 | /// the type take a start location of the token they are looking at as a |
297 | /// parameter. This avoids updating the type on hot paths in the parser. |
298 | class PreferredTypeBuilder { |
299 | public: |
300 | PreferredTypeBuilder(bool Enabled) : Enabled(Enabled) {} |
301 | |
302 | void enterCondition(Sema &S, SourceLocation Tok); |
303 | void enterReturn(Sema &S, SourceLocation Tok); |
304 | void enterVariableInit(SourceLocation Tok, Decl *D); |
305 | /// Handles e.g. BaseType{ .D = Tok... |
306 | void enterDesignatedInitializer(SourceLocation Tok, QualType BaseType, |
307 | const Designation &D); |
308 | /// Computing a type for the function argument may require running |
309 | /// overloading, so we postpone its computation until it is actually needed. |
310 | /// |
311 | /// Clients should be very careful when using this function, as it stores a |
312 | /// function_ref, clients should make sure all calls to get() with the same |
313 | /// location happen while function_ref is alive. |
314 | /// |
315 | /// The callback should also emit signature help as a side-effect, but only |
316 | /// if the completion point has been reached. |
317 | void enterFunctionArgument(SourceLocation Tok, |
318 | llvm::function_ref<QualType()> ComputeType); |
319 | |
320 | void enterParenExpr(SourceLocation Tok, SourceLocation LParLoc); |
321 | void enterUnary(Sema &S, SourceLocation Tok, tok::TokenKind OpKind, |
322 | SourceLocation OpLoc); |
323 | void enterBinary(Sema &S, SourceLocation Tok, Expr *LHS, tok::TokenKind Op); |
324 | void enterMemAccess(Sema &S, SourceLocation Tok, Expr *Base); |
325 | void enterSubscript(Sema &S, SourceLocation Tok, Expr *LHS); |
326 | /// Handles all type casts, including C-style cast, C++ casts, etc. |
327 | void enterTypeCast(SourceLocation Tok, QualType CastType); |
328 | |
329 | /// Get the expected type associated with this location, if any. |
330 | /// |
331 | /// If the location is a function argument, determining the expected type |
332 | /// involves considering all function overloads and the arguments so far. |
333 | /// In this case, signature help for these function overloads will be reported |
334 | /// as a side-effect (only if the completion point has been reached). |
335 | QualType get(SourceLocation Tok) const { |
336 | if (!Enabled || Tok != ExpectedLoc) |
337 | return QualType(); |
338 | if (!Type.isNull()) |
339 | return Type; |
340 | if (ComputeType) |
341 | return ComputeType(); |
342 | return QualType(); |
343 | } |
344 | |
345 | private: |
346 | bool Enabled; |
347 | /// Start position of a token for which we store expected type. |
348 | SourceLocation ExpectedLoc; |
349 | /// Expected type for a token starting at ExpectedLoc. |
350 | QualType Type; |
351 | /// A function to compute expected type at ExpectedLoc. It is only considered |
352 | /// if Type is null. |
353 | llvm::function_ref<QualType()> ComputeType; |
354 | }; |
355 | |
356 | struct SkipBodyInfo { |
357 | SkipBodyInfo() = default; |
358 | bool ShouldSkip = false; |
359 | bool CheckSameAsPrevious = false; |
360 | NamedDecl *Previous = nullptr; |
361 | NamedDecl *New = nullptr; |
362 | }; |
363 | |
364 | /// Describes the result of template argument deduction. |
365 | /// |
366 | /// The TemplateDeductionResult enumeration describes the result of |
367 | /// template argument deduction, as returned from |
368 | /// DeduceTemplateArguments(). The separate TemplateDeductionInfo |
369 | /// structure provides additional information about the results of |
370 | /// template argument deduction, e.g., the deduced template argument |
371 | /// list (if successful) or the specific template parameters or |
372 | /// deduced arguments that were involved in the failure. |
373 | enum class TemplateDeductionResult { |
374 | /// Template argument deduction was successful. |
375 | Success = 0, |
376 | /// The declaration was invalid; do nothing. |
377 | Invalid, |
378 | /// Template argument deduction exceeded the maximum template |
379 | /// instantiation depth (which has already been diagnosed). |
380 | InstantiationDepth, |
381 | /// Template argument deduction did not deduce a value |
382 | /// for every template parameter. |
383 | Incomplete, |
384 | /// Template argument deduction did not deduce a value for every |
385 | /// expansion of an expanded template parameter pack. |
386 | IncompletePack, |
387 | /// Template argument deduction produced inconsistent |
388 | /// deduced values for the given template parameter. |
389 | Inconsistent, |
390 | /// Template argument deduction failed due to inconsistent |
391 | /// cv-qualifiers on a template parameter type that would |
392 | /// otherwise be deduced, e.g., we tried to deduce T in "const T" |
393 | /// but were given a non-const "X". |
394 | Underqualified, |
395 | /// Substitution of the deduced template argument values |
396 | /// resulted in an error. |
397 | SubstitutionFailure, |
398 | /// After substituting deduced template arguments, a dependent |
399 | /// parameter type did not match the corresponding argument. |
400 | DeducedMismatch, |
401 | /// After substituting deduced template arguments, an element of |
402 | /// a dependent parameter type did not match the corresponding element |
403 | /// of the corresponding argument (when deducing from an initializer list). |
404 | DeducedMismatchNested, |
405 | /// A non-depnedent component of the parameter did not match the |
406 | /// corresponding component of the argument. |
407 | NonDeducedMismatch, |
408 | /// When performing template argument deduction for a function |
409 | /// template, there were too many call arguments. |
410 | TooManyArguments, |
411 | /// When performing template argument deduction for a function |
412 | /// template, there were too few call arguments. |
413 | TooFewArguments, |
414 | /// The explicitly-specified template arguments were not valid |
415 | /// template arguments for the given template. |
416 | InvalidExplicitArguments, |
417 | /// Checking non-dependent argument conversions failed. |
418 | NonDependentConversionFailure, |
419 | /// The deduced arguments did not satisfy the constraints associated |
420 | /// with the template. |
421 | ConstraintsNotSatisfied, |
422 | /// Deduction failed; that's all we know. |
423 | MiscellaneousDeductionFailure, |
424 | /// CUDA Target attributes do not match. |
425 | CUDATargetMismatch, |
426 | /// Some error which was already diagnosed. |
427 | AlreadyDiagnosed |
428 | }; |
429 | |
430 | /// Kinds of C++ special members. |
431 | enum class CXXSpecialMemberKind { |
432 | DefaultConstructor, |
433 | CopyConstructor, |
434 | MoveConstructor, |
435 | CopyAssignment, |
436 | MoveAssignment, |
437 | Destructor, |
438 | Invalid |
439 | }; |
440 | |
441 | /// The kind of conversion being performed. |
442 | enum class CheckedConversionKind { |
443 | /// An implicit conversion. |
444 | Implicit, |
445 | /// A C-style cast. |
446 | CStyleCast, |
447 | /// A functional-style cast. |
448 | FunctionalCast, |
449 | /// A cast other than a C-style cast. |
450 | OtherCast, |
451 | /// A conversion for an operand of a builtin overloaded operator. |
452 | ForBuiltinOverloadedOp |
453 | }; |
454 | |
455 | /// Sema - This implements semantic analysis and AST building for C. |
456 | /// \nosubgrouping |
457 | class Sema final : public SemaBase { |
458 | // Table of Contents |
459 | // ----------------- |
460 | // 1. Semantic Analysis (Sema.cpp) |
461 | // 2. C++ Access Control (SemaAccess.cpp) |
462 | // 3. Attributes (SemaAttr.cpp) |
463 | // 4. Availability Attribute Handling (SemaAvailability.cpp) |
464 | // 5. Casts (SemaCast.cpp) |
465 | // 6. Extra Semantic Checking (SemaChecking.cpp) |
466 | // 7. C++ Coroutines (SemaCoroutine.cpp) |
467 | // 8. C++ Scope Specifiers (SemaCXXScopeSpec.cpp) |
468 | // 9. Declarations (SemaDecl.cpp) |
469 | // 10. Declaration Attribute Handling (SemaDeclAttr.cpp) |
470 | // 11. C++ Declarations (SemaDeclCXX.cpp) |
471 | // 12. C++ Exception Specifications (SemaExceptionSpec.cpp) |
472 | // 13. Expressions (SemaExpr.cpp) |
473 | // 14. C++ Expressions (SemaExprCXX.cpp) |
474 | // 15. Member Access Expressions (SemaExprMember.cpp) |
475 | // 16. Initializers (SemaInit.cpp) |
476 | // 17. C++ Lambda Expressions (SemaLambda.cpp) |
477 | // 18. Name Lookup (SemaLookup.cpp) |
478 | // 19. Modules (SemaModule.cpp) |
479 | // 20. C++ Overloading (SemaOverload.cpp) |
480 | // 21. Pseudo-Object (SemaPseudoObject.cpp) |
481 | // 22. Statements (SemaStmt.cpp) |
482 | // 23. `inline asm` Statement (SemaStmtAsm.cpp) |
483 | // 24. Statement Attribute Handling (SemaStmtAttr.cpp) |
484 | // 25. C++ Templates (SemaTemplate.cpp) |
485 | // 26. C++ Template Argument Deduction (SemaTemplateDeduction.cpp) |
486 | // 27. C++ Template Instantiation (SemaTemplateInstantiate.cpp) |
487 | // 28. C++ Template Declaration Instantiation |
488 | // (SemaTemplateInstantiateDecl.cpp) |
489 | // 29. C++ Variadic Templates (SemaTemplateVariadic.cpp) |
490 | // 30. Constraints and Concepts (SemaConcept.cpp) |
491 | // 31. Types (SemaType.cpp) |
492 | // 32. ObjC Declarations (SemaDeclObjC.cpp) |
493 | // 33. ObjC Expressions (SemaExprObjC.cpp) |
494 | // 34. ObjC @property and @synthesize (SemaObjCProperty.cpp) |
495 | // 35. Code Completion (SemaCodeComplete.cpp) |
496 | // 36. FixIt Helpers (SemaFixItUtils.cpp) |
497 | // 37. Name Lookup for RISC-V Vector Intrinsic (SemaRISCVVectorLookup.cpp) |
498 | |
499 | /// \name Semantic Analysis |
500 | /// Implementations are in Sema.cpp |
501 | ///@{ |
502 | |
503 | public: |
504 | Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, |
505 | TranslationUnitKind TUKind = TU_Complete, |
506 | CodeCompleteConsumer *CompletionConsumer = nullptr); |
507 | ~Sema(); |
508 | |
509 | /// Perform initialization that occurs after the parser has been |
510 | /// initialized but before it parses anything. |
511 | void Initialize(); |
512 | |
513 | /// This virtual key function only exists to limit the emission of debug info |
514 | /// describing the Sema class. GCC and Clang only emit debug info for a class |
515 | /// with a vtable when the vtable is emitted. Sema is final and not |
516 | /// polymorphic, but the debug info size savings are so significant that it is |
517 | /// worth adding a vtable just to take advantage of this optimization. |
518 | virtual void anchor(); |
519 | |
520 | const LangOptions &getLangOpts() const { return LangOpts; } |
521 | OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; } |
522 | FPOptions &getCurFPFeatures() { return CurFPFeatures; } |
523 | |
524 | DiagnosticsEngine &getDiagnostics() const { return Diags; } |
525 | SourceManager &getSourceManager() const { return SourceMgr; } |
526 | Preprocessor &getPreprocessor() const { return PP; } |
527 | ASTContext &getASTContext() const { return Context; } |
528 | ASTConsumer &getASTConsumer() const { return Consumer; } |
529 | ASTMutationListener *getASTMutationListener() const; |
530 | ExternalSemaSource *getExternalSource() const { return ExternalSource.get(); } |
531 | |
532 | DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(SourceLocation Loc, |
533 | StringRef Platform); |
534 | DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(); |
535 | |
536 | /// Registers an external source. If an external source already exists, |
537 | /// creates a multiplex external source and appends to it. |
538 | /// |
539 | ///\param[in] E - A non-null external sema source. |
540 | /// |
541 | void addExternalSource(ExternalSemaSource *E); |
542 | |
543 | void PrintStats() const; |
544 | |
545 | /// Warn that the stack is nearly exhausted. |
546 | void warnStackExhausted(SourceLocation Loc); |
547 | |
548 | /// Run some code with "sufficient" stack space. (Currently, at least 256K is |
549 | /// guaranteed). Produces a warning if we're low on stack space and allocates |
550 | /// more in that case. Use this in code that may recurse deeply (for example, |
551 | /// in template instantiation) to avoid stack overflow. |
552 | void runWithSufficientStackSpace(SourceLocation Loc, |
553 | llvm::function_ref<void()> Fn); |
554 | |
555 | /// Returns default addr space for method qualifiers. |
556 | LangAS getDefaultCXXMethodAddrSpace() const; |
557 | |
558 | /// Load weak undeclared identifiers from the external source. |
559 | void LoadExternalWeakUndeclaredIdentifiers(); |
560 | |
561 | /// Determine if VD, which must be a variable or function, is an external |
562 | /// symbol that nonetheless can't be referenced from outside this translation |
563 | /// unit because its type has no linkage and it's not extern "C". |
564 | bool isExternalWithNoLinkageType(const ValueDecl *VD) const; |
565 | |
566 | /// Obtain a sorted list of functions that are undefined but ODR-used. |
567 | void getUndefinedButUsed( |
568 | SmallVectorImpl<std::pair<NamedDecl *, SourceLocation>> &Undefined); |
569 | |
570 | typedef std::pair<SourceLocation, bool> DeleteExprLoc; |
571 | typedef llvm::SmallVector<DeleteExprLoc, 4> DeleteLocs; |
572 | /// Retrieves list of suspicious delete-expressions that will be checked at |
573 | /// the end of translation unit. |
574 | const llvm::MapVector<FieldDecl *, DeleteLocs> & |
575 | getMismatchingDeleteExpressions() const; |
576 | |
577 | /// Cause the active diagnostic on the DiagosticsEngine to be |
578 | /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and |
579 | /// should not be used elsewhere. |
580 | void EmitCurrentDiagnostic(unsigned DiagID); |
581 | |
582 | void addImplicitTypedef(StringRef Name, QualType T); |
583 | |
584 | /// Whether uncompilable error has occurred. This includes error happens |
585 | /// in deferred diagnostics. |
586 | bool hasUncompilableErrorOccurred() const; |
587 | |
588 | bool findMacroSpelling(SourceLocation &loc, StringRef name); |
589 | |
590 | /// Calls \c Lexer::getLocForEndOfToken() |
591 | SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0); |
592 | |
593 | /// Retrieve the module loader associated with the preprocessor. |
594 | ModuleLoader &getModuleLoader() const; |
595 | |
596 | /// Invent a new identifier for parameters of abbreviated templates. |
597 | IdentifierInfo * |
598 | InventAbbreviatedTemplateParameterTypeName(const IdentifierInfo *ParamName, |
599 | unsigned Index); |
600 | |
601 | void emitAndClearUnusedLocalTypedefWarnings(); |
602 | |
603 | // Emit all deferred diagnostics. |
604 | void emitDeferredDiags(); |
605 | |
606 | enum TUFragmentKind { |
607 | /// The global module fragment, between 'module;' and a module-declaration. |
608 | Global, |
609 | /// A normal translation unit fragment. For a non-module unit, this is the |
610 | /// entire translation unit. Otherwise, it runs from the module-declaration |
611 | /// to the private-module-fragment (if any) or the end of the TU (if not). |
612 | Normal, |
613 | /// The private module fragment, between 'module :private;' and the end of |
614 | /// the translation unit. |
615 | Private |
616 | }; |
617 | |
618 | void ActOnStartOfTranslationUnit(); |
619 | void ActOnEndOfTranslationUnit(); |
620 | void ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind); |
621 | |
622 | Scope *getScopeForContext(DeclContext *Ctx); |
623 | |
624 | void PushFunctionScope(); |
625 | void PushBlockScope(Scope *BlockScope, BlockDecl *Block); |
626 | sema::LambdaScopeInfo *PushLambdaScope(); |
627 | |
628 | /// This is used to inform Sema what the current TemplateParameterDepth |
629 | /// is during Parsing. Currently it is used to pass on the depth |
630 | /// when parsing generic lambda 'auto' parameters. |
631 | void RecordParsingTemplateParameterDepth(unsigned Depth); |
632 | |
633 | void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD, |
634 | RecordDecl *RD, CapturedRegionKind K, |
635 | unsigned OpenMPCaptureLevel = 0); |
636 | |
637 | /// Custom deleter to allow FunctionScopeInfos to be kept alive for a short |
638 | /// time after they've been popped. |
639 | class PoppedFunctionScopeDeleter { |
640 | Sema *Self; |
641 | |
642 | public: |
643 | explicit PoppedFunctionScopeDeleter(Sema *Self) : Self(Self) {} |
644 | void operator()(sema::FunctionScopeInfo *Scope) const; |
645 | }; |
646 | |
647 | using PoppedFunctionScopePtr = |
648 | std::unique_ptr<sema::FunctionScopeInfo, PoppedFunctionScopeDeleter>; |
649 | |
650 | PoppedFunctionScopePtr |
651 | PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr, |
652 | const Decl *D = nullptr, |
653 | QualType BlockType = QualType()); |
654 | |
655 | sema::FunctionScopeInfo *getEnclosingFunction() const; |
656 | |
657 | void setFunctionHasBranchIntoScope(); |
658 | void setFunctionHasBranchProtectedScope(); |
659 | void setFunctionHasIndirectGoto(); |
660 | void setFunctionHasMustTail(); |
661 | |
662 | void PushCompoundScope(bool IsStmtExpr); |
663 | void PopCompoundScope(); |
664 | |
665 | bool hasAnyUnrecoverableErrorsInThisFunction() const; |
666 | |
667 | /// Retrieve the current block, if any. |
668 | sema::BlockScopeInfo *getCurBlock(); |
669 | |
670 | /// Get the innermost lambda enclosing the current location, if any. This |
671 | /// looks through intervening non-lambda scopes such as local functions and |
672 | /// blocks. |
673 | sema::LambdaScopeInfo *getEnclosingLambda() const; |
674 | |
675 | /// Retrieve the current lambda scope info, if any. |
676 | /// \param IgnoreNonLambdaCapturingScope true if should find the top-most |
677 | /// lambda scope info ignoring all inner capturing scopes that are not |
678 | /// lambda scopes. |
679 | sema::LambdaScopeInfo * |
680 | getCurLambda(bool IgnoreNonLambdaCapturingScope = false); |
681 | |
682 | /// Retrieve the current generic lambda info, if any. |
683 | sema::LambdaScopeInfo *getCurGenericLambda(); |
684 | |
685 | /// Retrieve the current captured region, if any. |
686 | sema::CapturedRegionScopeInfo *getCurCapturedRegion(); |
687 | |
688 | void (SourceRange ); |
689 | |
690 | /// Retrieve the parser's current scope. |
691 | /// |
692 | /// This routine must only be used when it is certain that semantic analysis |
693 | /// and the parser are in precisely the same context, which is not the case |
694 | /// when, e.g., we are performing any kind of template instantiation. |
695 | /// Therefore, the only safe places to use this scope are in the parser |
696 | /// itself and in routines directly invoked from the parser and *never* from |
697 | /// template substitution or instantiation. |
698 | Scope *getCurScope() const { return CurScope; } |
699 | |
700 | IdentifierInfo *getSuperIdentifier() const; |
701 | |
702 | DeclContext *getCurLexicalContext() const { |
703 | return OriginalLexicalContext ? OriginalLexicalContext : CurContext; |
704 | } |
705 | |
706 | SemaDiagnosticBuilder targetDiag(SourceLocation Loc, unsigned DiagID, |
707 | const FunctionDecl *FD = nullptr); |
708 | SemaDiagnosticBuilder targetDiag(SourceLocation Loc, |
709 | const PartialDiagnostic &PD, |
710 | const FunctionDecl *FD = nullptr) { |
711 | return targetDiag(Loc, DiagID: PD.getDiagID(), FD) << PD; |
712 | } |
713 | |
714 | /// Check if the type is allowed to be used for the current target. |
715 | void checkTypeSupport(QualType Ty, SourceLocation Loc, |
716 | ValueDecl *D = nullptr); |
717 | |
718 | // /// The kind of conversion being performed. |
719 | // enum CheckedConversionKind { |
720 | // /// An implicit conversion. |
721 | // CCK_ImplicitConversion, |
722 | // /// A C-style cast. |
723 | // CCK_CStyleCast, |
724 | // /// A functional-style cast. |
725 | // CCK_FunctionalCast, |
726 | // /// A cast other than a C-style cast. |
727 | // CCK_OtherCast, |
728 | // /// A conversion for an operand of a builtin overloaded operator. |
729 | // CCK_ForBuiltinOverloadedOp |
730 | // }; |
731 | |
732 | /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit |
733 | /// cast. If there is already an implicit cast, merge into the existing one. |
734 | /// If isLvalue, the result of the cast is an lvalue. |
735 | ExprResult ImpCastExprToType( |
736 | Expr *E, QualType Type, CastKind CK, ExprValueKind VK = VK_PRValue, |
737 | const CXXCastPath *BasePath = nullptr, |
738 | CheckedConversionKind CCK = CheckedConversionKind::Implicit); |
739 | |
740 | /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding |
741 | /// to the conversion from scalar type ScalarTy to the Boolean type. |
742 | static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); |
743 | |
744 | /// If \p AllowLambda is true, treat lambda as function. |
745 | DeclContext *getFunctionLevelDeclContext(bool AllowLambda = false) const; |
746 | |
747 | /// Returns a pointer to the innermost enclosing function, or nullptr if the |
748 | /// current context is not inside a function. If \p AllowLambda is true, |
749 | /// this can return the call operator of an enclosing lambda, otherwise |
750 | /// lambdas are skipped when looking for an enclosing function. |
751 | FunctionDecl *getCurFunctionDecl(bool AllowLambda = false) const; |
752 | |
753 | /// getCurMethodDecl - If inside of a method body, this returns a pointer to |
754 | /// the method decl for the method being parsed. If we're currently |
755 | /// in a 'block', this returns the containing context. |
756 | ObjCMethodDecl *getCurMethodDecl(); |
757 | |
758 | /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method |
759 | /// or C function we're in, otherwise return null. If we're currently |
760 | /// in a 'block', this returns the containing context. |
761 | NamedDecl *getCurFunctionOrMethodDecl() const; |
762 | |
763 | /// Warn if we're implicitly casting from a _Nullable pointer type to a |
764 | /// _Nonnull one. |
765 | void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType, |
766 | SourceLocation Loc); |
767 | |
768 | /// Warn when implicitly casting 0 to nullptr. |
769 | void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E); |
770 | |
771 | bool (SourceLocation loc, |
772 | UnavailableAttr::ImplicitReason reason); |
773 | |
774 | /// Retrieve a suitable printing policy for diagnostics. |
775 | PrintingPolicy getPrintingPolicy() const { |
776 | return getPrintingPolicy(Ctx: Context, PP); |
777 | } |
778 | |
779 | /// Retrieve a suitable printing policy for diagnostics. |
780 | static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx, |
781 | const Preprocessor &PP); |
782 | |
783 | /// Scope actions. |
784 | void ActOnTranslationUnitScope(Scope *S); |
785 | |
786 | /// Determine whether \param D is function like (function or function |
787 | /// template) for parsing. |
788 | bool isDeclaratorFunctionLike(Declarator &D); |
789 | |
790 | /// The maximum alignment, same as in llvm::Value. We duplicate them here |
791 | /// because that allows us not to duplicate the constants in clang code, |
792 | /// which we must to since we can't directly use the llvm constants. |
793 | /// The value is verified against llvm here: lib/CodeGen/CGDecl.cpp |
794 | /// |
795 | /// This is the greatest alignment value supported by load, store, and alloca |
796 | /// instructions, and global values. |
797 | static const unsigned MaxAlignmentExponent = 32; |
798 | static const uint64_t MaximumAlignment = 1ull << MaxAlignmentExponent; |
799 | |
800 | /// Flag indicating whether or not to collect detailed statistics. |
801 | bool CollectStats; |
802 | |
803 | std::unique_ptr<sema::FunctionScopeInfo> CachedFunctionScope; |
804 | |
805 | /// Stack containing information about each of the nested |
806 | /// function, block, and method scopes that are currently active. |
807 | SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes; |
808 | |
809 | /// The index of the first FunctionScope that corresponds to the current |
810 | /// context. |
811 | unsigned FunctionScopesStart = 0; |
812 | |
813 | /// Track the number of currently active capturing scopes. |
814 | unsigned CapturingFunctionScopes = 0; |
815 | |
816 | llvm::BumpPtrAllocator BumpAlloc; |
817 | |
818 | /// The kind of translation unit we are processing. |
819 | /// |
820 | /// When we're processing a complete translation unit, Sema will perform |
821 | /// end-of-translation-unit semantic tasks (such as creating |
822 | /// initializers for tentative definitions in C) once parsing has |
823 | /// completed. Modules and precompiled headers perform different kinds of |
824 | /// checks. |
825 | const TranslationUnitKind TUKind; |
826 | |
827 | /// Translation Unit Scope - useful to Objective-C actions that need |
828 | /// to lookup file scope declarations in the "ordinary" C decl namespace. |
829 | /// For example, user-defined classes, built-in "id" type, etc. |
830 | Scope *TUScope; |
831 | |
832 | bool WarnedStackExhausted = false; |
833 | |
834 | void incrementMSManglingNumber() const { |
835 | return CurScope->incrementMSManglingNumber(); |
836 | } |
837 | |
838 | /// Try to recover by turning the given expression into a |
839 | /// call. Returns true if recovery was attempted or an error was |
840 | /// emitted; this may also leave the ExprResult invalid. |
841 | bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, |
842 | bool ForceComplain = false, |
843 | bool (*IsPlausibleResult)(QualType) = nullptr); |
844 | |
845 | /// Figure out if an expression could be turned into a call. |
846 | bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy, |
847 | UnresolvedSetImpl &NonTemplateOverloads); |
848 | |
849 | typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; |
850 | typedef OpaquePtr<TemplateName> TemplateTy; |
851 | typedef OpaquePtr<QualType> TypeTy; |
852 | |
853 | OpenCLOptions OpenCLFeatures; |
854 | FPOptions CurFPFeatures; |
855 | |
856 | const LangOptions &LangOpts; |
857 | Preprocessor &PP; |
858 | ASTContext &Context; |
859 | ASTConsumer &Consumer; |
860 | DiagnosticsEngine &Diags; |
861 | SourceManager &SourceMgr; |
862 | api_notes::APINotesManager APINotes; |
863 | |
864 | /// A RAII object to enter scope of a compound statement. |
865 | class CompoundScopeRAII { |
866 | public: |
867 | CompoundScopeRAII(Sema &S, bool IsStmtExpr = false) : S(S) { |
868 | S.ActOnStartOfCompoundStmt(IsStmtExpr); |
869 | } |
870 | |
871 | ~CompoundScopeRAII() { S.ActOnFinishOfCompoundStmt(); } |
872 | |
873 | private: |
874 | Sema &S; |
875 | }; |
876 | |
877 | /// An RAII helper that pops function a function scope on exit. |
878 | struct FunctionScopeRAII { |
879 | Sema &S; |
880 | bool Active; |
881 | FunctionScopeRAII(Sema &S) : S(S), Active(true) {} |
882 | ~FunctionScopeRAII() { |
883 | if (Active) |
884 | S.PopFunctionScopeInfo(); |
885 | } |
886 | void disable() { Active = false; } |
887 | }; |
888 | |
889 | /// Build a partial diagnostic. |
890 | PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h |
891 | |
892 | sema::FunctionScopeInfo *getCurFunction() const { |
893 | return FunctionScopes.empty() ? nullptr : FunctionScopes.back(); |
894 | } |
895 | |
896 | /// Worker object for performing CFG-based warnings. |
897 | sema::AnalysisBasedWarnings AnalysisWarnings; |
898 | threadSafety::BeforeSet *ThreadSafetyDeclCache; |
899 | |
900 | /// Callback to the parser to parse templated functions when needed. |
901 | typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT); |
902 | typedef void LateTemplateParserCleanupCB(void *P); |
903 | LateTemplateParserCB *LateTemplateParser; |
904 | LateTemplateParserCleanupCB *LateTemplateParserCleanup; |
905 | void *OpaqueParser; |
906 | |
907 | void SetLateTemplateParser(LateTemplateParserCB *LTP, |
908 | LateTemplateParserCleanupCB *LTPCleanup, void *P) { |
909 | LateTemplateParser = LTP; |
910 | LateTemplateParserCleanup = LTPCleanup; |
911 | OpaqueParser = P; |
912 | } |
913 | |
914 | /// Callback to the parser to parse a type expressed as a string. |
915 | std::function<TypeResult(StringRef, StringRef, SourceLocation)> |
916 | ParseTypeFromStringCallback; |
917 | |
918 | /// VAListTagName - The declaration name corresponding to __va_list_tag. |
919 | /// This is used as part of a hack to omit that class from ADL results. |
920 | DeclarationName VAListTagName; |
921 | |
922 | /// Is the last error level diagnostic immediate. This is used to determined |
923 | /// whether the next info diagnostic should be immediate. |
924 | bool IsLastErrorImmediate = true; |
925 | |
926 | class DelayedDiagnostics; |
927 | |
928 | class DelayedDiagnosticsState { |
929 | sema::DelayedDiagnosticPool *SavedPool = nullptr; |
930 | friend class Sema::DelayedDiagnostics; |
931 | }; |
932 | typedef DelayedDiagnosticsState ParsingDeclState; |
933 | typedef DelayedDiagnosticsState ProcessingContextState; |
934 | |
935 | /// A class which encapsulates the logic for delaying diagnostics |
936 | /// during parsing and other processing. |
937 | class DelayedDiagnostics { |
938 | /// The current pool of diagnostics into which delayed |
939 | /// diagnostics should go. |
940 | sema::DelayedDiagnosticPool *CurPool = nullptr; |
941 | |
942 | public: |
943 | DelayedDiagnostics() = default; |
944 | |
945 | /// Adds a delayed diagnostic. |
946 | void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h |
947 | |
948 | /// Determines whether diagnostics should be delayed. |
949 | bool shouldDelayDiagnostics() { return CurPool != nullptr; } |
950 | |
951 | /// Returns the current delayed-diagnostics pool. |
952 | sema::DelayedDiagnosticPool *getCurrentPool() const { return CurPool; } |
953 | |
954 | /// Enter a new scope. Access and deprecation diagnostics will be |
955 | /// collected in this pool. |
956 | DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) { |
957 | DelayedDiagnosticsState state; |
958 | state.SavedPool = CurPool; |
959 | CurPool = &pool; |
960 | return state; |
961 | } |
962 | |
963 | /// Leave a delayed-diagnostic state that was previously pushed. |
964 | /// Do not emit any of the diagnostics. This is performed as part |
965 | /// of the bookkeeping of popping a pool "properly". |
966 | void popWithoutEmitting(DelayedDiagnosticsState state) { |
967 | CurPool = state.SavedPool; |
968 | } |
969 | |
970 | /// Enter a new scope where access and deprecation diagnostics are |
971 | /// not delayed. |
972 | DelayedDiagnosticsState pushUndelayed() { |
973 | DelayedDiagnosticsState state; |
974 | state.SavedPool = CurPool; |
975 | CurPool = nullptr; |
976 | return state; |
977 | } |
978 | |
979 | /// Undo a previous pushUndelayed(). |
980 | void popUndelayed(DelayedDiagnosticsState state) { |
981 | assert(CurPool == nullptr); |
982 | CurPool = state.SavedPool; |
983 | } |
984 | } DelayedDiagnostics; |
985 | |
986 | ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) { |
987 | return DelayedDiagnostics.push(pool); |
988 | } |
989 | |
990 | /// Diagnostics that are emitted only if we discover that the given function |
991 | /// must be codegen'ed. Because handling these correctly adds overhead to |
992 | /// compilation, this is currently only enabled for CUDA compilations. |
993 | SemaDiagnosticBuilder::DeferredDiagnosticsType DeviceDeferredDiags; |
994 | |
995 | /// CurContext - This is the current declaration context of parsing. |
996 | DeclContext *CurContext; |
997 | |
998 | SemaCUDA &CUDA() { |
999 | assert(CUDAPtr); |
1000 | return *CUDAPtr; |
1001 | } |
1002 | |
1003 | SemaHLSL &HLSL() { |
1004 | assert(HLSLPtr); |
1005 | return *HLSLPtr; |
1006 | } |
1007 | |
1008 | SemaOpenACC &OpenACC() { |
1009 | assert(OpenACCPtr); |
1010 | return *OpenACCPtr; |
1011 | } |
1012 | |
1013 | SemaOpenMP &OpenMP() { |
1014 | assert(OpenMPPtr && "SemaOpenMP is dead" ); |
1015 | return *OpenMPPtr; |
1016 | } |
1017 | |
1018 | SemaSYCL &SYCL() { |
1019 | assert(SYCLPtr); |
1020 | return *SYCLPtr; |
1021 | } |
1022 | |
1023 | protected: |
1024 | friend class Parser; |
1025 | friend class InitializationSequence; |
1026 | friend class ASTReader; |
1027 | friend class ASTDeclReader; |
1028 | friend class ASTWriter; |
1029 | |
1030 | private: |
1031 | std::optional<std::unique_ptr<DarwinSDKInfo>> CachedDarwinSDKInfo; |
1032 | bool WarnedDarwinSDKInfoMissing = false; |
1033 | |
1034 | Sema(const Sema &) = delete; |
1035 | void operator=(const Sema &) = delete; |
1036 | |
1037 | /// Source of additional semantic information. |
1038 | IntrusiveRefCntPtr<ExternalSemaSource> ExternalSource; |
1039 | |
1040 | /// The handler for the FileChanged preprocessor events. |
1041 | /// |
1042 | /// Used for diagnostics that implement custom semantic analysis for #include |
1043 | /// directives, like -Wpragma-pack. |
1044 | sema::SemaPPCallbacks *SemaPPCallbackHandler; |
1045 | |
1046 | /// The parser's current scope. |
1047 | /// |
1048 | /// The parser maintains this state here. |
1049 | Scope *CurScope; |
1050 | |
1051 | mutable IdentifierInfo *Ident_super; |
1052 | |
1053 | std::unique_ptr<SemaCUDA> CUDAPtr; |
1054 | std::unique_ptr<SemaHLSL> HLSLPtr; |
1055 | std::unique_ptr<SemaOpenACC> OpenACCPtr; |
1056 | std::unique_ptr<SemaOpenMP> OpenMPPtr; |
1057 | std::unique_ptr<SemaSYCL> SYCLPtr; |
1058 | |
1059 | ///@} |
1060 | |
1061 | // |
1062 | // |
1063 | // ------------------------------------------------------------------------- |
1064 | // |
1065 | // |
1066 | |
1067 | /// \name C++ Access Control |
1068 | /// Implementations are in SemaAccess.cpp |
1069 | ///@{ |
1070 | |
1071 | public: |
1072 | enum AccessResult { |
1073 | AR_accessible, |
1074 | AR_inaccessible, |
1075 | AR_dependent, |
1076 | AR_delayed |
1077 | }; |
1078 | |
1079 | bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, |
1080 | NamedDecl *PrevMemberDecl, |
1081 | AccessSpecifier LexicalAS); |
1082 | |
1083 | AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, |
1084 | DeclAccessPair FoundDecl); |
1085 | AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, |
1086 | DeclAccessPair FoundDecl); |
1087 | AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, |
1088 | SourceRange PlacementRange, |
1089 | CXXRecordDecl *NamingClass, |
1090 | DeclAccessPair FoundDecl, |
1091 | bool Diagnose = true); |
1092 | AccessResult CheckConstructorAccess(SourceLocation Loc, CXXConstructorDecl *D, |
1093 | DeclAccessPair FoundDecl, |
1094 | const InitializedEntity &Entity, |
1095 | bool IsCopyBindingRefToTemp = false); |
1096 | AccessResult CheckConstructorAccess(SourceLocation Loc, CXXConstructorDecl *D, |
1097 | DeclAccessPair FoundDecl, |
1098 | const InitializedEntity &Entity, |
1099 | const PartialDiagnostic &PDiag); |
1100 | AccessResult CheckDestructorAccess(SourceLocation Loc, |
1101 | CXXDestructorDecl *Dtor, |
1102 | const PartialDiagnostic &PDiag, |
1103 | QualType objectType = QualType()); |
1104 | AccessResult CheckFriendAccess(NamedDecl *D); |
1105 | AccessResult CheckMemberAccess(SourceLocation UseLoc, |
1106 | CXXRecordDecl *NamingClass, |
1107 | DeclAccessPair Found); |
1108 | AccessResult |
1109 | CheckStructuredBindingMemberAccess(SourceLocation UseLoc, |
1110 | CXXRecordDecl *DecomposedClass, |
1111 | DeclAccessPair Field); |
1112 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, |
1113 | const SourceRange &, |
1114 | DeclAccessPair FoundDecl); |
1115 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, |
1116 | Expr *ArgExpr, |
1117 | DeclAccessPair FoundDecl); |
1118 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, |
1119 | ArrayRef<Expr *> ArgExprs, |
1120 | DeclAccessPair FoundDecl); |
1121 | AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, |
1122 | DeclAccessPair FoundDecl); |
1123 | AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, QualType Base, |
1124 | QualType Derived, const CXXBasePath &Path, |
1125 | unsigned DiagID, bool ForceCheck = false, |
1126 | bool ForceUnprivileged = false); |
1127 | void CheckLookupAccess(const LookupResult &R); |
1128 | bool IsSimplyAccessible(NamedDecl *Decl, CXXRecordDecl *NamingClass, |
1129 | QualType BaseType); |
1130 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
1131 | DeclAccessPair Found, QualType ObjectType, |
1132 | SourceLocation Loc, |
1133 | const PartialDiagnostic &Diag); |
1134 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
1135 | DeclAccessPair Found, |
1136 | QualType ObjectType) { |
1137 | return isMemberAccessibleForDeletion(NamingClass, Found, ObjectType, |
1138 | Loc: SourceLocation(), Diag: PDiag()); |
1139 | } |
1140 | |
1141 | void HandleDependentAccessCheck( |
1142 | const DependentDiagnostic &DD, |
1143 | const MultiLevelTemplateArgumentList &TemplateArgs); |
1144 | void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
1145 | |
1146 | ///@} |
1147 | |
1148 | // |
1149 | // |
1150 | // ------------------------------------------------------------------------- |
1151 | // |
1152 | // |
1153 | |
1154 | /// \name Attributes |
1155 | /// Implementations are in SemaAttr.cpp |
1156 | ///@{ |
1157 | |
1158 | public: |
1159 | /// Controls member pointer representation format under the MS ABI. |
1160 | LangOptions::PragmaMSPointersToMembersKind |
1161 | MSPointerToMemberRepresentationMethod; |
1162 | |
1163 | bool MSStructPragmaOn; // True when \#pragma ms_struct on |
1164 | |
1165 | /// Source location for newly created implicit MSInheritanceAttrs |
1166 | SourceLocation ImplicitMSInheritanceAttrLoc; |
1167 | |
1168 | /// pragma clang section kind |
1169 | enum PragmaClangSectionKind { |
1170 | PCSK_Invalid = 0, |
1171 | PCSK_BSS = 1, |
1172 | PCSK_Data = 2, |
1173 | PCSK_Rodata = 3, |
1174 | PCSK_Text = 4, |
1175 | PCSK_Relro = 5 |
1176 | }; |
1177 | |
1178 | enum PragmaClangSectionAction { PCSA_Set = 0, PCSA_Clear = 1 }; |
1179 | |
1180 | struct PragmaClangSection { |
1181 | std::string SectionName; |
1182 | bool Valid = false; |
1183 | SourceLocation PragmaLocation; |
1184 | }; |
1185 | |
1186 | PragmaClangSection PragmaClangBSSSection; |
1187 | PragmaClangSection PragmaClangDataSection; |
1188 | PragmaClangSection PragmaClangRodataSection; |
1189 | PragmaClangSection PragmaClangRelroSection; |
1190 | PragmaClangSection PragmaClangTextSection; |
1191 | |
1192 | enum PragmaMsStackAction { |
1193 | PSK_Reset = 0x0, // #pragma () |
1194 | PSK_Set = 0x1, // #pragma (value) |
1195 | PSK_Push = 0x2, // #pragma (push[, id]) |
1196 | PSK_Pop = 0x4, // #pragma (pop[, id]) |
1197 | PSK_Show = 0x8, // #pragma (show) -- only for "pack"! |
1198 | PSK_Push_Set = PSK_Push | PSK_Set, // #pragma (push[, id], value) |
1199 | PSK_Pop_Set = PSK_Pop | PSK_Set, // #pragma (pop[, id], value) |
1200 | }; |
1201 | |
1202 | struct PragmaPackInfo { |
1203 | PragmaMsStackAction Action; |
1204 | StringRef SlotLabel; |
1205 | Token Alignment; |
1206 | }; |
1207 | |
1208 | // #pragma pack and align. |
1209 | class AlignPackInfo { |
1210 | public: |
1211 | // `Native` represents default align mode, which may vary based on the |
1212 | // platform. |
1213 | enum Mode : unsigned char { Native, Natural, Packed, Mac68k }; |
1214 | |
1215 | // #pragma pack info constructor |
1216 | AlignPackInfo(AlignPackInfo::Mode M, unsigned Num, bool IsXL) |
1217 | : PackAttr(true), AlignMode(M), PackNumber(Num), XLStack(IsXL) { |
1218 | assert(Num == PackNumber && "The pack number has been truncated." ); |
1219 | } |
1220 | |
1221 | // #pragma align info constructor |
1222 | AlignPackInfo(AlignPackInfo::Mode M, bool IsXL) |
1223 | : PackAttr(false), AlignMode(M), |
1224 | PackNumber(M == Packed ? 1 : UninitPackVal), XLStack(IsXL) {} |
1225 | |
1226 | explicit AlignPackInfo(bool IsXL) : AlignPackInfo(Native, IsXL) {} |
1227 | |
1228 | AlignPackInfo() : AlignPackInfo(Native, false) {} |
1229 | |
1230 | // When a AlignPackInfo itself cannot be used, this returns an 32-bit |
1231 | // integer encoding for it. This should only be passed to |
1232 | // AlignPackInfo::getFromRawEncoding, it should not be inspected directly. |
1233 | static uint32_t getRawEncoding(const AlignPackInfo &Info) { |
1234 | std::uint32_t Encoding{}; |
1235 | if (Info.IsXLStack()) |
1236 | Encoding |= IsXLMask; |
1237 | |
1238 | Encoding |= static_cast<uint32_t>(Info.getAlignMode()) << 1; |
1239 | |
1240 | if (Info.IsPackAttr()) |
1241 | Encoding |= PackAttrMask; |
1242 | |
1243 | Encoding |= static_cast<uint32_t>(Info.getPackNumber()) << 4; |
1244 | |
1245 | return Encoding; |
1246 | } |
1247 | |
1248 | static AlignPackInfo getFromRawEncoding(unsigned Encoding) { |
1249 | bool IsXL = static_cast<bool>(Encoding & IsXLMask); |
1250 | AlignPackInfo::Mode M = |
1251 | static_cast<AlignPackInfo::Mode>((Encoding & AlignModeMask) >> 1); |
1252 | int PackNumber = (Encoding & PackNumMask) >> 4; |
1253 | |
1254 | if (Encoding & PackAttrMask) |
1255 | return AlignPackInfo(M, PackNumber, IsXL); |
1256 | |
1257 | return AlignPackInfo(M, IsXL); |
1258 | } |
1259 | |
1260 | bool IsPackAttr() const { return PackAttr; } |
1261 | |
1262 | bool IsAlignAttr() const { return !PackAttr; } |
1263 | |
1264 | Mode getAlignMode() const { return AlignMode; } |
1265 | |
1266 | unsigned getPackNumber() const { return PackNumber; } |
1267 | |
1268 | bool IsPackSet() const { |
1269 | // #pragma align, #pragma pack(), and #pragma pack(0) do not set the pack |
1270 | // attriute on a decl. |
1271 | return PackNumber != UninitPackVal && PackNumber != 0; |
1272 | } |
1273 | |
1274 | bool IsXLStack() const { return XLStack; } |
1275 | |
1276 | bool operator==(const AlignPackInfo &Info) const { |
1277 | return std::tie(args: AlignMode, args: PackNumber, args: PackAttr, args: XLStack) == |
1278 | std::tie(args: Info.AlignMode, args: Info.PackNumber, args: Info.PackAttr, |
1279 | args: Info.XLStack); |
1280 | } |
1281 | |
1282 | bool operator!=(const AlignPackInfo &Info) const { |
1283 | return !(*this == Info); |
1284 | } |
1285 | |
1286 | private: |
1287 | /// \brief True if this is a pragma pack attribute, |
1288 | /// not a pragma align attribute. |
1289 | bool PackAttr; |
1290 | |
1291 | /// \brief The alignment mode that is in effect. |
1292 | Mode AlignMode; |
1293 | |
1294 | /// \brief The pack number of the stack. |
1295 | unsigned char PackNumber; |
1296 | |
1297 | /// \brief True if it is a XL #pragma align/pack stack. |
1298 | bool XLStack; |
1299 | |
1300 | /// \brief Uninitialized pack value. |
1301 | static constexpr unsigned char UninitPackVal = -1; |
1302 | |
1303 | // Masks to encode and decode an AlignPackInfo. |
1304 | static constexpr uint32_t IsXLMask{0x0000'0001}; |
1305 | static constexpr uint32_t AlignModeMask{0x0000'0006}; |
1306 | static constexpr uint32_t PackAttrMask{0x00000'0008}; |
1307 | static constexpr uint32_t PackNumMask{0x0000'01F0}; |
1308 | }; |
1309 | |
1310 | template <typename ValueType> struct PragmaStack { |
1311 | struct Slot { |
1312 | llvm::StringRef StackSlotLabel; |
1313 | ValueType Value; |
1314 | SourceLocation PragmaLocation; |
1315 | SourceLocation PragmaPushLocation; |
1316 | Slot(llvm::StringRef StackSlotLabel, ValueType Value, |
1317 | SourceLocation PragmaLocation, SourceLocation PragmaPushLocation) |
1318 | : StackSlotLabel(StackSlotLabel), Value(Value), |
1319 | PragmaLocation(PragmaLocation), |
1320 | PragmaPushLocation(PragmaPushLocation) {} |
1321 | }; |
1322 | |
1323 | void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, |
1324 | llvm::StringRef StackSlotLabel, ValueType Value) { |
1325 | if (Action == PSK_Reset) { |
1326 | CurrentValue = DefaultValue; |
1327 | CurrentPragmaLocation = PragmaLocation; |
1328 | return; |
1329 | } |
1330 | if (Action & PSK_Push) |
1331 | Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation, |
1332 | PragmaLocation); |
1333 | else if (Action & PSK_Pop) { |
1334 | if (!StackSlotLabel.empty()) { |
1335 | // If we've got a label, try to find it and jump there. |
1336 | auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) { |
1337 | return x.StackSlotLabel == StackSlotLabel; |
1338 | }); |
1339 | // If we found the label so pop from there. |
1340 | if (I != Stack.rend()) { |
1341 | CurrentValue = I->Value; |
1342 | CurrentPragmaLocation = I->PragmaLocation; |
1343 | Stack.erase(std::prev(I.base()), Stack.end()); |
1344 | } |
1345 | } else if (!Stack.empty()) { |
1346 | // We do not have a label, just pop the last entry. |
1347 | CurrentValue = Stack.back().Value; |
1348 | CurrentPragmaLocation = Stack.back().PragmaLocation; |
1349 | Stack.pop_back(); |
1350 | } |
1351 | } |
1352 | if (Action & PSK_Set) { |
1353 | CurrentValue = Value; |
1354 | CurrentPragmaLocation = PragmaLocation; |
1355 | } |
1356 | } |
1357 | |
1358 | // MSVC seems to add artificial slots to #pragma stacks on entering a C++ |
1359 | // method body to restore the stacks on exit, so it works like this: |
1360 | // |
1361 | // struct S { |
1362 | // #pragma <name>(push, InternalPragmaSlot, <current_pragma_value>) |
1363 | // void Method {} |
1364 | // #pragma <name>(pop, InternalPragmaSlot) |
1365 | // }; |
1366 | // |
1367 | // It works even with #pragma vtordisp, although MSVC doesn't support |
1368 | // #pragma vtordisp(push [, id], n) |
1369 | // syntax. |
1370 | // |
1371 | // Push / pop a named sentinel slot. |
1372 | void SentinelAction(PragmaMsStackAction Action, StringRef Label) { |
1373 | assert((Action == PSK_Push || Action == PSK_Pop) && |
1374 | "Can only push / pop #pragma stack sentinels!" ); |
1375 | Act(PragmaLocation: CurrentPragmaLocation, Action, StackSlotLabel: Label, Value: CurrentValue); |
1376 | } |
1377 | |
1378 | // Constructors. |
1379 | explicit PragmaStack(const ValueType &Default) |
1380 | : DefaultValue(Default), CurrentValue(Default) {} |
1381 | |
1382 | bool hasValue() const { return CurrentValue != DefaultValue; } |
1383 | |
1384 | SmallVector<Slot, 2> Stack; |
1385 | ValueType DefaultValue; // Value used for PSK_Reset action. |
1386 | ValueType CurrentValue; |
1387 | SourceLocation CurrentPragmaLocation; |
1388 | }; |
1389 | // FIXME: We should serialize / deserialize these if they occur in a PCH (but |
1390 | // we shouldn't do so if they're in a module). |
1391 | |
1392 | /// Whether to insert vtordisps prior to virtual bases in the Microsoft |
1393 | /// C++ ABI. Possible values are 0, 1, and 2, which mean: |
1394 | /// |
1395 | /// 0: Suppress all vtordisps |
1396 | /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial |
1397 | /// structors |
1398 | /// 2: Always insert vtordisps to support RTTI on partially constructed |
1399 | /// objects |
1400 | PragmaStack<MSVtorDispMode> VtorDispStack; |
1401 | PragmaStack<AlignPackInfo> AlignPackStack; |
1402 | // The current #pragma align/pack values and locations at each #include. |
1403 | struct AlignPackIncludeState { |
1404 | AlignPackInfo CurrentValue; |
1405 | SourceLocation CurrentPragmaLocation; |
1406 | bool HasNonDefaultValue, ShouldWarnOnInclude; |
1407 | }; |
1408 | SmallVector<AlignPackIncludeState, 8> AlignPackIncludeStack; |
1409 | // Segment #pragmas. |
1410 | PragmaStack<StringLiteral *> DataSegStack; |
1411 | PragmaStack<StringLiteral *> BSSSegStack; |
1412 | PragmaStack<StringLiteral *> ConstSegStack; |
1413 | PragmaStack<StringLiteral *> CodeSegStack; |
1414 | |
1415 | // #pragma strict_gs_check. |
1416 | PragmaStack<bool> StrictGuardStackCheckStack; |
1417 | |
1418 | // This stack tracks the current state of Sema.CurFPFeatures. |
1419 | PragmaStack<FPOptionsOverride> FpPragmaStack; |
1420 | FPOptionsOverride CurFPFeatureOverrides() { |
1421 | FPOptionsOverride result; |
1422 | if (!FpPragmaStack.hasValue()) { |
1423 | result = FPOptionsOverride(); |
1424 | } else { |
1425 | result = FpPragmaStack.CurrentValue; |
1426 | } |
1427 | return result; |
1428 | } |
1429 | |
1430 | enum PragmaSectionKind { |
1431 | PSK_DataSeg, |
1432 | PSK_BSSSeg, |
1433 | PSK_ConstSeg, |
1434 | PSK_CodeSeg, |
1435 | }; |
1436 | |
1437 | // RAII object to push / pop sentinel slots for all MS #pragma stacks. |
1438 | // Actions should be performed only if we enter / exit a C++ method body. |
1439 | class PragmaStackSentinelRAII { |
1440 | public: |
1441 | PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct); |
1442 | ~PragmaStackSentinelRAII(); |
1443 | |
1444 | private: |
1445 | Sema &S; |
1446 | StringRef SlotLabel; |
1447 | bool ShouldAct; |
1448 | }; |
1449 | |
1450 | /// Last section used with #pragma init_seg. |
1451 | StringLiteral *CurInitSeg; |
1452 | SourceLocation CurInitSegLoc; |
1453 | |
1454 | /// Sections used with #pragma alloc_text. |
1455 | llvm::StringMap<std::tuple<StringRef, SourceLocation>> FunctionToSectionMap; |
1456 | |
1457 | /// VisContext - Manages the stack for \#pragma GCC visibility. |
1458 | void *VisContext; // Really a "PragmaVisStack*" |
1459 | |
1460 | /// This an attribute introduced by \#pragma clang attribute. |
1461 | struct PragmaAttributeEntry { |
1462 | SourceLocation Loc; |
1463 | ParsedAttr *Attribute; |
1464 | SmallVector<attr::SubjectMatchRule, 4> MatchRules; |
1465 | bool IsUsed; |
1466 | }; |
1467 | |
1468 | /// A push'd group of PragmaAttributeEntries. |
1469 | struct PragmaAttributeGroup { |
1470 | /// The location of the push attribute. |
1471 | SourceLocation Loc; |
1472 | /// The namespace of this push group. |
1473 | const IdentifierInfo *Namespace; |
1474 | SmallVector<PragmaAttributeEntry, 2> Entries; |
1475 | }; |
1476 | |
1477 | SmallVector<PragmaAttributeGroup, 2> PragmaAttributeStack; |
1478 | |
1479 | /// The declaration that is currently receiving an attribute from the |
1480 | /// #pragma attribute stack. |
1481 | const Decl *PragmaAttributeCurrentTargetDecl; |
1482 | |
1483 | /// This represents the last location of a "#pragma clang optimize off" |
1484 | /// directive if such a directive has not been closed by an "on" yet. If |
1485 | /// optimizations are currently "on", this is set to an invalid location. |
1486 | SourceLocation OptimizeOffPragmaLocation; |
1487 | |
1488 | /// Get the location for the currently active "\#pragma clang optimize |
1489 | /// off". If this location is invalid, then the state of the pragma is "on". |
1490 | SourceLocation getOptimizeOffPragmaLocation() const { |
1491 | return OptimizeOffPragmaLocation; |
1492 | } |
1493 | |
1494 | /// The "on" or "off" argument passed by \#pragma optimize, that denotes |
1495 | /// whether the optimizations in the list passed to the pragma should be |
1496 | /// turned off or on. This boolean is true by default because command line |
1497 | /// options are honored when `#pragma optimize("", on)`. |
1498 | /// (i.e. `ModifyFnAttributeMSPragmaOptimze()` does nothing) |
1499 | bool MSPragmaOptimizeIsOn = true; |
1500 | |
1501 | /// Set of no-builtin functions listed by \#pragma function. |
1502 | llvm::SmallSetVector<StringRef, 4> MSFunctionNoBuiltins; |
1503 | |
1504 | /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to |
1505 | /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'. |
1506 | void AddAlignmentAttributesForRecord(RecordDecl *RD); |
1507 | |
1508 | /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. |
1509 | void AddMsStructLayoutForRecord(RecordDecl *RD); |
1510 | |
1511 | /// Add gsl::Pointer attribute to std::container::iterator |
1512 | /// \param ND The declaration that introduces the name |
1513 | /// std::container::iterator. \param UnderlyingRecord The record named by ND. |
1514 | void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord); |
1515 | |
1516 | /// Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types. |
1517 | void inferGslOwnerPointerAttribute(CXXRecordDecl *Record); |
1518 | |
1519 | /// Add [[gsl::Pointer]] attributes for std:: types. |
1520 | void inferGslPointerAttribute(TypedefNameDecl *TD); |
1521 | |
1522 | /// Add _Nullable attributes for std:: types. |
1523 | void inferNullableClassAttribute(CXXRecordDecl *CRD); |
1524 | |
1525 | enum PragmaOptionsAlignKind { |
1526 | POAK_Native, // #pragma options align=native |
1527 | POAK_Natural, // #pragma options align=natural |
1528 | POAK_Packed, // #pragma options align=packed |
1529 | POAK_Power, // #pragma options align=power |
1530 | POAK_Mac68k, // #pragma options align=mac68k |
1531 | POAK_Reset // #pragma options align=reset |
1532 | }; |
1533 | |
1534 | /// ActOnPragmaClangSection - Called on well formed \#pragma clang section |
1535 | void ActOnPragmaClangSection(SourceLocation PragmaLoc, |
1536 | PragmaClangSectionAction Action, |
1537 | PragmaClangSectionKind SecKind, |
1538 | StringRef SecName); |
1539 | |
1540 | /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align. |
1541 | void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, |
1542 | SourceLocation PragmaLoc); |
1543 | |
1544 | /// ActOnPragmaPack - Called on well formed \#pragma pack(...). |
1545 | void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, |
1546 | StringRef SlotLabel, Expr *Alignment); |
1547 | |
1548 | /// ConstantFoldAttrArgs - Folds attribute arguments into ConstantExprs |
1549 | /// (unless they are value dependent or type dependent). Returns false |
1550 | /// and emits a diagnostic if one or more of the arguments could not be |
1551 | /// folded into a constant. |
1552 | bool ConstantFoldAttrArgs(const AttributeCommonInfo &CI, |
1553 | MutableArrayRef<Expr *> Args); |
1554 | |
1555 | enum class PragmaAlignPackDiagnoseKind { |
1556 | NonDefaultStateAtInclude, |
1557 | ChangedStateAtExit |
1558 | }; |
1559 | |
1560 | void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind, |
1561 | SourceLocation IncludeLoc); |
1562 | void DiagnoseUnterminatedPragmaAlignPack(); |
1563 | |
1564 | /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off]. |
1565 | void ActOnPragmaMSStruct(PragmaMSStructKind Kind); |
1566 | |
1567 | /// ActOnPragmaMSComment - Called on well formed |
1568 | /// \#pragma comment(kind, "arg"). |
1569 | void (SourceLocation , PragmaMSCommentKind Kind, |
1570 | StringRef Arg); |
1571 | |
1572 | /// ActOnPragmaDetectMismatch - Call on well-formed \#pragma detect_mismatch |
1573 | void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, |
1574 | StringRef Value); |
1575 | |
1576 | /// Are precise floating point semantics currently enabled? |
1577 | bool isPreciseFPEnabled() { |
1578 | return !CurFPFeatures.getAllowFPReassociate() && |
1579 | !CurFPFeatures.getNoSignedZero() && |
1580 | !CurFPFeatures.getAllowReciprocal() && |
1581 | !CurFPFeatures.getAllowApproxFunc(); |
1582 | } |
1583 | |
1584 | void ActOnPragmaFPEvalMethod(SourceLocation Loc, |
1585 | LangOptions::FPEvalMethodKind Value); |
1586 | |
1587 | /// ActOnPragmaFloatControl - Call on well-formed \#pragma float_control |
1588 | void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, |
1589 | PragmaFloatControlKind Value); |
1590 | |
1591 | /// ActOnPragmaMSPointersToMembers - called on well formed \#pragma |
1592 | /// pointers_to_members(representation method[, general purpose |
1593 | /// representation]). |
1594 | void ActOnPragmaMSPointersToMembers( |
1595 | LangOptions::PragmaMSPointersToMembersKind Kind, |
1596 | SourceLocation PragmaLoc); |
1597 | |
1598 | /// Called on well formed \#pragma vtordisp(). |
1599 | void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, |
1600 | SourceLocation PragmaLoc, MSVtorDispMode Value); |
1601 | |
1602 | bool UnifySection(StringRef SectionName, int SectionFlags, |
1603 | NamedDecl *TheDecl); |
1604 | bool UnifySection(StringRef SectionName, int SectionFlags, |
1605 | SourceLocation PragmaSectionLocation); |
1606 | |
1607 | /// Called on well formed \#pragma bss_seg/data_seg/const_seg/code_seg. |
1608 | void ActOnPragmaMSSeg(SourceLocation PragmaLocation, |
1609 | PragmaMsStackAction Action, |
1610 | llvm::StringRef StackSlotLabel, |
1611 | StringLiteral *SegmentName, llvm::StringRef PragmaName); |
1612 | |
1613 | /// Called on well formed \#pragma section(). |
1614 | void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, |
1615 | StringLiteral *SegmentName); |
1616 | |
1617 | /// Called on well-formed \#pragma init_seg(). |
1618 | void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, |
1619 | StringLiteral *SegmentName); |
1620 | |
1621 | /// Called on well-formed \#pragma alloc_text(). |
1622 | void ActOnPragmaMSAllocText( |
1623 | SourceLocation PragmaLocation, StringRef Section, |
1624 | const SmallVector<std::tuple<IdentifierInfo *, SourceLocation>> |
1625 | &Functions); |
1626 | |
1627 | /// ActOnPragmaMSStrictGuardStackCheck - Called on well formed \#pragma |
1628 | /// strict_gs_check. |
1629 | void ActOnPragmaMSStrictGuardStackCheck(SourceLocation PragmaLocation, |
1630 | PragmaMsStackAction Action, |
1631 | bool Value); |
1632 | |
1633 | /// ActOnPragmaUnused - Called on well-formed '\#pragma unused'. |
1634 | void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, |
1635 | SourceLocation PragmaLoc); |
1636 | |
1637 | /// AddCFAuditedAttribute - Check whether we're currently within |
1638 | /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding |
1639 | /// the appropriate attribute. |
1640 | void AddCFAuditedAttribute(Decl *D); |
1641 | |
1642 | void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, |
1643 | SourceLocation PragmaLoc, |
1644 | attr::ParsedSubjectMatchRuleSet Rules); |
1645 | void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, |
1646 | const IdentifierInfo *Namespace); |
1647 | |
1648 | /// Called on well-formed '\#pragma clang attribute pop'. |
1649 | void ActOnPragmaAttributePop(SourceLocation PragmaLoc, |
1650 | const IdentifierInfo *Namespace); |
1651 | |
1652 | /// Adds the attributes that have been specified using the |
1653 | /// '\#pragma clang attribute push' directives to the given declaration. |
1654 | void AddPragmaAttributes(Scope *S, Decl *D); |
1655 | |
1656 | void PrintPragmaAttributeInstantiationPoint(); |
1657 | |
1658 | void DiagnoseUnterminatedPragmaAttribute(); |
1659 | |
1660 | /// Called on well formed \#pragma clang optimize. |
1661 | void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc); |
1662 | |
1663 | /// #pragma optimize("[optimization-list]", on | off). |
1664 | void ActOnPragmaMSOptimize(SourceLocation Loc, bool IsOn); |
1665 | |
1666 | /// Call on well formed \#pragma function. |
1667 | void |
1668 | ActOnPragmaMSFunction(SourceLocation Loc, |
1669 | const llvm::SmallVectorImpl<StringRef> &NoBuiltins); |
1670 | |
1671 | /// Only called on function definitions; if there is a pragma in scope |
1672 | /// with the effect of a range-based optnone, consider marking the function |
1673 | /// with attribute optnone. |
1674 | void AddRangeBasedOptnone(FunctionDecl *FD); |
1675 | |
1676 | /// Only called on function definitions; if there is a `#pragma alloc_text` |
1677 | /// that decides which code section the function should be in, add |
1678 | /// attribute section to the function. |
1679 | void AddSectionMSAllocText(FunctionDecl *FD); |
1680 | |
1681 | /// Adds the 'optnone' attribute to the function declaration if there |
1682 | /// are no conflicts; Loc represents the location causing the 'optnone' |
1683 | /// attribute to be added (usually because of a pragma). |
1684 | void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc); |
1685 | |
1686 | /// Only called on function definitions; if there is a MSVC #pragma optimize |
1687 | /// in scope, consider changing the function's attributes based on the |
1688 | /// optimization list passed to the pragma. |
1689 | void ModifyFnAttributesMSPragmaOptimize(FunctionDecl *FD); |
1690 | |
1691 | /// Only called on function definitions; if there is a pragma in scope |
1692 | /// with the effect of a range-based no_builtin, consider marking the function |
1693 | /// with attribute no_builtin. |
1694 | void AddImplicitMSFunctionNoBuiltinAttr(FunctionDecl *FD); |
1695 | |
1696 | /// AddPushedVisibilityAttribute - If '\#pragma GCC visibility' was used, |
1697 | /// add an appropriate visibility attribute. |
1698 | void AddPushedVisibilityAttribute(Decl *RD); |
1699 | |
1700 | /// FreeVisContext - Deallocate and null out VisContext. |
1701 | void FreeVisContext(); |
1702 | |
1703 | /// ActOnPragmaVisibility - Called on well formed \#pragma GCC visibility... . |
1704 | void ActOnPragmaVisibility(const IdentifierInfo *VisType, |
1705 | SourceLocation PragmaLoc); |
1706 | |
1707 | /// ActOnPragmaFPContract - Called on well formed |
1708 | /// \#pragma {STDC,OPENCL} FP_CONTRACT and |
1709 | /// \#pragma clang fp contract |
1710 | void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC); |
1711 | |
1712 | /// Called on well formed |
1713 | /// \#pragma clang fp reassociate |
1714 | /// or |
1715 | /// \#pragma clang fp reciprocal |
1716 | void ActOnPragmaFPValueChangingOption(SourceLocation Loc, PragmaFPKind Kind, |
1717 | bool IsEnabled); |
1718 | |
1719 | /// ActOnPragmaFenvAccess - Called on well formed |
1720 | /// \#pragma STDC FENV_ACCESS |
1721 | void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled); |
1722 | |
1723 | /// ActOnPragmaCXLimitedRange - Called on well formed |
1724 | /// \#pragma STDC CX_LIMITED_RANGE |
1725 | void ActOnPragmaCXLimitedRange(SourceLocation Loc, |
1726 | LangOptions::ComplexRangeKind Range); |
1727 | |
1728 | /// Called on well formed '\#pragma clang fp' that has option 'exceptions'. |
1729 | void ActOnPragmaFPExceptions(SourceLocation Loc, |
1730 | LangOptions::FPExceptionModeKind); |
1731 | |
1732 | /// Called to set constant rounding mode for floating point operations. |
1733 | void ActOnPragmaFEnvRound(SourceLocation Loc, llvm::RoundingMode); |
1734 | |
1735 | /// Called to set exception behavior for floating point operations. |
1736 | void setExceptionMode(SourceLocation Loc, LangOptions::FPExceptionModeKind); |
1737 | |
1738 | /// PushNamespaceVisibilityAttr - Note that we've entered a |
1739 | /// namespace with a visibility attribute. |
1740 | void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, |
1741 | SourceLocation Loc); |
1742 | |
1743 | /// PopPragmaVisibility - Pop the top element of the visibility stack; used |
1744 | /// for '\#pragma GCC visibility' and visibility attributes on namespaces. |
1745 | void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc); |
1746 | |
1747 | /// Handles semantic checking for features that are common to all attributes, |
1748 | /// such as checking whether a parameter was properly specified, or the |
1749 | /// correct number of arguments were passed, etc. Returns true if the |
1750 | /// attribute has been diagnosed. |
1751 | bool checkCommonAttributeFeatures(const Decl *D, const ParsedAttr &A, |
1752 | bool SkipArgCountCheck = false); |
1753 | bool checkCommonAttributeFeatures(const Stmt *S, const ParsedAttr &A, |
1754 | bool SkipArgCountCheck = false); |
1755 | |
1756 | ///@} |
1757 | |
1758 | // |
1759 | // |
1760 | // ------------------------------------------------------------------------- |
1761 | // |
1762 | // |
1763 | |
1764 | /// \name Availability Attribute Handling |
1765 | /// Implementations are in SemaAvailability.cpp |
1766 | ///@{ |
1767 | |
1768 | public: |
1769 | /// Issue any -Wunguarded-availability warnings in \c FD |
1770 | void DiagnoseUnguardedAvailabilityViolations(Decl *FD); |
1771 | |
1772 | void handleDelayedAvailabilityCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
1773 | |
1774 | /// Retrieve the current function, if any, that should be analyzed for |
1775 | /// potential availability violations. |
1776 | sema::FunctionScopeInfo *getCurFunctionAvailabilityContext(); |
1777 | |
1778 | void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
1779 | const ObjCInterfaceDecl *UnknownObjCClass, |
1780 | bool ObjCPropertyAccess, |
1781 | bool AvoidPartialAvailabilityChecks = false, |
1782 | ObjCInterfaceDecl *ClassReceiver = nullptr); |
1783 | |
1784 | ///@} |
1785 | |
1786 | // |
1787 | // |
1788 | // ------------------------------------------------------------------------- |
1789 | // |
1790 | // |
1791 | |
1792 | /// \name Casts |
1793 | /// Implementations are in SemaCast.cpp |
1794 | ///@{ |
1795 | |
1796 | public: |
1797 | static bool isCast(CheckedConversionKind CCK) { |
1798 | return CCK == CheckedConversionKind::CStyleCast || |
1799 | CCK == CheckedConversionKind::FunctionalCast || |
1800 | CCK == CheckedConversionKind::OtherCast; |
1801 | } |
1802 | |
1803 | /// ActOnCXXNamedCast - Parse |
1804 | /// {dynamic,static,reinterpret,const,addrspace}_cast's. |
1805 | ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, |
1806 | SourceLocation LAngleBracketLoc, Declarator &D, |
1807 | SourceLocation RAngleBracketLoc, |
1808 | SourceLocation LParenLoc, Expr *E, |
1809 | SourceLocation RParenLoc); |
1810 | |
1811 | ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, |
1812 | TypeSourceInfo *Ty, Expr *E, |
1813 | SourceRange AngleBrackets, SourceRange Parens); |
1814 | |
1815 | ExprResult ActOnBuiltinBitCastExpr(SourceLocation KWLoc, Declarator &Dcl, |
1816 | ExprResult Operand, |
1817 | SourceLocation RParenLoc); |
1818 | |
1819 | ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, |
1820 | Expr *Operand, SourceLocation RParenLoc); |
1821 | |
1822 | // Checks that reinterpret casts don't have undefined behavior. |
1823 | void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, |
1824 | bool IsDereference, SourceRange Range); |
1825 | |
1826 | // Checks that the vector type should be initialized from a scalar |
1827 | // by splatting the value rather than populating a single element. |
1828 | // This is the case for AltiVecVector types as well as with |
1829 | // AltiVecPixel and AltiVecBool when -faltivec-src-compat=xl is specified. |
1830 | bool ShouldSplatAltivecScalarInCast(const VectorType *VecTy); |
1831 | |
1832 | // Checks if the -faltivec-src-compat=gcc option is specified. |
1833 | // If so, AltiVecVector, AltiVecBool and AltiVecPixel types are |
1834 | // treated the same way as they are when trying to initialize |
1835 | // these vectors on gcc (an error is emitted). |
1836 | bool CheckAltivecInitFromScalar(SourceRange R, QualType VecTy, |
1837 | QualType SrcTy); |
1838 | |
1839 | ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty, |
1840 | SourceLocation RParenLoc, Expr *Op); |
1841 | |
1842 | ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, QualType Type, |
1843 | SourceLocation LParenLoc, |
1844 | Expr *CastExpr, |
1845 | SourceLocation RParenLoc); |
1846 | |
1847 | ///@} |
1848 | |
1849 | // |
1850 | // |
1851 | // ------------------------------------------------------------------------- |
1852 | // |
1853 | // |
1854 | |
1855 | /// \name Extra Semantic Checking |
1856 | /// Implementations are in SemaChecking.cpp |
1857 | ///@{ |
1858 | |
1859 | public: |
1860 | /// Used to change context to isConstantEvaluated without pushing a heavy |
1861 | /// ExpressionEvaluationContextRecord object. |
1862 | bool isConstantEvaluatedOverride = false; |
1863 | |
1864 | bool isConstantEvaluatedContext() const { |
1865 | return currentEvaluationContext().isConstantEvaluated() || |
1866 | isConstantEvaluatedOverride; |
1867 | } |
1868 | |
1869 | SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, |
1870 | unsigned ByteNo) const; |
1871 | |
1872 | enum FormatArgumentPassingKind { |
1873 | FAPK_Fixed, // values to format are fixed (no C-style variadic arguments) |
1874 | FAPK_Variadic, // values to format are passed as variadic arguments |
1875 | FAPK_VAList, // values to format are passed in a va_list |
1876 | }; |
1877 | |
1878 | // Used to grab the relevant information from a FormatAttr and a |
1879 | // FunctionDeclaration. |
1880 | struct FormatStringInfo { |
1881 | unsigned FormatIdx; |
1882 | unsigned FirstDataArg; |
1883 | FormatArgumentPassingKind ArgPassingKind; |
1884 | }; |
1885 | |
1886 | static bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember, |
1887 | bool IsVariadic, FormatStringInfo *FSI); |
1888 | |
1889 | // Used by C++ template instantiation. |
1890 | ExprResult BuiltinShuffleVector(CallExpr *TheCall); |
1891 | ExprResult ConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo, |
1892 | SourceLocation BuiltinLoc, |
1893 | SourceLocation RParenLoc); |
1894 | |
1895 | enum FormatStringType { |
1896 | FST_Scanf, |
1897 | FST_Printf, |
1898 | FST_NSString, |
1899 | FST_Strftime, |
1900 | FST_Strfmon, |
1901 | FST_Kprintf, |
1902 | FST_FreeBSDKPrintf, |
1903 | FST_OSTrace, |
1904 | FST_OSLog, |
1905 | FST_Unknown |
1906 | }; |
1907 | static FormatStringType GetFormatStringType(const FormatAttr *Format); |
1908 | |
1909 | bool FormatStringHasSArg(const StringLiteral *FExpr); |
1910 | |
1911 | static bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx); |
1912 | |
1913 | void CheckFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS, |
1914 | BinaryOperatorKind Opcode); |
1915 | |
1916 | /// Register a magic integral constant to be used as a type tag. |
1917 | void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind, |
1918 | uint64_t MagicValue, QualType Type, |
1919 | bool LayoutCompatible, bool MustBeNull); |
1920 | |
1921 | struct TypeTagData { |
1922 | TypeTagData() {} |
1923 | |
1924 | TypeTagData(QualType Type, bool LayoutCompatible, bool MustBeNull) |
1925 | : Type(Type), LayoutCompatible(LayoutCompatible), |
1926 | MustBeNull(MustBeNull) {} |
1927 | |
1928 | QualType Type; |
1929 | |
1930 | /// If true, \c Type should be compared with other expression's types for |
1931 | /// layout-compatibility. |
1932 | LLVM_PREFERRED_TYPE(bool) |
1933 | unsigned LayoutCompatible : 1; |
1934 | LLVM_PREFERRED_TYPE(bool) |
1935 | unsigned MustBeNull : 1; |
1936 | }; |
1937 | |
1938 | /// A pair of ArgumentKind identifier and magic value. This uniquely |
1939 | /// identifies the magic value. |
1940 | typedef std::pair<const IdentifierInfo *, uint64_t> TypeTagMagicValue; |
1941 | |
1942 | /// Diagnoses the current set of gathered accesses. This typically |
1943 | /// happens at full expression level. The set is cleared after emitting the |
1944 | /// diagnostics. |
1945 | void DiagnoseMisalignedMembers(); |
1946 | |
1947 | /// This function checks if the expression is in the sef of potentially |
1948 | /// misaligned members and it is converted to some pointer type T with lower |
1949 | /// or equal alignment requirements. If so it removes it. This is used when |
1950 | /// we do not want to diagnose such misaligned access (e.g. in conversions to |
1951 | /// void*). |
1952 | void DiscardMisalignedMemberAddress(const Type *T, Expr *E); |
1953 | |
1954 | /// This function calls Action when it determines that E designates a |
1955 | /// misaligned member due to the packed attribute. This is used to emit |
1956 | /// local diagnostics like in reference binding. |
1957 | void RefersToMemberWithReducedAlignment( |
1958 | Expr *E, |
1959 | llvm::function_ref<void(Expr *, RecordDecl *, FieldDecl *, CharUnits)> |
1960 | Action); |
1961 | |
1962 | enum class AtomicArgumentOrder { API, AST }; |
1963 | ExprResult |
1964 | BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, |
1965 | SourceLocation RParenLoc, MultiExprArg Args, |
1966 | AtomicExpr::AtomicOp Op, |
1967 | AtomicArgumentOrder ArgOrder = AtomicArgumentOrder::API); |
1968 | |
1969 | /// Check to see if a given expression could have '.c_str()' called on it. |
1970 | bool hasCStrMethod(const Expr *E); |
1971 | |
1972 | void DiagnoseAlwaysNonNullPointer(Expr *E, |
1973 | Expr::NullPointerConstantKind NullType, |
1974 | bool IsEqual, SourceRange Range); |
1975 | |
1976 | bool CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters, |
1977 | bool CheckParameterNames); |
1978 | |
1979 | void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); |
1980 | |
1981 | /// checkRetainCycles - Check whether an Objective-C message send |
1982 | /// might create an obvious retain cycle. |
1983 | void checkRetainCycles(ObjCMessageExpr *msg); |
1984 | void checkRetainCycles(Expr *receiver, Expr *argument); |
1985 | void checkRetainCycles(VarDecl *Var, Expr *Init); |
1986 | |
1987 | /// checkUnsafeAssigns - Check whether +1 expr is being assigned |
1988 | /// to weak/__unsafe_unretained type. |
1989 | bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); |
1990 | |
1991 | /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned |
1992 | /// to weak/__unsafe_unretained expression. |
1993 | void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); |
1994 | |
1995 | /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null |
1996 | /// statement as a \p Body, and it is located on the same line. |
1997 | /// |
1998 | /// This helps prevent bugs due to typos, such as: |
1999 | /// if (condition); |
2000 | /// do_stuff(); |
2001 | void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, const Stmt *Body, |
2002 | unsigned DiagID); |
2003 | |
2004 | /// Warn if a for/while loop statement \p S, which is followed by |
2005 | /// \p PossibleBody, has a suspicious null statement as a body. |
2006 | void DiagnoseEmptyLoopBody(const Stmt *S, const Stmt *PossibleBody); |
2007 | |
2008 | /// Warn if a value is moved to itself. |
2009 | void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr, |
2010 | SourceLocation OpLoc); |
2011 | |
2012 | // Used for emitting the right warning by DefaultVariadicArgumentPromotion |
2013 | enum VariadicCallType { |
2014 | VariadicFunction, |
2015 | VariadicBlock, |
2016 | VariadicMethod, |
2017 | VariadicConstructor, |
2018 | VariadicDoesNotApply |
2019 | }; |
2020 | |
2021 | bool IsLayoutCompatible(QualType T1, QualType T2) const; |
2022 | bool IsPointerInterconvertibleBaseOf(const TypeSourceInfo *Base, |
2023 | const TypeSourceInfo *Derived); |
2024 | |
2025 | bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, |
2026 | const FunctionProtoType *Proto); |
2027 | |
2028 | bool BuiltinVectorMath(CallExpr *TheCall, QualType &Res); |
2029 | bool BuiltinVectorToScalarMath(CallExpr *TheCall); |
2030 | |
2031 | bool CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
2032 | |
2033 | private: |
2034 | void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, |
2035 | const ArraySubscriptExpr *ASE = nullptr, |
2036 | bool AllowOnePastEnd = true, bool IndexNegated = false); |
2037 | void CheckArrayAccess(const Expr *E); |
2038 | |
2039 | bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc, |
2040 | ArrayRef<const Expr *> Args); |
2041 | bool CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall, |
2042 | const FunctionProtoType *Proto); |
2043 | bool CheckOtherCall(CallExpr *TheCall, const FunctionProtoType *Proto); |
2044 | void CheckConstructorCall(FunctionDecl *FDecl, QualType ThisType, |
2045 | ArrayRef<const Expr *> Args, |
2046 | const FunctionProtoType *Proto, SourceLocation Loc); |
2047 | |
2048 | void checkAIXMemberAlignment(SourceLocation Loc, const Expr *Arg); |
2049 | |
2050 | void CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl, |
2051 | StringRef ParamName, QualType ArgTy, QualType ParamTy); |
2052 | |
2053 | void checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, |
2054 | const Expr *ThisArg, ArrayRef<const Expr *> Args, |
2055 | bool IsMemberFunction, SourceLocation Loc, SourceRange Range, |
2056 | VariadicCallType CallType); |
2057 | |
2058 | bool CheckObjCString(Expr *Arg); |
2059 | ExprResult CheckOSLogFormatStringArg(Expr *Arg); |
2060 | |
2061 | ExprResult CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, |
2062 | CallExpr *TheCall); |
2063 | |
2064 | bool CheckTSBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
2065 | CallExpr *TheCall); |
2066 | |
2067 | void checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD, CallExpr *TheCall); |
2068 | |
2069 | bool CheckARMBuiltinExclusiveCall(unsigned BuiltinID, CallExpr *TheCall, |
2070 | unsigned MaxWidth); |
2071 | bool CheckNeonBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
2072 | CallExpr *TheCall); |
2073 | bool CheckMVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
2074 | bool CheckSVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
2075 | bool ParseSVEImmChecks(CallExpr *TheCall, |
2076 | SmallVector<std::tuple<int, int, int>, 3> &ImmChecks); |
2077 | bool CheckSMEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
2078 | bool CheckCDEBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
2079 | CallExpr *TheCall); |
2080 | bool CheckARMCoprocessorImmediate(const TargetInfo &TI, const Expr *CoprocArg, |
2081 | bool WantCDE); |
2082 | bool CheckARMBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
2083 | CallExpr *TheCall); |
2084 | |
2085 | bool CheckAArch64BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
2086 | CallExpr *TheCall); |
2087 | bool CheckBPFBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
2088 | bool CheckHexagonBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
2089 | bool CheckHexagonBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall); |
2090 | bool CheckMipsBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
2091 | CallExpr *TheCall); |
2092 | bool CheckMipsBuiltinCpu(const TargetInfo &TI, unsigned BuiltinID, |
2093 | CallExpr *TheCall); |
2094 | bool CheckMipsBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall); |
2095 | bool CheckSystemZBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
2096 | bool CheckX86BuiltinRoundingOrSAE(unsigned BuiltinID, CallExpr *TheCall); |
2097 | bool CheckX86BuiltinGatherScatterScale(unsigned BuiltinID, CallExpr *TheCall); |
2098 | bool CheckX86BuiltinTileArguments(unsigned BuiltinID, CallExpr *TheCall); |
2099 | bool CheckX86BuiltinTileArgumentsRange(CallExpr *TheCall, |
2100 | ArrayRef<int> ArgNums); |
2101 | bool CheckX86BuiltinTileDuplicate(CallExpr *TheCall, ArrayRef<int> ArgNums); |
2102 | bool CheckX86BuiltinTileRangeAndDuplicate(CallExpr *TheCall, |
2103 | ArrayRef<int> ArgNums); |
2104 | bool CheckX86BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
2105 | CallExpr *TheCall); |
2106 | bool CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
2107 | CallExpr *TheCall); |
2108 | bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
2109 | bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum); |
2110 | bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
2111 | CallExpr *TheCall); |
2112 | void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D, |
2113 | const llvm::StringMap<bool> &FeatureMap); |
2114 | bool CheckLoongArchBuiltinFunctionCall(const TargetInfo &TI, |
2115 | unsigned BuiltinID, CallExpr *TheCall); |
2116 | bool CheckWebAssemblyBuiltinFunctionCall(const TargetInfo &TI, |
2117 | unsigned BuiltinID, |
2118 | CallExpr *TheCall); |
2119 | bool CheckNVPTXBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
2120 | CallExpr *TheCall); |
2121 | |
2122 | bool BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall); |
2123 | bool BuiltinVAStartARMMicrosoft(CallExpr *Call); |
2124 | bool BuiltinUnorderedCompare(CallExpr *TheCall, unsigned BuiltinID); |
2125 | bool BuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs, |
2126 | unsigned BuiltinID); |
2127 | bool BuiltinComplex(CallExpr *TheCall); |
2128 | bool BuiltinVSX(CallExpr *TheCall); |
2129 | bool BuiltinOSLogFormat(CallExpr *TheCall); |
2130 | bool ValueIsRunOfOnes(CallExpr *TheCall, unsigned ArgNum); |
2131 | |
2132 | bool BuiltinPrefetch(CallExpr *TheCall); |
2133 | bool BuiltinAllocaWithAlign(CallExpr *TheCall); |
2134 | bool BuiltinArithmeticFence(CallExpr *TheCall); |
2135 | bool BuiltinAssume(CallExpr *TheCall); |
2136 | bool BuiltinAssumeAligned(CallExpr *TheCall); |
2137 | bool BuiltinLongjmp(CallExpr *TheCall); |
2138 | bool BuiltinSetjmp(CallExpr *TheCall); |
2139 | ExprResult BuiltinAtomicOverloaded(ExprResult TheCallResult); |
2140 | ExprResult BuiltinNontemporalOverloaded(ExprResult TheCallResult); |
2141 | ExprResult AtomicOpsOverloaded(ExprResult TheCallResult, |
2142 | AtomicExpr::AtomicOp Op); |
2143 | bool BuiltinConstantArg(CallExpr *TheCall, int ArgNum, llvm::APSInt &Result); |
2144 | bool BuiltinConstantArgRange(CallExpr *TheCall, int ArgNum, int Low, int High, |
2145 | bool RangeIsError = true); |
2146 | bool BuiltinConstantArgMultiple(CallExpr *TheCall, int ArgNum, |
2147 | unsigned Multiple); |
2148 | bool BuiltinConstantArgPower2(CallExpr *TheCall, int ArgNum); |
2149 | bool BuiltinConstantArgShiftedByte(CallExpr *TheCall, int ArgNum, |
2150 | unsigned ArgBits); |
2151 | bool BuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall, int ArgNum, |
2152 | unsigned ArgBits); |
2153 | bool BuiltinARMSpecialReg(unsigned BuiltinID, CallExpr *TheCall, int ArgNum, |
2154 | unsigned ExpectedFieldNum, bool AllowName); |
2155 | bool BuiltinARMMemoryTaggingCall(unsigned BuiltinID, CallExpr *TheCall); |
2156 | bool BuiltinPPCMMACall(CallExpr *TheCall, unsigned BuiltinID, |
2157 | const char *TypeDesc); |
2158 | |
2159 | bool CheckPPCMMAType(QualType Type, SourceLocation TypeLoc); |
2160 | |
2161 | bool BuiltinElementwiseMath(CallExpr *TheCall); |
2162 | bool BuiltinElementwiseTernaryMath(CallExpr *TheCall, |
2163 | bool CheckForFloatArgs = true); |
2164 | bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall); |
2165 | bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall); |
2166 | |
2167 | bool BuiltinNonDeterministicValue(CallExpr *TheCall); |
2168 | |
2169 | // Matrix builtin handling. |
2170 | ExprResult BuiltinMatrixTranspose(CallExpr *TheCall, ExprResult CallResult); |
2171 | ExprResult BuiltinMatrixColumnMajorLoad(CallExpr *TheCall, |
2172 | ExprResult CallResult); |
2173 | ExprResult BuiltinMatrixColumnMajorStore(CallExpr *TheCall, |
2174 | ExprResult CallResult); |
2175 | |
2176 | // WebAssembly builtin handling. |
2177 | bool BuiltinWasmRefNullExtern(CallExpr *TheCall); |
2178 | bool BuiltinWasmRefNullFunc(CallExpr *TheCall); |
2179 | bool BuiltinWasmTableGet(CallExpr *TheCall); |
2180 | bool BuiltinWasmTableSet(CallExpr *TheCall); |
2181 | bool BuiltinWasmTableSize(CallExpr *TheCall); |
2182 | bool BuiltinWasmTableGrow(CallExpr *TheCall); |
2183 | bool BuiltinWasmTableFill(CallExpr *TheCall); |
2184 | bool BuiltinWasmTableCopy(CallExpr *TheCall); |
2185 | |
2186 | bool CheckFormatArguments(const FormatAttr *Format, |
2187 | ArrayRef<const Expr *> Args, bool IsCXXMember, |
2188 | VariadicCallType CallType, SourceLocation Loc, |
2189 | SourceRange Range, |
2190 | llvm::SmallBitVector &CheckedVarArgs); |
2191 | bool CheckFormatArguments(ArrayRef<const Expr *> Args, |
2192 | FormatArgumentPassingKind FAPK, unsigned format_idx, |
2193 | unsigned firstDataArg, FormatStringType Type, |
2194 | VariadicCallType CallType, SourceLocation Loc, |
2195 | SourceRange range, |
2196 | llvm::SmallBitVector &CheckedVarArgs); |
2197 | |
2198 | void CheckInfNaNFunction(const CallExpr *Call, const FunctionDecl *FDecl); |
2199 | |
2200 | void CheckAbsoluteValueFunction(const CallExpr *Call, |
2201 | const FunctionDecl *FDecl); |
2202 | |
2203 | void CheckMaxUnsignedZero(const CallExpr *Call, const FunctionDecl *FDecl); |
2204 | |
2205 | void CheckMemaccessArguments(const CallExpr *Call, unsigned BId, |
2206 | IdentifierInfo *FnName); |
2207 | |
2208 | void CheckStrlcpycatArguments(const CallExpr *Call, IdentifierInfo *FnName); |
2209 | |
2210 | void CheckStrncatArguments(const CallExpr *Call, IdentifierInfo *FnName); |
2211 | |
2212 | void CheckFreeArguments(const CallExpr *E); |
2213 | |
2214 | void CheckReturnValExpr(Expr *RetValExp, QualType lhsType, |
2215 | SourceLocation ReturnLoc, bool isObjCMethod = false, |
2216 | const AttrVec *Attrs = nullptr, |
2217 | const FunctionDecl *FD = nullptr); |
2218 | |
2219 | void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); |
2220 | void CheckBoolLikeConversion(Expr *E, SourceLocation CC); |
2221 | void CheckForIntOverflow(const Expr *E); |
2222 | void CheckUnsequencedOperations(const Expr *E); |
2223 | |
2224 | /// Perform semantic checks on a completed expression. This will either |
2225 | /// be a full-expression or a default argument expression. |
2226 | void CheckCompletedExpr(Expr *E, SourceLocation CheckLoc = SourceLocation(), |
2227 | bool IsConstexpr = false); |
2228 | |
2229 | void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, |
2230 | Expr *Init); |
2231 | /// Check whether receiver is mutable ObjC container which |
2232 | /// attempts to add itself into the container |
2233 | void CheckObjCCircularContainer(ObjCMessageExpr *Message); |
2234 | |
2235 | void CheckTCBEnforcement(const SourceLocation CallExprLoc, |
2236 | const NamedDecl *Callee); |
2237 | |
2238 | /// A map from magic value to type information. |
2239 | std::unique_ptr<llvm::DenseMap<TypeTagMagicValue, TypeTagData>> |
2240 | TypeTagForDatatypeMagicValues; |
2241 | |
2242 | /// Peform checks on a call of a function with argument_with_type_tag |
2243 | /// or pointer_with_type_tag attributes. |
2244 | void CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr, |
2245 | const ArrayRef<const Expr *> ExprArgs, |
2246 | SourceLocation CallSiteLoc); |
2247 | |
2248 | /// Check if we are taking the address of a packed field |
2249 | /// as this may be a problem if the pointer value is dereferenced. |
2250 | void CheckAddressOfPackedMember(Expr *rhs); |
2251 | |
2252 | /// Helper class that collects misaligned member designations and |
2253 | /// their location info for delayed diagnostics. |
2254 | struct MisalignedMember { |
2255 | Expr *E; |
2256 | RecordDecl *RD; |
2257 | ValueDecl *MD; |
2258 | CharUnits Alignment; |
2259 | |
2260 | MisalignedMember() : E(), RD(), MD() {} |
2261 | MisalignedMember(Expr *E, RecordDecl *RD, ValueDecl *MD, |
2262 | CharUnits Alignment) |
2263 | : E(E), RD(RD), MD(MD), Alignment(Alignment) {} |
2264 | explicit MisalignedMember(Expr *E) |
2265 | : MisalignedMember(E, nullptr, nullptr, CharUnits()) {} |
2266 | |
2267 | bool operator==(const MisalignedMember &m) { return this->E == m.E; } |
2268 | }; |
2269 | /// Small set of gathered accesses to potentially misaligned members |
2270 | /// due to the packed attribute. |
2271 | SmallVector<MisalignedMember, 4> MisalignedMembers; |
2272 | |
2273 | /// Adds an expression to the set of gathered misaligned members. |
2274 | void AddPotentialMisalignedMembers(Expr *E, RecordDecl *RD, ValueDecl *MD, |
2275 | CharUnits Alignment); |
2276 | ///@} |
2277 | |
2278 | // |
2279 | // |
2280 | // ------------------------------------------------------------------------- |
2281 | // |
2282 | // |
2283 | |
2284 | /// \name C++ Coroutines |
2285 | /// Implementations are in SemaCoroutine.cpp |
2286 | ///@{ |
2287 | |
2288 | public: |
2289 | /// The C++ "std::coroutine_traits" template, which is defined in |
2290 | /// \<coroutine_traits> |
2291 | ClassTemplateDecl *StdCoroutineTraitsCache; |
2292 | |
2293 | bool ActOnCoroutineBodyStart(Scope *S, SourceLocation KwLoc, |
2294 | StringRef Keyword); |
2295 | ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
2296 | ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
2297 | StmtResult ActOnCoreturnStmt(Scope *S, SourceLocation KwLoc, Expr *E); |
2298 | |
2299 | ExprResult BuildOperatorCoawaitLookupExpr(Scope *S, SourceLocation Loc); |
2300 | ExprResult BuildOperatorCoawaitCall(SourceLocation Loc, Expr *E, |
2301 | UnresolvedLookupExpr *Lookup); |
2302 | ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, |
2303 | Expr *Awaiter, bool IsImplicit = false); |
2304 | ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, |
2305 | UnresolvedLookupExpr *Lookup); |
2306 | ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E); |
2307 | StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E, |
2308 | bool IsImplicit = false); |
2309 | StmtResult BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs); |
2310 | bool buildCoroutineParameterMoves(SourceLocation Loc); |
2311 | VarDecl *buildCoroutinePromise(SourceLocation Loc); |
2312 | void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body); |
2313 | |
2314 | // As a clang extension, enforces that a non-coroutine function must be marked |
2315 | // with [[clang::coro_wrapper]] if it returns a type marked with |
2316 | // [[clang::coro_return_type]]. |
2317 | // Expects that FD is not a coroutine. |
2318 | void CheckCoroutineWrapper(FunctionDecl *FD); |
2319 | /// Lookup 'coroutine_traits' in std namespace and std::experimental |
2320 | /// namespace. The namespace found is recorded in Namespace. |
2321 | ClassTemplateDecl *lookupCoroutineTraits(SourceLocation KwLoc, |
2322 | SourceLocation FuncLoc); |
2323 | /// Check that the expression co_await promise.final_suspend() shall not be |
2324 | /// potentially-throwing. |
2325 | bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend); |
2326 | |
2327 | ///@} |
2328 | |
2329 | // |
2330 | // |
2331 | // ------------------------------------------------------------------------- |
2332 | // |
2333 | // |
2334 | |
2335 | /// \name C++ Scope Specifiers |
2336 | /// Implementations are in SemaCXXScopeSpec.cpp |
2337 | ///@{ |
2338 | |
2339 | public: |
2340 | // Marks SS invalid if it represents an incomplete type. |
2341 | bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); |
2342 | // Complete an enum decl, maybe without a scope spec. |
2343 | bool RequireCompleteEnumDecl(EnumDecl *D, SourceLocation L, |
2344 | CXXScopeSpec *SS = nullptr); |
2345 | |
2346 | DeclContext *computeDeclContext(QualType T); |
2347 | DeclContext *computeDeclContext(const CXXScopeSpec &SS, |
2348 | bool EnteringContext = false); |
2349 | bool isDependentScopeSpecifier(const CXXScopeSpec &SS); |
2350 | CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); |
2351 | |
2352 | /// The parser has parsed a global nested-name-specifier '::'. |
2353 | /// |
2354 | /// \param CCLoc The location of the '::'. |
2355 | /// |
2356 | /// \param SS The nested-name-specifier, which will be updated in-place |
2357 | /// to reflect the parsed nested-name-specifier. |
2358 | /// |
2359 | /// \returns true if an error occurred, false otherwise. |
2360 | bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS); |
2361 | |
2362 | /// The parser has parsed a '__super' nested-name-specifier. |
2363 | /// |
2364 | /// \param SuperLoc The location of the '__super' keyword. |
2365 | /// |
2366 | /// \param ColonColonLoc The location of the '::'. |
2367 | /// |
2368 | /// \param SS The nested-name-specifier, which will be updated in-place |
2369 | /// to reflect the parsed nested-name-specifier. |
2370 | /// |
2371 | /// \returns true if an error occurred, false otherwise. |
2372 | bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc, |
2373 | SourceLocation ColonColonLoc, CXXScopeSpec &SS); |
2374 | |
2375 | bool isAcceptableNestedNameSpecifier(const NamedDecl *SD, |
2376 | bool *CanCorrect = nullptr); |
2377 | NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); |
2378 | |
2379 | /// Keeps information about an identifier in a nested-name-spec. |
2380 | /// |
2381 | struct NestedNameSpecInfo { |
2382 | /// The type of the object, if we're parsing nested-name-specifier in |
2383 | /// a member access expression. |
2384 | ParsedType ObjectType; |
2385 | |
2386 | /// The identifier preceding the '::'. |
2387 | IdentifierInfo *Identifier; |
2388 | |
2389 | /// The location of the identifier. |
2390 | SourceLocation IdentifierLoc; |
2391 | |
2392 | /// The location of the '::'. |
2393 | SourceLocation CCLoc; |
2394 | |
2395 | /// Creates info object for the most typical case. |
2396 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
2397 | SourceLocation ColonColonLoc, |
2398 | ParsedType ObjectType = ParsedType()) |
2399 | : ObjectType(ObjectType), Identifier(II), IdentifierLoc(IdLoc), |
2400 | CCLoc(ColonColonLoc) {} |
2401 | |
2402 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
2403 | SourceLocation ColonColonLoc, QualType ObjectType) |
2404 | : ObjectType(ParsedType::make(P: ObjectType)), Identifier(II), |
2405 | IdentifierLoc(IdLoc), CCLoc(ColonColonLoc) {} |
2406 | }; |
2407 | |
2408 | bool BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo, |
2409 | bool EnteringContext, CXXScopeSpec &SS, |
2410 | NamedDecl *ScopeLookupResult, |
2411 | bool ErrorRecoveryLookup, |
2412 | bool *IsCorrectedToColon = nullptr, |
2413 | bool OnlyNamespace = false); |
2414 | |
2415 | /// The parser has parsed a nested-name-specifier 'identifier::'. |
2416 | /// |
2417 | /// \param S The scope in which this nested-name-specifier occurs. |
2418 | /// |
2419 | /// \param IdInfo Parser information about an identifier in the |
2420 | /// nested-name-spec. |
2421 | /// |
2422 | /// \param EnteringContext Whether we're entering the context nominated by |
2423 | /// this nested-name-specifier. |
2424 | /// |
2425 | /// \param SS The nested-name-specifier, which is both an input |
2426 | /// parameter (the nested-name-specifier before this type) and an |
2427 | /// output parameter (containing the full nested-name-specifier, |
2428 | /// including this new type). |
2429 | /// |
2430 | /// \param IsCorrectedToColon If not null, suggestions to replace '::' -> ':' |
2431 | /// are allowed. The bool value pointed by this parameter is set to 'true' |
2432 | /// if the identifier is treated as if it was followed by ':', not '::'. |
2433 | /// |
2434 | /// \param OnlyNamespace If true, only considers namespaces in lookup. |
2435 | /// |
2436 | /// \returns true if an error occurred, false otherwise. |
2437 | bool ActOnCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo, |
2438 | bool EnteringContext, CXXScopeSpec &SS, |
2439 | bool *IsCorrectedToColon = nullptr, |
2440 | bool OnlyNamespace = false); |
2441 | |
2442 | /// The parser has parsed a nested-name-specifier |
2443 | /// 'template[opt] template-name < template-args >::'. |
2444 | /// |
2445 | /// \param S The scope in which this nested-name-specifier occurs. |
2446 | /// |
2447 | /// \param SS The nested-name-specifier, which is both an input |
2448 | /// parameter (the nested-name-specifier before this type) and an |
2449 | /// output parameter (containing the full nested-name-specifier, |
2450 | /// including this new type). |
2451 | /// |
2452 | /// \param TemplateKWLoc the location of the 'template' keyword, if any. |
2453 | /// \param TemplateName the template name. |
2454 | /// \param TemplateNameLoc The location of the template name. |
2455 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
2456 | /// \param TemplateArgs The template arguments. |
2457 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
2458 | /// \param CCLoc The location of the '::'. |
2459 | /// |
2460 | /// \param EnteringContext Whether we're entering the context of the |
2461 | /// nested-name-specifier. |
2462 | /// |
2463 | /// |
2464 | /// \returns true if an error occurred, false otherwise. |
2465 | bool ActOnCXXNestedNameSpecifier( |
2466 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
2467 | TemplateTy TemplateName, SourceLocation TemplateNameLoc, |
2468 | SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, |
2469 | SourceLocation RAngleLoc, SourceLocation CCLoc, bool EnteringContext); |
2470 | |
2471 | bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, const DeclSpec &DS, |
2472 | SourceLocation ColonColonLoc); |
2473 | |
2474 | bool ActOnCXXNestedNameSpecifierIndexedPack(CXXScopeSpec &SS, |
2475 | const DeclSpec &DS, |
2476 | SourceLocation ColonColonLoc, |
2477 | QualType Type); |
2478 | |
2479 | bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, |
2480 | NestedNameSpecInfo &IdInfo, |
2481 | bool EnteringContext); |
2482 | |
2483 | /// Given a C++ nested-name-specifier, produce an annotation value |
2484 | /// that the parser can use later to reconstruct the given |
2485 | /// nested-name-specifier. |
2486 | /// |
2487 | /// \param SS A nested-name-specifier. |
2488 | /// |
2489 | /// \returns A pointer containing all of the information in the |
2490 | /// nested-name-specifier \p SS. |
2491 | void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); |
2492 | |
2493 | /// Given an annotation pointer for a nested-name-specifier, restore |
2494 | /// the nested-name-specifier structure. |
2495 | /// |
2496 | /// \param Annotation The annotation pointer, produced by |
2497 | /// \c SaveNestedNameSpecifierAnnotation(). |
2498 | /// |
2499 | /// \param AnnotationRange The source range corresponding to the annotation. |
2500 | /// |
2501 | /// \param SS The nested-name-specifier that will be updated with the contents |
2502 | /// of the annotation pointer. |
2503 | void RestoreNestedNameSpecifierAnnotation(void *Annotation, |
2504 | SourceRange AnnotationRange, |
2505 | CXXScopeSpec &SS); |
2506 | |
2507 | bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
2508 | |
2509 | /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global |
2510 | /// scope or nested-name-specifier) is parsed, part of a declarator-id. |
2511 | /// After this method is called, according to [C++ 3.4.3p3], names should be |
2512 | /// looked up in the declarator-id's scope, until the declarator is parsed and |
2513 | /// ActOnCXXExitDeclaratorScope is called. |
2514 | /// The 'SS' should be a non-empty valid CXXScopeSpec. |
2515 | bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); |
2516 | |
2517 | /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously |
2518 | /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same |
2519 | /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. |
2520 | /// Used to indicate that names should revert to being looked up in the |
2521 | /// defining scope. |
2522 | void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
2523 | |
2524 | ///@} |
2525 | |
2526 | // |
2527 | // |
2528 | // ------------------------------------------------------------------------- |
2529 | // |
2530 | // |
2531 | |
2532 | /// \name Declarations |
2533 | /// Implementations are in SemaDecl.cpp |
2534 | ///@{ |
2535 | |
2536 | public: |
2537 | IdentifierResolver IdResolver; |
2538 | |
2539 | /// The index of the first InventedParameterInfo that refers to the current |
2540 | /// context. |
2541 | unsigned InventedParameterInfosStart = 0; |
2542 | |
2543 | /// A RAII object to temporarily push a declaration context. |
2544 | class { |
2545 | private: |
2546 | Sema &; |
2547 | DeclContext *; |
2548 | ProcessingContextState ; |
2549 | QualType ; |
2550 | unsigned ; |
2551 | unsigned ; |
2552 | |
2553 | public: |
2554 | (Sema &S, DeclContext *ContextToPush, bool NewThisContext = true) |
2555 | : S(S), SavedContext(S.CurContext), |
2556 | SavedContextState(S.DelayedDiagnostics.pushUndelayed()), |
2557 | SavedCXXThisTypeOverride(S.CXXThisTypeOverride), |
2558 | SavedFunctionScopesStart(S.FunctionScopesStart), |
2559 | SavedInventedParameterInfosStart(S.InventedParameterInfosStart) { |
2560 | assert(ContextToPush && "pushing null context" ); |
2561 | S.CurContext = ContextToPush; |
2562 | if (NewThisContext) |
2563 | S.CXXThisTypeOverride = QualType(); |
2564 | // Any saved FunctionScopes do not refer to this context. |
2565 | S.FunctionScopesStart = S.FunctionScopes.size(); |
2566 | S.InventedParameterInfosStart = S.InventedParameterInfos.size(); |
2567 | } |
2568 | |
2569 | void () { |
2570 | if (!SavedContext) |
2571 | return; |
2572 | S.CurContext = SavedContext; |
2573 | S.DelayedDiagnostics.popUndelayed(state: SavedContextState); |
2574 | S.CXXThisTypeOverride = SavedCXXThisTypeOverride; |
2575 | S.FunctionScopesStart = SavedFunctionScopesStart; |
2576 | S.InventedParameterInfosStart = SavedInventedParameterInfosStart; |
2577 | SavedContext = nullptr; |
2578 | } |
2579 | |
2580 | () { pop(); } |
2581 | }; |
2582 | |
2583 | void DiagnoseInvalidJumps(Stmt *Body); |
2584 | |
2585 | /// The function definitions which were renamed as part of typo-correction |
2586 | /// to match their respective declarations. We want to keep track of them |
2587 | /// to ensure that we don't emit a "redefinition" error if we encounter a |
2588 | /// correctly named definition after the renamed definition. |
2589 | llvm::SmallPtrSet<const NamedDecl *, 4> TypoCorrectedFunctionDefinitions; |
2590 | |
2591 | /// A cache of the flags available in enumerations with the flag_bits |
2592 | /// attribute. |
2593 | mutable llvm::DenseMap<const EnumDecl *, llvm::APInt> FlagBitsCache; |
2594 | |
2595 | /// WeakUndeclaredIdentifiers - Identifiers contained in \#pragma weak before |
2596 | /// declared. Rare. May alias another identifier, declared or undeclared. |
2597 | /// |
2598 | /// For aliases, the target identifier is used as a key for eventual |
2599 | /// processing when the target is declared. For the single-identifier form, |
2600 | /// the sole identifier is used as the key. Each entry is a `SetVector` |
2601 | /// (ordered by parse order) of aliases (identified by the alias name) in case |
2602 | /// of multiple aliases to the same undeclared identifier. |
2603 | llvm::MapVector< |
2604 | IdentifierInfo *, |
2605 | llvm::SetVector< |
2606 | WeakInfo, llvm::SmallVector<WeakInfo, 1u>, |
2607 | llvm::SmallDenseSet<WeakInfo, 2u, WeakInfo::DenseMapInfoByAliasOnly>>> |
2608 | WeakUndeclaredIdentifiers; |
2609 | |
2610 | /// ExtnameUndeclaredIdentifiers - Identifiers contained in |
2611 | /// \#pragma redefine_extname before declared. Used in Solaris system headers |
2612 | /// to define functions that occur in multiple standards to call the version |
2613 | /// in the currently selected standard. |
2614 | llvm::DenseMap<IdentifierInfo *, AsmLabelAttr *> ExtnameUndeclaredIdentifiers; |
2615 | |
2616 | /// Set containing all typedefs that are likely unused. |
2617 | llvm::SmallSetVector<const TypedefNameDecl *, 4> |
2618 | UnusedLocalTypedefNameCandidates; |
2619 | |
2620 | typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource, |
2621 | &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2> |
2622 | UnusedFileScopedDeclsType; |
2623 | |
2624 | /// The set of file scoped decls seen so far that have not been used |
2625 | /// and must warn if not used. Only contains the first declaration. |
2626 | UnusedFileScopedDeclsType UnusedFileScopedDecls; |
2627 | |
2628 | typedef LazyVector<VarDecl *, ExternalSemaSource, |
2629 | &ExternalSemaSource::ReadTentativeDefinitions, 2, 2> |
2630 | TentativeDefinitionsType; |
2631 | |
2632 | /// All the tentative definitions encountered in the TU. |
2633 | TentativeDefinitionsType TentativeDefinitions; |
2634 | |
2635 | /// All the external declarations encoutered and used in the TU. |
2636 | SmallVector<VarDecl *, 4> ExternalDeclarations; |
2637 | |
2638 | /// Generally null except when we temporarily switch decl contexts, |
2639 | /// like in \see ActOnObjCTemporaryExitContainerContext. |
2640 | DeclContext *OriginalLexicalContext; |
2641 | |
2642 | /// Is the module scope we are in a C++ Header Unit? |
2643 | bool () const { |
2644 | return ModuleScopes.empty() ? false |
2645 | : ModuleScopes.back().Module->isHeaderUnit(); |
2646 | } |
2647 | |
2648 | /// Get the module owning an entity. |
2649 | Module *getOwningModule(const Decl *Entity) { |
2650 | return Entity->getOwningModule(); |
2651 | } |
2652 | |
2653 | DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr); |
2654 | |
2655 | ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, |
2656 | Scope *S, CXXScopeSpec *SS = nullptr, |
2657 | bool isClassName = false, bool HasTrailingDot = false, |
2658 | ParsedType ObjectType = nullptr, |
2659 | bool IsCtorOrDtorName = false, |
2660 | bool WantNontrivialTypeSourceInfo = false, |
2661 | bool IsClassTemplateDeductionContext = true, |
2662 | ImplicitTypenameContext AllowImplicitTypename = |
2663 | ImplicitTypenameContext::No, |
2664 | IdentifierInfo **CorrectedII = nullptr); |
2665 | TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S); |
2666 | bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S); |
2667 | void DiagnoseUnknownTypeName(IdentifierInfo *&II, SourceLocation IILoc, |
2668 | Scope *S, CXXScopeSpec *SS, |
2669 | ParsedType &SuggestedType, |
2670 | bool IsTemplateName = false); |
2671 | |
2672 | /// Attempt to behave like MSVC in situations where lookup of an unqualified |
2673 | /// type name has failed in a dependent context. In these situations, we |
2674 | /// automatically form a DependentTypeName that will retry lookup in a related |
2675 | /// scope during instantiation. |
2676 | ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II, |
2677 | SourceLocation NameLoc, |
2678 | bool IsTemplateTypeArg); |
2679 | |
2680 | /// Describes the result of the name lookup and resolution performed |
2681 | /// by \c ClassifyName(). |
2682 | enum NameClassificationKind { |
2683 | /// This name is not a type or template in this context, but might be |
2684 | /// something else. |
2685 | NC_Unknown, |
2686 | /// Classification failed; an error has been produced. |
2687 | NC_Error, |
2688 | /// The name has been typo-corrected to a keyword. |
2689 | NC_Keyword, |
2690 | /// The name was classified as a type. |
2691 | NC_Type, |
2692 | /// The name was classified as a specific non-type, non-template |
2693 | /// declaration. ActOnNameClassifiedAsNonType should be called to |
2694 | /// convert the declaration to an expression. |
2695 | NC_NonType, |
2696 | /// The name was classified as an ADL-only function name. |
2697 | /// ActOnNameClassifiedAsUndeclaredNonType should be called to convert the |
2698 | /// result to an expression. |
2699 | NC_UndeclaredNonType, |
2700 | /// The name denotes a member of a dependent type that could not be |
2701 | /// resolved. ActOnNameClassifiedAsDependentNonType should be called to |
2702 | /// convert the result to an expression. |
2703 | NC_DependentNonType, |
2704 | /// The name was classified as an overload set, and an expression |
2705 | /// representing that overload set has been formed. |
2706 | /// ActOnNameClassifiedAsOverloadSet should be called to form a suitable |
2707 | /// expression referencing the overload set. |
2708 | NC_OverloadSet, |
2709 | /// The name was classified as a template whose specializations are types. |
2710 | NC_TypeTemplate, |
2711 | /// The name was classified as a variable template name. |
2712 | NC_VarTemplate, |
2713 | /// The name was classified as a function template name. |
2714 | NC_FunctionTemplate, |
2715 | /// The name was classified as an ADL-only function template name. |
2716 | NC_UndeclaredTemplate, |
2717 | /// The name was classified as a concept name. |
2718 | NC_Concept, |
2719 | }; |
2720 | |
2721 | class NameClassification { |
2722 | NameClassificationKind Kind; |
2723 | union { |
2724 | ExprResult Expr; |
2725 | NamedDecl *NonTypeDecl; |
2726 | TemplateName Template; |
2727 | ParsedType Type; |
2728 | }; |
2729 | |
2730 | explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {} |
2731 | |
2732 | public: |
2733 | NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {} |
2734 | |
2735 | NameClassification(const IdentifierInfo *Keyword) : Kind(NC_Keyword) {} |
2736 | |
2737 | static NameClassification Error() { return NameClassification(NC_Error); } |
2738 | |
2739 | static NameClassification Unknown() { |
2740 | return NameClassification(NC_Unknown); |
2741 | } |
2742 | |
2743 | static NameClassification OverloadSet(ExprResult E) { |
2744 | NameClassification Result(NC_OverloadSet); |
2745 | Result.Expr = E; |
2746 | return Result; |
2747 | } |
2748 | |
2749 | static NameClassification NonType(NamedDecl *D) { |
2750 | NameClassification Result(NC_NonType); |
2751 | Result.NonTypeDecl = D; |
2752 | return Result; |
2753 | } |
2754 | |
2755 | static NameClassification UndeclaredNonType() { |
2756 | return NameClassification(NC_UndeclaredNonType); |
2757 | } |
2758 | |
2759 | static NameClassification DependentNonType() { |
2760 | return NameClassification(NC_DependentNonType); |
2761 | } |
2762 | |
2763 | static NameClassification TypeTemplate(TemplateName Name) { |
2764 | NameClassification Result(NC_TypeTemplate); |
2765 | Result.Template = Name; |
2766 | return Result; |
2767 | } |
2768 | |
2769 | static NameClassification VarTemplate(TemplateName Name) { |
2770 | NameClassification Result(NC_VarTemplate); |
2771 | Result.Template = Name; |
2772 | return Result; |
2773 | } |
2774 | |
2775 | static NameClassification FunctionTemplate(TemplateName Name) { |
2776 | NameClassification Result(NC_FunctionTemplate); |
2777 | Result.Template = Name; |
2778 | return Result; |
2779 | } |
2780 | |
2781 | static NameClassification Concept(TemplateName Name) { |
2782 | NameClassification Result(NC_Concept); |
2783 | Result.Template = Name; |
2784 | return Result; |
2785 | } |
2786 | |
2787 | static NameClassification UndeclaredTemplate(TemplateName Name) { |
2788 | NameClassification Result(NC_UndeclaredTemplate); |
2789 | Result.Template = Name; |
2790 | return Result; |
2791 | } |
2792 | |
2793 | NameClassificationKind getKind() const { return Kind; } |
2794 | |
2795 | ExprResult getExpression() const { |
2796 | assert(Kind == NC_OverloadSet); |
2797 | return Expr; |
2798 | } |
2799 | |
2800 | ParsedType getType() const { |
2801 | assert(Kind == NC_Type); |
2802 | return Type; |
2803 | } |
2804 | |
2805 | NamedDecl *getNonTypeDecl() const { |
2806 | assert(Kind == NC_NonType); |
2807 | return NonTypeDecl; |
2808 | } |
2809 | |
2810 | TemplateName getTemplateName() const { |
2811 | assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || |
2812 | Kind == NC_VarTemplate || Kind == NC_Concept || |
2813 | Kind == NC_UndeclaredTemplate); |
2814 | return Template; |
2815 | } |
2816 | |
2817 | TemplateNameKind getTemplateNameKind() const { |
2818 | switch (Kind) { |
2819 | case NC_TypeTemplate: |
2820 | return TNK_Type_template; |
2821 | case NC_FunctionTemplate: |
2822 | return TNK_Function_template; |
2823 | case NC_VarTemplate: |
2824 | return TNK_Var_template; |
2825 | case NC_Concept: |
2826 | return TNK_Concept_template; |
2827 | case NC_UndeclaredTemplate: |
2828 | return TNK_Undeclared_template; |
2829 | default: |
2830 | llvm_unreachable("unsupported name classification." ); |
2831 | } |
2832 | } |
2833 | }; |
2834 | |
2835 | /// Perform name lookup on the given name, classifying it based on |
2836 | /// the results of name lookup and the following token. |
2837 | /// |
2838 | /// This routine is used by the parser to resolve identifiers and help direct |
2839 | /// parsing. When the identifier cannot be found, this routine will attempt |
2840 | /// to correct the typo and classify based on the resulting name. |
2841 | /// |
2842 | /// \param S The scope in which we're performing name lookup. |
2843 | /// |
2844 | /// \param SS The nested-name-specifier that precedes the name. |
2845 | /// |
2846 | /// \param Name The identifier. If typo correction finds an alternative name, |
2847 | /// this pointer parameter will be updated accordingly. |
2848 | /// |
2849 | /// \param NameLoc The location of the identifier. |
2850 | /// |
2851 | /// \param NextToken The token following the identifier. Used to help |
2852 | /// disambiguate the name. |
2853 | /// |
2854 | /// \param CCC The correction callback, if typo correction is desired. |
2855 | NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS, |
2856 | IdentifierInfo *&Name, SourceLocation NameLoc, |
2857 | const Token &NextToken, |
2858 | CorrectionCandidateCallback *CCC = nullptr); |
2859 | |
2860 | /// Act on the result of classifying a name as an undeclared (ADL-only) |
2861 | /// non-type declaration. |
2862 | ExprResult ActOnNameClassifiedAsUndeclaredNonType(IdentifierInfo *Name, |
2863 | SourceLocation NameLoc); |
2864 | /// Act on the result of classifying a name as an undeclared member of a |
2865 | /// dependent base class. |
2866 | ExprResult ActOnNameClassifiedAsDependentNonType(const CXXScopeSpec &SS, |
2867 | IdentifierInfo *Name, |
2868 | SourceLocation NameLoc, |
2869 | bool IsAddressOfOperand); |
2870 | /// Act on the result of classifying a name as a specific non-type |
2871 | /// declaration. |
2872 | ExprResult ActOnNameClassifiedAsNonType(Scope *S, const CXXScopeSpec &SS, |
2873 | NamedDecl *Found, |
2874 | SourceLocation NameLoc, |
2875 | const Token &NextToken); |
2876 | /// Act on the result of classifying a name as an overload set. |
2877 | ExprResult ActOnNameClassifiedAsOverloadSet(Scope *S, Expr *OverloadSet); |
2878 | |
2879 | /// Describes the detailed kind of a template name. Used in diagnostics. |
2880 | enum class TemplateNameKindForDiagnostics { |
2881 | ClassTemplate, |
2882 | FunctionTemplate, |
2883 | VarTemplate, |
2884 | AliasTemplate, |
2885 | TemplateTemplateParam, |
2886 | Concept, |
2887 | DependentTemplate |
2888 | }; |
2889 | TemplateNameKindForDiagnostics |
2890 | getTemplateNameKindForDiagnostics(TemplateName Name); |
2891 | |
2892 | /// Determine whether it's plausible that E was intended to be a |
2893 | /// template-name. |
2894 | bool mightBeIntendedToBeTemplateName(ExprResult E, bool &Dependent) { |
2895 | if (!getLangOpts().CPlusPlus || E.isInvalid()) |
2896 | return false; |
2897 | Dependent = false; |
2898 | if (auto *DRE = dyn_cast<DeclRefExpr>(Val: E.get())) |
2899 | return !DRE->hasExplicitTemplateArgs(); |
2900 | if (auto *ME = dyn_cast<MemberExpr>(Val: E.get())) |
2901 | return !ME->hasExplicitTemplateArgs(); |
2902 | Dependent = true; |
2903 | if (auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(Val: E.get())) |
2904 | return !DSDRE->hasExplicitTemplateArgs(); |
2905 | if (auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(Val: E.get())) |
2906 | return !DSME->hasExplicitTemplateArgs(); |
2907 | // Any additional cases recognized here should also be handled by |
2908 | // diagnoseExprIntendedAsTemplateName. |
2909 | return false; |
2910 | } |
2911 | |
2912 | void warnOnReservedIdentifier(const NamedDecl *D); |
2913 | |
2914 | Decl *ActOnDeclarator(Scope *S, Declarator &D); |
2915 | |
2916 | NamedDecl *HandleDeclarator(Scope *S, Declarator &D, |
2917 | MultiTemplateParamsArg TemplateParameterLists); |
2918 | bool tryToFixVariablyModifiedVarType(TypeSourceInfo *&TInfo, QualType &T, |
2919 | SourceLocation Loc, |
2920 | unsigned FailedFoldDiagID); |
2921 | void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S); |
2922 | bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info); |
2923 | bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, |
2924 | DeclarationName Name, SourceLocation Loc, |
2925 | TemplateIdAnnotation *TemplateId, |
2926 | bool IsMemberSpecialization); |
2927 | |
2928 | bool checkConstantPointerAuthKey(Expr *keyExpr, unsigned &key); |
2929 | |
2930 | void DiagnoseFunctionSpecifiers(const DeclSpec &DS); |
2931 | NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D, |
2932 | const LookupResult &R); |
2933 | NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult &R); |
2934 | NamedDecl *getShadowedDeclaration(const BindingDecl *D, |
2935 | const LookupResult &R); |
2936 | void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl, |
2937 | const LookupResult &R); |
2938 | void CheckShadow(Scope *S, VarDecl *D); |
2939 | |
2940 | /// Warn if 'E', which is an expression that is about to be modified, refers |
2941 | /// to a shadowing declaration. |
2942 | void CheckShadowingDeclModification(Expr *E, SourceLocation Loc); |
2943 | |
2944 | void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI); |
2945 | |
2946 | void handleTagNumbering(const TagDecl *Tag, Scope *TagScope); |
2947 | void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec, |
2948 | TypedefNameDecl *NewTD); |
2949 | void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D); |
2950 | NamedDecl *ActOnTypedefDeclarator(Scope *S, Declarator &D, DeclContext *DC, |
2951 | TypeSourceInfo *TInfo, |
2952 | LookupResult &Previous); |
2953 | NamedDecl *ActOnTypedefNameDecl(Scope *S, DeclContext *DC, TypedefNameDecl *D, |
2954 | LookupResult &Previous, bool &Redeclaration); |
2955 | NamedDecl *ActOnVariableDeclarator( |
2956 | Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, |
2957 | LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists, |
2958 | bool &AddToScope, ArrayRef<BindingDecl *> Bindings = std::nullopt); |
2959 | |
2960 | // Returns true if the variable declaration is a redeclaration |
2961 | bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous); |
2962 | void CheckVariableDeclarationType(VarDecl *NewVD); |
2963 | void CheckCompleteVariableDeclaration(VarDecl *VD); |
2964 | |
2965 | NamedDecl *ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, |
2966 | TypeSourceInfo *TInfo, |
2967 | LookupResult &Previous, |
2968 | MultiTemplateParamsArg TemplateParamLists, |
2969 | bool &AddToScope); |
2970 | bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); |
2971 | |
2972 | // Returns true if the function declaration is a redeclaration |
2973 | bool CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, |
2974 | LookupResult &Previous, |
2975 | bool IsMemberSpecialization, bool DeclIsDefn); |
2976 | bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl); |
2977 | bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD, |
2978 | QualType NewT, QualType OldT); |
2979 | void CheckMain(FunctionDecl *FD, const DeclSpec &D); |
2980 | void CheckMSVCRTEntryPoint(FunctionDecl *FD); |
2981 | Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, |
2982 | bool IsDefinition); |
2983 | void CheckFunctionOrTemplateParamDeclarator(Scope *S, Declarator &D); |
2984 | Decl *ActOnParamDeclarator(Scope *S, Declarator &D, |
2985 | SourceLocation ExplicitThisLoc = {}); |
2986 | ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, SourceLocation Loc, |
2987 | QualType T); |
2988 | QualType AdjustParameterTypeForObjCAutoRefCount(QualType T, |
2989 | SourceLocation NameLoc, |
2990 | TypeSourceInfo *TSInfo); |
2991 | ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc, |
2992 | SourceLocation NameLoc, |
2993 | const IdentifierInfo *Name, QualType T, |
2994 | TypeSourceInfo *TSInfo, StorageClass SC); |
2995 | |
2996 | // Contexts where using non-trivial C union types can be disallowed. This is |
2997 | // passed to err_non_trivial_c_union_in_invalid_context. |
2998 | enum NonTrivialCUnionContext { |
2999 | // Function parameter. |
3000 | NTCUC_FunctionParam, |
3001 | // Function return. |
3002 | NTCUC_FunctionReturn, |
3003 | // Default-initialized object. |
3004 | NTCUC_DefaultInitializedObject, |
3005 | // Variable with automatic storage duration. |
3006 | NTCUC_AutoVar, |
3007 | // Initializer expression that might copy from another object. |
3008 | NTCUC_CopyInit, |
3009 | // Assignment. |
3010 | NTCUC_Assignment, |
3011 | // Compound literal. |
3012 | NTCUC_CompoundLiteral, |
3013 | // Block capture. |
3014 | NTCUC_BlockCapture, |
3015 | // lvalue-to-rvalue conversion of volatile type. |
3016 | NTCUC_LValueToRValueVolatile, |
3017 | }; |
3018 | |
3019 | /// Emit diagnostics if the initializer or any of its explicit or |
3020 | /// implicitly-generated subexpressions require copying or |
3021 | /// default-initializing a type that is or contains a C union type that is |
3022 | /// non-trivial to copy or default-initialize. |
3023 | void checkNonTrivialCUnionInInitializer(const Expr *Init, SourceLocation Loc); |
3024 | |
3025 | // These flags are passed to checkNonTrivialCUnion. |
3026 | enum NonTrivialCUnionKind { |
3027 | NTCUK_Init = 0x1, |
3028 | NTCUK_Destruct = 0x2, |
3029 | NTCUK_Copy = 0x4, |
3030 | }; |
3031 | |
3032 | /// Emit diagnostics if a non-trivial C union type or a struct that contains |
3033 | /// a non-trivial C union is used in an invalid context. |
3034 | void checkNonTrivialCUnion(QualType QT, SourceLocation Loc, |
3035 | NonTrivialCUnionContext UseContext, |
3036 | unsigned NonTrivialKind); |
3037 | |
3038 | void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit); |
3039 | void ActOnUninitializedDecl(Decl *dcl); |
3040 | void ActOnInitializerError(Decl *Dcl); |
3041 | |
3042 | void ActOnCXXForRangeDecl(Decl *D); |
3043 | StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, |
3044 | IdentifierInfo *Ident, |
3045 | ParsedAttributes &Attrs); |
3046 | |
3047 | void CheckStaticLocalForDllExport(VarDecl *VD); |
3048 | void CheckThreadLocalForLargeAlignment(VarDecl *VD); |
3049 | void FinalizeDeclaration(Decl *D); |
3050 | DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, |
3051 | ArrayRef<Decl *> Group); |
3052 | DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group); |
3053 | |
3054 | /// Should be called on all declarations that might have attached |
3055 | /// documentation comments. |
3056 | void ActOnDocumentableDecl(Decl *D); |
3057 | void ActOnDocumentableDecls(ArrayRef<Decl *> Group); |
3058 | |
3059 | enum class FnBodyKind { |
3060 | /// C++26 [dcl.fct.def.general]p1 |
3061 | /// function-body: |
3062 | /// ctor-initializer[opt] compound-statement |
3063 | /// function-try-block |
3064 | Other, |
3065 | /// = default ; |
3066 | Default, |
3067 | /// deleted-function-body |
3068 | /// |
3069 | /// deleted-function-body: |
3070 | /// = delete ; |
3071 | /// = delete ( unevaluated-string ) ; |
3072 | Delete |
3073 | }; |
3074 | |
3075 | void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, |
3076 | SourceLocation LocAfterDecls); |
3077 | void CheckForFunctionRedefinition( |
3078 | FunctionDecl *FD, const FunctionDecl *EffectiveDefinition = nullptr, |
3079 | SkipBodyInfo *SkipBody = nullptr); |
3080 | Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D, |
3081 | MultiTemplateParamsArg TemplateParamLists, |
3082 | SkipBodyInfo *SkipBody = nullptr, |
3083 | FnBodyKind BodyKind = FnBodyKind::Other); |
3084 | Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D, |
3085 | SkipBodyInfo *SkipBody = nullptr, |
3086 | FnBodyKind BodyKind = FnBodyKind::Other); |
3087 | void applyFunctionAttributesBeforeParsingBody(Decl *FD); |
3088 | |
3089 | /// Determine whether we can delay parsing the body of a function or |
3090 | /// function template until it is used, assuming we don't care about emitting |
3091 | /// code for that function. |
3092 | /// |
3093 | /// This will be \c false if we may need the body of the function in the |
3094 | /// middle of parsing an expression (where it's impractical to switch to |
3095 | /// parsing a different function), for instance, if it's constexpr in C++11 |
3096 | /// or has an 'auto' return type in C++14. These cases are essentially bugs. |
3097 | bool canDelayFunctionBody(const Declarator &D); |
3098 | |
3099 | /// Determine whether we can skip parsing the body of a function |
3100 | /// definition, assuming we don't care about analyzing its body or emitting |
3101 | /// code for that function. |
3102 | /// |
3103 | /// This will be \c false only if we may need the body of the function in |
3104 | /// order to parse the rest of the program (for instance, if it is |
3105 | /// \c constexpr in C++11 or has an 'auto' return type in C++14). |
3106 | bool canSkipFunctionBody(Decl *D); |
3107 | |
3108 | void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope); |
3109 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body); |
3110 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation); |
3111 | Decl *ActOnSkippedFunctionBody(Decl *Decl); |
3112 | void ActOnFinishInlineFunctionDef(FunctionDecl *D); |
3113 | |
3114 | /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an |
3115 | /// attribute for which parsing is delayed. |
3116 | void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs); |
3117 | |
3118 | /// Diagnose any unused parameters in the given sequence of |
3119 | /// ParmVarDecl pointers. |
3120 | void DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters); |
3121 | |
3122 | /// Diagnose whether the size of parameters or return value of a |
3123 | /// function or obj-c method definition is pass-by-value and larger than a |
3124 | /// specified threshold. |
3125 | void |
3126 | DiagnoseSizeOfParametersAndReturnValue(ArrayRef<ParmVarDecl *> Parameters, |
3127 | QualType ReturnTy, NamedDecl *D); |
3128 | |
3129 | Decl *ActOnFileScopeAsmDecl(Expr *expr, SourceLocation AsmLoc, |
3130 | SourceLocation RParenLoc); |
3131 | |
3132 | TopLevelStmtDecl *ActOnStartTopLevelStmtDecl(Scope *S); |
3133 | void ActOnFinishTopLevelStmtDecl(TopLevelStmtDecl *D, Stmt *Statement); |
3134 | |
3135 | void ActOnPopScope(SourceLocation Loc, Scope *S); |
3136 | |
3137 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
3138 | const ParsedAttributesView &DeclAttrs, |
3139 | RecordDecl *&AnonRecord); |
3140 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
3141 | const ParsedAttributesView &DeclAttrs, |
3142 | MultiTemplateParamsArg TemplateParams, |
3143 | bool IsExplicitInstantiation, |
3144 | RecordDecl *&AnonRecord); |
3145 | |
3146 | Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, AccessSpecifier AS, |
3147 | RecordDecl *Record, |
3148 | const PrintingPolicy &Policy); |
3149 | |
3150 | /// Called once it is known whether |
3151 | /// a tag declaration is an anonymous union or struct. |
3152 | void ActOnDefinedDeclarationSpecifier(Decl *D); |
3153 | |
3154 | void DiagPlaceholderFieldDeclDefinitions(RecordDecl *Record); |
3155 | |
3156 | Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, |
3157 | RecordDecl *Record); |
3158 | |
3159 | /// Common ways to introduce type names without a tag for use in diagnostics. |
3160 | /// Keep in sync with err_tag_reference_non_tag. |
3161 | enum NonTagKind { |
3162 | NTK_NonStruct, |
3163 | NTK_NonClass, |
3164 | NTK_NonUnion, |
3165 | NTK_NonEnum, |
3166 | NTK_Typedef, |
3167 | NTK_TypeAlias, |
3168 | NTK_Template, |
3169 | NTK_TypeAliasTemplate, |
3170 | NTK_TemplateTemplateArgument, |
3171 | }; |
3172 | |
3173 | /// Given a non-tag type declaration, returns an enum useful for indicating |
3174 | /// what kind of non-tag type this is. |
3175 | NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK); |
3176 | |
3177 | bool isAcceptableTagRedeclaration(const TagDecl *Previous, TagTypeKind NewTag, |
3178 | bool isDefinition, SourceLocation NewTagLoc, |
3179 | const IdentifierInfo *Name); |
3180 | |
3181 | enum TagUseKind { |
3182 | TUK_Reference, // Reference to a tag: 'struct foo *X;' |
3183 | TUK_Declaration, // Fwd decl of a tag: 'struct foo;' |
3184 | TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;' |
3185 | TUK_Friend // Friend declaration: 'friend struct foo;' |
3186 | }; |
3187 | |
3188 | enum OffsetOfKind { |
3189 | // Not parsing a type within __builtin_offsetof. |
3190 | OOK_Outside, |
3191 | // Parsing a type within __builtin_offsetof. |
3192 | OOK_Builtin, |
3193 | // Parsing a type within macro "offsetof", defined in __buitin_offsetof |
3194 | // To improve our diagnostic message. |
3195 | OOK_Macro, |
3196 | }; |
3197 | |
3198 | DeclResult ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, |
3199 | SourceLocation KWLoc, CXXScopeSpec &SS, |
3200 | IdentifierInfo *Name, SourceLocation NameLoc, |
3201 | const ParsedAttributesView &Attr, AccessSpecifier AS, |
3202 | SourceLocation ModulePrivateLoc, |
3203 | MultiTemplateParamsArg TemplateParameterLists, |
3204 | bool &OwnedDecl, bool &IsDependent, |
3205 | SourceLocation ScopedEnumKWLoc, |
3206 | bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, |
3207 | bool IsTypeSpecifier, bool IsTemplateParamOrArg, |
3208 | OffsetOfKind OOK, SkipBodyInfo *SkipBody = nullptr); |
3209 | |
3210 | Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, |
3211 | Declarator &D, Expr *BitfieldWidth); |
3212 | |
3213 | FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, |
3214 | Declarator &D, Expr *BitfieldWidth, |
3215 | InClassInitStyle InitStyle, AccessSpecifier AS); |
3216 | |
3217 | FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, |
3218 | TypeSourceInfo *TInfo, RecordDecl *Record, |
3219 | SourceLocation Loc, bool Mutable, |
3220 | Expr *BitfieldWidth, InClassInitStyle InitStyle, |
3221 | SourceLocation TSSL, AccessSpecifier AS, |
3222 | NamedDecl *PrevDecl, Declarator *D = nullptr); |
3223 | |
3224 | bool CheckNontrivialField(FieldDecl *FD); |
3225 | |
3226 | void ActOnLastBitfield(SourceLocation DeclStart, |
3227 | SmallVectorImpl<Decl *> &AllIvarDecls); |
3228 | Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, Declarator &D, |
3229 | Expr *BitWidth, tok::ObjCKeywordKind visibility); |
3230 | |
3231 | // This is used for both record definitions and ObjC interface declarations. |
3232 | void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, |
3233 | ArrayRef<Decl *> Fields, SourceLocation LBrac, |
3234 | SourceLocation RBrac, const ParsedAttributesView &AttrList); |
3235 | |
3236 | /// ActOnTagStartDefinition - Invoked when we have entered the |
3237 | /// scope of a tag's definition (e.g., for an enumeration, class, |
3238 | /// struct, or union). |
3239 | void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); |
3240 | |
3241 | /// Perform ODR-like check for C/ObjC when merging tag types from modules. |
3242 | /// Differently from C++, actually parse the body and reject / error out |
3243 | /// in case of a structural mismatch. |
3244 | bool ActOnDuplicateDefinition(Decl *Prev, SkipBodyInfo &SkipBody); |
3245 | |
3246 | typedef void *SkippedDefinitionContext; |
3247 | |
3248 | /// Invoked when we enter a tag definition that we're skipping. |
3249 | SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD); |
3250 | |
3251 | void ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl); |
3252 | |
3253 | /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a |
3254 | /// C++ record definition's base-specifiers clause and are starting its |
3255 | /// member declarations. |
3256 | void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, |
3257 | SourceLocation FinalLoc, |
3258 | bool IsFinalSpelledSealed, |
3259 | bool IsAbstract, |
3260 | SourceLocation LBraceLoc); |
3261 | |
3262 | /// ActOnTagFinishDefinition - Invoked once we have finished parsing |
3263 | /// the definition of a tag (enumeration, class, struct, or union). |
3264 | void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, |
3265 | SourceRange BraceRange); |
3266 | |
3267 | void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context); |
3268 | |
3269 | void ActOnObjCContainerFinishDefinition(); |
3270 | |
3271 | /// Invoked when we must temporarily exit the objective-c container |
3272 | /// scope for parsing/looking-up C constructs. |
3273 | /// |
3274 | /// Must be followed by a call to \see ActOnObjCReenterContainerContext |
3275 | void ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx); |
3276 | void ActOnObjCReenterContainerContext(ObjCContainerDecl *ObjCCtx); |
3277 | |
3278 | /// ActOnTagDefinitionError - Invoked when there was an unrecoverable |
3279 | /// error parsing the definition of a tag. |
3280 | void ActOnTagDefinitionError(Scope *S, Decl *TagDecl); |
3281 | |
3282 | EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, |
3283 | EnumConstantDecl *LastEnumConst, |
3284 | SourceLocation IdLoc, IdentifierInfo *Id, |
3285 | Expr *val); |
3286 | bool CheckEnumUnderlyingType(TypeSourceInfo *TI); |
3287 | bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, |
3288 | QualType EnumUnderlyingTy, bool IsFixed, |
3289 | const EnumDecl *Prev); |
3290 | |
3291 | /// Determine whether the body of an anonymous enumeration should be skipped. |
3292 | /// \param II The name of the first enumerator. |
3293 | SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, |
3294 | SourceLocation IILoc); |
3295 | |
3296 | Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, |
3297 | SourceLocation IdLoc, IdentifierInfo *Id, |
3298 | const ParsedAttributesView &Attrs, |
3299 | SourceLocation EqualLoc, Expr *Val); |
3300 | void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, |
3301 | Decl *EnumDecl, ArrayRef<Decl *> Elements, Scope *S, |
3302 | const ParsedAttributesView &Attr); |
3303 | |
3304 | /// Set the current declaration context until it gets popped. |
3305 | void PushDeclContext(Scope *S, DeclContext *DC); |
3306 | void PopDeclContext(); |
3307 | |
3308 | /// EnterDeclaratorContext - Used when we must lookup names in the context |
3309 | /// of a declarator's nested name specifier. |
3310 | void EnterDeclaratorContext(Scope *S, DeclContext *DC); |
3311 | void ExitDeclaratorContext(Scope *S); |
3312 | |
3313 | /// Enter a template parameter scope, after it's been associated with a |
3314 | /// particular DeclContext. Causes lookup within the scope to chain through |
3315 | /// enclosing contexts in the correct order. |
3316 | void EnterTemplatedContext(Scope *S, DeclContext *DC); |
3317 | |
3318 | /// Push the parameters of D, which must be a function, into scope. |
3319 | void ActOnReenterFunctionContext(Scope *S, Decl *D); |
3320 | void ActOnExitFunctionContext(); |
3321 | |
3322 | /// Add this decl to the scope shadowed decl chains. |
3323 | void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true); |
3324 | |
3325 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
3326 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
3327 | /// true if 'D' belongs to the given declaration context. |
3328 | /// |
3329 | /// \param AllowInlineNamespace If \c true, allow the declaration to be in the |
3330 | /// enclosing namespace set of the context, rather than contained |
3331 | /// directly within it. |
3332 | bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr, |
3333 | bool AllowInlineNamespace = false) const; |
3334 | |
3335 | /// Finds the scope corresponding to the given decl context, if it |
3336 | /// happens to be an enclosing scope. Otherwise return NULL. |
3337 | static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC); |
3338 | |
3339 | /// Subroutines of ActOnDeclarator(). |
3340 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, |
3341 | TypeSourceInfo *TInfo); |
3342 | bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New); |
3343 | |
3344 | /// Describes the kind of merge to perform for availability |
3345 | /// attributes (including "deprecated", "unavailable", and "availability"). |
3346 | enum AvailabilityMergeKind { |
3347 | /// Don't merge availability attributes at all. |
3348 | AMK_None, |
3349 | /// Merge availability attributes for a redeclaration, which requires |
3350 | /// an exact match. |
3351 | AMK_Redeclaration, |
3352 | /// Merge availability attributes for an override, which requires |
3353 | /// an exact match or a weakening of constraints. |
3354 | AMK_Override, |
3355 | /// Merge availability attributes for an implementation of |
3356 | /// a protocol requirement. |
3357 | AMK_ProtocolImplementation, |
3358 | /// Merge availability attributes for an implementation of |
3359 | /// an optional protocol requirement. |
3360 | AMK_OptionalProtocolImplementation |
3361 | }; |
3362 | |
3363 | void mergeDeclAttributes(NamedDecl *New, Decl *Old, |
3364 | AvailabilityMergeKind AMK = AMK_Redeclaration); |
3365 | void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, |
3366 | LookupResult &OldDecls); |
3367 | bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S, |
3368 | bool MergeTypeWithOld, bool NewDeclIsDefn); |
3369 | bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, |
3370 | Scope *S, bool MergeTypeWithOld); |
3371 | void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old); |
3372 | void MergeVarDecl(VarDecl *New, LookupResult &Previous); |
3373 | void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld); |
3374 | bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn); |
3375 | void notePreviousDefinition(const NamedDecl *Old, SourceLocation New); |
3376 | |
3377 | void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, |
3378 | bool ConsiderLinkage, bool AllowInlineNamespace); |
3379 | |
3380 | bool CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old); |
3381 | bool CheckRedeclarationExported(NamedDecl *New, NamedDecl *Old); |
3382 | bool CheckRedeclarationInModule(NamedDecl *New, NamedDecl *Old); |
3383 | bool IsRedefinitionInModule(const NamedDecl *New, const NamedDecl *Old) const; |
3384 | |
3385 | bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; |
3386 | |
3387 | /// If it's a file scoped decl that must warn if not used, keep track |
3388 | /// of it. |
3389 | void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); |
3390 | |
3391 | typedef llvm::function_ref<void(SourceLocation Loc, PartialDiagnostic PD)> |
3392 | DiagReceiverTy; |
3393 | |
3394 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D); |
3395 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D, |
3396 | DiagReceiverTy DiagReceiver); |
3397 | void DiagnoseUnusedDecl(const NamedDecl *ND); |
3398 | void DiagnoseUnusedDecl(const NamedDecl *ND, DiagReceiverTy DiagReceiver); |
3399 | |
3400 | /// If VD is set but not otherwise used, diagnose, for a parameter or a |
3401 | /// variable. |
3402 | void DiagnoseUnusedButSetDecl(const VarDecl *VD, DiagReceiverTy DiagReceiver); |
3403 | |
3404 | ObjCInterfaceDecl *getObjCInterfaceDecl(const IdentifierInfo *&Id, |
3405 | SourceLocation IdLoc, |
3406 | bool TypoCorrection = false); |
3407 | |
3408 | Scope *getNonFieldDeclScope(Scope *S); |
3409 | |
3410 | FunctionDecl *CreateBuiltin(IdentifierInfo *II, QualType Type, unsigned ID, |
3411 | SourceLocation Loc); |
3412 | NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S, |
3413 | bool ForRedeclaration, SourceLocation Loc); |
3414 | |
3415 | /// Get the outermost AttributedType node that sets a calling convention. |
3416 | /// Valid types should not have multiple attributes with different CCs. |
3417 | const AttributedType *getCallingConvAttributedType(QualType T) const; |
3418 | |
3419 | DeclarationNameInfo GetNameForDeclarator(Declarator &D); |
3420 | DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name); |
3421 | |
3422 | /// ParsingInitForAutoVars - a set of declarations with auto types for which |
3423 | /// we are currently parsing the initializer. |
3424 | llvm::SmallPtrSet<const Decl *, 4> ParsingInitForAutoVars; |
3425 | |
3426 | /// Look for a locally scoped extern "C" declaration by the given name. |
3427 | NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name); |
3428 | |
3429 | bool inferObjCARCLifetime(ValueDecl *decl); |
3430 | |
3431 | void deduceOpenCLAddressSpace(ValueDecl *decl); |
3432 | |
3433 | static bool adjustContextForLocalExternDecl(DeclContext *&DC); |
3434 | |
3435 | void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F); |
3436 | |
3437 | /// Checks if the variant/multiversion functions are compatible. |
3438 | bool areMultiversionVariantFunctionsCompatible( |
3439 | const FunctionDecl *OldFD, const FunctionDecl *NewFD, |
3440 | const PartialDiagnostic &NoProtoDiagID, |
3441 | const PartialDiagnosticAt &NoteCausedDiagIDAt, |
3442 | const PartialDiagnosticAt &NoSupportDiagIDAt, |
3443 | const PartialDiagnosticAt &DiffDiagIDAt, bool TemplatesSupported, |
3444 | bool ConstexprSupported, bool CLinkageMayDiffer); |
3445 | |
3446 | /// type checking declaration initializers (C99 6.7.8) |
3447 | bool CheckForConstantInitializer( |
3448 | Expr *Init, unsigned DiagID = diag::err_init_element_not_constant); |
3449 | |
3450 | QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name, |
3451 | QualType Type, TypeSourceInfo *TSI, |
3452 | SourceRange Range, bool DirectInit, |
3453 | Expr *Init); |
3454 | |
3455 | bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit, |
3456 | Expr *Init); |
3457 | |
3458 | sema::LambdaScopeInfo *RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator); |
3459 | |
3460 | // Heuristically tells if the function is `get_return_object` member of a |
3461 | // coroutine promise_type by matching the function name. |
3462 | static bool CanBeGetReturnObject(const FunctionDecl *FD); |
3463 | static bool CanBeGetReturnTypeOnAllocFailure(const FunctionDecl *FD); |
3464 | |
3465 | NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
3466 | Scope *S); |
3467 | void AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction( |
3468 | FunctionDecl *FD); |
3469 | void AddKnownFunctionAttributes(FunctionDecl *FD); |
3470 | |
3471 | /// VerifyBitField - verifies that a bit field expression is an ICE and has |
3472 | /// the correct width, and that the field type is valid. |
3473 | /// Returns false on success. |
3474 | ExprResult VerifyBitField(SourceLocation FieldLoc, |
3475 | const IdentifierInfo *FieldName, QualType FieldTy, |
3476 | bool IsMsStruct, Expr *BitWidth); |
3477 | |
3478 | /// IsValueInFlagEnum - Determine if a value is allowed as part of a flag |
3479 | /// enum. If AllowMask is true, then we also allow the complement of a valid |
3480 | /// value, to be used as a mask. |
3481 | bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val, |
3482 | bool AllowMask) const; |
3483 | |
3484 | /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident. |
3485 | void ActOnPragmaWeakID(IdentifierInfo *WeakName, SourceLocation PragmaLoc, |
3486 | SourceLocation WeakNameLoc); |
3487 | |
3488 | /// ActOnPragmaRedefineExtname - Called on well formed |
3489 | /// \#pragma redefine_extname oldname newname. |
3490 | void ActOnPragmaRedefineExtname(IdentifierInfo *WeakName, |
3491 | IdentifierInfo *AliasName, |
3492 | SourceLocation PragmaLoc, |
3493 | SourceLocation WeakNameLoc, |
3494 | SourceLocation AliasNameLoc); |
3495 | |
3496 | /// ActOnPragmaWeakAlias - Called on well formed \#pragma weak ident = ident. |
3497 | void ActOnPragmaWeakAlias(IdentifierInfo *WeakName, IdentifierInfo *AliasName, |
3498 | SourceLocation PragmaLoc, |
3499 | SourceLocation WeakNameLoc, |
3500 | SourceLocation AliasNameLoc); |
3501 | |
3502 | ObjCContainerDecl *getObjCDeclContext() const; |
3503 | |
3504 | /// Status of the function emission on the CUDA/HIP/OpenMP host/device attrs. |
3505 | enum class FunctionEmissionStatus { |
3506 | Emitted, |
3507 | CUDADiscarded, // Discarded due to CUDA/HIP hostness |
3508 | OMPDiscarded, // Discarded due to OpenMP hostness |
3509 | TemplateDiscarded, // Discarded due to uninstantiated templates |
3510 | Unknown, |
3511 | }; |
3512 | FunctionEmissionStatus getEmissionStatus(const FunctionDecl *Decl, |
3513 | bool Final = false); |
3514 | |
3515 | // Whether the callee should be ignored in CUDA/HIP/OpenMP host/device check. |
3516 | bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee); |
3517 | |
3518 | private: |
3519 | /// Function or variable declarations to be checked for whether the deferred |
3520 | /// diagnostics should be emitted. |
3521 | llvm::SmallSetVector<Decl *, 4> DeclsToCheckForDeferredDiags; |
3522 | |
3523 | /// Map of current shadowing declarations to shadowed declarations. Warn if |
3524 | /// it looks like the user is trying to modify the shadowing declaration. |
3525 | llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls; |
3526 | |
3527 | static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD); |
3528 | |
3529 | ///@} |
3530 | |
3531 | // |
3532 | // |
3533 | // ------------------------------------------------------------------------- |
3534 | // |
3535 | // |
3536 | |
3537 | /// \name Declaration Attribute Handling |
3538 | /// Implementations are in SemaDeclAttr.cpp |
3539 | ///@{ |
3540 | |
3541 | public: |
3542 | /// Describes the kind of priority given to an availability attribute. |
3543 | /// |
3544 | /// The sum of priorities deteremines the final priority of the attribute. |
3545 | /// The final priority determines how the attribute will be merged. |
3546 | /// An attribute with a lower priority will always remove higher priority |
3547 | /// attributes for the specified platform when it is being applied. An |
3548 | /// attribute with a higher priority will not be applied if the declaration |
3549 | /// already has an availability attribute with a lower priority for the |
3550 | /// specified platform. The final prirority values are not expected to match |
3551 | /// the values in this enumeration, but instead should be treated as a plain |
3552 | /// integer value. This enumeration just names the priority weights that are |
3553 | /// used to calculate that final vaue. |
3554 | enum AvailabilityPriority : int { |
3555 | /// The availability attribute was specified explicitly next to the |
3556 | /// declaration. |
3557 | AP_Explicit = 0, |
3558 | |
3559 | /// The availability attribute was applied using '#pragma clang attribute'. |
3560 | AP_PragmaClangAttribute = 1, |
3561 | |
3562 | /// The availability attribute for a specific platform was inferred from |
3563 | /// an availability attribute for another platform. |
3564 | AP_InferredFromOtherPlatform = 2 |
3565 | }; |
3566 | |
3567 | /// Describes the reason a calling convention specification was ignored, used |
3568 | /// for diagnostics. |
3569 | enum class CallingConventionIgnoredReason { |
3570 | ForThisTarget = 0, |
3571 | VariadicFunction, |
3572 | ConstructorDestructor, |
3573 | BuiltinFunction |
3574 | }; |
3575 | |
3576 | /// WeakTopLevelDecl - Translation-unit scoped declarations generated by |
3577 | /// \#pragma weak during processing of other Decls. |
3578 | /// I couldn't figure out a clean way to generate these in-line, so |
3579 | /// we store them here and handle separately -- which is a hack. |
3580 | /// It would be best to refactor this. |
3581 | SmallVector<Decl *, 2> WeakTopLevelDecl; |
3582 | |
3583 | /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls |
3584 | SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; } |
3585 | |
3586 | typedef LazyVector<TypedefNameDecl *, ExternalSemaSource, |
3587 | &ExternalSemaSource::ReadExtVectorDecls, 2, 2> |
3588 | ExtVectorDeclsType; |
3589 | |
3590 | /// ExtVectorDecls - This is a list all the extended vector types. This allows |
3591 | /// us to associate a raw vector type with one of the ext_vector type names. |
3592 | /// This is only necessary for issuing pretty diagnostics. |
3593 | ExtVectorDeclsType ExtVectorDecls; |
3594 | |
3595 | bool checkStringLiteralArgumentAttr(const AttributeCommonInfo &CI, |
3596 | const Expr *E, StringRef &Str, |
3597 | SourceLocation *ArgLocation = nullptr); |
3598 | bool checkStringLiteralArgumentAttr(const ParsedAttr &Attr, unsigned ArgNum, |
3599 | StringRef &Str, |
3600 | SourceLocation *ArgLocation = nullptr); |
3601 | |
3602 | /// Determine if type T is a valid subject for a nonnull and similar |
3603 | /// attributes. By default, we look through references (the behavior used by |
3604 | /// nonnull), but if the second parameter is true, then we treat a reference |
3605 | /// type as valid. |
3606 | bool isValidPointerAttrType(QualType T, bool RefOkay = false); |
3607 | |
3608 | /// AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular |
3609 | /// declaration. |
3610 | void AddAssumeAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
3611 | Expr *OE); |
3612 | |
3613 | /// AddAllocAlignAttr - Adds an alloc_align attribute to a particular |
3614 | /// declaration. |
3615 | void AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI, |
3616 | Expr *ParamExpr); |
3617 | |
3618 | bool CheckAttrTarget(const ParsedAttr &CurrAttr); |
3619 | bool CheckAttrNoArgs(const ParsedAttr &CurrAttr); |
3620 | |
3621 | AvailabilityAttr * |
3622 | mergeAvailabilityAttr(NamedDecl *D, const AttributeCommonInfo &CI, |
3623 | IdentifierInfo *Platform, bool Implicit, |
3624 | VersionTuple Introduced, VersionTuple Deprecated, |
3625 | VersionTuple Obsoleted, bool IsUnavailable, |
3626 | StringRef Message, bool IsStrict, StringRef Replacement, |
3627 | AvailabilityMergeKind AMK, int Priority); |
3628 | TypeVisibilityAttr * |
3629 | mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
3630 | TypeVisibilityAttr::VisibilityType Vis); |
3631 | VisibilityAttr *mergeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
3632 | VisibilityAttr::VisibilityType Vis); |
3633 | SectionAttr *mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI, |
3634 | StringRef Name); |
3635 | |
3636 | llvm::Error isValidSectionSpecifier(StringRef Str); |
3637 | bool checkSectionName(SourceLocation LiteralLoc, StringRef Str); |
3638 | CodeSegAttr *mergeCodeSegAttr(Decl *D, const AttributeCommonInfo &CI, |
3639 | StringRef Name); |
3640 | |
3641 | bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str); |
3642 | bool checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D, |
3643 | StringRef &Str, bool &isDefault); |
3644 | bool checkTargetClonesAttrString( |
3645 | SourceLocation LiteralLoc, StringRef Str, const StringLiteral *Literal, |
3646 | Decl *D, bool &HasDefault, bool &HasCommas, bool &HasNotDefault, |
3647 | SmallVectorImpl<SmallString<64>> &StringsBuffer); |
3648 | |
3649 | ErrorAttr *mergeErrorAttr(Decl *D, const AttributeCommonInfo &CI, |
3650 | StringRef NewUserDiagnostic); |
3651 | FormatAttr *mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI, |
3652 | IdentifierInfo *Format, int FormatIdx, |
3653 | int FirstArg); |
3654 | |
3655 | /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. |
3656 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
3657 | bool IsPackExpansion); |
3658 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, TypeSourceInfo *T, |
3659 | bool IsPackExpansion); |
3660 | |
3661 | /// AddAlignValueAttr - Adds an align_value attribute to a particular |
3662 | /// declaration. |
3663 | void AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E); |
3664 | |
3665 | /// AddAnnotationAttr - Adds an annotation Annot with Args arguments to D. |
3666 | void AddAnnotationAttr(Decl *D, const AttributeCommonInfo &CI, |
3667 | StringRef Annot, MutableArrayRef<Expr *> Args); |
3668 | |
3669 | bool checkMSInheritanceAttrOnDefinition(CXXRecordDecl *RD, SourceRange Range, |
3670 | bool BestCase, |
3671 | MSInheritanceModel SemanticSpelling); |
3672 | |
3673 | void CheckAlignasUnderalignment(Decl *D); |
3674 | |
3675 | /// AddModeAttr - Adds a mode attribute to a particular declaration. |
3676 | void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Name, |
3677 | bool InInstantiation = false); |
3678 | AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, |
3679 | const AttributeCommonInfo &CI, |
3680 | const IdentifierInfo *Ident); |
3681 | MinSizeAttr *mergeMinSizeAttr(Decl *D, const AttributeCommonInfo &CI); |
3682 | SwiftNameAttr *mergeSwiftNameAttr(Decl *D, const SwiftNameAttr &SNA, |
3683 | StringRef Name); |
3684 | OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, |
3685 | const AttributeCommonInfo &CI); |
3686 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL); |
3687 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, |
3688 | const InternalLinkageAttr &AL); |
3689 | |
3690 | /// Check validaty of calling convention attribute \p attr. If \p FD |
3691 | /// is not null pointer, use \p FD to determine the CUDA/HIP host/device |
3692 | /// target. Otherwise, it is specified by \p CFT. |
3693 | bool CheckCallingConvAttr( |
3694 | const ParsedAttr &attr, CallingConv &CC, const FunctionDecl *FD = nullptr, |
3695 | CUDAFunctionTarget CFT = CUDAFunctionTarget::InvalidTarget); |
3696 | |
3697 | void AddParameterABIAttr(Decl *D, const AttributeCommonInfo &CI, |
3698 | ParameterABI ABI); |
3699 | bool CheckRegparmAttr(const ParsedAttr &attr, unsigned &value); |
3700 | |
3701 | /// Create an CUDALaunchBoundsAttr attribute. |
3702 | CUDALaunchBoundsAttr *CreateLaunchBoundsAttr(const AttributeCommonInfo &CI, |
3703 | Expr *MaxThreads, |
3704 | Expr *MinBlocks, |
3705 | Expr *MaxBlocks); |
3706 | |
3707 | /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular |
3708 | /// declaration. |
3709 | void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI, |
3710 | Expr *MaxThreads, Expr *MinBlocks, Expr *MaxBlocks); |
3711 | |
3712 | enum class RetainOwnershipKind { NS, CF, OS }; |
3713 | void AddXConsumedAttr(Decl *D, const AttributeCommonInfo &CI, |
3714 | RetainOwnershipKind K, bool IsTemplateInstantiation); |
3715 | |
3716 | bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type); |
3717 | |
3718 | /// Do a check to make sure \p Name looks like a legal argument for the |
3719 | /// swift_name attribute applied to decl \p D. Raise a diagnostic if the name |
3720 | /// is invalid for the given declaration. |
3721 | /// |
3722 | /// \p AL is used to provide caret diagnostics in case of a malformed name. |
3723 | /// |
3724 | /// \returns true if the name is a valid swift name for \p D, false otherwise. |
3725 | bool DiagnoseSwiftName(Decl *D, StringRef Name, SourceLocation Loc, |
3726 | const ParsedAttr &AL, bool IsAsync); |
3727 | |
3728 | UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI, |
3729 | StringRef UuidAsWritten, MSGuidDecl *GuidDecl); |
3730 | |
3731 | BTFDeclTagAttr *mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL); |
3732 | |
3733 | WebAssemblyImportNameAttr * |
3734 | mergeImportNameAttr(Decl *D, const WebAssemblyImportNameAttr &AL); |
3735 | WebAssemblyImportModuleAttr * |
3736 | mergeImportModuleAttr(Decl *D, const WebAssemblyImportModuleAttr &AL); |
3737 | |
3738 | /// Create an AMDGPUWavesPerEUAttr attribute. |
3739 | AMDGPUFlatWorkGroupSizeAttr * |
3740 | CreateAMDGPUFlatWorkGroupSizeAttr(const AttributeCommonInfo &CI, Expr *Min, |
3741 | Expr *Max); |
3742 | |
3743 | /// addAMDGPUFlatWorkGroupSizeAttr - Adds an amdgpu_flat_work_group_size |
3744 | /// attribute to a particular declaration. |
3745 | void addAMDGPUFlatWorkGroupSizeAttr(Decl *D, const AttributeCommonInfo &CI, |
3746 | Expr *Min, Expr *Max); |
3747 | |
3748 | /// Create an AMDGPUWavesPerEUAttr attribute. |
3749 | AMDGPUWavesPerEUAttr * |
3750 | CreateAMDGPUWavesPerEUAttr(const AttributeCommonInfo &CI, Expr *Min, |
3751 | Expr *Max); |
3752 | |
3753 | /// addAMDGPUWavePersEUAttr - Adds an amdgpu_waves_per_eu attribute to a |
3754 | /// particular declaration. |
3755 | void addAMDGPUWavesPerEUAttr(Decl *D, const AttributeCommonInfo &CI, |
3756 | Expr *Min, Expr *Max); |
3757 | |
3758 | /// Create an AMDGPUMaxNumWorkGroupsAttr attribute. |
3759 | AMDGPUMaxNumWorkGroupsAttr * |
3760 | CreateAMDGPUMaxNumWorkGroupsAttr(const AttributeCommonInfo &CI, Expr *XExpr, |
3761 | Expr *YExpr, Expr *ZExpr); |
3762 | |
3763 | /// addAMDGPUMaxNumWorkGroupsAttr - Adds an amdgpu_max_num_work_groups |
3764 | /// attribute to a particular declaration. |
3765 | void addAMDGPUMaxNumWorkGroupsAttr(Decl *D, const AttributeCommonInfo &CI, |
3766 | Expr *XExpr, Expr *YExpr, Expr *ZExpr); |
3767 | |
3768 | DLLImportAttr *mergeDLLImportAttr(Decl *D, const AttributeCommonInfo &CI); |
3769 | DLLExportAttr *mergeDLLExportAttr(Decl *D, const AttributeCommonInfo &CI); |
3770 | MSInheritanceAttr *mergeMSInheritanceAttr(Decl *D, |
3771 | const AttributeCommonInfo &CI, |
3772 | bool BestCase, |
3773 | MSInheritanceModel Model); |
3774 | |
3775 | EnforceTCBAttr *mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL); |
3776 | EnforceTCBLeafAttr *mergeEnforceTCBLeafAttr(Decl *D, |
3777 | const EnforceTCBLeafAttr &AL); |
3778 | |
3779 | // Helper for delayed processing of attributes. |
3780 | void ProcessDeclAttributeDelayed(Decl *D, |
3781 | const ParsedAttributesView &AttrList); |
3782 | |
3783 | // Options for ProcessDeclAttributeList(). |
3784 | struct ProcessDeclAttributeOptions { |
3785 | ProcessDeclAttributeOptions() |
3786 | : IncludeCXX11Attributes(true), IgnoreTypeAttributes(false) {} |
3787 | |
3788 | ProcessDeclAttributeOptions WithIncludeCXX11Attributes(bool Val) { |
3789 | ProcessDeclAttributeOptions Result = *this; |
3790 | Result.IncludeCXX11Attributes = Val; |
3791 | return Result; |
3792 | } |
3793 | |
3794 | ProcessDeclAttributeOptions WithIgnoreTypeAttributes(bool Val) { |
3795 | ProcessDeclAttributeOptions Result = *this; |
3796 | Result.IgnoreTypeAttributes = Val; |
3797 | return Result; |
3798 | } |
3799 | |
3800 | // Should C++11 attributes be processed? |
3801 | bool IncludeCXX11Attributes; |
3802 | |
3803 | // Should any type attributes encountered be ignored? |
3804 | // If this option is false, a diagnostic will be emitted for any type |
3805 | // attributes of a kind that does not "slide" from the declaration to |
3806 | // the decl-specifier-seq. |
3807 | bool IgnoreTypeAttributes; |
3808 | }; |
3809 | |
3810 | void ProcessDeclAttributeList(Scope *S, Decl *D, |
3811 | const ParsedAttributesView &AttrList, |
3812 | const ProcessDeclAttributeOptions &Options = |
3813 | ProcessDeclAttributeOptions()); |
3814 | bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, |
3815 | const ParsedAttributesView &AttrList); |
3816 | |
3817 | void checkUnusedDeclAttributes(Declarator &D); |
3818 | |
3819 | NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, const IdentifierInfo *II, |
3820 | SourceLocation Loc); |
3821 | void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, const WeakInfo &W); |
3822 | |
3823 | void ProcessPragmaWeak(Scope *S, Decl *D); |
3824 | // Decl attributes - this routine is the top level dispatcher. |
3825 | void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD); |
3826 | |
3827 | void PopParsingDeclaration(ParsingDeclState state, Decl *decl); |
3828 | |
3829 | void redelayDiagnostics(sema::DelayedDiagnosticPool &pool); |
3830 | |
3831 | ///@} |
3832 | |
3833 | // |
3834 | // |
3835 | // ------------------------------------------------------------------------- |
3836 | // |
3837 | // |
3838 | |
3839 | /// \name C++ Declarations |
3840 | /// Implementations are in SemaDeclCXX.cpp |
3841 | ///@{ |
3842 | |
3843 | public: |
3844 | void CheckDelegatingCtorCycles(); |
3845 | |
3846 | /// Called before parsing a function declarator belonging to a function |
3847 | /// declaration. |
3848 | void ActOnStartFunctionDeclarationDeclarator(Declarator &D, |
3849 | unsigned TemplateParameterDepth); |
3850 | |
3851 | /// Called after parsing a function declarator belonging to a function |
3852 | /// declaration. |
3853 | void ActOnFinishFunctionDeclarationDeclarator(Declarator &D); |
3854 | |
3855 | // Act on C++ namespaces |
3856 | Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, |
3857 | SourceLocation NamespaceLoc, |
3858 | SourceLocation IdentLoc, IdentifierInfo *Ident, |
3859 | SourceLocation LBrace, |
3860 | const ParsedAttributesView &AttrList, |
3861 | UsingDirectiveDecl *&UsingDecl, bool IsNested); |
3862 | void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); |
3863 | |
3864 | NamespaceDecl *getStdNamespace() const; |
3865 | NamespaceDecl *getOrCreateStdNamespace(); |
3866 | |
3867 | CXXRecordDecl *getStdBadAlloc() const; |
3868 | EnumDecl *getStdAlignValT() const; |
3869 | |
3870 | ValueDecl *tryLookupUnambiguousFieldDecl(RecordDecl *ClassDecl, |
3871 | const IdentifierInfo *MemberOrBase); |
3872 | |
3873 | enum class ComparisonCategoryUsage { |
3874 | /// The '<=>' operator was used in an expression and a builtin operator |
3875 | /// was selected. |
3876 | OperatorInExpression, |
3877 | /// A defaulted 'operator<=>' needed the comparison category. This |
3878 | /// typically only applies to 'std::strong_ordering', due to the implicit |
3879 | /// fallback return value. |
3880 | DefaultedOperator, |
3881 | }; |
3882 | |
3883 | /// Lookup the specified comparison category types in the standard |
3884 | /// library, an check the VarDecls possibly returned by the operator<=> |
3885 | /// builtins for that type. |
3886 | /// |
3887 | /// \return The type of the comparison category type corresponding to the |
3888 | /// specified Kind, or a null type if an error occurs |
3889 | QualType CheckComparisonCategoryType(ComparisonCategoryType Kind, |
3890 | SourceLocation Loc, |
3891 | ComparisonCategoryUsage Usage); |
3892 | |
3893 | /// Tests whether Ty is an instance of std::initializer_list and, if |
3894 | /// it is and Element is not NULL, assigns the element type to Element. |
3895 | bool isStdInitializerList(QualType Ty, QualType *Element); |
3896 | |
3897 | /// Looks for the std::initializer_list template and instantiates it |
3898 | /// with Element, or emits an error if it's not found. |
3899 | /// |
3900 | /// \returns The instantiated template, or null on error. |
3901 | QualType BuildStdInitializerList(QualType Element, SourceLocation Loc); |
3902 | |
3903 | /// Determine whether Ctor is an initializer-list constructor, as |
3904 | /// defined in [dcl.init.list]p2. |
3905 | bool isInitListConstructor(const FunctionDecl *Ctor); |
3906 | |
3907 | Decl *ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc, |
3908 | SourceLocation NamespcLoc, CXXScopeSpec &SS, |
3909 | SourceLocation IdentLoc, |
3910 | IdentifierInfo *NamespcName, |
3911 | const ParsedAttributesView &AttrList); |
3912 | |
3913 | void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); |
3914 | |
3915 | Decl *ActOnNamespaceAliasDef(Scope *CurScope, SourceLocation NamespaceLoc, |
3916 | SourceLocation AliasLoc, IdentifierInfo *Alias, |
3917 | CXXScopeSpec &SS, SourceLocation IdentLoc, |
3918 | IdentifierInfo *Ident); |
3919 | |
3920 | void FilterUsingLookup(Scope *S, LookupResult &lookup); |
3921 | void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); |
3922 | bool CheckUsingShadowDecl(BaseUsingDecl *BUD, NamedDecl *Target, |
3923 | const LookupResult &PreviousDecls, |
3924 | UsingShadowDecl *&PrevShadow); |
3925 | UsingShadowDecl *BuildUsingShadowDecl(Scope *S, BaseUsingDecl *BUD, |
3926 | NamedDecl *Target, |
3927 | UsingShadowDecl *PrevDecl); |
3928 | |
3929 | bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, |
3930 | bool HasTypenameKeyword, |
3931 | const CXXScopeSpec &SS, |
3932 | SourceLocation NameLoc, |
3933 | const LookupResult &Previous); |
3934 | bool CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename, |
3935 | const CXXScopeSpec &SS, |
3936 | const DeclarationNameInfo &NameInfo, |
3937 | SourceLocation NameLoc, |
3938 | const LookupResult *R = nullptr, |
3939 | const UsingDecl *UD = nullptr); |
3940 | |
3941 | NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS, |
3942 | SourceLocation UsingLoc, |
3943 | bool HasTypenameKeyword, |
3944 | SourceLocation TypenameLoc, CXXScopeSpec &SS, |
3945 | DeclarationNameInfo NameInfo, |
3946 | SourceLocation EllipsisLoc, |
3947 | const ParsedAttributesView &AttrList, |
3948 | bool IsInstantiation, bool IsUsingIfExists); |
3949 | NamedDecl *BuildUsingEnumDeclaration(Scope *S, AccessSpecifier AS, |
3950 | SourceLocation UsingLoc, |
3951 | SourceLocation EnumLoc, |
3952 | SourceLocation NameLoc, |
3953 | TypeSourceInfo *EnumType, EnumDecl *ED); |
3954 | NamedDecl *BuildUsingPackDecl(NamedDecl *InstantiatedFrom, |
3955 | ArrayRef<NamedDecl *> Expansions); |
3956 | |
3957 | bool CheckInheritingConstructorUsingDecl(UsingDecl *UD); |
3958 | |
3959 | /// Given a derived-class using shadow declaration for a constructor and the |
3960 | /// correspnding base class constructor, find or create the implicit |
3961 | /// synthesized derived class constructor to use for this initialization. |
3962 | CXXConstructorDecl * |
3963 | findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor, |
3964 | ConstructorUsingShadowDecl *DerivedShadow); |
3965 | |
3966 | Decl *ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS, |
3967 | SourceLocation UsingLoc, |
3968 | SourceLocation TypenameLoc, CXXScopeSpec &SS, |
3969 | UnqualifiedId &Name, SourceLocation EllipsisLoc, |
3970 | const ParsedAttributesView &AttrList); |
3971 | Decl *ActOnUsingEnumDeclaration(Scope *CurScope, AccessSpecifier AS, |
3972 | SourceLocation UsingLoc, |
3973 | SourceLocation EnumLoc, |
3974 | SourceLocation IdentLoc, IdentifierInfo &II, |
3975 | CXXScopeSpec *SS = nullptr); |
3976 | Decl *ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS, |
3977 | MultiTemplateParamsArg TemplateParams, |
3978 | SourceLocation UsingLoc, UnqualifiedId &Name, |
3979 | const ParsedAttributesView &AttrList, |
3980 | TypeResult Type, Decl *DeclFromDeclSpec); |
3981 | |
3982 | /// BuildCXXConstructExpr - Creates a complete call to a constructor, |
3983 | /// including handling of its default argument expressions. |
3984 | /// |
3985 | /// \param ConstructKind - a CXXConstructExpr::ConstructionKind |
3986 | ExprResult BuildCXXConstructExpr( |
3987 | SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, |
3988 | CXXConstructorDecl *Constructor, MultiExprArg Exprs, |
3989 | bool HadMultipleCandidates, bool IsListInitialization, |
3990 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
3991 | CXXConstructionKind ConstructKind, SourceRange ParenRange); |
3992 | |
3993 | /// Build a CXXConstructExpr whose constructor has already been resolved if |
3994 | /// it denotes an inherited constructor. |
3995 | ExprResult BuildCXXConstructExpr( |
3996 | SourceLocation ConstructLoc, QualType DeclInitType, |
3997 | CXXConstructorDecl *Constructor, bool Elidable, MultiExprArg Exprs, |
3998 | bool HadMultipleCandidates, bool IsListInitialization, |
3999 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
4000 | CXXConstructionKind ConstructKind, SourceRange ParenRange); |
4001 | |
4002 | // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if |
4003 | // the constructor can be elidable? |
4004 | ExprResult BuildCXXConstructExpr( |
4005 | SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, |
4006 | CXXConstructorDecl *Constructor, bool Elidable, MultiExprArg Exprs, |
4007 | bool HadMultipleCandidates, bool IsListInitialization, |
4008 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
4009 | CXXConstructionKind ConstructKind, SourceRange ParenRange); |
4010 | |
4011 | ExprResult ConvertMemberDefaultInitExpression(FieldDecl *FD, Expr *InitExpr, |
4012 | SourceLocation InitLoc); |
4013 | |
4014 | /// FinalizeVarWithDestructor - Prepare for calling destructor on the |
4015 | /// constructed variable. |
4016 | void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); |
4017 | |
4018 | /// Helper class that collects exception specifications for |
4019 | /// implicitly-declared special member functions. |
4020 | class ImplicitExceptionSpecification { |
4021 | // Pointer to allow copying |
4022 | Sema *Self; |
4023 | // We order exception specifications thus: |
4024 | // noexcept is the most restrictive, but is only used in C++11. |
4025 | // throw() comes next. |
4026 | // Then a throw(collected exceptions) |
4027 | // Finally no specification, which is expressed as noexcept(false). |
4028 | // throw(...) is used instead if any called function uses it. |
4029 | ExceptionSpecificationType ComputedEST; |
4030 | llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; |
4031 | SmallVector<QualType, 4> Exceptions; |
4032 | |
4033 | void ClearExceptions() { |
4034 | ExceptionsSeen.clear(); |
4035 | Exceptions.clear(); |
4036 | } |
4037 | |
4038 | public: |
4039 | explicit ImplicitExceptionSpecification(Sema &Self) |
4040 | : Self(&Self), ComputedEST(EST_BasicNoexcept) { |
4041 | if (!Self.getLangOpts().CPlusPlus11) |
4042 | ComputedEST = EST_DynamicNone; |
4043 | } |
4044 | |
4045 | /// Get the computed exception specification type. |
4046 | ExceptionSpecificationType getExceptionSpecType() const { |
4047 | assert(!isComputedNoexcept(ComputedEST) && |
4048 | "noexcept(expr) should not be a possible result" ); |
4049 | return ComputedEST; |
4050 | } |
4051 | |
4052 | /// The number of exceptions in the exception specification. |
4053 | unsigned size() const { return Exceptions.size(); } |
4054 | |
4055 | /// The set of exceptions in the exception specification. |
4056 | const QualType *data() const { return Exceptions.data(); } |
4057 | |
4058 | /// Integrate another called method into the collected data. |
4059 | void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method); |
4060 | |
4061 | /// Integrate an invoked expression into the collected data. |
4062 | void CalledExpr(Expr *E) { CalledStmt(E); } |
4063 | |
4064 | /// Integrate an invoked statement into the collected data. |
4065 | void CalledStmt(Stmt *S); |
4066 | |
4067 | /// Overwrite an EPI's exception specification with this |
4068 | /// computed exception specification. |
4069 | FunctionProtoType::ExceptionSpecInfo getExceptionSpec() const { |
4070 | FunctionProtoType::ExceptionSpecInfo ESI; |
4071 | ESI.Type = getExceptionSpecType(); |
4072 | if (ESI.Type == EST_Dynamic) { |
4073 | ESI.Exceptions = Exceptions; |
4074 | } else if (ESI.Type == EST_None) { |
4075 | /// C++11 [except.spec]p14: |
4076 | /// The exception-specification is noexcept(false) if the set of |
4077 | /// potential exceptions of the special member function contains "any" |
4078 | ESI.Type = EST_NoexceptFalse; |
4079 | ESI.NoexceptExpr = |
4080 | Self->ActOnCXXBoolLiteral(OpLoc: SourceLocation(), Kind: tok::kw_false).get(); |
4081 | } |
4082 | return ESI; |
4083 | } |
4084 | }; |
4085 | |
4086 | /// Evaluate the implicit exception specification for a defaulted |
4087 | /// special member function. |
4088 | void EvaluateImplicitExceptionSpec(SourceLocation Loc, FunctionDecl *FD); |
4089 | |
4090 | /// Check the given exception-specification and update the |
4091 | /// exception specification information with the results. |
4092 | void checkExceptionSpecification(bool IsTopLevel, |
4093 | ExceptionSpecificationType EST, |
4094 | ArrayRef<ParsedType> DynamicExceptions, |
4095 | ArrayRef<SourceRange> DynamicExceptionRanges, |
4096 | Expr *NoexceptExpr, |
4097 | SmallVectorImpl<QualType> &Exceptions, |
4098 | FunctionProtoType::ExceptionSpecInfo &ESI); |
4099 | |
4100 | /// Add an exception-specification to the given member function |
4101 | /// (or member function template). The exception-specification was parsed |
4102 | /// after the method itself was declared. |
4103 | void actOnDelayedExceptionSpecification( |
4104 | Decl *Method, ExceptionSpecificationType EST, |
4105 | SourceRange SpecificationRange, ArrayRef<ParsedType> DynamicExceptions, |
4106 | ArrayRef<SourceRange> DynamicExceptionRanges, Expr *NoexceptExpr); |
4107 | |
4108 | class InheritedConstructorInfo; |
4109 | |
4110 | /// Determine if a special member function should have a deleted |
4111 | /// definition when it is defaulted. |
4112 | bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMemberKind CSM, |
4113 | InheritedConstructorInfo *ICI = nullptr, |
4114 | bool Diagnose = false); |
4115 | |
4116 | /// Produce notes explaining why a defaulted function was defined as deleted. |
4117 | void DiagnoseDeletedDefaultedFunction(FunctionDecl *FD); |
4118 | |
4119 | /// Declare the implicit default constructor for the given class. |
4120 | /// |
4121 | /// \param ClassDecl The class declaration into which the implicit |
4122 | /// default constructor will be added. |
4123 | /// |
4124 | /// \returns The implicitly-declared default constructor. |
4125 | CXXConstructorDecl * |
4126 | DeclareImplicitDefaultConstructor(CXXRecordDecl *ClassDecl); |
4127 | |
4128 | /// DefineImplicitDefaultConstructor - Checks for feasibility of |
4129 | /// defining this constructor as the default constructor. |
4130 | void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, |
4131 | CXXConstructorDecl *Constructor); |
4132 | |
4133 | /// Declare the implicit destructor for the given class. |
4134 | /// |
4135 | /// \param ClassDecl The class declaration into which the implicit |
4136 | /// destructor will be added. |
4137 | /// |
4138 | /// \returns The implicitly-declared destructor. |
4139 | CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); |
4140 | |
4141 | /// DefineImplicitDestructor - Checks for feasibility of |
4142 | /// defining this destructor as the default destructor. |
4143 | void DefineImplicitDestructor(SourceLocation CurrentLocation, |
4144 | CXXDestructorDecl *Destructor); |
4145 | |
4146 | /// Build an exception spec for destructors that don't have one. |
4147 | /// |
4148 | /// C++11 says that user-defined destructors with no exception spec get one |
4149 | /// that looks as if the destructor was implicitly declared. |
4150 | void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor); |
4151 | |
4152 | /// Define the specified inheriting constructor. |
4153 | void DefineInheritingConstructor(SourceLocation UseLoc, |
4154 | CXXConstructorDecl *Constructor); |
4155 | |
4156 | /// Declare the implicit copy constructor for the given class. |
4157 | /// |
4158 | /// \param ClassDecl The class declaration into which the implicit |
4159 | /// copy constructor will be added. |
4160 | /// |
4161 | /// \returns The implicitly-declared copy constructor. |
4162 | CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); |
4163 | |
4164 | /// DefineImplicitCopyConstructor - Checks for feasibility of |
4165 | /// defining this constructor as the copy constructor. |
4166 | void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, |
4167 | CXXConstructorDecl *Constructor); |
4168 | |
4169 | /// Declare the implicit move constructor for the given class. |
4170 | /// |
4171 | /// \param ClassDecl The Class declaration into which the implicit |
4172 | /// move constructor will be added. |
4173 | /// |
4174 | /// \returns The implicitly-declared move constructor, or NULL if it wasn't |
4175 | /// declared. |
4176 | CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl); |
4177 | |
4178 | /// DefineImplicitMoveConstructor - Checks for feasibility of |
4179 | /// defining this constructor as the move constructor. |
4180 | void DefineImplicitMoveConstructor(SourceLocation CurrentLocation, |
4181 | CXXConstructorDecl *Constructor); |
4182 | |
4183 | /// Declare the implicit copy assignment operator for the given class. |
4184 | /// |
4185 | /// \param ClassDecl The class declaration into which the implicit |
4186 | /// copy assignment operator will be added. |
4187 | /// |
4188 | /// \returns The implicitly-declared copy assignment operator. |
4189 | CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); |
4190 | |
4191 | /// Defines an implicitly-declared copy assignment operator. |
4192 | void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, |
4193 | CXXMethodDecl *MethodDecl); |
4194 | |
4195 | /// Declare the implicit move assignment operator for the given class. |
4196 | /// |
4197 | /// \param ClassDecl The Class declaration into which the implicit |
4198 | /// move assignment operator will be added. |
4199 | /// |
4200 | /// \returns The implicitly-declared move assignment operator, or NULL if it |
4201 | /// wasn't declared. |
4202 | CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl); |
4203 | |
4204 | /// Defines an implicitly-declared move assignment operator. |
4205 | void DefineImplicitMoveAssignment(SourceLocation CurrentLocation, |
4206 | CXXMethodDecl *MethodDecl); |
4207 | |
4208 | /// Check a completed declaration of an implicit special member. |
4209 | void CheckImplicitSpecialMemberDeclaration(Scope *S, FunctionDecl *FD); |
4210 | |
4211 | /// Determine whether the given function is an implicitly-deleted |
4212 | /// special member function. |
4213 | bool isImplicitlyDeleted(FunctionDecl *FD); |
4214 | |
4215 | /// Check whether 'this' shows up in the type of a static member |
4216 | /// function after the (naturally empty) cv-qualifier-seq would be. |
4217 | /// |
4218 | /// \returns true if an error occurred. |
4219 | bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method); |
4220 | |
4221 | /// Whether this' shows up in the exception specification of a static |
4222 | /// member function. |
4223 | bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method); |
4224 | |
4225 | /// Check whether 'this' shows up in the attributes of the given |
4226 | /// static member function. |
4227 | /// |
4228 | /// \returns true if an error occurred. |
4229 | bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method); |
4230 | |
4231 | bool CheckImmediateEscalatingFunctionDefinition( |
4232 | FunctionDecl *FD, const sema::FunctionScopeInfo *FSI); |
4233 | |
4234 | void DiagnoseImmediateEscalatingReason(FunctionDecl *FD); |
4235 | |
4236 | bool CompleteConstructorCall(CXXConstructorDecl *Constructor, |
4237 | QualType DeclInitType, MultiExprArg ArgsPtr, |
4238 | SourceLocation Loc, |
4239 | SmallVectorImpl<Expr *> &ConvertedArgs, |
4240 | bool AllowExplicit = false, |
4241 | bool IsListInitialization = false); |
4242 | |
4243 | /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an |
4244 | /// initializer for the declaration 'Dcl'. |
4245 | /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a |
4246 | /// static data member of class X, names should be looked up in the scope of |
4247 | /// class X. |
4248 | void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); |
4249 | |
4250 | /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an |
4251 | /// initializer for the declaration 'Dcl'. |
4252 | void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); |
4253 | |
4254 | /// Define the "body" of the conversion from a lambda object to a |
4255 | /// function pointer. |
4256 | /// |
4257 | /// This routine doesn't actually define a sensible body; rather, it fills |
4258 | /// in the initialization expression needed to copy the lambda object into |
4259 | /// the block, and IR generation actually generates the real body of the |
4260 | /// block pointer conversion. |
4261 | void |
4262 | DefineImplicitLambdaToFunctionPointerConversion(SourceLocation CurrentLoc, |
4263 | CXXConversionDecl *Conv); |
4264 | |
4265 | /// Define the "body" of the conversion from a lambda object to a |
4266 | /// block pointer. |
4267 | /// |
4268 | /// This routine doesn't actually define a sensible body; rather, it fills |
4269 | /// in the initialization expression needed to copy the lambda object into |
4270 | /// the block, and IR generation actually generates the real body of the |
4271 | /// block pointer conversion. |
4272 | void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc, |
4273 | CXXConversionDecl *Conv); |
4274 | |
4275 | Decl *ActOnStartLinkageSpecification(Scope *S, SourceLocation ExternLoc, |
4276 | Expr *LangStr, SourceLocation LBraceLoc); |
4277 | Decl *ActOnFinishLinkageSpecification(Scope *S, Decl *LinkageSpec, |
4278 | SourceLocation RBraceLoc); |
4279 | |
4280 | //===--------------------------------------------------------------------===// |
4281 | // C++ Classes |
4282 | // |
4283 | CXXRecordDecl *getCurrentClass(Scope *S, const CXXScopeSpec *SS); |
4284 | bool isCurrentClassName(const IdentifierInfo &II, Scope *S, |
4285 | const CXXScopeSpec *SS = nullptr); |
4286 | bool isCurrentClassNameTypo(IdentifierInfo *&II, const CXXScopeSpec *SS); |
4287 | |
4288 | bool ActOnAccessSpecifier(AccessSpecifier Access, SourceLocation ASLoc, |
4289 | SourceLocation ColonLoc, |
4290 | const ParsedAttributesView &Attrs); |
4291 | |
4292 | NamedDecl * |
4293 | ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, |
4294 | MultiTemplateParamsArg TemplateParameterLists, |
4295 | Expr *BitfieldWidth, const VirtSpecifiers &VS, |
4296 | InClassInitStyle InitStyle); |
4297 | |
4298 | void ActOnStartCXXInClassMemberInitializer(); |
4299 | void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl, |
4300 | SourceLocation EqualLoc, |
4301 | Expr *Init); |
4302 | |
4303 | MemInitResult |
4304 | ActOnMemInitializer(Decl *ConstructorD, Scope *S, CXXScopeSpec &SS, |
4305 | IdentifierInfo *MemberOrBase, ParsedType TemplateTypeTy, |
4306 | const DeclSpec &DS, SourceLocation IdLoc, |
4307 | SourceLocation LParenLoc, ArrayRef<Expr *> Args, |
4308 | SourceLocation RParenLoc, SourceLocation EllipsisLoc); |
4309 | |
4310 | MemInitResult ActOnMemInitializer(Decl *ConstructorD, Scope *S, |
4311 | CXXScopeSpec &SS, |
4312 | IdentifierInfo *MemberOrBase, |
4313 | ParsedType TemplateTypeTy, |
4314 | const DeclSpec &DS, SourceLocation IdLoc, |
4315 | Expr *InitList, SourceLocation EllipsisLoc); |
4316 | |
4317 | MemInitResult BuildMemInitializer(Decl *ConstructorD, Scope *S, |
4318 | CXXScopeSpec &SS, |
4319 | IdentifierInfo *MemberOrBase, |
4320 | ParsedType TemplateTypeTy, |
4321 | const DeclSpec &DS, SourceLocation IdLoc, |
4322 | Expr *Init, SourceLocation EllipsisLoc); |
4323 | |
4324 | MemInitResult BuildMemberInitializer(ValueDecl *Member, Expr *Init, |
4325 | SourceLocation IdLoc); |
4326 | |
4327 | MemInitResult BuildBaseInitializer(QualType BaseType, |
4328 | TypeSourceInfo *BaseTInfo, Expr *Init, |
4329 | CXXRecordDecl *ClassDecl, |
4330 | SourceLocation EllipsisLoc); |
4331 | |
4332 | MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, Expr *Init, |
4333 | CXXRecordDecl *ClassDecl); |
4334 | |
4335 | bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, |
4336 | CXXCtorInitializer *Initializer); |
4337 | |
4338 | bool SetCtorInitializers( |
4339 | CXXConstructorDecl *Constructor, bool AnyErrors, |
4340 | ArrayRef<CXXCtorInitializer *> Initializers = std::nullopt); |
4341 | |
4342 | void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); |
4343 | |
4344 | /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, |
4345 | /// mark all the non-trivial destructors of its members and bases as |
4346 | /// referenced. |
4347 | void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, |
4348 | CXXRecordDecl *Record); |
4349 | |
4350 | /// Mark destructors of virtual bases of this class referenced. In the Itanium |
4351 | /// C++ ABI, this is done when emitting a destructor for any non-abstract |
4352 | /// class. In the Microsoft C++ ABI, this is done any time a class's |
4353 | /// destructor is referenced. |
4354 | void MarkVirtualBaseDestructorsReferenced( |
4355 | SourceLocation Location, CXXRecordDecl *ClassDecl, |
4356 | llvm::SmallPtrSetImpl<const RecordType *> *DirectVirtualBases = nullptr); |
4357 | |
4358 | /// Do semantic checks to allow the complete destructor variant to be emitted |
4359 | /// when the destructor is defined in another translation unit. In the Itanium |
4360 | /// C++ ABI, destructor variants are emitted together. In the MS C++ ABI, they |
4361 | /// can be emitted in separate TUs. To emit the complete variant, run a subset |
4362 | /// of the checks performed when emitting a regular destructor. |
4363 | void CheckCompleteDestructorVariant(SourceLocation CurrentLocation, |
4364 | CXXDestructorDecl *Dtor); |
4365 | |
4366 | /// The list of classes whose vtables have been used within |
4367 | /// this translation unit, and the source locations at which the |
4368 | /// first use occurred. |
4369 | typedef std::pair<CXXRecordDecl *, SourceLocation> VTableUse; |
4370 | |
4371 | /// The list of vtables that are required but have not yet been |
4372 | /// materialized. |
4373 | SmallVector<VTableUse, 16> VTableUses; |
4374 | |
4375 | /// The set of classes whose vtables have been used within |
4376 | /// this translation unit, and a bit that will be true if the vtable is |
4377 | /// required to be emitted (otherwise, it should be emitted only if needed |
4378 | /// by code generation). |
4379 | llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; |
4380 | |
4381 | /// Load any externally-stored vtable uses. |
4382 | void LoadExternalVTableUses(); |
4383 | |
4384 | /// Note that the vtable for the given class was used at the |
4385 | /// given location. |
4386 | void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, |
4387 | bool DefinitionRequired = false); |
4388 | |
4389 | /// Mark the exception specifications of all virtual member functions |
4390 | /// in the given class as needed. |
4391 | void MarkVirtualMemberExceptionSpecsNeeded(SourceLocation Loc, |
4392 | const CXXRecordDecl *RD); |
4393 | |
4394 | /// MarkVirtualMembersReferenced - Will mark all members of the given |
4395 | /// CXXRecordDecl referenced. |
4396 | void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD, |
4397 | bool ConstexprOnly = false); |
4398 | |
4399 | /// Define all of the vtables that have been used in this |
4400 | /// translation unit and reference any virtual members used by those |
4401 | /// vtables. |
4402 | /// |
4403 | /// \returns true if any work was done, false otherwise. |
4404 | bool DefineUsedVTables(); |
4405 | |
4406 | void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); |
4407 | |
4408 | void ActOnMemInitializers(Decl *ConstructorDecl, SourceLocation ColonLoc, |
4409 | ArrayRef<CXXCtorInitializer *> MemInits, |
4410 | bool AnyErrors); |
4411 | |
4412 | /// Check class-level dllimport/dllexport attribute. The caller must |
4413 | /// ensure that referenceDLLExportedClassMethods is called some point later |
4414 | /// when all outer classes of Class are complete. |
4415 | void checkClassLevelDLLAttribute(CXXRecordDecl *Class); |
4416 | void checkClassLevelCodeSegAttribute(CXXRecordDecl *Class); |
4417 | |
4418 | void referenceDLLExportedClassMethods(); |
4419 | |
4420 | void propagateDLLAttrToBaseClassTemplate( |
4421 | CXXRecordDecl *Class, Attr *ClassAttr, |
4422 | ClassTemplateSpecializationDecl *BaseTemplateSpec, |
4423 | SourceLocation BaseLoc); |
4424 | |
4425 | void CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record); |
4426 | |
4427 | /// Check that the C++ class annoated with "trivial_abi" satisfies all the |
4428 | /// conditions that are needed for the attribute to have an effect. |
4429 | void checkIllFormedTrivialABIStruct(CXXRecordDecl &RD); |
4430 | |
4431 | void ActOnFinishCXXMemberSpecification(Scope *S, SourceLocation RLoc, |
4432 | Decl *TagDecl, SourceLocation LBrac, |
4433 | SourceLocation RBrac, |
4434 | const ParsedAttributesView &AttrList); |
4435 | void ActOnFinishCXXMemberDecls(); |
4436 | void ActOnFinishCXXNonNestedClass(); |
4437 | |
4438 | void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param); |
4439 | unsigned ActOnReenterTemplateScope(Decl *Template, |
4440 | llvm::function_ref<Scope *()> EnterScope); |
4441 | void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); |
4442 | void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
4443 | void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); |
4444 | void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); |
4445 | void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
4446 | void ActOnFinishDelayedMemberInitializers(Decl *Record); |
4447 | |
4448 | bool EvaluateStaticAssertMessageAsString(Expr *Message, std::string &Result, |
4449 | ASTContext &Ctx, |
4450 | bool ErrorOnInvalidMessage); |
4451 | Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
4452 | Expr *AssertExpr, Expr *AssertMessageExpr, |
4453 | SourceLocation RParenLoc); |
4454 | Decl *BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
4455 | Expr *AssertExpr, Expr *AssertMessageExpr, |
4456 | SourceLocation RParenLoc, bool Failed); |
4457 | void DiagnoseStaticAssertDetails(const Expr *E); |
4458 | |
4459 | Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, |
4460 | MultiTemplateParamsArg TemplateParams); |
4461 | NamedDecl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, |
4462 | MultiTemplateParamsArg TemplateParams); |
4463 | |
4464 | QualType CheckConstructorDeclarator(Declarator &D, QualType R, |
4465 | StorageClass &SC); |
4466 | void CheckConstructor(CXXConstructorDecl *Constructor); |
4467 | QualType CheckDestructorDeclarator(Declarator &D, QualType R, |
4468 | StorageClass &SC); |
4469 | bool CheckDestructor(CXXDestructorDecl *Destructor); |
4470 | void CheckConversionDeclarator(Declarator &D, QualType &R, StorageClass &SC); |
4471 | Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); |
4472 | bool CheckDeductionGuideDeclarator(Declarator &D, QualType &R, |
4473 | StorageClass &SC); |
4474 | |
4475 | void CheckExplicitlyDefaultedFunction(Scope *S, FunctionDecl *MD); |
4476 | |
4477 | bool CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD, |
4478 | CXXSpecialMemberKind CSM, |
4479 | SourceLocation DefaultLoc); |
4480 | void CheckDelayedMemberExceptionSpecs(); |
4481 | |
4482 | /// Kinds of defaulted comparison operator functions. |
4483 | enum class DefaultedComparisonKind : unsigned char { |
4484 | /// This is not a defaultable comparison operator. |
4485 | None, |
4486 | /// This is an operator== that should be implemented as a series of |
4487 | /// subobject comparisons. |
4488 | Equal, |
4489 | /// This is an operator<=> that should be implemented as a series of |
4490 | /// subobject comparisons. |
4491 | ThreeWay, |
4492 | /// This is an operator!= that should be implemented as a rewrite in terms |
4493 | /// of a == comparison. |
4494 | NotEqual, |
4495 | /// This is an <, <=, >, or >= that should be implemented as a rewrite in |
4496 | /// terms of a <=> comparison. |
4497 | Relational, |
4498 | }; |
4499 | |
4500 | bool CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *MD, |
4501 | DefaultedComparisonKind DCK); |
4502 | void DeclareImplicitEqualityComparison(CXXRecordDecl *RD, |
4503 | FunctionDecl *Spaceship); |
4504 | void DefineDefaultedComparison(SourceLocation Loc, FunctionDecl *FD, |
4505 | DefaultedComparisonKind DCK); |
4506 | |
4507 | void CheckExplicitObjectMemberFunction(Declarator &D, DeclarationName Name, |
4508 | QualType R, bool IsLambda, |
4509 | DeclContext *DC = nullptr); |
4510 | void CheckExplicitObjectMemberFunction(DeclContext *DC, Declarator &D, |
4511 | DeclarationName Name, QualType R); |
4512 | void CheckExplicitObjectLambda(Declarator &D); |
4513 | |
4514 | //===--------------------------------------------------------------------===// |
4515 | // C++ Derived Classes |
4516 | // |
4517 | |
4518 | /// ActOnBaseSpecifier - Parsed a base specifier |
4519 | CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, |
4520 | SourceRange SpecifierRange, bool Virtual, |
4521 | AccessSpecifier Access, |
4522 | TypeSourceInfo *TInfo, |
4523 | SourceLocation EllipsisLoc); |
4524 | |
4525 | BaseResult ActOnBaseSpecifier(Decl *classdecl, SourceRange SpecifierRange, |
4526 | const ParsedAttributesView &Attrs, bool Virtual, |
4527 | AccessSpecifier Access, ParsedType basetype, |
4528 | SourceLocation BaseLoc, |
4529 | SourceLocation EllipsisLoc); |
4530 | |
4531 | bool AttachBaseSpecifiers(CXXRecordDecl *Class, |
4532 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
4533 | void ActOnBaseSpecifiers(Decl *ClassDecl, |
4534 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
4535 | |
4536 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base); |
4537 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base, |
4538 | CXXBasePaths &Paths); |
4539 | |
4540 | // FIXME: I don't like this name. |
4541 | void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); |
4542 | |
4543 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
4544 | SourceLocation Loc, SourceRange Range, |
4545 | CXXCastPath *BasePath = nullptr, |
4546 | bool IgnoreAccess = false); |
4547 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
4548 | unsigned InaccessibleBaseID, |
4549 | unsigned AmbiguousBaseConvID, |
4550 | SourceLocation Loc, SourceRange Range, |
4551 | DeclarationName Name, CXXCastPath *BasePath, |
4552 | bool IgnoreAccess = false); |
4553 | |
4554 | std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); |
4555 | |
4556 | bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New, |
4557 | const CXXMethodDecl *Old); |
4558 | |
4559 | /// CheckOverridingFunctionReturnType - Checks whether the return types are |
4560 | /// covariant, according to C++ [class.virtual]p5. |
4561 | bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, |
4562 | const CXXMethodDecl *Old); |
4563 | |
4564 | // Check that the overriding method has no explicit object parameter. |
4565 | bool CheckExplicitObjectOverride(CXXMethodDecl *New, |
4566 | const CXXMethodDecl *Old); |
4567 | |
4568 | bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); |
4569 | |
4570 | /// CheckOverrideControl - Check C++11 override control semantics. |
4571 | void CheckOverrideControl(NamedDecl *D); |
4572 | |
4573 | /// DiagnoseAbsenceOfOverrideControl - Diagnose if 'override' keyword was |
4574 | /// not used in the declaration of an overriding method. |
4575 | void DiagnoseAbsenceOfOverrideControl(NamedDecl *D, bool Inconsistent); |
4576 | |
4577 | /// CheckForFunctionMarkedFinal - Checks whether a virtual member function |
4578 | /// overrides a virtual member function marked 'final', according to |
4579 | /// C++11 [class.virtual]p4. |
4580 | bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, |
4581 | const CXXMethodDecl *Old); |
4582 | |
4583 | enum AbstractDiagSelID { |
4584 | AbstractNone = -1, |
4585 | AbstractReturnType, |
4586 | AbstractParamType, |
4587 | AbstractVariableType, |
4588 | AbstractFieldType, |
4589 | AbstractIvarType, |
4590 | AbstractSynthesizedIvarType, |
4591 | AbstractArrayType |
4592 | }; |
4593 | |
4594 | struct TypeDiagnoser; |
4595 | |
4596 | bool isAbstractType(SourceLocation Loc, QualType T); |
4597 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, |
4598 | TypeDiagnoser &Diagnoser); |
4599 | template <typename... Ts> |
4600 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, |
4601 | const Ts &...Args) { |
4602 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
4603 | return RequireNonAbstractType(Loc, T, Diagnoser); |
4604 | } |
4605 | |
4606 | void DiagnoseAbstractType(const CXXRecordDecl *RD); |
4607 | |
4608 | //===--------------------------------------------------------------------===// |
4609 | // C++ Overloaded Operators [C++ 13.5] |
4610 | // |
4611 | |
4612 | bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); |
4613 | |
4614 | bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); |
4615 | |
4616 | /// ActOnExplicitBoolSpecifier - Build an ExplicitSpecifier from an expression |
4617 | /// found in an explicit(bool) specifier. |
4618 | ExplicitSpecifier ActOnExplicitBoolSpecifier(Expr *E); |
4619 | |
4620 | /// tryResolveExplicitSpecifier - Attempt to resolve the explict specifier. |
4621 | /// Returns true if the explicit specifier is now resolved. |
4622 | bool tryResolveExplicitSpecifier(ExplicitSpecifier &ExplicitSpec); |
4623 | |
4624 | DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); |
4625 | |
4626 | // Emitting members of dllexported classes is delayed until the class |
4627 | // (including field initializers) is fully parsed. |
4628 | SmallVector<CXXRecordDecl *, 4> DelayedDllExportClasses; |
4629 | SmallVector<CXXMethodDecl *, 4> DelayedDllExportMemberFunctions; |
4630 | |
4631 | void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old); |
4632 | bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S); |
4633 | |
4634 | /// Helpers for dealing with blocks and functions. |
4635 | void CheckCXXDefaultArguments(FunctionDecl *FD); |
4636 | void (Declarator &D); |
4637 | |
4638 | CXXSpecialMemberKind getSpecialMember(const CXXMethodDecl *MD) { |
4639 | return getDefaultedFunctionKind(MD).asSpecialMember(); |
4640 | } |
4641 | |
4642 | VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, |
4643 | SourceLocation StartLoc, |
4644 | SourceLocation IdLoc, |
4645 | const IdentifierInfo *Id); |
4646 | |
4647 | Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); |
4648 | |
4649 | void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); |
4650 | |
4651 | DeclResult ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, |
4652 | unsigned TagSpec, SourceLocation TagLoc, |
4653 | CXXScopeSpec &SS, IdentifierInfo *Name, |
4654 | SourceLocation NameLoc, |
4655 | const ParsedAttributesView &Attr, |
4656 | MultiTemplateParamsArg TempParamLists); |
4657 | |
4658 | MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD, |
4659 | SourceLocation DeclStart, Declarator &D, |
4660 | Expr *BitfieldWidth, |
4661 | InClassInitStyle InitStyle, |
4662 | AccessSpecifier AS, |
4663 | const ParsedAttr &MSPropertyAttr); |
4664 | |
4665 | void DiagnoseNontrivial(const CXXRecordDecl *Record, |
4666 | CXXSpecialMemberKind CSM); |
4667 | |
4668 | enum TrivialABIHandling { |
4669 | /// The triviality of a method unaffected by "trivial_abi". |
4670 | TAH_IgnoreTrivialABI, |
4671 | |
4672 | /// The triviality of a method affected by "trivial_abi". |
4673 | TAH_ConsiderTrivialABI |
4674 | }; |
4675 | |
4676 | bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMemberKind CSM, |
4677 | TrivialABIHandling TAH = TAH_IgnoreTrivialABI, |
4678 | bool Diagnose = false); |
4679 | |
4680 | /// For a defaulted function, the kind of defaulted function that it is. |
4681 | class DefaultedFunctionKind { |
4682 | LLVM_PREFERRED_TYPE(CXXSpecialMemberKind) |
4683 | unsigned SpecialMember : 8; |
4684 | unsigned Comparison : 8; |
4685 | |
4686 | public: |
4687 | DefaultedFunctionKind() |
4688 | : SpecialMember(llvm::to_underlying(E: CXXSpecialMemberKind::Invalid)), |
4689 | Comparison(llvm::to_underlying(E: DefaultedComparisonKind::None)) {} |
4690 | DefaultedFunctionKind(CXXSpecialMemberKind CSM) |
4691 | : SpecialMember(llvm::to_underlying(E: CSM)), |
4692 | Comparison(llvm::to_underlying(E: DefaultedComparisonKind::None)) {} |
4693 | DefaultedFunctionKind(DefaultedComparisonKind Comp) |
4694 | : SpecialMember(llvm::to_underlying(E: CXXSpecialMemberKind::Invalid)), |
4695 | Comparison(llvm::to_underlying(E: Comp)) {} |
4696 | |
4697 | bool isSpecialMember() const { |
4698 | return static_cast<CXXSpecialMemberKind>(SpecialMember) != |
4699 | CXXSpecialMemberKind::Invalid; |
4700 | } |
4701 | bool isComparison() const { |
4702 | return static_cast<DefaultedComparisonKind>(Comparison) != |
4703 | DefaultedComparisonKind::None; |
4704 | } |
4705 | |
4706 | explicit operator bool() const { |
4707 | return isSpecialMember() || isComparison(); |
4708 | } |
4709 | |
4710 | CXXSpecialMemberKind asSpecialMember() const { |
4711 | return static_cast<CXXSpecialMemberKind>(SpecialMember); |
4712 | } |
4713 | DefaultedComparisonKind asComparison() const { |
4714 | return static_cast<DefaultedComparisonKind>(Comparison); |
4715 | } |
4716 | |
4717 | /// Get the index of this function kind for use in diagnostics. |
4718 | unsigned getDiagnosticIndex() const { |
4719 | static_assert(llvm::to_underlying(E: CXXSpecialMemberKind::Invalid) > |
4720 | llvm::to_underlying(E: CXXSpecialMemberKind::Destructor), |
4721 | "invalid should have highest index" ); |
4722 | static_assert((unsigned)DefaultedComparisonKind::None == 0, |
4723 | "none should be equal to zero" ); |
4724 | return SpecialMember + Comparison; |
4725 | } |
4726 | }; |
4727 | |
4728 | DefaultedFunctionKind getDefaultedFunctionKind(const FunctionDecl *FD); |
4729 | |
4730 | /// Handle a C++11 empty-declaration and attribute-declaration. |
4731 | Decl *ActOnEmptyDeclaration(Scope *S, const ParsedAttributesView &AttrList, |
4732 | SourceLocation SemiLoc); |
4733 | |
4734 | enum class CheckConstexprKind { |
4735 | /// Diagnose issues that are non-constant or that are extensions. |
4736 | Diagnose, |
4737 | /// Identify whether this function satisfies the formal rules for constexpr |
4738 | /// functions in the current lanugage mode (with no extensions). |
4739 | CheckValid |
4740 | }; |
4741 | |
4742 | bool CheckConstexprFunctionDefinition(const FunctionDecl *FD, |
4743 | CheckConstexprKind Kind); |
4744 | |
4745 | void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD); |
4746 | void |
4747 | FindHiddenVirtualMethods(CXXMethodDecl *MD, |
4748 | SmallVectorImpl<CXXMethodDecl *> &OverloadedMethods); |
4749 | void |
4750 | NoteHiddenVirtualMethods(CXXMethodDecl *MD, |
4751 | SmallVectorImpl<CXXMethodDecl *> &OverloadedMethods); |
4752 | void ActOnParamDefaultArgument(Decl *param, SourceLocation EqualLoc, |
4753 | Expr *defarg); |
4754 | void ActOnParamUnparsedDefaultArgument(Decl *param, SourceLocation EqualLoc, |
4755 | SourceLocation ArgLoc); |
4756 | void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc, |
4757 | Expr *DefaultArg); |
4758 | ExprResult ConvertParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
4759 | SourceLocation EqualLoc); |
4760 | void SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
4761 | SourceLocation EqualLoc); |
4762 | |
4763 | void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc); |
4764 | void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc, |
4765 | StringLiteral *Message = nullptr); |
4766 | void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc); |
4767 | |
4768 | void SetFunctionBodyKind(Decl *D, SourceLocation Loc, FnBodyKind BodyKind, |
4769 | StringLiteral *DeletedMessage = nullptr); |
4770 | void ActOnStartTrailingRequiresClause(Scope *S, Declarator &D); |
4771 | ExprResult ActOnFinishTrailingRequiresClause(ExprResult ConstraintExpr); |
4772 | ExprResult ActOnRequiresClause(ExprResult ConstraintExpr); |
4773 | |
4774 | NamedDecl * |
4775 | ActOnDecompositionDeclarator(Scope *S, Declarator &D, |
4776 | MultiTemplateParamsArg TemplateParamLists); |
4777 | void DiagPlaceholderVariableDefinition(SourceLocation Loc); |
4778 | bool DiagRedefinedPlaceholderFieldDecl(SourceLocation Loc, |
4779 | RecordDecl *ClassDecl, |
4780 | const IdentifierInfo *Name); |
4781 | |
4782 | void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD); |
4783 | |
4784 | /// Stack containing information needed when in C++2a an 'auto' is encountered |
4785 | /// in a function declaration parameter type specifier in order to invent a |
4786 | /// corresponding template parameter in the enclosing abbreviated function |
4787 | /// template. This information is also present in LambdaScopeInfo, stored in |
4788 | /// the FunctionScopes stack. |
4789 | SmallVector<InventedTemplateParameterInfo, 4> InventedParameterInfos; |
4790 | |
4791 | /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. |
4792 | std::unique_ptr<CXXFieldCollector> FieldCollector; |
4793 | |
4794 | typedef llvm::SmallSetVector<const NamedDecl *, 16> NamedDeclSetType; |
4795 | /// Set containing all declared private fields that are not used. |
4796 | NamedDeclSetType UnusedPrivateFields; |
4797 | |
4798 | typedef llvm::SmallPtrSet<const CXXRecordDecl *, 8> RecordDeclSetTy; |
4799 | |
4800 | /// PureVirtualClassDiagSet - a set of class declarations which we have |
4801 | /// emitted a list of pure virtual functions. Used to prevent emitting the |
4802 | /// same list more than once. |
4803 | std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet; |
4804 | |
4805 | typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource, |
4806 | &ExternalSemaSource::ReadDelegatingConstructors, 2, 2> |
4807 | DelegatingCtorDeclsType; |
4808 | |
4809 | /// All the delegating constructors seen so far in the file, used for |
4810 | /// cycle detection at the end of the TU. |
4811 | DelegatingCtorDeclsType DelegatingCtorDecls; |
4812 | |
4813 | /// The C++ "std" namespace, where the standard library resides. |
4814 | LazyDeclPtr StdNamespace; |
4815 | |
4816 | /// The C++ "std::initializer_list" template, which is defined in |
4817 | /// \<initializer_list>. |
4818 | ClassTemplateDecl *StdInitializerList; |
4819 | |
4820 | // Contains the locations of the beginning of unparsed default |
4821 | // argument locations. |
4822 | llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs; |
4823 | |
4824 | /// UndefinedInternals - all the used, undefined objects which require a |
4825 | /// definition in this translation unit. |
4826 | llvm::MapVector<NamedDecl *, SourceLocation> UndefinedButUsed; |
4827 | |
4828 | typedef llvm::PointerIntPair<CXXRecordDecl *, 3, CXXSpecialMemberKind> |
4829 | SpecialMemberDecl; |
4830 | |
4831 | /// The C++ special members which we are currently in the process of |
4832 | /// declaring. If this process recursively triggers the declaration of the |
4833 | /// same special member, we should act as if it is not yet declared. |
4834 | llvm::SmallPtrSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared; |
4835 | |
4836 | void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD); |
4837 | |
4838 | void ActOnDefaultCtorInitializers(Decl *CDtorDecl); |
4839 | |
4840 | typedef ProcessingContextState ParsingClassState; |
4841 | ParsingClassState PushParsingClass() { |
4842 | ParsingClassDepth++; |
4843 | return DelayedDiagnostics.pushUndelayed(); |
4844 | } |
4845 | void PopParsingClass(ParsingClassState state) { |
4846 | ParsingClassDepth--; |
4847 | DelayedDiagnostics.popUndelayed(state); |
4848 | } |
4849 | |
4850 | private: |
4851 | void setupImplicitSpecialMemberType(CXXMethodDecl *SpecialMem, |
4852 | QualType ResultTy, |
4853 | ArrayRef<QualType> Args); |
4854 | |
4855 | // A cache representing if we've fully checked the various comparison category |
4856 | // types stored in ASTContext. The bit-index corresponds to the integer value |
4857 | // of a ComparisonCategoryType enumerator. |
4858 | llvm::SmallBitVector FullyCheckedComparisonCategories; |
4859 | |
4860 | ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl, |
4861 | CXXScopeSpec &SS, |
4862 | ParsedType TemplateTypeTy, |
4863 | IdentifierInfo *MemberOrBase); |
4864 | |
4865 | /// Check if there is a field shadowing. |
4866 | void CheckShadowInheritedFields(const SourceLocation &Loc, |
4867 | DeclarationName FieldName, |
4868 | const CXXRecordDecl *RD, |
4869 | bool DeclIsField = true); |
4870 | |
4871 | ///@} |
4872 | |
4873 | // |
4874 | // |
4875 | // ------------------------------------------------------------------------- |
4876 | // |
4877 | // |
4878 | |
4879 | /// \name C++ Exception Specifications |
4880 | /// Implementations are in SemaExceptionSpec.cpp |
4881 | ///@{ |
4882 | |
4883 | public: |
4884 | /// All the overriding functions seen during a class definition |
4885 | /// that had their exception spec checks delayed, plus the overridden |
4886 | /// function. |
4887 | SmallVector<std::pair<const CXXMethodDecl *, const CXXMethodDecl *>, 2> |
4888 | DelayedOverridingExceptionSpecChecks; |
4889 | |
4890 | /// All the function redeclarations seen during a class definition that had |
4891 | /// their exception spec checks delayed, plus the prior declaration they |
4892 | /// should be checked against. Except during error recovery, the new decl |
4893 | /// should always be a friend declaration, as that's the only valid way to |
4894 | /// redeclare a special member before its class is complete. |
4895 | SmallVector<std::pair<FunctionDecl *, FunctionDecl *>, 2> |
4896 | DelayedEquivalentExceptionSpecChecks; |
4897 | |
4898 | /// Determine if we're in a case where we need to (incorrectly) eagerly |
4899 | /// parse an exception specification to work around a libstdc++ bug. |
4900 | bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D); |
4901 | |
4902 | /// Check the given noexcept-specifier, convert its expression, and compute |
4903 | /// the appropriate ExceptionSpecificationType. |
4904 | ExprResult ActOnNoexceptSpec(Expr *NoexceptExpr, |
4905 | ExceptionSpecificationType &EST); |
4906 | |
4907 | CanThrowResult canThrow(const Stmt *E); |
4908 | /// Determine whether the callee of a particular function call can throw. |
4909 | /// E, D and Loc are all optional. |
4910 | static CanThrowResult canCalleeThrow(Sema &S, const Expr *E, const Decl *D, |
4911 | SourceLocation Loc = SourceLocation()); |
4912 | const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc, |
4913 | const FunctionProtoType *FPT); |
4914 | void UpdateExceptionSpec(FunctionDecl *FD, |
4915 | const FunctionProtoType::ExceptionSpecInfo &ESI); |
4916 | bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range); |
4917 | bool CheckDistantExceptionSpec(QualType T); |
4918 | bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New); |
4919 | bool CheckEquivalentExceptionSpec(const FunctionProtoType *Old, |
4920 | SourceLocation OldLoc, |
4921 | const FunctionProtoType *New, |
4922 | SourceLocation NewLoc); |
4923 | bool CheckEquivalentExceptionSpec(const PartialDiagnostic &DiagID, |
4924 | const PartialDiagnostic &NoteID, |
4925 | const FunctionProtoType *Old, |
4926 | SourceLocation OldLoc, |
4927 | const FunctionProtoType *New, |
4928 | SourceLocation NewLoc); |
4929 | bool handlerCanCatch(QualType HandlerType, QualType ExceptionType); |
4930 | bool CheckExceptionSpecSubset( |
4931 | const PartialDiagnostic &DiagID, const PartialDiagnostic &NestedDiagID, |
4932 | const PartialDiagnostic &NoteID, const PartialDiagnostic &NoThrowDiagID, |
4933 | const FunctionProtoType *Superset, bool SkipSupersetFirstParameter, |
4934 | SourceLocation SuperLoc, const FunctionProtoType *Subset, |
4935 | bool SkipSubsetFirstParameter, SourceLocation SubLoc); |
4936 | bool CheckParamExceptionSpec( |
4937 | const PartialDiagnostic &NestedDiagID, const PartialDiagnostic &NoteID, |
4938 | const FunctionProtoType *Target, bool SkipTargetFirstParameter, |
4939 | SourceLocation TargetLoc, const FunctionProtoType *Source, |
4940 | bool SkipSourceFirstParameter, SourceLocation SourceLoc); |
4941 | |
4942 | bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); |
4943 | |
4944 | /// CheckOverridingFunctionExceptionSpec - Checks whether the exception |
4945 | /// spec is a subset of base spec. |
4946 | bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, |
4947 | const CXXMethodDecl *Old); |
4948 | |
4949 | ///@} |
4950 | |
4951 | // |
4952 | // |
4953 | // ------------------------------------------------------------------------- |
4954 | // |
4955 | // |
4956 | |
4957 | /// \name Expressions |
4958 | /// Implementations are in SemaExpr.cpp |
4959 | ///@{ |
4960 | |
4961 | public: |
4962 | /// Describes how the expressions currently being parsed are |
4963 | /// evaluated at run-time, if at all. |
4964 | enum class ExpressionEvaluationContext { |
4965 | /// The current expression and its subexpressions occur within an |
4966 | /// unevaluated operand (C++11 [expr]p7), such as the subexpression of |
4967 | /// \c sizeof, where the type of the expression may be significant but |
4968 | /// no code will be generated to evaluate the value of the expression at |
4969 | /// run time. |
4970 | Unevaluated, |
4971 | |
4972 | /// The current expression occurs within a braced-init-list within |
4973 | /// an unevaluated operand. This is mostly like a regular unevaluated |
4974 | /// context, except that we still instantiate constexpr functions that are |
4975 | /// referenced here so that we can perform narrowing checks correctly. |
4976 | UnevaluatedList, |
4977 | |
4978 | /// The current expression occurs within a discarded statement. |
4979 | /// This behaves largely similarly to an unevaluated operand in preventing |
4980 | /// definitions from being required, but not in other ways. |
4981 | DiscardedStatement, |
4982 | |
4983 | /// The current expression occurs within an unevaluated |
4984 | /// operand that unconditionally permits abstract references to |
4985 | /// fields, such as a SIZE operator in MS-style inline assembly. |
4986 | UnevaluatedAbstract, |
4987 | |
4988 | /// The current context is "potentially evaluated" in C++11 terms, |
4989 | /// but the expression is evaluated at compile-time (like the values of |
4990 | /// cases in a switch statement). |
4991 | ConstantEvaluated, |
4992 | |
4993 | /// In addition of being constant evaluated, the current expression |
4994 | /// occurs in an immediate function context - either a consteval function |
4995 | /// or a consteval if statement. |
4996 | ImmediateFunctionContext, |
4997 | |
4998 | /// The current expression is potentially evaluated at run time, |
4999 | /// which means that code may be generated to evaluate the value of the |
5000 | /// expression at run time. |
5001 | PotentiallyEvaluated, |
5002 | |
5003 | /// The current expression is potentially evaluated, but any |
5004 | /// declarations referenced inside that expression are only used if |
5005 | /// in fact the current expression is used. |
5006 | /// |
5007 | /// This value is used when parsing default function arguments, for which |
5008 | /// we would like to provide diagnostics (e.g., passing non-POD arguments |
5009 | /// through varargs) but do not want to mark declarations as "referenced" |
5010 | /// until the default argument is used. |
5011 | PotentiallyEvaluatedIfUsed |
5012 | }; |
5013 | |
5014 | /// Store a set of either DeclRefExprs or MemberExprs that contain a reference |
5015 | /// to a variable (constant) that may or may not be odr-used in this Expr, and |
5016 | /// we won't know until all lvalue-to-rvalue and discarded value conversions |
5017 | /// have been applied to all subexpressions of the enclosing full expression. |
5018 | /// This is cleared at the end of each full expression. |
5019 | using MaybeODRUseExprSet = llvm::SmallSetVector<Expr *, 4>; |
5020 | MaybeODRUseExprSet MaybeODRUseExprs; |
5021 | |
5022 | using ImmediateInvocationCandidate = llvm::PointerIntPair<ConstantExpr *, 1>; |
5023 | |
5024 | /// Data structure used to record current or nested |
5025 | /// expression evaluation contexts. |
5026 | struct ExpressionEvaluationContextRecord { |
5027 | /// The expression evaluation context. |
5028 | ExpressionEvaluationContext Context; |
5029 | |
5030 | /// Whether the enclosing context needed a cleanup. |
5031 | CleanupInfo ParentCleanup; |
5032 | |
5033 | /// The number of active cleanup objects when we entered |
5034 | /// this expression evaluation context. |
5035 | unsigned NumCleanupObjects; |
5036 | |
5037 | /// The number of typos encountered during this expression evaluation |
5038 | /// context (i.e. the number of TypoExprs created). |
5039 | unsigned NumTypos; |
5040 | |
5041 | MaybeODRUseExprSet SavedMaybeODRUseExprs; |
5042 | |
5043 | /// The lambdas that are present within this context, if it |
5044 | /// is indeed an unevaluated context. |
5045 | SmallVector<LambdaExpr *, 2> Lambdas; |
5046 | |
5047 | /// The declaration that provides context for lambda expressions |
5048 | /// and block literals if the normal declaration context does not |
5049 | /// suffice, e.g., in a default function argument. |
5050 | Decl *ManglingContextDecl; |
5051 | |
5052 | /// If we are processing a decltype type, a set of call expressions |
5053 | /// for which we have deferred checking the completeness of the return type. |
5054 | SmallVector<CallExpr *, 8> DelayedDecltypeCalls; |
5055 | |
5056 | /// If we are processing a decltype type, a set of temporary binding |
5057 | /// expressions for which we have deferred checking the destructor. |
5058 | SmallVector<CXXBindTemporaryExpr *, 8> DelayedDecltypeBinds; |
5059 | |
5060 | llvm::SmallPtrSet<const Expr *, 8> PossibleDerefs; |
5061 | |
5062 | /// Expressions appearing as the LHS of a volatile assignment in this |
5063 | /// context. We produce a warning for these when popping the context if |
5064 | /// they are not discarded-value expressions nor unevaluated operands. |
5065 | SmallVector<Expr *, 2> VolatileAssignmentLHSs; |
5066 | |
5067 | /// Set of candidates for starting an immediate invocation. |
5068 | llvm::SmallVector<ImmediateInvocationCandidate, 4> |
5069 | ImmediateInvocationCandidates; |
5070 | |
5071 | /// Set of DeclRefExprs referencing a consteval function when used in a |
5072 | /// context not already known to be immediately invoked. |
5073 | llvm::SmallPtrSet<DeclRefExpr *, 4> ReferenceToConsteval; |
5074 | |
5075 | /// P2718R0 - Lifetime extension in range-based for loops. |
5076 | /// MaterializeTemporaryExprs in for-range-init expressions which need to |
5077 | /// extend lifetime. Add MaterializeTemporaryExpr* if the value of |
5078 | /// InLifetimeExtendingContext is true. |
5079 | SmallVector<MaterializeTemporaryExpr *, 8> ForRangeLifetimeExtendTemps; |
5080 | |
5081 | /// \brief Describes whether we are in an expression constext which we have |
5082 | /// to handle differently. |
5083 | enum ExpressionKind { |
5084 | EK_Decltype, |
5085 | EK_TemplateArgument, |
5086 | EK_BoundsAttrArgument, |
5087 | EK_Other |
5088 | } ExprContext; |
5089 | |
5090 | // A context can be nested in both a discarded statement context and |
5091 | // an immediate function context, so they need to be tracked independently. |
5092 | bool InDiscardedStatement; |
5093 | bool InImmediateFunctionContext; |
5094 | bool InImmediateEscalatingFunctionContext; |
5095 | |
5096 | bool IsCurrentlyCheckingDefaultArgumentOrInitializer = false; |
5097 | |
5098 | // We are in a constant context, but we also allow |
5099 | // non constant expressions, for example for array bounds (which may be |
5100 | // VLAs). |
5101 | bool InConditionallyConstantEvaluateContext = false; |
5102 | |
5103 | /// Whether we are currently in a context in which all temporaries must be |
5104 | /// lifetime-extended, even if they're not bound to a reference (for |
5105 | /// example, in a for-range initializer). |
5106 | bool InLifetimeExtendingContext = false; |
5107 | |
5108 | // When evaluating immediate functions in the initializer of a default |
5109 | // argument or default member initializer, this is the declaration whose |
5110 | // default initializer is being evaluated and the location of the call |
5111 | // or constructor definition. |
5112 | struct InitializationContext { |
5113 | InitializationContext(SourceLocation Loc, ValueDecl *Decl, |
5114 | DeclContext *Context) |
5115 | : Loc(Loc), Decl(Decl), Context(Context) { |
5116 | assert(Decl && Context && "invalid initialization context" ); |
5117 | } |
5118 | |
5119 | SourceLocation Loc; |
5120 | ValueDecl *Decl = nullptr; |
5121 | DeclContext *Context = nullptr; |
5122 | }; |
5123 | std::optional<InitializationContext> DelayedDefaultInitializationContext; |
5124 | |
5125 | ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context, |
5126 | unsigned NumCleanupObjects, |
5127 | CleanupInfo ParentCleanup, |
5128 | Decl *ManglingContextDecl, |
5129 | ExpressionKind ExprContext) |
5130 | : Context(Context), ParentCleanup(ParentCleanup), |
5131 | NumCleanupObjects(NumCleanupObjects), NumTypos(0), |
5132 | ManglingContextDecl(ManglingContextDecl), ExprContext(ExprContext), |
5133 | InDiscardedStatement(false), InImmediateFunctionContext(false), |
5134 | InImmediateEscalatingFunctionContext(false) {} |
5135 | |
5136 | bool isUnevaluated() const { |
5137 | return Context == ExpressionEvaluationContext::Unevaluated || |
5138 | Context == ExpressionEvaluationContext::UnevaluatedAbstract || |
5139 | Context == ExpressionEvaluationContext::UnevaluatedList; |
5140 | } |
5141 | |
5142 | bool isConstantEvaluated() const { |
5143 | return Context == ExpressionEvaluationContext::ConstantEvaluated || |
5144 | Context == ExpressionEvaluationContext::ImmediateFunctionContext; |
5145 | } |
5146 | |
5147 | bool isImmediateFunctionContext() const { |
5148 | return Context == ExpressionEvaluationContext::ImmediateFunctionContext || |
5149 | (Context == ExpressionEvaluationContext::DiscardedStatement && |
5150 | InImmediateFunctionContext) || |
5151 | // C++23 [expr.const]p14: |
5152 | // An expression or conversion is in an immediate function |
5153 | // context if it is potentially evaluated and either: |
5154 | // * its innermost enclosing non-block scope is a function |
5155 | // parameter scope of an immediate function, or |
5156 | // * its enclosing statement is enclosed by the compound- |
5157 | // statement of a consteval if statement. |
5158 | (Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
5159 | InImmediateFunctionContext); |
5160 | } |
5161 | |
5162 | bool isDiscardedStatementContext() const { |
5163 | return Context == ExpressionEvaluationContext::DiscardedStatement || |
5164 | (Context == |
5165 | ExpressionEvaluationContext::ImmediateFunctionContext && |
5166 | InDiscardedStatement); |
5167 | } |
5168 | }; |
5169 | |
5170 | const ExpressionEvaluationContextRecord ¤tEvaluationContext() const { |
5171 | assert(!ExprEvalContexts.empty() && |
5172 | "Must be in an expression evaluation context" ); |
5173 | return ExprEvalContexts.back(); |
5174 | }; |
5175 | |
5176 | bool isBoundsAttrContext() const { |
5177 | return ExprEvalContexts.back().ExprContext == |
5178 | ExpressionEvaluationContextRecord::ExpressionKind:: |
5179 | EK_BoundsAttrArgument; |
5180 | } |
5181 | |
5182 | /// Increment when we find a reference; decrement when we find an ignored |
5183 | /// assignment. Ultimately the value is 0 if every reference is an ignored |
5184 | /// assignment. |
5185 | llvm::DenseMap<const VarDecl *, int> RefsMinusAssignments; |
5186 | |
5187 | /// Used to control the generation of ExprWithCleanups. |
5188 | CleanupInfo Cleanup; |
5189 | |
5190 | /// ExprCleanupObjects - This is the stack of objects requiring |
5191 | /// cleanup that are created by the current full expression. |
5192 | SmallVector<ExprWithCleanups::CleanupObject, 8> ExprCleanupObjects; |
5193 | |
5194 | // AssignmentAction - This is used by all the assignment diagnostic functions |
5195 | // to represent what is actually causing the operation |
5196 | enum AssignmentAction { |
5197 | AA_Assigning, |
5198 | AA_Passing, |
5199 | AA_Returning, |
5200 | AA_Converting, |
5201 | AA_Initializing, |
5202 | AA_Sending, |
5203 | AA_Casting, |
5204 | AA_Passing_CFAudited |
5205 | }; |
5206 | |
5207 | bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid); |
5208 | // A version of DiagnoseUseOfDecl that should be used if overload resolution |
5209 | // has been used to find this declaration, which means we don't have to bother |
5210 | // checking the trailing requires clause. |
5211 | bool DiagnoseUseOfOverloadedDecl(NamedDecl *D, SourceLocation Loc) { |
5212 | return DiagnoseUseOfDecl( |
5213 | D, Locs: Loc, /*UnknownObjCClass=*/UnknownObjCClass: nullptr, /*ObjCPropertyAccess=*/ObjCPropertyAccess: false, |
5214 | /*AvoidPartialAvailabilityChecks=*/AvoidPartialAvailabilityChecks: false, /*ClassReceiver=*/ClassReciever: nullptr, |
5215 | /*SkipTrailingRequiresClause=*/SkipTrailingRequiresClause: true); |
5216 | } |
5217 | |
5218 | bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
5219 | const ObjCInterfaceDecl *UnknownObjCClass = nullptr, |
5220 | bool ObjCPropertyAccess = false, |
5221 | bool AvoidPartialAvailabilityChecks = false, |
5222 | ObjCInterfaceDecl *ClassReciever = nullptr, |
5223 | bool SkipTrailingRequiresClause = false); |
5224 | void NoteDeletedFunction(FunctionDecl *FD); |
5225 | |
5226 | void DiagnoseSentinelCalls(const NamedDecl *D, SourceLocation Loc, |
5227 | ArrayRef<Expr *> Args); |
5228 | |
5229 | void PushExpressionEvaluationContext( |
5230 | ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl = nullptr, |
5231 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
5232 | ExpressionEvaluationContextRecord::EK_Other); |
5233 | enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl }; |
5234 | void PushExpressionEvaluationContext( |
5235 | ExpressionEvaluationContext NewContext, ReuseLambdaContextDecl_t, |
5236 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
5237 | ExpressionEvaluationContextRecord::EK_Other); |
5238 | void PopExpressionEvaluationContext(); |
5239 | |
5240 | void DiscardCleanupsInEvaluationContext(); |
5241 | |
5242 | ExprResult TransformToPotentiallyEvaluated(Expr *E); |
5243 | TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo); |
5244 | ExprResult HandleExprEvaluationContextForTypeof(Expr *E); |
5245 | |
5246 | void CheckUnusedVolatileAssignment(Expr *E); |
5247 | |
5248 | ExprResult ActOnConstantExpression(ExprResult Res); |
5249 | |
5250 | // Functions for marking a declaration referenced. These functions also |
5251 | // contain the relevant logic for marking if a reference to a function or |
5252 | // variable is an odr-use (in the C++11 sense). There are separate variants |
5253 | // for expressions referring to a decl; these exist because odr-use marking |
5254 | // needs to be delayed for some constant variables when we build one of the |
5255 | // named expressions. |
5256 | // |
5257 | // MightBeOdrUse indicates whether the use could possibly be an odr-use, and |
5258 | // should usually be true. This only needs to be set to false if the lack of |
5259 | // odr-use cannot be determined from the current context (for instance, |
5260 | // because the name denotes a virtual function and was written without an |
5261 | // explicit nested-name-specifier). |
5262 | void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse); |
5263 | void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, |
5264 | bool MightBeOdrUse = true); |
5265 | void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var); |
5266 | void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base = nullptr); |
5267 | void MarkMemberReferenced(MemberExpr *E); |
5268 | void MarkFunctionParmPackReferenced(FunctionParmPackExpr *E); |
5269 | void MarkCaptureUsedInEnclosingContext(ValueDecl *Capture, SourceLocation Loc, |
5270 | unsigned CapturingScopeIndex); |
5271 | |
5272 | ExprResult CheckLValueToRValueConversionOperand(Expr *E); |
5273 | void CleanupVarDeclMarking(); |
5274 | |
5275 | enum TryCaptureKind { |
5276 | TryCapture_Implicit, |
5277 | TryCapture_ExplicitByVal, |
5278 | TryCapture_ExplicitByRef |
5279 | }; |
5280 | |
5281 | /// Try to capture the given variable. |
5282 | /// |
5283 | /// \param Var The variable to capture. |
5284 | /// |
5285 | /// \param Loc The location at which the capture occurs. |
5286 | /// |
5287 | /// \param Kind The kind of capture, which may be implicit (for either a |
5288 | /// block or a lambda), or explicit by-value or by-reference (for a lambda). |
5289 | /// |
5290 | /// \param EllipsisLoc The location of the ellipsis, if one is provided in |
5291 | /// an explicit lambda capture. |
5292 | /// |
5293 | /// \param BuildAndDiagnose Whether we are actually supposed to add the |
5294 | /// captures or diagnose errors. If false, this routine merely check whether |
5295 | /// the capture can occur without performing the capture itself or complaining |
5296 | /// if the variable cannot be captured. |
5297 | /// |
5298 | /// \param CaptureType Will be set to the type of the field used to capture |
5299 | /// this variable in the innermost block or lambda. Only valid when the |
5300 | /// variable can be captured. |
5301 | /// |
5302 | /// \param DeclRefType Will be set to the type of a reference to the capture |
5303 | /// from within the current scope. Only valid when the variable can be |
5304 | /// captured. |
5305 | /// |
5306 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
5307 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
5308 | /// This is useful when enclosing lambdas must speculatively capture |
5309 | /// variables that may or may not be used in certain specializations of |
5310 | /// a nested generic lambda. |
5311 | /// |
5312 | /// \returns true if an error occurred (i.e., the variable cannot be |
5313 | /// captured) and false if the capture succeeded. |
5314 | bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, |
5315 | TryCaptureKind Kind, SourceLocation EllipsisLoc, |
5316 | bool BuildAndDiagnose, QualType &CaptureType, |
5317 | QualType &DeclRefType, |
5318 | const unsigned *const FunctionScopeIndexToStopAt); |
5319 | |
5320 | /// Try to capture the given variable. |
5321 | bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, |
5322 | TryCaptureKind Kind = TryCapture_Implicit, |
5323 | SourceLocation EllipsisLoc = SourceLocation()); |
5324 | |
5325 | /// Checks if the variable must be captured. |
5326 | bool NeedToCaptureVariable(ValueDecl *Var, SourceLocation Loc); |
5327 | |
5328 | /// Given a variable, determine the type that a reference to that |
5329 | /// variable will have in the given scope. |
5330 | QualType getCapturedDeclRefType(ValueDecl *Var, SourceLocation Loc); |
5331 | |
5332 | /// Mark all of the declarations referenced within a particular AST node as |
5333 | /// referenced. Used when template instantiation instantiates a non-dependent |
5334 | /// type -- entities referenced by the type are now referenced. |
5335 | void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); |
5336 | void MarkDeclarationsReferencedInExpr( |
5337 | Expr *E, bool SkipLocalVariables = false, |
5338 | ArrayRef<const Expr *> StopAt = std::nullopt); |
5339 | |
5340 | /// Try to convert an expression \p E to type \p Ty. Returns the result of the |
5341 | /// conversion. |
5342 | ExprResult tryConvertExprToType(Expr *E, QualType Ty); |
5343 | |
5344 | /// Conditionally issue a diagnostic based on the statements's reachability |
5345 | /// analysis. |
5346 | /// |
5347 | /// \param Stmts If Stmts is non-empty, delay reporting the diagnostic until |
5348 | /// the function body is parsed, and then do a basic reachability analysis to |
5349 | /// determine if the statement is reachable. If it is unreachable, the |
5350 | /// diagnostic will not be emitted. |
5351 | bool DiagIfReachable(SourceLocation Loc, ArrayRef<const Stmt *> Stmts, |
5352 | const PartialDiagnostic &PD); |
5353 | |
5354 | /// Conditionally issue a diagnostic based on the current |
5355 | /// evaluation context. |
5356 | /// |
5357 | /// \param Statement If Statement is non-null, delay reporting the |
5358 | /// diagnostic until the function body is parsed, and then do a basic |
5359 | /// reachability analysis to determine if the statement is reachable. |
5360 | /// If it is unreachable, the diagnostic will not be emitted. |
5361 | bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, |
5362 | const PartialDiagnostic &PD); |
5363 | /// Similar, but diagnostic is only produced if all the specified statements |
5364 | /// are reachable. |
5365 | bool DiagRuntimeBehavior(SourceLocation Loc, ArrayRef<const Stmt *> Stmts, |
5366 | const PartialDiagnostic &PD); |
5367 | |
5368 | // Primary Expressions. |
5369 | SourceRange getExprRange(Expr *E) const; |
5370 | |
5371 | ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, |
5372 | SourceLocation TemplateKWLoc, UnqualifiedId &Id, |
5373 | bool HasTrailingLParen, bool IsAddressOfOperand, |
5374 | CorrectionCandidateCallback *CCC = nullptr, |
5375 | bool IsInlineAsmIdentifier = false, |
5376 | Token *KeywordReplacement = nullptr); |
5377 | |
5378 | void DecomposeUnqualifiedId(const UnqualifiedId &Id, |
5379 | TemplateArgumentListInfo &Buffer, |
5380 | DeclarationNameInfo &NameInfo, |
5381 | const TemplateArgumentListInfo *&TemplateArgs); |
5382 | |
5383 | bool DiagnoseDependentMemberLookup(const LookupResult &R); |
5384 | |
5385 | bool |
5386 | DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, |
5387 | CorrectionCandidateCallback &CCC, |
5388 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
5389 | ArrayRef<Expr *> Args = std::nullopt, |
5390 | DeclContext *LookupCtx = nullptr, |
5391 | TypoExpr **Out = nullptr); |
5392 | |
5393 | DeclResult LookupIvarInObjCMethod(LookupResult &Lookup, Scope *S, |
5394 | IdentifierInfo *II); |
5395 | ExprResult BuildIvarRefExpr(Scope *S, SourceLocation Loc, ObjCIvarDecl *IV); |
5396 | |
5397 | ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S, |
5398 | IdentifierInfo *II, |
5399 | bool AllowBuiltinCreation = false); |
5400 | |
5401 | /// If \p D cannot be odr-used in the current expression evaluation context, |
5402 | /// return a reason explaining why. Otherwise, return NOUR_None. |
5403 | NonOdrUseReason getNonOdrUseReasonInCurrentContext(ValueDecl *D); |
5404 | |
5405 | DeclRefExpr *BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
5406 | SourceLocation Loc, |
5407 | const CXXScopeSpec *SS = nullptr); |
5408 | DeclRefExpr * |
5409 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
5410 | const DeclarationNameInfo &NameInfo, |
5411 | const CXXScopeSpec *SS = nullptr, |
5412 | NamedDecl *FoundD = nullptr, |
5413 | SourceLocation TemplateKWLoc = SourceLocation(), |
5414 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
5415 | DeclRefExpr * |
5416 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
5417 | const DeclarationNameInfo &NameInfo, |
5418 | NestedNameSpecifierLoc NNS, NamedDecl *FoundD = nullptr, |
5419 | SourceLocation TemplateKWLoc = SourceLocation(), |
5420 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
5421 | |
5422 | bool UseArgumentDependentLookup(const CXXScopeSpec &SS, const LookupResult &R, |
5423 | bool HasTrailingLParen); |
5424 | |
5425 | ExprResult |
5426 | BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, |
5427 | const DeclarationNameInfo &NameInfo, |
5428 | bool IsAddressOfOperand, const Scope *S, |
5429 | TypeSourceInfo **RecoveryTSI = nullptr); |
5430 | |
5431 | ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, |
5432 | bool NeedsADL, |
5433 | bool AcceptInvalidDecl = false); |
5434 | ExprResult BuildDeclarationNameExpr( |
5435 | const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D, |
5436 | NamedDecl *FoundD = nullptr, |
5437 | const TemplateArgumentListInfo *TemplateArgs = nullptr, |
5438 | bool AcceptInvalidDecl = false); |
5439 | |
5440 | // ExpandFunctionLocalPredefinedMacros - Returns a new vector of Tokens, |
5441 | // where Tokens representing function local predefined macros (such as |
5442 | // __FUNCTION__) are replaced (expanded) with string-literal Tokens. |
5443 | std::vector<Token> ExpandFunctionLocalPredefinedMacros(ArrayRef<Token> Toks); |
5444 | |
5445 | ExprResult BuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK); |
5446 | ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); |
5447 | ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val); |
5448 | |
5449 | bool CheckLoopHintExpr(Expr *E, SourceLocation Loc, bool AllowZero); |
5450 | |
5451 | ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr); |
5452 | ExprResult ActOnCharacterConstant(const Token &Tok, |
5453 | Scope *UDLScope = nullptr); |
5454 | ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E); |
5455 | ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, |
5456 | MultiExprArg Val); |
5457 | |
5458 | /// ActOnStringLiteral - The specified tokens were lexed as pasted string |
5459 | /// fragments (e.g. "foo" "bar" L"baz"). |
5460 | ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks, |
5461 | Scope *UDLScope = nullptr); |
5462 | |
5463 | ExprResult ActOnUnevaluatedStringLiteral(ArrayRef<Token> StringToks); |
5464 | |
5465 | /// ControllingExprOrType is either an opaque pointer coming out of a |
5466 | /// ParsedType or an Expr *. FIXME: it'd be better to split this interface |
5467 | /// into two so we don't take a void *, but that's awkward because one of |
5468 | /// the operands is either a ParsedType or an Expr *, which doesn't lend |
5469 | /// itself to generic code very well. |
5470 | ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, |
5471 | SourceLocation DefaultLoc, |
5472 | SourceLocation RParenLoc, |
5473 | bool PredicateIsExpr, |
5474 | void *ControllingExprOrType, |
5475 | ArrayRef<ParsedType> ArgTypes, |
5476 | ArrayRef<Expr *> ArgExprs); |
5477 | /// ControllingExprOrType is either a TypeSourceInfo * or an Expr *. FIXME: |
5478 | /// it'd be better to split this interface into two so we don't take a |
5479 | /// void *, but see the FIXME on ActOnGenericSelectionExpr as to why that |
5480 | /// isn't a trivial change. |
5481 | ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, |
5482 | SourceLocation DefaultLoc, |
5483 | SourceLocation RParenLoc, |
5484 | bool PredicateIsExpr, |
5485 | void *ControllingExprOrType, |
5486 | ArrayRef<TypeSourceInfo *> Types, |
5487 | ArrayRef<Expr *> Exprs); |
5488 | |
5489 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
5490 | ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, |
5491 | Expr *InputExpr, bool IsAfterAmp = false); |
5492 | ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, |
5493 | Expr *Input, bool IsAfterAmp = false); |
5494 | ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Op, |
5495 | Expr *Input, bool IsAfterAmp = false); |
5496 | |
5497 | bool isQualifiedMemberAccess(Expr *E); |
5498 | bool CheckUseOfCXXMethodAsAddressOfOperand(SourceLocation OpLoc, |
5499 | const Expr *Op, |
5500 | const CXXMethodDecl *MD); |
5501 | |
5502 | QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc); |
5503 | |
5504 | bool ActOnAlignasTypeArgument(StringRef KWName, ParsedType Ty, |
5505 | SourceLocation OpLoc, SourceRange R); |
5506 | bool CheckAlignasTypeArgument(StringRef KWName, TypeSourceInfo *TInfo, |
5507 | SourceLocation OpLoc, SourceRange R); |
5508 | |
5509 | ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, |
5510 | SourceLocation OpLoc, |
5511 | UnaryExprOrTypeTrait ExprKind, |
5512 | SourceRange R); |
5513 | ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, |
5514 | UnaryExprOrTypeTrait ExprKind); |
5515 | ExprResult ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, |
5516 | UnaryExprOrTypeTrait ExprKind, |
5517 | bool IsType, void *TyOrEx, |
5518 | SourceRange ArgRange); |
5519 | |
5520 | ExprResult CheckPlaceholderExpr(Expr *E); |
5521 | bool CheckVecStepExpr(Expr *E); |
5522 | |
5523 | bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind); |
5524 | bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc, |
5525 | SourceRange ExprRange, |
5526 | UnaryExprOrTypeTrait ExprKind, |
5527 | StringRef KWName); |
5528 | |
5529 | ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, |
5530 | tok::TokenKind Kind, Expr *Input); |
5531 | |
5532 | ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, |
5533 | MultiExprArg ArgExprs, |
5534 | SourceLocation RLoc); |
5535 | ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, |
5536 | Expr *Idx, SourceLocation RLoc); |
5537 | |
5538 | ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, |
5539 | Expr *ColumnIdx, |
5540 | SourceLocation RBLoc); |
5541 | |
5542 | bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, FunctionDecl *FDecl, |
5543 | const FunctionProtoType *Proto, |
5544 | ArrayRef<Expr *> Args, SourceLocation RParenLoc, |
5545 | bool ExecConfig = false); |
5546 | void CheckStaticArrayArgument(SourceLocation CallLoc, ParmVarDecl *Param, |
5547 | const Expr *ArgExpr); |
5548 | |
5549 | /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. |
5550 | /// This provides the location of the left/right parens and a list of comma |
5551 | /// locations. |
5552 | ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
5553 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
5554 | Expr *ExecConfig = nullptr); |
5555 | ExprResult BuildCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
5556 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
5557 | Expr *ExecConfig = nullptr, |
5558 | bool IsExecConfig = false, |
5559 | bool AllowRecovery = false); |
5560 | Expr *BuildBuiltinCallExpr(SourceLocation Loc, Builtin::ID Id, |
5561 | MultiExprArg CallArgs); |
5562 | |
5563 | using ADLCallKind = CallExpr::ADLCallKind; |
5564 | |
5565 | ExprResult |
5566 | BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, SourceLocation LParenLoc, |
5567 | ArrayRef<Expr *> Arg, SourceLocation RParenLoc, |
5568 | Expr *Config = nullptr, bool IsExecConfig = false, |
5569 | ADLCallKind UsesADL = ADLCallKind::NotADL); |
5570 | |
5571 | ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, Declarator &D, |
5572 | ParsedType &Ty, SourceLocation RParenLoc, |
5573 | Expr *CastExpr); |
5574 | |
5575 | CastKind PrepareScalarCast(ExprResult &src, QualType destType); |
5576 | |
5577 | /// Build an altivec or OpenCL literal. |
5578 | ExprResult BuildVectorLiteral(SourceLocation LParenLoc, |
5579 | SourceLocation RParenLoc, Expr *E, |
5580 | TypeSourceInfo *TInfo); |
5581 | |
5582 | ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); |
5583 | |
5584 | ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, ParsedType Ty, |
5585 | SourceLocation RParenLoc, Expr *InitExpr); |
5586 | |
5587 | ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, |
5588 | TypeSourceInfo *TInfo, |
5589 | SourceLocation RParenLoc, |
5590 | Expr *LiteralExpr); |
5591 | |
5592 | ExprResult ActOnInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList, |
5593 | SourceLocation RBraceLoc); |
5594 | |
5595 | ExprResult BuildInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList, |
5596 | SourceLocation RBraceLoc); |
5597 | |
5598 | ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, tok::TokenKind Kind, |
5599 | Expr *LHSExpr, Expr *RHSExpr); |
5600 | ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, |
5601 | Expr *LHSExpr, Expr *RHSExpr); |
5602 | ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, |
5603 | Expr *LHSExpr, Expr *RHSExpr); |
5604 | void LookupBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, |
5605 | UnresolvedSetImpl &Functions); |
5606 | |
5607 | void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc); |
5608 | |
5609 | /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
5610 | /// in the case of a the GNU conditional expr extension. |
5611 | ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, |
5612 | SourceLocation ColonLoc, Expr *CondExpr, |
5613 | Expr *LHSExpr, Expr *RHSExpr); |
5614 | |
5615 | /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". |
5616 | ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, |
5617 | LabelDecl *TheDecl); |
5618 | |
5619 | void ActOnStartStmtExpr(); |
5620 | ExprResult ActOnStmtExpr(Scope *S, SourceLocation LPLoc, Stmt *SubStmt, |
5621 | SourceLocation RPLoc); |
5622 | ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, |
5623 | SourceLocation RPLoc, unsigned TemplateDepth); |
5624 | // Handle the final expression in a statement expression. |
5625 | ExprResult ActOnStmtExprResult(ExprResult E); |
5626 | void ActOnStmtExprError(); |
5627 | |
5628 | // __builtin_offsetof(type, identifier(.identifier|[expr])*) |
5629 | struct OffsetOfComponent { |
5630 | SourceLocation LocStart, LocEnd; |
5631 | bool isBrackets; // true if [expr], false if .ident |
5632 | union { |
5633 | IdentifierInfo *IdentInfo; |
5634 | Expr *E; |
5635 | } U; |
5636 | }; |
5637 | |
5638 | /// __builtin_offsetof(type, a.b[123][456].c) |
5639 | ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, |
5640 | TypeSourceInfo *TInfo, |
5641 | ArrayRef<OffsetOfComponent> Components, |
5642 | SourceLocation RParenLoc); |
5643 | ExprResult ActOnBuiltinOffsetOf(Scope *S, SourceLocation BuiltinLoc, |
5644 | SourceLocation TypeLoc, |
5645 | ParsedType ParsedArgTy, |
5646 | ArrayRef<OffsetOfComponent> Components, |
5647 | SourceLocation RParenLoc); |
5648 | |
5649 | // __builtin_choose_expr(constExpr, expr1, expr2) |
5650 | ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, Expr *CondExpr, |
5651 | Expr *LHSExpr, Expr *RHSExpr, |
5652 | SourceLocation RPLoc); |
5653 | |
5654 | // __builtin_va_arg(expr, type) |
5655 | ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, |
5656 | SourceLocation RPLoc); |
5657 | ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, |
5658 | TypeSourceInfo *TInfo, SourceLocation RPLoc); |
5659 | |
5660 | // __builtin_LINE(), __builtin_FUNCTION(), __builtin_FUNCSIG(), |
5661 | // __builtin_FILE(), __builtin_COLUMN(), __builtin_source_location() |
5662 | ExprResult ActOnSourceLocExpr(SourceLocIdentKind Kind, |
5663 | SourceLocation BuiltinLoc, |
5664 | SourceLocation RPLoc); |
5665 | |
5666 | // Build a potentially resolved SourceLocExpr. |
5667 | ExprResult BuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, |
5668 | SourceLocation BuiltinLoc, SourceLocation RPLoc, |
5669 | DeclContext *ParentContext); |
5670 | |
5671 | // __null |
5672 | ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); |
5673 | |
5674 | bool CheckCaseExpression(Expr *E); |
5675 | |
5676 | //===------------------------- "Block" Extension ------------------------===// |
5677 | |
5678 | /// ActOnBlockStart - This callback is invoked when a block literal is |
5679 | /// started. |
5680 | void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); |
5681 | |
5682 | /// ActOnBlockArguments - This callback allows processing of block arguments. |
5683 | /// If there are no arguments, this is still invoked. |
5684 | void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, |
5685 | Scope *CurScope); |
5686 | |
5687 | /// ActOnBlockError - If there is an error parsing a block, this callback |
5688 | /// is invoked to pop the information about the block from the action impl. |
5689 | void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); |
5690 | |
5691 | /// ActOnBlockStmtExpr - This is called when the body of a block statement |
5692 | /// literal was successfully completed. ^(int x){...} |
5693 | ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, |
5694 | Scope *CurScope); |
5695 | |
5696 | //===---------------------------- Clang Extensions ----------------------===// |
5697 | |
5698 | /// __builtin_convertvector(...) |
5699 | ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy, |
5700 | SourceLocation BuiltinLoc, |
5701 | SourceLocation RParenLoc); |
5702 | |
5703 | //===---------------------------- OpenCL Features -----------------------===// |
5704 | |
5705 | /// __builtin_astype(...) |
5706 | ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, |
5707 | SourceLocation BuiltinLoc, |
5708 | SourceLocation RParenLoc); |
5709 | ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy, |
5710 | SourceLocation BuiltinLoc, |
5711 | SourceLocation RParenLoc); |
5712 | |
5713 | /// Attempts to produce a RecoveryExpr after some AST node cannot be created. |
5714 | ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, |
5715 | ArrayRef<Expr *> SubExprs, |
5716 | QualType T = QualType()); |
5717 | |
5718 | // Note that LK_String is intentionally after the other literals, as |
5719 | // this is used for diagnostics logic. |
5720 | enum ObjCLiteralKind { |
5721 | LK_Array, |
5722 | LK_Dictionary, |
5723 | LK_Numeric, |
5724 | LK_Boxed, |
5725 | LK_String, |
5726 | LK_Block, |
5727 | LK_None |
5728 | }; |
5729 | ObjCLiteralKind CheckLiteralKind(Expr *FromE); |
5730 | |
5731 | ExprResult PerformObjectMemberConversion(Expr *From, |
5732 | NestedNameSpecifier *Qualifier, |
5733 | NamedDecl *FoundDecl, |
5734 | NamedDecl *Member); |
5735 | |
5736 | /// CheckCallReturnType - Checks that a call expression's return type is |
5737 | /// complete. Returns true on failure. The location passed in is the location |
5738 | /// that best represents the call. |
5739 | bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, |
5740 | CallExpr *CE, FunctionDecl *FD); |
5741 | |
5742 | /// Emit a warning for all pending noderef expressions that we recorded. |
5743 | void WarnOnPendingNoDerefs(ExpressionEvaluationContextRecord &Rec); |
5744 | |
5745 | ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field); |
5746 | |
5747 | /// Instantiate or parse a C++ default argument expression as necessary. |
5748 | /// Return true on error. |
5749 | bool CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
5750 | ParmVarDecl *Param, Expr *Init = nullptr, |
5751 | bool SkipImmediateInvocations = true); |
5752 | |
5753 | /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating |
5754 | /// the default expr if needed. |
5755 | ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
5756 | ParmVarDecl *Param, Expr *Init = nullptr); |
5757 | |
5758 | /// Wrap the expression in a ConstantExpr if it is a potential immediate |
5759 | /// invocation. |
5760 | ExprResult CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl); |
5761 | |
5762 | void MarkExpressionAsImmediateEscalating(Expr *E); |
5763 | |
5764 | bool IsInvalidSMECallConversion(QualType FromType, QualType ToType); |
5765 | |
5766 | const DeclContext *getCurObjCLexicalContext() const { |
5767 | const DeclContext *DC = getCurLexicalContext(); |
5768 | // A category implicitly has the attribute of the interface. |
5769 | if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(Val: DC)) |
5770 | DC = CatD->getClassInterface(); |
5771 | return DC; |
5772 | } |
5773 | |
5774 | /// Abstract base class used for diagnosing integer constant |
5775 | /// expression violations. |
5776 | class VerifyICEDiagnoser { |
5777 | public: |
5778 | bool Suppress; |
5779 | |
5780 | VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) {} |
5781 | |
5782 | virtual SemaDiagnosticBuilder |
5783 | diagnoseNotICEType(Sema &S, SourceLocation Loc, QualType T); |
5784 | virtual SemaDiagnosticBuilder diagnoseNotICE(Sema &S, |
5785 | SourceLocation Loc) = 0; |
5786 | virtual SemaDiagnosticBuilder diagnoseFold(Sema &S, SourceLocation Loc); |
5787 | virtual ~VerifyICEDiagnoser() {} |
5788 | }; |
5789 | |
5790 | enum AllowFoldKind { |
5791 | NoFold, |
5792 | AllowFold, |
5793 | }; |
5794 | |
5795 | /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE, |
5796 | /// and reports the appropriate diagnostics. Returns false on success. |
5797 | /// Can optionally return the value of the expression. |
5798 | ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
5799 | VerifyICEDiagnoser &Diagnoser, |
5800 | AllowFoldKind CanFold = NoFold); |
5801 | ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
5802 | unsigned DiagID, |
5803 | AllowFoldKind CanFold = NoFold); |
5804 | ExprResult VerifyIntegerConstantExpression(Expr *E, |
5805 | llvm::APSInt *Result = nullptr, |
5806 | AllowFoldKind CanFold = NoFold); |
5807 | ExprResult VerifyIntegerConstantExpression(Expr *E, |
5808 | AllowFoldKind CanFold = NoFold) { |
5809 | return VerifyIntegerConstantExpression(E, Result: nullptr, CanFold); |
5810 | } |
5811 | |
5812 | /// DiagnoseAssignmentAsCondition - Given that an expression is |
5813 | /// being used as a boolean condition, warn if it's an assignment. |
5814 | void DiagnoseAssignmentAsCondition(Expr *E); |
5815 | |
5816 | /// Redundant parentheses over an equality comparison can indicate |
5817 | /// that the user intended an assignment used as condition. |
5818 | void (ParenExpr *ParenE); |
5819 | |
5820 | class FullExprArg { |
5821 | public: |
5822 | FullExprArg() : E(nullptr) {} |
5823 | FullExprArg(Sema &actions) : E(nullptr) {} |
5824 | |
5825 | ExprResult release() { return E; } |
5826 | |
5827 | Expr *get() const { return E; } |
5828 | |
5829 | Expr *operator->() { return E; } |
5830 | |
5831 | private: |
5832 | // FIXME: No need to make the entire Sema class a friend when it's just |
5833 | // Sema::MakeFullExpr that needs access to the constructor below. |
5834 | friend class Sema; |
5835 | |
5836 | explicit FullExprArg(Expr *expr) : E(expr) {} |
5837 | |
5838 | Expr *E; |
5839 | }; |
5840 | |
5841 | FullExprArg MakeFullExpr(Expr *Arg) { |
5842 | return MakeFullExpr(Arg, CC: Arg ? Arg->getExprLoc() : SourceLocation()); |
5843 | } |
5844 | FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) { |
5845 | return FullExprArg( |
5846 | ActOnFinishFullExpr(Expr: Arg, CC, /*DiscardedValue*/ DiscardedValue: false).get()); |
5847 | } |
5848 | FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) { |
5849 | ExprResult FE = |
5850 | ActOnFinishFullExpr(Expr: Arg, CC: Arg ? Arg->getExprLoc() : SourceLocation(), |
5851 | /*DiscardedValue*/ DiscardedValue: true); |
5852 | return FullExprArg(FE.get()); |
5853 | } |
5854 | |
5855 | class ConditionResult { |
5856 | Decl *ConditionVar; |
5857 | FullExprArg Condition; |
5858 | bool Invalid; |
5859 | std::optional<bool> KnownValue; |
5860 | |
5861 | friend class Sema; |
5862 | ConditionResult(Sema &S, Decl *ConditionVar, FullExprArg Condition, |
5863 | bool IsConstexpr) |
5864 | : ConditionVar(ConditionVar), Condition(Condition), Invalid(false) { |
5865 | if (IsConstexpr && Condition.get()) { |
5866 | if (std::optional<llvm::APSInt> Val = |
5867 | Condition.get()->getIntegerConstantExpr(Ctx: S.Context)) { |
5868 | KnownValue = !!(*Val); |
5869 | } |
5870 | } |
5871 | } |
5872 | explicit ConditionResult(bool Invalid) |
5873 | : ConditionVar(nullptr), Condition(nullptr), Invalid(Invalid), |
5874 | KnownValue(std::nullopt) {} |
5875 | |
5876 | public: |
5877 | ConditionResult() : ConditionResult(false) {} |
5878 | bool isInvalid() const { return Invalid; } |
5879 | std::pair<VarDecl *, Expr *> get() const { |
5880 | return std::make_pair(x: cast_or_null<VarDecl>(Val: ConditionVar), |
5881 | y: Condition.get()); |
5882 | } |
5883 | std::optional<bool> getKnownValue() const { return KnownValue; } |
5884 | }; |
5885 | static ConditionResult ConditionError() { return ConditionResult(true); } |
5886 | |
5887 | /// CheckBooleanCondition - Diagnose problems involving the use of |
5888 | /// the given expression as a boolean condition (e.g. in an if |
5889 | /// statement). Also performs the standard function and array |
5890 | /// decays, possibly changing the input variable. |
5891 | /// |
5892 | /// \param Loc - A location associated with the condition, e.g. the |
5893 | /// 'if' keyword. |
5894 | /// \return true iff there were any errors |
5895 | ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E, |
5896 | bool IsConstexpr = false); |
5897 | |
5898 | enum class ConditionKind { |
5899 | Boolean, ///< A boolean condition, from 'if', 'while', 'for', or 'do'. |
5900 | ConstexprIf, ///< A constant boolean condition from 'if constexpr'. |
5901 | Switch ///< An integral condition for a 'switch' statement. |
5902 | }; |
5903 | |
5904 | ConditionResult ActOnCondition(Scope *S, SourceLocation Loc, Expr *SubExpr, |
5905 | ConditionKind CK, bool MissingOK = false); |
5906 | |
5907 | QualType CheckConditionalOperands( // C99 6.5.15 |
5908 | ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, |
5909 | ExprObjectKind &OK, SourceLocation QuestionLoc); |
5910 | |
5911 | QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, |
5912 | SourceLocation QuestionLoc); |
5913 | |
5914 | bool DiagnoseConditionalForNull(const Expr *LHSExpr, const Expr *RHSExpr, |
5915 | SourceLocation QuestionLoc); |
5916 | |
5917 | /// type checking for vector binary operators. |
5918 | QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS, |
5919 | SourceLocation Loc, bool IsCompAssign, |
5920 | bool AllowBothBool, bool AllowBoolConversion, |
5921 | bool AllowBoolOperation, bool ReportInvalid); |
5922 | QualType GetSignedVectorType(QualType V); |
5923 | QualType GetSignedSizelessVectorType(QualType V); |
5924 | QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, |
5925 | SourceLocation Loc, |
5926 | BinaryOperatorKind Opc); |
5927 | QualType CheckSizelessVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, |
5928 | SourceLocation Loc, |
5929 | BinaryOperatorKind Opc); |
5930 | QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, |
5931 | SourceLocation Loc); |
5932 | |
5933 | /// Context in which we're performing a usual arithmetic conversion. |
5934 | enum ArithConvKind { |
5935 | /// An arithmetic operation. |
5936 | ACK_Arithmetic, |
5937 | /// A bitwise operation. |
5938 | ACK_BitwiseOp, |
5939 | /// A comparison. |
5940 | ACK_Comparison, |
5941 | /// A conditional (?:) operator. |
5942 | ACK_Conditional, |
5943 | /// A compound assignment expression. |
5944 | ACK_CompAssign, |
5945 | }; |
5946 | |
5947 | // type checking for sizeless vector binary operators. |
5948 | QualType CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS, |
5949 | SourceLocation Loc, bool IsCompAssign, |
5950 | ArithConvKind OperationKind); |
5951 | |
5952 | /// Type checking for matrix binary operators. |
5953 | QualType CheckMatrixElementwiseOperands(ExprResult &LHS, ExprResult &RHS, |
5954 | SourceLocation Loc, |
5955 | bool IsCompAssign); |
5956 | QualType CheckMatrixMultiplyOperands(ExprResult &LHS, ExprResult &RHS, |
5957 | SourceLocation Loc, bool IsCompAssign); |
5958 | |
5959 | bool isValidSveBitcast(QualType srcType, QualType destType); |
5960 | bool isValidRVVBitcast(QualType srcType, QualType destType); |
5961 | |
5962 | bool areMatrixTypesOfTheSameDimension(QualType srcTy, QualType destTy); |
5963 | |
5964 | bool areVectorTypesSameSize(QualType srcType, QualType destType); |
5965 | bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType); |
5966 | bool isLaxVectorConversion(QualType srcType, QualType destType); |
5967 | bool anyAltivecTypes(QualType srcType, QualType destType); |
5968 | |
5969 | // type checking C++ declaration initializers (C++ [dcl.init]). |
5970 | |
5971 | ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, |
5972 | Expr *CastExpr, CastKind &CastKind, |
5973 | ExprValueKind &VK, CXXCastPath &Path); |
5974 | |
5975 | /// Force an expression with unknown-type to an expression of the |
5976 | /// given type. |
5977 | ExprResult forceUnknownAnyToType(Expr *E, QualType ToType); |
5978 | |
5979 | /// Type-check an expression that's being passed to an |
5980 | /// __unknown_anytype parameter. |
5981 | ExprResult checkUnknownAnyArg(SourceLocation callLoc, Expr *result, |
5982 | QualType ¶mType); |
5983 | |
5984 | // CheckMatrixCast - Check type constraints for matrix casts. |
5985 | // We allow casting between matrixes of the same dimensions i.e. when they |
5986 | // have the same number of rows and column. Returns true if the cast is |
5987 | // invalid. |
5988 | bool CheckMatrixCast(SourceRange R, QualType DestTy, QualType SrcTy, |
5989 | CastKind &Kind); |
5990 | |
5991 | // CheckVectorCast - check type constraints for vectors. |
5992 | // Since vectors are an extension, there are no C standard reference for this. |
5993 | // We allow casting between vectors and integer datatypes of the same size. |
5994 | // returns true if the cast is invalid |
5995 | bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, |
5996 | CastKind &Kind); |
5997 | |
5998 | /// Prepare `SplattedExpr` for a vector splat operation, adding |
5999 | /// implicit casts if necessary. |
6000 | ExprResult prepareVectorSplat(QualType VectorTy, Expr *SplattedExpr); |
6001 | |
6002 | // CheckExtVectorCast - check type constraints for extended vectors. |
6003 | // Since vectors are an extension, there are no C standard reference for this. |
6004 | // We allow casting between vectors and integer datatypes of the same size, |
6005 | // or vectors and the element type of that vector. |
6006 | // returns the cast expr |
6007 | ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr, |
6008 | CastKind &Kind); |
6009 | |
6010 | QualType PreferredConditionType(ConditionKind K) const { |
6011 | return K == ConditionKind::Switch ? Context.IntTy : Context.BoolTy; |
6012 | } |
6013 | |
6014 | // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts |
6015 | // functions and arrays to their respective pointers (C99 6.3.2.1). |
6016 | ExprResult UsualUnaryConversions(Expr *E); |
6017 | |
6018 | /// CallExprUnaryConversions - a special case of an unary conversion |
6019 | /// performed on a function designator of a call expression. |
6020 | ExprResult CallExprUnaryConversions(Expr *E); |
6021 | |
6022 | // DefaultFunctionArrayConversion - converts functions and arrays |
6023 | // to their respective pointers (C99 6.3.2.1). |
6024 | ExprResult DefaultFunctionArrayConversion(Expr *E, bool Diagnose = true); |
6025 | |
6026 | // DefaultFunctionArrayLvalueConversion - converts functions and |
6027 | // arrays to their respective pointers and performs the |
6028 | // lvalue-to-rvalue conversion. |
6029 | ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, |
6030 | bool Diagnose = true); |
6031 | |
6032 | // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on |
6033 | // the operand. This function is a no-op if the operand has a function type |
6034 | // or an array type. |
6035 | ExprResult DefaultLvalueConversion(Expr *E); |
6036 | |
6037 | // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that |
6038 | // do not have a prototype. Integer promotions are performed on each |
6039 | // argument, and arguments that have type float are promoted to double. |
6040 | ExprResult DefaultArgumentPromotion(Expr *E); |
6041 | |
6042 | VariadicCallType getVariadicCallType(FunctionDecl *FDecl, |
6043 | const FunctionProtoType *Proto, |
6044 | Expr *Fn); |
6045 | |
6046 | // Used for determining in which context a type is allowed to be passed to a |
6047 | // vararg function. |
6048 | enum VarArgKind { |
6049 | VAK_Valid, |
6050 | VAK_ValidInCXX11, |
6051 | VAK_Undefined, |
6052 | VAK_MSVCUndefined, |
6053 | VAK_Invalid |
6054 | }; |
6055 | |
6056 | // Determines which VarArgKind fits an expression. |
6057 | VarArgKind isValidVarArgType(const QualType &Ty); |
6058 | |
6059 | /// Check to see if the given expression is a valid argument to a variadic |
6060 | /// function, issuing a diagnostic if not. |
6061 | void checkVariadicArgument(const Expr *E, VariadicCallType CT); |
6062 | |
6063 | /// GatherArgumentsForCall - Collector argument expressions for various |
6064 | /// form of call prototypes. |
6065 | bool GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl, |
6066 | const FunctionProtoType *Proto, |
6067 | unsigned FirstParam, ArrayRef<Expr *> Args, |
6068 | SmallVectorImpl<Expr *> &AllArgs, |
6069 | VariadicCallType CallType = VariadicDoesNotApply, |
6070 | bool AllowExplicit = false, |
6071 | bool IsListInitialization = false); |
6072 | |
6073 | // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but |
6074 | // will create a runtime trap if the resulting type is not a POD type. |
6075 | ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, |
6076 | FunctionDecl *FDecl); |
6077 | |
6078 | // UsualArithmeticConversions - performs the UsualUnaryConversions on it's |
6079 | // operands and then handles various conversions that are common to binary |
6080 | // operators (C99 6.3.1.8). If both operands aren't arithmetic, this |
6081 | // routine returns the first non-arithmetic type found. The client is |
6082 | // responsible for emitting appropriate error diagnostics. |
6083 | QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, |
6084 | SourceLocation Loc, ArithConvKind ACK); |
6085 | |
6086 | /// AssignConvertType - All of the 'assignment' semantic checks return this |
6087 | /// enum to indicate whether the assignment was allowed. These checks are |
6088 | /// done for simple assignments, as well as initialization, return from |
6089 | /// function, argument passing, etc. The query is phrased in terms of a |
6090 | /// source and destination type. |
6091 | enum AssignConvertType { |
6092 | /// Compatible - the types are compatible according to the standard. |
6093 | Compatible, |
6094 | |
6095 | /// PointerToInt - The assignment converts a pointer to an int, which we |
6096 | /// accept as an extension. |
6097 | PointerToInt, |
6098 | |
6099 | /// IntToPointer - The assignment converts an int to a pointer, which we |
6100 | /// accept as an extension. |
6101 | IntToPointer, |
6102 | |
6103 | /// FunctionVoidPointer - The assignment is between a function pointer and |
6104 | /// void*, which the standard doesn't allow, but we accept as an extension. |
6105 | FunctionVoidPointer, |
6106 | |
6107 | /// IncompatiblePointer - The assignment is between two pointers types that |
6108 | /// are not compatible, but we accept them as an extension. |
6109 | IncompatiblePointer, |
6110 | |
6111 | /// IncompatibleFunctionPointer - The assignment is between two function |
6112 | /// pointers types that are not compatible, but we accept them as an |
6113 | /// extension. |
6114 | IncompatibleFunctionPointer, |
6115 | |
6116 | /// IncompatibleFunctionPointerStrict - The assignment is between two |
6117 | /// function pointer types that are not identical, but are compatible, |
6118 | /// unless compiled with -fsanitize=cfi, in which case the type mismatch |
6119 | /// may trip an indirect call runtime check. |
6120 | IncompatibleFunctionPointerStrict, |
6121 | |
6122 | /// IncompatiblePointerSign - The assignment is between two pointers types |
6123 | /// which point to integers which have a different sign, but are otherwise |
6124 | /// identical. This is a subset of the above, but broken out because it's by |
6125 | /// far the most common case of incompatible pointers. |
6126 | IncompatiblePointerSign, |
6127 | |
6128 | /// CompatiblePointerDiscardsQualifiers - The assignment discards |
6129 | /// c/v/r qualifiers, which we accept as an extension. |
6130 | CompatiblePointerDiscardsQualifiers, |
6131 | |
6132 | /// IncompatiblePointerDiscardsQualifiers - The assignment |
6133 | /// discards qualifiers that we don't permit to be discarded, |
6134 | /// like address spaces. |
6135 | IncompatiblePointerDiscardsQualifiers, |
6136 | |
6137 | /// IncompatibleNestedPointerAddressSpaceMismatch - The assignment |
6138 | /// changes address spaces in nested pointer types which is not allowed. |
6139 | /// For instance, converting __private int ** to __generic int ** is |
6140 | /// illegal even though __private could be converted to __generic. |
6141 | IncompatibleNestedPointerAddressSpaceMismatch, |
6142 | |
6143 | /// IncompatibleNestedPointerQualifiers - The assignment is between two |
6144 | /// nested pointer types, and the qualifiers other than the first two |
6145 | /// levels differ e.g. char ** -> const char **, but we accept them as an |
6146 | /// extension. |
6147 | IncompatibleNestedPointerQualifiers, |
6148 | |
6149 | /// IncompatibleVectors - The assignment is between two vector types that |
6150 | /// have the same size, which we accept as an extension. |
6151 | IncompatibleVectors, |
6152 | |
6153 | /// IntToBlockPointer - The assignment converts an int to a block |
6154 | /// pointer. We disallow this. |
6155 | IntToBlockPointer, |
6156 | |
6157 | /// IncompatibleBlockPointer - The assignment is between two block |
6158 | /// pointers types that are not compatible. |
6159 | IncompatibleBlockPointer, |
6160 | |
6161 | /// IncompatibleObjCQualifiedId - The assignment is between a qualified |
6162 | /// id type and something else (that is incompatible with it). For example, |
6163 | /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. |
6164 | IncompatibleObjCQualifiedId, |
6165 | |
6166 | /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an |
6167 | /// object with __weak qualifier. |
6168 | IncompatibleObjCWeakRef, |
6169 | |
6170 | /// Incompatible - We reject this conversion outright, it is invalid to |
6171 | /// represent it in the AST. |
6172 | Incompatible |
6173 | }; |
6174 | |
6175 | /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the |
6176 | /// assignment conversion type specified by ConvTy. This returns true if the |
6177 | /// conversion was invalid or false if the conversion was accepted. |
6178 | bool DiagnoseAssignmentResult(AssignConvertType ConvTy, SourceLocation Loc, |
6179 | QualType DstType, QualType SrcType, |
6180 | Expr *SrcExpr, AssignmentAction Action, |
6181 | bool *Complained = nullptr); |
6182 | |
6183 | /// CheckAssignmentConstraints - Perform type checking for assignment, |
6184 | /// argument passing, variable initialization, and function return values. |
6185 | /// C99 6.5.16. |
6186 | AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, |
6187 | QualType LHSType, |
6188 | QualType RHSType); |
6189 | |
6190 | /// Check assignment constraints and optionally prepare for a conversion of |
6191 | /// the RHS to the LHS type. The conversion is prepared for if ConvertRHS |
6192 | /// is true. |
6193 | AssignConvertType CheckAssignmentConstraints(QualType LHSType, |
6194 | ExprResult &RHS, CastKind &Kind, |
6195 | bool ConvertRHS = true); |
6196 | |
6197 | /// Check assignment constraints for an assignment of RHS to LHSType. |
6198 | /// |
6199 | /// \param LHSType The destination type for the assignment. |
6200 | /// \param RHS The source expression for the assignment. |
6201 | /// \param Diagnose If \c true, diagnostics may be produced when checking |
6202 | /// for assignability. If a diagnostic is produced, \p RHS will be |
6203 | /// set to ExprError(). Note that this function may still return |
6204 | /// without producing a diagnostic, even for an invalid assignment. |
6205 | /// \param DiagnoseCFAudited If \c true, the target is a function parameter |
6206 | /// in an audited Core Foundation API and does not need to be checked |
6207 | /// for ARC retain issues. |
6208 | /// \param ConvertRHS If \c true, \p RHS will be updated to model the |
6209 | /// conversions necessary to perform the assignment. If \c false, |
6210 | /// \p Diagnose must also be \c false. |
6211 | AssignConvertType CheckSingleAssignmentConstraints( |
6212 | QualType LHSType, ExprResult &RHS, bool Diagnose = true, |
6213 | bool DiagnoseCFAudited = false, bool ConvertRHS = true); |
6214 | |
6215 | // If the lhs type is a transparent union, check whether we |
6216 | // can initialize the transparent union with the given expression. |
6217 | AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, |
6218 | ExprResult &RHS); |
6219 | |
6220 | /// the following "Check" methods will return a valid/converted QualType |
6221 | /// or a null QualType (indicating an error diagnostic was issued). |
6222 | |
6223 | /// type checking binary operators (subroutines of CreateBuiltinBinOp). |
6224 | QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS, |
6225 | ExprResult &RHS); |
6226 | QualType InvalidLogicalVectorOperands(SourceLocation Loc, ExprResult &LHS, |
6227 | ExprResult &RHS); |
6228 | |
6229 | QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
6230 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign, |
6231 | bool IsDivide); |
6232 | QualType CheckRemainderOperands( // C99 6.5.5 |
6233 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
6234 | bool IsCompAssign = false); |
6235 | QualType CheckAdditionOperands( // C99 6.5.6 |
6236 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
6237 | BinaryOperatorKind Opc, QualType *CompLHSTy = nullptr); |
6238 | QualType CheckSubtractionOperands( // C99 6.5.6 |
6239 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
6240 | QualType *CompLHSTy = nullptr); |
6241 | QualType CheckShiftOperands( // C99 6.5.7 |
6242 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
6243 | BinaryOperatorKind Opc, bool IsCompAssign = false); |
6244 | void CheckPtrComparisonWithNullChar(ExprResult &E, ExprResult &NullE); |
6245 | QualType CheckCompareOperands( // C99 6.5.8/9 |
6246 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
6247 | BinaryOperatorKind Opc); |
6248 | QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
6249 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
6250 | BinaryOperatorKind Opc); |
6251 | QualType CheckLogicalOperands( // C99 6.5.[13,14] |
6252 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
6253 | BinaryOperatorKind Opc); |
6254 | // CheckAssignmentOperands is used for both simple and compound assignment. |
6255 | // For simple assignment, pass both expressions and a null converted type. |
6256 | // For compound assignment, pass both expressions and the converted type. |
6257 | QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] |
6258 | Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType, |
6259 | BinaryOperatorKind Opc); |
6260 | |
6261 | bool CheckConversionToObjCLiteral(QualType DstType, Expr *&SrcExpr, |
6262 | bool Diagnose = true); |
6263 | |
6264 | /// To be used for checking whether the arguments being passed to |
6265 | /// function exceeds the number of parameters expected for it. |
6266 | static bool TooManyArguments(size_t NumParams, size_t NumArgs, |
6267 | bool PartialOverloading = false) { |
6268 | // We check whether we're just after a comma in code-completion. |
6269 | if (NumArgs > 0 && PartialOverloading) |
6270 | return NumArgs + 1 > NumParams; // If so, we view as an extra argument. |
6271 | return NumArgs > NumParams; |
6272 | } |
6273 | |
6274 | /// Whether the AST is currently being rebuilt to correct immediate |
6275 | /// invocations. Immediate invocation candidates and references to consteval |
6276 | /// functions aren't tracked when this is set. |
6277 | bool RebuildingImmediateInvocation = false; |
6278 | |
6279 | bool isAlwaysConstantEvaluatedContext() const { |
6280 | const ExpressionEvaluationContextRecord &Ctx = currentEvaluationContext(); |
6281 | return (Ctx.isConstantEvaluated() || isConstantEvaluatedOverride) && |
6282 | !Ctx.InConditionallyConstantEvaluateContext; |
6283 | } |
6284 | |
6285 | /// Determines whether we are currently in a context that |
6286 | /// is not evaluated as per C++ [expr] p5. |
6287 | bool isUnevaluatedContext() const { |
6288 | return currentEvaluationContext().isUnevaluated(); |
6289 | } |
6290 | |
6291 | bool isImmediateFunctionContext() const { |
6292 | return currentEvaluationContext().isImmediateFunctionContext(); |
6293 | } |
6294 | |
6295 | bool isInLifetimeExtendingContext() const { |
6296 | assert(!ExprEvalContexts.empty() && |
6297 | "Must be in an expression evaluation context" ); |
6298 | return ExprEvalContexts.back().InLifetimeExtendingContext; |
6299 | } |
6300 | |
6301 | bool isCheckingDefaultArgumentOrInitializer() const { |
6302 | const ExpressionEvaluationContextRecord &Ctx = currentEvaluationContext(); |
6303 | return (Ctx.Context == |
6304 | ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed) || |
6305 | Ctx.IsCurrentlyCheckingDefaultArgumentOrInitializer; |
6306 | } |
6307 | |
6308 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> |
6309 | InnermostDeclarationWithDelayedImmediateInvocations() const { |
6310 | assert(!ExprEvalContexts.empty() && |
6311 | "Must be in an expression evaluation context" ); |
6312 | for (const auto &Ctx : llvm::reverse(C: ExprEvalContexts)) { |
6313 | if (Ctx.Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
6314 | Ctx.DelayedDefaultInitializationContext) |
6315 | return Ctx.DelayedDefaultInitializationContext; |
6316 | if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() || |
6317 | Ctx.isUnevaluated()) |
6318 | break; |
6319 | } |
6320 | return std::nullopt; |
6321 | } |
6322 | |
6323 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> |
6324 | OutermostDeclarationWithDelayedImmediateInvocations() const { |
6325 | assert(!ExprEvalContexts.empty() && |
6326 | "Must be in an expression evaluation context" ); |
6327 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> Res; |
6328 | for (auto &Ctx : llvm::reverse(C: ExprEvalContexts)) { |
6329 | if (Ctx.Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
6330 | !Ctx.DelayedDefaultInitializationContext && Res) |
6331 | break; |
6332 | if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() || |
6333 | Ctx.isUnevaluated()) |
6334 | break; |
6335 | Res = Ctx.DelayedDefaultInitializationContext; |
6336 | } |
6337 | return Res; |
6338 | } |
6339 | |
6340 | /// keepInLifetimeExtendingContext - Pull down InLifetimeExtendingContext |
6341 | /// flag from previous context. |
6342 | void keepInLifetimeExtendingContext() { |
6343 | if (ExprEvalContexts.size() > 2 && |
6344 | ExprEvalContexts[ExprEvalContexts.size() - 2] |
6345 | .InLifetimeExtendingContext) { |
6346 | auto &LastRecord = ExprEvalContexts.back(); |
6347 | auto &PrevRecord = ExprEvalContexts[ExprEvalContexts.size() - 2]; |
6348 | LastRecord.InLifetimeExtendingContext = |
6349 | PrevRecord.InLifetimeExtendingContext; |
6350 | } |
6351 | } |
6352 | |
6353 | DefaultedComparisonKind getDefaultedComparisonKind(const FunctionDecl *FD) { |
6354 | return getDefaultedFunctionKind(FD).asComparison(); |
6355 | } |
6356 | |
6357 | /// Returns a field in a CXXRecordDecl that has the same name as the decl \p |
6358 | /// SelfAssigned when inside a CXXMethodDecl. |
6359 | const FieldDecl * |
6360 | getSelfAssignmentClassMemberCandidate(const ValueDecl *SelfAssigned); |
6361 | |
6362 | void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D); |
6363 | |
6364 | template <typename... Ts> |
6365 | bool RequireCompleteSizedType(SourceLocation Loc, QualType T, unsigned DiagID, |
6366 | const Ts &...Args) { |
6367 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
6368 | return RequireCompleteType(Loc, T, CompleteTypeKind::Normal, Diagnoser); |
6369 | } |
6370 | |
6371 | template <typename... Ts> |
6372 | bool RequireCompleteSizedExprType(Expr *E, unsigned DiagID, |
6373 | const Ts &...Args) { |
6374 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
6375 | return RequireCompleteExprType(E, CompleteTypeKind::Normal, Diagnoser); |
6376 | } |
6377 | |
6378 | /// Abstract class used to diagnose incomplete types. |
6379 | struct TypeDiagnoser { |
6380 | TypeDiagnoser() {} |
6381 | |
6382 | virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0; |
6383 | virtual ~TypeDiagnoser() {} |
6384 | }; |
6385 | |
6386 | template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser { |
6387 | protected: |
6388 | unsigned DiagID; |
6389 | std::tuple<const Ts &...> Args; |
6390 | |
6391 | template <std::size_t... Is> |
6392 | void emit(const SemaDiagnosticBuilder &DB, |
6393 | std::index_sequence<Is...>) const { |
6394 | // Apply all tuple elements to the builder in order. |
6395 | bool Dummy[] = {false, (DB << getPrintable(std::get<Is>(Args)))...}; |
6396 | (void)Dummy; |
6397 | } |
6398 | |
6399 | public: |
6400 | BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args) |
6401 | : TypeDiagnoser(), DiagID(DiagID), Args(Args...) { |
6402 | assert(DiagID != 0 && "no diagnostic for type diagnoser" ); |
6403 | } |
6404 | |
6405 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
6406 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID); |
6407 | emit(DB, std::index_sequence_for<Ts...>()); |
6408 | DB << T; |
6409 | } |
6410 | }; |
6411 | |
6412 | /// A derivative of BoundTypeDiagnoser for which the diagnostic's type |
6413 | /// parameter is preceded by a 0/1 enum that is 1 if the type is sizeless. |
6414 | /// For example, a diagnostic with no other parameters would generally have |
6415 | /// the form "...%select{incomplete|sizeless}0 type %1...". |
6416 | template <typename... Ts> |
6417 | class SizelessTypeDiagnoser : public BoundTypeDiagnoser<Ts...> { |
6418 | public: |
6419 | SizelessTypeDiagnoser(unsigned DiagID, const Ts &...Args) |
6420 | : BoundTypeDiagnoser<Ts...>(DiagID, Args...) {} |
6421 | |
6422 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
6423 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, this->DiagID); |
6424 | this->emit(DB, std::index_sequence_for<Ts...>()); |
6425 | DB << T->isSizelessType() << T; |
6426 | } |
6427 | }; |
6428 | |
6429 | /// Check an argument list for placeholders that we won't try to |
6430 | /// handle later. |
6431 | bool CheckArgsForPlaceholders(MultiExprArg args); |
6432 | |
6433 | /// The C++ "std::source_location::__impl" struct, defined in |
6434 | /// \<source_location>. |
6435 | RecordDecl *StdSourceLocationImplDecl; |
6436 | |
6437 | /// A stack of expression evaluation contexts. |
6438 | SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts; |
6439 | |
6440 | // Set of failed immediate invocations to avoid double diagnosing. |
6441 | llvm::SmallPtrSet<ConstantExpr *, 4> FailedImmediateInvocations; |
6442 | |
6443 | /// List of SourceLocations where 'self' is implicitly retained inside a |
6444 | /// block. |
6445 | llvm::SmallVector<std::pair<SourceLocation, const BlockDecl *>, 1> |
6446 | ImplicitlyRetainedSelfLocs; |
6447 | |
6448 | private: |
6449 | static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind); |
6450 | |
6451 | /// Methods for marking which expressions involve dereferencing a pointer |
6452 | /// marked with the 'noderef' attribute. Expressions are checked bottom up as |
6453 | /// they are parsed, meaning that a noderef pointer may not be accessed. For |
6454 | /// example, in `&*p` where `p` is a noderef pointer, we will first parse the |
6455 | /// `*p`, but need to check that `address of` is called on it. This requires |
6456 | /// keeping a container of all pending expressions and checking if the address |
6457 | /// of them are eventually taken. |
6458 | void CheckSubscriptAccessOfNoDeref(const ArraySubscriptExpr *E); |
6459 | void CheckAddressOfNoDeref(const Expr *E); |
6460 | |
6461 | ///@} |
6462 | |
6463 | // |
6464 | // |
6465 | // ------------------------------------------------------------------------- |
6466 | // |
6467 | // |
6468 | |
6469 | /// \name C++ Expressions |
6470 | /// Implementations are in SemaExprCXX.cpp |
6471 | ///@{ |
6472 | |
6473 | public: |
6474 | /// The C++ "std::bad_alloc" class, which is defined by the C++ |
6475 | /// standard library. |
6476 | LazyDeclPtr StdBadAlloc; |
6477 | |
6478 | /// The C++ "std::align_val_t" enum class, which is defined by the C++ |
6479 | /// standard library. |
6480 | LazyDeclPtr StdAlignValT; |
6481 | |
6482 | /// The C++ "type_info" declaration, which is defined in \<typeinfo>. |
6483 | RecordDecl *CXXTypeInfoDecl; |
6484 | |
6485 | /// A flag to remember whether the implicit forms of operator new and delete |
6486 | /// have been declared. |
6487 | bool GlobalNewDeleteDeclared; |
6488 | |
6489 | /// Delete-expressions to be analyzed at the end of translation unit |
6490 | /// |
6491 | /// This list contains class members, and locations of delete-expressions |
6492 | /// that could not be proven as to whether they mismatch with new-expression |
6493 | /// used in initializer of the field. |
6494 | llvm::MapVector<FieldDecl *, DeleteLocs> DeleteExprs; |
6495 | |
6496 | ParsedType getInheritingConstructorName(CXXScopeSpec &SS, |
6497 | SourceLocation NameLoc, |
6498 | const IdentifierInfo &Name); |
6499 | |
6500 | ParsedType getConstructorName(const IdentifierInfo &II, |
6501 | SourceLocation NameLoc, Scope *S, |
6502 | CXXScopeSpec &SS, bool EnteringContext); |
6503 | ParsedType getDestructorName(const IdentifierInfo &II, SourceLocation NameLoc, |
6504 | Scope *S, CXXScopeSpec &SS, |
6505 | ParsedType ObjectType, bool EnteringContext); |
6506 | |
6507 | ParsedType getDestructorTypeForDecltype(const DeclSpec &DS, |
6508 | ParsedType ObjectType); |
6509 | |
6510 | ExprResult BuildCXXTypeId(QualType TypeInfoType, SourceLocation TypeidLoc, |
6511 | TypeSourceInfo *Operand, SourceLocation RParenLoc); |
6512 | ExprResult BuildCXXTypeId(QualType TypeInfoType, SourceLocation TypeidLoc, |
6513 | Expr *Operand, SourceLocation RParenLoc); |
6514 | |
6515 | /// ActOnCXXTypeid - Parse typeid( something ). |
6516 | ExprResult ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc, |
6517 | bool isType, void *TyOrExpr, |
6518 | SourceLocation RParenLoc); |
6519 | |
6520 | ExprResult BuildCXXUuidof(QualType TypeInfoType, SourceLocation TypeidLoc, |
6521 | TypeSourceInfo *Operand, SourceLocation RParenLoc); |
6522 | ExprResult BuildCXXUuidof(QualType TypeInfoType, SourceLocation TypeidLoc, |
6523 | Expr *Operand, SourceLocation RParenLoc); |
6524 | |
6525 | /// ActOnCXXUuidof - Parse __uuidof( something ). |
6526 | ExprResult ActOnCXXUuidof(SourceLocation OpLoc, SourceLocation LParenLoc, |
6527 | bool isType, void *TyOrExpr, |
6528 | SourceLocation RParenLoc); |
6529 | |
6530 | //// ActOnCXXThis - Parse 'this' pointer. |
6531 | ExprResult ActOnCXXThis(SourceLocation Loc); |
6532 | |
6533 | /// Check whether the type of 'this' is valid in the current context. |
6534 | bool CheckCXXThisType(SourceLocation Loc, QualType Type); |
6535 | |
6536 | /// Build a CXXThisExpr and mark it referenced in the current context. |
6537 | Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit); |
6538 | void MarkThisReferenced(CXXThisExpr *This); |
6539 | |
6540 | /// Try to retrieve the type of the 'this' pointer. |
6541 | /// |
6542 | /// \returns The type of 'this', if possible. Otherwise, returns a NULL type. |
6543 | QualType getCurrentThisType(); |
6544 | |
6545 | /// When non-NULL, the C++ 'this' expression is allowed despite the |
6546 | /// current context not being a non-static member function. In such cases, |
6547 | /// this provides the type used for 'this'. |
6548 | QualType CXXThisTypeOverride; |
6549 | |
6550 | /// RAII object used to temporarily allow the C++ 'this' expression |
6551 | /// to be used, with the given qualifiers on the current class type. |
6552 | class CXXThisScopeRAII { |
6553 | Sema &S; |
6554 | QualType OldCXXThisTypeOverride; |
6555 | bool Enabled; |
6556 | |
6557 | public: |
6558 | /// Introduce a new scope where 'this' may be allowed (when enabled), |
6559 | /// using the given declaration (which is either a class template or a |
6560 | /// class) along with the given qualifiers. |
6561 | /// along with the qualifiers placed on '*this'. |
6562 | CXXThisScopeRAII(Sema &S, Decl *ContextDecl, Qualifiers CXXThisTypeQuals, |
6563 | bool Enabled = true); |
6564 | |
6565 | ~CXXThisScopeRAII(); |
6566 | }; |
6567 | |
6568 | /// Make sure the value of 'this' is actually available in the current |
6569 | /// context, if it is a potentially evaluated context. |
6570 | /// |
6571 | /// \param Loc The location at which the capture of 'this' occurs. |
6572 | /// |
6573 | /// \param Explicit Whether 'this' is explicitly captured in a lambda |
6574 | /// capture list. |
6575 | /// |
6576 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
6577 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
6578 | /// This is useful when enclosing lambdas must speculatively capture |
6579 | /// 'this' that may or may not be used in certain specializations of |
6580 | /// a nested generic lambda (depending on whether the name resolves to |
6581 | /// a non-static member function or a static function). |
6582 | /// \return returns 'true' if failed, 'false' if success. |
6583 | bool CheckCXXThisCapture( |
6584 | SourceLocation Loc, bool Explicit = false, bool BuildAndDiagnose = true, |
6585 | const unsigned *const FunctionScopeIndexToStopAt = nullptr, |
6586 | bool ByCopy = false); |
6587 | |
6588 | /// Determine whether the given type is the type of *this that is used |
6589 | /// outside of the body of a member function for a type that is currently |
6590 | /// being defined. |
6591 | bool isThisOutsideMemberFunctionBody(QualType BaseType); |
6592 | |
6593 | /// ActOnCXXBoolLiteral - Parse {true,false} literals. |
6594 | ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
6595 | |
6596 | /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals. |
6597 | ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
6598 | |
6599 | ExprResult |
6600 | ActOnObjCAvailabilityCheckExpr(llvm::ArrayRef<AvailabilitySpec> AvailSpecs, |
6601 | SourceLocation AtLoc, SourceLocation RParen); |
6602 | |
6603 | /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. |
6604 | ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); |
6605 | |
6606 | //// ActOnCXXThrow - Parse throw expressions. |
6607 | ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); |
6608 | ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, |
6609 | bool IsThrownVarInScope); |
6610 | bool CheckCXXThrowOperand(SourceLocation ThrowLoc, QualType ThrowTy, Expr *E); |
6611 | |
6612 | /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. |
6613 | /// Can be interpreted either as function-style casting ("int(x)") |
6614 | /// or class type construction ("ClassType(x,y,z)") |
6615 | /// or creation of a value-initialized type ("int()"). |
6616 | ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, |
6617 | SourceLocation LParenOrBraceLoc, |
6618 | MultiExprArg Exprs, |
6619 | SourceLocation RParenOrBraceLoc, |
6620 | bool ListInitialization); |
6621 | |
6622 | ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, |
6623 | SourceLocation LParenLoc, |
6624 | MultiExprArg Exprs, |
6625 | SourceLocation RParenLoc, |
6626 | bool ListInitialization); |
6627 | |
6628 | /// ActOnCXXNew - Parsed a C++ 'new' expression. |
6629 | ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, |
6630 | SourceLocation PlacementLParen, |
6631 | MultiExprArg PlacementArgs, |
6632 | SourceLocation PlacementRParen, |
6633 | SourceRange TypeIdParens, Declarator &D, |
6634 | Expr *Initializer); |
6635 | ExprResult |
6636 | BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, |
6637 | MultiExprArg PlacementArgs, SourceLocation PlacementRParen, |
6638 | SourceRange TypeIdParens, QualType AllocType, |
6639 | TypeSourceInfo *AllocTypeInfo, std::optional<Expr *> ArraySize, |
6640 | SourceRange DirectInitRange, Expr *Initializer); |
6641 | |
6642 | /// Determine whether \p FD is an aligned allocation or deallocation |
6643 | /// function that is unavailable. |
6644 | bool isUnavailableAlignedAllocationFunction(const FunctionDecl &FD) const; |
6645 | |
6646 | /// Produce diagnostics if \p FD is an aligned allocation or deallocation |
6647 | /// function that is unavailable. |
6648 | void diagnoseUnavailableAlignedAllocation(const FunctionDecl &FD, |
6649 | SourceLocation Loc); |
6650 | |
6651 | bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, |
6652 | SourceRange R); |
6653 | |
6654 | /// The scope in which to find allocation functions. |
6655 | enum AllocationFunctionScope { |
6656 | /// Only look for allocation functions in the global scope. |
6657 | AFS_Global, |
6658 | /// Only look for allocation functions in the scope of the |
6659 | /// allocated class. |
6660 | AFS_Class, |
6661 | /// Look for allocation functions in both the global scope |
6662 | /// and in the scope of the allocated class. |
6663 | AFS_Both |
6664 | }; |
6665 | |
6666 | /// Finds the overloads of operator new and delete that are appropriate |
6667 | /// for the allocation. |
6668 | bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, |
6669 | AllocationFunctionScope NewScope, |
6670 | AllocationFunctionScope DeleteScope, |
6671 | QualType AllocType, bool IsArray, |
6672 | bool &PassAlignment, MultiExprArg PlaceArgs, |
6673 | FunctionDecl *&OperatorNew, |
6674 | FunctionDecl *&OperatorDelete, |
6675 | bool Diagnose = true); |
6676 | void DeclareGlobalNewDelete(); |
6677 | void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, |
6678 | ArrayRef<QualType> Params); |
6679 | |
6680 | bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, |
6681 | DeclarationName Name, FunctionDecl *&Operator, |
6682 | bool Diagnose = true, bool WantSize = false, |
6683 | bool WantAligned = false); |
6684 | FunctionDecl *FindUsualDeallocationFunction(SourceLocation StartLoc, |
6685 | bool CanProvideSize, |
6686 | bool Overaligned, |
6687 | DeclarationName Name); |
6688 | FunctionDecl *FindDeallocationFunctionForDestructor(SourceLocation StartLoc, |
6689 | CXXRecordDecl *RD); |
6690 | |
6691 | /// ActOnCXXDelete - Parsed a C++ 'delete' expression |
6692 | ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, |
6693 | bool ArrayForm, Expr *Operand); |
6694 | void CheckVirtualDtorCall(CXXDestructorDecl *dtor, SourceLocation Loc, |
6695 | bool IsDelete, bool CallCanBeVirtual, |
6696 | bool WarnOnNonAbstractTypes, |
6697 | SourceLocation DtorLoc); |
6698 | |
6699 | ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, |
6700 | Expr *Operand, SourceLocation RParen); |
6701 | ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, |
6702 | SourceLocation RParen); |
6703 | |
6704 | ExprResult ActOnStartCXXMemberReference(Scope *S, Expr *Base, |
6705 | SourceLocation OpLoc, |
6706 | tok::TokenKind OpKind, |
6707 | ParsedType &ObjectType, |
6708 | bool &MayBePseudoDestructor); |
6709 | |
6710 | ExprResult BuildPseudoDestructorExpr( |
6711 | Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, |
6712 | const CXXScopeSpec &SS, TypeSourceInfo *ScopeType, SourceLocation CCLoc, |
6713 | SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType); |
6714 | |
6715 | ExprResult ActOnPseudoDestructorExpr( |
6716 | Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, |
6717 | CXXScopeSpec &SS, UnqualifiedId &FirstTypeName, SourceLocation CCLoc, |
6718 | SourceLocation TildeLoc, UnqualifiedId &SecondTypeName); |
6719 | |
6720 | ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, |
6721 | SourceLocation OpLoc, |
6722 | tok::TokenKind OpKind, |
6723 | SourceLocation TildeLoc, |
6724 | const DeclSpec &DS); |
6725 | |
6726 | /// MaybeCreateExprWithCleanups - If the current full-expression |
6727 | /// requires any cleanups, surround it with a ExprWithCleanups node. |
6728 | /// Otherwise, just returns the passed-in expression. |
6729 | Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); |
6730 | Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); |
6731 | ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); |
6732 | |
6733 | ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue) { |
6734 | return ActOnFinishFullExpr( |
6735 | Expr, CC: Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue); |
6736 | } |
6737 | ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC, |
6738 | bool DiscardedValue, bool IsConstexpr = false, |
6739 | bool IsTemplateArgument = false); |
6740 | StmtResult ActOnFinishFullStmt(Stmt *Stmt); |
6741 | |
6742 | ExprResult ActOnDecltypeExpression(Expr *E); |
6743 | |
6744 | bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id, |
6745 | bool IsUDSuffix); |
6746 | |
6747 | bool isUsualDeallocationFunction(const CXXMethodDecl *FD); |
6748 | |
6749 | ConditionResult ActOnConditionVariable(Decl *ConditionVar, |
6750 | SourceLocation StmtLoc, |
6751 | ConditionKind CK); |
6752 | |
6753 | ExprResult CheckConditionVariable(VarDecl *ConditionVar, |
6754 | SourceLocation StmtLoc, ConditionKind CK); |
6755 | |
6756 | /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. |
6757 | ExprResult CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr = false); |
6758 | |
6759 | bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); |
6760 | |
6761 | ExprResult PerformImplicitConversion( |
6762 | Expr *From, QualType ToType, const ImplicitConversionSequence &ICS, |
6763 | AssignmentAction Action, |
6764 | CheckedConversionKind CCK = CheckedConversionKind::Implicit); |
6765 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
6766 | const StandardConversionSequence &SCS, |
6767 | AssignmentAction Action, |
6768 | CheckedConversionKind CCK); |
6769 | |
6770 | bool CheckTypeTraitArity(unsigned Arity, SourceLocation Loc, size_t N); |
6771 | |
6772 | /// Parsed one of the type trait support pseudo-functions. |
6773 | ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
6774 | ArrayRef<ParsedType> Args, |
6775 | SourceLocation RParenLoc); |
6776 | ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
6777 | ArrayRef<TypeSourceInfo *> Args, |
6778 | SourceLocation RParenLoc); |
6779 | |
6780 | /// ActOnArrayTypeTrait - Parsed one of the binary type trait support |
6781 | /// pseudo-functions. |
6782 | ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, SourceLocation KWLoc, |
6783 | ParsedType LhsTy, Expr *DimExpr, |
6784 | SourceLocation RParen); |
6785 | |
6786 | ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, SourceLocation KWLoc, |
6787 | TypeSourceInfo *TSInfo, Expr *DimExpr, |
6788 | SourceLocation RParen); |
6789 | |
6790 | /// ActOnExpressionTrait - Parsed one of the unary type trait support |
6791 | /// pseudo-functions. |
6792 | ExprResult ActOnExpressionTrait(ExpressionTrait OET, SourceLocation KWLoc, |
6793 | Expr *Queried, SourceLocation RParen); |
6794 | |
6795 | ExprResult BuildExpressionTrait(ExpressionTrait OET, SourceLocation KWLoc, |
6796 | Expr *Queried, SourceLocation RParen); |
6797 | |
6798 | QualType CheckPointerToMemberOperands( // C++ 5.5 |
6799 | ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, SourceLocation OpLoc, |
6800 | bool isIndirect); |
6801 | QualType CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS, |
6802 | ExprResult &RHS, |
6803 | SourceLocation QuestionLoc); |
6804 | |
6805 | QualType CheckSizelessVectorConditionalTypes(ExprResult &Cond, |
6806 | ExprResult &LHS, ExprResult &RHS, |
6807 | SourceLocation QuestionLoc); |
6808 | |
6809 | QualType CXXCheckConditionalOperands( // C++ 5.16 |
6810 | ExprResult &cond, ExprResult &lhs, ExprResult &rhs, ExprValueKind &VK, |
6811 | ExprObjectKind &OK, SourceLocation questionLoc); |
6812 | |
6813 | QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, |
6814 | bool ConvertArgs = true); |
6815 | QualType FindCompositePointerType(SourceLocation Loc, ExprResult &E1, |
6816 | ExprResult &E2, bool ConvertArgs = true) { |
6817 | Expr *E1Tmp = E1.get(), *E2Tmp = E2.get(); |
6818 | QualType Composite = |
6819 | FindCompositePointerType(Loc, E1&: E1Tmp, E2&: E2Tmp, ConvertArgs); |
6820 | E1 = E1Tmp; |
6821 | E2 = E2Tmp; |
6822 | return Composite; |
6823 | } |
6824 | |
6825 | /// MaybeBindToTemporary - If the passed in expression has a record type with |
6826 | /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise |
6827 | /// it simply returns the passed in expression. |
6828 | ExprResult MaybeBindToTemporary(Expr *E); |
6829 | |
6830 | /// IgnoredValueConversions - Given that an expression's result is |
6831 | /// syntactically ignored, perform any conversions that are |
6832 | /// required. |
6833 | ExprResult IgnoredValueConversions(Expr *E); |
6834 | |
6835 | ExprResult CheckUnevaluatedOperand(Expr *E); |
6836 | |
6837 | /// Process any TypoExprs in the given Expr and its children, |
6838 | /// generating diagnostics as appropriate and returning a new Expr if there |
6839 | /// were typos that were all successfully corrected and ExprError if one or |
6840 | /// more typos could not be corrected. |
6841 | /// |
6842 | /// \param E The Expr to check for TypoExprs. |
6843 | /// |
6844 | /// \param InitDecl A VarDecl to avoid because the Expr being corrected is its |
6845 | /// initializer. |
6846 | /// |
6847 | /// \param RecoverUncorrectedTypos If true, when typo correction fails, it |
6848 | /// will rebuild the given Expr with all TypoExprs degraded to RecoveryExprs. |
6849 | /// |
6850 | /// \param Filter A function applied to a newly rebuilt Expr to determine if |
6851 | /// it is an acceptable/usable result from a single combination of typo |
6852 | /// corrections. As long as the filter returns ExprError, different |
6853 | /// combinations of corrections will be tried until all are exhausted. |
6854 | ExprResult CorrectDelayedTyposInExpr( |
6855 | Expr *E, VarDecl *InitDecl = nullptr, |
6856 | bool RecoverUncorrectedTypos = false, |
6857 | llvm::function_ref<ExprResult(Expr *)> Filter = |
6858 | [](Expr *E) -> ExprResult { return E; }); |
6859 | |
6860 | ExprResult CorrectDelayedTyposInExpr( |
6861 | ExprResult ER, VarDecl *InitDecl = nullptr, |
6862 | bool RecoverUncorrectedTypos = false, |
6863 | llvm::function_ref<ExprResult(Expr *)> Filter = |
6864 | [](Expr *E) -> ExprResult { return E; }) { |
6865 | return ER.isInvalid() |
6866 | ? ER |
6867 | : CorrectDelayedTyposInExpr(E: ER.get(), InitDecl, |
6868 | RecoverUncorrectedTypos, Filter); |
6869 | } |
6870 | |
6871 | /// Describes the result of an "if-exists" condition check. |
6872 | enum IfExistsResult { |
6873 | /// The symbol exists. |
6874 | IER_Exists, |
6875 | |
6876 | /// The symbol does not exist. |
6877 | IER_DoesNotExist, |
6878 | |
6879 | /// The name is a dependent name, so the results will differ |
6880 | /// from one instantiation to the next. |
6881 | IER_Dependent, |
6882 | |
6883 | /// An error occurred. |
6884 | IER_Error |
6885 | }; |
6886 | |
6887 | IfExistsResult |
6888 | CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, |
6889 | const DeclarationNameInfo &TargetNameInfo); |
6890 | |
6891 | IfExistsResult CheckMicrosoftIfExistsSymbol(Scope *S, |
6892 | SourceLocation KeywordLoc, |
6893 | bool IsIfExists, CXXScopeSpec &SS, |
6894 | UnqualifiedId &Name); |
6895 | |
6896 | RequiresExprBodyDecl * |
6897 | ActOnStartRequiresExpr(SourceLocation RequiresKWLoc, |
6898 | ArrayRef<ParmVarDecl *> LocalParameters, |
6899 | Scope *BodyScope); |
6900 | void ActOnFinishRequiresExpr(); |
6901 | concepts::Requirement *ActOnSimpleRequirement(Expr *E); |
6902 | concepts::Requirement *ActOnTypeRequirement(SourceLocation TypenameKWLoc, |
6903 | CXXScopeSpec &SS, |
6904 | SourceLocation NameLoc, |
6905 | const IdentifierInfo *TypeName, |
6906 | TemplateIdAnnotation *TemplateId); |
6907 | concepts::Requirement *ActOnCompoundRequirement(Expr *E, |
6908 | SourceLocation NoexceptLoc); |
6909 | concepts::Requirement *ActOnCompoundRequirement( |
6910 | Expr *E, SourceLocation NoexceptLoc, CXXScopeSpec &SS, |
6911 | TemplateIdAnnotation *TypeConstraint, unsigned Depth); |
6912 | concepts::Requirement *ActOnNestedRequirement(Expr *Constraint); |
6913 | concepts::ExprRequirement *BuildExprRequirement( |
6914 | Expr *E, bool IsSatisfied, SourceLocation NoexceptLoc, |
6915 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
6916 | concepts::ExprRequirement *BuildExprRequirement( |
6917 | concepts::Requirement::SubstitutionDiagnostic *ExprSubstDiag, |
6918 | bool IsSatisfied, SourceLocation NoexceptLoc, |
6919 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
6920 | concepts::TypeRequirement *BuildTypeRequirement(TypeSourceInfo *Type); |
6921 | concepts::TypeRequirement *BuildTypeRequirement( |
6922 | concepts::Requirement::SubstitutionDiagnostic *SubstDiag); |
6923 | concepts::NestedRequirement *BuildNestedRequirement(Expr *E); |
6924 | concepts::NestedRequirement * |
6925 | BuildNestedRequirement(StringRef InvalidConstraintEntity, |
6926 | const ASTConstraintSatisfaction &Satisfaction); |
6927 | ExprResult ActOnRequiresExpr(SourceLocation RequiresKWLoc, |
6928 | RequiresExprBodyDecl *Body, |
6929 | SourceLocation LParenLoc, |
6930 | ArrayRef<ParmVarDecl *> LocalParameters, |
6931 | SourceLocation RParenLoc, |
6932 | ArrayRef<concepts::Requirement *> Requirements, |
6933 | SourceLocation ClosingBraceLoc); |
6934 | |
6935 | private: |
6936 | ExprResult BuiltinOperatorNewDeleteOverloaded(ExprResult TheCallResult, |
6937 | bool IsDelete); |
6938 | |
6939 | void AnalyzeDeleteExprMismatch(const CXXDeleteExpr *DE); |
6940 | void AnalyzeDeleteExprMismatch(FieldDecl *Field, SourceLocation DeleteLoc, |
6941 | bool DeleteWasArrayForm); |
6942 | |
6943 | ///@} |
6944 | |
6945 | // |
6946 | // |
6947 | // ------------------------------------------------------------------------- |
6948 | // |
6949 | // |
6950 | |
6951 | /// \name Member Access Expressions |
6952 | /// Implementations are in SemaExprMember.cpp |
6953 | ///@{ |
6954 | |
6955 | public: |
6956 | /// Check whether an expression might be an implicit class member access. |
6957 | bool isPotentialImplicitMemberAccess(const CXXScopeSpec &SS, LookupResult &R, |
6958 | bool IsAddressOfOperand); |
6959 | |
6960 | ExprResult BuildPossibleImplicitMemberExpr( |
6961 | const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, |
6962 | const TemplateArgumentListInfo *TemplateArgs, const Scope *S); |
6963 | |
6964 | ExprResult |
6965 | BuildImplicitMemberExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
6966 | LookupResult &R, |
6967 | const TemplateArgumentListInfo *TemplateArgs, |
6968 | bool IsDefiniteInstance, const Scope *S); |
6969 | |
6970 | ExprResult ActOnDependentMemberExpr( |
6971 | Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OpLoc, |
6972 | const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
6973 | NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, |
6974 | const TemplateArgumentListInfo *TemplateArgs); |
6975 | |
6976 | ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, SourceLocation OpLoc, |
6977 | tok::TokenKind OpKind, CXXScopeSpec &SS, |
6978 | SourceLocation TemplateKWLoc, |
6979 | UnqualifiedId &Member, Decl *ObjCImpDecl); |
6980 | |
6981 | MemberExpr *BuildMemberExpr( |
6982 | Expr *Base, bool IsArrow, SourceLocation OpLoc, const CXXScopeSpec *SS, |
6983 | SourceLocation TemplateKWLoc, ValueDecl *Member, DeclAccessPair FoundDecl, |
6984 | bool HadMultipleCandidates, const DeclarationNameInfo &MemberNameInfo, |
6985 | QualType Ty, ExprValueKind VK, ExprObjectKind OK, |
6986 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
6987 | MemberExpr * |
6988 | BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc, |
6989 | NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, |
6990 | ValueDecl *Member, DeclAccessPair FoundDecl, |
6991 | bool HadMultipleCandidates, |
6992 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, |
6993 | ExprValueKind VK, ExprObjectKind OK, |
6994 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
6995 | |
6996 | bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, |
6997 | const CXXScopeSpec &SS, |
6998 | const LookupResult &R); |
6999 | |
7000 | // This struct is for use by ActOnMemberAccess to allow |
7001 | // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after |
7002 | // changing the access operator from a '.' to a '->' (to see if that is the |
7003 | // change needed to fix an error about an unknown member, e.g. when the class |
7004 | // defines a custom operator->). |
7005 | struct { |
7006 | Scope *; |
7007 | UnqualifiedId &; |
7008 | Decl *; |
7009 | }; |
7010 | |
7011 | ExprResult BuildMemberReferenceExpr( |
7012 | Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, |
7013 | CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
7014 | NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, |
7015 | const TemplateArgumentListInfo *TemplateArgs, const Scope *S, |
7016 | ActOnMemberAccessExtraArgs * = nullptr); |
7017 | |
7018 | ExprResult |
7019 | BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, |
7020 | bool IsArrow, const CXXScopeSpec &SS, |
7021 | SourceLocation TemplateKWLoc, |
7022 | NamedDecl *FirstQualifierInScope, LookupResult &R, |
7023 | const TemplateArgumentListInfo *TemplateArgs, |
7024 | const Scope *S, bool SuppressQualifierCheck = false, |
7025 | ActOnMemberAccessExtraArgs * = nullptr); |
7026 | |
7027 | ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, |
7028 | SourceLocation OpLoc, |
7029 | const CXXScopeSpec &SS, FieldDecl *Field, |
7030 | DeclAccessPair FoundDecl, |
7031 | const DeclarationNameInfo &MemberNameInfo); |
7032 | |
7033 | ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow); |
7034 | |
7035 | ExprResult BuildAnonymousStructUnionMemberReference( |
7036 | const CXXScopeSpec &SS, SourceLocation nameLoc, |
7037 | IndirectFieldDecl *indirectField, |
7038 | DeclAccessPair FoundDecl = DeclAccessPair::make(D: nullptr, AS: AS_none), |
7039 | Expr *baseObjectExpr = nullptr, SourceLocation opLoc = SourceLocation()); |
7040 | |
7041 | private: |
7042 | void CheckMemberAccessOfNoDeref(const MemberExpr *E); |
7043 | |
7044 | ///@} |
7045 | |
7046 | // |
7047 | // |
7048 | // ------------------------------------------------------------------------- |
7049 | // |
7050 | // |
7051 | |
7052 | /// \name Initializers |
7053 | /// Implementations are in SemaInit.cpp |
7054 | ///@{ |
7055 | |
7056 | public: |
7057 | /// Stack of types that correspond to the parameter entities that are |
7058 | /// currently being copy-initialized. Can be empty. |
7059 | llvm::SmallVector<QualType, 4> CurrentParameterCopyTypes; |
7060 | |
7061 | llvm::DenseMap<unsigned, CXXDeductionGuideDecl *> |
7062 | AggregateDeductionCandidates; |
7063 | |
7064 | bool IsStringInit(Expr *Init, const ArrayType *AT); |
7065 | |
7066 | bool CanPerformAggregateInitializationForOverloadResolution( |
7067 | const InitializedEntity &Entity, InitListExpr *From); |
7068 | |
7069 | ExprResult ActOnDesignatedInitializer(Designation &Desig, |
7070 | SourceLocation EqualOrColonLoc, |
7071 | bool GNUSyntax, ExprResult Init); |
7072 | |
7073 | /// Check that the lifetime of the initializer (and its subobjects) is |
7074 | /// sufficient for initializing the entity, and perform lifetime extension |
7075 | /// (when permitted) if not. |
7076 | void checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init); |
7077 | |
7078 | MaterializeTemporaryExpr * |
7079 | CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, |
7080 | bool BoundToLvalueReference); |
7081 | |
7082 | /// If \p E is a prvalue denoting an unmaterialized temporary, materialize |
7083 | /// it as an xvalue. In C++98, the result will still be a prvalue, because |
7084 | /// we don't have xvalues there. |
7085 | ExprResult TemporaryMaterializationConversion(Expr *E); |
7086 | |
7087 | ExprResult PerformQualificationConversion( |
7088 | Expr *E, QualType Ty, ExprValueKind VK = VK_PRValue, |
7089 | CheckedConversionKind CCK = CheckedConversionKind::Implicit); |
7090 | |
7091 | bool CanPerformCopyInitialization(const InitializedEntity &Entity, |
7092 | ExprResult Init); |
7093 | ExprResult PerformCopyInitialization(const InitializedEntity &Entity, |
7094 | SourceLocation EqualLoc, ExprResult Init, |
7095 | bool TopLevelOfInitList = false, |
7096 | bool AllowExplicit = false); |
7097 | |
7098 | QualType DeduceTemplateSpecializationFromInitializer( |
7099 | TypeSourceInfo *TInfo, const InitializedEntity &Entity, |
7100 | const InitializationKind &Kind, MultiExprArg Init); |
7101 | |
7102 | ///@} |
7103 | |
7104 | // |
7105 | // |
7106 | // ------------------------------------------------------------------------- |
7107 | // |
7108 | // |
7109 | |
7110 | /// \name C++ Lambda Expressions |
7111 | /// Implementations are in SemaLambda.cpp |
7112 | ///@{ |
7113 | |
7114 | public: |
7115 | /// Create a new lambda closure type. |
7116 | CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange, |
7117 | TypeSourceInfo *Info, |
7118 | unsigned LambdaDependencyKind, |
7119 | LambdaCaptureDefault CaptureDefault); |
7120 | |
7121 | /// Number lambda for linkage purposes if necessary. |
7122 | void handleLambdaNumbering(CXXRecordDecl *Class, CXXMethodDecl *Method, |
7123 | std::optional<CXXRecordDecl::LambdaNumbering> |
7124 | NumberingOverride = std::nullopt); |
7125 | |
7126 | /// Endow the lambda scope info with the relevant properties. |
7127 | void buildLambdaScope(sema::LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator, |
7128 | SourceRange IntroducerRange, |
7129 | LambdaCaptureDefault CaptureDefault, |
7130 | SourceLocation CaptureDefaultLoc, bool ExplicitParams, |
7131 | bool Mutable); |
7132 | |
7133 | CXXMethodDecl *CreateLambdaCallOperator(SourceRange IntroducerRange, |
7134 | CXXRecordDecl *Class); |
7135 | |
7136 | void AddTemplateParametersToLambdaCallOperator( |
7137 | CXXMethodDecl *CallOperator, CXXRecordDecl *Class, |
7138 | TemplateParameterList *TemplateParams); |
7139 | |
7140 | void CompleteLambdaCallOperator( |
7141 | CXXMethodDecl *Method, SourceLocation LambdaLoc, |
7142 | SourceLocation CallOperatorLoc, Expr *TrailingRequiresClause, |
7143 | TypeSourceInfo *MethodTyInfo, ConstexprSpecKind ConstexprKind, |
7144 | StorageClass SC, ArrayRef<ParmVarDecl *> Params, |
7145 | bool HasExplicitResultType); |
7146 | |
7147 | void DiagnoseInvalidExplicitObjectParameterInLambda(CXXMethodDecl *Method); |
7148 | |
7149 | /// Perform initialization analysis of the init-capture and perform |
7150 | /// any implicit conversions such as an lvalue-to-rvalue conversion if |
7151 | /// not being used to initialize a reference. |
7152 | ParsedType actOnLambdaInitCaptureInitialization( |
7153 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
7154 | IdentifierInfo *Id, LambdaCaptureInitKind InitKind, Expr *&Init) { |
7155 | return ParsedType::make(P: buildLambdaInitCaptureInitialization( |
7156 | Loc, ByRef, EllipsisLoc, NumExpansions: std::nullopt, Id, |
7157 | DirectInit: InitKind != LambdaCaptureInitKind::CopyInit, Init)); |
7158 | } |
7159 | QualType buildLambdaInitCaptureInitialization( |
7160 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
7161 | std::optional<unsigned> NumExpansions, IdentifierInfo *Id, |
7162 | bool DirectInit, Expr *&Init); |
7163 | |
7164 | /// Create a dummy variable within the declcontext of the lambda's |
7165 | /// call operator, for name lookup purposes for a lambda init capture. |
7166 | /// |
7167 | /// CodeGen handles emission of lambda captures, ignoring these dummy |
7168 | /// variables appropriately. |
7169 | VarDecl *createLambdaInitCaptureVarDecl( |
7170 | SourceLocation Loc, QualType InitCaptureType, SourceLocation EllipsisLoc, |
7171 | IdentifierInfo *Id, unsigned InitStyle, Expr *Init, DeclContext *DeclCtx); |
7172 | |
7173 | /// Add an init-capture to a lambda scope. |
7174 | void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var, bool ByRef); |
7175 | |
7176 | /// Note that we have finished the explicit captures for the |
7177 | /// given lambda. |
7178 | void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI); |
7179 | |
7180 | /// Deduce a block or lambda's return type based on the return |
7181 | /// statements present in the body. |
7182 | void deduceClosureReturnType(sema::CapturingScopeInfo &CSI); |
7183 | |
7184 | /// Once the Lambdas capture are known, we can start to create the closure, |
7185 | /// call operator method, and keep track of the captures. |
7186 | /// We do the capture lookup here, but they are not actually captured until |
7187 | /// after we know what the qualifiers of the call operator are. |
7188 | void ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro, |
7189 | Scope *CurContext); |
7190 | |
7191 | /// This is called after parsing the explicit template parameter list |
7192 | /// on a lambda (if it exists) in C++2a. |
7193 | void ActOnLambdaExplicitTemplateParameterList(LambdaIntroducer &Intro, |
7194 | SourceLocation LAngleLoc, |
7195 | ArrayRef<NamedDecl *> TParams, |
7196 | SourceLocation RAngleLoc, |
7197 | ExprResult RequiresClause); |
7198 | |
7199 | void ActOnLambdaClosureQualifiers(LambdaIntroducer &Intro, |
7200 | SourceLocation MutableLoc); |
7201 | |
7202 | void ActOnLambdaClosureParameters( |
7203 | Scope *LambdaScope, |
7204 | MutableArrayRef<DeclaratorChunk::ParamInfo> ParamInfo); |
7205 | |
7206 | /// ActOnStartOfLambdaDefinition - This is called just before we start |
7207 | /// parsing the body of a lambda; it analyzes the explicit captures and |
7208 | /// arguments, and sets up various data-structures for the body of the |
7209 | /// lambda. |
7210 | void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, |
7211 | Declarator &ParamInfo, const DeclSpec &DS); |
7212 | |
7213 | /// ActOnLambdaError - If there is an error parsing a lambda, this callback |
7214 | /// is invoked to pop the information about the lambda. |
7215 | void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, |
7216 | bool IsInstantiation = false); |
7217 | |
7218 | /// ActOnLambdaExpr - This is called when the body of a lambda expression |
7219 | /// was successfully completed. |
7220 | ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body); |
7221 | |
7222 | /// Does copying/destroying the captured variable have side effects? |
7223 | bool CaptureHasSideEffects(const sema::Capture &From); |
7224 | |
7225 | /// Diagnose if an explicit lambda capture is unused. Returns true if a |
7226 | /// diagnostic is emitted. |
7227 | bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange, |
7228 | const sema::Capture &From); |
7229 | |
7230 | /// Build a FieldDecl suitable to hold the given capture. |
7231 | FieldDecl *BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture); |
7232 | |
7233 | /// Initialize the given capture with a suitable expression. |
7234 | ExprResult BuildCaptureInit(const sema::Capture &Capture, |
7235 | SourceLocation ImplicitCaptureLoc, |
7236 | bool IsOpenMPMapping = false); |
7237 | |
7238 | /// Complete a lambda-expression having processed and attached the |
7239 | /// lambda body. |
7240 | ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, |
7241 | sema::LambdaScopeInfo *LSI); |
7242 | |
7243 | /// Get the return type to use for a lambda's conversion function(s) to |
7244 | /// function pointer type, given the type of the call operator. |
7245 | QualType |
7246 | getLambdaConversionFunctionResultType(const FunctionProtoType *CallOpType, |
7247 | CallingConv CC); |
7248 | |
7249 | ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, |
7250 | SourceLocation ConvLocation, |
7251 | CXXConversionDecl *Conv, Expr *Src); |
7252 | |
7253 | class LambdaScopeForCallOperatorInstantiationRAII |
7254 | : private FunctionScopeRAII { |
7255 | public: |
7256 | LambdaScopeForCallOperatorInstantiationRAII( |
7257 | Sema &SemasRef, FunctionDecl *FD, MultiLevelTemplateArgumentList MLTAL, |
7258 | LocalInstantiationScope &Scope, |
7259 | bool ShouldAddDeclsFromParentScope = true); |
7260 | }; |
7261 | |
7262 | /// Compute the mangling number context for a lambda expression or |
7263 | /// block literal. Also return the extra mangling decl if any. |
7264 | /// |
7265 | /// \param DC - The DeclContext containing the lambda expression or |
7266 | /// block literal. |
7267 | std::tuple<MangleNumberingContext *, Decl *> |
7268 | getCurrentMangleNumberContext(const DeclContext *DC); |
7269 | |
7270 | ///@} |
7271 | |
7272 | // |
7273 | // |
7274 | // ------------------------------------------------------------------------- |
7275 | // |
7276 | // |
7277 | |
7278 | /// \name Name Lookup |
7279 | /// |
7280 | /// These routines provide name lookup that is used during semantic |
7281 | /// analysis to resolve the various kinds of names (identifiers, |
7282 | /// overloaded operator names, constructor names, etc.) into zero or |
7283 | /// more declarations within a particular scope. The major entry |
7284 | /// points are LookupName, which performs unqualified name lookup, |
7285 | /// and LookupQualifiedName, which performs qualified name lookup. |
7286 | /// |
7287 | /// All name lookup is performed based on some specific criteria, |
7288 | /// which specify what names will be visible to name lookup and how |
7289 | /// far name lookup should work. These criteria are important both |
7290 | /// for capturing language semantics (certain lookups will ignore |
7291 | /// certain names, for example) and for performance, since name |
7292 | /// lookup is often a bottleneck in the compilation of C++. Name |
7293 | /// lookup criteria is specified via the LookupCriteria enumeration. |
7294 | /// |
7295 | /// The results of name lookup can vary based on the kind of name |
7296 | /// lookup performed, the current language, and the translation |
7297 | /// unit. In C, for example, name lookup will either return nothing |
7298 | /// (no entity found) or a single declaration. In C++, name lookup |
7299 | /// can additionally refer to a set of overloaded functions or |
7300 | /// result in an ambiguity. All of the possible results of name |
7301 | /// lookup are captured by the LookupResult class, which provides |
7302 | /// the ability to distinguish among them. |
7303 | /// |
7304 | /// Implementations are in SemaLookup.cpp |
7305 | ///@{ |
7306 | |
7307 | public: |
7308 | /// Tracks whether we are in a context where typo correction is |
7309 | /// disabled. |
7310 | bool DisableTypoCorrection; |
7311 | |
7312 | /// The number of typos corrected by CorrectTypo. |
7313 | unsigned TyposCorrected; |
7314 | |
7315 | typedef llvm::SmallSet<SourceLocation, 2> SrcLocSet; |
7316 | typedef llvm::DenseMap<IdentifierInfo *, SrcLocSet> IdentifierSourceLocations; |
7317 | |
7318 | /// A cache containing identifiers for which typo correction failed and |
7319 | /// their locations, so that repeated attempts to correct an identifier in a |
7320 | /// given location are ignored if typo correction already failed for it. |
7321 | IdentifierSourceLocations TypoCorrectionFailures; |
7322 | |
7323 | /// SpecialMemberOverloadResult - The overloading result for a special member |
7324 | /// function. |
7325 | /// |
7326 | /// This is basically a wrapper around PointerIntPair. The lowest bits of the |
7327 | /// integer are used to determine whether overload resolution succeeded. |
7328 | class SpecialMemberOverloadResult { |
7329 | public: |
7330 | enum Kind { NoMemberOrDeleted, Ambiguous, Success }; |
7331 | |
7332 | private: |
7333 | llvm::PointerIntPair<CXXMethodDecl *, 2> Pair; |
7334 | |
7335 | public: |
7336 | SpecialMemberOverloadResult() {} |
7337 | SpecialMemberOverloadResult(CXXMethodDecl *MD) |
7338 | : Pair(MD, MD->isDeleted() ? NoMemberOrDeleted : Success) {} |
7339 | |
7340 | CXXMethodDecl *getMethod() const { return Pair.getPointer(); } |
7341 | void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); } |
7342 | |
7343 | Kind getKind() const { return static_cast<Kind>(Pair.getInt()); } |
7344 | void setKind(Kind K) { Pair.setInt(K); } |
7345 | }; |
7346 | |
7347 | class SpecialMemberOverloadResultEntry : public llvm::FastFoldingSetNode, |
7348 | public SpecialMemberOverloadResult { |
7349 | public: |
7350 | SpecialMemberOverloadResultEntry(const llvm::FoldingSetNodeID &ID) |
7351 | : FastFoldingSetNode(ID) {} |
7352 | }; |
7353 | |
7354 | /// A cache of special member function overload resolution results |
7355 | /// for C++ records. |
7356 | llvm::FoldingSet<SpecialMemberOverloadResultEntry> SpecialMemberCache; |
7357 | |
7358 | /// Holds TypoExprs that are created from `createDelayedTypo`. This is used by |
7359 | /// `TransformTypos` in order to keep track of any TypoExprs that are created |
7360 | /// recursively during typo correction and wipe them away if the correction |
7361 | /// fails. |
7362 | llvm::SmallVector<TypoExpr *, 2> TypoExprs; |
7363 | |
7364 | enum class AcceptableKind { Visible, Reachable }; |
7365 | |
7366 | // Members have to be NamespaceDecl* or TranslationUnitDecl*. |
7367 | // TODO: make this is a typesafe union. |
7368 | typedef llvm::SmallSetVector<DeclContext *, 16> AssociatedNamespaceSet; |
7369 | typedef llvm::SmallSetVector<CXXRecordDecl *, 16> AssociatedClassSet; |
7370 | |
7371 | /// Describes the kind of name lookup to perform. |
7372 | enum LookupNameKind { |
7373 | /// Ordinary name lookup, which finds ordinary names (functions, |
7374 | /// variables, typedefs, etc.) in C and most kinds of names |
7375 | /// (functions, variables, members, types, etc.) in C++. |
7376 | LookupOrdinaryName = 0, |
7377 | /// Tag name lookup, which finds the names of enums, classes, |
7378 | /// structs, and unions. |
7379 | LookupTagName, |
7380 | /// Label name lookup. |
7381 | LookupLabel, |
7382 | /// Member name lookup, which finds the names of |
7383 | /// class/struct/union members. |
7384 | LookupMemberName, |
7385 | /// Look up of an operator name (e.g., operator+) for use with |
7386 | /// operator overloading. This lookup is similar to ordinary name |
7387 | /// lookup, but will ignore any declarations that are class members. |
7388 | LookupOperatorName, |
7389 | /// Look up a name following ~ in a destructor name. This is an ordinary |
7390 | /// lookup, but prefers tags to typedefs. |
7391 | LookupDestructorName, |
7392 | /// Look up of a name that precedes the '::' scope resolution |
7393 | /// operator in C++. This lookup completely ignores operator, object, |
7394 | /// function, and enumerator names (C++ [basic.lookup.qual]p1). |
7395 | LookupNestedNameSpecifierName, |
7396 | /// Look up a namespace name within a C++ using directive or |
7397 | /// namespace alias definition, ignoring non-namespace names (C++ |
7398 | /// [basic.lookup.udir]p1). |
7399 | LookupNamespaceName, |
7400 | /// Look up all declarations in a scope with the given name, |
7401 | /// including resolved using declarations. This is appropriate |
7402 | /// for checking redeclarations for a using declaration. |
7403 | LookupUsingDeclName, |
7404 | /// Look up an ordinary name that is going to be redeclared as a |
7405 | /// name with linkage. This lookup ignores any declarations that |
7406 | /// are outside of the current scope unless they have linkage. See |
7407 | /// C99 6.2.2p4-5 and C++ [basic.link]p6. |
7408 | LookupRedeclarationWithLinkage, |
7409 | /// Look up a friend of a local class. This lookup does not look |
7410 | /// outside the innermost non-class scope. See C++11 [class.friend]p11. |
7411 | LookupLocalFriendName, |
7412 | /// Look up the name of an Objective-C protocol. |
7413 | LookupObjCProtocolName, |
7414 | /// Look up implicit 'self' parameter of an objective-c method. |
7415 | LookupObjCImplicitSelfParam, |
7416 | /// Look up the name of an OpenMP user-defined reduction operation. |
7417 | LookupOMPReductionName, |
7418 | /// Look up the name of an OpenMP user-defined mapper. |
7419 | LookupOMPMapperName, |
7420 | /// Look up any declaration with any name. |
7421 | LookupAnyName |
7422 | }; |
7423 | |
7424 | /// The possible outcomes of name lookup for a literal operator. |
7425 | enum LiteralOperatorLookupResult { |
7426 | /// The lookup resulted in an error. |
7427 | LOLR_Error, |
7428 | /// The lookup found no match but no diagnostic was issued. |
7429 | LOLR_ErrorNoDiagnostic, |
7430 | /// The lookup found a single 'cooked' literal operator, which |
7431 | /// expects a normal literal to be built and passed to it. |
7432 | LOLR_Cooked, |
7433 | /// The lookup found a single 'raw' literal operator, which expects |
7434 | /// a string literal containing the spelling of the literal token. |
7435 | LOLR_Raw, |
7436 | /// The lookup found an overload set of literal operator templates, |
7437 | /// which expect the characters of the spelling of the literal token to be |
7438 | /// passed as a non-type template argument pack. |
7439 | LOLR_Template, |
7440 | /// The lookup found an overload set of literal operator templates, |
7441 | /// which expect the character type and characters of the spelling of the |
7442 | /// string literal token to be passed as template arguments. |
7443 | LOLR_StringTemplatePack, |
7444 | }; |
7445 | |
7446 | SpecialMemberOverloadResult |
7447 | LookupSpecialMember(CXXRecordDecl *D, CXXSpecialMemberKind SM, bool ConstArg, |
7448 | bool VolatileArg, bool RValueThis, bool ConstThis, |
7449 | bool VolatileThis); |
7450 | |
7451 | typedef std::function<void(const TypoCorrection &)> TypoDiagnosticGenerator; |
7452 | typedef std::function<ExprResult(Sema &, TypoExpr *, TypoCorrection)> |
7453 | TypoRecoveryCallback; |
7454 | |
7455 | RedeclarationKind forRedeclarationInCurContext() const; |
7456 | |
7457 | /// Look up a name, looking for a single declaration. Return |
7458 | /// null if the results were absent, ambiguous, or overloaded. |
7459 | /// |
7460 | /// It is preferable to use the elaborated form and explicitly handle |
7461 | /// ambiguity and overloaded. |
7462 | NamedDecl *LookupSingleName( |
7463 | Scope *S, DeclarationName Name, SourceLocation Loc, |
7464 | LookupNameKind NameKind, |
7465 | RedeclarationKind Redecl = RedeclarationKind::NotForRedeclaration); |
7466 | bool LookupBuiltin(LookupResult &R); |
7467 | void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID); |
7468 | bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation = false, |
7469 | bool ForceNoCPlusPlus = false); |
7470 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
7471 | bool InUnqualifiedLookup = false); |
7472 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
7473 | CXXScopeSpec &SS); |
7474 | bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, |
7475 | bool AllowBuiltinCreation = false, |
7476 | bool EnteringContext = false); |
7477 | ObjCProtocolDecl *LookupProtocol( |
7478 | IdentifierInfo *II, SourceLocation IdLoc, |
7479 | RedeclarationKind Redecl = RedeclarationKind::NotForRedeclaration); |
7480 | bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class); |
7481 | |
7482 | void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, |
7483 | UnresolvedSetImpl &Functions); |
7484 | |
7485 | LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, |
7486 | SourceLocation GnuLabelLoc = SourceLocation()); |
7487 | |
7488 | DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); |
7489 | CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class); |
7490 | CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class, |
7491 | unsigned Quals); |
7492 | CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, |
7493 | bool RValueThis, unsigned ThisQuals); |
7494 | CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class, |
7495 | unsigned Quals); |
7496 | CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals, |
7497 | bool RValueThis, unsigned ThisQuals); |
7498 | CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); |
7499 | |
7500 | /// Force the declaration of any implicitly-declared members of this |
7501 | /// class. |
7502 | void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); |
7503 | |
7504 | /// Make a merged definition of an existing hidden definition \p ND |
7505 | /// visible at the specified location. |
7506 | void makeMergedDefinitionVisible(NamedDecl *ND); |
7507 | |
7508 | /// Get the set of additional modules that should be checked during |
7509 | /// name lookup. A module and its imports become visible when instanting a |
7510 | /// template defined within it. |
7511 | llvm::DenseSet<Module *> &getLookupModules(); |
7512 | |
7513 | bool hasVisibleMergedDefinition(const NamedDecl *Def); |
7514 | bool hasMergedDefinitionInCurrentModule(const NamedDecl *Def); |
7515 | |
7516 | /// Determine if the template parameter \p D has a visible default argument. |
7517 | bool |
7518 | hasVisibleDefaultArgument(const NamedDecl *D, |
7519 | llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
7520 | /// Determine if the template parameter \p D has a reachable default argument. |
7521 | bool hasReachableDefaultArgument( |
7522 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
7523 | /// Determine if the template parameter \p D has a reachable default argument. |
7524 | bool hasAcceptableDefaultArgument(const NamedDecl *D, |
7525 | llvm::SmallVectorImpl<Module *> *Modules, |
7526 | Sema::AcceptableKind Kind); |
7527 | |
7528 | /// Determine if there is a visible declaration of \p D that is an explicit |
7529 | /// specialization declaration for a specialization of a template. (For a |
7530 | /// member specialization, use hasVisibleMemberSpecialization.) |
7531 | bool hasVisibleExplicitSpecialization( |
7532 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
7533 | /// Determine if there is a reachable declaration of \p D that is an explicit |
7534 | /// specialization declaration for a specialization of a template. (For a |
7535 | /// member specialization, use hasReachableMemberSpecialization.) |
7536 | bool hasReachableExplicitSpecialization( |
7537 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
7538 | |
7539 | /// Determine if there is a visible declaration of \p D that is a member |
7540 | /// specialization declaration (as opposed to an instantiated declaration). |
7541 | bool hasVisibleMemberSpecialization( |
7542 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
7543 | /// Determine if there is a reachable declaration of \p D that is a member |
7544 | /// specialization declaration (as opposed to an instantiated declaration). |
7545 | bool hasReachableMemberSpecialization( |
7546 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
7547 | |
7548 | bool isModuleVisible(const Module *M, bool ModulePrivate = false); |
7549 | |
7550 | /// Determine whether any declaration of an entity is visible. |
7551 | bool |
7552 | hasVisibleDeclaration(const NamedDecl *D, |
7553 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
7554 | return isVisible(D) || hasVisibleDeclarationSlow(D, Modules); |
7555 | } |
7556 | |
7557 | bool hasVisibleDeclarationSlow(const NamedDecl *D, |
7558 | llvm::SmallVectorImpl<Module *> *Modules); |
7559 | /// Determine whether any declaration of an entity is reachable. |
7560 | bool |
7561 | hasReachableDeclaration(const NamedDecl *D, |
7562 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
7563 | return isReachable(D) || hasReachableDeclarationSlow(D, Modules); |
7564 | } |
7565 | bool hasReachableDeclarationSlow( |
7566 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
7567 | |
7568 | void diagnoseTypo(const TypoCorrection &Correction, |
7569 | const PartialDiagnostic &TypoDiag, |
7570 | bool ErrorRecovery = true); |
7571 | |
7572 | void diagnoseTypo(const TypoCorrection &Correction, |
7573 | const PartialDiagnostic &TypoDiag, |
7574 | const PartialDiagnostic &PrevNote, |
7575 | bool ErrorRecovery = true); |
7576 | |
7577 | void FindAssociatedClassesAndNamespaces( |
7578 | SourceLocation InstantiationLoc, ArrayRef<Expr *> Args, |
7579 | AssociatedNamespaceSet &AssociatedNamespaces, |
7580 | AssociatedClassSet &AssociatedClasses); |
7581 | |
7582 | void DiagnoseAmbiguousLookup(LookupResult &Result); |
7583 | |
7584 | LiteralOperatorLookupResult |
7585 | LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef<QualType> ArgTys, |
7586 | bool AllowRaw, bool AllowTemplate, |
7587 | bool AllowStringTemplate, bool DiagnoseMissing, |
7588 | StringLiteral *StringLit = nullptr); |
7589 | |
7590 | void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc, |
7591 | ArrayRef<Expr *> Args, ADLResult &Functions); |
7592 | |
7593 | void LookupVisibleDecls(Scope *S, LookupNameKind Kind, |
7594 | VisibleDeclConsumer &Consumer, |
7595 | bool IncludeGlobalScope = true, |
7596 | bool LoadExternal = true); |
7597 | void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, |
7598 | VisibleDeclConsumer &Consumer, |
7599 | bool IncludeGlobalScope = true, |
7600 | bool IncludeDependentBases = false, |
7601 | bool LoadExternal = true); |
7602 | |
7603 | enum CorrectTypoKind { |
7604 | CTK_NonError, // CorrectTypo used in a non error recovery situation. |
7605 | CTK_ErrorRecovery // CorrectTypo used in normal error recovery. |
7606 | }; |
7607 | |
7608 | TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, |
7609 | Sema::LookupNameKind LookupKind, Scope *S, |
7610 | CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, |
7611 | CorrectTypoKind Mode, |
7612 | DeclContext *MemberContext = nullptr, |
7613 | bool EnteringContext = false, |
7614 | const ObjCObjectPointerType *OPT = nullptr, |
7615 | bool RecordFailure = true); |
7616 | |
7617 | TypoExpr *CorrectTypoDelayed( |
7618 | const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, |
7619 | Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, |
7620 | TypoDiagnosticGenerator TDG, TypoRecoveryCallback TRC, |
7621 | CorrectTypoKind Mode, DeclContext *MemberContext = nullptr, |
7622 | bool EnteringContext = false, const ObjCObjectPointerType *OPT = nullptr); |
7623 | |
7624 | /// Kinds of missing import. Note, the values of these enumerators correspond |
7625 | /// to %select values in diagnostics. |
7626 | enum class MissingImportKind { |
7627 | Declaration, |
7628 | Definition, |
7629 | DefaultArgument, |
7630 | ExplicitSpecialization, |
7631 | PartialSpecialization |
7632 | }; |
7633 | |
7634 | /// Diagnose that the specified declaration needs to be visible but |
7635 | /// isn't, and suggest a module import that would resolve the problem. |
7636 | void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl, |
7637 | MissingImportKind MIK, bool Recover = true); |
7638 | void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl, |
7639 | SourceLocation DeclLoc, ArrayRef<Module *> Modules, |
7640 | MissingImportKind MIK, bool Recover); |
7641 | |
7642 | struct TypoExprState { |
7643 | std::unique_ptr<TypoCorrectionConsumer> Consumer; |
7644 | TypoDiagnosticGenerator DiagHandler; |
7645 | TypoRecoveryCallback RecoveryHandler; |
7646 | TypoExprState(); |
7647 | TypoExprState(TypoExprState &&other) noexcept; |
7648 | TypoExprState &operator=(TypoExprState &&other) noexcept; |
7649 | }; |
7650 | |
7651 | const TypoExprState &getTypoExprState(TypoExpr *TE) const; |
7652 | |
7653 | /// Clears the state of the given TypoExpr. |
7654 | void clearDelayedTypo(TypoExpr *TE); |
7655 | |
7656 | /// Called on #pragma clang __debug dump II |
7657 | void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II); |
7658 | |
7659 | /// Called on #pragma clang __debug dump E |
7660 | void ActOnPragmaDump(Expr *E); |
7661 | |
7662 | private: |
7663 | // The set of known/encountered (unique, canonicalized) NamespaceDecls. |
7664 | // |
7665 | // The boolean value will be true to indicate that the namespace was loaded |
7666 | // from an AST/PCH file, or false otherwise. |
7667 | llvm::MapVector<NamespaceDecl *, bool> KnownNamespaces; |
7668 | |
7669 | /// Whether we have already loaded known namespaces from an extenal |
7670 | /// source. |
7671 | bool LoadedExternalKnownNamespaces; |
7672 | |
7673 | bool CppLookupName(LookupResult &R, Scope *S); |
7674 | |
7675 | bool isUsableModule(const Module *M); |
7676 | |
7677 | /// Helper for CorrectTypo and CorrectTypoDelayed used to create and |
7678 | /// populate a new TypoCorrectionConsumer. Returns nullptr if typo correction |
7679 | /// should be skipped entirely. |
7680 | std::unique_ptr<TypoCorrectionConsumer> makeTypoCorrectionConsumer( |
7681 | const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, |
7682 | Scope *S, CXXScopeSpec *SS, CorrectionCandidateCallback &CCC, |
7683 | DeclContext *MemberContext, bool EnteringContext, |
7684 | const ObjCObjectPointerType *OPT, bool ErrorRecovery); |
7685 | |
7686 | /// The set of unhandled TypoExprs and their associated state. |
7687 | llvm::MapVector<TypoExpr *, TypoExprState> DelayedTypos; |
7688 | |
7689 | /// Creates a new TypoExpr AST node. |
7690 | TypoExpr *createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC, |
7691 | TypoDiagnosticGenerator TDG, |
7692 | TypoRecoveryCallback TRC, SourceLocation TypoLoc); |
7693 | |
7694 | /// Cache for module units which is usable for current module. |
7695 | llvm::DenseSet<const Module *> UsableModuleUnitsCache; |
7696 | |
7697 | /// Record the typo correction failure and return an empty correction. |
7698 | TypoCorrection FailedCorrection(IdentifierInfo *Typo, SourceLocation TypoLoc, |
7699 | bool RecordFailure = true) { |
7700 | if (RecordFailure) |
7701 | TypoCorrectionFailures[Typo].insert(V: TypoLoc); |
7702 | return TypoCorrection(); |
7703 | } |
7704 | |
7705 | bool isAcceptableSlow(const NamedDecl *D, AcceptableKind Kind); |
7706 | |
7707 | /// Determine whether two declarations should be linked together, given that |
7708 | /// the old declaration might not be visible and the new declaration might |
7709 | /// not have external linkage. |
7710 | bool shouldLinkPossiblyHiddenDecl(const NamedDecl *Old, |
7711 | const NamedDecl *New) { |
7712 | if (isVisible(D: Old)) |
7713 | return true; |
7714 | // See comment in below overload for why it's safe to compute the linkage |
7715 | // of the new declaration here. |
7716 | if (New->isExternallyDeclarable()) { |
7717 | assert(Old->isExternallyDeclarable() && |
7718 | "should not have found a non-externally-declarable previous decl" ); |
7719 | return true; |
7720 | } |
7721 | return false; |
7722 | } |
7723 | bool shouldLinkPossiblyHiddenDecl(LookupResult &Old, const NamedDecl *New); |
7724 | |
7725 | ///@} |
7726 | |
7727 | // |
7728 | // |
7729 | // ------------------------------------------------------------------------- |
7730 | // |
7731 | // |
7732 | |
7733 | /// \name Modules |
7734 | /// Implementations are in SemaModule.cpp |
7735 | ///@{ |
7736 | |
7737 | public: |
7738 | /// Get the module unit whose scope we are currently within. |
7739 | Module *getCurrentModule() const { |
7740 | return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module; |
7741 | } |
7742 | |
7743 | /// Is the module scope we are an implementation unit? |
7744 | bool currentModuleIsImplementation() const { |
7745 | return ModuleScopes.empty() |
7746 | ? false |
7747 | : ModuleScopes.back().Module->isModuleImplementation(); |
7748 | } |
7749 | |
7750 | // When loading a non-modular PCH files, this is used to restore module |
7751 | // visibility. |
7752 | void makeModuleVisible(Module *Mod, SourceLocation ImportLoc) { |
7753 | VisibleModules.setVisible(M: Mod, Loc: ImportLoc); |
7754 | } |
7755 | |
7756 | enum class ModuleDeclKind { |
7757 | Interface, ///< 'export module X;' |
7758 | Implementation, ///< 'module X;' |
7759 | PartitionInterface, ///< 'export module X:Y;' |
7760 | PartitionImplementation, ///< 'module X:Y;' |
7761 | }; |
7762 | |
7763 | /// An enumeration to represent the transition of states in parsing module |
7764 | /// fragments and imports. If we are not parsing a C++20 TU, or we find |
7765 | /// an error in state transition, the state is set to NotACXX20Module. |
7766 | enum class ModuleImportState { |
7767 | FirstDecl, ///< Parsing the first decl in a TU. |
7768 | GlobalFragment, ///< after 'module;' but before 'module X;' |
7769 | ImportAllowed, ///< after 'module X;' but before any non-import decl. |
7770 | ImportFinished, ///< after any non-import decl. |
7771 | PrivateFragmentImportAllowed, ///< after 'module :private;' but before any |
7772 | ///< non-import decl. |
7773 | PrivateFragmentImportFinished, ///< after 'module :private;' but a |
7774 | ///< non-import decl has already been seen. |
7775 | NotACXX20Module ///< Not a C++20 TU, or an invalid state was found. |
7776 | }; |
7777 | |
7778 | /// The parser has processed a module-declaration that begins the definition |
7779 | /// of a module interface or implementation. |
7780 | DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc, |
7781 | SourceLocation ModuleLoc, ModuleDeclKind MDK, |
7782 | ModuleIdPath Path, ModuleIdPath Partition, |
7783 | ModuleImportState &ImportState); |
7784 | |
7785 | /// The parser has processed a global-module-fragment declaration that begins |
7786 | /// the definition of the global module fragment of the current module unit. |
7787 | /// \param ModuleLoc The location of the 'module' keyword. |
7788 | DeclGroupPtrTy ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc); |
7789 | |
7790 | /// The parser has processed a private-module-fragment declaration that begins |
7791 | /// the definition of the private module fragment of the current module unit. |
7792 | /// \param ModuleLoc The location of the 'module' keyword. |
7793 | /// \param PrivateLoc The location of the 'private' keyword. |
7794 | DeclGroupPtrTy ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc, |
7795 | SourceLocation PrivateLoc); |
7796 | |
7797 | /// The parser has processed a module import declaration. |
7798 | /// |
7799 | /// \param StartLoc The location of the first token in the declaration. This |
7800 | /// could be the location of an '@', 'export', or 'import'. |
7801 | /// \param ExportLoc The location of the 'export' keyword, if any. |
7802 | /// \param ImportLoc The location of the 'import' keyword. |
7803 | /// \param Path The module toplevel name as an access path. |
7804 | /// \param IsPartition If the name is for a partition. |
7805 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
7806 | SourceLocation ExportLoc, |
7807 | SourceLocation ImportLoc, ModuleIdPath Path, |
7808 | bool IsPartition = false); |
7809 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
7810 | SourceLocation ExportLoc, |
7811 | SourceLocation ImportLoc, Module *M, |
7812 | ModuleIdPath Path = {}); |
7813 | |
7814 | /// The parser has processed a module import translated from a |
7815 | /// #include or similar preprocessing directive. |
7816 | void ActOnAnnotModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
7817 | void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
7818 | |
7819 | /// The parsed has entered a submodule. |
7820 | void ActOnAnnotModuleBegin(SourceLocation DirectiveLoc, Module *Mod); |
7821 | /// The parser has left a submodule. |
7822 | void ActOnAnnotModuleEnd(SourceLocation DirectiveLoc, Module *Mod); |
7823 | |
7824 | /// Create an implicit import of the given module at the given |
7825 | /// source location, for error recovery, if possible. |
7826 | /// |
7827 | /// This routine is typically used when an entity found by name lookup |
7828 | /// is actually hidden within a module that we know about but the user |
7829 | /// has forgotten to import. |
7830 | void createImplicitModuleImportForErrorRecovery(SourceLocation Loc, |
7831 | Module *Mod); |
7832 | |
7833 | Decl *ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, |
7834 | SourceLocation LBraceLoc); |
7835 | Decl *ActOnFinishExportDecl(Scope *S, Decl *ExportDecl, |
7836 | SourceLocation RBraceLoc); |
7837 | |
7838 | private: |
7839 | /// The parser has begun a translation unit to be compiled as a C++20 |
7840 | /// Header Unit, helper for ActOnStartOfTranslationUnit() only. |
7841 | void HandleStartOfHeaderUnit(); |
7842 | |
7843 | struct ModuleScope { |
7844 | SourceLocation BeginLoc; |
7845 | clang::Module *Module = nullptr; |
7846 | VisibleModuleSet OuterVisibleModules; |
7847 | }; |
7848 | /// The modules we're currently parsing. |
7849 | llvm::SmallVector<ModuleScope, 16> ModuleScopes; |
7850 | |
7851 | /// For an interface unit, this is the implicitly imported interface unit. |
7852 | clang::Module *ThePrimaryInterface = nullptr; |
7853 | |
7854 | /// The explicit global module fragment of the current translation unit. |
7855 | /// The explicit Global Module Fragment, as specified in C++ |
7856 | /// [module.global.frag]. |
7857 | clang::Module *TheGlobalModuleFragment = nullptr; |
7858 | |
7859 | /// The implicit global module fragments of the current translation unit. |
7860 | /// |
7861 | /// The contents in the implicit global module fragment can't be discarded. |
7862 | clang::Module *TheImplicitGlobalModuleFragment = nullptr; |
7863 | |
7864 | /// Namespace definitions that we will export when they finish. |
7865 | llvm::SmallPtrSet<const NamespaceDecl *, 8> DeferredExportedNamespaces; |
7866 | |
7867 | /// In a C++ standard module, inline declarations require a definition to be |
7868 | /// present at the end of a definition domain. This set holds the decls to |
7869 | /// be checked at the end of the TU. |
7870 | llvm::SmallPtrSet<const FunctionDecl *, 8> PendingInlineFuncDecls; |
7871 | |
7872 | /// Helper function to judge if we are in module purview. |
7873 | /// Return false if we are not in a module. |
7874 | bool isCurrentModulePurview() const; |
7875 | |
7876 | /// Enter the scope of the explicit global module fragment. |
7877 | Module *PushGlobalModuleFragment(SourceLocation BeginLoc); |
7878 | /// Leave the scope of the explicit global module fragment. |
7879 | void PopGlobalModuleFragment(); |
7880 | |
7881 | /// Enter the scope of an implicit global module fragment. |
7882 | Module *PushImplicitGlobalModuleFragment(SourceLocation BeginLoc); |
7883 | /// Leave the scope of an implicit global module fragment. |
7884 | void PopImplicitGlobalModuleFragment(); |
7885 | |
7886 | VisibleModuleSet VisibleModules; |
7887 | |
7888 | ///@} |
7889 | |
7890 | // |
7891 | // |
7892 | // ------------------------------------------------------------------------- |
7893 | // |
7894 | // |
7895 | |
7896 | /// \name C++ Overloading |
7897 | /// Implementations are in SemaOverload.cpp |
7898 | ///@{ |
7899 | |
7900 | public: |
7901 | /// Whether deferrable diagnostics should be deferred. |
7902 | bool DeferDiags = false; |
7903 | |
7904 | /// RAII class to control scope of DeferDiags. |
7905 | class DeferDiagsRAII { |
7906 | Sema &S; |
7907 | bool SavedDeferDiags = false; |
7908 | |
7909 | public: |
7910 | DeferDiagsRAII(Sema &S, bool DeferDiags) |
7911 | : S(S), SavedDeferDiags(S.DeferDiags) { |
7912 | S.DeferDiags = DeferDiags; |
7913 | } |
7914 | ~DeferDiagsRAII() { S.DeferDiags = SavedDeferDiags; } |
7915 | }; |
7916 | |
7917 | /// Flag indicating if Sema is building a recovery call expression. |
7918 | /// |
7919 | /// This flag is used to avoid building recovery call expressions |
7920 | /// if Sema is already doing so, which would cause infinite recursions. |
7921 | bool IsBuildingRecoveryCallExpr; |
7922 | |
7923 | enum OverloadKind { |
7924 | /// This is a legitimate overload: the existing declarations are |
7925 | /// functions or function templates with different signatures. |
7926 | Ovl_Overload, |
7927 | |
7928 | /// This is not an overload because the signature exactly matches |
7929 | /// an existing declaration. |
7930 | Ovl_Match, |
7931 | |
7932 | /// This is not an overload because the lookup results contain a |
7933 | /// non-function. |
7934 | Ovl_NonFunction |
7935 | }; |
7936 | OverloadKind CheckOverload(Scope *S, FunctionDecl *New, |
7937 | const LookupResult &OldDecls, NamedDecl *&OldDecl, |
7938 | bool UseMemberUsingDeclRules); |
7939 | bool IsOverload(FunctionDecl *New, FunctionDecl *Old, |
7940 | bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs = true); |
7941 | |
7942 | // Checks whether MD constitutes an override the base class method BaseMD. |
7943 | // When checking for overrides, the object object members are ignored. |
7944 | bool IsOverride(FunctionDecl *MD, FunctionDecl *BaseMD, |
7945 | bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs = true); |
7946 | |
7947 | enum class AllowedExplicit { |
7948 | /// Allow no explicit functions to be used. |
7949 | None, |
7950 | /// Allow explicit conversion functions but not explicit constructors. |
7951 | Conversions, |
7952 | /// Allow both explicit conversion functions and explicit constructors. |
7953 | All |
7954 | }; |
7955 | |
7956 | ImplicitConversionSequence TryImplicitConversion( |
7957 | Expr *From, QualType ToType, bool SuppressUserConversions, |
7958 | AllowedExplicit AllowExplicit, bool InOverloadResolution, bool CStyle, |
7959 | bool AllowObjCWritebackConversion); |
7960 | |
7961 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
7962 | AssignmentAction Action, |
7963 | bool AllowExplicit = false); |
7964 | |
7965 | bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); |
7966 | bool IsFloatingPointPromotion(QualType FromType, QualType ToType); |
7967 | bool IsComplexPromotion(QualType FromType, QualType ToType); |
7968 | bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, |
7969 | bool InOverloadResolution, QualType &ConvertedType, |
7970 | bool &IncompatibleObjC); |
7971 | bool isObjCPointerConversion(QualType FromType, QualType ToType, |
7972 | QualType &ConvertedType, bool &IncompatibleObjC); |
7973 | bool isObjCWritebackConversion(QualType FromType, QualType ToType, |
7974 | QualType &ConvertedType); |
7975 | bool IsBlockPointerConversion(QualType FromType, QualType ToType, |
7976 | QualType &ConvertedType); |
7977 | |
7978 | bool FunctionParamTypesAreEqual(ArrayRef<QualType> Old, |
7979 | ArrayRef<QualType> New, |
7980 | unsigned *ArgPos = nullptr, |
7981 | bool Reversed = false); |
7982 | |
7983 | bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType, |
7984 | const FunctionProtoType *NewType, |
7985 | unsigned *ArgPos = nullptr, |
7986 | bool Reversed = false); |
7987 | |
7988 | bool FunctionNonObjectParamTypesAreEqual(const FunctionDecl *OldFunction, |
7989 | const FunctionDecl *NewFunction, |
7990 | unsigned *ArgPos = nullptr, |
7991 | bool Reversed = false); |
7992 | |
7993 | void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, QualType FromType, |
7994 | QualType ToType); |
7995 | |
7996 | bool CheckPointerConversion(Expr *From, QualType ToType, CastKind &Kind, |
7997 | CXXCastPath &BasePath, bool IgnoreBaseAccess, |
7998 | bool Diagnose = true); |
7999 | bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, |
8000 | bool InOverloadResolution, |
8001 | QualType &ConvertedType); |
8002 | bool CheckMemberPointerConversion(Expr *From, QualType ToType, CastKind &Kind, |
8003 | CXXCastPath &BasePath, |
8004 | bool IgnoreBaseAccess); |
8005 | bool IsQualificationConversion(QualType FromType, QualType ToType, |
8006 | bool CStyle, bool &ObjCLifetimeConversion); |
8007 | bool IsFunctionConversion(QualType FromType, QualType ToType, |
8008 | QualType &ResultTy); |
8009 | bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); |
8010 | void DiagnoseUseOfDeletedFunction(SourceLocation Loc, SourceRange Range, |
8011 | DeclarationName Name, |
8012 | OverloadCandidateSet &CandidateSet, |
8013 | FunctionDecl *Fn, MultiExprArg Args, |
8014 | bool IsMember = false); |
8015 | |
8016 | ExprResult InitializeExplicitObjectArgument(Sema &S, Expr *Obj, |
8017 | FunctionDecl *Fun); |
8018 | ExprResult PerformImplicitObjectArgumentInitialization( |
8019 | Expr *From, NestedNameSpecifier *Qualifier, NamedDecl *FoundDecl, |
8020 | CXXMethodDecl *Method); |
8021 | |
8022 | ExprResult PerformContextuallyConvertToBool(Expr *From); |
8023 | ExprResult PerformContextuallyConvertToObjCPointer(Expr *From); |
8024 | |
8025 | /// Contexts in which a converted constant expression is required. |
8026 | enum CCEKind { |
8027 | CCEK_CaseValue, ///< Expression in a case label. |
8028 | CCEK_Enumerator, ///< Enumerator value with fixed underlying type. |
8029 | CCEK_TemplateArg, ///< Value of a non-type template parameter. |
8030 | CCEK_ArrayBound, ///< Array bound in array declarator or new-expression. |
8031 | CCEK_ExplicitBool, ///< Condition in an explicit(bool) specifier. |
8032 | CCEK_Noexcept, ///< Condition in a noexcept(bool) specifier. |
8033 | CCEK_StaticAssertMessageSize, ///< Call to size() in a static assert |
8034 | ///< message. |
8035 | CCEK_StaticAssertMessageData, ///< Call to data() in a static assert |
8036 | ///< message. |
8037 | }; |
8038 | |
8039 | ExprResult BuildConvertedConstantExpression(Expr *From, QualType T, |
8040 | CCEKind CCE, |
8041 | NamedDecl *Dest = nullptr); |
8042 | |
8043 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
8044 | llvm::APSInt &Value, CCEKind CCE); |
8045 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
8046 | APValue &Value, CCEKind CCE, |
8047 | NamedDecl *Dest = nullptr); |
8048 | |
8049 | ExprResult |
8050 | EvaluateConvertedConstantExpression(Expr *E, QualType T, APValue &Value, |
8051 | CCEKind CCE, bool RequireInt, |
8052 | const APValue &PreNarrowingValue); |
8053 | |
8054 | /// Abstract base class used to perform a contextual implicit |
8055 | /// conversion from an expression to any type passing a filter. |
8056 | class ContextualImplicitConverter { |
8057 | public: |
8058 | bool Suppress; |
8059 | bool SuppressConversion; |
8060 | |
8061 | ContextualImplicitConverter(bool Suppress = false, |
8062 | bool SuppressConversion = false) |
8063 | : Suppress(Suppress), SuppressConversion(SuppressConversion) {} |
8064 | |
8065 | /// Determine whether the specified type is a valid destination type |
8066 | /// for this conversion. |
8067 | virtual bool match(QualType T) = 0; |
8068 | |
8069 | /// Emits a diagnostic complaining that the expression does not have |
8070 | /// integral or enumeration type. |
8071 | virtual SemaDiagnosticBuilder diagnoseNoMatch(Sema &S, SourceLocation Loc, |
8072 | QualType T) = 0; |
8073 | |
8074 | /// Emits a diagnostic when the expression has incomplete class type. |
8075 | virtual SemaDiagnosticBuilder |
8076 | diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0; |
8077 | |
8078 | /// Emits a diagnostic when the only matching conversion function |
8079 | /// is explicit. |
8080 | virtual SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, |
8081 | SourceLocation Loc, |
8082 | QualType T, |
8083 | QualType ConvTy) = 0; |
8084 | |
8085 | /// Emits a note for the explicit conversion function. |
8086 | virtual SemaDiagnosticBuilder |
8087 | noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
8088 | |
8089 | /// Emits a diagnostic when there are multiple possible conversion |
8090 | /// functions. |
8091 | virtual SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
8092 | QualType T) = 0; |
8093 | |
8094 | /// Emits a note for one of the candidate conversions. |
8095 | virtual SemaDiagnosticBuilder |
8096 | noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
8097 | |
8098 | /// Emits a diagnostic when we picked a conversion function |
8099 | /// (for cases when we are not allowed to pick a conversion function). |
8100 | virtual SemaDiagnosticBuilder diagnoseConversion(Sema &S, |
8101 | SourceLocation Loc, |
8102 | QualType T, |
8103 | QualType ConvTy) = 0; |
8104 | |
8105 | virtual ~ContextualImplicitConverter() {} |
8106 | }; |
8107 | |
8108 | class ICEConvertDiagnoser : public ContextualImplicitConverter { |
8109 | bool AllowScopedEnumerations; |
8110 | |
8111 | public: |
8112 | ICEConvertDiagnoser(bool AllowScopedEnumerations, bool Suppress, |
8113 | bool SuppressConversion) |
8114 | : ContextualImplicitConverter(Suppress, SuppressConversion), |
8115 | AllowScopedEnumerations(AllowScopedEnumerations) {} |
8116 | |
8117 | /// Match an integral or (possibly scoped) enumeration type. |
8118 | bool match(QualType T) override; |
8119 | |
8120 | SemaDiagnosticBuilder diagnoseNoMatch(Sema &S, SourceLocation Loc, |
8121 | QualType T) override { |
8122 | return diagnoseNotInt(S, Loc, T); |
8123 | } |
8124 | |
8125 | /// Emits a diagnostic complaining that the expression does not have |
8126 | /// integral or enumeration type. |
8127 | virtual SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
8128 | QualType T) = 0; |
8129 | }; |
8130 | |
8131 | /// Perform a contextual implicit conversion. |
8132 | ExprResult |
8133 | PerformContextualImplicitConversion(SourceLocation Loc, Expr *FromE, |
8134 | ContextualImplicitConverter &Converter); |
8135 | |
8136 | /// ReferenceCompareResult - Expresses the result of comparing two |
8137 | /// types (cv1 T1 and cv2 T2) to determine their compatibility for the |
8138 | /// purposes of initialization by reference (C++ [dcl.init.ref]p4). |
8139 | enum ReferenceCompareResult { |
8140 | /// Ref_Incompatible - The two types are incompatible, so direct |
8141 | /// reference binding is not possible. |
8142 | Ref_Incompatible = 0, |
8143 | /// Ref_Related - The two types are reference-related, which means |
8144 | /// that their unqualified forms (T1 and T2) are either the same |
8145 | /// or T1 is a base class of T2. |
8146 | Ref_Related, |
8147 | /// Ref_Compatible - The two types are reference-compatible. |
8148 | Ref_Compatible |
8149 | }; |
8150 | |
8151 | // Fake up a scoped enumeration that still contextually converts to bool. |
8152 | struct ReferenceConversionsScope { |
8153 | /// The conversions that would be performed on an lvalue of type T2 when |
8154 | /// binding a reference of type T1 to it, as determined when evaluating |
8155 | /// whether T1 is reference-compatible with T2. |
8156 | enum ReferenceConversions { |
8157 | Qualification = 0x1, |
8158 | NestedQualification = 0x2, |
8159 | Function = 0x4, |
8160 | DerivedToBase = 0x8, |
8161 | ObjC = 0x10, |
8162 | ObjCLifetime = 0x20, |
8163 | |
8164 | LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/ObjCLifetime) |
8165 | }; |
8166 | }; |
8167 | using ReferenceConversions = ReferenceConversionsScope::ReferenceConversions; |
8168 | |
8169 | ReferenceCompareResult |
8170 | CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2, |
8171 | ReferenceConversions *Conv = nullptr); |
8172 | |
8173 | void AddOverloadCandidate( |
8174 | FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef<Expr *> Args, |
8175 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
8176 | bool PartialOverloading = false, bool AllowExplicit = true, |
8177 | bool AllowExplicitConversion = false, |
8178 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
8179 | ConversionSequenceList EarlyConversions = std::nullopt, |
8180 | OverloadCandidateParamOrder PO = {}, |
8181 | bool AggregateCandidateDeduction = false); |
8182 | void AddFunctionCandidates( |
8183 | const UnresolvedSetImpl &Functions, ArrayRef<Expr *> Args, |
8184 | OverloadCandidateSet &CandidateSet, |
8185 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
8186 | bool SuppressUserConversions = false, bool PartialOverloading = false, |
8187 | bool FirstArgumentIsBase = false); |
8188 | void AddMethodCandidate(DeclAccessPair FoundDecl, QualType ObjectType, |
8189 | Expr::Classification ObjectClassification, |
8190 | ArrayRef<Expr *> Args, |
8191 | OverloadCandidateSet &CandidateSet, |
8192 | bool SuppressUserConversion = false, |
8193 | OverloadCandidateParamOrder PO = {}); |
8194 | void |
8195 | AddMethodCandidate(CXXMethodDecl *Method, DeclAccessPair FoundDecl, |
8196 | CXXRecordDecl *ActingContext, QualType ObjectType, |
8197 | Expr::Classification ObjectClassification, |
8198 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, |
8199 | bool SuppressUserConversions = false, |
8200 | bool PartialOverloading = false, |
8201 | ConversionSequenceList EarlyConversions = std::nullopt, |
8202 | OverloadCandidateParamOrder PO = {}); |
8203 | void AddMethodTemplateCandidate( |
8204 | FunctionTemplateDecl *MethodTmpl, DeclAccessPair FoundDecl, |
8205 | CXXRecordDecl *ActingContext, |
8206 | TemplateArgumentListInfo *ExplicitTemplateArgs, QualType ObjectType, |
8207 | Expr::Classification ObjectClassification, ArrayRef<Expr *> Args, |
8208 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
8209 | bool PartialOverloading = false, OverloadCandidateParamOrder PO = {}); |
8210 | void AddTemplateOverloadCandidate( |
8211 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
8212 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
8213 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
8214 | bool PartialOverloading = false, bool AllowExplicit = true, |
8215 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
8216 | OverloadCandidateParamOrder PO = {}, |
8217 | bool AggregateCandidateDeduction = false); |
8218 | bool CheckNonDependentConversions( |
8219 | FunctionTemplateDecl *FunctionTemplate, ArrayRef<QualType> ParamTypes, |
8220 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, |
8221 | ConversionSequenceList &Conversions, bool SuppressUserConversions, |
8222 | CXXRecordDecl *ActingContext = nullptr, QualType ObjectType = QualType(), |
8223 | Expr::Classification ObjectClassification = {}, |
8224 | OverloadCandidateParamOrder PO = {}); |
8225 | void AddConversionCandidate( |
8226 | CXXConversionDecl *Conversion, DeclAccessPair FoundDecl, |
8227 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
8228 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
8229 | bool AllowExplicit, bool AllowResultConversion = true); |
8230 | void AddTemplateConversionCandidate( |
8231 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
8232 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
8233 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
8234 | bool AllowExplicit, bool AllowResultConversion = true); |
8235 | void AddSurrogateCandidate(CXXConversionDecl *Conversion, |
8236 | DeclAccessPair FoundDecl, |
8237 | CXXRecordDecl *ActingContext, |
8238 | const FunctionProtoType *Proto, Expr *Object, |
8239 | ArrayRef<Expr *> Args, |
8240 | OverloadCandidateSet &CandidateSet); |
8241 | void AddNonMemberOperatorCandidates( |
8242 | const UnresolvedSetImpl &Functions, ArrayRef<Expr *> Args, |
8243 | OverloadCandidateSet &CandidateSet, |
8244 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
8245 | void AddMemberOperatorCandidates(OverloadedOperatorKind Op, |
8246 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
8247 | OverloadCandidateSet &CandidateSet, |
8248 | OverloadCandidateParamOrder PO = {}); |
8249 | void AddBuiltinCandidate(QualType *ParamTys, ArrayRef<Expr *> Args, |
8250 | OverloadCandidateSet &CandidateSet, |
8251 | bool IsAssignmentOperator = false, |
8252 | unsigned NumContextualBoolArguments = 0); |
8253 | void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, |
8254 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
8255 | OverloadCandidateSet &CandidateSet); |
8256 | void AddArgumentDependentLookupCandidates( |
8257 | DeclarationName Name, SourceLocation Loc, ArrayRef<Expr *> Args, |
8258 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
8259 | OverloadCandidateSet &CandidateSet, bool PartialOverloading = false); |
8260 | |
8261 | /// Check the enable_if expressions on the given function. Returns the first |
8262 | /// failing attribute, or NULL if they were all successful. |
8263 | EnableIfAttr *CheckEnableIf(FunctionDecl *Function, SourceLocation CallLoc, |
8264 | ArrayRef<Expr *> Args, |
8265 | bool MissingImplicitThis = false); |
8266 | |
8267 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
8268 | /// non-ArgDependent DiagnoseIfAttrs. |
8269 | /// |
8270 | /// Argument-dependent diagnose_if attributes should be checked each time a |
8271 | /// function is used as a direct callee of a function call. |
8272 | /// |
8273 | /// Returns true if any errors were emitted. |
8274 | bool diagnoseArgDependentDiagnoseIfAttrs(const FunctionDecl *Function, |
8275 | const Expr *ThisArg, |
8276 | ArrayRef<const Expr *> Args, |
8277 | SourceLocation Loc); |
8278 | |
8279 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
8280 | /// ArgDependent DiagnoseIfAttrs. |
8281 | /// |
8282 | /// Argument-independent diagnose_if attributes should be checked on every use |
8283 | /// of a function. |
8284 | /// |
8285 | /// Returns true if any errors were emitted. |
8286 | bool diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND, |
8287 | SourceLocation Loc); |
8288 | |
8289 | /// Determine if \p A and \p B are equivalent internal linkage declarations |
8290 | /// from different modules, and thus an ambiguity error can be downgraded to |
8291 | /// an extension warning. |
8292 | bool isEquivalentInternalLinkageDeclaration(const NamedDecl *A, |
8293 | const NamedDecl *B); |
8294 | void diagnoseEquivalentInternalLinkageDeclarations( |
8295 | SourceLocation Loc, const NamedDecl *D, |
8296 | ArrayRef<const NamedDecl *> Equiv); |
8297 | |
8298 | // Emit as a 'note' the specific overload candidate |
8299 | void NoteOverloadCandidate( |
8300 | const NamedDecl *Found, const FunctionDecl *Fn, |
8301 | OverloadCandidateRewriteKind RewriteKind = OverloadCandidateRewriteKind(), |
8302 | QualType DestType = QualType(), bool TakingAddress = false); |
8303 | |
8304 | // Emit as a series of 'note's all template and non-templates identified by |
8305 | // the expression Expr |
8306 | void NoteAllOverloadCandidates(Expr *E, QualType DestType = QualType(), |
8307 | bool TakingAddress = false); |
8308 | |
8309 | /// Returns whether the given function's address can be taken or not, |
8310 | /// optionally emitting a diagnostic if the address can't be taken. |
8311 | /// |
8312 | /// Returns false if taking the address of the function is illegal. |
8313 | bool checkAddressOfFunctionIsAvailable(const FunctionDecl *Function, |
8314 | bool Complain = false, |
8315 | SourceLocation Loc = SourceLocation()); |
8316 | |
8317 | // [PossiblyAFunctionType] --> [Return] |
8318 | // NonFunctionType --> NonFunctionType |
8319 | // R (A) --> R(A) |
8320 | // R (*)(A) --> R (A) |
8321 | // R (&)(A) --> R (A) |
8322 | // R (S::*)(A) --> R (A) |
8323 | QualType (QualType PossiblyAFunctionType); |
8324 | |
8325 | FunctionDecl * |
8326 | ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, QualType TargetType, |
8327 | bool Complain, DeclAccessPair &Found, |
8328 | bool *pHadMultipleCandidates = nullptr); |
8329 | |
8330 | FunctionDecl * |
8331 | resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &FoundResult); |
8332 | |
8333 | bool resolveAndFixAddressOfSingleOverloadCandidate( |
8334 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false); |
8335 | |
8336 | FunctionDecl *ResolveSingleFunctionTemplateSpecialization( |
8337 | OverloadExpr *ovl, bool Complain = false, DeclAccessPair *Found = nullptr, |
8338 | TemplateSpecCandidateSet *FailedTSC = nullptr); |
8339 | |
8340 | bool ResolveAndFixSingleFunctionTemplateSpecialization( |
8341 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false, |
8342 | bool Complain = false, SourceRange OpRangeForComplaining = SourceRange(), |
8343 | QualType DestTypeForComplaining = QualType(), |
8344 | unsigned DiagIDForComplaining = 0); |
8345 | |
8346 | void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, |
8347 | ArrayRef<Expr *> Args, |
8348 | OverloadCandidateSet &CandidateSet, |
8349 | bool PartialOverloading = false); |
8350 | void AddOverloadedCallCandidates( |
8351 | LookupResult &R, TemplateArgumentListInfo *ExplicitTemplateArgs, |
8352 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet); |
8353 | |
8354 | // An enum used to represent the different possible results of building a |
8355 | // range-based for loop. |
8356 | enum ForRangeStatus { |
8357 | FRS_Success, |
8358 | FRS_NoViableFunction, |
8359 | FRS_DiagnosticIssued |
8360 | }; |
8361 | |
8362 | ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc, |
8363 | SourceLocation RangeLoc, |
8364 | const DeclarationNameInfo &NameInfo, |
8365 | LookupResult &MemberLookup, |
8366 | OverloadCandidateSet *CandidateSet, |
8367 | Expr *Range, ExprResult *CallExpr); |
8368 | |
8369 | ExprResult BuildOverloadedCallExpr( |
8370 | Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, SourceLocation LParenLoc, |
8371 | MultiExprArg Args, SourceLocation RParenLoc, Expr *ExecConfig, |
8372 | bool AllowTypoCorrection = true, bool CalleesAddressIsTaken = false); |
8373 | |
8374 | bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, |
8375 | MultiExprArg Args, SourceLocation RParenLoc, |
8376 | OverloadCandidateSet *CandidateSet, |
8377 | ExprResult *Result); |
8378 | |
8379 | ExprResult CreateUnresolvedLookupExpr(CXXRecordDecl *NamingClass, |
8380 | NestedNameSpecifierLoc NNSLoc, |
8381 | DeclarationNameInfo DNI, |
8382 | const UnresolvedSetImpl &Fns, |
8383 | bool PerformADL = true); |
8384 | |
8385 | ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, |
8386 | UnaryOperatorKind Opc, |
8387 | const UnresolvedSetImpl &Fns, Expr *input, |
8388 | bool RequiresADL = true); |
8389 | |
8390 | void LookupOverloadedBinOp(OverloadCandidateSet &CandidateSet, |
8391 | OverloadedOperatorKind Op, |
8392 | const UnresolvedSetImpl &Fns, |
8393 | ArrayRef<Expr *> Args, bool RequiresADL = true); |
8394 | ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, |
8395 | const UnresolvedSetImpl &Fns, Expr *LHS, |
8396 | Expr *RHS, bool RequiresADL = true, |
8397 | bool AllowRewrittenCandidates = true, |
8398 | FunctionDecl *DefaultedFn = nullptr); |
8399 | ExprResult BuildSynthesizedThreeWayComparison(SourceLocation OpLoc, |
8400 | const UnresolvedSetImpl &Fns, |
8401 | Expr *LHS, Expr *RHS, |
8402 | FunctionDecl *DefaultedFn); |
8403 | |
8404 | ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, |
8405 | SourceLocation RLoc, Expr *Base, |
8406 | MultiExprArg Args); |
8407 | |
8408 | ExprResult BuildCallToMemberFunction( |
8409 | Scope *S, Expr *MemExpr, SourceLocation LParenLoc, MultiExprArg Args, |
8410 | SourceLocation RParenLoc, Expr *ExecConfig = nullptr, |
8411 | bool IsExecConfig = false, bool AllowRecovery = false); |
8412 | ExprResult BuildCallToObjectOfClassType(Scope *S, Expr *Object, |
8413 | SourceLocation LParenLoc, |
8414 | MultiExprArg Args, |
8415 | SourceLocation RParenLoc); |
8416 | |
8417 | ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, |
8418 | SourceLocation OpLoc, |
8419 | bool *NoArrowOperatorFound = nullptr); |
8420 | |
8421 | ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, |
8422 | CXXConversionDecl *Method, |
8423 | bool HadMultipleCandidates); |
8424 | |
8425 | ExprResult BuildLiteralOperatorCall( |
8426 | LookupResult &R, DeclarationNameInfo &SuffixInfo, ArrayRef<Expr *> Args, |
8427 | SourceLocation LitEndLoc, |
8428 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
8429 | |
8430 | ExprResult FixOverloadedFunctionReference(Expr *E, DeclAccessPair FoundDecl, |
8431 | FunctionDecl *Fn); |
8432 | ExprResult FixOverloadedFunctionReference(ExprResult, |
8433 | DeclAccessPair FoundDecl, |
8434 | FunctionDecl *Fn); |
8435 | |
8436 | private: |
8437 | /// - Returns a selector which best matches given argument list or |
8438 | /// nullptr if none could be found |
8439 | ObjCMethodDecl *SelectBestMethod(Selector Sel, MultiExprArg Args, |
8440 | bool IsInstance, |
8441 | SmallVectorImpl<ObjCMethodDecl *> &Methods); |
8442 | |
8443 | ///@} |
8444 | |
8445 | // |
8446 | // |
8447 | // ------------------------------------------------------------------------- |
8448 | // |
8449 | // |
8450 | |
8451 | /// \name Pseudo-Object |
8452 | /// Implementations are in SemaPseudoObject.cpp |
8453 | ///@{ |
8454 | |
8455 | public: |
8456 | void maybeExtendBlockObject(ExprResult &E); |
8457 | CastKind PrepareCastToObjCObjectPointer(ExprResult &E); |
8458 | |
8459 | enum ObjCSubscriptKind { OS_Array, OS_Dictionary, OS_Error }; |
8460 | ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE); |
8461 | |
8462 | ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc, |
8463 | UnaryOperatorKind Opcode, Expr *Op); |
8464 | ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc, |
8465 | BinaryOperatorKind Opcode, Expr *LHS, |
8466 | Expr *RHS); |
8467 | ExprResult checkPseudoObjectRValue(Expr *E); |
8468 | Expr *recreateSyntacticForm(PseudoObjectExpr *E); |
8469 | |
8470 | ///@} |
8471 | |
8472 | // |
8473 | // |
8474 | // ------------------------------------------------------------------------- |
8475 | // |
8476 | // |
8477 | |
8478 | /// \name Statements |
8479 | /// Implementations are in SemaStmt.cpp |
8480 | ///@{ |
8481 | |
8482 | public: |
8483 | /// Stack of active SEH __finally scopes. Can be empty. |
8484 | SmallVector<Scope *, 2> CurrentSEHFinally; |
8485 | |
8486 | StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue = true); |
8487 | StmtResult ActOnExprStmtError(); |
8488 | |
8489 | StmtResult ActOnNullStmt(SourceLocation SemiLoc, |
8490 | bool HasLeadingEmptyMacro = false); |
8491 | |
8492 | StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, |
8493 | SourceLocation EndLoc); |
8494 | void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); |
8495 | |
8496 | /// DiagnoseUnusedExprResult - If the statement passed in is an expression |
8497 | /// whose result is unused, warn. |
8498 | void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID); |
8499 | |
8500 | void ActOnStartOfCompoundStmt(bool IsStmtExpr); |
8501 | void ActOnAfterCompoundStatementLeadingPragmas(); |
8502 | void ActOnFinishOfCompoundStmt(); |
8503 | StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
8504 | ArrayRef<Stmt *> Elts, bool isStmtExpr); |
8505 | |
8506 | sema::CompoundScopeInfo &getCurCompoundScope() const; |
8507 | |
8508 | ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val); |
8509 | StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, |
8510 | SourceLocation DotDotDotLoc, ExprResult RHS, |
8511 | SourceLocation ColonLoc); |
8512 | void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); |
8513 | |
8514 | StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, |
8515 | SourceLocation ColonLoc, Stmt *SubStmt, |
8516 | Scope *CurScope); |
8517 | StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, |
8518 | SourceLocation ColonLoc, Stmt *SubStmt); |
8519 | |
8520 | StmtResult BuildAttributedStmt(SourceLocation AttrsLoc, |
8521 | ArrayRef<const Attr *> Attrs, Stmt *SubStmt); |
8522 | StmtResult ActOnAttributedStmt(const ParsedAttributes &AttrList, |
8523 | Stmt *SubStmt); |
8524 | |
8525 | /// Check whether the given statement can have musttail applied to it, |
8526 | /// issuing a diagnostic and returning false if not. In the success case, |
8527 | /// the statement is rewritten to remove implicit nodes from the return |
8528 | /// value. |
8529 | bool checkAndRewriteMustTailAttr(Stmt *St, const Attr &MTA); |
8530 | |
8531 | StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, |
8532 | SourceLocation LParenLoc, Stmt *InitStmt, |
8533 | ConditionResult Cond, SourceLocation RParenLoc, |
8534 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
8535 | StmtResult BuildIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, |
8536 | SourceLocation LParenLoc, Stmt *InitStmt, |
8537 | ConditionResult Cond, SourceLocation RParenLoc, |
8538 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
8539 | |
8540 | ExprResult CheckSwitchCondition(SourceLocation SwitchLoc, Expr *Cond); |
8541 | |
8542 | StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, |
8543 | SourceLocation LParenLoc, Stmt *InitStmt, |
8544 | ConditionResult Cond, |
8545 | SourceLocation RParenLoc); |
8546 | StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, |
8547 | Stmt *Body); |
8548 | |
8549 | /// DiagnoseAssignmentEnum - Warn if assignment to enum is a constant |
8550 | /// integer not in the range of enum values. |
8551 | void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, |
8552 | Expr *SrcExpr); |
8553 | |
8554 | StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, |
8555 | ConditionResult Cond, SourceLocation RParenLoc, |
8556 | Stmt *Body); |
8557 | StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, |
8558 | SourceLocation WhileLoc, SourceLocation CondLParen, |
8559 | Expr *Cond, SourceLocation CondRParen); |
8560 | |
8561 | StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
8562 | Stmt *First, ConditionResult Second, |
8563 | FullExprArg Third, SourceLocation RParenLoc, |
8564 | Stmt *Body); |
8565 | |
8566 | StmtResult ActOnForEachLValueExpr(Expr *E); |
8567 | |
8568 | ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, |
8569 | Expr *collection); |
8570 | StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, Stmt *First, |
8571 | Expr *collection, |
8572 | SourceLocation RParenLoc); |
8573 | StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body); |
8574 | |
8575 | enum BuildForRangeKind { |
8576 | /// Initial building of a for-range statement. |
8577 | BFRK_Build, |
8578 | /// Instantiation or recovery rebuild of a for-range statement. Don't |
8579 | /// attempt any typo-correction. |
8580 | BFRK_Rebuild, |
8581 | /// Determining whether a for-range statement could be built. Avoid any |
8582 | /// unnecessary or irreversible actions. |
8583 | BFRK_Check |
8584 | }; |
8585 | |
8586 | StmtResult ActOnCXXForRangeStmt( |
8587 | Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc, |
8588 | Stmt *InitStmt, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection, |
8589 | SourceLocation RParenLoc, BuildForRangeKind Kind, |
8590 | ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps = {}); |
8591 | StmtResult BuildCXXForRangeStmt( |
8592 | SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, |
8593 | SourceLocation ColonLoc, Stmt *RangeDecl, Stmt *Begin, Stmt *End, |
8594 | Expr *Cond, Expr *Inc, Stmt *LoopVarDecl, SourceLocation RParenLoc, |
8595 | BuildForRangeKind Kind, |
8596 | ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps = {}); |
8597 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body); |
8598 | |
8599 | StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
8600 | LabelDecl *TheDecl); |
8601 | StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, |
8602 | SourceLocation StarLoc, Expr *DestExp); |
8603 | StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope); |
8604 | StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope); |
8605 | |
8606 | struct NamedReturnInfo { |
8607 | const VarDecl *Candidate; |
8608 | |
8609 | enum Status : uint8_t { None, MoveEligible, MoveEligibleAndCopyElidable }; |
8610 | Status S; |
8611 | |
8612 | bool isMoveEligible() const { return S != None; }; |
8613 | bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; } |
8614 | }; |
8615 | enum class SimplerImplicitMoveMode { ForceOff, Normal, ForceOn }; |
8616 | NamedReturnInfo getNamedReturnInfo( |
8617 | Expr *&E, SimplerImplicitMoveMode Mode = SimplerImplicitMoveMode::Normal); |
8618 | NamedReturnInfo getNamedReturnInfo(const VarDecl *VD); |
8619 | const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info, |
8620 | QualType ReturnType); |
8621 | |
8622 | ExprResult |
8623 | PerformMoveOrCopyInitialization(const InitializedEntity &Entity, |
8624 | const NamedReturnInfo &NRInfo, Expr *Value, |
8625 | bool SupressSimplerImplicitMoves = false); |
8626 | |
8627 | TypeLoc getReturnTypeLoc(FunctionDecl *FD) const; |
8628 | |
8629 | bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD, |
8630 | SourceLocation ReturnLoc, Expr *RetExpr, |
8631 | const AutoType *AT); |
8632 | |
8633 | StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
8634 | Scope *CurScope); |
8635 | StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
8636 | bool AllowRecovery = false); |
8637 | StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
8638 | NamedReturnInfo &NRInfo, |
8639 | bool SupressSimplerImplicitMoves); |
8640 | |
8641 | StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, |
8642 | Decl *Parm, Stmt *Body); |
8643 | |
8644 | StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); |
8645 | |
8646 | StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, |
8647 | MultiStmtArg Catch, Stmt *Finally); |
8648 | |
8649 | StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); |
8650 | StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, |
8651 | Scope *CurScope); |
8652 | ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, |
8653 | Expr *operand); |
8654 | StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SynchExpr, |
8655 | Stmt *SynchBody); |
8656 | |
8657 | StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body); |
8658 | |
8659 | StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, Decl *ExDecl, |
8660 | Stmt *HandlerBlock); |
8661 | StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, |
8662 | ArrayRef<Stmt *> Handlers); |
8663 | |
8664 | StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ? |
8665 | SourceLocation TryLoc, Stmt *TryBlock, |
8666 | Stmt *Handler); |
8667 | StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, |
8668 | Stmt *Block); |
8669 | void ActOnStartSEHFinallyBlock(); |
8670 | void ActOnAbortSEHFinallyBlock(); |
8671 | StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block); |
8672 | StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope); |
8673 | |
8674 | StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
8675 | bool IsIfExists, |
8676 | NestedNameSpecifierLoc QualifierLoc, |
8677 | DeclarationNameInfo NameInfo, |
8678 | Stmt *Nested); |
8679 | StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, |
8680 | bool IsIfExists, CXXScopeSpec &SS, |
8681 | UnqualifiedId &Name, Stmt *Nested); |
8682 | |
8683 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
8684 | CapturedRegionKind Kind, unsigned NumParams); |
8685 | typedef std::pair<StringRef, QualType> CapturedParamNameType; |
8686 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
8687 | CapturedRegionKind Kind, |
8688 | ArrayRef<CapturedParamNameType> Params, |
8689 | unsigned OpenMPCaptureLevel = 0); |
8690 | StmtResult ActOnCapturedRegionEnd(Stmt *S); |
8691 | void ActOnCapturedRegionError(); |
8692 | RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD, |
8693 | SourceLocation Loc, |
8694 | unsigned NumParams); |
8695 | |
8696 | private: |
8697 | /// Check whether the given statement can have musttail applied to it, |
8698 | /// issuing a diagnostic and returning false if not. |
8699 | bool checkMustTailAttr(const Stmt *St, const Attr &MTA); |
8700 | |
8701 | /// Check if the given expression contains 'break' or 'continue' |
8702 | /// statement that produces control flow different from GCC. |
8703 | void CheckBreakContinueBinding(Expr *E); |
8704 | |
8705 | ///@} |
8706 | |
8707 | // |
8708 | // |
8709 | // ------------------------------------------------------------------------- |
8710 | // |
8711 | // |
8712 | |
8713 | /// \name `inline asm` Statement |
8714 | /// Implementations are in SemaStmtAsm.cpp |
8715 | ///@{ |
8716 | |
8717 | public: |
8718 | StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
8719 | bool IsVolatile, unsigned NumOutputs, |
8720 | unsigned NumInputs, IdentifierInfo **Names, |
8721 | MultiExprArg Constraints, MultiExprArg Exprs, |
8722 | Expr *AsmString, MultiExprArg Clobbers, |
8723 | unsigned NumLabels, SourceLocation RParenLoc); |
8724 | |
8725 | void FillInlineAsmIdentifierInfo(Expr *Res, |
8726 | llvm::InlineAsmIdentifierInfo &Info); |
8727 | ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS, |
8728 | SourceLocation TemplateKWLoc, |
8729 | UnqualifiedId &Id, |
8730 | bool IsUnevaluatedContext); |
8731 | bool LookupInlineAsmField(StringRef Base, StringRef Member, unsigned &Offset, |
8732 | SourceLocation AsmLoc); |
8733 | ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member, |
8734 | SourceLocation AsmLoc); |
8735 | StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
8736 | ArrayRef<Token> AsmToks, StringRef AsmString, |
8737 | unsigned NumOutputs, unsigned NumInputs, |
8738 | ArrayRef<StringRef> Constraints, |
8739 | ArrayRef<StringRef> Clobbers, |
8740 | ArrayRef<Expr *> Exprs, SourceLocation EndLoc); |
8741 | LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName, |
8742 | SourceLocation Location, bool AlwaysCreate); |
8743 | |
8744 | ///@} |
8745 | |
8746 | // |
8747 | // |
8748 | // ------------------------------------------------------------------------- |
8749 | // |
8750 | // |
8751 | |
8752 | /// \name Statement Attribute Handling |
8753 | /// Implementations are in SemaStmtAttr.cpp |
8754 | ///@{ |
8755 | |
8756 | public: |
8757 | bool CheckNoInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, |
8758 | const AttributeCommonInfo &A); |
8759 | bool CheckAlwaysInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, |
8760 | const AttributeCommonInfo &A); |
8761 | |
8762 | CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E); |
8763 | bool CheckRebuiltStmtAttributes(ArrayRef<const Attr *> Attrs); |
8764 | |
8765 | /// Process the attributes before creating an attributed statement. Returns |
8766 | /// the semantic attributes that have been processed. |
8767 | void ProcessStmtAttributes(Stmt *Stmt, const ParsedAttributes &InAttrs, |
8768 | SmallVectorImpl<const Attr *> &OutAttrs); |
8769 | |
8770 | ExprResult ActOnCXXAssumeAttr(Stmt *St, const ParsedAttr &A, |
8771 | SourceRange Range); |
8772 | ExprResult BuildCXXAssumeExpr(Expr *Assumption, |
8773 | const IdentifierInfo *AttrName, |
8774 | SourceRange Range); |
8775 | |
8776 | ///@} |
8777 | |
8778 | // |
8779 | // |
8780 | // ------------------------------------------------------------------------- |
8781 | // |
8782 | // |
8783 | |
8784 | /// \name C++ Templates |
8785 | /// Implementations are in SemaTemplate.cpp |
8786 | ///@{ |
8787 | |
8788 | public: |
8789 | // Saves the current floating-point pragma stack and clear it in this Sema. |
8790 | class FpPragmaStackSaveRAII { |
8791 | public: |
8792 | FpPragmaStackSaveRAII(Sema &S) |
8793 | : S(S), SavedStack(std::move(S.FpPragmaStack)) { |
8794 | S.FpPragmaStack.Stack.clear(); |
8795 | } |
8796 | ~FpPragmaStackSaveRAII() { S.FpPragmaStack = std::move(SavedStack); } |
8797 | |
8798 | private: |
8799 | Sema &S; |
8800 | PragmaStack<FPOptionsOverride> SavedStack; |
8801 | }; |
8802 | |
8803 | void resetFPOptions(FPOptions FPO) { |
8804 | CurFPFeatures = FPO; |
8805 | FpPragmaStack.CurrentValue = FPO.getChangesFrom(Base: FPOptions(LangOpts)); |
8806 | } |
8807 | |
8808 | ArrayRef<InventedTemplateParameterInfo> getInventedParameterInfos() const { |
8809 | return llvm::ArrayRef(InventedParameterInfos.begin() + |
8810 | InventedParameterInfosStart, |
8811 | InventedParameterInfos.end()); |
8812 | } |
8813 | |
8814 | /// The number of SFINAE diagnostics that have been trapped. |
8815 | unsigned NumSFINAEErrors; |
8816 | |
8817 | ArrayRef<sema::FunctionScopeInfo *> getFunctionScopes() const { |
8818 | return llvm::ArrayRef(FunctionScopes.begin() + FunctionScopesStart, |
8819 | FunctionScopes.end()); |
8820 | } |
8821 | |
8822 | typedef llvm::MapVector<const FunctionDecl *, |
8823 | std::unique_ptr<LateParsedTemplate>> |
8824 | LateParsedTemplateMapT; |
8825 | LateParsedTemplateMapT LateParsedTemplateMap; |
8826 | |
8827 | /// Determine the number of levels of enclosing template parameters. This is |
8828 | /// only usable while parsing. Note that this does not include dependent |
8829 | /// contexts in which no template parameters have yet been declared, such as |
8830 | /// in a terse function template or generic lambda before the first 'auto' is |
8831 | /// encountered. |
8832 | unsigned getTemplateDepth(Scope *S) const; |
8833 | |
8834 | void FilterAcceptableTemplateNames(LookupResult &R, |
8835 | bool AllowFunctionTemplates = true, |
8836 | bool AllowDependent = true); |
8837 | bool hasAnyAcceptableTemplateNames(LookupResult &R, |
8838 | bool AllowFunctionTemplates = true, |
8839 | bool AllowDependent = true, |
8840 | bool AllowNonTemplateFunctions = false); |
8841 | /// Try to interpret the lookup result D as a template-name. |
8842 | /// |
8843 | /// \param D A declaration found by name lookup. |
8844 | /// \param AllowFunctionTemplates Whether function templates should be |
8845 | /// considered valid results. |
8846 | /// \param AllowDependent Whether unresolved using declarations (that might |
8847 | /// name templates) should be considered valid results. |
8848 | static NamedDecl *getAsTemplateNameDecl(NamedDecl *D, |
8849 | bool AllowFunctionTemplates = true, |
8850 | bool AllowDependent = true); |
8851 | |
8852 | enum TemplateNameIsRequiredTag { TemplateNameIsRequired }; |
8853 | /// Whether and why a template name is required in this lookup. |
8854 | class RequiredTemplateKind { |
8855 | public: |
8856 | /// Template name is required if TemplateKWLoc is valid. |
8857 | RequiredTemplateKind(SourceLocation TemplateKWLoc = SourceLocation()) |
8858 | : TemplateKW(TemplateKWLoc) {} |
8859 | /// Template name is unconditionally required. |
8860 | RequiredTemplateKind(TemplateNameIsRequiredTag) {} |
8861 | |
8862 | SourceLocation getTemplateKeywordLoc() const { |
8863 | return TemplateKW.value_or(u: SourceLocation()); |
8864 | } |
8865 | bool hasTemplateKeyword() const { |
8866 | return getTemplateKeywordLoc().isValid(); |
8867 | } |
8868 | bool isRequired() const { return TemplateKW != SourceLocation(); } |
8869 | explicit operator bool() const { return isRequired(); } |
8870 | |
8871 | private: |
8872 | std::optional<SourceLocation> TemplateKW; |
8873 | }; |
8874 | |
8875 | enum class AssumedTemplateKind { |
8876 | /// This is not assumed to be a template name. |
8877 | None, |
8878 | /// This is assumed to be a template name because lookup found nothing. |
8879 | FoundNothing, |
8880 | /// This is assumed to be a template name because lookup found one or more |
8881 | /// functions (but no function templates). |
8882 | FoundFunctions, |
8883 | }; |
8884 | bool LookupTemplateName( |
8885 | LookupResult &R, Scope *S, CXXScopeSpec &SS, QualType ObjectType, |
8886 | bool EnteringContext, bool &MemberOfUnknownSpecialization, |
8887 | RequiredTemplateKind RequiredTemplate = SourceLocation(), |
8888 | AssumedTemplateKind *ATK = nullptr, bool AllowTypoCorrection = true); |
8889 | |
8890 | TemplateNameKind isTemplateName(Scope *S, CXXScopeSpec &SS, |
8891 | bool hasTemplateKeyword, |
8892 | const UnqualifiedId &Name, |
8893 | ParsedType ObjectType, bool EnteringContext, |
8894 | TemplateTy &Template, |
8895 | bool &MemberOfUnknownSpecialization, |
8896 | bool Disambiguation = false); |
8897 | |
8898 | /// Try to resolve an undeclared template name as a type template. |
8899 | /// |
8900 | /// Sets II to the identifier corresponding to the template name, and updates |
8901 | /// Name to a corresponding (typo-corrected) type template name and TNK to |
8902 | /// the corresponding kind, if possible. |
8903 | void ActOnUndeclaredTypeTemplateName(Scope *S, TemplateTy &Name, |
8904 | TemplateNameKind &TNK, |
8905 | SourceLocation NameLoc, |
8906 | IdentifierInfo *&II); |
8907 | |
8908 | bool resolveAssumedTemplateNameAsType(Scope *S, TemplateName &Name, |
8909 | SourceLocation NameLoc, |
8910 | bool Diagnose = true); |
8911 | |
8912 | /// Determine whether a particular identifier might be the name in a C++1z |
8913 | /// deduction-guide declaration. |
8914 | bool isDeductionGuideName(Scope *S, const IdentifierInfo &Name, |
8915 | SourceLocation NameLoc, CXXScopeSpec &SS, |
8916 | ParsedTemplateTy *Template = nullptr); |
8917 | |
8918 | bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, |
8919 | SourceLocation IILoc, Scope *S, |
8920 | const CXXScopeSpec *SS, |
8921 | TemplateTy &SuggestedTemplate, |
8922 | TemplateNameKind &SuggestedKind); |
8923 | |
8924 | bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation, |
8925 | NamedDecl *Instantiation, |
8926 | bool InstantiatedFromMember, |
8927 | const NamedDecl *Pattern, |
8928 | const NamedDecl *PatternDef, |
8929 | TemplateSpecializationKind TSK, |
8930 | bool Complain = true); |
8931 | |
8932 | /// DiagnoseTemplateParameterShadow - Produce a diagnostic complaining |
8933 | /// that the template parameter 'PrevDecl' is being shadowed by a new |
8934 | /// declaration at location Loc. Returns true to indicate that this is |
8935 | /// an error, and false otherwise. |
8936 | /// |
8937 | /// \param Loc The location of the declaration that shadows a template |
8938 | /// parameter. |
8939 | /// |
8940 | /// \param PrevDecl The template parameter that the declaration shadows. |
8941 | /// |
8942 | /// \param SupportedForCompatibility Whether to issue the diagnostic as |
8943 | /// a warning for compatibility with older versions of clang. |
8944 | /// Ignored when MSVC compatibility is enabled. |
8945 | void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl, |
8946 | bool SupportedForCompatibility = false); |
8947 | TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); |
8948 | |
8949 | NamedDecl *ActOnTypeParameter(Scope *S, bool Typename, |
8950 | SourceLocation EllipsisLoc, |
8951 | SourceLocation KeyLoc, |
8952 | IdentifierInfo *ParamName, |
8953 | SourceLocation ParamNameLoc, unsigned Depth, |
8954 | unsigned Position, SourceLocation EqualLoc, |
8955 | ParsedType DefaultArg, bool HasTypeConstraint); |
8956 | |
8957 | bool CheckTypeConstraint(TemplateIdAnnotation *TypeConstraint); |
8958 | |
8959 | bool ActOnTypeConstraint(const CXXScopeSpec &SS, |
8960 | TemplateIdAnnotation *TypeConstraint, |
8961 | TemplateTypeParmDecl *ConstrainedParameter, |
8962 | SourceLocation EllipsisLoc); |
8963 | bool BuildTypeConstraint(const CXXScopeSpec &SS, |
8964 | TemplateIdAnnotation *TypeConstraint, |
8965 | TemplateTypeParmDecl *ConstrainedParameter, |
8966 | SourceLocation EllipsisLoc, |
8967 | bool AllowUnexpandedPack); |
8968 | |
8969 | bool AttachTypeConstraint(NestedNameSpecifierLoc NS, |
8970 | DeclarationNameInfo NameInfo, |
8971 | ConceptDecl *NamedConcept, NamedDecl *FoundDecl, |
8972 | const TemplateArgumentListInfo *TemplateArgs, |
8973 | TemplateTypeParmDecl *ConstrainedParameter, |
8974 | SourceLocation EllipsisLoc); |
8975 | |
8976 | bool AttachTypeConstraint(AutoTypeLoc TL, |
8977 | NonTypeTemplateParmDecl *NewConstrainedParm, |
8978 | NonTypeTemplateParmDecl *OrigConstrainedParm, |
8979 | SourceLocation EllipsisLoc); |
8980 | |
8981 | bool RequireStructuralType(QualType T, SourceLocation Loc); |
8982 | |
8983 | QualType CheckNonTypeTemplateParameterType(TypeSourceInfo *&TSI, |
8984 | SourceLocation Loc); |
8985 | QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); |
8986 | |
8987 | NamedDecl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, |
8988 | unsigned Depth, unsigned Position, |
8989 | SourceLocation EqualLoc, |
8990 | Expr *DefaultArg); |
8991 | NamedDecl *ActOnTemplateTemplateParameter( |
8992 | Scope *S, SourceLocation TmpLoc, TemplateParameterList *Params, |
8993 | bool Typename, SourceLocation EllipsisLoc, IdentifierInfo *ParamName, |
8994 | SourceLocation ParamNameLoc, unsigned Depth, unsigned Position, |
8995 | SourceLocation EqualLoc, ParsedTemplateArgument DefaultArg); |
8996 | |
8997 | TemplateParameterList *ActOnTemplateParameterList( |
8998 | unsigned Depth, SourceLocation ExportLoc, SourceLocation TemplateLoc, |
8999 | SourceLocation LAngleLoc, ArrayRef<NamedDecl *> Params, |
9000 | SourceLocation RAngleLoc, Expr *RequiresClause); |
9001 | |
9002 | /// The context in which we are checking a template parameter list. |
9003 | enum TemplateParamListContext { |
9004 | TPC_ClassTemplate, |
9005 | TPC_VarTemplate, |
9006 | TPC_FunctionTemplate, |
9007 | TPC_ClassTemplateMember, |
9008 | TPC_FriendClassTemplate, |
9009 | TPC_FriendFunctionTemplate, |
9010 | TPC_FriendFunctionTemplateDefinition, |
9011 | TPC_TypeAliasTemplate |
9012 | }; |
9013 | |
9014 | bool CheckTemplateParameterList(TemplateParameterList *NewParams, |
9015 | TemplateParameterList *OldParams, |
9016 | TemplateParamListContext TPC, |
9017 | SkipBodyInfo *SkipBody = nullptr); |
9018 | TemplateParameterList *MatchTemplateParametersToScopeSpecifier( |
9019 | SourceLocation DeclStartLoc, SourceLocation DeclLoc, |
9020 | const CXXScopeSpec &SS, TemplateIdAnnotation *TemplateId, |
9021 | ArrayRef<TemplateParameterList *> ParamLists, bool IsFriend, |
9022 | bool &IsMemberSpecialization, bool &Invalid, |
9023 | bool SuppressDiagnostic = false); |
9024 | |
9025 | DeclResult CheckClassTemplate( |
9026 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
9027 | CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, |
9028 | const ParsedAttributesView &Attr, TemplateParameterList *TemplateParams, |
9029 | AccessSpecifier AS, SourceLocation ModulePrivateLoc, |
9030 | SourceLocation FriendLoc, unsigned NumOuterTemplateParamLists, |
9031 | TemplateParameterList **OuterTemplateParamLists, |
9032 | SkipBodyInfo *SkipBody = nullptr); |
9033 | |
9034 | void translateTemplateArguments(const ASTTemplateArgsPtr &In, |
9035 | TemplateArgumentListInfo &Out); |
9036 | |
9037 | ParsedTemplateArgument ActOnTemplateTypeArgument(TypeResult ParsedType); |
9038 | |
9039 | void NoteAllFoundTemplates(TemplateName Name); |
9040 | |
9041 | QualType CheckTemplateIdType(TemplateName Template, |
9042 | SourceLocation TemplateLoc, |
9043 | TemplateArgumentListInfo &TemplateArgs); |
9044 | |
9045 | TypeResult |
9046 | ActOnTemplateIdType(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
9047 | TemplateTy Template, const IdentifierInfo *TemplateII, |
9048 | SourceLocation TemplateIILoc, SourceLocation LAngleLoc, |
9049 | ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, |
9050 | bool IsCtorOrDtorName = false, bool IsClassName = false, |
9051 | ImplicitTypenameContext AllowImplicitTypename = |
9052 | ImplicitTypenameContext::No); |
9053 | |
9054 | /// Parsed an elaborated-type-specifier that refers to a template-id, |
9055 | /// such as \c class T::template apply<U>. |
9056 | TypeResult ActOnTagTemplateIdType( |
9057 | TagUseKind TUK, TypeSpecifierType TagSpec, SourceLocation TagLoc, |
9058 | CXXScopeSpec &SS, SourceLocation TemplateKWLoc, TemplateTy TemplateD, |
9059 | SourceLocation TemplateLoc, SourceLocation LAngleLoc, |
9060 | ASTTemplateArgsPtr TemplateArgsIn, SourceLocation RAngleLoc); |
9061 | |
9062 | DeclResult ActOnVarTemplateSpecialization( |
9063 | Scope *S, Declarator &D, TypeSourceInfo *DI, LookupResult &Previous, |
9064 | SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams, |
9065 | StorageClass SC, bool IsPartialSpecialization); |
9066 | |
9067 | /// Get the specialization of the given variable template corresponding to |
9068 | /// the specified argument list, or a null-but-valid result if the arguments |
9069 | /// are dependent. |
9070 | DeclResult CheckVarTemplateId(VarTemplateDecl *Template, |
9071 | SourceLocation TemplateLoc, |
9072 | SourceLocation TemplateNameLoc, |
9073 | const TemplateArgumentListInfo &TemplateArgs); |
9074 | |
9075 | /// Form a reference to the specialization of the given variable template |
9076 | /// corresponding to the specified argument list, or a null-but-valid result |
9077 | /// if the arguments are dependent. |
9078 | ExprResult CheckVarTemplateId(const CXXScopeSpec &SS, |
9079 | const DeclarationNameInfo &NameInfo, |
9080 | VarTemplateDecl *Template, NamedDecl *FoundD, |
9081 | SourceLocation TemplateLoc, |
9082 | const TemplateArgumentListInfo *TemplateArgs); |
9083 | |
9084 | ExprResult |
9085 | CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
9086 | const DeclarationNameInfo &ConceptNameInfo, |
9087 | NamedDecl *FoundDecl, ConceptDecl *NamedConcept, |
9088 | const TemplateArgumentListInfo *TemplateArgs); |
9089 | |
9090 | void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc); |
9091 | |
9092 | ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, |
9093 | SourceLocation TemplateKWLoc, LookupResult &R, |
9094 | bool RequiresADL, |
9095 | const TemplateArgumentListInfo *TemplateArgs); |
9096 | |
9097 | ExprResult |
9098 | BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
9099 | const DeclarationNameInfo &NameInfo, |
9100 | const TemplateArgumentListInfo *TemplateArgs); |
9101 | |
9102 | TemplateNameKind ActOnTemplateName(Scope *S, CXXScopeSpec &SS, |
9103 | SourceLocation TemplateKWLoc, |
9104 | const UnqualifiedId &Name, |
9105 | ParsedType ObjectType, |
9106 | bool EnteringContext, TemplateTy &Template, |
9107 | bool AllowInjectedClassName = false); |
9108 | |
9109 | DeclResult ActOnClassTemplateSpecialization( |
9110 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
9111 | SourceLocation ModulePrivateLoc, CXXScopeSpec &SS, |
9112 | TemplateIdAnnotation &TemplateId, const ParsedAttributesView &Attr, |
9113 | MultiTemplateParamsArg TemplateParameterLists, |
9114 | SkipBodyInfo *SkipBody = nullptr); |
9115 | |
9116 | bool CheckTemplatePartialSpecializationArgs(SourceLocation Loc, |
9117 | TemplateDecl *PrimaryTemplate, |
9118 | unsigned NumExplicitArgs, |
9119 | ArrayRef<TemplateArgument> Args); |
9120 | void CheckTemplatePartialSpecialization( |
9121 | ClassTemplatePartialSpecializationDecl *Partial); |
9122 | void CheckTemplatePartialSpecialization( |
9123 | VarTemplatePartialSpecializationDecl *Partial); |
9124 | |
9125 | Decl *ActOnTemplateDeclarator(Scope *S, |
9126 | MultiTemplateParamsArg TemplateParameterLists, |
9127 | Declarator &D); |
9128 | |
9129 | bool CheckSpecializationInstantiationRedecl( |
9130 | SourceLocation NewLoc, |
9131 | TemplateSpecializationKind ActOnExplicitInstantiationNewTSK, |
9132 | NamedDecl *PrevDecl, TemplateSpecializationKind PrevTSK, |
9133 | SourceLocation PrevPtOfInstantiation, bool &SuppressNew); |
9134 | |
9135 | bool CheckDependentFunctionTemplateSpecialization( |
9136 | FunctionDecl *FD, const TemplateArgumentListInfo *ExplicitTemplateArgs, |
9137 | LookupResult &Previous); |
9138 | |
9139 | bool CheckFunctionTemplateSpecialization( |
9140 | FunctionDecl *FD, TemplateArgumentListInfo *ExplicitTemplateArgs, |
9141 | LookupResult &Previous, bool QualifiedFriend = false); |
9142 | bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
9143 | void CompleteMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
9144 | |
9145 | DeclResult ActOnExplicitInstantiation( |
9146 | Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc, |
9147 | unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS, |
9148 | TemplateTy Template, SourceLocation TemplateNameLoc, |
9149 | SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, |
9150 | SourceLocation RAngleLoc, const ParsedAttributesView &Attr); |
9151 | |
9152 | DeclResult ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, |
9153 | SourceLocation TemplateLoc, |
9154 | unsigned TagSpec, SourceLocation KWLoc, |
9155 | CXXScopeSpec &SS, IdentifierInfo *Name, |
9156 | SourceLocation NameLoc, |
9157 | const ParsedAttributesView &Attr); |
9158 | |
9159 | DeclResult ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, |
9160 | SourceLocation TemplateLoc, |
9161 | Declarator &D); |
9162 | |
9163 | TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable( |
9164 | TemplateDecl *Template, SourceLocation TemplateLoc, |
9165 | SourceLocation RAngleLoc, Decl *Param, |
9166 | ArrayRef<TemplateArgument> SugaredConverted, |
9167 | ArrayRef<TemplateArgument> CanonicalConverted, bool &HasDefaultArg); |
9168 | |
9169 | SourceLocation getTopMostPointOfInstantiation(const NamedDecl *) const; |
9170 | |
9171 | /// Specifies the context in which a particular template |
9172 | /// argument is being checked. |
9173 | enum CheckTemplateArgumentKind { |
9174 | /// The template argument was specified in the code or was |
9175 | /// instantiated with some deduced template arguments. |
9176 | CTAK_Specified, |
9177 | |
9178 | /// The template argument was deduced via template argument |
9179 | /// deduction. |
9180 | CTAK_Deduced, |
9181 | |
9182 | /// The template argument was deduced from an array bound |
9183 | /// via template argument deduction. |
9184 | CTAK_DeducedFromArrayBound |
9185 | }; |
9186 | |
9187 | bool |
9188 | CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, |
9189 | NamedDecl *Template, SourceLocation TemplateLoc, |
9190 | SourceLocation RAngleLoc, unsigned ArgumentPackIndex, |
9191 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
9192 | SmallVectorImpl<TemplateArgument> &CanonicalConverted, |
9193 | CheckTemplateArgumentKind CTAK); |
9194 | |
9195 | /// Check that the given template arguments can be provided to |
9196 | /// the given template, converting the arguments along the way. |
9197 | /// |
9198 | /// \param Template The template to which the template arguments are being |
9199 | /// provided. |
9200 | /// |
9201 | /// \param TemplateLoc The location of the template name in the source. |
9202 | /// |
9203 | /// \param TemplateArgs The list of template arguments. If the template is |
9204 | /// a template template parameter, this function may extend the set of |
9205 | /// template arguments to also include substituted, defaulted template |
9206 | /// arguments. |
9207 | /// |
9208 | /// \param PartialTemplateArgs True if the list of template arguments is |
9209 | /// intentionally partial, e.g., because we're checking just the initial |
9210 | /// set of template arguments. |
9211 | /// |
9212 | /// \param Converted Will receive the converted, canonicalized template |
9213 | /// arguments. |
9214 | /// |
9215 | /// \param UpdateArgsWithConversions If \c true, update \p TemplateArgs to |
9216 | /// contain the converted forms of the template arguments as written. |
9217 | /// Otherwise, \p TemplateArgs will not be modified. |
9218 | /// |
9219 | /// \param ConstraintsNotSatisfied If provided, and an error occurred, will |
9220 | /// receive true if the cause for the error is the associated constraints of |
9221 | /// the template not being satisfied by the template arguments. |
9222 | /// |
9223 | /// \returns true if an error occurred, false otherwise. |
9224 | bool CheckTemplateArgumentList( |
9225 | TemplateDecl *Template, SourceLocation TemplateLoc, |
9226 | TemplateArgumentListInfo &TemplateArgs, bool PartialTemplateArgs, |
9227 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
9228 | SmallVectorImpl<TemplateArgument> &CanonicalConverted, |
9229 | bool UpdateArgsWithConversions = true, |
9230 | bool *ConstraintsNotSatisfied = nullptr); |
9231 | |
9232 | bool CheckTemplateTypeArgument( |
9233 | TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg, |
9234 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
9235 | SmallVectorImpl<TemplateArgument> &CanonicalConverted); |
9236 | |
9237 | bool CheckTemplateArgument(TypeSourceInfo *Arg); |
9238 | ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, |
9239 | QualType InstantiatedParamType, Expr *Arg, |
9240 | TemplateArgument &SugaredConverted, |
9241 | TemplateArgument &CanonicalConverted, |
9242 | CheckTemplateArgumentKind CTAK); |
9243 | bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, |
9244 | TemplateParameterList *Params, |
9245 | TemplateArgumentLoc &Arg); |
9246 | |
9247 | void NoteTemplateLocation(const NamedDecl &Decl, |
9248 | std::optional<SourceRange> ParamRange = {}); |
9249 | void NoteTemplateParameterLocation(const NamedDecl &Decl); |
9250 | |
9251 | ExprResult BuildExpressionFromDeclTemplateArgument( |
9252 | const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc); |
9253 | ExprResult |
9254 | BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg, |
9255 | SourceLocation Loc); |
9256 | |
9257 | /// Enumeration describing how template parameter lists are compared |
9258 | /// for equality. |
9259 | enum TemplateParameterListEqualKind { |
9260 | /// We are matching the template parameter lists of two templates |
9261 | /// that might be redeclarations. |
9262 | /// |
9263 | /// \code |
9264 | /// template<typename T> struct X; |
9265 | /// template<typename T> struct X; |
9266 | /// \endcode |
9267 | TPL_TemplateMatch, |
9268 | |
9269 | /// We are matching the template parameter lists of two template |
9270 | /// template parameters as part of matching the template parameter lists |
9271 | /// of two templates that might be redeclarations. |
9272 | /// |
9273 | /// \code |
9274 | /// template<template<int I> class TT> struct X; |
9275 | /// template<template<int Value> class Other> struct X; |
9276 | /// \endcode |
9277 | TPL_TemplateTemplateParmMatch, |
9278 | |
9279 | /// We are matching the template parameter lists of a template |
9280 | /// template argument against the template parameter lists of a template |
9281 | /// template parameter. |
9282 | /// |
9283 | /// \code |
9284 | /// template<template<int Value> class Metafun> struct X; |
9285 | /// template<int Value> struct integer_c; |
9286 | /// X<integer_c> xic; |
9287 | /// \endcode |
9288 | TPL_TemplateTemplateArgumentMatch, |
9289 | |
9290 | /// We are determining whether the template-parameters are equivalent |
9291 | /// according to C++ [temp.over.link]/6. This comparison does not consider |
9292 | /// constraints. |
9293 | /// |
9294 | /// \code |
9295 | /// template<C1 T> void f(T); |
9296 | /// template<C2 T> void f(T); |
9297 | /// \endcode |
9298 | TPL_TemplateParamsEquivalent, |
9299 | }; |
9300 | |
9301 | // A struct to represent the 'new' declaration, which is either itself just |
9302 | // the named decl, or the important information we need about it in order to |
9303 | // do constraint comparisons. |
9304 | class TemplateCompareNewDeclInfo { |
9305 | const NamedDecl *ND = nullptr; |
9306 | const DeclContext *DC = nullptr; |
9307 | const DeclContext *LexicalDC = nullptr; |
9308 | SourceLocation Loc; |
9309 | |
9310 | public: |
9311 | TemplateCompareNewDeclInfo(const NamedDecl *ND) : ND(ND) {} |
9312 | TemplateCompareNewDeclInfo(const DeclContext *DeclCtx, |
9313 | const DeclContext *LexicalDeclCtx, |
9314 | SourceLocation Loc) |
9315 | |
9316 | : DC(DeclCtx), LexicalDC(LexicalDeclCtx), Loc(Loc) { |
9317 | assert(DC && LexicalDC && |
9318 | "Constructor only for cases where we have the information to put " |
9319 | "in here" ); |
9320 | } |
9321 | |
9322 | // If this was constructed with no information, we cannot do substitution |
9323 | // for constraint comparison, so make sure we can check that. |
9324 | bool isInvalid() const { return !ND && !DC; } |
9325 | |
9326 | const NamedDecl *getDecl() const { return ND; } |
9327 | |
9328 | bool ContainsDecl(const NamedDecl *ND) const { return this->ND == ND; } |
9329 | |
9330 | const DeclContext *getLexicalDeclContext() const { |
9331 | return ND ? ND->getLexicalDeclContext() : LexicalDC; |
9332 | } |
9333 | |
9334 | const DeclContext *getDeclContext() const { |
9335 | return ND ? ND->getDeclContext() : DC; |
9336 | } |
9337 | |
9338 | SourceLocation getLocation() const { return ND ? ND->getLocation() : Loc; } |
9339 | }; |
9340 | |
9341 | bool TemplateParameterListsAreEqual( |
9342 | const TemplateCompareNewDeclInfo &NewInstFrom, TemplateParameterList *New, |
9343 | const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain, |
9344 | TemplateParameterListEqualKind Kind, |
9345 | SourceLocation TemplateArgLoc = SourceLocation()); |
9346 | |
9347 | bool TemplateParameterListsAreEqual( |
9348 | TemplateParameterList *New, TemplateParameterList *Old, bool Complain, |
9349 | TemplateParameterListEqualKind Kind, |
9350 | SourceLocation TemplateArgLoc = SourceLocation()) { |
9351 | return TemplateParameterListsAreEqual(NewInstFrom: nullptr, New, OldInstFrom: nullptr, Old, Complain, |
9352 | Kind, TemplateArgLoc); |
9353 | } |
9354 | |
9355 | bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); |
9356 | |
9357 | /// Called when the parser has parsed a C++ typename |
9358 | /// specifier, e.g., "typename T::type". |
9359 | /// |
9360 | /// \param S The scope in which this typename type occurs. |
9361 | /// \param TypenameLoc the location of the 'typename' keyword |
9362 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
9363 | /// \param II the identifier we're retrieving (e.g., 'type' in the example). |
9364 | /// \param IdLoc the location of the identifier. |
9365 | /// \param IsImplicitTypename context where T::type refers to a type. |
9366 | TypeResult ActOnTypenameType( |
9367 | Scope *S, SourceLocation TypenameLoc, const CXXScopeSpec &SS, |
9368 | const IdentifierInfo &II, SourceLocation IdLoc, |
9369 | ImplicitTypenameContext IsImplicitTypename = ImplicitTypenameContext::No); |
9370 | |
9371 | /// Called when the parser has parsed a C++ typename |
9372 | /// specifier that ends in a template-id, e.g., |
9373 | /// "typename MetaFun::template apply<T1, T2>". |
9374 | /// |
9375 | /// \param S The scope in which this typename type occurs. |
9376 | /// \param TypenameLoc the location of the 'typename' keyword |
9377 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
9378 | /// \param TemplateLoc the location of the 'template' keyword, if any. |
9379 | /// \param TemplateName The template name. |
9380 | /// \param TemplateII The identifier used to name the template. |
9381 | /// \param TemplateIILoc The location of the template name. |
9382 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
9383 | /// \param TemplateArgs The template arguments. |
9384 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
9385 | TypeResult |
9386 | ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, |
9387 | const CXXScopeSpec &SS, SourceLocation TemplateLoc, |
9388 | TemplateTy TemplateName, const IdentifierInfo *TemplateII, |
9389 | SourceLocation TemplateIILoc, SourceLocation LAngleLoc, |
9390 | ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc); |
9391 | |
9392 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
9393 | SourceLocation KeywordLoc, |
9394 | NestedNameSpecifierLoc QualifierLoc, |
9395 | const IdentifierInfo &II, SourceLocation IILoc, |
9396 | TypeSourceInfo **TSI, bool DeducedTSTContext); |
9397 | |
9398 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
9399 | SourceLocation KeywordLoc, |
9400 | NestedNameSpecifierLoc QualifierLoc, |
9401 | const IdentifierInfo &II, SourceLocation IILoc, |
9402 | bool DeducedTSTContext = true); |
9403 | |
9404 | TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, |
9405 | SourceLocation Loc, |
9406 | DeclarationName Name); |
9407 | bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); |
9408 | |
9409 | ExprResult RebuildExprInCurrentInstantiation(Expr *E); |
9410 | bool |
9411 | RebuildTemplateParamsInCurrentInstantiation(TemplateParameterList *Params); |
9412 | |
9413 | std::string |
9414 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
9415 | const TemplateArgumentList &Args); |
9416 | |
9417 | std::string |
9418 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
9419 | const TemplateArgument *Args, |
9420 | unsigned NumArgs); |
9421 | |
9422 | void diagnoseExprIntendedAsTemplateName(Scope *S, ExprResult TemplateName, |
9423 | SourceLocation Less, |
9424 | SourceLocation Greater); |
9425 | |
9426 | ExprResult ActOnDependentIdExpression( |
9427 | const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
9428 | const DeclarationNameInfo &NameInfo, bool isAddressOfOperand, |
9429 | const TemplateArgumentListInfo *TemplateArgs); |
9430 | |
9431 | ExprResult |
9432 | BuildDependentDeclRefExpr(const CXXScopeSpec &SS, |
9433 | SourceLocation TemplateKWLoc, |
9434 | const DeclarationNameInfo &NameInfo, |
9435 | const TemplateArgumentListInfo *TemplateArgs); |
9436 | |
9437 | // Calculates whether the expression Constraint depends on an enclosing |
9438 | // template, for the purposes of [temp.friend] p9. |
9439 | // TemplateDepth is the 'depth' of the friend function, which is used to |
9440 | // compare whether a declaration reference is referring to a containing |
9441 | // template, or just the current friend function. A 'lower' TemplateDepth in |
9442 | // the AST refers to a 'containing' template. As the constraint is |
9443 | // uninstantiated, this is relative to the 'top' of the TU. |
9444 | bool |
9445 | ConstraintExpressionDependsOnEnclosingTemplate(const FunctionDecl *Friend, |
9446 | unsigned TemplateDepth, |
9447 | const Expr *Constraint); |
9448 | |
9449 | /// Declare implicit deduction guides for a class template if we've |
9450 | /// not already done so. |
9451 | void DeclareImplicitDeductionGuides(TemplateDecl *Template, |
9452 | SourceLocation Loc); |
9453 | |
9454 | FunctionTemplateDecl *DeclareAggregateDeductionGuideFromInitList( |
9455 | TemplateDecl *Template, MutableArrayRef<QualType> ParamTypes, |
9456 | SourceLocation Loc); |
9457 | |
9458 | /// Find the failed Boolean condition within a given Boolean |
9459 | /// constant expression, and describe it with a string. |
9460 | std::pair<Expr *, std::string> findFailedBooleanCondition(Expr *Cond); |
9461 | |
9462 | void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD); |
9463 | |
9464 | Decl *ActOnConceptDefinition(Scope *S, |
9465 | MultiTemplateParamsArg TemplateParameterLists, |
9466 | const IdentifierInfo *Name, |
9467 | SourceLocation NameLoc, Expr *ConstraintExpr); |
9468 | |
9469 | void CheckConceptRedefinition(ConceptDecl *NewDecl, LookupResult &Previous, |
9470 | bool &AddToScope); |
9471 | |
9472 | TypeResult ActOnDependentTag(Scope *S, unsigned TagSpec, TagUseKind TUK, |
9473 | const CXXScopeSpec &SS, |
9474 | const IdentifierInfo *Name, |
9475 | SourceLocation TagLoc, SourceLocation NameLoc); |
9476 | |
9477 | void MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD, |
9478 | CachedTokens &Toks); |
9479 | void UnmarkAsLateParsedTemplate(FunctionDecl *FD); |
9480 | bool IsInsideALocalClassWithinATemplateFunction(); |
9481 | |
9482 | /// We've found a use of a templated declaration that would trigger an |
9483 | /// implicit instantiation. Check that any relevant explicit specializations |
9484 | /// and partial specializations are visible/reachable, and diagnose if not. |
9485 | void checkSpecializationVisibility(SourceLocation Loc, NamedDecl *Spec); |
9486 | void checkSpecializationReachability(SourceLocation Loc, NamedDecl *Spec); |
9487 | |
9488 | ///@} |
9489 | |
9490 | // |
9491 | // |
9492 | // ------------------------------------------------------------------------- |
9493 | // |
9494 | // |
9495 | |
9496 | /// \name C++ Template Argument Deduction |
9497 | /// Implementations are in SemaTemplateDeduction.cpp |
9498 | ///@{ |
9499 | |
9500 | public: |
9501 | /// When true, access checking violations are treated as SFINAE |
9502 | /// failures rather than hard errors. |
9503 | bool AccessCheckingSFINAE; |
9504 | |
9505 | /// RAII class used to determine whether SFINAE has |
9506 | /// trapped any errors that occur during template argument |
9507 | /// deduction. |
9508 | class SFINAETrap { |
9509 | Sema &SemaRef; |
9510 | unsigned PrevSFINAEErrors; |
9511 | bool PrevInNonInstantiationSFINAEContext; |
9512 | bool PrevAccessCheckingSFINAE; |
9513 | bool PrevLastDiagnosticIgnored; |
9514 | |
9515 | public: |
9516 | explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) |
9517 | : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), |
9518 | PrevInNonInstantiationSFINAEContext( |
9519 | SemaRef.InNonInstantiationSFINAEContext), |
9520 | PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE), |
9521 | PrevLastDiagnosticIgnored( |
9522 | SemaRef.getDiagnostics().isLastDiagnosticIgnored()) { |
9523 | if (!SemaRef.isSFINAEContext()) |
9524 | SemaRef.InNonInstantiationSFINAEContext = true; |
9525 | SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; |
9526 | } |
9527 | |
9528 | ~SFINAETrap() { |
9529 | SemaRef.NumSFINAEErrors = PrevSFINAEErrors; |
9530 | SemaRef.InNonInstantiationSFINAEContext = |
9531 | PrevInNonInstantiationSFINAEContext; |
9532 | SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; |
9533 | SemaRef.getDiagnostics().setLastDiagnosticIgnored( |
9534 | PrevLastDiagnosticIgnored); |
9535 | } |
9536 | |
9537 | /// Determine whether any SFINAE errors have been trapped. |
9538 | bool hasErrorOccurred() const { |
9539 | return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; |
9540 | } |
9541 | }; |
9542 | |
9543 | /// RAII class used to indicate that we are performing provisional |
9544 | /// semantic analysis to determine the validity of a construct, so |
9545 | /// typo-correction and diagnostics in the immediate context (not within |
9546 | /// implicitly-instantiated templates) should be suppressed. |
9547 | class TentativeAnalysisScope { |
9548 | Sema &SemaRef; |
9549 | // FIXME: Using a SFINAETrap for this is a hack. |
9550 | SFINAETrap Trap; |
9551 | bool PrevDisableTypoCorrection; |
9552 | |
9553 | public: |
9554 | explicit TentativeAnalysisScope(Sema &SemaRef) |
9555 | : SemaRef(SemaRef), Trap(SemaRef, true), |
9556 | PrevDisableTypoCorrection(SemaRef.DisableTypoCorrection) { |
9557 | SemaRef.DisableTypoCorrection = true; |
9558 | } |
9559 | ~TentativeAnalysisScope() { |
9560 | SemaRef.DisableTypoCorrection = PrevDisableTypoCorrection; |
9561 | } |
9562 | }; |
9563 | |
9564 | /// For each declaration that involved template argument deduction, the |
9565 | /// set of diagnostics that were suppressed during that template argument |
9566 | /// deduction. |
9567 | /// |
9568 | /// FIXME: Serialize this structure to the AST file. |
9569 | typedef llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1>> |
9570 | SuppressedDiagnosticsMap; |
9571 | SuppressedDiagnosticsMap SuppressedDiagnostics; |
9572 | |
9573 | bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg); |
9574 | |
9575 | TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, |
9576 | QualType NTTPType, |
9577 | SourceLocation Loc); |
9578 | |
9579 | /// Get a template argument mapping the given template parameter to itself, |
9580 | /// e.g. for X in \c template<int X>, this would return an expression template |
9581 | /// argument referencing X. |
9582 | TemplateArgumentLoc getIdentityTemplateArgumentLoc(NamedDecl *Param, |
9583 | SourceLocation Location); |
9584 | |
9585 | /// Adjust the type \p ArgFunctionType to match the calling convention, |
9586 | /// noreturn, and optionally the exception specification of \p FunctionType. |
9587 | /// Deduction often wants to ignore these properties when matching function |
9588 | /// types. |
9589 | QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType, |
9590 | bool AdjustExceptionSpec = false); |
9591 | |
9592 | TemplateDeductionResult |
9593 | DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, |
9594 | ArrayRef<TemplateArgument> TemplateArgs, |
9595 | sema::TemplateDeductionInfo &Info); |
9596 | |
9597 | TemplateDeductionResult |
9598 | DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, |
9599 | ArrayRef<TemplateArgument> TemplateArgs, |
9600 | sema::TemplateDeductionInfo &Info); |
9601 | |
9602 | TemplateDeductionResult DeduceTemplateArguments( |
9603 | TemplateParameterList *TemplateParams, ArrayRef<TemplateArgument> Ps, |
9604 | ArrayRef<TemplateArgument> As, sema::TemplateDeductionInfo &Info, |
9605 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
9606 | bool NumberOfArgumentsMustMatch); |
9607 | |
9608 | TemplateDeductionResult SubstituteExplicitTemplateArguments( |
9609 | FunctionTemplateDecl *FunctionTemplate, |
9610 | TemplateArgumentListInfo &ExplicitTemplateArgs, |
9611 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
9612 | SmallVectorImpl<QualType> &ParamTypes, QualType *FunctionType, |
9613 | sema::TemplateDeductionInfo &Info); |
9614 | |
9615 | /// brief A function argument from which we performed template argument |
9616 | // deduction for a call. |
9617 | struct OriginalCallArg { |
9618 | OriginalCallArg(QualType OriginalParamType, bool DecomposedParam, |
9619 | unsigned ArgIdx, QualType OriginalArgType) |
9620 | : OriginalParamType(OriginalParamType), |
9621 | DecomposedParam(DecomposedParam), ArgIdx(ArgIdx), |
9622 | OriginalArgType(OriginalArgType) {} |
9623 | |
9624 | QualType OriginalParamType; |
9625 | bool DecomposedParam; |
9626 | unsigned ArgIdx; |
9627 | QualType OriginalArgType; |
9628 | }; |
9629 | |
9630 | TemplateDeductionResult FinishTemplateArgumentDeduction( |
9631 | FunctionTemplateDecl *FunctionTemplate, |
9632 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
9633 | unsigned NumExplicitlySpecified, FunctionDecl *&Specialization, |
9634 | sema::TemplateDeductionInfo &Info, |
9635 | SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = nullptr, |
9636 | bool PartialOverloading = false, |
9637 | llvm::function_ref<bool()> CheckNonDependent = [] { return false; }); |
9638 | |
9639 | TemplateDeductionResult DeduceTemplateArguments( |
9640 | FunctionTemplateDecl *FunctionTemplate, |
9641 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
9642 | FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, |
9643 | bool PartialOverloading, bool AggregateDeductionCandidate, |
9644 | QualType ObjectType, Expr::Classification ObjectClassification, |
9645 | llvm::function_ref<bool(ArrayRef<QualType>)> CheckNonDependent); |
9646 | |
9647 | TemplateDeductionResult DeduceTemplateArguments( |
9648 | FunctionTemplateDecl *FunctionTemplate, |
9649 | TemplateArgumentListInfo *ExplicitTemplateArgs, QualType ArgFunctionType, |
9650 | FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, |
9651 | bool IsAddressOfFunction = false); |
9652 | |
9653 | TemplateDeductionResult DeduceTemplateArguments( |
9654 | FunctionTemplateDecl *FunctionTemplate, QualType ObjectType, |
9655 | Expr::Classification ObjectClassification, QualType ToType, |
9656 | CXXConversionDecl *&Specialization, sema::TemplateDeductionInfo &Info); |
9657 | |
9658 | TemplateDeductionResult |
9659 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
9660 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
9661 | FunctionDecl *&Specialization, |
9662 | sema::TemplateDeductionInfo &Info, |
9663 | bool IsAddressOfFunction = false); |
9664 | |
9665 | /// Substitute Replacement for \p auto in \p TypeWithAuto |
9666 | QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement); |
9667 | /// Substitute Replacement for auto in TypeWithAuto |
9668 | TypeSourceInfo *SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
9669 | QualType Replacement); |
9670 | |
9671 | // Substitute auto in TypeWithAuto for a Dependent auto type |
9672 | QualType SubstAutoTypeDependent(QualType TypeWithAuto); |
9673 | |
9674 | // Substitute auto in TypeWithAuto for a Dependent auto type |
9675 | TypeSourceInfo * |
9676 | SubstAutoTypeSourceInfoDependent(TypeSourceInfo *TypeWithAuto); |
9677 | |
9678 | /// Completely replace the \c auto in \p TypeWithAuto by |
9679 | /// \p Replacement. This does not retain any \c auto type sugar. |
9680 | QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement); |
9681 | TypeSourceInfo *ReplaceAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
9682 | QualType Replacement); |
9683 | |
9684 | TemplateDeductionResult |
9685 | DeduceAutoType(TypeLoc AutoTypeLoc, Expr *Initializer, QualType &Result, |
9686 | sema::TemplateDeductionInfo &Info, |
9687 | bool DependentDeduction = false, |
9688 | bool IgnoreConstraints = false, |
9689 | TemplateSpecCandidateSet *FailedTSC = nullptr); |
9690 | void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init); |
9691 | bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc, |
9692 | bool Diagnose = true); |
9693 | |
9694 | bool CheckIfFunctionSpecializationIsImmediate(FunctionDecl *FD, |
9695 | SourceLocation Loc); |
9696 | |
9697 | ClassTemplatePartialSpecializationDecl * |
9698 | getMoreSpecializedPartialSpecialization( |
9699 | ClassTemplatePartialSpecializationDecl *PS1, |
9700 | ClassTemplatePartialSpecializationDecl *PS2, SourceLocation Loc); |
9701 | |
9702 | bool isMoreSpecializedThanPrimary(ClassTemplatePartialSpecializationDecl *T, |
9703 | sema::TemplateDeductionInfo &Info); |
9704 | |
9705 | VarTemplatePartialSpecializationDecl *getMoreSpecializedPartialSpecialization( |
9706 | VarTemplatePartialSpecializationDecl *PS1, |
9707 | VarTemplatePartialSpecializationDecl *PS2, SourceLocation Loc); |
9708 | |
9709 | bool isMoreSpecializedThanPrimary(VarTemplatePartialSpecializationDecl *T, |
9710 | sema::TemplateDeductionInfo &Info); |
9711 | |
9712 | bool isTemplateTemplateParameterAtLeastAsSpecializedAs( |
9713 | TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc); |
9714 | |
9715 | void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced, |
9716 | unsigned Depth, llvm::SmallBitVector &Used); |
9717 | |
9718 | void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, |
9719 | bool OnlyDeduced, unsigned Depth, |
9720 | llvm::SmallBitVector &Used); |
9721 | void |
9722 | MarkDeducedTemplateParameters(const FunctionTemplateDecl *FunctionTemplate, |
9723 | llvm::SmallBitVector &Deduced) { |
9724 | return MarkDeducedTemplateParameters(Ctx&: Context, FunctionTemplate, Deduced); |
9725 | } |
9726 | static void |
9727 | MarkDeducedTemplateParameters(ASTContext &Ctx, |
9728 | const FunctionTemplateDecl *FunctionTemplate, |
9729 | llvm::SmallBitVector &Deduced); |
9730 | |
9731 | FunctionTemplateDecl *getMoreSpecializedTemplate( |
9732 | FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc, |
9733 | TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1, |
9734 | QualType RawObj1Ty = {}, QualType RawObj2Ty = {}, bool Reversed = false); |
9735 | |
9736 | UnresolvedSetIterator |
9737 | getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd, |
9738 | TemplateSpecCandidateSet &FailedCandidates, |
9739 | SourceLocation Loc, const PartialDiagnostic &NoneDiag, |
9740 | const PartialDiagnostic &AmbigDiag, |
9741 | const PartialDiagnostic &CandidateDiag, |
9742 | bool Complain = true, QualType TargetType = QualType()); |
9743 | |
9744 | ///@} |
9745 | |
9746 | // |
9747 | // |
9748 | // ------------------------------------------------------------------------- |
9749 | // |
9750 | // |
9751 | |
9752 | /// \name C++ Template Instantiation |
9753 | /// Implementations are in SemaTemplateInstantiate.cpp |
9754 | ///@{ |
9755 | |
9756 | public: |
9757 | /// A helper class for building up ExtParameterInfos. |
9758 | class ExtParameterInfoBuilder { |
9759 | SmallVector<FunctionProtoType::ExtParameterInfo, 16> Infos; |
9760 | bool HasInteresting = false; |
9761 | |
9762 | public: |
9763 | /// Set the ExtParameterInfo for the parameter at the given index, |
9764 | /// |
9765 | void set(unsigned index, FunctionProtoType::ExtParameterInfo info) { |
9766 | assert(Infos.size() <= index); |
9767 | Infos.resize(N: index); |
9768 | Infos.push_back(Elt: info); |
9769 | |
9770 | if (!HasInteresting) |
9771 | HasInteresting = (info != FunctionProtoType::ExtParameterInfo()); |
9772 | } |
9773 | |
9774 | /// Return a pointer (suitable for setting in an ExtProtoInfo) to the |
9775 | /// ExtParameterInfo array we've built up. |
9776 | const FunctionProtoType::ExtParameterInfo * |
9777 | getPointerOrNull(unsigned numParams) { |
9778 | if (!HasInteresting) |
9779 | return nullptr; |
9780 | Infos.resize(N: numParams); |
9781 | return Infos.data(); |
9782 | } |
9783 | }; |
9784 | |
9785 | /// The current instantiation scope used to store local |
9786 | /// variables. |
9787 | LocalInstantiationScope *CurrentInstantiationScope; |
9788 | |
9789 | typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>> |
9790 | UnparsedDefaultArgInstantiationsMap; |
9791 | |
9792 | /// A mapping from parameters with unparsed default arguments to the |
9793 | /// set of instantiations of each parameter. |
9794 | /// |
9795 | /// This mapping is a temporary data structure used when parsing |
9796 | /// nested class templates or nested classes of class templates, |
9797 | /// where we might end up instantiating an inner class before the |
9798 | /// default arguments of its methods have been parsed. |
9799 | UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations; |
9800 | |
9801 | /// A context in which code is being synthesized (where a source location |
9802 | /// alone is not sufficient to identify the context). This covers template |
9803 | /// instantiation and various forms of implicitly-generated functions. |
9804 | struct CodeSynthesisContext { |
9805 | /// The kind of template instantiation we are performing |
9806 | enum SynthesisKind { |
9807 | /// We are instantiating a template declaration. The entity is |
9808 | /// the declaration we're instantiating (e.g., a CXXRecordDecl). |
9809 | TemplateInstantiation, |
9810 | |
9811 | /// We are instantiating a default argument for a template |
9812 | /// parameter. The Entity is the template parameter whose argument is |
9813 | /// being instantiated, the Template is the template, and the |
9814 | /// TemplateArgs/NumTemplateArguments provide the template arguments as |
9815 | /// specified. |
9816 | DefaultTemplateArgumentInstantiation, |
9817 | |
9818 | /// We are instantiating a default argument for a function. |
9819 | /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs |
9820 | /// provides the template arguments as specified. |
9821 | DefaultFunctionArgumentInstantiation, |
9822 | |
9823 | /// We are substituting explicit template arguments provided for |
9824 | /// a function template. The entity is a FunctionTemplateDecl. |
9825 | ExplicitTemplateArgumentSubstitution, |
9826 | |
9827 | /// We are substituting template argument determined as part of |
9828 | /// template argument deduction for either a class template |
9829 | /// partial specialization or a function template. The |
9830 | /// Entity is either a {Class|Var}TemplatePartialSpecializationDecl or |
9831 | /// a TemplateDecl. |
9832 | DeducedTemplateArgumentSubstitution, |
9833 | |
9834 | /// We are substituting into a lambda expression. |
9835 | LambdaExpressionSubstitution, |
9836 | |
9837 | /// We are substituting prior template arguments into a new |
9838 | /// template parameter. The template parameter itself is either a |
9839 | /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. |
9840 | PriorTemplateArgumentSubstitution, |
9841 | |
9842 | /// We are checking the validity of a default template argument that |
9843 | /// has been used when naming a template-id. |
9844 | DefaultTemplateArgumentChecking, |
9845 | |
9846 | /// We are computing the exception specification for a defaulted special |
9847 | /// member function. |
9848 | ExceptionSpecEvaluation, |
9849 | |
9850 | /// We are instantiating the exception specification for a function |
9851 | /// template which was deferred until it was needed. |
9852 | ExceptionSpecInstantiation, |
9853 | |
9854 | /// We are instantiating a requirement of a requires expression. |
9855 | RequirementInstantiation, |
9856 | |
9857 | /// We are checking the satisfaction of a nested requirement of a requires |
9858 | /// expression. |
9859 | NestedRequirementConstraintsCheck, |
9860 | |
9861 | /// We are declaring an implicit special member function. |
9862 | DeclaringSpecialMember, |
9863 | |
9864 | /// We are declaring an implicit 'operator==' for a defaulted |
9865 | /// 'operator<=>'. |
9866 | DeclaringImplicitEqualityComparison, |
9867 | |
9868 | /// We are defining a synthesized function (such as a defaulted special |
9869 | /// member). |
9870 | DefiningSynthesizedFunction, |
9871 | |
9872 | // We are checking the constraints associated with a constrained entity or |
9873 | // the constraint expression of a concept. This includes the checks that |
9874 | // atomic constraints have the type 'bool' and that they can be constant |
9875 | // evaluated. |
9876 | ConstraintsCheck, |
9877 | |
9878 | // We are substituting template arguments into a constraint expression. |
9879 | ConstraintSubstitution, |
9880 | |
9881 | // We are normalizing a constraint expression. |
9882 | ConstraintNormalization, |
9883 | |
9884 | // Instantiating a Requires Expression parameter clause. |
9885 | RequirementParameterInstantiation, |
9886 | |
9887 | // We are substituting into the parameter mapping of an atomic constraint |
9888 | // during normalization. |
9889 | ParameterMappingSubstitution, |
9890 | |
9891 | /// We are rewriting a comparison operator in terms of an operator<=>. |
9892 | RewritingOperatorAsSpaceship, |
9893 | |
9894 | /// We are initializing a structured binding. |
9895 | InitializingStructuredBinding, |
9896 | |
9897 | /// We are marking a class as __dllexport. |
9898 | MarkingClassDllexported, |
9899 | |
9900 | /// We are building an implied call from __builtin_dump_struct. The |
9901 | /// arguments are in CallArgs. |
9902 | BuildingBuiltinDumpStructCall, |
9903 | |
9904 | /// Added for Template instantiation observation. |
9905 | /// Memoization means we are _not_ instantiating a template because |
9906 | /// it is already instantiated (but we entered a context where we |
9907 | /// would have had to if it was not already instantiated). |
9908 | Memoization, |
9909 | |
9910 | /// We are building deduction guides for a class. |
9911 | BuildingDeductionGuides, |
9912 | |
9913 | /// We are instantiating a type alias template declaration. |
9914 | TypeAliasTemplateInstantiation, |
9915 | } Kind; |
9916 | |
9917 | /// Was the enclosing context a non-instantiation SFINAE context? |
9918 | bool SavedInNonInstantiationSFINAEContext; |
9919 | |
9920 | /// The point of instantiation or synthesis within the source code. |
9921 | SourceLocation PointOfInstantiation; |
9922 | |
9923 | /// The entity that is being synthesized. |
9924 | Decl *Entity; |
9925 | |
9926 | /// The template (or partial specialization) in which we are |
9927 | /// performing the instantiation, for substitutions of prior template |
9928 | /// arguments. |
9929 | NamedDecl *Template; |
9930 | |
9931 | union { |
9932 | /// The list of template arguments we are substituting, if they |
9933 | /// are not part of the entity. |
9934 | const TemplateArgument *TemplateArgs; |
9935 | |
9936 | /// The list of argument expressions in a synthesized call. |
9937 | const Expr *const *CallArgs; |
9938 | }; |
9939 | |
9940 | // FIXME: Wrap this union around more members, or perhaps store the |
9941 | // kind-specific members in the RAII object owning the context. |
9942 | union { |
9943 | /// The number of template arguments in TemplateArgs. |
9944 | unsigned NumTemplateArgs; |
9945 | |
9946 | /// The number of expressions in CallArgs. |
9947 | unsigned NumCallArgs; |
9948 | |
9949 | /// The special member being declared or defined. |
9950 | CXXSpecialMemberKind SpecialMember; |
9951 | }; |
9952 | |
9953 | ArrayRef<TemplateArgument> template_arguments() const { |
9954 | assert(Kind != DeclaringSpecialMember); |
9955 | return {TemplateArgs, NumTemplateArgs}; |
9956 | } |
9957 | |
9958 | /// The template deduction info object associated with the |
9959 | /// substitution or checking of explicit or deduced template arguments. |
9960 | sema::TemplateDeductionInfo *DeductionInfo; |
9961 | |
9962 | /// The source range that covers the construct that cause |
9963 | /// the instantiation, e.g., the template-id that causes a class |
9964 | /// template instantiation. |
9965 | SourceRange InstantiationRange; |
9966 | |
9967 | CodeSynthesisContext() |
9968 | : Kind(TemplateInstantiation), |
9969 | SavedInNonInstantiationSFINAEContext(false), Entity(nullptr), |
9970 | Template(nullptr), TemplateArgs(nullptr), NumTemplateArgs(0), |
9971 | DeductionInfo(nullptr) {} |
9972 | |
9973 | /// Determines whether this template is an actual instantiation |
9974 | /// that should be counted toward the maximum instantiation depth. |
9975 | bool isInstantiationRecord() const; |
9976 | }; |
9977 | |
9978 | /// A stack object to be created when performing template |
9979 | /// instantiation. |
9980 | /// |
9981 | /// Construction of an object of type \c InstantiatingTemplate |
9982 | /// pushes the current instantiation onto the stack of active |
9983 | /// instantiations. If the size of this stack exceeds the maximum |
9984 | /// number of recursive template instantiations, construction |
9985 | /// produces an error and evaluates true. |
9986 | /// |
9987 | /// Destruction of this object will pop the named instantiation off |
9988 | /// the stack. |
9989 | struct InstantiatingTemplate { |
9990 | /// Note that we are instantiating a class template, |
9991 | /// function template, variable template, alias template, |
9992 | /// or a member thereof. |
9993 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
9994 | Decl *Entity, |
9995 | SourceRange InstantiationRange = SourceRange()); |
9996 | |
9997 | struct ExceptionSpecification {}; |
9998 | /// Note that we are instantiating an exception specification |
9999 | /// of a function template. |
10000 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10001 | FunctionDecl *Entity, ExceptionSpecification, |
10002 | SourceRange InstantiationRange = SourceRange()); |
10003 | |
10004 | /// Note that we are instantiating a type alias template declaration. |
10005 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10006 | TypeAliasTemplateDecl *Entity, |
10007 | ArrayRef<TemplateArgument> TemplateArgs, |
10008 | SourceRange InstantiationRange = SourceRange()); |
10009 | |
10010 | /// Note that we are instantiating a default argument in a |
10011 | /// template-id. |
10012 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10013 | TemplateParameter Param, TemplateDecl *Template, |
10014 | ArrayRef<TemplateArgument> TemplateArgs, |
10015 | SourceRange InstantiationRange = SourceRange()); |
10016 | |
10017 | /// Note that we are substituting either explicitly-specified or |
10018 | /// deduced template arguments during function template argument deduction. |
10019 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10020 | FunctionTemplateDecl *FunctionTemplate, |
10021 | ArrayRef<TemplateArgument> TemplateArgs, |
10022 | CodeSynthesisContext::SynthesisKind Kind, |
10023 | sema::TemplateDeductionInfo &DeductionInfo, |
10024 | SourceRange InstantiationRange = SourceRange()); |
10025 | |
10026 | /// Note that we are instantiating as part of template |
10027 | /// argument deduction for a class template declaration. |
10028 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10029 | TemplateDecl *Template, |
10030 | ArrayRef<TemplateArgument> TemplateArgs, |
10031 | sema::TemplateDeductionInfo &DeductionInfo, |
10032 | SourceRange InstantiationRange = SourceRange()); |
10033 | |
10034 | /// Note that we are instantiating as part of template |
10035 | /// argument deduction for a class template partial |
10036 | /// specialization. |
10037 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10038 | ClassTemplatePartialSpecializationDecl *PartialSpec, |
10039 | ArrayRef<TemplateArgument> TemplateArgs, |
10040 | sema::TemplateDeductionInfo &DeductionInfo, |
10041 | SourceRange InstantiationRange = SourceRange()); |
10042 | |
10043 | /// Note that we are instantiating as part of template |
10044 | /// argument deduction for a variable template partial |
10045 | /// specialization. |
10046 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10047 | VarTemplatePartialSpecializationDecl *PartialSpec, |
10048 | ArrayRef<TemplateArgument> TemplateArgs, |
10049 | sema::TemplateDeductionInfo &DeductionInfo, |
10050 | SourceRange InstantiationRange = SourceRange()); |
10051 | |
10052 | /// Note that we are instantiating a default argument for a function |
10053 | /// parameter. |
10054 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10055 | ParmVarDecl *Param, |
10056 | ArrayRef<TemplateArgument> TemplateArgs, |
10057 | SourceRange InstantiationRange = SourceRange()); |
10058 | |
10059 | /// Note that we are substituting prior template arguments into a |
10060 | /// non-type parameter. |
10061 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10062 | NamedDecl *Template, NonTypeTemplateParmDecl *Param, |
10063 | ArrayRef<TemplateArgument> TemplateArgs, |
10064 | SourceRange InstantiationRange); |
10065 | |
10066 | /// Note that we are substituting prior template arguments into a |
10067 | /// template template parameter. |
10068 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10069 | NamedDecl *Template, TemplateTemplateParmDecl *Param, |
10070 | ArrayRef<TemplateArgument> TemplateArgs, |
10071 | SourceRange InstantiationRange); |
10072 | |
10073 | /// Note that we are checking the default template argument |
10074 | /// against the template parameter for a given template-id. |
10075 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10076 | TemplateDecl *Template, NamedDecl *Param, |
10077 | ArrayRef<TemplateArgument> TemplateArgs, |
10078 | SourceRange InstantiationRange); |
10079 | |
10080 | struct ConstraintsCheck {}; |
10081 | /// \brief Note that we are checking the constraints associated with some |
10082 | /// constrained entity (a concept declaration or a template with associated |
10083 | /// constraints). |
10084 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10085 | ConstraintsCheck, NamedDecl *Template, |
10086 | ArrayRef<TemplateArgument> TemplateArgs, |
10087 | SourceRange InstantiationRange); |
10088 | |
10089 | struct ConstraintSubstitution {}; |
10090 | /// \brief Note that we are checking a constraint expression associated |
10091 | /// with a template declaration or as part of the satisfaction check of a |
10092 | /// concept. |
10093 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10094 | ConstraintSubstitution, NamedDecl *Template, |
10095 | sema::TemplateDeductionInfo &DeductionInfo, |
10096 | SourceRange InstantiationRange); |
10097 | |
10098 | struct ConstraintNormalization {}; |
10099 | /// \brief Note that we are normalizing a constraint expression. |
10100 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10101 | ConstraintNormalization, NamedDecl *Template, |
10102 | SourceRange InstantiationRange); |
10103 | |
10104 | struct ParameterMappingSubstitution {}; |
10105 | /// \brief Note that we are subtituting into the parameter mapping of an |
10106 | /// atomic constraint during constraint normalization. |
10107 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10108 | ParameterMappingSubstitution, NamedDecl *Template, |
10109 | SourceRange InstantiationRange); |
10110 | |
10111 | /// \brief Note that we are substituting template arguments into a part of |
10112 | /// a requirement of a requires expression. |
10113 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10114 | concepts::Requirement *Req, |
10115 | sema::TemplateDeductionInfo &DeductionInfo, |
10116 | SourceRange InstantiationRange = SourceRange()); |
10117 | |
10118 | /// \brief Note that we are checking the satisfaction of the constraint |
10119 | /// expression inside of a nested requirement. |
10120 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10121 | concepts::NestedRequirement *Req, ConstraintsCheck, |
10122 | SourceRange InstantiationRange = SourceRange()); |
10123 | |
10124 | /// \brief Note that we are checking a requires clause. |
10125 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10126 | const RequiresExpr *E, |
10127 | sema::TemplateDeductionInfo &DeductionInfo, |
10128 | SourceRange InstantiationRange); |
10129 | |
10130 | struct BuildingDeductionGuidesTag {}; |
10131 | /// \brief Note that we are building deduction guides. |
10132 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
10133 | TemplateDecl *Entity, BuildingDeductionGuidesTag, |
10134 | SourceRange InstantiationRange = SourceRange()); |
10135 | |
10136 | /// Note that we have finished instantiating this template. |
10137 | void Clear(); |
10138 | |
10139 | ~InstantiatingTemplate() { Clear(); } |
10140 | |
10141 | /// Determines whether we have exceeded the maximum |
10142 | /// recursive template instantiations. |
10143 | bool isInvalid() const { return Invalid; } |
10144 | |
10145 | /// Determine whether we are already instantiating this |
10146 | /// specialization in some surrounding active instantiation. |
10147 | bool isAlreadyInstantiating() const { return AlreadyInstantiating; } |
10148 | |
10149 | private: |
10150 | Sema &SemaRef; |
10151 | bool Invalid; |
10152 | bool AlreadyInstantiating; |
10153 | bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, |
10154 | SourceRange InstantiationRange); |
10155 | |
10156 | InstantiatingTemplate( |
10157 | Sema &SemaRef, CodeSynthesisContext::SynthesisKind Kind, |
10158 | SourceLocation PointOfInstantiation, SourceRange InstantiationRange, |
10159 | Decl *Entity, NamedDecl *Template = nullptr, |
10160 | ArrayRef<TemplateArgument> TemplateArgs = std::nullopt, |
10161 | sema::TemplateDeductionInfo *DeductionInfo = nullptr); |
10162 | |
10163 | InstantiatingTemplate(const InstantiatingTemplate &) = delete; |
10164 | |
10165 | InstantiatingTemplate &operator=(const InstantiatingTemplate &) = delete; |
10166 | }; |
10167 | |
10168 | bool SubstTemplateArgument(const TemplateArgumentLoc &Input, |
10169 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10170 | TemplateArgumentLoc &Output); |
10171 | bool |
10172 | SubstTemplateArguments(ArrayRef<TemplateArgumentLoc> Args, |
10173 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10174 | TemplateArgumentListInfo &Outputs); |
10175 | |
10176 | MultiLevelTemplateArgumentList getTemplateInstantiationArgs( |
10177 | const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false, |
10178 | std::optional<ArrayRef<TemplateArgument>> Innermost = std::nullopt, |
10179 | bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr, |
10180 | bool ForConstraintInstantiation = false, |
10181 | bool SkipForSpecialization = false); |
10182 | |
10183 | /// RAII object to handle the state changes required to synthesize |
10184 | /// a function body. |
10185 | class SynthesizedFunctionScope { |
10186 | Sema &S; |
10187 | Sema::ContextRAII SavedContext; |
10188 | bool PushedCodeSynthesisContext = false; |
10189 | |
10190 | public: |
10191 | SynthesizedFunctionScope(Sema &S, DeclContext *DC) |
10192 | : S(S), SavedContext(S, DC) { |
10193 | auto *FD = dyn_cast<FunctionDecl>(Val: DC); |
10194 | S.PushFunctionScope(); |
10195 | S.PushExpressionEvaluationContext( |
10196 | NewContext: (FD && FD->isConsteval()) |
10197 | ? ExpressionEvaluationContext::ImmediateFunctionContext |
10198 | : ExpressionEvaluationContext::PotentiallyEvaluated); |
10199 | if (FD) { |
10200 | FD->setWillHaveBody(true); |
10201 | S.ExprEvalContexts.back().InImmediateFunctionContext = |
10202 | FD->isImmediateFunction() || |
10203 | S.ExprEvalContexts[S.ExprEvalContexts.size() - 2] |
10204 | .isConstantEvaluated(); |
10205 | S.ExprEvalContexts.back().InImmediateEscalatingFunctionContext = |
10206 | S.getLangOpts().CPlusPlus20 && FD->isImmediateEscalating(); |
10207 | } else |
10208 | assert(isa<ObjCMethodDecl>(DC)); |
10209 | } |
10210 | |
10211 | void addContextNote(SourceLocation UseLoc) { |
10212 | assert(!PushedCodeSynthesisContext); |
10213 | |
10214 | Sema::CodeSynthesisContext Ctx; |
10215 | Ctx.Kind = Sema::CodeSynthesisContext::DefiningSynthesizedFunction; |
10216 | Ctx.PointOfInstantiation = UseLoc; |
10217 | Ctx.Entity = cast<Decl>(Val: S.CurContext); |
10218 | S.pushCodeSynthesisContext(Ctx); |
10219 | |
10220 | PushedCodeSynthesisContext = true; |
10221 | } |
10222 | |
10223 | ~SynthesizedFunctionScope() { |
10224 | if (PushedCodeSynthesisContext) |
10225 | S.popCodeSynthesisContext(); |
10226 | if (auto *FD = dyn_cast<FunctionDecl>(Val: S.CurContext)) { |
10227 | FD->setWillHaveBody(false); |
10228 | S.CheckImmediateEscalatingFunctionDefinition(FD, FSI: S.getCurFunction()); |
10229 | } |
10230 | S.PopExpressionEvaluationContext(); |
10231 | S.PopFunctionScopeInfo(); |
10232 | } |
10233 | }; |
10234 | |
10235 | /// List of active code synthesis contexts. |
10236 | /// |
10237 | /// This vector is treated as a stack. As synthesis of one entity requires |
10238 | /// synthesis of another, additional contexts are pushed onto the stack. |
10239 | SmallVector<CodeSynthesisContext, 16> CodeSynthesisContexts; |
10240 | |
10241 | /// Specializations whose definitions are currently being instantiated. |
10242 | llvm::DenseSet<std::pair<Decl *, unsigned>> InstantiatingSpecializations; |
10243 | |
10244 | /// Non-dependent types used in templates that have already been instantiated |
10245 | /// by some template instantiation. |
10246 | llvm::DenseSet<QualType> InstantiatedNonDependentTypes; |
10247 | |
10248 | /// Extra modules inspected when performing a lookup during a template |
10249 | /// instantiation. Computed lazily. |
10250 | SmallVector<Module *, 16> CodeSynthesisContextLookupModules; |
10251 | |
10252 | /// Cache of additional modules that should be used for name lookup |
10253 | /// within the current template instantiation. Computed lazily; use |
10254 | /// getLookupModules() to get a complete set. |
10255 | llvm::DenseSet<Module *> LookupModulesCache; |
10256 | |
10257 | /// Map from the most recent declaration of a namespace to the most |
10258 | /// recent visible declaration of that namespace. |
10259 | llvm::DenseMap<NamedDecl *, NamedDecl *> VisibleNamespaceCache; |
10260 | |
10261 | /// Whether we are in a SFINAE context that is not associated with |
10262 | /// template instantiation. |
10263 | /// |
10264 | /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside |
10265 | /// of a template instantiation or template argument deduction. |
10266 | bool InNonInstantiationSFINAEContext; |
10267 | |
10268 | /// The number of \p CodeSynthesisContexts that are not template |
10269 | /// instantiations and, therefore, should not be counted as part of the |
10270 | /// instantiation depth. |
10271 | /// |
10272 | /// When the instantiation depth reaches the user-configurable limit |
10273 | /// \p LangOptions::InstantiationDepth we will abort instantiation. |
10274 | // FIXME: Should we have a similar limit for other forms of synthesis? |
10275 | unsigned NonInstantiationEntries; |
10276 | |
10277 | /// The depth of the context stack at the point when the most recent |
10278 | /// error or warning was produced. |
10279 | /// |
10280 | /// This value is used to suppress printing of redundant context stacks |
10281 | /// when there are multiple errors or warnings in the same instantiation. |
10282 | // FIXME: Does this belong in Sema? It's tough to implement it anywhere else. |
10283 | unsigned LastEmittedCodeSynthesisContextDepth = 0; |
10284 | |
10285 | /// The template instantiation callbacks to trace or track |
10286 | /// instantiations (objects can be chained). |
10287 | /// |
10288 | /// This callbacks is used to print, trace or track template |
10289 | /// instantiations as they are being constructed. |
10290 | std::vector<std::unique_ptr<TemplateInstantiationCallback>> |
10291 | TemplateInstCallbacks; |
10292 | |
10293 | /// The current index into pack expansion arguments that will be |
10294 | /// used for substitution of parameter packs. |
10295 | /// |
10296 | /// The pack expansion index will be -1 to indicate that parameter packs |
10297 | /// should be instantiated as themselves. Otherwise, the index specifies |
10298 | /// which argument within the parameter pack will be used for substitution. |
10299 | int ArgumentPackSubstitutionIndex; |
10300 | |
10301 | /// RAII object used to change the argument pack substitution index |
10302 | /// within a \c Sema object. |
10303 | /// |
10304 | /// See \c ArgumentPackSubstitutionIndex for more information. |
10305 | class ArgumentPackSubstitutionIndexRAII { |
10306 | Sema &Self; |
10307 | int OldSubstitutionIndex; |
10308 | |
10309 | public: |
10310 | ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) |
10311 | : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { |
10312 | Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; |
10313 | } |
10314 | |
10315 | ~ArgumentPackSubstitutionIndexRAII() { |
10316 | Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; |
10317 | } |
10318 | }; |
10319 | |
10320 | friend class ArgumentPackSubstitutionRAII; |
10321 | |
10322 | void pushCodeSynthesisContext(CodeSynthesisContext Ctx); |
10323 | void popCodeSynthesisContext(); |
10324 | |
10325 | void PrintContextStack() { |
10326 | if (!CodeSynthesisContexts.empty() && |
10327 | CodeSynthesisContexts.size() != LastEmittedCodeSynthesisContextDepth) { |
10328 | PrintInstantiationStack(); |
10329 | LastEmittedCodeSynthesisContextDepth = CodeSynthesisContexts.size(); |
10330 | } |
10331 | if (PragmaAttributeCurrentTargetDecl) |
10332 | PrintPragmaAttributeInstantiationPoint(); |
10333 | } |
10334 | void PrintInstantiationStack(); |
10335 | |
10336 | /// Determines whether we are currently in a context where |
10337 | /// template argument substitution failures are not considered |
10338 | /// errors. |
10339 | /// |
10340 | /// \returns An empty \c Optional if we're not in a SFINAE context. |
10341 | /// Otherwise, contains a pointer that, if non-NULL, contains the nearest |
10342 | /// template-deduction context object, which can be used to capture |
10343 | /// diagnostics that will be suppressed. |
10344 | std::optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; |
10345 | |
10346 | TypeSourceInfo *SubstType(TypeSourceInfo *T, |
10347 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10348 | SourceLocation Loc, DeclarationName Entity, |
10349 | bool AllowDeducedTST = false); |
10350 | |
10351 | QualType SubstType(QualType T, |
10352 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10353 | SourceLocation Loc, DeclarationName Entity); |
10354 | |
10355 | TypeSourceInfo *SubstType(TypeLoc TL, |
10356 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10357 | SourceLocation Loc, DeclarationName Entity); |
10358 | |
10359 | TypeSourceInfo *SubstFunctionDeclType( |
10360 | TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, |
10361 | SourceLocation Loc, DeclarationName Entity, CXXRecordDecl *ThisContext, |
10362 | Qualifiers ThisTypeQuals, bool EvaluateConstraints = true); |
10363 | void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, |
10364 | const MultiLevelTemplateArgumentList &Args); |
10365 | bool SubstExceptionSpec(SourceLocation Loc, |
10366 | FunctionProtoType::ExceptionSpecInfo &ESI, |
10367 | SmallVectorImpl<QualType> &ExceptionStorage, |
10368 | const MultiLevelTemplateArgumentList &Args); |
10369 | ParmVarDecl * |
10370 | SubstParmVarDecl(ParmVarDecl *D, |
10371 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10372 | int indexAdjustment, std::optional<unsigned> NumExpansions, |
10373 | bool ExpectParameterPack, bool EvaluateConstraints = true); |
10374 | bool SubstParmTypes(SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
10375 | const FunctionProtoType::ExtParameterInfo *ExtParamInfos, |
10376 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10377 | SmallVectorImpl<QualType> &ParamTypes, |
10378 | SmallVectorImpl<ParmVarDecl *> *OutParams, |
10379 | ExtParameterInfoBuilder &ParamInfos); |
10380 | bool SubstDefaultArgument(SourceLocation Loc, ParmVarDecl *Param, |
10381 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10382 | bool ForCallExpr = false); |
10383 | ExprResult SubstExpr(Expr *E, |
10384 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10385 | |
10386 | // A RAII type used by the TemplateDeclInstantiator and TemplateInstantiator |
10387 | // to disable constraint evaluation, then restore the state. |
10388 | template <typename InstTy> struct ConstraintEvalRAII { |
10389 | InstTy &TI; |
10390 | bool OldValue; |
10391 | |
10392 | ConstraintEvalRAII(InstTy &TI) |
10393 | : TI(TI), OldValue(TI.getEvaluateConstraints()) { |
10394 | TI.setEvaluateConstraints(false); |
10395 | } |
10396 | ~ConstraintEvalRAII() { TI.setEvaluateConstraints(OldValue); } |
10397 | }; |
10398 | |
10399 | // Must be used instead of SubstExpr at 'constraint checking' time. |
10400 | ExprResult |
10401 | SubstConstraintExpr(Expr *E, |
10402 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10403 | // Unlike the above, this does not evaluates constraints. |
10404 | ExprResult SubstConstraintExprWithoutSatisfaction( |
10405 | Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs); |
10406 | |
10407 | /// Substitute the given template arguments into a list of |
10408 | /// expressions, expanding pack expansions if required. |
10409 | /// |
10410 | /// \param Exprs The list of expressions to substitute into. |
10411 | /// |
10412 | /// \param IsCall Whether this is some form of call, in which case |
10413 | /// default arguments will be dropped. |
10414 | /// |
10415 | /// \param TemplateArgs The set of template arguments to substitute. |
10416 | /// |
10417 | /// \param Outputs Will receive all of the substituted arguments. |
10418 | /// |
10419 | /// \returns true if an error occurred, false otherwise. |
10420 | bool SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall, |
10421 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10422 | SmallVectorImpl<Expr *> &Outputs); |
10423 | |
10424 | StmtResult SubstStmt(Stmt *S, |
10425 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10426 | |
10427 | ExprResult |
10428 | SubstInitializer(Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs, |
10429 | bool CXXDirectInit); |
10430 | |
10431 | bool SubstBaseSpecifiers(CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
10432 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10433 | |
10434 | bool InstantiateClass(SourceLocation PointOfInstantiation, |
10435 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
10436 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10437 | TemplateSpecializationKind TSK, bool Complain = true); |
10438 | |
10439 | bool InstantiateEnum(SourceLocation PointOfInstantiation, |
10440 | EnumDecl *Instantiation, EnumDecl *Pattern, |
10441 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10442 | TemplateSpecializationKind TSK); |
10443 | |
10444 | bool InstantiateInClassInitializer( |
10445 | SourceLocation PointOfInstantiation, FieldDecl *Instantiation, |
10446 | FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs); |
10447 | |
10448 | bool usesPartialOrExplicitSpecialization( |
10449 | SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec); |
10450 | |
10451 | bool InstantiateClassTemplateSpecialization( |
10452 | SourceLocation PointOfInstantiation, |
10453 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
10454 | TemplateSpecializationKind TSK, bool Complain = true); |
10455 | |
10456 | void |
10457 | InstantiateClassMembers(SourceLocation PointOfInstantiation, |
10458 | CXXRecordDecl *Instantiation, |
10459 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10460 | TemplateSpecializationKind TSK); |
10461 | |
10462 | void InstantiateClassTemplateSpecializationMembers( |
10463 | SourceLocation PointOfInstantiation, |
10464 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
10465 | TemplateSpecializationKind TSK); |
10466 | |
10467 | NestedNameSpecifierLoc SubstNestedNameSpecifierLoc( |
10468 | NestedNameSpecifierLoc NNS, |
10469 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10470 | |
10471 | DeclarationNameInfo |
10472 | SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
10473 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10474 | TemplateName |
10475 | SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, |
10476 | SourceLocation Loc, |
10477 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10478 | |
10479 | bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC, |
10480 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10481 | bool EvaluateConstraint); |
10482 | |
10483 | /// Determine whether we are currently performing template instantiation. |
10484 | bool inTemplateInstantiation() const { |
10485 | return CodeSynthesisContexts.size() > NonInstantiationEntries; |
10486 | } |
10487 | |
10488 | ///@} |
10489 | |
10490 | // |
10491 | // |
10492 | // ------------------------------------------------------------------------- |
10493 | // |
10494 | // |
10495 | |
10496 | /// \name C++ Template Declaration Instantiation |
10497 | /// Implementations are in SemaTemplateInstantiateDecl.cpp |
10498 | ///@{ |
10499 | |
10500 | public: |
10501 | /// An entity for which implicit template instantiation is required. |
10502 | /// |
10503 | /// The source location associated with the declaration is the first place in |
10504 | /// the source code where the declaration was "used". It is not necessarily |
10505 | /// the point of instantiation (which will be either before or after the |
10506 | /// namespace-scope declaration that triggered this implicit instantiation), |
10507 | /// However, it is the location that diagnostics should generally refer to, |
10508 | /// because users will need to know what code triggered the instantiation. |
10509 | typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; |
10510 | |
10511 | /// The queue of implicit template instantiations that are required |
10512 | /// but have not yet been performed. |
10513 | std::deque<PendingImplicitInstantiation> PendingInstantiations; |
10514 | |
10515 | /// Queue of implicit template instantiations that cannot be performed |
10516 | /// eagerly. |
10517 | SmallVector<PendingImplicitInstantiation, 1> LateParsedInstantiations; |
10518 | |
10519 | SmallVector<SmallVector<VTableUse, 16>, 8> SavedVTableUses; |
10520 | SmallVector<std::deque<PendingImplicitInstantiation>, 8> |
10521 | SavedPendingInstantiations; |
10522 | |
10523 | /// The queue of implicit template instantiations that are required |
10524 | /// and must be performed within the current local scope. |
10525 | /// |
10526 | /// This queue is only used for member functions of local classes in |
10527 | /// templates, which must be instantiated in the same scope as their |
10528 | /// enclosing function, so that they can reference function-local |
10529 | /// types, static variables, enumerators, etc. |
10530 | std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; |
10531 | |
10532 | class LocalEagerInstantiationScope { |
10533 | public: |
10534 | LocalEagerInstantiationScope(Sema &S) : S(S) { |
10535 | SavedPendingLocalImplicitInstantiations.swap( |
10536 | x&: S.PendingLocalImplicitInstantiations); |
10537 | } |
10538 | |
10539 | void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/LocalOnly: true); } |
10540 | |
10541 | ~LocalEagerInstantiationScope() { |
10542 | assert(S.PendingLocalImplicitInstantiations.empty() && |
10543 | "there shouldn't be any pending local implicit instantiations" ); |
10544 | SavedPendingLocalImplicitInstantiations.swap( |
10545 | x&: S.PendingLocalImplicitInstantiations); |
10546 | } |
10547 | |
10548 | private: |
10549 | Sema &S; |
10550 | std::deque<PendingImplicitInstantiation> |
10551 | SavedPendingLocalImplicitInstantiations; |
10552 | }; |
10553 | |
10554 | /// Records and restores the CurFPFeatures state on entry/exit of compound |
10555 | /// statements. |
10556 | class FPFeaturesStateRAII { |
10557 | public: |
10558 | FPFeaturesStateRAII(Sema &S); |
10559 | ~FPFeaturesStateRAII(); |
10560 | FPOptionsOverride getOverrides() { return OldOverrides; } |
10561 | |
10562 | private: |
10563 | Sema &S; |
10564 | FPOptions OldFPFeaturesState; |
10565 | FPOptionsOverride OldOverrides; |
10566 | LangOptions::FPEvalMethodKind OldEvalMethod; |
10567 | SourceLocation OldFPPragmaLocation; |
10568 | }; |
10569 | |
10570 | class GlobalEagerInstantiationScope { |
10571 | public: |
10572 | GlobalEagerInstantiationScope(Sema &S, bool Enabled) |
10573 | : S(S), Enabled(Enabled) { |
10574 | if (!Enabled) |
10575 | return; |
10576 | |
10577 | S.SavedPendingInstantiations.emplace_back(); |
10578 | S.SavedPendingInstantiations.back().swap(x&: S.PendingInstantiations); |
10579 | |
10580 | S.SavedVTableUses.emplace_back(); |
10581 | S.SavedVTableUses.back().swap(RHS&: S.VTableUses); |
10582 | } |
10583 | |
10584 | void perform() { |
10585 | if (Enabled) { |
10586 | S.DefineUsedVTables(); |
10587 | S.PerformPendingInstantiations(); |
10588 | } |
10589 | } |
10590 | |
10591 | ~GlobalEagerInstantiationScope() { |
10592 | if (!Enabled) |
10593 | return; |
10594 | |
10595 | // Restore the set of pending vtables. |
10596 | assert(S.VTableUses.empty() && |
10597 | "VTableUses should be empty before it is discarded." ); |
10598 | S.VTableUses.swap(RHS&: S.SavedVTableUses.back()); |
10599 | S.SavedVTableUses.pop_back(); |
10600 | |
10601 | // Restore the set of pending implicit instantiations. |
10602 | if (S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) { |
10603 | assert(S.PendingInstantiations.empty() && |
10604 | "PendingInstantiations should be empty before it is discarded." ); |
10605 | S.PendingInstantiations.swap(x&: S.SavedPendingInstantiations.back()); |
10606 | S.SavedPendingInstantiations.pop_back(); |
10607 | } else { |
10608 | // Template instantiations in the PCH may be delayed until the TU. |
10609 | S.PendingInstantiations.swap(x&: S.SavedPendingInstantiations.back()); |
10610 | S.PendingInstantiations.insert( |
10611 | position: S.PendingInstantiations.end(), |
10612 | first: S.SavedPendingInstantiations.back().begin(), |
10613 | last: S.SavedPendingInstantiations.back().end()); |
10614 | S.SavedPendingInstantiations.pop_back(); |
10615 | } |
10616 | } |
10617 | |
10618 | private: |
10619 | Sema &S; |
10620 | bool Enabled; |
10621 | }; |
10622 | |
10623 | ExplicitSpecifier instantiateExplicitSpecifier( |
10624 | const MultiLevelTemplateArgumentList &TemplateArgs, ExplicitSpecifier ES); |
10625 | |
10626 | struct LateInstantiatedAttribute { |
10627 | const Attr *TmplAttr; |
10628 | LocalInstantiationScope *Scope; |
10629 | Decl *NewDecl; |
10630 | |
10631 | LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S, |
10632 | Decl *D) |
10633 | : TmplAttr(A), Scope(S), NewDecl(D) {} |
10634 | }; |
10635 | typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec; |
10636 | |
10637 | void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, |
10638 | const Decl *Pattern, Decl *Inst, |
10639 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
10640 | LocalInstantiationScope *OuterMostScope = nullptr); |
10641 | void updateAttrsForLateParsedTemplate(const Decl *Pattern, Decl *Inst); |
10642 | |
10643 | void |
10644 | InstantiateAttrsForDecl(const MultiLevelTemplateArgumentList &TemplateArgs, |
10645 | const Decl *Pattern, Decl *Inst, |
10646 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
10647 | LocalInstantiationScope *OuterMostScope = nullptr); |
10648 | |
10649 | void InstantiateDefaultCtorDefaultArgs(CXXConstructorDecl *Ctor); |
10650 | |
10651 | bool InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD, |
10652 | ParmVarDecl *Param); |
10653 | void InstantiateExceptionSpec(SourceLocation PointOfInstantiation, |
10654 | FunctionDecl *Function); |
10655 | FunctionDecl *InstantiateFunctionDeclaration( |
10656 | FunctionTemplateDecl *FTD, const TemplateArgumentList *Args, |
10657 | SourceLocation Loc, |
10658 | CodeSynthesisContext::SynthesisKind CSC = |
10659 | CodeSynthesisContext::ExplicitTemplateArgumentSubstitution); |
10660 | void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, |
10661 | FunctionDecl *Function, |
10662 | bool Recursive = false, |
10663 | bool DefinitionRequired = false, |
10664 | bool AtEndOfTU = false); |
10665 | VarTemplateSpecializationDecl *BuildVarTemplateInstantiation( |
10666 | VarTemplateDecl *VarTemplate, VarDecl *FromVar, |
10667 | const TemplateArgumentList *PartialSpecArgs, |
10668 | const TemplateArgumentListInfo &TemplateArgsInfo, |
10669 | SmallVectorImpl<TemplateArgument> &Converted, |
10670 | SourceLocation PointOfInstantiation, |
10671 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
10672 | LocalInstantiationScope *StartingScope = nullptr); |
10673 | VarTemplateSpecializationDecl *CompleteVarTemplateSpecializationDecl( |
10674 | VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl, |
10675 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10676 | void |
10677 | BuildVariableInstantiation(VarDecl *NewVar, VarDecl *OldVar, |
10678 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10679 | LateInstantiatedAttrVec *LateAttrs, |
10680 | DeclContext *Owner, |
10681 | LocalInstantiationScope *StartingScope, |
10682 | bool InstantiatingVarTemplate = false, |
10683 | VarTemplateSpecializationDecl *PrevVTSD = nullptr); |
10684 | |
10685 | void InstantiateVariableInitializer( |
10686 | VarDecl *Var, VarDecl *OldVar, |
10687 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10688 | void InstantiateVariableDefinition(SourceLocation PointOfInstantiation, |
10689 | VarDecl *Var, bool Recursive = false, |
10690 | bool DefinitionRequired = false, |
10691 | bool AtEndOfTU = false); |
10692 | |
10693 | void InstantiateMemInitializers( |
10694 | CXXConstructorDecl *New, const CXXConstructorDecl *Tmpl, |
10695 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10696 | |
10697 | NamedDecl * |
10698 | FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, |
10699 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10700 | bool FindingInstantiatedContext = false); |
10701 | DeclContext * |
10702 | FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, |
10703 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10704 | |
10705 | Decl *SubstDecl(Decl *D, DeclContext *Owner, |
10706 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10707 | |
10708 | /// Substitute the name and return type of a defaulted 'operator<=>' to form |
10709 | /// an implicit 'operator=='. |
10710 | FunctionDecl *SubstSpaceshipAsEqualEqual(CXXRecordDecl *RD, |
10711 | FunctionDecl *Spaceship); |
10712 | |
10713 | void PerformPendingInstantiations(bool LocalOnly = false); |
10714 | |
10715 | TemplateParameterList * |
10716 | SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner, |
10717 | const MultiLevelTemplateArgumentList &TemplateArgs, |
10718 | bool EvaluateConstraints = true); |
10719 | |
10720 | void PerformDependentDiagnostics( |
10721 | const DeclContext *Pattern, |
10722 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10723 | |
10724 | private: |
10725 | /// Introduce the instantiated local variables into the local |
10726 | /// instantiation scope. |
10727 | void addInstantiatedLocalVarsToScope(FunctionDecl *Function, |
10728 | const FunctionDecl *PatternDecl, |
10729 | LocalInstantiationScope &Scope); |
10730 | /// Introduce the instantiated function parameters into the local |
10731 | /// instantiation scope, and set the parameter names to those used |
10732 | /// in the template. |
10733 | bool addInstantiatedParametersToScope( |
10734 | FunctionDecl *Function, const FunctionDecl *PatternDecl, |
10735 | LocalInstantiationScope &Scope, |
10736 | const MultiLevelTemplateArgumentList &TemplateArgs); |
10737 | |
10738 | int ParsingClassDepth = 0; |
10739 | |
10740 | class SavePendingParsedClassStateRAII { |
10741 | public: |
10742 | SavePendingParsedClassStateRAII(Sema &S) : S(S) { swapSavedState(); } |
10743 | |
10744 | ~SavePendingParsedClassStateRAII() { |
10745 | assert(S.DelayedOverridingExceptionSpecChecks.empty() && |
10746 | "there shouldn't be any pending delayed exception spec checks" ); |
10747 | assert(S.DelayedEquivalentExceptionSpecChecks.empty() && |
10748 | "there shouldn't be any pending delayed exception spec checks" ); |
10749 | swapSavedState(); |
10750 | } |
10751 | |
10752 | private: |
10753 | Sema &S; |
10754 | decltype(DelayedOverridingExceptionSpecChecks) |
10755 | SavedOverridingExceptionSpecChecks; |
10756 | decltype(DelayedEquivalentExceptionSpecChecks) |
10757 | SavedEquivalentExceptionSpecChecks; |
10758 | |
10759 | void swapSavedState() { |
10760 | SavedOverridingExceptionSpecChecks.swap( |
10761 | RHS&: S.DelayedOverridingExceptionSpecChecks); |
10762 | SavedEquivalentExceptionSpecChecks.swap( |
10763 | RHS&: S.DelayedEquivalentExceptionSpecChecks); |
10764 | } |
10765 | }; |
10766 | |
10767 | ///@} |
10768 | |
10769 | // |
10770 | // |
10771 | // ------------------------------------------------------------------------- |
10772 | // |
10773 | // |
10774 | |
10775 | /// \name C++ Variadic Templates |
10776 | /// Implementations are in SemaTemplateVariadic.cpp |
10777 | ///@{ |
10778 | |
10779 | public: |
10780 | /// Determine whether an unexpanded parameter pack might be permitted in this |
10781 | /// location. Useful for error recovery. |
10782 | bool isUnexpandedParameterPackPermitted(); |
10783 | |
10784 | /// The context in which an unexpanded parameter pack is |
10785 | /// being diagnosed. |
10786 | /// |
10787 | /// Note that the values of this enumeration line up with the first |
10788 | /// argument to the \c err_unexpanded_parameter_pack diagnostic. |
10789 | enum UnexpandedParameterPackContext { |
10790 | /// An arbitrary expression. |
10791 | UPPC_Expression = 0, |
10792 | |
10793 | /// The base type of a class type. |
10794 | UPPC_BaseType, |
10795 | |
10796 | /// The type of an arbitrary declaration. |
10797 | UPPC_DeclarationType, |
10798 | |
10799 | /// The type of a data member. |
10800 | UPPC_DataMemberType, |
10801 | |
10802 | /// The size of a bit-field. |
10803 | UPPC_BitFieldWidth, |
10804 | |
10805 | /// The expression in a static assertion. |
10806 | UPPC_StaticAssertExpression, |
10807 | |
10808 | /// The fixed underlying type of an enumeration. |
10809 | UPPC_FixedUnderlyingType, |
10810 | |
10811 | /// The enumerator value. |
10812 | UPPC_EnumeratorValue, |
10813 | |
10814 | /// A using declaration. |
10815 | UPPC_UsingDeclaration, |
10816 | |
10817 | /// A friend declaration. |
10818 | UPPC_FriendDeclaration, |
10819 | |
10820 | /// A declaration qualifier. |
10821 | UPPC_DeclarationQualifier, |
10822 | |
10823 | /// An initializer. |
10824 | UPPC_Initializer, |
10825 | |
10826 | /// A default argument. |
10827 | UPPC_DefaultArgument, |
10828 | |
10829 | /// The type of a non-type template parameter. |
10830 | UPPC_NonTypeTemplateParameterType, |
10831 | |
10832 | /// The type of an exception. |
10833 | UPPC_ExceptionType, |
10834 | |
10835 | /// Explicit specialization. |
10836 | UPPC_ExplicitSpecialization, |
10837 | |
10838 | /// Partial specialization. |
10839 | UPPC_PartialSpecialization, |
10840 | |
10841 | /// Microsoft __if_exists. |
10842 | UPPC_IfExists, |
10843 | |
10844 | /// Microsoft __if_not_exists. |
10845 | UPPC_IfNotExists, |
10846 | |
10847 | /// Lambda expression. |
10848 | UPPC_Lambda, |
10849 | |
10850 | /// Block expression. |
10851 | UPPC_Block, |
10852 | |
10853 | /// A type constraint. |
10854 | UPPC_TypeConstraint, |
10855 | |
10856 | // A requirement in a requires-expression. |
10857 | UPPC_Requirement, |
10858 | |
10859 | // A requires-clause. |
10860 | UPPC_RequiresClause, |
10861 | }; |
10862 | |
10863 | /// Diagnose unexpanded parameter packs. |
10864 | /// |
10865 | /// \param Loc The location at which we should emit the diagnostic. |
10866 | /// |
10867 | /// \param UPPC The context in which we are diagnosing unexpanded |
10868 | /// parameter packs. |
10869 | /// |
10870 | /// \param Unexpanded the set of unexpanded parameter packs. |
10871 | /// |
10872 | /// \returns true if an error occurred, false otherwise. |
10873 | bool DiagnoseUnexpandedParameterPacks( |
10874 | SourceLocation Loc, UnexpandedParameterPackContext UPPC, |
10875 | ArrayRef<UnexpandedParameterPack> Unexpanded); |
10876 | |
10877 | /// If the given type contains an unexpanded parameter pack, |
10878 | /// diagnose the error. |
10879 | /// |
10880 | /// \param Loc The source location where a diagnostc should be emitted. |
10881 | /// |
10882 | /// \param T The type that is being checked for unexpanded parameter |
10883 | /// packs. |
10884 | /// |
10885 | /// \returns true if an error occurred, false otherwise. |
10886 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, |
10887 | UnexpandedParameterPackContext UPPC); |
10888 | |
10889 | /// If the given expression contains an unexpanded parameter |
10890 | /// pack, diagnose the error. |
10891 | /// |
10892 | /// \param E The expression that is being checked for unexpanded |
10893 | /// parameter packs. |
10894 | /// |
10895 | /// \returns true if an error occurred, false otherwise. |
10896 | bool DiagnoseUnexpandedParameterPack( |
10897 | Expr *E, UnexpandedParameterPackContext UPPC = UPPC_Expression); |
10898 | |
10899 | /// If the given requirees-expression contains an unexpanded reference to one |
10900 | /// of its own parameter packs, diagnose the error. |
10901 | /// |
10902 | /// \param RE The requiress-expression that is being checked for unexpanded |
10903 | /// parameter packs. |
10904 | /// |
10905 | /// \returns true if an error occurred, false otherwise. |
10906 | bool DiagnoseUnexpandedParameterPackInRequiresExpr(RequiresExpr *RE); |
10907 | |
10908 | /// If the given nested-name-specifier contains an unexpanded |
10909 | /// parameter pack, diagnose the error. |
10910 | /// |
10911 | /// \param SS The nested-name-specifier that is being checked for |
10912 | /// unexpanded parameter packs. |
10913 | /// |
10914 | /// \returns true if an error occurred, false otherwise. |
10915 | bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, |
10916 | UnexpandedParameterPackContext UPPC); |
10917 | |
10918 | /// If the given name contains an unexpanded parameter pack, |
10919 | /// diagnose the error. |
10920 | /// |
10921 | /// \param NameInfo The name (with source location information) that |
10922 | /// is being checked for unexpanded parameter packs. |
10923 | /// |
10924 | /// \returns true if an error occurred, false otherwise. |
10925 | bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, |
10926 | UnexpandedParameterPackContext UPPC); |
10927 | |
10928 | /// If the given template name contains an unexpanded parameter pack, |
10929 | /// diagnose the error. |
10930 | /// |
10931 | /// \param Loc The location of the template name. |
10932 | /// |
10933 | /// \param Template The template name that is being checked for unexpanded |
10934 | /// parameter packs. |
10935 | /// |
10936 | /// \returns true if an error occurred, false otherwise. |
10937 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, |
10938 | TemplateName Template, |
10939 | UnexpandedParameterPackContext UPPC); |
10940 | |
10941 | /// If the given template argument contains an unexpanded parameter |
10942 | /// pack, diagnose the error. |
10943 | /// |
10944 | /// \param Arg The template argument that is being checked for unexpanded |
10945 | /// parameter packs. |
10946 | /// |
10947 | /// \returns true if an error occurred, false otherwise. |
10948 | bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, |
10949 | UnexpandedParameterPackContext UPPC); |
10950 | |
10951 | /// Collect the set of unexpanded parameter packs within the given |
10952 | /// template argument. |
10953 | /// |
10954 | /// \param Arg The template argument that will be traversed to find |
10955 | /// unexpanded parameter packs. |
10956 | void collectUnexpandedParameterPacks( |
10957 | TemplateArgument Arg, |
10958 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
10959 | |
10960 | /// Collect the set of unexpanded parameter packs within the given |
10961 | /// template argument. |
10962 | /// |
10963 | /// \param Arg The template argument that will be traversed to find |
10964 | /// unexpanded parameter packs. |
10965 | void collectUnexpandedParameterPacks( |
10966 | TemplateArgumentLoc Arg, |
10967 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
10968 | |
10969 | /// Collect the set of unexpanded parameter packs within the given |
10970 | /// type. |
10971 | /// |
10972 | /// \param T The type that will be traversed to find |
10973 | /// unexpanded parameter packs. |
10974 | void collectUnexpandedParameterPacks( |
10975 | QualType T, SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
10976 | |
10977 | /// Collect the set of unexpanded parameter packs within the given |
10978 | /// type. |
10979 | /// |
10980 | /// \param TL The type that will be traversed to find |
10981 | /// unexpanded parameter packs. |
10982 | void collectUnexpandedParameterPacks( |
10983 | TypeLoc TL, SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
10984 | |
10985 | /// Collect the set of unexpanded parameter packs within the given |
10986 | /// nested-name-specifier. |
10987 | /// |
10988 | /// \param NNS The nested-name-specifier that will be traversed to find |
10989 | /// unexpanded parameter packs. |
10990 | void collectUnexpandedParameterPacks( |
10991 | NestedNameSpecifierLoc NNS, |
10992 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
10993 | |
10994 | /// Collect the set of unexpanded parameter packs within the given |
10995 | /// name. |
10996 | /// |
10997 | /// \param NameInfo The name that will be traversed to find |
10998 | /// unexpanded parameter packs. |
10999 | void collectUnexpandedParameterPacks( |
11000 | const DeclarationNameInfo &NameInfo, |
11001 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
11002 | |
11003 | /// Invoked when parsing a template argument followed by an |
11004 | /// ellipsis, which creates a pack expansion. |
11005 | /// |
11006 | /// \param Arg The template argument preceding the ellipsis, which |
11007 | /// may already be invalid. |
11008 | /// |
11009 | /// \param EllipsisLoc The location of the ellipsis. |
11010 | ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, |
11011 | SourceLocation EllipsisLoc); |
11012 | |
11013 | /// Invoked when parsing a type followed by an ellipsis, which |
11014 | /// creates a pack expansion. |
11015 | /// |
11016 | /// \param Type The type preceding the ellipsis, which will become |
11017 | /// the pattern of the pack expansion. |
11018 | /// |
11019 | /// \param EllipsisLoc The location of the ellipsis. |
11020 | TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); |
11021 | |
11022 | /// Construct a pack expansion type from the pattern of the pack |
11023 | /// expansion. |
11024 | TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, |
11025 | SourceLocation EllipsisLoc, |
11026 | std::optional<unsigned> NumExpansions); |
11027 | |
11028 | /// Construct a pack expansion type from the pattern of the pack |
11029 | /// expansion. |
11030 | QualType CheckPackExpansion(QualType Pattern, SourceRange PatternRange, |
11031 | SourceLocation EllipsisLoc, |
11032 | std::optional<unsigned> NumExpansions); |
11033 | |
11034 | /// Invoked when parsing an expression followed by an ellipsis, which |
11035 | /// creates a pack expansion. |
11036 | /// |
11037 | /// \param Pattern The expression preceding the ellipsis, which will become |
11038 | /// the pattern of the pack expansion. |
11039 | /// |
11040 | /// \param EllipsisLoc The location of the ellipsis. |
11041 | ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); |
11042 | |
11043 | /// Invoked when parsing an expression followed by an ellipsis, which |
11044 | /// creates a pack expansion. |
11045 | /// |
11046 | /// \param Pattern The expression preceding the ellipsis, which will become |
11047 | /// the pattern of the pack expansion. |
11048 | /// |
11049 | /// \param EllipsisLoc The location of the ellipsis. |
11050 | ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
11051 | std::optional<unsigned> NumExpansions); |
11052 | |
11053 | /// Determine whether we could expand a pack expansion with the |
11054 | /// given set of parameter packs into separate arguments by repeatedly |
11055 | /// transforming the pattern. |
11056 | /// |
11057 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
11058 | /// pack expansion. |
11059 | /// |
11060 | /// \param PatternRange The source range that covers the entire pattern of |
11061 | /// the pack expansion. |
11062 | /// |
11063 | /// \param Unexpanded The set of unexpanded parameter packs within the |
11064 | /// pattern. |
11065 | /// |
11066 | /// \param ShouldExpand Will be set to \c true if the transformer should |
11067 | /// expand the corresponding pack expansions into separate arguments. When |
11068 | /// set, \c NumExpansions must also be set. |
11069 | /// |
11070 | /// \param RetainExpansion Whether the caller should add an unexpanded |
11071 | /// pack expansion after all of the expanded arguments. This is used |
11072 | /// when extending explicitly-specified template argument packs per |
11073 | /// C++0x [temp.arg.explicit]p9. |
11074 | /// |
11075 | /// \param NumExpansions The number of separate arguments that will be in |
11076 | /// the expanded form of the corresponding pack expansion. This is both an |
11077 | /// input and an output parameter, which can be set by the caller if the |
11078 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
11079 | /// and will be set by the callee when the number of expansions is known. |
11080 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
11081 | /// set this value in other cases. |
11082 | /// |
11083 | /// \returns true if an error occurred (e.g., because the parameter packs |
11084 | /// are to be instantiated with arguments of different lengths), false |
11085 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
11086 | /// must be set. |
11087 | bool CheckParameterPacksForExpansion( |
11088 | SourceLocation EllipsisLoc, SourceRange PatternRange, |
11089 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
11090 | const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand, |
11091 | bool &RetainExpansion, std::optional<unsigned> &NumExpansions); |
11092 | |
11093 | /// Determine the number of arguments in the given pack expansion |
11094 | /// type. |
11095 | /// |
11096 | /// This routine assumes that the number of arguments in the expansion is |
11097 | /// consistent across all of the unexpanded parameter packs in its pattern. |
11098 | /// |
11099 | /// Returns an empty Optional if the type can't be expanded. |
11100 | std::optional<unsigned> getNumArgumentsInExpansion( |
11101 | QualType T, const MultiLevelTemplateArgumentList &TemplateArgs); |
11102 | |
11103 | /// Determine whether the given declarator contains any unexpanded |
11104 | /// parameter packs. |
11105 | /// |
11106 | /// This routine is used by the parser to disambiguate function declarators |
11107 | /// with an ellipsis prior to the ')', e.g., |
11108 | /// |
11109 | /// \code |
11110 | /// void f(T...); |
11111 | /// \endcode |
11112 | /// |
11113 | /// To determine whether we have an (unnamed) function parameter pack or |
11114 | /// a variadic function. |
11115 | /// |
11116 | /// \returns true if the declarator contains any unexpanded parameter packs, |
11117 | /// false otherwise. |
11118 | bool containsUnexpandedParameterPacks(Declarator &D); |
11119 | |
11120 | /// Returns the pattern of the pack expansion for a template argument. |
11121 | /// |
11122 | /// \param OrigLoc The template argument to expand. |
11123 | /// |
11124 | /// \param Ellipsis Will be set to the location of the ellipsis. |
11125 | /// |
11126 | /// \param NumExpansions Will be set to the number of expansions that will |
11127 | /// be generated from this pack expansion, if known a priori. |
11128 | TemplateArgumentLoc getTemplateArgumentPackExpansionPattern( |
11129 | TemplateArgumentLoc OrigLoc, SourceLocation &Ellipsis, |
11130 | std::optional<unsigned> &NumExpansions) const; |
11131 | |
11132 | /// Given a template argument that contains an unexpanded parameter pack, but |
11133 | /// which has already been substituted, attempt to determine the number of |
11134 | /// elements that will be produced once this argument is fully-expanded. |
11135 | /// |
11136 | /// This is intended for use when transforming 'sizeof...(Arg)' in order to |
11137 | /// avoid actually expanding the pack where possible. |
11138 | std::optional<unsigned> getFullyPackExpandedSize(TemplateArgument Arg); |
11139 | |
11140 | ExprResult ActOnSizeofParameterPackExpr(Scope *S, SourceLocation OpLoc, |
11141 | IdentifierInfo &Name, |
11142 | SourceLocation NameLoc, |
11143 | SourceLocation RParenLoc); |
11144 | |
11145 | ExprResult ActOnPackIndexingExpr(Scope *S, Expr *PackExpression, |
11146 | SourceLocation EllipsisLoc, |
11147 | SourceLocation LSquareLoc, Expr *IndexExpr, |
11148 | SourceLocation RSquareLoc); |
11149 | |
11150 | ExprResult BuildPackIndexingExpr(Expr *PackExpression, |
11151 | SourceLocation EllipsisLoc, Expr *IndexExpr, |
11152 | SourceLocation RSquareLoc, |
11153 | ArrayRef<Expr *> ExpandedExprs = {}, |
11154 | bool EmptyPack = false); |
11155 | |
11156 | /// Handle a C++1z fold-expression: ( expr op ... op expr ). |
11157 | ExprResult ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS, |
11158 | tok::TokenKind Operator, |
11159 | SourceLocation EllipsisLoc, Expr *RHS, |
11160 | SourceLocation RParenLoc); |
11161 | ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, |
11162 | SourceLocation LParenLoc, Expr *LHS, |
11163 | BinaryOperatorKind Operator, |
11164 | SourceLocation EllipsisLoc, Expr *RHS, |
11165 | SourceLocation RParenLoc, |
11166 | std::optional<unsigned> NumExpansions); |
11167 | ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
11168 | BinaryOperatorKind Operator); |
11169 | |
11170 | ///@} |
11171 | |
11172 | // |
11173 | // |
11174 | // ------------------------------------------------------------------------- |
11175 | // |
11176 | // |
11177 | |
11178 | /// \name Constraints and Concepts |
11179 | /// Implementations are in SemaConcept.cpp |
11180 | ///@{ |
11181 | |
11182 | public: |
11183 | void PushSatisfactionStackEntry(const NamedDecl *D, |
11184 | const llvm::FoldingSetNodeID &ID) { |
11185 | const NamedDecl *Can = cast<NamedDecl>(D->getCanonicalDecl()); |
11186 | SatisfactionStack.emplace_back(Args&: Can, Args: ID); |
11187 | } |
11188 | |
11189 | void PopSatisfactionStackEntry() { SatisfactionStack.pop_back(); } |
11190 | |
11191 | bool SatisfactionStackContains(const NamedDecl *D, |
11192 | const llvm::FoldingSetNodeID &ID) const { |
11193 | const NamedDecl *Can = cast<NamedDecl>(D->getCanonicalDecl()); |
11194 | return llvm::find(Range: SatisfactionStack, Val: SatisfactionStackEntryTy{Can, ID}) != |
11195 | SatisfactionStack.end(); |
11196 | } |
11197 | |
11198 | using SatisfactionStackEntryTy = |
11199 | std::pair<const NamedDecl *, llvm::FoldingSetNodeID>; |
11200 | |
11201 | // Resets the current SatisfactionStack for cases where we are instantiating |
11202 | // constraints as a 'side effect' of normal instantiation in a way that is not |
11203 | // indicative of recursive definition. |
11204 | class SatisfactionStackResetRAII { |
11205 | llvm::SmallVector<SatisfactionStackEntryTy, 10> BackupSatisfactionStack; |
11206 | Sema &SemaRef; |
11207 | |
11208 | public: |
11209 | SatisfactionStackResetRAII(Sema &S) : SemaRef(S) { |
11210 | SemaRef.SwapSatisfactionStack(NewSS&: BackupSatisfactionStack); |
11211 | } |
11212 | |
11213 | ~SatisfactionStackResetRAII() { |
11214 | SemaRef.SwapSatisfactionStack(NewSS&: BackupSatisfactionStack); |
11215 | } |
11216 | }; |
11217 | |
11218 | void SwapSatisfactionStack( |
11219 | llvm::SmallVectorImpl<SatisfactionStackEntryTy> &NewSS) { |
11220 | SatisfactionStack.swap(RHS&: NewSS); |
11221 | } |
11222 | |
11223 | /// Check whether the given expression is a valid constraint expression. |
11224 | /// A diagnostic is emitted if it is not, false is returned, and |
11225 | /// PossibleNonPrimary will be set to true if the failure might be due to a |
11226 | /// non-primary expression being used as an atomic constraint. |
11227 | bool CheckConstraintExpression(const Expr *CE, Token NextToken = Token(), |
11228 | bool *PossibleNonPrimary = nullptr, |
11229 | bool IsTrailingRequiresClause = false); |
11230 | |
11231 | /// \brief Check whether the given list of constraint expressions are |
11232 | /// satisfied (as if in a 'conjunction') given template arguments. |
11233 | /// \param Template the template-like entity that triggered the constraints |
11234 | /// check (either a concept or a constrained entity). |
11235 | /// \param ConstraintExprs a list of constraint expressions, treated as if |
11236 | /// they were 'AND'ed together. |
11237 | /// \param TemplateArgLists the list of template arguments to substitute into |
11238 | /// the constraint expression. |
11239 | /// \param TemplateIDRange The source range of the template id that |
11240 | /// caused the constraints check. |
11241 | /// \param Satisfaction if true is returned, will contain details of the |
11242 | /// satisfaction, with enough information to diagnose an unsatisfied |
11243 | /// expression. |
11244 | /// \returns true if an error occurred and satisfaction could not be checked, |
11245 | /// false otherwise. |
11246 | bool CheckConstraintSatisfaction( |
11247 | const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs, |
11248 | const MultiLevelTemplateArgumentList &TemplateArgLists, |
11249 | SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction) { |
11250 | llvm::SmallVector<Expr *, 4> Converted; |
11251 | return CheckConstraintSatisfaction(Template, ConstraintExprs, ConvertedConstraints&: Converted, |
11252 | TemplateArgList: TemplateArgLists, TemplateIDRange, |
11253 | Satisfaction); |
11254 | } |
11255 | |
11256 | /// \brief Check whether the given list of constraint expressions are |
11257 | /// satisfied (as if in a 'conjunction') given template arguments. |
11258 | /// Additionally, takes an empty list of Expressions which is populated with |
11259 | /// the instantiated versions of the ConstraintExprs. |
11260 | /// \param Template the template-like entity that triggered the constraints |
11261 | /// check (either a concept or a constrained entity). |
11262 | /// \param ConstraintExprs a list of constraint expressions, treated as if |
11263 | /// they were 'AND'ed together. |
11264 | /// \param ConvertedConstraints a out parameter that will get populated with |
11265 | /// the instantiated version of the ConstraintExprs if we successfully checked |
11266 | /// satisfaction. |
11267 | /// \param TemplateArgList the multi-level list of template arguments to |
11268 | /// substitute into the constraint expression. This should be relative to the |
11269 | /// top-level (hence multi-level), since we need to instantiate fully at the |
11270 | /// time of checking. |
11271 | /// \param TemplateIDRange The source range of the template id that |
11272 | /// caused the constraints check. |
11273 | /// \param Satisfaction if true is returned, will contain details of the |
11274 | /// satisfaction, with enough information to diagnose an unsatisfied |
11275 | /// expression. |
11276 | /// \returns true if an error occurred and satisfaction could not be checked, |
11277 | /// false otherwise. |
11278 | bool CheckConstraintSatisfaction( |
11279 | const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs, |
11280 | llvm::SmallVectorImpl<Expr *> &ConvertedConstraints, |
11281 | const MultiLevelTemplateArgumentList &TemplateArgList, |
11282 | SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction); |
11283 | |
11284 | /// \brief Check whether the given non-dependent constraint expression is |
11285 | /// satisfied. Returns false and updates Satisfaction with the satisfaction |
11286 | /// verdict if successful, emits a diagnostic and returns true if an error |
11287 | /// occurred and satisfaction could not be determined. |
11288 | /// |
11289 | /// \returns true if an error occurred, false otherwise. |
11290 | bool CheckConstraintSatisfaction(const Expr *ConstraintExpr, |
11291 | ConstraintSatisfaction &Satisfaction); |
11292 | |
11293 | /// Check whether the given function decl's trailing requires clause is |
11294 | /// satisfied, if any. Returns false and updates Satisfaction with the |
11295 | /// satisfaction verdict if successful, emits a diagnostic and returns true if |
11296 | /// an error occurred and satisfaction could not be determined. |
11297 | /// |
11298 | /// \returns true if an error occurred, false otherwise. |
11299 | bool CheckFunctionConstraints(const FunctionDecl *FD, |
11300 | ConstraintSatisfaction &Satisfaction, |
11301 | SourceLocation UsageLoc = SourceLocation(), |
11302 | bool ForOverloadResolution = false); |
11303 | |
11304 | // Calculates whether two constraint expressions are equal irrespective of a |
11305 | // difference in 'depth'. This takes a pair of optional 'NamedDecl's 'Old' and |
11306 | // 'New', which are the "source" of the constraint, since this is necessary |
11307 | // for figuring out the relative 'depth' of the constraint. The depth of the |
11308 | // 'primary template' and the 'instantiated from' templates aren't necessarily |
11309 | // the same, such as a case when one is a 'friend' defined in a class. |
11310 | bool AreConstraintExpressionsEqual(const NamedDecl *Old, |
11311 | const Expr *OldConstr, |
11312 | const TemplateCompareNewDeclInfo &New, |
11313 | const Expr *NewConstr); |
11314 | |
11315 | // Calculates whether the friend function depends on an enclosing template for |
11316 | // the purposes of [temp.friend] p9. |
11317 | bool FriendConstraintsDependOnEnclosingTemplate(const FunctionDecl *FD); |
11318 | |
11319 | /// \brief Ensure that the given template arguments satisfy the constraints |
11320 | /// associated with the given template, emitting a diagnostic if they do not. |
11321 | /// |
11322 | /// \param Template The template to which the template arguments are being |
11323 | /// provided. |
11324 | /// |
11325 | /// \param TemplateArgs The converted, canonicalized template arguments. |
11326 | /// |
11327 | /// \param TemplateIDRange The source range of the template id that |
11328 | /// caused the constraints check. |
11329 | /// |
11330 | /// \returns true if the constrains are not satisfied or could not be checked |
11331 | /// for satisfaction, false if the constraints are satisfied. |
11332 | bool EnsureTemplateArgumentListConstraints( |
11333 | TemplateDecl *Template, |
11334 | const MultiLevelTemplateArgumentList &TemplateArgs, |
11335 | SourceRange TemplateIDRange); |
11336 | |
11337 | bool CheckInstantiatedFunctionTemplateConstraints( |
11338 | SourceLocation PointOfInstantiation, FunctionDecl *Decl, |
11339 | ArrayRef<TemplateArgument> TemplateArgs, |
11340 | ConstraintSatisfaction &Satisfaction); |
11341 | |
11342 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
11343 | /// unsatisfied. |
11344 | /// \param First whether this is the first time an unsatisfied constraint is |
11345 | /// diagnosed for this error. |
11346 | void DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction &Satisfaction, |
11347 | bool First = true); |
11348 | |
11349 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
11350 | /// unsatisfied. |
11351 | void |
11352 | DiagnoseUnsatisfiedConstraint(const ASTConstraintSatisfaction &Satisfaction, |
11353 | bool First = true); |
11354 | |
11355 | const NormalizedConstraint *getNormalizedAssociatedConstraints( |
11356 | NamedDecl *ConstrainedDecl, ArrayRef<const Expr *> AssociatedConstraints); |
11357 | |
11358 | /// \brief Check whether the given declaration's associated constraints are |
11359 | /// at least as constrained than another declaration's according to the |
11360 | /// partial ordering of constraints. |
11361 | /// |
11362 | /// \param Result If no error occurred, receives the result of true if D1 is |
11363 | /// at least constrained than D2, and false otherwise. |
11364 | /// |
11365 | /// \returns true if an error occurred, false otherwise. |
11366 | bool IsAtLeastAsConstrained(NamedDecl *D1, MutableArrayRef<const Expr *> AC1, |
11367 | NamedDecl *D2, MutableArrayRef<const Expr *> AC2, |
11368 | bool &Result); |
11369 | |
11370 | /// If D1 was not at least as constrained as D2, but would've been if a pair |
11371 | /// of atomic constraints involved had been declared in a concept and not |
11372 | /// repeated in two separate places in code. |
11373 | /// \returns true if such a diagnostic was emitted, false otherwise. |
11374 | bool MaybeEmitAmbiguousAtomicConstraintsDiagnostic( |
11375 | NamedDecl *D1, ArrayRef<const Expr *> AC1, NamedDecl *D2, |
11376 | ArrayRef<const Expr *> AC2); |
11377 | |
11378 | private: |
11379 | /// Caches pairs of template-like decls whose associated constraints were |
11380 | /// checked for subsumption and whether or not the first's constraints did in |
11381 | /// fact subsume the second's. |
11382 | llvm::DenseMap<std::pair<NamedDecl *, NamedDecl *>, bool> SubsumptionCache; |
11383 | /// Caches the normalized associated constraints of declarations (concepts or |
11384 | /// constrained declarations). If an error occurred while normalizing the |
11385 | /// associated constraints of the template or concept, nullptr will be cached |
11386 | /// here. |
11387 | llvm::DenseMap<NamedDecl *, NormalizedConstraint *> NormalizationCache; |
11388 | |
11389 | llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &> |
11390 | SatisfactionCache; |
11391 | |
11392 | // The current stack of constraint satisfactions, so we can exit-early. |
11393 | llvm::SmallVector<SatisfactionStackEntryTy, 10> SatisfactionStack; |
11394 | |
11395 | /// Introduce the instantiated captures of the lambda into the local |
11396 | /// instantiation scope. |
11397 | bool addInstantiatedCapturesToScope( |
11398 | FunctionDecl *Function, const FunctionDecl *PatternDecl, |
11399 | LocalInstantiationScope &Scope, |
11400 | const MultiLevelTemplateArgumentList &TemplateArgs); |
11401 | |
11402 | /// Used by SetupConstraintCheckingTemplateArgumentsAndScope to recursively(in |
11403 | /// the case of lambdas) set up the LocalInstantiationScope of the current |
11404 | /// function. |
11405 | bool |
11406 | SetupConstraintScope(FunctionDecl *FD, |
11407 | std::optional<ArrayRef<TemplateArgument>> TemplateArgs, |
11408 | const MultiLevelTemplateArgumentList &MLTAL, |
11409 | LocalInstantiationScope &Scope); |
11410 | |
11411 | /// Used during constraint checking, sets up the constraint template argument |
11412 | /// lists, and calls SetupConstraintScope to set up the |
11413 | /// LocalInstantiationScope to have the proper set of ParVarDecls configured. |
11414 | std::optional<MultiLevelTemplateArgumentList> |
11415 | SetupConstraintCheckingTemplateArgumentsAndScope( |
11416 | FunctionDecl *FD, std::optional<ArrayRef<TemplateArgument>> TemplateArgs, |
11417 | LocalInstantiationScope &Scope); |
11418 | |
11419 | ///@} |
11420 | |
11421 | // |
11422 | // |
11423 | // ------------------------------------------------------------------------- |
11424 | // |
11425 | // |
11426 | |
11427 | /// \name Types |
11428 | /// Implementations are in SemaType.cpp |
11429 | ///@{ |
11430 | |
11431 | public: |
11432 | /// A mapping that describes the nullability we've seen in each header file. |
11433 | FileNullabilityMap NullabilityMap; |
11434 | |
11435 | static int getPrintable(int I) { return I; } |
11436 | static unsigned getPrintable(unsigned I) { return I; } |
11437 | static bool getPrintable(bool B) { return B; } |
11438 | static const char *getPrintable(const char *S) { return S; } |
11439 | static StringRef getPrintable(StringRef S) { return S; } |
11440 | static const std::string &getPrintable(const std::string &S) { return S; } |
11441 | static const IdentifierInfo *getPrintable(const IdentifierInfo *II) { |
11442 | return II; |
11443 | } |
11444 | static DeclarationName getPrintable(DeclarationName N) { return N; } |
11445 | static QualType getPrintable(QualType T) { return T; } |
11446 | static SourceRange getPrintable(SourceRange R) { return R; } |
11447 | static SourceRange getPrintable(SourceLocation L) { return L; } |
11448 | static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); } |
11449 | static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange(); } |
11450 | |
11451 | enum class CompleteTypeKind { |
11452 | /// Apply the normal rules for complete types. In particular, |
11453 | /// treat all sizeless types as incomplete. |
11454 | Normal, |
11455 | |
11456 | /// Relax the normal rules for complete types so that they include |
11457 | /// sizeless built-in types. |
11458 | AcceptSizeless, |
11459 | |
11460 | // FIXME: Eventually we should flip the default to Normal and opt in |
11461 | // to AcceptSizeless rather than opt out of it. |
11462 | Default = AcceptSizeless |
11463 | }; |
11464 | |
11465 | /// Build a an Objective-C protocol-qualified 'id' type where no |
11466 | /// base type was specified. |
11467 | TypeResult actOnObjCProtocolQualifierType( |
11468 | SourceLocation lAngleLoc, ArrayRef<Decl *> protocols, |
11469 | ArrayRef<SourceLocation> protocolLocs, SourceLocation rAngleLoc); |
11470 | |
11471 | /// Build a specialized and/or protocol-qualified Objective-C type. |
11472 | TypeResult actOnObjCTypeArgsAndProtocolQualifiers( |
11473 | Scope *S, SourceLocation Loc, ParsedType BaseType, |
11474 | SourceLocation TypeArgsLAngleLoc, ArrayRef<ParsedType> TypeArgs, |
11475 | SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, |
11476 | ArrayRef<Decl *> Protocols, ArrayRef<SourceLocation> ProtocolLocs, |
11477 | SourceLocation ProtocolRAngleLoc); |
11478 | |
11479 | /// Build an Objective-C type parameter type. |
11480 | QualType BuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, |
11481 | SourceLocation ProtocolLAngleLoc, |
11482 | ArrayRef<ObjCProtocolDecl *> Protocols, |
11483 | ArrayRef<SourceLocation> ProtocolLocs, |
11484 | SourceLocation ProtocolRAngleLoc, |
11485 | bool FailOnError = false); |
11486 | |
11487 | /// Build an Objective-C object pointer type. |
11488 | QualType BuildObjCObjectType( |
11489 | QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, |
11490 | ArrayRef<TypeSourceInfo *> TypeArgs, SourceLocation TypeArgsRAngleLoc, |
11491 | SourceLocation ProtocolLAngleLoc, ArrayRef<ObjCProtocolDecl *> Protocols, |
11492 | ArrayRef<SourceLocation> ProtocolLocs, SourceLocation ProtocolRAngleLoc, |
11493 | bool FailOnError, bool Rebuilding); |
11494 | |
11495 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, |
11496 | const DeclSpec *DS = nullptr); |
11497 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA, |
11498 | const DeclSpec *DS = nullptr); |
11499 | QualType BuildPointerType(QualType T, SourceLocation Loc, |
11500 | DeclarationName Entity); |
11501 | QualType BuildReferenceType(QualType T, bool LValueRef, SourceLocation Loc, |
11502 | DeclarationName Entity); |
11503 | QualType BuildArrayType(QualType T, ArraySizeModifier ASM, Expr *ArraySize, |
11504 | unsigned Quals, SourceRange Brackets, |
11505 | DeclarationName Entity); |
11506 | QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc); |
11507 | QualType BuildExtVectorType(QualType T, Expr *ArraySize, |
11508 | SourceLocation AttrLoc); |
11509 | QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, |
11510 | SourceLocation AttrLoc); |
11511 | |
11512 | QualType BuildCountAttributedArrayType(QualType WrappedTy, Expr *CountExpr); |
11513 | |
11514 | QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace, |
11515 | SourceLocation AttrLoc); |
11516 | |
11517 | /// Same as above, but constructs the AddressSpace index if not provided. |
11518 | QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace, |
11519 | SourceLocation AttrLoc); |
11520 | |
11521 | bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc); |
11522 | |
11523 | bool CheckFunctionReturnType(QualType T, SourceLocation Loc); |
11524 | |
11525 | /// Build a function type. |
11526 | /// |
11527 | /// This routine checks the function type according to C++ rules and |
11528 | /// under the assumption that the result type and parameter types have |
11529 | /// just been instantiated from a template. It therefore duplicates |
11530 | /// some of the behavior of GetTypeForDeclarator, but in a much |
11531 | /// simpler form that is only suitable for this narrow use case. |
11532 | /// |
11533 | /// \param T The return type of the function. |
11534 | /// |
11535 | /// \param ParamTypes The parameter types of the function. This array |
11536 | /// will be modified to account for adjustments to the types of the |
11537 | /// function parameters. |
11538 | /// |
11539 | /// \param Loc The location of the entity whose type involves this |
11540 | /// function type or, if there is no such entity, the location of the |
11541 | /// type that will have function type. |
11542 | /// |
11543 | /// \param Entity The name of the entity that involves the function |
11544 | /// type, if known. |
11545 | /// |
11546 | /// \param EPI Extra information about the function type. Usually this will |
11547 | /// be taken from an existing function with the same prototype. |
11548 | /// |
11549 | /// \returns A suitable function type, if there are no errors. The |
11550 | /// unqualified type will always be a FunctionProtoType. |
11551 | /// Otherwise, returns a NULL type. |
11552 | QualType BuildFunctionType(QualType T, MutableArrayRef<QualType> ParamTypes, |
11553 | SourceLocation Loc, DeclarationName Entity, |
11554 | const FunctionProtoType::ExtProtoInfo &EPI); |
11555 | |
11556 | QualType BuildMemberPointerType(QualType T, QualType Class, |
11557 | SourceLocation Loc, DeclarationName Entity); |
11558 | QualType BuildBlockPointerType(QualType T, SourceLocation Loc, |
11559 | DeclarationName Entity); |
11560 | QualType BuildParenType(QualType T); |
11561 | QualType BuildAtomicType(QualType T, SourceLocation Loc); |
11562 | QualType BuildReadPipeType(QualType T, SourceLocation Loc); |
11563 | QualType BuildWritePipeType(QualType T, SourceLocation Loc); |
11564 | QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc); |
11565 | |
11566 | TypeSourceInfo *GetTypeForDeclarator(Declarator &D); |
11567 | TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy); |
11568 | |
11569 | /// Package the given type and TSI into a ParsedType. |
11570 | ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo); |
11571 | static QualType GetTypeFromParser(ParsedType Ty, |
11572 | TypeSourceInfo **TInfo = nullptr); |
11573 | |
11574 | TypeResult ActOnTypeName(Declarator &D); |
11575 | |
11576 | /// The parser has parsed the context-sensitive type 'instancetype' |
11577 | /// in an Objective-C message declaration. Return the appropriate type. |
11578 | ParsedType ActOnObjCInstanceType(SourceLocation Loc); |
11579 | |
11580 | // Check whether the size of array element of type \p EltTy is a multiple of |
11581 | // its alignment and return false if it isn't. |
11582 | bool checkArrayElementAlignment(QualType EltTy, SourceLocation Loc); |
11583 | |
11584 | void |
11585 | diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals, |
11586 | SourceLocation FallbackLoc, |
11587 | SourceLocation ConstQualLoc = SourceLocation(), |
11588 | SourceLocation VolatileQualLoc = SourceLocation(), |
11589 | SourceLocation RestrictQualLoc = SourceLocation(), |
11590 | SourceLocation AtomicQualLoc = SourceLocation(), |
11591 | SourceLocation UnalignedQualLoc = SourceLocation()); |
11592 | |
11593 | /// Retrieve the keyword associated |
11594 | IdentifierInfo *getNullabilityKeyword(NullabilityKind nullability); |
11595 | |
11596 | /// The struct behind the CFErrorRef pointer. |
11597 | RecordDecl *CFError = nullptr; |
11598 | bool isCFError(RecordDecl *D); |
11599 | |
11600 | /// Retrieve the identifier "NSError". |
11601 | IdentifierInfo *getNSErrorIdent(); |
11602 | |
11603 | /// Adjust the calling convention of a method to be the ABI default if it |
11604 | /// wasn't specified explicitly. This handles method types formed from |
11605 | /// function type typedefs and typename template arguments. |
11606 | void adjustMemberFunctionCC(QualType &T, bool HasThisPointer, |
11607 | bool IsCtorOrDtor, SourceLocation Loc); |
11608 | |
11609 | // Check if there is an explicit attribute, but only look through parens. |
11610 | // The intent is to look for an attribute on the current declarator, but not |
11611 | // one that came from a typedef. |
11612 | bool hasExplicitCallingConv(QualType T); |
11613 | |
11614 | /// Check whether a nullability type specifier can be added to the given |
11615 | /// type through some means not written in source (e.g. API notes). |
11616 | /// |
11617 | /// \param Type The type to which the nullability specifier will be |
11618 | /// added. On success, this type will be updated appropriately. |
11619 | /// |
11620 | /// \param Nullability The nullability specifier to add. |
11621 | /// |
11622 | /// \param DiagLoc The location to use for diagnostics. |
11623 | /// |
11624 | /// \param AllowArrayTypes Whether to accept nullability specifiers on an |
11625 | /// array type (e.g., because it will decay to a pointer). |
11626 | /// |
11627 | /// \param OverrideExisting Whether to override an existing, locally-specified |
11628 | /// nullability specifier rather than complaining about the conflict. |
11629 | /// |
11630 | /// \returns true if nullability cannot be applied, false otherwise. |
11631 | bool CheckImplicitNullabilityTypeSpecifier(QualType &Type, |
11632 | NullabilityKind Nullability, |
11633 | SourceLocation DiagLoc, |
11634 | bool AllowArrayTypes, |
11635 | bool OverrideExisting); |
11636 | |
11637 | /// Get the type of expression E, triggering instantiation to complete the |
11638 | /// type if necessary -- that is, if the expression refers to a templated |
11639 | /// static data member of incomplete array type. |
11640 | /// |
11641 | /// May still return an incomplete type if instantiation was not possible or |
11642 | /// if the type is incomplete for a different reason. Use |
11643 | /// RequireCompleteExprType instead if a diagnostic is expected for an |
11644 | /// incomplete expression type. |
11645 | QualType getCompletedType(Expr *E); |
11646 | |
11647 | void completeExprArrayBound(Expr *E); |
11648 | bool RequireCompleteExprType(Expr *E, CompleteTypeKind Kind, |
11649 | TypeDiagnoser &Diagnoser); |
11650 | bool RequireCompleteExprType(Expr *E, unsigned DiagID); |
11651 | |
11652 | template <typename... Ts> |
11653 | bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) { |
11654 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
11655 | return RequireCompleteExprType(E, CompleteTypeKind::Default, Diagnoser); |
11656 | } |
11657 | |
11658 | QualType getElaboratedType(ElaboratedTypeKeyword Keyword, |
11659 | const CXXScopeSpec &SS, QualType T, |
11660 | TagDecl *OwnedTagDecl = nullptr); |
11661 | |
11662 | // Returns the underlying type of a decltype with the given expression. |
11663 | QualType getDecltypeForExpr(Expr *E); |
11664 | |
11665 | QualType BuildTypeofExprType(Expr *E, TypeOfKind Kind); |
11666 | /// If AsUnevaluated is false, E is treated as though it were an evaluated |
11667 | /// context, such as when building a type for decltype(auto). |
11668 | QualType BuildDecltypeType(Expr *E, bool AsUnevaluated = true); |
11669 | |
11670 | QualType ActOnPackIndexingType(QualType Pattern, Expr *IndexExpr, |
11671 | SourceLocation Loc, |
11672 | SourceLocation EllipsisLoc); |
11673 | QualType BuildPackIndexingType(QualType Pattern, Expr *IndexExpr, |
11674 | SourceLocation Loc, SourceLocation EllipsisLoc, |
11675 | bool FullySubstituted = false, |
11676 | ArrayRef<QualType> Expansions = {}); |
11677 | |
11678 | using UTTKind = UnaryTransformType::UTTKind; |
11679 | QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind, |
11680 | SourceLocation Loc); |
11681 | QualType BuiltinEnumUnderlyingType(QualType BaseType, SourceLocation Loc); |
11682 | QualType BuiltinAddPointer(QualType BaseType, SourceLocation Loc); |
11683 | QualType BuiltinRemovePointer(QualType BaseType, SourceLocation Loc); |
11684 | QualType BuiltinDecay(QualType BaseType, SourceLocation Loc); |
11685 | QualType BuiltinAddReference(QualType BaseType, UTTKind UKind, |
11686 | SourceLocation Loc); |
11687 | QualType BuiltinRemoveExtent(QualType BaseType, UTTKind UKind, |
11688 | SourceLocation Loc); |
11689 | QualType BuiltinRemoveReference(QualType BaseType, UTTKind UKind, |
11690 | SourceLocation Loc); |
11691 | QualType BuiltinChangeCVRQualifiers(QualType BaseType, UTTKind UKind, |
11692 | SourceLocation Loc); |
11693 | QualType BuiltinChangeSignedness(QualType BaseType, UTTKind UKind, |
11694 | SourceLocation Loc); |
11695 | |
11696 | bool RequireLiteralType(SourceLocation Loc, QualType T, |
11697 | TypeDiagnoser &Diagnoser); |
11698 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID); |
11699 | |
11700 | template <typename... Ts> |
11701 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID, |
11702 | const Ts &...Args) { |
11703 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
11704 | return RequireLiteralType(Loc, T, Diagnoser); |
11705 | } |
11706 | |
11707 | bool isCompleteType(SourceLocation Loc, QualType T, |
11708 | CompleteTypeKind Kind = CompleteTypeKind::Default) { |
11709 | return !RequireCompleteTypeImpl(Loc, T, Kind, Diagnoser: nullptr); |
11710 | } |
11711 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
11712 | CompleteTypeKind Kind, TypeDiagnoser &Diagnoser); |
11713 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
11714 | CompleteTypeKind Kind, unsigned DiagID); |
11715 | |
11716 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
11717 | TypeDiagnoser &Diagnoser) { |
11718 | return RequireCompleteType(Loc, T, Kind: CompleteTypeKind::Default, Diagnoser); |
11719 | } |
11720 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID) { |
11721 | return RequireCompleteType(Loc, T, Kind: CompleteTypeKind::Default, DiagID); |
11722 | } |
11723 | |
11724 | template <typename... Ts> |
11725 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID, |
11726 | const Ts &...Args) { |
11727 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
11728 | return RequireCompleteType(Loc, T, Diagnoser); |
11729 | } |
11730 | |
11731 | /// Determine whether a declaration is visible to name lookup. |
11732 | bool isVisible(const NamedDecl *D) { |
11733 | return D->isUnconditionallyVisible() || |
11734 | isAcceptableSlow(D, Kind: AcceptableKind::Visible); |
11735 | } |
11736 | |
11737 | /// Determine whether a declaration is reachable. |
11738 | bool isReachable(const NamedDecl *D) { |
11739 | // All visible declarations are reachable. |
11740 | return D->isUnconditionallyVisible() || |
11741 | isAcceptableSlow(D, Kind: AcceptableKind::Reachable); |
11742 | } |
11743 | |
11744 | /// Determine whether a declaration is acceptable (visible/reachable). |
11745 | bool isAcceptable(const NamedDecl *D, AcceptableKind Kind) { |
11746 | return Kind == AcceptableKind::Visible ? isVisible(D) : isReachable(D); |
11747 | } |
11748 | |
11749 | /// Determine if \p D and \p Suggested have a structurally compatible |
11750 | /// layout as described in C11 6.2.7/1. |
11751 | bool hasStructuralCompatLayout(Decl *D, Decl *Suggested); |
11752 | |
11753 | /// Determine if \p D has a visible definition. If not, suggest a declaration |
11754 | /// that should be made visible to expose the definition. |
11755 | bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, |
11756 | bool OnlyNeedComplete = false); |
11757 | bool hasVisibleDefinition(const NamedDecl *D) { |
11758 | NamedDecl *Hidden; |
11759 | return hasVisibleDefinition(D: const_cast<NamedDecl *>(D), Suggested: &Hidden); |
11760 | } |
11761 | |
11762 | /// Determine if \p D has a reachable definition. If not, suggest a |
11763 | /// declaration that should be made reachable to expose the definition. |
11764 | bool hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested, |
11765 | bool OnlyNeedComplete = false); |
11766 | bool hasReachableDefinition(NamedDecl *D) { |
11767 | NamedDecl *Hidden; |
11768 | return hasReachableDefinition(D, Suggested: &Hidden); |
11769 | } |
11770 | |
11771 | bool hasAcceptableDefinition(NamedDecl *D, NamedDecl **Suggested, |
11772 | AcceptableKind Kind, |
11773 | bool OnlyNeedComplete = false); |
11774 | bool hasAcceptableDefinition(NamedDecl *D, AcceptableKind Kind) { |
11775 | NamedDecl *Hidden; |
11776 | return hasAcceptableDefinition(D, Suggested: &Hidden, Kind); |
11777 | } |
11778 | |
11779 | private: |
11780 | bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T, |
11781 | CompleteTypeKind Kind, TypeDiagnoser *Diagnoser); |
11782 | |
11783 | /// Nullability type specifiers. |
11784 | IdentifierInfo *Ident__Nonnull = nullptr; |
11785 | IdentifierInfo *Ident__Nullable = nullptr; |
11786 | IdentifierInfo *Ident__Nullable_result = nullptr; |
11787 | IdentifierInfo *Ident__Null_unspecified = nullptr; |
11788 | |
11789 | IdentifierInfo *Ident_NSError = nullptr; |
11790 | |
11791 | ///@} |
11792 | |
11793 | // |
11794 | // |
11795 | // ------------------------------------------------------------------------- |
11796 | // |
11797 | // |
11798 | |
11799 | /// \name ObjC Declarations |
11800 | /// Implementations are in SemaDeclObjC.cpp |
11801 | ///@{ |
11802 | |
11803 | public: |
11804 | enum ObjCSpecialMethodKind { |
11805 | OSMK_None, |
11806 | OSMK_Alloc, |
11807 | OSMK_New, |
11808 | OSMK_Copy, |
11809 | OSMK_RetainingInit, |
11810 | OSMK_NonRetainingInit |
11811 | }; |
11812 | |
11813 | /// Method selectors used in a \@selector expression. Used for implementation |
11814 | /// of -Wselector. |
11815 | llvm::MapVector<Selector, SourceLocation> ReferencedSelectors; |
11816 | |
11817 | class GlobalMethodPool { |
11818 | public: |
11819 | using Lists = std::pair<ObjCMethodList, ObjCMethodList>; |
11820 | using iterator = llvm::DenseMap<Selector, Lists>::iterator; |
11821 | iterator begin() { return Methods.begin(); } |
11822 | iterator end() { return Methods.end(); } |
11823 | iterator find(Selector Sel) { return Methods.find(Val: Sel); } |
11824 | std::pair<iterator, bool> insert(std::pair<Selector, Lists> &&Val) { |
11825 | return Methods.insert(KV: Val); |
11826 | } |
11827 | int count(Selector Sel) const { return Methods.count(Val: Sel); } |
11828 | bool empty() const { return Methods.empty(); } |
11829 | |
11830 | private: |
11831 | llvm::DenseMap<Selector, Lists> Methods; |
11832 | }; |
11833 | |
11834 | /// Method Pool - allows efficient lookup when typechecking messages to "id". |
11835 | /// We need to maintain a list, since selectors can have differing signatures |
11836 | /// across classes. In Cocoa, this happens to be extremely uncommon (only 1% |
11837 | /// of selectors are "overloaded"). |
11838 | /// At the head of the list it is recorded whether there were 0, 1, or >= 2 |
11839 | /// methods inside categories with a particular selector. |
11840 | GlobalMethodPool MethodPool; |
11841 | |
11842 | /// Check ODR hashes for C/ObjC when merging types from modules. |
11843 | /// Differently from C++, actually parse the body and reject in case |
11844 | /// of a mismatch. |
11845 | template <typename T, |
11846 | typename = std::enable_if_t<std::is_base_of<NamedDecl, T>::value>> |
11847 | bool ActOnDuplicateODRHashDefinition(T *Duplicate, T *Previous) { |
11848 | if (Duplicate->getODRHash() != Previous->getODRHash()) |
11849 | return false; |
11850 | |
11851 | // Make the previous decl visible. |
11852 | makeMergedDefinitionVisible(ND: Previous); |
11853 | return true; |
11854 | } |
11855 | |
11856 | typedef llvm::SmallPtrSet<Selector, 8> SelectorSet; |
11857 | |
11858 | enum MethodMatchStrategy { MMS_loose, MMS_strict }; |
11859 | |
11860 | enum ObjCContainerKind { |
11861 | OCK_None = -1, |
11862 | OCK_Interface = 0, |
11863 | OCK_Protocol, |
11864 | OCK_Category, |
11865 | OCK_ClassExtension, |
11866 | OCK_Implementation, |
11867 | OCK_CategoryImplementation |
11868 | }; |
11869 | ObjCContainerKind getObjCContainerKind() const; |
11870 | |
11871 | DeclResult actOnObjCTypeParam(Scope *S, ObjCTypeParamVariance variance, |
11872 | SourceLocation varianceLoc, unsigned index, |
11873 | IdentifierInfo *paramName, |
11874 | SourceLocation paramLoc, |
11875 | SourceLocation colonLoc, ParsedType typeBound); |
11876 | |
11877 | ObjCTypeParamList *actOnObjCTypeParamList(Scope *S, SourceLocation lAngleLoc, |
11878 | ArrayRef<Decl *> typeParams, |
11879 | SourceLocation rAngleLoc); |
11880 | void popObjCTypeParamList(Scope *S, ObjCTypeParamList *typeParamList); |
11881 | |
11882 | ObjCInterfaceDecl *ActOnStartClassInterface( |
11883 | Scope *S, SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, |
11884 | SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, |
11885 | IdentifierInfo *SuperName, SourceLocation SuperLoc, |
11886 | ArrayRef<ParsedType> SuperTypeArgs, SourceRange SuperTypeArgsRange, |
11887 | Decl *const *ProtoRefs, unsigned NumProtoRefs, |
11888 | const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, |
11889 | const ParsedAttributesView &AttrList, SkipBodyInfo *SkipBody); |
11890 | |
11891 | void ActOnSuperClassOfClassInterface( |
11892 | Scope *S, SourceLocation AtInterfaceLoc, ObjCInterfaceDecl *IDecl, |
11893 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
11894 | IdentifierInfo *SuperName, SourceLocation SuperLoc, |
11895 | ArrayRef<ParsedType> SuperTypeArgs, SourceRange SuperTypeArgsRange); |
11896 | |
11897 | void ActOnTypedefedProtocols(SmallVectorImpl<Decl *> &ProtocolRefs, |
11898 | SmallVectorImpl<SourceLocation> &ProtocolLocs, |
11899 | IdentifierInfo *SuperName, |
11900 | SourceLocation SuperLoc); |
11901 | |
11902 | Decl *ActOnCompatibilityAlias(SourceLocation AtCompatibilityAliasLoc, |
11903 | IdentifierInfo *AliasName, |
11904 | SourceLocation AliasLocation, |
11905 | IdentifierInfo *ClassName, |
11906 | SourceLocation ClassLocation); |
11907 | |
11908 | bool CheckForwardProtocolDeclarationForCircularDependency( |
11909 | IdentifierInfo *PName, SourceLocation &PLoc, SourceLocation PrevLoc, |
11910 | const ObjCList<ObjCProtocolDecl> &PList); |
11911 | |
11912 | ObjCProtocolDecl *ActOnStartProtocolInterface( |
11913 | SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName, |
11914 | SourceLocation ProtocolLoc, Decl *const *ProtoRefNames, |
11915 | unsigned NumProtoRefs, const SourceLocation *ProtoLocs, |
11916 | SourceLocation EndProtoLoc, const ParsedAttributesView &AttrList, |
11917 | SkipBodyInfo *SkipBody); |
11918 | |
11919 | ObjCCategoryDecl *ActOnStartCategoryInterface( |
11920 | SourceLocation AtInterfaceLoc, const IdentifierInfo *ClassName, |
11921 | SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, |
11922 | const IdentifierInfo *CategoryName, SourceLocation CategoryLoc, |
11923 | Decl *const *ProtoRefs, unsigned NumProtoRefs, |
11924 | const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, |
11925 | const ParsedAttributesView &AttrList); |
11926 | |
11927 | ObjCImplementationDecl *ActOnStartClassImplementation( |
11928 | SourceLocation AtClassImplLoc, const IdentifierInfo *ClassName, |
11929 | SourceLocation ClassLoc, const IdentifierInfo *SuperClassname, |
11930 | SourceLocation SuperClassLoc, const ParsedAttributesView &AttrList); |
11931 | |
11932 | ObjCCategoryImplDecl *ActOnStartCategoryImplementation( |
11933 | SourceLocation AtCatImplLoc, const IdentifierInfo *ClassName, |
11934 | SourceLocation ClassLoc, const IdentifierInfo *CatName, |
11935 | SourceLocation CatLoc, const ParsedAttributesView &AttrList); |
11936 | |
11937 | DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, |
11938 | ArrayRef<Decl *> Decls); |
11939 | |
11940 | DeclGroupPtrTy |
11941 | ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, |
11942 | ArrayRef<IdentifierLocPair> IdentList, |
11943 | const ParsedAttributesView &attrList); |
11944 | |
11945 | void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer, |
11946 | ArrayRef<IdentifierLocPair> ProtocolId, |
11947 | SmallVectorImpl<Decl *> &Protocols); |
11948 | |
11949 | void DiagnoseTypeArgsAndProtocols(IdentifierInfo *ProtocolId, |
11950 | SourceLocation ProtocolLoc, |
11951 | IdentifierInfo *TypeArgId, |
11952 | SourceLocation TypeArgLoc, |
11953 | bool SelectProtocolFirst = false); |
11954 | |
11955 | /// Given a list of identifiers (and their locations), resolve the |
11956 | /// names to either Objective-C protocol qualifiers or type |
11957 | /// arguments, as appropriate. |
11958 | void actOnObjCTypeArgsOrProtocolQualifiers( |
11959 | Scope *S, ParsedType baseType, SourceLocation lAngleLoc, |
11960 | ArrayRef<IdentifierInfo *> identifiers, |
11961 | ArrayRef<SourceLocation> identifierLocs, SourceLocation rAngleLoc, |
11962 | SourceLocation &typeArgsLAngleLoc, SmallVectorImpl<ParsedType> &typeArgs, |
11963 | SourceLocation &typeArgsRAngleLoc, SourceLocation &protocolLAngleLoc, |
11964 | SmallVectorImpl<Decl *> &protocols, SourceLocation &protocolRAngleLoc, |
11965 | bool warnOnIncompleteProtocols); |
11966 | |
11967 | void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, |
11968 | ObjCInterfaceDecl *ID); |
11969 | |
11970 | Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd, |
11971 | ArrayRef<Decl *> allMethods = std::nullopt, |
11972 | ArrayRef<DeclGroupPtrTy> allTUVars = std::nullopt); |
11973 | |
11974 | struct ObjCArgInfo { |
11975 | IdentifierInfo *Name; |
11976 | SourceLocation NameLoc; |
11977 | // The Type is null if no type was specified, and the DeclSpec is invalid |
11978 | // in this case. |
11979 | ParsedType Type; |
11980 | ObjCDeclSpec DeclSpec; |
11981 | |
11982 | /// ArgAttrs - Attribute list for this argument. |
11983 | ParsedAttributesView ArgAttrs; |
11984 | }; |
11985 | |
11986 | Decl *ActOnMethodDeclaration( |
11987 | Scope *S, |
11988 | SourceLocation BeginLoc, // location of the + or -. |
11989 | SourceLocation EndLoc, // location of the ; or {. |
11990 | tok::TokenKind MethodType, ObjCDeclSpec &ReturnQT, ParsedType ReturnType, |
11991 | ArrayRef<SourceLocation> SelectorLocs, Selector Sel, |
11992 | // optional arguments. The number of types/arguments is obtained |
11993 | // from the Sel.getNumArgs(). |
11994 | ObjCArgInfo *ArgInfo, DeclaratorChunk::ParamInfo *CParamInfo, |
11995 | unsigned CNumArgs, // c-style args |
11996 | const ParsedAttributesView &AttrList, tok::ObjCKeywordKind MethodImplKind, |
11997 | bool isVariadic, bool MethodDefinition); |
11998 | |
11999 | bool CheckARCMethodDecl(ObjCMethodDecl *method); |
12000 | |
12001 | bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); |
12002 | |
12003 | /// Check whether the given new method is a valid override of the |
12004 | /// given overridden method, and set any properties that should be inherited. |
12005 | void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, |
12006 | const ObjCMethodDecl *Overridden); |
12007 | |
12008 | /// Describes the compatibility of a result type with its method. |
12009 | enum ResultTypeCompatibilityKind { |
12010 | RTC_Compatible, |
12011 | RTC_Incompatible, |
12012 | RTC_Unknown |
12013 | }; |
12014 | |
12015 | void CheckObjCMethodDirectOverrides(ObjCMethodDecl *method, |
12016 | ObjCMethodDecl *overridden); |
12017 | |
12018 | void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod, |
12019 | ObjCInterfaceDecl *CurrentClass, |
12020 | ResultTypeCompatibilityKind RTC); |
12021 | |
12022 | /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global |
12023 | /// pool. |
12024 | void AddAnyMethodToGlobalPool(Decl *D); |
12025 | |
12026 | void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); |
12027 | bool isObjCMethodDecl(Decl *D) { return D && isa<ObjCMethodDecl>(Val: D); } |
12028 | |
12029 | /// CheckImplementationIvars - This routine checks if the instance variables |
12030 | /// listed in the implelementation match those listed in the interface. |
12031 | void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, |
12032 | ObjCIvarDecl **Fields, unsigned nIvars, |
12033 | SourceLocation Loc); |
12034 | |
12035 | void WarnConflictingTypedMethods(ObjCMethodDecl *Method, |
12036 | ObjCMethodDecl *MethodDecl, |
12037 | bool IsProtocolMethodDecl); |
12038 | |
12039 | void CheckConflictingOverridingMethod(ObjCMethodDecl *Method, |
12040 | ObjCMethodDecl *Overridden, |
12041 | bool IsProtocolMethodDecl); |
12042 | |
12043 | /// WarnExactTypedMethods - This routine issues a warning if method |
12044 | /// implementation declaration matches exactly that of its declaration. |
12045 | void WarnExactTypedMethods(ObjCMethodDecl *Method, ObjCMethodDecl *MethodDecl, |
12046 | bool IsProtocolMethodDecl); |
12047 | |
12048 | /// MatchAllMethodDeclarations - Check methods declaraed in interface or |
12049 | /// or protocol against those declared in their implementations. |
12050 | void MatchAllMethodDeclarations( |
12051 | const SelectorSet &InsMap, const SelectorSet &ClsMap, |
12052 | SelectorSet &InsMapSeen, SelectorSet &ClsMapSeen, ObjCImplDecl *IMPDecl, |
12053 | ObjCContainerDecl *IDecl, bool &IncompleteImpl, bool ImmediateClass, |
12054 | bool WarnCategoryMethodImpl = false); |
12055 | |
12056 | /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in |
12057 | /// category matches with those implemented in its primary class and |
12058 | /// warns each time an exact match is found. |
12059 | void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP); |
12060 | |
12061 | /// ImplMethodsVsClassMethods - This is main routine to warn if any method |
12062 | /// remains unimplemented in the class or category \@implementation. |
12063 | void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl *IMPDecl, |
12064 | ObjCContainerDecl *IDecl, |
12065 | bool IncompleteImpl = false); |
12066 | |
12067 | DeclGroupPtrTy ActOnForwardClassDeclaration( |
12068 | SourceLocation Loc, IdentifierInfo **IdentList, SourceLocation *IdentLocs, |
12069 | ArrayRef<ObjCTypeParamList *> TypeParamLists, unsigned NumElts); |
12070 | |
12071 | /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns |
12072 | /// true, or false, accordingly. |
12073 | bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, |
12074 | const ObjCMethodDecl *PrevMethod, |
12075 | MethodMatchStrategy strategy = MMS_strict); |
12076 | |
12077 | /// Add the given method to the list of globally-known methods. |
12078 | void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method); |
12079 | |
12080 | void ReadMethodPool(Selector Sel); |
12081 | void updateOutOfDateSelector(Selector Sel); |
12082 | |
12083 | /// - Returns instance or factory methods in global method pool for |
12084 | /// given selector. It checks the desired kind first, if none is found, and |
12085 | /// parameter checkTheOther is set, it then checks the other kind. If no such |
12086 | /// method or only one method is found, function returns false; otherwise, it |
12087 | /// returns true. |
12088 | bool |
12089 | CollectMultipleMethodsInGlobalPool(Selector Sel, |
12090 | SmallVectorImpl<ObjCMethodDecl *> &Methods, |
12091 | bool InstanceFirst, bool CheckTheOther, |
12092 | const ObjCObjectType *TypeBound = nullptr); |
12093 | |
12094 | bool |
12095 | AreMultipleMethodsInGlobalPool(Selector Sel, ObjCMethodDecl *BestMethod, |
12096 | SourceRange R, bool receiverIdOrClass, |
12097 | SmallVectorImpl<ObjCMethodDecl *> &Methods); |
12098 | |
12099 | void |
12100 | DiagnoseMultipleMethodInGlobalPool(SmallVectorImpl<ObjCMethodDecl *> &Methods, |
12101 | Selector Sel, SourceRange R, |
12102 | bool receiverIdOrClass); |
12103 | |
12104 | const ObjCMethodDecl * |
12105 | SelectorsForTypoCorrection(Selector Sel, QualType ObjectType = QualType()); |
12106 | /// LookupImplementedMethodInGlobalPool - Returns the method which has an |
12107 | /// implementation. |
12108 | ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); |
12109 | |
12110 | void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); |
12111 | |
12112 | /// Checks that the Objective-C declaration is declared in the global scope. |
12113 | /// Emits an error and marks the declaration as invalid if it's not declared |
12114 | /// in the global scope. |
12115 | bool CheckObjCDeclScope(Decl *D); |
12116 | |
12117 | void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, |
12118 | const IdentifierInfo *ClassName, |
12119 | SmallVectorImpl<Decl *> &Decls); |
12120 | |
12121 | VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, |
12122 | SourceLocation StartLoc, SourceLocation IdLoc, |
12123 | const IdentifierInfo *Id, |
12124 | bool Invalid = false); |
12125 | |
12126 | Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); |
12127 | |
12128 | /// CollectIvarsToConstructOrDestruct - Collect those ivars which require |
12129 | /// initialization. |
12130 | void |
12131 | CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, |
12132 | SmallVectorImpl<ObjCIvarDecl *> &Ivars); |
12133 | |
12134 | void DiagnoseUseOfUnimplementedSelectors(); |
12135 | |
12136 | /// DiagnoseUnusedBackingIvarInAccessor - Issue an 'unused' warning if ivar |
12137 | /// which backs the property is not used in the property's accessor. |
12138 | void DiagnoseUnusedBackingIvarInAccessor(Scope *S, |
12139 | const ObjCImplementationDecl *ImplD); |
12140 | |
12141 | /// GetIvarBackingPropertyAccessor - If method is a property setter/getter and |
12142 | /// it property has a backing ivar, returns this ivar; otherwise, returns |
12143 | /// NULL. It also returns ivar's property on success. |
12144 | ObjCIvarDecl * |
12145 | GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method, |
12146 | const ObjCPropertyDecl *&PDecl) const; |
12147 | |
12148 | /// AddInstanceMethodToGlobalPool - All instance methods in a translation |
12149 | /// unit are added to a global pool. This allows us to efficiently associate |
12150 | /// a selector with a method declaraation for purposes of typechecking |
12151 | /// messages sent to "id" (where the class of the object is unknown). |
12152 | void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, |
12153 | bool impl = false) { |
12154 | AddMethodToGlobalPool(Method, impl, /*instance*/ instance: true); |
12155 | } |
12156 | |
12157 | /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. |
12158 | void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl = false) { |
12159 | AddMethodToGlobalPool(Method, impl, /*instance*/ instance: false); |
12160 | } |
12161 | |
12162 | private: |
12163 | /// AddMethodToGlobalPool - Add an instance or factory method to the global |
12164 | /// pool. See descriptoin of AddInstanceMethodToGlobalPool. |
12165 | void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); |
12166 | |
12167 | /// LookupMethodInGlobalPool - Returns the instance or factory method and |
12168 | /// optionally warns if there are multiple signatures. |
12169 | ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, |
12170 | bool receiverIdOrClass, |
12171 | bool instance); |
12172 | |
12173 | ///@} |
12174 | |
12175 | // |
12176 | // |
12177 | // ------------------------------------------------------------------------- |
12178 | // |
12179 | // |
12180 | |
12181 | /// \name ObjC Expressions |
12182 | /// Implementations are in SemaExprObjC.cpp |
12183 | ///@{ |
12184 | |
12185 | public: |
12186 | /// Caches identifiers/selectors for NSFoundation APIs. |
12187 | std::unique_ptr<NSAPI> NSAPIObj; |
12188 | |
12189 | /// The declaration of the Objective-C NSNumber class. |
12190 | ObjCInterfaceDecl *NSNumberDecl; |
12191 | |
12192 | /// The declaration of the Objective-C NSValue class. |
12193 | ObjCInterfaceDecl *NSValueDecl; |
12194 | |
12195 | /// Pointer to NSNumber type (NSNumber *). |
12196 | QualType NSNumberPointer; |
12197 | |
12198 | /// Pointer to NSValue type (NSValue *). |
12199 | QualType NSValuePointer; |
12200 | |
12201 | /// The Objective-C NSNumber methods used to create NSNumber literals. |
12202 | ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]; |
12203 | |
12204 | /// The declaration of the Objective-C NSString class. |
12205 | ObjCInterfaceDecl *NSStringDecl; |
12206 | |
12207 | /// Pointer to NSString type (NSString *). |
12208 | QualType NSStringPointer; |
12209 | |
12210 | /// The declaration of the stringWithUTF8String: method. |
12211 | ObjCMethodDecl *StringWithUTF8StringMethod; |
12212 | |
12213 | /// The declaration of the valueWithBytes:objCType: method. |
12214 | ObjCMethodDecl *ValueWithBytesObjCTypeMethod; |
12215 | |
12216 | /// The declaration of the Objective-C NSArray class. |
12217 | ObjCInterfaceDecl *NSArrayDecl; |
12218 | |
12219 | /// The declaration of the arrayWithObjects:count: method. |
12220 | ObjCMethodDecl *ArrayWithObjectsMethod; |
12221 | |
12222 | /// The declaration of the Objective-C NSDictionary class. |
12223 | ObjCInterfaceDecl *NSDictionaryDecl; |
12224 | |
12225 | /// The declaration of the dictionaryWithObjects:forKeys:count: method. |
12226 | ObjCMethodDecl *DictionaryWithObjectsMethod; |
12227 | |
12228 | /// id<NSCopying> type. |
12229 | QualType QIDNSCopying; |
12230 | |
12231 | /// will hold 'respondsToSelector:' |
12232 | Selector RespondsToSelectorSel; |
12233 | |
12234 | ExprResult HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, |
12235 | Expr *BaseExpr, SourceLocation OpLoc, |
12236 | DeclarationName MemberName, |
12237 | SourceLocation MemberLoc, |
12238 | SourceLocation SuperLoc, |
12239 | QualType SuperType, bool Super); |
12240 | |
12241 | ExprResult ActOnClassPropertyRefExpr(const IdentifierInfo &receiverName, |
12242 | const IdentifierInfo &propertyName, |
12243 | SourceLocation receiverNameLoc, |
12244 | SourceLocation propertyNameLoc); |
12245 | |
12246 | // ParseObjCStringLiteral - Parse Objective-C string literals. |
12247 | ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, |
12248 | ArrayRef<Expr *> Strings); |
12249 | |
12250 | ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S); |
12251 | |
12252 | /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the |
12253 | /// numeric literal expression. Type of the expression will be "NSNumber *" |
12254 | /// or "id" if NSNumber is unavailable. |
12255 | ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number); |
12256 | ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc, |
12257 | bool Value); |
12258 | ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements); |
12259 | |
12260 | /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the |
12261 | /// '@' prefixed parenthesized expression. The type of the expression will |
12262 | /// either be "NSNumber *", "NSString *" or "NSValue *" depending on the type |
12263 | /// of ValueType, which is allowed to be a built-in numeric type, "char *", |
12264 | /// "const char *" or C structure with attribute 'objc_boxable'. |
12265 | ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr); |
12266 | |
12267 | ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, |
12268 | Expr *IndexExpr, |
12269 | ObjCMethodDecl *getterMethod, |
12270 | ObjCMethodDecl *setterMethod); |
12271 | |
12272 | ExprResult |
12273 | BuildObjCDictionaryLiteral(SourceRange SR, |
12274 | MutableArrayRef<ObjCDictionaryElement> Elements); |
12275 | |
12276 | ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, |
12277 | TypeSourceInfo *EncodedTypeInfo, |
12278 | SourceLocation RParenLoc); |
12279 | |
12280 | ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, |
12281 | SourceLocation EncodeLoc, |
12282 | SourceLocation LParenLoc, ParsedType Ty, |
12283 | SourceLocation RParenLoc); |
12284 | |
12285 | /// ParseObjCSelectorExpression - Build selector expression for \@selector |
12286 | ExprResult ParseObjCSelectorExpression(Selector Sel, SourceLocation AtLoc, |
12287 | SourceLocation SelLoc, |
12288 | SourceLocation LParenLoc, |
12289 | SourceLocation RParenLoc, |
12290 | bool WarnMultipleSelectors); |
12291 | |
12292 | /// ParseObjCProtocolExpression - Build protocol expression for \@protocol |
12293 | ExprResult ParseObjCProtocolExpression(IdentifierInfo *ProtocolName, |
12294 | SourceLocation AtLoc, |
12295 | SourceLocation ProtoLoc, |
12296 | SourceLocation LParenLoc, |
12297 | SourceLocation ProtoIdLoc, |
12298 | SourceLocation RParenLoc); |
12299 | |
12300 | ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc); |
12301 | |
12302 | /// Describes the kind of message expression indicated by a message |
12303 | /// send that starts with an identifier. |
12304 | enum ObjCMessageKind { |
12305 | /// The message is sent to 'super'. |
12306 | ObjCSuperMessage, |
12307 | /// The message is an instance message. |
12308 | ObjCInstanceMessage, |
12309 | /// The message is a class message, and the identifier is a type |
12310 | /// name. |
12311 | ObjCClassMessage |
12312 | }; |
12313 | |
12314 | ObjCMessageKind getObjCMessageKind(Scope *S, IdentifierInfo *Name, |
12315 | SourceLocation NameLoc, bool IsSuper, |
12316 | bool HasTrailingDot, |
12317 | ParsedType &ReceiverType); |
12318 | |
12319 | ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, Selector Sel, |
12320 | SourceLocation LBracLoc, |
12321 | ArrayRef<SourceLocation> SelectorLocs, |
12322 | SourceLocation RBracLoc, MultiExprArg Args); |
12323 | |
12324 | ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, |
12325 | QualType ReceiverType, SourceLocation SuperLoc, |
12326 | Selector Sel, ObjCMethodDecl *Method, |
12327 | SourceLocation LBracLoc, |
12328 | ArrayRef<SourceLocation> SelectorLocs, |
12329 | SourceLocation RBracLoc, MultiExprArg Args, |
12330 | bool isImplicit = false); |
12331 | |
12332 | ExprResult BuildClassMessageImplicit(QualType ReceiverType, |
12333 | bool isSuperReceiver, SourceLocation Loc, |
12334 | Selector Sel, ObjCMethodDecl *Method, |
12335 | MultiExprArg Args); |
12336 | |
12337 | ExprResult ActOnClassMessage(Scope *S, ParsedType Receiver, Selector Sel, |
12338 | SourceLocation LBracLoc, |
12339 | ArrayRef<SourceLocation> SelectorLocs, |
12340 | SourceLocation RBracLoc, MultiExprArg Args); |
12341 | |
12342 | ExprResult BuildInstanceMessage(Expr *Receiver, QualType ReceiverType, |
12343 | SourceLocation SuperLoc, Selector Sel, |
12344 | ObjCMethodDecl *Method, |
12345 | SourceLocation LBracLoc, |
12346 | ArrayRef<SourceLocation> SelectorLocs, |
12347 | SourceLocation RBracLoc, MultiExprArg Args, |
12348 | bool isImplicit = false); |
12349 | |
12350 | ExprResult BuildInstanceMessageImplicit(Expr *Receiver, QualType ReceiverType, |
12351 | SourceLocation Loc, Selector Sel, |
12352 | ObjCMethodDecl *Method, |
12353 | MultiExprArg Args); |
12354 | |
12355 | ExprResult ActOnInstanceMessage(Scope *S, Expr *Receiver, Selector Sel, |
12356 | SourceLocation LBracLoc, |
12357 | ArrayRef<SourceLocation> SelectorLocs, |
12358 | SourceLocation RBracLoc, MultiExprArg Args); |
12359 | |
12360 | ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, |
12361 | ObjCBridgeCastKind Kind, |
12362 | SourceLocation BridgeKeywordLoc, |
12363 | TypeSourceInfo *TSInfo, Expr *SubExpr); |
12364 | |
12365 | ExprResult ActOnObjCBridgedCast(Scope *S, SourceLocation LParenLoc, |
12366 | ObjCBridgeCastKind Kind, |
12367 | SourceLocation BridgeKeywordLoc, |
12368 | ParsedType Type, SourceLocation RParenLoc, |
12369 | Expr *SubExpr); |
12370 | |
12371 | void CheckTollFreeBridgeCast(QualType castType, Expr *castExpr); |
12372 | |
12373 | void CheckObjCBridgeRelatedCast(QualType castType, Expr *castExpr); |
12374 | |
12375 | bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr, |
12376 | CastKind &Kind); |
12377 | |
12378 | bool checkObjCBridgeRelatedComponents(SourceLocation Loc, QualType DestType, |
12379 | QualType SrcType, |
12380 | ObjCInterfaceDecl *&RelatedClass, |
12381 | ObjCMethodDecl *&ClassMethod, |
12382 | ObjCMethodDecl *&InstanceMethod, |
12383 | TypedefNameDecl *&TDNDecl, bool CfToNs, |
12384 | bool Diagnose = true); |
12385 | |
12386 | bool CheckObjCBridgeRelatedConversions(SourceLocation Loc, QualType DestType, |
12387 | QualType SrcType, Expr *&SrcExpr, |
12388 | bool Diagnose = true); |
12389 | |
12390 | /// Private Helper predicate to check for 'self'. |
12391 | bool isSelfExpr(Expr *RExpr); |
12392 | bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method); |
12393 | |
12394 | ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, |
12395 | const ObjCObjectPointerType *OPT, |
12396 | bool IsInstance); |
12397 | ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty, |
12398 | bool IsInstance); |
12399 | |
12400 | bool isKnownName(StringRef name); |
12401 | |
12402 | enum ARCConversionResult { ACR_okay, ACR_unbridged, ACR_error }; |
12403 | |
12404 | /// Checks for invalid conversions and casts between |
12405 | /// retainable pointers and other pointer kinds for ARC and Weak. |
12406 | ARCConversionResult CheckObjCConversion(SourceRange castRange, |
12407 | QualType castType, Expr *&op, |
12408 | CheckedConversionKind CCK, |
12409 | bool Diagnose = true, |
12410 | bool DiagnoseCFAudited = false, |
12411 | BinaryOperatorKind Opc = BO_PtrMemD); |
12412 | |
12413 | Expr *stripARCUnbridgedCast(Expr *e); |
12414 | void diagnoseARCUnbridgedCast(Expr *e); |
12415 | |
12416 | bool CheckObjCARCUnavailableWeakConversion(QualType castType, |
12417 | QualType ExprType); |
12418 | |
12419 | /// CheckMessageArgumentTypes - Check types in an Obj-C message send. |
12420 | /// \param Method - May be null. |
12421 | /// \param [out] ReturnType - The return type of the send. |
12422 | /// \return true iff there were any incompatible types. |
12423 | bool CheckMessageArgumentTypes(const Expr *Receiver, QualType ReceiverType, |
12424 | MultiExprArg Args, Selector Sel, |
12425 | ArrayRef<SourceLocation> SelectorLocs, |
12426 | ObjCMethodDecl *Method, bool isClassMessage, |
12427 | bool isSuperMessage, SourceLocation lbrac, |
12428 | SourceLocation rbrac, SourceRange RecRange, |
12429 | QualType &ReturnType, ExprValueKind &VK); |
12430 | |
12431 | /// Determine the result of a message send expression based on |
12432 | /// the type of the receiver, the method expected to receive the message, |
12433 | /// and the form of the message send. |
12434 | QualType getMessageSendResultType(const Expr *Receiver, QualType ReceiverType, |
12435 | ObjCMethodDecl *Method, bool isClassMessage, |
12436 | bool isSuperMessage); |
12437 | |
12438 | /// If the given expression involves a message send to a method |
12439 | /// with a related result type, emit a note describing what happened. |
12440 | void EmitRelatedResultTypeNote(const Expr *E); |
12441 | |
12442 | /// Given that we had incompatible pointer types in a return |
12443 | /// statement, check whether we're in a method with a related result |
12444 | /// type, and if so, emit a note describing what happened. |
12445 | void EmitRelatedResultTypeNoteForReturn(QualType destType); |
12446 | |
12447 | /// LookupInstanceMethodInGlobalPool - Returns the method and warns if |
12448 | /// there are multiple signatures. |
12449 | ObjCMethodDecl * |
12450 | LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, |
12451 | bool receiverIdOrClass = false) { |
12452 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
12453 | /*instance*/ instance: true); |
12454 | } |
12455 | |
12456 | /// LookupFactoryMethodInGlobalPool - Returns the method and warns if |
12457 | /// there are multiple signatures. |
12458 | ObjCMethodDecl * |
12459 | LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, |
12460 | bool receiverIdOrClass = false) { |
12461 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
12462 | /*instance*/ instance: false); |
12463 | } |
12464 | |
12465 | ///@} |
12466 | |
12467 | // |
12468 | // |
12469 | // ------------------------------------------------------------------------- |
12470 | // |
12471 | // |
12472 | |
12473 | /// \name ObjC @property and @synthesize |
12474 | /// Implementations are in SemaObjCProperty.cpp |
12475 | ///@{ |
12476 | |
12477 | public: |
12478 | /// Ensure attributes are consistent with type. |
12479 | /// \param [in, out] Attributes The attributes to check; they will |
12480 | /// be modified to be consistent with \p PropertyTy. |
12481 | void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, SourceLocation Loc, |
12482 | unsigned &Attributes, |
12483 | bool propertyInPrimaryClass); |
12484 | |
12485 | /// Process the specified property declaration and create decls for the |
12486 | /// setters and getters as needed. |
12487 | /// \param property The property declaration being processed |
12488 | void ProcessPropertyDecl(ObjCPropertyDecl *property); |
12489 | |
12490 | Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, SourceLocation LParenLoc, |
12491 | FieldDeclarator &FD, ObjCDeclSpec &ODS, |
12492 | Selector GetterSel, Selector SetterSel, |
12493 | tok::ObjCKeywordKind MethodImplKind, |
12494 | DeclContext *lexicalDC = nullptr); |
12495 | |
12496 | Decl *ActOnPropertyImplDecl(Scope *S, SourceLocation AtLoc, |
12497 | SourceLocation PropertyLoc, bool ImplKind, |
12498 | IdentifierInfo *PropertyId, |
12499 | IdentifierInfo *PropertyIvar, |
12500 | SourceLocation PropertyIvarLoc, |
12501 | ObjCPropertyQueryKind QueryKind); |
12502 | |
12503 | /// Called by ActOnProperty to handle \@property declarations in |
12504 | /// class extensions. |
12505 | ObjCPropertyDecl *HandlePropertyInClassExtension( |
12506 | Scope *S, SourceLocation AtLoc, SourceLocation LParenLoc, |
12507 | FieldDeclarator &FD, Selector GetterSel, SourceLocation GetterNameLoc, |
12508 | Selector SetterSel, SourceLocation SetterNameLoc, const bool isReadWrite, |
12509 | unsigned &Attributes, const unsigned AttributesAsWritten, QualType T, |
12510 | TypeSourceInfo *TSI, tok::ObjCKeywordKind MethodImplKind); |
12511 | |
12512 | /// Called by ActOnProperty and HandlePropertyInClassExtension to |
12513 | /// handle creating the ObjcPropertyDecl for a category or \@interface. |
12514 | ObjCPropertyDecl * |
12515 | CreatePropertyDecl(Scope *S, ObjCContainerDecl *CDecl, SourceLocation AtLoc, |
12516 | SourceLocation LParenLoc, FieldDeclarator &FD, |
12517 | Selector GetterSel, SourceLocation GetterNameLoc, |
12518 | Selector SetterSel, SourceLocation SetterNameLoc, |
12519 | const bool isReadWrite, const unsigned Attributes, |
12520 | const unsigned AttributesAsWritten, QualType T, |
12521 | TypeSourceInfo *TSI, tok::ObjCKeywordKind MethodImplKind, |
12522 | DeclContext *lexicalDC = nullptr); |
12523 | |
12524 | void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, |
12525 | ObjCPropertyDecl *SuperProperty, |
12526 | const IdentifierInfo *Name, |
12527 | bool OverridingProtocolProperty); |
12528 | |
12529 | bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, |
12530 | ObjCMethodDecl *Getter, |
12531 | SourceLocation Loc); |
12532 | |
12533 | /// DiagnoseUnimplementedProperties - This routine warns on those properties |
12534 | /// which must be implemented by this implementation. |
12535 | void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl, |
12536 | ObjCContainerDecl *CDecl, |
12537 | bool SynthesizeProperties); |
12538 | |
12539 | /// Diagnose any null-resettable synthesized setters. |
12540 | void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl); |
12541 | |
12542 | /// DefaultSynthesizeProperties - This routine default synthesizes all |
12543 | /// properties which must be synthesized in the class's \@implementation. |
12544 | void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, |
12545 | ObjCInterfaceDecl *IDecl, |
12546 | SourceLocation AtEnd); |
12547 | void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd); |
12548 | |
12549 | /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is |
12550 | /// an ivar synthesized for 'Method' and 'Method' is a property accessor |
12551 | /// declared in class 'IFace'. |
12552 | bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace, |
12553 | ObjCMethodDecl *Method, ObjCIvarDecl *IV); |
12554 | |
12555 | void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D); |
12556 | |
12557 | void |
12558 | DiagnoseMissingDesignatedInitOverrides(const ObjCImplementationDecl *ImplD, |
12559 | const ObjCInterfaceDecl *IFD); |
12560 | |
12561 | /// AtomicPropertySetterGetterRules - This routine enforces the rule (via |
12562 | /// warning) when atomic property has one but not the other user-declared |
12563 | /// setter or getter. |
12564 | void AtomicPropertySetterGetterRules(ObjCImplDecl *IMPDecl, |
12565 | ObjCInterfaceDecl *IDecl); |
12566 | |
12567 | ///@} |
12568 | |
12569 | // |
12570 | // |
12571 | // ------------------------------------------------------------------------- |
12572 | // |
12573 | // |
12574 | |
12575 | /// \name Code Completion |
12576 | /// Implementations are in SemaCodeComplete.cpp |
12577 | ///@{ |
12578 | |
12579 | public: |
12580 | /// Code-completion consumer. |
12581 | CodeCompleteConsumer *CodeCompleter; |
12582 | |
12583 | /// Describes the context in which code completion occurs. |
12584 | enum ParserCompletionContext { |
12585 | /// Code completion occurs at top-level or namespace context. |
12586 | PCC_Namespace, |
12587 | /// Code completion occurs within a class, struct, or union. |
12588 | PCC_Class, |
12589 | /// Code completion occurs within an Objective-C interface, protocol, |
12590 | /// or category. |
12591 | PCC_ObjCInterface, |
12592 | /// Code completion occurs within an Objective-C implementation or |
12593 | /// category implementation |
12594 | PCC_ObjCImplementation, |
12595 | /// Code completion occurs within the list of instance variables |
12596 | /// in an Objective-C interface, protocol, category, or implementation. |
12597 | PCC_ObjCInstanceVariableList, |
12598 | /// Code completion occurs following one or more template |
12599 | /// headers. |
12600 | PCC_Template, |
12601 | /// Code completion occurs following one or more template |
12602 | /// headers within a class. |
12603 | PCC_MemberTemplate, |
12604 | /// Code completion occurs within an expression. |
12605 | PCC_Expression, |
12606 | /// Code completion occurs within a statement, which may |
12607 | /// also be an expression or a declaration. |
12608 | PCC_Statement, |
12609 | /// Code completion occurs at the beginning of the |
12610 | /// initialization statement (or expression) in a for loop. |
12611 | PCC_ForInit, |
12612 | /// Code completion occurs within the condition of an if, |
12613 | /// while, switch, or for statement. |
12614 | PCC_Condition, |
12615 | /// Code completion occurs within the body of a function on a |
12616 | /// recovery path, where we do not have a specific handle on our position |
12617 | /// in the grammar. |
12618 | PCC_RecoveryInFunction, |
12619 | /// Code completion occurs where only a type is permitted. |
12620 | PCC_Type, |
12621 | /// Code completion occurs in a parenthesized expression, which |
12622 | /// might also be a type cast. |
12623 | PCC_ParenthesizedExpression, |
12624 | /// Code completion occurs within a sequence of declaration |
12625 | /// specifiers within a function, method, or block. |
12626 | PCC_LocalDeclarationSpecifiers, |
12627 | /// Code completion occurs at top-level in a REPL session |
12628 | PCC_TopLevelOrExpression, |
12629 | }; |
12630 | |
12631 | void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path); |
12632 | void CodeCompleteOrdinaryName(Scope *S, |
12633 | ParserCompletionContext CompletionContext); |
12634 | void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, bool AllowNonIdentifiers, |
12635 | bool AllowNestedNameSpecifiers); |
12636 | |
12637 | struct CodeCompleteExpressionData; |
12638 | void CodeCompleteExpression(Scope *S, const CodeCompleteExpressionData &Data); |
12639 | void CodeCompleteExpression(Scope *S, QualType PreferredType, |
12640 | bool IsParenthesized = false); |
12641 | void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase, |
12642 | SourceLocation OpLoc, bool IsArrow, |
12643 | bool IsBaseExprStatement, |
12644 | QualType PreferredType); |
12645 | void CodeCompletePostfixExpression(Scope *S, ExprResult LHS, |
12646 | QualType PreferredType); |
12647 | void CodeCompleteTag(Scope *S, unsigned TagSpec); |
12648 | void CodeCompleteTypeQualifiers(DeclSpec &DS); |
12649 | void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D, |
12650 | const VirtSpecifiers *VS = nullptr); |
12651 | void CodeCompleteBracketDeclarator(Scope *S); |
12652 | void CodeCompleteCase(Scope *S); |
12653 | enum class AttributeCompletion { |
12654 | Attribute, |
12655 | Scope, |
12656 | None, |
12657 | }; |
12658 | void CodeCompleteAttribute( |
12659 | AttributeCommonInfo::Syntax Syntax, |
12660 | AttributeCompletion Completion = AttributeCompletion::Attribute, |
12661 | const IdentifierInfo *Scope = nullptr); |
12662 | /// Determines the preferred type of the current function argument, by |
12663 | /// examining the signatures of all possible overloads. |
12664 | /// Returns null if unknown or ambiguous, or if code completion is off. |
12665 | /// |
12666 | /// If the code completion point has been reached, also reports the function |
12667 | /// signatures that were considered. |
12668 | /// |
12669 | /// FIXME: rename to GuessCallArgumentType to reduce confusion. |
12670 | QualType ProduceCallSignatureHelp(Expr *Fn, ArrayRef<Expr *> Args, |
12671 | SourceLocation OpenParLoc); |
12672 | QualType ProduceConstructorSignatureHelp(QualType Type, SourceLocation Loc, |
12673 | ArrayRef<Expr *> Args, |
12674 | SourceLocation OpenParLoc, |
12675 | bool Braced); |
12676 | QualType ProduceCtorInitMemberSignatureHelp( |
12677 | Decl *ConstructorDecl, CXXScopeSpec SS, ParsedType TemplateTypeTy, |
12678 | ArrayRef<Expr *> ArgExprs, IdentifierInfo *II, SourceLocation OpenParLoc, |
12679 | bool Braced); |
12680 | QualType ProduceTemplateArgumentSignatureHelp( |
12681 | TemplateTy, ArrayRef<ParsedTemplateArgument>, SourceLocation LAngleLoc); |
12682 | void CodeCompleteInitializer(Scope *S, Decl *D); |
12683 | /// Trigger code completion for a record of \p BaseType. \p InitExprs are |
12684 | /// expressions in the initializer list seen so far and \p D is the current |
12685 | /// Designation being parsed. |
12686 | void CodeCompleteDesignator(const QualType BaseType, |
12687 | llvm::ArrayRef<Expr *> InitExprs, |
12688 | const Designation &D); |
12689 | void CodeCompleteAfterIf(Scope *S, bool IsBracedThen); |
12690 | |
12691 | void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext, |
12692 | bool IsUsingDeclaration, QualType BaseType, |
12693 | QualType PreferredType); |
12694 | void CodeCompleteUsing(Scope *S); |
12695 | void CodeCompleteUsingDirective(Scope *S); |
12696 | void CodeCompleteNamespaceDecl(Scope *S); |
12697 | void CodeCompleteNamespaceAliasDecl(Scope *S); |
12698 | void CodeCompleteOperatorName(Scope *S); |
12699 | void CodeCompleteConstructorInitializer( |
12700 | Decl *Constructor, ArrayRef<CXXCtorInitializer *> Initializers); |
12701 | |
12702 | void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, |
12703 | bool AfterAmpersand); |
12704 | void CodeCompleteAfterFunctionEquals(Declarator &D); |
12705 | |
12706 | void CodeCompleteObjCAtDirective(Scope *S); |
12707 | void CodeCompleteObjCAtVisibility(Scope *S); |
12708 | void CodeCompleteObjCAtStatement(Scope *S); |
12709 | void CodeCompleteObjCAtExpression(Scope *S); |
12710 | void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); |
12711 | void CodeCompleteObjCPropertyGetter(Scope *S); |
12712 | void CodeCompleteObjCPropertySetter(Scope *S); |
12713 | void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, |
12714 | bool IsParameter); |
12715 | void CodeCompleteObjCMessageReceiver(Scope *S); |
12716 | void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, |
12717 | ArrayRef<const IdentifierInfo *> SelIdents, |
12718 | bool AtArgumentExpression); |
12719 | void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, |
12720 | ArrayRef<const IdentifierInfo *> SelIdents, |
12721 | bool AtArgumentExpression, |
12722 | bool IsSuper = false); |
12723 | void CodeCompleteObjCInstanceMessage( |
12724 | Scope *S, Expr *Receiver, ArrayRef<const IdentifierInfo *> SelIdents, |
12725 | bool AtArgumentExpression, ObjCInterfaceDecl *Super = nullptr); |
12726 | void CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar); |
12727 | void CodeCompleteObjCSelector(Scope *S, |
12728 | ArrayRef<const IdentifierInfo *> SelIdents); |
12729 | void |
12730 | CodeCompleteObjCProtocolReferences(ArrayRef<IdentifierLocPair> Protocols); |
12731 | void CodeCompleteObjCProtocolDecl(Scope *S); |
12732 | void CodeCompleteObjCInterfaceDecl(Scope *S); |
12733 | void CodeCompleteObjCClassForwardDecl(Scope *S); |
12734 | void CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName, |
12735 | SourceLocation ClassNameLoc); |
12736 | void CodeCompleteObjCImplementationDecl(Scope *S); |
12737 | void CodeCompleteObjCInterfaceCategory(Scope *S, IdentifierInfo *ClassName, |
12738 | SourceLocation ClassNameLoc); |
12739 | void CodeCompleteObjCImplementationCategory(Scope *S, |
12740 | IdentifierInfo *ClassName, |
12741 | SourceLocation ClassNameLoc); |
12742 | void CodeCompleteObjCPropertyDefinition(Scope *S); |
12743 | void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, |
12744 | IdentifierInfo *PropertyName); |
12745 | void CodeCompleteObjCMethodDecl(Scope *S, |
12746 | std::optional<bool> IsInstanceMethod, |
12747 | ParsedType ReturnType); |
12748 | void CodeCompleteObjCMethodDeclSelector( |
12749 | Scope *S, bool IsInstanceMethod, bool AtParameterName, |
12750 | ParsedType ReturnType, ArrayRef<const IdentifierInfo *> SelIdents); |
12751 | void CodeCompleteObjCClassPropertyRefExpr(Scope *S, |
12752 | const IdentifierInfo &ClassName, |
12753 | SourceLocation ClassNameLoc, |
12754 | bool IsBaseExprStatement); |
12755 | void CodeCompletePreprocessorDirective(bool InConditional); |
12756 | void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); |
12757 | void CodeCompletePreprocessorMacroName(bool IsDefinition); |
12758 | void CodeCompletePreprocessorExpression(); |
12759 | void CodeCompletePreprocessorMacroArgument(Scope *S, IdentifierInfo *Macro, |
12760 | MacroInfo *MacroInfo, |
12761 | unsigned Argument); |
12762 | void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled); |
12763 | void CodeCompleteNaturalLanguage(); |
12764 | void CodeCompleteAvailabilityPlatformName(); |
12765 | void |
12766 | GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, |
12767 | CodeCompletionTUInfo &CCTUInfo, |
12768 | SmallVectorImpl<CodeCompletionResult> &Results); |
12769 | |
12770 | ///@} |
12771 | |
12772 | // |
12773 | // |
12774 | // ------------------------------------------------------------------------- |
12775 | // |
12776 | // |
12777 | |
12778 | /// \name FixIt Helpers |
12779 | /// Implementations are in SemaFixItUtils.cpp |
12780 | ///@{ |
12781 | |
12782 | public: |
12783 | /// Get a string to suggest for zero-initialization of a type. |
12784 | std::string getFixItZeroInitializerForType(QualType T, |
12785 | SourceLocation Loc) const; |
12786 | std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const; |
12787 | |
12788 | ///@} |
12789 | |
12790 | // |
12791 | // |
12792 | // ------------------------------------------------------------------------- |
12793 | // |
12794 | // |
12795 | |
12796 | /// \name API Notes |
12797 | /// Implementations are in SemaAPINotes.cpp |
12798 | ///@{ |
12799 | |
12800 | public: |
12801 | /// Map any API notes provided for this declaration to attributes on the |
12802 | /// declaration. |
12803 | /// |
12804 | /// Triggered by declaration-attribute processing. |
12805 | void ProcessAPINotes(Decl *D); |
12806 | |
12807 | ///@} |
12808 | // |
12809 | // |
12810 | // ------------------------------------------------------------------------- |
12811 | // |
12812 | // |
12813 | |
12814 | /// \name Name Lookup for RISC-V Vector Intrinsic |
12815 | /// Implementations are in SemaRISCVVectorLookup.cpp |
12816 | ///@{ |
12817 | |
12818 | public: |
12819 | /// Indicate RISC-V vector builtin functions enabled or not. |
12820 | bool DeclareRISCVVBuiltins = false; |
12821 | |
12822 | /// Indicate RISC-V SiFive vector builtin functions enabled or not. |
12823 | bool DeclareRISCVSiFiveVectorBuiltins = false; |
12824 | |
12825 | private: |
12826 | std::unique_ptr<sema::RISCVIntrinsicManager> RVIntrinsicManager; |
12827 | |
12828 | ///@} |
12829 | }; |
12830 | |
12831 | DeductionFailureInfo |
12832 | MakeDeductionFailureInfo(ASTContext &Context, TemplateDeductionResult TDK, |
12833 | sema::TemplateDeductionInfo &Info); |
12834 | |
12835 | /// Contains a late templated function. |
12836 | /// Will be parsed at the end of the translation unit, used by Sema & Parser. |
12837 | struct LateParsedTemplate { |
12838 | CachedTokens Toks; |
12839 | /// The template function declaration to be late parsed. |
12840 | Decl *D; |
12841 | /// Floating-point options in the point of definition. |
12842 | FPOptions FPO; |
12843 | }; |
12844 | |
12845 | template <> |
12846 | void Sema::PragmaStack<Sema::AlignPackInfo>::Act(SourceLocation PragmaLocation, |
12847 | PragmaMsStackAction Action, |
12848 | llvm::StringRef StackSlotLabel, |
12849 | AlignPackInfo Value); |
12850 | |
12851 | std::unique_ptr<sema::RISCVIntrinsicManager> |
12852 | CreateRISCVIntrinsicManager(Sema &S); |
12853 | } // end namespace clang |
12854 | |
12855 | #endif |
12856 | |